From patchwork Wed Feb 28 06:55:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13574931 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 05731C54E4A for ; Wed, 28 Feb 2024 06:56:23 +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=SY006LMzpala2SsYKH9gJBTdWhbv/yVjuMtZV7zIiRI=; b=IcfmqJ45l9pnD2 JkyeKfJFic24+90Pe2wflnYsun5nj7D2LVFMEOfO1KYRSr7nhaMLUyjVh8mm/JZ3MS49B9mIihs4n L2n/9ruwVcy0yV2qD7+DblRD/t8PQxBAiYNiE/qOfmjqI7iNicpOdXLrVYR8CmI1WncP8OP/+43ft mhkXS2PtsD8sWkaOmO+wKoHuL/slU3q+9e11M7/krGxM1wmyreK+HfzPIVl22cbjWeMu8vv9v/paN Q9TQOx55ZyfK7ZveEnBqO3kHteX3IYkM6k+Tf/zIBXdPEjjTV2fBd4JDLcp1FX9EWGL8PkPrsPmw0 yw5J0pf5dTfHFgXNASvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfDrM-00000008EIt-1wyi; Wed, 28 Feb 2024 06:56:08 +0000 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfDrI-00000008EHF-2LE3 for linux-riscv@lists.infradead.org; Wed, 28 Feb 2024 06:56:06 +0000 Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-3c19dd9ade5so1694372b6e.3 for ; Tue, 27 Feb 2024 22:56:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1709103363; x=1709708163; 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=b1cp6XMBopp3tzzHV/G51+rKShiExWAPZnHAB8vVY2k=; b=S9yoIk2qd6sidZF1Q3PUKdJScEgt+BWA4d999Eurjx5+Tu32AGy+P4wQFDGJRjS2ID hh+MtxxxGWgspqSKbvfGid0of9HuCWyhe2KcqsxlSQ5zFDwqYbTKmzfJ0BxBafOgfv3c wTU/CuuD30/6jZaYC6Ntsl20JhWufHWjBsdtPl/88iQpnfDeixg9Eqq2+FF485OpkNsA lyxeBkPF+AY1a44oiezMlCVei4Vl+661ojn00t28eh91f3874/PdaSodceVU6LL3pJ8i PmRere2YO316zeamk3R2shbgdU1vcCH7arQYFdrfQqFFY5uogO5/9gGTrAcHy/ameWaF /Yjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709103363; x=1709708163; 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=b1cp6XMBopp3tzzHV/G51+rKShiExWAPZnHAB8vVY2k=; b=sg3iMD4RvyUDwfAQTk5idWrrX7cCykNRiLY+aC4iK7bbqCBr7JN/w04tW+qYzw84qz naXv7C8qJ9SQjSSDc7X2EJg73eEZCnkf1uL1ZfhtSziDvK0KgjQm/d4Uhi5Q5B2yAQXl zND4gNFEtX/lvwHkrsqeGqqhSyc3k5q1siKqJ5aiWDYI/ekC5kg++GItCH0zVfb2A5s4 b6IHefsLccKoENDHjRmtlzFv+y5cV7PVJnrc8DwaU9jqAr0lnITWurzy40afbaDhyaCX MFqnVPaczCSc8qPGmMw4UkMTOX76TY0wOHsmQlNFNCNAu05FrMbcVpep6z1FTVC99Ay6 EUWw== X-Forwarded-Encrypted: i=1; AJvYcCXomVIytJTqJyePtsk6U3B0C/7Mpg9wrSLLQYJQ76e+kFnyDF/2Ay4+EyzDBZMXhHVLP5ZnG/aeoWrXnZ+KnkHzwMy4dXZHoTp8Gw4VzuAK X-Gm-Message-State: AOJu0YyLDGUtBs/9E6jFZO+JIFF99WCx0q1xwS3/LmYWi7s6x9K1Ox5H BvVef/posQZoKt9pQJCFQNQPq4hUtFAQDMa608i0Yg8QzSBdz3hgcZoF8Gg4ITg= X-Google-Smtp-Source: AGHT+IFXIsSjDWuHRYBUZ4nH4ci0C53IjlWATHbpl7/aaCUY4gxiRH0rXlKJl12edB4xIX1p9ussRA== X-Received: by 2002:a05:6808:8b:b0:3c1:5b63:579b with SMTP id s11-20020a056808008b00b003c15b63579bmr3629169oic.49.1709103362812; Tue, 27 Feb 2024 22:56:02 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id e12-20020a62aa0c000000b006e5590729aasm1010112pff.89.2024.02.27.22.56.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 22:56:02 -0800 (PST) From: Samuel Holland To: Palmer Dabbelt Cc: Andrew Jones , linux-kernel@vger.kernel.org, Conor Dooley , Alexandre Ghiti , linux-riscv@lists.infradead.org, Stefan O'Rear , Samuel Holland , stable@vger.kernel.org Subject: [PATCH -fixes v4 1/3] riscv: Fix enabling cbo.zero when running in M-mode Date: Tue, 27 Feb 2024 22:55:33 -0800 Message-ID: <20240228065559.3434837-2-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240228065559.3434837-1-samuel.holland@sifive.com> References: <20240228065559.3434837-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240227_225604_727212_394D639C X-CRM114-Status: GOOD ( 10.89 ) 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 When the kernel is running in M-mode, the CBZE bit must be set in the menvcfg CSR, not in senvcfg. Cc: Fixes: 43c16d51a19b ("RISC-V: Enable cbo.zero in usermode") Reviewed-by: Andrew Jones Signed-off-by: Samuel Holland Reviewed-by: Conor Dooley --- (no changes since v1) arch/riscv/include/asm/csr.h | 2 ++ arch/riscv/kernel/cpufeature.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index 510014051f5d..2468c55933cd 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -424,6 +424,7 @@ # define CSR_STATUS CSR_MSTATUS # define CSR_IE CSR_MIE # define CSR_TVEC CSR_MTVEC +# define CSR_ENVCFG CSR_MENVCFG # define CSR_SCRATCH CSR_MSCRATCH # define CSR_EPC CSR_MEPC # define CSR_CAUSE CSR_MCAUSE @@ -448,6 +449,7 @@ # define CSR_STATUS CSR_SSTATUS # define CSR_IE CSR_SIE # define CSR_TVEC CSR_STVEC +# define CSR_ENVCFG CSR_SENVCFG # define CSR_SCRATCH CSR_SSCRATCH # define CSR_EPC CSR_SEPC # define CSR_CAUSE CSR_SCAUSE diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 89920f84d0a3..c5b13f7dd482 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -950,7 +950,7 @@ arch_initcall(check_unaligned_access_all_cpus); void riscv_user_isa_enable(void) { if (riscv_cpu_has_extension_unlikely(smp_processor_id(), RISCV_ISA_EXT_ZICBOZ)) - csr_set(CSR_SENVCFG, ENVCFG_CBZE); + csr_set(CSR_ENVCFG, ENVCFG_CBZE); } #ifdef CONFIG_RISCV_ALTERNATIVE From patchwork Wed Feb 28 06:55:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13574929 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 E2501C47DD9 for ; Wed, 28 Feb 2024 06:56:18 +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=YCwYivWGjeeAQYz1RNhMnOLma76TFHMNnVdCMoDf1CM=; b=yVjp+CNXqSjkBG ZtT3QJM1CK6whtsH87J3HL2wxiTFssjl/ILUoHaVQA01fsDkBp9ERCO0WeOzvGPHzS9+H0OEW+WD1 OT1GY7x41TE1i5eabugAZEL+FS3hJbi9r/1omwaut/v/tbl9dwiPq7YzBk2KLgVamOBxZ07INKzO9 VgmdzYA+pHfwahgtnGwe2FjTsoqCC9xvNzK6+IYKJcNDvi739asd8hM4HCKjFIe6KNhgHGlsH5qL/ 5512AhfRoQDMUtEbr9KZTKdjNnCxa6Swn41usA05p0hq1UxMnjiagGUGM6HHdo5tFPEODWURQxaNH yWZCUoVhm1X2QWpDcWwg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfDrP-00000008EK1-4BMH; Wed, 28 Feb 2024 06:56:12 +0000 Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfDrL-00000008EIP-23aa for linux-riscv@lists.infradead.org; Wed, 28 Feb 2024 06:56:08 +0000 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-6ddf26eba3cso4004045a34.0 for ; Tue, 27 Feb 2024 22:56:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1709103364; x=1709708164; 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=nifjTiVnKPzVz5Xx9U5qG6fvYEiI7lPtCucGoxbvIpQ=; b=JqkFZwTQ5Fyjur/4+a1mu2EFbXhCqAi4j0xRaConeSCdKuj40EIOaq2e1K/xedK8of ougfYxTlhPnPDza6Ow6n3TQuGTXIQfBgQKCMEFUlVhp9u6sBzRwOyr02gPoa6FOQI4Em A1dsC4/qlR5lZjKFz9Z4lDpOl6H0VQN3fhd/MHfQzXRnaLn6l6rcUN4HqAemC3exhDHJ 2aIPUkpM6HB22nm4e1uWTEKJ4SfxHQFo4tVaQavqz0xb1hwVBW3TrPcgoJACmwWG7nHe bE8hpwQBcBmiC1C2PKM19GYE1jdvZlMaGr+37qP+8py8yfBSBlyQyAlEefFEWuq8j7Et 2ktw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709103364; x=1709708164; 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=nifjTiVnKPzVz5Xx9U5qG6fvYEiI7lPtCucGoxbvIpQ=; b=SJxTmkxKvkFIEJt4MQPBvHezU5MrGdxqx0NNMX57BZ3h95bvXZ+SQGOWTBoaQc5NcS tVLiinR2O1wGB0g882UyO4HbVgGTSWSVSSo97ttcowl4c4WN7Tz32taQwklQtiVJW4U4 8VFgbvubRifDfCJdH9cetDQV7wXeNWNCv51SVJdfT4HVI8lJK8YfQ0eLyG3iswA3PBuV PQ3+ogf/FcmoEvIeyRwhzzjmO1viYOPQ/xCvbWkibpvrWCpayGwOpxCTy9QEqJCckhD+ S/0/phr2K8YVStWwQAhZ774x8sLqtcQjYkGsumti3ltFkNOVP5FkBgO7drVA2laXmfUz kcew== X-Forwarded-Encrypted: i=1; AJvYcCWcPA2xsOV8QQbB7r9Wkfw9mM7JtafYsASUaCcln70WfEiDtKG5irL0W2fyC2ygoHtDizOVRGR80QoKvmLFV/rI018sXUAQfnrrQfdlNOy9 X-Gm-Message-State: AOJu0YwXV1PP/2NahlKu13fgIkNbObEAYoEk7+qfbHSV/7VgMknFTWLK 8ClIHB4wsJmeepXhtDkoV1IT3WokrM2Ozr5rml+Aw0Ag78BAeTCN/WkQsN6m6/k= X-Google-Smtp-Source: AGHT+IH4U8aBkFA2SKkKEolatXoRyjbjHcx5laQ73wGPgxVUxDCeFNHOySd/fRV8xKBko/SIfS+RIA== X-Received: by 2002:a05:6870:e2d3:b0:21f:aa70:4c2b with SMTP id w19-20020a056870e2d300b0021faa704c2bmr13648589oad.12.1709103364136; Tue, 27 Feb 2024 22:56:04 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id e12-20020a62aa0c000000b006e5590729aasm1010112pff.89.2024.02.27.22.56.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 22:56:03 -0800 (PST) From: Samuel Holland To: Palmer Dabbelt Cc: Andrew Jones , linux-kernel@vger.kernel.org, Conor Dooley , Alexandre Ghiti , linux-riscv@lists.infradead.org, Stefan O'Rear , Samuel Holland , stable@vger.kernel.org Subject: [PATCH -fixes v4 2/3] riscv: Add a custom ISA extension for the [ms]envcfg CSR Date: Tue, 27 Feb 2024 22:55:34 -0800 Message-ID: <20240228065559.3434837-3-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240228065559.3434837-1-samuel.holland@sifive.com> References: <20240228065559.3434837-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240227_225607_550162_6ED1C419 X-CRM114-Status: GOOD ( 18.31 ) 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 The [ms]envcfg CSR was added in version 1.12 of the RISC-V privileged ISA (aka S[ms]1p12). However, bits in this CSR are defined by several other extensions which may be implemented separately from any particular version of the privileged ISA (for example, some unrelated errata may prevent an implementation from claiming conformance with Ss1p12). As a result, Linux cannot simply use the privileged ISA version to determine if the CSR is present. It must also check if any of these other extensions are implemented. It also cannot probe the existence of the CSR at runtime, because Linux does not require Sstrict, so (in the absence of additional information) it cannot know if a CSR at that address is [ms]envcfg or part of some non-conforming vendor extension. Since there are several standard extensions that imply the existence of the [ms]envcfg CSR, it becomes unwieldy to check for all of them wherever the CSR is accessed. Instead, define a custom Xlinuxenvcfg ISA extension bit that is implied by the other extensions and denotes that the CSR exists as defined in the privileged ISA, containing at least one of the fields common between menvcfg and senvcfg. This extension does not need to be parsed from the devicetree or ISA string because it can only be implemented as a subset of some other standard extension. Cc: # v6.7+ Signed-off-by: Samuel Holland Reviewed-by: Conor Dooley Reviewed-by: Andrew Jones --- Changes in v4: - New patch for v4 arch/riscv/include/asm/hwcap.h | 2 ++ arch/riscv/kernel/cpufeature.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h index 5340f818746b..1f2d2599c655 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -81,6 +81,8 @@ #define RISCV_ISA_EXT_ZTSO 72 #define RISCV_ISA_EXT_ZACAS 73 +#define RISCV_ISA_EXT_XLINUXENVCFG 127 + #define RISCV_ISA_EXT_MAX 128 #define RISCV_ISA_EXT_INVALID U32_MAX diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index c5b13f7dd482..dacffef68ce2 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -201,6 +201,16 @@ static const unsigned int riscv_zvbb_exts[] = { RISCV_ISA_EXT_ZVKB }; +/* + * While the [ms]envcfg CSRs were not defined until version 1.12 of the RISC-V + * privileged ISA, the existence of the CSRs is implied by any extension which + * specifies [ms]envcfg bit(s). Hence, we define a custom ISA extension for the + * existence of the CSR, and treat it as a subset of those other extensions. + */ +static const unsigned int riscv_xlinuxenvcfg_exts[] = { + RISCV_ISA_EXT_XLINUXENVCFG +}; + /* * The canonical order of ISA extension names in the ISA string is defined in * chapter 27 of the unprivileged specification. @@ -250,8 +260,8 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = { __RISCV_ISA_EXT_DATA(c, RISCV_ISA_EXT_c), __RISCV_ISA_EXT_DATA(v, RISCV_ISA_EXT_v), __RISCV_ISA_EXT_DATA(h, RISCV_ISA_EXT_h), - __RISCV_ISA_EXT_DATA(zicbom, RISCV_ISA_EXT_ZICBOM), - __RISCV_ISA_EXT_DATA(zicboz, RISCV_ISA_EXT_ZICBOZ), + __RISCV_ISA_EXT_SUPERSET(zicbom, RISCV_ISA_EXT_ZICBOM, riscv_xlinuxenvcfg_exts), + __RISCV_ISA_EXT_SUPERSET(zicboz, RISCV_ISA_EXT_ZICBOZ, riscv_xlinuxenvcfg_exts), __RISCV_ISA_EXT_DATA(zicntr, RISCV_ISA_EXT_ZICNTR), __RISCV_ISA_EXT_DATA(zicond, RISCV_ISA_EXT_ZICOND), __RISCV_ISA_EXT_DATA(zicsr, RISCV_ISA_EXT_ZICSR), From patchwork Wed Feb 28 06:55:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13574930 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 C3D1BC54E41 for ; Wed, 28 Feb 2024 06:56:19 +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=SpBl10GLuNu1Se/5CcXYU6WZ4WUqrFowbu/3vKztO6c=; b=kLpmCPdbuVrXTt fkEU5VZXg9R68QmYTO6/YBKaoztS0rA2yOs+cR8P7/t/tTaEvsTZJ/92dxsmob+gH7LcKQq9WShR6 nYwrfnfJqCpu48bAu6nYk6eK3FZcb0JvBdJKz5oksgncT5GD+fIExc5nAmGn+vvpxxtToGPaIE3rk 7WMqq3MIVpAQfmTMetPIRACE+ARhUIF1MiNKKp+ujh+HLVML/G05g70DhnA6Ed/yoXaMLNda408eS GUrzHjmyTeYzKdmo0Ql4wtGf3bAzuL8CCPEQl7IAOlydn+tqVc4B8/js70vKKhqpmqWBqENpVyTkI vbillUbmhB69UvxHmvaQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfDrP-00000008EJS-118N; Wed, 28 Feb 2024 06:56:11 +0000 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfDrK-00000008EHu-1b66 for linux-riscv@lists.infradead.org; Wed, 28 Feb 2024 06:56:07 +0000 Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3bbb4806f67so3878905b6e.3 for ; Tue, 27 Feb 2024 22:56:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1709103365; x=1709708165; 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=IJgAIcTGryvmtjsnjR7QyAZRnNOgxphdJs6wyGDboLY=; b=D5AV3nnWQfsiFIYqJmKoQB/923AiDig9FbxyqiwUV9bNM/zjQsHkN+Wsm5Ss/b6Gn7 mCVwc1zeEBzX8E1JbYmkLpvJoJeLw0FdGnTb4AUtRzED6TIvusBiG4d9L0a1602H6jQz jxzpd2L6X6RnpZDM7H+YHd0Ai/pCv6mvsbeZBHJWT3ChUPDiV+TLlEoBRY4rjbM7dM78 gQnwdS6gk89ajbYNZb8K6WBx0Z7ZSt5HL5+aBWW3PFxZ1aozfCd0Fk6U8YE7ot0+2Mn8 bNUSN7FS+OxlLiIcmOfVyllQGDr+Q54vfspBNzC24tBbrcE1ftNHQYq3s1VbCB1/AHyR OuAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709103365; x=1709708165; 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=IJgAIcTGryvmtjsnjR7QyAZRnNOgxphdJs6wyGDboLY=; b=xE9VJkoMA6PiCrMOR7XGn2JR0vZtG50MtMmh+/7qtnSmqW7/A1JKdCeD7e6mCjff+X sWh4pbhm85ZU+3+2MC8IUmJPylxTAPXjRuRImetHUqDsbylEOvDkC+0oyPmvZFcHppxa P/Idbs6/Jp/bHEQVV4nICC6rASgL94GoLVUHnYbJpBRTF+z97BwUYSVRu07sIqc4W0ul PhArGBnr1YwDNDvgJZUz3sqdrmXJOQWZiB36cV73ImZadL9o30nX4K7J4VDcc7Daw6/Z jdKGEL6DsyPQbthyvqDok2KApuof1IGEOBfkFLWuf3km1cx6Bvqtpf1jfLwNfrBuui7K 2/vw== X-Forwarded-Encrypted: i=1; AJvYcCVt5Xxxwl0vwJH5Tx3+9yd65tE2MVicuz51Xhr/ueCV9Gw4+YJqo4/yKaT0aDAdw6usURJcUamPZuRjddvC4tja38zXvWtD91/mHQmBoE0M X-Gm-Message-State: AOJu0YwXhVAAtOjkm1Gw5Ctz4EWTLHNOHEgnrbXJTCHmkTU3frRyN7FP 9pMhzTfMw5IByzYx7dIDALJ6Al0W6Zho39SPfCshyg5ENc8JobR1YOqjAAp6guk= X-Google-Smtp-Source: AGHT+IGGx/vnvLhHJPPq3FzMaf0ciOqylHEHVZRNqVVM/N13/blIW1fdU1Wt/S2raD6d/d9mTPu+ag== X-Received: by 2002:a05:6808:ec1:b0:3c0:4477:deab with SMTP id q1-20020a0568080ec100b003c04477deabmr4903802oiv.51.1709103365507; Tue, 27 Feb 2024 22:56:05 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id e12-20020a62aa0c000000b006e5590729aasm1010112pff.89.2024.02.27.22.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 22:56:05 -0800 (PST) From: Samuel Holland To: Palmer Dabbelt Cc: Andrew Jones , linux-kernel@vger.kernel.org, Conor Dooley , Alexandre Ghiti , linux-riscv@lists.infradead.org, Stefan O'Rear , Samuel Holland , stable@vger.kernel.org Subject: [PATCH -fixes v4 3/3] riscv: Save/restore envcfg CSR during CPU suspend Date: Tue, 27 Feb 2024 22:55:35 -0800 Message-ID: <20240228065559.3434837-4-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240228065559.3434837-1-samuel.holland@sifive.com> References: <20240228065559.3434837-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240227_225606_442053_25856CDD X-CRM114-Status: GOOD ( 10.82 ) 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 The value of the [ms]envcfg CSR is lost when entering a nonretentive idle state, so the CSR must be rewritten when resuming the CPU. Cc: # v6.7+ Fixes: 43c16d51a19b ("RISC-V: Enable cbo.zero in usermode") Signed-off-by: Samuel Holland Reviewed-by: Conor Dooley Reviewed-by: Andrew Jones --- Changes in v4: - Check for Xlinuxenvcfg instead of Zicboz Changes in v3: - Check for Zicboz instead of the privileged ISA version Changes in v2: - Check for privileged ISA v1.12 instead of the specific CSR - Use riscv_has_extension_likely() instead of new ALTERNATIVE()s arch/riscv/include/asm/suspend.h | 1 + arch/riscv/kernel/suspend.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/arch/riscv/include/asm/suspend.h b/arch/riscv/include/asm/suspend.h index 02f87867389a..491296a335d0 100644 --- a/arch/riscv/include/asm/suspend.h +++ b/arch/riscv/include/asm/suspend.h @@ -14,6 +14,7 @@ struct suspend_context { struct pt_regs regs; /* Saved and restored by high-level functions */ unsigned long scratch; + unsigned long envcfg; unsigned long tvec; unsigned long ie; #ifdef CONFIG_MMU diff --git a/arch/riscv/kernel/suspend.c b/arch/riscv/kernel/suspend.c index 239509367e42..299795341e8a 100644 --- a/arch/riscv/kernel/suspend.c +++ b/arch/riscv/kernel/suspend.c @@ -15,6 +15,8 @@ void suspend_save_csrs(struct suspend_context *context) { context->scratch = csr_read(CSR_SCRATCH); + if (riscv_cpu_has_extension_unlikely(smp_processor_id(), RISCV_ISA_EXT_XLINUXENVCFG)) + context->envcfg = csr_read(CSR_ENVCFG); context->tvec = csr_read(CSR_TVEC); context->ie = csr_read(CSR_IE); @@ -36,6 +38,8 @@ void suspend_save_csrs(struct suspend_context *context) void suspend_restore_csrs(struct suspend_context *context) { csr_write(CSR_SCRATCH, context->scratch); + if (riscv_cpu_has_extension_unlikely(smp_processor_id(), RISCV_ISA_EXT_XLINUXENVCFG)) + csr_write(CSR_ENVCFG, context->envcfg); csr_write(CSR_TVEC, context->tvec); csr_write(CSR_IE, context->ie);