intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Jason Ekstrand <jason@jlekstrand.net>
To: Matthew Auld <matthew.william.auld@gmail.com>
Cc: Intel Graphics Development <intel-gfx@lists.freedesktop.org>,
	ML dri-devel <dri-devel@lists.freedesktop.org>
Subject: Re: [Intel-gfx] [PATCH 2/7] drm/i915/gem: Refactor placement setup for i915_gem_object_create*
Date: Fri, 16 Jul 2021 08:52:01 -0500	[thread overview]
Message-ID: <CAOFGe96=XqYfed3nEbm2ZG-NtXLwEGVohJ+0zWozNxzpWdtHug@mail.gmail.com> (raw)
In-Reply-To: <CAM0jSHO0Pauw157x5CRTvNitsurPUu-k_8VcVyzrJ9Q=UBY4dw@mail.gmail.com>

On Fri, Jul 16, 2021 at 6:12 AM Matthew Auld
<matthew.william.auld@gmail.com> wrote:
>
> On Thu, 15 Jul 2021 at 23:39, Jason Ekstrand <jason@jlekstrand.net> wrote:
> >
> > Since we don't allow changing the set of regions after creation, we can
> > make ext_set_placements() build up the region set directly in the
> > create_ext and assign it to the object later.  This is similar to what
> > we did for contexts with the proto-context only simpler because there's
> > no funny object shuffling.  This will be used in the next patch to allow
> > us to de-duplicate a bunch of code.  Also, since we know the maximum
> > number of regions up-front, we can use a fixed-size temporary array for
> > the regions.  This simplifies memory management a bit for this new
> > delayed approach.
> >
> > Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
>
> I think the plan was to have each extension directly hang/apply their
> state on the vanilla/proto object, or at least that was the idea
> behind: 357814f878f9 ("drm/i915: rework gem_create flow for upcoming
> extensions"). A previous version looked similar to this IIRC.

Right.  In my mind, struct create_extis that proto-obj, more-or-less.
If we wanted to codify that somehow, we could rename it
i915_gem_object_create_params and make _create_user take one instead
of separate parameters.  With only having three right now, it didn't
seem necessary to go that far.

> > ---
> >  drivers/gpu/drm/i915/gem/i915_gem_create.c | 75 +++++++++++++---------
> >  1 file changed, 45 insertions(+), 30 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_create.c b/drivers/gpu/drm/i915/gem/i915_gem_create.c
> > index 51f92e4b1a69d..391c8c4a12172 100644
> > --- a/drivers/gpu/drm/i915/gem/i915_gem_create.c
> > +++ b/drivers/gpu/drm/i915/gem/i915_gem_create.c
> > @@ -27,10 +27,13 @@ static u32 object_max_page_size(struct drm_i915_gem_object *obj)
> >         return max_page_size;
> >  }
> >
> > -static void object_set_placements(struct drm_i915_gem_object *obj,
> > -                                 struct intel_memory_region **placements,
> > -                                 unsigned int n_placements)
> > +static int object_set_placements(struct drm_i915_gem_object *obj,
> > +                                struct intel_memory_region **placements,
> > +                                unsigned int n_placements)
> >  {
> > +       struct intel_memory_region **arr;
> > +       unsigned int i;
> > +
> >         GEM_BUG_ON(!n_placements);
> >
> >         /*
> > @@ -44,9 +47,20 @@ static void object_set_placements(struct drm_i915_gem_object *obj,
> >                 obj->mm.placements = &i915->mm.regions[mr->id];
> >                 obj->mm.n_placements = 1;
> >         } else {
> > -               obj->mm.placements = placements;
> > +               arr = kmalloc_array(n_placements,
> > +                                   sizeof(struct intel_memory_region *),
> > +                                   GFP_KERNEL);
> > +               if (!arr)
> > +                       return -ENOMEM;
> > +
> > +               for (i = 0; i < n_placements; i++)
> > +                       arr[i] = placements[i];
> > +
> > +               obj->mm.placements = arr;
> >                 obj->mm.n_placements = n_placements;
> >         }
> > +
> > +       return 0;
> >  }
> >
> >  static int i915_gem_publish(struct drm_i915_gem_object *obj,
> > @@ -148,7 +162,9 @@ i915_gem_dumb_create(struct drm_file *file,
> >                 return -ENOMEM;
> >
> >         mr = intel_memory_region_by_type(to_i915(dev), mem_type);
> > -       object_set_placements(obj, &mr, 1);
> > +       ret = object_set_placements(obj, &mr, 1);
> > +       if (ret)
> > +               goto object_free;
> >
> >         ret = i915_gem_setup(obj, args->size);
> >         if (ret)
> > @@ -184,7 +200,9 @@ i915_gem_create_ioctl(struct drm_device *dev, void *data,
> >                 return -ENOMEM;
> >
> >         mr = intel_memory_region_by_type(i915, INTEL_MEMORY_SYSTEM);
> > -       object_set_placements(obj, &mr, 1);
> > +       ret = object_set_placements(obj, &mr, 1);
> > +       if (ret)
> > +               goto object_free;
> >
> >         ret = i915_gem_setup(obj, args->size);
> >         if (ret)
> > @@ -197,9 +215,12 @@ i915_gem_create_ioctl(struct drm_device *dev, void *data,
> >         return ret;
> >  }
> >
> > +#define MAX_N_PLACEMENTS = (INTEL_REGION_UNKNOWN + 1)
>
> Unused?

Yup.  Left-over from an earlier version.  Dropped.

> > +
> >  struct create_ext {
> >         struct drm_i915_private *i915;
> > -       struct drm_i915_gem_object *vanilla_object;
> > +       struct intel_memory_region *placements[INTEL_REGION_UNKNOWN];
> > +       unsigned int n_placements;
> >  };
> >
> >  static void repr_placements(char *buf, size_t size,
> > @@ -230,8 +251,7 @@ static int set_placements(struct drm_i915_gem_create_ext_memory_regions *args,
> >         struct drm_i915_private *i915 = ext_data->i915;
> >         struct drm_i915_gem_memory_class_instance __user *uregions =
> >                 u64_to_user_ptr(args->regions);
> > -       struct drm_i915_gem_object *obj = ext_data->vanilla_object;
> > -       struct intel_memory_region **placements;
> > +       struct intel_memory_region *placements[INTEL_REGION_UNKNOWN];
> >         u32 mask;
> >         int i, ret = 0;
> >
> > @@ -245,6 +265,8 @@ static int set_placements(struct drm_i915_gem_create_ext_memory_regions *args,
> >                 ret = -EINVAL;
> >         }
> >
> > +       BUILD_BUG_ON(ARRAY_SIZE(i915->mm.regions) != ARRAY_SIZE(placements));
> > +       BUILD_BUG_ON(ARRAY_SIZE(ext_data->placements) != ARRAY_SIZE(placements));
> >         if (args->num_regions > ARRAY_SIZE(i915->mm.regions)) {
> >                 drm_dbg(&i915->drm, "num_regions is too large\n");
> >                 ret = -EINVAL;
> > @@ -253,12 +275,6 @@ static int set_placements(struct drm_i915_gem_create_ext_memory_regions *args,
> >         if (ret)
> >                 return ret;
> >
> > -       placements = kmalloc_array(args->num_regions,
> > -                                  sizeof(struct intel_memory_region *),
> > -                                  GFP_KERNEL);
> > -       if (!placements)
> > -               return -ENOMEM;
> > -
> >         mask = 0;
> >         for (i = 0; i < args->num_regions; i++) {
> >                 struct drm_i915_gem_memory_class_instance region;
> > @@ -293,14 +309,13 @@ static int set_placements(struct drm_i915_gem_create_ext_memory_regions *args,
> >                 ++uregions;
> >         }
> >
> > -       if (obj->mm.placements) {
> > +       if (ext_data->n_placements) {
> >                 ret = -EINVAL;
> >                 goto out_dump;
> >         }
> >
> > -       object_set_placements(obj, placements, args->num_regions);
> > -       if (args->num_regions == 1)
> > -               kfree(placements);
> > +       for (i = 0; i < args->num_regions; i++)
> > +               ext_data->placements[i] = placements[i];
>
> kfree(placements) is still in the error unwind?

Yup.  Fixed.  Thanks!

--Jason
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2021-07-16 13:52 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-15 22:38 [Intel-gfx] [PATCH 0/7] drm/i915: Migrate memory to SMEM when imported cross-device Jason Ekstrand
2021-07-15 22:38 ` [Intel-gfx] [PATCH 1/7] drm/i915/gem: Check object_can_migrate from object_migrate Jason Ekstrand
2021-07-15 22:38 ` [Intel-gfx] [PATCH 2/7] drm/i915/gem: Refactor placement setup for i915_gem_object_create* Jason Ekstrand
2021-07-16 11:12   ` Matthew Auld
2021-07-16 13:52     ` Jason Ekstrand [this message]
2021-07-15 22:38 ` [Intel-gfx] [PATCH 3/7] drm/i915/gem: Unify user object creation Jason Ekstrand
2021-07-16 11:20   ` Matthew Auld
2021-07-16 14:02     ` Jason Ekstrand
2021-07-20  9:34   ` Matthew Auld
2021-07-20 22:04     ` Jason Ekstrand
2021-07-21  8:24       ` Matthew Auld
2021-07-21 15:47         ` Jason Ekstrand
2021-07-21 16:29           ` Matthew Auld
2021-07-15 22:38 ` [Intel-gfx] [PATCH 4/7] drm/i915/gem/ttm: Place new BOs in the requested region Jason Ekstrand
2021-07-16 13:17   ` Matthew Auld
2021-07-16 13:46     ` Jason Ekstrand
2021-08-04  6:49   ` Thomas Hellström
2021-08-04  6:52     ` Thomas Hellström
2021-07-15 22:38 ` [Intel-gfx] [PATCH 5/7] drm/i915/gem/ttm: Respect the objection region in placement_from_obj Jason Ekstrand
2021-07-16 13:54   ` Matthew Auld
2021-07-16 14:10     ` Jason Ekstrand
2021-07-16 15:52       ` Matthew Auld
2021-07-16 16:00         ` Matthew Auld
2021-07-16 17:38           ` Jason Ekstrand
2021-07-16 18:44             ` Matthew Auld
2021-07-16 19:49               ` Jason Ekstrand
2021-07-19 13:34                 ` Matthew Auld
2021-07-21 20:11                   ` Jason Ekstrand
2021-07-21 20:32                     ` Daniel Vetter
2021-07-22  9:49                     ` Matthew Auld
2021-07-22  9:59                       ` Matthew Auld
2021-08-04  8:00                         ` Thomas Hellström
2021-08-04 14:35                           ` Daniel Vetter
2021-07-15 22:38 ` [Intel-gfx] [PATCH 6/7] drm/i915/gem: Correct the locking and pin pattern for dma-buf (v6) Jason Ekstrand
2021-07-15 22:39 ` [Intel-gfx] [PATCH 7/7] drm/i915/gem: Migrate to system at dma-buf attach time (v6) Jason Ekstrand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOFGe96=XqYfed3nEbm2ZG-NtXLwEGVohJ+0zWozNxzpWdtHug@mail.gmail.com' \
    --to=jason@jlekstrand.net \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=matthew.william.auld@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).