linux/arch/powerpc
Michael Ellerman c5ff46d69c powerpc: Add ppc_inst_next()
In a few places we want to calculate the address of the next
instruction. Previously that was simple, we just added 4 bytes, or if
using a u32 * we incremented that pointer by 1.

But prefixed instructions make it more complicated, we need to advance
by either 4 or 8 bytes depending on the actual instruction. We also
can't do pointer arithmetic using struct ppc_inst, because it is
always 8 bytes in size on 64-bit, even though we might only need to
advance by 4 bytes.

So add a ppc_inst_next() helper which calculates the location of the
next instruction, if the given instruction was located at the given
address. Note the instruction doesn't need to actually be at the
address in memory.

Although it would seem natural for the value to be passed by value,
that makes it too easy to write a loop that will read off the end of a
page, eg:

	for (; src < end; src = ppc_inst_next(src, *src),
			  dest = ppc_inst_next(dest, *dest))

As noticed by Christophe and Jordan, if end is the exact end of a
page, and the next page is not mapped, this will fault, because *dest
will read 8 bytes, 4 bytes into the next page.

So value is passed by reference, so the helper can be careful to use
ppc_inst_read() on it.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Reviewed-by: Jordan Niethe <jniethe5@gmail.com>
Link: https://lore.kernel.org/r/20200522133318.1681406-1-mpe@ellerman.id.au
2020-05-26 23:36:51 +10:00
..
boot powerpc/ps3: Add check for otheros image size 2020-05-20 23:39:56 +10:00
configs powerpc/8xx: Drop CONFIG_8xx_COPYBACK option 2020-05-26 22:22:20 +10:00
crypto crypto: remove CRYPTO_TFM_RES_BAD_KEY_LEN 2020-01-09 11:30:53 +08:00
include powerpc: Add ppc_inst_next() 2020-05-26 23:36:51 +10:00
kernel powerpc: Add ppc_inst_next() 2020-05-26 23:36:51 +10:00
kexec powerpc updates for 5.7 2020-04-05 11:12:59 -07:00
kvm Merge branch 'topic/ppc-kvm' into next 2020-05-20 23:38:13 +10:00
lib powerpc: Add ppc_inst_next() 2020-05-26 23:36:51 +10:00
math-emu
mm Merge branch 'fixes' into next 2020-05-26 22:56:03 +10:00
net treewide: Use sizeof_field() macro 2019-12-09 10:36:44 -08:00
oprofile powerpc updates for 5.6 2020-02-04 13:06:46 +00:00
perf powerpc/8xx: Remove now unused TLB miss functions 2020-05-26 22:22:22 +10:00
platforms Merge branch 'fixes' into next 2020-05-26 22:56:03 +10:00
purgatory .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
sysdev Merge "Use hugepages to map kernel mem on 8xx" into next 2020-05-26 22:54:27 +10:00
tools powerpc/head_check: Avoid broken pipe 2020-05-19 00:10:35 +10:00
xmon powerpc: Add ppc_inst_next() 2020-05-26 23:36:51 +10:00
Kbuild powerpc/kexec: Move kexec files into a dedicated subdir. 2019-11-21 15:41:34 +11:00
Kconfig Merge branch 'fixes' into next 2020-05-26 22:56:03 +10:00
Kconfig.debug powerpc/ptdump: Only enable PPC_CHECK_WX with STRICT_KERNEL_RWX 2020-01-23 21:31:13 +11:00
Makefile powerpc: Suppress .eh_frame generation 2020-04-01 14:30:51 +11:00
Makefile.postlink powerpc: Do not consider weak unresolved symbol relocations as bad 2020-01-31 20:17:22 +11:00