From patchwork Fri Oct 14 23:59:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 13007536 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9479EC433FE for ; Fri, 14 Oct 2022 23:59:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D3436B0092; Fri, 14 Oct 2022 19:59:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 283666B0093; Fri, 14 Oct 2022 19:59:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 14B6F6B0095; Fri, 14 Oct 2022 19:59:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 030756B0092 for ; Fri, 14 Oct 2022 19:59:13 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D862C160393 for ; Fri, 14 Oct 2022 23:59:12 +0000 (UTC) X-FDA: 80021223744.02.E4C8CB7 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf25.hostedemail.com (Postfix) with ESMTP id 4F030A0028 for ; Fri, 14 Oct 2022 23:59:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665791952; x=1697327952; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xtNMf37ZvlWFUlBN5phg2oXwEnFZD9IVJ73UXHkz864=; b=B1KTkvejPuKexEusLh6EuB5DV4ieWC4uYMmZG5punvfI9w5NvS2T1Cgc K5H33BiqgF3HinZ7HB2hqtciBCsLJLUKkWzZowRVwlt9BvAffqrpbG742 iJHxrXCSPYK/KWWyjAR+leCT54rmMrphC8c6SG4utE/nHNhYLpSmFkeRN CatGnyabjPWcj+Ps7hIsAjQp+9B7dApHJZF/oyH+kXfflRX1fXmG4KGUt ycPaNuzA3Ou75SfJ958mQzGND3OjOgw41v+dNMp0JGDHf6CCP6S8wOHtC bOGF7GyVb3m/IijEazuNxnlmeJ/vAbdCqqvqJlc4XXHQpJfTxQ2bkvPxD Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10500"; a="292862183" X-IronPort-AV: E=Sophos;i="5.95,185,1661842800"; d="scan'208";a="292862183" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2022 16:59:07 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10500"; a="605541354" X-IronPort-AV: E=Sophos;i="5.95,185,1661842800"; d="scan'208";a="605541354" Received: from uyoon-mobl.amr.corp.intel.com (HELO dwillia2-xfh.jf.intel.com) ([10.209.90.112]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2022 16:59:06 -0700 Subject: [PATCH v3 22/25] mm/memremap_pages: Replace zone_device_page_init() with pgmap_request_folios() From: Dan Williams To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , "Darrick J. Wong" , Christoph Hellwig , John Hubbard , Alistair Popple , Jason Gunthorpe , Felix Kuehling , Alex Deucher , Christian =?utf-8?b?S8O2bmln?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Ben Skeggs , Karol Herbst , Lyude Paul , =?utf-8?b?SsOpcsO0bWU=?= Glisse , david@fromorbit.com, nvdimm@lists.linux.dev, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org Date: Fri, 14 Oct 2022 16:59:06 -0700 Message-ID: <166579194621.2236710.8168919102434295671.stgit@dwillia2-xfh.jf.intel.com> In-Reply-To: <166579181584.2236710.17813547487183983273.stgit@dwillia2-xfh.jf.intel.com> References: <166579181584.2236710.17813547487183983273.stgit@dwillia2-xfh.jf.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665791952; a=rsa-sha256; cv=none; b=RCVnMG0sypYiDQ67ioDMGKJQptg6uFnYmT5QgbcG41LjKHqHiAwOUBPUaSkhsPKCO6jbGl mPOGIAxHdVoiE8C5n+61d89yfs045xrSOGoV5Mynpu57oPhfnKoUKoaYxniwVrcT9LoYE7 oa4Cu1YFo1mZsCLw4SMdAIaphOLY3/I= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=B1KTkvej; spf=pass (imf25.hostedemail.com: domain of dan.j.williams@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665791952; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=KOPoQq9qRu/SLFW4lLa/uh/OSLzi/RXmW0heKCYTTaI=; b=Dtm+RQ4URvcqjyNEhqb5tsEL0wKNtBIWlnCHIC8Tu4XOVGi8hxkOnBpcalT055Y45T6Avp DC96XIC1q61QV/j0ifSU8TZJs14xuijlebQ6TVfLygarwxQey40PhYshoFkL/qfUXSEjaF t+obsEFd7c6A9DoUTg/LmzDbwXQvz9E= X-Stat-Signature: 5kyab1c86fjuo3r6tfa6x5ctsz5yjqha X-Rspamd-Queue-Id: 4F030A0028 X-Rspam-User: Authentication-Results: imf25.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=B1KTkvej; spf=pass (imf25.hostedemail.com: domain of dan.j.williams@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspamd-Server: rspam06 X-HE-Tag: 1665791952-552778 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: Switch to the common method, shared across all MEMORY_DEVICE_* types, for requesting access to a ZONE_DEVICE page. The MEMORY_DEVICE_{PRIVATE,COHERENT} specific expectation that newly requested pages are locked is moved to the callers. Cc: Matthew Wilcox Cc: Jan Kara Cc: "Darrick J. Wong" Cc: Christoph Hellwig Cc: John Hubbard Cc: Alistair Popple Cc: Jason Gunthorpe Cc: Felix Kuehling Cc: Alex Deucher Cc: "Christian König" Cc: "Pan, Xinhui" Cc: David Airlie Cc: Daniel Vetter Cc: Ben Skeggs Cc: Karol Herbst Cc: Lyude Paul Cc: "Jérôme Glisse" Signed-off-by: Dan Williams Reviewed-by: Lyude Paul --- arch/powerpc/kvm/book3s_hv_uvmem.c | 3 ++- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 3 ++- drivers/gpu/drm/nouveau/nouveau_dmem.c | 3 ++- include/linux/memremap.h | 1 - lib/test_hmm.c | 3 ++- mm/memremap.c | 13 +------------ 6 files changed, 9 insertions(+), 17 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv_uvmem.c b/arch/powerpc/kvm/book3s_hv_uvmem.c index e2f11f9c3f2a..884ec112ad43 100644 --- a/arch/powerpc/kvm/book3s_hv_uvmem.c +++ b/arch/powerpc/kvm/book3s_hv_uvmem.c @@ -718,7 +718,8 @@ static struct page *kvmppc_uvmem_get_page(unsigned long gpa, struct kvm *kvm) dpage = pfn_to_page(uvmem_pfn); dpage->zone_device_data = pvt; - zone_device_page_init(dpage); + pgmap_request_folios(dpage->pgmap, page_folio(dpage), 1); + lock_page(dpage); return dpage; out_clear: spin_lock(&kvmppc_uvmem_bitmap_lock); diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c index 97a684568ae0..8cf97060122b 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -223,7 +223,8 @@ 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; - zone_device_page_init(page); + pgmap_request_folios(page->pgmap, page_folio(page), 1); + lock_page(page); } static void diff --git a/drivers/gpu/drm/nouveau/nouveau_dmem.c b/drivers/gpu/drm/nouveau/nouveau_dmem.c index 5fe209107246..1482533c7ca0 100644 --- a/drivers/gpu/drm/nouveau/nouveau_dmem.c +++ b/drivers/gpu/drm/nouveau/nouveau_dmem.c @@ -324,7 +324,8 @@ nouveau_dmem_page_alloc_locked(struct nouveau_drm *drm) return NULL; } - zone_device_page_init(page); + pgmap_request_folios(page->pgmap, page_folio(page), 1); + lock_page(page); return page; } diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 98196b8d3172..3fb3809d71f3 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -187,7 +187,6 @@ static inline bool folio_is_device_coherent(const struct folio *folio) } #ifdef CONFIG_ZONE_DEVICE -void zone_device_page_init(struct page *page); void *memremap_pages(struct dev_pagemap *pgmap, int nid); void memunmap_pages(struct dev_pagemap *pgmap); void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap); diff --git a/lib/test_hmm.c b/lib/test_hmm.c index 67e6f83fe0f8..e4f7219ae3bb 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -632,7 +632,8 @@ static struct page *dmirror_devmem_alloc_page(struct dmirror_device *mdevice) goto error; } - zone_device_page_init(dpage); + pgmap_request_folios(dpage->pgmap, page_folio(dpage), 1); + lock_page(dpage); dpage->zone_device_data = rpage; return dpage; diff --git a/mm/memremap.c b/mm/memremap.c index 87a649ecdc54..c46e700f5245 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -518,18 +518,6 @@ void free_zone_device_page(struct page *page) put_dev_pagemap(page->pgmap); } -void zone_device_page_init(struct page *page) -{ - /* - * Drivers shouldn't be allocating pages after calling - * memunmap_pages(). - */ - WARN_ON_ONCE(!percpu_ref_tryget_live(&page->pgmap->ref)); - set_page_count(page, 1); - lock_page(page); -} -EXPORT_SYMBOL_GPL(zone_device_page_init); - static bool folio_span_valid(struct dev_pagemap *pgmap, struct folio *folio, int nr_folios) { @@ -586,6 +574,7 @@ bool pgmap_request_folios(struct dev_pagemap *pgmap, struct folio *folio, return true; } +EXPORT_SYMBOL_GPL(pgmap_request_folios); void pgmap_release_folios(struct dev_pagemap *pgmap, struct folio *folio, int nr_folios) {