linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: "Joseph S. Myers" <joseph@codesourcery.com>
To: Scott Wood <scottwood@freescale.com>
Cc: Liu Yu <yu.liu@freescale.com>,
	linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
	Shan Hai <shan.hai@windriver.com>
Subject: Re: [PATCH 1/6] powerpc: fix exception clearing in e500 SPE float emulation
Date: Sat, 23 Nov 2013 01:22:31 +0000	[thread overview]
Message-ID: <Pine.LNX.4.64.1311230053360.12354@digraph.polyomino.org.uk> (raw)
In-Reply-To: <1385159644.1403.532.camel@snotra.buserror.net>

On Fri, 22 Nov 2013, Scott Wood wrote:

> This sounds like an incompatible change to userspace API.  What about
> older glibc?  What about user code that directly manipulates these bits
> rather than going through libc, or uses a libc other than glibc?  Where
> is this API requirement documented?

The previous EGLIBC port, and the uClibc code copied from it, is 
fundamentally broken as regards any use of prctl for floating-point 
exceptions because it didn't use the PR_FP_EXC_SW_ENABLE bit in its prctl 
calls (and did various worse things, such as passing a pointer when prctl 
expected an integer).  If you avoid anything where prctl is used, the 
clearing of sticky bits still means it will never give anything 
approximating correct exception semantics with existing kernels.  I don't 
believe the patch makes things any worse for existing code that doesn't 
try to inform the kernel of changes to sticky bits - such code may get 
incorrect exceptions in some cases, but it would have done so anyway in 
other cases.

This is the best API I could come up with to fix the fundamentally broken 
nature of what came before, taking into account that in many cases a prctl 
call is already needed along with userspace manipulation of exception 
bits.  I'm not aware of any kernel documentation where this sort of 
subarchitecture-specific API detail is documented.  (The API also includes 
such things as needing to leave the spefscr trap-enable bits set and use 
prctl to control whether SIGFPE results from exceptions.)

> I think the impact of this could be reduced by using this mechanism only
> to clear bits, rather than set them.  That is, if the exception bit is
> unset, don't set it just because it's set in spefscr_last -- but if it's
> not set in spefscr_last, and the emulation code doesn't want to set it,
> then clear it.

It should already be the case in this patch that if a bit is clear in 
spefscr, and set in spefscr_last (i.e. userspace did not inform the kernel 
of clearing the bit, and no traps since then have resulted in the kernel 
noticing it was cleared), it won't get set unless the emulation code wants 
to set it.  The sole place spefscr_last is read is in the statement 
"__FPU_FPSCR &= ~(FP_EX_INVALID | FP_EX_UNDERFLOW) | 
current->thread.spefscr_last;" - if the bit is already clear in spefscr, 
this statement has no effect on it.

> Are there any cases where the exception bit can be set without the
> kernel taking a trap, or is userspace manipulation limited to clearing
> the bits?

Userspace can both set and clear the bits without a trap.  For example, 
fesetenv restores a saved value of spefscr which may both set and clear 
bits (and then it calls prctl because it needs to do so anyway to restore 
the saved state for which exceptions were enabled).  fesetexceptflag 
restores saved state of particular exceptions without a trap (so needs to 
call prctl specially to inform the kernel of a change).

-- 
Joseph S. Myers
joseph@codesourcery.com

  reply	other threads:[~2013-11-23  1:22 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-04 16:50 [PATCH 0/6] powerpc/math-emu: e500 SPE float emulation fixes Joseph S. Myers
2013-11-04 16:52 ` [PATCH 1/6] powerpc: fix exception clearing in e500 SPE float emulation Joseph S. Myers
2013-11-22 22:34   ` Scott Wood
2013-11-23  1:22     ` Joseph S. Myers [this message]
2013-12-07  0:32       ` Scott Wood
2013-12-07  0:48         ` questions: second of the 2 pcie controllers does not scan the bus Ruchika
2013-12-07 13:26           ` Ruchika
2013-12-09 22:50           ` Scott Wood
2013-12-10 23:07         ` [PATCHv2 1/6] powerpc: fix exception clearing in e500 SPE float emulation Joseph S. Myers
2013-11-04 16:53 ` [PATCH 2/6] powerpc: fix e500 SPE float rounding inexactness detection Joseph S. Myers
2013-11-04 16:53 ` [PATCH 3/6] math-emu: fix floating-point to integer unsigned saturation Joseph S. Myers
2013-11-04 16:54 ` [PATCH 4/6] math-emu: fix floating-point to integer overflow detection Joseph S. Myers
2013-11-04 16:54 ` [PATCH 5/6] powerpc: fix e500 SPE float to integer and fixed-point conversions Joseph S. Myers
2013-11-04 16:55 ` [PATCH 6/6] powerpc: fix e500 SPE float SIGFPE generation Joseph S. Myers
2013-11-11 14:29 ` Ping Re: [PATCH 0/6] powerpc/math-emu: e500 SPE float emulation fixes Joseph S. Myers
2013-11-18 14:54   ` Ping^2 " Joseph S. Myers
2013-11-18 19:07     ` Scott Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.1311230053360.12354@digraph.polyomino.org.uk \
    --to=joseph@codesourcery.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=scottwood@freescale.com \
    --cc=shan.hai@windriver.com \
    --cc=yu.liu@freescale.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).