From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57849) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X2cdG-0006WG-60 for qemu-devel@nongnu.org; Thu, 03 Jul 2014 04:44:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X2cd9-0000AL-7U for qemu-devel@nongnu.org; Thu, 03 Jul 2014 04:44:42 -0400 Received: from mout.web.de ([212.227.15.14]:60932) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X2cd8-0000A9-TS for qemu-devel@nongnu.org; Thu, 03 Jul 2014 04:44:35 -0400 Message-ID: <53B517CD.7090209@web.de> Date: Thu, 03 Jul 2014 10:43:57 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <1404375987-29810-1-git-send-email-tamlokveer@gmail.com> In-Reply-To: <1404375987-29810-1-git-send-email-tamlokveer@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="sUJxgplLRpnK39TjMraFc1SeW0LLNclaB" Subject: Re: [Qemu-devel] [PATCH] ahci: map memory via device's address space instead of address_space_memory List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Le Tan , qemu-devel@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, pbonzini@redhat.com, afaerber@suse.de, mst@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --sUJxgplLRpnK39TjMraFc1SeW0LLNclaB Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable On 2014-07-03 10:26, Le Tan wrote: > In map_page() in hw/ide/ahci.c, replace cpu_physical_memory_map() and > cpu_physical_memory_unmap() with dma_memory_map() and dma_memory_unmap(= ), > because ahci devices should not access memory directly but via their ad= dress > space. Add an AddressSpace parameter to map_page(). In order to call > map_page(), we should pass the AHCIState.as as the AddressSpace argumen= t. BTW, when doing "git grep cpu_physical_memory_map hw", there are some more cases that should be checked (for x86). I suppose vhost is incompatible with an IOMMU, but plain virtio should work, same for vmxnet= =2E Jan >=20 > Signed-off-by: Le Tan > --- > hw/ide/ahci.c | 21 +++++++++++---------- > 1 file changed, 11 insertions(+), 10 deletions(-) >=20 > diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c > index 9bae22e..7bb0a03 100644 > --- a/hw/ide/ahci.c > +++ b/hw/ide/ahci.c > @@ -175,17 +175,18 @@ static void ahci_trigger_irq(AHCIState *s, AHCIDe= vice *d, > ahci_check_irq(s); > } > =20 > -static void map_page(uint8_t **ptr, uint64_t addr, uint32_t wanted) > +static void map_page(AddressSpace *as, uint8_t **ptr, uint64_t addr, > + uint32_t wanted) > { > hwaddr len =3D wanted; > =20 > if (*ptr) { > - cpu_physical_memory_unmap(*ptr, len, 1, len); > + dma_memory_unmap(as, *ptr, len, DMA_DIRECTION_FROM_DEVICE, len= ); > } > =20 > - *ptr =3D cpu_physical_memory_map(addr, &len, 1); > + *ptr =3D dma_memory_map(as, addr, &len, DMA_DIRECTION_FROM_DEVICE)= ; > if (len < wanted) { > - cpu_physical_memory_unmap(*ptr, len, 1, len); > + dma_memory_unmap(as, *ptr, len, DMA_DIRECTION_FROM_DEVICE, len= ); > *ptr =3D NULL; > } > } > @@ -198,24 +199,24 @@ static void ahci_port_write(AHCIState *s, int po= rt, int offset, uint32_t val) > switch (offset) { > case PORT_LST_ADDR: > pr->lst_addr =3D val; > - map_page(&s->dev[port].lst, > + map_page(s->as, &s->dev[port].lst, > ((uint64_t)pr->lst_addr_hi << 32) | pr->lst_addr,= 1024); > s->dev[port].cur_cmd =3D NULL; > break; > case PORT_LST_ADDR_HI: > pr->lst_addr_hi =3D val; > - map_page(&s->dev[port].lst, > + map_page(s->as, &s->dev[port].lst, > ((uint64_t)pr->lst_addr_hi << 32) | pr->lst_addr,= 1024); > s->dev[port].cur_cmd =3D NULL; > break; > case PORT_FIS_ADDR: > pr->fis_addr =3D val; > - map_page(&s->dev[port].res_fis, > + map_page(s->as, &s->dev[port].res_fis, > ((uint64_t)pr->fis_addr_hi << 32) | pr->fis_addr,= 256); > break; > case PORT_FIS_ADDR_HI: > pr->fis_addr_hi =3D val; > - map_page(&s->dev[port].res_fis, > + map_page(s->as, &s->dev[port].res_fis, > ((uint64_t)pr->fis_addr_hi << 32) | pr->fis_addr,= 256); > break; > case PORT_IRQ_STAT: > @@ -1260,9 +1261,9 @@ static int ahci_state_post_load(void *opaque, int= version_id) > ad =3D &s->dev[i]; > AHCIPortRegs *pr =3D &ad->port_regs; > =20 > - map_page(&ad->lst, > + map_page(s->as, &ad->lst, > ((uint64_t)pr->lst_addr_hi << 32) | pr->lst_addr, 102= 4); > - map_page(&ad->res_fis, > + map_page(s->as, &ad->res_fis, > ((uint64_t)pr->fis_addr_hi << 32) | pr->fis_addr, 256= ); > /* > * All pending i/o should be flushed out on a migrate. However= , >=20 --sUJxgplLRpnK39TjMraFc1SeW0LLNclaB Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iEYEARECAAYFAlO1F9AACgkQitSsb3rl5xSFUwCg2wef87+3cdyYzUBboENHVx6x 1U0AnitbrnjjnPtWEk0PCNrj3IMGS2Jx =tIbX -----END PGP SIGNATURE----- --sUJxgplLRpnK39TjMraFc1SeW0LLNclaB--