Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4785022ybg; Tue, 29 Oct 2019 12:20:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqyI7lktFccu7OJyb1R18mN6EDF8T5NqNtYmVjtR4Ve/8Uy/cxYDfKiaH+cFjqtwlI7rx49U X-Received: by 2002:a50:b966:: with SMTP id m93mr27108381ede.228.1572376838143; Tue, 29 Oct 2019 12:20:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572376838; cv=none; d=google.com; s=arc-20160816; b=kAhVDLnCUSCnwvbcyp78BgjuyBNu50gOrr47IpsYcDtK0Blx/BA3Cky31qLe73++sX Kr6ufwN6CyEvyWrUqw4ZcC0dpQ40yBN8XrZqse3Gpf8X3aFqyoG30DhoOWE3WgB/WKwo e7zUf418eSUhHPS2R5ImoS1/Rm2FA8MxdwUjbaK1FOHiKzDrhOqtAeIr0oXaDnRafMCG dRszw5iHXJOklKMPmSeh524ywJQpcZc+WMzW8lozfAyY3PY++AcezUg4JaYo3t9QRO0A LhsT0HebpmNaUTq3jWU74nucEeyYIi+c+/ygQbOc82ubMZ63wLnx1QXJwpxykiJ9Y62u Mluw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=c5TVCYf2MyQ5m7UVpCqBCLIUTH2CBfxMSLxMHSp3UXw=; b=FdXhqkTIS19zd2cpWUNiKIP6UQl95Eb8q+ZJTAEC7JspzHyP6JT0Cn302zPJy7R5HX oXNbuyOkI2FU+QieX9PI5vbw6Uhm8Lbaotlqs71G2HRrVlpkDLFkC2t093hYxlakFcWw Xdn7/5LDWR9obP4okdYrHfzrGKNx0CDkyuT6uzntqYToIbgkShyt6fdycOpSPU0SThoP uEkV4T5C6SiUN34ssJIi/OQMW8/lkn7OJ8Whqax6c2lEwwDskLschcNn4Cy9Zk384kAD pjV0DO7zOZoGOd4TEV6QhdbyyS7aQZtBrpnUAUadItkNagoxyKI1KP5Biq9nWc95ESDz v03A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gCso8YSQ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g23si8686687ejk.186.2019.10.29.12.20.14; Tue, 29 Oct 2019 12:20: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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gCso8YSQ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730269AbfJ2MRU (ORCPT + 99 others); Tue, 29 Oct 2019 08:17:20 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:26750 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727082AbfJ2MRU (ORCPT ); Tue, 29 Oct 2019 08:17:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572351439; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c5TVCYf2MyQ5m7UVpCqBCLIUTH2CBfxMSLxMHSp3UXw=; b=gCso8YSQKB2mbv431nmp+frf4w9LlzMZOobkUSCWl3MDrh8dZ8jzJxlCx38AK+/WbY4K0I edSxoWzpf/Ej+aGgACN58tAQ116KAEnbpXiQ0oGIZvXtOB3H2ibQTFppiyOS/mOAKek5mm IAv7a/tgOu48TGpjonSmZeoABPGyF8I= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-14-1I3Ni04hMhG__5_pXeNLHQ-1; Tue, 29 Oct 2019 08:17:15 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 29E9C107AD28; Tue, 29 Oct 2019 12:17:14 +0000 (UTC) Received: from [10.36.118.15] (unknown [10.36.118.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 728CC600C4; Tue, 29 Oct 2019 12:17:10 +0000 (UTC) Subject: Re: [PATCH 3/3] KVM: arm/arm64: vgic: Don't rely on the wrong pending table To: Zenghui Yu , maz@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com Cc: wanghaibin.wang@huawei.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20191029071919.177-1-yuzenghui@huawei.com> <20191029071919.177-4-yuzenghui@huawei.com> From: Auger Eric Message-ID: <5e4d1a2f-7107-efe3-9dde-626662e31ac5@redhat.com> Date: Tue, 29 Oct 2019 13:17:00 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20191029071919.177-4-yuzenghui@huawei.com> Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: 1I3Ni04hMhG__5_pXeNLHQ-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. >=20 > Signed-off-by: Zenghui Yu > --- >=20 > If this patch has done the right thing, we can even add the: >=20 > Fixes: 280771252c1b ("KVM: arm64: vgic-v3: KVM_DEV_ARM_VGIC_SAVE_PENDING_= TABLES") >=20 > 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 pendin= g > 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. >=20 > I think I must have some misunderstanding here... Please fix me. >=20 > virt/kvm/arm/vgic/vgic-v3.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) >=20 > 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) > { > =09struct vgic_dist *dist =3D &kvm->arch.vgic; > -=09int last_byte_offset =3D -1; > =09struct vgic_irq *irq; > +=09gpa_t last_ptr =3D -1; > =09int ret; > =09u8 val; > =20 > @@ -384,11 +384,11 @@ int vgic_v3_save_pending_tables(struct kvm *kvm) > =09=09bit_nr =3D irq->intid % BITS_PER_BYTE; > =09=09ptr =3D pendbase + byte_offset; > =20 > -=09=09if (byte_offset !=3D last_byte_offset) { > +=09=09if (ptr !=3D last_ptr) { > =09=09=09ret =3D kvm_read_guest_lock(kvm, ptr, &val, 1); > =09=09=09if (ret) > =09=09=09=09return ret; > -=09=09=09last_byte_offset =3D byte_offset; > +=09=09=09last_ptr =3D ptr; > =09=09} > =20 > =09=09stored =3D val & (1U << bit_nr); >=20 Acked-by: Eric Auger Thanks for fixing this. Eric