All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fuad Tabba <tabba@google.com>
To: kvm@vger.kernel.org
Cc: julien.thierry.kdev@gmail.com, andre.przywara@arm.com,
	alexandru.elisei@arm.com, alex.bennee@linaro.org,
	will@kernel.org, tabba@google.com
Subject: [RFC PATCH kvmtool v1 30/32] pkvm: Enable exit hypercall capability if supported
Date: Fri,  2 Dec 2022 17:44:15 +0000	[thread overview]
Message-ID: <20221202174417.1310826-31-tabba@google.com> (raw)
In-Reply-To: <20221202174417.1310826-1-tabba@google.com>

This hypercall allows the guest to communicate with the host via
the new exit type. It will be used in future patches to
communicate guest-triggered change of memory sharing status with
the host/vmm (kvmtool).

Signed-off-by: Fuad Tabba <tabba@google.com>
---
 arm/aarch32/include/kvm/kvm-arch.h |  1 +
 arm/aarch64/include/kvm/kvm-arch.h |  1 +
 arm/aarch64/kvm.c                  | 23 +++++++++++++++++++++++
 arm/kvm-cpu.c                      | 10 ++++++++++
 arm/kvm.c                          |  1 +
 5 files changed, 36 insertions(+)

diff --git a/arm/aarch32/include/kvm/kvm-arch.h b/arm/aarch32/include/kvm/kvm-arch.h
index 467fb09..5666f2f 100644
--- a/arm/aarch32/include/kvm/kvm-arch.h
+++ b/arm/aarch32/include/kvm/kvm-arch.h
@@ -7,6 +7,7 @@
 
 struct kvm;
 static inline void kvm__arch_enable_mte(struct kvm *kvm) {}
+static inline void kvm__arch_enable_exit_hypcall(struct kvm *kvm) {}
 
 #define MAX_PAGE_SIZE	SZ_4K
 
diff --git a/arm/aarch64/include/kvm/kvm-arch.h b/arm/aarch64/include/kvm/kvm-arch.h
index 02d09a4..9af002b 100644
--- a/arm/aarch64/include/kvm/kvm-arch.h
+++ b/arm/aarch64/include/kvm/kvm-arch.h
@@ -7,6 +7,7 @@ struct kvm;
 unsigned long long kvm__arch_get_kern_offset(struct kvm *kvm, int fd);
 int kvm__arch_get_ipa_limit(struct kvm *kvm);
 void kvm__arch_enable_mte(struct kvm *kvm);
+void kvm__arch_enable_exit_hypcall(struct kvm *kvm);
 
 #define MAX_PAGE_SIZE	SZ_64K
 
diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c
index f65c9c1..604a5e8 100644
--- a/arm/aarch64/kvm.c
+++ b/arm/aarch64/kvm.c
@@ -163,3 +163,26 @@ void kvm__arch_enable_mte(struct kvm *kvm)
 
 	pr_debug("MTE capability enabled");
 }
+
+void kvm__arch_enable_exit_hypcall(struct kvm *kvm)
+{
+	struct kvm_enable_cap cap = {
+		.cap = KVM_CAP_EXIT_HYPERCALL,
+		.args[0] = KVM_EXIT_HYPERCALL_VALID_MASK,
+	};
+
+	if (kvm->cfg.arch.aarch32_guest) {
+		pr_debug("EXIT HYPERCALL is incompatible with AArch32");
+		return;
+	}
+
+	if (!kvm__supports_extension(kvm, KVM_CAP_EXIT_HYPERCALL)) {
+		pr_debug("EXIT HYPERCALL capability not available");
+		return;
+	}
+
+	if (ioctl(kvm->vm_fd, KVM_ENABLE_CAP, &cap))
+		die_perror("KVM_ENABLE_CAP(KVM_CAP_EXIT_HYPERCALL)");
+
+	pr_debug("EXIT capability enabled");
+}
diff --git a/arm/kvm-cpu.c b/arm/kvm-cpu.c
index 98bc5fd..cb5a92a 100644
--- a/arm/kvm-cpu.c
+++ b/arm/kvm-cpu.c
@@ -146,6 +146,16 @@ void kvm_cpu__delete(struct kvm_cpu *vcpu)
 
 bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu)
 {
+	switch (vcpu->kvm_run->exit_reason) {
+	case KVM_EXIT_HYPERCALL:
+		pr_warning("Unhandled exit hypercall: 0x%llx, 0x%llx, 0x%llx, 0x%llx",
+			   vcpu->kvm_run->hypercall.nr,
+			   vcpu->kvm_run->hypercall.ret,
+			   vcpu->kvm_run->hypercall.args[0],
+			   vcpu->kvm_run->hypercall.args[1]);
+		return true;
+	}
+
 	return false;
 }
 
diff --git a/arm/kvm.c b/arm/kvm.c
index 094fbe4..f4b0247 100644
--- a/arm/kvm.c
+++ b/arm/kvm.c
@@ -84,6 +84,7 @@ void kvm__arch_init(struct kvm *kvm)
 		die("Failed to create virtual GIC");
 
 	kvm__arch_enable_mte(kvm);
+	kvm__arch_enable_exit_hypcall(kvm);
 }
 
 #define FDT_ALIGN	SZ_2M
-- 
2.39.0.rc0.267.gcb52ba06e7-goog


  parent reply	other threads:[~2022-12-02 17:46 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-02 17:43 [RFC PATCH kvmtool v1 00/32] Add support for restricted guest memory in kvmtool Fuad Tabba
2022-12-02 17:43 ` [RFC PATCH kvmtool v1 01/32] Initialize the return value in kvm__for_each_mem_bank() Fuad Tabba
2022-12-02 17:43 ` [RFC PATCH kvmtool v1 02/32] Remove newline from end of die() aborts Fuad Tabba
2022-12-02 17:43 ` [RFC PATCH kvmtool v1 03/32] Make mmap_hugetlbfs() static Fuad Tabba
2022-12-02 17:43 ` [RFC PATCH kvmtool v1 04/32] Rename parameter in mmap_anon_or_hugetlbfs() Fuad Tabba
2022-12-02 17:43 ` [RFC PATCH kvmtool v1 05/32] Add hostmem va to debug print Fuad Tabba
2022-12-02 17:43 ` [RFC PATCH kvmtool v1 06/32] Factor out getting the hugetlb block size Fuad Tabba
2022-12-02 17:43 ` [RFC PATCH kvmtool v1 07/32] Use memfd for hugetlbfs when allocating guest ram Fuad Tabba
2022-12-02 17:43 ` [RFC PATCH kvmtool v1 08/32] Make blk_size a parameter and pass it to mmap_hugetlbfs() Fuad Tabba
2022-12-02 17:43 ` [RFC PATCH kvmtool v1 09/32] Use memfd for all guest ram allocations Fuad Tabba
2022-12-02 17:43 ` [RFC PATCH kvmtool v1 10/32] Allocate pvtime memory with memfd Fuad Tabba
2022-12-02 17:43 ` [RFC PATCH kvmtool v1 11/32] Allocate vesa " Fuad Tabba
2022-12-02 17:43 ` [RFC PATCH kvmtool v1 12/32] Add a function that allocates aligned memory if specified Fuad Tabba
2022-12-02 17:43 ` [RFC PATCH kvmtool v1 13/32] Use new function to align memory Fuad Tabba
2022-12-02 17:43 ` [RFC PATCH kvmtool v1 14/32] Remove struct fields and code used for alignment Fuad Tabba
2022-12-02 17:44 ` [RFC PATCH kvmtool v1 15/32] Replace kvm__arch_delete_ram() with kvm__delete_ram() Fuad Tabba
2022-12-02 17:44 ` [RFC PATCH kvmtool v1 16/32] Remove no-longer used macro Fuad Tabba
2022-12-02 17:44 ` [RFC PATCH kvmtool v1 17/32] Factor out set_user_memory_region code Fuad Tabba
2022-12-02 17:44 ` [RFC PATCH kvmtool v1 18/32] Pass the memory file descriptor and offset when registering ram Fuad Tabba
2022-12-02 17:44 ` [RFC PATCH kvmtool v1 19/32] Add memfd_restricted system call Fuad Tabba
2022-12-02 17:44 ` [RFC PATCH kvmtool v1 20/32] Add kvm linux headers and structure extensions for restricted_fd Fuad Tabba
2022-12-02 17:44 ` [RFC PATCH kvmtool v1 21/32] Add option for enabling restricted memory for guests Fuad Tabba
2022-12-02 17:44 ` [RFC PATCH kvmtool v1 22/32] Change guest ram mapping from private to shared Fuad Tabba
2022-12-02 17:44 ` [RFC PATCH kvmtool v1 23/32] Change pvtime " Fuad Tabba
2022-12-02 17:44 ` [RFC PATCH kvmtool v1 24/32] Change vesa " Fuad Tabba
2022-12-02 17:44 ` [RFC PATCH kvmtool v1 25/32] Allocate guest memory as restricted if needed Fuad Tabba
2022-12-07 14:25   ` Steven Price
2022-12-07 14:52     ` Fuad Tabba
2022-12-07 15:09       ` Steven Price
2022-12-07 15:30         ` Fuad Tabba
2022-12-02 17:44 ` [RFC PATCH kvmtool v1 26/32] Use the new fd-based extended memory region Fuad Tabba
2022-12-02 17:44 ` [RFC PATCH kvmtool v1 27/32] Track the memfd in the bank Fuad Tabba
2022-12-02 17:44 ` [RFC PATCH kvmtool v1 28/32] Add functions for mapping/unmapping guest memory Fuad Tabba
2022-12-02 17:44 ` [RFC PATCH kvmtool v1 29/32] pkvm: Add option to spawn a protected vm in pkvm Fuad Tabba
2022-12-02 17:44 ` Fuad Tabba [this message]
2022-12-02 17:44 ` [RFC PATCH kvmtool v1 31/32] pkvm: Handle (un)share hypercalls coming from the guest Fuad Tabba
2022-12-02 17:44 ` [RFC PATCH kvmtool v1 32/32] pkvm: Unmap all guest memory after initialization Fuad Tabba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221202174417.1310826-31-tabba@google.com \
    --to=tabba@google.com \
    --cc=alex.bennee@linaro.org \
    --cc=alexandru.elisei@arm.com \
    --cc=andre.przywara@arm.com \
    --cc=julien.thierry.kdev@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.