From b93c24ba31dd1da600f6abdbdb45fb617c94cf52 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Wed, 14 Feb 2018 08:36:25 -0500 Subject: [PATCH] memory: Add global-locking property to memory regions This introduces the memory region property "global_locking". It is true by default. By setting it to false, a device model can request BQL-free dispatching of region accesses to its r/w handlers. The actual BQL break-up will be provided in a separate patch. Backports commit 196ea13104f802c508e57180b2a0d2b3418989a3 from qemu --- qemu/aarch64.h | 2 ++ qemu/aarch64eb.h | 2 ++ qemu/arm.h | 2 ++ qemu/armeb.h | 2 ++ qemu/header_gen.py | 2 ++ qemu/include/exec/memory.h | 26 ++++++++++++++++++++++++++ qemu/m68k.h | 2 ++ qemu/memory.c | 11 +++++++++++ qemu/mips.h | 2 ++ qemu/mips64.h | 2 ++ qemu/mips64el.h | 2 ++ qemu/mipsel.h | 2 ++ qemu/powerpc.h | 2 ++ qemu/sparc.h | 2 ++ qemu/sparc64.h | 2 ++ qemu/x86_64.h | 2 ++ 16 files changed, 65 insertions(+) diff --git a/qemu/aarch64.h b/qemu/aarch64.h index a8b26eb7..ef3453cc 100644 --- a/qemu/aarch64.h +++ b/qemu/aarch64.h @@ -2052,6 +2052,7 @@ #define memory_region_add_subregion_common memory_region_add_subregion_common_aarch64 #define memory_region_add_subregion_overlap memory_region_add_subregion_overlap_aarch64 #define memory_region_big_endian memory_region_big_endian_aarch64 +#define memory_region_clear_global_locking memory_region_clear_global_locking_aarch64 #define memory_region_clear_pending memory_region_clear_pending_aarch64 #define memory_region_del_subregion memory_region_del_subregion_aarch64 #define memory_region_destructor_alias memory_region_destructor_alias_aarch64 @@ -2104,6 +2105,7 @@ #define memory_region_set_address memory_region_set_address_aarch64 #define memory_region_set_alias_offset memory_region_set_alias_offset_aarch64 #define memory_region_set_enabled memory_region_set_enabled_aarch64 +#define memory_region_set_global_locking memory_region_set_global_locking_aarch64 #define memory_region_set_readonly memory_region_set_readonly_aarch64 #define memory_region_set_skip_dump memory_region_set_skip_dump_aarch64 #define memory_region_size memory_region_size_aarch64 diff --git a/qemu/aarch64eb.h b/qemu/aarch64eb.h index 9e25ad19..e3e491ca 100644 --- a/qemu/aarch64eb.h +++ b/qemu/aarch64eb.h @@ -2052,6 +2052,7 @@ #define memory_region_add_subregion_common memory_region_add_subregion_common_aarch64eb #define memory_region_add_subregion_overlap memory_region_add_subregion_overlap_aarch64eb #define memory_region_big_endian memory_region_big_endian_aarch64eb +#define memory_region_clear_global_locking memory_region_clear_global_locking_aarch64eb #define memory_region_clear_pending memory_region_clear_pending_aarch64eb #define memory_region_del_subregion memory_region_del_subregion_aarch64eb #define memory_region_destructor_alias memory_region_destructor_alias_aarch64eb @@ -2104,6 +2105,7 @@ #define memory_region_set_address memory_region_set_address_aarch64eb #define memory_region_set_alias_offset memory_region_set_alias_offset_aarch64eb #define memory_region_set_enabled memory_region_set_enabled_aarch64eb +#define memory_region_set_global_locking memory_region_set_global_locking_aarch64eb #define memory_region_set_readonly memory_region_set_readonly_aarch64eb #define memory_region_set_skip_dump memory_region_set_skip_dump_aarch64eb #define memory_region_size memory_region_size_aarch64eb diff --git a/qemu/arm.h b/qemu/arm.h index 70c7eff9..3d30070c 100644 --- a/qemu/arm.h +++ b/qemu/arm.h @@ -2052,6 +2052,7 @@ #define memory_region_add_subregion_common memory_region_add_subregion_common_arm #define memory_region_add_subregion_overlap memory_region_add_subregion_overlap_arm #define memory_region_big_endian memory_region_big_endian_arm +#define memory_region_clear_global_locking memory_region_clear_global_locking_arm #define memory_region_clear_pending memory_region_clear_pending_arm #define memory_region_del_subregion memory_region_del_subregion_arm #define memory_region_destructor_alias memory_region_destructor_alias_arm @@ -2104,6 +2105,7 @@ #define memory_region_set_address memory_region_set_address_arm #define memory_region_set_alias_offset memory_region_set_alias_offset_arm #define memory_region_set_enabled memory_region_set_enabled_arm +#define memory_region_set_global_locking memory_region_set_global_locking_arm #define memory_region_set_readonly memory_region_set_readonly_arm #define memory_region_set_skip_dump memory_region_set_skip_dump_arm #define memory_region_size memory_region_size_arm diff --git a/qemu/armeb.h b/qemu/armeb.h index 10a72b31..5488361d 100644 --- a/qemu/armeb.h +++ b/qemu/armeb.h @@ -2052,6 +2052,7 @@ #define memory_region_add_subregion_common memory_region_add_subregion_common_armeb #define memory_region_add_subregion_overlap memory_region_add_subregion_overlap_armeb #define memory_region_big_endian memory_region_big_endian_armeb +#define memory_region_clear_global_locking memory_region_clear_global_locking_armeb #define memory_region_clear_pending memory_region_clear_pending_armeb #define memory_region_del_subregion memory_region_del_subregion_armeb #define memory_region_destructor_alias memory_region_destructor_alias_armeb @@ -2104,6 +2105,7 @@ #define memory_region_set_address memory_region_set_address_armeb #define memory_region_set_alias_offset memory_region_set_alias_offset_armeb #define memory_region_set_enabled memory_region_set_enabled_armeb +#define memory_region_set_global_locking memory_region_set_global_locking_armeb #define memory_region_set_readonly memory_region_set_readonly_armeb #define memory_region_set_skip_dump memory_region_set_skip_dump_armeb #define memory_region_size memory_region_size_armeb diff --git a/qemu/header_gen.py b/qemu/header_gen.py index add19b32..a0554aa6 100644 --- a/qemu/header_gen.py +++ b/qemu/header_gen.py @@ -2058,6 +2058,7 @@ symbols = ( 'memory_region_add_subregion_common', 'memory_region_add_subregion_overlap', 'memory_region_big_endian', + 'memory_region_clear_global_locking', 'memory_region_clear_pending', 'memory_region_del_subregion', 'memory_region_destructor_alias', @@ -2110,6 +2111,7 @@ symbols = ( 'memory_region_set_address', 'memory_region_set_alias_offset', 'memory_region_set_enabled', + 'memory_region_set_global_locking', 'memory_region_set_readonly', 'memory_region_set_skip_dump', 'memory_region_size', diff --git a/qemu/include/exec/memory.h b/qemu/include/exec/memory.h index 954a7f20..74fbadee 100644 --- a/qemu/include/exec/memory.h +++ b/qemu/include/exec/memory.h @@ -169,6 +169,7 @@ struct MemoryRegion { bool enabled; bool rom_device; bool warning_printed; /* For reservations */ + bool global_locking; MemoryRegion *alias; hwaddr alias_offset; int32_t priority; @@ -587,6 +588,31 @@ bool memory_region_test_and_clear_dirty(MemoryRegion *mr, hwaddr addr, */ void memory_region_set_readonly(MemoryRegion *mr, bool readonly); +/** + * memory_region_set_global_locking: Declares the access processing requires + * QEMU's global lock. + * + * When this is invoked, accesses to the memory region will be processed while + * holding the global lock of QEMU. This is the default behavior of memory + * regions. + * + * @mr: the memory region to be updated. + */ +void memory_region_set_global_locking(MemoryRegion *mr); + +/** + * memory_region_clear_global_locking: Declares that access processing does + * not depend on the QEMU global lock. + * + * By clearing this property, accesses to the memory region will be processed + * outside of QEMU's global lock (unless the lock is held on when issuing the + * access request). In this case, the device model implementing the access + * handlers is responsible for synchronization of concurrency. + * + * @mr: the memory region to be updated. + */ +void memory_region_clear_global_locking(MemoryRegion *mr); + /** * memory_region_rom_device_set_romd: enable/disable ROMD mode * diff --git a/qemu/m68k.h b/qemu/m68k.h index dc4f2711..4e785262 100644 --- a/qemu/m68k.h +++ b/qemu/m68k.h @@ -2052,6 +2052,7 @@ #define memory_region_add_subregion_common memory_region_add_subregion_common_m68k #define memory_region_add_subregion_overlap memory_region_add_subregion_overlap_m68k #define memory_region_big_endian memory_region_big_endian_m68k +#define memory_region_clear_global_locking memory_region_clear_global_locking_m68k #define memory_region_clear_pending memory_region_clear_pending_m68k #define memory_region_del_subregion memory_region_del_subregion_m68k #define memory_region_destructor_alias memory_region_destructor_alias_m68k @@ -2104,6 +2105,7 @@ #define memory_region_set_address memory_region_set_address_m68k #define memory_region_set_alias_offset memory_region_set_alias_offset_m68k #define memory_region_set_enabled memory_region_set_enabled_m68k +#define memory_region_set_global_locking memory_region_set_global_locking_m68k #define memory_region_set_readonly memory_region_set_readonly_m68k #define memory_region_set_skip_dump memory_region_set_skip_dump_m68k #define memory_region_size memory_region_size_m68k diff --git a/qemu/memory.c b/qemu/memory.c index 6addfc05..df37b907 100644 --- a/qemu/memory.c +++ b/qemu/memory.c @@ -953,6 +953,7 @@ static void memory_region_initfn(struct uc_struct *uc, Object *obj, void *opaque mr->ram_addr = RAM_ADDR_INVALID; mr->enabled = true; mr->romd_mode = true; + mr->global_locking = true; mr->destructor = memory_region_destructor_none; QTAILQ_INIT(&mr->subregions); @@ -1313,6 +1314,16 @@ void memory_region_set_readonly(MemoryRegion *mr, bool readonly) } } +void memory_region_set_global_locking(MemoryRegion *mr) +{ + mr->global_locking = true; +} + +void memory_region_clear_global_locking(MemoryRegion *mr) +{ + mr->global_locking = false; +} + void memory_region_rom_device_set_romd(MemoryRegion *mr, bool romd_mode) { if (mr->romd_mode != romd_mode) { diff --git a/qemu/mips.h b/qemu/mips.h index 177078e0..173d9520 100644 --- a/qemu/mips.h +++ b/qemu/mips.h @@ -2052,6 +2052,7 @@ #define memory_region_add_subregion_common memory_region_add_subregion_common_mips #define memory_region_add_subregion_overlap memory_region_add_subregion_overlap_mips #define memory_region_big_endian memory_region_big_endian_mips +#define memory_region_clear_global_locking memory_region_clear_global_locking_mips #define memory_region_clear_pending memory_region_clear_pending_mips #define memory_region_del_subregion memory_region_del_subregion_mips #define memory_region_destructor_alias memory_region_destructor_alias_mips @@ -2104,6 +2105,7 @@ #define memory_region_set_address memory_region_set_address_mips #define memory_region_set_alias_offset memory_region_set_alias_offset_mips #define memory_region_set_enabled memory_region_set_enabled_mips +#define memory_region_set_global_locking memory_region_set_global_locking_mips #define memory_region_set_readonly memory_region_set_readonly_mips #define memory_region_set_skip_dump memory_region_set_skip_dump_mips #define memory_region_size memory_region_size_mips diff --git a/qemu/mips64.h b/qemu/mips64.h index 6036a496..5fd876ab 100644 --- a/qemu/mips64.h +++ b/qemu/mips64.h @@ -2052,6 +2052,7 @@ #define memory_region_add_subregion_common memory_region_add_subregion_common_mips64 #define memory_region_add_subregion_overlap memory_region_add_subregion_overlap_mips64 #define memory_region_big_endian memory_region_big_endian_mips64 +#define memory_region_clear_global_locking memory_region_clear_global_locking_mips64 #define memory_region_clear_pending memory_region_clear_pending_mips64 #define memory_region_del_subregion memory_region_del_subregion_mips64 #define memory_region_destructor_alias memory_region_destructor_alias_mips64 @@ -2104,6 +2105,7 @@ #define memory_region_set_address memory_region_set_address_mips64 #define memory_region_set_alias_offset memory_region_set_alias_offset_mips64 #define memory_region_set_enabled memory_region_set_enabled_mips64 +#define memory_region_set_global_locking memory_region_set_global_locking_mips64 #define memory_region_set_readonly memory_region_set_readonly_mips64 #define memory_region_set_skip_dump memory_region_set_skip_dump_mips64 #define memory_region_size memory_region_size_mips64 diff --git a/qemu/mips64el.h b/qemu/mips64el.h index 10e26bec..da89a17b 100644 --- a/qemu/mips64el.h +++ b/qemu/mips64el.h @@ -2052,6 +2052,7 @@ #define memory_region_add_subregion_common memory_region_add_subregion_common_mips64el #define memory_region_add_subregion_overlap memory_region_add_subregion_overlap_mips64el #define memory_region_big_endian memory_region_big_endian_mips64el +#define memory_region_clear_global_locking memory_region_clear_global_locking_mips64el #define memory_region_clear_pending memory_region_clear_pending_mips64el #define memory_region_del_subregion memory_region_del_subregion_mips64el #define memory_region_destructor_alias memory_region_destructor_alias_mips64el @@ -2104,6 +2105,7 @@ #define memory_region_set_address memory_region_set_address_mips64el #define memory_region_set_alias_offset memory_region_set_alias_offset_mips64el #define memory_region_set_enabled memory_region_set_enabled_mips64el +#define memory_region_set_global_locking memory_region_set_global_locking_mips64el #define memory_region_set_readonly memory_region_set_readonly_mips64el #define memory_region_set_skip_dump memory_region_set_skip_dump_mips64el #define memory_region_size memory_region_size_mips64el diff --git a/qemu/mipsel.h b/qemu/mipsel.h index e7ca951d..a8c575e4 100644 --- a/qemu/mipsel.h +++ b/qemu/mipsel.h @@ -2052,6 +2052,7 @@ #define memory_region_add_subregion_common memory_region_add_subregion_common_mipsel #define memory_region_add_subregion_overlap memory_region_add_subregion_overlap_mipsel #define memory_region_big_endian memory_region_big_endian_mipsel +#define memory_region_clear_global_locking memory_region_clear_global_locking_mipsel #define memory_region_clear_pending memory_region_clear_pending_mipsel #define memory_region_del_subregion memory_region_del_subregion_mipsel #define memory_region_destructor_alias memory_region_destructor_alias_mipsel @@ -2104,6 +2105,7 @@ #define memory_region_set_address memory_region_set_address_mipsel #define memory_region_set_alias_offset memory_region_set_alias_offset_mipsel #define memory_region_set_enabled memory_region_set_enabled_mipsel +#define memory_region_set_global_locking memory_region_set_global_locking_mipsel #define memory_region_set_readonly memory_region_set_readonly_mipsel #define memory_region_set_skip_dump memory_region_set_skip_dump_mipsel #define memory_region_size memory_region_size_mipsel diff --git a/qemu/powerpc.h b/qemu/powerpc.h index 5c76755d..a3716f05 100644 --- a/qemu/powerpc.h +++ b/qemu/powerpc.h @@ -2052,6 +2052,7 @@ #define memory_region_add_subregion_common memory_region_add_subregion_common_powerpc #define memory_region_add_subregion_overlap memory_region_add_subregion_overlap_powerpc #define memory_region_big_endian memory_region_big_endian_powerpc +#define memory_region_clear_global_locking memory_region_clear_global_locking_powerpc #define memory_region_clear_pending memory_region_clear_pending_powerpc #define memory_region_del_subregion memory_region_del_subregion_powerpc #define memory_region_destructor_alias memory_region_destructor_alias_powerpc @@ -2104,6 +2105,7 @@ #define memory_region_set_address memory_region_set_address_powerpc #define memory_region_set_alias_offset memory_region_set_alias_offset_powerpc #define memory_region_set_enabled memory_region_set_enabled_powerpc +#define memory_region_set_global_locking memory_region_set_global_locking_powerpc #define memory_region_set_readonly memory_region_set_readonly_powerpc #define memory_region_set_skip_dump memory_region_set_skip_dump_powerpc #define memory_region_size memory_region_size_powerpc diff --git a/qemu/sparc.h b/qemu/sparc.h index 28ad32b1..f83eefb8 100644 --- a/qemu/sparc.h +++ b/qemu/sparc.h @@ -2052,6 +2052,7 @@ #define memory_region_add_subregion_common memory_region_add_subregion_common_sparc #define memory_region_add_subregion_overlap memory_region_add_subregion_overlap_sparc #define memory_region_big_endian memory_region_big_endian_sparc +#define memory_region_clear_global_locking memory_region_clear_global_locking_sparc #define memory_region_clear_pending memory_region_clear_pending_sparc #define memory_region_del_subregion memory_region_del_subregion_sparc #define memory_region_destructor_alias memory_region_destructor_alias_sparc @@ -2104,6 +2105,7 @@ #define memory_region_set_address memory_region_set_address_sparc #define memory_region_set_alias_offset memory_region_set_alias_offset_sparc #define memory_region_set_enabled memory_region_set_enabled_sparc +#define memory_region_set_global_locking memory_region_set_global_locking_sparc #define memory_region_set_readonly memory_region_set_readonly_sparc #define memory_region_set_skip_dump memory_region_set_skip_dump_sparc #define memory_region_size memory_region_size_sparc diff --git a/qemu/sparc64.h b/qemu/sparc64.h index 913c63b8..a96b632d 100644 --- a/qemu/sparc64.h +++ b/qemu/sparc64.h @@ -2052,6 +2052,7 @@ #define memory_region_add_subregion_common memory_region_add_subregion_common_sparc64 #define memory_region_add_subregion_overlap memory_region_add_subregion_overlap_sparc64 #define memory_region_big_endian memory_region_big_endian_sparc64 +#define memory_region_clear_global_locking memory_region_clear_global_locking_sparc64 #define memory_region_clear_pending memory_region_clear_pending_sparc64 #define memory_region_del_subregion memory_region_del_subregion_sparc64 #define memory_region_destructor_alias memory_region_destructor_alias_sparc64 @@ -2104,6 +2105,7 @@ #define memory_region_set_address memory_region_set_address_sparc64 #define memory_region_set_alias_offset memory_region_set_alias_offset_sparc64 #define memory_region_set_enabled memory_region_set_enabled_sparc64 +#define memory_region_set_global_locking memory_region_set_global_locking_sparc64 #define memory_region_set_readonly memory_region_set_readonly_sparc64 #define memory_region_set_skip_dump memory_region_set_skip_dump_sparc64 #define memory_region_size memory_region_size_sparc64 diff --git a/qemu/x86_64.h b/qemu/x86_64.h index 5e7de80d..6ba2e52b 100644 --- a/qemu/x86_64.h +++ b/qemu/x86_64.h @@ -2052,6 +2052,7 @@ #define memory_region_add_subregion_common memory_region_add_subregion_common_x86_64 #define memory_region_add_subregion_overlap memory_region_add_subregion_overlap_x86_64 #define memory_region_big_endian memory_region_big_endian_x86_64 +#define memory_region_clear_global_locking memory_region_clear_global_locking_x86_64 #define memory_region_clear_pending memory_region_clear_pending_x86_64 #define memory_region_del_subregion memory_region_del_subregion_x86_64 #define memory_region_destructor_alias memory_region_destructor_alias_x86_64 @@ -2104,6 +2105,7 @@ #define memory_region_set_address memory_region_set_address_x86_64 #define memory_region_set_alias_offset memory_region_set_alias_offset_x86_64 #define memory_region_set_enabled memory_region_set_enabled_x86_64 +#define memory_region_set_global_locking memory_region_set_global_locking_x86_64 #define memory_region_set_readonly memory_region_set_readonly_x86_64 #define memory_region_set_skip_dump memory_region_set_skip_dump_x86_64 #define memory_region_size memory_region_size_x86_64