Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp387825ybk; Sat, 9 May 2020 06:04:13 -0700 (PDT) X-Google-Smtp-Source: APiQypJ3UflxSmb7AcI5MsoGR2h0xI3IkdkzZVtvfDUmEoSFQIi2WR5hp8QrVADkm/D2YZvHaWoe X-Received: by 2002:a17:906:4907:: with SMTP id b7mr5622682ejq.279.1589029453527; Sat, 09 May 2020 06:04:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589029453; cv=none; d=google.com; s=arc-20160816; b=nshiCoqe/ubE6nrDEEwaQU7Lo93C/P6irTkZKjfLB+n6+xDHM4GVQXFG+TJsEdHKGs HjBvJisg/900r9SaYMWMHsKt9cEe7hh/FjwmGy8qv9OhvK6HPrUMRNVllrV1YTBxPh5o 2H+Gr+ZkoYy3PhYXmBy2ZGlJxnWy83nCwU1Lc0XhLnTfn2RueYxo+tIadfOhw1FiXh65 vIlxC4/jiVtSUrQ+tuPw+mE8bD0wn8a5zQ+0oieVzs/hGkVpFqjt1YQuOhvag1MvD4YC T9Zn4PC9PS8veTKecVAQ1zh81l7r26fs9OjNQsieaflCLZY8vlJmWhJE9VQZyeE30yb7 3kpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=jTuvTs2BUGfgevsdxkTl5Pz0n3BVDsnYhNL9VJKSs9o=; b=C5EpBMb1GOTZdB9Pea4HvDEQr603cJxQ/81pWHpr4t/+h7CED9QE56cnNPpy3HocPq qrv3RYNxy9Zk56mbdntinW2cpJaDQqFx5F9hCBUAWcJZi7ZFZlRLHpFcG96Fg7CeREBv k4oCAGZ3NYVNulz+zGFZ4/r0yKVX/jfXZ5GGHtFEXtgfo/2Zav/3wwCzjyBztonAG9SD dybfRju12fYfdHtcyMzTzIS+Af+OjRxMfTIWxOq6bFpxKweWfXM+DVd4e+zR1Hxlk1OU 6miZlkL0UlS+H/0VSgu94GwME8/XWr96N0eDPhMF8hVWOwjuUWYDly9ddzoh7jgP5USZ CHEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=JomB970a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id me3si2662195ejb.250.2020.05.09.06.03.44; Sat, 09 May 2020 06:04:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=JomB970a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727777AbgEINB4 (ORCPT + 99 others); Sat, 9 May 2020 09:01:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726370AbgEINB4 (ORCPT ); Sat, 9 May 2020 09:01:56 -0400 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1102DC061A0C for ; Sat, 9 May 2020 06:01:56 -0700 (PDT) Received: by mail-qk1-x744.google.com with SMTP id t3so4426524qkg.1 for ; Sat, 09 May 2020 06:01:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=jTuvTs2BUGfgevsdxkTl5Pz0n3BVDsnYhNL9VJKSs9o=; b=JomB970amfbS7tlmVt6Zk1DINDaC0AXdo6I2BycPXku8wEExjHK8J+LlTQPExHIrvs 6vxm4SsS8vQsChgochARhojcSgstz0+4p4VQfm8SJRUawUXPc4UkmKDl4w0MsrlzdNG2 w3Sd1qIktLEary+Oi7JpzA+VqnRI7N8G9sjpjgJ7kCZ6IMFvXKMICL/igec9kgRGLwFY FxwSAr0PJusFCUILo+7PEpfk1cwrRl9Vd1j/unXRc3t0RDM4u73eaZ+rZud2AXASZagY c+BoatdL4ncmyL1n1voA85i4RUo01v6tAIo0+JNJmrUiPjay51hWuM4feexL7PNuWCmu 5U0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=jTuvTs2BUGfgevsdxkTl5Pz0n3BVDsnYhNL9VJKSs9o=; b=JiI9xjylJIX71mAtoL74DZg21aglEjQ6Vz8RHngQLgnnAno2iUXxzqRWXORXdiTMUt tpOkTMZiXY9Ms0yXz4eTY1OUr8qFh7QBkVWY/eQZ1NAZuLdEnf1s7zjf8HMbPDj5Ao+s Av7bEP20WopZyrsYs3EiZWKT3Q6yTNxdJvhf0sSXC9kl2QmXOfi479iMso/GqwX/w86F Zs1PiZISFVspLMkBbJTet5h9K4jTZ8ZGkElPY+EwZiaJ8TFo1fbb7i3K75pBHqOVL/Sy W4HCXL7BFUKZpgoDxYPsdJiDbKBba4UNaZs0EKRXAU+oLT06APup9PkxHOT7h1jeFSvI FJjA== X-Gm-Message-State: AGi0PuZ9vaJvRXUkeiMLhoEP5MYu5mMMMordjGcUHvOPfOjGxDDhEqG3 HC5glc5k4YqbhO/FBaY2FgmqzYvnP8jT4w== X-Received: by 2002:ae9:dfc6:: with SMTP id t189mr6651875qkf.15.1589029315093; Sat, 09 May 2020 06:01:55 -0700 (PDT) Received: from qians-mbp.fios-router.home (pool-71-184-117-43.bstnma.fios.verizon.net. [71.184.117.43]) by smtp.gmail.com with ESMTPSA id c197sm3555474qkg.133.2020.05.09.06.01.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 09 May 2020 06:01:54 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) Subject: Re: [PATCH -next v2] locking/osq_lock: annotate a data race in osq_lock From: Qian Cai In-Reply-To: <20200509043308.GL2869@paulmck-ThinkPad-P72> Date: Sat, 9 May 2020 09:01:53 -0400 Cc: Will Deacon , Elver Marco , LKML , Ingo Molnar , "Peter Zijlstra (Intel)" Content-Transfer-Encoding: quoted-printable Message-Id: <9FBC2A17-2821-49F7-9A0F-5E41116BBC70@lca.pw> References: <1581429255-12542-1-git-send-email-cai@lca.pw> <2C8BF141-5384-475F-B713-6D473557C65C@lca.pw> <20200509043308.GL2869@paulmck-ThinkPad-P72> To: "Paul E. McKenney" X-Mailer: Apple Mail (2.3608.80.23.2.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On May 9, 2020, at 12:33 AM, Paul E. McKenney = wrote: >=20 > On Fri, May 08, 2020 at 04:59:05PM -0400, Qian Cai wrote: >>=20 >>=20 >>> On Feb 11, 2020, at 8:54 AM, Qian Cai wrote: >>>=20 >>> prev->next could be accessed concurrently as noticed by KCSAN, >>>=20 >>> write (marked) to 0xffff9d3370dbbe40 of 8 bytes by task 3294 on cpu = 107: >>> osq_lock+0x25f/0x350 >>> osq_wait_next at kernel/locking/osq_lock.c:79 >>> (inlined by) osq_lock at kernel/locking/osq_lock.c:185 >>> rwsem_optimistic_spin >>> >>>=20 >>> read to 0xffff9d3370dbbe40 of 8 bytes by task 3398 on cpu 100: >>> osq_lock+0x196/0x350 >>> osq_lock at kernel/locking/osq_lock.c:157 >>> rwsem_optimistic_spin >>> >>>=20 >>> Since the write only stores NULL to prev->next and the read tests if >>> prev->next equals to this_cpu_ptr(&osq_node). Even if the value is >>> shattered, the code is still working correctly. Thus, mark it as an >>> intentional data race using the data_race() macro. >>>=20 >>> Signed-off-by: Qian Cai >>=20 >> Hmm, this patch has been dropped from linux-next from some reasons. >>=20 >> Paul, can you pick this up along with KCSAN fixes? >>=20 >> = https://lore.kernel.org/lkml/1581429255-12542-1-git-send-email-cai@lca.pw/= >=20 > I have queued it on -rcu, but it is too late for v5.8 via the -rcu = tree, > so this is v5.9 at the earliest. Plus I would need an ack from one of > the locking folks. Peter, Will, can you give an ACK? This v2 should incorporate all the = feedback from Peter, = https://lore.kernel.org/lkml/20200211124753.GP14914@hirez.programming.kick= s-ass.net/ V5.9 is fine. All I care about is it is always in linux-next (so the = testing bots won=E2=80=99t trigger this over and over again) and to be = in mainline at some point in the future. >=20 > Thanx, Paul >=20 >>> --- >>>=20 >>> v2: insert some code comments. >>>=20 >>> kernel/locking/osq_lock.c | 6 +++++- >>> 1 file changed, 5 insertions(+), 1 deletion(-) >>>=20 >>> diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c >>> index 1f7734949ac8..f733bcd99e8a 100644 >>> --- a/kernel/locking/osq_lock.c >>> +++ b/kernel/locking/osq_lock.c >>> @@ -154,7 +154,11 @@ bool osq_lock(struct optimistic_spin_queue = *lock) >>> */ >>>=20 >>> for (;;) { >>> - if (prev->next =3D=3D node && >>> + /* >>> + * cpu_relax() below implies a compiler barrier which = would >>> + * prevent this comparison being optimized away. >>> + */ >>> + if (data_race(prev->next =3D=3D node) && >>> cmpxchg(&prev->next, node, NULL) =3D=3D node) >>> break; >>>=20 >>> --=20 >>> 1.8.3.1