Paul Floyd [Wed, 1 May 2024 13:17:50 +0000 (15:17 +0200)]
FreeBSD ioctl: CAMIOCOMMAND with subcommmand XPT_DEV_MATCH
CAM is the FreeBSD disk I/O subsystem (Common Access Method).
I had picked up an implementation of this from bitbucket done
by a FreeBSD dev. It was done a long time ago, around 2013 on
Valgrind 3.8. Mercurial bitbucket is now kickbucket. There
were 2 big problems.
1. Bit rot. The CAM ioctl is versioned and the version that I
copies was 0x15 whilst the current version is 0x2a, 6 versions
later. That meant that the ioctl wrapper wasn't even getting
called. In addition, as the versioning implies, the data structures
were also out of date.
2. Might also be bit rot but the data structures were copied with
QUEUE_MACRO_DEBUG_TRACE enabled. For that to work the whole
FreeBSD system needs to be built with it turned on. With that
macro turned on in Valgrind the data structures were offset
compared to the kernel, and nothing worked correctly.
There are still a huge number of CAM ioctls unimplemented.
"camcontrol devlist" now works wihtout generating false positives.
Paul Floyd [Tue, 30 Apr 2024 05:58:38 +0000 (07:58 +0200)]
DRD regtest: try to make drd/tests/pth_mutex_signal less flaky
Use a loop of 1ms usleeps rather than a single 1s usleep.
This is usually more releable in ensuring that there's a context switch and that signals
get handled in the order that we want.
Paul Floyd [Mon, 29 Apr 2024 19:11:53 +0000 (21:11 +0200)]
Darwin regtest: don't visit dSYM directories with tests/vg_regtest
Due to the extra directory depth of dSYM directories the following line
my $dashes = "-" x (50 - length $full_dir);
generates a warning on Darwin because the length of $full_dir is more than 50
("Negative repeat count does nothing"). This change makes test_one_dir return
early if the directory contains "dSYM".
Paul Floyd [Sun, 28 Apr 2024 16:19:55 +0000 (18:19 +0200)]
fd leaks: add an assert for the error extra data
Coverity claims that it could cause a NULL dereference. I don't
think it's possible. Adding an assert will at least make things
clearer if Coverity ever turns out to be right.
One reported by Fabien Launay on valgrind-developers. The other
two found with grep. There's a fourth one, but it's in a patch
file so I've left it for now.
Andreas Arnez [Thu, 25 Apr 2024 12:38:45 +0000 (14:38 +0200)]
s390x: Add support for the `NNPA' instruction
Finalize the NNPA facility support by handling the NNPA instruction
itself, using the new "extension" approach. Also reflect NNPA facility
support in HWCAP and in the STFLE bits.
Paul Floyd [Wed, 24 Apr 2024 19:34:03 +0000 (21:34 +0200)]
FreeBSD syscall: add wrapper for kcmp
For FreeBSD 15.0-CURRENT. Will need to add for 14.1 when it is out.
Mostly the same as the Linux kcmp syscall (small differences in the
supported types).
Mark Wielaard [Wed, 24 Apr 2024 18:50:43 +0000 (20:50 +0200)]
Add prereqs for tests using python 3.9+
Adds a script tests/python_test.sh that checks whether there is a python3
binary and that it supports python version 3.9 or higher. Use this script
in the various cachegrind/tests annotate vgtests as prereq.
Paul Floyd [Wed, 24 Apr 2024 18:14:40 +0000 (20:14 +0200)]
FreeBSD syswrap: wrong length for __sysctlbyname(name)
Copied and pasted from syscall where name is a pointer to array of ints
so the size has a '*sizeof(int)'. -byname name is a char* so should not
have the *4 factor.
From
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=278566
Andreas Arnez [Tue, 23 Apr 2024 14:27:11 +0000 (16:27 +0200)]
s390x: Improve operand names in trackers for PRNO
The operand names in the trackers called in the implementation of the PRNO
extension do not indicate the extension being handled. Change this by
adding the name PRNO to all these names.
Mark Wielaard [Tue, 23 Apr 2024 12:14:33 +0000 (14:14 +0200)]
Filter away "main" differences in filter_fdleak
Stack traces showing where fds were created show some differences in
the "main" function, different line numbers, or (in binary) or (below
main). Since the precise location of the original call in the main
function isn't the goal of these tests just filer them all out and
replace them with a simple "main".
Paul Floyd [Sat, 20 Apr 2024 05:54:05 +0000 (07:54 +0200)]
FreeBSD suppression: reachable for setlocale
Normally I have LANG=en_GB.UTF-8 and LC_ALL=C but if I switch to
C.UTF-8 for everything (which is the default for a fresh install)
then setlocale comes into the picture with a reachable allocation
on exit.
Mark Wielaard [Fri, 19 Apr 2024 20:46:11 +0000 (22:46 +0200)]
core errors suppression support
Add two new functions core_get_extra_suppression_info and
core_get_error_name as alternatives for tool suppression callbacks.
These functions are used in gen_suppression.
Instead of a tool name, a core error component name is "CoreError".
Two new suppression kinds FdBadCloseSupp and FdNotClosedSupp
were added. Corresponding to the FdBadClose and FdNotClosed
error kinds.
core_error_matches_suppression matches these suppression kinds
with error kinds.
core_get_extra_suppression_info and core_print_extra_suppression_use
are noops for core errors.
is_suppressible_error, supp_matches_error, load_one_suppressions_file
and show_used_suppressions have been adjusted to work with core
error kinds.
A new function VG_(found_or_suppressed_errs) helps to not output
an empty error summary if only core errors are requested, but no
errors were detected.
VG_(clo_track_fds) has been moved from pub_core_options.h to
pub_tool_options.h. And VG_(needs_core_errors) now takes a Bool
that can be set to false in the tool post_clo_init handler. This
is used in the none tool to request core errors, but disable all
reporting if no option has been given that enables such errors.
This make sure only the none/tests/fdleak_ipv4.stderr.exp needs
adjustment. For all other tests the output is exactly as before.
Improve file descriptor xml output, add fd and path elements
Add needs_xml_output to none tool so it can also output xml when
--track-fds enabled.
Use xml protocolversion 5 when clo_track_fds is enabled
Split OpenFD pathname and description. Add description when a file
descriptor is closed so it can be used in a future error. On error
print <fd> element and (if known) a <path> element.
Mark Wielaard [Wed, 20 Mar 2024 05:44:23 +0000 (01:44 -0400)]
Add core errors and use them to implement file descriptor tracker
All the tool error callbacks now have a core error equivalent.
core errors are negative (while tool errors are positive).
There are two new ones for tracking issues with file descriptors.
FdBadClose (-2) and FdNotClosed (-3).
Add following core error functions with delegates to file descriptor
specific functions (implemented in syswrap-generic):
- core_eq_Error (fd_eq_Error)
Compares core errors to detect duplicates
- core_before_pp_Error (fd_before_pp_Error)
Currently prints nothing for known core errors and
exists with FATAL for unknown core errors
- core_pp_Error (fd_pp_Error)
For FdBadClose prints the backtraces for the file descriptor was
opened, where it was originally closed and where it was closed again.
For FdNotClosed prints where the file descriptor was opened.
- core_update_extra (fd_update_extra)
Returns the size of the BadCloseExtra or FdNotClosedExtra struct
which data needs to be saved (the fd number, pathname/description
and previous backtraces).
We now accept the error (ExeContext) where to be NULL.
This is necessary for reporting not closed file descriptors when
the descriptor is inherited from the parent (so wasn't actually
created and doesn't have a 'where' in the current process code).
All the testcases still pass since the (stderr) output is the
same. But now they count as "real" errors. And so --error-exitcode
does now also work for file descriptor errors or leaks.
https://bugs.kde.org/show_bug.cgi?id=362680
Co-authored-by: Alexandra Hájková <ahajkova@redhat.com>
Andreas Arnez [Thu, 18 Apr 2024 11:49:52 +0000 (13:49 +0200)]
Add extension concept and exploit it for s390x `PRNO'
z/Architecture specifies various "complex" machine instructions whose
register and memory effects cannot be expressed with Valgrind's current
mechanisms.
One example is the PPNO instruction -- "perform pseudorandom number
operation", whose main purpose is to generate a chunk of pseudorandom
data. When doing so, it reads and writes a so-called "parameter block"
while also writing the variable-sized pseudorandom data itself. These
memory effects cannot be adequately represented by the IRDirty concept.
Instead of using dirty helpers, a different approach is to treat such
instructions similar to syscalls, adding a new IRJumpKind for this
purpose.
This patch provides an implementation of this approach and an illustration
of its use at the example of PPNO (or its newer instantiation "PRNO").
Andreas Arnez [Tue, 16 Apr 2024 15:24:47 +0000 (17:24 +0200)]
s390x: Re-implement `vpdi' without intermediate updates
The vpdi instruction is implemented incorrectly for the case where the
result vector coincides with one of the input operands, because it
performs an intermediate update. An example where this produces wrong
results is for
vpdi %v3,%v3,%v3,4
where the instruction is used to swap the two halves of %v3.
Fix this by avoiding the intermediate update and using Iop_64HLtoV128
instead.
ensure error output of vgdb relay mode is shown to the GDB user
With GDB14.1, when there is more than one valgrind process, 'target remote | vgdb' shows:
(gdb) tar rem | vgdb
Remote debugging using | vgdb
no --pid= arg given and multiple valgrind pids found:
use --pid=913621 for ./Inst/bin/valgrind --vgdb-stop-at=startup ./gdbserver_tests/sleepers
use --pid=913622 for ./Inst/bin/valgrind --vgdb-stop-at=startup ./gdbserver_tests/sleepers
Remote communication error. Target disconnected: Connection reset by peer.
(gdb)
With GDB 15.0.50.20240414-git, we obtain:
(gdb) tar rem | vgdb
Remote debugging using | vgdb
Remote communication error. Target disconnected: error while reading: Connection reset by peer.
(gdb)
This looks like a race condition:
When vgdb exits due to several pid or due to any other error (e.g. an argument
error), GDB gets a SIGPIPE and closes the pipe to/from vgdb. To avoid losing
the error messages In such cases, have vgdb wait for the first packet from GDB
before exiting.
With this change, the early errors of vgdb are shown to the user.
Tested on debian, with GDB 12, 13, 15 and 15.0.50.20240414-git.
Paul Floyd [Sun, 14 Apr 2024 13:32:41 +0000 (15:32 +0200)]
FreeBSD regtest: fix for scalar sigaltstack
I was lazy and using pointers to the same struct for the new and old
data (which isn't allowed, the new is 'restrict'). The current gets
copied to the old first so under Valgrind it worked. In the kernel
there are separate structs (which get copied in and copied out) and
it doesn't work.
Maybe we should consider changing VG_(do_sys_sigaltstack) to have at
least one local copy in order to behave like the kernel.
Allow to see more details about suppressed errors.
Extend --show-error-list=no|yes with all to allow to look also the
list of suppressed errors and see which supp entry is suppressing it.
Add an option also_suppressed in the monitor command 'c.vinfo all_errors'
to similarly be able to show the suppressed errors.
Small fix in check_makefile_consistency: avoid it considers emacs ~ files.
Mark Wielaard [Sat, 13 Apr 2024 12:33:19 +0000 (14:33 +0200)]
amd64: Implement VFMADD213 for Iop_MAddF32 and Iop_MAddF64
Speed up F32 and F64 FMA on amd64. Add priv/host_amd64_maddf.c
implementing h_amd64_calc_MAddF32_fma4 and h_amd64_calc_MAddF64_fma4
to be used instead of the generic variants h_generic_calc_MAddF32
and h_generic_calc_MAddF64 when host has VEX_HWCAPS_AMD64_FMA4.
Add fma3 and fma4 detection m_machine.c (machine_get_hwcaps).
This patch also fixes the memcheck/tests/vcpu_fnfns and
none/tests/amd64/fma testcases when run on a x86-64-v3 system.
Patch contributed by Grazvydas Ignotas <notasas@gmail.com> and
Bruno Lathuilière <bruno.lathuiliere@edf.fr>
Paul Floyd [Fri, 12 Apr 2024 18:14:18 +0000 (20:14 +0200)]
regtest arm64: fixes for arm64 clang, part 2
More clang moans about using int where long long is expected
Also clang assembler refuses to accept opcodes like sub x21,x22,x23,sxtb
According to the arm manual it is right and it should be
sub x21,x22,w23,sxtb.
I asked on the LLVM discourse and they said they preferred to be strict
and unambiguous.
Paul Floyd [Fri, 12 Apr 2024 17:59:35 +0000 (19:59 +0200)]
regtest arm64: fixes for arm64 clang, part 1
clang warns about using integers where long longs are expected.
Secondly a few of the tests read the executable text. clang uses
different registers than GCC which causes a diff. Hence another
expected. The tests are potentially flaky so if we see instability
we need to modify the test.
Mark Wielaard [Thu, 11 Apr 2024 17:48:22 +0000 (19:48 +0200)]
Add __set_vma_name suppression to drd/tests/std_thread2.supp
glibc uses a atomic var to set whether the kernel supports
PR_SET_VMA_ANON_NAME. This looks like a conflicting access to drd.
Suppress it for this testcase.
Paul Floyd [Fri, 29 Mar 2024 06:33:29 +0000 (07:33 +0100)]
regtest: rename none/tests/arm64/memory
This directory now contains a C++ test. 'memory' is also the name
of a C++ header. The include paths include ".". All that means that
if 'memory' builds before 'bug484426' then bug484426.cpp will try to
include the binary executable file 'memory' from the same directory
and not the header somewhere under /usr/include.