Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5505714ybl; Tue, 27 Aug 2019 05:51:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqwuO7uZS85qS1IpOGhF58GhwKinwglTejQIcZuUt2Y6mRGbygchjCC2bGJia/WzNGrt24Fp X-Received: by 2002:aa7:9393:: with SMTP id t19mr25028579pfe.12.1566910283692; Tue, 27 Aug 2019 05:51:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566910283; cv=none; d=google.com; s=arc-20160816; b=YgrkCDL4bt2bft4PjszILjQ9dKmGnJZ/T8iRJTFHO4XDZSHBsFriDSltVCI2Iu0kkB Icae8MXlwP+6BsfrUPUTPrRKifv58jl47tWzJ0z124G/u8MprGSd8By/WlC11H8LF9WI P77tSw/pqPxFyMqwXR+apS4KQfMFm6faqEwC9S61UUVd/04aTs7ANIqPf/YL80qUIU2e iLJPbRWubkOK9dzjJW0AfM985ZYGzb6oP9Pa9YHJ0oz5hP+Z7FYtRANQUacwkeggJpw3 Jj23dRmT6bSetMTxVisdQjp1ou9WpGE/0tC3YX1VvYJfDLEIp3g4Z5lIMmDUXMyzlllc uPNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=huW+5fYYb6vgXEb4UiFYBGtcXQPU5uNQjGDB8yuKxYg=; b=NgtfAcXS+ZhJQvVimFTNySVpaY1haWKzSiVH/gqNp1JtmAfHxAwvp6W3tgduOvsdh1 MqKDCdbwNHI7o3yYuMNm6cuWvw13Hbhs+k6d4BfQ3veEa2k7wQqYWSemrSUiwcFftIlx 9bqD+/RwrUNN7Q8DP+LBvlKJCjw9OKS0ut6zRyblTt2OTywgpR8yI1reeznirUHJblLi 6BFy6JwXPU/D5aURJIAKKuRYYMGNxqxfHkufAWgeGVEFcvkiKF0CW5uusgBCbRgAaVE/ 5fVHH4in60uG9Ztdj5/iPNhWzJu0BWEcawk+ZW6w6yyWIL3z/dhJVpM9sv5CK9HyAScu ueWg== 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=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f17si12463013plj.17.2019.08.27.05.51.08; Tue, 27 Aug 2019 05:51:23 -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=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729820AbfH0MuF (ORCPT + 99 others); Tue, 27 Aug 2019 08:50:05 -0400 Received: from out30-42.freemail.mail.aliyun.com ([115.124.30.42]:54139 "EHLO out30-42.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726170AbfH0MuF (ORCPT ); Tue, 27 Aug 2019 08:50:05 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04395;MF=luoben@linux.alibaba.com;NM=1;PH=DS;RN=3;SR=0;TI=SMTPD_---0TacAofi_1566910188; Received: from localhost(mailfrom:luoben@linux.alibaba.com fp:SMTPD_---0TacAofi_1566910188) by smtp.aliyun-inc.com(127.0.0.1); Tue, 27 Aug 2019 20:49:54 +0800 From: Ben Luo To: alex.williamson@redhat.com, cohuck@redhat.com Cc: linux-kernel@vger.kernel.org Subject: [PATCH] vfio/type1: avoid redundant PageReserved checking Date: Tue, 27 Aug 2019 20:49:48 +0800 Message-Id: <3e892a6bdaa069a6e79c50208bd01cab8c9588ac.1566910119.git.luoben@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 1.8.3.1