Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] drm/i915/bios: do not discard address space
@ 2019-11-20 23:46 Lucas De Marchi
  2019-11-20 23:46 ` [Intel-gfx] " Lucas De Marchi
                   ` (4 more replies)
  0 siblings, 5 replies; 24+ messages in thread
From: Lucas De Marchi @ 2019-11-20 23:46 UTC (permalink / raw)
  To: intel-gfx

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)

v3: drop const in function return since now we are copying the vbt,
rather than just finding it

Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.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 f6a9a5ccb556..8bdfc1d55040 100644
--- a/drivers/gpu/drm/i915/display/intel_bios.c
+++ b/drivers/gpu/drm/i915/display/intel_bios.c
@@ -1896,28 +1896,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 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;
 }
 
@@ -1953,7 +1977,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;
 
@@ -1990,6 +2014,9 @@ void intel_bios_init(struct drm_i915_private *dev_priv)
 
 	if (oprom)
 		pci_unmap_rom(pdev, oprom);
+
+	if (vbt != dev_priv->opregion.vbt)
+		kfree(vbt);
 }
 
 /**
-- 
2.24.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 24+ messages in thread
* [PATCH 0/3] bios: dot not discard address space
@ 2019-11-26 22:51 Lucas De Marchi
  2019-11-26 22:51 ` [PATCH 2/3] drm/i915/bios: fold pci rom map/unmap into copy function Lucas De Marchi
  0 siblings, 1 reply; 24+ messages in thread
From: Lucas De Marchi @ 2019-11-26 22:51 UTC (permalink / raw)
  To: intel-gfx

v4 of https://patchwork.freedesktop.org/series/69790/

Add missing unmap in patch 2 and update 3rd patch to the bare minimum.

Lucas De Marchi (3):
  drm/i915/bios: do not discard address space
  drm/i915/bios: fold pci rom map/unmap into copy function
  drm/i915/bios: assume vbt is 4-byte aligned into oprom

 drivers/gpu/drm/i915/display/intel_bios.c | 75 +++++++++++++++--------
 1 file changed, 51 insertions(+), 24 deletions(-)

-- 
2.24.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 24+ messages in thread
* [PATCH 1/3] drm/i915/bios: do not discard address space
@ 2019-11-15 23:35 Lucas De Marchi
  2019-11-15 23:35 ` [PATCH 2/3] drm/i915/bios: fold pci rom map/unmap into copy function Lucas De Marchi
  0 siblings, 1 reply; 24+ messages in thread
From: Lucas De Marchi @ 2019-11-15 23:35 UTC (permalink / raw)
  To: intel-gfx

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)

v3: drop const in function return since now we are copying the vbt,
rather than just finding it

Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20191108211353.22288-3-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 6d7b1a83cb07..cc0ca2f8dd7b 100644
--- a/drivers/gpu/drm/i915/display/intel_bios.c
+++ b/drivers/gpu/drm/i915/display/intel_bios.c
@@ -1796,28 +1796,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 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;
 }
 
@@ -1853,7 +1877,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;
 
@@ -1889,6 +1913,9 @@ void intel_bios_init(struct drm_i915_private *dev_priv)
 
 	if (oprom)
 		pci_unmap_rom(pdev, oprom);
+
+	if (vbt != dev_priv->opregion.vbt)
+		kfree(vbt);
 }
 
 /**
-- 
2.24.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2019-11-26 22:51 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-20 23:46 [PATCH 1/3] drm/i915/bios: do not discard address space Lucas De Marchi
2019-11-20 23:46 ` [Intel-gfx] " Lucas De Marchi
2019-11-20 23:46 ` [PATCH 2/3] drm/i915/bios: fold pci rom map/unmap into copy function Lucas De Marchi
2019-11-20 23:46   ` [Intel-gfx] " Lucas De Marchi
2019-11-21 13:02   ` Jani Nikula
2019-11-21 13:02     ` [Intel-gfx] " Jani Nikula
2019-11-22 13:49   ` Ville Syrjälä
2019-11-22 13:49     ` [Intel-gfx] " Ville Syrjälä
2019-11-20 23:46 ` [PATCH 3/3] drm/i915/i915: assume vbt is 4-byte aligned into oprom Lucas De Marchi
2019-11-20 23:46   ` [Intel-gfx] " Lucas De Marchi
2019-11-21 13:09   ` Jani Nikula
2019-11-21 13:09     ` [Intel-gfx] " Jani Nikula
2019-11-21 18:54     ` Lucas De Marchi
2019-11-21 18:54       ` [Intel-gfx] " Lucas De Marchi
2019-11-22 13:55       ` Ville Syrjälä
2019-11-22 13:55         ` [Intel-gfx] " Ville Syrjälä
2019-11-25 17:43         ` Lucas De Marchi
2019-11-25 17:43           ` [Intel-gfx] " Lucas De Marchi
2019-11-21  3:44 ` ✓ Fi.CI.BAT: success for series starting with [1/3] drm/i915/bios: do not discard address space Patchwork
2019-11-21  3:44   ` [Intel-gfx] " Patchwork
2019-11-22  5:42 ` ✗ Fi.CI.IGT: failure " Patchwork
2019-11-22  5:42   ` [Intel-gfx] " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2019-11-26 22:51 [PATCH 0/3] bios: dot " Lucas De Marchi
2019-11-26 22:51 ` [PATCH 2/3] drm/i915/bios: fold pci rom map/unmap into copy function Lucas De Marchi
2019-11-15 23:35 [PATCH 1/3] drm/i915/bios: do not discard address space Lucas De Marchi
2019-11-15 23:35 ` [PATCH 2/3] drm/i915/bios: fold pci rom map/unmap into copy function Lucas De Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox