From patchwork Mon Feb 10 21:35:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 13969377 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 08877C021A4 for ; Mon, 10 Feb 2025 22:55:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FnTB84Cs9NlMXw96htNbIHhJy9cx5+7FdrJDwpWaKgg=; b=xjCvMyuKWFwhCx j9ejE45KWhKcBUGEbfg5BgsUU4z7ERg/rVb0hPKbsLD2Mnc2PycRDl4QWZoh5J7XHWVamS/TkAPfI aD8VFh5C5BdAeZqJ46W9Vcib4DHcipy9gu8ibi4Q+FLnHD7TqQXbr7iVTnRdflVgtm2eVMIZ5bxBn jxuyzMR44+GEuYgzxiKCIu2IjC/rBfVsfAnHYd7qjAtHdiU3tNIAEbERelKkzj9MSuFeVZ2h7IRG2 +FCiV3jhHeYHjmBD942g73U0FHkEizRkNCJTCiAfccY/4TQgOkX/CNARZxqYIW83ulxpW4JcoS1t1 Ie5FJXQNvcGQbLRLtBdw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1thcgw-00000001kdz-0TZ6; Mon, 10 Feb 2025 22:55:50 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1thbS9-00000001VWl-2iCV for linux-riscv@bombadil.infradead.org; Mon, 10 Feb 2025 21:36:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=Omq0jMe02v0O4r8y1/1Uapc6yttVgCIGxdH7exDcAxo=; b=aRpmsMnKd0FmpM6kBEMGvL/k85 37yTaLZ9ld7RUz9n15FR7oCoJqUbNV1v14jgWoH9Hg0ReM22q07MOrZFR2mrzFMDlakWj1DlaB9Ic KtpKTfjZ6OJWsGpPSvTg8eCgDrbM5CLCQpMzA0DeNwchZmHb10hI5Cxk9YvHcPuEpxHzQ2cSMmyr6 8mRe35q4MpsC+7iaMeY8q35jjKxZxjF//ByPkfZjpOmbX+knMr2hVTIDmyN9g3FKA2zVaMoQiTwwG Wj4c6WDjRBytWntJYbsT3fvL4ve5Ius1sBuoRmtUlk7F5cyrWUKiNWPnUcW9TycrjYPjgN4dFGErT nl55jzhw==; Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1thbS0-00000000I9T-111n for linux-riscv@lists.infradead.org; Mon, 10 Feb 2025 21:36:27 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-43937cf2131so14413215e9.2 for ; Mon, 10 Feb 2025 13:36:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1739223371; x=1739828171; darn=lists.infradead.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=Omq0jMe02v0O4r8y1/1Uapc6yttVgCIGxdH7exDcAxo=; b=dg58qYlT3aNYwONXAxBBhYfBEj31nVCWyNVEFUKKxZSIPPR4NE5+2C521eW7yrnf63 9L37+0MuuxjtGkfh7vIWFCnXK0L/w+Ulj5nnW+SSnAxT8Qy/rtV2cGZ8xfHs3aXJvo8e mWR5zScQw0TiKNRUCTrXYjTgYk0eST1/sEzmHnR4T8z3kEfEyPROixYjV5B//4e12uKb R6lXPAlmV2DDzKJKxHxTzBkqo1WCWnsUfMScN9EpVlkTADQKovTDOaZVCPg8CiNu6st9 ZvyrcPZmFMBMEXRzo/FrjFTdCZ1UxvzwvGz9fK/63oTwf1xNvj5LO/30/InyLj9YTZRC 0JEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739223371; x=1739828171; 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=Omq0jMe02v0O4r8y1/1Uapc6yttVgCIGxdH7exDcAxo=; b=Luj091svsxbrKgkvl3II8J8cK4VgCj7M2+a7Qn2iPazoSD3s+YP+Gr0DyTFSgDwE5n 2GfI52/tmyaRHKdpCMM111zM1SZQeQ9YBK4FcCeg1TzlT4AmTdRGzF80nNVYMT9RFVqT FpftuEUFhIQ5GoXQrYegKFjhXADZC2o7aqdJM3qVWuo0gdrxAdmf+RGKhwos/GGIBAwz z2H5vZVKsbXLgUTMpT+iSvcTyrinz1AmhDUXOV3+mopIrxZ+FHrRiJSCIH/nRC1XwFwQ fPH5hpti7jec+mx6EWAdYt7wfCq0aWDckPz8H8CiUdBZpTWPRPYULWyqY9nzt2DJOQ9T nTXA== X-Forwarded-Encrypted: i=1; AJvYcCWRvmYSD1d/k7UGZMnkMEWA37wlxDCxRXFz+LqQCCq8U14WKfW6Dj7tYJ/M/HOtZRWwRhzrkewDVstATw==@lists.infradead.org X-Gm-Message-State: AOJu0YwxwWlKWa+iW0mGMW7ltJlPM2vB78zUCGjf2vlOITtkmfZm/DsH NZkUch77ECPJ45qYPy0RsP7muFQwKmBA0Akc6pzAS+ZQlMV5MeCgHIoGjyn0T7g= X-Gm-Gg: ASbGnct2XfhYWEiKkUC188YUlgw/BWHzLAh2fg+EhIiLPaTxSPwlF0236aZu0JsaC9k MgBc4BqVUuIUql0WeFqBFq5P78AiBvQmpJCfvHPaWgy8DTi6pHx3eP4uW60z/czP/tWtuc6Py9g Ki/JPzdE0+8pMUbZEYNZ7wTZhibh499xpj5TAx0brJ69Cp3IoHfsS+VD15rvPcxbeyH/f3Mk9gL RKbCApx0SvdRkKo9PMz0O3T565suBqZEbUt10HBVO4j2ORIUjjppz2/2XC6+noXmBHL75OTkhOO aAgD242diIw5y/xk X-Google-Smtp-Source: AGHT+IEW4IwiVYF//YV32GNZdcYc01vxx73uhLVhCiMW8eGAxNPBu731uRffpK0oYRexJJNizE9I8g== X-Received: by 2002:a05:600c:510c:b0:434:a4b3:5ebe with SMTP id 5b1f17b1804b1-4394c847ad4mr11919565e9.24.1739223371617; Mon, 10 Feb 2025 13:36:11 -0800 (PST) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4394376118esm47541515e9.40.2025.02.10.13.36.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 13:36:11 -0800 (PST) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Paul Walmsley , Palmer Dabbelt , Anup Patel , Atish Patra , Shuah Khan , Jonathan Corbet , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Samuel Holland Subject: [PATCH v2 06/15] riscv: misaligned: add a function to check misalign trap delegability Date: Mon, 10 Feb 2025 22:35:39 +0100 Message-ID: <20250210213549.1867704-7-cleger@rivosinc.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250210213549.1867704-1-cleger@rivosinc.com> References: <20250210213549.1867704-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250210_213622_574755_8667AB08 X-CRM114-Status: GOOD ( 11.94 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Checking for the delegability of the misaligned access trap is needed for the KVM FWFT extension implementation. Add a function to get the delegability of the misaligned trap exception. Signed-off-by: Clément Léger --- arch/riscv/include/asm/cpufeature.h | 5 +++++ arch/riscv/kernel/traps_misaligned.c | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm/cpufeature.h index ad7d26788e6a..8b97cba99fc3 100644 --- a/arch/riscv/include/asm/cpufeature.h +++ b/arch/riscv/include/asm/cpufeature.h @@ -69,12 +69,17 @@ int cpu_online_unaligned_access_init(unsigned int cpu); #if defined(CONFIG_RISCV_SCALAR_MISALIGNED) void unaligned_emulation_finish(void); bool unaligned_ctl_available(void); +bool misaligned_traps_can_delegate(void); DECLARE_PER_CPU(long, misaligned_access_speed); #else static inline bool unaligned_ctl_available(void) { return false; } +static inline bool misaligned_traps_can_delegate(void) +{ + return false; +} #endif bool check_vector_unaligned_access_emulated_all_cpus(void); diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/traps_misaligned.c index 7d6185deea33..1d523cf96ff0 100644 --- a/arch/riscv/kernel/traps_misaligned.c +++ b/arch/riscv/kernel/traps_misaligned.c @@ -716,6 +716,8 @@ static int cpu_online_check_unaligned_access_emulated(unsigned int cpu) } #endif +static bool misaligned_traps_delegated; + #ifdef CONFIG_RISCV_SBI struct misaligned_deleg_req { @@ -732,8 +734,6 @@ static int sbi_request_unaligned_delegation(void) return sbi_err_map_linux_errno(ret.error); } -static bool misaligned_traps_delegated; - static int cpu_online_sbi_unaligned_setup(unsigned int cpu) { if (sbi_request_unaligned_delegation() && misaligned_traps_delegated) { @@ -782,6 +782,7 @@ static int cpu_online_sbi_unaligned_setup(unsigned int cpu __always_unused) { return 0; } + #endif int cpu_online_unaligned_access_init(unsigned int cpu) @@ -792,3 +793,15 @@ int cpu_online_unaligned_access_init(unsigned int cpu) return cpu_online_check_unaligned_access_emulated(cpu); } + +bool misaligned_traps_can_delegate(void) +{ + /* + * Either we successfully requested misaligned traps delegation for all + * CPUS or the SBI does not implemented FWFT extension but delegated the + * exception by default. + */ + return misaligned_traps_delegated || + all_cpus_unaligned_scalar_access_emulated(); +} +EXPORT_SYMBOL_GPL(misaligned_traps_can_delegate); \ No newline at end of file