From patchwork Wed Sep 18 02:52:25 2024
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Patchwork-Submitter: Huan Yang
X-Patchwork-Id: 829520
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 5A205139D09;
Wed, 18 Sep 2024 02:53:01 +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=1726627983; cv=fail;
b=HcsVtNXNM8i8RBIprUWGtdLwY3YUzKaT1/O813p391940XiTl+j5viXxpXFIOzw2jz99HVLMqrt3oy6hCZGP6bsO1rlR3zGSqEcraEo7XHXIiBi5pB7SQd0PONkQJd7RiMxbAjgCni+IiYz8mnuQMflAfUaKsWWZLqo7Y13xIxY=
ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1726627983; c=relaxed/simple;
bh=/gKolQTMs38UCvE511ydGXd706sDH+pHUsomxv5mFh4=;
h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
Content-Type:MIME-Version;
b=h3lCPkxDYFosdNvfZu1Yyswf1CjXo3GauM0BZKTtPHuKfsMiJKQPt+Nt/8pCnEv7Ma4jmWL6cL43i5bRjkGuCkLMVR2lp04SE2BmaB+XLFgvHKfXb8jKvCDJ65m7ublMamawnJFFRQC+3+Kcsw5shtr3WoZYydS5GZjFziZEHjQ=
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=qu3JB8+I; 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="qu3JB8+I"
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
b=DGEM/L0/RWhtqKuRZsLPCn8v+bQCSAcpr6dsNLTmGn38nQW7dekz2guprbG3f+qepL99lUsZO29L9nioPwPBpzyD5AbM/W4+3E4yCY8MXoxPZtjHm/j0/RUn+FyXp6+YByk5L10GQEdgF3q4zzyiVYzf9Xu1jlAqHuXG/p2B2RhxrQtT9734/fC+RjfdmWIo/SozC2izsNaeNsPdtIDVUGSe/vA914Gop2Ti/qppy9f+XCW0APHDg4w1AZXSva92MEWG42WI5QtUKKsDFQfv1uMtVpWtxDoz/boUiM8F28RHceZxGfCeqrrIig9C3sEURfwDxRBy9AvuQz6kirWdxQ==
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=gMzgGgj3NgwLdKXnhpYPZxgFQlER0fazfsN7tOlr61Q=;
b=wt4yr2YWaZ4LTh56Mk1W3wInpTHU9tH/JI4wnVIDZMJlLWwfGm30RQFcx7tikdo9JOmQaGFEHE1NhDvxKoWIjJMMt5yEFulYO3cWeW+Ws7ule8YDs3nc01/sDS/7k7A9VB5qbLSAVWdAYDuMoceqV90TGaE0I2HCluG8g83faPa8GomibRnlrueQIN61Un9YwRLZZvTbqAjDm0Bzg4gi+6jOK42+UhaZUGEkDq5JsPfcAnCnE3Erl+ZIMD5j5Kw735dzkRpudmA9xQCu0iOtFTXFBoNR+aVQpaB1tUr9tzvoswsDihwg7yEY9bfdr8at2LFnflZp2WCrxF4zlemJ6Q==
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=gMzgGgj3NgwLdKXnhpYPZxgFQlER0fazfsN7tOlr61Q=;
b=qu3JB8+IOB8nsKkO4hrL7UIh2beXxefLGOu7tGm7jhCpA9Vu4eVb+5B5zUrr4ZSby8CnSsDFpedgu0DdW5i2e+D8pTGuZYHb9FTtHfuSZS6OcOnuulYxfchDmsEU3mkoRdYO+HbgQ3kmIVkFVVJLEmA9U88/cJb7L0INaorK5CIIvzrq7LwQHnwstrdaHS5kr3IJAYy5ROej0tG6UtpVZgR9yoJDv4QoeZ7U/omRyooB23vT7/LcVfUJqnIllPBApvuSXs5sxRXEVvbJPVBC/5fuIW5zi9f/zXHu8RQD/XP8mgPoL1t+NYcgXr9uFyFmOLabdN6EHPiQSFGnO8gzeA==
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:55 +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:55 +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 2/7] udmabuf: change folios array from kmalloc to kvmalloc
Date: Wed, 18 Sep 2024 10:52:25 +0800
Message-ID: <20240918025238.2957823-3-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: 5e083001-4293-478e-aff8-08dcd78cff1b
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: =?utf-8?q?9lKtJmuoPoy+zMPxerw0WIs8ka11icq?=
=?utf-8?q?EjhlvKo7XRLUeC2YLWk0zP1XgtFVPU0F+tnySm9/zazVlmoPAbCOYgyobigZC6pks?=
=?utf-8?q?LJEuIWUafG1Zqyj9S9RvvDxEgpsRJXXnYglf0LHbeT7Kn/iM/zgbS6QoWb/WBk6Sd?=
=?utf-8?q?04/oDSM4PEGA/Bzbc5W+tRdZCXAQNVxj3Fq2Lur/ruk9p/kN/cMmPP4bj8nDJuSOm?=
=?utf-8?q?WEXVb63sCryDV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8jMIYqhUpiucS3dJC2ShSDmuY3Bql1Co2ZgTkicACdzVCsRWrL0kYyQ8QmEQpr0?=
=?utf-8?q?cILyR/Q6wgOZdtItQ5HYrDt9q4oRUfdP0PBhKcWLIZyky7qEiJTqr/oScIVzHYAXK?=
=?utf-8?q?RBw/1ChK1bFLtKwBPBXukj7qV0fCKx/YxwNV/TvSllChWn5x0chNkO2SttmiZhqkj?=
=?utf-8?q?jgIi0PNM+ye4hawEfVcDdtHdoaKI9obBy+z8D/kU+SlFsGYw8mpR4LlUbt3B1pNlK?=
=?utf-8?q?qMEIlSzuNa9/7FRflmLZo0CxNcl1oYC8ZF8CUpIbn1K5KfkGGQcUPQ0=3D?=
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: =?utf-8?q?xrCEfFtv9ZQqLkrRD4vYFSEowYn8?=
=?utf-8?q?np7d8d0sSQ42H+SuYTb2MKtg08fQsLkBlpnNFI7pjHEaNJCxgvYOlZ7OqoUPfu6vK?=
=?utf-8?q?JxDHtsUbevpoGfGo6UtMIlqlvdzJDIYx8504CSxnZ+02WmRvwry1TlMOY3uiuBWgJ?=
=?utf-8?q?G/0nIEWk7iOKHqY82ACSH4UBpPMVpQxuvlzkx388cpDNZyetPlIfgov2aKe6kCeF6?=
=?utf-8?q?ErDpGhJ06CBBB+JJAe38U/Vt6PIzVZp1nsONP9l9IpNobv/T3gRsuqW9pWlX3l0FI?=
=?utf-8?q?8fRZzE5M9p+Vze4xH5mNEqk0yQx171FGQA5xt/M0v+t9ryW+k7n1JfUIWuAoMwIny?=
=?utf-8?q?3wpS6a0aOANECfaGO/TqBg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eenTz6RtYujk2kc+DtUiyutWQBSA1ZTzOcC+et2exn9tsQg7dJOyclNPUwIH?=
=?utf-8?q?c2VBzxcpMCvcOFoQcLViBr6rbs8FLascqfz3lKcr3EY6RZcrKhcpl9mSmll7kNtOp?=
=?utf-8?q?xt3GcUCCcKbWM2BXKceB2bm4iHiTtAS+BqMKzz938pU9XjgYs9rZ9XpD70zhcxt+4?=
=?utf-8?q?iFDAMrL1hwBWPM0KY8uddDPex22T32X/pKqL0j/XNTSlxtaQ2SsGQ3J3R9N705tdE?=
=?utf-8?q?Za+4TWQxhS8X9mtkLaQzu3/mlg94jdPvbyxkwpUS2N3zicdWMijbgGOgr/K+qduMq?=
=?utf-8?q?rzSn/rQ0NQIQ?=
X-OriginatorOrg: vivo.com
X-MS-Exchange-CrossTenant-Network-Message-Id: 5e083001-4293-478e-aff8-08dcd78cff1b
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:55.6766 (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: P2ifdxKyrXGDYjXMLPVSQ5QQeXMUOnuEayRGmkn6pZlTIVZG2UD4ol9wpfPkwSOatOz+gfD3tjHjToZPZcoCiw==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR06MB6236
When PAGE_SIZE 4096, MAX_PAGE_ORDER 10, 64bit machine,
page_alloc only support 4MB.
If above this, trigger this warn and return NULL.
udmabuf can change size limit, if change it to 3072(3GB), and then alloc
3GB udmabuf, will fail create.
[ 4080.876581] ------------[ cut here ]------------
[ 4080.876843] WARNING: CPU: 3 PID: 2015 at mm/page_alloc.c:4556 __alloc_pages+0x2c8/0x350
[ 4080.878839] RIP: 0010:__alloc_pages+0x2c8/0x350
[ 4080.879470] Call Trace:
[ 4080.879473]
[ 4080.879473] ? __alloc_pages+0x2c8/0x350
[ 4080.879475] ? __warn.cold+0x8e/0xe8
[ 4080.880647] ? __alloc_pages+0x2c8/0x350
[ 4080.880909] ? report_bug+0xff/0x140
[ 4080.881175] ? handle_bug+0x3c/0x80
[ 4080.881556] ? exc_invalid_op+0x17/0x70
[ 4080.881559] ? asm_exc_invalid_op+0x1a/0x20
[ 4080.882077] ? udmabuf_create+0x131/0x400
Because MAX_PAGE_ORDER, kmalloc can max alloc 4096 * (1 << 10), 4MB
memory, each array entry is pointer(8byte), so can save 524288 pages(2GB).
Further more, costly order(order 3) may not be guaranteed that it can be
applied for, due to fragmentation.
This patch change udmabuf array use kvmalloc_array, this can fallback
alloc into vmalloc, which can guarantee allocation for any size and does
not affect the performance of kmalloc allocations.
Signed-off-by: Huan Yang
Acked-by: Christian König
Acked-by: Vivek Kasireddy
---
drivers/dma-buf/udmabuf.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index 2170d975cc76..ba9dbc7caf71 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -109,7 +109,7 @@ static int vmap_udmabuf(struct dma_buf *buf, struct iosys_map *map)
dma_resv_assert_held(buf->resv);
- pages = kmalloc_array(ubuf->pagecount, sizeof(*pages), GFP_KERNEL);
+ pages = kvmalloc_array(ubuf->pagecount, sizeof(*pages), GFP_KERNEL);
if (!pages)
return -ENOMEM;
@@ -117,7 +117,7 @@ static int vmap_udmabuf(struct dma_buf *buf, struct iosys_map *map)
pages[pg] = &ubuf->folios[pg]->page;
vaddr = vm_map_ram(pages, ubuf->pagecount, -1);
- kfree(pages);
+ kvfree(pages);
if (!vaddr)
return -EINVAL;
@@ -225,8 +225,8 @@ static void release_udmabuf(struct dma_buf *buf)
put_sg_table(dev, ubuf->sg, DMA_BIDIRECTIONAL);
unpin_all_folios(&ubuf->unpin_list);
- kfree(ubuf->offsets);
- kfree(ubuf->folios);
+ kvfree(ubuf->offsets);
+ kvfree(ubuf->folios);
kfree(ubuf);
}
@@ -351,14 +351,14 @@ static long udmabuf_create(struct miscdevice *device,
if (!ubuf->pagecount)
goto err;
- ubuf->folios = kmalloc_array(ubuf->pagecount, sizeof(*ubuf->folios),
- GFP_KERNEL);
+ ubuf->folios = kvmalloc_array(ubuf->pagecount, sizeof(*ubuf->folios),
+ GFP_KERNEL);
if (!ubuf->folios) {
ret = -ENOMEM;
goto err;
}
- ubuf->offsets = kcalloc(ubuf->pagecount, sizeof(*ubuf->offsets),
- GFP_KERNEL);
+ ubuf->offsets = kvcalloc(ubuf->pagecount, sizeof(*ubuf->offsets),
+ GFP_KERNEL);
if (!ubuf->offsets) {
ret = -ENOMEM;
goto err;
@@ -372,7 +372,7 @@ static long udmabuf_create(struct miscdevice *device,
goto err;
pgcnt = list[i].size >> PAGE_SHIFT;
- folios = kmalloc_array(pgcnt, sizeof(*folios), GFP_KERNEL);
+ folios = kvmalloc_array(pgcnt, sizeof(*folios), GFP_KERNEL);
if (!folios) {
ret = -ENOMEM;
goto err;
@@ -382,7 +382,7 @@ static long udmabuf_create(struct miscdevice *device,
ret = memfd_pin_folios(memfd, list[i].offset, end,
folios, pgcnt, &pgoff);
if (ret <= 0) {
- kfree(folios);
+ kvfree(folios);
if (!ret)
ret = -EINVAL;
goto err;
@@ -411,7 +411,7 @@ static long udmabuf_create(struct miscdevice *device,
}
}
- kfree(folios);
+ kvfree(folios);
fput(memfd);
memfd = NULL;
}
@@ -427,8 +427,8 @@ static long udmabuf_create(struct miscdevice *device,
if (memfd)
fput(memfd);
unpin_all_folios(&ubuf->unpin_list);
- kfree(ubuf->offsets);
- kfree(ubuf->folios);
+ kvfree(ubuf->offsets);
+ kvfree(ubuf->folios);
kfree(ubuf);
return ret;
}