mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-28 11:18:45 +07:00
16ef9767e4
The code patching code wants to get the value of a struct ppc_inst as
a u64 when the instruction is prefixed, so we can pass the u64 down to
__put_user_asm() and write it with a single store.
The optprobes code wants to load a struct ppc_inst as an immediate
into a register so it is useful to have it as a u64 to use the
existing helper function.
Currently this is a bit awkward because the value differs based on the
CPU endianness, so add a helper to do the conversion.
This fixes the usage in arch_prepare_optimized_kprobe() which was
previously incorrect on big endian.
Fixes: 650b55b707
("powerpc: Add prefixed instructions to instruction data type")
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Tested-by: Jordan Niethe <jniethe5@gmail.com>
Link: https://lore.kernel.org/r/20200526072630.2487363-1-mpe@ellerman.id.au
132 lines
2.6 KiB
C
132 lines
2.6 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
#ifndef _ASM_POWERPC_INST_H
|
|
#define _ASM_POWERPC_INST_H
|
|
|
|
#include <asm/ppc-opcode.h>
|
|
|
|
/*
|
|
* Instruction data type for POWER
|
|
*/
|
|
|
|
struct ppc_inst {
|
|
u32 val;
|
|
#ifdef CONFIG_PPC64
|
|
u32 suffix;
|
|
#endif
|
|
} __packed;
|
|
|
|
static inline u32 ppc_inst_val(struct ppc_inst x)
|
|
{
|
|
return x.val;
|
|
}
|
|
|
|
static inline int ppc_inst_primary_opcode(struct ppc_inst x)
|
|
{
|
|
return ppc_inst_val(x) >> 26;
|
|
}
|
|
|
|
#ifdef CONFIG_PPC64
|
|
#define ppc_inst(x) ((struct ppc_inst){ .val = (x), .suffix = 0xff })
|
|
|
|
#define ppc_inst_prefix(x, y) ((struct ppc_inst){ .val = (x), .suffix = (y) })
|
|
|
|
static inline u32 ppc_inst_suffix(struct ppc_inst x)
|
|
{
|
|
return x.suffix;
|
|
}
|
|
|
|
static inline bool ppc_inst_prefixed(struct ppc_inst x)
|
|
{
|
|
return (ppc_inst_primary_opcode(x) == 1) && ppc_inst_suffix(x) != 0xff;
|
|
}
|
|
|
|
static inline struct ppc_inst ppc_inst_swab(struct ppc_inst x)
|
|
{
|
|
return ppc_inst_prefix(swab32(ppc_inst_val(x)),
|
|
swab32(ppc_inst_suffix(x)));
|
|
}
|
|
|
|
static inline struct ppc_inst ppc_inst_read(const struct ppc_inst *ptr)
|
|
{
|
|
u32 val, suffix;
|
|
|
|
val = *(u32 *)ptr;
|
|
if ((val >> 26) == OP_PREFIX) {
|
|
suffix = *((u32 *)ptr + 1);
|
|
return ppc_inst_prefix(val, suffix);
|
|
} else {
|
|
return ppc_inst(val);
|
|
}
|
|
}
|
|
|
|
static inline bool ppc_inst_equal(struct ppc_inst x, struct ppc_inst y)
|
|
{
|
|
return *(u64 *)&x == *(u64 *)&y;
|
|
}
|
|
|
|
#else
|
|
|
|
#define ppc_inst(x) ((struct ppc_inst){ .val = x })
|
|
|
|
static inline bool ppc_inst_prefixed(struct ppc_inst x)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
static inline u32 ppc_inst_suffix(struct ppc_inst x)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline struct ppc_inst ppc_inst_swab(struct ppc_inst x)
|
|
{
|
|
return ppc_inst(swab32(ppc_inst_val(x)));
|
|
}
|
|
|
|
static inline struct ppc_inst ppc_inst_read(const struct ppc_inst *ptr)
|
|
{
|
|
return *ptr;
|
|
}
|
|
|
|
static inline bool ppc_inst_equal(struct ppc_inst x, struct ppc_inst y)
|
|
{
|
|
return ppc_inst_val(x) == ppc_inst_val(y);
|
|
}
|
|
|
|
#endif /* CONFIG_PPC64 */
|
|
|
|
static inline int ppc_inst_len(struct ppc_inst x)
|
|
{
|
|
return ppc_inst_prefixed(x) ? 8 : 4;
|
|
}
|
|
|
|
/*
|
|
* Return the address of the next instruction, if the instruction @value was
|
|
* located at @location.
|
|
*/
|
|
static inline struct ppc_inst *ppc_inst_next(void *location, struct ppc_inst *value)
|
|
{
|
|
struct ppc_inst tmp;
|
|
|
|
tmp = ppc_inst_read(value);
|
|
|
|
return location + ppc_inst_len(tmp);
|
|
}
|
|
|
|
static inline u64 ppc_inst_as_u64(struct ppc_inst x)
|
|
{
|
|
#ifdef CONFIG_CPU_LITTLE_ENDIAN
|
|
return (u64)ppc_inst_suffix(x) << 32 | ppc_inst_val(x);
|
|
#else
|
|
return (u64)ppc_inst_val(x) << 32 | ppc_inst_suffix(x);
|
|
#endif
|
|
}
|
|
|
|
int probe_user_read_inst(struct ppc_inst *inst,
|
|
struct ppc_inst __user *nip);
|
|
|
|
int probe_kernel_read_inst(struct ppc_inst *inst,
|
|
struct ppc_inst *src);
|
|
|
|
#endif /* _ASM_POWERPC_INST_H */
|