Received: by 2002:a05:7412:7c14:b0:fa:6e18:a558 with SMTP id ii20csp350566rdb; Mon, 22 Jan 2024 06:17:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IHzxmnwnzP8fns5Ulg/QNqZpcbEabRfHa3oq+sxTRAbOw/HpCkgcgguBVdNLkiQVm9gJKrK X-Received: by 2002:a05:6e02:8e2:b0:361:a94f:7db2 with SMTP id n2-20020a056e0208e200b00361a94f7db2mr5586829ilt.4.1705933053029; Mon, 22 Jan 2024 06:17:33 -0800 (PST) Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id o29-20020a635d5d000000b0057760853706si8380138pgm.578.2024.01.22.06.17.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 06:17:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-33103-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=Z6nyTA1C; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-33103-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33103-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 943BFB25792 for ; Mon, 22 Jan 2024 13:41:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7BDF23D0BF; Mon, 22 Jan 2024 13:41:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Z6nyTA1C" Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2055.outbound.protection.outlook.com [40.107.244.55]) (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 AC0D13D0A0; Mon, 22 Jan 2024 13:41:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.55 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705930889; cv=fail; b=UH4g28Q/pqRVYugkxej8GXRWlbI3c86AwNYLqbIdWEpsIWBNWFiRXlCcW2svB64JAs6+D/i0aTCEKTuO9NoT0c3Vjr4+fuRjAoJwO1GLhSCTXVcYubjvyqNBpc2VTzEbHmggO5j5jEE2DjtbXLuOGa/P3182ZHa92/nHuBkwTBg= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705930889; c=relaxed/simple; bh=7UnPKYfA7kae8AZIaSzQlAXYXgZOYZLpqtd2/2bJ5CU=; h=Message-ID:Date:Subject:To:Cc:References:From:In-Reply-To: Content-Type:MIME-Version; b=FMty2JkLWzVm/UB6yYAidWDUYJ1Mg+imJhqRCfElviwHk9L/XCYgVLrXXvddB42AnOnxQM1xOmIilY9ZiiXoIGNNEm0q4b+UAtKj48ZmlAWdLgU3lPPYOdxfltyfo21EcAP0mpX+FfCuQcpBj4CqSZXyaNMkMmsPtGa+ao1Jm38= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=Z6nyTA1C; arc=fail smtp.client-ip=40.107.244.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MyJurin/nm60kD6kOf9GBDpmEHH1VFbtltGOB+Hgf/repmX5QFFejdNsJoNky/KjzSAWJx9JBhznvyysgUHkYyT8xGiaCxwjPigiU7Qgkgew/9x2kHtiMhY9Dv6V4gWXopMVHdXlSJfNfEAJlLWCQ9/GhHEy3EhzFWZsWQ2Rgq8fGJSELWkN2NQaDXyhB1dz9fRh9dtgRyIFQgFMCjvBvN0l6Qiqx+R+fUeHzCWoDqlLhFRnmC/HunpS6rrhgzjjjfpXSD+X0uzFKfFgWPs/QWQ2woQpe1NtPvI9FOPjdVv9EzEU/3veeGrGEBTSQbubw01veMpx0Xs861h1Y86Lzg== 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=e2/uND+PylRqEr8qzmxLFKHDrUvlITQ5CkViw7tP1Q0=; b=WLuXjFqUymwtYFA2vuXQJ9cF98jZAlsmENPfjeor4JZJNCZHkroGcTsPnl9V9esx0/037UAouiY1OCK6ue0LvAIOSTu6QqozCJzf2Z47yYTSgh3BcVuXHg16yHIOxgTCdYPzFhgEfaqywfzRfwAdR3n3Yn11PMR5huXJX7ydnBUyPC6u1zKn6ogi6kyE8jbZp5o0nWW2MqkxHzYJMSHAjF7LeQlv2XYLnGDNz6pQ4E3OXlW05TwCzHjdEGfmo7akthNHYTTY26wCuCcRkkE/+aJgHyCfUPC12g4lljik6XYejUIxF84yQKr/efwPV5+7N3UDff3YyBemunqWvzTNyQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=e2/uND+PylRqEr8qzmxLFKHDrUvlITQ5CkViw7tP1Q0=; b=Z6nyTA1CcFTlk8lGvi0oRYWNh273RCO6YsguN43OtCH0zv4abzOGfh3645H9P/nSwE+1pktsO6Cny0noX4CPzxsUn0qfS7Ouug4bAZV9sQ7h+HLDADk6JKKa7OXwyRH7d/SOwRKPuGRYylBZcOuV36KSq9C8+WKe+Rr24AQnyMc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from PH7PR12MB5685.namprd12.prod.outlook.com (2603:10b6:510:13c::22) by MW4PR12MB7213.namprd12.prod.outlook.com (2603:10b6:303:22a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.32; Mon, 22 Jan 2024 13:41:23 +0000 Received: from PH7PR12MB5685.namprd12.prod.outlook.com ([fe80::e1fb:4123:48b1:653]) by PH7PR12MB5685.namprd12.prod.outlook.com ([fe80::e1fb:4123:48b1:653%4]) with mapi id 15.20.7202.031; Mon, 22 Jan 2024 13:41:23 +0000 Message-ID: <0b6b8738-9ea3-44fa-a624-9297bd55778f@amd.com> Date: Mon, 22 Jan 2024 14:41:14 +0100 User-Agent: Mozilla Thunderbird Subject: Re: [Linaro-mm-sig] [PATCH v5 1/6] dma-buf: Add dma_buf_{begin,end}_access() Content-Language: en-US To: Paul Cercueil , =?UTF-8?Q?Christian_K=C3=B6nig?= , Greg Kroah-Hartman , Jonathan Corbet , Sumit Semwal Cc: Jonathan Cameron , =?UTF-8?Q?Nuno_S=C3=A1?= , Michael Hennerich , linux-usb@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org References: <20240119141402.44262-1-paul@crapouillou.net> <20240119141402.44262-2-paul@crapouillou.net> <8035f515-591f-4c87-bf0a-23d5705d9b1c@gmail.com> <442f69f31ece6d441f3dc41c3dfeb4dcf52c00b8.camel@crapouillou.net> From: =?UTF-8?Q?Christian_K=C3=B6nig?= In-Reply-To: <442f69f31ece6d441f3dc41c3dfeb4dcf52c00b8.camel@crapouillou.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: FR5P281CA0014.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:f2::7) To PH7PR12MB5685.namprd12.prod.outlook.com (2603:10b6:510:13c::22) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH7PR12MB5685:EE_|MW4PR12MB7213:EE_ X-MS-Office365-Filtering-Correlation-Id: 1332b9b8-ed1a-47a8-79fe-08dc1b4fd298 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: E/DFazMuZlCZO8kkNh5i26b8cm/YMhDofn1fwhnj3gml8L+xPxNk+oDwnH2DP7DlnfYvdvBRflj0z+2fYaBHfJxupybv5rZ71wAgiXVVfiFBU8ys4Opx89e1UPx178p1XH3rhvmgy8NntLaFRsYOY8OzSaWQxQT0BZXmZp4knmbbdcMJ7BmzMx6v8n8gDCOLisQKHbrXo0hNq4/J2tqyte2NlU1bkHEZ6PgEge+Yr1rGsz2wwlL08z701RpyomhdVy975uQub4fptSut/y4rfO0UUtmBuKq8tQuYMxQKhxK5vtBKTV4KY9v53GxuZoH6xPMVWcFKQuz1AsZgLRUS+brZxxaqR5Y/ch4TTdru25mFD5zIutWw7pZ/+B3wbDRAMP8CPoBrtuboqnVCMW4Bl3HeEY2fvW1Lo7X/PcbRkq5EPW9xOwWw6PBOEasDNvRzYrZKpyX0NlwmOhvb9US6a+xDYpgHT4ZQE2hLTExHbW/OEWPDp06w68vBmfVy05S8TfKQMJSvOl4OOKAlgC4TIjKg5ZMP4FuK4fOO6nSrQx/2/HWCv2vWAZaHqmuJSfie+KQ4m13USzTkASSWCzos2zBWgdgmz4uvJZiayOaSiOiEvV2sx8vdBjDlvqxlEVZR4Xj2N4zXpFgdeUM+HY8JAw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH7PR12MB5685.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(396003)(39860400002)(136003)(366004)(376002)(230922051799003)(1800799012)(186009)(64100799003)(451199024)(31686004)(2906002)(66946007)(54906003)(66556008)(66476007)(26005)(66574015)(110136005)(6666004)(8676002)(6486002)(6506007)(478600001)(4326008)(316002)(8936002)(6512007)(5660300002)(7416002)(2616005)(38100700002)(83380400001)(86362001)(31696002)(36756003)(41300700001)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?L3AwMXcva1BUaThCNC9GTVF1Z3RhQUdOc0pUdm1qMlBNRDZ4cWFmQlFFcTA2?= =?utf-8?B?aEZtY0NYazFNWHJpNSswelI3TDVEcGN2aUl3TWRBL1JIYlAzUHlGbXBFa2FU?= =?utf-8?B?SVFVcngvUHNYNzVXUXV3ejZOSjNSaDBvWWRGREtqRGdrQUVacXowT2lzdUdG?= =?utf-8?B?dzVjZlQvaTd4aFVSVnBZSlpkZGRkTlVtTzNDTmNSTEl6dW5DcjR5cXNBM0Rk?= =?utf-8?B?ZnlwWTNkTjVzZHpjZU9jSUtuclJscXlCN0M0Y0ZwMWxwZW5EMnVQUWF6dTRK?= =?utf-8?B?dnROZ1M2QkxOMzF5emV3TkRBcElMM3d5NzlmQWlYYjFaOWxZMW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B7WpbRgmWui8exUbubgi4eRoI?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1332b9b8-ed1a-47a8-79fe-08dc1b4fd298 X-MS-Exchange-CrossTenant-AuthSource: PH7PR12MB5685.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2024 13:41:23.2065 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: alu2sZLKakqmTHNNQh2RKjwubVmZ0W57sxMifsEKGJFkYTt2iux4BUKgvZinutSw X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7213 Am 22.01.24 um 12:01 schrieb Paul Cercueil: > Hi Christian, > > Le lundi 22 janvier 2024 à 11:35 +0100, Christian König a écrit : >> Am 19.01.24 um 15:13 schrieb Paul Cercueil: >>> These functions should be used by device drivers when they start >>> and >>> stop accessing the data of DMABUF. It allows DMABUF importers to >>> cache >>> the dma_buf_attachment while ensuring that the data they want to >>> access >>> is available for their device when the DMA transfers take place. >> As Daniel already noted as well this is a complete no-go from the >> DMA-buf design point of view. > What do you mean "as Daniel already noted"? It was him who suggested > this. Sorry, I haven't fully catched up to the discussion then. In general DMA-buf is build around the idea that the data can be accessed coherently by the involved devices. Having a begin/end of access for devices was brought up multiple times but so far rejected for good reasons. That an exporter has to call extra functions to access his own buffers is a complete no-go for the design since this forces exporters into doing extra steps for allowing importers to access their data. That in turn is pretty much un-testable unless you have every possible importer around while testing the exporter. Regards, Christian. > >> Regards, >> Christian. > Cheers, > -Paul > >>> Signed-off-by: Paul Cercueil >>> >>> --- >>> v5: New patch >>> --- >>>   drivers/dma-buf/dma-buf.c | 66 >>> +++++++++++++++++++++++++++++++++++++++ >>>   include/linux/dma-buf.h   | 37 ++++++++++++++++++++++ >>>   2 files changed, 103 insertions(+) >>> >>> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c >>> index 8fe5aa67b167..a8bab6c18fcd 100644 >>> --- a/drivers/dma-buf/dma-buf.c >>> +++ b/drivers/dma-buf/dma-buf.c >>> @@ -830,6 +830,8 @@ static struct sg_table * __map_dma_buf(struct >>> dma_buf_attachment *attach, >>>    *     - dma_buf_mmap() >>>    *     - dma_buf_begin_cpu_access() >>>    *     - dma_buf_end_cpu_access() >>> + *     - dma_buf_begin_access() >>> + *     - dma_buf_end_access() >>>    *     - dma_buf_map_attachment_unlocked() >>>    *     - dma_buf_unmap_attachment_unlocked() >>>    *     - dma_buf_vmap_unlocked() >>> @@ -1602,6 +1604,70 @@ void dma_buf_vunmap_unlocked(struct dma_buf >>> *dmabuf, struct iosys_map *map) >>>   } >>>   EXPORT_SYMBOL_NS_GPL(dma_buf_vunmap_unlocked, DMA_BUF); >>> >>> +/** >>> + * @dma_buf_begin_access - Call before any hardware access from/to >>> the DMABUF >>> + * @attach: [in] attachment used for hardware access >>> + * @sg_table: [in] scatterlist used for the DMA transfer >>> + * @direction:  [in]    direction of DMA transfer >>> + */ >>> +int dma_buf_begin_access(struct dma_buf_attachment *attach, >>> + struct sg_table *sgt, enum >>> dma_data_direction dir) >>> +{ >>> + struct dma_buf *dmabuf; >>> + bool cookie; >>> + int ret; >>> + >>> + if (WARN_ON(!attach)) >>> + return -EINVAL; >>> + >>> + dmabuf = attach->dmabuf; >>> + >>> + if (!dmabuf->ops->begin_access) >>> + return 0; >>> + >>> + cookie = dma_fence_begin_signalling(); >>> + ret = dmabuf->ops->begin_access(attach, sgt, dir); >>> + dma_fence_end_signalling(cookie); >>> + >>> + if (WARN_ON_ONCE(ret)) >>> + return ret; >>> + >>> + return 0; >>> +} >>> +EXPORT_SYMBOL_NS_GPL(dma_buf_begin_access, DMA_BUF); >>> + >>> +/** >>> + * @dma_buf_end_access - Call after any hardware access from/to >>> the DMABUF >>> + * @attach: [in] attachment used for hardware access >>> + * @sg_table: [in] scatterlist used for the DMA transfer >>> + * @direction:  [in]    direction of DMA transfer >>> + */ >>> +int dma_buf_end_access(struct dma_buf_attachment *attach, >>> +        struct sg_table *sgt, enum >>> dma_data_direction dir) >>> +{ >>> + struct dma_buf *dmabuf; >>> + bool cookie; >>> + int ret; >>> + >>> + if (WARN_ON(!attach)) >>> + return -EINVAL; >>> + >>> + dmabuf = attach->dmabuf; >>> + >>> + if (!dmabuf->ops->end_access) >>> + return 0; >>> + >>> + cookie = dma_fence_begin_signalling(); >>> + ret = dmabuf->ops->end_access(attach, sgt, dir); >>> + dma_fence_end_signalling(cookie); >>> + >>> + if (WARN_ON_ONCE(ret)) >>> + return ret; >>> + >>> + return 0; >>> +} >>> +EXPORT_SYMBOL_NS_GPL(dma_buf_end_access, DMA_BUF); >>> + >>>   #ifdef CONFIG_DEBUG_FS >>>   static int dma_buf_debug_show(struct seq_file *s, void *unused) >>>   { >>> diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h >>> index 8ff4add71f88..8ba612c7cc16 100644 >>> --- a/include/linux/dma-buf.h >>> +++ b/include/linux/dma-buf.h >>> @@ -246,6 +246,38 @@ struct dma_buf_ops { >>>    */ >>>    int (*end_cpu_access)(struct dma_buf *, enum >>> dma_data_direction); >>> >>> + /** >>> + * @begin_access: >>> + * >>> + * This is called from dma_buf_begin_access() when a >>> device driver >>> + * wants to access the data of the DMABUF. The exporter >>> can use this >>> + * to flush/sync the caches if needed. >>> + * >>> + * This callback is optional. >>> + * >>> + * Returns: >>> + * >>> + * 0 on success or a negative error code on failure. >>> + */ >>> + int (*begin_access)(struct dma_buf_attachment *, struct >>> sg_table *, >>> +     enum dma_data_direction); >>> + >>> + /** >>> + * @end_access: >>> + * >>> + * This is called from dma_buf_end_access() when a device >>> driver is >>> + * done accessing the data of the DMABUF. The exporter can >>> use this >>> + * to flush/sync the caches if needed. >>> + * >>> + * This callback is optional. >>> + * >>> + * Returns: >>> + * >>> + * 0 on success or a negative error code on failure. >>> + */ >>> + int (*end_access)(struct dma_buf_attachment *, struct >>> sg_table *, >>> +   enum dma_data_direction); >>> + >>>    /** >>>    * @mmap: >>>    * >>> @@ -606,6 +638,11 @@ void dma_buf_detach(struct dma_buf *dmabuf, >>>   int dma_buf_pin(struct dma_buf_attachment *attach); >>>   void dma_buf_unpin(struct dma_buf_attachment *attach); >>> >>> +int dma_buf_begin_access(struct dma_buf_attachment *attach, >>> + struct sg_table *sgt, enum >>> dma_data_direction dir); >>> +int dma_buf_end_access(struct dma_buf_attachment *attach, >>> +        struct sg_table *sgt, enum >>> dma_data_direction dir); >>> + >>>   struct dma_buf *dma_buf_export(const struct dma_buf_export_info >>> *exp_info); >>> >>>   int dma_buf_fd(struct dma_buf *dmabuf, int flags);