Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2985272rdb; Wed, 15 Nov 2023 17:30:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IFtLJqHSevGduYV8PVBIVVMNKFdNQNU5n2jcfMJlHy7KHfi94xIWkuGk5cSgYC1ngZYZESo X-Received: by 2002:a05:6a20:8e10:b0:181:a9b6:8883 with SMTP id y16-20020a056a208e1000b00181a9b68883mr14802634pzj.35.1700098256260; Wed, 15 Nov 2023 17:30:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700098256; cv=none; d=google.com; s=arc-20160816; b=jYfWjL2jr2jy9M7xKJSXzINcvQ5/YUX755a+Ca1hHGcbYwmV2TQZRJ1r2jXaIJfUDO SZFf4JtwFjLQPTCKIyhosHqsT+p1IPfJgWt3ngfJrGpaYjEQaWJbinvcg/IO3499rN5P uAUO6HFbgJXALd8MKrzKDqHBRKgLCF7MIaBJ6FBhv4vvCjeLGLnkAQRuwSQ9uUD1mCsf oP9sKZrFI8rHffuWxTVmq3WETJOSFdNvcKecB112ZE86ixc9l18Kj3HoneKmjCiK6CJ7 8Bcw7bT+07Sc/BaKBrGByAN0GHApVINMjJDVxOvNQShZya1KKe2Xn9KUMPXN9juwBGwQ CDPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=k0e00AejVp7ba16+GtnRW4DXLpdJhvAKN3LJp7S4MZU=; fh=o+FJD7UTEFgAOwGBZppViFyhRpBzPGRfoO/6xzRNnMs=; b=guHrG4Sru249bz4lTFWgv4tirTPeRqGmUSH7GP1hNNPE8/12XIbmGKG7q22CYgxIIL yDlOpPl7JeKd/5hFhWK9wUtm8KJni0ukjiuAQHdVlBAfl2KC3GuEiHQVCuIXq8eXXg1v 9gBckHCQmCQkfbvObVgNxvVnIHu1pItWS2PLR+GXUJO0e99lmXhT0g5+ND/GVET4gG5N DySCMCtk7E1CvE6115yxb/G7pbN4JY1bNFJ9CqCk3vHELK4sM5MfLJc2Qv7fY1/mrmtW n56fAIAFeBAJJgeDXQ69trY44NW42W2tOcZOXwSTNzzMa43fCMN6/rhXkzgvYykXAv/d Bdaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=emhn3xMi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id ca34-20020a056a0206a200b005b909e678dfsi11784044pgb.450.2023.11.15.17.30.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 17:30:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=emhn3xMi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 2AD1F80698D1; Wed, 15 Nov 2023 17:30:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344534AbjKPBaP (ORCPT + 99 others); Wed, 15 Nov 2023 20:30:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344522AbjKPB35 (ORCPT ); Wed, 15 Nov 2023 20:29:57 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEEC01998 for ; Wed, 15 Nov 2023 17:29:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700098174; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k0e00AejVp7ba16+GtnRW4DXLpdJhvAKN3LJp7S4MZU=; b=emhn3xMiKf8ctbhmkRjms69Nrxdm/+sdzlZElYnyd4aFAdu44akvpFO/Pbl+JJDDUoLXqx 3lAQ7Bq4N3RcuVQef3m5CXh6zrl2od9uQrTpt8U9BXBMhpfk/zJsImNPlRtUoyIqfc2F7a L6Hho4CKRyk4XPsUd93H7nSRzO8qjFU= Received: from mail-vs1-f71.google.com (mail-vs1-f71.google.com [209.85.217.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-385-0dE_vhAMM6SblPENVDGvlw-1; Wed, 15 Nov 2023 20:29:33 -0500 X-MC-Unique: 0dE_vhAMM6SblPENVDGvlw-1 Received: by mail-vs1-f71.google.com with SMTP id ada2fe7eead31-46107bc7936so12697137.1 for ; Wed, 15 Nov 2023 17:29:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700098171; x=1700702971; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k0e00AejVp7ba16+GtnRW4DXLpdJhvAKN3LJp7S4MZU=; b=UyCkTtwkEgkbc3eMSRFpITGAXUFtSNRDgLZH0w6L8HfhPR7Vjl3SdjvKOFNGv6JyX8 ZAATQT7XOWLu1w4SUhFfZt9/7RhK/8yycZG/jMyuri53fZ7OtIr+X0EzL+dngRPxHnu1 dK/4LzSh1Ppb9XpBRhfhr6oZDGz0ZMKJ5t60Vgwe3E0Dr9dSW6zc+HjhSImFRyv2egCX HrCrueFi4FzIMWV9VCoruxIP8KbQtqXxjDnSkLvUL7SD8KexEySOC/ESwZ9+zL4O9FPK 0HrhEZUgL/5Bv4Ewf29f3wswWeM4w2LIMY+3f6zLcu5rgw/Z/phgUbjtPaaAjfKwWHVk 4hhQ== X-Gm-Message-State: AOJu0YzsEHgzsUQYqOPyxXRGPyFvX99qU8mMInbHnD8jaZSNoc9EJ4NL KsMX6KLdP37RY/ajGhd6+RMGBER8U4OVcY+o0pa7QgcVCLfcnI6GWh0sD6NMkWj8aC0HDlb7p1b g0b08DkNxYg83gyHktNE8JTGDzJl9a3Dtlx1mEwxHzUnFELmkScyUby1y/yrRmyeV1VD2Ybe32e fDRVonpg== X-Received: by 2002:a1f:a017:0:b0:4ac:3694:7011 with SMTP id j23-20020a1fa017000000b004ac36947011mr7269398vke.0.1700098171317; Wed, 15 Nov 2023 17:29:31 -0800 (PST) X-Received: by 2002:a1f:a017:0:b0:4ac:3694:7011 with SMTP id j23-20020a1fa017000000b004ac36947011mr7269371vke.0.1700098170969; Wed, 15 Nov 2023 17:29:30 -0800 (PST) Received: from x1n.redhat.com (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id c24-20020ac85198000000b0041e383d527esm3922598qtn.66.2023.11.15.17.29.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 17:29:30 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , "Kirill A . Shutemov" , Lorenzo Stoakes , Axel Rasmussen , Matthew Wilcox , John Hubbard , Mike Rapoport , peterx@redhat.com, Hugh Dickins , David Hildenbrand , Andrea Arcangeli , Rik van Riel , James Houghton , Yang Shi , Jason Gunthorpe , Vlastimil Babka , Andrew Morton Subject: [PATCH RFC 12/12] mm/gup: Merge hugetlb into generic mm code Date: Wed, 15 Nov 2023 20:29:08 -0500 Message-ID: <20231116012908.392077-13-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231116012908.392077-1-peterx@redhat.com> References: <20231116012908.392077-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SORBS_WEB,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 15 Nov 2023 17:30:50 -0800 (PST) Now follow_page() is ready to handle hugetlb pages in whatever form, and over all architectures. Switch to the generic code path. Time to retire hugetlb_follow_page_mask(), following the previous retirement of follow_hugetlb_page() in 4849807114b8. There may be a slight difference of how the loops run when processing GUP over a large hugetlb range on either ARM64 (e.g. CONT_PMD) or RISCV (mostly its Svnapot extension on 64K huge pages): each loop of __get_user_pages() will resolve one pgtable entry with the patch applied, rather than relying on the size of hugetlb hstate, the latter may cover multiple entries in one loop. However, the performance difference should hopefully not be a major concern, considering that GUP just yet got 57edfcfd3419 ("mm/gup: accelerate thp gup even for "pages != NULL""), and that's not part of a performance analysis but a side dish. If the performance will be a concern, we can consider handle CONT_PTE in follow_page(), for example. Before that is justified to be necessary, keep everything clean and simple. Signed-off-by: Peter Xu --- include/linux/hugetlb.h | 7 ---- mm/gup.c | 15 +++------ mm/hugetlb.c | 71 ----------------------------------------- 3 files changed, 5 insertions(+), 88 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index bb07279b8991..87630a185acf 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -332,13 +332,6 @@ static inline void hugetlb_zap_end( { } -static inline struct page *hugetlb_follow_page_mask( - struct vm_area_struct *vma, unsigned long address, unsigned int flags, - unsigned int *page_mask) -{ - BUILD_BUG(); /* should never be compiled in if !CONFIG_HUGETLB_PAGE*/ -} - static inline int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, struct vm_area_struct *dst_vma, diff --git a/mm/gup.c b/mm/gup.c index e635278f65f9..23fcac5aa3db 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -830,18 +830,11 @@ static struct page *follow_page_mask(struct vm_area_struct *vma, { pgd_t *pgd, pgdval; struct mm_struct *mm = vma->vm_mm; + struct page *page; - ctx->page_mask = 0; - - /* - * Call hugetlb_follow_page_mask for hugetlb vmas as it will use - * special hugetlb page table walking code. This eliminates the - * need to check for hugetlb entries in the general walking code. - */ - if (is_vm_hugetlb_page(vma)) - return hugetlb_follow_page_mask(vma, address, flags, - &ctx->page_mask); + vma_pgtable_walk_begin(vma); + ctx->page_mask = 0; pgd = pgd_offset(mm, address); pgdval = *pgd; @@ -853,6 +846,8 @@ static struct page *follow_page_mask(struct vm_area_struct *vma, else page = follow_p4d_mask(vma, address, pgd, flags, ctx); + vma_pgtable_walk_end(vma); + return page; } diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 29705e5c6f40..3013122a739f 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6783,77 +6783,6 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, } #endif /* CONFIG_USERFAULTFD */ -struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, - unsigned long address, unsigned int flags, - unsigned int *page_mask) -{ - struct hstate *h = hstate_vma(vma); - struct mm_struct *mm = vma->vm_mm; - unsigned long haddr = address & huge_page_mask(h); - struct page *page = NULL; - spinlock_t *ptl; - pte_t *pte, entry; - int ret; - - hugetlb_vma_lock_read(vma); - pte = hugetlb_walk(vma, haddr, huge_page_size(h)); - if (!pte) - goto out_unlock; - - ptl = huge_pte_lock(h, mm, pte); - entry = huge_ptep_get(pte); - if (pte_present(entry)) { - page = pte_page(entry); - - if (!huge_pte_write(entry)) { - if (flags & FOLL_WRITE) { - page = NULL; - goto out; - } - - if (gup_must_unshare(vma, flags, page)) { - /* Tell the caller to do unsharing */ - page = ERR_PTR(-EMLINK); - goto out; - } - } - - page = nth_page(page, ((address & ~huge_page_mask(h)) >> PAGE_SHIFT)); - - /* - * Note that page may be a sub-page, and with vmemmap - * optimizations the page struct may be read only. - * try_grab_page() will increase the ref count on the - * head page, so this will be OK. - * - * try_grab_page() should always be able to get the page here, - * because we hold the ptl lock and have verified pte_present(). - */ - ret = try_grab_page(page, flags); - - if (WARN_ON_ONCE(ret)) { - page = ERR_PTR(ret); - goto out; - } - - *page_mask = (1U << huge_page_order(h)) - 1; - } -out: - spin_unlock(ptl); -out_unlock: - hugetlb_vma_unlock_read(vma); - - /* - * Fixup retval for dump requests: if pagecache doesn't exist, - * don't try to allocate a new page but just skip it. - */ - if (!page && (flags & FOLL_DUMP) && - !hugetlbfs_pagecache_present(h, vma, address)) - page = ERR_PTR(-EFAULT); - - return page; -} - long hugetlb_change_protection(struct vm_area_struct *vma, unsigned long address, unsigned long end, pgprot_t newprot, unsigned long cp_flags) -- 2.41.0