From patchwork Mon Jun 19 23:10:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13285008 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 8303BEB64DA for ; Mon, 19 Jun 2023 23:10:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1ADA68D0003; Mon, 19 Jun 2023 19:10:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 15C488D0001; Mon, 19 Jun 2023 19:10:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F19118D0003; Mon, 19 Jun 2023 19:10:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id DEC178D0001 for ; Mon, 19 Jun 2023 19:10:53 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A74031C80ED for ; Mon, 19 Jun 2023 23:10:53 +0000 (UTC) X-FDA: 80921044386.01.308292C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 8C6E04000C for ; Mon, 19 Jun 2023 23:10:50 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=i+x7nZUP; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.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=1687216250; 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=KBG5VmVtD6hD7uqVIm/KwEJm6kTIhRuBKiuOHix9n+4=; b=P9T/rzS6pLC7FGy/IlPpVfZ04OKXZj56Kw+HTpJ991/exSQ5poZMIm90Rv3ge20/k2tClw 4fNdQu+JalTmFcHhjShDp0knzXlF+Bri7ve9UOgJEkLjf0Iy1K/VAjuDuQbwEjknN00huM vMwpKcZvPSKOWhM1WJcsJpUQMV5yKIE= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=i+x7nZUP; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687216250; a=rsa-sha256; cv=none; b=gQJGMTkymsVzxoR0ApYgxwdYRCIOx1s9GJ+lxDDCf1avUhZCrBN0lv8QCQxHmIbymn9gUp lF9GdDgO/3Ey0ipgv7DUGMC/PsjUW8Lgpc7HsOQIx3NMxg26Yw4Vfy0QNmmaiVtDl/4gf6 Jhza1kiwafgRT0xKyugC1wPO8IeIpPk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687216249; 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=KBG5VmVtD6hD7uqVIm/KwEJm6kTIhRuBKiuOHix9n+4=; b=i+x7nZUPGwfTQMhk+Ap2Q1Zv4G1I+IYFIlUkZJTqV6Qbk5CsnsUZGXFKw0EDULz4vNN+GS aGd7+CdEeQGxZjITfGUz74xXG1LXQ4dgeYkIDXkTQFTFeNcVR11uE0L7+q54bBTKmR5Rl8 2BN1vhgRuDTC0WqZqaLOrcMMTN4IR9g= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-449-2xm7KTEFODWIjzFM414adQ-1; Mon, 19 Jun 2023 19:10:48 -0400 X-MC-Unique: 2xm7KTEFODWIjzFM414adQ-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-7625940fbf3so29805385a.0 for ; Mon, 19 Jun 2023 16:10:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687216248; x=1689808248; 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=KBG5VmVtD6hD7uqVIm/KwEJm6kTIhRuBKiuOHix9n+4=; b=VQCt7JwxsMD6U/eewXnCrbJbiF9TycIGfpnlVrpkz6lU9NSaezy/UVGKops1v0mxKb d5lsiqIK7Cg3c1E7dt8fUWVretSVLUr5ePWviy7kRUBjInLpuZlBdsjMZ0a1nIOAEPdL v/E0aixa+cOlRC8vvNzGOy/fJirlJfB6NnXGDDzSaPICYXvlc0+qlqqFWDYCm1mJ8oCa 5nJcQlAEHRKRQBajeH4VEI9vQ8aQcVh+u97b/SqFIRZzkSEB4cKHr6hK5c723/uxBd1k ergDt/XpHqfjaZwZlUt7PdNFqWq5IhxUHeU6Ut/j+5Qw0hEEELr1t+5dfmTJ4nHTKUMT cdDA== X-Gm-Message-State: AC+VfDwPYCJvqyzDXSGBbWCfSv7JYswAYK6JGoVOU3XCRfu8YrL/vQbX kvd0KFaoCEbR+OnW24uAMEzVgO+Hhg7y8xNiCYPRo7gTpXsI9G2J5vZ/iPJ31o7hKhL0NWA1WQF 6M6hqVXHiO4v5QDSTplXebxYz5xZQN0bZ2Mfw3/JOYaof16ViN9FCdhmzdJcMvFuS7qVw X-Received: by 2002:a05:620a:2889:b0:75b:23a1:82a4 with SMTP id j9-20020a05620a288900b0075b23a182a4mr13246178qkp.5.1687216248113; Mon, 19 Jun 2023 16:10:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5uYNYA6ud1mXk5kCO8SQ709g56KLRkH0S51iN3gvNVcm96teEhHrAWMqahC/SXJPrCrLeZqA== X-Received: by 2002:a05:620a:2889:b0:75b:23a1:82a4 with SMTP id j9-20020a05620a288900b0075b23a182a4mr13246155qkp.5.1687216247779; Mon, 19 Jun 2023 16:10:47 -0700 (PDT) Received: from x1n.. (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id t15-20020a05620a034f00b007592f2016f4sm405864qkm.110.2023.06.19.16.10.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 16:10:47 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrea Arcangeli , Mike Rapoport , David Hildenbrand , Matthew Wilcox , Vlastimil Babka , John Hubbard , "Kirill A . Shutemov" , James Houghton , Andrew Morton , Lorenzo Stoakes , Hugh Dickins , Mike Kravetz , peterx@redhat.com, Jason Gunthorpe Subject: [PATCH v2 1/8] mm/hugetlb: Handle FOLL_DUMP well in follow_page_mask() Date: Mon, 19 Jun 2023 19:10:37 -0400 Message-Id: <20230619231044.112894-2-peterx@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230619231044.112894-1-peterx@redhat.com> References: <20230619231044.112894-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 8C6E04000C X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: dy4szqq99s3sd5bfhg51ezjxs1hd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B78AudP1lVCkjah5OfvPY2SDEREl12bcXDNmSMVhE+eDboTk9Cfbk/Cl+C6a7PmSf1/Nqhe0UxfLyryps7GC5mf268Bh6z3Z3/Nt4at1skEIs1kG4bywRHAwYBqGzstGGJr+ojy69oWPjRv0Up80ofdOXVz5lCVewkdbtcRwKyDILgPFmBi0b0C2mfAiNMXHS0I3YR+IB5n5jxh5cPfkaxYjRS2Ca7G5xmG58VLvbRnffgwol8m4OVffXRBWgEAbw2zWUp6MIvo7M9BdfUHuNvQqp6nqt2ZR+UcAqAtj4AE2mJc9fqz0ZEDFZf4G8Pwi1dgctMitAaNLAyeUOdOEGLizQ11VgYH7I3rMokXgHmokUZkZJOAk5YRN0+hVL9IGNKALUGfCOD0113ZCi6iaITnHA= 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. Reviewed-by: Mike Kravetz Reviewed-by: David Hildenbrand Signed-off-by: Peter Xu --- 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 ce14d4d28503..abcd841d94b7 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -767,7 +767,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; @@ -780,12 +779,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 d76574425da3..f75f5e78ff0b 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6498,6 +6498,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; }