From: Maxime Ripard Subject: Re: [PATCH] drm/fb_helper: Allow leaking fbdev smem_start Date: Fri, 21 Sep 2018 16:07:40 +0200 Message-ID: <20180921140740.j7u7etiuqcih5t2m@flea> References: <1537448652-17780-1-git-send-email-narmstrong@baylibre.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0348729776==" Return-path: Received: from mail.bootlin.com (mail.bootlin.com [62.4.15.54]) by gabe.freedesktop.org (Postfix) with ESMTP id DA55A6E7F0 for ; Fri, 21 Sep 2018 14:07:51 +0000 (UTC) In-Reply-To: <1537448652-17780-1-git-send-email-narmstrong@baylibre.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To: Neil Armstrong Cc: Bartlomiej Zolnierkiewicz , Daniel Vetter , dri-devel@lists.freedesktop.org, Christian =?utf-8?B?S8O2bmln?= List-Id: dri-devel@lists.freedesktop.org --===============0348729776== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="fa4staykg2nxpto4" Content-Disposition: inline --fa4staykg2nxpto4 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, On Thu, Sep 20, 2018 at 03:04:12PM +0200, Neil Armstrong wrote: > Since "drm/fb: Stop leaking physical address", the default behaviour of > the DRM fbdev emulation is to set the smem_base to 0 and pass the new > FBINFO_HIDE_SMEM_START flag. >=20 > The main reason is to avoid leaking physical addresse to user-space, and > it follows a general move over the kernel code to avoid user-space to > manipulate physical addresses and then use some other mechanisms like > dma-buf to transfer physical buffer handles over multiple subsystems. >=20 > But, a lot of devices depends on closed sources binaries to enable > OpenGL hardware acceleration that uses this smem_start value to > pass physical addresses to out-of-tree modules in order to render > into these physical adresses. These should use dma-buf buffers allocated > from the DRM display device instead and stop relying on fbdev overallocat= ion > to gather DMA memory (some HW vendors delivers GBM and Wayland capable > binaries, but older unsupported devices won't have these new binaries > and are doomed until an Open Source solution like Lima finalizes). >=20 > Since these devices heavily depends on this kind of software and because > the smem_start population was available for years, it's a breakage to > stop leaking smem_start without any alternative solutions. >=20 > This patch adds a Kconfig depending on the EXPERT config and an unsafe > kernel module parameter tainting the kernel when enabled. >=20 > A clear comment and Kconfig help text was added to clarify why and when > this patch should be reverted, but in the meantime it's a necessary > feature to keep. >=20 > Cc: Dave Airlie > Cc: Daniel Vetter > Cc: Bartlomiej Zolnierkiewicz > Cc: Noralf Tr=F8nnes > Cc: Maxime Ripard > Cc: Eric Anholt > Cc: Lucas Stach > Cc: Rob Clark > Cc: Ben Skeggs > Cc: Christian K=F6nig > Signed-off-by: Neil Armstrong > --- > drivers/gpu/drm/Kconfig | 15 +++++++++++++++ > drivers/gpu/drm/drm_fb_helper.c | 33 +++++++++++++++++++++++++++++++-- > 2 files changed, 46 insertions(+), 2 deletions(-) >=20 > diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig > index 8871b3f..b07c298 100644 > --- a/drivers/gpu/drm/Kconfig > +++ b/drivers/gpu/drm/Kconfig > @@ -110,6 +110,21 @@ config DRM_FBDEV_OVERALLOC > is 100. Typical values for double buffering will be 200, > triple buffering 300. > =20 > +config DRM_FBDEV_LEAK_PHYS_SMEM > + bool "Shamelessly allow leaking of fbdev physical address (DANGEROUS)" > + depends on DRM_FBDEV_EMULATION && EXPERT > + default n > + help > + In order to keep user-space compatibility, we want in certain > + use-cases to keep leaking the fbdev physical address to the > + user-space program handling the fbdev buffer. > + This option is a shame and should be removed as soon as possible > + and be considered as a broken and legacy behaviour from a modern > + fbdev device driver. > + > + If in doubt, say "N" or spread the word to your closed source > + library vendor. > + > config DRM_LOAD_EDID_FIRMWARE > bool "Allow to specify an EDID data set instead of probing for it" > depends on DRM > diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_hel= per.c > index bf2190c..a354944 100644 > --- a/drivers/gpu/drm/drm_fb_helper.c > +++ b/drivers/gpu/drm/drm_fb_helper.c > @@ -56,6 +56,25 @@ MODULE_PARM_DESC(drm_fbdev_overalloc, > "Overallocation of the fbdev buffer (%) [default=3D" > __MODULE_STRING(CONFIG_DRM_FBDEV_OVERALLOC) "]"); > =20 > +/* > + * In order to keep user-space compatibility, we want in certain use-cas= es > + * to keep leaking the fbdev physical address to the user-space program > + * handling the fbdev buffer. > + * This is a bad habit essentially kept into closed source opengl driver > + * that should really be moved into open-source upstream projects instead > + * of using legacy physical addresses in user space to communicate with > + * other out-of-tree kernel modules. > + * > + * This module_param *should* be removed as soon as possible and be > + * considered as a broken and legacy behaviour from a modern fbdev devic= e. > + */ > +#if IS_ENABLED(CONFIG_DRM_FBDEV_LEAK_PHYS_SMEM) > +static bool drm_leak_fbdev_smem =3D false; > +module_param_unsafe(drm_leak_fbdev_smem, bool, 0600); > +MODULE_PARM_DESC(fbdev_emulation, > + "Allow unsafe leaking fbdev physical smem address [default=3Dfalse]"); > +#endif > + > static LIST_HEAD(kernel_fb_helper_list); > static DEFINE_MUTEX(kernel_fb_helper_lock); > =20 > @@ -2673,8 +2692,12 @@ __drm_fb_helper_initial_config_and_unlock(struct d= rm_fb_helper *fb_helper, > =20 > info =3D fb_helper->fbdev; > info->var.pixclock =3D 0; > - /* don't leak any physical addresses to userspace */ > - info->flags |=3D FBINFO_HIDE_SMEM_START; > + /* Shamelessly allow physical address leaking to userspace */ > +#if IS_ENABLED(CONFIG_DRM_FBDEV_LEAK_PHYS_SMEM) > + if (!drm_leak_fbdev_smem) > +#endif You can use the IS_ENABLED directy within the if statement. It would make the code a bit nicer. > + /* don't leak any physical addresses to userspace */ > + info->flags |=3D FBINFO_HIDE_SMEM_START; > =20 > /* Need to drop locks to avoid recursive deadlock in > * register_framebuffer. This is ok because the only thing left to do is > @@ -3083,6 +3106,12 @@ int drm_fb_helper_generic_probe(struct drm_fb_help= er *fb_helper, > fbi->fbops =3D &drm_fbdev_fb_ops; > fbi->screen_size =3D fb->height * fb->pitches[0]; > fbi->fix.smem_len =3D fbi->screen_size; > + /* Shamelessly leak the physical address to user-space */ > +#if IS_ENABLED(CONFIG_DRM_FBDEV_LEAK_PHYS_SMEM) > + if (drm_leak_fbdev_smem) > + fbi->fix.smem_start =3D > + page_to_phys(virt_to_page(fbi->screen_buffer)); > +#endif fbi->screen_buffer is only set.. > fbi->screen_buffer =3D buffer->vaddr; =2E. at the next line. Moving that line before the if statement works. With that fixed, and the IS_ENABLED in the if Reviewed-by: Maxime Ripard Tested-by: Maxime Ripard Thanks! Maxime --=20 Maxime Ripard, Bootlin Embedded Linux and Kernel engineering https://bootlin.com --fa4staykg2nxpto4 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEE0VqZU19dR2zEVaqr0rTAlCFNr3QFAluk+ysACgkQ0rTAlCFN r3RHRhAAlX9JmXdE8jmVF4b7uC7tNllfiND4h+r+rjfPvISO0AiojZ0HzdeyJrw1 YeLhPpV3CuFRkPHyKkp70G6vRfIGB4AcEIFTPyt0tNty2XhW4oBfE2Dn1BaY2cwd pC8iLFUMjX4/z4j+01VKZaPEt7KTrOv3/ahWWOaECdn15IfvWM44OJO7fQ1Cz/4c YoTYScrf4ninFyyAzZdeVHUYl1wGOGpV4tOMSxzhE3K+41IL1u/rsJs+BuJZEQtw iMBkpSENdKl8xAn4fJGeIFCSwAC69Wn2wm2qwtAndfcEefHMJRw86k81ftoMpqnz NAT9t9Rg+ow7rZqGZ/H8L2A6uflBY0GGqEmA5dbG5NF4q7AzBQ18BE6pSzIj6iRg Oo6vabZUNB+IuC1OK4Rw29encuzqzNUE0xWarb0LRuUT0ivDpmbtSUccdLWTmVXy 5Ys8VjdzD6WtzyG2oBZnNk+/8HqDpV3xnVvTu87q+ZJ3VrdB4D4plE5LvI2QA46Q g9jXINK98gpQEtJKVAkAUDI8uFST1/7iM8KU0/rK6TKgCDlTJlEWo2MK9Zhbm7xI ipGzLyEf12ViBCZLdGXGeT+JZ0olhvjeOV131yuSftq15zxkkBDwm9woxHELDojW bY1CTy3JmRr/irED/pEOqJiYXaU1bYUKGa0YNcGt5+ANeRL/9xo= =Rtae -----END PGP SIGNATURE----- --fa4staykg2nxpto4-- --===============0348729776== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KZHJpLWRldmVs IG1haWxpbmcgbGlzdApkcmktZGV2ZWxAbGlzdHMuZnJlZWRlc2t0b3Aub3JnCmh0dHBzOi8vbGlz dHMuZnJlZWRlc2t0b3Aub3JnL21haWxtYW4vbGlzdGluZm8vZHJpLWRldmVsCg== --===============0348729776==--