All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: David Howells <dhowells@redhat.com>
Cc: bpf@vger.kernel.org, dm-devel@lists.linux.dev,
	fsverity@lists.linux.dev, keyrings@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	Alasdair Kergon <agk@redhat.com>,
	Alexei Starovoitov <ast@kernel.org>, Alex Shi <alexs@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Benjamin Marzinski <bmarzins@redhat.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Dongliang Mu <dzm91@hust.edu.cn>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Emil Tsalapatis <emil@etsalapatis.com>,
	Eric Biggers <ebiggers@kernel.org>,
	Ignat Korchagin <ignat@linux.win>,
	Ihor Solodrai <ihor.solodrai@linux.dev>,
	James Morris <jmorris@namei.org>, Jiri Olsa <jolsa@kernel.org>,
	Jonathan Corbet <corbet@lwn.net>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Mike Snitzer <snitzer@kernel.org>,
	Mikulas Patocka <mpatocka@redhat.com>,
	Paul Moore <paul@paul-moore.com>,
	Randy Dunlap <rdunlap@infradead.org>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Song Liu <song@kernel.org>, "Theodore Y. Ts'o" <tytso@mit.edu>,
	Yanteng Si <si.yanteng@linux.dev>,
	Yonghong Song <yonghong.song@linux.dev>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH v9 2/3] KEYS: Replace assoc_array with rhashtable
Date: Tue, 10 Nov 2026 08:06:36 +0200	[thread overview]
Message-ID: <avK0bC5VmO7LXlfS@kernel.org> (raw)
In-Reply-To: <20261110053323.2936729-3-jarkko@kernel.org>

On Tue, Nov 10, 2026 at 07:33:22AM +0200, Jarkko Sakkinen wrote:
>  /*
>   * Preallocate memory so that a key can be linked into to a keyring.
>   */
>  int __key_link_begin(struct key *keyring,
>  		     const struct keyring_index_key *index_key,
> -		     struct assoc_array_edit **_edit)
> +		     struct keyring_edit *edit)
>  {
> -	struct assoc_array_edit *edit;
> +	struct keyring_link *link = NULL;
> +	struct keyring_link *replace;
> +	struct keyring_index *links;
>  	int ret;
>  
>  	kenter("%d,%s,%s,",
>  	       keyring->serial, index_key->type->name, index_key->description);
>  
> -	BUG_ON(index_key->desc_len == 0);
> -	BUG_ON(*_edit != NULL);
> +	if (WARN_ON(index_key->desc_len == 0) || WARN_ON(edit->new)) {
> +		ret = -EINVAL;
> +		goto out;
> +	}
>  
> -	*_edit = NULL;
> +	edit->new = NULL;
> +	edit->old = NULL;
>  
> -	ret = -EKEYREVOKED;
> -	if (test_bit(KEY_FLAG_REVOKED, &keyring->flags))
> -		goto error;
> +	if (test_bit(KEY_FLAG_REVOKED, &keyring->flags)) {
> +		ret = -EKEYREVOKED;
> +		goto out;
> +	}
>  
> -	/* Create an edit script that will insert/replace the key in the
> -	 * keyring tree.
> -	 */
> -	edit = assoc_array_insert(&keyring->keys,
> -				  &keyring_assoc_array_ops,
> -				  index_key,
> -				  NULL);
> -	if (IS_ERR(edit)) {
> -		ret = PTR_ERR(edit);
> -		goto error;
> +	links = keyring_get_index(keyring);
> +	if (IS_ERR(links)) {
> +		ret = PTR_ERR(links);
> +		goto out;
>  	}
>  
> -	/* If we're not replacing a link in-place then we're going to need some
> +	link = kzalloc_obj(struct keyring_link);
> +	if (!link) {
> +		ret = -ENOMEM;
> +		goto out;
> +	}
> +	link->hash = index_key->hash;
> +
> +	replace = keyring_find_link(links, index_key);
> +
> +	/*
> +	 * If we're not replacing a link in-place then we're going to need some
>  	 * extra quota.
>  	 */
> -	if (!edit->dead_leaf) {
> +	if (!replace) {
>  		ret = key_payload_reserve(keyring,
>  					  keyring->datalen + KEYQUOTA_LINK_BYTES);
>  		if (ret < 0)
> -			goto error_cancel;
> +			goto out;
> +
> +		ret = rhashtable_insert_fast(&links->ht, &link->node,
> +					     keyring_link_params);
> +		if (ret < 0) {
> +			key_payload_reserve(keyring,
> +					    keyring->datalen - KEYQUOTA_LINK_BYTES);
> +			goto out;
> +		}
>  	}
>  
> -	*_edit = edit;
> -	kleave(" = 0");
> -	return 0;
> +	edit->new = link;
> +	edit->old = replace;
> +	ret = 0;
>  
> -error_cancel:
> -	assoc_array_cancel_edit(edit);
> -error:
> +out:
> +	if (ret && link)
> +		kfree(link);
>  	kleave(" = %d", ret);
>  	return ret;
>  }

No additional Sashiko complains.

Despite a few unfortunate extra rounds I'm happy how this shaped in the
end. It has a sane flow now I think.

And it definitely made sense to drop cleanup.h shenanigans from
__key_link_begin().

Br, Jarkko

  parent reply	other threads:[~2026-11-10  6:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10  5:33 [PATCH v9 0/3] KEYS: Replace assoc_array with rhashtable Jarkko Sakkinen
2026-11-10  5:33 ` [PATCH v9 1/3] KEYS: Introduce keyring_is_empty() Jarkko Sakkinen
2026-11-10  5:39   ` sashiko-bot
2026-11-10  5:33 ` [PATCH v9 2/3] KEYS: Replace assoc_array with rhashtable Jarkko Sakkinen
2026-11-10  5:56   ` sashiko-bot
2026-11-10  6:06   ` Jarkko Sakkinen [this message]
2026-11-10  5:33 ` [PATCH v9 3/3] lib: Remove assoc_array Jarkko Sakkinen
2026-11-10  5:58   ` sashiko-bot
2026-11-12 14:19 ` [PATCH v9 0/3] KEYS: Replace assoc_array with rhashtable Jarkko Sakkinen

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=avK0bC5VmO7LXlfS@kernel.org \
    --to=jarkko@kernel.org \
    --cc=agk@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexs@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bmarzins@redhat.com \
    --cc=bpf@vger.kernel.org \
    --cc=corbet@lwn.net \
    --cc=daniel@iogearbox.net \
    --cc=dhowells@redhat.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=dzm91@hust.edu.cn \
    --cc=ebiggers@kernel.org \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=fsverity@lists.linux.dev \
    --cc=ignat@linux.win \
    --cc=ihor.solodrai@linux.dev \
    --cc=jmorris@namei.org \
    --cc=jolsa@kernel.org \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=mpatocka@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=rdunlap@infradead.org \
    --cc=serge@hallyn.com \
    --cc=si.yanteng@linux.dev \
    --cc=skhan@linuxfoundation.org \
    --cc=snitzer@kernel.org \
    --cc=song@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=tytso@mit.edu \
    --cc=yonghong.song@linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.