From patchwork Wed Jul 17 00:14:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ralph Campbell X-Patchwork-Id: 11046841 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 E4F1C1395 for ; Wed, 17 Jul 2019 00:15:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4A95285CC for ; Wed, 17 Jul 2019 00:15:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C8113285FB; Wed, 17 Jul 2019 00:15:43 +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 1A885285CC for ; Wed, 17 Jul 2019 00:15:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A4FD6B0006; Tue, 16 Jul 2019 20:15:42 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 157BF6B0008; Tue, 16 Jul 2019 20:15:42 -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 F392F8E0001; Tue, 16 Jul 2019 20:15:41 -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 D5B3E6B0006 for ; Tue, 16 Jul 2019 20:15:41 -0400 (EDT) Received: by mail-yb1-f197.google.com with SMTP id b22so18294747yba.4 for ; Tue, 16 Jul 2019 17:15:41 -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=n97TMr2JNhrSZ7vCgIqLLYdPmnZDRy5pEGPbgjYfhkI=; b=Jdl/zyVnyebhJEplCUP7BfjwEdslCOYsNCVK25+iRIQcffYXScmgr6d0oGx1TJnP5i aGxAE9fn0fp6JuTxRElkLK+6a878Xl48hR8AWPMC4xmQIkov9xoCipuDlF99J2q/v49b ZbfgM+fz+XFVKJswF1DW9uT0eLd7ZZcxEZKwizv0EPMCNE4Su0FT+BIKWl2KN1Vrkysh GITPL4CImE8JqbbefguHodwpzw4Axfilz4fKMd1Mq3PLXPsHxlsZ4INUtbRcSNPf5RKM +inwa3SmCkixligA068TVeMaIkCfy+P8nPh6z5+B9XJB3RkA+Mj6eozCHhNtMmK3lBRz 0vZg== X-Gm-Message-State: APjAAAVymt+lLut1zfB2Q1Qymffe6/fiHb+/wSS56HRp5wdAzzM16EGP qn7psQDKqHfI0CeIYbGACW0h1cn2lOxgSB+FjxU+KCZ3NvyyGhEg1biVxA0Amx6NXTl6Gsj7LZC Ari+H1ONkCX5z+JUgAy1oQWlpAFNi0xZ/RNad8qF5+1YJ8Ewxi1/Zigbxx7R36vBnew== X-Received: by 2002:a25:400c:: with SMTP id n12mr21169416yba.427.1563322541649; Tue, 16 Jul 2019 17:15:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqwRvhEFwecVn1XRA92JISPK6hXmF0eM7oyka/lvMAnPxDIcJJXAkZUHt6PBep+hghvYWgL0 X-Received: by 2002:a25:400c:: with SMTP id n12mr21169399yba.427.1563322541110; Tue, 16 Jul 2019 17:15:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563322541; cv=none; d=google.com; s=arc-20160816; b=fHdz8y2t0rNsaMLoBD6AwmRBHalvqmX/UXpYCmJMevIvt0Uemmx+1GhzAP/ICvtLGC CYrV6L36d5H1+lCyUTx5JvobdU6BWxACUHLvz4VvJGJ3Wrj/r4fNLTLj3YqpKgjnYU1H lZL8xuiC7Nu9LSAsBIAarSv0vo9ymOXJwBmXPUoVeBlrXrGRbkAh0Idcydp5axv69Tgf XuzMSo1DbyYeyjn5Eg3sboontD2MF6DtwBKYSAii8GBjnG9GDid794677/BBGGOf8mMP 3gKgVVIcSYoX9XJz3KfxcUw7vem4foCAEYGyF72sn4Z065gEixTPqUcJL08gROUxrwm3 TM9w== 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=n97TMr2JNhrSZ7vCgIqLLYdPmnZDRy5pEGPbgjYfhkI=; b=AuHlPkwwCBBM7Jih9pPbtCYo6vHdjD+vpUA1+FMSop5TFcaG3+IU3p9zDwNpXdY33e 0wtrPRqx5c7+0FC2ogqcycb956rDFDey+nKanxNvLV5Z1eFpo+kR5HgWOU292nQrp7bF 8c1Mk3yMKU84FkFMRInlnP8nQs55YlCJ5MTpMBCu3wytYMXdp3xkbnmfc1j2+yE2w5w4 ZrhtOS3rf7wKjHYiln/uHreQGPvVtos41qrGwM9uFjs9GW9kuUJG47YS/OhpZd4kiobR e8GijGDcpC+CNXc8Iyj1c724iXzeCPCHPvw3tiQ8AcXgU4W5hBr2HUcYTZsJje978kZl MBsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=h8ViET5n; 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 t140si8061890ywc.12.2019.07.16.17.15.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jul 2019 17:15:41 -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=h8ViET5n; 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 ; Tue, 16 Jul 2019 17:15:37 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Tue, 16 Jul 2019 17:15:39 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Tue, 16 Jul 2019 17:15:39 -0700 Received: from HQMAIL110.nvidia.com (172.18.146.15) by HQMAIL108.nvidia.com (172.18.146.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 17 Jul 2019 00:15:39 +0000 Received: from HQMAIL101.nvidia.com (172.20.187.10) by hqmail110.nvidia.com (172.18.146.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 17 Jul 2019 00:15:35 +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, 17 Jul 2019 00:15:34 +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 ; Tue, 16 Jul 2019 17:15:34 -0700 From: Ralph Campbell To: CC: , Ralph Campbell , 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 1/3] mm: document zone device struct page reserved fields Date: Tue, 16 Jul 2019 17:14:44 -0700 Message-ID: <20190717001446.12351-2-rcampbell@nvidia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190717001446.12351-1-rcampbell@nvidia.com> References: <20190717001446.12351-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=1563322537; bh=n97TMr2JNhrSZ7vCgIqLLYdPmnZDRy5pEGPbgjYfhkI=; 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=h8ViET5nQwShosN/h1iEpWwaV7U1MHGQpL145RrpAfBB7pb/hc+UNknepxfXQ+2/i J+K60wFo6SunE78IG0A0ZSAQQeHwH/iXCHjF1/BHYLCYl3qTA94/TYq7La3Xwhx6OP gIEoMP9B+YfuGPWfz589qTOokW9//Lnvs9yq4U6FNVX3dULjF7MDdxO3WjRTLpsJsk tWfbqPbketRhICohw8wN/hPjyiSo5iFqWRtGTPq5HVuEdlwUaI8dNzNaW/yvih5paC odsBDvIHPlG1zU/ocufSij+Hmh0IUQJWk1lLgIl95Wsxl/xkTE8AzjnLcE1crREseF Cd6FZowRbWTkw== 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 reserved fields when anonymous pages are migrated to device private memory. This is so the page->mapping and page->index fields are preserved and the page can be migrated back to system memory. Document this in comments so it is more clear. Signed-off-by: Ralph Campbell 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 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 3a37a89eb7a7..d6ea74e20306 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -159,7 +159,14 @@ 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 */ + /* + * The following fields are used to hold the source + * page anonymous mapping information while it is + * migrated to device memory. See migrate_page(). + */ + unsigned long _zd_pad_1; /* aliases mapping */ + unsigned long _zd_pad_2; /* aliases index */ + unsigned long _zd_pad_3; /* aliases private */ }; /** @rcu_head: You can use this to free a page by RCU. */ From patchwork Wed Jul 17 00:14:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ralph Campbell X-Patchwork-Id: 11046843 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 049231395 for ; Wed, 17 Jul 2019 00:15:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9E6F285CC for ; Wed, 17 Jul 2019 00:15:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD4C4285FB; Wed, 17 Jul 2019 00:15:45 +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 46DE1285CC for ; Wed, 17 Jul 2019 00:15:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DDA876B0008; Tue, 16 Jul 2019 20:15:43 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D8DBD6B000A; Tue, 16 Jul 2019 20:15:43 -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 B42758E0001; Tue, 16 Jul 2019 20:15:43 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f69.google.com (mail-yw1-f69.google.com [209.85.161.69]) by kanga.kvack.org (Postfix) with ESMTP id 916BD6B0008 for ; Tue, 16 Jul 2019 20:15:43 -0400 (EDT) Received: by mail-yw1-f69.google.com with SMTP id x20so17483220ywg.23 for ; Tue, 16 Jul 2019 17:15:43 -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=xvR8iX2outgELqejVmTcMhX9RlYLy+wU1js0WKyDum8=; b=dofLExKzZ1YAp2mnGWnp2qwKnBBe0Jir1AZR9Szj17VLZc8ErE9PWGypGFL9GJv/NO eexpiL/kf6mtUocUHhqt3QxNdmrxdZnJcDSt9sbKxd66Ma2GkE7wXoZ2mPiFdCb1NZgz 7i9hwHg63aVgu4qkb5Xxedk07v67WA8CUX8nAVsUanig6V4jvdJEgkAbC8CmJA0tIw6R GrFBVpjfsPaYc59aPACxEHPMYMhYkWkKMwmdeFb5rRqruqMTi5LuK6CGibxUPJkHBhjn Z6/3+LId7tMA2S6kqalQYHX00c43bXHMRPIsY1TtrESvpYW8eGWEAR9KgiaAPpgspSN7 UfHg== X-Gm-Message-State: APjAAAUdizFyBy3ivHF4tOz72Wa1TZM97w6YiMi6dV28ybvV1U+PLoth bskGbyqaE5PCba7yR8TaJSJM5QTmQ3pZYKGKMqvU9rzESSV8kbaac3JBNR9jkeob+dc1oiU49UF B+TpL+6tBPkNXvXNsl1bkLEHxoNREAqg36bW+XvSztunx4gvWz3fsYfUDUAaIgk7Kqw== X-Received: by 2002:a0d:ce84:: with SMTP id q126mr20340882ywd.88.1563322543324; Tue, 16 Jul 2019 17:15:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqz1mDRcYQ0ruS4uNLFPXD6LCpIAZoJfNOJbUbQOiDACqtlzYV0KDQEphA1w7uUGzWxlo3Q9 X-Received: by 2002:a0d:ce84:: with SMTP id q126mr20340855ywd.88.1563322542739; Tue, 16 Jul 2019 17:15:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563322542; cv=none; d=google.com; s=arc-20160816; b=WK4yVF7jnO6PQc0k7okvpH7G9NqGJzfeI06hZ4cvmUXJrws84e+X1iH+Hjfvg0FwLJ lz6m/e+E07bKkU2ZgAo7ZqZxAHbI+iNYsetShDES2mIhufiwlvfK5Z5wS3SOQqpcWL2r +He+MHj1IiT+fqTVJdd5vZwc3esHjvnprl2wofTJr8++COMmxy5gpEC46KmfaBBL+X4d YaTYK3YcaJY7qlDQtvFSytpPojYxIQ6bopvMhLwN8kE9xx5/ZrcpKGgZMpD9QyC/rC6/ USBSEztUzlPdiWU68nkqZzykVgdmLRaeWVqUQfxskZZLkiP9Tb+N10T5CWHiRF2kHycI IXGg== 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=xvR8iX2outgELqejVmTcMhX9RlYLy+wU1js0WKyDum8=; b=nACFUUKR2Z+wZQ86soOtQ/gEpXyCOZS9LimKnpk9P/9XCmkFkUdrUO+5yqOZkNuBqY +hQr1liBlhXeNajhW8nJJ0cIDFuJyQnGWfAXQQRERPksFrYMmu3o++2GIUzftT8p58Xa mZ68j8/PvrTm2W13XKogbW7pIFHOszX98ows/QsdpfVRl23UVALgJ7RwEpSTpuym1CS0 VhxvSymT734SNGVYANfM1/G8Jzk4pxhp0gfLlBHKikWYmbt7y7j7SaUa2V83XE/Nkisb CEML9SFa6H6+TTPS1+LaSZGD3Ntct9S3GzjndXYlDh1SeA2W/LduvHGpXfILrX4ZoaoY 7ZCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=TRCk27Tt; 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 d14si8691441ybr.421.2019.07.16.17.15.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jul 2019 17:15:42 -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=TRCk27Tt; 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 ; Tue, 16 Jul 2019 17:15:48 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Tue, 16 Jul 2019 17:15:41 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Tue, 16 Jul 2019 17:15:41 -0700 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL104.nvidia.com (172.18.146.11) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 17 Jul 2019 00:15:38 +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, 17 Jul 2019 00:15:38 +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 ; Tue, 16 Jul 2019 17:15:38 -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 2/3] mm/hmm: fix ZONE_DEVICE anon page mapping reuse Date: Tue, 16 Jul 2019 17:14:45 -0700 Message-ID: <20190717001446.12351-3-rcampbell@nvidia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190717001446.12351-1-rcampbell@nvidia.com> References: <20190717001446.12351-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=1563322548; bh=xvR8iX2outgELqejVmTcMhX9RlYLy+wU1js0WKyDum8=; 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=TRCk27TtRrVv4ByDmKeCrqvJNp6+08H/etGBrEm50CH2SOXfZYymRmojCkvp8tLa6 H24TZFPuMsdO5jijygFy328uG5wNmKsxJMZir8gAsUoeMTM1BKQGEV8NBWZSheafK/ 1S/5Im8uAHIvUgtRm1EwNzfrk7IV6HonA8TEYRmmBQ2vyc8BFuVHI6uvlLQaEQfw0v XMqf8AqOwJrQxQ9pw5ESS5F/4G13BCIKLFjGjLccKaQ2cKaJzvx7FfBQi37zgSgXYP Ci17HzuHtXsMwYZDJqiTmYa54GJSGJ9gco+U/XzjJcosLSDUgG8c6QBed9JHo23xEJ cUx2MNq/WejeQ== 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" --- kernel/memremap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/memremap.c b/kernel/memremap.c index bea6f887adad..238ae5d0ae8a 100644 --- a/kernel/memremap.c +++ b/kernel/memremap.c @@ -408,6 +408,10 @@ void __put_devmap_managed_page(struct page *page) mem_cgroup_uncharge(page); + /* Clear anonymous page mapping to prevent stale pointers */ + 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 17 00:14:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ralph Campbell X-Patchwork-Id: 11046845 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 BEFB41395 for ; Wed, 17 Jul 2019 00:15:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AED85285CC for ; Wed, 17 Jul 2019 00:15:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3257285FB; Wed, 17 Jul 2019 00:15:51 +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 A7AFF285CD for ; Wed, 17 Jul 2019 00:15:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 96EC06B000A; Tue, 16 Jul 2019 20:15:48 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 91E528E0001; Tue, 16 Jul 2019 20:15:48 -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 80D676B000D; Tue, 16 Jul 2019 20:15:48 -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 634576B000A for ; Tue, 16 Jul 2019 20:15:48 -0400 (EDT) Received: by mail-yw1-f72.google.com with SMTP id h203so17457923ywb.9 for ; Tue, 16 Jul 2019 17:15:48 -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=dQvYVBMTRYc3SjF1PkfCIGikt9DQJqiS5LuvPJGyR14=; b=bJqTgDyCup/dYj1HNrpOeVGBUmBabqkcviGyOUPdLrFBBTGQzwnGQmUA3NwzWOD3Pv 00lGpyL7kwDMNDh/Nwz0fOJv9379GW9s/QQgt8iq83+es6HdiBnYWLL711xZlPD3oL9d l+0bu3saJYEy0mBQZRL8DRjtAd0LbH33vF0gLQ0rcZnNDK+80AztJ42why9uc9vtZhiu hRE97XYQQRP25JWHgffg0ltS29yTbIq6fBX84X9WIPfMQvtsW4Zmix9v1QVanPr5f4Yw N3MS0q0dd4Q9J0QJyQ0gv3xcnpki0lXkEWL4jmZsB/Wh9i78U5lI7QUkYlOJgf8l8Zm+ fySQ== X-Gm-Message-State: APjAAAVf9tjyTmqUFuuxWFcl0/KlW810mNTsR/dFDXEktbvfVvg4ztkb yRzhXMLkzm6+pHouGhWHDUu2CGtlmeJxuQDOQHIwHvs9i7solRZqlx/MPKIYdjloyGTLBRC99dH qkUTlpU4JIhnB6qXR9nxY7ZGScFr94gXFtPwfiEhcn+6YHFW1z8VxZ0TfDFkyq7Ggzg== X-Received: by 2002:a25:41c6:: with SMTP id o189mr23181423yba.110.1563322548126; Tue, 16 Jul 2019 17:15:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqzjVUejQC/E6WVDcv4cjEDCYXOW6AIo6d3ESaorp/o7KYAN6xvvuLBfa0f/1rosbaagn3kk X-Received: by 2002:a25:41c6:: with SMTP id o189mr23181396yba.110.1563322547630; Tue, 16 Jul 2019 17:15:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563322547; cv=none; d=google.com; s=arc-20160816; b=v4OcIs6ALJXpRjOyTiabl4g7E5KYkyOMmjJWnlZZrQM2y+iY0jpiJXTJmzlErV1Pxz 0WmP5O+tRiZKHETOP9EZlo8jlQv051W6bXVa3nGENeArlQN9cZZgzlj0zQ3ydegySDhS uN55OlbT8WNMufVdBXR2MgG4S+SJUn4Lh6KTw4RYJUHptG+acJqXYBWAamDvJqFt3IJF ARpaC2PF8+UpDjB1EnH6+6Z0CjpC4kpfJFRSB+ESeI4FP25+tdO+tN76F/LOMYMc/Z88 TVn/ZIYH5z944SbX29i8ER3xxkN9z2hkJ9Zdxv9kLGVGKq0kmEl03aQroe4hMqeuaSYd 6zvA== 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=dQvYVBMTRYc3SjF1PkfCIGikt9DQJqiS5LuvPJGyR14=; b=qRca0tPtbfj9noAp3Qi+TVHuoWfTXe+2GYJ2wROCmtieCMB4OWbrN8ws2btiWKH+9q /ZSSp3AYGUpDoqQGTCZm4UyUkiSvn4KHNxiF/02a1rmWpw9ZhckxcseCLPdQ0ipyGByV hfQpuAQeWxIkN+GXa9iZk5mgt3bL+9J6tymHvjfnUe0l0ShZMVagFr31t7pQnVFRJb1V OE5MWmqCM1azSze/IEfmsakLGQjGklsws0/fed0sYeUSIfEGlMiHif8P8CIydoVzFPO9 tsgwBGBvjebGLm/FojQHWWB0y47w2Fp14kYVlj8rIH3Df437Yj0YV0mpcM6SVad4KTED EioQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=OvNb5yTx; 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 p188si9262417ywg.204.2019.07.16.17.15.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jul 2019 17:15:47 -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=OvNb5yTx; 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 hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 16 Jul 2019 17:15:53 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 16 Jul 2019 17:15:46 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 16 Jul 2019 17:15:46 -0700 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL104.nvidia.com (172.18.146.11) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 17 Jul 2019 00:15:43 +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, 17 Jul 2019 00:15:43 +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 ; Tue, 16 Jul 2019 17:15:43 -0700 From: Ralph Campbell To: CC: , Ralph Campbell , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , "Kirill A. Shutemov" , Mike Kravetz , Christoph Hellwig , Jason Gunthorpe , , Andrew Morton Subject: [PATCH 3/3] mm/hmm: Fix bad subpage pointer in try_to_unmap_one Date: Tue, 16 Jul 2019 17:14:46 -0700 Message-ID: <20190717001446.12351-4-rcampbell@nvidia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190717001446.12351-1-rcampbell@nvidia.com> References: <20190717001446.12351-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=1563322553; bh=dQvYVBMTRYc3SjF1PkfCIGikt9DQJqiS5LuvPJGyR14=; 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=OvNb5yTxS0yQJ/QFCE+O4SUPLwvoCMYAUHOjDwGSxYfeA1s4J/mA35mjyGpfefFUp 073C33WyN1TcgFCRmljuxkv/yP/G7JpuRxl+7h3pCLo8uhRNryeGc3ILxOMvxAZYqI MsZ1qQWuqITEjYO9PQUmuc7GegYK+3RR6Rm1IMpon66Mk9LNCVjhy0crsVH35ow5X8 PwWlDzE+p3qI1hdOSLU0ZhwcMc1aBC865suP4f+l7DrrSh23BlRaZ2I8dLfTO8rR5Z eOYvJA2qp1GRRBUkEmlbC4RJH3BuFWJIbrA8MKrcUq1TC22VYponvU4B+FIrlUKCv8 I2xExWbJO+Kww== 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: 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; }