diff mbox

[1/2,v2,addendum,v2] drm/i915: Allow parsing of variable size child device entries from VBT

Message ID 20150813131415.GO6150@boom (mailing list archive)
State New, archived
Headers show

Commit Message

David Weinehall Aug. 13, 2015, 1:14 p.m. UTC
On Wed, Aug 12, 2015 at 05:19:35PM +0300, Jani Nikula wrote:
> On Wed, 12 Aug 2015, David Weinehall <david.weinehall@linux.intel.com> wrote:
> > Some more fixup is needed; the bits from Antti's patch
> > that actually expanded the struct to fully fit the newer
> > versions of the child_device_config was part of the second
> > patch; since that patch hasn't been merged yet we need this bit:
> >
> > This applies on top of the patch you already merged
> > (the Iboost patch will need corresponding adjustment to
> >  remove the changes I split out):
> >
> > Expand common_child_dev_config to be able to fit all information
> > defined by the latest VBT specification.
> >
> > Signed-off-by: David Weinehall <david.weinehall@linux.intel.com>
> > CC: Antti Koskipaa <antti.koskipaa@linux.intel.com>
> > ---
> >  intel_bios.c |    7 ++++++-
> >  intel_bios.h |    4 ++++
> >  2 files changed, 10 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
> > index 990acc20771a..40e2cc4e7419 100644
> > --- a/drivers/gpu/drm/i915/intel_bios.c
> > +++ b/drivers/gpu/drm/i915/intel_bios.c
> > @@ -1038,6 +1038,10 @@ parse_device_mapping(struct drm_i915_private *dev_priv,
> >  		DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
> >  		return;
> >  	}
> > +	/* Remember to keep this in sync with child_device_config;
> > +	 * whenever a new feature is added to BDB that causes that
> > +	 * struct to grow this needs to be updated too
> > +	 */
> >  	if (bdb->version < 195) {
> >  		expected_size = 33;
> >  	} else if (bdb->version == 195) {
> > @@ -1051,7 +1055,8 @@ parse_device_mapping(struct drm_i915_private *dev_priv,
> >  	}
> >  
> >  	if (expected_size > sizeof(*p_child)) {
> > -		DRM_ERROR("child_device_config cannot fit in p_child\n");
> > +		DRM_ERROR("child_device_config (size %u) cannot fit in p_child (size %u); bdb->version: %u\n",
> > +			  expected_size, sizeof(*p_child), bdb->version);
> 
> drivers/gpu/drm/i915/intel_bios.c: In function ‘parse_device_mapping’:
> drivers/gpu/drm/i915/intel_bios.c:1058:3: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 3 has type ‘long unsigned int’ [-Wformat=]
>    DRM_ERROR("child_device_config (size %u) cannot fit in p_child (size %u); bdb->version: %u\n",
>    ^
>   CC [M]  drivers/gpu/drm/i915/intel_fifo_underrun.o

Well spotted.  Or rather, stupid of me to forget that sizeof yields
size_t as type, thus necessitating %zu as conversion specifier.

Fixed version:

Expand common_child_dev_config to be able to fit all information
defined by the latest VBT specification.

v2: Use proper conversion specifier for size_t (%zu)

Signed-off-by: David Weinehall <david.weinehall@linux.intel.com>
CC: Antti Koskipaa <antti.koskipaa@linux.intel.com>

 intel_bios.c |    7 ++++++-
 intel_bios.h |    4 ++++
 2 files changed, 10 insertions(+), 1 deletion(-)

Comments

Timo Aaltonen Aug. 14, 2015, 8:07 a.m. UTC | #1
On 13.08.2015 16:14, David Weinehall wrote:
> On Wed, Aug 12, 2015 at 05:19:35PM +0300, Jani Nikula wrote:
>> On Wed, 12 Aug 2015, David Weinehall <david.weinehall@linux.intel.com> wrote:
>>> Some more fixup is needed; the bits from Antti's patch
>>> that actually expanded the struct to fully fit the newer
>>> versions of the child_device_config was part of the second
>>> patch; since that patch hasn't been merged yet we need this bit:
>>>
>>> This applies on top of the patch you already merged
>>> (the Iboost patch will need corresponding adjustment to
>>>  remove the changes I split out):
>>>
>>> Expand common_child_dev_config to be able to fit all information
>>> defined by the latest VBT specification.
>>>
>>> Signed-off-by: David Weinehall <david.weinehall@linux.intel.com>
>>> CC: Antti Koskipaa <antti.koskipaa@linux.intel.com>
>>> ---
>>>  intel_bios.c |    7 ++++++-
>>>  intel_bios.h |    4 ++++
>>>  2 files changed, 10 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
>>> index 990acc20771a..40e2cc4e7419 100644
>>> --- a/drivers/gpu/drm/i915/intel_bios.c
>>> +++ b/drivers/gpu/drm/i915/intel_bios.c
>>> @@ -1038,6 +1038,10 @@ parse_device_mapping(struct drm_i915_private *dev_priv,
>>>  		DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
>>>  		return;
>>>  	}
>>> +	/* Remember to keep this in sync with child_device_config;
>>> +	 * whenever a new feature is added to BDB that causes that
>>> +	 * struct to grow this needs to be updated too
>>> +	 */
>>>  	if (bdb->version < 195) {
>>>  		expected_size = 33;
>>>  	} else if (bdb->version == 195) {
>>> @@ -1051,7 +1055,8 @@ parse_device_mapping(struct drm_i915_private *dev_priv,
>>>  	}
>>>  
>>>  	if (expected_size > sizeof(*p_child)) {
>>> -		DRM_ERROR("child_device_config cannot fit in p_child\n");
>>> +		DRM_ERROR("child_device_config (size %u) cannot fit in p_child (size %u); bdb->version: %u\n",
>>> +			  expected_size, sizeof(*p_child), bdb->version);
>>
>> drivers/gpu/drm/i915/intel_bios.c: In function ‘parse_device_mapping’:
>> drivers/gpu/drm/i915/intel_bios.c:1058:3: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 3 has type ‘long unsigned int’ [-Wformat=]
>>    DRM_ERROR("child_device_config (size %u) cannot fit in p_child (size %u); bdb->version: %u\n",
>>    ^
>>   CC [M]  drivers/gpu/drm/i915/intel_fifo_underrun.o
> 
> Well spotted.  Or rather, stupid of me to forget that sizeof yields
> size_t as type, thus necessitating %zu as conversion specifier.
> 
> Fixed version:
> 
> Expand common_child_dev_config to be able to fit all information
> defined by the latest VBT specification.
> 
> v2: Use proper conversion specifier for size_t (%zu)
> 
> Signed-off-by: David Weinehall <david.weinehall@linux.intel.com>
> CC: Antti Koskipaa <antti.koskipaa@linux.intel.com>
> 
>  intel_bios.c |    7 ++++++-
>  intel_bios.h |    4 ++++
>  2 files changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
> index 990acc20771a..5673ed53797b 100644
> --- a/drivers/gpu/drm/i915/intel_bios.c
> +++ b/drivers/gpu/drm/i915/intel_bios.c
> @@ -1038,6 +1038,10 @@ parse_device_mapping(struct drm_i915_private *dev_priv,
>  		DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
>  		return;
>  	}
> +	/* Remember to keep this in sync with child_device_config;
> +	 * whenever a new feature is added to BDB that causes that
> +	 * struct to grow this needs to be updated too
> +	 */
>  	if (bdb->version < 195) {
>  		expected_size = 33;
>  	} else if (bdb->version == 195) {
> @@ -1051,7 +1055,8 @@ parse_device_mapping(struct drm_i915_private *dev_priv,
>  	}
>  
>  	if (expected_size > sizeof(*p_child)) {
> -		DRM_ERROR("child_device_config cannot fit in p_child\n");
> +		DRM_ERROR("child_device_config (size %u) cannot fit in p_child (size %zu); bdb->version: %u\n",
> +			  expected_size, sizeof(*p_child), bdb->version);
>  		return;
>  	}
>  
> diff --git a/drivers/gpu/drm/i915/intel_bios.h b/drivers/gpu/drm/i915/intel_bios.h
> index f7ad6a585129..71cb96f77870 100644
> --- a/drivers/gpu/drm/i915/intel_bios.h
> +++ b/drivers/gpu/drm/i915/intel_bios.h
> @@ -239,6 +239,10 @@ struct common_child_dev_config {
>  	u8 not_common2[2];
>  	u8 ddc_pin;
>  	u16 edid_ptr;
> +	u8 obsolete;
> +	u8 flags_1;
> +	u8 not_common3[13];
> +	u8 iboost_level;
>  } __packed;
>  
>  /* This field changes depending on the BDB version, so the most reliable way to

Please apply this, fixes issues on some machine(s) here. Probably also
cc:stable since it applies to BSW as well as SKL.

and the upstream bug could be referenced too, it's
https://bugs.freedesktop.org/show_bug.cgi?id=91613
Jani Nikula Aug. 14, 2015, 8:42 a.m. UTC | #2
On Thu, 13 Aug 2015, David Weinehall <david.weinehall@linux.intel.com> wrote:
> On Wed, Aug 12, 2015 at 05:19:35PM +0300, Jani Nikula wrote:
>> On Wed, 12 Aug 2015, David Weinehall <david.weinehall@linux.intel.com> wrote:
>> > Some more fixup is needed; the bits from Antti's patch
>> > that actually expanded the struct to fully fit the newer
>> > versions of the child_device_config was part of the second
>> > patch; since that patch hasn't been merged yet we need this bit:
>> >
>> > This applies on top of the patch you already merged
>> > (the Iboost patch will need corresponding adjustment to
>> >  remove the changes I split out):
>> >
>> > Expand common_child_dev_config to be able to fit all information
>> > defined by the latest VBT specification.
>> >
>> > Signed-off-by: David Weinehall <david.weinehall@linux.intel.com>
>> > CC: Antti Koskipaa <antti.koskipaa@linux.intel.com>
>> > ---
>> >  intel_bios.c |    7 ++++++-
>> >  intel_bios.h |    4 ++++
>> >  2 files changed, 10 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
>> > index 990acc20771a..40e2cc4e7419 100644
>> > --- a/drivers/gpu/drm/i915/intel_bios.c
>> > +++ b/drivers/gpu/drm/i915/intel_bios.c
>> > @@ -1038,6 +1038,10 @@ parse_device_mapping(struct drm_i915_private *dev_priv,
>> >  		DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
>> >  		return;
>> >  	}
>> > +	/* Remember to keep this in sync with child_device_config;
>> > +	 * whenever a new feature is added to BDB that causes that
>> > +	 * struct to grow this needs to be updated too
>> > +	 */
>> >  	if (bdb->version < 195) {
>> >  		expected_size = 33;
>> >  	} else if (bdb->version == 195) {
>> > @@ -1051,7 +1055,8 @@ parse_device_mapping(struct drm_i915_private *dev_priv,
>> >  	}
>> >  
>> >  	if (expected_size > sizeof(*p_child)) {
>> > -		DRM_ERROR("child_device_config cannot fit in p_child\n");
>> > +		DRM_ERROR("child_device_config (size %u) cannot fit in p_child (size %u); bdb->version: %u\n",
>> > +			  expected_size, sizeof(*p_child), bdb->version);
>> 
>> drivers/gpu/drm/i915/intel_bios.c: In function ‘parse_device_mapping’:
>> drivers/gpu/drm/i915/intel_bios.c:1058:3: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 3 has type ‘long unsigned int’ [-Wformat=]
>>    DRM_ERROR("child_device_config (size %u) cannot fit in p_child (size %u); bdb->version: %u\n",
>>    ^
>>   CC [M]  drivers/gpu/drm/i915/intel_fifo_underrun.o
>
> Well spotted.  Or rather, stupid of me to forget that sizeof yields
> size_t as type, thus necessitating %zu as conversion specifier.
>
> Fixed version:
>
> Expand common_child_dev_config to be able to fit all information
> defined by the latest VBT specification.
>
> v2: Use proper conversion specifier for size_t (%zu)
>
> Signed-off-by: David Weinehall <david.weinehall@linux.intel.com>
> CC: Antti Koskipaa <antti.koskipaa@linux.intel.com>
>
>  intel_bios.c |    7 ++++++-
>  intel_bios.h |    4 ++++
>  2 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
> index 990acc20771a..5673ed53797b 100644
> --- a/drivers/gpu/drm/i915/intel_bios.c
> +++ b/drivers/gpu/drm/i915/intel_bios.c
> @@ -1038,6 +1038,10 @@ parse_device_mapping(struct drm_i915_private *dev_priv,
>  		DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
>  		return;
>  	}
> +	/* Remember to keep this in sync with child_device_config;
> +	 * whenever a new feature is added to BDB that causes that
> +	 * struct to grow this needs to be updated too
> +	 */
>  	if (bdb->version < 195) {
>  		expected_size = 33;
>  	} else if (bdb->version == 195) {
> @@ -1051,7 +1055,8 @@ parse_device_mapping(struct drm_i915_private *dev_priv,
>  	}
>  
>  	if (expected_size > sizeof(*p_child)) {
> -		DRM_ERROR("child_device_config cannot fit in p_child\n");
> +		DRM_ERROR("child_device_config (size %u) cannot fit in p_child (size %zu); bdb->version: %u\n",
> +			  expected_size, sizeof(*p_child), bdb->version);
>  		return;
>  	}
>  
> diff --git a/drivers/gpu/drm/i915/intel_bios.h b/drivers/gpu/drm/i915/intel_bios.h
> index f7ad6a585129..71cb96f77870 100644
> --- a/drivers/gpu/drm/i915/intel_bios.h
> +++ b/drivers/gpu/drm/i915/intel_bios.h
> @@ -239,6 +239,10 @@ struct common_child_dev_config {
>  	u8 not_common2[2];
>  	u8 ddc_pin;
>  	u16 edid_ptr;
> +	u8 obsolete;
> +	u8 flags_1;
> +	u8 not_common3[13];
> +	u8 iboost_level;

How does this impact the if (p_defs->child_dev_size != sizeof(*p_child))
check in parse_sdvo_device_mapping()?

BR,
Jani.

>  } __packed;
>  
>  /* This field changes depending on the BDB version, so the most reliable way to
Jani Nikula Aug. 14, 2015, 9:40 a.m. UTC | #3
On Fri, 14 Aug 2015, Jani Nikula <jani.nikula@linux.intel.com> wrote:
> On Thu, 13 Aug 2015, David Weinehall <david.weinehall@linux.intel.com> wrote:
>> On Wed, Aug 12, 2015 at 05:19:35PM +0300, Jani Nikula wrote:
>>> On Wed, 12 Aug 2015, David Weinehall <david.weinehall@linux.intel.com> wrote:
>>> > Some more fixup is needed; the bits from Antti's patch
>>> > that actually expanded the struct to fully fit the newer
>>> > versions of the child_device_config was part of the second
>>> > patch; since that patch hasn't been merged yet we need this bit:
>>> >
>>> > This applies on top of the patch you already merged
>>> > (the Iboost patch will need corresponding adjustment to
>>> >  remove the changes I split out):
>>> >
>>> > Expand common_child_dev_config to be able to fit all information
>>> > defined by the latest VBT specification.
>>> >
>>> > Signed-off-by: David Weinehall <david.weinehall@linux.intel.com>
>>> > CC: Antti Koskipaa <antti.koskipaa@linux.intel.com>
>>> > ---
>>> >  intel_bios.c |    7 ++++++-
>>> >  intel_bios.h |    4 ++++
>>> >  2 files changed, 10 insertions(+), 1 deletion(-)
>>> >
>>> > diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
>>> > index 990acc20771a..40e2cc4e7419 100644
>>> > --- a/drivers/gpu/drm/i915/intel_bios.c
>>> > +++ b/drivers/gpu/drm/i915/intel_bios.c
>>> > @@ -1038,6 +1038,10 @@ parse_device_mapping(struct drm_i915_private *dev_priv,
>>> >  		DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
>>> >  		return;
>>> >  	}
>>> > +	/* Remember to keep this in sync with child_device_config;
>>> > +	 * whenever a new feature is added to BDB that causes that
>>> > +	 * struct to grow this needs to be updated too
>>> > +	 */
>>> >  	if (bdb->version < 195) {
>>> >  		expected_size = 33;
>>> >  	} else if (bdb->version == 195) {
>>> > @@ -1051,7 +1055,8 @@ parse_device_mapping(struct drm_i915_private *dev_priv,
>>> >  	}
>>> >  
>>> >  	if (expected_size > sizeof(*p_child)) {
>>> > -		DRM_ERROR("child_device_config cannot fit in p_child\n");
>>> > +		DRM_ERROR("child_device_config (size %u) cannot fit in p_child (size %u); bdb->version: %u\n",
>>> > +			  expected_size, sizeof(*p_child), bdb->version);
>>> 
>>> drivers/gpu/drm/i915/intel_bios.c: In function ‘parse_device_mapping’:
>>> drivers/gpu/drm/i915/intel_bios.c:1058:3: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 3 has type ‘long unsigned int’ [-Wformat=]
>>>    DRM_ERROR("child_device_config (size %u) cannot fit in p_child (size %u); bdb->version: %u\n",
>>>    ^
>>>   CC [M]  drivers/gpu/drm/i915/intel_fifo_underrun.o
>>
>> Well spotted.  Or rather, stupid of me to forget that sizeof yields
>> size_t as type, thus necessitating %zu as conversion specifier.
>>
>> Fixed version:
>>
>> Expand common_child_dev_config to be able to fit all information
>> defined by the latest VBT specification.
>>
>> v2: Use proper conversion specifier for size_t (%zu)
>>
>> Signed-off-by: David Weinehall <david.weinehall@linux.intel.com>
>> CC: Antti Koskipaa <antti.koskipaa@linux.intel.com>
>>
>>  intel_bios.c |    7 ++++++-
>>  intel_bios.h |    4 ++++
>>  2 files changed, 10 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
>> index 990acc20771a..5673ed53797b 100644
>> --- a/drivers/gpu/drm/i915/intel_bios.c
>> +++ b/drivers/gpu/drm/i915/intel_bios.c
>> @@ -1038,6 +1038,10 @@ parse_device_mapping(struct drm_i915_private *dev_priv,
>>  		DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
>>  		return;
>>  	}
>> +	/* Remember to keep this in sync with child_device_config;
>> +	 * whenever a new feature is added to BDB that causes that
>> +	 * struct to grow this needs to be updated too
>> +	 */
>>  	if (bdb->version < 195) {
>>  		expected_size = 33;
>>  	} else if (bdb->version == 195) {
>> @@ -1051,7 +1055,8 @@ parse_device_mapping(struct drm_i915_private *dev_priv,
>>  	}
>>  
>>  	if (expected_size > sizeof(*p_child)) {
>> -		DRM_ERROR("child_device_config cannot fit in p_child\n");
>> +		DRM_ERROR("child_device_config (size %u) cannot fit in p_child (size %zu); bdb->version: %u\n",
>> +			  expected_size, sizeof(*p_child), bdb->version);
>>  		return;
>>  	}
>>  
>> diff --git a/drivers/gpu/drm/i915/intel_bios.h b/drivers/gpu/drm/i915/intel_bios.h
>> index f7ad6a585129..71cb96f77870 100644
>> --- a/drivers/gpu/drm/i915/intel_bios.h
>> +++ b/drivers/gpu/drm/i915/intel_bios.h
>> @@ -239,6 +239,10 @@ struct common_child_dev_config {
>>  	u8 not_common2[2];
>>  	u8 ddc_pin;
>>  	u16 edid_ptr;
>> +	u8 obsolete;
>> +	u8 flags_1;
>> +	u8 not_common3[13];
>> +	u8 iboost_level;
>
> How does this impact the if (p_defs->child_dev_size != sizeof(*p_child))
> check in parse_sdvo_device_mapping()?

Ugh. What a mess the whole child device parsing is.

What's really broken in the current code is *assuming* some expected
size for future versions, *and* then refusing to parse if the child dev
size has grown. We should just parse *up to* min(VBT reported child dev
size, the biggest child dev we know about). The current code keeps us
doing busywork whenever someone decides to add a field at the end.

Side note, we have *two* functions and loops iterating child
devices. One for new stuff and another for old stuff. Yay.

BR,
Jani.


>
> BR,
> Jani.
>
>>  } __packed;
>>  
>>  /* This field changes depending on the BDB version, so the most reliable way to
>
> -- 
> Jani Nikula, Intel Open Source Technology Center
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
index 990acc20771a..5673ed53797b 100644
--- a/drivers/gpu/drm/i915/intel_bios.c
+++ b/drivers/gpu/drm/i915/intel_bios.c
@@ -1038,6 +1038,10 @@  parse_device_mapping(struct drm_i915_private *dev_priv,
 		DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
 		return;
 	}
+	/* Remember to keep this in sync with child_device_config;
+	 * whenever a new feature is added to BDB that causes that
+	 * struct to grow this needs to be updated too
+	 */
 	if (bdb->version < 195) {
 		expected_size = 33;
 	} else if (bdb->version == 195) {
@@ -1051,7 +1055,8 @@  parse_device_mapping(struct drm_i915_private *dev_priv,
 	}
 
 	if (expected_size > sizeof(*p_child)) {
-		DRM_ERROR("child_device_config cannot fit in p_child\n");
+		DRM_ERROR("child_device_config (size %u) cannot fit in p_child (size %zu); bdb->version: %u\n",
+			  expected_size, sizeof(*p_child), bdb->version);
 		return;
 	}
 
diff --git a/drivers/gpu/drm/i915/intel_bios.h b/drivers/gpu/drm/i915/intel_bios.h
index f7ad6a585129..71cb96f77870 100644
--- a/drivers/gpu/drm/i915/intel_bios.h
+++ b/drivers/gpu/drm/i915/intel_bios.h
@@ -239,6 +239,10 @@  struct common_child_dev_config {
 	u8 not_common2[2];
 	u8 ddc_pin;
 	u16 edid_ptr;
+	u8 obsolete;
+	u8 flags_1;
+	u8 not_common3[13];
+	u8 iboost_level;
 } __packed;
 
 /* This field changes depending on the BDB version, so the most reliable way to