Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp393150rwb; Sun, 25 Sep 2022 23:30:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4XtrOdh1yWg3AOxKDUmbwYR1KY+6+i6/YCqqaRSA8aRNF9gFo0OKfe64zrZBTBpkfPy2eR X-Received: by 2002:a17:903:18a:b0:178:3ad0:2689 with SMTP id z10-20020a170903018a00b001783ad02689mr20497078plg.20.1664173837535; Sun, 25 Sep 2022 23:30:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1664173837; cv=pass; d=google.com; s=arc-20160816; b=tq1MwhheDoFmnJSF0tN8WjVMIC3/YH4hjsz7WbHZzjO5Rhkf/olCdq6zwksB5VTSIN cKmSOeFz9ckw+4Q4o9tgPJBqylCJaCXu7voqUNgMwqKapsDl1TB/CdfRCW9ymobVe6lL 6w0tXA321g3XJK/nbOCfO40jZtd/0ofU7JvYFNzGxnbzV0P+ZkVcv/uvkbOVJUu361BZ nxRK01Mm+ytDXpmMftUziGtxz9Usxiq8pKO9bbzhbDkBwxeqZ4DYfTib0HMIBvqobtk6 9+Fp6XCwCCQuiFiZia8T43vXrZSVeVlTV/5Qww7DfgYZScwuwpeeOT8BOmWiUbf7uxGM Cz7g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lpUR8gcIPaAR7nD1dKeC+83we5Ll0QdDdKicRyU/2VU=; b=CoN0y7OD2517jwsh+7kIUkpjmJUqCHTmdcxWMbHiKv25J297eNv/4Dqu07GCxV+AlN t5fuku2S9y4PdsZXDsWBxsDFtsvKmVqwTGt4f09DMr8jcYSOhHDzjn0dspUHtP+KLd+J DZFLh2W0B7JMzKFiERo2O6/09QyZMU36X/DraUAGw/1tev0eijdYIJaOs98YqHbuRwHp cg5MidMVMbKp/2+D/66f9ltEHitIKm0zAXbbbrz8Ibe74w1zhrnrDwpsTkcNWHmhBXIT KBgHwa8XYHTUSv0314fsN7ZvppBkEzXK8Rf5Bd9+ghYH8sJCMVUpmFF+0HjKWTpV8yyo TXxQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=PMHcNX1A; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r12-20020a1709028bcc00b0016eeb210483si10741096plo.321.2022.09.25.23.30.25; Sun, 25 Sep 2022 23:30:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=PMHcNX1A; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233528AbiIZGEi (ORCPT + 99 others); Mon, 26 Sep 2022 02:04:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233517AbiIZGEV (ORCPT ); Mon, 26 Sep 2022 02:04:21 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2065.outbound.protection.outlook.com [40.107.92.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C08A2648E for ; Sun, 25 Sep 2022 23:04:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Oca6pW+6+KtG/XgCOK0VrJvZ6IhDf/Nyfx/5a8Mmk63oyuThRZP1J+mGiuqYAk/5RhG8aUYgwFYjJ376bIKV/2RaLYxMMGYEWTPzSC6qslwWKWR7h0f8cv30ahReMc3jE4pv+G3oP58CGVRJ3rCIylPVkGKAWSp/nyQUuZRiAtjrwTwIhw0g7Xt8dMyKJZLljNgS8KxMV51bgn6aPuG0Kj/bBLVPlUUmGNYBkO9VR/6e65z4Yen8SiOZBRL9sMdAMfryQ//cDjjuSHx+NC4sUcxtk3Q9TmFRFz8AAqqzJEcNclncMirxISFUSx7EMvaFjUj5nBZlUxGSJC7mUpinaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=lpUR8gcIPaAR7nD1dKeC+83we5Ll0QdDdKicRyU/2VU=; b=Fhop26GLvxmPg1GIiy6s7+0gK9ChzQqUbXlK7SR5s2IauiEC666hVU2OP0uDZBpyaVWAHBFoimP/Nv5pet9OUaXm4DDYjXihmmjuXSSNLB213PT6urGg0OTuxNSxHXdAY3ETSEQuUms93krHl4W5FlO6GrURiZ+04Y8VM+l2fA1kLGuVgCb1Q531JoKWQrUzpB9j6YMZhSFpko1EPplTZNP3OoW9QsmqlDxcmLJmMotrCK+FGVPX/Zs+CZQuOZ0xs9/t+heTiHGIN4tA/P7hxhDeAlC1IOIp085qhvnYundWbWPSUt5TL5yre60mjigEPobtaBQS5AQrnzaDJWKCNA== 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=lpUR8gcIPaAR7nD1dKeC+83we5Ll0QdDdKicRyU/2VU=; b=PMHcNX1AcNm68fswb4wqfJoo6IGL+BWzkRMjjMdIa7gj5tXlvdnuBp3XWC1q/p3cvsfuh/l9f4VPo/p2oT3uDedlJ8xugwlEQxBDlanEdSBVw9C4fZZJp9CWAQbmutX53+sg+LmJoHvH2SMSS/qYUBA7aYsZ10kDa+ur0Gr5kFDoxnteawoWHIuIap6SNaJM93GHXoGq+1W3iShdwMXA3WQtxMLA+8NlO5t77uWKM1i6SKlG5plvh2RF/K4txTbw7G11atKzhaTBVPIqdQqYUcXfqEkThG4ASMY/gKvA03kn9ZpqrC0inHhn+AnWhoE0nljFeOW1fZNpIpo9bI3QdA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by MW4PR12MB7359.namprd12.prod.outlook.com (2603:10b6:303:219::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.25; Mon, 26 Sep 2022 06:04:18 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::ed0:a520:ac8e:9966]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::ed0:a520:ac8e:9966%6]) with mapi id 15.20.5654.025; Mon, 26 Sep 2022 06:04:18 +0000 From: Alistair Popple To: linux-mm@kvack.org, Andrew Morton Cc: Michael Ellerman , Nicholas Piggin , Felix Kuehling , Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Ben Skeggs , Karol Herbst , Lyude Paul , Ralph Campbell , "Matthew Wilcox (Oracle)" , Alex Sierra , John Hubbard , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Jason Gunthorpe , Dan Williams , Alistair Popple Subject: [PATCH 2/7] mm: Free device private pages have zero refcount Date: Mon, 26 Sep 2022 16:03:06 +1000 Message-Id: <3d74bb439723c7e46cbe47d1711795308aee4ae3.1664171943.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SY0PR01CA0006.ausprd01.prod.outlook.com (2603:10c6:10:1bb::22) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR12MB3176:EE_|MW4PR12MB7359:EE_ X-MS-Office365-Filtering-Correlation-Id: 42dc79fb-aca4-4410-816b-08da9f84f2bc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Sg8pk3ObyJPpGQXkXCrSAZrlI2JfuD7xYLEcvcWnSqNBC5l/zr/eIlMA3v5g6cNqFpPIBZk6le8SP+1o/FzBAL4i298q7XU4Kp9UvfXgJAAazaL5Y0LgRpKIT6vGoMrUJ6k83kfQiAfhQLcFQIZ3fdeKxeX9YB1BtbvXFM5Lm02EmMDaNfd/sWVTogWERr+z3BIjIbdaBtCYJP7TkUY/ejuUd3E9huIAFtn8wqeP5VL0egDMcAThpaErJjkr22/RjMXX0C9W298V96AgEpdLVPSQhHN4J6sAs5tjbO1olnfHB4XS7KLZHzA90D8yqDbkZS0RAwW9M1m8+03MajgeToulqBnox/cdDpW4BKDlRInUqrswG9FkTGJS8KYn+lKcHGpzU5FmLnSMOR+690JQiMJM0XDAe6x/8Il11R+32tILcxb+Ixsx5235bOE5DVZDhEhq1sGsAHejmdLZvVLsNyZzDGt37RBfyI34D0qol+lPRmRUC64DXhPG9thIZglx7UWSbk2kRXXYePRu1B0OEPvF7+a2v0n9VsYg84I48jx6H7oSJ6ahBzRofXCsytfXeDWYF3z1INZJJsLOvVBrlNvOmfzzNKfaP0YoYH/j0tmhBprpZi1PJwxHo3H7G1oF8ssOicZY4CBSYRlzlq/MNDSFawTCgGpnaDv6EwDnyMs/hixWEyIXMpuV0vZY9/X/43jPLnYlfV1eXqgcMT1isUQP8//m/8to+Mwhjhyy22+23EH3Sl1JLVgwrZkP6cio X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR12MB3176.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(136003)(366004)(376002)(396003)(346002)(451199015)(8936002)(86362001)(7416002)(2906002)(5660300002)(83380400001)(6666004)(41300700001)(6512007)(186003)(107886003)(26005)(6506007)(478600001)(6486002)(2616005)(6916009)(66946007)(4326008)(66556008)(66476007)(8676002)(316002)(38100700002)(54906003)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?VzBdNO6pyTug0f53OiDET+Rk1JMLTpnAA29eaaVmvQqdoMusNTsQgP71Jb0g?= =?us-ascii?Q?K/+grlWM0NnjIFLOFpmEmc0nXC4M/aINMh1iXnNqtZ0fkl/vQJ/CLZNEZGHO?= =?us-ascii?Q?cEcy9lJBqmAgQQm0guSUiTuImpDL+dIBBDc8dlGTSWGYE3nDF/Drh0AeTe5Q?= =?us-ascii?Q?a6o6zJW6/xatwj20z9g85cAJ2DD3ircz5HkNCT1o3PNRkSUnsan0vWLhQw0O?= =?us-ascii?Q?R/lDyzlMOH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i4OlxUz86sphVVDDe?= =?us-ascii?Q?dQml6IyQTILLDJQrpQdEIyASkcRVVkQIhMhbTAC6Og7O9AhV9ICIMLh4cHSU?= =?us-ascii?Q?J+GuFxqStPeZjJjmD3cmiTNjXmsKDTxYEeomxSsqwYlueEA1Ps3YO0Q6fzhD?= =?us-ascii?Q?2t2MLePgr4PprgH4lNHigstCWuEtH7L3DY8yq4VDEMn/f31wpTiIjTjFG/M3?= =?us-ascii?Q?TtpW2wmLKFXlx1BD68gk+s0ihbZhs4xgrskwjxsCPVZgBoD2q+5Hz0Bok9/m?= =?us-ascii?Q?JLKLpLsVcXzRGsqJ+LFpqPMd6EApW8sjmOKeFalYPA7RFvDowp2eFK9CvBqV?= =?us-ascii?Q?r6L5bY+8sD4+/M6BDFvi8k83r5LoPowU95+td4ia1QdCG1tRUy8zTtVIeUwz?= =?us-ascii?Q?yDGuU6yp2Sebi+iAFsld31UWJNhkTdpoLhrKLHKxneFtWKLxbpAO4s7hg6AJ?= =?us-ascii?Q?z7V9MJ3DA7Bl8M57P0Zr4gN9onksrqXmZZoAer1F?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 42dc79fb-aca4-4410-816b-08da9f84f2bc X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Sep 2022 06:04:18.5160 (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: pSJfaFl+AoP2iXV+KdZPR0OQ/OuPImsGV0AlcHXWV5stObXND6Q/pax0LvM2JKiC8tBfzane1jtZP79gVwCvAw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7359 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since 27674ef6c73f ("mm: remove the extra ZONE_DEVICE struct page refcount") device private pages have no longer had an extra reference count when the page is in use. However before handing them back to the owning device driver we add an extra reference count such that free pages have a reference count of one. This makes it difficult to tell if a page is free or not because both free and in use pages will have a non-zero refcount. Instead we should return pages to the drivers page allocator with a zero reference count. Kernel code can then safely use kernel functions such as get_page_unless_zero(). Signed-off-by: Alistair Popple --- arch/powerpc/kvm/book3s_hv_uvmem.c | 1 + drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 1 + drivers/gpu/drm/nouveau/nouveau_dmem.c | 1 + lib/test_hmm.c | 1 + mm/memremap.c | 5 ----- mm/page_alloc.c | 6 ++++++ 6 files changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv_uvmem.c b/arch/powerpc/kvm/book3s_hv_uvmem.c index d4eacf4..08d2f7d 100644 --- a/arch/powerpc/kvm/book3s_hv_uvmem.c +++ b/arch/powerpc/kvm/book3s_hv_uvmem.c @@ -718,6 +718,7 @@ static struct page *kvmppc_uvmem_get_page(unsigned long gpa, struct kvm *kvm) dpage = pfn_to_page(uvmem_pfn); dpage->zone_device_data = pvt; + set_page_count(dpage, 1); lock_page(dpage); return dpage; out_clear: diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c index 776448b..05c2f4d 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -223,6 +223,7 @@ svm_migrate_get_vram_page(struct svm_range *prange, unsigned long pfn) page = pfn_to_page(pfn); svm_range_bo_ref(prange->svm_bo); page->zone_device_data = prange->svm_bo; + set_page_count(page, 1); lock_page(page); } diff --git a/drivers/gpu/drm/nouveau/nouveau_dmem.c b/drivers/gpu/drm/nouveau/nouveau_dmem.c index 1635661..f9234ed 100644 --- a/drivers/gpu/drm/nouveau/nouveau_dmem.c +++ b/drivers/gpu/drm/nouveau/nouveau_dmem.c @@ -326,6 +326,7 @@ nouveau_dmem_page_alloc_locked(struct nouveau_drm *drm) return NULL; } + set_page_count(page, 1); lock_page(page); return page; } diff --git a/lib/test_hmm.c b/lib/test_hmm.c index 89463ff..2bd3a67 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -627,6 +627,7 @@ static struct page *dmirror_devmem_alloc_page(struct dmirror_device *mdevice) goto error; } + set_page_count(dpage, 1); dpage->zone_device_data = rpage; lock_page(dpage); return dpage; diff --git a/mm/memremap.c b/mm/memremap.c index 25029a4..e065171 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -501,11 +501,6 @@ void free_zone_device_page(struct page *page) */ page->mapping = NULL; page->pgmap->ops->page_free(page); - - /* - * Reset the page count to 1 to prepare for handing out the page again. - */ - set_page_count(page, 1); } #ifdef CONFIG_FS_DAX diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 9d49803..67eaab5 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6744,6 +6744,12 @@ static void __ref __init_zone_device_page(struct page *page, unsigned long pfn, set_pageblock_migratetype(page, MIGRATE_MOVABLE); cond_resched(); } + + /* + * ZONE_DEVICE pages are released directly to the driver page allocator + * which will set the page count to 1 when allocating the page. + */ + set_page_count(page, 0); } /* -- git-series 0.9.1