From: Roger Pau Monné Date: Tue, 7 Jul 2020 13:23:26 +0000 (+0200) Subject: vtd: don't assume addresses are aligned in sync_cache X-Git-Tag: archive/raspbian/4.11.4+24-gddaaccbbab-1_deb10u1+rpi1^2^2~53^2~4 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=37c853a0bcb214f3de66cc44622287ef89cb51d1;p=xen.git vtd: don't assume addresses are aligned in sync_cache Current code in sync_cache assume that the address passed in is aligned to a cache line size. Fix the code to support passing in arbitrary addresses not necessarily aligned to a cache line size. This is part of XSA-321. Reported-by: Jan Beulich Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich master commit: b6d9398144f21718d25daaf8d72669a75592abc5 master date: 2020-07-07 14:39:05 +0200 --- diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/vtd/iommu.c index facd84ffc8..270eb1c31a 100644 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -161,8 +161,8 @@ static int iommus_incoherent; static void sync_cache(const void *addr, unsigned int size) { - int i; - static unsigned int clflush_size = 0; + static unsigned long clflush_size = 0; + const void *end = addr + size; if ( !iommus_incoherent ) return; @@ -170,8 +170,9 @@ static void sync_cache(const void *addr, unsigned int size) if ( clflush_size == 0 ) clflush_size = get_cache_line_size(); - for ( i = 0; i < size; i += clflush_size ) - cacheline_flush((char *)addr + i); + addr -= (unsigned long)addr & (clflush_size - 1); + for ( ; addr < end; addr += clflush_size ) + cacheline_flush((char *)addr); } /* Allocate page table, return its machine address */