From patchwork Wed Mar 27 15:23:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13606788 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 3D75EC54E67 for ; Wed, 27 Mar 2024 15:24:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 64ADC6B009D; Wed, 27 Mar 2024 11:23:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 560096B009F; Wed, 27 Mar 2024 11:23:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B5136B00A0; Wed, 27 Mar 2024 11:23:58 -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 1BEBD6B009D for ; Wed, 27 Mar 2024 11:23:58 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CEA5CA03EC for ; Wed, 27 Mar 2024 15:23:57 +0000 (UTC) X-FDA: 81943189314.16.E10E9FF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf02.hostedemail.com (Postfix) with ESMTP id EC3BC80017 for ; Wed, 27 Mar 2024 15:23:55 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=De2WPSLD; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf02.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=1711553036; 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=2/UoYTg8lz4bAl/L4a1cbQCJuXO8WYRlAVPmeKHJK2E=; b=Qx4l3jYiYJouVW8VK1tSiNbLVQxK1vpQOG4MebKYcrUbBNzuWGbKJgsWFyAUePx3ybLPie TjlblM5XRENIUj2/cx9Z/1VzHo+FNvYOyrSgP7t1ExhmIx302a7VWJWlxDOQzAPNlsTbKs lw5v9UeEtBOggLTrf6nwQAePkw4Crxk= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=De2WPSLD; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf02.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=1711553036; a=rsa-sha256; cv=none; b=BdD/L3FmdvdOgc5loTiklg6gPmtxDArgH7SMdAm2UC9cS6izdY6yUvisPiNDY+aSiCsVnB M3A+YfqUXZtQ/KfGXDkSEXnGnmfjHbrtEPzxqJmEgTGReF843oQ1etNTuMOKVT8KKVLN9G IrrtQR2ujRW2CurDn4+G4vVNoL1QhB4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711553035; 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=2/UoYTg8lz4bAl/L4a1cbQCJuXO8WYRlAVPmeKHJK2E=; b=De2WPSLDQBlryuPjCl/FjvTSJQdZboyR9+Z0CJEllaeg7GCX/IxfdKPDsm1xQ6TWFSwe4A q577qKZm5SRfqW1bp4tJ0pDkwCWRoVE3teBMkenAQVJtVWUKCTUeL1nWFGmTBVFMP273dx 5/P8nZNjJV8wHbM/Xw7leV7MJJGuCII= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-508-xKCepNNQNqCHX1TapyOK7Q-1; Wed, 27 Mar 2024 11:23:54 -0400 X-MC-Unique: xKCepNNQNqCHX1TapyOK7Q-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7830635331bso149215685a.1 for ; Wed, 27 Mar 2024 08:23:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711553033; x=1712157833; 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=2/UoYTg8lz4bAl/L4a1cbQCJuXO8WYRlAVPmeKHJK2E=; b=E65I1WeN/X7AWT/LzWsPqGwQpF8xhS+5LIEU9Fw2cBAGSwn6UCs6Lx5mfBk5YutccC S3KqCvKk3u79dzcflpigh9GyzQdtLY9bGPqNcE55NzJHY+bUq4qL1qw7853IFweFfuiF hsSMQEVDIlZdWVx6AZFjjswRXzr3qBklxUKE66Ks8K9Ckwk/37u9ZOv4XMv5k9749Hwq Oi6Ye6ph4Yo+gXLFyqLOvmT+zY2fMXqoYauvGeHHy3oaRWQIR/Vw5AYoDr/wLiKva0Xz yStjNaM3bj4h80I2UzvgHcBMMMHQkOLHA2o/Yod6kQMeM4Qp9rtKKHjykIKxQzJzWuwq tbRA== X-Gm-Message-State: AOJu0YyNTrTRWAL78cuZf3b1fRHPWkQQPZP35yUiJl8gJgiJZFtXhBfq 0p+R4tvbzKpXXbhBGC8NaSs7kY0hBDTlaHEBglIDZdnfpDBajLXJiv1vq6luI5nTcaiRw/Z1JBU oiHTsIXJWqghsk4vCIbVlcaEitXujBrC5bO8Po9cFhImVcV4al0CR1lNxxb1aS+YHw9GB0XH5uQ DT1hYtdjRnB3N7y3ujPzvpecGm8UgH+g== X-Received: by 2002:a05:6214:4a8a:b0:696:ad00:7deb with SMTP id pi10-20020a0562144a8a00b00696ad007debmr2078377qvb.2.1711553033327; Wed, 27 Mar 2024 08:23:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH8Fh1FPXUmWlSE4Ssu3coIMvek7Et1xEVKx+8QTY39hYxqq3mRFRgZ7bz+i1V9Jmd/zYMv6Q== X-Received: by 2002:a05:6214:4a8a:b0:696:ad00:7deb with SMTP id pi10-20020a0562144a8a00b00696ad007debmr2078325qvb.2.1711553032687; Wed, 27 Mar 2024 08:23:52 -0700 (PDT) Received: from x1n.redhat.com ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id hu4-20020a056214234400b00690dd47a41csm6412639qvb.86.2024.03.27.08.23.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 08:23:52 -0700 (PDT) From: peterx@redhat.com To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Yang Shi , "Kirill A . Shutemov" , Mike Kravetz , John Hubbard , Michael Ellerman , peterx@redhat.com, Andrew Jones , Muchun Song , linux-riscv@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, Christophe Leroy , Andrew Morton , Christoph Hellwig , Lorenzo Stoakes , Matthew Wilcox , Rik van Riel , linux-arm-kernel@lists.infradead.org, Andrea Arcangeli , David Hildenbrand , "Aneesh Kumar K . V" , Vlastimil Babka , James Houghton , Jason Gunthorpe , Mike Rapoport , Axel Rasmussen Subject: [PATCH v4 08/13] mm/gup: Handle hugetlb for no_page_table() Date: Wed, 27 Mar 2024 11:23:27 -0400 Message-ID: <20240327152332.950956-9-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240327152332.950956-1-peterx@redhat.com> References: <20240327152332.950956-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Stat-Signature: wqyu57crcw9wwwzpaest38obstcwq6cs X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: EC3BC80017 X-HE-Tag: 1711553035-335269 X-HE-Meta: U2FsdGVkX19FhfA+0TUImFFo9oLuPrZq/reHnKL4M2XFyCuaif3AIIAv0yoLduw8QG7Qa4gJ2zU4MiFFDslctRqW/b67BOa0HamCzJJcTnVKRE0jhaDtOtXzXd4faOuuJLAxNPxLNNlGG3aVAakE33756IiabjIIRT+TrFb4R1XdgT3VizlGo4rmlBSTpsst8YKvQ2ZvvAOOzAMV24J0CHeoqPkWdNmKQhk8ghB+wL3J5Y0D5ytq0KnPkR23b8cFPJiN2lVRfBIVSycZeTOkiQn+ejLdIWBqWKVJD2gbk+opaEgIC1aY1q17XiBrzKOGXlZz6Sjc1FJtSz2GKutoj8BM4o2O8gIZ+KIG8YJMKeqOp9QO5iA3bQCN2XBE2O63J/Zj6fZFcSDrO0fJ739eYJZBd7rMMA7smfY4dbQ5LBVyIfmGAkT08B0U+LNYEe4rXMdZdpr/UtuhGnAGwqcAWjurTucU6KQZek2RXH4GUJhNFAmIXXXk1kRz8fyCKvDKyTe7ShJpHMMq01dG9kEx5Bh8dNvUXUj+hrnE12srfO3RU/Uvr/ml2OdQxWmG6jWmf/+Nh7BWiYVm/DnN8630uuYsbQk/uPeiYw9CvFWTiWWmWc2mDVdhg/D/s7JQsEGs5RLD0OEKec7mfKQRBVOQ6qapSnYDxM7YUWIylkbz8R8XSuIIgxDYSFneLUVB+Fs80F3azUUBcTuKk2OXDDqdDRoyICT0AJ2HMQvFijm7YLdlzy0/n1Pi2pEkKgRWxD8YhDBeOKFG2pqRQ4FtlCGx0MnOP9ZgvMvvK2IcEngavXj/hQTFBKKs4unxcjBxi5i0R90BXYXQJ3yIw7Z2qcJuWCmFngyaqfeQTi06LGYPROO771HNUxBW3j6LliEKrpwXF/7iI/6PAUMnjHa5jhBoby39zW2Y6kbv6ciZ7dBkiBXlN0d4VYXpZIcePFpq4aOfgDL67a9xjsSYilac4cX j4Pctjy+ VyGD64tAb9qGw7iUH4cSeX9jN+7+9OkTvibNAthlRZ9mfOHM+VlYgiX6+H13OR4kNHqUAQqBsEHn4Oe/5G8mCJVzHw+ZgZHVRM+0hCS+N2drl2557YMIbRsUU52EnMRfRKU3rqRe6nPXIR90= 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 c2881772216b..ef46a7053e16 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); }