From patchwork Thu Nov 16 01:29:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13457482 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 9C710C5AE4A for ; Thu, 16 Nov 2023 01:29:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D8FA06B03E9; Wed, 15 Nov 2023 20:29:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D186A6B03EB; Wed, 15 Nov 2023 20:29:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B41576B03EC; Wed, 15 Nov 2023 20:29:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 9C4126B03E9 for ; Wed, 15 Nov 2023 20:29:29 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6FDEF804B7 for ; Thu, 16 Nov 2023 01:29:29 +0000 (UTC) X-FDA: 81462084858.25.0AB74A4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 6D4CB20006 for ; Thu, 16 Nov 2023 01:29:27 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Nvp2qtJX; spf=pass (imf03.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700098167; 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=hxqjSAwi8aTfo4zdaLYLd0e+DlQCcl09BvXUJR2cui0=; b=6AW7hBR7CI9RFnU8m1xe0n5e3HLLXA5jFjY/2c1REeQq1ZXXZWsmKvgPRdCAI3OxXcihQV E5bjifMLm8+g9msXxiMiTNx7oPtYwfvRRpII+/TNbnb8JYq9F4L8Pjcf2N3HfmIFhoo0fU Y/HEueupoLSrzlqaEjsqHxv4WHMZ3AE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700098167; a=rsa-sha256; cv=none; b=y6VKonOxI4yT2U3VlbDKszqvrhYFM5Fi8zBtwFf4dOrhO8l81kEGtVQ8RdsZ75c1YQzfaZ ohF4ntWoRvusN6R/RmyJAXVGehG5SenZnHhVU92lOhDERTt7kKOLZrSfjQne9iROV3CUFK 4MnteLLEyDh+CbZEMFjHJyUVprCvEaI= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Nvp2qtJX; spf=pass (imf03.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700098166; 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=hxqjSAwi8aTfo4zdaLYLd0e+DlQCcl09BvXUJR2cui0=; b=Nvp2qtJXwSymt57zTo3T1jyHUAW/TexmQ25H4l6H0t5L7jpbsCrjLiciEDZ8/toCHOPFD4 LvcadK6yDX0Y/AMxv7Cv0cfvBDflQGU1z9TomHsATXcZBapnCC0EOCQeltRtduln0kFYKG 4izUGfxwWEAndFUrWxIGbG8Ak950Kx8= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-21-nAhfH7V0O9G7ofKJvQTx9A-1; Wed, 15 Nov 2023 20:29:25 -0500 X-MC-Unique: nAhfH7V0O9G7ofKJvQTx9A-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-66d7b75c854so807686d6.1 for ; Wed, 15 Nov 2023 17:29:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700098164; x=1700702964; 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=hxqjSAwi8aTfo4zdaLYLd0e+DlQCcl09BvXUJR2cui0=; b=SrUyeDynWACTvuzX/IjvZ0hPra1RyK7KjFV1W/slVCV5YsEYzfrt8jDyw2KLNo8q7D /ZrIBdBCwrUwlz8DJqLQHZAa2aqxx5amqEpE8SRMT1z1DtBLU0yNjfO6TVPCSt3DM8Q9 65Fj0zmQk/k69XKfCCLB/8NKP44NCOL00GibmdMWmnv0mZ8G0i76lhSyoK5OprrTpU/L s1zQsu7fk8l4boKys5KLzTmZ8YLJvfC/hJ8XfCdXtxshy9XNlfZ+0rqHcWk0SsSXyRC0 U8rkOgP2n2mrvLsp9VvYeKuXifEilpmCEHG8l38sLDr4stGR5lCbvEF+ZVFrbPfqZcgo 3nJQ== X-Gm-Message-State: AOJu0Yw68rb4oIuvRcixgLE/plhExExuRe9tP85wH+4Hh7Wsw5XVqNa8 jnlhuV3cMeCsSvo25fVHk3hBaSh4IK853kMGIPR0ytkOkQwJ+Va7GYaiB9zU41koeKCZIosjE82 CGCAJhocbVOg= X-Received: by 2002:a05:622a:4291:b0:41c:d528:6589 with SMTP id cr17-20020a05622a429100b0041cd5286589mr8639212qtb.4.1700098164580; Wed, 15 Nov 2023 17:29:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IHJwc+nHfVii0rwj2VF/0wkfwbvSOBYLSzNseCq1M0oxHWvF5z7fbEvQHxGk1DiYrhq4t4KkQ== X-Received: by 2002:a05:622a:4291:b0:41c:d528:6589 with SMTP id cr17-20020a05622a429100b0041cd5286589mr8639189qtb.4.1700098164258; Wed, 15 Nov 2023 17:29:24 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 17:29:23 -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 08/12] mm/gup: Handle hugetlb for no_page_table() Date: Wed, 15 Nov 2023 20:29:04 -0500 Message-ID: <20231116012908.392077-9-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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Stat-Signature: sf1sxsgocx6p1uengytihgrex1u6rfez X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 6D4CB20006 X-Rspam-User: X-HE-Tag: 1700098167-535881 X-HE-Meta: U2FsdGVkX1/0XIM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Kv2lsYajt3ewruTnn2QaV35eySg+hON+N6I1r5C2L/BrfoM+mKylU0utGlJkP56QJjwObZiHDAbgcn4oJoPwzx5bK4dGGhS0mlKrN6ngIemxyCvvAviROwdGddVww2bhOD3tm8/7OCeTNs5H4ze9PSbh2EXB4o4iaEds/+WCOlbEEchvPA5mRNMAnizdtSAlusUlD6LZbHEG90E27lg6S7asaWibUTmeDJCzryWFTmzjs1I7/0AuRrZTJbsduMBEmc8KOi9chDzUNz7dZv7A2DCIvbop3e6bebPkI2Pn7N1tU+CKnTqTimh+ww5N3C9M0FfEMcivAhiJNTnUIREkSXsZHEIVA== 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: List-Subscribe: List-Unsubscribe: no_page_table() is not yet used for hugetlb code paths. Make it prepared. The major difference here is hugetlb will return -EFAULT as long as page cache does not exist, even if VM_SHARED. See hugetlb_follow_page_mask(). Pass "address" into no_page_table() too, as hugetlb will need it. Signed-off-by: Peter Xu Reviewed-by: Christoph Hellwig --- mm/gup.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 69dae51f3eb1..89c1584d68f0 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -501,19 +501,27 @@ static inline void mm_set_has_pinned_flag(unsigned long *mm_flags) #ifdef CONFIG_MMU static struct page *no_page_table(struct vm_area_struct *vma, - unsigned int flags) + unsigned int flags, unsigned long address) { + if (!(flags & FOLL_DUMP)) + return NULL; + /* - * When core dumping an enormous anonymous area that nobody - * has touched so far, we don't want to allocate unnecessary pages or + * When core dumping, we don't want to allocate unnecessary pages or * page tables. Return error instead of NULL to skip handle_mm_fault, * then get_dump_page() will return NULL to leave a hole in the dump. * But we can only make this optimization where a hole would surely * be zero-filled if handle_mm_fault() actually did handle it. */ - if ((flags & FOLL_DUMP) && - (vma_is_anonymous(vma) || !vma->vm_ops->fault)) + if (is_vm_hugetlb_page(vma)) { + struct hstate *h = hstate_vma(vma); + + if (!hugetlbfs_pagecache_present(h, vma, address)) + return ERR_PTR(-EFAULT); + } else if ((vma_is_anonymous(vma) || !vma->vm_ops->fault)) { return ERR_PTR(-EFAULT); + } + return NULL; } @@ -593,7 +601,7 @@ static struct page *follow_page_pte(struct vm_area_struct *vma, ptep = pte_offset_map_lock(mm, pmd, address, &ptl); if (!ptep) - return no_page_table(vma, flags); + return no_page_table(vma, flags, address); pte = ptep_get(ptep); if (!pte_present(pte)) goto no_page; @@ -685,7 +693,7 @@ static struct page *follow_page_pte(struct vm_area_struct *vma, pte_unmap_unlock(ptep, ptl); if (!pte_none(pte)) return NULL; - return no_page_table(vma, flags); + return no_page_table(vma, flags, address); } static struct page *follow_pmd_mask(struct vm_area_struct *vma, @@ -701,9 +709,9 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma, pmd = pmd_offset(pudp, address); pmdval = pmdp_get_lockless(pmd); if (pmd_none(pmdval)) - return no_page_table(vma, flags); + return no_page_table(vma, flags, address); if (!pmd_present(pmdval)) - return no_page_table(vma, flags); + return no_page_table(vma, flags, address); if (pmd_devmap(pmdval)) { ptl = pmd_lock(mm, pmd); page = follow_devmap_pmd(vma, address, pmd, flags, &ctx->pgmap); @@ -714,12 +722,12 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma, return follow_page_pte(vma, address, pmd, flags, &ctx->pgmap); if (pmd_protnone(pmdval) && !gup_can_follow_protnone(vma, flags)) - return no_page_table(vma, flags); + return no_page_table(vma, flags, address); ptl = pmd_lock(mm, pmd); if (unlikely(!pmd_present(*pmd))) { spin_unlock(ptl); - return no_page_table(vma, flags); + return no_page_table(vma, flags, address); } if (unlikely(!pmd_trans_huge(*pmd))) { spin_unlock(ptl); @@ -750,7 +758,7 @@ static struct page *follow_pud_mask(struct vm_area_struct *vma, pud = pud_offset(p4dp, address); if (pud_none(*pud)) - return no_page_table(vma, flags); + return no_page_table(vma, flags, address); if (pud_devmap(*pud)) { ptl = pud_lock(mm, pud); page = follow_devmap_pud(vma, address, pud, flags, &ctx->pgmap); @@ -758,7 +766,7 @@ static struct page *follow_pud_mask(struct vm_area_struct *vma, return page; } if (unlikely(pud_bad(*pud))) - return no_page_table(vma, flags); + return no_page_table(vma, flags, address); return follow_pmd_mask(vma, address, pud, flags, ctx); } @@ -772,10 +780,10 @@ static struct page *follow_p4d_mask(struct vm_area_struct *vma, p4d = p4d_offset(pgdp, address); if (p4d_none(*p4d)) - return no_page_table(vma, flags); + return no_page_table(vma, flags, address); BUILD_BUG_ON(p4d_huge(*p4d)); if (unlikely(p4d_bad(*p4d))) - return no_page_table(vma, flags); + return no_page_table(vma, flags, address); return follow_pud_mask(vma, address, p4d, flags, ctx); } @@ -825,7 +833,7 @@ static struct page *follow_page_mask(struct vm_area_struct *vma, pgd = pgd_offset(mm, address); if (pgd_none(*pgd) || unlikely(pgd_bad(*pgd))) - return no_page_table(vma, flags); + return no_page_table(vma, flags, address); return follow_p4d_mask(vma, address, pgd, flags, ctx); }