Skip to content

Commit 208f432

Browse files
Robert Richterdavejiang
authored andcommitted
cxl: Disable HPA/SPA translation handlers for Normalized Addressing
The root decoder provides the callbacks hpa_to_spa and spa_to_hpa to perform Host Physical Address (HPA) and System Physical Address translations, respectively. The callbacks are required to convert addresses when HPA != SPA. XOR interleaving depends on this mechanism, and the necessary handlers are implemented. The translation handlers are used for poison injection (trace_cxl_poison, cxl_poison_inject_fops) and error handling (cxl_event_trace_record). In AMD Zen5 systems with Normalized Addressing, endpoint addresses are not SPAs, and translation handlers are required for these features to function correctly. Now, as ACPI PRM translation could be expensive in tracing or error handling code paths, do not yet enable translations to avoid its intensive use. Instead, disable those features which are used only for debugging and enhanced logging. Introduce the flag CXL_REGION_F_NORMALIZED_ADDRESSING that indicates Normalized Addressing for a region and use it to disable poison injection and DPA to HPA conversion. Note: Dropped unused CXL_DECODER_F_MASK macro. [dj: Fix commit log CXL_REGION_F_NORM_ADDR to CXL_REGION_F_NORMALIZED_ADDRESSING ] Reviewed-by: Alison Schofield <alison.schofield@intel.com> Signed-off-by: Robert Richter <rrichter@amd.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Link: https://patch.msgid.link/20260114164837.1076338-14-rrichter@amd.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent d1c9ba4 commit 208f432

3 files changed

Lines changed: 36 additions & 9 deletions

File tree

drivers/cxl/core/atl.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,11 @@ static int cxl_prm_setup_root(struct cxl_root *cxl_root, void *data)
169169
* decoders in the BIOS would prevent a capable kernel (or
170170
* other operating systems) from shutting down auto-generated
171171
* regions and managing resources dynamically.
172+
*
173+
* Indicate that Normalized Addressing is enabled.
172174
*/
173175
cxld->flags |= CXL_DECODER_F_LOCK;
176+
cxld->flags |= CXL_DECODER_F_NORMALIZED_ADDRESSING;
174177

175178
ctx->hpa_range = hpa_range;
176179
ctx->interleave_ways = ways;

drivers/cxl/core/region.c

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,14 +1097,16 @@ static int cxl_rr_assign_decoder(struct cxl_port *port, struct cxl_region *cxlr,
10971097
return 0;
10981098
}
10991099

1100-
static void cxl_region_set_lock(struct cxl_region *cxlr,
1101-
struct cxl_decoder *cxld)
1100+
static void cxl_region_setup_flags(struct cxl_region *cxlr,
1101+
struct cxl_decoder *cxld)
11021102
{
1103-
if (!test_bit(CXL_DECODER_F_LOCK, &cxld->flags))
1104-
return;
1103+
if (test_bit(CXL_DECODER_F_LOCK, &cxld->flags)) {
1104+
set_bit(CXL_REGION_F_LOCK, &cxlr->flags);
1105+
clear_bit(CXL_REGION_F_NEEDS_RESET, &cxlr->flags);
1106+
}
11051107

1106-
set_bit(CXL_REGION_F_LOCK, &cxlr->flags);
1107-
clear_bit(CXL_REGION_F_NEEDS_RESET, &cxlr->flags);
1108+
if (test_bit(CXL_DECODER_F_NORMALIZED_ADDRESSING, &cxld->flags))
1109+
set_bit(CXL_REGION_F_NORMALIZED_ADDRESSING, &cxlr->flags);
11081110
}
11091111

11101112
/**
@@ -1218,7 +1220,7 @@ static int cxl_port_attach_region(struct cxl_port *port,
12181220
}
12191221
}
12201222

1221-
cxl_region_set_lock(cxlr, cxld);
1223+
cxl_region_setup_flags(cxlr, cxld);
12221224

12231225
rc = cxl_rr_ep_add(cxl_rr, cxled);
12241226
if (rc) {
@@ -2493,7 +2495,7 @@ static struct cxl_region *cxl_region_alloc(struct cxl_root_decoder *cxlrd, int i
24932495
device_set_pm_not_required(dev);
24942496
dev->bus = &cxl_bus_type;
24952497
dev->type = &cxl_region_type;
2496-
cxl_region_set_lock(cxlr, &cxlrd->cxlsd.cxld);
2498+
cxl_region_setup_flags(cxlr, &cxlrd->cxlsd.cxld);
24972499

24982500
return cxlr;
24992501
}
@@ -3132,6 +3134,13 @@ u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd,
31323134
u8 eiw = 0;
31333135
int pos;
31343136

3137+
/*
3138+
* Conversion between SPA and DPA is not supported in
3139+
* Normalized Address mode.
3140+
*/
3141+
if (test_bit(CXL_REGION_F_NORMALIZED_ADDRESSING, &cxlr->flags))
3142+
return ULLONG_MAX;
3143+
31353144
for (int i = 0; i < p->nr_targets; i++) {
31363145
if (cxlmd == cxled_to_memdev(p->targets[i])) {
31373146
cxled = p->targets[i];
@@ -3922,6 +3931,14 @@ static int cxl_region_setup_poison(struct cxl_region *cxlr)
39223931
struct cxl_region_params *p = &cxlr->params;
39233932
struct dentry *dentry;
39243933

3934+
/*
3935+
* Do not enable poison injection in Normalized Address mode.
3936+
* Conversion between SPA and DPA is required for this, but it is
3937+
* not supported in this mode.
3938+
*/
3939+
if (test_bit(CXL_REGION_F_NORMALIZED_ADDRESSING, &cxlr->flags))
3940+
return 0;
3941+
39253942
/* Create poison attributes if all memdevs support the capabilities */
39263943
for (int i = 0; i < p->nr_targets; i++) {
39273944
struct cxl_endpoint_decoder *cxled = p->targets[i];

drivers/cxl/cxl.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ int cxl_dport_map_rcd_linkcap(struct pci_dev *pdev, struct cxl_dport *dport);
332332
#define CXL_DECODER_F_TYPE3 BIT(3)
333333
#define CXL_DECODER_F_LOCK BIT(4)
334334
#define CXL_DECODER_F_ENABLE BIT(5)
335-
#define CXL_DECODER_F_MASK GENMASK(5, 0)
335+
#define CXL_DECODER_F_NORMALIZED_ADDRESSING BIT(6)
336336

337337
enum cxl_decoder_type {
338338
CXL_DECODER_DEVMEM = 2,
@@ -525,6 +525,13 @@ enum cxl_partition_mode {
525525
*/
526526
#define CXL_REGION_F_LOCK 2
527527

528+
/*
529+
* Indicate Normalized Addressing. Use it to disable SPA conversion if
530+
* HPA != SPA and an address translation callback handler does not
531+
* exist. Flag is needed by AMD Zen5 platforms.
532+
*/
533+
#define CXL_REGION_F_NORMALIZED_ADDRESSING 3
534+
528535
/**
529536
* struct cxl_region - CXL region
530537
* @dev: This region's device

0 commit comments

Comments
 (0)