From patchwork Mon Jan 6 15:48:37 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: 13927605 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 54372E77199 for ; Mon, 6 Jan 2025 15:51:04 +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: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:In-Reply-To:References: List-Owner; bh=LAhFGhIaLZf+dt+ChBVlguAkfoDoFIGuX8l1htwt+MU=; b=Mh4mzHH8h4ExrM iSUUwgQIbtRA2laJytGx82dFu3h/lE5JdRjKkmWfp1ZNHDI7iPnEdZ5BELWoBvQ9Kx29qr6nPxqXG eELoaV22WdbhUqddVlqe3j1uIZK4YiXw9eao8fWk+8hFQhUkmmaVZ9JYafJXnuE8owO/2FQf/CRp8 j1OfYk3FaNSU8kDFjvHZrgOJCR3ws3uiPevV6mopfoTsHdu5FpTSWeEGf+QSjSS6qkNq9GL4BPXrC 3iuzIIBtiJuU9frBKZgraOcDheuuPSc2pgtmkLc9ynS0Q47bH7BhFaplevGPIx510a8WEQ5FsHOX2 MH7047m+LHb0JdPwGkhw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tUpNb-00000001qTp-1VNG; Mon, 06 Jan 2025 15:50:59 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tUpLn-00000001q1F-0NNv for linux-riscv@lists.infradead.org; Mon, 06 Jan 2025 15:49:08 +0000 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-2166f1e589cso254209355ad.3 for ; Mon, 06 Jan 2025 07:49:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1736178546; x=1736783346; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3GGpStBvhQ5K8XseHJPb5by+BUYzACgXmQyCH18qmBg=; b=auAx6zO6aTv6oJmuvIk4f62yPGDNMobd0nTuFX2D0IxsbajfOG0SVO9jVTtvg9Dltb XA8oZ+2xC87jX158thC8oNFrh2sziBZQQYODiyWy4X+1QMtDTBZuTwmw2goJVacim6AX zVTSx5RO80i306Jhc+qePcWq8kAXztdS1D7KbiIYaZn0eavsofmwLENihjZiVg9jGGEs wB3iNwLfCo7Y4q2cBGRCfmtzcc8DuelI+aavlez0H7icizw/lqdyObLKjOVh7JD1VtLp NBxOwcKXgcBQHNthpT98BF7zm3Y+o/pOD1+WjfIMPYgYaK/dB0drix49L83PFVNmG9y4 Fb6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736178546; x=1736783346; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3GGpStBvhQ5K8XseHJPb5by+BUYzACgXmQyCH18qmBg=; b=CtGeVqnBnR1Uam/qZKpwdVoaWUeuMIrekQgU8tWe0XWxKjthVJERF6YzPpBYTm2unb RKqOPi2Pch+rUe4Mft/xvEpbnl0YAkDykPJFy6eVrmuR+GSFEE6dd7Q+rbrxv2WL6hDn zQPS/6JYSir/1ttrgaLMUJaLhUp77F7+6ObQVsM5Kepm0F4HlyeXuLKDAbSixRWZkPMt s6PBKsrbXlbBMsx0feqh1/QKzNMtg/LYm8riWjUtSgLkIeGMKAROYU3bMhaMM5VHsMOf zbvSI8izDFbF1zq3QksZzSkTsh1EwXLbI5Ud0C1PYd2EwPkj5i1zKkQO2pqrjqpE5fO2 kfFA== X-Forwarded-Encrypted: i=1; AJvYcCWsLsKpOeF4chbfPhahila0l7Yup+Bz1oi1sTD/UVtH9r4jweJtx+7js4SQ+K/zUe86ZjiejAfxKQjMKA==@lists.infradead.org X-Gm-Message-State: AOJu0YzKqO1DQW1x2Atke+M5g9HgGzLLwoFyoGH3rfHRE8AP05EVPI+m dV/i3wgRhhdXizia8kz6/VOXYqOlD3nQ9ct09uhlp0wvCkYnwrsX/AQBRTVT8xs= X-Gm-Gg: ASbGnctRx5WRIheOPh10i3QLOqoMUmKBSy0Y2Xht6UzZVlN6thBpK/GN62LM0OntQhN l1FZ5S+IT+0z2HOk/JQxCPwOBMILehVnLoHgz9TynoxwCkiZhqCscUQJeC+gbm6DzXMTyYku+wB XTrIzGx0cExN3unYnHUoD2v7y2S4rre0ukEZvntZTk2qHQP4phY41fRRO0626CUHAUUySLQany8 vIRosEoYEAQwEzgF0OcfZ/Pe8X8HVKxerufeyinbXz4jXN6mOtMNHvCwQ== X-Google-Smtp-Source: AGHT+IEPJYkB+GjJZ58TJzg7jlP2DmeS3NY6LvjoJXuDWaiGaC9bRpxjyB6+IigEUT+Axr/d/VfYnA== X-Received: by 2002:a17:90b:2752:b0:2ee:fdf3:38ea with SMTP id 98e67ed59e1d1-2f452ec714amr77626971a91.23.1736178545785; Mon, 06 Jan 2025 07:49:05 -0800 (PST) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc9f6967sm292479535ad.214.2025.01.06.07.48.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 07:49:05 -0800 (PST) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Paul Walmsley , Palmer Dabbelt , Anup Patel , Atish Patra , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= Subject: [PATCH 0/6] riscv: add SBI FWFT misaligned exception delegation support Date: Mon, 6 Jan 2025 16:48:37 +0100 Message-ID: <20250106154847.1100344-1-cleger@rivosinc.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250106_074907_123498_70151799 X-CRM114-Status: GOOD ( 13.09 ) 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 The SBI Firmware Feature extension allows the S-mode to request some specific features (either hardware or software) to be enabled. This series uses this extension to request misaligned access exception delegation to S-mode in order to let the kernel handle it. It also adds support for the KVM FWFT SBI extension based on the misaligned access handling infrastructure. FWFT SBI extension is part of the SBI V3.0 specifications [1]. It can be tested using the qemu provided at [2] which contains the series from [3]. kvm-unit-tests [4] can be used inside kvm to tests the correct delegation of misaligned exceptions. Upstream OpenSBI can be used. The test can be run using a small utility[5] as well as using kvm-tools: $ qemu-system-riscv64 \ -cpu rv64,trap-misaligned-access=true,v=true \ -M virt \ -m 1024M \ -bios fw_dynamic.bin \ -kernel Image ... # ./unaligned Buf base address: 0x5555756ff0f0 Testing emulated misaligned accesses, size 2, offset 1 Testing non-emulated misaligned accesses, size 2, offset 1 Testing emulated misaligned accesses, size 4, offset 1 Testing non-emulated misaligned accesses, size 4, offset 1 Testing emulated misaligned accesses, size 4, offset 2 Testing non-emulated misaligned accesses, size 4, offset 2 Testing emulated misaligned accesses, size 4, offset 3 Testing non-emulated misaligned accesses, size 4, offset 3 Testing emulated misaligned accesses, size 8, offset 1 Testing non-emulated misaligned accesses, size 8, offset 1 Testing emulated misaligned accesses, size 8, offset 2 Testing non-emulated misaligned accesses, size 8, offset 2 Testing emulated misaligned accesses, size 8, offset 3 Testing non-emulated misaligned accesses, size 8, offset 3 Testing emulated misaligned accesses, size 8, offset 4 Testing non-emulated misaligned accesses, size 8, offset 4 Testing emulated misaligned accesses, size 8, offset 5 Testing non-emulated misaligned accesses, size 8, offset 5 Testing emulated misaligned accesses, size 8, offset 6 Testing non-emulated misaligned accesses, size 8, offset 6 Testing emulated misaligned accesses, size 8, offset 7 Testing non-emulated misaligned accesses, size 8, offset 7 # lkvm run -k sbi.flat -m 128 Info: # lkvm run -k sbi.flat -m 128 -c 1 --name guest-97 Info: Removed ghost socket file "/root/.lkvm//guest-97.sock". ########################################################################## # kvm-unit-tests ########################################################################## ... [test messages elided] PASS: sbi: fwft: FWFT extension probing no error PASS: sbi: fwft: get/set reserved feature 0x6 error == SBI_ERR_DENIED PASS: sbi: fwft: get/set reserved feature 0x3fffffff error == SBI_ERR_DENIED PASS: sbi: fwft: get/set reserved feature 0x80000000 error == SBI_ERR_DENIED PASS: sbi: fwft: get/set reserved feature 0xbfffffff error == SBI_ERR_DENIED PASS: sbi: fwft: misaligned_deleg: Get misaligned deleg feature no error PASS: sbi: fwft: misaligned_deleg: Set misaligned deleg feature invalid value error PASS: sbi: fwft: misaligned_deleg: Set misaligned deleg feature invalid value error PASS: sbi: fwft: misaligned_deleg: Set misaligned deleg feature value no error PASS: sbi: fwft: misaligned_deleg: Set misaligned deleg feature value 0 PASS: sbi: fwft: misaligned_deleg: Set misaligned deleg feature value no error PASS: sbi: fwft: misaligned_deleg: Set misaligned deleg feature value 1 PASS: sbi: fwft: misaligned_deleg: Verify misaligned load exception trap in supervisor SUMMARY: 50 tests, 2 unexpected failures, 12 skipped This series is available at [6]. Link: https://github.com/riscv-non-isa/riscv-sbi-doc/releases/download/vv3.0-rc2/riscv-sbi.pdf [1] Link: https://github.com/rivosinc/qemu/tree/dev/cleger/misaligned [2] Link: https://lore.kernel.org/all/20241211211933.198792-3-fkonrad@amd.com/T/ [3] Link: https://github.com/clementleger/kvm-unit-tests/tree/dev/cleger/fwft_v1 [4] Link: https://github.com/clementleger/unaligned_test [5] Link: https://github.com/rivosinc/linux/tree/dev/cleger/fwft_v1 [6] --- Clément Léger (6): riscv: add Firmware Feature (FWFT) SBI extensions definitions riscv: request misaligned exception delegation from SBI RISC-V: KVM: add SBI extension init()/deinit() functions RISC-V: KVM: add support for FWFT SBI extension riscv: export unaligned_ctl_available() as a GPL symbol RISC-V: KVM: add support for SBI_FWFT_MISALIGNED_DELEG arch/riscv/include/asm/cpufeature.h | 1 + arch/riscv/include/asm/kvm_host.h | 4 + arch/riscv/include/asm/kvm_vcpu_sbi.h | 10 + arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h | 37 ++++ arch/riscv/include/asm/sbi.h | 28 +++ arch/riscv/include/uapi/asm/kvm.h | 1 + arch/riscv/kernel/traps_misaligned.c | 61 ++++++ arch/riscv/kernel/unaligned_access_speed.c | 2 + arch/riscv/kvm/Makefile | 1 + arch/riscv/kvm/vcpu.c | 5 + arch/riscv/kvm/vcpu_sbi.c | 35 +++- arch/riscv/kvm/vcpu_sbi_fwft.c | 215 +++++++++++++++++++++ 12 files changed, 399 insertions(+), 1 deletion(-) create mode 100644 arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h create mode 100644 arch/riscv/kvm/vcpu_sbi_fwft.c