* [PATCH] hw/cxl: fix DC extent capacity tracking
@ 2025-05-20 19:56 nifan.cxl
2025-05-28 17:39 ` Fan Ni
2025-05-29 14:31 ` Jonathan Cameron via
0 siblings, 2 replies; 3+ messages in thread
From: nifan.cxl @ 2025-05-20 19:56 UTC (permalink / raw)
To: jonathan.cameron, qemu-devel
Cc: linux-cxl, a.manzanares, dave, nmtadam.samsung, nifan.cxl,
anisa.su887, gourry, Fan Ni
From: Fan Ni <fan.ni@samsung.com>
Per cxl r3.2 Section 9.13.3.3, extent capacity tracking should include
extents in different states including added, pending, etc.
Before the change, for the in-device extent number tracking purpose, we only
have "total_extent_count" defined, which only tracks the number of
extents accepted. However, we need to track number of extents in other
states also, for now it is extents pending-to-add.
To fix that, we introduce a new counter for dynamic capacity
"nr_extents_accepted" which explicitly tracks number of the extents
accepted by the hosts, and fix "total_extent_count" to include
both accepted and pending extents counting.
Signed-off-by: Fan Ni <fan.ni@samsung.com>
---
hw/cxl/cxl-mailbox-utils.c | 26 ++++++++++++++++++--------
hw/mem/cxl_type3.c | 1 +
include/hw/cxl/cxl_device.h | 3 ++-
3 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
index 299f232f26..0b615ea37a 100644
--- a/hw/cxl/cxl-mailbox-utils.c
+++ b/hw/cxl/cxl-mailbox-utils.c
@@ -2750,7 +2750,7 @@ static CXLRetCode cmd_dcd_get_dyn_cap_ext_list(const struct cxl_cmd *cmd,
uint16_t out_pl_len, size;
CXLDCExtent *ent;
- if (start_extent_id > ct3d->dc.total_extent_count) {
+ if (start_extent_id > ct3d->dc.nr_extents_accepted) {
return CXL_MBOX_INVALID_INPUT;
}
@@ -2761,7 +2761,7 @@ static CXLRetCode cmd_dcd_get_dyn_cap_ext_list(const struct cxl_cmd *cmd,
out_pl_len = sizeof(*out) + record_count * sizeof(out->records[0]);
stl_le_p(&out->count, record_count);
- stl_le_p(&out->total_extents, ct3d->dc.total_extent_count);
+ stl_le_p(&out->total_extents, ct3d->dc.nr_extents_accepted);
stl_le_p(&out->generation_num, ct3d->dc.ext_list_gen_seq);
if (record_count > 0) {
@@ -2883,16 +2883,20 @@ void cxl_extent_group_list_insert_tail(CXLDCExtentGroupList *list,
QTAILQ_INSERT_TAIL(list, group, node);
}
-void cxl_extent_group_list_delete_front(CXLDCExtentGroupList *list)
+uint32_t cxl_extent_group_list_delete_front(CXLDCExtentGroupList *list)
{
CXLDCExtent *ent, *ent_next;
CXLDCExtentGroup *group = QTAILQ_FIRST(list);
+ uint32_t extents_deleted = 0;
QTAILQ_REMOVE(list, group, node);
QTAILQ_FOREACH_SAFE(ent, &group->list, node, ent_next) {
cxl_remove_extent_from_extent_list(&group->list, ent);
+ extents_deleted++;
}
g_free(group);
+
+ return extents_deleted;
}
/*
@@ -3011,7 +3015,7 @@ static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const struct cxl_cmd *cmd,
CXLUpdateDCExtentListInPl *in = (void *)payload_in;
CXLType3Dev *ct3d = CXL_TYPE3(cci->d);
CXLDCExtentList *extent_list = &ct3d->dc.extents;
- uint32_t i;
+ uint32_t i, num;
uint64_t dpa, len;
CXLRetCode ret;
@@ -3020,7 +3024,8 @@ static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const struct cxl_cmd *cmd,
}
if (in->num_entries_updated == 0) {
- cxl_extent_group_list_delete_front(&ct3d->dc.extents_pending);
+ num = cxl_extent_group_list_delete_front(&ct3d->dc.extents_pending);
+ ct3d->dc.total_extent_count -= num;
return CXL_MBOX_SUCCESS;
}
@@ -3051,10 +3056,12 @@ static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const struct cxl_cmd *cmd,
cxl_insert_extent_to_extent_list(extent_list, dpa, len, NULL, 0);
ct3d->dc.total_extent_count += 1;
+ ct3d->dc.nr_extents_accepted += 1;
ct3_set_region_block_backed(ct3d, dpa, len);
}
/* Remove the first extent group in the pending list */
- cxl_extent_group_list_delete_front(&ct3d->dc.extents_pending);
+ num = cxl_extent_group_list_delete_front(&ct3d->dc.extents_pending);
+ ct3d->dc.total_extent_count -= num;
return CXL_MBOX_SUCCESS;
}
@@ -3160,7 +3167,7 @@ free_and_exit:
}
*updated_list_size = 0;
} else {
- *updated_list_size = ct3d->dc.total_extent_count + cnt_delta;
+ *updated_list_size = ct3d->dc.nr_extents_accepted + cnt_delta;
}
return ret;
@@ -3222,7 +3229,10 @@ static CXLRetCode cmd_dcd_release_dyn_cap(const struct cxl_cmd *cmd,
ct3_set_region_block_backed(ct3d, ent->start_dpa, ent->len);
cxl_remove_extent_from_extent_list(&updated_list, ent);
}
- ct3d->dc.total_extent_count = updated_list_size;
+ ct3d->dc.total_extent_count += (updated_list_size -
+ ct3d->dc.nr_extents_accepted);
+
+ ct3d->dc.nr_extents_accepted = updated_list_size;
return CXL_MBOX_SUCCESS;
}
diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c
index 94e7274912..f283178d88 100644
--- a/hw/mem/cxl_type3.c
+++ b/hw/mem/cxl_type3.c
@@ -2076,6 +2076,7 @@ static void qmp_cxl_process_dynamic_capacity_prescriptive(const char *path,
}
if (group) {
cxl_extent_group_list_insert_tail(&dcd->dc.extents_pending, group);
+ dcd->dc.total_extent_count += num_extents;
}
/*
diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h
index ed6cd50c67..a151e19da8 100644
--- a/include/hw/cxl/cxl_device.h
+++ b/include/hw/cxl/cxl_device.h
@@ -618,6 +618,7 @@ struct CXLType3Dev {
CXLDCExtentList extents;
CXLDCExtentGroupList extents_pending;
uint32_t total_extent_count;
+ uint32_t nr_extents_accepted;
uint32_t ext_list_gen_seq;
uint8_t num_regions; /* 0-8 regions */
@@ -696,7 +697,7 @@ CXLDCExtentGroup *cxl_insert_extent_to_extent_group(CXLDCExtentGroup *group,
uint16_t shared_seq);
void cxl_extent_group_list_insert_tail(CXLDCExtentGroupList *list,
CXLDCExtentGroup *group);
-void cxl_extent_group_list_delete_front(CXLDCExtentGroupList *list);
+uint32_t cxl_extent_group_list_delete_front(CXLDCExtentGroupList *list);
void ct3_set_region_block_backed(CXLType3Dev *ct3d, uint64_t dpa,
uint64_t len);
void ct3_clear_region_block_backed(CXLType3Dev *ct3d, uint64_t dpa,
--
2.47.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] hw/cxl: fix DC extent capacity tracking
2025-05-20 19:56 [PATCH] hw/cxl: fix DC extent capacity tracking nifan.cxl
@ 2025-05-28 17:39 ` Fan Ni
2025-05-29 14:31 ` Jonathan Cameron via
1 sibling, 0 replies; 3+ messages in thread
From: Fan Ni @ 2025-05-28 17:39 UTC (permalink / raw)
To: nifan.cxl
Cc: jonathan.cameron, qemu-devel, linux-cxl, a.manzanares, dave,
nmtadam.samsung, anisa.su887, gourry
On Tue, May 20, 2025 at 12:56:43PM -0700, nifan.cxl@gmail.com wrote:
> From: Fan Ni <fan.ni@samsung.com>
>
> Per cxl r3.2 Section 9.13.3.3, extent capacity tracking should include
> extents in different states including added, pending, etc.
>
> Before the change, for the in-device extent number tracking purpose, we only
> have "total_extent_count" defined, which only tracks the number of
> extents accepted. However, we need to track number of extents in other
> states also, for now it is extents pending-to-add.
>
> To fix that, we introduce a new counter for dynamic capacity
> "nr_extents_accepted" which explicitly tracks number of the extents
> accepted by the hosts, and fix "total_extent_count" to include
> both accepted and pending extents counting.
>
> Signed-off-by: Fan Ni <fan.ni@samsung.com>
Ping ...
Hi Jonathan,
The FM DCD management mailbox patches needs to be on top of this fix.
Fan
> ---
> hw/cxl/cxl-mailbox-utils.c | 26 ++++++++++++++++++--------
> hw/mem/cxl_type3.c | 1 +
> include/hw/cxl/cxl_device.h | 3 ++-
> 3 files changed, 21 insertions(+), 9 deletions(-)
>
> diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
> index 299f232f26..0b615ea37a 100644
> --- a/hw/cxl/cxl-mailbox-utils.c
> +++ b/hw/cxl/cxl-mailbox-utils.c
> @@ -2750,7 +2750,7 @@ static CXLRetCode cmd_dcd_get_dyn_cap_ext_list(const struct cxl_cmd *cmd,
> uint16_t out_pl_len, size;
> CXLDCExtent *ent;
>
> - if (start_extent_id > ct3d->dc.total_extent_count) {
> + if (start_extent_id > ct3d->dc.nr_extents_accepted) {
> return CXL_MBOX_INVALID_INPUT;
> }
>
> @@ -2761,7 +2761,7 @@ static CXLRetCode cmd_dcd_get_dyn_cap_ext_list(const struct cxl_cmd *cmd,
> out_pl_len = sizeof(*out) + record_count * sizeof(out->records[0]);
>
> stl_le_p(&out->count, record_count);
> - stl_le_p(&out->total_extents, ct3d->dc.total_extent_count);
> + stl_le_p(&out->total_extents, ct3d->dc.nr_extents_accepted);
> stl_le_p(&out->generation_num, ct3d->dc.ext_list_gen_seq);
>
> if (record_count > 0) {
> @@ -2883,16 +2883,20 @@ void cxl_extent_group_list_insert_tail(CXLDCExtentGroupList *list,
> QTAILQ_INSERT_TAIL(list, group, node);
> }
>
> -void cxl_extent_group_list_delete_front(CXLDCExtentGroupList *list)
> +uint32_t cxl_extent_group_list_delete_front(CXLDCExtentGroupList *list)
> {
> CXLDCExtent *ent, *ent_next;
> CXLDCExtentGroup *group = QTAILQ_FIRST(list);
> + uint32_t extents_deleted = 0;
>
> QTAILQ_REMOVE(list, group, node);
> QTAILQ_FOREACH_SAFE(ent, &group->list, node, ent_next) {
> cxl_remove_extent_from_extent_list(&group->list, ent);
> + extents_deleted++;
> }
> g_free(group);
> +
> + return extents_deleted;
> }
>
> /*
> @@ -3011,7 +3015,7 @@ static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const struct cxl_cmd *cmd,
> CXLUpdateDCExtentListInPl *in = (void *)payload_in;
> CXLType3Dev *ct3d = CXL_TYPE3(cci->d);
> CXLDCExtentList *extent_list = &ct3d->dc.extents;
> - uint32_t i;
> + uint32_t i, num;
> uint64_t dpa, len;
> CXLRetCode ret;
>
> @@ -3020,7 +3024,8 @@ static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const struct cxl_cmd *cmd,
> }
>
> if (in->num_entries_updated == 0) {
> - cxl_extent_group_list_delete_front(&ct3d->dc.extents_pending);
> + num = cxl_extent_group_list_delete_front(&ct3d->dc.extents_pending);
> + ct3d->dc.total_extent_count -= num;
> return CXL_MBOX_SUCCESS;
> }
>
> @@ -3051,10 +3056,12 @@ static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const struct cxl_cmd *cmd,
>
> cxl_insert_extent_to_extent_list(extent_list, dpa, len, NULL, 0);
> ct3d->dc.total_extent_count += 1;
> + ct3d->dc.nr_extents_accepted += 1;
> ct3_set_region_block_backed(ct3d, dpa, len);
> }
> /* Remove the first extent group in the pending list */
> - cxl_extent_group_list_delete_front(&ct3d->dc.extents_pending);
> + num = cxl_extent_group_list_delete_front(&ct3d->dc.extents_pending);
> + ct3d->dc.total_extent_count -= num;
>
> return CXL_MBOX_SUCCESS;
> }
> @@ -3160,7 +3167,7 @@ free_and_exit:
> }
> *updated_list_size = 0;
> } else {
> - *updated_list_size = ct3d->dc.total_extent_count + cnt_delta;
> + *updated_list_size = ct3d->dc.nr_extents_accepted + cnt_delta;
> }
>
> return ret;
> @@ -3222,7 +3229,10 @@ static CXLRetCode cmd_dcd_release_dyn_cap(const struct cxl_cmd *cmd,
> ct3_set_region_block_backed(ct3d, ent->start_dpa, ent->len);
> cxl_remove_extent_from_extent_list(&updated_list, ent);
> }
> - ct3d->dc.total_extent_count = updated_list_size;
> + ct3d->dc.total_extent_count += (updated_list_size -
> + ct3d->dc.nr_extents_accepted);
> +
> + ct3d->dc.nr_extents_accepted = updated_list_size;
>
> return CXL_MBOX_SUCCESS;
> }
> diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c
> index 94e7274912..f283178d88 100644
> --- a/hw/mem/cxl_type3.c
> +++ b/hw/mem/cxl_type3.c
> @@ -2076,6 +2076,7 @@ static void qmp_cxl_process_dynamic_capacity_prescriptive(const char *path,
> }
> if (group) {
> cxl_extent_group_list_insert_tail(&dcd->dc.extents_pending, group);
> + dcd->dc.total_extent_count += num_extents;
> }
>
> /*
> diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h
> index ed6cd50c67..a151e19da8 100644
> --- a/include/hw/cxl/cxl_device.h
> +++ b/include/hw/cxl/cxl_device.h
> @@ -618,6 +618,7 @@ struct CXLType3Dev {
> CXLDCExtentList extents;
> CXLDCExtentGroupList extents_pending;
> uint32_t total_extent_count;
> + uint32_t nr_extents_accepted;
> uint32_t ext_list_gen_seq;
>
> uint8_t num_regions; /* 0-8 regions */
> @@ -696,7 +697,7 @@ CXLDCExtentGroup *cxl_insert_extent_to_extent_group(CXLDCExtentGroup *group,
> uint16_t shared_seq);
> void cxl_extent_group_list_insert_tail(CXLDCExtentGroupList *list,
> CXLDCExtentGroup *group);
> -void cxl_extent_group_list_delete_front(CXLDCExtentGroupList *list);
> +uint32_t cxl_extent_group_list_delete_front(CXLDCExtentGroupList *list);
> void ct3_set_region_block_backed(CXLType3Dev *ct3d, uint64_t dpa,
> uint64_t len);
> void ct3_clear_region_block_backed(CXLType3Dev *ct3d, uint64_t dpa,
> --
> 2.47.2
>
--
Fan Ni (From gmail)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] hw/cxl: fix DC extent capacity tracking
2025-05-20 19:56 [PATCH] hw/cxl: fix DC extent capacity tracking nifan.cxl
2025-05-28 17:39 ` Fan Ni
@ 2025-05-29 14:31 ` Jonathan Cameron via
1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Cameron via @ 2025-05-29 14:31 UTC (permalink / raw)
To: nifan.cxl
Cc: qemu-devel, linux-cxl, a.manzanares, dave, nmtadam.samsung,
anisa.su887, gourry, Fan Ni
On Tue, 20 May 2025 12:56:43 -0700
nifan.cxl@gmail.com wrote:
> From: Fan Ni <fan.ni@samsung.com>
>
> Per cxl r3.2 Section 9.13.3.3, extent capacity tracking should include
> extents in different states including added, pending, etc.
>
> Before the change, for the in-device extent number tracking purpose, we only
> have "total_extent_count" defined, which only tracks the number of
> extents accepted. However, we need to track number of extents in other
> states also, for now it is extents pending-to-add.
>
> To fix that, we introduce a new counter for dynamic capacity
> "nr_extents_accepted" which explicitly tracks number of the extents
> accepted by the hosts, and fix "total_extent_count" to include
> both accepted and pending extents counting.
Hi Fan,
This is complex code but looks correct to me - I'd managed to forget
all the weird ways the extent counts can go up and down - most of
which Linux doesn't actually hit.
For fixes like this can save a bit of time by +CC mst@redhat.com then
it just needs a review tag from me (or you if it is me sending).
I only have that other regloc fix and just sent that out for review
with mst +CC so maybe just send a v2 of this (rebased on upstream)
and add
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-05-29 14:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-20 19:56 [PATCH] hw/cxl: fix DC extent capacity tracking nifan.cxl
2025-05-28 17:39 ` Fan Ni
2025-05-29 14:31 ` Jonathan Cameron via
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).