From nobody Thu Feb 12 20:14:54 2026 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.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 8379D1D5CEE for ; Sat, 4 Jan 2025 21:16:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736025368; cv=none; b=ov0xVt2xpjWOaLtQeMwx5/ol+MFv0jFIYDIE3WmY5CURoNy0gv8g43qDbKDOpeqWuL4S2xxzNhiJEYXbP6QMS6FWX6L1YaSr8DZvsaKIyx9NRL32allcWVxtHzumdfhNTwMXCe0alB8kdj9hEaBPjdNN3BsnFK7lCSr4YUHrrGI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736025368; c=relaxed/simple; bh=DYU5AoJFN88QPgDHNfxcw0BVy8MieTaaGFGqDOAKSrQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QabCcox4TdPMccLII4lfWC6a9PQs4WX06X6hpH8tCgnGxJro/ryeHSeyVy8oNhqRdQTms1ZbtQG6JQcrIY7K48PSTayThi40T3lMpHgex+AStkVhV1u2czTbEVhJUkaXd1mMs+INfQYP4sFB6pzoy4lRgOpEVYxrfA4rRFBee4s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=colorfullife.com; spf=pass smtp.mailfrom=colorfullife.com; dkim=pass (2048-bit key) header.d=colorfullife-com.20230601.gappssmtp.com header.i=@colorfullife-com.20230601.gappssmtp.com header.b=aFVxSd+9; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=colorfullife.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=colorfullife.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=colorfullife-com.20230601.gappssmtp.com header.i=@colorfullife-com.20230601.gappssmtp.com header.b="aFVxSd+9" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-388cae9eb9fso7165395f8f.3 for ; Sat, 04 Jan 2025 13:16:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=colorfullife-com.20230601.gappssmtp.com; s=20230601; t=1736025363; x=1736630163; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gyr/eOHsgmSVZnniBJlKIc3iYrLLHuoPpsr0i9Z8NYs=; b=aFVxSd+9V+AcWQNM9IkJiCbzjTcVn/fkwZ69dGf3fZvq+qoCj/owq+Uu+3SHEJ/RAo rUHq8b10WCyXM3QS/pZ3v3Ds/xVqBOJyOtyZst4Tl3QBCEZNLjFdRhXrC4zmrukW2Gsg SHzm3Jl19Mpvm9fySd6oXqJJ0LeLp17duDqmqy7ey2q9i8U1A8Vs30r/AyVgqtcZz+cK DqlamlV2/rFJ66Re/5YwklnRPXfe9iwVdL0MbDVaBv6xUpqiL0Ag0Zwio8Pw9LbQX5dk tNxTJYTN/tyKZixoF0pCRCnSduhvh3WsrHxDB+QlVj7AAmJ4uakE/6d+Mz02VeYrsBLr CsaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736025363; x=1736630163; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gyr/eOHsgmSVZnniBJlKIc3iYrLLHuoPpsr0i9Z8NYs=; b=OPfxVFRJ3SJJsem3P5o2HFST4crSoRgZwys9hBMHI1y5Hgcrz73uwFKKV94Gt8apoa T2K5xfYLzFXjvlkgenZlKbwdUfZbCrw2NSEiNgUd6R6ZRsaVXhb+xaci5n/JtXG1uRGm WWByznJKhTOXQTvUWKEGcQHs1ZSiBxDrAZA6qyMN1oM9Oo3dVJdGulUZCwaRxjJilV9T eiWYIPHfU8rCqfGhdNm5CAj+ngzbeZGO9dHJ/w+RxytGNSCB7kPgtgqHZHXBGqxL2hgB RJB/IfR2fOsCBD0QM+h9SQcopybjNB04/zMzx4ewWsENncTSu0Falf/xlMMqqzPeTOpu 9F0g== X-Forwarded-Encrypted: i=1; AJvYcCXGkzffca2dWrsssa6H0dsMsLHD3okuh2QGcQ03OAb3yD00Iiv9jzDdatz4xSKF3MiKBffZ2wekk1843fQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxPtQP7ZQJyBoQkARBAIyRP2paf5YIx6UM19aJ4gT6blI0AsLrA BliqJ7YYCQ9CQRVrMFu7NbYa1qNB+g/98mtzuRI7in1ggZ6z3NGAE2tbtJZ+Gg== X-Gm-Gg: ASbGncuvj6iGf2+zBe4uwApjosCIFaDwggXNmUHoVAkU76eVTQRorSf+XVKEZDDNbDb SW3fo0KbY7Xnhf97AFCwDZARJsEV20Uxteq2emlwpqIgTcXM6lI6gIvHAbdLMX2StOegxKvGze/ 1O43JJ6mJ8/gh+8ISbxtHNxletbPzyEAkGiFfjkUVaW4M95HoBqeTzbCVQm4CYG5xT3hpd906U5 vrOW37UZRzXDkPsybFG6l0TCFG4erXH2eeMJaTbU/yMQR/KHWbNXI4mbtKCWBUx1C9YXLHW7vOQ 6gHu20/YAvLYHurAdjw59VIugpNoUoA85TqP1JCY+gBbv9KLddbuo77MvtQ2P8QY X-Google-Smtp-Source: AGHT+IHiI9NKb62RzTDNVCW3aL8W1D6GUC+nkKfpURYeEe95xovPEND/d+FNloiqr8u+h5iZCIi17w== X-Received: by 2002:a5d:6da1:0:b0:386:4a0c:fe17 with SMTP id ffacd0b85a97d-38a2220039fmr43957061f8f.27.1736025362594; Sat, 04 Jan 2025 13:16:02 -0800 (PST) Received: from localhost.localdomain (p200300d9973d88005833f4708c0fe0a2.dip0.t-ipconnect.de. [2003:d9:973d:8800:5833:f470:8c0f:e0a2]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-38a67c77a90sm5935667f8f.54.2025.01.04.13.16.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Jan 2025 13:16:01 -0800 (PST) From: Manfred Spraul To: Oleg Nesterov Cc: Joe Perches , Linus Torvalds , WangYuli , linux-fsdevel , Linux Kernel Mailing List , Christian Brauner , 1vier1@web.de, Manfred Spraul Subject: RFC: Checkpatch: Introduce list of functions that need memory barriers. Date: Sat, 4 Jan 2025 22:15:54 +0100 Message-ID: <20250104211554.20205-1-manfred@colorfullife.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241230153844.GA15134@redhat.com> References: <20241230153844.GA15134@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" (depending on output of the discussion in https://lore.kernel.org/lkml/20250102163320.GA17691@redhat.com/T/#u It does not make sense to change it now, but I do not see a reason to single out waitqueue_active(). The code is copy&paste, it seems to work. There is already a recommendation for spin_is_locked() ) 2nd spinoff from the fs/pipe discussion, and ortogonal to both the initial topic (use waitqueue_active()) and the 2nd topic (do not wake up writers if the pipe is not writable) Memory barriers must be paired to be effective, thus it is mandatory to add comments that explain the pairing. Several functions depend on the caller to take care of this. There is already a request to add a comment for waitqueue_active(), but there are further comparable functions: wq_has_sleepers(): No barrier is needed if the function is paired with prepare_to_wait(). With add_wait_queue(), a barrier is needed after the add_wait_queue() call. - spin_is_locked(): the ACQUIRE barrier from spin_lock() is on the load, not on the store. Thus spin_is_locked() may return false even though the lock is already taken. Avoid to use it outside of debug code. (and, for completeness) - waitqueue_active(): Usually, a memory barrier before the call is needed, and if add_wait_queue() is used, also a barrier after add_wait_queue. See wait.h for details. - Signed-off-by: Manfred Spraul --- scripts/checkpatch.pl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 9eed3683ad76..8bf5849ee108 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -6685,11 +6685,17 @@ sub process { "__smp memory barriers shouldn't be used outside barrier.h and asm= -generic\n" . $herecurr); } =20 -# check for waitqueue_active without a comment. - if ($line =3D~ /\bwaitqueue_active\s*\(/) { +# check for functions that are only safe with memory barriers without a co= mment. + my $need_barriers =3D qr{ + waitqueue_active| + wq_has_sleeper| + spin_is_locked + }x; + + if ($line =3D~ /\b(?:$need_barriers)\s*\(/) { if (!ctx_has_comment($first_line, $linenr)) { - WARN("WAITQUEUE_ACTIVE", - "waitqueue_active without comment\n" . $herecurr); + WARN("NEED_MEMORY_BARRIERS", + "function that usually depend on manual memory barriers without c= omment\n" . $herecurr); } } =20 --=20 2.47.1