Skip to content

Commit ddca156

Browse files
kvaneeshagraf
authored andcommitted
KVM: PPC: BOOK3S: Remove open coded make_dsisr in alignment handler
Use make_dsisr instead of open coding it. This also have the added benefit of handling alignment interrupt on additional instructions. Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Signed-off-by: Alexander Graf <agraf@suse.de>
1 parent 7310f3a commit ddca156

3 files changed

Lines changed: 36 additions & 71 deletions

File tree

‎arch/powerpc/include/asm/disassemble.h‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,38 @@ static inline unsigned int get_oc(u32 inst)
8181
{
8282
return (inst >> 11) & 0x7fff;
8383
}
84+
85+
#define IS_XFORM(inst) (get_op(inst) == 31)
86+
#define IS_DSFORM(inst) (get_op(inst) >= 56)
87+
88+
/*
89+
* Create a DSISR value from the instruction
90+
*/
91+
static inline unsigned make_dsisr(unsigned instr)
92+
{
93+
unsigned dsisr;
94+
95+
96+
/* bits 6:15 --> 22:31 */
97+
dsisr = (instr & 0x03ff0000) >> 16;
98+
99+
if (IS_XFORM(instr)) {
100+
/* bits 29:30 --> 15:16 */
101+
dsisr |= (instr & 0x00000006) << 14;
102+
/* bit 25 --> 17 */
103+
dsisr |= (instr & 0x00000040) << 8;
104+
/* bits 21:24 --> 18:21 */
105+
dsisr |= (instr & 0x00000780) << 3;
106+
} else {
107+
/* bit 5 --> 17 */
108+
dsisr |= (instr & 0x04000000) >> 12;
109+
/* bits 1: 4 --> 18:21 */
110+
dsisr |= (instr & 0x78000000) >> 17;
111+
/* bits 30:31 --> 12:13 */
112+
if (IS_DSFORM(instr))
113+
dsisr |= (instr & 0x00000003) << 18;
114+
}
115+
116+
return dsisr;
117+
}
84118
#endif /* __ASM_PPC_DISASSEMBLE_H__ */

‎arch/powerpc/kernel/align.c‎

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@
2525
#include <asm/cputable.h>
2626
#include <asm/emulated_ops.h>
2727
#include <asm/switch_to.h>
28+
#include <asm/disassemble.h>
2829

2930
struct aligninfo {
3031
unsigned char len;
3132
unsigned char flags;
3233
};
3334

34-
#define IS_XFORM(inst) (((inst) >> 26) == 31)
35-
#define IS_DSFORM(inst) (((inst) >> 26) >= 56)
3635

3736
#define INVALID { 0, 0 }
3837

@@ -191,37 +190,6 @@ static struct aligninfo aligninfo[128] = {
191190
INVALID, /* 11 1 1111 */
192191
};
193192

194-
/*
195-
* Create a DSISR value from the instruction
196-
*/
197-
static inline unsigned make_dsisr(unsigned instr)
198-
{
199-
unsigned dsisr;
200-
201-
202-
/* bits 6:15 --> 22:31 */
203-
dsisr = (instr & 0x03ff0000) >> 16;
204-
205-
if (IS_XFORM(instr)) {
206-
/* bits 29:30 --> 15:16 */
207-
dsisr |= (instr & 0x00000006) << 14;
208-
/* bit 25 --> 17 */
209-
dsisr |= (instr & 0x00000040) << 8;
210-
/* bits 21:24 --> 18:21 */
211-
dsisr |= (instr & 0x00000780) << 3;
212-
} else {
213-
/* bit 5 --> 17 */
214-
dsisr |= (instr & 0x04000000) >> 12;
215-
/* bits 1: 4 --> 18:21 */
216-
dsisr |= (instr & 0x78000000) >> 17;
217-
/* bits 30:31 --> 12:13 */
218-
if (IS_DSFORM(instr))
219-
dsisr |= (instr & 0x00000003) << 18;
220-
}
221-
222-
return dsisr;
223-
}
224-
225193
/*
226194
* The dcbz (data cache block zero) instruction
227195
* gives an alignment fault if used on non-cacheable

‎arch/powerpc/kvm/book3s_emulate.c‎

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -634,44 +634,7 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val
634634

635635
u32 kvmppc_alignment_dsisr(struct kvm_vcpu *vcpu, unsigned int inst)
636636
{
637-
u32 dsisr = 0;
638-
639-
/*
640-
* This is what the spec says about DSISR bits (not mentioned = 0):
641-
*
642-
* 12:13 [DS] Set to bits 30:31
643-
* 15:16 [X] Set to bits 29:30
644-
* 17 [X] Set to bit 25
645-
* [D/DS] Set to bit 5
646-
* 18:21 [X] Set to bits 21:24
647-
* [D/DS] Set to bits 1:4
648-
* 22:26 Set to bits 6:10 (RT/RS/FRT/FRS)
649-
* 27:31 Set to bits 11:15 (RA)
650-
*/
651-
652-
switch (get_op(inst)) {
653-
/* D-form */
654-
case OP_LFS:
655-
case OP_LFD:
656-
case OP_STFD:
657-
case OP_STFS:
658-
dsisr |= (inst >> 12) & 0x4000; /* bit 17 */
659-
dsisr |= (inst >> 17) & 0x3c00; /* bits 18:21 */
660-
break;
661-
/* X-form */
662-
case 31:
663-
dsisr |= (inst << 14) & 0x18000; /* bits 15:16 */
664-
dsisr |= (inst << 8) & 0x04000; /* bit 17 */
665-
dsisr |= (inst << 3) & 0x03c00; /* bits 18:21 */
666-
break;
667-
default:
668-
printk(KERN_INFO "KVM: Unaligned instruction 0x%x\n", inst);
669-
break;
670-
}
671-
672-
dsisr |= (inst >> 16) & 0x03ff; /* bits 22:31 */
673-
674-
return dsisr;
637+
return make_dsisr(inst);
675638
}
676639

677640
ulong kvmppc_alignment_dar(struct kvm_vcpu *vcpu, unsigned int inst)

0 commit comments

Comments
 (0)