Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp368524ybi; Wed, 19 Jun 2019 00:36:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqxT/GBKauTk7pc6x7wGB4IP1iJZd9Q5605gcCtNTmr+IDO3HMdqG3ADd017u9zLX9kXHxED X-Received: by 2002:a63:4104:: with SMTP id o4mr6705690pga.345.1560929809407; Wed, 19 Jun 2019 00:36:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560929809; cv=none; d=google.com; s=arc-20160816; b=wuxladhZhLf3mAU44heQd+LhBVFJsI3m7d26NYw2rli+p96IoTxYiT4ZeVlYobH0Hl 4vHT3+W714MpzpXf+JavdmA6fprlZz5ywUD7CCsIFnzp1Kujr2akRmWPlrit65pYiYFW CultIAzEwyn7dTkXi8EFYihlZ72w/sJWY7FaJh768vHTp9ZzpDljT99Y6qROZmRR4ToZ hTaXbaeyYy+4jihtNlFuv6Zw8ScCmTC/hX91VJIEnOIIlrsm3Mz80QWwiFX1LNdmTniU r9Y8axF3AKhcGzNMAcqrcxNEongtOuItZCNfl9t6hGGaMC6Ha7pF5DmVGNB+bO/ZufbB mIbw== 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=iB/8NaD/XOsJAa1HLV/gy7FLOf+edppACtEceKz/09A=; b=jSNVvPqGlnbq1b3QFl/xstN8lAgjqqLRabFpOsCmkH843yMLKKnTgw1dKmq3NOzAL2 c8y7gf+cj/+Ex7chuMRgh07Idch7eYOd3f1m2Hu59z303M4CZxdxRTKUdFt9hbV0F1QZ lObQgCEw5EUnUYZpgE8j6Hgx2Moz4n+i31yy/CZ797FfGdP4NLZNri+I97WaFlOVfXpQ NXHHtTp9TR4mQ+2AaOBdUVCFum/r57iVWNMcdfxDgsfhmfD77DqaFjzVA1QpdylQ7VJr an+MrbpKQ9ph22o6aC5S9PIvYUrGb051yiiddnLjTAzRnNcvuCdMSm2+FR6j5AB8gW9x cQyQ== 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 126si2445087pgb.349.2019.06.19.00.36.33; Wed, 19 Jun 2019 00:36:49 -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 S1731195AbfFSHgI (ORCPT + 99 others); Wed, 19 Jun 2019 03:36:08 -0400 Received: from foss.arm.com ([217.140.110.172]:53664 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725854AbfFSHgH (ORCPT ); Wed, 19 Jun 2019 03:36:07 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 14CB6344; Wed, 19 Jun 2019 00:36:07 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 103953F246; Wed, 19 Jun 2019 00:36:05 -0700 (PDT) Date: Wed, 19 Jun 2019 08:36:01 +0100 From: Mark Rutland To: Palmer Dabbelt Cc: linux-riscv@lists.infradead.org, Paul Walmsley , marco@decred.org, me@carlosedp.com, joel@sing.id.au, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] RISC-V: Break load reservations during switch_to Message-ID: <20190619073600.GA29918@lakrids.cambridge.arm.com> 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.11.1+11 (2f07cb52) (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 07, 2019 at 03:22:22PM -0700, 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. > > Thanks to Carlos Eduardo for finding the bug! > @@ -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. > + */ I suspect that you need to do the same as 32-bit ARM, and clear this in your exception return path, rather than in __switch_to, since handlers for interrupts and other exceptions could leave a dangling reservation. For ARM, the architecture permits a store-exclusive to succeed even if the address differed from the load-exclusive. I don't know if the same applies here, but regardless I believe the case above applies if an IRQ is taken from kernel context, since the handler can manipulate the same variable as the interrupted code. Thanks, Mark.