Message ID | 20241119044923.194853-1-jhubbard@nvidia.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 98C1FD60D1A for <linux-mm@archiver.kernel.org>; Tue, 19 Nov 2024 04:49:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1E8746B0093; Mon, 18 Nov 2024 23:49:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 199196B0095; Mon, 18 Nov 2024 23:49:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 011D26B0096; Mon, 18 Nov 2024 23:49:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D6EDD6B0093 for <linux-mm@kvack.org>; Mon, 18 Nov 2024 23:49:33 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4C62D140121 for <linux-mm@kvack.org>; Tue, 19 Nov 2024 04:49:33 +0000 (UTC) X-FDA: 82801614294.25.2FCB167 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2077.outbound.protection.outlook.com [40.107.96.77]) by imf30.hostedemail.com (Postfix) with ESMTP id 6B6BD80002 for <linux-mm@kvack.org>; Tue, 19 Nov 2024 04:47:56 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=Z89SGdK7; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf30.hostedemail.com: domain of jhubbard@nvidia.com designates 40.107.96.77 as permitted sender) smtp.mailfrom=jhubbard@nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731991587; 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=nmmghdc1Y+iTgl9QToz9Bq6ODyB6Zd8YesIsyDsTpm8=; b=gVpnm4bAzB6kwBcAzOY6vAFrAol1VCmexeXbW/Trbrnh6vJyUWjFPDs3pLDzYVMuTUySv2 BIcmNzeP0m/7c0rRH5D9yLGmaHxWH3fv6FG0a//RK25rMyvfulejcYyJ7u4gHKRqVThM+B B8BBrWwL/uRTANn/Pa4j+GxiIloEVT4= ARC-Authentication-Results: i=2; imf30.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=Z89SGdK7; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf30.hostedemail.com: domain of jhubbard@nvidia.com designates 40.107.96.77 as permitted sender) smtp.mailfrom=jhubbard@nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1731991587; a=rsa-sha256; cv=pass; b=woOP8YAb1quiU8uzbLXmtzOBv/DaMmtoYR0xqSPwS6MPiZFOSiz5FLu5t+myw4h4ySEzYk eY6EAtLZHCslIXKedyM1eEO4tFTvZbwBQwfkDrvpgs9sK0jDd1pAt/Wl1o+4PBIgrR1sm9 Lw4Ls0cOECnbzJd+Ogiwn4JiN/nKt5I= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NSQmq8Z9bKHZayM6Uzv+ZFTgyJp1hlov3Pm6zRTnVu3vMKC7bnFVfx5STdAUO8SjlpR2Snqt9Im/covPWzM+sEwGAbC+arfJiqxv0+agKPh9iNa8shnIIZPNn7IKZq1EMk0k2W3YxfZSgQSvakCjEpRvtrfgHAVggWtOTXD5FRuZivTULHjlbMmikbgQrFLP7StpuAYKrQlAXGe/TVtctQAO1PHoVcaIXbspQiV3eUxnMEPlnsA3hYJOUYU7ZRq6XJ+NLox3SAKD1qqMmwjhCdsk9cKr3SP3qyrKWN3qMSRZQwFRj5ORyn6TrUg3Tg5PJ09UCp7z4q/bHInw2Xd5/g== 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=nmmghdc1Y+iTgl9QToz9Bq6ODyB6Zd8YesIsyDsTpm8=; b=iqsDLuLSQBZTD9Ku/o9WNTVBesAXBehw70YHk5bAKwpK2mp8lR8EJSsQez/tjgRJif6jp4MNQ8Yyr21LHE6boYsEfRos37CDjaSV/H7XBUz+5+Qv/4Fb+fnVFQ0aVOTjbSHk4xmt1lTdajFciHHBLWgvIWz3baYSazgRNgpwdbQYHhaUsTQOnEZumtw3pouRLUdalYywzEm77BqOON3hJJrPzfgEl7sgt2VwEPKTVYsXCRZlO6o2Pbh3KAC5Hv424yVOJM7ctinsePS82PtJyCyZST7eQgbdVALkI17cLAboU3I5kUrx6j2dbYBBw+clPxUpiO/K0qyxwkAKpb1XqQ== 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=nmmghdc1Y+iTgl9QToz9Bq6ODyB6Zd8YesIsyDsTpm8=; b=Z89SGdK77Oob6ehVa/XJu6/j05Du3Pk8FL7zJa7T+xFFKoItvBz93Jy+8/DqRxOl1mj3KQsydreWVVDLhRIECcFg51yOk4vW62XcGxMRiFEyhXbwOTZaxKUZVx/b9/j3GnwB3XZjTfF3HldZahDNmNBjpD0pcOIGDEJIbz6lkFdWskI17cp+H5cnCiQ+g1BKYlszmc3D9Rd3q6RGtOv3msJ9yBv7KUru7hKZf1+NRbDgVMIOKkGmTtbN8l634UCPxk8ABNgKtyJVOEqsBBifn1nv9Ge19L9F7vbo+b+LDkeS3oFqsq97QiaFFW15nWqiLEk040re630TeYBpyTttyQ== Received: from SJ0PR12MB5469.namprd12.prod.outlook.com (2603:10b6:a03:37f::16) by DS0PR12MB6559.namprd12.prod.outlook.com (2603:10b6:8:d1::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.24; Tue, 19 Nov 2024 04:49:25 +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.8158.023; Tue, 19 Nov 2024 04:49:25 +0000 From: John Hubbard <jhubbard@nvidia.com> To: Andrew Morton <akpm@linux-foundation.org> Cc: LKML <linux-kernel@vger.kernel.org>, linux-mm@kvack.org, John Hubbard <jhubbard@nvidia.com>, David Hildenbrand <david@redhat.com>, Oscar Salvador <osalvador@suse.de>, Vivek Kasireddy <vivek.kasireddy@intel.com>, Dave Airlie <airlied@redhat.com>, Gerd Hoffmann <kraxel@redhat.com>, Matthew Wilcox <willy@infradead.org>, Christoph Hellwig <hch@infradead.org>, Jason Gunthorpe <jgg@nvidia.com>, Peter Xu <peterx@redhat.com>, Arnd Bergmann <arnd@arndb.de>, Daniel Vetter <daniel.vetter@ffwll.ch>, Dongwon Kim <dongwon.kim@intel.com>, Hugh Dickins <hughd@google.com>, Junxiao Chang <junxiao.chang@intel.com>, stable@vger.kernel.org Subject: [PATCH] mm/gup: handle NULL pages in unpin_user_pages() Date: Mon, 18 Nov 2024 20:49:23 -0800 Message-ID: <20241119044923.194853-1-jhubbard@nvidia.com> X-Mailer: git-send-email 2.47.0 X-NVConfidentiality: public Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: BY5PR16CA0013.namprd16.prod.outlook.com (2603:10b6:a03:1a0::26) To SJ0PR12MB5469.namprd12.prod.outlook.com (2603:10b6:a03:37f::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR12MB5469:EE_|DS0PR12MB6559:EE_ X-MS-Office365-Filtering-Correlation-Id: 0280a419-bb6d-450f-4568-08dd08558b0d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: buKCB8bGOa/UzC57dOV7eyMukpvIk+AcisHxS6Z54BmYGcGAh9e+3b1ThVQjyPiiwzFjOxEldEhPgBKa1kKK1ycg8d+IF2vmXUppkuTcXi8zdOJ2WwA+v2+HaADmAw4wot+kl0iaSM53H/v3V4wfejA5Y5iEoU1jfIF9sARrGbHScZN7+Rz1X1OdIlF5Sks+cznrQN1TNqjHg+KNBDQBD0Bd4LFHnU5AS0vGIijApDS4SxIb6gbic0b9f6vUkrUmsJcj2lKp6jwfLJ4d4EOi865EjMbFT1Jk5PA0rIg7HCTeuNGz6d5wAx0DmoHf2ulaS/OUHN9bQzBf6Q/9m9DZVSixtYYNWcwIi+tWX/ZXP408uUUwpLq0qqD1nBHy7lWhxhl1rTPlT6NWwz1EVydWynTGM/wjtoefcRSa53Tdh2rN6xUw86NPh1lsr0p3fifOpsPZXidGogUAZ9cOtB6TSQ/wxfK6KWMLyubzp19BjiMpYUjQj4EG3v29JwDIl0QrWvbqYF5p3EatB6U6EOLmPrMADQjCgbWlq+uoJVxegUY1fBWDq0snscStVl3anzbuUOkzjXF+GIBA5Z+FZ+ia0yflhb7j/vGrV5a9jNyBtQjFH+6nmiaQq0rWpSBpCXMAi0QyNMSEyt30CPcAmQGqejR8RTl3Z18HYE4Fz/UdMM4BvObn85Gy8xwC1sr1JsjkHxbCgCBxalM76URIm1j/Qe/I5sgGoPYch23VDY5eZjp94a1IV6P+ymbxTQQasZDfWPEMV/vcQlz9mMFoc+z6PXih3geG30XeEBIsgAWqSz0ZCBQsVQVTjlnxOtzpr6iMIBZ8WOXJvxxud85TqTAOo7a5LcZBHEcbmSnyMunFfcfo1A3uiVVKTxtSwQtytpncYmwT+t4bEmBmfDBMwckw5YgU692ocA4CdqWvktv2Wo8d4ILnHp0WdudRALm4SFybVL5lxRwsfjnTpWl8UP7+DwDDhDvxpuDJrc3GgF2ordot2ZvTOlANHVm+im55CpZG9O6WtA8UmkiJZt11eMr0aJOzdI+9zj9S6I1TRQRCVx8qIZmYWN8kWT/tV3nlDKee3cxcBD1zVg26I1NmpA+ZYsmbv0tJwSq0ojAPWFGrNdFc6Aqeal1rxjGNtVY9qZNGQAWrLlmqX1kPmHh3Xy7aDnEQcOxefaxFjnrssHl0rY1a5C27iaxrey3sgEJt3AttEyilSeLy/PLWDPKcKFXtyHiYs+LGemmUPcYftbRrhGZerbM2qFpvusGqCKtWIh7/Gcn2GCQYskv6RyqDrMhABMRSBAlvR3SRnBO2poXr2qujJQ4ejuGEpUZ2soxYemvg 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)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ER1hmtQSDCEA1Dtu5bUOWc8HeuxudAeTwbvqq2o5fXkTGDMRMi9Q8kkgS8WQx+Ctlqf2vEeRuPp5gycnLe5LFhNOrSiC5jMiIDErEJRDzjojewjr3lel7bLhhK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hwKxnPg23Jm5HG4FVxYRUX1+M2QUG+cvL8A0UAByOXuZRjoaE3TpNmTnYa9lPPupxyWiVu/26RwGqiby2mb0mfJCwy3sHzzyEuWE/jDun/Z2yxatz2dS4NyTzAHbmMg7UocKIzmkNlJqGWPyym1iRifL4N+K/vm9cQGIWlwOSnLIZyIw0Ob4/LTpsAQBFjhSoTSujBquyeB//yjlol7c95AY9UPcdm/YbkRrNnQ4OM/13gNzavN4JeFemubNLq6WlNCX0OscutzgMn36mG3t0vYIFFYFY7QZLsb7aNgofRsNjqXIXHqYF7FceVNGZAcnYthZPjkWlkILenbb4z0UAaJIIB7g9x5rD4ja+jnJYj+1aNbhf09L9fCNAn7fnYi5neuVtsUrUur6dLjnQlwpAR9Cb3 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0280a419-bb6d-450f-4568-08dd08558b0d X-MS-Exchange-CrossTenant-AuthSource: SJ0PR12MB5469.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2024 04:49:25.5934 (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: EGHIHq8qLVV9CKQFJDdgkMUUR0CIMlPHGR43FWCb1FilXl/kYBjIPH2Jc8gI9mf7HQ3Y/zcjjsa1OELlv0DJXQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6559 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 6B6BD80002 X-Stat-Signature: rzcs5xozki3r481gjxb15fqsnhp4x7oa X-Rspam-User: X-HE-Tag: 1731991676-36014 X-HE-Meta: U2FsdGVkX1+Tma8wLWvifJjd0w4St0SXeE0idd3fHs9+qSxsCCT03ab6g9NO+0efBOJxgTx+O03AEZa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9v0PxBnMQpf3gSYsdEfz+7A8eJ9Un3jHtBiYa+GIyXUfev5t0FBodCDjiFPl8wSlTJGHJqP2ICDRN59vxC+8WJGaLfxpNclXv+ecet42yg1HVKqPMOHOJg36sD0P/OkGAulc9fDCHOnjE61Y288rB0nbw/tL/4kk9CcwhlxEJ2wzAj8aSEeVMCC3V0d2sFx6mJ4IMESlnnwSHxH+vpPju98PtRNbQyAC4MZ29Q6QGlU6JsJQRn1rL6ePYgtVPRD1FUgX23TuItSjtXUuVFLLSkBsAmYxIqTt4LTdWbgKsS6SMesE4A6inLg5aTPQ3t9X8dlC63kgffLMhlUoK3QGLaC59UvBdLMdU3VyIdO4Ll3QpIwlOVBOrIYdy5BjC 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: <linux-mm.kvack.org> List-Subscribe: <mailto:majordomo@kvack.org> List-Unsubscribe: <mailto:majordomo@kvack.org> |
Series |
mm/gup: handle NULL pages in unpin_user_pages()
|
expand
|
diff --git a/mm/gup.c b/mm/gup.c index ad0c8922dac3..6e417502728a 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)) @@ -248,9 +253,14 @@ static inline struct folio *gup_folio_range_next(struct page *start, static inline struct folio *gup_folio_next(struct page **list, unsigned long npages, unsigned long i, unsigned int *ntails) { - struct folio *folio = page_folio(list[i]); + struct folio *folio; unsigned int nr; + if (!list[i]) + return NULL; + + folio = page_folio(list[i]); + for (nr = i + 1; nr < npages; nr++) { if (page_folio(list[nr]) != folio) break; @@ -410,6 +420,9 @@ void unpin_user_pages(struct page **pages, unsigned long npages) sanity_check_pinned_pages(pages, npages); for (i = 0; i < npages; i += nr) { folio = gup_folio_next(pages, npages, i, &nr); + if (!folio) + continue; + gup_put_folio(folio, nr, FOLL_PIN); } }
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: <TASK> ? __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 <david@redhat.com> Cc: Oscar Salvador <osalvador@suse.de> Cc: Vivek Kasireddy <vivek.kasireddy@intel.com> Cc: Dave Airlie <airlied@redhat.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Christoph Hellwig <hch@infradead.org> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Peter Xu <peterx@redhat.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Daniel Vetter <daniel.vetter@ffwll.ch> Cc: Dongwon Kim <dongwon.kim@intel.com> Cc: Hugh Dickins <hughd@google.com> Cc: Junxiao Chang <junxiao.chang@intel.com> Cc: <stable@vger.kernel.org> Signed-off-by: John Hubbard <jhubbard@nvidia.com> --- Hi, I got a nasty shock when I tried out a new test machine setup last night--I wish I'd noticed the problem earlier! But anyway, this should make it all better... I've asked Greg K-H to hold off on including commit 94efde1d1539 ("mm/gup: avoid an unnecessary allocation call for FOLL_LONGTERM cases") in linux-stable (6.11.y), but if this fix-to-the-fix looks good, then maybe both fixes can ultimately end up in stable. thanks, John Hubbard mm/gup.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)