Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp432985ybf; Wed, 26 Feb 2020 16:03:55 -0800 (PST) X-Google-Smtp-Source: APXvYqxzAhNWtGfATb9g7m3FNBY6zWz5BCfWX3+oBEuceAfbw6MpbwN/+AcnfdwCkwEuELObvjBf X-Received: by 2002:a05:6808:b23:: with SMTP id t3mr1318873oij.88.1582761835341; Wed, 26 Feb 2020 16:03:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582761835; cv=none; d=google.com; s=arc-20160816; b=cO8bPgD9hai/qafsfhbqqn12Bu//pQkO+PSEPmcCgYfF3uQOyHNT7tK2QYgMfklROM qBtTuzXbB3ieeXvY+0Kndmj5QFXGhcukST2JhN3nk8r3NH/vgwPxR3qlZ6aNS6z1ug/Q at/pB/lUPovT0KRtyxBLPjuVWHdVNien+kmY+Is1HFmZkkuA1ZTV1nZLxPSg/Suiz5cs vijnLx+Yz12TW2BIXyPLND3U5EUyolkZpt9/TcPY8ZHvmTJtg1/6ArkkFZqX2pr8G5rL giVfNFQI+9ISHYtWmAWRC20VPnNPzD1Hekh7d//2zszXZhQ92I3cd33V5QJkHTJ47PoS PXGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=tZtnM0e+xr4AH9861svl/LlAtVjcSg0W4wskznM5ZKY=; b=Vg4mAP9lXF5Hk9ybxVqe1Q1fBP5h8fHEhJukDfsqBn9MPhyqPC5XCsr0akRFupDZSa a+BzDQmxDPRODVgSypBmZ3wBT8x0SQPhPQN19Se384in+6QBYG6Yr9X91RlX09MeRDMv 9nOSr8+zZR0KcoFXBqLwEBy5oaGqjhnvkYABA7HbAgi07fMGSRYCWbObiVBLmqiwJPtG hL1rlghKn64GjYurnrkxsCQ96XlUeVTj3IPXgFPrlW2Jvf9DzBHC3cBAMYt5SUGL90Su Vjcrg3iVZ+mMx7MhB5u1p1wyl33IlyhcmXJJGCr4MVIj7rt3H3KaZa+DUToZ0Go2KfzK 0m3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=C4wxSclB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t20si329856oih.70.2020.02.26.16.03.39; Wed, 26 Feb 2020 16:03:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=C4wxSclB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728008AbgB0ADD (ORCPT + 99 others); Wed, 26 Feb 2020 19:03:03 -0500 Received: from mail-io1-f65.google.com ([209.85.166.65]:36182 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727966AbgB0ADC (ORCPT ); Wed, 26 Feb 2020 19:03:02 -0500 Received: by mail-io1-f65.google.com with SMTP id d15so1206739iog.3; Wed, 26 Feb 2020 16:03:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=tZtnM0e+xr4AH9861svl/LlAtVjcSg0W4wskznM5ZKY=; b=C4wxSclBqOr2LuIMMwxD7oLZMwwjbp4vTUF3ZiBhz/VGtOdBYagVxf6pObpH9POUo+ m9ci0oJvKahUD2zyeWp3IAIxTbFjQVVcZx/n8jU28HdofOZvk9KMGrHvBMt3p+IgFb8g bj35iSwW6vw6J43AhaGoR0aU6MEDc7I2lbQ6A3Qm4jf4W+ZNeWmnGUgxPRp7bHlpNsQx ombBRcrwfqlXWMwnY26xViHnqggxOEAnHlyjACJtW1+TSAnvTAmNA51IGzRc3VYslq0C NzNrdK2FGKqfrVRJMVt0lGSVy4UK+M2L5RuGU3jHRTg4uuI/4kUYmLAAXDVE8dwpL5T9 YY1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=tZtnM0e+xr4AH9861svl/LlAtVjcSg0W4wskznM5ZKY=; b=RoWJjvRBV6TB4q1fDwsJqZ1ruq4O2hNd93PfG6lGxnCdxmVmIqZ/kdt/EdEkPDOMl/ /pDrIHk6EynqRk2aGReijYMQplRj1RhJ0v5tJWYhPXYzKfVdZqB7T4Mdy81CJyfiqsLZ e6scZq0ozte3b0OT6g15hSEf1Vvef5lqPkgtWta7UpoPleduc9Rea626/X3xo5C3rS51 LeIxU4kVE3DkaJiu1EMhZn+onWzhJxcLNoPj8BsZe6fEDMJlvhTH5Go1sUsH3hx91AaC 33OLvCf9XUwupaUrOyewe8IwSUENaMfhr+ScVdxk95uzP69rCIg6rh7Pq4a3EKzqr6rG pJtw== X-Gm-Message-State: APjAAAWpMIxsEYKBcvFOd7ZOBa/c0su/V7SQne8Hg9m6fHsDOAEWzc5Q f0HE+R8HA7u2g+oW7WC/w5JSzNZD2LShAlVE3ck= X-Received: by 2002:a02:c815:: with SMTP id p21mr65171jao.20.1582761781497; Wed, 26 Feb 2020 16:03:01 -0800 (PST) MIME-Version: 1.0 References: <20200226154752.24328-1-kraxel@redhat.com> <20200226154752.24328-2-kraxel@redhat.com> In-Reply-To: From: Chia-I Wu Date: Wed, 26 Feb 2020 16:02:50 -0800 Message-ID: Subject: Re: [PATCH v5 1/3] drm/shmem: add support for per object caching flags. To: =?UTF-8?Q?Thomas_Hellstr=C3=B6m_=28VMware=29?= Cc: Gerd Hoffmann , ML dri-devel , Guillaume Gardet , David Airlie , open list , stable@vger.kernel.org, Gurchetan Singh , tzimmermann@suse.de Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 26, 2020 at 10:25 AM Thomas Hellstr=C3=B6m (VMware) 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.ht= ml. > 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 > > --- > > 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_s= hmem_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/d= rm_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 =3D dma_buf_vmap(obj->import_attach->dmabuf)= ; > > - else > > + } else { > > + pgprot_t prot =3D PAGE_KERNEL; > > + > > + if (!shmem->map_cached) > > + prot =3D pgprot_writecombine(prot); > > shmem->vaddr =3D vmap(shmem->pages, obj->size >> PAGE_SHI= FT, > > - VM_MAP, pgprot_writecombine(PAGE_KERN= EL)); > > + 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 |=3D VM_MIXEDMAP | VM_DONTEXPAND; > > - vma->vm_page_prot =3D pgprot_writecombine(vm_get_page_prot(vma->v= m_flags)); > > + vma->vm_page_prot =3D vm_get_page_prot(vma->vm_flags); > > + if (!shmem->map_cached) > > + vma->vm_page_prot =3D pgprot_writecombine(vma->vm_page_pr= ot); > > 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 =3D 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 =3D &drm_gem_shmem_vm_ops; > > > > Thanks, > Thomas > > > > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel