From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 3/3] drm/i915/bios: do not discard address space
Date: Fri, 15 Nov 2019 19:40:15 +0200 [thread overview]
Message-ID: <20191115174015.GI1208@intel.com> (raw)
In-Reply-To: <20191108211353.22288-3-lucas.demarchi@intel.com>
On Fri, Nov 08, 2019 at 01:13:53PM -0800, Lucas De Marchi wrote:
> When we map the VBT through pci_map_rom() we may not be allowed
> to simply discard the address space and go on reading the memory.
> That doesn't work on my test system, but by dumping the rom via
> sysfs I can can get the correct vbt. So change our find_vbt() to do
> the same as done by pci_read_rom(), i.e. use memcpy_fromio().
>
> v2: the just the minimal changes by not bothering with the unaligned io
> reads: this can be done on top (from Ville and Jani)
>
> Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
> ---
> drivers/gpu/drm/i915/display/intel_bios.c | 51 +++++++++++++++++------
> 1 file changed, 39 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_bios.c b/drivers/gpu/drm/i915/display/intel_bios.c
> index c79781e1ccbf..c079febae9c8 100644
> --- a/drivers/gpu/drm/i915/display/intel_bios.c
> +++ b/drivers/gpu/drm/i915/display/intel_bios.c
> @@ -1811,28 +1811,52 @@ bool intel_bios_is_valid_vbt(const void *buf, size_t size)
> return vbt;
> }
>
> -static const struct vbt_header *find_vbt(void __iomem *oprom, size_t size)
> +static const struct vbt_header *copy_vbt(void __iomem *oprom, size_t size)
> {
> + void __iomem *p = NULL;
> + struct vbt_header *vbt;
> + u16 vbt_size;
> size_t i;
>
> /* Scour memory looking for the VBT signature. */
> for (i = 0; i + 4 < size; i++) {
> - void *vbt;
> -
> if (ioread32(oprom + i) != *((const u32 *)"$VBT"))
> continue;
>
> - /*
> - * This is the one place where we explicitly discard the address
> - * space (__iomem) of the BIOS/VBT.
> - */
> - vbt = (void __force *)oprom + i;
> - if (intel_bios_is_valid_vbt(vbt, size - i))
> - return vbt;
> -
> + p = oprom + i;
> + size -= i;
> break;
> }
>
> + if (!p)
> + return NULL;
> +
> + if (sizeof(struct vbt_header) > size) {
> + DRM_DEBUG_DRIVER("VBT header incomplete\n");
> + return NULL;
> + }
> +
> + vbt_size = ioread16(p + offsetof(struct vbt_header, vbt_size));
> + if (vbt_size > size) {
> + DRM_DEBUG_DRIVER("VBT incomplete (vbt_size overflows)\n");
> + return NULL;
> + }
> +
> + /* The rest will be validated by intel_bios_is_valid_vbt() */
> + vbt = kmalloc(vbt_size, GFP_KERNEL);
> + if (!vbt)
> + return NULL;
> +
> + memcpy_fromio(vbt, p, vbt_size);
> +
> + if (!intel_bios_is_valid_vbt(vbt, vbt_size))
> + goto err_free_vbt;
> +
> + return vbt;
> +
> +err_free_vbt:
> + kfree(vbt);
> +
> return NULL;
> }
>
> @@ -1866,7 +1890,7 @@ void intel_bios_init(struct drm_i915_private *dev_priv)
> if (!oprom)
> goto out;
>
> - vbt = find_vbt(oprom, size);
> + vbt = copy_vbt(oprom, size);
> if (!vbt)
> goto out;
>
> @@ -1902,6 +1926,9 @@ void intel_bios_init(struct drm_i915_private *dev_priv)
>
> if (oprom)
> pci_unmap_rom(pdev, oprom);
lgtm
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
As a followup we could now move the rom map/unamp into copy_vbt() as
there's no longer any need to keep it mapped across the whole thing.
> +
> + if (vbt != dev_priv->opregion.vbt)
> + kfree(vbt);
> }
>
> /**
> --
> 2.24.0
--
Ville Syrjälä
Intel
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
WARNING: multiple messages have this Message-ID (diff)
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [Intel-gfx] [PATCH 3/3] drm/i915/bios: do not discard address space
Date: Fri, 15 Nov 2019 19:40:15 +0200 [thread overview]
Message-ID: <20191115174015.GI1208@intel.com> (raw)
Message-ID: <20191115174015.JtusdXyULOAqkD6XMll-uLlNiweCVEhikLd7wqAJRdE@z> (raw)
In-Reply-To: <20191108211353.22288-3-lucas.demarchi@intel.com>
On Fri, Nov 08, 2019 at 01:13:53PM -0800, Lucas De Marchi wrote:
> When we map the VBT through pci_map_rom() we may not be allowed
> to simply discard the address space and go on reading the memory.
> That doesn't work on my test system, but by dumping the rom via
> sysfs I can can get the correct vbt. So change our find_vbt() to do
> the same as done by pci_read_rom(), i.e. use memcpy_fromio().
>
> v2: the just the minimal changes by not bothering with the unaligned io
> reads: this can be done on top (from Ville and Jani)
>
> Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
> ---
> drivers/gpu/drm/i915/display/intel_bios.c | 51 +++++++++++++++++------
> 1 file changed, 39 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_bios.c b/drivers/gpu/drm/i915/display/intel_bios.c
> index c79781e1ccbf..c079febae9c8 100644
> --- a/drivers/gpu/drm/i915/display/intel_bios.c
> +++ b/drivers/gpu/drm/i915/display/intel_bios.c
> @@ -1811,28 +1811,52 @@ bool intel_bios_is_valid_vbt(const void *buf, size_t size)
> return vbt;
> }
>
> -static const struct vbt_header *find_vbt(void __iomem *oprom, size_t size)
> +static const struct vbt_header *copy_vbt(void __iomem *oprom, size_t size)
> {
> + void __iomem *p = NULL;
> + struct vbt_header *vbt;
> + u16 vbt_size;
> size_t i;
>
> /* Scour memory looking for the VBT signature. */
> for (i = 0; i + 4 < size; i++) {
> - void *vbt;
> -
> if (ioread32(oprom + i) != *((const u32 *)"$VBT"))
> continue;
>
> - /*
> - * This is the one place where we explicitly discard the address
> - * space (__iomem) of the BIOS/VBT.
> - */
> - vbt = (void __force *)oprom + i;
> - if (intel_bios_is_valid_vbt(vbt, size - i))
> - return vbt;
> -
> + p = oprom + i;
> + size -= i;
> break;
> }
>
> + if (!p)
> + return NULL;
> +
> + if (sizeof(struct vbt_header) > size) {
> + DRM_DEBUG_DRIVER("VBT header incomplete\n");
> + return NULL;
> + }
> +
> + vbt_size = ioread16(p + offsetof(struct vbt_header, vbt_size));
> + if (vbt_size > size) {
> + DRM_DEBUG_DRIVER("VBT incomplete (vbt_size overflows)\n");
> + return NULL;
> + }
> +
> + /* The rest will be validated by intel_bios_is_valid_vbt() */
> + vbt = kmalloc(vbt_size, GFP_KERNEL);
> + if (!vbt)
> + return NULL;
> +
> + memcpy_fromio(vbt, p, vbt_size);
> +
> + if (!intel_bios_is_valid_vbt(vbt, vbt_size))
> + goto err_free_vbt;
> +
> + return vbt;
> +
> +err_free_vbt:
> + kfree(vbt);
> +
> return NULL;
> }
>
> @@ -1866,7 +1890,7 @@ void intel_bios_init(struct drm_i915_private *dev_priv)
> if (!oprom)
> goto out;
>
> - vbt = find_vbt(oprom, size);
> + vbt = copy_vbt(oprom, size);
> if (!vbt)
> goto out;
>
> @@ -1902,6 +1926,9 @@ void intel_bios_init(struct drm_i915_private *dev_priv)
>
> if (oprom)
> pci_unmap_rom(pdev, oprom);
lgtm
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
As a followup we could now move the rom map/unamp into copy_vbt() as
there's no longer any need to keep it mapped across the whole thing.
> +
> + if (vbt != dev_priv->opregion.vbt)
> + kfree(vbt);
> }
>
> /**
> --
> 2.24.0
--
Ville Syrjälä
Intel
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2019-11-15 17:40 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-08 21:13 [PATCH 1/3] drm/i915/bios: rename bios to oprom when mapping pci rom Lucas De Marchi
2019-11-08 21:13 ` [Intel-gfx] " Lucas De Marchi
2019-11-08 21:13 ` [PATCH 2/3] drm/i915/bios: make sure to check vbt size Lucas De Marchi
2019-11-08 21:13 ` [Intel-gfx] " Lucas De Marchi
2019-11-08 21:13 ` [PATCH 3/3] drm/i915/bios: do not discard address space Lucas De Marchi
2019-11-08 21:13 ` [Intel-gfx] " Lucas De Marchi
2019-11-15 17:40 ` Ville Syrjälä [this message]
2019-11-15 17:40 ` Ville Syrjälä
2019-11-15 17:45 ` Lucas De Marchi
2019-11-15 17:45 ` [Intel-gfx] " Lucas De Marchi
2019-11-08 21:53 ` ✓ Fi.CI.BAT: success for series starting with [1/3] drm/i915/bios: rename bios to oprom when mapping pci rom Patchwork
2019-11-08 21:53 ` [Intel-gfx] " Patchwork
2019-11-10 18:59 ` ✓ Fi.CI.IGT: " Patchwork
2019-11-10 18:59 ` [Intel-gfx] " Patchwork
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=20191115174015.GI1208@intel.com \
--to=ville.syrjala@linux.intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=lucas.demarchi@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.