Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1787294imu; Thu, 24 Jan 2019 01:46:33 -0800 (PST) X-Google-Smtp-Source: ALg8bN6+aBUNjxSDYLCm+PwLhMBLnaSJ8Su2G6b5gGc9an0eGquPWIB0YwB6fjvWXDaBkZpB/bg1 X-Received: by 2002:a17:902:8b88:: with SMTP id ay8mr5970009plb.55.1548323193170; Thu, 24 Jan 2019 01:46:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548323193; cv=none; d=google.com; s=arc-20160816; b=T94F1bg90imC6jyEwHged3SVM5j1h0ajZtnQIVWJqnzmqH3yPcvkS5thfPYHMYZeIy aj8f5X2iUQDbBExppsp4rQt2qesjfyAdd5G9uNdNa2F50T/zAvOXuqdbYuknbTCgHVeo Oj3NgDRigKhpC8GAlEPL9aTaHlDUn64UH7oA40nSynQ9htD0FApnkXzYz4sHeNzPR0Kt clAV+vinJVHMNyywSJiT7I1Fwb70Q8as4lsmaHUxvNmAR7f14DhSl+qEVRy7Ae7oNvES lymqv1xDiioIau32amYYtJSNLalytOawMbAY660xZv3Ngwk0CFiQX/YPjHllsJ7Sqsk1 k9WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=gf0hyMVdTFzDLNKqHchudVcwi0LHhYQv29+4M/G2bxk=; b=Uz8PJJPuhmZcD/6NW/X1kNGxdzKXpWIGLyXbyaKcpi/2pj9O2Vq6blMvzucA75g2+u rA7pdVeRwzRRjr2aqvaWPuKZZO653o6EyO4OfSGQOwccMEYpnqR3kijCPRgXgYhWf+Vx RcWqON7Ks39UtHaMO0JXfHN2KfjjHUfeGu+jU0MfzDH6H3/rNr5AgsInzkKoHeN2/6kL k14qcT1qwbzKoaxQs/XqG9Hv+hUi3CFoKEOZCesV9ydfHXoWZQDvhicxNRdpUplORZmA ASOPn/re565qxvjo+jOfk7wxZ4STZi6frXYZHB6b5cXZMjVd3rLDQD0zfum68NVqTenY EZxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gWgailOc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a68si22556359pla.267.2019.01.24.01.46.17; Thu, 24 Jan 2019 01:46:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gWgailOc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727491AbfAXJp0 (ORCPT + 99 others); Thu, 24 Jan 2019 04:45:26 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:38151 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727126AbfAXJpZ (ORCPT ); Thu, 24 Jan 2019 04:45:25 -0500 Received: by mail-wm1-f65.google.com with SMTP id m22so2269610wml.3 for ; Thu, 24 Jan 2019 01:45:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=gf0hyMVdTFzDLNKqHchudVcwi0LHhYQv29+4M/G2bxk=; b=gWgailOcY9+Q//xPJJWjg+CxqBhv/FZedQFz/2CKA57EpCMZTZH6/659iaZSqVOD6I Evr7r4HKKMtE02e6na2NPdNNyaSYWcZIFeBmME4rNxXWHEYIoOgA8gQl96lqMt4/4gFi EbnhpkobIkltziSVLAbnopKWZYVsiifRAOonU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=gf0hyMVdTFzDLNKqHchudVcwi0LHhYQv29+4M/G2bxk=; b=V5UNue5EQrbht1VHKCFiv7cNfuBFWNabfAYW+DHOHo9+uo12KOe3U39jHnD3JNBCKl izSgCFLUiixcYMmrpKYcwhWkbcjIenDAVNoI20S/qz//wfOvmgz4bYxpgVRSE+HKmNl1 uV+pmMyGpRNA4F+214lFnTCTPz5HC1H4CMHtPOgChSKCqXy3sVJe6scMUowwiCxnACcg y0PFZ2CJA3ocDkeY8YIcAe1/TCOX1gcaWX8zyArZlBggZ9aX6sf5Fa5pVgOMTpjD4TSE V9vteW+WHht9E3JVZ8/QUypEfdUpIRHUHssquQDodEJ10teH4+tPR1EE2tjK5JZj9YW3 ANRQ== X-Gm-Message-State: AJcUukfgBfNnZCKRUdMRhJdVW1CcLnlmjmqguJpiJB25a1c6h8VYLpuF 3hLnjbnLhwfy6y9S8Vl7PqwY4g== X-Received: by 2002:a1c:87cc:: with SMTP id j195mr1857894wmd.2.1548323122477; Thu, 24 Jan 2019 01:45:22 -0800 (PST) Received: from holly.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id 202sm71432480wmt.8.2019.01.24.01.45.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Jan 2019 01:45:20 -0800 (PST) Date: Thu, 24 Jan 2019 09:45:18 +0000 From: Daniel Thompson To: Sumit Garg Cc: jens.wiklander@linaro.org, herbert@gondor.apana.org.au, ard.biesheuvel@linaro.org, linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, yamada.masahiro@socionext.com, michal.lkml@markovi.net, mpm@selenic.com, robh+dt@kernel.org, mark.rutland@arm.com, arnd@arndb.de, gregkh@linuxfoundation.org, bhsharma@redhat.com, tee-dev@lists.linaro.org Subject: Re: [PATCH v5 1/4] tee: add bus driver framework for TEE based devices Message-ID: <20190124094518.qig25h4vzuya6yhz@holly.lan> References: <1548309279-5281-1-git-send-email-sumit.garg@linaro.org> <1548309279-5281-2-git-send-email-sumit.garg@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1548309279-5281-2-git-send-email-sumit.garg@linaro.org> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 24, 2019 at 11:24:36AM +0530, Sumit Garg wrote: > Introduce a generic TEE bus driver concept for TEE based kernel drivers > which would like to communicate with TEE based devices/services. Also > add support in module device table for these new TEE based devices. > > In this TEE bus concept, devices/services are identified via Universally > Unique Identifier (UUID) and drivers register a table of device UUIDs > which they can support. > > So this TEE bus framework registers following apis: > - match(): Iterates over the driver UUID table to find a corresponding > match for device UUID. If a match is found, then this particular device > is probed via corresponding probe api registered by the driver. This > process happens whenever a device or a driver is registered with TEE > bus. > - uevent(): Notifies user-space (udev) whenever a new device is registered > on this bus for auto-loading of out-of-tree drivers. out-of-tree? Surely it can be used to auto-load any modulized driver. > Also this framework allows for device enumeration to be specific to > corresponding TEE implementation like OP-TEE etc. > > Signed-off-by: Sumit Garg > --- > drivers/tee/tee_core.c | 57 ++++++++++++++++++++++++++++++++++++--- > include/linux/mod_devicetable.h | 9 +++++++ > include/linux/tee_drv.h | 32 +++++++++++++++++++++- > scripts/mod/devicetable-offsets.c | 3 +++ > scripts/mod/file2alias.c | 19 +++++++++++++ > 5 files changed, 115 insertions(+), 5 deletions(-) > > diff --git a/drivers/tee/tee_core.c b/drivers/tee/tee_core.c > index 7b2bb4c..9f4c8bc 100644 > --- a/drivers/tee/tee_core.c > +++ b/drivers/tee/tee_core.c > @@ -15,7 +15,6 @@ > #define pr_fmt(fmt) "%s: " fmt, __func__ > > #include > -#include > #include > #include > #include > @@ -1027,6 +1026,42 @@ int tee_client_invoke_func(struct tee_context *ctx, > } > EXPORT_SYMBOL_GPL(tee_client_invoke_func); > > +static int tee_client_device_match(struct device *dev, > + struct device_driver *drv) > +{ > + const struct tee_client_device_id *id_table; > + struct tee_client_device *tee_device; > + > + id_table = to_tee_client_driver(drv)->id_table; > + tee_device = to_tee_client_device(dev); > + > + while (!uuid_is_null(&id_table->uuid)) { > + if (uuid_equal(&tee_device->id.uuid, &id_table->uuid)) > + return 1; > + id_table++; > + } > + > + return 0; > +} > + > +static int tee_client_device_uevent(struct device *dev, > + struct kobj_uevent_env *env) > +{ > + uuid_t *dev_id = &to_tee_client_device(dev)->id.uuid; > + > + if (add_uevent_var(env, "MODALIAS=tee:%pUb", dev_id)) > + return -ENOMEM; > + > + return 0; Can just return directly here: return add_uevent_var(... ) Other than these nitpicks then FWIW: Reviewed-by: Daniel Thompson > +} > + > +struct bus_type tee_bus_type = { > + .name = "tee", > + .match = tee_client_device_match, > + .uevent = tee_client_device_uevent, > +}; > +EXPORT_SYMBOL_GPL(tee_bus_type); > + > static int __init tee_init(void) > { > int rc; > @@ -1040,18 +1075,32 @@ static int __init tee_init(void) > rc = alloc_chrdev_region(&tee_devt, 0, TEE_NUM_DEVICES, "tee"); > if (rc) { > pr_err("failed to allocate char dev region\n"); > - class_destroy(tee_class); > - tee_class = NULL; > + goto out_unreg_class; > } > > + rc = bus_register(&tee_bus_type); > + if (rc) { > + pr_err("failed to register tee bus\n"); > + goto out_unreg_chrdev; > + } > + > + return 0; > + > +out_unreg_chrdev: > + unregister_chrdev_region(tee_devt, TEE_NUM_DEVICES); > +out_unreg_class: > + class_destroy(tee_class); > + tee_class = NULL; > + > return rc; > } > > static void __exit tee_exit(void) > { > + bus_unregister(&tee_bus_type); > + unregister_chrdev_region(tee_devt, TEE_NUM_DEVICES); > class_destroy(tee_class); > tee_class = NULL; > - unregister_chrdev_region(tee_devt, TEE_NUM_DEVICES); > } > > subsys_initcall(tee_init); > diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h > index f9bd2f3..14eaeeb 100644 > --- a/include/linux/mod_devicetable.h > +++ b/include/linux/mod_devicetable.h > @@ -779,4 +779,13 @@ struct typec_device_id { > kernel_ulong_t driver_data; > }; > > +/** > + * struct tee_client_device_id - tee based device identifier > + * @uuid: For TEE based client devices we use the device uuid as > + * the identifier. > + */ > +struct tee_client_device_id { > + uuid_t uuid; > +}; > + > #endif /* LINUX_MOD_DEVICETABLE_H */ > diff --git a/include/linux/tee_drv.h b/include/linux/tee_drv.h > index 6cfe058..ce957ce 100644 > --- a/include/linux/tee_drv.h > +++ b/include/linux/tee_drv.h > @@ -15,11 +15,14 @@ > #ifndef __TEE_DRV_H > #define __TEE_DRV_H > > -#include > +#include > #include > #include > #include > +#include > #include > +#include > +#include > > /* > * The file describes the API provided by the generic TEE driver to the > @@ -538,4 +541,31 @@ static inline bool tee_param_is_memref(struct tee_param *param) > } > } > > +extern struct bus_type tee_bus_type; > + > +/** > + * struct tee_client_device - tee based device > + * @id: device identifier > + * @dev: device structure > + */ > +struct tee_client_device { > + struct tee_client_device_id id; > + struct device dev; > +}; > + > +#define to_tee_client_device(d) container_of(d, struct tee_client_device, dev) > + > +/** > + * struct tee_client_driver - tee client driver > + * @id_table: device id table supported by this driver > + * @driver: driver structure > + */ > +struct tee_client_driver { > + const struct tee_client_device_id *id_table; > + struct device_driver driver; > +}; > + > +#define to_tee_client_driver(d) \ > + container_of(d, struct tee_client_driver, driver) > + > #endif /*__TEE_DRV_H*/ > diff --git a/scripts/mod/devicetable-offsets.c b/scripts/mod/devicetable-offsets.c > index 2930044..1607183 100644 > --- a/scripts/mod/devicetable-offsets.c > +++ b/scripts/mod/devicetable-offsets.c > @@ -225,5 +225,8 @@ int main(void) > DEVID_FIELD(typec_device_id, svid); > DEVID_FIELD(typec_device_id, mode); > > + DEVID(tee_client_device_id); > + DEVID_FIELD(tee_client_device_id, uuid); > + > return 0; > } > diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c > index a37af7d..d0e4172 100644 > --- a/scripts/mod/file2alias.c > +++ b/scripts/mod/file2alias.c > @@ -37,6 +37,9 @@ typedef unsigned char __u8; > typedef struct { > __u8 b[16]; > } uuid_le; > +typedef struct { > + __u8 b[16]; > +} uuid_t; > > /* Big exception to the "don't include kernel headers into userspace, which > * even potentially has different endianness and word sizes, since > @@ -1287,6 +1290,21 @@ static int do_typec_entry(const char *filename, void *symval, char *alias) > return 1; > } > > +/* Looks like: tee:uuid */ > +static int do_tee_entry(const char *filename, void *symval, char *alias) > +{ > + DEF_FIELD(symval, tee_client_device_id, uuid); > + > + sprintf(alias, "tee:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", > + uuid.b[0], uuid.b[1], uuid.b[2], uuid.b[3], uuid.b[4], > + uuid.b[5], uuid.b[6], uuid.b[7], uuid.b[8], uuid.b[9], > + uuid.b[10], uuid.b[11], uuid.b[12], uuid.b[13], uuid.b[14], > + uuid.b[15]); > + > + add_wildcard(alias); > + return 1; > +} > + > /* Does namelen bytes of name exactly match the symbol? */ > static bool sym_is(const char *name, unsigned namelen, const char *symbol) > { > @@ -1357,6 +1375,7 @@ static const struct devtable devtable[] = { > {"fslmc", SIZE_fsl_mc_device_id, do_fsl_mc_entry}, > {"tbsvc", SIZE_tb_service_id, do_tbsvc_entry}, > {"typec", SIZE_typec_device_id, do_typec_entry}, > + {"tee", SIZE_tee_client_device_id, do_tee_entry}, > }; > > /* Create MODULE_ALIAS() statements. > -- > 2.7.4 >