Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7660292pxb; Thu, 18 Feb 2021 16:51:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5mDJGi7vrFgtGghmY87zTBrarYgJ5ickwDiMdKE+6flp00PlODPhqILjkO9YPfkIZNppp X-Received: by 2002:a05:6402:d05:: with SMTP id eb5mr6501022edb.143.1613695892550; Thu, 18 Feb 2021 16:51:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613695892; cv=none; d=google.com; s=arc-20160816; b=enVozxeopthNGKTQeYTvwK6W/ABRO+44eglWqRK6zUOWOWFLb+q2pvqJhm+hdaNjT1 LKJOndQu45qkj0Ss2ofZdkXnX/tAxk3co0+YadIKLcBOpvTpBZgsK+pGbuVSmjR6G7aX ToUJ2c9Kd0OrlyuAhFgm28Rz0xI1nBy0Mb1HjreKvNmMTvLFwuvpx7KGGcW5Im48Bcrk 4xwZxfPC8KS4nXepRaz4KyXcJJtht23ZwxIcc58QJdisElsVwvIovao+KnCp5LHlfz1G 0R3QfWz4GV1QVwFQupnUj+cUsR7p9tgRG4h74R/PrL6YJb+GVLO4O6GSJPEw+wMdRjCk IdKA== 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=YLKfreZGzyZ40jYkVyobB++yF7t36mvNO2MMRpwh5Mo=; b=025Dv0WwqFgEdEJpDfTE1dCsGdVZQ3YcJDj6j7QHXQSq68E4Lql+41TeRCRNtFtLAK ctrMDHvy06wHB8FEYoio3X15a+sfSV+k47hvKM8RJEXQXID02jOAdVnU0h9BNnJWk4Xa eqhjWTp1eiWKLRIgljKOiPOBB5v+W3TsQlV32Zz7sW4cI3YU6lxun8EgoFDg9MoTH8pw mlkp0MY2dj1IITVzllXZ+cU1nc2lRo4W/9npF7xV1ItQ8r/HtUE6mg2Rw8qL5m0n0+RC qhEEpdqq7AmcU1uflPm9KJflc1VNsw4RUUKTS3ToQMKoU9ywocLMdZCRXeba3S4BF26B z0/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=F4rL2A2y; 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 bx22si3849591edb.290.2021.02.18.16.51.10; Thu, 18 Feb 2021 16:51:32 -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=F4rL2A2y; 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 S229943AbhBSAuM (ORCPT + 99 others); Thu, 18 Feb 2021 19:50:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229871AbhBSAtx (ORCPT ); Thu, 18 Feb 2021 19:49:53 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 914A9C06178C for ; Thu, 18 Feb 2021 16:48:38 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id f127so4756578ybf.12 for ; Thu, 18 Feb 2021 16:48:38 -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=YLKfreZGzyZ40jYkVyobB++yF7t36mvNO2MMRpwh5Mo=; b=F4rL2A2y6KkWrRZM1eunAfZ6lX3wxUBY3Z5h/OvEQbyVHGWAtW/3Tv7B/CTvrAn88U A8zfJtjMObPSWcfj9JseIqRUr9CRg8KvRJ/3pjfLJ+2n6bVGaqBno1fxQ8EWEH0uWEKw z2yiTf6S2c+20JX3TDyn9BesfjLoAs01udHYlvJgVi+8GxOVQpag3XizNezw2TUslLiA un+PQtagO3sgc8GwBE6h7F7t7Ergl8BWVVhOuhS2b4ScNVTGjKWrZGSL+YdRiLbAnyQs YJ3v2oyDOGE9X3DUEBCdZFyRi75K7lnWpEpx8kHAGI4118OEcF4fi8iyWCsDmYeWfXs1 +p2A== 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=YLKfreZGzyZ40jYkVyobB++yF7t36mvNO2MMRpwh5Mo=; b=J54STd452mGhhtgZTKvQ15v0oyPAG/HBerKm7yMHTSVK5xFno/fJzzvJIoA2zZevq3 3swzaTg3TyhC+mj+qZbGsCZ+CpPFAl3sSL3U0hS98GR3D16MKgY1V1T3QaO8n9wG03Oc dN6Vb2x6SIPSIyQGEVeC++D7Mo8vjRDiuB8ittjKjh3plna3iajEcr05eZe5/4V51QMI 6hkgwjz7Evh63QymwDBZE7sLvv9VaY1yLIbsQBDqBirMG9nhH6Iy8SqAWcemTZk9cb7z tu/UvWuUcbRKRoNRQMOdquFsfkbD3YLAmYKWK5ZSrwxIGHoHFjvmZQQ5Gizvw+p+Vjor d7YA== X-Gm-Message-State: AOAM533HQzeI6ySKPgL/Qqd4q6UAPhXZ/GmHo6qaerAcDvzWdxCNQ25V pIaL0OFo2l1I7hBy+2YeX1Mkm2jsNmYBxk/Y3tA8 Sender: "axelrasmussen via sendgmr" X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:e939:4cce:117:5af3]) (user=axelrasmussen job=sendgmr) by 2002:a25:7784:: with SMTP id s126mr10722976ybc.475.1613695717644; Thu, 18 Feb 2021 16:48:37 -0800 (PST) Date: Thu, 18 Feb 2021 16:48:21 -0800 In-Reply-To: <20210219004824.2899045-1-axelrasmussen@google.com> Message-Id: <20210219004824.2899045-4-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210219004824.2899045-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.30.0.617.g56c4b15f3c-goog Subject: [PATCH v7 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 0388107da4b1..301b6b64c04e 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4624,6 +4624,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. @@ -4754,6 +4755,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