From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D24ACCA9EAE for ; Tue, 29 Oct 2019 12:30:51 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 9E70421479 for ; Tue, 29 Oct 2019 12:30:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="dZCTtjqu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9E70421479 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=D9DUIOx/TpaSU6W/AjUW3u0B9GrvRLlE28WXSVL0W1Y=; b=dZCTtjquLQBWeWNbtMN///UhG bhig9wbY/4WWsJBsIf5ofrS+PKnw3onFqKC18tHT6pKQNTruIPKDloUtCaSeIr8B0KDBO6LNw/Q/B 2hsmSm25uqqvs++akarAsOWvHTHwY/1i4jC03O1xNSxfF31Tz4coy1t4+zqQ1OVRn9zaQT5YqKP20 MPItDlnczQPKAm5fHSTMccWxG3qvxSB54sUGXCNOuxBWoYgxIOCWjzpno76PIS77hjyz3RjVsODt7 wTpL1IOLfXv0EhsuwZokHuKyzElMdKIFutRhwCsFy7LPaN+i2Gdn7kXFPn4lXwY7kBjjNH4u3M6E4 I3y/FOw0g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iPQeA-0006Gc-6v; Tue, 29 Oct 2019 12:30:50 +0000 Received: from szxga06-in.huawei.com ([45.249.212.32] helo=huawei.com) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iPQe6-0006Eq-NC for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2019 12:30:48 +0000 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 836A69BEE590D4A6CFA9; Tue, 29 Oct 2019 20:30:41 +0800 (CST) Received: from [127.0.0.1] (10.173.222.27) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.439.0; Tue, 29 Oct 2019 20:30:32 +0800 Subject: Re: [PATCH 3/3] KVM: arm/arm64: vgic: Don't rely on the wrong pending table To: Auger Eric , , , , References: <20191029071919.177-1-yuzenghui@huawei.com> <20191029071919.177-4-yuzenghui@huawei.com> <5e4d1a2f-7107-efe3-9dde-626662e31ac5@redhat.com> From: Zenghui Yu Message-ID: <825b87df-618f-7f2d-0fe9-4cec240c88bf@huawei.com> Date: Tue, 29 Oct 2019 20:30:32 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.0 MIME-Version: 1.0 In-Reply-To: <5e4d1a2f-7107-efe3-9dde-626662e31ac5@redhat.com> Content-Language: en-US X-Originating-IP: [10.173.222.27] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191029_053046_954403_D24BD3D8 X-CRM114-Status: GOOD ( 14.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: wanghaibin.wang@huawei.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2019/10/29 20:17, Auger Eric wrote: > Hi Zenghui, Marc, > > On 10/29/19 8:19 AM, Zenghui Yu wrote: >> 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); >> > Acked-by: Eric Auger Thanks Eric, Zenghui _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel