From patchwork Fri Jun 23 14:29:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13290735 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 BB8DCEB64DD for ; Fri, 23 Jun 2023 14:29:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 19F868D0006; Fri, 23 Jun 2023 10:29:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 13CAB8D0001; Fri, 23 Jun 2023 10:29:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD0328D0006; Fri, 23 Jun 2023 10:29:49 -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 93A618D0005 for ; Fri, 23 Jun 2023 10:29:49 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5EA73C0118 for ; Fri, 23 Jun 2023 14:29:49 +0000 (UTC) X-FDA: 80934246498.10.ADFD0F1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 4085080009 for ; Fri, 23 Jun 2023 14:29:47 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=c5XzPguF; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.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=1687530587; 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=kqyY+x2QLggisqHxk6p5/e1iQd0i792KL+XWdM1gQLA=; b=zFLwdQBs9j5WG2uFKddmRmG4PxuOYKkRYygIG12Ni78iL1nPEtWRDJMpNaNJUW8dDVRzDR x3Z2JWUb0o6ceez0SbKot2hMCKjvJpQzACSHb4Et3+nP5+yYnG35R3GfKLsMlKxvqAj7YC Ua8bh26pQicv00BCvvtoUojJDYmlS6Q= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=c5XzPguF; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.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=1687530587; a=rsa-sha256; cv=none; b=Uim5ljzB1yBhLerbr4uZc3ACItbZcSmDFEon9l7CSYrqJhB39g9WbpiQvl0d0BakCYeNbJ I6Bs+eyKpmVFHJJXSWRbQ9Qcis8OlicExEtJu0irTU/2q2NDD/JGZ/JZTLjgebd9b44GwX QyA41lzg5xmwrzkKD6CHWpJEgjHjP88= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687530586; 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=kqyY+x2QLggisqHxk6p5/e1iQd0i792KL+XWdM1gQLA=; b=c5XzPguFXA42xWpO8G4nFzgvX+KSpQwJyiCDnV5fW1nNPLfdJ6FSyW6yJXz5x3MTLgy5Bo UgTYSl/7U2/V8FVrHaxUHboiiO+Y/2LbxAzQ9thMKRlO/aC0sK6GFm8xQU/xVD+3nAiKKu XZverMjV95Z+wQXUHCWQt/l5gwMj6II= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-664-C1wuQSNMOPiWOECO9BXJug-1; Fri, 23 Jun 2023 10:29:44 -0400 X-MC-Unique: C1wuQSNMOPiWOECO9BXJug-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-3f8283a3a7aso1822101cf.1 for ; Fri, 23 Jun 2023 07:29:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687530584; x=1690122584; 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=kqyY+x2QLggisqHxk6p5/e1iQd0i792KL+XWdM1gQLA=; b=iAfjOlZqRqzdWpfAoKQPNT2pZOawwwr633ttuPVbZNnxC+5BjSxOzmQVdATE0GAKfH WOXQh2rRuri/oF22LBSWrimahXquuHZ9i1eigVqIb0gi0n08d5Vp5Am/sbEhUz5DFLJJ LKLa7fafWtQQyffWMqrT+bDD3r+zjMl96tBypWSVxFCB/FTvKQJ9cR5XXvPwxsrY3rrm myU8QfwU87c+RD222hlcJPTkxMi6iIpk9vLNCcjS/o9W8aWFGi2jLv9f0t4x6KfPQW6j Fymqhp1W4uY6OqOOUGQBVQqN8HN2FgvHjR2bdQMo+cdvyN7AiJ7zDEdHDPvzBm0r4wcd cjTw== X-Gm-Message-State: AC+VfDyqbOFJ8wRLskBwDMtHXZmXTFKRPzJzV0pUPfsporwj1jV6tIP1 8snt9DTjoi5/3NrqTE7TMM9vKSxLckLt4gbjA9I7OxdBfKC69/sE4leIez11LieAwzhlyhVnBj9 hz/+hn/08XrRrgw99VPDiYX9gQ5vtVnMZMy+3hUtvNA5zBqBEG3528XbBWF6//aVhiYhv X-Received: by 2002:ad4:5b8a:0:b0:62f:e4de:5bed with SMTP id 10-20020ad45b8a000000b0062fe4de5bedmr25209009qvp.5.1687530584036; Fri, 23 Jun 2023 07:29:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ73mR/vS6ro7yIhMCL42Ko8gAJI2pqYLlmvye+6zRW8sb2ZlI2HrV+rMo76OgVpAmu4iXJJhg== X-Received: by 2002:ad4:5b8a:0:b0:62f:e4de:5bed with SMTP id 10-20020ad45b8a000000b0062fe4de5bedmr25208969qvp.5.1687530583682; Fri, 23 Jun 2023 07:29:43 -0700 (PDT) Received: from x1n.. (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id b9-20020a0cc989000000b0062821057ac7sm5104827qvk.39.2023.06.23.07.29.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 07:29:43 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Lorenzo Stoakes , John Hubbard , Andrew Morton , Mike Rapoport , David Hildenbrand , peterx@redhat.com, Yang Shi , Andrea Arcangeli , Vlastimil Babka , "Kirill A . Shutemov" , James Houghton , Matthew Wilcox , Mike Kravetz , Hugh Dickins , Jason Gunthorpe Subject: [PATCH v3 3/8] mm/hugetlb: Add page_mask for hugetlb_follow_page_mask() Date: Fri, 23 Jun 2023 10:29:31 -0400 Message-Id: <20230623142936.268456-4-peterx@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623142936.268456-1-peterx@redhat.com> References: <20230623142936.268456-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 4085080009 X-Stat-Signature: 9jq3mo8oeoj6mhu688u1tng6sq7q68uw X-Rspam-User: X-HE-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BCJKQVmfM64yE0Rq+cMMvO9CpvWFWQ3KnZdlgtaAXyu0QuiahTwYt6TXSi7ONhDjkr7opZUVs/MSdPddwzMEHpYH4dFONiCesgE8QEaT/uR4hz7dsAwd3f/ftBzcZvQKNW1JurbcWLLoL/0l2b5CLBWyMlbh/frxV44WJiUiUyhKoCc9N0CTRbMImqiFes6GpqHg60k4twaAjf/Sg9iY1Q4AjWGsZkUXqAhSpAI1MIfW8XXvytrLCzSW24260NAngzPhOOE8xWNgN0bZzto324mcvDrU0CqH/c5mFwv0Rv67enUafAcWim3CiSBPEmMnognhRJdEI89pnCgBEgB68yycCFKlE6bNpejOUiUdoO4pyobEnub8+qTA== 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 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 27367edf5c72..b4973edef9f2 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; @@ -6502,6 +6503,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);