From nobody Fri Sep 5 23:29:05 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4cJXc20g77z66Ybj; Fri, 05 Sep 2025 23:29:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cJXc16GWVz40xn; Fri, 05 Sep 2025 23:29:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1757114945; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=v0/vlZyjS4n/Ppjl62kbgCNZXRJBsjfBjxVJIOadeSo=; b=oW8Zkywy+VEnj7+Bxm4fBt5qIZoCRgDlK8d428g1VGB7mZR1I9ZznIh1p/9ZiDCO6CGmnT FaDlq5zUGXE6DEnAC6J4mW7ouoOaAcPEQ8fqO+pizI6wqfLhzhcp0i/SZ42sR/aUs3GDiK 7Qkh8qFk4dXm3lVLSan6wQ5vqb3ZFzIdWUaUx+00H45kLwFXbcglWNirjMmlDaYZDwwtf7 tPXDckDPqXlM01FTjDY16Br+N6vqlN/s5C/I8cXaopcu5fHuuNTS2pGgGuuAijIX04bd7R M3FA3ho3z/1RaGKauRMdHfjT78cK6JRV2AIIKf9xZCUxO1AAtvfmxW4t5MdB5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1757114945; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=v0/vlZyjS4n/Ppjl62kbgCNZXRJBsjfBjxVJIOadeSo=; b=Z4RqI46SaT+vGn6RRExQQO3Rl6rRbEvhys7mpqzbjECs3ddwk4M7GKb78lrzhCeVol4PVG i4+MgRRm619HyrWzqEH8UBhENYCY4EQ6eKUhVHOHWng3LXTr3UMOUybL45LShnp94tYRej 9XxU3TUZ3v+u13NhgUb/NLm2xeev1jvHDNt9Tj98RecbQs87k5OV6bMHl+UuZy5H8Z6wFD YVyXLX7oHOBwKILuZ5YaKkxtUCO+tGP424OcjMFMH3dQiljZYS/CfPXjCmAXngsbT278xH fQTzLYSVturR82/gchUuj1Cl8j9khp5Nertj8yonVtQBSrt8fCrq0C8T+6Jwkg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1757114945; a=rsa-sha256; cv=none; b=TCmtAgGxAZjYTQiuOFZ4MPukWQB0zzpUrWhabbsZI0iHpV0uLtHX88xkdO4261m2SH1hU6 YcMHFCUgUnvmv98QQMwYuSuf/KRzrmAiseIAiRblyZ6/fNS/53Y7Vweteuo6DDDHq5xYlZ o44JFyVVG/1N0R4xQ7rrlhnCw2adFHaHdeJkJ0Z9PnATYmKGsER7TKc0vWw645vkxh7z+A 4tlngLP53hNAoRgZCulcvffeZ10IF9JhM2IN68soB2u7LLPAtzQxVFdE0uf3c2Kx3dEPX+ CLrYhbqIBKcBVdTHKNJmE50HDQA1B5OkdLs6qwEIoBq1tOCMSgzAHi/pZaIQYw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4cJXc15sjZz1808; Fri, 05 Sep 2025 23:29:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 585NT5ij029404; Fri, 5 Sep 2025 23:29:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 585NT5Wn029401; Fri, 5 Sep 2025 23:29:05 GMT (envelope-from git) Date: Fri, 5 Sep 2025 23:29:05 GMT Message-Id: <202509052329.585NT5Wn029401@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: 3f48a0fe53ca - main - LinuxKPI: add DEFINE_LOCK_GUARD_0 for rcu List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3f48a0fe53ca7e001852f4a406c1bdfab1cd2f6d Auto-Submitted: auto-generated The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=3f48a0fe53ca7e001852f4a406c1bdfab1cd2f6d commit 3f48a0fe53ca7e001852f4a406c1bdfab1cd2f6d Author: Bjoern A. Zeeb AuthorDate: 2025-09-04 20:25:30 +0000 Commit: Bjoern A. Zeeb CommitDate: 2025-09-05 23:24:15 +0000 LinuxKPI: add DEFINE_LOCK_GUARD_0 for rcu This adds guard support for non-real-types like rcu locking meaning that we need to keep the lock state separately ourselves. _T is still special and needs to be updated. Given it may not be used it needs an __unused attribute (we are using the LinuxKPI __maybe_unused which indeed is more expressive in this case). Sponsored by: The FreeBSD Foundation (initially) MFC after: 3 days Reviewed by: dumbbell Differential Revision: https://reviews.freebsd.org/D52076 --- sys/compat/linuxkpi/common/include/linux/cleanup.h | 35 ++++++++++++++++++++++ .../linuxkpi/common/include/linux/rcupdate.h | 5 +++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/sys/compat/linuxkpi/common/include/linux/cleanup.h b/sys/compat/linuxkpi/common/include/linux/cleanup.h index 45c2a2359ddf..5bb146f082ed 100644 --- a/sys/compat/linuxkpi/common/include/linux/cleanup.h +++ b/sys/compat/linuxkpi/common/include/linux/cleanup.h @@ -55,4 +55,39 @@ #define __free(_n) __cleanup(__free_##_n) +/* + * Given this is a _0 version it should likely be broken up into parts. + * But we have no idead what a _1, _2, ... version would do different + * until we see a call. + * This is used for a not-real-type (rcu). We use a bool to "simulate" + * the lock held. Also _T still special, may not always be used, so tag + * with __unused (or better the LinuxKPI __maybe_unused). + */ +#define DEFINE_LOCK_GUARD_0(_n, _lock, _unlock, ...) \ + \ + typedef struct { \ + bool lock; \ + __VA_ARGS__; \ + } guard_ ## _n ## _t; \ + \ + static inline void \ + guard_ ## _n ## _destroy(guard_ ## _n ## _t *_T) \ + { \ + if (_T->lock) { \ + _unlock; \ + } \ + } \ + \ + static inline guard_ ## _n ## _t \ + guard_ ## _n ## _create(void) \ + { \ + guard_ ## _n ## _t _tmp; \ + guard_ ## _n ## _t *_T __maybe_unused; \ + \ + _tmp.lock = true; \ + _T = &_tmp; \ + _lock; \ + return (_tmp); \ + } + #endif /* _LINUXKPI_LINUX_CLEANUP_H */ diff --git a/sys/compat/linuxkpi/common/include/linux/rcupdate.h b/sys/compat/linuxkpi/common/include/linux/rcupdate.h index 85d766c8dbc9..4aceb7296cd6 100644 --- a/sys/compat/linuxkpi/common/include/linux/rcupdate.h +++ b/sys/compat/linuxkpi/common/include/linux/rcupdate.h @@ -1,7 +1,7 @@ /*- * Copyright (c) 2016-2017 Mellanox Technologies, Ltd. * All rights reserved. - * Copyright (c) 2024 The FreeBSD Foundation + * Copyright (c) 2024-2025 The FreeBSD Foundation * * Portions of this software were developed by Björn Zeeb * under sponsorship from the FreeBSD Foundation. @@ -35,6 +35,7 @@ #include #include #include +#include #include @@ -162,4 +163,6 @@ void linux_synchronize_rcu(unsigned type); #define init_rcu_head_on_stack(...) #define destroy_rcu_head_on_stack(...) +DEFINE_LOCK_GUARD_0(rcu, rcu_read_lock(), rcu_read_unlock()) + #endif /* _LINUXKPI_LINUX_RCUPDATE_H_ */