Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2590392rdd; Fri, 12 Jan 2024 14:53:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IGbvJB89X4YrbeutdEldQlOQ8aqUZnJir9XSffMUsd6uMLgJWL49YTGQp/XY/MAABFhb4BH X-Received: by 2002:a05:6808:3a17:b0:3bb:c1dd:f3ab with SMTP id gr23-20020a0568083a1700b003bbc1ddf3abmr2932908oib.38.1705099985850; Fri, 12 Jan 2024 14:53:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705099985; cv=none; d=google.com; s=arc-20160816; b=e93Y8IrGvwFnCFjpIkwlPZ9rd8KFCkBAMXm8tCxYAy5ycMRrGApW1VuNeF8snZDjh4 RL9oRVBC1u8R7vV+DOKNSHVCD2DyE08jqEvMrndOKVM6ATJg1C1UJx0X4wLhd+96sARx GBPQjkAW1S6KoUYkbGXFfn4sGeOIAU20r6hJwxLY1DsXwwzrJ86GAR9gfAuxiffebBFY p348UBcgnMA+YDUtSGqYgfjjIMTJRd/OQ63oWjiewin8Js5Ope0Pudvn1vHXLPtfEItZ 4AP0J3TbHEIyT9SuRboZ5T7QQESwbn0HGXLZCsv3LIw2R/P/K9i3dvlbTGu7UDt3u1XM VABQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=5zEBqjbWZbZ/3Uylirb4GeOi3RLFiwNvDX78phkZWD8=; fh=SQcvd5rjOqdPPecVYqXp1psR2AGYbhPMkrnWJwS39LY=; b=O/UfXqY+sNUWBRwS+NOYmC6Zv2w0C8iYrkUQAIpUjt8zf9pqM7NhVVIB4shlp6DqDa rftHtHI7K12uVnPkoLCVzZo1skv5alhJ1yyxi/a630h0CqxOLILum20D+OwKBcLh/8T5 6tcGKlhJALmumSeVAT1wqp2s3s62hR9qp+Yzwa8hwr1JH1vdP19O9flyW0nubHhcDZjN HTvimiiGv82DFq8MvgeWty1XsLloMRjrn6xzTJ23dFhZ2g4cMrYnu8pgfXmiVeyKHphQ 3BCJOAoZ63lfYEkOqm7V634d4SRm+PRKZv77tl9iWg9zr1EN7yfCFyUgHUPD+8rRDQtI pTvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=c5qcLjF5; spf=pass (google.com: domain of linux-kernel+bounces-25083-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25083-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id du21-20020a056a002b5500b006dabae16930si3929594pfb.102.2024.01.12.14.53.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 14:53:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25083-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=c5qcLjF5; spf=pass (google.com: domain of linux-kernel+bounces-25083-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25083-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 5614AB241C2 for ; Fri, 12 Jan 2024 22:53:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9E85718C32; Fri, 12 Jan 2024 22:52:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="c5qcLjF5" Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E15D18B0C for ; Fri, 12 Jan 2024 22:52:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-553e36acfbaso4068a12.0 for ; Fri, 12 Jan 2024 14:52:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705099969; x=1705704769; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=5zEBqjbWZbZ/3Uylirb4GeOi3RLFiwNvDX78phkZWD8=; b=c5qcLjF5G6rsdOJSEN+5jNUHtaJnz6bg7DZd4TSYSqQlU69Btav9OyEpNvGvhq3rab FNQJK0of7qznSdVcvCFVRGru+BYD31/qz7NC6AHp44IrONbUvE6bDEa1Q0YGVlyXtvUU KQPO89/QEm3MTb8C7uGUMGqB51qIP6pO5LVG2SuKQf3RCLFrbBAUGbT90GN6uzcJO+tD xVaMuzulaP5Qxw4Pe7+wtK3mi58rzoEhlnynwPY40AnT9adIRqN/7Bn0BE5sVpgzYr7N cxA2l4/xBs0dSf0qvDZkj4mLoE9R2j3uXyx8vYjWlDJCZIgBtkPxl3LwNDHwOdJyaece 683A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705099969; x=1705704769; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5zEBqjbWZbZ/3Uylirb4GeOi3RLFiwNvDX78phkZWD8=; b=QIg2JgNm3zsJjCpxk4+TpDUH5R7CyHVcc5mCm1XY0bG2Ry6fH16rloVrZnEgaWNLP2 dwSRAfzK65cNHorb0BOubsUd+zsaH8rzYiZyUgs+iz8XVQNWxL4T8LxBnGJgFnP77jtL +n9HdZORTM/nR+oVlDrvBcJdguQzJR4Ei9+dGU9vpCt3/t6DrE4rBtTYaXbvhJzsmR0Y kuiFv3qGegbloHL8qoD6t7Z8BZmiOWkWAmXRuDeA2nJm7lVo40p9tDlna1t2ecD8qnxX s74kVQoWqY819lZwzvPekE9iWE+zIYn9l8d+6wtDO75LK63WzsU02AjvLBvLut0Ddxe4 M5QA== X-Gm-Message-State: AOJu0YyyNQ4wEaNXdYMXsbOqgFZ1TFx+Um8fpMgM6WNNYROibH/qo0PO 0tNKrvDBahVL/koaDQMFFtEpXC/2I4jLgL6MmqVd0Io0pr0= X-Received: by 2002:aa7:c98b:0:b0:554:2501:cc8e with SMTP id c11-20020aa7c98b000000b005542501cc8emr18281edt.6.1705099969244; Fri, 12 Jan 2024 14:52:49 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240112092014.23999-1-yong.wu@mediatek.com> <20240112092014.23999-4-yong.wu@mediatek.com> In-Reply-To: <20240112092014.23999-4-yong.wu@mediatek.com> From: John Stultz Date: Fri, 12 Jan 2024 14:52:37 -0800 Message-ID: Subject: Re: [PATCH v4 3/7] dma-buf: heaps: restricted_heap: Add private heap ops To: Yong Wu Cc: Rob Herring , Matthias Brugger , christian.koenig@amd.com, Sumit Semwal , Krzysztof Kozlowski , Conor Dooley , Benjamin Gaignard , Brian Starkey , tjmercier@google.com, AngeloGioacchino Del Regno , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Robin Murphy , Vijayanand Jitta , Joakim Bech , Jeffrey Kardatzke , Pavel Machek , Simon Ser , Pekka Paalanen , jianjiao.zeng@mediatek.com, kuohong.wang@mediatek.com, youlin.pei@mediatek.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jan 12, 2024 at 1:21=E2=80=AFAM Yong Wu wrot= e: > > Add "struct restricted_heap_ops". For the restricted memory, totally ther= e > are two steps: > a) memory_alloc: Allocate the buffer in kernel; > b) memory_restrict: Restrict/Protect/Secure that buffer. > The memory_alloc is mandatory while memory_restrict is optinal since it m= ay > be part of memory_alloc. > > Signed-off-by: Yong Wu > --- > drivers/dma-buf/heaps/restricted_heap.c | 41 ++++++++++++++++++++++++- > drivers/dma-buf/heaps/restricted_heap.h | 12 ++++++++ > 2 files changed, 52 insertions(+), 1 deletion(-) > Thanks for sending this out! A thought below. > diff --git a/drivers/dma-buf/heaps/restricted_heap.h b/drivers/dma-buf/he= aps/restricted_heap.h > index 443028f6ba3b..ddeaf9805708 100644 > --- a/drivers/dma-buf/heaps/restricted_heap.h > +++ b/drivers/dma-buf/heaps/restricted_heap.h > @@ -15,6 +15,18 @@ struct restricted_buffer { > > struct restricted_heap { > const char *name; > + > + const struct restricted_heap_ops *ops; > +}; > + > +struct restricted_heap_ops { > + int (*heap_init)(struct restricted_heap *heap); > + > + int (*memory_alloc)(struct restricted_heap *heap, struct rest= ricted_buffer *buf); > + void (*memory_free)(struct restricted_heap *heap, struct restr= icted_buffer *buf); > + > + int (*memory_restrict)(struct restricted_heap *heap, struct r= estricted_buffer *buf); > + void (*memory_unrestrict)(struct restricted_heap *heap, struct= restricted_buffer *buf); > }; > > int restricted_heap_add(struct restricted_heap *rstrd_heap); So, I'm a little worried here, because you're basically turning the restricted_heap dma-buf heap driver into a framework itself. Where this patch is creating a subdriver framework. Part of my hesitancy, is you're introducing this under the dma-buf heaps. For things like CMA, that's more of a core subsystem that has multiple users, and exporting cma buffers via dmabuf heaps is just an additional interface. What I like about that is the core kernel has to define the semantics for the memory type and then the dmabuf heap is just exporting that well understood type of buffer. But with these restricted buffers, I'm not sure there's yet a well understood set of semantics nor a central abstraction for that which other drivers use directly. I know part of this effort here is to start to centralize all these vendor specific restricted buffer implementations, which I think is great, but I just worry that in doing it in the dmabuf heap interface, it is a bit too user-facing. The likelihood of encoding a particular semantic to the singular "restricted_heap" name seems high. Similarly we might run into systems with multiple types of restricted buffers (imagine a discrete gpu having one type along with TEE protected buffers also being used on the same system). So the one question I have: Why not just have a mediatek specific restricted_heap dmabuf heap driver? Since there's already been some talk of slight semantic differences in various restricted buffer implementations, should we just start with separately named dmabuf heaps for each? Maybe consolidating to a common name as more drivers arrive and we gain a better understanding of the variations of semantics folks are using? thanks -john