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: 207678 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3174915dyb; Tue, 27 Feb 2024 22:56:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVcQzl2ZT0Jg+nFxZY6VHIBAyISATzY28KNr5KJZdgcWue9C3kK+G4lvVJk+6I8l3nR/KRNo8xXxafX1CVDGNjl7vW4aA== X-Google-Smtp-Source: AGHT+IGsJDwtK7dYWVJfDHHpIibHMO7VOyAtsC2WP9CepE/7f+KowmSoGyXT6xd1swfuJT1xGFXj X-Received: by 2002:a17:902:e552:b0:1dc:c59d:5dde with SMTP id n18-20020a170902e55200b001dcc59d5ddemr2250148plf.59.1709103393656; Tue, 27 Feb 2024 22:56:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709103393; cv=pass; d=google.com; s=arc-20160816; b=R0n0m97gDePRLgPyIiFJm15IBuCXVETRC0NVpLSSyWk1Shl93l073LsllzL2d6dH71 E/1fBaSLSB7A2hh5dqSXn2bZfdUXI8JhK3D658jTVOUKGhzlQQu1vSDvZejuaEYykhik 0h6Vi3lNMn8ajLboyu7XD81ypdkgIi/MrO8vmuIDRfgsgnzCz18oavz6m83AZp8I6qLv K1pCpxBL9AzrVfUaMmA1SmtOyQ2QA2vPc3ubvgY2grbnUMJLAyeGl/0djmsRWNQfeWci HkwzH0PxOO2akRpd7TDwGcCYkvU2affQBCxR1R824tzW4gFH6vcMNv5aBIH0nfdIEy3w 8kdg== 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=b1cp6XMBopp3tzzHV/G51+rKShiExWAPZnHAB8vVY2k=; fh=sAF0toHai8yeNahvxKWn9JiDU4w+H4wcMS6etSAmCdk=; b=SXqyHOdv+N387o/oYiTkvRKnDeuWxroPNqx5/7qYcoMtgl3Xdll1WCaTGZ5TJ1jwRn Dotzkpb5db0ZGnc55y7muzq0BBltOJGzYQSA387w+4TTgdrsqSen/p+hH6Z9PJKX6Vxz xYVTeCEF35o75C5VhV11YMUT2qoVzi+ma+ZHAW1kOuRa0W87jqAJpngaC6FnBHJLJGlV QvzxTucT3B1zluwF8nntC3lI14vAHgxQqOZn0zijryAmRcrwPCo9o6kmclwQJedWFMs+ IYlEMrYTpcTUoXp+xl4k1zyS4L3vPn4kvJWHO62f3LYLhbCn9KL0j3sRGBfpA2sF3z5F mSxQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=dxpPXuGc; 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-84579-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84579-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id p8-20020a170902e74800b001d99acc35b8si2897179plf.573.2024.02.27.22.56.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 22:56:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84579-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=dxpPXuGc; 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-84579-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84579-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 79972285A84 for ; Wed, 28 Feb 2024 06:56:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 15FAF24B2A; Wed, 28 Feb 2024 06:56:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="dxpPXuGc" Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) (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 AA4F921362 for ; Wed, 28 Feb 2024 06:56:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709103365; cv=none; b=pxlVWmtRhEhBoi9LKYxaxvQxP4Edqf5hwGt8lFDdWkSK/tEPLHAsrH7+whyFZ8Bi9T/gXriGpygx1Jax0rwDjZjizSRx6MJDuGoF/M+O6yM8jzgG7QMUwHda/O3WEG3y9LzLlboHcKLhUzrkOyxPZWrokn9Q03sQD0kAzF/Tc3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709103365; c=relaxed/simple; bh=DS0otXxBIAg/AMim69yUhYg9b3z+zSXh8HjudQ+pVJo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V/t/l7xjOk9PnthL4dOX/CrXFSFWov75dLrJoSjnBXxu8R0pGvSwwRpg51OM5SDv0oS7Ec2bRVlJPYRUs6Yik6n0F1XaxpGEvdu+RFDrdsiDseYf4lnUat+Co/uejjO4Ivgd2NVcB+ZfjsYgUOKKJaAukNBTpkPBggJDxi5W/SQ= 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=dxpPXuGc; arc=none smtp.client-ip=209.85.167.182 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-f182.google.com with SMTP id 5614622812f47-3c17ac08a38so2326987b6e.1 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=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=b1cp6XMBopp3tzzHV/G51+rKShiExWAPZnHAB8vVY2k=; b=dxpPXuGcq3+WrgWE8Yq5E9zD7FeffDa0Xic+iFOo6HYQ5vZ711HhbF+2HRSEgAMvo/ eodWK3e9GwQiJx/eucWVD8yInRFgqQpQlYaYnPPU4/qJ8Sqeuad5tI68egIPGze1p9ar T7JU9DKUu98mtel+SNhpvVQ10vMLxR0ad4lSxsxr6jzs0nf42gB4TGLH4UQMYCdEn1fo lnyBHoQzLh83FonyN6eQ2d5LqoM0xD/H7hR2LI5SYOhbA+kDZXNzAtCy/vncdtE8q7CU yo5jd3KYHbBBm04HzKpI0HMk6Mr9HOt/r9Sak/Emfim4n+u3PUSkscalIPe9dAeiJX9V bMmg== 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=J4W6XfFKoWMC+UVZyWB5uOMkXx7n37mqhUqmnth0sSs+87dynFaQzMNJlzCc7Zg1wy VtdHc2pPsjvjgHR9/LaO0fc3qtDUFvjtd49MW9QNfL51m6Iac/F6TGA4rPxq43EkHTGA YfUomoMsJgvkwHULQ415Lx9RIuPTjxm/3+qnicMqkPB8Icz22IprRFCRlDV5dOKkK9A5 BQK8Yb8LWeus1n78ydqXtSEh4HjGzbDCj/e8G2pgSaTvN9YQiYpxPzfKjt0itU6TFtt1 eUrKxu6rXbvXppiOBLMeO/1DysnnmMISUeAoicXIotv3zH5wE9ode8o8UYhB8ohhf7fT mbZQ== X-Forwarded-Encrypted: i=1; AJvYcCXJ8PPFyaESyAxZEIdj2L45kH+ZNhYnOCkbP1bZx+iOfk0aicRHb1tio6o45TZ/+Lir8wJsdBxmGxkea2cS/ed9T8bEggWDBgmrTAu4 X-Gm-Message-State: AOJu0YwaEgOa3ZJvvIadmqN42mX7jXyqKI6ME91zmydWwKhjdYLWGIH5 sjfWVohHTsb4KO25ZDpDr8QKv7Zcwo4BN27566P1TLvxmXrz9HFdC1aEUEe15XY= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792124799857832796 X-GMAIL-MSGID: 1792124799857832796 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: 207679 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3175002dyb; Tue, 27 Feb 2024 22:56:50 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUrMJX6cblx4N/FpevCDErzi5GWFDI6s7BhuMmAZfmbi1AJ7tOuZD24tpX5daQH6pIYjzbcUNAAP6ZZQQo4sYgJet8ZgQ== X-Google-Smtp-Source: AGHT+IGXCCdXyuywItRATrTS8vAb3a5zPRzRjh1EhsyAQbHQHSXLChU5kRa/pFDyrzEwUpj76iUj X-Received: by 2002:a05:6a20:9f43:b0:19e:a1ae:944e with SMTP id ml3-20020a056a209f4300b0019ea1ae944emr5077769pzb.37.1709103409820; Tue, 27 Feb 2024 22:56:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709103409; cv=pass; d=google.com; s=arc-20160816; b=V7JUYcK/I6jIauzZ0mfVGWuWSjerel/jG2j3oQf+SuO4wNaUCzsJxsAanaKdX0vYKF rBU5ZvqSkzJxjocDviPBC5OCuz4mrw/WC1HVA+IpeHGUctKRBkBF3FdPeIB1DjJVcMsn QSwcwV9HS6/0iIwo1ofBdAwup7H14qeg/wKel5TTEK01Btap4ZfEY96+sS4taR36yzRG N3AVettsgGQdpHvLL1yqntTCkpqjO+oSrEsZOcZdoETonDM3GNVN7PSDHzqQg46v+6J1 YHz/pIRl6n/qS7vz4tkH/noi3WF74Hc3zeYBqZypVWrtbyOcNLDQ9ZZnTvIk34tHuHRc Tc/Q== 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=nifjTiVnKPzVz5Xx9U5qG6fvYEiI7lPtCucGoxbvIpQ=; fh=aZXmnnWvl8hxBPEz+t9Ft5/DCHvN3aAtWAaqaEGxF0A=; b=KAb6+AwUlzEHiEyTABZMngNkn3BBAcBIn6FBn9cnKZyZmN3ev/fhrFI9j4mabNVhin zOzhoEB+igk3Ycbmt6L7t6Yja+UzzyY6nQAbW/e+4g9UgVcwHenasS5BbFrFGmauolpv wl0mRqVsXogASp+2dsLR/M/c5v11LHb+/jD8/EQo2G4eAvyvDnDvDk7sDyT4QEYBocig wSzkpg1S4qdk1OE2JPEc6VLQxApMJzkLzlDHg2BKAR5dAielGHVugII4sRMywmP+DLhk Dy5FYMgccIsm3QK7pF7vbv86IIEwJ/RRIQ7r6BHij/s+c2AbpsswW+t5J/rnPjZSLvCQ nh1g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b="fnl/Tedv"; 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-84580-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84580-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id p8-20020a170902e74800b001d99acc35b8si2897179plf.573.2024.02.27.22.56.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 22:56:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84580-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b="fnl/Tedv"; 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-84580-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84580-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 92723285AA1 for ; Wed, 28 Feb 2024 06:56:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8831A2560F; Wed, 28 Feb 2024 06:56:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="fnl/Tedv" Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (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 0DED522F0E for ; Wed, 28 Feb 2024 06:56:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709103367; cv=none; b=TTcWmYqxf0tbDHMCc5vo0mWWhpRCZ4NGXc1534Mo1Y3878sYB+bNj0aGIVxzmVtLQS1dAICWQ7f7wVD2ACn3fKZKwd7BeNLmXP+YHH1aNniWKdYttNRioW5R9xmoWtFeDXirzDx1Wnpw5BAQ/aGTWnWFGTeOp3tuwNex3IaT6n4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709103367; c=relaxed/simple; bh=xTb1dPQYXT3wKImjGSHyQAkc7DbxWJHBELId/zBPW5I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t8hvC+uPbJsFcz3i5FbPoy8fnpyNBM/ElY376r/wlr2XPgVrknFaxGTfSeu/XLG9bGsjFGH1tYoaa7KXhIWRxrogoDi8+xUptww9PL76U3Ll+X7t2lLTa7sI/IcINptc37BilXFEM7EiOL/nqwFwkH0f+r5/MLOnSiVfeiNvgdY= 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=fnl/Tedv; arc=none smtp.client-ip=209.85.210.45 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-ot1-f45.google.com with SMTP id 46e09a7af769-6e47498f4a2so2433639a34.2 for ; Tue, 27 Feb 2024 22:56:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1709103364; x=1709708164; 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=nifjTiVnKPzVz5Xx9U5qG6fvYEiI7lPtCucGoxbvIpQ=; b=fnl/TedvuLO5jBuqUWMTFKeYfTLwox8KspHIhvPDNwfkC4XTzen70LHw6uipOkkTf1 1B3tY2ZNoeNDEH+KHIg0JabKJbfu/CjD2cAut7PJXKFzYKyy0QXP4MWoLxKUpVhqHfdt CWfXcCNLyQDK7lgQIxMuXytytd8VDEuLSuXu2uh/7lI/liZGY18blcizpLBur0587Ki/ rg36oPMby7JVhVpFtmOQ3zJsOhlE3GmK64gH4ceqS1aJY1sNsxt3gxNo6msfp8qE80tg flILJNy7fEM06EuGU1kxUBN1lCbj+ycTgx1nNDZDqVfLQEe6mpy5E+D/SwJhOlSYB1h0 sLhg== 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=vYJMDUPztEh85nkARKNsBdrDRIuLejef1ZSFkbNLyB25U/0I7dYFNiQbv7ztwkVLUA QnQjD5VupCBhGb0IdeCMdfhXYBC7U0VIRNgJSgCZUpf9mjGyBY29hIB47DcPXtlgYH5v ICOf6L9uGusNDb9RLLDmb6n+D6kpnL8IOiRezTYYJ8snGXW9Jm08vEDQ5tfi/JjTQ1YC KVI3QBA04cWsFkwHA6PlaxB2SxMIt4Kp6soaVGGxh3ssjdXA+JcIaWFjkoa9EmoYSO0V PhGyJ/uB3d7VvgmT/V45/6Ph5S9B5CilgyvBHi0AXTZ7WVslbyier1NkaZY649+nWady lOsA== X-Forwarded-Encrypted: i=1; AJvYcCX1EvVvL9sUPUvUYW9b0mTyo1p3Ou6GHuNMZScRRrzhK5zPxlaQ9R9SZwwgbaX8yAOlHPWYPV2f9Oiauk5Em/3LocR5kp6IGqXTmmpL X-Gm-Message-State: AOJu0Yy5D+XX0FhcAMS1Xk+dtsHWfaysXICiVdgUJuD8HErXCgDXWH9y O6E4gFy6eZFf6BdOF5WDB7nWCh8k0gy4XaDWVEJOfrzfQ5c9e7TVCRubLXg86wo+UYl+qEiVVX1 H 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792124817131677695 X-GMAIL-MSGID: 1792124817131677695 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: 207680 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3175037dyb; Tue, 27 Feb 2024 22:56:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXHRylbuYcZz7/q87T+HqOORlpdSpD15q6i0IikgvLM/RTB8C6qVjkea70S5/4GJuKRgsnKjjXjvY7XoOrE8Q+VNR3Pfg== X-Google-Smtp-Source: AGHT+IEDwlaf1bZnJLWCPTyBr+olKNKh8c2hjxk/3Jfa5tk5qAY8HTcmk7TD7I07QfuU1dkswxa6 X-Received: by 2002:a05:6808:38c7:b0:3c1:5c93:7e55 with SMTP id el7-20020a05680838c700b003c15c937e55mr5608529oib.19.1709103415336; Tue, 27 Feb 2024 22:56:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709103415; cv=pass; d=google.com; s=arc-20160816; b=s+ZM0SdQMi+hWUildA2MN+x1eWJXjfTmgNvBUg+VHz530sKf+DTDo8vd+aVnw26RNM nB5ABccdm4cwhpNZVH8unULCCAx7RiCd3/3H5uW7jsQJcysGU3KWOdbVPQOHaUFqFWiM 3E5Myu2HeMxYccaKAhedqfbxAXGdfZ0E+Gu9zVm/gN2GRb0FgDinqOiVf0H+bmIZEur0 DGM0A7tOWe7FBmK/2nlNx8fpUChdV2OK9yTkaaWO9JL7Ae3c9WnBr4UoFOR5clni/Q0R jt2qWURqJ2UrqxC/mj01JcU3WnzSzI9f4czGDg1zVhXpqeaCpWLsdTJq2AFtvvc2vWBz h5/A== 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-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84581-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id fk7-20020a056a003a8700b006e48974006csi6807422pfb.72.2024.02.27.22.56.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 22:56:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84581-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84581-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 25E63285AEE for ; Wed, 28 Feb 2024 06:56:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F0DC25624; Wed, 28 Feb 2024 06:56:11 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792124823314596197 X-GMAIL-MSGID: 1792124823314596197 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);