Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5928712ybl; Tue, 27 Aug 2019 11:43:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqwp1p06+gOnKBHT12DGA/UzD2ZvoEhJ+Z5fQal4xnBfv4aSMOI1OVTAJy5IMJ0Tml+JN+NR X-Received: by 2002:a63:6ec1:: with SMTP id j184mr22538902pgc.232.1566931405547; Tue, 27 Aug 2019 11:43:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566931405; cv=none; d=google.com; s=arc-20160816; b=FV/HgNmeWbV1l0RfEjQI+ckyf3kbGTrO4OJcPK/w+6qODJ1MhQmZ4eSsQCJ0EJBg1q q1aS/bNmCoEapiIWXlYY1UZF0idWC1EorunT+pwUloLGd2s5OrcMfhmEMVUA6HlAMQ6P +RY+lPNrZeeBK8RBC/W8UT6Yxx/tjTmB99o9DIQV36Exm5P1Y8beTh/gQlHp6FrRWnic IXzUWJMWDYgxYNV9R53XwkFK0GLwclHxVAyHmAc79BFrkCIXye6j0TouJb3KiXzn9Sa0 x2squPIqjkKKHl90jegdrxtELGeaNHLKCWocK169cwZTq42MwMyPksbULfIq4hwEqJDI KzNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=AMcn7v/sdTFqGJuC8qbmdz1k2hIwEuJVE1gQDPR3UOo=; b=jxEQGFkupKAHQGudw9C/4St+79AcshWekrM519W7WoDwVV5jMdgpt9v1W9/C/lzAa/ cxeDJAc54T/jFFiyvnJlurkdxA/u1Vxb8YnYUrjKRVShpCnfqZMe8pqSr9GkdKZBRpF6 CTFErKCYwMeFsOQjTR38JB3ky/GWS/SKDsM4Us07yPEIfltDQOTZgG83JzI+0O7Yt7CS rmO7HYZJNuQXeMDuHfVgbuBV68vqElViK5pXYTzQs+mlwvp7lMPn4btxFmUJVy32edc2 0m0ngiyEmcs/5DactmKHZby7nlkPwUG/HuacCc1ssOe4/+5PB2rFm6NMvJjkyUM4uhgC +4qg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b13si80853pgr.460.2019.08.27.11.43.09; Tue, 27 Aug 2019 11:43:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730808AbfH0Skn (ORCPT + 99 others); Tue, 27 Aug 2019 14:40:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:9957 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728312AbfH0Skn (ORCPT ); Tue, 27 Aug 2019 14:40:43 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 847888980EA; Tue, 27 Aug 2019 18:40:42 +0000 (UTC) Received: from x1.home (ovpn-116-99.phx2.redhat.com [10.3.116.99]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F3521001B01; Tue, 27 Aug 2019 18:40:41 +0000 (UTC) Date: Tue, 27 Aug 2019 12:40:41 -0600 From: Alex Williamson To: Ben Luo Cc: cohuck@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] vfio/type1: avoid redundant PageReserved checking Message-ID: <20190827124041.4f986005@x1.home> In-Reply-To: <3e892a6bdaa069a6e79c50208bd01cab8c9588ac.1566910119.git.luoben@linux.alibaba.com> References: <3e892a6bdaa069a6e79c50208bd01cab8c9588ac.1566910119.git.luoben@linux.alibaba.com> Organization: Red Hat 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.67]); Tue, 27 Aug 2019 18:40:42 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 27 Aug 2019 20:49:48 +0800 Ben Luo wrote: > currently, if the page is not a tail of compound page, it will be > checked twice for the same thing. > > Signed-off-by: Ben Luo > --- > drivers/vfio/vfio_iommu_type1.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c > index 054391f..cbe0d88 100644 > --- a/drivers/vfio/vfio_iommu_type1.c > +++ b/drivers/vfio/vfio_iommu_type1.c > @@ -291,11 +291,10 @@ static int vfio_lock_acct(struct vfio_dma *dma, long npage, bool async) > static bool is_invalid_reserved_pfn(unsigned long pfn) > { > if (pfn_valid(pfn)) { > - bool reserved; > struct page *tail = pfn_to_page(pfn); > struct page *head = compound_head(tail); > - reserved = !!(PageReserved(head)); > if (head != tail) { > + bool reserved = !!(PageReserved(head)); > /* > * "head" is not a dangling pointer > * (compound_head takes care of that) > @@ -310,7 +309,7 @@ static bool is_invalid_reserved_pfn(unsigned long pfn) > if (PageTail(tail)) > return reserved; > } > - return PageReserved(tail); > + return !!(PageReserved(tail)); > } > > return true; Logic seems fine to me, though I'd actually prefer to get rid of the !! in the first use than duplicate it at the second use. Thanks, Alex