From patchwork Mon Jan 6 15:48:38 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: 13927596 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C926D1DBB13 for ; Mon, 6 Jan 2025 15:49:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736178554; cv=none; b=Ef2BzwetnGaAHUDUaXg4wkfpmk17w4r8ckJQuHe/CgC4byXpcQASevQiOYc+3p4/4d31B1Xdb1NkMHo6ZcabiYN8oZELGU9OJFxcSX0RoIAwNLMGglGT1mIPOZLqxHySIdDMWbjmZaps0AEKWWj2FV1OU2Ieewac6jl66goB9a8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736178554; c=relaxed/simple; bh=KJViQbIKB51hAmzJsn4Tca3rpV3uTsCs5XwY4x4I6Mc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uvOuiQk6c5cMPvdiV1brPkE3rui4Rg4v+ka9Qw0MtVEQEDd5gyO9L8ZTeYcSriD2VxvQgJcc7erP/dJuGk/FvbmBJwDJhymM0Qn1k8PS7ebu4KhjplKuYRCBSKnX7Px6vfSvVg0B/yHOtR9R1mk4VczhLC/1I2hcjl0M6kH7saA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=dTsdyakz; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="dTsdyakz" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-216401de828so197556015ad.3 for ; Mon, 06 Jan 2025 07:49:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1736178552; x=1736783352; darn=vger.kernel.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=YWWbvbVWcBkTLDmBWRGuP/373zfHHQD7CsE6sYbpx+8=; b=dTsdyakzKfleJvvMixWTIgLaIhfi7Be/jGyyhzbC81o1RlJklegP9a3+rrsNlNOMVU bBOkCbO+0/JMC1TLn2TaA3J3ijEr5kNsiZTy7ZFmJnCy60dU6NVlHRr+um3aBTeyGgv0 nc5KrF4r4PSNyeLQORYiE5LzGFbWydgbp5Ff65VQxSFDnqXyyJPccLVpXunYf4mfvQlW aEQJshSr8GvP8jLpaT6prOKxGSDtBYsCVqXk4EfY12Ec+G1W+2f9D0otUKoUfQOH5DV8 UpcuNTMc+9l9uu4kcPCFb3ZFFo4YNLkEdIT2BpZAeOacaGb/tSSnuqrcOVeqPlCDSuMq /k/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736178552; x=1736783352; 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=YWWbvbVWcBkTLDmBWRGuP/373zfHHQD7CsE6sYbpx+8=; b=B/3/kY3D8fsUoypYEnlLLDsqBXaVhvVhhlsq+y6EN/NWVuV1xVYzG1WjOwwYHfFSbF HdSNHea4DJw/S8DTRixYmUlT4AE8MmaPhmvUZNvFtb0DkZAZtRTHVfqRgmpDAMxf+DH4 Eud534miVP52PxuhSa++IGghUhW+SNp4pTewNxuc6VfinVy6fH9lA0QztebDqHkpUa1J Uq48UvyHll3hsZZZ4egOVgiYNFu5ccfU852Nvwdh2i2IrNrZUWQCyqhpjFV8t31tdg8u 9sFWQo36Xoyq2/GgX0lyEIHpCzsTn/qimmBHC1m1M8np33tO6cg7qbbkqopjASmTG2ZM 9byg== X-Forwarded-Encrypted: i=1; AJvYcCXBBlMPXg22ufmv0wqitlhPyvYIZIhLSXPsD3yElmKw+qHcvRk20C00qS2dQCnN+kgbOIA=@vger.kernel.org X-Gm-Message-State: AOJu0Yw2UVsBHbeWihue5onnJ45jsmbKpb9XW6Xtm/7DKm9DcEHUAqM/ 22iyFtrvPZpoB0WOrcKC/Zv1ZpUgmNnAeLKK0K5NHIhEy5fSHFn4g1Dinf77+V0= X-Gm-Gg: ASbGncsN/Hy5rGD00FyJoFz4NzOetzZJqu+HhjlQc/gkcuhvchREsBAU9UpnAyEhWM3 FLg+LX01d1KEJfJpSKIYCfyDxRSxDNhDFqdf2ypqLOs77wJhmZSXSvKK/AtLJ4AeEEPArsCZsn1 MojjpM4B7nEaOAigeEa4+Ay1cn5gWolN+urBw/L8lzw8e70RUv0mKMrdOe9gNjdjs1rp2YDVPrc QVj0VUx9p/ufHlhhSwAvXS/K647pKYzDWB0vlQmbl2j18wasFPoJNwo7A== X-Google-Smtp-Source: AGHT+IFsrR++da94vh57i8gZG2YCIfCJlCqOllnoSuVQjwf/TtLCIaXs8yZigKmfjKjyX3pC2+VXhQ== X-Received: by 2002:a17:902:d2c7:b0:216:5448:22a4 with SMTP id d9443c01a7336-219e6e89a6dmr805222645ad.10.1736178552138; Mon, 06 Jan 2025 07:49:12 -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.49.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 07:49:11 -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 1/6] riscv: add Firmware Feature (FWFT) SBI extensions definitions Date: Mon, 6 Jan 2025 16:48:38 +0100 Message-ID: <20250106154847.1100344-2-cleger@rivosinc.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106154847.1100344-1-cleger@rivosinc.com> References: <20250106154847.1100344-1-cleger@rivosinc.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The Firmware Features extension (FWFT) was added as part of the SBI 3.0 specification. Add SBI definitions to use this extension. Signed-off-by: Clément Léger --- arch/riscv/include/asm/sbi.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 6c82318065cf..ec78de071e0e 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -35,6 +35,7 @@ enum sbi_ext_id { SBI_EXT_DBCN = 0x4442434E, SBI_EXT_STA = 0x535441, SBI_EXT_NACL = 0x4E41434C, + SBI_EXT_FWFT = 0x46574654, /* Experimentals extensions must lie within this range */ SBI_EXT_EXPERIMENTAL_START = 0x08000000, @@ -401,6 +402,33 @@ enum sbi_ext_nacl_feature { #define SBI_NACL_SHMEM_SRET_X(__i) ((__riscv_xlen / 8) * (__i)) #define SBI_NACL_SHMEM_SRET_X_LAST 31 +/* SBI function IDs for FW feature extension */ +#define SBI_EXT_FWFT_SET 0x0 +#define SBI_EXT_FWFT_GET 0x1 + +enum sbi_fwft_feature_t { + SBI_FWFT_MISALIGNED_EXC_DELEG = 0x0, + SBI_FWFT_LANDING_PAD = 0x1, + SBI_FWFT_SHADOW_STACK = 0x2, + SBI_FWFT_DOUBLE_TRAP = 0x3, + SBI_FWFT_PTE_AD_HW_UPDATING = 0x4, + SBI_FWFT_POINTER_MASKING_PMLEN = 0x5, + SBI_FWFT_LOCAL_RESERVED_START = 0x6, + SBI_FWFT_LOCAL_RESERVED_END = 0x3fffffff, + SBI_FWFT_LOCAL_PLATFORM_START = 0x40000000, + SBI_FWFT_LOCAL_PLATFORM_END = 0x7fffffff, + + SBI_FWFT_GLOBAL_RESERVED_START = 0x80000000, + SBI_FWFT_GLOBAL_RESERVED_END = 0xbfffffff, + SBI_FWFT_GLOBAL_PLATFORM_START = 0xc0000000, + SBI_FWFT_GLOBAL_PLATFORM_END = 0xffffffff, +}; + +#define SBI_FWFT_PLATFORM_FEATURE_BIT (1 << 30) +#define SBI_FWFT_GLOBAL_FEATURE_BIT (1 << 31) + +#define SBI_FWFT_SET_FLAG_LOCK (1 << 0) + /* SBI spec version fields */ #define SBI_SPEC_VERSION_DEFAULT 0x1 #define SBI_SPEC_VERSION_MAJOR_SHIFT 24 From patchwork Mon Jan 6 15:48: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: 13927597 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BD9916D9B8 for ; Mon, 6 Jan 2025 15:49:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736178561; cv=none; b=C+M/mWyL79lQQN2HDG1opw3IHZZQVhqxv4Yrs0GDzjdaDunop7YV/rCOAaNvbdvUGrjux+T2TOzYg3bNC87O7rKi/PByKi4GPQknescgs6JxlNAsbagXPW805O5MLmbDR6oU648vBw9UsDPk80vANdcfAL/VtvAVl/1Wu7AFwCE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736178561; c=relaxed/simple; bh=wpnt0dYFW/QmOcPu7DwJHbFXJcaNGQ3V61Y7MK2RfEc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AVFOGc7WhyIMWBoYlEYHJgppXqeubiTmPsQFQK2FYm8N1Rpps680HtGgMqCOn9QQwHjPzWLH6ZjcRPDOJwzPc+YviW8F3LvjcqZO+B/YfEU7K+PPQXHhvXrT0MXAwQN+52SV83e9oVKUHZ+pza4pymZB41S67oZaSLnWOknYHnw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=hopdBrqu; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="hopdBrqu" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2161eb94cceso147535955ad.2 for ; Mon, 06 Jan 2025 07:49:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1736178558; x=1736783358; darn=vger.kernel.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=hUAp13cfLrcRgomb+YDwJflWyLOeBTRPSVeLvL2aSrw=; b=hopdBrquTptvhx9a6Ae/iSawSOVTVzk4NI0nQNHQwE47ECq/A4Fv0uyDZ4dwj8fZWM wlqoYGMYCBaZ2wNSFj0QabzLXb/FFNoX1McE1IOmOe4UJkbp1qQDFz0G1cVQHNklYbVL OnJEQ1qa50kxeqGyGaErEAbmIsLTA92QSUiB80WKa4o9CYxdIk/GroFSwXlgtd/hR7GR GKq63somwd4bIzQ+QqI097pGuxzDs3E5ePbmIAFIBWR0Dn1o6iMrCn+1fnQAKjntc98N 52Qs9zdpatH++doyvGnGY/YKbHpn6WdVkh8/qj8GJujQEt7aNm20BAHaOCluW0rbTFO0 i7lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736178558; x=1736783358; 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=hUAp13cfLrcRgomb+YDwJflWyLOeBTRPSVeLvL2aSrw=; b=hCtJBfZyN5sSqnALeKFvOum6RouTIwjmAxgFbzClIf0ogLQY3ktrk1eKxnKPpO7M/K zusDGJiBzGZERbksGB4ww6Qwbwgv991pr7fVBf8FzKjSVTP/Nxc8ExYsCV6hwQc/go7F OCjX6306D0XcUmN5+6+ZXqZr3/XIBDOY+0MpXqfsNiu5FCRAOw4q7wlLc/PmT+lNg7QT DFb8q1NAqwZrT9wZ4tk3szekjLModjQ4ohmqfiLL93e7ayLKr4n/Xfs1inQC79YNIlhq 73z2XSe7MMOmdu5Gu6YH/1RH8/H7rLleKlsz1FVkz5KnqCWEJrDw6rSXaFWhOXaUfWHt CaMA== X-Forwarded-Encrypted: i=1; AJvYcCWR5oZ9vu1lgnjxym4ulDi/l3cGo5WeC3pxJ1PwKEUNsCRNOGsZA5+ojVwFmjoQ7AnB6mE=@vger.kernel.org X-Gm-Message-State: AOJu0YyDCSkVrHdW/kILHl1IhW5qWCEZiW+lj6oB1A5+cEVHSkTmP3wO VUKmw6z5zrAAASRShvLVUJQCyFbHFiyhcP+PqxVBO8VEpZHszv/nnNTjl8TqAJ8= X-Gm-Gg: ASbGncsIwTstqtD3b12yqjbb+XWJ5+iS53TlA0WtEJrNDwsPxn632AkEx+6j6czUaei 7ue7mxpDv2+pR5cBia7kQ38NPsqyk+zvwLXG6y9ZiCbjbLf2aFxeuIJj7jpQFBIo27tlfKaYCCx 0Zabcu6gOXdQKnn7CJSsOErIZTtqtpgsf0sQZtCA4VFMccMo38L5Vtf3wJG0BkdIO86nnLRW5AG 2ki27jMvM4FkWOaN4Exw3oubPaS0HT2VaJUGYwtNxsZbuyl+C8YZ5Pcig== X-Google-Smtp-Source: AGHT+IEAi4C08D2uh9ehheSrgZdf7WN1M3JGxvQSdR5w+ojassJn4RAe3pkLwbVvSQ+6CKRXrqzn6Q== X-Received: by 2002:a17:903:946:b0:216:2af7:a2a3 with SMTP id d9443c01a7336-219e6f27157mr1007178485ad.53.1736178558552; Mon, 06 Jan 2025 07:49:18 -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.49.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 07:49:17 -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 2/6] riscv: request misaligned exception delegation from SBI Date: Mon, 6 Jan 2025 16:48:39 +0100 Message-ID: <20250106154847.1100344-3-cleger@rivosinc.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106154847.1100344-1-cleger@rivosinc.com> References: <20250106154847.1100344-1-cleger@rivosinc.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that the kernel can handle misaligned accesses in S-mode, request misaligned access exception delegation from SBI. This uses the FWFT SBI extension defined in SBI version 3.0. Signed-off-by: Clément Léger Reviewed-by: Jesse Taube --- arch/riscv/include/asm/cpufeature.h | 1 + arch/riscv/kernel/traps_misaligned.c | 59 ++++++++++++++++++++++ arch/riscv/kernel/unaligned_access_speed.c | 2 + 3 files changed, 62 insertions(+) diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm/cpufeature.h index 4bd054c54c21..cd406fe37df8 100644 --- a/arch/riscv/include/asm/cpufeature.h +++ b/arch/riscv/include/asm/cpufeature.h @@ -62,6 +62,7 @@ void __init riscv_user_isa_enable(void); _RISCV_ISA_EXT_DATA(_name, _id, _sub_exts, ARRAY_SIZE(_sub_exts), _validate) bool check_unaligned_access_emulated_all_cpus(void); +void unaligned_access_init(void); #if defined(CONFIG_RISCV_SCALAR_MISALIGNED) void check_unaligned_access_emulated(struct work_struct *work __always_unused); void unaligned_emulation_finish(void); diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/traps_misaligned.c index 7cc108aed74e..4aca600527e9 100644 --- a/arch/riscv/kernel/traps_misaligned.c +++ b/arch/riscv/kernel/traps_misaligned.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #define INSN_MATCH_LB 0x3 @@ -689,3 +690,61 @@ bool check_unaligned_access_emulated_all_cpus(void) return false; } #endif + +#ifdef CONFIG_RISCV_SBI + +struct misaligned_deleg_req { + bool enable; + int error; +}; + +static void +cpu_unaligned_sbi_request_delegation(void *arg) +{ + struct misaligned_deleg_req *req = arg; + struct sbiret ret; + + ret = sbi_ecall(SBI_EXT_FWFT, SBI_EXT_FWFT_SET, + SBI_FWFT_MISALIGNED_EXC_DELEG, req->enable, 0, 0, 0, 0); + if (ret.error) + req->error = 1; +} + +static void unaligned_sbi_request_delegation(void) +{ + struct misaligned_deleg_req req = {true, 0}; + + on_each_cpu(cpu_unaligned_sbi_request_delegation, &req, 1); + if (!req.error) { + pr_info("SBI misaligned access exception delegation ok\n"); + /* + * Note that we don't have to take any specific action here, if + * the delegation is successful, then + * check_unaligned_access_emulated() will verify that indeed the + * platform traps on misaligned accesses. + */ + return; + } + + /* + * If at least delegation request failed on one hart, revert misaligned + * delegation for all harts, if we don't do that, we'll panic at + * misaligned delegation check time (see + * check_unaligned_access_emulated()). + */ + req.enable = false; + req.error = 0; + on_each_cpu(cpu_unaligned_sbi_request_delegation, &req, 1); + if (req.error) + panic("Failed to disable misaligned delegation for all CPUs\n"); + +} + +void unaligned_access_init(void) +{ + if (sbi_probe_extension(SBI_EXT_FWFT) > 0) + unaligned_sbi_request_delegation(); +} +#else +void unaligned_access_init(void) {} +#endif diff --git a/arch/riscv/kernel/unaligned_access_speed.c b/arch/riscv/kernel/unaligned_access_speed.c index 91f189cf1611..1e3166100837 100644 --- a/arch/riscv/kernel/unaligned_access_speed.c +++ b/arch/riscv/kernel/unaligned_access_speed.c @@ -403,6 +403,8 @@ static int check_unaligned_access_all_cpus(void) { bool all_cpus_emulated, all_cpus_vec_unsupported; + unaligned_access_init(); + all_cpus_emulated = check_unaligned_access_emulated_all_cpus(); all_cpus_vec_unsupported = check_vector_unaligned_access_emulated_all_cpus(); From patchwork Mon Jan 6 15:48:40 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: 13927598 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B48C14900B for ; Mon, 6 Jan 2025 15:49:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736178570; cv=none; b=NpptGoDDRHlOFI8ttVXq2jM4J1Y5lZfftk6yephCeh3bLZnAZOe+cOq2xgvAdRYbNPd+3pIM0OY4tDNClAVxYo3dCU4huoFMPyXaEr1DUMeVVUDXKI6Ofrk1LtHDYgo+mKHWn1JgfJ/A9GnpUunLqX+GNGMAZrmjAY8uBBFim3k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736178570; c=relaxed/simple; bh=uuAHTstZa1Zpk6rx2ds/OHmd2ADhPuNSZeEnxaM5EGk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OIzkEwHlW0bpaKmNEx35GsBPzuvHFwcG7QF792MFwl7Mz3mFilWHlVMd/PDppaRGHy3fP2cFA+zApsykVgSoZdLKJh+IPaHNE8bXnovz58M0Y7/LtKo+fwXWEW2R9O6kQQnjSs/XbDn6tFOigpIWlxXk9VwfBPWo4CD1+zJqJN0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=15pRzSOo; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="15pRzSOo" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-21636268e43so26715445ad.2 for ; Mon, 06 Jan 2025 07:49:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1736178566; x=1736783366; darn=vger.kernel.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=mxBjx4Pwy3s9wNFrCu0QzGcTxzWHmeeGktVNtPbGFVU=; b=15pRzSOocDahB4E5LOkq53HyqOWAhjQVm/Hbhxl0GMhX9BQeclZOyK62doxPzduZey ET4TxGQXL6NhavzSqSQvs8ptSlt8llCu3qaV8Gku+HKrBU5AS5fdXjcEXtf1XTIitfNV LpRLTSQ3J3wT1SGxVzBFeHrqbXH8TnWZg91ldeiJuYW7RI4GUyFTTRqDAaa16lOu7mx4 Br6D75cA5CK/95wB2XkE937AVnVx1X+FTsFIIyz7YTwN5sd5W63xZ2ll/pJemx/1Xs7P ApzpEkSQqxm75r/vSQj1ra6Cxm9iiicS4ANy8lIWx3tzpw0PtpyvoJyOG5zHlVBglI2S /QoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736178566; x=1736783366; 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=mxBjx4Pwy3s9wNFrCu0QzGcTxzWHmeeGktVNtPbGFVU=; b=K5rdTEATGpm/W/Ljg0XjZzA86V6coaDjaNslAkit0I9Sa/hwubQpW9wTXCiBpuZdZF 5IJ+99/gqLSoeU2qQ98XixoBe0nNHFrYtbPQJk3obJcM4kWoxpYt39sXpE7Z9a1dqqpH pf4E2A/OxX4gtl42WfddSZmGf2hxrBJBDqm+G1HxTy0aL+zLVvcrQSA9vQTIz2zsO/0K xttBvIPJBSxPbax5Fu8KJ71yH4zQdfwv1GYSj2Iwfbg1gW6wBiJJNSzc5FwznZwt1VNK 83cah6i9mbJuvTI3z1a5tQxHntcL8OpfBrWt2m6VcGx7ig9S+OzTDPiV8E05jZIvanB0 MshQ== X-Forwarded-Encrypted: i=1; AJvYcCXfioczGQ/Ww6ToNsX5DoDEqPYasbI+deZ7febORyg3tyHANngV+sjH8ysHWNyP+gaQkL4=@vger.kernel.org X-Gm-Message-State: AOJu0Ywlo/nZLpulu1ZrtV7DrfHqBSu0FCOWbHToSv71XulTiHrw74V4 8a371IzCMIpVR5pEM8WmIf3IGcmhpxn87vEG6VC39s66oM3WuzSghJ9F45coO9Q= X-Gm-Gg: ASbGnct91BAn50jk4ei+1MmdvS9TgSwLNmqSqYkWzKY2fldEaYV9mIrJ0MsTEKHmy+7 sBnbSqHEcdzLq5sUIWB2ZupKjIN5u5Htqx99hB/0J621SWIcofgdRcLhv+TyOHCOsEgoje2R/zE AeLPv0DoQvXNWvbAhk/c6Y7Awe1lp+t2jZrAIMVgaFbnx3K1Sxj0mZ6IUHAKArJ9N5vqqE3lMAD w5TuSBQrACy4FhKD29LlMwbybVEE+68w1mFEEF+2tVkSXRmGeH/rpuZ+Q== X-Google-Smtp-Source: AGHT+IFBFcio9MaUGZCTb/Jg2857ywT0hQvVtOg6GlbEZCyc6I2hLialdck8Jevr/BDDD1XTJo/mLA== X-Received: by 2002:a17:902:c406:b0:216:2bd7:1c4a with SMTP id d9443c01a7336-219e6ebb716mr872299045ad.26.1736178564924; Mon, 06 Jan 2025 07:49:24 -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.49.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 07:49:24 -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 3/6] RISC-V: KVM: add SBI extension init()/deinit() functions Date: Mon, 6 Jan 2025 16:48:40 +0100 Message-ID: <20250106154847.1100344-4-cleger@rivosinc.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106154847.1100344-1-cleger@rivosinc.com> References: <20250106154847.1100344-1-cleger@rivosinc.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The FWFT SBI extension will need to dynamically allocate memory and do init time specific initialization. Add an init/deinit callbacks that allows to do so. Signed-off-by: Clément Léger --- arch/riscv/include/asm/kvm_vcpu_sbi.h | 9 ++++++++ arch/riscv/kvm/vcpu.c | 2 ++ arch/riscv/kvm/vcpu_sbi.c | 31 ++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi.h b/arch/riscv/include/asm/kvm_vcpu_sbi.h index b96705258cf9..8c465ce90e73 100644 --- a/arch/riscv/include/asm/kvm_vcpu_sbi.h +++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h @@ -49,6 +49,14 @@ struct kvm_vcpu_sbi_extension { /* Extension specific probe function */ unsigned long (*probe)(struct kvm_vcpu *vcpu); + + /* + * Init/deinit function called once during VCPU init/destroy. These + * might be use if the SBI extensions need to allocate or do specific + * init time only configuration. + */ + int (*init)(struct kvm_vcpu *vcpu); + void (*deinit)(struct kvm_vcpu *vcpu); }; void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run); @@ -69,6 +77,7 @@ const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_find_ext( bool riscv_vcpu_supports_sbi_ext(struct kvm_vcpu *vcpu, int idx); int kvm_riscv_vcpu_sbi_ecall(struct kvm_vcpu *vcpu, struct kvm_run *run); void kvm_riscv_vcpu_sbi_init(struct kvm_vcpu *vcpu); +void kvm_riscv_vcpu_sbi_deinit(struct kvm_vcpu *vcpu); int kvm_riscv_vcpu_get_reg_sbi_sta(struct kvm_vcpu *vcpu, unsigned long reg_num, unsigned long *reg_val); diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index e048dcc6e65e..3420a4a62c94 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -180,6 +180,8 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu) void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu) { + kvm_riscv_vcpu_sbi_deinit(vcpu); + /* Cleanup VCPU AIA context */ kvm_riscv_vcpu_aia_deinit(vcpu); diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c index 6e704ed86a83..d2dbb0762072 100644 --- a/arch/riscv/kvm/vcpu_sbi.c +++ b/arch/riscv/kvm/vcpu_sbi.c @@ -486,7 +486,7 @@ void kvm_riscv_vcpu_sbi_init(struct kvm_vcpu *vcpu) struct kvm_vcpu_sbi_context *scontext = &vcpu->arch.sbi_context; const struct kvm_riscv_sbi_extension_entry *entry; const struct kvm_vcpu_sbi_extension *ext; - int idx, i; + int idx, i, ret; for (i = 0; i < ARRAY_SIZE(sbi_ext); i++) { entry = &sbi_ext[i]; @@ -501,8 +501,37 @@ void kvm_riscv_vcpu_sbi_init(struct kvm_vcpu *vcpu) continue; } + if (ext->init) { + ret = ext->init(vcpu); + if (ret) + scontext->ext_status[idx] = + KVM_RISCV_SBI_EXT_STATUS_UNAVAILABLE; + } + scontext->ext_status[idx] = ext->default_disabled ? KVM_RISCV_SBI_EXT_STATUS_DISABLED : KVM_RISCV_SBI_EXT_STATUS_ENABLED; } } + +void kvm_riscv_vcpu_sbi_deinit(struct kvm_vcpu *vcpu) +{ + struct kvm_vcpu_sbi_context *scontext = &vcpu->arch.sbi_context; + const struct kvm_riscv_sbi_extension_entry *entry; + const struct kvm_vcpu_sbi_extension *ext; + int idx, i; + + for (i = 0; i < ARRAY_SIZE(sbi_ext); i++) { + entry = &sbi_ext[i]; + ext = entry->ext_ptr; + idx = entry->ext_idx; + + if (idx < 0 || idx >= ARRAY_SIZE(scontext->ext_status)) + continue; + + if (scontext->ext_status[idx] != KVM_RISCV_SBI_EXT_STATUS_ENABLED || !ext->deinit) + continue; + + ext->deinit(vcpu); + } +} From patchwork Mon Jan 6 15:48:41 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: 13927599 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4315B1DED49 for ; Mon, 6 Jan 2025 15:49:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736178574; cv=none; b=Sh2kv5my7zw0JbGeLnNkJOa6tWwstChNIim6rsjB9kucflwLSmAm1ZdVV2eb5e4EeZkO5e7ECpL8BnCkahVtlNJASy7LPDg9CErEQT9ewa0yv+t239O/XM8OHyCqTeN7H0KAb108A3L2YTbfIIBOO/FOMHG4jmetJJrz4aSsFmw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736178574; c=relaxed/simple; bh=Sf4mkChjGPawhlMdNs6sYUSQY7rxaMa0aiV0h0QaDa4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=j4mbuzf05RsFWXRfj41TXfhe7nW+euGaPgSiK0/4x0CgIML8GMunzgF75HeCi0GtRRPgvtjoSkr4wJ1Sqscihz4Of/zFiZtezaLEMLFeETuKqAjOcs8XJ3dVIm53JhgXSJOUj3g92CN6V8j2ezlEnFnV7ZPpMFejfOMEZqGYOoE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=MYwukq9M; arc=none smtp.client-ip=209.85.216.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="MYwukq9M" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2ee46851b5eso17079499a91.1 for ; Mon, 06 Jan 2025 07:49:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1736178571; x=1736783371; darn=vger.kernel.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=pmv3FPl4GV//dUdGFHsJuNQdfa6373N/9drpleSw3Cw=; b=MYwukq9MQH5upUsoLwco47QFT5a1gR1m1slm41nhclncH1ftzUPSsdl1KZVp1KZCF/ a2aOfYxKiTAUOZfwmfmW8OB/sNfPN5CcZxngwpbyI+FupsR64fcN0FJjyco3xCWFHCg2 zwtU6gK7D5JjeAnFVYOyiyHxc2ssNLvkjCIZvnWdIDKPf0lN8mrvNbvOAVJqFQGmwU/B tE31Anuo3PdZY4YGUrjfV6DCa3RtjHvQKDluZVQtos+Vw3vOcWKGm/JbIfdulBAJNWg/ 7mfO2sFjkqqe7RsjAedQ6jLAlvQ54DhqBsi1ZIW2tjpwm4LxL47eHdSJmW0mGZ5VlD3u OF6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736178571; x=1736783371; 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=pmv3FPl4GV//dUdGFHsJuNQdfa6373N/9drpleSw3Cw=; b=ThjnJTX1TMKVa/5kIj+3rsF3l2zzUEtzXbHBYzQPo125Zl0gpmcWCQn2mwiKne0W8t KPhP+vJhEakepaT3j3/+ebbY2qem4O4FXqx4Sui9aIDayjSwO0IxEtJivFcg9aH6dJqy 4qoA8sHrq6IWxK2JKs5s4VoP/GE3PPk+WVL+5YEA64ux6bljvg65ADzyAEe6VWvbmnZr H3vPlMJtpsRRNBl3ODnvA1o1jRY2EZ62qunw+2gvMZWNq91b09BNQtRZX50nosy3O1wA 2mhKNSwdVJ4TGArpE6nW3dqhA72rb+4yeRA00B+xi36AmzH3dYkSBcTMD4iE4IGc/MTi /hyA== X-Forwarded-Encrypted: i=1; AJvYcCX6ahaup8x+pJ+zgh57e6/P09Pd/zvMetMtTyf62F3umW4tn8WnXSjDfF3zjLJaG2Y4/M4=@vger.kernel.org X-Gm-Message-State: AOJu0Yyi2ZIqGpD0WnFcJygYZRA/VfghhMLNgNYlicvEoey5zgrPqiEF 3QhPYAeHlkdn5Cd9LsvSoErSGVYwAMOK4Xn8UYHu84dUFSWPkQy2zVCOuwnli9w= X-Gm-Gg: ASbGncvqejwD+yBsI6/i2/NFntco0dd82g4LhSeTEqWZxHkQ8CijOAxos3nnBcO0hok nFwmnlHmFzq2+qBETRz+NY7llg0aYWalAKvtBb3aMnVBkAsiGs4x9TFnofgA+DH4jJhuop+oPl8 BQy2GqYQ5iuHDUB2xzFWV1KbzZLGEpclzhRBIWTtL+y0zye6KrcAsHC/386PVRbSq/iiskYdmEC nwEqUAvtZ1kwZcmmXFMHW3vb60BPdJkaAu+lk+AenOV2rsDCnxlBBfq0A== X-Google-Smtp-Source: AGHT+IHmlaHSPqFlwypLhD4uQLLN0+z7Y6gy5e30raQNWiHTPxZ57UoHgVMO9gETG3Wu9LX0cFWz9w== X-Received: by 2002:a17:90a:da8e:b0:2ee:9d65:65a7 with SMTP id 98e67ed59e1d1-2f452ec6ff3mr89290918a91.29.1736178571339; Mon, 06 Jan 2025 07:49:31 -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.49.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 07:49:30 -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 4/6] RISC-V: KVM: add support for FWFT SBI extension Date: Mon, 6 Jan 2025 16:48:41 +0100 Message-ID: <20250106154847.1100344-5-cleger@rivosinc.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106154847.1100344-1-cleger@rivosinc.com> References: <20250106154847.1100344-1-cleger@rivosinc.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add basic infrastructure to support the FWFT extension in KVM. Signed-off-by: Clément Léger --- arch/riscv/include/asm/kvm_host.h | 4 + arch/riscv/include/asm/kvm_vcpu_sbi.h | 1 + arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h | 37 +++++ arch/riscv/include/uapi/asm/kvm.h | 1 + arch/riscv/kvm/Makefile | 1 + arch/riscv/kvm/vcpu_sbi.c | 4 + arch/riscv/kvm/vcpu_sbi_fwft.c | 176 +++++++++++++++++++++ 7 files changed, 224 insertions(+) create mode 100644 arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h create mode 100644 arch/riscv/kvm/vcpu_sbi_fwft.c diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h index 35eab6e0f4ae..9bd046ed7907 100644 --- a/arch/riscv/include/asm/kvm_host.h +++ b/arch/riscv/include/asm/kvm_host.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -276,6 +277,9 @@ struct kvm_vcpu_arch { /* Performance monitoring context */ struct kvm_pmu pmu_context; + /* Firmware feature SBI extension context */ + struct kvm_sbi_fwft fwft_context; + /* 'static' configurations which are set only once */ struct kvm_vcpu_config cfg; diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi.h b/arch/riscv/include/asm/kvm_vcpu_sbi.h index 8c465ce90e73..7ff200a1ad3b 100644 --- a/arch/riscv/include/asm/kvm_vcpu_sbi.h +++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h @@ -95,6 +95,7 @@ extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_srst; extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_hsm; extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_dbcn; extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_sta; +extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_fwft; extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_experimental; extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_vendor; diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h b/arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h new file mode 100644 index 000000000000..5782517f6e08 --- /dev/null +++ b/arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2025 Rivos Inc. + * + * Authors: + * Clément Léger + */ + +#ifndef __KVM_VCPU_RISCV_FWFT_H +#define __KVM_VCPU_RISCV_FWFT_H + +#include + +struct kvm_sbi_fwft_config; +struct kvm_vcpu; + +struct kvm_sbi_fwft_feature { + enum sbi_fwft_feature_t id; + bool (*supported)(struct kvm_vcpu *vcpu); + int (*set)(struct kvm_vcpu *vcpu, struct kvm_sbi_fwft_config *conf, unsigned long value); + int (*get)(struct kvm_vcpu *vcpu, struct kvm_sbi_fwft_config *conf, unsigned long *value); +}; + +struct kvm_sbi_fwft_config { + const struct kvm_sbi_fwft_feature *feature; + bool supported; + unsigned long flags; +}; + +/* FWFT data structure per vcpu */ +struct kvm_sbi_fwft { + struct kvm_sbi_fwft_config *configs; +}; + +#define vcpu_to_fwft(vcpu) (&(vcpu)->arch.fwft_context) + +#endif /* !__KVM_VCPU_RISCV_FWFT_H */ diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/asm/kvm.h index 3482c9a73d1b..0813145a6272 100644 --- a/arch/riscv/include/uapi/asm/kvm.h +++ b/arch/riscv/include/uapi/asm/kvm.h @@ -198,6 +198,7 @@ enum KVM_RISCV_SBI_EXT_ID { KVM_RISCV_SBI_EXT_VENDOR, KVM_RISCV_SBI_EXT_DBCN, KVM_RISCV_SBI_EXT_STA, + KVM_RISCV_SBI_EXT_FWFT, KVM_RISCV_SBI_EXT_MAX, }; diff --git a/arch/riscv/kvm/Makefile b/arch/riscv/kvm/Makefile index 0fb1840c3e0a..ece6b119913a 100644 --- a/arch/riscv/kvm/Makefile +++ b/arch/riscv/kvm/Makefile @@ -32,6 +32,7 @@ kvm-y += vcpu_sbi_replace.o kvm-y += vcpu_sbi_sta.o kvm-$(CONFIG_RISCV_SBI_V01) += vcpu_sbi_v01.o kvm-y += vcpu_switch.o +kvm-y += vcpu_sbi_fwft.o kvm-y += vcpu_timer.o kvm-y += vcpu_vector.o kvm-y += vm.o diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c index d2dbb0762072..5bf6c92cca5b 100644 --- a/arch/riscv/kvm/vcpu_sbi.c +++ b/arch/riscv/kvm/vcpu_sbi.c @@ -74,6 +74,10 @@ static const struct kvm_riscv_sbi_extension_entry sbi_ext[] = { .ext_idx = KVM_RISCV_SBI_EXT_STA, .ext_ptr = &vcpu_sbi_ext_sta, }, + { + .ext_idx = KVM_RISCV_SBI_EXT_FWFT, + .ext_ptr = &vcpu_sbi_ext_fwft, + }, { .ext_idx = KVM_RISCV_SBI_EXT_EXPERIMENTAL, .ext_ptr = &vcpu_sbi_ext_experimental, diff --git a/arch/riscv/kvm/vcpu_sbi_fwft.c b/arch/riscv/kvm/vcpu_sbi_fwft.c new file mode 100644 index 000000000000..55433e805baa --- /dev/null +++ b/arch/riscv/kvm/vcpu_sbi_fwft.c @@ -0,0 +1,176 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2025 Rivos Inc. + * + * Authors: + * Clément Léger + */ + +#include +#include +#include +#include +#include +#include +#include + +static const enum sbi_fwft_feature_t kvm_fwft_defined_features[] = { + SBI_FWFT_MISALIGNED_EXC_DELEG, + SBI_FWFT_LANDING_PAD, + SBI_FWFT_SHADOW_STACK, + SBI_FWFT_DOUBLE_TRAP, + SBI_FWFT_PTE_AD_HW_UPDATING, + SBI_FWFT_POINTER_MASKING_PMLEN, +}; + +static bool kvm_fwft_is_defined_feature(enum sbi_fwft_feature_t feature) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(kvm_fwft_defined_features); i++) { + if (kvm_fwft_defined_features[i] == feature) + return true; + } + + return false; +} + +static const struct kvm_sbi_fwft_feature features[] = { +}; + +static struct kvm_sbi_fwft_config * +kvm_sbi_fwft_get_config(struct kvm_vcpu *vcpu, enum sbi_fwft_feature_t feature) +{ + int i = 0; + struct kvm_sbi_fwft *fwft = vcpu_to_fwft(vcpu); + + for (i = 0; i < ARRAY_SIZE(features); i++) { + if (fwft->configs[i].feature->id == feature) + return &fwft->configs[i]; + } + + return NULL; +} + +static int kvm_fwft_get_feature(struct kvm_vcpu *vcpu, + enum sbi_fwft_feature_t feature, + struct kvm_sbi_fwft_config **conf) +{ + struct kvm_sbi_fwft_config *tconf; + + tconf = kvm_sbi_fwft_get_config(vcpu, feature); + if (!tconf) { + if (kvm_fwft_is_defined_feature(feature)) + return SBI_ERR_NOT_SUPPORTED; + + return SBI_ERR_DENIED; + } + + if (!tconf->supported) + return SBI_ERR_NOT_SUPPORTED; + + *conf = tconf; + + return SBI_SUCCESS; +} + +static int kvm_sbi_fwft_set(struct kvm_vcpu *vcpu, + enum sbi_fwft_feature_t feature, + unsigned long value, unsigned long flags) +{ + int ret; + struct kvm_sbi_fwft_config *conf; + + ret = kvm_fwft_get_feature(vcpu, feature, &conf); + if (ret) + return ret; + + if ((flags & ~SBI_FWFT_SET_FLAG_LOCK) != 0) + return SBI_ERR_INVALID_PARAM; + + if (conf->flags & SBI_FWFT_SET_FLAG_LOCK) + return SBI_ERR_DENIED; + + conf->flags = flags; + + return conf->feature->set(vcpu, conf, value); +} + +static int kvm_sbi_fwft_get(struct kvm_vcpu *vcpu, + enum sbi_fwft_feature_t feature, + unsigned long *value) +{ + int ret; + struct kvm_sbi_fwft_config *conf; + + ret = kvm_fwft_get_feature(vcpu, feature, &conf); + if (ret) + return ret; + + return conf->feature->get(vcpu, conf, value); +} + +static int kvm_sbi_ext_fwft_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, + struct kvm_vcpu_sbi_return *retdata) +{ + int ret = 0; + struct kvm_cpu_context *cp = &vcpu->arch.guest_context; + unsigned long funcid = cp->a6; + + switch (funcid) { + case SBI_EXT_FWFT_SET: + ret = kvm_sbi_fwft_set(vcpu, cp->a0, cp->a1, cp->a2); + break; + case SBI_EXT_FWFT_GET: + ret = kvm_sbi_fwft_get(vcpu, cp->a0, &retdata->out_val); + break; + default: + ret = SBI_ERR_NOT_SUPPORTED; + break; + } + + retdata->err_val = ret; + + return 0; +} + +static int kvm_sbi_ext_fwft_init(struct kvm_vcpu *vcpu) +{ + struct kvm_sbi_fwft *fwft = vcpu_to_fwft(vcpu); + const struct kvm_sbi_fwft_feature *feature; + struct kvm_sbi_fwft_config *conf; + int i; + + fwft->configs = kcalloc(ARRAY_SIZE(features), sizeof(struct kvm_sbi_fwft_config), + GFP_KERNEL); + if (!fwft->configs) + return -ENOMEM; + + for (i = 0; i < ARRAY_SIZE(features); i++) { + feature = &features[i]; + conf = &fwft->configs[i]; + if (feature->supported) + conf->supported = feature->supported(vcpu); + else + conf->supported = true; + + conf->feature = feature; + } + + return 0; +} + +static void kvm_sbi_ext_fwft_deinit(struct kvm_vcpu *vcpu) +{ + struct kvm_sbi_fwft *fwft = vcpu_to_fwft(vcpu); + + kfree(fwft->configs); +} + +const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_fwft = { + .extid_start = SBI_EXT_FWFT, + .extid_end = SBI_EXT_FWFT, + .handler = kvm_sbi_ext_fwft_handler, + .init = kvm_sbi_ext_fwft_init, + .deinit = kvm_sbi_ext_fwft_deinit, +}; From patchwork Mon Jan 6 15:48:42 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: 13927600 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57C861DED49 for ; Mon, 6 Jan 2025 15:49:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736178579; cv=none; b=Et8gUvRmhhfeflDX7f+SZo6SBq6pp6ddU5bGbHIEz1M9IpUxuN8HMFZP+VGb59H6+1lcEbAJXSQFR5ZLRUpu8lG4CcUo0e+4FrorABfTG5APzpTTUrberdQ+82KXp/iwCzoPq4lbkPgI0SMVA72M3BvNUGttbQAXGeSfcovafYY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736178579; c=relaxed/simple; bh=wAyylKrJoHKJ4K8tjIr0buB0/0rlmDZDbg+0t9SMuuY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Cq9buQBMcq3lEQcRJJkh+7VQqF2MVweuyW75KeFfXSNVJr/qk3eyCrn0QGMA9A/Km8J90RUJcFPQhUVBByc7k7nEJrTIO/1z0Dmp9P/4PDRJ+WLJsp8TGR8XjJ5/C82Tq/OW36O6NxacEHUhbDWUTzSjsW3o5/CplWnrQf/w3dw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=NOil2j/F; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="NOil2j/F" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-21661be2c2dso190890125ad.1 for ; Mon, 06 Jan 2025 07:49:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1736178578; x=1736783378; darn=vger.kernel.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=CcVyV1LOtw6V8Ho5gVIQl8YkyD+SXwNo0hQboe95Nr0=; b=NOil2j/Fci1ZcTQV4RxOl1D044MkVM3QJqH6+IrkAZW5CpjbvYZ5LD+Sz7hZlDyvjC g85LmBZppA0IZXSvXLFOGS9JA2kniL4rmmGrH0A/PIF72nEBIsgGJWBebqnwLrG9mniT tHBJ9uH28U39N0W8q7SUO3H46G4RfpvnHJehh3gNv7FWwHzHdkgQc9qRKRw0qJQJ6siZ PQ/EqGVZrSuNXNy2g3HdpCfSrqwNOo9G/sYAczHtXiNYDC2ee7QAVQVy8V6ZDBULqFgy NdwZ6qLI42KPQLwcOOCUA5YVPzwmS9jaOkp9i+uie787PtaztRVdUDZdKlgYH/SCsfbL FOdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736178578; x=1736783378; 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=CcVyV1LOtw6V8Ho5gVIQl8YkyD+SXwNo0hQboe95Nr0=; b=j5u4LIwfKex9PZjBC0pLBY9Dk4HEeKEmL9v98tOvWgVzgeTf061QtkABbPfheeh+V9 8/GEBj30QMojrRU7/XHg4avjEnPf1kDzrJN2J7ip024THVxVd7GfiVBXt1smgWQ6giEg EHvoJ/bMqNPRkGfNJQN6AR7MjbxsjKtzHPT7p/FdbP+/BL0h/0lsQr7oUg+a4QRAlGfr RmYx8aIIw95DnThOUGSb1SsA25CTVP2yQ6rDQKeUNtgge8Vrec7P3DZfG5pFSd3gSM7c 3AIiA5oHpwsjLpkc9+Nr3ZyoC8Fxb8P3BzEP4SXW3uqBwlM0dPRmhtW5AkVNcGmbh78m hhgw== X-Forwarded-Encrypted: i=1; AJvYcCW1nQEnf0V9lGmtpBwpDubR7PEcJLQLdehQcCKulgP+nCrZy5ojUeNopwWZviQTODUfg9c=@vger.kernel.org X-Gm-Message-State: AOJu0YxpnpxT+SNCh2dadTR3ueS5aTnF93CnWEq6fA1u4UnSbMLR+dBm lL3GMmNdqaEcHs+EDM/TPJdgCPxI7WARbrSVtPFt/vhWw3IJChK1yuq+GZI6PE8= X-Gm-Gg: ASbGncvOxUyI8/1WmcXuzMsucf/VmUoSFhLooU7uBtOEUrquRDqSMuMzBjguzh1x2y0 ZXXbCo//mFZtesafv7EOpgIQpzoKlSXA7vPkGmQzyFo/ZoiMMF5exzeWZlA3F/rY4jItiItmhsv darQbO+TjNHdRCvOAYfTwvMYvmtg698ozLomYAtC9tYJtuDY9Z32EkawW4hxRhNd2DGgbIpJvL6 xEyDdYImeUp2sCY9IaWhduOBWi9Hvy22ImyfghfZwYJCqpYKKNmFoGZ1Q== X-Google-Smtp-Source: AGHT+IFsXBphfyy9s3JHMbepbPzIKCpal6gBIDcIfNIg+T9QhHs1bx0Q0ootfBFREr+mo3N4LGUQPA== X-Received: by 2002:a17:902:fc8e:b0:215:522d:72d6 with SMTP id d9443c01a7336-219e6f0e605mr939915245ad.38.1736178577712; Mon, 06 Jan 2025 07:49:37 -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.49.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 07:49:37 -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 5/6] riscv: export unaligned_ctl_available() as a GPL symbol Date: Mon, 6 Jan 2025 16:48:42 +0100 Message-ID: <20250106154847.1100344-6-cleger@rivosinc.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106154847.1100344-1-cleger@rivosinc.com> References: <20250106154847.1100344-1-cleger@rivosinc.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This symbol will be used by the KVM SBI firmware feature extension implementation. Since KVM can be built as a module, this needs to be exported. Export it using EXPORT_SYMBOL_GPL(). Signed-off-by: Clément Léger Reviewed-by: Jesse Taube --- arch/riscv/kernel/traps_misaligned.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/traps_misaligned.c index 4aca600527e9..7118d74673ee 100644 --- a/arch/riscv/kernel/traps_misaligned.c +++ b/arch/riscv/kernel/traps_misaligned.c @@ -684,6 +684,8 @@ bool unaligned_ctl_available(void) { return unaligned_ctl; } +EXPORT_SYMBOL_GPL(unaligned_ctl_available); + #else bool check_unaligned_access_emulated_all_cpus(void) { From patchwork Mon Jan 6 15:48:43 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: 13927601 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A859A1DF240 for ; Mon, 6 Jan 2025 15:49:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736178587; cv=none; b=rfy/vceWOWXclL61BKvb1sZykhLSLVGBlt9QIfVJG5UeZm5n/YYl1MemKamrEVV2vd4IPQgNcSt/gq6GQ+sFyLmMpCMmmNJ84ouNN3rh1mAFl0HKntzfZmiPqCChpgfM3sb5dBcFy5HcmKMMJ2wNUbfCEmCIa7WY67gI7t58HDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736178587; c=relaxed/simple; bh=V1YlIcuVQQaREOmCPGx43j3enQKqJFZ4VquEsvSJlW4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oY6av5lLo6BGvE7+Tkj9cI4ZcQU/E5Eon8wh7T+bhaf0/DMKpMSLwntljt29fHWTDEedJfAa5qBM4BHXt8QYrCEncRZhRlbof1WbytVlFAzB4INxA223ZfmS/jYizMQoIxmSEq17jww6Pf64hW96qVK8IrVsAYbpijIzo94eK0U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=IEYo6nVS; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="IEYo6nVS" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-21636268e43so26720655ad.2 for ; Mon, 06 Jan 2025 07:49:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1736178584; x=1736783384; darn=vger.kernel.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=pZted/4cRJuHwsNYAobqssxEi0f1evq9XJsjrZaPJkE=; b=IEYo6nVS0g5DPNqbj0KQleNcwXYlrALOpqN6WKgfHTLQaIo0+oB2Z/UsGtCFmxNPob 88QVc9opNCsOPBbJNZPoe4bSGTNPhyQQ4kIfZO12VFZcngiL8UZt1vhtMZrWPuRVtXiq dHdoh1GuLAvrYx+luSgifC7cPTTLHjp9Rq+OdwEbIJ3idabu6DQImr8kFk2384KDimtA xpzWiOyEKI/6T3zd2ZQ74YJ4EIjEhBtIV800XyMA0UFKQBcSV+PoRDGDHlm7B9oxdr49 1pz6bTRaD1pJWlJsRV7RspITcYzNRewlaUQ1ppheLJ0t5pWJC/k9Tm14JITJi+TyUZT1 3xpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736178584; x=1736783384; 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=pZted/4cRJuHwsNYAobqssxEi0f1evq9XJsjrZaPJkE=; b=jeEQLJSJ+4FFlEbd8cFgYjZVT28vpopkna9Ns/kjucr+R+tsyeD6LCAgNjKBesZepu aCqQVhVujAvOTV8+1NnKCl1E4+LvOVwrxgVgtTbAkaST0RO/ROpyDYjy3SN4nnBMK73s qub53NRwhVvXRFnRihTNoHwr6QRL8/LCf1pFOVrJwFdF+5+Y+l+crOfP4Fk35lENQCxq eE5FOql87Bsqbz0SN+raiQSDBEkj2V65u7AJxt9deUtfSwTAQfuof+83Pcvo02tefJ3N Efzz2Ksvrnqfll+ZNjJbajhgNO0kbBgpzflS0aUWuZTbRhiLXtaLBEJad91KO5tpqRvV FMnQ== X-Forwarded-Encrypted: i=1; AJvYcCXC6jbS7Ey7RWsnwAu4Z3QDkd8DN5pYPfCrAE4+/6kHh6+fDDr01ljJgcBv5nDrOwr7oS0=@vger.kernel.org X-Gm-Message-State: AOJu0YwQDSzClU6d/fdqO8JkDQPURjyMccnimUDga4F8xrutNnvCMw/Y 4LGDXx+0ysTclj4JJ9RnySBOWQ0R9AGLQ30y4SpF6YP5hP4pO0tdOfBIQeQA2ik= X-Gm-Gg: ASbGncvxlVMV67sEMPA0bdItJMKDqmAoFv0+nNOQBTpxW4VJSA6ZIfhutW01nKslH57 bkwg6HB0ePDhxqNK6hAxjzMcSWaitOzHy47t3S7kuHHhhChaDdPf+XKP4t50QEoWR6OcbG9DedC sgqC9MC+6j2O7SeyUvGLXNY17KsLTjaMzpdMfmoQFC3OohnX8HD/omSvK9+2dnKoEthg6TZxmAb U0cehP1AJUwHiBgYLNtS7Q1EiLtzCPU2Nf5SdYJS/2Z34o1znXlNAkarA== X-Google-Smtp-Source: AGHT+IEOmk52vJbM/lir6EnXzGo8rHZx0c8SdsX59VoQTeStIErxbb+u7Tg8JzB4+OJAm4+54IkSXg== X-Received: by 2002:a17:902:e886:b0:216:5e6e:68cb with SMTP id d9443c01a7336-219e6e9fd95mr868563935ad.16.1736178584085; Mon, 06 Jan 2025 07:49:44 -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.49.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 07:49:43 -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 6/6] RISC-V: KVM: add support for SBI_FWFT_MISALIGNED_DELEG Date: Mon, 6 Jan 2025 16:48:43 +0100 Message-ID: <20250106154847.1100344-7-cleger@rivosinc.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106154847.1100344-1-cleger@rivosinc.com> References: <20250106154847.1100344-1-cleger@rivosinc.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 SBI_FWFT_MISALIGNED_DELEG needs hedeleg to be modified to delegate misaligned load/store exceptions. Save and restore it during CPU load/put. Signed-off-by: Clément Léger --- arch/riscv/kvm/vcpu.c | 3 +++ arch/riscv/kvm/vcpu_sbi_fwft.c | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index 3420a4a62c94..bb6f788d46f5 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -641,6 +641,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) { void *nsh; struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; + struct kvm_vcpu_config *cfg = &vcpu->arch.cfg; vcpu->cpu = -1; @@ -666,6 +667,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) csr->vstval = nacl_csr_read(nsh, CSR_VSTVAL); csr->hvip = nacl_csr_read(nsh, CSR_HVIP); csr->vsatp = nacl_csr_read(nsh, CSR_VSATP); + cfg->hedeleg = nacl_csr_read(nsh, CSR_HEDELEG); } else { csr->vsstatus = csr_read(CSR_VSSTATUS); csr->vsie = csr_read(CSR_VSIE); @@ -676,6 +678,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) csr->vstval = csr_read(CSR_VSTVAL); csr->hvip = csr_read(CSR_HVIP); csr->vsatp = csr_read(CSR_VSATP); + cfg->hedeleg = csr_read(CSR_HEDELEG); } } diff --git a/arch/riscv/kvm/vcpu_sbi_fwft.c b/arch/riscv/kvm/vcpu_sbi_fwft.c index 55433e805baa..1e85ff6666af 100644 --- a/arch/riscv/kvm/vcpu_sbi_fwft.c +++ b/arch/riscv/kvm/vcpu_sbi_fwft.c @@ -14,6 +14,8 @@ #include #include +#define MIS_DELEG (1UL << EXC_LOAD_MISALIGNED | 1UL << EXC_STORE_MISALIGNED) + static const enum sbi_fwft_feature_t kvm_fwft_defined_features[] = { SBI_FWFT_MISALIGNED_EXC_DELEG, SBI_FWFT_LANDING_PAD, @@ -35,7 +37,44 @@ static bool kvm_fwft_is_defined_feature(enum sbi_fwft_feature_t feature) return false; } +static bool kvm_sbi_fwft_misaligned_delegation_supported(struct kvm_vcpu *vcpu) +{ + if (!unaligned_ctl_available()) + return false; + + return true; +} + +static int kvm_sbi_fwft_set_misaligned_delegation(struct kvm_vcpu *vcpu, + struct kvm_sbi_fwft_config *conf, + unsigned long value) +{ + if (value == 1) + csr_set(CSR_HEDELEG, MIS_DELEG); + else if (value == 0) + csr_clear(CSR_HEDELEG, MIS_DELEG); + else + return SBI_ERR_INVALID_PARAM; + + return SBI_SUCCESS; +} + +static int kvm_sbi_fwft_get_misaligned_delegation(struct kvm_vcpu *vcpu, + struct kvm_sbi_fwft_config *conf, + unsigned long *value) +{ + *value = (csr_read(CSR_HEDELEG) & MIS_DELEG) != 0; + + return SBI_SUCCESS; +} + static const struct kvm_sbi_fwft_feature features[] = { + { + .id = SBI_FWFT_MISALIGNED_EXC_DELEG, + .supported = kvm_sbi_fwft_misaligned_delegation_supported, + .set = kvm_sbi_fwft_set_misaligned_delegation, + .get = kvm_sbi_fwft_get_misaligned_delegation, + } }; static struct kvm_sbi_fwft_config *