From patchwork Thu Aug 31 08:30:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 137350 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c792:0:b0:3f2:4152:657d with SMTP id b18csp507005vqu; Thu, 31 Aug 2023 14:27:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExdrtwkWmhVZk5piwuKM0OXm27ijkBoYgayNz5SOVgB4b4mPymc+UKvAYe0sOcKIiI+ccn X-Received: by 2002:a17:906:1d:b0:9a2:28dc:4166 with SMTP id 29-20020a170906001d00b009a228dc4166mr414269eja.75.1693517268246; Thu, 31 Aug 2023 14:27:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693517268; cv=none; d=google.com; s=arc-20160816; b=puRim2zTkFGHRvqXFZQ0MU/cL7CyRjbfa9Yu3Vw1ZvfjO3DDEMDbgQC1EuwaKvZ7o6 cDdVW2j8udegw9iFy3P4QZiWb2zVL/qT1TI9iNOHSWGlP5DWmvCRxElCrF/abtLE2L/G ul032wEH780JOdc061t8R9AQ3oot1S1EgBPazW0v286RqinybP855yce2IeLfo3JnWz/ xrBn5P055k2R1D3AOkHIWLUwnaMDEw5mGA/pBqyB6E+veBwzhn1ZV45bWM5T/dV8mLzr dpSaAuu0+18cyS/rrVcl4Nkl9iSoTcOI8KXgHy+5bYJwe+lNN+1pGL3UK+plthhdoYeb mhYQ== 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=DT8opXme4ZB6R4g1Kx0rs/+Mh4v3H9yA5C/5+3WTn8c=; fh=ejoaVAUUbBXsA/6jM/beuI9xCYtV2osdR9SpI7hjY84=; b=LR+w74OwQySPrtLz/efQs6vvwJzAPbAAGugI9NpTpdsijQRlREoDxasHnGyxwD8F1c Q0KvpRQUIqdXif3OTI2FHgMDsT+ERA3T3zEMmGwC5rX0zkSCmJ1tMEYkeNgV++q6PtYD nQZ9jlEwLbymR/Dhr64XSBP3HKO0VtK9lHoiJhH3MLE7q/j6W6ef9wkkYUwf3Z7T5OPI xtqBCXxNB5uDyYmHdh4vI1NGjCwjscd6ebQUSFwctr9/BHIz4kFqJqwENhpDb0uqBEBT 6VgRONFMXSgFMjHIh34mjbtnQdhrM96U5Rfy8CzAleRVPrk7/kfG2iOuEPvDZiimQ9YT c6bg== 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 rh28-20020a17090720fc00b0099307a6635esi1539290ejb.701.2023.08.31.14.27.21; Thu, 31 Aug 2023 14:27:48 -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 S231237AbjHaIcO (ORCPT + 99 others); Thu, 31 Aug 2023 04:32:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236261AbjHaIb3 (ORCPT ); Thu, 31 Aug 2023 04:31:29 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E31B210E3; Thu, 31 Aug 2023 01:30:45 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8AxEvCuT_Bk3V4dAA--.59308S3; Thu, 31 Aug 2023 16:30:38 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Ax3c6gT_BkOPVnAA--.55892S28; Thu, 31 Aug 2023 16:30:38 +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 v20 26/30] LoongArch: KVM: Implement kvm exception vector Date: Thu, 31 Aug 2023 16:30:16 +0800 Message-Id: <20230831083020.2187109-27-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230831083020.2187109-1-zhaotianrui@loongson.cn> References: <20230831083020.2187109-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Ax3c6gT_BkOPVnAA--.55892S28 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, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1775781563169528449 X-GMAIL-MSGID: 1775781563169528449 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 f9c7951261..a6df2b56ed 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -654,3 +654,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); +}