From: Tao Su <tao1.su@linux.intel.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/6] KVM: Add a dedicated API for setting KVM-internal memslots
Date: Mon, 5 Aug 2024 16:42:37 +0800 [thread overview]
Message-ID: <ZrCQffKMMuvuYQT9@linux.bj.intel.com> (raw)
In-Reply-To: <20240802205003.353672-4-seanjc@google.com>
On Fri, Aug 02, 2024 at 01:50:00PM -0700, Sean Christopherson wrote:
> Add a dedicated API for setting internal memslots, and have it explicitly
> disallow setting userspace memslots. Setting a userspace memslots without
> a direct command from userspace would result in all manner of issues.
>
> No functional change intended.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
> arch/x86/kvm/x86.c | 2 +-
> include/linux/kvm_host.h | 4 ++--
> virt/kvm/kvm_main.c | 15 ++++++++++++---
> 3 files changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index af6c8cf6a37a..77949fee13f7 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -12794,7 +12794,7 @@ void __user * __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa,
> m.guest_phys_addr = gpa;
> m.userspace_addr = hva;
> m.memory_size = size;
> - r = __kvm_set_memory_region(kvm, &m);
> + r = kvm_set_internal_memslot(kvm, &m);
> if (r < 0)
> return ERR_PTR_USR(r);
> }
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index b341d00aae37..cefa274c0852 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -1179,8 +1179,8 @@ enum kvm_mr_change {
> KVM_MR_FLAGS_ONLY,
> };
>
> -int __kvm_set_memory_region(struct kvm *kvm,
> - const struct kvm_userspace_memory_region2 *mem);
> +int kvm_set_internal_memslot(struct kvm *kvm,
> + const struct kvm_userspace_memory_region2 *mem);
> void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *slot);
> void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen);
> int kvm_arch_prepare_memory_region(struct kvm *kvm,
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index f202bdbfca9e..63b43644ed9f 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -1973,8 +1973,8 @@ static bool kvm_check_memslot_overlap(struct kvm_memslots *slots, int id,
> return false;
> }
>
> -int __kvm_set_memory_region(struct kvm *kvm,
> - const struct kvm_userspace_memory_region2 *mem)
> +static int __kvm_set_memory_region(struct kvm *kvm,
> + const struct kvm_userspace_memory_region2 *mem)
> {
> struct kvm_memory_slot *old, *new;
> struct kvm_memslots *slots;
> @@ -2097,7 +2097,16 @@ int __kvm_set_memory_region(struct kvm *kvm,
> kfree(new);
> return r;
> }
> -EXPORT_SYMBOL_GPL(__kvm_set_memory_region);
> +
> +int kvm_set_internal_memslot(struct kvm *kvm,
> + const struct kvm_userspace_memory_region2 *mem)
> +{
> + if (WARN_ON_ONCE(mem->slot < KVM_USER_MEM_SLOTS))
> + return -EINVAL;
> +
> + return __kvm_set_memory_region(kvm, mem);
^^
Two spaces are introduced here.
> +}
> +EXPORT_SYMBOL_GPL(kvm_set_internal_memslot);
>
> static int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
> struct kvm_userspace_memory_region2 *mem)
> --
> 2.46.0.rc2.264.g509ed76dc8-goog
>
>
next prev parent reply other threads:[~2024-08-05 8:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-02 20:49 [PATCH 0/6] KVM: kvm_set_memory_region() cleanups Sean Christopherson
2024-08-02 20:49 ` [PATCH 1/6] KVM: Open code kvm_set_memory_region() into its sole caller (ioctl() API) Sean Christopherson
2024-08-05 8:39 ` Tao Su
2024-08-02 20:49 ` [PATCH 2/6] KVM: Assert slots_lock is held in __kvm_set_memory_region() Sean Christopherson
2024-08-05 8:41 ` Tao Su
2024-08-05 22:01 ` Sean Christopherson
2024-08-02 20:50 ` [PATCH 3/6] KVM: Add a dedicated API for setting KVM-internal memslots Sean Christopherson
2024-08-05 8:42 ` Tao Su [this message]
2024-08-02 20:50 ` [PATCH 4/6] KVM: x86: Drop double-underscores from __kvm_set_memory_region() Sean Christopherson
2024-08-02 20:50 ` [PATCH 5/6] KVM: Disallow all flags for KVM-internal memslots Sean Christopherson
2024-08-02 20:50 ` [PATCH 6/6] KVM: Move flags check for user memory regions to the ioctl() specific API Sean Christopherson
2024-08-08 7:41 ` Xiaoyao Li
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=ZrCQffKMMuvuYQT9@linux.bj.intel.com \
--to=tao1.su@linux.intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox