From patchwork Mon Jun 19 23:10:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13285010 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 94D4DEB64D9 for ; Mon, 19 Jun 2023 23:10:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8B0818D0006; Mon, 19 Jun 2023 19:10:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8628B8D0001; Mon, 19 Jun 2023 19:10:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B4DA8D0006; Mon, 19 Jun 2023 19:10:56 -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 5DC0F8D0001 for ; Mon, 19 Jun 2023 19:10:56 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 376B01C80C9 for ; Mon, 19 Jun 2023 23:10:56 +0000 (UTC) X-FDA: 80921044512.13.9315DA5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 19EB6100005 for ; Mon, 19 Jun 2023 23:10:53 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WkZtwASx; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687216254; a=rsa-sha256; cv=none; b=SWWKkYF/WKztYlFHSyKKrpmykdwnFkB9pRpFFAkP16hncdy+dLloghNivuEi+1ZCAE0YND Kn27Zno6PKB7yKQUI6K9TS4/PzPRsGFv2Zb+kR4kRXuxH96Y3gUWN8Y5ynNvGx5zsi3YDv ZedPH1G75dlPjjt/8zjovWE2ku/XTHo= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WkZtwASx; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.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=1687216254; 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=6bDfMbeRbNTGIwHWXqT4W/WFCKBAZr5szTZ9WWVoPyY=; b=kZqjBlNmEP6Hc+LljNUpAfn+EWXN1NqvMY5cCj1H1tL2bvHveFSOMhKC7lPfobu1BmV3n9 BrPCycJroRt96lNRgGvE4n1ECRqok2nWp33QfRa1KWQRD54TnIs3rFEnvQp1unJrbI0qLU kb5iU46uhnvSpKtcHQnEr5TwF3SgSnA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687216253; 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=6bDfMbeRbNTGIwHWXqT4W/WFCKBAZr5szTZ9WWVoPyY=; b=WkZtwASxGvwt+FQcGMYIuuSxxFRhEA71QP0syy8r2rkv0FhOdjQ0yv8oE0sO0YEnTRgBax rlBxMYLzM4TzKljJiyrHKReBgwveJPhtwREBHG+xcMVYztTzMOBeBFmZB7tIvYO01oU7G6 AJduXWJWQkRumX0BVoZzzgz3FuAfEbs= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-590-gwrobBKnNWGYPj0_mgfr_g-1; Mon, 19 Jun 2023 19:10:52 -0400 X-MC-Unique: gwrobBKnNWGYPj0_mgfr_g-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-7606a134623so64595385a.1 for ; Mon, 19 Jun 2023 16:10:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687216251; x=1689808251; 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=6bDfMbeRbNTGIwHWXqT4W/WFCKBAZr5szTZ9WWVoPyY=; b=mETjT0EeGtxqcZ8uGJoggzUApCuZDSJ92+d0b171dtZxP7KBFarlLVpb9YpsJ7rtte 1nX1PXScArucpI3hu78rV/QVdpVKzrf07p5fmpoGIwPSR+ccbMPMU3WHmw8H1eTjwls1 eDqrYh/71kTnNGJcQJj0Px+5/S1w3r+4zv+Dou5VRerISkeGYWdyKbOMgA71bhhbBXDw sOavDHeKgwOs3ioJNaCe8AB+QRwAszsImqlfFM6aDu72PzAPXzIcuGLR+GkHU8oGsQ/t qmeAjoAgrzfcSgGJhwzk/JhiCteSIR1J1U2HGXqsYI/hbfwxgXwl+6KI3e937i1ZoAkN 8vIA== X-Gm-Message-State: AC+VfDzZ/3CDP7fDaQt9OdUwNzSN7PzMSy+BRzP3kWha9wEX1N1jyltH /rZZTVspfX+iip4SOkGQe6nUXCZmA4IU8YdawzZvo0iv5G5sL0vUikBbveHdj2CrKOIHUzqX24b +gExUj+RZZSHbui5qILMZNYrMtgys9dDNCioesns4VSmYvSZiyifW6XskarpGr0x+r9Rz X-Received: by 2002:a05:620a:171f:b0:75d:e31a:a015 with SMTP id az31-20020a05620a171f00b0075de31aa015mr12743219qkb.2.1687216251249; Mon, 19 Jun 2023 16:10:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6l3RVvQSr/D1LXHPe5NTuMnLt2zR7kaZEIqF+D9ThQr41twmjAeA1Pct5PrS5DNmUPlNg8Gg== X-Received: by 2002:a05:620a:171f:b0:75d:e31a:a015 with SMTP id az31-20020a05620a171f00b0075de31aa015mr12743182qkb.2.1687216250831; Mon, 19 Jun 2023 16:10:50 -0700 (PDT) Received: from x1n.. (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id t15-20020a05620a034f00b007592f2016f4sm405864qkm.110.2023.06.19.16.10.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 16:10:50 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrea Arcangeli , Mike Rapoport , David Hildenbrand , Matthew Wilcox , Vlastimil Babka , John Hubbard , "Kirill A . Shutemov" , James Houghton , Andrew Morton , Lorenzo Stoakes , Hugh Dickins , Mike Kravetz , peterx@redhat.com, Jason Gunthorpe Subject: [PATCH v2 3/8] mm/hugetlb: Add page_mask for hugetlb_follow_page_mask() Date: Mon, 19 Jun 2023 19:10:39 -0400 Message-Id: <20230619231044.112894-4-peterx@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230619231044.112894-1-peterx@redhat.com> References: <20230619231044.112894-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 19EB6100005 X-Stat-Signature: j3tjn6hzum1yrsnnf1gn3fki6zmhae57 X-HE-Tag: 1687216253-438355 X-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yBml8IOvIpbYkw8+YNweOs1hPIoIvvAL3Pd9SI8BlTBCuZdhf8xvW91fIfQLFajSeHdy4hmGnpFbadQ1MHeg39R/SjGj4P9dd8NYGw7XXMNGlcz3jHxB0I/FbQfYSt0kCN8wQu9tiOxxRlP6H6ljo/D2uXBk1d8cLV7GcZOnSRT8RWvE1RuFTLQMRV9EcQl0Z9ZoKkuMndBVQg4H4ld8ygRVIAH/w/AmpVYY+3sXnL9PYoUqjFUfEa8Zbhz6Tn4p/+i6XWGjHoXzLglmEeUUYL012KMp78dbldb5OlMRMYfFOOBKtdsR8CcTovYTzbxv4OOQI7hD8r3Bsp7zZZU1gH+5WUxKt3fOjJUjJQ== 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. Signed-off-by: Peter Xu Reviewed-by: David Hildenbrand --- 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 beb7c63d2871..2e2d89e79d6c 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 abcd841d94b7..9fc9271cba8d 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 9a6918c4250a..fbf6a09c0ec4 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; @@ -6499,6 +6500,8 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, page = NULL; goto out; } + + *page_mask = ~huge_page_mask(h) >> PAGE_SHIFT; } out: spin_unlock(ptl);