From patchwork Tue Jun 13 21:53:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 107585 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp852640vqr; Tue, 13 Jun 2023 15:09:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ69aNQdCZ6tUMiiZVJxlBSCc3Il2HgZrNfia4wm9pWJ99lDKYruzN8vzOXyl1zLcm/NOmSw X-Received: by 2002:a17:90a:aa12:b0:258:b43d:bdcc with SMTP id k18-20020a17090aaa1200b00258b43dbdccmr128169pjq.8.1686694170366; Tue, 13 Jun 2023 15:09:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686694170; cv=none; d=google.com; s=arc-20160816; b=NfP3M/zkQmhF7uWSCu0Fn8bPi5N6O1ISatd+EKOlkMghnaxr0CoARwVbq64ESsqyFr 5BqVLxIh47XyG5sUvDc4DLMtPpYe9RzrfOQO3jenomZs6Tz/Faxl7hc3jeKkAASNdRG+ tpzJqkcRrAdK3ifANOoQNR717RF57emDHNNSHsNGdU1ohw2stXAMNJ5+JTJbW/YwW/MU HYDf7QjmEgPjPpEkL6EugP+mb5rYIcR8lvikabnLOv2sPpQXUJqBIFEt2hhYOgbxNZUA WGw+updDLdZ6tkXShwc9lpBK7iX3NKcxjKLCjQ0kcDo+eq6c1yPLB8MWG7umqYWnNBdH vtXg== 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=RMeXibFgr6WGH9TADmv6GKzvddxtLLfsVSaxyvBxKHs=; b=hyROXa3TEoYnft7/YQX3zxv4yHe0VhTl+AkiMatcMSn3oWIaNieou3G1amDJUirZYi nRmm2JHZb+/ooYlTBXa2jnMoyZTSG1ExnQmwau8jiupIE64///hiRuF61wvNZ1iluIJv X406dEVRwQMXKIiNgFqi7X7Uh9SH13wgLsiwLCdVetVjbaPECup086UzTfX5uOZDARBd pUdoe5boN864QOXCm9yb3nEUBIYPSt76hgDr8W7swZNHOJE6A7+4KwmehdkyMlWEyVsF FRC3SVJU1C9rXapP0PhZdMiddNaGwPdePpt7lEDbblS0Tfjj5XRO58nK8FlqCLlcoL3S Ua4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PARZNzKL; 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 md4-20020a17090b23c400b0025d54872955si575067pjb.183.2023.06.13.15.09.18; Tue, 13 Jun 2023 15:09:30 -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=PARZNzKL; 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 S234413AbjFMVyl (ORCPT + 99 others); Tue, 13 Jun 2023 17:54:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230150AbjFMVyh (ORCPT ); Tue, 13 Jun 2023 17:54:37 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D6631BCD for ; Tue, 13 Jun 2023 14:53:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686693238; 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=RMeXibFgr6WGH9TADmv6GKzvddxtLLfsVSaxyvBxKHs=; b=PARZNzKLdWiCszzTYXIw3Ca3t1mpR+kTz9+VafnEKoYOjj8VHujKQgkLkguCayCeo/XmIq cUW1giZO106cu4CU5OUBXZmwPOCAnKVGrcpn6NGDFsYyEIYMdgliE2wTMJO41Hw5Ui4Nq5 NQX5WpUp4kV69dmmhceRA1PI78RnDTM= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-371-R6PFmtyvP62yj4Agsx3PVw-1; Tue, 13 Jun 2023 17:53:57 -0400 X-MC-Unique: R6PFmtyvP62yj4Agsx3PVw-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-3f871a1e3f9so8070031cf.0 for ; Tue, 13 Jun 2023 14:53:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686693232; x=1689285232; 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=RMeXibFgr6WGH9TADmv6GKzvddxtLLfsVSaxyvBxKHs=; b=kfUo6tZ0VEfUFxaMyYXyqlWtTI0LPup5j6JAtCqN3kwHoDXl77JLxD1K7V3Ae6fNOT KIOaYJNiq5eK1DujZ6A7Kzyykma8rH2GorHIiFEBDVnLX3PvATJ9wB0VC4rIT0Y7SHCH wJ205OvH8k2GuzhLppnczhUdSsFr0RBiKXsmQ+jn70Hh8GwvYJJgDOrlWI0RO3l8tCiU peh2pKuCLZumNARaZVDlC4ARyBdZCeyUWAYiQXQyd5cuhM/x9kfgXnf4R08L+SbuDfvQ 4U4c0sm9X1+A7T6RRJmtSrI5TiHo31EuONJHCIeslFhQ2yLsMAcG2aPBgh/cXmS8BYhh pAcQ== X-Gm-Message-State: AC+VfDxyK7cfLU3+5j4b7UMAK8FGouZryLwR16z6+W8W1UpfNHwK/08T pzhulGNiN5d96GP0QAHWbE8j/nTUfXvcX+dqszq0n4jQoYGotrbFTivNTJL2YUP0htriCo86bin fzJmfACxlbUx7d2e1Y8jftAnHTF3Sc0BAR4YtJ78SKCzWOTXH+oUhvoEC3xHoQ7aR8nRoV4CwY2 1xkUbYmA== X-Received: by 2002:a05:622a:1887:b0:3f9:ab2c:8895 with SMTP id v7-20020a05622a188700b003f9ab2c8895mr18016485qtc.3.1686693232286; Tue, 13 Jun 2023 14:53:52 -0700 (PDT) X-Received: by 2002:a05:622a:1887:b0:3f9:ab2c:8895 with SMTP id v7-20020a05622a188700b003f9ab2c8895mr18016457qtc.3.1686693231907; Tue, 13 Jun 2023 14:53:51 -0700 (PDT) Received: from x1n.redhat.com (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id fz24-20020a05622a5a9800b003f9bccc3182sm4522330qtb.32.2023.06.13.14.53.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 14:53:50 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Matthew Wilcox , Andrea Arcangeli , John Hubbard , Mike Rapoport , David Hildenbrand , Vlastimil Babka , peterx@redhat.com, "Kirill A . Shutemov" , Andrew Morton , Mike Kravetz , James Houghton , Hugh Dickins Subject: [PATCH 1/7] mm/hugetlb: Handle FOLL_DUMP well in follow_page_mask() Date: Tue, 13 Jun 2023 17:53:40 -0400 Message-Id: <20230613215346.1022773-2-peterx@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230613215346.1022773-1-peterx@redhat.com> References: <20230613215346.1022773-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, 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?1768627026562330694?= X-GMAIL-MSGID: =?utf-8?q?1768627026562330694?= 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. Signed-off-by: Peter Xu Reviewed-by: Mike Kravetz Reviewed-by: David Hildenbrand --- 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 dbe96d266670..aa0668505d61 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -781,7 +781,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; @@ -794,12 +793,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 270ec0ecd5a1..82dfdd96db4c 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6501,6 +6501,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; }