Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp11234882pxu; Thu, 31 Dec 2020 04:02:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJw7E3MBDMHD8ISweNhXgmyAryquHBMUPZu4n10nkPvS5gf0z5WV2p+CpvKyekGZpU8kPXoT X-Received: by 2002:a17:906:eb8d:: with SMTP id mh13mr51939316ejb.299.1609416166220; Thu, 31 Dec 2020 04:02:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609416166; cv=none; d=google.com; s=arc-20160816; b=zObhuikeTX4UUyV7aUFKWyiRSqOq0K7BVtMNI/IGYn2iKXLbbJ+e2p/Kq/0yQ5S+l1 SYTclsS6HsC0lIkeGJo6V0HSitikGDZGpEEI+V7MRFpAmUiQk8LFh30HYFMGbZYTzSPp szwZQ+u/lDFHHCTkIwQ36EWPTxAcOpged7arIOZNDyYswO6pQzKwhCh3REbYej3S+KQq 0wC/DIajko/gdOyWETCiI3zAj3Ze+7TW3LhVfWjAIhh9EBPKdlk87+0NuxzX4igxc8iM 0rTtdDX5dBy2y6hT5rbxAEZ+pDZ7LLkGsuO+24pNmaiIe1kXmuIzI8zfOX8Jww2epuRH n83Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=VswVZBbNeURLJKnrPqY3qwu/+tnd/XQnjluoeQ9Gikk=; b=CajGLPkWHOv3V96X9j5IOvyb+8uFKyhGXslBnWVZvtEulUB5fmkUk+OXKcE29nE2ht ahgEwsuPOq3OwERzckIjfZzezCwY7weazB+bFypoqfz4TNlTcstQMvkvF6YxZuU7Sy+C FKHswxKX503qNpfz6dPtV0gPqd9vlayY1fvLqXqDvZXebn2cM1QlrproeSAmL5PO+FoH G6izuCCgtMBremz6/hHNWO/LIprxkuOOyj3ZB7k7fRCRj1V3X/E39M8+XEMQKkSFqrk8 dNBg/LZouUZpvKj/94QCtLgdcCn7h98/oOF3E6oeKNSlIMB1FDmNKBr2HDu3W4hEZ7k7 L5+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z16si23416031eju.92.2020.12.31.04.02.22; Thu, 31 Dec 2020 04:02:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726515AbgLaL7q (ORCPT + 99 others); Thu, 31 Dec 2020 06:59:46 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:10014 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726071AbgLaL7q (ORCPT ); Thu, 31 Dec 2020 06:59:46 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4D669c1H9Mzj1r4; Thu, 31 Dec 2020 19:58:12 +0800 (CST) Received: from [10.174.184.196] (10.174.184.196) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Thu, 31 Dec 2020 19:58:53 +0800 Subject: Re: [PATCH RFC] KVM: arm64: vgic: Decouple the check of the EnableLPIs bit from the ITS LPI translation To: Marc Zyngier CC: Will Deacon , Eric Auger , , , , , References: <20201231062813.714-1-lushenming@huawei.com> <683134bdea8a22d3bb784117dcfe17a1@kernel.org> From: Shenming Lu Message-ID: Date: Thu, 31 Dec 2020 19:58:41 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.2.2 MIME-Version: 1.0 In-Reply-To: <683134bdea8a22d3bb784117dcfe17a1@kernel.org> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.184.196] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/12/31 16:57, Marc Zyngier wrote: > Hi Shemming, > > On 2020-12-31 06:28, Shenming Lu wrote: >> When the EnableLPIs bit is set to 0, any ITS LPI requests in the >> Redistributor would be ignored. And this check is independent from >> the ITS LPI translation. So it might be better to move the check >> of the EnableLPIs bit out of the LPI resolving, and also add it >> to the path that uses the translation cache. > > But by doing that, you are moving the overhead of checking for > EnableLPIs from the slow path (translation walk) to the fast > path (cache hit), which seems counter-productive. Oh, I didn't notice the overhead of the checking, I thought it would be negligible... > >> Besides it seems that >> by this the invalidating of the translation cache caused by the LPI >> disabling is unnecessary. >> >> Not sure if I have missed something... Thanks. > > I am certainly missing the purpose of this patch. > > The effect of EnableLPIs being zero is to drop the result of any > translation (a new pending bit) on the floor. Given that, it is > immaterial whether this causes a new translation or hits in the > cache, as the result is still to not pend a new interrupt. > > I get the feeling that you are trying to optimise for the unusual > case where EnableLPIs is 0 *and* you have a screaming device > injecting tons of interrupt. If that is the case, I don't think > this is worth it. In fact, I just found (imagining) that if the EnableLPIs bit is 0, the kvm_vgic_v4_set_forwarding() would fail when performing the LPI translation, but indeed we don't try to pend any interrupts there... By the way, it seems that the LPI disabling would not affect the injection of VLPIs... Thanks, Shenming > > Thanks, > >         M. > >> >> Signed-off-by: Shenming Lu >> --- >>  arch/arm64/kvm/vgic/vgic-its.c     | 9 +++++---- >>  arch/arm64/kvm/vgic/vgic-mmio-v3.c | 4 +--- >>  2 files changed, 6 insertions(+), 7 deletions(-) >> >> diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c >> index 40cbaca81333..f53446bc154e 100644 >> --- a/arch/arm64/kvm/vgic/vgic-its.c >> +++ b/arch/arm64/kvm/vgic/vgic-its.c >> @@ -683,9 +683,6 @@ int vgic_its_resolve_lpi(struct kvm *kvm, struct >> vgic_its *its, >>      if (!vcpu) >>          return E_ITS_INT_UNMAPPED_INTERRUPT; >> >> -    if (!vcpu->arch.vgic_cpu.lpis_enabled) >> -        return -EBUSY; >> - >>      vgic_its_cache_translation(kvm, its, devid, eventid, ite->irq); >> >>      *irq = ite->irq; >> @@ -738,6 +735,9 @@ static int vgic_its_trigger_msi(struct kvm *kvm, >> struct vgic_its *its, >>      if (err) >>          return err; >> >> +    if (!irq->target_vcpu->arch.vgic_cpu.lpis_enabled) >> +        return -EBUSY; >> + >>      if (irq->hw) >>          return irq_set_irqchip_state(irq->host_irq, >>                           IRQCHIP_STATE_PENDING, true); >> @@ -757,7 +757,8 @@ int vgic_its_inject_cached_translation(struct kvm >> *kvm, struct kvm_msi *msi) >> >>      db = (u64)msi->address_hi << 32 | msi->address_lo; >>      irq = vgic_its_check_cache(kvm, db, msi->devid, msi->data); >> -    if (!irq) >> + >> +    if (!irq || !irq->target_vcpu->arch.vgic_cpu.lpis_enabled) >>          return -EWOULDBLOCK; >> >>      raw_spin_lock_irqsave(&irq->irq_lock, flags); >> diff --git a/arch/arm64/kvm/vgic/vgic-mmio-v3.c >> b/arch/arm64/kvm/vgic/vgic-mmio-v3.c >> index 15a6c98ee92f..7b0749f7660d 100644 >> --- a/arch/arm64/kvm/vgic/vgic-mmio-v3.c >> +++ b/arch/arm64/kvm/vgic/vgic-mmio-v3.c >> @@ -242,10 +242,8 @@ static void vgic_mmio_write_v3r_ctlr(struct kvm_vcpu *vcpu, >> >>      vgic_cpu->lpis_enabled = val & GICR_CTLR_ENABLE_LPIS; >> >> -    if (was_enabled && !vgic_cpu->lpis_enabled) { >> +    if (was_enabled && !vgic_cpu->lpis_enabled) >>          vgic_flush_pending_lpis(vcpu); >> -        vgic_its_invalidate_cache(vcpu->kvm); >> -    } >> >>      if (!was_enabled && vgic_cpu->lpis_enabled) >>          vgic_enable_lpis(vcpu); >