qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* Re: [Qemu-devel] [PATCH] ahci: map memory via device's address space instead of address_space_memory
@ 2015-02-26  5:13 Jordan Hargrave
  2015-02-26 14:45 ` Stefan Hajnoczi
  2015-03-12 17:41 ` John Snow
  0 siblings, 2 replies; 20+ messages in thread
From: Jordan Hargrave @ 2015-02-26  5:13 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 516 bytes --]

Referencing this old thread:
https://lists.nongnu.org/archive/html/qemu-devel/2014-07/msg00606.html

I've run into an issue recently with testing q35 DMAR/intel iommu with ahci
driver.  My ahci driver writes the upper-32 bits (PORT_FIS_ADDR_HI) first
then the lower 32-bits (PORT_FIS_ADDR).

The contents of PORT_FIS_ADDR therefore are stale when the PORT_FIS_ADDR_HI
write calls map_page().  DMAR translation fails at this point as the old
stale address (from SEABIOS initialization) is not in the DMAR page table.

[-- Attachment #2: Type: text/html, Size: 671 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH] ahci: map memory via device's address space instead of address_space_memory
@ 2014-07-03  8:26 Le Tan
  2014-07-03  8:28 ` Michael S. Tsirkin
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Le Tan @ 2014-07-03  8:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, peter.maydell, mst, Le Tan, jan.kiszka, pbonzini, afaerber

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 address
space. Add an AddressSpace parameter to map_page(). In order to call
map_page(), we should pass the AHCIState.as as the AddressSpace argument.

Signed-off-by: Le Tan <tamlokveer@gmail.com>
---
 hw/ide/ahci.c |   21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

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, AHCIDevice *d,
     ahci_check_irq(s);
 }
 
-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 = wanted;
 
     if (*ptr) {
-        cpu_physical_memory_unmap(*ptr, len, 1, len);
+        dma_memory_unmap(as, *ptr, len, DMA_DIRECTION_FROM_DEVICE, len);
     }
 
-    *ptr = cpu_physical_memory_map(addr, &len, 1);
+    *ptr = 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 = NULL;
     }
 }
@@ -198,24 +199,24 @@ static void  ahci_port_write(AHCIState *s, int port, int offset, uint32_t val)
     switch (offset) {
         case PORT_LST_ADDR:
             pr->lst_addr = 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 = NULL;
             break;
         case PORT_LST_ADDR_HI:
             pr->lst_addr_hi = 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 = NULL;
             break;
         case PORT_FIS_ADDR:
             pr->fis_addr = 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 = 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 = &s->dev[i];
         AHCIPortRegs *pr = &ad->port_regs;
 
-        map_page(&ad->lst,
+        map_page(s->as, &ad->lst,
                  ((uint64_t)pr->lst_addr_hi << 32) | pr->lst_addr, 1024);
-        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,
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2015-03-12 17:41 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-26  5:13 [Qemu-devel] [PATCH] ahci: map memory via device's address space instead of address_space_memory Jordan Hargrave
2015-02-26 14:45 ` Stefan Hajnoczi
2015-02-26 21:31   ` Jordan Hargrave
2015-02-26 22:02     ` Paolo Bonzini
2015-03-09 22:42       ` John Snow
2015-02-26 22:31     ` John Snow
     [not found]       ` <CAC1AzdcoEUtiGyCSXSf0bniUvQZ9tTeX2Vc9KQUyBfQxFV+JFg@mail.gmail.com>
2015-03-02 16:37         ` John Snow
2015-03-12 17:41 ` John Snow
  -- strict thread matches above, loose matches on Subject: below --
2014-07-03  8:26 Le Tan
2014-07-03  8:28 ` Michael S. Tsirkin
2014-07-03  8:47   ` Paolo Bonzini
2014-07-03  8:43 ` Jan Kiszka
2014-07-03  9:41   ` Paolo Bonzini
2014-07-03 10:11     ` Michael S. Tsirkin
2014-07-03 10:02   ` Michael S. Tsirkin
2014-07-03 16:45     ` Jan Kiszka
2014-07-03 20:30       ` Michael S. Tsirkin
2014-07-04  5:26         ` Jan Kiszka
2014-07-06  5:58           ` Michael S. Tsirkin
2014-07-07  8:23 ` Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).