Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2393992rwd; Sun, 21 May 2023 20:22:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ltAAJUzZ/45hSJZJy6f7zQKyCicGX96+jxow1Fnc0SpHvUdgWFGMKKlFV0ELfCbVvjpXB X-Received: by 2002:a17:902:ced0:b0:1af:b9ed:1677 with SMTP id d16-20020a170902ced000b001afb9ed1677mr732543plg.2.1684725730386; Sun, 21 May 2023 20:22:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684725730; cv=none; d=google.com; s=arc-20160816; b=mBWx63xa3a6yVc1vOA7TmiDqqnnKl3LF9Qft0p0NYf/bdsFpwWNZHy/JZeeeYtIQ2x SQIJqLd5EFSts2DIhamIZL0bdGk8KLfRxMogaNP/BlTNfzghyJyPsnaNBx0PygNYjPgf no11mRfh021xlFOvcpfC7hq3mwLt/M53gqAkPEgkccmkh+WZPmsgoisdXb2KgruZ9LNA 2ch8ZXseAsRX94bTNOyI6b03I93XdKDygLTi1ZgT/wHlnIAejNfaOneGG57x+2E9en73 PESCPs1RlIFJQtKCS7GxOTpiYT+wgZCFlcKhZpK1gmKt26/QH+a3QhO9vNXB680lmYa5 vYow== 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=n7fAX5A5APQuXkMG5KfDqNHa4BNHTyIEZmSFodEaAmc=; b=X6ATW6AIliDbz9Qx5lgNxU5wCspBX3LCnFaMPRPFs2voac0lHaAAtN+sH0WmvfIU52 H62k6vsNrwiksjMq/7oOB2I4TrJxmtpnv4VY1LJVl3rbCjNb19ozhnkjExvmbgCpmcJi FJtHGItXItwFUzT//zzWhJu21H91SOcQnQYd4drCEUyRZmXOgKyT5Ba9IMR29aVzwdf5 tdS1TDA80a5Lt30NHLjG8TR59JtKEUplQOfK0Dk23WIPnYgpJRqf2R5T2GwO8lCtkELp 1m/DDijOFcSC02vHbF4i2C0Qno3jnNQXNDYV1ZIJy75pqad+vkNmcMk7RJxSoboii/qt vslA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d7-20020a170902cec700b001afac49e04dsi1791799plg.642.2023.05.21.20.21.56; Sun, 21 May 2023 20:22:10 -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 S229947AbjEVDOB (ORCPT + 99 others); Sun, 21 May 2023 23:14:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231557AbjEVDM2 (ORCPT ); Sun, 21 May 2023 23:12:28 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3FC0AF1; Sun, 21 May 2023 20:12:26 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8Cx_eqZ3WpkscsKAA--.18428S3; Mon, 22 May 2023 11:12:25 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxMMiR3WpkJIFuAA--.54000S24; Mon, 22 May 2023 11:12:24 +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 v11 22/31] LoongArch: KVM: Implement handle idle exception Date: Mon, 22 May 2023 11:12:08 +0800 Message-Id: <20230522031217.956464-23-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230522031217.956464-1-zhaotianrui@loongson.cn> References: <20230522031217.956464-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8DxMMiR3WpkJIFuAA--.54000S24 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvdXoW7JrW5uFykWr43XF4UXFyUAwb_yoWkXrb_ZF Z7Jas5GFWrXFs8Ka4Dt345Ka4Ygw4kXFWY9FW7ury3GF1qyrWUC39rWw1DZrWkKFWUZFW5 K3yDZas7Z342qjkaLaAFLSUrUUUUeb8apTn2vfkv8UJUUUU8wcxFpf9Il3svdxBIdaVrn0 xqx4xG64xvF2IEw4CE5I8CrVC2j2Jv73VFW2AGmfu7bjvjm3AaLaJ3UjIYCTnIWjp_UUUY 27CY07I20VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6x kF7I0E14v26r4UJVWxJr1ln4kS14v26r126r1DM2AIxVAIcxkEcVAq07x20xvEncxIr21l 57IF6xkI12xvs2x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6x8ErcxFaV Av8VWrMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCY1x0262kKe7AKxVWU AVWUtwCF04k20xvY0x0EwIxGrwCF04k20xvE74AGY7Cv6cx26rWl4I8I3I0E4IkC6x0Yz7 v_Jr0_Gr1l4IxYO2xFxVAFwI0_JF0_Jw1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_tr0E3s1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4UJVWxJr1lIxAIcVC2z280aV CY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0zR9iSdUUUUU= 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 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; +} -- 2.39.1