Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp626889rwl; Wed, 12 Apr 2023 01:33:36 -0700 (PDT) X-Google-Smtp-Source: AKy350ZJce2ldbjiEa/eRrrufwbi9JGX8hQaQz4yjRNQk99xQFs6Pt7/jY+cJq2S+SM6hxp8k1DB X-Received: by 2002:a17:906:148f:b0:94a:9ae2:1642 with SMTP id x15-20020a170906148f00b0094a9ae21642mr5057399ejc.46.1681288416402; Wed, 12 Apr 2023 01:33:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681288416; cv=none; d=google.com; s=arc-20160816; b=RlExU+TqkgBBQxPVDB86WXi6/5uFuU4z1t1pRLU9o0T1gdRVc4hb71aMGy0aGVueCh AS7QPn0wWd3lVY+fbTzc2hQyJLK3518LuylzWwAs/R0HiKs1gIgC+DDvs0gNQ3IiU25a 774Qv4xnDto7brPfCG1LfydE+8/T0Z14pHki/2hxX2VdS3x8jhAM+tuuCuJVIZV4Qi1W olV5jxbEQwO5FXV7jOnOqYTnsuQOUyIk0ktuQsMo/hw0gCAyF+FTMqJ+GLsGskhq5ViW gbspJTNEyk+VEA4IXSEjIL+ZC1AByVrAz4ckyzewng6w/KgC0i5oQ7t1I05t0k0kj7OU kSdg== 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=9zMzKQz+dpCfDtjJ5YL73c6BuYbaRMBin8HWfmnRIqk=; b=RUKowlVbIRwuXTtBqgDkZ/lou/2aLEgnmaHxXYW2MeIhU1vX+4KqQeU0Z2mSMFS8cM YiJ68qewnq0CMdw+Mnpqp01kqSr4CVLSZBJ86gTe/oTNWRNo3CuORMxKlqFTVutm+JIO LGZo4nS+D70cNq8VEKpjJMF1FsX3w5ybum0Uko79MNUaH/RUxkqIvIaTKQcl66fDLgZ0 Bmi5bz/TPVGSyri3uFz9CDYF002Y0Ycc3ks+ss/qQApdi2Ki2ZRnLxZ5JKvuwjiwPBiC +uai+0nRiizMdz4CGMds55JVSfBCvPsTCMY7pIENNK3vCM6TZhdWnWJ87dFsCd2yXSoy RsmQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id go8-20020a1709070d8800b00947de40ef34si9443758ejc.440.2023.04.12.01.33.11; Wed, 12 Apr 2023 01:33:36 -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 S230362AbjDLIcG (ORCPT + 99 others); Wed, 12 Apr 2023 04:32:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230128AbjDLIb3 (ORCPT ); Wed, 12 Apr 2023 04:31:29 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8C26A72BD; Wed, 12 Apr 2023 01:30:41 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8Dxj80vbDZkFSIbAA--.42022S3; Wed, 12 Apr 2023 16:30:39 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxC74fbDZkdKwgAA--.35751S28; Wed, 12 Apr 2023 16:30:38 +0800 (CST) From: Tianrui Zhao To: Paolo Bonzini Cc: Huacai Chen , WANG Xuerui , Greg Kroah-Hartman , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Jens Axboe , Mark Brown , Alex Deucher , Oliver Upton , maobibo@loongson.cn, Xi Ruoyao , zhaotianrui@loongson.cn Subject: [PATCH v6 26/30] LoongArch: KVM: Implement kvm exception vector Date: Wed, 12 Apr 2023 16:30:19 +0800 Message-Id: <20230412083023.1693910-27-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230412083023.1693910-1-zhaotianrui@loongson.cn> References: <20230412083023.1693910-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8DxC74fbDZkdKwgAA--.35751S28 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoW7Kw15tF1UurWUKF17uF4UJwb_yoW8ZFWfpF yfA34YyrW8Ww12va4akw4vgF13AayxKr17WrW7G345uw4jqryrtrWkK393JF43KryrZF1x JFZ8Jr15uF4UG37anT9S1TB71UUUUjJqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj 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_PASS, SPF_PASS 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 e218e7a43447..1a4be2af3926 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -659,3 +659,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=%#llx\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; +} -- 2.31.1