2022-08-31 09:14:07

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 02/15] cxl/core: Check physical address before mapping it in devm_cxl_iomap_block()

On Wed, 31 Aug 2022 10:15:50 +0200
Robert Richter <[email protected]> wrote:

> The physical base address of a CXL range can be invalid and is then
> set to CXL_RESOURCE_NONE. Early check this case before mapping a
> memory block in devm_cxl_iomap_block().

An example of when it is invalid would be a useful addition
to this description. Feels to me like this is papering over the cracks
in something we should have ruled out earlier in the flow.

Jonathan

>
> Signed-off-by: Robert Richter <[email protected]>
> ---
> drivers/cxl/core/regs.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/cxl/core/regs.c b/drivers/cxl/core/regs.c
> index 39a129c57d40..f216c017a474 100644
> --- a/drivers/cxl/core/regs.c
> +++ b/drivers/cxl/core/regs.c
> @@ -165,6 +165,9 @@ void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr,
> void __iomem *ret_val;
> struct resource *res;
>
> + if (addr == CXL_RESOURCE_NONE)
> + return NULL;
> +
> res = devm_request_mem_region(dev, addr, length, dev_name(dev));
> if (!res) {
> resource_size_t end = addr + length - 1;


2022-09-01 05:45:05

by Robert Richter

[permalink] [raw]
Subject: Re: [PATCH 02/15] cxl/core: Check physical address before mapping it in devm_cxl_iomap_block()

On 31.08.22 09:56:51, Jonathan Cameron wrote:
> On Wed, 31 Aug 2022 10:15:50 +0200
> Robert Richter <[email protected]> wrote:
>
> > The physical base address of a CXL range can be invalid and is then
> > set to CXL_RESOURCE_NONE. Early check this case before mapping a
> > memory block in devm_cxl_iomap_block().
>
> An example of when it is invalid would be a useful addition
> to this description. Feels to me like this is papering over the cracks
> in something we should have ruled out earlier in the flow.

IIRC this happened during code development in cxl_pci_probe() when
cxl_map_regs() is called but the base addr was not determined
correctly before. It's similar to a NULL pointer check.

-Robert