hw/cxl: Add support for scan media.
cover hw/cxl: Add support for scan media.
Now DCD is upstream, a number of sets that were dependent on it, that have otherwise been in a good state for a long time, are (hopefully) ready to upstream. I was also holding back series that were less critical for kernel testing to make sure they didn't distract from the progress of Dynamic Capacity.
This 1st series includes a couple of more general improvements that interact closely with the scan media changes. This series applies directly on master and can go in parallel to
[PATCH qemu v2 0/3] hw/cxl: Misc minor improvements
The Scan Media commands enable recovery from the situation where a poison list has overflowed and the OS has no other way to find out which memory is bad, or because the user wants force a recheck for uncorrectable ECC errors. This functionality is emulated by keeping an additional list of injected poison that is not exposed via the existing get poison list command. This list is 'discovered' during processing of Scan Media as if the hardware had detected these errors in real memory.
Davidlohr Bueso (2):
hw/cxl: Add get scan media capabilities cmd support hw/cxl: Add get scan media results cmd support
Hyeonggon Yoo (2):
hw/cxl/mbox: replace sanitize_running() with cxl_dev_media_disabled() hw/cxl/events: discard all event records during sanitation
include/hw/cxl/cxl_device.h | 15 +- hw/cxl/cxl-events.c | 13 ++ hw/cxl/cxl-mailbox-utils.c | 326 ++++++++++++++++++++++++++++++++++-- hw/mem/cxl_type3.c | 26 ++- 4 files changed, 355 insertions(+), 25 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/4 hw/cxl: Add get scan media capabilities cmd support
From: Davidlohr Bueso <[email protected]>
Use simple heuristics to determine the cost of scanning any given chunk, assuming cost is equal across the whole device, without differentiating between volatile or persistent partitions. This is aligned to the fact that these constraints are not enforced in respective poison query commands.
---
Tweaks: Update reference to 3.1 specification given 3.0 not easily available any more.
--- include/hw/cxl/cxl_device.h | 9 ++ hw/cxl/cxl-mailbox-utils.c | 211 +++++++++++++++++++++++++++++++++++- hw/mem/cxl_type3.c | 22 ++-- 3 files changed, 233 insertions(+), 9 deletions(-)
include/hw/cxl/cxl_device.h +9 -0
@@ -397,6 +397,11 @@ static inline void __toggle_media(CXLDeviceState *cxl_dstate, int val)#define cxl_dev_enable_media (cxlds) \ do { __toggle_media((cxlds), 0x1); } while (0) +static inline bool scan_media_running (CXLCCI *cci) +{ +return !!cci->bg.runtime && cci->bg.opcode ==0x4304 ; +} +static inline bool sanitize_running (CXLCCI *cci) {return !!cci->bg.runtime && cci->bg.opcode ==0x4400 ;
@@ -491,6 +496,9 @@ struct CXLType3Dev {unsigned int poison_list_cnt;bool poison_list_overflowed;uint64_t poison_list_overflow_ts; +/* Poison Injection - backup */ +CXLPoisonList poison_list_bkp; +CXLPoisonList scan_media_results;struct dynamic_capacity {HostMemoryBackend *host_dc;
@@ -558,6 +566,7 @@ CXLRetCode cxl_event_clear_records(CXLDeviceState *cxlds,void cxl_event_irq_assert (CXLType3Dev *ct3d);void cxl_set_poison_list_overflowed (CXLType3Dev *ct3d); +void cxl_clear_poison_list_overflowed (CXLType3Dev *ct3d);CXLDCRegion *cxl_find_dc_region (CXLType3Dev *ct3d,uint64_t dpa,uint64_t len);
hw/cxl/cxl-mailbox-utils.c +209 -2
271 lines not on this page · raw message
hw/mem/cxl_type3.c +15 -7
@@ -1304,6 +1304,12 @@ void cxl_set_poison_list_overflowed(CXLType3Dev *ct3d)cxl_device_get_timestamp (&ct3d->cxl_dstate); } +void cxl_clear_poison_list_overflowed (CXLType3Dev *ct3d) +{ + ct3d->poison_list_overflowed = false; + ct3d->poison_list_overflow_ts =0 ; +} +void qmp_cxl_inject_poison (const char *path,uint64_t start,uint64_t length,Error **errp) {
@@ -1340,19 +1346,21 @@ void qmp_cxl_inject_poison(const char *path, uint64_t start, uint64_t length, } } -if (ct3d->poison_list_cnt ==CXL_POISON_LIST_LIMIT ) { -cxl_set_poison_list_overflowed (ct3d); -return ; - } - p =g_new0 (CXLPoison,1 ); p->length = length; p->start = start;/* Different from injected via the mbox */ p->type =CXL_POISON_TYPE_INTERNAL ; -QLIST_INSERT_HEAD (&ct3d->poison_list, p, node); - ct3d->poison_list_cnt++; +if (ct3d->poison_list_cnt <CXL_POISON_LIST_LIMIT ) { +QLIST_INSERT_HEAD (&ct3d->poison_list, p, node); + ct3d->poison_list_cnt++; + }else { +if (!ct3d->poison_list_overflowed) { +cxl_set_poison_list_overflowed (ct3d); + } +QLIST_INSERT_HEAD (&ct3d->poison_list_bkp, p, node); + } }/* For uncorrectable errors include support for multiple header recording */
Signature · 1 line
2.43.0
PATCH 2/4 hw/cxl/mbox: replace sanitize_running() with cxl_dev_media_disabled()
In reply to Jonathan CameronFrom: Hyeonggon Yoo <[email protected]>
The spec states that reads/writes should have no effect and a part of commands should be ignored when the media is disabled, not when the sanitize command is running.
Introduce cxl_dev_media_disabled() to check if the media is disabled and replace sanitize_running() with it.
Make sure that the media has been correctly disabled during sanitation by adding an assert to __toggle_media(). Now, enabling when already enabled or vice versa results in an assert() failure.
---
Fix added to ensure the state sanity check only applies on type3 devices
--- include/hw/cxl/cxl_device.h | 10 +++++----- hw/cxl/cxl-mailbox-utils.c | 29 +++++++++++++++++------------ hw/mem/cxl_type3.c | 4 ++-- 3 files changed, 24 insertions(+), 19 deletions(-)
include/hw/cxl/cxl_device.h +5 -5
@@ -397,14 +397,14 @@ static inline void __toggle_media(CXLDeviceState *cxl_dstate, int val)#define cxl_dev_enable_media (cxlds) \ do { __toggle_media((cxlds), 0x1); } while (0) -static inline bool scan_media_running (CXLCCI *cci) +static inline bool cxl_dev_media_disabled (CXLDeviceState *cxl_dstate) { -return !!cci->bg.runtime && cci->bg.opcode ==0x4304 ; +uint64_t dev_status_reg = cxl_dstate->mbox_reg_state64[R_CXL_MEM_DEV_STS ]; +return FIELD_EX64 (dev_status_reg,CXL_MEM_DEV_STS ,MEDIA_STATUS ) ==0x3 ; } - -static inline bool sanitize_running (CXLCCI *cci) +static inline bool scan_media_running (CXLCCI *cci) { -return !!cci->bg.runtime && cci->bg.opcode ==0x4400 ; +return !!cci->bg.runtime && cci->bg.opcode ==0x4304 ; } typedef struct CXLError {
hw/cxl/cxl-mailbox-utils.c +17 -12
@@ -2115,6 +2115,7 @@ int cxl_process_cci_message(CXLCCI *cci, uint8_t set, uint8_t cmd,int ret;const struct cxl_cmd *cxl_cmd;opcode_handler h; +CXLDeviceState *cxl_dstate; *len_out =0 ; cxl_cmd = &cci->cxl_cmd_set[set][cmd];
@@ -2135,18 +2136,22 @@ int cxl_process_cci_message(CXLCCI *cci, uint8_t set, uint8_t cmd,return CXL_MBOX_BUSY ; } -/* forbid any selected commands while overwriting */ -if (sanitize_running (cci)) { -if (h == cmd_events_get_records || - h == cmd_ccls_get_partition_info || - h == cmd_ccls_set_lsa || - h == cmd_ccls_get_lsa || - h == cmd_logs_get_log || - h == cmd_media_get_poison_list || - h == cmd_media_inject_poison || - h == cmd_media_clear_poison || - h == cmd_sanitize_overwrite) { -return CXL_MBOX_MEDIA_DISABLED ; +/* forbid any selected commands while the media is disabled */ +if (object_dynamic_cast (OBJECT (cci->d),TYPE_CXL_TYPE3 )) { + cxl_dstate = &CXL_TYPE3 (cci->d)->cxl_dstate; + +if (cxl_dev_media_disabled (cxl_dstate)) { +if (h == cmd_events_get_records || + h == cmd_ccls_get_partition_info || + h == cmd_ccls_set_lsa || + h == cmd_ccls_get_lsa || + h == cmd_logs_get_log || + h == cmd_media_get_poison_list || + h == cmd_media_inject_poison || + h == cmd_media_clear_poison || + h == cmd_sanitize_overwrite) { +return CXL_MBOX_MEDIA_DISABLED ; + } } }
hw/mem/cxl_type3.c +2 -2
@@ -1127,7 +1127,7 @@ MemTxResult cxl_type3_read(PCIDevice *d, hwaddr host_addr, uint64_t *data,return MEMTX_ERROR ; } -if (sanitize_running (&ct3d->cci)) { +if (cxl_dev_media_disabled (&ct3d->cxl_dstate)) {qemu_guest_getrandom_nofail (data, size);return MEMTX_OK ; }
@@ -1149,7 +1149,7 @@ MemTxResult cxl_type3_write(PCIDevice *d, hwaddr host_addr, uint64_t data,return MEMTX_ERROR ; } -if (sanitize_running (&ct3d->cci)) { +if (cxl_dev_media_disabled (&ct3d->cxl_dstate)) {return MEMTX_OK ; }
Signature · 1 line
2.43.0
PATCH 3/4 hw/cxl/events: discard all event records during sanitation
In reply to Jonathan CameronFrom: Hyeonggon Yoo <[email protected]>
Per CXL r3.1 Section 8.2.9.9.5.1: Sanitize (Opcode 4400h), the sanitize command should delete all event logs. Introduce cxl_discard_all_event_logs() and call
this in __do_sanitization().
---
Tweaks: Made the reference in this description clearly refer to the 3.1 specification version.
--- include/hw/cxl/cxl_device.h | 1 + hw/cxl/cxl-events.c | 13 +++++++++++++ hw/cxl/cxl-mailbox-utils.c | 1 + 3 files changed, 15 insertions(+)
include/hw/cxl/cxl_device.h +1 -0
@@ -562,6 +562,7 @@ CXLRetCode cxl_event_get_records(CXLDeviceState *cxlds, CXLGetEventPayload *pl, size_t *len);CXLRetCode cxl_event_clear_records (CXLDeviceState *cxlds,CXLClearEventPayload *pl); +void cxl_discard_all_event_records (CXLDeviceState *cxlds);void cxl_event_irq_assert (CXLType3Dev *ct3d);
hw/cxl/cxl-events.c +13 -0
@@ -139,6 +139,19 @@ bool cxl_event_insert(CXLDeviceState *cxlds, CXLEventLogType log_type,return cxl_event_count (log) ==1 ; } +void cxl_discard_all_event_records (CXLDeviceState *cxlds) +{ +CXLEventLogType log_type; +CXLEventLog *log; + +for (log_type =0 ; log_type <CXL_EVENT_TYPE_MAX ; log_type++) { + log = &cxlds->event_logs[log_type]; +while (!cxl_event_empty (log)) { +cxl_event_delete_head (cxlds, log_type, log); + } + } +} +CXLRetCode cxl_event_get_records (CXLDeviceState *cxlds,CXLGetEventPayload *pl,uint8_t log_type,int max_recs,size_t *len)
hw/cxl/cxl-mailbox-utils.c +1 -0
@@ -955,6 +955,7 @@ static void __do_sanitization(CXLType3Dev *ct3d)memset (lsa,0 ,memory_region_size (mr)); } } +cxl_discard_all_event_records (&ct3d->cxl_dstate); }/*
Signature · 1 line
2.43.0
PATCH 4/4 hw/cxl: Add get scan media results cmd support
In reply to Jonathan CameronFrom: Davidlohr Bueso <[email protected]>
Iterate over the list keeping the output payload size into account, returning the results from a previous scan media operation. The scan media operation does not fail prematurely due to device being out of storage, so this implementation does not deal with the retry/restart functionality.
---
Tweak - update references to point to CXL r3.1 given lack of easy availability of r3.0.
--- include/hw/cxl/cxl_device.h | 1 + hw/cxl/cxl-mailbox-utils.c | 85 +++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+)
include/hw/cxl/cxl_device.h +1 -0
@@ -499,6 +499,7 @@ struct CXLType3Dev {/* Poison Injection - backup */ CXLPoisonList poison_list_bkp;CXLPoisonList scan_media_results; +bool scan_media_hasrun;struct dynamic_capacity {HostMemoryBackend *host_dc;
hw/cxl/cxl-mailbox-utils.c +85 -0
109 lines not on this page · raw message
Signature · 1 line
2.43.0