From: "Christian König" <christian.koenig@amd.com>
To: Daniel Vetter <daniel@ffwll.ch>
Cc: Thomas Hellstrom <thellstrom@vmware.com>,
Daniel Vetter <daniel.vetter@ffwll.ch>,
DRI Development <dri-devel@lists.freedesktop.org>,
Huang Rui <ray.huang@amd.com>, Brian Paul <brianp@vmware.com>,
Daniel Vetter <daniel.vetter@intel.com>
Subject: Re: [PATCH] drm/ttm: don't set page->mapping
Date: Thu, 5 Nov 2020 13:56:22 +0100 [thread overview]
Message-ID: <614b3893-b735-7ba4-4f0a-55891adbdc8d@amd.com> (raw)
In-Reply-To: <20201105125009.GV401619@phenom.ffwll.local>
Am 05.11.20 um 13:50 schrieb Daniel Vetter:
> On Thu, Nov 05, 2020 at 01:29:50PM +0100, Christian König wrote:
>> Am 05.11.20 um 10:11 schrieb Daniel Vetter:
>>> On Thu, Nov 5, 2020 at 9:00 AM Christian König <christian.koenig@amd.com> wrote:
>>>> Am 04.11.20 um 17:50 schrieb Daniel Vetter:
>>>>> Random observation while trying to review Christian's patch series to
>>>>> stop looking at struct page for dma-buf imports.
>>>>>
>>>>> This was originally added in
>>>>>
>>>>> commit 58aa6622d32af7d2c08d45085f44c54554a16ed7
>>>>> Author: Thomas Hellstrom <thellstrom@vmware.com>
>>>>> Date: Fri Jan 3 11:47:23 2014 +0100
>>>>>
>>>>> drm/ttm: Correctly set page mapping and -index members
>>>>>
>>>>> Needed for some vm operations; most notably unmap_mapping_range() with
>>>>> even_cows = 0.
>>>>>
>>>>> Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
>>>>> Reviewed-by: Brian Paul <brianp@vmware.com>
>>>>>
>>>>> but we do not have a single caller of unmap_mapping_range with
>>>>> even_cows == 0. And all the gem drivers don't do this, so another
>>>>> small thing we could standardize between drm and ttm drivers.
>>>>>
>>>>> Plus I don't really see a need for unamp_mapping_range where we don't
>>>>> want to indiscriminately shoot down all ptes.
>>>> NAK, we use this to determine if a pages belongs to the driver or not in
>>>> amdgpu for example.
>>>>
>>>> Mostly used for debugging, but I would really like to keep that.
>>> Can you pls point me at that code? A quick grep hasn't really found much at all.
>> See amdgpu_iomem_read() for an example:
> Why do you reject this?
When IOMMU is disabled or uses an 1 to 1 mapping we would otherwise give
the same access as /dev/mem to system memory and that is forbidden. But
as I noted this is just for the debugfs file.
When I tried a few years ago to not set the page->mapping I immediately
ran into issues with our eviction test. So I think that this is used
elsewhere as well.
Regards,
Christian.
>
> If this is to avoid issues with userptr, then I think there's a simple
> trick:
> - grab page reference
> - recheck that the iova still points at the same address
> - do read/write, safe in the knowledge that this page cannot be reused for
> anything else
> - drop page reference
>
> Of course this can still race against iova updates, but that seems to be a
> fundamental part of your debug interface here.
>
> Or am I missing something?
>
> Just pondering this more since setting the page->mapping pointer for just
> this seems somewhat wild abuse of ->mapping semantics :-)
> -Daniel
>
>>> if (p->mapping != adev->mman.bdev.dev_mapping)
>>> return -EPERM;
>> Christian.
>>
>>> -Daniel
>>>
>>>> Christian.
>>>>
>>>>> Cc: Thomas Hellstrom <thellstrom@vmware.com>
>>>>> Cc: Brian Paul <brianp@vmware.com>
>>>>> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
>>>>> Cc: Christian Koenig <christian.koenig@amd.com>
>>>>> Cc: Huang Rui <ray.huang@amd.com>
>>>>> ---
>>>>> drivers/gpu/drm/ttm/ttm_tt.c | 12 ------------
>>>>> 1 file changed, 12 deletions(-)
>>>>>
>>>>> diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
>>>>> index 8861a74ac335..438ea43fd8c1 100644
>>>>> --- a/drivers/gpu/drm/ttm/ttm_tt.c
>>>>> +++ b/drivers/gpu/drm/ttm/ttm_tt.c
>>>>> @@ -291,17 +291,6 @@ int ttm_tt_swapout(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
>>>>> return ret;
>>>>> }
>>>>>
>>>>> -static void ttm_tt_add_mapping(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
>>>>> -{
>>>>> - pgoff_t i;
>>>>> -
>>>>> - if (ttm->page_flags & TTM_PAGE_FLAG_SG)
>>>>> - return;
>>>>> -
>>>>> - for (i = 0; i < ttm->num_pages; ++i)
>>>>> - ttm->pages[i]->mapping = bdev->dev_mapping;
>>>>> -}
>>>>> -
>>>>> int ttm_tt_populate(struct ttm_bo_device *bdev,
>>>>> struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
>>>>> {
>>>>> @@ -320,7 +309,6 @@ int ttm_tt_populate(struct ttm_bo_device *bdev,
>>>>> if (ret)
>>>>> return ret;
>>>>>
>>>>> - ttm_tt_add_mapping(bdev, ttm);
>>>>> ttm->page_flags |= TTM_PAGE_FLAG_PRIV_POPULATED;
>>>>> if (unlikely(ttm->page_flags & TTM_PAGE_FLAG_SWAPPED)) {
>>>>> ret = ttm_tt_swapin(ttm);
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2020-11-05 12:56 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-04 16:50 [PATCH] drm/ttm: don't set page->mapping Daniel Vetter
2020-11-05 7:59 ` Christian König
2020-11-05 9:11 ` Daniel Vetter
2020-11-05 12:29 ` Christian König
2020-11-05 12:50 ` Daniel Vetter
2020-11-05 12:56 ` Christian König [this message]
2020-11-05 13:20 ` Daniel Vetter
2020-11-05 13:22 ` Christian König
2020-11-05 14:31 ` Daniel Vetter
2020-11-05 14:38 ` Daniel Vetter
2020-11-05 15:15 ` Christian König
2020-11-05 16:37 ` Daniel Vetter
2020-11-06 8:30 ` Christian König
2020-11-20 9:54 [PATCH 0/3] mmu_notifier fs fs_reclaim lockdep annotations Daniel Vetter
2020-11-20 9:54 ` [PATCH] drm/ttm: don't set page->mapping Daniel Vetter
2020-11-20 10:04 ` Christian König
2020-11-20 10:05 ` Daniel Vetter
2020-11-20 10:08 ` Christian König
2020-11-20 15:01 ` Daniel Vetter
2020-11-25 16:25 [PATCH v4 0/3] mmu_notifier vs fs_reclaim lockdep annotations Daniel Vetter
2020-11-25 16:25 ` [PATCH] drm/ttm: don't set page->mapping Daniel Vetter
2020-11-25 16:28 ` Daniel Vetter
2020-11-25 18:06 ` Jason Gunthorpe
2020-11-25 18:16 ` Daniel Stone
[not found] ` <20201125181129.GA1858@infradead.org>
2020-11-25 23:57 ` Jason Gunthorpe
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=614b3893-b735-7ba4-4f0a-55891adbdc8d@amd.com \
--to=christian.koenig@amd.com \
--cc=brianp@vmware.com \
--cc=daniel.vetter@ffwll.ch \
--cc=daniel.vetter@intel.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=ray.huang@amd.com \
--cc=thellstrom@vmware.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;
as well as URLs for NNTP newsgroup(s).