Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6072874rwd; Mon, 19 Jun 2023 01:44:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5OVdCffnBO1xxrqjZtZM7Dkjidh3YWItVIPJ7keTvM5fape0bQGS38sPE3j8q5cNrR2eoB X-Received: by 2002:a17:90b:a46:b0:25b:ec0c:bf2 with SMTP id gw6-20020a17090b0a4600b0025bec0c0bf2mr6954209pjb.20.1687164256167; Mon, 19 Jun 2023 01:44:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687164256; cv=none; d=google.com; s=arc-20160816; b=YGTRonQQhV8cttT/8Ygklnx1hevwXzQR2QZM8h4EY/F5Bm1LZ9wawpaPayDgX1gE8Q sjdC2g822Zs112PMjmvtsNjRA/zzxPRtrsyBtaOGeWAjFPWRJWVgkdJ1X/YEBaeRqzw9 U+iypsA7NmEyj/HIvluV7AqUffrafNkYybk9wgPxfjKLDSc2Li01OMz+kfdm3X2E9NEt +taqM6kYy/3dkOpPqBV6x6ViXGh8FbBeHcE7ojObfyu+8lzjbHXJVs1XRoeKSHx0RAEk tUaz1Yncz4ZuVa+GsqUmLXDyP4IH2IwhXvmsa7kz84iLld6EX//+5ulJoMrsCfwoVQr9 TrAw== 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=WGxADIiFAVIQzJWVkF14hjD3AhDr9yfrIT8Ffbh+XCw=; b=ivM9O36hGNRSMKqYHYaVrjAorOGu81LMEjKFBnjrW6CmvXvBY9vNvvGKn5ggEMao8c +2BIzz7WKiKo3R7FSMa+rM66SKdlvsqBxm6tUyoqbHWfFPdILs/Uq02u7qwKeDUNDvnH KvF+nQrYS3AdoiXfBIVTy2skyq/0vn0f3OGzMgzpR6N0jRKKRW8Sczro80NsxrXFcIlL L5fc9w+gckXk7XqKXH2pS2oGRf55oTQ27lBIwQtA6JJePRiOGA7JkAOZjT35T6zHzYDl juyHOWNk/fn6OXBSmQ6Qkrx6WukHTPwfmsRjMYcrI6zKCuvUKcGNDn6t0GePtRH7u5ki iWqQ== 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 19-20020a17090a191300b0024e140702efsi7009197pjg.118.2023.06.19.01.44.04; Mon, 19 Jun 2023 01:44:16 -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 S231157AbjFSIeo (ORCPT + 99 others); Mon, 19 Jun 2023 04:34:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230047AbjFSIdS (ORCPT ); Mon, 19 Jun 2023 04:33:18 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E4B34106; Mon, 19 Jun 2023 01:33:16 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8Bx4OjGEpBkGswGAA--.12176S3; Mon, 19 Jun 2023 16:33:10 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxC8q3EpBkAgsgAA--.15169S24; Mon, 19 Jun 2023 16:33:10 +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, tangyouling@loongson.cn Subject: [PATCH v14 22/30] LoongArch: KVM: Implement handle idle exception Date: Mon, 19 Jun 2023 16:32:47 +0800 Message-Id: <20230619083255.3841777-23-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230619083255.3841777-1-zhaotianrui@loongson.cn> References: <20230619083255.3841777-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8BxC8q3EpBkAgsgAA--.15169S24 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, 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. Reviewed-by: Bibo Mao 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 32edd915ebcb..30748238c78c 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