From patchwork Tue Oct 3 23:03:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 13408051 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 16A10E8FDC3 for ; Tue, 3 Oct 2023 23:04:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0329510E0AC; Tue, 3 Oct 2023 23:04:40 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5141B10E092; Tue, 3 Oct 2023 23:04:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696374277; x=1727910277; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=b/EAFviwjIkhRcjWTQN1BVxZ/F71IF9ah+TklmixhFU=; b=GC4/C4WA+jEvSacfCLAf3lBxsmFQg+R74xRNyg6T2W7qkpBd2VGHddxa BgKHO5liM9flVzALqLHS1gCu8Euh1FVWb22sq6eX7ifJ6h/7mg+DlOO4m h+qe5Muda3bxtdJZkPb4sbm2Wlum7TbMj6tktG9xD+FcRg1iwYeVIMRE2 239Oq0sX7ugG4zZL+AAbYBDgugTZ2nWVFmltxhVoPNHRiN74zSGXGFdWW gtjZs/2ZJTDE+cCMChSLizp5bvR+EKDLbJQz50hVvqVUPv8lg/WK6Sn6U t9ICzjT6hi8uWv6QremaEUBF8a81l2xryptzDojw468f7v3djBSpL2QLW A==; X-IronPort-AV: E=McAfee;i="6600,9927,10852"; a="381867103" X-IronPort-AV: E=Sophos;i="6.03,198,1694761200"; d="scan'208";a="381867103" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Oct 2023 16:04:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10852"; a="816881366" X-IronPort-AV: E=Sophos;i="6.03,198,1694761200"; d="scan'208";a="816881366" Received: from adelynhu-mobl1.gar.corp.intel.com (HELO intel.com) ([10.214.161.181]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Oct 2023 16:04:30 -0700 From: Andi Shyti To: Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= Date: Wed, 4 Oct 2023 01:03:32 +0200 Message-Id: <20231003230332.513051-1-andi.shyti@linux.intel.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH] dma-buf: Deny copy-on-writes mmaps X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx , Chris Wilson , dri-devel , linux-media@vger.kernel.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Chris Wilson Enforce that an mmap of a dmabuf is always using MAP_SHARED so that all access (both read and writes) using the device memory and not a local copy-on-write page in system memory. Signed-off-by: Chris Wilson Signed-off-by: Andi Shyti --- drivers/dma-buf/dma-buf.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 21916bba77d5..1ec297241842 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -128,6 +129,19 @@ static struct file_system_type dma_buf_fs_type = { .kill_sb = kill_anon_super, }; +static unsigned long +dma_buf_get_unmapped_area(struct file *file, + unsigned long addr, + unsigned long len, + unsigned long pgoff, + unsigned long flags) +{ + if ((flags & MAP_TYPE) == MAP_PRIVATE) + return -EINVAL; + + return current->mm->get_unmapped_area(file, addr, len, pgoff, flags); +} + static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma) { struct dma_buf *dmabuf; @@ -508,6 +522,7 @@ static void dma_buf_show_fdinfo(struct seq_file *m, struct file *file) static const struct file_operations dma_buf_fops = { .release = dma_buf_file_release, + .get_unmapped_area = dma_buf_get_unmapped_area, .mmap = dma_buf_mmap_internal, .llseek = dma_buf_llseek, .poll = dma_buf_poll,