Skip to content

Commit de0c513

Browse files
bibo-maochenhuacai
authored andcommitted
LoongArch: KVM: Add more CPUCFG mask bits
With new CPU cores there are more features supported which are indicated in CPUCFG2 bits 24:30 and CPUCFG3 bits 17:23. The KVM hypervisor cannot enable or disable (most of) these features and there is no KVM exception when instructions of these features are executed in guest mode. Here add more CPUCFG mask support with LA664 CPU type. Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent 18f7fcd commit de0c513

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

arch/loongarch/kvm/vcpu.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,8 @@ static int _kvm_setcsr(struct kvm_vcpu *vcpu, unsigned int id, u64 val)
652652

653653
static int _kvm_get_cpucfg_mask(int id, u64 *v)
654654
{
655+
unsigned int config;
656+
655657
if (id < 0 || id >= KVM_MAX_CPUCFG_REGS)
656658
return -EINVAL;
657659

@@ -684,9 +686,17 @@ static int _kvm_get_cpucfg_mask(int id, u64 *v)
684686
if (cpu_has_ptw)
685687
*v |= CPUCFG2_PTW;
686688

689+
config = read_cpucfg(LOONGARCH_CPUCFG2);
690+
*v |= config & (CPUCFG2_FRECIPE | CPUCFG2_DIV32 | CPUCFG2_LAM_BH);
691+
*v |= config & (CPUCFG2_LAMCAS | CPUCFG2_LLACQ_SCREL | CPUCFG2_SCQ);
687692
return 0;
688693
case LOONGARCH_CPUCFG3:
689-
*v = GENMASK(16, 0);
694+
*v = GENMASK(23, 0);
695+
696+
/* VM does not support memory order and SFB setting */
697+
config = read_cpucfg(LOONGARCH_CPUCFG3);
698+
*v &= config & ~(CPUCFG3_SFB);
699+
*v &= config & ~(CPUCFG3_ALDORDER_CAP | CPUCFG3_ASTORDER_CAP | CPUCFG3_SLDORDER_CAP);
690700
return 0;
691701
case LOONGARCH_CPUCFG4:
692702
case LOONGARCH_CPUCFG5:
@@ -717,6 +727,7 @@ static int _kvm_get_cpucfg_mask(int id, u64 *v)
717727
static int kvm_check_cpucfg(int id, u64 val)
718728
{
719729
int ret;
730+
u32 host;
720731
u64 mask = 0;
721732

722733
ret = _kvm_get_cpucfg_mask(id, &mask);
@@ -746,9 +757,16 @@ static int kvm_check_cpucfg(int id, u64 val)
746757
/* LASX architecturally implies LSX and FP but val does not satisfy that */
747758
return -EINVAL;
748759
return 0;
760+
case LOONGARCH_CPUCFG3:
761+
host = read_cpucfg(LOONGARCH_CPUCFG3);
762+
if ((val & CPUCFG3_RVAMAX) > (host & CPUCFG3_RVAMAX))
763+
return -EINVAL;
764+
if ((val & CPUCFG3_SPW_LVL) > (host & CPUCFG3_SPW_LVL))
765+
return -EINVAL;
766+
return 0;
749767
case LOONGARCH_CPUCFG6:
750768
if (val & CPUCFG6_PMP) {
751-
u32 host = read_cpucfg(LOONGARCH_CPUCFG6);
769+
host = read_cpucfg(LOONGARCH_CPUCFG6);
752770
if ((val & CPUCFG6_PMBITS) != (host & CPUCFG6_PMBITS))
753771
return -EINVAL;
754772
if ((val & CPUCFG6_PMNUM) > (host & CPUCFG6_PMNUM))

0 commit comments

Comments
 (0)