Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4284923rdb; Thu, 14 Sep 2023 18:54:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGOXBiEKTnpp3UsIXSp3Il6qQU9lq6JptBrZwWkUVq3LAvOeyIE32SIfZGL/HUb7BGILzaQ X-Received: by 2002:a17:902:e5ca:b0:1c1:fbec:bc3f with SMTP id u10-20020a170902e5ca00b001c1fbecbc3fmr324155plf.5.1694742880639; Thu, 14 Sep 2023 18:54:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694742880; cv=none; d=google.com; s=arc-20160816; b=Vzp48ROS7GyTwVrsVCVKvobNqKjZXTQGYRtStlgVNDV3qpgfBTvqcwLuTBBTtVldnr b8B1S0DTz3ub/CtiyeGz6WBDkrAqao2W0+RLqKUOgjlneDlZaha9wZGrP/VTMNPpwZMR syAK9OW+iEgaJjFZCu6lv/CSODmTsQX+/HW3mMifvfGm+ECllGEK2FtQrEr3tM9AA1yJ ms1gD+2+hVnEaNwh/fFSV6KGXTq1YHVAmxY8oMfRlOBUs5BVMX634k8AqibvZ9UqXqq7 kEEzxur6bg2P06iPOaGXBGkgzAmIv/UbqYHtB/Rv3lmOcvWBySA5fDaiKmRKn6hN0eYT yNIg== 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=tvRfvMFO3bePpa+w7j84FoFMhaP6/TowFjrILFi5fhM=; fh=ejoaVAUUbBXsA/6jM/beuI9xCYtV2osdR9SpI7hjY84=; b=xv8zi4xh4oumNfuNH3sUiTCaO8KrkIR/czTraDV7uA3sj/Qtio60HYmSZixNlv2w5/ CBMRNciskRBW781t7TKTQaNxfnrgVNUX3xyt1qKeNXtiRxBTZr/mA0VWPH2MYyIPc8k/ IO21aQ0obEHqaC+I6l8z9gho8YLJdHP38Bf0dfxrJ32DY4QabWFIOFz/kdnZzgsZvGjg z92/7gkS0v/TJrsA3IWz9apqRkXMhWVu6+2pox6SH/XWsQye/qckvajQ2Xfu54XA16N4 aVSlnT5m4Sv7D3Vhba6kuF4XkFdbXoCBOogvXEoI8TbgEI7hXA3XmjeWN9vZuJsSC5CX 3qEg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id o18-20020a170902e01200b001b9d2010c39si2462807plo.192.2023.09.14.18.54.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 18:54:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 66390858DB54; Thu, 14 Sep 2023 18:51:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231735AbjIOBvC (ORCPT + 99 others); Thu, 14 Sep 2023 21:51:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231685AbjIOBuv (ORCPT ); Thu, 14 Sep 2023 21:50:51 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2E1473599; Thu, 14 Sep 2023 18:50:13 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8BxnutKuANlRP8nAA--.9359S3; Fri, 15 Sep 2023 09:50:02 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Axndw9uANl+ioGAA--.11927S23; Fri, 15 Sep 2023 09:50:01 +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 Subject: [PATCH v21 21/29] LoongArch: KVM: Implement handle idle exception Date: Fri, 15 Sep 2023 09:49:41 +0800 Message-Id: <20230915014949.1222777-22-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230915014949.1222777-1-zhaotianrui@loongson.cn> References: <20230915014949.1222777-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8Axndw9uANl+ioGAA--.11927S23 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== 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 (howler.vger.email [0.0.0.0]); Thu, 14 Sep 2023 18:51:17 -0700 (PDT) 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 1a83eb9afe..9f3d9131c1 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -199,3 +199,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