From patchwork Mon Sep 9 09:18:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Huan Yang X-Patchwork-Id: 13796499 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2069.outbound.protection.outlook.com [40.107.255.69]) (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 23A4654673; Mon, 9 Sep 2024 09:19:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.255.69 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725873553; cv=fail; b=M3LbRXZY6dG6Iw8wXYtQ6JOolZvKJpVdbT7jilMzb/3tKPM4BARe1QKMiALZoSE21PtQIIGZodpMBr2JuqcrR/2O6kXFqT4uhEhsGkj1I3Zy9z6llBGW7pmUMnjPzAVCLyZWQoKomlFV4Gyw7HUVuhvW6qVMAhHBpyxCicQkzCY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725873553; c=relaxed/simple; bh=sAukEkM+/E8tpEnAOPZeDaL9Axn/bZ4m1fOKrxh8aGQ=; h=From:To:Cc:Subject:Date:Message-ID:Content-Type:MIME-Version; b=Qra/I8A3gEHcUTlW4X0E93C+HvsPW8VlWmr16BsaTOhggpMBT8UsLQ6i2xFFyqAdnYiUspmOUhqGXJMKEI/IFNAtQ8fD5gZeIdtRHlOVJ/0VSwMKKPWAEqiL4cCcX05rM6TlS/3NEgVg2wnEpZfr7oqgr2SweW5wOgK+0gmWEn0= 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=nJg+gNv7; arc=fail smtp.client-ip=40.107.255.69 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="nJg+gNv7" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PmJ7oQ5glLOYLbnX5sUr28Llpl+g2ck0WbNTeV9UjjCq5CrDxWEMR0aIxB3svbY1pRh2jV8WM/qybvKHQOo4++hq8rRF1w3HRVPj6f+lYcw0GjCm4r5/6xn2Hv9HtSRpCd0iDBVl5smMuogEb7X6e6QaBAhb/9FUH6adeAxc0MbZurVJcfAS5qk59ff2McVEaWtag77SLdfm22VFIZVS7t0UoMxqigAslsx7gIkAB2ADywzvrNwS+Jn1lmQxfi1ymFpIrVSi8fwefZj41hvJrCIPZcKmU/+I6TkP0KrGYYhBX8lB8zMmBxAhHnPTza53pdRkwQ16g7dVoA9zYeqPFg== 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=82eGfnCbo8KkdrPCLtzYYdJ3/a5cBJrrBEqwde4qPso=; b=fyQxOWluupoCeWtxGEYlei1+X+dXhWhXiV3mFPZe1JvA9N9BV7Yzq8oz5oLzEuv1+EE+AZBwrV4dDABs67nWkrHL+IKd8MnB2B1Mtp5GzT8ROoFhDCAHLESKf6nVTT2X3lUydTYUca9QcKpjsNA7+R8KZrBZZz0FCxzVKNFLQFyuW+KQS7B9fYC0moKO1rcGEkjmwqgggkTErN82AalzZ1ENC0y+JzSCYHPAfNpG659ufdxSibF6G4jln+0s6Q4f3oPMkFS6pXHBpm/9uod6cjKP8gVAAqnHhylqA+OGIlLdPV0w8S+2Ghy6Hi/nHIlnS32OVup0ZgP5MoUTp51rdw== 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=82eGfnCbo8KkdrPCLtzYYdJ3/a5cBJrrBEqwde4qPso=; b=nJg+gNv7IZPWRaBmdPdmoDdKJKuzWlPlO9g8KvdYei3xNQjX7OATf7a28FVHiF9JM16iWEij/Pvvt/whlVt0IYnPocwZJP4gWK7EwzbBr3dBbxlI6abRf84M/OAyhf23jVAcN1ui+5lEwQ07+RIEPFsBg6FMlrT2iciTnb9CaEU5RfIW+/RiuSkOIDR14+TzzjuPzREc1bsok4cMxvbODBKv4rQsZZ7UZMOoibixUcY3AEPvynb3CpqI6o59gwyOMQWTe18OxHsYsVQBrugkJKATh4PiSg5s/saeTWPSL3JIvrDyRITcfx3MCPIyrg0yIltnhOsjXPLBfjQ7eEnyFg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from PUZPR06MB5676.apcprd06.prod.outlook.com (2603:1096:301:f8::10) by JH0PR06MB7180.apcprd06.prod.outlook.com (2603:1096:990:98::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27; Mon, 9 Sep 2024 09:19:06 +0000 Received: from PUZPR06MB5676.apcprd06.prod.outlook.com ([fe80::a00b:f422:ac44:636f]) by PUZPR06MB5676.apcprd06.prod.outlook.com ([fe80::a00b:f422:ac44:636f%6]) with mapi id 15.20.7939.017; Mon, 9 Sep 2024 09:19:06 +0000 From: Huan Yang To: vivek.kasireddy@intel.com, Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , Gerd Hoffmann , 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 v6 0/7] udmabuf bug fix and some improvements Date: Mon, 9 Sep 2024 17:18:38 +0800 Message-ID: <20240909091851.1165742-1-link@vivo.com> X-Mailer: git-send-email 2.45.2 X-ClientProxiedBy: SI1PR02CA0011.apcprd02.prod.outlook.com (2603:1096:4:1f7::19) To PUZPR06MB5676.apcprd06.prod.outlook.com (2603:1096:301:f8::10) 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: PUZPR06MB5676:EE_|JH0PR06MB7180:EE_ X-MS-Office365-Filtering-Correlation-Id: 4230fead-4628-4670-7f02-08dcd0b07411 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|52116014|376014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?oD9Q/KcfLaI+xaG4xE4teILkCV+YJVm?= =?utf-8?q?LBPHTaaTy8qrupkYzh2jVRvQiQNIq4Tvltg70QbPRF7GDIDaQGNzdGScwe8nI4ArZ?= =?utf-8?q?omM1vr2BkYgGiq/zES6T95rfKD2JDOsQFx1gfLUIiqAeG9o9seSfppw3vaFH+ql8F?= =?utf-8?q?CKNb6vfTPgNqOinPLxc9dJ6KGVzi0sisdeVY9O9eci2YQRp1dTQ7lgbzATiOZdRXz?= =?utf-8?q?amBUhUQ7COYUKQu1Q1rKXU6bhqwMKimVuvfhibQ14L901sgzsPC0GmJQpp7AOnZ8b?= =?utf-8?q?NLJc2EIk2om7FBGO4EGPC/4cwY281Jao7phxzZN6GeuXEhSIGwQqRVWmbHrQR6CIn?= =?utf-8?q?W1Gk6QqtUln18KJa7pcqLf6CEK/l7/r1Uhk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2tb2WsAhlrpPvTALEfavmZ0zcDcoZo6?= =?utf-8?q?5zKtp8c83RmslX7/I//skVlMIiuJKcjhZWZEgPnBFXM5Mb45Pli6dUBd1vjt4xEYR?= =?utf-8?q?1kvBxyAnfKcy724YDLlXC20VBJjSUy+iVQ=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR06MB5676.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(52116014)(376014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Ti9+M1/SLJ1upQbZhMff+rRGemy2?= =?utf-8?q?N8ZZckCMeYR9sIvqSXyBuX1wO8y7ko+ybgW/I1gmaX+va2vr/uOlFd4W6NRrwPPLx?= =?utf-8?q?f5EDQu3GKrGV8wf6BhsBpEr8C1zxapEXar1qK/84tXtmW3SEebowt0/Gu8Gcd+zp4?= =?utf-8?q?DYD+fxIv7OZSQbqNAJmCbQejng3kZy/Fg4k758gbfSYV2PHqIlEja2tryuCtKlWOo?= =?utf-8?q?W5I2vxcnfajgGNsYuro31526vqjwsc6/KL5V0OIVrQbFr1+oSrnD/TczzbDtL0H1b?= =?utf-8?q?dlkpptx8HG2lb4Tzcorzaa4YV1vsSG7ZroGq5e5QSjWon0ADWEhYHa/bTpV4mHppl?= =?utf-8?q?iznU79x6pwnYiiqRqMAc0Vj4cFaBGHlz4Ke3+Hz2YLjjbHKSfwU+05ryTbCQHDJcT?= =?utf-8?q?S3u/uolfUyMjejrnlaAjACV3I/4F8OKlYoXwhOe0arOxkeem8N1eJzP+BD8/1MB1G?= =?utf-8?q?zh6DpNtxe56TBstLMmqz1R8wJpqAen+TMwAfUjXj77isoVaQjqZPqfbW4BWKS7I/X?= =?utf-8?q?7PwSqg/fYPm2fmG1hZc28d52LYOqFQTUH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4DNQQMFXBiJG/oCy/PSgSbam?= =?utf-8?q?RBa4ZTvcmE7LLDS3NqWHjUM5YqFPX4Q3AhBvS1G85A52gNaXgDxtUPKjEGt1Tv9oZ?= =?utf-8?q?FQa/D8fdY1AO?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4230fead-4628-4670-7f02-08dcd0b07411 X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2024 09:19:06.2222 (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: /UpAnwgNq7e01R/iF+s1Qfuc1KNslZY3SLw+XbOvBxYpCNueKjn66Maj/mMi88tpiIpTeDBfKqhGnuoEmE0w5g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: JH0PR06MB7180 This patchset attempts to fix some errors in udmabuf and remove the upin_list structure, also try clean up code. By this patchset, udmabuf remove page struct relay, only use pfn and folios. Some of this fix just gather the patches which I upload before. Any patch has passed the udmabuf self-test suite's tests. Suggested by Kasireddy, Vivek Patch6 modified the unpin function, therefore running the udmabuf self-test program in a loop did not reveal any memory leaks. Notice: Test item 6 maybe requires running the command: echo 1024 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages Changelog === v5 -> v6: Patch1 use Vivek's comments(thank you), fix code style, update ack-tag. Patch2, 3 no change. Patch4 fix memfd miss fput, use Vivek's comments(thank you), fix code style, update suggested-by. Patch5 update ack-tag, fix error word in commit message. Patch6 update ack-tag, use xmas style. Patch7 update ack-tag, remove unused ret variable. --- v4 -> v5: Patch1 doc why pre-fault failed not report error. Patch2 no change Patch3 update ack tag marked in v4 Patch4 split some change into patch5 and patch7, this only contains udmabuf pin folio's function Patch5 add helper init/deini to clean udmabuf struct initialized Patch6 remove unnecessary code Patch7 remove reuse folio remove v4 patch4 --- v3 -> v4: Patch1 fill vma area with pfn only when true access. Patch2 no change Patch3 select VMAP_PFN Patch4 use function pin each item. Patch5 use pinned folio array instead udmabuf_folio struct. --- v2 -> v3: Patch1, avoid use page, instead, use pfn, and use vmf_insert_pfn map suggested-by Kasireddy, Vivek Patch2, update acked-by Kasireddy, Vivek And keep the kvcalloc on the same line. Patch3, avoid use page, instead, use pfn, then use vmap_pfn map Patch4, split v2 patch4, single update codestyle to keep review easy. Patch5, another way to remove udmabuf_folio --- v1 -> v2: Patch1, 3 Rectify the improper use of the sg table. suggested-by Christian König Patch2 add acked-by Christian K�nig which marked in v1 Patch4 Modify the data structure to restore the use of pages and correct the misunderstanding of loop conditions such as "pgcnt". make sure pass self test. remove v1's patch4 v5 https://lore.kernel.org/all/20240903083818.3071759-1-link@vivo.com/ v4 https://lore.kernel.org/all/20240822084342.1574914-1-link@vivo.com/ v3 https://lore.kernel.org/all/20240813090518.3252469-1-link@vivo.com/ v2 https://lore.kernel.org/all/20240805032550.3912454-1-link@vivo.com/ v1 https://lore.kernel.org/all/20240801104512.4056860-1-link@vivo.com/ Huan Yang (7): udmabuf: pre-fault when first page fault udmabuf: change folios array from kmalloc to kvmalloc udmabuf: fix vmap_udmabuf error page set udmabuf: udmabuf_create pin folio codestyle cleanup udmabuf: introduce udmabuf init and deinit helper udmabuf: remove udmabuf_folio udmabuf: reuse folio array when pin folios drivers/dma-buf/Kconfig | 1 + drivers/dma-buf/udmabuf.c | 272 +++++++++++++++++++++++--------------- 2 files changed, 169 insertions(+), 104 deletions(-) base-commit: ad40aff1edffeccc412cde93894196dca7bc739e