From: Richard Henderson <richard.henderson@linaro.org>
To: "Anton Johansson" <anjo@rev.ng>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
pierrick.bouvier@linaro.org, qemu-devel@nongnu.org,
alistair.francis@wdc.com, palmer@dabbelt.com,
Song Gao <gaosong@loongson.cn>, Helge Deller <deller@gmx.de>
Subject: Re: [PATCH 4/5] target-info: Introduce runtime TARGET_PHYS_ADDR_SPACE_BITS
Date: Fri, 17 Oct 2025 11:47:48 -0700 [thread overview]
Message-ID: <8f0db5c1-f20b-4b7a-8d6c-76ce7ec7b4e0@linaro.org> (raw)
In-Reply-To: <7jzcbl2yqkssu5lshz4umayaesoxwg3gcskrrkobc37df2p4z2@s26yst4mfxoe>
On 10/17/25 09:11, Anton Johansson wrote:
> Hmm you're right looking at git grep -C1 TARGET_PHYS_ADDR_SPACE_BITS
> (output below excluding the hw/riscv change in the following patch),
> there are really aren't that many uses left and none in common code.
>
> We still got to move it to a runtime value somewhere though, what
> would be a more suitable location? Maybe as a field in CPUArchState or
> some parent QOM machine as only i386, hppa, loongarch, riscv, alpha
> actually use the definition.
A fair few of these are arguably wrong.
> hw/loongarch/boot.c: return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
> --
> hw/loongarch/boot.c- *kernel_entry = extract64(le64_to_cpu(hdr->kernel_entry),
> hw/loongarch/boot.c: 0, TARGET_PHYS_ADDR_SPACE_BITS);
> hw/loongarch/boot.c- *kernel_low = extract64(le64_to_cpu(hdr->load_offset),
> hw/loongarch/boot.c: 0, TARGET_PHYS_ADDR_SPACE_BITS);
This is cpu_loongarch_virt_to_phys, and some repetitions.
This should probably use a loongarch-specific runtime function to find the address space
range supported by the chosen cpu. Or perhaps just a target-specific constant mask.
> linux-user/alpha/target_proc.h- "L3 cache\t\t: n/a\n",
> linux-user/alpha/target_proc.h: model, TARGET_PAGE_SIZE, TARGET_PHYS_ADDR_SPACE_BITS,
> linux-user/alpha/target_proc.h- max_cpus, num_cpus, cpu_mask);
This is the alpha-linux-user implementation of /proc/cpuinfo.
Ideally this should be a target-specific function; see
/* ??? EV4 has 34 phys addr bits, EV5 has 40, EV6 has 44. */
#define TARGET_PHYS_ADDR_SPACE_BITS 44
It's certainly not generic, and it's also not really important.
> --
> target/hppa/mem_helper.c: QEMU_BUILD_BUG_ON(TARGET_PHYS_ADDR_SPACE_BITS > 54);
> target/hppa/mem_helper.c: return sextract64(addr, 0, TARGET_PHYS_ADDR_SPACE_BITS);
> --
> target/hppa/mem_helper.c: addr |= -1ull << (TARGET_PHYS_ADDR_SPACE_BITS - 4);
> --
> target/hppa/mem_helper.c- /* Ignore the bits beyond physical address space. */
> target/hppa/mem_helper.c: ent->pa = sextract64(ent->pa, 0, TARGET_PHYS_ADDR_SPACE_BITS);
Similarly
/* ??? PA-8000 through 8600 have 40 bits; PA-8700 and 8900 have 44 bits. */
# define TARGET_PHYS_ADDR_SPACE_BITS 40
While we don't actually name concrete cpu models, bios advertises the (32-bit) HP B160L
machine, which originally had a 7300LC, and the (64-bit) which had a 8700.
I can't find definitive documentation, but I suspect the 7300LC has only 32 physical
address bits. And according to our own comment we get the 8700 value wrong.
In either case, it's not exposed to generic code.
> --
> target/i386/cpu.c- if (cpu->phys_bits &&
> target/i386/cpu.c: (cpu->phys_bits > TARGET_PHYS_ADDR_SPACE_BITS ||
> target/i386/cpu.c- cpu->phys_bits < 32)) {
> --
> target/i386/cpu.c- " (but is %u)",
> target/i386/cpu.c: TARGET_PHYS_ADDR_SPACE_BITS, cpu->phys_bits);
> --
> target/i386/kvm/kvm.c: QEMU_BUILD_BUG_ON(TARGET_PHYS_ADDR_SPACE_BITS > 52);
> target/i386/kvm/kvm.c: assert(cpu->phys_bits <= TARGET_PHYS_ADDR_SPACE_BITS);
All of these are simply making sure that cpu->phys_bits is "in range", which is now
irrelevant because TARGET_PHYS_ADDR_SPACE_BITS itself is no longer in use. They can all
be removed.
> --
> target/i386/tcg/helper-tcg.h:QEMU_BUILD_BUG_ON(TCG_PHYS_ADDR_BITS > TARGET_PHYS_ADDR_SPACE_BITS);
Likewise.
> target/loongarch/internals.h:#define TARGET_PHYS_MASK MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS)
This is used by target/loongarch/tcg/tlb_helper.c.
I'm not sure what the implications are.
Should it be using a common function with the loongarch boot virt-to-phys?
Is it re-using TARGET_PHYS_ADDR_SPACE_BITS just because it was convienient?
In either case, it's not exposed to generic code.
r~
next prev parent reply other threads:[~2025-10-17 18:48 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-15 13:27 [PATCH 0/5] single-binary: Prepare hw/riscv for single compilation Anton Johansson via
2025-10-15 13:27 ` [PATCH 1/5] hw/riscv: Use generic hwaddr for firmware addressses Anton Johansson via
2025-10-15 14:21 ` Philippe Mathieu-Daudé
2025-10-23 17:14 ` Anton Johansson via
2025-10-23 17:55 ` Philippe Mathieu-Daudé
2025-10-27 12:11 ` Anton Johansson via
2025-10-15 13:27 ` [PATCH 2/5] hw/riscv: Replace target_ulong uses Anton Johansson via
2025-10-15 14:22 ` Philippe Mathieu-Daudé
2025-10-15 16:31 ` Richard Henderson
2025-10-15 16:50 ` Philippe Mathieu-Daudé
2025-10-15 13:27 ` [PATCH 3/5] hw/riscv: Widen OpenSBI dynamic info struct Anton Johansson via
2025-10-16 23:42 ` Alistair Francis
2025-10-15 13:27 ` [PATCH 4/5] target-info: Introduce runtime TARGET_PHYS_ADDR_SPACE_BITS Anton Johansson via
2025-10-15 14:32 ` Philippe Mathieu-Daudé
2025-10-17 16:11 ` Anton Johansson via
2025-10-17 18:47 ` Richard Henderson [this message]
2025-10-18 2:34 ` Bibo Mao
2025-10-15 13:27 ` [PATCH 5/5] hw/riscv: Use runtime target_phys_addr_space_bits() Anton Johansson via
2025-10-16 23:43 ` Alistair Francis
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=8f0db5c1-f20b-4b7a-8d6c-76ce7ec7b4e0@linaro.org \
--to=richard.henderson@linaro.org \
--cc=alistair.francis@wdc.com \
--cc=anjo@rev.ng \
--cc=deller@gmx.de \
--cc=gaosong@loongson.cn \
--cc=palmer@dabbelt.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=pierrick.bouvier@linaro.org \
--cc=qemu-devel@nongnu.org \
/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).