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; } From patchwork Mon Jun 19 23:10:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 110188 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3307434vqr; Mon, 19 Jun 2023 16:21:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4b3mEhwGtNRh1P+FMrZqZeT+zXVqizYpSSsl1IxFSA6IN1aEHG/fCY72Hih9cjO1sPmWz7 X-Received: by 2002:a05:6358:c603:b0:130:dddb:18b0 with SMTP id fd3-20020a056358c60300b00130dddb18b0mr3328560rwb.5.1687216892757; Mon, 19 Jun 2023 16:21:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687216892; cv=none; d=google.com; s=arc-20160816; b=zZUvIz78eBoM/h4InZezAsuZedk3LNsUd49H6tLDC+Tsu0GwIMhJ7/3HFcYapZRoUY KRUX8Tf5Tg2cdnbcDLCSt0f5k/VA10ohwtP306iVRP9i4eoXmlSc8ivtxrgzvAHTrZP8 9gCwyE1EjmJktNNW8Xz4d5a/xPU9iBM/u7PkqxX6Y82lc3zqPGNTstFLfa4fySGXMRtp 6jZH2LeMHnsjEbt7QysdjTNrxP4t93GPMMvZFJqPHsN1dC/PeqiY+5cpDit6Wv0l0BqQ OsqKYzWON9i6cjHxvOcfPUGOlNW85JJFi/GgjV0vT+UaMe2xbNsPbFc4LgghQu77dSlR Rd4Q== 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=AeVTfhKtj8N8KTpZF3pjKuqjoCywpEvllD4d3FaXf9c=; b=09/onJ1R34+VgZ5+Fdp+kBvLoveiKGJ1LXwQamG+tItNoKNyOFoJoIN7CF2cjV32mS iV2KuRwI5v1vYkMWMlbGEDr+4DtTsgp8GMfmV0cYX70fIey23DwbvMf/q3aZZZ4YUVal C2+2JykcuQ/Qo0ayKu/57eteUW9Y7TIsOQZj/fCB3AZUmMATPRvaSyV+qeaMAoPHwB1V BgmT5tQsW7phTYYCSizJMDbzWN1tIlf7szU3vTdVSt3ist6OYWPUewRIzbH4BxfaqM2M s16IAg/2ox8bnWxC98bX3JIbaf3SlXr3LqnysMoWv8Y0wbTr3ifVw7uDIbMjGYL5bfzL vpug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OryfhD2z; 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.18; Mon, 19 Jun 2023 16:21:32 -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=OryfhD2z; 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 S229830AbjFSXLp (ORCPT + 99 others); Mon, 19 Jun 2023 19:11:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229677AbjFSXLf (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 88164E63 for ; Mon, 19 Jun 2023 16:10:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687216251; 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=AeVTfhKtj8N8KTpZF3pjKuqjoCywpEvllD4d3FaXf9c=; b=OryfhD2zLjeRdfhsA7D5vhfYjL/zTiBvNkNWx4WGyaYIP+uDbtO9IGmH+lg+QneuTfCDG2 YRhG34Kkp1NsEtK7eesfuVPsCkhihho2MBipajLL2VPSyHx7cEjcvsPsF4hQkRaAtK+Bxs vM2bVjUF6vcbGPX1Him36EhhXTegn/I= 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-22-WID_dHrMP168ottQo23Aaw-1; Mon, 19 Jun 2023 19:10:50 -0400 X-MC-Unique: WID_dHrMP168ottQo23Aaw-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-76248f3057bso37226485a.1 for ; Mon, 19 Jun 2023 16:10:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687216250; x=1689808250; 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=AeVTfhKtj8N8KTpZF3pjKuqjoCywpEvllD4d3FaXf9c=; b=Cmy9UavqbjDQk5c4XVtrPs3+S5ByiBg6rPIK/fq4KY/wAkdEgQjZCYMPVQjPRgr4/R YtcVnosrv/CkDm9/ZuKTgeSGDEPK4+9SSkng4+rWVpdufCtQGp8Kd/iqGOl6fMXXt53w O68HbF61aKMrdS0bR0wG+rNSDp5yY9TpWixBA9BRDZFmRyw1h9Q10UV2RcEqJWXSlZvz sy4f6iMVpoaJc2bl2oWgseKvFpg8r3qEhIVLbOxQ+fz6HFFx7rQrxEM11RQPsX95+p8m JVfXTzwYl2WZ65X513EguqoTSpNTDgKO5Oo83VCKhE/5UnQoMifIQLSxhwFsSfykuz96 Tewg== X-Gm-Message-State: AC+VfDwGaCmlKI5ggoRgHoVP6jUFWgbvMf+/mhbN6LC8g8lR+0y3EA+i EiGTyZmZjFx/ZK/DZrlNqGOomvWTusLDr3abHoRH829buCmfETgZisisq/8J0Uw23TtJ8aCt+Pb lZJUv3YxgMNoIWtu01Vh0Hp5h X-Received: by 2002:a05:620a:2889:b0:75b:23a1:82a4 with SMTP id j9-20020a05620a288900b0075b23a182a4mr13246239qkp.5.1687216249803; Mon, 19 Jun 2023 16:10:49 -0700 (PDT) X-Received: by 2002:a05:620a:2889:b0:75b:23a1:82a4 with SMTP id j9-20020a05620a288900b0075b23a182a4mr13246224qkp.5.1687216249526; Mon, 19 Jun 2023 16:10:49 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 16:10:49 -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 2/8] mm/hugetlb: Prepare hugetlb_follow_page_mask() for FOLL_PIN Date: Mon, 19 Jun 2023 19:10:38 -0400 Message-Id: <20230619231044.112894-3-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?1769175140355751645?= X-GMAIL-MSGID: =?utf-8?q?1769175140355751645?= follow_page() doesn't use FOLL_PIN, meanwhile hugetlb seems to not be the target of FOLL_WRITE either. However add the checks. Namely, either the need to CoW due to missing write bit, or proper CoR on !AnonExclusive pages over R/O pins to reject the follow page. That brings this function closer to follow_hugetlb_page(). So we don't care before, and also for now. But we'll care if we switch over slow-gup to use hugetlb_follow_page_mask(). We'll also care when to return -EMLINK properly, as that's the gup internal api to mean "we should do CoR". Not really needed for follow page path, though. When at it, switching the try_grab_page() to use WARN_ON_ONCE(), to be clear that it just should never fail. Reviewed-by: Mike Kravetz Signed-off-by: Peter Xu --- mm/hugetlb.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index f75f5e78ff0b..9a6918c4250a 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6463,13 +6463,6 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, spinlock_t *ptl; pte_t *pte, entry; - /* - * FOLL_PIN is not supported for follow_page(). Ordinary GUP goes via - * follow_hugetlb_page(). - */ - if (WARN_ON_ONCE(flags & FOLL_PIN)) - return NULL; - hugetlb_vma_lock_read(vma); pte = hugetlb_walk(vma, haddr, huge_page_size(h)); if (!pte) @@ -6478,8 +6471,21 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, ptl = huge_pte_lock(h, mm, pte); entry = huge_ptep_get(pte); if (pte_present(entry)) { - page = pte_page(entry) + - ((address & ~huge_page_mask(h)) >> PAGE_SHIFT); + page = pte_page(entry); + + if (gup_must_unshare(vma, flags, page)) { + /* Tell the caller to do Copy-On-Read */ + page = ERR_PTR(-EMLINK); + goto out; + } + + if ((flags & FOLL_WRITE) && !pte_write(entry)) { + page = NULL; + goto out; + } + + page += ((address & ~huge_page_mask(h)) >> PAGE_SHIFT); + /* * Note that page may be a sub-page, and with vmemmap * optimizations the page struct may be read only. From patchwork Mon Jun 19 23:10:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 110182 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3304114vqr; Mon, 19 Jun 2023 16:13:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4DGjeNVhKnLAZM94yLoNfv4mlARynGQ8zO9ucK88RetGxoDvIBAn39VKxR72sQ789BbB7D X-Received: by 2002:a1f:c14e:0:b0:46e:8724:5dbb with SMTP id r75-20020a1fc14e000000b0046e87245dbbmr1436684vkf.2.1687216412350; Mon, 19 Jun 2023 16:13:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687216412; cv=none; d=google.com; s=arc-20160816; b=PbPH6ncZC4h1/95npa7POhzy9Tve68O02dSBKhini9y65tf5woufYpWSNqwxQTEZ+J i3WUoOao6FXhzDz2uZZ6rt1SRZpfIarJ7jDBaYJsHfHjXuwPWT8cpTAZzxDP+qZGZDRR r6z/8XVzKX8SavHYtib74MqImkMIVGeJC4aGiLgi2j15YPD2wcSCYhNtoeUZ+SFhjB7s rAdZJs/QzmaxBBStUfoHz04PG1Nw7cnTXxv+AS73pplJ1DaXrTpDRsuknT+plY+LhYSp PT8AEfcj9+KK2eqmPRHd2PqD83L4qyZk/oMcPkX62dDOp0DwULo+/jYt9hzcuXvxlOMM 3EFA== 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=6bDfMbeRbNTGIwHWXqT4W/WFCKBAZr5szTZ9WWVoPyY=; b=DFYJM1893flnt2Nqdh65CLIa/0eQbdZlokI9UUEVA4FDyiCzs9dW+kn6Yrgmms8IJ6 U1axEf/sxqRiC7QWyk/4n564irBOMtsZx/f4CZYN/nKNLQr0OBOxtC2To1mrVLoQcHaX l9ZyQRNLU8KVA3328AgtfQh6tf0fvHTXKaNtbIi8HtUi4+KXE2+Ng+EOi9X51pouOxRt 3VbQfJLBWMUjU5sUHfm6CYgpiiFHaRMvd5uvRiB9jnA6l7xSDyPesA3asQs8Inyl9RKM 209xpDAuf8x8x3U/63ATYKnAU9TNntCoWptAtlWYR1ckAswC6htLgRcIBuZ8lWMrV3A3 oHEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VBTHFw9r; 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 v4-20020a637a04000000b005533c55dc3esi431598pgc.573.2023.06.19.16.13.19; Mon, 19 Jun 2023 16:13:32 -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=VBTHFw9r; 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 S229823AbjFSXLv (ORCPT + 99 others); Mon, 19 Jun 2023 19:11:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229716AbjFSXLj (ORCPT ); Mon, 19 Jun 2023 19:11:39 -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 28A35E65 for ; Mon, 19 Jun 2023 16:10:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687216253; 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=6bDfMbeRbNTGIwHWXqT4W/WFCKBAZr5szTZ9WWVoPyY=; b=VBTHFw9rqImxlVYOTjywvRhb+WR+8TuAosfwmepDv5/KoUh5wgUK5Kw4aEeL84kRWJh+4B 2qnWAhCZPmq3MPB8hFCzUuihZTsvovTM5pHhkevUl4v44h5azSE5aYLniAz7BHe06c1gV1 tCu8HPj0nosq9mpru/9YMqxaeAIpOqE= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-590-8LLJQvs8PQ2IOvpAGgBglQ-1; Mon, 19 Jun 2023 19:10:51 -0400 X-MC-Unique: 8LLJQvs8PQ2IOvpAGgBglQ-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-7623c0f2856so48475885a.0 for ; Mon, 19 Jun 2023 16:10:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687216251; x=1689808251; 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=6bDfMbeRbNTGIwHWXqT4W/WFCKBAZr5szTZ9WWVoPyY=; b=MrqYRMpoJK/zqUu1ub1WPbrKsoc9D2cwRgIxBHUuJ5ErbclU+5DwrfvrzcVS1Cjtrf 1n8KCaKh0fUXh3+1AZVrj3/GZ0Ov1J/G5mAsQ9wkPfggTAlFjPVkZ6H9JAUmL87HVxAt SLKAQeOK/NTY6d6COU+c4y2xfZHi2TflXAKeW4/2d5ldmKEr06B7Vbo8ea8ziZHG3R9D h2zni0178QxMHlMMDBhjDNO823x4schvnYAqWRx55gY2aFuqlvll9yiCtEe3Vuqo1B7V cZP4n6KSZ2di2tzd71CulfYUiAlVmoDJ/BAb5Xk4yG/H59YevKvO1xdkEO6dP4bwI+TV drlQ== X-Gm-Message-State: AC+VfDxBweceyxHxpnJksCIxaGwmoXrVs/YTxnGWk4KTM0D9Cvr72x0l Li5VZRj5SRhVFPqIZ+JRFUrVlH/6MHJ3LR7PBof3GjPokjR/l7DI/GDFOfV8+t7SWveioyldq1+ AgIs/wLKpOsFRdEqK+n7GW4IV X-Received: by 2002:a05:620a:171f:b0:75d:e31a:a015 with SMTP id az31-20020a05620a171f00b0075de31aa015mr12743197qkb.2.1687216251119; Mon, 19 Jun 2023 16:10:51 -0700 (PDT) X-Received: by 2002:a05:620a:171f:b0:75d:e31a:a015 with SMTP id az31-20020a05620a171f00b0075de31aa015mr12743182qkb.2.1687216250831; Mon, 19 Jun 2023 16:10:50 -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.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 16:10:50 -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 3/8] mm/hugetlb: Add page_mask for hugetlb_follow_page_mask() Date: Mon, 19 Jun 2023 19:10:39 -0400 Message-Id: <20230619231044.112894-4-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?1769174636893815027?= X-GMAIL-MSGID: =?utf-8?q?1769174636893815027?= follow_page() doesn't need it, but we'll start to need it when unifying gup for hugetlb. Signed-off-by: Peter Xu Reviewed-by: David Hildenbrand --- include/linux/hugetlb.h | 8 +++++--- mm/gup.c | 3 ++- mm/hugetlb.c | 5 ++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index beb7c63d2871..2e2d89e79d6c 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -131,7 +131,8 @@ int move_hugetlb_page_tables(struct vm_area_struct *vma, int copy_hugetlb_page_range(struct mm_struct *, struct mm_struct *, struct vm_area_struct *, struct vm_area_struct *); struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, - unsigned long address, unsigned int flags); + unsigned long address, unsigned int flags, + unsigned int *page_mask); long follow_hugetlb_page(struct mm_struct *, struct vm_area_struct *, struct page **, unsigned long *, unsigned long *, long, unsigned int, int *); @@ -297,8 +298,9 @@ static inline void adjust_range_if_pmd_sharing_possible( { } -static inline struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, - unsigned long address, unsigned int flags) +static inline struct page *hugetlb_follow_page_mask( + struct vm_area_struct *vma, unsigned long address, unsigned int flags, + unsigned int *page_mask) { BUILD_BUG(); /* should never be compiled in if !CONFIG_HUGETLB_PAGE*/ } diff --git a/mm/gup.c b/mm/gup.c index abcd841d94b7..9fc9271cba8d 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -780,7 +780,8 @@ static struct page *follow_page_mask(struct vm_area_struct *vma, * Ordinary GUP uses follow_hugetlb_page for hugetlb processing. */ if (is_vm_hugetlb_page(vma)) - return hugetlb_follow_page_mask(vma, address, flags); + return hugetlb_follow_page_mask(vma, address, flags, + &ctx->page_mask); pgd = pgd_offset(mm, address); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 9a6918c4250a..fbf6a09c0ec4 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6454,7 +6454,8 @@ static inline bool __follow_hugetlb_must_fault(struct vm_area_struct *vma, } struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, - unsigned long address, unsigned int flags) + unsigned long address, unsigned int flags, + unsigned int *page_mask) { struct hstate *h = hstate_vma(vma); struct mm_struct *mm = vma->vm_mm; @@ -6499,6 +6500,8 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, page = NULL; goto out; } + + *page_mask = ~huge_page_mask(h) >> PAGE_SHIFT; } out: spin_unlock(ptl); From patchwork Mon Jun 19 23:10: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: 110183 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3304152vqr; Mon, 19 Jun 2023 16:13:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ64BoLkvMz10F+azLOkL3QdIV0CTd4q8MM37zVchFTniGgAMzc6roPuRVT05td8xb+IuiDQ X-Received: by 2002:a92:2a10:0:b0:342:1012:1196 with SMTP id r16-20020a922a10000000b0034210121196mr9932987ile.15.1687216420405; Mon, 19 Jun 2023 16:13:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687216420; cv=none; d=google.com; s=arc-20160816; b=Za/qmnh+Vn9zM3kS8oe4N40NrFEZyK/cW+ZAHtRi3101PGrbPs1muOosmETcSHuyeM aLd2e5hl9TF39/ByD+yyI7HJb8PO+XvEIsLYI7V02FtKeaEwVG0MkQ0iF/GzWXjQOCB1 t+CrpGrYmBhdK1XImPOrKZMr9NwcrBaGqDOuqFlirENTGn+AE962LXClkKm+1R5L4XX5 hkz1jXiYdncxOtKrLdE1Bpp+ekAFRzY/Rt+5NazgcZ6zu/Q0eFODC4zSLA3uhdsEJNYJ DQtdZudBSfCXq8Mayjq9YF1A40WZOhicQe8gTbSyGsI34qZX5/hvWjCM5r6PRev+jAFR YCeA== 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=G5PvpMSc9PWeUNzovzE5WASqMyhgs2MBMMaZX0mlkro=; b=aTAexHChMBmfKj70RXQx4we9vPYvT5ZF7RLy84OUd/LXxNiqabG5uEdspXcKZ4QWLM dq7MLYEDprfFmS395ng/sMx4+BNNZL1v7yhALzlEIW4QHF40nn99fKXbdWIWUETJoxuo Ib+nTZ5b9J/+hb6n4kg2AFrB6IZAq31H6yBy7saxHlnCz+ONp+fuhoYEH3G/KWu4q0S5 x9Fuoi9NFbr7/v7fbsLK3+vEaq6TGjZ9t8ksgZLpS+V1rwh7wRo90J9ElAmaio/WY0VE lixZlFZEfI2TG8kQBWF5+Mrlom97Vc3MPm9ssrOfpMYibLE1K2Nod+po1C+FdOc69CIa 7vEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HsrfWaFG; 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 g129-20020a636b87000000b0054f993847a7si434662pgc.150.2023.06.19.16.13.28; Mon, 19 Jun 2023 16:13:40 -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=HsrfWaFG; 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 S229887AbjFSXLz (ORCPT + 99 others); Mon, 19 Jun 2023 19:11:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229736AbjFSXLn (ORCPT ); Mon, 19 Jun 2023 19:11:43 -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 400FDF9 for ; Mon, 19 Jun 2023 16:10:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687216254; 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=G5PvpMSc9PWeUNzovzE5WASqMyhgs2MBMMaZX0mlkro=; b=HsrfWaFGRNGW7TyqANKJXScYe9zyJOxCR9WJ2uLjTGhDhqAWnatUQY7r1NI3E5AyZZhr0l 3x3Csn0p86ULBAcyHGR1YwyVNu45UN/5trM7b/w/POwyHylavMtMVJwQciwVg6hxa/Ru71 v0exEzuJzbpZ2yI1ce+yxe71MAIgH4M= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-367-ADuqldeKOdC8jdP2BC1-Wg-1; Mon, 19 Jun 2023 19:10:53 -0400 X-MC-Unique: ADuqldeKOdC8jdP2BC1-Wg-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-76077669a5aso105210085a.0 for ; Mon, 19 Jun 2023 16:10:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687216252; x=1689808252; 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=G5PvpMSc9PWeUNzovzE5WASqMyhgs2MBMMaZX0mlkro=; b=RF39+mw1lECiHeviN7uE0PT+gnphVOGi182Z5xSfA+KCcVuoCnbin9yzecpBqawujg 1CyKn1G529yVjklqbX+o7KX04WE6HrLCi1gmMXa09esKEcw5AE20nctGqJYUzavBEkYS Yad+9gny8Zqk9xYVFKDkE/ocK3hwyk/DRTxY8a60p4rASuZo8l0P/wJBxqa/cnAlQe9G UHI+az9wzuMV3zfc9vi639V9szqlh7eVk1FXhRxb5QGS6wFU1wwdBg0da3eL2NMLQFxH m88NWspXIc8x/PGDESW4YRd7QheGT056Phsjl5fGVOx9rlTItGXgUAf+ZZt+BwruWtsY +T0A== X-Gm-Message-State: AC+VfDz8GmTaexW9uJ/MPRW5YC5YuLJNvtMVkZt8NOri0rmvlILX/Cd/ SVaJGjX7B8PL7nPT8OUNQmZu0epVBpjiA0GYuaHiJ+MuxZylI+35X5UjCt9t1dCF4WFmwjh3RQI y4OyE6NSN8k4hUocTLaqZwsZq X-Received: by 2002:a05:620a:800e:b0:763:b025:9f40 with SMTP id ee14-20020a05620a800e00b00763b0259f40mr146888qkb.7.1687216252497; Mon, 19 Jun 2023 16:10:52 -0700 (PDT) X-Received: by 2002:a05:620a:800e:b0:763:b025:9f40 with SMTP id ee14-20020a05620a800e00b00763b0259f40mr146867qkb.7.1687216252208; Mon, 19 Jun 2023 16:10:52 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 16:10:51 -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 4/8] mm/gup: Cleanup next_page handling Date: Mon, 19 Jun 2023 19:10:40 -0400 Message-Id: <20230619231044.112894-5-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, 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?1769174645672019000?= X-GMAIL-MSGID: =?utf-8?q?1769174645672019000?= The only path that doesn't use generic "**pages" handling is the gate vma. Make it use the same path, meanwhile tune the next_page label upper to cover "**pages" handling. This prepares for THP handling for "**pages". Reviewed-by: Lorenzo Stoakes Signed-off-by: Peter Xu Acked-by: David Hildenbrand --- mm/gup.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 9fc9271cba8d..4a00d609033e 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1124,7 +1124,7 @@ static long __get_user_pages(struct mm_struct *mm, if (!vma && in_gate_area(mm, start)) { ret = get_gate_page(mm, start & PAGE_MASK, gup_flags, &vma, - pages ? &pages[i] : NULL); + pages ? &page : NULL); if (ret) goto out; ctx.page_mask = 0; @@ -1194,19 +1194,18 @@ static long __get_user_pages(struct mm_struct *mm, ret = PTR_ERR(page); goto out; } - - goto next_page; } else if (IS_ERR(page)) { ret = PTR_ERR(page); goto out; } +next_page: if (pages) { pages[i] = page; flush_anon_page(vma, page, start); flush_dcache_page(page); ctx.page_mask = 0; } -next_page: + page_increm = 1 + (~(start >> PAGE_SHIFT) & ctx.page_mask); if (page_increm > nr_pages) page_increm = nr_pages; From patchwork Mon Jun 19 23:10:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 110187 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3307123vqr; Mon, 19 Jun 2023 16:20:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ60aa9Vh3VIr6FYAfoFXqTWW0oWkQlglc42d5QUhuk1Vab3PH+hUVGAKnXGC0JQ1bITmxhw X-Received: by 2002:a17:90a:e385:b0:25e:e70f:423f with SMTP id b5-20020a17090ae38500b0025ee70f423fmr8414115pjz.19.1687216840298; Mon, 19 Jun 2023 16:20:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687216840; cv=none; d=google.com; s=arc-20160816; b=ngpremygdOIKLAj2Av/emeBi0f6TMv1ru9UiBeu5ppDLpoSPjo5KcwHGr2FCidN4jH T0q7X7r6oSrLCrZQnG6YbaVSuuuc1ulkv734qNyc63vv9ObkYeTigJPDJ1Xbz0hTR8u/ g+mxN7THxn06+cREuRVcQ77P9EEldg1E0JtEkvOE4b5rfoNDHowwlF7/Q26mI2LhUwnS izP2ACzmD904TporAMzyC3ikDuaYSWYAHdg/gmbym2xhIxRvbtXzPCUlDoKP/foVhQl2 zd6X5a594o0Eavk6G7wKt6ojbMI/hnQRVUaWBy817LXUh5auDt3hqsSFAephCmT9qtOh bviw== 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=00BT5P4M9oBALYuFaAi0Lj2RlKWYXU3sXFeAAd1zvs8=; b=DgSwi86kLFxDYtu69x/8uIikwUMyX/onPUATsQH+0CbInTrq4aKUuV1u3s/jSvq1LX 6DmrBF5hxrjbD/oogcang8Gc+8zbItutzNVGj9VKwqvyB546GhQJRflLExAdJldhw+q1 ITgqP72HexKW8U294zq3ToZNY1blqNrGZ53kTXzsM+7Lgbe8gEUWxluVEszpn7Uo/QlA kuuIVqr4UxtZkTRQ4185yBP0+KU6cv6yUUY4R9DatxRf1LSsjwOZUX61ZMqLIoyJuvd2 kFQT8mMgz87m30Ou588LDZHo1ChHMQh5Vgs5dne/7nqhEmrbQ8yWU1FV1OQ4rqQFk94g fG8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=f0tYTU3I; 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 k127-20020a636f85000000b0054fd2f87c21si441052pgc.198.2023.06.19.16.20.28; Mon, 19 Jun 2023 16:20:40 -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=f0tYTU3I; 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 S229674AbjFSXL7 (ORCPT + 99 others); Mon, 19 Jun 2023 19:11:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229782AbjFSXLo (ORCPT ); Mon, 19 Jun 2023 19:11:44 -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 5B654E60 for ; Mon, 19 Jun 2023 16:10:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687216255; 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=00BT5P4M9oBALYuFaAi0Lj2RlKWYXU3sXFeAAd1zvs8=; b=f0tYTU3IzvH4uOMNyt0P+hlzEtEZI38d/jYjo6H9ZbicL5L3gPelcENF6pHDuQpqGrlqkB YqG95Aqb2zqhx9ez0cL7WzqFWH/febnEomXp8EQZSl5OLcqKncb4PVjAZEDTFoa9LsfdxG C73H4N6xdT7IQZkROB7OveoMmizkAFA= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-606-6T6UrSYSPX6oDz6AbT-ZHw-1; Mon, 19 Jun 2023 19:10:54 -0400 X-MC-Unique: 6T6UrSYSPX6oDz6AbT-ZHw-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-76248f3057bso37228285a.1 for ; Mon, 19 Jun 2023 16:10:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687216254; x=1689808254; 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=00BT5P4M9oBALYuFaAi0Lj2RlKWYXU3sXFeAAd1zvs8=; b=f7PsrErmV0NWmaf+Ba5wXgnthol/rA2XpQzqS+xn/puj1ia7E1UdQC4qU4OH1BNQsn fU1VTiagNN9blmMKn3HfxeMFcUxasgoXxlnx4P4pS2sSBajkJBmkKXNULTvTIEx9NqMk Ij9ebXYbmjNf99TzxBqAJgZCkLgFEz+r4DlZPRo76BT+ezuEXAQFSsMK7J9AioaJ4ILt 31RCIUK3jTxaSzgBt+Z2U2mgJRwn3lPP1rmM3heJJllRshnxdUc1tqDkSDcvNr4/Hgja u+jAsCHTELuSnqoyj+BQ7d3cNaQ3L4bPG8IYou+YfydkVSBDlSXrTTPM8JzfAV7T/cE+ YMdQ== X-Gm-Message-State: AC+VfDy7E0RZ8MAzHPBGUl6pUzd7Z2nOsHuiz2WjWfc6GCSIGdbM7bOI uaD93ANv01zkg/6gPt8Y+x68ENada5/Zp+dRqNdXrnGbDOb5kjNRfuU4NP4UIVAaZk7IcfPxgPd Euje83LIkDjwDKD8xsUVISRJ6 X-Received: by 2002:a05:620a:2889:b0:75b:23a1:82a4 with SMTP id j9-20020a05620a288900b0075b23a182a4mr13246406qkp.5.1687216253843; Mon, 19 Jun 2023 16:10:53 -0700 (PDT) X-Received: by 2002:a05:620a:2889:b0:75b:23a1:82a4 with SMTP id j9-20020a05620a288900b0075b23a182a4mr13246392qkp.5.1687216253602; Mon, 19 Jun 2023 16:10:53 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 16:10:53 -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 5/8] mm/gup: Accelerate thp gup even for "pages != NULL" Date: Mon, 19 Jun 2023 19:10:41 -0400 Message-Id: <20230619231044.112894-6-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?1769175085594240061?= X-GMAIL-MSGID: =?utf-8?q?1769175085594240061?= The acceleration of THP was done with ctx.page_mask, however it'll be ignored if **pages is non-NULL. The old optimization was introduced in 2013 in 240aadeedc4a ("mm: accelerate mm_populate() treatment of THP pages"). It didn't explain why we can't optimize the **pages non-NULL case. It's possible that at that time the major goal was for mm_populate() which should be enough back then. Optimize thp for all cases, by properly looping over each subpage, doing cache flushes, and boost refcounts / pincounts where needed in one go. This can be verified using gup_test below: # chrt -f 1 ./gup_test -m 512 -t -L -n 1024 -r 10 Before: 13992.50 ( +-8.75%) After: 378.50 (+-69.62%) Signed-off-by: Peter Xu Reviewed-by: Lorenzo Stoakes --- mm/gup.c | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 4a00d609033e..b50272012e49 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1199,16 +1199,53 @@ static long __get_user_pages(struct mm_struct *mm, goto out; } next_page: - if (pages) { - pages[i] = page; - flush_anon_page(vma, page, start); - flush_dcache_page(page); - ctx.page_mask = 0; - } - page_increm = 1 + (~(start >> PAGE_SHIFT) & ctx.page_mask); if (page_increm > nr_pages) page_increm = nr_pages; + + if (pages) { + struct page *subpage; + unsigned int j; + + /* + * This must be a large folio (and doesn't need to + * be the whole folio; it can be part of it), do + * the refcount work for all the subpages too. + * + * NOTE: here the page may not be the head page + * e.g. when start addr is not thp-size aligned. + * try_grab_folio() should have taken care of tail + * pages. + */ + if (page_increm > 1) { + struct folio *folio; + + /* + * Since we already hold refcount on the + * large folio, this should never fail. + */ + folio = try_grab_folio(page, page_increm - 1, + foll_flags); + if (WARN_ON_ONCE(!folio)) { + /* + * Release the 1st page ref if the + * folio is problematic, fail hard. + */ + gup_put_folio(page_folio(page), 1, + foll_flags); + ret = -EFAULT; + goto out; + } + } + + for (j = 0; j < page_increm; j++) { + subpage = nth_page(page, j); + pages[i+j] = subpage; + flush_anon_page(vma, subpage, start + j * PAGE_SIZE); + flush_dcache_page(subpage); + } + } + i += page_increm; start += page_increm * PAGE_SIZE; nr_pages -= page_increm; From patchwork Mon Jun 19 23:10:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 110186 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3306159vqr; Mon, 19 Jun 2023 16:18:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4EbYY802WnPEvaBeGy4fYEFiLsqdTqDDmySaufaxYask0rw4zWMfbxs5EaSeRm9T2wDFrh X-Received: by 2002:a05:6a20:8f1e:b0:10b:40a9:ec48 with SMTP id b30-20020a056a208f1e00b0010b40a9ec48mr15399448pzk.29.1687216709931; Mon, 19 Jun 2023 16:18:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687216709; cv=none; d=google.com; s=arc-20160816; b=dTXkQTdPBkoOXuRMUKaHEz4MXl+y5fmDaFEy58s+iT4CpAGC1IDMoi2w9mPsT78P51 7Y4BiIYOLa/bIuwHV92sqZY6wTSgldKjQpL3eP+qcUhZIxM2jLpAeCd7bXquEBxh0WoW z5ah71mLiLrhf1TdM/B0PlCt4zrL9IJVMtformHdmjsMqUCGiZG7oKsK9JBkngBF5E9T nXVO1GH0cTfxNMEMD3NH5P/WpeYPARQHug0cvE6/br0kSKyqlWv2G4mFtEMrFlb8FkA2 bgXhOZlS48PZwnphVbz2gapmEHpH07Y+NyA0wpyPL51IWEg7t1OeWJ8ePU7SKxbbD3vE FJiQ== 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=LfImLhKhuRzr1PTA4t2FBf8hxw7M1QNNKWA4dIYrJXo=; b=DybWG0hM9IzL+1qxtAY1GdbqTSOcGaWSGh5UYDFnH0DWetaAsr2O5WPePFajzmibXE oa90Td6mij+HkEC23dpeNZX5GxHAqtMoWew+Oqpo53hxwHJSyY+sSqLZkxU3+Kyc75TR qNiah+PFb9ol9QBPtBK0y2jSN87Fvt6xIhOZDIF/kJD9I3KnoMeFy3q0xHhldLVk9oiH C8OptDJSoBx4OrGauZz0pe3fDU+oz1zs2lZ6/7kIAUCieUYedvlacw9M4ls9AmGluaO+ dBh2InD/Uh+7YGjbj431g/r25pib1ASI2eMmYZFvwQNAAG3ilZZslQVUvYQHUvzIcctJ YwLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Ag8L9og/"; 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 y20-20020a63b514000000b0054ff0e193fesi498872pge.225.2023.06.19.16.18.17; Mon, 19 Jun 2023 16:18:29 -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="Ag8L9og/"; 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 S229601AbjFSXLt (ORCPT + 99 others); Mon, 19 Jun 2023 19:11:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229567AbjFSXLf (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 66491E68 for ; Mon, 19 Jun 2023 16:10:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687216257; 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=LfImLhKhuRzr1PTA4t2FBf8hxw7M1QNNKWA4dIYrJXo=; b=Ag8L9og/DVxGME3XhkVlGYPFYYI8GxzY3+IQzTvIqo1ckj7C83+uweWV1iY4E4Z0sgVGm4 fxFJbXVCSRY26uFcchdUCVguuqW/bsgXQpfp4fcy/iveuxqC41fHLxYhoJJy1gO/I7Z5xH /iDNRRSgA7SuGJ0ZSl0+YTnd3eJ3t4g= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-266-eKxTJo0uOxmMSYzhJJrL8A-1; Mon, 19 Jun 2023 19:10:56 -0400 X-MC-Unique: eKxTJo0uOxmMSYzhJJrL8A-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-7606a134623so64598085a.1 for ; Mon, 19 Jun 2023 16:10:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687216255; x=1689808255; 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=LfImLhKhuRzr1PTA4t2FBf8hxw7M1QNNKWA4dIYrJXo=; b=bUTAeEWKgru0QcCwInp869/6s1RVgmGWhJuFO/vJNuNfrnoxOo2xdCbMHzUraB38Xe r7tZZYdbqgcYlDZx1N5GAREkxZkLpiZcxKenC2YxqKOLn0ClV9M3U2mr+MwNs5W7FmvO QDCYtd9aXO0eutNAV1wgddlFERODMJgETNch3XR+PxoilHYqzF/TYNSq62wsXLcnluo2 FmNy9anvPzP1/Lh93oeaZ+DWT7CVP7aifVav8Sz2HIhP481Us+3KPoVG+cSrg7f50M1I ukTbQ81QjK8wKT5JYGcUrEx4cOzwC5PcBykmRM67Cs0GzFhSfzD9dZI8MQGtc6Gy7O2v kGow== X-Gm-Message-State: AC+VfDynBK86wIgNW5t5lJfrp2KA+8SfHia1Pn1L0kpo2GqUxRWFr/t1 Q7kl5un9kf3ibn3lIVnqv7zUuWfcByHZ9uS137XqrNWNIQKlpDuyAndsDh5WvN+NRfi6B8EsN5j qU6ZjVuCMHxNOyNxSP88OTjUYo2LF0X6S X-Received: by 2002:a05:620a:171f:b0:75d:e31a:a015 with SMTP id az31-20020a05620a171f00b0075de31aa015mr12743405qkb.2.1687216255289; Mon, 19 Jun 2023 16:10:55 -0700 (PDT) X-Received: by 2002:a05:620a:171f:b0:75d:e31a:a015 with SMTP id az31-20020a05620a171f00b0075de31aa015mr12743392qkb.2.1687216254978; Mon, 19 Jun 2023 16:10:54 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 16:10:54 -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 6/8] mm/gup: Retire follow_hugetlb_page() Date: Mon, 19 Jun 2023 19:10:42 -0400 Message-Id: <20230619231044.112894-7-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?1769174948835504712?= X-GMAIL-MSGID: =?utf-8?q?1769174948835504712?= Now __get_user_pages() should be well prepared to handle thp completely, as long as hugetlb gup requests even without the hugetlb's special path. Time to retire follow_hugetlb_page(). Tweak misc comments to reflect reality of follow_hugetlb_page()'s removal. Signed-off-by: Peter Xu --- fs/userfaultfd.c | 2 +- include/linux/hugetlb.h | 12 --- mm/gup.c | 19 ---- mm/hugetlb.c | 224 ---------------------------------------- 4 files changed, 1 insertion(+), 256 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 7cecd49e078b..ae711f1d7a83 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -427,7 +427,7 @@ vm_fault_t handle_userfault(struct vm_fault *vmf, unsigned long reason) * * We also don't do userfault handling during * coredumping. hugetlbfs has the special - * follow_hugetlb_page() to skip missing pages in the + * hugetlb_follow_page_mask() to skip missing pages in the * FOLL_DUMP case, anon memory also checks for FOLL_DUMP with * the no_page_table() helper in follow_page_mask(), but the * shmem_vm_ops->fault method is invoked even during diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 2e2d89e79d6c..bb5024718fc1 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -133,9 +133,6 @@ int copy_hugetlb_page_range(struct mm_struct *, struct mm_struct *, struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, unsigned long address, unsigned int flags, unsigned int *page_mask); -long follow_hugetlb_page(struct mm_struct *, struct vm_area_struct *, - struct page **, unsigned long *, unsigned long *, - long, unsigned int, int *); void unmap_hugepage_range(struct vm_area_struct *, unsigned long, unsigned long, struct page *, zap_flags_t); @@ -305,15 +302,6 @@ static inline struct page *hugetlb_follow_page_mask( BUILD_BUG(); /* should never be compiled in if !CONFIG_HUGETLB_PAGE*/ } -static inline long follow_hugetlb_page(struct mm_struct *mm, - struct vm_area_struct *vma, struct page **pages, - unsigned long *position, unsigned long *nr_pages, - long i, unsigned int flags, int *nonblocking) -{ - BUG(); - return 0; -} - static inline int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, struct vm_area_struct *dst_vma, diff --git a/mm/gup.c b/mm/gup.c index b50272012e49..e6c1e524bd6b 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -775,9 +775,6 @@ static struct page *follow_page_mask(struct vm_area_struct *vma, * Call hugetlb_follow_page_mask for hugetlb vmas as it will use * special hugetlb page table walking code. This eliminates the * need to check for hugetlb entries in the general walking code. - * - * 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)) return hugetlb_follow_page_mask(vma, address, flags, @@ -1138,22 +1135,6 @@ static long __get_user_pages(struct mm_struct *mm, ret = check_vma_flags(vma, gup_flags); if (ret) goto out; - - if (is_vm_hugetlb_page(vma)) { - i = follow_hugetlb_page(mm, vma, pages, - &start, &nr_pages, i, - gup_flags, locked); - if (!*locked) { - /* - * We've got a VM_FAULT_RETRY - * and we've lost mmap_lock. - * We must stop here. - */ - BUG_ON(gup_flags & FOLL_NOWAIT); - goto out; - } - continue; - } } retry: /* diff --git a/mm/hugetlb.c b/mm/hugetlb.c index fbf6a09c0ec4..da4c76bee01f 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5721,7 +5721,6 @@ static vm_fault_t hugetlb_wp(struct mm_struct *mm, struct vm_area_struct *vma, /* * Return whether there is a pagecache page to back given address within VMA. - * Caller follow_hugetlb_page() holds page_table_lock so we cannot lock_page. */ static bool hugetlbfs_pagecache_present(struct hstate *h, struct vm_area_struct *vma, unsigned long address) @@ -6422,37 +6421,6 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, } #endif /* CONFIG_USERFAULTFD */ -static void record_subpages(struct page *page, struct vm_area_struct *vma, - int refs, struct page **pages) -{ - int nr; - - for (nr = 0; nr < refs; nr++) { - if (likely(pages)) - pages[nr] = nth_page(page, nr); - } -} - -static inline bool __follow_hugetlb_must_fault(struct vm_area_struct *vma, - unsigned int flags, pte_t *pte, - bool *unshare) -{ - pte_t pteval = huge_ptep_get(pte); - - *unshare = false; - if (is_swap_pte(pteval)) - return true; - if (huge_pte_write(pteval)) - return false; - if (flags & FOLL_WRITE) - return true; - if (gup_must_unshare(vma, flags, pte_page(pteval))) { - *unshare = true; - return true; - } - return false; -} - struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, unsigned long address, unsigned int flags, unsigned int *page_mask) @@ -6519,198 +6487,6 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, return page; } -long follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma, - struct page **pages, unsigned long *position, - unsigned long *nr_pages, long i, unsigned int flags, - int *locked) -{ - unsigned long pfn_offset; - unsigned long vaddr = *position; - unsigned long remainder = *nr_pages; - struct hstate *h = hstate_vma(vma); - int err = -EFAULT, refs; - - while (vaddr < vma->vm_end && remainder) { - pte_t *pte; - spinlock_t *ptl = NULL; - bool unshare = false; - int absent; - struct page *page; - - /* - * If we have a pending SIGKILL, don't keep faulting pages and - * potentially allocating memory. - */ - if (fatal_signal_pending(current)) { - remainder = 0; - break; - } - - hugetlb_vma_lock_read(vma); - /* - * Some archs (sparc64, sh*) have multiple pte_ts to - * each hugepage. We have to make sure we get the - * first, for the page indexing below to work. - * - * Note that page table lock is not held when pte is null. - */ - pte = hugetlb_walk(vma, vaddr & huge_page_mask(h), - huge_page_size(h)); - if (pte) - ptl = huge_pte_lock(h, mm, pte); - absent = !pte || huge_pte_none(huge_ptep_get(pte)); - - /* - * When coredumping, it suits get_dump_page if we just return - * an error where there's an empty slot with no huge pagecache - * to back it. This way, we avoid allocating a hugepage, and - * the sparse dumpfile avoids allocating disk blocks, but its - * huge holes still show up with zeroes where they need to be. - */ - if (absent && (flags & FOLL_DUMP) && - !hugetlbfs_pagecache_present(h, vma, vaddr)) { - if (pte) - spin_unlock(ptl); - hugetlb_vma_unlock_read(vma); - remainder = 0; - break; - } - - /* - * We need call hugetlb_fault for both hugepages under migration - * (in which case hugetlb_fault waits for the migration,) and - * hwpoisoned hugepages (in which case we need to prevent the - * caller from accessing to them.) In order to do this, we use - * here is_swap_pte instead of is_hugetlb_entry_migration and - * is_hugetlb_entry_hwpoisoned. This is because it simply covers - * both cases, and because we can't follow correct pages - * directly from any kind of swap entries. - */ - if (absent || - __follow_hugetlb_must_fault(vma, flags, pte, &unshare)) { - vm_fault_t ret; - unsigned int fault_flags = 0; - - if (pte) - spin_unlock(ptl); - hugetlb_vma_unlock_read(vma); - - if (flags & FOLL_WRITE) - fault_flags |= FAULT_FLAG_WRITE; - else if (unshare) - fault_flags |= FAULT_FLAG_UNSHARE; - if (locked) { - fault_flags |= FAULT_FLAG_ALLOW_RETRY | - FAULT_FLAG_KILLABLE; - if (flags & FOLL_INTERRUPTIBLE) - fault_flags |= FAULT_FLAG_INTERRUPTIBLE; - } - if (flags & FOLL_NOWAIT) - fault_flags |= FAULT_FLAG_ALLOW_RETRY | - FAULT_FLAG_RETRY_NOWAIT; - if (flags & FOLL_TRIED) { - /* - * Note: FAULT_FLAG_ALLOW_RETRY and - * FAULT_FLAG_TRIED can co-exist - */ - fault_flags |= FAULT_FLAG_TRIED; - } - ret = hugetlb_fault(mm, vma, vaddr, fault_flags); - if (ret & VM_FAULT_ERROR) { - err = vm_fault_to_errno(ret, flags); - remainder = 0; - break; - } - if (ret & VM_FAULT_RETRY) { - if (locked && - !(fault_flags & FAULT_FLAG_RETRY_NOWAIT)) - *locked = 0; - *nr_pages = 0; - /* - * VM_FAULT_RETRY must not return an - * error, it will return zero - * instead. - * - * No need to update "position" as the - * caller will not check it after - * *nr_pages is set to 0. - */ - return i; - } - continue; - } - - pfn_offset = (vaddr & ~huge_page_mask(h)) >> PAGE_SHIFT; - page = pte_page(huge_ptep_get(pte)); - - VM_BUG_ON_PAGE((flags & FOLL_PIN) && PageAnon(page) && - !PageAnonExclusive(page), page); - - /* - * If subpage information not requested, update counters - * and skip the same_page loop below. - */ - if (!pages && !pfn_offset && - (vaddr + huge_page_size(h) < vma->vm_end) && - (remainder >= pages_per_huge_page(h))) { - vaddr += huge_page_size(h); - remainder -= pages_per_huge_page(h); - i += pages_per_huge_page(h); - spin_unlock(ptl); - hugetlb_vma_unlock_read(vma); - continue; - } - - /* vaddr may not be aligned to PAGE_SIZE */ - refs = min3(pages_per_huge_page(h) - pfn_offset, remainder, - (vma->vm_end - ALIGN_DOWN(vaddr, PAGE_SIZE)) >> PAGE_SHIFT); - - if (pages) - record_subpages(nth_page(page, pfn_offset), - vma, refs, - likely(pages) ? pages + i : NULL); - - if (pages) { - /* - * try_grab_folio() should always succeed here, - * because: a) we hold the ptl lock, and b) we've just - * checked that the huge page is present in the page - * tables. If the huge page is present, then the tail - * pages must also be present. The ptl prevents the - * head page and tail pages from being rearranged in - * any way. As this is hugetlb, the pages will never - * be p2pdma or not longterm pinable. So this page - * must be available at this point, unless the page - * refcount overflowed: - */ - if (WARN_ON_ONCE(!try_grab_folio(pages[i], refs, - flags))) { - spin_unlock(ptl); - hugetlb_vma_unlock_read(vma); - remainder = 0; - err = -ENOMEM; - break; - } - } - - vaddr += (refs << PAGE_SHIFT); - remainder -= refs; - i += refs; - - spin_unlock(ptl); - hugetlb_vma_unlock_read(vma); - } - *nr_pages = remainder; - /* - * setting position is actually required only if remainder is - * not zero but it's faster not to add a "if (remainder)" - * branch. - */ - *position = vaddr; - - return i ? i : err; -} - long hugetlb_change_protection(struct vm_area_struct *vma, unsigned long address, unsigned long end, pgprot_t newprot, unsigned long cp_flags) From patchwork Mon Jun 19 23:10:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 110184 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3304435vqr; Mon, 19 Jun 2023 16:14:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Nk5V3ZeUzmh/sjx0TlGmeRNW8yxXWaOTHTIt05qnLDGEqNUi5nGUKR9Nafgm26Lhoc8bs X-Received: by 2002:a05:6a00:22d6:b0:668:7fb2:d99d with SMTP id f22-20020a056a0022d600b006687fb2d99dmr2812897pfj.24.1687216460175; Mon, 19 Jun 2023 16:14:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687216460; cv=none; d=google.com; s=arc-20160816; b=AfffcTkU/a+ujNMedWY6vm/qi9+xjx/jyhlOKMsAcrs4uOSQdMb0/yus6xxfFOkctF sDS0aPcmlWaDVaoknJ/vGlpkntZpeQ72h5MRSd5O5CkJIMJlgiNbLNPWWezgQrLnOiQj 33Nb7Fdsr+a7BrHCS9GKzbNmp8Kk72MewYdVFVfz43BoqjnrrAQpU+c+MDP5RmL0qEI3 p8Oxn6G0L0ytx9W9Rw55ar+zfzRHnaDBH+o6mI/5vHZX26BNxrJhyICRCHHF4PPLNOGU wEJ+l0I0KlB25vZW9gDWoKo5nqzWQRX45HypYZzzAQKAyxi8qdkbroh+OCdSwLRRgWmv FiFA== 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=3EQ9G/WyCR5BzbeYKEOc/c4ex09bzeUnnwnMR75AIjI=; b=K9Bed4oW2hy5RrGKjVhxnhUlGuL0B2uCVCU32j3YSMeus02gR3G2nzSeMlrCvzikKV rzXFUY7y4nkhm57QfPrVc3Id3GZwjFmRewHZ0p4/vukunVnCQjRlJQfAgw309QbEb4E0 wSaRDq6uoxLdBOj9ZNuI4yQo1b8K2TRqlFvuUi0n4QugJQg9p2Fehbg1kij4RNDYFs1q hBg8ztqfZ8DRhtWS9MJctnvYNi+hCyjUtE7B6hORcOgK5V6lvuzKjeixwPb0mIbg6jGY 8oniFaU3eefVL3U++iV0ATzMifZW+yJDMVuekg8pHAutlCR5LfhPRd6bo8PWfxuwjnwj cyAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=M88cQhai; 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 o6-20020aa79786000000b0064f7eb606f4si364568pfp.369.2023.06.19.16.14.07; Mon, 19 Jun 2023 16:14:20 -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=M88cQhai; 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 S229843AbjFSXMC (ORCPT + 99 others); Mon, 19 Jun 2023 19:12:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229784AbjFSXLo (ORCPT ); Mon, 19 Jun 2023 19:11:44 -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 76DFDE6C for ; Mon, 19 Jun 2023 16:10:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687216258; 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=3EQ9G/WyCR5BzbeYKEOc/c4ex09bzeUnnwnMR75AIjI=; b=M88cQhai4OsCyETed1vR9EwN40oL2oyty2cgTKtukIKUS+SSmXrAgcBq88xeE0ROqLxFgv ok/MVC+6aPpG1eXcCt5+YL6bWwvIGJuVnyjg68VzjuZYpRe/YWTeJ9jf0Tw67wdeoxr++4 FOj9oirxKOhZAJuPj5gBZM4SkWTOiSM= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-617-fECThjJKPNa7mK2VvHfJTA-1; Mon, 19 Jun 2023 19:10:57 -0400 X-MC-Unique: fECThjJKPNa7mK2VvHfJTA-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-3fde794cd50so5980721cf.1 for ; Mon, 19 Jun 2023 16:10:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687216257; x=1689808257; 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=3EQ9G/WyCR5BzbeYKEOc/c4ex09bzeUnnwnMR75AIjI=; b=XErrbztvtNkkdYevFOcVfg/GyMY/og/9VM6Ls5s541AwLi2bAIi0ehmwJ23f7D2qwT CRrrinkRfLpPcXB65CGqKPjXXoZJqDrvuS/QKmNo3ZPsUSsXUE3o88JlXkAPXXKiuWBg LcKsDX6KlRNI33GBjUQ2PvrIgCM+8tHt1+frwU+8Ua4RIwxBvBtvFczxs+6jGFhvqlCr 1uKW4OS4OKqsJ/hUoYOZYVs0hUXkN6nZ0AnYrE3mqPQHUtF8d5t15iXZx1wkIHdqrBoZ xrGQmhPh+4O9xNtV7wV9M90HaHwGcA4ZVjgpNsUONvfPCaLLSOYR+746RaeXygY16yIp y/7w== X-Gm-Message-State: AC+VfDx5B6ZEyxs6kx0X7aYk/Vs2BlZ7v+a3KCPWXRp8x6+mpBsdsc06 2m3vS7RY8gQM9+cIHrxQs4Ls5nufoMMtOHRVZyLgxkgBflPTpRYcZ27HPGFh28HeCgq5k5BH44F fmsALLdaHr43/nUUlp5afHBVC X-Received: by 2002:a05:6214:411c:b0:62d:f62b:907 with SMTP id kc28-20020a056214411c00b0062df62b0907mr14179212qvb.0.1687216256827; Mon, 19 Jun 2023 16:10:56 -0700 (PDT) X-Received: by 2002:a05:6214:411c:b0:62d:f62b:907 with SMTP id kc28-20020a056214411c00b0062df62b0907mr14179194qvb.0.1687216256500; Mon, 19 Jun 2023 16:10:56 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 16:10:56 -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 7/8] selftests/mm: Add -a to run_vmtests.sh Date: Mon, 19 Jun 2023 19:10:43 -0400 Message-Id: <20230619231044.112894-8-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, 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?1769174686870338976?= X-GMAIL-MSGID: =?utf-8?q?1769174686870338976?= Allows to specify optional tests in run_vmtests.sh, where we can run time consuming test matrix only when user specified "-a". Signed-off-by: Peter Xu --- tools/testing/selftests/mm/run_vmtests.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh index 3f26f6e15b2a..824e651f62f4 100644 --- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -12,11 +12,14 @@ exitcode=0 usage() { cat <"] +usage: ${BASH_SOURCE[0]:-$0} [ options ] + + -a: run all tests, including extra ones -t: specify specific categories to tests to run -h: display this message -The default behavior is to run all tests. +The default behavior is to run required tests only. If -a is specified, +will run all tests. Alternatively, specific groups tests can be run by passing a string to the -t argument containing one or more of the following categories @@ -60,9 +63,11 @@ EOF exit 0 } +RUN_ALL=false -while getopts "ht:" OPT; do +while getopts "aht:" OPT; do case ${OPT} in + "a") RUN_ALL=true ;; "h") usage ;; "t") VM_SELFTEST_ITEMS=${OPTARG} ;; esac From patchwork Mon Jun 19 23:10:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 110185 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3304549vqr; Mon, 19 Jun 2023 16:14:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ73ooYCnu6pNkVgsixYa8sKb727YnOjHk5vwBW2c/iFRC3yF9fIl2R7PBnxs4M1A8ejGQsb X-Received: by 2002:a05:6a21:6d96:b0:121:56aa:82d6 with SMTP id wl22-20020a056a216d9600b0012156aa82d6mr5890283pzb.22.1687216474799; Mon, 19 Jun 2023 16:14:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687216474; cv=none; d=google.com; s=arc-20160816; b=H/zTo8yCSVsrNFtS/TEc2LPKtvQPUi4WTJ48FkF3nkwiObMwa6mr1kFKN/45l7GYja 2A06wzp9XXey69cgwlj4tboUjc8Cn2xkceYVxDQ3KYtQ+cPcDH/kQ/fCAdO7Sz772eJe +KnUo0srhX7M+XQwQNfGN43T+N6WTI0XTnSYCKdgaua/SdSd+MQGMv812sLh8ij7JxQp G3UYA3U8UMuExfaMrXc7BF4Syx3dbdhoilkj84xdEAkWXsbany/wGZHF6EA5x9bcF4yr VXraeSx08ztjONM1kzJZobYeOKi99S6IOBA1qD8jZXzEOBbBX8BjX7YVRnKj2Xsr2HJ4 b7HQ== 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=lJajW3CLipjyQ640k+WW23diII/jzqCXLm/r+yoabGU=; b=ueDt0/QI99JqQuWFbM4Hsk55ziSqMeW59883YnuF1J0eMqhm3qRiwum7jvXu64WaTK wmOtTz2zYN54e5sC9srwkskWmevow+Qw8G5kyHye8/GybJKQZEMVae1eBeTtdgR2Gt8S tQrTp17Gc33inKhWrOUtxKWsv0uf10i2b9KaUtv2RQCQsklbKZXrQMkxiS952PYQfrOD zUj7Om7dfhjwtIh7TMUYp8xdRqmiH3zf/GdSAeFJvosaq4YrXVN3hL6T8mV+F85f8SNX 2Slda1p0z+RXJjxKItox1UgEWFZjj4zg0R6NymaMfEr/moRdc11vSgGELw+TEV0aadjs DVSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ScTonLJP; 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 n17-20020a170902d2d100b001ac68acb1e8si690074plc.518.2023.06.19.16.14.22; Mon, 19 Jun 2023 16:14:34 -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=ScTonLJP; 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 S229784AbjFSXMk (ORCPT + 99 others); Mon, 19 Jun 2023 19:12:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229923AbjFSXMV (ORCPT ); Mon, 19 Jun 2023 19:12:21 -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 918BEE6E for ; Mon, 19 Jun 2023 16:11:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687216259; 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=lJajW3CLipjyQ640k+WW23diII/jzqCXLm/r+yoabGU=; b=ScTonLJPeCP5RcZsSjBU1fqNCsI1OK2Fxwbgp61vS/mHZwA2U2DjFvNmUWE+rf2Vg7sGgh vMVI7+lMLOodGnQx8p0pb16l/qPFG4QOx/1ZDy3R+POIhpTrQnN+TDA1GNAFRf24mFG+fw crYMmzrorQYffrGehFKmVpRPVUyPY9s= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-646-Gm_WOQplN3i02Nm-V8_UgA-1; Mon, 19 Jun 2023 19:10:58 -0400 X-MC-Unique: Gm_WOQplN3i02Nm-V8_UgA-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-7625940fbf3so29808785a.0 for ; Mon, 19 Jun 2023 16:10:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687216258; x=1689808258; 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=lJajW3CLipjyQ640k+WW23diII/jzqCXLm/r+yoabGU=; b=R8jv0i9LiQpFdxOaiRX4+ZI5ZSTPp0D3ENp92HJj6/P1PVwXlcKSfseE0HQRTRURGc GnUYxoHYTOsKgDK6e4inegt2fJ2f9wqOSgzn3OlrtGg7Uvo8ed9JEdQf6fjeB5vg3t9Y TK0hlCk4y47QNs0cmq2vwh7kFhZqVjMkKS3eEUH/HCLqWUcipWt9lsAXPwjCtPqvw1HD y8CXBqTetItXwyWdQ9L5ZUXzerqbO+B3VO2l/fTwHLHSbXh2aw33DxqaOZKZ2znvR+E4 UtvFGpAtI8czD/kXhYOt9T4xzi2r6gsdlRsJWOxM+kNXZUXDkZDK7iD2MJuIxg6W7DOC 9C9w== X-Gm-Message-State: AC+VfDxy40OVICivyymhJn7wX68bG1oGbsMeN7NoyyYqjPd8XPFs7kVb SOUAfLBoyBfJ72M3MRnoKBPexANujDRl9KZsDgacoKxWTRq2/8iJybbTRBtyTxuCSNAuf/hpzjc Ylk0pLljTMUM7ZsRkYALjw2b+ X-Received: by 2002:a05:620a:4104:b0:762:63b:e10b with SMTP id j4-20020a05620a410400b00762063be10bmr14345380qko.1.1687216258220; Mon, 19 Jun 2023 16:10:58 -0700 (PDT) X-Received: by 2002:a05:620a:4104:b0:762:63b:e10b with SMTP id j4-20020a05620a410400b00762063be10bmr14345358qko.1.1687216257943; Mon, 19 Jun 2023 16:10:57 -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.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 16:10:57 -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 8/8] selftests/mm: Add gup test matrix in run_vmtests.sh Date: Mon, 19 Jun 2023 19:10:44 -0400 Message-Id: <20230619231044.112894-9-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?1769174702497487945?= X-GMAIL-MSGID: =?utf-8?q?1769174702497487945?= Add a matrix for testing gup based on the current gup_test. Only run the matrix when -a is specified because it's a bit slow. It covers: - Different types of huge pages: thp, hugetlb, or no huge page - Permissions: Write / Read-only - Fast-gup, with/without - Types of the GUP: pin / gup / longterm pins - Shared / Private memories - GUP size: 1 / 512 / random page sizes Signed-off-by: Peter Xu --- tools/testing/selftests/mm/run_vmtests.sh | 37 ++++++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh index 824e651f62f4..9666c0c171ab 100644 --- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -90,6 +90,30 @@ test_selected() { fi } +run_gup_matrix() { + # -t: thp=on, -T: thp=off, -H: hugetlb=on + local hugetlb_mb=$(( needmem_KB / 1024 )) + + for huge in -t -T "-H -m $hugetlb_mb"; do + # -u: gup-fast, -U: gup-basic, -a: pin-fast, -b: pin-basic, -L: pin-longterm + for test_cmd in -u -U -a -b -L; do + # -w: write=1, -W: write=0 + for write in -w -W; do + # -S: shared + for share in -S " "; do + # -n: How many pages to fetch together? 512 is special + # because it's default thp size (or 2M on x86), 123 to + # just test partial gup when hit a huge in whatever form + for num in "-n 1" "-n 512" "-n 123"; do + CATEGORY="gup_test" run_test ./gup_test \ + $huge $test_cmd $write $share $num + done + done + done + done + done +} + # get huge pagesize and freepages from /proc/meminfo while read -r name size unit; do if [ "$name" = "HugePages_Free:" ]; then @@ -194,13 +218,16 @@ fi CATEGORY="mmap" run_test ./map_fixed_noreplace -# get_user_pages_fast() benchmark -CATEGORY="gup_test" run_test ./gup_test -u -# pin_user_pages_fast() benchmark -CATEGORY="gup_test" run_test ./gup_test -a +if $RUN_ALL; then + run_gup_matrix +else + # get_user_pages_fast() benchmark + CATEGORY="gup_test" run_test ./gup_test -u + # pin_user_pages_fast() benchmark + CATEGORY="gup_test" run_test ./gup_test -a +fi # Dump pages 0, 19, and 4096, using pin_user_pages: CATEGORY="gup_test" run_test ./gup_test -ct -F 0x1 0 19 0x1000 - CATEGORY="gup_test" run_test ./gup_longterm CATEGORY="userfaultfd" run_test ./uffd-unit-tests