Re: Re: [PATCH v12 26/31] LoongArch: KVM: Implement kvm exception vector

From: 赵天瑞
Date: Thu Jun 08 2023 - 07:45:55 EST





> -----原始邮件-----
> 发件人: "Youling Tang" <tangyouling@xxxxxxxxxxx>
> 发送时间:2023-06-06 15:00:11 (星期二)
> 收件人: "Tianrui Zhao" <zhaotianrui@xxxxxxxxxxx>
> 抄送: linux-kernel@xxxxxxxxxxxxxxx, kvm@xxxxxxxxxxxxxxx, "Paolo Bonzini" <pbonzini@xxxxxxxxxx>, "Huacai Chen" <chenhuacai@xxxxxxxxxx>, "WANG Xuerui" <kernel@xxxxxxxxxx>, "Greg Kroah-Hartman" <gregkh@xxxxxxxxxxxxxxxxxxx>, loongarch@xxxxxxxxxxxxxxx, "Jens Axboe" <axboe@xxxxxxxxx>, "Mark Brown" <broonie@xxxxxxxxxx>, "Alex Deucher" <alexander.deucher@xxxxxxx>, "Oliver Upton" <oliver.upton@xxxxxxxxx>, maobibo@xxxxxxxxxxx, "Xi Ruoyao" <xry111@xxxxxxxxxxx>
> 主题: Re: [PATCH v12 26/31] LoongArch: KVM: Implement kvm exception vector
>
>
>
> On 05/30/2023 09:52 AM, Tianrui Zhao wrote:
> > Implement kvm exception vector, using _kvm_fault_tables array to save
> > the handle function pointer and it is used when vcpu handle exit.
> >
> > Signed-off-by: Tianrui Zhao <zhaotianrui@xxxxxxxxxxx>
> > ---
> > arch/loongarch/kvm/exit.c | 48 +++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 48 insertions(+)
> >
> > diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c
> > index 10f9922a7e76..625045fc95c8 100644
> > --- a/arch/loongarch/kvm/exit.c
> > +++ b/arch/loongarch/kvm/exit.c
> > @@ -657,3 +657,51 @@ static int _kvm_handle_fpu_disabled(struct kvm_vcpu *vcpu)
> > kvm_own_fpu(vcpu);
> > return RESUME_GUEST;
> > }
> > +
> > +/*
> > + * Loongarch KVM callback handling for not implemented guest exiting
> > + */
> > +static int _kvm_fault_ni(struct kvm_vcpu *vcpu)
> > +{
> > + unsigned long estat, badv;
> > + unsigned int exccode, inst;
> > +
> > + /*
> > + * Fetch the instruction.
> > + */
> > + badv = vcpu->arch.badv;
> > + estat = vcpu->arch.host_estat;
> > + exccode = (estat & CSR_ESTAT_EXC) >> CSR_ESTAT_EXC_SHIFT;
> > + inst = vcpu->arch.badi;
> > + kvm_err("Exccode: %d PC=%#lx inst=0x%08x BadVaddr=%#lx estat=%#lx\n",
> > + exccode, vcpu->arch.pc, inst, badv, read_gcsr_estat());
> > + kvm_arch_vcpu_dump_regs(vcpu);
> > + vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
> > +
> > + return RESUME_HOST;
> > +}
> > +
> > +static exit_handle_fn _kvm_fault_tables[EXCCODE_INT_START] = {
> > + [EXCCODE_TLBL] = _kvm_handle_read_fault,
> > + [EXCCODE_TLBI] = _kvm_handle_read_fault,
> > + [EXCCODE_TLBNR] = _kvm_handle_read_fault,
> > + [EXCCODE_TLBNX] = _kvm_handle_read_fault,
> > + [EXCCODE_TLBS] = _kvm_handle_write_fault,
> > + [EXCCODE_TLBM] = _kvm_handle_write_fault,
> > + [EXCCODE_FPDIS] = _kvm_handle_fpu_disabled,
> > + [EXCCODE_GSPR] = _kvm_handle_gspr,
> > +};
> It can be modified as follows and remove _kvm_init_fault().
>
> static exit_handle_fn _kvm_fault_tables[EXCCODE_INT_START] = {
> [0 ... EXCCODE_INT_START - 1] = _kvm_fault_ni,
>
> [EXCCODE_TLBL] = _kvm_handle_read_fault,
> [EXCCODE_TLBI] = _kvm_handle_read_fault,
> [EXCCODE_TLBNR] = _kvm_handle_read_fault,
> [EXCCODE_TLBNX] = _kvm_handle_read_fault,
> [EXCCODE_TLBS] = _kvm_handle_write_fault,
> [EXCCODE_TLBM] = _kvm_handle_write_fault,
> [EXCCODE_FPDIS] = _kvm_handle_fpu_disabled,
> [EXCCODE_GSPR] = _kvm_handle_gspr,
> };
>
> Thanks,
> Youling
Hi Youling,
When I compile this code with W=1, there is a warning: initialized field overwritten [-Woverride-init], so considering this problem I think we have to keep the previous _kvm_init_fault, what do you think of it?

Thanks
Tianrui Zhao
>
> > +
> > +int _kvm_handle_fault(struct kvm_vcpu *vcpu, int fault)
> > +{
> > + return _kvm_fault_tables[fault](vcpu);
> > +}
> > +
> > +void _kvm_init_fault(void)
> > +{
> > + int i;
> > +
> > + for (i = 0; i < EXCCODE_INT_START; i++)
> > + if (!_kvm_fault_tables[i])
> > + _kvm_fault_tables[i] = _kvm_fault_ni;
> > +}
> >


本邮件及其附件含有龙芯中科的商业秘密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制或散发)本邮件及其附件中的信息。如果您错收本邮件,请您立即电话或邮件通知发件人并删除本邮件。
This email and its attachments contain confidential information from Loongson Technology , which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this email in error, please notify the sender by phone or email immediately and delete it.