From: Mikko Perttunen <cyndis@kapsi.fi>
To: Dmitry Osipenko <digetx@gmail.com>,
Mikko Perttunen <mperttunen@nvidia.com>,
thierry.reding@gmail.com, jonathanh@nvidia.com, joro@8bytes.org,
will@kernel.org, robh+dt@kernel.org, robin.murphy@arm.com
Cc: linux-tegra@vger.kernel.org, dri-devel@lists.freedesktop.org,
iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v3 9/9] drm/tegra: Support context isolation
Date: Tue, 22 Feb 2022 10:37:05 +0200 [thread overview]
Message-ID: <134c4a28-4331-deed-a374-75c9711168f0@kapsi.fi> (raw)
In-Reply-To: <bb533634-6cde-3835-db11-7b6191385294@gmail.com>
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
prev parent reply other threads:[~2022-02-22 8:37 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-18 11:39 [PATCH v3 0/9] Host1x context isolation support Mikko Perttunen
2022-02-18 11:39 ` [PATCH v3 1/9] dt-bindings: host1x: Add memory-contexts property Mikko Perttunen
2022-02-21 15:23 ` Robin Murphy
2022-02-21 15:28 ` Mikko Perttunen
2022-02-21 16:58 ` Robin Murphy
2022-02-21 17:12 ` Mikko Perttunen
2022-02-18 11:39 ` [PATCH v3 2/9] gpu: host1x: Add context bus Mikko Perttunen
2022-02-19 17:54 ` Dmitry Osipenko
2022-02-19 18:15 ` Dmitry Osipenko
2022-02-22 16:21 ` Christoph Hellwig
2022-02-22 21:30 ` Robin Murphy
2022-02-23 6:36 ` Christoph Hellwig
2022-02-18 11:39 ` [PATCH v3 3/9] gpu: host1x: Add context device management code Mikko Perttunen
2022-02-19 17:48 ` Dmitry Osipenko
2022-02-21 11:35 ` Mikko Perttunen
2022-02-19 17:52 ` Dmitry Osipenko
2022-02-21 11:37 ` Mikko Perttunen
2022-02-22 16:24 ` Christoph Hellwig
2022-02-23 9:44 ` Mikko Perttunen
2022-02-18 11:39 ` [PATCH v3 4/9] gpu: host1x: Program context stream ID on submission Mikko Perttunen
2022-02-18 11:39 ` [PATCH v3 5/9] iommu/arm-smmu: Attach to host1x context device bus Mikko Perttunen
2022-02-18 11:39 ` [PATCH v3 6/9] arm64: tegra: Add Host1x context stream IDs on Tegra186+ Mikko Perttunen
2022-02-18 11:39 ` [PATCH v3 7/9] drm/tegra: falcon: Set DMACTX field on DMA transactions Mikko Perttunen
2022-02-18 11:39 ` [PATCH v3 8/9] drm/tegra: vic: Implement get_streamid_offset Mikko Perttunen
2022-02-19 18:49 ` Dmitry Osipenko
2022-02-19 18:54 ` Dmitry Osipenko
2022-02-21 11:44 ` Mikko Perttunen
2022-02-21 20:10 ` Dmitry Osipenko
2022-02-22 8:27 ` Mikko Perttunen
2022-02-22 10:46 ` Dmitry Osipenko
2022-02-22 10:54 ` Mikko Perttunen
2022-02-22 11:02 ` Dmitry Osipenko
2022-02-21 17:27 ` Robin Murphy
2022-02-21 17:36 ` Mikko Perttunen
2022-02-18 11:39 ` [PATCH v3 9/9] drm/tegra: Support context isolation Mikko Perttunen
2022-02-19 18:35 ` Dmitry Osipenko
2022-02-21 12:06 ` Mikko Perttunen
2022-02-21 20:02 ` Dmitry Osipenko
2022-02-22 8:37 ` Mikko Perttunen [this message]
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=134c4a28-4331-deed-a374-75c9711168f0@kapsi.fi \
--to=cyndis@kapsi.fi \
--cc=devicetree@vger.kernel.org \
--cc=digetx@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=iommu@lists.linux-foundation.org \
--cc=jonathanh@nvidia.com \
--cc=joro@8bytes.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=mperttunen@nvidia.com \
--cc=robh+dt@kernel.org \
--cc=robin.murphy@arm.com \
--cc=thierry.reding@gmail.com \
--cc=will@kernel.org \
/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