From patchwork Fri Jun 23 14:29:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13290732 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 624FCEB64D7 for ; Fri, 23 Jun 2023 14:29:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC6A58D0002; Fri, 23 Jun 2023 10:29:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A4FA78D0001; Fri, 23 Jun 2023 10:29:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C9548D0002; Fri, 23 Jun 2023 10:29:47 -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 79D1F8D0001 for ; Fri, 23 Jun 2023 10:29:47 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3BE2A80281 for ; Fri, 23 Jun 2023 14:29:47 +0000 (UTC) X-FDA: 80934246414.30.62280A5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 59FA340018 for ; Fri, 23 Jun 2023 14:29:44 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bGhZw3U1; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.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=1687530584; 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=Dyl/EiZSTjIoNKI5/WG17M+a/F3FtCw9rVYjip161rgldH/OSlipupZ2M5sccGdPDaeFjF jPxQs1q1DFlM/xokQh3I3EE3K4/0qU5UtswSnKw+zuXDvDfgxhS1+TtfdsQU+OjLa5dVqO 89zkVVcQT2Vi4+EUMH5BB6gxgqD3G2M= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bGhZw3U1; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.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=1687530584; a=rsa-sha256; cv=none; b=0p18H3Y7n4K2dWH5LaE/cCtatF9yMP2P7PQjwptaUuJmGOwPXZ1ZHKhWsFH0afwwHAXHC3 d9rFiTdWw23ce2Tkrvlj9S9hsTifv0CQcoWGeaXn1s6KtADCW9Etm2eXrC6tQumwO6EIKD k+KiD1T79ARHgkDpty3tzg3RjgAPGx4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687530583; 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=bGhZw3U1rf9Qt+Fj57KQ3Yh0HFT7hi4M9YYUzLBryCXpa9ppjHs092278toSDYAYOffq64 BmcWTXGH6QCMRRp8wj6VMwrtJu0YB6nn47ZuJX8FRlXQ4im4LXXdIWW6ZdtfdE1azp3DN1 6LQizlXg6+JuSk8mU9W4KTtoBkscbH0= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-192-4jgGoOJCNbmkgSJiXRLP2w-1; Fri, 23 Jun 2023 10:29:42 -0400 X-MC-Unique: 4jgGoOJCNbmkgSJiXRLP2w-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-6340023ffbbso477486d6.1 for ; Fri, 23 Jun 2023 07:29:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687530581; x=1690122581; 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=CTIMFWmdo5utyTRVK6ECM2alKlWd4tQypWetaaa78cD3nTjPiwUpcLk3wr9Eg314zn eGfgWYztdEesjnUIRM3tG78caWQHmsX9ebADhwy1NjMsCZ5McePTq7ZvqhfKPcDWPNK1 Otu44ryuI1i24LRRcFTHb/ox6vBna6uK5olgSo11Y0zvZ1wD6hzqhSStVo3M6a7VCJ33 12GKzZZRACN6PVBgDk15EwwFUYO6iYgH8F7A5a97InmLPai2WlLMEVF8zDjzHr5eOpN9 YGp95Jsz5WTnD5SX/0pwjIjYtVbsKfk04tOhQWRpqnM005snimU0vjeSqUFztECK1idW lEqg== X-Gm-Message-State: AC+VfDyIY5TEW+d5yw/mUnt+nj77up6iNU3uHOpCaIoQBOevQ2ZurEXN 0DsGgkJSOgImFnx3QEm2YpewJSEQ/C0h6Oi3U7asHcfFXqZ3FNNP8Hv3N52wAlfBOogx9DV4hV6 ppBzsnFyo58K6WZRNrGBB8Vb2iJ6v6WNPJSjo+EYDwa71NuvlbAULrDDQmFoPoWMb9q1n X-Received: by 2002:ad4:5b8a:0:b0:62f:e4de:5bed with SMTP id 10-20020ad45b8a000000b0062fe4de5bedmr25208874qvp.5.1687530581325; Fri, 23 Jun 2023 07:29:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ77EhCcf/GM+yw2Xot5giAOKEx2zhLBubqKJqeheIkq+W5o91Ui2eWJpfYc4H7mEvuNOB2yeQ== X-Received: by 2002:ad4:5b8a:0:b0:62f:e4de:5bed with SMTP id 10-20020ad45b8a000000b0062fe4de5bedmr25208839qvp.5.1687530580951; Fri, 23 Jun 2023 07:29:40 -0700 (PDT) Received: from x1n.. (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id b9-20020a0cc989000000b0062821057ac7sm5104827qvk.39.2023.06.23.07.29.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 07:29:40 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Lorenzo Stoakes , John Hubbard , Andrew Morton , Mike Rapoport , David Hildenbrand , peterx@redhat.com, Yang Shi , Andrea Arcangeli , Vlastimil Babka , "Kirill A . Shutemov" , James Houghton , Matthew Wilcox , Mike Kravetz , Hugh Dickins , Jason Gunthorpe Subject: [PATCH v3 1/8] mm/hugetlb: Handle FOLL_DUMP well in follow_page_mask() Date: Fri, 23 Jun 2023 10:29:29 -0400 Message-Id: <20230623142936.268456-2-peterx@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623142936.268456-1-peterx@redhat.com> References: <20230623142936.268456-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 59FA340018 X-Stat-Signature: a3euosmihpsxz9aexr5fwijfqjt77kid X-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f3W2i+4NNPTFaxq53vj1pY0ZaIZ9q299F32GJyl5o+cY7RFDc39ZsxyhSJHp5NRJtOd69sLS9vFGstGnatZQ8NGXr8jq8vxpGL80YS7KOSIfayydV38qdDjoWAAj/v3qQSe33PhXmzc2pwULJCxAa8ZB1zYESjo+VQ2SbdZdT7nsKa1akTlFyVI1BrOxdAhd9nTQ1C4MmyWnMsOKISsoie2tw/pwXhiNPSAwo9Obk1zaFTDUaaLbn/NcmLvEPtr1mgZaFVq/kwQNPSfRieIU4i80/6m6EHkaUJ+jm/aBqfy0CE4hkxYPAy1KFgHW4DDVMAdBIQwsc0x6n1gX4+HDsVzNFltD2uRuPM7k9EHNfTxw0wdSUAhjpIQiQcRqDV1ySSJsjbl04DT7Os3Q= 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; }