Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp3164369ybh; Sat, 25 Jul 2020 13:14:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaRBowr7iJBt2v76zSVvdOVj3TD9xT74KR7ODlgycKq7vzaQ5dmjTAmtqtjhZBQoPx4kJS X-Received: by 2002:a17:906:2a41:: with SMTP id k1mr2318820eje.300.1595708046323; Sat, 25 Jul 2020 13:14:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595708046; cv=none; d=google.com; s=arc-20160816; b=Z32Ma95mrJFUIZqYTX3JoSYgqXOidDS628D+7Dj24MpPsU8MGq0kl/iDnoXtWz9Ssk HCMzwMH8n1ANvbk5ELwfiibcFIDckIrZ/rlppBqTGAZ2/kej1E3crX/nwbYygwsrSm6U cK+HyGsfQ4f1GUbk9RdoHV+8i2UPVzt/53worj8AoYAipleVSpf5Z3g+k2R9WQqz59X3 hdxdrRIa6qx9BJKWSGHz9QaNKWNWcqY2g+JKjn5ebLvEDIe0xuLci9cPXwMFYaheDYR3 3cDTVRrDcnMg4JBoUFYweQFL+tq2cpP6LKIkI+7/J2ZhgkqnxRulzNg2IjW5VqhDCPpx hktw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=Pw5RUMobivqcNCfDWDHWYkXzCXE5qOoVsxCJP/NEQ88=; b=ofq6pfYWTInymyQds6tqKw4V5P4rI40xgL19Hcyi8TYgmaTmQXwdhEew+YsWNxSLrh S0izpfCI2T3Q6Wck1W5jzbb/WmoDt8TL0FOarCjcKujWGPyV6XCrQSJN3YSG0gr+yHjH 0wUreUZYIpqV5FOSFe4NgZRTgLFY52hpUwcY5k32HLcq+/b+3YrsEk26RRNiYUgwmlMY wc2u/236hTkuh8C3Ruiy/DrHPSS6icEZ3cb/5dTfKnzuLb0pi1Ut3fINix8nWBc2H5aM dLKLLdB8Y/s10TZTMuGa1sdCDN5KSrBFuP1k3+PhxXWf77HjFP1OEz4bM60WT89buDTH pwOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=KOcxNFyF; 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 t3si2876079edw.327.2020.07.25.13.13.30; Sat, 25 Jul 2020 13:14:06 -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=fail header.i=@infradead.org header.s=casper.20170209 header.b=KOcxNFyF; 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 S1727936AbgGYUKY (ORCPT + 99 others); Sat, 25 Jul 2020 16:10:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726381AbgGYUKY (ORCPT ); Sat, 25 Jul 2020 16:10:24 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2421AC08C5C0 for ; Sat, 25 Jul 2020 13:10:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=Pw5RUMobivqcNCfDWDHWYkXzCXE5qOoVsxCJP/NEQ88=; b=KOcxNFyFQPJAlT02SO5ozn3dyO VP7SPGW0orHgpa2x5jdZSazYY62jrFX+6p4Ucc8IXcpM4Evn1qHatKG2Kc7bdHSLI8Tpo+jFDneVf 4GKx5s3nzq/5mnut6zoyoAgmdugvTAuPujSNJQys21qcMbDbIorBhAix3ErioCMUA3YBALhYaTHb0 CM8MiFLp/UwIz4K2JerjC/7a5Ul0eH9gCoE/KSq00jjQq9ZqbOI8QqixkOZmbWal988elBSsqgak2 FQVzGJrsrJclOnMrp0Zc4SU6MW0yxjSvsoZ/apvt96rrD8Kz9O3AW7Ka8LyQZgV50SJjo+H4cfBoI JKKOwWgw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jzQUr-0008Hv-PC; Sat, 25 Jul 2020 20:10:19 +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 757B03013E5; Sat, 25 Jul 2020 22:10:13 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 6045B2B8A8164; Sat, 25 Jul 2020 22:10:13 +0200 (CEST) Date: Sat, 25 Jul 2020 22:10:13 +0200 From: peterz@infradead.org To: "Paul E. McKenney" Cc: Marco Elver , Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , kasan-dev , LKML Subject: Re: [PATCH] kcsan: Add option to allow watcher interruptions Message-ID: <20200725201013.GZ119549@hirez.programming.kicks-ass.net> References: <20200220141551.166537-1-elver@google.com> <20200220185855.GY2935@paulmck-ThinkPad-P72> <20200220213317.GA35033@google.com> <20200725145623.GZ9247@paulmck-ThinkPad-P72> <20200725174430.GH10769@hirez.programming.kicks-ass.net> <20200725193909.GB9247@paulmck-ThinkPad-P72> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200725193909.GB9247@paulmck-ThinkPad-P72> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jul 25, 2020 at 12:39:09PM -0700, Paul E. McKenney wrote: > On Sat, Jul 25, 2020 at 07:44:30PM +0200, Peter Zijlstra wrote: > > So the thing is, since RCU count is 0 per context (an IRQ must have an > > equal amount of rcu_read_unlock() as it has rcu_read_lock()), interrupts > > are not in fact a problem, even on load-store (RISC) architectures > > (preempt_count has the same thing). > > True enough! > > > So the addition/subtraction in rcu_preempt_read_{enter,exit}() doesn't > > need to be atomic vs interrupts. The only thing we really do need is > > them being single-copy-atomic. > > > > The problem with READ/WRITE_ONCE is that if we were to use it, we'd end > > up with a load-store, even on x86, which is sub-optimal. > > Agreed. > > > I suppose the 'correct' code here would be something like: > > > > *((volatile int *)¤t->rcu_read_lock_nesting)++; > > > > then the compiler can either do a single memop (x86 and the like) or a > > load-store that is free from tearing. > > Hah!!! That is the original ACCESS_ONCE(), isn't it? ;-) > > ACCESS_ONCE(current->rcu_read_lock_nesting)++; Indeed :-) > But open-coding makes sense unless a lot of other places need something > similar. Besides, open-coding allows me to defer bikeshedding on the > name, given that there are actually two accesses. :-/ Yeah, ISTR that being one of the reasons we got rid of it. > So: > (*(volatile int *)&(current->rcu_read_lock_nesting))++; Urgh, sorry for messing that up. > This gets me the following for __rcu_read_lock(): > > 00000000000000e0 <__rcu_read_lock>: > e0: 48 8b 14 25 00 00 00 mov 0x0,%rdx > e7: 00 > e8: 8b 82 e0 02 00 00 mov 0x2e0(%rdx),%eax > ee: 83 c0 01 add $0x1,%eax > f1: 89 82 e0 02 00 00 mov %eax,0x2e0(%rdx) > f7: c3 retq > f8: 0f 1f 84 00 00 00 00 nopl 0x0(%rax,%rax,1) > ff: 00 > > One might hope for a dec instruction, but this isn't bad. We do lose > a few instructions compared to the C-language case due to differences > in address calculation: > > 00000000000000e0 <__rcu_read_lock>: > e0: 48 8b 04 25 00 00 00 mov 0x0,%rax > e7: 00 > e8: 83 80 e0 02 00 00 01 addl $0x1,0x2e0(%rax) > ef: c3 retq Shees, that's daft... I think this is one of the cases where GCC is perhaps overly cautious when presented with 'volatile'. It has a history of generating excessively crap code around volatile, and while it has improved somewhat, this seems to show there's still room for improvement... I suppose this is the point where we go bug a friendly compiler person. Alternatively we can employ data_race() and trust the compiler not to be daft about tearing... which we've been relying with this code anyway.