Merge commit a558d6560437 from llvm-project (by A. Jiang):
[CodeGen] Get rid of incorrect `std` template specializations (#160804)
This patch renames comparators
- from `std::equal_to<llvm::rdf::RegisterRef>` to
`llvm::rdf::RegisterRefEqualTo`, and
- from `std::less<llvm::rdf::RegisterRef>` to
`llvm::rdf::RegisterRefLess`.
The original specializations don't satisfy the requirements for the
original `std` templates by being stateful and
non-default-constructible, so they make the program have UB due to C++17
[namespace.std]/2, C++20/23 [namespace.std]/5.
> A program may explicitly instantiate a class template defined in the
standard library only if the declaration
> - depends on the name of at least one program-defined type, and
> - the instantiation meets the standard library requirements for the
[7 lines not shown]
brt: forget the vdev array when freeing it
brt_vdevs_free() frees spa_brt_vdevs but leaves it and spa_brt_nvdevs
set. When spa_load() fails after brt_load() -- for example in
spa_load_verify() -- the pool is unloaded and the load is retried on
the same spa_t. If the pool has deduplicated blocks, ddt_load() reset
the dedup space estimate, so the retry's vdev_load() recomputes the
pool's space through spa_get_slop_space() -> spa_update_dspace() ->
brt_get_dspace() before brt_load() runs again. brt_get_dspace() then
walks the freed array and the freed brt_vdev_t structures, and the
import oopses.
Clear both fields after freeing the array, as brt_alloc() does.
The test checks the retry itself by counting the dbgmsg lines of the
failed verifications and the retries (suggested by @tigerblue77 in
review), and that the rewind target lies between the checkpointed
state and the last txg before the damage. It then checks the file
contents, the block cloning and dedup accounting and the checkpoint.
[5 lines not shown]
[AMDGPU] Fix LDS externalization for object linking (#243337)
With object linking, the backend converts LDS variables and named
barriers to external declarations, and the linker allocates them. There
are two cases that could potentially make invalid IR or cause a crash:
- LDS or a named barrier with vague linkage, for example a shared
variable in an inline function, is in a comdat. The external declaration
kept the comdat, and the verifier rejected the module: "Declaration may
not be in a Comdat!".
- Alloca promotion to LDS runs after LDS lowering. The LDS variable that
it created stayed an internal definition, and the asm printer asserted:
"LDS definitions should have been externalized when object linking is
enabled".
This PR fixes both of them.
This PR was assisted by AI but I reviewed all the changes.
PowerPC: Use LastSubtargetCache in getSubtargetImpl (#248926)
Migrate to use the new common infrastructure and pattern which caches
based on the last used subtarget.
Assisted-by: Claude
libcrypto: avoid buffer overwrite due to truncating long to int
The cached DER encoding has a length stored as a long but the i2d API
uses an int. Since i2d has this two-step Muppet API where the first
call reports back an int to allow the caller to allocate a buffer and
then have i2d write to it, this can go wrong when LONG_MAX > INT_MAX:
the caller allocates the truncated int size reported back and passes
that in and the API then writes out the long-sized buffer containing
the cached DER, writing past the end.
This requires lots of memory to be an actual issue.
Fix adapted from OpenSSL 8257d58a by Cygnus Qu with a few tweaks by me.
ok jsing kenjiro
AMDGPU: Add gfx7 disassembler tests
Generated from the encodings in the gfx7_asm_*.s assembler tests.
s_cbranch_join with src_vccz, src_execz or src_scc is left
out. Despite assembling, these are already broken on gfx8+ and don't
decode.
Assisted-by: Claude
bootpd: preserve request flags in reply
RFC 1542 §5.4: "the server MUST preserve the state of the BROADCAST flag
so that the relay agent can correctly act upon it."
Reported by: llm-postcr
Fixes: 7d8b5bd3f15ba99343e2d93c53ac73cc4bc550f0
AMDGPU: Do not decode inv-2pi inline constant on gfx6/gfx7
The disassembler assumed the inline constant was always available. On
SI/CI the encoding is reserved and decoding it printed a literal which
does not encode back to the same bytes. A literal with that value was
also printed with lit().
Assisted-by: Claude
AMDGPU: Decode gfx/gfx7 special register encodings
flat_scratch and xnack_mask do not exist on gfx6. gfx6 and gfx7 have
s102 and s103 where VI has flat_scratch. gfx7 encodes flat_scratch
where gfx8 has xnack_mask.
Assisted-by: Claude
AMDGPU: Support disassembling gfx6 and gfx7 (#249031)
This is necessary to allow dropping mesa's use of the DumpCode
feature. The decoder tables for the SI/CI encodings were already
generated, but the disassembler gave up on these targets. Remove the
artificial check and try to decode.
The gfx6/gfx7 encoding of the VOP3 instructions with a carry-out has
no clamp bit but the instructions still have a clamp operand. Declare
it as a zero width field so the decoder adds the operand.
Special registers that are encoded differently from gfx8 are not
handled yet.
Assisted-by: Claude
bootpd: better handle getifaddrs() results
Pick up the first matching address, not the last. Check if getifaddrs()
failed.
Reported by: llm-postcr
Fixes: 7d8b5bd3f15ba99343e2d93c53ac73cc4bc550f0
bootpgw: improve multihoming
This BOOTP relay daemon is mostly a paste of bootpd. Removal of getif.c
in 7d8b5bd3f15b broke its build. Apply same logic to this daemon,
speculatively improving it. Not tested.
Fixes: 7d8b5bd3f15ba99343e2d93c53ac73cc4bc550f0
ZTS: zeroing part of an unfilled readahead page leaves no stale bytes
On Linux before 6.14, read_pages() leaves the pages that ->readahead()
did not take in the page cache, unlocked and not up to date.
zfs_zero_partial_page() zeroes part of a cached page when a write
extends the file past its last page, and when a hole is punched inside
a page. If it then marks such a page up to date, read(2) and mmap
return the rest of the page, which was never read.
Add a test for it. With 128K records, a file of 8292 bytes is a single
block of 8704 bytes. The pool is exported and imported to drop the
file's pages, the first page is touched through a MADV_RANDOM mapping,
so that zpl_fadvise() goes on to generic_fadvise(), and
posix_fadvise(WILLNEED) is called over the whole file. Without
MADV_RANDOM, a nonzero readahead window makes the fault read around the
page and set the async part of the window, and read_pages() then removes
the pages ->readahead() did not take instead of keeping them. A
one-byte write at 20000, or a hole punched at [8200, 8250), then zeroes
part of the last page. The test fails if pread() of that page, or of
[17 lines not shown]
ZTS: fadvise(WILLNEED) readahead keeps up with writes to a mapped file
Four writers rewrite a file while four readers drop a span of it from
the page cache, fault one page of the span back in through a MADV_RANDOM
mapping, so that zpl_fadvise() goes on to generic_fadvise(), and ask for
the span with fadvise(WILLNEED). A readahead that waits for a writer's
range lock with the rest of its batch locked, while that writer waits in
update_pages() for a page of the batch, hangs both, and the pool stops
syncing behind them (#19447).
The test fails when neither side has moved for ten seconds, or when the
helper is still running a minute after it should have finished. On a
module that hangs here the pool stays hung after the test has failed.
Reviewed-by: Tigerblue77 <37409593+tigerblue77 at users.noreply.github.com>
Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: ElXreno <elxreno at gmail.com>
Closes #19447
Closes #19651
ZTS: sub-page write racing fadvise(WILLNEED) leaves no stale bytes
When readahead gives up on a page because a writer holds its range
lock, the page stays in the page cache, unlocked and not up to date.
If update_pages() then copies in only the bytes the write covered and
marks the page up to date, the rest of the page is stale for mmap and
read(2).
Add a test for it. The file's data is kept out of the ARC and reads
are delayed with zinject, so a 512-byte write inside the first page of
a record holds the range lock while it waits for that record.
posix_fadvise(WILLNEED) over the record and a cached page beyond it
then reaches the written page while the writer holds the lock. Once
the delay is cleared, the page is compared, through a shared mapping
and through pread(), with a copy of the file kept outside the pool,
and the test fails on any difference. Freed pages of a file of 0xA5
bytes make stale bytes non-zero where new pages are not zeroed, and
zeroes differ from the random file data too.
[12 lines not shown]
Linux: fill a readahead batch from one hold of its dbufs
zpl_readahead() filled a batch one page at a time through zfs_getpage(),
so every 4K page entered the filesystem, took and dropped the range
lock, held and released the dbufs behind it and told the prefetcher
about a one page read. With recordsize=128K that is 32 rounds of all of
it per block, and the readers of one file queue on the mutex of its
range lock.
It could also hang the pool. The kernel hands ->readahead() the whole
batch locked, and zfs_getpage() unlocks only its own page before it
waits for the range lock. zfs_write() holds the range lock while
update_pages() locks the pages of the range it wrote, so a writer
waiting for a page further down the batch and a readahead waiting for
the writer's range never move again (#19447). posix_fadvise(WILLNEED)
reaches it with the readahead window at zero, through bdi->io_pages.
Fill the batch in zfs_getpages() instead: enter the filesystem once, try
the range lock over the whole batch, hold the dbufs behind it with
[18 lines not shown]
[MustExecute] Define the block context helpers out of line
They use BasicBlock, which MustExecute.h only declares, so the header
did not compile without precompiled headers.
Co-Authored-By: Claude Opus 5.5 <noreply at anthropic.com>
[MustExecute] Fix the memory regression of block number contexts
The previous commit gave every block context a bit vector with a bit for
every block of the function, which takes memory quadratic in the number
of blocks: +110 MB for a switch with 30000 cases. Use a set until the
bit vector is not larger than the list of blocks of the context.
Also assert that the block numbers are not outdated, as DominatorTree
does, and drop the unused SetVector include.
Co-Authored-By: Claude Opus 5.5 <noreply at anthropic.com>
MustExecute: Look up the blocks of contexts by their number
isInContextOf looked up the block of every queried instruction in a hash
map of the forward context and a hash set of the backward context, which
was a few percent of the full Attributor on large functions. The blocks of
a context are all included except for a prefix of the last block of a
forward context, so keep a bit vector indexed by block number instead,
and the end of the last block. NFC.
CTMark instructions:u with -attributor-enable=full:
O3: -0.74% (sqlite3 -2.22%)
ThinLTO: -1.27% (tramp3d-v4 -4.62%, sqlite3 -2.73%)
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
Linux: leave unfilled pages to their filler in update_pages()
update_pages() copies only the bytes a write covered into each cached
page and then marks the page up to date. For a page that was never
filled, the rest of the page is whatever the allocator left there, and
it becomes visible to mmap and to mappedread().
Such pages exist. zfs_getpage() unlocks its page while it waits for
the range lock, so a writer holding that lock can reach the page before
it is filled, and other readers can see it after the writer is done and
before zfs_getpage() relocks it. Readahead that stops early also
leaves its unconsumed pages cached and not up to date on kernels before
6.14, whose read_pages() removes only the async part of the window.
Skip a page that is neither up to date nor dirty. Every filler
(zfs_getpage(), mappedread(), readahead) takes the range lock, which
our callers hold as writer, so the filler reads this write from the
DMU once it is done. This is also needed before readahead may stop
early on range lock contention.
[12 lines not shown]