PPC64: lockfix for rtas error log
PATCH 1/1 PPC64: lockfix for rtas error log
Paul,
Could you please apply the following path to the ameslab tree, and/or forward it to the main 2.6 kernel maintainers.
This patch moves the location of a lock in order to protect the contents of a buffer until it has been copied to its final destination. Prior to this, a race existed whereby the buffer could be filled even while it was being emptied.
--linas
ppc64/kernel/rtas.c renamed from ppc64/kernel/rtas.c.orig-pre-lockfix +7 -5
@@ -134,9 +134,10 @@ log_rtas_error(void)spin_lock_irqsave (&rtas.lock, s); rc =__log_rtas_error (); -spin_unlock_irqrestore (&rtas.lock, s); -if (rc ==0 ) +if (rc ==0 ) {log_error (rtas_err_buf,ERR_TYPE_RTAS_LOG ,0 ); + } +spin_unlock_irqrestore (&rtas.lock, s); }int
@@ -193,12 +194,13 @@ rtas_call(int token, int nargs, int nret outputs[i] = rtas_args->rets[i+1 ]; ret = (int )((nret >0 ) ? rtas_args->rets[0 ] :0 ); +if (logit) { +log_error (rtas_err_buf,ERR_TYPE_RTAS_LOG ,0 ); + } +/* Gotta do something different here, use global lock for now... */ spin_unlock_irqrestore (&rtas.lock, s); -if (logit) -log_error (rtas_err_buf,ERR_TYPE_RTAS_LOG ,0 ); -return ret; }
Quoted 6 lines · On Tue, Jun 29, 2004 at 05:50:07PM -0500, [email protected] wrote:
Paul,
Could you please apply the following path to the ameslab tree, and/or forward it to the main 2.6 kernel maintainers.
Quoted 6 lines
This patch moves the location of a lock in order to protect the contents of a buffer until it has been copied to its final destination. Prior to this, a race existed whereby the buffer could be filled even while it was being emptied.
Signed-off-by Linas Vepstas <[email protected]>
Hmm... I note that log_error() does nothing but call ppc_md.log_error, and I can't see anywhere that that is set to be non-NULL...
Quoted 31 lines
+++
arch/ppc64/kernel/rtas.c2004-06-29 17:14:05.000000000 -0500ppc64/kernel/rtas.c renamed from ppc64/kernel/rtas.c.orig-pre-lockfix +7
-5@@ -134,9 +134,10 @@ log_rtas_error(void)spin_lock_irqsave (&rtas.lock, s); rc =__log_rtas_error (); -spin_unlock_irqrestore (&rtas.lock, s); -if (rc ==0 ) +if (rc ==0 ) {log_error (rtas_err_buf,ERR_TYPE_RTAS_LOG ,0 ); + } +spin_unlock_irqrestore (&rtas.lock, s); }int @@ -193,12 +194,13 @@ rtas_call(int token, int nargs, int nret outputs[i] = rtas_args->rets[i+1 ]; ret = (int )((nret >0 ) ? rtas_args->rets[0 ] :0 ); +if (logit) { +log_error (rtas_err_buf,ERR_TYPE_RTAS_LOG ,0 ); + } +/* Gotta do something different here, use global lock for now... */ spin_unlock_irqrestore (&rtas.lock, s); -if (logit) -log_error (rtas_err_buf,ERR_TYPE_RTAS_LOG ,0 ); -return ret; }
Signature · 4 lines
David Gibson | For every complex problem there is a david AT gibson.dropbear.id.au | solution which is simple, neat and | wrong. http://www.ozlabs.org/people/dgibson
Quoted 12 lines · David Gibson
Quoted 11 lines · On Tue, Jun 29, 2004 at 05:50:07PM -0500, [email protected] wrote:
Paul,
Could you please apply the following path to the ameslab tree, and/or forward it to the main 2.6 kernel maintainers.
This patch moves the location of a lock in order to protect the contents of a buffer until it has been copied to its final destination. Prior to this, a race existed whereby the buffer could be filled even while it was being emptied.
Quoted 4 lines
Quoted 1 line
Signed-off-by Linas Vepstas <[email protected]>Hmm... I note that
log_error()does nothing but call ppc_md.log_error, and I can't see anywhere that that is set to be non-NULL...
grep log_error *.cchrp_setup.c: ppc_md.log_error = pSeries_log_error;
--linas
Quoted 9 lines · On Tue, 2004-06-29 at 17:50, [email protected] wrote:
Paul,
Could you please apply the following path to the ameslab tree, and/or forward it to the main 2.6 kernel maintainers.
This patch moves the location of a lock in order to protect the contents of a buffer until it has been copied to its final destination. Prior to this, a race existed whereby the buffer could be filled even while it was being emptied.
Hrm....
That's bad, I moved that out of the lock on purpose to avoid deadlocks, I think ppc_md.log_error can take the rtas lock again (nvram). We need to take a separate lock for the err buf if that function can be called concurrently I suppose.
Ben.
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 5 lines · On Tue, 2004-06-29 at 17:50, [email protected] wrote:
Paul,
Could you please apply the following path to the ameslab tree, and/or forward it to the main 2.6 kernel maintainers.
Quoted 8 lines
Quoted 4 lines
This patch moves the location of a lock in order to protect the contents of a buffer until it has been copied to its final destination. Prior to this, a race existed whereby the buffer could be filled even while it was being emptied.
Hrm....
That's bad, I moved that out of the lock on purpose to avoid deadlocks,
I looked for deadlocks, but didn't see anything obvious. I'll take your word, though.
Quoted 3 lines
I think ppc_md.log_error can take the rtas lock again (nvram). We need to take a separate lock for the err buf if that function can be called concurrently I suppose.
Well, the problem was that there is no lock that is protecting the use of the single, global buffer. Adding yet another lock is bad; it makes hunting for deadlocks that much more tedious and difficult; already, finding deadlocks is error-prone, and subject to bit-rot as future hackers update the code. So instead, the problem can be easily avoided by not using a global buffer. The code below mallocs/frees. Its not perf-critcal, so I don't mind malloc overhead. Would this work for you? Patch attached below.
--linas
ppc64/kernel/rtas.c renamed from ppc64/kernel/rtas.c.orig-pre-lockfix +20 -5
@@ -131,12 +131,20 @@ log_rtas_error(void) {unsigned long s;int rc; +char * buff_copy =NULL ;spin_lock_irqsave (&rtas.lock, s); rc =__log_rtas_error (); +if (rc ==0 ) { + buff_copy =kmalloc (RTAS_ERROR_LOG_MAX ,GFP_ATOMIC ); +memcpy (buff_copy, rtas_err_buf,RTAS_ERROR_LOG_MAX ); + }spin_unlock_irqrestore (&rtas.lock, s); -if (rc ==0 ) -log_error (rtas_err_buf,ERR_TYPE_RTAS_LOG ,0 ); + +if (buff_copy) { +log_error (buff_copy,ERR_TYPE_RTAS_LOG ,0 ); +kfree (buff_copy); + } }int
@@ -147,6 +155,7 @@ rtas_call(int token, int nargs, int nretint i, logit =0 ;unsigned long s;struct rtas_args *rtas_args; +char * buff_copy =NULL ;int ret;PPCDBG (PPCDBG_RTAS ,"Entering rtas_call\n" );
@@ -193,12 +202,18 @@ rtas_call(int token, int nargs, int nret outputs[i] = rtas_args->rets[i+1 ]; ret = (int )((nret >0 ) ? rtas_args->rets[0 ] :0 ); +if (logit) { + buff_copy =kmalloc (RTAS_ERROR_LOG_MAX ,GFP_ATOMIC ); +memcpy (buff_copy, rtas_err_buf,RTAS_ERROR_LOG_MAX ); + } +/* Gotta do something different here, use global lock for now... */ spin_unlock_irqrestore (&rtas.lock, s); -if (logit) -log_error (rtas_err_buf,ERR_TYPE_RTAS_LOG ,0 ); - +if (buff_copy) { +log_error (buff_copy,ERR_TYPE_RTAS_LOG ,0 ); +kfree (buff_copy); + }return ret; }
Quoted 9 lines
Well, the problem was that there is no lock that is protecting the use of the single, global buffer. Adding yet another lock is bad; it makes hunting for deadlocks that much more tedious and difficult; already, finding deadlocks is error-prone, and subject to bit-rot as future hackers update the code. So instead, the problem can be easily avoided by not using a global buffer. The code below mallocs/frees. Its not perf-critcal, so I don't mind malloc overhead. Would this work for you? Patch attached below.
I prefer that, but couldn't we move the kmalloc outside of the spinlock and so use GFP_KERNEL instead ?
Ben.
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 4 lines
So instead, the problem can be easily
avoided by not using a global buffer. The code below mallocs/frees. Its not perf-critcal, so I don't mind malloc overhead. Would this work for you? Patch attached below.I prefer that, but couldn't we move the kmalloc outside of the spinlock and so use
GFP_KERNELinstead ?
Isn't the global buffer used since it's in BSS, and as such, in low memory, guaranteed to be below 4GB? RTAS has limitations that restricts any passed-in buffers to be addressable as 32-bit real mode pointers, right?
-Olof
Quoted 4 lines
Isn't the global buffer used since it's in BSS, and as such, in low memory, guaranteed to be below 4GB? RTAS has limitations that restricts any passed-in buffers to be addressable as 32-bit real mode pointers, right?
The global buffer is still used within the spinlocked region for RTAS itself, the patch just uses a local buffer and copies into it from the global one before releasing the lock.
Ben.
PATCH 1/1 2.6 PPC64: lockfix for rtas error log (third-times-a-charm?)
In reply to Benjamin HerrenschmidtQuoted 10 lines · Benjamin Herrenschmidt
Quoted 9 lines
Well, the problem was that there is no lock that is protecting the use of the single, global buffer. Adding yet another lock is bad; it makes hunting for deadlocks that much more tedious and difficult; already, finding deadlocks is error-prone, and subject to bit-rot as future hackers update the code. So instead, the problem can be easily avoided by not using a global buffer. The code below mallocs/frees. Its not perf-critcal, so I don't mind malloc overhead. Would this work for you? Patch attached below.
Quoted 2 lines
I prefer that, but couldn't we move the kmalloc outside of the spinlock and so use
GFP_KERNELinstead ?
OK,
Upon closer analysis of the code, I see that log_rtas_error() was incorrectly named, and was being used incorrectly. The solution is to get rid of it entirely; see patch below. So:
-- In one case kmalloc must be GFP_ATOMIC because rtas_call()
can happen in any context, incl. irqs.
-- In the other case, I turned it into GFP_KENREL, at the cost
of doing a needless malloc/free in the vast majority of cases where there is no error. Small price, as I beleive that this routine is very rarely called.
Patch below,
--linas
Linas,
Quoted 4 lines
This patch moves the location of a lock in order to protect the contents of a buffer until it has been copied to its final destination. Prior to this, a race existed whereby the buffer could be filled even while it was being emptied.
Given that log_error() seems to be a no-op at the moment AFAICT, and that Ben H was concerned about possible deadlocks if log_error actually did do something, I'd like to see a resolution of (a) what log_error should be doing and (b) whether there is in fact any possibility of deadlock with this patch once (a) is resolved.
Thanks,
Paul.
Quoted 8 lines · Paul Mackerras
Linas,
Quoted 4 lines
This patch moves the location of a lock in order to protect the contents of a buffer until it has been copied to its final destination. Prior to this, a race existed whereby the buffer could be filled even while it was being emptied.
Given that
log_error()seems to be a no-op at the moment AFAICT, and
!!
Too many kernel trees. Someone must have whacked the ameslab tree by accident, or on purpose, because they got sick of seeing rtas messages. I don't find the RTAS messages to be pleasent, but simply whacking them is not the right solution. The following diff is between an older tree and the current tree. If you could re-add these lines, that would be great.
--linas
arch/ppc64/kernel/chrp_setup.c +6 -0
@@ -243,6 +243,12 @@ chrp_init(unsigned long r3, unsigned lon ppc_md.get_irq = xics_get_irq; } +#ifdef CONFIG_PPC_PSERIES + ppc_md.log_error = pSeries_log_error; +#else + ppc_md.log_error =NULL ; +#endif + ppc_md.init = chrp_init2; ppc_md.pcibios_fixup = pSeries_final_fixup;
Linas,
Quoted 6 lines
Too many kernel trees. Someone must have whacked the ameslab tree by accident, or on purpose, because they got sick of seeing rtas messages. I don't find the RTAS messages to be pleasent, but simply whacking them is not the right solution. The following diff is between an older tree and the current tree. If you could re-add these lines, that would be great.
As far as I can see, the ameslab tree has _never_ contained those lines. The last change to chrp_setup.c was on 1 May 2004, and neither that version nor any of the earlier versions that I looked at have those lines. Are you sure you don't have that as a local change in your copy? Do a bk sfiles -i and a bk push -n and see if it shows up.
In any case the #ifdef is redundant, because chrp_setup.o is only linked in if CONFIG_PPC_PSERIES is set.
As for the RTAS messages being printk'd, the only possible justification would be if there was a userspace tool to analyse them. I don't know if such a thing exists, and if it does, I certainly don't have a copy. Is anyone working on that?
Paul.
Quoted 5 lines
As far as I can see, the ameslab tree has _never_ contained those lines. The last change to
chrp_setup.cwas on 1 May 2004, and neither that version nor any of the earlier versions that I looked at have those lines. Are you sure you don't have that as a local change in your copy? Do a bk sfiles -i and a bk push -n and see if it shows up.
Back on May 6th, Nathan Fontenot posted a patch to linuxppc64, that had this fixed when he noticed it got removed. It looks like the patch was never merged.
Quoted 4 lines
As for the RTAS messages being printk'd, the only possible justification would be if there was a userspace tool to analyse them. I don't know if such a thing exists, and if it does, I certainly don't have a copy. Is anyone working on that?
I pushed a patch to remove the log_error messages from going to the console by default. The error logs still should be put in /proc/ppc64/rtas/error_log for rtas_errd to pick them up and send it to ELA for decode. These apps are already done and can be found on IBM's diagnostic service website.
http://techsupport.services.ibm.com/server/lopdiags/suselinux/pseries
Thanks,
Jake