Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp3845419rwe; Mon, 17 Apr 2023 04:34:24 -0700 (PDT) X-Google-Smtp-Source: AKy350bL8wQkBuPfGrT3qIgQZcfejU5EOicWiz6CVy9CmEfkCaZJS9hSi2LK5qY5uD3Xzs7LReEJ X-Received: by 2002:a17:90a:5d11:b0:233:e1e6:33d4 with SMTP id s17-20020a17090a5d1100b00233e1e633d4mr14581251pji.47.1681731264599; Mon, 17 Apr 2023 04:34:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681731264; cv=none; d=google.com; s=arc-20160816; b=YwIIwoD7wP+2ojnm5595EnVNyBEQR+Yw8SL8WgAosp6P711Y6MswWxUbkF/N8C7QvP sYbKOCyB+Ju/hySV6K45TbOc/JPitjn2fDp9qv7APChj6jSyQlFSAxJQzDAAlZPRt1Li ElKuh6MfXlZITmmWcUyRSbdNsLY7Lps4ChZGzeD2RES+6STffjlupe+GE2Qe5ZdH61aw U8sKi3D/Z3XV9SsQIN8yFaTmAo1D0OddEGzpdo2j3QgYDC/vMM0qEJPZPbHHilF2kPTv V+KcbzsXs80qR7mDAMxPxbq4KYF9VRiQ+6jqVKmp0SUv+W1N2QvcL61YwT9o6wIyjv2k 0eQw== 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=n4voFILVXURsZBwxuIq+6pDYlUb3TLswi0g/jArNMbE=; b=Ij3wJlPF5VQW8WvteeES4CZ860hGh+BkeyWgorHi4XOZ7Wxf/P/YiwKiLl3kyaSPcE uO3GfALt+88RbP0EYNcj7W18M+fv8C8TK4AjqUjn1ITZ/wVhvJdSJ3LzrXM3IelLL4ww 9WYMjdosxUUDYsCQfvcGXWMA1gboLjgdtpA3PYk+szFsNp8lu0x+yzh6dKigUMpKH+lI J4IYenR07iRq6bhVHJKD9Zh7N8VLwWpVeQrhtFutSjEamsDJX+F89oCOJRCkaboNw4Bg UbXYmCHGWxdI0hyyfJHiGnmzo9srOYHqs4U8ekZzoomWMtMP3lxptdJ/QIwiVw+a42ci j1yA== 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 a21-20020a63e855000000b00502d75b6681si12087292pgk.228.2023.04.17.04.34.10; Mon, 17 Apr 2023 04:34: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 S230513AbjDQL0H (ORCPT + 99 others); Mon, 17 Apr 2023 07:26:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbjDQL0F (ORCPT ); Mon, 17 Apr 2023 07:26:05 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4CABB6198; Mon, 17 Apr 2023 04:25:06 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8CxQMySFT1kzuMdAA--.46461S3; Mon, 17 Apr 2023 17:46:58 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxtryKFT1kyagqAA--.47974S24; Mon, 17 Apr 2023 17:46:58 +0800 (CST) From: Tianrui Zhao To: Paolo Bonzini Cc: Huacai Chen , WANG Xuerui , 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 v7 22/30] LoongArch: KVM: Implement handle idle exception Date: Mon, 17 Apr 2023 17:46:41 +0800 Message-Id: <20230417094649.874671-23-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230417094649.874671-1-zhaotianrui@loongson.cn> References: <20230417094649.874671-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8CxtryKFT1kyagqAA--.47974S24 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvdXoW7JrW5uFykWr43XF4UXFyUAwb_yoWkXrb_ZF Z7Jas5GrWrXF45Ka4Dt3s8Ka4Ygw4kXFWYvFW7ury3GF1qyrWUC39rWwn5ZrWkKFWUZFW5 K3ykZas7Zw12qjkaLaAFLSUrUUUUnb8apTn2vfkv8UJUUUU8wcxFpf9Il3svdxBIdaVrn0 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.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 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.31.1