Skip to content

Commit 7a0d85d

Browse files
Ian Munsiempe
authored andcommitted
cxl: Add kernel API to allow a context to operate with relocate disabled
cxl 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 API, cxl_set_translation_mode, that can be used to disable relocation on a given kernel context. 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 <imunsie@au1.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 3c206fa commit 7a0d85d

5 files changed

Lines changed: 34 additions & 2 deletions

File tree

‎drivers/misc/cxl/api.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ int cxl_start_context(struct cxl_context *ctx, u64 wed,
183183
ctx->pid = get_task_pid(task, PIDTYPE_PID);
184184
ctx->glpid = get_task_pid(task->group_leader, PIDTYPE_PID);
185185
kernel = false;
186+
ctx->real_mode = false;
186187
}
187188

188189
cxl_ctx_get();
@@ -219,6 +220,24 @@ void cxl_set_master(struct cxl_context *ctx)
219220
}
220221
EXPORT_SYMBOL_GPL(cxl_set_master);
221222

223+
int cxl_set_translation_mode(struct cxl_context *ctx, bool real_mode)
224+
{
225+
if (ctx->status == STARTED) {
226+
/*
227+
* We could potentially update the PE and issue an update LLCMD
228+
* to support this, but it doesn't seem to have a good use case
229+
* since it's trivial to just create a second kernel context
230+
* with different translation modes, so until someone convinces
231+
* me otherwise:
232+
*/
233+
return -EBUSY;
234+
}
235+
236+
ctx->real_mode = real_mode;
237+
return 0;
238+
}
239+
EXPORT_SYMBOL_GPL(cxl_set_translation_mode);
240+
222241
/* wrappers around afu_* file ops which are EXPORTED */
223242
int cxl_fd_open(struct inode *inode, struct file *file)
224243
{

‎drivers/misc/cxl/cxl.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ struct cxl_context {
514514
bool pe_inserted;
515515
bool master;
516516
bool kernel;
517+
bool real_mode;
517518
bool pending_irq;
518519
bool pending_fault;
519520
bool pending_afu_err;

‎drivers/misc/cxl/guest.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,9 @@ static int guest_attach_process(struct cxl_context *ctx, bool kernel, u64 wed, u
617617
{
618618
pr_devel("in %s\n", __func__);
619619

620+
if (ctx->real_mode)
621+
return -EPERM;
622+
620623
ctx->kernel = kernel;
621624
if (ctx->afu->current_mode == CXL_MODE_DIRECTED)
622625
return attach_afu_directed(ctx, wed, amr);

‎drivers/misc/cxl/native.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,9 @@ static u64 calculate_sr(struct cxl_context *ctx)
494494
if (mfspr(SPRN_LPCR) & LPCR_TC)
495495
sr |= CXL_PSL_SR_An_TC;
496496
if (ctx->kernel) {
497-
sr |= CXL_PSL_SR_An_R | (mfmsr() & MSR_SF);
498-
sr |= CXL_PSL_SR_An_HV;
497+
if (!ctx->real_mode)
498+
sr |= CXL_PSL_SR_An_R;
499+
sr |= (mfmsr() & MSR_SF) | CXL_PSL_SR_An_HV;
499500
} else {
500501
sr |= CXL_PSL_SR_An_PR | CXL_PSL_SR_An_R;
501502
sr &= ~(CXL_PSL_SR_An_HV);

‎include/misc/cxl.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ int cxl_afu_reset(struct cxl_context *ctx);
126126
*/
127127
void cxl_set_master(struct cxl_context *ctx);
128128

129+
/*
130+
* Sets the context to use real mode memory accesses to operate with
131+
* translation disabled. Note that this only makes sense for kernel contexts
132+
* under bare metal, and will not work with virtualisation. May only be
133+
* performed on stopped contexts.
134+
*/
135+
int cxl_set_translation_mode(struct cxl_context *ctx, bool real_mode);
136+
129137
/*
130138
* Map and unmap the AFU Problem Space area. The amount and location mapped
131139
* depends on if this context is a master or slave.

0 commit comments

Comments
 (0)