Received: by 2002:a17:90a:9307:0:0:0:0 with SMTP id p7csp5144058pjo; Tue, 11 Feb 2020 04:50:05 -0800 (PST) X-Google-Smtp-Source: APXvYqxvJPeWrUZcWyBxL9s1ZYmkL7VaOdJFn0HR8duUUm97zz1v9Rq59l15gGRFB+DsmR0wvrGz X-Received: by 2002:a9d:3b8:: with SMTP id f53mr4731975otf.47.1581425405504; Tue, 11 Feb 2020 04:50:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581425405; cv=none; d=google.com; s=arc-20160816; b=MH5UJHP+It0rTH8+DqpJ/UH3BCqjQndyHn1uIo3jMefDbLyI+GSSVL4BpHYIuOrggL NrAorGO1/GBLq3KqxXOXiq4levjMHECVfvjhXIQmX2STq/SOH6jKnBJtQqUfHxoiKlzW 4rm8/X/u4QrJnuu0SZHXOMuASzt/CyPjzb4FARrYNf9aiwxOaeStKO7hELfoMI4rGPa6 8STlAE4oqkmUMOYDuUgGa0tEkSooy7alDsMfDh0AO0bGulTk7MTpIN9nV2mvl9r8cIvC lH5EKdQr0n2jZdAsi3wfhXMI3rk9G8Cs7K8IIKGe+CkZjsvjn7xKuaRu/Q/g2F6h23qU lsaQ== 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=Wow2V2wSrgauWzev0Bhb5YG00cQ+K8D0/cORVHfU1r4=; b=ZwTlaxX9uMmz3RThnsztVdsuGK04OkF2amxB3xb5ua0JgdcdYdYaJUvuLn+oALFbjY urmwA4sP9teW72p+tnpZfQaUfe6M/ISP86KBl60YvotMFDA+Ud1ZA+vlonIjkEr+jSYB 8p+7WdiEtbo6kQpRKmkmY3FjRCHzMDsg6f9X86RxcuL0ySXucMsvRr5iMsd2BG/N8aeh 5xCL2Ws2PZAEvKgTFxSCCg9NiLcWeK4yHwTgTVFDg4BautoKk97AF4luNYuTcPf00bD8 8fcDyxUe1kUJDpP0X5jVhwAnoomkrwpL+H+RtppAgc0mjQnEuO+T+sqyiznUc/AFW6Id 9gPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ikWx2cpm; 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 c5si2593509ots.233.2020.02.11.04.49.53; Tue, 11 Feb 2020 04:50:05 -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=ikWx2cpm; 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 S1728720AbgBKMsD (ORCPT + 99 others); Tue, 11 Feb 2020 07:48:03 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:48282 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728680AbgBKMsA (ORCPT ); Tue, 11 Feb 2020 07:48:00 -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; bh=Wow2V2wSrgauWzev0Bhb5YG00cQ+K8D0/cORVHfU1r4=; b=ikWx2cpmEg0yhJFXb5yTZsVeJU tyYI7ynFJTAnWCgARyB0PPf9VAsrO1JtIBaRJMRRH87+WJC/EFv9epxiHvwnqC3qRvzdcrlQaZSt4 6GKABv/WOPWo658JTIIpHGiwXtwcjDp+42lMyAm86hb+eJctv1Sye87AxwXSxMY+KRghzYI5ND6jh /NVyTeKTl3+Iutif4D9yGjArftJkWoTpKijX3AcddkrjZUX+u6Ro8wpsnMhEFnAeMRQrvsjuL5qCZ 9svaqcTh58JpfJH3PRLx6XmGyxia4BR9qZs6AyPDngtuy6wqD13q8p9w8MK7HtT0xmDbCTRtimPjJ eB9KMy+w==; 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 1j1UxH-0004ft-ID; Tue, 11 Feb 2020 12:47:55 +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 447A030793E; Tue, 11 Feb 2020 13:46:05 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id EE53A2B88D75F; Tue, 11 Feb 2020 13:47:53 +0100 (CET) Date: Tue, 11 Feb 2020 13:47:53 +0100 From: Peter Zijlstra To: Marco Elver Cc: Qian Cai , Ingo Molnar , Will Deacon , LKML Subject: Re: [PATCH -next] locking/osq_lock: annotate a data race in osq_lock Message-ID: <20200211124753.GP14914@hirez.programming.kicks-ass.net> References: <20200211040651.1993-1-cai@lca.pw> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Tue, Feb 11, 2020 at 11:16:05AM +0100, Marco Elver wrote: > On Tue, 11 Feb 2020 at 05:07, 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. > > I have said this before: we're not just guarding against load/store > tearing, although on their own, they make it deceptively easy to > reason about data races. > > The case here seems to be another instance of a C-CAS, to avoid > unnecessarily dirtying a cacheline. > > Here, the loop would make me suspicious, because a compiler could > optimize out re-loading the value. Due to the smp_load_acquire, > however, at the least we have 1 implied compiler barrier in this loop > which means that will likely not happen. The loop has cpu_relax() (as any spin loop should have), that implies a compiler barrier() and should disallow the compiler from being funny. That said; I feel it would be very good to mandate a comment with every use of data_race(), just like we mandate a comment with memory barriers. This comment can then explain why the data_race() annotation is correct.