From patchwork Fri Sep 15 01:49:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 139975 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp744463vqi; Thu, 14 Sep 2023 18:53:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFyxhnrZbOhX5I/Wvvv2XglfphNoS7t4AW1ykvXJggTD9GzmeUYG0U2xvvFwj9abR9OtMLU X-Received: by 2002:a05:6358:895:b0:135:47e8:76e2 with SMTP id m21-20020a056358089500b0013547e876e2mr533819rwj.4.1694742837389; Thu, 14 Sep 2023 18:53:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694742837; cv=none; d=google.com; s=arc-20160816; b=xhpgJgPnGLogkGSJQh03OLDSGfL2tEh7yd9q0R+VpmTb/vtOaiesb/ZZ8ga6MO6GyI UrgvlATbLvzEwR94noGek8tLDjl1vzj8DqHPzXqcsuAsW4Y/OFN6ROq7nA1O2LhzSe5l XA7K/oUGb1R8/yz0EcmgQwOHtamGsbDRrBLIuexFwDulPCt/Ho5MYUHouFCF7mkaWDSF 61T1brl2TUmRjI7J+zlC/Pe3mBYWvPwKJZ/jO+DTcKf+2Qkrg2F2jKQxLL//qmgMYnj2 +2+kdM8jI5zG8JVl9wGnYWpsKnYSHM+YnrnN6MtyIweavANeU5xPwQ7oNO1nzDsGVFUd uGAA== 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=/e1EPCqV1viYqaDmA5e9CgST4P3AyAYMPv5w6OBtK68=; fh=ejoaVAUUbBXsA/6jM/beuI9xCYtV2osdR9SpI7hjY84=; b=sJqL4c0N9lTH261E3tVYy6cA2K1Got26fTLtjFykmO5d58SbBk26FctLWBl1v4b46x ouZMXaUD8RS050X5V6082mz9CugLiG4UAoSgDvpqr0NSUE/uOWrOoa1wYJlu/u1mAi4u utteGaK8aFJ+MRh5OpVjhQwf6BGt/tyE6kTmfYV2t4nNgv137g+pobi+Y91l3zC3r0kO iDXrhp0FQhA3HGVwaPec83L9jdHo+qUX+U/k/otdRjWsAQG0vssxxILemDCHcB6wgoNC KmIWuxWgtCV/K2KDVykjEmBG6liIZ5j3TJnNpLMCEnUxkoqA2Nz8zDg7rmwLFa2fATsk f53Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id a35-20020a631a63000000b00573e6013bc4si2315731pgm.851.2023.09.14.18.53.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 18:53:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 52A6082A2B82; Thu, 14 Sep 2023 18:52:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231888AbjIOBvK (ORCPT + 33 others); Thu, 14 Sep 2023 21:51:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231625AbjIOBuw (ORCPT ); Thu, 14 Sep 2023 21:50:52 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EB4DE3A84; Thu, 14 Sep 2023 18:50:15 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8Dxg_BMuANlfP8nAA--.12067S3; Fri, 15 Sep 2023 09:50:04 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Axndw9uANl+ioGAA--.11927S27; Fri, 15 Sep 2023 09:50: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 Subject: [PATCH v21 25/29] LoongArch: KVM: Implement kvm exception vector Date: Fri, 15 Sep 2023 09:49:45 +0800 Message-Id: <20230915014949.1222777-26-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230915014949.1222777-1-zhaotianrui@loongson.cn> References: <20230915014949.1222777-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Axndw9uANl+ioGAA--.11927S27 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== 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 (lipwig.vger.email [0.0.0.0]); Thu, 14 Sep 2023 18:52:59 -0700 (PDT) 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 lipwig.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777066665345859234 X-GMAIL-MSGID: 1777066665345859234 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 | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c index a91811918d..6ceeddf581 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -664,3 +664,48 @@ 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); + kvm_queue_exception(vcpu, EXCCODE_INE, 0); + return RESUME_GUEST; +} + +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); +}