From: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
To: Sandipan Das <sandipan@linux.ibm.com>
Cc: ravi.bangoria@linux.ibm.com, ananth@linux.ibm.com,
jniethe5@gmail.com, paulus@samba.org,
linuxppc-dev@lists.ozlabs.org, dja@axtens.net
Subject: Re: [PATCH v2 1/3] powerpc: sstep: Fix load and update emulation
Date: Wed, 3 Feb 2021 15:19:09 +0530 [thread overview]
Message-ID: <20210203094909.GD210@DESKTOP-TDPLP67.localdomain> (raw)
In-Reply-To: <20210203063841.431063-1-sandipan@linux.ibm.com>
On 2021/02/03 12:08PM, Sandipan Das wrote:
> The Power ISA says that the fixed-point load and update
> instructions must neither use R0 for the base address (RA)
> nor have the destination (RT) and the base address (RA) as
> the same register. In these cases, the instruction is
> invalid. This applies to the following instructions.
> * Load Byte and Zero with Update (lbzu)
> * Load Byte and Zero with Update Indexed (lbzux)
> * Load Halfword and Zero with Update (lhzu)
> * Load Halfword and Zero with Update Indexed (lhzux)
> * Load Halfword Algebraic with Update (lhau)
> * Load Halfword Algebraic with Update Indexed (lhaux)
> * Load Word and Zero with Update (lwzu)
> * Load Word and Zero with Update Indexed (lwzux)
> * Load Word Algebraic with Update Indexed (lwaux)
> * Load Doubleword with Update (ldu)
> * Load Doubleword with Update Indexed (ldux)
>
> However, the following behaviour is observed using some
> invalid opcodes where RA = RT.
>
> An userspace program using an invalid instruction word like
> 0xe9ce0001, i.e. "ldu r14, 0(r14)", runs and exits without
> getting terminated abruptly. The instruction performs the
> load operation but does not write the effective address to
> the base address register.
While the processor (p8 in my test) doesn't seem to be throwing an
exception, I don't think it is necessarily loading the value. Qemu
throws an exception though. It's probably best to term the behavior as
being undefined.
> Attaching an uprobe at that
> instruction's address results in emulation which writes the
> effective address to the base register. Thus, the final value
> of the base address register is different.
>
> To remove any inconsistencies, this adds an additional check
> for the aforementioned instructions to make sure that they
> are treated as unknown by the emulation infrastructure when
> RA = 0 or RA = RT. The kernel will then fallback to executing
> the instruction on hardware.
>
> Fixes: 0016a4cf5582 ("powerpc: Emulate most Book I instructions in emulate_step()")
> Reviewed-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
> Signed-off-by: Sandipan Das <sandipan@linux.ibm.com>
> ---
> Previous versions can be found at:
> v1: https://lore.kernel.org/linuxppc-dev/20201119054139.244083-1-sandipan@linux.ibm.com/
>
> Changes in v2:
> - Jump to unknown_opcode instead of returning -1 for invalid
> instruction forms.
>
> ---
> arch/powerpc/lib/sstep.c | 22 ++++++++++++++++++++++
> 1 file changed, 22 insertions(+)
Wouldn't it be easier to just do the below at the end? Or, am I missing something?
diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
index ede093e9623472..a2d726d2a5e9d1 100644
--- a/arch/powerpc/lib/sstep.c
+++ b/arch/powerpc/lib/sstep.c
@@ -2980,6 +2980,10 @@ int analyse_instr(struct instruction_op *op, const struct pt_regs *regs,
}
#endif /* CONFIG_VSX */
+ if (GETTYPE(op->type) == LOAD && (op->type & UPDATE) &&
+ (ra == 0 || ra == rd))
+ goto unknown_opcode;
+
return 0;
logical_done:
- Naveen
next prev parent reply other threads:[~2021-02-03 9:51 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-03 6:38 [PATCH v2 1/3] powerpc: sstep: Fix load and update emulation Sandipan Das
2021-02-03 6:38 ` [PATCH v2 2/3] powerpc: sstep: Fix store " Sandipan Das
2021-02-03 6:38 ` [PATCH v2 3/3] powerpc: sstep: Fix darn emulation Sandipan Das
2021-02-03 9:49 ` Naveen N. Rao [this message]
2021-02-03 10:35 ` [PATCH v2 1/3] powerpc: sstep: Fix load and update emulation Sandipan Das
2021-02-03 11:37 ` Sandipan Das
2021-02-04 0:53 ` Michael Ellerman
2021-02-03 21:17 ` Segher Boessenkool
2021-02-04 8:27 ` Naveen N. Rao
2021-03-02 2:37 ` Segher Boessenkool
2021-03-03 16:31 ` Naveen N. Rao
2021-03-04 15:45 ` Segher Boessenkool
2021-03-04 1:06 ` Naveen N. Rao
2021-02-04 10:29 ` David Laight
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=20210203094909.GD210@DESKTOP-TDPLP67.localdomain \
--to=naveen.n.rao@linux.vnet.ibm.com \
--cc=ananth@linux.ibm.com \
--cc=dja@axtens.net \
--cc=jniethe5@gmail.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=paulus@samba.org \
--cc=ravi.bangoria@linux.ibm.com \
--cc=sandipan@linux.ibm.com \
/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