From patchwork Wed Mar 27 15:23:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13606827 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4FF1BCD1284 for ; Wed, 27 Mar 2024 15:25:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=51JLFXZ3fpY3t7YZqbu9rItsSLiHQuX5op9RTk0R3/g=; b=YQh096j9D6neGd Rp5Pr1X66brX86eUqJNq8E+c47fDtDcMLGRntxbVlOYHngni05O7TwZZVULx0K+9rMpWRPqeUJ5kE XfIUFD0iekwHtX72cQiqdf1Dc15mG+TOAVfJqkWthJx8u6R5wmJokH3Xu/9Dqs/edfZ69TfmKN3JJ WComAN1EtwLXHZO2dZTt6JsV3tkcFGUAzyUuzfeM8t7F4F57Wv5qDRjtB/pyzk/BYFFHDQ+1TeO4c nDNb79k5sgG/gxvQZYBnksUHL54r9VeYS3wHMmlk19k9LNu1RoEXMXZPV/xnd+65YqDjX4KpMhEkd uotN6H86jzBeZU/PCpgg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpV9X-00000009mP3-32lW; Wed, 27 Mar 2024 15:25:23 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpV89-00000009lRX-1RdN for linux-arm-kernel@bombadil.infradead.org; Wed, 27 Mar 2024 15:23:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Content-Transfer-Encoding :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=gD68z8/n0HSMW69QF19tjjGBtDgz4n3uypdcneHmRPc=; b=FuBiZQjP59v4kXTXfXU/PkGbt5 pnFjgPZzCDl7EALqxJhkijIjYUDQOjiNx6EWqoAsYdJsPbXUAfHxVc+Za0TG6LOenK5xMRwgzOfOj +lGlcS1KUWsIkO812zW4iXVYLkKQgQ3tDR6jnAEpdYzb74QdFgYh+0sQix3OrSUL/5O22rUUhXrkk H4MG5y1xkc7e+YRQCFFy3lUKzc1FB4tbR3yNCBjBhmtIW3NeIV76UhL2zqRb+lrR1FfC1fe5b1wXX PYTaJHNRhe9Av+FOfPYn54wAk5wO0akcN7XTm3Kk8mFGPzBBjx22n3PucNS0uR1wX+Kl0yz/kmltn BTM7cz1Q==; Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpV83-00000000L1g-44a8 for linux-arm-kernel@lists.infradead.org; Wed, 27 Mar 2024 15:23:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711553030; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gD68z8/n0HSMW69QF19tjjGBtDgz4n3uypdcneHmRPc=; b=URgRD63zRlDW9Tzk+yUQ6m3s3RquSQHPR4IFpodqqffSs0LHiUOuLjiK6wv7x74UWV7Q2Y 2SpzviHmAdtRg0QSfjeXuXA2cdvaXc7EASWvJ+xiwT5C3UfhzBpNDl0zarUubyu3//ICWm vVfDBpawqWWrgLfaqylb7D5lbY1wNxM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711553031; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gD68z8/n0HSMW69QF19tjjGBtDgz4n3uypdcneHmRPc=; b=MmVWvOTmTU6nujh5vqCWOvh40F2hfZGnujaJOTLKSL1yFnAGxQ4g3uLfFiByr/zlkmcOQY ilQbcnWPImt4PEV4bgatJGE6JiNqgsB0sGlqJhncvrw/Z5NtDTHzinR+sWw6JzChrB51nU VvMjCL3Zn3JP7dFwbrsQZySMmR31jtA= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-681-y677CfHiNmKYwRQgIJnWGg-1; Wed, 27 Mar 2024 11:23:49 -0400 X-MC-Unique: y677CfHiNmKYwRQgIJnWGg-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-690c19ee50bso2422036d6.0 for ; Wed, 27 Mar 2024 08:23:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711553029; x=1712157829; 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=gD68z8/n0HSMW69QF19tjjGBtDgz4n3uypdcneHmRPc=; b=k4tKwdEDSBH+G08nKdzLni59Ah7VxVj/HAFjpNdp8JFLfKSExiF5ljNjeQXZ85svY+ 7LVdkMwc8ApRf3m5GvCopaEXLyuMsphyZnY5EjPtKLP4uv40eaarRN5tEfc8fMXkN9nR mSHgIy/ln6nZD5wl6CLCxm95w/7rp8euBaeLuq1j8fPMfV1kU2Oupb3Cw2dgWrAMShv1 Omdj3toh3852yLImFGazkqqH8fC5gIt6tZVJCgGLT4kwrOQXmAWAfd716jq+IJUxq7Y7 y+mnq+QoDrv2+UDe4C7M0NQRwxCZYfpHOuAw4//yeLjid4cmddsrxNeY9HW68Btwusvk o0ZA== X-Forwarded-Encrypted: i=1; AJvYcCV7z4sWif0xZY1Izi3ctVZ/RpGOa26fpQ8gewac1YrenAHGxR665c4XvL9sN2zwIwGbOGCfcd/laldgvDuR1oudezUyMIXRfRCTAE0RN/ykUHhr38c= X-Gm-Message-State: AOJu0YyIKD9HszlXzSOYEVCF5mbby+Ome7x0qN3VyEJK7StdfdbDVKtk C58XnKKMRbuxzXWBYGPUorrxMylGIDP/QUzHQiG58brO3qKSJNzyvisZiL56iGtmS8unyBg3mLf NK7VTufMyAx3piwgNNVWaPHZq/Ds4EB1mMcmH7wdNXpPTHkPT/NQVnRBFDPJnaztTuIST4LRO X-Received: by 2002:a05:6214:3a01:b0:696:81b8:a462 with SMTP id nw1-20020a0562143a0100b0069681b8a462mr13234469qvb.0.1711553028776; Wed, 27 Mar 2024 08:23:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFaIIFSwEPr6utJECaPIJXCgmHTkHVcLUQEzRJpciko/79sjH/yOlRx7KIof08fJkHOKzrhqQ== X-Received: by 2002:a05:6214:3a01:b0:696:81b8:a462 with SMTP id nw1-20020a0562143a0100b0069681b8a462mr13234423qvb.0.1711553028305; Wed, 27 Mar 2024 08:23:48 -0700 (PDT) Received: from x1n.redhat.com ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id hu4-20020a056214234400b00690dd47a41csm6412639qvb.86.2024.03.27.08.23.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 08:23:47 -0700 (PDT) From: peterx@redhat.com To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Yang Shi , "Kirill A . Shutemov" , Mike Kravetz , John Hubbard , Michael Ellerman , peterx@redhat.com, Andrew Jones , Muchun Song , linux-riscv@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, Christophe Leroy , Andrew Morton , Christoph Hellwig , Lorenzo Stoakes , Matthew Wilcox , Rik van Riel , linux-arm-kernel@lists.infradead.org, Andrea Arcangeli , David Hildenbrand , "Aneesh Kumar K . V" , Vlastimil Babka , James Houghton , Jason Gunthorpe , Mike Rapoport , Axel Rasmussen Subject: [PATCH v4 06/13] mm/gup: Drop folio_fast_pin_allowed() in hugepd processing Date: Wed, 27 Mar 2024 11:23:25 -0400 Message-ID: <20240327152332.950956-7-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240327152332.950956-1-peterx@redhat.com> References: <20240327152332.950956-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240327_152353_789962_4905B9C6 X-CRM114-Status: GOOD ( 17.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Peter Xu Hugepd format for GUP is only used in PowerPC with hugetlbfs. There are some kernel usage of hugepd (can refer to hugepd_populate_kernel() for PPC_8XX), however those pages are not candidates for GUP. Commit a6e79df92e4a ("mm/gup: disallow FOLL_LONGTERM GUP-fast writing to file-backed mappings") added a check to fail gup-fast if there's potential risk of violating GUP over writeback file systems. That should never apply to hugepd. Considering that hugepd is an old format (and even software-only), there's no plan to extend hugepd into other file typed memories that is prone to the same issue. Drop that check, not only because it'll never be true for hugepd per any known plan, but also it paves way for reusing the function outside fast-gup. To make sure we'll still remember this issue just in case hugepd will be extended to support non-hugetlbfs memories, add a rich comment above gup_huge_pd(), explaining the issue with proper references. Cc: Christoph Hellwig Cc: Lorenzo Stoakes Cc: Michael Ellerman Cc: linuxppc-dev@lists.ozlabs.org Signed-off-by: Peter Xu --- mm/gup.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index e7510b6ce765..db35b056fc9a 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2832,11 +2832,6 @@ static int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr, return 0; } - if (!folio_fast_pin_allowed(folio, flags)) { - gup_put_folio(folio, refs, flags); - return 0; - } - if (!pte_write(pte) && gup_must_unshare(NULL, flags, &folio->page)) { gup_put_folio(folio, refs, flags); return 0; @@ -2847,6 +2842,14 @@ static int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr, return 1; } +/* + * NOTE: currently GUP for a hugepd is only possible on hugetlbfs file + * systems on Power, which does not have issue with folio writeback against + * GUP updates. When hugepd will be extended to support non-hugetlbfs or + * even anonymous memory, we need to do extra check as what we do with most + * of the other folios. See writable_file_mapping_allowed() and + * folio_fast_pin_allowed() for more information. + */ static int gup_huge_pd(hugepd_t hugepd, unsigned long addr, unsigned int pdshift, unsigned long end, unsigned int flags, struct page **pages, int *nr)