Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp692345lqt; Tue, 19 Mar 2024 00:07:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXNua4gP4zCN2XHc8hoXHaiY1yEv6qyNjdjU1x/Yk0nxQHpc8/MQZ034/1E/ldnYQlb34uyvsyy1o/2761CB1I6235U4c7I8bJeMpcUzw== X-Google-Smtp-Source: AGHT+IFn4OXtHo2n4MhjmNaOvmTsMLXGCFFT986ohrNYpW6RozcekJI6/uO/fqv6qEGYw5pJMTsu X-Received: by 2002:ac8:7d8e:0:b0:430:bd2f:bc88 with SMTP id c14-20020ac87d8e000000b00430bd2fbc88mr12013410qtd.30.1710832071899; Tue, 19 Mar 2024 00:07:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710832071; cv=pass; d=google.com; s=arc-20160816; b=z3vp5liR1bSpO5DvkB4h4aeCmwrFA8nzI9orHt9ICs2Vo+2UVwPrB9mMEvwyywHc6F ccqfjy2rOsxMMf1/V+vCcpvaA1QyO8bjQs+Y31yM3ZytOHI8uZID2R/PD2YkAXnnQdT1 f1K1hYjtwKmZ4e39oRhjc19koHtOYaXictyUVQXJKFD+rmt2QtWlOuZQinxdgCvh6aqd ZnDytukVu2azFcl6X+V+oK04R5Q7arKIponGBXRYUOIWYXqbhnqpmPX9F6B7CPgTrNBf M+wnsbtoI6hOyKMs8OYQa2S0TX3HTpJhIoY04PdlG5z/RR2J/Qa8BVbNzjebpUjHqWgV Mtsg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:cc:to:from:dkim-signature :dkim-signature:date; bh=pC/wpDRJZDRfQKX/eRdqlrCvgp6Dahbk2I2pygprEIk=; fh=lU9d435sQyRZx59Gen+cMSk9nVa/hATtC+tJucZmN/M=; b=ClAbGQjFSDbIp1TcZ/QX7tgqJ3NFOcJvEEeRbjlqcydosWfHN41YbqZMgtYyo+CQHB QBcsFywn+RLvQO/0pCfVNw75EdISzp+WpVkclWCCXbiINQztWVmO73NymORFKlD9i9eN 2dQxWUuYQVS7HNaPiIyVXeiZcp271wvNJOA6cC6nwOA3yiYJf5HHVV8r5HIVkSOyBYpp LsuLgEs9/K4GhQA24j1ZIUS22xYRueY3eIR8n4GIsCybAthWyFNBUgZ+UnE1r4Er2PXO aEonf4oTtoapgT80md/GMR40Dr5Zi3/ehXzDOVV3VmfJbDq1pg2J7RQ0mI/bSrIUtPyA t3Sg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=v4o+wILb; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-107149-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107149-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g19-20020ac85813000000b0042ee624e2fdsi9331389qtg.337.2024.03.19.00.07.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 00:07:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-107149-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=v4o+wILb; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-107149-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107149-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 9EE841C2186A for ; Tue, 19 Mar 2024 07:07:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 809EC537FC; Tue, 19 Mar 2024 07:05:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="v4o+wILb"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="c6Zvcnrd" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 147C650A97 for ; Tue, 19 Mar 2024 07:05:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710831955; cv=none; b=GcgzxjadBpBsQZ492dzlIMfI0X8Vf4ntlJ2nFubVobir2qmGJcXY37IDnd2zX7wI7fvneL8z0TVFpQj3d2pVEIm0MRj9HoroYlAMeVlWB/xvyqi2pHue4VunAqVd9D0JO48PWGbxGCn+bQmdAFmcp5eBgNBi84oxvq/kfqnl8FY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710831955; c=relaxed/simple; bh=SMC53HP4py1br5aAuhfS6sBbuhypMvRPEcFuFgGNcao=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=lwkYmrsxKjjjtkPGUhnuSOu/Ka845cOJ2/RU5/hqnmnUMKlnswr5iDXjzMrP9oe1VzIoSLO558emDYsZ5Ph/PCtZAWlKROuHFkPK4aIeSBE8yJakpmBJjGDi4W06SryLHnxQIpjH8Emt+I/XvbuRvNZ6CtzSv5Jo4QIOfWy7MDo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=v4o+wILb; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=c6Zvcnrd; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Tue, 19 Mar 2024 08:05:50 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1710831952; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=pC/wpDRJZDRfQKX/eRdqlrCvgp6Dahbk2I2pygprEIk=; b=v4o+wILbSUlY+1B/gbnNZM+cnQaBsvUZkfayrjRorA2mXVRlcTWjwE6wWvvIZq7X1TFJN2 iKkddvw+11MGsqYJazcqHFrusJSH0PT4BGRLynkY2FcdbF0Hw4JMoz6t4mvChYKpH8CjW8 rArQAc1jDmJlSADRBW6qp66++Gi4ENfAR+qNzdTEJxuKSZVy05ecdK3eFATbCH4XDSQQDO ZKdLZ+V4Ge8WXy5Ddjrjn6HPtRKYm3Zi/7oW1ZsQIy8MBSoM4YTwziN4JsiIcskRhNkjGt 2DbXfvTrSwj27JsihVPeoDIxc5x3pEgj3eC3n1SnUl77dKhWUq7bqW5VYAh6aQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1710831952; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=pC/wpDRJZDRfQKX/eRdqlrCvgp6Dahbk2I2pygprEIk=; b=c6Zvcnrd00VAwnkmooSeUK+OmtSAdV5Qr3VymbdMXOtEyfpeIR63jzQrfMT1n46fHYm0lV s3gpflFXAoWiDHBQ== From: Sebastian Andrzej Siewior To: linux-kernel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , Boqun Feng , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Waiman Long , Will Deacon , Clark Williams Subject: [PATCH] Locking: Let PREEMPT_RT compile again with new rwsem asserts. Message-ID: <20240319070550.ws_uO21-@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline The commit cited below broke the build for PREEMPT_RT because rwsem_assert_held_write_nolockdep() passes a struct rw_semaphore but rw_base_assert_held_write() expects struct rwbase_rt. Fixing the type alone leads to the problem that WARN_ON() is not found because bug.h is missing. In order to resolve this: - Keep the assert (WARN_ON()) in rwsem.h (not rwbase_rt.h) - Add the rwsem_held_write() which returns true if the lock is already write-locked and no reader are around. - Make rw_base_is_write_locked() do the implementation specific (rw_base) writer check. - Replace the "inline" with __always_inline which was used before. Fixes: f70405afc99b1 ("locking: Add rwsem_assert_held() and rwsem_assert_held_write()") Reported-by: Clark Williams Signed-off-by: Sebastian Andrzej Siewior --- include/linux/rwbase_rt.h | 4 ++-- include/linux/rwsem.h | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/linux/rwbase_rt.h b/include/linux/rwbase_rt.h index 29c4e4f243e47..f2394a409c9d5 100644 --- a/include/linux/rwbase_rt.h +++ b/include/linux/rwbase_rt.h @@ -31,9 +31,9 @@ static __always_inline bool rw_base_is_locked(const struct rwbase_rt *rwb) return atomic_read(&rwb->readers) != READER_BIAS; } -static inline void rw_base_assert_held_write(const struct rwbase_rt *rwb) +static __always_inline bool rw_base_is_write_locked(const struct rwbase_rt *rwb) { - WARN_ON(atomic_read(&rwb->readers) != WRITER_BIAS); + return atomic_read(&rwb->readers) == WRITER_BIAS; } static __always_inline bool rw_base_is_contended(const struct rwbase_rt *rwb) diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h index 4f1c18992f768..c81630d81018d 100644 --- a/include/linux/rwsem.h +++ b/include/linux/rwsem.h @@ -167,14 +167,19 @@ static __always_inline int rwsem_is_locked(const struct rw_semaphore *sem) return rw_base_is_locked(&sem->rwbase); } -static inline void rwsem_assert_held_nolockdep(const struct rw_semaphore *sem) +static __always_inline void rwsem_assert_held_nolockdep(const struct rw_semaphore *sem) { WARN_ON(!rwsem_is_locked(sem)); } -static inline void rwsem_assert_held_write_nolockdep(const struct rw_semaphore *sem) +static __always_inline bool rwsem_held_write(const struct rw_semaphore *sem) { - rw_base_assert_held_write(sem); + return rw_base_is_write_locked(&sem->rwbase); +} + +static __always_inline void rwsem_assert_held_write_nolockdep(const struct rw_semaphore *sem) +{ + WARN_ON(!rwsem_held_write(sem)); } static __always_inline int rwsem_is_contended(struct rw_semaphore *sem) -- 2.43.0