Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1676528rwo; Wed, 2 Aug 2023 19:38:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlFA0dClGsnq/ldOPa0usEWO58sMroiZcixgJBUoeDHuqEMwqcXoiCWXc7Ovc93CNPTyuc6X X-Received: by 2002:a17:902:8216:b0:1b8:c6:ec8f with SMTP id x22-20020a170902821600b001b800c6ec8fmr13839716pln.46.1691030310297; Wed, 02 Aug 2023 19:38:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691030310; cv=none; d=google.com; s=arc-20160816; b=vziCQVbir5+QF1iquqqAOn3s+TwqHX2tfp9IaB5WRfnUKDGwr/2c8E2frHPtgRSauG 2a5bKh+EbKBFqwy1x2BKGMq0jZbGCjqQ9sR4ScR/MRebx7rbe7SIz2c+jDMga/IO8vhm KOY9GAEmlHvvEje3mwWHBtl8TJd7IPJKTtygbyOaPUSEx47oPcKxXuSjC6sVm2bpL5Xt mhCjF9q95RkOnFMGZGLGGZwgJjfbl3oSLawRnaNXHbrubLUDzTUjXRqJ/sZLqKwOkbCI 46kdilTaCTGdOpBioBLx+srQcNKkI7KtSV7ezMvzHVzGd1mUvxvSmNNvuVUB8MDh7rTf hcJQ== 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=/wtMvZ8G0eZwxXVQyWy5RDNXqdEXyt/m5RxMiKCAZQI=; fh=vBXozhnPXwSB3DJhjnKWz3f6luaN/KxHDpM6/QeZg4o=; b=GLSsukz64QWtIR1HbifNi1QZESz3WwIKkE0PWRm7kgbnEJkcoYGaCQPz+VuMYufqrN qfy+oPCNke0aV/IdEQOLFd2E5eB5HpTwUnoH63TuMilUL+fq8FNEE88VUbnnBk7aNCQu 5PcwlvFPDT0MTPruyiTssZ4LlDPW13/xwgNuAxLWng2JzQXgoWKShwxrVAkoEmrnl6Tp aWT8ra+59ydsoV+Hs8/ePZBU5EWkzfaydO+dez5FRtACzOqVPE6yqdmgoq1EqHhaAp+o UXCcLmEcBfuaXcijtI5cHc78zWQvqeohoDfDJfu4QC5pBnluNJXkc1vmrUOuYS7dQ6yg rgrw== 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 kb14-20020a170903338e00b001bb792749a2si11397197plb.146.2023.08.02.19.38.18; Wed, 02 Aug 2023 19:38:30 -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 S232707AbjHCC0K (ORCPT + 99 others); Wed, 2 Aug 2023 22:26:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230393AbjHCCZX (ORCPT ); Wed, 2 Aug 2023 22:25:23 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F335B4685; Wed, 2 Aug 2023 19:22:49 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8CxNvFcD8tk7WkPAA--.36016S3; Thu, 03 Aug 2023 10:22:20 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cx_c4yD8tk8oNGAA--.51268S28; Thu, 03 Aug 2023 10:22:16 +0800 (CST) From: Tianrui Zhao To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Huacai Chen , WANG Xuerui , Greg Kroah-Hartman , loongarch@lists.linux.dev, Jens Axboe , Mark Brown , Alex Deucher , Oliver Upton , maobibo@loongson.cn, Xi Ruoyao , zhaotianrui@loongson.cn Subject: [PATCH v18 26/30] LoongArch: KVM: Implement kvm exception vector Date: Thu, 3 Aug 2023 10:21:34 +0800 Message-Id: <20230803022138.2736430-27-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230803022138.2736430-1-zhaotianrui@loongson.cn> References: <20230803022138.2736430-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8Cx_c4yD8tk8oNGAA--.51268S28 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== 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: 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. Reviewed-by: Bibo Mao Signed-off-by: Tianrui Zhao --- arch/loongarch/kvm/exit.c | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c index 17e94ecec140..b49b99888424 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -657,3 +657,49 @@ 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_TLBS] = _kvm_handle_write_fault, + [EXCCODE_TLBM] = _kvm_handle_write_fault, + [EXCCODE_FPDIS] = _kvm_handle_fpu_disabled, + [EXCCODE_GSPR] = _kvm_handle_gspr, +}; + +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; +} + +int _kvm_handle_fault(struct kvm_vcpu *vcpu, int fault) +{ + return _kvm_fault_tables[fault](vcpu); +} -- 2.39.1