Skip to contentSkip to conversation

gnttab: hypervisor side XSA-448 follow-up

PATCH New Jan Beulich 1 participant 3 messages Feb 26, 2024

lore
Share & tools
lore
#0 lore raw

v2 cover gnttab: hypervisor side XSA-448 follow-up

1: almost fully ignore zero-size flush requests
2: restrict GNTTABOP_cache_flush to Arm

Jan

#1 lore raw

PATCH v2 1/2 gnttab: almost fully ignore zero-size flush requests

Along the line with observations in the context of XSA-448, besides "op" no field is relevant when the range to be flushed is empty, much like e.g. the pointers passed to memcpy() are irrelevant (and would never be "validated") when the passed length is zero. Split the existing condition validating "op", "offset", and "length", leaving only the "op" part ahead of the check for length being zero (or no flushing to be performed).

---
v2: Undo expression folding.

xen/common/grant_table.c +6 -4
@@ -3528,15 +3528,17 @@ static int _cache_flush(const gnttab_cac
     void *v;
     int ret;
 
-    if ( (cflush->offset >= PAGE_SIZE) ||
-         (cflush->length > PAGE_SIZE) ||
-         (cflush->offset + cflush->length > PAGE_SIZE) ||
-         (cflush->op & ~(GNTTAB_CACHE_INVAL | GNTTAB_CACHE_CLEAN)) )
+    if ( cflush->op & ~(GNTTAB_CACHE_INVAL | GNTTAB_CACHE_CLEAN) )
         return -EINVAL;
 
     if ( cflush->length == 0 || cflush->op == 0 )
         return !*cur_ref ? 0 : -EILSEQ;
 
+    if ( (cflush->offset >= PAGE_SIZE) ||
+         (cflush->length > PAGE_SIZE) ||
+         cflush->offset + cflush->length > PAGE_SIZE )
+        return -EINVAL;
+
     /* currently unimplemented */
     if ( cflush->op & GNTTAB_CACHE_SOURCE_GREF )
         return -EOPNOTSUPP;
#2 lore raw

PATCH v2 2/2 gnttab: restrict GNTTABOP_cache_flush to Arm

In reply to Jan Beulich

This special purpose operation possibly shouldn't have been a grant table sub-op, but instead an arch-specific memory management one. No users are known or supposed to exist outside of Arm. Along with adding suitable #ifdef-s, move a helper function used solely here into the first of these new #ifdef-s.

With the functionality restricted, questionable helper functions can then also be purged from x86.

---
v2: New.

xen/arch/x86/include/asm/flushtlb.h +0 -15
@@ -182,21 +182,6 @@ void flush_area_mask(const cpumask_t *ma
 }
 
 static inline void flush_page_to_ram(unsigned long mfn, bool sync_icache) {}
-static inline int invalidate_dcache_va_range(const void *p,
-                                             unsigned long size)
-{ return -EOPNOTSUPP; }
-static inline int clean_and_invalidate_dcache_va_range(const void *p,
-                                                       unsigned long size)
-{
-    unsigned int order = get_order_from_bytes(size);
-    /* sub-page granularity support needs to be added if necessary */
-    flush_area_local(p, FLUSH_CACHE|FLUSH_ORDER(order));
-    return 0;
-}
-static inline int clean_dcache_va_range(const void *p, unsigned long size)
-{
-    return clean_and_invalidate_dcache_va_range(p, size);
-}
 
 unsigned int guest_flush_tlb_flags(const struct domain *d);
 void guest_flush_tlb_mask(const struct domain *d, const cpumask_t *mask);
xen/common/grant_table.c +44 -36

110 lines not on this page · raw message