From nobody Mon Feb 9 09:12:15 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1747817554; cv=none; d=zohomail.com; s=zohoarc; b=gYA4BWDMdohPOSYTH4pTBDtIMr6bKuqH4tbsYloy0wNqelPEg0bKr9UOVM0bHRN/hY7WjVLRO/eZcsc21omlIqsCSMOwEGgXFLW0HqahOgql+sFyIWJMKlhRd7dTfP3kibBaBE0PKNIWLzG7+n/SEOaf1ELzxmNe4F0Sktn1G54= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747817554; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YCUn1PIbwBCxw1cn97O5FsKta9uLJW/+01K2MDVFP7A=; b=Lj+dBv33rLrlGRSdFx7onVXBVCNn0C6kExN0Xjpcsw6er4o4Sbla1fZovlL/IQTFaVA8FOgHiDChQQUdfj4lrx4Q8Gfby1QA9XKjSuG7J6IFWqOf1dcLb5qLKZtWaTgJPLYrigOfOSFGa+sDwNxKRrQXKz/feDH3Z8Zgg1GEh/Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1747817554710599.5853242202726; Wed, 21 May 2025 01:52:34 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.991614.1375457 (Exim 4.92) (envelope-from ) id 1uHfBI-00028K-DM; Wed, 21 May 2025 08:52:08 +0000 Received: by outflank-mailman (output) from mailman id 991614.1375457; Wed, 21 May 2025 08:52:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uHfBI-00028D-AL; Wed, 21 May 2025 08:52:08 +0000 Received: by outflank-mailman (input) for mailman id 991614; Wed, 21 May 2025 08:52:06 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uHfBG-000287-SG for xen-devel@lists.xenproject.org; Wed, 21 May 2025 08:52:06 +0000 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id dcc2233a-3620-11f0-b892-0df219b8e170; Wed, 21 May 2025 10:52:04 +0200 (CEST) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 54L8Spjg026402; Wed, 21 May 2025 08:51:56 GMT Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 46sahbg66d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 May 2025 08:51:55 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 54L7i855034623; Wed, 21 May 2025 08:51:47 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 46rwepjar3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 May 2025 08:51:47 +0000 Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 54L8pjuj027328; Wed, 21 May 2025 08:51:47 GMT Received: from ca-dev112.us.oracle.com (ca-dev112.us.oracle.com [10.129.136.47]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 46rwepjaq9-2; Wed, 21 May 2025 08:51:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: dcc2233a-3620-11f0-b892-0df219b8e170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=YCUn1 PIbwBCxw1cn97O5FsKta9uLJW/+01K2MDVFP7A=; b=UcT01hPmJJP9Az+0HamHp GRVQE4qd9IrqBk027upBdONbhbR3Hp9I1JtA8nyimgJGOBy8vz1kCZrwp80Lc1ML bfoC5Yjnfw1rOPKCTDZX34QQDJxIVdEg81Jnldkf8JrXk+MIUram4f6/IzMO01EZ GgMYpQTKFXVpqocVmxqC3mWTEQqVALe+SOlefwYzw7Lm4PLJ/pDSPZvweyg7IfXS 5a7jc2xYvhzhtOpgYZYsen5k800AISAUbBZxzka94hYIKp6Sy5sn6S0WJy0Yhi96 LgsdrNOf9O+xP8mqk+NfImd72Oet7IAlymasE47wHIlEG82oUBdFbTjdQ9Rrf71C A== From: Harshvardhan Jha To: jgross@suse.com, sstabellini@kernel.org, boris.ostrovsky@oracle.com Cc: harshvardhan.j.jha@oracle.com, xen-devel@lists.xenproject.org, iommu@lists.linux.dev, stable@vger.kernel.org Subject: [PATCH 5.15.y v3 1/1] xen/swiotlb: relax alignment requirements Date: Wed, 21 May 2025 01:51:44 -0700 Message-ID: <20250521085144.1578880-2-harshvardhan.j.jha@oracle.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250521085144.1578880-1-harshvardhan.j.jha@oracle.com> References: <20250521085144.1578880-1-harshvardhan.j.jha@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-05-21_02,2025-05-20_03,2025-03-28_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxscore=0 spamscore=0 suspectscore=0 adultscore=0 malwarescore=0 phishscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2505160000 definitions=main-2505210086 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNTIxMDA4NyBTYWx0ZWRfX8f+U4oe/EQtS R/xiEPxMlpCBYcGuSQb5iApcpwt2bmOsBhLJna3sBQCLd5HDWYDNekKfY1QecnMQlfdNx1guQ6w b/HUBOQfH7SoRiXARMavCgfslIukAR6mpQBKRmmdISRxAjwX6iI7UWFK5QC5E1xDh6hQe9N4xCP Eg2fBmmEj79OkO1rnHahTu7bL7m+1rupo5HbijlmQzaxeGePPTFe4Ef/N9bQaXxHBGvKgwrCLRN FpUS51MqTZzh+1sp4UqjSFsHwL9cRzsaXXLNS3pfgY05jzK3q+bPLbHPhyEtoB0Y3gQ8l0iZI5J Ddu3ekRaYU3wNbFgYy77CAe0B5hT33E2I4FHNhGOrJbqyF5TK/qecCK9T9oP9ry31JAw9qQKenb vh5j+AJUHZwQMQUP/VcVcHMNcVFjAQR4AQc0ly/5ZTGEy7hitICqG1D1CGIjmDF75kfUMGHi X-Authority-Analysis: v=2.4 cv=VY/3PEp9 c=1 sm=1 tr=0 ts=682d942b b=1 cx=c_pps a=zPCbziy225d3KhSqZt3L1A==:117 a=zPCbziy225d3KhSqZt3L1A==:17 a=dt9VzEwgFbYA:10 a=iox4zFpeAAAA:8 a=yPCof4ZbAAAA:8 a=E5hRKjw2lWykmI9IJP0A:9 a=WzC6qhA0u3u7Ye7llzcV:22 cc=ntf awl=host:13206 X-Proofpoint-GUID: 5_s0WM-cZWPJR4YTdgd_l_rYSXFz68xK X-Proofpoint-ORIG-GUID: 5_s0WM-cZWPJR4YTdgd_l_rYSXFz68xK X-ZohoMail-DKIM: pass (identity @oracle.com) X-ZM-MESSAGEID: 1747817555585116600 Content-Type: text/plain; charset="utf-8" [ Upstream commit 85fcb57c983f423180ba6ec5d0034242da05cc54 ] 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: Juergen Gross Signed-off-by: Harshvardhan Jha --- 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)); } =20 +static inline bool range_requires_alignment(phys_addr_t p, size_t size) +{ + phys_addr_t algn =3D 1ULL << (get_order(size) + PAGE_SHIFT); + phys_addr_t bus_addr =3D 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 =3D XEN_PFN_DOWN(p); unsigned int i, nr_pages =3D XEN_PFN_UP(xen_offset_in_page(p) + size); - phys_addr_t algn =3D 1ULL << (get_order(size) + PAGE_SHIFT); =20 next_bfn =3D pfn_to_bfn(xen_pfn); =20 - /* 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 =3D 1; i < nr_pages; i++) if (pfn_to_bfn(++xen_pfn) !=3D ++next_bfn) return 1; @@ -306,7 +308,8 @@ xen_swiotlb_alloc_coherent(struct device *hwdev, size_t= size, phys =3D dma_to_phys(hwdev, *dma_handle); dev_addr =3D xen_phys_to_dma(hwdev, phys); if (((dev_addr + size - 1 <=3D dma_mask)) && - !range_straddles_page_boundary(phys, size)) + !range_straddles_page_boundary(phys, size) && + !range_requires_alignment(phys, size)) *dma_handle =3D 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, =20 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); =20 --=20 2.47.1