Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp2745475ybg; Mon, 28 Oct 2019 01:29:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqwg4Ga6GzSNLylrQm3x4ZYpl2e83rPhNpZyPAhBx9vXYCJEBDx3sPJ1qz1frtJL8i7P2iOr X-Received: by 2002:a17:906:a0f:: with SMTP id w15mr14981611ejf.321.1572251356108; Mon, 28 Oct 2019 01:29:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572251356; cv=none; d=google.com; s=arc-20160816; b=r/oec1OU1Hnx5bQCBiR4/GDGRsfnov/j+1k/dlDU0FaCN2g0Xg2gPPEDL+AZs0v4ZE xF6Fr/8FqmhEt8ybO3Ev65usfgcKRLsndWWSOZBp2ac/Lezm4AEssYvTP6+H1D08aevN MwEOxr3msP/nxw7gL4PdMm6+1wene1gqbZlbXVjV15VNPeS/BKTsjzRh2qIf/PO1erGC 0LMGfZiyNoPu3faWxxrEmZTsqk2z+NBH+cImjggLtWx6pOVT/ekBUPg5r5l+iOq6F7d4 9QqrSvYHbePshAT8ISrXCgDsLeMabQhm3QfJpx4Ja6YrDPeeXiCIATHcnecvqMC/yEzm HZ3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9qiP0P86gBYNZEh0mfeRAtxfcbBR5wUFLDjf6S3bMuQ=; b=iqPfwt42/CyAqPYsYvuZr3p32ifPxKiEbp7NAJIULbQ44ErKPX4eKsjqZqefL93j9s nzGLbUN1R6HudlZAfW8iNKmKq4/Wlus1s9o9oEMiPSeNwEUJ3otyb73bGnBvR8eUK+dZ Dc2kFpbYQzwESeRoai/eeNOsVJuFj5W1ip4c4Jb4HuFtPSFTo2Tsl+FjZy8Zl71E+Mmu v/LLywoGy4Jwh7JiiD1jRFr2V1BIdHL4KLp0WAFfWPCdNhdHAgXv6RW4PYpjWR8XxNGN 3sIy7lAkVmTkZ+kHHeYoztpgSQTMmt96POB9PqSNwT+n80/+m9a4A58NT7jWyKIYB4vw ME5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=h6Q4Q+Y8; 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 8si6166181ejc.104.2019.10.28.01.28.53; Mon, 28 Oct 2019 01:29:16 -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; dkim=pass header.i=@kernel.org header.s=default header.b=h6Q4Q+Y8; 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 S1731828AbfJ0VVA (ORCPT + 99 others); Sun, 27 Oct 2019 17:21:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:41642 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731813AbfJ0VU5 (ORCPT ); Sun, 27 Oct 2019 17:20:57 -0400 Received: from localhost (100.50.158.77.rev.sfr.net [77.158.50.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 925B3205C9; Sun, 27 Oct 2019 21:20:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572211257; bh=aYvmwZ8K19xAuz/J4n8ZHtP9meBds7d74/RjbcmdqF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h6Q4Q+Y8uPtUTaBRRQ+bVlrukV1wntEmlvvYLlidSzRCFqP0oZURAnQOMY9bjGQBx mBtexYDxO3gKycbGRC7MR4jftH3R+dATFsGd7PPvGnGNy5Ci9Go13HEHMZtBolIRnl GIO6HcH38A0+QVgcGu02WLhXjdAHBRfcY4B1fRrs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Palmer Dabbelt , Christoph Hellwig , Paul Walmsley , Sasha Levin Subject: [PATCH 5.3 043/197] RISC-V: Clear load reservations while restoring hart contexts Date: Sun, 27 Oct 2019 21:59:21 +0100 Message-Id: <20191027203354.035458609@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191027203351.684916567@linuxfoundation.org> References: <20191027203351.684916567@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Palmer Dabbelt [ Upstream commit 18856604b3e7090ce42d533995173ee70c24b1c9 ] This is almost entirely a comment. The bug is unlikely to manifest on existing hardware because there is a timeout on load reservations, but manifests on QEMU because there is no timeout. Signed-off-by: Palmer Dabbelt Reviewed-by: Christoph Hellwig Signed-off-by: Paul Walmsley Signed-off-by: Sasha Levin --- arch/riscv/include/asm/asm.h | 1 + arch/riscv/kernel/entry.S | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/asm.h b/arch/riscv/include/asm/asm.h index 5a02b7d509408..9c992a88d858f 100644 --- a/arch/riscv/include/asm/asm.h +++ b/arch/riscv/include/asm/asm.h @@ -22,6 +22,7 @@ #define REG_L __REG_SEL(ld, lw) #define REG_S __REG_SEL(sd, sw) +#define REG_SC __REG_SEL(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 9b60878a4469c..2a82e0a5af46e 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -98,7 +98,26 @@ _save_context: */ .macro RESTORE_ALL REG_L a0, PT_SSTATUS(sp) - REG_L a2, PT_SEPC(sp) + /* + * The current load reservation is effectively part of the processor's + * state, in the sense that load reservations cannot be shared between + * different hart contexts. We can't actually save and restore a load + * reservation, so instead here we clear any existing reservation -- + * it's always legal for implementations to clear load reservations at + * any point (as long as the forward progress guarantee is kept, but + * we'll ignore that here). + * + * Dangling load reservations can be the result of taking a trap in the + * middle of an LR/SC sequence, but can also be the result of a taken + * forward branch around an SC -- which is how we implement CAS. As a + * result we need to clear reservations between the last CAS and the + * jump back to the new context. While it is unlikely the store + * completes, implementations are allowed to expand reservations to be + * arbitrarily large. + */ + REG_L a2, PT_SEPC(sp) + REG_SC x0, a2, PT_SEPC(sp) + csrw CSR_SSTATUS, a0 csrw CSR_SEPC, a2 -- 2.20.1