Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2313779rdh; Tue, 26 Sep 2023 21:18:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF8uqHZIft+UiqzgjWD4Wqzp1YU112PecOtB/Xr/2ELc+oaYbu094c5QaoBfUdeXl3QbKvQ X-Received: by 2002:a17:90a:b293:b0:277:4be4:7a84 with SMTP id c19-20020a17090ab29300b002774be47a84mr7048787pjr.19.1695788327036; Tue, 26 Sep 2023 21:18:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695788327; cv=none; d=google.com; s=arc-20160816; b=aCk7Zs3H94zDWzkD7I8L83HY3KAHCp+O73wGEUzsxkLdT8ziNtpkAKrlG7hgDxFjZW cFx3x9Afr5OV1VndeSKMpLRrCytXUF4Iqi2y/BHemgDpZeWNsGybvHHJ24Gkggu9/qAb nGlbXxY9vGWNJcBcMM7Wx2wBwTjr/dLedt/AuUf5VjpgWyXxs2nOXPy2HmZFSa7eQ8sl xly4qnd8JIoh5DNeB1LVRWXrofxzaP22usR3+ZDRmJfX4GKeJsyR0klqBJCdGASPEyPZ TwIoOUjKL1FEb9Q4QqUErrJsp/n+DBPsn8U8G0Hk5Lt3JQ3QkFYvgTehG+lU/NLy0bIi RNJA== 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=BbVa8PmgwQm+xa/1knwJUsD8okVFsio4Qs72yTDucFA=; fh=DndB7O6DTG6Sgonrk2zkDJR5MPyE/Qek5uYuwsra5zw=; b=nbi2LGiLr9lvJQclsuyNTymdRVddeQGmVFTv6m5DbIq1Mt2sYc89IZNNTPfvwBeXTj OItZf9ntFYEJt0qikowZvBVbSEBU3zAPAi0EyNPlx7at1+/kgNfHo5w2yVlz4qApUKhW cIJ0lm7NJN8feA61ZIdRmi0aQUDkj9M1qtNdESKx8mOoOUPe8/YI5eEhnR/n/8jk4Ihq DZLnFgrExhI2ip0aow6ZBZ3Vqf6G0g312XmLCZJSHmVf1Vb/E9wUGRfLOLLlYygjj3gD CqmPmOZCClngJFP/SmVnB90h28uVS/EpoADPHz4X7BjaSRqOs1f8X+5UA7LzXTVGyl1m vfaA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id p5-20020a635b05000000b00584b293d17fsi3525686pgb.550.2023.09.26.21.18.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 21:18:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id BA666801B3FF; Tue, 26 Sep 2023 21:07:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229581AbjI0EGl (ORCPT + 99 others); Wed, 27 Sep 2023 00:06:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229689AbjI0EFd (ORCPT ); Wed, 27 Sep 2023 00:05:33 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3CF58CE3; Tue, 26 Sep 2023 20:10:16 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8AxlPARnRNlnBctAA--.21056S3; Wed, 27 Sep 2023 11:10:09 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxjd4InRNlhZETAA--.42466S23; Wed, 27 Sep 2023 11:10:08 +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, Huacai Chen Subject: [PATCH v22 21/25] LoongArch: KVM: Implement kvm exception vectors Date: Wed, 27 Sep 2023 11:09:55 +0800 Message-Id: <20230927030959.3629941-22-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230927030959.3629941-1-zhaotianrui@loongson.cn> References: <20230927030959.3629941-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8Cxjd4InRNlhZETAA--.42466S23 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 26 Sep 2023 21:07:11 -0700 (PDT) Implement kvm exception vectors, using kvm_fault_tables array to save the handle function pointers and it is used when vcpu handle guest exit. Reviewed-by: Bibo Mao Tested-by: Huacai Chen Signed-off-by: Tianrui Zhao --- arch/loongarch/kvm/exit.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c index e855ab9099..ce8de3fa47 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -658,3 +658,39 @@ static int kvm_handle_fpu_disabled(struct kvm_vcpu *vcpu) return RESUME_GUEST; } + +/* + * LoongArch KVM callback handling for unimplemented guest exiting + */ +static int kvm_fault_ni(struct kvm_vcpu *vcpu) +{ + unsigned int ecode, inst; + unsigned long estat, badv; + + /* Fetch the instruction */ + inst = vcpu->arch.badi; + badv = vcpu->arch.badv; + estat = vcpu->arch.host_estat; + ecode = (estat & CSR_ESTAT_EXC) >> CSR_ESTAT_EXC_SHIFT; + kvm_err("ECode: %d PC=%#lx Inst=0x%08x BadVaddr=%#lx ESTAT=%#lx\n", + ecode, vcpu->arch.pc, inst, badv, read_gcsr_estat()); + kvm_arch_vcpu_dump_regs(vcpu); + kvm_queue_exception(vcpu, EXCCODE_INE, 0); + + return RESUME_GUEST; +} + +static exit_handle_fn kvm_fault_tables[EXCCODE_INT_START] = { + [0 ... EXCCODE_INT_START - 1] = kvm_fault_ni, + [EXCCODE_TLBI] = kvm_handle_read_fault, + [EXCCODE_TLBL] = 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); +} -- 2.39.3