target/ppc: Fix PMU hflags calculation
authorNicholas Piggin <npiggin@gmail.com>
Tue, 30 May 2023 13:04:47 +0000 (23:04 +1000)
committerDaniel Henrique Barboza <danielhb413@gmail.com>
Sat, 10 Jun 2023 13:19:24 +0000 (10:19 -0300)
commit6494d2c1fd4ebc37b575130399a97a1fcfff1afc
tree7cf1f320f297839621d74c49cf37209f83c689d5
parent34b4313070b5f5613fb8198806f57614826b0aac
target/ppc: Fix PMU hflags calculation

Some of the PMU hflags bits can go out of synch, for example a store to
MMCR0 with PMCjCE=1 fails to update hflags correctly and results in
hflags mismatch:

  qemu: fatal: TCG hflags mismatch (current:0x2408003d rebuilt:0x240a003d)

This can be reproduced by running perf on a recent machine.

Some of the fragility here is the duplication of PMU hflags calculations.
This change consolidates that in a single place to update pmu-related
hflags, to be called after a well defined state changes.

The post-load PMU update is pulled out of the MSR update because it does
not depend on the MSR value.

Fixes: 8b3d1c49a9f0 ("target/ppc: Add new PMC HFLAGS")
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Message-Id: <20230530130447.372617-1-npiggin@gmail.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
target/ppc/cpu_init.c
target/ppc/helper_regs.c
target/ppc/helper_regs.h
target/ppc/machine.c
target/ppc/power8-pmu.c
target/ppc/power8-pmu.h