From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, "Laurent Vivier" <lvivier@redhat.com>,
"Thomas Huth" <thuth@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>
Subject: [PATCH v2 2/3] memory: add memory_region_is_mapped_shared()
Date: Tue, 25 May 2021 15:28:02 +0100 [thread overview]
Message-ID: <20210525142803.125401-3-stefanha@redhat.com> (raw)
In-Reply-To: <20210525142803.125401-1-stefanha@redhat.com>
Add a function to query whether a memory region is mmap(MAP_SHARED).
This will be used to check that vhost-user memory regions can be shared
with the device backend process in the next patch.
An inline function in "exec/memory.h" would have been nice but RAMBlock
fields are only accessible from memory.c (see "exec/ramblock.h").
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
include/exec/memory.h | 11 +++++++++++
softmmu/memory.c | 6 ++++++
2 files changed, 17 insertions(+)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index c8b9088924..88dbcb69c4 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -2483,6 +2483,17 @@ static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write)
}
}
+/**
+ * memory_region_is_mapped_shared: check whether a memory region is
+ * mmap(MAP_SHARED)
+ *
+ * Returns %true is a memory region is mmap(MAP_SHARED). This is always false
+ * on memory regions that do not support memory_region_get_ram_ptr().
+ *
+ * @mr: the memory region being queried
+ */
+bool memory_region_is_mapped_shared(MemoryRegion *mr);
+
/**
* address_space_read: read from an address space.
*
diff --git a/softmmu/memory.c b/softmmu/memory.c
index 3bb533c0bc..7379d44d18 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -1808,6 +1808,12 @@ bool memory_region_is_ram_device(MemoryRegion *mr)
return mr->ram_device;
}
+bool memory_region_is_mapped_shared(MemoryRegion *mr)
+{
+ return memory_access_is_direct(mr, false) &&
+ (mr->ram_block->flags & RAM_SHARED);
+}
+
uint8_t memory_region_get_dirty_log_mask(MemoryRegion *mr)
{
uint8_t mask = mr->dirty_log_mask;
--
2.31.1
next prev parent reply other threads:[~2021-05-25 14:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-25 14:28 [PATCH v2 0/3] vhost-user: warn when guest RAM is not shared Stefan Hajnoczi
2021-05-25 14:28 ` [PATCH v2 1/3] tests/qtest/vhost-user-test: use share=on with memfd Stefan Hajnoczi
2021-05-25 14:28 ` Stefan Hajnoczi [this message]
2021-05-25 14:28 ` [PATCH v2 3/3] vhost-user: warn when guest RAM is not shared Stefan Hajnoczi
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=20210525142803.125401-3-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=kwolf@redhat.com \
--cc=lvivier@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
/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).