From patchwork Tue Oct 29 23:44:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13855719 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 D3299D7494E for ; Tue, 29 Oct 2024 23:44:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F03A6B0095; Tue, 29 Oct 2024 19:44:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 39F786B0096; Tue, 29 Oct 2024 19:44:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 219B16B0098; Tue, 29 Oct 2024 19:44:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 0197A6B0095 for ; Tue, 29 Oct 2024 19:44:26 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 948C91607DB for ; Tue, 29 Oct 2024 23:44:26 +0000 (UTC) X-FDA: 82728270576.30.F1C1485 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by imf05.hostedemail.com (Postfix) with ESMTP id 25C79100027 for ; Tue, 29 Oct 2024 23:43:36 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=NYlO4CBu; spf=pass (imf05.hostedemail.com: domain of debug@rivosinc.com designates 209.85.210.181 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=1730245304; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=32Fr64bQ4i4M4Gkdnki92yyt1KBIEMerrOdU8b6lAUE=; b=360+if933QqEtITnCRfyMZG9Yl0XHG9yfPnDB5i+mST/7hWZo887uNXslOcTiYkhmliKUI 2OH+I/WWvjccFaCskLh5a/Qum0kDphwiG0OWgm8cT3NQiamioCTSLzJqUY20903HjdPhMW BkPKfl1ugUFiqW6/jDGvHJyzp0TljZs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730245304; a=rsa-sha256; cv=none; b=ZHclZY4fzeiC1q0N0pVB85HEG9DkWsH1njCs1QXFet1cj9rcBizWNyzLTihEeYhr17bHMa o5gJZsLoroHZAzqhR30Q616wZjrHYyJUWjwabffpK3VU9CnQB40sfSC9aZafLfR9P1evPf MGmyQfnEo8QiMGvMraXapqyiQ/DVV8Q= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=NYlO4CBu; spf=pass (imf05.hostedemail.com: domain of debug@rivosinc.com designates 209.85.210.181 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-71e625b00bcso4518691b3a.3 for ; Tue, 29 Oct 2024 16:44:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1730245463; x=1730850263; darn=kvack.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=32Fr64bQ4i4M4Gkdnki92yyt1KBIEMerrOdU8b6lAUE=; b=NYlO4CBuqEGcHDL4pFB8/7dUwm+7EomD54LQXoKNiOhHLtHFD7T27UqPHNw0I8ntD+ OkW2kM3zdigpWYypyC/TE7sX8Xx2I9918gcuNYSFMsr81QgazYoTCafaJR+3tGgPopyW n6boWjrU4YNopEkpiBmbjRHSmuPG2h8QY9ASQfaXd+ZcNhMOeJVzwjmcaj/xv9JbzptN tSv/EFf/HYmy8CLj3bUdfdgP9JAkuIEVhQvjtcl7730VXn+XG/Lrbp+7aWNrWj8GSxRM HpiRRF0AzWyUY/TTTlYM9AwJkDuvio4vBn1hUz3BxYIBWycfqtMnMZ9g5xiXIbR/7zY7 eHmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730245463; x=1730850263; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=32Fr64bQ4i4M4Gkdnki92yyt1KBIEMerrOdU8b6lAUE=; b=F0kQjkkx+OChLiISYQJ3nyAPIO4OBxJbjVqj5g0GazjwNSft5DGv2ew3zYjCKl+i34 zTmZigI1QvyuOjuhZevzG+I+KznMx/qcOPbLPS2RvwBb4d+yNIE2cJlxPiXHkf/dJHCc UXIlsrhVlFIc7xRI/j9zLS64PKW0cwnvwtBHIP9dSj2ReRt6n2RTreZWT+gsRbMxdgVB me+MMjSGhrx3h9TXcINheZgiRObxTo1ZrQF/lDN+K/CPlCX51wU7Hz910QovXek3700i dX6/06s3WfTlM6IfvNmZ11AtwylQN5I/GQr4wFuFUZLxhVARSGuLgp5xAOyGOIHGiihb YnyA== X-Forwarded-Encrypted: i=1; AJvYcCVVAz8B+14Dwgs8WOTL15hXPguYKd0tcFX3arqQlPw+sUYICfm5r1EF/xMMSNShQDVqzqLJe6K5kQ==@kvack.org X-Gm-Message-State: AOJu0YyX1AMidVhBPQ8CLyNjsgcauOa8xBBEhtW9VXdT9KN3cfzT+9g6 oXqUbiVlebxYB2osVwSalo8Xqf3c6CflV5QVnAKSo6PkXpwXSPrgidvRpbeYY54= X-Google-Smtp-Source: AGHT+IF9XBA82NtKTvuWXQFZShmgImM2eVgaE8hxac78pAdDA8yPlrXMXV9vOyyNJTLolGWQzFlm1Q== X-Received: by 2002:a05:6a00:2d17:b0:71e:5fa1:d3e4 with SMTP id d2e1a72fcca58-72062f86747mr18631012b3a.2.1730245463422; Tue, 29 Oct 2024 16:44:23 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72057921863sm8157643b3a.33.2024.10.29.16.44.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 16:44:23 -0700 (PDT) From: Deepak Gupta Date: Tue, 29 Oct 2024 16:44:03 -0700 Subject: [PATCH v7 03/32] riscv: Enable cbo.zero only when all harts support Zicboz MIME-Version: 1.0 Message-Id: <20241029-v5_user_cfi_series-v7-3-2727ce9936cb@rivosinc.com> References: <20241029-v5_user_cfi_series-v7-0-2727ce9936cb@rivosinc.com> In-Reply-To: <20241029-v5_user_cfi_series-v7-0-2727ce9936cb@rivosinc.com> To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Lorenzo Stoakes , Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Rob Herring , Krzysztof Kozlowski , Arnd Bergmann , Christian Brauner , Peter Zijlstra , Oleg Nesterov , Eric Biederman , Kees Cook , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, alistair.francis@wdc.com, richard.henderson@linaro.org, jim.shu@sifive.com, andybnac@gmail.com, kito.cheng@sifive.com, charlie@rivosinc.com, atishp@rivosinc.com, evan@rivosinc.com, cleger@rivosinc.com, alexghiti@rivosinc.com, samitolvanen@google.com, broonie@kernel.org, rick.p.edgecombe@intel.com, Samuel Holland , Andrew Jones , Conor Dooley , Deepak Gupta X-Mailer: b4 0.14.0 X-Stat-Signature: w7xwpd5j1c1o3yp5fmmhrcqat1ym5iix X-Rspamd-Queue-Id: 25C79100027 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1730245416-192901 X-HE-Meta: U2FsdGVkX18p9oPTQLlw9M4FC0VB1mU+XQW2SvNusp2jGcyTbWCWRz9BomeB7bMlDzszbAHCnX7Jh/wiEl2iWdpEb5RU3gJmLp35M5yQXUbmFM2ZvVF41WIMLh+5OE1qoDsiD9bhFMSYFW5mZirEy7NXDjG/ns/d30IjLI24YjHDumjYD+D55rrXnr4ZWR9JIZ70zF9t2Gy06hCoYBU5gn8bWvM7p22ICT55NlM0CTl7g6KKmXSXxhTG9A6Jd6Kn6yeroRayiH+XgWFPPk73ww7USIA3v77+Psa2OAxCk4nSCx4IfGs3sm3SOYiwiHssc7u4D+UqfNEKzIG70s9qD5pa/pR59mmRMORe1pfaNvpcgeOxFUGC1BAPSN5JiCFHFSU6VRVAcNG/cuMxKNKF5UrjP8NtKstXpMN+Xk5BDhNh6E5+NaIkhXQbARJn76+Sx5ml5yWzgA8nv6IGQIEfM9joJdUxAn5A2hKQty2iP5/EBP0liggc1HmzWh8ZFhZ3k9O8atgs6RraxiFY2uaxQ/YzXHGuTGJeDJz4a5sJacVb7IRwMF+mCvX8Zsito13QxWjWPKaz/c5TULKfNpVSo4Z1yRCVv+ipI5wue88ZtiCK2FT0b2sViJgongU+JWeGMypUiTjb/VC/rItvo4kld62DU1AReaEkOPv7ZJ78JjNqn1ME3KR+TC3PJN7qaotmm6gKMSw5b2CHrhNt19iU2rxjeIy0c28dby5JibHj3ETqkcoueCsS/ZrOXKYWT9nn2Qm9bdOV7R5EKnwsv28VqHpTVmC+Msqx1pEznN2xG/l04roElg3lckk+f+2DCAo0FqehnvSJudPvfA2ZWSKd7ibhofwMLvFeL4y9oEC3idB+brXxw5nytivQ/8WdxWxIyVkdkgWwcBhaHrfM08IJL974ly4SMhQP/RRC1W0EcMxSEHOp6eQK/bLfLFNa/vTbO9eoJ+YmeILvtWkyq9k HwoS4qVN WenBtRXp1XLv7vvIyLFSPnG6WIX/RSMiQnSHmNVVRfBiKHKWTyMYRkgvkzzxIhwHLkia4hrN0NwN4i078uWgPnTUmP4Ws3etDWxYoliMhkrZ3IpG5W7iA594tfmIu8IMJB01RoXTfV0ViJ9EmOZMFBDpK8JYumpaVJ6MMrtKMukRdTXxVs/NCaxE41x8iZ5iOfblialIwW9ZmOLEhMEPrsoDj06IoLy1Vb3j4CHkgsDabZHXlcj08161DyWGBMP/tvMLTfPduZNb0u1yF+wTOMsfvkRMsl0LHPxZJfN15hvm5+B8AQcQnlJ1j8fWxYPQImQmHRUZ/hc/CRfydhRfViynTC3QsYP7m2kjUTNZrPABxZymIpJrdTaCEkAssetHXy/G6YMQ6vATL4T8zvllmKFZ6Ua8BhxWnyVCYZOdnZ+3gKhjEI5IuGsfv7EYPMci9K9F+g3tO+1j7YRVfaHSfp5GSt5zMLo2jklgk8488frBIyIgs8bw+5inuTfyN6XMHzOemVNWrJzcd0pDcCqrR4KrTFV7u0tStNZ/L7LFYQ0gYBzW9Lrc6tj5T/wPDp/j3Qf6Fu9jW4ODMuLfpw8RLQmsShsMWBSTTX5KnVppgBj9GrjIWFXfvu9+kJDEaehMJ92k8ZUieMtgT5VQl9Cwi/4BIkfJ+FmZFiOn9 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 --- 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 3a8eeaa9310c..e560a253e99b 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; } @@ -919,8 +922,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);