From patchwork Mon Nov 6 06:15:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13446260 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 7F32DC4167D for ; Mon, 6 Nov 2023 06:17:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1580B6B01A2; Mon, 6 Nov 2023 01:17:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 108706B01A3; Mon, 6 Nov 2023 01:17:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F11A96B01A4; Mon, 6 Nov 2023 01:17:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id DEFAB6B01A2 for ; Mon, 6 Nov 2023 01:17:40 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B1BE640657 for ; Mon, 6 Nov 2023 06:17:40 +0000 (UTC) X-FDA: 81426523080.13.26F2234 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by imf27.hostedemail.com (Postfix) with ESMTP id 5F71C40002 for ; Mon, 6 Nov 2023 06:17:37 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Th2aFzVP; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf27.hostedemail.com: domain of vivek.kasireddy@intel.com designates 134.134.136.65 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=1699251458; 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=VHK8f89ze78G4VDA21g27Sd3N+mKqs6dF5vvGDY55Qk=; b=vCHmwVbxPXj71O9/BQBJX893vV4ccRolCY4SmMdhDi3Y6DUIE35VbvWNWNbg72E2w0nmgW LDN9chAizp+XeNpMQ4WOgHoA67I/LCcBDsyKEitUrbepFhK9EeLrs2YFA1P/vE/DSl0ziH C5soxqCfLwqNEiIe10kY1EolUTCYdlY= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Th2aFzVP; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf27.hostedemail.com: domain of vivek.kasireddy@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=vivek.kasireddy@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699251458; a=rsa-sha256; cv=none; b=Vp5ZSPmlfIbXcptdB2xeaIWn1qikD9ncFt7KKolPZQDzOnLxm5DbAwrflBr7SGfyBGXNKD toCm6ExRIfsxsgA5s3QOBIkF9dgrryX1x9nEG673qeYY59yFGCnm+M8ZDv4uHOwzIKyusg pASnFeJD68YInH0KQLyNnguhOjgJgB8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699251457; x=1730787457; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LRgtqEGhnRjdv65luGGLdEpI5+g8BPuw2uD/fg3QljU=; b=Th2aFzVPpya3gMIH2dGCcQXk0yN2LifyQNvihMRvsuMWbvDv6+XwRy5C HNwbcC3CNX504Dm7F0V3gHlk4nNbuTGSrBblx+y8oCzhTEViqCcMf31NW 2IwFVBH+XZs46hQKgz9HEuzd0u8/+aO6mWGqlXT7APHjpad26E5lR9MnH KNCD1kC/UlorDUd4+gWs51whNBfpLY6a3amyx9IjJMYOR07UXzyoBW6JW GLL8K6En62Kls0Or5WPHef4dsyYbza92lB/vHqWhcVONbzr1tJkwtXP0V k0ow/bNlPMvLPZnS5HxVTgLMBKUbtPNR8SfameE63cepM8K48ixmANb65 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10885"; a="393113914" X-IronPort-AV: E=Sophos;i="6.03,280,1694761200"; d="scan'208";a="393113914" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Nov 2023 22:17:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10885"; a="797213047" X-IronPort-AV: E=Sophos;i="6.03,280,1694761200"; d="scan'208";a="797213047" Received: from vkasired-desk2.fm.intel.com ([10.105.128.7]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Nov 2023 22:17:35 -0800 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 , Gerd Hoffmann , Dongwon Kim , Junxiao Chang , Jason Gunthorpe Subject: [PATCH v2 1/3] mm/gup: Introduce pin_user_pages_fd() for pinning shmem/hugetlbfs file pages (v2) Date: Sun, 5 Nov 2023 22:15:39 -0800 Message-Id: <20231106061541.507116-2-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231106061541.507116-1-vivek.kasireddy@intel.com> References: <20231106061541.507116-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 5F71C40002 X-Stat-Signature: ndsgcgz8fh9dmfaazs7h4aeaozwtqrat X-Rspam-User: X-HE-Tag: 1699251457-483287 X-HE-Meta: U2FsdGVkX19Wwso4bzQv9dI1XBje5ywUp1GOJEDxB2NYq2euw2JOs4ol5QnF5V0A5pGojGGJGd6b01qd2uQbOtyU95yro6mQo4maDpNkgHwDJInZ/Gey7qcLjaboAmSPW6PnvVrs4gAjmDk9W+iAemZxQirszWQKySq9Tud2G5pgT0Jg5VVY5PvKJzr+eR3mveXimaJ0Uj0KATLYBeYwTZhYhuMx4X/y2g4HSiegHlqThKJrsG+tFgaPuK48m70O2g7WkU9XLGRBRSZ6f2J89nPmLdxMAemtgZiMdXOZOEPOghCadCepDlAJMNRUgs+uqNMUXDtxTUrL1nrFEU8j6NZDhQZPNk/wvR4ZhdPXngYESp52jpCBbvSm7WAsQ3L/HfDPxkUvb06Dyhw4dTuovjED9yBg8hhFE6DWifo8/33VpiQ4tx++yVCKJg5kkfNgo3NoOeoyQZJZrfAThYBeH26a74sLDOgmvgDntUt1z8lJvLqO3j/HxzqlSjROcJZEuPQZP5ZaWa9VAdcSjIRjQPiDSiE2Fd8hwWW6pvGzRA9t4JkWUrK9pGDnbwN7kGU19CI6CdlBXY9JOzWHDeKacs5enR1KHvSo9svq1JZFNB5MUbWsHCrb8tI80vLox5gg4mcEn5wGeyMkTWQiHnbwYRzmg+p1Tf/ytAICq4UZoxV55V1XEjdVcHKN926md/tLlQy839ErpeBJsOp4oc3BegMy8Xb2NyFWEVq0BTYqjnOWWH/odjEAld3TDqzH5NnGFxOho+QvYLpIhP+yqgggfmCoknf/4jn5dRCR8qKqIxUC3xF6+JOi4sFp6ldAxkuf0ilbbPs+XYtgPf6kJ6mzK/p5dpDu1HkWbpEEXMt7u4jPt876zcYiBzdyLi7MveEiKj0SPK5EQEjOTEqLPJrGDepK/STiJcX7ys3BSgeaWyDNvG7XYkcgL9fTB+m295d15Zjx4UWXC/JjGssOUxN 1eOWR7lV 1OyvgSu1nxxUJ4r80/XUG/BhvHN4JWTi8AeeI6EN4e+8knJzp8KJ6gJNf7F0UdJ9PwGn6a1+Xxv4gbq7CmFK9d2EZLwIrTaGu655Kfxn3eqacc9JlnWZ2usPU6vVeFq0Q+7SkKJelbL6SC3AwT2FsjY6pT/RWS7iKlm/pImlLeJgG0zO056050Ikc2JZHARhiaktco+EnlwNivHdCHFt9G3A4395ktw9wMWjHa4i7S0JJ78nzYndByP6h4czuphrLOHebA0Qqiqs8l94gT3L+EJlzv4qPLMZpzYIeNzLD2civgrI= 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: List-Subscribe: List-Unsubscribe: For drivers that would like to longterm-pin the pages associated with a file, the pin_user_pages_fd() API provides an option to not only pin the pages via FOLL_PIN but also to check and migrate them if they reside in movable zone or CMA block. This API currently works with files that belong to either shmem or hugetlbfs. Files belonging to other filesystems are rejected for now. The pages need to be located first before pinning them via FOLL_PIN. If they are found in the page cache, they can be immediately pinned. Otherwise, they need to be allocated using the filesystem specific APIs and then pinned. v2: - Drop gup_flags and improve comments and commit message (David) - Allocate a page if we cannot find in page cache for the hugetlbfs case as well (David) - Don't unpin pages if there is a migration related failure (David) - Drop the unnecessary nr_pages <= 0 check (Jason) - Have the caller of the API pass in file * instead of fd (Jason) Cc: David Hildenbrand Cc: Daniel Vetter Cc: Mike Kravetz Cc: Hugh Dickins Cc: Peter Xu Cc: Gerd Hoffmann Cc: Dongwon Kim Cc: Junxiao Chang Suggested-by: Jason Gunthorpe Signed-off-by: Vivek Kasireddy Reviewed-by: Jason Gunthorpe --- include/linux/mm.h | 2 + mm/gup.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index bf5d0b1b16f4..f6cc17b14653 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2457,6 +2457,8 @@ long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages, struct page **pages, unsigned int gup_flags); long pin_user_pages_unlocked(unsigned long start, unsigned long nr_pages, struct page **pages, unsigned int gup_flags); +long pin_user_pages_fd(struct file *file, pgoff_t start, + unsigned long nr_pages, struct page **pages); int get_user_pages_fast(unsigned long start, int nr_pages, unsigned int gup_flags, struct page **pages); diff --git a/mm/gup.c b/mm/gup.c index 2f8a2d89fde1..d30b9dfebbb6 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -3400,3 +3400,102 @@ long pin_user_pages_unlocked(unsigned long start, unsigned long nr_pages, &locked, gup_flags); } EXPORT_SYMBOL(pin_user_pages_unlocked); + +static struct page *alloc_file_page(struct file *file, pgoff_t idx) +{ + struct page *page = ERR_PTR(-ENOMEM); + struct folio *folio; + int err; + + if (shmem_file(file)) + return shmem_read_mapping_page(file->f_mapping, idx); + + folio = alloc_hugetlb_folio_nodemask(hstate_file(file), + NUMA_NO_NODE, + NULL, + GFP_USER); + if (folio && folio_try_get(folio)) { + page = &folio->page; + err = hugetlb_add_to_page_cache(folio, file->f_mapping, idx); + if (err) { + folio_put(folio); + free_huge_folio(folio); + page = ERR_PTR(err); + } + } + + return page; +} + +/** + * pin_user_pages_fd() - pin user pages associated with a file + * @file: the file whose pages are to be pinned + * @start: starting file offset + * @nr_pages: number of pages from start to pin + * @pages: array that receives pointers to the pages pinned. + * Should be at-least nr_pages long. + * + * Attempt to pin pages associated with a file that belongs to either shmem + * or hugetlbfs. The pages are either found in the page cache or allocated + * if necessary. Once the pages are located, they are all pinned via FOLL_PIN. + * And, these pinned pages need to be released using unpin_user_pages() or + * unpin_user_page(). + * + * Returns number of pages pinned. This would be equal to the number of + * pages requested. If no pages were pinned, it returns -errno. + */ +long pin_user_pages_fd(struct file *file, pgoff_t start, + unsigned long nr_pages, struct page **pages) +{ + struct page *page; + unsigned int flags, i; + long ret; + + if (start < 0) + return -EINVAL; + + if (!file) + return -EINVAL; + + if (!shmem_file(file) && !is_file_hugepages(file)) + return -EINVAL; + + flags = memalloc_pin_save(); + do { + for (i = 0; i < nr_pages; i++) { + /* + * In most cases, we should be able to find the page + * in the page cache. If we cannot find it, we try to + * allocate one and add it to the page cache. + */ + page = find_get_page_flags(file->f_mapping, + start + i, + FGP_ACCESSED); + if (!page) { + page = alloc_file_page(file, start + i); + if (IS_ERR(page)) { + ret = PTR_ERR(page); + goto err; + } + } + ret = try_grab_page(page, FOLL_PIN); + if (unlikely(ret)) + goto err; + + pages[i] = page; + put_page(pages[i]); + } + + ret = check_and_migrate_movable_pages(nr_pages, pages); + } while (ret == -EAGAIN); + + memalloc_pin_restore(flags); + return ret ? ret : nr_pages; +err: + while (i > 0 && pages[--i]) + unpin_user_page(pages[i]); + + return ret; +} +EXPORT_SYMBOL_GPL(pin_user_pages_fd); + From patchwork Mon Nov 6 06:15:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13446262 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 972F2C4167B for ; Mon, 6 Nov 2023 06:17:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F9BE6B01A5; Mon, 6 Nov 2023 01:17:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 881656B01A6; Mon, 6 Nov 2023 01:17:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D5846B01A7; Mon, 6 Nov 2023 01:17:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 53E726B01A5 for ; Mon, 6 Nov 2023 01:17:44 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2D4671206AD for ; Mon, 6 Nov 2023 06:17:44 +0000 (UTC) X-FDA: 81426523248.11.E7599B3 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by imf20.hostedemail.com (Postfix) with ESMTP id 0FBA91C0009 for ; Mon, 6 Nov 2023 06:17:41 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=dmeRRJsZ; spf=pass (imf20.hostedemail.com: domain of vivek.kasireddy@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=vivek.kasireddy@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=1699251462; 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=Qjm7lKAZbAhJatUJ83BQp2sbDtQYxloHbUf4ynC9KgM=; b=arfiZFDBk9WAUDZ14j4DfS8XxALxirKk/IUSQ0Wp/kjRxg+uCfO8Oy5sMjjxl1DLYUfKrl aZ565c9eumeaAdvwzYJJvbRCa5OnOE3k8dpXTXX1JZCjYIF3eb+UMgnvgarteh8Hff4MMF o+AFL7EMte2H5Fj34v4r2xTsThNO8e0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699251462; a=rsa-sha256; cv=none; b=k9j/btVUhiw2Ha56Y1ZjDgZfcHG20EbTNUUS0gyj1NWRKlvIxC+igFlssP0CLEx/tPy7BV Sf1mwUQDn9d0QAJiCXzr5ePgLiWnXFyrr7sR53SrSd2iu9IJeGHHmlPWnby9M3jAYr3eMV vaq/P5GicFRKpbOsatJ14ioFjwg44+c= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=dmeRRJsZ; spf=pass (imf20.hostedemail.com: domain of vivek.kasireddy@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=vivek.kasireddy@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699251462; x=1730787462; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nVN0HkxWtfg8eXqDo7dzNjDMWcgdPswKsobFnSzYfJc=; b=dmeRRJsZjpjw+PQ7gnEqlFZqornceuBjgiVV/CUKUx8Isz8hys2Zq9Tc yIsYsUpuXgjERJ00CSnZ1N2kacUCqGgxbaJoZgyYnA/lF5NXHucVm2obd NC78cTWUIk4k3GORXBC3jFIYtw2BHleSWwXn0MFn4KJzQxicLd4mH76nJ zTEhiYYLgDFKeZ/vWff6Xsp5pNyB7kNB34kIb6Xg2Sj97630QyDd0lQtU tlhIkQRcubunpDGTB/kTBBr9yw1oyqhVQOfRYsUaAauJvRHbScwzQwiLt DhGLeP050XKphIEBn3hqMLMNA/zEoN02zyz0LI5VCmRhfaaIIzRYM7kLd Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10885"; a="393113922" X-IronPort-AV: E=Sophos;i="6.03,280,1694761200"; d="scan'208";a="393113922" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Nov 2023 22:17:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10885"; a="797213050" X-IronPort-AV: E=Sophos;i="6.03,280,1694761200"; d="scan'208";a="797213050" Received: from vkasired-desk2.fm.intel.com ([10.105.128.7]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Nov 2023 22:17:35 -0800 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 v2 2/3] udmabuf: Pin the pages using pin_user_pages_fd() API (v2) Date: Sun, 5 Nov 2023 22:15:40 -0800 Message-Id: <20231106061541.507116-3-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231106061541.507116-1-vivek.kasireddy@intel.com> References: <20231106061541.507116-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 0FBA91C0009 X-Rspam-User: X-Stat-Signature: bs79nkwasxz8dmnmfochx6wui94g8fng X-Rspamd-Server: rspam03 X-HE-Tag: 1699251461-390922 X-HE-Meta: U2FsdGVkX19ti5HoF3iIpLeraN9bvJhVC83Ab8A9xU5rBcGBUobwurvStuemTTWAgmi74bCY/YdL6APZhy6wfyUKfAfKtFXNxI39/kFzRJgC7fXUIX82nAf23MddnR6x6bnGt6TW+gF2iBGmUJhuDj9pDMTFuo0fegJr0rmGqdZknwZpxDGP5/cX67PTgWHOqmXIB4otFVH4RkY09B/55L7IJoQl2FtbdDQ9FagyGywg0fDZ1GG/NqOBNR4J/N4d4Mq7Fw5xQMf8VxUqpQHWvAQxVz2GDENyN5p2YJWvtvZB0wuBC/4MwwaHZnyz7yYHOemLxRovrF1arCseC4ShXuy/4UFeorD6aJd6F/tcDpgI6hpb/j0qwCZqEjOyKsNyCUmxXbEQ0/nyBXCmrYh/kxzzlz0iJfSVian3rjhAswiHw5XjMiwcTBf1E4ZWr+3POCIeJNBuuV+ZeSvJ3XizvXeYy47gKiGT8zkm1aS3g1AfDwHJAHwybCemIcpoU4MPt/cpRLhJLu2p4HwgqXRCWJv3ZR/izT8+PkuzEjDWKX5W9gmDdHn1twNbne16ASDxfmAW8xaHvuAlZ+JL2Hcj7h7poE5f9EF1VUpfLi6P1a6i2X/R14uDFEW6q7sxNJdjBDS6IEEe3cKAm7Mnkom9WOhnmUA56y8UjNd9zjxaIX4YFhM8iytC6Hi/fXm91MBZxB32VNS3M6UKx3ajsW4sJa61cIi131q62DJoyU1nyvN7yJC6kF9YrjQDcQ2GLOIba80Eqlwv8674BTS9tPUEO9vEHoVfDTBnhgLiXR1HTjpiwki8A7q8rnKUpYQKEUEI4qkMy8omiwnmB1+apzhnyOenK/QIhMnUnBkZeOjuuGgC3xCx5YVivhFtL6Uib5qmwu1CK9kfrIH8VT2HHEzEAvv9sa/7q+tWpz09UsUo3bpP5z0G9EZ5eGwWM5Lu7ZU4khTU697arYhguoxypwq bJCjamed GNvxyA1KujxSpbhdw3YG8KKHPygexTCFOGhpiCGqywkGzQvx9qC/WZqcxXb9xqQcI6HmdPHP5FtKekqNwTcgFnZnzr0dgkYMolkBTzOpwYZnrwh26SIAHLiDke/wLJpV4srS2hai8aD6V+mtQ/6ogD8ePrAX1sUXVOUC/T7Hr4E6X0N2reMN8n/GBA9q2kWBWXN+Dbg/H9Ou7iFK1MMzi+cDMLNLzmjXWLftGdPwVElBxCrTuUNCpitT8K++l1uS9rQzGECzV4O6WyF3ae/WrIy3IywcBw4KVUYWdLF2pE3EbjdY= 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: List-Subscribe: List-Unsubscribe: Using pin_user_pages_fd() will ensure that the pages are pinned correctly using FOLL_PIN. And, this also ensures that we don't accidentally break features such as memory hotunplug as it would not allow pinning pages in the movable zone. This patch also adds back support for mapping hugetlbfs pages by noting the subpage offsets within the huge pages and uses this information while populating the scatterlist. v2: - Adjust to the change in signature of pin_user_pages_fd() by passing in file * instead of fd. 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 --- drivers/dma-buf/udmabuf.c | 81 +++++++++++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 21 deletions(-) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 820c993c8659..aa47af2b547f 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,7 @@ struct udmabuf { struct page **pages; struct sg_table *sg; struct miscdevice *device; + pgoff_t *subpgoff; }; static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf) @@ -90,23 +92,31 @@ static struct sg_table *get_sg_table(struct device *dev, struct dma_buf *buf, { struct udmabuf *ubuf = buf->priv; struct sg_table *sg; + struct scatterlist *sgl; + pgoff_t offset; + unsigned long i = 0; int ret; sg = kzalloc(sizeof(*sg), GFP_KERNEL); if (!sg) return ERR_PTR(-ENOMEM); - ret = sg_alloc_table_from_pages(sg, ubuf->pages, ubuf->pagecount, - 0, ubuf->pagecount << PAGE_SHIFT, - GFP_KERNEL); + + ret = sg_alloc_table(sg, ubuf->pagecount, GFP_KERNEL); if (ret < 0) - goto err; + goto err_alloc; + + for_each_sg(sg->sgl, sgl, ubuf->pagecount, i) { + offset = ubuf->subpgoff ? ubuf->subpgoff[i] : 0; + sg_set_page(sgl, ubuf->pages[i], PAGE_SIZE, offset); + } ret = dma_map_sgtable(dev, sg, direction, 0); if (ret < 0) - goto err; + goto err_map; return sg; -err: +err_map: sg_free_table(sg); +err_alloc: kfree(sg); return ERR_PTR(ret); } @@ -142,7 +152,9 @@ static void release_udmabuf(struct dma_buf *buf) put_sg_table(dev, ubuf->sg, DMA_BIDIRECTIONAL); for (pg = 0; pg < ubuf->pagecount; pg++) - put_page(ubuf->pages[pg]); + unpin_user_page(ubuf->pages[pg]); + + kfree(ubuf->subpgoff); kfree(ubuf->pages); kfree(ubuf); } @@ -202,12 +214,13 @@ static long udmabuf_create(struct miscdevice *device, { DEFINE_DMA_BUF_EXPORT_INFO(exp_info); struct file *memfd = NULL; - struct address_space *mapping = NULL; struct udmabuf *ubuf; struct dma_buf *buf; - pgoff_t pgoff, pgcnt, pgidx, pgbuf = 0, pglimit; - struct page *page; - int seals, ret = -EINVAL; + pgoff_t pgoff, pgcnt, pgbuf = 0, pglimit, nr_pages; + pgoff_t subpgoff, maxsubpgs; + struct hstate *hpstate; + long ret = -EINVAL; + int seals; u32 i, flags; ubuf = kzalloc(sizeof(*ubuf), GFP_KERNEL); @@ -241,8 +254,7 @@ static long udmabuf_create(struct miscdevice *device, memfd = fget(list[i].memfd); if (!memfd) goto err; - mapping = memfd->f_mapping; - if (!shmem_mapping(mapping)) + if (!shmem_file(memfd) && !is_file_hugepages(memfd)) goto err; seals = memfd_fcntl(memfd, F_GET_SEALS, 0); if (seals == -EINVAL) @@ -253,14 +265,40 @@ static long udmabuf_create(struct miscdevice *device, goto err; pgoff = list[i].offset >> PAGE_SHIFT; pgcnt = list[i].size >> PAGE_SHIFT; - for (pgidx = 0; pgidx < pgcnt; pgidx++) { - page = shmem_read_mapping_page(mapping, pgoff + pgidx); - if (IS_ERR(page)) { - ret = PTR_ERR(page); + if (is_file_hugepages(memfd)) { + if (!ubuf->subpgoff) { + ubuf->subpgoff = kmalloc_array(ubuf->pagecount, + sizeof(*ubuf->subpgoff), + GFP_KERNEL); + if (!ubuf->subpgoff) { + ret = -ENOMEM; + goto err; + } + } + hpstate = hstate_file(memfd); + pgoff = list[i].offset >> huge_page_shift(hpstate); + subpgoff = (list[i].offset & + ~huge_page_mask(hpstate)) >> PAGE_SHIFT; + maxsubpgs = huge_page_size(hpstate) >> PAGE_SHIFT; + } + + do { + nr_pages = shmem_file(memfd) ? pgcnt : 1; + ret = pin_user_pages_fd(memfd, pgoff, nr_pages, + ubuf->pages + pgbuf); + if (ret < 0) goto err; + + if (is_file_hugepages(memfd)) { + ubuf->subpgoff[pgbuf] = subpgoff << PAGE_SHIFT; + if (++subpgoff == maxsubpgs) { + subpgoff = 0; + pgoff++; + } } - ubuf->pages[pgbuf++] = page; - } + pgbuf += nr_pages; + pgcnt -= nr_pages; + } while (pgcnt > 0); fput(memfd); memfd = NULL; } @@ -283,10 +321,11 @@ static long udmabuf_create(struct miscdevice *device, return dma_buf_fd(buf, flags); err: - while (pgbuf > 0) - put_page(ubuf->pages[--pgbuf]); + while (pgbuf > 0 && ubuf->pages[--pgbuf]) + unpin_user_page(ubuf->pages[pgbuf]); if (memfd) fput(memfd); + kfree(ubuf->subpgoff); kfree(ubuf->pages); kfree(ubuf); return ret; From patchwork Mon Nov 6 06:15:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13446263 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 B43DBC0018A for ; Mon, 6 Nov 2023 06:17:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A58DF6B01A6; Mon, 6 Nov 2023 01:17:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A09166B01A7; Mon, 6 Nov 2023 01:17:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 884726B01A8; Mon, 6 Nov 2023 01:17:46 -0500 (EST) 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 71C476B01A6 for ; Mon, 6 Nov 2023 01:17:46 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 43DCC1406B8 for ; Mon, 6 Nov 2023 06:17:46 +0000 (UTC) X-FDA: 81426523332.05.512F41E Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by imf27.hostedemail.com (Postfix) with ESMTP id 3B11B40002 for ; Mon, 6 Nov 2023 06:17:43 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=FmMuz8ca; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf27.hostedemail.com: domain of vivek.kasireddy@intel.com designates 134.134.136.65 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=1699251463; 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=h3emmYlObQz4YBWvxea89j9SxvY/uMNOIgA3BV8wvNU=; b=t7XCHTKDxDZBQu1srZ9ScNix4bghy7IPg+e2yrJzt29opJjsFgLwMn99kzc8DZAQ2lLlNo JXuu2o6TFrSUTUxVakxDSKOKFa/YPxwbzaaIKsGYn4iDBb8S7RHChZrpJEjBSgiroW7LC6 S+jJTb5uUTb+GHaJPNV/lyvxWzBIaiQ= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=FmMuz8ca; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf27.hostedemail.com: domain of vivek.kasireddy@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=vivek.kasireddy@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699251463; a=rsa-sha256; cv=none; b=zaCJ6ky+jVlrskj297l7errgDIeS0gDD6Q0hmXntQoIu4Z9jlHqPJ2/va4PV5kRoknvdE7 zkzFOL7g7OvW8CFD+0m18Fog31GY+26yT1bg7QZmbozh+GSuMA7RTBCDb9lTVorjqeRUX9 /stSDpDA6T4n1Ik3TgpqTWxPd++u4tU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699251463; x=1730787463; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=r39C9fURv/tYjjTgfRvVfOiacLkGBXJF65fG2x4l+b0=; b=FmMuz8cajKqnd2LBciNWZxpwZmkriwt/VQVFrIUdK/6ebV4IF57749Ic KUZdWCkotjyQt9xQ3JTEhUGTMP0atxozvMWxN/qFPbaWiZVxO2kFO2DU3 7SQG0TWdD2drIVB9ZnXWJEM8CxPXgMUrASdKRn+EmkqaR8I8tXEVUDmK4 C/RdFvzy3qitxyPocT9wLH+ns+ptVD8CM8Gd7JKufZPZxmalXhO/fxHr6 nEDwVTyomGYYeeqgVj7oOSLXyV+Gfor5CM4cWD0dbscG0Hr8s6EbKPegm oOqhGwHiW2t+K0b2xMTynSQYJNsL9+Z2fEry+6+C0HvQFS/74r/LbWVCK w==; X-IronPort-AV: E=McAfee;i="6600,9927,10885"; a="393113930" X-IronPort-AV: E=Sophos;i="6.03,280,1694761200"; d="scan'208";a="393113930" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Nov 2023 22:17:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10885"; a="797213053" X-IronPort-AV: E=Sophos;i="6.03,280,1694761200"; d="scan'208";a="797213053" Received: from vkasired-desk2.fm.intel.com ([10.105.128.7]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Nov 2023 22:17:35 -0800 From: Vivek Kasireddy To: dri-devel@lists.freedesktop.org, linux-mm@kvack.org Cc: Vivek Kasireddy , Shuah Khan , David Hildenbrand , Daniel Vetter , Mike Kravetz , Hugh Dickins , Peter Xu , Jason Gunthorpe , Gerd Hoffmann , Dongwon Kim , Junxiao Chang Subject: [PATCH v2 3/3] selftests/dma-buf/udmabuf: Add tests to verify data after page migration Date: Sun, 5 Nov 2023 22:15:41 -0800 Message-Id: <20231106061541.507116-4-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231106061541.507116-1-vivek.kasireddy@intel.com> References: <20231106061541.507116-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 3B11B40002 X-Stat-Signature: grbykwgdtt4chujuhu8dxsctstcefi4s X-Rspam-User: X-HE-Tag: 1699251463-423879 X-HE-Meta: U2FsdGVkX1/wCJe996UUXEYhjLbMzf3qqLPSDdabQEdaOuY7Zxs5MOEikKC2DsAcO7hcdn+GKLN+jghPeNuXFdoRSbtJjPzV2CeOiCIGrL+kPGoxzpw9ydTFMdRHWidy4z0WMPUXMdB37m8gzQJPLY/IMdXL8zmjPSJTCU2Yc+M4pKR8C2neJsVJ9u/IQD233/NRdHcsBTpbepaVLj11jMWbEOApjS2QKoXja/bRgV3Gaw0wF63sqQZ614Q9nhm0Nj89bhuNwSvotFvPJLQB/0b7FY8Xqqm2ppOm5c1mLVLDFYRSSmJDMEndKa8JC89fUr2uVYQ8+KeYj/yt5nIfTjwimuZYL5ZcQXP/CONVVZRl0De5DxgjLFnuvV2OzLxZq19cQ9ILV95rjNvsr+pSTaoXu5XAb9AJz5LAnJ0ajiE/3BbpfoH08yZ4fFhsbKmRuSSytreVi81W9FpwysxxuPaCOZeKrXT576AWIS/YyEW0paHg3zAMSECP/MY7Z5RTGk3EFl9yoY7d6Yhdll4f29pZ2l5vYbNI8yvVCVvg8ti+vlu6S9DP87WEo4cJ9syA+Ma9CU3xup+HL6KNvLdsl6sZ8G944WI+d9DtbK1F5CUcW396CVHL3jEsfBep5gK/qVt28ocXgU8Lqx4kxKAmHTBKhr3bmgxsxyCcCifM5VvQbvBf7gpMiM+nLwHQzE0IbeZn+016zUGQd9Lp4rMWWFN2iHMbSbYNEopn3jEHj5zskf7q4m566IJOOtunkCmkDeHFPresxEUVL67oFUTPD4FRZEDZ9sQLYjh+zws0coKnjRFtKbw+te2uTDSpj0/gJb6xDIo49khJCvO0XhvS/adpHBq2IUKjj9qEQwVfZbVJG3De8GwaClYQFhFbTedOCRpZhv7KNVZGoySwJyoFommzamXyg8eG7zowjBjlKjUnvir7SNbstSiugfbUegXF5ECpffVYWJ2TDFC6NCY x5X4rmRu LWafVHQeva1h6MZ+rTzZKe3jMnJaGW/Hy7QlIEpd5CLKjowSHGAJ94JmVjwGnUuzfhMnhiOq/67750noRKzIcqgJyZ/0wDlGp/4BmDb+viiWGPC/7TeVq3ZTrqMUJLydjNMK0rw2DEP7Fv2Ru34ajvIkN5aAia10J0/D1O5R779YtnT7b+xTFEe1a640qx3nL0DDKJ9xOf/JUxdZT39LDubr4Rln/LyzfNWzjbV6aw6G/lb4YFfTI5TwkhmIV756kxBKEovGRqWvVy9fY2w5VQ1cUnB3Dq+CxxNNzNdFfB6EHM4PJky4UJ9cjjY8BZSFjMGYO 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: List-Subscribe: List-Unsubscribe: Since the memfd pages associated with a udmabuf may be migrated as part of udmabuf create, we need to verify the data coherency after successful migration. The new tests added in this patch try to do just that using 4k sized pages and also 2 MB sized huge pages for the memfd. Successful completion of the tests would mean that there is no disconnect between the memfd pages and the ones associated with a udmabuf. And, these tests can also be augmented in the future to test newer udmabuf features (such as handling memfd hole punch). Cc: Shuah Khan 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 Based-on-patch-by: Mike Kravetz Signed-off-by: Vivek Kasireddy --- .../selftests/drivers/dma-buf/udmabuf.c | 151 +++++++++++++++++- 1 file changed, 147 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/drivers/dma-buf/udmabuf.c b/tools/testing/selftests/drivers/dma-buf/udmabuf.c index c812080e304e..d76c813fe652 100644 --- a/tools/testing/selftests/drivers/dma-buf/udmabuf.c +++ b/tools/testing/selftests/drivers/dma-buf/udmabuf.c @@ -9,26 +9,132 @@ #include #include #include +#include #include #include +#include #include #include #define TEST_PREFIX "drivers/dma-buf/udmabuf" #define NUM_PAGES 4 +#define NUM_ENTRIES 4 +#define MEMFD_SIZE 1024 /* in pages */ -static int memfd_create(const char *name, unsigned int flags) +static unsigned int page_size; + +static int create_memfd_with_seals(off64_t size, bool hpage) +{ + int memfd, ret; + unsigned int flags = MFD_ALLOW_SEALING; + + if (hpage) + flags |= MFD_HUGETLB; + + memfd = memfd_create("udmabuf-test", flags); + if (memfd < 0) { + printf("%s: [skip,no-memfd]\n", TEST_PREFIX); + exit(77); + } + + ret = fcntl(memfd, F_ADD_SEALS, F_SEAL_SHRINK); + if (ret < 0) { + printf("%s: [skip,fcntl-add-seals]\n", TEST_PREFIX); + exit(77); + } + + ret = ftruncate(memfd, size); + if (ret == -1) { + printf("%s: [FAIL,memfd-truncate]\n", TEST_PREFIX); + exit(1); + } + + return memfd; +} + +static int create_udmabuf_list(int devfd, int memfd, off64_t memfd_size) +{ + struct udmabuf_create_list *list; + int ubuf_fd, i; + + list = malloc(sizeof(struct udmabuf_create_list) + + sizeof(struct udmabuf_create_item) * NUM_ENTRIES); + if (!list) { + printf("%s: [FAIL, udmabuf-malloc]\n", TEST_PREFIX); + exit(1); + } + + for (i = 0; i < NUM_ENTRIES; i++) { + list->list[i].memfd = memfd; + list->list[i].offset = i * (memfd_size / NUM_ENTRIES); + list->list[i].size = getpagesize() * NUM_PAGES; + } + + list->count = NUM_ENTRIES; + list->flags = UDMABUF_FLAGS_CLOEXEC; + ubuf_fd = ioctl(devfd, UDMABUF_CREATE_LIST, list); + free(list); + if (ubuf_fd < 0) { + printf("%s: [FAIL, udmabuf-create]\n", TEST_PREFIX); + exit(1); + } + + return ubuf_fd; +} + +static void write_to_memfd(void *addr, off64_t size, char chr) +{ + int i; + + for (i = 0; i < size / page_size; i++) { + *((char *)addr + (i * page_size)) = chr; + } +} + +static void *mmap_fd(int fd, off64_t size) { - return syscall(__NR_memfd_create, name, flags); + void *addr; + + addr = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); + if (addr == MAP_FAILED) { + printf("%s: ubuf_fd mmap fail\n", TEST_PREFIX); + exit(1); + } + + return addr; +} + +static int compare_chunks(void *addr1, void *addr2, off64_t memfd_size) +{ + off64_t off; + int i = 0, j, k = 0, ret = 0; + char char1, char2; + + while (i < NUM_ENTRIES) { + off = i * (memfd_size / NUM_ENTRIES); + for (j = 0; j < NUM_PAGES; j++, k++) { + char1 = *((char *)addr1 + off + (j * getpagesize())); + char2 = *((char *)addr2 + (k * getpagesize())); + if (char1 != char2) { + ret = -1; + goto err; + } + } + i++; + } +err: + munmap(addr1, memfd_size); + munmap(addr2, NUM_ENTRIES * NUM_PAGES * getpagesize()); + return ret; } int main(int argc, char *argv[]) { struct udmabuf_create create; int devfd, memfd, buf, ret; - off_t size; - void *mem; + off64_t size; + void *addr1, *addr2; devfd = open("/dev/udmabuf", O_RDWR); if (devfd < 0) { @@ -90,6 +196,9 @@ int main(int argc, char *argv[]) } /* should work */ + page_size = getpagesize(); + addr1 = mmap_fd(memfd, size); + write_to_memfd(addr1, size, 'a'); create.memfd = memfd; create.offset = 0; create.size = size; @@ -98,6 +207,40 @@ int main(int argc, char *argv[]) printf("%s: [FAIL,test-4]\n", TEST_PREFIX); exit(1); } + munmap(addr1, size); + close(buf); + close(memfd); + + /* should work (migration of 4k size pages)*/ + size = MEMFD_SIZE * page_size; + memfd = create_memfd_with_seals(size, false); + addr1 = mmap_fd(memfd, size); + write_to_memfd(addr1, size, 'a'); + buf = create_udmabuf_list(devfd, memfd, size); + addr2 = mmap_fd(buf, NUM_PAGES * NUM_ENTRIES * getpagesize()); + write_to_memfd(addr1, size, 'b'); + ret = compare_chunks(addr1, addr2, size); + if (ret < 0) { + printf("%s: [FAIL,test-5]\n", TEST_PREFIX); + exit(1); + } + close(buf); + close(memfd); + + /* should work (migration of 2MB size huge pages)*/ + page_size = getpagesize() * 512; /* 2 MB */ + size = MEMFD_SIZE * page_size; + memfd = create_memfd_with_seals(size, true); + addr1 = mmap_fd(memfd, size); + write_to_memfd(addr1, size, 'a'); + buf = create_udmabuf_list(devfd, memfd, size); + addr2 = mmap_fd(buf, NUM_PAGES * NUM_ENTRIES * getpagesize()); + write_to_memfd(addr1, size, 'b'); + ret = compare_chunks(addr1, addr2, size); + if (ret < 0) { + printf("%s: [FAIL,test-6]\n", TEST_PREFIX); + exit(1); + } fprintf(stderr, "%s: ok\n", TEST_PREFIX); close(buf);