Linux Confidential Computing Development
 help / color / mirror / Atom feed
From: Jiri Pirko <jiri@resnulli.us>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org,
	 linux-api@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org,
	linux-doc@vger.kernel.org,  jgg@ziepe.ca,
	david.quigley@intel.com, lukas@wunner.de, ksinyuk@kernel.org,
	 rodrigo.vivi@intel.com, cedric.xing@intel.com, sameo@meta.com,
	drdeeglaze@gmail.com,  James.Bottomley@hansenpartnership.com,
	aik@amd.com, jpiotrowski@nvidia.com, qinkun@google.com,
	 pgonda@google.com, jic23@kernel.org, alistair.francis@wdc.com,
	ankita@nvidia.com,  suzuki.poulose@arm.com, kas@kernel.org,
	rick.p.edgecombe@intel.com,  elena.reshetova@intel.com,
	dave.hansen@linux.intel.com,
	 sathyanarayanan.kuppuswamy@linux.intel.com,
	peter.fang@intel.com, jarkko@kernel.org, zohar@linux.ibm.com,
	 yeoreum.yun@arm.com, aneesh.kumar@kernel.org,
	dave.jiang@intel.com,  nik.borisov@suse.com,
	sergii.dmytruk@3mdeb.com
Subject: Re: [PATCH RFC v2 3/9] attestation: Prepare provider and instance core
Date: Mon, 30 Nov 2026 15:19:54 +0100	[thread overview]
Message-ID: <aw2B8Bz6hClyrtUY@FV6GYCPJ69> (raw)
In-Reply-To: <179573913907.519186.16798649738277789303.b4-review@b4>

Fri, Nov 27, 2026 at 01:25:39AM +0100, jgg@nvidia.com wrote:
>> Add provider validation, instance registration and lifecycle management
>> for the attestation family. Each instance is a device of the attestation
>> class, with a node under /dev/attestation/, and embeds its CTLV
>> instance and node.
>> 
>> The provider descriptor is one immutable evidence and MR contract; MR
>> state follows in the next patch. The core object can be compile-checked
>> here. CONFIG_ATTESTATION remains unwired until the CTLV handlers land.
>> 
>> Assisted-by: Cursor: GPT-5.6 Sol
>> Assisted-by: Cursor: Claude Opus 5.5
>> Signed-off-by: Jiri Pirko <jiri@nvidia.com>
>> ---
>> RFC->RFCv2:
>> - gave attestation its own device, class and /dev/attestation/ nodes,
>>   each a struct ctlv_device
>> - dropped the goto from attestation_registry_insert()
>> - noted that instance indexes are never reused
>> - selected CRYPTO_HASH_INFO
>> - selected CTLV instead of depending on it
>> - kept each guard() on one line
>> - dropped the journal from the Kconfig help
>> - dropped read(), poll() and the event teardown
>> - refused hash algorithms the hash-algo enum does not list
>> - gave each evidence object a class and the formats it may have
>> - dropped max_total_output_length
>> - took each signed object's challenge lengths as a list, ascending
>>   and disjoint
>> - left the object count and challenge length limits to CTLV
>> - added attestation_evidence_write(), for blobs of any length
>> - let a request omit the challenge
>> - separated the steps of the longer functions
>> - took an MR's algorithms in any order, each once
>> - let mr_extend get the digests of some of an MR's banks
>> - required mr_read of a provider with MRs, as every MR can be read
>> - said that an MR's extend cap is fixed
>> - took the UAPI headers from include/uapi/ctlv/
>> - named evidence objects by ID, and had the provider give each
>>   result's format
>> ---
>>  MAINTAINERS                         |   1 +
>>  drivers/attestation/Kconfig         |  12 +
>>  drivers/attestation/Makefile        |   4 +
>>  drivers/attestation/core/core.c     | 429 ++++++++++++++++++++++++++++
>>  drivers/attestation/core/internal.h |  21 ++
>
>Traditionally subsystems put their core code in the top dir and
>drivers in sub dirs, or loose in the main dir too. The really big big
>subsystems use a subdir for core.

Okay. Makes sense.


>
>I think in this case we should skip the core/ subdir. Linus has also
>complained about the directory name stuttering like core/core.c in the
>past.
>
>> [ ... 78 lines skipped ... ]
>> +/* A reply carries only what hash-algo in ctlv-attestation.yaml lists. */
>> +static bool attestation_algorithm_valid(enum hash_algo algorithm)
>> +{
>> +	return algorithm >= 0 && algorithm <= HASH_ALGO_SHA3_512 && hash_digest_size[algorithm] &&
>> +	       hash_digest_size[algorithm] <= HASH_MAX_DIGESTSIZE;
>
><= HASH_ALGO_SHA3_512 should be < ARRAY_SIZE(hash_digest_size) ?

Sure.


>
>> +}
>> +
>> +static int attestation_mr_props_validate(const struct attestation_provider *provider,
>> +					 const struct attestation_mr_props *props)
>> +{
>> +	DECLARE_BITMAP(seen, HASH_ALGO__LAST) = {};
>> +	size_t index;
>> +
>> +	if (!props || !props->name || !*props->name || strlen(props->name) > 128 ||
>> +	    !props->algorithms || !props->algorithms_count || props->algorithms_count > 23)
>> +		return -EINVAL;
>
>The magic numbers should come from someplace..

Agreed.

>
>> +	for (index = 0; index < props->algorithms_count; index++) {
>> +		enum hash_algo algorithm = props->algorithms[index];
>> +
>> +		if (!attestation_algorithm_valid(algorithm) ||
>> +		    __test_and_set_bit(algorithm, seen))
>> +			return -EINVAL;
>> +	}
>> +	if (props->extendable && !provider->mr_extend)
>> +		return -EINVAL;
>> +	return 0;
>> +}
>> +
>> +/* What device-get and evidence-get carry, as ctlv-attestation.yaml bounds it. */
>> +#define ATTESTATION_EVIDENCE_OBJECTS_MAX 16
>> +#define ATTESTATION_EVIDENCE_FORMATS_MAX 4
>> +#define ATTESTATION_CHALLENGE_LENGTHS_MAX 8
>> +#define ATTESTATION_CHALLENGE_MAX 4096
>
>> +/* Moves with each value appended to evidence-format. */
>> +#define ATTESTATION_EVIDENCE_FORMAT_LAST CTLV_ATTESTATION_EVIDENCE_FORMAT_CCEL
>
>Should the general schema processor be checking these? Seems odd they
>are just open coded here when it has the information..

Agreed, The generator will emit the bounds the spec declares as
constants, and the core will use those, so nothing is open coded and
a regen follows the spec. The checks stay where they are, as they
fail a provider at probe; the schema processor does check the same
when a reply is built, but only then, and with a warning.


>
>> [ ... 110 lines skipped ... ]
>> +static int attestation_registry_insert(struct attestation_dev *att)
>> +{
>> +	unsigned long index;
>> +	void *old;
>> +	int ret;
>> +
>> +	guard(mutex)(&attestation_registry_lock);
>> +	if (attestation_next_index > UINT_MAX)
>> +		return -ENOSPC;
>> +	index = attestation_next_index;
>> +	ret = xa_reserve(&attestation_instances, index, GFP_KERNEL);
>
>This is usually written as xa_alloc_cyclic()
>
>> +	if (ret)
>> +		return ret;
>> +
>> +	xa_lock(&attestation_instances);
>> +	if (attestation_parent_exists(att->node.dev.parent)) {
>
>Why? What's the issue if a device wants a bunch of attestation end points?
>
>> [ ... 19 lines skipped ... ]
>> +bool attestation_registered(struct attestation_dev *att)
>> +{
>> +	bool registered;
>> +
>> +	lockdep_assert_held(&att->lock);
>> +	xa_lock(&attestation_instances);
>> +	registered = xa_get_mark(&attestation_instances, att->index, ATTESTATION_REGISTERED);
>> +	xa_unlock(&attestation_instances);
>
>No need for the spinlock here
>
>> [ ... 50 lines skipped ... ]
>> +static int attestation_op_pre(struct ctlv *ctlv, struct ctlv_op_ctx *ctx)
>> +{
>> +	struct attestation_dev *att = attestation_from_ctlv(ctlv);
>> +
>> +	mutex_lock(&att->lock);
>> +	if (!attestation_registered(att)) {
>> +		mutex_unlock(&att->lock);
>> +		return -ENODEV;
>> +	}
>
>I'm struggling to figure out why there is an xa mark, it doesn't seem
>needed by anything?
>
>The revoke flow is already handled by the common code with:
>
>	scoped_guard(rwsem_read, &ctlv->registration_lock) {
>		if (!ctlv->registered || !ctlv->family)
>			return -ENODEV;
>		ret = ctlv_op_exec(cfile, &exec, snapshot, &reply, &reply_len);
>	}
>
>Why does it need two layers of the same thing?
>
>In fact, why does the xarray exist at all? Its only purpose is to
>de-duplicate the parent, which seems pointless and not something a
>subsystem should do. Seems like it can be removed. It is confusing
>that the xarray gives an id but then the ctlv has an idr which then
>gives a different id.

You are right, nothing in this series needs it. It is there for
in-kernel consumers, like IMA. It selects an instance by its parent
and holds on to it by index. I'll take the registry out of this series
and leave revoke to CTLV.

After IMA is work will be posted, I'll look at finding the instance
through the class device instead, so there is one ID and no limit on the
endpoints of a parent.


>
>> [ ... 146 lines skipped ... ]
>> +static void __exit attestation_module_exit(void)
>> +{
>> +	WARN_ON_ONCE(!xa_empty(&attestation_instances));
>> +	xa_destroy(&attestation_instances);
>> +	ctlv_device_class_unregister(&attestation_class);
>> +}
>> +
>> +module_init(attestation_module_init);
>> +module_exit(attestation_module_exit);
>
>subsys_init

Okay. Thanks!

>
>-- 
>Jason

  reply	other threads:[~2026-11-30 14:20 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13 16:08 [PATCH RFC v2 0/9] attestation: Add a common subsystem and TDX support Jiri Pirko
2026-11-13 16:08 ` [PATCH RFC v2 1/9] attestation: Add the base family specification and generated files Jiri Pirko
2026-11-27  0:25   ` Jason Gunthorpe
2026-11-27 12:54     ` Jiri Pirko
2026-11-30 14:00     ` Jiri Pirko
2026-11-13 16:08 ` [PATCH RFC v2 2/9] Documentation: attestation: Add userspace ABI Jiri Pirko
2026-11-13 16:08 ` [PATCH RFC v2 3/9] attestation: Prepare provider and instance core Jiri Pirko
2026-11-27  0:25   ` Jason Gunthorpe
2026-11-30 14:19     ` Jiri Pirko [this message]
2026-11-13 16:08 ` [PATCH RFC v2 4/9] attestation: Prepare measurement registers Jiri Pirko
2026-11-13 16:08 ` [PATCH RFC v2 5/9] attestation: Add CTLV operation handling Jiri Pirko
2026-11-13 16:08 ` [PATCH RFC v2 6/9] Documentation: attestation: Describe how to write a provider Jiri Pirko
2026-11-13 16:08 ` [PATCH RFC v2 7/9] tdx-guest: Expose the native attestation service API Jiri Pirko
2026-11-13 16:08 ` [PATCH RFC v2 8/9] attestation: Add the TDX family specification and generated files Jiri Pirko
2026-11-13 16:08 ` [PATCH RFC v2 9/9] attestation: Add the TDX family implementation Jiri Pirko
2026-11-23  9:09   ` Yeoreum Yun
2026-11-23 12:38     ` Jarkko Sakkinen
2026-11-23 15:11       ` Jason Gunthorpe
2026-11-23 15:15         ` Jarkko Sakkinen
2026-11-23 15:24           ` Jarkko Sakkinen
2026-11-23 15:40             ` Jason Gunthorpe
2026-11-23 15:42               ` Jarkko Sakkinen
2026-11-24 12:13                 ` Jiri Pirko

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=aw2B8Bz6hClyrtUY@FV6GYCPJ69 \
    --to=jiri@resnulli.us \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=aik@amd.com \
    --cc=alistair.francis@wdc.com \
    --cc=aneesh.kumar@kernel.org \
    --cc=ankita@nvidia.com \
    --cc=cedric.xing@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=dave.jiang@intel.com \
    --cc=david.quigley@intel.com \
    --cc=drdeeglaze@gmail.com \
    --cc=elena.reshetova@intel.com \
    --cc=jarkko@kernel.org \
    --cc=jgg@nvidia.com \
    --cc=jgg@ziepe.ca \
    --cc=jic23@kernel.org \
    --cc=jpiotrowski@nvidia.com \
    --cc=kas@kernel.org \
    --cc=ksinyuk@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=nik.borisov@suse.com \
    --cc=peter.fang@intel.com \
    --cc=pgonda@google.com \
    --cc=qinkun@google.com \
    --cc=rick.p.edgecombe@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=sameo@meta.com \
    --cc=sathyanarayanan.kuppuswamy@linux.intel.com \
    --cc=sergii.dmytruk@3mdeb.com \
    --cc=suzuki.poulose@arm.com \
    --cc=x86@kernel.org \
    --cc=yeoreum.yun@arm.com \
    --cc=zohar@linux.ibm.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