Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp590392lqp; Fri, 5 Apr 2024 03:05:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXry7WaWCDJ0ORYF6J7peyS/YQyBxaldY4YBb7Du9ma2i/ducuIAL8JjwxBkroO62LOCuQB2fYa3oniD95Bn2m4F8y1naWlzS5GykN72w== X-Google-Smtp-Source: AGHT+IG8oeRnnbhYwkYifAXXR9KQFwseFCrYaLQz0ps8SehI2fSHJBnddtjqFKG7odEnovTeV54/ X-Received: by 2002:a17:906:bc50:b0:a4e:2d1e:6914 with SMTP id s16-20020a170906bc5000b00a4e2d1e6914mr723744ejv.11.1712311529565; Fri, 05 Apr 2024 03:05:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712311529; cv=pass; d=google.com; s=arc-20160816; b=nqB9FDVTUlMdQpG+URgd31BDfxK4cWYDHTlsWLwi6oKrfUmx1xjkiWLoKfzgsO/Jrb JQohsu1zqSuCGFzs4Tw5ZjuAdymw0FzvThotO1CF/epkrTdhwVUG9LWvlTsOkIT0ddiO H61NNP/YaZZyzXkAEPMaK3IX07LUs2ULA+3GKnHMRgtjQvwuaq//KLs8v0KaZVL6n8xE O+GPl8HOKDlVf2kQ6cuofSZN2Z563vr5ElAuRGkbrbMKFqBGEZPZ7xQDd+BnuvFus4Lm Kjt6Z1Su81PmFeuJPjcxfwq9uS56bUS6MxZ123ul/GF/CyP6sIrbg3gcP5nbofU6PPiQ 2BTQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=7VnK8I425dCI37ex6fueoi4IBtnoCCvi/FqHwWJZqFc=; fh=H98NbjcI+jDtyNo+yraapdRoy6NjQClKWcuGbA20ndk=; b=dgJHbbzQv/IhSxXC/Mx9l9TnPFIehlye6v29jmOGBShKOkKhy4UdUD+1jyV8uZRM07 y3iPhuWZs2yEmB3cibRKmhWpKKQASFIFdC9wm5ljjpeZgN//nzKrvY6Pie1aZL19AeXP rwQSb44myvp+SCrCPbWqsTgsWQEPgSYsk8cYWZr96dE+6FkKlLC0rXttcqOpaddb072t /OdZ/Bm0mua7JdICCX8yIZIy45AyG0HROV1XMjyIAxjzhTZZpNA9Tb3NGTVLHRDGNrNC hJr3761uL8HeljI2L3UK6M+O1UqeboTQpdbwna7RTQIV2fl8/E6UcBR9pIfQXaC8dxDw EeQw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QGZzqsqC; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-132789-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132789-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id lv6-20020a170906bc8600b00a4e34255b09si549980ejb.306.2024.04.05.03.05.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 03:05:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-132789-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QGZzqsqC; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-132789-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132789-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 24B061F22FAA for ; Fri, 5 Apr 2024 10:05:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7654A16133D; Fri, 5 Apr 2024 10:05:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QGZzqsqC" Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 D970F27447; Fri, 5 Apr 2024 10:05:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712311521; cv=none; b=HSPiC6D000hitAH+kLRdA/titRX5PVg+AMCzW2HDph7VMYwF1MNbIWU6r2Fv60+x+PRimm0zBQL1z2S/dTDKgcbQkb9qWxoN4W/N53pkYESVngYw7uy9MRVCZaTepy3JWVTd3PwgvO/3WP+z8RkwPSEQsgBabb67W1SLG4RXwPA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712311521; c=relaxed/simple; bh=7kM1F19yoDOcUM2VHaBFp2c+soyX1IiwreAYmFx4a+s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fmfnQMP5B+7IySTDet8N7EDNMzESVclg6Zx5WDFUbzUqRj9P9huJY4w97OD2RW5/fhk857H/CIyKscwQavk9zWuoo4vhz7YI3gxiWxKbTZs6mVdd2V5k4YAJF8MDJwFguEc5lksBV9pZqFut+mnrxdIEXckrJE5tRipUOBoeBI0= 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=QGZzqsqC; arc=none smtp.client-ip=209.85.128.50 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 Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-41551500a7eso15673425e9.2; Fri, 05 Apr 2024 03:05:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712311518; x=1712916318; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=7VnK8I425dCI37ex6fueoi4IBtnoCCvi/FqHwWJZqFc=; b=QGZzqsqCxu2dBhB7OPb9oJCfC2mXNgNvv91ZNtCLWEP9kcB6O5g/bSOim370Tiunq+ Ue/1YXAQkrVuwm+v/udWZCaFG+u0nAKo8wVu5/fBCgzkOd98QfngW8vPjmzsYxrvS1yl w0FgVwGTxGWXC4jfdmTfNgf39fr7wJeh1Eev4IVPhKjGBF+fbi+XSDm/uNwwcM4bObqL ZZPAk/zaoszYU/+Suw57lwGPP/IhN2+qPtQ9qoisvVZlcW5TIjQimw4hYSlsTsoa00eI am5QVAyz5hjbdGIFnZfoQozEgHbAroonT4uizCPEcgGxCP97FSQAztJ9tGGUKne6DgCB Mh8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712311518; x=1712916318; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=7VnK8I425dCI37ex6fueoi4IBtnoCCvi/FqHwWJZqFc=; b=cuzPeMQWGBzbl2p9kWb3pJoUs3xoMztaVLIKJEcRKI5lu8nAN+1fp2kFrEwC/WY7Cg 3drrhVE4Uxj7WAM38PioGIqCAIztwwzmcNtuQlWsuEADT10kufoZDvKjf5u0Ew6nGwhq msTLK3R0IJxX3py2BxGJ2pJm5nYjvV+wAOUnVIS6xTjZC6a1cPL9Ud59VgFrMdQ/Pkqy FiOwlT+G7/nLy/vxj6jDiPtHE3CLZzRJ0qyKDwiO2/MftHO5hNLKT8DXZl6sXHDN2a1c AQRnoY6zVPv0i1nBeO7kBYQim0j+uuBy7RtsE8hKH+p5He1kJ/e+CHJ3N3jV9Jzss+Y/ mkrQ== X-Forwarded-Encrypted: i=1; AJvYcCVlBQvvpu2rj0GTNHqVaC7WtcvxpwZh22OKVpKoLBAR/rR9+u9b6+PldYWJgC1d33iMLD2q2FF0cSv2/EoU0DY6CXcOcmtXgyYW9rp+irmfaenZuNUV14xAd+goKZ7TmU4pY/QnXA== X-Gm-Message-State: AOJu0YxRAZCK5EsfFJgSfsh3Db6eggvK/jEsJDiCY2o1tsoHsNBO63+n jPFIptxXp7BnXKPA8a2J8TIzadjYup/MprfgCaBbl6Jf/sI6+/M6 X-Received: by 2002:a05:600c:4e4a:b0:415:63df:6513 with SMTP id e10-20020a05600c4e4a00b0041563df6513mr746663wmq.39.1712311517988; Fri, 05 Apr 2024 03:05:17 -0700 (PDT) Received: from andrea ([31.189.25.240]) by smtp.gmail.com with ESMTPSA id m13-20020a05600c4f4d00b00416326cc353sm310063wmq.8.2024.04.05.03.05.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 03:05:17 -0700 (PDT) Date: Fri, 5 Apr 2024 12:05:11 +0200 From: Andrea Parri To: "Paul E. McKenney" Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, kernel-team@meta.com, mingo@kernel.org, stern@rowland.harvard.edu, will@kernel.org, peterz@infradead.org, boqun.feng@gmail.com, npiggin@gmail.com, dhowells@redhat.com, j.alglave@ucl.ac.uk, luc.maranget@inria.fr, akiyks@gmail.com, Frederic Weisbecker , Daniel Lustig , Joel Fernandes , Mark Rutland , Jonathan Corbet , linux-doc@vger.kernel.org Subject: Re: [PATCH memory-model 2/3] Documentation/litmus-tests: Demonstrate unordered failing cmpxchg Message-ID: References: <8550daf1-4bfd-4607-8325-bfb7c1e2d8c7@paulmck-laptop> <20240404192649.531112-2-paulmck@kernel.org> 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=us-ascii Content-Disposition: inline In-Reply-To: <20240404192649.531112-2-paulmck@kernel.org> > DCL-broken.litmus > - Demonstrates that double-checked locking needs more than just > - the obvious lock acquisitions and releases. > + Demonstrates that double-checked locking needs more than just > + the obvious lock acquisitions and releases. > > DCL-fixed.litmus > - Demonstrates corrected double-checked locking that uses > - smp_store_release() and smp_load_acquire() in addition to the > - obvious lock acquisitions and releases. > + Demonstrates corrected double-checked locking that uses > + smp_store_release() and smp_load_acquire() in addition to the > + obvious lock acquisitions and releases. > > RM-broken.litmus > - Demonstrates problems with "roach motel" locking, where code is > - freely moved into lock-based critical sections. This example also > - shows how to use the "filter" clause to discard executions that > - would be excluded by other code not modeled in the litmus test. > - Note also that this "roach motel" optimization is emulated by > - physically moving P1()'s two reads from x under the lock. > + Demonstrates problems with "roach motel" locking, where code is > + freely moved into lock-based critical sections. This example also > + shows how to use the "filter" clause to discard executions that > + would be excluded by other code not modeled in the litmus test. > + Note also that this "roach motel" optimization is emulated by > + physically moving P1()'s two reads from x under the lock. > > - What is a roach motel? This is from an old advertisement for > - a cockroach trap, much later featured in one of the "Men in > - Black" movies. "The roaches check in. They don't check out." > + What is a roach motel? This is from an old advertisement for > + a cockroach trap, much later featured in one of the "Men in > + Black" movies. "The roaches check in. They don't check out." > > RM-fixed.litmus > - The counterpart to RM-broken.litmus, showing P0()'s two loads from > - x safely outside of the critical section. > + The counterpart to RM-broken.litmus, showing P0()'s two loads from > + x safely outside of the critical section. AFAIU, the changes above belong to patch #1. Looks like you realigned the text, but forgot to integrate the changes in #1? > +C cmpxchg-fail-ordered-1 > + > +(* > + * Result: Never > + * > + * Demonstrate that a failing cmpxchg() operation will act as a full > + * barrier when followed by smp_mb__after_atomic(). > + *) > + > +{} > + > +P0(int *x, int *y, int *z) > +{ > + int r0; > + int r1; > + > + WRITE_ONCE(*x, 1); > + r1 = cmpxchg(z, 1, 0); > + smp_mb__after_atomic(); > + r0 = READ_ONCE(*y); > +} > + > +P1(int *x, int *y, int *z) > +{ > + int r0; > + > + WRITE_ONCE(*y, 1); > + r1 = cmpxchg(z, 1, 0); P1's r1 is undeclared (so klitmus7 will complain). The same observation holds for cmpxchg-fail-unordered-1.litmus. > + smp_mb__after_atomic(); > + r0 = READ_ONCE(*x); > +} > + > +locations[0:r1;1:r1] > +exists (0:r0=0 /\ 1:r0=0) > +C cmpxchg-fail-ordered-2 > + > +(* > + * Result: Never > + * > + * Demonstrate use of smp_mb__after_atomic() to make a failing cmpxchg > + * operation have acquire ordering. > + *) > + > +{} > + > +P0(int *x, int *y) > +{ > + int r0; > + int r1; > + > + WRITE_ONCE(*x, 1); > + r1 = cmpxchg(y, 0, 1); > +} > + > +P1(int *x, int *y) > +{ > + int r0; > + > + r1 = cmpxchg(y, 0, 1); > + smp_mb__after_atomic(); > + r2 = READ_ONCE(*x); P1's r1 and r2 are undeclared. P0's r0 and P1's r0 are unused. Same for cmpxchg-fail-unordered-2.litmus. Andrea