Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp164241pxb; Thu, 14 Jan 2021 02:44:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJzMzZ0T/7mKO9+gmPvCVXGhbq44nZ2gC9cU4yE92jWjWdkkDqmqMcjSpM4V9Z1Pnr9DRdu0 X-Received: by 2002:a17:906:591a:: with SMTP id h26mr4705378ejq.174.1610621048815; Thu, 14 Jan 2021 02:44:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610621048; cv=none; d=google.com; s=arc-20160816; b=CfMUjrlRkDPcrp3FipE0spVET2vLV+86Nz2LMBuqM8ds6sYgXhr5tFI3hx+IfwoqTv NklBIKa6sIrMeeWiFJBp2fyevJrNxh1r3IofzPNb63G4Gw+2LKbtfP5UKcnyB+3OjdZp /UUcKKVw6I582gsYFzUyMwn6SzEhhEJ5Mbbk83UC3yyiLgoPVZLmUAJV7KCI8qTCeh26 FldARjDSeSVmmtnjmA05D1RF5kjp+ffWrb/QsQSQX7vadoj2To3Ijpc0wqsa8DGhBakI Qv95PAyUo2m3fNkp5Ityokqn8oMPlHUtOJx8pjXsc2znunUHh0CLh03AW4xvLraJ495t cKNA== 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=oKdwrjYJNoYhljc3HaThzszr/6Fqa60W1Mc5o3lCwaY=; b=dYP+DNgQa4QXQiKVrdPhdPLh7I3JUX7pu3EW7CsoiSvE5nqsHpOKAuMLx6zf/tPE0a 999qA2guAGPnVRoo3xpFzeE2hjMlnfgjyZo+oOP0KKER5iO0zaSPnd07IzB7SNNJtDDL nXg4zuukLhP2oiDJMLMgfmGZAxkfK8bpnUpv+O+GxG2MyNGd9Uoh8l7H0iaHiQ5C9NNH NxCP0FGpxfYWe++LkhTaI2OkWUFqyDw3icUyTqUNfZJrwjJ16ThtcflU+o7NfIvjV1fm qTvaS/AXvCGcd+KPurxOUr9V3RV1PuobdBhylO3/g7I6mHcBOquUOOr56KZ7VuM46pSu 5tQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HQ2ji2Vv; 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 j4si2169010ejf.307.2021.01.14.02.43.44; Thu, 14 Jan 2021 02:44:08 -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=HQ2ji2Vv; 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 S1728316AbhANKiu (ORCPT + 99 others); Thu, 14 Jan 2021 05:38:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:49518 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727857AbhANKis (ORCPT ); Thu, 14 Jan 2021 05:38:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610620643; 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=oKdwrjYJNoYhljc3HaThzszr/6Fqa60W1Mc5o3lCwaY=; b=HQ2ji2VvDWjnbBi+vGHBLrIvdGQIvFLbazn9PHuZX/DdxsHHp220Y1+BNp84g79guYTLEU gix3k95vWXqHjfBi+CSWZGe3fD2fLExBQV3CQ23acxLGPBsixXVtfJ9sGixOuHjLsaaJkQ 4/ljrRx+ZnJoSTFcl8+ItVfd44v6mWE= 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-314-eE_13MMTPVCU9lBs4wkM2g-1; Thu, 14 Jan 2021 05:37:21 -0500 X-MC-Unique: eE_13MMTPVCU9lBs4wkM2g-1 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 BA3281009456; Thu, 14 Jan 2021 10:37:19 +0000 (UTC) Received: from laptop.redhat.com (ovpn-114-165.ams2.redhat.com [10.36.114.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id E266612D7E; Thu, 14 Jan 2021 10:37:16 +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 v2 1/9] KVM: arm64: vgic-v3: Fix some error codes when setting RDIST base Date: Thu, 14 Jan 2021 11:37:00 +0100 Message-Id: <20210114103708.26763-2-eric.auger@redhat.com> In-Reply-To: <20210114103708.26763-1-eric.auger@redhat.com> References: <20210114103708.26763-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org KVM_DEV_ARM_VGIC_GRP_ADDR group doc says we should return -EEXIST in case the base address of the redist is already set. We currently return -EINVAL. However we need to return -EINVAL in case a legacy REDIST address is attempted to be set while REDIST_REGIONS were set. This case is discriminated by looking at the count field. Signed-off-by: Eric Auger --- v1 -> v2: - simplify the check sequence --- arch/arm64/kvm/vgic/vgic-mmio-v3.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kvm/vgic/vgic-mmio-v3.c b/arch/arm64/kvm/vgic/vgic-mmio-v3.c index 15a6c98ee92f..013b737b658f 100644 --- a/arch/arm64/kvm/vgic/vgic-mmio-v3.c +++ b/arch/arm64/kvm/vgic/vgic-mmio-v3.c @@ -791,10 +791,6 @@ static int vgic_v3_insert_redist_region(struct kvm *kvm, uint32_t index, size_t size = count * KVM_VGIC_V3_REDIST_SIZE; int ret; - /* single rdist region already set ?*/ - if (!count && !list_empty(rd_regions)) - return -EINVAL; - /* cross the end of memory ? */ if (base + size < base) return -EINVAL; @@ -805,11 +801,14 @@ static int vgic_v3_insert_redist_region(struct kvm *kvm, uint32_t index, } else { rdreg = list_last_entry(rd_regions, struct vgic_redist_region, list); - if (index != rdreg->index + 1) - return -EINVAL; - /* Cannot add an explicitly sized regions after legacy region */ - if (!rdreg->count) + if ((!count) != (!rdreg->count)) + return -EINVAL; /* Mix REDIST and REDIST_REGION */ + + if (!count) + return -EEXIST; + + if (index != rdreg->index + 1) return -EINVAL; } -- 2.21.3