Re: [PATCH V7] cxl: Add support for ASB_Notify on POWER9

2018-01-14 Thread Andrew Donnellan

On 11/01/18 19:55, Christophe Lombard wrote:

The POWER9 core supports a new feature: ASB_Notify which requires the
support of the Special Purpose Register: TIDR.

The ASB_Notify command, generated by the AFU, will attempt to
wake-up the host thread identified by the particular LPID:PID:TID.

This patch assign a unique TIDR (thread id) for the current thread which
will be used in the process element entry.

Signed-off-by: Christophe Lombard 
Reviewed-by: Philippe Bergheaud 


Acked-by: Andrew Donnellan 



---
Changelog[v7]
  - Rebased to latest upstream.
  - Added boolean: "need to allocate a TIDR"
  - Released the mutex and mark the context as STARTED in case of error.

Changelog[v6]
  - Rebased to latest upstream.
  - Updated the ioctl interface.
  - Removed the updated ptrace.
  - Assigned a unique TIDR for the current thread at a lower level.

Changelog[v5]
  - Rebased to latest upstream.
  - Updated the ioctl interface.
  - Returned the tid in the ioctl structure.

Changelog[v4]
  - Rebased to latest upstream.
  - Updated the ioctl interface.
  - Removed the field tid in the context structure.

Changelog[v3]
  - Rebased to latest upstream.
  - Updated attr->tid field in cxllib_get_PE_attributes().

Changelog[v2]
  - Rebased to latest upstream.
  - Updated the ioctl interface.
  - Added a checking to allow updating the TIDR if a P9 chip is present.
---
  arch/powerpc/kernel/process.c |  1 +
  drivers/misc/cxl/context.c|  2 ++
  drivers/misc/cxl/cxl.h|  3 +++
  drivers/misc/cxl/cxllib.c |  3 ++-
  drivers/misc/cxl/file.c   | 15 +--
  drivers/misc/cxl/native.c | 13 -
  include/uapi/misc/cxl.h   | 10 ++
  7 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 72be0c3..1dc39dd 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1589,6 +1589,7 @@ int set_thread_tidr(struct task_struct *t)

return 0;
  }
+EXPORT_SYMBOL_GPL(set_thread_tidr);

  #endif /* CONFIG_PPC64 */

diff --git a/drivers/misc/cxl/context.c b/drivers/misc/cxl/context.c
index 12a41b2..7ff315a 100644
--- a/drivers/misc/cxl/context.c
+++ b/drivers/misc/cxl/context.c
@@ -45,6 +45,8 @@ int cxl_context_init(struct cxl_context *ctx, struct cxl_afu 
*afu, bool master)
ctx->pid = NULL; /* Set in start work ioctl */
mutex_init(>mapping_lock);
ctx->mapping = NULL;
+   ctx->tidr = 0;
+   ctx->assign_tidr = false;

if (cxl_is_power8()) {
spin_lock_init(>sste_lock);
diff --git a/drivers/misc/cxl/cxl.h b/drivers/misc/cxl/cxl.h
index e46a406..53149fb 100644
--- a/drivers/misc/cxl/cxl.h
+++ b/drivers/misc/cxl/cxl.h
@@ -630,6 +630,9 @@ struct cxl_context {
struct list_head extra_irq_contexts;

struct mm_struct *mm;
+
+   u16 tidr;
+   bool assign_tidr;
  };

  struct cxl_irq_info;
diff --git a/drivers/misc/cxl/cxllib.c b/drivers/misc/cxl/cxllib.c
index dc9bc18..30ccba4 100644
--- a/drivers/misc/cxl/cxllib.c
+++ b/drivers/misc/cxl/cxllib.c
@@ -199,10 +199,11 @@ int cxllib_get_PE_attributes(struct task_struct *task,
 */
attr->pid = mm->context.id;
mmput(mm);
+   attr->tid = task->thread.tidr;
} else {
attr->pid = 0;
+   attr->tid = 0;
}
-   attr->tid = 0;
return 0;
  }
  EXPORT_SYMBOL_GPL(cxllib_get_PE_attributes);
diff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c
index 76c0b0c..93fd381 100644
--- a/drivers/misc/cxl/file.c
+++ b/drivers/misc/cxl/file.c
@@ -173,7 +173,7 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
 * flags are set it's invalid
 */
if (work.reserved1 || work.reserved2 || work.reserved3 ||
-   work.reserved4 || work.reserved5 || work.reserved6 ||
+   work.reserved4 || work.reserved5 ||
(work.flags & ~CXL_START_WORK_ALL)) {
rc = -EINVAL;
goto out;
@@ -186,12 +186,16 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
rc =  -EINVAL;
goto out;
}
+
if ((rc = afu_register_irqs(ctx, work.num_interrupts)))
goto out;

if (work.flags & CXL_START_WORK_AMR)
amr = work.amr & mfspr(SPRN_UAMOR);

+   if (work.flags & CXL_START_WORK_TID)
+   ctx->assign_tidr = true;
+
ctx->mmio_err_ff = !!(work.flags & CXL_START_WORK_ERR_FF);

/*
@@ -263,8 +267,15 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
goto out;
}

-   ctx->status = STARTED;
rc = 0;
+   if (work.flags & CXL_START_WORK_TID) {
+   work.tid = ctx->tidr;
+   if (copy_to_user(uwork, , sizeof(work)))
+   rc = -EFAULT;
+ 

Re: [PATCH V7] cxl: Add support for ASB_Notify on POWER9

2018-01-12 Thread Vaibhav Jain
Christophe Lombard  writes:

> The POWER9 core supports a new feature: ASB_Notify which requires the
> support of the Special Purpose Register: TIDR.
>
> The ASB_Notify command, generated by the AFU, will attempt to
> wake-up the host thread identified by the particular LPID:PID:TID.
>
> This patch assign a unique TIDR (thread id) for the current thread which
> will be used in the process element entry.
>
> Signed-off-by: Christophe Lombard 
> Reviewed-by: Philippe Bergheaud 
>
Reviewed-by: Vaibhav Jain 



Re: [PATCH V7] cxl: Add support for ASB_Notify on POWER9

2018-01-11 Thread Frederic Barrat



Le 11/01/2018 à 09:55, Christophe Lombard a écrit :

The POWER9 core supports a new feature: ASB_Notify which requires the
support of the Special Purpose Register: TIDR.

The ASB_Notify command, generated by the AFU, will attempt to
wake-up the host thread identified by the particular LPID:PID:TID.

This patch assign a unique TIDR (thread id) for the current thread which
will be used in the process element entry.

Signed-off-by: Christophe Lombard 
Reviewed-by: Philippe Bergheaud 


Looks ok to me, thanks!

Acked-by: Frederic Barrat 



Changelog[v7]
  - Rebased to latest upstream.
  - Added boolean: "need to allocate a TIDR"
  - Released the mutex and mark the context as STARTED in case of error.

Changelog[v6]
  - Rebased to latest upstream.
  - Updated the ioctl interface.
  - Removed the updated ptrace.
  - Assigned a unique TIDR for the current thread at a lower level.

Changelog[v5]
  - Rebased to latest upstream.
  - Updated the ioctl interface.
  - Returned the tid in the ioctl structure.

Changelog[v4]
  - Rebased to latest upstream.
  - Updated the ioctl interface.
  - Removed the field tid in the context structure.

Changelog[v3]
  - Rebased to latest upstream.
  - Updated attr->tid field in cxllib_get_PE_attributes().

Changelog[v2]
  - Rebased to latest upstream.
  - Updated the ioctl interface.
  - Added a checking to allow updating the TIDR if a P9 chip is present.
---
  arch/powerpc/kernel/process.c |  1 +
  drivers/misc/cxl/context.c|  2 ++
  drivers/misc/cxl/cxl.h|  3 +++
  drivers/misc/cxl/cxllib.c |  3 ++-
  drivers/misc/cxl/file.c   | 15 +--
  drivers/misc/cxl/native.c | 13 -
  include/uapi/misc/cxl.h   | 10 ++
  7 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 72be0c3..1dc39dd 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1589,6 +1589,7 @@ int set_thread_tidr(struct task_struct *t)

return 0;
  }
+EXPORT_SYMBOL_GPL(set_thread_tidr);

  #endif /* CONFIG_PPC64 */

diff --git a/drivers/misc/cxl/context.c b/drivers/misc/cxl/context.c
index 12a41b2..7ff315a 100644
--- a/drivers/misc/cxl/context.c
+++ b/drivers/misc/cxl/context.c
@@ -45,6 +45,8 @@ int cxl_context_init(struct cxl_context *ctx, struct cxl_afu 
*afu, bool master)
ctx->pid = NULL; /* Set in start work ioctl */
mutex_init(>mapping_lock);
ctx->mapping = NULL;
+   ctx->tidr = 0;
+   ctx->assign_tidr = false;

if (cxl_is_power8()) {
spin_lock_init(>sste_lock);
diff --git a/drivers/misc/cxl/cxl.h b/drivers/misc/cxl/cxl.h
index e46a406..53149fb 100644
--- a/drivers/misc/cxl/cxl.h
+++ b/drivers/misc/cxl/cxl.h
@@ -630,6 +630,9 @@ struct cxl_context {
struct list_head extra_irq_contexts;

struct mm_struct *mm;
+
+   u16 tidr;
+   bool assign_tidr;
  };

  struct cxl_irq_info;
diff --git a/drivers/misc/cxl/cxllib.c b/drivers/misc/cxl/cxllib.c
index dc9bc18..30ccba4 100644
--- a/drivers/misc/cxl/cxllib.c
+++ b/drivers/misc/cxl/cxllib.c
@@ -199,10 +199,11 @@ int cxllib_get_PE_attributes(struct task_struct *task,
 */
attr->pid = mm->context.id;
mmput(mm);
+   attr->tid = task->thread.tidr;
} else {
attr->pid = 0;
+   attr->tid = 0;
}
-   attr->tid = 0;
return 0;
  }
  EXPORT_SYMBOL_GPL(cxllib_get_PE_attributes);
diff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c
index 76c0b0c..93fd381 100644
--- a/drivers/misc/cxl/file.c
+++ b/drivers/misc/cxl/file.c
@@ -173,7 +173,7 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
 * flags are set it's invalid
 */
if (work.reserved1 || work.reserved2 || work.reserved3 ||
-   work.reserved4 || work.reserved5 || work.reserved6 ||
+   work.reserved4 || work.reserved5 ||
(work.flags & ~CXL_START_WORK_ALL)) {
rc = -EINVAL;
goto out;
@@ -186,12 +186,16 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
rc =  -EINVAL;
goto out;
}
+
if ((rc = afu_register_irqs(ctx, work.num_interrupts)))
goto out;

if (work.flags & CXL_START_WORK_AMR)
amr = work.amr & mfspr(SPRN_UAMOR);

+   if (work.flags & CXL_START_WORK_TID)
+   ctx->assign_tidr = true;
+
ctx->mmio_err_ff = !!(work.flags & CXL_START_WORK_ERR_FF);

/*
@@ -263,8 +267,15 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
goto out;
}

-   ctx->status = STARTED;
rc = 0;
+   if (work.flags & CXL_START_WORK_TID) {
+   work.tid = ctx->tidr;
+   if (copy_to_user(uwork, , sizeof(work)))
+

[PATCH V7] cxl: Add support for ASB_Notify on POWER9

2018-01-11 Thread Christophe Lombard
The POWER9 core supports a new feature: ASB_Notify which requires the
support of the Special Purpose Register: TIDR.

The ASB_Notify command, generated by the AFU, will attempt to
wake-up the host thread identified by the particular LPID:PID:TID.

This patch assign a unique TIDR (thread id) for the current thread which
will be used in the process element entry.

Signed-off-by: Christophe Lombard 
Reviewed-by: Philippe Bergheaud 

---
Changelog[v7]
 - Rebased to latest upstream.
 - Added boolean: "need to allocate a TIDR"
 - Released the mutex and mark the context as STARTED in case of error.

Changelog[v6]
 - Rebased to latest upstream.
 - Updated the ioctl interface.
 - Removed the updated ptrace.
 - Assigned a unique TIDR for the current thread at a lower level.

Changelog[v5]
 - Rebased to latest upstream.
 - Updated the ioctl interface.
 - Returned the tid in the ioctl structure.

Changelog[v4]
 - Rebased to latest upstream.
 - Updated the ioctl interface.
 - Removed the field tid in the context structure.

Changelog[v3]
 - Rebased to latest upstream.
 - Updated attr->tid field in cxllib_get_PE_attributes().

Changelog[v2]
 - Rebased to latest upstream.
 - Updated the ioctl interface.
 - Added a checking to allow updating the TIDR if a P9 chip is present.
---
 arch/powerpc/kernel/process.c |  1 +
 drivers/misc/cxl/context.c|  2 ++
 drivers/misc/cxl/cxl.h|  3 +++
 drivers/misc/cxl/cxllib.c |  3 ++-
 drivers/misc/cxl/file.c   | 15 +--
 drivers/misc/cxl/native.c | 13 -
 include/uapi/misc/cxl.h   | 10 ++
 7 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 72be0c3..1dc39dd 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1589,6 +1589,7 @@ int set_thread_tidr(struct task_struct *t)
 
return 0;
 }
+EXPORT_SYMBOL_GPL(set_thread_tidr);
 
 #endif /* CONFIG_PPC64 */
 
diff --git a/drivers/misc/cxl/context.c b/drivers/misc/cxl/context.c
index 12a41b2..7ff315a 100644
--- a/drivers/misc/cxl/context.c
+++ b/drivers/misc/cxl/context.c
@@ -45,6 +45,8 @@ int cxl_context_init(struct cxl_context *ctx, struct cxl_afu 
*afu, bool master)
ctx->pid = NULL; /* Set in start work ioctl */
mutex_init(>mapping_lock);
ctx->mapping = NULL;
+   ctx->tidr = 0;
+   ctx->assign_tidr = false;
 
if (cxl_is_power8()) {
spin_lock_init(>sste_lock);
diff --git a/drivers/misc/cxl/cxl.h b/drivers/misc/cxl/cxl.h
index e46a406..53149fb 100644
--- a/drivers/misc/cxl/cxl.h
+++ b/drivers/misc/cxl/cxl.h
@@ -630,6 +630,9 @@ struct cxl_context {
struct list_head extra_irq_contexts;
 
struct mm_struct *mm;
+
+   u16 tidr;
+   bool assign_tidr;
 };
 
 struct cxl_irq_info;
diff --git a/drivers/misc/cxl/cxllib.c b/drivers/misc/cxl/cxllib.c
index dc9bc18..30ccba4 100644
--- a/drivers/misc/cxl/cxllib.c
+++ b/drivers/misc/cxl/cxllib.c
@@ -199,10 +199,11 @@ int cxllib_get_PE_attributes(struct task_struct *task,
 */
attr->pid = mm->context.id;
mmput(mm);
+   attr->tid = task->thread.tidr;
} else {
attr->pid = 0;
+   attr->tid = 0;
}
-   attr->tid = 0;
return 0;
 }
 EXPORT_SYMBOL_GPL(cxllib_get_PE_attributes);
diff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c
index 76c0b0c..93fd381 100644
--- a/drivers/misc/cxl/file.c
+++ b/drivers/misc/cxl/file.c
@@ -173,7 +173,7 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
 * flags are set it's invalid
 */
if (work.reserved1 || work.reserved2 || work.reserved3 ||
-   work.reserved4 || work.reserved5 || work.reserved6 ||
+   work.reserved4 || work.reserved5 ||
(work.flags & ~CXL_START_WORK_ALL)) {
rc = -EINVAL;
goto out;
@@ -186,12 +186,16 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
rc =  -EINVAL;
goto out;
}
+
if ((rc = afu_register_irqs(ctx, work.num_interrupts)))
goto out;
 
if (work.flags & CXL_START_WORK_AMR)
amr = work.amr & mfspr(SPRN_UAMOR);
 
+   if (work.flags & CXL_START_WORK_TID)
+   ctx->assign_tidr = true;
+
ctx->mmio_err_ff = !!(work.flags & CXL_START_WORK_ERR_FF);
 
/*
@@ -263,8 +267,15 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
goto out;
}
 
-   ctx->status = STARTED;
rc = 0;
+   if (work.flags & CXL_START_WORK_TID) {
+   work.tid = ctx->tidr;
+   if (copy_to_user(uwork, , sizeof(work)))
+   rc = -EFAULT;
+   }
+
+   ctx->status = STARTED;
+
 out:
mutex_unlock(>status_mutex);
return rc;
diff --git