Re: [PATCH 3/9] Implement GIF, clgi and stgi v5

2008-10-30 Thread Anthony Liguori

Alexander Graf wrote:

This patch implements the GIF flag and the clgi and stgi instructions that
set this flag. Only if the flag is set (default), interrupts can be received by
the CPU.

To keep the information about that somewhere, this patch adds a new hidden
flags vector. that is used to store information that does not go into the
vmcb, but is SVM specific.

v2 moves the hflags to x86 generic code
v3 makes use of the new permission helper

Signed-off-by: Alexander Graf [EMAIL PROTECTED]
---
 arch/x86/kvm/svm.c |   42 +++---
 include/asm-x86/kvm_host.h |3 +++
 2 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index a00421b..62bfa2b 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -614,6 +614,8 @@ static void init_vmcb(struct vcpu_svm *svm)
save-cr4 = 0;
}
force_new_asid(svm-vcpu);
+
+   svm-vcpu.arch.hflags = HF_GIF_MASK;
 }
 
 static int svm_vcpu_reset(struct kvm_vcpu *vcpu)

@@ -1233,6 +1235,36 @@ static int nested_svm_do(struct vcpu_svm *svm,
return retval;
 }
 
+static int stgi_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)

+{
+   if (nested_svm_check_permissions(svm))
+   return 1;
+
+   svm-next_rip = kvm_rip_read(svm-vcpu) + 3;
+   skip_emulated_instruction(svm-vcpu);
+
+   svm-vcpu.arch.hflags |= HF_GIF_MASK;
+
+   return 1;
+}
  


It feels a little strange to see this here instead of an implementation 
of stgi/clgi in x86_emulate.  Any reason for not going that route?


GIF somehow needs exposure to userspace too, right?  Otherwise, when 
using -no-kernel-apic, userspace may try to inject an interrupt when the 
guest cannot handle it, right?


Regards,

Anthony Liguori

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/9] Implement GIF, clgi and stgi v5

2008-10-30 Thread Avi Kivity

Anthony Liguori wrote:
 
+static int stgi_interception(struct vcpu_svm *svm, struct kvm_run 
*kvm_run)

+{


It feels a little strange to see this here instead of an 
implementation of stgi/clgi in x86_emulate.  Any reason for not going 
that route?




We already know the instruction is stgi, no need to go through the guest 
page tables to fetch it.  We do the same thing for all instructions for 
which we have the length and all the information necessary to execute it.


GIF somehow needs exposure to userspace too, right?  Otherwise, when 
using -no-kernel-apic, userspace may try to inject an interrupt when 
the guest cannot handle it, right?


Hmm, right, it needs to close the interrupt window.

--
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/9] Implement GIF, clgi and stgi v5

2008-10-30 Thread Alexander Graf


On 30.10.2008, at 19:10, Avi Kivity wrote:


Anthony Liguori wrote:
+static int stgi_interception(struct vcpu_svm *svm, struct kvm_run  
*kvm_run)

+{


It feels a little strange to see this here instead of an  
implementation of stgi/clgi in x86_emulate.  Any reason for not  
going that route?




We already know the instruction is stgi, no need to go through the  
guest page tables to fetch it.  We do the same thing for all  
instructions for which we have the length and all the information  
necessary to execute it.


GIF somehow needs exposure to userspace too, right?  Otherwise,  
when using -no-kernel-apic, userspace may try to inject an  
interrupt when the guest cannot handle it, right?


Hmm, right, it needs to close the interrupt window.


Yes, it's broken with -no-kernel-apic, since the userspace doesn't  
know the window is closed. Any good suggestions here? Joerg and me  
decided to just ignore the non-kernel-apic case, but if it's important  
we might want to sync the hflags with userspace, so we can export the  
GIF.


Alex

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/9] Implement GIF, clgi and stgi v5

2008-10-30 Thread Anthony Liguori

Alexander Graf wrote:


On 30.10.2008, at 19:10, Avi Kivity wrote:
GIF somehow needs exposure to userspace too, right?  Otherwise, when 
using -no-kernel-apic, userspace may try to inject an interrupt when 
the guest cannot handle it, right?


Hmm, right, it needs to close the interrupt window.


Yes, it's broken with -no-kernel-apic, since the userspace doesn't 
know the window is closed. Any good suggestions here? Joerg and me 
decided to just ignore the non-kernel-apic case, but if it's important 
we might want to sync the hflags with userspace, so we can export the 
GIF.


Maybe abusing kvm_run-if_flag?  Current, userspace treats if_flag as a 
boolean.  If you stored GIF and eflags.IF in there, I believe old 
userspaces would just work.


Regards,

Anthony Liguori


Alex



--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/9] Implement GIF, clgi and stgi v5

2008-10-30 Thread Anthony Liguori

Avi Kivity wrote:

Anthony Liguori wrote:
 
+static int stgi_interception(struct vcpu_svm *svm, struct kvm_run 
*kvm_run)

+{


It feels a little strange to see this here instead of an 
implementation of stgi/clgi in x86_emulate.  Any reason for not going 
that route?




We already know the instruction is stgi, no need to go through the 
guest page tables to fetch it.  We do the same thing for all 
instructions for which we have the length and all the information 
necessary to execute it.


Fair enough.

Regards,

Anthony Liguori

GIF somehow needs exposure to userspace too, right?  Otherwise, when 
using -no-kernel-apic, userspace may try to inject an interrupt when 
the guest cannot handle it, right?


Hmm, right, it needs to close the interrupt window.



--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html