From patchwork Wed Jun 28 21:53:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13296389 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 8D258EB64D7 for ; Wed, 28 Jun 2023 21:53:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 871268D0003; Wed, 28 Jun 2023 17:53:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8200A8D0001; Wed, 28 Jun 2023 17:53:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E7D18D0003; Wed, 28 Jun 2023 17:53:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5F96F8D0001 for ; Wed, 28 Jun 2023 17:53:19 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 106BB1C84F6 for ; Wed, 28 Jun 2023 21:53:19 +0000 (UTC) X-FDA: 80953508118.11.F7D0503 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf02.hostedemail.com (Postfix) with ESMTP id D6F9E80012 for ; Wed, 28 Jun 2023 21:53:16 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WSPuBJpk; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf02.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=1687989196; a=rsa-sha256; cv=none; b=tQsUzhOV0W0vTuTQDrD5b393u5QHaVdkJ9rFz7/kPt3uSyP3QezWjz7BmYUxwpgYb0+t+e S8FWXg4Ya7RpG1EHeBKdnHK4n/KxBZyZWoqQOOAF5v2VZ9o0/iRj0zE6HO+Fa4FEbElyHY G++ZMZ+G//ReUkf+DaStpiPFVcuUT00= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WSPuBJpk; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf02.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=1687989196; 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=d8FL5BW3box1F48wj3b8rnHOt4NGgVkomS4C4Z085kw=; b=HKf7L+kJkw0uf+saAZmNihoRob1tGByavpBN8qnxGhn0x93XksJD8Zo5iiEHdKVZWunJcm yIrows5qPpXLkfAuHgMr2onHs1VJIB683dfQt8wr4TXljmMgeInqfleFcs9ercph7j3Ang aqkWjh8JyDM0wJcU9h+KVktmlE5eWGs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687989196; 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=d8FL5BW3box1F48wj3b8rnHOt4NGgVkomS4C4Z085kw=; b=WSPuBJpkqpfxNLq2KR3ZPe+7i5u1JGRP0drjAzDEf4auzWtedPi5QV+Qx0P/QLXwVJZJ6e eaKrFfII8eZaFEhf7kfJwjOdkjBpG6HaZ4UpIka97RIXqsk65MFz7Bz5FIFdEqe2U7bC/H CkOE2PrXpd/VRNKmFjPsaOVvpmHv6UQ= 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-613-kKFWf2xGPU-T0iVRLtUZ6Q-1; Wed, 28 Jun 2023 17:53:15 -0400 X-MC-Unique: kKFWf2xGPU-T0iVRLtUZ6Q-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-635de6f75e0so20516d6.1 for ; Wed, 28 Jun 2023 14:53:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687989194; x=1690581194; 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=d8FL5BW3box1F48wj3b8rnHOt4NGgVkomS4C4Z085kw=; b=iU1JbhXbgsutykap4CN2CYofJGu++5/gMqkLgku/bNbrsNNyjxstztTHmDfA7NRKvt 3Im+cnQ0vQX7uY/Fqo0nF/TT3kaYMz0mRvkBOwOHwp8B2eQevlxFKiae33igXDvusurW YD0Rr+srvWYa+/5XGkGlPWz1N1QsKR9o3EnjJwWkaHRHwpWHm07EsQTUh4/q0v60RcMg nxDocDPqYS6HgqlDyMkk9hDPK3z3QzcUdRLp16z6lFtA4NCxS7Mwp9t3NG//B15ZSxst V25NoW2GU3edQge9wqQ5tl+9t+9AS3y0AKvxRWXVNZ+s5gSQajfq+MyMjMdOOg625rjR 5U1Q== X-Gm-Message-State: AC+VfDwj6nBy8RcHa4qlRcxWDkioAh/ohNh9R4GG2Y/ETjhTrRkGa+AM TAb3hEvAvtclUSBu4vImZQCniM90GYAufXWVUeRrf/YEPYiPzfrn77EtJBnKRa4P5YaBG1MyBFr EVPtblMdvrW8GPB5eRIF/DeX3FnvYO6Y5F1BV4EXAxHhRZT/STGTOtrh0gTdFJu46wzr+ X-Received: by 2002:a05:6214:401a:b0:62d:fdc4:1e8b with SMTP id kd26-20020a056214401a00b0062dfdc41e8bmr42375766qvb.2.1687989194368; Wed, 28 Jun 2023 14:53:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4MC34MgzekDp0X74lVrIdzH9S5zruaiTrJfdeBf4bPnhG07fp5o87gyAcA985czOX/TxVoqw== X-Received: by 2002:a05:6214:401a:b0:62d:fdc4:1e8b with SMTP id kd26-20020a056214401a00b0062dfdc41e8bmr42375738qvb.2.1687989194020; Wed, 28 Jun 2023 14:53:14 -0700 (PDT) Received: from x1n.. (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id p3-20020a0cfac3000000b00631fea4d5bcsm6277797qvo.95.2023.06.28.14.53.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 14:53:13 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , "Kirill A . Shutemov" , Andrew Morton , Andrea Arcangeli , Mike Rapoport , John Hubbard , Matthew Wilcox , Mike Kravetz , Vlastimil Babka , Yang Shi , James Houghton , Jason Gunthorpe , Lorenzo Stoakes , Hugh Dickins , peterx@redhat.com Subject: [PATCH v4 1/8] mm/hugetlb: Handle FOLL_DUMP well in follow_page_mask() Date: Wed, 28 Jun 2023 17:53:03 -0400 Message-ID: <20230628215310.73782-2-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628215310.73782-1-peterx@redhat.com> References: <20230628215310.73782-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: D6F9E80012 X-Stat-Signature: 96rs3qw1cg6eecpx45pj5axii1cp8ude X-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L6OzqUS7nwxE7KiWEPvhQBBFPCQKjq1rbE0FGdkbV7IPsb7BNvlKxQAeNEIVPLkldIEFh4OunCaJ1Nic4puNdd9abv/t1tdpTf09hIfhxBS31DduYidxnyQe1l4EyCsYlZj2doU7fXeOpb076r9V7OaT7nh1uyXWcJPZLPRZtrdnXQZAq2Lutunlo9B2HHluwwoIkiAy+C0mOEofsHYfuVsANOieRMrClqnJ847EFAqOVMDfpZo3aNyk3IBbqnFqU3ExShmoT3lGmUj6iHYobMy++ix8PKxISKkgbV0zZ1C0jOvRzRhnMP8JRfHSNeugqIXtpLZwtBWWJZJiOESG2VHHBt4HDlYQf3FwdWOCj2xQ+SPP+JZB4U0nAGfdBMJkSQRZQx9F77h/g6jTsp6zDmkqyP3n5A= 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 a8336b39d6b5..06bc2e31f209 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 bce28cca73a1..d04ba5782fdd 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; }