From 38b3362dd15c2dc4ad0edd105cde914e639d90fa Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Fri, 2 Jun 2017 18:12:23 +0400 Subject: exec: split qemu_ram_alloc_from_file() Add qemu_ram_alloc_from_fd(), which can be use to allocate ramblock from fd only. Signed-off-by: Marc-André Lureau Message-Id: <20170602141229.15326-4-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini --- include/exec/ram_addr.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/exec') diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 140efa840c..73d1bea8b6 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -65,6 +65,9 @@ unsigned long last_ram_page(void); RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, bool share, const char *mem_path, Error **errp); +RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, + bool share, int fd, + Error **errp); RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr, Error **errp); RAMBlock *qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr, Error **errp); -- cgit v1.2.3-55-g7522 From fea617c58b777495b9285f3dc6b33f2898352886 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Fri, 2 Jun 2017 18:12:24 +0400 Subject: Add memory_region_init_ram_from_fd() Add a new function to initialize a RAM memory region with a file descriptor to be mmap-ed. Signed-off-by: Marc-André Lureau Message-Id: <20170602141229.15326-5-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini --- include/exec/memory.h | 20 ++++++++++++++++++++ memory.c | 16 ++++++++++++++++ 2 files changed, 36 insertions(+) (limited to 'include/exec') diff --git a/include/exec/memory.h b/include/exec/memory.h index 80e605a96a..51a54c92d5 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -456,6 +456,26 @@ void memory_region_init_ram_from_file(MemoryRegion *mr, bool share, const char *path, Error **errp); + +/** + * memory_region_init_ram_from_fd: Initialize RAM memory region with a + * mmap-ed backend. + * + * @mr: the #MemoryRegion to be initialized. + * @owner: the object that tracks the region's reference count + * @name: the name of the region. + * @size: size of the region. + * @share: %true if memory must be mmaped with the MAP_SHARED flag + * @fd: the fd to mmap. + * @errp: pointer to Error*, to store an error if it happens. + */ +void memory_region_init_ram_from_fd(MemoryRegion *mr, + struct Object *owner, + const char *name, + uint64_t size, + bool share, + int fd, + Error **errp); #endif /** diff --git a/memory.c b/memory.c index 0ddc4cc28d..b2ace20bac 100644 --- a/memory.c +++ b/memory.c @@ -1397,6 +1397,22 @@ void memory_region_init_ram_from_file(MemoryRegion *mr, mr->ram_block = qemu_ram_alloc_from_file(size, mr, share, path, errp); mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; } + +void memory_region_init_ram_from_fd(MemoryRegion *mr, + struct Object *owner, + const char *name, + uint64_t size, + bool share, + int fd, + Error **errp) +{ + memory_region_init(mr, owner, name, size); + mr->ram = true; + mr->terminates = true; + mr->destructor = memory_region_destructor_ram; + mr->ram_block = qemu_ram_alloc_from_fd(size, mr, share, fd, errp); + mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; +} #endif void memory_region_init_ram_ptr(MemoryRegion *mr, -- cgit v1.2.3-55-g7522 From 6b9911d0b6508b5fe4efa55d4f3bc9bc851c73a2 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Fri, 2 Jun 2017 18:12:26 +0400 Subject: memory: remove memory_region_set_fd Now unnecessary since ivshmem uses memory_region_init_ram_from_fd. Signed-off-by: Marc-André Lureau Message-Id: <20170602141229.15326-7-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini --- include/exec/memory.h | 11 ----------- memory.c | 10 ---------- 2 files changed, 21 deletions(-) (limited to 'include/exec') diff --git a/include/exec/memory.h b/include/exec/memory.h index 51a54c92d5..37f8e78e71 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -824,17 +824,6 @@ static inline bool memory_region_is_rom(MemoryRegion *mr) */ int memory_region_get_fd(MemoryRegion *mr); -/** - * memory_region_set_fd: Mark a RAM memory region as backed by a - * file descriptor. - * - * This function is typically used after memory_region_init_ram_ptr(). - * - * @mr: the memory region being queried. - * @fd: the file descriptor that backs @mr. - */ -void memory_region_set_fd(MemoryRegion *mr, int fd); - /** * memory_region_from_host: Convert a pointer into a RAM memory region * and an offset within it. diff --git a/memory.c b/memory.c index b2ace20bac..e08fa0ae6c 100644 --- a/memory.c +++ b/memory.c @@ -1851,16 +1851,6 @@ int memory_region_get_fd(MemoryRegion *mr) return fd; } -void memory_region_set_fd(MemoryRegion *mr, int fd) -{ - rcu_read_lock(); - while (mr->alias) { - mr = mr->alias; - } - mr->ram_block->fd = fd; - rcu_read_unlock(); -} - void *memory_region_get_ram_ptr(MemoryRegion *mr) { void *ptr; -- cgit v1.2.3-55-g7522 From e947738e3840025704e6d037aec4c341c8008994 Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Wed, 14 Jun 2017 21:21:50 +0200 Subject: include/exec/poison: Add missing TARGET defines Since we've got some new CPU targets in QEMU during the last months and years, we've got some new TARGET_xxx defines now which should be marked as poisoned for common code. Signed-off-by: Thomas Huth Message-Id: <1497468113-2874-2-git-send-email-thuth@redhat.com> Signed-off-by: Paolo Bonzini --- include/exec/poison.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include/exec') diff --git a/include/exec/poison.h b/include/exec/poison.h index 3ca7929cce..9356d5fff3 100644 --- a/include/exec/poison.h +++ b/include/exec/poison.h @@ -12,17 +12,28 @@ #pragma GCC poison TARGET_CRIS #pragma GCC poison TARGET_LM32 #pragma GCC poison TARGET_M68K +#pragma GCC poison TARGET_MICROBLAZE #pragma GCC poison TARGET_MIPS +#pragma GCC poison TARGET_ABI_MIPSO32 #pragma GCC poison TARGET_MIPS64 +#pragma GCC poison TARGET_ABI_MIPSN64 +#pragma GCC poison TARGET_MOXIE +#pragma GCC poison TARGET_NIOS2 #pragma GCC poison TARGET_OPENRISC #pragma GCC poison TARGET_PPC #pragma GCC poison TARGET_PPCEMB #pragma GCC poison TARGET_PPC64 #pragma GCC poison TARGET_ABI32 +#pragma GCC poison TARGET_S390X #pragma GCC poison TARGET_SH4 #pragma GCC poison TARGET_SPARC #pragma GCC poison TARGET_SPARC64 +#pragma GCC poison TARGET_TRICORE +#pragma GCC poison TARGET_UNICORE32 +#pragma GCC poison TARGET_XTENSA +#pragma GCC poison TARGET_NAME +#pragma GCC poison TARGET_SUPPORTS_MTTCG #pragma GCC poison TARGET_WORDS_BIGENDIAN #pragma GCC poison BSWAP_NEEDED -- cgit v1.2.3-55-g7522 From 067b913619ac36299be5ab23921fd19a0347df60 Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Wed, 14 Jun 2017 21:21:51 +0200 Subject: include/exec/poison: Mark some CONFIG defines as poisoned, too These are defined in config-target.h and thus should never be used in common code. Signed-off-by: Thomas Huth Message-Id: <1497468113-2874-3-git-send-email-thuth@redhat.com> Signed-off-by: Paolo Bonzini --- include/exec/poison.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'include/exec') diff --git a/include/exec/poison.h b/include/exec/poison.h index 9356d5fff3..5ffed4d56e 100644 --- a/include/exec/poison.h +++ b/include/exec/poison.h @@ -61,5 +61,25 @@ #pragma GCC poison CPU_INTERRUPT_TGT_INT_1 #pragma GCC poison CPU_INTERRUPT_TGT_INT_2 +#pragma GCC poison CONFIG_ALPHA_DIS +#pragma GCC poison CONFIG_ARM_A64_DIS +#pragma GCC poison CONFIG_ARM_DIS +#pragma GCC poison CONFIG_CRIS_DIS +#pragma GCC poison CONFIG_I386_DIS +#pragma GCC poison CONFIG_LM32_DIS +#pragma GCC poison CONFIG_M68K_DIS +#pragma GCC poison CONFIG_MICROBLAZE_DIS +#pragma GCC poison CONFIG_MIPS_DIS +#pragma GCC poison CONFIG_MOXIE_DIS +#pragma GCC poison CONFIG_NIOS2_DIS +#pragma GCC poison CONFIG_PPC_DIS +#pragma GCC poison CONFIG_S390_DIS +#pragma GCC poison CONFIG_SH4_DIS +#pragma GCC poison CONFIG_SPARC_DIS +#pragma GCC poison CONFIG_XTENSA_DIS + +#pragma GCC poison CONFIG_LINUX_USER +#pragma GCC poison CONFIG_VHOST_NET + #endif #endif -- cgit v1.2.3-55-g7522