Skip to content

Commit d9232a3

Browse files
Ian Munsiempe
authored andcommitted
cxl: Add alternate MMIO error handling
userspace programs using cxl currently have to use two strategies for dealing with MMIO errors simultaneously. They have to check every read for a return of all Fs in case the adapter has gone away and the kernel has not yet noticed, and they have to deal with SIGBUS in case the kernel has already noticed, invalidated the mapping and marked the context as failed. In order to simplify things, this patch adds an alternative approach where the kernel will return a page filled with Fs instead of delivering a SIGBUS. This allows userspace to only need to deal with one of these two error paths, and is intended for use in libraries that use cxl transparently and may not be able to safely install a signal handler. This approach will only work if certain constraints are met. Namely, if the application is both reading and writing to an address in the problem state area it cannot assume that a non-FF read is OK, as it may just be reading out a value it has previously written. Further - since only one page is used per context a write to a given offset would be visible when reading the same offset from a different page in the mapping (this only applies within a single context, not between contexts). An application could deal with this by e.g. making sure it also reads from a read-only offset after any reads to a read/write offset. Due to these constraints, this functionality must be explicitly requested by userspace when starting the context by passing in the CXL_START_WORK_ERR_FF flag. Signed-off-by: Ian Munsie <imunsie@au1.ibm.com> Acked-by: Michael Neuling <mikey@neuling.org> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent fc9e9cb commit d9232a3

4 files changed

Lines changed: 23 additions & 3 deletions

File tree

‎drivers/misc/cxl/context.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ static int cxl_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
126126
if (ctx->status != STARTED) {
127127
mutex_unlock(&ctx->status_mutex);
128128
pr_devel("%s: Context not started, failing problem state access\n", __func__);
129+
if (ctx->mmio_err_ff) {
130+
if (!ctx->ff_page) {
131+
ctx->ff_page = alloc_page(GFP_USER);
132+
if (!ctx->ff_page)
133+
return VM_FAULT_OOM;
134+
memset(page_address(ctx->ff_page), 0xff, PAGE_SIZE);
135+
}
136+
get_page(ctx->ff_page);
137+
vmf->page = ctx->ff_page;
138+
vma->vm_page_prot = pgprot_cached(vma->vm_page_prot);
139+
return 0;
140+
}
129141
return VM_FAULT_SIGBUS;
130142
}
131143

@@ -257,6 +269,8 @@ static void reclaim_ctx(struct rcu_head *rcu)
257269
struct cxl_context *ctx = container_of(rcu, struct cxl_context, rcu);
258270

259271
free_page((u64)ctx->sstp);
272+
if (ctx->ff_page)
273+
__free_page(ctx->ff_page);
260274
ctx->sstp = NULL;
261275

262276
kfree(ctx);

‎drivers/misc/cxl/cxl.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern uint cxl_verbose;
3434
* Bump version each time a user API change is made, whether it is
3535
* backwards compatible ot not.
3636
*/
37-
#define CXL_API_VERSION 1
37+
#define CXL_API_VERSION 2
3838
#define CXL_API_VERSION_COMPATIBLE 1
3939

4040
/*
@@ -418,6 +418,8 @@ struct cxl_context {
418418
/* Used to unmap any mmaps when force detaching */
419419
struct address_space *mapping;
420420
struct mutex mapping_lock;
421+
struct page *ff_page;
422+
bool mmio_err_ff;
421423

422424
spinlock_t sste_lock; /* Protects segment table entries */
423425
struct cxl_sste *sstp;

‎drivers/misc/cxl/file.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
184184
if (work.flags & CXL_START_WORK_AMR)
185185
amr = work.amr & mfspr(SPRN_UAMOR);
186186

187+
ctx->mmio_err_ff = !!(work.flags & CXL_START_WORK_ERR_FF);
188+
187189
/*
188190
* We grab the PID here and not in the file open to allow for the case
189191
* where a process (master, some daemon, etc) has opened the chardev on
@@ -538,7 +540,7 @@ int __init cxl_file_init(void)
538540
* If these change we really need to update API. Either change some
539541
* flags or update API version number CXL_API_VERSION.
540542
*/
541-
BUILD_BUG_ON(CXL_API_VERSION != 1);
543+
BUILD_BUG_ON(CXL_API_VERSION != 2);
542544
BUILD_BUG_ON(sizeof(struct cxl_ioctl_start_work) != 64);
543545
BUILD_BUG_ON(sizeof(struct cxl_event_header) != 8);
544546
BUILD_BUG_ON(sizeof(struct cxl_event_afu_interrupt) != 8);

‎include/uapi/misc/cxl.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ struct cxl_ioctl_start_work {
2929

3030
#define CXL_START_WORK_AMR 0x0000000000000001ULL
3131
#define CXL_START_WORK_NUM_IRQS 0x0000000000000002ULL
32+
#define CXL_START_WORK_ERR_FF 0x0000000000000004ULL
3233
#define CXL_START_WORK_ALL (CXL_START_WORK_AMR |\
33-
CXL_START_WORK_NUM_IRQS)
34+
CXL_START_WORK_NUM_IRQS |\
35+
CXL_START_WORK_ERR_FF)
3436

3537

3638
/* Possible modes that an afu can be in */

0 commit comments

Comments
 (0)