Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp600640pxb; Tue, 15 Feb 2022 23:23:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJzS9bJbWEMDSE7rDTgyjmgpWAmM8gppe6Xq3pSlvJd7K8uqCT5sZwqN8c31RFt3Ly4G/4Id X-Received: by 2002:a05:6a00:22cc:b0:4e0:58dc:e489 with SMTP id f12-20020a056a0022cc00b004e058dce489mr1800109pfj.58.1644996229487; Tue, 15 Feb 2022 23:23:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1644996229; cv=pass; d=google.com; s=arc-20160816; b=VjzpH0fLJz0xVVCO3Jvu3bwOLwjY/bq9mOJabwCoIDsp13QPGitMf49JXSylGm17hp jDJ6ZhPGE/yoIVp0oEDKWebU2V0JHM2j7xLlJblHj43AWPItOGqlvXmKkkK3VqFfnRUL iyWDPo0AesFvsCvnkYNTTN0HjSRWGyhJetDrZpE0TO9k3FH0XX6tu/o4eldrK7W/G6Xu 1IKzZmynpQAcpp1EMz8AbBSe7uhKTvJ5lwI5yYo5f7G0l7PjIwmmMrJSTofzkQj9gq03 0EOmRqHPsjz6vsW3vHWxtDm391iq9NPpsf1mf7Y63Gw0Hx5SyYcqkmY7Pa9AS8i1hbgs 0F7A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:in-reply-to:content-disposition :references:message-id:subject:cc:to:from:date:dkim-signature; bh=r+Ia2MduhHwDl8RlZcxpMeY8sMz2eLMp9xGxf/FSl/E=; b=adaWIXCNCXcG9M/ZfsH1qrzPUyFoiPEoTe4IbIviCNKW0TD0pYgAV3JGInr6dY702+ DKiC3t9WhdVmERILsStDLaog1Et0eeFfuE7OL99Hi6O/LERbc+cERoby366OByUSgG/i BwVa2xVmCiS2yThB0Ce07qWxzUO9hpMlkIXf2PnXtZeTAgS5Y+aoilDqESMhyD1pE7aB +FvTDHxZHsKeS2hdf1wE6Qh3NHdjLb5ztUXBkxjO6iNUyUdLcdpjG9kZOfONCaPpG0Sw Mg2QsPC9+B9yOCuuFDbdoWFtcKX8RGh85KZ9D4nr02i6ORPI3snNo5ZZoOJi7rx8VXtv qDFA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=Qp7NqG5g; arc=pass (i=1); spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id v190si4551529pgd.728.2022.02.15.23.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 23:23:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=Qp7NqG5g; arc=pass (i=1); spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 87EE62838C4; Tue, 15 Feb 2022 22:53:00 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233448AbiBOVsF (ORCPT + 99 others); Tue, 15 Feb 2022 16:48:05 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:45964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232789AbiBOVsF (ORCPT ); Tue, 15 Feb 2022 16:48:05 -0500 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2070.outbound.protection.outlook.com [40.107.220.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1365CE5B1; Tue, 15 Feb 2022 13:47:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gk9/hYoZjLLa5YRxGR2+uXQ96Y5aL/NvEbgYf3sCJ+8nZQfksxsx0JgSzioEuDxxRbiIIpHGBscHH7pw4kV9NvVB5lEuKxd1yUs7f0V2jkfc/SU5+v6nL1E5RXrxFAqoBR/hr9J+kupv/bJd/3sAjVtjFHl3ThJl89K4xkEREHii7MY9EvVksW+qApLVrjjigoYHpCfCbmb7+ZcqAxrJSaIvwEHZr+ZU6wqMHe7rhq0PkKdqVkqW/p4ns1N3p0c1wOqYYZDiG/ANy3hzc3w0twmcImlOnO+j3muGV4tHw59D+PXjbnk1MpAuu4u9tYzBuoGUMLpbcas+7iz939qEeQ== 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=r+Ia2MduhHwDl8RlZcxpMeY8sMz2eLMp9xGxf/FSl/E=; b=U3V5GL34Np4ZYsCwW1TZ80kM3140SY4YCZ4um4juJMn9Ep40nSJeYfcfExIf1+br5VLOi0T0HSIxlB4FNGrLkiQgGYjXhxgJ0VV/4kH6s6WazZbOTppCYdesoJDRy9XPlm+XjBmUzjmBeMSpsDT/SlCUMjhjFw2bNkEbB+xZrxPZUzjLpuvfj7o1JJ3rjS09Zm8AJ8OmHfWHl03dmV6V7xzg1rJ1RCnj+W6/fui+R3VdvyufFCXTQF8x0O8t5dmUgJzxAebtrt7LYNWjOh6JabgLJHRyPf0yBvyHT/l2+WAkwGWzMdQ4ENPJeBTn8juBj06cLXowpwCV2k0StSo3QA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=r+Ia2MduhHwDl8RlZcxpMeY8sMz2eLMp9xGxf/FSl/E=; b=Qp7NqG5gvkiT7Mv1NkHFEnNGwv/TW9RhYMPLbKYnfaSg4GIt2zc9qZN1CYMBpZZ4DiRiycMyLtaUkUr4/wobCxNNbam8Gx5T0wt+wYLIYSKR9p0wVxl0g1NuCPR+5Hc7YAvHBUk7YQSU6xn9bfgrkiWjhCtPBEr2/u72h2UW6sKAVsr5BP2XwY1iuna76zYTou0B1Kq3WKTzp6w7+krF8eRE4vlV9ShHmJS21NcAWQ7VmhbKKV1n3dORo2G2Pztdas/r//mufpazwEXqkXSbLFxhUE3cFabWUMKCTXOvTh74PljXI+rNIv0ptFToLfk163eiFoHAcL+SA0sCc4NZQg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) by CH0PR12MB5217.namprd12.prod.outlook.com (2603:10b6:610:d0::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.17; Tue, 15 Feb 2022 21:47:50 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::287d:b5f6:ed76:64ba]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::287d:b5f6:ed76:64ba%4]) with mapi id 15.20.4975.019; Tue, 15 Feb 2022 21:47:50 +0000 Date: Tue, 15 Feb 2022 17:47:49 -0400 From: Jason Gunthorpe To: Felix Kuehling Cc: Christoph Hellwig , David Hildenbrand , Alex Sierra , akpm@linux-foundation.org, linux-mm@kvack.org, rcampbell@nvidia.com, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, jglisse@redhat.com, apopple@nvidia.com, willy@infradead.org Subject: Re: [PATCH v6 01/10] mm: add zone device coherent type memory support Message-ID: <20220215214749.GA4160@nvidia.com> References: <20220201154901.7921-1-alex.sierra@amd.com> <20220201154901.7921-2-alex.sierra@amd.com> <078dd84e-ebbc-5c89-0407-f5ecc2ca3ebf@redhat.com> <20220215144524.GR4160@nvidia.com> <20220215183209.GA24409@lst.de> <20220215194107.GZ4160@nvidia.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: MN2PR03CA0028.namprd03.prod.outlook.com (2603:10b6:208:23a::33) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: baa9f4d1-c3ba-475f-a94a-08d9f0ccd02b X-MS-TrafficTypeDiagnostic: CH0PR12MB5217:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: e5ee25wSOcV6kWxZUY3hwES7JMnboFXq08KQ5TQizd6gysRokBHhQl9H0K9Quw7uA3SQ/z2CBO7tbKZxxKI8LLxRz2iRcbGMKql4fnThrEOksmSbxf3F7oYJDWciH4rMOyncgitkkB/LbcNMLTDPGHTi/A5BCwOyw3WpJMbAUpmgSUmlBxZRqVFCjI/17Lwl77ZWaT+8bFCwExxGphlJbNm79xQou37udLffCy4W2b4VhEuMf8UtqEpMCAHb5roVq1MfiiBp7ppgiR5xEjcBBN1+UXTj0O8cZ84sLVIDAwREw58fpBg1BocGQEF7g+vrC6eM5O2NL0CRxRfUZlfkSvd4rXOksa2DF7T7t9d3b00IaT7I3Ob26dSmM3fV0Bnor9d+2mLsX6VDGu34ha6z2xRBxWK165SRtPrwlQMIf+R/NHAGLv8CjHaFuEJ3wraSx0IxbQS3srpAJsLg/ndT/b1wpEof4B6kRzH1pTmtYFNTaJEe3MgbIOHS+ZGa1lZmNjZdmCBTl/+SrzcBgHPx09PVNeGuEuV2ddtFjUsuQT9gbx4S10IMC+FUlgvmXRQ/nKaORrzmrwnsi7GP3gEQBPHhPVqMEe5+D9ob9Sscm1CQoJtWwKeDc0AR7oyqnJ0qky0aK2Yshg+RouYdnqc6jA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR12MB4181.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(6512007)(53546011)(2616005)(6506007)(186003)(1076003)(2906002)(26005)(33656002)(508600001)(36756003)(54906003)(8936002)(86362001)(8676002)(6486002)(6916009)(7416002)(66556008)(66946007)(5660300002)(38100700002)(66476007)(4326008)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?rjpNj1cq1+6ZHekg0bJvkKUDj7Nq3SUkHwbV+z/Xnry+C775vbj+vGQ16HKU?= =?us-ascii?Q?2FcF97X6HPqRxTlhgpVi8LVaUgz4mYB86zPMLrcGAQ4E0Gn2xttdkr4LaUvj?= =?us-ascii?Q?F19MSde4Si6KeRHJ+CN6v5JX+0piNtN8yhLExJ72RoqS6aL+G7qFHMplNmm0?= =?us-ascii?Q?6eAhWvFiLLZDGy0bYySaL7V3urC1OCk8u92rmPgXeZThu96CvFS0xPtFAlCI?= =?us-ascii?Q?zEkCupY7wmY3Y4wGaXlXiM8q3gg7JXKa3+7bkybx7oAcvbnd5CegiRUfEt+Y?= =?us-ascii?Q?LfQe4dxo6PuYEm1GxOv4NeOPG7FLobz57nW/THbr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1QwN2xBHqaWFC99Csp6dIc3ps9i76Ik25ze0XQ3fQ7g?= =?us-ascii?Q?K1QwZ3VCg46urj+jfIkI3OIc/fRHqkmqNKrUxbcvXvP8qz/2pjUdvjuOOtDz?= =?us-ascii?Q?PHzk4uG52ONp6aKW9HLEByOx3Mfibm2Qaqt7BdyVwzuyDBF0Jw0vHayKbTQL?= =?us-ascii?Q?T89SPicSz6M14SUjTMkW/J7jaHNOUVYAPaNevXiYPc5JoX2xNcyi1DttsjG2?= =?us-ascii?Q?56NQhO6xeD/EcVF9H3UgOwGnFjYbIad5dBVIgcqBLy2BejyaSMXaq/45ThQ3?= =?us-ascii?Q?xYD93KeJU/e0do352kxWPiSpyqXDufBYaeowbSSlKKXpVc+FpofXV3TmXD/k?= =?us-ascii?Q?70rNCF3oHpe1tIh8MHw=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: baa9f4d1-c3ba-475f-a94a-08d9f0ccd02b X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4181.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Feb 2022 21:47:50.8351 (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: IhoZ4gE7jeglok5iYA+44CwEXi2iabe4Qob6thHMAiA/XS7CjxBgKl0/qaM2oGIu X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5217 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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-ext4@vger.kernel.org On Tue, Feb 15, 2022 at 04:35:56PM -0500, Felix Kuehling wrote: > > On 2022-02-15 14:41, Jason Gunthorpe wrote: > > On Tue, Feb 15, 2022 at 07:32:09PM +0100, Christoph Hellwig wrote: > > > On Tue, Feb 15, 2022 at 10:45:24AM -0400, Jason Gunthorpe wrote: > > > > > Do you know if DEVICE_GENERIC pages would end up as PageAnon()? My > > > > > assumption was that they would be part of a special mapping. > > > > We need to stop using the special PTEs and VMAs for things that have a > > > > struct page. This is a mistake DAX created that must be undone. > > > Yes, we'll get to it. Maybe we can do it for the non-DAX devmap > > > ptes first given that DAX is more complicated. > > Probably, I think we can check the page->pgmap type to tell the > > difference. > > > > I'm not sure how the DEVICE_GENERIC can work without this, as DAX was > > made safe by using the unmap_mapping_range(), which won't work > > here. Is there some other trick being used to keep track of references > > inside the AMD driver? > > Not sure I'm following all the discussion about VMAs and DAX. So I may be > answering the wrong question: We treat each ZONE_DEVICE page as a reference > to the BO (buffer object) that backs the page. We increment the BO refcount > for each page we migrate into it. In the dev_pagemap_ops.page_free callback > we drop that reference. Once all pages backed by a BO are freed, the BO > refcount reaches 0 [*] and we can free the BO allocation. Userspace does 1) mmap(MAP_PRIVATE) to allocate anon memory 2) something to trigger migration to install a ZONE_DEVICE page 3) munmap() Who decrements the refcout on the munmap? When a ZONE_DEVICE page is installed in the PTE is supposed to be marked as pte_devmap and that disables all the normal page refcounting during munmap(). fsdax makes this work by working the refcounts backwards, the page is refcounted while it exists in the driver, when the driver decides to remove it then unmap_mapping_range() is called to purge it from all PTEs and then refcount is decrd. munmap/fork/etc don't change the refcount. Jason