diff mbox series

[v2,2/2] powerpc: Do not assign thread.tidr if already assigned

Message ID 20171124083338.15283-2-vaibhav@linux.vnet.ibm.com (mailing list archive)
State Accepted
Commit 7e4d4233260be0611c7fbdb2730c12731c4b8dc0
Headers show
Series [v2,1/2] powerpc: Avoid signed to unsigned conversion in set_thread_tidr() | expand

Commit Message

Vaibhav Jain Nov. 24, 2017, 8:33 a.m. UTC
If set_thread_tidr() is called twice for same task_struct then it will
allocate a new tidr value to it leaving the previous value still
dangling in the vas_thread_ida table.

To fix this the patch changes set_thread_tidr() to check if a tidr
value is already assigned to the task_struct and if yes then returns
the existing value from function instead of allocating a new one.

Fixes: ec233ede4c86("powerpc: Add support for setting SPRN_TIDR")
Signed-off-by: Vaibhav Jain <vaibhav@linux.vnet.ibm.com>
---
v2 ->	Fix minor spell errors in patch description
---
 arch/powerpc/kernel/process.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Andrew Donnellan Nov. 27, 2017, 1:06 a.m. UTC | #1
On 24/11/17 19:33, Vaibhav Jain wrote:
> If set_thread_tidr() is called twice for same task_struct then it will
> allocate a new tidr value to it leaving the previous value still
> dangling in the vas_thread_ida table.
> 
> To fix this the patch changes set_thread_tidr() to check if a tidr
> value is already assigned to the task_struct and if yes then returns
> the existing value from function instead of allocating a new one.
> 
> Fixes: ec233ede4c86("powerpc: Add support for setting SPRN_TIDR")
> Signed-off-by: Vaibhav Jain <vaibhav@linux.vnet.ibm.com>

Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>

> ---
> v2 ->	Fix minor spell errors in patch description
> ---
>   arch/powerpc/kernel/process.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
> index 5d8176c7c2d8..9a72282b022d 100644
> --- a/arch/powerpc/kernel/process.c
> +++ b/arch/powerpc/kernel/process.c
> @@ -1577,6 +1577,9 @@ int set_thread_tidr(struct task_struct *t)
>   	if (t != current)
>   		return -EINVAL;
> 
> +	if (t->thread.tidr)
> +		return t->thread.tidr;
> +
>   	rc = assign_thread_tidr();
>   	if (rc > 0) {
>   		t->thread.tidr = rc;
>
Michael Ellerman Nov. 29, 2017, 12:06 p.m. UTC | #2
On Fri, 2017-11-24 at 08:33:38 UTC, Vaibhav Jain wrote:
> If set_thread_tidr() is called twice for same task_struct then it will
> allocate a new tidr value to it leaving the previous value still
> dangling in the vas_thread_ida table.
> 
> To fix this the patch changes set_thread_tidr() to check if a tidr
> value is already assigned to the task_struct and if yes then returns
> the existing value from function instead of allocating a new one.
> 
> Fixes: ec233ede4c86("powerpc: Add support for setting SPRN_TIDR")
> Signed-off-by: Vaibhav Jain <vaibhav@linux.vnet.ibm.com>
> Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/7e4d4233260be0611c7fbdb2730c12

cheers
diff mbox series

Patch

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 5d8176c7c2d8..9a72282b022d 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1577,6 +1577,9 @@  int set_thread_tidr(struct task_struct *t)
 	if (t != current)
 		return -EINVAL;
 
+	if (t->thread.tidr)
+		return t->thread.tidr;
+
 	rc = assign_thread_tidr();
 	if (rc > 0) {
 		t->thread.tidr = rc;