Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4473518ioa; Wed, 27 Apr 2022 04:46:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6PJ5ijTGl6VxQH3Gjglx7oqKscF1IROKH8XHansYbbGfrDrKsTy3uIEUes10sJBNSee5T X-Received: by 2002:a62:b60f:0:b0:508:2a61:2c8b with SMTP id j15-20020a62b60f000000b005082a612c8bmr29632977pff.2.1651060002765; Wed, 27 Apr 2022 04:46:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651060002; cv=none; d=google.com; s=arc-20160816; b=FzM+tlv5S4QS9ssm1qAitpPs8TNFJQpdS7vsmcaMS4SVFr3f68+jV7lx6LVXb5Pj1h K03jD2nQDTyFUUqInqrCzVuatiteEUpEdq7qn7xwDn96gFg1qMmL1S6q8WMFXGN08yUA 9cDtIDTbZ2uN2mZ3pqmgQ3WkT4VNcmE5d9vGJsDU0HRzM+Dx0H1c9+tR96ID13W4b2/a RdDIUG+T1qTWOuMN1RUnv2vA3TZZvzqNCkNbZHJZS2WE2ksPDZXSkJpfr793mwXHB8O5 o7JEthD/IU7SxeGkKYsZjpIqvOoRiiDLfFAqqCjh2Zh7FyFlaCSYlJxoLubUakSKL6Jj 2Qiw== 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:organization:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=ariuO0ZOJLXWYOhgSTIf0bo/JsxAICVAPChBbY6Fhbk=; b=w9jsWqUlrzoid0iT2AxEOanAB1jyGCGhI2HBTJJsEimjIQBdOuxDk6W2QO1IMktKTS UVjkfGEyJAgYpsHDJI7Gu2LkGPqWFiEdCsmS/31l0yA4ej4q26X/U4L2h9sCBif9x/BF fLyxdtx4WfpG9ooaeFphtR5yjjCdTXuSr/DthbTW0VTZuDt8SS0s4Hfg5cbbGNHjVe1T jG8peuFrResSHfyvmZmfOZRlSqTao7HCZdy6ZQiTBt+7HzPzjkRrggaJoPEJb4btbW38 NarcBYWUx/V3rb7DUkwNp4aLIEfxl+1uF6IllVlotVSdxMwnehU/RoFb5at6kzS7XnaJ om9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=foSTcApJ; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id rj14-20020a17090b3e8e00b001c6a62efe0dsi1631115pjb.89.2022.04.27.04.46.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 04:46:42 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=foSTcApJ; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8C6CC3D4A0; Wed, 27 Apr 2022 04:07:21 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232678AbiD0LIl (ORCPT + 99 others); Wed, 27 Apr 2022 07:08:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232625AbiD0LIM (ORCPT ); Wed, 27 Apr 2022 07:08:12 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10FBB3C9D7C for ; Wed, 27 Apr 2022 04:03:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651057401; x=1682593401; h=message-id:subject:from:to:cc:date:in-reply-to: references:mime-version:content-transfer-encoding; bh=4o0UHgvGu8OD3M/sb8BWbyJCu2+OXfzKJRyCZAr6T9Q=; b=foSTcApJWNbUdit51B1HDvQtePFwZSroWx5+XjhqOX4G/zXv8rHpqbwf HXAjD+NGMLyb8zzNxYj5C3C5/Ngnu2ogLW5RIVs4k5yEq1PTUa4U8NoDK C4NQsxdv6/w+rCUbf2Rp4c3HKa7O70wFTPhEExBSKtS/KBWPjNyziZGnk a1+4kCT6Bncckkz6SF8/YmknspIugSNT5kBsLrZ1hlIO+6WKwyIvMcGHA EcF2O6IffDJMDjs4H1i1T3VQw2pfuH9coJRyLMWW+D3Oo09t7mZFli01/ +X5n3YPO2CtHUwt7BuZnqBZwHUDQDnzcQ35CiONAwPkk0ny5XEoe1BzQ8 g==; X-IronPort-AV: E=McAfee;i="6400,9594,10329"; a="328827036" X-IronPort-AV: E=Sophos;i="5.90,292,1643702400"; d="scan'208";a="328827036" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2022 03:14:07 -0700 X-IronPort-AV: E=Sophos;i="5.90,292,1643702400"; d="scan'208";a="596214496" Received: from apiotrox-mobl.ger.corp.intel.com (HELO [10.249.254.91]) ([10.249.254.91]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2022 03:14:02 -0700 Message-ID: <8c4494b2b4c0d1017219d1d75f98fcbba4c6f72d.camel@linux.intel.com> Subject: Re: [PATCH v2 4/5] drm/i915: ttm backend dont provide mmap_offset for kernel buffers From: Thomas =?ISO-8859-1?Q?Hellstr=F6m?= To: Robert Beckett , dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter Cc: Matthew Auld , linux-kernel@vger.kernel.org Date: Wed, 27 Apr 2022 12:14:00 +0200 In-Reply-To: References: <20220412151838.1298956-1-bob.beckett@collabora.com> <20220412151838.1298956-5-bob.beckett@collabora.com> <07e5b1dc442e0b318ee0314f90a433216ed38dcb.camel@linux.intel.com> Organization: Intel Sweden AB, Registration Number: 556189-6027 Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.4 (3.40.4-3.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=unavailable 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 Sorry for late reply, On Thu, 2022-04-14 at 17:13 +0100, Robert Beckett wrote: > > > On 14/04/2022 15:05, Thomas Hellström wrote: > > On Tue, 2022-04-12 at 15:18 +0000, Robert Beckett wrote: > > > stolen/kernel buffers should not be mmapable by userland. > > > do not provide callbacks to facilitate this for these buffers. > > > > > > Signed-off-by: Robert Beckett > > > --- > > >   drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 32 > > > +++++++++++++++++++++-- > > > -- > > >   1 file changed, 27 insertions(+), 5 deletions(-) > > > > > > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c > > > b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c > > > index a878910a563c..b20f81836c54 100644 > > > --- a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c > > > +++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c > > > @@ -1092,8 +1092,8 @@ static void i915_ttm_unmap_virtual(struct > > > drm_i915_gem_object *obj) > > >          ttm_bo_unmap_virtual(i915_gem_to_ttm(obj)); > > >   } > > >   > > > -static const struct drm_i915_gem_object_ops i915_gem_ttm_obj_ops > > > = { > > > -       .name = "i915_gem_object_ttm", > > > +static const struct drm_i915_gem_object_ops > > > i915_gem_ttm_user_obj_ops = { > > > +       .name = "i915_gem_object_ttm_user", > > >          .flags = I915_GEM_OBJECT_IS_SHRINKABLE | > > >                   I915_GEM_OBJECT_SELF_MANAGED_SHRINK_LIST, > > >   > > > @@ -1111,6 +1111,21 @@ static const struct > > > drm_i915_gem_object_ops > > > i915_gem_ttm_obj_ops = { > > >          .mmap_ops = &vm_ops_ttm, > > >   }; > > >   > > > +static const struct drm_i915_gem_object_ops > > > i915_gem_ttm_kern_obj_ops = { > > > +       .name = "i915_gem_object_ttm_kern", > > > +       .flags = I915_GEM_OBJECT_IS_SHRINKABLE | > > > +                I915_GEM_OBJECT_SELF_MANAGED_SHRINK_LIST, > > > + > > > +       .get_pages = i915_ttm_get_pages, > > > +       .put_pages = i915_ttm_put_pages, > > > +       .truncate = i915_ttm_truncate, > > > +       .shrink = i915_ttm_shrink, > > > + > > > +       .adjust_lru = i915_ttm_adjust_lru, > > > +       .delayed_free = i915_ttm_delayed_free, > > > +       .migrate = i915_ttm_migrate, > > > +}; > > > > Do we really need two different ops here? > > > > Since if we don't have mmap ops, basically that tells GEM it should > > do > > the mmapping rather than TTM. > > > > That might of course come in handy for the shmem backend, but I > > don't > > fully follow why we need this for stolen. > > the main rationale for doing this was to avoid > drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c:can_mmap() > presuming > that is can use I915_MMAP_TYPE_FIXED > > As the original backend also did not have mmap_offset handlers for > stolen, this seemed like a reasonable design. > > If desired, we could add a special case for the testing logic, but > those > special cases have tendency to multiply. > > > > > Also for the framebuffer handed over from BIOS to fbdev, Does that > > need > > mmapping and if so, how do we handle that? > > > > I'm not sure of the usecase there. Do you know of any igt test that > tests this? I can investigate further if you do not. It would be if we the fbdev driver at startup inherits some image that bios has preloaded into stolen, and then a client tries to write into it. Not sure that this is a real use case though, or whether, in that case, that takes a separate path for user-space mappings. /Thomas > > > > > /Thomas > > > > > > > > > > > + > > >   void i915_ttm_bo_destroy(struct ttm_buffer_object *bo) > > >   { > > >          struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo); > > > @@ -1165,10 +1180,19 @@ int __i915_gem_ttm_object_init(struct > > > intel_memory_region *mem, > > >                  .no_wait_gpu = false, > > >          }; > > >          enum ttm_bo_type bo_type; > > > +       const struct drm_i915_gem_object_ops *ops; > > >          int ret; > > >   > > >          drm_gem_private_object_init(&i915->drm, &obj->base, > > > size); > > > -       i915_gem_object_init(obj, &i915_gem_ttm_obj_ops, > > > &lock_class, > > > flags); > > > + > > > +       if (flags & I915_BO_ALLOC_USER && > > > intel_region_to_ttm_type(mem) != I915_PL_STOLEN) { > > > +               bo_type = ttm_bo_type_device; > > > +               ops = &i915_gem_ttm_user_obj_ops; > > > +       } else { > > > +               bo_type = ttm_bo_type_kernel; > > > +               ops = &i915_gem_ttm_kern_obj_ops; > > > +       } > > > +       i915_gem_object_init(obj, ops, &lock_class, flags); > > >   > > >          obj->bo_offset = offset; > > >   > > > @@ -1178,8 +1202,6 @@ int __i915_gem_ttm_object_init(struct > > > intel_memory_region *mem, > > >   > > >          INIT_RADIX_TREE(&obj->ttm.get_io_page.radix, GFP_KERNEL > > > | > > > __GFP_NOWARN); > > >          mutex_init(&obj->ttm.get_io_page.lock); > > > -       bo_type = (obj->flags & I915_BO_ALLOC_USER) ? > > > ttm_bo_type_device : > > > -               ttm_bo_type_kernel; > > >   > > >          obj->base.vma_node.driver_private = > > > i915_gem_to_ttm(obj); > > >   > > > >