From patchwork Wed Sep 18 02:52:26 2024
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Huan Yang
X-Patchwork-Id: 829755
Received: from APC01-SG2-obe.outbound.protection.outlook.com
(mail-sgaapc01on2078.outbound.protection.outlook.com [40.107.215.78])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B09613D53E;
Wed, 18 Sep 2024 02:53:03 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
arc=fail smtp.client-ip=40.107.215.78
ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1726627985; cv=fail;
b=lmwe5Jvn5F1Rip5tVNqeUq2XuBXpack/Gg0q2l+rvdVYDus30g+sxmF4y0r0kPQrfDI12mlHbK6ExLPaA31DdSz1uOyBi9q1q2ckvy3KZGi+mxPj80kmuRD9cUDU1jZ6RMXodQaN2IUe2xuFxwrTNA7+/LfKataRObLl09v7+wY=
ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1726627985; c=relaxed/simple;
bh=a+prow2G8AOmB1mazi2wSP+bUuPXY5IMcpLNRCoxAlM=;
h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
Content-Type:MIME-Version;
b=u3VUpu99GVShja9quKq4HXjkMtKk/acnaKMDBTAkauFGNl+qZe3zidy14r4prn1EyBAONaXYWLevfjKU8w9KkRh2SYNXB0mTerFtGAaOn6GuoPdPhMA/NTdwveA4NORQBtQwWL8Zco4drvu0HNp776bdfJFOHYXWAVGAcR/V2VQ=
ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dmarc=pass (p=quarantine dis=none) header.from=vivo.com;
spf=pass smtp.mailfrom=vivo.com;
dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com
header.b=Yv9zqMr7; arc=fail smtp.client-ip=40.107.215.78
Authentication-Results: smtp.subspace.kernel.org;
dmarc=pass (p=quarantine dis=none) header.from=vivo.com
Authentication-Results: smtp.subspace.kernel.org;
spf=pass smtp.mailfrom=vivo.com
Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com
header.b="Yv9zqMr7"
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
b=F7G38yLVQsQr7V5GO+n4phmKCcM+w1JTWwAT4yBqyEMnAFpqVj4clPHJ3ptBOopxBq8OINpDv5Ey7/peJrKGPHJaT8B1zUjHovdVyN+rIgoGmuBQe5Fh2akGpPWfZo/gK29++aR/6e3t+0/dz9AWzVJueuuQ93XXFprj7t13XOSNM3VsUHEAtcAT//yXs3Wo7JoP8VF/qyO20ZvgjU6OK/zr4HeZdBFWr/2Xp2ttgzm67f2mf1kWqOxHRq0MOzdWPnavVcfzhWw/L08oCEPoUuXgeFq8I6ytuFSYJdn6hJQuhgImnP834xGycFUAXKtn3aIcpq5yPR2/gVrdxm+3WA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;
s=arcselector10001;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
bh=pR9wSPVOI7eXTkp0FrF0jRKskMdnCcm+aAsS3Z2Iew0=;
b=GZExe/Jv7CsvVxXZ63L9FMwxwP6BcUvn4WFjXFywzB0fm3eilcsc12wxvHVh9k+Qh0sDTi/BrcY5ypk7zMWMrrKge4elFAjIVu13hzTCIxc27QlMndoNm55IXbmgKeA/o1metLWPmBQoNlK4sVM8nu6495N+bMoyf/37fTmGDZz1j+vMFAbtCyKoojzvlSNvXYr+Qh3gOLdkR7CLJ/dg6xYP5NFnWsCYw3Es8iT3/lS+gfViHXn1hjjTi1+93chOdgXhr7o9xRyXoYpuOSl6hEYoRsFVINZPdnXiN+cE0/8zAE4GdVe3aTaxjAGdfuOJUYgTI1YocPVF/LHLQz1ZsA==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com;
dkim=pass header.d=vivo.com; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
bh=pR9wSPVOI7eXTkp0FrF0jRKskMdnCcm+aAsS3Z2Iew0=;
b=Yv9zqMr7E16+F7hFxE+U8LiQg0aoqXF7aCyMnp8qjxNbcE5PEiQEZb+RdFBtnGE6fdq9vQEhgCEAdci+rY45qgAb0zQKRIjemoDr/jzgGyA99R0j2JbXL4nVc5ZMONk7knMiMp4nzZL2+zXuQas5LIGotnOwupIXA8JuAnBU+oCR6ej/m/xEMecjlCz0E7+iLZV2vkZslvo8JXaDGYgpZRVW5bCoFwMtnZweBLLd6mFVMKJbcWOgMsf4IOCZogH+4pNo0Ib6kAzMI7tTCk8HDx6//3ltiPpbd8YiVBarP0HNPXfpQKoofpFx9tHP1qwjT7+f5/iGeuaoibr/9Hs94w==
Authentication-Results: dkim=none (message not signed)
header.d=none;dmarc=none action=none header.from=vivo.com;
Received: from SEYPR06MB5672.apcprd06.prod.outlook.com (2603:1096:101:bc::11)
by KL1PR06MB6236.apcprd06.prod.outlook.com (2603:1096:820:d7::11)
with Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.23; Wed, 18 Sep
2024 02:52:58 +0000
Received: from SEYPR06MB5672.apcprd06.prod.outlook.com
([fe80::2f0c:5cf2:abb0:d852]) by SEYPR06MB5672.apcprd06.prod.outlook.com
([fe80::2f0c:5cf2:abb0:d852%5]) with mapi id 15.20.7962.022; Wed, 18 Sep 2024
02:52:58 +0000
From: Huan Yang
To: vivek.kasireddy@intel.com, Sumit Semwal ,
=?utf-8?q?Christian_K=C3=B6nig?= ,
Gerd Hoffmann , Dave Airlie ,
Andrew Morton , linux-media@vger.kernel.org,
dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org,
linux-kernel@vger.kernel.org
Cc: opensource.kernel@vivo.com,
Huan Yang
Subject: [PATCH v7 3/7] udmabuf: fix vmap_udmabuf error page set
Date: Wed, 18 Sep 2024 10:52:26 +0800
Message-ID: <20240918025238.2957823-4-link@vivo.com>
X-Mailer: git-send-email 2.45.2
In-Reply-To: <20240918025238.2957823-1-link@vivo.com>
References: <20240918025238.2957823-1-link@vivo.com>
X-ClientProxiedBy: SI2P153CA0014.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::6)
To SEYPR06MB5672.apcprd06.prod.outlook.com
(2603:1096:101:bc::11)
Precedence: bulk
X-Mailing-List: linux-media@vger.kernel.org
List-Id:
List-Subscribe:
List-Unsubscribe:
MIME-Version: 1.0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: SEYPR06MB5672:EE_|KL1PR06MB6236:EE_
X-MS-Office365-Filtering-Correlation-Id: 5030fe5e-96bd-4e00-94bb-08dcd78d00ca
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
ARA:13230040|1800799024|52116014|366016|376014|7416014|38350700014|921020;
X-Microsoft-Antispam-Message-Info: NhV9IdxDzVXyNzetCmjbDyqcoWjLC/yWk53OrUUgkXVLu/T9su3r3PS5bX798pmYnPaG40jsxiWc73GclwdaChEXLRA8hN6GeeSjTQn5KVpUccAqLsUYj+iPdcZ6D+xi5AIxuYmIRBI763l3cSJhxxinbReVX1YLoE+YuhbG9OPu3k3kk1uTCQET2WZ6ON8Y4DxC6qdgxg5iIB7L0K0A1v+wh8itBAcy1cyLG/7k3nGBmKpNdcEwL46cQghVC52EjCeYBqxzzylZs1fyZviYcFeJ4OdIjw9udXx2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jMx81GRAbeN11AHt1hmBsozkgG0OBgLMPo1rHGYVoaUX3IgRDtUTFB7/K+jH6RA08paGKzRd7P4qggNY=
X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
IPV:NLI; SFV:NSPM; H:SEYPR06MB5672.apcprd06.prod.outlook.com; PTR:; CAT:NONE;
SFS:(13230040)(1800799024)(52116014)(366016)(376014)(7416014)(38350700014)(921020);
DIR:OUT; SFP:1101;
X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1
X-MS-Exchange-AntiSpam-MessageData-0: SMZeFA+EuoR1qEUWUAoacDIL8Fy4ndBotw+csp1fwjyTAvyy2uIS5dpbqq6TtDX6CKOGSUrX/Jc25eJ9bHY69gHkdTRlOAVaW+8GrGHODUsp6Cv34vccHc79+DmFl0GhlzCDx804XWNNSqZZqH5IW8HnX31WQDl/mJHZEdjEFj9mzIOCz0cjmxYyoCQGYVsyKaclbn8yr4hUN6SOFYq9zYQXmlPoHXt+ezJhZ8E+hPIlvF3BfMIBPHtldP3zj7QEHR5zeQCmmxC/4soTe7uQJ6aX9IzOZkSoUxBf0rnZWKhpg7YHf0E6GvHyqlqHfhNFMfDOiTzuc1WCiN1FDNrBWd1uRHAYNh8c+9Y1SKzpot7y7sCfx/QLMnWUTthyAqKL1S9ByqBjxzBIb599nM5Rms+nS4ZbrK6plTgKr+XC88QFnCtoaTAtOPRhaip7GDHahyH8DfVkyhc/rbtjlEqdBkai7F77BJxaIdAiiOZBfTD5KOEkSHGVgEibxuhXti9uxqJ76GnrLe/fU3swBInnx44wP6XkciXpBoRzb08NtwLG84DjMxL8gs1DFWZlzeyplcmbaVGjKPXX7l4DeepfOOnwJrUqhxt0mNiB0FDHnml90EcjqzXh0/apwN7fLQSRZ0/JP44JsByAF9X/Wit6JpFmfKiAK045ysM/7NAyF/4S3R6KjsQTEYzkNU+iyTt2usql/NJQzlrXUzdxb6bMB+gNdcDmKx6MBt1PqYMQNNjmpSStF1O13rWrnrhm5DoA7NjjG+nyC8MMpI2aN9ufQDyi7h2puUvyqj7GuIKi/b7ICQuwr4FVsrCITxr1M46vxv35WcsXO6kjJTFJz6eV2yXBdFf447+S/QEeljb7EIe+pBhWGe3MLZQ/YyQ6jqta6x8KJfKmgTbvPHp5wItTRnXIkClTRbbqNPJ3JYUmxYwDGmHvUJmIE1PaxI7KPW9Dz7Tv3bHMpJouipNwN4manYyqU45Y83BVG447ixcPhvfS/cHsMWEhMZeICcSBP8382s1YJrDgp6Y3WQTwtAcLyoRzGfm0KNb3A/MxdD/Ea6591Nun+swannAsRCvVLJPUxqF14j3u8UYtiNjdcxUpKDNn6/eJKqc9vM/jubVXPUKllV9J+ImqLaI4pzJKaEDK9M4NEIIK2qgj0NgVvmPR2mS6SE2xBmKZhfFhs0iscuRlJTa9lehXtKGP0eVgaKHyUvkQsH8pOP2B2L00QLYcqppTmWPd57SCtgTJlcobzBfpXReEvRZ3WnVaAD9UW3xl7fbRVT04WwknAmFhsExT297ZWiwLnR1eSxnMChcyYNVp1XdGVcf4AllyfXxGDx/5HAiEmpIBMMlhM/5yQpwq59V4VF3f5zM5KipAwBSgTpS9t50MH6R+LMOhDUmMcDv8CkxXkJuIxx/LSojpBwVH6A3eM4wAyZUjnpu9EqQpDGyQMSZ1aLBsXgo0kmUBdyRX6fAI2nIZs02CwZYgNkr/EDF2CX3Rf7jUKEzkzCMjtlA7rV6CsUkEigy09ZXkKFs5PedXTi0qUpkswFptFrH8QphbVj3O2nJpAt+LGASYu5gVgkyqe5r21q3KzFzJGo8c
X-OriginatorOrg: vivo.com
X-MS-Exchange-CrossTenant-Network-Message-Id: 5030fe5e-96bd-4e00-94bb-08dcd78d00ca
X-MS-Exchange-CrossTenant-AuthSource: SEYPR06MB5672.apcprd06.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2024 02:52:58.5178 (UTC)
X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted
X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed
X-MS-Exchange-CrossTenant-MailboxType: HOSTED
X-MS-Exchange-CrossTenant-UserPrincipalName: 7T9db4i6KYS9Nb6SMjitG9gy/3H3w6f7wTYtWt3WGX2KrXrnHzXrs1lY1/Fo/vuKxDTnLo2pRVzEKjvE4fh5MQ==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR06MB6236
Currently vmap_udmabuf set page's array by each folio.
But, ubuf->folios is only contain's the folio's head page.
That mean we repeatedly mapped the folio head page to the vmalloc area.
Due to udmabuf can use hugetlb, if HVO enabled, tail page may not exist,
so, we can't use page array to map, instead, use pfn array.
By this, we removed page usage in udmabuf totally.
Fixes: 5e72b2b41a21 ("udmabuf: convert udmabuf driver to use folios")
Suggested-by: Vivek Kasireddy
Signed-off-by: Huan Yang
Acked-by: Vivek Kasireddy
---
drivers/dma-buf/Kconfig | 1 +
drivers/dma-buf/udmabuf.c | 22 +++++++++++++++-------
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/drivers/dma-buf/Kconfig b/drivers/dma-buf/Kconfig
index b46eb8a552d7..fee04fdb0822 100644
--- a/drivers/dma-buf/Kconfig
+++ b/drivers/dma-buf/Kconfig
@@ -36,6 +36,7 @@ config UDMABUF
depends on DMA_SHARED_BUFFER
depends on MEMFD_CREATE || COMPILE_TEST
depends on MMU
+ select VMAP_PFN
help
A driver to let userspace turn memfd regions into dma-bufs.
Qemu can use this to create host dmabufs for guest framebuffers.
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index ba9dbc7caf71..aa182a9dcdfa 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -103,21 +103,29 @@ static int mmap_udmabuf(struct dma_buf *buf, struct vm_area_struct *vma)
static int vmap_udmabuf(struct dma_buf *buf, struct iosys_map *map)
{
struct udmabuf *ubuf = buf->priv;
- struct page **pages;
+ unsigned long *pfns;
void *vaddr;
pgoff_t pg;
dma_resv_assert_held(buf->resv);
- pages = kvmalloc_array(ubuf->pagecount, sizeof(*pages), GFP_KERNEL);
- if (!pages)
+ /**
+ * HVO may free tail pages, so just use pfn to map each folio
+ * into vmalloc area.
+ */
+ pfns = kvmalloc_array(ubuf->pagecount, sizeof(*pfns), GFP_KERNEL);
+ if (!pfns)
return -ENOMEM;
- for (pg = 0; pg < ubuf->pagecount; pg++)
- pages[pg] = &ubuf->folios[pg]->page;
+ for (pg = 0; pg < ubuf->pagecount; pg++) {
+ unsigned long pfn = folio_pfn(ubuf->folios[pg]);
- vaddr = vm_map_ram(pages, ubuf->pagecount, -1);
- kvfree(pages);
+ pfn += ubuf->offsets[pg] >> PAGE_SHIFT;
+ pfns[pg] = pfn;
+ }
+
+ vaddr = vmap_pfn(pfns, ubuf->pagecount, PAGE_KERNEL);
+ kvfree(pfns);
if (!vaddr)
return -EINVAL;