Skip to content

Commit f0832a5

Browse files
AlisonSchofielddjbw
authored andcommitted
cxl/region: Provide region info to the cxl_poison trace event
User space may need to know which region, if any, maps the poison address(es) logged in a cxl_poison trace event. Since the mapping of DPAs (device physical addresses) to a region can change, the kernel must provide this information at the time the poison list is read. The event informs user space that at event <timestamp> this <region> mapped to this <DPA>, which is poisoned. The cxl_poison trace event is already wired up to log the region name and uuid if it receives param 'struct cxl_region'. In order to provide that cxl_region, add another method for gathering poison - by committed endpoint decoder mappings. This method is only available with CONFIG_CXL_REGION and is only used if a region actually maps the memdev where poison is being read. After the region driver reads the poison list for all the mapped resources, poison is read for any remaining unmapped resources. The default method remains: read the poison by memdev resource. Signed-off-by: Alison Schofield <alison.schofield@intel.com> Tested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Link: https://lore.kernel.org/r/438b01ccaa70592539e8eda4eb2b1d617ba03160.1681838292.git.alison.schofield@intel.com Tested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 7ff6ad1 commit f0832a5

File tree

3 files changed

+141
-1
lines changed

3 files changed

+141
-1
lines changed

drivers/cxl/core/core.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ void cxl_decoder_kill_region(struct cxl_endpoint_decoder *cxled);
2525
#define CXL_DAX_REGION_TYPE(x) (&cxl_dax_region_type)
2626
int cxl_region_init(void);
2727
void cxl_region_exit(void);
28+
int cxl_get_poison_by_endpoint(struct cxl_port *port);
2829
#else
30+
static inline int cxl_get_poison_by_endpoint(struct cxl_port *port)
31+
{
32+
return 0;
33+
}
2934
static inline void cxl_decoder_kill_region(struct cxl_endpoint_decoder *cxled)
3035
{
3136
}

drivers/cxl/core/memdev.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,24 @@ static int cxl_get_poison_by_memdev(struct cxl_memdev *cxlmd)
136136

137137
int cxl_trigger_poison_list(struct cxl_memdev *cxlmd)
138138
{
139+
struct cxl_port *port;
139140
int rc;
140141

142+
port = dev_get_drvdata(&cxlmd->dev);
143+
if (!port || !is_cxl_endpoint(port))
144+
return -EINVAL;
145+
141146
rc = down_read_interruptible(&cxl_dpa_rwsem);
142147
if (rc)
143148
return rc;
144149

145-
rc = cxl_get_poison_by_memdev(cxlmd);
150+
if (port->commit_end == -1) {
151+
/* No regions mapped to this memdev */
152+
rc = cxl_get_poison_by_memdev(cxlmd);
153+
} else {
154+
/* Regions mapped, collect poison by endpoint */
155+
rc = cxl_get_poison_by_endpoint(port);
156+
}
146157
up_read(&cxl_dpa_rwsem);
147158

148159
return rc;

drivers/cxl/core/region.c

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,6 +2238,130 @@ struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev)
22382238
}
22392239
EXPORT_SYMBOL_NS_GPL(to_cxl_pmem_region, CXL);
22402240

2241+
struct cxl_poison_context {
2242+
struct cxl_port *port;
2243+
enum cxl_decoder_mode mode;
2244+
u64 offset;
2245+
};
2246+
2247+
static int cxl_get_poison_unmapped(struct cxl_memdev *cxlmd,
2248+
struct cxl_poison_context *ctx)
2249+
{
2250+
struct cxl_dev_state *cxlds = cxlmd->cxlds;
2251+
u64 offset, length;
2252+
int rc = 0;
2253+
2254+
/*
2255+
* Collect poison for the remaining unmapped resources
2256+
* after poison is collected by committed endpoints.
2257+
*
2258+
* Knowing that PMEM must always follow RAM, get poison
2259+
* for unmapped resources based on the last decoder's mode:
2260+
* ram: scan remains of ram range, then any pmem range
2261+
* pmem: scan remains of pmem range
2262+
*/
2263+
2264+
if (ctx->mode == CXL_DECODER_RAM) {
2265+
offset = ctx->offset;
2266+
length = resource_size(&cxlds->ram_res) - offset;
2267+
rc = cxl_mem_get_poison(cxlmd, offset, length, NULL);
2268+
if (rc == -EFAULT)
2269+
rc = 0;
2270+
if (rc)
2271+
return rc;
2272+
}
2273+
if (ctx->mode == CXL_DECODER_PMEM) {
2274+
offset = ctx->offset;
2275+
length = resource_size(&cxlds->dpa_res) - offset;
2276+
if (!length)
2277+
return 0;
2278+
} else if (resource_size(&cxlds->pmem_res)) {
2279+
offset = cxlds->pmem_res.start;
2280+
length = resource_size(&cxlds->pmem_res);
2281+
} else {
2282+
return 0;
2283+
}
2284+
2285+
return cxl_mem_get_poison(cxlmd, offset, length, NULL);
2286+
}
2287+
2288+
static int poison_by_decoder(struct device *dev, void *arg)
2289+
{
2290+
struct cxl_poison_context *ctx = arg;
2291+
struct cxl_endpoint_decoder *cxled;
2292+
struct cxl_memdev *cxlmd;
2293+
u64 offset, length;
2294+
int rc = 0;
2295+
2296+
if (!is_endpoint_decoder(dev))
2297+
return rc;
2298+
2299+
cxled = to_cxl_endpoint_decoder(dev);
2300+
if (!cxled->dpa_res || !resource_size(cxled->dpa_res))
2301+
return rc;
2302+
2303+
/*
2304+
* Regions are only created with single mode decoders: pmem or ram.
2305+
* Linux does not support mixed mode decoders. This means that
2306+
* reading poison per endpoint decoder adheres to the requirement
2307+
* that poison reads of pmem and ram must be separated.
2308+
* CXL 3.0 Spec 8.2.9.8.4.1
2309+
*/
2310+
if (cxled->mode == CXL_DECODER_MIXED) {
2311+
dev_dbg(dev, "poison list read unsupported in mixed mode\n");
2312+
return rc;
2313+
}
2314+
2315+
cxlmd = cxled_to_memdev(cxled);
2316+
if (cxled->skip) {
2317+
offset = cxled->dpa_res->start - cxled->skip;
2318+
length = cxled->skip;
2319+
rc = cxl_mem_get_poison(cxlmd, offset, length, NULL);
2320+
if (rc == -EFAULT && cxled->mode == CXL_DECODER_RAM)
2321+
rc = 0;
2322+
if (rc)
2323+
return rc;
2324+
}
2325+
2326+
offset = cxled->dpa_res->start;
2327+
length = cxled->dpa_res->end - offset + 1;
2328+
rc = cxl_mem_get_poison(cxlmd, offset, length, cxled->cxld.region);
2329+
if (rc == -EFAULT && cxled->mode == CXL_DECODER_RAM)
2330+
rc = 0;
2331+
if (rc)
2332+
return rc;
2333+
2334+
/* Iterate until commit_end is reached */
2335+
if (cxled->cxld.id == ctx->port->commit_end) {
2336+
ctx->offset = cxled->dpa_res->end + 1;
2337+
ctx->mode = cxled->mode;
2338+
return 1;
2339+
}
2340+
2341+
return 0;
2342+
}
2343+
2344+
int cxl_get_poison_by_endpoint(struct cxl_port *port)
2345+
{
2346+
struct cxl_poison_context ctx;
2347+
int rc = 0;
2348+
2349+
rc = down_read_interruptible(&cxl_region_rwsem);
2350+
if (rc)
2351+
return rc;
2352+
2353+
ctx = (struct cxl_poison_context) {
2354+
.port = port
2355+
};
2356+
2357+
rc = device_for_each_child(&port->dev, &ctx, poison_by_decoder);
2358+
if (rc == 1)
2359+
rc = cxl_get_poison_unmapped(to_cxl_memdev(port->uport), &ctx);
2360+
2361+
up_read(&cxl_region_rwsem);
2362+
return rc;
2363+
}
2364+
22412365
static struct lock_class_key cxl_pmem_region_key;
22422366

22432367
static struct cxl_pmem_region *cxl_pmem_region_alloc(struct cxl_region *cxlr)

0 commit comments

Comments
 (0)