Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp631448rwl; Wed, 12 Apr 2023 01:38:44 -0700 (PDT) X-Google-Smtp-Source: AKy350aWkiqfbt1MUTOZ0326xvTiI5e9YMkYfg1SbYy9clLmiOAg18WMQ/+G04SwOLuf9SVeDmLM X-Received: by 2002:a17:902:c403:b0:1a5:2377:c7e7 with SMTP id k3-20020a170902c40300b001a52377c7e7mr7751592plk.44.1681288724012; Wed, 12 Apr 2023 01:38:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681288723; cv=none; d=google.com; s=arc-20160816; b=gxewiDdshDwyWOsVKsp1wLH6uiO4Cr3/Xx3BHooUulF+AnytedAXJLwm3P7nScpVII IPFBoAqgKvZgUYaVClC/8EM88+Y7FJXT3Po2u7cRxX61eBu07BcSOZ7HIRi+ddD85PXn nUgZjBSTUAgC7ASQayNV/GkFGbGfB0yAFLlpROrOkdSFJv/rO/xFuslc69Y4BqvaJQh9 Sfhm24eY4ZxOovIUpmENrpOX2AHmDJl1jAM6U52e9qI59AeQ7m2JJUlnxcf0m8/ie4pv Sl6gzqCROxz8qeYMazK5zXPEavlKHtHPGKTgqYdRC+YN9C6/2S5Xhy+ZRwyvjHKEjjw2 n1Jw== 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=X2dxc+KRCxZc5cAYtsXRYG+cS5kqcBLaYGUYvB/F/xg=; b=ydEcrTgPeITWFSDYcEw/ZMsqOtb3W7eS+6Tm0WwFjTiGW9PSY7s7BcIz9qM6fWkohc 2MbRn+jNhpuuAUfimR5gZTvth7R+4LYr4RmDWxSkogR3Fm9cGI3NWCeIq5WTmJ0bTITH thy4+fJsPLf0VXiIBl2MYZdxXVLJJVKLNypwZ3k2WMknoKKVCCwwV8Evkz+1hcxXbsma biYs/fvFXpf7Iidu8pG0RO5xeDFhPxchKLImPa1XlcZ6lWL7jvrj+4jEXUUOgG3VEe31 i16fWVALCn7tmKLwy4UoFfwnIM7tmywbxBeBkJK2KcZniNfTezcqJeDeneqzlw1FAfZ/ WzRw== 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 x10-20020a170902ec8a00b001a517480784si13800591plg.157.2023.04.12.01.38.32; Wed, 12 Apr 2023 01:38:43 -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 S230186AbjDLIht (ORCPT + 99 others); Wed, 12 Apr 2023 04:37:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229615AbjDLIh2 (ORCPT ); Wed, 12 Apr 2023 04:37:28 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 21CE87685; Wed, 12 Apr 2023 01:36:01 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8Dx3toqbDZk3SEbAA--.30652S3; Wed, 12 Apr 2023 16:30:34 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxC74fbDZkdKwgAA--.35751S24; Wed, 12 Apr 2023 16:30:33 +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 v6 22/30] LoongArch: KVM: Implement handle idle exception Date: Wed, 12 Apr 2023 16:30:15 +0800 Message-Id: <20230412083023.1693910-23-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230412083023.1693910-1-zhaotianrui@loongson.cn> References: <20230412083023.1693910-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8DxC74fbDZkdKwgAA--.35751S24 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvdXoW7JrW5uFykWr43XF4UXFyUAwb_yoWkXrb_ZF Z3Jas5GFWrXFs8Ka4Dtw15Ka4Ygw4kXF45ZF47ury3Gr1qyrWUC3yDWwn5ZrWDKFWUZFW3 K3ykZ3s7A34jqjkaLaAFLSUrUUUUeb8apTn2vfkv8UJUUUU8wcxFpf9Il3svdxBIdaVrn0 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 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 f151cc2dd0b9..3de08a4798fc 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -190,3 +190,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