From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anthony Liguori Subject: Re: [PATCH 07/10] Add RAM -> physical addr mapping in MCE simulation Date: Wed, 20 Oct 2010 14:56:32 -0500 Message-ID: <4CBF4970.5040504@linux.vnet.ibm.com> References: <9867fba99ce6108dcc6684d707aa30681b46f5f8.1287596626.git.mtosatti@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Anthony Liguori , qemu-devel@nongnu.org, kvm@vger.kernel.org, Huang Ying , Avi Kivity To: Marcelo Tosatti Return-path: Received: from e38.co.us.ibm.com ([32.97.110.159]:60826 "EHLO e38.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755060Ab0JTT4i (ORCPT ); Wed, 20 Oct 2010 15:56:38 -0400 Received: from d03relay01.boulder.ibm.com (d03relay01.boulder.ibm.com [9.17.195.226]) by e38.co.us.ibm.com (8.14.4/8.13.1) with ESMTP id o9KJmaaG019318 for ; Wed, 20 Oct 2010 13:48:36 -0600 Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by d03relay01.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o9KJuXjG148766 for ; Wed, 20 Oct 2010 13:56:33 -0600 Received: from d03av03.boulder.ibm.com (loopback [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o9KJuWFW007970 for ; Wed, 20 Oct 2010 13:56:33 -0600 In-Reply-To: <9867fba99ce6108dcc6684d707aa30681b46f5f8.1287596626.git.mtosatti@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 10/20/2010 12:43 PM, Marcelo Tosatti wrote: > From: Huang Ying > > 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 > Signed-off-by: Huang Ying > Signed-off-by: Marcelo Tosatti > Signed-off-by: Avi Kivity > --- > kvm-all.c | 18 ++++++++++++++++++ > kvm.h | 6 ++++++ > 2 files changed, 24 insertions(+), 0 deletions(-) > > diff --git a/kvm-all.c b/kvm-all.c > index 1cc696f..37b99c7 100644 > --- a/kvm-all.c > +++ b/kvm-all.c > @@ -137,6 +137,24 @@ static KVMSlot *kvm_lookup_overlapping_slot(KVMState *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; > + } > + } > This is bogus. There isn't one mapping from ram_addr_t to target_phys_addr_t. There may be many because or RAM aliasing. Using KVMSlot is also wrong. This is a function that belongs in exec.c. Regards, Anthony Liguori > + return 0; > +} > + > static int kvm_set_user_memory_region(KVMState *s, KVMSlot *slot) > { > struct kvm_userspace_memory_region mem; > diff --git a/kvm.h b/kvm.h > index 50b6c01..b2fb3af 100644 > --- a/kvm.h > +++ b/kvm.h > @@ -174,6 +174,12 @@ static inline void cpu_synchronize_post_init(CPUState *env) > } > } > > + > +#if !defined(CONFIG_USER_ONLY) > +int kvm_physical_memory_addr_from_ram(KVMState *s, ram_addr_t ram_addr, > + target_phys_addr_t *phys_addr); > +#endif > + > #endif > int kvm_set_ioeventfd_mmio_long(int fd, uint32_t adr, uint32_t val, bool assign); > >