From patchwork Thu Sep 12 23:16:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13802826 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70599EEE270 for ; Thu, 12 Sep 2024 23:17:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F3D286B0093; Thu, 12 Sep 2024 19:17:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EEE1C6B0095; Thu, 12 Sep 2024 19:17:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D41346B0096; Thu, 12 Sep 2024 19:17:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B45656B0093 for ; Thu, 12 Sep 2024 19:17:23 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2F741140C70 for ; Thu, 12 Sep 2024 23:17:23 +0000 (UTC) X-FDA: 82557649566.17.8D725D5 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by imf21.hostedemail.com (Postfix) with ESMTP id 5780A1C0003 for ; Thu, 12 Sep 2024 23:17:20 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=h2pggIgw; spf=pass (imf21.hostedemail.com: domain of debug@rivosinc.com designates 209.85.215.170 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726182987; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=AYIoljWVtOX+4iWfX6n3x0ZmKPdqj9thDEJcRhBom38=; b=bcCaY4lDOrWhdSluC/1GzjHlMT4OKbDXca7gUhGHg2oqH59nGGuRLIiWlfOH+DlmeedXyP BJavlBX9mv+GbEnTe27do0grJLMFzzFVIXVL8w1ssjPwjATJV09hOjWbRqlZApNQxrRPn5 oo0QGK5CctVvn3NLzaQq30Z4Swl1Ebs= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=h2pggIgw; spf=pass (imf21.hostedemail.com: domain of debug@rivosinc.com designates 209.85.215.170 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726182987; a=rsa-sha256; cv=none; b=FaTc6v5oXp3RIXeyhG0BUf6PNIWlwp7y7erHsI0ThX6y0phk3jVF2WmWrHgoEQQcWx9Hgz Ll0kVJ7eeoIKdXyl6o/W4bvnc+mstGfq1/SZbiqKIOiA7akSRkOsyI1pgtpQbSlUkG0VDo OX4LztlQoQZYR/duDvbUQGA/9cfHi4g= Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-7d82b0ebd51so87361a12.2 for ; Thu, 12 Sep 2024 16:17:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726183039; x=1726787839; darn=kvack.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=AYIoljWVtOX+4iWfX6n3x0ZmKPdqj9thDEJcRhBom38=; b=h2pggIgwUJKmqHC1xy6P/0s4ya9z+AwSLk0PsMNulxUiJlj/zu9lwYBATscShLWW1V 2ckDuyB1G+pAfbhrQp6VCeFBb/xhGhd+kyxfroWxI0E9WxhpIBMWAECwpKH9Dh9qq8eK ib3oOQHiy/Gr3v2ysxyz2ujrqTKO+yPf2AchFyjcZuqh2Zu+CpkUiE95M/rsXiFcOjMU dukrZi2bw17Md8erXaridvWUyuVyFXasU99WILGLHzJK1dN8ZvI6hpo7oCUH+2EUvzSQ FQeLxczAXHoxNIfBIPt1O1rdk3zGrVLHvBxuJrfvtGPaYcMaxsdfFXxBwAeYZSI5IYFN rB2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726183039; x=1726787839; 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=AYIoljWVtOX+4iWfX6n3x0ZmKPdqj9thDEJcRhBom38=; b=W/mE59Gn6N5LTTanUmRrsvUQE4xVSUzVhdaSBD1NmRugiXQGcQn19fPdb6oCqzpH0s HHkk7AcTaFBA/yDpQ8fjAD12eh7ABEHmZ6GyvMrOh3+Ryd5MA121QMEsyZ7yBt+p9Cdu E1IJ4QDMW8afli/Kr9wYkT+29JG3xvPzk9cO+Ki1efkCZ/OgoqrTAqsx2u6cAygizFgP /RsnTqz8KEx9KbVewtHaPHl88v4RjtbZZxhhTb7zcQ7CNDFxBSZEYgco/USBqJq5eHYy zyau/9ds7j14tagXpFk1SFG+ilNSYfUudRMbme4bx1l5UgBK7aJsnTGkuFFkCFN0ECKh 2Usw== X-Forwarded-Encrypted: i=1; AJvYcCW5pbQRCE1e7OK5ksyLNm9MBMvFyXNv/2G8hmUhVjU6gJGWZn59br9N272rH9N9X4e0aGUUtEJwHQ==@kvack.org X-Gm-Message-State: AOJu0YzFa/oL0Cc4jMsvvPJGSuovAB8O4ZvZwMyOiymaJCujyRR357jh 3nHhGMqT2gEPyIFgRLCRRrQPPxDjo1RHQ28IZ67gT7jS813TCHL17dJPCRYgvQI= X-Google-Smtp-Source: AGHT+IHhk1/Ai6cyL1jJrvo5NU2IwAp0mq4oXO+l/4MJM1q0WDrPHsg2BmH5QLgdNFEq/wAXrgX1nQ== X-Received: by 2002:a17:90a:1648:b0:2d3:c9bb:9cd7 with SMTP id 98e67ed59e1d1-2dbb9f08b4amr1099367a91.36.1726183038878; Thu, 12 Sep 2024 16:17:18 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2db6c1ac69asm3157591a91.0.2024.09.12.16.17.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:17:18 -0700 (PDT) From: Deepak Gupta To: paul.walmsley@sifive.com, palmer@sifive.com, conor@kernel.org, linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: corbet@lwn.net, palmer@dabbelt.com, aou@eecs.berkeley.edu, robh@kernel.org, krzk+dt@kernel.org, oleg@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, peterz@infradead.org, akpm@linux-foundation.org, arnd@arndb.de, ebiederm@xmission.com, kees@kernel.org, Liam.Howlett@oracle.com, vbabka@suse.cz, lorenzo.stoakes@oracle.com, shuah@kernel.org, brauner@kernel.org, samuel.holland@sifive.com, debug@rivosinc.com, andy.chiu@sifive.com, jerry.shih@sifive.com, greentime.hu@sifive.com, charlie@rivosinc.com, evan@rivosinc.com, cleger@rivosinc.com, xiao.w.wang@intel.com, ajones@ventanamicro.com, anup@brainfault.org, mchitale@ventanamicro.com, atishp@rivosinc.com, sameo@rivosinc.com, bjorn@rivosinc.com, alexghiti@rivosinc.com, david@redhat.com, libang.li@antgroup.com, jszhang@kernel.org, leobras@redhat.com, guoren@kernel.org, samitolvanen@google.com, songshuaishuai@tinylab.org, costa.shul@redhat.com, bhe@redhat.com, zong.li@sifive.com, puranjay@kernel.org, namcaov@gmail.com, antonb@tenstorrent.com, sorear@fastmail.com, quic_bjorande@quicinc.com, ancientmodern4@gmail.com, ben.dooks@codethink.co.uk, quic_zhonhan@quicinc.com, cuiyunhui@bytedance.com, yang.lee@linux.alibaba.com, ke.zhao@shingroup.cn, sunilvl@ventanamicro.com, tanzhasanwork@gmail.com, schwab@suse.de, dawei.li@shingroup.cn, rppt@kernel.org, willy@infradead.org, usama.anjum@collabora.com, osalvador@suse.de, ryan.roberts@arm.com, andrii@kernel.org, alx@kernel.org, catalin.marinas@arm.com, broonie@kernel.org, revest@chromium.org, bgray@linux.ibm.com, deller@gmx.de, zev@bewilderbeest.net, Conor Dooley Subject: [PATCH v4 03/30] riscv: Enable cbo.zero only when all harts support Zicboz Date: Thu, 12 Sep 2024 16:16:22 -0700 Message-ID: <20240912231650.3740732-4-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912231650.3740732-1-debug@rivosinc.com> References: <20240912231650.3740732-1-debug@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 5780A1C0003 X-Stat-Signature: 4h74f6qst5n1tno67t8qcyxeibb6xaqo X-HE-Tag: 1726183040-93209 X-HE-Meta: U2FsdGVkX1+kRfwy+OhJeQpJLu+v4/fQ1S9FFOBWtqFB+4Cc29QIlRfBTjobtV7kWOBdBXo2GwjILWYJVRWdFPL+70LjJ29IHK0WwriOpHXe2bhS2TSoa9FFfrf5JNodzOgoIRqmSuDWvf5AZ9/XZ5xdcrwgFHw4GC95rdRNCJ37NvpKesMMLTDwphXhoW/gTo1ihpH5zHxU8PEER4HzcjJ3RyV0teyKTnTrfAlazKcs2ObI2prUKYa4eMQFoGXNl0qo/DKKyfltpwxnZo0Y+yc7Q3ip2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b6yNs181mTMjiZ81WjA1hqK3UaYuvS9H1rcLCo3pPUYjRcpNrFbIpMdygA4H4Ny+WT8FNCO+70iHdTBPnEgGkxnZnBn//dw4pXjoa9zlocA0fl+nzclNghlsdKsSM8YYoWTtsHjV4cQKTRuqrijyBAgnnWqu/WJsX/286BERD9lkMCu1vy0ZnxGQuJLtdMlQ1WjjlWOOw1IqqISLRNe44n/R3mCy5Y314Ri3uv3tXhTV/DkUbY2m4Wp7HC/iuqt9Wm+9kDAKKgmBKew1vq31Mxa8NA/psex0A= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Samuel Holland Currently, we enable cbo.zero for usermode on each hart that supports the Zicboz extension. This means that the [ms]envcfg CSR value may differ between harts. Other features, such as pointer masking and CFI, require setting [ms]envcfg bits on a per-thread basis. The combination of these two adds quite some complexity and overhead to context switching, as we would need to maintain two separate masks for the per-hart and per-thread bits. Andrew Jones, who originally added Zicboz support, writes[1][2]: I've approached Zicboz the same way I would approach all extensions, which is to be per-hart. I'm not currently aware of a platform that is / will be composed of harts where some have Zicboz and others don't, but there's nothing stopping a platform like that from being built. So, how about we add code that confirms Zicboz is on all harts. If any hart does not have it, then we complain loudly and disable it on all the other harts. If it was just a hardware description bug, then it'll get fixed. If there's actually a platform which doesn't have Zicboz on all harts, then, when the issue is reported, we can decide to not support it, support it with defconfig, or support it under a Kconfig guard which must be enabled by the user. Let's follow his suggested solution and require the extension to be available on all harts, so the envcfg CSR value does not need to change when a thread migrates between harts. Since we are doing this for all extensions with fields in envcfg, the CSR itself only needs to be saved/ restored when it is present on all harts. This should not be a regression as no known hardware has asymmetric Zicboz support, but if anyone reports seeing the warning, we will re-evaluate our solution. Link: https://lore.kernel.org/linux-riscv/20240322-168f191eeb8479b2ea169a5e@orel/ [1] Link: https://lore.kernel.org/linux-riscv/20240323-28943722feb57a41fb0ff488@orel/ [2] Reviewed-by: Andrew Jones Reviewed-by: Conor Dooley Reviewed-by: Deepak Gupta Signed-off-by: Samuel Holland Signed-off-by: Deepak Gupta --- arch/riscv/kernel/cpufeature.c | 7 ++++++- arch/riscv/kernel/suspend.c | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index b427188b28fc..0139d4ea8426 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -28,6 +28,8 @@ #define NUM_ALPHA_EXTS ('z' - 'a' + 1) +static bool any_cpu_has_zicboz; + unsigned long elf_hwcap __read_mostly; /* Host ISA bitmap */ @@ -98,6 +100,7 @@ static int riscv_ext_zicboz_validate(const struct riscv_isa_ext_data *data, pr_err("Zicboz disabled as cboz-block-size present, but is not a power-of-2\n"); return -EINVAL; } + any_cpu_has_zicboz = true; return 0; } @@ -918,8 +921,10 @@ unsigned long riscv_get_elf_hwcap(void) void riscv_user_isa_enable(void) { - if (riscv_cpu_has_extension_unlikely(smp_processor_id(), RISCV_ISA_EXT_ZICBOZ)) + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_ZICBOZ)) csr_set(CSR_ENVCFG, ENVCFG_CBZE); + else if (any_cpu_has_zicboz) + pr_warn_once("Zicboz disabled as it is unavailable on some harts\n"); } #ifdef CONFIG_RISCV_ALTERNATIVE diff --git a/arch/riscv/kernel/suspend.c b/arch/riscv/kernel/suspend.c index c8cec0cc5833..9a8a0dc035b2 100644 --- a/arch/riscv/kernel/suspend.c +++ b/arch/riscv/kernel/suspend.c @@ -14,7 +14,7 @@ void suspend_save_csrs(struct suspend_context *context) { - if (riscv_cpu_has_extension_unlikely(smp_processor_id(), RISCV_ISA_EXT_XLINUXENVCFG)) + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_XLINUXENVCFG)) context->envcfg = csr_read(CSR_ENVCFG); context->tvec = csr_read(CSR_TVEC); context->ie = csr_read(CSR_IE); @@ -37,7 +37,7 @@ void suspend_save_csrs(struct suspend_context *context) void suspend_restore_csrs(struct suspend_context *context) { csr_write(CSR_SCRATCH, 0); - if (riscv_cpu_has_extension_unlikely(smp_processor_id(), RISCV_ISA_EXT_XLINUXENVCFG)) + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_XLINUXENVCFG)) csr_write(CSR_ENVCFG, context->envcfg); csr_write(CSR_TVEC, context->tvec); csr_write(CSR_IE, context->ie);