Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2317345rdh; Tue, 26 Sep 2023 21:30:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHM3Z45htoumNllHlPd/p3p7VP3DYBRuXVtrKjTVpXgdFtaHUkFL+UWLkVxLrmca+Z1i/pT X-Received: by 2002:a17:902:b209:b0:1c5:cd1c:46fa with SMTP id t9-20020a170902b20900b001c5cd1c46famr548294plr.36.1695789000590; Tue, 26 Sep 2023 21:30:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695789000; cv=none; d=google.com; s=arc-20160816; b=GYWS5o+iNxC+4KhCciTAQr8RLjTfYxMKODbDvHsKbUz+pjBYarz7omgpEGjtT4f9kr 8PFkPK3q140daxDMvypVth12WCg1GlMOoAfXGZtXmWmdgAl+B6NH+zu/Hi0XPj1WSLfq 8VMeV8XO9l03jHqmAa5IfCikJIP6+Nn6OVXiGADI5A8LEQCH0zAhaU7w22mGq7ph8z14 rHIvLZ+VH2w9JsyZPn7gxccA0yLaFo73DEgtfeLp5PDLsjqMtLWg35/FaPss2FkJxInZ +lBJmBXT8pdXNucAa0bOuH0dw1Hhu7AWiPX3L6fyGrK+GJRM+rdPmmJPfG15IPXmh0tw Jdsg== 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=Yi30+ggbb0wXUbBwoBHlXstsP2lY276q8TD3z/qZYAo=; fh=DndB7O6DTG6Sgonrk2zkDJR5MPyE/Qek5uYuwsra5zw=; b=KDhyu1KluGA4bti9iqeIxx4A8sxsAiN93iW2a9qw2bP8hkpD5Bltgv8dYNyGCOo/zU 3tL68Knr4icSyBsb5M/5S80/bTgEVUKO0g5MKj83OVmSos862RWocFdKQNo1Gw22rZ1n IJcvtYNVMb9O9U7XpGZ1k4h+p9MNR4o2H5Su0k97UILbd0uLu8DVBlcIy64SFy5j3c4m V1OvJ20rD2cFkxSPZ935UsdPtIspgeFPc0l3HJhQZMbM1CO6nPrBSY4BBG3sf1D5zgNa mtMuP1tr7wc4oH55Ed1H+pVpthO1btwCdcR1MoresJ914J5HPZJ/AnqV3aeTNkPK3iJL L/JQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id n9-20020a170902e54900b001c3ffc982cfsi15246007plf.142.2023.09.26.21.30.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 21:30:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 6056F8098486; Tue, 26 Sep 2023 21:29:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229804AbjI0E3l (ORCPT + 99 others); Wed, 27 Sep 2023 00:29:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229609AbjI0E24 (ORCPT ); Wed, 27 Sep 2023 00:28:56 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BE8A0CD7; Tue, 26 Sep 2023 20:10:14 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8AxjusQnRNleRctAA--.18088S3; Wed, 27 Sep 2023 11:10:08 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxjd4InRNlhZETAA--.42466S19; Wed, 27 Sep 2023 11:10:07 +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, Huacai Chen Subject: [PATCH v22 17/25] LoongArch: KVM: Implement handle idle exception Date: Wed, 27 Sep 2023 11:09:51 +0800 Message-Id: <20230927030959.3629941-18-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230927030959.3629941-1-zhaotianrui@loongson.cn> References: <20230927030959.3629941-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8Cxjd4InRNlhZETAA--.42466S19 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 26 Sep 2023 21:29:56 -0700 (PDT) Implement kvm handle LoongArch vcpu idle exception, using kvm_vcpu_block to emulate it. Reviewed-by: Bibo Mao Tested-by: Huacai Chen 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 7e729dd9e9..d4d7e74f72 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -194,3 +194,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.3