Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp383750rdb; Sat, 19 Aug 2023 05:50:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF6sy+eQfNRHCkKdzxgOt4j7MCMpZqvSWac7W4ysUYVNqA+qwlmQOIIruoqzC2zK44glLqX X-Received: by 2002:a17:903:32cd:b0:1b3:d8ac:8db3 with SMTP id i13-20020a17090332cd00b001b3d8ac8db3mr2381175plr.6.1692449406408; Sat, 19 Aug 2023 05:50:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692449406; cv=none; d=google.com; s=arc-20160816; b=cSb/HQIq5i35SgQJl8DM1cTt8aZ5ljR3i3a65QzPV1zf0yf2y5gDxnp456E//sk2FZ BjRb6f0V1m26JWpYOjkBf9N8XOy12YN3VyQY29g943L/+ny9K7yR03qrqPYSbiymmq59 Ns233Z5CNPtfJdG8rxy44qkrQpZkvECbNFrJiQmloOUWcFSw5AHPX/fqMn55d54aNzL5 o4+6HGnvA4PNNP47iMYYL6aRezFfDkRUv69K9OKoN6Brqd+7oqhnjfFcCvweC7xLTn30 RciUdRJHdP25YzXwa2ZLU2crhUcGs8jRL1COSwhvPUGneq86Q72d/3d/2zD5nZSJvF/m PAFg== 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=; fh=vBXozhnPXwSB3DJhjnKWz3f6luaN/KxHDpM6/QeZg4o=; b=f7XBiZxBAJugg6Q8rKdNfGJ2oSIAV8N/xJ9FETITx+1DsRFIKneFugZbcnWfuAJWSv vWXIwPtVja/tlOoNF6+wcqce4gaPdZIaBYoohDnWVNyKZ6Zg399dcB3aXgrk4H3c0ztF sNg+Clo7AZKHb5DDOrchaNyWXMjqmH4id6MQiMlSm5EfAUESJLJGEVSX6DKWZg9NuY6X W1zwk/qv3xI4vcER2gaIhggMIQUCJyeolO7qXCQzunY6/HaQID7dYBAzemJyyfRe+bIg d2SLO0JPgOpcLGDMJw6FCcS96R63E2g7Sm55j2QJUigA+5k1E6FXImDhukbcqcJMRJ7K eaRQ== 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:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id jw4-20020a170903278400b001b8c6f80ddbsi3295030plb.105.2023.08.19.05.50.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 05:50:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E921E8EED8; Sat, 19 Aug 2023 01:38:36 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351114AbjHQNAV (ORCPT + 99 others); Thu, 17 Aug 2023 09:00:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351117AbjHQNAL (ORCPT ); Thu, 17 Aug 2023 09:00:11 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 55B0030D0; Thu, 17 Aug 2023 06:00:09 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8BxpPDPGd5kiIYZAA--.52360S3; Thu, 17 Aug 2023 20:59:59 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxniPIGd5kmchcAA--.55665S24; Thu, 17 Aug 2023 20:59:59 +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 v19 22/30] LoongArch: KVM: Implement handle idle exception Date: Thu, 17 Aug 2023 20:59:43 +0800 Message-Id: <20230817125951.1126909-23-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230817125951.1126909-1-zhaotianrui@loongson.cn> References: <20230817125951.1126909-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8BxniPIGd5kmchcAA--.55665S24 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, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS 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