From patchwork Sat Nov 4 08:57:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: maobibo X-Patchwork-Id: 161549 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp1539879vqu; Sat, 4 Nov 2023 01:59:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFHxvcmICSH0qsrP36gy5puMXRUPvafAWgaHlR9MJ1P50Jplkli91cUrGFI8/WNlpLY9ubt X-Received: by 2002:a05:6214:529c:b0:66d:2af4:c423 with SMTP id kj28-20020a056214529c00b0066d2af4c423mr26441229qvb.2.1699088382665; Sat, 04 Nov 2023 01:59:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699088382; cv=none; d=google.com; s=arc-20160816; b=tbv6oB91VxKJnL1rcpN/j4QYVARGPN/LFxA4jk8Vtn/f2DfAYrcISiGlRfjJnPMaQ6 O9u1rOptyysGW/hsJvedchWfHucG7gv643EyTpTEyTQak/+L09/ADcwXkCelNGJjqKR0 EH++zGjC/z1mQfQSY047Cx4SBuPBHd4xnhbn8B8kJBt4fFMSlemXHZ97m2WU/hsxjUuE /Xp4P7WAWBLZG42mCKo8BxM1OWQj5w2TSa+mhKAobFq8Ff15CHP1RXhPCMyd6+aZtdgc FBcaLE7zvarjeKOzM7jctOJKzkLSgRBOANP2nPqru7YUCHgQ4owt/PiI+OHDVRn0A5Gz N6vw== 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=W6IjnLujlcH8tAMRtvw+JyMDpoouLIrp1AvWRMxObv4=; fh=JOrDXAv7dX9lqUsWenmIinruxsV5NNS7FV+l4Q4onAY=; b=NB+I8iXRIYKWyKpflid83sm23ijktdXEHNCQMbLT9Pw45S2WpbQabBBD8RBgob3enI miTryMQEBfxi3FQKAyPMqJ9FghZpOGVpS4yZPHORDKf73qRwPKxcu9MQxd/w+52+qZT8 B2sXd9aX85O9OQknkYVbN0Z4zYWR5xrAlgXnjiudyJRubUEvdgF/ojmaeOf4D9i2ZiYb 4pEBiravzZye/X9wxZ+mG7zuncjwy3JWP0Fmyy7UF2IrkH5VzLnRs8Du+7itpq9RBe8C i1FFpFh/g3Qe4np3l+Z/B7wDSkQ+y4cmVLbXaJlzSb4IsUnlh18NujGh3AXuAVqe6oDU chqQ== 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:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id be2-20020a656e42000000b00565eb0b2e66si3588719pgb.864.2023.11.04.01.59.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Nov 2023 01:59:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 3AD2A81067B7; Sat, 4 Nov 2023 01:59:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230460AbjKDI7b (ORCPT + 35 others); Sat, 4 Nov 2023 04:59:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230518AbjKDI73 (ORCPT ); Sat, 4 Nov 2023 04:59:29 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B36851BF; Sat, 4 Nov 2023 01:59:25 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8DxqOqVB0Zl1+E2AA--.6334S3; Sat, 04 Nov 2023 16:57:57 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxbS+UB0ZlmGs5AA--.59322S3; Sat, 04 Nov 2023 16:57:57 +0800 (CST) From: Bibo Mao To: Tianrui Zhao , Huacai Chen Cc: WANG Xuerui , kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/3] LoongArch: KVM: Remove SW timer switch during vcpu block flow Date: Sat, 4 Nov 2023 16:57:53 +0800 Message-Id: <20231104085755.930439-2-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231104085755.930439-1-maobibo@loongson.cn> References: <20231104085755.930439-1-maobibo@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxbS+UB0ZlmGs5AA--.59322S3 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoW7ur45Ar18Wr1kJF48JFWDGFX_yoW8uF4fpF W7Crnaqw4rWr1kK3srtw4kWr4UXw4kKF1fXasrAFW5Ar1qyF18tF4rKrWqqFy5Kw4rCFyf Zr1rK3W5uF15A3cCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkFb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r126r13M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r126r1DMcIj6I8E87Iv 67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6x kF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07jjpB-UUUUU= X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Sat, 04 Nov 2023 01:59:40 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781623300101165320 X-GMAIL-MSGID: 1781623300101165320 When idle instruction is emulation, kvm will check whether there is pending interrupts including timer interrupt. HW timer event checking is used now, so it is not necessary to switch to sw timer during vcpu block checking flow, since hw timer pending interrupt can be set directly with CSR staus register. This patch adds preemption disabling during checking hw CSR status register, and removes SW timer mode switching in idle instruction emulation function. Signed-off-by: Bibo Mao --- arch/loongarch/kvm/exit.c | 11 +---------- arch/loongarch/kvm/vcpu.c | 9 ++++++++- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c index ce8de3fa472c..d2a38cd47032 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -200,17 +200,8 @@ 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); + if (!kvm_arch_vcpu_runnable(vcpu)) kvm_vcpu_block(vcpu); - } return EMULATE_DONE; } diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c index 73d0c2b9c1a5..42663a345bd1 100644 --- a/arch/loongarch/kvm/vcpu.c +++ b/arch/loongarch/kvm/vcpu.c @@ -187,8 +187,15 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu) { - return kvm_pending_timer(vcpu) || + int ret; + + /* protect from TOD sync and vcpu_load/put */ + preempt_disable(); + ret = kvm_pending_timer(vcpu) || kvm_read_hw_gcsr(LOONGARCH_CSR_ESTAT) & (1 << INT_TI); + preempt_enable(); + + return ret; } int kvm_arch_vcpu_dump_regs(struct kvm_vcpu *vcpu)