Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp726508pxb; Tue, 2 Feb 2021 16:50:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJxTTxzK+R2NcC4bcNaSsK8ULtELw5Vu1W9s3v+bWJElPjT51E7yO2iw7sCOo68AD4UHuSW3 X-Received: by 2002:a17:906:4bc1:: with SMTP id x1mr595731ejv.509.1612313438691; Tue, 02 Feb 2021 16:50:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612313438; cv=none; d=google.com; s=arc-20160816; b=yPKNx/kWTxmRlyYssjZHtJFRMFTWrlZMHeYFNd6dJN6ZIX59OJ97WNiXsrtMqfiLU2 Djri2zxY0bHYlEGaPcdqJDc7rWI8ZOFQaAy6EPEGy8XDLyD70q6l1YZbmq6kA9ziXAP0 J8WL+di5xTVPZj//fB9FS65WQq0GJ8Fj91WBuDopb+Tf6j897HyQoyBqdqKKKwKpKLut nREJoNi2JmrQeLkogcLSZ4/i6i4UmHTFQx+MQI+t/uZ1qf7Ge1bCffSPx5b/Ebqbn7h3 X9OlsvGiG/UoFgCmb58KTnxTI+3DcC/DiZ+6cTclrJWH1/XLIrqJ5+MobH3+ZshgZVlG ggdA== 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:mime-version:message-id:date :sender:dkim-signature; bh=jdyGh3Cr13aO6mxXsMzHUjoD5A4fbl/u70z2sgUvPf0=; b=zg0qGn6H8S8Czzw/Y2eRaSGfXHvop/rJDdVOudBLfn8qsShGtZg0bQggxypuiQJ0se FT+i33Qo3fD0tiNXtSczlr86gauQNXDvGFu+tsGhgw9cpSFIeXKgIu1TOJIL/QsnEmRv HRVnSkPm6qC5GJAlFdJeVrWcJRlMRbbkyA632uPyNDtM0nIRyubqznaxc/B/21HEL1Ka yi0xbHi12ohN7sg8raUQmM8ePMg7T7HLgeUFvixpudwzS9rF8/YCYNLBzd1bNNbzUhso cpGf8fGcDzW5ZO6rxfS0LOcvOe41syI9nQF2UewwpE7xdE1/19XiQTobpxagBetQd9Wz Op0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Lx7QlDEA; 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 r18si305461edi.216.2021.02.02.16.50.14; Tue, 02 Feb 2021 16:50:38 -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=Lx7QlDEA; 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 S231842AbhBBUc2 (ORCPT + 99 others); Tue, 2 Feb 2021 15:32:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231788AbhBBUbu (ORCPT ); Tue, 2 Feb 2021 15:31:50 -0500 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52C21C0613D6 for ; Tue, 2 Feb 2021 12:31:34 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id y34so14979909pgk.21 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=WKoC1Zy5zWgo0bRyD6NNuOr47sctymSqjmAqy0iUvneBTpuJYkw3SagftyODxlJJmw bfI8vcvv2TRWEq4VDSMuCseHnRC7ifMGQSnm/f1rEfCRWk3swzYcyWECt8MITZxdU3rC wG7FfKmXQwDOAzamec+OwQZXJ68uhEVxbhmwbMM6Wx/3GSfkpy+XMAUEC/6w2aLX4cT9 0S3zJo6jKPipt8t62hFNd39vu5RBfK7fG0O5wu7XF9KXKI3DuWS3tkFHHrSkf12DRG2r SwBkDi49zw5K4elTcrd9PCa2YGbcoa6bd/UkI/FHoOB7EINrZwMh/Q1aouLeHfnM+r9y lGug== X-Gm-Message-State: AOAM531/48tCsQLq7IaLyNCIu1BRm0/hrqGDoqzlkN0MoKokSey3C618 fmNFyYVHj8ZGBkKgv3XKlRnUuZMncPOTSF4uUM7p Sender: "axelrasmussen via sendgmr" 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 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 (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 --- 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, -- 2.30.0.365.g02bc693789-goog