page-vary: Build set_preferred_target_page_bits() as common code
cover page-vary: Build set_preferred_target_page_bits() as common code
Allow common code check TARGET_PAGE_BITS_VARY at runtime via the target_page_bits_vary() helper, then use that in set_preferred_target_page_bits() in order to build this method once as common code.
Philippe Mathieu-Daudé (5):
qemu/target_info: Add target_page_bits_vary() helper
page-vary: Expose TARGET_PAGE_BITS_MIN definition
page-vary: Use target_page_bits_vary in set_preferred_target_page_bits
page-vary: Build set_preferred_target_page_bits() as common code
page-vary: Inline set_preferred_target_page_bits_common()
include/exec/page-vary.h | 15 ++++++++++++++- include/qemu/target-info-impl.h | 2 ++ include/qemu/target-info.h | 7 +++++++ configs/targets/aarch64-softmmu.c | 1 + configs/targets/arm-softmmu.c | 1 + page-vary-common.c | 29 ++++++++++++++++++----------- page-vary-target.c | 25 ------------------------- target-info-stub.c | 5 +++++ target-info.c | 5 +++++ 9 files changed, 53 insertions(+), 37 deletions(-)
Signature · 1 line
2.52.0
PATCH 1/5 qemu/target_info: Add target_page_bits_vary() helper
Add a helper returning whether a target support variable page sizes (only ARM targets so far).
--- include/qemu/target-info-impl.h | 2 ++ include/qemu/target-info.h | 7 +++++++ configs/targets/aarch64-softmmu.c | 1 + configs/targets/arm-softmmu.c | 1 + target-info-stub.c | 5 +++++ target-info.c | 5 +++++ 6 files changed, 21 insertions(+)
include/qemu/target-info-impl.h +2 -0
@@ -19,6 +19,8 @@ typedef struct TargetInfo {SysEmuTarget target_arch;/* runtime equivalent of TARGET_LONG_BITS definition */ unsigned long_bits; +/* runtime equivalent of TARGET_PAGE_BITS_VARY definition */ +bool page_bits_vary;/* runtime equivalent of CPU_RESOLVING_TYPE definition */ const char *cpu_type;/* QOM typename machines for this binary must implement */
include/qemu/target-info.h +7 -0
@@ -23,6 +23,13 @@ const char *target_name(void);*/ unsigned target_long_bits (void ); +/** +* target_page_bits_vary: +* +* Returns: whether the target support variable page sizes +*/ +bool target_page_bits_vary (void ); +/** * target_machine_typename: *
configs/targets/aarch64-softmmu.c +1 -0
@@ -15,6 +15,7 @@ static const TargetInfo target_info_aarch64_system = { .target_name = "aarch64", .target_arch = SYS_EMU_TARGET_AARCH64, .long_bits = 64, + .page_bits_vary = true, .cpu_type = TYPE_ARM_CPU, .machine_typename = TYPE_TARGET_AARCH64_MACHINE, .endianness = ENDIAN_MODE_LITTLE,
configs/targets/arm-softmmu.c +1 -0
@@ -15,6 +15,7 @@ static const TargetInfo target_info_arm_system = { .target_name = "arm", .target_arch = SYS_EMU_TARGET_ARM, .long_bits = 32, + .page_bits_vary = true, .cpu_type = TYPE_ARM_CPU, .machine_typename = TYPE_TARGET_ARM_MACHINE, .endianness = ENDIAN_MODE_LITTLE,
target-info-stub.c +5 -0
@@ -20,6 +20,11 @@ static const TargetInfo target_info_stub = { .target_name = TARGET_NAME, .target_arch = glue(SYS_EMU_TARGET_, TARGET_ARCH), .long_bits =TARGET_LONG_BITS , +#ifdef TARGET_PAGE_BITS_VARY + .page_bits_vary = true, +#else + .page_bits_vary = false, +#endif .cpu_type =CPU_RESOLVING_TYPE , .machine_typename = TYPE_MACHINE, .endianness = TARGET_BIG_ENDIAN ? ENDIAN_MODE_BIG : ENDIAN_MODE_LITTLE,
target-info.c +5 -0
@@ -22,6 +22,11 @@ unsigned target_long_bits(void)return target_info ()->long_bits; } +bool target_page_bits_vary (void ) +{ +return target_info ()->page_bits_vary; +} +SysEmuTarget target_arch (void ) {return target_info ()->target_arch;
Signature · 1 line
2.52.0
Re: [PATCH 1/5] qemu/target_info: Add target_page_bits_vary() helper
Quoted 4 lines · Philippe Mathieu-Daudé
Add a helper returning whether a target support variable page sizes (only ARM targets so far).
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 9 lines
--- include/qemu/target-info-impl.h | 2 ++ include/qemu/target-info.h | 7 +++++++ configs/targets/aarch64-softmmu.c | 1 + configs/targets/arm-softmmu.c | 1 + target-info-stub.c | 5 +++++ target-info.c | 5 +++++ 6 files changed, 21 insertions(+)
PATCH 2/5 page-vary: Expose TARGET_PAGE_BITS_MIN definition
In reply to Philippe Mathieu-DaudéWe'll use TARGET_PAGE_BITS_MIN in page-vary-common.c, so expose it via "exec/page-vary.h".
--- include/exec/page-vary.h | 14 ++++++++++++++ page-vary-target.c | 15 --------------- 2 files changed, 14 insertions(+), 15 deletions(-)
include/exec/page-vary.h +14 -0
@@ -20,6 +20,20 @@ #ifndef EXEC_PAGE_VARY_H #define EXEC_PAGE_VARY_H +/* + * For system mode, the minimum comes from the number of bits + * required for maximum alignment (6) and the number of bits + * required for TLB_FLAGS_MASK (3). + * + * For user mode, TARGET_PAGE_BITS_VARY is a hack to allow the target + * page size to match the host page size. Mostly, this reduces the + * ordinary target page size to run on a host with 4KiB pages (i.e. x86). + * There is no true minimum required by the implementation, but keep the + * same minimum as for system mode for sanity. + * See linux-user/mmap.c, mmap_h_lt_g and mmap_h_gt_g. + */ +#define TARGET_PAGE_BITS_MIN 9 + typedef struct { bool decided; int bits;
page-vary-target.c +0 -15
@@ -23,21 +23,6 @@#include "exec/page-vary.h" #include "exec/target_page.h" - -/* -* For system mode, the minimum comes from the number of bits -* required for maximum alignment (6) and the number of bits -* required for TLB_FLAGS_MASK (3). -* -* For user mode, TARGET_PAGE_BITS_VARY is a hack to allow the target -* page size to match the host page size. Mostly, this reduces the -* ordinary target page size to run on a host with 4KiB pages (i.e. x86). -* There is no true minimum required by the implementation, but keep the -* same minimum as for system mode for sanity. -* See linux-user/mmap.c, mmap_h_lt_g and mmap_h_gt_g. -*/ -#define TARGET_PAGE_BITS_MIN 9 -#ifndef TARGET_PAGE_BITS_VARY QEMU_BUILD_BUG_ON (TARGET_PAGE_BITS <TARGET_PAGE_BITS_MIN );#endif
Signature · 1 line
2.52.0
Re: [PATCH 2/5] page-vary: Expose TARGET_PAGE_BITS_MIN definition
Quoted 9 lines · Philippe Mathieu-Daudé
We'll use
TARGET_PAGE_BITS_MINinpage-vary-common.c, so expose it via "exec/page-vary.h".Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/exec/page-vary.h | 14 ++++++++++++++ page-vary-target.c | 15 --------------- 2 files changed, 14 insertions(+), 15 deletions(-)
PATCH 3/5 page-vary: Use target_page_bits_vary in set_preferred_target_page_bits
In reply to Philippe Mathieu-DaudéRather checking whether the target uses variable page sizes at runtime calling target_page_bits_vary().
--- page-vary-target.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
page-vary-target.c +4 -4
@@ -20,6 +20,7 @@#define IN_PAGE_VARY 1#include "qemu/osdep.h" +#include "qemu/target-info.h" #include "exec/page-vary.h" #include "exec/target_page.h"
@@ -46,11 +47,10 @@ int migration_legacy_page_bits(void)bool set_preferred_target_page_bits (int bits) {assert (bits >=TARGET_PAGE_BITS_MIN ); -#ifdef TARGET_PAGE_BITS_VARY -return set_preferred_target_page_bits_common (bits); -#else +if (target_page_bits_vary ()) { +return set_preferred_target_page_bits_common (bits); + }return true; -#endif }void finalize_target_page_bits (void )
Signature · 1 line
2.52.0
Re: [PATCH 3/5] page-vary: Use target_page_bits_vary in set_preferred_target_page_bits
Quoted 8 lines · Philippe Mathieu-Daudé
Rather checking whether the target uses variable page sizes at runtime calling
target_page_bits_vary().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- page-vary-target.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
PATCH 4/5 page-vary: Build set_preferred_target_page_bits() as common code
In reply to Philippe Mathieu-Daudéset_preferred_target_page_bits() doesn't have any
target specific restriction anymore; move it to
the common counterpart.
--- page-vary-common.c | 10 ++++++++++ page-vary-target.c | 10 ---------- 2 files changed, 10 insertions(+), 10 deletions(-)
page-vary-common.c +10 -0
@@ -20,6 +20,7 @@#define IN_PAGE_VARY 1#include "qemu/osdep.h" +#include "qemu/target-info.h" #include "exec/page-vary.h" /* WARNING: This file must *not* be complied with -flto. */
@@ -43,6 +44,15 @@ bool set_preferred_target_page_bits_common(int bits)return true; } +bool set_preferred_target_page_bits (int bits) +{ +assert (bits >=TARGET_PAGE_BITS_MIN ); +if (target_page_bits_vary ()) { +return set_preferred_target_page_bits_common (bits); + } +return true; +} +void finalize_target_page_bits_common (int min) {if (target_page.bits ==0 ) {
page-vary-target.c +0 -10
@@ -20,7 +20,6 @@#define IN_PAGE_VARY 1#include "qemu/osdep.h" -#include "qemu/target-info.h" #include "exec/page-vary.h" #include "exec/target_page.h"
@@ -44,15 +43,6 @@ int migration_legacy_page_bits(void) }#endif -bool set_preferred_target_page_bits (int bits) -{ -assert (bits >=TARGET_PAGE_BITS_MIN ); -if (target_page_bits_vary ()) { -return set_preferred_target_page_bits_common (bits); - } -return true; -} -void finalize_target_page_bits (void ) {#ifndef TARGET_PAGE_BITS_VARY
Signature · 1 line
2.52.0
Quoted 10 lines · Philippe Mathieu-Daudé
set_preferred_target_page_bits()doesn't have any
target specific restriction anymore; move it to
the common counterpart.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- page-vary-common.c | 10 ++++++++++ page-vary-target.c | 10 ---------- 2 files changed, 10 insertions(+), 10 deletions(-)
PATCH 5/5 page-vary: Inline set_preferred_target_page_bits_common()
In reply to Philippe Mathieu-Daudéset_preferred_target_page_bits_common() is only used once in set_preferred_target_page_bits(): inline it there and remove its prototype.
--- include/exec/page-vary.h | 1 - page-vary-common.c | 33 +++++++++++++++------------------ 2 files changed, 15 insertions(+), 19 deletions(-)
include/exec/page-vary.h +0 -1
@@ -41,7 +41,6 @@ typedef struct { } TargetPageBits;#ifdef IN_PAGE_VARY -bool set_preferred_target_page_bits_common (int bits);void finalize_target_page_bits_common (int min);#endif
page-vary-common.c +15 -18
@@ -27,29 +27,26 @@TargetPageBits target_page; -bool set_preferred_target_page_bits_common (int bits) -{ -/* -* The target page size is the lowest common denominator for all -* the CPUs in the system, so we can only make it smaller, never -* larger. And we can't make it smaller once we've committed to -* a particular size. -*/ -if (target_page.bits ==0 || target_page.bits > bits) { -if (target_page.decided) { -return false; - } - target_page.bits = bits; - } -return true; -} -bool set_preferred_target_page_bits (int bits) {assert (bits >=TARGET_PAGE_BITS_MIN ); +if (target_page_bits_vary ()) { -return set_preferred_target_page_bits_common (bits); +/* +* The target page size is the lowest common denominator for all +* the CPUs in the system, so we can only make it smaller, never +* larger. And we can't make it smaller once we've committed to +* a particular size. +*/ +if (target_page.bits ==0 || target_page.bits > bits) { +if (target_page.decided) { +return false; + } + target_page.bits = bits; + } +return true; } +return true; }
Signature · 1 line
2.52.0
Re: [PATCH 5/5] page-vary: Inline set_preferred_target_page_bits_common()
Quoted 10 lines · Philippe Mathieu-Daudé
set_preferred_target_page_bits_common()is only used once inset_preferred_target_page_bits(): inline it there and remove its prototype.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/exec/page-vary.h | 1 - page-vary-common.c | 33 +++++++++++++++------------------ 2 files changed, 15 insertions(+), 19 deletions(-)
Quoted 12 lines · Philippe Mathieu-Daudé
Allow common code check
TARGET_PAGE_BITS_VARYat runtime via thetarget_page_bits_vary()helper, then use that inset_preferred_target_page_bits()in order to build this method once as common code.Philippe Mathieu-Daudé (5):
qemu/target_info: Addtarget_page_bits_vary()helper
page-vary: ExposeTARGET_PAGE_BITS_MINdefinition
page-vary: Usetarget_page_bits_varyinset_preferred_target_page_bits
page-vary: Buildset_preferred_target_page_bits()as common code
page-vary: Inlineset_preferred_target_page_bits_common()
Quoted 11 lines
include/exec/page-vary.h | 15 ++++++++++++++- include/qemu/target-info-impl.h | 2 ++ include/qemu/target-info.h | 7 +++++++ configs/targets/aarch64-softmmu.c | 1 + configs/targets/arm-softmmu.c | 1 + page-vary-common.c | 29 ++++++++++++++++++----------- page-vary-target.c | 25 ------------------------- target-info-stub.c | 5 +++++ target-info.c | 5 +++++ 9 files changed, 53 insertions(+), 37 deletions(-)
This patch set moves code from page-vary-target.c to page-vary-common.c, based on the new target_info hook. But since TARGET_PAGE_BITS_VARY is still used, I don't see the point.
r~
Quoted 25 lines · Richard Henderson
Quoted 17 lines · Philippe Mathieu-Daudé
Allow common code check
TARGET_PAGE_BITS_VARYat runtime via thetarget_page_bits_vary()helper, then use that inset_preferred_target_page_bits()in order to build this method once as common code.Philippe Mathieu-Daudé (5):
qemu/target_info: Addtarget_page_bits_vary()helper
page-vary: ExposeTARGET_PAGE_BITS_MINdefinition
page-vary: Usetarget_page_bits_varyinset_preferred_target_page_bits
page-vary: Buildset_preferred_target_page_bits()as common code
page-vary: Inlineset_preferred_target_page_bits_common()include/exec/page-vary.h | 15 ++++++++++++++- include/qemu/target-info-impl.h | 2 ++ include/qemu/target-info.h | 7 +++++++
configs/targets/aarch64-softmmu.c| 1 + configs/targets/arm-softmmu.c | 1 +Quoted 6 lines
page-vary-common.c | 29 ++++++++++++++++++----------- page-vary-target.c | 25 ------------------------- target-info-stub.c | 5 +++++ target-info.c | 5 +++++ 9 files changed, 53 insertions(+), 37 deletions(-)
Quoted 1 line
This patch set moves code from
page-vary-target.ctopage-vary-common.c, based on the newtarget_infohook. But sinceTARGET_PAGE_BITS_VARYis still used, I don't see the point.
The set_preferred_target_page_bits() symbol is removed from the per-target clash symbol list. One step at a time?
I followed removing TARGET_PAGE_BITS_LEGACY, removing the use of TARGET_PAGE_BITS_VARY in common code, but I still haven't fully understood Peter's comments on my previous question, and am still processing it before posting the rest:
https://lore.kernel.org/qemu-devel/CAFEAcA9D3Wx2w7i2X93uX1H3GtrqdVKtGidG309XLb=AdGVOOA@mail.gmail.com/
Quoted 26 lines · Philippe Mathieu-Daudé
Quoted 25 lines · Richard Henderson
Quoted 23 lines · Philippe Mathieu-Daudé
Allow common code check
TARGET_PAGE_BITS_VARYat runtime via thetarget_page_bits_vary()helper, then use that inset_preferred_target_page_bits()in order to build this method once as common code.Philippe Mathieu-Daudé (5):
qemu/target_info: Addtarget_page_bits_vary()helper
page-vary: ExposeTARGET_PAGE_BITS_MINdefinition
page-vary: Usetarget_page_bits_varyinset_preferred_target_page_bits
page-vary: Buildset_preferred_target_page_bits()as common code
page-vary: Inlineset_preferred_target_page_bits_common()include/exec/page-vary.h | 15 ++++++++++++++- include/qemu/target-info-impl.h | 2 ++ include/qemu/target-info.h | 7 +++++++
configs/targets/aarch64-softmmu.c| 1 + configs/targets/arm-softmmu.c | 1 +page-vary-common.c | 29 ++++++++++++++++++----------- page-vary-target.c | 25 ------------------------- target-info-stub.c | 5 +++++ target-info.c | 5 +++++ 9 files changed, 53 insertions(+), 37 deletions(-)
Quoted 4 lines
Quoted 1 line
This patch set moves code from
page-vary-target.ctopage-vary-common.c, based on the newtarget_infohook. But sinceTARGET_PAGE_BITS_VARYis still used, I don't see the point.The
set_preferred_target_page_bits()symbol is removed from the per-target clash symbol list. One step at a time?
Ok, so, making set_preferred_target_page_bits is the goal. I now see that you even stated that above, but I missed it.
I'll give this another think.
r~