From: Chia-I Wu <olvaffe@gmail.com>
To: "Thomas Hellström (VMware)" <thomas_os@shipmail.org>
Cc: Gerd Hoffmann <kraxel@redhat.com>,
ML dri-devel <dri-devel@lists.freedesktop.org>,
Guillaume Gardet <Guillaume.Gardet@arm.com>,
David Airlie <airlied@linux.ie>,
open list <linux-kernel@vger.kernel.org>,
stable@vger.kernel.org,
Gurchetan Singh <gurchetansingh@chromium.org>,
tzimmermann@suse.de
Subject: Re: [PATCH v5 1/3] drm/shmem: add support for per object caching flags.
Date: Wed, 26 Feb 2020 16:02:50 -0800 [thread overview]
Message-ID: <CAPaKu7R4VFYnk9UdpguZnkWeKk2ELVnoQ60=i72RN2GkME1ukw@mail.gmail.com> (raw)
In-Reply-To: <f1afba4b-9c06-48a3-42c7-046695947e91@shipmail.org>
On Wed, Feb 26, 2020 at 10:25 AM Thomas Hellström (VMware)
<thomas_os@shipmail.org> wrote:
>
> Hi, Gerd,
>
> While looking at this patchset I came across some stuff that seems
> strange but that was merged in a previous patchset.
>
> (please refer to
> https://lists.freedesktop.org/archives/dri-devel/2018-September/190001.html.
> Forgive me if I've missed any discussion leading up to this).
>
>
> On 2/26/20 4:47 PM, Gerd Hoffmann wrote:
> > Add map_cached bool to drm_gem_shmem_object, to request cached mappings
> > on a per-object base. Check the flag before adding writecombine to
> > pgprot bits.
> >
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> > ---
> > include/drm/drm_gem_shmem_helper.h | 5 +++++
> > drivers/gpu/drm/drm_gem_shmem_helper.c | 15 +++++++++++----
> > 2 files changed, 16 insertions(+), 4 deletions(-)
> >
> > diff --git a/include/drm/drm_gem_shmem_helper.h b/include/drm/drm_gem_shmem_helper.h
> > index e34a7b7f848a..294b2931c4cc 100644
> > --- a/include/drm/drm_gem_shmem_helper.h
> > +++ b/include/drm/drm_gem_shmem_helper.h
> > @@ -96,6 +96,11 @@ struct drm_gem_shmem_object {
> > * The address are un-mapped when the count reaches zero.
> > */
> > unsigned int vmap_use_count;
> > +
> > + /**
> > + * @map_cached: map object cached (instead of using writecombine).
> > + */
> > + bool map_cached;
> > };
> >
> > #define to_drm_gem_shmem_obj(obj) \
> > diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
> > index a421a2eed48a..aad9324dcf4f 100644
> > --- a/drivers/gpu/drm/drm_gem_shmem_helper.c
> > +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
> > @@ -254,11 +254,16 @@ static void *drm_gem_shmem_vmap_locked(struct drm_gem_shmem_object *shmem)
> > if (ret)
> > goto err_zero_use;
> >
> > - if (obj->import_attach)
> > + if (obj->import_attach) {
> > shmem->vaddr = dma_buf_vmap(obj->import_attach->dmabuf);
> > - else
> > + } else {
> > + pgprot_t prot = PAGE_KERNEL;
> > +
> > + if (!shmem->map_cached)
> > + prot = pgprot_writecombine(prot);
> > shmem->vaddr = vmap(shmem->pages, obj->size >> PAGE_SHIFT,
> > - VM_MAP, pgprot_writecombine(PAGE_KERNEL));
> > + VM_MAP, prot)
>
>
> Wouldn't a vmap with pgprot_writecombine() create conflicting mappings
> with the linear kernel map which is not write-combined? Or do you change
> the linear kernel map of the shmem pages somewhere? vmap bypassess at
> least the x86 PAT core mapping consistency check and this could
> potentially cause spuriously overwritten memory.
Yeah, I think this creates a conflicting alias. It seems a call to
set_pages_array_wc here or changes elsewhere is needed..
But this is a pre-existing issue in the shmem helper. There is also
no universal fix (e.g., set_pages_array_wc is x86 only)? I would hope
this series can be merged sooner to fix the regression first.
>
>
> > + }
> >
> > if (!shmem->vaddr) {
> > DRM_DEBUG_KMS("Failed to vmap pages\n");
> > @@ -540,7 +545,9 @@ int drm_gem_shmem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
> > }
> >
> > vma->vm_flags |= VM_MIXEDMAP | VM_DONTEXPAND;
> > - vma->vm_page_prot = pgprot_writecombine(vm_get_page_prot(vma->vm_flags));
> > + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
> > + if (!shmem->map_cached)
> > + vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
>
> Same thing here. Note that vmf_insert_page() which is used by the fault
> handler also bypasses the x86 PAT consistency check, whereas
> vmf_insert_mixed() doesn't.
>
> > vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
>
> At least with SME or SEV encryption, where shmem memory has its kernel
> map set to encrypted, creating conflicting mappings is explicitly
> disallowed.
> BTW, why is mmap mapping decrypted while vmap isn't?
>
> > vma->vm_ops = &drm_gem_shmem_vm_ops;
> >
>
> Thanks,
> Thomas
>
>
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2020-02-27 0:03 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20200226154752.24328-1-kraxel@redhat.com>
2020-02-26 15:47 ` [PATCH v5 1/3] drm/shmem: add support for per object caching flags Gerd Hoffmann
2020-02-26 16:51 ` Guillaume Gardet
2020-02-26 18:24 ` Thomas Hellström (VMware)
2020-02-27 0:02 ` Chia-I Wu [this message]
2020-02-27 7:16 ` Thomas Hellström (VMware)
2020-02-27 7:53 ` Gerd Hoffmann
2020-02-27 8:10 ` Thomas Hellström (VMware)
2020-02-27 10:56 ` Gerd Hoffmann
2020-02-27 12:16 ` Thomas Hellström (VMware)
2020-02-27 13:21 ` Gerd Hoffmann
2020-02-27 13:44 ` Thomas Hellström (VMware)
2020-02-27 13:49 ` Thomas Hellström (VMware)
2020-02-28 9:49 ` Gerd Hoffmann
2020-02-28 9:54 ` Thomas Hellström (VMware)
2020-02-28 10:46 ` Gerd Hoffmann
2020-03-02 1:56 ` Qiang Yu
2020-02-26 15:47 ` [PATCH v5 2/3] drm/virtio: fix mmap page attributes Gerd Hoffmann
2020-02-26 16:52 ` Guillaume Gardet
2020-02-26 15:47 ` [PATCH v5 3/3] drm/udl: simplify gem object mapping Gerd Hoffmann
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='CAPaKu7R4VFYnk9UdpguZnkWeKk2ELVnoQ60=i72RN2GkME1ukw@mail.gmail.com' \
--to=olvaffe@gmail.com \
--cc=Guillaume.Gardet@arm.com \
--cc=airlied@linux.ie \
--cc=dri-devel@lists.freedesktop.org \
--cc=gurchetansingh@chromium.org \
--cc=kraxel@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=thomas_os@shipmail.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;
as well as URLs for NNTP newsgroup(s).