From: Sarah Walker <Sarah.Walker@imgtec.com>
To: "jannh@google.com" <jannh@google.com>
Cc: "tzimmermann@suse.de" <tzimmermann@suse.de>,
"afd@ti.com" <afd@ti.com>,
Donald Robson <Donald.Robson@imgtec.com>,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>,
"matthew.brost@intel.com" <matthew.brost@intel.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"luben.tuikov@amd.com" <luben.tuikov@amd.com>,
"boris.brezillon@collabora.com" <boris.brezillon@collabora.com>,
"faith.ekstrand@collabora.com" <faith.ekstrand@collabora.com>,
"dakr@redhat.com" <dakr@redhat.com>,
"mripard@kernel.org" <mripard@kernel.org>,
"hns@goldelico.com" <hns@goldelico.com>,
"christian.koenig@amd.com" <christian.koenig@amd.com>
Subject: Re: [EXTERNAL] Re: [PATCH v5 13/17] drm/imagination: Implement context creation/destruction ioctls
Date: Fri, 18 Aug 2023 11:00:04 +0000 [thread overview]
Message-ID: <8fb0a30a06e31357128b4d2248a923beff80d029.camel@imgtec.com> (raw)
In-Reply-To: <CAG48ez2xv2i_gObpRZ7v0O8x+dJpHT9a3gcvte7R9_S7bvUNgg@mail.gmail.com>
On Fri, 2023-08-18 at 00:42 +0200, Jann Horn wrote:
> *** CAUTION: This email originates from a source not known to Imagination Technologies. Think before you click a link or open an attachment ***
>
> On Wed, Aug 16, 2023 at 10:25 AM Sarah Walker <sarah.walker@imgtec.com> wrote:
> > Implement ioctls for the creation and destruction of contexts. Contexts are
> > used for job submission and each is associated with a particular job type.
> [...]
> > +/**
> > + * pvr_context_create() - Create a context.
> > + * @pvr_file: File to attach the created context to.
> > + * @args: Context creation arguments.
> > + *
> > + * Return:
> > + * * 0 on success, or
> > + * * A negative error code on failure.
> > + */
> > +int pvr_context_create(struct pvr_file *pvr_file, struct drm_pvr_ioctl_create_context_args *args)
> > +{
> > + struct pvr_device *pvr_dev = pvr_file->pvr_dev;
> > + struct pvr_context *ctx;
> > + int ctx_size;
> > + int err;
> > +
> > + /* Context creation flags are currently unused and must be zero. */
> > + if (args->flags)
> > + return -EINVAL;
> > +
> > + ctx_size = get_fw_obj_size(args->type);
> > + if (ctx_size < 0)
> > + return ctx_size;
> > +
> > + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
> > + if (!ctx)
> > + return -ENOMEM;
> > +
> > + ctx->data_size = ctx_size;
> > + ctx->type = args->type;
> > + ctx->flags = args->flags;
> > + ctx->pvr_dev = pvr_dev;
> > + kref_init(&ctx->ref_count);
> > +
> > + err = remap_priority(pvr_file, args->priority, &ctx->priority);
> > + if (err)
> > + goto err_free_ctx;
> > +
> > + ctx->vm_ctx = pvr_vm_context_lookup(pvr_file, args->vm_context_handle);
> > + if (IS_ERR(ctx->vm_ctx)) {
> > + err = PTR_ERR(ctx->vm_ctx);
> > + goto err_free_ctx;
> > + }
> > +
> > + ctx->data = kzalloc(ctx_size, GFP_KERNEL);
> > + if (!ctx->data) {
> > + err = -ENOMEM;
> > + goto err_put_vm;
> > + }
> > +
> > + err = init_fw_objs(ctx, args, ctx->data);
> > + if (err)
> > + goto err_free_ctx_data;
> > +
> > + err = pvr_fw_object_create(pvr_dev, ctx_size, PVR_BO_FW_FLAGS_DEVICE_UNCACHED,
> > + ctx_fw_data_init, ctx, &ctx->fw_obj);
> > + if (err)
> > + goto err_free_ctx_data;
> > +
> > + err = xa_alloc(&pvr_dev->ctx_ids, &ctx->ctx_id, ctx, xa_limit_32b, GFP_KERNEL);
> > + if (err)
> > + goto err_destroy_fw_obj;
> > +
> > + err = xa_alloc(&pvr_file->ctx_handles, &args->handle, ctx, xa_limit_32b, GFP_KERNEL);
> > + if (err)
> > + goto err_release_id;
>
> This bailout looks a bit dodgy. We have already inserted ctx into
> &pvr_dev->ctx_ids, and now we just take it out again. If someone could
> concurrently call pvr_context_lookup_id() on the ID we just allocated
> (I don't understand enough about what's going on here at a high level
> to be able to tell if that's possible), I think they would be able to
> elevate the ctx->ref_count from 1 to 2, and then on the bailout path
> we'll just free the ctx without looking at the refcount.
>
> If this can't happen, it might be a good idea to add a comment
> explaining why. If it can happen, I guess one way to fix it would be
> to replace this last bailout with a call to pvr_context_put()?
Yes, I think you're correct here. I don't think there's anything in the current
patch set that can actually trigger this, but it definitely needs fixing.
Thanks,
Sarah
>
>
> > +
> > + return 0;
> > +
> > +err_release_id:
> > + xa_erase(&pvr_dev->ctx_ids, ctx->ctx_id);
> > +
> > +err_destroy_fw_obj:
> > + pvr_fw_object_destroy(ctx->fw_obj);
> > +
> > +err_free_ctx_data:
> > + kfree(ctx->data);
> > +
> > +err_put_vm:
> > + pvr_vm_context_put(ctx->vm_ctx);
> > +
> > +err_free_ctx:
> > + kfree(ctx);
> > + return err;
> > +}
next prev parent reply other threads:[~2023-08-18 11:01 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-16 8:25 [PATCH v5 00/17] Imagination Technologies PowerVR DRM driver Sarah Walker
2023-08-16 8:25 ` [PATCH v5 01/17] sizes.h: Add entries between 32G and 64T Sarah Walker
2023-08-16 8:25 ` [PATCH v5 02/17] dt-bindings: gpu: Add Imagination Technologies PowerVR GPU Sarah Walker
2023-08-18 9:36 ` Linus Walleij
2023-08-18 10:33 ` Krzysztof Kozlowski
2023-09-05 16:32 ` Frank Binns
2023-08-18 10:32 ` Krzysztof Kozlowski
2023-08-16 8:25 ` [PATCH v5 03/17] drm/imagination/uapi: Add PowerVR driver UAPI Sarah Walker
[not found] ` <CAOFGe94OtnfKY+ZWzWOGz8kjKQhihzSOrLKrB_M=JE-i4cEMVg@mail.gmail.com>
2023-08-18 13:49 ` [EXTERNAL] " Sarah Walker
2023-08-16 8:25 ` [PATCH v5 04/17] drm/imagination: Add skeleton PowerVR driver Sarah Walker
2023-08-16 8:25 ` [PATCH v5 05/17] drm/imagination: Get GPU resources Sarah Walker
2023-08-16 8:25 ` [PATCH v5 06/17] drm/imagination: Add GPU register and FWIF headers Sarah Walker
2023-08-16 8:25 ` [PATCH v5 07/17] drm/imagination: Add GPU ID parsing and firmware loading Sarah Walker
2023-08-16 8:25 ` [PATCH v5 08/17] drm/imagination: Add GEM and VM related code Sarah Walker
2023-08-17 22:42 ` Jann Horn
2023-08-18 14:19 ` [EXTERNAL] " Sarah Walker
2023-08-18 15:30 ` Danilo Krummrich
2023-08-21 8:30 ` [EXTERNAL] " Donald Robson
2023-08-21 11:05 ` Danilo Krummrich
2023-08-18 22:59 ` Jann Horn
2023-08-16 8:25 ` [PATCH v5 09/17] drm/imagination: Implement power management Sarah Walker
2023-08-16 10:56 ` Paul Cercueil
2023-09-05 16:34 ` Frank Binns
2023-08-16 8:25 ` [PATCH v5 10/17] drm/imagination: Implement firmware infrastructure and META FW support Sarah Walker
2023-08-16 8:25 ` [PATCH v5 11/17] drm/imagination: Implement MIPS firmware processor and MMU support Sarah Walker
2023-08-16 8:25 ` [PATCH v5 12/17] drm/imagination: Implement free list and HWRT create and destroy ioctls Sarah Walker
2023-08-16 8:25 ` [PATCH v5 13/17] drm/imagination: Implement context creation/destruction ioctls Sarah Walker
2023-08-17 22:42 ` Jann Horn
2023-08-18 11:00 ` Sarah Walker [this message]
2023-08-16 8:25 ` [PATCH v5 14/17] drm/imagination: Implement job submission and scheduling Sarah Walker
2023-08-17 22:42 ` Jann Horn
2023-08-16 8:25 ` [PATCH v5 15/17] drm/imagination: Add firmware trace to debugfs Sarah Walker
2023-08-16 8:25 ` [PATCH v5 16/17] drm/imagination: Add driver documentation Sarah Walker
2023-08-16 8:25 ` [PATCH v5 17/17] arm64: dts: ti: k3-am62-main: Add GPU device node [DO NOT MERGE] Sarah Walker
2023-08-18 10:34 ` Krzysztof Kozlowski
2023-08-23 22:31 ` [PATCH v5 00/17] Imagination Technologies PowerVR DRM driver Masahiro Yamada
2023-08-24 8:08 ` Sarah Walker
2023-08-24 8:14 ` Sarah Walker
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=8fb0a30a06e31357128b4d2248a923beff80d029.camel@imgtec.com \
--to=sarah.walker@imgtec.com \
--cc=Donald.Robson@imgtec.com \
--cc=afd@ti.com \
--cc=boris.brezillon@collabora.com \
--cc=christian.koenig@amd.com \
--cc=dakr@redhat.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=faith.ekstrand@collabora.com \
--cc=hns@goldelico.com \
--cc=jannh@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luben.tuikov@amd.com \
--cc=matthew.brost@intel.com \
--cc=mripard@kernel.org \
--cc=tzimmermann@suse.de \
/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
all inboxes | Powered by JetHome®