From nobody Mon Mar 23 21:27:42 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E313926CE2C for ; Mon, 23 Mar 2026 15:05:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774278345; cv=none; b=O4YKhokd4LlbqOEX+CLzl7a9HXXb0/G95V2ueuD8+JkQHp2ieL4mOD8jH8gfnk3upyhNMBwFjfqqulxtGYB+fr57OmfzGLrhllniEvfXjwQBAHqZc1LwTK9T+qjQsIBledTPaSKkxKFGfjEgI/qUoAUt+QOSyNRNIZ/Ya9NOwec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774278345; c=relaxed/simple; bh=n0iPo2pDZQX9XRo48GkCor41ZVjHORjsiDeF+v5aYvg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KXFBSr5Dm/jlJ0DntTSnTshIM0czSu9cjyRnQht0EMMB7J+ue8LRaWS0aXHfbj8iKPHxaWgIcWcw0S7uZOlxLXyJR9qmaf2FRt5xgYRg1OBewVHWfVBeah4j0Z+tzs76yFLobrY9UOw7u45dKP6g7xtXX5zuX4tKKVUnKnOJyyQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=U/+JWtiO; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="U/+JWtiO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774278343; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v8irQRHfFWnEfG6qljHMonM0AVFnFCevGipBEnTRuQk=; b=U/+JWtiO1xka+2UBeMxZJbr1Mum12VEhwsIJ8y+y4ahJje/oh/kWsoC+6B675n8B1hSqC2 VD1k57pl+yslpa50t2mipajg3zDW/ZKYKFELKrtQLyOGwXa91YF95lDiItd59m39AG5Hk2 dTCVqxYVLUsaYB294Pe/Nvv/UzeoIX8= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-50-1PmYBqROPYW4-KZDozPj9w-1; Mon, 23 Mar 2026 11:05:39 -0400 X-MC-Unique: 1PmYBqROPYW4-KZDozPj9w-1 X-Mimecast-MFC-AGG-ID: 1PmYBqROPYW4-KZDozPj9w_1774278337 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 08B6E180049D; Mon, 23 Mar 2026 15:05:37 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.44.33.121]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 27DB71955F2E; Mon, 23 Mar 2026 15:05:31 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org Cc: David Howells , Marc Dionne , Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org, Mathieu Desnoyers , John Johansen , Simon Horman , apparmor@lists.ubuntu.com, stable@kernel.org Subject: [PATCH net v2 04/10] list: Move on_list_rcu() to list.h and add on_list() also Date: Mon, 23 Mar 2026 15:04:55 +0000 Message-ID: <20260323150505.3513839-5-dhowells@redhat.com> In-Reply-To: <20260323150505.3513839-1-dhowells@redhat.com> References: <20260323150505.3513839-1-dhowells@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" Unfortunately, list_empty() is not usable with an entry that has been removed from a list with list_del_rcu() as ->next must be left pointing at the following entry so as not to break traversal under RCU. Solve this by moving on_list_rcu() from AppArmor to linux/list.h, and turning it into an inline function. Also add an on_list() counterpart (functionally, this is just an antonym for list_empty()), but the name looks less awkward when applied to a non-head element. We probably don't want to use on_list_rcu() generally because it requires an extra check as ->prev is set differently in the two cases. Signed-off-by: David Howells cc: Mathieu Desnoyers cc: John Johansen cc: Marc Dionne cc: Eric Dumazet cc: "David S. Miller" cc: Jakub Kicinski cc: Paolo Abeni cc: Simon Horman cc: linux-afs@lists.infradead.org cc: apparmor@lists.ubuntu.com cc: netdev@vger.kernel.org cc: stable@kernel.org --- include/linux/list.h | 26 ++++++++++++++++++++++++++ security/apparmor/include/policy.h | 2 -- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/include/linux/list.h b/include/linux/list.h index 00ea8e5fb88b..d224e7210d1b 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -381,6 +381,32 @@ static inline int list_empty(const struct list_head *h= ead) return READ_ONCE(head->next) =3D=3D head; } =20 +/** + * on_list - Test whether an entry is on a list. + * @entry: The entry to check + * + * Test whether an entry is on a list. Safe to use on an entry initialised + * with INIT_LIST_HEAD() or LIST_HEAD() or removed with things like + * list_del_init(). Not safe for use with list_del() or list_del_rcu(). + */ +static inline bool on_list(const struct list_head *entry) +{ + return !list_empty(entry); +} + +/** + * on_list_rcu - Test whether an entry is on a list (RCU-del safe). + * @entry: The entry to check + * + * Test whether an entry is on a list. Safe to use on an entry initialised + * with INIT_LIST_HEAD() or LIST_HEAD() or removed with things like + * list_del_init(). Also safe for use with list_del() or list_del_rcu(). + */ +static inline bool on_list_rcu(const struct list_head *entry) +{ + return !list_empty(entry) && entry->prev !=3D LIST_POISON2; +} + /** * list_del_init_careful - deletes entry from list and reinitialize it. * @entry: the element to delete from the list. diff --git a/security/apparmor/include/policy.h b/security/apparmor/include= /policy.h index 3895f8774a3f..c3697c23bbed 100644 --- a/security/apparmor/include/policy.h +++ b/security/apparmor/include/policy.h @@ -57,8 +57,6 @@ extern const char *const aa_profile_mode_names[]; =20 #define profile_is_stale(_profile) (label_is_stale(&(_profile)->label)) =20 -#define on_list_rcu(X) (!list_empty(X) && (X)->prev !=3D LIST_POISON2) - /* flags in the dfa accept2 table */ enum dfa_accept_flags { ACCEPT_FLAG_OWNER =3D 1,