Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5040757ybl; Wed, 22 Jan 2020 09:11:32 -0800 (PST) X-Google-Smtp-Source: APXvYqxD9P9JFnkLYy+xtlzg1uK+cD89NYLeWRcX9sU0Ct5sT/rzFD3vRUC4KbFLeII54790E4nI X-Received: by 2002:a9d:6196:: with SMTP id g22mr8352470otk.204.1579713092037; Wed, 22 Jan 2020 09:11:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579713092; cv=none; d=google.com; s=arc-20160816; b=iTC0u/9e9vZ1IWURtdwRbOISIWs8sOyuIspqbKjtpjpGaaRibexat2xzZ18d/fkfFv I7PMwTOcPtIOtvIaXX2ocrOakmw3uUc0ykERvSWbWheuLmtsFdJF90dp50KzqOE7dLHQ gTHwuaTJ9OfVR8PJP7NebIdY+Dq7wDG/YZ14+5ricvjn7uvzxh0ZfYPBAAaEk6tCdlFj 9qebSN9PbqOOw7goue4YZ24TKqA2jpDn0yxVdQi936TafOoUKbSeoMU5wJzS3tZ1FLFL vzNNZCa0L4Zfnasek7gla9/8jgaZXwKmyaOX1S+AFzHdqphGFPUUig0LSHGEDCivQjhk Mo7w== 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:message-id:subject:cc :to:from:date:dkim-signature; bh=H41vAC6tCQoCgyqVrd/aoqOng0EACXvJHnhie2BBbxs=; b=yZpQBwDRKirxTRb5ViNGfIKEU5I5msVhZl3sXTJOaCMBoPJZ/lIWSEm4ekR3rd0XLB z9mfCNjsiCbqT3eK/2bwQaI6NjMe7wuqfYxXlwBgDqX4CJKaRIJodP/yXxQEfZ6yw+3Q tjF/RTIjh1WGlWPlhL5eUu7MufVX70d7njDe4ChiNS2eKbtWKOMha0hE8Rm59O2L216C eMWj67my39UEfiYV0Gyh1Yh8Pqf/YOnKNzFh71S+UzYvBV0vOPP23aSEfp+bvTD3w2uU CltndacO5YjzE902a4fka0SoucxBWf8Ckgi9UmGH6O1qQKi8lXZQZDu5o5qrPGANRUbd evNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=lpFA08sr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z1si24482873otq.21.2020.01.22.09.11.18; Wed, 22 Jan 2020 09:11:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=lpFA08sr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728816AbgAVRJu (ORCPT + 99 others); Wed, 22 Jan 2020 12:09:50 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:39942 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725802AbgAVRJu (ORCPT ); Wed, 22 Jan 2020 12:09:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=H41vAC6tCQoCgyqVrd/aoqOng0EACXvJHnhie2BBbxs=; b=lpFA08srx/a08vn7Z2cOK+dBm B4hCoXMx/GECzcK00sFT21MD4rAVwG9MQ9GgrArzAWDlCkj0FqAibxVZxE1ejC0lqa65GIvVDSb69 8Rw+bzy7teRrJsv5W4ZqaJIoup5yWeLBo2x8fwrDB/+bIkc4TPgjhca1SNFnSmhiZxX3qI7F8yrK3 lqt91rEduGnbLYZ024dgyUicOERWp1S+k29iztYhnX7eqRvhBZElJvLIEy8c0entD16/XuRcZ8+8v 2xCDCqCNdO3AyxQPyV4krFYi3oJnZvGIe9I5NLlW1NlVm2LIhqB2t2sVzO2ycUUYRBEzlwjzw5iWU 82442y+hQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1iuJVi-0005pY-R8; Wed, 22 Jan 2020 17:09:47 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 3F84E30067C; Wed, 22 Jan 2020 18:08:05 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id E0E192B7249AA; Wed, 22 Jan 2020 18:09:44 +0100 (CET) Date: Wed, 22 Jan 2020 18:09:44 +0100 From: Peter Zijlstra To: Qian Cai Cc: mingo@redhat.com, will@kernel.org, elver@google.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] locking/osq_lock: fix a data race in osq_wait_next Message-ID: <20200122170944.GZ14879@hirez.programming.kicks-ass.net> References: <20200122163857.4605-1-cai@lca.pw> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200122163857.4605-1-cai@lca.pw> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 22, 2020 at 11:38:57AM -0500, Qian Cai wrote: > KCSAN complains, > > write (marked) to 0xffff941ca3b3be00 of 8 bytes by task 670 on cpu 6: > osq_lock+0x24c/0x340 > __mutex_lock+0x277/0xd20 > mutex_lock_nested+0x31/0x40 > memcg_create_kmem_cache+0x2e/0x190 > memcg_kmem_cache_create_func+0x40/0x80 > process_one_work+0x54c/0xbe0 > worker_thread+0x80/0x650 > kthread+0x1e0/0x200 > ret_from_fork+0x27/0x50 > > read to 0xffff941ca3b3be00 of 8 bytes by task 703 on cpu 44: > osq_lock+0x18e/0x340 > __mutex_lock+0x277/0xd20 > mutex_lock_nested+0x31/0x40 > memcg_create_kmem_cache+0x2e/0x190 > memcg_kmem_cache_create_func+0x40/0x80 > process_one_work+0x54c/0xbe0 > worker_thread+0x80/0x650 > kthread+0x1e0/0x200 > ret_from_fork+0x27/0x50 That's useless gibberish, at the very least run it through some decode so we get line numbers. > which points to those lines in osq_wait_next(), > > next = xchg(&node->next, NULL); > if (next) > break; > > Since only the read is outside of critical sections, fixed it by adding > a READ_ONCE(). What?!?! Did you actually read what you wrote? Also, you have to stop calling things fixes unless you can prove (and explain) there is an actual problem. > Signed-off-by: Qian Cai > --- > kernel/locking/osq_lock.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c > index 6ef600aa0f47..8f565165019a 100644 > --- a/kernel/locking/osq_lock.c > +++ b/kernel/locking/osq_lock.c > @@ -77,7 +77,7 @@ osq_wait_next(struct optimistic_spin_queue *lock, > */ > if (node->next) { > next = xchg(&node->next, NULL); > - if (next) > + if (READ_ONCE(next)) > break; > } > This seems to suggest you ought to maybe brush up on your C skills.