Skip to contentSkip to conversation

kvm: fix Win2k boot without KVM

PATCH NAK Blue Swirl 2 participants 10 messages Nov 3, 2012

lore
Share & tools
lore

Blue Swirl

author
#0 lore raw

PATCH 1/1 kvm: fix Win2k boot without KVM

Ignore accesses to VAPIC when kvmvapic is not enabled.

---
 hw/kvmvapic.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
hw/kvmvapic.c +4 -3
index dc111ee..a97d532 100644
@@ -612,6 +612,9 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t data,
     hwaddr rom_paddr;
     VAPICROMState *s = opaque;
 
+    if (!kvm_irqchip_in_kernel()) {
+        return;
+    }
     cpu_synchronize_state(env);
 
     /*
@@ -665,9 +668,7 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t data,
         break;
     default:
     case 4:
-        if (!kvm_irqchip_in_kernel()) {
-            apic_poll_irq(env->apic_state);
-        }
+        apic_poll_irq(env->apic_state);
         break;
     }
 }
Signature · 1 line
1.7.2.5
#1 lore raw
Quoted 24 lines · Blue Swirl

Ignore accesses to VAPIC when kvmvapic is not enabled.

---
 hw/kvmvapic.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
hw/kvmvapic.c +3 -0
index dc111ee..a97d532 100644
@@ -612,6 +612,9 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t data,
     hwaddr rom_paddr;
     VAPICROMState *s = opaque;
 
+    if (!kvm_irqchip_in_kernel()) {
+        return;
+    }
     cpu_synchronize_state(env);
 
     /*

hw/kvmvapic.c static void vapic_write(void *opaque, hwaddr addr, uint64_t data, · line 674

Quoted 10 lines
hw/kvmvapic.c +1 -3
@@ -665,9 +668,7 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t data,
         break;
     default:
     case 4:
-        if (!kvm_irqchip_in_kernel()) {
-            apic_poll_irq(env->apic_state);
-        }
+        apic_poll_irq(env->apic_state);
         break;
     }
 }

NACK, I'm already debugging the true reason (related to code patching).

Jan

author
#2 lore raw
Quoted 22 lines · Jan Kiszka
Quoted 21 lines · Blue Swirl

Ignore accesses to VAPIC when kvmvapic is not enabled.

---
 hw/kvmvapic.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
hw/kvmvapic.c +3 -0
index dc111ee..a97d532 100644
@@ -612,6 +612,9 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t data,
     hwaddr rom_paddr;
     VAPICROMState *s = opaque;
 
+    if (!kvm_irqchip_in_kernel()) {
+        return;
+    }
     cpu_synchronize_state(env);
 
Quoted 15 lines

hw/kvmvapic.c static void vapic_write(void *opaque, hwaddr addr, uint64_t data, · line 674

Quoted 13 lines
hw/kvmvapic.c +1 -3
     /*
@@ -665,9 +668,7 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t data,
         break;
     default:
     case 4:
-        if (!kvm_irqchip_in_kernel()) {
-            apic_poll_irq(env->apic_state);
-        }
+        apic_poll_irq(env->apic_state);
         break;
     }
 }

NACK, I'm already debugging the true reason (related to code patching).

This is a minimal fix that lets Win2k boot, now it does not work at all. I think it should be applied for 1.3, it can be reverted when (if) you find a better fix. There's no hurry though.

Quoted 3 lines

Jan

#3 lore raw
Quoted 39 lines · Blue Swirl
Quoted 22 lines · Jan Kiszka
Quoted 21 lines · Blue Swirl

Ignore accesses to VAPIC when kvmvapic is not enabled.

---
 hw/kvmvapic.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
hw/kvmvapic.c +3 -0
index dc111ee..a97d532 100644
@@ -612,6 +612,9 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t data,
     hwaddr rom_paddr;
     VAPICROMState *s = opaque;
 
+    if (!kvm_irqchip_in_kernel()) {
+        return;
+    }
     cpu_synchronize_state(env);
 
Quoted 15 lines

hw/kvmvapic.c static void vapic_write(void *opaque, hwaddr addr, uint64_t data, · line 674

Quoted 13 lines
hw/kvmvapic.c +1 -3
     /*
@@ -665,9 +668,7 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t data,
         break;
     default:
     case 4:
-        if (!kvm_irqchip_in_kernel()) {
-            apic_poll_irq(env->apic_state);
-        }
+        apic_poll_irq(env->apic_state);
         break;
     }
 }

NACK, I'm already debugging the true reason (related to code patching).

Quoted 3 lines

This is a minimal fix that lets Win2k boot, now it does not work at all. I think it should be applied for 1.3, it can be reverted when (if) you find a better fix. There's no hurry though.

If you want to disable it, flip apic.vapic for !kvm_enabled. Your patch affects user space APIC with KVM as well, though that is perfectly fine.

But first of all give this some days as I just started.

Jan

author
#4 lore raw
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Blue Swirl
Quoted 37 lines · Jan Kiszka
Quoted 24 lines · Blue Swirl

Ignore accesses to VAPIC when kvmvapic is not enabled.

---
 hw/kvmvapic.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
hw/kvmvapic.c +3 -0
index dc111ee..a97d532 100644
@@ -612,6 +612,9 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t data,
     hwaddr rom_paddr;
     VAPICROMState *s = opaque;
 
+    if (!kvm_irqchip_in_kernel()) {
+        return;
+    }
     cpu_synchronize_state(env);
 
     /*

hw/kvmvapic.c static void vapic_write(void *opaque, hwaddr addr, uint64_t data, · line 674

Quoted 10 lines
hw/kvmvapic.c +1 -3
@@ -665,9 +668,7 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t data,
         break;
     default:
     case 4:
-        if (!kvm_irqchip_in_kernel()) {
-            apic_poll_irq(env->apic_state);
-        }
+        apic_poll_irq(env->apic_state);
         break;
     }
 }

NACK, I'm already debugging the true reason (related to code patching).

Quoted 6 lines
Quoted 3 lines

This is a minimal fix that lets Win2k boot, now it does not work at all. I think it should be applied for 1.3, it can be reverted when (if) you find a better fix. There's no hurry though.

If you want to disable it, flip apic.vapic for !kvm_enabled. Your patch affects user space APIC with KVM as well, though that is perfectly fine.

I thought about that, but kvm_enabled and kvm_kernel_irqchip may not be initialized yet during vapic_init().

Quoted 2 lines

But first of all give this some days as I just started.

Sure.

Quoted 4 lines

Jan

#5 lore raw
In reply to Jan Kiszka
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Blue Swirl
Quoted 37 lines · Jan Kiszka
Quoted 24 lines · Blue Swirl

Ignore accesses to VAPIC when kvmvapic is not enabled.

---
 hw/kvmvapic.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
hw/kvmvapic.c +3 -0
index dc111ee..a97d532 100644
@@ -612,6 +612,9 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t data,
     hwaddr rom_paddr;
     VAPICROMState *s = opaque;
 
+    if (!kvm_irqchip_in_kernel()) {
+        return;
+    }
     cpu_synchronize_state(env);
 
     /*

hw/kvmvapic.c static void vapic_write(void *opaque, hwaddr addr, uint64_t data, · line 674

Quoted 10 lines
hw/kvmvapic.c +1 -3
@@ -665,9 +668,7 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t data,
         break;
     default:
     case 4:
-        if (!kvm_irqchip_in_kernel()) {
-            apic_poll_irq(env->apic_state);
-        }
+        apic_poll_irq(env->apic_state);
         break;
     }
 }

NACK, I'm already debugging the true reason (related to code patching).

Quoted 8 lines
Quoted 3 lines

This is a minimal fix that lets Win2k boot, now it does not work at all. I think it should be applied for 1.3, it can be reverted when (if) you find a better fix. There's no hurry though.

If you want to disable it, flip apic.vapic for !kvm_enabled. Your patch affects user space APIC with KVM as well, though that is perfectly fine.

But first of all give this some days as I just started.

...even more as this regression may not be related to the introduction of the kvmvapic: My original test case for the kvmvapic under TCG, WinXP, is now also broken, causing a segfault too.

What I'm seeing is that tb_invalidate_phys_page_range in patch_instruction no longer seems to detect that the currently executed tb was just changed. Any ideas what may cause this are welcome.

Jan

author
#6 lore raw
Quoted 50 lines · Jan Kiszka
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Blue Swirl
Quoted 37 lines · Jan Kiszka
Quoted 24 lines · Blue Swirl

Ignore accesses to VAPIC when kvmvapic is not enabled.

---
 hw/kvmvapic.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
hw/kvmvapic.c +3 -0
index dc111ee..a97d532 100644
@@ -612,6 +612,9 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t data,
     hwaddr rom_paddr;
     VAPICROMState *s = opaque;
 
+    if (!kvm_irqchip_in_kernel()) {
+        return;
+    }
     cpu_synchronize_state(env);
 
     /*

hw/kvmvapic.c static void vapic_write(void *opaque, hwaddr addr, uint64_t data, · line 674

Quoted 10 lines
hw/kvmvapic.c +1 -3
@@ -665,9 +668,7 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t data,
         break;
     default:
     case 4:
-        if (!kvm_irqchip_in_kernel()) {
-            apic_poll_irq(env->apic_state);
-        }
+        apic_poll_irq(env->apic_state);
         break;
     }
 }

NACK, I'm already debugging the true reason (related to code patching).

Quoted 8 lines
Quoted 3 lines

This is a minimal fix that lets Win2k boot, now it does not work at all. I think it should be applied for 1.3, it can be reverted when (if) you find a better fix. There's no hurry though.

If you want to disable it, flip apic.vapic for !kvm_enabled. Your patch affects user space APIC with KVM as well, though that is perfectly fine.

But first of all give this some days as I just started.

Quoted 7 lines

...even more as this regression may not be related to the introduction of the kvmvapic: My original test case for the kvmvapic under TCG, WinXP, is now also broken, causing a segfault too.

What I'm seeing is that tb_invalidate_phys_page_range in patch_instruction no longer seems to detect that the currently executed tb was just changed. Any ideas what may cause this are welcome.

My theory is that the kvmvapic ROM tries to make the PIO hypercalls, but the PIO devices in QEMU are not ready, maybe not initialized at all.

Quoted 3 lines

Jan

#7 lore raw
Quoted 55 lines · Blue Swirl
Quoted 54 lines · Jan Kiszka
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Blue Swirl
Quoted 37 lines · Jan Kiszka
Quoted 24 lines · Blue Swirl

Ignore accesses to VAPIC when kvmvapic is not enabled.

---
 hw/kvmvapic.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
hw/kvmvapic.c +3 -0
index dc111ee..a97d532 100644
@@ -612,6 +612,9 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t data,
     hwaddr rom_paddr;
     VAPICROMState *s = opaque;
 
+    if (!kvm_irqchip_in_kernel()) {
+        return;
+    }
     cpu_synchronize_state(env);
 
     /*

hw/kvmvapic.c static void vapic_write(void *opaque, hwaddr addr, uint64_t data, · line 674

Quoted 10 lines
hw/kvmvapic.c +1 -3
@@ -665,9 +668,7 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t data,
         break;
     default:
     case 4:
-        if (!kvm_irqchip_in_kernel()) {
-            apic_poll_irq(env->apic_state);
-        }
+        apic_poll_irq(env->apic_state);
         break;
     }
 }

NACK, I'm already debugging the true reason (related to code patching).

Quoted 8 lines
Quoted 3 lines

This is a minimal fix that lets Win2k boot, now it does not work at all. I think it should be applied for 1.3, it can be reverted when (if) you find a better fix. There's no hurry though.

If you want to disable it, flip apic.vapic for !kvm_enabled. Your patch affects user space APIC with KVM as well, though that is perfectly fine.

But first of all give this some days as I just started.

...even more as this regression may not be related to the introduction of the kvmvapic: My original test case for the kvmvapic under TCG, WinXP, is now also broken, causing a segfault too.

Quoted 7 lines
Quoted 3 lines

What I'm seeing is that tb_invalidate_phys_page_range in patch_instruction no longer seems to detect that the currently executed tb was just changed. Any ideas what may cause this are welcome.

My theory is that the kvmvapic ROM tries to make the PIO hypercalls, but the PIO devices in QEMU are not ready, maybe not initialized at all.

You are on the wrong track: All is set up, the first TPR accesses are happening, and the kvmvapic is trying to patch them away. In TCG mode, this requires a flush of the current TB afterward. And this somehow fails, causing various issues as executing resumes at invalid addresses.

Jan

PS: A good hash is e.g. b34bd5e5c8f356ec206e5a306ee3a9b6f42c4315, long after the kvmvapic merge.

PPS: Bisecting in QEMU is no fun - too many transient build breakages.

#8 lore raw
Quoted 69 lines · Jan Kiszka
Quoted 55 lines · Blue Swirl
Quoted 54 lines · Jan Kiszka
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Blue Swirl
Quoted 37 lines · Jan Kiszka
Quoted 24 lines · Blue Swirl

Ignore accesses to VAPIC when kvmvapic is not enabled.

---
 hw/kvmvapic.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
hw/kvmvapic.c +3 -0
index dc111ee..a97d532 100644
@@ -612,6 +612,9 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t data,
     hwaddr rom_paddr;
     VAPICROMState *s = opaque;
 
+    if (!kvm_irqchip_in_kernel()) {
+        return;
+    }
     cpu_synchronize_state(env);
 
     /*

hw/kvmvapic.c static void vapic_write(void *opaque, hwaddr addr, uint64_t data, · line 674

Quoted 10 lines
hw/kvmvapic.c +1 -3
@@ -665,9 +668,7 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t data,
         break;
     default:
     case 4:
-        if (!kvm_irqchip_in_kernel()) {
-            apic_poll_irq(env->apic_state);
-        }
+        apic_poll_irq(env->apic_state);
         break;
     }
 }

NACK, I'm already debugging the true reason (related to code patching).

Quoted 8 lines
Quoted 3 lines

This is a minimal fix that lets Win2k boot, now it does not work at all. I think it should be applied for 1.3, it can be reverted when (if) you find a better fix. There's no hurry though.

If you want to disable it, flip apic.vapic for !kvm_enabled. Your patch affects user space APIC with KVM as well, though that is perfectly fine.

But first of all give this some days as I just started.

...even more as this regression may not be related to the introduction of the kvmvapic: My original test case for the kvmvapic under TCG, WinXP, is now also broken, causing a segfault too.

Quoted 7 lines
Quoted 3 lines

What I'm seeing is that tb_invalidate_phys_page_range in patch_instruction no longer seems to detect that the currently executed tb was just changed. Any ideas what may cause this are welcome.

My theory is that the kvmvapic ROM tries to make the PIO hypercalls, but the PIO devices in QEMU are not ready, maybe not initialized at all.

You are on the wrong track: All is set up, the first TPR accesses are happening, and the kvmvapic is trying to patch them away. In TCG mode, this requires a flush of the current TB afterward. And this somehow fails, causing various issues as executing resumes at invalid addresses.

Quoted 7 lines

Jan

PS: A good hash is e.g. b34bd5e5c8f356ec206e5a306ee3a9b6f42c4315, long after the kvmvapic merge.

PPS: Bisecting in QEMU is no fun - too many transient build breakages.

Bisection ended here: 0b57e287138728f72d88b06e69b970c5d745c44a (cpu_physical_memory_write_rom() needs to do TB invalidates).

The problem is that this invalidation happens with is_cpu_write_access=0, "consuming" the current TB for the final invalidation in patch_instruction with is_cpu_write_access=1. So, instead of generating a new TB and resuming execution there, the guest jumps back to an invalidated TB.

I have a patch, but it moves half of tb_invalidate_phys_page_range to patch_instruction. Need to check if that can be solved cleaner.

Jan

#9 lore raw
Quoted 87 lines · Jan Kiszka
Quoted 69 lines · Jan Kiszka
Quoted 55 lines · Blue Swirl
Quoted 54 lines · Jan Kiszka
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Blue Swirl
Quoted 37 lines · Jan Kiszka
Quoted 24 lines · Blue Swirl

Ignore accesses to VAPIC when kvmvapic is not enabled.

---
 hw/kvmvapic.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
hw/kvmvapic.c +3 -0
index dc111ee..a97d532 100644
@@ -612,6 +612,9 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t data,
     hwaddr rom_paddr;
     VAPICROMState *s = opaque;
 
+    if (!kvm_irqchip_in_kernel()) {
+        return;
+    }
     cpu_synchronize_state(env);
 
     /*

hw/kvmvapic.c static void vapic_write(void *opaque, hwaddr addr, uint64_t data, · line 674

Quoted 10 lines
hw/kvmvapic.c +1 -3
@@ -665,9 +668,7 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t data,
         break;
     default:
     case 4:
-        if (!kvm_irqchip_in_kernel()) {
-            apic_poll_irq(env->apic_state);
-        }
+        apic_poll_irq(env->apic_state);
         break;
     }
 }

NACK, I'm already debugging the true reason (related to code patching).

Quoted 8 lines
Quoted 3 lines

This is a minimal fix that lets Win2k boot, now it does not work at all. I think it should be applied for 1.3, it can be reverted when (if) you find a better fix. There's no hurry though.

If you want to disable it, flip apic.vapic for !kvm_enabled. Your patch affects user space APIC with KVM as well, though that is perfectly fine.

But first of all give this some days as I just started.

...even more as this regression may not be related to the introduction of the kvmvapic: My original test case for the kvmvapic under TCG, WinXP, is now also broken, causing a segfault too.

Quoted 7 lines
Quoted 3 lines

What I'm seeing is that tb_invalidate_phys_page_range in patch_instruction no longer seems to detect that the currently executed tb was just changed. Any ideas what may cause this are welcome.

My theory is that the kvmvapic ROM tries to make the PIO hypercalls, but the PIO devices in QEMU are not ready, maybe not initialized at all.

You are on the wrong track: All is set up, the first TPR accesses are happening, and the kvmvapic is trying to patch them away. In TCG mode, this requires a flush of the current TB afterward. And this somehow fails, causing various issues as executing resumes at invalid addresses.

Quoted 7 lines

Jan

PS: A good hash is e.g. b34bd5e5c8f356ec206e5a306ee3a9b6f42c4315, long after the kvmvapic merge.

PPS: Bisecting in QEMU is no fun - too many transient build breakages.

Bisection ended here: 0b57e287138728f72d88b06e69b970c5d745c44a (cpu_physical_memory_write_rom() needs to do TB invalidates).

The problem is that this invalidation happens with is_cpu_write_access=0, "consuming" the current TB for the final invalidation in patch_instruction with is_cpu_write_access=1. So, instead of generating a new TB and resuming execution there, the guest jumps back to an invalidated TB.

Quoted 5 lines

I have a patch, but it moves half of tb_invalidate_phys_page_range to patch_instruction. Need to check if that can be solved cleaner.

Jan

Unrelated, just to note it:

The boot-up screen of Win2k is drawn much slower with git head than with 1.2 e.g. My bet is: some regression of recent memory region changes. Requires another bisection round... :-/

Jan