Skip to contentSkip to conversation

page-vary: Build set_preferred_target_page_bits() as common code

PATCH In review Philippe Mathieu-Daudé 3 participants 14 messages Feb 13 – Feb 17

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index e446585bf53..537aad04fa8 100644
@@ -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
index e3287334304..0d2269e0401 100644
@@ -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
index 4e1e2f64da1..f9fb73a41c6 100644
@@ -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
index 9b3fdd2854a..a3bca3c9f0d 100644
@@ -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
index 65220cc7820..a6a080295f0 100644
@@ -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
index a26532f660f..06bf329de72 100644
@@ -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
Reviewed-by on v1 1/5
#2 lore raw

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).

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(+)
#3 lore raw

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
index 101c25911c1..3c77689ca52 100644
@@ -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
index 49a32b4fe51..ab92da4539d 100644
@@ -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
Reviewed-by on v1 2/5
#4 lore raw

Re: [PATCH 2/5] page-vary: Expose TARGET_PAGE_BITS_MIN definition

Quoted 9 lines · 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(-)
#5 lore raw

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
index ab92da4539d..5fb79eb5752 100644
@@ -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
#7 lore raw

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
index ab77672dd41..a2417354cc5 100644
@@ -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
index 5fb79eb5752..a81c91410b3 100644
@@ -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
#9 lore raw

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
index 3c77689ca52..c4dc56634bc 100644
@@ -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
index a2417354cc5..e2ccc7b0ead 100644
@@ -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
Reviewed-by on v1 5/5
#10 lore raw

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 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(-)
#11 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 12 lines · Philippe Mathieu-Daudé

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()

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~

#12 lore raw
Quoted 25 lines · Richard Henderson
Quoted 17 lines · Philippe Mathieu-Daudé

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 +

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.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.

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/

#13 lore raw
Quoted 26 lines · Philippe Mathieu-Daudé
Quoted 25 lines · Richard Henderson
Quoted 23 lines · Philippe Mathieu-Daudé

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(-)
Quoted 4 lines
Quoted 1 line

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.

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~