Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp139213ybk; Fri, 8 May 2020 21:37:52 -0700 (PDT) X-Google-Smtp-Source: APiQypJCq7Jf17Dk8i0iVwiZaK1GHRuLWhMjEAxX3hYd2Q1keJbzJ9RrIUVpzQSrdqdQEMQpEW7Y X-Received: by 2002:a50:d615:: with SMTP id x21mr4581604edi.62.1588999072117; Fri, 08 May 2020 21:37:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588999072; cv=none; d=google.com; s=arc-20160816; b=R1wt/Pudm0pSMWVIYQNMcltgwAEz6kXBaA/1bw+Vt7ocxjhsKHq0yz4i4svenoSTp7 5GHezptnI+6vzxy7pa2EZc/kh13uCEdJ2gpj0yqHNbZtUoxLwe/9uLVIs6VBeK7tUeWw 5LISEtd/sOBxsNXBd3/Co6iQdTscI8AAo5r8PXtaZR9y9TFHtPQSloTc+tOBp04B5Q2W D1upcdvmeWSIoMhVVEmrtnpyuXZh0w95YSrIIRx/qVnHfVVGSxGLMODJzOQ920QggNR5 VXp4AASWZOM/MM7sOwKAqZK0Rw1x+9wZ2S6SrSKhwSpBts2MuQ3VxZ9pVbAaTwzjshxO B6kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=/93wdZyH2GNlkYadpJXNnOqIZqn5d8xjcuXtciBzY8Y=; b=CXnq9uMgpLVLUsD4ZVkMHluORWoVFxiuOD1i7nwcKvkf0QrrON0e1sPT32f1PR2u3i lVPBo6ZT+IuBNqWNTDeYAaHGx6AoDpscqHps5E6KCa3vRpfX1wQvwlCUeet7AneaEy3b HlJhOouNCcSf4RnUK+wN+1ucLJgbuiROpFlik3RylRmJczge4KlXbq4shegMYTUD0UE0 pkv+lx9YjIcioshMejJjbkBzYURiu2+STxHzN+4jzCQMcj1OEPX43+HkgbZYii2exGSG B/+nJPwMTeTw+y2kV5Dw22swOMMEeoBxMVpu5ytdJB7I90sPNyZjjehlX8s0e/ASVdOS JlIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=F5+NMPaG; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d6si2259444edy.66.2020.05.08.21.36.58; Fri, 08 May 2020 21:37:52 -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=@kernel.org header.s=default header.b=F5+NMPaG; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725987AbgEIEdJ (ORCPT + 99 others); Sat, 9 May 2020 00:33:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:39070 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725795AbgEIEdI (ORCPT ); Sat, 9 May 2020 00:33:08 -0400 Received: from paulmck-ThinkPad-P72.home (50-39-105-78.bvtn.or.frontiernet.net [50.39.105.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5291020735; Sat, 9 May 2020 04:33:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588998788; bh=O04g/ed99TB3Q1nZ1fxfTeIntZZXj5bXO9bE+5e5nn0=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=F5+NMPaGYzuEyMVkGH22M/WOTFbi8m7oVsGmcdRL8rq9bixg1EYlEUOHuAWVMBws1 6vSdb+hshPWWKUh+T6nIF9o8KrmFZ1PvZicYk/HjLK/wIZjbSpf6QfImT8ALngqfEF gymPJLZBSF0gMYH/2bKmLy3O6SBTkcY6zp1Xkb6g= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 34A773523058; Fri, 8 May 2020 21:33:08 -0700 (PDT) Date: Fri, 8 May 2020 21:33:08 -0700 From: "Paul E. McKenney" To: Qian Cai Cc: Will Deacon , Elver Marco , LKML , Ingo Molnar , "Peter Zijlstra (Intel)" Subject: Re: [PATCH -next v2] locking/osq_lock: annotate a data race in osq_lock Message-ID: <20200509043308.GL2869@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <1581429255-12542-1-git-send-email-cai@lca.pw> <2C8BF141-5384-475F-B713-6D473557C65C@lca.pw> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2C8BF141-5384-475F-B713-6D473557C65C@lca.pw> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 08, 2020 at 04:59:05PM -0400, Qian Cai wrote: > > > > 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/ 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. Thanx, Paul > > --- > > > > 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 > > >