Repository navigation
Softmmu/TLB upgrade from QEMU 1.0 to 11.1.0 - #120
Merged
Merged
Conversation
Merge the three separate cmake projects into a single libutils project that builds one static library, libutils.a. The public headers are merged into a single include root, so they keep their original include prefixes (coroutine.h, fsigc++/fsigc++.h, qapi/, qerror.h, qqueue.h) and no source file needed to change. Update the build system accordingly: libs2e/configure takes a single --with-libutils flag in place of --with-fsigc++, --with-libq and --with-libcoroutine, and all consumers use find_package(LIBUTILS). Note that libq and libcoroutine are now built without NDEBUG, which was already the case for libfsigc++ and for the rest of the codebase. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
libtcg is a de-QEMU-ified fork of TCG that has been reformatted with the S2E clang-format style, so upstream patches never apply directly: every line differs because of reformatting alone. Normalizing the upstream file first, by running it through clang-format with the S2E style, reduces the difference against its libtcg counterpart to the genuine S2E delta. For src/tcg.c that is the difference between a 6800-line diff and a 79-line one, which makes the upgrade an ordinary three-way merge. Signed-off-by: Vitaly Chipounov <vitaly@chipounov.fr> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Merged the TCG core from qemu v10.2.0 to v11.1.0 using the normalize and three-way merge workflow from scripts/upgrade. The S2E patches are preserved: the per-context qemu_ld_helpers and qemu_st_helpers tables, the CONFIG_SYMBEX_MP se_addend TLB hit path, and tcg_target_force_tb_exit. The dominant upstream change is the removal of 32-bit host support, hence the i386 to x86_64 rename, the now target-independent target-reg-bits.h with TCG_TARGET_REG_BITS unconditionally 64, and the folding of the i386 cpuinfo header into x86_64. Memory operations moved out of tcg-op.h into the new tcg-op-mem.h; the S2E tcg_gen_qemu_ld8u style wrappers stay behind in tcg-op.h. The four sadd/ssub saturate helpers are pulled into host-utils.h because the new tcg-runtime-gvec.c needs them. Two latent bugs are fixed along the way: - tcg-gvec-desc.h was missed by the upgrade to 10.2 and still had the old descriptor encoding, while simd_desc() in tcg-op-gvec.c already wrote the new one. In particular simd_desc() encodes oprsz as 2 to mean "matches maxsz", which the stale simd_oprsz() decoded as 24. - The atomic helpers in atomic_common.c.inc declared their address argument as target_ulong while the DEF_HELPER prototypes say i64. Harmless on x86_64, wrong for the i386 guest. Also removed tcg-pool.c.inc, tcg-ldst.c.inc and tcg-target.opc.h, which were unreferenced leftovers from earlier upgrades. fpu/softfloat and most of utils/ remain at qemu v8.1.0 and are not part of this upgrade. Upgrading softfloat changes float semantics that KLEE interprets symbolically via softfloat.bc, so it wants to be a separate change. Signed-off-by: Vitaly Chipounov <vitaly@chipounov.fr> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
qemu 11.1 removed TARGET_INSN_START_EXTRA_WORDS and gave tcg_gen_insn_start a single fixed form taking INSN_START_WORDS arguments, with callers padding out the unused slots. i386 only uses one extra word, so pass a trailing zero. Signed-off-by: Vitaly Chipounov <vitaly@chipounov.fr> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
softfloat had been left at qemu v8.1.0 by the previous upgrades. The S2E delta on it turned out to be tiny, so the three-way merge from v8.1.0 was nearly clean: softfloat-parts.c.inc and softfloat-specialize.c.inc are now byte for byte upstream, and the rest differs only in include paths and the C++ linkage guards. Two structural changes were needed to fit it into libtcg: softfloat-types.h now needs FIELD() for the 3-NaN propagation rules, which lives in registerfields.h, which includes bitops.h. That creates a cycle, because bswap.h used to define the float and integer reinterpretation unions and therefore included softfloat-types.h. Upstream keeps those unions in include/qemu/cpu-float.h instead, so split them out the same way and drop the bswap.h dependency from host-utils.h, as qemu 11.1 did. float_status.float_rounding_mode is kept as a plain field rather than the bitfield upstream uses. S2E addresses the CPU state by (offset, size) so that helpers running as bitcode inside KLEE can read it back through g_sqi.regs.read_concrete(), and the RR_cpu()/WR_cpu() accessors in ops_sse.h need offsetof() and sizeof() on this field. Neither works on a bitfield, and dropping the accessors would silently read the native copy of the CPU state instead of KLEE's. FloatRoundMode is packed, so this costs one byte. Note that this changes guest visible floating point behaviour: v8.1.0 predates the canonicalization of input denormals, the explicit default NaN pattern, and the configurable flush to zero detection point. softfloat.c is compiled to softfloat.bc and interpreted by KLEE, so symbolic paths see the new semantics too. Signed-off-by: Vitaly Chipounov <vitaly@chipounov.fr> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Since qemu 11.1 softfloat asserts when it has to choose between two or three input NaNs and no propagation rule was selected, and when it has to produce a default NaN and no bit pattern was set. cpu_state_reset() memsets the CPU state, which leaves every rule at zero, so these have to be reapplied on every reset. Without this the build is clean but the first operation on two NaNs aborts. Mirrors cpu_init_fp_statuses() in qemu's target/i386/tcg/fpu_helper.c. Also include the new tcg/utils/cpu-float.h, which now holds the float and integer reinterpretation unions that used to live in bswap.h. Signed-off-by: Vitaly Chipounov <vitaly@chipounov.fr> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Captures the workflow used for the qemu 10.2 to 11.1 upgrade: normalize the upstream formatting before comparing, then three-way merge. Records the S2E deviations that have to survive future merges, the libcpu fallout that libtcg's own build does not catch, and the changes that are guest visible rather than merely mechanical. The most important part is the warning not to replace RR_cpu()/WR_cpu() with direct struct access when upstream makes a field unaddressable: that silences the compiler but silently reads the native CPU state instead of KLEE's on symbolic paths. Signed-off-by: Vitaly Chipounov <vitaly@chipounov.fr> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The utility subset had been left behind by the earlier upgrades. Checking each file's baseline individually rather than assuming one showed a spread: most of utils/ was at v8.1.0, elf.h at v8.0.0, and the host support headers somewhere between v9.1.0 and v11.0.0. Merged each group from its own baseline. atomic128-cas.h was the interesting one: it had been stranded before v10.2.0 and so was missing atomic16_xchg entirely. That is a host support file which should have moved with the TCG core, and it was missed. elf.h is now byte for byte upstream. The rest differ only by include rewiring, the C++ linkage guards, and three deviations now recorded in scripts/upgrade/README.md and the skill: the new -> _new parameter rename in atomic128-cas.h (new is a C++ keyword and these headers are included from C++), the #ifndef BIT guard in bitops.h (libcpu/include/cpu/kvm.h also defines BIT), and osdep.h carrying what upstream keeps in include/qemu/compiler.h, which now needs typeof_strip_qual for the 11.1 qatomic macros. Dropping bswap.h from int128.h, which 11.1 no longer needs, exposed two files that had been relying on it transitively: int128.h itself for inttypes.h, and optimize.c for bswap16/32/64. Both now include what they use. The files not mentioned here were simply never touched upstream since their baseline, so they are current by definition. The hand written subsets (osdep.h, cutils.*, log.*, bitmap.h, bswap.h) stay at v8.1.0 era deliberately: they are reduced S2E-specific rewrites rather than vendored copies, and a mechanical merge would be wrong. Signed-off-by: Vitaly Chipounov <vitaly@chipounov.fr> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Adds the three deviations found while upgrading utils, and corrects the claim that most of utils/ lags the TCG core: it no longer does. What still lags is the set of hand written subsets flagged in mapping.tsv. Signed-off-by: Vitaly Chipounov <vitaly@chipounov.fr> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
utils/memalign.h is a three declaration stub, not a reduced copy of upstream's header, which is why its diff against upstream never moved across any release. Group it with the other hand written subsets so the mapping does not imply it tracks BASELINE. Signed-off-by: Vitaly Chipounov <vitaly@chipounov.fr> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
llvm::raw_string_ostream::str() is on its way out upstream ("In most
cases it is better to simply use the underlying std::string directly.
TODO: Consider removing this API."). Flush the stream and use the
backing std::string instead, matching the idiom already used elsewhere
in the tree.
In KModule::evalConstantExpr the raw_string_ostream wrappers were only
ever used to fetch the message back out, so they are dropped entirely.
Also stop building asio buffers from `ss.str().c_str()` with a second
`ss.str().length()` call: that materialized two temporary strings per
write. Take the string once and let asio::buffer deduce the length.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Upgrading softfloat to qemu 11.1 brought in the parts128/float128 code.
Its helpers take noalias qualified pointers, so clang emits
llvm.experimental.noalias.scope.decl at every inlining site, and the
op_helper bitcode now carries fourteen of them. The engine died before
executing a single instruction:
KLEE: ERROR: Cannot handle constant !58 = !{!59} of type metadata at
tail call void @llvm.experimental.noalias.scope.decl(metadata !58)
The hint is a pure aliasing annotation with no run time semantics, but
IntrinsicCleaner did not know it and only warned, so the call survived
into the constant table. Erase it instead, which is what its lack of
semantics allows.
That the metadata reached evalConstant() at all is a second defect.
KFunction had two copies of the operand classification: getOperandNum()
for calls and an inline one for everything else. Only the inline copy
tried to reject metadata, and its isa<MDNode>(ValueAsMetadata::get(v))
test can never be true, since ValueAsMetadata::get() returns a
ValueAsMetadata and never an MDNode. Metadata arguments therefore fell
through to assert(isa<Constant>(v)), which in a release build degrades
into the error above. Test for MetadataAsValue in getOperandNum() and
route the non-call operands through it, so the two paths cannot drift
apart again.
Two unit tests cover this. NoAliasScopeDeclDoesNotBreakThePreparePasses
runs a function built from a fixture that clang compiles with the hints
in place, and MetadataOperandsAreNotInterned pins the classification
using llvm.type.test, an intrinsic the cleaner deliberately leaves
alone. Both abort without the fix.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
softfloat only falls back to its own arithmetic when the host cannot do the job, and the fast paths it takes instead compile down to intrinsics that the engine did not know. float64_add() and float64_sub() classify their operands with __builtin_isnormal(), which clang 19 lowers to llvm.is.fpclass, and float32_muladd()/float64_muladd() call fma(). helper_fprem1() has been using llvm.rint and llvm.fmuladd for longer. IntrinsicCleaner only warned about all of these, and an unhandled intrinsic reaching executeCall() is a klee_error, so the first guest double addition executed as bitcode would have taken the engine down. llvm.is.fpclass is expanded into integer tests on the raw encoding of its operand: exponent and mantissa are compared against the constants that delimit each class, and the requested classes are or-ed together. Testing the encoding rather than concretizing keeps the predicate symbolic when the operand is, which matters because these tests guard which arithmetic path softfloat takes. x86_fp80 is left out, it stores the leading significand bit explicitly and the tests do not apply. llvm.fmuladd is expanded into a multiply and an add. Contraction is optional for it, so the unfused form is a valid lowering and it also keeps its operands symbolic. llvm.fma has to round once and cannot be expressed that way, so it is evaluated in the Executor with APFloat::fusedMultiplyAdd() on concretized operands, as llvm.fabs already is. llvm.rint and llvm.nearbyint round the same way, through roundToIntegral(). The guest rounding mode is emulated by softfloat itself, so the host one stays at its default of round to nearest, ties to even. The tests run one function per intrinsic out of a fixture that must be compiled at -O0, since at -O1 and above clang folds most of the class predicates into comparisons and the intrinsics disappear. The class predicates are checked against every class and both signs so that a wrong bit shows up as a mismatch rather than cancelling out, and the fused and unfused multiply-adds are separated by an input whose exact result, 2^-104, only survives a single rounding. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Vitaly Chipounov <vitaly@chipounov.fr>
Signed-off-by: Vitaly Chipounov <vitaly@chipounov.fr>
libtcg is configured per target: the build produces six trees per build
type ({i386,x86_64} x {plain, s2e, s2e_sp}), and each rebuilds libtcg
from scratch. libutils is configured once per build type, so keeping
target-independent code in libtcg compiled every one of these objects
six times. libtcg already declared find_package(LIBUTILS REQUIRED) and
libs2e already linked libutils.a after libtcg.a, so no new dependency
edge was needed.
Moved 25 headers to libutils/include/utils/ and 8 sources to
libutils/src/utils/. The include prefix becomes <utils/...>, matching
libutils' existing flat <qqueue.h> / <coroutine.h> shape; 77 include
lines across 46 files in libtcg, libcpu and libs2e follow.
Three files stayed behind. log.c tests TARGET_I386 and CONFIG_SYMBEX to
build its CPU_LOG_* mask table. bswap.h tests TARGET_WORDS_BIGENDIAN and
TARGET_LONG_SIZE in live code and is mapped to upstream
include/qemu/bswap.h, so it cannot be edited to drop the dependency
without creating a merge deviation. cpu-float.h needs libtcg's
fpu/softfloat-types.h.
libutils now defines CONFIG_INT128, HOST_BIG_ENDIAN=0 and
HAVE_GLIB_WITH_SLICE_ALLOCATOR, which int128.h, host-utils.h and qtree.h
read. Consumers of those headers have to define them identically or the
struct layouts disagree across translation units.
The upgrade tooling follows the files: libutils gets its own
scripts/upgrade/{BASELINE,mapping.tsv,merge.sh,normalize.sh} and the 28
corresponding rows move out of libtcg's mapping. merge.sh v11.1.0
v11.1.0 reports zero conflicts on both components.
Signed-off-by: Vitaly Chipounov <vitaly@chipounov.fr>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
CONFIG_INT128, HOST_BIG_ENDIAN and HAVE_GLIB_WITH_SLICE_ALLOCATOR were defined three times on the command line: in libutils, in libtcg and (for CONFIG_INT128) in libcpu's generated config-target.h. The bitcode rule for softfloat.c got none of them, because it passes CARGS_LIST, which libtcg never sets, so softfloat.bc declared mulu64() extern and carried an unresolvable reference that op_helper.bc inherited. utils/config-host.h now derives CONFIG_INT128 and HOST_BIG_ENDIAN from compiler builtins and fixes HAVE_GLIB_WITH_SLICE_ALLOCATOR, and int128.h and osdep.h include it, so every translation unit that uses a utils header sees the same values regardless of how it is compiled. The command-line copies are gone. CONFIG_CPUID_H stays undefined on purpose: the TCG backend would start advertising andc, ctz, clz, ctpop and vector ops that tcg-llvm.cpp does not translate. cpuinfo-i386.c and host/x86_64/atomic128-ldst.h still pointed at upstream include paths that exist nowhere in the tree; they now use <utils/...>. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Vitaly Chipounov <vitaly@chipounov.fr>
stamps/libs2e-*-configure and stamps/tools-*-configure depended on stamps/libutils-*-make, and libs2e/configure removes every per-target tree before running cmake. Since the utilities moved into libutils, touching any of them wiped and rebuilt all six libs2e targets per build type. The configure stamps now depend on libutils' configure stamp only, and the make stamps depend on its make stamp, so a libutils change relinks incrementally. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Vitaly Chipounov <vitaly@chipounov.fr>
libtcg and libutils carried byte-identical copies of merge.sh and normalize.sh. Both now live in scripts/upgrade/ at the source root; merge.sh takes the component name and reads <component>/scripts/upgrade/mapping.tsv, whose new "# upstream-dirs:" header names the upstream directories to scan for added files. The components keep only BASELINE and mapping.tsv. merge.sh also computes the rename table once with the rename limit lifted (-l0), which used to skip inexact renames over a large range and report atomic128-ldst.h as absent at v8.1.0; reports pure renames, since their mapping row still has to change; reports a mapping row whose S2E file is missing instead of aborting; lists files written with conflict markers under --apply; and drops foreign-architecture host headers from the added-upstream list. The README, the upgrade skill and PORTING.md follow: both components are merged on every tag bump, libutils first, and the hand-written and S2E-original file lists now match mapping.tsv. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Vitaly Chipounov <vitaly@chipounov.fr>
….1.0
The rows below the "hand written" marker in mapping.tsv (memalign.h,
bitmap.h, cutils.{h,c}, osdep.{h,c}) were v8.1.0-era subsets that had to
be merged by hand on every upgrade, and cache.{h,c} and rounding.h were
S2E-original stand-ins for upstream code. They are now upstream files:
- compiler.h, memalign.h, ctype.h, madvise.h, mprotect.h, cacheflush.{h,c},
cacheinfo.h and hexdump.c are vendored verbatim, with the <utils/...>
include paths, extern "C" guards and the includes each header needs to
stand alone, since S2E has no qemu/osdep.h prelude.
- cutils.h, osdep.h, cutils.c, osdep.c and oslib-posix.c are pruned copies:
upstream text with the sections that need meson configuration, os-posix.h,
the Error API, error_report() or sockets deleted. cutils.h drops the
prototypes (qemu_init_exec_dir, get_relocated_path, parse_debug_env) whose
bodies cutils.c prunes, so every declaration it keeps has a definition.
The kept sections are verbatim, so merge.sh handles them like any other
row.
- cache.{h,c} is replaced by cacheflush.c (qemu_icache_linesize and
friends, initialized from a constructor), rounding.h by the QEMU_ALIGN_*
and ROUND_* macros in osdep.h, and bitmap.h is dropped: nothing used it
and upstream bitmap.c needs bswap.h, which libtcg still owns.
- src/q/cutils.{c,h}, a renamed copy of the same upstream file, is gone;
the QAPI code calls qemu_strto*() directly.
config-host.h gains CONFIG_MADVISE and CONFIG_POSIX_MEMALIGN and loses
HOST_BIG_ENDIAN, which compiler.h defines as upstream does. The remaining
deviations are small and documented in scripts/upgrade/README.md: compiler.h
spells typeof as __typeof__ for C++, cutils.h spells restrict as __restrict
and casts the buffer_is_zero() argument so it compiles as C++ behind its
extern "C" guard, osdep.h keeps the plain MIN/MAX/ARRAY_SIZE for C++ and
drops the #error on NDEBUG (libtcg and libcpu build with it in release), and
osdep.c reports mprotect failures with fprintf.
The consumers follow upstream naming: region.c uses qemu_dcache_linesize,
QEMU_MADV_HUGEPAGE and QEMU_ALIGN_DOWN; tcg.c uses qemu_icache_linesize and
<utils/cacheflush.h>; tcg.h uses QEMU_ALIGN_UP; translate-all.c no longer
calls init_cache_info(); exec-ram.c uses qemu_strtosz_MiB() and rejects
sizes above INT64_MAX, which its int64_t return would otherwise turn into
the default. libcpu's libcpu-compiler.h had the same COMPILER_H guard as
upstream compiler.h and types.h redefined HOST_LONG_BITS; libs2e.cpp
includes <dirent.h> before it undefines __REDIRECT_NTH, since osdep.h now
pulls in glib; coroutine.h and coroutine-ucontext.c drop their private
coroutine_fn and container_of.
mutex.h and spinlock.h stay S2E-original: qemu/thread.h drags in qsp,
notify, the generated trace.h and main-loop.h, far more than the two
wrappers replace.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Vitaly Chipounov <vitaly@chipounov.fr>
libtcg's utils/bswap.h was the last v8.1.0-era hand-written subset besides
log.{h,c}. It was target-dependent only through its tswap*() tail, and it
still tested HOST_WORDS_BIGENDIAN, which nothing defines. Upstream's
include/qemu/bswap.h is host-only until its final section, which needs
exec/memop.h (ldm_p/stm_p) and target-info.h (ld*_p/st*_p following target
endianness). The file is now split along that line:
- libutils' utils/bswap.h is the host half, verbatim minus the two includes
and the tail.
- libtcg's utils/bswap.h is the MemOp and target-endian half, on top of
tcg-memop.h, utils/target-info.h and utils/bswap.h.
- libtcg's utils/target-info.h is upstream's declarations plus one S2E
block: under COMPILING_PER_TARGET, target_big_endian() is
TARGET_BIG_ENDIAN, since S2E has no runtime TargetInfo and ldl_p() and
friends sit on libcpu's softmmu paths. The block errors out if the macro
is missing, since it expands inside inline functions and would otherwise
fail one include order at a time. TARGET_BIG_ENDIAN is defined (0) where
upstream's meson would define it: libcpu's generated config-target.h and
libtcg's CMake flags.
- libtcg's exec/tswap.h is upstream's without the CPUState-based
cpu_internal_tswap*(); it replaces the old tswap tail.
cpu-all.h drops its lduw_p..stq_p macros, now inline functions from the
libtcg half, and keeps only the float ldfl_p/stfq_p mapping, keyed on
TARGET_BIG_ENDIAN. exec.c includes <tcg/exec/tswap.h> for its one tswap64()
and optimize.c includes <utils/bswap.h>.
With bswap.h in libutils, bitmap.{h,c} and bufferiszero.c with its x86_64
bufferiszero.c.inc are vendored too, so every declaration in cutils.h has a
definition. CONFIG_AVX2_OPT joins config-host.h behind CONFIG_CPUID_H, the
dependency upstream's meson enforces; with CONFIG_CPUID_H left undefined,
cpuinfo never reports SSE2/AVX2 and buffer_is_zero() takes the integer path.
Both halves map to the same upstream file, so each component's merge
reports the other half's changes as a conflict in a deleted section, which
is resolved by deleting it again; README and the upgrade skill say so.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Vitaly Chipounov <vitaly@chipounov.fr>
….1.0
These are the concurrency utilities section 4.2 of PORTING.md lists as
missing for the accel/tcg import: the TB hash table, its RCU machinery,
and the thread primitives underneath. The import closure adds futex.h,
processor.h, lockable.h, notify.{h,c}, sys_membarrier.h, coroutine-tls.h,
event.c (QemuEvent, split out of qemu-thread-posix.c upstream) and
qemu-thread-common.h. processor.h, xxhash.h, coroutine-tls.h,
thread-posix.h, seqlock.h and event.c are verbatim with the <utils/...>
includes and extern "C" guards; the rest are pruned copies:
- thread.h drops win32 and the QSP profiler indirection. Its lock macros
call the _impl functions directly and the __raw variants are aliases,
so qht.c's QHT_MODE_RAW_MUTEXES path stays upstream text. It also
declares the QemuMutex and QemuSpin typedefs that upstream keeps in
qemu/typedefs.h, which is not vendored.
- qht.{h,c} drop qht_statistics, the only user of qdist, which stays out.
- rcu.c drops the BQL around callbacks: the BQL stub belongs to libcpu
and libutils cannot depend on it. It also keeps the pthread_atfork
hooks unconditionally instead of behind CONFIG_POSIX; defining that
macro would activate region.c's split-wx memfd section, which needs
the unvendored qemu/memfd.h.
- lockable.h drops CoMutex, notify.{h,c} drop NotifierWithReturn (Error
API), sys_membarrier.h keeps only the non-CONFIG_MEMBARRIER branch,
qemu-thread-common.h drops tracing and BQL status tracking, and
qemu-thread-posix.c drops the TSAN annotation and trace calls.
config-host.h gains CONFIG_LINUX, which futex.h keys HAVE_FUTEX on, and
CONFIG_PTHREAD_CONDATTR_SETCLOCK. The pthread_*_np name and affinity
configs stay undefined: glibc hides those behind _GNU_SOURCE, and the
fallbacks (unnamed threads, -ENOSYS affinity) cost nothing.
qqueue.h is now the full upstream include/qemu/queue.h rather than the
old v8.1.0-era subset: this brings QLIST_SAFE_REMOVE (notify.c needs it),
QSLIST_REMOVE, the RAW macros and the union-based QTAILQ. The deviations
for C++ follow compiler.h's precedent: typeof is spelled __typeof__ and
QLIST_SWAP's temporary is typed instead of void *. Nothing in the tree
touches the queue fields outside the macros, so the QTAILQ representation
change is invisible.
With the real thread.h in place, the mutex.h stand-in (kept in the last
vendoring round because thread.h then dragged in qsp and trace.h) is
gone: region.c uses QemuMutex and qemu_mutex_*(), matching upstream
region.c, and tcg.c drops its unused include.
merge.sh reports zero conflicts for both components at v11.1.0, and
libutils, its tests and libs2e build in release and debug.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Vitaly Chipounov <vitaly@chipounov.fr>
The new cpu/state.h defines the slim CPUState, CPUNegativeOffsetState and ArchCPU with upstream's layout contract: CPUX86State immediately follows CPUState, so cpu_env() / env_cpu() are pointer arithmetic and generated code reaches the TLB at a negative offset from env (tlb-update.md, step 2). The TLB, the RAM TLB, se_tlb_current and the TB jump cache moved from CPU_COMMON into CPUNegativeOffsetState, keeping the QEMU-1.0 TLB organization; the unused iotlb_ramaddr array is gone. cpu_x86_init() allocates the enclosing ArchCPU, and tlb_fast_offset is now negative. libs2ecore registers the cache region as a third shared-concrete KLEE object so the bitcode softmmu fast path still resolves, snapshots it explicitly in saveConcreteState() / restoreConcreteState() to keep the per-state semantics unchanged, and reaches it through the new getCpuCaches() accessor, which also fixes flushTlbCachePage() and clearRamTlb() bypassing the per-state buffer via the global env. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The audit ran only when S2E_DEBUG_TLBCACHE was defined at compile time and relied on asserts. It is now enabled with --tlb-audit, runs after every TLB update, and reports the mismatching coordinates and object pointers before aborting. The checks are plain conditionals, so they are not compiled out with NDEBUG, and the loops use range-based for instead of foreach2. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
updateTlbEntry() took the global env and updateTlbEntryConcreteStatus() took a CPUState pointer while the other TLB methods went through getCpuCaches(), so one update could index the global TLB and then clear the per-state buffer. Both now fetch the caches through the accessor, and updateTlbEntryConcreteStatus() is private since only the class calls it. The libcpu hook s2e_update_tlb_entry() keeps its env parameter and aborts when it does not name the active state's CPU, which is the only CPU libcpu fills TLB entries for (tlb-update.md, step 1). The plan records that step 4 turns getCpuCaches() into the place that enforces I3. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
addressSpaceSymbolicStatusChange() called updateConcreteFastPath() for whichever state's registers changed concreteness. The fast path flag, generate_llvm and the clock scaling are globals that describe the active state, so a plugin making a suspended state's registers symbolic clobbered them until the next state switch. The call now runs only on the active state; selectSearcherState() recomputes the flags after every switch. The plan records the decision for the unguarded TLB entry points: the per-state address space cache invalidation always runs, and the TLB update becomes a checked no-op on inactive states in step 4, inside updateTlb() and updateRamTlb() (tlb-update.md, step 1). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The TLB, the RAM TLB and the TB jump cache are caches of a mapping that the guest page tables and the KLEE address space determine, so they no longer travel with the state. saveConcreteState() and restoreConcreteState() leave the cache region alone, and doStateSwitch() flushes the TLB, clears the RAM TLB and empties the outgoing state's TLB map once the flush guard is cleared, so every activated state starts with an empty TLB. Only the active state has a TLB now. getCpuCaches() aborts on an inactive state, updateTlb() and updateRamTlb() return early on one after checking that its map is empty, and a forked state no longer inherits the parent's map. The per-state copy of the cache object is gone with the snapshot; the KLEE registration stays so that the bitcode softmmu fast path still resolves (tlb-update.md, step 4). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
MergingSearcher::mergeEnd() flushed the TLB so that the two states' cached entries would compare equal in compareArchitecturalConcreteState(). The caches no longer live in CPUX86State and are not compared, and both states are deactivated before S2EExecutionState::merge() runs, so the survivor gets a fresh TLB from doStateSwitch() when it is activated again. The flush was dead and is gone. The comparison keeps its two-memcmp shape: the window between se_common_start and se_common_end still hides the current TB, jmp_env, the breakpoint and watchpoint lists and the other non-architectural execution fields that CPU_COMMON leaves in the structure. The comments now say what the window hides and how the merged dirty mask reaches the TLB (tlb-update.md, step 6). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
CPUX86State no longer carries CPU_COMMON. The execution fields that upstream keeps in CPUState (exception_index, interrupt_request, halted, exit_request, jmp_env, the breakpoint and watchpoint lists, cpu_index) and the S2E additions that go with them (the current TB, se_current_tb, the softmmu IO context, translate_single_instruction, se_tb_abort, generate_llvm) now sit in the slim CPUState ahead of the caches. The fields that had no reader (temp_buf, restored_instruction_size, next_cpu, numa_node, running, opaque, created, stop) are gone, and the CPU list that next_cpu threaded is a single first_cpu pointer. cpu_state_reset() clears the CPUX86State prefix up to the size field and calls cpu_common_reset() for the CPUState fields a reset discards. libs2ecore registers the new region as its own shared-concrete object, CpuExecutionState, covering [&g_cpu, offsetof(CPUState, neg)), and snapshots it with the concrete registers on every state switch, so the fields do not inherit the never-snapshotted cache region. doStateSwitch() keeps carrying jmp_env across the restore because it belongs to the host call stack doing the switch. The se_common_start / se_common_end window and the two-memcmp comparison in compareArchitecturalConcreteState() are gone: the concrete region holds only architectural state now. Generated code reaches exit_request, se_current_tb and se_tb_abort at a negative offset from tcg_env, so TCGContext::env_offset_se_tb_abort is signed. All other accesses go through env_cpu(env). PORTING.md and tlb-update.md record the TLB ownership work and this move as landed, and phase 4 keeps only the renames onto 11.1 field names. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The header was still at its 8.1.2 content, with the mmu index in the low 4 bits of MemOpIdx. Upstream uses 5 bits since 10.2. The softmmu template and the mmu function handlers now extract the index with get_mmuidx() instead of a hard-coded mask. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Deleted the translator headers in tools and the STATIC_TRANSLATOR code paths that supported them in libcpu and libtcg. Nothing in the build defined STATIC_TRANSLATOR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The files are the output of scripts/upgrade/normalize.sh, without any change. Nothing compiles them yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The file is the output of scripts/upgrade/normalize.sh, without any change. Nothing includes it yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The includes point at the libcpu, libtcg and libutils headers. The TLB entry gains se_addend, the comparator gains the S2E flags, and the TLB size is pinned. cpu-mmu-index.h is hand written. Nothing compiles these files yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each deviation carries a comment that starts with "S2E:". The glue that stands in for the QEMU code that is not ported is in src/s2e/cputlb-deps.h, and the symbolic execution half is in the two cputlb-symbex files. Nothing compiles these files yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
….0's cputlb.c
The TLB layout is shared by cputlb.c, the libtcg backend and libs2ecore,
so the three change together.
libcpu compiles accel/cputlb.c natively and as bitcode, takes upstream's
TLB structures in cpu/state.h, and provides the TCGCPUOps hooks and the
watchpoint functions that cputlb.c calls. softmmu-compat.h maps the old
accessor names onto the new API. The softmmu template headers,
exec-tlb.c, exec-phys.c and the unused ld*_raw_symb accessors are
removed. x86_cpu_tlb_fill() aborts when a probe faults, because the page
walk has already recorded the fault in CR2.
libtcg calls helper_{ld,st}*_mmu directly, as upstream does. tcg/tlb.h,
tcg/cpu.h, the helper override tables and the atomic helper stubs are
removed. The atomic templates now live in libcpu. The LLVM translator
aborts on a 128-bit memory operation, which it has no helper for.
libs2ecore reads the KLEE object of a TLB entry from CPUTLBEntryFull and
its MMU function handlers follow the new TLB layout and helper
arguments. g_sqi.mem.read_ram_concrete_check lost its last user and is
removed.
libs2e links libcpu.a and libtcg.a as a group, because libtcg refers to
helpers that libcpu defines.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The upstream softmmu passes the address of the access to notdirty_write() and cpu_check_watchpoint() directly, so nothing reads the field or its symbolic copy in the execution state anymore. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
KLEE interprets every instruction of a translation block, but the blocks were not optimized. Run sroa, early-cse, instsimplify, simplifycfg and adce on each block. On coreutils-echo, this removes 22% of the instructions of the blocks and every alloca. The pipeline keeps the shape of the code that S2E depends on: simplifycfg does not speculate or simplify conditional branches, which create selects and freeze instructions, instcombine is not used because it creates intrinsics that KLEE does not lower in translation blocks, and there is no dead store elimination. splitCommonReturn() undoes the merging of the returns, which GetStaticBranchTarget() needs. The translator also removes the memory effects that the compiler inferred for the helpers, such as memory(none) on helper_lzcnt(). KLEE can fork inside a helper, and early-cse could otherwise remove a store to the CPU state that a later store overwrites after the call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… access path KLEE interpreted about 185 instructions for each guest memory access in the bitcode of cputlb.c, against 45 before the softmmu replacement. - Inline the access path in the bitcode build, so that MMULookupLocals stays in registers and the call frames disappear. - Add a TLB hit fast path to the bitcode wrappers (se_tlb_hit_haddr()), which accesses the host address directly when the page has no flags. - With fork-on-symbolic-address, make the address concrete once per access in the wrappers, before the TLB lookup, instead of again in mmu_lookup(). - Report symbolic hardware accesses from the device path (se_hw_ld_beN(), se_hw_st_leN()) instead of doing a second TLB lookup after every access. The host address comes from the lookup result. The reports carry the physical address, a load returns the value that the symbolic hardware plugins give back, and a store that TLB_DISCARD_WRITE drops is not reported. Code fetches from device pages are not reported. handlerTraceMmioAccess() takes the bytes of a load in the order of do_ld_mmio_beN() and converts them to guest byte order only when the access hits symbolic hardware, so that other symbolic bytes are returned unchanged. It now returns the value instead of the address when no symbolic hardware hook is registered. - Compute the TLB index once per lookup in mmu_lookup1(). - Compile the bitcode library with -Oz and the inline threshold of -Os, and force tlb_index() and tlb_entry() inline. This removes 25% of the instructions of op_helper.bc and keeps the TLB hit path at 47 to 51 instructions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
shl_double(), shr_double() and udiv_qrnnd() used x86 inline assembly because the bitcode is compiled with -march=x86-64. KLEE cannot interpret inline assembly and terminated any state that ran an FPU helper in symbolic mode. The bitcode build now uses the portable C versions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The request was only copied when the cpu coroutine started a new cpu_x86_exec. When the client requested a window on the KVM_RUN that completes an I/O exit, the coroutine resumed in the middle of cpu_x86_exec and the request was ignored. An interrupt raised by an I/O handler while the guest had interrupts disabled then stayed pending until an unrelated exit. SeaBIOS failed to boot from a floppy because the controller's reset interrupt never arrived in time. This was masked until 4223c7d, whose cpu exit signal handler set the window request on every kick. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
s2e_log.h declares print_stacktrace() inside extern "C", but Utils.cpp did not include the header and defined the function with C++ linkage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The TLB is no longer in CPUX86State. virt_to_host_tlb and s2e-cpu-print-tlb now find it in the CPUState that precedes env in ArchCPU, and take the table size from its mask. The print command shows every MMU index. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
softmmu-update.md is marked as landed and records the remaining deviations from the plan. PORTING.md marks the softmmu work of phases 1, 2, 4 and 6 as done and describes the flag allocation that was used. tlb-update.md notes that the cputlb.c import has landed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR moves libtcg, softfloat and the vendored QEMU utilities to QEMU v11.1.0 and replaces the QEMU 1.0 era softmmu of libcpu with upstream's
accel/tcg/cputlb.c. The QEMU code moves into two places:bswap.h).Both components are upgraded with a shared normalize and three-way merge script, so future QEMU releases can be merged mechanically.
The CPU state is reorganized to match upstream's
CPUState/ArchCPUlayout, which the new softmmu requires. The TLB and other caches no longer travel with each execution state. The PR also includes KLEE fixes for the new bitcode, LLVM optimization of translation blocks, and an interrupt window fix in libs2e.Changes
Upgrade tooling
scripts/upgrade/(normalize.sh,merge.sh), shared by libtcg and libutils.normalize.shruns the upstream file through clang-format with the S2E style, so the diff against the S2E copy only contains the S2E changes (79 lines instead of 6800 fortcg.c).merge.shthen does a three-way merge driven by each component'sBASELINEandmapping.tsv.upgrade-libtcgskill, which describes the workflow, the S2E deviations that must survive a merge, and the libcpu changes that libtcg's own build does not catch.libtcg, softfloat and libutils
libutils.a.libs2e/configuretakes--with-libutilsinstead of the three separate flags.tcg-op-mem.h, andtcg_gen_insn_starttakes a fixed number of words. This also fixes two existing bugs: a staletcg-gvec-desc.hthat decodedoprszincorrectly, and atomic helpers that declared their address astarget_ulonginstead of i64.softfloat.bc, so symbolic paths see the new behavior too.cpu_state_reset()now sets the NaN propagation rules, otherwise softfloat asserts on the first operation with two NaNs.cutils,osdep,compiler.h,qht,rcu,thread,xxhash,seqlock,queue.h,bitmap,bufferiszero, ...). Most of them replace hand-written subsets that had to be merged by hand. Target-independent files moved from libtcg to libutils.bswap.his split into a host half (libutils) and a target half (libtcg). The remaining deviations are listed inscripts/upgrade/README.md.utils/config-host.hdefinesCONFIG_INT128,HOST_BIG_ENDIANand the glib slice allocator config in one place. Previously the bitcode build ofsoftfloat.cdid not get these definitions, which left an unresolvedmulu64()reference inop_helper.bc.CPU state layout
cpu/state.hdefinesCPUState,CPUNegativeOffsetStateandArchCPUwith the upstream layout:CPUX86Statedirectly followsCPUState, and generated code reaches the TLB at a negative offset from env.CPU_COMMONexecution fields (exception_index,interrupt_request,jmp_env, breakpoints, ...) moved intoCPUState. libs2ecore registers them as a separate concrete object (CpuExecutionState) and saves it on every state switch. The concrete CPU region now holds only architectural state.STATIC_TRANSLATOR), which nothing in the build defined.Softmmu replacement
cputlb.candtlb-common.hfrom v11.1.0 as normalized copies. The S2E deviations are added in separate commits and each starts with anS2E:comment. The glue code for the QEMU parts that are not ported is insrc/s2e/cputlb-deps.h, and the symbolic execution part is in thecputlb-symbexfiles.helper_{ld,st}*_mmudirectly, as upstream does. The old softmmu templates,exec-tlb.c,exec-phys.c, the helper override tables andmem_io_vaddrare removed. The LLVM translator aborts on 128-bit memory operations, for which it has no helper.-Oz. A TLB hit now takes 47 to 51 instructions.TLB handling in libs2ecore
doStateSwitch()flushes them, so every activated state starts with an empty TLB.getCpuCaches()aborts on an inactive state.getCpuCaches(). Before, one update could index the global TLB and then clear the per-state buffer.--tlb-auditturns on at runtime the TLB cache consistency check, which used to require the compile-timeS2E_DEBUG_TLBCACHEdefine and relied on asserts.LLVM and KLEE
splitCommonReturn()keeps the shape thatGetStaticBranchTarget()needs. The translator also removes the memory effects that the compiler inferred for helpers, because KLEE can fork inside a helper.llvm.experimental.noalias.scope.decl, which the float128 code brings intoop_helper.bcand which made KLEE fail before it executed the first instruction. Metadata operands are now classified correctly inKFunction.llvm.is.fpclassis expanded into integer tests, so the result stays symbolic.llvm.fmuladdis expanded into a multiply and an add.llvm.fma,llvm.rintandllvm.nearbyintare evaluated with APFloat on concrete operands.raw_string_ostream::str().Other fixes
KVM_RUN. Before, the request was only passed when the CPU coroutine started a newcpu_x86_exec, so a request made when completing an I/O exit was ignored. SeaBIOS could not boot from a floppy because the controller's reset interrupt arrived too late.print_stacktrace()now has C linkage, ass2e_log.hdeclares it.Documentation
libcpu/PORTING.md,tlb-update.mdandsoftmmu-update.mddescribe the plan for the remaining QEMU 11.1 porting work and what has landed so far.CLAUDE.mdhas updated writing style rules.Requirements
libs2e/configuremust pass--with-libutilsinstead of--with-fsigc++,--with-libqand--with-libcoroutine.Testing
merge.shreports zero conflicts for libtcg and libutils at v11.1.0.noalias.scope.declremoval, metadata operand classification and each floating point intrinsic.🤖 Generated with Claude Code