]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commit
KVM: arm64: Make vcpu flag updates non-preemptible
authorMarc Zyngier <maz@kernel.org>
Tue, 18 Apr 2023 12:57:37 +0000 (13:57 +0100)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 16 Jun 2023 12:57:57 +0000 (14:57 +0200)
commitb064c8156bfa9ccce232ebad2a62a941375d7d06
tree3c1c016d12e24996de15bd493e40b75e14ffbfa5
parent5f2b9e309f8537e29a7035b527c1912f00ac5f54
KVM: arm64: Make vcpu flag updates non-preemptible

BugLink: https://bugs.launchpad.net/bugs/2023929
commit 35dcb3ac663a16510afc27ba2725d70c15e012a5 upstream.

Per-vcpu flags are updated using a non-atomic RMW operation.
Which means it is possible to get preempted between the read and
write operations.

Another interesting thing to note is that preemption also updates
flags, as we have some flag manipulation in both the load and put
operations.

It is thus possible to lose information communicated by either
load or put, as the preempted flag update will overwrite the flags
when the thread is resumed. This is specially critical if either
load or put has stored information which depends on the physical
CPU the vcpu runs on.

This results in really elusive bugs, and kudos must be given to
Mostafa for the long hours of debugging, and finally spotting
the problem.

Fix it by disabling preemption during the RMW operation, which
ensures that the state stays consistent. Also upgrade vcpu_get_flag
path to use READ_ONCE() to make sure the field is always atomically
accessed.

Fixes: e87abb73e594 ("KVM: arm64: Add helpers to manipulate vcpu flags among a set")
Reported-by: Mostafa Saleh <smostafa@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20230418125737.2327972-1-maz@kernel.org
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
arch/arm64/include/asm/kvm_host.h