Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2908894iog; Mon, 27 Jun 2022 05:33:39 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ts9YFUaItzAIJQ6R2WhPAUKPqHxDCfKKcPjDoJa/DtWHcmUIi19pW7bZduEN1A/c6+uBhu X-Received: by 2002:a05:6402:2711:b0:437:7404:2229 with SMTP id y17-20020a056402271100b0043774042229mr13152631edd.413.1656333219178; Mon, 27 Jun 2022 05:33:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656333219; cv=none; d=google.com; s=arc-20160816; b=hw1yyYRBptaqzL3bVsem1zXdrjaoiQhdgJQPcRmp4xg/GBsKAEW+hqqenQE99KuYar qmDlLfYB7w4v+ZxENPgAMrE31F8gmyO/o9hC/XLLPhqZ6uhfgcoZ7K/rteMgdT9HO/IQ WnuUEySF+FGclcTcXTgppZ8mVrwmtNf1h++QKfLBgzd1x3Vz8Cpx67+HpbPgJDT8ew3n sXOOLI3p6UHz2xOQUyIuN6SdczQj2uLp1fPN2oexRHo90990D9iVopiEtH3ir8PM/zqk 1dio/dYHMUwv6LbSObfn4jKihAXX/iYv+lfcrJdsBVA+eCZ46fxd3HPQFRv2eTeMbFcq OENg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=96cSGkTz/x/eUxUwijHG/ntXTGlpgjs92y56V1eiYkU=; b=KeVTAYy0J8fQvFNNSnyPxyM8lXFP8rcN+qnrKNQ+oXAJv4vUd4HulYsbyM+Nr7FWVH dVUS52zfpkAPfSZu7HT/BZq0HZ+z2J0MBysrEh95X0VyndXEj9CVD3QmejWXMDbOJ14N hpKUtWwiELYxzCPBF2IdlbmPrWkBCZfvQ/NsnDMo2sDInBOUYAvnjHkk52c0nU5SX8F8 u6/rqzR3gLowRMqvWdeZdRe8JHxfICF9o+9pfzqIvyaAulYwUU6xFR6IKoBAp3HNB5TN Crq6ZV8kDvHZUOuhA7JvGrTVdIXDyLJ6aX5DqV+1fj9ELgE+cwQcVgyZ8H8QDxcXKtiW hFeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XYKMahno; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sa39-20020a1709076d2700b00726b4ecf7b6si1875667ejc.466.2022.06.27.05.33.11; Mon, 27 Jun 2022 05:33:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XYKMahno; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238146AbiF0Lxd (ORCPT + 99 others); Mon, 27 Jun 2022 07:53:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238149AbiF0Lrw (ORCPT ); Mon, 27 Jun 2022 07:47:52 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DFE1E0F7; Mon, 27 Jun 2022 04:39:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id BF828B81123; Mon, 27 Jun 2022 11:39:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CCD8C3411D; Mon, 27 Jun 2022 11:39:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656329983; bh=nCi3D9xJWiY54ZyWgf/1NdYgSfUsPsg66ZmrbrXnbMI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XYKMahnoYmJ3QJ8QK7E/7/MPQs4vayFkE2cq1i1m/owqTJVeh510SlXsM5LwY+ECF jbswAVrf1HD6PP0WDwNZ6frmyuYRReSK4aV4QQ1az9+6hhPiVSAO1p9kKXGxnUcn85 Ds/nly8Sg3Er4T3W80HgA+hq9XLh/OAKWBjJyUNQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rob Clark , Dmitry Baryshkov , Sasha Levin Subject: [PATCH 5.18 042/181] drm/msm: Ensure mmap offset is initialized Date: Mon, 27 Jun 2022 13:20:15 +0200 Message-Id: <20220627111945.782965610@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220627111944.553492442@linuxfoundation.org> References: <20220627111944.553492442@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rob Clark [ Upstream commit 036d20726c30267724416e966c9f92db07de8081 ] If a GEM object is allocated, and then exported as a dma-buf fd which is mmap'd before or without the GEM buffer being directly mmap'd, the vma_node could be unitialized. This leads to a situation where the CPU mapping is not correctly torn down in drm_vma_node_unmap(). Fixes: e5516553999f ("drm: call drm_gem_object_funcs.mmap with fake offset") Signed-off-by: Rob Clark Reviewed-by: Dmitry Baryshkov Link: https://lore.kernel.org/r/20220531200857.136547-1-robdclark@gmail.com Signed-off-by: Sasha Levin --- drivers/gpu/drm/msm/msm_drv.c | 2 +- drivers/gpu/drm/msm/msm_drv.h | 1 + drivers/gpu/drm/msm/msm_gem_prime.c | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c index f2c46116df55..b5f6acfe7c6e 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -967,7 +967,7 @@ static const struct drm_driver msm_driver = { .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_import_sg_table = msm_gem_prime_import_sg_table, - .gem_prime_mmap = drm_gem_prime_mmap, + .gem_prime_mmap = msm_gem_prime_mmap, #ifdef CONFIG_DEBUG_FS .debugfs_init = msm_debugfs_init, #endif diff --git a/drivers/gpu/drm/msm/msm_drv.h b/drivers/gpu/drm/msm/msm_drv.h index d661debb50f1..9b985b641319 100644 --- a/drivers/gpu/drm/msm/msm_drv.h +++ b/drivers/gpu/drm/msm/msm_drv.h @@ -288,6 +288,7 @@ unsigned long msm_gem_shrinker_shrink(struct drm_device *dev, unsigned long nr_t void msm_gem_shrinker_init(struct drm_device *dev); void msm_gem_shrinker_cleanup(struct drm_device *dev); +int msm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma); struct sg_table *msm_gem_prime_get_sg_table(struct drm_gem_object *obj); int msm_gem_prime_vmap(struct drm_gem_object *obj, struct iosys_map *map); void msm_gem_prime_vunmap(struct drm_gem_object *obj, struct iosys_map *map); diff --git a/drivers/gpu/drm/msm/msm_gem_prime.c b/drivers/gpu/drm/msm/msm_gem_prime.c index 94ab705e9b8a..dcc8a573bc76 100644 --- a/drivers/gpu/drm/msm/msm_gem_prime.c +++ b/drivers/gpu/drm/msm/msm_gem_prime.c @@ -11,6 +11,21 @@ #include "msm_drv.h" #include "msm_gem.h" +int msm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma) +{ + int ret; + + /* Ensure the mmap offset is initialized. We lazily initialize it, + * so if it has not been first mmap'd directly as a GEM object, the + * mmap offset will not be already initialized. + */ + ret = drm_gem_create_mmap_offset(obj); + if (ret) + return ret; + + return drm_gem_prime_mmap(obj, vma); +} + struct sg_table *msm_gem_prime_get_sg_table(struct drm_gem_object *obj) { struct msm_gem_object *msm_obj = to_msm_bo(obj); -- 2.35.1