From patchwork Wed Jul 24 23:26:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ralph Campbell X-Patchwork-Id: 11057705 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B0C0B1398 for ; Wed, 24 Jul 2019 23:27:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DB8F2893B for ; Wed, 24 Jul 2019 23:27:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9125B2893A; Wed, 24 Jul 2019 23:27:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9A042893A for ; Wed, 24 Jul 2019 23:27:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A7718E0018; Wed, 24 Jul 2019 19:27:16 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 432F68E0002; Wed, 24 Jul 2019 19:27:16 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 284478E0018; Wed, 24 Jul 2019 19:27:16 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f72.google.com (mail-yw1-f72.google.com [209.85.161.72]) by kanga.kvack.org (Postfix) with ESMTP id EE9938E0002 for ; Wed, 24 Jul 2019 19:27:15 -0400 (EDT) Received: by mail-yw1-f72.google.com with SMTP id d18so35607994ywb.19 for ; Wed, 24 Jul 2019 16:27:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding:dkim-signature; bh=R7tBXQO9rPgjXDqjGz3N+EME0mRb0btVdpzxMZ8l/ZM=; b=APOZ+Lw39yHfIDKohjKbAuMg0jQRMvwnBNkQ6H9PSbh50VtRG5FgXHfvgqW/KbucmW UMgjdPFj8DAfHq70dazTicWo8aOlsalm/lPl8ObqEC+P9JenHChYXzxU2/fXTJ6PiUyJ SRYzYoAPviLT/IzWa/pWE64TsUWuShdN+VYige1DFXCyKrBh+yTAhPrVpZ0URx98URyu 8xybmJ9KNCXvopr87/1dPQgt8I9DGPE4nVpE7go4MqzPZ0HNFUvJBeeshceJL+w9P4JG 31LVFqcnj0K0PtLH5YfoEgoAKpvr3w1eQ2eb04ZksAcazRh5SXrgwypE7+ZgQsxhScdf sxmw== X-Gm-Message-State: APjAAAUP5hcWTnArGx3MrzJnl1WBJHll75tXuRKcrLLzT0s7lIbyCiX5 oVCOm2G7+fI/NUGZlzUe5pXTiskuiVyFYJ15NgWPr75ZbR3T2SjQyVPSvIqMMzSDYmb3NAxN0zl Du7awsVXnbarMelcKhx6hM9/zxyBkPJxvk0HTOHv4D2TjjzAKwXsMhWxWPP5QF4HOnQ== X-Received: by 2002:a0d:e60a:: with SMTP id p10mr48694026ywe.370.1564010835745; Wed, 24 Jul 2019 16:27:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqzO0u06OhGdOO2oLtl2dlrHWlRv22E8wYePXgXSqgHi4CGSKfecUc2gg2bg3JtHeBBeNy2f X-Received: by 2002:a0d:e60a:: with SMTP id p10mr48694002ywe.370.1564010835183; Wed, 24 Jul 2019 16:27:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564010835; cv=none; d=google.com; s=arc-20160816; b=GsfBV+e7OjoLbR8OCCibIWGpbhwxrdoYK/dEInvoMO8KAPegm4N76bZf0P55wX1QFB wPXsibd2CVXd+ISkBzisSVy0FQSze5N13DuV7aos38gFow6x/oPksVkLAMgujnQNkO1L dTJBNtDOlllcmF9HD9di7zSMdGt/+YaBjboQ4hsynXnVCfj0DudnU8b6OQCNIwClc1/z ODMRT2iR0RYnfVt3H9WrhDy4U6tAciXRSkbu4BTjxQyYAJA5nySMjFfzr+ZBateD88oa mXeZ2FuEjUp//VUzj2/G22ERzs0cSCJMDRtZ6JJ6du5JC4Dlmn1LN7ggchi8O7KTZVRf JD8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=dkim-signature:content-transfer-encoding:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from; bh=R7tBXQO9rPgjXDqjGz3N+EME0mRb0btVdpzxMZ8l/ZM=; b=VSnplsgxIh33I+u4OR4bS3pLxmuTM5HV0hBB6JcLdLGWbxTA87t/t6LWmyTEtLE1xg q2GYxuescJ3yMXT0K2lMhSByWgWhKHhQxj7VezxAFYmS4J2F5r2bLXKaMP8JErgtZ0uB r0T9nuBELRxVDRqutRonVeP8Lqwy0zMf1f2/Z2vIcKEbKEg7aQNNOFJqJ7kpMaldO00h vaJ69KyoGwJmhMo4Ko8Qtxo69LgilHZ3mJ9s9+UjBOVjDZ2yDhiDQun00Ybp/FX6FfE0 UwifJoVtkZcYBvLHoBbnqeJsksnURRpaB/Z4ExJAhgjm0/hBWtunWiXgvRsdhNdJqxV0 OxcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=kuNrmdut; spf=pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.143 as permitted sender) smtp.mailfrom=rcampbell@nvidia.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: from hqemgate14.nvidia.com (hqemgate14.nvidia.com. [216.228.121.143]) by mx.google.com with ESMTPS id l125si16518386ybl.374.2019.07.24.16.27.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Jul 2019 16:27:15 -0700 (PDT) Received-SPF: pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.143 as permitted sender) client-ip=216.228.121.143; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=kuNrmdut; spf=pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.143 as permitted sender) smtp.mailfrom=rcampbell@nvidia.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqemgate14.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Wed, 24 Jul 2019 16:27:14 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Wed, 24 Jul 2019 16:27:13 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Wed, 24 Jul 2019 16:27:13 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 24 Jul 2019 23:27:08 +0000 Received: from hqnvemgw01.nvidia.com (172.20.150.20) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Wed, 24 Jul 2019 23:27:08 +0000 Received: from rcampbell-dev.nvidia.com (Not Verified[10.110.48.66]) by hqnvemgw01.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Wed, 24 Jul 2019 16:27:07 -0700 From: Ralph Campbell To: CC: , Ralph Campbell , John Hubbard , Matthew Wilcox , Vlastimil Babka , Christoph Lameter , "Dave Hansen" , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , "Kirill A . Shutemov" , Lai Jiangshan , Martin Schwidefsky , Pekka Enberg , Randy Dunlap , Andrey Ryabinin , Christoph Hellwig , Jason Gunthorpe , Andrew Morton , Linus Torvalds Subject: [PATCH v3 1/3] mm: document zone device struct page field usage Date: Wed, 24 Jul 2019 16:26:58 -0700 Message-ID: <20190724232700.23327-2-rcampbell@nvidia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190724232700.23327-1-rcampbell@nvidia.com> References: <20190724232700.23327-1-rcampbell@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1564010834; bh=R7tBXQO9rPgjXDqjGz3N+EME0mRb0btVdpzxMZ8l/ZM=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:X-NVConfidentiality: Content-Type:Content-Transfer-Encoding; b=kuNrmdutQu8OtJz0LkyZEgZtbgpSB31azxVA6IxHVhWwyekrrPMk35utH++IUUR0V ySZRHjTnQuRxkH0mSRZr0lRX8zjcwQo3cSTXfApyuOpwqFkqCoCiNAHnUNbMP3YhOs fvYiGYGvu8V9As7306izV/f8A7DsPZU0zIOSCCJa6mCtyaXg6gIRyFnjjzs13WYPWA +RuZoYfW0QBPbXhlmlgRYiiMtwtonS/EbKE7Gq9TxQbZtH0EPUSzQ1XJO4Adpk0SXl Wr32U6NJLVw+CC1G77WQ4pgNY01eGesQd/e/J1j5Yk22sCMPNUCHDfJLKSuGCaJAHh /9ROeBw+Xc+CA== 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: X-Virus-Scanned: ClamAV using ClamSMTP Struct page for ZONE_DEVICE private pages uses the page->mapping and and page->index fields while the source anonymous pages are migrated to device private memory. This is so rmap_walk() can find the page when migrating the ZONE_DEVICE private page back to system memory. ZONE_DEVICE pmem backed fsdax pages also use the page->mapping and page->index fields when files are mapped into a process address space. Add comments to struct page and remove the unused "_zd_pad_1" field to make this more clear. Signed-off-by: Ralph Campbell Reviewed-by: John Hubbard Cc: Matthew Wilcox Cc: Vlastimil Babka Cc: Christoph Lameter Cc: Dave Hansen Cc: Jérôme Glisse Cc: "Kirill A . Shutemov" Cc: Lai Jiangshan Cc: Martin Schwidefsky Cc: Pekka Enberg Cc: Randy Dunlap Cc: Andrey Ryabinin Cc: Christoph Hellwig Cc: Jason Gunthorpe Cc: Andrew Morton Cc: Linus Torvalds --- include/linux/mm_types.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 3a37a89eb7a7..6a7a1083b6fb 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -159,7 +159,16 @@ struct page { /** @pgmap: Points to the hosting device page map. */ struct dev_pagemap *pgmap; void *zone_device_data; - unsigned long _zd_pad_1; /* uses mapping */ + /* + * ZONE_DEVICE private pages are counted as being + * mapped so the next 3 words hold the mapping, index, + * and private fields from the source anonymous or + * page cache page while the page is migrated to device + * private memory. + * ZONE_DEVICE MEMORY_DEVICE_FS_DAX pages also + * use the mapping, index, and private fields when + * pmem backed DAX files are mapped. + */ }; /** @rcu_head: You can use this to free a page by RCU. */ From patchwork Wed Jul 24 23:26:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ralph Campbell X-Patchwork-Id: 11057703 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9111B746 for ; Wed, 24 Jul 2019 23:27:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E4682893A for ; Wed, 24 Jul 2019 23:27:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7256D2893D; Wed, 24 Jul 2019 23:27:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1AD02893A for ; Wed, 24 Jul 2019 23:27:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 061A68E0017; Wed, 24 Jul 2019 19:27:15 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 011238E0002; Wed, 24 Jul 2019 19:27:14 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF5358E0017; Wed, 24 Jul 2019 19:27:14 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f72.google.com (mail-yw1-f72.google.com [209.85.161.72]) by kanga.kvack.org (Postfix) with ESMTP id B965E8E0002 for ; Wed, 24 Jul 2019 19:27:14 -0400 (EDT) Received: by mail-yw1-f72.google.com with SMTP id x20so35731151ywg.23 for ; Wed, 24 Jul 2019 16:27:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding:dkim-signature; bh=AGMennFGR3RQwqOaKvawxIvCw+p1UUJkNAyV14vll0s=; b=JPjUoHT1d+RObcxWK2GJHZqOo49jw+wsRTMfz2pEihi6yBuVaLGJPrMo1ssgBLTtCv LzpHhUjMierUsFt/5FIhiAkf53ZMa9RFzbK/1miDIPW8BH9B5SGYgIvPuSTXtcq8hd++ JwksgHEG+8RkVpf1kvzvvxsM2e5EyG+WYgFAspBUotF/Xj/NaDb4FjoODjUWZnKT+SnF zksu0JDEfd8lUcs16STna6OQIR+MWsaa04lsUIvzNQJPkdB+x5qUWrc9hzeZQ+zL66Yo 7fgI06p4JUpuAN2R1gtXWCVzYuQnu0f9itaCIU/AH4Y27Z1LZbcObNpKMIcoJlMGsN5C YPMA== X-Gm-Message-State: APjAAAX7qlcJhr0gkxDP/n6NqRRTzSpXIwJ5QcMTfY7t14kRhoVVZ2hl ILEJ9T3rpvD+PLzYyzZ+MG136mCDW7q1crSbUfKkGTJaqgceFlFelnraO28S+2sTLkd3gzPfhdu RLdQC8qthaSY1p9TT0rtdIcM5A5OYYT0dsrvHZLPAoXEdobLZaSrUZw+ETC5P9MqUJA== X-Received: by 2002:a81:3803:: with SMTP id f3mr50448230ywa.337.1564010834522; Wed, 24 Jul 2019 16:27:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqwxp7/gYccoHysvseOCG664xuHe81z6/6MaqlhnDARaqLlA+CnbzR+UtYXJqFzqFKI14OAg X-Received: by 2002:a81:3803:: with SMTP id f3mr50448208ywa.337.1564010833925; Wed, 24 Jul 2019 16:27:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564010833; cv=none; d=google.com; s=arc-20160816; b=HAd6SVtpJm869eZ6+MJZAtfXad9Iejo30ukQEniGOOeAl7V7J9jM8RpYlRUO+hR0bQ /oDApVSSD7xa0fqm67/bwrqzWHqD3hl7sL/INBXQfiR7GWoc/XJUHwsDVGkW54d4NPAE NRcFYn2YpCrHlTVzt+uy6WgO87PrRT8JQDQ7KvbLuwBU0BUgVPCPERhpTtQBZqeXdQy0 t0bLwOf7dggfEt9cgrliRsNv7wijBXoZsgRbr/kj1avgbfT6foe4hapEvPZTmOtWVGx1 TOrdOWeKDPx6AVQlOgNkbiRbhbZwlCfWAOeB1t4nY1Iev0OmUGO0q0NY+U30V6/Pm9/D qGLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=dkim-signature:content-transfer-encoding:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from; bh=AGMennFGR3RQwqOaKvawxIvCw+p1UUJkNAyV14vll0s=; b=cl60uCWyyXWj4gI34YMK8HYDxJKSh+mNKFpzA9+vSUaxox50RRN6zKEhHrm6PTfVTF fhhnjgSP9x1R587trpPLo7VG0BiDsTz3gKQvOXtqZYTUARdejMljqvLwOOtw+ZE2h4+8 nP19atJbHhzKvhECSdyJpmCa4YXut0LT682Q0oK1Jksy81naoD96N2aPfUG/Jd/CFPkM i4t6dEp8NenQBh+D5mX1URHMc/CUc1G7Bak31jo9qdd54yS2rbQk0w7IkbPGC4jolO7M IanDDYv0uiXo+9IezluqHZn+dfKaIEkkE7GzVF2rlm8mp26qgderyAW2aKQ3nNfPJL/n 0VaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b="T/Wkfrdv"; spf=pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.64 as permitted sender) smtp.mailfrom=rcampbell@nvidia.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: from hqemgate15.nvidia.com (hqemgate15.nvidia.com. [216.228.121.64]) by mx.google.com with ESMTPS id k129si17420939ywe.425.2019.07.24.16.27.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Jul 2019 16:27:13 -0700 (PDT) Received-SPF: pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.64 as permitted sender) client-ip=216.228.121.64; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b="T/Wkfrdv"; spf=pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.64 as permitted sender) smtp.mailfrom=rcampbell@nvidia.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Wed, 24 Jul 2019 16:27:20 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Wed, 24 Jul 2019 16:27:13 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Wed, 24 Jul 2019 16:27:13 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 24 Jul 2019 23:27:12 +0000 Received: from hqnvemgw01.nvidia.com (172.20.150.20) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Wed, 24 Jul 2019 23:27:12 +0000 Received: from rcampbell-dev.nvidia.com (Not Verified[10.110.48.66]) by hqnvemgw01.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Wed, 24 Jul 2019 16:27:12 -0700 From: Ralph Campbell To: CC: , Ralph Campbell , , John Hubbard , "Christoph Hellwig" , Dan Williams , Andrew Morton , Jason Gunthorpe , "Logan Gunthorpe" , Ira Weiny , "Matthew Wilcox" , Mel Gorman , "Jan Kara" , "Kirill A. Shutemov" , Michal Hocko , Andrea Arcangeli , "Mike Kravetz" , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= Subject: [PATCH v3 2/3] mm/hmm: fix ZONE_DEVICE anon page mapping reuse Date: Wed, 24 Jul 2019 16:26:59 -0700 Message-ID: <20190724232700.23327-3-rcampbell@nvidia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190724232700.23327-1-rcampbell@nvidia.com> References: <20190724232700.23327-1-rcampbell@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1564010840; bh=AGMennFGR3RQwqOaKvawxIvCw+p1UUJkNAyV14vll0s=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:X-NVConfidentiality: Content-Type:Content-Transfer-Encoding; b=T/WkfrdvQlqhaZ1B4Gy+zyQ5343De2o15Dzo1m6FD/7MgNn5uKqnffF4dzB3dkmKY mmiUUmdHltbF6ltMVOwrDVa9GllkGYNiDoq8WmcIVGVqsC/Elp3l1WNPJ6CISgybvP AwRg2lBx7h+xQwmrhC5943YxhIcGH0bPZsj/InKaG0EwCLvi44iY7FVj6+e7E486BE 0tj8W2NNZgnn4UEtqs7sUYEQXacImUiNmRFT/MsiwokLzZHmyOCJmraHOwsIzPppSV S/3nigz0kzkE415ZkUpGn5gyuXcicjh1ltdikJX7/SSNVGUDERXSqHLu4wTA/V2awn z6wm+r3AU1nPQ== 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: X-Virus-Scanned: ClamAV using ClamSMTP When a ZONE_DEVICE private page is freed, the page->mapping field can be set. If this page is reused as an anonymous page, the previous value can prevent the page from being inserted into the CPU's anon rmap table. For example, when migrating a pte_none() page to device memory: migrate_vma(ops, vma, start, end, src, dst, private) migrate_vma_collect() src[] = MIGRATE_PFN_MIGRATE migrate_vma_prepare() /* no page to lock or isolate so OK */ migrate_vma_unmap() /* no page to unmap so OK */ ops->alloc_and_copy() /* driver allocates ZONE_DEVICE page for dst[] */ migrate_vma_pages() migrate_vma_insert_page() page_add_new_anon_rmap() __page_set_anon_rmap() /* This check sees the page's stale mapping field */ if (PageAnon(page)) return /* page->mapping is not updated */ The result is that the migration appears to succeed but a subsequent CPU fault will be unable to migrate the page back to system memory or worse. Clear the page->mapping field when freeing the ZONE_DEVICE page so stale pointer data doesn't affect future page use. Fixes: b7a523109fb5c9d2d6dd ("mm: don't clear ->mapping in hmm_devmem_free") Cc: stable@vger.kernel.org Signed-off-by: Ralph Campbell Reviewed-by: John Hubbard Reviewed-by: Christoph Hellwig Cc: Dan Williams Cc: Andrew Morton Cc: Jason Gunthorpe Cc: Logan Gunthorpe Cc: Ira Weiny Cc: Matthew Wilcox Cc: Mel Gorman Cc: Jan Kara Cc: "Kirill A. Shutemov" Cc: Michal Hocko Cc: Andrea Arcangeli Cc: Mike Kravetz Cc: "Jérôme Glisse" --- kernel/memremap.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/kernel/memremap.c b/kernel/memremap.c index 6ee03a816d67..289a086e1467 100644 --- a/kernel/memremap.c +++ b/kernel/memremap.c @@ -397,6 +397,30 @@ void __put_devmap_managed_page(struct page *page) mem_cgroup_uncharge(page); + /* + * When a device_private page is freed, the page->mapping field + * may still contain a (stale) mapping value. For example, the + * lower bits of page->mapping may still identify the page as + * an anonymous page. Ultimately, this entire field is just + * stale and wrong, and it will cause errors if not cleared. + * One example is: + * + * migrate_vma_pages() + * migrate_vma_insert_page() + * page_add_new_anon_rmap() + * __page_set_anon_rmap() + * ...checks page->mapping, via PageAnon(page) call, + * and incorrectly concludes that the page is an + * anonymous page. Therefore, it incorrectly, + * silently fails to set up the new anon rmap. + * + * For other types of ZONE_DEVICE pages, migration is either + * handled differently or not done at all, so there is no need + * to clear page->mapping. + */ + if (is_device_private_page(page)) + page->mapping = NULL; + page->pgmap->ops->page_free(page); } else if (!count) __put_page(page); From patchwork Wed Jul 24 23:27:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ralph Campbell X-Patchwork-Id: 11057707 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 981A31398 for ; Wed, 24 Jul 2019 23:27:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87BB92893A for ; Wed, 24 Jul 2019 23:27:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B9372893D; Wed, 24 Jul 2019 23:27:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB29E2893A for ; Wed, 24 Jul 2019 23:27:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F2E168E0019; Wed, 24 Jul 2019 19:27:21 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EDEDB8E0002; Wed, 24 Jul 2019 19:27:21 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA66B8E0019; Wed, 24 Jul 2019 19:27:21 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f197.google.com (mail-yb1-f197.google.com [209.85.219.197]) by kanga.kvack.org (Postfix) with ESMTP id B84FF8E0002 for ; Wed, 24 Jul 2019 19:27:21 -0400 (EDT) Received: by mail-yb1-f197.google.com with SMTP id e71so30550066ybh.21 for ; Wed, 24 Jul 2019 16:27:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding:dkim-signature; bh=aE9jvpYovWbAuB2E+N8tRNTGgKOEO3ZSK7JOHwBAVAQ=; b=hUv+8GX4V+t2YAd4wVnnkVok+TXI2WH0Hd8gD5CYwLi0izH7/cO64mu9IoGKKupSLw DLt9ltsoggd3WLQBeCowg1V0DaboLZUykEyljKb/93spjVNYgZrVgH7nRTrjOBTblmil UnUF/iSktWtzchIcXRNnzoy6jcI1t6ViGgkji4+OeMLe9/CCV6PZdRrQTP+wd6OhRFVd o/N/yxxP1ZwzOXfF5UWasiyprFccnREQt7j1GvEvtyPhvI5iTrTobZsNtrAwCKu09+uv SUc5vcRWox2Ar5Qb4JhEX7ToHHH7QVSSdRd3URyZnerZrnAxB6+aPs3DMHWzVmsiO3fl sAJQ== X-Gm-Message-State: APjAAAXiSGz0J3nu2tQrfJX76QAni6cJmS+6TM5mRsYEtvX5dz/b83QV ODnrSRBzg1nPJzozYBywECOefdTIhJTSMOK0IFLR1y2IHUkSzV83fQ/etI5GAwErrlIkDcHwr06 BG/G9/waCuynlzx7sn64LyHtoz/snLKyFvXK2CTOEK6ntA+wG8w3kQJRRXGHtwxeG1A== X-Received: by 2002:a0d:ed41:: with SMTP id w62mr49864977ywe.177.1564010841529; Wed, 24 Jul 2019 16:27:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwwGgFPEmI/KdTFPirAjhWJJHCXkxb7tMC2M2fsG4NQO+WQaJ93Ae1m9oE2k3YwRH5l1v3g X-Received: by 2002:a0d:ed41:: with SMTP id w62mr49864960ywe.177.1564010840956; Wed, 24 Jul 2019 16:27:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564010840; cv=none; d=google.com; s=arc-20160816; b=HKz4luUEW7W9RKYgZJS6Mk4W04fHyV8fUYtyePOLgXPAa5alc1z8Ku+WqOLzjo6Ot+ URJR4ALWFWJzIlvT7V9nWhXIYXgB3Af0lNeFJAy2WfCGY+AgiUgJnLc4eoypYDV+L2Ga sdA8YYdQu8DMUS4FitbVsBaGzFsNiqdGOAf97a8vxOtxe6e0W6aXTjxdSGgu6GkINnsz WPFfw5v2DIArVuiK5vh5RP0T0Nt0An2RxknQnN2gFaY6wBlrrReP51L84oze79VZZY81 j3Zvx/CSDDm/u2F6BQVdbXzXcfvb53un6QSXJBuGZZYzCzAwf4O9JiyiNJandVkJV7KH dWVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=dkim-signature:content-transfer-encoding:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from; bh=aE9jvpYovWbAuB2E+N8tRNTGgKOEO3ZSK7JOHwBAVAQ=; b=HYCdOeRL08VN/zrIxTiZDYvg8Rl8SxIJQAHOYO5SCZrmIwiyYHklYT2H6IGicJO5Xr GkiSfa839uyN4vxZI/QLWKcwEIhQZ0MAuxSRobBVfDwOVWBKIpdUkM7UZq+QCWNxdGqc arABCpqUKKLDG4pvtyEsau8cKwUQAwe/iDRW3Q6jK+V/xxhxx7hhSn8IiQUoty8XS/jE ZJK7ZNSBi1dBSpLfZfhV7x4f2th4e0MoBq0qZzI3sa9qRQCXx2A0wYU1C0e7QxsOQ2xb NH+k5Tzw9HfDWyZ3hdSBVOnH6uWEeDVzxPhzYXO7EhARK6gUiXr19VhbRRI3fCfzEANS FzQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=IhtEE+3R; spf=pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.64 as permitted sender) smtp.mailfrom=rcampbell@nvidia.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: from hqemgate15.nvidia.com (hqemgate15.nvidia.com. [216.228.121.64]) by mx.google.com with ESMTPS id 7si16575698ybc.449.2019.07.24.16.27.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Jul 2019 16:27:20 -0700 (PDT) Received-SPF: pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.64 as permitted sender) client-ip=216.228.121.64; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=IhtEE+3R; spf=pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.64 as permitted sender) smtp.mailfrom=rcampbell@nvidia.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Wed, 24 Jul 2019 16:27:27 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Wed, 24 Jul 2019 16:27:20 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Wed, 24 Jul 2019 16:27:20 -0700 Received: from HQMAIL102.nvidia.com (172.18.146.10) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 24 Jul 2019 23:27:20 +0000 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL102.nvidia.com (172.18.146.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 24 Jul 2019 23:27:15 +0000 Received: from hqnvemgw01.nvidia.com (172.20.150.20) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Wed, 24 Jul 2019 23:27:16 +0000 Received: from rcampbell-dev.nvidia.com (Not Verified[10.110.48.66]) by hqnvemgw01.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Wed, 24 Jul 2019 16:27:15 -0700 From: Ralph Campbell To: CC: , Ralph Campbell , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , "Kirill A. Shutemov" , Mike Kravetz , Christoph Hellwig , Jason Gunthorpe , John Hubbard , , Andrew Morton Subject: [PATCH v3 3/3] mm/hmm: Fix bad subpage pointer in try_to_unmap_one Date: Wed, 24 Jul 2019 16:27:00 -0700 Message-ID: <20190724232700.23327-4-rcampbell@nvidia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190724232700.23327-1-rcampbell@nvidia.com> References: <20190724232700.23327-1-rcampbell@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1564010847; bh=aE9jvpYovWbAuB2E+N8tRNTGgKOEO3ZSK7JOHwBAVAQ=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:X-NVConfidentiality: Content-Type:Content-Transfer-Encoding; b=IhtEE+3R5QhqFa2KEziinP9eneZiPUTOmHuX3Sno5dk2gEzneBtRMuE8WEt2lHLaE AbaDZ5iX+QdPmQeebfejcPvuZ4D41S1xhiA4BLii6pTJSgMWdXUcWW5CrPQsupLeco WBFf8AmzolDvoi5goY2JR1CweNtxSz6XR7Uv3XX+852s/f3+eqUPQ8jEJVd0GHsU6l vxxT9YQ/FXsRyf5nVged5cLxXEImsR4cR31dJ1aHACQ5222keRwpvpiR+DC0o1NuR1 aTwHQdshh/APUALxv1ugMrYoF3O96zNWbpTodlMK2Kie1c1L6Vmuk5NhiwgwJp1xYB K6yWPNzPEp/LA== 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: X-Virus-Scanned: ClamAV using ClamSMTP 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. 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". Fixes: a5430dda8a3a1c ("mm/migrate: support un-addressable ZONE_DEVICE page in migration") Signed-off-by: Ralph Campbell Cc: "Jérôme Glisse" Cc: "Kirill A. Shutemov" Cc: Mike Kravetz Cc: Christoph Hellwig Cc: Jason Gunthorpe Cc: John Hubbard Cc: Signed-off-by: Andrew Morton --- mm/rmap.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/rmap.c b/mm/rmap.c index e5dfe2ae6b0d..003377e24232 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1475,7 +1475,15 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, /* * 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 = page; goto discard; }