qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, deller@kernel.org, alex.bennee@linaro.org,
	linux-parisc@vger.kernel.org, qemu-arm@nongnu.org
Subject: Re: [PATCH v2 13/21] target/arm: Pass MemOp to get_phys_addr
Date: Tue, 8 Oct 2024 10:32:42 -0700	[thread overview]
Message-ID: <5c33b223-10cc-4ad6-a3e8-15082266b31d@linaro.org> (raw)
In-Reply-To: <CAFEAcA_jXTuB6c8oVcXmi66zcXn5-PYM7W9z1wf7-fzXg7_Oiw@mail.gmail.com>

On 10/8/24 07:45, Peter Maydell wrote:
> On Sat, 5 Oct 2024 at 21:06, Richard Henderson
> <richard.henderson@linaro.org> wrote:
>>
>> Zero is the safe do-nothing value for callers to use.
>>
>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
>> ---
>>   target/arm/internals.h      | 3 ++-
>>   target/arm/ptw.c            | 2 +-
>>   target/arm/tcg/m_helper.c   | 8 ++++----
>>   target/arm/tcg/tlb_helper.c | 2 +-
>>   4 files changed, 8 insertions(+), 7 deletions(-)
> 
>> diff --git a/target/arm/tcg/m_helper.c b/target/arm/tcg/m_helper.c
>> index 23d7f73035..f7354f3c6e 100644
>> --- a/target/arm/tcg/m_helper.c
>> +++ b/target/arm/tcg/m_helper.c
>> @@ -222,7 +222,7 @@ static bool v7m_stack_write(ARMCPU *cpu, uint32_t addr, uint32_t value,
>>       int exc;
>>       bool exc_secure;
>>
>> -    if (get_phys_addr(env, addr, MMU_DATA_STORE, mmu_idx, &res, &fi)) {
>> +    if (get_phys_addr(env, addr, MMU_DATA_STORE, 0, mmu_idx, &res, &fi)) {
>>           /* MPU/SAU lookup failed */
>>           if (fi.type == ARMFault_QEMU_SFault) {
>>               if (mode == STACK_LAZYFP) {
>> @@ -311,7 +311,7 @@ static bool v7m_stack_read(ARMCPU *cpu, uint32_t *dest, uint32_t addr,
>>       bool exc_secure;
>>       uint32_t value;
>>
>> -    if (get_phys_addr(env, addr, MMU_DATA_LOAD, mmu_idx, &res, &fi)) {
>> +    if (get_phys_addr(env, addr, MMU_DATA_LOAD, 0, mmu_idx, &res, &fi)) {
>>           /* MPU/SAU lookup failed */
>>           if (fi.type == ARMFault_QEMU_SFault) {
>>               qemu_log_mask(CPU_LOG_INT,
> 
> We do actually know what kind of memory operation we're doing here:
> it's a 4-byte access. (It should never be unaligned because an M-profile
> SP can't ever be un-4-aligned, though I forget whether our implementation
> really enforces that.)
> 
>> @@ -2009,7 +2009,7 @@ static bool v7m_read_half_insn(ARMCPU *cpu, ARMMMUIdx mmu_idx, bool secure,
>>                         "...really SecureFault with SFSR.INVEP\n");
>>           return false;
>>       }
>> -    if (get_phys_addr(env, addr, MMU_INST_FETCH, mmu_idx, &res, &fi)) {
>> +    if (get_phys_addr(env, addr, MMU_INST_FETCH, 0, mmu_idx, &res, &fi)) {
>>           /* the MPU lookup failed */
>>           env->v7m.cfsr[env->v7m.secure] |= R_V7M_CFSR_IACCVIOL_MASK;
>>           armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_MEM, env->v7m.secure);
> 
> Similarly this is a 16-bit load that in theory should never
> be possible to be unaligned.
> 
>> @@ -2045,7 +2045,7 @@ static bool v7m_read_sg_stack_word(ARMCPU *cpu, ARMMMUIdx mmu_idx,
>>       ARMMMUFaultInfo fi = {};
>>       uint32_t value;
>>
>> -    if (get_phys_addr(env, addr, MMU_DATA_LOAD, mmu_idx, &res, &fi)) {
>> +    if (get_phys_addr(env, addr, MMU_DATA_LOAD, 0, mmu_idx, &res, &fi)) {
>>           /* MPU/SAU lookup failed */
>>           if (fi.type == ARMFault_QEMU_SFault) {
>>               qemu_log_mask(CPU_LOG_INT,
> 
> and this is another 4-byte load via sp.
> 
>> diff --git a/target/arm/tcg/tlb_helper.c b/target/arm/tcg/tlb_helper.c
>> index 885bf4ec14..1d8b7bcaa2 100644
>> --- a/target/arm/tcg/tlb_helper.c
>> +++ b/target/arm/tcg/tlb_helper.c
>> @@ -344,7 +344,7 @@ bool arm_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
>>        * return false.  Otherwise populate fsr with ARM DFSR/IFSR fault
>>        * register format, and signal the fault.
>>        */
>> -    ret = get_phys_addr(&cpu->env, address, access_type,
>> +    ret = get_phys_addr(&cpu->env, address, access_type, 0,
>>                           core_to_arm_mmu_idx(&cpu->env, mmu_idx),
>>                           &res, fi);
>>       if (likely(!ret)) {

The question is: if it should be impossible for them to be misaligned, should we pass an 
argument that checks alignment and then (!) potentially raise a guest exception.

I suspect the answer is no.

If it should be impossible, no alignment fault is ever visible to the guest in this 
context, then we should at most assert(), otherwise do nothing.

We *can* pass, e.g. MO_32 or MO_16 for documentation purposes, if you like.  Without 
additional adornment, this does not imply alignment enforcement (i.e. MO_ALIGN).  But this 
would be functionally indistinguishable from 0 (which I imperfectly documented with "or 0" 
in the function block comments).


r~


  reply	other threads:[~2024-10-08 17:33 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-05 20:05 [PATCH v2 00/21] accel/tcg: Introduce tlb_fill_align hook Richard Henderson
2024-10-05 20:05 ` [PATCH v2 01/21] accel/tcg: Assert noreturn from write-only page for atomics Richard Henderson
2024-10-07 20:58   ` Helge Deller
2024-10-08 14:04   ` Peter Maydell
2024-10-05 20:05 ` [PATCH v2 02/21] accel/tcg: Expand tlb_fill for 3 callers Richard Henderson
2024-10-07 21:01   ` Helge Deller
2024-10-08 14:04   ` Peter Maydell
2024-10-05 20:05 ` [PATCH v2 03/21] include/exec/memop: Move get_alignment_bits from tcg.h Richard Henderson
2024-10-07 21:02   ` Helge Deller
2024-10-08 14:04   ` Peter Maydell
2024-10-05 20:05 ` [PATCH v2 04/21] include/exec/memop: Rename get_alignment_bits Richard Henderson
2024-10-07 21:03   ` Helge Deller
2024-10-08 14:05   ` Peter Maydell
2024-10-05 20:05 ` [PATCH v2 05/21] include/exec/memop: Introduce memop_atomicity_bits Richard Henderson
2024-10-07 21:04   ` Helge Deller
2024-10-08 14:05   ` Peter Maydell
2024-10-05 20:05 ` [PATCH v2 06/21] hw/core/tcg-cpu-ops: Introduce tlb_fill_align hook Richard Henderson
2024-10-07 21:09   ` Helge Deller
2024-10-08 14:12   ` Peter Maydell
2024-10-05 20:05 ` [PATCH v2 07/21] accel/tcg: Use the " Richard Henderson
2024-10-07 21:13   ` Helge Deller
2024-10-08 14:12   ` Peter Maydell
2024-10-05 20:05 ` [PATCH v2 08/21] target/hppa: Add MemOp argument to hppa_get_physical_address Richard Henderson
2024-10-07 21:14   ` Helge Deller
2024-10-05 20:05 ` [PATCH v2 09/21] target/hppa: Perform access rights before protection id check Richard Henderson
2024-10-07 21:15   ` Helge Deller
2024-10-05 20:05 ` [PATCH v2 10/21] target/hppa: Fix priority of T, D, and B page faults Richard Henderson
2024-10-07 21:16   ` Helge Deller
2024-10-05 20:05 ` [PATCH v2 11/21] target/hppa: Handle alignment faults in hppa_get_physical_address Richard Henderson
2024-10-07 21:18   ` Helge Deller
2024-10-05 20:05 ` [PATCH v2 12/21] target/hppa: Add hppa_cpu_tlb_fill_align Richard Henderson
2024-10-07 21:19   ` Helge Deller
2024-10-05 20:05 ` [PATCH v2 13/21] target/arm: Pass MemOp to get_phys_addr Richard Henderson
2024-10-07 21:20   ` Helge Deller
2024-10-08 14:45   ` Peter Maydell
2024-10-08 17:32     ` Richard Henderson [this message]
2024-10-09 13:59       ` Peter Maydell
2024-10-05 20:05 ` [PATCH v2 14/21] target/arm: Pass MemOp to get_phys_addr_with_space_nogpc Richard Henderson
2024-10-07 21:21   ` Helge Deller
2024-10-08 14:35   ` Peter Maydell
2024-10-08 17:50     ` Richard Henderson
2024-10-05 20:05 ` [PATCH v2 15/21] target/arm: Pass MemOp to get_phys_addr_gpc Richard Henderson
2024-10-07 21:21   ` Helge Deller
2024-10-08 14:26   ` Peter Maydell
2024-10-05 20:05 ` [PATCH v2 16/21] target/arm: Pass MemOp to get_phys_addr_nogpc Richard Henderson
2024-10-07 21:22   ` Helge Deller
2024-10-08 14:25   ` Peter Maydell
2024-10-05 20:05 ` [PATCH v2 17/21] target/arm: Pass MemOp through get_phys_addr_twostage Richard Henderson
2024-10-07 21:22   ` Helge Deller
2024-10-08 14:24   ` Peter Maydell
2024-10-05 20:05 ` [PATCH v2 18/21] target/arm: Pass MemOp to get_phys_addr_lpae Richard Henderson
2024-10-07 21:23   ` Helge Deller
2024-10-08 14:24   ` Peter Maydell
2024-10-05 20:05 ` [PATCH v2 19/21] target/arm: Move device detection earlier in get_phys_addr_lpae Richard Henderson
2024-10-07 21:25   ` Helge Deller
2024-10-08 14:22   ` Peter Maydell
2024-10-05 20:05 ` [PATCH v2 20/21] target/arm: Add arm_cpu_tlb_fill_align Richard Henderson
2024-10-07 21:26   ` Helge Deller
2024-10-08 14:22   ` Peter Maydell
2024-10-05 20:06 ` [PATCH v2 21/21] target/arm: Fix alignment fault priority in get_phys_addr_lpae Richard Henderson
2024-10-08 14:23   ` Peter Maydell
2024-10-07 20:55 ` [PATCH v2 00/21] accel/tcg: Introduce tlb_fill_align hook Helge Deller

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=5c33b223-10cc-4ad6-a3e8-15082266b31d@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=deller@kernel.org \
    --cc=linux-parisc@vger.kernel.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.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).