From mboxrd@z Thu Jan 1 00:00:00 1970 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 D0C0BC433DB for ; Thu, 4 Feb 2021 18:39:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A65B064E06 for ; Thu, 4 Feb 2021 18:39:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238911AbhBDSj1 (ORCPT ); Thu, 4 Feb 2021 13:39:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238506AbhBDSgI (ORCPT ); Thu, 4 Feb 2021 13:36:08 -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 DA6C0C06121F for ; Thu, 4 Feb 2021 10:34:57 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 134so4180765ybd.3 for ; Thu, 04 Feb 2021 10:34:57 -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=6t26rKAvHjVFZcXii/SQ9LPddb8Vo4DY2aiNhPD/qRs=; b=cqkrziIP5zqsbNi+7iPKrIRJFkRc5OoJGU6PPxyXFOvTc5OTgyewUBCxxU7+RiugT2 rLqQmq7zKRktfRXm4KL6H97QyIP8GuCtz0LucRcs4E9xMev4vFQHoC92QvxehmX7JU8U nRhtKwXJoDT4jT0ppA10AMLICawO44OafW3HomNTDDnDn5hBePss1bXwnTI5BEwaCwoT XaZi6GYGz7iW59Coj6CGgt8ir7XbK/7yz6ZwapZMRDI9mX2nxtSjES+HW4yOALhbNCkD YTB9e8wV4XGRRBD07yV9RL4YAkk1rMrOagY8UgbCof4KrLKLBqb9stuDztyc1OMV42Ys /UDw== 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=6t26rKAvHjVFZcXii/SQ9LPddb8Vo4DY2aiNhPD/qRs=; b=I7SwQA5EV5vt+MlXx+zsnnrUnzZxwpPlOnifkJJlpfUBETzsMf6sO0EQ+pFxTKH+AZ 5Tq+F8tyxLWrRDx4VE4orhmWPntJKrvEfUd5eqAZxaJ6NsCpX+1lqyJT7O1P9bvyl2d0 3GhWDTFcVEjqPmI7X9DMDixei3S6o+18l5kitzazgaFgzDPlXHkbLNxEFwyVSl4uYupW WTP4IlZrs5Kd9Nj8ohJ3ONnfpGEUpt35fAxQUXu0B7nEak5FRHEJkTqoyxIv7VMjP+aT oAa1dfWcmcQS1e9Ro98wbWxSJBsq9DXSdgT5DxQDsGu6K6RRbpgfwsOGPZimZqKGcu7p UJ/g== X-Gm-Message-State: AOAM533LFRFIAn2TEfztRHuIAH6//vENmSA3qh9xNwsRpzpoJMpDcFcJ iE6SBCtJC8c1+Zy2pSZ2b7BtB+D9cgLEJqlDlpPz X-Google-Smtp-Source: ABdhPJyaJGA2aAl5NZt4ao326zJOwq4Igh8Fg36gWGJSfGsKs4TIk146f12vqJ/nXSy/hNeR1lumq3NaHFnv9uKgt4+q Sender: "axelrasmussen via sendgmr" X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:b001:12c1:dc19:2089]) (user=axelrasmussen job=sendgmr) by 2002:a25:cb8f:: with SMTP id b137mr841939ybg.312.1612463697102; Thu, 04 Feb 2021 10:34:57 -0800 (PST) Date: Thu, 4 Feb 2021 10:34:30 -0800 In-Reply-To: <20210204183433.1431202-1-axelrasmussen@google.com> Message-Id: <20210204183433.1431202-8-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210204183433.1431202-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.30.0.365.g02bc693789-goog Subject: [PATCH v4 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=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 af40500c99f0..261c3284015d 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 */ int 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 2b6c1c67ee88..868292cf148a 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4647,6 +4647,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. @@ -4777,6 +4778,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, put_page(page); goto out; } +#endif /* CONFIG_USERFAULTFD */ 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 From mboxrd@z Thu Jan 1 00:00:00 1970 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 6897AC433DB for ; Thu, 4 Feb 2021 18:35:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1149264D9A for ; Thu, 4 Feb 2021 18:35:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1149264D9A 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 199236B0073; Thu, 4 Feb 2021 13:34:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0FD8C6B0074; Thu, 4 Feb 2021 13:34:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F2A7F6B0075; Thu, 4 Feb 2021 13:34:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0175.hostedemail.com [216.40.44.175]) by kanga.kvack.org (Postfix) with ESMTP id D7B5F6B0073 for ; Thu, 4 Feb 2021 13:34:58 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9EE1B180AD80F for ; Thu, 4 Feb 2021 18:34:58 +0000 (UTC) X-FDA: 77781437076.11.pies36_0a150fb275de Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id 7EB6A180F8B80 for ; Thu, 4 Feb 2021 18:34:58 +0000 (UTC) X-HE-Tag: pies36_0a150fb275de X-Filterd-Recvd-Size: 7257 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Thu, 4 Feb 2021 18:34:57 +0000 (UTC) Received: by mail-yb1-f201.google.com with SMTP id v17so4164891ybq.9 for ; Thu, 04 Feb 2021 10:34:57 -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=6t26rKAvHjVFZcXii/SQ9LPddb8Vo4DY2aiNhPD/qRs=; b=cqkrziIP5zqsbNi+7iPKrIRJFkRc5OoJGU6PPxyXFOvTc5OTgyewUBCxxU7+RiugT2 rLqQmq7zKRktfRXm4KL6H97QyIP8GuCtz0LucRcs4E9xMev4vFQHoC92QvxehmX7JU8U nRhtKwXJoDT4jT0ppA10AMLICawO44OafW3HomNTDDnDn5hBePss1bXwnTI5BEwaCwoT XaZi6GYGz7iW59Coj6CGgt8ir7XbK/7yz6ZwapZMRDI9mX2nxtSjES+HW4yOALhbNCkD YTB9e8wV4XGRRBD07yV9RL4YAkk1rMrOagY8UgbCof4KrLKLBqb9stuDztyc1OMV42Ys /UDw== 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=6t26rKAvHjVFZcXii/SQ9LPddb8Vo4DY2aiNhPD/qRs=; b=pdyGNHgbff06wHY8nETs7LdoSwxry907E+ezk4YmKLRqZclqa5iA7wmW9Vyhc9stAM tUqYXPfJ52t8sTC4cJTQYaNOR5lLlvEDyBu063KV5lsyRHVY7P8NhKKZW88RRcfSVyVx vgpFJzgdURnh2G5qwH4kpFDcPDcXuCe48jnlDxz+nQaplCnZjtC+BwnvHbfGA/GySxcL OZL5z2QBXczff0uCF4hyo971qn1yzoP0KHgyhSI6VB8Be6eGSLFbPEr/65TM8ZdFymJE CT3d0Gg7mngdBAOnf0ergipLTQ5KvuYCcwh4LxrJXajBNO2rYtnrc51GXlkzFmfWe8QU vNcA== X-Gm-Message-State: AOAM530uarsQ+t+L39SQ66ieKnLy+BiCzw0Smv9bFMNe7jEfWeBKB7qp YDEyXYO2/CeDTcv3tkI98V99e9fxQd+BwEfdhXpW X-Google-Smtp-Source: ABdhPJyaJGA2aAl5NZt4ao326zJOwq4Igh8Fg36gWGJSfGsKs4TIk146f12vqJ/nXSy/hNeR1lumq3NaHFnv9uKgt4+q X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:b001:12c1:dc19:2089]) (user=axelrasmussen job=sendgmr) by 2002:a25:cb8f:: with SMTP id b137mr841939ybg.312.1612463697102; Thu, 04 Feb 2021 10:34:57 -0800 (PST) Date: Thu, 4 Feb 2021 10:34:30 -0800 In-Reply-To: <20210204183433.1431202-1-axelrasmussen@google.com> Message-Id: <20210204183433.1431202-8-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210204183433.1431202-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.30.0.365.g02bc693789-goog Subject: [PATCH v4 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=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" 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 af40500c99f0..261c3284015d 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 */ int 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 2b6c1c67ee88..868292cf148a 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4647,6 +4647,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. @@ -4777,6 +4778,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, put_page(page); goto out; } +#endif /* CONFIG_USERFAULTFD */ 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