From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752438AbdJFOi3 (ORCPT ); Fri, 6 Oct 2017 10:38:29 -0400 Received: from foss.arm.com ([217.140.101.70]:35068 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751642AbdJFOi1 (ORCPT ); Fri, 6 Oct 2017 10:38:27 -0400 Subject: Re: [PATCH v2 05/10] KVM: arm/arm64: vgic-its: Check GITS_CBASER validity before processing commands To: Eric Auger , eric.auger.pro@gmail.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, marc.zyngier@arm.com, cdall@linaro.org, peter.maydell@linaro.org, wanghaibin.wang@huawei.com Cc: wu.wubin@huawei.com References: <1506518920-18571-1-git-send-email-eric.auger@redhat.com> <1506518920-18571-6-git-send-email-eric.auger@redhat.com> From: Andre Przywara Message-ID: <44a357a8-6ef2-4fd3-597d-3efd28317056@arm.com> Date: Fri, 6 Oct 2017 15:38:29 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <1506518920-18571-6-git-send-email-eric.auger@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 27/09/17 14:28, Eric Auger wrote: > At the moment vgic_its_process_commands() does not > check the CBASER is valid before processing any command. > Let's fix that. Good catch, but actually it goes a bit further: "When GITS_CTLR.Enabled is written from 0 to 1 behavior is UNPREDICTABLE if any of the following conditions are true: ยท GITS_CBASER.Valid == 0. ... " So I think we need to check it upon setting CTLR.Enabled. I did this in Xen, but forgot to fix this in KVM as well: https://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=xen/arch/arm/vgic-v3-its.c;hb=HEAD#l1164 Cheers, Andre. > > Also rename cbaser local variable into cbaser_pa to avoid > any confusion with the full register. > > Signed-off-by: Eric Auger > --- > virt/kvm/arm/vgic/vgic-its.c | 13 ++++++++----- > 1 file changed, 8 insertions(+), 5 deletions(-) > > diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c > index 60ecf91..720552c 100644 > --- a/virt/kvm/arm/vgic/vgic-its.c > +++ b/virt/kvm/arm/vgic/vgic-its.c > @@ -1301,17 +1301,20 @@ static void vgic_mmio_write_its_cbaser(struct kvm *kvm, struct vgic_its *its, > /* Must be called with the cmd_lock held. */ > static void vgic_its_process_commands(struct kvm *kvm, struct vgic_its *its) > { > - gpa_t cbaser; > + gpa_t cbaser_pa; > u64 cmd_buf[4]; > > - /* Commands are only processed when the ITS is enabled. */ > - if (!its->enabled) > + /* > + * Commands are only processed when the ITS is enabled and > + * CBASER is valid > + */ > + if (!its->enabled || (!(its->cbaser & GITS_CBASER_VALID))) > return; > > - cbaser = CBASER_ADDRESS(its->cbaser); > + cbaser_pa = CBASER_ADDRESS(its->cbaser); > > while (its->cwriter != its->creadr) { > - int ret = kvm_read_guest(kvm, cbaser + its->creadr, > + int ret = kvm_read_guest(kvm, cbaser_pa + its->creadr, > cmd_buf, ITS_CMD_SIZE); > /* > * If kvm_read_guest() fails, this could be due to the guest >