From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 433C0C433F5 for ; Wed, 20 Oct 2021 15:46:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D4A3960FC3 for ; Wed, 20 Oct 2021 15:46:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D4A3960FC3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 56C70900002; Wed, 20 Oct 2021 11:46:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 51B8C6B0072; Wed, 20 Oct 2021 11:46:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E372900002; Wed, 20 Oct 2021 11:46:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 3081C6B0071 for ; Wed, 20 Oct 2021 11:46:00 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id E2BCE2BA83 for ; Wed, 20 Oct 2021 15:45:59 +0000 (UTC) X-FDA: 78717241638.14.0C3239A Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf26.hostedemail.com (Postfix) with ESMTP id E32F920019C8 for ; Wed, 20 Oct 2021 15:45:59 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6200,9189,10143"; a="228685312" X-IronPort-AV: E=Sophos;i="5.87,167,1631602800"; d="scan'208";a="228685312" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2021 08:40:07 -0700 X-IronPort-AV: E=Sophos;i="5.87,167,1631602800"; d="scan'208";a="718997241" Received: from bsieu-mobl1.amr.corp.intel.com (HELO ldmartin-desk2) ([10.254.14.221]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2021 08:40:06 -0700 Date: Wed, 20 Oct 2021 08:40:05 -0700 From: Lucas De Marchi To: Christoph Hellwig Cc: Andrew Morton , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Peter Zijlstra , Daniel Vetter , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Chris Wilson , linux-mm@kvack.org, matthew.auld@intel.com Subject: Re: [Intel-gfx] [PATCH 2/4] mm: add a io_mapping_map_user helper Message-ID: <20211020154005.uk6u4ovcmlhpyubk@ldmartin-desk2> References: <20210326055505.1424432-1-hch@lst.de> <20210326055505.1424432-3-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20210326055505.1424432-3-hch@lst.de> Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=intel.com (policy=none); spf=none (imf26.hostedemail.com: domain of lucas.demarchi@intel.com has no SPF policy when checking 134.134.136.24) smtp.mailfrom=lucas.demarchi@intel.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: E32F920019C8 X-Stat-Signature: cdd3hma8u9hnuj75di7wghomebdmnoxs X-HE-Tag: 1634744759-402135 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: On Fri, Mar 26, 2021 at 06:55:03AM +0100, Christoph Hellwig wrote: >Add a helper that calls remap_pfn_range for an struct io_mapping, relying >on the pgprot pre-validation done when creating the mapping instead of >doing it at runtime. > >Signed-off-by: Christoph Hellwig >--- > include/linux/io-mapping.h | 3 +++ > mm/Kconfig | 3 +++ > mm/Makefile | 1 + > mm/io-mapping.c | 29 +++++++++++++++++++++++++++++ > 4 files changed, 36 insertions(+) > create mode 100644 mm/io-mapping.c > >diff --git a/include/linux/io-mapping.h b/include/linux/io-mapping.h >index c093e81310a9b3..e9743cfd858527 100644 >--- a/include/linux/io-mapping.h >+++ b/include/linux/io-mapping.h >@@ -220,3 +220,6 @@ io_mapping_free(struct io_mapping *iomap) > } > > #endif /* _LINUX_IO_MAPPING_H */ >+ >+int io_mapping_map_user(struct io_mapping *iomap, struct vm_area_struct *vma, >+ unsigned long addr, unsigned long pfn, unsigned long size); I'm not sure what exactly brought me to check this, but while debugging I noticed this outside the header guard. But then after some more checks I saw nothing actually selects CONFIG_IO_MAPPING because commit using it was reverted in commit 0e4fe0c9f2f9 ("Revert "i915: use io_mapping_map_user"") Is this something we want to re-attempt moving to mm/ ? thanks Lucas De Marchi >diff --git a/mm/Kconfig b/mm/Kconfig >index 24c045b24b9506..6b0f2cfbfac0f3 100644 >--- a/mm/Kconfig >+++ b/mm/Kconfig >@@ -872,4 +872,7 @@ config MAPPING_DIRTY_HELPERS > config KMAP_LOCAL > bool > >+# struct io_mapping based helper. Selected by drivers that need them >+config IO_MAPPING >+ bool > endmenu >diff --git a/mm/Makefile b/mm/Makefile >index 72227b24a61688..c0135e385984bb 100644 >--- a/mm/Makefile >+++ b/mm/Makefile >@@ -120,3 +120,4 @@ obj-$(CONFIG_MEMFD_CREATE) += memfd.o > obj-$(CONFIG_MAPPING_DIRTY_HELPERS) += mapping_dirty_helpers.o > obj-$(CONFIG_PTDUMP_CORE) += ptdump.o > obj-$(CONFIG_PAGE_REPORTING) += page_reporting.o >+obj-$(CONFIG_IO_MAPPING) += io-mapping.o >diff --git a/mm/io-mapping.c b/mm/io-mapping.c >new file mode 100644 >index 00000000000000..01b3627999304e >--- /dev/null >+++ b/mm/io-mapping.c >@@ -0,0 +1,29 @@ >+// SPDX-License-Identifier: GPL-2.0-only >+ >+#include >+#include >+ >+/** >+ * io_mapping_map_user - remap an I/O mapping to userspace >+ * @iomap: the source io_mapping >+ * @vma: user vma to map to >+ * @addr: target user address to start at >+ * @pfn: physical address of kernel memory >+ * @size: size of map area >+ * >+ * Note: this is only safe if the mm semaphore is held when called. >+ */ >+int io_mapping_map_user(struct io_mapping *iomap, struct vm_area_struct *vma, >+ unsigned long addr, unsigned long pfn, unsigned long size) >+{ >+ vm_flags_t expected_flags = VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP; >+ >+ if (WARN_ON_ONCE((vma->vm_flags & expected_flags) != expected_flags)) >+ return -EINVAL; >+ >+ /* We rely on prevalidation of the io-mapping to skip track_pfn(). */ >+ return remap_pfn_range_notrack(vma, addr, pfn, size, >+ __pgprot((pgprot_val(iomap->prot) & _PAGE_CACHE_MASK) | >+ (pgprot_val(vma->vm_page_prot) & ~_PAGE_CACHE_MASK))); >+} >+EXPORT_SYMBOL_GPL(io_mapping_map_user); >-- >2.30.1 > >_______________________________________________ >Intel-gfx mailing list >Intel-gfx@lists.freedesktop.org >https://lists.freedesktop.org/mailman/listinfo/intel-gfx >