Skip to content

Commit c0b3467

Browse files
committed
Merge branch 'topic/ppc-kvm' into next
Merge the DAWR series, which touches arch code and KVM code and may need to be merged into the kvm-ppc tree.
2 parents 34a286a + 9654153 commit c0b3467

File tree

10 files changed

+59
-6
lines changed

10 files changed

+59
-6
lines changed

arch/powerpc/include/asm/cputable.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,8 @@ static inline void cpu_feature_keys_init(void) { }
464464
CPU_FTR_DSCR | CPU_FTR_SAO | \
465465
CPU_FTR_STCX_CHECKS_ADDRESS | CPU_FTR_POPCNTB | CPU_FTR_POPCNTD | \
466466
CPU_FTR_CFAR | CPU_FTR_HVMODE | CPU_FTR_VMX_COPY | \
467-
CPU_FTR_DBELL | CPU_FTR_HAS_PPR | CPU_FTR_DAWR | \
468-
CPU_FTR_ARCH_207S | CPU_FTR_TM_COMP | CPU_FTR_ARCH_300 | \
469-
CPU_FTR_PKEY)
467+
CPU_FTR_DBELL | CPU_FTR_HAS_PPR | CPU_FTR_ARCH_207S | \
468+
CPU_FTR_TM_COMP | CPU_FTR_ARCH_300 | CPU_FTR_PKEY)
470469
#define CPU_FTRS_POWER9_DD1 ((CPU_FTRS_POWER9 | CPU_FTR_POWER9_DD1) & \
471470
(~CPU_FTR_SAO))
472471
#define CPU_FTRS_POWER9_DD2_0 CPU_FTRS_POWER9

arch/powerpc/include/asm/debug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static inline int debugger_fault_handler(struct pt_regs *regs) { return 0; }
4747

4848
void set_breakpoint(struct arch_hw_breakpoint *brk);
4949
void __set_breakpoint(struct arch_hw_breakpoint *brk);
50+
bool ppc_breakpoint_available(void);
5051
#ifdef CONFIG_PPC_ADV_DEBUG_REGS
5152
extern void do_send_trap(struct pt_regs *regs, unsigned long address,
5253
unsigned long error_code, int brkpt);

arch/powerpc/include/asm/hvcall.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
#define H_P8 -61
8989
#define H_P9 -62
9090
#define H_TOO_BIG -64
91+
#define H_UNSUPPORTED -67
9192
#define H_OVERLAP -68
9293
#define H_INTERRUPT -69
9394
#define H_BAD_DATA -70

arch/powerpc/kernel/dt_cpu_ftrs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,9 @@ static __init void cpufeatures_cpu_quirks(void)
713713
else if ((version & 0xffffefff) == 0x004e0202)
714714
cur_cpu_spec->cpu_features |= CPU_FTR_P9_TM_HV_ASSIST |
715715
CPU_FTR_P9_TM_XER_SO_BUG;
716+
717+
if ((version & 0xffff0000) == 0x004e0000)
718+
cur_cpu_spec->cpu_features &= ~(CPU_FTR_DAWR);
716719
}
717720

718721
static void __init cpufeatures_setup_finished(void)

arch/powerpc/kernel/hw_breakpoint.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <asm/hw_breakpoint.h>
3434
#include <asm/processor.h>
3535
#include <asm/sstep.h>
36+
#include <asm/debug.h>
3637
#include <linux/uaccess.h>
3738

3839
/*
@@ -171,6 +172,8 @@ int arch_validate_hwbkpt_settings(struct perf_event *bp)
171172
* HW_BREAKPOINT_ALIGN by rounding off to the lower address, the
172173
* 'symbolsize' should satisfy the check below.
173174
*/
175+
if (!ppc_breakpoint_available())
176+
return -ENODEV;
174177
length_max = 8; /* DABR */
175178
if (cpu_has_feature(CPU_FTR_DAWR)) {
176179
length_max = 512 ; /* 64 doublewords */

arch/powerpc/kernel/process.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,18 @@ void set_breakpoint(struct arch_hw_breakpoint *brk)
827827
preempt_enable();
828828
}
829829

830+
/* Check if we have DAWR or DABR hardware */
831+
bool ppc_breakpoint_available(void)
832+
{
833+
if (cpu_has_feature(CPU_FTR_DAWR))
834+
return true; /* POWER8 DAWR */
835+
if (cpu_has_feature(CPU_FTR_ARCH_207S))
836+
return false; /* POWER9 with DAWR disabled */
837+
/* DABR: Everything but POWER8 and POWER9 */
838+
return true;
839+
}
840+
EXPORT_SYMBOL_GPL(ppc_breakpoint_available);
841+
830842
#ifdef CONFIG_PPC64
831843
DEFINE_PER_CPU(struct cpu_usage, cpu_usage_array);
832844
#endif

arch/powerpc/kernel/ptrace.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <asm/switch_to.h>
4242
#include <asm/tm.h>
4343
#include <asm/asm-prototypes.h>
44+
#include <asm/debug.h>
4445

4546
#define CREATE_TRACE_POINTS
4647
#include <trace/events/syscalls.h>
@@ -2378,6 +2379,7 @@ static int ptrace_set_debugreg(struct task_struct *task, unsigned long addr,
23782379
struct perf_event_attr attr;
23792380
#endif /* CONFIG_HAVE_HW_BREAKPOINT */
23802381
#ifndef CONFIG_PPC_ADV_DEBUG_REGS
2382+
bool set_bp = true;
23812383
struct arch_hw_breakpoint hw_brk;
23822384
#endif
23832385

@@ -2411,9 +2413,10 @@ static int ptrace_set_debugreg(struct task_struct *task, unsigned long addr,
24112413
hw_brk.address = data & (~HW_BRK_TYPE_DABR);
24122414
hw_brk.type = (data & HW_BRK_TYPE_DABR) | HW_BRK_TYPE_PRIV_ALL;
24132415
hw_brk.len = 8;
2416+
set_bp = (data) && (hw_brk.type & HW_BRK_TYPE_RDWR);
24142417
#ifdef CONFIG_HAVE_HW_BREAKPOINT
24152418
bp = thread->ptrace_bps[0];
2416-
if ((!data) || !(hw_brk.type & HW_BRK_TYPE_RDWR)) {
2419+
if (!set_bp) {
24172420
if (bp) {
24182421
unregister_hw_breakpoint(bp);
24192422
thread->ptrace_bps[0] = NULL;
@@ -2450,6 +2453,9 @@ static int ptrace_set_debugreg(struct task_struct *task, unsigned long addr,
24502453
return PTR_ERR(bp);
24512454
}
24522455

2456+
#else /* !CONFIG_HAVE_HW_BREAKPOINT */
2457+
if (set_bp && (!ppc_breakpoint_available()))
2458+
return -ENODEV;
24532459
#endif /* CONFIG_HAVE_HW_BREAKPOINT */
24542460
task->thread.hw_brk = hw_brk;
24552461
#else /* CONFIG_PPC_ADV_DEBUG_REGS */
@@ -2904,6 +2910,9 @@ static long ppc_set_hwdebug(struct task_struct *child,
29042910
if (child->thread.hw_brk.address)
29052911
return -ENOSPC;
29062912

2913+
if (!ppc_breakpoint_available())
2914+
return -ENODEV;
2915+
29072916
child->thread.hw_brk = brk;
29082917

29092918
return 1;
@@ -3052,7 +3061,10 @@ long arch_ptrace(struct task_struct *child, long request,
30523061
#endif
30533062
#else /* !CONFIG_PPC_ADV_DEBUG_REGS */
30543063
dbginfo.num_instruction_bps = 0;
3055-
dbginfo.num_data_bps = 1;
3064+
if (ppc_breakpoint_available())
3065+
dbginfo.num_data_bps = 1;
3066+
else
3067+
dbginfo.num_data_bps = 0;
30563068
dbginfo.num_condition_regs = 0;
30573069
#ifdef CONFIG_PPC64
30583070
dbginfo.data_bp_alignment = 8;

arch/powerpc/kvm/book3s_hv.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ static int kvmppc_h_set_mode(struct kvm_vcpu *vcpu, unsigned long mflags,
741741
case H_SET_MODE_RESOURCE_SET_DAWR:
742742
if (!kvmppc_power8_compatible(vcpu))
743743
return H_P2;
744+
if (!ppc_breakpoint_available())
745+
return H_P2;
744746
if (mflags)
745747
return H_UNSUPPORTED_FLAG_START;
746748
if (value2 & DABRX_HYP)

arch/powerpc/kvm/book3s_hv_rmhandlers.S

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,8 +892,14 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
892892
ld r6, VCPU_DAWRX(r4)
893893
ld r7, VCPU_CIABR(r4)
894894
ld r8, VCPU_TAR(r4)
895+
/*
896+
* Handle broken DAWR case by not writing it. This means we
897+
* can still store the DAWR register for migration.
898+
*/
899+
BEGIN_FTR_SECTION
895900
mtspr SPRN_DAWR, r5
896901
mtspr SPRN_DAWRX, r6
902+
END_FTR_SECTION_IFSET(CPU_FTR_DAWR)
897903
mtspr SPRN_CIABR, r7
898904
mtspr SPRN_TAR, r8
899905
ld r5, VCPU_IC(r4)
@@ -1855,6 +1861,10 @@ BEGIN_FTR_SECTION
18551861
ld r6, STACK_SLOT_DAWR(r1)
18561862
ld r7, STACK_SLOT_DAWRX(r1)
18571863
mtspr SPRN_CIABR, r5
1864+
/*
1865+
* If the DAWR doesn't work, it's ok to write these here as
1866+
* this value should always be zero
1867+
*/
18581868
mtspr SPRN_DAWR, r6
18591869
mtspr SPRN_DAWRX, r7
18601870
END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
@@ -2563,8 +2573,14 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
25632573
li r3,0
25642574
blr
25652575

2576+
2:
2577+
BEGIN_FTR_SECTION
2578+
/* POWER9 with disabled DAWR */
2579+
li r3, H_UNSUPPORTED
2580+
blr
2581+
END_FTR_SECTION_IFCLR(CPU_FTR_DAWR)
25662582
/* Emulate H_SET_DABR/X on P8 for the sake of compat mode guests */
2567-
2: rlwimi r5, r4, 5, DAWRX_DR | DAWRX_DW
2583+
rlwimi r5, r4, 5, DAWRX_DR | DAWRX_DW
25682584
rlwimi r5, r4, 2, DAWRX_WT
25692585
clrrdi r4, r4, 3
25702586
std r4, VCPU_DAWR(r3)

arch/powerpc/xmon/xmon.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,10 @@ bpt_cmds(void)
13021302
static const char badaddr[] = "Only kernel addresses are permitted for breakpoints\n";
13031303
int mode;
13041304
case 'd': /* bd - hardware data breakpoint */
1305+
if (!ppc_breakpoint_available()) {
1306+
printf("Hardware data breakpoint not supported on this cpu\n");
1307+
break;
1308+
}
13051309
mode = 7;
13061310
cmd = inchar();
13071311
if (cmd == 'r')

0 commit comments

Comments
 (0)