Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp165760ybe; Thu, 12 Sep 2019 17:38:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqwmeX83NHoaz39PykMSNOpKKbGsx/lDDjjbuPGQqjrIwKgmR97T4ygm23rK17s5305l/Evf X-Received: by 2002:a50:c90c:: with SMTP id o12mr28664270edh.126.1568335113377; Thu, 12 Sep 2019 17:38:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568335113; cv=none; d=google.com; s=arc-20160816; b=LMBP4CLsGml5T3vhChfxwAvEzRGuC1Py3/ZCgZJSH8HtrecpqLVM/pL+JevjjdRotU QO5SwX58yzRwjIKHSQsvryOCj9VQQ8lSWNtxhUHC/QFGnrVRCTilP58j0C9+RdMD8CwI WKO06Rx/QCDvzp3ahRgB+rL1BVf68j5/kJZcEDEZEngpA3uvE1KS9DhW/uYtlHmWKEcU 4jmBTQX0/b1KaXwU5UaGVxWHdDzgNRVUQ/rnycmdABZ6mTxhj/olm7gvu82ed5rQjjSA i9IcT0+lqkODxIHJz/mwiDbVBSk1ZDTLOcU4ROab/M5g3+i+vwyajuDC5rOq+/8Z74Hb mGsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=9km1FfNMe5AlEoZWaqdQkTneWybkCS71/mUIeBe8tn0=; b=RRNCIMLQsTc8ge5Ah0v1neq2IHYukOjYL8NGeWdrl+juPfnkUhp9trLnwud3tBzlX6 Jd4wmL+i5SBEMCUrZbjByzSp6b2ZyUglVR0iqhvGRKuA7LGs2rIdojEZLwci4+lJ5dFk j1qxFGh1wNmynwnhXbf0hog0Lb06u67QaEnNd/1JCeN/09vSaWazsxnuxpB6Y+pBwdYM lFX42nNK+NNdo+5kIgeVq5TqztVSIaPZkm4p72E1+ScxLA6U8GZ8/NuW7kAeRPQq4D8q xXZmxL0fh65miCxpR10YMnGMkgARt3hxyEkfTWt8IP7581i2nUlO3nfPjDdbcDlvjcu6 2JXw== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z23si13918439eja.368.2019.09.12.17.38.09; Thu, 12 Sep 2019 17:38:33 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728994AbfILViQ (ORCPT + 99 others); Thu, 12 Sep 2019 17:38:16 -0400 Received: from mga18.intel.com ([134.134.136.126]:29755 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728630AbfILViN (ORCPT ); Thu, 12 Sep 2019 17:38:13 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Sep 2019 14:38:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,492,1559545200"; d="scan'208";a="179487181" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by orsmga008.jf.intel.com with ESMTP; 12 Sep 2019 14:31:45 -0700 From: Wei Yang To: viro@zeniv.linux.org.uk Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Wei Yang Subject: [PATCH 3/3] fs/userfaultfd.c: wrap cheching huge page alignment into a helper Date: Fri, 13 Sep 2019 05:31:10 +0800 Message-Id: <20190912213110.3691-3-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190912213110.3691-1-richardw.yang@linux.intel.com> References: <20190912213110.3691-1-richardw.yang@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are three places checking whether one address is huge page aligned. This patch just makes a helper function to wrap it up. Signed-off-by: Wei Yang --- fs/userfaultfd.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 70c0e0ef01d7..d8665ffdd576 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1296,6 +1296,16 @@ static inline bool vma_can_userfault(struct vm_area_struct *vma) vma_is_shmem(vma); } +static inline bool addr_huge_page_aligned(unsigned long addr, + struct vm_area_struct *vma) +{ + unsigned long vma_hpagesize = vma_kernel_pagesize(vma); + + if (addr & (vma_hpagesize - 1)) + return false; + return true; +} + static int userfaultfd_register(struct userfaultfd_ctx *ctx, unsigned long arg) { @@ -1363,12 +1373,8 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx, * If the first vma contains huge pages, make sure start address * is aligned to huge page size. */ - if (is_vm_hugetlb_page(vma)) { - unsigned long vma_hpagesize = vma_kernel_pagesize(vma); - - if (start & (vma_hpagesize - 1)) - goto out_unlock; - } + if (is_vm_hugetlb_page(vma) && !addr_huge_page_aligned(start, vma)) + goto out_unlock; /* * Search for not compatible vmas. @@ -1403,11 +1409,9 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx, * check alignment. */ if (end <= cur->vm_end && is_vm_hugetlb_page(cur)) { - unsigned long vma_hpagesize = vma_kernel_pagesize(cur); - ret = -EINVAL; - if (end & (vma_hpagesize - 1)) + if (!addr_huge_page_aligned(end, cur)) goto out_unlock; } @@ -1551,12 +1555,8 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx, * If the first vma contains huge pages, make sure start address * is aligned to huge page size. */ - if (is_vm_hugetlb_page(vma)) { - unsigned long vma_hpagesize = vma_kernel_pagesize(vma); - - if (start & (vma_hpagesize - 1)) - goto out_unlock; - } + if (is_vm_hugetlb_page(vma) && !addr_huge_page_aligned(start, vma)) + goto out_unlock; /* * Search for not compatible vmas. -- 2.17.1