Skip to content

Commit df08bd1

Browse files
agrafavikivity
authored andcommitted
KVM: PPC: Make PV mtmsrd L=1 work with r30 and r31
We had an arbitrary limitation in mtmsrd L=1 that kept us from using r30 and r31 as input registers. Let's get rid of that and get more potential speedups! Signed-off-by: Alexander Graf <agraf@suse.de>
1 parent 9ee18b1 commit df08bd1

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

‎arch/powerpc/kernel/kvm.c‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ static u32 *kvm_alloc(int len)
158158

159159
extern u32 kvm_emulate_mtmsrd_branch_offs;
160160
extern u32 kvm_emulate_mtmsrd_reg_offs;
161+
extern u32 kvm_emulate_mtmsrd_orig_ins_offs;
161162
extern u32 kvm_emulate_mtmsrd_len;
162163
extern u32 kvm_emulate_mtmsrd[];
163164

@@ -186,7 +187,21 @@ static void kvm_patch_ins_mtmsrd(u32 *inst, u32 rt)
186187
/* Modify the chunk to fit the invocation */
187188
memcpy(p, kvm_emulate_mtmsrd, kvm_emulate_mtmsrd_len * 4);
188189
p[kvm_emulate_mtmsrd_branch_offs] |= distance_end & KVM_INST_B_MASK;
189-
p[kvm_emulate_mtmsrd_reg_offs] |= rt;
190+
switch (get_rt(rt)) {
191+
case 30:
192+
kvm_patch_ins_ll(&p[kvm_emulate_mtmsrd_reg_offs],
193+
magic_var(scratch2), KVM_RT_30);
194+
break;
195+
case 31:
196+
kvm_patch_ins_ll(&p[kvm_emulate_mtmsrd_reg_offs],
197+
magic_var(scratch1), KVM_RT_30);
198+
break;
199+
default:
200+
p[kvm_emulate_mtmsrd_reg_offs] |= rt;
201+
break;
202+
}
203+
204+
p[kvm_emulate_mtmsrd_orig_ins_offs] = *inst;
190205
flush_icache_range((ulong)p, (ulong)p + kvm_emulate_mtmsrd_len * 4);
191206

192207
/* Patch the invocation */
@@ -423,9 +438,7 @@ static void kvm_check_ins(u32 *inst, u32 features)
423438

424439
/* Rewrites */
425440
case KVM_INST_MTMSRD_L1:
426-
/* We use r30 and r31 during the hook */
427-
if (get_rt(inst_rt) < 30)
428-
kvm_patch_ins_mtmsrd(inst, inst_rt);
441+
kvm_patch_ins_mtmsrd(inst, inst_rt);
429442
break;
430443
case KVM_INST_MTMSR:
431444
case KVM_INST_MTMSRD_L0:

‎arch/powerpc/kernel/kvm_emul.S‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ kvm_emulate_mtmsrd:
7878

7979
/* OR the register's (MSR_EE|MSR_RI) on MSR */
8080
kvm_emulate_mtmsrd_reg:
81-
andi. r30, r0, (MSR_EE|MSR_RI)
81+
ori r30, r0, 0
82+
andi. r30, r30, (MSR_EE|MSR_RI)
8283
or r31, r31, r30
8384

8485
/* Put MSR back into magic page */
@@ -96,6 +97,7 @@ kvm_emulate_mtmsrd_reg:
9697
SCRATCH_RESTORE
9798

9899
/* Nag hypervisor */
100+
kvm_emulate_mtmsrd_orig_ins:
99101
tlbsync
100102

101103
b kvm_emulate_mtmsrd_branch
@@ -117,6 +119,10 @@ kvm_emulate_mtmsrd_branch_offs:
117119
kvm_emulate_mtmsrd_reg_offs:
118120
.long (kvm_emulate_mtmsrd_reg - kvm_emulate_mtmsrd) / 4
119121

122+
.global kvm_emulate_mtmsrd_orig_ins_offs
123+
kvm_emulate_mtmsrd_orig_ins_offs:
124+
.long (kvm_emulate_mtmsrd_orig_ins - kvm_emulate_mtmsrd) / 4
125+
120126
.global kvm_emulate_mtmsrd_len
121127
kvm_emulate_mtmsrd_len:
122128
.long (kvm_emulate_mtmsrd_end - kvm_emulate_mtmsrd) / 4

0 commit comments

Comments
 (0)