From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
To: Samuel Ortiz <sameo@rivosinc.com>,
Dan Williams <dan.j.williams@intel.com>
Cc: Qinkun Bao <qinkun@google.com>,
"Yao, Jiewen" <jiewen.yao@intel.com>,
"Xing, Cedric" <cedric.xing@intel.com>,
Dionna Amalie Glaze <dionnaglaze@google.com>,
biao.lu@intel.com, linux-coco@lists.linux.dev,
linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH v2 2/4] tsm: Add RTMRs to the configfs-tsm hierarchy
Date: Sun, 28 Jan 2024 14:38:54 -0800 [thread overview]
Message-ID: <15c0d74c-70ea-4b1b-9ebb-66cc464e20eb@linux.intel.com> (raw)
In-Reply-To: <20240128212532.2754325-3-sameo@rivosinc.com>
On 1/28/24 1:25 PM, Samuel Ortiz wrote:
> RTMRs are defined and managed by their corresponding TSM provider. As
> such, they can be configured through the TSM configfs root.
>
> An additional `rtmrs` directory is added by default under the `tsm` one,
> where each supported RTMR can be configured:
>
> mkdir /sys/kernel/config/tsm/rtmrs/rtmr0
> echo 0 > /sys/kernel/config/tsm/rtmrs/rtmr0/index
>
> An RTMR can not be extended nor read before its configured by assigning
> it an index. It is the TSM backend responsibility and choice to map that
> index to a hardware RTMR.
>
> Signed-off-by: Samuel Ortiz <sameo@rivosinc.com>
> ---
> Documentation/ABI/testing/configfs-tsm | 11 ++
> drivers/virt/coco/tsm.c | 164 +++++++++++++++++++++++++
> 2 files changed, 175 insertions(+)
>
> diff --git a/Documentation/ABI/testing/configfs-tsm b/Documentation/ABI/testing/configfs-tsm
> index dd24202b5ba5..590e103a9bcd 100644
> --- a/Documentation/ABI/testing/configfs-tsm
> +++ b/Documentation/ABI/testing/configfs-tsm
> @@ -80,3 +80,14 @@ Contact: linux-coco@lists.linux.dev
> Description:
> (RO) Indicates the minimum permissible value that can be written
> to @privlevel.
> +
> +What: /sys/kernel/config/tsm/rtmrs/$name/index
> +Date: January, 2024
> +KernelVersion: v6.8
v6.9?
> +Contact: linux-coco@lists.linux.dev
> +Description:
> + (RW) A Runtime Measurement Register (RTMR) hardware index.
> + Once created under /sys/kernel/config/tsm/rtmrs/, an RTMR entry
> + can be mapped to a hardware RTMR by writing into its index
> + attribute. The TSM provider will then map the configfs entry to
> + its corresponding hardware register.
> diff --git a/drivers/virt/coco/tsm.c b/drivers/virt/coco/tsm.c
> index 1a8c3c096120..bb9ed2d2accc 100644
> --- a/drivers/virt/coco/tsm.c
> +++ b/drivers/virt/coco/tsm.c
> @@ -419,6 +419,108 @@ static const struct config_item_type tsm_reports_type = {
> .ct_group_ops = &tsm_report_group_ops,
> };
>
> +static ssize_t tsm_rtmr_index_store(struct config_item *cfg,
> + const char *buf, size_t len)
> +{
> + struct tsm_rtmr_state *rtmr_state = to_tsm_rtmr_state(cfg);
> + const struct tsm_ops *ops;
> + unsigned int val;
> + int rc;
> +
> + rc = kstrtouint(buf, 0, &val);
> + if (rc)
> + return rc;
> +
> + guard(rwsem_write)(&tsm_rwsem);
> +
> + /* Index can only be configured once */
> + if (is_rtmr_configured(rtmr_state))
> + return -EBUSY;
> +
> + /* Check that index stays within the TSM provided capabilities */
> + ops = provider.ops;
> + if (!ops)
> + return -ENOTTY;
> +
> + if (val > ops->capabilities.num_rtmrs - 1)
> + return -EINVAL;
> +
> + /* Check that this index is available */
> + if (tsm_rtmrs->rtmrs[val])
> + return -EINVAL;
> +
> + rtmr_state->index = val;
> + rtmr_state->alg = ops->capabilities.rtmrs[val].hash_alg;
> +
> + tsm_rtmrs->rtmrs[val] = rtmr_state;
> +
> + return len;
> +}
> +
> +static ssize_t tsm_rtmr_index_show(struct config_item *cfg,
> + char *buf)
> +{
> + struct tsm_rtmr_state *rtmr_state = to_tsm_rtmr_state(cfg);
> +
> + guard(rwsem_read)(&tsm_rwsem);
> +
> + /* An RTMR is not available if it has not been configured */
> + if (!is_rtmr_configured(rtmr_state))
> + return -ENXIO;
> +
> + return sysfs_emit(buf, "%u\n", rtmr_state->index);
> +}
> +CONFIGFS_ATTR(tsm_rtmr_, index);
> +
> +static struct configfs_attribute *tsm_rtmr_attrs[] = {
> + &tsm_rtmr_attr_index,
> + NULL,
> +};
> +
> +static void tsm_rtmr_item_release(struct config_item *cfg)
> +{
> + struct tsm_rtmr_state *state = to_tsm_rtmr_state(cfg);
> +
> + kfree(state);
I think you need to clear the index history as well?
> +}
> +
> +static struct configfs_item_operations tsm_rtmr_item_ops = {
> + .release = tsm_rtmr_item_release,
> +};
> +
> +const struct config_item_type tsm_rtmr_type = {
> + .ct_owner = THIS_MODULE,
> + .ct_attrs = tsm_rtmr_attrs,
> + .ct_item_ops = &tsm_rtmr_item_ops,
> +};
> +
> +static struct config_item *tsm_rtmrs_make_item(struct config_group *group,
> + const char *name)
> +{
> + struct tsm_rtmr_state *state;
> +
> + guard(rwsem_read)(&tsm_rwsem);
> + if (!(provider.ops && (provider.ops->capabilities.num_rtmrs > 0)))
> + return ERR_PTR(-ENXIO);
> +
> + state = kzalloc(sizeof(*state), GFP_KERNEL);
> + if (!state)
> + return ERR_PTR(-ENOMEM);
> + state->index = U32_MAX;
> +
> + config_item_init_type_name(&state->cfg, name, &tsm_rtmr_type);
> + return &state->cfg;
> +}
> +
> +static struct configfs_group_operations tsm_rtmrs_group_ops = {
> + .make_item = tsm_rtmrs_make_item,
> +};
> +
> +static const struct config_item_type tsm_rtmrs_type = {
> + .ct_owner = THIS_MODULE,
> + .ct_group_ops = &tsm_rtmrs_group_ops,
> +};
> +
> static const struct config_item_type tsm_root_group_type = {
> .ct_owner = THIS_MODULE,
> };
> @@ -433,10 +535,48 @@ static struct configfs_subsystem tsm_configfs = {
> .su_mutex = __MUTEX_INITIALIZER(tsm_configfs.su_mutex),
> };
>
> +static int tsm_rtmr_register(const struct tsm_ops *ops)
> +{
> + struct config_group *rtmrs_group;
> +
> + lockdep_assert_held_write(&tsm_rwsem);
> +
> + if (!ops || !ops->capabilities.num_rtmrs)
> + return 0;
> +
> + if (ops->capabilities.num_rtmrs > TSM_MAX_RTMR)
> + return -EINVAL;
> +
> + tsm_rtmrs = kzalloc(sizeof(struct tsm_rtmrs_state), GFP_KERNEL);
> + if (!tsm_rtmrs)
> + return -ENOMEM;
> +
> + tsm_rtmrs->rtmrs = kcalloc(ops->capabilities.num_rtmrs,
> + sizeof(struct tsm_rtmr_state *),
> + GFP_KERNEL);
> + if (!tsm_rtmrs->rtmrs) {
> + kfree(tsm_rtmrs);
> + return -ENOMEM;
> + }
> +
> + rtmrs_group = configfs_register_default_group(&tsm_configfs.su_group, "rtmrs",
> + &tsm_rtmrs_type);
> + if (IS_ERR(rtmrs_group)) {
> + kfree(tsm_rtmrs->rtmrs);
> + kfree(tsm_rtmrs);
> + return PTR_ERR(rtmrs_group);
> + }
> +
> + tsm_rtmrs->group = rtmrs_group;
> +
> + return 0;
> +}
> +
> int tsm_register(const struct tsm_ops *ops, void *priv,
> const struct config_item_type *type)
> {
> const struct tsm_ops *conflict;
> + int rc;
>
> if (!type)
> type = &tsm_report_default_type;
> @@ -450,6 +590,10 @@ int tsm_register(const struct tsm_ops *ops, void *priv,
> return -EBUSY;
> }
>
> + rc = tsm_rtmr_register(ops);
> + if (rc < 0)
> + return rc;
> +
> provider.ops = ops;
> provider.data = priv;
> provider.type = type;
> @@ -457,11 +601,31 @@ int tsm_register(const struct tsm_ops *ops, void *priv,
> }
> EXPORT_SYMBOL_GPL(tsm_register);
>
> +static int tsm_rtmr_unregister(const struct tsm_ops *ops)
> +{
> + lockdep_assert_held_write(&tsm_rwsem);
> +
> + if ((ops) && (ops->capabilities.num_rtmrs > 0)) {
This check is used in multiple places. May you can add a helper function
for it. is_valid_rtmr()?
> + configfs_unregister_default_group(tsm_rtmrs->group);
> + kfree(tsm_rtmrs->rtmrs);
> + kfree(tsm_rtmrs);
> + }
> +
> + return 0;
> +}
> +
> int tsm_unregister(const struct tsm_ops *ops)
> {
> + int rc;
> +
> guard(rwsem_write)(&tsm_rwsem);
> if (ops != provider.ops)
> return -EBUSY;
> +
> + rc = tsm_rtmr_unregister(ops);
> + if (rc < 0)
> + return rc;
> +
> provider.ops = NULL;
> provider.data = NULL;
> provider.type = NULL;
--
Sathyanarayanan Kuppuswamy
Linux Kernel Developer
next prev parent reply other threads:[~2024-01-28 22:38 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-28 21:25 [RFC PATCH v2 0/4] tsm: Runtime measurement registers ABI Samuel Ortiz
2024-01-28 21:25 ` [RFC PATCH v2 1/4] tsm: Runtime measurement register support Samuel Ortiz
2024-01-29 16:57 ` Dionna Amalie Glaze
2024-02-01 22:03 ` Jarkko Sakkinen
2024-01-28 21:25 ` [RFC PATCH v2 2/4] tsm: Add RTMRs to the configfs-tsm hierarchy Samuel Ortiz
2024-01-28 22:38 ` Kuppuswamy Sathyanarayanan [this message]
2024-02-01 22:05 ` Jarkko Sakkinen
2024-02-21 16:16 ` Mikko Ylinen
2024-01-28 21:25 ` [RFC PATCH v2 3/4] tsm: Map RTMRs to TCG TPM PCRs Samuel Ortiz
2024-01-28 22:44 ` Kuppuswamy Sathyanarayanan
2024-02-02 6:18 ` James Bottomley
2024-01-28 21:25 ` [RFC PATCH v2 4/4] tsm: Allow for extending and reading configured RTMRs Samuel Ortiz
2024-05-11 2:57 ` James Bottomley
2024-05-13 10:16 ` Samuel Ortiz
2024-05-13 14:03 ` James Bottomley
2024-05-14 5:08 ` Samuel Ortiz
2024-05-16 8:33 ` Xing, Cedric
2024-02-01 22:02 ` [RFC PATCH v2 0/4] tsm: Runtime measurement registers ABI Jarkko Sakkinen
2024-02-02 6:24 ` James Bottomley
2024-02-02 23:07 ` Dan Middleton
2024-02-03 6:03 ` James Bottomley
2024-02-03 7:13 ` Kuppuswamy Sathyanarayanan
2024-02-03 10:27 ` James Bottomley
2024-02-06 8:34 ` Xing, Cedric
2024-02-06 8:57 ` James Bottomley
2024-02-07 2:02 ` Dan Williams
2024-02-07 20:16 ` Xing, Cedric
2024-02-07 21:08 ` Kuppuswamy Sathyanarayanan
2024-02-07 21:46 ` James Bottomley
2024-02-09 20:58 ` Dan Williams
2024-02-13 7:36 ` Xing, Cedric
2024-02-13 16:05 ` James Bottomley
2024-02-14 8:54 ` Xing, Cedric
2024-02-15 6:14 ` Dan Williams
2024-02-16 2:05 ` Xing, Cedric
2024-03-05 1:19 ` Xing, Cedric
2024-04-17 20:23 ` Dan Middleton
2024-02-13 16:54 ` Mikko Ylinen
2024-02-15 22:44 ` Dr. Greg
2024-02-22 15:45 ` Lukas Wunner
2024-08-19 21:25 ` Qinkun Bao
2024-08-20 13:19 ` Samuel Ortiz
2024-08-20 19:44 ` Qinkun Bao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=15c0d74c-70ea-4b1b-9ebb-66cc464e20eb@linux.intel.com \
--to=sathyanarayanan.kuppuswamy@linux.intel.com \
--cc=biao.lu@intel.com \
--cc=cedric.xing@intel.com \
--cc=dan.j.williams@intel.com \
--cc=dionnaglaze@google.com \
--cc=jiewen.yao@intel.com \
--cc=linux-coco@lists.linux.dev \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=qinkun@google.com \
--cc=sameo@rivosinc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).