From patchwork Wed Feb 10 21:21:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Rasmussen X-Patchwork-Id: 12081799 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07974C433E6 for ; Wed, 10 Feb 2021 21:22:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ACCBE64ED0 for ; Wed, 10 Feb 2021 21:22:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ACCBE64ED0 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 412EE8D0001; Wed, 10 Feb 2021 16:22:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3847A6B0081; Wed, 10 Feb 2021 16:22:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 10C7A8D0001; Wed, 10 Feb 2021 16:22:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0199.hostedemail.com [216.40.44.199]) by kanga.kvack.org (Postfix) with ESMTP id DB9706B007E for ; Wed, 10 Feb 2021 16:22:21 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id A294F1261E for ; Wed, 10 Feb 2021 21:22:21 +0000 (UTC) X-FDA: 77803631682.11.glass30_061195b27613 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id 7BF1E18233674 for ; Wed, 10 Feb 2021 21:22:21 +0000 (UTC) X-HE-Tag: glass30_061195b27613 X-Filterd-Recvd-Size: 7245 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Wed, 10 Feb 2021 21:22:20 +0000 (UTC) Received: by mail-yb1-f202.google.com with SMTP id u17so3935623ybi.10 for ; Wed, 10 Feb 2021 13:22:20 -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=LwH+hfZPM+jVaAvlEL06OqVkbSlUL6Tgir5CZCKVHkU=; b=CJaq+ppVANH85LoaHTydYsQP+8qhXAc7DrD4fdpFizDt2IgpDk7qxVTivgjvFVHaAn hIqSZ/ibeEDQ4RVZW+7QRBAb2qq/Zph49sd705AweyTTZV/ICBugKHxkGbiezRL1Jw+2 uO3gZmePfbnjcXyjnht/ayrxZZi3cADuKTGZCoeBMTwdLUDemTKeX0FNnBX5sOQmwkb3 kZNi3Y9/Oagf58q7kagO2ju36xQkCffTD97vTha4xtJdQKiL4o/ji26wiMYbKVBFfcvE f7igf8zpRTvJnxfDcdxk+FF8JfVWJfE1hXwaT6QvlRd/h62QlrqCrFGNkNLD3arlOMYf fJdA== 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=LwH+hfZPM+jVaAvlEL06OqVkbSlUL6Tgir5CZCKVHkU=; b=TdSe8d162hSIQPbis5efVYv2XgvjmCsZufh40Sk12upXpkegfvnbP/KZlybYT5Bq9n 2nobc2tbIlI6ZSwYeRVBbzkyAzqemQWEtrqIc4aDgq8oq4ho0EIkpyiIL2y76IxFkmjA bCWCoOxhOkQhmMtRldymeBs+QGFJJ9q2LSZ3zZpfivBC8rmhBKWN7VojZ5GWwCF7k9fv 7hBA2se3xKScfY/GhQfLDvXe1yvcQqPw/CbAtWwYnvxtRsZmmHD7zfMD3Qv14vr9fbvI oFqO4/q/wGZg3mFCtTA0ZRq//H/0i5Xw9cYgMHdYj4yMgSIV/PJmIr6yrE4dnM/RsKLj lHmg== X-Gm-Message-State: AOAM531Br6HD/YDErRLaOuU4UoEZfnq2z4JL52724tUHcd7HOJthLpWn 1NnavJsFZwfTIOB4k3ovKo+dMbmhENnV825WW3RX X-Google-Smtp-Source: ABdhPJyyOu+evzNPJIKXPNB23IlLnIR5tDerndgDK9uc4DM87em2C9Af400s2pIB0TmS4jGuHqFYrYvdw49B/vh4BiM0 X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:94ee:de01:168:9f20]) (user=axelrasmussen job=sendgmr) by 2002:a25:25cd:: with SMTP id l196mr6561637ybl.433.1612992140166; Wed, 10 Feb 2021 13:22:20 -0800 (PST) Date: Wed, 10 Feb 2021 13:21:57 -0800 In-Reply-To: <20210210212200.1097784-1-axelrasmussen@google.com> Message-Id: <20210210212200.1097784-8-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210210212200.1097784-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH v5 07/10] 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_Koutn=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 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 f150b10981a8..2331281cf133 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,