From patchwork Thu Apr 24 17:31:48 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: 884107 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 42F662857EF for ; Thu, 24 Apr 2025 17:33:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745516027; cv=none; b=Errh7N1QIzNKK6KNSpxjSVcexOudD9uIqTiSTm0W/u8VmG8VgdGQAb7+yo8/YF1WH06vJ9tWqra/xTGHMRDKtxF98z9U15qTgS8/qu8B2G2FF6WS3WeWpxYpKGOAl/a+025f9rCqlK174V2nS7r+nQvnChBPNB5P+d3UdDtSgUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745516027; c=relaxed/simple; bh=aFqX3fLDtG8cy76aRcSSCxbszjtqQl817f+Kcc6ZMK0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OKYvH7P6MsNAF/YTru4hd1huhfQ7gSqep+vAGlTD5kg9IGhcWHonmMi8u4k53FlKXxRAoE26oMqzGIsKIt5wCFRCkCSmI2a6AyH3YftjoCSIUGlJOmJYgbdz4zcoB2LlhRR2OC1FH6TzGIW4uowxTfAvFrGt7yWifUIPW5x8n+o= 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=WJwCQifU; arc=none smtp.client-ip=209.85.214.176 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="WJwCQifU" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-22d95f0dda4so20286355ad.2 for ; Thu, 24 Apr 2025 10:33:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1745516025; x=1746120825; 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=MqV/L1fucoXh0zEq3ZbEkv0iZBTOf63rS7eOzOMDARE=; b=WJwCQifUIjEIFJgV0n05o7j7lWn9dcycnDP2Pyyrz7rerqfFUHvaYfGjn5GAoMnJo7 2zRQRzRBACmMJ+eSOPqkgYRZ+wughP9TcJHqjhf0Zanmhq1XpnFwldRUmlcmCw/KkN/g ySIihldhHHDzcVWgaLuMNSxZRrEgeFJK/YDCFXjQdTyx5nJ8F2opt3YduaiIxaTl+MBU dn5fxv9OjXJe3ryU444b0heqdljT2FCo0fmAVG6yLt5tt75SpZTvS00jm9Bwgz0uQrTe 8IfFxPqD1GLYzHVQKJyxbGcAIzdCIDkqGj1NgWPyji5tYs7aIJPFPHf5KrQdJ+Axb9kt ekwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745516025; x=1746120825; 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=MqV/L1fucoXh0zEq3ZbEkv0iZBTOf63rS7eOzOMDARE=; b=mw6OQQyOwMiy6sDSFZMLRB9dk1vd6IcLFmJ9rtP+uho+pY24+V2xj8AXgOfjOLYsyG i9mOjo62sVpk8K37dQfmyGPFGwqJk8x1zgp6K4Aq+Tc50apIFAkVXjSwiwccfD6auH+r v3n1IU1+BhbbjGHykkZPQf8tbrq1pd1fJ1DbPF2GOZh5cvol+G8oDg9+COkFd+Vhb6sm V8aR0Ahobn3j3TcOJv+3Gn6YSPyDMjFWMUPL+54shOAapmuAJ1VsylwEJJ+q7S1bIluk b1ReWWPGZN5ZM+KlM/qzXF3LnFlPRIKqEXgkU43xsQ7pLdCZNzds76sZDFRvvt4bzeqE G12A== X-Forwarded-Encrypted: i=1; AJvYcCW6wjjtpMUC96yEzERiwQnszWluXH1Q8V9DR4htnIW7UbUheHnARlpcNEku0NKLE8a07KkF+KDD5M/HwOrefys=@vger.kernel.org X-Gm-Message-State: AOJu0Yz63ek7B64Or/zMSQ8gZjnX9EeKDHxTytCQUO8zrgOqsYYUqkKV +oMghpwO51RupGHBSqtQzNS/Vna5B6WbjPjKo7JkGJVG1sjPKOC+rjHVgJbHgTE= X-Gm-Gg: ASbGncsptsCaidIWmi6vlgZaY0UBCY7KJw3c26A8bwR5Xcnws9Ynut9/YRrvdP09Fim e8fk5abIrCKV0xoi1nMt/zXIDBO34bnOplgRnZHKGtBN6+mznBdIX0hJJ21c/chPIxH/RYSbDmF /wVQymXqGB2L24l6GQPhX8m85CSbmqT1g9lbhjzeE/IfHmMC0WoUKk6YuMEdaUAE4KU173Znwyo Y9RBembQsPVKxl5c7kKYv586oyOVYh632GwVPEc878sWZ6qy0uwixLNb+UdcNTKIOhrTFnOqQqH TH783ygCb8ji8jZeswUM7D1FX2sMUt/kqdk1qqiYbg== X-Google-Smtp-Source: AGHT+IGoXel2WMkjiTK/q7g1/yBkqNZ84Lmsw32W4+SLXcM2BGBaWrGqIbaWGI5EV1R0ZMMR1eKW3w== X-Received: by 2002:a17:903:2445:b0:220:d078:eb33 with SMTP id d9443c01a7336-22db3d71d34mr56439695ad.36.1745516025550; Thu, 24 Apr 2025 10:33:45 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db5100c4esm16270255ad.173.2025.04.24.10.33.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 10:33:44 -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 , Deepak Gupta Subject: [PATCH v6 01/14] riscv: sbi: add Firmware Feature (FWFT) SBI extensions definitions Date: Thu, 24 Apr 2025 19:31:48 +0200 Message-ID: <20250424173204.1948385-2-cleger@rivosinc.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250424173204.1948385-1-cleger@rivosinc.com> References: <20250424173204.1948385-1-cleger@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kselftest@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 Reviewed-by: Samuel Holland Tested-by: Samuel Holland Reviewed-by: Deepak Gupta Reviewed-by: Andrew Jones --- arch/riscv/include/asm/sbi.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 3d250824178b..bb077d0c912f 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, @@ -402,6 +403,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 BIT(30) +#define SBI_FWFT_GLOBAL_FEATURE_BIT BIT(31) + +#define SBI_FWFT_SET_FLAG_LOCK BIT(0) + /* SBI spec version fields */ #define SBI_SPEC_VERSION_DEFAULT 0x1 #define SBI_SPEC_VERSION_MAJOR_SHIFT 24 @@ -419,6 +447,11 @@ enum sbi_ext_nacl_feature { #define SBI_ERR_ALREADY_STARTED -7 #define SBI_ERR_ALREADY_STOPPED -8 #define SBI_ERR_NO_SHMEM -9 +#define SBI_ERR_INVALID_STATE -10 +#define SBI_ERR_BAD_RANGE -11 +#define SBI_ERR_TIMEOUT -12 +#define SBI_ERR_IO -13 +#define SBI_ERR_DENIED_LOCKED -14 extern unsigned long sbi_spec_version; struct sbiret { From patchwork Thu Apr 24 17:31:50 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: 884106 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 237B828E5E1 for ; Thu, 24 Apr 2025 17:34:03 +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=1745516046; cv=none; b=ewi7w6jF7OO1CwTSGNt9UPfXJWBx9qOo900HkdHAlaSMvoiAnaF/vNKcZLzWvFgYZF6tkbra1LFKMdndjRWN8YptZUURUJcqzIHCWxFwt/GE90/3yrFdVh+pqowhlb+7h4Yw4NhO7Y0Os3bDGxCytQrADkMnLMMKZFdYgkxfem8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745516046; c=relaxed/simple; bh=I8q3a/r8sIPwl9ULO4heNHCAxh6RA5hJvMvMHg5vqgk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QeN+nmRl5T/B0+/7x0bKyTyafeukXDM5pES5p6jft1d4kSpHiJQprThqsadt0arkP9YWdSpYGUwxz5dM7LTDK1CNsJTDkq1Lll1MvUEhP1cf/cmXsZ1EfX6mNiVQC2FoEUeJPWdBr82Q1Ed08lm6mKhM4rOEZZwS9sLuX4JOC28= 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=nOO22wwC; 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="nOO22wwC" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-22c33e5013aso17664585ad.0 for ; Thu, 24 Apr 2025 10:34:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1745516043; x=1746120843; 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=kJ5IZYf4f1NhGHvFycXXpF/34tAS76qwhFgvuPH97UQ=; b=nOO22wwCEeeCLRdveDX1XJoulJIftSH2Nt3zOLaUXbwhKvcj7lcqH87YEsPTBbZZVa DAZ92Bd8Qn0w/IXvr6KM2BLUODk+EeRU+BzFKu3J8g29wrEmXLW4zt8L/U+KtaqYVI1E 1uVZ4y1fDi5d5ZdC40Rbt7iLF5i1i5LlbLDyP/24BqAHGGZ5l9ZyGFNaST9DcpVhflpv AfqL3xSYZe6wrmKxpIZImjsLgR6rYg5TWruM+xJmm7bN64PuspNEKe1mWR2TlFafaKnd xN1Xqs7d8jv6TDen0V0LTc3ynMr0xWKDV2TFI0PWiQKG/mraDPeHnKEyRGyF9fkw/HTA jPsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745516043; x=1746120843; 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=kJ5IZYf4f1NhGHvFycXXpF/34tAS76qwhFgvuPH97UQ=; b=kethng5Kjyzw1q9farYsfWWYiDnk9/ew20lmwV3oPlo6/G9t5GlWpRGtNSP6gqUOIn F51443EKDqe/0SDfJGI67LV96oYVmob0g1Lopk5hr10W5SaGU34MYu9/1hCfy7Lj7EmK D15urSgjcrpVvZj7ZlWlAPtE1u7w1gf+CXR8S29YnjVCpErFT9fVO0J/h7h2iUj3VvBI JtrbMhy+QlKqhxWYIihUx6glZWXs0V6IbscxPvUfq3sEaNrFTCLVE0z4dhsYwCPn0FyI HxH9iFz6298kv0MQadDQP9abyslWSlZXjkJINPGV5/kQKaVWlXR7YCCTUgfjDYEgjmZU O3RA== X-Forwarded-Encrypted: i=1; AJvYcCUPAbXmvOZTIJ5SjBH/j47hIjcxI3BEYHOy6NImyGOQq0Tiw1JbZ4yeY1Onk+ycFl3gI9W7cCvEWEiLf9gYP8A=@vger.kernel.org X-Gm-Message-State: AOJu0YwWDlC49ATCA8MXp7Bktcj4FyadRuCwTKne4ZNS8PbmNtGkfXBY b82Kg/ifVWRaWPnw8Ik10wusdTUa0ieviU2k0LfYwHLRPaU42HnCnoqO9v8Qw9k= X-Gm-Gg: ASbGncsqK34GnlW4xuapOb5J67w7asbJ5JmzI8dA/TMaRRLyjBh1WvN0XKmy0YkOWAd h2GCZX+DBbrw+41b1bABmEc3LG86IxQxuxMX1Y/ReImbjOjSdutm6GH8ufYKJyDK7touD/5dCdx xOb11zP9BaXsxYcuZksjdYJ5ZQDhUAxFMSBtTPnpjWEW2XvjTPaT2u1YA4gIt5MY6NwvxAyAzF5 p56qS3e2qSthVhRBDEOoYwDVaWULBWAW8VdKIZq9ErZu2fbJ1Uhlxw8DFuC9TGfLzpEI9pRSab3 mTQlkbQHHUJDfTmk8FPq3XfKmVpVlyXm8Vji+apDeQ== X-Google-Smtp-Source: AGHT+IHzS5PXDP+Qy5Xmwwn0uCCNIK9/92EEG8lEAWpb5PTGOgGH/HAmRDTuUMHUdz3Q/hblJk8Z1w== X-Received: by 2002:a17:903:234e:b0:223:67ac:8929 with SMTP id d9443c01a7336-22dbd35407bmr5533655ad.0.1745516043323; Thu, 24 Apr 2025 10:34:03 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db5100c4esm16270255ad.173.2025.04.24.10.33.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 10:34:02 -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 , Deepak Gupta Subject: [PATCH v6 03/14] riscv: sbi: add new SBI error mappings Date: Thu, 24 Apr 2025 19:31:50 +0200 Message-ID: <20250424173204.1948385-4-cleger@rivosinc.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250424173204.1948385-1-cleger@rivosinc.com> References: <20250424173204.1948385-1-cleger@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A few new errors have been added with SBI V3.0, maps them as close as possible to errno values. Signed-off-by: Clément Léger Reviewed-by: Andrew Jones --- arch/riscv/include/asm/sbi.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index bb077d0c912f..7ec249fea880 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -536,11 +536,21 @@ static inline int sbi_err_map_linux_errno(int err) case SBI_SUCCESS: return 0; case SBI_ERR_DENIED: + case SBI_ERR_DENIED_LOCKED: return -EPERM; case SBI_ERR_INVALID_PARAM: + case SBI_ERR_INVALID_STATE: return -EINVAL; + case SBI_ERR_BAD_RANGE: + return -ERANGE; case SBI_ERR_INVALID_ADDRESS: return -EFAULT; + case SBI_ERR_NO_SHMEM: + return -ENOMEM; + case SBI_ERR_TIMEOUT: + return -ETIME; + case SBI_ERR_IO: + return -EIO; case SBI_ERR_NOT_SUPPORTED: case SBI_ERR_FAILURE: default: From patchwork Thu Apr 24 17:31:52 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: 884105 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 332DD288CB5 for ; Thu, 24 Apr 2025 17:34:21 +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=1745516063; cv=none; b=YKn2D5WjziFISvb4mvJ7/Bq0vAoAjb/eZqJjw5DsOmTWGwurGiWPpx5GiMCIQbXhWF/oPsR3CK84hlhipdK7jXRV1ZJ/OEd/2/A9OhEKktwujvSPZ9h9MEfrlbkoVmlbthMt4sHY2AnsDwiRXYjk8hMTTw0z79oi2hTcfZZGDpc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745516063; c=relaxed/simple; bh=WFmpbMMF8HntgsLUUpVbwFoU5lFzEDsl21mQjoTPJz8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=o2kYxs4LWm6n95yXFWdtFM8Qr8x2YNVu/U260WYFTPQWpWyEMAKsmZ3K7YWC8231FmGDo2JS+OWVCqam9IJdqJBZRTlhpzNH4C9R/DW2XvnaQN4aXIRHSWYx+/uPxrXz4N7cWoewPpbGrR1a9Ue+CE9XyPazjPxu+DqmXmop5jM= 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=vrABEJbx; 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="vrABEJbx" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-22409077c06so21047265ad.1 for ; Thu, 24 Apr 2025 10:34:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1745516061; x=1746120861; 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=3eGkKF9qJdSzcJjZFaybinwNECXrhVepEnvdsnCoIkY=; b=vrABEJbxwBMRtIyYIwPcHH5MTwJ69rs1sdTNR2yrbw3Jv2LN27K5WZ1xO9m0DMeCEt eskgkmEtXtjIjgJoBTrVSIN//nCm8uY6IY7uEJaq0lCDhnUSVRqtX5UCLjULMXH95fZ3 AQVf9p5V/gMwJe+059AV9EAs84DZQFWGF4vQEPinsNuUJG9DGDXVITp/JtDCPOZY7TkL IRh3RG1Q5rH+vupKn06ayea4WoHCk4vsw5LjJwGKyJyhshnY8NxJgdkC62cKM7uvrHmr X924iIKWJBj2E+ciH878r87l9gi3SWBmxg3OAJ8erl6p2AgwkGqUBB3fRimwOJ6X4jHH 5pPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745516061; x=1746120861; 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=3eGkKF9qJdSzcJjZFaybinwNECXrhVepEnvdsnCoIkY=; b=tzb68AhSS0VhAN+kHTgFwcc785NqNzQRkR4fEamU/KpkwfFgUCu2tCd+F9vbPkD39z ZUapJPuhvn+lTEY2cOzmalQLUrxM1jMM0HbIm+btylS4OIsgcz1ar/ecSfZCQhx5iDeo hwbB+NPOpMFV0l6/IQoF5cyppqEfcEGp9Rf9PAmNTpQiE9VMGOmhQTF4dFBd2kXdL4Pp TLY3GVSuF5wU21jgArhc2q5tipQqBATcZ8PTDU1gmbF2NPooH9pcKOqOt+Cslza/qIvn hrT/FP9KuC3jbICOGM7+vsao5Rolo6QHbTfy0uP5nqGHx2Tex1CU2K4jbYFODWoCp51J 08EQ== X-Forwarded-Encrypted: i=1; AJvYcCVvm1ivL4YK7fob/UyJcypgvcVB26BbPu3/TCWsFI+heyrZPT6f45uK7ATijpJA9YfBAgrBRKq156OWQqbPGbI=@vger.kernel.org X-Gm-Message-State: AOJu0Yx8KblHTl1DxYf1xzJzwr6VO4rmW5OQa0YiPImEKp2PMfKlmrM3 xh3hCZZsrj1FaOvN23+4Gixa75dK1P+f5aT6eht8YES7kMgVRNcYsVKBnqy4Ieg= X-Gm-Gg: ASbGncvh2nF6KAR1lJXNwA4rBNZPkmNhknsG2uuDqFcX/t/eNrOqmf1hVHDT7dddfx+ XW1dNXKPQvEBoA2WiV/hPQyO4+akYz3tylOxXqoTZ2jXqm2kHpnGDkKQdkWyqsZu0VTjw6pLpFk nPKcoAgxCYfTDtpvddqgAC1oen/QcbgpIiU1UiTPh72I006yx6R+k0THX8v4Zc3rlXyq/kRdT3v nnLmUMptS0ejeraVOEHZm2OMfG8VKTsJd+aNOPyJUX5nC7ctEMY5DXtZU1PxZ7fbnLny9LWGoiu A5Ud7C5ErP2WolO74LHniIMBUCLydM7FBytgHyfKIw== X-Google-Smtp-Source: AGHT+IEs4ew4uugiJtDbQhNEaEfxtdPEFF4bo2T+1eF9T2VcpqRrkFtRa0ffscLhiLfSNXEuYhJu4Q== X-Received: by 2002:a17:902:db11:b0:223:5a6e:b16 with SMTP id d9443c01a7336-22dbd3f9de4mr5146115ad.5.1745516061340; Thu, 24 Apr 2025 10:34:21 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db5100c4esm16270255ad.173.2025.04.24.10.34.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 10:34:20 -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 , Deepak Gupta Subject: [PATCH v6 05/14] riscv: sbi: add SBI FWFT extension calls Date: Thu, 24 Apr 2025 19:31:52 +0200 Message-ID: <20250424173204.1948385-6-cleger@rivosinc.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250424173204.1948385-1-cleger@rivosinc.com> References: <20250424173204.1948385-1-cleger@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add FWFT extension calls. This will be ratified in SBI V3.0 hence, it is provided as a separate commit that can be left out if needed. Signed-off-by: Clément Léger Reviewed-by: Andrew Jones --- arch/riscv/kernel/sbi.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c index d57e4dae7dac..070014ff35d4 100644 --- a/arch/riscv/kernel/sbi.c +++ b/arch/riscv/kernel/sbi.c @@ -299,6 +299,8 @@ static int __sbi_rfence_v02(int fid, const struct cpumask *cpu_mask, return 0; } +static bool sbi_fwft_supported; + /** * sbi_fwft_set() - Set a feature on the local hart * @feature: The feature ID to be set @@ -309,7 +311,15 @@ static int __sbi_rfence_v02(int fid, const struct cpumask *cpu_mask, */ int sbi_fwft_set(u32 feature, unsigned long value, unsigned long flags) { - return -EOPNOTSUPP; + struct sbiret ret; + + if (!sbi_fwft_supported) + return -EOPNOTSUPP; + + ret = sbi_ecall(SBI_EXT_FWFT, SBI_EXT_FWFT_SET, + feature, value, flags, 0, 0, 0); + + return sbi_err_map_linux_errno(ret.error); } struct fwft_set_req { @@ -348,6 +358,9 @@ int sbi_fwft_set_cpumask(const cpumask_t *mask, u32 feature, .error = ATOMIC_INIT(0), }; + if (!sbi_fwft_supported) + return -EOPNOTSUPP; + if (feature & SBI_FWFT_GLOBAL_FEATURE_BIT) return -EINVAL; @@ -679,6 +692,11 @@ void __init sbi_init(void) pr_info("SBI DBCN extension detected\n"); sbi_debug_console_available = true; } + if (sbi_spec_version >= sbi_mk_version(3, 0) && + sbi_probe_extension(SBI_EXT_FWFT)) { + pr_info("SBI FWFT extension detected\n"); + sbi_fwft_supported = true; + } } else { __sbi_set_timer = __sbi_set_timer_v01; __sbi_send_ipi = __sbi_send_ipi_v01; From patchwork Thu Apr 24 17:31:54 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: 884104 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (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 F3BE528E60E for ; Thu, 24 Apr 2025 17:34:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745516082; cv=none; b=hEaWoh18lvaP7in+D6atzbPT375EKtmf9hQmlWTvkyCjZD8AalrU1nL43eHWT2gje0BMg+6HZhFOTg0DX/BHpWvyqRIY7jqWA8RWIGtTxzmoHSApuhMpF/6YbX63HV6R9R1dXgMD/LwbS1/W4X9rB0uF8rx+mJZpOKVRnoLWKCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745516082; c=relaxed/simple; bh=LcpSprXMV6bcNVh6rueh5KTbTp1K/fbkooupP6MTizk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Fe4pGIYYF5ZZDwiHx86wW0Pglis3B6IvLc9IsYE9mu796cj6FsOgoF7jxDd+9Qs+YG5wjX8R5wODYlvXSE1Y+LX7eS4+vOv13KTXahZPfqvZzIA7iICfhHJRT57XjU1q5iEYI8je+6z9sWsivoFIgneP7zwVDXMxS29guDTQAck= 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=owfWtu9h; arc=none smtp.client-ip=209.85.216.43 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="owfWtu9h" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-30828fc17adso1359290a91.1 for ; Thu, 24 Apr 2025 10:34:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1745516079; x=1746120879; 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=SH77kPPOP+qp5pa2Cr8pgAGSaFmjEWdE92nKDczco64=; b=owfWtu9hdkAHE0zKblqsvB1dUkIPCXmYCfyvccCw1Pp/VcDq7vvWGLwjREa0bt/ims pkDNOz7FIEpA9eItkuJ+01IXuBh176qfud6JMq4EWtsJOMeEaeRsAdlyGgXOijeU3W+y 4YCUIuFnSOK5USK4Q16Wi0xWCcxdPSS15+9ig9ILKCdsJzc9BTvV+UJ9ndnN3G/F9NVs lV7Vm4CP9VBMGx0L0Oc3/nbYVaInEg/OA1/glgdVOnkUJ6V4+R4r+aKET7rnghJhhEc4 zA6Y8AWEQxDudw5GDTqpolylcn9YG0vU2zI40WznPQOu+RWkgHgK73+Gv4kvZ7AkgeXV u4fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745516079; x=1746120879; 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=SH77kPPOP+qp5pa2Cr8pgAGSaFmjEWdE92nKDczco64=; b=uoMYpNTOxMtsufBX8Gp5Lf5ptyAHOop0CVCRZHdmD0deWtGL2T7OVG2D585LYrwpNq 4VD4BGj7Q6QZr0L+Ko0+sI5ZaMutsIYVVmwx6EXQBHIEvXj7NMK5IDDrNXQSSR3VRKuy tHR4lOS46+wkjh538axgT2VA2ZDafvsh77h9J0MGow+k2C00rs3VfG41odUeb8fUOG2J kkmozLVvZ/jTpaDLylGkekQiDdXmfemc1MGxIhbWOU3Vgy8SKYWz3gnU2H9qX+TLWlvp LGBMUa5FT0WXbqseSZTI3D3Eo/HyRvuyADjSdkLpfUpn3g/1OJ9SBd7VfynBWn4IE5Ja Jk2A== X-Forwarded-Encrypted: i=1; AJvYcCU5HIIYkDwVveviIH5tyFKY0KxGYOkAJXM671o+UG3L5KVK9ZP1yeB06oWNsa+BqQhIXW18EdEVMU5K60CxKuY=@vger.kernel.org X-Gm-Message-State: AOJu0YzDtya9y144rWxuv9aXc8h7VtP0RnKYn3SmC/SQ0TBB/D+2domW 2HUE4/khfchlj+hkGfutf/ahzvnMaa8517zZojYotYSZxj24cKAKUBWUaLTsdj0= X-Gm-Gg: ASbGncsEwbVRyDz+GBSBgCLxw/JbCCJcbaG80QmJDtrHlWIcyKalC97O3fxVmJUXCHx 7HbEsEwB2OhTjxlrdZl8LKZUHtp1WrI8+PVaCCt5epF3GmM7YbeB53vW5tbuakrGty7oeDUB8dL pzQ2BvAJaYbMZ8st14hCLSkXBUu9t1pj+SrBj17LPtYVa8NuuWKdvfX7stUDeKbNaVxHnUYJq1u jULjUIPn3e+UuMr1WS8bJXa3eD69SOyXdYz3TeUeNEz23H2W8RGtIVShmJrd3NdJuRiBx+c4T1X fsv0Krk5beqrByL/grUPTvNhtHAkcOooyi2zo8O2sw== X-Google-Smtp-Source: AGHT+IFi4Le7AzhhmTTIRr2FvD3j5KIgFxeLHXA7hAgbxEuSLsG1Fq72dIzoCsCCWJEHQANRW1hXVg== X-Received: by 2002:a17:90b:1d4f:b0:2ee:f22a:61dd with SMTP id 98e67ed59e1d1-309f56fa88cmr642762a91.32.1745516079316; Thu, 24 Apr 2025 10:34:39 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db5100c4esm16270255ad.173.2025.04.24.10.34.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 10:34:38 -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 , Deepak Gupta Subject: [PATCH v6 07/14] riscv: misaligned: use on_each_cpu() for scalar misaligned access probing Date: Thu, 24 Apr 2025 19:31:54 +0200 Message-ID: <20250424173204.1948385-8-cleger@rivosinc.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250424173204.1948385-1-cleger@rivosinc.com> References: <20250424173204.1948385-1-cleger@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 schedule_on_each_cpu() was used without any good reason while documented as very slow. This call was in the boot path, so better use on_each_cpu() for scalar misaligned checking. Vector misaligned check still needs to use schedule_on_each_cpu() since it requires irqs to be enabled but that's less of a problem since this code is ran in a kthread. Add a comment to explicit that. Signed-off-by: Clément Léger Reviewed-by: Andrew Jones --- arch/riscv/kernel/traps_misaligned.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/traps_misaligned.c index 6bb734abf9a4..e1fe39cc6709 100644 --- a/arch/riscv/kernel/traps_misaligned.c +++ b/arch/riscv/kernel/traps_misaligned.c @@ -610,6 +610,10 @@ bool __init check_vector_unaligned_access_emulated_all_cpus(void) { int cpu; + /* + * While being documented as very slow, schedule_on_each_cpu() is used since + * kernel_vector_begin() expects irqs to be enabled or it will panic() + */ schedule_on_each_cpu(check_vector_unaligned_access_emulated); for_each_online_cpu(cpu) @@ -630,7 +634,7 @@ bool __init check_vector_unaligned_access_emulated_all_cpus(void) static bool unaligned_ctl __read_mostly; -static void check_unaligned_access_emulated(struct work_struct *work __always_unused) +static void check_unaligned_access_emulated(void *arg __always_unused) { int cpu = smp_processor_id(); long *mas_ptr = per_cpu_ptr(&misaligned_access_speed, cpu); @@ -671,7 +675,7 @@ bool __init check_unaligned_access_emulated_all_cpus(void) * accesses emulated since tasks requesting such control can run on any * CPU. */ - schedule_on_each_cpu(check_unaligned_access_emulated); + on_each_cpu(check_unaligned_access_emulated, NULL, 1); for_each_online_cpu(cpu) if (per_cpu(misaligned_access_speed, cpu) From patchwork Thu Apr 24 17:31:56 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: 884103 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 E4BD328E610 for ; Thu, 24 Apr 2025 17:34:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745516100; cv=none; b=DXb7z0m1drGvSpnRIS3IocfEshXBk9RFtEPHfQl+i9GunIRooAhjSP+vyX5AMtT+SXnGduNsftaHpB8RfCTVZ8UnXZBvMf0MrQ/9dLWSh909L26z41FX5ABamw9vjzV/lHrIUzlZd89aiSx/imPuBg1YST+ogcrtBemh80j4j1g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745516100; c=relaxed/simple; bh=i5EIv8p28s9SzqwrmxjoQqEJ1yfHwtC674KTF1pprHo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jnDCUz7m8t7kak6Mnnv8S2aciUoeXqhYliGfD6osASD8CMsHLSuAMXFM8jXFvfreu3E/nEsMqF1pooTCPbgn+Byzk/HrMxpBVniUm1nSR/XDiTZSidvSqUp03RbT7KK+S2DSypsXVMlu4i5vLw2XQmArAWTeAbnFgEJkUzYQ/HU= 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=1VZgrW3i; arc=none smtp.client-ip=209.85.214.172 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="1VZgrW3i" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-227cf12df27so13335705ad.0 for ; Thu, 24 Apr 2025 10:34:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1745516097; x=1746120897; 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=d9V9rr9KXScjB209CCQhOyL2xY7TO+2YEqW9Zt14WVs=; b=1VZgrW3ieCTJyupdtrSzNRChjSrTt4vxjboJO3oYPeJCPtFhgXTsz0TdL/sckxV5Cw RAoNKuRJjYYlodoeNheGzH959ekAGgr4OS0V4z0DOvR4kUXK25OwlLy71LHSL5tJbFsS 8NT9wO+qyG/DpBM7Q+qwHKQhjSlKm+BUrxcqhRyte1b+6WmBBw/ohVnOmVlM28vdrVI3 W3lY377hDMPfCUUrU8YEzEFLPh+iETYA6DEednsSwelK8nO27b2xFxq5ddW3t/Dzo9z8 90PSicaUF1TZ8EgBeQ8Dt4B7fXd1CyIrc1HcUsLIM+eXII5k7UfeRbmqeEee3k46kZks btvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745516097; x=1746120897; 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=d9V9rr9KXScjB209CCQhOyL2xY7TO+2YEqW9Zt14WVs=; b=bfRVrNS/CEI/jD/1Jn7dq/m5OmYE1e4Z6gaMdIvQOqIjfQRMlUok99Ur9bFb1s569j 4QVKYu9IPEIAJFsE1nlmerODG0kcvbEV0maAxsxXfKGpIIsH08WYGSG6W+di+OBDpCOi Q3NcZSpJePuYkFN4Q14XRpyVEdCGQUXeLcbCOm6ybA1ZlGDedP13bb24vcDcVuA/3Znb 1sXL3JMOdZu9EX+6TotDcARGcJnvTRB8/l3m5M9A8hVAhG16m08PidF98u8y6JO0nmNZ 8QAAuDjncMQz8u+Bnmc6KdE2X7oNNtWDwrt4IEaJl2EP5nJVzL3F4iGF7zKWOfB/wtyR RpcA== X-Forwarded-Encrypted: i=1; AJvYcCVoTu4RNw8lwQkWt6nnU3BmHihyLJRHnTFJLZEOuEZXuqJo4egVqxqDDXRbsvwGUYBOJspV7m/nyMAcQUBMFxg=@vger.kernel.org X-Gm-Message-State: AOJu0YwfqWPBch8wBUary38uqpDWnwhx7M+Im6LZ1SqisgyJN/nhCc19 OyT8fZfFYJN6DvMGQQIUFUS7KpHgxqcvk8t89kWwm6nfi1l6pubkfs+f5b2El/0= X-Gm-Gg: ASbGncvweLwjCaqYNE13ekc149Z+JWdSn49VYxJlXmiOt3ugRE/bZRCzFc5D5MlZIST qcQcCx+bQOeGzh2+G9PQQ0gtHqGozEM86poXRVCepn4bBFf5eD/faGNfLkMX0Ta02+hQgxNv5QN VqxVPEuQmg/zRdLg4AArYedR3EU7Gv4lvG/HE2s5mVYzVz9hbtmFcADQmY9DiXODJiL8HnCBwnR ncrSQ6wsgTaAKUm/8ETA2cWbheBnwUxXfwDDhepdEe7PUjGlAqDnDcI29DhV+uOCG2HbLIU6DSP Cws/Dk7QiwL+0ucFbMVe4diNFbfMRE4B1DYZV8wVcse3qM5nPF5X X-Google-Smtp-Source: AGHT+IGAQrQw/KilPGjWcs2DXTqeGJNePUSlT3bxzRIay4dKTLJvYkpcmDxPXRgdgSxGOsYJ0V1TjQ== X-Received: by 2002:a17:903:14b:b0:223:607c:1d99 with SMTP id d9443c01a7336-22db46a3332mr45750265ad.0.1745516097242; Thu, 24 Apr 2025 10:34:57 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db5100c4esm16270255ad.173.2025.04.24.10.34.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 10:34:56 -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 , Deepak Gupta Subject: [PATCH v6 09/14] riscv: misaligned: move emulated access uniformity check in a function Date: Thu, 24 Apr 2025 19:31:56 +0200 Message-ID: <20250424173204.1948385-10-cleger@rivosinc.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250424173204.1948385-1-cleger@rivosinc.com> References: <20250424173204.1948385-1-cleger@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Split the code that check for the uniformity of misaligned accesses performance on all cpus from check_unaligned_access_emulated_all_cpus() to its own function which will be used for delegation check. No functional changes intended. Signed-off-by: Clément Léger Reviewed-by: Andrew Jones --- arch/riscv/kernel/traps_misaligned.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/traps_misaligned.c index e02e9b4b0fc5..410b2e0e0765 100644 --- a/arch/riscv/kernel/traps_misaligned.c +++ b/arch/riscv/kernel/traps_misaligned.c @@ -666,10 +666,20 @@ static int cpu_online_check_unaligned_access_emulated(unsigned int cpu) return 0; } -bool __init check_unaligned_access_emulated_all_cpus(void) +static bool all_cpus_unaligned_scalar_access_emulated(void) { int cpu; + for_each_online_cpu(cpu) + if (per_cpu(misaligned_access_speed, cpu) != + RISCV_HWPROBE_MISALIGNED_SCALAR_EMULATED) + return false; + + return true; +} + +bool __init check_unaligned_access_emulated_all_cpus(void) +{ /* * We can only support PR_UNALIGN controls if all CPUs have misaligned * accesses emulated since tasks requesting such control can run on any @@ -677,10 +687,8 @@ bool __init check_unaligned_access_emulated_all_cpus(void) */ on_each_cpu(check_unaligned_access_emulated, NULL, 1); - for_each_online_cpu(cpu) - if (per_cpu(misaligned_access_speed, cpu) - != RISCV_HWPROBE_MISALIGNED_SCALAR_EMULATED) - return false; + if (!all_cpus_unaligned_scalar_access_emulated()) + return false; unaligned_ctl = true; return true; From patchwork Thu Apr 24 17:31:58 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: 884102 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 783DB28FFE4 for ; Thu, 24 Apr 2025 17:35:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745516117; cv=none; b=GhS9wsRmldQZyWgsvcv27SeH2YQDHKa5yMCLH7qOoPBHMz2URIAwGh9agCnm/fOyg4CJi3ZyMGs83B6w9H9O/HEEh39GdvfdwbJ6Dn3131NB4W33I7dzvm6DcxArL9ULTq12XpDciGyRBzefd6+GHPphr49Pvyssh6FYKO6qBNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745516117; c=relaxed/simple; bh=NXa9HEO5RKY1D2k9IbxsxMtK9lSmU2PJg0VdH4XU874=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=k6d2ijvzEoE43JIym4Tp20xpiIptRsiyoPmyxXnysMV6GrCVLpoDACtHefuklr+ZWthWhe/gJcIy9mrdMe55cogZrhMJUz3I+V92CPt5PhCjnknOlKpDa3U47xY8n7NAZ+WDBtQDSHIMFbJDreA/HnHirDZGZUAV/Y433iZOb+I= 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=Bnm+M5Jw; arc=none smtp.client-ip=209.85.214.182 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="Bnm+M5Jw" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2243803b776so23423805ad.0 for ; Thu, 24 Apr 2025 10:35:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1745516115; x=1746120915; 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=/KHThPTp9HBECdAqxs4JY6wN99GqOifsmOPr7rqjaok=; b=Bnm+M5Jw3DAc3lwaZErrhiqa5TB0lLR8Ik327yAAsdeOP28hQnBQ4LKxfNYm1hP7SX UpWMjhrwgKf7Rk3qk6luqq+Dp0Z9b0aDLBRteFGku9gBNRlXnpWft7QxcLT1RKX2ZT/A 97Wuj2dp1oWPftm75fnE9wOoRZlr/AWtTruJOVynhSHaFtGK7U/MaL5qHOvuN3X8rX6T 6q108FZvYqhRlWUaIvtEvLzoL19DkrRTkcazg2a3l59IScl0bHUnNorCvfy7j1mkLzPH j+ZVbXoKBp1zQsf4EQmCWNEIk0CE/6vmT0JvlAsyHGpF880XZJZlq5bqM1T2rduGoKNQ pGIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745516115; x=1746120915; 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=/KHThPTp9HBECdAqxs4JY6wN99GqOifsmOPr7rqjaok=; b=Ct6feZelPLeRn3JpXpIqoveaiHFYeXwKJfrG1Z1RM/qRVWQVaTchOEhx8zukPUNZlL x13j1Llfx/c/OfBW4GV8nwrj1jgaldTEBL6azpYF2avPixUxtODbgTzMFfuxVriVGFig oRg/Its2dmkBHTp+OxdBIvn+MFVvTx2DUPR9v1RBgDfLfayfegNHxTG9Jrkg6Al4UgGP v8hD7MtpLNayx+PX4XURS10TT2PPhNFHgQIvXD1+32JJAO+SoQ0ulGCmxuokebAnI7aq kFxU//4eUjT8MMQxw0dLdQYP7cbjZmVdRb76W7D51iuRZ+Cy70gGvMliNP95nxmzfseu CK1Q== X-Forwarded-Encrypted: i=1; AJvYcCV6L7NasSpPcQATi0Z2g3QV+sWcWfHthM6drl5LTvRG/7QBAylHbOASCsM7iRlU6Maj53Vpz9HzBv7uSDCKgp4=@vger.kernel.org X-Gm-Message-State: AOJu0YzpgGjQcBtbBGEku4ymHvRc2O4AOSBjQowwDVDg1Tr+0FMNIogo yHC2z8UJ9S5dWh9y+57NiJFRDuMo/Yh/OQR/QGaZEdE6L/R0TNOY/9Ddx5bAXzM= X-Gm-Gg: ASbGnctH2CCJF+dRqFVWgMcxwECRwJiZHXhll2xiAgv571hZ5dRmkA22VuS7QSFNypX WEQb4WDmHiMiIgea6nJ3wwrbCa1BKYiPSNwaGNJ71rVWzJ+8lzxHWEiSnq1eVRl3jBDMfIlnhIB O3wzNnjcJPEzubuUxxc6uA/ZjAMpHBH5iWig1p90v7aGBNcyTFxQoq+On38UqaYjWkoLFwLa4ca 46J7ArY02CTVCBSA459Q7SxMyRA9sx1CDSZLgixJINXMq853ZNqWIApDp68GLfrZBfA9px1EvFQ mo+to+El9NYrvQjoKLAIMqCQ5/uLBGoJGWnK/25csg== X-Google-Smtp-Source: AGHT+IHk7ifeDzXStWRadJ48a4Rbu1GdvPFHAeWe+THKzkAyDqtofKTCbTRnNG+8lnQC3H+eIm6QNA== X-Received: by 2002:a17:902:d489:b0:220:ff3f:6cba with SMTP id d9443c01a7336-22db3d71b30mr52646935ad.38.1745516115638; Thu, 24 Apr 2025 10:35:15 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db5100c4esm16270255ad.173.2025.04.24.10.35.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 10:35:14 -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 , Deepak Gupta Subject: [PATCH v6 11/14] RISC-V: KVM: add SBI extension init()/deinit() functions Date: Thu, 24 Apr 2025 19:31:58 +0200 Message-ID: <20250424173204.1948385-12-cleger@rivosinc.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250424173204.1948385-1-cleger@rivosinc.com> References: <20250424173204.1948385-1-cleger@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kselftest@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 Reviewed-by: Andrew Jones --- arch/riscv/include/asm/kvm_vcpu_sbi.h | 9 +++++++++ arch/riscv/kvm/vcpu.c | 2 ++ arch/riscv/kvm/vcpu_sbi.c | 26 ++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi.h b/arch/riscv/include/asm/kvm_vcpu_sbi.h index 4ed6203cdd30..bcb90757b149 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 60d684c76c58..877bcc85c067 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -185,6 +185,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 d1c83a77735e..3139f171c20f 100644 --- a/arch/riscv/kvm/vcpu_sbi.c +++ b/arch/riscv/kvm/vcpu_sbi.c @@ -508,5 +508,31 @@ void kvm_riscv_vcpu_sbi_init(struct kvm_vcpu *vcpu) scontext->ext_status[idx] = ext->default_disabled ? KVM_RISCV_SBI_EXT_STATUS_DISABLED : KVM_RISCV_SBI_EXT_STATUS_ENABLED; + + if (ext->init && ext->init(vcpu) != 0) + scontext->ext_status[idx] = KVM_RISCV_SBI_EXT_STATUS_UNAVAILABLE; + } +} + +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_UNAVAILABLE || + !ext->deinit) + continue; + + ext->deinit(vcpu); } } From patchwork Thu Apr 24 17:32:00 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: 884101 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 721DD2900A6 for ; Thu, 24 Apr 2025 17:35:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745516136; cv=none; b=arvZQza0rQTYZfF0v5tHj9F3PHiJ1YlQBdFsnRClWZhOEJP/4eLNsrl0m0xL0Q/sseRpNhMAmELowSHBjPwkoLXXOE+lUrxuIxonUPPwnQulMYD1bjCRC55kpnETt1YqQkyoyhEJUrh+xi5QANXQsLioIp7o0D+ORCuNaQcDEQY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745516136; c=relaxed/simple; bh=1C7Djni+0IZk+aDQP5LiExVKCiwH2agzUNaeaAf13I4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=H6uq+8NcPOS7+azDMgqTD/wdAGj+IzhW/FP9Ls3dcbWfyyTxlYArb8TihgTz40yiIzoX0bjOadIKr0PE2Ql3hZo9eOB6ByUc9wC6CQKbt0mMUpUYH+RsyOf4lhOIOwvOA1GLMDCXyZ1hjVQPrPqt06ch6h53lLmfOQlpgdGiVCM= 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=0OuXm3eq; arc=none smtp.client-ip=209.85.214.173 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="0OuXm3eq" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-22c33e5013aso17686205ad.0 for ; Thu, 24 Apr 2025 10:35:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1745516133; x=1746120933; 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=pIsv+titG4x0ovEMDknM6ko4IiiOufEK1Ymj080VPx4=; b=0OuXm3eq5dRrmJC9snSoI50FFQZhAzXlr2ejaAT5uESgat/91ksVjmo48TFG4pcvKM 5Co3m+5Mz3234mcVxUOf/NNVzDe/SbmAuGyi0dCiB3oJ9SiP5qZhSDvWf9gz6mQfbR57 G1wMoCqzmDuNtVYRhLw7pQhSFWubBPy38f5+PkFyVO7RXzC+Fbx1mcEmSD3LqnzzV/kt AnWoomz7sDsHAMcZra056SNJjtjPoBQEN1FEErY4ANifK464pMTv8byOtSPiyE4DXSXg guyR1i/U6T118wdUHWx1ZvQoEncfrHMxqX5EduowiA9F6yoAJrcWZ2wp/zzSzIg09diH psEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745516133; x=1746120933; 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=pIsv+titG4x0ovEMDknM6ko4IiiOufEK1Ymj080VPx4=; b=LHUVKyjK4v9wbXEB2SAhmMjwEj84y8ipfcX5AbyQwvao2o/HauUYCsvSThi3480PzS V99lI7u6MfpgcKSg8cGF8eewl49nM3t4hEFR57Dr4K1xcHMy0R4Yq+HW8cJzqWVF8U74 f4nGg9MDeMOW5+GyZTwam4xVdJ/ExPZNrMU+Lc41LfYq2xmSrt/9mKU5FgTXpGWS5V8z +KXy8MlQZLxchpJsYcETc+qzjSEzdwTsGM9GFiL1JDxC+f89lCxLQbdFHoQp3GS4UkaO 5HAnhlCwoYOwCzQjvR338SuhQg4suF5NiwGjo0RZdHJw9ZiuUyGamkOY/71lk13SXCqc XIEA== X-Forwarded-Encrypted: i=1; AJvYcCXLDux8t+lkAhHNjY5AwnbYL7F1b4Pgxq5yofN13XKAjwq0w0Elv32mkiAcs31n78idp2LzrKzjiW8raFAOeK4=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+BFziINkiCHvZ0AuXLG3/I+Q1vd+WiqDl2Ew7Q7am0l6niQza rM1tInqAObksxS42ekamrxP1vz6wQ7amx9GSGMLX8AtRJ4QznQFLktLrmlfsbNU= X-Gm-Gg: ASbGncuSUrFB3pucVPdbI4aVyMlPRDnkVAv61/hDkbC+7i7RjAadiMhhLCPNHVM2xsq YIxKR/zWJluGGzZI5O6X2CD8Gp9JxGzovuD28qu+OjbT7M6VHnIe0FeYXpmHwMCFEeug8t8PNA2 T6PZ16/ny8iSjnaF6nLD/S/78Nogdpx5Un8WPXvjspL+ct2h8iFDqO6SYn+bNbB8fWcfstYyq3B vFs23vhjumyA9alWuv7XntfD2/iDDdl/5AiPGL+Eb89lBScU0HX1FV3sxINvuThsLsN8EA3ggvS cb9g1XZd27h0F9+anxMvRX3TZol6PrHR2cc/PDUNRg== X-Google-Smtp-Source: AGHT+IG9MFmvlCC44cS0jYEh46W0kXDkUBACm39Pu4nHZgkwqd3/vf/EeN8PbrVqTWMOQVYaPZCP6g== X-Received: by 2002:a17:903:234e:b0:223:67ac:8929 with SMTP id d9443c01a7336-22dbd35407bmr5607675ad.0.1745516133553; Thu, 24 Apr 2025 10:35:33 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db5100c4esm16270255ad.173.2025.04.24.10.35.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 10:35:32 -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 , Deepak Gupta Subject: [PATCH v6 13/14] RISC-V: KVM: add support for FWFT SBI extension Date: Thu, 24 Apr 2025 19:32:00 +0200 Message-ID: <20250424173204.1948385-14-cleger@rivosinc.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250424173204.1948385-1-cleger@rivosinc.com> References: <20250424173204.1948385-1-cleger@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kselftest@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 Reviewed-by: Andrew Jones --- 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 | 29 +++ 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 | 216 +++++++++++++++++++++ 7 files changed, 256 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 4fa02e082142..c3f880763b9a 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 @@ -281,6 +282,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 cb68b3a57c8f..ffd03fed0c06 100644 --- a/arch/riscv/include/asm/kvm_vcpu_sbi.h +++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h @@ -98,6 +98,7 @@ 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_susp; 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..9ba841355758 --- /dev/null +++ b/arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h @@ -0,0 +1,29 @@ +/* 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_feature; + +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 5f59fd226cc5..5ba77a3d9f6e 100644 --- a/arch/riscv/include/uapi/asm/kvm.h +++ b/arch/riscv/include/uapi/asm/kvm.h @@ -204,6 +204,7 @@ enum KVM_RISCV_SBI_EXT_ID { KVM_RISCV_SBI_EXT_DBCN, KVM_RISCV_SBI_EXT_STA, KVM_RISCV_SBI_EXT_SUSP, + KVM_RISCV_SBI_EXT_FWFT, KVM_RISCV_SBI_EXT_MAX, }; diff --git a/arch/riscv/kvm/Makefile b/arch/riscv/kvm/Makefile index 4e0bba91d284..06e2d52a9b88 100644 --- a/arch/riscv/kvm/Makefile +++ b/arch/riscv/kvm/Makefile @@ -26,6 +26,7 @@ kvm-y += vcpu_onereg.o kvm-$(CONFIG_RISCV_PMU_SBI) += vcpu_pmu.o kvm-y += vcpu_sbi.o kvm-y += vcpu_sbi_base.o +kvm-y += vcpu_sbi_fwft.o kvm-y += vcpu_sbi_hsm.o kvm-$(CONFIG_RISCV_PMU_SBI) += vcpu_sbi_pmu.o kvm-y += vcpu_sbi_replace.o diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c index 50be079b5528..0748810c0252 100644 --- a/arch/riscv/kvm/vcpu_sbi.c +++ b/arch/riscv/kvm/vcpu_sbi.c @@ -78,6 +78,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..b0f66c7bf010 --- /dev/null +++ b/arch/riscv/kvm/vcpu_sbi_fwft.c @@ -0,0 +1,216 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2025 Rivos Inc. + * + * Authors: + * Clément Léger + */ + +#include +#include +#include +#include +#include +#include +#include + +struct kvm_sbi_fwft_feature { + /** + * @id: Feature ID + */ + enum sbi_fwft_feature_t id; + + /** + * @supported: Check if the feature is supported on the vcpu + * + * This callback is optional, if not provided the feature is assumed to + * be supported + */ + bool (*supported)(struct kvm_vcpu *vcpu); + + /** + * @set: Set the feature value + * + * Return SBI_SUCCESS on success or an SBI error (SBI_ERR_*) + * + * This callback is mandatory + */ + long (*set)(struct kvm_vcpu *vcpu, struct kvm_sbi_fwft_config *conf, unsigned long value); + + /** + * @get: Get the feature current value + * + * Return SBI_SUCCESS on success or an SBI error (SBI_ERR_*) + * + * This callback is mandatory + */ + long (*get)(struct kvm_vcpu *vcpu, struct kvm_sbi_fwft_config *conf, unsigned long *value); +}; + +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; + 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, u32 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, u32 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_LOCKED; + + conf->flags = flags; + + return conf->feature->set(vcpu, conf, value); +} + +static int kvm_sbi_fwft_get(struct kvm_vcpu *vcpu, unsigned long 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; + 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); +} + +static void kvm_sbi_ext_fwft_reset(struct kvm_vcpu *vcpu) +{ + int i; + struct kvm_sbi_fwft *fwft = vcpu_to_fwft(vcpu); + + for (i = 0; i < ARRAY_SIZE(features); i++) + fwft->configs[i].flags = 0; +} + +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, + .reset = kvm_sbi_ext_fwft_reset, +};