Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3271770pxb; Fri, 12 Feb 2021 13:58:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJxlU3D9Yn38Q7W5dKJUntLRhO0gCbU19w54UrHk7HCFaKrUpSIJW2wOsgsR0MRll6dVAXnz X-Received: by 2002:a17:907:7605:: with SMTP id jx5mr5103595ejc.340.1613167132233; Fri, 12 Feb 2021 13:58:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613167132; cv=none; d=google.com; s=arc-20160816; b=LYQ+ifK2Ij4bu7KNNue2vQDA5o7qg6+vP5+lC1M9FrLdPiLDCXY9peRL719vRFeBsS db+5Vqe6J7PCKuokDj8tzNMXIPYSaW8d4jMJ4zGGZkzGVNIovKt3wd2PWoWaTz7g3nOH R7wiVVD7CZ7aKziLRrngw4Ez1EK8sUtxae18LVGt735tkIRN7GYgi+US8c++YsQu5nV/ KDwDQrC81QLGydqmHI4xBT8XjRbBMyW8FDDWe671FPtC2xE0x5GsV5wiZpbgLx8psqXQ aOqqiYVOqhz9q6s9nu3NmYa9YCLESNAjstxUgfERKeqESNDF4f9JkTA+ZQUuy0bnGkjq eAqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=LiVtqkhHz/r4Zeb2EoTFGJ4n9HyxABq0yJQZLNwm2Q8=; b=y9V/4WxVfkVGaEtoBwmSU9DGY+P6541i0cqzkn7dUTy5g263fndeGcq/I+bEea+iGG 9wl8+/V4nJtQDLxoDnT7II7LWO56n+p70GMTK5cufKT2FMESRa5HOx3UrW78fRukRQTL CHKf70E0nP7kX1Ang8lL0PnPRtIaJ544Rs8pELDTYp05xqg8WJ0ErFfYoGyE1sn6bHGz OFz/W5TlyFEt68TRhf4uxk5STrySpoiw2llB1RS2Po4mHGouQStrEj60XatyOQxKG9cl KoHEq1Cy+YEOczzZ2Cx6o0zFWwOOK2rb+bdbgaIpQmDM2H8oEBsj9LhaHGJxIteRWQpR q/Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=O7vBRrIx; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q27si7000263eja.338.2021.02.12.13.58.28; Fri, 12 Feb 2021 13:58:52 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=O7vBRrIx; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231388AbhBLV4P (ORCPT + 99 others); Fri, 12 Feb 2021 16:56:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230421AbhBLVzi (ORCPT ); Fri, 12 Feb 2021 16:55:38 -0500 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 468BFC06178C for ; Fri, 12 Feb 2021 13:54:25 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id u14so702546plf.4 for ; Fri, 12 Feb 2021 13:54:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=LiVtqkhHz/r4Zeb2EoTFGJ4n9HyxABq0yJQZLNwm2Q8=; b=O7vBRrIx5Dz4nWqloIt5jjd55w0xsLnlt0ZDfNUqgpCSKytSZeYWl0eBlXJzeWpeRO mscnUD5ciEeVnFWj+vELioxHhbcdFk8ZcE4meUV7GbG7ACQ9UbH9iHAy7dTBR40KHQN5 P0hsB2ltoSujvseIWy6uirjIjIg4naFd/PpA4y8/OsQjCl3eTn+PF4YA7JYYQgBZNuWd +fufUKzyhCpmV5A54qOsXjtQjiaEHdyjh5wo/oIisoos1/fGTY6VrO+T/UrFGDo4JKnK tQPUFUk28KtNK14EG6HH21RO5ZAJLF4s/Zb1WVduHQCLGjGSRkFjoI20fT39Bjs8h2ci 2C7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=LiVtqkhHz/r4Zeb2EoTFGJ4n9HyxABq0yJQZLNwm2Q8=; b=HFQJTz6XIPzmtnqtxPSamjucFeIwL4xijzhIz/mefYgXiZj1qeqfnDFZ4PSGrgUQba DipWNOIhjfmA87Oe7amvhDhxMHnLf7oMmvLSQ8GJJ+NJy+0qFcyeO147InEcZMRBxbRT RexwfBj/l+nONbk4seR0rT4Y76jI1bXSM+TPiQ6Qgf5d7EAbg207Eu6c/Bzc9k+yJAJG 9Mimo8PHJC/VKagdFqQH9K7FtpncGQXWToTMCU5cHbqZzeforlgAuXftSOAHzNB4cwlX tK6YrRUdXkW9sRFnWYvi4/aOriX/327q0VPJqRCApojF8M4nEUDAyjTPHJ+lsXz6gyzk ifvQ== X-Gm-Message-State: AOAM532oiy0OJE+abzVr958QfRv7Oa5QBzKF8yfIUbifMk9KHIwcjqqT O6EcHDzpto7mQZOGjNq7nxpDykkvOQ7jfM9JLJQd Sender: "axelrasmussen via sendgmr" X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:d2f:99bb:c1e0:34ba]) (user=axelrasmussen job=sendgmr) by 2002:a17:90a:8c18:: with SMTP id a24mr2543745pjo.218.1613166864656; Fri, 12 Feb 2021 13:54:24 -0800 (PST) Date: Fri, 12 Feb 2021 13:54:00 -0800 In-Reply-To: <20210212215403.3457686-1-axelrasmussen@google.com> Message-Id: <20210212215403.3457686-5-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210212215403.3457686-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH v6 4/7] userfaultfd: hugetlbfs: only compile UFFD helpers if config enabled From: Axel Rasmussen To: Alexander Viro , Alexey Dobriyan , Andrea Arcangeli , Andrew Morton , Anshuman Khandual , Catalin Marinas , Chinwen Chang , Huang Ying , Ingo Molnar , Jann Horn , Jerome Glisse , Lokesh Gidra , "Matthew Wilcox (Oracle)" , Michael Ellerman , "=?UTF-8?q?Michal=20Koutn=C3=BD?=" , Michel Lespinasse , Mike Kravetz , Mike Rapoport , Nicholas Piggin , Peter Xu , Shaohua Li , Shawn Anastasio , Steven Rostedt , Steven Price , Vlastimil Babka Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Adam Ruprecht , Axel Rasmussen , Cannon Matthews , "Dr . David Alan Gilbert" , David Rientjes , Mina Almasry , Oliver Upton Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For background, mm/userfaultfd.c provides a general mcopy_atomic implementation. But some types of memory (i.e., hugetlb and shmem) need a slightly different implementation, so they provide their own helpers for this. In other words, userfaultfd is the only caller of these functions. This patch achieves two things: 1. Don't spend time compiling code which will end up never being referenced anyway (a small build time optimization). 2. In patches later in this series, we extend the signature of these helpers with UFFD-specific state (a mode enumeration). Once this happens, we *have to* either not compile the helpers, or unconditionally define the UFFD-only state (which seems messier to me). This includes the declarations in the headers, as otherwise they'd yield warnings about implicitly defining the type of those arguments. Reviewed-by: Mike Kravetz Reviewed-by: Peter Xu Signed-off-by: Axel Rasmussen --- include/linux/hugetlb.h | 4 ++++ mm/hugetlb.c | 2 ++ 2 files changed, 6 insertions(+) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index d740c6fd19ae..aa9e1d6de831 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -134,11 +134,13 @@ void hugetlb_show_meminfo(void); unsigned long hugetlb_total_pages(void); vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long address, unsigned int flags); +#ifdef CONFIG_USERFAULTFD int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, pte_t *dst_pte, struct vm_area_struct *dst_vma, unsigned long dst_addr, unsigned long src_addr, struct page **pagep); +#endif /* CONFIG_USERFAULTFD */ bool hugetlb_reserve_pages(struct inode *inode, long from, long to, struct vm_area_struct *vma, vm_flags_t vm_flags); @@ -309,6 +311,7 @@ static inline void hugetlb_free_pgd_range(struct mmu_gather *tlb, BUG(); } +#ifdef CONFIG_USERFAULTFD static inline int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, pte_t *dst_pte, struct vm_area_struct *dst_vma, @@ -319,6 +322,7 @@ static inline int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, BUG(); return 0; } +#endif /* CONFIG_USERFAULTFD */ static inline pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr, unsigned long sz) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 93307fb058b7..37b9ff7c2d04 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4638,6 +4638,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, return ret; } +#ifdef CONFIG_USERFAULTFD /* * Used by userfaultfd UFFDIO_COPY. Based on mcopy_atomic_pte with * modifications for huge pages. @@ -4768,6 +4769,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, put_page(page); goto out; } +#endif /* CONFIG_USERFAULTFD */ static void record_subpages_vmas(struct page *page, struct vm_area_struct *vma, int refs, struct page **pages, -- 2.30.0.478.g8a0d178c01-goog