cxl/core/region: check interleave way capability
PATCH 1/1 cxl/core/region: check interleave way capability
I used qemu to emulaute the cxl.mem and attmpted to create a 6-way region, the region was created successfully, but I could not access the memory properly:
$ numactl -m 2 ls Segmentation fault (core dumped)
I found the root cause is that the logic of converting HPA to DPA for 3-way, 6-way and 12-way were not implimented on qemu side.
But qemu has already disable the capability, so we should not create region in such ways.
So I think we should check whether the interleave way is supported by the target while attaching it to region.
--- drivers/cxl/core/region.c | 25 +++++++++++++++++++++++++ drivers/cxl/cxl.h | 2 ++ 2 files changed, 27 insertions(+)
drivers/cxl/core/region.c +25 -0
@@ -1786,6 +1786,24 @@ static int cxl_region_sort_targets(struct cxl_region *cxlr)return rc; } +static bool check_iw_capability (struct cxl_endpoint_decoder *cxled,u8 iw) +{ +struct cxl_port *port =to_cxl_port (cxled->cxld.dev.parent); +struct cxl_hdm *cxlhdm =dev_get_drvdata (&port->dev); +void __iomem *hdm = cxlhdm->regs.hdm_decoder; +u32 cap; + + cap =readl (hdm +CXL_HDM_DECODER_CAP_OFFSET ); +if (!FIELD_GET (CXL_HDM_DECODER_INTERLEAVE_3_6_12_WAY , cap) && + (iw ==3 || iw ==6 || iw ==12 )) +return false; + +if (!FIELD_GET (CXL_HDM_DECODER_INTERLEAVE_16_WAY , cap) && iw ==16 ) +return false; + +return true; +} +static int cxl_region_attach (struct cxl_region *cxlr,struct cxl_endpoint_decoder *cxled,int pos) {
@@ -1796,6 +1814,13 @@ static int cxl_region_attach(struct cxl_region *cxlr,struct cxl_dport *dport;int rc = -ENXIO ; +if (!check_iw_capability (cxled, p->interleave_ways)) { +dev_dbg (&cxlr->dev, +"%s with region interleave ways: %d is not supported\n" , +dev_name (&cxled->cxld.dev), p->interleave_ways); +return -EOPNOTSUPP ; + } +if (cxled->mode != cxlr->mode) {dev_dbg (&cxlr->dev,"%s region mode: %d mismatch: %d\n" ,dev_name (&cxled->cxld.dev), cxlr->mode, cxled->mode);
drivers/cxl/cxl.h +2 -0
@@ -45,6 +45,8 @@#define CXL_HDM_DECODER_TARGET_COUNT_MASK GENMASK(7, 4)#define CXL_HDM_DECODER_INTERLEAVE_11_8 BIT(8)#define CXL_HDM_DECODER_INTERLEAVE_14_12 BIT(9) +#define CXL_HDM_DECODER_INTERLEAVE_3_6_12_WAY BIT(11) +#define CXL_HDM_DECODER_INTERLEAVE_16_WAY BIT(12)#define CXL_HDM_DECODER_CTRL_OFFSET 0x4#define CXL_HDM_DECODER_ENABLE BIT(1)#define CXL_HDM_DECODER0_BASE_LOW_OFFSET (i) (0x20 * (i) + 0x10)
Signature · 1 line
2.37.3
Alison Schofield
maintainerQuoted 6 lines · Yao Xingtao
I used qemu to emulaute the cxl.mem and attmpted to create a 6-way region, the region was created successfully, but I could not access the memory properly:
$ numactl -m 2 ls Segmentation fault (core dumped)
Quoted 8 lines
I found the root cause is that the logic of converting HPA to DPA for 3-way, 6-way and 12-way were not implimented on qemu side.
But qemu has already disable the capability, so we should not create region in such ways.
So I think we should check whether the interleave way is supported by the target while attaching it to region.
Nice find!
I'm wondering if this may be done where other hdm caps are parsed, at parse_hdm_decoder_caps() and saved as a capability of the port, as opposed to reading the register on region creation attempts.
--Alison
Quoted 67 lines
Signed-off-by Yao Xingtao <[email protected]>--- drivers/cxl/core/region.c | 25 +++++++++++++++++++++++++ drivers/cxl/cxl.h | 2 ++ 2 files changed, 27 insertions(+)drivers/cxl/core/region.c +25
-0@@ -1786,6 +1786,24 @@ static int cxl_region_sort_targets(struct cxl_region *cxlr)return rc; } +static bool check_iw_capability (struct cxl_endpoint_decoder *cxled,u8 iw) +{ +struct cxl_port *port =to_cxl_port (cxled->cxld.dev.parent); +struct cxl_hdm *cxlhdm =dev_get_drvdata (&port->dev); +void __iomem *hdm = cxlhdm->regs.hdm_decoder; +u32 cap; + + cap =readl (hdm +CXL_HDM_DECODER_CAP_OFFSET ); +if (!FIELD_GET (CXL_HDM_DECODER_INTERLEAVE_3_6_12_WAY , cap) && + (iw ==3 || iw ==6 || iw ==12 )) +return false; + +if (!FIELD_GET (CXL_HDM_DECODER_INTERLEAVE_16_WAY , cap) && iw ==16 ) +return false; + +return true; +} +static int cxl_region_attach (struct cxl_region *cxlr,struct cxl_endpoint_decoder *cxled,int pos) {@@ -1796,6 +1814,13 @@ static int cxl_region_attach(struct cxl_region *cxlr,struct cxl_dport *dport;int rc = -ENXIO ; +if (!check_iw_capability (cxled, p->interleave_ways)) { +dev_dbg (&cxlr->dev, +"%s with region interleave ways: %d is not supported\n" , +dev_name (&cxled->cxld.dev), p->interleave_ways); +return -EOPNOTSUPP ; + } +if (cxled->mode != cxlr->mode) {dev_dbg (&cxlr->dev,"%s region mode: %d mismatch: %d\n" ,dev_name (&cxled->cxld.dev), cxlr->mode, cxled->mode);drivers/cxl/cxl.h +2
-0@@ -45,6 +45,8 @@#define CXL_HDM_DECODER_TARGET_COUNT_MASK GENMASK(7, 4)#define CXL_HDM_DECODER_INTERLEAVE_11_8 BIT(8)#define CXL_HDM_DECODER_INTERLEAVE_14_12 BIT(9) +#define CXL_HDM_DECODER_INTERLEAVE_3_6_12_WAY BIT(11) +#define CXL_HDM_DECODER_INTERLEAVE_16_WAY BIT(12)#define CXL_HDM_DECODER_CTRL_OFFSET 0x4#define CXL_HDM_DECODER_ENABLE BIT(1)#define CXL_HDM_DECODER0_BASE_LOW_OFFSET (i) (0x20 * (i) + 0x10)Signature · 1 line
2.37.3
Quoted 24 lines
-----Original Message-----
From: Alison Schofield <[email protected]>
Sent: Tuesday, April 2, 2024 12:51 AM
To: Yao, Xingtao/姚 幸涛 <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] cxl/core/region: check interleave way capabilityQuoted 12 lines · Yao Xingtao
I used qemu to emulaute the cxl.mem and attmpted to create a 6-way region, the region was created successfully, but I could not access the memory properly:
$ numactl -m 2 ls Segmentation fault (core dumped)I found the root cause is that the logic of converting HPA to DPA for 3-way, 6-way and 12-way were not implimented on qemu side.
But qemu has already disable the capability, so we should not create region in such ways.
Quoted 8 lines
Quoted 2 lines
So I think we should check whether the interleave way is supported by the target while attaching it to region.
Nice find!
I'm wondering if this may be done where other hdm caps are parsed, at
parse_hdm_decoder_caps()and saved as a capability of the port, as opposed to reading the register on region creation attempts.
thanks for your advice!
I will move this operation into parse_hdm_decoder_caps() in the next version.
Quoted 78 lines
--Alison
Quoted 2 lines
Link:
https://lore.kernel.org/qemu-devel/[email protected]
om/T/#rdrivers/cxl/core/region.c static int cxl_region_sort_targets(struct cxl_region
Quoted 11 lines
Signed-off-by Yao Xingtao <[email protected]>--- drivers/cxl/core/region.c | 25 +++++++++++++++++++++++++ drivers/cxl/cxl.h | 2 ++ 2 files changed, 27 insertions(+)drivers/cxl/core/region.c +0
-0@@ -1786,6 +1786,24 @@ static int cxl_region_sort_targets(struct cxl_region*cxlr)
drivers/cxl/core/region.c static int cxl_region_sort_targets(struct cxl_region *cxlr)
Quoted 12 lines
drivers/cxl/core/region.c +9
-0return rc; } +static bool check_iw_capability (struct cxl_endpoint_decoder *cxled,u8 iw) +{ +struct cxl_port *port =to_cxl_port (cxled->cxld.dev.parent); +struct cxl_hdm *cxlhdm =dev_get_drvdata (&port->dev); +void __iomem *hdm = cxlhdm->regs.hdm_decoder; +u32 cap; + + cap =readl (hdm +CXL_HDM_DECODER_CAP_OFFSET ); + if (!FIELD_GET(CXL_HDM_DECODER_INTERLEAVE_3_6_12_WAY, cap)&&
drivers/cxl/core/region.c static int cxl_region_sort_targets(struct cxl_region *cxlr)
Quoted 4 lines
drivers/cxl/core/region.c +4
-0+ (iw == 3 || iw == 6 || iw == 12)) +return false; + + if (!FIELD_GET(CXL_HDM_DECODER_INTERLEAVE_16_WAY, cap) && iw== 16)
Quoted 12 lines
drivers/cxl/core/region.c +5
-0+return false; + +return true; +} +static int cxl_region_attach (struct cxl_region *cxlr,struct cxl_endpoint_decoder *cxled,int pos) {@@ -1796,6 +1814,13 @@ static int cxl_region_attach(struct cxl_region *cxlr,struct cxl_dport *dport;int rc = -ENXIO ;drivers/cxl/core/region.c static int cxl_region_attach(struct cxl_region *cxlr, · line 1826
Quoted 10 lines
drivers/cxl/core/region.c +7
-0+if (!check_iw_capability (cxled, p->interleave_ways)) { +dev_dbg (&cxlr->dev, +"%s with region interleave ways: %d is not supported\n" , +dev_name (&cxled->cxld.dev), p->interleave_ways); +return -EOPNOTSUPP ; + } +if (cxled->mode != cxlr->mode) { dev_dbg(&cxlr->dev, "%s region mode: %d mismatch: %d\n", dev_name(&cxled->cxld.dev), cxlr->mode,
cxled->mode);Quoted 16 lines
drivers/cxl/cxl.h +2
-1@@ -45,6 +45,8 @@#define CXL_HDM_DECODER_TARGET_COUNT_MASK GENMASK(7, 4)#define CXL_HDM_DECODER_INTERLEAVE_11_8 BIT(8)#define CXL_HDM_DECODER_INTERLEAVE_14_12 BIT(9) +#define CXL_HDM_DECODER_INTERLEAVE_3_6_12_WAY BIT(11) +#define CXL_HDM_DECODER_INTERLEAVE_16_WAY BIT(12)#define CXL_HDM_DECODER_CTRL_OFFSET 0x4#define CXL_HDM_DECODER_ENABLE BIT(1)#define CXL_HDM_DECODER0_BASE_LOW_OFFSET (i) (0x20 * (i) + 0x10) --2.37.3
Quoted 6 lines · Yao Xingtao
I used qemu to emulaute the cxl.mem and attmpted to create a 6-way region, the region was created successfully, but I could not access the memory properly:
$ numactl -m 2 ls Segmentation fault (core dumped)
Quoted 8 lines
I found the root cause is that the logic of converting HPA to DPA for 3-way, 6-way and 12-way were not implimented on qemu side.
But qemu has already disable the capability, so we should not create region in such ways.
So I think we should check whether the interleave way is supported by the target while attaching it to region.
Good find!
Not only does this need to happen for 3, 6, 12, but it also needs to be checked to make sure the device can support interleaves on address bits 11to8 and 14to12 (CXL_HDM_DECODER_INTERLEAVE_11_8, CXL_HDM_DECODER_INTERLEAVE_14_12).
As it stands the 'struct cxl_hdm' 'interleave_mask' attribute is unused, and IIRC was meant to support this capabilty check.
Quoted 1 line
This can be trimmed to:
Quoted 36 lines
Signed-off-by Yao Xingtao <[email protected]>--- drivers/cxl/core/region.c | 25 +++++++++++++++++++++++++ drivers/cxl/cxl.h | 2 ++ 2 files changed, 27 insertions(+)drivers/cxl/core/region.c +18
-0@@ -1786,6 +1786,24 @@ static int cxl_region_sort_targets(struct cxl_region *cxlr)return rc; } +static bool check_iw_capability (struct cxl_endpoint_decoder *cxled,u8 iw) +{ +struct cxl_port *port =to_cxl_port (cxled->cxld.dev.parent); +struct cxl_hdm *cxlhdm =dev_get_drvdata (&port->dev); +void __iomem *hdm = cxlhdm->regs.hdm_decoder; +u32 cap; + + cap =readl (hdm +CXL_HDM_DECODER_CAP_OFFSET ); +if (!FIELD_GET (CXL_HDM_DECODER_INTERLEAVE_3_6_12_WAY , cap) && + (iw ==3 || iw ==6 || iw ==12 )) +return false; + +if (!FIELD_GET (CXL_HDM_DECODER_INTERLEAVE_16_WAY , cap) && iw ==16 ) +return false; + +return true; +} +static int cxl_region_attach (struct cxl_region *cxlr,struct cxl_endpoint_decoder *cxled,int pos) {
drivers/cxl/core/region.c static int cxl_region_attach(struct cxl_region *cxlr, · line 1822
Quoted 9 lines
drivers/cxl/core/region.c +6
-0@@ -1796,6 +1814,13 @@ static int cxl_region_attach(struct cxl_region *cxlr,struct cxl_dport *dport;int rc = -ENXIO ; +if (!check_iw_capability (cxled, p->interleave_ways)) { +dev_dbg (&cxlr->dev, +"%s with region interleave ways: %d is not supported\n" , +dev_name (&cxled->cxld.dev), p->interleave_ways); +return -EOPNOTSUPP ; + }
In order to validate the address-bit capabilities of the endpoint this routine will also need the 'interleave_granularity' argument.
Quoted 30 lines
-----Original Message-----
From: Dan Williams <[email protected]>
Sent: Tuesday, April 2, 2024 2:34 AM
To: Yao, Xingtao/姚 幸涛 <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; Yao, Xingtao/姚 幸涛 <[email protected]>
Subject: Re: [PATCH] cxl/core/region: check interleave way capabilityQuoted 6 lines · Yao Xingtao
I used qemu to emulaute the cxl.mem and attmpted to create a 6-way region, the region was created successfully, but I could not access the memory properly:
$ numactl -m 2 ls Segmentation fault (core dumped)Quoted 8 lines
I found the root cause is that the logic of converting HPA to DPA for 3-way, 6-way and 12-way were not implimented on qemu side.
But qemu has already disable the capability, so we should not create region in such ways.
So I think we should check whether the interleave way is supported by the target while attaching it to region.
Good find!
Quoted 7 lines
Not only does this need to happen for 3, 6, 12, but it also needs to be checked to make sure the device can support interleaves on address bits 11to8 and 14to12 (
CXL_HDM_DECODER_INTERLEAVE_11_8,CXL_HDM_DECODER_INTERLEAVE_14_12).As it stands the 'struct
cxl_hdm' 'interleave_mask' attribute is unused, and IIRC was meant to support this capabilty check.
I will add this check in the next version.
Quoted 8 lines
Quoted 2 lines
Link:
https://lore.kernel.org/qemu-devel/[email protected]
om/T/#rThis can be trimmed to:
I will change the comment in the next version
Quoted 52 lines
drivers/cxl/core/region.c static int cxl_region_sort_targets(struct cxl_region
Quoted 12 lines
Signed-off-by Yao Xingtao <[email protected]>--- drivers/cxl/core/region.c | 25 +++++++++++++++++++++++++ drivers/cxl/cxl.h | 2 ++ 2 files changed, 27 insertions(+)drivers/cxl/core/region.c +0
-0@@ -1786,6 +1786,24 @@ static int cxl_region_sort_targets(struct cxl_region*cxlr)
drivers/cxl/core/region.c static int cxl_region_sort_targets(struct cxl_region *cxlr)
Quoted 12 lines
drivers/cxl/core/region.c +9
-0return rc; } +static bool check_iw_capability (struct cxl_endpoint_decoder *cxled,u8 iw) +{ +struct cxl_port *port =to_cxl_port (cxled->cxld.dev.parent); +struct cxl_hdm *cxlhdm =dev_get_drvdata (&port->dev); +void __iomem *hdm = cxlhdm->regs.hdm_decoder; +u32 cap; + + cap =readl (hdm +CXL_HDM_DECODER_CAP_OFFSET ); + if (!FIELD_GET(CXL_HDM_DECODER_INTERLEAVE_3_6_12_WAY, cap)&&
drivers/cxl/core/region.c static int cxl_region_sort_targets(struct cxl_region *cxlr)
Quoted 4 lines
drivers/cxl/core/region.c +4
-0+ (iw == 3 || iw == 6 || iw == 12)) +return false; + + if (!FIELD_GET(CXL_HDM_DECODER_INTERLEAVE_16_WAY, cap) && iw== 16)
Quoted 9 lines
drivers/cxl/core/region.c +5
-0+return false; + +return true; +} +static int cxl_region_attach (struct cxl_region *cxlr,struct cxl_endpoint_decoder *cxled,int pos) {drivers/cxl/core/region.c static int cxl_region_attach(struct cxl_region *cxlr, · line 1822
Quoted 9 lines
drivers/cxl/core/region.c +6
-0@@ -1796,6 +1814,13 @@ static int cxl_region_attach(struct cxl_region *cxlr,struct cxl_dport *dport;int rc = -ENXIO ; +if (!check_iw_capability (cxled, p->interleave_ways)) { +dev_dbg (&cxlr->dev, +"%s with region interleave ways: %d is not supported\n" , +dev_name (&cxled->cxld.dev), p->interleave_ways); +return -EOPNOTSUPP ; + }In order to validate the address-bit capabilities of the endpoint this routine will also need the '
interleave_granularity' argument.