Re: [PATCH] platform/x86: intel_pmc_core: Do not ioremap RAM

2019-09-07 Thread Andy Shevchenko
On Fri, Aug 16, 2019 at 4:42 AM M. Vefa Bicakci  wrote:
>
> On a Xen-based PVH virtual machine with more than 4 GiB of RAM,
> intel_pmc_core fails initialization with the following warning message
> from the kernel, indicating that the driver is attempting to ioremap
> RAM:
>
>   [ cut here ]
>   ioremap on RAM at 0xfe00 - 0xfe001fff
>   WARNING: CPU: 1 PID: 434 at arch/x86/mm/ioremap.c:186 
> __ioremap_caller.constprop.0+0x2aa/0x2c0
>   Modules linked in: intel_pmc_core_pltdrv(+) xen_netfront(+) intel_pmc_core \
> crct10dif_pclmul crc32_pclmul crc32c_intel ghash_clmulni_intel \
> intel_rapl_perf pcspkr binfmt_misc u2mfn(O) xenfs xen_gntdev \
> xen_gntalloc xen_blkback xen_privcmd xen_evtchn ip_tables overlay \
> xen_blkfront
>   CPU: 1 PID: 434 Comm: systemd-udevd Tainted: G   O  
> 5.3.0-rc3-next-20190809-1 #2
>   RIP: 0010:__ioremap_caller.constprop.0+0x2aa/0x2c0
>   Code: 05 0f c9 1b 01 49 09 c6 e9 8e fe ff ff 48 8d 54 24 28 48 c7 c7 68 87 
> 0a 82 c6 05 c4 23 2b 01 01 48 8d 74 24 18 e8 d4 4a 06 00 <0f> 0b 45 31 ff e9 
> fe fe ff ff e8 e7 47 06 00 0f 1f 80 00 00 00 00
>   RSP: 0018:c92dfa20 EFLAGS: 00010282
>   RAX:  RBX: c0107000 RCX: 0006
>   RDX: 0007 RSI: 0092 RDI: 88813bb17540
>   RBP: fe00 R08: 015f R09: 000a
>   R10: 000a R11: c92df8da R12: 2000
>   R13:  R14: 0002 R15: 822da3a0
>   FS:  72ecce666940() GS:88813bb0() knlGS:
>   CS:  0010 DS:  ES:  CR0: 80050033
>   CR2: 785be7346d20 CR3: 0d872001 CR4: 003606e0
>   Call Trace:
>? pmc_core_probe+0x87/0x2d0 [intel_pmc_core]
>pmc_core_probe+0x87/0x2d0 [intel_pmc_core]
>platform_drv_probe+0x35/0x80
>really_probe+0x298/0x3c0
>driver_probe_device+0x7a/0x100
>? driver_allows_async_probing+0x50/0x50
>bus_for_each_drv+0x8f/0xd0
>__device_attach+0xf0/0x170
>bus_probe_device+0x8e/0xa0
>device_add+0x692/0x7e0
>platform_device_add+0xe9/0x240
>? 0xc00ec000
>do_one_initcall+0x59/0x214
>do_init_module+0x5c/0x230
>load_module+0x258d/0x2840
>? __do_sys_finit_module+0xbb/0x120
>__do_sys_finit_module+0xbb/0x120
>do_syscall_64+0x5f/0x1a0
>entry_SYSCALL_64_after_hwframe+0x44/0xa9
>   RIP: 0033:0x72eccf662fad
>   Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 
> 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 
> 73 01 c3 48 8b 0d ab 9e 0c 00 f7 d8 64 89 01 48
>   RSP: 002b:7ffd3710d018 EFLAGS: 0246 ORIG_RAX: 0139
>   RAX: ffda RBX: 60ab8fda2530 RCX: 72eccf662fad
>   RDX:  RSI: 72eccf2bd84d RDI: 0017
>   RBP: 0002 R08:  R09: 0007
>   R10: 0017 R11: 0246 R12: 72eccf2bd84d
>   R13:  R14: 60ab8fd9b5e0 R15: 0007
>   ---[ end trace 5e5421608729d6f4 ]---
>
> This issue appears to manifest itself because of the following fallback
> mechanism in the driver:
>
> if (lpit_read_residency_count_address(_s0_addr))
> pmcdev->base_addr = PMC_BASE_ADDR_DEFAULT;
>
> The validity of address PMC_BASE_ADDR_DEFAULT (i.e., 0xFE00) is not
> verified by the driver, which is what this patch introduces. With this
> patch, if address PMC_BASE_ADDR_DEFAULT is in RAM, then the driver will
> not attempt to ioremap the aforementioned address.
>

Pushed to my review and testing queue, thanks!

P.S. I cut unnecessary output off.

> Signed-off-by: M. Vefa Bicakci 
> ---
>  drivers/platform/x86/intel_pmc_core.c | 8 ++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/platform/x86/intel_pmc_core.c 
> b/drivers/platform/x86/intel_pmc_core.c
> index c510d0d72475..3b6b8dcc4767 100644
> --- a/drivers/platform/x86/intel_pmc_core.c
> +++ b/drivers/platform/x86/intel_pmc_core.c
> @@ -878,10 +878,14 @@ static int pmc_core_probe(struct platform_device *pdev)
> if (pmcdev->map == _reg_map && !pci_dev_present(pmc_pci_ids))
> pmcdev->map = _reg_map;
>
> -   if (lpit_read_residency_count_address(_s0_addr))
> +   if (lpit_read_residency_count_address(_s0_addr)) {
> pmcdev->base_addr = PMC_BASE_ADDR_DEFAULT;
> -   else
> +
> +   if (page_is_ram(PHYS_PFN(pmcdev->base_addr)))
> +   return -ENODEV;
> +   } else {
> pmcdev->base_addr = slp_s0_addr - pmcdev->map->slp_s0_offset;
> +   }
>
> pmcdev->regbase = ioremap(pmcdev->base_addr,
>   pmcdev->map->regmap_length);
> --
> 2.21.0
>


-- 
With Best Regards,
Andy Shevchenko


Re: [PATCH] platform/x86: intel_pmc_core: Do not ioremap RAM

2019-08-16 Thread M. Vefa Bicakci
On Fri, 16 Aug 2019 12:21:58 +0300
Andy Shevchenko  wrote:

> On Fri, Aug 16, 2019 at 4:42 AM M. Vefa Bicakci  wrote:
> >
> > On a Xen-based PVH virtual machine with more than 4 GiB of RAM,
> > intel_pmc_core fails initialization with the following warning message
> > from the kernel, indicating that the driver is attempting to ioremap
> > RAM:
> >
> >   [ cut here ]
> >   ioremap on RAM at 0xfe00 - 0xfe001fff  
> 
> > This issue appears to manifest itself because of the following fallback
> > mechanism in the driver:
> >
> > if (lpit_read_residency_count_address(_s0_addr))
> > pmcdev->base_addr = PMC_BASE_ADDR_DEFAULT;
> >
> > The validity of address PMC_BASE_ADDR_DEFAULT (i.e., 0xFE00) is not
> > verified by the driver, which is what this patch introduces. With this
> > patch, if address PMC_BASE_ADDR_DEFAULT is in RAM, then the driver will
> > not attempt to ioremap the aforementioned address.  
> 
> Thank you for the patch.

Hello Andy,

Thank you for reviewing the patch!

> Is there anything preventing us to use memremap() in such case?

I re-read the documentation for memremap a few times along with taking
a look at its code, but I think I am missing an important piece of
information. As I understand it, depending on its flags, memremap would
allow a section of RAM to be mapped for the PMC driver.

The intention with this patch is to prevent the driver from being
instantiated when the default/fallback memory address is in RAM, as
this issue occurs with a non-administrative virtual machine (domU in
Xen terminology) that does not simulate or pass-through a corresponding
PMC device.

I think that I have misunderstood your review comment though, so I
would apppreciate it if you could elaborate.

Thanks again for reviewing the patch,

Vefa

(Please note that my next reply may be delayed by about 10 hours.)


Re: [PATCH] platform/x86: intel_pmc_core: Do not ioremap RAM

2019-08-16 Thread Andy Shevchenko
On Fri, Aug 16, 2019 at 4:42 AM M. Vefa Bicakci  wrote:
>
> On a Xen-based PVH virtual machine with more than 4 GiB of RAM,
> intel_pmc_core fails initialization with the following warning message
> from the kernel, indicating that the driver is attempting to ioremap
> RAM:
>
>   [ cut here ]
>   ioremap on RAM at 0xfe00 - 0xfe001fff

> This issue appears to manifest itself because of the following fallback
> mechanism in the driver:
>
> if (lpit_read_residency_count_address(_s0_addr))
> pmcdev->base_addr = PMC_BASE_ADDR_DEFAULT;
>
> The validity of address PMC_BASE_ADDR_DEFAULT (i.e., 0xFE00) is not
> verified by the driver, which is what this patch introduces. With this
> patch, if address PMC_BASE_ADDR_DEFAULT is in RAM, then the driver will
> not attempt to ioremap the aforementioned address.

Thank you for the patch.
Is there anything preventing us to use memremap() in such case?

-- 
With Best Regards,
Andy Shevchenko


[PATCH] platform/x86: intel_pmc_core: Do not ioremap RAM

2019-08-15 Thread M. Vefa Bicakci
On a Xen-based PVH virtual machine with more than 4 GiB of RAM,
intel_pmc_core fails initialization with the following warning message
from the kernel, indicating that the driver is attempting to ioremap
RAM:

  [ cut here ]
  ioremap on RAM at 0xfe00 - 0xfe001fff
  WARNING: CPU: 1 PID: 434 at arch/x86/mm/ioremap.c:186 
__ioremap_caller.constprop.0+0x2aa/0x2c0
  Modules linked in: intel_pmc_core_pltdrv(+) xen_netfront(+) intel_pmc_core \
crct10dif_pclmul crc32_pclmul crc32c_intel ghash_clmulni_intel \
intel_rapl_perf pcspkr binfmt_misc u2mfn(O) xenfs xen_gntdev \
xen_gntalloc xen_blkback xen_privcmd xen_evtchn ip_tables overlay \
xen_blkfront
  CPU: 1 PID: 434 Comm: systemd-udevd Tainted: G   O  
5.3.0-rc3-next-20190809-1 #2
  RIP: 0010:__ioremap_caller.constprop.0+0x2aa/0x2c0
  Code: 05 0f c9 1b 01 49 09 c6 e9 8e fe ff ff 48 8d 54 24 28 48 c7 c7 68 87 0a 
82 c6 05 c4 23 2b 01 01 48 8d 74 24 18 e8 d4 4a 06 00 <0f> 0b 45 31 ff e9 fe fe 
ff ff e8 e7 47 06 00 0f 1f 80 00 00 00 00
  RSP: 0018:c92dfa20 EFLAGS: 00010282
  RAX:  RBX: c0107000 RCX: 0006
  RDX: 0007 RSI: 0092 RDI: 88813bb17540
  RBP: fe00 R08: 015f R09: 000a
  R10: 000a R11: c92df8da R12: 2000
  R13:  R14: 0002 R15: 822da3a0
  FS:  72ecce666940() GS:88813bb0() knlGS:
  CS:  0010 DS:  ES:  CR0: 80050033
  CR2: 785be7346d20 CR3: 0d872001 CR4: 003606e0
  Call Trace:
   ? pmc_core_probe+0x87/0x2d0 [intel_pmc_core]
   pmc_core_probe+0x87/0x2d0 [intel_pmc_core]
   platform_drv_probe+0x35/0x80
   really_probe+0x298/0x3c0
   driver_probe_device+0x7a/0x100
   ? driver_allows_async_probing+0x50/0x50
   bus_for_each_drv+0x8f/0xd0
   __device_attach+0xf0/0x170
   bus_probe_device+0x8e/0xa0
   device_add+0x692/0x7e0
   platform_device_add+0xe9/0x240
   ? 0xc00ec000
   do_one_initcall+0x59/0x214
   do_init_module+0x5c/0x230
   load_module+0x258d/0x2840
   ? __do_sys_finit_module+0xbb/0x120
   __do_sys_finit_module+0xbb/0x120
   do_syscall_64+0x5f/0x1a0
   entry_SYSCALL_64_after_hwframe+0x44/0xa9
  RIP: 0033:0x72eccf662fad
  Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 
89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 
c3 48 8b 0d ab 9e 0c 00 f7 d8 64 89 01 48
  RSP: 002b:7ffd3710d018 EFLAGS: 0246 ORIG_RAX: 0139
  RAX: ffda RBX: 60ab8fda2530 RCX: 72eccf662fad
  RDX:  RSI: 72eccf2bd84d RDI: 0017
  RBP: 0002 R08:  R09: 0007
  R10: 0017 R11: 0246 R12: 72eccf2bd84d
  R13:  R14: 60ab8fd9b5e0 R15: 0007
  ---[ end trace 5e5421608729d6f4 ]---

This issue appears to manifest itself because of the following fallback
mechanism in the driver:

if (lpit_read_residency_count_address(_s0_addr))
pmcdev->base_addr = PMC_BASE_ADDR_DEFAULT;

The validity of address PMC_BASE_ADDR_DEFAULT (i.e., 0xFE00) is not
verified by the driver, which is what this patch introduces. With this
patch, if address PMC_BASE_ADDR_DEFAULT is in RAM, then the driver will
not attempt to ioremap the aforementioned address.

Signed-off-by: M. Vefa Bicakci 
---
 drivers/platform/x86/intel_pmc_core.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/intel_pmc_core.c 
b/drivers/platform/x86/intel_pmc_core.c
index c510d0d72475..3b6b8dcc4767 100644
--- a/drivers/platform/x86/intel_pmc_core.c
+++ b/drivers/platform/x86/intel_pmc_core.c
@@ -878,10 +878,14 @@ static int pmc_core_probe(struct platform_device *pdev)
if (pmcdev->map == _reg_map && !pci_dev_present(pmc_pci_ids))
pmcdev->map = _reg_map;
 
-   if (lpit_read_residency_count_address(_s0_addr))
+   if (lpit_read_residency_count_address(_s0_addr)) {
pmcdev->base_addr = PMC_BASE_ADDR_DEFAULT;
-   else
+
+   if (page_is_ram(PHYS_PFN(pmcdev->base_addr)))
+   return -ENODEV;
+   } else {
pmcdev->base_addr = slp_s0_addr - pmcdev->map->slp_s0_offset;
+   }
 
pmcdev->regbase = ioremap(pmcdev->base_addr,
  pmcdev->map->regmap_length);
-- 
2.21.0