From patchwork Fri Aug 13 04:41:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Hubbard X-Patchwork-Id: 12434701 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED94DC4320E for ; Fri, 13 Aug 2021 04:41:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 99937610A5 for ; Fri, 13 Aug 2021 04:41:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 99937610A5 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 37F068D0002; Fri, 13 Aug 2021 00:41:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 32EFE6B0071; Fri, 13 Aug 2021 00:41:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D0678D0002; Fri, 13 Aug 2021 00:41:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0050.hostedemail.com [216.40.44.50]) by kanga.kvack.org (Postfix) with ESMTP id 0492D6B006C for ; Fri, 13 Aug 2021 00:41:38 -0400 (EDT) Received: from smtpin34.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id A7EF71690D for ; Fri, 13 Aug 2021 04:41:38 +0000 (UTC) X-FDA: 78468809076.34.CA11158 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2073.outbound.protection.outlook.com [40.107.237.73]) by imf17.hostedemail.com (Postfix) with ESMTP id 567DEF006759 for ; Fri, 13 Aug 2021 04:41:38 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NaArGSSh2WgxIf/NZgayKZYGwFfluJPeE6JiZ6snT3hJAGY8MbXrmtzqik04s0X9buPLX2CFNbzW9eXzHCtEap35YnlWr48iyqnNdrXcvjBXpx09sLjHjqHl2swDfU1eLskzvUdLlrk2L9+eJasVt7eqguYuLynUFdo7fH3RQ7pkNi4X8ET8dJSj4VFQzt7m1uCUcTsJfx84TjDXc8yL5QQ29AP8/XyF5DkRMk3wYCjJvxkB+U+KspG8bSElEgrJnmFN4r/ZgipksQC2x9HUmyC8YrYkNnWOE23LrPQxtIAJzIr91Pm8LpsFmStSKOWQjng/1rq6XIzXYrHB8PC1Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TBxDzvWl/c/IHWxMVFXMKwj27YOd/yVk3L+q5DJEkWs=; b=deMOq6BkjFnKFAkoBlkBU+rH6K9NzgZAma+q8yVtDDyMEY31V/SKA/4a7HlYrS2GbN26KhE/AuCPDFY0ZLrBrhU5FuJVK2XBRNaahstIIkJJPk81ibcWes5R8mihOk4Wvto8DhQBCTRWy0hrGOTzbTIRJA0CfwQyR5e42Gig2ntLF/SHjNMcAsgZdJPRG/HJEcX4zVjTtNv/K/XUf8+TomCxqOlPUwZcmV25Ew7W2QxlRsd7+rzTqHs8V1xLSrJOozGBV3Mn3qV5WbVgbvtJQY+ztLkdVN63A3y2ommsua2QWzYLi7ZiUCXGXa6F82jhVX9YMJjZxPAQHT8Rd3ei9g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TBxDzvWl/c/IHWxMVFXMKwj27YOd/yVk3L+q5DJEkWs=; b=OzzxVNTsqF0y9CM8m749T9kUaMpKp3SZbg3g1J/yskPHUIJ1LnmtaO12BtZyUiWdDnykcNKRvS8neUu9fCZCk5KyP6W7mbxWe80NiMhePqDrWrrLBoJxRCGUIb/1QX3ZT2GQcP02ouOH5jzuRPtbChULAHdOUmc1iu+Mrd6srq2mdJspHGe6q8FucDmuCjHzdGmA+Edfly6gwkCAJjXYf0BnKd/5CCcCeXjmznWSrsfu39Jbcijeqfu4FvyWCkdsEV6pBRmmNdVz8ylLmytLjbOpr4fyfkxGYUqYoM5jU+r5UaDA2aeq3f2J1ajjqpCj2RhHtcSwAchfcWq+xua6KA== Received: from BN9PR03CA0076.namprd03.prod.outlook.com (2603:10b6:408:fc::21) by BN9PR12MB5099.namprd12.prod.outlook.com (2603:10b6:408:118::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.16; Fri, 13 Aug 2021 04:41:36 +0000 Received: from BN8NAM11FT016.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fc:cafe::eb) by BN9PR03CA0076.outlook.office365.com (2603:10b6:408:fc::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.17 via Frontend Transport; Fri, 13 Aug 2021 04:41:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by BN8NAM11FT016.mail.protection.outlook.com (10.13.176.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4415.14 via Frontend Transport; Fri, 13 Aug 2021 04:41:36 +0000 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 12 Aug 2021 21:41:35 -0700 Received: from sandstorm.attlocal.net (172.20.187.5) by mail.nvidia.com (172.20.187.13) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 13 Aug 2021 04:41:35 +0000 From: John Hubbard To: Andrew Morton CC: Matthew Wilcox , Christoph Hellwig , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , LKML , , , , John Hubbard Subject: [PATCH v3 3/3] mm/gup: Remove try_get_page(), call try_get_compound_head() directly Date: Thu, 12 Aug 2021 21:41:33 -0700 Message-ID: <20210813044133.1536842-4-jhubbard@nvidia.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210813044133.1536842-1-jhubbard@nvidia.com> References: <20210813044133.1536842-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 76314af1-ad14-4db4-0d81-08d95e14a265 X-MS-TrafficTypeDiagnostic: BN9PR12MB5099: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PxwZtv+fXudGMB3gGfMvgCyAj29gbEhM+b4t3uuf8WF6NqHb++VuuJWqinNeqjjgk+NXh+lWcz9Z7DVBJ2h14dV0BDIFgHAk/XoiYtSHle7g1hNzp39WUyy3KZhTc+xv2gUhoWgEJ2qmL9SMnVLyiv5ijbLkeWwwOqtEMNpxaMqhcgVbf8UTKiPt2vSiO+7MIbaui5BdMd2xKbQZtdkf9Zgsk4WJ1zIMFaS3kxzQibtyz8LUOfVU+hsd6hBcOwiGgnjvOiu2nT++/8K9MU+QSHbE0RppnOm0Iz0gsQ+dhZBSRAIU3S1HyWwpONJ1T/pJW55DAlRxBJKSSaIdyiIDc9ig3ykbkOWxGo9lt2HugsAvVBAI0lLU+XzZSLEGtnpNwEAsJb9sjikqRL8miVoouU4s1HkcD20FuMJy5w8gGJ0DiYk2HmIy4DjlgvmUE0vf8OO/NcyyStZBJpwAAObzLdYQsW4G8tnXkgVm7oCI3OlHucoJw/MYgQwSJbmjq6rmWm4pfWF8d8SvJt0c9YLiB0xYmTSYg9ef5jbFYhRkiTVeR6qhuHe03orgslCztFSNq8zqwO1C6oumKhhBFP2lNLRjKu8X12SAW0AAc0wSAZYIMYN/mNL2wbqZUpDNqJ2Wn8GIiihnJ51RImXc0kt5MWAUSDdtc7n6KXAHeOfxVYbL6rJ5PfSPK8w41Im4alMcPKioOK/usiSqGy06VcSb8g== X-Forefront-Antispam-Report: CIP:216.228.112.32;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid01.nvidia.com;CAT:NONE;SFS:(4636009)(136003)(39860400002)(376002)(396003)(346002)(46966006)(36840700001)(82740400003)(70586007)(7636003)(186003)(7416002)(36860700001)(70206006)(86362001)(4326008)(426003)(82310400003)(336012)(2906002)(83380400001)(356005)(54906003)(2616005)(47076005)(5660300002)(316002)(8676002)(6916009)(1076003)(36756003)(26005)(8936002)(107886003)(478600001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Aug 2021 04:41:36.3875 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 76314af1-ad14-4db4-0d81-08d95e14a265 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.32];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT016.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5099 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 567DEF006759 X-Stat-Signature: 1r37qcip8fawtqsunz4jkt5zzgerwsbm Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=OzzxVNTs; dmarc=pass (policy=quarantine) header.from=nvidia.com; spf=none (imf17.hostedemail.com: domain of jhubbard@nvidia.com has no SPF policy when checking 40.107.237.73) smtp.mailfrom=jhubbard@nvidia.com X-HE-Tag: 1628829698-71627 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: try_get_page() is very similar to try_get_compound_head(), and in fact try_get_page() has fallen a little behind in terms of maintenance: try_get_compound_head() handles speculative page references more thoroughly. There are only two try_get_page() callsites, so just call try_get_compound_head() directly from those, and remove try_get_page() entirely. Also, seeing as how this changes try_get_compound_head() into a non-static function, provide some kerneldoc documentation for it. Cc: Matthew Wilcox Reviewed-by: Christoph Hellwig Signed-off-by: John Hubbard --- arch/s390/mm/fault.c | 2 +- fs/pipe.c | 2 +- include/linux/mm.h | 10 +--------- mm/gup.c | 21 +++++++++++++++++---- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c index 212632d57db9..a834e4672f72 100644 --- a/arch/s390/mm/fault.c +++ b/arch/s390/mm/fault.c @@ -822,7 +822,7 @@ void do_secure_storage_access(struct pt_regs *regs) break; case KERNEL_FAULT: page = phys_to_page(addr); - if (unlikely(!try_get_page(page))) + if (unlikely(!try_get_compound_head(page, 1))) break; rc = arch_make_page_accessible(page); put_page(page); diff --git a/fs/pipe.c b/fs/pipe.c index 8e6ef62aeb1c..4394b80dc84f 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -191,7 +191,7 @@ EXPORT_SYMBOL(generic_pipe_buf_try_steal); */ bool generic_pipe_buf_get(struct pipe_inode_info *pipe, struct pipe_buffer *buf) { - return try_get_page(buf->page); + return try_get_compound_head(buf->page, 1); } EXPORT_SYMBOL(generic_pipe_buf_get); diff --git a/include/linux/mm.h b/include/linux/mm.h index ba985eaf3f19..f5ab4fd6d48c 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1207,15 +1207,7 @@ bool __must_check try_grab_page(struct page *page, unsigned int flags); struct page *try_grab_compound_head(struct page *page, int refs, unsigned int flags); - -static inline __must_check bool try_get_page(struct page *page) -{ - page = compound_head(page); - if (WARN_ON_ONCE(page_ref_count(page) <= 0)) - return false; - page_ref_inc(page); - return true; -} +struct page *try_get_compound_head(struct page *page, int refs); /** * folio_put - Decrement the reference count on a folio. diff --git a/mm/gup.c b/mm/gup.c index 886d6148d3d0..7a406d79bd2e 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -62,11 +62,24 @@ static void put_page_refs(struct page *page, int refs) put_page(page); } -/* - * Return the compound head page with ref appropriately incremented, - * or NULL if that failed. +/** + * try_get_compound_head() - return the compound head page with refcount + * appropriately incremented, or NULL if that failed. + * + * This handles potential refcount overflow correctly. It also works correclty + * for various lockless get_user_pages()-related callers, due to the use of + * page_cache_add_speculative(). + * + * Even though the name includes "compound_head", this function is still + * appropriate for callers that have a non-compound @page to get. + * + * @page: pointer to page to be gotten + * @refs: the value to add to the page's refcount + * + * Return: head page (with refcount appropriately incremented) for success, or + * NULL upon failure. */ -static inline struct page *try_get_compound_head(struct page *page, int refs) +struct page *try_get_compound_head(struct page *page, int refs) { struct page *head = compound_head(page);