Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2991020rwb; Thu, 29 Sep 2022 18:57:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5fn6H9hjZySqq4OMl2+Eemt8eO9Fw8M4noBA2De8d0oYIqHkK/Il33sphcCAfwHFfFIMLP X-Received: by 2002:a17:907:7625:b0:779:e6f7:a669 with SMTP id jy5-20020a170907762500b00779e6f7a669mr4831931ejc.472.1664503066277; Thu, 29 Sep 2022 18:57:46 -0700 (PDT) Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ji10-20020a170907980a00b007808393cf7fsi927986ejc.413.2022.09.29.18.57.20; Thu, 29 Sep 2022 18:57:46 -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=@intel.com header.s=Intel header.b=bZRGQJE3; arc=fail (signature failed); 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229998AbiI3Btq (ORCPT + 99 others); Thu, 29 Sep 2022 21:49:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229885AbiI3Btn (ORCPT ); Thu, 29 Sep 2022 21:49:43 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CEC4E8D for ; Thu, 29 Sep 2022 18:49:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664502573; x=1696038573; h=date:from:to:cc:subject:message-id:references: in-reply-to:mime-version; bh=D0z8hsS40PlLHZh0wFjL38mUyX7aB8MdWDY1E/dj1v0=; b=bZRGQJE3x8D8Q6LYBB9qCOcRxpaVNKKwf9qn64CWpAF6HKPmrWdc1b+K 1Ys0hHIj+NQKy9zC5CuvvE6hHSfEZIbpNY+OLWJG+Ff0uxB8Y/cUx1utp DjjPti1ETIz+h7xqafIns95S0eG8UBBShg4S/tGG42zAf0UruPwOStYDK PYh4a91jnu7BLtXRRkP3j9uqT7LQFd4tU9g7K7mKfN6tatFKSrKi6wEFY oEycy41IQqHZncrh0NUbiOWX2IfmwIY6H9vHZo/4htXBdLjIg3BVP22/D Ug/H1jvh80YXXeV1+5QBqwIQzvResxRKqe6TlxekVcBwTo0Yvv6etM7hM w==; X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="303563754" X-IronPort-AV: E=Sophos;i="5.93,357,1654585200"; d="scan'208";a="303563754" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2022 18:49:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="600236764" X-IronPort-AV: E=Sophos;i="5.93,357,1654585200"; d="scan'208";a="600236764" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by orsmga006.jf.intel.com with ESMTP; 29 Sep 2022 18:49:32 -0700 Received: from orsmsx608.amr.corp.intel.com (10.22.229.21) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 29 Sep 2022 18:49:32 -0700 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX608.amr.corp.intel.com (10.22.229.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 29 Sep 2022 18:49:31 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Thu, 29 Sep 2022 18:49:31 -0700 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.100) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2375.31; Thu, 29 Sep 2022 18:49:31 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KGqp6RZWjxnbVv0QgIaF0id+OPy02XH3+7NSI4rbaA+XpRTRBBpYBHS+K5pQE4Xcq/QwSl4SCvp/RqjlmwZha4qx6QopC0hxNEttMqzDmHevhVTw4Aues8CdUUaiaHBUO1YP/unK9/i8Cr/iVxstJf/wD7e+9ojQ2BBLqg7K0Do9bA4ae0LfXng4CPcYH6A1T1Z1ZTFaSBDDsc+343JvVWrfekVdfpMhWHDXfMEQZkj6N4ZVz8BAIGtaplKUU9hiph+ZFP6g2lGN2lM4h0qXA/nsp8PlaWVlTEC0rKheWZJnoRx0pcjnyot3x4PLr8wrfq56txcUbDw/iIx6EVSMww== 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=45y12BK85FuuqjolWf81debnE7b6tfOr2CSN3criTEQ=; b=T0dhoYhqdeW5VC3lyau3IVfPGK0zio6xokT2bs3IeOV7415JbS/IXoMazXQyxK/rAv2W+zQu4sGiewNpFcCjgAPqNdLPebF/cerGPg08uoJ38WfSsqIdaSSA+Tj4gFDerK8ehyfwi9/CxPgPy6uJYXS22exVwtWPnzDzoJot54B4Msa6mXCuDacNio38GQdnt0AphWCw72jyvDlTciMupKmPloLyTdl1o0VmQCAVjcPyI8NKN6EOkXmuMTJ/Lo0SrKvT1XC1XZtdX6vWEDQ6QpsuqwQZ0j7PXWnzLsGGwT9550bmNcyPEWQx+0bqUehEl3GADoZrBeNTrpE0gbYz/w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from MWHPR1101MB2126.namprd11.prod.outlook.com (2603:10b6:301:50::20) by PH0PR11MB5877.namprd11.prod.outlook.com (2603:10b6:510:141::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.17; Fri, 30 Sep 2022 01:49:24 +0000 Received: from MWHPR1101MB2126.namprd11.prod.outlook.com ([fe80::7d5a:684d:99f7:4e83]) by MWHPR1101MB2126.namprd11.prod.outlook.com ([fe80::7d5a:684d:99f7:4e83%12]) with mapi id 15.20.5676.017; Fri, 30 Sep 2022 01:49:24 +0000 Date: Thu, 29 Sep 2022 18:49:20 -0700 From: Dan Williams To: Alistair Popple , Dan Williams CC: Jason Gunthorpe , , Andrew Morton , Michael Ellerman , "Nicholas Piggin" , Felix Kuehling , "Alex Deucher" , Christian =?iso-8859-1?Q?K=F6nig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Ben Skeggs , Karol Herbst , Lyude Paul , Ralph Campbell , "Matthew Wilcox (Oracle)" , Alex Sierra , "John Hubbard" , , , , , Subject: Re: [PATCH 2/7] mm: Free device private pages have zero refcount Message-ID: <63364b20ee66d_7390294a1@dwillia2-mobl3.amr.corp.intel.com.notmuch> References: <3d74bb439723c7e46cbe47d1711795308aee4ae3.1664171943.git-series.apopple@nvidia.com> <877d1plfrm.fsf@nvdebian.thelocal> <6335fd87adc7f_f6c9d29474@dwillia2-xfh.jf.intel.com.notmuch> <87k05llly0.fsf@nvdebian.thelocal> Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <87k05llly0.fsf@nvdebian.thelocal> X-ClientProxiedBy: SJ0P220CA0006.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:41b::29) To MWHPR1101MB2126.namprd11.prod.outlook.com (2603:10b6:301:50::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR1101MB2126:EE_|PH0PR11MB5877:EE_ X-MS-Office365-Filtering-Correlation-Id: 200e443b-4afa-4160-d52f-08daa2860071 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zfOezU+l/ZfaFYLKZXeHJQ3UB4mTnLwQhncz9vFvqcG5jYvl6BtOaqyMqYOB0tHGadjPgS3mVaYxzak676CMkDJwJwyJdTws1Ue+IqPulz9mrAbyqZoRTqxsRYF//URFaOTpvNN5m8aT/uJAA+t8UijqRO5icmF9wsfXiZwP9uMy9HZempzQ+OosPfUqHRrHtg4SNUJ3p9UkniqQ6rhP1U7nKE1fEKE2ZKyxkl1qERmE+h3nC6empLUYjSD/H+1XmGVSaJcwJkXTjvOVzJkEBkglu5tYWNuueOSsR5Mi4BrqUiEQfWOn3wTpt7j8auaxPDQ9HwXJ9I1vxrHrdcGaHKWlqM+WuqmPfVFJX+X+PB5QbjYNy+BE0eSxE8/VfZG5Hb2WVwoYP2/P7veQLn73PtnURVqC9ZYFsXXsqgoX1yqbLC9xm4v5ZjgOvQD512udwf50slhmPZY7JzUcUtL+DJ9ecINB+/ivD9pf3Z3i2PPpKuRLDs1sHKGtS5kkRLANfSJyttP5yfv7cgeCiEoR3XOIGSw4JfQckeVcb91xednme6NpyfKxKM7lMTLuDFJKAQv7mMgoNsqrDIiezPZuLnvbIZDxGfzATSubiJmOcWvcvDVoaRtVrQkuEV9ApWj2iwtCPBy9mkYCKm56sm4oIogkdL8P4VEhpBBPdPsU8eJbYZuF42qyth/0mhRB7E5sfrzv3xhD+PqaOg38OGpBU3zbQYWcQoF9QUkvcROLtCF/J17AaaT+aUUo+Mjf2klB X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR1101MB2126.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(136003)(376002)(346002)(39860400002)(396003)(366004)(451199015)(2906002)(478600001)(66946007)(41300700001)(4326008)(66556008)(8676002)(66476007)(316002)(6666004)(86362001)(186003)(5660300002)(83380400001)(7416002)(9686003)(6512007)(6506007)(26005)(8936002)(38100700002)(82960400001)(110136005)(54906003)(6486002)(966005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?0M0H5Ibl78YFwgxHjkTJVmCguTih14uLQrWTIWhrT+iGddLvNYacOj2JkTWI?= =?us-ascii?Q?XQ//g2fx+sqA5vG7kESi54ep66pTkSkiL5yX2lqME1x8UxbARTm4h3g8Ml/z?= =?us-ascii?Q?m9xjRsuZtGMaQ12A9mjG6l3oeMSQi54hzyMYfj+Isno8Wce0aM93crgbBoN6?= =?us-ascii?Q?Ct7YAjM79YE+E9yzxW3C+XRj2wPGxIaOCXXsbBjCcrUNurb3A65VpKfUZl/V?= =?us-ascii?Q?Vex4PmlCo41oG+oiza48m78Ut7jJaK2QUabFFSKw77qOgznq9Fs3a6pKoIIh?= =?us-ascii?Q?apvx7LZDIp3PPDzXacG+/XTd3/iU5WqnsPl0duHkE+JgeR69bk2cC5IpgG98?= =?us-ascii?Q?rS2BkDEhlKPOer6zO6ULUCBTDSrsySxGp7j/ITFnH+nUhWIJ6fuW45lgO/O/?= =?us-ascii?Q?bx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1fkH6+cZaEal7/QC?= =?us-ascii?Q?Pbauxky39BxPsNIex8he8wVLxxABTdpYGd6nRmV6ouqBV8OyQmAGc2TUTKeO?= =?us-ascii?Q?EL5daB9PGXd8IwCJ6qGDOPbSkndTiBkhmg4uoFPMrJNrTrP8FlnVxubo18//?= =?us-ascii?Q?sm1Ayh5XRcRjaeGbQKAh3JMz1qL168WvDDHqg889eZYBwAV43nM/6tNzx6Do?= =?us-ascii?Q?DwhAgcVgCAVK7TrJqciEwLTtL+M0+PyubzCdJrUbB4xNGSKLg7/qhv6rQdHY?= =?us-ascii?Q?mZ8J/aEu09t53Eutuig9uaz/gkaqTI9yz4sTTzExE61exHPzEaA5R5RzvEVU?= =?us-ascii?Q?2g=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 200e443b-4afa-4160-d52f-08daa2860071 X-MS-Exchange-CrossTenant-AuthSource: MWHPR1101MB2126.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2022 01:49:24.5155 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Il8CfWe8Zs6X5xU0+zppk5yiuvhekafKsJzcDqSiC6QKpf3+uZGSygvAdf59wkFE28rVRzycSfIL473+ul+XPXz7RNcaVaTfCA904MPEUjc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5877 X-OriginatorOrg: intel.com X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,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 Alistair Popple wrote: > > Dan Williams writes: > > > Alistair Popple wrote: > >> > >> Jason Gunthorpe writes: > >> > >> > On Mon, Sep 26, 2022 at 04:03:06PM +1000, Alistair Popple wrote: > >> >> 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(-) > >> > > >> > I think this is a great idea, but I'm surprised no dax stuff is > >> > touched here? > >> > >> free_zone_device_page() shouldn't be called for pgmap->type == > >> MEMORY_DEVICE_FS_DAX so I don't think we should have to worry about DAX > >> there. Except that the folio code looks like it might have introduced a > >> bug. AFAICT put_page() always calls > >> put_devmap_managed_page(&folio->page) but folio_put() does not (although > >> folios_put() does!). So it seems folio_put() won't end up calling > >> __put_devmap_managed_page_refs() as I think it should. > >> > >> I think you're right about the change to __init_zone_device_page() - I > >> should limit it to DEVICE_PRIVATE/COHERENT pages only. But I need to > >> look at Dan's patch series more closely as I suspect it might be better > >> to rebase this patch on top of that. > > > > Apologies for the delay I was travelling the past few days. Yes, I think > > this patch slots in nicely to avoid the introduction of an init_mode > > [1]: > > > > https://lore.kernel.org/nvdimm/166329940343.2786261.6047770378829215962.stgit@dwillia2-xfh.jf.intel.com/ > > > > Mind if I steal it into my series? > > No problem, although I notice Andrew has already merged it into > mm-unstable. If you end up rebasing your series on top of mine I think > all that's needed is a patch somewhere in your series to drop the > various `if (pgmap->type == MEMORY_DEVICE_*)` I added to (hopefully) > avoid breaking DAX. Assuming DAX takes a pagemap reference on struct > page allocation something like below. Yeah, I'll go that route and rebase on top of -mm. Thanks again.