qemu-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Is there a good method to convert guest machine's user virtual addre


From: ckim
Subject: RE: Is there a good method to convert guest machine's user virtual address to qemu host's virtual address?
Date: Thu, 15 Jul 2021 14:05:07 +0900

Hello Peter Maydell,

Thank you for the confirmation.
But with more thoughts, in our case, the accelerator (which is risc-v based and 
has special hardware for acceleration) connected to qemu virtual machine should 
access memory many times like a processor with many cores does. And the 
'address' information passed to the accelerator model contains tables 
containing 'addresses' of codes and data and they are all virtual addresses, 
and will be setup by the application running on OS. So I realized just using 
'guest physical to host virtual' offset isn't enough because the contiguous 
virtual address range can be physically discontiguos as you said and this 
'adding offset' scheme isn't reliable. We need translation for each page table. 
(for baremetal case, it was ok because the memory range of an array or data is 
always contiguous).
Actually, in actual hardware we will have iommu (arm's SMMU MMU-600) so after 
discussion with others, I concluded I'll have to somehow ask the kernel to 
create a page table entry when we need it (when launching work to the 
accelerator) and let the iommu to use the same table entry our arm64 core uses 
for the job(context)(I've analyzed Habanalab's goya chip linux driver last 
year, though for many parts it was difficult for me to understand, and the code 
included page table setup for each context to be run on its accelerator). I 
guess the driver should support this page table setup for the arm processor's 
MMU and for the SMMU through kernel mm functions. 
I guess this will be possible in qemu. I found in hw/arm/virt.c, there is iommu 
instantiation for PCI (default is none). Do you think I should instantiate SMMU 
for the accelerator and let it use this SMMU? And if there is any qemu 
peripheral model(using iommu, preferably arm SMMU) or a good document, please 
let me know.

Thank you,

Chan Kim

> -----Original Message-----
> From: Peter Maydell <peter.maydell@linaro.org>
> Sent: Wednesday, July 14, 2021 10:10 PM
> To: Chan Kim <ckim@etri.re.kr>
> Cc: qemu-discuss <qemu-discuss@nongnu.org>
> Subject: Re: Is there a good method to convert guest machine's user
> virtual address to qemu host's virtual address?
> 
> On Wed, 14 Jul 2021 at 13:12, <ckim@etri.re.kr> wrote:
> >
> > On second thought, I guess the application should convert the virtual
> address to physical address (by reading the page table) and write the
> value to the register.
> 
> Yes. Generally models that emulate real devices will always operate on
> physical addresses, because in hardware they are separate from the CPU and
> don't have access to the virtual-to-physical translation that the CPU does.
> It is possible to design purely virtual hardware that wants to take a
> virtual address, but this is a bad idea:
> a buffer that's a contiguous lump of virtual memory could be non-
> contiguous in physical memory if it spans multiple pages; and QEMU's APIs
> are not designed to make it easy to do virtual-to-physical lookups from a
> device model.
> 
> thanks
> -- PMM







reply via email to

[Prev in Thread] Current Thread [Next in Thread]