From patchwork Thu Jun 20 03:35:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bibo Mao X-Patchwork-Id: 13704839 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 46FDB3C00; Thu, 20 Jun 2024 03:35:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718854559; cv=none; b=V56ZdFFeCG8LVpTqC9MtdbkNqkVxi4aYdV03Ynq75fjdoGKB080G9ZypSqIsa/Mfvf4woHIB13itoe6Fb8C+MMn00k4mqUSLUmGiSNWQ2/8xVfctZ0U47yaub2UfBMiXWc7M85BxGwI6HzPhjl3oZ9juMiFfJ+ZAS7v61fLv5vM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718854559; c=relaxed/simple; bh=pxEJn23nT6+sqxNt5VIguQ2SC4vykVQraEA5VugQ+mQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=bfFC3hBRxDfjPB3i81Kyflc6ztpswAOu0cyOfXLepnJI1v/WyQxo2IuH5O9bgjfp7zP7h7OsrfBc3s4TZoN7cYWJUEbf+cRhVpYeMeGzjDgoNFOrn1HOyez+nizE7KXk88+IlyW6XHxRt9hClJl8InllMLdXUzLTS+MFyFCovZ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8Bx3+uZo3NmSWkIAA--.18063S3; Thu, 20 Jun 2024 11:35:53 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cx78eYo3Nm6ugpAA--.35757S2; Thu, 20 Jun 2024 11:35:53 +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] LoongArch: KVM: Sync pending interrupt when getting ESTAT from user mode Date: Thu, 20 Jun 2024 11:35:52 +0800 Message-Id: <20240620033552.2739845-1-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Cx78eYo3Nm6ugpAA--.35757S2 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Currently interrupt is posted and cleared with async mode, and it is saved in SW state vcpu::arch::irq_pending and vcpu::arch::irq_clear. When vcpu is ready to run, interrupt is synced to ESTAT CSR register from SW state vcpu::arch::irq_pending at guest entrance. During VM migration stage, vcpu is put into stopped state, however pending interrupt is not synced to ESTAT CSR register. So there will be interrupt lost when VCPU is stopped and migrated to other host machines. Here when ESTAT CSR register is read from VMM user mode, pending interrupt is synced to ESTAT also. So that VMM can get correct pending interrupt. Signed-off-by: Bibo Mao --- arch/loongarch/kvm/vcpu.c | 9 +++++++++ 1 file changed, 9 insertions(+) base-commit: 92e5605a199efbaee59fb19e15d6cc2103a04ec2 diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c index b747bd8bc037..81622cd055af 100644 --- a/arch/loongarch/kvm/vcpu.c +++ b/arch/loongarch/kvm/vcpu.c @@ -371,9 +371,18 @@ static int _kvm_getcsr(struct kvm_vcpu *vcpu, unsigned int id, u64 *val) return -EINVAL; if (id == LOONGARCH_CSR_ESTAT) { + preempt_disable(); + vcpu_load(vcpu); + /* + * Sync pending interrupt into estat so that interrupt + * remains during migration stage + */ + kvm_deliver_intr(vcpu); /* ESTAT IP0~IP7 get from GINTC */ gintc = kvm_read_sw_gcsr(csr, LOONGARCH_CSR_GINTC) & 0xff; *val = kvm_read_sw_gcsr(csr, LOONGARCH_CSR_ESTAT) | (gintc << 2); + vcpu_put(vcpu); + preempt_enable(); return 0; }