From patchwork Thu Nov 21 03:49:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Hubbard X-Patchwork-Id: 13881608 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1801D75BA7 for ; Thu, 21 Nov 2024 03:49:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3788B6B007B; Wed, 20 Nov 2024 22:49:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 329376B0083; Wed, 20 Nov 2024 22:49:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A2216B0085; Wed, 20 Nov 2024 22:49:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id F03076B007B for ; Wed, 20 Nov 2024 22:49:48 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 913E8140F8E for ; Thu, 21 Nov 2024 03:49:48 +0000 (UTC) X-FDA: 82808722164.18.C5C221E Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2076.outbound.protection.outlook.com [40.107.223.76]) by imf25.hostedemail.com (Postfix) with ESMTP id 07D2FA0005 for ; Thu, 21 Nov 2024 03:49:07 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b="EV6/X8xf"; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf25.hostedemail.com: domain of jhubbard@nvidia.com designates 40.107.223.76 as permitted sender) smtp.mailfrom=jhubbard@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732160739; h=from:from:sender: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: references:dkim-signature; bh=Ev5FmAIzpZYSjnRVgilauia7Iu/E86hqcf2/cWen3/4=; b=CkPWz3VyLCDwAPKKV1K0RYdr5ayS6MhFbaZzLsf2vKqEdfTkDTvc30ZkV+lPNnjknSss8D Cp3FteT5Z9NPBLjWNF4SGfI58lqm9fe6FKnoeqP2rGn1NBeVOFHnuNKUtDuQ2SgXLxWf82 2JbffIoyZwa+ZP4iFc58QjJJA/mSoTE= ARC-Authentication-Results: i=2; imf25.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b="EV6/X8xf"; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf25.hostedemail.com: domain of jhubbard@nvidia.com designates 40.107.223.76 as permitted sender) smtp.mailfrom=jhubbard@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1732160739; a=rsa-sha256; cv=pass; b=ajIopsOeRmDCeHIQLRgMs6ImaHZn7GtX+UI/DhSu54ahd7zbKYUN07kpjnEhMzRWPijtNI Zn8zoZEY94yZMubUG8jIvW2ztaK+bF3TipliLHL8QUCUnyqjve9yeyTUij7ZdNjDOdfRa3 B6da5+rlQeZ1jRGwqRAX4taFnayxz2o= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=F01rqlKfqXAFLfMSM9f7A9u5ZMxirrwTh+o+azJA0bfwZY8ozwuNkElH+xV0uXTvlii1E0rUwtehxXpucl97uBOKmfT2QizY+AvjKeVlTpZtAxr3U73jQio5V7IOUc6WcK13OIApRjq8uI1dvEgI/I6huUUK1HdTTtWeLv0EzrAKrRg/5yiQRYEsDE1Do4Wx9MP6ymByuYnhA7rkA/2SxcDhZtSIPAb2iNuIv+wwbHRD/+xjLy1nECSO5ylPyu7psBnkpIOPjroztcaCBn/81lFHrZ5rVcarKH4HKHcIBVH8bXRyOSTZ+IqBA5neuKGh/meDEQKwUa9NWPGstYk2sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ev5FmAIzpZYSjnRVgilauia7Iu/E86hqcf2/cWen3/4=; b=D8rePkwtbbC1Vfzhr/TdGu54Qq88oItNw/+bUXExH99UfFOd51qbJyPJirSWbmRf+VIc9/GtMkjMh9JPYefDqF0CNW5d2NtDZrIIkLlSY/K/k6uDbrigVnTZEI6ZcdYlvHYi7+kImxU4fo6PFJmarUALVfrCyK68lh00DhhiAvj6S0HBMlYjgnDBUVlq9oeHAqfmoDV5W8/iWAqBX6biJ0s9PZ4Ul2kGamL/rQIl7fX5C1Yc5bt8SFE2EKMKK3hoMlIUf3udBNVhbCHfiisvwcUvIfqbsfPBNJhA2T70Uv5ZBLOnudmHzmhya6raABaxAVwlkYcPWBNXQAuLDr2u7Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=Ev5FmAIzpZYSjnRVgilauia7Iu/E86hqcf2/cWen3/4=; b=EV6/X8xfCtwaXUgxp5G8cnnuuvgjoih3eAAGc/jJ9cFJSXhBAYyJSZVbpkJbMXFUg62GoGjwMWWHRppYapVOa4q0djaV8gUL2hl/TviXgzHVC9LZeukEYcty8Kgx99uoiULI/6cnmIcw3xoDjduE25TmEVF+FOSYrxwVKwbdI6K4FLKx3ul0Ali1va3kM5eghyKkTw+aZInHxTvdVB+Fld+EvbrKPnEo66IwJq3eKUCKuVKlO9HZtmn49BPzWJzUHEowtXcwNoEkSzwS1lFSqxlCXeRoCMtCqKThudMTDyLpQoQt2J67VzpNnIMqsdWwaddXHjw9S4lx5/4uGsSOag== Received: from SJ0PR12MB5469.namprd12.prod.outlook.com (2603:10b6:a03:37f::16) by SA3PR12MB7857.namprd12.prod.outlook.com (2603:10b6:806:31e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.23; Thu, 21 Nov 2024 03:49:40 +0000 Received: from SJ0PR12MB5469.namprd12.prod.outlook.com ([fe80::ff21:d180:55f2:d0c0]) by SJ0PR12MB5469.namprd12.prod.outlook.com ([fe80::ff21:d180:55f2:d0c0%4]) with mapi id 15.20.8182.014; Thu, 21 Nov 2024 03:49:40 +0000 From: John Hubbard To: Andrew Morton Cc: LKML , linux-mm@kvack.org, John Hubbard , David Hildenbrand , Oscar Salvador , Vivek Kasireddy , Dave Airlie , Gerd Hoffmann , Matthew Wilcox , Christoph Hellwig , Jason Gunthorpe , Peter Xu , Arnd Bergmann , Daniel Vetter , Dongwon Kim , Hugh Dickins , Junxiao Chang , stable@vger.kernel.org Subject: [PATCH v2] mm/gup: handle NULL pages in unpin_user_pages() Date: Wed, 20 Nov 2024 19:49:33 -0800 Message-ID: <20241121034933.77502-1-jhubbard@nvidia.com> X-Mailer: git-send-email 2.47.0 X-NVConfidentiality: public X-ClientProxiedBy: SJ0PR13CA0027.namprd13.prod.outlook.com (2603:10b6:a03:2c0::32) To SJ0PR12MB5469.namprd12.prod.outlook.com (2603:10b6:a03:37f::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR12MB5469:EE_|SA3PR12MB7857:EE_ X-MS-Office365-Filtering-Correlation-Id: 9c7a9bd2-f941-4dc1-8998-08dd09df86ce X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: ncxr+BfFbQe1hW4eyvxDPHvHHeG4pZmjhDzOT62Wq3xPV6fP0M+PExwfvuY9AT2maK9vJRhthfx5EmA7AAciMtQe+8GBFYpjfU7907vADGhXsZOs+kW2+CZn5DXsybjRQ1yCM0v3LrXGvRFvLXbxb/buMTGdBfOyTlV/4fUfJAUZeQEp9Od/tJOCaWJr9nk3ZYjPTNkEMJ1NfjWVuOrjsh2E2RQ1t/4m6IMVlo1IAiTsC26nfGgLXHu/k63xQ/94R5AUFyV94vneym1LvA7JsbhARDRr9PlvRygc98U/YPjx+DDvm0rtUSu5R9lv88lDlii4vt7EWD1QgZfyvxcI5rECpw8vzDTtGvF65apA/+h/CWGthrpzV4lOf+HbleCuRYmG3tMIytlu6ImqFdrAgPwhggpIH+4jSYJchgFvT5cMuuiax9ESB1X2kBC72KUJlf64+Ku342TzZOraMxp/PczKTNskzIb7emAcDWUuCzhBOpAn7OFZG0J4LjhCFjHUjDBTfjvg1GaU7Sv945LkiGzU7qi1b60zF8bWTnwXqLeibA3nv2U1YwYuQkqIooERUxv9AWQ2eoXWx/tUlRZxWZ8jD9Bhv+sGvozY/XveJQpwvS9N0WrEM/m7vjQbEgBUNaQcFGd8o6ElofimdIWo4ypR5UfHc4N6ZSNPJ2I1kfjwd4CvpRz5Dsj670l/aOuuWG/+lHrK4lb5+T7f3lUDEO0eU+kPg89jsY8wZ5yw2N1NdJvpaIclbBWeiLaeaOLc5tpUC8NDN3/emlv1bBARI+HmtsHNGop9LJq0v7XGyF7U9FQLyv5IPied42gc+bkic9RMlPrno+zP9rzwxz57fCChpy23316k/Qu/rRbj2ubqeW++NKUqKRSkvZ912tajBfAwzX3ekutdjo9Ns70tFSTGk01tUSNuHiWiBMueGDouZSw4wGiUVvqDrkgU81husi+vzjamrW7nggLmLukckQF1QKguBAj++OGdAlCiC6frT02Lx5ax2xLuxUnMXV2ZJsLHYwLQhjHJr2DHcP1kyRjeow1OxFmGDlSuUpWz/V0FDK01avYOnKVA/OuldozeGsFlLr8kv+FthWyiwZUiZhBdazhnsl/XPPhrAkqHbZGOM+yQiLcoJz0k3iix5raWZ6cD/qsMKJrwoUAAjES46zRGUvcXJq6r6056628Mgtio2ek2nXdrPbUKjKKylBF31gKDpJYvprUiTY2NyRGmMvn3fTxs3rk8jmJ3knppXBl/KxDbXzHtOnryfQ5NAuUJo5nTH+mygNze2fvWIgSp2fmuLw5g1tr2tumQIBg2PxuDcyNZOz6pK3xhLWBf89Rr X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR12MB5469.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tAxVvJ6DnJ2vAB0ApyLgSuqunq1nWBI5XiCd5TrhlDcWC0WywmuBn8llNvQi0azEdDdsM8G3T08aNIc2G9Mi3aCw6rm/x6vYkO96OPvEAHPdoMrIOD4J4IZpd6Q5j0nCyZmzJDBJJLxRKccRSVG3XusSZ8izgpKtc/Q0DavPgTq7GpVl+O8GcTI2h2cOi4GEewrmiky77TNev+zjQ0Aophn0/U+qpdSmL0HCoPDSA2slyvVQbqpZ43uGprPAj6oDaUcx0hO6wQJpZqDmas0sgTrvXEVg6MKboaTmGQ7O1YlQCNvzkbof77X0b91NcNWAy3aqzTK7WFRVuVlM2Ao0xs7hO/1Yrw7ucHF3DMMqmVYP/TtYiT60auZnJcSAxvvLtisLQLSq+xiQU3cWEIbJf1GoZpnAv6zUV7yisnCdrNR2lnreCzLIz74J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MyHfAM5YBFzoHq1M56/hl7YilidNKXrIYHHZpDCUcAtwnzqqdYc8aif5SySoXgkJJYP8yUPLdziBbXE3ZnGAb X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9c7a9bd2-f941-4dc1-8998-08dd09df86ce X-MS-Exchange-CrossTenant-AuthSource: SJ0PR12MB5469.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2024 03:49:40.1662 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: GQcCqGYePDe69O/Z4zl5GUpTwNJsXU8O9zhlwPDMMNFdjs6xR7qWZGVX2frGUounntkoWQpqN+7j0RpWCVYlvA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7857 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 07D2FA0005 X-Stat-Signature: xoftrbuah48nqyaoxuz1bademn5ri644 X-Rspam-User: X-HE-Tag: 1732160947-608967 X-HE-Meta: U2FsdGVkX1/bnyWvPoQMQbRVLFZIurFYuN0z0kLWLv5qRokJSlwzKDFJvqtynIb2i1BHhWoHFpV5V+X4ep7RIb16nJSRLC2nPrEpol+3xaE+FC4sYNFq3KRt8ZMybYZULb1gUzVs+DOXepc26fxH8HSCwqMnkrKSR2UTSMNhwZEdbaS+5iv1/nl1ppkQmFK06VPnuOLj9mFMz5RmQvpXJo5P4gZIzgpR8qWs2gquiHVJfdx0lH4ylAQPylFsENznG+jtwz1pv4Yu8owz+giepeIt35KeSW9BnY2e8RkbiCuvlYP6bNSSAEOG7yvqlcXzzsG01KAUNFAgZS4yHk+nzp1VgG5t/bBLTkYcB3jJk55o8fgZ3OUmdW5DL9/PnAmTzEwuGelBUWYyb0i3i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saIMjyFpVhuEuvTeJ2d65dPr40KEMfjmC7rpYJ5nRWgZdPMuCvQQ 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: List-Subscribe: List-Unsubscribe: The recent addition of "pofs" (pages or folios) handling to gup has a flaw: it assumes that unpin_user_pages() handles NULL pages in the pages** array. That's not the case, as I discovered when I ran on a new configuration on my test machine. Fix this by skipping NULL pages in unpin_user_pages(), just like unpin_folios() already does. Details: when booting on x86 with "numa=fake=2 movablecore=4G" on Linux 6.12, and running this: tools/testing/selftests/mm/gup_longterm ...I get the following crash: BUG: kernel NULL pointer dereference, address: 0000000000000008 RIP: 0010:sanity_check_pinned_pages+0x3a/0x2d0 ... Call Trace: ? __die_body+0x66/0xb0 ? page_fault_oops+0x30c/0x3b0 ? do_user_addr_fault+0x6c3/0x720 ? irqentry_enter+0x34/0x60 ? exc_page_fault+0x68/0x100 ? asm_exc_page_fault+0x22/0x30 ? sanity_check_pinned_pages+0x3a/0x2d0 unpin_user_pages+0x24/0xe0 check_and_migrate_movable_pages_or_folios+0x455/0x4b0 __gup_longterm_locked+0x3bf/0x820 ? mmap_read_lock_killable+0x12/0x50 ? __pfx_mmap_read_lock_killable+0x10/0x10 pin_user_pages+0x66/0xa0 gup_test_ioctl+0x358/0xb20 __se_sys_ioctl+0x6b/0xc0 do_syscall_64+0x7b/0x150 entry_SYSCALL_64_after_hwframe+0x76/0x7e Fixes: 94efde1d1539 ("mm/gup: avoid an unnecessary allocation call for FOLL_LONGTERM cases") Cc: David Hildenbrand Cc: Oscar Salvador Cc: Vivek Kasireddy Cc: Dave Airlie Cc: Gerd Hoffmann Cc: Matthew Wilcox Cc: Christoph Hellwig Cc: Jason Gunthorpe Cc: Peter Xu Cc: Arnd Bergmann Cc: Daniel Vetter Cc: Dongwon Kim Cc: Hugh Dickins Cc: Junxiao Chang Cc: Signed-off-by: John Hubbard Acked-by: David Hildenbrand --- Hi, This is based on v6.12. Changes since v1: Simplified by limiting the change to unpin_user_pages() and the associated sanity_check_pinned_pages(), thanks to David Hildenbrand for pointing out that issue in v1 [1]. [1] https://lore.kernel.org/20241119044923.194853-1-jhubbard@nvidia.com thanks, John Hubbard mm/gup.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) base-commit: adc218676eef25575469234709c2d87185ca223a diff --git a/mm/gup.c b/mm/gup.c index ad0c8922dac3..7053f8114e01 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -52,7 +52,12 @@ static inline void sanity_check_pinned_pages(struct page **pages, */ for (; npages; npages--, pages++) { struct page *page = *pages; - struct folio *folio = page_folio(page); + struct folio *folio; + + if (!page) + continue; + + folio = page_folio(page); if (is_zero_page(page) || !folio_test_anon(folio)) @@ -409,6 +414,10 @@ void unpin_user_pages(struct page **pages, unsigned long npages) sanity_check_pinned_pages(pages, npages); for (i = 0; i < npages; i += nr) { + if (!pages[i]) { + nr = 1; + continue; + } folio = gup_folio_next(pages, npages, i, &nr); gup_put_folio(folio, nr, FOLL_PIN); }