Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1766390ybl; Thu, 30 Jan 2020 05:41:38 -0800 (PST) X-Google-Smtp-Source: APXvYqwtO7aOw8G/uLodsBUvTcwrKjVgdisfQC+De77/HIMws2bSNqA6P8X+XZe+sSrzDNeSNHYo X-Received: by 2002:a05:6830:114f:: with SMTP id x15mr3396583otq.291.1580391698044; Thu, 30 Jan 2020 05:41:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580391698; cv=none; d=google.com; s=arc-20160816; b=BHVG74REp0qr3wO6i32o68Gbq9RMuHB8HoAakepda5bVXT3eXPIxqsW0stDTW8jQfp mo35i0uRNhYJ+CWaNhb4r+l1D+Utep5dz60w+MjOakRNU6Tv3B4XFU/UmkGUbFyPzCT/ WCcUeiEfPW62FmvV31uTkydnhLmeZEPfhwhOjmsAex2EOKeuENggWo9Yne7baWg0YUoa 76GqZVO/pHOuf9RMWLLBqjFMkiDKmK5VGsHmDrJFith3zYQQASM1hbZND4SGgKAgUrv+ rX74rF0ih72ALV23PP0Gp/pZWZEBU/3oKXAI0vyyfwIQBnIRe0BSAbb2+4jzC/ja4NSU NB2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=P4H48YtpiLm+taBVkGC08gZKk3HEB7Nrcktl9EzCxbo=; b=qmtmuwyHXggrrj4hNahqlzVQG3HZAWImqyzWVyjvuf0lv77VtrssP8fn9MhEunnz+P yMjs37e/WY8o9Iqjp7Iyk7eviYTqY6E+OL1JZISDic4O6gu/THye23HU/jcT4D8PSiGB 91juVGnK9fO56ZbdqLy/V4xDNnDl7SolJCNIf3Z3uyD1ADwaBU5nNvPcD4xak1C5o6vY pScvQQ+uiwD6/+gOqnHFvZ96siRrT+U8f0LpgLfx+bfGordEoSQ7Mm5sFkpMhGroUjaK L0yQDsu0gNBqDI9MjL32Z0kzlLoR89ORvAYp6OjO1dVcb5FVLP2/inCzKRbAxsYCB9Zh LSMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=fpmvpHVJ; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g108si3161323otg.79.2020.01.30.05.41.25; Thu, 30 Jan 2020 05:41:38 -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=pass header.i=@google.com header.s=20161025 header.b=fpmvpHVJ; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727348AbgA3Njw (ORCPT + 99 others); Thu, 30 Jan 2020 08:39:52 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:39284 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727206AbgA3Njv (ORCPT ); Thu, 30 Jan 2020 08:39:51 -0500 Received: by mail-ot1-f65.google.com with SMTP id 77so3127696oty.6 for ; Thu, 30 Jan 2020 05:39:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=P4H48YtpiLm+taBVkGC08gZKk3HEB7Nrcktl9EzCxbo=; b=fpmvpHVJRwNGUKox3FbEv7QUeGtehnoVBpDFYdiVATAqAM2G5s3/rCn29rmIX/hUag 7ZoiJdy/WbI6C1J2JsP0HzCQCQfBoisD2ocZE0JDPDDkLD7qdTWJFq4LIjLmOcRthVZd klwgF6tsX0NGqdCRvReOs3VInFUomaDW8nSBcjUqtAwobvQe9VcetgP9iMrBHXgRo4Y1 XYp1YRKVgtTBwQN8TWgfmmcRkJ7/emXY4x3E+4mrKikSHusR7bSSMRjF3faPTQU2fkQK SuTLimSrW0UkUVUngakgkbprP6I8nYK+r5L8zHsat5kiFrYHTEIGkzeAYEnkoHlC1BAA kb3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=P4H48YtpiLm+taBVkGC08gZKk3HEB7Nrcktl9EzCxbo=; b=V1FAJoy6SvrqmwJo+C1zKclATggHsRCV3wsVy/fmLmOA35ZElT5wlC7Bh8s9wRV8kk jTbrGOKQSrtaEoq/U4xPKL4QCS1pmLz6PhPBHqtJW0mrayLo0UXnbkR5ETSsiet3BgwC Ohtu0pjOsUCltw17C/Z5rbfiCocqGUijFL63fwncdb/q40ABPi6gPYh78Qv0QG3grLHw 4nVusuAfSuptIcXPbRogk4acJAjj2imUH8HUBRnCBfL4XUQh2ZWieqVoMpWIkiRwxM21 Tj1KI9K0usXO3gXV9KfeB9tw5UsdNfEJe4idZvqhL8iBDD8T9DDjeTih07MuMZpco/bT A24w== X-Gm-Message-State: APjAAAXSgn9CAQ4tInN5+M1ont3OULtKxFRn5KMdG+PF1loy2pQ9O62n 3gMx/2uHQBMUtFY1po24TCC+pIWjesBeFiGojnUmwQ== X-Received: by 2002:a9d:7f12:: with SMTP id j18mr3755637otq.17.1580391590549; Thu, 30 Jan 2020 05:39:50 -0800 (PST) MIME-Version: 1.0 References: <20200122165938.GA16974@willie-the-truck> <20200122223851.GA45602@google.com> <20200123093905.GU14914@hirez.programming.kicks-ass.net> <20200128165655.GM14914@hirez.programming.kicks-ass.net> <20200129002253.GT2935@paulmck-ThinkPad-P72> <20200129184024.GT14879@hirez.programming.kicks-ass.net> In-Reply-To: <20200129184024.GT14879@hirez.programming.kicks-ass.net> From: Marco Elver Date: Thu, 30 Jan 2020 14:39:38 +0100 Message-ID: Subject: Re: [PATCH] locking/osq_lock: fix a data race in osq_wait_next To: Peter Zijlstra Cc: "Paul E. McKenney" , Qian Cai , Will Deacon , Ingo Molnar , Linux Kernel Mailing List , kasan-dev Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 29 Jan 2020 at 19:40, Peter Zijlstra wrote: > > On Wed, Jan 29, 2020 at 04:29:43PM +0100, Marco Elver wrote: > > > On Tue, 28 Jan 2020 at 17:52, Peter Zijlstra wrote: > > > I'm claiming that in the first case, the only thing that's ever done > > > with a racy load is comparing against 0, there is no possible bad > > > outcome ever. While obviously if you let the load escape, or do anything > > > other than compare against 0, there is. > > > > It might sound like a simple rule, but implementing this is anything > > but simple: This would require changing the compiler, > > Right. > > > which we said we'd like to avoid as it introduces new problems. > > Ah, I missed that brief. > > > This particular rule relies on semantic analysis that is beyond what > > the TSAN instrumentation currently supports. Right now we support GCC > > and Clang; changing the compiler probably means we'd end up with only > > one (probably Clang), and many more years before the change has > > propagated to the majority of used compiler versions. It'd be good if > > we can do this purely as a change in the kernel's codebase. > > *sigh*, I didn't know there was such a resistance to change the tooling. > That seems very unfortunate :-/ Unfortunately. Just wanted to highlight what to expect if we go down that path. We can put it on a nice-to-have list, but don't expect or rely on it to happen soon, given the implications above. > > Keeping the bigger picture in mind, how frequent is this case, and > > what are we really trying to accomplish? > > It's trying to avoid the RmW pulling the line in exclusive/modified > state in a loop. The basic C-CAS pattern if you will. > > > Is it only to avoid a READ_ONCE? Why is the READ_ONCE bad here? If > > there is a racing access, why not be explicit about it? > > It's probably not terrible to put a READ_ONCE() there; we just need to > make sure the compiler doesn't do something stupid (it is known to do > stupid when 'volatile' is present). Maybe we need to optimize READ_ONCE(). 'if (data_race(..))' would also work here and has no cost. > But the fact remains that it is entirely superfluous, there is no > possible way the compiler can wreck this. Agree. Still thinking if there is a way to do it without changing the compiler, but I can't see it right now. :/ Thanks, -- Marco