From patchwork Fri Jan 27 11:39:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118451 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 679E8C61DB3 for ; Fri, 27 Jan 2023 11:40:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231710AbjA0Lkr (ORCPT ); Fri, 27 Jan 2023 06:40:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234143AbjA0Lkf (ORCPT ); Fri, 27 Jan 2023 06:40:35 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4C14D70D54; Fri, 27 Jan 2023 03:40:15 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A44601576; Fri, 27 Jan 2023 03:40:33 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1E5433F64C; Fri, 27 Jan 2023 03:39:49 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 01/31] arm64: Disable MTE when CFI flash is emulated Date: Fri, 27 Jan 2023 11:39:02 +0000 Message-Id: <20230127113932.166089-2-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org CFI Flash file image cannot be mapped into the memory of the guest if MTE is enabled. Thus disable MTE if flash emulation is requested. Signed-off-by: Suzuki K Poulose --- arm/aarch64/kvm.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index 54200c9e..5a53badb 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -145,6 +145,12 @@ void kvm__arch_enable_mte(struct kvm *kvm) return; } + if (kvm->cfg.flash_filename) { + kvm->cfg.arch.mte_disabled = true; + pr_info("MTE is incompatible with CFI flash support, disabling"); + return; + } + if (kvm->cfg.arch.mte_disabled) { pr_debug("MTE disabled by user"); return; From patchwork Fri Jan 27 11:39:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118448 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4098BC61DA7 for ; Fri, 27 Jan 2023 11:40:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230377AbjA0Lkn (ORCPT ); Fri, 27 Jan 2023 06:40:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234168AbjA0Lkg (ORCPT ); Fri, 27 Jan 2023 06:40:36 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 648F2C650; Fri, 27 Jan 2023 03:40:18 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 86EAB15BF; Fri, 27 Jan 2023 03:40:36 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id F3FB23F64C; Fri, 27 Jan 2023 03:39:51 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 02/31] script: update_headers: Ignore missing architectures Date: Fri, 27 Jan 2023 11:39:03 +0000 Message-Id: <20230127113932.166089-3-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Ignore missing architectures for header updates, for use with older kernels. Signed-off-by: Suzuki K Poulose --- util/update_headers.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/util/update_headers.sh b/util/update_headers.sh index 789e2a42..bdfb798c 100755 --- a/util/update_headers.sh +++ b/util/update_headers.sh @@ -48,6 +48,7 @@ copy_optional_arch () { for arch in arm64 mips powerpc riscv x86 do + [ -f $LINUX_ROOT/arch/${arch} ] || continue; case "$arch" in arm64) KVMTOOL_PATH=arm/aarch64 copy_optional_arch asm/sve_context.h ;; From patchwork Fri Jan 27 11:39:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118449 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CFEBC636BD for ; Fri, 27 Jan 2023 11:40:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233678AbjA0Lko (ORCPT ); Fri, 27 Jan 2023 06:40:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234195AbjA0Lki (ORCPT ); Fri, 27 Jan 2023 06:40:38 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 80CC710F4; Fri, 27 Jan 2023 03:40:20 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 68AA515DB; Fri, 27 Jan 2023 03:40:39 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D6A303F64C; Fri, 27 Jan 2023 03:39:54 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 03/31] hw: cfi flash: Handle errors in memory transitions Date: Fri, 27 Jan 2023 11:39:04 +0000 Message-Id: <20230127113932.166089-4-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Handle failures in creating the memory maps and back in transitioning the CFI flash. e.g., with MTE enabled, CFI flash emulation breaks with the map operation, silently. And we later hit unhandled aborts in the guest. To avoid such issues, let us make sure we catch the error and handle it right at source. Signed-off-by: Suzuki K Poulose --- hw/cfi_flash.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/cfi_flash.c b/hw/cfi_flash.c index 7faecdfb..bce546bc 100644 --- a/hw/cfi_flash.c +++ b/hw/cfi_flash.c @@ -455,6 +455,8 @@ static int map_flash_memory(struct kvm *kvm, struct cfi_flash_device *sfdev) KVM_MEM_TYPE_RAM | KVM_MEM_TYPE_READONLY); if (!ret) sfdev->is_mapped = true; + else + die("CFI Flash: ERROR: Unable to map memory: %d\n", ret); return ret; } @@ -472,6 +474,8 @@ static int unmap_flash_memory(struct kvm *kvm, struct cfi_flash_device *sfdev) if (!ret) sfdev->is_mapped = false; + else + die("CFI Flash: Failed to unmap Flash %d", ret); return ret; } From patchwork Fri Jan 27 11:39:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118450 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A41FCC636CB for ; Fri, 27 Jan 2023 11:40:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233455AbjA0Lkq (ORCPT ); Fri, 27 Jan 2023 06:40:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234219AbjA0Lkk (ORCPT ); Fri, 27 Jan 2023 06:40:40 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0BE7024CB3; Fri, 27 Jan 2023 03:40:22 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 415CD1650; Fri, 27 Jan 2023 03:40:42 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B89653F64C; Fri, 27 Jan 2023 03:39:57 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 04/31] Add --nocompat option to disable compat warnings Date: Fri, 27 Jan 2023 11:39:05 +0000 Message-Id: <20230127113932.166089-5-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Alexandru Elisei Commit e66942073035 ("kvm tools: Guest kernel compatability") added the functionality that enables devices to print a warning message if the device hasn't been initialized by the time the VM is destroyed. The purpose of these messages is to let the user know if the kernel hasn't been built with the correct Kconfig options to take advantage of the said devices (all using virtio). Since then, kvmtool has evolved and now supports loading different payloads (like firmware images), and having those warnings even when it is entirely intentional for the payload not to touch the devices can be confusing for the user and makes the output unnecessarily verbose in those cases. Add the --nocompat option to disable the warnings; the warnings are still enabled by default. Reported-by: Christoffer Dall Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- builtin-run.c | 5 ++++- guest_compat.c | 1 + include/kvm/kvm-config.h | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/builtin-run.c b/builtin-run.c index bb7e6e8d..f8edfb3f 100644 --- a/builtin-run.c +++ b/builtin-run.c @@ -183,6 +183,8 @@ static int mem_parser(const struct option *opt, const char *arg, int unset) OPT_BOOLEAN('\0', "nodefaults", &(cfg)->nodefaults, "Disable" \ " implicit configuration that cannot be" \ " disabled otherwise"), \ + OPT_BOOLEAN('\0', "nocompat", &(cfg)->nocompat, "Disable" \ + " compat warnings"), \ OPT_CALLBACK('\0', "9p", NULL, "dir_to_share,tag_name", \ "Enable virtio 9p to share files between host and" \ " guest", virtio_9p_rootdir_parser, kvm), \ @@ -797,7 +799,8 @@ static int kvm_cmd_run_work(struct kvm *kvm) static void kvm_cmd_run_exit(struct kvm *kvm, int guest_ret) { - compat__print_all_messages(); + if (!kvm->cfg.nocompat) + compat__print_all_messages(); init_list__exit(kvm); diff --git a/guest_compat.c b/guest_compat.c index fd4704b2..a413c12c 100644 --- a/guest_compat.c +++ b/guest_compat.c @@ -88,6 +88,7 @@ int compat__print_all_messages(void) printf("\n # KVM compatibility warning.\n\t%s\n\t%s\n", msg->title, msg->desc); + printf("\tTo stop seeing this warning, use the --nocompat option.\n"); list_del(&msg->list); compat__free(msg); diff --git a/include/kvm/kvm-config.h b/include/kvm/kvm-config.h index 368e6c7d..88df7cc2 100644 --- a/include/kvm/kvm-config.h +++ b/include/kvm/kvm-config.h @@ -30,6 +30,7 @@ struct kvm_config { u64 vsock_cid; bool virtio_rng; bool nodefaults; + bool nocompat; int active_console; int debug_iodelay; int nrcpus; From patchwork Fri Jan 27 11:39:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118452 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA680C38142 for ; Fri, 27 Jan 2023 11:41:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233848AbjA0LlR (ORCPT ); Fri, 27 Jan 2023 06:41:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233857AbjA0LlK (ORCPT ); Fri, 27 Jan 2023 06:41:10 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 94271F77F; Fri, 27 Jan 2023 03:40:41 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2471D1684; Fri, 27 Jan 2023 03:40:45 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 911713F64C; Fri, 27 Jan 2023 03:40:00 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 05/31] arm64: Check pvtime support against the KVM instance Date: Fri, 27 Jan 2023 11:39:06 +0000 Message-Id: <20230127113932.166089-6-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org KVM_CAP_STEAL_TIME can be checked against a VM instance. To allow controlling the feature depending on the VM type, use the cap against the VM. Signed-off-by: Suzuki K Poulose --- arm/aarch64/pvtime.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arm/aarch64/pvtime.c b/arm/aarch64/pvtime.c index 2933ac7c..839aa8a7 100644 --- a/arm/aarch64/pvtime.c +++ b/arm/aarch64/pvtime.c @@ -58,8 +58,8 @@ int kvm_cpu__setup_pvtime(struct kvm_cpu *vcpu) if (kvm_cfg->no_pvtime) return 0; - has_stolen_time = kvm__supports_extension(vcpu->kvm, - KVM_CAP_STEAL_TIME); + has_stolen_time = kvm__supports_vm_extension(vcpu->kvm, + KVM_CAP_STEAL_TIME); if (!has_stolen_time) { kvm_cfg->no_pvtime = true; return 0; From patchwork Fri Jan 27 11:39:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118453 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6852C61DA7 for ; Fri, 27 Jan 2023 11:41:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231805AbjA0LlT (ORCPT ); Fri, 27 Jan 2023 06:41:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233855AbjA0LlK (ORCPT ); Fri, 27 Jan 2023 06:41:10 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9446B10250; Fri, 27 Jan 2023 03:40:41 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 06F48165C; Fri, 27 Jan 2023 03:40:48 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7406D3F64C; Fri, 27 Jan 2023 03:40:03 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 06/31] arm64: Check SVE capability on the VM instance Date: Fri, 27 Jan 2023 11:39:07 +0000 Message-Id: <20230127113932.166089-7-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Similar to PVtime, check the SVE capability on the VM instance to account for the different VM types and the corresponding support. Signed-off-by: Suzuki K Poulose --- arm/aarch64/kvm-cpu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arm/aarch64/kvm-cpu.c b/arm/aarch64/kvm-cpu.c index c8be10b3..da809806 100644 --- a/arm/aarch64/kvm-cpu.c +++ b/arm/aarch64/kvm-cpu.c @@ -150,13 +150,15 @@ void kvm_cpu__select_features(struct kvm *kvm, struct kvm_vcpu_init *init) } /* Enable SVE if available */ - if (kvm__supports_extension(kvm, KVM_CAP_ARM_SVE)) + if (kvm__supports_vm_extension(kvm, KVM_CAP_ARM_SVE)) init->features[0] |= 1UL << KVM_ARM_VCPU_SVE; } int kvm_cpu__configure_features(struct kvm_cpu *vcpu) { - if (kvm__supports_extension(vcpu->kvm, KVM_CAP_ARM_SVE)) { + struct kvm *kvm = vcpu->kvm; + + if (kvm__supports_vm_extension(kvm, KVM_CAP_ARM_SVE)) { int feature = KVM_ARM_VCPU_SVE; if (ioctl(vcpu->vcpu_fd, KVM_ARM_VCPU_FINALIZE, &feature)) { From patchwork Fri Jan 27 11:39:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118454 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73E3FC61DA4 for ; Fri, 27 Jan 2023 11:41:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233736AbjA0LlV (ORCPT ); Fri, 27 Jan 2023 06:41:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233174AbjA0LlK (ORCPT ); Fri, 27 Jan 2023 06:41:10 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 68A7411650; Fri, 27 Jan 2023 03:40:42 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D42961688; Fri, 27 Jan 2023 03:40:50 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 56CDA3F64C; Fri, 27 Jan 2023 03:40:06 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 07/31] arm64: Add option to disable SVE Date: Fri, 27 Jan 2023 11:39:08 +0000 Message-Id: <20230127113932.166089-8-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org kvmtool enables SVE whenever it is supported by the KVM. However, Realm VMs may want controlled features, which gets measured during the creation. Thus, provide an option to disable the SVE, to preserve the current behavior of SVE on by default. Signed-off-by: Suzuki K Poulose --- arm/aarch64/include/kvm/kvm-config-arch.h | 4 +++- arm/aarch64/kvm-cpu.c | 8 +++++--- arm/include/arm-common/kvm-config-arch.h | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/arm/aarch64/include/kvm/kvm-config-arch.h b/arm/aarch64/include/kvm/kvm-config-arch.h index eae8080d..b055fef4 100644 --- a/arm/aarch64/include/kvm/kvm-config-arch.h +++ b/arm/aarch64/include/kvm/kvm-config-arch.h @@ -19,7 +19,9 @@ int vcpu_affinity_parser(const struct option *opt, const char *arg, int unset); "Specify random seed for Kernel Address Space " \ "Layout Randomization (KASLR)"), \ OPT_BOOLEAN('\0', "no-pvtime", &(cfg)->no_pvtime, "Disable" \ - " stolen time"), + " stolen time"), \ + OPT_BOOLEAN('\0', "disable-sve", &(cfg)->disable_sve, \ + "Disable SVE"), #include "arm-common/kvm-config-arch.h" #endif /* KVM__KVM_CONFIG_ARCH_H */ diff --git a/arm/aarch64/kvm-cpu.c b/arm/aarch64/kvm-cpu.c index da809806..e7649239 100644 --- a/arm/aarch64/kvm-cpu.c +++ b/arm/aarch64/kvm-cpu.c @@ -149,8 +149,9 @@ void kvm_cpu__select_features(struct kvm *kvm, struct kvm_vcpu_init *init) init->features[0] |= 1UL << KVM_ARM_VCPU_PTRAUTH_GENERIC; } - /* Enable SVE if available */ - if (kvm__supports_vm_extension(kvm, KVM_CAP_ARM_SVE)) + /* If SVE is not disabled explicitly, enable if available */ + if (!kvm->cfg.arch.disable_sve && + kvm__supports_vm_extension(kvm, KVM_CAP_ARM_SVE)) init->features[0] |= 1UL << KVM_ARM_VCPU_SVE; } @@ -158,7 +159,8 @@ int kvm_cpu__configure_features(struct kvm_cpu *vcpu) { struct kvm *kvm = vcpu->kvm; - if (kvm__supports_vm_extension(kvm, KVM_CAP_ARM_SVE)) { + if (!kvm->cfg.arch.disable_sve && + kvm__supports_vm_extension(kvm, KVM_CAP_ARM_SVE)) { int feature = KVM_ARM_VCPU_SVE; if (ioctl(vcpu->vcpu_fd, KVM_ARM_VCPU_FINALIZE, &feature)) { diff --git a/arm/include/arm-common/kvm-config-arch.h b/arm/include/arm-common/kvm-config-arch.h index 9949bfe4..6599305b 100644 --- a/arm/include/arm-common/kvm-config-arch.h +++ b/arm/include/arm-common/kvm-config-arch.h @@ -15,6 +15,7 @@ struct kvm_config_arch { enum irqchip_type irqchip; u64 fw_addr; bool no_pvtime; + bool disable_sve; }; int irqchip_parser(const struct option *opt, const char *arg, int unset); From patchwork Fri Jan 27 11:39:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118455 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9858EC61DA4 for ; Fri, 27 Jan 2023 11:41:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233880AbjA0LlX (ORCPT ); Fri, 27 Jan 2023 06:41:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233863AbjA0LlK (ORCPT ); Fri, 27 Jan 2023 06:41:10 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BCE2320D1B; Fri, 27 Jan 2023 03:40:42 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id ADE761691; Fri, 27 Jan 2023 03:40:53 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 30A043F64C; Fri, 27 Jan 2023 03:40:09 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 08/31] linux: Update kernel headers for RME support Date: Fri, 27 Jan 2023 11:39:09 +0000 Message-Id: <20230127113932.166089-9-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Update the RME specific ABI bits from the kernel headers. Signed-off-by: Suzuki K Poulose --- arm/aarch64/include/asm/kvm.h | 64 +++++++++++++++++++++++++++++++++++ include/linux/kvm.h | 22 +++++++++--- include/linux/virtio_blk.h | 19 ----------- include/linux/virtio_net.h | 14 ++++---- include/linux/virtio_ring.h | 16 +++------ 5 files changed, 93 insertions(+), 42 deletions(-) diff --git a/arm/aarch64/include/asm/kvm.h b/arm/aarch64/include/asm/kvm.h index 316917b9..653a08fb 100644 --- a/arm/aarch64/include/asm/kvm.h +++ b/arm/aarch64/include/asm/kvm.h @@ -108,6 +108,7 @@ struct kvm_regs { #define KVM_ARM_VCPU_SVE 4 /* enable SVE for this CPU */ #define KVM_ARM_VCPU_PTRAUTH_ADDRESS 5 /* VCPU uses address authentication */ #define KVM_ARM_VCPU_PTRAUTH_GENERIC 6 /* VCPU uses generic authentication */ +#define KVM_ARM_VCPU_REC 7 /* VCPU REC state as part of Realm */ struct kvm_vcpu_init { __u32 target; @@ -400,6 +401,69 @@ enum { #define KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES 3 #define KVM_DEV_ARM_ITS_CTRL_RESET 4 +/* KVM_CAP_ARM_RME kvm_enable_cap->args[0] points to this */ +#define KVM_CAP_ARM_RME_CONFIG_REALM 0 +#define KVM_CAP_ARM_RME_CREATE_RD 1 +#define KVM_CAP_ARM_RME_INIT_IPA_REALM 2 +#define KVM_CAP_ARM_RME_POPULATE_REALM 3 +#define KVM_CAP_ARM_RME_ACTIVATE_REALM 4 + +#define KVM_CAP_ARM_RME_MEASUREMENT_ALGO_ZERO (0x01ULL << 7) +#define KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA256 0 +#define KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA512 1 + +#define KVM_CAP_ARM_RME_RPV_SIZE 64 + +/* List of configuration items accepted for KVM_CAP_ARM_RME_CONFIG_REALM */ +#define KVM_CAP_ARM_RME_CFG_RPV 0 +#define KVM_CAP_ARM_RME_CFG_HASH_ALGO 1 +#define KVM_CAP_ARM_RME_CFG_SVE 2 +#define KVM_CAP_ARM_RME_CFG_DBG 3 +#define KVM_CAP_ARM_RME_CFG_PMU 4 + +struct kvm_cap_arm_rme_config_item { + __u32 cfg; + union { + /* cfg == KVM_CAP_ARM_RME_CFG_RPV */ + struct { + __u8 rpv[KVM_CAP_ARM_RME_RPV_SIZE]; + }; + + /* cfg == KVM_CAP_ARM_RME_CFG_HASH_ALGO */ + struct { + __u32 hash_algo; + }; + + /* cfg == KVM_CAP_ARM_RME_CFG_SVE */ + struct { + __u32 sve_vq; + }; + + /* cfg == KVM_CAP_ARM_RME_CFG_DBG */ + struct { + __u32 num_brps; + __u32 num_wrps; + }; + + /* cfg == KVM_CAP_ARM_RME_CFG_PMU */ + struct { + __u32 num_pmu_cntrs; + }; + /* Fix the size of the union */ + __u8 reserved[256]; + }; +}; + +struct kvm_cap_arm_rme_populate_realm_args { + __u64 populate_ipa_base; + __u64 populate_ipa_size; +}; + +struct kvm_cap_arm_rme_init_ipa_args { + __u64 init_ipa_base; + __u64 init_ipa_size; +}; + /* Device Control API on vcpu fd */ #define KVM_ARM_VCPU_PMU_V3_CTRL 0 #define KVM_ARM_VCPU_PMU_V3_IRQ 0 diff --git a/include/linux/kvm.h b/include/linux/kvm.h index 0d5d4419..789c7f89 100644 --- a/include/linux/kvm.h +++ b/include/linux/kvm.h @@ -903,14 +903,25 @@ struct kvm_ppc_resize_hpt { #define KVM_S390_SIE_PAGE_OFFSET 1 /* - * On arm64, machine type can be used to request the physical - * address size for the VM. Bits[7-0] are reserved for the guest - * PA size shift (i.e, log2(PA_Size)). For backward compatibility, - * value 0 implies the default IPA size, 40bits. + * On arm64, machine type can be used to request both the machine type and + * the physical address size for the VM. + * + * Bits[11-8] are reserved for the ARM specific machine type. + * + * Bits[7-0] are reserved for the guest PA size shift (i.e, log2(PA_Size)). + * For backward compatibility, value 0 implies the default IPA size, 40bits. */ +#define KVM_VM_TYPE_ARM_SHIFT 8 +#define KVM_VM_TYPE_ARM_MASK (0xfULL << KVM_VM_TYPE_ARM_SHIFT) +#define KVM_VM_TYPE_ARM(_type) \ + (((_type) << KVM_VM_TYPE_ARM_SHIFT) & KVM_VM_TYPE_ARM_MASK) +#define KVM_VM_TYPE_ARM_NORMAL KVM_VM_TYPE_ARM(0) +#define KVM_VM_TYPE_ARM_REALM KVM_VM_TYPE_ARM(1) + #define KVM_VM_TYPE_ARM_IPA_SIZE_MASK 0xffULL #define KVM_VM_TYPE_ARM_IPA_SIZE(x) \ ((x) & KVM_VM_TYPE_ARM_IPA_SIZE_MASK) + /* * ioctls for /dev/kvm fds: */ @@ -1177,7 +1188,8 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_VM_DISABLE_NX_HUGE_PAGES 220 #define KVM_CAP_S390_ZPCI_OP 221 #define KVM_CAP_S390_CPU_TOPOLOGY 222 -#define KVM_CAP_DIRTY_LOG_RING_ACQ_REL 223 + +#define KVM_CAP_ARM_RME 300 // FIXME: Large number to prevent conflicts #ifdef KVM_CAP_IRQ_ROUTING diff --git a/include/linux/virtio_blk.h b/include/linux/virtio_blk.h index 58e70b24..d888f013 100644 --- a/include/linux/virtio_blk.h +++ b/include/linux/virtio_blk.h @@ -40,7 +40,6 @@ #define VIRTIO_BLK_F_MQ 12 /* support more than one vq */ #define VIRTIO_BLK_F_DISCARD 13 /* DISCARD is supported */ #define VIRTIO_BLK_F_WRITE_ZEROES 14 /* WRITE ZEROES is supported */ -#define VIRTIO_BLK_F_SECURE_ERASE 16 /* Secure Erase is supported */ /* Legacy feature bits */ #ifndef VIRTIO_BLK_NO_LEGACY @@ -122,21 +121,6 @@ struct virtio_blk_config { __u8 write_zeroes_may_unmap; __u8 unused1[3]; - - /* the next 3 entries are guarded by VIRTIO_BLK_F_SECURE_ERASE */ - /* - * The maximum secure erase sectors (in 512-byte sectors) for - * one segment. - */ - __virtio32 max_secure_erase_sectors; - /* - * The maximum number of secure erase segments in a - * secure erase command. - */ - __virtio32 max_secure_erase_seg; - /* Secure erase commands must be aligned to this number of sectors. */ - __virtio32 secure_erase_sector_alignment; - } __attribute__((packed)); /* @@ -171,9 +155,6 @@ struct virtio_blk_config { /* Write zeroes command */ #define VIRTIO_BLK_T_WRITE_ZEROES 13 -/* Secure erase command */ -#define VIRTIO_BLK_T_SECURE_ERASE 14 - #ifndef VIRTIO_BLK_NO_LEGACY /* Barrier before this op. */ #define VIRTIO_BLK_T_BARRIER 0x80000000 diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h index 6cb842ea..29ced555 100644 --- a/include/linux/virtio_net.h +++ b/include/linux/virtio_net.h @@ -56,7 +56,7 @@ #define VIRTIO_NET_F_MQ 22 /* Device supports Receive Flow * Steering */ #define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ -#define VIRTIO_NET_F_NOTF_COAL 53 /* Device supports notifications coalescing */ +#define VIRTIO_NET_F_NOTF_COAL 53 /* Guest can handle notifications coalescing */ #define VIRTIO_NET_F_HASH_REPORT 57 /* Supports hash report */ #define VIRTIO_NET_F_RSS 60 /* Supports RSS RX steering */ #define VIRTIO_NET_F_RSC_EXT 61 /* extended coalescing info */ @@ -364,24 +364,24 @@ struct virtio_net_hash_config { */ #define VIRTIO_NET_CTRL_NOTF_COAL 6 /* - * Set the tx-usecs/tx-max-packets parameters. + * Set the tx-usecs/tx-max-packets patameters. + * tx-usecs - Maximum number of usecs to delay a TX notification. + * tx-max-packets - Maximum number of packets to send before a TX notification. */ struct virtio_net_ctrl_coal_tx { - /* Maximum number of packets to send before a TX notification */ __le32 tx_max_packets; - /* Maximum number of usecs to delay a TX notification */ __le32 tx_usecs; }; #define VIRTIO_NET_CTRL_NOTF_COAL_TX_SET 0 /* - * Set the rx-usecs/rx-max-packets parameters. + * Set the rx-usecs/rx-max-packets patameters. + * rx-usecs - Maximum number of usecs to delay a RX notification. + * rx-max-frames - Maximum number of packets to receive before a RX notification. */ struct virtio_net_ctrl_coal_rx { - /* Maximum number of packets to receive before a RX notification */ __le32 rx_max_packets; - /* Maximum number of usecs to delay a RX notification */ __le32 rx_usecs; }; diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h index f8c20d3d..476d3e5c 100644 --- a/include/linux/virtio_ring.h +++ b/include/linux/virtio_ring.h @@ -93,21 +93,15 @@ #define VRING_USED_ALIGN_SIZE 4 #define VRING_DESC_ALIGN_SIZE 16 -/** - * struct vring_desc - Virtio ring descriptors, - * 16 bytes long. These can chain together via @next. - * - * @addr: buffer address (guest-physical) - * @len: buffer length - * @flags: descriptor flags - * @next: index of the next descriptor in the chain, - * if the VRING_DESC_F_NEXT flag is set. We chain unused - * descriptors via this, too. - */ +/* Virtio ring descriptors: 16 bytes. These can chain together via "next". */ struct vring_desc { + /* Address (guest-physical). */ __virtio64 addr; + /* Length. */ __virtio32 len; + /* The flags as indicated above. */ __virtio16 flags; + /* We chain unused descriptors via this, too */ __virtio16 next; }; From patchwork Fri Jan 27 11:39:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118456 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85FF9C61DA7 for ; Fri, 27 Jan 2023 11:41:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229550AbjA0LlY (ORCPT ); Fri, 27 Jan 2023 06:41:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233864AbjA0LlK (ORCPT ); Fri, 27 Jan 2023 06:41:10 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EA711196B1; Fri, 27 Jan 2023 03:40:42 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8928E169C; Fri, 27 Jan 2023 03:40:56 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0A2453F64C; Fri, 27 Jan 2023 03:40:11 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 09/31] arm64: Add --realm command line option Date: Fri, 27 Jan 2023 11:39:10 +0000 Message-Id: <20230127113932.166089-10-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Alexandru Elisei Add the --realm command line option which causes kvmtool to exit with an error if specified, but which will be enabled once realms are fully supported by kvmtool. Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- arm/aarch64/include/kvm/kvm-config-arch.h | 5 ++++- arm/aarch64/kvm.c | 20 ++++++++++++++++++-- arm/include/arm-common/kvm-config-arch.h | 1 + 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/arm/aarch64/include/kvm/kvm-config-arch.h b/arm/aarch64/include/kvm/kvm-config-arch.h index b055fef4..d2df850a 100644 --- a/arm/aarch64/include/kvm/kvm-config-arch.h +++ b/arm/aarch64/include/kvm/kvm-config-arch.h @@ -21,7 +21,10 @@ int vcpu_affinity_parser(const struct option *opt, const char *arg, int unset); OPT_BOOLEAN('\0', "no-pvtime", &(cfg)->no_pvtime, "Disable" \ " stolen time"), \ OPT_BOOLEAN('\0', "disable-sve", &(cfg)->disable_sve, \ - "Disable SVE"), + "Disable SVE"), \ + OPT_BOOLEAN('\0', "realm", &(cfg)->is_realm, \ + "Create VM running in a realm using Arm RME"), + #include "arm-common/kvm-config-arch.h" #endif /* KVM__KVM_CONFIG_ARCH_H */ diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index 5a53badb..25be2f2d 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -38,9 +38,8 @@ int vcpu_affinity_parser(const struct option *opt, const char *arg, int unset) return 0; } -void kvm__arch_validate_cfg(struct kvm *kvm) +static void validate_mem_cfg(struct kvm *kvm) { - if (kvm->cfg.ram_addr < ARM_MEMORY_AREA) { die("RAM address is below the I/O region ending at %luGB", ARM_MEMORY_AREA >> 30); @@ -52,6 +51,23 @@ void kvm__arch_validate_cfg(struct kvm *kvm) } } +static void validate_realm_cfg(struct kvm *kvm) +{ + if (!kvm->cfg.arch.is_realm) + return; + + if (kvm->cfg.arch.aarch32_guest) + die("Realms supported only for 64bit guests"); + + die("Realms not supported"); +} + +void kvm__arch_validate_cfg(struct kvm *kvm) +{ + validate_mem_cfg(kvm); + validate_realm_cfg(kvm); +} + u64 kvm__arch_default_ram_address(void) { return ARM_MEMORY_AREA; diff --git a/arm/include/arm-common/kvm-config-arch.h b/arm/include/arm-common/kvm-config-arch.h index 6599305b..5eb791da 100644 --- a/arm/include/arm-common/kvm-config-arch.h +++ b/arm/include/arm-common/kvm-config-arch.h @@ -11,6 +11,7 @@ struct kvm_config_arch { bool aarch32_guest; bool has_pmuv3; bool mte_disabled; + bool is_realm; u64 kaslr_seed; enum irqchip_type irqchip; u64 fw_addr; From patchwork Fri Jan 27 11:39:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118457 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 370A4C61DB3 for ; Fri, 27 Jan 2023 11:41:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233295AbjA0Ll0 (ORCPT ); Fri, 27 Jan 2023 06:41:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233865AbjA0LlK (ORCPT ); Fri, 27 Jan 2023 06:41:10 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 19C1C20D28; Fri, 27 Jan 2023 03:40:43 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 62808169E; Fri, 27 Jan 2023 03:40:59 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D96673F64C; Fri, 27 Jan 2023 03:40:14 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 10/31] arm64: Create a realm virtual machine Date: Fri, 27 Jan 2023 11:39:11 +0000 Message-Id: <20230127113932.166089-11-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Christoffer Dall Set the machine type to realm when creating a VM via the KVM_CREATE_VM ioctl. Signed-off-by: Christoffer Dall [ Alex E: Reworked patch, split the command line option into a different patch ] Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- arm/aarch64/kvm.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index 25be2f2d..5db4c572 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -131,12 +131,15 @@ int kvm__arch_get_ipa_limit(struct kvm *kvm) int kvm__get_vm_type(struct kvm *kvm) { unsigned int ipa_bits, max_ipa_bits; - unsigned long max_ipa; + unsigned long max_ipa, vm_type; - /* If we're running on an old kernel, use 0 as the VM type */ + vm_type = kvm->cfg.arch.is_realm ? \ + KVM_VM_TYPE_ARM_REALM : KVM_VM_TYPE_ARM_NORMAL; + + /* If we're running on an old kernel, use 0 as the IPA bits */ max_ipa_bits = kvm__arch_get_ipa_limit(kvm); if (!max_ipa_bits) - return 0; + return vm_type; /* Otherwise, compute the minimal required IPA size */ max_ipa = kvm->cfg.ram_addr + kvm->cfg.ram_size - 1; @@ -147,7 +150,8 @@ int kvm__get_vm_type(struct kvm *kvm) if (ipa_bits > max_ipa_bits) die("Memory too large for this system (needs %d bits, %d available)", ipa_bits, max_ipa_bits); - return KVM_VM_TYPE_ARM_IPA_SIZE(ipa_bits); + vm_type |= KVM_VM_TYPE_ARM_IPA_SIZE(ipa_bits); + return vm_type; } void kvm__arch_enable_mte(struct kvm *kvm) From patchwork Fri Jan 27 11:39:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118458 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27CC5C38142 for ; Fri, 27 Jan 2023 11:41:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232235AbjA0Ll2 (ORCPT ); Fri, 27 Jan 2023 06:41:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233690AbjA0LlL (ORCPT ); Fri, 27 Jan 2023 06:41:11 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 18908126CA; Fri, 27 Jan 2023 03:40:44 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3C11D16A3; Fri, 27 Jan 2023 03:41:02 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B29523F64C; Fri, 27 Jan 2023 03:40:17 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 11/31] arm64: Lock realm RAM in memory Date: Fri, 27 Jan 2023 11:39:12 +0000 Message-Id: <20230127113932.166089-12-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Alexandru Elisei RMM doesn't yet support paging protected memory pages. Thus the VMM must pin the entire VM memory. Use mlock2 to keep the realm pages pinned in memory once they are faulted in. Use the MLOCK_ONFAULT flag to prevent pre-mapping the pages and maintain some semblance of on demand-paging for a realm VM. Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- arm/kvm.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/arm/kvm.c b/arm/kvm.c index d51cc15d..0e40b753 100644 --- a/arm/kvm.c +++ b/arm/kvm.c @@ -7,6 +7,8 @@ #include "arm-common/gic.h" +#include + #include #include #include @@ -24,6 +26,25 @@ bool kvm__arch_cpu_supports_vm(void) return true; } +static void try_increase_mlock_limit(struct kvm *kvm) +{ + u64 size = kvm->arch.ram_alloc_size; + struct rlimit mlock_limit, new_limit; + + if (getrlimit(RLIMIT_MEMLOCK, &mlock_limit)) { + perror("getrlimit(RLIMIT_MEMLOCK)"); + return; + } + + if (mlock_limit.rlim_cur > size) + return; + + new_limit.rlim_cur = size; + new_limit.rlim_max = max((rlim_t)size, mlock_limit.rlim_max); + /* Requires CAP_SYS_RESOURCE capability. */ + setrlimit(RLIMIT_MEMLOCK, &new_limit); +} + void kvm__init_ram(struct kvm *kvm) { u64 phys_start, phys_size; @@ -49,8 +70,27 @@ void kvm__init_ram(struct kvm *kvm) kvm->ram_start = (void *)ALIGN((unsigned long)kvm->arch.ram_alloc_start, SZ_2M); - madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size, - MADV_MERGEABLE); + /* + * Do not merge pages if this is a Realm. + * a) We cannot replace a page in realm stage2 without export/import + * + * Pin the realm memory until we have export/import, due to the same + * reason as above. + * + * Use mlock2(,,MLOCK_ONFAULT) to allow faulting in pages and thus + * allowing to lazily populate the PAR. + */ + if (kvm->cfg.arch.is_realm) { + int ret; + + try_increase_mlock_limit(kvm); + ret = mlock2(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size, + MLOCK_ONFAULT); + if (ret) + die_perror("mlock2"); + } else { + madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size, MADV_MERGEABLE); + } madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size, MADV_HUGEPAGE); From patchwork Fri Jan 27 11:39:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118459 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76162C61DA4 for ; Fri, 27 Jan 2023 11:41:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233863AbjA0Lla (ORCPT ); Fri, 27 Jan 2023 06:41:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233874AbjA0LlM (ORCPT ); Fri, 27 Jan 2023 06:41:12 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9F27722A29; Fri, 27 Jan 2023 03:40:44 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 14FA01692; Fri, 27 Jan 2023 03:41:05 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8C0393F64C; Fri, 27 Jan 2023 03:40:20 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 12/31] arm64: Create Realm Descriptor Date: Fri, 27 Jan 2023 11:39:13 +0000 Message-Id: <20230127113932.166089-13-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Alexandru Elisei Create the Realm Descriptor using the measurement algorithm set with --measurement-algo. Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- Makefile | 1 + arm/aarch32/include/asm/realm.h | 10 ++++++++++ arm/aarch64/include/asm/realm.h | 10 ++++++++++ arm/aarch64/realm.c | 14 ++++++++++++++ arm/kvm.c | 3 +++ 5 files changed, 38 insertions(+) create mode 100644 arm/aarch32/include/asm/realm.h create mode 100644 arm/aarch64/include/asm/realm.h create mode 100644 arm/aarch64/realm.c diff --git a/Makefile b/Makefile index ed2414bd..88cdf6d2 100644 --- a/Makefile +++ b/Makefile @@ -192,6 +192,7 @@ ifeq ($(ARCH), arm64) OBJS += arm/aarch64/kvm.o OBJS += arm/aarch64/pvtime.o OBJS += arm/aarch64/pmu.o + OBJS += arm/aarch64/realm.o ARCH_INCLUDE := $(HDRS_ARM_COMMON) ARCH_INCLUDE += -Iarm/aarch64/include diff --git a/arm/aarch32/include/asm/realm.h b/arm/aarch32/include/asm/realm.h new file mode 100644 index 00000000..5aca6cca --- /dev/null +++ b/arm/aarch32/include/asm/realm.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __ASM_REALM_H +#define __ASM_REALM_H + +#include "kvm/kvm.h" + +static inline void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm) {} + +#endif /* ! __ASM_REALM_H */ diff --git a/arm/aarch64/include/asm/realm.h b/arm/aarch64/include/asm/realm.h new file mode 100644 index 00000000..e176f15f --- /dev/null +++ b/arm/aarch64/include/asm/realm.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __ASM_REALM_H +#define __ASM_REALM_H + +#include "kvm/kvm.h" + +void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm); + +#endif /* ! __ASM_REALM_H */ diff --git a/arm/aarch64/realm.c b/arm/aarch64/realm.c new file mode 100644 index 00000000..3a4adb66 --- /dev/null +++ b/arm/aarch64/realm.c @@ -0,0 +1,14 @@ +#include "kvm/kvm.h" + +#include + +void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm) +{ + struct kvm_enable_cap rme_create_rd = { + .cap = KVM_CAP_ARM_RME, + .args[0] = KVM_CAP_ARM_RME_CREATE_RD, + }; + + if (ioctl(kvm->vm_fd, KVM_ENABLE_CAP, &rme_create_rd) < 0) + die_perror("KVM_CAP_RME(KVM_CAP_ARM_RME_CREATE_RD)"); +} diff --git a/arm/kvm.c b/arm/kvm.c index 0e40b753..2510a322 100644 --- a/arm/kvm.c +++ b/arm/kvm.c @@ -127,6 +127,9 @@ void kvm__arch_set_cmdline(char *cmdline, bool video) void kvm__arch_init(struct kvm *kvm) { + if (kvm->cfg.arch.is_realm) + kvm_arm_realm_create_realm_descriptor(kvm); + /* Create the virtual GIC. */ if (gic__create(kvm, kvm->cfg.arch.irqchip)) die("Failed to create virtual GIC"); From patchwork Fri Jan 27 11:39:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118460 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6964FC38142 for ; Fri, 27 Jan 2023 11:41:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232164AbjA0Llc (ORCPT ); Fri, 27 Jan 2023 06:41:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233878AbjA0LlM (ORCPT ); Fri, 27 Jan 2023 06:41:12 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 66D6C22A39; Fri, 27 Jan 2023 03:40:45 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E28C316F8; Fri, 27 Jan 2023 03:41:07 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6552D3F64C; Fri, 27 Jan 2023 03:40:23 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 13/31] arm64: Add --measurement-algo command line option for a realm Date: Fri, 27 Jan 2023 11:39:14 +0000 Message-Id: <20230127113932.166089-14-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Christoffer Dall Add the command line option to specify the algorithm that will be used to create the cryptographic measurement of the realm. Valid options are "sha256" and "sha512". The final measurement will be a hash using the selected algorithm Signed-off-by: Christoffer Dall Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- arm/aarch64/include/kvm/kvm-config-arch.h | 5 ++++- arm/aarch64/kvm.c | 17 ++++++++++++++++- arm/include/arm-common/kvm-arch.h | 1 + arm/include/arm-common/kvm-config-arch.h | 1 + 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/arm/aarch64/include/kvm/kvm-config-arch.h b/arm/aarch64/include/kvm/kvm-config-arch.h index d2df850a..b93999b6 100644 --- a/arm/aarch64/include/kvm/kvm-config-arch.h +++ b/arm/aarch64/include/kvm/kvm-config-arch.h @@ -23,7 +23,10 @@ int vcpu_affinity_parser(const struct option *opt, const char *arg, int unset); OPT_BOOLEAN('\0', "disable-sve", &(cfg)->disable_sve, \ "Disable SVE"), \ OPT_BOOLEAN('\0', "realm", &(cfg)->is_realm, \ - "Create VM running in a realm using Arm RME"), + "Create VM running in a realm using Arm RME"), \ + OPT_STRING('\0', "measurement-algo", &(cfg)->measurement_algo, \ + "sha256, sha512", \ + "Realm Measurement algorithm, default: sha256"), #include "arm-common/kvm-config-arch.h" diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index 5db4c572..a5a98b2e 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -53,12 +53,27 @@ static void validate_mem_cfg(struct kvm *kvm) static void validate_realm_cfg(struct kvm *kvm) { - if (!kvm->cfg.arch.is_realm) + if (!kvm->cfg.arch.is_realm) { + if (kvm->cfg.arch.measurement_algo) + die("--measurement-algo valid only with --realm"); return; + } if (kvm->cfg.arch.aarch32_guest) die("Realms supported only for 64bit guests"); + if (kvm->cfg.arch.measurement_algo) { + if (strcmp(kvm->cfg.arch.measurement_algo, "sha256") == 0) + kvm->arch.measurement_algo = KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA256; + else if (strcmp(kvm->cfg.arch.measurement_algo, "sha512") == 0) + kvm->arch.measurement_algo = KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA512; + else + die("unknown realm measurement algorithm"); + } else { + pr_debug("Realm Hash algorithm: Using default SHA256\n"); + kvm->arch.measurement_algo = KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA256; + } + die("Realms not supported"); } diff --git a/arm/include/arm-common/kvm-arch.h b/arm/include/arm-common/kvm-arch.h index b2ae373c..68224b1c 100644 --- a/arm/include/arm-common/kvm-arch.h +++ b/arm/include/arm-common/kvm-arch.h @@ -113,6 +113,7 @@ struct kvm_arch { u64 dtb_guest_start; cpu_set_t *vcpu_affinity_cpuset; + u64 measurement_algo; }; #endif /* ARM_COMMON__KVM_ARCH_H */ diff --git a/arm/include/arm-common/kvm-config-arch.h b/arm/include/arm-common/kvm-config-arch.h index 5eb791da..a2faa3af 100644 --- a/arm/include/arm-common/kvm-config-arch.h +++ b/arm/include/arm-common/kvm-config-arch.h @@ -6,6 +6,7 @@ struct kvm_config_arch { const char *dump_dtb_filename; const char *vcpu_affinity; + const char *measurement_algo; unsigned int force_cntfrq; bool virtio_trans_pci; bool aarch32_guest; From patchwork Fri Jan 27 11:39:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118461 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49518C54EAA for ; Fri, 27 Jan 2023 11:41:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233834AbjA0Lle (ORCPT ); Fri, 27 Jan 2023 06:41:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233816AbjA0LlM (ORCPT ); Fri, 27 Jan 2023 06:41:12 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 730BC22DD3; Fri, 27 Jan 2023 03:40:45 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BC9521758; Fri, 27 Jan 2023 03:41:10 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3E5DB3F64C; Fri, 27 Jan 2023 03:40:26 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 14/31] arm64: Add configuration step for Realms Date: Fri, 27 Jan 2023 11:39:15 +0000 Message-Id: <20230127113932.166089-15-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Realm must be configured before it is created. Add the step to specify the parameters for the Realm. Signed-off-by: Suzuki K Poulose --- arm/aarch64/realm.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arm/aarch64/realm.c b/arm/aarch64/realm.c index 3a4adb66..31543e55 100644 --- a/arm/aarch64/realm.c +++ b/arm/aarch64/realm.c @@ -2,6 +2,29 @@ #include + +static void realm_configure_hash_algo(struct kvm *kvm) +{ + struct kvm_cap_arm_rme_config_item hash_algo_cfg = { + .cfg = KVM_CAP_ARM_RME_CFG_HASH_ALGO, + .hash_algo = kvm->arch.measurement_algo, + }; + + struct kvm_enable_cap rme_config = { + .cap = KVM_CAP_ARM_RME, + .args[0] = KVM_CAP_ARM_RME_CONFIG_REALM, + .args[1] = (u64)&hash_algo_cfg, + }; + + if (ioctl(kvm->vm_fd, KVM_ENABLE_CAP, &rme_config) < 0) + die_perror("KVM_CAP_RME(KVM_CAP_ARM_RME_CONFIG_REALM) hash_algo"); +} + +static void realm_configure_parameters(struct kvm *kvm) +{ + realm_configure_hash_algo(kvm); +} + void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm) { struct kvm_enable_cap rme_create_rd = { @@ -9,6 +32,7 @@ void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm) .args[0] = KVM_CAP_ARM_RME_CREATE_RD, }; + realm_configure_parameters(kvm); if (ioctl(kvm->vm_fd, KVM_ENABLE_CAP, &rme_create_rd) < 0) die_perror("KVM_CAP_RME(KVM_CAP_ARM_RME_CREATE_RD)"); } From patchwork Fri Jan 27 11:39:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118607 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94F49C61DB3 for ; Fri, 27 Jan 2023 12:20:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232525AbjA0MUA (ORCPT ); Fri, 27 Jan 2023 07:20:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233541AbjA0MT3 (ORCPT ); Fri, 27 Jan 2023 07:19:29 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 349088324C; Fri, 27 Jan 2023 04:16:08 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 95E9C175D; Fri, 27 Jan 2023 03:41:13 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 186843F64C; Fri, 27 Jan 2023 03:40:28 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 15/31] arm64: Add support for Realm Personalisation Value Date: Fri, 27 Jan 2023 11:39:16 +0000 Message-Id: <20230127113932.166089-16-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add option to specify Realm personalisation value Signed-off-by: Suzuki K Poulose --- arm/aarch64/include/kvm/kvm-config-arch.h | 6 +++++- arm/aarch64/kvm.c | 7 +++++++ arm/aarch64/realm.c | 23 +++++++++++++++++++++++ arm/include/arm-common/kvm-config-arch.h | 1 + 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/arm/aarch64/include/kvm/kvm-config-arch.h b/arm/aarch64/include/kvm/kvm-config-arch.h index b93999b6..f2e659ad 100644 --- a/arm/aarch64/include/kvm/kvm-config-arch.h +++ b/arm/aarch64/include/kvm/kvm-config-arch.h @@ -26,7 +26,11 @@ int vcpu_affinity_parser(const struct option *opt, const char *arg, int unset); "Create VM running in a realm using Arm RME"), \ OPT_STRING('\0', "measurement-algo", &(cfg)->measurement_algo, \ "sha256, sha512", \ - "Realm Measurement algorithm, default: sha256"), + "Realm Measurement algorithm, default: sha256"),\ + OPT_STRING('\0', "realm-pv", &(cfg)->realm_pv, \ + "personalisation value", \ + "Personalisation Value (only) for Realm VMs"), + #include "arm-common/kvm-config-arch.h" diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index a5a98b2e..4798e359 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -56,6 +56,8 @@ static void validate_realm_cfg(struct kvm *kvm) if (!kvm->cfg.arch.is_realm) { if (kvm->cfg.arch.measurement_algo) die("--measurement-algo valid only with --realm"); + if (kvm->cfg.arch.realm_pv) + die("--realm-pv valid only with --realm"); return; } @@ -74,6 +76,11 @@ static void validate_realm_cfg(struct kvm *kvm) kvm->arch.measurement_algo = KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA256; } + if (kvm->cfg.arch.realm_pv) { + if (strlen(kvm->cfg.arch.realm_pv) > KVM_CAP_ARM_RME_RPV_SIZE) + die("Invalid size for Realm Personalization Value\n"); + } + die("Realms not supported"); } diff --git a/arm/aarch64/realm.c b/arm/aarch64/realm.c index 31543e55..2e0be982 100644 --- a/arm/aarch64/realm.c +++ b/arm/aarch64/realm.c @@ -20,9 +20,32 @@ static void realm_configure_hash_algo(struct kvm *kvm) die_perror("KVM_CAP_RME(KVM_CAP_ARM_RME_CONFIG_REALM) hash_algo"); } +static void realm_configure_rpv(struct kvm *kvm) +{ + struct kvm_cap_arm_rme_config_item rpv_cfg = { + .cfg = KVM_CAP_ARM_RME_CFG_RPV, + }; + + struct kvm_enable_cap rme_config = { + .cap = KVM_CAP_ARM_RME, + .args[0] = KVM_CAP_ARM_RME_CONFIG_REALM, + .args[1] = (u64)&rpv_cfg, + }; + + if (!kvm->cfg.arch.realm_pv) + return; + + memset(&rpv_cfg.rpv, 0, sizeof(rpv_cfg.rpv)); + memcpy(&rpv_cfg.rpv, kvm->cfg.arch.realm_pv, strlen(kvm->cfg.arch.realm_pv)); + + if (ioctl(kvm->vm_fd, KVM_ENABLE_CAP, &rme_config) < 0) + die_perror("KVM_CAP_RME(KVM_CAP_ARM_RME_CONFIG_REALM) RPV"); +} + static void realm_configure_parameters(struct kvm *kvm) { realm_configure_hash_algo(kvm); + realm_configure_rpv(kvm); } void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm) diff --git a/arm/include/arm-common/kvm-config-arch.h b/arm/include/arm-common/kvm-config-arch.h index a2faa3af..80a3b18e 100644 --- a/arm/include/arm-common/kvm-config-arch.h +++ b/arm/include/arm-common/kvm-config-arch.h @@ -7,6 +7,7 @@ struct kvm_config_arch { const char *dump_dtb_filename; const char *vcpu_affinity; const char *measurement_algo; + const char *realm_pv; unsigned int force_cntfrq; bool virtio_trans_pci; bool aarch32_guest; From patchwork Fri Jan 27 11:39:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118462 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FF3DC38142 for ; Fri, 27 Jan 2023 11:42:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233907AbjA0LmA (ORCPT ); Fri, 27 Jan 2023 06:42:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232834AbjA0Ll2 (ORCPT ); Fri, 27 Jan 2023 06:41:28 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E971C78ACD; Fri, 27 Jan 2023 03:41:05 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6EDC71763; Fri, 27 Jan 2023 03:41:16 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E5B2D3F64C; Fri, 27 Jan 2023 03:40:31 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 16/31] arm64: Add support for specifying the SVE vector length for Realm Date: Fri, 27 Jan 2023 11:39:17 +0000 Message-Id: <20230127113932.166089-17-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add option to specify SVE vector length for realms. Signed-off-by: Suzuki K Poulose --- arm/aarch64/include/kvm/kvm-config-arch.h | 6 ++++-- arm/aarch64/kvm.c | 23 +++++++++++++++++++++++ arm/aarch64/realm.c | 21 +++++++++++++++++++++ arm/include/arm-common/kvm-arch.h | 1 + arm/include/arm-common/kvm-config-arch.h | 1 + 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/arm/aarch64/include/kvm/kvm-config-arch.h b/arm/aarch64/include/kvm/kvm-config-arch.h index f2e659ad..0f42c2c2 100644 --- a/arm/aarch64/include/kvm/kvm-config-arch.h +++ b/arm/aarch64/include/kvm/kvm-config-arch.h @@ -29,8 +29,10 @@ int vcpu_affinity_parser(const struct option *opt, const char *arg, int unset); "Realm Measurement algorithm, default: sha256"),\ OPT_STRING('\0', "realm-pv", &(cfg)->realm_pv, \ "personalisation value", \ - "Personalisation Value (only) for Realm VMs"), - + "Personalisation Value (only) for Realm VMs"), \ + OPT_U64('\0', "sve-vl", &(cfg)->sve_vl, \ + "SVE Vector Length the VM" \ + "(only supported for Realms)"), #include "arm-common/kvm-config-arch.h" diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index 4798e359..fca1410b 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -51,13 +51,19 @@ static void validate_mem_cfg(struct kvm *kvm) } } +#define SVE_VL_ALIGN 128 + static void validate_realm_cfg(struct kvm *kvm) { + u32 sve_vl; + if (!kvm->cfg.arch.is_realm) { if (kvm->cfg.arch.measurement_algo) die("--measurement-algo valid only with --realm"); if (kvm->cfg.arch.realm_pv) die("--realm-pv valid only with --realm"); + if (kvm->cfg.arch.sve_vl) + die("--sve-vl valid only with --realm"); return; } @@ -76,6 +82,23 @@ static void validate_realm_cfg(struct kvm *kvm) kvm->arch.measurement_algo = KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA256; } + sve_vl = kvm->cfg.arch.sve_vl; + if (sve_vl) { + if (kvm->cfg.arch.disable_sve) + die("SVE VL requested when SVE is disabled"); + if (!IS_ALIGNED(sve_vl, SVE_VL_ALIGN)) + die("SVE VL is not aligned to %dbit\n", SVE_VL_ALIGN); + kvm->arch.sve_vq = (sve_vl / SVE_VL_ALIGN) - 1; + } else { + /* + * Disable SVE for Realms, if a VL is not requested. + * The SVE VL will be measured as part of the parameter + * and we do not want to add an unknown entity to the + * measurement. + */ + kvm->cfg.arch.disable_sve = true; + } + if (kvm->cfg.arch.realm_pv) { if (strlen(kvm->cfg.arch.realm_pv) > KVM_CAP_ARM_RME_RPV_SIZE) die("Invalid size for Realm Personalization Value\n"); diff --git a/arm/aarch64/realm.c b/arm/aarch64/realm.c index 2e0be982..fc7f8d6a 100644 --- a/arm/aarch64/realm.c +++ b/arm/aarch64/realm.c @@ -42,10 +42,31 @@ static void realm_configure_rpv(struct kvm *kvm) die_perror("KVM_CAP_RME(KVM_CAP_ARM_RME_CONFIG_REALM) RPV"); } +static void realm_configure_sve(struct kvm *kvm) +{ + struct kvm_cap_arm_rme_config_item sve_cfg = { + .cfg = KVM_CAP_ARM_RME_CFG_SVE, + .sve_vq = kvm->arch.sve_vq, + }; + + struct kvm_enable_cap rme_config = { + .cap = KVM_CAP_ARM_RME, + .args[0] = KVM_CAP_ARM_RME_CONFIG_REALM, + .args[1] = (u64)&sve_cfg, + }; + + if (kvm->cfg.arch.disable_sve) + return; + + if (ioctl(kvm->vm_fd, KVM_ENABLE_CAP, &rme_config) < 0) + die_perror("KVM_CAP_RME(KVM_CAP_ARM_RME_CONFIG_REALM) SVE"); +} + static void realm_configure_parameters(struct kvm *kvm) { realm_configure_hash_algo(kvm); realm_configure_rpv(kvm); + realm_configure_sve(kvm); } void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm) diff --git a/arm/include/arm-common/kvm-arch.h b/arm/include/arm-common/kvm-arch.h index 68224b1c..41b31f11 100644 --- a/arm/include/arm-common/kvm-arch.h +++ b/arm/include/arm-common/kvm-arch.h @@ -114,6 +114,7 @@ struct kvm_arch { cpu_set_t *vcpu_affinity_cpuset; u64 measurement_algo; + u64 sve_vq; }; #endif /* ARM_COMMON__KVM_ARCH_H */ diff --git a/arm/include/arm-common/kvm-config-arch.h b/arm/include/arm-common/kvm-config-arch.h index 80a3b18e..d923fd9e 100644 --- a/arm/include/arm-common/kvm-config-arch.h +++ b/arm/include/arm-common/kvm-config-arch.h @@ -19,6 +19,7 @@ struct kvm_config_arch { u64 fw_addr; bool no_pvtime; bool disable_sve; + u64 sve_vl; }; int irqchip_parser(const struct option *opt, const char *arg, int unset); From patchwork Fri Jan 27 11:39:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118463 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CD6AC61DA7 for ; Fri, 27 Jan 2023 11:42:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233933AbjA0LmC (ORCPT ); Fri, 27 Jan 2023 06:42:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233513AbjA0Ll2 (ORCPT ); Fri, 27 Jan 2023 06:41:28 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2D2FF78AEB; Fri, 27 Jan 2023 03:41:06 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 480471576; Fri, 27 Jan 2023 03:41:19 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BEBA93F64C; Fri, 27 Jan 2023 03:40:34 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 17/31] arm: Add kernel size to VM context Date: Fri, 27 Jan 2023 11:39:18 +0000 Message-Id: <20230127113932.166089-18-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Alexandru Elisei Add the kernel image size to the VM context, as we are going to use it later. This matches what we already do with the initrd. Signed-off-by: Alexandru Elisei [Fix kernel size printed in debug messages] Signed-off-by: Suzuki K Poulose --- arm/include/arm-common/kvm-arch.h | 1 + arm/kvm.c | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/arm/include/arm-common/kvm-arch.h b/arm/include/arm-common/kvm-arch.h index 41b31f11..b5a4b851 100644 --- a/arm/include/arm-common/kvm-arch.h +++ b/arm/include/arm-common/kvm-arch.h @@ -108,6 +108,7 @@ struct kvm_arch { */ u64 memory_guest_start; u64 kern_guest_start; + u64 kern_size; u64 initrd_guest_start; u64 initrd_size; u64 dtb_guest_start; diff --git a/arm/kvm.c b/arm/kvm.c index 2510a322..acb627b2 100644 --- a/arm/kvm.c +++ b/arm/kvm.c @@ -153,7 +153,6 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd, limit = kvm->ram_start + min(kvm->ram_size, (u64)SZ_256M) - 1; pos = kvm->ram_start + kvm__arch_get_kern_offset(kvm, fd_kernel); - kvm->arch.kern_guest_start = host_to_guest_flat(kvm, pos); file_size = read_file(fd_kernel, pos, limit - pos); if (file_size < 0) { if (errno == ENOMEM) @@ -161,9 +160,12 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd, die_perror("kernel read"); } + + kvm->arch.kern_guest_start = host_to_guest_flat(kvm, pos); + kvm->arch.kern_size = file_size; kernel_end = pos + file_size; - pr_debug("Loaded kernel to 0x%llx (%zd bytes)", - kvm->arch.kern_guest_start, file_size); + pr_debug("Loaded kernel to 0x%llx (%llu bytes)", + kvm->arch.kern_guest_start, kvm->arch.kern_size); /* * Now load backwards from the end of memory so the kernel From patchwork Fri Jan 27 11:39:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118608 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A51AFC61DA7 for ; Fri, 27 Jan 2023 12:20:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233092AbjA0MUB (ORCPT ); Fri, 27 Jan 2023 07:20:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231909AbjA0MTk (ORCPT ); Fri, 27 Jan 2023 07:19:40 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 379C684976; Fri, 27 Jan 2023 04:16:14 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2199715DB; Fri, 27 Jan 2023 03:41:22 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 980F33F64C; Fri, 27 Jan 2023 03:40:37 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 18/31] arm64: Populate initial realm contents Date: Fri, 27 Jan 2023 11:39:19 +0000 Message-Id: <20230127113932.166089-19-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Alexandru Elisei Populate the realm memory with the initial contents, which include the device tree blob, the kernel image, and initrd, if specified, or the firmware image. Populating an image in the realm involves two steps: a) Mark the IPA area as RAM - INIT_IPA_REALM b) Load the contents into the IPA - POPULATE_REALM Wherever we know the actual size of an image in memory, we make sure the "memory area" is initialised to RAM. e.g., Linux kernel image size from the header which includes the bss etc. The "file size" on disk for the Linux image is much smaller. We mark the region of size Image.header.size as RAM (a), from the kernel load address. And load the Image file into the memory (b) above. At the moment we only detect the Arm64 Linux Image header format. Since we're already touching the code that copies the initrd in guest memory, let's do a bit of cleaning and remove a useless local variable. Signed-off-by: Alexandru Elisei [ Make sure the Linux kernel image area is marked as RAM ] Signed-off-by: Suzuki K Poulose --- arm/aarch32/include/asm/realm.h | 3 + arm/aarch64/include/asm/realm.h | 3 + arm/aarch64/realm.c | 112 ++++++++++++++++++++++++++++++++ arm/fdt.c | 6 ++ arm/kvm.c | 20 ++++-- include/linux/kernel.h | 1 + 6 files changed, 140 insertions(+), 5 deletions(-) diff --git a/arm/aarch32/include/asm/realm.h b/arm/aarch32/include/asm/realm.h index 5aca6cca..fcff0e55 100644 --- a/arm/aarch32/include/asm/realm.h +++ b/arm/aarch32/include/asm/realm.h @@ -6,5 +6,8 @@ #include "kvm/kvm.h" static inline void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm) {} +static inline void kvm_arm_realm_populate_kernel(struct kvm *kvm) {} +static inline void kvm_arm_realm_populate_initrd(struct kvm *kvm) {} +static inline void kvm_arm_realm_populate_dtb(struct kvm *kvm) {} #endif /* ! __ASM_REALM_H */ diff --git a/arm/aarch64/include/asm/realm.h b/arm/aarch64/include/asm/realm.h index e176f15f..6e760ac9 100644 --- a/arm/aarch64/include/asm/realm.h +++ b/arm/aarch64/include/asm/realm.h @@ -6,5 +6,8 @@ #include "kvm/kvm.h" void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm); +void kvm_arm_realm_populate_kernel(struct kvm *kvm); +void kvm_arm_realm_populate_initrd(struct kvm *kvm); +void kvm_arm_realm_populate_dtb(struct kvm *kvm); #endif /* ! __ASM_REALM_H */ diff --git a/arm/aarch64/realm.c b/arm/aarch64/realm.c index fc7f8d6a..eddccece 100644 --- a/arm/aarch64/realm.c +++ b/arm/aarch64/realm.c @@ -1,5 +1,7 @@ #include "kvm/kvm.h" +#include +#include #include @@ -80,3 +82,113 @@ void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm) if (ioctl(kvm->vm_fd, KVM_ENABLE_CAP, &rme_create_rd) < 0) die_perror("KVM_CAP_RME(KVM_CAP_ARM_RME_CREATE_RD)"); } + +static void realm_init_ipa_range(struct kvm *kvm, u64 start, u64 size) +{ + struct kvm_cap_arm_rme_init_ipa_args init_ipa_args = { + .init_ipa_base = start, + .init_ipa_size = size + }; + struct kvm_enable_cap rme_init_ipa_realm = { + .cap = KVM_CAP_ARM_RME, + .args[0] = KVM_CAP_ARM_RME_INIT_IPA_REALM, + .args[1] = (u64)&init_ipa_args + }; + + if (ioctl(kvm->vm_fd, KVM_ENABLE_CAP, &rme_init_ipa_realm) < 0) + die("unable to intialise IPA range for Realm %llx - %llx (size %llu)", + start, start + size, size); + +} + +static void __realm_populate(struct kvm *kvm, u64 start, u64 size) +{ + struct kvm_cap_arm_rme_populate_realm_args populate_args = { + .populate_ipa_base = start, + .populate_ipa_size = size + }; + struct kvm_enable_cap rme_populate_realm = { + .cap = KVM_CAP_ARM_RME, + .args[0] = KVM_CAP_ARM_RME_POPULATE_REALM, + .args[1] = (u64)&populate_args + }; + + if (ioctl(kvm->vm_fd, KVM_ENABLE_CAP, &rme_populate_realm) < 0) + die("unable to populate Realm memory %llx - %llx (size %llu)", + start, start + size, size); +} + +static void realm_populate(struct kvm *kvm, u64 start, u64 size) +{ + realm_init_ipa_range(kvm, start, size); + __realm_populate(kvm, start, size); +} + +static bool is_arm64_linux_kernel_image(void *header) +{ + struct arm64_image_header *hdr = header; + + return memcmp(&hdr->magic, ARM64_IMAGE_MAGIC, sizeof(hdr->magic)) == 0; +} + +static ssize_t arm64_linux_kernel_image_size(void *header) +{ + struct arm64_image_header *hdr = header; + + if (is_arm64_linux_kernel_image(header)) + return le64_to_cpu(hdr->image_size); + die("Not arm64 Linux kernel Image"); +} + +void kvm_arm_realm_populate_kernel(struct kvm *kvm) +{ + u64 start, end, mem_size; + void *header = guest_flat_to_host(kvm, kvm->arch.kern_guest_start); + + start = ALIGN_DOWN(kvm->arch.kern_guest_start, SZ_4K); + end = ALIGN(kvm->arch.kern_guest_start + kvm->arch.kern_size, SZ_4K); + + if (is_arm64_linux_kernel_image(header)) + mem_size = arm64_linux_kernel_image_size(header); + else + mem_size = end - start; + + realm_init_ipa_range(kvm, start, mem_size); + __realm_populate(kvm, start, end - start); +} + +void kvm_arm_realm_populate_initrd(struct kvm *kvm) +{ + u64 kernel_end, start, end; + + kernel_end = ALIGN(kvm->arch.kern_guest_start + kvm->arch.kern_size, SZ_4K); + start = ALIGN_DOWN(kvm->arch.initrd_guest_start, SZ_4K); + /* + * Because we align the initrd to 4 bytes, it is theoretically possible + * for the start of the initrd to overlap with the same page where the + * kernel ends. + */ + if (start < kernel_end) + start = kernel_end; + end = ALIGN(kvm->arch.initrd_guest_start + kvm->arch.initrd_size, SZ_4K); + if (end > start) + realm_populate(kvm, start, end - start); +} + +void kvm_arm_realm_populate_dtb(struct kvm *kvm) +{ + u64 initrd_end, start, end; + + initrd_end = ALIGN(kvm->arch.initrd_guest_start + kvm->arch.initrd_size, SZ_4K); + start = ALIGN_DOWN(kvm->arch.dtb_guest_start, SZ_4K); + /* + * Same situation as with the initrd, but now it is the DTB which is + * overlapping with the last page of the initrd, because the initrd is + * populated first. + */ + if (start < initrd_end) + start = initrd_end; + end = ALIGN(kvm->arch.dtb_guest_start + FDT_MAX_SIZE, SZ_4K); + if (end > start) + realm_populate(kvm, start, end - start); +} diff --git a/arm/fdt.c b/arm/fdt.c index 286ccadf..762a604d 100644 --- a/arm/fdt.c +++ b/arm/fdt.c @@ -7,6 +7,8 @@ #include "arm-common/gic.h" #include "arm-common/pci.h" +#include + #include #include @@ -231,6 +233,10 @@ static int setup_fdt(struct kvm *kvm) if (kvm->cfg.arch.dump_dtb_filename) dump_fdt(kvm->cfg.arch.dump_dtb_filename, fdt_dest); + + if (kvm->cfg.arch.is_realm) + kvm_arm_realm_populate_dtb(kvm); + return 0; } late_init(setup_fdt); diff --git a/arm/kvm.c b/arm/kvm.c index acb627b2..57c5b5f7 100644 --- a/arm/kvm.c +++ b/arm/kvm.c @@ -6,6 +6,7 @@ #include "kvm/fdt.h" #include "arm-common/gic.h" +#include #include @@ -167,6 +168,9 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd, pr_debug("Loaded kernel to 0x%llx (%llu bytes)", kvm->arch.kern_guest_start, kvm->arch.kern_size); + if (kvm->cfg.arch.is_realm) + kvm_arm_realm_populate_kernel(kvm); + /* * Now load backwards from the end of memory so the kernel * decompressor has plenty of space to work with. First up is @@ -188,7 +192,6 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd, /* ... and finally the initrd, if we have one. */ if (fd_initrd != -1) { struct stat sb; - unsigned long initrd_start; if (fstat(fd_initrd, &sb)) die_perror("fstat"); @@ -199,7 +202,6 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd, if (pos < kernel_end) die("initrd overlaps with kernel image."); - initrd_start = guest_addr; file_size = read_file(fd_initrd, pos, limit - pos); if (file_size == -1) { if (errno == ENOMEM) @@ -208,11 +210,13 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd, die_perror("initrd read"); } - kvm->arch.initrd_guest_start = initrd_start; + kvm->arch.initrd_guest_start = guest_addr; kvm->arch.initrd_size = file_size; pr_debug("Loaded initrd to 0x%llx (%llu bytes)", - kvm->arch.initrd_guest_start, - kvm->arch.initrd_size); + kvm->arch.initrd_guest_start, kvm->arch.initrd_size); + + if (kvm->cfg.arch.is_realm) + kvm_arm_realm_populate_initrd(kvm); } else { kvm->arch.initrd_size = 0; } @@ -269,6 +273,8 @@ bool kvm__load_firmware(struct kvm *kvm, const char *firmware_filename) /* Kernel isn't loaded by kvm, point start address to firmware */ kvm->arch.kern_guest_start = fw_addr; + kvm->arch.kern_size = fw_sz; + pr_debug("Loaded firmware to 0x%llx (%zd bytes)", kvm->arch.kern_guest_start, fw_sz); @@ -283,6 +289,10 @@ bool kvm__load_firmware(struct kvm *kvm, const char *firmware_filename) kvm->arch.dtb_guest_start, kvm->arch.dtb_guest_start + FDT_MAX_SIZE); + if (kvm->cfg.arch.is_realm) + /* We hijack the kernel fields to describe the firmware. */ + kvm_arm_realm_populate_kernel(kvm); + return true; } diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 6c22f1c0..25f19c20 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -9,6 +9,7 @@ #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) +#define ALIGN_DOWN(x,a) __ALIGN_MASK(x - (typeof(x))((a) - 1),(typeof(x))(a)-1) #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) From patchwork Fri Jan 27 11:39:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118464 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB175C38142 for ; Fri, 27 Jan 2023 11:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233951AbjA0LmE (ORCPT ); Fri, 27 Jan 2023 06:42:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232155AbjA0Llf (ORCPT ); Fri, 27 Jan 2023 06:41:35 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 72D5D78AFC; Fri, 27 Jan 2023 03:41:06 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EF4CE2B; Fri, 27 Jan 2023 03:41:24 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 713E03F64C; Fri, 27 Jan 2023 03:40:40 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 19/31] arm64: Don't try to set PSTATE for VCPUs belonging to a realm Date: Fri, 27 Jan 2023 11:39:20 +0000 Message-Id: <20230127113932.166089-20-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Christoffer Dall RME doesn't allow setting the PSTATE but resets it to an architectural value, and KVM also does not allow setting this register from user space, so stop trying to do that. Signed-off-by: Christoffer Dall Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- arm/aarch64/kvm-cpu.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/arm/aarch64/kvm-cpu.c b/arm/aarch64/kvm-cpu.c index e7649239..37f9aa9d 100644 --- a/arm/aarch64/kvm-cpu.c +++ b/arm/aarch64/kvm-cpu.c @@ -92,11 +92,13 @@ static void reset_vcpu_aarch64(struct kvm_cpu *vcpu) reg.addr = (u64)&data; - /* pstate = all interrupts masked */ - data = PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT | PSR_MODE_EL1h; - reg.id = ARM64_CORE_REG(regs.pstate); - if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®) < 0) - die_perror("KVM_SET_ONE_REG failed (spsr[EL1])"); + if (!kvm->cfg.arch.is_realm) { + /* pstate = all interrupts masked */ + data = PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT | PSR_MODE_EL1h; + reg.id = ARM64_CORE_REG(regs.pstate); + if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®) < 0) + die_perror("KVM_SET_ONE_REG failed (PSTATE)"); + } /* x1...x3 = 0 */ data = 0; From patchwork Fri Jan 27 11:39:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118606 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C544C38142 for ; Fri, 27 Jan 2023 12:20:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230044AbjA0MT7 (ORCPT ); Fri, 27 Jan 2023 07:19:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234012AbjA0MT3 (ORCPT ); Fri, 27 Jan 2023 07:19:29 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 387E783251; Fri, 27 Jan 2023 04:16:08 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D149115BF; Fri, 27 Jan 2023 03:41:27 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4AF653F64C; Fri, 27 Jan 2023 03:40:43 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 20/31] arm64: Finalize realm VCPU after reset Date: Fri, 27 Jan 2023 11:39:21 +0000 Message-Id: <20230127113932.166089-21-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Alexandru Elisei In order to run a VCPU belonging to a realm, that VCPU must be in the finalized state. Finalize the CPU after reset, since kvmtool won't be touching the VCPU state afterwards. Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- arm/aarch64/kvm-cpu.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arm/aarch64/kvm-cpu.c b/arm/aarch64/kvm-cpu.c index 37f9aa9d..24e570c4 100644 --- a/arm/aarch64/kvm-cpu.c +++ b/arm/aarch64/kvm-cpu.c @@ -128,6 +128,13 @@ static void reset_vcpu_aarch64(struct kvm_cpu *vcpu) if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®) < 0) die_perror("KVM_SET_ONE_REG failed (pc)"); } + + if (kvm->cfg.arch.is_realm) { + int feature = KVM_ARM_VCPU_REC; + + if (ioctl(vcpu->vcpu_fd, KVM_ARM_VCPU_FINALIZE, &feature) < 0) + die_perror("KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_REC)"); + } } void kvm_cpu__select_features(struct kvm *kvm, struct kvm_vcpu_init *init) From patchwork Fri Jan 27 11:39:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118599 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26132C38142 for ; Fri, 27 Jan 2023 12:16:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233408AbjA0MQH (ORCPT ); Fri, 27 Jan 2023 07:16:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232851AbjA0MPq (ORCPT ); Fri, 27 Jan 2023 07:15:46 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E546B8627B; Fri, 27 Jan 2023 04:11:17 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AAE681650; Fri, 27 Jan 2023 03:41:30 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2D7A03F64C; Fri, 27 Jan 2023 03:40:46 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 21/31] init: Add last_{init, exit} list macros Date: Fri, 27 Jan 2023 11:39:22 +0000 Message-Id: <20230127113932.166089-22-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Alexandru Elisei Add a last_init macro for constructor functions that will be executed last in the initialization process. Add a symmetrical macro, last_exit, for destructor functions that will be the last to be executed when kvmtool exits. The list priority for the late_{init, exit} macros has been bumped down a spot, but their relative priority remains unchanged, to keep the same size for the init_lists and exit_lists. Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- include/kvm/util-init.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/kvm/util-init.h b/include/kvm/util-init.h index 13d4f04d..e6a0e169 100644 --- a/include/kvm/util-init.h +++ b/include/kvm/util-init.h @@ -39,7 +39,8 @@ static void __attribute__ ((constructor)) __init__##cb(void) \ #define dev_init(cb) __init_list_add(cb, 5) #define virtio_dev_init(cb) __init_list_add(cb, 6) #define firmware_init(cb) __init_list_add(cb, 7) -#define late_init(cb) __init_list_add(cb, 9) +#define late_init(cb) __init_list_add(cb, 8) +#define last_init(cb) __init_list_add(cb, 9) #define core_exit(cb) __exit_list_add(cb, 0) #define base_exit(cb) __exit_list_add(cb, 2) @@ -47,5 +48,6 @@ static void __attribute__ ((constructor)) __init__##cb(void) \ #define dev_exit(cb) __exit_list_add(cb, 5) #define virtio_dev_exit(cb) __exit_list_add(cb, 6) #define firmware_exit(cb) __exit_list_add(cb, 7) -#define late_exit(cb) __exit_list_add(cb, 9) +#define late_exit(cb) __exit_list_add(cb, 8) +#define last_exit(cb) __exit_list_add(cb, 9) #endif From patchwork Fri Jan 27 11:39:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118600 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 341CCC38142 for ; Fri, 27 Jan 2023 12:16:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234133AbjA0MQi (ORCPT ); Fri, 27 Jan 2023 07:16:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233975AbjA0MQT (ORCPT ); Fri, 27 Jan 2023 07:16:19 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F3475A5C8; Fri, 27 Jan 2023 04:11:52 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 85B3D175A; Fri, 27 Jan 2023 03:41:33 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 068563F64C; Fri, 27 Jan 2023 03:40:48 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 22/31] arm64: Activate realm before the first VCPU is run Date: Fri, 27 Jan 2023 11:39:23 +0000 Message-Id: <20230127113932.166089-23-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Alexandru Elisei Before KVM can run a VCPU belong to a realm, the realm be activated. Activating a realm prevents the adding of new object and seals the cryptographic measurement of that realm. The VCPU state is part of the measurement, which means that realm activation must be performed after all VCPUs have been reset. Current RMM implementation can only create RECs in the order of their MPIDRs. VCPUs get assigned MPIDRs by KVM based on their VCPU id. Reset the VCPUs in the order they were created from the main thread instead of doing it from their own thread, which doesn't guarantee any ordering. Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- arm/aarch64/kvm-cpu.c | 4 ++++ arm/aarch64/realm.c | 35 +++++++++++++++++++++++++++++++ arm/include/arm-common/kvm-arch.h | 1 + 3 files changed, 40 insertions(+) diff --git a/arm/aarch64/kvm-cpu.c b/arm/aarch64/kvm-cpu.c index 24e570c4..32fa7609 100644 --- a/arm/aarch64/kvm-cpu.c +++ b/arm/aarch64/kvm-cpu.c @@ -187,6 +187,10 @@ void kvm_cpu__reset_vcpu(struct kvm_cpu *vcpu) cpu_set_t *affinity; int ret; + /* VCPU reset is done before activating the realm. */ + if (kvm->arch.realm_is_active) + return; + affinity = kvm->arch.vcpu_affinity_cpuset; if (affinity) { ret = sched_setaffinity(0, sizeof(cpu_set_t), affinity); diff --git a/arm/aarch64/realm.c b/arm/aarch64/realm.c index eddccece..808d39c5 100644 --- a/arm/aarch64/realm.c +++ b/arm/aarch64/realm.c @@ -1,4 +1,5 @@ #include "kvm/kvm.h" +#include "kvm/kvm-cpu.h" #include #include @@ -192,3 +193,37 @@ void kvm_arm_realm_populate_dtb(struct kvm *kvm) if (end > start) realm_populate(kvm, start, end - start); } + +static void kvm_arm_realm_activate_realm(struct kvm *kvm) +{ + struct kvm_enable_cap activate_realm = { + .cap = KVM_CAP_ARM_RME, + .args[0] = KVM_CAP_ARM_RME_ACTIVATE_REALM, + }; + + if (ioctl(kvm->vm_fd, KVM_ENABLE_CAP, &activate_realm) < 0) + die_perror("KVM_CAP_ARM_RME(KVM_CAP_ARM_RME_ACTIVATE_REALM)"); + + kvm->arch.realm_is_active = true; +} + +static int kvm_arm_realm_finalize(struct kvm *kvm) +{ + int i; + + if (!kvm->cfg.arch.is_realm) + return 0; + + /* + * VCPU reset must happen before the realm is activated, because their + * state is part of the cryptographic measurement for the realm. + */ + for (i = 0; i < kvm->nrcpus; i++) + kvm_cpu__reset_vcpu(kvm->cpus[i]); + + /* Activate and seal the measurement for the realm. */ + kvm_arm_realm_activate_realm(kvm); + + return 0; +} +last_init(kvm_arm_realm_finalize) diff --git a/arm/include/arm-common/kvm-arch.h b/arm/include/arm-common/kvm-arch.h index b5a4b851..6d48e13c 100644 --- a/arm/include/arm-common/kvm-arch.h +++ b/arm/include/arm-common/kvm-arch.h @@ -116,6 +116,7 @@ struct kvm_arch { cpu_set_t *vcpu_affinity_cpuset; u64 measurement_algo; u64 sve_vq; + bool realm_is_active; }; #endif /* ARM_COMMON__KVM_ARCH_H */ From patchwork Fri Jan 27 11:39:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118468 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AD33C38142 for ; Fri, 27 Jan 2023 11:42:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233912AbjA0LmN (ORCPT ); Fri, 27 Jan 2023 06:42:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233870AbjA0Llo (ORCPT ); Fri, 27 Jan 2023 06:41:44 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DFAFA7264A; Fri, 27 Jan 2023 03:41:10 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 68CBE1595; Fri, 27 Jan 2023 03:41:36 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D6C173F64C; Fri, 27 Jan 2023 03:40:51 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 23/31] arm64: Specify SMC as the PSCI conduits for realms Date: Fri, 27 Jan 2023 11:39:24 +0000 Message-Id: <20230127113932.166089-24-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Christoffer Dall This lets the VM use the RMM implementation for PSCI. Signed-off-by: Christoffer Dall Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- arm/fdt.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arm/fdt.c b/arm/fdt.c index 762a604d..c46ff410 100644 --- a/arm/fdt.c +++ b/arm/fdt.c @@ -208,7 +208,14 @@ static int setup_fdt(struct kvm *kvm) _FDT(fdt_property_string(fdt, "compatible", "arm,psci")); fns = &psci_0_1_fns; } - _FDT(fdt_property_string(fdt, "method", "hvc")); + + + if (kvm->cfg.arch.is_realm) { + _FDT(fdt_property_string(fdt, "method", "smc")); + } else { + _FDT(fdt_property_string(fdt, "method", "hvc")); + } + _FDT(fdt_property_cell(fdt, "cpu_suspend", fns->cpu_suspend)); _FDT(fdt_property_cell(fdt, "cpu_off", fns->cpu_off)); _FDT(fdt_property_cell(fdt, "cpu_on", fns->cpu_on)); From patchwork Fri Jan 27 11:39:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118470 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23003C38142 for ; Fri, 27 Jan 2023 11:42:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233961AbjA0LmR (ORCPT ); Fri, 27 Jan 2023 06:42:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233825AbjA0Llp (ORCPT ); Fri, 27 Jan 2023 06:41:45 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 00A527AE7F; Fri, 27 Jan 2023 03:41:10 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4B9CB1762; Fri, 27 Jan 2023 03:41:39 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B8BF43F8D6; Fri, 27 Jan 2023 03:40:54 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 24/31] arm64: Don't try to debug a realm Date: Fri, 27 Jan 2023 11:39:25 +0000 Message-Id: <20230127113932.166089-25-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Alexandru Elisei Don't read the register values for a running realm, because they don't reflect the actual hardware state of a realm. And don't try to read realm memory, because that will promptly lead to kvmtool being killed. Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- arm/aarch64/kvm-cpu.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arm/aarch64/kvm-cpu.c b/arm/aarch64/kvm-cpu.c index 32fa7609..a29a3413 100644 --- a/arm/aarch64/kvm-cpu.c +++ b/arm/aarch64/kvm-cpu.c @@ -250,6 +250,9 @@ void kvm_cpu__show_code(struct kvm_cpu *vcpu) reg.addr = (u64)&data; + if (vcpu->kvm->cfg.arch.is_realm) + return; + dprintf(debug_fd, "\n*pc:\n"); reg.id = ARM64_CORE_REG(regs.pc); if (ioctl(vcpu->vcpu_fd, KVM_GET_ONE_REG, ®) < 0) @@ -274,6 +277,11 @@ void kvm_cpu__show_registers(struct kvm_cpu *vcpu) reg.addr = (u64)&data; dprintf(debug_fd, "\n Registers:\n"); + if (vcpu->kvm->cfg.arch.is_realm) { + dprintf(debug_fd, " UNACCESSIBLE\n"); + return; + } + reg.id = ARM64_CORE_REG(regs.pc); if (ioctl(vcpu->vcpu_fd, KVM_GET_ONE_REG, ®) < 0) die("KVM_GET_ONE_REG failed (pc)"); From patchwork Fri Jan 27 11:39:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118478 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62C9AC54EAA for ; Fri, 27 Jan 2023 11:43:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232958AbjA0Lnu (ORCPT ); Fri, 27 Jan 2023 06:43:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234032AbjA0Lnd (ORCPT ); Fri, 27 Jan 2023 06:43:33 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 33B737C313; Fri, 27 Jan 2023 03:42:13 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2D1C71764; Fri, 27 Jan 2023 03:41:42 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9B35E3F64C; Fri, 27 Jan 2023 03:40:57 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 25/31] arm64: realm: Double the IPA space Date: Fri, 27 Jan 2023 11:39:26 +0000 Message-Id: <20230127113932.166089-26-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The Realm's IPA space is divided into 2 halves. Protected (lower half) and Unprotected (upper half). KVM implements aliasing of the IPA, where the unprotected IPA is alias of the corresponding protected ipa. Thus we must double the IPA space required for a given VM. Signed-off-by: Suzuki K Poulose --- arm/aarch64/kvm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index fca1410b..344c568b 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -189,6 +189,9 @@ int kvm__get_vm_type(struct kvm *kvm) /* Otherwise, compute the minimal required IPA size */ max_ipa = kvm->cfg.ram_addr + kvm->cfg.ram_size - 1; ipa_bits = max(32, fls_long(max_ipa)); + /* Realm needs double the IPA space */ + if (kvm->cfg.arch.is_realm) + ipa_bits++; pr_debug("max_ipa %lx ipa_bits %d max_ipa_bits %d", max_ipa, ipa_bits, max_ipa_bits); From patchwork Fri Jan 27 11:39:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118472 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12EA4C61DA7 for ; Fri, 27 Jan 2023 11:42:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232638AbjA0Lmp (ORCPT ); Fri, 27 Jan 2023 06:42:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233879AbjA0LmA (ORCPT ); Fri, 27 Jan 2023 06:42:00 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3586270D7E; Fri, 27 Jan 2023 03:41:28 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 06657176A; Fri, 27 Jan 2023 03:41:45 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7CD023F64C; Fri, 27 Jan 2023 03:41:00 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 26/31] virtio: Add a wrapper for get_host_features Date: Fri, 27 Jan 2023 11:39:27 +0000 Message-Id: <20230127113932.166089-27-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add a wrapper to the vdev->ops->get_host_features() to allow setting platform specific flags outside the device Signed-off-by: Suzuki K Poulose --- include/kvm/virtio.h | 2 ++ virtio/core.c | 5 +++++ virtio/mmio-legacy.c | 2 +- virtio/mmio-modern.c | 2 +- virtio/pci-legacy.c | 2 +- virtio/pci-modern.c | 2 +- 6 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/kvm/virtio.h b/include/kvm/virtio.h index 94bddefe..e95cfad5 100644 --- a/include/kvm/virtio.h +++ b/include/kvm/virtio.h @@ -248,4 +248,6 @@ void virtio_set_guest_features(struct kvm *kvm, struct virtio_device *vdev, void virtio_notify_status(struct kvm *kvm, struct virtio_device *vdev, void *dev, u8 status); +u64 virtio_dev_get_host_features(struct virtio_device *vdev, struct kvm *kvm, void *dev); + #endif /* KVM__VIRTIO_H */ diff --git a/virtio/core.c b/virtio/core.c index ea0e5b65..50e7f86d 100644 --- a/virtio/core.c +++ b/virtio/core.c @@ -283,6 +283,11 @@ void virtio_notify_status(struct kvm *kvm, struct virtio_device *vdev, vdev->ops->notify_status(kvm, dev, ext_status); } +u64 virtio_dev_get_host_features(struct virtio_device *vdev, struct kvm *kvm, void *dev) +{ + return vdev->ops->get_host_features(kvm, dev); +} + bool virtio_access_config(struct kvm *kvm, struct virtio_device *vdev, void *dev, unsigned long offset, void *data, size_t size, bool is_write) diff --git a/virtio/mmio-legacy.c b/virtio/mmio-legacy.c index 7ca7e69f..42673236 100644 --- a/virtio/mmio-legacy.c +++ b/virtio/mmio-legacy.c @@ -26,7 +26,7 @@ static void virtio_mmio_config_in(struct kvm_cpu *vcpu, break; case VIRTIO_MMIO_DEVICE_FEATURES: if (vmmio->hdr.host_features_sel == 0) - val = vdev->ops->get_host_features(vmmio->kvm, + val = virtio_dev_get_host_features(vdev, vmmio->kvm, vmmio->dev); ioport__write32(data, val); break; diff --git a/virtio/mmio-modern.c b/virtio/mmio-modern.c index 6c0bb382..a09fa8e9 100644 --- a/virtio/mmio-modern.c +++ b/virtio/mmio-modern.c @@ -26,7 +26,7 @@ static void virtio_mmio_config_in(struct kvm_cpu *vcpu, case VIRTIO_MMIO_DEVICE_FEATURES: if (vmmio->hdr.host_features_sel > 1) break; - features |= vdev->ops->get_host_features(vmmio->kvm, vmmio->dev); + features |= virtio_dev_get_host_features(vdev, vmmio->kvm, vmmio->dev); val = features >> (32 * vmmio->hdr.host_features_sel); break; case VIRTIO_MMIO_QUEUE_NUM_MAX: diff --git a/virtio/pci-legacy.c b/virtio/pci-legacy.c index 58047967..d5f5dee7 100644 --- a/virtio/pci-legacy.c +++ b/virtio/pci-legacy.c @@ -44,7 +44,7 @@ static bool virtio_pci__data_in(struct kvm_cpu *vcpu, struct virtio_device *vdev switch (offset) { case VIRTIO_PCI_HOST_FEATURES: - val = vdev->ops->get_host_features(kvm, vpci->dev); + val = virtio_dev_get_host_features(vdev, kvm, vpci->dev); ioport__write32(data, val); break; case VIRTIO_PCI_QUEUE_PFN: diff --git a/virtio/pci-modern.c b/virtio/pci-modern.c index c5b4bc50..2c5bf3f8 100644 --- a/virtio/pci-modern.c +++ b/virtio/pci-modern.c @@ -158,7 +158,7 @@ static bool virtio_pci__common_read(struct virtio_device *vdev, case VIRTIO_PCI_COMMON_DF: if (vpci->device_features_sel > 1) break; - features |= vdev->ops->get_host_features(vpci->kvm, vpci->dev); + features |= virtio_dev_get_host_features(vdev, vpci->kvm, vpci->dev); val = features >> (32 * vpci->device_features_sel); ioport__write32(data, val); break; From patchwork Fri Jan 27 11:39:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118473 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B91DC54EAA for ; Fri, 27 Jan 2023 11:42:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233209AbjA0Lmr (ORCPT ); Fri, 27 Jan 2023 06:42:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233903AbjA0LmA (ORCPT ); Fri, 27 Jan 2023 06:42:00 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8AEF372659; Fri, 27 Jan 2023 03:41:28 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D6C8F1684; Fri, 27 Jan 2023 03:41:47 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 561883F64C; Fri, 27 Jan 2023 03:41:03 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 27/31] virtio: Add arch specific hook for virtio host flags Date: Fri, 27 Jan 2023 11:39:28 +0000 Message-Id: <20230127113932.166089-28-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add callbacks for archs to provide virtio host flags. Signed-off-by: Suzuki K Poulose --- arm/aarch32/kvm.c | 5 +++++ arm/aarch64/kvm.c | 5 +++++ include/kvm/kvm.h | 2 ++ mips/kvm.c | 5 +++++ powerpc/kvm.c | 5 +++++ riscv/kvm.c | 5 +++++ virtio/core.c | 5 ++++- x86/kvm.c | 5 +++++ 8 files changed, 36 insertions(+), 1 deletion(-) diff --git a/arm/aarch32/kvm.c b/arm/aarch32/kvm.c index 768a56bb..849c55d3 100644 --- a/arm/aarch32/kvm.c +++ b/arm/aarch32/kvm.c @@ -12,3 +12,8 @@ u64 kvm__arch_default_ram_address(void) { return ARM_MEMORY_AREA; } + +u64 kvm__arch_get_virtio_host_features(struct kvm *kvm) +{ + return 0; +} diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index 344c568b..a4664237 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -234,3 +234,8 @@ void kvm__arch_enable_mte(struct kvm *kvm) pr_debug("MTE capability enabled"); } + +u64 kvm__arch_get_virtio_host_features(struct kvm *kvm) +{ + return 0; +} diff --git a/include/kvm/kvm.h b/include/kvm/kvm.h index 3872dc65..a3624de4 100644 --- a/include/kvm/kvm.h +++ b/include/kvm/kvm.h @@ -203,6 +203,8 @@ int kvm__arch_free_firmware(struct kvm *kvm); bool kvm__arch_cpu_supports_vm(void); void kvm__arch_read_term(struct kvm *kvm); +u64 kvm__arch_get_virtio_host_features(struct kvm *kvm); + #ifdef ARCH_HAS_CFG_RAM_ADDRESS static inline bool kvm__arch_has_cfg_ram_address(void) { diff --git a/mips/kvm.c b/mips/kvm.c index 0faa03a9..e23d5cf9 100644 --- a/mips/kvm.c +++ b/mips/kvm.c @@ -374,3 +374,8 @@ void ioport__map_irq(u8 *irq) void serial8250__inject_sysrq(struct kvm *kvm, char sysrq) { } + +u64 kvm__arch_get_virtio_host_features(struct kvm *kvm) +{ + return 0; +} diff --git a/powerpc/kvm.c b/powerpc/kvm.c index 7b0d0669..6b3ab93f 100644 --- a/powerpc/kvm.c +++ b/powerpc/kvm.c @@ -529,3 +529,8 @@ int kvm__arch_free_firmware(struct kvm *kvm) { return 0; } + +u64 kvm__arch_get_virtio_host_features(struct kvm *kvm) +{ + return 0; +} diff --git a/riscv/kvm.c b/riscv/kvm.c index 4d6f5cb5..884321ca 100644 --- a/riscv/kvm.c +++ b/riscv/kvm.c @@ -182,3 +182,8 @@ int kvm__arch_setup_firmware(struct kvm *kvm) { return 0; } + +u64 kvm__arch_get_virtio_host_features(struct kvm *kvm) +{ + return 0; +} diff --git a/virtio/core.c b/virtio/core.c index 50e7f86d..674f6fae 100644 --- a/virtio/core.c +++ b/virtio/core.c @@ -285,7 +285,10 @@ void virtio_notify_status(struct kvm *kvm, struct virtio_device *vdev, u64 virtio_dev_get_host_features(struct virtio_device *vdev, struct kvm *kvm, void *dev) { - return vdev->ops->get_host_features(kvm, dev); + u64 features = kvm__arch_get_virtio_host_features(kvm); + + features |= vdev->ops->get_host_features(kvm, dev); + return features; } bool virtio_access_config(struct kvm *kvm, struct virtio_device *vdev, diff --git a/x86/kvm.c b/x86/kvm.c index 328fa750..961b5d3f 100644 --- a/x86/kvm.c +++ b/x86/kvm.c @@ -387,3 +387,8 @@ void kvm__arch_read_term(struct kvm *kvm) serial8250__update_consoles(kvm); virtio_console__inject_interrupt(kvm); } + +u64 kvm__arch_get_virtio_host_features(struct kvm *kvm) +{ + return 0; +} From patchwork Fri Jan 27 11:39:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118474 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A8D9C54EAA for ; Fri, 27 Jan 2023 11:42:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233811AbjA0Lmu (ORCPT ); Fri, 27 Jan 2023 06:42:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233925AbjA0LmB (ORCPT ); Fri, 27 Jan 2023 06:42:01 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E13317A4A1; Fri, 27 Jan 2023 03:41:29 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B8BAC165C; Fri, 27 Jan 2023 03:41:50 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 329813F64C; Fri, 27 Jan 2023 03:41:06 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 28/31] arm64: realm: Enforce virtio F_ACCESS_PLATFORM flag Date: Fri, 27 Jan 2023 11:39:29 +0000 Message-Id: <20230127113932.166089-29-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org For realms, force the F_ACCESS_PLATFORM flag to ensure DMA-APIs are triggered for virtio in Linux Signed-off-by: Suzuki K Poulose --- arm/aarch64/kvm.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index a4664237..1f3a0def 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -5,6 +5,7 @@ #include #include #include +#include #include @@ -237,5 +238,10 @@ void kvm__arch_enable_mte(struct kvm *kvm) u64 kvm__arch_get_virtio_host_features(struct kvm *kvm) { - return 0; + u64 features = 0; + + /* Enforce F_ACCESS_PLATFORM for Realms */ + if (kvm->cfg.arch.is_realm) + features |= (1ULL << VIRTIO_F_ACCESS_PLATFORM); + return features; } From patchwork Fri Jan 27 11:39:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118475 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57510C61DA4 for ; Fri, 27 Jan 2023 11:43:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230458AbjA0Lmx (ORCPT ); Fri, 27 Jan 2023 06:42:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232184AbjA0LmC (ORCPT ); Fri, 27 Jan 2023 06:42:02 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 22E837B418; Fri, 27 Jan 2023 03:41:30 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AC9DC1688; Fri, 27 Jan 2023 03:41:53 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 14CAB3F64C; Fri, 27 Jan 2023 03:41:08 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly Subject: [RFC kvmtool 29/31] mmio: add arch hook for an unhandled MMIO access Date: Fri, 27 Jan 2023 11:39:30 +0000 Message-Id: <20230127113932.166089-30-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Joey Gouly Add a hook that allows an architecture to run some code on an unhandled MMIO access. Signed-off-by: Joey Gouly Signed-off-by: Suzuki K Poulose --- arm/kvm-cpu.c | 4 ++++ include/kvm/kvm-cpu.h | 2 ++ mips/kvm-cpu.c | 4 ++++ mmio.c | 3 +++ powerpc/kvm-cpu.c | 4 ++++ riscv/kvm-cpu.c | 4 ++++ x86/kvm-cpu.c | 4 ++++ 7 files changed, 25 insertions(+) diff --git a/arm/kvm-cpu.c b/arm/kvm-cpu.c index 98bc5fdf..90a15ae9 100644 --- a/arm/kvm-cpu.c +++ b/arm/kvm-cpu.c @@ -152,3 +152,7 @@ bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu) void kvm_cpu__show_page_tables(struct kvm_cpu *vcpu) { } + +void kvm_cpu__arch_unhandled_mmio(struct kvm_cpu *vcpu) +{ +} diff --git a/include/kvm/kvm-cpu.h b/include/kvm/kvm-cpu.h index 0f16f8d6..d0c40598 100644 --- a/include/kvm/kvm-cpu.h +++ b/include/kvm/kvm-cpu.h @@ -29,4 +29,6 @@ void kvm_cpu__show_page_tables(struct kvm_cpu *vcpu); void kvm_cpu__arch_nmi(struct kvm_cpu *cpu); void kvm_cpu__run_on_all_cpus(struct kvm *kvm, struct kvm_cpu_task *task); +void kvm_cpu__arch_unhandled_mmio(struct kvm_cpu *cpu); + #endif /* KVM__KVM_CPU_H */ diff --git a/mips/kvm-cpu.c b/mips/kvm-cpu.c index 30a3de18..0ce88ac3 100644 --- a/mips/kvm-cpu.c +++ b/mips/kvm-cpu.c @@ -217,3 +217,7 @@ void kvm_cpu__show_code(struct kvm_cpu *vcpu) void kvm_cpu__show_page_tables(struct kvm_cpu *vcpu) { } + +void kvm_cpu__arch_unhandled_mmio(struct kvm_cpu *cpu) +{ +} diff --git a/mmio.c b/mmio.c index 5a114e99..7e31079b 100644 --- a/mmio.c +++ b/mmio.c @@ -206,6 +206,9 @@ bool kvm__emulate_mmio(struct kvm_cpu *vcpu, u64 phys_addr, u8 *data, fprintf(stderr, "Warning: Ignoring MMIO %s at %016llx (length %u)\n", to_direction(is_write), (unsigned long long)phys_addr, len); + + kvm_cpu__arch_unhandled_mmio(vcpu); + goto out; } diff --git a/powerpc/kvm-cpu.c b/powerpc/kvm-cpu.c index 461e0a90..e0c20f9d 100644 --- a/powerpc/kvm-cpu.c +++ b/powerpc/kvm-cpu.c @@ -288,3 +288,7 @@ void kvm_cpu__show_page_tables(struct kvm_cpu *vcpu) { /* Does nothing yet */ } + +void kvm_cpu__arch_unhandled_mmio(struct kvm_cpu *cpu) +{ +} diff --git a/riscv/kvm-cpu.c b/riscv/kvm-cpu.c index f98bd7ae..8417e361 100644 --- a/riscv/kvm-cpu.c +++ b/riscv/kvm-cpu.c @@ -461,3 +461,7 @@ void kvm_cpu__show_registers(struct kvm_cpu *vcpu) kvm_cpu__show_csrs(vcpu); } + +void kvm_cpu__arch_unhandled_mmio(struct kvm_cpu *cpu) +{ +} diff --git a/x86/kvm-cpu.c b/x86/kvm-cpu.c index b02ff65e..ac075ee4 100644 --- a/x86/kvm-cpu.c +++ b/x86/kvm-cpu.c @@ -444,3 +444,7 @@ void kvm_cpu__arch_nmi(struct kvm_cpu *cpu) ioctl(cpu->vcpu_fd, KVM_NMI); } + +void kvm_cpu__arch_unhandled_mmio(struct kvm_cpu *cpu) +{ +} From patchwork Fri Jan 27 11:39:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118477 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CBB9C61DB3 for ; Fri, 27 Jan 2023 11:43:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233882AbjA0Lm5 (ORCPT ); Fri, 27 Jan 2023 06:42:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233930AbjA0LmB (ORCPT ); Fri, 27 Jan 2023 06:42:01 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B2C177C31A; Fri, 27 Jan 2023 03:41:30 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A914E1691; Fri, 27 Jan 2023 03:41:56 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 08A9B3F64C; Fri, 27 Jan 2023 03:41:11 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly Subject: [RFC kvmtool 30/31] arm64: realm: inject an abort on an unhandled MMIO access Date: Fri, 27 Jan 2023 11:39:31 +0000 Message-Id: <20230127113932.166089-31-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Joey Gouly For Realms, inject a synchronous external abort, instead of ignoring unknown MMIO accesses. Signed-off-by: Joey Gouly Signed-off-by: Suzuki K Poulose --- arm/kvm-cpu.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arm/kvm-cpu.c b/arm/kvm-cpu.c index 90a15ae9..c96d75eb 100644 --- a/arm/kvm-cpu.c +++ b/arm/kvm-cpu.c @@ -155,4 +155,13 @@ void kvm_cpu__show_page_tables(struct kvm_cpu *vcpu) void kvm_cpu__arch_unhandled_mmio(struct kvm_cpu *vcpu) { + struct kvm_vcpu_events events = { }; + + if (!vcpu->kvm->cfg.arch.is_realm) + return; + + events.exception.ext_dabt_pending = 1; + + if (ioctl(vcpu->vcpu_fd, KVM_SET_VCPU_EVENTS, &events) < 0) + die_perror("KVM_SET_VCPU_EVENTS failed"); } From patchwork Fri Jan 27 11:39:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13118476 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C9DFC54EAA for ; Fri, 27 Jan 2023 11:43:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233373AbjA0Lm4 (ORCPT ); Fri, 27 Jan 2023 06:42:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231487AbjA0LmC (ORCPT ); Fri, 27 Jan 2023 06:42:02 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 056107C328; Fri, 27 Jan 2023 03:41:32 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8AE0E169C; Fri, 27 Jan 2023 03:41:59 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 04DDB3F64C; Fri, 27 Jan 2023 03:41:14 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 31/31] arm64: Allow the user to create a realm Date: Fri, 27 Jan 2023 11:39:32 +0000 Message-Id: <20230127113932.166089-32-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Alexandru Elisei We have everything in place to create a realm, allow the user to do so. Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- arm/aarch64/kvm.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index 1f3a0def..422dbec2 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -104,8 +104,6 @@ static void validate_realm_cfg(struct kvm *kvm) if (strlen(kvm->cfg.arch.realm_pv) > KVM_CAP_ARM_RME_RPV_SIZE) die("Invalid size for Realm Personalization Value\n"); } - - die("Realms not supported"); } void kvm__arch_validate_cfg(struct kvm *kvm)