From nobody Mon Feb 9 14:16:48 2026 Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4A3F42073 for ; Sun, 7 Apr 2024 21:32:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712525564; cv=none; b=sOlHunantG5C7MPVFguUShYrIhOcE7Jqj+FEieV2Iz44xzmDTRyK9Eutza0mW09kVQxUUTfzOtv2yfJjLsFET/hTosOCukd2opJXGAAcdd3OxpaKsZQit9tnrLhVDrR8xa3UbetRmV9zbnrYqgQf4POZSFkcIfHHF6woAXxnjys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712525564; c=relaxed/simple; bh=Vd+Jcz3NEwAHWZiNnJr9mmiPAQD0apkBNs/WpUnjVc8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YmPMjawXMnQNkUz9nRouUXHr4+agfeXL9DENy3apRTmZ+SDkzxwNboSDdaLcsiY8KdBNMoncoVtjysXXx1/S9z/xgoeHtWqm7Eta6xGzVmRUjY3Ou08lcB0uioHqrFnNPo7NlHdRsknMzvBQ/L7PZ7rxeDveFoyu7UrrRi28Hzg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=vrull.eu; spf=pass smtp.mailfrom=vrull.eu; dkim=pass (2048-bit key) header.d=vrull.eu header.i=@vrull.eu header.b=VBBI6PeT; arc=none smtp.client-ip=209.85.208.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=vrull.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=vrull.eu header.i=@vrull.eu header.b="VBBI6PeT" Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-2d87660d5dbso14092331fa.3 for ; Sun, 07 Apr 2024 14:32:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1712525561; x=1713130361; darn=vger.kernel.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=4EsNSIHIYC4W6bV2ld6cL2XgDhSvlKY5N8B8yWmcW/U=; b=VBBI6PeTpInV3oIYd0O6DDvmAACk/XBUWRbe4xb878q+5AupiMNn2jWL+6TOmn2N7P 9PcGHaow8qrK+MFuzO4pj1NF1Y5IBqi6HDMI1kZWjOvPeqygC9IuyQa6IxpFq2/NS6Na H5M/Mbh5pCteQJedWPqBIc6YVeFiS4keuUb4vCtzB9aK8GDJcy4EYnyRjjgg/FcUE8rn /eqIpD0mJbHDyXhfgxPSDHJTMgE+FSY7tvATo39omxdcqBd2K7B9gdlrM4m90Jz/N9FM 1Xo1Ub4hDg08OT9P5TJw/gcAoAGVsZEaj6ihLauNQuE+rxD8rXikarvbiaSHkLfpVeX6 w1Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712525561; x=1713130361; 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=4EsNSIHIYC4W6bV2ld6cL2XgDhSvlKY5N8B8yWmcW/U=; b=RI9SZmJeY5E8SMRMzDHiIwq43/r4URLzLP9GKxdmk8fGWXhm2tIebzYi3sb0GloGS2 OEqPmeEMbmRq7mC1D2T+s1GPp/eXvTfeN0Zvpx+R9f9alDkaQ80dPU49r9Ze+nZILoOY +eJkAr7igw3V3DtAMvusjQM/7+T/l9XvQ29TvEFORCYI9j80I3MUhLCQLx1nkFbZYH7h ia8Dr5cgHiImQ9/1W8C2TY4lkRINPcSchS/XMw2FClSQ5Hy85khtVgjuYLG9Kttnk/NT 5PFjtGmoXxBS+VWg5rhG1Ux1e9ihjU9k7lqeilylG8dnq3K7CqGWdCq4D5UwLNx7gN+Y utkg== X-Forwarded-Encrypted: i=1; AJvYcCW5FS84FlS3wre2Eht8seU//IzT2fEP1lhydPZNpDhwTxsuDYvobk4STszye+3nSft8+jowY693WqK9Z0/Ftgs2+vgiZDXUGyqpWRIZ X-Gm-Message-State: AOJu0YzijyLD8DlX+U4kM+Zm1yT8WW/jflhVbVUMabm8wG1P6SRTQsS+ IyLlWRegJOAo27l6pm+HY/W8dAZe8Us2bLswPEqoJe6sn5aj8O/NVjUuWy4f7JgH+jEGwRqaI4M 9i0Y= X-Google-Smtp-Source: AGHT+IGi22D+aAqEe+3xMw9LUgzcozlZLoUYTQmYP6THAXpqnmjX0IEtXPFfJdDttmWTP1xPE/azBw== X-Received: by 2002:a2e:b00c:0:b0:2d4:9201:d505 with SMTP id y12-20020a2eb00c000000b002d49201d505mr4908747ljk.51.1712525560966; Sun, 07 Apr 2024 14:32:40 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 14:32:40 -0700 (PDT) From: =?UTF-8?q?Christoph=20M=C3=BCllner?= To: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , Paul Walmsley , Albert Ou , Philipp Tomsich , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , 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=20M=C3=BCllner?= , Conor Dooley Subject: [PATCH v3 1/2] riscv: thead: Rename T-Head PBMT to MAE Date: Sun, 7 Apr 2024 23:32:35 +0200 Message-ID: <20240407213236.2121592-2-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable T-Head's vendor extension to set page attributes has the name MAE (memory attribute extension). Let's rename it, so it is clear what this referes to. Link: https://github.com/T-head-Semi/thead-extension-spec/blob/master/xthea= dmae.adoc Reviewed-by: Conor Dooley Signed-off-by: Christoph M=C3=BCllner --- arch/riscv/Kconfig.errata | 8 ++++---- arch/riscv/errata/thead/errata.c | 10 +++++----- arch/riscv/include/asm/errata_list.h | 20 ++++++++++---------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/arch/riscv/Kconfig.errata b/arch/riscv/Kconfig.errata index 910ba8837add..2acc7d876e1f 100644 --- a/arch/riscv/Kconfig.errata +++ b/arch/riscv/Kconfig.errata @@ -82,14 +82,14 @@ config ERRATA_THEAD =20 Otherwise, please say "N" here to avoid unnecessary overhead. =20 -config ERRATA_THEAD_PBMT - bool "Apply T-Head memory type errata" +config ERRATA_THEAD_MAE + bool "Apply T-Head's memory attribute extension (XTheadMae) errata" depends on ERRATA_THEAD && 64BIT && MMU select RISCV_ALTERNATIVE_EARLY default y help - This will apply the memory type errata to handle the non-standard - memory type bits in page-table-entries on T-Head SoCs. + This will apply the memory attribute extension errata to handle the + non-standard PTE utilization on T-Head SoCs (XTheadMae). =20 If you don't know what to do here, say "Y". =20 diff --git a/arch/riscv/errata/thead/errata.c b/arch/riscv/errata/thead/err= ata.c index b1c410bbc1ae..6e7ee1f16bee 100644 --- a/arch/riscv/errata/thead/errata.c +++ b/arch/riscv/errata/thead/errata.c @@ -19,10 +19,10 @@ #include #include =20 -static bool errata_probe_pbmt(unsigned int stage, - unsigned long arch_id, unsigned long impid) +static bool errata_probe_mae(unsigned int stage, + unsigned long arch_id, unsigned long impid) { - if (!IS_ENABLED(CONFIG_ERRATA_THEAD_PBMT)) + if (!IS_ENABLED(CONFIG_ERRATA_THEAD_MAE)) return false; =20 if (arch_id !=3D 0 || impid !=3D 0) @@ -140,8 +140,8 @@ static u32 thead_errata_probe(unsigned int stage, { u32 cpu_req_errata =3D 0; =20 - if (errata_probe_pbmt(stage, archid, impid)) - cpu_req_errata |=3D BIT(ERRATA_THEAD_PBMT); + if (errata_probe_mae(stage, archid, impid)) + cpu_req_errata |=3D BIT(ERRATA_THEAD_MAE); =20 errata_probe_cmo(stage, archid, impid); =20 diff --git a/arch/riscv/include/asm/errata_list.h b/arch/riscv/include/asm/= errata_list.h index 1f2dbfb8a8bf..efd851e1b483 100644 --- a/arch/riscv/include/asm/errata_list.h +++ b/arch/riscv/include/asm/errata_list.h @@ -23,7 +23,7 @@ #endif =20 #ifdef CONFIG_ERRATA_THEAD -#define ERRATA_THEAD_PBMT 0 +#define ERRATA_THEAD_MAE 0 #define ERRATA_THEAD_PMU 1 #define ERRATA_THEAD_NUMBER 2 #endif @@ -53,20 +53,20 @@ asm(ALTERNATIVE("sfence.vma %0", "sfence.vma", SIFIVE_V= ENDOR_ID, \ * in the default case. */ #define ALT_SVPBMT_SHIFT 61 -#define ALT_THEAD_PBMT_SHIFT 59 +#define ALT_THEAD_MAE_SHIFT 59 #define ALT_SVPBMT(_val, prot) \ asm(ALTERNATIVE_2("li %0, 0\t\nnop", \ "li %0, %1\t\nslli %0,%0,%3", 0, \ RISCV_ISA_EXT_SVPBMT, CONFIG_RISCV_ISA_SVPBMT, \ "li %0, %2\t\nslli %0,%0,%4", THEAD_VENDOR_ID, \ - ERRATA_THEAD_PBMT, CONFIG_ERRATA_THEAD_PBMT) \ + ERRATA_THEAD_MAE, CONFIG_ERRATA_THEAD_MAE) \ : "=3Dr"(_val) \ : "I"(prot##_SVPBMT >> ALT_SVPBMT_SHIFT), \ - "I"(prot##_THEAD >> ALT_THEAD_PBMT_SHIFT), \ + "I"(prot##_THEAD >> ALT_THEAD_MAE_SHIFT), \ "I"(ALT_SVPBMT_SHIFT), \ - "I"(ALT_THEAD_PBMT_SHIFT)) + "I"(ALT_THEAD_MAE_SHIFT)) =20 -#ifdef CONFIG_ERRATA_THEAD_PBMT +#ifdef CONFIG_ERRATA_THEAD_MAE /* * IO/NOCACHE memory types are handled together with svpbmt, * so on T-Head chips, check if no other memory type is set, @@ -83,11 +83,11 @@ asm volatile(ALTERNATIVE( \ "slli t3, t3, %3\n\t" \ "or %0, %0, t3\n\t" \ "2:", THEAD_VENDOR_ID, \ - ERRATA_THEAD_PBMT, CONFIG_ERRATA_THEAD_PBMT) \ + ERRATA_THEAD_MAE, CONFIG_ERRATA_THEAD_MAE) \ : "+r"(_val) \ - : "I"(_PAGE_MTMASK_THEAD >> ALT_THEAD_PBMT_SHIFT), \ - "I"(_PAGE_PMA_THEAD >> ALT_THEAD_PBMT_SHIFT), \ - "I"(ALT_THEAD_PBMT_SHIFT) \ + : "I"(_PAGE_MTMASK_THEAD >> ALT_THEAD_MAE_SHIFT), \ + "I"(_PAGE_PMA_THEAD >> ALT_THEAD_MAE_SHIFT), \ + "I"(ALT_THEAD_MAE_SHIFT) \ : "t3") #else #define ALT_THEAD_PMA(_val) --=20 2.44.0 From nobody Mon Feb 9 14:16:48 2026 Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7506544C85 for ; Sun, 7 Apr 2024 21:32:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712525566; cv=none; b=GTHPSWfdm6sjgGEyQIQ+ELfKLbf4wzSqvh8gyFKzUKIPNCZzWv+KP+bYzppJKTuNsd1mLYZWLhtyhvmBxpfSSrG4m4MXoy+D+JSq8c0jkb9D29ZK3lWVDktC4NzvZgXRYyAJ55dJ8fz6m4/7+L/tznxiX+0U7DIZ/gRWVQbzLo8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712525566; c=relaxed/simple; bh=PrvneksNVywBX9QBVW+e4qsjCsF+Bt3beRefKOIht/I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=g+RAj4zuIJy62o8i9xOYu0uKH/SljXWpjj9qfJY3kDtS7N5ut/gTc/DAOYg23GrpxK+QZI1yFAf91MRj/wTHBQMA+7Q8NReMoYqeOr2pLH1VXMmCdITmYFRI1nJOajCKfNeLiDJljqZr09+VE0oqtqBgNGzGdxC8HqVuQDSu/IE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=vrull.eu; spf=pass smtp.mailfrom=vrull.eu; dkim=pass (2048-bit key) header.d=vrull.eu header.i=@vrull.eu header.b=JH6ZEESO; arc=none smtp.client-ip=209.85.208.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=vrull.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=vrull.eu header.i=@vrull.eu header.b="JH6ZEESO" Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2d476d7972aso50176521fa.1 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=vger.kernel.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=JH6ZEESOBzikNz0D3qPxE0u+uBcqISo07Ku8US6GA5U5chXYFI/RDsgnUhPAn9oHu4 QjQAqO4qRqOs9NdR67jnE+9tKgkfhnG4nleIS1xF42waEq2rWIvgEFN0NxfH+5VGTWlT c9jAJZVLRM35O5pICOADlKrlNvmCB+v3wTaMXWAr3U2eAq7tkO1n5ELtjpRXoN+ZXO2y H/Zn/bfMA9da+RYJ/BO/HIb3QVDNZjfE9lQbQB60N8K8bUx9byxkA2q9fvDU4LoC4Th2 3KHC4880JT2A/sareWtAyNAmU5OwqWcF0stgl3ne9HA2Hqyme43IzHo5MADsYHuMhRN2 JwWA== 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=j5yal9rEqR1DWuBPH2iqd6jgcOCH6sj1ip87Bq0KGIGv6kECOEcBZeuWT2ENy4trPF 2YHoCtJsTrShjFli9oNuC18sTdQLxdZSFb2gal28bbYcMS3SWVfFF+CnW4nTlLjCK7u6 S3uPPRT9e7MmQx5OfhqaauhuMQ4uFWDsZj7WdpggBNBTnu0RlVDYf6OFBftwe+S6eozm kjD4/TVysiyCOO0vdBjGb2VDv0OhYK/ayNlqG6U1BSM0qRd6raS30Zc9rB1N8vzpuFbK Ns3ZY7IJGGsgCosHJEVFGuukPhCsG1WtQXv/agBoKxzEYOkXbsoy3oogQvd66tdxqsXP uqKQ== X-Forwarded-Encrypted: i=1; AJvYcCVmIwDwBunv1iXY1CWkBf2tvJHNbe7E2vkHcrA/hBf1HhYrc0ZrTi1/hlizS+VvXffWLWtmyDw+AnNE9I3JZPV1Ky2hX25ZP1EQMzhL X-Gm-Message-State: AOJu0YzOPpYHGBM2BfX7TB+qhK6pGmujUUH0kuCDs8VzUxdfCn/YVRVP +G58crlh4HpySSJkD5luQDiDM0deE0WY+txzqYeyoNoNDHkRfaLRrRbXceiF+i4= 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=20M=C3=BCllner?= To: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , Paul Walmsley , Albert Ou , Philipp Tomsich , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , 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=20M=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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=C3=BCllner --- 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/err= ata.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 =20 +#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 !=3D 0 || impid !=3D 0) return false; =20 - if (stage =3D=3D RISCV_ALTERNATIVES_EARLY_BOOT || - stage =3D=3D RISCV_ALTERNATIVES_MODULE) - return true; + if (stage !=3D RISCV_ALTERNATIVES_EARLY_BOOT && + stage !=3D RISCV_ALTERNATIVES_MODULE) + return false; =20 - return false; + if (!(csr_read(CSR_TH_SXSTATUS) & SXSTATUS_MAEE)) + return false; + + return true; } =20 /* --=20 2.44.0