From patchwork Tue Jun 13 21:53:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13279234 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 D4CA6EB64D8 for ; Tue, 13 Jun 2023 21:54:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 56FA06B0075; Tue, 13 Jun 2023 17:54:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 51FCC6B0078; Tue, 13 Jun 2023 17:54:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E8476B007B; Tue, 13 Jun 2023 17:54:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3241C6B0075 for ; Tue, 13 Jun 2023 17:54:00 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E16FC140602 for ; Tue, 13 Jun 2023 21:53:59 +0000 (UTC) X-FDA: 80899077798.16.BB047D5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 9E13740020 for ; Tue, 13 Jun 2023 21:53:57 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gmXL4wyN; spf=pass (imf07.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=1686693237; 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=RMeXibFgr6WGH9TADmv6GKzvddxtLLfsVSaxyvBxKHs=; b=0FBQRRFEBAsJ3uHZUfHRAtfNQXJ3FwMtHNxlvuJsJK9NApNgFlxQqk+Say61qBy2adbbjX q200coOT3o2evaDQzlRQFcq3kzcZci4PAM2J875wqB9ibS2jDvJUCndx0hS52rxTLlSwcI VjKXjYGWnqbOd/OLXsune+TQksDpdyw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686693237; a=rsa-sha256; cv=none; b=K75XaBsN5xqokRLW6TiTq950ecBcGnzn9VOoaNBTpLwaSnjdFrYui+F30bn86mqX8Wjjxf OKT9j/ZKXH9v+ysisvw01WTPSX5pqKZbjVQ0Upsvp1D3K8wSvnYkN+AY/VYusRb/K2BYy4 hBw5v8EQgfqQN2/W6CWvNbocmeKznQs= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gmXL4wyN; spf=pass (imf07.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686693236; 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=RMeXibFgr6WGH9TADmv6GKzvddxtLLfsVSaxyvBxKHs=; b=gmXL4wyNLjxv09p6dTqLBFX7a7fvOg85tVn+h3AnSMp36CQK5fLxD8n6DiFO7WfmyvX5GF aSRKC25MFBdprZT57LEruZWbKzUbbZLH1D1MwTSXTxCbUeCXZyKxJSYeUY4zXzVSe9taB9 Z2Ngu4pJzwpLejrToJUIOqpg9+j8XdQ= 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-54-6zzRuUP0PeS6Hz7dIss30Q-1; Tue, 13 Jun 2023 17:53:54 -0400 X-MC-Unique: 6zzRuUP0PeS6Hz7dIss30Q-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-3f9eb7d5202so4776221cf.1 for ; Tue, 13 Jun 2023 14:53:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686693232; x=1689285232; 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=RMeXibFgr6WGH9TADmv6GKzvddxtLLfsVSaxyvBxKHs=; b=N+tCkGW0sjzWx4gPp7qEb7SM3LAN2s1MoDZntIudSvlc006nPWYzSuN0BH36I0UyRD wgcT7p8VrR8DxyaLtXditeGpYkOGaZ652/ws4ihNZQU9iF/1nMVtzVlc/yRpj7gQ3gvJ xKWDABO1XtRv7HP8VqqaJKkpeSrMDx86jsVuXvEpfIGAj3Y6x1kB7trXAaIkM0S2ZpZd X7rrYzRzT6z1Bk08i4wa6FMuISQ5OeDz4Zh60ImolJ4JtD33H6km7Izvh/88dEy93qpI R+Zd4LNPyXOMxUhEtWmDF6MDtWWCqGMOfxlIVi2PTKD0u+I+cHFcSbebHqacXyy0jT4N YsZQ== X-Gm-Message-State: AC+VfDxLzFNbPcbSvZzE8ux5TIjBYGYG6go7Q/l9uLBNCiFsWy+h7CHJ P4ZMPNfhF9HvympDsDvIDqzVLr0K6/5xXWp2+31aFYWxP6ndBczkJnoNpqyh5PVskcxxvSq1rBE kxWi4arI5Pq0= X-Received: by 2002:a05:622a:1887:b0:3f9:ab2c:8895 with SMTP id v7-20020a05622a188700b003f9ab2c8895mr18016472qtc.3.1686693232157; Tue, 13 Jun 2023 14:53:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ72MmVJ/KYdtXeaLxllJ/hfKOlDEtGiOvMuFZzCmuKll0yFpjBUzckwXKh9hVVGptkRtecEgQ== X-Received: by 2002:a05:622a:1887:b0:3f9:ab2c:8895 with SMTP id v7-20020a05622a188700b003f9ab2c8895mr18016457qtc.3.1686693231907; Tue, 13 Jun 2023 14:53:51 -0700 (PDT) Received: from x1n.redhat.com (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id fz24-20020a05622a5a9800b003f9bccc3182sm4522330qtb.32.2023.06.13.14.53.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 14:53:50 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Matthew Wilcox , Andrea Arcangeli , John Hubbard , Mike Rapoport , David Hildenbrand , Vlastimil Babka , peterx@redhat.com, "Kirill A . Shutemov" , Andrew Morton , Mike Kravetz , James Houghton , Hugh Dickins Subject: [PATCH 1/7] mm/hugetlb: Handle FOLL_DUMP well in follow_page_mask() Date: Tue, 13 Jun 2023 17:53:40 -0400 Message-Id: <20230613215346.1022773-2-peterx@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230613215346.1022773-1-peterx@redhat.com> References: <20230613215346.1022773-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 9E13740020 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: d8wzessyoyqh9459gxsxcqk4hgzfmbzz X-HE-Tag: 1686693237-456230 X-HE-Meta: U2FsdGVkX1/X4dBNw9hGBV1SXEEpB+9PWQP0MNe4rGQhL1965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/X/Re0yKg5KlirHWIvAo7aptBYsSBq5aIu0fKuU+CEhRdKePNp+1hWs83EgmmVYqLYSySC+2F9jMNACnyRFMd+r/8Z/gRHV5Mw0GPc/dQyYpYQeGpFc8g9cswwmR0VO25gPmCBO0/C2TMIDj9TnqxE9PvvBEwfA7uOXjkthcggBFNFi72r5GIwJxvsbypzPdrtPUjFlE1woywKv393ztg5OEZAkLW9akHFZLCNLHTJiKLICgbhHqSKm4DfCLyX/ya7jg7KT+P4RzZat6+fju3D1XfxrpArNRyVZu8t0goKlZ34t9gVnw== 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: Firstly, the no_page_table() is meaningless for hugetlb which is a no-op there, because a hugetlb page always satisfies: - vma_is_anonymous() == false - vma->vm_ops->fault != NULL So we can already safely remove it in hugetlb_follow_page_mask(), alongside with the page* variable. Meanwhile, what we do in follow_hugetlb_page() actually makes sense for a dump: we try to fault in the page only if the page cache is already allocated. Let's do the same here for follow_page_mask() on hugetlb. It should so far has zero effect on real dumps, because that still goes into follow_hugetlb_page(). But this may start to influence a bit on follow_page() users who mimics a "dump page" scenario, but hopefully in a good way. This also paves way for unifying the hugetlb gup-slow. Signed-off-by: Peter Xu Reviewed-by: Mike Kravetz Reviewed-by: David Hildenbrand --- mm/gup.c | 9 ++------- mm/hugetlb.c | 9 +++++++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index dbe96d266670..aa0668505d61 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -781,7 +781,6 @@ static struct page *follow_page_mask(struct vm_area_struct *vma, struct follow_page_context *ctx) { pgd_t *pgd; - struct page *page; struct mm_struct *mm = vma->vm_mm; ctx->page_mask = 0; @@ -794,12 +793,8 @@ static struct page *follow_page_mask(struct vm_area_struct *vma, * hugetlb_follow_page_mask is only for follow_page() handling here. * Ordinary GUP uses follow_hugetlb_page for hugetlb processing. */ - if (is_vm_hugetlb_page(vma)) { - page = hugetlb_follow_page_mask(vma, address, flags); - if (!page) - page = no_page_table(vma, flags); - return page; - } + if (is_vm_hugetlb_page(vma)) + return hugetlb_follow_page_mask(vma, address, flags); pgd = pgd_offset(mm, address); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 270ec0ecd5a1..82dfdd96db4c 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6501,6 +6501,15 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, spin_unlock(ptl); out_unlock: hugetlb_vma_unlock_read(vma); + + /* + * Fixup retval for dump requests: if pagecache doesn't exist, + * don't try to allocate a new page but just skip it. + */ + if (!page && (flags & FOLL_DUMP) && + !hugetlbfs_pagecache_present(h, vma, address)) + page = ERR_PTR(-EFAULT); + return page; }