Re: [PATCH RFC v2 3/9] attestation: Prepare provider and instance core
From: Aneesh Kumar K . V
Date: Fri Dec 04 2026 - 02:58:04 EST
Jiri Pirko <jiri@xxxxxxxxxxx> writes:
> From: Jiri Pirko <jiri@xxxxxxxxxx>
>
> 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.
>
[ ... 444 lines skipped ... ]
> +/**
> + * attestation_register - Make an allocated device reachable.
> + * @att: device from attestation_alloc()
> + *
> + * Return: 0, or a negative errno with @att still to be put.
> + */
> +int attestation_register(struct attestation_dev *att)
> +{
> + int ret;
> +
> + ret = attestation_registry_insert(att);
> + if (ret)
> + return ret;
> + ctlv_publish(&att->ctlv);
> + xa_lock(&attestation_instances);
> + __xa_set_mark(&attestation_instances, att->index, ATTESTATION_REGISTERED);
> + xa_unlock(&attestation_instances);
> +
> + ret = ctlv_device_add(&att->node);
> + if (ret)
> + goto err_withdraw;
> + return 0;
> +
> +err_withdraw:
> + attestation_withdraw(att);
> + ctlv_unpublish(&att->ctlv);
> + attestation_registry_remove(att);
> + return ret;
> +}
> +EXPORT_SYMBOL_NS_GPL(attestation_register, "ATTESTATION");
>
I ran into this while implementing SPDM attestation. We should keep
ctlv->registered false until all registration steps, including
ctlv_device_add(), have succeeded. Enabling callbacks should be the
final step in attestation_register().
Could we also avoid taking ctlv->registration_lock in ctlv_device_add()
and ctlv_publish()? TSM drivers may call attestation_register() while
holding their own locks. For CCA, registration holds pci_tsm_rwsem, so
taking registration_lock here introduces this dependency:
pci_tsm_rwsem -> ctlv->registration_lock
CTLV operations hold registration_lock while invoking callbacks, and
those callbacks may need to acquire pci_tsm_rwsem, creating the reverse
dependency.
I think we should preserve this lock ordering:
ctlv->registration_lock -> pci_tsm_rwsem
and avoid taking registration_lock during ctlv_publish() and
ctlv_device_add().
-aneesh