From patchwork Thu Jul 4 14:23:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kunkun Jiang X-Patchwork-Id: 13723798 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ABEEDC3271E for ; Thu, 4 Jul 2024 14:24:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+gMI9h3EwEc4uufTgmipfWDmm8uW0hfMM5WbbcwcBow=; b=fm0NCamUcQ1TmCPXb0SAUykVmZ LkAH42bV5Ksv6BYK8M8IqW70D0gI7Mk0QqQGaVvWK8+Hvlltkj6mwWsKIZmPpDvIPQTkP0u0kuDVa FOjjKR+lfn3f51oi404QzGNi5a6e5VVTwajPLB7Z9agzOePSD8FwjdMvdk+/PBLDj6jk0rdJRRiJ4 SFCtAeD3NgkKRSDnaMqouzwlzP2BdQuImuHZPkOtgRhmd9KHlpE9rIFRnGr7iFux5AisKv2Vqbdxx l1XALm2kMlzRfVNRQwoQitEko5VxJcR1XbOpgcuw2vnD2tUCAUsv8b6z7X2EO95dIRT47YJaAouQD tobc0Pvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPNNz-0000000DS3B-0ua2; Thu, 04 Jul 2024 14:24:35 +0000 Received: from szxga08-in.huawei.com ([45.249.212.255]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPNNI-0000000DRpX-1rGe for linux-arm-kernel@lists.infradead.org; Thu, 04 Jul 2024 14:23:54 +0000 Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4WFJg20c8Rz1T571; Thu, 4 Jul 2024 22:19:10 +0800 (CST) Received: from kwepemm600007.china.huawei.com (unknown [7.193.23.208]) by mail.maildlp.com (Postfix) with ESMTPS id E1875180A9C; Thu, 4 Jul 2024 22:23:44 +0800 (CST) Received: from DESKTOP-6NKE0BC.china.huawei.com (10.174.185.210) by kwepemm600007.china.huawei.com (7.193.23.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 4 Jul 2024 22:23:43 +0800 From: Kunkun Jiang To: Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Randy Dunlap , Eric Auger CC: , , , Kunkun Jiang , , Subject: [PATCH v2 3/3] KVM: arm64: vgic-its: Clear ite when discard frees an ite Date: Thu, 4 Jul 2024 22:23:19 +0800 Message-ID: <20240704142319.728-4-jiangkunkun@huawei.com> X-Mailer: git-send-email 2.26.2.windows.1 In-Reply-To: <20240704142319.728-1-jiangkunkun@huawei.com> References: <20240704142319.728-1-jiangkunkun@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.185.210] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600007.china.huawei.com (7.193.23.208) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240704_072352_718391_8363360F X-CRM114-Status: GOOD ( 11.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When discard frees an ite, we do not invalidate the corresponding ite. In the scenario of continuous save and restore, there may be a situation where an ite is not saved but is restored. This is unreasonable and may cause restore to fail. This patch clears the corresponding ite when discard frees a ite. Signed-off-by: Kunkun Jiang --- arch/arm64/kvm/vgic/vgic-its.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c index 223a5f1d6a3d..cf4a85a29504 100644 --- a/arch/arm64/kvm/vgic/vgic-its.c +++ b/arch/arm64/kvm/vgic/vgic-its.c @@ -782,6 +782,10 @@ static int vgic_its_cmd_handle_discard(struct kvm *kvm, struct vgic_its *its, ite = find_ite(its, device_id, event_id); if (ite && its_is_collection_mapped(ite->collection)) { + struct its_device *device = find_its_device(its, device_id); + int ite_esz = vgic_its_get_abi(its)->ite_esz; + gpa_t gpa = device->itt_addr + ite->event_id * ite_esz; + u64 val = 0; /* * Though the spec talks about removing the pending state, we * don't bother here since we clear the ITTE anyway and the @@ -790,6 +794,11 @@ static int vgic_its_cmd_handle_discard(struct kvm *kvm, struct vgic_its *its, vgic_its_invalidate_cache(its); its_free_ite(kvm, ite); + + if (KVM_BUG_ON(ite_esz != sizeof(val), kvm)) + return -EINVAL; + + vgic_write_guest_lock(kvm, gpa, &val, ite_esz); return 0; }