Skip to content

Commit f0f5c48

Browse files
xen0nchenhuacai
authored andcommitted
LoongArch: KVM: Streamline kvm_check_cpucfg() and improve comments
All the checks currently done in kvm_check_cpucfg can be realized with early returns, so just do that to avoid extra cognitive burden related to the return value handling. While at it, clean up comments of _kvm_get_cpucfg_mask() and kvm_check_cpucfg(), by removing comments that are merely restatement of the code nearby, and paraphrasing the rest so they read more natural for English speakers (that likely are not familiar with the actual Chinese- influenced grammar). No functional changes intended. Reviewed-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: WANG Xuerui <git@xen0n.name> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent ec83f39 commit f0f5c48

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

arch/loongarch/kvm/vcpu.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -305,20 +305,16 @@ static int _kvm_get_cpucfg_mask(int id, u64 *v)
305305

306306
switch (id) {
307307
case 2:
308-
/* Return CPUCFG2 features which have been supported by KVM */
308+
/* CPUCFG2 features unconditionally supported by KVM */
309309
*v = CPUCFG2_FP | CPUCFG2_FPSP | CPUCFG2_FPDP |
310310
CPUCFG2_FPVERS | CPUCFG2_LLFTP | CPUCFG2_LLFTPREV |
311311
CPUCFG2_LAM;
312312
/*
313-
* If LSX is supported by CPU, it is also supported by KVM,
314-
* as we implement it.
313+
* For the ISA extensions listed below, if one is supported
314+
* by the host, then it is also supported by KVM.
315315
*/
316316
if (cpu_has_lsx)
317317
*v |= CPUCFG2_LSX;
318-
/*
319-
* if LASX is supported by CPU, it is also supported by KVM,
320-
* as we implement it.
321-
*/
322318
if (cpu_has_lasx)
323319
*v |= CPUCFG2_LASX;
324320

@@ -349,24 +345,26 @@ static int kvm_check_cpucfg(int id, u64 val)
349345

350346
switch (id) {
351347
case 2:
352-
/* CPUCFG2 features checking */
353348
if (!(val & CPUCFG2_LLFTP))
354-
/* The LLFTP must be set, as guest must has a constant timer */
355-
ret = -EINVAL;
356-
else if ((val & CPUCFG2_FP) && (!(val & CPUCFG2_FPSP) || !(val & CPUCFG2_FPDP)))
357-
/* Single and double float point must both be set when enable FP */
358-
ret = -EINVAL;
359-
else if ((val & CPUCFG2_LSX) && !(val & CPUCFG2_FP))
360-
/* FP should be set when enable LSX */
361-
ret = -EINVAL;
362-
else if ((val & CPUCFG2_LASX) && !(val & CPUCFG2_LSX))
363-
/* LSX, FP should be set when enable LASX, and FP has been checked before. */
364-
ret = -EINVAL;
365-
break;
349+
/* Guests must have a constant timer */
350+
return -EINVAL;
351+
if ((val & CPUCFG2_FP) && (!(val & CPUCFG2_FPSP) || !(val & CPUCFG2_FPDP)))
352+
/* Single and double float point must both be set when FP is enabled */
353+
return -EINVAL;
354+
if ((val & CPUCFG2_LSX) && !(val & CPUCFG2_FP))
355+
/* LSX architecturally implies FP but val does not satisfy that */
356+
return -EINVAL;
357+
if ((val & CPUCFG2_LASX) && !(val & CPUCFG2_LSX))
358+
/* LASX architecturally implies LSX and FP but val does not satisfy that */
359+
return -EINVAL;
360+
return 0;
366361
default:
367-
break;
362+
/*
363+
* Values for the other CPUCFG IDs are not being further validated
364+
* besides the mask check above.
365+
*/
366+
return 0;
368367
}
369-
return ret;
370368
}
371369

372370
static int kvm_get_one_reg(struct kvm_vcpu *vcpu,

0 commit comments

Comments
 (0)