Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp223340pxb; Thu, 25 Feb 2021 00:17:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJyPUNWcy256aYAlEEi2qFlRRv3rtXPMPVUVB8jWMQU0xVT3LronRmH8J8LKaGaDwd1ygSpF X-Received: by 2002:a17:906:a1c2:: with SMTP id bx2mr1627176ejb.138.1614241069775; Thu, 25 Feb 2021 00:17:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614241069; cv=none; d=google.com; s=arc-20160816; b=VPaV5AQ6OTpcFPo5c4jXlI6t82zQh/ugrQkxAZQGxCkMK/hw8WwoQud6cASuI/qMFK 62zc1NnGkJx3r9iMvZwZn0BFHCqhxJzdeIK1bKEWg2rIsXx3rc4BLlxaMSXa72dCdceO H0jzapYa8XN9vaiDBvysJNXxSw2EVNX2KEptPSbDrBNLgXk/l+DJFLUlndJQUYWlg70I MrMWVxjRElHL2MxyDp0BykRzgYraYomaUNdDYjk4eGOT/s+0X/NubX/LpAFbSo742Wpq JQ5OtdVGO/EkNjsCs/DYqSrXJVdDHG9VOcvcsJ/wXRF69sTlnRiiLJ2I1SXK2FIIEyRN /nPw== 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=szGEt3o0qFpaHEBZZQO0VSXzDMyxQL5PtuhdO6ERPgY=; b=nNSPTap9/MiuHLwWJzcI/uXIaEr+EmacsxqBb+zJWPmlAf/unCUNpgfVNpG2dbugTG jmmYe1mi4BjvxNG9VnY+G9lqLLty6Vy69gIaRs7ptPMNYHZPM4ptBUIcR/4p704kn2zn pnZGjVqU3dXrQDenPpWiqtBKHjS0kzQQ/QmqCwU3c6eYggrRWzkLOzsJPMX3o+JPxc11 ApPZTqZuSa/Ax4787pnsKoo0Ms5fZmmm4Pi35VvdO1sGWolBxdLhD0gMuHJ2VJHNOx/y +6NqPryO+kDwg7Xu6368W3mYAyoZ/LKdpINKdfCnFrKjZwfgv7wfP/3XsAGSzO/UlcLj lo6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Lp3/iorZ"; 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 r21si3121906ejo.142.2021.02.25.00.17.27; Thu, 25 Feb 2021 00:17:49 -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="Lp3/iorZ"; 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 S236429AbhBYA2p (ORCPT + 99 others); Wed, 24 Feb 2021 19:28:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236412AbhBYA2d (ORCPT ); Wed, 24 Feb 2021 19:28:33 -0500 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76311C06178C for ; Wed, 24 Feb 2021 16:27:14 -0800 (PST) Received: by mail-qk1-x749.google.com with SMTP id m16so3147616qkh.20 for ; Wed, 24 Feb 2021 16:27:14 -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=szGEt3o0qFpaHEBZZQO0VSXzDMyxQL5PtuhdO6ERPgY=; b=Lp3/iorZZRf87wK8lw+ZvUPIx9o0DFr4xrVXJ/N3bh/eB45JduZ1xLbUThQmY9bH9i G2nywxd9BVfQG5pYSAKlSiruy7YYsA0r4xLoM5VOCLYVsKIlWubbjGO5KUYeFsFhKV2+ /D/Z8/wLOYmtkejORlwoGRdLixCgthOdd1iUm3GPNYwe1odWflIqdQO51HUeMtZzHJSV ZTpjw+rFWMfB6bF7hVHQS1hl3o3gBQ/L2upx5hUK30AelL7by144ElLjJKR3O4EJVbsl W745ioaG7iRoIUlZYsR2cBHwTUZhEda/ECoLuEZZdC3/39nWSUgITIM7GjDUVCNubZ9K vQPQ== 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=szGEt3o0qFpaHEBZZQO0VSXzDMyxQL5PtuhdO6ERPgY=; b=sUeYkmIirDbwKBbZEHgIAhQWj/bvA8HyDBW6VC5VDoiC2NQfJ1wz0NxkQ4kX0/FVha 3KUyfrcc4CCg5Rl2WOTsv9pYs9fWdZG11xjQ35M91aE6Mg03RxW6s2jBl5BPlEVMyP+1 jHRs27ZVf1N3HoyZbSraz1PlWwrx2sVznh+3gsrw6tYBrmX/VgP/rSmK3faZv479va0U olc6crw7a85EvNyLkU/Ved5sxh/F5//eWg2N1X0i4l+xqILahmkQide0F1v/ptp/+TXh FOkrV6+h/GfyX1nsOHBLv4XDWIQZTgFUd5mFXfDZ8igYNF4JmGMG9CgKXR2Id3o4yAoo o/0A== X-Gm-Message-State: AOAM532ZA3SGDHKtJvN7XbYpeKkXlmQy3Xn5s9UK/GjvAO8XBS19OZhG ep7SS0NE/AAnOPYS+HkSp2Zis89DX8IwfOiiXwzg Sender: "axelrasmussen via sendgmr" X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:a5fd:f848:2fdf:4651]) (user=axelrasmussen job=sendgmr) by 2002:a05:6214:f65:: with SMTP id iy5mr352301qvb.32.1614212833596; Wed, 24 Feb 2021 16:27:13 -0800 (PST) Date: Wed, 24 Feb 2021 16:26:55 -0800 In-Reply-To: <20210225002658.2021807-1-axelrasmussen@google.com> Message-Id: <20210225002658.2021807-4-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210225002658.2021807-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.30.0.617.g56c4b15f3c-goog Subject: [PATCH v8 3/6] 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 ef5b55dbeb9a..7e6d2f126df3 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); @@ -310,6 +312,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, @@ -320,6 +323,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 1d314b769cb5..9f17dc32d88f 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4626,6 +4626,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. @@ -4756,6 +4757,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.617.g56c4b15f3c-goog