* [PATCH] Add RAM -> physical addr mapping in MCE simulation
@ 2010-09-19 1:00 Huang Ying
2010-09-20 16:10 ` Marcelo Tosatti
0 siblings, 1 reply; 3+ messages in thread
From: Huang Ying @ 2010-09-19 1:00 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: kvm@vger.kernel.org, Andi Kleen, Dean Nelson
In QEMU-KVM, physical address != RAM address. While MCE simulation
needs physical address instead of RAM address. So
kvm_physical_memory_addr_from_ram() is implemented to do the
conversion, and it is invoked before being filled in the IA32_MCi_ADDR
MSR.
Reported-by: Dean Nelson <dnelson@redhat.com>
Signed-off-by: Huang Ying <ying.huang@intel.com>
---
kvm-all.c | 18 ++++++++++++++++++
kvm.h | 3 +++
qemu-kvm.c | 13 ++++++++++---
3 files changed, 31 insertions(+), 3 deletions(-)
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -1137,12 +1137,15 @@ static void sigbus_handler(int n, struct
if (first_cpu->mcg_cap && siginfo->ssi_addr
&& siginfo->ssi_code == BUS_MCEERR_AO) {
uint64_t status;
+ void *vaddr;
+ ram_addr_t ram_addr;
unsigned long paddr;
CPUState *cenv;
/* Hope we are lucky for AO MCE */
- if (do_qemu_ram_addr_from_host((void *)(intptr_t)siginfo->ssi_addr,
- &paddr)) {
+ vaddr = (void *)(intptr_t)siginfo->ssi_addr;
+ if (do_qemu_ram_addr_from_host(vaddr, &ram_addr) ||
+ !kvm_physical_memory_addr_from_ram(kvm_state, ram_addr, &paddr)) {
fprintf(stderr, "Hardware memory error for memory used by "
"QEMU itself instead of guest system!: %llx\n",
(unsigned long long)siginfo->ssi_addr);
@@ -1316,6 +1319,8 @@ static void kvm_on_sigbus(CPUState *env,
struct kvm_x86_mce mce = {
.bank = 9,
};
+ void *vaddr;
+ ram_addr_t ram_addr;
unsigned long paddr;
int r;
@@ -1347,7 +1352,9 @@ static void kvm_on_sigbus(CPUState *env,
mce.misc = (MCM_ADDR_PHYS << 6) | 0xc;
mce.mcg_status = MCG_STATUS_MCIP | MCG_STATUS_RIPV;
}
- if (do_qemu_ram_addr_from_host((void *)siginfo->si_addr, &paddr)) {
+ vaddr = (void *)siginfo->si_addr;
+ if (do_qemu_ram_addr_from_host(vaddr, &ram_addr) ||
+ !kvm_physical_memory_addr_from_ram(kvm_state, ram_addr, &paddr)) {
fprintf(stderr, "Hardware memory error for memory used by "
"QEMU itself instaed of guest system!\n");
/* Hope we are lucky for AO MCE */
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -141,6 +141,24 @@ static KVMSlot *kvm_lookup_overlapping_s
return found;
}
+int kvm_physical_memory_addr_from_ram(KVMState *s, ram_addr_t ram_addr,
+ target_phys_addr_t *phys_addr)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
+ KVMSlot *mem = &s->slots[i];
+
+ if (ram_addr >= mem->phys_offset &&
+ ram_addr < mem->phys_offset + mem->memory_size) {
+ *phys_addr = mem->start_addr + (ram_addr - mem->phys_offset);
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
static int kvm_set_user_memory_region(KVMState *s, KVMSlot *slot)
{
struct kvm_userspace_memory_region mem;
--- a/kvm.h
+++ b/kvm.h
@@ -195,4 +195,7 @@ int kvm_set_irqfd(int gsi, int fd, bool
#endif
int kvm_set_ioeventfd_pio_word(int fd, uint16_t adr, uint16_t val, bool assign);
+
+int kvm_physical_memory_addr_from_ram(KVMState *s, ram_addr_t ram_addr,
+ target_phys_addr_t *phys_addr);
#endif
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Add RAM -> physical addr mapping in MCE simulation
2010-09-19 1:00 [PATCH] Add RAM -> physical addr mapping in MCE simulation Huang Ying
@ 2010-09-20 16:10 ` Marcelo Tosatti
2010-09-27 1:12 ` Huang Ying
0 siblings, 1 reply; 3+ messages in thread
From: Marcelo Tosatti @ 2010-09-20 16:10 UTC (permalink / raw)
To: Huang Ying; +Cc: Avi Kivity, kvm@vger.kernel.org, Andi Kleen, Dean Nelson
On Sun, Sep 19, 2010 at 09:00:33AM +0800, Huang Ying wrote:
> In QEMU-KVM, physical address != RAM address. While MCE simulation
> needs physical address instead of RAM address. So
> kvm_physical_memory_addr_from_ram() is implemented to do the
> conversion, and it is invoked before being filled in the IA32_MCi_ADDR
> MSR.
>
> Reported-by: Dean Nelson <dnelson@redhat.com>
> Signed-off-by: Huang Ying <ying.huang@intel.com>
Applied, thanks.
Can you please submit the code necessary to run the test suite upstream?
Is there anything else needed other than p2v monitor command?
TIA
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Add RAM -> physical addr mapping in MCE simulation
2010-09-20 16:10 ` Marcelo Tosatti
@ 2010-09-27 1:12 ` Huang Ying
0 siblings, 0 replies; 3+ messages in thread
From: Huang Ying @ 2010-09-27 1:12 UTC (permalink / raw)
To: Marcelo Tosatti, Zheng, Shaohui, You Yongkang
Cc: Avi Kivity, kvm@vger.kernel.org, Andi Kleen, Dean Nelson
Hi, Marcelo,
On Tue, 2010-09-21 at 00:10 +0800, Marcelo Tosatti wrote:
> On Sun, Sep 19, 2010 at 09:00:33AM +0800, Huang Ying wrote:
> > In QEMU-KVM, physical address != RAM address. While MCE simulation
> > needs physical address instead of RAM address. So
> > kvm_physical_memory_addr_from_ram() is implemented to do the
> > conversion, and it is invoked before being filled in the IA32_MCi_ADDR
> > MSR.
> >
> > Reported-by: Dean Nelson <dnelson@redhat.com>
> > Signed-off-by: Huang Ying <ying.huang@intel.com>
>
> Applied, thanks.
>
> Can you please submit the code necessary to run the test suite upstream?
> Is there anything else needed other than p2v monitor command?
The only missing part is p2v monitor command. I will re-post it.
Do you want to merge the test suite into kvm autotest tool? If so,
Shaohui can help to do that. But it seems that he is busy on some other
project now.
Best Regards,
Huang Ying
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-09-27 1:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-19 1:00 [PATCH] Add RAM -> physical addr mapping in MCE simulation Huang Ying
2010-09-20 16:10 ` Marcelo Tosatti
2010-09-27 1:12 ` Huang Ying
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox