All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 5.15.y 0/1] Manual Backport of 099606a7b2d5 to 5.15
@ 2025-04-07  7:02 Harshvardhan Jha
  2025-04-07  7:02 ` [PATCH 5.15.y 1/1] xen/swiotlb: relax alignment requirements Harshvardhan Jha
  0 siblings, 1 reply; 4+ messages in thread
From: Harshvardhan Jha @ 2025-04-07  7:02 UTC (permalink / raw)
  To: jgross, sstabellini, boris.ostrovsky
  Cc: harshvardhan.j.jha, xen-devel, iommu, iommu, stable

The patch 099606a7b2d5 didn't cleanly apply to 5.15 due to the
significant difference in codebases.

I've tried to manually bring it back to 5.15 via some minor conflict
resolution but also invoking the newly introduced API using inverted
logic as the conditional statements present in 5.15 are the opposite of
those in 6.1 xen/swiotlib.

Harshvardhan Jha (1):
  xen/swiotlb: relax alignment requirements

 drivers/xen/swiotlb-xen.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

-- 
2.47.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 5.15.y 1/1] xen/swiotlb: relax alignment requirements
  2025-04-07  7:02 [PATCH 5.15.y 0/1] Manual Backport of 099606a7b2d5 to 5.15 Harshvardhan Jha
@ 2025-04-07  7:02 ` Harshvardhan Jha
  2025-04-07  7:14   ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Harshvardhan Jha @ 2025-04-07  7:02 UTC (permalink / raw)
  To: jgross, sstabellini, boris.ostrovsky
  Cc: harshvardhan.j.jha, xen-devel, iommu, iommu, stable

[ Upstream commit 099606a7b2d53e99ce31af42894c1fc9d77c6db9]

When mapping a buffer for DMA via .map_page or .map_sg DMA operations,
there is no need to check the machine frames to be aligned according
to the mapped areas size. All what is needed in these cases is that the
buffer is contiguous at machine level.

So carve out the alignment check from range_straddles_page_boundary()
and move it to a helper called by xen_swiotlb_alloc_coherent() and
xen_swiotlb_free_coherent() directly.

Fixes: 9f40ec84a797 ("xen/swiotlb: add alignment check for dma buffers")
Signed-off-by: Harshvardhan Jha <harshvardhan.j.jha@oracle.com>
---
 drivers/xen/swiotlb-xen.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 0392841a822fa..65da97be06285 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -75,19 +75,21 @@ static inline phys_addr_t xen_dma_to_phys(struct device *dev,
 	return xen_bus_to_phys(dev, dma_to_phys(dev, dma_addr));
 }
 
+static inline bool range_requires_alignment(phys_addr_t p, size_t size)
+{
+	phys_addr_t algn = 1ULL << (get_order(size) + PAGE_SHIFT);
+	phys_addr_t bus_addr = pfn_to_bfn(XEN_PFN_DOWN(p)) << XEN_PAGE_SHIFT;
+
+	return IS_ALIGNED(p, algn) && !IS_ALIGNED(bus_addr, algn);
+}
+
 static inline int range_straddles_page_boundary(phys_addr_t p, size_t size)
 {
 	unsigned long next_bfn, xen_pfn = XEN_PFN_DOWN(p);
 	unsigned int i, nr_pages = XEN_PFN_UP(xen_offset_in_page(p) + size);
-	phys_addr_t algn = 1ULL << (get_order(size) + PAGE_SHIFT);
 
 	next_bfn = pfn_to_bfn(xen_pfn);
 
-	/* If buffer is physically aligned, ensure DMA alignment. */
-	if (IS_ALIGNED(p, algn) &&
-	    !IS_ALIGNED((phys_addr_t)next_bfn << XEN_PAGE_SHIFT, algn))
-		return 1;
-
 	for (i = 1; i < nr_pages; i++)
 		if (pfn_to_bfn(++xen_pfn) != ++next_bfn)
 			return 1;
@@ -306,7 +308,8 @@ xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
 	phys = dma_to_phys(hwdev, *dma_handle);
 	dev_addr = xen_phys_to_dma(hwdev, phys);
 	if (((dev_addr + size - 1 <= dma_mask)) &&
-	    !range_straddles_page_boundary(phys, size))
+	    !range_straddles_page_boundary(phys, size) &&
+	    !range_requires_alignment(phys, size))
 		*dma_handle = dev_addr;
 	else {
 		if (xen_create_contiguous_region(phys, order,
@@ -347,6 +350,7 @@ xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
 
 	if (!WARN_ON((dev_addr + size - 1 > dma_mask) ||
 		     range_straddles_page_boundary(phys, size)) &&
+	    !range_requires_alignment(phys, size) &&
 	    TestClearPageXenRemapped(page))
 		xen_destroy_contiguous_region(phys, order);
 
-- 
2.47.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 5.15.y 1/1] xen/swiotlb: relax alignment requirements
  2025-04-07  7:02 ` [PATCH 5.15.y 1/1] xen/swiotlb: relax alignment requirements Harshvardhan Jha
@ 2025-04-07  7:14   ` Greg KH
  2025-04-07  9:38     ` Harshvardhan Jha
  0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2025-04-07  7:14 UTC (permalink / raw)
  To: Harshvardhan Jha
  Cc: jgross, sstabellini, boris.ostrovsky, xen-devel, iommu, iommu,
	stable

On Mon, Apr 07, 2025 at 12:02:35AM -0700, Harshvardhan Jha wrote:
> [ Upstream commit 099606a7b2d53e99ce31af42894c1fc9d77c6db9]

Wrong git id :(

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 5.15.y 1/1] xen/swiotlb: relax alignment requirements
  2025-04-07  7:14   ` Greg KH
@ 2025-04-07  9:38     ` Harshvardhan Jha
  0 siblings, 0 replies; 4+ messages in thread
From: Harshvardhan Jha @ 2025-04-07  9:38 UTC (permalink / raw)
  To: Greg KH
  Cc: jgross, sstabellini, boris.ostrovsky, xen-devel, iommu, iommu,
	stable


On 07/04/25 12:44 PM, Greg KH wrote:
> On Mon, Apr 07, 2025 at 12:02:35AM -0700, Harshvardhan Jha wrote:
>> [ Upstream commit 099606a7b2d53e99ce31af42894c1fc9d77c6db9]
> Wrong git id :(

Ah my bad is it 85fcb57c983f423180ba6ec5d0034242da05cc54 instead?

Harshvardhan


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-04-07  9:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-07  7:02 [PATCH 5.15.y 0/1] Manual Backport of 099606a7b2d5 to 5.15 Harshvardhan Jha
2025-04-07  7:02 ` [PATCH 5.15.y 1/1] xen/swiotlb: relax alignment requirements Harshvardhan Jha
2025-04-07  7:14   ` Greg KH
2025-04-07  9:38     ` Harshvardhan Jha

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.