Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp581402pxb; Tue, 15 Feb 2022 22:48:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJxiLvWAdNp7YMAoNm/Y3w08g86ly95e/xofyM2UEpTeNY8tXsi33C3ZjB+biHv8IphJa9dK X-Received: by 2002:a17:902:f24a:b0:14d:b2cf:20cc with SMTP id j10-20020a170902f24a00b0014db2cf20ccmr1030744plc.118.1644994088207; Tue, 15 Feb 2022 22:48:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1644994088; cv=pass; d=google.com; s=arc-20160816; b=um7h0dts5/KzBU8YnAoe9RggRXfiWkUH0JKKqUYDe4Vpsb5IWXIsomJX1OMRM7CvIJ UWDH6pb/uoH4HlfD8U/oErmnxA8G9nTi3phWkYnGaUZoQbTm3EoDfJLSTE52weJl6nZ2 6Xt9C0f8uwwf4fg8qjG1RVgedlDw4IqLPIfQJC+FnHezD1/9XIvyTHrZDk/qwcI/7hnQ L8WUVImR7sra66xUHDiERxMA3JOmRggyz4niAPg8EdRF2RYaZkBkHxbh1NX+wyEwbR4R Sq0y1Xf8r2sg108PaHzHWOvzetAeK4qk5cwjqcKTXcuSo6M/VSzNPXKkyhlgRUzxEDP9 545g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:in-reply-to:user-agent :references:date:subject:cc:to:from:dkim-signature; bh=wiAGY9J6hBs55TYV19qkBE/0yt4FsMmKVbVzXfnMrss=; b=rkEsMCo8niLor13IExppeJL4NPizhyiTo2VFhQaXfwCKLyHljSuCxZT8tEOn0tsyfD S/4WdF8gA34rExNj8z71e0KDKw1xzSE82Yglgv9O6uckEa4u965inXZB/idPp6uoOey8 iFNjxsRZ3VkHGO8oZ52gYUtqk4XfUYSO5APT2udIoloavvo2Jjc1CVzUWuc80gjok6kf pHkLdOYYE9WlqqW3a1GlG/V/EbETqbEOFe1Oh41gsdxaz8mZNsjKQnuiHlcmRNA4Fmc6 H+EAQzdhIcPFQfXrJmYMailnn8CaydYufwx2Hj9fnippFSxuHxhv+MCXq6zU+qkfojwL MyMw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b="Mec/DCmq"; 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 w12si16674300pjc.51.2022.02.15.22.48.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 22:48:08 -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="Mec/DCmq"; 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 1C0D81FCBF1; Tue, 15 Feb 2022 22:34:27 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245743AbiBPCAF (ORCPT + 99 others); Tue, 15 Feb 2022 21:00:05 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:47136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233285AbiBPCAE (ORCPT ); Tue, 15 Feb 2022 21:00:04 -0500 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2079.outbound.protection.outlook.com [40.107.220.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEE709D0C2; Tue, 15 Feb 2022 17:59:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fkIZGrSkFaOVcGLEXMnGRd5ESqiRN2Ad//CrRKcCbVr6Ko/KU2Zfb2EPT6QNJLUyGKNf1bxRi6RHbBBKmKv8uv8hA2mIfbs1maQmDNQm5fXpBR8V4w/5oa3fTfbgyfRbGj0rZ/9k5XK+0UGCNAR/kS2cG1y4e5GhB63LYN/56J4E5gXEo1VBF3EXV5Z15JnGYrcnrSvkOo6nqGZFA0X7wkb5jDG/+k90ZoFYPgecRFjspsA9fjBGPROuKQNcVyd4Wi3ZWHPQI+C/xUFg7Mmsx1MxWRDbKy8MY2fM5SBXKRalzIbfSm8XkB/N6O5Q/VQrYNQSbnipmcirvNWuVz8cng== 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=wiAGY9J6hBs55TYV19qkBE/0yt4FsMmKVbVzXfnMrss=; b=dnCIzqJGgLZeeTgV9PArIjk6xG69HbJcIV6EKxobzxZUzZ/se8D6bcZYZIh2gpEVKQNXOZTxolDevYNnbw5V6oWAXqP7AVFQ7qX5ijEHGNe3Ub1ehagbYViDR6b+d6KCHyKMiyG/JbqYz5bMuqKr0DrDb5IfYqYe4ObjnjV4qPhVdgJyMB3IPbX4/UoCDR/k9+wCWAhm5kzqZXr1epDxFMkl0A2n1aZ8qQvp3PKgXsAFXHbL8Rmc5Cvlf4MP6HqXcoAzLwZEUY/vXo1GY4YuA060ZlnWs9/pCh3aHopsWx9xaxuhM6Zd8ANlT20LnhTEK9VYUvxHlgtrWGzi/8/prg== 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=wiAGY9J6hBs55TYV19qkBE/0yt4FsMmKVbVzXfnMrss=; b=Mec/DCmqSuNhXEkq3RCtWTKqRDesT8RhgMnBpAOMSlV242QBNGhvKwEPfwJTW1oDS1k7TQQEM3nFJCAwjJt6p2eEVDGXEFvj3ZnlpK91oII1+K9G6aEVuq9f9DLuDc0ewzxsZ5NHXJGVcbTIQ1Si9LYzj9pdnd1bEFSzZVJuHZW7buYtSHqXpjItIhDDdBm/DP1kAP9iPm8iwn/2/OZnXmYOdSz4WZ0S5gFxtso6A5glEMU/VLnvf0ZZ6meTcwhjLC82reS03iM1uiWdJaOYPAyQQe9An2x2ny+GySBWWbjKOiZUbJ3MRcJoCzt9cb/9Jezo8plWCK30OJUsA0D/6g== 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 BN8PR12MB3268.namprd12.prod.outlook.com (2603:10b6:408:6c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.15; Wed, 16 Feb 2022 01:59:48 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::1528:82a2:aa0:7aa6]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::1528:82a2:aa0:7aa6%6]) with mapi id 15.20.4975.019; Wed, 16 Feb 2022 01:59:48 +0000 From: Alistair Popple To: Jason Gunthorpe Cc: Felix Kuehling , 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, willy@infradead.org Subject: Re: [PATCH v6 01/10] mm: add zone device coherent type memory support Date: Wed, 16 Feb 2022 12:23:44 +1100 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> <20220215214749.GA4160@nvidia.com> User-agent: mu4e 1.6.9; emacs 27.1 In-reply-to: <20220215214749.GA4160@nvidia.com> Message-ID: <877d9vd10u.fsf@nvdebian.thelocal> Content-Type: multipart/mixed; boundary="=-=-=" X-ClientProxiedBy: BY5PR16CA0018.namprd16.prod.outlook.com (2603:10b6:a03:1a0::31) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3b735cc9-17a6-47ae-d826-08d9f0f002d1 X-MS-TrafficTypeDiagnostic: BN8PR12MB3268:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BFKxd24A2JCt37A5qzPVV1NO7NN1zkP/UNGC0PdSnzb5UYFe9o5TyFAZOt295RWycjN1DAyTC2okWsTBT8SHjnRRGufNPlIc+4CM9zcKQgViUH71yK42GoO3OZqS7Zx9U8NiFXO8ElpfiEFUtMZJ3lwnmI0e7oHSsr3ddnPJIJikvIYZJ7/oBlEm/vx9HocoAG7sYqdIvJEFpFbtFj5cGijJHmpYtC0iLY2kXO8+aZHQEObqvQy7AkxriNCynB17BBudDS5jBdArvQ3Yj/V92v1NubjE0B60D+osnIW6H16GqlOj7N+5NQTFtSK6DA1Ml473iCmq14nD1oVgLyQntgwBWVlDFswIxgQ61uvBGItvsCNI05xapKhaoO+V33yb2g/ld1GDyC5WoBYjGXPAaCcTJs+wtDRT7Q1NmGGBRK+XYr3RaaazG7IF2MXfUnrvI7XJK6Ta8eRaITB8n2aewjmT7jSv2WYbev3FRuFw9Vuj30RWL2lWMR8eXP2a91M1gH/EOgEGzIyX2fex1TpvWV27jEZKt7C5cdF7ws47IvF8O6p7UJmSf/89IxirYZTfMgZZ4Y7fbj9BmGx56UaK1MDYaAMb7Wtv3KqSsKPQohhEOdtkdeoi5Eij89gHWsCx4opLU/9WC00O1+r+XrHRbw== 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:(13230001)(4636009)(366004)(508600001)(6862004)(6636002)(66476007)(66556008)(26005)(4326008)(186003)(316002)(7416002)(38100700002)(54906003)(6486002)(66946007)(8676002)(2906002)(6512007)(8936002)(86362001)(6506007)(6666004)(53546011)(44144004)(5660300002)(9686003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?aufCifvl2+1r8IBD8fm9vthpTUWN3JCDT20Cc/U1pdmwDSnNpe4r25Jzfl2G?= =?us-ascii?Q?Gw7U7tPRDDNWbvCEbg71wTbufG3OdONTWkYMcS2xlca6IjTIkxPoxtHpmKja?= =?us-ascii?Q?l3n2qPfSF6R0hBgfWL4aNEHY5Juos0JkuT34T79jTatHTgwjVLBvwiN+wgMH?= =?us-ascii?Q?HOJPuT+n8tNJHk9zfD+PThjAflGw3163Xv6bNOCRZNiJB/zPYk0DQzINoQX6?= =?us-ascii?Q?Daf+C+EbSGQsgvxyfy2uQV2uGz0D6dBYOM0X2RM1QXlT2pqGfxXxbTIjk3ZT?= =?us-ascii?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94SV7TziSph37TzQShO8D1ZR?= =?us-ascii?Q?0Eb2HB1qSyTayhoK91rem+uWWvCd7bqVn9ufoMiytr1IVpp/vWOH4GMSza0j?= =?us-ascii?Q?iCxMbvEtL+ndWQoKTIB00+kDp1mHxjfhKF/liApheW+o/4tHbBai5Pa7alN2?= =?us-ascii?Q?iKDrcYl9VQZqkyLPCy4xOjS6lS2Ira8C3FKos3F6UtXKU0pQPgZce62t1D6/?= =?us-ascii?Q?0WarzuJiLeZmLEkBTZLRaaAu2uaaZVyeNxL6d+POjAUmyY0BontaXB7LavEE?= =?us-ascii?Q?b3XM58ecDtpaWVEx09fUNrdVjx5hpUvWTY33xyqAXGvDgEawtC3jRxMPKR9f?= =?us-ascii?Q?E+iPU9fG8z+VEe0EbzrYU2iKmTryrKPkzqq26nN9IBI/5gkX3PBl7mTynKbo?= =?us-ascii?Q?QPOfm1NNwBJcq7o4CVj5wDW93wazj3hecZgNtxD9olwKweYICwEyNvekVgv+?= =?us-ascii?Q?RxxqEbE7AdPioTqKTVmFYnc=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3b735cc9-17a6-47ae-d826-08d9f0f002d1 X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Feb 2022 01:59:48.1947 (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: XPGkitRuRn1JGng18z90KblluL4BsROevpxI8jcs+OQMjwFRkfIwIYJy1M8R2Ng50h2C7WS/KUJMHrCqZMSr4A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3268 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 --=-=-= Content-Type: text/plain Content-Disposition: inline Jason Gunthorpe writes: > 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(). Device private and device coherent pages are not marked with pte_devmap and they are backed by a struct page. The only way of inserting them is via migrate_vma. The refcount is decremented in zap_pte_range() on munmap() with special handling for device private pages. Looking at it again though I wonder if there is any special treatment required in zap_pte_range() for device coherent pages given they count as present pages. > 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. The equivalent here is for drivers to use migrate_vma to migrate the pages back from device memory to CPU memory. In this case the refcounting is (mostly) handled by migration code which decrements the refcount on the original source device page during the migration. - Alistair > Jason --=-=-=--