Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1697758ybi; Sun, 16 Jun 2019 11:01:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqzruCGFl9Vyr5dC/lY5Qq2IvCI97HtG4MFyIU1eLfQUtGITIfStl16qDz0NYhNlUUs1f0wn X-Received: by 2002:a63:e018:: with SMTP id e24mr45126568pgh.361.1560708067377; Sun, 16 Jun 2019 11:01:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560708067; cv=none; d=google.com; s=arc-20160816; b=d1BW3zOrBcBfee/QJWD8gF6LxqrS4szg3MAdCQtGx+373mBV7ril2u0wPCZMGDDuHC nuD18uQJP/TNVCD2VzdJkaqBTZ8OXgeEJcEbB4HmDf0dG4nV2czGnBe/74ubYoHZZX1l W4ENMhdT3GU9SqeB18ql/MjJ7eiKB0/cYMsHJdMmSPS5aHpXGbhtXQCkOS+kEDC0DY68 mGWH69TSh0LkuPeSJO8cEEG43wtCBwv5JqXXYrTN+Ec8YiFhwupr8J7RIxOlvRDdPOiS qzljTEPPnoaPLH7swwBQKVB1RbQvnNVSyoA6DD0L7kOyMMj3/pQngbW04AxyhIxFkQdI oNqw== 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; bh=RWP5xfDZTUp2ggn+kSbq9lsHn9opqEkzC8c6FFiXImc=; b=apbqceNoXgpilvoRRACtcv4lDr3K4oP3wBzoe8904SPI+o7LkdpQgvmpddA6mmomvS 7k8B/b7OS1mJ3J8vQMXMJ6LBuACQtQKrCEeTFX8pyaR13hddjpoNQQccc/tFNUK5eFHd dy7PkGe6ZHp7Cuz7MB8tAqbuL1q5q9nSoFlix5FAzfACJFDtQJYgFU9zVp5T67fNFUhx JUP3DLTZItE/W1wcViF5iUArRyxGGqnponCUrs7w3smW/x+PVGZflJXNM9zi2YGsSywf 0mk2n+jGuKSgw3FzFbVxVx84wjSw3yKcIUsp2YTfHdjjg+3MRM8x8n5EUlpjBc/H82OL 2PQA== ARC-Authentication-Results: i=1; mx.google.com; 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 j6si7885231pll.162.2019.06.16.11.00.52; Sun, 16 Jun 2019 11:01:07 -0700 (PDT) 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; 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 S1727215AbfFPSAt (ORCPT + 99 others); Sun, 16 Jun 2019 14:00:49 -0400 Received: from stingray.exigere.com.au ([162.217.113.74]:45630 "EHLO stingray.exigere.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726683AbfFPSAt (ORCPT ); Sun, 16 Jun 2019 14:00:49 -0400 X-Greylist: delayed 397 seconds by postgrey-1.27 at vger.kernel.org; Sun, 16 Jun 2019 14:00:49 EDT Received: from hippo.sing.id.au (exi2311632.lnk.telstra.net [144.139.233.124]) by stingray.exigere.com.au (OpenSMTPD) with ESMTPSA id b42fe4cc (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO); Mon, 17 Jun 2019 04:17:28 +1000 (AEST) Received: from localhost (hippo.sing.id.au [local]) by hippo.sing.id.au (OpenSMTPD) with ESMTPA id 67ebf947; Mon, 17 Jun 2019 03:54:06 +1000 (AEST) Date: Mon, 17 Jun 2019 03:54:06 +1000 From: Joel Sing To: Palmer Dabbelt Cc: linux-riscv@lists.infradead.org, Paul Walmsley , marco@decred.org, me@carlosedp.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] RISC-V: Break load reservations during switch_to Message-ID: <20190616175405.GF61734@hippo.sing.id.au> References: <20190607222222.15300-1-palmer@sifive.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190607222222.15300-1-palmer@sifive.com> 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 19-06-07 15:22:22, Palmer Dabbelt wrote: > The comment describes why in detail. This was found because QEMU never > gives up load reservations, the issue is unlikely to manifest on real > hardware. Makes sense, however it obviously will not help until qemu actually clears load reservations on SC (or otherwise handles the interleaved SC case). See comment inline. > Thanks to Carlos Eduardo for finding the bug! > > Signed-off-by: Palmer Dabbelt > --- > Changes since v1 <20190605231735.26581-1-palmer@sifive.com>: > > * REG_SC is now defined as a helper macro, for any code that wants to SC > a register-sized value. > * The explicit #ifdef to check that TASK_THREAD_RA_RA is 0 has been > removed. Instead we rely on the assembler to catch non-zero SC > offsets. I've tested this does actually work. > > arch/riscv/include/asm/asm.h | 1 + > arch/riscv/kernel/entry.S | 11 +++++++++++ > 2 files changed, 12 insertions(+) > > diff --git a/arch/riscv/include/asm/asm.h b/arch/riscv/include/asm/asm.h > index 5ad4cb622bed..946b671f996c 100644 > --- a/arch/riscv/include/asm/asm.h > +++ b/arch/riscv/include/asm/asm.h > @@ -30,6 +30,7 @@ > > #define REG_L __REG_SEL(ld, lw) > #define REG_S __REG_SEL(sd, sw) > +#define REG_SC __REG_SEL(sc.w, sc.d) The instructions appear to be inverted here (i.e. "sc.d, sc.w"). > #define SZREG __REG_SEL(8, 4) > #define LGREG __REG_SEL(3, 2) > > diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S > index 1c1ecc238cfa..af685782af17 100644 > --- a/arch/riscv/kernel/entry.S > +++ b/arch/riscv/kernel/entry.S > @@ -330,6 +330,17 @@ ENTRY(__switch_to) > add a3, a0, a4 > add a4, a1, a4 > REG_S ra, TASK_THREAD_RA_RA(a3) > + /* > + * The Linux ABI allows programs to depend on load reservations being > + * broken on context switches, but the ISA doesn't require that the > + * hardware ever breaks a load reservation. The only way to break a > + * load reservation is with a store conditional, so we emit one here. > + * Since nothing ever takes a load reservation on TASK_THREAD_RA_RA we > + * know this will always fail, but just to be on the safe side this > + * writes the same value that was unconditionally written by the > + * previous instruction. > + */ > + REG_SC x0, ra, TASK_THREAD_RA_RA(a3) > REG_S sp, TASK_THREAD_SP_RA(a3) > REG_S s0, TASK_THREAD_S0_RA(a3) > REG_S s1, TASK_THREAD_S1_RA(a3) > -- > 2.21.0 >