Skip to contentSkip to conversation

dma-buf: add DMA_BUF_IOCTL_SYNC_PARTIAL support

PATCH In review Jianqun Xu 5 participants 15 messages Nov 13, 2021 – Apr 12, 2024

Subsystems (3)
lore
Share & tools
lore

Jianqun Xu

author
#0 lore raw

PATCH 1/1 dma-buf: add DMA_BUF_IOCTL_SYNC_PARTIAL support

Add DMA_BUF_IOCTL_SYNC_PARTIAL support for user to sync dma-buf with offset and len.

Change-Id I03d2d2e10e48d32aa83c31abade57e0931e1be49
---
 drivers/dma-buf/dma-buf.c    | 42 ++++++++++++++++++++++++++++++++++++
 include/uapi/linux/dma-buf.h |  8 +++++++
 2 files changed, 50 insertions(+)
drivers/dma-buf/dma-buf.c +42 -0
index d9948d58b3f4..78f37f7c3462 100644
@@ -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;
 	}
include/uapi/linux/dma-buf.h +8 -0
index 7f30393b92c3..6236c644624d 100644
@@ -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
Signature · 1 line
2.25.1
maintainer
#1 lore raw

Am 13.11.21 um 07:22 schrieb Jianqun Xu:

Quoted 2 lines

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.

Quoted 85 lines
Change-Id I03d2d2e10e48d32aa83c31abade57e0931e1be49
---
  drivers/dma-buf/dma-buf.c    | 42 ++++++++++++++++++++++++++++++++++++
  include/uapi/linux/dma-buf.h |  8 +++++++
  2 files changed, 50 insertions(+)
drivers/dma-buf/dma-buf.c +42 -0
index d9948d58b3f4..78f37f7c3462 100644
@@ -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;
  	}
include/uapi/linux/dma-buf.h +8 -0
index 7f30393b92c3..6236c644624d 100644
@@ -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
#2 lore raw
Quoted 526 lines · Christian König

Am 13.11.21 um 07:22 schrieb Jianqun Xu:

Quoted 2 lines

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.

Quoted 85 lines
Change-Id I03d2d2e10e48d32aa83c31abade57e0931e1be49

---
  drivers/dma-buf/dma-buf.c    | 42 ++++++++++++++++++++++++++++++++++++ include/uapi/linux/dma-buf.h |  8 +++++++

  2 files changed, 50 insertions(+)
drivers/dma-buf/dma-buf.c +1 -0
index d9948d58b3f4..78f37f7c3462 100644
@@ -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;

drivers/dma-buf/dma-buf.c +5 -0
+
+        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;

drivers/dma-buf/dma-buf.c +29 -0
+
+        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;
      }

include/uapi/linux/dma-buf.h +7 -0
index 7f30393b92c3..6236c644624d 100644
@@ -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)
+
Quoted 1 line

  #endif

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <[email protected]>
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 <[email protected]>; 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 <[email protected]>; 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 <[email protected]>; 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 <[email protected]>, [email protected]
References: <[email protected]>
From: =?UTF-8?Q?Christian_K=c3=b6nig?= <[email protected]>
Message-ID: <[email protected]>
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: <[email protected]>
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: <MWHPR12MB18370021933B2E90497B3E8C83989@MWHPR12MB1837.namprd12.prod.outlook.com>
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?NVI2K0xOaFQ3QlMyYitGMDRxa2JCVHQrQW40VnpPUkJ4SDN2UjRnU29TeHFU?= =?utf-8?B?cUVVSjEzLzV1ZFFxcndBbkw0T2Q0MHo3YUtoOThVTlgxcm5odjlqVzBYUkV3?= =?utf-8?B?RzM1dmllc3pTSFIvS0xaNWVoVDNWVXQ3Q1NJc0NpcjAwWUY1VkR0eEFhZnRX?= =?utf-8?B?R3gyeEIyMjR3SGVDdDhUaGtmZWRJTnkyeWhuWkpIVVg2RHoxQWtrUEJtNjdv?= =?utf-8?B?YlNmbzI2ME1hQkcrVVBNQ1pFT1FWZFRZZFhyZE9OWWJzRUlDM29pQUJ0V24y?= =?utf-8?B?NjRQM2g0a0J4NzJVVGw1MDRqMXFndVBJellQazRvUnFVMHFLRlR2Q3lJMlpq?= =?utf-8?B?V1F3b1BwZFpUM2xyYUpvR0RTcDJEZ1dGZWdMdDVHYzd2eW5ZYnlwTXlrckpD?= =?utf-8?B?OTdGU0w1My9SUVRkdmk3L1VaWDJseUc3S2tjdFhEZ3dUeDZ1RVIrK2ZNUDkv?= =?utf-8?B?aU9NbkZqRFpPQzFvVFpOWHYzd2QxS256OTRKaVQrVlR3c29nNHdwcjVjVklD?= =?utf-8?B?cVp6dFN0TUpNMDd1SlFzRUx2SjlraVczakM3VmFJdExzVGJ5cXdmSGlKTTVx?= =?utf-8?B?dHNCaUFjVmRPZkRuVFp1RVhWTFB0L1FtNHI1TEZEcTFsQUFMNjdUMnIxaVZr?= =?utf-8?B?d09MaXhiSFlrMjhPOGxrcGFLVElSR1pOQkdMdG4wa1k1VktnVVRFTXU0QlJk?= =?utf-8?B?Z09uemlVVHJxUHNoY3d1UXIrOUxCMU85bHM1TlpYRzZGcHRRcndtbERtdU9s?= =?utf-8?B?VUZRaVY2Z3N2RnlFbk14L1lER2Jib0JSSVNyZkw3Wk1sVExYaDhnMXRDUkhv?= =?utf-8?B?Z0FyK0NmMDlEKzcxUTdUY3A5SFJBYUhCOEpIbFNTK3Vic2hxcXR5MWZUcFND?= =?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: [email protected]
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Direct Rendering Infrastructure - Development
<dri-devel.lists.freedesktop.org>
List-Unsubscribe: <https://lists.freedesktop.org/mailman/options/dri-devel>,
<mailto:[email protected]?subject=unsubscribe>
List-Archive: <https://lists.freedesktop.org/archives/dri-devel>
List-Post: <mailto:[email protected]>
List-Help: <mailto:[email protected]?subject=help>
List-Subscribe: <https://lists.freedesktop.org/mailman/listinfo/dri-devel>,
<mailto:[email protected]?subject=subscribe>
Cc: [email protected], [email protected],
[email protected], [email protected], [email protected], [email protected],
[email protected], [email protected]
Errors-To: [email protected]
Sender: "dri-devel" <[email protected]>

Am 13.11.21 um 07:22 schrieb Jianqun Xu:

Quoted 2 lines

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.

Quoted 85 lines
Change-Id I03d2d2e10e48d32aa83c31abade57e0931e1be49

---
  drivers/dma-buf/dma-buf.c    | 42 ++++++++++++++++++++++++++++++++++++ include/uapi/linux/dma-buf.h |  8 +++++++

  2 files changed, 50 insertions(+)
drivers/dma-buf/dma-buf.c +1 -0
index d9948d58b3f4..78f37f7c3462 100644
@@ -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;

drivers/dma-buf/dma-buf.c +5 -0
+
+        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;

drivers/dma-buf/dma-buf.c +29 -0
+
+        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;
      }

include/uapi/linux/dma-buf.h +7 -0
index 7f30393b92c3..6236c644624d 100644
@@ -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)
+
Quoted 1 line

  #endif

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=bc75=QC=lists.infradead.org=linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@kernel.org>
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 <[email protected]>; 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 <[email protected]>; 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 [email protected]; 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 <[email protected]>, [email protected]
Cc: [email protected], [email protected],
[email protected], [email protected],
[email protected], [email protected],
[email protected], [email protected]
References: <[email protected]>
From: =?UTF-8?Q?Christian_K=c3=b6nig?= <[email protected]>
Message-ID: <[email protected]>
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: <[email protected]>
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: <MWHPR12MB18370021933B2E90497B3E8C83989@MWHPR12MB1837.namprd12.prod.outlook.com>
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?NVI2K0xOaFQ3QlMyYitGMDRxa2JCVHQrQW40VnpPUkJ4SDN2UjRnU29TeHFU?= =?utf-8?B?cUVVSjEzLzV1ZFFxcndBbkw0T2Q0MHo3YUtoOThVTlgxcm5odjlqVzBYUkV3?= =?utf-8?B?RzM1dmllc3pTSFIvS0xaNWVoVDNWVXQ3Q1NJc0NpcjAwWUY1VkR0eEFhZnRX?= =?utf-8?B?R3gyeEIyMjR3SGVDdDhUaGtmZWRJTnkyeWhuWkpIVVg2RHoxQWtrUEJtNjdv?= =?utf-8?B?YlNmbzI2ME1hQkcrVVBNQ1pFT1FWZFRZZFhyZE9OWWJzRUlDM29pQUJ0V24y?= =?utf-8?B?NjRQM2g0a0J4NzJVVGw1MDRqMXFndVBJellQazRvUnFVMHFLRlR2Q3lJMlpq?= =?utf-8?B?V1F3b1BwZFpUM2xyYUpvR0RTcDJEZ1dGZWdMdDVHYzd2eW5ZYnlwTXlrckpD?= =?utf-8?B?OTdGU0w1My9SUVRkdmk3L1VaWDJseUc3S2tjdFhEZ3dUeDZ1RVIrK2ZNUDkv?= =?utf-8?B?aU9NbkZqRFpPQzFvVFpOWHYzd2QxS256OTRKaVQrVlR3c29nNHdwcjVjVklD?= =?utf-8?B?cVp6dFN0TUpNMDd1SlFzRUx2SjlraVczakM3VmFJdExzVGJ5cXdmSGlKTTVx?= =?utf-8?B?dHNCaUFjVmRPZkRuVFp1RVhWTFB0L1FtNHI1TEZEcTFsQUFMNjdUMnIxaVZr?= =?utf-8?B?d09MaXhiSFlrMjhPOGxrcGFLVElSR1pOQkdMdG4wa1k1VktnVVRFTXU0QlJk?= =?utf-8?B?Z09uemlVVHJxUHNoY3d1UXIrOUxCMU85bHM1TlpYRzZGcHRRcndtbERtdU9s?= =?utf-8?B?VUZRaVY2Z3N2RnlFbk14L1lER2Jib0JSSVNyZkw3Wk1sVExYaDhnMXRDUkhv?= =?utf-8?B?Z0FyK0NmMDlEKzcxUTdUY3A5SFJBYUhCOEpIbFNTK3Vic2hxcXR5MWZUcFND?= =?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: [email protected]
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: Upstream kernel work for Rockchip platforms
<linux-rockchip.lists.infradead.org>
List-Unsubscribe: <http://lists.infradead.org/mailman/options/linux-rockchip>, <mailto:[email protected]?subject=unsubscribe>
List-Archive: <http://lists.infradead.org/pipermail/linux-rockchip/>
List-Post: <mailto:[email protected]>
List-Help: <mailto:[email protected]?subject=help>
List-Subscribe: <http://lists.infradead.org/mailman/listinfo/linux-rockchip>, <mailto:[email protected]?subject=subscribe>
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="us-ascii"; Format="flowed"
Sender: "Linux-rockchip" <[email protected]>
Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org

Am 13.11.21 um 07:22 schrieb Jianqun Xu:

Quoted 2 lines

Add DMA_BUF_IOCTL_SYNC_PARTIAL support for user to sync dma-buf with offset and len.

Quoted 6 lines

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.

Quoted 94 lines
Quoted 86 lines
Change-Id I03d2d2e10e48d32aa83c31abade57e0931e1be49

---
  drivers/dma-buf/dma-buf.c    | 42 ++++++++++++++++++++++++++++++++++++ include/uapi/linux/dma-buf.h |  8 +++++++

  2 files changed, 50 insertions(+)
drivers/dma-buf/dma-buf.c +1 -0
index d9948d58b3f4..78f37f7c3462 100644
@@ -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;

drivers/dma-buf/dma-buf.c +5 -0
+
+        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;

drivers/dma-buf/dma-buf.c +29 -0
+
+        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;
      }

include/uapi/linux/dma-buf.h +7 -0
index 7f30393b92c3..6236c644624d 100644
@@ -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)
+
Quoted 1 line

  #endif

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

maintainer
#3 lore raw

Am 07.04.24 um 09:50 schrieb Rong Qianfeng:

Quoted 9 lines

[SNIP]

Quoted 8 lines

Am 13.11.21 um 07:22 schrieb Jianqun Xu:

Quoted 2 lines

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.

Quoted 7 lines
Quoted 2 lines

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.

Well that is obvious, but where is the code doing that?

You can't send out code without an actual user of it. That will obviously be rejected.

Regards,
Christian.

Quoted 3 lines

Thanks
Rong Qianfeng.

#4 lore raw
Quoted 18 lines · Christian König

Am 07.04.24 um 09:50 schrieb Rong Qianfeng:

Quoted 9 lines

[SNIP]

Quoted 8 lines

Am 13.11.21 um 07:22 schrieb Jianqun Xu:

Quoted 2 lines

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.

Quoted 7 lines
Quoted 2 lines

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.

Quoted 6 lines

Well that is obvious, but where is the code doing that?

You can't send out code without an actual user of it. That will obviously be rejected.

Regards,
Christian.

In fact, we have already used the user-level dma-buf memory pool in the camera shooting scenario on the phone.

From the test results, The execution time of the photo shooting algorithm has been reduced from 3.8s to 3s.

To be honest, I didn't understand your concern "...how drivers should be able to fulfill this semantics." Can you please help explain it in more detail?

Thanks,

Rong Qianfeng.

Quoted 5 lines
Quoted 4 lines

Thanks
Rong Qianfeng.

maintainer
#5 lore raw

Am 09.04.24 um 09:32 schrieb Rong Qianfeng:

Quoted 24 lines · Christian König
Quoted 22 lines

Am 07.04.24 um 09:50 schrieb Rong Qianfeng:

Quoted 9 lines

[SNIP]

Quoted 8 lines

Am 13.11.21 um 07:22 schrieb Jianqun Xu:

Quoted 2 lines

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.

Quoted 7 lines
Quoted 2 lines

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.

Well that is obvious, but where is the code doing that?

You can't send out code without an actual user of it. That will obviously be rejected.

Quoted 8 lines
Quoted 2 lines

Regards,
Christian.

In fact, we have already used the user-level dma-buf memory pool in the camera shooting scenario on the phone.

From the test results, The execution time of the photo shooting algorithm has been reduced from 3.8s to 3s.

To be honest, I didn't understand your concern "...how drivers should be able to fulfill this semantics." Can you please help explain it in more detail?

Well you don't give any upstream driver code which actually uses this interface.

If you want to suggest some changes to the core Linux kernel your driver actually needs to be upstream.

As long as that isn't the case this approach here is a completely no-go.

Regards,
Christian.

Quoted 10 lines

Thanks,

Rong Qianfeng.

Quoted 5 lines
Quoted 4 lines

Thanks
Rong Qianfeng.

#6 lore raw
Quoted 32 lines · Christian König

Am 09.04.24 um 09:32 schrieb Rong Qianfeng:

Quoted 31 lines · Christian König
Quoted 18 lines

Am 07.04.24 um 09:50 schrieb Rong Qianfeng:

Quoted 9 lines

[SNIP]

Quoted 8 lines

Am 13.11.21 um 07:22 schrieb Jianqun Xu:

Quoted 2 lines

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.

Quoted 7 lines
Quoted 2 lines

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.

Quoted 6 lines

Well that is obvious, but where is the code doing that?

You can't send out code without an actual user of it. That will obviously be rejected.

Regards,
Christian.

In fact, we have already used the user-level dma-buf memory pool in the camera shooting scenario on the phone.

From the test results, The execution time of the photo shooting algorithm has been reduced from 3.8s to 3s.

Quoted 7 lines
Quoted 1 line

To be honest, I didn't understand your concern "...how drivers should be able to fulfill this semantics." Can you please help explain it in more detail?

Well you don't give any upstream driver code which actually uses this interface.

If you want to suggest some changes to the core Linux kernel your driver actually needs to be upstream.

As long as that isn't the case this approach here is a completely no-go.

Ok, I get it now, thanks!

Regards,

Rong Qianfeng.

Quoted 15 lines

Regards,
Christian.

Quoted 10 lines

Thanks,

Rong Qianfeng.

Quoted 5 lines
Quoted 4 lines

Thanks
Rong Qianfeng.

#7 lore raw
In reply to Rong Qianfeng
Quoted 34 lines · Rong Qianfeng
Quoted 31 lines · Christian König

Am 07.04.24 um 09:50 schrieb Rong Qianfeng:

Quoted 14 lines

[SNIP]

Quoted 8 lines

Am 13.11.21 um 07:22 schrieb Jianqun Xu:

Quoted 2 lines

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.

Quoted 5 lines

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.

Quoted 10 lines

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.

Well that is obvious, but where is the code doing that?

You can't send out code without an actual user of it. That will obviously be rejected.

Quoted 9 lines
Quoted 2 lines

Regards,
Christian.

In fact, we have already used the user-level dma-buf memory pool in the camera shooting scenario on the phone.

From the test results, The execution time of the photo shooting
algorithm has been reduced from 3.8s to 3s.

For phones, the (out of tree) Android version of the system heap has a page pool connected to a shrinker. That allows you to skip page allocation without fully pinning the memory like you get when allocating a dma-buf that's way larger than necessary. If it's for a camera maybe you need physically contiguous memory, but it's also possible to set that up.

https://android.googlesource.com/kernel/common/+/refs/heads/android14-6.1/drivers/dma-buf/heaps/system_heap.c#377

Quoted 14 lines

To be honest, I didn't understand your concern "...how drivers should be able to fulfill this semantics." Can you please help explain it in more detail?

Thanks,

Rong Qianfeng.

Quoted 5 lines
Quoted 4 lines

Thanks
Rong Qianfeng.

maintainer
#8 lore raw

Am 09.04.24 um 18:37 schrieb T.J. Mercier:

Quoted 34 lines · Rong Qianfeng
Quoted 33 lines · Christian König
Quoted 31 lines

Am 07.04.24 um 09:50 schrieb Rong Qianfeng:

Quoted 13 lines

[SNIP]

Quoted 7 lines

Am 13.11.21 um 07:22 schrieb Jianqun Xu:

Quoted 2 lines

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.

Quoted 5 lines

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.

Quoted 10 lines

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.

Well that is obvious, but where is the code doing that?

You can't send out code without an actual user of it. That will obviously be rejected.

Regards,
Christian.

Quoted 8 lines
Quoted 6 lines

In fact, we have already used the user-level dma-buf memory pool in the camera shooting scenario on the phone.

From the test results, The execution time of the photo shooting
algorithm has been reduced from 3.8s to 3s.

For phones, the (out of tree) Android version of the system heap has a page pool connected to a shrinker.

Well, it should be obvious but I'm going to repeat it here: Submitting kernel patches for our of tree code is a rather *extreme* no-go.

That in kernel code *must* have an in kernel user is a number one rule.

When somebody violates this rule he pretty much disqualifying himself as reliable source of patches since maintainers then have to assume that this person tries to submit code which doesn't have a justification to be upstream.

So while this actually looks useful from the technical side as long as nobody does an implementation based on an upstream driver I absolutely have to reject it from the organizational side.

Regards,
Christian.

Quoted 19 lines

That allows you to skip page
allocation without fully pinning the memory like you get when allocating a dma-buf that's way larger than necessary. If it's for a camera maybe you need physically contiguous memory, but it's also possible to set that up.

https://android.googlesource.com/kernel/common/+/refs/heads/android14-6.1/drivers/dma-buf/heaps/system_heap.c#377

Quoted 10 lines

To be honest, I didn't understand your concern "...how drivers should be able to fulfill this semantics." Can you please help explain it in more detail?

Thanks,

Rong Qianfeng.

Quoted 2 lines
Quoted 2 lines

Thanks
Rong Qianfeng.

#9 lore raw
Quoted 39 lines · Christian König

Am 09.04.24 um 18:37 schrieb T.J. Mercier:

Quoted 37 lines · Rong Qianfeng
Quoted 36 lines · Christian König
Quoted 24 lines

Am 07.04.24 um 09:50 schrieb Rong Qianfeng:

Quoted 13 lines

[SNIP]

Quoted 7 lines

Am 13.11.21 um 07:22 schrieb Jianqun Xu:

Quoted 2 lines

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.

Quoted 5 lines

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.

Quoted 10 lines

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.

Quoted 7 lines

Well that is obvious, but where is the code doing that?

You can't send out code without an actual user of it. That will obviously be rejected.

Regards,
Christian.

In fact, we have already used the user-level dma-buf memory pool in the camera shooting scenario on the phone.

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

From the test results, The execution time of the photo shooting
algorithm has been reduced from 3.8s to 3s.

For phones, the (out of tree) Android version of the system heap has a page pool connected to a shrinker.

Well, it should be obvious but I'm going to repeat it here: Submitting kernel patches for our of tree code is a rather *extreme* no-go.

Sorry I think my comment led to some confusion. I wasn't suggesting you should take the patch; it's clearly incomplete. I was pointing out another option to Rong. It appears Rong is creating a single oversized dma-buf, and subdividing it in userspace to avoid multiple allocations for multiple buffers. That would lead to a need for a partial sync of the buffer from userspace. Instead of that, using a heap with a page pool gets you kind of the same thing with a lot less headache in userspace, and no need for partial sync. So I wanted to share that option, and that can go in just Android if necessary without this patch.

Quoted 34 lines

That in kernel code *must* have an in kernel user is a number one rule.

When somebody violates this rule he pretty much disqualifying himself as reliable source of patches since maintainers then have to assume that this person tries to submit code which doesn't have a justification to be upstream.

So while this actually looks useful from the technical side as long as nobody does an implementation based on an upstream driver I absolutely have to reject it from the organizational side.

Regards,
Christian.

Quoted 19 lines

That allows you to skip page
allocation without fully pinning the memory like you get when allocating a dma-buf that's way larger than necessary. If it's for a camera maybe you need physically contiguous memory, but it's also possible to set that up.

https://android.googlesource.com/kernel/common/+/refs/heads/android14-6.1/drivers/dma-buf/heaps/system_heap.c#377

Quoted 10 lines

To be honest, I didn't understand your concern "...how drivers should be able to fulfill this semantics." Can you please help explain it in more detail?

Thanks,

Rong Qianfeng.

Quoted 2 lines
Quoted 2 lines

Thanks
Rong Qianfeng.

#10 lore raw
Quoted 49 lines · T.J. Mercier

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Quoted 37 lines · Christian König

Am 09.04.24 um 18:37 schrieb T.J. Mercier:

Quoted 36 lines · Rong Qianfeng
Quoted 35 lines · Christian König
Quoted 24 lines

Am 07.04.24 um 09:50 schrieb Rong Qianfeng:

Quoted 13 lines

[SNIP]

Quoted 7 lines

Am 13.11.21 um 07:22 schrieb Jianqun Xu:

Quoted 2 lines

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.

Quoted 5 lines

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.

Quoted 10 lines

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.

Quoted 7 lines

Well that is obvious, but where is the code doing that?

You can't send out code without an actual user of it. That will obviously be rejected.

Regards,
Christian.

In fact, we have already used the user-level dma-buf memory pool in the camera shooting scenario on the phone.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

From the test results, The execution time of the photo shooting
algorithm has been reduced from 3.8s to 3s.

For phones, the (out of tree) Android version of the system heap has a page pool connected to a shrinker.

Well, it should be obvious but I'm going to repeat it here: Submitting kernel patches for our of tree code is a rather *extreme* no-go.

Quoted 10 lines

Sorry I think my comment led to some confusion. I wasn't suggesting you should take the patch; it's clearly incomplete. I was pointing out another option to Rong. It appears Rong is creating a single oversized dma-buf, and subdividing it in userspace to avoid multiple allocations for multiple buffers. That would lead to a need for a partial sync of the buffer from userspace. Instead of that, using a heap with a page pool gets you kind of the same thing with a lot less headache in userspace, and no need for partial sync. So I wanted to share that option, and that can go in just Android if necessary without this patch.

Hi T.J.

If there is a chance to use this patch on Android, I can explain to you in detail

why the user layer needs the dma-buf memory pool.

Thanks

Rong Qianfeng

Quoted 34 lines
Quoted 34 lines

That in kernel code *must* have an in kernel user is a number one rule.

When somebody violates this rule he pretty much disqualifying himself as reliable source of patches since maintainers then have to assume that this person tries to submit code which doesn't have a justification to be upstream.

So while this actually looks useful from the technical side as long as nobody does an implementation based on an upstream driver I absolutely have to reject it from the organizational side.

Regards,
Christian.

Quoted 19 lines

That allows you to skip page
allocation without fully pinning the memory like you get when allocating a dma-buf that's way larger than necessary. If it's for a camera maybe you need physically contiguous memory, but it's also possible to set that up.

https://android.googlesource.com/kernel/common/+/refs/heads/android14-6.1/drivers/dma-buf/heaps/system_heap.c#377

Quoted 10 lines

To be honest, I didn't understand your concern "...how drivers should be able to fulfill this semantics." Can you please help explain it in more detail?

Thanks,

Rong Qianfeng.

Quoted 2 lines
Quoted 2 lines

Thanks
Rong Qianfeng.

maintainer
#11 lore raw
In reply to T.J. Mercier

Am 10.04.24 um 17:07 schrieb T.J. Mercier:

Quoted 47 lines
Quoted 37 lines · Christian König

Am 09.04.24 um 18:37 schrieb T.J. Mercier:

Quoted 36 lines · Rong Qianfeng
Quoted 35 lines · Christian König
Quoted 24 lines

Am 07.04.24 um 09:50 schrieb Rong Qianfeng:

Quoted 13 lines

[SNIP]

Quoted 7 lines

Am 13.11.21 um 07:22 schrieb Jianqun Xu:

Quoted 2 lines

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.

Quoted 5 lines

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.

Quoted 10 lines

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.

Quoted 7 lines

Well that is obvious, but where is the code doing that?

You can't send out code without an actual user of it. That will obviously be rejected.

Regards,
Christian.

In fact, we have already used the user-level dma-buf memory pool in the camera shooting scenario on the phone.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

From the test results, The execution time of the photo shooting
algorithm has been reduced from 3.8s to 3s.

For phones, the (out of tree) Android version of the system heap has a page pool connected to a shrinker.

Well, it should be obvious but I'm going to repeat it here: Submitting kernel patches for our of tree code is a rather *extreme* no-go.

Quoted 10 lines

Sorry I think my comment led to some confusion. I wasn't suggesting you should take the patch; it's clearly incomplete. I was pointing out another option to Rong. It appears Rong is creating a single oversized dma-buf, and subdividing it in userspace to avoid multiple allocations for multiple buffers. That would lead to a need for a partial sync of the buffer from userspace. Instead of that, using a heap with a page pool gets you kind of the same thing with a lot less headache in userspace, and no need for partial sync. So I wanted to share that option, and that can go in just Android if necessary without this patch.

Ah! Thanks for the clarification and sorry for any noise I created.

I mean from the technical side the patch doesn't looks invalid or anything, but there is simply no upstream use case.

Regards,
Christian.

Quoted 34 lines
Quoted 34 lines

That in kernel code *must* have an in kernel user is a number one rule.

When somebody violates this rule he pretty much disqualifying himself as reliable source of patches since maintainers then have to assume that this person tries to submit code which doesn't have a justification to be upstream.

So while this actually looks useful from the technical side as long as nobody does an implementation based on an upstream driver I absolutely have to reject it from the organizational side.

Regards,
Christian.

Quoted 19 lines

That allows you to skip page
allocation without fully pinning the memory like you get when allocating a dma-buf that's way larger than necessary. If it's for a camera maybe you need physically contiguous memory, but it's also possible to set that up.

https://android.googlesource.com/kernel/common/+/refs/heads/android14-6.1/drivers/dma-buf/heaps/system_heap.c#377

Quoted 10 lines

To be honest, I didn't understand your concern "...how drivers should be able to fulfill this semantics." Can you please help explain it in more detail?

Thanks,

Rong Qianfeng.

Quoted 2 lines
Quoted 2 lines

Thanks
Rong Qianfeng.

#12 lore raw
In reply to T.J. Mercier
Quoted 42 lines · T.J. Mercier

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Quoted 31 lines · Rong Qianfeng
Quoted 29 lines · Christian König

Am 07.04.24 um 09:50 schrieb Rong Qianfeng:

Quoted 13 lines

[SNIP]

Quoted 7 lines

Am 13.11.21 um 07:22 schrieb Jianqun Xu:

Quoted 2 lines

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.

Quoted 5 lines

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.

Quoted 10 lines

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.

Well that is obvious, but where is the code doing that?

You can't send out code without an actual user of it. That will obviously be rejected.

Quoted 8 lines
Quoted 2 lines

Regards,
Christian.

In fact, we have already used the user-level dma-buf memory pool in the camera shooting scenario on the phone.

From the test results, The execution time of the photo shooting
algorithm has been reduced from 3.8s to 3s.

Quoted 9 lines

For phones, the (out of tree) Android version of the system heap has a page pool connected to a shrinker. That allows you to skip page allocation without fully pinning the memory like you get when allocating a dma-buf that's way larger than necessary. If it's for a camera maybe you need physically contiguous memory, but it's also possible to set that up.

https://android.googlesource.com/kernel/common/+/refs/heads/android14-6.1/drivers/dma-buf/heaps/system_heap.c#377

Thank you for the reminder.

The page pool of the system heap can meet the needs of most scenarios, but the camera shooting scenario is quite special.

Why the camera shooting scenario needs to have a dma-buf memory pool in the user-level?

(1) The memory demand is extremely high and time requirements are stringent.

(2) The memory in the page pool(system heap) is easily reclaimed or used by other apps.

(3) High concurrent allocation and release (with deferred-free) lead to high memory usage peaks.

Additionally, after the camera exits, the shared memory pool can be released, with minimal impact.

Thanks

Rong Qianfeng

Quoted 10 lines
Quoted 10 lines

To be honest, I didn't understand your concern "...how drivers should be able to fulfill this semantics." Can you please help explain it in more detail?

Thanks,

Rong Qianfeng.

Quoted 2 lines
Quoted 2 lines

Thanks
Rong Qianfeng.

#13 lore raw
Quoted 56 lines · Rong Qianfeng
Quoted 42 lines · T.J. Mercier

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Quoted 31 lines · Rong Qianfeng
Quoted 29 lines · Christian König

Am 07.04.24 um 09:50 schrieb Rong Qianfeng:

Quoted 13 lines

[SNIP]

Quoted 7 lines

Am 13.11.21 um 07:22 schrieb Jianqun Xu:

Quoted 2 lines

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.

Quoted 5 lines

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.

Quoted 10 lines

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.

Well that is obvious, but where is the code doing that?

You can't send out code without an actual user of it. That will obviously be rejected.

Quoted 8 lines
Quoted 2 lines

Regards,
Christian.

In fact, we have already used the user-level dma-buf memory pool in the camera shooting scenario on the phone.

From the test results, The execution time of the photo shooting
algorithm has been reduced from 3.8s to 3s.

Quoted 9 lines

For phones, the (out of tree) Android version of the system heap has a page pool connected to a shrinker. That allows you to skip page allocation without fully pinning the memory like you get when allocating a dma-buf that's way larger than necessary. If it's for a camera maybe you need physically contiguous memory, but it's also possible to set that up.

https://android.googlesource.com/kernel/common/+/refs/heads/android14-6.1/drivers/dma-buf/heaps/system_heap.c#377

Thank you for the reminder.

Quoted 8 lines

The page pool of the system heap can meet the needs of most scenarios, but the camera shooting scenario is quite special.

Why the camera shooting scenario needs to have a dma-buf memory pool in the user-level?

(1) The memory demand is extremely high and time requirements are stringent.

Preallocating for this makes sense to me, whether it is individual buffers or one large one.

Quoted 2 lines

(2) The memory in the page pool(system heap) is easily reclaimed or used by other apps.

Yeah, by design I guess. I have seen an implementation where the page pool is proactively refilled after it has been empty for some time which would help in scenarios where the pool is often reclaimed and low/empty. You could add that in a vendor heap.

Quoted 2 lines

(3) High concurrent allocation and release (with deferred-free) lead to high memory usage peaks.

Hopefully this is not every frame? I saw enough complaints about the deferred free of pool pages that it hasn't been carried forward since Android 13, so this should be less of a problem on recent kernels.

Quoted 2 lines

Additionally, after the camera exits, the shared memory pool can be released, with minimal impact.

Why do you care about the difference here? In one case it's when the buffer refcount goes to 0 and memory is freed immediately, and in the other it's the next time reclaim runs the shrinker.

I don't want to add UAPI for DMA_BUF_IOCTL_SYNC_PARTIAL to Android without it being in the upstream kernel. I don't think we can get that without an in-kernel user of dma_buf_begin_cpu_access_partial first, even though your use case wouldn't rely on that in-kernel usage. :\ So if you want to add this to phones for your camera app, then I think your best option is to add a vendor driver which implements this IOCTL and calls the dma_buf_begin_cpu_access_partial functions which are already exported.

Best,
T.J.

#14 lore raw
Quoted 66 lines · T.J. Mercier
Quoted 54 lines · Rong Qianfeng
Quoted 41 lines · T.J. Mercier

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Quoted 30 lines · Rong Qianfeng
Quoted 29 lines · Christian König

Am 07.04.24 um 09:50 schrieb Rong Qianfeng:

Quoted 13 lines

[SNIP]

Quoted 7 lines

Am 13.11.21 um 07:22 schrieb Jianqun Xu:

Quoted 2 lines

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.

Quoted 5 lines

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.

Quoted 10 lines

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.

Well that is obvious, but where is the code doing that?

You can't send out code without an actual user of it. That will obviously be rejected.

Quoted 8 lines
Quoted 2 lines

Regards,
Christian.

In fact, we have already used the user-level dma-buf memory pool in the camera shooting scenario on the phone.

From the test results, The execution time of the photo shooting
algorithm has been reduced from 3.8s to 3s.

Quoted 9 lines

For phones, the (out of tree) Android version of the system heap has a page pool connected to a shrinker. That allows you to skip page allocation without fully pinning the memory like you get when allocating a dma-buf that's way larger than necessary. If it's for a camera maybe you need physically contiguous memory, but it's also possible to set that up.

https://android.googlesource.com/kernel/common/+/refs/heads/android14-6.1/drivers/dma-buf/heaps/system_heap.c#377

Thank you for the reminder.

Quoted 8 lines

The page pool of the system heap can meet the needs of most scenarios, but the camera shooting scenario is quite special.

Why the camera shooting scenario needs to have a dma-buf memory pool in the user-level?

(1) The memory demand is extremely high and time requirements are stringent.

Preallocating for this makes sense to me, whether it is individual buffers or one large one.

Quoted 6 lines
Quoted 2 lines

(2) The memory in the page pool(system heap) is easily reclaimed or used by other apps.

Yeah, by design I guess. I have seen an implementation where the page pool is proactively refilled after it has been empty for some time which would help in scenarios where the pool is often reclaimed and low/empty. You could add that in a vendor heap.

Yeah, a similar feature has already been implemented by vendor.

Quoted 7 lines
Quoted 3 lines

(3) High concurrent allocation and release (with deferred-free) lead to high memory usage peaks.

Hopefully this is not every frame? I saw enough complaints about the deferred free of pool pages that it hasn't been carried forward since Android 13, so this should be less of a problem on recent kernels.

Quoted 5 lines
Quoted 2 lines

Additionally, after the camera exits, the shared memory pool can be released, with minimal impact.

Why do you care about the difference here? In one case it's when the buffer refcount goes to 0 and memory is freed immediately, and in the other it's the next time reclaim runs the shrinker.

I'm sorry, my description wasn't clear enough. What I meant to explain is that the user-level dma-buf memory pool does not use reserved memory (physically contiguous memory), and the memoryoccupation time is not too long, resulting in a minimal impact on the system.

Quoted 10 lines

I don't want to add UAPI for DMA_BUF_IOCTL_SYNC_PARTIAL to Android without it being in the upstream kernel. I don't think we can get that without an in-kernel user of dma_buf_begin_cpu_access_partial first, even though your use case wouldn't rely on that in-kernel usage. :\ So if you want to add this to phones for your camera app, then I think your best option is to add a vendor driver which implements this IOCTL and calls the dma_buf_begin_cpu_access_partial functions which are already exported.

Ok, thank you very much for your suggestion. I will definitely take it into consideration.

Quoted 3 lines

Best,
T.J.