From nobody Sat Feb 7 08:44:04 2026 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D65713B780; Thu, 28 Nov 2024 05:40:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732772433; cv=none; b=j+tG7QG6Ac71vlal6VbiDlCDUFWYsLzpfR1rNVfHmrO4gXtKW93pJnwxs3ZdxUIVr7bgnQweUftRY3eJ+jkZXx1py5KLvC43l3VcPnTiKdxqOtU+QOhUpJaQF/zFYonKDM6nuTdYp29ascbkkN1FKO+RcD6lb1Vq6YuVrgs7hQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732772433; c=relaxed/simple; bh=ixRiRLFUR6ATH+j6wrA/Rib8wv30TgwPXmEuEgllpXs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=D7eoxWWc6PsEUiqypsEHr7CsWdnrKUY7FQS3zOvODTUNAQkluhjgUiyFwRi8CoISnbwaNgBfoCk6PJkd0KN+KNIQ0Z1iRUNDKIgdEq01qIskYnmTYsQQ+Yd/63mqxk7W2q1aIZETZ/OVNfQQ/OMKyFZqfA0uwWvNPLZEG7FNwPI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FByEP0nu; arc=none smtp.client-ip=209.85.222.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FByEP0nu" Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-7b15467f383so34672585a.3; Wed, 27 Nov 2024 21:40:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732772431; x=1733377231; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:from:to:cc:subject :date:message-id:reply-to; bh=UuDqpNXPe14+YM41wgrKY6nvGGrPtfugmk04sFpdLAU=; b=FByEP0num8YBxhdfV/jKyl9zoRI+b7MMNbyMETEOyl+dEIAon4D3AhWNDdnYRuN3Nt dtZ6Jr1LbhT9c2FI9SxIR/h4pMa1lcOWYzhACcPWD5zp5S+hVuG/VZDq+V0FImfT1MiI WN+YKeNZXVolSqVdC0bnqNSsdmoiFsMmIp+oia9we7NoTkw/oaF7fXKJVN9p0xkVVj6W Nf7vOQ49QiT9bR6KFB5602SmuXjYQwsoyydISwc8RniaQ1ENXmv7Ofo+w+x9uSCa/Oe6 YGaZBU5ZfMfqpBNFgpTxPtnqun18cRClTAlAdorf2AJcqifJPvSIGB53/cDVXKwl1+c4 7IXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732772431; x=1733377231; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=UuDqpNXPe14+YM41wgrKY6nvGGrPtfugmk04sFpdLAU=; b=sMNLoaY8vzM3qnBfc4AdvM+NGJn/3CsZ9uv/sX3FfZ8BG98BC5S7WCPAUJyYoV5lxh PFqV5P4BRdo1/Ww6xmcVzBoIM/9uhz04o10ajAbx57i+uyw8qtZPql9my22iruwqtVza Fi34xryrtic/TK4QGdADn32HoBzDPW7B5OfbanNTpnvzo/Fw1ltKcThLRZMdkydeYCyI p7+Cln+HO7JEyZg/tE18gG78S+QOqxa134o+uVyAvN4fKlh8LYNMc1L4/K01iC4GXAps YeTu0JTQ3zlX6GIEV64GgEgwP2i98ugbxkMpI13cd1g+99yt0ipfy09V3BCGwgHOa+mb Bs1A== X-Forwarded-Encrypted: i=1; AJvYcCUntUbf3N/pI+DsNnf8ejvDE4GLDKgJNT1J3RUsl6U87yl+DqwryzzRXqi/YHBFC23NQj8BJjhZg9nAna8=@vger.kernel.org, AJvYcCVllmFVIar26I8sPyTPpi1xlq7yo/dPtoP93jv8rH/dNEEppgEm2fM1mwFRjNQwrexvWV6q2A8IOMlqhOZwBbo=@vger.kernel.org X-Gm-Message-State: AOJu0YyMdPMw4spAgy72W6ztHP4wi7yVwdIixYEitMvesOpwQEsJu/Ry PPSRLppMaO7obfcndXtUM5HE+DlC204tdwdHkMvRVSeghn4VG42d X-Gm-Gg: ASbGncuW36KcPKopIQSSh9J1/Zvwsk3+VQA618jX9+AIZP6IAeivA7b+TqM3wAW36vx 2JaeQV6g/otpnziXofua9Ix0betI8XrZeAfjlng+SAumQhUYCfUywg54/Jd0i0HO3+HJCcSFuSB ESvxAqh22KokVC/s/xp/mJdoQxopJbtRVLsKGeerguExinv2A3Z4lVLC6RDWvoycKQE+5TajxGD tku+l0k/ydhhX5Df3GX21dyeP/MFTSd1lvyfG9VdhHllUMJ/+y4eJ+pYHfnnkmzBsXkRbLGvy3H sGQq9cgWkEiLOIwSZchTwTap5L2RRipC4R1vSNYg X-Google-Smtp-Source: AGHT+IFMeO0gyRy/2FTu1UOOggSxZ0ngWzcNP/odyYzUJLnyityrEomUr8M59JcExIYe9ne+knR6Qg== X-Received: by 2002:a05:620a:2715:b0:7b6:6765:4ca6 with SMTP id af79cd13be357-7b67c47113amr642131785a.34.1732772431022; Wed, 27 Nov 2024 21:40:31 -0800 (PST) Received: from fauth-a2-smtp.messagingengine.com (fauth-a2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b6849ab218sm29149985a.95.2024.11.27.21.40.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 21:40:30 -0800 (PST) Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfauth.phl.internal (Postfix) with ESMTP id 358701200077; Thu, 28 Nov 2024 00:40:30 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Thu, 28 Nov 2024 00:40:30 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrhedtgdekhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecu hfhrohhmpeeuohhquhhnucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtg homheqnecuggftrfgrthhtvghrnhepgffhffevhffhvdfgjefgkedvlefgkeegveeuheel hfeivdegffejgfetuefgheeinecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhquhhnodhm vghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdeigedqudejjeekhe ehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfihigmhgvrdhnrghm vgdpnhgspghrtghpthhtohepudejpdhmohguvgepshhmthhpohhuthdprhgtphhtthhope hmihhnghhosehrvgguhhgrthdrtghomhdprhgtphhtthhopehpvghtvghriiesihhnfhhr rgguvggrugdrohhrghdprhgtphhtthhopehojhgvuggrsehkvghrnhgvlhdrohhrghdprh gtphhtthhopeifihhllheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhonhhgmhgr nhesrhgvughhrghtrdgtohhmpdhrtghpthhtoheprghlvgigrdhgrgihnhhorhesghhmrg hilhdrtghomhdprhgtphhtthhopehgrghrhiesghgrrhihghhuohdrnhgvthdprhgtphht thhopegsjhhorhhnfegpghhhsehprhhothhonhhmrghilhdrtghomhdprhgtphhtthhope gsvghnnhhordhlohhsshhinhesphhrohhtohhnrdhmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 28 Nov 2024 00:40:29 -0500 (EST) From: Boqun Feng To: Ingo Molnar , Peter Zijlstra , Miguel Ojeda Cc: Will Deacon , Waiman Long , Alex Gaynor , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Lyude Paul , Filipe Xavier , Boqun Feng Subject: [RFC 1/5] locking: MAINTAINERS: Start watching Rust locking primitives Date: Wed, 27 Nov 2024 21:40:18 -0800 Message-Id: <20241128054022.19586-2-boqun.feng@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241128054022.19586-1-boqun.feng@gmail.com> References: <20241128054022.19586-1-boqun.feng@gmail.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 Content-Type: text/plain; charset="utf-8" It makes sense to add Rust locking primitives under the watch of general locking primitives maintainers. This will encourage more reviews and find potential issues earlier. Hence add related Rust files into the LOCKING PRIMITIVES entry in MAINTAINERS. While we are at it, change the role of myself into the maintainer of LOCKDEP and RUST to reflect my responsibility for the corresponding code. Signed-off-by: Boqun Feng Acked-by: Ingo Molnar Acked-by: Miguel Ojeda Acked-by: Peter Zijlstra (Intel) --- MAINTAINERS | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index 443217066eb9..3a6a193fad99 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13351,8 +13351,8 @@ LOCKING PRIMITIVES M: Peter Zijlstra M: Ingo Molnar M: Will Deacon +M: Boqun Feng (LOCKDEP & RUST) R: Waiman Long -R: Boqun Feng (LOCKDEP) L: linux-kernel@vger.kernel.org S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git locking/c= ore @@ -13366,6 +13366,11 @@ F: include/linux/seqlock.h F: include/linux/spinlock*.h F: kernel/locking/ F: lib/locking*.[ch] +F: rust/helpers/mutex.c +F: rust/helpers/spinlock.c +F: rust/kernel/sync/lock.rs +F: rust/kernel/sync/lock/ +F: rust/kernel/sync/locked_by.rs X: kernel/locking/locktorture.c =20 LOGICAL DISK MANAGER SUPPORT (LDM, Windows 2000/XP/Vista Dynamic Disks) --=20 2.39.5 (Apple Git-154) From nobody Sat Feb 7 08:44:04 2026 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C79C213DBB6; Thu, 28 Nov 2024 05:40:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732772435; cv=none; b=FTNJf1CDuX7y/XxyJkoc9+DOAxDtttXqNr2h68y1iCXdI+UQyyYliVQdb+BpcjJ1ZsSvhIOBijdKPC5o47lXSbSg657fOp3vbBGbFdsiJck7klviY/aetynz6yzE7nVEDPx5Jn23O5gh5fAYlXq7DdgVxniWHEp8iyJ1bKgdkXs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732772435; c=relaxed/simple; bh=YN8n60PSDMwr7uU95ylj0vAul2eLak7aOtfQxBvzLIE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oOCNCELRY/6xWjsr/X0gxKYLaEMQehcX5VepjtBETANkTy8CTkbSS3GsrCBp/sLvkbAGV9Jf5jEOocVLhZ3wuhVu4y12DNM2AMia8fi7yIO3OhugRatwtcAWvvYza2jOF6KqsSh34onJLIBr4tRQn0p1Uws1ARkwGVg6w2ivgJ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HKOwXudE; arc=none smtp.client-ip=209.85.219.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HKOwXudE" Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-6d41f721047so3621056d6.1; Wed, 27 Nov 2024 21:40:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732772432; x=1733377232; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:from:to:cc:subject :date:message-id:reply-to; bh=SJfkPspJ/qv6pFbs/gDVi3DrHQvIU8R6iPu/lyxW774=; b=HKOwXudEnnZxPBu5YqItwaYcbtLl1yrWgM6mUE5utTcbWmnCNAcac398U2dSkPwnPB zQpovjIN91c+r2AO9MB1rhUSCl+N20ecuz2v3Mr44ApA4ehLOqZhWA0qu/s6s9g3tHbi hlBce8x7cTYQ108PjMV9B92gO68n5YsUdSqzCDgJFHlk5Az5zWLfxhjAmv7DrYkFpYpZ 1iWOQkVLyYTTr6VnWtiE6mNGMBQdJg1rbVsqFblUztZXJ2cbh3wdP9GS/oooILgewDWN qv+FduccilmeOFtuT5/ed0u5NryaL4XEX104LmTtEhwPUBVRIbnR7EEl0xRCQTvcpmvI 8JNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732772432; x=1733377232; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=SJfkPspJ/qv6pFbs/gDVi3DrHQvIU8R6iPu/lyxW774=; b=EBshqmtXOXazojrtHQO6Q7KSLSVZR2ecyA7rTF/5xOnEMh7RZJ0OmbvCPWA0baSjrg a6fzeRL3Pf4goIGeMa/Ns6v5y9K+skmNuANDTkM42JE8JAiNpZPvSZsb4vL8YBL3Eiia uYY68b6diCwTnf3hWLmGrSjc7qCsZO3ueIeHag4ft3CIJ06Gm/98FL2RTBWWHCfIwrd9 dXovSaaD/3xQYoZiUNr7qBUEW393L6Izg370lhZN/AsgmnbBrVvyg7Yy6pBQJe7wBwK2 NI167XGVyx/pq7ydhRX0K1qyM2hPNvCcpKb+l6tCnKiBmHvoH1+sbBOMRfT7L991qA2B 46KA== X-Forwarded-Encrypted: i=1; AJvYcCWmlSHPinQ9rCrYJzb8Ha/6wTrqofrSwgy33Ss/jIT7PSVvcrKhrtbRsTjNghVw4pyiJ/1evZGPjHHgr3aIyy0=@vger.kernel.org, AJvYcCX82VEvwGQu7PXlIN4RbmI6qZg+ERw0p+EoxG1hrJ93Z/IaP8FPwV+ZNkaCmdiKILGVKTPSpRfbA8GVe/g=@vger.kernel.org X-Gm-Message-State: AOJu0Yx7xWKcBZA2bbv5Y7PQcx70/YUl8WVDQxqQtR1e/+PNAFPFza5e gI8Q+g3kADLPYl2EfEg0JoTWi/4rnKsguCERZSoPi2vyFlJB7GLz X-Gm-Gg: ASbGncvNFZV4gKcbXsow/vPOiPYMTCZexwGpvEWqWWCAsLlVIA9jFjcgemaMIAxjm38 RYo0T33imqpMknw49GVFTubD+Wk/sRkp2Yy7dRNCp36H9LpI4BPXA6zIvyO7jY4nuhduhdPqHNo cH9IS7Kq347benw+5RzeCP257AS6+WXz3JzoCZzbIVA9axXXDQwKlGDpUN9ASH32LyKEs+4m/NT rNGC+CuABBqTMzRt8ghDrS3eVAoApfTaSQnIj/3xilwR60eUmy4A7gLlA9UDjEeqJQnq4yJSE9i m6FbAhn/SRkdEflg0nRQKXAwSPuFCxYS9QpUFalW X-Google-Smtp-Source: AGHT+IH+1jtP9enrnfOS30VjgW11fLVwljjSRsGYoMiA2+GdavbO0SE2rkj6DI0F3T2YSr7acDoATg== X-Received: by 2002:a05:6214:767:b0:6cb:3643:3370 with SMTP id 6a1803df08f44-6d864d78d27mr84817516d6.23.1732772432624; Wed, 27 Nov 2024 21:40:32 -0800 (PST) Received: from fauth-a2-smtp.messagingengine.com (fauth-a2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d87516651esm3178996d6.17.2024.11.27.21.40.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 21:40:32 -0800 (PST) Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfauth.phl.internal (Postfix) with ESMTP id BB5DB1200077; Thu, 28 Nov 2024 00:40:31 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Thu, 28 Nov 2024 00:40:31 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrhedtgdekhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecu hfhrohhmpeeuohhquhhnucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtg homheqnecuggftrfgrthhtvghrnhepudekleehjedtudfgudejvedvveeiffevveeufeet heeuteegjeefveelffeuteetnecuffhomhgrihhnpehfrhgvvgguvghskhhtohhprdhorh hgpdhkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhep mhgrihhlfhhrohhmpegsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhith ihqdeiledvgeehtdeigedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgr ihhlrdgtohhmsehfihigmhgvrdhnrghmvgdpnhgspghrtghpthhtohepudejpdhmohguvg epshhmthhpohhuthdprhgtphhtthhopehmihhnghhosehrvgguhhgrthdrtghomhdprhgt phhtthhopehpvghtvghriiesihhnfhhrrgguvggrugdrohhrghdprhgtphhtthhopehojh gvuggrsehkvghrnhgvlhdrohhrghdprhgtphhtthhopeifihhllheskhgvrhhnvghlrdho rhhgpdhrtghpthhtoheplhhonhhgmhgrnhesrhgvughhrghtrdgtohhmpdhrtghpthhtoh eprghlvgigrdhgrgihnhhorhesghhmrghilhdrtghomhdprhgtphhtthhopehgrghrhies ghgrrhihghhuohdrnhgvthdprhgtphhtthhopegsjhhorhhnfegpghhhsehprhhothhonh hmrghilhdrtghomhdprhgtphhtthhopegsvghnnhhordhlohhsshhinhesphhrohhtohhn rdhmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 28 Nov 2024 00:40:31 -0500 (EST) From: Boqun Feng To: Ingo Molnar , Peter Zijlstra , Miguel Ojeda Cc: Will Deacon , Waiman Long , Alex Gaynor , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Lyude Paul , Filipe Xavier , Boqun Feng Subject: [RFC 2/5] rust: sync: Add Lock::from_raw() for Lock<(), B> Date: Wed, 27 Nov 2024 21:40:19 -0800 Message-Id: <20241128054022.19586-3-boqun.feng@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241128054022.19586-1-boqun.feng@gmail.com> References: <20241128054022.19586-1-boqun.feng@gmail.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 Content-Type: text/plain; charset="utf-8" From: Lyude Paul The KMS bindings [1] have a few bindings that require manually acquiring specific locks before calling certain functions. At the moment though, the only way of acquiring these locks in bindings is to simply call the C locking functions directly - since said locks are not initialized on the Rust side of things. However - if we add `#[repr(C)]` to `Lock<(), B>`, then given `()` is a ZST - `Lock<(), B>` becomes equivalent in data layout to its inner `B::State` type. Since locks in C don't have data explicitly associated with them anyway, we can take advantage of this to add a `Lock::from_raw()` function that can translate a raw pointer to `B::State` into its proper `Lock<(), B>` equivalent. This lets us simply acquire a reference to the lock in question and work with it like it was initialized on the Rust side of things, allowing us to use less unsafe code to implement bindings with lock requirements. [Boqun: Use "Link:" instead of a URL and format the commit log] Signed-off-by: Lyude Paul Reviewed-by: Alice Ryhl Link: https://patchwork.freedesktop.org/series/131522/ [1] Signed-off-by: Boqun Feng Link: https://lore.kernel.org/r/20241119231146.2298971-2-lyude@redhat.com --- rust/kernel/sync/lock.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs index 41dcddac69e2..57dc2e90e504 100644 --- a/rust/kernel/sync/lock.rs +++ b/rust/kernel/sync/lock.rs @@ -96,6 +96,7 @@ unsafe fn relock(ptr: *mut Self::State, guard_state: &mut= Self::GuardState) { /// /// Exposes one of the kernel locking primitives. Which one is exposed dep= ends on the lock /// [`Backend`] specified as the generic parameter `B`. +#[repr(C)] #[pin_data] pub struct Lock { /// The kernel lock object. @@ -134,6 +135,28 @@ pub fn new(t: T, name: &'static CStr, key: &'static Lo= ckClassKey) -> impl PinIni } } =20 +impl Lock<(), B> { + /// Constructs a [`Lock`] from a raw pointer. + /// + /// This can be useful for interacting with a lock which was initialis= ed outside of Rust. + /// + /// # Safety + /// + /// The caller promises that `ptr` points to a valid initialised insta= nce of [`State`] during + /// the whole lifetime of `'a`. + /// + /// [`State`]: Backend::State + pub unsafe fn from_raw<'a>(ptr: *mut B::State) -> &'a Self { + // SAFETY: + // - By the safety contract `ptr` must point to a valid initialise= d instance of `B::State` + // - Since the lock data type is `()` which is a ZST, `state` is t= he only non-ZST member of + // the struct + // - Combined with `#[repr(C)]`, this guarantees `Self` has an equ= ivalent data layout to + // `B::State`. + unsafe { &*ptr.cast() } + } +} + impl Lock { /// Acquires the lock and gives the caller access to the data protecte= d by it. pub fn lock(&self) -> Guard<'_, T, B> { --=20 2.39.5 (Apple Git-154) From nobody Sat Feb 7 08:44:04 2026 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35A6E143C7E; Thu, 28 Nov 2024 05:40:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732772436; cv=none; b=cVIUrUsY9Yim4SwNp3EWnQ/3p4w5dAaJ9CN1Q/0YcX/lFZqlNpP8BYpD+4mJ63ZvoGVH/YotcYbNW+CYcZWKchoA4wqxpbkANJGQQi/aFPTDI9LXZ7c7tn6wo9dvhTKl84esyuKRdQA6srSDar31y5ZfWxH9lf/wnhj08qaFvmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732772436; c=relaxed/simple; bh=cuwL9VqarSJVGIwq+5/T9t9lJH8i9EKhmCPorLI0/mA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CeuiIcQQZijDkZ2usowHOES2oIzRm9DGD19dWyRFjdZujsZaVgaRl/l9Xrzl19TyMIK1FwpvwdrbD71pN/Z7N0Ru8KNX9qcBJBWvuXY4y+OD5cPFDFyvOPxjIR0qf+DBZn632bKDiJhTSlF8Mo38kS0MgWOcQMl7mbJ1VJaNSS4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CgboAPwB; arc=none smtp.client-ip=209.85.160.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CgboAPwB" Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-46695dd02e8so4452191cf.2; Wed, 27 Nov 2024 21:40:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732772434; x=1733377234; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:from:to:cc:subject :date:message-id:reply-to; bh=s9sC83tozDH958mCO8AjXOvSeVyc3KvU5CweJZKTNc4=; b=CgboAPwBZna0vS7g3TyaM4JNNMtRZlePlmBboILtAt4nExgtiE+UJ19se8nAUx2ltM 9fWs1pUqdIpZ/YFuCbkHnGh4dupqeeG6a3iIdNu4QjyyVMG+NZTR0+ejXOBKYbALLOic OP7RwTZlM7IEcMwcFfsGporp7F0d2M1pchmeMaNw3z14sCxMuKfKJindYmcRiFxk2YLe JG5o0JZMqano+hds2zwG3E/ktMdGqcS3G6j0+gmQBt7BGH/LAGtWjaD7sQxYjLXyniu3 Gc7h85UbYaD8fMx0zgr0rw9RXlAW1XhYrYPJ/E9cZprjCJoOjnB7VYfKaz+g/biPpgfn UadQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732772434; x=1733377234; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=s9sC83tozDH958mCO8AjXOvSeVyc3KvU5CweJZKTNc4=; b=nPgz3K7ctQNZHoGVXJHxdfMw/5+x/mhUiwwE7160ON378vvIUWt37D3Op4snvft2pj v6dKg9ynwVfzWF+87dWQWvHNHpxsKoppaePC/5EcnTN67eqeeGNKnul386D5tDcR+N4Z VqyL+bI8pfATpo0/nrPufMNanED/9ZjS3EdvYiqAFb4Sd6VetlUUPoA1xHyV+3EmZVSb 8800gjS2gfz8uLyKIe2MDsu7lzyXj8jvGWGf5BWFYvLrMXv9o821NU/axNx4Dkb4wr9X pzI3AHOwy350pifW8AHB/6da2E/ZVN9lJEOQ6odzf28uvvotgFkiID+iZuwDxjrI1x56 9i+A== X-Forwarded-Encrypted: i=1; AJvYcCVQ9Jlb+YxuY6osai0OXp0AST7MWf6VhyzlF/tbA5jMtM+qcUdz0jc+GKxDdWlvwd7SDB+dmY2xDUZvX3g=@vger.kernel.org, AJvYcCWVx6jBTjWmQhswlVY45ozD9TE5MtDhI/tiSDtGeVWget8/qS8//85Y+o+7BWzRdYGF1d7JSrKpy5TFiGExy0I=@vger.kernel.org X-Gm-Message-State: AOJu0Yzf0wts0FZo9kiD7NZxWHG4S62JUNXoClj8b9+vhSStTrGy6NjL RFLEKOxd8nqJDovCkVDk6p8YEp5TCX3wxlIkYP0kwrt1G3Cxysg6 X-Gm-Gg: ASbGnctL5tK8UKXK6m7weJc0hCPjQJJ4P2uZZ+tWDZ4kLL5Xaur4is9LsnRupe2QxbG 05FXvhkWyo+jTbMZfQVfl7mex94LPfbcdUiB3SHvYDqsTWj5GlzPsRqq+3x0zsP57eewoDdJyWC qti6avpCBEjS6Mh09OJlVoICsSIc82nWPddCuDSBXN1L9Gyfih9FlRQOyeJl94BZvnJpbYxdVo8 sVpeHYRPX3zFz+RWhs2V7/DBiC7cXCZm6UqkKxZaLLaTgPJ0s7B4dOLjO/RDjzOPV+hS19trfVZ iOVqAehU/OVwTjtEKNpimXkVZlrztOozlxqoz1tn X-Google-Smtp-Source: AGHT+IHgwZdR2+teOyM3YD+g4y+ADT+FCk0IgmuWoLP7jjC9Eq7T3FpxTEktQgwhBiSqurPBoEXGag== X-Received: by 2002:a05:622a:1bac:b0:466:b122:513e with SMTP id d75a77b69052e-466b359c947mr96108761cf.12.1732772434206; Wed, 27 Nov 2024 21:40:34 -0800 (PST) Received: from fauth-a2-smtp.messagingengine.com (fauth-a2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-466c421f832sm3107581cf.56.2024.11.27.21.40.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 21:40:33 -0800 (PST) Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfauth.phl.internal (Postfix) with ESMTP id 3D3511200079; Thu, 28 Nov 2024 00:40:33 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Thu, 28 Nov 2024 00:40:33 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrhedtgdekhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecu hfhrohhmpeeuohhquhhnucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtg homheqnecuggftrfgrthhtvghrnhepgffhffevhffhvdfgjefgkedvlefgkeegveeuheel hfeivdegffejgfetuefgheeinecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhquhhnodhm vghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdeigedqudejjeekhe ehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfihigmhgvrdhnrghm vgdpnhgspghrtghpthhtohepudejpdhmohguvgepshhmthhpohhuthdprhgtphhtthhope hmihhnghhosehrvgguhhgrthdrtghomhdprhgtphhtthhopehpvghtvghriiesihhnfhhr rgguvggrugdrohhrghdprhgtphhtthhopehojhgvuggrsehkvghrnhgvlhdrohhrghdprh gtphhtthhopeifihhllheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhonhhgmhgr nhesrhgvughhrghtrdgtohhmpdhrtghpthhtoheprghlvgigrdhgrgihnhhorhesghhmrg hilhdrtghomhdprhgtphhtthhopehgrghrhiesghgrrhihghhuohdrnhgvthdprhgtphht thhopegsjhhorhhnfegpghhhsehprhhothhonhhmrghilhdrtghomhdprhgtphhtthhope gsvghnnhhordhlohhsshhinhesphhrohhtohhnrdhmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 28 Nov 2024 00:40:32 -0500 (EST) From: Boqun Feng To: Ingo Molnar , Peter Zijlstra , Miguel Ojeda Cc: Will Deacon , Waiman Long , Alex Gaynor , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Lyude Paul , Filipe Xavier , Boqun Feng Subject: [RFC 3/5] rust: sync: Make Guard::new() public Date: Wed, 27 Nov 2024 21:40:20 -0800 Message-Id: <20241128054022.19586-4-boqun.feng@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241128054022.19586-1-boqun.feng@gmail.com> References: <20241128054022.19586-1-boqun.feng@gmail.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 Content-Type: text/plain; charset="utf-8" From: Lyude Paul Since we added a `Lock::from_raw()` function previously, it makes sense to also introduce an interface for creating a `Guard` from a reference to a `Lock` for instances where we've derived the `Lock` from a raw pointer and know that the lock is already acquired, there are such usages in KMS API. [Boqun: Add backquotes to type names, reformat the commit log, reword a bit on the usage of KMS API] Signed-off-by: Lyude Paul Reviewed-by: Filipe Xavier Reviewed-by: Alice Ryhl Signed-off-by: Boqun Feng Link: https://lore.kernel.org/r/20241119231146.2298971-3-lyude@redhat.com --- rust/kernel/sync/lock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs index 57dc2e90e504..72dbf3fbb259 100644 --- a/rust/kernel/sync/lock.rs +++ b/rust/kernel/sync/lock.rs @@ -234,7 +234,7 @@ impl<'a, T: ?Sized, B: Backend> Guard<'a, T, B> { /// # Safety /// /// The caller must ensure that it owns the lock. - pub(crate) unsafe fn new(lock: &'a Lock, state: B::GuardState) -= > Self { + pub unsafe fn new(lock: &'a Lock, state: B::GuardState) -> Self { Self { lock, state, --=20 2.39.5 (Apple Git-154) From nobody Sat Feb 7 08:44:04 2026 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88E8B146599; Thu, 28 Nov 2024 05:40:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732772438; cv=none; b=o9Nqi+IyinTV8LA6I1qrDUL5A8b9dvAMhtyx+i6IixdPNdQdhJ1aemPk4F2T0ETxLaXz9ErAP1W2oGlUNXu4RD8s6OwmjU4s/6cm4+DKT5lF6fP1NqAWJ/ewS3qC1e0HBWrng1YpbE4SBvSCmv3Cs0WpgcLWEiSm0zUnliZU12s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732772438; c=relaxed/simple; bh=JLuFJCiPXJaBx3ccyANB7IEhy956uEc8w5YOj6ESKzk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UtNYG6lndu3FGuxD9K4aSsMdjpvngEdfdr2eHIlbA3RoFAj2O5cQEmmKu+OoMzYb4TxWf7ECvM7AA4MW9kdAou4ULjgxpDKxu9xmYr+MuDeVHErZ0LWosQbp0W+iW2rNwDU22FyWrGN+L9oJHn/uEvB2TXhsP8IgxuqvSeYLAZY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=X5NIeU3G; arc=none smtp.client-ip=209.85.219.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="X5NIeU3G" Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-6d41eeca2d6so3780726d6.1; Wed, 27 Nov 2024 21:40:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732772435; x=1733377235; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:from:to:cc:subject :date:message-id:reply-to; bh=a/J+XDTMBujL2eWQ+xCrnrriCPdeqXCUJRKcpurXPz0=; b=X5NIeU3GwZjKTkCkDgHBn66cEQxXIzdXzNjz7e4QalGLcBr4uKzqlNsBL9+J1+05eA jdCK1CfQx6qLFBDsTwuQ1JSaRlYO7gxZisIHsHWm8v2JJuLjpIcM3PbBI2ri68/9JQqD 2m6v3YQYYAD0BXzsBf4E+XumaiJQoINUK5fEu6/SQd1vqNfhig2arn6zGWaJaDqlhMRJ wGbWWjwo4DNH++GyAxyTUsKWEV0KLH02TDTS3l41JvE3H+dHZh7mUhGC/XeqEvBYEG4v 98qY+rAWevpNCZdpN1JAt798LWoDSHt/4CxAThJcBGWHgmbp5pVeFR9sm5ZuNf2sWjXr UKvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732772435; x=1733377235; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=a/J+XDTMBujL2eWQ+xCrnrriCPdeqXCUJRKcpurXPz0=; b=QaYM8X9snaVoHK9niSvYmuGHWhx/JRR812iItylxTCzn6Ate0jNxvv6Xo1cD5JWqF/ ZgxQNMgvFBlpjGHRDW/PcSirgnbwRE5992CNI4U8rEQM71Zw2TL96BKarsQiEZMjHEcO md338GLIPTvzNAkM/oP91YDpAcV6qCP9HH7/wvF5520nlqEKRu7joTmOYVpEqv2Tl5Z5 1ai8oqWIKxDxfSEpRs1bio/BSVPejez2pLDcRufdEIRob+18OCdopVIEJDf2vZyEzENS W91Sir3jGsvfyjP9UkfYJhwNN1ef7Z7hgeECJorWcdhx+XwaT4DfTICSs4ZYjm8k6Qg8 qy1Q== X-Forwarded-Encrypted: i=1; AJvYcCUSn1LmCKyEBOexH8rMkuwnkKUUa1MDP6Aw9nwgKon+I2Sd+JWLEhlaaWbqWUF7AUBA9Y7N0YmlGIkqy8ME17A=@vger.kernel.org, AJvYcCVHhWu0Ullu2B9MIu6NDY3xwZLfAyff1T/ZpBmxrMLI2zosrh2iuH8PzV2obEKVkNliw1/7gJC2vSYxkuA=@vger.kernel.org X-Gm-Message-State: AOJu0YwYCU98rsuKriTK9yw3XvXi+FbN8nBISN/7obaDla0fY5BwR76z +acosZFgn/VS4sBwbuBYaFTgRZAUvco3EUqre/HZC7dDsiIdqR8O X-Gm-Gg: ASbGncvoubHp5tdoM24C7eLmpBuB6FcNilK9Jt/JNPv75Q9lEEksdoyv2euPrtK6+0i Kb3b6MW2XIzIcTeLh+pVAxU+hYMzCnnAXUf2FjEpTgrO8TRXRKkWqrkj/1iXdI12pf+A6cJMeYa wz9tVA+zeqOGkr2h351KyjJLDDIO2Y9M833FGx5vbUbTbLp6A7zceMlxjYddEfpeFf0a5pncjr1 xKvGvwE5nTqjIorI9+iQLLHc4KZSEPY02aQDT0h5bsvdH2mIyVOweL0Y8X986HM3sy4KfKJ1LyI djFAUSGFeKGrJ3qfOxQqrrwPKcb+2fbwrhIrpEZv X-Google-Smtp-Source: AGHT+IFhppQntXL1KL7iNkJVtdFW4nUluPJdwKCQ2x0UF4SuXdv+IDNf5NO3sULwF2FDVxLI0pm9PQ== X-Received: by 2002:a05:6214:1d2f:b0:6d4:1f86:b1e2 with SMTP id 6a1803df08f44-6d864d06e7fmr80452446d6.10.1732772435531; Wed, 27 Nov 2024 21:40:35 -0800 (PST) Received: from fauth-a2-smtp.messagingengine.com (fauth-a2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d8751f5635sm3122566d6.94.2024.11.27.21.40.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 21:40:35 -0800 (PST) Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfauth.phl.internal (Postfix) with ESMTP id B403F1200077; Thu, 28 Nov 2024 00:40:34 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Thu, 28 Nov 2024 00:40:34 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrhedtgdekhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecu hfhrohhmpeeuohhquhhnucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtg homheqnecuggftrfgrthhtvghrnhepgffhffevhffhvdfgjefgkedvlefgkeegveeuheel hfeivdegffejgfetuefgheeinecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhquhhnodhm vghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdeigedqudejjeekhe ehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfihigmhgvrdhnrghm vgdpnhgspghrtghpthhtohepudejpdhmohguvgepshhmthhpohhuthdprhgtphhtthhope hmihhnghhosehrvgguhhgrthdrtghomhdprhgtphhtthhopehpvghtvghriiesihhnfhhr rgguvggrugdrohhrghdprhgtphhtthhopehojhgvuggrsehkvghrnhgvlhdrohhrghdprh gtphhtthhopeifihhllheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhonhhgmhgr nhesrhgvughhrghtrdgtohhmpdhrtghpthhtoheprghlvgigrdhgrgihnhhorhesghhmrg hilhdrtghomhdprhgtphhtthhopehgrghrhiesghgrrhihghhuohdrnhgvthdprhgtphht thhopegsjhhorhhnfegpghhhsehprhhothhonhhmrghilhdrtghomhdprhgtphhtthhope gsvghnnhhordhlohhsshhinhesphhrohhtohhnrdhmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 28 Nov 2024 00:40:34 -0500 (EST) From: Boqun Feng To: Ingo Molnar , Peter Zijlstra , Miguel Ojeda Cc: Will Deacon , Waiman Long , Alex Gaynor , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Lyude Paul , Filipe Xavier , Boqun Feng Subject: [RFC 4/5] rust: sync: Add MutexGuard type alias Date: Wed, 27 Nov 2024 21:40:21 -0800 Message-Id: <20241128054022.19586-5-boqun.feng@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241128054022.19586-1-boqun.feng@gmail.com> References: <20241128054022.19586-1-boqun.feng@gmail.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 Content-Type: text/plain; charset="utf-8" From: Lyude Paul A simple helper alias for code that needs to deal with Guard types returned from Mutexes. Signed-off-by: Lyude Paul Reviewed-by: Alice Ryhl Signed-off-by: Boqun Feng Link: https://lore.kernel.org/r/20241120222742.2490495-2-lyude@redhat.com --- rust/kernel/sync.rs | 2 +- rust/kernel/sync/lock/mutex.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/rust/kernel/sync.rs b/rust/kernel/sync.rs index 1eab7ebf25fd..2721b5c8deda 100644 --- a/rust/kernel/sync.rs +++ b/rust/kernel/sync.rs @@ -16,7 +16,7 @@ pub use arc::{Arc, ArcBorrow, UniqueArc}; pub use condvar::{new_condvar, CondVar, CondVarTimeoutResult}; pub use lock::global::{global_lock, GlobalGuard, GlobalLock, GlobalLockBac= kend, GlobalLockedBy}; -pub use lock::mutex::{new_mutex, Mutex}; +pub use lock::mutex::{new_mutex, Mutex, MutexGuard}; pub use lock::spinlock::{new_spinlock, SpinLock}; pub use locked_by::LockedBy; =20 diff --git a/rust/kernel/sync/lock/mutex.rs b/rust/kernel/sync/lock/mutex.rs index 0e946ebefce1..10a70c07268d 100644 --- a/rust/kernel/sync/lock/mutex.rs +++ b/rust/kernel/sync/lock/mutex.rs @@ -86,6 +86,14 @@ macro_rules! new_mutex { /// [`struct mutex`]: srctree/include/linux/mutex.h pub type Mutex =3D super::Lock; =20 +/// A [`Guard`] acquired from locking a [`Mutex`]. +/// +/// This is simply a type alias for a [`Guard`] returned from locking a [`= Mutex`]. It will unlock +/// the [`Mutex`] upon being dropped. +/// +/// [`Guard`]: super::Guard +pub type MutexGuard<'a, T> =3D super::Guard<'a, T, MutexBackend>; + /// A kernel `struct mutex` lock backend. pub struct MutexBackend; =20 --=20 2.39.5 (Apple Git-154) From nobody Sat Feb 7 08:44:04 2026 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 385CA13C836; Thu, 28 Nov 2024 05:40:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732772439; cv=none; b=QXmLBcPa2yV3K0CiN0LQhNI83bGUF5UBmq1FM4llfbdgsSqIgIZc5SqiR3KlJKEpqwA1Z8tPqlzlNZIZHFTNED1qlwhvWcBTkGTaFh5RVmW+ZVI31a5fQsHxQgSlsqp6dDWakMOi+nqgFN0Ch0Jf+2OSxMbAYQrud0mzesrySTQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732772439; c=relaxed/simple; bh=1irOa5iMMXRoDzCJXwveBV0OqpPr+P+ur0YtrHr68zY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rXruprDbZH5M3rDv7M/+09dK173zjcDLgPz6DU2ueRNdNfIsHn08/3ngXZN4ZiAcUfof+ynMxOOGHfBmtEdFzGgYDdbF0HWMPDQFKml4p2GvLVtQJuOiucu3tAuBxqUXHfkBMIOyR5gJTaepC3nm5ZaIiyAwwFvS56ZxMelhlHQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WLchBLth; arc=none smtp.client-ip=209.85.222.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WLchBLth" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-7b666215645so22428585a.0; Wed, 27 Nov 2024 21:40:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732772437; x=1733377237; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:from:to:cc:subject :date:message-id:reply-to; bh=qe5bljGPbBbJFGGFe8TjhBQ9K3SXU61aSYWBPYS66OQ=; b=WLchBLthFldz3EG2zc/VKR4/ReNkGJdcPCOHzRnPRj3CMQ+AJpITYDIZGJ8EwVssyK Sq8gxa2cDiloOgCXeCbnCa/Bnkc4zwHmXEfK7+S0l9NhhjZSg1FCIdqeZ+OrfW9HHd5C MEPm+nc1CRxN8iclSpED1cAqZGBcKYAyIPkOZBn+ycKMyMyhSnjflZgtWojh3iTiqzk+ RTWTA6dCi3VtwB0PfY1v7qce7/2KyeIjVvWCUofnjQKd5AiyKbfbYEUl47WupA6cgOAI vtp5YVTbqZCmiN6dCkrpmwCrKxA+1kb7wCyAIISmwe+a3JG2iArRH2phW0EkK7FBko9z Nc+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732772437; x=1733377237; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=qe5bljGPbBbJFGGFe8TjhBQ9K3SXU61aSYWBPYS66OQ=; b=PdG5YhLX8By8DJM9VsDVZKfybHPcU333P3y5k/ghQ9s37bzFOuXEKkwH2ta3iGeAw8 if1UgUABifYWgSjBAdcRSBC8NtA+oWj6dATZpmZ4gpFfWIH5eVu+yuiTxBRPzUAEM2Sp dBWqJSNrv2zwoS6+0n6vQiKacwdSpPeSNGaa2vGq/h19o5MBV08Jofc5N60iL7HizDSf E76qgh4cqw6H1dBiJNIrv8n/ziEqupC/PvTyUXQmdXXr+9LdBumsA1+XU0IiEvvliCya q2cw7FLzkjbfoPsicRVfS0FVgLMWrXn5aCPZHKQrvUco4yBbnl/9h4bVwuWhv8lhEqUj CLQQ== X-Forwarded-Encrypted: i=1; AJvYcCU0osCDmgI1bxvDCwgHg9LgjoVL47ruYB3B6XHB6GF+ZzSYvw4ohHeDL+fwFZCo0SVc+I/1RvXo+sYfjdFgOSU=@vger.kernel.org, AJvYcCUf51eDZkImZuutDzanZ9VlJrd6yCxmvrIxLyEvJ4hO4JfDHZYMj7q8SpK3U0R+ALGVez7CyGPgePCopMM=@vger.kernel.org X-Gm-Message-State: AOJu0YyXOksNEQElqVr1nw7r0h3tHyI9jL8FkMnMqnGf4gZrGbwRalBZ 6awQywZRtvXYqYRf+ZduK65aS5RE+9lI0A4o8v2u7DCDHqTiKTqf X-Gm-Gg: ASbGnctI0ofcNcZSsRCzegFlLNEH4pNd7Oo6Z2agDW9QxLt0bTZOqdCdgli9L3InvAH Fxa0mpfjfPRi86uH94sZuY1URQAL7YgeAP1M4Ad/Pb64dn1d0nAdzBVoa7BlMoPNV8wng2lL4oF 8v5RMItsbE3mRrK4JMu7HsbjAmkuRur+xJ6y/gPVxchSsG8p0FwE3oPT+lXCNX1+pAqENzOt5el EzSgzJt+eM+Po9ZzcFK56MDZsYeTsgNKVQoEOSdCNvrCKC0jEVoOpet0+PhU3+Kk0VuQ6CFmVnF eaboWbvJNIFY2zZWF6wxY+WsK15QM4rIfRXY7Z8d X-Google-Smtp-Source: AGHT+IF9fs3kli7JcKoMj1NEFNyoAQcN9hkYTEd2oIPST/YfiSLfaOzVILdiwnWjDfqA1wxkx2G25A== X-Received: by 2002:a05:620a:260b:b0:7af:daa4:3564 with SMTP id af79cd13be357-7b67c460896mr893254585a.48.1732772437034; Wed, 27 Nov 2024 21:40:37 -0800 (PST) Received: from fauth-a2-smtp.messagingengine.com (fauth-a2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b6849b7280sm28985085a.102.2024.11.27.21.40.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 21:40:36 -0800 (PST) Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfauth.phl.internal (Postfix) with ESMTP id 316441200077; Thu, 28 Nov 2024 00:40:36 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-09.internal (MEProxy); Thu, 28 Nov 2024 00:40:36 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrhedtgdekhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecu hfhrohhmpeeuohhquhhnucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtg homheqnecuggftrfgrthhtvghrnhepgffhffevhffhvdfgjefgkedvlefgkeegveeuheel hfeivdegffejgfetuefgheeinecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhquhhnodhm vghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdeigedqudejjeekhe ehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfihigmhgvrdhnrghm vgdpnhgspghrtghpthhtohepudejpdhmohguvgepshhmthhpohhuthdprhgtphhtthhope hmihhnghhosehrvgguhhgrthdrtghomhdprhgtphhtthhopehpvghtvghriiesihhnfhhr rgguvggrugdrohhrghdprhgtphhtthhopehojhgvuggrsehkvghrnhgvlhdrohhrghdprh gtphhtthhopeifihhllheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhonhhgmhgr nhesrhgvughhrghtrdgtohhmpdhrtghpthhtoheprghlvgigrdhgrgihnhhorhesghhmrg hilhdrtghomhdprhgtphhtthhopehgrghrhiesghgrrhihghhuohdrnhgvthdprhgtphht thhopegsjhhorhhnfegpghhhsehprhhothhonhhmrghilhdrtghomhdprhgtphhtthhope gsvghnnhhordhlohhsshhinhesphhrohhtohhnrdhmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 28 Nov 2024 00:40:35 -0500 (EST) From: Boqun Feng To: Ingo Molnar , Peter Zijlstra , Miguel Ojeda Cc: Will Deacon , Waiman Long , Alex Gaynor , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Lyude Paul , Filipe Xavier , Boqun Feng Subject: [RFC 5/5] rust: sync: Add SpinLockGuard type alias Date: Wed, 27 Nov 2024 21:40:22 -0800 Message-Id: <20241128054022.19586-6-boqun.feng@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241128054022.19586-1-boqun.feng@gmail.com> References: <20241128054022.19586-1-boqun.feng@gmail.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 Content-Type: text/plain; charset="utf-8" From: Lyude Paul A simple helper alias for code that needs to deal with Guard types returned from SpinLocks. Signed-off-by: Lyude Paul Reviewed-by: Alice Ryhl Signed-off-by: Boqun Feng Link: https://lore.kernel.org/r/20241120222742.2490495-3-lyude@redhat.com --- rust/kernel/sync.rs | 2 +- rust/kernel/sync/lock/spinlock.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/rust/kernel/sync.rs b/rust/kernel/sync.rs index 2721b5c8deda..dffdaad972ce 100644 --- a/rust/kernel/sync.rs +++ b/rust/kernel/sync.rs @@ -17,7 +17,7 @@ pub use condvar::{new_condvar, CondVar, CondVarTimeoutResult}; pub use lock::global::{global_lock, GlobalGuard, GlobalLock, GlobalLockBac= kend, GlobalLockedBy}; pub use lock::mutex::{new_mutex, Mutex, MutexGuard}; -pub use lock::spinlock::{new_spinlock, SpinLock}; +pub use lock::spinlock::{new_spinlock, SpinLock, SpinLockGuard}; pub use locked_by::LockedBy; =20 /// Represents a lockdep class. It's a wrapper around C's `lock_class_key`. diff --git a/rust/kernel/sync/lock/spinlock.rs b/rust/kernel/sync/lock/spin= lock.rs index 9f4d128bed98..081c0220013b 100644 --- a/rust/kernel/sync/lock/spinlock.rs +++ b/rust/kernel/sync/lock/spinlock.rs @@ -87,6 +87,14 @@ macro_rules! new_spinlock { /// A kernel `spinlock_t` lock backend. pub struct SpinLockBackend; =20 +/// A [`Guard`] acquired from locking a [`SpinLock`]. +/// +/// This is simply a type alias for a [`Guard`] returned from locking a [`= SpinLock`]. It will unlock +/// the [`SpinLock`] upon being dropped. +/// +/// [`Guard`]: super::Guard +pub type SpinLockGuard<'a, T> =3D super::Guard<'a, T, SpinLockBackend>; + // SAFETY: The underlying kernel `spinlock_t` object ensures mutual exclus= ion. `relock` uses the // default implementation that always calls the same locking method. unsafe impl super::Backend for SpinLockBackend { --=20 2.39.5 (Apple Git-154)