Skip to contentSkip to conversation

x86/xen: add physically contiguous check to xen_destroy_contiguous_region

PATCH In review Joe Jin 1 participant 3 messages Oct 26, 2018

Subsystems (4)
lore
Share & tools
lore

Joe Jin

author
#0 lore raw

PATCH 1/1 x86/xen: add physically contiguous check to xen_destroy_contiguous_region

xen_destroy_contiguous_region() used to exchange physically contiguous memory with hypervisor, but it does not verify that the memory is physically contiguous or no, passing non-contiguous memory to xen_destroy_contiguous_region() will lead kernel panic.

Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Juergen Gross <[email protected]>
---
 arch/x86/xen/mmu_pv.c     | 3 +++
 drivers/xen/swiotlb-xen.c | 3 +--
 2 files changed, 4 insertions(+), 2 deletions(-)
arch/x86/xen/mmu_pv.c +3 -0
index 70ea598a37d2..c2f081f8ebe3 100644
@@ -2649,6 +2649,9 @@ void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order)
 	if (unlikely(order > MAX_CONTIG_ORDER))
 		return;
 
+	if (range_straddles_page_boundary(pstart, PAGE_SIZE << order))
+		return;
+
 	vstart = (unsigned long)phys_to_virt(pstart);
 	memset((void *) vstart, 0, PAGE_SIZE << order);
 
drivers/xen/swiotlb-xen.c +1 -2
index f5c1af4ce9ab..432eeae02d7d 100644
@@ -357,8 +357,7 @@ xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
 	/* Convert the size to actually allocated. */
 	size = 1UL << (order + XEN_PAGE_SHIFT);
 
-	if (((dev_addr + size - 1 <= dma_mask)) ||
-	    range_straddles_page_boundary(phys, size))
+	if (dev_addr + size - 1 <= dma_mask)
 		xen_destroy_contiguous_region(phys, order);
 
 	xen_free_coherent_pages(hwdev, size, vaddr, (dma_addr_t)phys, attrs);
Signature · 1 line
2.17.1 (Apple Git-112)
author
#1 lore raw

I did not realized range_straddles_page_boundary() only available on xen-swiotlb, please ignore this patch.

Sorry for the bother.

Thanks,
Joe

Quoted 35 lines · Joe Jin

xen_destroy_contiguous_region() used to exchange physically contiguous memory with hypervisor, but it does not verify that the memory is physically contiguous or no, passing non-contiguous memory to xen_destroy_contiguous_region() will lead kernel panic.

Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Juergen Gross <[email protected]>
---
 arch/x86/xen/mmu_pv.c     | 3 +++
 drivers/xen/swiotlb-xen.c | 3 +--
 2 files changed, 4 insertions(+), 2 deletions(-)
arch/x86/xen/mmu_pv.c +3 -0
index 70ea598a37d2..c2f081f8ebe3 100644
@@ -2649,6 +2649,9 @@ void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order)
 	if (unlikely(order > MAX_CONTIG_ORDER))
 		return;
 
+	if (range_straddles_page_boundary(pstart, PAGE_SIZE << order))
+		return;
+
 	vstart = (unsigned long)phys_to_virt(pstart);
 	memset((void *) vstart, 0, PAGE_SIZE << order);
 
drivers/xen/swiotlb-xen.c +0 -0
index f5c1af4ce9ab..432eeae02d7d 100644

drivers/xen/swiotlb-xen.c xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr, · line 363

Quoted 9 lines
drivers/xen/swiotlb-xen.c +1 -2
@@ -357,8 +357,7 @@ xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
 	/* Convert the size to actually allocated. */
 	size = 1UL << (order + XEN_PAGE_SHIFT);
 
-	if (((dev_addr + size - 1 <= dma_mask)) ||
-	    range_straddles_page_boundary(phys, size))
+	if (dev_addr + size - 1 <= dma_mask)
 		xen_destroy_contiguous_region(phys, order);
 
 	xen_free_coherent_pages(hwdev, size, vaddr, (dma_addr_t)phys, attrs);

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#2 lore raw
In reply to Joe Jin

I did not realized range_straddles_page_boundary() only available on xen-swiotlb, please ignore this patch.

Sorry for the bother.

Thanks,
Joe

Quoted 44 lines · Joe Jin

xen_destroy_contiguous_region() used to exchange physically contiguous memory with hypervisor, but it does not verify that the memory is physically contiguous or no, passing non-contiguous memory to xen_destroy_contiguous_region() will lead kernel panic.

Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Juergen Gross <[email protected]>
---
 arch/x86/xen/mmu_pv.c     | 3 +++
 drivers/xen/swiotlb-xen.c | 3 +--
 2 files changed, 4 insertions(+), 2 deletions(-)
arch/x86/xen/mmu_pv.c +3 -0
index 70ea598a37d2..c2f081f8ebe3 100644
@@ -2649,6 +2649,9 @@ void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order)
 	if (unlikely(order > MAX_CONTIG_ORDER))
 		return;
 
+	if (range_straddles_page_boundary(pstart, PAGE_SIZE << order))
+		return;
+
 	vstart = (unsigned long)phys_to_virt(pstart);
 	memset((void *) vstart, 0, PAGE_SIZE << order);
 
drivers/xen/swiotlb-xen.c +1 -2
index f5c1af4ce9ab..432eeae02d7d 100644
@@ -357,8 +357,7 @@ xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
 	/* Convert the size to actually allocated. */
 	size = 1UL << (order + XEN_PAGE_SHIFT);
 
-	if (((dev_addr + size - 1 <= dma_mask)) ||
-	    range_straddles_page_boundary(phys, size))
+	if (dev_addr + size - 1 <= dma_mask)
 		xen_destroy_contiguous_region(phys, order);
 
 	xen_free_coherent_pages(hwdev, size, vaddr, (dma_addr_t)phys, attrs);