Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp58725ybk; Fri, 8 May 2020 14:01:10 -0700 (PDT) X-Google-Smtp-Source: APiQypKFQnrPzZtGp0oOWbsr598a0QchqFE7WRxqTRZIUqoBEyo5ZKZ3gOnYxdDIxm2Lk43RNMwu X-Received: by 2002:a17:906:1393:: with SMTP id f19mr3540643ejc.26.1588971669807; Fri, 08 May 2020 14:01:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588971669; cv=none; d=google.com; s=arc-20160816; b=zoWBjI+L1ZiL90ZuPsRBGhxZm18w842KGUGjXXuRKdA3eXbO/sT+aYLpoqfkB8h322 kghftuNqLas00/vHQsiTtMMWnPC0aISV/hUwAV1sPFih3PXRxiWdQ1RdEsAI40BEIrBo nC1uRr1KI3n07DcZZJqjDbMNXqll8VKu4Pbvx3OGm7OKZf6GagSX+Hh2tDnBMNlOcuXP JJHTNz6cAulHebbaJEHznpJKs38v2gAnTN4e6voRa2UXAcbvXWcblyjYfGUaYH2rVI6X KC3MsKgsXCp7v0HOz//u01IRMqKdP02gHRI6Olvm414N0Sal3H7BJKBvWWe+HnXJcudy YVRA== 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=qinORr0SG7+11njGJ/ss7smA7LMvIKvcYCz/jRR8lPQ=; b=McSnkVjB3HwVH3zmUN4oR/k77AxZRYJQURku6MpwdXTYG8ZaXwjMCWuPy1hZcIZavM wBJnmaGrWEqkGEPhmtYbeb2FV7KsEKvxa1+535xOyEUd8IlPW2GLf7zngqVzfXAyM7GO udWST07mh4dKRyK7Ybwibo3PSGPsBAOr0H1iYsL2slgm6s0tLB6Ps+990GpoMlPtBJq4 p5xclq0JCBgco2IK7r3Q8kkfrQhrA6EbRX2HszKm6OE2A+WaQ4rBeC7YTziwLBMyXT6L Mr6ZYTmLIA9WnIzzi5yNVn7EQCk4Rt3WK8xzaVKR2wp2Rmg0nuloWmovatvSmHHqfHiF VlcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b="BzwRTp8/"; 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 x22si1552165eju.478.2020.05.08.14.00.42; Fri, 08 May 2020 14:01:09 -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="BzwRTp8/"; 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 S1727787AbgEHU7J (ORCPT + 99 others); Fri, 8 May 2020 16:59:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726811AbgEHU7J (ORCPT ); Fri, 8 May 2020 16:59:09 -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 F3326C061A0C for ; Fri, 8 May 2020 13:59:08 -0700 (PDT) Received: by mail-qk1-x744.google.com with SMTP id c64so3201279qkf.12 for ; Fri, 08 May 2020 13:59:08 -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=qinORr0SG7+11njGJ/ss7smA7LMvIKvcYCz/jRR8lPQ=; b=BzwRTp8/rzv8F0T2+rEdndgXdruIJ5jfa5qOyBo5ITWnod+C9DkmRjeFJU9yNgG1Ri PV2cd2sDwWDHt1oWL19KugIzj0H7DF4DI7a4CMnMPaesS7XTDfSQ8ddaSlwU/u/S3/cM zqIjNQ+q4kWOmOQ4oxSj+Gn7dSHh9eC2ZAmxYYQLWo5USDX+TWqKbLAFN/G/0YOh0lBF 9KRUCD1w7DryfpcJR/AvHbdDpq+rYxRNDg20EIfHb4YiPX2wPSUMV9LLL2H5p2mfnxBF Hzr4vJuWcu5B1D/oBBu+ZQ5BBft1aWtC4GF+U2g3M6SuvMm9g0sAq87WHErHRbJ008wU SshQ== 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=qinORr0SG7+11njGJ/ss7smA7LMvIKvcYCz/jRR8lPQ=; b=pgdaTVsh1qxoZJuMb5MBCER3NEIATGmdkLQbOQdU/1JX88OX3yHp+t+tcDf0TQz6dc IR6yYHt8ZnTB3Sre1AyciJkwm+TYImng6U7WRmOotPo5mw6EL/SiNkC/F5yNnRH38VoJ Q2QzyenJ4fYTdrniu9hwe+00G9I36DSf0WXqtCXSEPHndDDFgEvyGe4/n4AkozKQnVR7 Jguxj4uuurWXlLsOG8OYsWmXOMa7VUvZCX3tBpXMbWcWIyDTOwCioj6HvoTu4JUtd5tE dOa2gQlkIQzY2VB+qXIDjk4JpPPcpwRLjupHrCmnwhEPApwbwa0zzMH2Kwfew0Ivbpnj mtMQ== X-Gm-Message-State: AGi0PuZZzPaKTNBHrMFK6Ydf5DDEoNidEEsl3GqtscStycbIFwp7s7VR /e6PsQh9Z23UDR/Vu5MSRzK+eQ== X-Received: by 2002:a05:620a:13a7:: with SMTP id m7mr2699887qki.498.1588971547831; Fri, 08 May 2020 13:59:07 -0700 (PDT) Received: from [192.168.1.153] (pool-71-184-117-43.bstnma.fios.verizon.net. [71.184.117.43]) by smtp.gmail.com with ESMTPSA id 206sm2058974qki.48.2020.05.08.13.59.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 May 2020 13:59:07 -0700 (PDT) Content-Type: text/plain; charset=us-ascii 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: <1581429255-12542-1-git-send-email-cai@lca.pw> Date: Fri, 8 May 2020 16:59:05 -0400 Cc: Will Deacon , Elver Marco , LKML , Ingo Molnar , "Peter Zijlstra (Intel)" Content-Transfer-Encoding: 7bit Message-Id: <2C8BF141-5384-475F-B713-6D473557C65C@lca.pw> References: <1581429255-12542-1-git-send-email-cai@lca.pw> 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 Feb 11, 2020, at 8:54 AM, Qian Cai wrote: > > prev->next could be accessed concurrently as noticed by KCSAN, > > 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 > > > 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 > > > 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. > > Signed-off-by: Qian Cai Hmm, this patch has been dropped from linux-next from some reasons. Paul, can you pick this up along with KCSAN fixes? https://lore.kernel.org/lkml/1581429255-12542-1-git-send-email-cai@lca.pw/ > --- > > v2: insert some code comments. > > kernel/locking/osq_lock.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > 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) > */ > > for (;;) { > - if (prev->next == node && > + /* > + * cpu_relax() below implies a compiler barrier which would > + * prevent this comparison being optimized away. > + */ > + if (data_race(prev->next == node) && > cmpxchg(&prev->next, node, NULL) == node) > break; > > -- > 1.8.3.1 >