From nobody Sun Feb 8 05:08:11 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 D2C9C258CD8 for ; Fri, 7 Mar 2025 23:28:42 +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=1741390124; cv=none; b=K8RaTN+ckUAMtXGTbqz+Xh1EyVMhykTTGNIFWmBguO/3YFFVFOlXB6KwxKCFYM/i1P8Qid+OhV7/np200H8hzq1VEgsnYwQO9gz/3mfZlJ1JyNPFNaaS3Ji0mV4lVQU5Fp/FvfJXzCyW+OHvcWoitFwn/DLjOiz32m9yCIwLS2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390124; c=relaxed/simple; bh=KDNVqr/S/byS4T7wBHLFLKUTFNzAkppqHeaF42sUSNQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FjcSol+6FYm9jKhXedu26Nx+Q2BiHtlGP+FSrLbfTseOhb4i/Uyb1Q2Y1RjuDYVRRtTBcalfNAtYbPHkgaXfla3v/ILSNxoVjqZDgui2HhD3VCHIqqxL0bFOGcOK37N5wrj2i0tp/hIJu/cRI3RCMFZuoCcy5CXMWRdQdE7iOuU= 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=G1T5v1nd; 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="G1T5v1nd" Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-7c3b63dfebfso272208185a.3 for ; Fri, 07 Mar 2025 15:28:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741390121; x=1741994921; 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=lRPqFGRZw6NFdUejOY/dH/DT35a3CucFgKyNntrLxXk=; b=G1T5v1ndOaEQX+YTmxvaQl+9AJDWkmiuVmdBC0vjwMQNaUXaG425PVp0D57vkR+3MX UZdd/AEpzqlicxFgCcEY/IoFaLawCNpPMDTg5eroQJ4muBUztLXxoI1IxCwwIdtCBE3c yz9wq77YVkdAnIUNDa8ElrYQcnOEuXDn+j9k6creThl9BFvFAuSOysoV66a0ivvZaSSy AiFssyAhy/SJd/TuN5Xs5jfz+ePMUpLiAhesnORmb3lLlaeJWOUAzrPcKcFfy9K7GO/f HfXmSyNOFtqZVuX0ZszvzmzbOLy83za+xpe44pudYlc5YLoGYSN2rGLKB1xUBiTov8x3 Ohig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741390121; x=1741994921; 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=lRPqFGRZw6NFdUejOY/dH/DT35a3CucFgKyNntrLxXk=; b=UhHZ7R/7j7N/RjMb4nw23nrutgtgZP6Hdp+TkPGO8LumhVZI0r26lq3GaODgi7k0EG 90BH7Okr8EL/VeuR9ru7m77zHtqRFevaa3iixjjBBAJe6ZFdGIDAPHMZ8ERyhQJwKmRQ IgZKqEfqH4Y+zide0xbB50zRLAULHhaghk6LTAcAO+nli5+vnRgaa4wi0xfx9Z/yicdI GdPr/TJ4Wh0bgKzEWB4YQszyYP/qKdGvCKnOPdoNoFvZZbEjHRTSoNEyfLZB5Vg9kq2H rJarCOAE8VdmZ0ibPls9tgyCwXw9e3/K6TZ9y+Sb0ANHnOubCk6ZnONqCguA4MKdKzqf xAGQ== X-Forwarded-Encrypted: i=1; AJvYcCUs33vcL6XYmojTQi934nBgDnMrFbYW8IBFM33XvdZEFYGxZ345oqf2cFVice8NWpkAioF8DhBUjz2zhZc=@vger.kernel.org X-Gm-Message-State: AOJu0YxL+IqrrrFy6burZlK3pVLhQy9bw5BLyyhcYh7FLRTTBhGElKXT KHzJ9rt+ALBcRq6apZZUpSiacxwsJuNEcutfpirDLKhBpcXtX0y3 X-Gm-Gg: ASbGncvQrXyLvTFvD+rdIpBR1pkS1jNDhGbk7CbpfCunUvlc9B+Hj1HnnfFt0hgsist UWB1iLVw74v23ZJhAPDKScpvSV5jVdetlbTmnBoHKt1Y2w7n5RK/b283HAi3sBW+oGea8Qwt+qN qWlO+hPbjcHYsC5gEdaBa5pTPiJMhMgtTUJK6XZCdGtee5CM7kKQgKocWBgrPvTVZl0coJDR7R/ aw76jKvTKsNdtqRN/NUU+ihxw1FLLOiAzmrg7UZ10zoTbwoYCrGZPbRvCplZyggTPqWJlIhRsF2 O3JF0I/WA2hdGXOtQKuV2UPGi2C9uuxT6sv3qaKqiaqE+qTXTOmjO2nXUx2zv+poQB7n+jPZ0vd 4A0szypAd5RI1tSFRs6JcEqBmOVrm4PgZa8s= X-Google-Smtp-Source: AGHT+IFyGDiG9sfPUruLtGIwuXWA8Of7BRLMxPCHa7zC6WxZM5GLrB1q8EP1fULDJ4zqghRVSf3fww== X-Received: by 2002:a05:620a:4808:b0:7b6:d26e:9d89 with SMTP id af79cd13be357-7c4e6178cefmr736471185a.42.1741390121626; Fri, 07 Mar 2025 15:28:41 -0800 (PST) Received: from fauth-a1-smtp.messagingengine.com (fauth-a1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c3e5381d16sm302866485a.51.2025.03.07.15.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Mar 2025 15:28:41 -0800 (PST) Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfauth.phl.internal (Postfix) with ESMTP id CC6C0120006A; Fri, 7 Mar 2025 18:28:40 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Fri, 07 Mar 2025 18:28:40 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduudduleekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredt tdenucfhrhhomhepuehoqhhunhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrih hlrdgtohhmqeenucggtffrrghtthgvrhhnpefghfffvefhhfdvgfejgfekvdelgfekgeev ueehlefhiedvgeffjefgteeugfehieenucffohhmrghinhepkhgvrhhnvghlrdhorhhgne cuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhu nhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqdduje ejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdr nhgrmhgvpdhnsggprhgtphhtthhopeekpdhmohguvgepshhmthhpohhuthdprhgtphhtth hopehmihhnghhosehkvghrnhgvlhdrohhrghdprhgtphhtthhopehpvghtvghriiesihhn fhhrrgguvggrugdrohhrghdprhgtphhtthhopeifihhllheskhgvrhhnvghlrdhorhhgpd hrtghpthhtoheplhhonhhgmhgrnhesrhgvughhrghtrdgtohhmpdhrtghpthhtoheplhhi nhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprh guuhhnlhgrphesihhnfhhrrgguvggrugdrohhrghdprhgtphhtthhopehmihhnghhosehr vgguhhgrthdrtghomhdprhgtphhtthhopegsohhquhhnrdhfvghnghesghhmrghilhdrtg homh X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Mar 2025 18:28:40 -0500 (EST) From: Boqun Feng To: Ingo Molnar , Peter Zijlstra Cc: Will Deacon , Waiman Long , linux-kernel@vger.kernel.org, Randy Dunlap , Ingo Molnar , Boqun Feng Subject: [PATCH locking 01/11] locking/rtmutex: Use struct keyword in kernel-doc comment Date: Fri, 7 Mar 2025 15:26:51 -0800 Message-ID: <20250307232717.1759087-2-boqun.feng@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250307232717.1759087-1-boqun.feng@gmail.com> References: <20250307232717.1759087-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: Randy Dunlap Add the "struct" keyword to prevent a kernel-doc warning: rtmutex_common.h:67: warning: cannot understand function prototype: 'struct= rt_wake_q_head ' Signed-off-by: Randy Dunlap Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Will Deacon Cc: Waiman Long Cc: Boqun Feng Acked-by: Waiman Long Signed-off-by: Boqun Feng Link: https://lore.kernel.org/r/20250111063040.910763-1-rdunlap@infradead.o= rg --- kernel/locking/rtmutex_common.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/locking/rtmutex_common.h b/kernel/locking/rtmutex_commo= n.h index c38a2d2d4a7e..78dd3d8c6554 100644 --- a/kernel/locking/rtmutex_common.h +++ b/kernel/locking/rtmutex_common.h @@ -59,8 +59,8 @@ struct rt_mutex_waiter { }; =20 /** - * rt_wake_q_head - Wrapper around regular wake_q_head to support - * "sleeping" spinlocks on RT + * struct rt_wake_q_head - Wrapper around regular wake_q_head to support + * "sleeping" spinlocks on RT * @head: The regular wake_q_head for sleeping lock variants * @rtlock_task: Task pointer for RT lock (spin/rwlock) wakeups */ --=20 2.47.1 From nobody Sun Feb 8 05:08:11 2026 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) (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 2A63425A348 for ; Fri, 7 Mar 2025 23:28:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390128; cv=none; b=aIZzSktlpD+cBTzq0A+KRSmI3HSbh2IZkc1nr+wI8T5fVXUd5UQhoMNp478QoLEAuaYUJjlKDBpf+aHWw2tF0K4XdmB6VJSGj4V46qzxlBnxROcgJEVezOxasFwsl5Q8zdXrgs3AyrjCJ7ONh4hNh/zJthiX+DPOBe/dxM1adRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390128; c=relaxed/simple; bh=51MZLzXkS/gAmyurVHEUuvnawFcO89opK6dXX3LX/B0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NKA2O+y85bWKf0sla7y7TY+NISodOXREe0cPbOeDS1jH8UmsX0+fBT53HPmcR7C0gv2BHHO2WbAQJyKqmQgpxx/6//M/4lN4mIICfWm/p227U8UiiwHNrp9Z9+R4+aZcZj5Q83+SPnYf8S7fmj2qB8KwP52BPiK8Cp5z8YmJ2SU= 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=g5zCTnEY; arc=none smtp.client-ip=209.85.222.170 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="g5zCTnEY" Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-7c0e135e953so250768985a.2 for ; Fri, 07 Mar 2025 15:28:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741390125; x=1741994925; 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=cUiFX8pTShZ5Z5nSz7FJsuU+rZ7PTZP7Um1B6Q+rnpc=; b=g5zCTnEYerA6nQbIIdk0SqKufwYDQ+Q8LyUqyL0rWhPAeRgQ+hTZOP0yQngL7NDUK5 oZXs5F4FZeeFFvNnFHk4p/cInrlCgFkCHzdAS6awfGnRkmqinHh4MKJfw38nYnU4VS7U TtOk9OjkH/HExG8knlseNHxT63NLg15lsbezS2N3OivIHokvA1Q557n9Mf2R3Lw+v5S6 cbTIhd+KZdzExEUsoAvThBmwV4g2DFeIayYpUs+ov5RpZ4eqpBX5zqCkQdCVsJfi4Lnd eWaarXoGws1pBLgFRmjV9XHO3+fQLDZtAot9Cde0Chb5AQcb56TJ0PUII8DmQa4Y01ri 1KGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741390125; x=1741994925; 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=cUiFX8pTShZ5Z5nSz7FJsuU+rZ7PTZP7Um1B6Q+rnpc=; b=cVdGq6qUpn8uv2AiMC7raCUWcoWQF4Ic0EJk9waPUBDp8nGIXTEZKfCjthqvRHu3uK djjqhlDkmoDcu1yF1M9zMmhRb0qtSIe9F1q6b8V6cYszyt10/ik33SMTaYqnvesHbtZ3 fjzYiXmWYi6UTPNdvbDPFr1h3+0jIp2y2Jb4eKA4N5+ncq3qOiRIF8maCCCdlRCZVSfO /Yoex3ku+UOo+4tbO2F7c4Ux91+0aSv/myUpz06LGskVv1i9QRq4iPcXgKBvVP7ELPKK xnkct/HoukXcYFreBIoV0YuM2Ae6Q6cD8wtZDf3PQ03M7ZfHKqCgivA1DVqXrqK/l+cs 5NkA== X-Forwarded-Encrypted: i=1; AJvYcCXzNOPJeLB3kMFB3dFl7LrvI/dgcytfbw4kSZNRl7kaF5yOlSOdVBepBQHZa+zRY8GEktH8x4MyFLfjVHc=@vger.kernel.org X-Gm-Message-State: AOJu0YyswEWmDrHM+ueod4aSmQb/yvfd5SJasDd/JLpPTOOmzZdQc6e9 oazLKq24Nh838C8nOpYqddOk42l+Dd3VKiVbhxJNuRXuEuOeEHlK X-Gm-Gg: ASbGncubx3CrstpCx+0GxUnONXUGg3iVkhVRuPW9BXHG8/nn0UovFhEfvyr4OfCK3vZ s9GBv7iXhMQAabKCXACfix3ZsAi8gKVOar4ZsNBj74lmUxuWAWGFMKGQSTatgOGYLH+WoG+Cj6d vzsoC6reDsUmPMNPXSxNMK2TZ0zkYZDfoG+6mI4nbm/wmZfzHZ9OHS/LaG3U+tLr71OMm4QHrYE chAF7THpQOrOG/d8qxZZP6JTqKYA+wj5+vU723ufuriZbeoMDZnkisbxyoSHP5nSzWV8eux1kad jue4ZcwhVUXtyBP9T1zb/VJSVEeKew38UPbiQsuuwW9FECtSrBt7oe667LuTY9prw+G7sr/EMUh ceVevpdScBGeyBHFQn3EoeJNYwoftciphbjg= X-Google-Smtp-Source: AGHT+IHuhEDsVS6PpbJiWQoNhXqLd6dP41mFNik4w0hbc1MxTAzVESDNoU2wQmZU3Iq2nn/VRxKxGw== X-Received: by 2002:a05:620a:2814:b0:7c0:9fb1:683d with SMTP id af79cd13be357-7c4e61122c3mr709955585a.34.1741390123430; Fri, 07 Mar 2025 15:28:43 -0800 (PST) Received: from fauth-a1-smtp.messagingengine.com (fauth-a1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c3e54ff881sm302599785a.68.2025.03.07.15.28.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Mar 2025 15:28:43 -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 9A785120006A; Fri, 7 Mar 2025 18:28:42 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Fri, 07 Mar 2025 18:28:42 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduudduleelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredt tdenucfhrhhomhepuehoqhhunhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrih hlrdgtohhmqeenucggtffrrghtthgvrhhnpefghfffvefhhfdvgfejgfekvdelgfekgeev ueehlefhiedvgeffjefgteeugfehieenucffohhmrghinhepkhgvrhhnvghlrdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhu nhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqdduje ejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdr nhgrmhgvpdhnsggprhgtphhtthhopeduuddpmhhouggvpehsmhhtphhouhhtpdhrtghpth htohepmhhinhhgoheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepphgvthgvrhiisehi nhhfrhgruggvrggurdhorhhgpdhrtghpthhtohepfihilhhlsehkvghrnhgvlhdrohhrgh dprhgtphhtthhopehlohhnghhmrghnsehrvgguhhgrthdrtghomhdprhgtphhtthhopehl ihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhope gsohhquhhnrdhfvghnghesghhmrghilhdrtghomhdprhgtphhtthhopehmihhnghhosehr vgguhhgrthdrtghomhdprhgtphhtthhopegsihhgvggrshihsehlihhnuhhtrhhonhhigi druggvpdhrtghpthhtoheptghlrhhkfihllhhmsheskhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Mar 2025 18:28:42 -0500 (EST) From: Boqun Feng To: Ingo Molnar , Peter Zijlstra Cc: Will Deacon , Waiman Long , linux-kernel@vger.kernel.org, Boqun Feng , Ingo Molnar , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , linux-rt-devel@lists.linux.dev (open list:Real-time Linux (PREEMPT_RT):Keyword:PREEMPT_RT) Subject: [PATCH locking 02/11] locking/semaphore: Use wake_q to wake up processes outside lock critical section Date: Fri, 7 Mar 2025 15:26:52 -0800 Message-ID: <20250307232717.1759087-3-boqun.feng@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250307232717.1759087-1-boqun.feng@gmail.com> References: <20250307232717.1759087-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: Waiman Long A circular lock dependency splat has been seen involving down_trylock(). [ 4011.795602] =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D [ 4011.795603] WARNING: possible circular locking dependency detected [ 4011.795607] 6.12.0-41.el10.s390x+debug [ 4011.795612] ------------------------------------------------------ [ 4011.795613] dd/32479 is trying to acquire lock: [ 4011.795617] 0015a20accd0d4f8 ((console_sem).lock){-.-.}-{2:2}, at: down_= trylock+0x26/0x90 [ 4011.795636] [ 4011.795636] but task is already holding lock: [ 4011.795637] 000000017e461698 (&zone->lock){-.-.}-{2:2}, at: rmqueue_bulk= +0xac/0x8f0 the existing dependency chain (in reverse order) is: -> #4 (&zone->lock){-.-.}-{2:2}: -> #3 (hrtimer_bases.lock){-.-.}-{2:2}: -> #2 (&rq->__lock){-.-.}-{2:2}: -> #1 (&p->pi_lock){-.-.}-{2:2}: -> #0 ((console_sem).lock){-.-.}-{2:2}: The console_sem -> pi_lock dependency is due to calling try_to_wake_up() while holding the console.sem raw_spinlock. This dependency can be broken by using wake_q to do the wakeup instead of calling try_to_wake_up() under the console_sem lock. This will also make the semaphore's raw_spinlock become a terminal lock without taking any further locks underneath it. The hrtimer_bases.lock is a raw_spinlock while zone->lock is a spinlock. The hrtimer_bases.lock -> zone->lock dependency happens via the debug_objects_fill_pool() helper function in the debugobjects code. [ 4011.795646] -> #4 (&zone->lock){-.-.}-{2:2}: [ 4011.795650] __lock_acquire+0xe86/0x1cc0 [ 4011.795655] lock_acquire.part.0+0x258/0x630 [ 4011.795657] lock_acquire+0xb8/0xe0 [ 4011.795659] _raw_spin_lock_irqsave+0xb4/0x120 [ 4011.795663] rmqueue_bulk+0xac/0x8f0 [ 4011.795665] __rmqueue_pcplist+0x580/0x830 [ 4011.795667] rmqueue_pcplist+0xfc/0x470 [ 4011.795669] rmqueue.isra.0+0xdec/0x11b0 [ 4011.795671] get_page_from_freelist+0x2ee/0xeb0 [ 4011.795673] __alloc_pages_noprof+0x2c2/0x520 [ 4011.795676] alloc_pages_mpol_noprof+0x1fc/0x4d0 [ 4011.795681] alloc_pages_noprof+0x8c/0xe0 [ 4011.795684] allocate_slab+0x320/0x460 [ 4011.795686] ___slab_alloc+0xa58/0x12b0 [ 4011.795688] __slab_alloc.isra.0+0x42/0x60 [ 4011.795690] kmem_cache_alloc_noprof+0x304/0x350 [ 4011.795692] fill_pool+0xf6/0x450 [ 4011.795697] debug_object_activate+0xfe/0x360 [ 4011.795700] enqueue_hrtimer+0x34/0x190 [ 4011.795703] __run_hrtimer+0x3c8/0x4c0 [ 4011.795705] __hrtimer_run_queues+0x1b2/0x260 [ 4011.795707] hrtimer_interrupt+0x316/0x760 [ 4011.795709] do_IRQ+0x9a/0xe0 [ 4011.795712] do_irq_async+0xf6/0x160 Normally raw_spinlock to spinlock dependency is not legit and will be warned if PROVE_RAW_LOCK_NESTING is enabled, but debug_objects_fill_pool() is an exception as it explicitly allows this dependency for non-PREEMPT_RT kernel without causing PROVE_RAW_LOCK_NESTING lockdep splat. As a result, this dependency is legit and not a bug. Anyway, semaphore is the only locking primitive left that is still using try_to_wake_up() to do wakeup inside critical section, all the other locking primitives had been migrated to use wake_q to do wakeup outside of the critical section. It is also possible that there are other circular locking dependencies involving printk/console_sem or other existing/new semaphores lurking somewhere which may show up in the future. Let just do the migration now to wake_q to avoid headache like this. Reported-by:syzbot+ed801a886dfdbfe7136d@syzkaller.appspotmail.com Signed-off-by: Waiman Long Signed-off-by: Boqun Feng Link: https://lore.kernel.org/r/20250127013127.3913153-1-longman@redhat.com --- kernel/locking/semaphore.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/kernel/locking/semaphore.c b/kernel/locking/semaphore.c index 34bfae72f295..de9117c0e671 100644 --- a/kernel/locking/semaphore.c +++ b/kernel/locking/semaphore.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -38,7 +39,7 @@ static noinline void __down(struct semaphore *sem); static noinline int __down_interruptible(struct semaphore *sem); static noinline int __down_killable(struct semaphore *sem); static noinline int __down_timeout(struct semaphore *sem, long timeout); -static noinline void __up(struct semaphore *sem); +static noinline void __up(struct semaphore *sem, struct wake_q_head *wake_= q); =20 /** * down - acquire the semaphore @@ -183,13 +184,16 @@ EXPORT_SYMBOL(down_timeout); void __sched up(struct semaphore *sem) { unsigned long flags; + DEFINE_WAKE_Q(wake_q); =20 raw_spin_lock_irqsave(&sem->lock, flags); if (likely(list_empty(&sem->wait_list))) sem->count++; else - __up(sem); + __up(sem, &wake_q); raw_spin_unlock_irqrestore(&sem->lock, flags); + if (!wake_q_empty(&wake_q)) + wake_up_q(&wake_q); } EXPORT_SYMBOL(up); =20 @@ -269,11 +273,12 @@ static noinline int __sched __down_timeout(struct sem= aphore *sem, long timeout) return __down_common(sem, TASK_UNINTERRUPTIBLE, timeout); } =20 -static noinline void __sched __up(struct semaphore *sem) +static noinline void __sched __up(struct semaphore *sem, + struct wake_q_head *wake_q) { struct semaphore_waiter *waiter =3D list_first_entry(&sem->wait_list, struct semaphore_waiter, list); list_del(&waiter->list); waiter->up =3D true; - wake_up_process(waiter->task); + wake_q_add(wake_q, waiter->task); } --=20 2.47.1 From nobody Sun Feb 8 05:08:11 2026 Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) (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 54E4F25A2B1 for ; Fri, 7 Mar 2025 23:28:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390133; cv=none; b=ajPxjXgRPcQ2jixP/4GNZnHAYTnmq2i6Umxl/uscnUHauOODdLkI8bTWOOBM9dkAc6FIE3sIcmlNa0Pvsr4DmL3ExkKucEZ5J/joh0NEUo9UwRzMr9NV3D7DH6yX94MqRObnd7cRaJv81MGtdeWEZ8xLB2zBOzQ4jcBqq+X3yw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390133; c=relaxed/simple; bh=YWS3YTxPo0eIxetQZ5Wi1gbfGXr70VpbX+VkMOMzsbk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LCEi9Q7iqOH19RqoyaPGVpH8K6jqxNvefbOrX5WOnrE4Zx7jI2bKjageR3k5i+ct3dEzNPmN0SGCLkh7k7bjwJ18yVyHIN6sc5wcgnGCKVkz9Lm+7cFg9OsEwhEsGXS6gwL1NabDeVEDHspF9T6xDgeOuDC27fANqSwplPkma1c= 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=B0YLHXT7; arc=none smtp.client-ip=209.85.219.43 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="B0YLHXT7" Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-6e8fb8ad525so18977796d6.3 for ; Fri, 07 Mar 2025 15:28:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741390130; x=1741994930; 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=nK9C2ycbnsbicr/CbpEtAT9WiQIoIO2pIW0NwItXeA0=; b=B0YLHXT7Qvoq/ctVpznKH9F8FLp/VtJ7hyXkUJ2X4E8O+MJzZGgAECbigoARjyZHhT 7x1SFcyslL4jc7dW0KOx5S1hhozihNEIB/ws8lV7+OsXCkfUcsFWDlvqJYO97Int8f6A Wm6kFvWHLk7ZLLPfOFfihYXT/Vv5jDOoEo/WICFzTDRxrvBXYaAFclMo0FoUM1XER7aq 8tZaadF9JeyFk1XFH+/UDkHqsaB5EvWD1TKs6fJZkSgSZ0QJBQPSYY1HZTsSwh2rCxRI 4nhyoPz8CbRvpNTSNheDzqEL6jpypVk7iaO6ynlCpiSMBjlgJts8dzSWBLE6miZP9LaA vVoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741390130; x=1741994930; 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=nK9C2ycbnsbicr/CbpEtAT9WiQIoIO2pIW0NwItXeA0=; b=PwaWa8ddd6SJsD1hsUQG+4ItZD1K6JY2I+q6DmCSeAQBrZRF/zaGqbhqUgPqfaPuYR zjzMkdOgDfVG0Ox6j1VJhfSFBqJaTk4basUJ6TMGF7ulROQkOITNRvSlTCSLjQq6lz0B IhRgcRsN58n6BXUWoDHRI6cOPTvvRTyzTE+iga1raFp90cqaVn7PSoUnqws/uEILe758 bFmpn8swDyBsviHf1HdOyrroDz/a+109YPedkVdfnFaV7k2C4MgAAenPAWrtHWD2RTrN yzn403DzbH8S5VLmBNUKmNS/2pSw8w0ax5f8c6DkOk9xxPJoYzBZk8z2Xucl0t/g++uv 2UhA== X-Forwarded-Encrypted: i=1; AJvYcCXgxMJL8KwTfeJvNwqEtPlDgtriXMb8gTel9K9XCGKJ6CPdVgCUNocV50TDFsYEIgXd5Oh56XTU+WO5XUE=@vger.kernel.org X-Gm-Message-State: AOJu0YzjXDzeG3ZQTikSZm/HfTLT3oVqkUieb64kSNLO3/MGICxLiTLf c6QtC4zQfbd3pgNBaPIRzwQkurbXXGyiN2zxesePbAbRpzBmQ7JL X-Gm-Gg: ASbGnctfktfBUzdfzwHe0rdQKTbq19p5Ker4k4pV3E6PEByxBSums1Q5sJnSm3bEYpH eJJU3++20UfKd3nPxDKiVcSoArdfmAu9zKG174MM7tTw6IEYRTL1zSfLs1fWBGc2xcJQSnyRLDl cel2S82RwQ0fq9XB4TIHN44cRaZ64I3SPgqeVt92iAZskToSoDVGqqbvoPatpY/eAd4N0DpNhb3 4pguipJjlWR+KART4gNIjpoWXYlTv3M7qaobjfkV/90qjoGIfZkA1lDab2VLeIQ+VDuXh0zPWiH daUdp0e8Z7BVIxjeUlWpIPZ8CZnIB79GyhgcOn9s/H92M9xUKKumJuL0vnR1sZB078nZe55ubf5 h+WcDYajc6qrvFzITV7PXgZEYSAsOhof1Kiw= X-Google-Smtp-Source: AGHT+IH1508u/0Io/iePaf6ivNgvvb8S3mxMKS0aUYuDLOagTX1WvAsArhuVHGGT88SIj2qTxIZPjA== X-Received: by 2002:ad4:5ce8:0:b0:6e6:68d6:3932 with SMTP id 6a1803df08f44-6e900693f6amr58047116d6.40.1741390130146; Fri, 07 Mar 2025 15:28:50 -0800 (PST) Received: from fauth-a1-smtp.messagingengine.com (fauth-a1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6e8f7171e6esm24680806d6.104.2025.03.07.15.28.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Mar 2025 15:28:49 -0800 (PST) Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfauth.phl.internal (Postfix) with ESMTP id 64A37120006A; Fri, 7 Mar 2025 18:28:49 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Fri, 07 Mar 2025 18:28:49 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduudduleekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredt tdenucfhrhhomhepuehoqhhunhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrih hlrdgtohhmqeenucggtffrrghtthgvrhhnpefghfffvefhhfdvgfejgfekvdelgfekgeev ueehlefhiedvgeffjefgteeugfehieenucffohhmrghinhepkhgvrhhnvghlrdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhu nhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqdduje ejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdr nhgrmhgvpdhnsggprhgtphhtthhopeejpdhmohguvgepshhmthhpohhuthdprhgtphhtth hopehmihhnghhosehkvghrnhgvlhdrohhrghdprhgtphhtthhopehpvghtvghriiesihhn fhhrrgguvggrugdrohhrghdprhgtphhtthhopeifihhllheskhgvrhhnvghlrdhorhhgpd hrtghpthhtoheplhhonhhgmhgrnhesrhgvughhrghtrdgtohhmpdhrtghpthhtoheplhhi nhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepsg hoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmpdhrtghpthhtohepmhhinhhgohesrhgv ughhrghtrdgtohhm X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Mar 2025 18:28:48 -0500 (EST) From: Boqun Feng To: Ingo Molnar , Peter Zijlstra Cc: Will Deacon , Waiman Long , linux-kernel@vger.kernel.org, Boqun Feng , Ingo Molnar Subject: [PATCH locking 03/11] locking/lock_events: Add locking events for rtmutex slow paths Date: Fri, 7 Mar 2025 15:26:53 -0800 Message-ID: <20250307232717.1759087-4-boqun.feng@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250307232717.1759087-1-boqun.feng@gmail.com> References: <20250307232717.1759087-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: Waiman Long Add locking events for rtlock_slowlock() and rt_mutex_slowlock() for profiling the slow path behavior of rt_spin_lock() and rt_mutex_lock(). Signed-off-by: Waiman Long Signed-off-by: Boqun Feng Link: https://lore.kernel.org/r/20250213200228.1993588-2-longman@redhat.com --- kernel/locking/lock_events_list.h | 21 +++++++++++++++++++++ kernel/locking/rtmutex.c | 29 ++++++++++++++++++++++++----- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/kernel/locking/lock_events_list.h b/kernel/locking/lock_events= _list.h index 97fb6f3f840a..80b11f194c9f 100644 --- a/kernel/locking/lock_events_list.h +++ b/kernel/locking/lock_events_list.h @@ -67,3 +67,24 @@ LOCK_EVENT(rwsem_rlock_handoff) /* # of read lock handof= fs */ LOCK_EVENT(rwsem_wlock) /* # of write locks acquired */ LOCK_EVENT(rwsem_wlock_fail) /* # of failed write lock acquisitions */ LOCK_EVENT(rwsem_wlock_handoff) /* # of write lock handoffs */ + +/* + * Locking events for rtlock_slowlock() + */ +LOCK_EVENT(rtlock_slowlock) /* # of rtlock_slowlock() calls */ +LOCK_EVENT(rtlock_slow_acq1) /* # of locks acquired after wait_lock */ +LOCK_EVENT(rtlock_slow_acq2) /* # of locks acquired in for loop */ +LOCK_EVENT(rtlock_slow_sleep) /* # of sleeps */ +LOCK_EVENT(rtlock_slow_wake) /* # of wakeup's */ + +/* + * Locking events for rt_mutex_slowlock() + */ +LOCK_EVENT(rtmutex_slowlock) /* # of rt_mutex_slowlock() calls */ +LOCK_EVENT(rtmutex_slow_block) /* # of rt_mutex_slowlock_block() calls */ +LOCK_EVENT(rtmutex_slow_acq1) /* # of locks acquired after wait_lock */ +LOCK_EVENT(rtmutex_slow_acq2) /* # of locks acquired at the end */ +LOCK_EVENT(rtmutex_slow_acq3) /* # of locks acquired in *block() */ +LOCK_EVENT(rtmutex_slow_sleep) /* # of sleeps */ +LOCK_EVENT(rtmutex_slow_wake) /* # of wakeup's */ +LOCK_EVENT(rtmutex_deadlock) /* # of rt_mutex_handle_deadlock()'s */ diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c index 4a8df1800cbb..c80902eacd79 100644 --- a/kernel/locking/rtmutex.c +++ b/kernel/locking/rtmutex.c @@ -27,6 +27,7 @@ #include =20 #include "rtmutex_common.h" +#include "lock_events.h" =20 #ifndef WW_RT # define build_ww_mutex() (false) @@ -1612,10 +1613,13 @@ static int __sched rt_mutex_slowlock_block(struct r= t_mutex_base *lock, struct task_struct *owner; int ret =3D 0; =20 + lockevent_inc(rtmutex_slow_block); for (;;) { /* Try to acquire the lock: */ - if (try_to_take_rt_mutex(lock, current, waiter)) + if (try_to_take_rt_mutex(lock, current, waiter)) { + lockevent_inc(rtmutex_slow_acq3); break; + } =20 if (timeout && !timeout->task) { ret =3D -ETIMEDOUT; @@ -1638,8 +1642,10 @@ static int __sched rt_mutex_slowlock_block(struct rt= _mutex_base *lock, owner =3D NULL; raw_spin_unlock_irq_wake(&lock->wait_lock, wake_q); =20 - if (!owner || !rtmutex_spin_on_owner(lock, waiter, owner)) + if (!owner || !rtmutex_spin_on_owner(lock, waiter, owner)) { + lockevent_inc(rtmutex_slow_sleep); rt_mutex_schedule(); + } =20 raw_spin_lock_irq(&lock->wait_lock); set_current_state(state); @@ -1694,6 +1700,7 @@ static int __sched __rt_mutex_slowlock(struct rt_mute= x_base *lock, int ret; =20 lockdep_assert_held(&lock->wait_lock); + lockevent_inc(rtmutex_slowlock); =20 /* Try to acquire the lock again: */ if (try_to_take_rt_mutex(lock, current, NULL)) { @@ -1701,6 +1708,7 @@ static int __sched __rt_mutex_slowlock(struct rt_mute= x_base *lock, __ww_mutex_check_waiters(rtm, ww_ctx, wake_q); ww_mutex_lock_acquired(ww, ww_ctx); } + lockevent_inc(rtmutex_slow_acq1); return 0; } =20 @@ -1719,10 +1727,12 @@ static int __sched __rt_mutex_slowlock(struct rt_mu= tex_base *lock, __ww_mutex_check_waiters(rtm, ww_ctx, wake_q); ww_mutex_lock_acquired(ww, ww_ctx); } + lockevent_inc(rtmutex_slow_acq2); } else { __set_current_state(TASK_RUNNING); remove_waiter(lock, waiter); rt_mutex_handle_deadlock(ret, chwalk, lock, waiter); + lockevent_inc(rtmutex_deadlock); } =20 /* @@ -1751,6 +1761,7 @@ static inline int __rt_mutex_slowlock_locked(struct r= t_mutex_base *lock, &waiter, wake_q); =20 debug_rt_mutex_free_waiter(&waiter); + lockevent_cond_inc(rtmutex_slow_wake, !wake_q_empty(wake_q)); return ret; } =20 @@ -1823,9 +1834,12 @@ static void __sched rtlock_slowlock_locked(struct rt= _mutex_base *lock, struct task_struct *owner; =20 lockdep_assert_held(&lock->wait_lock); + lockevent_inc(rtlock_slowlock); =20 - if (try_to_take_rt_mutex(lock, current, NULL)) + if (try_to_take_rt_mutex(lock, current, NULL)) { + lockevent_inc(rtlock_slow_acq1); return; + } =20 rt_mutex_init_rtlock_waiter(&waiter); =20 @@ -1838,8 +1852,10 @@ static void __sched rtlock_slowlock_locked(struct rt= _mutex_base *lock, =20 for (;;) { /* Try to acquire the lock again */ - if (try_to_take_rt_mutex(lock, current, &waiter)) + if (try_to_take_rt_mutex(lock, current, &waiter)) { + lockevent_inc(rtlock_slow_acq2); break; + } =20 if (&waiter =3D=3D rt_mutex_top_waiter(lock)) owner =3D rt_mutex_owner(lock); @@ -1847,8 +1863,10 @@ static void __sched rtlock_slowlock_locked(struct rt= _mutex_base *lock, owner =3D NULL; raw_spin_unlock_irq_wake(&lock->wait_lock, wake_q); =20 - if (!owner || !rtmutex_spin_on_owner(lock, &waiter, owner)) + if (!owner || !rtmutex_spin_on_owner(lock, &waiter, owner)) { + lockevent_inc(rtlock_slow_sleep); schedule_rtlock(); + } =20 raw_spin_lock_irq(&lock->wait_lock); set_current_state(TASK_RTLOCK_WAIT); @@ -1865,6 +1883,7 @@ static void __sched rtlock_slowlock_locked(struct rt_= mutex_base *lock, debug_rt_mutex_free_waiter(&waiter); =20 trace_contention_end(lock, 0); + lockevent_cond_inc(rtlock_slow_wake, !wake_q_empty(wake_q)); } =20 static __always_inline void __sched rtlock_slowlock(struct rt_mutex_base *= lock) --=20 2.47.1 From nobody Sun Feb 8 05:08:11 2026 Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) (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 E940325A2CB for ; Fri, 7 Mar 2025 23:29:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390144; cv=none; b=CSRi/NNhYeTH9HruRyTXPULmHqZZnCsRHWszAkrLENN20s69ooWtaCrNMC7MiUdNobNQFio4425LU2qZPcNk/0Pu7pC6LdyXrxUaIfTzi93Fn109zL4qlEkrppMoJREgrNREIUfsrfNmFi7iM9qvDjcoGC0sm3XvojQjNCqJKp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390144; c=relaxed/simple; bh=jn0DuQ9IMi7jCb85Jk+1q9FpJFYxx2es1I9LoBLuqIQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mqWRVxVdVHifiZJDHQurgbTKWFadzs4rL8Go558Sjjsdst1hspSUIYHymfHrNuGrs6LpOcNnG1gbGkHkA0Hd87QphIZfOqvHUfau9UgTGiqGF75482fqb9Bl6D4alEONEAdqCkdZCXXdGmLv8Z7PnAhuInb8FU+Jburi7iqz6Wg= 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=XhCDMisG; arc=none smtp.client-ip=209.85.219.47 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="XhCDMisG" Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-6dd15d03eacso23100436d6.0 for ; Fri, 07 Mar 2025 15:29:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741390142; x=1741994942; 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=6oa0g1rkDvXXMBgFSGlnnbz7MDZtKGDALU7XEJAN79k=; b=XhCDMisGr7W1y9nkZRELMM3G4sm5XnxS0q4cUu2cMQOtBBlSB3h4OlJjSszAEHlh0L oZ/0XBIho4wZtawMTBng4Mt7UK8lL+M6IzvcFcTOnGtxEq/EttQkSWSHYj7SAlWLAvyq 0JwyZossPNdLWrNypyoU+EvPT252c/Fhtuaq+NOZRgbXYhbwn4s7U3l6Z/EsXcXDze4K 3/eJC94o0k8pAGGlavP9b7SXYS6YslTSfVwUrCEI7B8AvnzjH8Ria49UllQscjAV6o10 d/WItC8XSa3a3EvQs5xzUVNGWUC/2Aio3B7vhOtErku0TGXKL9V/aoDtf6bTpQS8WBhB 0okg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741390142; x=1741994942; 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=6oa0g1rkDvXXMBgFSGlnnbz7MDZtKGDALU7XEJAN79k=; b=WcRV1l1QN0No060S6d4Rir32VaKhtNtSAFS3b5qhuqd2bioBTMJ/Y6r+YkTQ2X8ESz JyDVUtLnYiMFQ0tugh/NOPq2K/M/64/TpsYxNcWI9bBdUi6VQyS97KFbk8YQhKhXRyF/ zTOW9HlqAwrhNJX5KWXbFXt/FK0ta03C76rIBC7JsC4hTr2/6nR1ckgec9ywV+oqfBVc DUGTmp+FmDmsFavIQHVK5XQg6fySUtJmTHX+uSb4VivUUiD9eYovvUyhUlxOO/QVabqZ nEugxI/ZJrn8B5RWFfXotXIcONZrJpW/Ujq/c8Jo8StgC2QUgq3MKob6dVPtBYJfGOXD Arsg== X-Forwarded-Encrypted: i=1; AJvYcCVuMKpXhY6iGR29qMEtxWaBEApQ/mNnTs0BnMNE2X5uqiW5dy8TzfIuJHmF3OCSIzmhmhbaIlcMDzOkzHU=@vger.kernel.org X-Gm-Message-State: AOJu0YwN+NAfRqkUSx00y5qgQLV+//4kLt2X0vITZ6IB/eKDEAriSXXy cG/mJZ62wDJG1ZiDF4vYGVf5Zy9EwQ6dNGAGML3rM/zfa7yfj1Q8 X-Gm-Gg: ASbGnctCK0v3ctzZuFd6FBpEQp+7W+NMM6uKYJBvTRIAJoqvx+hiZXQSViGQV/jwDDC XfhonWEW17VQFdKao8pkeNuJPBtlr1GD83QCPI/IKuKgxa0ZTg7akxgMSO03uwR2S4grhJFi8Lm OtGh8BVdrlL/EakBxIvCRewanA8nX0gGvkWqJE7h+VcqPQV8umI3zYKQSboFAWEGv8Vu+jCt/82 nS+Mpi2XtJCY9O+McRiOejNAHlArNUYsJDbzvpkka1XQ9odb/ON6BJHI11d042Pwhy0zKB5MZGE +9DRE5ZWIuLHQz2wQOUCkr6+oLg49woXEMavFdAzi32dxcqMV5bHYtXznBYHBHnbaA6Pu16Gow+ F+Lni7+STA/T+gQp9tCZaHs2PvfIl2Bh+nww= X-Google-Smtp-Source: AGHT+IEyQbV4bi3Auefqc0BIAvh/1iCfeShsZjtTfSTfrzZDVli91ksnjs3y9w+XYA4sf9RIiEZ6QQ== X-Received: by 2002:a05:6214:ac7:b0:6e4:540b:5352 with SMTP id 6a1803df08f44-6e907d3b5e5mr24505566d6.16.1741390141707; Fri, 07 Mar 2025 15:29:01 -0800 (PST) Received: from fauth-a1-smtp.messagingengine.com (fauth-a1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6e8f707bec2sm24919316d6.6.2025.03.07.15.29.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Mar 2025 15:29:01 -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 12056120006A; Fri, 7 Mar 2025 18:29:01 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Fri, 07 Mar 2025 18:29:01 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduudduleelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredt tdenucfhrhhomhepuehoqhhunhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrih hlrdgtohhmqeenucggtffrrghtthgvrhhnpefghfffvefhhfdvgfejgfekvdelgfekgeev ueehlefhiedvgeffjefgteeugfehieenucffohhmrghinhepkhgvrhhnvghlrdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhu nhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqdduje ejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdr nhgrmhgvpdhnsggprhgtphhtthhopeejpdhmohguvgepshhmthhpohhuthdprhgtphhtth hopehmihhnghhosehkvghrnhgvlhdrohhrghdprhgtphhtthhopehpvghtvghriiesihhn fhhrrgguvggrugdrohhrghdprhgtphhtthhopeifihhllheskhgvrhhnvghlrdhorhhgpd hrtghpthhtoheplhhonhhgmhgrnhesrhgvughhrghtrdgtohhmpdhrtghpthhtoheplhhi nhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepsg hoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmpdhrtghpthhtohepmhhinhhgohesrhgv ughhrghtrdgtohhm X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Mar 2025 18:29:00 -0500 (EST) From: Boqun Feng To: Ingo Molnar , Peter Zijlstra Cc: Will Deacon , Waiman Long , linux-kernel@vger.kernel.org, Boqun Feng , Ingo Molnar Subject: [PATCH locking 04/11] locking/lock_events: Add locking events for lockdep Date: Fri, 7 Mar 2025 15:26:54 -0800 Message-ID: <20250307232717.1759087-5-boqun.feng@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250307232717.1759087-1-boqun.feng@gmail.com> References: <20250307232717.1759087-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: Waiman Long Add some lock events to the lockdep for profiling its behavior. Signed-off-by: Waiman Long Signed-off-by: Boqun Feng Link: https://lore.kernel.org/r/20250213200228.1993588-3-longman@redhat.com --- kernel/locking/lock_events_list.h | 7 +++++++ kernel/locking/lockdep.c | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/kernel/locking/lock_events_list.h b/kernel/locking/lock_events= _list.h index 80b11f194c9f..9ef9850aeebe 100644 --- a/kernel/locking/lock_events_list.h +++ b/kernel/locking/lock_events_list.h @@ -88,3 +88,10 @@ LOCK_EVENT(rtmutex_slow_acq3) /* # of locks acquired in = *block() */ LOCK_EVENT(rtmutex_slow_sleep) /* # of sleeps */ LOCK_EVENT(rtmutex_slow_wake) /* # of wakeup's */ LOCK_EVENT(rtmutex_deadlock) /* # of rt_mutex_handle_deadlock()'s */ + +/* + * Locking events for lockdep + */ +LOCK_EVENT(lockdep_acquire) +LOCK_EVENT(lockdep_lock) +LOCK_EVENT(lockdep_nocheck) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 4470680f0226..8436f017c74d 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -61,6 +61,7 @@ #include =20 #include "lockdep_internals.h" +#include "lock_events.h" =20 #include =20 @@ -170,6 +171,7 @@ static struct task_struct *lockdep_selftest_task_struct; static int graph_lock(void) { lockdep_lock(); + lockevent_inc(lockdep_lock); /* * Make sure that if another CPU detected a bug while * walking the graph we dont change it (while the other @@ -5091,8 +5093,12 @@ static int __lock_acquire(struct lockdep_map *lock, = unsigned int subclass, if (unlikely(lock->key =3D=3D &__lockdep_no_track__)) return 0; =20 - if (!prove_locking || lock->key =3D=3D &__lockdep_no_validate__) + lockevent_inc(lockdep_acquire); + + if (!prove_locking || lock->key =3D=3D &__lockdep_no_validate__) { check =3D 0; + lockevent_inc(lockdep_nocheck); + } =20 if (subclass < NR_LOCKDEP_CACHING_CLASSES) class =3D lock->class_cache[subclass]; --=20 2.47.1 From nobody Sun Feb 8 05:08:11 2026 Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) (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 DB97425A2CA for ; Fri, 7 Mar 2025 23:29:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390146; cv=none; b=hDjnRjLEJ+0mHKz4F4g8kfoxcBM6mB+I1xXwdKKfFdZBdxZeDMZAfq7/Nyd6FPFwlPitaSXTcuFuBzIVz8DL4V5a9COYMjvWdhTk7OwnhcGEbcn3ztvn348cQsHjtahwqvSUoG5FEHZKmctajNvh2u8P3I3DiADemJKEGrLtTr0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390146; c=relaxed/simple; bh=lz9kuFeOneoNnBLyFoR/bYunAUSseRNqLWZa9SZl0Rk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E7yrvDvpGZ07hJFnhrNK3777KbgwFK8KHl8jtkOMe/8+UUlHdfWI5tLFBJ0Tmrcm7mBCen44Lbs0Im7FpB/TDJEWqlXC4NVL0ahVlCAX5O39/kZB4x6TLXFJOTw2y3GcZKQQHlGfBfD3jeZaHibf9AkX1W8LzuO+BCngvFzDKmo= 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=X88GEPtS; arc=none smtp.client-ip=209.85.219.48 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="X88GEPtS" Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-6e8f6970326so17843286d6.0 for ; Fri, 07 Mar 2025 15:29:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741390144; x=1741994944; 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=fEKUUBWKonq+SljYML2UXgAOZGt6uRAsGBJ5aZUIg9Y=; b=X88GEPtSQTRNHa6Xi7jWyimI/lrBu45xAftEhus06SrO5UJo9E4vE0oyzXX4rvtOyA OIc2DbuAx6WH4q5QJPqYrT4lUIrzcaEmBXOTaP6/SRefBrpQn2GoINRfYQ7tIlgHxmug 8tAj7j+IH6sPnunWkHDJI5TiVwl2u/Z6UCBfFFai35s7hWCwmaV6FTQqBq4atsyzZVjx XSp8ii0Wf4+PGBw/30zHmw/uzx1KSRrxQ37aGCa/LJ+JAZPVX4ILkhgQ+nlXAjWHPJKF mDXtZVSTLMGa8LTFobhgYj3V+bk78Y5Rqqtk7Fk1EWTi6o8+e9dH3KLQWgJwbc4gBmXO Yf8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741390144; x=1741994944; 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=fEKUUBWKonq+SljYML2UXgAOZGt6uRAsGBJ5aZUIg9Y=; b=H+bm5kOg9gNJTIEvE2VKKrrFB1xPkJ6LSlte5qv4jMhTAVTpiyp+yZCrQBycjCjotD OsBgMH0gqjsu3xvYQDcrPspP6r2GgJGtfCuhE4C6Zcq251p8Y5A3wT1CvjA15U7oMyTX sg21N72fMoQ/K9QDirGU8aa7pese5dY3nLmHlPNzxk0XzS6ETyMhAfCSw2MqtBTD3VR/ xZpFgHiR8yMrnHfND3KNvEDPIqBoyqxS62PfudNox+klqYr4q9gb2UgSEjX5w3VYGl2z e9naceCsWCv9w9GPTz6NKFkJEj2YCONENtT5+uJssepjtK1L47BcScCwqV52T6GGSoV5 yCCA== X-Forwarded-Encrypted: i=1; AJvYcCXQ+45cmEM9YksDIfmoEG+j8UPgQu3P7AoeOqhB9jQsRVAGCkfuYjNcMFzXTv+PO8N1Hmh623a3XxhUjOs=@vger.kernel.org X-Gm-Message-State: AOJu0YwSYJu/7bur7UtzN5kitbOy/LPSx2elVLMKU1tZFkNBMEzU7Fma ug0w5MezbfHpVtHWN/65sMSqjQQTMyGmJ5QWp38x5x/xWz8U7Phv X-Gm-Gg: ASbGncuOHONXwd9ZZ0ZtAIpMbbUMvDPcNDbd03zbSQdfdGFI3UVIQY3yqcdzE0wY6ZR ty/ox7MIKp35f8HzE6vPulzwYPmHls7wECsCMq+5ndHq7fpMgxoX/EdunV6+Z4lz71cALi4syv4 wTeVp/zrpmyhqIE2QnXvVGBvkPsxExJyyzpWmkQ+JfzQ9ul+FZX502g5qJq7Us3C4d7lJb7Mlhn 9dkTvYzS4puseQcMP69ZO+jn2UZhF+x5/hxljx7gvY6NpQV6YcPOYDhWHnWFVUaA444qy6gy7zf 6P5v7RwLxxCInv1qsOsF5No4R5frmSEbSVNGAfA9yKimwebGzqH0qzkrqSeZtGFoyzQTsazlcr5 Sg1GKDhwM8qMijHlYaTJMakgBODaTGNEKrT4= X-Google-Smtp-Source: AGHT+IFM216j7EhXIuk+4I+vq2cMw4p8ydmdv3/X+4fxjfl8b1BfnnaMq894v1Yu/hI5FSmydzNBJA== X-Received: by 2002:ad4:5cae:0:b0:6e8:f433:20a8 with SMTP id 6a1803df08f44-6e9005bc7e4mr66798286d6.9.1741390143644; Fri, 07 Mar 2025 15:29:03 -0800 (PST) Received: from fauth-a1-smtp.messagingengine.com (fauth-a1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6e8f715b60fsm24564746d6.92.2025.03.07.15.29.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Mar 2025 15:29:03 -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 B8DBF120006A; Fri, 7 Mar 2025 18:29:02 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Fri, 07 Mar 2025 18:29:02 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduudduleelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredt tdenucfhrhhomhepuehoqhhunhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrih hlrdgtohhmqeenucggtffrrghtthgvrhhnpefghfffvefhhfdvgfejgfekvdelgfekgeev ueehlefhiedvgeffjefgteeugfehieenucffohhmrghinhepkhgvrhhnvghlrdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhu nhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqdduje ejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdr nhgrmhgvpdhnsggprhgtphhtthhopedufedpmhhouggvpehsmhhtphhouhhtpdhrtghpth htohepmhhinhhgoheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepphgvthgvrhiisehi nhhfrhgruggvrggurdhorhhgpdhrtghpthhtohepfihilhhlsehkvghrnhgvlhdrohhrgh dprhgtphhtthhopehlohhnghhmrghnsehrvgguhhgrthdrtghomhdprhgtphhtthhopehl ihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhope gvlhhvvghrsehgohhoghhlvgdrtghomhdprhgtphhtthhopegrnhgurhgvhihknhhvlhes ghhmrghilhdrtghomhdprhgtphhtthhopegsohhquhhnrdhfvghnghesghhmrghilhdrtg homhdprhgtphhtthhopehmihhnghhosehrvgguhhgrthdrtghomh X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Mar 2025 18:29:02 -0500 (EST) From: Boqun Feng To: Ingo Molnar , Peter Zijlstra Cc: Will Deacon , Waiman Long , linux-kernel@vger.kernel.org, Marco Elver , Andrey Konovalov , Boqun Feng , Ingo Molnar , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , linux-rt-devel@lists.linux.dev (open list:Real-time Linux (PREEMPT_RT):Keyword:PREEMPT_RT) Subject: [PATCH locking 05/11] locking/lockdep: Disable KASAN instrumentation of lockdep.c Date: Fri, 7 Mar 2025 15:26:55 -0800 Message-ID: <20250307232717.1759087-6-boqun.feng@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250307232717.1759087-1-boqun.feng@gmail.com> References: <20250307232717.1759087-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: Waiman Long Both KASAN and LOCKDEP are commonly enabled in building a debug kernel. Each of them can significantly slow down the speed of a debug kernel. Enabling KASAN instrumentation of the LOCKDEP code will further slow thing down. Since LOCKDEP is a high overhead debugging tool, it will never get enabled in a production kernel. The LOCKDEP code is also pretty mature and is unlikely to get major changes. There is also a possibility of recursion similar to KCSAN. To evaluate the performance impact of disabling KASAN instrumentation of lockdep.c, the time to do a parallel build of the Linux defconfig kernel was used as the benchmark. Two x86-64 systems (Skylake & Zen 2) and an arm64 system were used as test beds. Two sets of non-RT and RT kernels with similar configurations except mainly CONFIG_PREEMPT_RT were used for evaulation. For the Skylake system: Kernel Run time Sys time ------ -------- -------- Non-debug kernel (baseline) 0m47.642s 4m19.811s [CONFIG_KASAN_INLINE=3Dy] Debug kernel 2m11.108s (x2.8) 38m20.467s (x8.9) Debug kernel (patched) 1m49.602s (x2.3) 31m28.501s (x7.3) Debug kernel (patched + mitigations=3Doff) 1m30.988s (x1.9) 26m41.993s (x6.2) RT kernel (baseline) 0m54.871s 7m15.340s [CONFIG_KASAN_INLINE=3Dn] RT debug kernel 6m07.151s (x6.7) 135m47.428s (x18.7) RT debug kernel (patched) 3m42.434s (x4.1) 74m51.636s (x10.3) RT debug kernel (patched + mitigations=3Doff) 2m40.383s (x2.9) 57m54.369s (x8.0) [CONFIG_KASAN_INLINE=3Dy] RT debug kernel 3m22.155s (x3.7) 77m53.018s (x10.7) RT debug kernel (patched) 2m36.700s (x2.9) 54m31.195s (x7.5) RT debug kernel (patched + mitigations=3Doff) 2m06.110s (x2.3) 45m49.493s (x6.3) For the Zen 2 system: Kernel Run time Sys time ------ -------- -------- Non-debug kernel (baseline) 1m42.806s 39m48.714s [CONFIG_KASAN_INLINE=3Dy] Debug kernel 4m04.524s (x2.4) 125m35.904s (x3.2) Debug kernel (patched) 3m56.241s (x2.3) 127m22.378s (x3.2) Debug kernel (patched + mitigations=3Doff) 2m38.157s (x1.5) 92m35.680s (x2.3) RT kernel (baseline) 1m51.500s 14m56.322s [CONFIG_KASAN_INLINE=3Dn] RT debug kernel 16m04.962s (x8.7) 244m36.463s (x16.4) RT debug kernel (patched) 9m09.073s (x4.9) 129m28.439s (x8.7) RT debug kernel (patched + mitigations=3Doff) 3m31.662s (x1.9) 51m01.391s (x3.4) For the arm64 system: Kernel Run time Sys time ------ -------- -------- Non-debug kernel (baseline) 1m56.844s 8m47.150s Debug kernel 3m54.774s (x2.0) 92m30.098s (x10.5) Debug kernel (patched) 3m32.429s (x1.8) 77m40.779s (x8.8) RT kernel (baseline) 4m01.641s 18m16.777s [CONFIG_KASAN_INLINE=3Dn] RT debug kernel 19m32.977s (x4.9) 304m23.965s (x16.7) RT debug kernel (patched) 16m28.354s (x4.1) 234m18.149s (x12.8) Turning the mitigations off doesn't seems to have any noticeable impact on the performance of the arm64 system. So the mitigation=3Doff entries aren't included. For the x86 CPUs, cpu mitigations has a much bigger impact on performance, especially the RT debug kernel with CONFIG_KASAN_INLINE=3Dn. The SRSO mitigation in Zen 2 has an especially big impact on the debug kernel. It is also the majority of the slowdown with mitigations on. It is because the patched ret instruction slows down function returns. A lot of helper functions that are normally compiled out or inlined may become real function calls in the debug kernel. With CONFIG_KASAN_INLINE=3Dn, the KASAN instrumentation inserts a lot of __asan_loadX*() and __kasan_check_read() function calls to memory access portion of the code. The lockdep's __lock_acquire() function, for instance, has 66 __asan_loadX*() and 6 __kasan_check_read() calls added with KASAN instrumentation. Of course, the actual numbers may vary depending on the compiler used and the exact version of the lockdep code. With the Skylake test system, the parallel kernel build times reduction of the RT debug kernel with this patch are: CONFIG_KASAN_INLINE=3Dn: -37% CONFIG_KASAN_INLINE=3Dy: -22% The time reduction is less with CONFIG_KASAN_INLINE=3Dy, but it is still significant. Setting CONFIG_KASAN_INLINE=3Dy can result in a significant performance improvement. The major drawback is a significant increase in the size of kernel text. In the case of vmlinux, its text size increases from 45997948 to 67606807. That is a 47% size increase (about 21 Mbytes). The size increase of other kernel modules should be similar. With the newly added rtmutex and lockdep lock events, the relevant event counts for the test runs with the Skylake system were: Event type Debug kernel RT debug kernel ---------- ------------ --------------- lockdep_acquire 1,968,663,277 5,425,313,953 rtlock_slowlock - 401,701,156 rtmutex_slowlock - 139,672 The __lock_acquire() calls in the RT debug kernel are x2.8 times of the non-RT debug kernel with the same workload. Since the __lock_acquire() function is a big hitter in term of performance slowdown, this makes the RT debug kernel much slower than the non-RT one. The average lock nesting depth is likely to be higher in the RT debug kernel too leading to longer execution time in the __lock_acquire() function. As the small advantage of enabling KASAN instrumentation to catch potential memory access error in the lockdep debugging tool is probably not worth the drawback of further slowing down a debug kernel, disable KASAN instrumentation in the lockdep code to allow the debug kernels to regain some performance back, especially for the RT debug kernels. Signed-off-by: Waiman Long Reviewed-by: Marco Elver Reviewed-by: Andrey Konovalov Signed-off-by: Boqun Feng Link: https://lore.kernel.org/r/20250213200228.1993588-4-longman@redhat.com --- kernel/locking/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/locking/Makefile b/kernel/locking/Makefile index 0db4093d17b8..a114949eeed5 100644 --- a/kernel/locking/Makefile +++ b/kernel/locking/Makefile @@ -5,7 +5,8 @@ KCOV_INSTRUMENT :=3D n =20 obj-y +=3D mutex.o semaphore.o rwsem.o percpu-rwsem.o =20 -# Avoid recursion lockdep -> sanitizer -> ... -> lockdep. +# Avoid recursion lockdep -> sanitizer -> ... -> lockdep & improve perform= ance. +KASAN_SANITIZE_lockdep.o :=3D n KCSAN_SANITIZE_lockdep.o :=3D n =20 ifdef CONFIG_FUNCTION_TRACER --=20 2.47.1 From nobody Sun Feb 8 05:08:11 2026 Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) (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 25BA925A2DD for ; Fri, 7 Mar 2025 23:29:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390147; cv=none; b=qx/XR1d9Hbi+h4N9H5PvCqqAwnJNAiuawqFap6WrSbbU5hLXJM37pa7rIA1YRTLQu+rc8jocLW7y9e8dDm59l2sTn91UNXWXCKsW/dm8mH/7xV3YzVeaA4QB4fJ4ULDl/nZze37fb1ujvYv/hxdYJ8q0Ddv8h4rrAduf0i0mI1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390147; c=relaxed/simple; bh=BhTKRjIMREwfVtTeTmz2dTeC8AQI+l9ny9QW/hOYcxM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UnbP5oKRJAxqZtwvYKswCm9KgS4hceoTPW+eFgHPNHfhuwDIaDc/SdwAEe6pXGmFBwpz/h+GeKL2gLIf0zrUnA2ONdYkoYHlwBd2tc3W8j+8x9PniU57Zp8xZOIi7vQGYzs9TsHQ08za/5v3iPENurwtMqZ31PU21y2zgK94GoU= 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=ZdUr/rL8; arc=none smtp.client-ip=209.85.160.172 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="ZdUr/rL8" Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-475162ce281so21946291cf.1 for ; Fri, 07 Mar 2025 15:29:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741390145; x=1741994945; 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=MK8683Y4U/Xs0Jj2/W+kaz45+I6ShhhE6QAy0NDqYbc=; b=ZdUr/rL8KzH2EP0OMXGblALsxiDXMwDRrHU2e0PVDnzidNSFh4uYCozyJvlRQcC2TW rXyoTePhcNxTUa5Wh5VPBVZnN+rT+72VsA+srzhlTtI7OSQQliPUSqm5YQXQJcavyyVo fXS/0MZzw/JPzHoKQchJx9I5w0mIZfULqiWJdZqq1QXyPdh0/JEUBWOrA4/98UacEJf1 Jlwr2AUGhCV7AfM3d81+kSQLu1kxM5tfE8RV84FfnbfdhblufFg4HlPwCpmd52OgSRPw N66vwLx7sMaIjBunc5ts9FcNGtt4LiwyuwKgRvjJZRxz3tV67g+swV1Dzmg+rXhq9d+/ y4mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741390145; x=1741994945; 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=MK8683Y4U/Xs0Jj2/W+kaz45+I6ShhhE6QAy0NDqYbc=; b=h2E2bUju5r7pm1+1CkpT31l1IxALk4VtxQZHKA9dR8jcZGJngfEJ3wjctXusKi/CoU aX55DmRTm58VKtLyYkFVcgVIS5mc7wy7iMkplG6c/PvQN+//2HC0oiFH6/6j9U3vdP/z whyhkkFJtiivWPr8dlylz5m1OzLcBNdOHwHJJ7j/LfYSV7axnlfryry3H0ii4n0iPBeb +FI2N2963rmi5eLaIlVi4HcQR4CT7LkGQfFa6q658uRGqIAIeum5iBwfDZrSt7YooN7s 7RJOJVAH/1AxDNqcsoXV0sgdDaNqQ9hs+vgCKSK6ef/gaN61CzDXWW9s2eBqrlueOAxA Xxog== X-Forwarded-Encrypted: i=1; AJvYcCUZr6ZyoAvmk0D5koA67NLUh8a45ElK/fgFLAR0rxGMii6bGLq6m8h992iG23k1V4yyNQqKJvd8e9pazp4=@vger.kernel.org X-Gm-Message-State: AOJu0Yw/I1Y1q5q5aZIY/A0Y5qi/ti8jXK5T35Hd7/Y+RJBDTXhkeA+f rZ1n4Hz5FiiGla11xvCkLoo3ktzlc80N9GuZI+g6uUIWmivARCJV X-Gm-Gg: ASbGncvDdWEJSx1O5FkXRekAMc1tM4ITIj29YAHL8rC0U0aHpLqR0UpA4FdcyaD6lA1 lkkVscSdPJDk0gJoroHcZYVZBWdyUsrCDubRqntl0HRMzSYGTwj7zwaeg/CpADUZUYF4z8Egwsc sgAvMJtVigJWBZIvzrVKFA7xALmzb3hZ8w8raf0t9ppo5StwbZdk7bXf0IJe5AXNdCEDFn/y4OQ Ln1pK/ujMnkrp9fxIF57A3vzV0u055oTNK8K+7kARhelleRlILRBhg/N3SACy02SnMpJYznZ7x0 5Sz4/dk6EBEWIKAxk21KSgRG9lQHM5Ry2e9uDyNfuzF3p0fpleWDkhllLyt92Lzg4ChpBAPb8sE gYCAU0OnVit6JIdSno8YlN8Ns5DEGMO5kyus= X-Google-Smtp-Source: AGHT+IEV33lI3dDrN5pmumJqxSqx+Wk8doSbwh33v9/lcPn3OgK8bRjrkT8IEoccoRhLK2s0fRN4aw== X-Received: by 2002:a05:622a:348:b0:475:b03:a054 with SMTP id d75a77b69052e-476109cdc92mr57004911cf.25.1741390145189; Fri, 07 Mar 2025 15:29:05 -0800 (PST) Received: from fauth-a1-smtp.messagingengine.com (fauth-a1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4765f877398sm5558191cf.4.2025.03.07.15.29.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Mar 2025 15:29:04 -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 76F18120006A; Fri, 7 Mar 2025 18:29:04 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Fri, 07 Mar 2025 18:29:04 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduudduleelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredt tdenucfhrhhomhepuehoqhhunhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrih hlrdgtohhmqeenucggtffrrghtthgvrhhnpefghfffvefhhfdvgfejgfekvdelgfekgeev ueehlefhiedvgeffjefgteeugfehieenucffohhmrghinhepkhgvrhhnvghlrdhorhhgne cuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhu nhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqdduje ejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdr nhgrmhgvpdhnsggprhgtphhtthhopeelpdhmohguvgepshhmthhpohhuthdprhgtphhtth hopehmihhnghhosehkvghrnhgvlhdrohhrghdprhgtphhtthhopehpvghtvghriiesihhn fhhrrgguvggrugdrohhrghdprhgtphhtthhopeifihhllheskhgvrhhnvghlrdhorhhgpd hrtghpthhtoheplhhonhhgmhgrnhesrhgvughhrghtrdgtohhmpdhrtghpthhtoheplhhi nhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepvg hlvhgvrhesghhoohhglhgvrdgtohhmpdhrtghpthhtoheprghnughrvgihkhhnvhhlsehg mhgrihhlrdgtohhmpdhrtghpthhtohepsghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtoh hmpdhrtghpthhtohepmhhinhhgohesrhgvughhrghtrdgtohhm X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Mar 2025 18:29:03 -0500 (EST) From: Boqun Feng To: Ingo Molnar , Peter Zijlstra Cc: Will Deacon , Waiman Long , linux-kernel@vger.kernel.org, Marco Elver , Andrey Konovalov , Boqun Feng , Ingo Molnar Subject: [PATCH locking 06/11] locking/lockdep: Add kasan_check_byte() check in lock_acquire() Date: Fri, 7 Mar 2025 15:26:56 -0800 Message-ID: <20250307232717.1759087-7-boqun.feng@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250307232717.1759087-1-boqun.feng@gmail.com> References: <20250307232717.1759087-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: Waiman Long KASAN instrumentation of lockdep has been disabled as we don't need KASAN to check the validity of lockdep internal data structures and incur unnecessary performance overhead. However, the lockdep_map pointer passed in externally may not be valid (e.g. use-after-free) and we run the risk of using garbage data resulting in false lockdep reports. Add kasan_check_byte() call in lock_acquire() for non kernel core data object to catch invalid lockdep_map and print out a KASAN report before any lockdep splat, if any. Suggested-by: Marco Elver Signed-off-by: Waiman Long Reviewed-by: Marco Elver Reviewed-by: Andrey Konovalov Signed-off-by: Boqun Feng Link: https://lore.kernel.org/r/20250214195242.2480920-1-longman@redhat.com --- kernel/locking/lockdep.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 8436f017c74d..b15757e63626 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -57,6 +57,7 @@ #include #include #include +#include =20 #include =20 @@ -5830,6 +5831,14 @@ void lock_acquire(struct lockdep_map *lock, unsigned= int subclass, if (!debug_locks) return; =20 + /* + * As KASAN instrumentation is disabled and lock_acquire() is usually + * the first lockdep call when a task tries to acquire a lock, add + * kasan_check_byte() here to check for use-after-free and other + * memory errors. + */ + kasan_check_byte(lock); + if (unlikely(!lockdep_enabled())) { /* XXX allow trylock from NMI ?!? */ if (lockdep_nmi() && !trylock) { --=20 2.47.1 From nobody Sun Feb 8 05:08:11 2026 Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) (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 2BDA225BAC8; Fri, 7 Mar 2025 23:29:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390150; cv=none; b=phf7sAvWkWfAGBS4TIvfVhEhEbjRq4Mkt7ZY7QYY3PXBkoY33mQhsmXDZSUI/4H6oa+19Wub5QO71MO0XBLVhZSo0+PvGXTLoPbvNxV8OFpj8brOMpVvsIgCXbhl8BIJ1V3y5ipOTKfc9rROQZrLimEJx9eC0s3109CSKT+KMKU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390150; c=relaxed/simple; bh=nl25mqOSxDqiYyUcE43CHVQwdknuB5u30lCgt3g9Sh0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Uqv8tNK3G4Vcoen0+tsxrIT7SPp85sZLl8u05JW8uWJUWu+/UNe0QPQaKHF7s7ggrhXFIefIwm3mgGq0p3qM5QazSH9pW8fFKHeTPCbRTwLSYLD6MUbQ3W3WYw0LpuPc+WLKpSRzNmRD/lW4dEhbd66QP/LrIY4/eOV++YuW3Yk= 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=FMrxsTJz; arc=none smtp.client-ip=209.85.219.46 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="FMrxsTJz" Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-6dcd4f1aaccso36752476d6.2; Fri, 07 Mar 2025 15:29:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741390147; x=1741994947; 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=bLQdfjh9zsl19tiH0Lw1EUrOmo9Rg9QbErOXRQYmnV0=; b=FMrxsTJzCo5c/QO6FRIN+NjPP0Uwozaj7ivjLMFvkisGOTYw/bDQP0TaNd4LPbpsoi JrSF7GpnpjRKdTIL1JslfJ8IQ0U+pfgpquxp1n6/PlYQ+Ui8r9/RwH4k0TTPPuhXGag9 XCXbBJfBqqeKj+RuTLmOw69/sduChsIhqMwnOyUo7L32kMqb+nzNATxBNDrYLdUpFH3G kuCYTx+1eqkIHEXddy/DD/gsdrlT5Tij6ylpwvqgv730PjHztmyIYmT4CxXYh/UeCAGn J1iW3LzhNHiBE4kAonDA+2kcBVkOCrzTmawkC8uBwdALfl/obsAbeDzYXRfsgmj+kAan jm3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741390147; x=1741994947; 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=bLQdfjh9zsl19tiH0Lw1EUrOmo9Rg9QbErOXRQYmnV0=; b=M0IkQgyrteiNn0oOrmulTZLLm8vlqfED3VsAJG/uMWsbypXW5/b1eQ3kPNlho4ZLH9 5QkQAx2u9lbAGdhgXDOtyoA1rDmdqNCHQ438YTeswRhsK5ojRI1TeSBEfl3lDMYb1NzJ k8yTFwFpURr7QFsQYoZPzJgZwOyEOgVfcSYTjF9H2Hbkp3hnOy/hTOb5UJJ2jnzhWNwM ihif3P4eKdHDVVbgpcO4PTNKgpHtP0wbip5DHs7/9xmx92Y6XOdy33arjNH/TuI5KgHz 5/L7SGQ0wYOgb4XhsxLqrZ46bfefIPTyqn6qB1UeahdwcMhOxHE2BCuj1fuAYgfc1ZQY QLKw== X-Forwarded-Encrypted: i=1; AJvYcCUuWTWLRaJWCFVzSp/u1xoDGp0dHB1qERvAB5/0ro+cw3qrJCzY+QwZFaBFWdzUmWiN4yNIdD0ZeXO3k1ULHQs=@vger.kernel.org, AJvYcCV+3Je3tkf+GXIed7fKXnM7CGbqalDQoanKQnN2mD9Uo6FMYNbF5gRLaU+k2C4icE8evuHP50uo/z/ZMEg=@vger.kernel.org X-Gm-Message-State: AOJu0YxKdaKjDJhJSY2muSoCoi06UKPcQqeuVT9xWTQ3+TwTHVrnQjYH D+Mv4I3vV6lEwx2fldfoQUxkvCf6wZaq67W4vwIymRMfbLp5VSYN X-Gm-Gg: ASbGncuJ727CHbnfL4KlyltJth6NO22iaLCHRE4HJspJPlxE4nocFyNENLfkCcIAcFE GfNk7c6P9uchN+YgjpPlQmDpTCNEh+2stxNVsBeEppqMrP0g0mh/dNmYZA4weN5WMQ3Qzq68hxk oJngIq6myMl8r3B6Q6ZXjferaDZAY2gzVr4U3sXWdQAjXP3A/2OnKF2mEQXD4VqEUww8subymX3 OUfmv27DeGMCXVg5+VCUAE1Ub8WQStDZ3FMtKR2oT31AICa1V1KV/xNSNpnaX9PWaFSRkvAzqIO mN6yHwoNKg+z6bDzvoTzwsebcQERlP6nIDboZMXmFw8BylAP21uJ7TaXEkvoE7Q7sPoM1DqrVkJ 9CSlTZ+duUKXHDKPdCJJpra7R8eycyCQwEHM= X-Google-Smtp-Source: AGHT+IGkHwsbUOOaEjNaBUuQ4z6z/Udf2U+2u0ei1UzbhAqrpyOYvd2Rgzfu4BsSO6u23VxJbRKXww== X-Received: by 2002:a05:6214:2622:b0:6d8:8466:d205 with SMTP id 6a1803df08f44-6e9006049c1mr51710416d6.6.1741390146944; Fri, 07 Mar 2025 15:29:06 -0800 (PST) Received: from fauth-a1-smtp.messagingengine.com (fauth-a1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6e8f715b718sm24714966d6.91.2025.03.07.15.29.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Mar 2025 15:29:06 -0800 (PST) Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfauth.phl.internal (Postfix) with ESMTP id 1E642120006A; Fri, 7 Mar 2025 18:29:06 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Fri, 07 Mar 2025 18:29:06 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduudduleekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredt tdenucfhrhhomhepuehoqhhunhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrih hlrdgtohhmqeenucggtffrrghtthgvrhhnpefghfffvefhhfdvgfejgfekvdelgfekgeev ueehlefhiedvgeffjefgteeugfehieenucffohhmrghinhepkhgvrhhnvghlrdhorhhgne cuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhu nhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqdduje ejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdr nhgrmhgvpdhnsggprhgtphhtthhopedujedpmhhouggvpehsmhhtphhouhhtpdhrtghpth htohepmhhinhhgoheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepphgvthgvrhiisehi nhhfrhgruggvrggurdhorhhgpdhrtghpthhtohepfihilhhlsehkvghrnhgvlhdrohhrgh dprhgtphhtthhopehlohhnghhmrghnsehrvgguhhgrthdrtghomhdprhgtphhtthhopehl ihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhope grlhhitggvrhihhhhlsehgohhoghhlvgdrtghomhdprhgtphhtthhopehmvgeskhhlohgv nhhkrdguvghvpdhrtghpthhtohepsghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmpd hrtghpthhtohepmhhinhhgohesrhgvughhrghtrdgtohhm X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Mar 2025 18:29:05 -0500 (EST) From: Boqun Feng To: Ingo Molnar , Peter Zijlstra Cc: Will Deacon , Waiman Long , linux-kernel@vger.kernel.org, Alice Ryhl , Fiona Behrens , Boqun Feng , Ingo Molnar , Miguel Ojeda , Alex Gaynor , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , rust-for-linux@vger.kernel.org (open list:RUST) Subject: [PATCH locking 07/11] rust: sync: Add accessor for the lock behind a given guard Date: Fri, 7 Mar 2025 15:26:57 -0800 Message-ID: <20250307232717.1759087-8-boqun.feng@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250307232717.1759087-1-boqun.feng@gmail.com> References: <20250307232717.1759087-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: Alice Ryhl In order to assert a particular `Guard` is associated with a particular `Lock`, add an accessor to obtain a reference to the underlying `Lock` of a `Guard`. Binder needs this assertion to ensure unsafe list operations are done with the correct lock held. [Boqun: Capitalize the title and reword the commit log] Signed-off-by: Alice Ryhl Reviewed-by: Fiona Behrens Signed-off-by: Boqun Feng Link: https://lore.kernel.org/r/20250205-guard-get-lock-v2-1-ba32a8c1d5b7@g= oogle.com --- rust/kernel/sync/lock.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs index eb80048e0110..8e7e6d5f61e4 100644 --- a/rust/kernel/sync/lock.rs +++ b/rust/kernel/sync/lock.rs @@ -199,7 +199,12 @@ pub struct Guard<'a, T: ?Sized, B: Backend> { // SAFETY: `Guard` is sync when the data protected by the lock is also syn= c. unsafe impl Sync for Guard<'_, T, B> {} =20 -impl Guard<'_, T, B> { +impl<'a, T: ?Sized, B: Backend> Guard<'a, T, B> { + /// Returns the lock that this guard originates from. + pub fn lock_ref(&self) -> &'a Lock { + self.lock + } + pub(crate) fn do_unlocked(&mut self, cb: impl FnOnce() -> U) -> U { // SAFETY: The caller owns the lock, so it is safe to unlock it. unsafe { B::unlock(self.lock.state.get(), &self.state) }; --=20 2.47.1 From nobody Sun Feb 8 05:08:11 2026 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (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 A8744258CE9; Fri, 7 Mar 2025 23:29:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390156; cv=none; b=gto6YnULPDF2Fm+zohE8iuiZ9DTazn/3PRsl7hJOupKO/dDh1DNYkZnM2vrEIHSWLgXAz3uuWYoaF5TezCcIn8GB7cPuXBGGr8wR1T/n80lEP2aTmUg3xnAuRU3yEAke+Hev+6tW772zsNXSY9owFPQduxiKKwlSV08FSVf8h6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390156; c=relaxed/simple; bh=Vd5EkNo9wfox14TAXRzD0lIZdPzB8y8QIV6QgguuxEQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kK3sRnemlbb1owx+XTTEP31vbnhK0wwoUK9anGb66aYw+/iQkAIXr5JFrJxGlmceEy0AOww9MSlDnJDWkKeLoTTQxrmoCSUrQNOuw2fbUt3Ysm5Ip7p4KKEIIFwI1LXYXD80NfczKqH1D9oafS8ugu45c0WJEqgWdpeD+g7Kwyk= 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=c84TxJrF; arc=none smtp.client-ip=209.85.222.174 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="c84TxJrF" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-7c0155af484so348560585a.0; Fri, 07 Mar 2025 15:29:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741390153; x=1741994953; 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=WDEaEguToLusUNSt4i7vCjrvhnl/P8iCXD1cRcQPnHQ=; b=c84TxJrFfID+NkZyUNDz87jif3j8l+DCauxBjVMeN71UKr0vNrzS9IQdPNQFWUiZJh oMdoZN1Am8TP/ZYyMheSApZuV97Zm+tlsMBuIEGKfAtGZgrNbVx3ywdtEpNHbfz0eXFc 2BNEHV/8IfJTowr+mGBn+47KS4SAp9A6ZbnuLroxDNCgQgK47835jCJsb7MVWXez5exo TXf1mTjyzUpbs3peyM9LfmZtdKn3EE/+9hcXQKYs4QNqyYLoIVFbs49UHZVC+XN18TTe GR5/3r/DnsOA9Oozk7TbErReF+c7LrMSdb79Vt32sRmaulpiFdm1nEp+7rblwsRvFWIM I+lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741390153; x=1741994953; 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=WDEaEguToLusUNSt4i7vCjrvhnl/P8iCXD1cRcQPnHQ=; b=I/kTRtUYijcm4bPIFcJR25Ibpaa4FNOXsaruk4uslsKNgDl+erYJ6LDw01cMtK1QhN 4wJ4apnkkFRR/0D8nXz6HLBcpIzC4zCGRKt9qTTAR3F14XuV7zq59SBqFBiDe1Xgj1of /imNfHTR9wmO8bOSHRkyj8iT5mZ2cPY5I4j1qnXNHQVxsz1eh/B0CU02no6aUtSvd3Yq 2BNEt1FerikIyg10DptjpcCHaMCV+5ulM49L47TqrFSnNaG2zh/20n+GIj9V1vW3fksr 1BVjP0E0tHlTm2VgXMoou4/fKg65XwN7BNMS4JzejkdOQbKxee7c79sUikcuL1tJOj4h gnDw== X-Forwarded-Encrypted: i=1; AJvYcCVV2HKhcvbJuD+kBXCxAA8X/xZIy/WP0qYonsdxbMt2f3ERBzCDr5lv67VXcDN2H7XAjaqERhEDlVdswWEU0Fc=@vger.kernel.org, AJvYcCVgPV+G3ZgzRy0daihxXqQoTSgau29O7p8O8XaXV2KbNRIt4+BjTvmVQzeh0qOQbHIjxEY0NHegqZOVfF0=@vger.kernel.org X-Gm-Message-State: AOJu0YyKo+sZBAJ3rDRDaZmYkYYluWdFkWB+wuMOTXqGAOhZEIU4mtfL xP8ZMc0wxTD7NJi5Z8oef6nyroYJiFF8NM75RMOoK8MjUP4hr6bQ X-Gm-Gg: ASbGncvz6HhpnTywIZyFCKN0I04CAi3lwYR9uDXPh3SU/rmhJeMituDnfNJFXodiisz gaCI/PVmdYHiS5LTdhy2tjyP/xekv4KDcH34J5YCUd+zkaYEAE2q7VScDIf4qoS9QiN9ffj7gn6 6QJgLFPy+ReYM7lc4fwOW6IvBTo0TIK5XmGDutNWgguqXM4eIiKjsHy+1yHNg8JZtlJYiAYSZnV Ub3CoOd4o4/2pDedcqeFr9UbTG6R/Bu+iq9OKPl05HesaCT+SllmS1ou38F0sTJvQWWgz3hoNmw Mw+NB1Q80PJFDlRJHeDKgoWETD/Hpdi2HFqGlMRF1JS868gb250tP2kBksOE+1lVye4ndNoUH1m sCmYYfhp4lqj428t5kPCtXa5ULi33pW1Q244= X-Google-Smtp-Source: AGHT+IF5cFAvN3uCa1O+zL+UsBCYoiXQijEgtAfDlQq9ii8OhEQ4J8/m00zdHDNaRq6V+ePNWY5tCQ== X-Received: by 2002:a05:620a:4394:b0:7c3:c406:ec07 with SMTP id af79cd13be357-7c4e61ceb7amr757627085a.45.1741390153585; Fri, 07 Mar 2025 15:29:13 -0800 (PST) Received: from fauth-a1-smtp.messagingengine.com (fauth-a1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c3e5389d57sm303390185a.64.2025.03.07.15.29.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Mar 2025 15:29:13 -0800 (PST) Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfauth.phl.internal (Postfix) with ESMTP id C0B9B120006A; Fri, 7 Mar 2025 18:29:12 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-12.internal (MEProxy); Fri, 07 Mar 2025 18:29:12 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduudduleekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredt tdenucfhrhhomhepuehoqhhunhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrih hlrdgtohhmqeenucggtffrrghtthgvrhhnpefghfffvefhhfdvgfejgfekvdelgfekgeev ueehlefhiedvgeffjefgteeugfehieenucffohhmrghinhepkhgvrhhnvghlrdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhu nhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqdduje ejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdr nhgrmhgvpdhnsggprhgtphhtthhopeduiedpmhhouggvpehsmhhtphhouhhtpdhrtghpth htohepmhhinhhgoheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepphgvthgvrhiisehi nhhfrhgruggvrggurdhorhhgpdhrtghpthhtohepfihilhhlsehkvghrnhgvlhdrohhrgh dprhgtphhtthhopehlohhnghhmrghnsehrvgguhhgrthdrtghomhdprhgtphhtthhopehl ihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhope gsohhquhhnrdhfvghnghesghhmrghilhdrtghomhdprhgtphhtthhopegsvghnnhhordhl ohhsshhinhesphhrohhtohhnrdhmvgdprhgtphhtthhopegrlhhitggvrhihhhhlsehgoh hoghhlvgdrtghomhdprhgtphhtthhopehmihhnghhosehrvgguhhgrthdrtghomh X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Mar 2025 18:29:12 -0500 (EST) From: Boqun Feng To: Ingo Molnar , Peter Zijlstra Cc: Will Deacon , Waiman Long , linux-kernel@vger.kernel.org, Boqun Feng , Benno Lossin , Alice Ryhl , Ingo Molnar , Miguel Ojeda , Alex Gaynor , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Andreas Hindborg , Trevor Gross , rust-for-linux@vger.kernel.org (open list:RUST) Subject: [PATCH locking 08/11] rust: sync: lock: Add an example for Guard::lock_ref() Date: Fri, 7 Mar 2025 15:26:58 -0800 Message-ID: <20250307232717.1759087-9-boqun.feng@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250307232717.1759087-1-boqun.feng@gmail.com> References: <20250307232717.1759087-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" To provide examples on usage of `Guard::lock_ref()` along with the unit test, an "assert a lock is held by a guard" example is added. [boqun: Apply feedback from Benno] Signed-off-by: Boqun Feng Reviewed-by: Benno Lossin Reviewed-by: Alice Ryhl Link: https://lore.kernel.org/r/20250223072114.3715-1-boqun.feng@gmail.com --- rust/kernel/sync/lock.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs index 8e7e6d5f61e4..f53e87d04cd2 100644 --- a/rust/kernel/sync/lock.rs +++ b/rust/kernel/sync/lock.rs @@ -201,6 +201,30 @@ unsafe impl Sync for Gua= rd<'_, T, B> {} =20 impl<'a, T: ?Sized, B: Backend> Guard<'a, T, B> { /// Returns the lock that this guard originates from. + /// + /// # Examples + /// + /// The following example shows how to use [`Guard::lock_ref()`] to as= sert the corresponding + /// lock is held. + /// + /// ``` + /// # use kernel::{new_spinlock, stack_pin_init, sync::lock::{Backend,= Guard, Lock}}; + /// + /// fn assert_held(guard: &Guard<'_, T, B>, lock: &Lock= ) { + /// // Address-equal means the same lock. + /// assert!(core::ptr::eq(guard.lock_ref(), lock)); + /// } + /// + /// // Creates a new lock on the stack. + /// stack_pin_init!{ + /// let l =3D new_spinlock!(42) + /// } + /// + /// let g =3D l.lock(); + /// + /// // `g` originates from `l`. + /// assert_held(&g, &l); + /// ``` pub fn lock_ref(&self) -> &'a Lock { self.lock } --=20 2.47.1 From nobody Sun Feb 8 05:08:11 2026 Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) (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 D4834259498; Fri, 7 Mar 2025 23:29:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390159; cv=none; b=HlNNMRwOBcICKWSeKHAbOKlJtb8TYiMr8fFaPYD/7mv8zw1qmdn4xG09XyNzXzrxy371zwHiEgimxF1OT6tMKyYP0YcacWmAxHbUi5fIg2v91dUg+efqPSoxAGXKRCkFEnLnAFWRXU2IgucJ5imrNQFCi63hZ0CmdZixUK+LSLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390159; c=relaxed/simple; bh=wUb5rfJUOpP8/cv5OVcdeCzQYA9WpFk3XgjGRDPEQ9E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WxB46RWFlZtHg3xlVzuy/w3oTkADmvb2MIRmTMGHEx5mcH0An20RFYG93WXW6EWtUT8lr3Px/+YPSrbEatXg87DvY/RDKmqD+h6aXvMpCIz7dSaITy5DO4KsaYLotyZzmerJmDw6uykl+qgcQYvuUD9ZXuWabTQlKI3BcREKpPE= 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=g0Q5qXwV; arc=none smtp.client-ip=209.85.160.178 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="g0Q5qXwV" Received: by mail-qt1-f178.google.com with SMTP id d75a77b69052e-475a77bbd8cso18531941cf.3; Fri, 07 Mar 2025 15:29:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741390157; x=1741994957; 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=tE+jSgRvh6Fy38K0jqC+l/4MCEBY1CsSIryETB5MTvY=; b=g0Q5qXwVIKjaBHgzklFxR0i63BDZFmtdjW/pBCtEkGSFYb62ztrmDabAbGQKOayRlm o5I9esGC7vYYAdmpo4q9N3g1snGgMExx5wHYuZl9GSX6R3vSNjKFnMI4ACj8VkXo+yAk tqSsivVuLlQNioNjLpqqs2puw+A5snoMcoeAgsD9+x32SGBY9T63iS86Rx7Np+MuCEKg ZjG7wgFVAJIzBxUjWpqn3uQpEAJ0cfBIr15xwReQlLbDdF5JgxXUQ7bmIzzTy/Db/drW oGioI48Gk6W6tXS6N5WvbrVRViIz38Qs/klU+A2BYZC4Hpi4+P1yJjWwGBxBYAvRwYzI 7pvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741390157; x=1741994957; 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=tE+jSgRvh6Fy38K0jqC+l/4MCEBY1CsSIryETB5MTvY=; b=hTZty4x6FTvLUkbchCBPxDmOOcGVugI0UDsyQjYeMvszFkGkwhScX2eIr6JHJ0VAkH FEGB86XAownzxHOaC8XJB05I+YPhMW9xJ5hgjRYVszncvvoJYIZHrGtnXxWX4Jk8N63p HcI04+yEXF7gTsjR5ni9E9MpVFB6xOEkcPRYm2+n4vGppUKUmv4zHheBOU7vKYUfyPhE kMO9m1ObzmTHrfNjkVW2wcDGw1dAJYkRXT1Jxl7FAerg5RcTzhklLGPXXTaGkDbvM+Kz c8965YJDQjQUnAOedhyCU5M4g9gUOtE03m+7PJPuq+6+NjegMh92VkF5/n6rVfgwjPf8 2cjg== X-Forwarded-Encrypted: i=1; AJvYcCWYD3kkNbQiQq7hJc5UFlTx4pm4rxQK3ZJxztUh9ScoVA9NxGs7jwx19kBOORn6vipqQyeyd4Ekx5Twg2E=@vger.kernel.org, AJvYcCWi4UdTLDJiAPedi571ki84vlMMytJmLley3kItogZSunKpETcOz4bGL3pdLX83nek9ldo9G4B7vGVvuSN8LGs=@vger.kernel.org X-Gm-Message-State: AOJu0Yym1tEsoQWXXuOiABtMQT4za3XoxDcoZb7Z/xutZNtryI2s8BMj dIWo4WKh9W/MUoEozPgx2F5VTZ4hsfsPE/07a86WGHO/2DXZxEJG X-Gm-Gg: ASbGncu37jUsE2qjevMLJIVz5cPCLtUWxDjGJkoYmDtc3s3qix3ELSluLaoFxyYUbMr igPJ6bMK7FIGESVfOxbLD134gQJ7l80OR35xbgsdXMofeVbRrofIGcmGE681xzv92jtZyHgFaYV JtN13M2u7r9WC42aCZDQmCofi6tt/95G9uJRPUgZom9qmF92WSS8MwXBHXRYhgyDbHra9xNJrmx DYCSeaQu2xVt4FUiFz5vRZDREtDmPID3sfWosxNyaKbc8a4XLHXJ4TzSKSonOgPJ/cFZ75KDSpE YS8fafz9M407xO7pA17l0FsixdzpuHKVlSBe4kkBtC+rtxlhcIbAzimK7tOgxkWWW01YQT4Cx2V 750PlqzNoB/1EG+Hdy9/mubH+EN8xF7UN8To= X-Google-Smtp-Source: AGHT+IEgcjb0FSbQZshtsaIF+CM3DH9ikYNkpa/0oUa7AP1FXkeIPFycbNxtS6bc1jBNw+yrLcM+fQ== X-Received: by 2002:a05:620a:268b:b0:7c0:9df3:a0cb with SMTP id af79cd13be357-7c4e61b96d5mr958372185a.53.1741390156761; Fri, 07 Mar 2025 15:29:16 -0800 (PST) Received: from fauth-a1-smtp.messagingengine.com (fauth-a1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c3e54ff7a5sm302875285a.82.2025.03.07.15.29.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Mar 2025 15:29:16 -0800 (PST) Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfauth.phl.internal (Postfix) with ESMTP id 00717120006A; Fri, 7 Mar 2025 18:29:16 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Fri, 07 Mar 2025 18:29:16 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduudduleelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredt tdenucfhrhhomhepuehoqhhunhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrih hlrdgtohhmqeenucggtffrrghtthgvrhhnpefghfffvefhhfdvgfejgfekvdelgfekgeev ueehlefhiedvgeffjefgteeugfehieenucffohhmrghinhepkhgvrhhnvghlrdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhu nhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqdduje ejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdr nhgrmhgvpdhnsggprhgtphhtthhopeduledpmhhouggvpehsmhhtphhouhhtpdhrtghpth htohepmhhinhhgoheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepphgvthgvrhiisehi nhhfrhgruggvrggurdhorhhgpdhrtghpthhtohepfihilhhlsehkvghrnhgvlhdrohhrgh dprhgtphhtthhopehlohhnghhmrghnsehrvgguhhgrthdrtghomhdprhgtphhtthhopehl ihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhope grlhhitggvrhihhhhlsehgohhoghhlvgdrtghomhdprhgtphhtthhopegsohhquhhnrdhf vghnghesghhmrghilhdrtghomhdprhgtphhtthhopehojhgvuggrsehkvghrnhgvlhdroh hrghdprhgtphhtthhopegrlhgvgidrghgrhihnohhrsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Mar 2025 18:29:15 -0500 (EST) From: Boqun Feng To: Ingo Molnar , Peter Zijlstra Cc: Will Deacon , Waiman Long , linux-kernel@vger.kernel.org, Alice Ryhl , Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Mitchell Levy , Danilo Krummrich , Christian Brauner , Martin Rodriguez Reboredo , rust-for-linux@vger.kernel.org (open list:RUST) Subject: [PATCH locking 09/11] rust: sync: condvar: Add wait_interruptible_freezable() Date: Fri, 7 Mar 2025 15:26:59 -0800 Message-ID: <20250307232717.1759087-10-boqun.feng@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250307232717.1759087-1-boqun.feng@gmail.com> References: <20250307232717.1759087-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: Alice Ryhl To support waiting for a `CondVar` as a freezable process, add a wait_interruptible_freezable() function. Binder needs this function in the appropriate places to freeze a process where some of its threads are blocked on the Binder driver. [Boqun: Capitalize the title, reword the commit log and rephrase the function doc comment with the impersonal style to align with rest of the file] Signed-off-by: Alice Ryhl Signed-off-by: Boqun Feng Link: https://lore.kernel.org/r/20250204-condvar-freeze-v2-1-804483096260@g= oogle.com --- rust/kernel/sync/condvar.rs | 23 ++++++++++++++++++++++- rust/kernel/task.rs | 2 ++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs index 7df565038d7d..5c1e546a26c3 100644 --- a/rust/kernel/sync/condvar.rs +++ b/rust/kernel/sync/condvar.rs @@ -11,7 +11,9 @@ init::PinInit, pin_init, str::CStr, - task::{MAX_SCHEDULE_TIMEOUT, TASK_INTERRUPTIBLE, TASK_NORMAL, TASK_UNI= NTERRUPTIBLE}, + task::{ + MAX_SCHEDULE_TIMEOUT, TASK_FREEZABLE, TASK_INTERRUPTIBLE, TASK_NOR= MAL, TASK_UNINTERRUPTIBLE, + }, time::Jiffies, types::Opaque, }; @@ -159,6 +161,25 @@ pub fn wait_interruptible(&self= , guard: &mut Guard<'_, T, crate::current!().signal_pending() } =20 + /// Releases the lock and waits for a notification in interruptible an= d freezable mode. + /// + /// The process is allowed to be frozen during this sleep. No lock sho= uld be held when calling + /// this function, and there is a lockdep assertion for this. Freezing= a task that holds a lock + /// can trivially deadlock vs another task that needs that lock to com= plete before it too can + /// hit freezable. + #[must_use =3D "wait_interruptible_freezable returns if a signal is pe= nding, so the caller must check the return value"] + pub fn wait_interruptible_freezable( + &self, + guard: &mut Guard<'_, T, B>, + ) -> bool { + self.wait_internal( + TASK_INTERRUPTIBLE | TASK_FREEZABLE, + guard, + MAX_SCHEDULE_TIMEOUT, + ); + crate::current!().signal_pending() + } + /// Releases the lock and waits for a notification in interruptible mo= de. /// /// Atomically releases the given lock (whose ownership is proven by t= he guard) and puts the diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs index 07bc22a7645c..ea43a3b8d9c5 100644 --- a/rust/kernel/task.rs +++ b/rust/kernel/task.rs @@ -23,6 +23,8 @@ pub const TASK_INTERRUPTIBLE: c_int =3D bindings::TASK_INTERRUPTIBLE as c_= int; /// Bitmask for tasks that are sleeping in an uninterruptible state. pub const TASK_UNINTERRUPTIBLE: c_int =3D bindings::TASK_UNINTERRUPTIBLE a= s c_int; +/// Bitmask for tasks that are sleeping in a freezable state. +pub const TASK_FREEZABLE: c_int =3D bindings::TASK_FREEZABLE as c_int; /// Convenience constant for waking up tasks regardless of whether they ar= e in interruptible or /// uninterruptible sleep. pub const TASK_NORMAL: c_uint =3D bindings::TASK_NORMAL as c_uint; --=20 2.47.1 From nobody Sun Feb 8 05:08:11 2026 Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) (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 AA0FE25D8F2; Fri, 7 Mar 2025 23:29:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390167; cv=none; b=dyvtasxdfISj8rRbO2XLpdA94eMNaF6aDEf6senM3LUgMht0t1O1Qe/WWVD8IecXLU8va3ESaCGiFUG1K3lJZGCLajYZ2YkmCEy+gixDw8CMo65gRxD0LCFtcVbaLFbs1dD5WjQeCAI39p+Yeis3QZFsYFgYExyYqPPvHtQvOxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390167; c=relaxed/simple; bh=EN2WCM3Fe2apmKI2sJLPkfk+FyqHPeBOOQKGk2eCDQU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=czbYFSmS2P6BbMLLVO/trff5/cxuKIbozmpXXzZNS9vyuamg3Zpvoh29Ffh1/DZewdghy0RRdpyrvCSebDIQzkN9JX/SuJskoGQqRJ5fAaRydXSMeS8MUhDTXGV6dc9yrq10QL3oIBD56tg8xhq0DL4gBECCmUAl5SnIbA4jc3g= 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=f19YZS0f; arc=none smtp.client-ip=209.85.160.179 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="f19YZS0f" Received: by mail-qt1-f179.google.com with SMTP id d75a77b69052e-46c8474d8f6so19355291cf.3; Fri, 07 Mar 2025 15:29:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741390164; x=1741994964; 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=u97qSHNSHn4i8j/JUzVrDl8csPGwebUmG7SRNObd36M=; b=f19YZS0fAepfWSvwp8/xTHsj0CPW7AKOrM6WGgRoTfYqVxRg3HMaKi8jyIDpf1d+uY SrB6UJy3CB46Dsl7JGC2g+HBlADDbhMMlI5v9qqnBqTkiBQmL4T8kiCbpWL8TAHfPg1l NqXQcs6by0KoNnggqJqUlLOAJrBt7+LxfhI8XD4M2ntHOPvO9ZwjUi4Y1iBkhfgh/bK4 vaenisJeq7Y2p0XBvhksPn1PwKLBBQKN8TNBYxdhZKgxqlZ4GQzbEzGrEGCazh863Dpn BOQIRp6PxuRMF1bk86r5Gv/tYYzHlxl5CoISx3aAtjXng9ZwfaJGWGJIUBVIrVGKko/O NcpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741390164; x=1741994964; 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=u97qSHNSHn4i8j/JUzVrDl8csPGwebUmG7SRNObd36M=; b=vMCEXZwOiKRhD+g7rEUbnT/RDtmUXn/pS7ZRuGj1EMJdL9YVWSCYybJQStWQ6DqtUL VgpST5cMdzPBpNNSHSxCerJcKry6eKbhwo+UmqIVbCtVarpBmV2OQwvp53mLORL5W7Wb 6++VRjbABm8e/t8PdYi2IaO1+W1IbNZRiFefzdIcuqvmqkSLfi5qnhNW0tGA+zI8uslf Yr/YMeZVBsftDvnpESGIkFbZZLF30Yl46suys7mubjhgd0dIbkSLDuO5x2KRBY47mbaf qCuJH+byrtzDAnt6uEM5faZP+Iw+zB3Ox+fR82iwqsNlJ7TypDcgaCPN+nDakrqFtp1k wBlA== X-Forwarded-Encrypted: i=1; AJvYcCUyiN3owfG4dwIn22knlHl6jDXPxoScR0+J3tyIGIWxUoieCAWqVhYM082rDspvkcHUE1H0DG1GMWbxs7Y=@vger.kernel.org, AJvYcCWdRrtuGcZhHnlQP++I8nX8/dahio9v/JVrI2Dm9nmtxFyzfh2sW7qbCT5u2I/GYTY8kHoDHqXoTA6kgvTJi4g=@vger.kernel.org, AJvYcCXPj1ymVdcrI6uRA0TMMyQhAr+ZuSlf9dWNPqrs3eIZfJMOH/fpxfBLQ6h0U7dGReErrqM45GCT@vger.kernel.org X-Gm-Message-State: AOJu0YzG9GxfZ2wqtRMgbnizmm9LEaPtdnaiCWXukWubJ6pi4SuVaDLs XOHVzLVGmRjX+7Vw0r36Vp2snLhx1Fw4saqyE97mTtPRTzBTwwMi X-Gm-Gg: ASbGncu5K+n1pMNbHVeUZjepCaQenvHRNJFRHO5r12ZogmLszrdY+6kRCHMGVk38GS3 m6eqpEoQZA6a7bAGn9GISYkm+03Rvc/UkmAKhRTKGkK6Q/kUj776QApcGgmk+VhWY13RFotY02K 9J51DzJe9DTx1EPewNie4+6t3aEPowjCdMwBtGVW24ic2e4b9LxsV6DyGaWXus+G2H8ta1U8Nlq ktsnXEjG5/RMcVXH5xXbrbsi41p5HHL5ON2X0rgpjEZmK+5xgPjkDt7jOXboGGoSK579Lo/zK6N wMhqbEaubvh4V393P8890MHVNilEi1LEVzw8H9jdQb/rv9zs0Dabb63w0YL5cfxMIjFzTvz8p/C TZmwI/Gu2/+7+A85BT8FIYqpcZLwVv4SwpPI= X-Google-Smtp-Source: AGHT+IGYRCdD3Q7FZFT43BsjaBxyWh9yUY4vkr7hQ9Bi4GFFzJrNeT+f1m1+ytPjCvc8tEGf4Wl58g== X-Received: by 2002:a05:622a:1a1e:b0:474:bca3:9192 with SMTP id d75a77b69052e-476109ad024mr74857131cf.26.1741390164440; Fri, 07 Mar 2025 15:29:24 -0800 (PST) Received: from fauth-a1-smtp.messagingengine.com (fauth-a1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4751d9a89acsm26020021cf.44.2025.03.07.15.29.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Mar 2025 15:29:24 -0800 (PST) Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfauth.phl.internal (Postfix) with ESMTP id 6C7F6120006B; Fri, 7 Mar 2025 18:29:23 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Fri, 07 Mar 2025 18:29:23 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduudduleekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredt tdenucfhrhhomhepuehoqhhunhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrih hlrdgtohhmqeenucggtffrrghtthgvrhhnpefghfffvefhhfdvgfejgfekvdelgfekgeev ueehlefhiedvgeffjefgteeugfehieenucffohhmrghinhepkhgvrhhnvghlrdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhu nhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqdduje ejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdr nhgrmhgvpdhnsggprhgtphhtthhopedvtddpmhhouggvpehsmhhtphhouhhtpdhrtghpth htohepmhhinhhgoheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepphgvthgvrhiisehi nhhfrhgruggvrggurdhorhhgpdhrtghpthhtohepfihilhhlsehkvghrnhgvlhdrohhrgh dprhgtphhtthhopehlohhnghhmrghnsehrvgguhhgrthdrtghomhdprhgtphhtthhopehl ihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhope hlvghvhihmihhttghhvghllhdtsehgmhgrihhlrdgtohhmpdhrtghpthhtoheprghlihgt vghrhihhlhesghhoohhglhgvrdgtohhmpdhrtghpthhtohepshhtrggslhgvsehvghgvrh drkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepsggvnhhnohdrlhhoshhsihhnsehprhho thhonhdrmhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Mar 2025 18:29:22 -0500 (EST) From: Boqun Feng To: Ingo Molnar , Peter Zijlstra Cc: Will Deacon , Waiman Long , linux-kernel@vger.kernel.org, Mitchell Levy , Alice Ryhl , stable@vger.kernel.org, Benno Lossin , Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Andreas Hindborg , Trevor Gross , Lyude Paul , Wedson Almeida Filho , Martin Rodriguez Reboredo , rust-for-linux@vger.kernel.org (open list:RUST) Subject: [PATCH locking 10/11] rust: lockdep: Remove support for dynamically allocated LockClassKeys Date: Fri, 7 Mar 2025 15:27:00 -0800 Message-ID: <20250307232717.1759087-11-boqun.feng@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250307232717.1759087-1-boqun.feng@gmail.com> References: <20250307232717.1759087-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: Mitchell Levy Currently, dynamically allocated LockCLassKeys can be used from the Rust side without having them registered. This is a soundness issue, so remove them. Suggested-by: Alice Ryhl Link: https://lore.kernel.org/rust-for-linux/20240815074519.2684107-3-nmi@m= etaspace.dk/ Cc: stable@vger.kernel.org Fixes: 6ea5aa08857a ("rust: sync: introduce `LockClassKey`") Reviewed-by: Benno Lossin Signed-off-by: Mitchell Levy Signed-off-by: Boqun Feng Link: https://lore.kernel.org/r/20250207-rust-lockdep-v4-1-7a50a7e88656@gma= il.com --- rust/kernel/sync.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/rust/kernel/sync.rs b/rust/kernel/sync.rs index 3498fb344dc9..16eab9138b2b 100644 --- a/rust/kernel/sync.rs +++ b/rust/kernel/sync.rs @@ -30,28 +30,20 @@ unsafe impl Sync for LockClassKey {} =20 impl LockClassKey { - /// Creates a new lock class key. - pub const fn new() -> Self { - Self(Opaque::uninit()) - } - pub(crate) fn as_ptr(&self) -> *mut bindings::lock_class_key { self.0.get() } } =20 -impl Default for LockClassKey { - fn default() -> Self { - Self::new() - } -} - /// Defines a new static lock class and returns a pointer to it. #[doc(hidden)] #[macro_export] macro_rules! static_lock_class { () =3D> {{ - static CLASS: $crate::sync::LockClassKey =3D $crate::sync::LockCla= ssKey::new(); + static CLASS: $crate::sync::LockClassKey =3D + // SAFETY: lockdep expects uninitialized memory when it's hand= ed a statically allocated + // lock_class_key + unsafe { ::core::mem::MaybeUninit::uninit().assume_init() }; &CLASS }}; } --=20 2.47.1 From nobody Sun Feb 8 05:08:11 2026 Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) (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 4AD0325A2AA; Fri, 7 Mar 2025 23:29:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390184; cv=none; b=QbU5mchX4iY+Sts6Iv30F0kgXL00IukQ7e0Jnhf2drUKRIAQTMEO/MUbuAQS6aQAdtTm0d8geSVbBbLjVpf5K3G/i3arSjIBRGZKq0FqD8+Su1eDcqLPgTvoJhrSgxsNUoiQG30esy73BSO6I3tpNVkezWoouxuTaIWthfuJW2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390184; c=relaxed/simple; bh=4T6JiUrprXIHYAAwo9JH+u1tRa+hCt1edvmkZjmco9s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p0TNlMG4njAqRcV2xV0AS+xdkTaVDnfTTM7yujY7GITPgGvxY5TWHE4cidgEdztC1AN16N59olPI002E1O/GbqDXjnMmRBmJfQIChJ5y07WnWpmaot7074h+yA1wZzfLkQvB9X6hoRZawi7tZ/0QrgPmxQJf6300Kh0+DTH4ohs= 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=lntV4bw+; arc=none smtp.client-ip=209.85.219.41 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="lntV4bw+" Received: by mail-qv1-f41.google.com with SMTP id 6a1803df08f44-6e8f6970326so17846056d6.0; Fri, 07 Mar 2025 15:29:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741390181; x=1741994981; 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=APp1sd7jGBSg/u5pTAADDBD+S92qNVZmi8A5p35ed74=; b=lntV4bw+Yu/4saIo9Lvnj7S5b7NgQfMyKKqaSfTZ/wbI19oF7/wSXHdhpc2jz4h7Kx VWI/EUdRVNfdlGANsjqDPGRbiSVNOn8wPXHOBpBFtovbgcM6jkOPHUj7vjKO332G2YCC v2hyYf7eaZt3W0vJ9ekCC/8h7ZXj2gRyH21FoY76khOzvxqVnSjZcuY57XzqGSxVN1DT GT1bYKaIuTqoNyNr32ReIIjrgbq0xEfQPL1YKIAKkpa316/djrxFyZzkApdSw17+x0Zp JZvDwvEbc6HfRioyFGUs4P4agPdwoiJa80ZmhqwAo10Gr2qEjtreQkRN2cifzMZN0SnU EJyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741390181; x=1741994981; 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=APp1sd7jGBSg/u5pTAADDBD+S92qNVZmi8A5p35ed74=; b=nZA8hQ0pX9W0WNO0cJHaK85HjcXKfoNR8ABkL2hcYSxtTmvlAHoh7gDQhlLLnDI2ci 5j1xkRERrBxbPkjC1RSf2jLJlXXza3eDdke3aD0jvIBbNfdI2cVpHUrI4HiDI7Rc+VXX N4wgxeWb+OQBO64KBp5yFM+VvMzaZf7/ZBYP0sxpuorWYBdn4T18FCSnLhH/Cz5JF/Aj pm0bqUBbu+841Uc04ETef+/1Fp3oPSScSVdXrOyA/hc7YuAsNdWLt3W7GSxaOMhynSrt IprZ5yn3cAXInGqcw2/0xOv+MyBfm265Bb44ONkWyeseoOwDtKPHUd4KPJ7upppO+APB v3wg== X-Forwarded-Encrypted: i=1; AJvYcCUwPBIf43EAo7SenRZpYkH4GwnCF+RDoiBfbo+TWkesljyzi/rp3BzsbnG3qvAzHWpENkuLQzcFvrp3jzs=@vger.kernel.org, AJvYcCVQGH9bNxbjcJFXMkSBDTe3J4WCfl/Acw0vQ/iCoA+LMtlSuRSw+XVUeU82awtTTl+9R7RD/WG51RrbMtPjVsA=@vger.kernel.org X-Gm-Message-State: AOJu0Yzwd5fbWXuEdvrJL9u0+KBtlEzVh65Q7Rgdt2JGg0+VWuRPoKBp fAU/ov+CBCobNdmPB2E9/QDdPZVMcVlerGK94dBu8cDucq3gVixQ X-Gm-Gg: ASbGncsnAghYJFOfvYJk6JqClESF58FXzHz4RFQrAQq3Gr45GJIGO1K6VvJt9HCRFbq 5uwNvzgyIS8YiYnc7huJljA2RAUPQYXrngEuVptCbdMgKKDxr3dbwl1pi3fdd2pLbaa1ql2M+M0 iUJYCBv9qXsDabr3QV/s/vlqmqO9grFNvr66I2wAHkAC1zlsRX/6rrWcSbA7qXvzyEj8uhJSKx8 YSoHl3/0BLQ/cgqbNgJsXHUcsALbdX9j1wbaowAYIFRybpUmDijdj6A1Yr1Soa08l1vH9G9SRWJ 4YqQWEniOGzq1lfau1H16py5/WhxM5aiDEvtngPYnNk97ksO+R40GJGMsHjAGX+wzWg1trB6lMr KtmuMokFzh4VAzHgLoDakiy4QpLBCS+NolTI= X-Google-Smtp-Source: AGHT+IHcYE8/LLj0kiFeVLR9T+AdpRWKX6nUtKgMM2ov/QeiBydpmcduyzzTOanK37zj/UgZu6cPpg== X-Received: by 2002:ad4:5cae:0:b0:6e8:ebfa:42f9 with SMTP id 6a1803df08f44-6e9005f79admr72055636d6.16.1741390181043; Fri, 07 Mar 2025 15:29:41 -0800 (PST) Received: from fauth-a1-smtp.messagingengine.com (fauth-a1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6e8f707c4b5sm24771966d6.1.2025.03.07.15.29.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Mar 2025 15:29:40 -0800 (PST) Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfauth.phl.internal (Postfix) with ESMTP id 1EF7A120006A; Fri, 7 Mar 2025 18:29:40 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Fri, 07 Mar 2025 18:29:40 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduudduleekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredt tdenucfhrhhomhepuehoqhhunhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrih hlrdgtohhmqeenucggtffrrghtthgvrhhnpeekteetjeegudeikedujeefvddvtdeigfei ffffleejfeeiheeiffefvdeffffgteenucffohhmrghinhepghhithhhuhgsrdgtohhmpd hkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgr ihhlfhhrohhmpegsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqd eiledvgeehtdeigedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhl rdgtohhmsehfihigmhgvrdhnrghmvgdpnhgspghrtghpthhtohepvdegpdhmohguvgepsh hmthhpohhuthdprhgtphhtthhopehmihhnghhosehkvghrnhgvlhdrohhrghdprhgtphht thhopehpvghtvghriiesihhnfhhrrgguvggrugdrohhrghdprhgtphhtthhopeifihhllh eskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhonhhgmhgrnhesrhgvughhrghtrdgt ohhmpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrd horhhgpdhrtghpthhtoheplhgvvhihmhhithgthhgvlhhltdesghhmrghilhdrtghomhdp rhgtphhtthhopegsvghnnhhordhlohhsshhinhesphhrohhtohhnrdhmvgdprhgtphhtth hopegsohhquhhnrdhfvghnghesghhmrghilhdrtghomhdprhgtphhtthhopehojhgvuggr sehkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Mar 2025 18:29:39 -0500 (EST) From: Boqun Feng To: Ingo Molnar , Peter Zijlstra Cc: Will Deacon , Waiman Long , linux-kernel@vger.kernel.org, Mitchell Levy , Benno Lossin , Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Andreas Hindborg , Alice Ryhl , Trevor Gross , Ingo Molnar , Danilo Krummrich , Wedson Almeida Filho , Christian Brauner , Lyude Paul , Martin Rodriguez Reboredo , Konstantin Andrikopoulos , Roland Xu , rust-for-linux@vger.kernel.org (open list:RUST) Subject: [PATCH locking 11/11] rust: lockdep: Use Pin for all LockClassKey usages Date: Fri, 7 Mar 2025 15:27:01 -0800 Message-ID: <20250307232717.1759087-12-boqun.feng@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250307232717.1759087-1-boqun.feng@gmail.com> References: <20250307232717.1759087-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: Mitchell Levy Reintroduce dynamically-allocated LockClassKeys such that they are automatically (de)registered. Require that all usages of LockClassKeys ensure that they are Pin'd. Currently, only `'static` LockClassKeys are supported, so Pin is redundant. However, it is intended that dynamically-allocated LockClassKeys will eventually be supported, so using Pin from the outset will make that change simpler. Closes: https://github.com/Rust-for-Linux/linux/issues/1102 Suggested-by: Benno Lossin Suggested-by: Boqun Feng Signed-off-by: Mitchell Levy Reviewed-by: Benno Lossin Signed-off-by: Boqun Feng Link: https://lore.kernel.org/r/20250207-rust-lockdep-v4-2-7a50a7e88656@gma= il.com --- rust/helpers/helpers.c | 1 + rust/helpers/sync.c | 13 ++++++++ rust/kernel/sync.rs | 57 +++++++++++++++++++++++++++++++-- rust/kernel/sync/condvar.rs | 5 ++- rust/kernel/sync/lock.rs | 4 +-- rust/kernel/sync/lock/global.rs | 5 +-- rust/kernel/sync/poll.rs | 2 +- rust/kernel/workqueue.rs | 2 +- 8 files changed, 77 insertions(+), 12 deletions(-) create mode 100644 rust/helpers/sync.c diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c index 0640b7e115be..4c1a10a419cf 100644 --- a/rust/helpers/helpers.c +++ b/rust/helpers/helpers.c @@ -30,6 +30,7 @@ #include "signal.c" #include "slab.c" #include "spinlock.c" +#include "sync.c" #include "task.c" #include "uaccess.c" #include "vmalloc.c" diff --git a/rust/helpers/sync.c b/rust/helpers/sync.c new file mode 100644 index 000000000000..ff7e68b48810 --- /dev/null +++ b/rust/helpers/sync.c @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include + +void rust_helper_lockdep_register_key(struct lock_class_key *k) +{ + lockdep_register_key(k); +} + +void rust_helper_lockdep_unregister_key(struct lock_class_key *k) +{ + lockdep_unregister_key(k); +} diff --git a/rust/kernel/sync.rs b/rust/kernel/sync.rs index 16eab9138b2b..4104bc26471a 100644 --- a/rust/kernel/sync.rs +++ b/rust/kernel/sync.rs @@ -5,6 +5,8 @@ //! This module contains the kernel APIs related to synchronisation that h= ave been ported or //! wrapped for usage by Rust code in the kernel. =20 +use crate::pin_init; +use crate::prelude::*; use crate::types::Opaque; =20 mod arc; @@ -23,15 +25,64 @@ =20 /// Represents a lockdep class. It's a wrapper around C's `lock_class_key`. #[repr(transparent)] -pub struct LockClassKey(Opaque); +#[pin_data(PinnedDrop)] +pub struct LockClassKey { + #[pin] + inner: Opaque, +} =20 // SAFETY: `bindings::lock_class_key` is designed to be used concurrently = from multiple threads and // provides its own synchronization. unsafe impl Sync for LockClassKey {} =20 impl LockClassKey { + /// Initializes a dynamically allocated lock class key. In the common = case of using a + /// statically allocated lock class key, the static_lock_class! macro = should be used instead. + /// + /// # Example + /// ``` + /// # use kernel::{c_str, stack_pin_init}; + /// # use kernel::alloc::KBox; + /// # use kernel::types::ForeignOwnable; + /// # use kernel::sync::{LockClassKey, SpinLock}; + /// + /// let key =3D KBox::pin_init(LockClassKey::new_dynamic(), GFP_KERNEL= )?; + /// let key_ptr =3D key.into_foreign(); + /// + /// { + /// stack_pin_init!(let num: SpinLock =3D SpinLock::new( + /// 0, + /// c_str!("my_spinlock"), + /// // SAFETY: `key_ptr` is returned by the above `into_foreig= n()`, whose + /// // `from_foreign()` has not yet been called. + /// unsafe { > as ForeignOwnable>::borr= ow(key_ptr) } + /// )); + /// } + /// + /// // SAFETY: We dropped `num`, the only use of the key, so the resul= t of the previous + /// // `borrow` has also been dropped. Thus, it's safe to use from_for= eign. + /// unsafe { drop(> as ForeignOwnable>::from_fo= reign(key_ptr)) }; + /// + /// # Ok::<(), Error>(()) + /// ``` + pub fn new_dynamic() -> impl PinInit { + pin_init!(Self { + // SAFETY: lockdep_register_key expects an uninitialized block= of memory + inner <- Opaque::ffi_init(|slot| unsafe { bindings::lockdep_re= gister_key(slot) }) + }) + } + pub(crate) fn as_ptr(&self) -> *mut bindings::lock_class_key { - self.0.get() + self.inner.get() + } +} + +#[pinned_drop] +impl PinnedDrop for LockClassKey { + fn drop(self: Pin<&mut Self>) { + // SAFETY: self.as_ptr was registered with lockdep and self is pin= ned, so the address + // hasn't changed. Thus, it's safe to pass to unregister. + unsafe { bindings::lockdep_unregister_key(self.as_ptr()) } } } =20 @@ -44,7 +95,7 @@ macro_rules! static_lock_class { // SAFETY: lockdep expects uninitialized memory when it's hand= ed a statically allocated // lock_class_key unsafe { ::core::mem::MaybeUninit::uninit().assume_init() }; - &CLASS + $crate::prelude::Pin::static_ref(&CLASS) }}; } =20 diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs index 5c1e546a26c3..fbf68ada582f 100644 --- a/rust/kernel/sync/condvar.rs +++ b/rust/kernel/sync/condvar.rs @@ -17,8 +17,7 @@ time::Jiffies, types::Opaque, }; -use core::marker::PhantomPinned; -use core::ptr; +use core::{marker::PhantomPinned, pin::Pin, ptr}; use macros::pin_data; =20 /// Creates a [`CondVar`] initialiser with the given name and a newly-crea= ted lock class. @@ -103,7 +102,7 @@ unsafe impl Sync for CondVar {} =20 impl CondVar { /// Constructs a new condvar initialiser. - pub fn new(name: &'static CStr, key: &'static LockClassKey) -> impl Pi= nInit { + pub fn new(name: &'static CStr, key: Pin<&'static LockClassKey>) -> im= pl PinInit { pin_init!(Self { _pin: PhantomPinned, // SAFETY: `slot` is valid while the closure is called and bot= h `name` and `key` have diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs index f53e87d04cd2..360a10a9216d 100644 --- a/rust/kernel/sync/lock.rs +++ b/rust/kernel/sync/lock.rs @@ -12,7 +12,7 @@ str::CStr, types::{NotThreadSafe, Opaque, ScopeGuard}, }; -use core::{cell::UnsafeCell, marker::PhantomPinned}; +use core::{cell::UnsafeCell, marker::PhantomPinned, pin::Pin}; use macros::pin_data; =20 pub mod mutex; @@ -129,7 +129,7 @@ unsafe impl Sync for Lock= {} =20 impl Lock { /// Constructs a new lock initialiser. - pub fn new(t: T, name: &'static CStr, key: &'static LockClassKey) -> i= mpl PinInit { + pub fn new(t: T, name: &'static CStr, key: Pin<&'static LockClassKey>)= -> impl PinInit { pin_init!(Self { data: UnsafeCell::new(t), _pin: PhantomPinned, diff --git a/rust/kernel/sync/lock/global.rs b/rust/kernel/sync/lock/global= .rs index 480ee724e3cc..d65f94b5caf2 100644 --- a/rust/kernel/sync/lock/global.rs +++ b/rust/kernel/sync/lock/global.rs @@ -13,6 +13,7 @@ use core::{ cell::UnsafeCell, marker::{PhantomData, PhantomPinned}, + pin::Pin, }; =20 /// Trait implemented for marker types for global locks. @@ -26,7 +27,7 @@ pub trait GlobalLockBackend { /// The backend used for this global lock. type Backend: Backend + 'static; /// The class for this global lock. - fn get_lock_class() -> &'static LockClassKey; + fn get_lock_class() -> Pin<&'static LockClassKey>; } =20 /// Type used for global locks. @@ -270,7 +271,7 @@ impl $crate::sync::lock::GlobalLockBackend for $name { type Item =3D $valuety; type Backend =3D $crate::global_lock_inner!(backend $kind); =20 - fn get_lock_class() -> &'static $crate::sync::LockClassKey { + fn get_lock_class() -> Pin<&'static $crate::sync::LockClassKey= > { $crate::static_lock_class!() } } diff --git a/rust/kernel/sync/poll.rs b/rust/kernel/sync/poll.rs index d5f17153b424..c4934f82d68b 100644 --- a/rust/kernel/sync/poll.rs +++ b/rust/kernel/sync/poll.rs @@ -89,7 +89,7 @@ pub struct PollCondVar { =20 impl PollCondVar { /// Constructs a new condvar initialiser. - pub fn new(name: &'static CStr, key: &'static LockClassKey) -> impl Pi= nInit { + pub fn new(name: &'static CStr, key: Pin<&'static LockClassKey>) -> im= pl PinInit { pin_init!(Self { inner <- CondVar::new(name, key), }) diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs index 0cd100d2aefb..6b6f3ad08951 100644 --- a/rust/kernel/workqueue.rs +++ b/rust/kernel/workqueue.rs @@ -369,7 +369,7 @@ unsafe impl Sync for Work {} impl Work { /// Creates a new instance of [`Work`]. #[inline] - pub fn new(name: &'static CStr, key: &'static LockClassKey) -> impl Pi= nInit + pub fn new(name: &'static CStr, key: Pin<&'static LockClassKey>) -> im= pl PinInit where T: WorkItem, { --=20 2.47.1