All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch] fix kvm_arch_vcpu_ioctl_[gs]et_regs() - v2
@ 2008-12-16 15:45 Jes Sorensen
  2008-12-17  1:41 ` Zhang, Xiantao
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Jes Sorensen @ 2008-12-16 15:45 UTC (permalink / raw)
  To: kvm-ia64

[-- Attachment #1: Type: text/plain, Size: 641 bytes --]

Avi Kivity wrote:
> This makes several tons of sense, but breaks backwards compatibility.  
> If I understand correctly, get/set was never used so this shouldn't matter?
> 
> I suggest reserving some space at the end of kvm_regs in case further 
> state needs to be added.
> 
> Please add a KVM_CAP_ entry to advertise the fixup.  This way userspace 
> can determine that it's compiling or running on an old kernel and error 
> out gracefully.

Hi Avi,

Here's an update version of this patch, which leaves some space for
future extensions in struct kvm_regs. The KVM_CAP is unnecessary as
GET/SET_REGS never worked on ia64.

Cheers,
Jes




[-- Attachment #2: 6000-kvm-ia64-get-regs-locking.patch --]
[-- Type: text/plain, Size: 3471 bytes --]

Fix kvm_arch_vcpu_ioctl_[gs]et_regs() to do something meaningful on
ia64. Old versions could never have worked since they required
pointers to be set in the ioctl payload which were never being set by
the ioctl handler for get_regs.

In addition reserve extra space for future extensions.

The change of layout of struct kvm_regs doesn't require adding a new
CAP since get/set regs never worked on ia64 until now. 

This version doesn't support copying the KVM kernel stack in/out of
the kernel. This should be implemented in a seperate ioctl call if
ever needed.

Signed-off-by: Jes Sorensen <jes@sgi.com>

---
 arch/ia64/include/asm/kvm.h |    6 ++++--
 arch/ia64/kvm/kvm-ia64.c    |   40 ++++++++++------------------------------
 2 files changed, 14 insertions(+), 32 deletions(-)

Index: linux-2.6.git/arch/ia64/include/asm/kvm.h
===================================================================
--- linux-2.6.git.orig/arch/ia64/include/asm/kvm.h
+++ linux-2.6.git/arch/ia64/include/asm/kvm.h
@@ -199,8 +199,6 @@
 };
 
 struct kvm_regs {
-	char *saved_guest;
-	char *saved_stack;
 	struct saved_vpd vpd;
 	/*Arch-regs*/
 	int mp_state;
@@ -233,6 +231,10 @@
 	unsigned long fp_psr;       /*used for lazy float register */
 	unsigned long saved_gp;
 	/*for phycial  emulation */
+
+	unsigned long reserved[64];	/* for future use */
+
+	union context saved_guest;
 };
 
 struct kvm_sregs {
Index: linux-2.6.git/arch/ia64/kvm/kvm-ia64.c
===================================================================
--- linux-2.6.git.orig/arch/ia64/kvm/kvm-ia64.c
+++ linux-2.6.git/arch/ia64/kvm/kvm-ia64.c
@@ -867,9 +867,8 @@
 
 int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
 {
-	int i;
 	struct vpd *vpd = to_host(vcpu->kvm, vcpu->arch.vpd);
-	int r;
+	int i;
 
 	vcpu_load(vcpu);
 
@@ -886,18 +885,7 @@
 
 	vpd->vpr = regs->vpd.vpr;
 
-	r = -EFAULT;
-	r = copy_from_user(&vcpu->arch.guest, regs->saved_guest,
-						sizeof(union context));
-	if (r)
-		goto out;
-	r = copy_from_user(vcpu + 1, regs->saved_stack +
-			sizeof(struct kvm_vcpu),
-			KVM_STK_OFFSET - sizeof(struct kvm_vcpu));
-	if (r)
-		goto out;
-	vcpu->arch.exit_data =
-		((struct kvm_vcpu *)(regs->saved_stack))->arch.exit_data;
+	memcpy(&vcpu->arch.guest, &regs->saved_guest, sizeof(union context));
 
 	RESTORE_REGS(mp_state);
 	RESTORE_REGS(vmm_rr);
@@ -931,9 +919,8 @@
 	set_bit(KVM_REQ_RESUME, &vcpu->requests);
 
 	vcpu_put(vcpu);
-	r = 0;
-out:
-	return r;
+
+	return 0;
 }
 
 long kvm_arch_vm_ioctl(struct file *filp,
@@ -1418,9 +1405,9 @@
 
 int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
 {
-	int i;
-	int r;
 	struct vpd *vpd = to_host(vcpu->kvm, vcpu->arch.vpd);
+	int i;
+
 	vcpu_load(vcpu);
 
 	for (i = 0; i < 16; i++) {
@@ -1435,14 +1422,8 @@
 	regs->vpd.vpsr = vpd->vpsr;
 	regs->vpd.vpr = vpd->vpr;
 
-	r = -EFAULT;
-	r = copy_to_user(regs->saved_guest, &vcpu->arch.guest,
-					sizeof(union context));
-	if (r)
-		goto out;
-	r = copy_to_user(regs->saved_stack, (void *)vcpu, KVM_STK_OFFSET);
-	if (r)
-		goto out;
+	memcpy(&regs->saved_guest, &vcpu->arch.guest, sizeof(union context));
+
 	SAVE_REGS(mp_state);
 	SAVE_REGS(vmm_rr);
 	memcpy(regs->itrs, vcpu->arch.itrs, sizeof(struct thash_data) * NITRS);
@@ -1470,10 +1451,9 @@
 	SAVE_REGS(metaphysical_saved_rr4);
 	SAVE_REGS(fp_psr);
 	SAVE_REGS(saved_gp);
+
 	vcpu_put(vcpu);
-	r = 0;
-out:
-	return r;
+	return 0;
 }
 
 void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu)

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

end of thread, other threads:[~2008-12-18 11:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-16 15:45 [patch] fix kvm_arch_vcpu_ioctl_[gs]et_regs() - v2 Jes Sorensen
2008-12-17  1:41 ` Zhang, Xiantao
2008-12-17  1:41 ` Zhang, Xiantao
2008-12-17 10:32 ` Avi Kivity
2008-12-17 10:32 ` Avi Kivity
2008-12-18  9:13 ` Jes Sorensen
2008-12-18 10:11 ` Avi Kivity
2008-12-18 10:26 ` Jes Sorensen
2008-12-18 11:19 ` Avi Kivity
2008-12-18 11:21 ` Jes Sorensen

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.