From patchwork Thu Aug 31 08:30:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 137283 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c792:0:b0:3f2:4152:657d with SMTP id b18csp182222vqu; Thu, 31 Aug 2023 04:43:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG1FYLcilDPmBVwRRixhtsKbzgeTOI+J2IL8UbzxWEelG1xkimgP1wGtVoSQu20gFDcDfOH X-Received: by 2002:a05:6402:1288:b0:521:a4bb:374f with SMTP id w8-20020a056402128800b00521a4bb374fmr4265339edv.5.1693482237427; Thu, 31 Aug 2023 04:43:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693482237; cv=none; d=google.com; s=arc-20160816; b=ignh3kNgjfZnMizeGMe53aM6A4FbXkBnAbYpdC9N3tsHN0x5zSqj8RCynTGjI5/VC2 wHbA6Ln1pT8QnMaMbQEHbOP0fZvGbqOoJHo7kiXHJac5LfE87552InGtHUeseDsunyxp +3yF3JdWOCvu0QQTAZ7YO7RBQ2RwC55MdgtUH4DlvxSJSDOBcowNuqq83rU2B1YRjMUS hWbegcsZW0PViHnJZKwk2kSRdRh6wDbIb+MrK0eClZRu8TN1kRuIWcg/jy2XT4u1tQSa FMzvjhVGULiJr8JBnCypUN7CAdH2k7igOAre2Y88S2zK4ZERAxRcFS+TCvDEYkb3sdgW aAWA== 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=YR6oMRucCHft1Qgi26mumQwdsMX1HhZIFD/+6LTQP1M=; fh=ejoaVAUUbBXsA/6jM/beuI9xCYtV2osdR9SpI7hjY84=; b=Ywm3Z+kyUxiaZT4hOS4bHj6hTCvJcK0+VuIL9jAqljtJOJSabDux+tGwVFceD0zTkt dcTif9gaoXH3CAngZ3kwwSDCPex5GDpNjPFPQWRSk8ErI4dCnHZflpsBtsOMRhnP7dqU 0jcUFLYUHQqEtkmBqNeYG7aEylrYFTju/Oty4CenUUwRgxq6Pdtt5fKe1xBMhfTRT3oY ye9df1POd7XfK5EMOuz7oS/SOtd3a/Hi5IAaqbyI0/EbgK4SlAoGFWBbqG/yw69HKs37 tZ7skpMu5dwvdyWsibeKThfaVBiMazZgJrKQPTudbbgVmCARzoOBSEkZx3GLQMJKunc1 bGow== 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 j16-20020aa7c0d0000000b00522b8b66749si907216edp.492.2023.08.31.04.43.07; Thu, 31 Aug 2023 04:43:57 -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 S1343715AbjHaIcF (ORCPT + 99 others); Thu, 31 Aug 2023 04:32:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345099AbjHaIb0 (ORCPT ); Thu, 31 Aug 2023 04:31:26 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7777410CB; Thu, 31 Aug 2023 01:30:43 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8AxTeutT_BkuV4dAA--.54667S3; Thu, 31 Aug 2023 16:30:37 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Ax3c6gT_BkOPVnAA--.55892S24; Thu, 31 Aug 2023 16:30:36 +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 v20 22/30] LoongArch: KVM: Implement handle idle exception Date: Thu, 31 Aug 2023 16:30:12 +0800 Message-Id: <20230831083020.2187109-23-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230831083020.2187109-1-zhaotianrui@loongson.cn> References: <20230831083020.2187109-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Ax3c6gT_BkOPVnAA--.55892S24 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1775744830399067205 X-GMAIL-MSGID: 1775744830399067205 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 32edd915eb..30748238c7 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; +}