From patchwork Wed Dec 20 16:00:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13500319 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B86DFC3DA6E for ; Wed, 20 Dec 2023 16:00:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ItrizmMfF3zOPobiQgR3+9xhQLh2Fk1ULcXngq6UeqQ=; b=IHGLHnP65PHI09 tb9TXiskYii2ZGnX1GA/Q/iMayY8hCut1saoe6ddfNmC5PwNWipNV9sJP1UhVra1S6pchPEYLMWb/ XQ5BJ+Bn5myQeYiNPRLjoIDvMRm/B2dvSUycOIbxm4XY6xPSBUXanxiznw6CqBt7a83k84YPNzPRi YSLrLFJyjPQvgfWLNghbPP225iig5QKwwjffGxyYIIX0p2qUUZTdR573S9uJOUAtw+5yp1r63WP/q NxX9eh92xrSk00H42BKMugEPaNcuqVeKZ36KZN20VlYCbqwT5R5wzeWbPmXGxl0SfOTiM4RtxhhwU 6JbwyR4gcxu4NSeG+Fqg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rFyzu-000M23-17; Wed, 20 Dec 2023 16:00:38 +0000 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rFyze-000LkL-01 for linux-riscv@lists.infradead.org; Wed, 20 Dec 2023 16:00:26 +0000 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-33670b90013so583877f8f.1 for ; Wed, 20 Dec 2023 08:00:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1703088018; x=1703692818; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VOo7Z/H7J6tqkBq4hfDJpxmukb9QSdgx1tFy1WWbX+c=; b=BK0wPl7CDmhKtPHkvbil/XzkJsfYlvO/gPRhsBSL/P5mLPD7w4db60a9o1Vn7qgZv5 UK1Ao3s6Dj1uEERzT8xgeCa3b5JGbIIj6rgTThNhogutjPa76qAhfN222Qpf83Cqnivu Pljd9Ds94XXcDBUSCxWsGg4B+wMebRcAdWK7CjXWhvlmQ+/gcLUn6uD6YZvuDczINrqR viYxlr/vH3rrjnuFiG6qiXGvcySRm6rMd9XV5ZW7YnPwqn0Lvf2DU5J7gF0Dc5iSEUEs CB7bq1rrMGSmTvw2yrfNzDEWz3tuqmipogjerPSjJAtGWg+6aoF4lFlW1rMBS/hsNzGG 05eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703088018; x=1703692818; 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=VOo7Z/H7J6tqkBq4hfDJpxmukb9QSdgx1tFy1WWbX+c=; b=qonEQ3UaK8Y8XZKDw8sG4xpjhL+AgiILD4omYJKaIZovgZHlsJZxgne/boIbGbzOF+ gGQRSkjPm0qrBxsBEufoxzzM+PYKQv34qG0K/IW25rWlO2Y21wa8D1KGkEcEJaFUXC4O G/Rr+cMD9ArNMWFzm1dnvs6zWAEv8YK2vJbvn/0lWDJMo0u/e8amOs8tsq3tvYixC+6b lIwLnREO/UA4cCyGH9rhmBYOSBc/s0JpEK40zoAKv9N+zKVRvzlbHotET6pfwpOZ4xoT Gn9fF4ETM8bAWIWmhDUfzdmZgg0OsdMKWdFXm0lX+zUnRLDL3tbjRwBFrJ1pI0oPVJUU LV3w== X-Gm-Message-State: AOJu0Yxoe1JgcLTEz4d9CmAaIUdkFonCNPWTVyN9Rbk28HBJLR47xi3M peJ0GxQ9BTm+9GiUfWUTo76LbL1i20bIDA== X-Google-Smtp-Source: AGHT+IE9Iky3gmCLotvLOL4f831qzbTWlJLLRC6KMqg2w11BB/xgLe5O7Bfdlx/IFMWyv5cbl48bcQ== X-Received: by 2002:adf:e58d:0:b0:336:7229:d152 with SMTP id l13-20020adfe58d000000b003367229d152mr1529189wrm.2.1703088018055; Wed, 20 Dec 2023 08:00:18 -0800 (PST) Received: from localhost (cst-prg-16-115.cust.vodafone.cz. [46.135.16.115]) by smtp.gmail.com with ESMTPSA id e6-20020a056000194600b003367a5b6b69sm1985298wry.106.2023.12.20.08.00.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 08:00:17 -0800 (PST) From: Andrew Jones To: kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, virtualization@lists.linux-foundation.org Cc: anup@brainfault.org, atishp@atishpatra.org, pbonzini@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, jgross@suse.com, srivatsa@csail.mit.edu, guoren@kernel.org, conor.dooley@microchip.com, Atish Patra Subject: [PATCH v4 01/13] RISC-V: paravirt: Add skeleton for pv-time support Date: Wed, 20 Dec 2023 17:00:14 +0100 Message-ID: <20231220160012.40184-16-ajones@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220160012.40184-15-ajones@ventanamicro.com> References: <20231220160012.40184-15-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231220_080022_087783_23FB6E37 X-CRM114-Status: GOOD ( 18.47 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add the files and functions needed to support paravirt time on RISC-V. Also include the common code needed for the first application of pv-time, which is steal-time. In the next patches we'll complete the functions to fully enable steal-time support. Reviewed-by: Anup Patel Reviewed-by: Atish Patra Signed-off-by: Andrew Jones Acked-by: Palmer Dabbelt --- .../admin-guide/kernel-parameters.txt | 6 +- arch/riscv/include/asm/paravirt.h | 28 +++++++ arch/riscv/include/asm/paravirt_api_clock.h | 1 + arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/paravirt.c | 77 +++++++++++++++++++ arch/riscv/kernel/time.c | 3 + 6 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 arch/riscv/include/asm/paravirt.h create mode 100644 arch/riscv/include/asm/paravirt_api_clock.h create mode 100644 arch/riscv/kernel/paravirt.c diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 65731b060e3f..a0d9259e4857 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -3985,9 +3985,9 @@ vulnerability. System may allow data leaks with this option. - no-steal-acc [X86,PV_OPS,ARM64,PPC/PSERIES] Disable paravirtualized - steal time accounting. steal time is computed, but - won't influence scheduler behaviour + no-steal-acc [X86,PV_OPS,ARM64,PPC/PSERIES,RISCV] Disable + paravirtualized steal time accounting. steal time is + computed, but won't influence scheduler behaviour nosync [HW,M68K] Disables sync negotiation for all devices. diff --git a/arch/riscv/include/asm/paravirt.h b/arch/riscv/include/asm/paravirt.h new file mode 100644 index 000000000000..c0abde70fc2c --- /dev/null +++ b/arch/riscv/include/asm/paravirt.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_RISCV_PARAVIRT_H +#define _ASM_RISCV_PARAVIRT_H + +#ifdef CONFIG_PARAVIRT +#include + +struct static_key; +extern struct static_key paravirt_steal_enabled; +extern struct static_key paravirt_steal_rq_enabled; + +u64 dummy_steal_clock(int cpu); + +DECLARE_STATIC_CALL(pv_steal_clock, dummy_steal_clock); + +static inline u64 paravirt_steal_clock(int cpu) +{ + return static_call(pv_steal_clock)(cpu); +} + +int __init pv_time_init(void); + +#else + +#define pv_time_init() do {} while (0) + +#endif /* CONFIG_PARAVIRT */ +#endif /* _ASM_RISCV_PARAVIRT_H */ diff --git a/arch/riscv/include/asm/paravirt_api_clock.h b/arch/riscv/include/asm/paravirt_api_clock.h new file mode 100644 index 000000000000..65ac7cee0dad --- /dev/null +++ b/arch/riscv/include/asm/paravirt_api_clock.h @@ -0,0 +1 @@ +#include diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile index fee22a3d1b53..807c2bde1f83 100644 --- a/arch/riscv/kernel/Makefile +++ b/arch/riscv/kernel/Makefile @@ -85,6 +85,7 @@ obj-$(CONFIG_SMP) += sbi-ipi.o obj-$(CONFIG_SMP) += cpu_ops_sbi.o endif obj-$(CONFIG_HOTPLUG_CPU) += cpu-hotplug.o +obj-$(CONFIG_PARAVIRT) += paravirt.o obj-$(CONFIG_KGDB) += kgdb.o obj-$(CONFIG_KEXEC_CORE) += kexec_relocate.o crash_save_regs.o machine_kexec.o obj-$(CONFIG_KEXEC_FILE) += elf_kexec.o machine_kexec_file.o diff --git a/arch/riscv/kernel/paravirt.c b/arch/riscv/kernel/paravirt.c new file mode 100644 index 000000000000..080c95d2a295 --- /dev/null +++ b/arch/riscv/kernel/paravirt.c @@ -0,0 +1,77 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2023 Ventana Micro Systems Inc. + */ + +#define pr_fmt(fmt) "riscv-pv: " fmt + +#include +#include +#include +#include +#include +#include + +struct static_key paravirt_steal_enabled; +struct static_key paravirt_steal_rq_enabled; + +static u64 native_steal_clock(int cpu) +{ + return 0; +} + +DEFINE_STATIC_CALL(pv_steal_clock, native_steal_clock); + +static bool steal_acc = true; +static int __init parse_no_stealacc(char *arg) +{ + steal_acc = false; + return 0; +} + +early_param("no-steal-acc", parse_no_stealacc); + +static bool __init has_pv_steal_clock(void) +{ + return false; +} + +static int pv_time_cpu_online(unsigned int cpu) +{ + return 0; +} + +static int pv_time_cpu_down_prepare(unsigned int cpu) +{ + return 0; +} + +static u64 pv_time_steal_clock(int cpu) +{ + return 0; +} + +int __init pv_time_init(void) +{ + int ret; + + if (!has_pv_steal_clock()) + return 0; + + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, + "riscv/pv_time:online", + pv_time_cpu_online, + pv_time_cpu_down_prepare); + if (ret < 0) + return ret; + + static_call_update(pv_steal_clock, pv_time_steal_clock); + + static_key_slow_inc(¶virt_steal_enabled); + if (steal_acc) + static_key_slow_inc(¶virt_steal_rq_enabled); + + pr_info("Computing paravirt steal-time\n"); + + return 0; +} diff --git a/arch/riscv/kernel/time.c b/arch/riscv/kernel/time.c index 23641e82a9df..ba3477197789 100644 --- a/arch/riscv/kernel/time.c +++ b/arch/riscv/kernel/time.c @@ -12,6 +12,7 @@ #include #include #include +#include unsigned long riscv_timebase __ro_after_init; EXPORT_SYMBOL_GPL(riscv_timebase); @@ -45,4 +46,6 @@ void __init time_init(void) timer_probe(); tick_setup_hrtimer_broadcast(); + + pv_time_init(); } From patchwork Wed Dec 20 16:00:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13500320 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F0945C46CD3 for ; Wed, 20 Dec 2023 16:00:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2b/9Yav3EQ8K0UUs3czdIYaKlRndFl10wbqCTEjM4X4=; b=dGIkjS8nzIZYlt 7ZvXt6+FOLscJqKrErBmhTMWJWl9O37picIu1gvbA76Oo5jZwIMMWHF7nvOSq+0j/HivSs/4TgD0Y aLySXoOx9dSlPlZ2QbcUyu1byX+1LyuSv7OyGpPOmj4c24r69cuflCTBMop111++cO8AI/+tKFudu g94ab4iPeQv6tZ4HtPVXGmPqQSRNnTtbTR5njQCGlX4GMa6vJQRYKDGEhqwy9NRRE1O52dgOR3r27 v+TuPrBtxvbBWVJXE9GmFSe2fkrlybCmmvOHBi0ZAyDmMPAMTMqPYx8ELkup2ucKvIzX/ylcTAFuh F3uaao9nhLJbJxAVP3IA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rFyzw-000M4C-2E; Wed, 20 Dec 2023 16:00:40 +0000 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rFyzg-000LmE-1F for linux-riscv@lists.infradead.org; Wed, 20 Dec 2023 16:00:27 +0000 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-3363aa2bbfbso6276781f8f.0 for ; Wed, 20 Dec 2023 08:00:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1703088020; x=1703692820; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bsqMVAX9+HvHM4O5cP+0LJ3eZPLQeiGLpoG96t1YCys=; b=CbmiRUrlACdELKI9D6FR3/8u8AtNZgPi1R5MGQczJZyFbYVgcTlgLuSjHCaIF7IUa9 hkw8wXPX7YH+nVlfYsEDnCw7sCP25JKIQ9k5yDlqz3dp+qWR/xU+9E0khwg0mtp0E6OW x+h3GHsdMf6XxJ6ZtEn8y+Q8gBWg0cYPYdBpun8A3X7M43AaOsl/b4m+eJ50JRGcJyaU CcZAdZGIfYEV8yBv/7XEs/EIdeXQ0jNq06Nr0T6adZMrQqZ7ci0OwGjX/g8ow7BY6Y3P dhO7RPEXdBayl8GrqbZy5FuG6Sp44oAL7su/obmPpX9rspmcm4VwX3wVFm/Rhi9e8FnH r+Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703088020; x=1703692820; 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=bsqMVAX9+HvHM4O5cP+0LJ3eZPLQeiGLpoG96t1YCys=; b=wO39KVgBkK1e+WIU9QwLb7Dekm+V00ouxM4RdhRcrT97pYHn5xelsDArFKTtTMOaE8 XOqDr5Td+F2CHhn0z4Nu2T3ETXmzng13Tfi73/VqIIP7qbqLZOf3Xxs1mHeY8jg+jH44 YGUUL0YyFspK7JlU/tNX0eIJGDDjQtZEuxgLj8rnp9CU4NC6iWyIunKlaFwZUeot/Tf+ Ul/G3Jy6MxnDDkWYRu4WiRfTvEJzJLtBLBKB8+bbKsDFV1c96bsvH1OK6cTW/nSoIo8q KooB9FuoP9Zi1kpV9yuj28dwNyyrph4OBYgOkms0+bPcHnP/X3rCe+mKf0k2KSaJd4gO R6+g== X-Gm-Message-State: AOJu0Yw9TkSu2/MNEwIo5zJngd5rA2Ce/bs2PSq1BLU0PsQNuuvOU5rg oHo7LjX6O5QvRzrh8pxnvq6eXQ== X-Google-Smtp-Source: AGHT+IGvi//DvXAg1xDIrKAJaGuMCehkfokcMb0T9IgvWVneX0+gPJn+9LH1j0ttz6W8NArfksk+Iw== X-Received: by 2002:adf:e412:0:b0:336:7a8d:bf6b with SMTP id g18-20020adfe412000000b003367a8dbf6bmr757905wrm.58.1703088020563; Wed, 20 Dec 2023 08:00:20 -0800 (PST) Received: from localhost (cst-prg-16-115.cust.vodafone.cz. [46.135.16.115]) by smtp.gmail.com with ESMTPSA id n9-20020a5d4009000000b0033677a4e0d6sm2893440wrp.13.2023.12.20.08.00.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 08:00:20 -0800 (PST) From: Andrew Jones To: kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, virtualization@lists.linux-foundation.org Cc: anup@brainfault.org, atishp@atishpatra.org, pbonzini@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, jgross@suse.com, srivatsa@csail.mit.edu, guoren@kernel.org, conor.dooley@microchip.com, Atish Patra Subject: [PATCH v4 02/13] RISC-V: Add SBI STA extension definitions Date: Wed, 20 Dec 2023 17:00:15 +0100 Message-ID: <20231220160012.40184-17-ajones@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220160012.40184-15-ajones@ventanamicro.com> References: <20231220160012.40184-15-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231220_080024_489037_FCB6A130 X-CRM114-Status: UNSURE ( 7.26 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The SBI STA extension enables steal-time accounting. Add the definitions it specifies. Reviewed-by: Conor Dooley Reviewed-by: Anup Patel Reviewed-by: Atish Patra Signed-off-by: Andrew Jones Acked-by: Palmer Dabbelt --- arch/riscv/include/asm/sbi.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 0892f4421bc4..b6f898c56940 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -31,6 +31,7 @@ enum sbi_ext_id { SBI_EXT_SRST = 0x53525354, SBI_EXT_PMU = 0x504D55, SBI_EXT_DBCN = 0x4442434E, + SBI_EXT_STA = 0x535441, /* Experimentals extensions must lie within this range */ SBI_EXT_EXPERIMENTAL_START = 0x08000000, @@ -243,6 +244,22 @@ enum sbi_ext_dbcn_fid { SBI_EXT_DBCN_CONSOLE_WRITE_BYTE = 2, }; +/* SBI STA (steal-time accounting) extension */ +enum sbi_ext_sta_fid { + SBI_EXT_STA_STEAL_TIME_SET_SHMEM = 0, +}; + +struct sbi_sta_struct { + __le32 sequence; + __le32 flags; + __le64 steal; + u8 preempted; + u8 pad[47]; +} __packed; + +#define SBI_STA_SHMEM_DISABLE -1 + +/* SBI spec version fields */ #define SBI_SPEC_VERSION_DEFAULT 0x1 #define SBI_SPEC_VERSION_MAJOR_SHIFT 24 #define SBI_SPEC_VERSION_MAJOR_MASK 0x7f From patchwork Wed Dec 20 16:00:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13500321 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0868FC3DA6E for ; Wed, 20 Dec 2023 16:00:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wIrdGhM+vfiotly56XbfhMVwfg715FH5klUoeXhu59U=; b=mRrMuhTyjsxC2t +fmKRWMvPY5ZSxAf3j74VrlVREIcOnFoKR7tEjRLRZKjk+9kWZtcYMXV/LBv6ndia3imYfUkubycL EcWd+vUt9z8dlE7zUfFPZNuzUWan7DeM0N8NRK1M9y2F0Fp55W8XvJT4LE//gq3J8OuRG6a7c2aLH PotgQ5RvdqcSUpvbhU9hFoQ96+BPn1gsGcqx3PzmEztE0oaJXmDVuD3QS5VnxM/HKdENKeB/kJhSB bYJI4eVQkegUTDmKIHQU+vbQRvPOSlYwyPP2G5sckCCcoUJYY0Cpp181c7p4Kz3XOj7SpBDby8EyX 3b99plJ3ljmlSsYGNxDw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rFyzy-000M6W-2H; Wed, 20 Dec 2023 16:00:42 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rFyzo-000LrJ-0T for linux-riscv@lists.infradead.org; Wed, 20 Dec 2023 16:00:34 +0000 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-40c48d7a7a7so53980995e9.3 for ; Wed, 20 Dec 2023 08:00:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1703088025; x=1703692825; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lWv1b2FFYWZhlrkz0rd4Y40mouV9jQQisf/jEYboQMg=; b=lne4Kz2aSVDkOU3i7lCERtRpQnJj6JX8XJh7lc2QDE+hA2Sk2nyRt63zRQGvydon5f r2z7TP97szQpsc5wKv6XdEN9ZAZ8OyYlngH9ZYePFPhZ1h4QhJ19F0RCy3h5d2v35VvD aQJduc3zK/pvsbBoaqJNROkf+5LNDf/nWknl5N1rAwyIFXMwMAQvX3fFDJRmIuobv85w gZKpRbHw0yC3hpxfM3MyqGHeq1RWvQBVLcfmbdS1psxe7FV1nKB1kXx/rRyg/vv/oiAO hWEw9T4Gqk4DLql/bezXzdx03L36BMUTM/usrEwnW2AAmgIwdtRQy3GgsOkxA4mAlprx gK4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703088025; x=1703692825; 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=lWv1b2FFYWZhlrkz0rd4Y40mouV9jQQisf/jEYboQMg=; b=eAmz0B27q0hpylOjR1W6hxNXr2GLL3HyVZT//ifkUfCXWbZdAfwSEyj8ut2I9uauwQ mPErnw7CHEoW/78+fjSuXZTQN418JfRza31Eo5nrYmX0IPbQ7txNhHbriId4BQpKn/mJ hhdLngiqBrRuZkFFZgKHUsBu2ZlYU/juu+Tzw4FIfoQHBhYWcCrYbvP7k1V73ibrskek oCOsWEnI92OGQtxmWZj/yzHuQunvn21jvSKYkStUlDbms3DORLEGPSH3hjr7mn3wO7RU 7cNGudRUZXmRtsG7oxeSn56zV5wQk6GqG9UYP2TqjCJkTK0U1jX6DfyoWx5LzpsGPGfo aQmg== X-Gm-Message-State: AOJu0YwbQr3cNsiJlKKqATNqjAw3jR29UsSTjUOxniFIiMftsF/JrDoG vZ/9TJEz+1klAoHZkfrSDjYmog== X-Google-Smtp-Source: AGHT+IHVvI5ZqhZaeg4C46CXZ1+zhCNNhxSIuL3dAJlR2VQgnunKdikGdwK0omwckzUrn3x0Ub3amQ== X-Received: by 2002:a05:600c:3105:b0:40c:7103:d9c9 with SMTP id g5-20020a05600c310500b0040c7103d9c9mr4994434wmo.115.1703088025717; Wed, 20 Dec 2023 08:00:25 -0800 (PST) Received: from localhost (cst-prg-16-115.cust.vodafone.cz. [46.135.16.115]) by smtp.gmail.com with ESMTPSA id c5-20020a05600c0a4500b0040c411da99csm7955710wmq.48.2023.12.20.08.00.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 08:00:25 -0800 (PST) From: Andrew Jones To: kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, virtualization@lists.linux-foundation.org Cc: anup@brainfault.org, atishp@atishpatra.org, pbonzini@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, jgross@suse.com, srivatsa@csail.mit.edu, guoren@kernel.org, conor.dooley@microchip.com, Atish Patra Subject: [PATCH v4 03/13] RISC-V: paravirt: Implement steal-time support Date: Wed, 20 Dec 2023 17:00:16 +0100 Message-ID: <20231220160012.40184-18-ajones@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220160012.40184-15-ajones@ventanamicro.com> References: <20231220160012.40184-15-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231220_080032_483052_A4F6F994 X-CRM114-Status: GOOD ( 18.37 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org When the SBI STA extension exists we can use it to implement paravirt steal-time support. Fill in the empty pv-time functions with an SBI STA implementation and add the Kconfig knobs allowing it to be enabled. Reviewed-by: Atish Patra Reviewed-by: Anup Patel Signed-off-by: Andrew Jones Acked-by: Palmer Dabbelt --- arch/riscv/Kconfig | 19 +++++++++++ arch/riscv/kernel/paravirt.c | 63 ++++++++++++++++++++++++++++++++++-- 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 95a2a06acc6a..b99fd8129edf 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -724,6 +724,25 @@ config COMPAT If you want to execute 32-bit userspace applications, say Y. +config PARAVIRT + bool "Enable paravirtualization code" + depends on RISCV_SBI + help + This changes the kernel so it can modify itself when it is run + under a hypervisor, potentially improving performance significantly + over full virtualization. + +config PARAVIRT_TIME_ACCOUNTING + bool "Paravirtual steal time accounting" + depends on PARAVIRT + help + Select this option to enable fine granularity task steal time + accounting. Time spent executing other tasks in parallel with + the current vCPU is discounted from the vCPU power. To account for + that, there can be a small performance impact. + + If in doubt, say N here. + config RELOCATABLE bool "Build a relocatable kernel" depends on MMU && 64BIT && !XIP_KERNEL diff --git a/arch/riscv/kernel/paravirt.c b/arch/riscv/kernel/paravirt.c index 080c95d2a295..574733b2bbea 100644 --- a/arch/riscv/kernel/paravirt.c +++ b/arch/riscv/kernel/paravirt.c @@ -6,12 +6,21 @@ #define pr_fmt(fmt) "riscv-pv: " fmt #include +#include +#include #include #include +#include +#include +#include #include #include #include +#include +#include +#include + struct static_key paravirt_steal_enabled; struct static_key paravirt_steal_rq_enabled; @@ -31,24 +40,72 @@ static int __init parse_no_stealacc(char *arg) early_param("no-steal-acc", parse_no_stealacc); +DEFINE_PER_CPU(struct sbi_sta_struct, steal_time) __aligned(64); + static bool __init has_pv_steal_clock(void) { + if (sbi_spec_version >= sbi_mk_version(2, 0) && + sbi_probe_extension(SBI_EXT_STA) > 0) { + pr_info("SBI STA extension detected\n"); + return true; + } + return false; } -static int pv_time_cpu_online(unsigned int cpu) +static int sbi_sta_steal_time_set_shmem(unsigned long lo, unsigned long hi, + unsigned long flags) { + struct sbiret ret; + + ret = sbi_ecall(SBI_EXT_STA, SBI_EXT_STA_STEAL_TIME_SET_SHMEM, + lo, hi, flags, 0, 0, 0); + if (ret.error) { + if (lo == SBI_STA_SHMEM_DISABLE && hi == SBI_STA_SHMEM_DISABLE) + pr_warn("Failed to disable steal-time shmem"); + else + pr_warn("Failed to set steal-time shmem"); + return sbi_err_map_linux_errno(ret.error); + } + return 0; } +static int pv_time_cpu_online(unsigned int cpu) +{ + struct sbi_sta_struct *st = this_cpu_ptr(&steal_time); + phys_addr_t pa = __pa(st); + unsigned long lo = (unsigned long)pa; + unsigned long hi = IS_ENABLED(CONFIG_32BIT) ? upper_32_bits((u64)pa) : 0; + + return sbi_sta_steal_time_set_shmem(lo, hi, 0); +} + static int pv_time_cpu_down_prepare(unsigned int cpu) { - return 0; + return sbi_sta_steal_time_set_shmem(SBI_STA_SHMEM_DISABLE, + SBI_STA_SHMEM_DISABLE, 0); } static u64 pv_time_steal_clock(int cpu) { - return 0; + struct sbi_sta_struct *st = per_cpu_ptr(&steal_time, cpu); + u32 sequence; + u64 steal; + + /* + * Check the sequence field before and after reading the steal + * field. Repeat the read if it is different or odd. + */ + do { + sequence = READ_ONCE(st->sequence); + virt_rmb(); + steal = READ_ONCE(st->steal); + virt_rmb(); + } while ((le32_to_cpu(sequence) & 1) || + sequence != READ_ONCE(st->sequence)); + + return le64_to_cpu(steal); } int __init pv_time_init(void) From patchwork Wed Dec 20 16:00:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13500323 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 49DDDC3DA6E for ; Wed, 20 Dec 2023 16:00:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ABSdupdRTM7Wj1uwS3m248fyPJQy/swdcBFX3sjbeiA=; b=Ro8DjbT40sz8YX CociqwWddQGOi6S4ZQRKhLcWG6bsD9lPHy0n/D0/TdVrFD04RWz79NDS9aUzGOIp9DasTQ4R9BZUU lkzaE59maEOyBE3khcDNjvu5pIy+fv1KLDmOs1TMahCBcPOBpEVZzNDDXAVLj/shZxn0DVF6VnEJK QRJHOrafTWfby7ombc5DXDdBH67sYwVjv1j4zojLy9wy+IsQsSBqH1yNhBrmGpieq97BtRGg/1HZy mr2NS2bjerT+ZCghlPKmKWT+oR0O4iXciY3gaH2bC5ZGs0TdW1hN2RxEUnj1UVpoZriB5f8fNSm5T sWDbEnDL7Xp/GiTfK6vw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rFz05-000ME4-30; Wed, 20 Dec 2023 16:00:49 +0000 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rFyzp-000Lsm-1Q for linux-riscv@lists.infradead.org; Wed, 20 Dec 2023 16:00:36 +0000 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-33666946422so3076952f8f.1 for ; Wed, 20 Dec 2023 08:00:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1703088028; x=1703692828; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ef7BOv98cAGOovGfjdBZq243xgaKf+nknpOtiiGkzlE=; b=LQ3hmuWy0700PmPAqI3E/mv7gevGLrKS2QnZ6yPhwpuWrz+T5UbopuW5kIrCvXact9 L+uULQgKY6/bpdDhj760bO0eB7Om+qpYCMuOxdAiSlAY7kLZTBXRKbKv1AGQhM8M5NZj aoJ7kwau1Zir48iGNTnvQbfrHpOOmYrC/WHYbGaWku0NNsmeXy3Z2kn/zGmEpHkgEf5i 7MELyo3Ga3Masbs0MwRH95zn7E7VBh72vxW+0SPDTP9K42aMpQlBz+XYALcRa6XBXdMH JG7doSPyPXAPJoswVtrZQbWGawPuOsztT7dXl7O1EAA0GcIRhRInXcIYUmqpY3Hn6HVM mIeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703088028; x=1703692828; 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=Ef7BOv98cAGOovGfjdBZq243xgaKf+nknpOtiiGkzlE=; b=SBqnEnTzZgW9C2ztMLs8fkLR42XvTWyPu48MJL98AFYdj75scCaH3b6lZOMiwBRr/l GRT3ZPzpEd3ZVaye6nnwsf1XBvZGwlUACTFwsROyS9xrjPWj7EI7KZxftBAmv8i3ufdL mr3OwbHgOC3AgkkeZ4s+9C5OqGeM3OXsm6lRiGgcXMML2SrtJpNGUD5aIxnJoP37RUja 3GrffOJ3aH/Pq7Zs0mpiWlA4bKA8gP4NKCymvt00oZppwRHRjqGwyxKa5x7zryTIUTwP LTqt/IEzJ3SixZYrzU8A3ze0xloNJtOH/EOhQ579VcYj68HpmS/7xuZlqW69TmoGIseB +AWQ== X-Gm-Message-State: AOJu0YyZrMt6fnFeXiTEpE7Fthlm6wfDhnnbGMELe1v/oeM8AdHpXdvN kcsz4GvjvsuXoBpDnySa5Pf9HQ== X-Google-Smtp-Source: AGHT+IEUaGQVUmOJpZrX/6wcMiUkr7MlMCgJwXmlqp3SKkS+7blylWY6WOfvZFXTaKATAxCW7rwCPQ== X-Received: by 2002:adf:f68c:0:b0:336:64cd:3fc3 with SMTP id v12-20020adff68c000000b0033664cd3fc3mr3328065wrp.59.1703088027960; Wed, 20 Dec 2023 08:00:27 -0800 (PST) Received: from localhost (cst-prg-16-115.cust.vodafone.cz. [46.135.16.115]) by smtp.gmail.com with ESMTPSA id d5-20020a5d5385000000b0033662cf5e51sm10303884wrv.93.2023.12.20.08.00.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 08:00:27 -0800 (PST) From: Andrew Jones To: kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, virtualization@lists.linux-foundation.org Cc: anup@brainfault.org, atishp@atishpatra.org, pbonzini@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, jgross@suse.com, srivatsa@csail.mit.edu, guoren@kernel.org, conor.dooley@microchip.com, Atish Patra Subject: [PATCH v4 04/13] RISC-V: KVM: Add SBI STA extension skeleton Date: Wed, 20 Dec 2023 17:00:17 +0100 Message-ID: <20231220160012.40184-19-ajones@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220160012.40184-15-ajones@ventanamicro.com> References: <20231220160012.40184-15-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231220_080033_519883_4A99EF9F X-CRM114-Status: GOOD ( 15.53 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add the files and functions needed to support the SBI STA (steal-time accounting) extension. In the next patches we'll complete the functions to fully enable SBI STA support. Reviewed-by: Anup Patel Reviewed-by: Atish Patra Signed-off-by: Andrew Jones --- arch/riscv/include/asm/kvm_vcpu_sbi.h | 1 + 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_sta.c | 47 +++++++++++++++++++++++++++ 5 files changed, 54 insertions(+) create mode 100644 arch/riscv/kvm/vcpu_sbi_sta.c diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi.h b/arch/riscv/include/asm/kvm_vcpu_sbi.h index bffda0ac59b6..99c23bb37a37 100644 --- a/arch/riscv/include/asm/kvm_vcpu_sbi.h +++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h @@ -76,6 +76,7 @@ extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_rfence; 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_experimental; extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_vendor; diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/asm/kvm.h index 60d3b21dead7..e961d79622fb 100644 --- a/arch/riscv/include/uapi/asm/kvm.h +++ b/arch/riscv/include/uapi/asm/kvm.h @@ -157,6 +157,7 @@ enum KVM_RISCV_SBI_EXT_ID { KVM_RISCV_SBI_EXT_EXPERIMENTAL, KVM_RISCV_SBI_EXT_VENDOR, KVM_RISCV_SBI_EXT_DBCN, + KVM_RISCV_SBI_EXT_STA, KVM_RISCV_SBI_EXT_MAX, }; diff --git a/arch/riscv/kvm/Makefile b/arch/riscv/kvm/Makefile index 4c2067fc59fc..c9646521f113 100644 --- a/arch/riscv/kvm/Makefile +++ b/arch/riscv/kvm/Makefile @@ -26,6 +26,7 @@ kvm-$(CONFIG_RISCV_SBI_V01) += vcpu_sbi_v01.o kvm-y += vcpu_sbi_base.o kvm-y += vcpu_sbi_replace.o kvm-y += vcpu_sbi_hsm.o +kvm-y += vcpu_sbi_sta.o kvm-y += vcpu_timer.o kvm-$(CONFIG_RISCV_PMU_SBI) += vcpu_pmu.o vcpu_sbi_pmu.o kvm-y += aia.o diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c index dcdff4458190..088daaa23dd8 100644 --- a/arch/riscv/kvm/vcpu_sbi.c +++ b/arch/riscv/kvm/vcpu_sbi.c @@ -70,6 +70,10 @@ static const struct kvm_riscv_sbi_extension_entry sbi_ext[] = { .ext_idx = KVM_RISCV_SBI_EXT_DBCN, .ext_ptr = &vcpu_sbi_ext_dbcn, }, + { + .ext_idx = KVM_RISCV_SBI_EXT_STA, + .ext_ptr = &vcpu_sbi_ext_sta, + }, { .ext_idx = KVM_RISCV_SBI_EXT_EXPERIMENTAL, .ext_ptr = &vcpu_sbi_ext_experimental, diff --git a/arch/riscv/kvm/vcpu_sbi_sta.c b/arch/riscv/kvm/vcpu_sbi_sta.c new file mode 100644 index 000000000000..839911dcd837 --- /dev/null +++ b/arch/riscv/kvm/vcpu_sbi_sta.c @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2023 Ventana Micro Systems Inc. + */ + +#include + +#include +#include + +static int kvm_sbi_sta_steal_time_set_shmem(struct kvm_vcpu *vcpu) +{ + return SBI_ERR_FAILURE; +} + +static int kvm_sbi_ext_sta_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, + struct kvm_vcpu_sbi_return *retdata) +{ + struct kvm_cpu_context *cp = &vcpu->arch.guest_context; + unsigned long funcid = cp->a6; + int ret; + + switch (funcid) { + case SBI_EXT_STA_STEAL_TIME_SET_SHMEM: + ret = kvm_sbi_sta_steal_time_set_shmem(vcpu); + break; + default: + ret = SBI_ERR_NOT_SUPPORTED; + break; + } + + retdata->err_val = ret; + + return 0; +} + +static unsigned long kvm_sbi_ext_sta_probe(struct kvm_vcpu *vcpu) +{ + return 0; +} + +const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_sta = { + .extid_start = SBI_EXT_STA, + .extid_end = SBI_EXT_STA, + .handler = kvm_sbi_ext_sta_handler, + .probe = kvm_sbi_ext_sta_probe, +}; From patchwork Wed Dec 20 16:00:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13500322 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 04D3AC46CD2 for ; Wed, 20 Dec 2023 16:00:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=KQMiQKzLwFiXFuHFSQOnKlYvO2lpbvK76/SpRTQU8GI=; b=gsHshCqu/+i92D 57Eh935Azttd4zo7QmbLsSa2b6Y42h2hcQ6rjfJkJs6QbQLMOasX6NpecafnMNBk+xF56OEfQV6Yt XMFmgIXQ4EuuUx4zwNdqVc9IBC7Wn6Nbhq6yX6DfEb5JTNemRrXxD3P726Yw1pMAkG5WPjyKOvwha b3QC3sDGBBM6y9PQVesqlgYAY77lyuclcc0Yq2jUJQ60b66lbZI0S/ub0U17Y/i7VhK3dtlQEKVaj hadgqsA3PoygAlu0QWOtvIiDQ0DCmjoY2otzqyD/hILhtPNpF/sj8bVi7e9/SX95OAE9pfxNDFzlw rQjdUh5OmUwELoJ/OjKg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rFz00-000M7z-1f; Wed, 20 Dec 2023 16:00:44 +0000 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rFyzp-000Luc-17 for linux-riscv@lists.infradead.org; Wed, 20 Dec 2023 16:00:36 +0000 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-33664b6d6abso3544793f8f.2 for ; Wed, 20 Dec 2023 08:00:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1703088030; x=1703692830; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=r9WZowL+tiFdWWavUDOR83U5hXyPT732YQIbLq7cwAs=; b=KS3tzBz9RTtJOswSud2FeZT7woTdX+gYD6Ewbh/zZokZRaEVO8ItVUqBvNn0w+CAUl wRpJsO9pSHRPGDBt/3zttaOHpI2zPnwKPxnoWCAN7ATmCPSs17OGBRjfD1MGIWp5a+lC ++AbhMMzi2XnQclSmV31XBlOsm0krB96kMMFaDzPoCmSA5LOKVObJxWjvbUrr9kIGk9d ICnQ9N+bVkVdJSE28HOBdmI1XnZjwlp05L8mUhiUG+mOw4QUbBJHCeMZl6agVSuDSYpX m8gvRiZXZ20awOP0q3304th35W+ex77N2hP9soDtF4jlFZhBGobWMQncmLoGmm2cDyHk w2QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703088030; x=1703692830; 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=r9WZowL+tiFdWWavUDOR83U5hXyPT732YQIbLq7cwAs=; b=leB57aHuumDzRpPzXJM1kT4Fxl7XnSSC2mr0v6XflK+T7ORgSWKmk7cwiGTbqSGfZH Ykn+cDqc/zDm0lTEcuh11Sdpm4eczdVxo6jk2L6tEeLQJ2xstmo0mH10ZmOYwQpjHiO/ GVXEVo6mttHY6OQS27/sN+chyZwY32QVUNddoVndg6ljpzxZaUg6ohngko2Rs3l14tgd ExvAvcKA7YARyRY8V9XVyQ+j8cEMmq+Qf9Z75pKPjTPYQoLrWKk1zAxSPOAvzOTIdtMb REBMzWXxFKY7SRnBeeAEGs4zyVYJ3NZYxavk7R2r19wzOIQ/0JONpffII+WzZt/Y8HLc J3ZQ== X-Gm-Message-State: AOJu0YyIFNzuSwxrSQZU7wdQiNKn5ddHuHnIIE4x4hV/aA6H00idFSql Y/Jk4I5h9V1OAO9bZxh+qI901w== X-Google-Smtp-Source: AGHT+IEVa6diqsl6ZvfXSq0rGo7hhkqDRW+n7TrUzKDkkOE6cmouItUMotaPVRNMlhVQdWbIguLklw== X-Received: by 2002:a05:6000:2ae:b0:336:7a51:5fad with SMTP id l14-20020a05600002ae00b003367a515fadmr862343wry.141.1703088030605; Wed, 20 Dec 2023 08:00:30 -0800 (PST) Received: from localhost (cst-prg-16-115.cust.vodafone.cz. [46.135.16.115]) by smtp.gmail.com with ESMTPSA id z18-20020a5d4412000000b003367a51217csm2000039wrq.34.2023.12.20.08.00.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 08:00:30 -0800 (PST) From: Andrew Jones To: kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, virtualization@lists.linux-foundation.org Cc: anup@brainfault.org, atishp@atishpatra.org, pbonzini@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, jgross@suse.com, srivatsa@csail.mit.edu, guoren@kernel.org, conor.dooley@microchip.com, Atish Patra Subject: [PATCH v4 05/13] RISC-V: KVM: Add steal-update vcpu request Date: Wed, 20 Dec 2023 17:00:18 +0100 Message-ID: <20231220160012.40184-20-ajones@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220160012.40184-15-ajones@ventanamicro.com> References: <20231220160012.40184-15-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231220_080033_480729_60608E98 X-CRM114-Status: GOOD ( 12.67 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add a new vcpu request to inform a vcpu that it should record its steal-time information. The request is made each time it has been detected that the vcpu task was not assigned a cpu for some time, which is easy to do by making the request from vcpu-load. The record function is just a stub for now and will be filled in with the rest of the steal-time support functions in following patches. Reviewed-by: Anup Patel Reviewed-by: Atish Patra Signed-off-by: Andrew Jones --- arch/riscv/include/asm/kvm_host.h | 3 +++ arch/riscv/kvm/vcpu.c | 5 +++++ arch/riscv/kvm/vcpu_sbi_sta.c | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h index 0eefd9c991ae..230b82c3118d 100644 --- a/arch/riscv/include/asm/kvm_host.h +++ b/arch/riscv/include/asm/kvm_host.h @@ -41,6 +41,7 @@ KVM_ARCH_REQ_FLAGS(4, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP) #define KVM_REQ_HFENCE \ KVM_ARCH_REQ_FLAGS(5, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP) +#define KVM_REQ_STEAL_UPDATE KVM_ARCH_REQ(6) enum kvm_riscv_hfence_type { KVM_RISCV_HFENCE_UNKNOWN = 0, @@ -372,4 +373,6 @@ bool kvm_riscv_vcpu_has_interrupts(struct kvm_vcpu *vcpu, u64 mask); void kvm_riscv_vcpu_power_off(struct kvm_vcpu *vcpu); void kvm_riscv_vcpu_power_on(struct kvm_vcpu *vcpu); +void kvm_riscv_vcpu_record_steal_time(struct kvm_vcpu *vcpu); + #endif /* __RISCV_KVM_HOST_H__ */ diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index bf3952d1a621..6995b8b641e4 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -541,6 +541,8 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) kvm_riscv_vcpu_aia_load(vcpu, cpu); + kvm_make_request(KVM_REQ_STEAL_UPDATE, vcpu); + vcpu->cpu = cpu; } @@ -614,6 +616,9 @@ static void kvm_riscv_check_vcpu_requests(struct kvm_vcpu *vcpu) if (kvm_check_request(KVM_REQ_HFENCE, vcpu)) kvm_riscv_hfence_process(vcpu); + + if (kvm_check_request(KVM_REQ_STEAL_UPDATE, vcpu)) + kvm_riscv_vcpu_record_steal_time(vcpu); } } diff --git a/arch/riscv/kvm/vcpu_sbi_sta.c b/arch/riscv/kvm/vcpu_sbi_sta.c index 839911dcd837..e28351c9488b 100644 --- a/arch/riscv/kvm/vcpu_sbi_sta.c +++ b/arch/riscv/kvm/vcpu_sbi_sta.c @@ -8,6 +8,10 @@ #include #include +void kvm_riscv_vcpu_record_steal_time(struct kvm_vcpu *vcpu) +{ +} + static int kvm_sbi_sta_steal_time_set_shmem(struct kvm_vcpu *vcpu) { return SBI_ERR_FAILURE; From patchwork Wed Dec 20 16:00:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13500324 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 19E38C46CD2 for ; Wed, 20 Dec 2023 16:00:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aT5NTmgeAq0JsUiWUagcIKdrSlBtWCQzZvsLViQvqkQ=; b=m7113e6aA32H3S TvfkSLD4ksDSFnhKDGRFBGnB7qoxp8Xi94aRXkle0H/aYTLG5/s2aqt0GrpBTqxug2jOqfrjiYGQp Qvhx/h2f+sxvDAgQHwqoYnuDuvnKCDjt7Ehms+PI9KUAESjSBpurrZhmlizdcEoT70XA75IXu9g84 lfQJ620Q9GrR/zY5Soj8qvsTJSLEhETMBjuPIeXVeRheclJf9ocWbjKHzVM3R89kA6Sq+FZ15KnDh rM7K6wBHFRWNO2Tp+BJkdYa4TL4rcKx1pzL0xkppS08PKqwMe0FGXBCHjrl7O2ma+N/qygprcAOMZ oI7Vlzw0CmQY8NGgdbRg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rFz09-000MHl-1L; Wed, 20 Dec 2023 16:00:53 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rFyzq-000LxS-2W for linux-riscv@lists.infradead.org; Wed, 20 Dec 2023 16:00:36 +0000 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40c38e292c8so5828795e9.0 for ; Wed, 20 Dec 2023 08:00:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1703088033; x=1703692833; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VzYdl48Qu5esNXPbSwOP+CU6JD+JcYH87so17FZbvqA=; b=aNCtCG3Lkwr7lJ6Qitt1txa6J+mSo/QlIrp/GVqciilsEFnYTxAfpbGtFJbfJT6RAx ORzag9CIgF/m0Xe00hqDHgtItM/OlBv4lzkUfzVXtBOb1ElZPZs+pWByjgknV8GnrvHb aM2D4iou9GPkKooib9hglRghBB8zJgxwNq7gsnAXk9mUaTWJ4WEsc35+Iwe1LZo/9wG+ Zj+5eArAWFuOH4nABxm7SWhoBf+zuD6Hk6RbuFLB9CneRYcOYISMJw4lLKL5r/clEdsH mYafHplWeMHDbwNuviCVK6mW78IxSjY6OzMU8vy7BY9lBT+i4Sy0BYUq4T9PFgwtMJXb X4Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703088033; x=1703692833; 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=VzYdl48Qu5esNXPbSwOP+CU6JD+JcYH87so17FZbvqA=; b=Y1YKIhTgLDvFPZuE5txa7vJpFCT3cHqw3GjOR/W9cCbISpmxhV2Gq0U4MnyS307pIC C5FeBJ5oU8/qaT4PfVO0IgFnJ6CdZBcJPFadivpvr4cqTM3qtJtID1hx0d/nz4hHJEXV S5MunK/kTzOFv80HTOKqlvUr2sKi4j7SQ84WFC1pJbyc7KdDYXPySK3l4ZGSfiB79Rsv G5batToR0GkNdBr5qhELY3SUeQs3gHU8pPtCoI/MwEE1AW0l5IYNqXnxmpj0eq8/gXuP zbdvvahR7VDyehF8pTzjqvsfX9R9WFQUsdxzbZivdFa9oKsWf////l1kBaRdwZhkvrnS zVxQ== X-Gm-Message-State: AOJu0Yx3uR+OBHt5vzG4/USHSrjtZATno9BY0UjdpIF8M4KcIAo/HWmx kS2MyVj3NUCEWFwAwwfOi+HfjenT1YeIYQ== X-Google-Smtp-Source: AGHT+IE2QaQuI9sTDEwmQ5L0J8v/ZOAqNOWfssdYwo0NHGA5EvJQcP/ys+t3hMIZlKA61rdHjaH6Kw== X-Received: by 2002:a05:600c:3514:b0:40c:28ce:5d4 with SMTP id h20-20020a05600c351400b0040c28ce05d4mr1584057wmq.8.1703088033363; Wed, 20 Dec 2023 08:00:33 -0800 (PST) Received: from localhost (cst-prg-16-115.cust.vodafone.cz. [46.135.16.115]) by smtp.gmail.com with ESMTPSA id e18-20020adffc52000000b003366b15ddfasm7271251wrs.82.2023.12.20.08.00.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 08:00:32 -0800 (PST) From: Andrew Jones To: kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, virtualization@lists.linux-foundation.org Cc: anup@brainfault.org, atishp@atishpatra.org, pbonzini@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, jgross@suse.com, srivatsa@csail.mit.edu, guoren@kernel.org, conor.dooley@microchip.com, Atish Patra Subject: [PATCH v4 06/13] RISC-V: KVM: Add SBI STA info to vcpu_arch Date: Wed, 20 Dec 2023 17:00:19 +0100 Message-ID: <20231220160012.40184-21-ajones@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220160012.40184-15-ajones@ventanamicro.com> References: <20231220160012.40184-15-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231220_080035_109706_49A601AE X-CRM114-Status: GOOD ( 13.25 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org KVM's implementation of SBI STA needs to track the address of each VCPU's steal-time shared memory region as well as the amount of stolen time. Add a structure to vcpu_arch to contain this state and make sure that the address is always set to INVALID_GPA on vcpu reset. And, of course, ensure KVM won't try to update steal- time when the shared memory address is invalid. Reviewed-by: Anup Patel Reviewed-by: Atish Patra Signed-off-by: Andrew Jones --- arch/riscv/include/asm/kvm_host.h | 7 +++++++ arch/riscv/kvm/vcpu.c | 2 ++ arch/riscv/kvm/vcpu_sbi_sta.c | 10 ++++++++++ 3 files changed, 19 insertions(+) diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h index 230b82c3118d..525cba63e0c5 100644 --- a/arch/riscv/include/asm/kvm_host.h +++ b/arch/riscv/include/asm/kvm_host.h @@ -263,6 +263,12 @@ struct kvm_vcpu_arch { /* 'static' configurations which are set only once */ struct kvm_vcpu_config cfg; + + /* SBI steal-time accounting */ + struct { + gpa_t shmem; + u64 last_steal; + } sta; }; static inline void kvm_arch_sync_events(struct kvm *kvm) {} @@ -373,6 +379,7 @@ bool kvm_riscv_vcpu_has_interrupts(struct kvm_vcpu *vcpu, u64 mask); void kvm_riscv_vcpu_power_off(struct kvm_vcpu *vcpu); void kvm_riscv_vcpu_power_on(struct kvm_vcpu *vcpu); +void kvm_riscv_vcpu_sbi_sta_reset(struct kvm_vcpu *vcpu); void kvm_riscv_vcpu_record_steal_time(struct kvm_vcpu *vcpu); #endif /* __RISCV_KVM_HOST_H__ */ diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index 6995b8b641e4..b5ca9f2e98ac 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -83,6 +83,8 @@ static void kvm_riscv_reset_vcpu(struct kvm_vcpu *vcpu) vcpu->arch.hfence_tail = 0; memset(vcpu->arch.hfence_queue, 0, sizeof(vcpu->arch.hfence_queue)); + kvm_riscv_vcpu_sbi_sta_reset(vcpu); + /* Reset the guest CSRs for hotplug usecase */ if (loaded) kvm_arch_vcpu_load(vcpu, smp_processor_id()); diff --git a/arch/riscv/kvm/vcpu_sbi_sta.c b/arch/riscv/kvm/vcpu_sbi_sta.c index e28351c9488b..6592d287fc4e 100644 --- a/arch/riscv/kvm/vcpu_sbi_sta.c +++ b/arch/riscv/kvm/vcpu_sbi_sta.c @@ -8,8 +8,18 @@ #include #include +void kvm_riscv_vcpu_sbi_sta_reset(struct kvm_vcpu *vcpu) +{ + vcpu->arch.sta.shmem = INVALID_GPA; + vcpu->arch.sta.last_steal = 0; +} + void kvm_riscv_vcpu_record_steal_time(struct kvm_vcpu *vcpu) { + gpa_t shmem = vcpu->arch.sta.shmem; + + if (shmem == INVALID_GPA) + return; } static int kvm_sbi_sta_steal_time_set_shmem(struct kvm_vcpu *vcpu) From patchwork Wed Dec 20 16:00:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13500325 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 89D54C3DA6E for ; Wed, 20 Dec 2023 16:01:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=lS9EgRhBmaOAImkOnz7J6p6qFqgsV9Lh7k4dELZZUEA=; b=Qt8HVc2aWqfVXO Dn+hkb7TzO03NC9SO7CJ9YA/SH99VDE1ctD80SmVUNYbrUnBYuGG+aKhUmvypjlsAjsw3vEIwpQj8 K1ktoCNuUR7hlUt/tUiww+NDCg8hLbFrREFygkwCBwrnPWXic2QN3tZFgvx/iv0tW0ODiXmSST0HK qPBnAegVQUvB2iZtMG/mJwDVtxQBRhK0N8RZnpdAMdkC34Cp/w4db5hgxWP+gnkuMOtKYvoZIjcpP NTbYIa+VFMfiP/Ifsl4UO9yPkZS71ykgc07gvXInTD/T/kGr0ZkFwEAFAJZYYkXAyjBGpSiS+RPBC m0B8cIA+At87ID/zIx+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rFz0C-000ML3-11; Wed, 20 Dec 2023 16:00:56 +0000 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rFyzt-000M0F-1d for linux-riscv@lists.infradead.org; Wed, 20 Dec 2023 16:00:40 +0000 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-40c60dfa5bfso68276645e9.0 for ; Wed, 20 Dec 2023 08:00:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1703088036; x=1703692836; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rNcg4udqfynRQHSfPI9BJDgQt1epD/CHP8B3hiiPTls=; b=VSXXBci7qh3B61sR9FCML+sYNQdvZ8nD4CP15Tz4SRWB9gNBCpxTESkh4hhsH/nZ0V GZbN+f2RSWkvN0QXY1SDk1lm59OY3M8Qsj7mLgN9eKWc2Pq/JiMgaiBG4W9J+Q+8HzJH zm5i68XXGphUkD4LzXlD2NG+wCxOHWmgQPczDlVWp2ZEmB1/m5bBBmg+5C+LMe7aVV8G Fa6xE8xu5619SaKOdx6sl/vBvISBcTkUz953MBQOykCZQd4Cq7vNpuLsaQsd8bFRe0SZ vveJgjBvgAYlfWNOA9YdB1PVQIcL/K2eSV3C7f1lDQBl5kP4KbEUU17ujZ4TI2DGm0ZY nN0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703088036; x=1703692836; 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=rNcg4udqfynRQHSfPI9BJDgQt1epD/CHP8B3hiiPTls=; b=tgUn3OxIbB+zOviSWBny+vlImlLSSlnM/l9UP5ZpGCsOsFCnHn6P3qr6B/8yUxvbFm hCOWmgFv5f5dabYl+U1uyXorgPrjgOilE62KDcX9d2X2jkL4GYhiF3kpb2maohVSwJKq W7UWe1j5nZshiDixiSHfqeg4eK6s10kyGILBXX+U+gzMthEcP4TpoEkZZdZV7Hj/6MIE o7dpjMpnQw+TkDU/jtHDpnFNcLA5GeTsrmXTpphOk1dA/KX/cxOM5YBBLwAgOU8Twx8O MmIqkU+7l+5t8ZWplatfIAyS8dOyIRqZMliXu1ufvt71bxa9kQ48yR0tom2N28E66G4A uenQ== X-Gm-Message-State: AOJu0YyUfk2Jq4KS0eQj3U7McowIL8DzCDQfajq+10WUcrkZSKrVRX7j 6qxZNityOWqy02LAN5OoLgc+Aw== X-Google-Smtp-Source: AGHT+IF46vxvJMbWYlmd76wErQA1d8b5qP/ZBPcfspZS1cyPORa8PdYeblN7xjiAp7wAbnWZ0L1qbQ== X-Received: by 2002:a05:600c:808e:b0:40b:5e59:c581 with SMTP id ew14-20020a05600c808e00b0040b5e59c581mr10876084wmb.171.1703088035897; Wed, 20 Dec 2023 08:00:35 -0800 (PST) Received: from localhost (cst-prg-16-115.cust.vodafone.cz. [46.135.16.115]) by smtp.gmail.com with ESMTPSA id q11-20020a05600c46cb00b0040d2d33312csm92255wmo.2.2023.12.20.08.00.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 08:00:35 -0800 (PST) From: Andrew Jones To: kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, virtualization@lists.linux-foundation.org Cc: anup@brainfault.org, atishp@atishpatra.org, pbonzini@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, jgross@suse.com, srivatsa@csail.mit.edu, guoren@kernel.org, conor.dooley@microchip.com, Atish Patra Subject: [PATCH v4 07/13] RISC-V: KVM: Add support for SBI extension registers Date: Wed, 20 Dec 2023 17:00:20 +0100 Message-ID: <20231220160012.40184-22-ajones@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220160012.40184-15-ajones@ventanamicro.com> References: <20231220160012.40184-15-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231220_080037_567586_9496E9D7 X-CRM114-Status: GOOD ( 15.04 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Some SBI extensions have state that needs to be saved / restored when migrating the VM. Provide a get/set-one-reg register type for SBI extension registers. Each SBI extension that uses this type will have its own subtype. There are currently no subtypes defined. The next patch introduces the first one. Reviewed-by: Anup Patel Reviewed-by: Atish Patra Signed-off-by: Andrew Jones --- arch/riscv/include/asm/kvm_vcpu_sbi.h | 4 ++ arch/riscv/include/uapi/asm/kvm.h | 3 ++ arch/riscv/kvm/vcpu_onereg.c | 42 +++++++++++++++++-- arch/riscv/kvm/vcpu_sbi.c | 58 +++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 4 deletions(-) diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi.h b/arch/riscv/include/asm/kvm_vcpu_sbi.h index 99c23bb37a37..dd60f73b5c36 100644 --- a/arch/riscv/include/asm/kvm_vcpu_sbi.h +++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h @@ -60,6 +60,10 @@ int kvm_riscv_vcpu_set_reg_sbi_ext(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg); int kvm_riscv_vcpu_get_reg_sbi_ext(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg); +int kvm_riscv_vcpu_set_reg_sbi(struct kvm_vcpu *vcpu, + const struct kvm_one_reg *reg); +int kvm_riscv_vcpu_get_reg_sbi(struct kvm_vcpu *vcpu, + const struct kvm_one_reg *reg); const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_find_ext( struct kvm_vcpu *vcpu, unsigned long extid); bool riscv_vcpu_supports_sbi_ext(struct kvm_vcpu *vcpu, int idx); diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/asm/kvm.h index e961d79622fb..3471b1e48d18 100644 --- a/arch/riscv/include/uapi/asm/kvm.h +++ b/arch/riscv/include/uapi/asm/kvm.h @@ -242,6 +242,9 @@ enum KVM_RISCV_SBI_EXT_ID { #define KVM_REG_RISCV_VECTOR_REG(n) \ ((n) + sizeof(struct __riscv_v_ext_state) / sizeof(unsigned long)) +/* Registers for specific SBI extensions are mapped as type 10 */ +#define KVM_REG_RISCV_SBI_STATE (0x0a << KVM_REG_RISCV_TYPE_SHIFT) + /* Device Control API: RISC-V AIA */ #define KVM_DEV_RISCV_APLIC_ALIGN 0x1000 #define KVM_DEV_RISCV_APLIC_SIZE 0x4000 diff --git a/arch/riscv/kvm/vcpu_onereg.c b/arch/riscv/kvm/vcpu_onereg.c index 11cdbf844291..c7f82a3b8fba 100644 --- a/arch/riscv/kvm/vcpu_onereg.c +++ b/arch/riscv/kvm/vcpu_onereg.c @@ -961,6 +961,29 @@ static unsigned long num_sbi_ext_regs(struct kvm_vcpu *vcpu) return copy_sbi_ext_reg_indices(vcpu, NULL); } +static inline unsigned long num_sbi_regs(struct kvm_vcpu *vcpu) +{ + return 0; +} + +static int copy_sbi_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices) +{ + int n = num_sbi_regs(vcpu); + + for (int i = 0; i < n; i++) { + u64 reg = KVM_REG_RISCV | KVM_REG_SIZE_U64 | + KVM_REG_RISCV_SBI_STATE | i; + + if (uindices) { + if (put_user(reg, uindices)) + return -EFAULT; + uindices++; + } + } + + return n; +} + static inline unsigned long num_vector_regs(const struct kvm_vcpu *vcpu) { if (!riscv_isa_extension_available(vcpu->arch.isa, v)) @@ -1028,6 +1051,7 @@ unsigned long kvm_riscv_vcpu_num_regs(struct kvm_vcpu *vcpu) res += num_vector_regs(vcpu); res += num_isa_ext_regs(vcpu); res += num_sbi_ext_regs(vcpu); + res += num_sbi_regs(vcpu); return res; } @@ -1083,6 +1107,12 @@ int kvm_riscv_vcpu_copy_reg_indices(struct kvm_vcpu *vcpu, ret = copy_sbi_ext_reg_indices(vcpu, uindices); if (ret < 0) return ret; + uindices += ret; + + ret = copy_sbi_reg_indices(vcpu, uindices); + if (ret < 0) + return ret; + uindices += ret; return 0; } @@ -1105,12 +1135,14 @@ int kvm_riscv_vcpu_set_reg(struct kvm_vcpu *vcpu, case KVM_REG_RISCV_FP_D: return kvm_riscv_vcpu_set_reg_fp(vcpu, reg, KVM_REG_RISCV_FP_D); + case KVM_REG_RISCV_VECTOR: + return kvm_riscv_vcpu_set_reg_vector(vcpu, reg); case KVM_REG_RISCV_ISA_EXT: return kvm_riscv_vcpu_set_reg_isa_ext(vcpu, reg); case KVM_REG_RISCV_SBI_EXT: return kvm_riscv_vcpu_set_reg_sbi_ext(vcpu, reg); - case KVM_REG_RISCV_VECTOR: - return kvm_riscv_vcpu_set_reg_vector(vcpu, reg); + case KVM_REG_RISCV_SBI_STATE: + return kvm_riscv_vcpu_set_reg_sbi(vcpu, reg); default: break; } @@ -1136,12 +1168,14 @@ int kvm_riscv_vcpu_get_reg(struct kvm_vcpu *vcpu, case KVM_REG_RISCV_FP_D: return kvm_riscv_vcpu_get_reg_fp(vcpu, reg, KVM_REG_RISCV_FP_D); + case KVM_REG_RISCV_VECTOR: + return kvm_riscv_vcpu_get_reg_vector(vcpu, reg); case KVM_REG_RISCV_ISA_EXT: return kvm_riscv_vcpu_get_reg_isa_ext(vcpu, reg); case KVM_REG_RISCV_SBI_EXT: return kvm_riscv_vcpu_get_reg_sbi_ext(vcpu, reg); - case KVM_REG_RISCV_VECTOR: - return kvm_riscv_vcpu_get_reg_vector(vcpu, reg); + case KVM_REG_RISCV_SBI_STATE: + return kvm_riscv_vcpu_get_reg_sbi(vcpu, reg); default: break; } diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c index 088daaa23dd8..a1997c39dfde 100644 --- a/arch/riscv/kvm/vcpu_sbi.c +++ b/arch/riscv/kvm/vcpu_sbi.c @@ -325,6 +325,64 @@ int kvm_riscv_vcpu_get_reg_sbi_ext(struct kvm_vcpu *vcpu, return 0; } +int kvm_riscv_vcpu_set_reg_sbi(struct kvm_vcpu *vcpu, + const struct kvm_one_reg *reg) +{ + unsigned long __user *uaddr = + (unsigned long __user *)(unsigned long)reg->addr; + unsigned long reg_num = reg->id & ~(KVM_REG_ARCH_MASK | + KVM_REG_SIZE_MASK | + KVM_REG_RISCV_SBI_STATE); + unsigned long reg_subtype, reg_val; + + if (KVM_REG_SIZE(reg->id) != sizeof(unsigned long)) + return -EINVAL; + + if (copy_from_user(®_val, uaddr, KVM_REG_SIZE(reg->id))) + return -EFAULT; + + reg_subtype = reg_num & KVM_REG_RISCV_SUBTYPE_MASK; + reg_num &= ~KVM_REG_RISCV_SUBTYPE_MASK; + + switch (reg_subtype) { + default: + return -EINVAL; + } + + return 0; +} + +int kvm_riscv_vcpu_get_reg_sbi(struct kvm_vcpu *vcpu, + const struct kvm_one_reg *reg) +{ + unsigned long __user *uaddr = + (unsigned long __user *)(unsigned long)reg->addr; + unsigned long reg_num = reg->id & ~(KVM_REG_ARCH_MASK | + KVM_REG_SIZE_MASK | + KVM_REG_RISCV_SBI_STATE); + unsigned long reg_subtype, reg_val; + int ret; + + if (KVM_REG_SIZE(reg->id) != sizeof(unsigned long)) + return -EINVAL; + + reg_subtype = reg_num & KVM_REG_RISCV_SUBTYPE_MASK; + reg_num &= ~KVM_REG_RISCV_SUBTYPE_MASK; + + switch (reg_subtype) { + default: + return -EINVAL; + } + + if (ret) + return ret; + + if (copy_to_user(uaddr, ®_val, KVM_REG_SIZE(reg->id))) + return -EFAULT; + + return 0; +} + const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_find_ext( struct kvm_vcpu *vcpu, unsigned long extid) { From patchwork Wed Dec 20 16:00:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13500326 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 806A4C46CD2 for ; Wed, 20 Dec 2023 16:01:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mxU3SRy9vx6y9SNwv1D4CSBhakyF4kvkD0cZiX/trhI=; b=EnU1SNpPEqiSy3 MXJc0GYeANg2nD9zgyQvsvC+td/5FdyUe9BxCXy1TKXAS/F6ksRPx42MreTP+9qagcovPXwVJrA1e YtwfxQkQs2GquiQMvoD2Bba8ycRB7PpkxkI0+E+rekOAq2qKBe3efLJDxhcNhsuPgAv+5x5lucuaA Uj9RANWwFrob9GrF3/kNSrTpByisFCPfuZBWwhN5Tztmy8qZiuebTzSIxRUN5tay1AwLQBeO49D/P J9islZ+PHNsHOtlw8+OREldr0eHu9/u6Sv/Qo4itsQAgcMf0hZrzdhz5CpAGm0A82TXuhLljgEos5 2B6Go/wwtdvfXWyHDvRA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rFz0D-000MLp-0H; Wed, 20 Dec 2023 16:00:57 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rFyzv-000M2e-1a for linux-riscv@lists.infradead.org; Wed, 20 Dec 2023 16:00:41 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-40d3a2703c9so3270535e9.0 for ; Wed, 20 Dec 2023 08:00:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1703088038; x=1703692838; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zpURfIIPcWjXkfktChCkrPfs/5M7Hj157zHrpDPFlwA=; b=XTI8FcQsbkXP3s+004CZabRpHOandtlI4Vo11oAmkZVYh0ml77PaBN4tz0f9QzBC/x eiRaE4lqvhLiyL/nI2dX/QpEDCSLDCAdVEnam5xlw8kB/hiHsa29uG6gsVlUjRF4yJAF sd9scn73aXEGTLrqZusX4FT3VdF8TdlPMYva4Dhf9HFPOrvL+fN7ZC2konlKbB/pGd0M jiv1//9wjb7u1nrkZYFmVDBhP+9Srdym8bBs6MYbCVULd/ErOrYhGGfvbSfXGkPm3Ova z9/QjW/2ley/HOM85ld9s3gIUlP4vpYuQAXFY7gYwrkh5369Cjg+L1aShn0JAsgDu+xf HHow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703088038; x=1703692838; 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=zpURfIIPcWjXkfktChCkrPfs/5M7Hj157zHrpDPFlwA=; b=WnZnKFkOxg36ah21GN8jVK4cIqCjDXpma/oCR5LOVQjnnBRHz7mv3VmhsM2i7JAJmD O4kkBWtIx3Nr+ILiyodq3qsemWiVNSsIn4jjXza/2HgpcSE0yJVmVyMnbNhNg1jatu5W PaJ8ZB29ZYViTx+mTiz8dY+DfYb74Tif7MkgLpmg4ARc96yW50DURvn59PHr6XAxWNO2 BgZQbKwN27MnLW+rlhYscqxbZzUmGrjq2tAplPu98MTOvCgZphRwkxtGsk606H7sXiEX +yTjgGQB9aXSn2vj9PjmM+HtM3gAkGucvNFyhNGIsekGNVbUgQZmzhFZ1dtrxmtzfrFY QoYA== X-Gm-Message-State: AOJu0YwgZxQbnaMSo4/DI/3wzETLKdmCbILKPup/h7z4nH9buqoXkCUo HbuLXsroQnAJDY0oRe9LmL3olQ== X-Google-Smtp-Source: AGHT+IGL7oUGx3f83Bo5k9llp34bKGp7jr5O5YoDBmVfFbYVE8j7jG1k5cMM6Pj230qSoSaurUzjsg== X-Received: by 2002:a05:600c:1688:b0:40c:1db4:3a53 with SMTP id k8-20020a05600c168800b0040c1db43a53mr10192900wmn.157.1703088038040; Wed, 20 Dec 2023 08:00:38 -0800 (PST) Received: from localhost (cst-prg-16-115.cust.vodafone.cz. [46.135.16.115]) by smtp.gmail.com with ESMTPSA id r20-20020a05600c459400b0040c3dcc36e6sm54372wmo.47.2023.12.20.08.00.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 08:00:37 -0800 (PST) From: Andrew Jones To: kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, virtualization@lists.linux-foundation.org Cc: anup@brainfault.org, atishp@atishpatra.org, pbonzini@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, jgross@suse.com, srivatsa@csail.mit.edu, guoren@kernel.org, conor.dooley@microchip.com Subject: [PATCH v4 08/13] RISC-V: KVM: Add support for SBI STA registers Date: Wed, 20 Dec 2023 17:00:21 +0100 Message-ID: <20231220160012.40184-23-ajones@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220160012.40184-15-ajones@ventanamicro.com> References: <20231220160012.40184-15-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231220_080039_553071_99C7AF57 X-CRM114-Status: GOOD ( 19.54 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org KVM userspace needs to be able to save and restore the steal-time shared memory address. Provide the address through the get/set-one-reg interface with two ulong-sized SBI STA extension registers (lo and hi). 64-bit KVM userspace must not set the hi register to anything other than zero and is allowed to completely neglect saving/restoring it. Reviewed-by: Anup Patel Signed-off-by: Andrew Jones --- arch/riscv/include/asm/kvm_vcpu_sbi.h | 5 +++ arch/riscv/include/uapi/asm/kvm.h | 9 +++++ arch/riscv/kvm/vcpu_onereg.c | 37 +++++++++++------- arch/riscv/kvm/vcpu_sbi.c | 5 +++ arch/riscv/kvm/vcpu_sbi_sta.c | 55 +++++++++++++++++++++++++++ 5 files changed, 97 insertions(+), 14 deletions(-) diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi.h b/arch/riscv/include/asm/kvm_vcpu_sbi.h index dd60f73b5c36..b96705258cf9 100644 --- a/arch/riscv/include/asm/kvm_vcpu_sbi.h +++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h @@ -70,6 +70,11 @@ 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); +int kvm_riscv_vcpu_get_reg_sbi_sta(struct kvm_vcpu *vcpu, unsigned long reg_num, + unsigned long *reg_val); +int kvm_riscv_vcpu_set_reg_sbi_sta(struct kvm_vcpu *vcpu, unsigned long reg_num, + unsigned long reg_val); + #ifdef CONFIG_RISCV_SBI_V01 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_v01; #endif diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/asm/kvm.h index 3471b1e48d18..d6b7a5b95874 100644 --- a/arch/riscv/include/uapi/asm/kvm.h +++ b/arch/riscv/include/uapi/asm/kvm.h @@ -161,6 +161,12 @@ enum KVM_RISCV_SBI_EXT_ID { KVM_RISCV_SBI_EXT_MAX, }; +/* SBI STA extension registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ +struct kvm_riscv_sbi_sta { + unsigned long shmem_lo; + unsigned long shmem_hi; +}; + /* Possible states for kvm_riscv_timer */ #define KVM_RISCV_TIMER_STATE_OFF 0 #define KVM_RISCV_TIMER_STATE_ON 1 @@ -244,6 +250,9 @@ enum KVM_RISCV_SBI_EXT_ID { /* Registers for specific SBI extensions are mapped as type 10 */ #define KVM_REG_RISCV_SBI_STATE (0x0a << KVM_REG_RISCV_TYPE_SHIFT) +#define KVM_REG_RISCV_SBI_STA (0x0 << KVM_REG_RISCV_SUBTYPE_SHIFT) +#define KVM_REG_RISCV_SBI_STA_REG(name) \ + (offsetof(struct kvm_riscv_sbi_sta, name) / sizeof(unsigned long)) /* Device Control API: RISC-V AIA */ #define KVM_DEV_RISCV_APLIC_ALIGN 0x1000 diff --git a/arch/riscv/kvm/vcpu_onereg.c b/arch/riscv/kvm/vcpu_onereg.c index c7f82a3b8fba..c95ea55c29a7 100644 --- a/arch/riscv/kvm/vcpu_onereg.c +++ b/arch/riscv/kvm/vcpu_onereg.c @@ -961,27 +961,36 @@ static unsigned long num_sbi_ext_regs(struct kvm_vcpu *vcpu) return copy_sbi_ext_reg_indices(vcpu, NULL); } -static inline unsigned long num_sbi_regs(struct kvm_vcpu *vcpu) -{ - return 0; -} - static int copy_sbi_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices) { - int n = num_sbi_regs(vcpu); + struct kvm_vcpu_sbi_context *scontext = &vcpu->arch.sbi_context; + int total = 0; - for (int i = 0; i < n; i++) { - u64 reg = KVM_REG_RISCV | KVM_REG_SIZE_U64 | - KVM_REG_RISCV_SBI_STATE | i; + if (scontext->ext_status[KVM_RISCV_SBI_EXT_STA] == KVM_RISCV_SBI_EXT_STATUS_ENABLED) { + u64 size = IS_ENABLED(CONFIG_32BIT) ? KVM_REG_SIZE_U32 : KVM_REG_SIZE_U64; + int n = sizeof(struct kvm_riscv_sbi_sta) / sizeof(unsigned long); - if (uindices) { - if (put_user(reg, uindices)) - return -EFAULT; - uindices++; + for (int i = 0; i < n; i++) { + u64 reg = KVM_REG_RISCV | size | + KVM_REG_RISCV_SBI_STATE | + KVM_REG_RISCV_SBI_STA | i; + + if (uindices) { + if (put_user(reg, uindices)) + return -EFAULT; + uindices++; + } } + + total += n; } - return n; + return total; +} + +static inline unsigned long num_sbi_regs(struct kvm_vcpu *vcpu) +{ + return copy_sbi_reg_indices(vcpu, NULL); } static inline unsigned long num_vector_regs(const struct kvm_vcpu *vcpu) diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c index a1997c39dfde..72a2ffb8dcd1 100644 --- a/arch/riscv/kvm/vcpu_sbi.c +++ b/arch/riscv/kvm/vcpu_sbi.c @@ -345,6 +345,8 @@ int kvm_riscv_vcpu_set_reg_sbi(struct kvm_vcpu *vcpu, reg_num &= ~KVM_REG_RISCV_SUBTYPE_MASK; switch (reg_subtype) { + case KVM_REG_RISCV_SBI_STA: + return kvm_riscv_vcpu_set_reg_sbi_sta(vcpu, reg_num, reg_val); default: return -EINVAL; } @@ -370,6 +372,9 @@ int kvm_riscv_vcpu_get_reg_sbi(struct kvm_vcpu *vcpu, reg_num &= ~KVM_REG_RISCV_SUBTYPE_MASK; switch (reg_subtype) { + case KVM_REG_RISCV_SBI_STA: + ret = kvm_riscv_vcpu_get_reg_sbi_sta(vcpu, reg_num, ®_val); + break; default: return -EINVAL; } diff --git a/arch/riscv/kvm/vcpu_sbi_sta.c b/arch/riscv/kvm/vcpu_sbi_sta.c index 6592d287fc4e..87bf1a5f05ce 100644 --- a/arch/riscv/kvm/vcpu_sbi_sta.c +++ b/arch/riscv/kvm/vcpu_sbi_sta.c @@ -3,6 +3,8 @@ * Copyright (c) 2023 Ventana Micro Systems Inc. */ +#include +#include #include #include @@ -59,3 +61,56 @@ const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_sta = { .handler = kvm_sbi_ext_sta_handler, .probe = kvm_sbi_ext_sta_probe, }; + +int kvm_riscv_vcpu_get_reg_sbi_sta(struct kvm_vcpu *vcpu, + unsigned long reg_num, + unsigned long *reg_val) +{ + switch (reg_num) { + case KVM_REG_RISCV_SBI_STA_REG(shmem_lo): + *reg_val = (unsigned long)vcpu->arch.sta.shmem; + break; + case KVM_REG_RISCV_SBI_STA_REG(shmem_hi): + if (IS_ENABLED(CONFIG_32BIT)) + *reg_val = upper_32_bits(vcpu->arch.sta.shmem); + else + *reg_val = 0; + break; + default: + return -EINVAL; + } + + return 0; +} + +int kvm_riscv_vcpu_set_reg_sbi_sta(struct kvm_vcpu *vcpu, + unsigned long reg_num, + unsigned long reg_val) +{ + switch (reg_num) { + case KVM_REG_RISCV_SBI_STA_REG(shmem_lo): + if (IS_ENABLED(CONFIG_32BIT)) { + gpa_t hi = upper_32_bits(vcpu->arch.sta.shmem); + + vcpu->arch.sta.shmem = reg_val; + vcpu->arch.sta.shmem |= hi << 32; + } else { + vcpu->arch.sta.shmem = reg_val; + } + break; + case KVM_REG_RISCV_SBI_STA_REG(shmem_hi): + if (IS_ENABLED(CONFIG_32BIT)) { + gpa_t lo = lower_32_bits(vcpu->arch.sta.shmem); + + vcpu->arch.sta.shmem = ((gpa_t)reg_val << 32); + vcpu->arch.sta.shmem |= lo; + } else if (reg_val != 0) { + return -EINVAL; + } + break; + default: + return -EINVAL; + } + + return 0; +} From patchwork Wed Dec 20 16:00:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13500327 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C9423C46CD3 for ; Wed, 20 Dec 2023 16:01:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2MHIJuMZhgoDpn9p6EBIuG4q1I4oKwz6pYAA5dbz8AQ=; b=n1NUp9SqU6nSxc TNRwCy6kcWuLuHMrOLofH5YTnFR9656ayHktEknJV7DsvHIOqkNKhrRrcwyu1AD5+HBNKodrt0jID 36F127p2E2odCGcJH3yp9QB+XHct5Kf+5v0MzDedFYHgXl5CIHug+oMyq5Bn4lcuYOh/ISOxLWGcs XeFFipYHYagq+P0Dlz5ojH4UXRviAQg3G73Gr7ZhxfTNLgH62oj5voXmOSJ76pW0SwKiSEjjbw8/T pX6kJMXWa/Ms7qeLL/13fyCz3SS072qtJ2hP+PR4h8oADdt/dBwF/oCuwTfF4+TtHsiUpJFdsS6ux 3mGFnGThp8JTpUkBTFTA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rFz0F-000MP6-2M; Wed, 20 Dec 2023 16:00:59 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rFyzz-000M4q-21 for linux-riscv@lists.infradead.org; Wed, 20 Dec 2023 16:00:45 +0000 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-33678156e27so1016180f8f.1 for ; Wed, 20 Dec 2023 08:00:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1703088041; x=1703692841; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gwLdEL3t/SiXrqXkaiuKfwXDHLYhzeq9cY7LIf5M13Y=; b=mKY8iz1N3Sh0YYrFMi8XhC8Ra9ux7UUfLSq/RSxLUVfMns+YFXyhheQ7GYFeagE1VA J8UFpx92UzTVhH99duERwtHw5ygWWVT+t+RsifTIodaIxV0qSSBU1dX+sv2YGv3Iho06 2vl6MbP3gVEY6AhjzPruwReBkPi25N7Endw1scg4IhTOVSJIsIof+UifZ/jR0vlbFKie JIYJr4quiSIs3Yhk3J3mkxGVcQCV8qVgJELHWLcG8+stXEN3unkBzyFsxuKnm9aM57wa sG74KA17jp5K6gUoVwPmDbuEJThMPQwUAadvl91EmT66FjZpf7ECHWWYBIZ2vh5zbv91 r98Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703088041; x=1703692841; 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=gwLdEL3t/SiXrqXkaiuKfwXDHLYhzeq9cY7LIf5M13Y=; b=hDX+AVUQuXcmp9cCpQXZNydSxTfxBHtx+rlJuHWjSYlK6Q4PKx5fP3DflsUYzXfmme +HcW3wKEbWiX7tfsba4aops5EFWb11slbBw6g91Osg8J6GkExoKZrKtYFHoSLhYxTHGa dQ1fc06bvA7N0vHU75IPmcfI90J10yq/lcFwBcQvEEVC35Dw/apQwKxhXqkcN62TQ83H 9jfJLHGdgXVjdCPLsLoESab1bCdOUbqkRGv2VKmrBq/Q2Uuktwza5basGv0uJ0x3Kjjc 9K6XT4Swyf6SUoxx75EE/wEmW8o247h0xjW+B40d17Inkf5PzivGQHLElYDkyAOXt2aT KSuw== X-Gm-Message-State: AOJu0Yy6McK+QTXADxLWl4LMk3qnYJ8AP1wk6AGeT4GD+TzTufYWmMZS DT+dOZF5u7MIVhTtbZXKlQ1flA== X-Google-Smtp-Source: AGHT+IEUW/DiFOKNXsoqmxGaEpp9aDk7k7GiHIRbWZ5wbPtHchhvyTT+72hquJBGViI4njrJlZxthQ== X-Received: by 2002:a5d:5f93:0:b0:336:6602:1b5 with SMTP id dr19-20020a5d5f93000000b00336660201b5mr3785782wrb.133.1703088040796; Wed, 20 Dec 2023 08:00:40 -0800 (PST) Received: from localhost (cst-prg-16-115.cust.vodafone.cz. [46.135.16.115]) by smtp.gmail.com with ESMTPSA id u17-20020a5d5151000000b003365e685102sm12300507wrt.29.2023.12.20.08.00.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 08:00:40 -0800 (PST) From: Andrew Jones To: kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, virtualization@lists.linux-foundation.org Cc: anup@brainfault.org, atishp@atishpatra.org, pbonzini@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, jgross@suse.com, srivatsa@csail.mit.edu, guoren@kernel.org, conor.dooley@microchip.com, Atish Patra Subject: [PATCH v4 09/13] RISC-V: KVM: Implement SBI STA extension Date: Wed, 20 Dec 2023 17:00:22 +0100 Message-ID: <20231220160012.40184-24-ajones@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220160012.40184-15-ajones@ventanamicro.com> References: <20231220160012.40184-15-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231220_080043_671324_6F58EAB2 X-CRM114-Status: GOOD ( 17.75 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add a select SCHED_INFO to the KVM config in order to get run_delay info. Then implement SBI STA's set-steal-time-shmem function and kvm_riscv_vcpu_record_steal_time() to provide the steal-time info to guests. Reviewed-by: Anup Patel Reviewed-by: Atish Patra Signed-off-by: Andrew Jones --- arch/riscv/kvm/Kconfig | 1 + arch/riscv/kvm/vcpu_sbi_sta.c | 96 ++++++++++++++++++++++++++++++++++- 2 files changed, 95 insertions(+), 2 deletions(-) diff --git a/arch/riscv/kvm/Kconfig b/arch/riscv/kvm/Kconfig index dfc237d7875b..148e52b516cf 100644 --- a/arch/riscv/kvm/Kconfig +++ b/arch/riscv/kvm/Kconfig @@ -32,6 +32,7 @@ config KVM select KVM_XFER_TO_GUEST_WORK select MMU_NOTIFIER select PREEMPT_NOTIFIERS + select SCHED_INFO help Support hosting virtualized guest machines. diff --git a/arch/riscv/kvm/vcpu_sbi_sta.c b/arch/riscv/kvm/vcpu_sbi_sta.c index 87bf1a5f05ce..01f09fe8c3b0 100644 --- a/arch/riscv/kvm/vcpu_sbi_sta.c +++ b/arch/riscv/kvm/vcpu_sbi_sta.c @@ -6,9 +6,15 @@ #include #include #include +#include +#include +#include +#include #include +#include #include +#include void kvm_riscv_vcpu_sbi_sta_reset(struct kvm_vcpu *vcpu) { @@ -19,14 +25,100 @@ void kvm_riscv_vcpu_sbi_sta_reset(struct kvm_vcpu *vcpu) void kvm_riscv_vcpu_record_steal_time(struct kvm_vcpu *vcpu) { gpa_t shmem = vcpu->arch.sta.shmem; + u64 last_steal = vcpu->arch.sta.last_steal; + u32 *sequence_ptr, sequence; + u64 *steal_ptr, steal; + unsigned long hva; + gfn_t gfn; if (shmem == INVALID_GPA) return; + + /* + * shmem is 64-byte aligned (see the enforcement in + * kvm_sbi_sta_steal_time_set_shmem()) and the size of sbi_sta_struct + * is 64 bytes, so we know all its offsets are in the same page. + */ + gfn = shmem >> PAGE_SHIFT; + hva = kvm_vcpu_gfn_to_hva(vcpu, gfn); + + if (WARN_ON(kvm_is_error_hva(hva))) { + vcpu->arch.sta.shmem = INVALID_GPA; + return; + } + + sequence_ptr = (u32 *)(hva + offset_in_page(shmem) + + offsetof(struct sbi_sta_struct, sequence)); + steal_ptr = (u64 *)(hva + offset_in_page(shmem) + + offsetof(struct sbi_sta_struct, steal)); + + if (WARN_ON(get_user(sequence, sequence_ptr))) + return; + + sequence = le32_to_cpu(sequence); + sequence += 1; + + if (WARN_ON(put_user(cpu_to_le32(sequence), sequence_ptr))) + return; + + if (!WARN_ON(get_user(steal, steal_ptr))) { + steal = le64_to_cpu(steal); + vcpu->arch.sta.last_steal = READ_ONCE(current->sched_info.run_delay); + steal += vcpu->arch.sta.last_steal - last_steal; + WARN_ON(put_user(cpu_to_le64(steal), steal_ptr)); + } + + sequence += 1; + WARN_ON(put_user(cpu_to_le32(sequence), sequence_ptr)); + + kvm_vcpu_mark_page_dirty(vcpu, gfn); } static int kvm_sbi_sta_steal_time_set_shmem(struct kvm_vcpu *vcpu) { - return SBI_ERR_FAILURE; + struct kvm_cpu_context *cp = &vcpu->arch.guest_context; + unsigned long shmem_phys_lo = cp->a0; + unsigned long shmem_phys_hi = cp->a1; + u32 flags = cp->a2; + struct sbi_sta_struct zero_sta = {0}; + unsigned long hva; + bool writable; + gpa_t shmem; + int ret; + + if (flags != 0) + return SBI_ERR_INVALID_PARAM; + + if (shmem_phys_lo == SBI_STA_SHMEM_DISABLE && + shmem_phys_hi == SBI_STA_SHMEM_DISABLE) { + vcpu->arch.sta.shmem = INVALID_GPA; + return 0; + } + + if (shmem_phys_lo & (SZ_64 - 1)) + return SBI_ERR_INVALID_PARAM; + + shmem = shmem_phys_lo; + + if (shmem_phys_hi != 0) { + if (IS_ENABLED(CONFIG_32BIT)) + shmem |= ((gpa_t)shmem_phys_hi << 32); + else + return SBI_ERR_INVALID_ADDRESS; + } + + hva = kvm_vcpu_gfn_to_hva_prot(vcpu, shmem >> PAGE_SHIFT, &writable); + if (kvm_is_error_hva(hva) || !writable) + return SBI_ERR_INVALID_ADDRESS; + + ret = kvm_vcpu_write_guest(vcpu, shmem, &zero_sta, sizeof(zero_sta)); + if (ret) + return SBI_ERR_FAILURE; + + vcpu->arch.sta.shmem = shmem; + vcpu->arch.sta.last_steal = current->sched_info.run_delay; + + return 0; } static int kvm_sbi_ext_sta_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, @@ -52,7 +144,7 @@ static int kvm_sbi_ext_sta_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, static unsigned long kvm_sbi_ext_sta_probe(struct kvm_vcpu *vcpu) { - return 0; + return !!sched_info_on(); } const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_sta = { From patchwork Wed Dec 20 16:00:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13500328 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 92ADDC3DA6E for ; Wed, 20 Dec 2023 16:01:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Eg1ynbqSV3At8cjCW0P90V/Zg26/nVnN3H0wzYV1j4M=; b=Wrx68qIpZ6zs/8 REOmzA+wjqGHx4gPiqQqRzwc9sFsIF3xb4QsEgld6xknDTY4ybLe36IB9kCQ7w0YkIrsGtVh0f9HB WBcwFPG5AkQs7jW4y/vnX0TIzF/A3QADdjbCl96tStKDSat5MHeyVSXAwS8tnwDIs583iAS2VNWnx UBJfe6m3T2xuXoLy4XG0lpfRPhjjzE1Q93HaroF5P73VDyjG2kPFPZEemTJgUqYkrs5vdhRTB/221 rsD1haoZAZXhZ5vW6wP1AnFijYjYr0aiuxIzdnyNAoIZor1ONPBEipF5tx/T9ptfR7KbM+7ftujYm 3Q+m7ssKNPY+jkjnsuDQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rFz0H-000MRQ-1v; Wed, 20 Dec 2023 16:01:03 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rFz03-000M89-2m for linux-riscv@lists.infradead.org; Wed, 20 Dec 2023 16:00:50 +0000 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-33680da01d6so196975f8f.2 for ; Wed, 20 Dec 2023 08:00:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1703088044; x=1703692844; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SOMbKPx9f+JcS4fNjPCKfauG48/CPKUV3NQDAwTQdeE=; b=i5J1dCKN3ndFlL2BmWg/cLLwpz7nhtDWcznYn6wXEC6UlAC3h1fKDg+FD/Pzg5TLLI Mg5/Fr+b9w2Wn4KkrFXiRy9OyY0DgGWYWXcGI4OykT+UTMhWiSimtf98jkbY0I5iqsBP ZsCJHZ1Tuw+4/DHUdgKljcEhFQpHTD8xBhc5O6wgbtThe0dk8NGgJ2Geb11ZYgpRmRyf etzwx56YIT7TZD+yssRg2xnvkASUq7blxs4TDnpLQatbJ1k2cx/j2bBikYKRT4gYLfif y1T6tCGC29rVD4qEJIjp+Ef9rlhrRguDw9p7unV1TpRcJZp0usubKpqHGwJ0gVaioEFD KvxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703088044; x=1703692844; 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=SOMbKPx9f+JcS4fNjPCKfauG48/CPKUV3NQDAwTQdeE=; b=nC6yoRssm+euB5V3puribuULVbBrMU9dt4qmm6pL6KM0MByKrlcjyUo3ldcHFB+NIP Lidq9OeO/I4vmfUaXBApUY2absrHBGtOXO5wSAKIA1oE38TBMcffo6sBdJ9DeEYnajc4 lAqOP7qb3FekV6yDKBet7Yh45AQ1OJPVsuwer5LveksFNYOsq4+BCuRIrEnyLcXe5AjT Qh5hbXtFbe+msLQH+MzqPXgLGubFvw122et2kSkJhaNvcq5HamwmkX2e5lbMRzjp1lnD t2iZytgs2sb0zrxj8zplgzgne0rajGLlKuGteMGyd4meCGrkZHkjfWn4Pr7mmVgzhOK1 6Srw== X-Gm-Message-State: AOJu0YzYZmZpO983IEz00uqnjXK30e4LPCIXK6KMBSfWzvhTLUq+ZoyU iefSkopJbB0rQ9PVm1yADgLBuKifvGwTamMYJQY= X-Google-Smtp-Source: AGHT+IHAymYvsc8zEqN1v3qElq0WfVx384eiJmTqDAz6MBPOM6JEK5f4WJQK6gTsluRbahFbSGEd9A== X-Received: by 2002:a5d:6691:0:b0:336:7659:c2c2 with SMTP id l17-20020a5d6691000000b003367659c2c2mr1430322wru.21.1703088043894; Wed, 20 Dec 2023 08:00:43 -0800 (PST) Received: from localhost (cst-prg-16-115.cust.vodafone.cz. [46.135.16.115]) by smtp.gmail.com with ESMTPSA id s8-20020a5d5108000000b003366fb71297sm5272750wrt.81.2023.12.20.08.00.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 08:00:43 -0800 (PST) From: Andrew Jones To: kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, virtualization@lists.linux-foundation.org Cc: anup@brainfault.org, atishp@atishpatra.org, pbonzini@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, jgross@suse.com, srivatsa@csail.mit.edu, guoren@kernel.org, conor.dooley@microchip.com Subject: [PATCH v4 10/13] RISC-V: KVM: selftests: Move sbi_ecall to processor.c Date: Wed, 20 Dec 2023 17:00:23 +0100 Message-ID: <20231220160012.40184-25-ajones@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220160012.40184-15-ajones@ventanamicro.com> References: <20231220160012.40184-15-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231220_080047_934279_B91C331B X-CRM114-Status: UNSURE ( 9.20 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org sbi_ecall() isn't ucall specific and its prototype is already in processor.h. Move its implementation to processor.c. Reviewed-by: Anup Patel Signed-off-by: Andrew Jones --- .../selftests/kvm/lib/riscv/processor.c | 26 +++++++++++++++++++ tools/testing/selftests/kvm/lib/riscv/ucall.c | 26 ------------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/riscv/processor.c b/tools/testing/selftests/kvm/lib/riscv/processor.c index 6c25f7843ef4..6905a4348380 100644 --- a/tools/testing/selftests/kvm/lib/riscv/processor.c +++ b/tools/testing/selftests/kvm/lib/riscv/processor.c @@ -367,3 +367,29 @@ void vcpu_args_set(struct kvm_vcpu *vcpu, unsigned int num, ...) void assert_on_unhandled_exception(struct kvm_vcpu *vcpu) { } + +struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, + unsigned long arg1, unsigned long arg2, + unsigned long arg3, unsigned long arg4, + unsigned long arg5) +{ + register uintptr_t a0 asm ("a0") = (uintptr_t)(arg0); + register uintptr_t a1 asm ("a1") = (uintptr_t)(arg1); + register uintptr_t a2 asm ("a2") = (uintptr_t)(arg2); + register uintptr_t a3 asm ("a3") = (uintptr_t)(arg3); + register uintptr_t a4 asm ("a4") = (uintptr_t)(arg4); + register uintptr_t a5 asm ("a5") = (uintptr_t)(arg5); + register uintptr_t a6 asm ("a6") = (uintptr_t)(fid); + register uintptr_t a7 asm ("a7") = (uintptr_t)(ext); + struct sbiret ret; + + asm volatile ( + "ecall" + : "+r" (a0), "+r" (a1) + : "r" (a2), "r" (a3), "r" (a4), "r" (a5), "r" (a6), "r" (a7) + : "memory"); + ret.error = a0; + ret.value = a1; + + return ret; +} diff --git a/tools/testing/selftests/kvm/lib/riscv/ucall.c b/tools/testing/selftests/kvm/lib/riscv/ucall.c index fe6d1004f018..14ee17151a59 100644 --- a/tools/testing/selftests/kvm/lib/riscv/ucall.c +++ b/tools/testing/selftests/kvm/lib/riscv/ucall.c @@ -10,32 +10,6 @@ #include "kvm_util.h" #include "processor.h" -struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, - unsigned long arg1, unsigned long arg2, - unsigned long arg3, unsigned long arg4, - unsigned long arg5) -{ - register uintptr_t a0 asm ("a0") = (uintptr_t)(arg0); - register uintptr_t a1 asm ("a1") = (uintptr_t)(arg1); - register uintptr_t a2 asm ("a2") = (uintptr_t)(arg2); - register uintptr_t a3 asm ("a3") = (uintptr_t)(arg3); - register uintptr_t a4 asm ("a4") = (uintptr_t)(arg4); - register uintptr_t a5 asm ("a5") = (uintptr_t)(arg5); - register uintptr_t a6 asm ("a6") = (uintptr_t)(fid); - register uintptr_t a7 asm ("a7") = (uintptr_t)(ext); - struct sbiret ret; - - asm volatile ( - "ecall" - : "+r" (a0), "+r" (a1) - : "r" (a2), "r" (a3), "r" (a4), "r" (a5), "r" (a6), "r" (a7) - : "memory"); - ret.error = a0; - ret.value = a1; - - return ret; -} - void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu) { struct kvm_run *run = vcpu->run; From patchwork Wed Dec 20 16:00:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13500329 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 33E1DC46CD8 for ; Wed, 20 Dec 2023 16:01:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=KhAhVqV8K6rWhJhDhHQHWb9cYT3/yIcTlEOHrdf0stQ=; b=k9qRCBxUFN5JbS ZOyjuyDpYMNhQaGpuPEDbdd0jmdwnUBQCEp/pHRYefU7ZxUnNHe3LG45e+G32VhnvFWxXVHCZtW5P DLSl9m/knH2LGd1LrpDNQMdDiTcrJX0dtuWNi9B339polUokIpCfi5MW8Z+7kJuHCBb0bouLeJrJY NmghJA1hE169cafzEALPc+oOA733mfNnnKstTn0UgyThiiw2pium/7uymYvba8oEJfK38JBSCswaO mtvXsSWrLrikcUN3YH1JsrVNLBTthEyQ/ei9Y8NmhfnGv5vvTDmmboojQPfbGCN4xirzAmi/Ql+qb sfKZvbwcoer8Ed3RCNFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rFz0K-000MTx-1r; Wed, 20 Dec 2023 16:01:04 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rFz03-000MBI-2n for linux-riscv@lists.infradead.org; Wed, 20 Dec 2023 16:00:50 +0000 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-336746a545fso589896f8f.0 for ; Wed, 20 Dec 2023 08:00:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1703088046; x=1703692846; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=62TTtkxd00oH+oWvK2W/ODaQKWhDhsp3HCJ4KK5vX24=; b=ZY8xoQQg5leI4FIHNLvA8699CujfuWq2PZzcUkZyQw31ynreI6dxtJeoGlUMHLpGo5 ReXTnmx86UBdHg2CGC/c7q03ebIuS3FdhNvWTm+0FVnlatsygwz25JvLdeOaqy1s80jW 91M2GqTOHrs/zTSpRuzoqmdxAG0MYkW1iPeMmMzkFF3oQkDnHyx69Mv/HSDpCexArAFF h1XtkwYqjScvatG1JLmnz9NEu6Lj7IWoe4LBlRti3Qce4IoPMLYE2jFDZ9/p7/rlQ/g2 IX9G4EVxT6bZJslgzobNV+IWYHSCPPzCzK3W9Zi71vijWnhJ5XxqsRDhhqM1v6yRSMa2 xYKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703088046; x=1703692846; 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=62TTtkxd00oH+oWvK2W/ODaQKWhDhsp3HCJ4KK5vX24=; b=EbR5dFU4mnhsriMHb0RcjR8iD0bCWA+8pQ5NI3qKlOlnZmtmbKDRmPp1/Bsxbauyyi HR1y4bgptxghC6/geI34LHUfjVVtD4isf7MlYhHR/8lWTHdo0HT/KXSPwFrCdsHYKeBr 4Efqpjbib8bIY3QW2Ww7WPdPBGR/mcbE4b6W59jFNiOIJcVCjMrpZyoNCUEXazHVGsaQ Tarx0yQvuc0ov8hC4FLaAf/JZhfXFY0TxDutv0cW/Rbvz/dGnFlITLPYSA6k/jnEAtuE FE6x9BqlD/PkQqz1Q+9ovcnkNuRdGtQEmj2XEA3788b5RNZucG+VR4qvd2rogU2YLnhp 0QCg== X-Gm-Message-State: AOJu0YyzLPWKdLbalXP/LCH4pdWKbkBGg/8hZIiaJtm8FWzu3MAJ2uiE q3i6O5QysEqxakY5y7cPUDfNfPSeHAktfw== X-Google-Smtp-Source: AGHT+IEEMYELu7/A+1G49HQKJD0DCWws+PGCbWuHkMwSf1zShbkZAUEp29RUgz8Y81u0XEfxyO2+Uw== X-Received: by 2002:adf:ec04:0:b0:336:7bd0:479e with SMTP id x4-20020adfec04000000b003367bd0479emr589222wrn.26.1703088046506; Wed, 20 Dec 2023 08:00:46 -0800 (PST) Received: from localhost (cst-prg-16-115.cust.vodafone.cz. [46.135.16.115]) by smtp.gmail.com with ESMTPSA id k17-20020adff291000000b003367bb8898dsm1789906wro.66.2023.12.20.08.00.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 08:00:46 -0800 (PST) From: Andrew Jones To: kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, virtualization@lists.linux-foundation.org Cc: anup@brainfault.org, atishp@atishpatra.org, pbonzini@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, jgross@suse.com, srivatsa@csail.mit.edu, guoren@kernel.org, conor.dooley@microchip.com, Atish Patra Subject: [PATCH v4 11/13] RISC-V: KVM: selftests: Add guest_sbi_probe_extension Date: Wed, 20 Dec 2023 17:00:24 +0100 Message-ID: <20231220160012.40184-26-ajones@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220160012.40184-15-ajones@ventanamicro.com> References: <20231220160012.40184-15-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231220_080047_967138_112EC8E4 X-CRM114-Status: UNSURE ( 9.22 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add guest_sbi_probe_extension(), allowing guest code to probe for SBI extensions. As guest_sbi_probe_extension() needs SBI_ERR_NOT_SUPPORTED, take the opportunity to bring in all SBI error codes. We don't bring in all current extension IDs or base extension function IDs though, even though we need one of each, because we'd prefer to bring those in as necessary. Reviewed-by: Anup Patel Reviewed-by: Atish Patra Signed-off-by: Andrew Jones --- .../selftests/kvm/include/riscv/processor.h | 21 +++++++++++++++++++ .../selftests/kvm/lib/riscv/processor.c | 19 +++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/tools/testing/selftests/kvm/include/riscv/processor.h b/tools/testing/selftests/kvm/include/riscv/processor.h index e70ccda2011b..dc50ad62e150 100644 --- a/tools/testing/selftests/kvm/include/riscv/processor.h +++ b/tools/testing/selftests/kvm/include/riscv/processor.h @@ -108,6 +108,17 @@ static inline uint64_t __kvm_reg_id(uint64_t type, uint64_t subtype, #define SATP_ASID_SHIFT 44 #define SATP_ASID_MASK _AC(0xFFFF, UL) +/* SBI return error codes */ +#define SBI_SUCCESS 0 +#define SBI_ERR_FAILURE -1 +#define SBI_ERR_NOT_SUPPORTED -2 +#define SBI_ERR_INVALID_PARAM -3 +#define SBI_ERR_DENIED -4 +#define SBI_ERR_INVALID_ADDRESS -5 +#define SBI_ERR_ALREADY_AVAILABLE -6 +#define SBI_ERR_ALREADY_STARTED -7 +#define SBI_ERR_ALREADY_STOPPED -8 + #define SBI_EXT_EXPERIMENTAL_START 0x08000000 #define SBI_EXT_EXPERIMENTAL_END 0x08FFFFFF @@ -115,6 +126,14 @@ static inline uint64_t __kvm_reg_id(uint64_t type, uint64_t subtype, #define KVM_RISCV_SELFTESTS_SBI_UCALL 0 #define KVM_RISCV_SELFTESTS_SBI_UNEXP 1 +enum sbi_ext_id { + SBI_EXT_BASE = 0x10, +}; + +enum sbi_ext_base_fid { + SBI_EXT_BASE_PROBE_EXT = 3, +}; + struct sbiret { long error; long value; @@ -125,4 +144,6 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, unsigned long arg3, unsigned long arg4, unsigned long arg5); +bool guest_sbi_probe_extension(int extid, long *out_val); + #endif /* SELFTEST_KVM_PROCESSOR_H */ diff --git a/tools/testing/selftests/kvm/lib/riscv/processor.c b/tools/testing/selftests/kvm/lib/riscv/processor.c index 6905a4348380..7ca736fb4194 100644 --- a/tools/testing/selftests/kvm/lib/riscv/processor.c +++ b/tools/testing/selftests/kvm/lib/riscv/processor.c @@ -393,3 +393,22 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, return ret; } + +bool guest_sbi_probe_extension(int extid, long *out_val) +{ + struct sbiret ret; + + ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_PROBE_EXT, extid, + 0, 0, 0, 0, 0); + + __GUEST_ASSERT(!ret.error || ret.error == SBI_ERR_NOT_SUPPORTED, + "ret.error=%ld, ret.value=%ld\n", ret.error, ret.value); + + if (ret.error == SBI_ERR_NOT_SUPPORTED) + return false; + + if (out_val) + *out_val = ret.value; + + return true; +} From patchwork Wed Dec 20 16:00:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13500330 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4655AC46CD3 for ; Wed, 20 Dec 2023 16:01:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1HsA7bRgFVvCkC5N1PtN8cDolDeNgBCQxoN8OHLFtls=; b=RU/fVLNNb2cpMC HugAWBFqx3BOSolwNxGEHAsJA8xyB6+s5yrgweSNvkhOIs24D+r8JUWXGT5FWFSyzScyTllf7axa6 S5ELUrcVqT6m+nfb/m1y0QP+U+ymUqYoBjUvHbQvsferZT4XNjrYPjPofiEZAytfUq9C5zOVoD9Sx 6anstAHq/5/69CRsC4L2QtEliO1lqE7hj5/iMw6jk82QkMFCT/x0U8nJQEKS+jK3RcHvmjU2tZhkm 8ePC4BY4C9DMIMHBoITVTYUYaTMTzsQjvw/wmud6t1SEifytzcJOwe9wQAYnCz5xD9LlgCJntzUQF hivBcxxkusVP16bhZn1A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rFz0L-000MUo-0n; Wed, 20 Dec 2023 16:01:05 +0000 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rFz07-000MEs-0r for linux-riscv@lists.infradead.org; Wed, 20 Dec 2023 16:00:54 +0000 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-33664b6d6abso3545177f8f.2 for ; Wed, 20 Dec 2023 08:00:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1703088050; x=1703692850; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dfFfKWtvrkmT221HR8Q1VQaH3JsKQHJKfN6wXUEYG9g=; b=esSPJL2v6nmWwtUSl6/HurKil+0oIfJQRg0nax6QYajIWiP4B3Dw/Hivw7fBE1tCW1 4GNjrhnxk/UEI56T8jVlLb0ad5yu4+jiYg9LU3tm3d7/GVF136gKdbiJt9NqrBUvGAKe b56Lf7rXHF52brlYbHDJViCB1/ZFV51cB0RXsChAB/R3CbduFZ9WV7DSEocYzVS0Nzom +6mvpqsh7SXL0fR+ywgAQO78KmndkD9AjVqSPIRCC81/8kGbhptqr4FJT7InzIE5uMKh BZvGEhnA2yhe9wk3Ie9NC6LE01uMliO2uYFzLDFI/hBehgWrdikXKoEncbBfafck3BPi 149w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703088050; x=1703692850; 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=dfFfKWtvrkmT221HR8Q1VQaH3JsKQHJKfN6wXUEYG9g=; b=EQLPEN4iRWoGQJD+mtof1hzMXGNQ+AZ2WAp+Y9dYpjPSSxWdZapiGfLmB2d3WzaIrh ZUxoYoajpKKjNuN07zC1xr3vXJi31Lzb/kFrw3OZQk4mufdZ2sZ4Mh0C+W2/EpND0Fxm I084Wj7njX8GUZh+343WK1P0F4u/QssKjMDc4jSBWNaEMElxnYk/P10UCE9aGl/zZExz j7z89zwZUE2LBmNNqkEI1LgQX/vQCDq0nckpu6uUr/JijV8lDzFA9nLMlIs20FK3oDpn YjNH+tvhgUQWdEjcdFrVl0e11xFTWT87beqPNZYOnv8t6GA6NiTt5ZJHYv/OXgTkuvnx A5Eg== X-Gm-Message-State: AOJu0YzI/3g8YCiYT2FVkYsckQ6PDS9GodTHeNfDlNPhNXoB1CUuJZ1r gC/xOBE9G8V22Z+OYEZut2uuZA== X-Google-Smtp-Source: AGHT+IFy7hQsVy6wi/dJPns4yQ8X3HqUXJ+wUSSQic4Yuf6fqtPe4NMhMJQy4J8MUdxydm1j127xlg== X-Received: by 2002:a05:6000:400a:b0:336:6956:b848 with SMTP id cp10-20020a056000400a00b003366956b848mr3022937wrb.134.1703088049887; Wed, 20 Dec 2023 08:00:49 -0800 (PST) Received: from localhost (cst-prg-16-115.cust.vodafone.cz. [46.135.16.115]) by smtp.gmail.com with ESMTPSA id t18-20020adfa2d2000000b003364aa5cc13sm2977693wra.1.2023.12.20.08.00.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 08:00:49 -0800 (PST) From: Andrew Jones To: kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, virtualization@lists.linux-foundation.org Cc: anup@brainfault.org, atishp@atishpatra.org, pbonzini@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, jgross@suse.com, srivatsa@csail.mit.edu, guoren@kernel.org, conor.dooley@microchip.com, Atish Patra Subject: [PATCH v4 12/13] RISC-V: KVM: selftests: Add steal_time test support Date: Wed, 20 Dec 2023 17:00:25 +0100 Message-ID: <20231220160012.40184-27-ajones@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220160012.40184-15-ajones@ventanamicro.com> References: <20231220160012.40184-15-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231220_080051_332099_0AD07532 X-CRM114-Status: GOOD ( 13.60 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org With the introduction of steal-time accounting support for RISC-V KVM we can add RISC-V support to the steal_time test. Reviewed-by: Anup Patel Reviewed-by: Atish Patra Signed-off-by: Andrew Jones --- tools/testing/selftests/kvm/Makefile | 5 +- .../selftests/kvm/include/riscv/processor.h | 1 + tools/testing/selftests/kvm/steal_time.c | 99 +++++++++++++++++++ 3 files changed, 103 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index 963435959a92..4bf4f52341a8 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -194,12 +194,13 @@ TEST_GEN_PROGS_s390x += kvm_binary_stats_test TEST_GEN_PROGS_riscv += demand_paging_test TEST_GEN_PROGS_riscv += dirty_log_test -TEST_GEN_PROGS_riscv += guest_print_test TEST_GEN_PROGS_riscv += get-reg-list +TEST_GEN_PROGS_riscv += guest_print_test +TEST_GEN_PROGS_riscv += kvm_binary_stats_test TEST_GEN_PROGS_riscv += kvm_create_max_vcpus TEST_GEN_PROGS_riscv += kvm_page_table_test TEST_GEN_PROGS_riscv += set_memory_region_test -TEST_GEN_PROGS_riscv += kvm_binary_stats_test +TEST_GEN_PROGS_riscv += steal_time SPLIT_TESTS += get-reg-list diff --git a/tools/testing/selftests/kvm/include/riscv/processor.h b/tools/testing/selftests/kvm/include/riscv/processor.h index dc50ad62e150..a0f9efe5a2a8 100644 --- a/tools/testing/selftests/kvm/include/riscv/processor.h +++ b/tools/testing/selftests/kvm/include/riscv/processor.h @@ -128,6 +128,7 @@ static inline uint64_t __kvm_reg_id(uint64_t type, uint64_t subtype, enum sbi_ext_id { SBI_EXT_BASE = 0x10, + SBI_EXT_STA = 0x535441, }; enum sbi_ext_base_fid { diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c index 171adfb2a6cb..bae0c5026f82 100644 --- a/tools/testing/selftests/kvm/steal_time.c +++ b/tools/testing/selftests/kvm/steal_time.c @@ -11,7 +11,9 @@ #include #include #include +#ifndef __riscv #include +#endif #include "test_util.h" #include "kvm_util.h" @@ -203,6 +205,103 @@ static void steal_time_dump(struct kvm_vm *vm, uint32_t vcpu_idx) pr_info(" st_time: %ld\n", st->st_time); } +#elif defined(__riscv) + +/* SBI STA shmem must have 64-byte alignment */ +#define STEAL_TIME_SIZE ((sizeof(struct sta_struct) + 63) & ~63) + +static vm_paddr_t st_gpa[NR_VCPUS]; + +struct sta_struct { + uint32_t sequence; + uint32_t flags; + uint64_t steal; + uint8_t preempted; + uint8_t pad[47]; +} __packed; + +static void sta_set_shmem(vm_paddr_t gpa, unsigned long flags) +{ + unsigned long lo = (unsigned long)gpa; +#if __riscv_xlen == 32 + unsigned long hi = (unsigned long)(gpa >> 32); +#else + unsigned long hi = gpa == -1 ? -1 : 0; +#endif + struct sbiret ret = sbi_ecall(SBI_EXT_STA, 0, lo, hi, flags, 0, 0, 0); + + GUEST_ASSERT(ret.value == 0 && ret.error == 0); +} + +static void check_status(struct sta_struct *st) +{ + GUEST_ASSERT(!(READ_ONCE(st->sequence) & 1)); + GUEST_ASSERT(READ_ONCE(st->flags) == 0); + GUEST_ASSERT(READ_ONCE(st->preempted) == 0); +} + +static void guest_code(int cpu) +{ + struct sta_struct *st = st_gva[cpu]; + uint32_t sequence; + long out_val = 0; + bool probe; + + probe = guest_sbi_probe_extension(SBI_EXT_STA, &out_val); + GUEST_ASSERT(probe && out_val == 1); + + sta_set_shmem(st_gpa[cpu], 0); + GUEST_SYNC(0); + + check_status(st); + WRITE_ONCE(guest_stolen_time[cpu], st->steal); + sequence = READ_ONCE(st->sequence); + check_status(st); + GUEST_SYNC(1); + + check_status(st); + GUEST_ASSERT(sequence < READ_ONCE(st->sequence)); + WRITE_ONCE(guest_stolen_time[cpu], st->steal); + check_status(st); + GUEST_DONE(); +} + +static bool is_steal_time_supported(struct kvm_vcpu *vcpu) +{ + uint64_t id = RISCV_SBI_EXT_REG(KVM_RISCV_SBI_EXT_STA); + unsigned long enabled; + + vcpu_get_reg(vcpu, id, &enabled); + TEST_ASSERT(enabled == 0 || enabled == 1, "Expected boolean result"); + + return enabled; +} + +static void steal_time_init(struct kvm_vcpu *vcpu, uint32_t i) +{ + /* ST_GPA_BASE is identity mapped */ + st_gva[i] = (void *)(ST_GPA_BASE + i * STEAL_TIME_SIZE); + st_gpa[i] = addr_gva2gpa(vcpu->vm, (vm_vaddr_t)st_gva[i]); + sync_global_to_guest(vcpu->vm, st_gva[i]); + sync_global_to_guest(vcpu->vm, st_gpa[i]); +} + +static void steal_time_dump(struct kvm_vm *vm, uint32_t vcpu_idx) +{ + struct sta_struct *st = addr_gva2hva(vm, (ulong)st_gva[vcpu_idx]); + int i; + + pr_info("VCPU%d:\n", vcpu_idx); + pr_info(" sequence: %d\n", st->sequence); + pr_info(" flags: %d\n", st->flags); + pr_info(" steal: %"PRIu64"\n", st->steal); + pr_info(" preempted: %d\n", st->preempted); + pr_info(" pad: "); + for (i = 0; i < 47; ++i) + pr_info("%d", st->pad[i]); + pr_info("\n"); +} + #endif static void *do_steal_time(void *arg) From patchwork Wed Dec 20 16:00:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13500331 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2C6F8C3DA6E for ; Wed, 20 Dec 2023 16:01:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TdOegERUv7H0qiUSH4abA2Ywgp8uOeSk4W6OwZ759pU=; b=ecx/rIjlGmxIiy WSOQ0Sf4EohOX1raAJ4O3pcaT9a7YYzhGGsypgr82HcL6EVxzHtZw3uxfu1Sy0uuSkPRahfOTLCXY TtYTTnGbClyAonFdNAKZ/01z2HUmdab6CfS3gZaMwHAwqn0oNEjHuyg6SGP0pgXMNBeEb1xpsfMlp 4VRzBNVXH8J2pqycRVpCHyNSxKgg/etNGQn1+LXIhkVHYErKU7FoZqP5YYwxljikE65idK2cjrukA fYi1mLZz0cPAK1hkhMSB0JJEYVHIKUcDDc5zIvHIWcCOgb4XZkmTsX4gDQ56JldoCpQVE9JsOwgSY Mum3cs5ouSo85my77Lhg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rFz0N-000MXR-0b; Wed, 20 Dec 2023 16:01:07 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rFz0A-000MHq-1e for linux-riscv@lists.infradead.org; Wed, 20 Dec 2023 16:00:57 +0000 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-336746a545fso589989f8f.0 for ; Wed, 20 Dec 2023 08:00:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1703088053; x=1703692853; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9MIeG//CYqgQU1t4MUGLxBCDTtfcBv4CzngYE6hts0o=; b=ZIWalTSPWGD4DJgb60ofmD62OEwfBwzIxm64xUEkSnip35C4Dt9ukm4bHVARMTchQ8 40HCpL/aMnb3kHsu3bn80ZZENotIZHJUkrSdUD4Eb3X/GSmp0V4q847RWrvDb9CCKE6i tZRqzaBgIrwSB+io3+3XdpIF2NL2mLfKZEpyyk/zcUaDNNnc1MNuGh4UMXnSMm8y7Qol 6h6O8pqJG0RyQtd4hMHvkoEoB5Keo5HBP7bsbL3rloYIKS5TvSdlv9eE6yEY1kFEdNfC XmaiPvLNyL6PcJQ46TlAFIkPDxOIvTtO14L23lqNr1ackHyv66/qOeOkVj8tVlMz+cE8 mxsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703088053; x=1703692853; 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=9MIeG//CYqgQU1t4MUGLxBCDTtfcBv4CzngYE6hts0o=; b=av6trCvs1k5PJ7yJX+ggBrBSEAffNZM46kK/gkByIrNUndXqlmUsd77FuPCXup7hRh okMOqpxDVMcITCK/MtEJWQtHFO1Z8SqOlbc4vktOtAjB5Ru8AiRq2gTEfVISbWkMIqXF YqUOo0LXVuea9p37eb+NpW9bjCuoQsRInNh39oIe9su5EsKieri1Y8hicpGd1bgGvN4z Vtk85hwIh5FpJMadRwbnDVUSzjbEr+6IahNaOFWbKwzXYxLSnBckEX6wFZi0GKGsXytF jyFucgi2e3MxtkQ95ogP1CxJ8w++UKwq4uOyKY1c7UvRnJKVhKa1eXF47myIxFHcqoMo O9KQ== X-Gm-Message-State: AOJu0YxhFQ3RBoLG3DvsaNJQqy6WyFpdXrRTGtXyyHvQ9TozSkOpS/FI 8vBl/JYxlGidXhcSAcwl/Z1xZw== X-Google-Smtp-Source: AGHT+IFqWQdYTmWfiHtgaVs9TEWkO52iriQdpaOOyzN/Hx9SJcnJo/k/ijqG6DhlnoIGa8of3niFzA== X-Received: by 2002:adf:ee0c:0:b0:336:7686:d5e2 with SMTP id y12-20020adfee0c000000b003367686d5e2mr1265268wrn.53.1703088052920; Wed, 20 Dec 2023 08:00:52 -0800 (PST) Received: from localhost (cst-prg-16-115.cust.vodafone.cz. [46.135.16.115]) by smtp.gmail.com with ESMTPSA id j11-20020a5d564b000000b0033664ffaf5dsm9777896wrw.37.2023.12.20.08.00.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 08:00:52 -0800 (PST) From: Andrew Jones To: kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, virtualization@lists.linux-foundation.org Cc: anup@brainfault.org, atishp@atishpatra.org, pbonzini@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, jgross@suse.com, srivatsa@csail.mit.edu, guoren@kernel.org, conor.dooley@microchip.com, Atish Patra Subject: [PATCH v4 13/13] RISC-V: KVM: selftests: Add get-reg-list test for STA registers Date: Wed, 20 Dec 2023 17:00:26 +0100 Message-ID: <20231220160012.40184-28-ajones@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220160012.40184-15-ajones@ventanamicro.com> References: <20231220160012.40184-15-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231220_080054_608856_AE2D94E7 X-CRM114-Status: GOOD ( 10.22 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add SBI STA and its two registers to the get-reg-list test. Reviewed-by: Anup Patel Reviewed-by: Atish Patra Signed-off-by: Andrew Jones --- .../selftests/kvm/riscv/get-reg-list.c | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tools/testing/selftests/kvm/riscv/get-reg-list.c b/tools/testing/selftests/kvm/riscv/get-reg-list.c index b8da2e86bf9c..6652108816db 100644 --- a/tools/testing/selftests/kvm/riscv/get-reg-list.c +++ b/tools/testing/selftests/kvm/riscv/get-reg-list.c @@ -71,6 +71,7 @@ bool filter_reg(__u64 reg) case KVM_REG_RISCV_SBI_EXT | KVM_REG_RISCV_SBI_SINGLE | KVM_RISCV_SBI_EXT_HSM: case KVM_REG_RISCV_SBI_EXT | KVM_REG_RISCV_SBI_SINGLE | KVM_RISCV_SBI_EXT_PMU: case KVM_REG_RISCV_SBI_EXT | KVM_REG_RISCV_SBI_SINGLE | KVM_RISCV_SBI_EXT_DBCN: + case KVM_REG_RISCV_SBI_EXT | KVM_REG_RISCV_SBI_SINGLE | KVM_RISCV_SBI_EXT_STA: case KVM_REG_RISCV_SBI_EXT | KVM_REG_RISCV_SBI_SINGLE | KVM_RISCV_SBI_EXT_EXPERIMENTAL: case KVM_REG_RISCV_SBI_EXT | KVM_REG_RISCV_SBI_SINGLE | KVM_RISCV_SBI_EXT_VENDOR: return true; @@ -461,6 +462,7 @@ static const char *sbi_ext_single_id_to_str(__u64 reg_off) KVM_SBI_EXT_ARR(KVM_RISCV_SBI_EXT_SRST), KVM_SBI_EXT_ARR(KVM_RISCV_SBI_EXT_HSM), KVM_SBI_EXT_ARR(KVM_RISCV_SBI_EXT_PMU), + KVM_SBI_EXT_ARR(KVM_RISCV_SBI_EXT_STA), KVM_SBI_EXT_ARR(KVM_RISCV_SBI_EXT_EXPERIMENTAL), KVM_SBI_EXT_ARR(KVM_RISCV_SBI_EXT_VENDOR), KVM_SBI_EXT_ARR(KVM_RISCV_SBI_EXT_DBCN), @@ -509,6 +511,32 @@ static const char *sbi_ext_id_to_str(const char *prefix, __u64 id) return strdup_printf("%lld | %lld /* UNKNOWN */", reg_subtype, reg_off); } +static const char *sbi_sta_id_to_str(__u64 reg_off) +{ + switch (reg_off) { + case 0: return "KVM_REG_RISCV_SBI_STA | KVM_REG_RISCV_SBI_STA_REG(shmem_lo)"; + case 1: return "KVM_REG_RISCV_SBI_STA | KVM_REG_RISCV_SBI_STA_REG(shmem_hi)"; + } + return strdup_printf("KVM_REG_RISCV_SBI_STA | %lld /* UNKNOWN */", reg_off); +} + +static const char *sbi_id_to_str(const char *prefix, __u64 id) +{ + __u64 reg_off = id & ~(REG_MASK | KVM_REG_RISCV_SBI_STATE); + __u64 reg_subtype = reg_off & KVM_REG_RISCV_SUBTYPE_MASK; + + assert((id & KVM_REG_RISCV_TYPE_MASK) == KVM_REG_RISCV_SBI_STATE); + + reg_off &= ~KVM_REG_RISCV_SUBTYPE_MASK; + + switch (reg_subtype) { + case KVM_REG_RISCV_SBI_STA: + return sbi_sta_id_to_str(reg_off); + } + + return strdup_printf("%lld | %lld /* UNKNOWN */", reg_subtype, reg_off); +} + void print_reg(const char *prefix, __u64 id) { const char *reg_size = NULL; @@ -565,6 +593,10 @@ void print_reg(const char *prefix, __u64 id) printf("\tKVM_REG_RISCV | %s | KVM_REG_RISCV_SBI_EXT | %s,\n", reg_size, sbi_ext_id_to_str(prefix, id)); break; + case KVM_REG_RISCV_SBI_STATE: + printf("\tKVM_REG_RISCV | %s | KVM_REG_RISCV_SBI_STATE | %s,\n", + reg_size, sbi_id_to_str(prefix, id)); + break; default: printf("\tKVM_REG_RISCV | %s | 0x%llx /* UNKNOWN */,\n", reg_size, id & ~REG_MASK); @@ -651,6 +683,12 @@ static __u64 sbi_base_regs[] = { KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_SBI_EXT | KVM_REG_RISCV_SBI_SINGLE | KVM_RISCV_SBI_EXT_VENDOR, }; +static __u64 sbi_sta_regs[] = { + KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_SBI_EXT | KVM_REG_RISCV_SBI_SINGLE | KVM_RISCV_SBI_EXT_STA, + KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_SBI_STATE | KVM_REG_RISCV_SBI_STA | KVM_REG_RISCV_SBI_STA_REG(shmem_lo), + KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_SBI_STATE | KVM_REG_RISCV_SBI_STA | KVM_REG_RISCV_SBI_STA_REG(shmem_hi), +}; + static __u64 zicbom_regs[] = { KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_CONFIG | KVM_REG_RISCV_CONFIG_REG(zicbom_block_size), KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_ZICBOM, @@ -757,6 +795,9 @@ static __u64 fp_d_regs[] = { #define SUBLIST_SBI_BASE \ {"sbi-base", .feature_type = VCPU_FEATURE_SBI_EXT, .feature = KVM_RISCV_SBI_EXT_V01, \ .regs = sbi_base_regs, .regs_n = ARRAY_SIZE(sbi_base_regs),} +#define SUBLIST_SBI_STA \ + {"sbi-sta", .feature_type = VCPU_FEATURE_SBI_EXT, .feature = KVM_RISCV_SBI_EXT_STA, \ + .regs = sbi_sta_regs, .regs_n = ARRAY_SIZE(sbi_sta_regs),} #define SUBLIST_ZICBOM \ {"zicbom", .feature = KVM_RISCV_ISA_EXT_ZICBOM, .regs = zicbom_regs, .regs_n = ARRAY_SIZE(zicbom_regs),} #define SUBLIST_ZICBOZ \ @@ -832,6 +873,7 @@ static struct vcpu_reg_list config_sbi_##ext = { \ /* Note: The below list is alphabetically sorted. */ KVM_SBI_EXT_SUBLIST_CONFIG(base, BASE); +KVM_SBI_EXT_SUBLIST_CONFIG(sta, STA); KVM_SBI_EXT_SIMPLE_CONFIG(pmu, PMU); KVM_SBI_EXT_SIMPLE_CONFIG(dbcn, DBCN); @@ -858,6 +900,7 @@ KVM_ISA_EXT_SIMPLE_CONFIG(zihpm, ZIHPM); struct vcpu_reg_list *vcpu_configs[] = { &config_sbi_base, + &config_sbi_sta, &config_sbi_pmu, &config_sbi_dbcn, &config_aia,