Message ID | 20230530015223.147755-27-zhaotianrui@loongson.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1877743vqr; Mon, 29 May 2023 18:56:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ58Wcbg7vYJ0JNPOuhkLwJs9MiWUGEvgLlsuLenNDJplEG8HIXLZWD0oZz62uRQdih0TWU/ X-Received: by 2002:a17:902:ba84:b0:1ae:7631:7fa9 with SMTP id k4-20020a170902ba8400b001ae76317fa9mr839996pls.37.1685411772247; Mon, 29 May 2023 18:56:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685411772; cv=none; d=google.com; s=arc-20160816; b=EuF82AXODSSrooDf7SipQGeF4cNQp/QdOgxO1rAlMYIvesE2RotO/Jyy9aQwHkQ5Sf +OPVlgiQfpl8e2F0B8SXWv7WNHEg0qsreMgZcHFF6Ee6wkIg/Va0Sk6xXW0uDlGD+NFM ywD2o5wyHd4APkQ+8HihE3WFZwJ/iUJw8UTmo82RADGmSQFVAFwFuMw1t0GA38DeTQHl ntvU3NDnGp4bqbOJysDpG7wJ7Y6AmYTwIOjQtHEBO9iNwhABtJpYVHlJbLWpOssE9QBS iEsa5Qhq5h5Je7Opj1IuDQ7gcvHFgNF+Ibg1RbEs8+hEbIf/TFRGfbuh1uY+hX5aT5eX NH/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=/g/+piTcWpi38IKmvpjEy8BtlnBij2atbLdTADosfh4=; b=H64UGRGPcBofoRFyNf6Ud+L2KSKqeyh8H/+fKZ7IJdO2T2Fuy0Ss/NPX4DG7E2BTlE 0iDgUB1Kw4FYw3DVvWPHhTxPoCJGAAXDqouWCqhPax0bqS0Ixk0lSuUIkOAOhim2TiR+ Fjn8NCYRMtiTUmxmdBiqozX/ysQgZAi6f1vri9BZSt07LLq+GdJmhAnO1TI1PU+plOQZ ZCXfCZntF7AKcFo+J1yZkXdsdJtbW4FLRwraEUQ1XnLPCsKtvanl+mQAyyzg6XXNp5e9 Gb2wPCoHCs3Rfr+mSgkMD7xkvWavhPQ+DAM0xDK19CD+8SXco4vGOEAowlZATt8V15oL wobw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z4-20020a170902834400b001ac9ab8539csi242537pln.77.2023.05.29.18.56.00; Mon, 29 May 2023 18:56:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230158AbjE3ByE (ORCPT <rfc822;andrewvogler123@gmail.com> + 99 others); Mon, 29 May 2023 21:54:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229937AbjE3Bwz (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 29 May 2023 21:52:55 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B815113A; Mon, 29 May 2023 18:52:36 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8BxGvLiVnVk5GoCAA--.5589S3; Tue, 30 May 2023 09:52:34 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxQbTYVnVkQNZ_AA--.12077S28; Tue, 30 May 2023 09:52:33 +0800 (CST) From: Tianrui Zhao <zhaotianrui@loongson.cn> To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini <pbonzini@redhat.com>, Huacai Chen <chenhuacai@kernel.org>, WANG Xuerui <kernel@xen0n.name>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, loongarch@lists.linux.dev, Jens Axboe <axboe@kernel.dk>, Mark Brown <broonie@kernel.org>, Alex Deucher <alexander.deucher@amd.com>, Oliver Upton <oliver.upton@linux.dev>, maobibo@loongson.cn, Xi Ruoyao <xry111@xry111.site>, zhaotianrui@loongson.cn Subject: [PATCH v12 26/31] LoongArch: KVM: Implement kvm exception vector Date: Tue, 30 May 2023 09:52:18 +0800 Message-Id: <20230530015223.147755-27-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230530015223.147755-1-zhaotianrui@loongson.cn> References: <20230530015223.147755-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8AxQbTYVnVkQNZ_AA--.12077S28 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoW7Kw15tF1UurWUKF17uF4UJwb_yoW8ZFW3pF yfA34Yyr48Wa42va4akw1vgF13AayxKr17WrW7G343uw4jqryrtrWvk397JF43KryrZF1x AFZ8tr15uF4UG37anT9S1TB71UUUUjJqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU b4AFc2x0x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4 AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF 7I0E14v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVWxJr0_GcWl84ACjcxK6I8E87Iv6x kF7I0E14v26F4UJVW0owAaw2AFwI0_JF0_Jw1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAq jxCEc2xF0cIa020Ex4CE44I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E74AGY7Cv6c x26rWlOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkF7I0En4kS14v26r12 6r1DMxAIw28IcxkI7VAKI48JMxAIw28IcVCjz48v1sIEY20_WwCFx2IqxVCFs4IE7xkEbV WUJVW8JwCFI7km07C267AKxVWUAVWUtwC20s026c02F40E14v26r1j6r18MI8I3I0E7480 Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7 IYx2IY67AKxVWDJVCq3wCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAI w20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr1j6F4UJwCI42IY6I8E87Iv6x kF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7xRiTKZJUUUUU== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767282334426556845?= X-GMAIL-MSGID: =?utf-8?q?1767282334426556845?= |
Series |
Add KVM LoongArch support
|
|
Commit Message
zhaotianrui
May 30, 2023, 1:52 a.m. UTC
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@loongson.cn>
---
arch/loongarch/kvm/exit.c | 48 +++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
Comments
Reviewed-by: Bibo, Mao <maobibo@loongson.cn> 在 2023/5/30 09:52, Tianrui Zhao 写道: > 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@loongson.cn> > --- > 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, > +}; > + > +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; > +}
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@loongson.cn> > --- > 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 > + > +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; > +} >
在 2023年06月06日 15:00, Youling Tang 写道: > > > 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@loongson.cn> >> --- >> 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 Thanks, this method can simplify the code, I will fix 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; >> +} >>
> -----原始邮件----- > 发件人: "Youling Tang" <tangyouling@loongson.cn> > 发送时间:2023-06-06 15:00:11 (星期二) > 收件人: "Tianrui Zhao" <zhaotianrui@loongson.cn> > 抄送: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, "Paolo Bonzini" <pbonzini@redhat.com>, "Huacai Chen" <chenhuacai@kernel.org>, "WANG Xuerui" <kernel@xen0n.name>, "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>, loongarch@lists.linux.dev, "Jens Axboe" <axboe@kernel.dk>, "Mark Brown" <broonie@kernel.org>, "Alex Deucher" <alexander.deucher@amd.com>, "Oliver Upton" <oliver.upton@linux.dev>, maobibo@loongson.cn, "Xi Ruoyao" <xry111@xry111.site> > 主题: 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@loongson.cn> > > --- > > 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.
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, +}; + +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; +}