mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: Dawei Li <set_pte_at@outlook.com>,
	alexander.deucher@amd.com, Xinhui.Pan@amd.com
Cc: airlied@gmail.com, daniel@ffwll.ch, jglisse@redhat.com,
	amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drm/radeon: fix potential racing issue due to mmap_lock
Date: Mon, 14 Nov 2022 11:26:35 +0100	[thread overview]
Message-ID: <45eee340-8806-f0cc-9a93-02f2b776b284@amd.com> (raw)
In-Reply-To: <TYCP286MB232339970F7009B962E2F1BECA029@TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM>

Am 13.11.22 um 13:42 schrieb Dawei Li:
> Both find_vma() and get_user_pages() need explicit protection of
> mmap lock, fix them by mmap_lock and get_user_pages_fast().

NAK, the MM read lock should already be taken when we reach this function.

Could be that this is buggy and the function is called without holding 
the lock, but trying to grab it while holding the reservation lock is 
also forbidden.

Christian.

>
> Fixes: ddd00e33e17a ("drm/radeon: add userptr flag to limit it to anonymous memory v2")
> Fixes: f72a113a71ab ("drm/radeon: add userptr support v8")
> Signed-off-by: Dawei Li <set_pte_at@outlook.com>
> ---
>   drivers/gpu/drm/radeon/radeon_ttm.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
> index d33fec488713..741ea64b9402 100644
> --- a/drivers/gpu/drm/radeon/radeon_ttm.c
> +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
> @@ -351,7 +351,10 @@ static int radeon_ttm_tt_pin_userptr(struct ttm_device *bdev, struct ttm_tt *ttm
>   		   to prevent problems with writeback */
>   		unsigned long end = gtt->userptr + (u64)ttm->num_pages * PAGE_SIZE;
>   		struct vm_area_struct *vma;
> +
> +		mmap_read_lock(gtt->usermm);
>   		vma = find_vma(gtt->usermm, gtt->userptr);
> +		mmap_read_unlock(gtt->usermm);
>   		if (!vma || vma->vm_file || vma->vm_end < end)
>   			return -EPERM;
>   	}
> @@ -361,8 +364,7 @@ static int radeon_ttm_tt_pin_userptr(struct ttm_device *bdev, struct ttm_tt *ttm
>   		uint64_t userptr = gtt->userptr + pinned * PAGE_SIZE;
>   		struct page **pages = ttm->pages + pinned;
>   
> -		r = get_user_pages(userptr, num_pages, write ? FOLL_WRITE : 0,
> -				   pages, NULL);
> +		r = get_user_pages_fast(userptr, num_pages, write ? FOLL_WRITE : 0, pages);
>   		if (r < 0)
>   			goto release_pages;
>   


      reply	other threads:[~2022-11-14 10:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-13 12:42 Dawei Li
2022-11-14 10:26 ` Christian König [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=45eee340-8806-f0cc-9a93-02f2b776b284@amd.com \
    --to=christian.koenig@amd.com \
    --cc=Xinhui.Pan@amd.com \
    --cc=airlied@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jglisse@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=set_pte_at@outlook.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

all inboxes | Powered by JetHome®