From patchwork Thu Aug 17 06:49:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13356022 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 50274C2FC14 for ; Thu, 17 Aug 2023 07:10:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C6400280024; Thu, 17 Aug 2023 03:10:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C146D280023; Thu, 17 Aug 2023 03:10:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ADD80280024; Thu, 17 Aug 2023 03:10:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A07C2280023 for ; Thu, 17 Aug 2023 03:10:22 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6291A120FEB for ; Thu, 17 Aug 2023 07:10:22 +0000 (UTC) X-FDA: 81132723084.05.2A10B09 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by imf21.hostedemail.com (Postfix) with ESMTP id 4C9A41C0022 for ; Thu, 17 Aug 2023 07:10:20 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=SZ6oeVXP; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf21.hostedemail.com: domain of vivek.kasireddy@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=vivek.kasireddy@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692256220; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HSbfcFRzWKnUPIMwRtvbNjhz2JF5a97flZcJGyMLD/E=; b=NMTKsHMLPRVwVOaMvfNLr5dVqpGaO+LO+P11g5oZ9H+aZjD1DjO1CabJA2rTyRvDiypDYv +01NAGYhciZ27noCpxuq1z5vtdDi1wDTGCZ4ezOGwv+Z4GFt3gKNAFcEuNhysgYwSpNRQ+ jcTvWJLSO8t/7xC1fyjujc5pFdtVZu8= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=SZ6oeVXP; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf21.hostedemail.com: domain of vivek.kasireddy@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=vivek.kasireddy@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692256220; a=rsa-sha256; cv=none; b=xTnvbAo9dHXH4No37C68K8yE/f53+g7yBkMsrbyGzwSSolODycogpPdcvKIHomJUi9pc/0 s3xQ7byvvexhCfgKd2wTNlzVbJzI3nQuN9ddk+fuUH1nrQX/0LbytZjdy4YqlTeU/ek3bg r97cw4fk3ravtDWTuE/OEz1BcnLGpzA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692256220; x=1723792220; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JjzPYPUuROIA08YPCfDWkzc6f7ow2v3WRVW39hUB6/A=; b=SZ6oeVXPhc7JCQMgsmsZ7Sfa1GN1v9qVhw5hczAbtvjWpGGAS/bL9OqE DVChFS/xR5GSvyJKwoPj8uTaxsp0HuD9X9761mZj/e8qvv6glR3Z4jFKk k6X6FBu//3z3lD+XasBv/N6YmmYPJadGJfQVL5nXv455+4qP8qVV9C26F JrzUYjq1Yo3uqGLD4YNjAzoyDcadxMRhMdIBe65zxE+OWIgzOteGBcS/c JD1VLSVN9RUmlLToY5ryMRm/jodfm5rnZ+vP5zhA0Xrm7HBWEWtcr6sPr 0PNg7568d8BK8quLH3QuqsMFT0vRuJ8PPBNK0H3HxQosBISnX7jZFZ5Ii g==; X-IronPort-AV: E=McAfee;i="6600,9927,10803"; a="370200883" X-IronPort-AV: E=Sophos;i="6.01,179,1684825200"; d="scan'208";a="370200883" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Aug 2023 00:10:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10803"; a="1065142182" X-IronPort-AV: E=Sophos;i="6.01,179,1684825200"; d="scan'208";a="1065142182" Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Aug 2023 00:10:18 -0700 From: Vivek Kasireddy To: dri-devel@lists.freedesktop.org, linux-mm@kvack.org Cc: Vivek Kasireddy , David Hildenbrand , Daniel Vetter , Mike Kravetz , Hugh Dickins , Peter Xu , Jason Gunthorpe , Gerd Hoffmann , Dongwon Kim , Junxiao Chang Subject: [PATCH v1 1/3] mm/gup: Export check_and_migrate_movable_pages() Date: Wed, 16 Aug 2023 23:49:32 -0700 Message-Id: <20230817064934.3424431-2-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230817064934.3424431-1-vivek.kasireddy@intel.com> References: <20230817064934.3424431-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4C9A41C0022 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: ysnbrkbqxgaofryuihsp6mfnqxp5d3e4 X-HE-Tag: 1692256220-532632 X-HE-Meta: U2Fs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ISwUDbgiL2bAI58asvs97W40lwxDZrK/BgGOHddfCTyLAp94BDM4vNzaNk5JrUjeF/6qyfFmV0hjlD0D3uUvPUDjc+8LGW6i8FrN9EHz/05tB4kcMknDZkmCNUGCg94vsE2P6dUGqdv8AoWiY64Gwmzcuc4soM11UTN11Gn56xzXC3EM7iD1lgr2wfBQrhi1iDLgDjkuSdErRYUc= 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: For drivers that would like to migrate pages out of the movable zone (or CMA) in order to pin them (longterm) for DMA, using check_and_migrate_movable_pages() directly provides a convenient option instead of duplicating similar checks (e.g, checking the folios for zone, hugetlb, etc) and calling migrate_pages() directly. Ideally, a driver is expected to call pin_user_pages(FOLL_LONGTERM) to migrate and pin the pages for longterm DMA but there are situations where the GUP APIs cannot be used directly for various reasons (e.g, when the VMA or start addr cannot be easily determined but the relevant pages are available). Cc: David Hildenbrand Cc: Daniel Vetter Cc: Mike Kravetz Cc: Hugh Dickins Cc: Peter Xu Cc: Jason Gunthorpe Cc: Gerd Hoffmann Cc: Dongwon Kim Cc: Junxiao Chang Signed-off-by: Vivek Kasireddy --- include/linux/mm.h | 2 ++ mm/gup.c | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 406ab9ea818f..81871ffd3ff9 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1547,6 +1547,8 @@ void unpin_user_pages_dirty_lock(struct page **pages, unsigned long npages, void unpin_user_page_range_dirty_lock(struct page *page, unsigned long npages, bool make_dirty); void unpin_user_pages(struct page **pages, unsigned long npages); +long check_and_migrate_movable_pages(unsigned long nr_pages, + struct page **pages); static inline bool is_cow_mapping(vm_flags_t flags) { diff --git a/mm/gup.c b/mm/gup.c index 76d222ccc3ff..18beda89fcf3 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2141,8 +2141,8 @@ static int migrate_longterm_unpinnable_pages( * If everything is OK and all pages in the range are allowed to be pinned, then * this routine leaves all pages pinned and returns zero for success. */ -static long check_and_migrate_movable_pages(unsigned long nr_pages, - struct page **pages) +long check_and_migrate_movable_pages(unsigned long nr_pages, + struct page **pages) { unsigned long collected; LIST_HEAD(movable_page_list); @@ -2156,12 +2156,13 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages, pages); } #else -static long check_and_migrate_movable_pages(unsigned long nr_pages, - struct page **pages) +long check_and_migrate_movable_pages(unsigned long nr_pages, + struct page **pages) { return 0; } #endif /* CONFIG_MIGRATION */ +EXPORT_SYMBOL(check_and_migrate_movable_pages); /* * __gup_longterm_locked() is a wrapper for __get_user_pages_locked which