From patchwork Thu Mar 21 22:07:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13599411 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 0CCC0C54E58 for ; Thu, 21 Mar 2024 22:08:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 538C86B009F; Thu, 21 Mar 2024 18:08:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E5A96B00A0; Thu, 21 Mar 2024 18:08:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 35FD56B00A1; Thu, 21 Mar 2024 18:08:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1DCF06B009F for ; Thu, 21 Mar 2024 18:08:25 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id EFCF71208D4 for ; Thu, 21 Mar 2024 22:08:24 +0000 (UTC) X-FDA: 81922435728.08.E1CE765 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 035FE20024 for ; Thu, 21 Mar 2024 22:08:22 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Cc53ODA6; spf=pass (imf13.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711058903; a=rsa-sha256; cv=none; b=XbKheqJeGuO5oX/BrwW4aXmqVtxNnzQSac+/qWIV8sG5u9kRpXufaAo45JY2uXbMqbo+e/ Obo5c8Fa5WpQcBv+6aqH10RTfIsgJcBX9o6cjY5Tav8dWIiPG4f6ea5hfOkb4K9IlKi5k6 5AbtttB9VMngEM7DcL2iX31IWjosLs8= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Cc53ODA6; spf=pass (imf13.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.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=1711058903; 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=U+6dxwHwA9JOroUFOiyHgWbjpU2ZpFB4CR6YlbtDU08=; b=5H7R6yQ6662DzmGTIS0iun2sQF7x/1wQlNJxhBywuu0LsRCF372vFnlriSJu4h99/xiV4p W5msXznaiDzCPPVSJpHQxGhsBFiSlwoaULLPxMfM80Vy+sEdVnln2nSpC21vq7T2c2T4Gw JbfupsaNmpC8bzx+udg2nkBJNQ+Vhvk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711058902; 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=U+6dxwHwA9JOroUFOiyHgWbjpU2ZpFB4CR6YlbtDU08=; b=Cc53ODA6OpPSYeP1IbdCtJMdggxM09LN49N0r1g8/n5J+dMY+GF2ZAhelE21sOe1tF8YZO oK0PQAqnWzGfxs9FV0i6l/td2InZAgmf5ywkY8MFFvfHtJSF/a6MsTQcQ115xGCL6Rl8J5 qW6cder7b/gKgJ/8G66By+pFEqHvm9c= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-550-Eaf9gDPJP8CrxMOMt0NL7Q-1; Thu, 21 Mar 2024 18:08:20 -0400 X-MC-Unique: Eaf9gDPJP8CrxMOMt0NL7Q-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-430b9ee6bfbso2961151cf.0 for ; Thu, 21 Mar 2024 15:08:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711058899; x=1711663699; 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=U+6dxwHwA9JOroUFOiyHgWbjpU2ZpFB4CR6YlbtDU08=; b=He66j6UCHHbrrCKOqc+3bpu1awWlSmR/DI2b8Ej3q1D2VzvWYTEOn/o1J84F8ugMIx NB7oHOI9zPcyOZxlmcJ2/1tOdCWAoDPhCuFe0gF3MXOWnc2FUSPLnF5PASALJdy2ok7L yWgx/HGXo03YWR/911XvgGkhMT6cDuzoHpsQiV3gBMRRy3v6Poq7dwaL9FnJ1Nlr5uPT RB4rPLTpewDM1vjp+uXbFDmXLPuQGips7SsmzQPna7pAtM+Ffkttb9QEuaYtOIkgPGnq CimELN5x5lLpMxdv2mNJ19jZbrexVeB9fgVZSjxlyVjEkwJW5SPtSRsGsdzWlBFxtPbr Fn1w== X-Gm-Message-State: AOJu0YwqVWyYbtVkSaJtprLVqXS1P9dKSu9GIDrgfjf643aDy0PV/bHH Pn3nlFlVYRS8JZ3TLIrOfAi7uqqbvX8j6PFJP4T0IMExfCf96K1fOFJ6FhEqS+DcEedaRRe5Px6 aW14LjxTEO3ihu4LECQ7lXds20yGgzHYK7eL+4N5QmodmAxBXwOwPd75yLTmaBEBeNSRvsqYGgC AIxBnm+eGEY48BMFYuZ+9gOb0cmTtevw== X-Received: by 2002:a05:6214:3912:b0:691:456f:415a with SMTP id nh18-20020a056214391200b00691456f415amr179425qvb.4.1711058899235; Thu, 21 Mar 2024 15:08:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFnkSxmKz4azbUELRR0cRTvXrQr4udCnJcoTFPGMx5l/qOyVfxe6G6Q7JjdIdQ6Zo0lZ2QFGA== X-Received: by 2002:a05:6214:3912:b0:691:456f:415a with SMTP id nh18-20020a056214391200b00691456f415amr179365qvb.4.1711058898616; Thu, 21 Mar 2024 15:08:18 -0700 (PDT) Received: from x1n.redhat.com ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id o6-20020a0562140e4600b00690baf5cde9sm351663qvc.118.2024.03.21.15.08.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 15:08:18 -0700 (PDT) From: peterx@redhat.com To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Christophe Leroy , Matthew Wilcox , Rik van Riel , Lorenzo Stoakes , Axel Rasmussen , peterx@redhat.com, Yang Shi , John Hubbard , linux-arm-kernel@lists.infradead.org, "Kirill A . Shutemov" , Andrew Jones , Vlastimil Babka , Mike Rapoport , Andrew Morton , Muchun Song , Christoph Hellwig , linux-riscv@lists.infradead.org, James Houghton , David Hildenbrand , Jason Gunthorpe , Andrea Arcangeli , "Aneesh Kumar K . V" , Mike Kravetz Subject: [PATCH v3 07/12] mm/gup: Handle hugetlb for no_page_table() Date: Thu, 21 Mar 2024 18:07:57 -0400 Message-ID: <20240321220802.679544-8-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240321220802.679544-1-peterx@redhat.com> References: <20240321220802.679544-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 035FE20024 X-Stat-Signature: 44xor1dqa93je4xi7mhqask8uf54fbp8 X-Rspam-User: X-HE-Tag: 1711058902-499673 X-HE-Meta: U2FsdGVkX19utP48TsGHIY6TOUKW3dX0J+IkGpKsASe2Z/jx+Wid/gcH9o126qeMbA49H9AfvZIDrf/Fyv9XmSD5SeckvMsz2s0teQMh4loPlKS+ban30JQDfFU9dPmw8KMZN3WYG0K89A70P18WsVYibYzlDTR8ljZCApU0wX1GN5BuOBGxgtGHCr/jrop2Y4JjelERVPZlPOhq4xHon5ixSbrf01Z44oRR8+8HVujnfzYQfJN18+2qimE61ygtcba9ro8gPMqqHfbOCtKz8raSZ7nPWkdrcwsj4Z+WfHbWSyF8Ohgs/XgKGZx7snu+SLMaxq/XLetTSlcTp8lG1uVwhBdQXWEq1ATwaeH+FBf2i4EDMHBilhxCdnWSJEo/07e3/FuCSwTJo3t7nT3AcSCRkFZ6w2IJkNt96XSzv/OQs6ctYahrE0GmUjq3xx6tNXougb27M9NqXsnGMew1GFfDp8cZXhgOZ2o0dP+kghThjCp7IiEashZvRgL8eZQf1Wj50FNgC8Qj+Maf+C8QFJHxP/giULUCntMfGbZHR0D9ldEddZP97hsEv9i4gXHC98yFuBHVIpYtNXzFEQVzYSUb9kYAi1Nuxr2/7MfnSHNbf24w1BCluqbBRXC4CR+llT+w/fqiJwYYI/WjqoXTLykONhW47ni03wGOhWv8X3i0IE0hdpiAnIeZ1q0k6rP9pg2xR6HjOTB0pz8vZOnP/J2+jyGjtZaYbh6P5GKgvskIfOYIkms8VAFJxyFdv7ovPq4GzU5lr4rMMv3sL9fA69TNvbOVmoksobAO7aXIf2FPu+ISwUNLyJvPQqKwnc8FKH+2vk+XwiqfrC+ffV/hAu0tvUWr/Yzvzsqu6IIA/H8qsYWh5Elld4puJSlc/OGDYBlSxqdLuQx0mOZHNT1xn1f6nmjutZpvD2f3LpH7Sle+CM/T/dxCCtRGam4DWU/7tDZ0N9J7/7MuppRcS1z ygB19OPx EmMPubNa+B8RqkF+X67+BkeIkvM8oDwFtbZLogbA5V2oi3d0JTCsTMHSwhwtFGzsD9uuW6tQL5u2ouYqqvBp2HHc3xhWYhlIWTSLFz4ebpTpE/i1tZ0LDk7SGVygKA0BuixvnGYavSo4m8Mo= 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: From: Peter Xu 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. Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Signed-off-by: Peter Xu --- mm/gup.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index f3ae8f6ce8a4..943671736080 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,27 +709,27 @@ 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); spin_unlock(ptl); if (page) return page; - return no_page_table(vma, flags); + return no_page_table(vma, flags, address); } if (likely(!pmd_trans_huge(pmdval))) 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); @@ -752,17 +760,17 @@ 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); spin_unlock(ptl); if (page) return page; - return no_page_table(vma, flags); + return no_page_table(vma, flags, address); } 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); } @@ -777,10 +785,10 @@ static struct page *follow_p4d_mask(struct vm_area_struct *vma, p4dp = p4d_offset(pgdp, address); p4d = READ_ONCE(*p4dp); if (!p4d_present(p4d)) - return no_page_table(vma, flags); + return no_page_table(vma, flags, address); BUILD_BUG_ON(p4d_leaf(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, p4dp, flags, ctx); } @@ -830,7 +838,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); }