From patchwork Sun Apr 7 21:32:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christoph_M=C3=BCllner?= X-Patchwork-Id: 13620295 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4F121CD1292 for ; Sun, 7 Apr 2024 21:32:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=htryupzJXAPKM9aD9kto3PQ+ZnpoYZ1WLb7Rf303XzY=; b=huduo/h8QwkKlN fsoStJ+mJFz7n4EKKSJtdQiDc+yFHcGukRCkAgvipXCEEYbuHRpcWL9R4O+jGltpMgIcOHakOHvU/ 1mfG7r5cakzztCHg/Vt1quy5dK30ryJ3lYIqkdqJzJf7EDN/vacePU/8YyKuZCmGu54cwJh/qFO2u h0i1AH9xfnQlZG0f08rz54hrNSWAtJbVd7eK+sZ39650AGwT90Ji+TQlpNLfgU4QtFVb1M4tot3qp JJdFLrpzlx1W/WHZ9cC5dZhjbcEjoXTPo+rmiIiDPYG+3G3NdOEceFqB9CjbfxqPAb+Bdjy+Qho5+ AU6zdHyJ9RZv9HGk+YDA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rta88-0000000DYZN-3zjd; Sun, 07 Apr 2024 21:32:48 +0000 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rta84-0000000DYYI-41vn for linux-riscv@lists.infradead.org; Sun, 07 Apr 2024 21:32:46 +0000 Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2d8863d8a6eso10375371fa.3 for ; Sun, 07 Apr 2024 14:32:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1712525562; x=1713130362; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Cpsym7Sf/nHOWsd3i9dIJWLFXouR7iLMcrTGkY+MhkE=; b=n6X8j03dniYW8GRmcNDz6c6V8q3Y5bgZtphIPMA/aUCn4mMGHT6FfkHjvQYAqDfx5k /6I+0uJzot5IsGvca7dZtoPKvZ99YPauim2+3zrg9RlFVj8ZQ5MpDRYKR8B8iWA6uRkU CeMJObegm9cbptV6ogwccaY68m072gD5vr9XzS0j5TTI1kf7JRAoqK8FsoUOk+H6vxbG e4l81BmlZddcAlI6NJXuZeXCyfVWykzPyCEaV5y/08yJGg+MpTFd+LH0bjn+gfUwwQDG hLBSy8rzH9G6MtcfoG6fn9Tg9+/CtueenfHuUIVTazdHbBLGcyLHxYIRUMxg4SQqr33F De1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712525562; x=1713130362; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Cpsym7Sf/nHOWsd3i9dIJWLFXouR7iLMcrTGkY+MhkE=; b=BDRXf/cG+HT4kSQrdz1uxrcGukmgJoOtN/KXJix4P18W4k1TAlIwUqNtWpIpXXYhls fxTCv3LviwiD15P69E/951kpOMc8PUQmmY/2yrdB/PrC62NK3XAz5Phwp3cuj4Cj6kZ9 ljRZP87Xmhm0DlVd1Pg7Wl01cmSY6Dgxgu2ISHooZ/ZGWj+MTvTdMlZHuSljzj/C3ywr Z5apu2MghxzYcA6OA4HVtlOfpbPfY2oA26vgvaI0NzeTuUmizNqzTAgmV31bn7hSgcAA hCG5ugby5Y8wO7iOocljA5HUh/pFhwHYIoZKP7kFKPSphBaJz0/jd1gpt01EQ5uiF+/R JPfw== X-Gm-Message-State: AOJu0Yw0NowtFnpCtll8qIJG/ojl8OVOYNEUIhA+eW+zAyCPm63xaVIB haYxXh7Onct9AHMTpJLG14jK8qEENGwMbME7ziVkdJYM1+ccSO6yg9PQIuzSlvwiVG14+eAXw2L lxtA= X-Google-Smtp-Source: AGHT+IHu0pX2u2R5/xFiOzLKYemPhVeotLvlqxwy6j4sGwaJJZl/b8VeAR1RK5E1ty/vAsGXsDt7hA== X-Received: by 2002:a2e:bb91:0:b0:2d6:c001:d87 with SMTP id y17-20020a2ebb91000000b002d6c0010d87mr4816723lje.8.1712525562496; Sun, 07 Apr 2024 14:32:42 -0700 (PDT) Received: from antares.fritz.box (62-178-148-172.cable.dynamic.surfer.at. [62.178.148.172]) by smtp.gmail.com with ESMTPSA id i2-20020a50fc02000000b0056e22be831dsm3267562edr.42.2024.04.07.14.32.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 14:32:41 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , Paul Walmsley , Albert Ou , Philipp Tomsich , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Daniel Henrique Barboza , Heiko Stuebner , Cooper Qu , Zhiwei Liu , Huang Tao , Alistair Francis , Andrew Jones , Conor Dooley , Qingfang Deng , Alexandre Ghiti , Samuel Holland Cc: =?utf-8?q?Christoph_M=C3=BCllner?= , Conor Dooley Subject: [PATCH v3 2/2] riscv: T-Head: Test availability bit before enabling MAE errata Date: Sun, 7 Apr 2024 23:32:36 +0200 Message-ID: <20240407213236.2121592-3-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240407213236.2121592-1-christoph.muellner@vrull.eu> References: <20240407213236.2121592-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240407_143245_025659_9BF64FE3 X-CRM114-Status: GOOD ( 14.07 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org T-Head's memory attribute extension (XTheadMae) (non-compatible equivalent of RVI's Svpbmt) is currently assumed for all T-Head harts. However, QEMU recently decided to drop acceptance of guests that write reserved bits in PTEs. As XTheadMae uses reserved bits in PTEs and Linux applies the MAE errata for all T-Head harts, this broke the Linux startup on QEMU emulations of the C906 emulation. This patch attempts to address this issue by testing the MAE-enable bit in the th.sxstatus CSR. This CSR is available in HW and can be emulated in QEMU. This patch also makes the XTheadMae probing mechanism reliable, because a test for the right combination of mvendorid, marchid, and mimpid is not sufficient to enable MAE. Reviewed-by: Conor Dooley Signed-off-by: Christoph Müllner --- arch/riscv/errata/thead/errata.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/riscv/errata/thead/errata.c b/arch/riscv/errata/thead/errata.c index 6e7ee1f16bee..bf6a0a6318ee 100644 --- a/arch/riscv/errata/thead/errata.c +++ b/arch/riscv/errata/thead/errata.c @@ -19,6 +19,9 @@ #include #include +#define CSR_TH_SXSTATUS 0x5c0 +#define SXSTATUS_MAEE _AC(0x200000, UL) + static bool errata_probe_mae(unsigned int stage, unsigned long arch_id, unsigned long impid) { @@ -28,11 +31,14 @@ static bool errata_probe_mae(unsigned int stage, if (arch_id != 0 || impid != 0) return false; - if (stage == RISCV_ALTERNATIVES_EARLY_BOOT || - stage == RISCV_ALTERNATIVES_MODULE) - return true; + if (stage != RISCV_ALTERNATIVES_EARLY_BOOT && + stage != RISCV_ALTERNATIVES_MODULE) + return false; - return false; + if (!(csr_read(CSR_TH_SXSTATUS) & SXSTATUS_MAEE)) + return false; + + return true; } /*