From patchwork Wed Sep 27 03:09:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 145136 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2372832vqu; Tue, 26 Sep 2023 21:18:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHnQhSQ2xS1B3x1x0gb7WE2viXz4T4EbiTc3cD/Y6BQOVSflQII0dZD6nqb8qe1esoYN7Kf X-Received: by 2002:a17:90a:e612:b0:26b:36a4:feeb with SMTP id j18-20020a17090ae61200b0026b36a4feebmr6925015pjy.8.1695788302393; Tue, 26 Sep 2023 21:18:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695788302; cv=none; d=google.com; s=arc-20160816; b=Zvsu+J7s+KeGpeBMf3Z8DgfcgGnjt11wfdfMr4MGZRL93oO0ZkKigWtWM09lKWRAN8 T9x/EXuWs/nAumwXabuOJGUUxrmu40/zwe0OeNjgJP/fXUgaeozt9n/6WGQ/V9NEJxnm 2F/X1m5y/HrrLLo1fvd0rZyuu/JJ0+9Na2o46jZqie5L9bX18AjBhlO86096q0mpUyLy Lg9+4IORQ8n1rBQEUo2E8T6NKKajLrJ7VUuSYzy3HUFtlC1Mc76ihi1JJJZOkKE3z9Er sia7gaPwftcrSWRG49WFOo7MWKP/o366G8plAdMsS6c9fQcJRga7MtLTJy3Kkp+hjg21 kWdA== 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.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id q25-20020a656859000000b00578ac88e239si14736386pgt.595.2023.09.26.21.18.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 21:18:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 478C4807E416; Tue, 26 Sep 2023 21:07:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229601AbjI0EGm (ORCPT + 26 others); Wed, 27 Sep 2023 00:06:42 -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 X-CM-TRANSID: AQAAf8Cxjd4InRNlhZETAA--.42466S23 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email 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 (morse.vger.email [0.0.0.0]); Tue, 26 Sep 2023 21:07:13 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778162915283677230 X-GMAIL-MSGID: 1778162915283677230 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); +}