qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert (git)" <dgilbert@redhat.com>
To: qemu-devel@nongnu.org
Cc: aarcange@redhat.com, yamahata@private.email.ne.jp,
	quintela@redhat.com, liang.z.li@intel.com, luis@cs.umu.se,
	bharata@linux.vnet.ibm.com, amit.shah@redhat.com,
	pbonzini@redhat.com, david@gibson.dropbear.id.au
Subject: [Qemu-devel] [PATCH v9 05/56] qemu_ram_block_from_host
Date: Thu,  5 Nov 2015 18:10:32 +0000	[thread overview]
Message-ID: <1446747083-18205-6-git-send-email-dgilbert@redhat.com> (raw)
In-Reply-To: <1446747083-18205-1-git-send-email-dgilbert@redhat.com>

From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

Postcopy sends RAMBlock names and offsets over the wire (since it can't
rely on the order of ramaddr being the same), and it starts out with
HVA fault addresses from the kernel.

qemu_ram_block_from_host translates a HVA into a RAMBlock, an offset
in the RAMBlock and the global ram_addr_t value.

Rewrite qemu_ram_addr_from_host to use qemu_ram_block_from_host.

Provide qemu_ram_get_idstr since its the actual name text sent on the
wire.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Amit Shah <amit.shah@redhat.com>
---
 exec.c                    | 54 +++++++++++++++++++++++++++++++++++++++--------
 include/exec/cpu-common.h |  3 +++
 include/exec/ram_addr.h   |  2 --
 include/qemu/typedefs.h   |  1 +
 4 files changed, 49 insertions(+), 11 deletions(-)

diff --git a/exec.c b/exec.c
index 13cbb5a..2b1e13a 100644
--- a/exec.c
+++ b/exec.c
@@ -1375,6 +1375,11 @@ static RAMBlock *find_ram_block(ram_addr_t addr)
     return NULL;
 }
 
+const char *qemu_ram_get_idstr(RAMBlock *rb)
+{
+    return rb->idstr;
+}
+
 /* Called with iothread lock held.  */
 void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev)
 {
@@ -1875,8 +1880,16 @@ static void *qemu_ram_ptr_length(ram_addr_t addr, hwaddr *size)
     }
 }
 
-/* Some of the softmmu routines need to translate from a host pointer
- * (typically a TLB entry) back to a ram offset.
+/*
+ * Translates a host ptr back to a RAMBlock, a ram_addr and an offset
+ * in that RAMBlock.
+ *
+ * ptr: Host pointer to look up
+ * round_offset: If true round the result offset down to a page boundary
+ * *ram_addr: set to result ram_addr
+ * *offset: set to result offset within the RAMBlock
+ *
+ * Returns: RAMBlock (or NULL if not found)
  *
  * By the time this function returns, the returned pointer is not protected
  * by RCU anymore.  If the caller is not within an RCU critical section and
@@ -1884,18 +1897,22 @@ static void *qemu_ram_ptr_length(ram_addr_t addr, hwaddr *size)
  * pointer, such as a reference to the region that includes the incoming
  * ram_addr_t.
  */
-MemoryRegion *qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr)
+RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset,
+                                   ram_addr_t *ram_addr,
+                                   ram_addr_t *offset)
 {
     RAMBlock *block;
     uint8_t *host = ptr;
-    MemoryRegion *mr;
 
     if (xen_enabled()) {
         rcu_read_lock();
         *ram_addr = xen_ram_addr_from_mapcache(ptr);
-        mr = qemu_get_ram_block(*ram_addr)->mr;
+        block = qemu_get_ram_block(*ram_addr);
+        if (block) {
+            *offset = (host - block->host);
+        }
         rcu_read_unlock();
-        return mr;
+        return block;
     }
 
     rcu_read_lock();
@@ -1918,10 +1935,29 @@ MemoryRegion *qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr)
     return NULL;
 
 found:
-    *ram_addr = block->offset + (host - block->host);
-    mr = block->mr;
+    *offset = (host - block->host);
+    if (round_offset) {
+        *offset &= TARGET_PAGE_MASK;
+    }
+    *ram_addr = block->offset + *offset;
     rcu_read_unlock();
-    return mr;
+    return block;
+}
+
+/* Some of the softmmu routines need to translate from a host pointer
+   (typically a TLB entry) back to a ram offset.  */
+MemoryRegion *qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr)
+{
+    RAMBlock *block;
+    ram_addr_t offset; /* Not used */
+
+    block = qemu_ram_block_from_host(ptr, false, ram_addr, &offset);
+
+    if (!block) {
+        return NULL;
+    }
+
+    return block->mr;
 }
 
 static void notdirty_mem_write(void *opaque, hwaddr ram_addr,
diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index 9fb1d54..94d1f8a 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -64,8 +64,11 @@ typedef uint32_t CPUReadMemoryFunc(void *opaque, hwaddr addr);
 void qemu_ram_remap(ram_addr_t addr, ram_addr_t length);
 /* This should not be used by devices.  */
 MemoryRegion *qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr);
+RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset,
+                                   ram_addr_t *ram_addr, ram_addr_t *offset);
 void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev);
 void qemu_ram_unset_idstr(ram_addr_t addr);
+const char *qemu_ram_get_idstr(RAMBlock *rb);
 
 void cpu_physical_memory_rw(hwaddr addr, uint8_t *buf,
                             int len, int is_write);
diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index 3360ac5..7115154 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -22,8 +22,6 @@
 #ifndef CONFIG_USER_ONLY
 #include "hw/xen/xen.h"
 
-typedef struct RAMBlock RAMBlock;
-
 struct RAMBlock {
     struct rcu_head rcu;
     struct MemoryRegion *mr;
diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
index d961362..e4b8520 100644
--- a/include/qemu/typedefs.h
+++ b/include/qemu/typedefs.h
@@ -78,6 +78,7 @@ typedef struct QEMUSizedBuffer QEMUSizedBuffer;
 typedef struct QEMUTimerListGroup QEMUTimerListGroup;
 typedef struct QEMUTimer QEMUTimer;
 typedef struct Range Range;
+typedef struct RAMBlock RAMBlock;
 typedef struct SerialState SerialState;
 typedef struct SHPCDevice SHPCDevice;
 typedef struct SMBusDevice SMBusDevice;
-- 
2.5.0

  parent reply	other threads:[~2015-11-05 18:11 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-05 18:10 [Qemu-devel] [PATCH v9 00/56] Postcopy implementation Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 01/56] Add postcopy documentation Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 02/56] Provide runtime Target page information Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 03/56] Move configuration section writing Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 04/56] Move page_size_init earlier Dr. David Alan Gilbert (git)
2015-11-09  9:21   ` Juan Quintela
2015-11-05 18:10 ` Dr. David Alan Gilbert (git) [this message]
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 06/56] qemu_ram_block_by_name Dr. David Alan Gilbert (git)
2015-11-09  9:24   ` Juan Quintela
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 07/56] Rename mis->file to from_src_file Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 08/56] Add qemu_get_buffer_in_place to avoid copies some of the time Dr. David Alan Gilbert (git)
2015-11-09  9:25   ` Juan Quintela
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 09/56] Add wrapper for setting blocking status on a QEMUFile Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 10/56] Add QEMU_MADV_NOHUGEPAGE Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 11/56] ram_debug_dump_bitmap: Dump a migration bitmap as text Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 12/56] ram_load: Factor out host_from_stream_offset call and check Dr. David Alan Gilbert (git)
2015-11-09  9:29   ` Juan Quintela
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 13/56] migrate_init: Call from savevm Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 14/56] Rename save_live_complete to save_live_complete_precopy Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 15/56] Add Linux userfaultfd.h header Dr. David Alan Gilbert (git)
2015-11-09  9:31   ` Juan Quintela
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 16/56] Return path: Open a return path on QEMUFile for sockets Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 17/56] Return path: socket_writev_buffer: Block even on non-blocking fd's Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 18/56] Migration commands Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 19/56] Return path: Control commands Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 20/56] Return path: Send responses from destination to source Dr. David Alan Gilbert (git)
2015-11-09 10:54   ` Juan Quintela
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 21/56] migration_is_setup_or_active Dr. David Alan Gilbert (git)
2015-11-09 10:55   ` Juan Quintela
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 22/56] Return path: Source handling of return path Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 23/56] Rework loadvm path for subloops Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 24/56] Add migration-capability boolean for postcopy-ram Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 25/56] Add wrappers and handlers for sending/receiving the postcopy-ram migration messages Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 26/56] MIG_CMD_PACKAGED: Send a packaged chunk of migration stream Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 27/56] Modify save_live_pending for postcopy Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 28/56] postcopy: OS support test Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 29/56] migrate_start_postcopy: Command to trigger transition to postcopy Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 30/56] migration_completion: Take current state Dr. David Alan Gilbert (git)
2015-11-09 10:57   ` Juan Quintela
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 31/56] MIGRATION_STATUS_POSTCOPY_ACTIVE: Add new migration state Dr. David Alan Gilbert (git)
2015-11-05 18:10 ` [Qemu-devel] [PATCH v9 32/56] Avoid sending vmdescription during postcopy Dr. David Alan Gilbert (git)
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 33/56] Add qemu_savevm_state_complete_postcopy Dr. David Alan Gilbert (git)
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 34/56] Postcopy: Maintain unsentmap Dr. David Alan Gilbert (git)
2015-11-09 11:01   ` Juan Quintela
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 35/56] Postcopy: Calculate discard Dr. David Alan Gilbert (git)
2015-11-09 11:08   ` Juan Quintela
2015-11-09 18:27     ` Dr. David Alan Gilbert
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 36/56] postcopy: Incoming initialisation Dr. David Alan Gilbert (git)
2015-11-09 11:11   ` Juan Quintela
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 37/56] postcopy: ram_enable_notify to switch on userfault Dr. David Alan Gilbert (git)
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 38/56] Postcopy: Postcopy startup in migration thread Dr. David Alan Gilbert (git)
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 39/56] Postcopy: End of iteration Dr. David Alan Gilbert (git)
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 40/56] Page request: Add MIG_RP_MSG_REQ_PAGES reverse command Dr. David Alan Gilbert (git)
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 41/56] Page request: Process incoming page request Dr. David Alan Gilbert (git)
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 42/56] Page request: Consume pages off the post-copy queue Dr. David Alan Gilbert (git)
2015-11-09 11:18   ` Juan Quintela
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 43/56] postcopy_ram.c: place_page and helpers Dr. David Alan Gilbert (git)
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 44/56] Postcopy: Use helpers to map pages during migration Dr. David Alan Gilbert (git)
2015-11-09 11:19   ` Juan Quintela
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 45/56] postcopy: Check order of received target pages Dr. David Alan Gilbert (git)
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 46/56] Don't sync dirty bitmaps in postcopy Dr. David Alan Gilbert (git)
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 47/56] Don't iterate on precopy-only devices during postcopy Dr. David Alan Gilbert (git)
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 48/56] Host page!=target page: Cleanup bitmaps Dr. David Alan Gilbert (git)
2015-11-09 11:22   ` Juan Quintela
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 49/56] Round up RAMBlock sizes to host page sizes Dr. David Alan Gilbert (git)
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 50/56] Postcopy; Handle userfault requests Dr. David Alan Gilbert (git)
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 51/56] Start up a postcopy/listener thread ready for incoming page data Dr. David Alan Gilbert (git)
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 52/56] postcopy: Wire up loadvm_postcopy_handle_ commands Dr. David Alan Gilbert (git)
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 53/56] Postcopy: Mark nohugepage before discard Dr. David Alan Gilbert (git)
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 54/56] End of migration for postcopy Dr. David Alan Gilbert (git)
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 55/56] Disable mlock around incoming postcopy Dr. David Alan Gilbert (git)
2015-11-05 18:11 ` [Qemu-devel] [PATCH v9 56/56] Inhibit ballooning during postcopy Dr. David Alan Gilbert (git)
2015-11-06  3:48 ` [Qemu-devel] [PATCH v9 00/56] Postcopy implementation Bharata B Rao
2015-11-06  9:09   ` Dr. David Alan Gilbert
2015-11-06 11:06     ` Bharata B Rao
2015-11-06 12:22       ` Dr. David Alan Gilbert
2015-11-06 13:43         ` Dr. David Alan Gilbert
2015-11-06 15:33           ` Bharata B Rao
2015-11-06 15:48             ` Dr. David Alan Gilbert
2015-11-09  3:21               ` Bharata B Rao
2015-11-09  9:08                 ` Dr. David Alan Gilbert
2015-11-09 10:28                   ` Bharata B Rao
2015-11-09 11:03                     ` Dr. David Alan Gilbert
2015-11-09 12:39                       ` Bharata B Rao
2015-11-09 12:52                         ` Dr. David Alan Gilbert
2015-11-09  4:13         ` David Gibson
2015-11-09  9:05           ` Paolo Bonzini
2015-11-09 16:02 ` Juan Quintela
2015-11-09 16:17   ` Dr. David Alan Gilbert
2016-01-27 11:54 ` Vladimir Sementsov-Ogievskiy
2016-01-27 12:42   ` Dr. David Alan Gilbert
2016-01-27 14:47     ` Vladimir Sementsov-Ogievskiy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1446747083-18205-6-git-send-email-dgilbert@redhat.com \
    --to=dgilbert@redhat.com \
    --cc=aarcange@redhat.com \
    --cc=amit.shah@redhat.com \
    --cc=bharata@linux.vnet.ibm.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=liang.z.li@intel.com \
    --cc=luis@cs.umu.se \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=yamahata@private.email.ne.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).