Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp436378rdh; Wed, 14 Feb 2024 01:02:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVvnMDdWWKINdB2Czwuowv6eBgmhW8ei4aH5ICLjl65kzDil/zPlo0sfkaehQ80Ymy8bzZWk5ohWQ2LSmitjXm6mNtovG2yPeQWLZq8tw== X-Google-Smtp-Source: AGHT+IG8k34H4kNsdcQ4OLns0vf4ZSY7DUXr3kLgC7ypG1bzRehKSjRAPwHN+zYt9W9MbxugIkvk X-Received: by 2002:a05:620a:42:b0:787:1db5:f0de with SMTP id t2-20020a05620a004200b007871db5f0demr2086551qkt.26.1707901359114; Wed, 14 Feb 2024 01:02:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707901359; cv=pass; d=google.com; s=arc-20160816; b=btqZCGMSKwF27Ryb5o36/vAWxdeikaV7Qk4+x6riWNklt8W31D+Q0GHJrc/km5Lku+ C0EUmKsfcLQGc6NJQtrNwi9UQyFQSlOSs5vc2cqyRIlQ22kqYqvXON/DH4SrTiM3Qhlx N7xsoHylHcRHdHYFzSVZZF4Y6GBvogcNsCdaxE3PbTszboRHsNQwwF3MAfPWjOA4S2Pr sAqxjuGY7ZtlTwyVNs/hO2Pq48vE1wg1ehf2PkuCjz4LcJ1/zsN4I33LfAyFIIjLFg7L KEdBi3ILj8NKitwW9v0NXsZC8kh1DZ0T9eKOM23rsO9xRUrpDnmfCkjplH6Oq7ZeQH6v J54A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=PPRsJ6g4sGjHYOROeqaGh/pr9ekDnpVi90clFxCUkAg=; fh=vE4Jdtz6LSc89Sv3BOkzFAah3WqJJJlxuzeONZHe3bQ=; b=Jo57MWzaMhfhWzviYrUdLeN/T/f4IFKQrBpZNxAQWRihcoT6J/+nI7Gtq2uZbwz+JS LEwxs6IWt6Mv68wpWP2cZKCXA8/Zb5eDMkbnBvAjbQWZ6Un4E8UbRh2Nu/VBGwQmlBja YREeYNtAXNr/5Cvnu3DdEnrP/ArD+xK/PcykYMS20d5IRq8VM0iXOmdEdE77ga6LdHo1 1Halh+XgAE9mwvIX27pvGGRvf+lslebY4w37xzSrbiWfaqEOXFQQYv6JG594NcjSdSsW +bLZitbUeyUdZNOD2aqFCHIf6tEOmZlMu/G+fEmnB8+6Uc7KerECqPqzBHYVBTtcJrB1 dF9g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=CISgWuk1; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-64906-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64906-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com X-Forwarded-Encrypted: i=2; AJvYcCWDco7wNujWoDAar8f1E0dcDLn6gZEhAlS1IBWA+NYEnjSBo6rZFSoqqKmqs/iLi6b4TlCFjm95+mk7NVt/7YzA6XVSf1V7cqEcGgpQwA== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id u20-20020a05622a199400b0042da7c297b9si5075235qtc.663.2024.02.14.01.02.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 01:02:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64906-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=CISgWuk1; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-64906-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64906-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DABF71C2150D for ; Wed, 14 Feb 2024 09:02:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 31E85125C2; Wed, 14 Feb 2024 09:02:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="CISgWuk1" Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 DBDEEB645 for ; Wed, 14 Feb 2024 09:02:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707901332; cv=none; b=G0GPYBtYZMq/+HcgNuZKycP2UIMrPE49CzClgqE2XgfS1CRa25S314o3aSY4ocskcf2Laxa7r1qP6vSDyfHklY+7ggZHtiC070dg3UECDqxeyLUl5tuRZNtOpumtxJCp7IcnmaWmDbbEMCCGT/2Y5PXD0Bpl8gkbF2tFR9tcxbg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707901332; c=relaxed/simple; bh=MfcAXUCHb2E1/+tWEyK5zhlte6BwjTT4yiXkFWjcBoI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I56D1rujwBrWi7ELRLhkAWmaTS1aLTwERv74b+CCcWUkZ7/cqFVw33T1Mie9z3EKzGWKhMPjmTbDD6ovd71vyVggLteMYCNQGiU01vOVboF9oyyjoPcM3a4LPqRU7/GVMdvdNbR0ofP9S9AOUxgXiMh+GstnPLMfU2XmlwUnfek= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=CISgWuk1; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6e09493eb8eso464740b3a.1 for ; Wed, 14 Feb 2024 01:02:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1707901330; x=1708506130; 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=PPRsJ6g4sGjHYOROeqaGh/pr9ekDnpVi90clFxCUkAg=; b=CISgWuk1/rbOKV2EdoWpaODq3ELivfPw1Mg9iVc+qnhrS7ZA8KHhT3VeIUjwiFVILe kuhok7KbFPm8UmUvGpMq8G01o4Y9zfFFNqv2WbXguBozSTjIf2zK+JnBfIEF0rTasyBL FfICzQRZOWIqMJlJixXaDGpXDMs+/+n+izwL8XMtLaOnvetvqIbwd3dwRn0/awzvJ0ki BrN2W3LO3gE6V6OZS84OAMDmkQC4fINJ7A03Emf3yqmUjkt9e4z9NEA91HdyCUJG4Sng vWfRWJMTGU693hHSX8rc/RJFhxbN97c5Uat2ZnkjDPab+VeAy8fRHs2dJHB35OeeD6ih 7k3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707901330; x=1708506130; 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=PPRsJ6g4sGjHYOROeqaGh/pr9ekDnpVi90clFxCUkAg=; b=FpYwZ3nff+azja5/cwZpLa5HtOk4fOFNRP21WP4qnhhm0FpWyX+MD2Z6/lrPWNcoXM shvQdFZuaF+zaQYw+Oski85n/WTgaPs5ncrz1nPTJc+rNzcY1EBeJIfIrtibItsTvgYQ lF1Daf3qJh0c7CJCjmcCnT/TiAda3IZHz3365GljyC/B++UQowlFPW4huSbZX3bv7gTM VWwl1vYC4rSU075dUtYuHNPIDAoQL7XiKWVKF6jOFZpH4lTRAk1YP58i2UEDOYOwJNyy Ir2WujTMLgNq8RviGJWJz6Q2sPrFMw7/w6QEwMM7yGbugyS9VsK+LEIDz1tSw7PmkpFj Ux3Q== X-Forwarded-Encrypted: i=1; AJvYcCUTUMYj6Mbob234o6DVkvzgdfcee6xQnFWptSYffagJMi1onPluc5MIgjQ6BKEnHl1P1kMVcoth6n4tU1YljZiWRn7STpH6ZhSvKCx+ X-Gm-Message-State: AOJu0Ywk2leSXEYkwiQmcEt0ALc52iIdfCjrTWN5uCCVna7mn1kloqrB PrNXL53cJeVcbXErxpAMaggxi+MEwXyIZ87e1pZwyXn2DNioDnY7RObYIm7x72I= X-Received: by 2002:a05:6a20:d487:b0:19e:4c37:8737 with SMTP id im7-20020a056a20d48700b0019e4c378737mr2014592pzb.5.1707901330438; Wed, 14 Feb 2024 01:02:10 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVBa/niUfhaptGFm9lpsC7zFdtIR2IEOBXSB0tdcyp6YZbUOgFtfbI/clENDxQCc8TCx8cnV0UJM0uPePynqx9jmQ7hY4b5ASPHIgiC4ZfxONgs2/Bri+S7wIUid9Bd0gcGYFrdshm5ssWW0rX7DOV8ZmKL6m+ulTzguKOnSdLt5I/uYehmsE75yEXVwh5SFONe5K6zDtg+cMtGVcnmC/zs52MkLQukmDPBDfZPnewiiQR2bVV8CVafM5Yknt5+zeqr1cvS7wKO Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id m25-20020a638c19000000b005d7994a08dcsm2476681pgd.36.2024.02.14.01.02.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 01:02:10 -0800 (PST) From: Samuel Holland To: Palmer Dabbelt Cc: Andrew Jones , linux-kernel@vger.kernel.org, Conor Dooley , linux-riscv@lists.infradead.org, Stefan O'Rear , Samuel Holland , stable@vger.kernel.org Subject: [PATCH -fixes v3 2/2] riscv: Save/restore envcfg CSR during CPU suspend Date: Wed, 14 Feb 2024 01:01:57 -0800 Message-ID: <20240214090206.195754-3-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214090206.195754-1-samuel.holland@sifive.com> References: <20240214090206.195754-1-samuel.holland@sifive.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. The [ms]envcfg CSR was added in version 1.12 of the privileged ISA, and is used by extensions other than Zicboz. However, the kernel currenly has no way to determine the privileged ISA version. Since Zicboz is the only in-kernel user of this CSR so far, use it as a proxy for determining if the CSR is implemented. Cc: # v6.7+ Fixes: 43c16d51a19b ("RISC-V: Enable cbo.zero in usermode") Signed-off-by: Samuel Holland --- 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..28166006688e 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_ZICBOZ)) + 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_ZICBOZ)) + csr_write(CSR_ENVCFG, context->envcfg); csr_write(CSR_TVEC, context->tvec); csr_write(CSR_IE, context->ie); -- 2.43.0