Page MenuHomeFreeBSD

riscv: Fix copyin/copyout

Authored by kristof on Jul 29 2019, 12:58 PM.



r343275 introduced a performance optimisation to the copyin/copyout
routines by attempting to copy word-per-word rather than byte-per-byte
where possible.

This optimisation failed to account for cases where the buffer is longer
than XLEN_BYTES, but due to misalignment does not not allow for any
word-sized copies. E.g. a 9 byte buffer (with XLEN_BYTES == 8) which is
misaligned by 2 bytes. The code nevertheless did a single full-word
copy, which meant we copied too much data. This potentially clobbered
other data.

This is most easily demonstrated by a simple sysctl -a.

Fix it by not assuming that we'll always have at least one full-word
copy to do, but instead checking the remaining length first.

Sponsored by: Axiado

Diff Detail

rS FreeBSD src repository
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

kristof created this revision.Jul 29 2019, 12:58 PM

Looks okay to me, but would you mind updating the diff with full context?

kristof updated this revision to Diff 60232.Jul 29 2019, 1:57 PM

Full context.

markj accepted this revision.Jul 29 2019, 2:22 PM
This revision is now accepted and ready to land.Jul 29 2019, 2:22 PM
mhorne accepted this revision.Jul 29 2019, 2:39 PM
This revision was automatically updated to reflect the committed changes.