Re: [PATCH] cxl: Add kernel API to allow a context to operate with relocate disabled
Sure thing, that actually simplifies things a great deal. Testing now and will resend shortly :) -Ian ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
Re: [PATCH] cxl: Add kernel API to allow a context to operate with relocate disabled
On Wed, 2016-05-04 at 18:07 +0200, Frederic Barrat wrote: > Hi Ian, > > The principle is fine, but the cxl_start_context2 API bothers me a bit. > Would something similar to this make sense, I think it would keep the > API cleaner: > > /* new kernel-only API */ > void cxl_set_translation_mode(struct cxl_context *ctx, bool real_mode) > > For mlx5, the call sequence would be: > ctx = cxl_dev_context_init() > cxl_set_translation_mode(ctx, true) > cxl_start_context(ctx) I'd prefer that if it works. The new "2" API and the bool being passed everywhere is a bit smelly. cheers ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
Re: [PATCH] cxl: Add kernel API to allow a context to operate with relocate disabled
Hi Ian, The principle is fine, but the cxl_start_context2 API bothers me a bit. Would something similar to this make sense, I think it would keep the API cleaner: /* new kernel-only API */ void cxl_set_translation_mode(struct cxl_context *ctx, bool real_mode) For mlx5, the call sequence would be: ctx = cxl_dev_context_init() cxl_set_translation_mode(ctx, true) cxl_start_context(ctx) And of course, default would keep enabling relocation if cxl_set_translation_mode() is not used. Fred Le 04/05/2016 08:54, Ian Munsie a écrit : From: Ian Munsiecxl devices typically access memory using an MMU in much the same way as the CPU, and each context includes a state register much like the MSR in the CPU. Like the CPU, the state register includes a bit to enable relocation, which we currently always enable. In some cases, it may be desirable to allow a device to access memory using real addresses instead of effective addresses, so this adds a new version of the start context kernel API, cxl_start_context2, to allow contexts to be created with relocation disabled. This can allow for the creation of a special privileged context that the device can use if it needs relocation disabled, and can use regular contexts at times when it needs relocation enabled. This interface is only available to users of the kernel API for obvious reasons, and will never be supported in a virtualised environment. This will be used by the upcoming cxl support in the mlx5 driver. Signed-off-by: Ian Munsie --- drivers/misc/cxl/api.c| 14 +++--- drivers/misc/cxl/cxl.h| 2 +- drivers/misc/cxl/file.c | 4 ++-- drivers/misc/cxl/guest.c | 6 +- drivers/misc/cxl/native.c | 20 +++- include/misc/cxl.h| 8 6 files changed, 38 insertions(+), 16 deletions(-) diff --git a/drivers/misc/cxl/api.c b/drivers/misc/cxl/api.c index 8075823..675952a 100644 --- a/drivers/misc/cxl/api.c +++ b/drivers/misc/cxl/api.c @@ -167,8 +167,8 @@ EXPORT_SYMBOL_GPL(cxl_unmap_afu_irq); * Start a context * Code here similar to afu_ioctl_start_work(). */ -int cxl_start_context(struct cxl_context *ctx, u64 wed, - struct task_struct *task) +int cxl_start_context2(struct cxl_context *ctx, u64 wed, + struct task_struct *task, bool real_mode) { int rc = 0; bool kernel = true; @@ -183,11 +183,12 @@ int cxl_start_context(struct cxl_context *ctx, u64 wed, ctx->pid = get_task_pid(task, PIDTYPE_PID); ctx->glpid = get_task_pid(task->group_leader, PIDTYPE_PID); kernel = false; + real_mode = false; } cxl_ctx_get(); - if ((rc = cxl_ops->attach_process(ctx, kernel, wed, 0))) { + if ((rc = cxl_ops->attach_process(ctx, kernel, real_mode, wed, 0))) { put_pid(ctx->pid); cxl_ctx_put(); goto out; @@ -198,6 +199,13 @@ out: mutex_unlock(>status_mutex); return rc; } +EXPORT_SYMBOL_GPL(cxl_start_context2); + +int cxl_start_context(struct cxl_context *ctx, u64 wed, + struct task_struct *task) +{ + return cxl_start_context2(ctx, wed, task, false); +} EXPORT_SYMBOL_GPL(cxl_start_context); int cxl_process_element(struct cxl_context *ctx) diff --git a/drivers/misc/cxl/cxl.h b/drivers/misc/cxl/cxl.h index dfdbfb0..cffded1 100644 --- a/drivers/misc/cxl/cxl.h +++ b/drivers/misc/cxl/cxl.h @@ -857,7 +857,7 @@ struct cxl_backend_ops { irqreturn_t (*psl_interrupt)(int irq, void *data); int (*ack_irq)(struct cxl_context *ctx, u64 tfc, u64 psl_reset_mask); int (*attach_process)(struct cxl_context *ctx, bool kernel, - u64 wed, u64 amr); + bool real_mode, u64 wed, u64 amr); int (*detach_process)(struct cxl_context *ctx); bool (*support_attributes)(const char *attr_name, enum cxl_attrs type); bool (*link_ok)(struct cxl *cxl, struct cxl_afu *afu); diff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c index eec468f..0f7a418 100644 --- a/drivers/misc/cxl/file.c +++ b/drivers/misc/cxl/file.c @@ -207,8 +207,8 @@ static long afu_ioctl_start_work(struct cxl_context *ctx, trace_cxl_attach(ctx, work.work_element_descriptor, work.num_interrupts, amr); - if ((rc = cxl_ops->attach_process(ctx, false, work.work_element_descriptor, - amr))) { + if ((rc = cxl_ops->attach_process(ctx, false, false, + work.work_element_descriptor, amr))) { afu_release_irqs(ctx, ctx); goto out; } diff --git a/drivers/misc/cxl/guest.c b/drivers/misc/cxl/guest.c index 769971c..9a53d45 100644 --- a/drivers/misc/cxl/guest.c +++ b/drivers/misc/cxl/guest.c @@ -613,10 +613,14 @@ out_free: return
[PATCH] cxl: Add kernel API to allow a context to operate with relocate disabled
From: Ian Munsiecxl devices typically access memory using an MMU in much the same way as the CPU, and each context includes a state register much like the MSR in the CPU. Like the CPU, the state register includes a bit to enable relocation, which we currently always enable. In some cases, it may be desirable to allow a device to access memory using real addresses instead of effective addresses, so this adds a new version of the start context kernel API, cxl_start_context2, to allow contexts to be created with relocation disabled. This can allow for the creation of a special privileged context that the device can use if it needs relocation disabled, and can use regular contexts at times when it needs relocation enabled. This interface is only available to users of the kernel API for obvious reasons, and will never be supported in a virtualised environment. This will be used by the upcoming cxl support in the mlx5 driver. Signed-off-by: Ian Munsie --- drivers/misc/cxl/api.c| 14 +++--- drivers/misc/cxl/cxl.h| 2 +- drivers/misc/cxl/file.c | 4 ++-- drivers/misc/cxl/guest.c | 6 +- drivers/misc/cxl/native.c | 20 +++- include/misc/cxl.h| 8 6 files changed, 38 insertions(+), 16 deletions(-) diff --git a/drivers/misc/cxl/api.c b/drivers/misc/cxl/api.c index 8075823..675952a 100644 --- a/drivers/misc/cxl/api.c +++ b/drivers/misc/cxl/api.c @@ -167,8 +167,8 @@ EXPORT_SYMBOL_GPL(cxl_unmap_afu_irq); * Start a context * Code here similar to afu_ioctl_start_work(). */ -int cxl_start_context(struct cxl_context *ctx, u64 wed, - struct task_struct *task) +int cxl_start_context2(struct cxl_context *ctx, u64 wed, + struct task_struct *task, bool real_mode) { int rc = 0; bool kernel = true; @@ -183,11 +183,12 @@ int cxl_start_context(struct cxl_context *ctx, u64 wed, ctx->pid = get_task_pid(task, PIDTYPE_PID); ctx->glpid = get_task_pid(task->group_leader, PIDTYPE_PID); kernel = false; + real_mode = false; } cxl_ctx_get(); - if ((rc = cxl_ops->attach_process(ctx, kernel, wed, 0))) { + if ((rc = cxl_ops->attach_process(ctx, kernel, real_mode, wed, 0))) { put_pid(ctx->pid); cxl_ctx_put(); goto out; @@ -198,6 +199,13 @@ out: mutex_unlock(>status_mutex); return rc; } +EXPORT_SYMBOL_GPL(cxl_start_context2); + +int cxl_start_context(struct cxl_context *ctx, u64 wed, + struct task_struct *task) +{ + return cxl_start_context2(ctx, wed, task, false); +} EXPORT_SYMBOL_GPL(cxl_start_context); int cxl_process_element(struct cxl_context *ctx) diff --git a/drivers/misc/cxl/cxl.h b/drivers/misc/cxl/cxl.h index dfdbfb0..cffded1 100644 --- a/drivers/misc/cxl/cxl.h +++ b/drivers/misc/cxl/cxl.h @@ -857,7 +857,7 @@ struct cxl_backend_ops { irqreturn_t (*psl_interrupt)(int irq, void *data); int (*ack_irq)(struct cxl_context *ctx, u64 tfc, u64 psl_reset_mask); int (*attach_process)(struct cxl_context *ctx, bool kernel, - u64 wed, u64 amr); + bool real_mode, u64 wed, u64 amr); int (*detach_process)(struct cxl_context *ctx); bool (*support_attributes)(const char *attr_name, enum cxl_attrs type); bool (*link_ok)(struct cxl *cxl, struct cxl_afu *afu); diff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c index eec468f..0f7a418 100644 --- a/drivers/misc/cxl/file.c +++ b/drivers/misc/cxl/file.c @@ -207,8 +207,8 @@ static long afu_ioctl_start_work(struct cxl_context *ctx, trace_cxl_attach(ctx, work.work_element_descriptor, work.num_interrupts, amr); - if ((rc = cxl_ops->attach_process(ctx, false, work.work_element_descriptor, - amr))) { + if ((rc = cxl_ops->attach_process(ctx, false, false, + work.work_element_descriptor, amr))) { afu_release_irqs(ctx, ctx); goto out; } diff --git a/drivers/misc/cxl/guest.c b/drivers/misc/cxl/guest.c index 769971c..9a53d45 100644 --- a/drivers/misc/cxl/guest.c +++ b/drivers/misc/cxl/guest.c @@ -613,10 +613,14 @@ out_free: return rc; } -static int guest_attach_process(struct cxl_context *ctx, bool kernel, u64 wed, u64 amr) +static int guest_attach_process(struct cxl_context *ctx, bool kernel, + bool real_mode, u64 wed, u64 amr) { pr_devel("in %s\n", __func__); + if (real_mode) + return -EINVAL; + ctx->kernel = kernel; if (ctx->afu->current_mode == CXL_MODE_DIRECTED) return attach_afu_directed(ctx, wed, amr); diff --git a/drivers/misc/cxl/native.c b/drivers/misc/cxl/native.c index ef494ba..c00a275 100644