From patchwork Wed Jun 28 21:53:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13296391 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D22A6EB64D7 for ; Wed, 28 Jun 2023 21:53:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A1FA68D0006; Wed, 28 Jun 2023 17:53:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9A6FE8D0001; Wed, 28 Jun 2023 17:53:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 822D88D0006; Wed, 28 Jun 2023 17:53:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7480B8D0001 for ; Wed, 28 Jun 2023 17:53:21 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3430BC0336 for ; Wed, 28 Jun 2023 21:53:21 +0000 (UTC) X-FDA: 80953508202.22.FE6FEFB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf08.hostedemail.com (Postfix) with ESMTP id 1A5DD160004 for ; Wed, 28 Jun 2023 21:53:18 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Akw5Raoq; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687989199; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IlLdQZDWL4abQusa0fWM05NgtC5yViIwxz1MKIy8bPA=; b=ehgaq0HXFPI6RMR/NtSX+VsXzPdcbiTPLHn01foWC6E08bXilk+5EhSzL/o3qCsclyyqkM vn43qrn0ZP4n5bitDja9ZT7s1nL7hFH8+k7eE5cPOdj6R84TV1spkszgaTSpzME9ytDPXv cZkjjNShEyAGaoFcUW9DHj1m2QKAgvQ= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Akw5Raoq; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687989199; a=rsa-sha256; cv=none; b=HBicJ0DFXe6oAJdCzNHqbWrpkDZPgPUve0GhUfX26Wkus4uJE8UM8Q7KNG7L4unnHlvqPC 2eBUQ8Lez84bkjr1P+aeYsIQKueIU3x1yOqKjcTc87d77UxceiGbeRA4H0+ljn1ziv4K9K z9wjlHVX8Sz+HLz9N4/Ejw1VX45ybUU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687989198; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IlLdQZDWL4abQusa0fWM05NgtC5yViIwxz1MKIy8bPA=; b=Akw5RaoqS1n+uI2Aj0PTKAoAMl+ZPR0DIHSaMZY/bi11XeUREbDsg8sjBNTr4TuuFra8iz 4+zogOxeSeW9lgdEhEMN+EPZxB8dwCr8h7qySrF3++sl2D4AqxqsBc5NIFQ1F4Qv05m5/J NYBeIQqBOU8nsdW/k+OoeFhn9DHcJ/Y= Received: from mail-vk1-f199.google.com (mail-vk1-f199.google.com [209.85.221.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-649-o1kgDH27MVWLJRsznwe-tw-1; Wed, 28 Jun 2023 17:53:17 -0400 X-MC-Unique: o1kgDH27MVWLJRsznwe-tw-1 Received: by mail-vk1-f199.google.com with SMTP id 71dfb90a1353d-4716b1f55b9so2893e0c.0 for ; Wed, 28 Jun 2023 14:53:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687989197; x=1690581197; 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=IlLdQZDWL4abQusa0fWM05NgtC5yViIwxz1MKIy8bPA=; b=kjGY3J/4RHI2kDKi1/Cs1ubUIAxZ3tUEs4q3nARcRZzRnneFkDUQPl8Ulr4SOEtwSi EXcKIo84QMC1W+S9+AzoZbopWP0TzEAR2w9KSSaVn9juRTDEao39y5SFJDLLenbjfjJW R/dgZOV633Q4JXeMhn0Ll79vf0f+SRxqnBFtEO7TQ2rj/Sp29u2QQByd0O4z6e9Azohf F3n22rn0ZlXcACC+Wex1x5QisyfKFGmBusVDijXrmPh8oQyVXXaD7+X7wVw0BosJiV3w ruSemJHSUapAu+TnyInkwOsQuL7pNjvLHUgHNx4GIczJjtBPHnxNF5xGB6RUiLGzfxrG nxCQ== X-Gm-Message-State: AC+VfDwp0fqHJam4m8v4S9BYaWeHzjyYWt9XMU8BORNuDcNgjKo6VSN1 nYFu6O7q4Y4kKJFhR17+cA675S4c3N0L52zrVCu+TEicYFVg4PVnz86/pxvKzjcjzSpxbkwExqf BV4vDuDcb9HLUBF+4LGxbCC3KiZY7Y4CUPq5BUVi2WEYn1ewk43dqL37NhdL9nGynk1px X-Received: by 2002:a05:6102:358d:b0:440:b763:a69d with SMTP id h13-20020a056102358d00b00440b763a69dmr12045555vsu.2.1687989196849; Wed, 28 Jun 2023 14:53:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7xAhw0w/TD6i35B4jAPAsfvCfbDcR0SS33V5o7YLBIW4QDiUOfL0qQyToMemXcWuE4mGgWTQ== X-Received: by 2002:a05:6102:358d:b0:440:b763:a69d with SMTP id h13-20020a056102358d00b00440b763a69dmr12045528vsu.2.1687989196447; Wed, 28 Jun 2023 14:53:16 -0700 (PDT) Received: from x1n.. (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id p3-20020a0cfac3000000b00631fea4d5bcsm6277797qvo.95.2023.06.28.14.53.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 14:53:16 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , "Kirill A . Shutemov" , Andrew Morton , Andrea Arcangeli , Mike Rapoport , John Hubbard , Matthew Wilcox , Mike Kravetz , Vlastimil Babka , Yang Shi , James Houghton , Jason Gunthorpe , Lorenzo Stoakes , Hugh Dickins , peterx@redhat.com Subject: [PATCH v4 3/8] mm/hugetlb: Add page_mask for hugetlb_follow_page_mask() Date: Wed, 28 Jun 2023 17:53:05 -0400 Message-ID: <20230628215310.73782-4-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628215310.73782-1-peterx@redhat.com> References: <20230628215310.73782-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 1A5DD160004 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 66znfbm55a9rbtj3sotbugksx3x7znb9 X-HE-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0hy/+eGugdFus95fLekqxcCa4myiv+4I3XsbftkEK0kK+ehmBJMnJQruz9uuLZg1/al0r+9ODhDyT53H27ZAqiGivfw53/Toxv33lJ9j+snlHaKfNVV1pxndGO+d78wAgzNDJtf0NudpQ2BXMlf4SuuCqjcHX/knZjyTNYFexVO6OLUiRbkHwQlsHNl0ud6HoTgt7mt0tHRD3YA1pMXMVxEGAACTDzZjhhWWCRSBpXDyGda9d78j/+i3enKQZY8hMElvjoIDM7WVWVIRo9IilwPDRoX0Ak9EHH6MtRhQ6wq5Ah9UyIHL0Z9r4eyheQQ5SWn36XbXMlIbu6OOdDJr5Xq/a6zvDC/L7wNRia8GbGg8e5nTvMCdCQ== 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: follow_page() doesn't need it, but we'll start to need it when unifying gup for hugetlb. Reviewed-by: David Hildenbrand Signed-off-by: Peter Xu --- include/linux/hugetlb.h | 8 +++++--- mm/gup.c | 3 ++- mm/hugetlb.c | 5 ++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index ca3c8e10f24a..9f282f370d96 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -131,7 +131,8 @@ int move_hugetlb_page_tables(struct vm_area_struct *vma, int copy_hugetlb_page_range(struct mm_struct *, struct mm_struct *, struct vm_area_struct *, struct vm_area_struct *); struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, - unsigned long address, unsigned int flags); + unsigned long address, unsigned int flags, + unsigned int *page_mask); long follow_hugetlb_page(struct mm_struct *, struct vm_area_struct *, struct page **, unsigned long *, unsigned long *, long, unsigned int, int *); @@ -297,8 +298,9 @@ static inline void adjust_range_if_pmd_sharing_possible( { } -static inline struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, - unsigned long address, unsigned int flags) +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*/ } diff --git a/mm/gup.c b/mm/gup.c index 06bc2e31f209..1e2e23084f3c 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -780,7 +780,8 @@ static struct page *follow_page_mask(struct vm_area_struct *vma, * Ordinary GUP uses follow_hugetlb_page for hugetlb processing. */ if (is_vm_hugetlb_page(vma)) - return hugetlb_follow_page_mask(vma, address, flags); + return hugetlb_follow_page_mask(vma, address, flags, + &ctx->page_mask); pgd = pgd_offset(mm, address); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 4410139cf890..15e82a8a2b76 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6454,7 +6454,8 @@ static inline bool __follow_hugetlb_must_fault(struct vm_area_struct *vma, } struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, - unsigned long address, unsigned int flags) + unsigned long address, unsigned int flags, + unsigned int *page_mask) { struct hstate *h = hstate_vma(vma); struct mm_struct *mm = vma->vm_mm; @@ -6504,6 +6505,8 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, page = ERR_PTR(ret); goto out; } + + *page_mask = (1U << huge_page_order(h)) - 1; } out: spin_unlock(ptl);