Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp145543pxb; Thu, 14 Jan 2021 02:06:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJz4pV/jgcANK8eIqRBW0hC/xXRSZHWcCRrZ4O36j5fU4wqKI/z1ctX1fzAA0qPni8u39XR/ X-Received: by 2002:a05:6402:ca2:: with SMTP id cn2mr5106716edb.137.1610618817173; Thu, 14 Jan 2021 02:06:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610618817; cv=none; d=google.com; s=arc-20160816; b=c+4R2+f2nDxmXMNLau6tgzRleC1qpz5vrPGB8YMqx73q9Dh+jzWn28k5r+jceWuIBm LHbm0SJjb1gegmCxSWpqoHptTZPIIJk5xr5acN+rw+7/kdFVmRU2Ny+DHt5Hoa4ao9y5 qQxazFI95Ts5VuDvJ9g0/qPv26xj/MRoIu1RYOgTwyiP8Bw46te4Th402ARvxoJeiGyu GHEpoy4/GrtUuz/XN8ESylRo2w5dP9pGcorx6ETJFgm4QwKVAU4cDJV4tOa1UdcbSPLI ocVu6mAlRCgozMrusDoc0egP43nfeIJiIMj/7CpuzM//68PXsqfHuLijpo8GXQtCofMI jcoQ== 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:dkim-signature; bh=xXjNcBX1zyUVY22wn0iABMXWOTnE52HCbnMakakpYNA=; b=PBOcSLZRi54UZOedqVnwZDJ/hQ9hJsZJet1vd8Bw/vUzXTaY2MFqaZff0GYS9k/Alx rGcRO/uwLWLl19bdNDrCNAZFFMhn538aVCVh+rNXXJp/lQlKgqCxy0+4a+5P4dOKZ3VV HLeQTiLPQkyRHMdjsMg4RhSeNAxrwD9YAKH2txwk8c4JCgGjlOG4yc5ciUPGlmnOTZtg 92fSPokReHFjeOjQUvDRE//bKLHK8eePwl6zJR5fMxae+nIxWfnuhUiIM/m/IyyEV9U4 XbNKFZ9eVGKDIkK5wrm2OAUbcazXXcq87QziS3J97Tet5CgF7jC5mpgXC07bk+UV4wU2 jyQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VbclXDgS; 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 go33si2172156ejc.40.2021.01.14.02.06.27; Thu, 14 Jan 2021 02:06:57 -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=VbclXDgS; 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 S1728514AbhANKEc (ORCPT + 99 others); Thu, 14 Jan 2021 05:04:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:48474 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728480AbhANKEa (ORCPT ); Thu, 14 Jan 2021 05:04:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610618585; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xXjNcBX1zyUVY22wn0iABMXWOTnE52HCbnMakakpYNA=; b=VbclXDgS+vYtvlz0BJpIzzWF5fgZeSdow1f22alM95qhiKV4/xEYBIARk0vke0TVgajNy+ 7PoedDtagvdUTA6e/Jb7Ey9voeHx6FDIL0G1U4CFOPrLuDTXfpDX9hdgDfhIfoYXbI4v5J 45Q7FHYvbuSdTiqu1ukbQsUYExgt8/o= 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-348-p58qiEhWMVmNF5ryZwfFhw-1; Thu, 14 Jan 2021 05:03:01 -0500 X-MC-Unique: p58qiEhWMVmNF5ryZwfFhw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8338084A5E8; Thu, 14 Jan 2021 10:02:59 +0000 (UTC) Received: from [10.36.114.165] (ovpn-114-165.ams2.redhat.com [10.36.114.165]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B7CBF71D60; Thu, 14 Jan 2021 10:02:56 +0000 (UTC) Subject: Re: [PATCH 1/9] KVM: arm64: vgic-v3: Fix some error codes when setting RDIST base To: Alexandru Elisei , eric.auger.pro@gmail.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, maz@kernel.org, drjones@redhat.com Cc: james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, shuah@kernel.org, pbonzini@redhat.com References: <20201212185010.26579-1-eric.auger@redhat.com> <20201212185010.26579-2-eric.auger@redhat.com> From: Auger Eric Message-ID: Date: Thu, 14 Jan 2021 11:02:55 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Alexandru, On 1/6/21 5:32 PM, Alexandru Elisei wrote: > Hi Eric, > > On 12/12/20 6:50 PM, Eric Auger wrote: >> 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 >> --- >> arch/arm64/kvm/vgic/vgic-mmio-v3.c | 9 +++++++-- >> 1 file changed, 7 insertions(+), 2 deletions(-) >> >> diff --git a/arch/arm64/kvm/vgic/vgic-mmio-v3.c b/arch/arm64/kvm/vgic/vgic-mmio-v3.c >> index 15a6c98ee92f..8e8a862def76 100644 >> --- a/arch/arm64/kvm/vgic/vgic-mmio-v3.c >> +++ b/arch/arm64/kvm/vgic/vgic-mmio-v3.c >> @@ -792,8 +792,13 @@ static int vgic_v3_insert_redist_region(struct kvm *kvm, uint32_t index, >> int ret; >> >> /* single rdist region already set ?*/ >> - if (!count && !list_empty(rd_regions)) >> - return -EINVAL; >> + if (!count && !list_empty(rd_regions)) { >> + rdreg = list_last_entry(rd_regions, >> + struct vgic_redist_region, list); >> + if (rdreg->count) >> + return -EINVAL; /* Mixing REDIST and REDIST_REGION API */ >> + return -EEXIST; >> + } > > A few instructions below: > >     if (list_empty(rd_regions)) { >         [..] >     } else { >         rdreg = list_last_entry(rd_regions, >                     struct vgic_redist_region, list); >         [..] > >         /* Cannot add an explicitly sized regions after legacy region */ >         if (!rdreg->count) >             return -EINVAL; >     } > > Isn't this testing for the same thing, but using the opposite condition? Or am I > misunderstanding the code (quite likely)? the 1st test sequence handles the case where the legacy KVM_VGIC_V3_ADDR_TYPE_REDIST is used (!count) while the second handles the case where the REDIST_REGION is used. Nevertheless I think this can be simplified into: if (list_empty(rd_regions)) { if (index != 0) return -EINVAL; } else { rdreg = list_last_entry(rd_regions, struct vgic_redist_region, list); if ((!count) != (!rdreg->count)) return -EINVAL; /* Mix REDIST and REDIST_REGION */ if (!count) return -EEXIST; if (index != rdreg->index + 1) return -EINVAL; } > > Looks to me like KVM_DEV_ARM_VGIC_GRP_ADDR(KVM_VGIC_V3_ADDR_TYPE_REDIST{,_REGION}) > used to return -EEXIST (from vgic_check_ioaddr()) before commit ccc27bf5be7b7 > ("KVM: arm/arm64: Helper to register a new redistributor region") which added the > vgic_v3_insert_redist_region() function, so bringing back the -EEXIST return code > looks the right thing to me. OK thank you for the detailed study. Eric > > Thanks, > Alex >> >> /* cross the end of memory ? */ >> if (base + size < base) >