From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: linmiaohe <linmiaohe@huawei.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
x86@kernel.org, pbonzini@redhat.com, rkrcmar@redhat.com,
sean.j.christopherson@intel.com, jmattson@google.com,
joro@8bytes.org, tglx@linutronix.de, mingo@redhat.com,
bp@alien8.de, hpa@zytor.com
Subject: Re: [PATCH] KVM: VMX: Use wrapper macro ~RMODE_GUEST_OWNED_EFLAGS_BITS directly
Date: Thu, 05 Mar 2020 11:08:39 +0100 [thread overview]
Message-ID: <87tv33cdw8.fsf@vitty.brq.redhat.com> (raw)
In-Reply-To: <1583375731-18219-1-git-send-email-linmiaohe@huawei.com>
linmiaohe <linmiaohe@huawei.com> writes:
> From: Miaohe Lin <linmiaohe@huawei.com>
>
> (X86_EFLAGS_IOPL | X86_EFLAGS_VM) indicates the eflag bits that can not be
> owned by realmode guest, i.e. ~RMODE_GUEST_OWNED_EFLAGS_BITS. Use wrapper
> macro directly to make it clear and also improve readability.
>
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
> arch/x86/kvm/vmx/vmx.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index 743b81642ce2..9571f8dea016 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -1466,7 +1466,7 @@ void vmx_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags)
> vmx->rflags = rflags;
> if (vmx->rmode.vm86_active) {
> vmx->rmode.save_rflags = rflags;
> - rflags |= X86_EFLAGS_IOPL | X86_EFLAGS_VM;
> + rflags |= ~RMODE_GUEST_OWNED_EFLAGS_BITS;
> }
> vmcs_writel(GUEST_RFLAGS, rflags);
>
> @@ -2797,7 +2797,7 @@ static void enter_rmode(struct kvm_vcpu *vcpu)
> flags = vmcs_readl(GUEST_RFLAGS);
> vmx->rmode.save_rflags = flags;
>
> - flags |= X86_EFLAGS_IOPL | X86_EFLAGS_VM;
> + flags |= ~RMODE_GUEST_OWNED_EFLAGS_BITS;
>
> vmcs_writel(GUEST_RFLAGS, flags);
> vmcs_writel(GUEST_CR4, vmcs_readl(GUEST_CR4) | X86_CR4_VME);
Double negations are evil, let's define a macro for 'X86_EFLAGS_IOPL |
X86_EFLAGS_VM' instead (completely untested):
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 4ee19fb35cde..d838f93bd6d2 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -139,7 +139,8 @@ module_param_named(preemption_timer, enable_preemption_timer, bool, S_IRUGO);
#define KVM_PMODE_VM_CR4_ALWAYS_ON (X86_CR4_PAE | X86_CR4_VMXE)
#define KVM_RMODE_VM_CR4_ALWAYS_ON (X86_CR4_VME | X86_CR4_PAE | X86_CR4_VMXE)
-#define RMODE_GUEST_OWNED_EFLAGS_BITS (~(X86_EFLAGS_IOPL | X86_EFLAGS_VM))
+#define RMODE_HOST_OWNED_EFLAGS_BITS (X86_EFLAGS_IOPL | X86_EFLAGS_VM)
+#define RMODE_GUEST_OWNED_EFLAGS_BITS (~RMODE_HOST_OWNED_EFLAGS_BITS)
#define MSR_IA32_RTIT_STATUS_MASK (~(RTIT_STATUS_FILTEREN | \
RTIT_STATUS_CONTEXTEN | RTIT_STATUS_TRIGGEREN | \
@@ -1468,7 +1469,7 @@ void vmx_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags)
vmx->rflags = rflags;
if (vmx->rmode.vm86_active) {
vmx->rmode.save_rflags = rflags;
- rflags |= X86_EFLAGS_IOPL | X86_EFLAGS_VM;
+ rflags |= RMODE_HOST_OWNED_EFLAGS_BITS;
}
vmcs_writel(GUEST_RFLAGS, rflags);
@@ -2794,7 +2795,7 @@ static void enter_rmode(struct kvm_vcpu *vcpu)
flags = vmcs_readl(GUEST_RFLAGS);
vmx->rmode.save_rflags = flags;
- flags |= X86_EFLAGS_IOPL | X86_EFLAGS_VM;
+ flags |= RMODE_HOST_OWNED_EFLAGS_BITS;
vmcs_writel(GUEST_RFLAGS, flags);
vmcs_writel(GUEST_CR4, vmcs_readl(GUEST_CR4) | X86_CR4_VME);
--
Vitaly
next prev parent reply other threads:[~2020-03-05 10:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-05 2:35 [PATCH] KVM: VMX: Use wrapper macro ~RMODE_GUEST_OWNED_EFLAGS_BITS directly linmiaohe
2020-03-05 10:08 ` Vitaly Kuznetsov [this message]
2020-03-05 11:49 ` Paolo Bonzini
-- strict thread matches above, loose matches on Subject: below --
2020-03-06 2:11 linmiaohe
2020-03-06 2:17 linmiaohe
2020-03-06 5:32 ` Paolo Bonzini
2020-03-06 9:44 ` Vitaly Kuznetsov
2020-03-06 10:00 ` Paolo Bonzini
2020-03-06 10:15 ` Vitaly Kuznetsov
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=87tv33cdw8.fsf@vitty.brq.redhat.com \
--to=vkuznets@redhat.com \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
--cc=sean.j.christopherson@intel.com \
--cc=tglx@linutronix.de \
--cc=x86@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.