Skip to contentSkip to conversation

IS_ERR_VALUE failing on socfpga gen5

U-Boot Simon Goldschmidt 2 participants 8 messages Oct 8, 2019 – Oct 14, 2019

lore
Share & tools
lore
#0 lore raw

In a series I'm currently preparing, I've stumbled accross the fact that IS_ERR_VALUE() doesn't reliably work on socfpga SPL as the onchip SRAM begins at 0xffff0000 and the heap is at the end of the 32 bit range.

Being like that, the current test for error (value >= -4095) which equals 'value >= 0xfffff001' would require us to waste the last 4K of that memory, which is not an option when it comes to using DM in SPL...

Now on this platform, I'm sure I could find a range of 4096 bytes to use as invalid pointer range, but the question is: how do I integrate that into U-Boot in a clean manner? Would it be acceptable to change the error headers imported from Linux or would I have to through the hassle of changing Linux first?

Or does anyone have a better idea to allow using the last 4K for heap?

Regards,
Simon

#1 lore raw

Hi Simon,

Quoted 5 lines · Simon Goldschmidt

In a series I'm currently preparing, I've stumbled accross the fact that IS_ERR_VALUE() doesn't reliably work on socfpga SPL as the onchip SRAM begins at 0xffff0000 and the heap is at the end of the 32 bit range.

Which function is returning that address?

Quoted 11 lines

Being like that, the current test for error (value >= -4095) which equals 'value >= 0xfffff001' would require us to waste the last 4K of that memory, which is not an option when it comes to using DM in SPL...

Now on this platform, I'm sure I could find a range of 4096 bytes to use as invalid pointer range, but the question is: how do I integrate that into U-Boot in a clean manner? Would it be acceptable to change the error headers imported from Linux or would I have to through the hassle of changing Linux first?

Or does anyone have a better idea to allow using the last 4K for heap?

Regards,
Simon

#2 lore raw

Simon Glass <[email protected]> schrieb am Fr., 11. Okt. 2019, 20:27:

Quoted 5 lines

Hi Simon,

Quoted 1 line · Simon Goldschmidt
Quoted 7 lines
Quoted 4 lines

In a series I'm currently preparing, I've stumbled accross the fact that IS_ERR_VALUE() doesn't reliably work on socfpga SPL as the onchip SRAM begins at 0xffff0000 and the heap is at the end of the 32 bit range.

Which function is returning that address?

Sorry, I don't know right now and it was kind of hard to debug. But it was somewhere in the DM initialization of new drivers I was adding. One of those functions returned a heap pointer that was interpreted as an error due to the address being in the range regarded as "error pointer"...

Regards,
Simon

Quoted 15 lines
Quoted 11 lines

Being like that, the current test for error (value >= -4095) which equals 'value >= 0xfffff001' would require us to waste the last 4K of that memory, which is not an option when it comes to using DM in SPL...

Now on this platform, I'm sure I could find a range of 4096 bytes to use as invalid pointer range, but the question is: how do I integrate that into U-Boot in a clean manner? Would it be acceptable to change the error headers imported from Linux or would I have to through the hassle of changing Linux first?

Or does anyone have a better idea to allow using the last 4K for heap?

Regards,
Simon

#3 lore raw

Hi Simon,

Quoted 15 lines · Simon Goldschmidt

Simon Glass <[email protected]> schrieb am Fr., 11. Okt. 2019, 20:27:

Quoted 11 lines

Hi Simon,

Quoted 5 lines · Simon Goldschmidt

In a series I'm currently preparing, I've stumbled accross the fact that IS_ERR_VALUE() doesn't reliably work on socfpga SPL as the onchip SRAM begins at 0xffff0000 and the heap is at the end of the 32 bit range.

Quoted 4 lines
Quoted 1 line

Which function is returning that address?

Sorry, I don't know right now and it was kind of hard to debug. But it was somewhere in the DM initialization of new drivers I was adding. One of those functions returned a heap pointer that was interpreted as an error due to the address being in the range regarded as "error pointer"...

I don't know a good solution to this. But we should consider changing whatever API it was to use an int return value instead of an address. The address can be passed back in another parameter. That is how most uclass methods work.

Regards,
Simon

#4 lore raw

Am 12.10.2019 um 00:11 schrieb Simon Glass:

Quoted 22 lines

Hi Simon,

Quoted 18 lines · Simon Goldschmidt

Simon Glass <[email protected]> schrieb am Fr., 11. Okt. 2019, 20:27:

Quoted 12 lines

Hi Simon,

Quoted 5 lines · Simon Goldschmidt

In a series I'm currently preparing, I've stumbled accross the fact that IS_ERR_VALUE() doesn't reliably work on socfpga SPL as the onchip SRAM begins at 0xffff0000 and the heap is at the end of the 32 bit range.

Which function is returning that address?

Quoted 6 lines
Quoted 1 line

Sorry, I don't know right now and it was kind of hard to debug. But it was somewhere in the DM initialization of new drivers I was adding. One of those functions returned a heap pointer that was interpreted as an error due to the address being in the range regarded as "error pointer"...

I don't know a good solution to this. But we should consider changing whatever API it was to use an int return value instead of an address. The address can be passed back in another parameter. That is how most uclass methods work.

Digging into this again, it was 'syscon_node_to_regmap', which seems to be copied from Linux, so I don't think it's feasible to change this function. Also, IS_ERR() is used in ~120 files, I wouldn't want to change all these for socfpga.

One idea that came to mind was to change the ERR_PTR/PTR_ERR macros in linux/err.h to convert errors to an architecture-specified pointer range instead of just converting the data type. However, that would mean another change to Linux imports, and Tom just seemed a little opposed to that...?

Tom?

Regards,
Simon

Quoted 4 lines

Regards,
Simon

#5 lore raw

Hi Simon,

Quoted 36 lines · Simon Goldschmidt

Am 12.10.2019 um 00:11 schrieb Simon Glass:

Quoted 22 lines

Hi Simon,

Quoted 18 lines · Simon Goldschmidt

Simon Glass <[email protected]> schrieb am Fr., 11. Okt. 2019, 20:27:

Quoted 12 lines

Hi Simon,

Quoted 5 lines · Simon Goldschmidt

In a series I'm currently preparing, I've stumbled accross the fact that IS_ERR_VALUE() doesn't reliably work on socfpga SPL as the onchip SRAM begins at 0xffff0000 and the heap is at the end of the 32 bit range.

Which function is returning that address?

Quoted 6 lines
Quoted 1 line

Sorry, I don't know right now and it was kind of hard to debug. But it was somewhere in the DM initialization of new drivers I was adding. One of those functions returned a heap pointer that was interpreted as an error due to the address being in the range regarded as "error pointer"...

I don't know a good solution to this. But we should consider changing whatever API it was to use an int return value instead of an address. The address can be passed back in another parameter. That is how most uclass methods work.

Digging into this again, it was 'syscon_node_to_regmap', which seems to be copied from Linux, so I don't think it's feasible to change this function. Also, IS_ERR() is used in ~120 files, I wouldn't want to change all these for socfpga.

Quoted 5 lines

One idea that came to mind was to change the ERR_PTR/PTR_ERR macros in linux/err.h to convert errors to an architecture-specified pointer range instead of just converting the data type. However, that would mean another change to Linux imports, and Tom just seemed a little opposed to that...?

I think we should keep it simple and change syscon_node_to_regmap() to return an int. It's an easy change affecting 17 files and avoids the problem.

Quoted 2 lines

Tom?

Regards,
Simon

#6 lore raw

Am 14.10.2019 um 22:02 schrieb Simon Glass:

Quoted 46 lines

Hi Simon,

Quoted 36 lines · Simon Goldschmidt

Am 12.10.2019 um 00:11 schrieb Simon Glass:

Quoted 22 lines

Hi Simon,

Quoted 18 lines · Simon Goldschmidt

Simon Glass <[email protected]> schrieb am Fr., 11. Okt. 2019, 20:27:

Quoted 12 lines

Hi Simon,

Quoted 5 lines · Simon Goldschmidt

In a series I'm currently preparing, I've stumbled accross the fact that IS_ERR_VALUE() doesn't reliably work on socfpga SPL as the onchip SRAM begins at 0xffff0000 and the heap is at the end of the 32 bit range.

Which function is returning that address?

Quoted 6 lines
Quoted 1 line

Sorry, I don't know right now and it was kind of hard to debug. But it was somewhere in the DM initialization of new drivers I was adding. One of those functions returned a heap pointer that was interpreted as an error due to the address being in the range regarded as "error pointer"...

I don't know a good solution to this. But we should consider changing whatever API it was to use an int return value instead of an address. The address can be passed back in another parameter. That is how most uclass methods work.

Digging into this again, it was 'syscon_node_to_regmap', which seems to be copied from Linux, so I don't think it's feasible to change this function. Also, IS_ERR() is used in ~120 files, I wouldn't want to change all these for socfpga.

Quoted 5 lines

One idea that came to mind was to change the ERR_PTR/PTR_ERR macros in linux/err.h to convert errors to an architecture-specified pointer range instead of just converting the data type. However, that would mean another change to Linux imports, and Tom just seemed a little opposed to that...?

Quoted 3 lines

I think we should keep it simple and change syscon_node_to_regmap() to return an int. It's an easy change affecting 17 files and avoids the problem.

Well, it took me some hours to find the issue (without access to a debugger, sadly) and I'd like to save me and others from facing this again in the future. When I write the next driver, who tells me internals aren't using IS_ERR again?

Plus, linux/err.h says:

"This should be a per-architecture thing, to allow different error and pointer decisions."

Let me prepare a patch to show what I mean and we can see if it's acceptable.

Regards,
Simon

Quoted 7 lines
Quoted 3 lines

Tom?

Regards,
Simon

#7 lore raw

Hi Simon,

Quoted 57 lines · Simon Goldschmidt

Am 14.10.2019 um 22:02 schrieb Simon Glass:

Quoted 46 lines

Hi Simon,

Quoted 36 lines · Simon Goldschmidt

Am 12.10.2019 um 00:11 schrieb Simon Glass:

Quoted 22 lines

Hi Simon,

Quoted 18 lines · Simon Goldschmidt

Simon Glass <[email protected]> schrieb am Fr., 11. Okt. 2019, 20:27:

Quoted 12 lines

Hi Simon,

Quoted 5 lines · Simon Goldschmidt

In a series I'm currently preparing, I've stumbled accross the fact that IS_ERR_VALUE() doesn't reliably work on socfpga SPL as the onchip SRAM begins at 0xffff0000 and the heap is at the end of the 32 bit range.

Which function is returning that address?

Quoted 6 lines
Quoted 1 line

Sorry, I don't know right now and it was kind of hard to debug. But it was somewhere in the DM initialization of new drivers I was adding. One of those functions returned a heap pointer that was interpreted as an error due to the address being in the range regarded as "error pointer"...

I don't know a good solution to this. But we should consider changing whatever API it was to use an int return value instead of an address. The address can be passed back in another parameter. That is how most uclass methods work.

Digging into this again, it was 'syscon_node_to_regmap', which seems to be copied from Linux, so I don't think it's feasible to change this function. Also, IS_ERR() is used in ~120 files, I wouldn't want to change all these for socfpga.

Quoted 5 lines

One idea that came to mind was to change the ERR_PTR/PTR_ERR macros in linux/err.h to convert errors to an architecture-specified pointer range instead of just converting the data type. However, that would mean another change to Linux imports, and Tom just seemed a little opposed to that...?

Quoted 3 lines

I think we should keep it simple and change syscon_node_to_regmap() to return an int. It's an easy change affecting 17 files and avoids the problem.

Well, it took me some hours to find the issue (without access to a debugger, sadly) and I'd like to save me and others from facing this again in the future. When I write the next driver, who tells me internals aren't using IS_ERR again?

Quoted 7 lines

Plus, linux/err.h says:

"This should be a per-architecture thing, to allow different error and pointer decisions."

Let me prepare a patch to show what I mean and we can see if it's acceptable.

I don't think so. This is just making things confusing.

There is no need to use pointers to return errors. I know it is slightly more efficient but the pain is much greater, as you have found.

Also please check out log_msg_ret(). If you sprinkle that on all your error returns and enable logging, then you get a nice detailed error trace showing you where the problem happened. We should start trying to use that everywhere IMO.

Regards,
Simon