From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796356092; b=jjIRJgp0W8RbOLeRYVlDkdX+H3cDhqgDKucvk/REr0Of7PDtOHrfMuaIpu2SqkB9vc7o B1HNOt+VEh3fyQ0uinSGnxwMXmxlC3q7dI2ly5djO2I2tb2HxFJ8pxUIZgZ8oMYHNI5tq UxEfvfIrYRL0Ox3d3s9JKG5Pg5sRepNIgi2MnN8QNo/ASwyCMEOqGdMSjNMFJo9ZHcTJF LdnuIccqpRMMu2d1snRnSw2gRvP/QVH/ygASyN6yEWDioscy+ncZdbYob1Mt6HkRkSGgn ptKAJupr8G0yv9cv1VcV3AH8hHRiI101SLfCCG5wX0s/45yGevUYiO7NzqZM0+7rTgw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796356092; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:X-Google-Original-From:Date:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=FLt6CczZOg2uxZKiVT3mUtb0P/AMKQhzDG18uofYNz0=; b=0XxLD60ya/yUh36C5Z3uKNDNRSz+fslcIwGedZ5zYris2/QZ98tnAqatVyyD1QGJWtjR s7Yiih7hpCHTrCJXLw7+Qb5HiTadJBooVBpsITo+lsSPb6SVWd8RXxrwotzz3jAmNkQAk dKacSpCuZIGFjUzUQsl7GVbhj+PLJfZYywWsfGwEoOdd46RBalZgOQb2Xq4rlTGD4/3AS VD5h7An+FYkhSiUVQy/BoZ0lwqTv2qUt2B0S/uAR1WeGgRGmbCgv9MG6zonvOG4Uyqy9i xiwuWy0nv2dd8eSILysFhgDhHXq0c+4V5TZ681z1sRE3DjNv9QFXhaPK1miUBCmgMNg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=pepxtoOn; arc=none smtp.remote-ip=209.85.210.171 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08AD9606A32C for ; Fri, 4 Dec 2026 03:48:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 08AD9606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=pepxtoOn Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-8b4c8b51b58so362334b3a.1 for ; Thu, 03 Dec 2026 19:48:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796356090; x=1796960890; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:date:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=FLt6CczZOg2uxZKiVT3mUtb0P/AMKQhzDG18uofYNz0=; b=pepxtoOntXfT0YC3ApmESgRlOsXJSWeUyTjGVcve2f6nRFGMGenaYr0zOcfGdJboVU Fiv4aS5w92nrOQfpBMMag74pVQXcAuqiQ50zvUKEMYZHkYM+ASlAxfAW1+BI1nBbB/A4 75Sdf3VJ39ck9pAP9cu8cYaWmczEG/HbxolslmO4NryChCFiFapxKCgu1YKzXxIcW3kC Vfvuyd4JR9Yn4mLrjGdWSznkJ/bDGqpKLCr+/G3Ts08/rMVtzTuWB+dTo125wpGXrfjY fKDZOQTWmWzTJIGUrm0dGINRHcnt5dAsA4uOlfR8RZPeprKOdy35cSyP63t8dOdzs/R8 4QXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796356090; x=1796960890; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=FLt6CczZOg2uxZKiVT3mUtb0P/AMKQhzDG18uofYNz0=; b=bWz7RI3GWnLjwrp8QLTKfeRxQd8nG5R24uC71GKH1t/L6ECs2O2V09veZgwb/IHkhq pWikv4HKbA86nBp5xYGRtG6xby2IrDhecbfIgzzo0VxfKRrHQfpBdR2KlaJSMozflTq0 6H8dOefmj1asQUP05oAumm4m0C5uYJgO/6boFiU7J6PQo7OSfyUiwaJUTVT8e1xGmm2V RlTjN2Dn7AcPrQIBOYccE3mAxgMlfw+c7TO5OstUEHA6iUSod2nu+RJZvDjG5IYcjaDv LroZUXD4KbPDSa2tcg54s2+2kZAlcffDxNUCBAXqDziQ2w4ESL2Z79r+DQz+TLtjMhHh NzqA== X-Forwarded-Encrypted: i=1; AL+hErFmEC3DRdo+YxQonyetQiwRV7wRY6DWI1SuqPv71+BdD8f0LZ9/nQre70xPK1ehSmrcTMQIZNlDHRU=@vger.kernel.org X-Gm-Message-State: APuU4Z+zdALR6GmJnKkof80rWpL6PUM+bQkFOjcqZLmYx7Og7+U9VhIn wg79lIDFORzCuY6NgtfdaZ249H7LLUqoE2v8uExo0q103WEYmNodP1mx X-Gm-Gg: AZFdTZekyOebmbMgoP3+OokWmcpf5uFpV00VcdyA7wp7eCoonkDBYwUz4SCfxdGoxoQ KpeIxk6L3PTU/P4ADFI9/wJebKhfCiwF4qpQiLEDXARfvXkBsKWqNEQ+RGCi1DnOBAp0p64dr/D k7XvAelAl72pOJKMjadVsd9t5270mkfKqe65OWFgQa9f5K7L5N37+PGg9ZqG8pRGMKfka1XkMqM G+EJ3kCI6RxMgzg6XJec1sFUZWxZxub1d8uTuH4HmtSWBB4DNVxjFddwBN13DbzAvTrqR10+QKC lfHN6ZWISLYZWdCaznO6Cy2e9oXQSAIRA2SmnxIPV/CmSf3ZbhatM3SZ8wvuIUJTh6vlBIy3MzZ oDDjpdv589ARfUjUYZmTxQhVQEKc/3YAqTMhcRaWyZqRB9w/YNY1kUycIF2SBDlV3XfjD6vCeKo MecjCn9WxTxOvn3Cc3S2eII4LeuMEk3vTkJP1gw1O+wt+1VVGZ8peksQcKTo7rQANOWIq5s1Ncz 1yCfSCfneF7rkXZ+DieCfA7xpzr+Iou3dzUohPrnwiomwXsp5P5WnypFvfbveeUZTImyQ5YPzjP WBebQ1nJMg14wRG9v8EFTk7Z6g== X-Received: by 2002:a05:6a00:174b:b0:886:84b:3e92 with SMTP id d2e1a72fcca58-8de2e9bc391mr892530b3a.56.1796356090160; Thu, 03 Dec 2026 19:48:10 -0800 (PST) Received: from cxlqual ([220.120.90.131]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8de121f3f95sm604465b3a.11.2026.12.03.19.48.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 19:48:09 -0800 (PST) From: Anisa Su X-Google-Original-From: Anisa Su Date: Fri, 4 Dec 2026 12:50:01 +0900 To: Jonathan Cameron Cc: Anisa Su , linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, Dave Jiang , Alison Schofield , Davidlohr Bueso , Ira Weiny , Vishal Verma , Fan Ni , Li Ming , Benjamin Cheatham , Gregory Price , Richard Cheng Subject: Re: [PATCH v1 04/14] cxl/mem: Introduce DC event handlers Message-ID: References: <20261104230445.66625-1-anisa.su@samsung.com> <20261104230445.66625-5-anisa.su@samsung.com> <20261117025427.48bb687d@jic23-hlaptop> X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261117025427.48bb687d@jic23-hlaptop> On Tue, Nov 17, 2026 at 02:54:27AM +0000, Jonathan Cameron wrote: > On Thu, 5 Nov 2026 08:02:28 +0900 > Anisa Su wrote: > > > From: Ira Weiny > > > > Add the handling skeleton for DC Add and DC Release events. Per CXL > > r4.0 Section 8.2.10.9.9.3, the host is expected to respond to one or > > more Add Capacity Event Record(s) with an Add Dynamic Capacity Response > > (Opcode 4802h) to acknowledge which extents the host accepts for use. > > Similarly, per CXL r4.0 Section 8.2.10.9.9.4, the host is expected to > > respond to Release Capacity Event Record(s) with a Release Dynamic > > Capacity command (Opcode 4803h), or to issue one that is not > > associated with any event to release capacity on its own. > > > > The records of one operation can be chained by the More flag. Chained > > records are contiguous in the event log and share one event type (CXL > > r4.0 Table 8-229), so a single staging context, mds->dc_chain, holds > > the records of the open chain until the closing record (More=0) > > arrives and the chain is processed and responded to as a whole. A > > record that fails to stage, or one of the other type arriving inside an > > open chain, drops the chain: an add is refused with an empty response, > > a release is left for the device to retry. > > > > This commit refuses all extents from Add Capacity chains and acks all > > Release Capacity chains. Subsequent commits implement accepting and > > releasing extents. > > > > Forced Capacity Release and Region Configuration Updated events are > > logged and ignored. > > > > Based on an original patch by Navneet Singh. > > > > Signed-off-by: Ira Weiny > > Co-developed-by: Anisa Su > > Signed-off-by: Anisa Su > > Tested-by: Wonjae Lee > > Tested-by: Junhee Park > > Tested-by: Heesoo Kim > Sashiko does raise an interesting question about trailing events > in a chain after an error. If it's shared capacity we aren't allowed > a partial accept. Otherwise it is fine (I think) but perhaps not complexity we > want. So probably need some flag to say problem occured on a record > with more flag set. Keep dropping until we have had a closing record. > Yes, for simplicity, v2 will just abort the regardless of if the capacity is shared or not. Also IIUC it's really tag groups that must be all or none, and non-shareable capacity can be optionally tagged. So as you suggested, a new flag is aded: + * @discard: a record failed to stage; refuse the chain when it closes ... struct cxl_dc_event_chain { struct list_head pending_extents; u8 event_type; + bool discard; }; Set chain->discard to true if staging fails in handle_dcd_chain_event(): if (chain->discard || stage_pending_extent(&chain->pending_extents, &event->extent)) chain->discard = true; > For force release, I'm not sure if we should just panic() (maybe > with a sanity check that the range was mapped) or ignore it and > die in a storm of poison (hopefully rather than zeros). > Hmm, will do the panic() for v2. The check to see if the capacity is being used belongs to the DAX half, so this half just gets unconditional panic(), which should be fine since DCD is turned off. > > --- > > drivers/cxl/core/mbox.c | 246 ++++++++++++++++++++++++++++++++++++++- > > drivers/cxl/core/trace.h | 3 +- > > drivers/cxl/cxl.h | 9 ++ > > drivers/cxl/cxlmem.h | 46 ++++++++ > > drivers/cxl/pci.c | 20 +++- > > include/cxl/event.h | 37 ++++++ > > 6 files changed, 353 insertions(+), 8 deletions(-) > > > > diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c > > index 13a68f5cef69..3acf5ace48db 100644 > > --- a/drivers/cxl/core/mbox.c > > +++ b/drivers/cxl/core/mbox.c > > > +static int cxl_send_dc_response(struct cxl_memdev_state *mds, int opcode, > > + struct list_head *extent_list, int cnt) > > +{ > > + struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox; > > + struct cxl_mbox_dc_response *p; > > + struct cxl_extent_list_node *pos, *tmp; > > + struct cxl_extent *extent; > > + u32 pl_index; > > + > > + size_t pl_size = struct_size(p, extent_list, cnt); > > + u32 max_extents = cnt; > > + > > + /* May have to use more bit on response. */ > > + if (pl_size > cxl_mbox->payload_size) { > > + max_extents = (cxl_mbox->payload_size - sizeof(*p)) / > > + sizeof(struct updated_extent_list); > > + pl_size = struct_size(p, extent_list, max_extents); > > + } > > + > > + struct cxl_mbox_dc_response *response __free(kfree) = > > + kzalloc(pl_size, GFP_KERNEL); > > + if (!response) { > > + struct cxl_mbox_dc_response empty = { }; > > + > > + /* An empty Release DC is invalid (CXL r4.0 Table 8-352) */ > > + if (opcode == CXL_MBOX_OP_RELEASE_DC) > > + return -ENOMEM; > > + /* Refuse all extents rather than stall the device. */ > > + return send_one_response(cxl_mbox, &empty, opcode, 0, 0); > > + } > > + > > + /* Set __counted_by to capacity before populating; reset per response. */ > > + response->extent_list_size = cpu_to_le32(max_extents); > > + > > + if (cnt == 0) > > + return send_one_response(cxl_mbox, response, opcode, 0, 0); > > + > > + pl_index = 0; > > + list_for_each_entry_safe(pos, tmp, extent_list, list) { > > + extent = pos->extent; > > + response->extent_list[pl_index].dpa_start = extent->start_dpa; > > + response->extent_list[pl_index].length = extent->length; > > + pl_index++; > > + > > + if (pl_index == max_extents) { > Maybe flip? > if (pl_index != max_extents) > continue; > > flags = 0; > > ... Flipped > > > + u8 flags = 0; > > + int rc; > > + > > + if (pl_index < cnt) > > + flags |= CXL_DCD_EVENT_MORE; > > + rc = send_one_response(cxl_mbox, response, opcode, > > + pl_index, flags); > > + if (rc) > > + return rc; > > + cnt -= pl_index; > > + if (cnt < max_extents) > > + max_extents = cnt; > > + pl_index = 0; > > + } > > + } > > + > > + if (!pl_index) /* nothing more to do */ > > + return 0; > > + return send_one_response(cxl_mbox, response, opcode, pl_index, 0); > > +} > > > + > > +static int stage_pending_extent(struct list_head *pending, > > + struct cxl_extent *to_add) > > +{ > > + struct cxl_extent_list_node *node = kzalloc(sizeof(*node), GFP_KERNEL); > > + struct cxl_extent *extent; > > + > > + if (!node) > > + return -ENOMEM; > > + extent = kmemdup(to_add, sizeof(*extent), GFP_KERNEL); > > Maybe scatter some __free() magic in here and no_free_ptr() where > they get handed off.. I changed stuct cxl_extent_list_node to hold struct cxl_extent itself instead of a pointer to a separately allocated one. So: struct cxl_extent_list_node { struct cxl_extent extent; /* was: struct cxl_extent *extent; */ struct list_head list; }; This function becomes: static int stage_pending_extent(struct list_head *pending, struct cxl_extent *to_add) { struct cxl_extent_list_node *node = kmalloc(sizeof(*node), GFP_KERNEL); if (!node) return -ENOMEM; node->extent = *to_add; list_add_tail(&node->list, pending); return 0; } So a node can never be left in a partially built status that needs cleaning up. > > > + if (!extent) { > > + kfree(node); > > + return -ENOMEM; > > + } > > + > > + node->extent = extent; > e.g. > node->extent = no_free_ptr(extent); > > > + list_add_tail(&node->list, pending); > > list_add_tail(&no_free_ptr(node)->list, pending); > > > + return 0; > > +} > > > + > > +static void cxl_handle_dcd_event_records(struct cxl_memdev_state *mds, > > + struct cxl_event_record_raw *raw_rec) > > +{ > > + struct cxl_event_dcd *event = &raw_rec->event.dcd; > > + struct cxl_extent *extent = &event->extent; > > + struct device *dev = mds->cxlds.dev; > > + uuid_t *id = &raw_rec->id; > > + int rc; > > + > > + if (!uuid_equal(id, &CXL_EVENT_DC_EVENT_UUID)) > > + return; > > + > > + dev_dbg(dev, "DCD event %s : DPA:%#llx LEN:%#llx\n", > > + cxl_dcd_evt_type_str(event->event_type), > > + le64_to_cpu(extent->start_dpa), le64_to_cpu(extent->length)); > > + > > + switch (event->event_type) { > > + case DCD_ADD_CAPACITY: > > + case DCD_RELEASE_CAPACITY: > > + rc = handle_dcd_chain_event(mds, event); > > + break; > > + case DCD_FORCED_CAPACITY_RELEASE: > > + dev_err_ratelimited(dev, "Forced release event ignored.\n"); > > If that actually happens to us, maybe we should panic? All bets are off > if we get one of these for capacity that was actually in use. > Yes, makes more sense to panic here: panic("%s: DC capacity forcibly released\n", dev_name(dev)); > > + rc = 0; > > + break; > > + case DCD_REGION_CONFIGURATION_UPDATED: > > + dev_dbg(dev, "Region configuration updated event ignored.\n"); > > + rc = 0; > > + break; > > + default: > > + rc = -EINVAL; > > + break; > > + } > > + > > + if (rc) > > + dev_err_ratelimited(dev, "dcd event failed: %d\n", rc); > > +} > > + > > static void cxl_mem_get_records_log(struct cxl_memdev_state *mds, > > enum cxl_event_log_type type) > > { > > @@ -1136,9 +1368,13 @@ static void cxl_mem_get_records_log(struct cxl_memdev_state *mds, > > if (!nr_rec) > > break; > > > > - for (i = 0; i < nr_rec; i++) > > + for (i = 0; i < nr_rec; i++) { > > __cxl_event_trace_record(cxlmd, type, > > &payload->records[i]); > > + if (type == CXL_EVENT_TYPE_DCD) > > + cxl_handle_dcd_event_records(mds, > > + &payload->records[i]); > > Just go long on that one. I wouldn't do the normal thing of flipping the condition > because this being out of line makes sense as its an oddity in this function. > Done > > + } > > > > if (payload->flags & CXL_GET_EVENT_FLAG_OVERFLOW) > > trace_cxl_overflow(cxlmd, type, payload); > > > diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h > > index d098f7f50bef..64138e1768a1 100644 > > --- a/drivers/cxl/cxl.h > > +++ b/drivers/cxl/cxl.h > > @@ -12,6 +12,7 @@ > > #include > > #include > > #include > > +#include > > This looks misplaces as nothing in the header changed > that has anything to do with xarrays. > Oops. Moved to the patch that adds struct cxl_dc_tag_group, which tracks extents in xarray. Thanks, Anisa > > #include > > > > extern const struct nvdimm_security_ops *cxl_security_ops; > > @@ -557,6 +558,14 @@ struct cxl_pmem_region { > > struct cxl_pmem_region_mapping mapping[]; > > }; > > > > +/* See CXL r4.0 8.2.10.2.1.6 */ > > +enum dc_event { > > + DCD_ADD_CAPACITY, > > + DCD_RELEASE_CAPACITY, > > + DCD_FORCED_CAPACITY_RELEASE, > > + DCD_REGION_CONFIGURATION_UPDATED, > > +}; > > + > > struct cxl_dax_region { > > struct device dev; > > struct cxl_region *cxlr; >