Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2379555rbb; Tue, 27 Feb 2024 22:56:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWcChrkTWKetr36SIOx2amIfGuBDTExIoJEkPDacDJe6HKuGhrpwohbvSwLl042Opoif3DjWmSt+STnq8xdxefFzTzDbReB7lH2ws/SMQ== X-Google-Smtp-Source: AGHT+IGse0V/Zp0OmZjROEWmNasL5ATR1EJHI0eU+QPjhPtmhET4Uc7Oae5Dp+eWOvAxKSCCM49+ X-Received: by 2002:ac8:4e54:0:b0:42e:8d5f:8375 with SMTP id e20-20020ac84e54000000b0042e8d5f8375mr7424804qtw.42.1709103404242; Tue, 27 Feb 2024 22:56:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709103404; cv=pass; d=google.com; s=arc-20160816; b=DRp63oc5klS6TXBoF/wGdD62PWA/yUCBl9l+FemSgGY/N0R3EWXWsDs8ZgWnbo53nk D0sUc4YjOabWd8kuoFRc41h1of7AlPGGu01gOIlYey/tWRqAdYkT3gem9hlgrHdT4rCU XZvJ7Ykbvy01HPWQWKrOxWTPCloaUfSVV7eZFL5PyNZMYapDsCqdIIbmFAv5Q+Dow5Vj 3nAxy1jtrhrw5lWq9KKHXYR0gpL+yfD6pY4XwzIeucwgcLFRxrM+NNfhK61gCynoFVmI tXMgtNyMBCwCfEtpYqm05NY8ReKV4x+eL5Bo8KNfHm4NigTMUOEzLRmxkT/qvx0SrFlZ 1npg== 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=IJgAIcTGryvmtjsnjR7QyAZRnNOgxphdJs6wyGDboLY=; fh=BtetI7mEggr79jOThVg/D/kJX1rZHpRvcYW3Me99fR0=; b=eFKOfbgprWxkuPUrQFDMCI8nvKvKrKQBJMkAa4sgI6TWygx7odQP9cRVBq7czGa6WR z//0UobJiz1EgeJju3UtquoDePyJu3lCfXg9i7V+eLreo2zEzJnajB8PeZJu4uwlQYjS 6secp7gPBRf4NoC8NRdoj06dwaVRvSRbK4vZ5kK1CSR1+ynb6lvN3oUgrerxy071Nq6c SbLCJms3H4WMevsOvHmy2XHYriSw/OPEPqq1Ptq6PuQbtDCbSWrriF50bgiBLvwwwTn5 rRSe/IuUOztH282L0Z2Ma94CD5jirETjIJmgbgBJnI10fIzynlgiV2UKY1PkcEs6uZAd 3xUA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=b2ciu2vv; 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-84581-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84581-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f21-20020ac859d5000000b0042ea4fb6165si2232742qtf.28.2024.02.27.22.56.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 22:56:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84581-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=b2ciu2vv; 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-84581-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84581-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 E2C1F1C2430F for ; Wed, 28 Feb 2024 06:56:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 960032556D; Wed, 28 Feb 2024 06:56:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="b2ciu2vv" Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) (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 6940023774 for ; Wed, 28 Feb 2024 06:56:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709103368; cv=none; b=N9UUvRfSIsrAUMfy6SWrtlbS1gu3/utCHgrqXZY0YDDhyXg35cq8yEYK1Z3jSyIyzJOnzhBFSzQhrUS7agxovo7bHtDmtR1XQG4zYItcC1mueW/Pj+ta5CXmlXzztGkjzudOtHSmsJEWv+21+f5dhYVHXqk4daC3SsiaEYeZG80= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709103368; c=relaxed/simple; bh=bs5XYVcCzho+feAUo6s75ciZiH7nmPW++UTpE+FfRb4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Eo8ir/nP5mMSp8+RAK1AfTxjQWLwUSUG0nuXOvojz6sx2hC3GepsAfUH4dLCVRJgayh/kO4ZB/xxYKUPyE7oQDPHSckTVtEwWyo57Qt5xaRzLDY1/JsYMABJsBkMfQy0lzoNfx1XvXL/ttvJMSIsVJfrgi92zmTiR6puyaYl5nY= 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=b2ciu2vv; arc=none smtp.client-ip=209.85.167.181 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-oi1-f181.google.com with SMTP id 5614622812f47-3c1b38ee443so367111b6e.1 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=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=IJgAIcTGryvmtjsnjR7QyAZRnNOgxphdJs6wyGDboLY=; b=b2ciu2vv8Q2NBZXmajJ97fbJt1gVAumNpIuOcAU5p7NCRJ76IZnL/+1bnYcsSe7621 E9jKTglTB3fZE1NI40rglhfRWXmoYsOTR263MH4Q/zJd5uRoWQLNCE85q3RWvDo7fXwZ +3xeEdzFTX+s99BlP32WYA97dFiXVetDrlTiFlDWSxtO9IL3YEpXnb0p26KndpwGHGL+ 4avcG6iPJHLtv8lC5bapa5xkG8Mxsx0FRybEFZcodVV0vo9fbK0orkBiUyfQbFtT1Om8 UTgyO+LZwD3M1QiaPkKK8XV7E3Ww2Vri4R6h4O5P3NuBCal0lZzciLIhTXxSszbNyJY3 D/Tg== 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=dvbi/fD+tyjIZMCCKkbso/1jRFZmdI8vT+BZOzhY8l+b4BVDjFMBJTMoPA+Y76hDtu cD8kXNsDBtG+2nROXpU/UAftHTBVCar2pkpx12PeHqZS/jVgrNjGpRvWOOQ21K0zhXhb dnst7STy1sWTcM3CklIn4IBhPQpxEGr/ufgC1xxZHg47nPuzt76OKFeEQq8qdIo4fgpq TPaytxxg0bbZLawk/YZjUD0/scA1e7iXtDi1+bt9lOs6RiIcQphuDQ2CwvdSmHMaaiV3 HaxnCC6q9B2Rl61fG5XkWsoHi3U2IHc2qyI9sKy+hXow9MpiGiNjdrtxOHddg7m5zuEp gY/w== X-Forwarded-Encrypted: i=1; AJvYcCWf0cQOxg1xj+HzOW1lplAdZTUUDTvt5uE4YL3hItfoEvTsnW3GIGxUZOSXCDzN32v9dVPGJ8k3T6f+zAoQv6a10C9OSJvVMKDr5H3q X-Gm-Message-State: AOJu0YzLRKqiuDLAXHwPCxjstgj/ifzq2byOWzImm5CccGLCjDIWxtmW 4aGIhVEVhUd8ABGiV02AtuOnewaIFFwBvoBmK5y6wYabIXttFJdTOl0Lm91e0/Pa7ECRjI7Dd6/ 8 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> 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. Cc: # v6.7+ Fixes: 43c16d51a19b ("RISC-V: Enable cbo.zero in usermode") Signed-off-by: Samuel Holland --- 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); -- 2.43.1