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: 110189 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3307665vqr; Mon, 19 Jun 2023 16:22:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6clbpueM/MJi9hicE8KA3chWNY529bjQ3uzkHEh4fvY9pyNyJZlqyrx9zOFUS1mvhAT7WZ X-Received: by 2002:a05:6a00:1a94:b0:653:91c1:1611 with SMTP id e20-20020a056a001a9400b0065391c11611mr13646497pfv.14.1687216927625; Mon, 19 Jun 2023 16:22:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687216927; cv=none; d=google.com; s=arc-20160816; b=NMTtJB8wKavtvxa/GEzor20ai/2y23jGmlaUIoJjSqDTUDtzsOylhmW1dSOdBw4QXY Cguyi7qmXnBu+q+Q34hrx7IDI2qS/ql9TczvffRXcR9NH0jUn+TZ/HaOfWurbHpRq4GL J9Rw8pBWE8Xrn2IMjQwhos6V7zzUdswz4MHVbFRHwHwZmmj1b/UXgr4gRaCysnA3Wdto 3RdRF59R1q5Zy5ztQ8Jx67yHFIYGI2I9SwRKup6b9ah1YR6XMV9pp+Z3w/THWBAn4qW+ u6Vp38k7lWRmCVOfRabI5mezxSRNM1M9s9xxHDsEpv9n7EoHZc9aia1LjQcw+NwIrmYd j9ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KBG5VmVtD6hD7uqVIm/KwEJm6kTIhRuBKiuOHix9n+4=; b=sJScjsT4k81F0Dc8PVtnSMJs67iSu7sPyBG5d7+d6AEZJH8mVfNAe6p98OHgnfn6PS SqK5nRs2ZoEEGrVBZFBIBsSCf5QvjkT8TA1oR6ZNV+BdxxEq6zmQY6S8Try0RDXwPc7R GMqcRCZcSsVw6o8dXlJVBGReo+6a9F9E9Rbu4QfUSSNE04JT6uCzcUyR7/unQXGq9kDx iclH8t7GmMrhiUE+gLuZY6eKVVCinZxhIx82QAT/vXOyqsiO70Q6Nrf2n8psn7DUOkZX fIptCP6Ua3PUsmaKOXmBUwgVRwWkpQexzqhnQcezqkReAYSFKrHCGPDwY+teAKaxcJOL KhUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IdfLtYzJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y17-20020a056a001c9100b00668230a86edsi412643pfw.256.2023.06.19.16.21.53; Mon, 19 Jun 2023 16:22:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IdfLtYzJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229753AbjFSXLn (ORCPT + 99 others); Mon, 19 Jun 2023 19:11:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbjFSXLf (ORCPT ); Mon, 19 Jun 2023 19:11:35 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A6F5E61 for ; Mon, 19 Jun 2023 16:10:50 -0700 (PDT) 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KBG5VmVtD6hD7uqVIm/KwEJm6kTIhRuBKiuOHix9n+4=; b=IdfLtYzJg5nfM1cC0zhMd+QEAcvwSsbOq9GVW32hRyKNHyRVWWeXo7gTeMmL0yYzyDAmIx zpoOpGWcn78s4jZ089kOJ2xH2Y81zwUa6IK3IruiFQBVM7/H3kt60H01mZ0eS1mHHbJySM 9FTEJSSH8jg6ELOxAVviLYUMdc6Gl5c= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-RyIDWfBNOV6-QYY3OBaziA-1; Mon, 19 Jun 2023 19:10:48 -0400 X-MC-Unique: RyIDWfBNOV6-QYY3OBaziA-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-76248f3057bso37225485a.1 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=CMSkPpjOr49VE3Nj7tp+pAfkCr2BZ39XrkDAfVChKeKnhHgdX+LsOVNnZPwGV//Apr ZRJF6zQ7LlVyAXnCoUy5v2XYYvuNWINemKkyuUe2hBNLFyaXhju/Qsjmug6EI744i3RD O26phSRSWHWL3yWJh3dV/29uQi+g9UJbTEj86PbIhDAAcQ4Wb4EyO1KCKyoJyABY5k8x q0f92eqR7iKptpGH0kSBuLm4rVUFNHc45cuC9x0W944u63U5AdDnyDUgunE1T0E7yRKn Y8grQTUw9tDDG4nD9sZ8Uj7O4SG0bypbP2lAGD0b0yKoWRXS7kUyrClnJq4pFTczjy+/ wcdQ== X-Gm-Message-State: AC+VfDwinMi6jPy5eak3IncX8NDgw6tufW95S9OKngpNy74hGMw9EbOw BYZypXVsZYnHGlxB/k0mpfglrF/sahimvxpTZJW8ku9lAdl2JyQdAHMeKcu+2TmdJIv/EeLYysJ cVxHugbXIOdHfalwi/IF4JTTe X-Received: by 2002:a05:620a:2889:b0:75b:23a1:82a4 with SMTP id j9-20020a05620a288900b0075b23a182a4mr13246170qkp.5.1687216248029; Mon, 19 Jun 2023 16:10:48 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769175176920047196?= X-GMAIL-MSGID: =?utf-8?q?1769175176920047196?= 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; }