Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp954350pxu; Wed, 6 Jan 2021 08:36:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJzSi6IsUhRtwL4WXPSNPMvzaCuWFfiB5bnbYCnkwdRdVHIwdLQwy6PLNueWuTGHqyXa+oIT X-Received: by 2002:aa7:c3cd:: with SMTP id l13mr4413066edr.97.1609950998718; Wed, 06 Jan 2021 08:36:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609950998; cv=none; d=google.com; s=arc-20160816; b=J1g93wE4gnsOts+T1ZfwHBOkVdKAX0W2AhRYhhGPzZYjnurtChmhfLP6J+Bzl3dblc D2qxMQln1oX43KzmQWkViUtHVcIMepDTvbp9SGV+I8hHJFIbFYZ2CVQEr0tgEaCvJFQa UMG0+5pTNxR8fNuobsKBnofU0XnN1CvVUxfsqiaE/KqS8McYR8oZMs0Aw4L/bek3zXH5 CfkeK5vJ46vJrZN0fFi1QqLECY5Oosx0e9pS//9EeO2wQUHD1FsqI6Gq2uRwSjWbpuFf UsrhEojYPjB209ufh0iVgZW5QJ3cZZBxIArojJ1kQQ5fwpS2ySb1LHlPCSzvFlbqeq8C Kjhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=zyTBNogjQvRuWvzP5iv4lP0KRz5P+PTrtVZkl/w+qw0=; b=lO8muOiN5CtTin+0ClCVHENTDXfAbOiYFheERV71H08RxPdDqPQcYSPb9rI7RxAfAC y6cQMtJ6535bubWhgmtaidVBY10WWaT+P+/cOtVySvV/+vLW1DAJ0hqKx55OOOHtBZUV JSFxjvPDCOctoFlsGnHJ/Brjelu5WaJ4dXngjlqJJOGi+GB4YLDN2WQIO/EzuMyl0Dyc ZwrG0BrJXFcS4YdThh0ycQ3eQKAEaI9HKK6Gs4bnP53dQ+h8L4SSIiI/eBTXam9fGUNC 3o4cdcLLiOvh6cH0qxqYEAc2PVSnLmXSc+j/Mdof80nx3g/Lg7Cm3S9GRqdaqdZ2FLx7 3SiQ== 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s23si1136629eds.566.2021.01.06.08.36.14; Wed, 06 Jan 2021 08:36:38 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727471AbhAFQdK (ORCPT + 99 others); Wed, 6 Jan 2021 11:33:10 -0500 Received: from foss.arm.com ([217.140.110.172]:43832 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727406AbhAFQdK (ORCPT ); Wed, 6 Jan 2021 11:33:10 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 66309106F; Wed, 6 Jan 2021 08:32:24 -0800 (PST) Received: from [192.168.0.110] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E07033F719; Wed, 6 Jan 2021 08:32:22 -0800 (PST) Subject: Re: [PATCH 1/9] KVM: arm64: vgic-v3: Fix some error codes when setting RDIST base To: Eric Auger , 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: Alexandru Elisei Message-ID: Date: Wed, 6 Jan 2021 16:32:23 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20201212185010.26579-2-eric.auger@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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)? 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. Thanks, Alex > > /* cross the end of memory ? */ > if (base + size < base)