From patchwork Mon Apr 17 09:59:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 84136 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2012414vqo; Mon, 17 Apr 2023 03:22:42 -0700 (PDT) X-Google-Smtp-Source: AKy350bZGjG3p5niWUFk6TyDzsIo1j9vP4OzNumF3xth2ajdhfizPvcuCh/ztc6iAKwjICrtBcLj X-Received: by 2002:a05:6a21:32a8:b0:ef:ed72:779c with SMTP id yt40-20020a056a2132a800b000efed72779cmr2736494pzb.8.1681726962361; Mon, 17 Apr 2023 03:22:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681726962; cv=none; d=google.com; s=arc-20160816; b=oZub3CHkoPRIWe75MvcBGdwS2OfT4B1xKfcoP7+8JcKr4RwX3sZZA8OS9N9guiM8TK zduGuKHnRfqFIe+YTTvst/1egO5bvVHz6WFcH0HEfX/2AoyCZqMv/3bON0Gm8PBVAIDa z+pd5un3MUmstyIE8JRcp+NWIfiDMWjgGa2onYMOUTm3gPk7P2p9nkJ01UvolcIOdJXa kIoiN77j2KPawtn5Qdw2NP1pOqKaLXNCrgO7NVEHY1egyLffBywaBZWKbRUQ7teXMba6 chLSff4Cw0GnCm3S/hgxL+wf5Ht1qcytVtOwKCwraQsPkjnw+UeKt+UqRU7HVHG6ZtoF 822A== 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=FLGxpQgTyC5pUJXppObT3wa4T8403zWMExwVfABPEJ6cQdfPlbTAIU2Kr1dAg7FjAS N5m36s3CgKME/FOJ48gRn9/H7tsFYXTHSce53v+SqYNc1I41M8Gh5Yu681Prgkje3UH8 UF3d5I4N30fJtO27m78TOvniOLAN+AYbxG1EVyqxek7uLKE1c+vG5yFVNoZ+NLGJ38Eh Dd7R3nHKo7ULR0RijyMfncNtCgqCbghB+jUfBAUTutMCpPNnHdpSqUFWNv0Bn/AMt5yo woqZ28YyCjUVPHh5qzqsYcvJs4tAQRYigD6Yvl9wbeF3vi07UIJjQXjF0RKAb+QC6XNK jNtA== 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 u11-20020a6540cb000000b00503a029385asi11376255pgp.849.2023.04.17.03.22.27; Mon, 17 Apr 2023 03:22:42 -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 S230404AbjDQKCY (ORCPT + 99 others); Mon, 17 Apr 2023 06:02:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230023AbjDQKB0 (ORCPT ); Mon, 17 Apr 2023 06:01:26 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B188CE57; Mon, 17 Apr 2023 03:00:48 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8DxEzSdGD1krOYdAA--.46565S3; Mon, 17 Apr 2023 17:59:57 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Bx57yWGD1kua0qAA--.48254S24; Mon, 17 Apr 2023 17:59:56 +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:59:42 +0800 Message-Id: <20230417095950.875228-23-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230417095950.875228-1-zhaotianrui@loongson.cn> References: <20230417095950.875228-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Bx57yWGD1kua0qAA--.48254S24 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvdXoW7JrW5uFykWr43XF4UXFyUAwb_yoWkXrb_ZF Z7Jas5GrWrXF45Ka4Dt3s8Ka4Ygw4kXFWYvFW7ury3GF1qyrWUC39rWwn5ZrWkKFWUZFW5 K3ykZas7Zw12qjkaLaAFLSUrUUUUcb8apTn2vfkv8UJUUUU8wcxFpf9Il3svdxBIdaVrn0 xqx4xG64xvF2IEw4CE5I8CrVC2j2Jv73VFW2AGmfu7bjvjm3AaLaJ3UjIYCTnIWjp_UUUY O7CY07I20VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Cr1j6rxdM28EF7xvwVC2z280aVAFwI0_Cr1j6rxdM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAaw2AFwI0_GFv_Wryle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCE c2xF0cIa020Ex4CE44I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E74AGY7Cv6cx26r WlOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkF7I0En4kS14v26r4a6rW5 MxAIw28IcxkI7VAKI48JMxAIw28IcVCjz48v1sIEY20_WwCFx2IqxVCFs4IE7xkEbVWUJV W8JwCFI7km07C267AKxVW8ZVWrXwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE 14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2 IY67AKxVWDJVCq3wCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr1j6rxdMIIF0xvE42xK8VAv wI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWxJr0_GcWlIxAIcVC2z280aVCY1x0267 AKxVWxJr0_GcJvcSsGvfC2KfnxnUUI43ZEXa7IU8AcTPUUUUU== 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763418531576895340?= X-GMAIL-MSGID: =?utf-8?q?1763418531576895340?= 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; +}