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

[Xen-devel] [PATCH v2] xen-mapcache: use MAP_FIXED flag so the mmap address hint is always honored


  • To: <qemu-devel@xxxxxxxxxx>
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Mon, 18 Mar 2019 16:45:45 +0100
  • Cc: Igor Druzhinin <igor.druzhinin@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Eduardo Habkost <ehabkost@xxxxxxxxxx>, "Michael S. Tsirkin" <mst@xxxxxxxxxx>, Paul Durrant <paul.durrant@xxxxxxxxxx>, Marcel Apfelbaum <marcel.apfelbaum@xxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx, Anthony Perard <anthony.perard@xxxxxxxxxx>, Paolo Bonzini <pbonzini@xxxxxxxxxx>, Richard Henderson <rth@xxxxxxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Delivery-date: Mon, 18 Mar 2019 15:46:13 +0000
  • Ironport-data: A9a23:+ERPma9NHN1x7NLR+aLSDrVtTnXEGK7SOkUsrf30RpOx8vdXlk5Xxd SFxLPOcU1th6Pjb+gBB+GE7DyHl6rnQZiuZqOoUddr6h2ZUdbYggUWWr/cyz2Xa0PCyca0XU 43qgxcudzGtH2lXRf/xfVmduj5hkT2GzVdHLgJMHaO2VqVKm2XaiItgpOUQ4y5NsGgP7WQRi Y1cnjOJaKnpRu/n0g6d/kpMIjJnHNjjiXehQYLwfayRJHQMGY6vYOSofV8M1G2e3OmN3H4i9 2PgCh/+5du3sQSNEVHZHgg00kjTWnsYJcbrBuXEYLZ+KMvR2F/E6HqhUf5rSA1AKWSK4K22s ix99VKZ/AyKDUJXPchnzjaAB4hHW3EDTAJnBpyaBSzKMuzFpgZq6HL8bhDs1rWFVA2Q5pXbc 3hCmJ4gYq3BKt+XuCdjSuRWU+/+nbDQXoGImYkYC2L3hNYloqzDBlZaNw/SYOLJ4ewpUdRtz XHRk+ynDOh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1WlrpUqsH5o9jZKEf4ffBkpJayFLXPLJOYVmzCxJLHcoMQnYv93STigrcZ6xb1wEwG87jZJ Yr+rr8gwgr0FZ/89WbMmOgKq9P7iI/CAcj2vBHky0G0QxHRXDgdQI3YwuEJBTT4YKmeyUiVf 6EDnr1jM95vOM/9KdWb7SQj3rWRZX86MbkGDVdnunepNvsQhuZvHIAqfCJo/XmpPpJHyj86z 9LWnMcFMxFwRQ3AOxnTaFiEG0lF32ZRJENuYYjTREgmgsKtIJqwNV8W8nHdJ5klw4Vau8TI5 7B47gyL/p+71fXAMorjSNFRj1VaoIrQ3vRhmIE7RCHj/hRPmWl5aG8fBZK4Wiq9OtqwP0FDi upcrTd2Qep7gwON/Sy7BkyhYmJoUl6pai0lXiA/rSPDhIOOO1mf1NBVQTaPrT3HP8YXFD71w REG7lcCRvA7jQEnXckPfy2sykSMwrbz10bPw8y4ajUcX9kajpWnizGNM27+lQ+rSZVizdHYo RV+PeyMKN78crY9pPZqPV+JncyQH10AcI8RYdYx8zzXz9M0EMidRBSZqVwVlLIusSHOrwf
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Or if it's not possible to honor the hinted address an error is returned
instead. This makes it easier to spot the actual failure, instead of
failing later on when the caller of xen_remap_bucket realizes the
mapping has not been created at the requested address.

Also note that at least on FreeBSD using MAP_FIXED will cause mmap to
try harder to honor the passed address.

Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>
Cc: Anthony Perard <anthony.perard@xxxxxxxxxx>
Cc: Paul Durrant <paul.durrant@xxxxxxxxxx>
Cc: Igor Druzhinin <igor.druzhinin@xxxxxxxxxx>
Cc: Paolo Bonzini <pbonzini@xxxxxxxxxx>
Cc: Richard Henderson <rth@xxxxxxxxxxx>
Cc: Eduardo Habkost <ehabkost@xxxxxxxxxx>
Cc: "Michael S. Tsirkin" <mst@xxxxxxxxxx>
Cc: Marcel Apfelbaum <marcel.apfelbaum@xxxxxxxxx>
Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx
---
Changes since v1:
 - Use MAP_FIXED for the dummy mmap call also if a specific virtual
   address is requested.
---
 hw/i386/xen/xen-mapcache.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/hw/i386/xen/xen-mapcache.c b/hw/i386/xen/xen-mapcache.c
index 349f72d00c..23de5517db 100644
--- a/hw/i386/xen/xen-mapcache.c
+++ b/hw/i386/xen/xen-mapcache.c
@@ -185,8 +185,13 @@ static void xen_remap_bucket(MapCacheEntry *entry,
     }
 
     if (!dummy) {
+        /*
+         * If the caller has requested the mapping at a specific address use
+         * MAP_FIXED to make sure it's honored.
+         */
         vaddr_base = xenforeignmemory_map2(xen_fmem, xen_domid, vaddr,
-                                           PROT_READ | PROT_WRITE, 0,
+                                           PROT_READ | PROT_WRITE,
+                                           vaddr ? MAP_FIXED : 0,
                                            nb_pfn, pfns, err);
         if (vaddr_base == NULL) {
             perror("xenforeignmemory_map2");
@@ -198,7 +203,8 @@ static void xen_remap_bucket(MapCacheEntry *entry,
          * mapping immediately due to certain circumstances (i.e. on resume 
now)
          */
         vaddr_base = mmap(vaddr, size, PROT_READ | PROT_WRITE,
-                          MAP_ANON | MAP_SHARED, -1, 0);
+                          MAP_ANON | MAP_SHARED | (vaddr ? MAP_FIXED : 0),
+                          -1, 0);
         if (vaddr_base == MAP_FAILED) {
             perror("mmap");
             exit(-1);
-- 
2.17.2 (Apple Git-113)


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.