Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp730289lqe; Sun, 7 Apr 2024 00:50:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVlwKfsVycn699H6kvagnXRK4GS7EFUzbE9Zqm+GlETxaUmQMyryCQKruEtCDjhIiRo21FDuWHqNPkFrRTHqBk7KHLmKSH46jqyoAOuhw== X-Google-Smtp-Source: AGHT+IE3G+o2COTvNy1AS9ENN7Kn5ao8swoAimQgJO53yhxSMf54s+pToBs4W/HNO5Dxx4ILLXWo X-Received: by 2002:a05:620a:2811:b0:78d:5ea3:e750 with SMTP id f17-20020a05620a281100b0078d5ea3e750mr2770418qkp.58.1712476230701; Sun, 07 Apr 2024 00:50:30 -0700 (PDT) Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id yf1-20020a05620a3bc100b00789f57caff0si5661876qkn.199.2024.04.07.00.50.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 00:50:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-134229-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b="hd59/J9d"; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-134229-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134229-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 3A7801C20357 for ; Sun, 7 Apr 2024 07:50:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0BED4101F7; Sun, 7 Apr 2024 07:50:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b="hd59/J9d" Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2122.outbound.protection.outlook.com [40.107.117.122]) (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 317037484; Sun, 7 Apr 2024 07:50:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.117.122 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712476220; cv=fail; b=jzAuwJfKT0sdGLjj6xhrdVEQ2sYIYFv05vOANd/8IwZjXVazsIWeM2ww+MuN/Bac0+mg1bttVCPrQmGOhgnPRh0hiTGrY4h1OItPca+BvquQ+I6ISrt7tN9Z6+ObnNnpsXUML4Gw7IZS+7vhEkzY/bOMov/MriaJrsqjhvyHpOI= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712476220; c=relaxed/simple; bh=HoClI9pNwEEyQQBoIxDaVCQugvVlJnL8U39VT+plqLg=; h=Message-ID:Date:Subject:To:Cc:References:From:In-Reply-To: Content-Type:MIME-Version; b=nGp/R3RDh0kTJooPZBlcj+EVXBASsur4xpnFYSYTLSHkC9mSEoA5vReVvukAU8K62u4QBUladsbR7TKm6PHuIb07bBn/ElPPqsD0h2elnJdNrvdHaDqyM1Zgc0yxOFsp8kA6fFMT5C2yNJhDRixLLWBwxWnitNPAnGwjMxEuD00= 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=hd59/J9d; arc=fail smtp.client-ip=40.107.117.122 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 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D2PEeAxzyCJLYJ5ZP+XCvdLv+TptfSdlrn7y12xoMNNDXJKReFvUSpy4QmP5zHN6wwSHXr0Gl5jPXcDkLAnQ7pX/HtO5Q6IcLXFwPphM8qLPu+9DE7ElEVS3xZpT8amBerVJLtvaG7PsFn6AXPnfznx58/Xz4wtYOAX8wcatiJ3ydqhzCVG8lSQ8DQT2AG7OA9X2qI6Kk0l+4KcszsUBfX1Swg2rGkaLuXeGvUM7X6UWTYuw6I4t3Td2s4x/ubIhnh/RtyWtSq7iQs+YxnZw2ik8x+nsm7EhSXl3HQewODOy4CePl/yhAh704JRsiSEZvnHoG9dRthnBNPXkdRDJMw== 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=KRIBZRHZZk7GVwQBNGmJ2/2xp/a4WyzEvW1+6hfqUuA=; b=MgEPi+H9IbTH10OLk1Dy5bKplmPiQz20VnnD0FTnum5FcKNHyB7haxrpBnyv5QT9U608h6YvlYWqFlHOQQdlCrJoRnBqpKueSXVuP7hRFvZGS1z/OvHMe/V+Ch3Zq49VI8VfxgiM2BHG78sskUz1dHeACWdPxwzA5LOjVJRa4vAUCbQT/vmUylBaSKtnpeMKekoOVjIC9zfon26Yqyob7FDVxK4JehXtAUt4rIyyozulT4rCKUzOjm0yK1w7+leaA1vLvj7s3bnFF0YgfNwXuYbhS3wNYtwYP3NigQuLXtvzh0N0Zbi6BmIGpt4p8cLvdq0stmT1fuAU64ImmU2kcw== 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=KRIBZRHZZk7GVwQBNGmJ2/2xp/a4WyzEvW1+6hfqUuA=; b=hd59/J9dYV1u3BJtYiRIQj36mkv9ozZYYzW1CkJcdrgsHys1enoKeOx84ONBZmVk+P+7R7Pd5H3C3HNSbOgj/x41E/uRNWucOhJJWfX4sbDDEjR0TtTzI9/6E+jSROjzQLZavFsOsSuT0i1i8pEPBlhMw2K9Xi1ubhOjSkij+DWk7rGywKxBdu5gdnfxzvjv0n0AUxsRbyFGPR96GMmsr/VFpLCmTVMIg3YwBaUNBR+Bpp6j9aFu+whJffvHUXgUpgtCal3vPQJTKTiBRQwyGLsY0dkXKYG+7klnm6ntdqFfcHu1WLY0UbQ83i6Fx758YtiTihppU0uE7VkOtRpYsg== Received: from SI2PR06MB5140.apcprd06.prod.outlook.com (2603:1096:4:1af::9) by JH0PR06MB7353.apcprd06.prod.outlook.com (2603:1096:990:a5::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Sun, 7 Apr 2024 07:50:13 +0000 Received: from SI2PR06MB5140.apcprd06.prod.outlook.com ([fe80::a60c:298:c201:e4a1]) by SI2PR06MB5140.apcprd06.prod.outlook.com ([fe80::a60c:298:c201:e4a1%3]) with mapi id 15.20.7409.042; Sun, 7 Apr 2024 07:50:13 +0000 Message-ID: <3175d41a-fc44-4741-91ac-005c8f21abb8@vivo.com> Date: Sun, 7 Apr 2024 15:50:10 +0800 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] dma-buf: add DMA_BUF_IOCTL_SYNC_PARTIAL support Content-Language: en-US To: =?UTF-8?Q?Christian_K=C3=B6nig?= , Jianqun Xu , sumit.semwal@linaro.org Cc: pekka.paalanen@collabora.com, daniel.vetter@ffwll.ch, jason@jlekstrand.net, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org References: <20211113062222.3743909-1-jay.xu@rock-chips.com> <1da5cdf0-ccb8-3740-cf96-794c4d5b2eb4@amd.com> From: Rong Qianfeng In-Reply-To: <1da5cdf0-ccb8-3740-cf96-794c4d5b2eb4@amd.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: SG2PR02CA0014.apcprd02.prod.outlook.com (2603:1096:3:17::26) To SI2PR06MB5140.apcprd06.prod.outlook.com (2603:1096:4:1af::9) 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: SI2PR06MB5140:EE_|JH0PR06MB7353:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FgdvjyGuShLjBYT3Cp+pWNuTySxfhA+6jesEVfTv6vqAefjMYzxytSh4DT+845xlP4o5+rhgDOEwBh2qRkvdCYt98wABK3T1iTvWl2gvc+ljzFp38RULNg6sj3Gl6RhDAY1uaSinLWr1YQjIC6BWkpH/8GuMpKgqwyzGclKUvrlKIEUyQlsIeZcEl/bOtCtLSbS/XtxGJz8t1Zj/CbdZ3nex5FZiXdbnc2wNfHZQbcl6otzQoj2sq2kwGU/KaBeLji81jtzL7FN8ogrkVLemOxz02N64JssRKBzuLWU7C10R8lEZSQU3t8oR9zbU585X7Cy7UtM3m9jIbMYTOf0DgnGXX3I/bURwfZA5TjcF5q6gHlAQtxwyGpokrNpvX/ae0BWCPGpn4ZSkGEXWfUSVOpwqOuV0aTPMg8vDkCBOzLeYWDuqKaEdCmD/xj20vJZXyLBmDui89TQG9jQHRWyl3FG3xeahSNY6uqUQyRKewRTmxVbjcenXXLuLyPnSusR6z7ycXGCiMGcRrYHhRmvDgiTf5sTdOk1Es1mC1NBxiRAZShWtwCAsyOBjNynX04/1TUx9/7Xp0a9/Jd6ZpyOlzfd4VdAdeKniikYI8etgwaG+oXxmUciFtfNzoJdEtxiF217ZqypCdjwp5IPivpU1ndU+FqlEPWu461IDyxHiQ0o= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SI2PR06MB5140.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376005)(366007)(52116005)(1800799015)(7416005)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?WmpPbm45OHc3bXJnWkxuY3lSRzVEZWRvSUFzTnp3N2FUTXpLeGRUUTdVa3dr?= =?utf-8?B?c0NJSk8yYURKenNnay9SN243RFFXK055SytldmZMbkRIK1pNOHJsTDhlbEIz?= =?utf-8?B?MmhFZ1ZPSGRmb2hhV095NXpxeVh6TWZEbUNDUWtwdDB1aEN0QVdTL3Z6NlBm?= =?utf-8?B?VFA1YTRtOHFDWGlrNEorZmJzQVllRzI5eURsOGhkb3RncC80NytlMFJvUUg4?= =?utf-8?B?em9yQ0pLNnloMlpoanprOUdlZXVZdXp5Zk5uUWtuRGtFSkNsUWJVMFZWcEtZ?= =?utf-8?B?dFc0V0ExMG1BMDgrTjAxeVlQa1lEUGhqK2ExV1FTYmpUODlMUTgxbm5jSnJU?= =?utf-8?B?TWE4ODdGV0N0M1dCSEpNS21CUUxLSStxMzllSzJIM29wQmtmVEFncHlZNVBL?= =?utf-8?B?Ql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08dc56d75b44 X-MS-Exchange-CrossTenant-AuthSource: SI2PR06MB5140.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Apr 2024 07:50:13.1264 (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: U4wsfP7TIIFtqlbQL9t9KHmVzxmEypCatq/CxY9oZ7XsfJSVYgW2t2uyBgDVfgr7J1Xm0kUfs8dl8UjyNmC/iw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: JH0PR06MB7353 在 2021/11/15 19:42, Christian König 写道: > Am 13.11.21 um 07:22 schrieb Jianqun Xu: >> Add DMA_BUF_IOCTL_SYNC_PARTIAL support for user to sync dma-buf with >> offset and len. > > You have not given an use case for this so it is a bit hard to review. > And from the existing use cases I don't see why this should be necessary. > > Even worse from the existing backend implementation I don't even see > how drivers should be able to fulfill this semantics. > > Please explain further, > Christian. > >> >> Change-Id: I03d2d2e10e48d32aa83c31abade57e0931e1be49 >> Signed-off-by: Jianqun Xu >> --- >>   drivers/dma-buf/dma-buf.c    | 42 ++++++++++++++++++++++++++++++++++++ >>   include/uapi/linux/dma-buf.h |  8 +++++++ >>   2 files changed, 50 insertions(+) >> >> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c >> index d9948d58b3f4..78f37f7c3462 100644 >> --- a/drivers/dma-buf/dma-buf.c >> +++ b/drivers/dma-buf/dma-buf.c >> @@ -392,6 +392,7 @@ static long dma_buf_ioctl(struct file *file, >>   { >>       struct dma_buf *dmabuf; >>       struct dma_buf_sync sync; >> +    struct dma_buf_sync_partial sync_p; >>       enum dma_data_direction direction; >>       int ret; >>   @@ -430,6 +431,47 @@ static long dma_buf_ioctl(struct file *file, >>       case DMA_BUF_SET_NAME_B: >>           return dma_buf_set_name(dmabuf, (const char __user *)arg); >>   +    case DMA_BUF_IOCTL_SYNC_PARTIAL: >> +        if (copy_from_user(&sync_p, (void __user *) arg, >> sizeof(sync_p))) >> +            return -EFAULT; >> + >> +        if (sync_p.len == 0) >> +            return 0; >> + >> +        if ((sync_p.offset % cache_line_size()) || (sync_p.len % >> cache_line_size())) >> +            return -EINVAL; >> + >> +        if (sync_p.len > dmabuf->size || sync_p.offset > >> dmabuf->size - sync_p.len) >> +            return -EINVAL; >> + >> +        if (sync_p.flags & ~DMA_BUF_SYNC_VALID_FLAGS_MASK) >> +            return -EINVAL; >> + >> +        switch (sync_p.flags & DMA_BUF_SYNC_RW) { >> +        case DMA_BUF_SYNC_READ: >> +            direction = DMA_FROM_DEVICE; >> +            break; >> +        case DMA_BUF_SYNC_WRITE: >> +            direction = DMA_TO_DEVICE; >> +            break; >> +        case DMA_BUF_SYNC_RW: >> +            direction = DMA_BIDIRECTIONAL; >> +            break; >> +        default: >> +            return -EINVAL; >> +        } >> + >> +        if (sync_p.flags & DMA_BUF_SYNC_END) >> +            ret = dma_buf_end_cpu_access_partial(dmabuf, direction, >> +                                 sync_p.offset, >> +                                 sync_p.len); >> +        else >> +            ret = dma_buf_begin_cpu_access_partial(dmabuf, direction, >> +                                   sync_p.offset, >> +                                   sync_p.len); >> + >> +        return ret; >> + >>       default: >>           return -ENOTTY; >>       } >> diff --git a/include/uapi/linux/dma-buf.h b/include/uapi/linux/dma-buf.h >> index 7f30393b92c3..6236c644624d 100644 >> --- a/include/uapi/linux/dma-buf.h >> +++ b/include/uapi/linux/dma-buf.h >> @@ -47,4 +47,12 @@ struct dma_buf_sync { >>   #define DMA_BUF_SET_NAME_A    _IOW(DMA_BUF_BASE, 1, u32) >>   #define DMA_BUF_SET_NAME_B    _IOW(DMA_BUF_BASE, 1, u64) >>   +struct dma_buf_sync_partial { >> +    __u64 flags; >> +    __u32 offset; >> +    __u32 len; >> +}; >> + >> +#define DMA_BUF_IOCTL_SYNC_PARTIAL    _IOW(DMA_BUF_BASE, 2, struct >> dma_buf_sync_partial) >> + >>   #endif > > > From mboxrd@z Thu Jan  1 00:00:00 1970 > Return-Path: > > X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on >     aws-us-west-2-korg-lkml-1.web.codeaurora.org > Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) >     by smtp.lore.kernel.org (Postfix) with ESMTP id C34E8C433EF >     for ; Mon, 15 Nov 2021 11:42:25 > +0000 (UTC) > Received: from gabe.freedesktop.org (gabe.freedesktop.org > [131.252.210.177]) >     (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 > bits)) >     (No client certificate requested) >     by mail.kernel.org (Postfix) with ESMTPS id 802C761AA2 >     for ; Mon, 15 Nov 2021 11:42:25 > +0000 (UTC) > DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 802C761AA2 > Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine > dis=none) header.from=amd.com > Authentication-Results: mail.kernel.org; spf=none > smtp.mailfrom=lists.freedesktop.org > Received: from gabe.freedesktop.org (localhost [127.0.0.1]) >     by gabe.freedesktop.org (Postfix) with ESMTP id 10E466E943; >     Mon, 15 Nov 2021 11:42:25 +0000 (UTC) > Received: from NAM10-BN7-obe.outbound.protection.outlook.com > (mail-bn7nam10on2068.outbound.protection.outlook.com [40.107.92.68]) > by gabe.freedesktop.org (Postfix) with ESMTPS id D422E6E943 > for ; Mon, 15 Nov 2021 11:42:23 +0000 > (UTC) > ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; > b=ZYSFfhU+N5Fq39gpw5NCsolRnyvMmfKTA5cWgJx3l903N5tP6BK6x7pUqmtcQZvyCwwzQwonnQGCZqIx/M4qourfwzBBS0SVUSHvvU6Vn4nZRrd/wffjMaX24XwtUxIdQAQntPFWRi0SjIWpG+72E2TIxwcuyY3/5+qkQiF8s3iNnNXmY4zdZ9fx48I5MHFePTx+VAyZvxzedsyfjjAxGaaaPl2uZagHTH9TDFFaAg/rHvH6O2vq0RwQIaMOGxhA8DgCmsj9dMlSloko0iLt+p2s/WUQShbSQrZq13R3POIyU6aCBx32Zz+biTbwpcXQyXxwfQIi+2nIruJQvuvwSw== > > 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=JkRdepoBhhvZgBl9zd4oG1PeOv+kPWSxKw1ORztFSv4=; > b=hYGlnailNdl4CzgRcFMK/ZTAFR1Ipev9djYIyqc4j32m6sMsqyx1YxjcAPDo6Rnk3qtB+9sMag1rldkddxzJCBGDOLkgX7hQFl7AFRIQhpXLQsUek5IrCfbd0rGW4HpdbUxyGyRz70XnjFPSTGQFhlz7glYKDPeyHN/X3RtVBfrUG1ywFsVzjD6+I8Uc0O9jbG6Rw5S1/dydWeyovBOPcbUVYt1ZF0z7JDt4Tj90hAElD4cTmc/rfAt3eY3pB6pydnGu+nXJ5bKZIY/U7Wec+TwdXPNGU+ia5E4MN6xuL+kVLPNPa1G6h8qetsVTw5UYOkGtPZCxcR6pUKs0ocJTZg== > > 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=JkRdepoBhhvZgBl9zd4oG1PeOv+kPWSxKw1ORztFSv4=; > b=4zNaX2CfJHDxjaHlT7C84/jyXuQUhJVYoDhuLfWp/MO0v73QSPzoDc9EiD6G3taNwfNkwRBOMm5VIiF2wOMmVeJmV2JabQp0VPjTYkXDZL9xbtuoXkdCtQFx1+Fz1GJhOnpgaIMZrSQ+DugqAkbmKW5Jp6o8P3GT/ZDzIFBk4xk= > > Authentication-Results: dkim=none (message not signed) > header.d=none;dmarc=none action=none header.from=amd.com; > Received: from MWHPR1201MB0192.namprd12.prod.outlook.com > (2603:10b6:301:5a::14) by MWHPR12MB1837.namprd12.prod.outlook.com > (2603:10b6:300:113::20) with Microsoft SMTP Server (version=TLS1_2, > cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.27; Mon, > 15 Nov > 2021 11:42:20 +0000 > Received: from MWHPR1201MB0192.namprd12.prod.outlook.com > ([fe80::2d02:26e7:a2d0:3769]) by > MWHPR1201MB0192.namprd12.prod.outlook.com > ([fe80::2d02:26e7:a2d0:3769%5]) with mapi id 15.20.4690.027; Mon, 15 > Nov 2021 > 11:42:20 +0000 > Subject: Re: [PATCH] dma-buf: add DMA_BUF_IOCTL_SYNC_PARTIAL support > To: Jianqun Xu , sumit.semwal@linaro.org > References: <20211113062222.3743909-1-jay.xu@rock-chips.com> > From: =?UTF-8?Q?Christian_K=c3=b6nig?= > Message-ID: <1da5cdf0-ccb8-3740-cf96-794c4d5b2eb4@amd.com> > Date: Mon, 15 Nov 2021 12:42:13 +0100 > User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 > Thunderbird/78.13.0 > In-Reply-To: <20211113062222.3743909-1-jay.xu@rock-chips.com> > Content-Type: text/plain; charset=utf-8; format=flowed > Content-Transfer-Encoding: 7bit > Content-Language: en-US > X-ClientProxiedBy: AS9PR0301CA0041.eurprd03.prod.outlook.com > (2603:10a6:20b:469::32) To MWHPR1201MB0192.namprd12.prod.outlook.com > (2603:10b6:301:5a::14) > MIME-Version: 1.0 > Received: from [IPv6:2a02:908:1252:fb60:bf0c:d52c:6ba0:cfc6] > (2a02:908:1252:fb60:bf0c:d52c:6ba0:cfc6) by > AS9PR0301CA0041.eurprd03.prod.outlook.com (2603:10a6:20b:469::32) with > Microsoft SMTP Server (version=TLS1_2, > cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.26 via > Frontend > Transport; Mon, 15 Nov 2021 11:42:17 +0000 > X-MS-PublicTrafficType: Email > X-MS-Office365-Filtering-Correlation-Id: > 00ebe1d3-562c-44d3-ab7c-08d9a82cfb38 > X-MS-TrafficTypeDiagnostic: MWHPR12MB1837: > X-Microsoft-Antispam-PRVS: > > X-MS-Oob-TLC-OOBClassifiers: OLM:8273; > X-MS-Exchange-SenderADCheck: 1 > X-MS-Exchange-AntiSpam-Relay: 0 > X-Microsoft-Antispam: BCL:0; > X-Microsoft-Antispam-Message-Info: > qnNpT+UDEdrvmTrphgUzQsrIExW/nJQjCEAt6/leQnM/+F75uQ4P/gIEmE2mfi+FLGZoBp+qpesYv6TE414JsgHBjmPsq9wqAxODHs5+tKntVesYVzi2T3a+bor5SPTdHrjOyz4Lv5il0Z00hyIMOsC898lxdXNK3DY8ClRa/X+z05ZLWWI9kbXDjVdrVqmD31Ciy9En6YG1TKIV+epuDLGRKEvYe8NhgoFs6tUkQ/bWmTBdRJgllNrqms9k2nXdSN5hRpvEjPb3R0jF3kat4c9/g+R9ZfNDU0z3Qo2VAfydWQzqA1BIV1A7EDnRTXmW5vnAV79Migw7l8P0CqzM1nBlO5bCjKtHXPj4OXseQUwQWFO5216Sj4yR6FeIQFVrAO7lW3pd3S4bncIRU17nSaQPkQnnNSdXm0OBFoDdrVzhxYO5g7CoHdrAh0S0Y4Q8vQFqy36ujVGByHPPFfX+aaKXQ/BWnlM6tghXuVYUcoYtqlV4AJpRnByfYBQrumA1ouTLedvwpUsQlCItufU36509QJHuQ9oa3NDqXos2SPnUS/F/6HsBJHw63Rq1Jcd0WGmqDrp9wFQaK959C6zotCP8LC+p2pB0gQYgRieAeifspuQuKmSFk46/7OZfmlwmv8i1rhIK65/inlDat2eDtJBEpqk15UW3bMvw1g5dv5Kr9RmOvFfjfRv5uYDkmxM4OcYG/KHnhd59tAKjoVDXcLgv4Z/rf5i8pgCG0D7SWcZI1XNcdbglDuWiigm3ihyx > X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; > SCL:1; SRV:; > IPV:NLI; SFV:NSPM; H:MWHPR1201MB0192.namprd12.prod.outlook.com; PTR:; > CAT:NONE; > SFS:(4636009)(366004)(316002)(7416002)(2616005)(6486002)(8936002)(8676002)(186003)(31686004)(66556008)(66476007)(86362001)(66946007)(83380400001)(31696002)(6666004)(508600001)(38100700002)(5660300002)(2906002)(4326008)(36756003)(43740500002)(45980500001); > > DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 > X-MS-Exchange-AntiSpam-MessageData-0: > =?utf-8?B?VmtQa3NIa1NhVm40N2lmZnBueGVQS3ZuTWpaWm4waU1IQ3kvYlFHSGI1ZllH?= > =?utf-8?B?ek13MElkY3lWUlVuVWxJUkZPR0tlQ01FV0lCUnJrUWRSejg0WjZJWW5CTFdS?= > =?utf-8?B?TDVMZTVHNitXaW9taUpweTFaL2pJS1NZbGJacnlDWVNyMFl3MjlkdGd3YTEr?= > =?utf-8?B?MmRodnF3dnlzd0NKZEtZN1JaVFA2OTBJRGQ1WjZBUHROK0dhMlhMWWZkaUd3?= > =?utf-8?B?RFlQd3NmNGRWZFZydFhXSVJyRmxQMEZDWlhxU3hMcDYzNUtJRGtHVzZtMmIx?= > =?utf-8?B?NU5zT0VvNmI1MUE1WTRmQWRUZkM4aXFtYVBzK3ovM2E3dGFEQ2ZJZ1B5U2Vv?= > =?utf-8?B?eWVQN0tEZUhFQi93ZG8zdFJaTjcwT2dUc3VzdTgzNzZsaVNuUHFOQjRFN2Nq?= > =?utf-8?B?eGZJamhBMDhBbmhsRjhWUDY3dmFhODJKR0UwVWlFcW42TXR6Q2lRV0ZhQnJW?= > =?utf-8?B?SVAvalMxUVpmSVNzWmxpR3Z1cWtYSTlXTHZOMUY4dExKMFJZcXl2UGZ5S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UTdUY3A5SFJBYUhCOEpIbFNTK3Vic2hxcXR5MWZUcFND?= > =?utf-8?B?bDZlRnl0VkxWajFyeDF4SFpoQzJTbTNPU1U2c1c4TlhscWNQNXhRaWMxTG5G?= > =?utf-8?B?emJtUURBZVlqT3cxR2hRdGFVZUh1akxuRHIwYlRPOWZZSnVKeXFvMCtlNTFT?= > =?utf-8?B?Q3BvMGROdlZ2ZFJUNzYya3hvUVlHYmYzaGlSMHMyK1U0Nis1YksrWFZWc1JH?= > =?utf-8?B?VHFoY0phcnNVdHNJN2Y4Z0lxRzhHRng0SWQ2NmJuZENWUE5uMktmZktpeTY2?= > =?utf-8?B?dU15L0FOWDNobkJkN0x6RkdlY1BQalhSK3p0S2ZsTVpwUnFSN0l6S1RMcXJh?= > =?utf-8?B?bnptcHlHc2VDVm50NW52MkRVK0FpbGpNb3JPektpc1pVM3BibGRhNklaMjVN?= > =?utf-8?B?MTZxNFNOd2lTbDBhSk5XcFk0UTdZbXdsaW5BYm1kRzlGeThJOU4rMWNyL09l?= > =?utf-8?B?N3ZTM1NSeUFraVMvVnJYcWhNRjFPOVZYNUhTRFUyWHo5QVpKZlhia05HQy9S?= > =?utf-8?B?Uit6VG51RCtqWGJsNU4vRGlFVXhJdjh4Y1RhdWhEVVpVTUNpcGdMQUY2L005?= > =?utf-8?B?WG9wejVLbEZjampPYVcxNDMySXNQelVEZEFGQWROZ2h4ZjFNOWR3c084SjFN?= > =?utf-8?B?b2lMbThOZmdXQW84YWg4ekJyQW9mWStyZnMvV1JWd3lMajVEM2hTbFVUczNv?= > =?utf-8?B?QmhyeVpQVVUrOUtyRWNjUXp2a1JhQUpsSnk0ZVlrSDdnaFFYaFVTdHpjM01O?= > =?utf-8?Q?BO9RKUEVN4uMTDc9B3JQWSk=3D?= > X-OriginatorOrg: amd.com > X-MS-Exchange-CrossTenant-Network-Message-Id: > 00ebe1d3-562c-44d3-ab7c-08d9a82cfb38 > X-MS-Exchange-CrossTenant-AuthSource: > MWHPR1201MB0192.namprd12.prod.outlook.com > X-MS-Exchange-CrossTenant-AuthAs: Internal > X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Nov 2021 > 11:42:19.8907 (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: > cPSQhRvD4Dau5vTrINquy4Yo1A5DbJm3yOORz6qQDOx+umrhjPgdp0FqKASMDEeu > X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1837 > X-BeenThere: dri-devel@lists.freedesktop.org > X-Mailman-Version: 2.1.29 > Precedence: list > List-Id: Direct Rendering Infrastructure - Development > > List-Unsubscribe: > , > > List-Archive: > List-Post: > List-Help: > List-Subscribe: > , > > Cc: pekka.paalanen@collabora.com, daniel.vetter@ffwll.ch, > linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, > linaro-mm-sig@lists.linaro.org, linux-rockchip@lists.infradead.org, > jason@jlekstrand.net, linux-media@vger.kernel.org > Errors-To: dri-devel-bounces@lists.freedesktop.org > Sender: "dri-devel" > > Am 13.11.21 um 07:22 schrieb Jianqun Xu: >> Add DMA_BUF_IOCTL_SYNC_PARTIAL support for user to sync dma-buf with >> offset and len. > > You have not given an use case for this so it is a bit hard to review. > And from the existing use cases I don't see why this should be necessary. > > Even worse from the existing backend implementation I don't even see > how drivers should be able to fulfill this semantics. > > Please explain further, > Christian. > >> >> Change-Id: I03d2d2e10e48d32aa83c31abade57e0931e1be49 >> Signed-off-by: Jianqun Xu >> --- >>   drivers/dma-buf/dma-buf.c    | 42 ++++++++++++++++++++++++++++++++++++ >>   include/uapi/linux/dma-buf.h |  8 +++++++ >>   2 files changed, 50 insertions(+) >> >> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c >> index d9948d58b3f4..78f37f7c3462 100644 >> --- a/drivers/dma-buf/dma-buf.c >> +++ b/drivers/dma-buf/dma-buf.c >> @@ -392,6 +392,7 @@ static long dma_buf_ioctl(struct file *file, >>   { >>       struct dma_buf *dmabuf; >>       struct dma_buf_sync sync; >> +    struct dma_buf_sync_partial sync_p; >>       enum dma_data_direction direction; >>       int ret; >>   @@ -430,6 +431,47 @@ static long dma_buf_ioctl(struct file *file, >>       case DMA_BUF_SET_NAME_B: >>           return dma_buf_set_name(dmabuf, (const char __user *)arg); >>   +    case DMA_BUF_IOCTL_SYNC_PARTIAL: >> +        if (copy_from_user(&sync_p, (void __user *) arg, >> sizeof(sync_p))) >> +            return -EFAULT; >> + >> +        if (sync_p.len == 0) >> +            return 0; >> + >> +        if ((sync_p.offset % cache_line_size()) || (sync_p.len % >> cache_line_size())) >> +            return -EINVAL; >> + >> +        if (sync_p.len > dmabuf->size || sync_p.offset > >> dmabuf->size - sync_p.len) >> +            return -EINVAL; >> + >> +        if (sync_p.flags & ~DMA_BUF_SYNC_VALID_FLAGS_MASK) >> +            return -EINVAL; >> + >> +        switch (sync_p.flags & DMA_BUF_SYNC_RW) { >> +        case DMA_BUF_SYNC_READ: >> +            direction = DMA_FROM_DEVICE; >> +            break; >> +        case DMA_BUF_SYNC_WRITE: >> +            direction = DMA_TO_DEVICE; >> +            break; >> +        case DMA_BUF_SYNC_RW: >> +            direction = DMA_BIDIRECTIONAL; >> +            break; >> +        default: >> +            return -EINVAL; >> +        } >> + >> +        if (sync_p.flags & DMA_BUF_SYNC_END) >> +            ret = dma_buf_end_cpu_access_partial(dmabuf, direction, >> +                                 sync_p.offset, >> +                                 sync_p.len); >> +        else >> +            ret = dma_buf_begin_cpu_access_partial(dmabuf, direction, >> +                                   sync_p.offset, >> +                                   sync_p.len); >> + >> +        return ret; >> + >>       default: >>           return -ENOTTY; >>       } >> diff --git a/include/uapi/linux/dma-buf.h b/include/uapi/linux/dma-buf.h >> index 7f30393b92c3..6236c644624d 100644 >> --- a/include/uapi/linux/dma-buf.h >> +++ b/include/uapi/linux/dma-buf.h >> @@ -47,4 +47,12 @@ struct dma_buf_sync { >>   #define DMA_BUF_SET_NAME_A    _IOW(DMA_BUF_BASE, 1, u32) >>   #define DMA_BUF_SET_NAME_B    _IOW(DMA_BUF_BASE, 1, u64) >>   +struct dma_buf_sync_partial { >> +    __u64 flags; >> +    __u32 offset; >> +    __u32 len; >> +}; >> + >> +#define DMA_BUF_IOCTL_SYNC_PARTIAL    _IOW(DMA_BUF_BASE, 2, struct >> dma_buf_sync_partial) >> + >>   #endif > > > From mboxrd@z Thu Jan  1 00:00:00 1970 > Return-Path: > > X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on >     aws-us-west-2-korg-lkml-1.web.codeaurora.org > Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) >     by smtp.lore.kernel.org (Postfix) with ESMTP id 1DF63C433F5 >     for ; Mon, 15 Nov 2021 > 11:42:39 +0000 (UTC) > Received: from bombadil.infradead.org (bombadil.infradead.org > [198.137.202.133]) >     (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 > bits)) >     (No client certificate requested) >     by mail.kernel.org (Postfix) with ESMTPS id D939A61175 >     for ; Mon, 15 Nov 2021 > 11:42:38 +0000 (UTC) > DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D939A61175 > Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine > dis=none) header.from=amd.com > Authentication-Results: mail.kernel.org; spf=none > smtp.mailfrom=lists.infradead.org > DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; >     d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: >     Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: > >     List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:Date:Message-ID:From: > >     References:Cc:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: > >     Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; > >     bh=YynYeIAZi+K+m2naIfrKtqrQanTeUDG2hfxK0scEY+M=; > b=JLVk0WfVJXF3my3DZsIyB8zoBQ >     XDDOsW4/MgUPrPvBnKH0xH2UztD/Tzxw3KkYpeUAxb8mx+buAB+V5wJH40hRMgTKSQFKUvsZMZOdS > >     /HgFcaxhD1Zgm/DZDUctpGlg85qHL3T6NVS6HTVmNnyckiGeiW51pgCbPFZl/3FyFiMSABxukwdQm > >     tD3yDWBz1d9BkxA48UHC/k+LbeyyldyHxkuR1c2/CoHk0X9kwxWx78BI94DfyUNE1A4V8Lnvtae07 > >     aUnHLtVfWLo5nobyfoep93NHxihd+/nZSJ88ZYGYOg7rsaTeh68YZXKzk7WvuepjMfXYZlzUCS7OX > >     dg1rskUg==; > Received: from localhost ([::1] helo=bombadil.infradead.org) >     by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) >     id 1mmaNd-00FR0i-Oq; Mon, 15 Nov 2021 11:42:33 +0000 > Received: from mail-mw2nam10on2065.outbound.protection.outlook.com > ([40.107.94.65] helo=NAM10-MW2-obe.outbound.protection.outlook.com) > by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) > id 1mmaNZ-00FQyX-9A > for linux-rockchip@lists.infradead.org; Mon, 15 Nov 2021 11:42:32 +0000 > ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; > b=ZYSFfhU+N5Fq39gpw5NCsolRnyvMmfKTA5cWgJx3l903N5tP6BK6x7pUqmtcQZvyCwwzQwonnQGCZqIx/M4qourfwzBBS0SVUSHvvU6Vn4nZRrd/wffjMaX24XwtUxIdQAQntPFWRi0SjIWpG+72E2TIxwcuyY3/5+qkQiF8s3iNnNXmY4zdZ9fx48I5MHFePTx+VAyZvxzedsyfjjAxGaaaPl2uZagHTH9TDFFaAg/rHvH6O2vq0RwQIaMOGxhA8DgCmsj9dMlSloko0iLt+p2s/WUQShbSQrZq13R3POIyU6aCBx32Zz+biTbwpcXQyXxwfQIi+2nIruJQvuvwSw== > > 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=JkRdepoBhhvZgBl9zd4oG1PeOv+kPWSxKw1ORztFSv4=; > b=hYGlnailNdl4CzgRcFMK/ZTAFR1Ipev9djYIyqc4j32m6sMsqyx1YxjcAPDo6Rnk3qtB+9sMag1rldkddxzJCBGDOLkgX7hQFl7AFRIQhpXLQsUek5IrCfbd0rGW4HpdbUxyGyRz70XnjFPSTGQFhlz7glYKDPeyHN/X3RtVBfrUG1ywFsVzjD6+I8Uc0O9jbG6Rw5S1/dydWeyovBOPcbUVYt1ZF0z7JDt4Tj90hAElD4cTmc/rfAt3eY3pB6pydnGu+nXJ5bKZIY/U7Wec+TwdXPNGU+ia5E4MN6xuL+kVLPNPa1G6h8qetsVTw5UYOkGtPZCxcR6pUKs0ocJTZg== > > 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=JkRdepoBhhvZgBl9zd4oG1PeOv+kPWSxKw1ORztFSv4=; > b=4zNaX2CfJHDxjaHlT7C84/jyXuQUhJVYoDhuLfWp/MO0v73QSPzoDc9EiD6G3taNwfNkwRBOMm5VIiF2wOMmVeJmV2JabQp0VPjTYkXDZL9xbtuoXkdCtQFx1+Fz1GJhOnpgaIMZrSQ+DugqAkbmKW5Jp6o8P3GT/ZDzIFBk4xk= > > Authentication-Results: dkim=none (message not signed) > header.d=none;dmarc=none action=none header.from=amd.com; > Received: from MWHPR1201MB0192.namprd12.prod.outlook.com > (2603:10b6:301:5a::14) by MWHPR12MB1837.namprd12.prod.outlook.com > (2603:10b6:300:113::20) with Microsoft SMTP Server (version=TLS1_2, > cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.27; Mon, > 15 Nov > 2021 11:42:20 +0000 > Received: from MWHPR1201MB0192.namprd12.prod.outlook.com > ([fe80::2d02:26e7:a2d0:3769]) by > MWHPR1201MB0192.namprd12.prod.outlook.com > ([fe80::2d02:26e7:a2d0:3769%5]) with mapi id 15.20.4690.027; Mon, 15 > Nov 2021 > 11:42:20 +0000 > Subject: Re: [PATCH] dma-buf: add DMA_BUF_IOCTL_SYNC_PARTIAL support > To: Jianqun Xu , sumit.semwal@linaro.org > Cc: pekka.paalanen@collabora.com, daniel.vetter@ffwll.ch, > jason@jlekstrand.net, linux-media@vger.kernel.org, > dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, > linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org > References: <20211113062222.3743909-1-jay.xu@rock-chips.com> > From: =?UTF-8?Q?Christian_K=c3=b6nig?= > Message-ID: <1da5cdf0-ccb8-3740-cf96-794c4d5b2eb4@amd.com> > Date: Mon, 15 Nov 2021 12:42:13 +0100 > User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 > Thunderbird/78.13.0 > In-Reply-To: <20211113062222.3743909-1-jay.xu@rock-chips.com> > Content-Language: en-US > X-ClientProxiedBy: AS9PR0301CA0041.eurprd03.prod.outlook.com > (2603:10a6:20b:469::32) To MWHPR1201MB0192.namprd12.prod.outlook.com > (2603:10b6:301:5a::14) > MIME-Version: 1.0 > Received: from [IPv6:2a02:908:1252:fb60:bf0c:d52c:6ba0:cfc6] > (2a02:908:1252:fb60:bf0c:d52c:6ba0:cfc6) by > AS9PR0301CA0041.eurprd03.prod.outlook.com (2603:10a6:20b:469::32) with > Microsoft SMTP Server (version=TLS1_2, > cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.26 via > Frontend > Transport; Mon, 15 Nov 2021 11:42:17 +0000 > X-MS-PublicTrafficType: Email > X-MS-Office365-Filtering-Correlation-Id: > 00ebe1d3-562c-44d3-ab7c-08d9a82cfb38 > X-MS-TrafficTypeDiagnostic: MWHPR12MB1837: > X-Microsoft-Antispam-PRVS: > > X-MS-Oob-TLC-OOBClassifiers: OLM:8273; > X-MS-Exchange-SenderADCheck: 1 > X-MS-Exchange-AntiSpam-Relay: 0 > X-Microsoft-Antispam: BCL:0; > X-Microsoft-Antispam-Message-Info: > qnNpT+UDEdrvmTrphgUzQsrIExW/nJQjCEAt6/leQnM/+F75uQ4P/gIEmE2mfi+FLGZoBp+qpesYv6TE414JsgHBjmPsq9wqAxODHs5+tKntVesYVzi2T3a+bor5SPTdHrjOyz4Lv5il0Z00hyIMOsC898lxdXNK3DY8ClRa/X+z05ZLWWI9kbXDjVdrVqmD31Ciy9En6YG1TKIV+epuDLGRKEvYe8NhgoFs6tUkQ/bWmTBdRJgllNrqms9k2nXdSN5hRpvEjPb3R0jF3kat4c9/g+R9ZfNDU0z3Qo2VAfydWQzqA1BIV1A7EDnRTXmW5vnAV79Migw7l8P0CqzM1nBlO5bCjKtHXPj4OXseQUwQWFO5216Sj4yR6FeIQFVrAO7lW3pd3S4bncIRU17nSaQPkQnnNSdXm0OBFoDdrVzhxYO5g7CoHdrAh0S0Y4Q8vQFqy36ujVGByHPPFfX+aaKXQ/BWnlM6tghXuVYUcoYtqlV4AJpRnByfYBQrumA1ouTLedvwpUsQlCItufU36509QJHuQ9oa3NDqXos2SPnUS/F/6HsBJHw63Rq1Jcd0WGmqDrp9wFQaK959C6zotCP8LC+p2pB0gQYgRieAeifspuQuKmSFk46/7OZfmlwmv8i1rhIK65/inlDat2eDtJBEpqk15UW3bMvw1g5dv5Kr9RmOvFfjfRv5uYDkmxM4OcYG/KHnhd59tAKjoVDXcLgv4Z/rf5i8pgCG0D7SWcZI1XNcdbglDuWiigm3ihyx > X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; > SCL:1; SRV:; > IPV:NLI; SFV:NSPM; H:MWHPR1201MB0192.namprd12.prod.outlook.com; PTR:; > CAT:NONE; > SFS:(4636009)(366004)(316002)(7416002)(2616005)(6486002)(8936002)(8676002)(186003)(31686004)(66556008)(66476007)(86362001)(66946007)(83380400001)(31696002)(6666004)(508600001)(38100700002)(5660300002)(2906002)(4326008)(36756003)(43740500002)(45980500001); > > DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 > X-MS-Exchange-AntiSpam-MessageData-0: > =?utf-8?B?VmtQa3NIa1NhVm40N2lmZnBueGVQS3ZuTWpaWm4waU1IQ3kvYlFHSGI1ZllH?= > =?utf-8?B?ek13MElkY3lWUlVuVWxJUkZPR0tlQ01FV0lCUnJrUWRSejg0WjZJWW5CTFdS?= > =?utf-8?B?TDVMZTVHNitXaW9taUpweTFaL2pJS1NZbGJacnlDWVNyMFl3MjlkdGd3YTEr?= > =?utf-8?B?MmRodnF3dnlzd0NKZEtZN1JaVFA2OTBJRGQ1WjZBUHROK0dhMlhMWWZkaUd3?= > =?utf-8?B?RFlQd3NmNGRWZFZydFhXSVJyRmxQMEZDWlhxU3hMcDYzNUtJRGtHVzZtMmIx?= > =?utf-8?B?NU5zT0VvNmI1MUE1WTRmQWRUZkM4aXFtYVBzK3ovM2E3dGFEQ2ZJZ1B5U2Vv?= > =?utf-8?B?eWVQN0tEZUhFQi93ZG8zdFJaTjcwT2dUc3VzdTgzNzZsaVNuUHFOQjRFN2Nq?= > =?utf-8?B?eGZJamhBMDhBbmhsRjhWUDY3dmFhODJKR0UwVWlFcW42TXR6Q2lRV0ZhQnJW?= > =?utf-8?B?SVAvalMxUVpmSVNzWmxpR3Z1cWtYSTlXTHZOMUY4dExKMFJZcXl2UGZ5S2pZ?= > =?utf-8?B?NVI2K0xOaFQ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vic2hxcXR5MWZUcFND?= > =?utf-8?B?bDZlRnl0VkxWajFyeDF4SFpoQzJTbTNPU1U2c1c4TlhscWNQNXhRaWMxTG5G?= > =?utf-8?B?emJtUURBZVlqT3cxR2hRdGFVZUh1akxuRHIwYlRPOWZZSnVKeXFvMCtlNTFT?= > =?utf-8?B?Q3BvMGROdlZ2ZFJUNzYya3hvUVlHYmYzaGlSMHMyK1U0Nis1YksrWFZWc1JH?= > =?utf-8?B?VHFoY0phcnNVdHNJN2Y4Z0lxRzhHRng0SWQ2NmJuZENWUE5uMktmZktpeTY2?= > =?utf-8?B?dU15L0FOWDNobkJkN0x6RkdlY1BQalhSK3p0S2ZsTVpwUnFSN0l6S1RMcXJh?= > =?utf-8?B?bnptcHlHc2VDVm50NW52MkRVK0FpbGpNb3JPektpc1pVM3BibGRhNklaMjVN?= > =?utf-8?B?MTZxNFNOd2lTbDBhSk5XcFk0UTdZbXdsaW5BYm1kRzlGeThJOU4rMWNyL09l?= > =?utf-8?B?N3ZTM1NSeUFraVMvVnJYcWhNRjFPOVZYNUhTRFUyWHo5QVpKZlhia05HQy9S?= > =?utf-8?B?Uit6VG51RCtqWGJsNU4vRGlFVXhJdjh4Y1RhdWhEVVpVTUNpcGdMQUY2L005?= > =?utf-8?B?WG9wejVLbEZjampPYVcxNDMySXNQelVEZEFGQWROZ2h4ZjFNOWR3c084SjFN?= > =?utf-8?B?b2lMbThOZmdXQW84YWg4ekJyQW9mWStyZnMvV1JWd3lMajVEM2hTbFVUczNv?= > =?utf-8?B?QmhyeVpQVVUrOUtyRWNjUXp2a1JhQUpsSnk0ZVlrSDdnaFFYaFVTdHpjM01O?= > =?utf-8?Q?BO9RKUEVN4uMTDc9B3JQWSk=3D?= > X-OriginatorOrg: amd.com > X-MS-Exchange-CrossTenant-Network-Message-Id: > 00ebe1d3-562c-44d3-ab7c-08d9a82cfb38 > X-MS-Exchange-CrossTenant-AuthSource: > MWHPR1201MB0192.namprd12.prod.outlook.com > X-MS-Exchange-CrossTenant-AuthAs: Internal > X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Nov 2021 > 11:42:19.8907 (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: > cPSQhRvD4Dau5vTrINquy4Yo1A5DbJm3yOORz6qQDOx+umrhjPgdp0FqKASMDEeu > X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1837 > X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) > MR-646709E3 X-CRM114-CacheID: sfid-20211115_034229_353755_F892CB5A > X-CRM114-Status: GOOD (  21.17  ) > X-BeenThere: linux-rockchip@lists.infradead.org > X-Mailman-Version: 2.1.34 > Precedence: list > List-Id: Upstream kernel work for Rockchip platforms > > List-Unsubscribe: > , > > List-Archive: > List-Post: > List-Help: > > List-Subscribe: > , > > Content-Transfer-Encoding: 7bit > Content-Type: text/plain; charset="us-ascii"; Format="flowed" > Sender: "Linux-rockchip" > Errors-To: > linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org > > Am 13.11.21 um 07:22 schrieb Jianqun Xu: >> Add DMA_BUF_IOCTL_SYNC_PARTIAL support for user to sync dma-buf with >> offset and len. > > You have not given an use case for this so it is a bit hard to review. > And from the existing use cases I don't see why this should be necessary. > > Even worse from the existing backend implementation I don't even see > how drivers should be able to fulfill this semantics. > > Please explain further, > Christian. Here is a practical case: The user space can allocate a large chunk of dma-buf for self-management, used as a shared memory pool. Small dma-buf can be allocated from this shared memory pool and released back to it after use, thus improving the speed of dma-buf allocation and release. Additionally, custom functionalities such as memory statistics and boundary checking can be implemented in the user space. Of course, the above-mentioned functionalities require the implementation of a partial cache sync interface. Thanks Rong Qianfeng. > >> >> Change-Id: I03d2d2e10e48d32aa83c31abade57e0931e1be49 >> Signed-off-by: Jianqun Xu >> --- >>   drivers/dma-buf/dma-buf.c    | 42 ++++++++++++++++++++++++++++++++++++ >>   include/uapi/linux/dma-buf.h |  8 +++++++ >>   2 files changed, 50 insertions(+) >> >> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c >> index d9948d58b3f4..78f37f7c3462 100644 >> --- a/drivers/dma-buf/dma-buf.c >> +++ b/drivers/dma-buf/dma-buf.c >> @@ -392,6 +392,7 @@ static long dma_buf_ioctl(struct file *file, >>   { >>       struct dma_buf *dmabuf; >>       struct dma_buf_sync sync; >> +    struct dma_buf_sync_partial sync_p; >>       enum dma_data_direction direction; >>       int ret; >>   @@ -430,6 +431,47 @@ static long dma_buf_ioctl(struct file *file, >>       case DMA_BUF_SET_NAME_B: >>           return dma_buf_set_name(dmabuf, (const char __user *)arg); >>   +    case DMA_BUF_IOCTL_SYNC_PARTIAL: >> +        if (copy_from_user(&sync_p, (void __user *) arg, >> sizeof(sync_p))) >> +            return -EFAULT; >> + >> +        if (sync_p.len == 0) >> +            return 0; >> + >> +        if ((sync_p.offset % cache_line_size()) || (sync_p.len % >> cache_line_size())) >> +            return -EINVAL; >> + >> +        if (sync_p.len > dmabuf->size || sync_p.offset > >> dmabuf->size - sync_p.len) >> +            return -EINVAL; >> + >> +        if (sync_p.flags & ~DMA_BUF_SYNC_VALID_FLAGS_MASK) >> +            return -EINVAL; >> + >> +        switch (sync_p.flags & DMA_BUF_SYNC_RW) { >> +        case DMA_BUF_SYNC_READ: >> +            direction = DMA_FROM_DEVICE; >> +            break; >> +        case DMA_BUF_SYNC_WRITE: >> +            direction = DMA_TO_DEVICE; >> +            break; >> +        case DMA_BUF_SYNC_RW: >> +            direction = DMA_BIDIRECTIONAL; >> +            break; >> +        default: >> +            return -EINVAL; >> +        } >> + >> +        if (sync_p.flags & DMA_BUF_SYNC_END) >> +            ret = dma_buf_end_cpu_access_partial(dmabuf, direction, >> +                                 sync_p.offset, >> +                                 sync_p.len); >> +        else >> +            ret = dma_buf_begin_cpu_access_partial(dmabuf, direction, >> +                                   sync_p.offset, >> +                                   sync_p.len); >> + >> +        return ret; >> + >>       default: >>           return -ENOTTY; >>       } >> diff --git a/include/uapi/linux/dma-buf.h b/include/uapi/linux/dma-buf.h >> index 7f30393b92c3..6236c644624d 100644 >> --- a/include/uapi/linux/dma-buf.h >> +++ b/include/uapi/linux/dma-buf.h >> @@ -47,4 +47,12 @@ struct dma_buf_sync { >>   #define DMA_BUF_SET_NAME_A    _IOW(DMA_BUF_BASE, 1, u32) >>   #define DMA_BUF_SET_NAME_B    _IOW(DMA_BUF_BASE, 1, u64) >>   +struct dma_buf_sync_partial { >> +    __u64 flags; >> +    __u32 offset; >> +    __u32 len; >> +}; >> + >> +#define DMA_BUF_IOCTL_SYNC_PARTIAL    _IOW(DMA_BUF_BASE, 2, struct >> dma_buf_sync_partial) >> + >>   #endif > > > _______________________________________________ > Linux-rockchip mailing list > Linux-rockchip@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-rockchip >