From patchwork Mon Mar 10 15:12:15 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: 14010357 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 36DECC28B2E for ; Mon, 10 Mar 2025 15:47:46 +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=ezPF9RbRKyoyHdB+6Ix0smuGm+9an3uaXgKFFcrobHg=; b=a1UPrDHOrCEZsX Z8pD2s927HqyBS9ATduBfnmi1tIu0Bbuuv9OYaIv2JVZ+1GuWomO7zBH5Wn+/P4PTOGuI5IECe50H Q4tgBAZWR4iZ7ad4zUZ4W5rYjis5q6g7vd3sZpM40hkhUy8tub13rq3O6lxSZjlZ3WcDh96CobFE5 3MYpje5Er2UJCvp+q0TaNqqpZGOjaWRXw1ecQqbwctAYypXpFcZcGeJlVX8Ts5PU4yhNfW0w8UqRN 1zGljoXnYAlplw9xrjMR8RQNAPL/rtKG6dv7+DpKazKC5uctpusrcT4BLC2I4KuQGEKqeQ8AMJSb/ j6dE1gZ7POAb4lbaq9lA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1trfLw-00000003G0r-49Mx; Mon, 10 Mar 2025 15:47:40 +0000 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1trepG-000000037nv-1wbJ for linux-riscv@lists.infradead.org; Mon, 10 Mar 2025 15:13:55 +0000 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-225477548e1so33349615ad.0 for ; Mon, 10 Mar 2025 08:13:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1741619634; x=1742224434; 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=aJEE3tstWlxClRLN5XCqSGWhwaxxi8RTX0eYkvDKRxQ=; b=D+JHsFOb6sbgkr7O3kYZmPgQqv2auuhizLNkrN9k/9PaDbfiGYw5itXny1blxf4Xbj 5Mqx8U/hvZEYDuQ+V/KOKfjkaIm0waOHqo4Q9wPTwDk2YSjr9VoWFYIXggMNRJ6ypkFc N3qBEqzGEKB6TrG3UEHi7EhBCgmrGhobEhjCG9oG9gRNf7kVXXIWX8NGLSjgrBjxjA4i pJgJqcdkHvZPCcL7nvjsno1vKmZH5+bpBRFhH7LlThATs99G1zIt/0Rat/ouim/FUQ4O 6ebUc3KdrGPJfscGuV+VE9Zf4WvkLKWnuWjUStrdtoFBSS3eicEFtuTX/hApgniaW+On djFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741619634; x=1742224434; 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=aJEE3tstWlxClRLN5XCqSGWhwaxxi8RTX0eYkvDKRxQ=; b=uNSyoZltFcLv4XwftZGYzXaFxynr0UTW8TyhvK/sD/y8at7acufIcYc/P5PP5Yd3tU tkE/7R/8sfQkuuEokltayxPd+b8vSDpIpgT19qZyY1myFkHPNY/VcNeJ2uH7WJHepHFb 8WRTaXGxsh7GvKRyw0g6ZSSnsz0tdumQLoiT7KoN2DrL0ALTQaR6czHNdtJeUKKINFiE irHtJEK6oMlyiyVrDb8VqTtj6Uea1e1RZb0tWz2LP3NoKF46I6nXoQG7cTSHEpJfEnUm Wx5W1234yRo4q/Z7D0hILiA+lIETxQQuPWYXlGYfUqIQpkWWSFSaXXU8gB0VEGLTS2FV 3d1A== X-Forwarded-Encrypted: i=1; AJvYcCWKgCrbKXk83zAecUGmXo8810w1bH82trdedIanOQtjPP15QDq9Nh0mmeJHmJ4+7TfI/swgOS5Sc/pv3g==@lists.infradead.org X-Gm-Message-State: AOJu0Yx4tP4TG85eqZUS0a5jwEtbRPGVg9hqZp1AZr2nIJ++Q/bqaiFR xQrgILcD9ixASIdQbLP7yJhkdt1dyrNE1dqQrYQHYqMsqM6AiZmR3qnBJ13l5Uw= X-Gm-Gg: ASbGncslzV3g+WSEvg5hNgtzhb7Jvfg4DsAP/pj4yyNYjG61PGnIBuowa5jzlxiCzB9 jTcZ40UOWBSatXbvZeaPZP6nmaOzAOIq7LrNcz1KOTfF+4xv8SW0a5CXZvgiBpc3oVYt0DvbaS8 rJvPWRcTEKWZsOPCkjzc4CLm76tbMRncGKqHm2NopTck9CfeAEP8/8m7LNJp+xwORroEFNrzWHe UonrWb61vkjZNOcona47s7brMSZJbh74tMAHs5VhxxqIkLF1/KvbHJ7STwQUyKDHBS67l/6lhbH dG3NipRVE7RXRLeAhn/Xo2EER0bLl3tL+RqhS8WDUISCgQ== X-Google-Smtp-Source: AGHT+IFu79SrTcHr6DQ0LZoB48TuSJ0ALQO1FccV1+6ehx1qbYGTJAEYU8+IrRgycH415AfK45aV/g== X-Received: by 2002:a17:902:f68a:b0:220:bcc5:2845 with SMTP id d9443c01a7336-2242888666bmr164594065ad.7.1741619633926; Mon, 10 Mar 2025 08:13:53 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-224109e99dfsm79230515ad.91.2025.03.10.08.13.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Mar 2025 08:13:53 -0700 (PDT) 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 v3 08/17] riscv: misaligned: add a function to check misalign trap delegability Date: Mon, 10 Mar 2025 16:12:15 +0100 Message-ID: <20250310151229.2365992-9-cleger@rivosinc.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250310151229.2365992-1-cleger@rivosinc.com> References: <20250310151229.2365992-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250310_081354_501908_EA1535D6 X-CRM114-Status: GOOD ( 12.08 ) 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 Reviewed-by: Andrew Jones --- 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 db31966a834e..a67a6e709a06 100644 --- a/arch/riscv/kernel/traps_misaligned.c +++ b/arch/riscv/kernel/traps_misaligned.c @@ -716,10 +716,10 @@ static int cpu_online_check_unaligned_access_emulated(unsigned int cpu) } #endif -#ifdef CONFIG_RISCV_SBI - static bool misaligned_traps_delegated; +#ifdef CONFIG_RISCV_SBI + static int cpu_online_sbi_unaligned_setup(unsigned int cpu) { if (sbi_fwft_set(SBI_FWFT_MISALIGNED_EXC_DELEG, 1, 0) && @@ -761,6 +761,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) @@ -773,3 +774,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