linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: VMX: Use wrapper macro ~RMODE_GUEST_OWNED_EFLAGS_BITS directly
@ 2020-03-05  2:35 linmiaohe
  2020-03-05 10:08 ` Vitaly Kuznetsov
  2020-03-05 11:49 ` Paolo Bonzini
  0 siblings, 2 replies; 9+ messages in thread
From: linmiaohe @ 2020-03-05  2:35 UTC (permalink / raw)
  To: pbonzini, rkrcmar, sean.j.christopherson, vkuznets, jmattson,
	joro, tglx, mingo, bp, hpa
  Cc: linmiaohe, kvm, linux-kernel, x86

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);
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread
* Re: [PATCH] KVM: VMX: Use wrapper macro ~RMODE_GUEST_OWNED_EFLAGS_BITS directly
@ 2020-03-06  2:11 linmiaohe
  0 siblings, 0 replies; 9+ messages in thread
From: linmiaohe @ 2020-03-06  2:11 UTC (permalink / raw)
  To: Vitaly Kuznetsov
  Cc: kvm, linux-kernel, x86, pbonzini, rkrcmar, sean.j.christopherson,
	jmattson, joro, tglx, mingo, bp, hpa

Vitaly Kuznetsov <vkuznets@redhat.com> writes:
>linmiaohe <linmiaohe@huawei.com> writes:
>
>> From: Miaohe Lin <linmiaohe@huawei.com>
>>
>>  
>>  	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):

You catch the evil guys again. :) But ~RMODE_GUEST_OWNED_EFLAGS_BITS is used by many other func, we should fix them
together. Would try your version, many thanks!

>
>
>-       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);
>

^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: [PATCH] KVM: VMX: Use wrapper macro ~RMODE_GUEST_OWNED_EFLAGS_BITS directly
@ 2020-03-06  2:17 linmiaohe
  2020-03-06  5:32 ` Paolo Bonzini
  0 siblings, 1 reply; 9+ messages in thread
From: linmiaohe @ 2020-03-06  2:17 UTC (permalink / raw)
  To: Paolo Bonzini, vkuznets
  Cc: rkrcmar, sean.j.christopherson, jmattson, joro, tglx, mingo, bp,
	hpa, kvm, linux-kernel, x86

Paolo Bonzini <pbonzini@redhat.com> wrote:
>On 05/03/20 03:35, linmiaohe wrote:
>> (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.
>
>... but ~RMODE_GUEST_OWNED_EFLAGS_BITS is the bits that are owned by the host; they could be 0 or 1 and that's why the code was using X86_EFLAGS_IOPL | X86_EFLAGS_VM.
>
>I understand where ~RMODE_GUEST_OWNED_EFLAGS_BITS is better than X86_EFLAGS_IOPL | X86_EFLAGS_VM, but I cannot think of a way to express it that is the best of both worlds.
>

Define a macro RMODE_HOST_OWNED_EFLAGS_BITS for (X86_EFLAGS_IOPL | X86_EFLAGS_VM) as suggested by Vitaly seems a good way to fix this ? Thanks.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-03-06 10:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2020-03-05 11:49 ` Paolo Bonzini
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).