BACKPORT: UPSTREAM: KVM: arm64: timers: Allow userspace to set the global counter offset

And this is the moment you have all been waiting for: setting the
counter offset from userspace.

We expose a brand new capability that reports the ability to set
the offset for both the virtual and physical sides.

In keeping with the architecture, the offset is expressed as
a delta that is substracted from the physical counter value.

Once this new API is used, there is no going back, and the counters
cannot be written to to set the offsets implicitly (the writes
are instead ignored).

Reviewed-by: Colton Lewis <coltonlewis@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20230330174800.2677007-8-maz@kernel.org

(cherry picked from commit 30ec7997d175cd689fc61bfc4059f4d35b11858c)

Conflicts:
	arch/arm64/include/asm/kvm_host.h

Didn't cherry-pick commit 06394531b425 ("KVM: arm64: Generalise VM
features into a set of flags"), which adds the flags variable to,
simply backports.

	arch/arm64/kvm/arch_timer.c

No poffset. The changes that add poffset didn't get cherry-picked
since we don't use the physical counter.

	virt/kvm/arm/arm.c (renamed and context)
	include/uapi/linux/kvm.h (context)
	arch/arm64/include/uapi/asm/kvm.h (context)
	include/uapi/linux/kvm.h (context)

BUG=b:295256641
TEST=Observed difference in CLOCK_BOOTTIME and CLOCK_MONOTONIC in guest
    after suspend.

Signed-off-by: Suleiman Souhlal <suleiman@google.com>
Change-Id: I12e67ab4ff450a0eaa4c02259bfba0563fb4a047
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/5540816
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
5 files changed