Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3399063pxf; Mon, 5 Apr 2021 11:00:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuUm1jUGn9h0DnxohPQc3k/c6TLwDUXJ1Tu7L1JBIETngryNNv/hFMFBR/Rq639/QE9eLr X-Received: by 2002:a05:6402:4244:: with SMTP id g4mr32718756edb.204.1617645633683; Mon, 05 Apr 2021 11:00:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617645633; cv=none; d=google.com; s=arc-20160816; b=aZJljL1OrtsFcelmO/1RljvdDqQNmntBY/OklYVWtrQJj8DQrDHMabB1qQXbRqIp5m yggNZbz7FVJyHSEKCZQcxex8Oo8r2rtj1T+vdz7DTCK5rhGOEgDOvZcFwHyaN3GFdBMP ZcYbuCKlk4t2262IO4/I3oKBq2FCQBzPSc+NcWFrVvaHJlhRlewa33Jitawdt+ni5ca0 GepwoTeW1WaArsiXcg8zbspWAWsisNB+dk4UxOuymOA9AXOzgUafxf3EZDGEBa1O20f/ 2LdzKt+N6aM1BlwpZ/mkAccVPZ6BGwJ6bwqEMlxcszjXMpeSNAswp9VNceB1pHvQDKme K+vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date; bh=yDauHmiW/Er3HFEaICGxElQmi+oraPgXf3D0tD3AFOc=; b=D0hePElf1uZEJ344kYl1M/6V+5LDKv0k642eLJcCB6nvJht9bH5BPBYcTHP90iW5Vm JEQ82ZeaTx6pqUhJuCBwzq/Nx27VaBbjNwcjim37K0iaxA2KK2qWFqmrYk9ma0D4CDIU w1/uVdXI/yd7vfQcumMDtdBGDb6HD72X3lJIJ6PgaMPqj0noMWQoOT9FovjolzduYYg+ KJLaznW73MXiZlLIIWiEFr1E/pe8XJ7uwMQI1CP7nHeK3unA2MgyxA6kGEgvlGcYQ2y4 ewu55QOrFLTL/KbOZwCpSDv6Bp0THD1M5uIfYG40hj5dyjj+XoIiFyE1XMruT1S9wayN juxQ== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ba15si5484714edb.75.2021.04.05.11.00.09; Mon, 05 Apr 2021 11:00:33 -0700 (PDT) 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238081AbhDEKK1 (ORCPT + 99 others); Mon, 5 Apr 2021 06:10:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:50188 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232456AbhDEKK1 (ORCPT ); Mon, 5 Apr 2021 06:10:27 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 612AB611CC; Mon, 5 Apr 2021 10:10:21 +0000 (UTC) Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1lTMBX-005eqm-5T; Mon, 05 Apr 2021 11:10:19 +0100 Date: Mon, 05 Apr 2021 11:10:18 +0100 Message-ID: <878s5xf3ed.wl-maz@kernel.org> From: Marc Zyngier To: Eric Auger Cc: eric.auger.pro@gmail.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, drjones@redhat.com, alexandru.elisei@arm.com, james.morse@arm.com, suzuki.poulose@arm.com, shuah@kernel.org, pbonzini@redhat.com Subject: Re: [PATCH v5 7/8] KVM: arm64: vgic-v3: Expose GICR_TYPER.Last for userspace In-Reply-To: <20210404172243.504309-8-eric.auger@redhat.com> References: <20210404172243.504309-1-eric.auger@redhat.com> <20210404172243.504309-8-eric.auger@redhat.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: eric.auger@redhat.com, eric.auger.pro@gmail.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, drjones@redhat.com, alexandru.elisei@arm.com, james.morse@arm.com, suzuki.poulose@arm.com, shuah@kernel.org, pbonzini@redhat.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 04 Apr 2021 18:22:42 +0100, Eric Auger wrote: > > Commit 23bde34771f1 ("KVM: arm64: vgic-v3: Drop the > reporting of GICR_TYPER.Last for userspace") temporarily fixed > a bug identified when attempting to access the GICR_TYPER > register before the redistributor region setting, but dropped > the support of the LAST bit. > > Emulating the GICR_TYPER.Last bit still makes sense for > architecture compliance though. This patch restores its support > (if the redistributor region was set) while keeping the code safe. > > We introduce a new helper, vgic_mmio_vcpu_rdist_is_last() which > computes whether a redistributor is the highest one of a series > of redistributor contributor pages. > > With this new implementation we do not need to have a uaccess > read accessor anymore. > > Signed-off-by: Eric Auger > > --- > > v4 -> v5: > - redist region list now is sorted by @base > - change the implementation according to Marc's understanding of > the spec > --- > arch/arm64/kvm/vgic/vgic-mmio-v3.c | 58 +++++++++++++++++------------- > include/kvm/arm_vgic.h | 1 + > 2 files changed, 34 insertions(+), 25 deletions(-) > > diff --git a/arch/arm64/kvm/vgic/vgic-mmio-v3.c b/arch/arm64/kvm/vgic/vgic-mmio-v3.c > index e1ed0c5a8eaa..03a253785700 100644 > --- a/arch/arm64/kvm/vgic/vgic-mmio-v3.c > +++ b/arch/arm64/kvm/vgic/vgic-mmio-v3.c > @@ -251,45 +251,52 @@ static void vgic_mmio_write_v3r_ctlr(struct kvm_vcpu *vcpu, > vgic_enable_lpis(vcpu); > } > > +static bool vgic_mmio_vcpu_rdist_is_last(struct kvm_vcpu *vcpu) > +{ > + struct vgic_dist *vgic = &vcpu->kvm->arch.vgic; > + struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; > + struct vgic_redist_region *iter, *rdreg = vgic_cpu->rdreg; > + > + if (!rdreg) > + return false; > + > + if (vgic_cpu->rdreg_index < rdreg->free_index - 1) { > + return false; > + } else if (rdreg->count && vgic_cpu->rdreg_index == (rdreg->count - 1)) { > + struct list_head *rd_regions = &vgic->rd_regions; > + gpa_t end = rdreg->base + rdreg->count * KVM_VGIC_V3_REDIST_SIZE; > + > + /* > + * the rdist is the last one of the redist region, > + * check whether there is no other contiguous rdist region > + */ > + list_for_each_entry(iter, rd_regions, list) { > + if (iter->base == end && iter->free_index > 0) > + return false; > + } In the above notes, you state that the region list is now sorted by base address, but I really can't see what sorts that list. And the lines above indicate that you are still iterating over the whole RD regions. It's not a big deal (the code is now simple enough), but that's just to confirm that I understand what is going on here. Thanks, M. -- Without deviation from the norm, progress is not possible.