Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp3199964lqo; Wed, 15 May 2024 02:45:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXPNpKfPMQANDdH9BvmmkvW1yNvtMQXHVrzFVNpZnUXuzoCAoSMCJRFcZO8ICrvcrDHEC4uNI4nkxAjDc9WHWW6NONhGMrlq9jpyBS6MA== X-Google-Smtp-Source: AGHT+IFafqOrwI3YYXz3R3hm9xsi6RJVErG+KXg8qrsUfZ3bLbafiqjVUwTBI7sXmzyNNr+B2H0p X-Received: by 2002:a17:906:c413:b0:a59:a2f0:ee51 with SMTP id a640c23a62f3a-a5a2d65987dmr1531474066b.54.1715766342071; Wed, 15 May 2024 02:45:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715766342; cv=pass; d=google.com; s=arc-20160816; b=pNoXqGW7hC1OQJdMyk5P+VvSh9OpvNlJ1L8v8L8qaDix1G4zWtYB8Rf4pWzOy72yk5 YZyd3/WfZc5Xwl6Eo9L3WMrqoGsmoqnIzuf5dHOMg9ZeGSkZBJmR2QUpYeSduwHal/xQ D9HM55dmbSDnOymxabdEBkWTAXjKQZuhAyNLH7sJiuC+xrIsV4ONl3U5EdScN7cDV4R5 x7q/A48Oh9TCE4mCvJm4HhZ9AebRloF3PFdXJBNrPyF1MVMAG6s2KGrZ1Rqo4i2XRiux NNZhPgXD/PCi73qeDKW+V13i5aRNVJrUasSmpvUFqLAdM7eacJda04DfJpvRzYFPJQd1 vJrg== ARC-Message-Signature: i=2; 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=n6EkIVd0v6k33+WDHvOH1msWEs1FiIcoXhRYw7Xr9mg=; fh=1f7rhIu39CJkOXQAKOSyLqvzWywrT26Q80coJusjylo=; b=tzvJn3+Igju6z4fzC45k3ZHE4XjkuhjhhgF7XWyAs16zPeB/PtxBhCEMbRnyDQtUrP Kw+aHNtbMz8wHbU7PT0v2eQrw7stJxTc2GJCYoaEcq8SLfuOw7ySJOuJVE0cRZExC5zI asX8ChoaddXGG2Es7dLMxPB1ZE4S1kts4qqMoRWCMvkvZbOz4eRJ8NGucwkMTunSy0O6 7B0qlkN5pObU9AEc2PeCNo757x0uPd9jxgAKjrL/OdVoL4uH8aScSMxnN7NuhqpBXiQ0 P9uE58SCEZ/pmlw9JklQUjBxIqPfbv0/HhLI/wpB2iUhmeAAXtazfJ7Nk7PaBkwg7jpG yK3w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WmWbDqtN; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-179716-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179716-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a179461a2si733324766b.106.2024.05.15.02.45.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 02:45:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179716-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WmWbDqtN; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-179716-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179716-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A890A1F226EF for ; Wed, 15 May 2024 09:45:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CDD2F59154; Wed, 15 May 2024 09:45:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="WmWbDqtN" Received: from mail-oa1-f44.google.com (mail-oa1-f44.google.com [209.85.160.44]) (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 DF4473B78D for ; Wed, 15 May 2024 09:45:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715766334; cv=none; b=C1NIed+n15OjUfAWCn3+TvAN9m+zFXv9zUfRVwC4jTLnrb/j7kM/vs7b2C3zsxGXcQvmdROcGs9WL8hVpAcPAdWxFPWC1qI9+Han0bRbHDqcc+GW8EsZWGnJTOFsh2GWtLKKapwhYZeRbH8NIOJLHMF22t+I93odYCRQnY60n3A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715766334; c=relaxed/simple; bh=JRLsaes2n+fx1g7fTVlLvO0GErQiuRGa5Ukv0jsD8JU=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Udb3Cgnci6nvbBHXdNU4qweFXa8NYbqMrLz9sETtS7NMwpMcHPn7PV478sq0AtbmBAo+3p3NuCH3ycGZtVNni7/kyM9REEcuryJl+M6rYPAXDvyClu/nIYmw5i+gfcKArDbEBw7vQtGHhOhCgTeiOpL6VIhXaxLjZVRcBFOcz2k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=WmWbDqtN; arc=none smtp.client-ip=209.85.160.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oa1-f44.google.com with SMTP id 586e51a60fabf-244d692e9b9so1649052fac.3 for ; Wed, 15 May 2024 02:45:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715766332; x=1716371132; 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=n6EkIVd0v6k33+WDHvOH1msWEs1FiIcoXhRYw7Xr9mg=; b=WmWbDqtNry4Gl2cIJTlpeGQQlf6abdKndgdSRP+G47fnyyeddMNCL5MMusKIshNxE7 w5in/ubKi5tcx4bYpA1SgUgceRAkJQSCXUXyZYkiKopfXWImD/mTD4ZAa6vah0qXjVn/ awBBHoYd587s/6sGKblc3FqHtRZAJWTDb2NNzBPRTTxBpG6HknqcA+dzU2U5SUHiFWWE 1u8UJqqRZ02o77FAFXCi9pgJepkH7nB/Rz42cDhn87OrPQfioavGQlzIGix8EeuhP/h+ N4sf+pM22p0ov4wXj1DFKghk8uirc/LKp/NUOvBwmOx1qvzPY/+Axkel+Hal6ohCzdw3 7Khg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715766332; x=1716371132; 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=n6EkIVd0v6k33+WDHvOH1msWEs1FiIcoXhRYw7Xr9mg=; b=pdUmW//iH+uvxcSf/ONF9UPcnLOImAzdvNm7K1LevMlaTR6L8rwgsXmROWLlsOb20U QwH3cFHX19GjBHIVxt7RDJISiRxce33vYYZXVHaPHAeLpzA4AvRPc3Xxno/wwMSwl13/ s8hirsU9I5OcfeuSY7xNjSh5t03BIx46C8fqWvNGBrpF+gTSsq4a0cwDIpLdjCPubZAE zO1Pm0cogyDGJD7yvd3PgonME7sPWzpgCzhbiDUqWY07NwCVhtS95npU1t4lMx8jsZkw ydaC+5M1Qpg7+JlVEIVBEe6fvZDsZ/dUQgFQmswS4pmONX+wg9L91952On7dMjNOIWvA UhZg== X-Gm-Message-State: AOJu0YwVytrFICChxl7uh+iO5yvXG9cTvDyPVs1BDiwmHpmNbm24mr0C iRuCoBpCJeRL1ZH1r6F1GsNE2O45lO0NMflag1WC2xG57S2dmwBDqzzBf312oetbIioNaLxyQ1H 5O50IjQnUV49I5WvrHzXH6ubWDNN5i3x4avmHpQ== X-Received: by 2002:a05:6870:8552:b0:23c:ca10:cc23 with SMTP id 586e51a60fabf-24172f84d1emr16783291fac.51.1715766331748; Wed, 15 May 2024 02:45:31 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240507091619.2208810-1-jens.wiklander@linaro.org> <20240507091619.2208810-2-jens.wiklander@linaro.org> <2024051424-shack-blinking-547a@gregkh> <2024051544-clarinet-baffle-c9d6@gregkh> In-Reply-To: <2024051544-clarinet-baffle-c9d6@gregkh> From: Jens Wiklander Date: Wed, 15 May 2024 11:45:20 +0200 Message-ID: Subject: Re: [PATCH v6 1/3] rpmb: add Replay Protected Memory Block (RPMB) subsystem To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, op-tee@lists.trustedfirmware.org, Shyam Saini , Ulf Hansson , Linus Walleij , Jerome Forissier , Sumit Garg , Ilias Apalodimas , Bart Van Assche , Randy Dunlap , Ard Biesheuvel , Arnd Bergmann , Manuel Traut , Tomas Winkler , =?UTF-8?B?QWxleCBCZW5uw6ll?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, May 15, 2024 at 10:04=E2=80=AFAM Greg Kroah-Hartman wrote: > > On Wed, May 15, 2024 at 09:51:32AM +0200, Jens Wiklander wrote: > > On Tue, May 14, 2024 at 5:45=E2=80=AFPM Greg Kroah-Hartman > > wrote: > > > > > > On Tue, May 07, 2024 at 11:16:17AM +0200, Jens Wiklander wrote: > > > > A number of storage technologies support a specialised hardware > > > > partition designed to be resistant to replay attacks. The underlyin= g > > > > HW protocols differ but the operations are common. The RPMB partiti= on > > > > cannot be accessed via standard block layer, but by a set of specif= ic > > > > RPMB commands. Such a partition provides authenticated and replay > > > > protected access, hence suitable as a secure storage. > > > > > > > > The initial aim of this patch is to provide a simple RPMB driver > > > > interface which can be accessed by the optee driver to facilitate e= arly > > > > RPMB access to OP-TEE OS (secure OS) during the boot time. > > > > > > > > A TEE device driver can claim the RPMB interface, for example, via > > > > rpmb_interface_register() or rpmb_dev_find_device(). The RPMB drive= r > > > > provides a callback to route RPMB frames to the RPMB device accessi= ble > > > > via rpmb_route_frames(). > > > > > > > > The detailed operation of implementing the access is left to the TE= E > > > > device driver itself. > > > > > > > > Signed-off-by: Tomas Winkler > > > > Signed-off-by: Alex Benn=C3=A9e > > > > Signed-off-by: Shyam Saini > > > > Signed-off-by: Jens Wiklander > > > > Reviewed-by: Linus Walleij > > > > --- > > > > MAINTAINERS | 7 ++ > > > > drivers/misc/Kconfig | 10 ++ > > > > drivers/misc/Makefile | 1 + > > > > drivers/misc/rpmb-core.c | 233 +++++++++++++++++++++++++++++++++++= ++++ > > > > include/linux/rpmb.h | 136 +++++++++++++++++++++++ > > > > 5 files changed, 387 insertions(+) > > > > create mode 100644 drivers/misc/rpmb-core.c > > > > create mode 100644 include/linux/rpmb.h > > > > > > > > diff --git a/MAINTAINERS b/MAINTAINERS > > > > index 8999497011a2..e83152c42499 100644 > > > > --- a/MAINTAINERS > > > > +++ b/MAINTAINERS > > > > @@ -19012,6 +19012,13 @@ T: git git://linuxtv.org/media_tree.git > > > > F: Documentation/devicetree/bindings/media/allwinner,sun8i-a83t-= de2-rotate.yaml > > > > F: drivers/media/platform/sunxi/sun8i-rotate/ > > > > > > > > +RPMB SUBSYSTEM > > > > +M: Jens Wiklander > > > > +L: linux-kernel@vger.kernel.org > > > > +S: Supported > > > > +F: drivers/misc/rpmb-core.c > > > > +F: include/linux/rpmb.h > > > > + > > > > RPMSG TTY DRIVER > > > > M: Arnaud Pouliquen > > > > L: linux-remoteproc@vger.kernel.org > > > > diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig > > > > index 4fb291f0bf7c..dbff9e8c3a03 100644 > > > > --- a/drivers/misc/Kconfig > > > > +++ b/drivers/misc/Kconfig > > > > @@ -104,6 +104,16 @@ config PHANTOM > > > > If you choose to build module, its name will be phantom. If= unsure, > > > > say N here. > > > > > > > > +config RPMB > > > > + tristate "RPMB partition interface" > > > > + depends on MMC > > > > + help > > > > + Unified RPMB unit interface for RPMB capable devices such a= s eMMC and > > > > + UFS. Provides interface for in-kernel security controllers = to access > > > > + RPMB unit. > > > > + > > > > + If unsure, select N. > > > > + > > > > config TIFM_CORE > > > > tristate "TI Flash Media interface support" > > > > depends on PCI > > > > diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile > > > > index ea6ea5bbbc9c..8af058ad1df4 100644 > > > > --- a/drivers/misc/Makefile > > > > +++ b/drivers/misc/Makefile > > > > @@ -15,6 +15,7 @@ obj-$(CONFIG_LKDTM) +=3D lkdtm/ > > > > obj-$(CONFIG_TIFM_CORE) +=3D tifm_core.o > > > > obj-$(CONFIG_TIFM_7XX1) +=3D tifm_7xx1.o > > > > obj-$(CONFIG_PHANTOM) +=3D phantom.o > > > > +obj-$(CONFIG_RPMB) +=3D rpmb-core.o > > > > obj-$(CONFIG_QCOM_COINCELL) +=3D qcom-coincell.o > > > > obj-$(CONFIG_QCOM_FASTRPC) +=3D fastrpc.o > > > > obj-$(CONFIG_SENSORS_BH1770) +=3D bh1770glc.o > > > > diff --git a/drivers/misc/rpmb-core.c b/drivers/misc/rpmb-core.c > > > > new file mode 100644 > > > > index 000000000000..e42a45debc76 > > > > --- /dev/null > > > > +++ b/drivers/misc/rpmb-core.c > > > > @@ -0,0 +1,233 @@ > > > > +// SPDX-License-Identifier: GPL-2.0 > > > > +/* > > > > + * Copyright(c) 2015 - 2019 Intel Corporation. All rights reserved= . > > > > + * Copyright(c) 2021 - 2024 Linaro Ltd. > > > > + */ > > > > +#include > > > > +#include > > > > +#include > > > > +#include > > > > +#include > > > > +#include > > > > +#include > > > > +#include > > > > + > > > > +static struct list_head rpmb_dev_list; > > > > +static DEFINE_MUTEX(rpmb_mutex); > > > > +static struct blocking_notifier_head rpmb_interface =3D > > > > + BLOCKING_NOTIFIER_INIT(rpmb_interface); > > > > + > > > > +/** > > > > + * rpmb_dev_get() - increase rpmb device ref counter > > > > + * @rdev: rpmb device > > > > + */ > > > > +struct rpmb_dev *rpmb_dev_get(struct rpmb_dev *rdev) > > > > +{ > > > > + if (rdev) > > > > + get_device(rdev->parent_dev); > > > > > > Odd, why are you thinking the parent reference has anything to do wit= h > > > this device's reference? > > > > > > Why isn't this a "real" device and part of the driver model properly? > > > This way of "hanging onto" a device and attempting to influence it's > > > reference count is odd, please make this real and not "fake". > > > > I did this in response to > > https://lore.kernel.org/lkml/CAPDyKFqNhGWKm=3D+7niNsjXOjEJE3U=3Do7dRNG= =3DJqpptUSo9G-ug@mail.gmail.com/ > > And I would argue, "Yes, we do need yet-another class and sysfs entry". > > This is a "device" that a driver controls, it is NOT the parent device, > it is a class device, so as such, make it one. That's what the driver > model is for. Trying to avoid it causes problems. > > > Perhaps "parent_dev" isn't the best name. The struct rpmb_dev can be > > seen as another representation of the underlying device. > > I.e. a class device. So use that :) I see your point. > > > The life > > cycle of struct rpmb_dev is tied to the underlying device with > > rpmb_dev_register() and rpmb_dev_unregister(). Just as > > rpmb_route_frames() forwards the frames to the device, rpmb_dev_{get, > > put}() does the corresponding thing. > > You should never be modifying the reference count of a device you really > do not control, unless you are trying to make sure it is present to use > it yourself. > > > > Bonus, you get that notifier callback "for free" if you do that. But > > > really, notifier callbacks are a pain, are you sure you want that? > > > > Yes, they are needed because the device may show up late and the > > OP-TEE driver doesn't know if any device will show up. As Ulf pointed > > out in the link above, at this point, there's no need to tell user > > space about this kernel internal abstraction. > > If this is a representation of how the device is interacted with, then > yes, you do need to represent that. Thanks for straightening out this. I'll bring back the class device in the next version Cheers, Jens