Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4020693ybg; Tue, 29 Oct 2019 00:34:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqz/BvHsn0fuqc0uatXYCM8DJxo+bkn6yEkGp7W+tD7YD6ADFWkmJRduKgWB0CVJ5zxHIv4b X-Received: by 2002:aa7:cdc2:: with SMTP id h2mr12764211edw.4.1572334478020; Tue, 29 Oct 2019 00:34:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572334478; cv=none; d=google.com; s=arc-20160816; b=WBjcEweySuOm3jxxEp/HMBqUvqPfvTQ406CuaIJSbr9DMITxBOJB3WfoIclQd5xEhx ZEZ70qL3fGZbOcb09sCnCYJUFUa/wZIA36Hzq+l1XpoARqr39xK4ZqfqDOqm346RchpI fSqNzoFm5CdUoi5JukIW14oZsLAcJEkeGngsFQRXJJot1AUsW/VBmqBmFZu4Bh70nvoY 2GvXlDEcZNkjsEdDQTt/i8IxWSX32Kwi8jk+udnyLo45Flj2luwzBEu3Sax2RwJvKcoq g4sIEWV0Dx8m94dsdcIDT4NHEeoVLlz0XtCHD+0w0tv01kUwU+oEU7eBl2VZgZsPRagK zlVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=l2+5tpD94vYVzUkcBLFx2k66YauLaFc/cHrPeTcXN68=; b=T+trNI5GUpmXv4LQUuS/phvQ/8whJ/NIp56WVaiW2MO7LGxCmMYETNoBGDVV+cBMXE cmWqEbDzgnE221t3b+MhnZR1nYT5o9ICrriW0ldYxlfBTF4Y/dKW6wNlwWixM+Q17TDw pr+hlkq6k2BYPE+ZNzIWVFmpWXXoMqs9C38wyN6EwnQ22YX6rOAN+QC78lq/WUKrzxoC qZSLCOdKQZQax9TI9Tr14CuySjoHjN5zn8Nv86jPhiwibaVcg+orWuEMsXyrPR7Ox4l5 8oyPDcAk01KcAiyvlLdDP/XHgB7C358CpogI/WlEMrrDQhRsccWl8u7FAjpseCih6bQs 1cMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qc9si7848420ejb.265.2019.10.29.00.34.14; Tue, 29 Oct 2019 00:34:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730194AbfJ2HVK (ORCPT + 99 others); Tue, 29 Oct 2019 03:21:10 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:40378 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728111AbfJ2HU2 (ORCPT ); Tue, 29 Oct 2019 03:20:28 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 453D89AEB92ADC6E058B; Tue, 29 Oct 2019 15:20:27 +0800 (CST) Received: from DESKTOP-8RFUVS3.china.huawei.com (10.173.222.27) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.439.0; Tue, 29 Oct 2019 15:20:17 +0800 From: Zenghui Yu To: , , , , CC: , , , , Zenghui Yu Subject: [PATCH 3/3] KVM: arm/arm64: vgic: Don't rely on the wrong pending table Date: Tue, 29 Oct 2019 15:19:19 +0800 Message-ID: <20191029071919.177-4-yuzenghui@huawei.com> X-Mailer: git-send-email 2.23.0.windows.1 In-Reply-To: <20191029071919.177-1-yuzenghui@huawei.com> References: <20191029071919.177-1-yuzenghui@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.173.222.27] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It's possible that two LPIs locate in the same "byte_offset" but target two different vcpus, where their pending status are indicated by two different pending tables. In such a scenario, using last_byte_offset optimization will lead KVM relying on the wrong pending table entry. Let us use last_ptr instead, which can be treated as a byte index into a pending table and also, can be vcpu specific. Signed-off-by: Zenghui Yu --- If this patch has done the right thing, we can even add the: Fixes: 280771252c1b ("KVM: arm64: vgic-v3: KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES") But to be honest, I'm not clear about what has this patch actually fixed. Pending tables should contain all zeros before we flush vgic_irq's pending status into guest's RAM (thinking that guest should never write anything into it). So the pending table entry we've read from the guest memory seems always be zero. And we will always do the right thing even if we rely on the wrong pending table entry. I think I must have some misunderstanding here... Please fix me. virt/kvm/arm/vgic/vgic-v3.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c index 5ef93e5041e1..7cd2e2f81513 100644 --- a/virt/kvm/arm/vgic/vgic-v3.c +++ b/virt/kvm/arm/vgic/vgic-v3.c @@ -363,8 +363,8 @@ int vgic_v3_lpi_sync_pending_status(struct kvm *kvm, struct vgic_irq *irq) int vgic_v3_save_pending_tables(struct kvm *kvm) { struct vgic_dist *dist = &kvm->arch.vgic; - int last_byte_offset = -1; struct vgic_irq *irq; + gpa_t last_ptr = -1; int ret; u8 val; @@ -384,11 +384,11 @@ int vgic_v3_save_pending_tables(struct kvm *kvm) bit_nr = irq->intid % BITS_PER_BYTE; ptr = pendbase + byte_offset; - if (byte_offset != last_byte_offset) { + if (ptr != last_ptr) { ret = kvm_read_guest_lock(kvm, ptr, &val, 1); if (ret) return ret; - last_byte_offset = byte_offset; + last_ptr = ptr; } stored = val & (1U << bit_nr); -- 2.19.1