From: Rusty Russell <rusty-8n+1lVoiYb80n/F98K4Iww@public.gmane.org>
To: kvm-devel <kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Subject: [PATCH 1/2] kvm: Insist on a reason when injecting a #GP into a guest
Date: Tue, 24 Jul 2007 16:47:57 +1000 [thread overview]
Message-ID: <1185259677.1803.239.camel@localhost.localdomain> (raw)
Insist on a reason when injecting a #GP into a guest
All places but one already do a printk before injecting a #GP: just
formalize it a little.
Signed-off-by: Rusty Russell <rusty-8n+1lVoiYb80n/F98K4Iww@public.gmane.org>
diff -r f75b0a5fc387 drivers/kvm/kvm_main.c
--- a/drivers/kvm/kvm_main.c Mon Jul 23 11:16:12 2007 +1000
+++ b/drivers/kvm/kvm_main.c Mon Jul 23 16:59:56 2007 +1000
@@ -419,8 +419,15 @@ static int kvm_vm_release(struct inode *
return 0;
}
-static void inject_gp(struct kvm_vcpu *vcpu)
-{
+static void __attribute__((format(printf, 2, 3)))
+inject_gp(struct kvm_vcpu *vcpu, const char *why_fmt, ...)
+{
+ va_list args;
+
+ va_start(args, why_fmt);
+ printk(KERN_DEBUG "kvm: #GP ");
+ vprintk(why_fmt, args);
+ va_end(args);
kvm_arch_ops->inject_gp(vcpu, 0);
}
@@ -464,22 +471,21 @@ void set_cr0(struct kvm_vcpu *vcpu, unsi
void set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
{
if (cr0 & CR0_RESERVED_BITS) {
- printk(KERN_DEBUG "set_cr0: 0x%lx #GP, reserved bits 0x%lx\n",
- cr0, vcpu->cr0);
- inject_gp(vcpu);
+ inject_gp(vcpu,
+ "set_cr0: 0x%lx reserved bits 0x%lx\n",
+ cr0, vcpu->cr0);
return;
}
if ((cr0 & X86_CR0_NW) && !(cr0 & X86_CR0_CD)) {
- printk(KERN_DEBUG "set_cr0: #GP, CD == 0 && NW == 1\n");
- inject_gp(vcpu);
+ inject_gp(vcpu,
+ "set_cr0: CD == 0 && NW == 1\n");
return;
}
if ((cr0 & X86_CR0_PG) && !(cr0 & X86_CR0_PE)) {
- printk(KERN_DEBUG "set_cr0: #GP, set PG flag "
- "and a clear PE flag\n");
- inject_gp(vcpu);
+ inject_gp(vcpu,
+ "set_cr0: set PG flag and a clear PE flag\n");
return;
}
@@ -489,25 +495,23 @@ void set_cr0(struct kvm_vcpu *vcpu, unsi
int cs_db, cs_l;
if (!is_pae(vcpu)) {
- printk(KERN_DEBUG "set_cr0: #GP, start paging "
- "in long mode while PAE is disabled\n");
- inject_gp(vcpu);
+ inject_gp(vcpu,
+ "set_cr0: start paging in long"
+ " mode while PAE is disabled\n");
return;
}
kvm_arch_ops->get_cs_db_l_bits(vcpu, &cs_db, &cs_l);
if (cs_l) {
- printk(KERN_DEBUG "set_cr0: #GP, start paging "
- "in long mode while CS.L == 1\n");
- inject_gp(vcpu);
+ inject_gp(vcpu,
+ "set_cr0: start paging "
+ "in long mode while CS.L == 1\n");
return;
}
} else
#endif
if (is_pae(vcpu) && !load_pdptrs(vcpu, vcpu->cr3)) {
- printk(KERN_DEBUG "set_cr0: #GP, pdptrs "
- "reserved bits\n");
- inject_gp(vcpu);
+ inject_gp(vcpu, "set_cr0: pdptrs reserved bits\n");
return;
}
@@ -532,28 +536,24 @@ void set_cr4(struct kvm_vcpu *vcpu, unsi
void set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
{
if (cr4 & CR4_RESERVED_BITS) {
- printk(KERN_DEBUG "set_cr4: #GP, reserved bits\n");
- inject_gp(vcpu);
+ inject_gp(vcpu, "set_cr4: reserved bits\n");
return;
}
if (is_long_mode(vcpu)) {
if (!(cr4 & X86_CR4_PAE)) {
- printk(KERN_DEBUG "set_cr4: #GP, clearing PAE while "
- "in long mode\n");
- inject_gp(vcpu);
+ inject_gp(vcpu, "set_cr4: clearing PAE while "
+ "in long mode\n");
return;
}
} else if (is_paging(vcpu) && !is_pae(vcpu) && (cr4 & X86_CR4_PAE)
&& !load_pdptrs(vcpu, vcpu->cr3)) {
- printk(KERN_DEBUG "set_cr4: #GP, pdptrs reserved bits\n");
- inject_gp(vcpu);
+ inject_gp(vcpu, "set_cr4: pdptrs reserved bits\n");
return;
}
if (cr4 & X86_CR4_VMXE) {
- printk(KERN_DEBUG "set_cr4: #GP, setting VMXE\n");
- inject_gp(vcpu);
+ inject_gp(vcpu, "set_cr4: setting VMXE\n");
return;
}
kvm_arch_ops->set_cr4(vcpu, cr4);
@@ -566,29 +566,24 @@ void set_cr3(struct kvm_vcpu *vcpu, unsi
{
if (is_long_mode(vcpu)) {
if (cr3 & CR3_L_MODE_RESERVED_BITS) {
- printk(KERN_DEBUG "set_cr3: #GP, reserved bits\n");
- inject_gp(vcpu);
+ inject_gp(vcpu, "set_cr3: reserved bits\n");
return;
}
} else {
if (is_pae(vcpu)) {
if (cr3 & CR3_PAE_RESERVED_BITS) {
- printk(KERN_DEBUG
- "set_cr3: #GP, reserved bits\n");
- inject_gp(vcpu);
+ inject_gp(vcpu, "set_cr3: reserved bits\n");
return;
}
if (is_paging(vcpu) && !load_pdptrs(vcpu, cr3)) {
- printk(KERN_DEBUG "set_cr3: #GP, pdptrs "
+ inject_gp(vcpu, "set_cr3: pdptrs "
"reserved bits\n");
- inject_gp(vcpu);
return;
}
} else {
if (cr3 & CR3_NONPAE_RESERVED_BITS) {
- printk(KERN_DEBUG
- "set_cr3: #GP, reserved bits\n");
- inject_gp(vcpu);
+ inject_gp(vcpu, "set_cr3: reserved bits\n");
+
return;
}
}
@@ -606,7 +601,7 @@ void set_cr3(struct kvm_vcpu *vcpu, unsi
* to debug) behavior on the guest side.
*/
if (unlikely(!gfn_to_memslot(vcpu->kvm, cr3 >> PAGE_SHIFT)))
- inject_gp(vcpu);
+ inject_gp(vcpu, "set_cr3: 0x%lx not valid guest phys", cr3);
else
vcpu->mmu.new_cr3(vcpu);
spin_unlock(&vcpu->kvm->lock);
@@ -616,8 +611,7 @@ void set_cr8(struct kvm_vcpu *vcpu, unsi
void set_cr8(struct kvm_vcpu *vcpu, unsigned long cr8)
{
if (cr8 & CR8_RESERVED_BITS) {
- printk(KERN_DEBUG "set_cr8: #GP, reserved bits 0x%lx\n", cr8);
- inject_gp(vcpu);
+ inject_gp(vcpu, "set_cr8: reserved bits 0x%lx\n", cr8);
return;
}
vcpu->cr8 = cr8;
@@ -1533,16 +1527,13 @@ static void set_efer(struct kvm_vcpu *vc
static void set_efer(struct kvm_vcpu *vcpu, u64 efer)
{
if (efer & EFER_RESERVED_BITS) {
- printk(KERN_DEBUG "set_efer: 0x%llx #GP, reserved bits\n",
- efer);
- inject_gp(vcpu);
+ inject_gp(vcpu, "set_efer: 0x%llx reserved bits\n", efer);
return;
}
if (is_paging(vcpu)
&& (vcpu->shadow_efer & EFER_LME) != (efer & EFER_LME)) {
- printk(KERN_DEBUG "set_efer: #GP, change LME while paging\n");
- inject_gp(vcpu);
+ inject_gp(vcpu, "set_efer: change LME while paging\n");
return;
}
@@ -1843,8 +1834,7 @@ int kvm_setup_pio(struct kvm_vcpu *vcpu,
/*
* String I/O in reverse. Yuck. Kill the guest, fix later.
*/
- printk(KERN_ERR "kvm: guest string pio down\n");
- inject_gp(vcpu);
+ inject_gp(vcpu, "guest string pio down\n");
return 1;
}
vcpu->run->io.count = now;
@@ -1858,7 +1848,8 @@ int kvm_setup_pio(struct kvm_vcpu *vcpu,
vcpu->pio.guest_pages[i] = page;
spin_unlock(&vcpu->kvm->lock);
if (!page) {
- inject_gp(vcpu);
+ inject_gp(vcpu, "pio: invalid address %#lx\n",
+ address + i * PAGE_SIZE);
free_pio_guest_pages(vcpu);
return 1;
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
next reply other threads:[~2007-07-24 6:47 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-24 6:47 Rusty Russell [this message]
[not found] ` <1185259677.1803.239.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-07-24 7:03 ` [PATCH 2/2] kvm: pr_guest: don't let guest invoke printk() on host Rusty Russell
[not found] ` <1185260620.1803.245.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-07-24 10:19 ` Avi Kivity
[not found] ` <46A5D215.5030301-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-07-24 10:48 ` Rusty Russell
[not found] ` <1185274114.1803.309.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-07-24 11:01 ` Avi Kivity
[not found] ` <46A5DC11.4070400-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-07-24 11:29 ` Rusty Russell
[not found] ` <1185276567.1803.330.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-07-24 12:19 ` Avi Kivity
[not found] ` <46A5EE38.3060703-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-07-25 0:19 ` Rusty Russell
[not found] ` <1185322747.1803.392.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-07-25 6:25 ` Avi Kivity
[not found] ` <46A6ECD4.8040804-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-07-25 6:45 ` Avi Kivity
2007-07-24 10:15 ` [PATCH 1/2] kvm: Insist on a reason when injecting a #GP into a guest Avi Kivity
[not found] ` <46A5D153.9020302-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-07-24 10:41 ` Rusty Russell
[not found] ` <1185273661.1803.300.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-07-24 10:44 ` Avi Kivity
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=1185259677.1803.239.camel@localhost.localdomain \
--to=rusty-8n+1lvoiyb80n/f98k4iww@public.gmane.org \
--cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox