From patchwork Mon Mar 17 17:06: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: 14019760 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 3FC3EC35FFA for ; Mon, 17 Mar 2025 17:13:14 +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=YDQOvO/GH3TUvNprBLHNLAgZGPJSyDdtB/bJMzB/QuQ=; b=loJ/95QylrBnAO yPVcD3gYTfv9shcGOLoBU8izJTHpHgBiiY8BM2itUqDvdrLUcI/ENRg7mF4J49cOkj6GFOEg+RUsc f0VZLQyYzmVLgYFk2q3OYz42bUF3yVbYclFMZSL65rb69Dktt4eVwWNKLd2m+dGqgXjwKWVqfAOJM fV6FlZlGgJqAa7l2ob3RyV4d+cNOMMYMDCcpT5NVirKjDHiDT/IrPATEt2PiuT5d4Q7vWkdRf2U2E rOu8uCVUW/wc8M7RXjYGsU77v4qds4ZtrKVIJ6umaF1LkkkumhFTEe249QitPyEg2TZ3aLheonfT8 OR3GmVNHePE4gjfNwXww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tuE1V-00000003V6d-3W0x; Mon, 17 Mar 2025 17:13:09 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tuDwo-00000003TU5-0GN0 for linux-riscv@lists.infradead.org; Mon, 17 Mar 2025 17:08:19 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-43d0359b1fcso15670615e9.0 for ; Mon, 17 Mar 2025 10:08:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1742231297; x=1742836097; 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=goQPfqUUhZrDcxyWXuqyDL1Ho5AqcAiizxxMLq8C+LA=; b=RRB2GAS4pT4TAS9+BLMWuAaxwz9n4UnENwCVxdPJtH/POVRI5HKIG2/r1qsbMB/LKq aEXWJzyrFvJbpCzMBILUEYzH4neWeKQsFDFVo8PhjaxWxN2HGSNIntharY98YqnadzeV gH1KJHY9237AA+sCLExpDSM72GT5W0TFxs3K1YYhB5otbnfEiW/5KZ6RFpeJ7fip0tMl eHGqvM4lW927aPj5ChKSKQWjP61WupUXG7ot8SrQuskvmoR+LvbUxL0/HxPV/6RwYCKE hZXgDXBBUiJo598NZ8Due1aT1rPzBw45syJCZFtWuwJiNLchE9DcXVd+wKFb/im1DiZH hJOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742231297; x=1742836097; 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=goQPfqUUhZrDcxyWXuqyDL1Ho5AqcAiizxxMLq8C+LA=; b=NlKJZN5nooRYl5bufwda/MS5yw1NI+fgdVkSD33cJBSuRasxLo7DqkcKWeeIgHbUMY sSFsrab0ecOf7BFtXlAv+w3V+ZxRzjhh/XoV3MAKt7raZKRJM+S2kC4opVcaM4jsy5Ri ReI+Jm7aX0vTskVeE+mKmhdMi4RXJlswpXBMGeB3EPksoln0plFX9DJQs8n7uCYNyVj3 hoSZiXycUxqSUGpcizVov8Bux7BQGKzSaBXHK955NVFdhiYSIAr9Kh5iiR98l5HtyaLq cPYip5M9zKLxmHMD3oQbLKawPJyMtIiq0g6DS8EhAL8ZiV1x7d/m8mEkqeHn6tdeZpIZ cOzA== X-Forwarded-Encrypted: i=1; AJvYcCVhclRUvlbjUfA72SDH6X5AATno5ffKpQ/PWnxfCfH6KPa6syJFtTKywU3APyDdGgPcliD+jwDu22DhvA==@lists.infradead.org X-Gm-Message-State: AOJu0YyfZ87V7w5nmArWlM0g9H8Pd2FRW6GRaMlcpZlbS2D1tLg+SHnS kuz1j7FL85f5oQ1jWNXSfaOlNQEtlMDkJGjHqeyLT58BWb2TU7eNUrQU1a7Gwpo= X-Gm-Gg: ASbGncuBxEt6kzScOnEDlJGKY6i7afKo28idZz9NMExtspg7HKgW7pZLzi5qiLOmi0k haE9/PrHnZ4dImUfRaLbkvdk5Q4KP9mqVaVS8rt5yjRpE8gCEBQ9NW+qjITevwfJ91qoxY6dirh tgv/Pq1Oy+76Vlu16LVkjdl9xz2/Wd0+FbqyMOYNl13B4S3QJ7n/JmxhRJqYVeo9zeb0CQnIBEp hh3/sOZnReQQEzWsgalYm2OTce+eHzGcTtTu8vjReLA9qVX8fLRZUPoyqG/NJBp4qlxGXFqPgDd EYS4Q8djEhxiU8VSsQKPRAGhMpID79w4kC3iftJvejUvlw== X-Google-Smtp-Source: AGHT+IFputIgv6zhtm+v7+MGBN3nI7X+BtRN1fT5rRbozYZS+RzAoNXF9CqISuMs9K5H8TPGERcLdQ== X-Received: by 2002:a05:600c:4e51:b0:439:8878:5029 with SMTP id 5b1f17b1804b1-43d38f72af6mr2448325e9.2.1742231296757; Mon, 17 Mar 2025 10:08:16 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d23cddb2asm96014505e9.39.2025.03.17.10.08.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Mar 2025 10:08:16 -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 , Andrew Jones Subject: [PATCH v4 09/18] riscv: misaligned: add a function to check misalign trap delegability Date: Mon, 17 Mar 2025 18:06:15 +0100 Message-ID: <20250317170625.1142870-10-cleger@rivosinc.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250317170625.1142870-1-cleger@rivosinc.com> References: <20250317170625.1142870-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250317_100818_119791_AE7887BC X-CRM114-Status: GOOD ( 11.36 ) 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 3c77fc78fe4f..0fb663ac200f 100644 --- a/arch/riscv/kernel/traps_misaligned.c +++ b/arch/riscv/kernel/traps_misaligned.c @@ -715,10 +715,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) && @@ -760,6 +760,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) @@ -772,3 +773,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);