From: Sean Christopherson <seanjc@google.com>
To: Aaron Lewis <aaronlewis@google.com>
Cc: kvm@vger.kernel.org, pbonzini@redhat.com, jmattson@google.com
Subject: Re: [PATCH v4 2/5] KVM: x86: Add a VALID_MASK for the MSR exit reason flags
Date: Fri, 7 Oct 2022 22:04:04 +0000 [thread overview]
Message-ID: <Y0CiVMWB3o1b7i/x@google.com> (raw)
In-Reply-To: <20220921151525.904162-3-aaronlewis@google.com>
On Wed, Sep 21, 2022, Aaron Lewis wrote:
> Add the mask KVM_MSR_EXIT_REASON_VALID_MASK for the MSR exit reason
Uber nit, "the mask" is rather redundant, e.g.
Add KVM_MSR_EXIT_REASON_VALID_MASK to track the allowed MSR exit reason
flags.
> flags. This simplifies checks that validate these flags, and makes it
> easier to introduce new flags in the future.
>
> No functional change intended.
>
> Signed-off-by: Aaron Lewis <aaronlewis@google.com>
> ---
> arch/x86/kvm/x86.c | 4 +---
> include/uapi/linux/kvm.h | 3 +++
> 2 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index d7374d768296..852614246825 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -6182,9 +6182,7 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
> break;
> case KVM_CAP_X86_USER_SPACE_MSR:
> r = -EINVAL;
> - if (cap->args[0] & ~(KVM_MSR_EXIT_REASON_INVAL |
> - KVM_MSR_EXIT_REASON_UNKNOWN |
> - KVM_MSR_EXIT_REASON_FILTER))
> + if (cap->args[0] & ~KVM_MSR_EXIT_REASON_VALID_MASK)
> break;
> kvm->arch.user_space_msr_mask = cap->args[0];
> r = 0;
> diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
> index eed0315a77a6..44d476c3143a 100644
> --- a/include/uapi/linux/kvm.h
> +++ b/include/uapi/linux/kvm.h
> @@ -485,6 +485,9 @@ struct kvm_run {
> #define KVM_MSR_EXIT_REASON_INVAL (1 << 0)
> #define KVM_MSR_EXIT_REASON_UNKNOWN (1 << 1)
> #define KVM_MSR_EXIT_REASON_FILTER (1 << 2)
> +#define KVM_MSR_EXIT_REASON_VALID_MASK (KVM_MSR_EXIT_REASON_INVAL | \
> + KVM_MSR_EXIT_REASON_UNKNOWN | \
> + KVM_MSR_EXIT_REASON_FILTER)
Put all of these VALID_MASK defines in arch/x86/include/asm/kvm_host.h so that
they aren't exposed to userspace, e.g. see KVM_X86_NOTIFY_VMEXIT_VALID_BITS.
Generally speaking, things should be kept in-kernel unless there's an actual need
to expose something to userspace. Once something is exposed to userspace, our
options become much more limited.
E.g. if userspace does something silly like:
filters = KVM_MSR_EXIT_REASON_VALID_MASK;
then upgrading kernel headers will unexpectedly change and potentially break
userspace, and then KVM is stuck having a bogus VALID_MASK.
next prev parent reply other threads:[~2022-10-07 22:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-21 15:15 [PATCH v4 0/5] MSR filtering and MSR exiting flag clean up Aaron Lewis
2022-09-21 15:15 ` [PATCH v4 1/5] KVM: x86: Disallow the use of KVM_MSR_FILTER_DEFAULT_ALLOW in the kernel Aaron Lewis
2022-10-07 21:57 ` Sean Christopherson
2022-09-21 15:15 ` [PATCH v4 2/5] KVM: x86: Add a VALID_MASK for the MSR exit reason flags Aaron Lewis
2022-10-07 22:04 ` Sean Christopherson [this message]
2022-09-21 15:15 ` [PATCH v4 3/5] KVM: x86: Add a VALID_MASK for the flag in kvm_msr_filter Aaron Lewis
2022-09-21 15:15 ` [PATCH v4 4/5] KVM: x86: Add a VALID_MASK for the flags in kvm_msr_filter_range Aaron Lewis
2022-09-21 15:15 ` [PATCH v4 5/5] selftests: kvm/x86: Test the flags in MSR filtering and MSR exiting Aaron Lewis
2022-10-07 22:24 ` Sean Christopherson
2022-11-02 17:09 ` [PATCH v4 0/5] MSR filtering and MSR exiting flag clean up Paolo Bonzini
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=Y0CiVMWB3o1b7i/x@google.com \
--to=seanjc@google.com \
--cc=aaronlewis@google.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.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 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.