Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2318818pxu; Sun, 13 Dec 2020 22:07:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJyT0VSa0rHIC9O91ECGYByLGPGVo1aGG4Rz4H/XLTayb8HaRWQV1c2UucGW2hWFopVwVxdy X-Received: by 2002:a50:a692:: with SMTP id e18mr23234036edc.233.1607926074023; Sun, 13 Dec 2020 22:07:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607926074; cv=none; d=google.com; s=arc-20160816; b=fsYVW6Sbgy/oLUMOz9Nflk6cm4VZc8OHLbbGrbJG3o4r1WzUQ5grOcknqvT2IQaIug 349Z47f0QWgAEVNts7diiZitPNk1I1mQmgXSFHqV/jiqXZ70yq/HPfBIohUfn/iUkzRN H0x+9eNIL0zi6Uzim9PFU+7Fl3oacHQXmLyn0FTBuzGDn/0u1noVRaoYy6zGmjoq0K1y HvzdfpnDTludaDHSJFo4snDglzJ2Gdq3bH2a6uzuGFqf3wMnDLKm2QQlolX52fwsS33P E2tRmFpwuo7sda7cqJc7Rb2o72PUsDUER8HDU0OuQV5lCH4x1JtqfQ0gE0xFtiZdqwkw 4MdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CumM37e9oXY+3Aq1rXNKl8pXNhxsyPTexNGxMZe8JOM=; b=xIfz0rVThnVsf2lelb0gtx1mOSORRqTU+NGQ8bCZTAkcRUjdZzCEFHFUVNwulvm1Ta 5ixcRl/Ow+6Ez6MFHfN/8WsX1AasW4/4/O1DfY/vWwL3R2f5fs0zwnktooDkxEwAB3QX b88gKZBCE1wl/pGcbUsoRT7gxqBOK7yCthRdtKaQgCLBsI1AG/lCbulNwzRk04b3rdKm d/er78DeNdNjoOfzqzMKg2zBYpYTmuW7ePrCYF2chnsXWG5qT4lAyQLasy3j0Ly1XKv4 fLHsxvxzvKSQDBqDsFN+Pb5lbS48kAOKV+C3mgoZIDkSMuD1F+pndkWp34KQq86lSW2Y bL7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Zcl3Whxk; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h27si8762365ejl.529.2020.12.13.22.07.30; Sun, 13 Dec 2020 22:07:54 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Zcl3Whxk; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392010AbgLLSyk (ORCPT + 99 others); Sat, 12 Dec 2020 13:54:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:47081 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437618AbgLLSw0 (ORCPT ); Sat, 12 Dec 2020 13:52:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607799060; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CumM37e9oXY+3Aq1rXNKl8pXNhxsyPTexNGxMZe8JOM=; b=Zcl3WhxkQUUWnJyyZSaqbzfIH17bJvnwGCdR+HOGw8X4lpmfXTD7MSAX8xAmiGumO/Omki FGH8cN7rTJZEUqYQgzg5zO1v109VyIsUZ2/SwsbeDhb3m+GFaT/KIgGMLP/MJZbvoFyswV HK23WcCV1SsJ6epIrB93+UoARhZClck= 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-232-UzRCJjvEPDeoKlmfqhJb0w-1; Sat, 12 Dec 2020 13:50:58 -0500 X-MC-Unique: UzRCJjvEPDeoKlmfqhJb0w-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 39D60107ACE3; Sat, 12 Dec 2020 18:50:57 +0000 (UTC) Received: from laptop.redhat.com (ovpn-115-41.ams2.redhat.com [10.36.115.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30E941F069; Sat, 12 Dec 2020 18:50:54 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, maz@kernel.org, drjones@redhat.com Cc: alexandru.elisei@arm.com, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, shuah@kernel.org, pbonzini@redhat.com Subject: [PATCH 8/9] KVM: arm64: vgic-v3: Expose GICR_TYPER.Last for userspace Date: Sat, 12 Dec 2020 19:50:09 +0100 Message-Id: <20201212185010.26579-9-eric.auger@redhat.com> In-Reply-To: <20201212185010.26579-1-eric.auger@redhat.com> References: <20201212185010.26579-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. This patch restores its support (if the redistributor region was set) while keeping the code safe. Signed-off-by: Eric Auger --- arch/arm64/kvm/vgic/vgic-mmio-v3.c | 7 ++++++- include/kvm/arm_vgic.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/vgic/vgic-mmio-v3.c b/arch/arm64/kvm/vgic/vgic-mmio-v3.c index 581f0f490000..2f9ef6058f6e 100644 --- a/arch/arm64/kvm/vgic/vgic-mmio-v3.c +++ b/arch/arm64/kvm/vgic/vgic-mmio-v3.c @@ -277,6 +277,8 @@ static unsigned long vgic_uaccess_read_v3r_typer(struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len) { unsigned long mpidr = kvm_vcpu_get_mpidr_aff(vcpu); + struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; + struct vgic_redist_region *rdreg = vgic_cpu->rdreg; int target_vcpu_id = vcpu->vcpu_id; u64 value; @@ -286,7 +288,9 @@ static unsigned long vgic_uaccess_read_v3r_typer(struct kvm_vcpu *vcpu, if (vgic_has_its(vcpu->kvm)) value |= GICR_TYPER_PLPIS; - /* reporting of the Last bit is not supported for userspace */ + if (rdreg && (vgic_cpu->rdreg_index == (rdreg->free_index - 1))) + value |= GICR_TYPER_LAST; + return extract_bytes(value, addr & 7, len); } @@ -714,6 +718,7 @@ int vgic_register_redist_iodev(struct kvm_vcpu *vcpu) return -EINVAL; vgic_cpu->rdreg = rdreg; + vgic_cpu->rdreg_index = rdreg->free_index; rd_base = rdreg->base + rdreg->free_index * KVM_VGIC_V3_REDIST_SIZE; diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h index a8d8fdcd3723..596c069263a7 100644 --- a/include/kvm/arm_vgic.h +++ b/include/kvm/arm_vgic.h @@ -322,6 +322,7 @@ struct vgic_cpu { */ struct vgic_io_device rd_iodev; struct vgic_redist_region *rdreg; + u32 rdreg_index; /* Contains the attributes and gpa of the LPI pending tables. */ u64 pendbaser; -- 2.21.3