From: Guenter Roeck <linux@roeck-us.net>
To: Rob Clark <robdclark@gmail.com>
Cc: dri-devel@lists.freedesktop.org,
"Rob Clark" <robdclark@chromium.org>,
"open list" <linux-kernel@vger.kernel.org>,
stable@vger.kernel.org, "Eric Anholt" <eric@anholt.net>,
"Noralf Trønnes" <noralf@tronnes.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>
Subject: Re: [2/2] drm/shmem-helper: Avoid vm_open error paths
Date: Tue, 29 Nov 2022 12:32:05 -0800 [thread overview]
Message-ID: <20221129203205.GA2132357@roeck-us.net> (raw)
In-Reply-To: <20221129200242.298120-3-robdclark@gmail.com>
On Tue, Nov 29, 2022 at 12:02:42PM -0800, Rob Clark wrote:
> From: Rob Clark <robdclark@chromium.org>
>
> vm_open() is not allowed to fail. Fortunately we are guaranteed that
> the pages are already pinned, and only need to increment the refcnt. So
> just increment it directly.
I don't know anything about drm or gem, but I am wondering _how_
this would be guaranteed. Would it be through the pin function ?
Just wondering, because that function does not seem to be mandatory.
>
> Fixes: 2194a63a818d ("drm: Add library for shmem backed GEM objects")
> Cc: stable@vger.kernel.org
> Signed-off-by: Rob Clark <robdclark@chromium.org>
> ---
> drivers/gpu/drm/drm_gem_shmem_helper.c | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
> index 110a9eac2af8..9885ba64127f 100644
> --- a/drivers/gpu/drm/drm_gem_shmem_helper.c
> +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
> @@ -571,12 +571,20 @@ static void drm_gem_shmem_vm_open(struct vm_area_struct *vma)
> {
> struct drm_gem_object *obj = vma->vm_private_data;
> struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
> - int ret;
>
> WARN_ON(shmem->base.import_attach);
>
> - ret = drm_gem_shmem_get_pages(shmem);
> - WARN_ON_ONCE(ret != 0);
> + mutex_lock(&shmem->pages_lock);
> +
> + /*
> + * We should have already pinned the pages, vm_open() just grabs
should or guaranteed ? This sounds a bit weaker than the commit
description.
> + * an additional reference for the new mm the vma is getting
> + * copied into.
> + */
> + WARN_ON_ONCE(!shmem->pages_use_count);
> +
> + shmem->pages_use_count++;
> + mutex_unlock(&shmem->pages_lock);
The previous code, in that situation, would not increment pages_use_count,
and it would not set not set shmem->pages. Hopefully, it would not try to
do anything with the pages it was unable to get. The new code assumes that
shmem->pages is valid even if pages_use_count is 0, while at the same time
taking into account that this can possibly happen (or the WARN_ON_ONCE
would not be needed).
Again, I don't know anything about gem and drm, but it seems to me that
there might now be a severe problem later on if the WARN_ON_ONCE()
ever triggers.
Thanks,
Guenter
>
> drm_gem_vm_open(vma);
> }
next prev parent reply other threads:[~2022-11-29 20:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-29 20:02 [PATCH 0/2] drm/shmem-helper: Fix a couple of error path bugs Rob Clark
2022-11-29 20:02 ` [PATCH 1/2] drm/shmem-helper: Remove errant put in error path Rob Clark
2022-11-29 20:13 ` [1/2] " Guenter Roeck
2022-11-30 11:19 ` [PATCH 1/2] " Daniel Vetter
2022-11-29 20:02 ` [PATCH 2/2] drm/shmem-helper: Avoid vm_open error paths Rob Clark
2022-11-29 20:32 ` Guenter Roeck [this message]
2022-11-29 20:47 ` [2/2] " Rob Clark
2022-11-30 0:13 ` Guenter Roeck
2022-11-30 11:21 ` Daniel Vetter
2022-11-30 14:03 ` [PATCH 2/2] " Daniel Vetter
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=20221129203205.GA2132357@roeck-us.net \
--to=linux@roeck-us.net \
--cc=dri-devel@lists.freedesktop.org \
--cc=eric@anholt.net \
--cc=linux-kernel@vger.kernel.org \
--cc=noralf@tronnes.org \
--cc=robdclark@chromium.org \
--cc=robdclark@gmail.com \
--cc=stable@vger.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®