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=-3.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 2620AC32750 for ; Tue, 13 Aug 2019 22:37:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EAC8120844 for ; Tue, 13 Aug 2019 22:37:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565735834; bh=RKfYzsTAgYU/z5+V3fu9/qvGMi+RHmejhzIjyiV9L+0=; h=Date:From:To:Subject:List-ID:From; b=k2xqKdhNiedhW8geFgw3BDD4vnuZRNWyhhY9kb+kmrFcBkUEfnoJ2tGVg8P4sQBPu bTRcDKdXlRLB4SDyljGxoxx5HEBMiMP2e4zqPzTC6tyf9fCKXeY1SWxNUUNCS708Pk 43yCsqb466MSCv8pBGe0AKLvU0Dsk1Iphv4D3J2g= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727276AbfHMWhN (ORCPT ); Tue, 13 Aug 2019 18:37:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:48520 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726698AbfHMWhN (ORCPT ); Tue, 13 Aug 2019 18:37:13 -0400 Received: from akpm3.svl.corp.google.com (unknown [104.133.8.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E1DC620644; Tue, 13 Aug 2019 22:37:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565735832; bh=RKfYzsTAgYU/z5+V3fu9/qvGMi+RHmejhzIjyiV9L+0=; h=Date:From:To:Subject:From; b=AuhO/2bxDfwjGyO1aFDxVrYZfzLQ/aVvHk88Y6jjv6pNcxBAjgaBRE6xFEzsdcL47 gf4A2PLENEOPstE+Nm58K1Tm+2OUx0r0HWxLvSEbbw6QUG1z4XsJpLJDfMQtkl6UuD zv7npgG26JgStcffDFK+z1X/Na/65Gq9vMWHwOig= Date: Tue, 13 Aug 2019 15:37:11 -0700 From: akpm@linux-foundation.org To: willy@infradead.org, vbabka@suse.cz, stable@vger.kernel.org, schwidefsky@de.ibm.com, rdunlap@infradead.org, penberg@kernel.org, mike.kravetz@oracle.com, mhocko@suse.com, mgorman@techsingularity.net, logang@deltatee.com, kirill.shutemov@linux.intel.com, jiangshanlai@gmail.com, jhubbard@nvidia.com, jglisse@redhat.com, jgg@mellanox.com, jack@suse.cz, ira.weiny@intel.com, hch@lst.de, dave.hansen@linux.intel.com, dan.j.williams@intel.com, cl@linux.com, aryabinin@virtuozzo.com, aarcange@redhat.com, rcampbell@nvidia.com, akpm@linux-foundation.org, mm-commits@vger.kernel.org, torvalds@linux-foundation.org Subject: [patch 03/18] mm/hmm: fix bad subpage pointer in try_to_unmap_one Message-ID: <20190813223711.OpPez%akpm@linux-foundation.org> User-Agent: s-nail v14.9.10 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Ralph Campbell Subject: mm/hmm: fix bad subpage pointer in try_to_unmap_one When migrating an anonymous private page to a ZONE_DEVICE private page, the source page->mapping and page->index fields are copied to the destination ZONE_DEVICE struct page and the page_mapcount() is increased.= =20 This is so rmap_walk() can be used to unmap and migrate the page back to system memory. However, try_to_unmap_one() computes the subpage pointer from a swap pte which computes an invalid page pointer and a kernel panic results such as: BUG: unable to handle page fault for address: ffffea1fffffffc8 Currently, only single pages can be migrated to device private memory so no subpage computation is needed and it can be set to "page". [rcampbell@nvidia.com: add comment] Link: http://lkml.kernel.org/r/20190724232700.23327-4-rcampbell@nvidia.com Link: http://lkml.kernel.org/r/20190719192955.30462-4-rcampbell@nvidia.com Fixes: a5430dda8a3a1c ("mm/migrate: support un-addressable ZONE_DEVICE page= in migration") Signed-off-by: Ralph Campbell Cc: "J=C3=A9r=C3=B4me Glisse" Cc: "Kirill A. Shutemov" Cc: Mike Kravetz Cc: Christoph Hellwig Cc: Jason Gunthorpe Cc: John Hubbard Cc: Andrea Arcangeli Cc: Andrey Ryabinin Cc: Christoph Lameter Cc: Dan Williams Cc: Dave Hansen Cc: Ira Weiny Cc: Jan Kara Cc: Lai Jiangshan Cc: Logan Gunthorpe Cc: Martin Schwidefsky Cc: Matthew Wilcox Cc: Mel Gorman Cc: Michal Hocko Cc: Pekka Enberg Cc: Randy Dunlap Cc: Vlastimil Babka Cc: Signed-off-by: Andrew Morton --- mm/rmap.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/mm/rmap.c~mm-hmm-fix-bad-subpage-pointer-in-try_to_unmap_one +++ a/mm/rmap.c @@ -1475,7 +1475,15 @@ static bool try_to_unmap_one(struct page /* * No need to invalidate here it will synchronize on * against the special swap migration pte. + * + * The assignment to subpage above was computed from a + * swap PTE which results in an invalid pointer. + * Since only PAGE_SIZE pages can currently be + * migrated, just set it to page. This will need to be + * changed when hugepage migrations to device private + * memory are supported. */ + subpage =3D page; goto discard; } =20 _