From patchwork Tue May 9 07:53:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 91441 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2703272vqo; Tue, 9 May 2023 01:08:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Wz28sftV4zvz7a/JsvNAsWS0bO0BIuaxw7dQ6tmjLtexcHDhYfkNZ8g6Bkh13jibybfpx X-Received: by 2002:a05:6a00:2345:b0:63d:3981:313d with SMTP id j5-20020a056a00234500b0063d3981313dmr18263022pfj.10.1683619704429; Tue, 09 May 2023 01:08:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683619704; cv=none; d=google.com; s=arc-20160816; b=WJ2TaW2D/27xdrLaMv68chZqXihGsQyAS3rhwkAhdszRo+xDEHCw00uP2ydS8msNAf PcHqkfe2Y//3tSRowjVHMOtStLZpn/VtZAG+XocTuwni7N0f0z+/4mSxY+pNfajDzAuO AvMITi3oINj/E+oTmu95hME9gHBQTDJ/uW/QqaXByYr98mDU5Mg1UBFEqbjO5RyKrWuT YQErBDUoCuzg0RDuQTxo2flKlTCHlSKsgWE5kaQPd5Qr8YrvKcSkmsE41Ayf4hunWi9i PqxGfwQ3IVhl1kk6E3YvNkmclNWaHpWjkUCcY2WhVQX0lBgF8/yMNUriQzMyQ8G2UrBO TpYg== 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=5odh1/qZOMz9aD5tPSyMKibGTxA4hG6rFGH+H/sq3r8=; b=Krx4namg6J+p2CUh0xygPM88vP25xFAYhvsPnzahg4tAnTfIQ8fuD9MS3E1T+JsmAm 7gfxaJWtINsOhychX9UkXaChm1KSz12pXin/lkRxc81Fr4PRDbWTShlAnLRYfWdWXiWq X1U6sTjE8Wwv29zphkywT+C/4mHLgfSMST8rKlAc3egzoy0nfVafjYjLNszaCksmFXyY 1KHZhIXqvKma5SbkTAn4VCqVU1Ah5hGteCpDYb8M+zl5zwn9zvvl1iJU2yAHA5X+1bmH bDJndAB4S2c9XJ1x2RWjRaH1p/DXbmEU6KP7DZ0TVHu5C2MZAmemrHCFoSF1rqbOThf6 wTvA== 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 j63-20020a638042000000b005287c9c425csi953034pgd.407.2023.05.09.01.08.09; Tue, 09 May 2023 01:08:24 -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 S235365AbjEIHzO (ORCPT + 99 others); Tue, 9 May 2023 03:55:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234658AbjEIHyD (ORCPT ); Tue, 9 May 2023 03:54:03 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8FA6E8698; Tue, 9 May 2023 00:54:00 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8AxHusW_Flkg+MGAA--.11503S3; Tue, 09 May 2023 15:53:58 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxFLUK_FlkIEhSAA--.16908S24; Tue, 09 May 2023 15:53:57 +0800 (CST) From: Tianrui Zhao To: Paolo Bonzini , Huacai Chen , WANG Xuerui Cc: Greg Kroah-Hartman , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Jens Axboe , Mark Brown , Alex Deucher , Oliver Upton , maobibo@loongson.cn, Xi Ruoyao , zhaotianrui@loongson.cn Subject: [PATCH v9 22/30] LoongArch: KVM: Implement handle idle exception Date: Tue, 9 May 2023 15:53:38 +0800 Message-Id: <20230509075346.1023386-23-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230509075346.1023386-1-zhaotianrui@loongson.cn> References: <20230509075346.1023386-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8BxFLUK_FlkIEhSAA--.16908S24 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvdXoW7JrW5uFykWr43XF4UXFyUAwb_yoWkXrb_ZF Z7Jas5GFWrXF45Ka4Dt345Ka4Ygw4kXFWY9FW7ury3GF1qyrWUC39rWw1DZrWkKFWUZFW5 K3ykZas7Zw12qjkaLaAFLSUrUUUUeb8apTn2vfkv8UJUUUU8wcxFpf9Il3svdxBIdaVrn0 xqx4xG64xvF2IEw4CE5I8CrVC2j2Jv73VFW2AGmfu7bjvjm3AaLaJ3UjIYCTnIWjp_UUUY z7CY07I20VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26F4UJVW0owA2z4x0Y4vEx4A2jsIEc7 CjxVAFwI0_Cr1j6rxdM2kKe7AKxVWUAVWUtwAS0I0E0xvYzxvE52x082IY62kv0487Mc80 4VCY07AIYIkI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VCjz48v1sIEY2 0_WwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_JF0_ Jw1l42xK82IYc2Ij64vIr41l42xK82IY6x8ErcxFaVAv8VWrMxC20s026xCaFVCjc4AY6r 1j6r4UMxCIbckI1I0E14v26r126r1DMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xv wVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjx v20xvE14v26w1j6s0DMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UMIIF0xvE42xK 8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8Jr0_Cr1UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvj4RKpBTUUUUU X-Spam-Status: No, score=1.4 required=5.0 tests=BAYES_00,RCVD_IN_SBL_CSS, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765403215197273100?= X-GMAIL-MSGID: =?utf-8?q?1765403215197273100?= Implement kvm handle LoongArch vcpu idle exception, using kvm_vcpu_block to emulate it. Signed-off-by: Tianrui Zhao --- arch/loongarch/kvm/exit.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c index bd33fe0c6424..3fdb42939a05 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -188,3 +188,23 @@ int _kvm_complete_iocsr_read(struct kvm_vcpu *vcpu, struct kvm_run *run) return er; } + +int _kvm_emu_idle(struct kvm_vcpu *vcpu) +{ + ++vcpu->stat.idle_exits; + trace_kvm_exit_idle(vcpu, KVM_TRACE_EXIT_IDLE); + + if (!kvm_arch_vcpu_runnable(vcpu)) { + /* + * Switch to the software timer before halt-polling/blocking as + * the guest's timer may be a break event for the vCPU, and the + * hypervisor timer runs only when the CPU is in guest mode. + * Switch before halt-polling so that KVM recognizes an expired + * timer before blocking. + */ + kvm_save_timer(vcpu); + kvm_vcpu_block(vcpu); + } + + return EMULATE_DONE; +}