From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796048402; b=O7cs/zFxFniCKtulUsPWn9PKYndOeJ4yZgDpRpkOraQuXRUXzbBKLcSv6UhkbCvxQlSO zZzMnQS3EZfvxmStU6wXdZUMMu3D0qzE2cbglD3tzSL7GeTp9hvz6zhwHddZaWPiIvbTS 9dPux/W5XGXugJA2mRI/kJ2GGaI1GpDAlXNEJk3HZOAbsxWJPIcL3Z12N58lt982R3qWf zfHYrTkpu5G/z1Esu7Tkha1Xq63pp7DsrW/7DFf5z4bsIvwt9Qx8MRXCRH/+k40Wi/tMH A/o7y5SXk8kX5ZNdV9OEH8acA2K/MzZEZ/VZEzqlGT5haKgvad1SZxTQbE/vHKruO3A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796048402; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=7CtcVUGI1/fc//QAFc/0IZQlbIOE8eEHtGptu4HE0l8=; b=guuDPBzpxsV+/Ro3L4V5mmCY4s4oYTeiXK7esHC7JH3EoZQuidv1ygXcUWknjMdQ16o6 M2dvCHsQdWTqV0qxwWiRSgnBP+zuyXWJBhh9RCONjDWCeCLfDmHSwwRbzh38K2bAwxzB8 XQB1EHMAsayZlNORDKET2lCnGp106Y03KS1XZeQiwCZ12T+MZM593aMP1DySY6hDOkwYh acAjq24IBXoXHG5Msv1SdX2+ctog2vqW5oAorv1YdvaYU+BB/Eczb/D8jUSSTJLhObY/7 6Z0KuRgHqaqsInBVfSjDc1OEy3JiFWHg9+p7PvWpgX99F6T7lW+zSIOJRtB5cv0bCMg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=resnulli.us; spf=pass smtp.mailfrom=resnulli.us; dkim=pass header.d=resnulli.us header.i=@resnulli.us header.a=rsa-sha256 header.s=google header.b=mbbzFGlb; arc=none smtp.remote-ip=209.85.167.46 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 156F2606A68E for ; Mon, 30 Nov 2026 14:20:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 156F2606A68E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=resnulli.us Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=resnulli.us Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli.us header.i=@resnulli.us header.a=rsa-sha256 header.s=google header.b=mbbzFGlb Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-5c14f3dab66so9925741e87.0 for ; Mon, 30 Nov 2026 06:20:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli.us; s=google; t=1796048399; x=1796653199; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=7CtcVUGI1/fc//QAFc/0IZQlbIOE8eEHtGptu4HE0l8=; b=mbbzFGlbDB6aqdvoPJNyusIVy2Jh5kB4fLFeg+jFtzrT9zSK1bT/OGeNKYYKqwf7mS s65Ru0wAPyyYH0D9Usya7QQg+sDfCkTqWEFjix6MUDkl44v794pdGQlr0MX91bw3630m dXBHLVN1n+fs7dADE7yGRN+D/nVimzY7CSCQEFKeMvVR4tFm7mTJX+rd4+eDJ2hYFF0X jocHuX9YO4TG5eTcX2gEwqipjYaYnxoXgYzt8QutPRkVHZH0Smcvu2f9qAXWFO2zXNKh U9totxxEIl4WarNF0NBqhxvZL3hNwTd70Z5udMNvm3VLN/jYjn9TihY84okuLIQgFUIf 92TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796048399; x=1796653199; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=7CtcVUGI1/fc//QAFc/0IZQlbIOE8eEHtGptu4HE0l8=; b=ont3/B3bHr2qgETLG58e4rI09rUMiXsPBxoQgxlbMF20P1TjGUpQDjFigzBQrdAWPa 74IMJNK4wj8Znte7SjJOtl1l9hSD7XlX65uwyzt2GE0TIZ2g21fVXsDYsPkyycoj/JlY e7eFisaPR0Jfsn+IYAgN58i0R6YR/BH3JnwCXI2WFg1oLnESyciSorZ69P9odmGRR3Ql C3VtZbnp/AbJGtB2vfeBqBwyPfEYJ0Q/7+nPzfKjmCVG7QGHfiHCeCdx19wl+dNCCzBy yRaAj0OPdBf3wQHr1ohaHC2EouLBah+gPfsT6dchLKPO3Uu3/uJUochuA7qedhtd8c+u TX0w== X-Forwarded-Encrypted: i=1; AL+hErFmk6Mhe6+R5KgKG1508lBkId/ryTMxpwba0GvLIs60iDHUSAq1saoczQL+vx/3j7SDHEV8yb/wXZk=@vger.kernel.org X-Gm-Message-State: APuU4Z+554qw5MPwgPzhwgq/UPCpxaKYGOOL5azUuBW8CPVbDa2kdnnF fFqwCD4fdTLEs5HLbGYf1qLnq8G+uh5ux3nnk2OKuuA5fVUNWfsxOLk9OERYA1lA9h4= X-Gm-Gg: AZFdTZeCc2zvf1UYWFJB2TYXycQsndBVJF+BiNUL8KgU3Y3E0LQFT1WEQG2C7RvZeLO xSaKXAkSxRcoF9zUbYIDZx7juDZTMNELSPxqS/Tk7hdKaGAUqSAOkezmyQ/WNnV0TIrOK8w+c4W XCCsgv6jFpDvq69EsCGHVbS4iHuzNt4kGyNstNYMYz9UXmF1Zld8NeEb0a2v+Q31c0OkAn8yZob FYdkkQPbCaxZ7FY6LO0MekpsvCMmM3BODRDTHjr6Vkdb+jbK9tNa92kqstlMMpYc3SEuCBkChF0 U2zIFUEcDQ+BCnzT6r7DgKyvXX07KGkeX2JBsUWDKvPkA7WfhROwycOoKjUqNxgjQvxv+/zzBa6 1PxEgTzk8eO7jB2vZS4rVEh/HeChsf+n6hYJivaX2CYoK04hKnBJ3+L9D/zBJCj9jgkP60gpXS/ eo7Kxwtpuq7QBi903oazoXM5yJJl4qLwGBgG8P5a+t4BTEj9msER0RKXnqE1PRNPQdVrSOoFY9c rvwKcR8T9fjlKlWFu8UPhEUYleaY/xMmh3l7iLpeE/f/hMkdD1sH+7ztDuoD+2VDR6pk/qNla7E CUHtKwMv/P07gV56ivn8cq3yIdqhquO6wcIPCl/f X-Received: by 2002:a05:6512:401d:b0:5c3:38ba:937e with SMTP id 2adb3069b0e04-5c338ba9530mr3590064e87.13.1796048399105; Mon, 30 Nov 2026 06:19:59 -0800 (PST) Received: from localhost ([140.209.217.212]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5c1bcf332c9sm8416352e87.7.2026.11.30.06.19.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 06:19:58 -0800 (PST) Date: Mon, 30 Nov 2026 15:19:54 +0100 From: Jiri Pirko To: Jason Gunthorpe 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 Message-ID: References: <20261113160838.2512652-1-jiri@resnulli.us> <20261113160838.2512652-4-jiri@resnulli.us> <179573913907.519186.16798649738277789303.b4-review@b4> X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 >> --- >> 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