From: Abhinav Srivastava Subject: Re: DMA understanding Date: Thu, 1 Jul 2010 11:38:31 +0530 (IST) Message-ID: <127686.1993.qm@web7905.mail.in.yahoo.com> References: <20100630160222.GC5100@phenom.dumpdata.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <20100630160222.GC5100@phenom.dumpdata.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Konrad Rzeszutek Wilk Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org Hi Konrad,=0A=0AThanks for your reply. You reply was very helpful in unders= tanding the =0ADMA mechanism. The goal of my project is to intercept all DM= A requests issued by guest HVM domains and check for the memory regions (gu= est physical address) mentioned in those requests. This will help detect ma= licious DMA writes specified by malicious drivers. I am trying =0Ato achiev= e this without VT-d support on intel processors.=0A=0AI have some follow up= questions:=0A=0A1. When a guest HVM domain requests DMA operations, it spe= cifies guest physical addresses. Who converts guest physical to host physic= al addresses? Does this conversion happen in Dom0 or hypervisor? Which code= path should I be looking at?=0A=0A2. I am looking at the place where I can= hook into so that I could intercept all DMA requests issued by the HVM gue= st and verify the addresses? Is there any place where all DMA requests come= and then routed to specific devices in QEMU emulation code? If I could hoo= k at the common place, it would be easier to intercept rather putting the c= heck =0Ain each device specific files.=0A=0AI really appreciate for your ti= me.=0A=0AThanks,=0AAbhinav=0A=0A--- On Wed, 30/6/10, Konrad Rzeszutek Wilk = wrote:=0A=0A> From: Konrad Rzeszutek Wilk =0A> Subject: Re: [Xen-devel] DMA understanding=0A> To: "Ab= hinav Srivastava" =0A> Cc: xen-devel@lists.xen= source.com=0A> Date: Wednesday, 30 June, 2010, 9:32 PM=0A> On Tue, Jun 29, = 2010 at 12:10:48AM=0A> +0530, Abhinav Srivastava wrote:=0A> > =0A> > Hi the= re,=0A> > =0A> > I am trying to understand how an HVM guest domain=0A> perf= orms its DMA operations, and how this DMA operations are=0A> intercepted by= the Xen. I wanted to understand both the code=0A> path with and without Vt= -d support (for intel processors).=0A> On looking inside the Xen code, I fo= und that iommu code is=0A> inside the vmx/vtd/ directory only. By seeing th= e code, my=0A> understanding is that when Vt-d is enabled, iommu.c and=0A> = dmar.c inside the vtd directory is the place to look for DMA=0A> operations= . However, I do not understand which code path=0A> inside the hypervisor is= getting used in case of Vt-d is=0A> disabled?=A0 How does Xen intercept gu= est DMA operations=0A> in this case? I am using Xen 3.3 version for my proj= ect (I=0A> admit that it is very old version).=0A> =0A> Lets start without = the Intel VT-d or AMD Vi in the=0A> picture.=0A> =0A> When the QEMU boots u= p an HVM guest, it emulates everything=0A> the guest=0A> sees or does. Whic= h means that when the guest decides to=0A> use the=0A> IDE controller to do= DMA operations, QEMU decodes that=0A> operation=0A> (look in hw/ide.c, sea= rch for 'WIN_READDMA') and it follows=0A> it=0A> through by setting up a ca= llback mechanism that ends up=0A> fetching=0A> the data from wherever the g= uest disk and then triggering=0A> an interrupt=0A> so that the guest notici= es that the DMA finished.=0A> =0A> So in essence the hypervisor does not de= al with guest DMA=0A> at all.=0A> =0A> When you insert an Intel VT-d or AMD= Vi chipset you have=0A> the option=0A> of passing in a native PCI device t= o the guest. If you=0A> don't pass=0A> in a PCI device then you are still u= sing the old=0A> mechanism.=0A> =0A> =0A> _________________________________= ______________=0A> Xen-devel mailing list=0A> Xen-devel@lists.xensource.com= =0A> http://lists.xensource.com/xen-devel=0A> =0A=0A