[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <134c4a28-4331-deed-a374-75c9711168f0@kapsi.fi>
Date: Tue, 22 Feb 2022 10:37:05 +0200
From: Mikko Perttunen <cyndis@...si.fi>
To: Dmitry Osipenko <digetx@...il.com>,
Mikko Perttunen <mperttunen@...dia.com>,
thierry.reding@...il.com, jonathanh@...dia.com, joro@...tes.org,
will@...nel.org, robh+dt@...nel.org, robin.murphy@....com
Cc: linux-tegra@...r.kernel.org, dri-devel@...ts.freedesktop.org,
iommu@...ts.linux-foundation.org, linux-kernel@...r.kernel.org,
devicetree@...r.kernel.org, linux-arm-kernel@...ts.infradead.org
Subject: Re: [PATCH v3 9/9] drm/tegra: Support context isolation
On 2/21/22 22:02, Dmitry Osipenko wrote:
> 21.02.2022 15:06, Mikko Perttunen пишет:
>> On 2/19/22 20:35, Dmitry Osipenko wrote:
>>> 18.02.2022 14:39, Mikko Perttunen пишет:
>>>> + if (context->memory_context &&
>>>> context->client->ops->get_streamid_offset) {
>>> ^^^
>>>> + int offset =
>>>> context->client->ops->get_streamid_offset(context->client);
>>>> +
>>>> + if (offset >= 0) {
>>>> + job->context = context->memory_context;
>>>> + job->engine_streamid_offset = offset;
>>>> + host1x_context_get(job->context);
>>>> + }
>>>
>>> You should bump refcount unconditionally or you'll get refcnt underflow
>>> on put, when offset < 0.
>>
>> This refcount is intended to be dropped from 'release_job', where it's
>> dropped if job->context is set, which it is from this path.
>>
>>>
>>>> + }
>>>> +
>>>> /*
>>>> * job_data is now part of job reference counting, so don't
>>>> release
>>>> * it from here.
>>>> diff --git a/drivers/gpu/drm/tegra/uapi.c b/drivers/gpu/drm/tegra/uapi.c
>>>> index 9ab9179d2026..be33da54d12c 100644
>>>> --- a/drivers/gpu/drm/tegra/uapi.c
>>>> +++ b/drivers/gpu/drm/tegra/uapi.c
>>>> @@ -33,6 +33,9 @@ static void tegra_drm_channel_context_close(struct
>>>> tegra_drm_context *context)
>>>> struct tegra_drm_mapping *mapping;
>>>> unsigned long id;
>>>> + if (context->memory_context)
>>>> + host1x_context_put(context->memory_context);
>>>
>>> The "if (context->memory_context &&
>>> context->client->ops->get_streamid_offset)" above doesn't match the "if
>>> (context->memory_context)". You'll get refcount underflow.
>>
>> And this drop is for the refcount implicitly added when allocating the
>> memory context through host1x_context_alloc; so these two places should
>> be independent.
>>
>> Please elaborate if I missed something.
>
> You named context as memory_context and then have
> context=context->memory_context. Please try to improve the variable
> names, like drm_ctx->host1x_ctx for example.
>
> I'm also not a big fan of the "if (ref) put(ref)" pattern. Won't be
> better to move all the "if (!NULL)" checks inside of get()/put() and
> make the invocations unconditional?
I agree that the naming here is confusing with different kinds of
contexts flying around, though I would prefer not to change the original
'struct tegra_drm_context *context' since it's used all around the code.
But I'll try to make it clearer.
Regarding moving NULL checks inside get/put, I personally dislike that
pattern (also with e.g. kfree) since when reading the code, it makes it
more difficult to see that the pointer can be NULL.
Mikko
Powered by blists - more mailing lists