From patchwork Tue Oct 1 16:06:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13818406 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 B6371CEACE7 for ; Tue, 1 Oct 2024 16:07:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F53528009E; Tue, 1 Oct 2024 12:07:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E06D280068; Tue, 1 Oct 2024 12:07:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 10DFA28009E; Tue, 1 Oct 2024 12:07:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E338B280068 for ; Tue, 1 Oct 2024 12:07:11 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9FBBE16174D for ; Tue, 1 Oct 2024 16:07:11 +0000 (UTC) X-FDA: 82625512662.23.2326794 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf14.hostedemail.com (Postfix) with ESMTP id A24EC100007 for ; Tue, 1 Oct 2024 16:07:08 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=yHucswFl; dmarc=none; spf=pass (imf14.hostedemail.com: domain of debug@rivosinc.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=debug@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727798789; a=rsa-sha256; cv=none; b=kR+RM6hH8bCvM6cyaIeXPE7Nm2P/f0R5qA4qEtGvvkmbpCfpbItuCCDi5+om3++8iSTrQt GmV94mFPoHTcoip97enGZUDKNn52rzaHmfGnmMv7JBun9F9lRJWXFfs8+g/8nW9kbNzQjY Q4XOkuXuYfQrtUS3x2OqsJZnCKF+Ixk= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=yHucswFl; dmarc=none; spf=pass (imf14.hostedemail.com: domain of debug@rivosinc.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=debug@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727798789; 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=TN/jwUyrk7nWeXz+2PkcX9PcP6JH0CIrLV6B3SOl4g0=; b=TZrWRRlJSrdYawr4ucd7/H7U6XYt6eU2YUEYBZ4Out3SFrnJ8Kpzy7BRCgh5UdonXJmyxa dRtKr4+zFidpKlekr62cl035Bw+6NgPmbDoitTyOoC6E/ji7ickmvQ9YWOPRvYd5ayNB8r t4lsQGFbCkja9qETIZnWwOTNGu2hatw= Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-2e0b0142bbfso3662012a91.1 for ; Tue, 01 Oct 2024 09:07:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1727798827; x=1728403627; 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=TN/jwUyrk7nWeXz+2PkcX9PcP6JH0CIrLV6B3SOl4g0=; b=yHucswFl8RZDqnf9c4EnyB+3fUam1dFup2xWM2eMu5HvtdA/1Kkiob1VMwYGUJATpH uXxJVxQPnDCOlQu7pOszwPKB5soVHoPtOl2NbUTEC3A/K2VVEA4407I2uGTvh85Cfi2x TpESCdnuXx2C3sZ+ii611ucXUdqpGUGmsyO0Yt201AbYMyB/IsSqjvDMagGZ11Ciw3p4 TaJ91/ftAcaiEwJCtOheQkuj2HA5buKwT7WM7Qt/Go+mbdSMWbPnX3FQ/k7WBsV/A8Ui z2Nt1DZyRcilzPCXd11E691/EUHzjfk84KdZTSedozDYQELzptYVwoKGBZ5tEMtWayJr 7MLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727798827; x=1728403627; 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=TN/jwUyrk7nWeXz+2PkcX9PcP6JH0CIrLV6B3SOl4g0=; b=avQrOHfhQmazzxnBFzuEGCa1SUauvueI3Zpy9JZ11zZL2p2U+uPeO0XRmCm9kzzeUQ t042VaYtkh/ki6SgfCmXLrsjl9YGJkTkLPoYu/j7//zjCU83Kyz8khbqHEUNe9kRyAOI AgxDxihWpKJdVZWg1OE26jhMoYyyRsMej5qW6n0TctnxB64r6boholJL2MSVJ5l92K8h f/zrkmyXsIRyxP6RiGwHdCKHNCqH771An5wkHZaKZH8lfpSp0xEE6OE13PFWC24PoDdo bcxuCxE/6CujtDASvkwx1+P4jOqEJ3QFCBTwe5pprDxWqIPEUZQaIPbr6cFO4O9FXRtf iM7w== X-Forwarded-Encrypted: i=1; AJvYcCVRHrmXVmq6d7UfdY98QAyXoVi88coZiT/Qi6XKj228vptqige7S5tdaDfGj8lBK1fDyA/mquRZrw==@kvack.org X-Gm-Message-State: AOJu0YzFbyHEHwpruni99KXeZHKq9E5B2G7jErzjAgZXgcOvZ3EnjPxs Cc4JzSlv6bG/Czu1F8bp5uAD0PHTmp88D9Ez4CKH0hO5zcBTBSpvbogr7mtYxcM= X-Google-Smtp-Source: AGHT+IGqLEH3PdcnOlfVjojRDIDEBcHW24GL0v1kFxG1jIxdQxmcVKqlOntROUvuoUxPrGiWv1Q9yg== X-Received: by 2002:a17:90a:cb8f:b0:2c9:36bf:ba6f with SMTP id 98e67ed59e1d1-2e1851496c6mr147502a91.3.1727798826977; Tue, 01 Oct 2024 09:07:06 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e06e1d7d47sm13843973a91.28.2024.10.01.09.07.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 09:07:06 -0700 (PDT) From: Deepak Gupta Date: Tue, 01 Oct 2024 09:06:08 -0700 Subject: [PATCH 03/33] riscv: Enable cbo.zero only when all harts support Zicboz MIME-Version: 1.0 Message-Id: <20241001-v5_user_cfi_series-v1-3-3ba65b6e550f@rivosinc.com> References: <20241001-v5_user_cfi_series-v1-0-3ba65b6e550f@rivosinc.com> In-Reply-To: <20241001-v5_user_cfi_series-v1-0-3ba65b6e550f@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, Deepak Gupta , Samuel Holland , Andrew Jones , Conor Dooley X-Mailer: b4 0.14.0 X-Rspam-User: X-Rspamd-Queue-Id: A24EC100007 X-Rspamd-Server: rspam01 X-Stat-Signature: mrjjptjq5qbs9s7kfzzpdrcijks7mqug X-HE-Tag: 1727798828-858985 X-HE-Meta: U2FsdGVkX1/RG9g5eMw5cKUUZq6JDOFhN3GOeFQBG8kqhvGAEywe9B8NtC9BiatlgNseRJg8BrxzCfeJF7qWJ9bTYnM8e1yzFJwvQTWHzZkqZgxdhCqWU0XuQ8OQSR2v0JWVIGkC+/+uG8KfwsNhZvEpkFZO1XtRh2jY1/kZiA42muPW6jP0A+D3ta/XF0QnK5Z7UhLA9GiUa/wUJlshdVY+RYA1kueI+br2KDdM1TkSGws01zOwOCS+sRODSdPZ8zQIYeQYBgz5uc2T0u7dLk68HZ6In+GuQSb4DdvH4YLMJ6L8Co/CnVkv1+EzqcEZ9Hiq8ruZCEd00WRvUUw1uJ97TvFJ+WLsi+dqc4eX5RyZzQA/lpbf0NDtVY2VChO89IIQyEKzpehS8GDGIYsm3JQpe8pz8TyFsD7mKs6HcZMhiZuLW1EbBtnxmgLByhPaiAQE8aHucb/iU7krFRqi9ezfWBx1OQnJ7VxK7icsR3oh8RHirMII7ssAexwj5FsSEY2G+8NoD9sz3M22tkBQ60HNDGJEfnium5DknVu1yAmQVtWDrrjrNn6Nh71b1zlAl5jEmtQNPbrpCCPfruafVVkDKztPEId1Vnd1DjD51WHpYeTNLnOkF712AoRZrd+ix4kDEFYLtObUKDgx7vxTSrPRCN1Zbo+vEz85sfb+94DZvmzLNPvAfnbK7fVhILY2tF4YeWi8A/fgV50Y82TObLEgbLoSWl6cN1JajtS0+xVXgAsvotZ8003ZPfE7rtU+MijfswBzI8TfyH8bHewfwo8GUxqJXkKxTRw+VCQVWB+Dpw4mf4fXbQwl1j9ELe62LFSTC05GhZwTKj211NdKi1Z/rRWlKcrNB+RwhjlL/30fec4+UhMFjp1SQ6g1OCRl5YGGNl0hiYzfYzo6aad8y+5EsIoGPTqKfUZKREBgVzcxCZa/dC2G/f+OnwGqjrurT05ikAC89qMoq1r8qL8 cLrZkqIt 5q8OcNLuoqnxXtoCx2lZSlkdKGKs/vGuDkUZ2MFeo2KmHb5EWyfjYkv6l5p/YR8Gkiqc+pTK16tS3rSzESQ5fyf6WiRzm515OAQVuLHA+mS5n59xWASbLnw6wpS7lJgGwrsx9eCebRtlYFYi0JbuXh5ZyFEIjoHrg9VAvOgPeygOSUnBbq57gwV+Txpt8vto3TD80BmCMyArztwSEk5bhSnZEPJR995y6fH12WJNHpRvQNde6uhMPVQl5wVV/b/jLG9vRBu2CT835UgcOO7BkZf0VcLeY0yVkUYBFSKoJ1b8C9h3fj1Kdfe1vS4TPxfa49CPaIKxeNnIcxHgZH9nPE1XSlhQSisrCZUgfs3n/oI9/wuFaeEKLUrqEn7BWBaUSEzTIl/qcQ3m19jwhjXhcKT2jkc0iNpbUZuTdNOqeUMk4mdx2xbln16/x4SHx0oX71GmngqKU/NJ6AxTvmHfAifKNE6+9NP65xUv1Hit2FTWV/542//j/InEnJ79GObinxME/z25yPmLWEm7SgFMQMj5G7AKVK/EnysjcRg3OLJ6DCmfDrY7g4S7HwMuPZEmUR022DVd3YNJ8AeI8dWmHX+f1ndjUmScbh+bFv6IdAraeipM8ogz8nA7jS/y/bBol7qB8RV/AVOE8li3CRaaBol5czhznUB+hGtoQ 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);