From: Eric W. Biederman <hidden> Date: 2018-09-18 17:41:26
This is the continuation of my work to sort out signaling of exceptions
with siginfo. The old functions by passing siginfo resulted in many
cases of fields of siginfo that were not initialized and then passed to
userspace, and also resulted in callers getting confused and
initializing the wrong fields. My remedy is to have specific functions
for sending each different kind of signal with siginfo. Those functions
take the information needed to fill in siginfo and do the work
themselves.
This is my set of changes to update powerpc to use those functions.
Along with some refactoring so those functions can be cleanly used.
Folks please review and double check me. I think I have kept these
changes simple and obviously correct but I am human and mess up
sometimes.
After these patches have had a chance to be reviewed I plan to merge
them by my siginfo tree. If you would rather take them in the powerpc
tree let me know. All of the prerequisites should have been merged
through Linus's tree several releases ago.
Eric W. Biederman (9):
signal/powerpc: Use force_sig_mceerr as appropriate
signal/powerpc: Remove pkey parameter from __bad_area
signal/powerpc: Call _exception_pkey directly from bad_key_fault_exception
signal/powerpc: Remove pkey parameter from __bad_area_nosemaphore
signal/powerpc: Factor the common exception code into exception_common
signal/powerpc: Call force_sig_fault from _exception
signal/poewrpc: Specialize _exception_pkey for handling pkey exceptions
signal/powerpc: Simplify _exception_pkey by using force_sig_pkuerr
signal/powerpc: Use force_sig_fault where appropriate
arch/powerpc/include/asm/bug.h | 2 +-
arch/powerpc/kernel/process.c | 9 +----
arch/powerpc/kernel/traps.c | 27 ++++++++-------
arch/powerpc/mm/fault.c | 55 +++++++++++++++++--------------
arch/powerpc/platforms/cell/spu_base.c | 4 +--
arch/powerpc/platforms/cell/spufs/fault.c | 26 +++++----------
6 files changed, 57 insertions(+), 66 deletions(-)
Eric
From: Eric W. Biederman <hidden> Date: 2018-09-18 17:59:09
In do_sigbus isolate the mceerr signaling code and call
force_sig_mceerr instead of falling through to the force_sig_info that
works for all of the other signals.
Signed-off-by: "Eric W. Biederman" <redacted>
---
arch/powerpc/mm/fault.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
From: Eric W. Biederman <hidden> Date: 2018-09-18 17:59:27
There are no callers of __bad_area that pass in a pkey parameter so it makes
no sense to take one.
Signed-off-by: "Eric W. Biederman" <redacted>
---
arch/powerpc/mm/fault.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
@@ -124,8 +124,7 @@ static noinline int bad_area_nosemaphore(struct pt_regs *regs, unsigned long addreturn__bad_area_nosemaphore(regs,address,SEGV_MAPERR,0);}-staticint__bad_area(structpt_regs*regs,unsignedlongaddress,intsi_code,-intpkey)+staticint__bad_area(structpt_regs*regs,unsignedlongaddress,intsi_code){structmm_struct*mm=current->mm;
@@ -135,12 +134,12 @@ static int __bad_area(struct pt_regs *regs, unsigned long address, int si_code,*/up_read(&mm->mmap_sem);-return__bad_area_nosemaphore(regs,address,si_code,pkey);+return__bad_area_nosemaphore(regs,address,si_code,0);}staticnoinlineintbad_area(structpt_regs*regs,unsignedlongaddress){-return__bad_area(regs,address,SEGV_MAPERR,0);+return__bad_area(regs,address,SEGV_MAPERR);}staticintbad_key_fault_exception(structpt_regs*regs,unsignedlongaddress,
@@ -151,7 +150,7 @@ static int bad_key_fault_exception(struct pt_regs *regs, unsigned long address,staticnoinlineintbad_access(structpt_regs*regs,unsignedlongaddress){-return__bad_area(regs,address,SEGV_ACCERR,0);+return__bad_area(regs,address,SEGV_ACCERR);}staticintdo_sigbus(structpt_regs*regs,unsignedlongaddress,
From: Eric W. Biederman <hidden> Date: 2018-09-18 17:59:33
This removes the need for other code paths to deal with pkey exceptions.
Signed-off-by: "Eric W. Biederman" <redacted>
---
arch/powerpc/mm/fault.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
From: Eric W. Biederman <hidden> Date: 2018-09-18 17:59:38
Now that bad_key_fault_exception no longer calls __bad_area_nosemaphore
there is no reason for __bad_area_nosemaphore to handle pkeys.
Signed-off-by: "Eric W. Biederman" <redacted>
---
arch/powerpc/mm/fault.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
@@ -103,8 +103,7 @@ static bool store_updates_sp(unsigned int inst)*/staticint-__bad_area_nosemaphore(structpt_regs*regs,unsignedlongaddress,intsi_code,-intpkey)+__bad_area_nosemaphore(structpt_regs*regs,unsignedlongaddress,intsi_code){/**Ifweareinkernelmode,bailoutwithaSEGV,thiswill
@@ -114,14 +113,14 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long address, int si_code,if(!user_mode(regs))returnSIGSEGV;-_exception_pkey(SIGSEGV,regs,si_code,address,pkey);+_exception(SIGSEGV,regs,si_code,address);return0;}staticnoinlineintbad_area_nosemaphore(structpt_regs*regs,unsignedlongaddress){-return__bad_area_nosemaphore(regs,address,SEGV_MAPERR,0);+return__bad_area_nosemaphore(regs,address,SEGV_MAPERR);}staticint__bad_area(structpt_regs*regs,unsignedlongaddress,intsi_code)
@@ -134,7 +133,7 @@ static int __bad_area(struct pt_regs *regs, unsigned long address, int si_code)*/up_read(&mm->mmap_sem);-return__bad_area_nosemaphore(regs,address,si_code,0);+return__bad_area_nosemaphore(regs,address,si_code);}staticnoinlineintbad_area(structpt_regs*regs,unsignedlongaddress)
From: Eric W. Biederman <hidden> Date: 2018-09-18 17:59:43
It is brittle and wrong to populate si_pkey when there was not a pkey
exception. The field does not exist for all si_codes and in some
cases another field exists in the same memory location.
So factor out the code that all exceptions handlers must run
into exception_common, leaving the individual exception handlers
to generate the signals themselves.
Signed-off-by: "Eric W. Biederman" <redacted>
---
arch/powerpc/kernel/traps.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
From: Eric W. Biederman <hidden> Date: 2018-09-18 17:59:48
The callers of _exception don't need the pkey exception logic because
they are not processing a pkey exception. So just call exception_common
directly and then call force_sig_fault to generate the appropriate siginfo
and deliver the appropriate signal.
Signed-off-by: "Eric W. Biederman" <redacted>
---
arch/powerpc/kernel/traps.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
From: Eric W. Biederman <hidden> Date: 2018-09-18 18:00:10
Now that _exception no longer calls _exception_pkey it is no longer
necessary to handle any signal with any si_code. All pkey exceptions
are SIGSEGV with paired with SEGV_PKUERR. So just handle
that case and remove the now unnecessary parameters from _exception_pkey.
Signed-off-by: "Eric W. Biederman" <redacted>
---
arch/powerpc/include/asm/bug.h | 2 +-
arch/powerpc/kernel/traps.c | 10 +++++-----
arch/powerpc/mm/fault.c | 2 +-
3 files changed, 7 insertions(+), 7 deletions(-)
From: Eric W. Biederman <hidden> Date: 2018-09-18 18:00:13
Call force_sig_pkuerr directly instead of rolling it by hand
in _exception_pkey.
Signed-off-by: "Eric W. Biederman" <redacted>
---
arch/powerpc/kernel/traps.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
@@ -36,42 +36,32 @@staticvoidspufs_handle_event(structspu_context*ctx,unsignedlongea,inttype){-siginfo_tinfo;-if(ctx->flags&SPU_CREATE_EVENTS_ENABLED){ctx->event_return|=type;wake_up_all(&ctx->stop_wq);return;}-clear_siginfo(&info);-switch(type){caseSPE_EVENT_INVALID_DMA:-info.si_signo=SIGBUS;-info.si_code=BUS_OBJERR;+force_sig_fault(SIGBUS,BUS_OBJERR,NULL,current);break;caseSPE_EVENT_SPE_DATA_STORAGE:-info.si_signo=SIGSEGV;-info.si_addr=(void__user*)ea;-info.si_code=SEGV_ACCERR;ctx->ops->restart_dma(ctx);+force_sig_fault(SIGSEGV,SEGV_ACCERR,(void__user*)ea,+current);break;caseSPE_EVENT_DMA_ALIGNMENT:-info.si_signo=SIGBUS;/* DAR isn't set for an alignment fault :( */-info.si_code=BUS_ADRALN;+force_sig_fault(SIGBUS,BUS_ADRALN,NULL,current);break;caseSPE_EVENT_SPE_ERROR:-info.si_signo=SIGILL;-info.si_addr=(void__user*)(unsignedlong)-ctx->ops->npc_read(ctx)-4;-info.si_code=ILL_ILLOPC;+force_sig_fault(+SIGILL,ILL_ILLOPC,+(void__user*)(unsignedlong)+ctx->ops->npc_read(ctx)-4,current);break;}--if(info.si_signo)-force_sig_info(info.si_signo,&info,current);}intspufs_handle_class0(structspu_context*ctx)
From: Stephen Rothwell <hidden> Date: 2018-09-21 08:21:06
Hi Eric,
On Tue, 18 Sep 2018 19:58:42 +0200 "Eric W. Biederman" [off-list ref] wrote:
In do_sigbus isolate the mceerr signaling code and call
force_sig_mceerr instead of falling through to the force_sig_info that
works for all of the other signals.
Signed-off-by: "Eric W. Biederman" <redacted>
Looks good to me. I was going to mention further cleanup, but I see
you do that in a later patch.
Reviewed-by: Stephen Rothwell <redacted>
--
Cheers,
Stephen Rothwell
From: Stephen Rothwell <hidden> Date: 2018-09-21 08:32:33
Hi Eric,
On Tue, 18 Sep 2018 19:58:45 +0200 "Eric W. Biederman" [off-list ref] wrote:
Now that bad_key_fault_exception no longer calls __bad_area_nosemaphore
there is no reason for __bad_area_nosemaphore to handle pkeys.
Signed-off-by: "Eric W. Biederman" <redacted>
Again, very straight forward given that _exception(a,b,c,d) -> _exception_pkey(a,b,c,d,0).
Reviewed-by: Stephen Rothwell <redacted>
--
Cheers,
Stephen Rothwell
From: Stephen Rothwell <hidden> Date: 2018-09-21 08:38:14
Hi Eric,
On Tue, 18 Sep 2018 19:58:46 +0200 "Eric W. Biederman" [off-list ref] wrote:
It is brittle and wrong to populate si_pkey when there was not a pkey
exception. The field does not exist for all si_codes and in some
cases another field exists in the same memory location.
So factor out the code that all exceptions handlers must run
into exception_common, leaving the individual exception handlers
to generate the signals themselves.
Signed-off-by: "Eric W. Biederman" <redacted>
Clearly no change in semantics.
Reviewed-by: Stephen Rothwell <redacted>
--
Cheers,
Stephen Rothwell
From: Stephen Rothwell <hidden> Date: 2018-09-21 08:48:24
Hi Eric,
On Tue, 18 Sep 2018 19:58:47 +0200 "Eric W. Biederman" [off-list ref] wrote:
The callers of _exception don't need the pkey exception logic because
they are not processing a pkey exception. So just call exception_common
directly and then call force_sig_fault to generate the appropriate siginfo
and deliver the appropriate signal.
Signed-off-by: "Eric W. Biederman" <redacted>
Looks right to me.
Reviewed-by: Stephen Rothwell <redacted>
--
Cheers,
Stephen Rothwell
From: Stephen Rothwell <hidden> Date: 2018-09-21 08:54:35
Hi Eric,
On Tue, 18 Sep 2018 19:58:48 +0200 "Eric W. Biederman" [off-list ref] wrote:
Now that _exception no longer calls _exception_pkey it is no longer
necessary to handle any signal with any si_code. All pkey exceptions
are SIGSEGV with paired with SEGV_PKUERR. So just handle
that case and remove the now unnecessary parameters from _exception_pkey.
Signed-off-by: "Eric W. Biederman" <redacted>
Looks fine to me (small query below).
Reviewed-by: Stephen Rothwell <redacted>
Hi Eric,
On Tue, 18 Sep 2018 19:58:48 +0200 "Eric W. Biederman" [off-list ref] wrote:
quoted
Now that _exception no longer calls _exception_pkey it is no longer
necessary to handle any signal with any si_code. All pkey exceptions
are SIGSEGV with paired with SEGV_PKUERR. So just handle
that case and remove the now unnecessary parameters from _exception_pkey.
Signed-off-by: "Eric W. Biederman" <redacted>
Looks fine to me (small query below).
Reviewed-by: Stephen Rothwell <redacted>