Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp507842pxf; Wed, 7 Apr 2021 05:12:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQsuhwAH8bnzuB2AQy+BFBDDAAPyzVR/2N8Eq2YtyIJV0qqi/tgzWWIJ4tdglkXmv7rGOD X-Received: by 2002:a05:6638:1a6:: with SMTP id b6mr3227020jaq.116.1617797561338; Wed, 07 Apr 2021 05:12:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617797561; cv=none; d=google.com; s=arc-20160816; b=yql+Pvq4QWq7uCoGDY6YZAz9xK+GVEe/yp6Y22Pj4th6ffMBLZCc5SkkxqSwqFpqoo GFG2WnkD8X+8aR1Ez9farq/j+T7xqPNorFwMziaAC+skNcW9Pd8Pdz5iEL0yIT3uFd+u SrY6MmYEPuc5gzVydV5BnfMY4m0bDXg+x5ir5beXs/hr5L1Bc8RC4vy7hA4rMshWWiZU eRkr6PTXb5PnkzNJhW4wxTqeLljh+VkCqjcLpOzCrKhnuxKu5atf1QSD4i0c5nD7ti5d EjPxmHkAkE+qMwcYg5ZNY9xdWmgaPvsXZ13fAqP7Wpz2s5UgoMngVrsyWvsjU+IJbEyL yRQQ== 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:subject:cc:to:from:date :dkim-signature; bh=CdLng19W5LYZEztCULVl6EDAF0QSKZ/kbT35H54v7uo=; b=vvi95+E7QsZSPLKH93mimcTRkMwdkxvj8cKlfcx9Hsg/yR0wF//Cb3mjhFe7wRQPMp RcAdfRv8NxGHbnhSpR6hToaqMqZwvoH61uMkLWFDbW+z2STVkXoJ9hQyDhBYInaiA6XC 3WBeewYtqruDU/28r3OoXNjnvm+w0A21dHN9MQsE2ec4de0SsIlqH/vDQHdT7OsVbp5n +5Ue/t8cliFl/o+mIBOYlz8hCnchQA0amGACbMDFkruWViIY5XfSrcnRzW3HIUCadazT 8/mTyiY+Yd3LnlZG3CPMA6u6nUasNH45berpXhvb2YUoIAWGYrKlbYBHNicEwwu1uU+Z GpDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RWrwgAy4; 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 y5si20780831ilu.35.2021.04.07.05.12.27; Wed, 07 Apr 2021 05:12:41 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RWrwgAy4; 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 S244898AbhDFTiR (ORCPT + 99 others); Tue, 6 Apr 2021 15:38:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35189 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244888AbhDFTiO (ORCPT ); Tue, 6 Apr 2021 15:38:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617737886; 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=CdLng19W5LYZEztCULVl6EDAF0QSKZ/kbT35H54v7uo=; b=RWrwgAy4/bAwGVWSn4JHphGdeFCM0n7D9RA1QGp70sFoUvSZOiPzExVnBQqk1l866rs16x nmC1yGgc/JT1mSACfQWOiNqfHjdvJLGDosLuIeJeVmcDabeT6lMnOkVfeR2MQe1loQEKNe 08NBqcpuX0M+ixPtTUjkJqBOe515WNo= 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-159-HLhu_tLKPZSyNpGWcDPLUA-1; Tue, 06 Apr 2021 15:38:01 -0400 X-MC-Unique: HLhu_tLKPZSyNpGWcDPLUA-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 4B2895B371; Tue, 6 Apr 2021 19:37:57 +0000 (UTC) Received: from omen (ovpn-112-85.phx2.redhat.com [10.3.112.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id D562119D61; Tue, 6 Apr 2021 19:37:56 +0000 (UTC) Date: Tue, 6 Apr 2021 13:37:56 -0600 From: Alex Williamson To: Shenming Lu Cc: Cornelia Huck , , , , Subject: Re: [PATCH v1] vfio/type1: Remove the almost unused check in vfio_iommu_type1_unpin_pages Message-ID: <20210406133756.4520772c@omen> In-Reply-To: <20210406135009.1707-1-lushenming@huawei.com> References: <20210406135009.1707-1-lushenming@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 6 Apr 2021 21:50:09 +0800 Shenming Lu wrote: > The check i > npage at the end of vfio_iommu_type1_unpin_pages is unused > unless npage < 0, but if npage < 0, this function will return npage, which > should return -EINVAL instead. So let's just check the parameter npage at > the start of the function. By the way, replace unpin_exit with break. > > Signed-off-by: Shenming Lu > --- > drivers/vfio/vfio_iommu_type1.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c > index 45cbfd4879a5..fd4213c41743 100644 > --- a/drivers/vfio/vfio_iommu_type1.c > +++ b/drivers/vfio/vfio_iommu_type1.c > @@ -960,7 +960,7 @@ static int vfio_iommu_type1_unpin_pages(void *iommu_data, > bool do_accounting; > int i; > > - if (!iommu || !user_pfn) > + if (!iommu || !user_pfn || npage <= 0) > return -EINVAL; > > /* Supported for v2 version only */ > @@ -977,13 +977,13 @@ static int vfio_iommu_type1_unpin_pages(void *iommu_data, > iova = user_pfn[i] << PAGE_SHIFT; > dma = vfio_find_dma(iommu, iova, PAGE_SIZE); > if (!dma) > - goto unpin_exit; > + break; > + > vfio_unpin_page_external(dma, iova, do_accounting); > } > > -unpin_exit: > mutex_unlock(&iommu->lock); > - return i > npage ? npage : (i > 0 ? i : -EINVAL); > + return i > 0 ? i : -EINVAL; > } > > static long vfio_sync_unpin(struct vfio_dma *dma, struct vfio_domain *domain, Very odd behavior previously. Applied to vfio next branch for v5.13. Thanks, Alex