From patchwork Fri Jul 19 19:29:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ralph Campbell X-Patchwork-Id: 11050543 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 78B256C5 for ; Fri, 19 Jul 2019 19:30:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AA2F28984 for ; Fri, 19 Jul 2019 19:30:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55BD4289BF; Fri, 19 Jul 2019 19:30:12 +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 339AC28984 for ; Fri, 19 Jul 2019 19:30:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 42B4D6B0007; Fri, 19 Jul 2019 15:30:10 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3DB8B6B0008; Fri, 19 Jul 2019 15:30:10 -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 2CA5C8E0001; Fri, 19 Jul 2019 15:30:10 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f70.google.com (mail-yw1-f70.google.com [209.85.161.70]) by kanga.kvack.org (Postfix) with ESMTP id 0E7856B0007 for ; Fri, 19 Jul 2019 15:30:10 -0400 (EDT) Received: by mail-yw1-f70.google.com with SMTP id f15so24609791ywb.5 for ; Fri, 19 Jul 2019 12:30:10 -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=5BzlDT+tWQDH/Xg8OWZLql9VCG1Bt/EFc4+GdPSo8lc=; b=Bdy2bf3A4f8bWO5QqSwXjruA8mwed4tzgR9yETgwDGJlB5sxBprXhcBEjwlPLuw5YJ BOk97myL7fHhzPqv8HU2l8XDw1cFW69wCNiYKwyk3zFxfQ/PylvgMFmWnNQVMxKLvptV K7oNrH9BKhIsy+4t8IiyBhSf/4xVJeDXs1315tzY2N581CLHCv2RhuIH7oTLMM719Wq5 YCINMMqQTx6ld6lDokpbjwMgcOhAnfuWbXZcI1S0yjMjk9MS4RkSaUQx4Go4ncNqr7CV loRVkzw+gT2q0x/nrnwOVl23igR3NwV6SMm6EPRKcO9TZ7ZGHxG7VYFMPa8ruLkFGkeJ +ktQ== X-Gm-Message-State: APjAAAXlBmeRdhWynvyYg8yqS1TUapEflMXzH7xgZX5e7Wl/+JBhxeYm Ghmv/Rjesl5epKZh91GYjY0MJTBwuxz9yr4MsPEhpiHf1V/TLrXjhwajEcRdnbSG41S3pG3bd58 0zU4A1vyOLB9Lx1cPInoJC3VX9XcWy5EL0Jni4uybsWXhtYSUQbDjoIWx3dY0VhuXGw== X-Received: by 2002:a25:7507:: with SMTP id q7mr32183855ybc.494.1563564609818; Fri, 19 Jul 2019 12:30:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqy075oMoMalyB+JPfARHu4FK1rJ5OAVh7u2I0gA/Nto7vsMDOyR0UgxenlgS+LcwBIxogOU X-Received: by 2002:a25:7507:: with SMTP id q7mr32183820ybc.494.1563564609002; Fri, 19 Jul 2019 12:30:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563564608; cv=none; d=google.com; s=arc-20160816; b=TcoL33c5SjSq7JgPI61ICoMJbPl8nnNckEFXNifVpdxGXaowPUnqgXeQDe56R09Cvk /EXvgghl6mtpWdJz9q3Fij/3HUxjGc3MGH2nmT9YPA2GTe7BVaLPRW1zuSjHi2WeMi48 GZg4MviDxXQcCwIW2p7MjZDLP6nFXeabbI0WRNsC91HLl5iFCE1rO3i6gupwtwi6T/Ii UA8pzYBMUFR5dVK9y7EjjlGwnwn45MVkjZdMdr9EDWw7auBbjSalWpu0Yv3t2jZIUR+e FOKODc0cQQEEQRGNRz2LGO9ll9bMRQv0eyZElYFtiRro+yHo0yfibqoT0gHlo3tHjwZG SjxA== 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=5BzlDT+tWQDH/Xg8OWZLql9VCG1Bt/EFc4+GdPSo8lc=; b=juAGqD1vEnrfKtr+M/eiqCdORY6Lmf9EgXron2d822YZDREdYmaAMz/3e8z9FCyUNP utXZK7qlRdnXXvyGpcvoS+aAFhej+jA3I7Evfri/ftRZyyHg1KiqCdbD6SkGNCom40JJ uMa3IQrU4DkWV3QfUYalQMpevxPHySWlq/hScuWzaTwysxtlv70FidC+hxeaGC7xpv8l LglpLR59sEQ1hu9/E3F1CpsMXFp6OOrafz+ZvNOcAAOExnhLOyrqLdFe7WQ5rYNEH6lt gandetgJutXXL/fYz8Zm+w9klXvsekTVZoZxS6Jg+UKEMq8QYKcxKMROvSTlkHisnXdY pfzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=PQexChhB; 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 r129si12860790ywg.165.2019.07.19.12.30.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jul 2019 12:30:08 -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=PQexChhB; 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 ; Fri, 19 Jul 2019 12:30:08 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Fri, 19 Jul 2019 12:30:07 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Fri, 19 Jul 2019 12:30:07 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL104.nvidia.com (172.18.146.11) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 19 Jul 2019 19:30:03 +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; Fri, 19 Jul 2019 19:30:03 +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 ; Fri, 19 Jul 2019 12:30:03 -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 v2 1/3] mm: document zone device struct page field usage Date: Fri, 19 Jul 2019 12:29:53 -0700 Message-ID: <20190719192955.30462-2-rcampbell@nvidia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719192955.30462-1-rcampbell@nvidia.com> References: <20190719192955.30462-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=1563564608; bh=5BzlDT+tWQDH/Xg8OWZLql9VCG1Bt/EFc4+GdPSo8lc=; 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=PQexChhBZx3+OWZZ6A+wrhywrKQby9FhOWY5qduhs3ASzwzTGT5/e+pR4+/0KGzdu zc8xUGQTFKV/eGaRb3lqi32sg+IiQX2anYnS2PocFFF5W2OhNynMmfZuXm9iI+f0JL WB2FhbKiTQMV/TXeGZcU0LIVz4FwdypJ88fXi61dgUV+Oss+CYgNHRCpRN7u0Vs0op 50S4AqXNU97o0O36Y4EHqNSij20fLwUfZQ8hH3LzoXyI0+w1dg8aQGg13GvjJQSXXp aTksokvD/6cJAU4uRYdMCJe3hyLMENdviYEtmb9w+0e7IrM0fgMbp/3zzRZFk7HtLW 8KBOIAdX0ZUpQ== 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. Restructure struct page and add comments 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 Reviewed-by: Christoph Hellwig --- include/linux/mm_types.h | 42 +++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 3a37a89eb7a7..f6c52e44d40c 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -76,13 +76,35 @@ struct page { * avoid collision and false-positive PageTail(). */ union { - struct { /* Page cache and anonymous pages */ - /** - * @lru: Pageout list, eg. active_list protected by - * pgdat->lru_lock. Sometimes used as a generic list - * by the page owner. - */ - struct list_head lru; + struct { /* Page cache, anonymous, ZONE_DEVICE pages */ + union { + /** + * @lru: Pageout list, e.g., active_list + * protected by pgdat->lru_lock. Sometimes + * used as a generic list by the page owner. + */ + struct list_head lru; + /** + * ZONE_DEVICE pages are never on the lru + * list so they reuse the list space. + * ZONE_DEVICE private pages are counted as + * being mapped so the @mapping and @index + * fields are used while the page is migrated + * to device private memory. + * ZONE_DEVICE MEMORY_DEVICE_FS_DAX pages also + * use the @mapping and @index fields when pmem + * backed DAX files are mapped. + */ + struct { + /** + * @pgmap: Points to the hosting + * device page map. + */ + struct dev_pagemap *pgmap; + /** @zone_device_data: opaque data. */ + void *zone_device_data; + }; + }; /* See page-flags.h for PAGE_MAPPING_FLAGS */ struct address_space *mapping; pgoff_t index; /* Our offset within mapping. */ @@ -155,12 +177,6 @@ struct page { spinlock_t ptl; #endif }; - struct { /* ZONE_DEVICE pages */ - /** @pgmap: Points to the hosting device page map. */ - struct dev_pagemap *pgmap; - void *zone_device_data; - unsigned long _zd_pad_1; /* uses mapping */ - }; /** @rcu_head: You can use this to free a page by RCU. */ struct rcu_head rcu_head; From patchwork Fri Jul 19 19:29:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ralph Campbell X-Patchwork-Id: 11050547 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 02B8A112C for ; Fri, 19 Jul 2019 19:30:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8D6E289A0 for ; Fri, 19 Jul 2019 19:30:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DCF80289BC; Fri, 19 Jul 2019 19:30:17 +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 425E7289BE for ; Fri, 19 Jul 2019 19:30:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A9186B000A; Fri, 19 Jul 2019 15:30:16 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 00B586B000C; Fri, 19 Jul 2019 15:30:15 -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 DC6408E0001; Fri, 19 Jul 2019 15:30:15 -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 B658A6B000A for ; Fri, 19 Jul 2019 15:30:15 -0400 (EDT) Received: by mail-yw1-f72.google.com with SMTP id r67so24450760ywg.7 for ; Fri, 19 Jul 2019 12:30: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=VRtcfh5WiSupUP5Y8ZWeqEYjlWzsti4A1ZaXu55dh6o=; b=VNkTdpxakaw8TBHhkGJ6CWeuWWzy2crPbnGZ3ciw7BIliPt4uKSEjlaA6o/GwVKHO+ avEOsagSpH3P8gsW1GNpoo/vTDkO56yCs95BqdIiYSpXX2v0oBMacv4dTmudQUQJz4j1 NYvg3PH8fgHtZbGhMMTBag/clNOsRH52ZcsOAYrzXy63Sh7OR/1/SnwZuo7I6L83W9Fr P8082vdrS8AuSd2S4davwOJAQLiquPmCZoSVCyShtI6BRXaT4DS73O+E9T1vcoyKxEoC Uy4PXjX3+Jif9u5bONQzCQokjeJ2+y4O1WdEKrIZz2CWHI/wOBKq0SxHvpq/dK0aZtZK df/w== X-Gm-Message-State: APjAAAXuZ6yMF2BSaIytc1uHxEiaZIKrlWg0J8lqOrIArOz3YgzE9XcE V+EgbDS6RYrVwi7xDoD8FyPh9SHLcb1TKL5XnPRVydeEzwkO4cPBhyiJjsk8A4l+kMyjQ7Z7nzI cad/4hh+E23IixKvdU3juTu9GJUM+pNWs8LYri3yY46Q6sku6W62mRMuVugPCAsHgdQ== X-Received: by 2002:a25:30c2:: with SMTP id w185mr32090215ybw.508.1563564615471; Fri, 19 Jul 2019 12:30:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqz3uMglz7FrcODb+sLt62hm3PaJ8JTDJ4iw9xIsxRRlDQWuXcj/ddSNvjANhwNyt61PXLn5 X-Received: by 2002:a25:30c2:: with SMTP id w185mr32090194ybw.508.1563564614892; Fri, 19 Jul 2019 12:30:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563564614; cv=none; d=google.com; s=arc-20160816; b=lfd1+WF6f8gRZNI1rIzb2SOrhXVvYhsMzB119UdOr8ALZ+CsrwvOhYjUBnNk4rOdXn aT4Z52+VvpA82kqLEmI8T/JOzIeeEMxTV0vttigotvP6l+nVoJKf46zEBGyWRAVkrM5s 8iz+kWJ/nmHRPdcQql4NfwxE2Isi6rtcSID+RnaId+dIRyfIgNODskNZhH2IgAk3sXl7 0qC2r0noHOX7xkZ+RTJG1Hc+JtMpbPpILlitO09HL76WaADnOCbOSIFYOSQt4wLk8oTm Wzrr/xH4qKHwVcpGq3P+FDzZaEczdVL5/oz2jEZb9nnqywe+h8JjNSZ7rzTBdOxxG6YV zd/g== 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=VRtcfh5WiSupUP5Y8ZWeqEYjlWzsti4A1ZaXu55dh6o=; b=llu3J9whev89454IY+XmW8BpMZsTKoklCMqLSAlvaZiw9vl3cqfEvXf9TPaHw/WQBy Okft8MIKmA/k4RYgz60DsgGHp8jqPHgrMYrUTXLvX/8/cxIGJf9h78jX6UwM2be6p7EC yfq8QOJfu2Q2j0oSP/ZjtHRgDnJax340Ggs85JX5bNQodbuUUXbrWVJ81KPAvnstCyBT ZyKDNo9e0iwNXlWTTkCJx+UozQSIZkaBWi+yO9ddT+WXtvMavknn1lS+5xyhYespfMpc Z3SFiBW+2CgftBsAT+FyZkxHX8TVMQ78HRHRR1rCKh5Ns0GX+0RQd6FZ31WeEwEci8ab ciHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=B+e5qGRX; spf=pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.65 as permitted sender) smtp.mailfrom=rcampbell@nvidia.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: from hqemgate16.nvidia.com (hqemgate16.nvidia.com. [216.228.121.65]) by mx.google.com with ESMTPS id r21si14448901ybc.179.2019.07.19.12.30.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jul 2019 12:30:14 -0700 (PDT) Received-SPF: pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.65 as permitted sender) client-ip=216.228.121.65; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=B+e5qGRX; spf=pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.65 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 hqemgate16.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Fri, 19 Jul 2019 12:30:12 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Fri, 19 Jul 2019 12:30:14 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Fri, 19 Jul 2019 12:30:14 -0700 Received: from HQMAIL102.nvidia.com (172.18.146.10) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 19 Jul 2019 19:30:13 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL102.nvidia.com (172.18.146.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 19 Jul 2019 19:30:05 +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; Fri, 19 Jul 2019 19:30:05 +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 ; Fri, 19 Jul 2019 12:30:04 -0700 From: Ralph Campbell To: CC: , Ralph Campbell , , 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 v2 2/3] mm/hmm: fix ZONE_DEVICE anon page mapping reuse Date: Fri, 19 Jul 2019 12:29:54 -0700 Message-ID: <20190719192955.30462-3-rcampbell@nvidia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719192955.30462-1-rcampbell@nvidia.com> References: <20190719192955.30462-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=1563564612; bh=VRtcfh5WiSupUP5Y8ZWeqEYjlWzsti4A1ZaXu55dh6o=; 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=B+e5qGRXNq78hbYvK0jR2F1wmPW858/Up0dRZbJZpsibttglgzYKMDTaY5O0kkqDn 9XStOpiEipTaCyrs4/YYKvqn2ukRw1bC2K1taS/8pvAIiY5YV1wRR1eZoCnOQyd2Xm m8p3EG0tNoc8Hi1wKkrvHwCYFl+s6QyG9NN5XoFPT1hOlps3WClf1HEndKYJynvkoB 7guzLd8DbBpE457bUieNeGtI+dYXN1BKmnMKX6qTVcztr8EfCgk3TDriLPmNtXcix9 kqzuQVVFUoTFFU3ejMuQmfd6x0wh8YqS+TGYByo/+1bsLybirEeYo7rFI7MX3Ad/Mz DlD4XaHKKTrAw== 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 Cc: 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" Reviewed-by: John Hubbard Reviewed-by: Christoph Hellwig --- kernel/memremap.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/kernel/memremap.c b/kernel/memremap.c index bea6f887adad..98d04466dcde 100644 --- a/kernel/memremap.c +++ b/kernel/memremap.c @@ -408,6 +408,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 Fri Jul 19 19:29:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ralph Campbell X-Patchwork-Id: 11050545 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 DFC71112C for ; Fri, 19 Jul 2019 19:30:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4F7728986 for ; Fri, 19 Jul 2019 19:30:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C8A0E289BE; Fri, 19 Jul 2019 19:30:13 +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 4DF6C289A1 for ; Fri, 19 Jul 2019 19:30:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7D5B96B0008; Fri, 19 Jul 2019 15:30:11 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 75EE56B000A; Fri, 19 Jul 2019 15:30:11 -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 58A868E0001; Fri, 19 Jul 2019 15:30:11 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f200.google.com (mail-yb1-f200.google.com [209.85.219.200]) by kanga.kvack.org (Postfix) with ESMTP id 375C56B0008 for ; Fri, 19 Jul 2019 15:30:11 -0400 (EDT) Received: by mail-yb1-f200.google.com with SMTP id q196so25392400ybg.8 for ; Fri, 19 Jul 2019 12:30:11 -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=U0IXy/zKKcejMP4DQKHZ57GJs0lTlzQ4MYtXzCim3fk=; b=n2xURjvAEea/yjLoYOlYusPeqFd2NtS0cAkJQERdv0oPASKP54pYM7nvVvazCAZz3I Ubof8FlzwektkmWyreOSXqtixtnj1LCDzJlKqJr7clagGV8oK0l5lpYqSfcvay3SmOpY JUW70F64KhTU4nGBqdSrzh0V5rcOaLtj8wJrGglx/LzHxSMarXqDv893zR9/noYZdn5K qtp5v15P7cQbKqwWlaBpkHfWB0l61Vu9/GdGVpoG8+kW1Tz/XSvmlWOwDjzkP7D6JGFc FQHz+BVWSSYZdHeAZztpR43sveqSER8EO8f5Y8dfAKwUsY/OJVaFPrMG8R/zRkA4Ym3S +W6A== X-Gm-Message-State: APjAAAVbNuBck1gl+BWJuojI/DuQGLd/eqkPMMhbR1XA3RhgLLsBvlP+ fK5ZX42jg0tGqMr/Iu276JNk8+iRHLUtqMrmliziVWofHRPMyzPV3XnhbAgwYtU95FFOsyAFCiX 5h3K2jwOgOgzrATPyzA4nA3HW3mJurBcri71hL2L4GEbIck0n+54+kifRjKIE7cWuqA== X-Received: by 2002:a0d:c5c6:: with SMTP id h189mr32212156ywd.274.1563564610991; Fri, 19 Jul 2019 12:30:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqzgsSXyHrLDWZPk15MFns5BbSwBb8keSHgNe2wLPECcwTaBwbgGh9F1lAZTIl+qYHqwFIUJ X-Received: by 2002:a0d:c5c6:: with SMTP id h189mr32212132ywd.274.1563564610387; Fri, 19 Jul 2019 12:30:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563564610; cv=none; d=google.com; s=arc-20160816; b=G3BLFQOmm8tW7a5EabaJPS9I4lTbwZXeslZ83PFgSQ6QURTD8U1kzMIsUULSeBxYN5 dK76BZxbEMcsETXCoWD8aH7mFqbMp/QxgfwqEf5LhZr4bdvV3p+NmMFjls31jCknQz6g QfoHcjVjcmvDSfUnWvyZJSvX1YuL4NgifWGluxUKV43J2gohksVFKHBxZG0BShhhVlvh mne7p1t4ScfgX4O4ppwWfU3ODt2Z0vvRdlgefCT2Se2GdrnYKV73AI+nnik8Aqun1fuO QY9/o3sIRBdoS3aFiFs0YXfTV4fs5q2/0IAFwIAE/ANzru3rFW4l720/WkfSIWXYBEsa aiLw== 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=U0IXy/zKKcejMP4DQKHZ57GJs0lTlzQ4MYtXzCim3fk=; b=Lyx85A+wOWOA4Rl1wmr81pHewDmPYQHw/0DSTVIK60+C14z4Dj6vaTMT+gn3Q39FEW HPjYoo4IVuqhMNnabO1/GxXExvV/xnRHynstTa7zCcvASKaxPRKQ+i81w3pdoyRgMP/U cgBYCeeIjBLZXEWd5qT6MwpgI5iQP1BwELJplINDYO6Yu1KkvWAwgFE8QVQWZYqMsmlQ PDU6F12ZyV9CfpnjBVduWHQGSbRF4wvR4GG6kxHyd0Sjl1uIvUox8R+96ZWzndXAeBBU +zsWSbc/NbzrhMxOfE9Dek7Avvp4sjn9m2V8c+/NVzqy4JpeNftK6koyg9+1xqurYqvO 5Gag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=YIkfifBJ; spf=pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.65 as permitted sender) smtp.mailfrom=rcampbell@nvidia.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: from hqemgate16.nvidia.com (hqemgate16.nvidia.com. [216.228.121.65]) by mx.google.com with ESMTPS id b4si2129808ybk.4.2019.07.19.12.30.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jul 2019 12:30:10 -0700 (PDT) Received-SPF: pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.65 as permitted sender) client-ip=216.228.121.65; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=YIkfifBJ; spf=pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.65 as permitted sender) smtp.mailfrom=rcampbell@nvidia.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Fri, 19 Jul 2019 12:30:07 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Fri, 19 Jul 2019 12:30:09 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Fri, 19 Jul 2019 12:30:09 -0700 Received: from HQMAIL110.nvidia.com (172.18.146.15) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 19 Jul 2019 19:30:09 +0000 Received: from HQMAIL104.nvidia.com (172.18.146.11) by hqmail110.nvidia.com (172.18.146.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 19 Jul 2019 19:30:06 +0000 Received: from hqnvemgw01.nvidia.com (172.20.150.20) by HQMAIL104.nvidia.com (172.18.146.11) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Fri, 19 Jul 2019 19:30:06 +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 ; Fri, 19 Jul 2019 12:30:06 -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 v2 3/3] mm/hmm: Fix bad subpage pointer in try_to_unmap_one Date: Fri, 19 Jul 2019 12:29:55 -0700 Message-ID: <20190719192955.30462-4-rcampbell@nvidia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719192955.30462-1-rcampbell@nvidia.com> References: <20190719192955.30462-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=1563564607; bh=U0IXy/zKKcejMP4DQKHZ57GJs0lTlzQ4MYtXzCim3fk=; 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=YIkfifBJUS0alAYsaVI5Ym8d5Mg4+IaenMIF+Y0kr5t7XnywK5CHmhhjsvvwxA9YN hbDUy5VkcxKbbwBf9ukQ7ACI2HDXzbD0iTnXCostTVhbyzPsfBQOqW5ZqgiHWqg/TP MIS7pFfiezJRrkz9KW5msKmEg7H2CntpEWhdHIJXJb/VPi3uVI0Od4R1IDwOXCe4NP QNBpDA11Dl9eAOplh9CwMN2llenNQpmONbUBX2CZwZ2FnX2zNmEGFP2F7n1WNt3mYk ma8muqGT1xXFWVoBZKhUXjZHA19CbXrT/M+0ogyaKVYdDZFCytv8Rv2cc+PudYibtr kBIWEui1O0Rtg== 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 | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/rmap.c b/mm/rmap.c index e5dfe2ae6b0d..ec1af8b60423 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1476,6 +1476,7 @@ 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. */ + subpage = page; goto discard; }