intel/pinctrl: check some registers reads
Subsystems (3)
v2 cover intel/pinctrl: check some registers reads
Hello,
The following series adds some consistency checks to the values returned by some of the MMIO registers of the Intel pinctrl device.
That done to avoid a crash when running as a PVH dom0. See patch #1 for more details.
Thanks, Roger.
Roger Pau Monne (2):
intel/pinctrl: check REVID register value for device presence intel/pinctrl: check capability offset is between MMIO region
drivers/pinctrl/intel/pinctrl-intel.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
Signature · 1 line
2.30.1
PATCH v2 1/2 intel/pinctrl: check REVID register value for device presence
Use the value read from the REVID register in order to check for the presence of the device. A read of all ones is treated as if the device is not present, and hence probing is ended.
This fixes an issue when running as a Xen PVH dom0, where the ACPI DSDT table is provided unmodified to dom0 and hence contains the pinctrl devices, but the MMIO region(s) containing the device registers might not be mapped in the guest physical memory map if such region(s) are not exposed on a PCI device BAR or marked as reserved in the host memory map.
---
Changes since v1:
- New in this version.
---
Cc: Mika Westerberg <[email protected]>
Cc: Andy Shevchenko <[email protected]>
Cc: Linus Walleij <[email protected]>
Cc: [email protected]
--- drivers/pinctrl/intel/pinctrl-intel.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/pinctrl/intel/pinctrl-intel.c +2 -0
@@ -1493,6 +1493,8 @@ static int intel_pinctrl_probe(struct platform_device *pdev,/* Determine community features based on the revision */ value =readl (regs +REVID ); +if (value == ~0u ) +return -ENODATA ;if (((value &REVID_MASK ) >>REVID_SHIFT ) >=0x94 ) { community->features |=PINCTRL_FEATURE_DEBOUNCE ; community->features |=PINCTRL_FEATURE_1K_PD ;
Signature · 1 line
2.30.1
Re: [PATCH v2 1/2] intel/pinctrl: check REVID register value for device presence
On Wed, Mar 24, 2021 at 04:43:11PM +0100, Roger Pau Monne wrote:
Thanks for a fix! My comments below.
Quoted 10 lines
Use the value read from the REVID register in order to check for the presence of the device. A read of all ones is treated as if the device is not present, and hence probing is ended.
This fixes an issue when running as a Xen PVH dom0, where the ACPI DSDT table is provided unmodified to dom0 and hence contains the pinctrl devices, but the MMIO region(s) containing the device registers might not be mapped in the guest physical memory map if such region(s) are not exposed on a PCI device BAR or marked as reserved in the host memory map.
Any particular point that we can use in the Fixes tag?
...
Quoted 1 line
Suggested-by Andy Shevchenko <[email protected]>
Hmm... was it that address I have used? In any case I think my @linux.intel.com is better.
...
drivers/pinctrl/intel/pinctrl-intel.c static int intel_pinctrl_probe(struct platform_device *pdev, · line 1497
Quoted 4 lines
drivers/pinctrl/intel/pinctrl-intel.c +2
-0/* Determine community features based on the revision */ value =readl (regs +REVID ); +if (value == ~0u ) +return -ENODATA ;
I think -ENODEV is more appropriate here.
Also comment above should be adjusted to explain this check.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 1/2] intel/pinctrl: check REVID register value for device presence
Quoted 8 lines · Andy Shevchenko
On Wed, Mar 24, 2021 at 04:43:11PM +0100, Roger Pau Monne wrote:
Thanks for a fix! My comments below.
Quoted 4 lines
Use the value read from the REVID register in order to check for the presence of the device. A read of all ones is treated as if the device is not present, and hence probing is ended.
Quoted 8 lines
Quoted 6 lines
This fixes an issue when running as a Xen PVH dom0, where the ACPI DSDT table is provided unmodified to dom0 and hence contains the pinctrl devices, but the MMIO region(s) containing the device registers might not be mapped in the guest physical memory map if such region(s) are not exposed on a PCI device BAR or marked as reserved in the host memory map.
Any particular point that we can use in the Fixes tag?
Hm, I haven't seen those issues up until 91d898e51e60 ('pinctrl:
intel: Convert capability list to features'), but the device wasn't working properly for sure, as the registers where not accessible, it just didn't lead to a kernel crash.
Quoted 6 lines
...
Quoted 1 line
Suggested-by Andy Shevchenko <[email protected]>Hmm... was it that address I have used? In any case I think my @linux.intel.com is better.
I just used the same as the one that's on the MAINTAINERS file, because I already had that n my Cc list. I can change to the @intel one if that's your preference.
Quoted 9 lines
...
drivers/pinctrl/intel/pinctrl-intel.c static int intel_pinctrl_probe(struct platform_device *pdev, · line 1497
Quoted 4 lines
drivers/pinctrl/intel/pinctrl-intel.c +2
-0/* Determine community features based on the revision */ value =readl (regs +REVID ); +if (value == ~0u ) +return -ENODATA ;I think
-ENODEVis more appropriate here.
Also comment above should be adjusted to explain this check.
Right, will change and send v3.
Thanks.
PATCH v2 2/2 intel/pinctrl: check capability offset is between MMIO region
In reply to Roger Pau MonneWhen parsing the capability list make sure the offset is between the MMIO region mapped in 'regs', or else the kernel hits a page fault.
Adding the check is harmless, and prevents buggy or broken systems from crashing the kernel if the capability linked list is somehow broken.
---
Changes since v1:
- Adjust commit message.
---
Cc: Mika Westerberg <[email protected]>
Cc: Andy Shevchenko <[email protected]>
Cc: Linus Walleij <[email protected]>
Cc: [email protected]
--- drivers/pinctrl/intel/pinctrl-intel.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/pinctrl/intel/pinctrl-intel.c +13 -1
@@ -1481,16 +1481,22 @@ static int intel_pinctrl_probe(struct platform_device *pdev,for (i =0 ; i < pctrl->ncommunities; i++) {struct intel_community *community = &pctrl->communities[i]; +struct resource *res;void __iomem *regs; +size_t size;u32 offset;u32 value; *community = pctrl->soc->communities[i]; - regs =devm_platform_ioremap_resource (pdev, community->barno); + regs =devm_platform_get_and_ioremap_resource (pdev, + community->barno, + &res);if (IS_ERR (regs))return PTR_ERR (regs); + size = res->end - res->start; +/* Determine community features based on the revision */ value =readl (regs +REVID );if (value == ~0u )
@@ -1521,6 +1527,12 @@ static int intel_pinctrl_probe(struct platform_device *pdev,break ; } offset = (value &CAPLIST_NEXT_MASK ) >>CAPLIST_NEXT_SHIFT ; +if (offset >= size) { +dev_err (&pdev->dev, +"wrong capability offset: %#x\n" , + offset); +return -ENOENT ; + } }while (offset);dev_dbg (&pdev->dev,"Community%d features: %#08x\n" , i, community->features);
Signature · 1 line
2.30.1
Re: [PATCH v2 2/2] intel/pinctrl: check capability offset is between MMIO region
Quoted 6 lines · Roger Pau Monne
When parsing the capability list make sure the offset is between the MMIO region mapped in 'regs', or else the kernel hits a page fault.
Adding the check is harmless, and prevents buggy or broken systems from crashing the kernel if the capability linked list is somehow broken.
I don't think we need a dead code in the kernel. If you have a hardware to show this issue, I eagerly want to know this!
Signature · 2 lines
With Best Regards, Andy Shevchenko