From patchwork Tue Feb 2 20:31:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Rasmussen X-Patchwork-Id: 12062835 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.5 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 195A3C433E0 for ; Tue, 2 Feb 2021 20:31:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 82A9364E2A for ; Tue, 2 Feb 2021 20:31:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 82A9364E2A 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 C3C1F6B0005; Tue, 2 Feb 2021 15:31:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BC35A6B0006; Tue, 2 Feb 2021 15:31:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A8BEF6B006C; Tue, 2 Feb 2021 15:31:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0126.hostedemail.com [216.40.44.126]) by kanga.kvack.org (Postfix) with ESMTP id 8C1A86B0005 for ; Tue, 2 Feb 2021 15:31:37 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 41BB4181AEF1D for ; Tue, 2 Feb 2021 20:31:37 +0000 (UTC) X-FDA: 77774473434.05.shelf50_5d058ff275cd Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id 2F1EE1826B6AE for ; Tue, 2 Feb 2021 20:31:37 +0000 (UTC) X-HE-Tag: shelf50_5d058ff275cd X-Filterd-Recvd-Size: 5912 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Tue, 2 Feb 2021 20:31:35 +0000 (UTC) Received: by mail-pf1-f202.google.com with SMTP id z10so4566642pfa.1 for ; Tue, 02 Feb 2021 12:31:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=jdyGh3Cr13aO6mxXsMzHUjoD5A4fbl/u70z2sgUvPf0=; b=Lx7QlDEAghdeRr3SPOTNVhhWEjvAeuC22rYEIbrnDs/W+rluV1hKL9pt0J5PkDt3QJ IxpgiDxcD0FCwGsCAGYFzbvc/R4cb/FBOQBeKErKOgcNdE/P9Ex9kSqh/RGOY+rVRgoJ GzIxMvLtzderd7hFWeBTijeBBcJzWMtku554B0ZtvyI+LweZZQjlrhK7dX7ysWkUKRj9 ZkqyOxjt2fXnhq0wnkpsXiQkEdQmCZcSK+ho1Os89jQKok3uyYI8rgtW6iUaypxWa/lW GDgIHZ1MY+I2kDlde/wGonjrsCpOosUTwHVzBEKGI317ge0Ec4/qDFQHlm8WuOcti6c0 ZLYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=jdyGh3Cr13aO6mxXsMzHUjoD5A4fbl/u70z2sgUvPf0=; b=SCsvWEpUnirFaES2d+pVtxL7oSfTmRV+bGLKTQGhepvPvpwsRcaLi6Eb0fqzVcwA7O nUGn85cFSZmmsLnSOr3UrwtAhEwUrUlJ2g4f8yowtMEF2ZtPY4/xebilJd4tosXTdFKa JF8DGZW8pvg9fi1Oz6BR7ZOHsG/Iot7UlPJtikxzHKN63w5tkWxem3+Mc0AmN00wHhiK DhKYkgpL3FMq9lP1dQ66aeMkbCRg1YPwErIL42E/4GyjWQbydNNyFTfZnoo1u0wtjRXW OMt1VyNCYZjEWKjALiE3of8T+iDdxEknWvMn7zKKYgxTzslNeSiCHNwkcGGzdB8XF55w NwrA== X-Gm-Message-State: AOAM533YMZhMSu21eVcgqV56o0HdoqEuWOI1q617TBcHfloIxL6c5gRh cf2wpZ1l2vIInSFmGjjcJYyFKv/xjJTDkKbTcFza X-Google-Smtp-Source: ABdhPJz/45+MtodomO1H1HLrYkrMbcNcdRpiO0romIzCbIwp4zP8F6N6r+fyux+W7ilB1fwkljmhQcXvPoeihdoTPa3y X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:81fb:f6a4:3e9d:5e8c]) (user=axelrasmussen job=sendgmr) by 2002:a17:902:7408:b029:e1:63d0:75e5 with SMTP id g8-20020a1709027408b02900e163d075e5mr10479761pll.20.1612297893814; Tue, 02 Feb 2021 12:31:33 -0800 (PST) Date: Tue, 2 Feb 2021 12:31:27 -0800 Message-Id: <20210202203127.3596707-1-axelrasmussen@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.30.0.365.g02bc693789-goog Subject: [PATCH] userfaultfd: hugetlbfs: only compile UFFD helpers if config enabled From: Axel Rasmussen To: Andrea Arcangeli , Andrew Morton , Mike Kravetz , Peter Xu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Axel Rasmussen 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 (e.g., 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 this function. 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 future patches (e.g. [1]), we plan to extend the signature of these helpers with UFFD-specific state (e.g., enums or structs defined conditionally in userfaultfd_k.h). Once this happens, this patch will be needed to avoid build errors (or, we'd need to define more UFFD-only stuff unconditionally, which seems messier to me). Peter Xu suggested this be sent as a standalone patch, in the mailing list discussion for [1]. [1] https://patchwork.kernel.org/project/linux-mm/list/?series=424091 Signed-off-by: Axel Rasmussen Reviewed-by: Peter Xu Reviewed-by: Mike Kravetz --- 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 ebca2ef02212..749701b5c153 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 int hugetlb_reserve_pages(struct inode *inode, long from, long to, struct vm_area_struct *vma, vm_flags_t vm_flags); @@ -308,6 +310,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, @@ -318,6 +321,7 @@ static inline int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, BUG(); return 0; } +#endif 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 18f6ee317900..821bfa9c0c80 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4615,6 +4615,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. @@ -4745,6 +4746,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, put_page(page); goto out; } +#endif long follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma, struct page **pages, struct vm_area_struct **vmas,