check interleave capability
Subsystems (2)
v8 cover check interleave capability
Currently, the cxl driver does not check the interleave capability of devices (such as host bridges, switches, cxl_mem, etc.) when creating a region.
When the driver adds a device to the region and sets its decoder, if the device does not support the specified interleave ways or interleave granularity, the device may ignore unsupported bits, causing the configured decoder to be inconsistent with expectations.
During memory access, the decoder may decode the HPA into an incorrect DPA, ultimately leading to memory access failure.
Checking the interleave capability of a device early in the process of adding it to a region can quickly prevent this issue from occurring.
Changes:
V7[7] -> V8:
-- drop the redundant check in check_interleave_cap() -- add cxlmem.h to kernel-doc (newly add)
-- fixup cxl_test (newly add)
V6[6] -> V7:
-- update comment.
V5[5] -> V6:
-- fix some typo.
-- update comment.
-- set rc when check failed in cxl_port_attach_region().
V4[4] -> V5:
-- update comment.
-- add nr_targets check while attaching a port to switch.
-- delete passthrough flag and allow all the capabilities for passthrough
decoders.
V3[3] -> V4:
-- update comment.
-- optimize the code.
-- add a passthrough flag to mark the passthrough decoder.
V2[2] -> V3:
-- revert ig_cap_mask to interleave_mask.
-- fix the interleave bits check logical.
V1[1] -> V2:
-- rename interleave_mask to ig_cap_mask. -- add a check for interleave granularity. -- update commit.
-- move hdm caps init to parse_hdm_decoder_caps().
[1]
https://lore.kernel.org/linux-cxl/[email protected]
[2]
https://lore.kernel.org/linux-cxl/[email protected]
[3]
https://lore.kernel.org/linux-cxl/[email protected]
[4]
https://lore.kernel.org/linux-cxl/[email protected]
[5]
https://lore.kernel.org/linux-cxl/[email protected]
[6]
https://lore.kernel.org/linux-cxl/[email protected]
[7]
https://lore.kernel.org/linux-cxl/[email protected]
Yao Xingtao (3):
cxl/region: check interleave capability
cxl: documentation: add cxlmem.h to cxl driver-api
cxl_test: fix the 'create region failed' error
.../driver-api/cxl/memory-devices.rst | 3 + drivers/cxl/core/hdm.c | 13 +++ drivers/cxl/core/region.c | 89 +++++++++++++++++++ drivers/cxl/cxl.h | 2 + drivers/cxl/cxlmem.h | 10 +++ tools/testing/cxl/test/cxl.c | 4 + 6 files changed, 121 insertions(+)
Signature · 1 line
2.37.3
PATCH v8 1/3 cxl/region: check interleave capability
Since interleave capability is not verified, if the interleave capability of a target does not match the region need, committing decoder should have failed at the device end.
In order to checkout this error as quickly as possible, driver needs to check the interleave capability of target during attaching it to region.
Per CXL specification r3.1(8.2.4.20.1 CXL HDM Decoder Capability Register), bits 11 and 12 indicate the capability to establish interleaving in 3, 6, 12 and 16 ways. If these bits are not set, the target cannot be attached to a region utilizing such interleave ways.
Additionally, bits 8 and 9 represent the capability of the bits used for interleaving in the address, Linux tracks this in the cxl_port interleave_mask.
Per CXL specification r3.1(8.2.4.20.13 Decoder Protection):
eIW means encoded Interleave Ways.
eIG means encoded Interleave Granularity.
in HPA:
if eIW is 0 or 8 (interleave ways: 1, 3), all the bits of HPA are used, the interleave bits are none, the following check is ignored.
if eIW is less than 8 (interleave ways: 2, 4, 8, 16), the interleave bits start at bit position eIG + 8 and end at eIG + eIW + 8 - 1.
if eIW is greater than 8 (interleave ways: 6, 12), the interleave bits start at bit position eIG + 8 and end at eIG + eIW - 1.
if the interleave mask is insufficient to cover the required interleave bits, the target cannot be attached to the region.
--- drivers/cxl/core/hdm.c | 13 +++++++ drivers/cxl/core/region.c | 82 +++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxl.h | 2 + drivers/cxl/cxlmem.h | 10 +++++ 4 files changed, 107 insertions(+)
drivers/cxl/core/hdm.c +13 -0
@@ -52,6 +52,14 @@ int devm_cxl_add_passthrough_decoder(struct cxl_port *port)struct cxl_dport *dport =NULL ;int single_port_map[1 ];unsigned long index; +struct cxl_hdm *cxlhdm =dev_get_drvdata (&port->dev); + +/* +* Capability checks are moot for passthrough decoders, support +* any and all possibilities. +*/ + cxlhdm->interleave_mask = ~0U ; + cxlhdm->iw_cap_mask = ~0UL ; cxlsd =cxl_switch_decoder_alloc (port,1 );if (IS_ERR (cxlsd))
@@ -79,6 +87,11 @@ static void parse_hdm_decoder_caps(struct cxl_hdm *cxlhdm) cxlhdm->interleave_mask |=GENMASK (11 ,8 );if (FIELD_GET (CXL_HDM_DECODER_INTERLEAVE_14_12 , hdm_cap)) cxlhdm->interleave_mask |=GENMASK (14 ,12 ); + cxlhdm->iw_cap_mask =BIT (1 ) |BIT (2 ) |BIT (4 ) |BIT (8 ); +if (FIELD_GET (CXL_HDM_DECODER_INTERLEAVE_3_6_12_WAY , hdm_cap)) + cxlhdm->iw_cap_mask |=BIT (3 ) |BIT (6 ) |BIT (12 ); +if (FIELD_GET (CXL_HDM_DECODER_INTERLEAVE_16_WAY , hdm_cap)) + cxlhdm->iw_cap_mask |=BIT (16 ); }static bool should_emulate_decoders (struct cxl_endpoint_dvsec_info *info)
drivers/cxl/core/region.c +82 -0
106 lines not on this page · raw message
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)
drivers/cxl/cxlmem.h +10 -0
@@ -848,11 +848,21 @@ static inline void cxl_mem_active_dec(void)int cxl_mem_sanitize (struct cxl_memdev *cxlmd,u16 cmd); +/* +* struct cxl_hdm - HDM Decoder registers and cached / decoded capabilities +* @regs: mapped registers, see devm_cxl_setup_hdm() +* @decoder_count: number of decoders for this port +* @target_count: for switch decoders, max downstream port targets +* @interleave_mask: interleave granularity capability, see check_interleave_cap() +* @iw_cap_mask: bitmask of supported interleave ways, see check_interleave_cap() +* @port: mapped cxl_port, see devm_cxl_setup_hdm() +*/ struct cxl_hdm {struct cxl_component_regs regs;unsigned int decoder_count;unsigned int target_count;unsigned int interleave_mask; +unsigned long iw_cap_mask;struct cxl_port *port; };
Signature · 1 line
2.37.3
PATCH v8 2/3 cxl: documentation: add cxlmem.h to cxl driver-api
In reply to Yao XingtaoSince the interleave capability check is supported, and this feature depends on cxl_hdm, add cxl_hdm structure to the cxl driver API documentation.
--- Documentation/driver-api/cxl/memory-devices.rst | 3 +++ 1 file changed, 3 insertions(+)
Documentation/driver-api/cxl/memory-devices.rst +3 -0
@@ -325,6 +325,9 @@ CXL Memory Device .. kernel-doc:: drivers/cxl/pci.c :internal: +.. kernel-doc:: drivers/cxl/cxlmem.h + :internal: + .. kernel-doc:: drivers/cxl/mem.c :doc: cxl mem
Signature · 1 line
2.37.3
Alison Schofield
maintainerRe: [PATCH v8 2/3] cxl: documentation: add cxlmem.h to cxl driver-api
Quoted 4 lines · Yao Xingtao
Since the interleave capability check is supported, and this feature depends on
cxl_hdm, addcxl_hdmstructure to the cxl driver API documentation.
Hi Yao,
I was hoping you were going to add the other missing files here, core/cdat.c and core/hdm.c
If you don't we can pick them up another time.
However, the new struct in Patch 1 doesn't have the kernel doc notation so this isn't picking up the cxl_hdm structure for the docs.
-- Alison
Quoted 23 lines
Suggested-by Dan Williams <[email protected]>Signed-off-by Yao Xingtao <[email protected]>--- Documentation/driver-api/cxl/memory-devices.rst | 3 +++ 1 file changed, 3 insertions(+)Documentation/driver-api/cxl/memory-devices.rst +3
-0@@ -325,6 +325,9 @@ CXL Memory Device .. kernel-doc:: drivers/cxl/pci.c :internal: +.. kernel-doc:: drivers/cxl/cxlmem.h + :internal: + .. kernel-doc:: drivers/cxl/mem.c :doc: cxl memSignature · 1 line
2.37.3
RE: [PATCH v8 2/3] cxl: documentation: add cxlmem.h to cxl driver-api
Quoted 17 lines
-----Original Message-----
From: Alison Schofield <[email protected]>
Sent: Friday, June 14, 2024 12:47 PM
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 v8 2/3] cxl: documentation: addcxlmem.hto cxl driver-apiQuoted 4 lines · Yao Xingtao
Since the interleave capability check is supported, and this feature depends on
cxl_hdm, addcxl_hdmstructure to the cxl driver API documentation.
Quoted 6 lines
Hi Yao,
I was hoping you were going to add the other missing files here,
core/cdat.candcore/hdm.cIf you don't we can pick them up another time.
sorry, I misunderstood what your request.
I thought that these file will be added in another patch other than in this patch set.
will add in next revision.
Quoted 4 lines
However, the new struct in Patch 1 doesn't have the kernel doc notation so this isn't picking up the
cxl_hdmstructure for the docs.
yes, that's a problem.
Quoted 28 lines
-- Alison
Review
Quoted 7 lines
Suggested-by Dan Williams <[email protected]>Signed-off-by Yao Xingtao <[email protected]>--- Documentation/driver-api/cxl/memory-devices.rst | 3 +++ 1 file changed, 3 insertions(+)(quoted diff) +0
-0
b/Documentation/driver-api/cxl/memory-devices.rstQuoted 16 lines
index
5149ecdc53c7..e33ee67ac1a2100644Documentation/driver-api/cxl/memory-devices.rst +3
-1@@ -325,6 +325,9 @@ CXL Memory Device .. kernel-doc:: drivers/cxl/pci.c :internal: +.. kernel-doc:: drivers/cxl/cxlmem.h + :internal: + .. kernel-doc:: drivers/cxl/mem.c :doc: cxl mem --2.37.3
PATCH v8 3/3 cxl_test: fix the 'create region failed' error
In reply to Yao XingtaoSince the interleave capability check is supported, the cxl_test will fail.
Support any and all possibilities for the mock cxl device (host bridge, switch, cxl_mem .etc).
--- tools/testing/cxl/test/cxl.c | 4 ++++ 1 file changed, 4 insertions(+)
tools/testing/cxl/test/cxl.c +4 -0
@@ -630,11 +630,15 @@ static struct cxl_hdm *mock_cxl_setup_hdm(struct cxl_port *port, struct cxl_endpoint_dvsec_info *info) {struct cxl_hdm *cxlhdm =devm_kzalloc (&port->dev,sizeof (*cxlhdm),GFP_KERNEL ); +struct device *dev = &port->dev;if (!cxlhdm)return ERR_PTR (-ENOMEM ); cxlhdm->port = port; + cxlhdm->interleave_mask = ~0U ; + cxlhdm->iw_cap_mask = ~0UL ; +dev_set_drvdata (dev, cxlhdm);return cxlhdm; }
Signature · 1 line
2.37.3
Alison Schofield
maintainerRe: [PATCH v8 3/3] cxl_test: fix the 'create region failed' error
Quoted 4 lines · Yao Xingtao
Since the interleave capability check is supported, the
cxl_testwill fail.
Support any and all possibilities for the mock cxl device (host bridge, switch,cxl_mem.etc).
This needs to be folded into Patch 1.
FYI - sometimes when we add a new feature the cxl-test mock support is added as a separate patch. In this case, we're just preserving existing functionality of cxl-test. Prefer not to break it in Patch 1 and then fix it in a subsequent patch.
-- Alison
Quoted 32 lines
Suggested-by Dan Williams <[email protected]>Suggested-by Alison Schofield <[email protected]>Signed-off-by Yao Xingtao <[email protected]>--- tools/testing/cxl/test/cxl.c | 4 ++++ 1 file changed, 4 insertions(+)tools/testing/cxl/test/cxl.c +4
-0@@ -630,11 +630,15 @@ static struct cxl_hdm *mock_cxl_setup_hdm(struct cxl_port *port, struct cxl_endpoint_dvsec_info *info) {struct cxl_hdm *cxlhdm =devm_kzalloc (&port->dev,sizeof (*cxlhdm),GFP_KERNEL ); +struct device *dev = &port->dev;if (!cxlhdm)return ERR_PTR (-ENOMEM ); cxlhdm->port = port; + cxlhdm->interleave_mask = ~0U ; + cxlhdm->iw_cap_mask = ~0UL ; +dev_set_drvdata (dev, cxlhdm);return cxlhdm; }Signature · 1 line
2.37.3
RE: [PATCH v8 3/3] cxl_test: fix the 'create region failed' error
Quoted 17 lines
-----Original Message-----
From: Alison Schofield <[email protected]>
Sent: Friday, June 14, 2024 12:58 PM
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 v8 3/3]cxl_test: fix the 'create region failed' errorQuoted 4 lines · Yao Xingtao
Since the interleave capability check is supported, the
cxl_testwill fail.
Support any and all possibilities for the mock cxl device (host bridge, switch,cxl_mem.etc).
Quoted 6 lines
This needs to be folded into Patch 1.
FYI - sometimes when we add a new feature the cxl-test mock support is added as a separate patch. In this case, we're just preserving existing functionality of cxl-test. Prefer not to break it in Patch 1 and then fix it in a subsequent patch.
OK, thanks for your advice, will fix in next revision.
Quoted 37 lines
-- Alison
tools/testing/cxl/test/cxl.c static struct cxl_hdm *mock_cxl_setup_hdm(struct
Quoted 13 lines
Suggested-by Dan Williams <[email protected]>Suggested-by Alison Schofield <[email protected]>Signed-off-by Yao Xingtao <[email protected]>--- tools/testing/cxl/test/cxl.c | 4 ++++ 1 file changed, 4 insertions(+)tools/testing/cxl/test/cxl.c +0
-0@@ -630,11 +630,15 @@ static struct cxl_hdm *mock_cxl_setup_hdm(struct
cxl_port*port,tools/testing/cxl/test/cxl.c static struct cxl_hdm *mock_cxl_setup_hdm(struct cxl_port *port,
Quoted 3 lines
tools/testing/cxl/test/cxl.c +0
-0struct cxl_endpoint_dvsec_info *info) { struct cxl_hdm *cxlhdm = devm_kzalloc(&port->dev, sizeof(*cxlhdm),
GFP_KERNEL);Quoted 16 lines
tools/testing/cxl/test/cxl.c +4
-1+struct device *dev = &port->dev;if (!cxlhdm)return ERR_PTR (-ENOMEM ); cxlhdm->port = port; + cxlhdm->interleave_mask = ~0U ; + cxlhdm->iw_cap_mask = ~0UL ; +dev_set_drvdata (dev, cxlhdm);return cxlhdm; } --2.37.3