From patchwork Mon Jun 3 11:40:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hailong Liu X-Patchwork-Id: 102161 Received: from am.mirrors.kernel.org ([147.75.80.249]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1sE63g-0005bS-1r for patchwork@linuxtv.org; Mon, 03 Jun 2024 11:41:02 +0000 Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 18DEF1F25D70 for ; Mon, 3 Jun 2024 11:40:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2022284D23; Mon, 3 Jun 2024 11:40:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=oppo.com header.i=@oppo.com header.b="Q/DFzWx5" X-Original-To: linux-media@vger.kernel.org Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2068.outbound.protection.outlook.com [40.107.255.68]) (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 B934B84D05; Mon, 3 Jun 2024 11:40:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.255.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717414852; cv=fail; b=B0AJdcmIwEJTKqkL5iLGxM8KqvABc9wIz9IICiN5UBvIfdWeAssEsabW3FQH6hXRiQdWC1G0QAtLdAxh2mmwrnQxWe5Y9nomWq/V/0VD8KSNq9EKe73czcxXlpWUk+2E0HL+kdIoLf6z68UfnEPl9p/seKZXKAUb/VUUK4Oh38s= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717414852; c=relaxed/simple; bh=VWQXlrWaqgeWJGNJEQGyrWGp5OBw+8/CihEgW72KAz4=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=ShqrdDxPecjpB/umzCqc9ylLLkXhwhlZIaS2b1QHyJRONaXRkvcTmTwso+pBpZu6IDIflZ1XVPi/ER2rSMMmG1ONyevZWcw5A09yDy09cPuStIBiofrb7sd6YEz8ntEXJj+o+l0+J9bDOpdfT/j9kUBkc8CkV2jd+9ntkl41SlE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oppo.com; spf=pass smtp.mailfrom=oppo.com; dkim=pass (1024-bit key) header.d=oppo.com header.i=@oppo.com header.b=Q/DFzWx5; arc=fail smtp.client-ip=40.107.255.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oppo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oppo.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ReHEXSbxPFaj32VjD0sHxhn8+d/MfQniPC1YN6ycckO/K/OEiWTb4ulgRLGx6InKHs7Df9m1CpCzrr6fwpamT6qndDKEsST5jj8M8mYQzvZlfgSrxS3nTM2h+urmwUDujOwnFs575Mx4FEtWwJIbfjITO08QFEDY/9qP99/po+ZUScJlqHQ6PvfWgnP9L8F3O/FQx8+lvo8hATcnAHmbPuE5G7tHPlGMUc63B4Y5coHTmiwA2XaFrTnMwlqNQWHflf6aTbFek+6GxaQkqbU+TF9U9wx9vTp5YNxIJ6q9GVrodZwUOjaO79/ABt+j+WAFj6ecRAMI2o84N850CF5Akg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=yoIM7lC3W2CmzRv5ldHqXT4NLmee7//rWVqgOuxoapU=; b=Jn15r9SryYqAxsdKhMpvALdBExiIthl5c33WVxb1sPy1iESS04xLXbtZO1KWXgk4XDlffdMY28jomNx/Lv4f9ji468zGQl6yMAiOM+46mTD8kVEz+nbcGY+82t4cD02EEJtj3ZyzFuNpTbcVKHz9sVYK5x3IbTsecarccnygVTCgnBl55tyWbSWdrl5iL+iLQzk62oMbKsFPvzD2Ulwsekdhm71PcLvnMnISW1gvIwnBLLlSOerM0lfwLOybLezJpWKewrFmqfxfvr9jfrXYAHm5mXFapY/Mxphpt0EhWj0jO7PJhteYfCgUilbcJrrXgboTyJ2ru/jclq9OS/f7QQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 58.252.5.68) smtp.rcpttodomain=linaro.org smtp.mailfrom=oppo.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=oppo.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yoIM7lC3W2CmzRv5ldHqXT4NLmee7//rWVqgOuxoapU=; b=Q/DFzWx5bafjt7/E5pgCq7hcJYc0Dy/FvJe2pjgmDvQzqPkMyJ9Pm3Il9K3RNuHejcR4bUsfO0VyqKT54T6aUGEMWcQ6cq5i4WTTnlV2yMuYz0irHWlkor3g/7kGDTfcf8Fgw7dZiFJhB/LiwvzLCDq8mydg7WvgvFv6musvTgs= Received: from SG2PR01CA0134.apcprd01.prod.exchangelabs.com (2603:1096:4:8f::14) by TY0PR02MB6803.apcprd02.prod.outlook.com (2603:1096:405:b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.23; Mon, 3 Jun 2024 11:40:47 +0000 Received: from SG2PEPF000B66D0.apcprd03.prod.outlook.com (2603:1096:4:8f:cafe::60) by SG2PR01CA0134.outlook.office365.com (2603:1096:4:8f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.29 via Frontend Transport; Mon, 3 Jun 2024 11:40:47 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 58.252.5.68) smtp.mailfrom=oppo.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=oppo.com; Received-SPF: Pass (protection.outlook.com: domain of oppo.com designates 58.252.5.68 as permitted sender) receiver=protection.outlook.com; client-ip=58.252.5.68; helo=mail.oppo.com; pr=C Received: from mail.oppo.com (58.252.5.68) by SG2PEPF000B66D0.mail.protection.outlook.com (10.167.240.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Mon, 3 Jun 2024 11:40:46 +0000 Received: from PH80250894.adc.com (172.16.40.118) by mailappw31.adc.com (172.16.56.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 3 Jun 2024 19:40:46 +0800 From: To: Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= CC: <21cnbao@gmail.com>, Hailong.Liu , , , , Subject: [RFC PATCH v1] dma-buf: heaps: move the verification of heap_flags to the corresponding heap Date: Mon, 3 Jun 2024 19:40:05 +0800 Message-ID: <20240603114008.16235-1-hailong.liu@oppo.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: mailappw31.adc.com (172.16.56.198) To mailappw31.adc.com (172.16.56.198) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SG2PEPF000B66D0:EE_|TY0PR02MB6803:EE_ X-MS-Office365-Filtering-Correlation-Id: 586d08e1-1f6f-4a70-f977-08dc83c2029d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|376005|1800799015|36860700004|82310400017; X-Microsoft-Antispam-Message-Info: =?utf-8?q?AgVuV+1NbMK0sdGnbqwjVGvePgkefL0?= =?utf-8?q?qnUPnuCBIirYKtmy6AwlxQKrVF2yUgpP3Y11xLgUB7uQU2Tx9CjKuUvPmbcj+gmSp?= =?utf-8?q?8QkkJTRmtNjpqie44haIXpJd2uUQs9HPNuhxq0+RF2IyendV4EtwLlWLQX0ZC5Jy8?= =?utf-8?q?158SfoYahm4Yqo/rg09gCvV7AKDj/vOs7Fs7//hywCLe656L6OPmpKvmCU2K8Ves/?= =?utf-8?q?10HRVpFMgCSofjKJ88wsZ2otAtWkC28yOXKColxVlaBZSk36nrNB6X0JUoKbfJ+kw?= =?utf-8?q?imFovbhl6IlWk7gPAQj+PXF/aPBaEkOwFAwqi4A+zYh9fe1D4fkYH7gds4C+8apD+?= =?utf-8?q?aTm8HJUdBI7d5ExN9HA/UmpWnO2wiBmsO8rLyGOxLGCMjQleGqzCDwjCj6XKXddpS?= =?utf-8?q?jEDJQigyJU6Y7fT64MJFCzShERapTP4v+UZghm95hYtIRVOjmAsc22roEi/gR1/Ku?= =?utf-8?q?qaCNjb0ncuDskI8SqOwaRS23aJvT7kjnya20U+Qp008Nw2EeBZviIu45hf7Pc1F7f?= =?utf-8?q?btpJ9alQOiqyJL+MLA598EQW/wsbfFgQjVKbBcmzFA1q+SS9jcw3BzPEtEGSmERHx?= =?utf-8?q?v+JYtEN1oRcEj78QnFTjQAOUfoTJ2fBgzlQSjikf493gtwAR9zHkVNAFhHiud25vb?= =?utf-8?q?zYXw0dYKb8ihiKfPowSlMQg52CaTWNeUr0LB7WzWQd5LifmaxzxetDHvmK+mlGxUZ?= =?utf-8?q?5MeKCutzFrlPOhv7vyYaB72PeVf10dDaAql8uJcJ29o5KsX/QcwaP7wEsKLKCczdn?= =?utf-8?q?PgW8v5PhUJFvGZQCEgrhhVaE/N5dnjAI5+R09yfIVGA3SElZN/DNi5n3dAgWZoqmY?= =?utf-8?q?4S3ytwEiZHK4sBxQii6robp+8vu5s7s8KPrnYBLPr3shTbIGru0x+lcdMflWqD9eh?= =?utf-8?q?gZ/1vIqJDVUhiV1n07BthoJhOO4RB0+AKqeHFopx+4L5LoZvSwBDnqsG9nw6ZdpO2?= =?utf-8?q?Z1l0qQp9NkXy6i+B13moCtI/F1YWG6cv+suIP4DnHum7+pPMg0eHr0gAjjozFlLuR?= =?utf-8?q?aCkQIDrzOskDlmewVxw0C4sD0WqdEsBdcH9evxsVc/rIcOGDEl1oPzXdn/i6ur+Dk?= =?utf-8?q?9kUPhxJuLwhbJE3taCkTerylbKqEakbly4tIx2Y2ulP+FJ+jolysZsmZYu44lkdtT?= =?utf-8?q?azkZxahWIo2MOtz9YHSNzdyZcd4Qd83yhAs1UGSZg0yjITslkjmtKh32TOe+jQZnI?= =?utf-8?q?sJQdAIqWiHla50Q79Solm/po/wGN1chRPAW63SIU0X2vJcTEfNu6ILEgCE8t/tZUn?= =?utf-8?q?4L0j1lhZswCB88Lsn30/bvDUYjiiTlDWXPDFfr7+t3ye0M1BBkJTbau0pOVqj9eo7?= =?utf-8?q?zoKTe01c9Hr9?= X-Forefront-Antispam-Report: CIP:58.252.5.68;CTRY:CN;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.oppo.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(7416005)(376005)(1800799015)(36860700004)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jun 2024 11:40:46.9475 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 586d08e1-1f6f-4a70-f977-08dc83c2029d X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f1905eb1-c353-41c5-9516-62b4a54b5ee6;Ip=[58.252.5.68];Helo=[mail.oppo.com] X-MS-Exchange-CrossTenant-AuthSource: SG2PEPF000B66D0.apcprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY0PR02MB6803 X-LSpam-Score: -2.6 (--) X-LSpam-Report: No, score=-2.6 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_PASS=-0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,SPF_HELO_NONE=0.001,SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no From: "Hailong.Liu" This help module use heap_flags to determine the type of dma-buf, so that some mechanisms can be used to speed up allocation, such as memory_pool, to optimize the allocation time of dma-buf. Signed-off-by: Hailong.Liu --- drivers/dma-buf/dma-heap.c | 3 --- drivers/dma-buf/heaps/cma_heap.c | 3 +++ drivers/dma-buf/heaps/system_heap.c | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) --- In fact, there are many differences between the main Linux code and Android code, I’m not sure if it’s appropriate to submit here. -- 2.34.1 diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c index 84ae708fafe7..6c78ee6c7a58 100644 --- a/drivers/dma-buf/dma-heap.c +++ b/drivers/dma-buf/dma-heap.c @@ -105,9 +105,6 @@ static long dma_heap_ioctl_allocate(struct file *file, void *data) if (heap_allocation->fd_flags & ~DMA_HEAP_VALID_FD_FLAGS) return -EINVAL; - if (heap_allocation->heap_flags & ~DMA_HEAP_VALID_HEAP_FLAGS) - return -EINVAL; - fd = dma_heap_buffer_alloc(heap, heap_allocation->len, heap_allocation->fd_flags, heap_allocation->heap_flags); diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c index 4a63567e93ba..ae4fa974372b 100644 --- a/drivers/dma-buf/heaps/cma_heap.c +++ b/drivers/dma-buf/heaps/cma_heap.c @@ -288,6 +288,9 @@ static struct dma_buf *cma_heap_allocate(struct dma_heap *heap, int ret = -ENOMEM; pgoff_t pg; + if (heap_flags & ~DMA_HEAP_VALID_HEAP_FLAGS) + return ERR_PTR(-EINVAL); + buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); if (!buffer) return ERR_PTR(-ENOMEM); diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c index 9076d47ed2ef..80858719a819 100644 --- a/drivers/dma-buf/heaps/system_heap.c +++ b/drivers/dma-buf/heaps/system_heap.c @@ -347,6 +347,9 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap, struct page *page, *tmp_page; int i, ret = -ENOMEM; + if (heap_flags & ~DMA_HEAP_VALID_HEAP_FLAGS) + return ERR_PTR(-EINVAL); + buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); if (!buffer) return ERR_PTR(-ENOMEM);