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: 112182 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5823523vqr; Fri, 23 Jun 2023 07:43:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Zl9cQCI6ORtfj2hb8eKXfE0/aP+Y8ZaGHz8sxCj840nELKpF3qdGe4LA5+G5TYQotIQez X-Received: by 2002:a05:6a00:399f:b0:66c:a45:f00b with SMTP id fi31-20020a056a00399f00b0066c0a45f00bmr1556250pfb.23.1687531422277; Fri, 23 Jun 2023 07:43:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687531422; cv=none; d=google.com; s=arc-20160816; b=QKjXL5b1Y7DcwvUygZOqt+nowLE/5beSrFEoDrKvHckrLjPY/nlzhJXyuYTDB6F+cm acx1594sUj01dVegmnfPHoUISIgFwVZQQI7hdH7IKNO2fJbalKyGuZRbIf1DhdAivA6y Mt6R2oNwVnRIChtJtMPkJ4UMX6iZ1pD9NNbnBH3VzHpz84ugI2ZTf7sIGj5Vr7HyarFE oU6/FsLo54ux2dYA8v1JydgXbvimUrGrOqVwQl9n1rxbfLnL/2JQVJsJwrDJ+/l4H/k0 eI6CgSGVxH7dT1RCppO220FU8zQpJvX6XegVYNXRO/7TnG/yiaAMdzPiTL7qqCjVzkBl i1DQ== 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=pFcxcY5AyEd0X+1H9E6Fnp759Ybb+PA6QAU7l9NhXjiwxC7Ms+AC+DPZ+WIBt2SwsT /WbATvA9eWptAcz2+ujSlG4F+Rpt0jviqhOY4LsEIN7uEsKxCajJ8TWsgPzjQyh6XVYD QfhP/rKkLxgFEBA+PHvnj4FoTbevrT7uPif7JcyQQtKZ8xuyU4n+dZAXPjJPhTdyyU/y Y/xK5eiglKRd/UI3tQaSabW7EZHcAsRB5EHp++vUePwkrnowE3EO6LRKNIS5ukqnRX4J NnNsJQctnyUvYj1UTxXtXr3xggbZkDdg+qhC2OaMHNmI4Y0dhTFGDGm/xpeBwaJqelWq vrPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fygFZNri; 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 z14-20020aa7958e000000b0064d35b65bddsi8663229pfj.362.2023.06.23.07.43.29; Fri, 23 Jun 2023 07:43:42 -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=fygFZNri; 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 S231742AbjFWOaa (ORCPT + 99 others); Fri, 23 Jun 2023 10:30:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232166AbjFWOaW (ORCPT ); Fri, 23 Jun 2023 10:30:22 -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 5617D2136 for ; Fri, 23 Jun 2023 07:29:44 -0700 (PDT) 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KBG5VmVtD6hD7uqVIm/KwEJm6kTIhRuBKiuOHix9n+4=; b=fygFZNrililEdWBDJA6sF2jN8hxy06g13wVD3fzPu5mvqZZYGRBteo87dLSKOyKiBLwZOa 9EvUAcsGErERplrpqQRwwEO2G+N0MvF2s8FxWan4AEGdR+U/kHFosmJ5qpJ1EzPc2JxeMi 56BMkQAdJpfT28JJVwZCurp2EEKkILo= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-316-MM_UJJgaNiqU1U509BK5PA-1; Fri, 23 Jun 2023 10:29:42 -0400 X-MC-Unique: MM_UJJgaNiqU1U509BK5PA-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-3f8283a3a7aso1821981cf.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=YD/LtA+luB60LcgwXUAvFTbjZywJqyxipKPxvVda7r8zp7DWJZm2K328t413Wr76Na Uksg3N6RrJRwsH6azIcXDXKRX9MhHjVz8Q0BwQYLKHCgFwQOTyCtLMOhLdM49c+EDq9Z 37MHVK0sTwrCPE8viPBTxKXDPYMmcR4KX8O+syxirXR16vGxVwuaSlr0EgNMf3CnrCLj N2N7unKK7nDwcsBGC1E1VlS8h6mwrScnkOCHDmVp+uPk6OupT4i+CmhPgMrMeTApsgsB zEGaGaQCYa9uD8kCjDfE7Mlh6Uhzwr5OYsPNj68D5dQbV/jhTpo53J3zCkIBpjvyYuC0 rxWw== X-Gm-Message-State: AC+VfDyym+xTSvBCdirU3UY4sh8/MlzbdzyKDA1b1BodEBQnzB1RujGF tuint276deTt6+jn3a+3heo+GNp7qTLeUo6Tnartwqt65W7BccWDhJtOdcQAqQHs+ibsYqgM/ve OhO4D6uNfSdJErf788igNKySppOVvC2Cz X-Received: by 2002:ad4:5b8a:0:b0:62f:e4de:5bed with SMTP id 10-20020ad45b8a000000b0062fe4de5bedmr25208868qvp.5.1687530581206; Fri, 23 Jun 2023 07:29:41 -0700 (PDT) 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-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?1769504948938361897?= X-GMAIL-MSGID: =?utf-8?q?1769504948938361897?= 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; }