Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp643155ybl; Wed, 11 Dec 2019 05:22:02 -0800 (PST) X-Google-Smtp-Source: APXvYqzPBY3s65GwpZc5G3QOEZGthSbl1VaKE/ETTlWwWzvTiwHQEMzInCbY+K6Fs+7Lmv8EK/r1 X-Received: by 2002:aca:fdd7:: with SMTP id b206mr2595358oii.35.1576070522610; Wed, 11 Dec 2019 05:22:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576070522; cv=none; d=google.com; s=arc-20160816; b=liuznxnJ51wDe+fp606KKMcIC4uPXj1S69IIJxaZy/YlqRCs31a5vA40GeWvHqMu0e sdmmNi5/T/lZaNLMIkAxFBPklyGxki4gsP03l1c9kcCp6jUuQ8Vr9o/fnaDww2JRPYCB aP8d+AjB57m8uhrX8Sg8Lw6hWFD0Io7vH27LRF992+lptbItFMUiz6L6788+q5iHDc4v NcJ5ndsMEkp/pzpE8wpHUQ8QPEZCo2oz0oGZbmf2ECgWCiZLI2idEhygSThMNTGmkhyk BMLXsP7mAenqAjP6V+LvQMBQx7i1YSFPjRnDnQAPeNU4wL7zQ7j+itFVpn5MGQIZyShu zXTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:from:references:to:subject; bh=PNqHZWmrSamlRwOb98sku/Su7juqZFbxMSmtCLRGlsE=; b=iXbIoRJb7miphLLzY9I1WFbvS6WQpHqiHPehsakKj00vIh7RcvymyVWc7I31VBOMaK oOS+WscVZUQuMzNo3Jvm+jrTdlWcQJYFiEmwBysHPGM8LKP5kJrTD89SUB5+O51Ds5wU RU3zn+aePTZ99UqKERY0UeM8w5AQLGz8EuCBn3zOnVggdZA0KFZqY2UkzQCvmBGAgPZu 6wzGBPmgSxqZlWiw6JY8rA1Ata3kuijvbzXIIaEwC8+tjV865/UvWpNIW7ATPBJrc6v6 /2AG5FEwQITfQFg2UbX4ps1kuY1YzAyt/Jwm7uru54NM8XAJelJBGWmREpRMv8Zaz5pU ordQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z10si1143356oto.50.2019.12.11.05.21.50; Wed, 11 Dec 2019 05:22:02 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729495AbfLKNVT (ORCPT + 99 others); Wed, 11 Dec 2019 08:21:19 -0500 Received: from mx2.suse.de ([195.135.220.15]:39672 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729132AbfLKNVQ (ORCPT ); Wed, 11 Dec 2019 08:21:16 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 4E584ABF6; Wed, 11 Dec 2019 13:21:14 +0000 (UTC) Subject: Re: [PATCH v3 1/4] drm: add pgprot callback to drm_gem_object_funcs To: Gerd Hoffmann , dri-devel@lists.freedesktop.org, gurchetansingh@chromium.org, Maarten Lankhorst , Maxime Ripard , David Airlie , open list References: <20191211121957.18637-1-kraxel@redhat.com> <20191211121957.18637-2-kraxel@redhat.com> <20191211123835.GZ624164@phenom.ffwll.local> From: Thomas Zimmermann Autocrypt: addr=tzimmermann@suse.de; keydata= mQENBFs50uABCADEHPidWt974CaxBVbrIBwqcq/WURinJ3+2WlIrKWspiP83v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Kvbaxq0zb ehDda8lvhFXodNFMAgTLJlLuDYOGLK2AwbrS3Sp0AEbkpdJBb44qVlGm5bApZouHeJ/+n+7r 12+lqdsAEQEAAYkBPAQYAQgAJhYhBHIX+6yM6c9jRKFo5WgNwR1TC3ojBQJbOdLgAhsMBQkD wmcAAAoJEGgNwR1TC3ojpfcIAInwP5OlcEKokTnHCiDTz4Ony4GnHRP2fXATQZCKxmu4AJY2 h9ifw9Nf2TjCZ6AMvC3thAN0rFDj55N9l4s1CpaDo4J+0fkrHuyNacnT206CeJV1E7NYntxU n+LSiRrOdywn6erjxRi9EYTVLCHcDhBEjKmFZfg4AM4GZMWX1lg0+eHbd5oL1as28WvvI/uI aMyV8RbyXot1r/8QLlWldU3NrTF5p7TMU2y3ZH2mf5suSKHAMtbE4jKJ8ZHFOo3GhLgjVrBW HE9JXO08xKkgD+w6v83+nomsEuf6C6LYrqY/tsZvyEX6zN8CtirPdPWu/VXNRYAl/lat7lSI 3H26qrE= Message-ID: <226bad4b-09db-4c89-0611-d3c89e3628cd@suse.de> Date: Wed, 11 Dec 2019 14:21:09 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20191211123835.GZ624164@phenom.ffwll.local> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="8rsNep00E8ys0bAoSOGO4rfAQ3Hgi85R2" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --8rsNep00E8ys0bAoSOGO4rfAQ3Hgi85R2 Content-Type: multipart/mixed; boundary="ZpRogva5wQ0Ag0bvgxTv8YttlUxQqsu2m"; protected-headers="v1" From: Thomas Zimmermann To: Gerd Hoffmann , dri-devel@lists.freedesktop.org, gurchetansingh@chromium.org, Maarten Lankhorst , Maxime Ripard , David Airlie , open list Message-ID: <226bad4b-09db-4c89-0611-d3c89e3628cd@suse.de> Subject: Re: [PATCH v3 1/4] drm: add pgprot callback to drm_gem_object_funcs References: <20191211121957.18637-1-kraxel@redhat.com> <20191211121957.18637-2-kraxel@redhat.com> <20191211123835.GZ624164@phenom.ffwll.local> In-Reply-To: <20191211123835.GZ624164@phenom.ffwll.local> --ZpRogva5wQ0Ag0bvgxTv8YttlUxQqsu2m Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable Hi Am 11.12.19 um 13:38 schrieb Daniel Vetter: > On Wed, Dec 11, 2019 at 01:19:53PM +0100, Gerd Hoffmann wrote: >> The callback allows drivers and helpers to tweak pgprot for mappings. >> This is especially helpful when using shmem helpers. It allows driver= s >> to switch mappings from writecombine (default) to something else (cach= ed >> for example) on a per-object base without having to supply their own >> mmap() and vmap() functions. >> >> The patch also adds two implementations for the callback, for cached a= nd >> writecombine mappings, and the drm_gem_pgprot() function to update >> pgprot for a given object, using the new &drm_gem_object_funcs.pgprot >> callback if available. >> >> Signed-off-by: Gerd Hoffmann >> --- >> include/drm/drm_gem.h | 15 +++++++++++++ >> drivers/gpu/drm/drm_gem.c | 46 ++++++++++++++++++++++++++++++++++++++= - >> 2 files changed, 60 insertions(+), 1 deletion(-) >> >> diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h >> index 0b375069cd48..5beef7226e69 100644 >> --- a/include/drm/drm_gem.h >> +++ b/include/drm/drm_gem.h >> @@ -163,6 +163,17 @@ struct drm_gem_object_funcs { >> */ >> int (*mmap)(struct drm_gem_object *obj, struct vm_area_struct *vma);= >> =20 >> + /** >> + * @pgprot: >> + * >> + * Tweak pgprot as needed, typically used to set cache bits. >> + * >> + * This callback is optional. >> + * >> + * If unset drm_gem_pgprot_wc() will be used. >> + */ >> + pgprot_t (*pgprot)(struct drm_gem_object *obj, pgprot_t prot); >=20 > I kinda prefer v1, mostly because this is a huge can of worms, and solv= ing > this properly is going to be real hard (and will necessarily involve > dma-buf and dma-api and probably more). Charging ahead here just risks > that we dig ourselves into a corner. You're v1 is maybe not the most > clean, but just a few code bits here&there should be more flexible and > easier to hack on and experiment around with. > -Daniel I agree; at least patch v1 is known to be a sound approach. The others might fall on our feet at some point. Sorry, Gerd, if my proposals added lots of work for you. Best regards Thomas >=20 >> + >> /** >> * @vm_ops: >> * >> @@ -350,6 +361,10 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, = unsigned long obj_size, >> struct vm_area_struct *vma); >> int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma); >> =20 >> +pgprot_t drm_gem_pgprot_cached(struct drm_gem_object *obj, pgprot_t p= rot); >> +pgprot_t drm_gem_pgprot_wc(struct drm_gem_object *obj, pgprot_t prot)= ; >> +pgprot_t drm_gem_pgprot(struct drm_gem_object *obj, pgprot_t prot); >> + >> /** >> * drm_gem_object_get - acquire a GEM buffer object reference >> * @obj: GEM buffer object >> diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c >> index 56f42e0f2584..1c468fe8e342 100644 >> --- a/drivers/gpu/drm/drm_gem.c >> +++ b/drivers/gpu/drm/drm_gem.c >> @@ -1119,7 +1119,8 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj,= unsigned long obj_size, >> return -EINVAL; >> =20 >> vma->vm_flags |=3D VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP;= >> - vma->vm_page_prot =3D pgprot_writecombine(vm_get_page_prot(vma->vm_= flags)); >> + vma->vm_page_prot =3D vm_get_page_prot(vma->vm_flags); >> + vma->vm_page_prot =3D drm_gem_pgprot(obj, vma->vm_page_prot); >> vma->vm_page_prot =3D pgprot_decrypted(vma->vm_page_prot); >> } >> =20 >> @@ -1210,6 +1211,49 @@ int drm_gem_mmap(struct file *filp, struct vm_a= rea_struct *vma) >> } >> EXPORT_SYMBOL(drm_gem_mmap); >> =20 >> +/** >> + * drm_gem_mmap - update pgprot for objects needing a cachable mappin= g. >> + * @obj: the GEM object. >> + * @prot: page attributes. >> + * >> + * This function can be used as &drm_gem_object_funcs.pgprot callback= =2E >> + */ >> +pgprot_t drm_gem_pgprot_cached(struct drm_gem_object *obj, pgprot_t p= rot) >> +{ >> + return prot; >> +} >> +EXPORT_SYMBOL(drm_gem_pgprot_cached); >> + >> +/** >> + * drm_gem_mmap - update pgprot for objects needing a wc mapping. >> + * @obj: the GEM object. >> + * @prot: page attributes. >> + * >> + * This function can be used as &drm_gem_object_funcs.pgprot callback= =2E >> + */ >> +pgprot_t drm_gem_pgprot_wc(struct drm_gem_object *obj, pgprot_t prot)= >> +{ >> + return pgprot_writecombine(prot); >> +} >> +EXPORT_SYMBOL(drm_gem_pgprot_wc); >> + >> +/** >> + * drm_gem_mmap - update pgprot for a given gem object. >> + * @obj: the GEM object. >> + * @prot: page attributes. >> + * >> + * This function updates pgprot according to the needs of the given >> + * object. If present &drm_gem_object_funcs.pgprot callback will be >> + * used, otherwise drm_gem_pgprot_wc() is called. >> + */ >> +pgprot_t drm_gem_pgprot(struct drm_gem_object *obj, pgprot_t prot) >> +{ >> + if (obj->funcs->pgprot) >> + return obj->funcs->pgprot(obj, prot); >> + return drm_gem_pgprot_wc(obj, prot); >> +} >> +EXPORT_SYMBOL(drm_gem_pgprot); >> + >> void drm_gem_print_info(struct drm_printer *p, unsigned int indent, >> const struct drm_gem_object *obj) >> { >> --=20 >> 2.18.1 >> >=20 --=20 Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 N=C3=BCrnberg, Germany (HRB 36809, AG N=C3=BCrnberg) Gesch=C3=A4ftsf=C3=BChrer: Felix Imend=C3=B6rffer --ZpRogva5wQ0Ag0bvgxTv8YttlUxQqsu2m-- --8rsNep00E8ys0bAoSOGO4rfAQ3Hgi85R2 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEchf7rIzpz2NEoWjlaA3BHVMLeiMFAl3w7UUACgkQaA3BHVML eiMNAgf9EYgarwDWgI5cEixKKpWA5Vm47XNqgXIrxMCcqbzy4qAsymMEokX+o+4e IQQNzkQG5DT+j4MX/b9QnrNkZoerodmLjxksg3jPQHEWENEl/tScL7RktpMVf355 LKBqtkwuPEEAWOzb2nbLkcMSvYYcvNNboVdMlum45YbVj4gcTlajAV/rqyFdlGW+ urccISoEMka+7MDy5slnpCNT4jSUQc4Ofy+VxApeWd2o7An4p/Zb5SJ00oH5YiUo SS4n8CTOf25ghWPVE+uDnfH0FW1A0t6bV/hETfTed4NTTbUMBuQR4XEUp7faXwIW ii6pKDDwHF3+FSFOOODtss/+MfLy4A== =AHVo -----END PGP SIGNATURE----- --8rsNep00E8ys0bAoSOGO4rfAQ3Hgi85R2--