From patchwork Mon May 15 02:15:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 93797 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp6614897vqo; Sun, 14 May 2023 19:29:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Bs5bFX+vunYbil5Bem7ez5eGC3aO12ghVPHlumlE2enqeRKmyjYF3WYtN/N/B60K5eWbH X-Received: by 2002:a17:903:230e:b0:1ab:19f6:ef0f with SMTP id d14-20020a170903230e00b001ab19f6ef0fmr44457298plh.33.1684117745361; Sun, 14 May 2023 19:29:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684117745; cv=none; d=google.com; s=arc-20160816; b=vXg5LqrPPB+wFZcIfI10umpxHmr78whFEqUzXcSO+qwl42ukuAsG0Wx+M+dTXIoSMK bUuuZ01ELK+BCrJN3+XBvTul3VQuOjbHDKkpj3sjGSx0WYMnWOi4frJcKW3eGsKefXzL FHJ3iwe+MfYCjf6LrfVMekkCYnSllRqh4zudVYi+XXJ5IHPpT/KEOxp5eTeCZ+/LlUZO kI8Nl1dTJgpnxNuYmkv1Nn22PbDGU1HUf5Bp/iA6J3OQnar5oBsQl0fG/nAt3zwK9F9J 4KGFQ8phjFEkOHUg0h13wxBAtb5ZNSQ94wvGCNyGXlKLyiDWmAoFJmtGak4tH0YXVGFG q1rg== 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=MQVzGboW5Zz0L89NLNpqmPgD2dUYtVHjF8iwWRM5ZE3MUWT03OA92FQNX8Gtp+LV+D D3z9E7go2OSYcq6cbwsx1siTUmGzZYi+Q0+pWscXPhUC4pssqO6kUSukduRC+gLPcleA 1B3QZYRFidQpR2wNMMlE5JSi0d7XEVn5oLnNTWNMz1nZuak//o8MAvbLuVhoZ0C7SVgl N1y8t5gekD0aeWCfiEgO5ZwxcbxktvDVdm1UFwNTyLmSRy3A2va3mzPY997ieFmGLSo/ L7rnBn4LV3j2vX/6Thk2dPlYTCDJe1h+Irl82DzBhYhkURm6Wm8xP04CtWBfonqZQsO6 OL8g== 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 h190-20020a6383c7000000b00534295ca79bsi37212pge.483.2023.05.14.19.28.52; Sun, 14 May 2023 19:29:05 -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 S238085AbjEOCRX (ORCPT + 99 others); Sun, 14 May 2023 22:17:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237967AbjEOCPm (ORCPT ); Sun, 14 May 2023 22:15:42 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F09201725; Sun, 14 May 2023 19:15:38 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8DxZPDJlWFkEbAIAA--.14956S3; Mon, 15 May 2023 10:15:37 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dxn7O6lWFk0KJeAA--.33838S24; Mon, 15 May 2023 10:15:36 +0800 (CST) From: Tianrui Zhao To: Paolo Bonzini , Huacai Chen Cc: 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 v10 22/30] LoongArch: KVM: Implement handle idle exception Date: Mon, 15 May 2023 10:15:14 +0800 Message-Id: <20230515021522.2445551-23-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230515021522.2445551-1-zhaotianrui@loongson.cn> References: <20230515021522.2445551-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dxn7O6lWFk0KJeAA--.33838S24 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvdXoW7JrW5uFykWr43XF4UXFyUAwb_yoWkXrb_ZF Z7Jas5GFWrXF45Ka4Dt345Ka4Ygw4kXFWY9FW7ury3GF1qyrWUC39rWw1DZrWkKFWUZFW5 K3ykZas7Zw12qjkaLaAFLSUrUUUUeb8apTn2vfkv8UJUUUU8wcxFpf9Il3svdxBIdaVrn0 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.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?1765925448825852503?= X-GMAIL-MSGID: =?utf-8?q?1765925448825852503?= 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; +}