This is the mail archive of the libc-ports@sources.redhat.com mailing list for the libc-ports project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch, mips, memmove] Remove memmove's use of memcpy on MIPS


While doing some other testing Maciej Rozycki found a bug in the MIPS
memmove.  A few weeks ago (after the release of 2.17) I updated the MIPS
memcpy.S to use the prepare-to-store prefetch instruction.  This makes
memcpy (particularly long memcpy's) much faster.  The problem is that the
prepare-to-store prefetch is not a 'real' prefetch, it doesn't read the
memory into the cache but, if the data is not already in cache, it creates a
cache line with all zeros and assumes that the user will write to the entire
line.  If you try to read from that cache line or if you don't write to the
entire cache line before it is flushed you will get bad results.

By setting MEMCPY_OK_FOR_FWD_MEMMOVE in memmove.c, we are causing memmove
to call memcpy for overlapping forward memmoves and while the MIPS memcpy
does correctly read the source bytes before writing them, it may do a
(prepare-to-store) prefetch on data in the source buffer before reading it.
This will corrupt the data it is trying to read and give bad results.

Rather then use a slower safer prefetch for memcpy, which would also fix
this problem,  I would like to remove the setting of MEMCPY_OK_FOR_FWD_MEMMOVE
in memmove.c.

OK for checkin?

Steve Ellcey
sellcey@mips.com



2013-01-25  Steve Ellcey  <sellcey@mips.com>

	* sysdeps/mips/memmove.c: Do not set MEMCPY_OK_FOR_FWD_MEMMOVE.



diff --git a/ports/sysdeps/mips/memmove.c b/ports/sysdeps/mips/memmove.c
index fd36859..ae312d1 100644
--- a/ports/sysdeps/mips/memmove.c
+++ b/ports/sysdeps/mips/memmove.c
@@ -18,6 +18,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-/* MIPS' implementation of memcpy is safe to use for memmove.  */
-#define MEMCPY_OK_FOR_FWD_MEMMOVE 1
+/* MIPS' implementation of memcpy is not safe to use for memmove
+   due to the use of the prepare-to-store prefetch so we do not
+   define MEMCPY_OK_FOR_FWD_MEMMOVE.  */
+
 #include <string/memmove.c>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]