Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp15854038rwd; Mon, 26 Jun 2023 02:10:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7DIHNb0G6uz8JqFj034WrtozWf8gXfS0Priyh00VuomrUsOCG/gIL43f/l470mfQ+d4N9s X-Received: by 2002:a17:907:7ba5:b0:982:9b01:a57c with SMTP id ne37-20020a1709077ba500b009829b01a57cmr26812779ejc.12.1687770621254; Mon, 26 Jun 2023 02:10:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687770621; cv=none; d=google.com; s=arc-20160816; b=n2tfjqdZDGSfGeRD4EGfFifXf7Jvg7w9tCUPepU8ue9o59E3gvAFlq1fZGTZ1/iowo bdIdSDXHEgndHLakcmCkGSZbfwjmUPzAlXP9FKEVBVM1CIkf2XiYENJr6z4Lre2SxQow 6wjGmbo/YkPzC7Y1fXtYJvvBon5wil5cp0jv4j2Ky7v1IL/BfLU9CektUyVU0xx9DYwo GjgCrRTbgbkFYewuLwMfNpJ24VzmWk7gBO7jVfC3f67KB9xjl9fqf1WwpFLXOaPmZpQK 2fotqBrcAl6Xd/DILH5gK4GsSyCLcMA0h4P3XUuqwVONCXH9o2YGTd1n5ioNgL57jK/D u9rg== 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=RnTBNVKugXch15CiD4hgCcdJhLphgIKe2mr0juFqTe0=; fh=FJJE1KfQOXNgUCxk/Gxke8tBG9gBLo3aFI+sNzAMBeU=; b=M+ec8BEgPvmasQeOMp/UtFzsDBMd3AdL7Az7h228b+uV/WehnAr5a524pH3UOtNxZi t+ndXHAE9p00YDdwrrOsLjn1Yzvrm0QU3MPFtp3cStKFpEOw58Q+fssgG7Y5Q5nKvINP f2LWNrB+VGYQN0n6Qepsi5PZLhH+offXvgrq+OONDMBP2MkN5/AG4UAg0tSxWOzHclTT utpChkwDOwkC3iTv9xbC3CLJpkFolhbqP0W441faohlDFxSL9rUG/AnV1xzJCH2NGgcg NCsRRI3xDsEDzSpVJ+n1ZwEUtLo1Bm/x6F0ePcmvDpw9VuoYc41RXr0CuV31mwipidtH 40mw== 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 h15-20020a170906590f00b00988a4e660f9si2729882ejq.491.2023.06.26.02.09.56; Mon, 26 Jun 2023 02:10:21 -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 S230053AbjFZIu0 (ORCPT + 99 others); Mon, 26 Jun 2023 04:50:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230322AbjFZItf (ORCPT ); Mon, 26 Jun 2023 04:49:35 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0BE0D1FF0; Mon, 26 Jun 2023 01:48:15 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8Axz8fFUJlkPzUCAA--.3226S3; Mon, 26 Jun 2023 16:48:05 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Bxxsy5UJlk4hQJAA--.19269S28; Mon, 26 Jun 2023 16:48:04 +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, tangyouling@loongson.cn Subject: [PATCH v15 26/30] LoongArch: KVM: Implement kvm exception vector Date: Mon, 26 Jun 2023 16:47:48 +0800 Message-Id: <20230626084752.1138621-27-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230626084752.1138621-1-zhaotianrui@loongson.cn> References: <20230626084752.1138621-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8Bxxsy5UJlk4hQJAA--.19269S28 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 | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c index 17e94ecec140..4332dc9ce2d6 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, +}; + +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