Commit Graph

986008 Commits

Author SHA1 Message Date
Ramji Jiyani
2da3b12bc0 ANDROID: GKI: Enable system_dlkm build for gki
Update GKI build configs to build system_dlkm.img.

Add an empty system_dlkm modules list file at:
android/gki_system_dlkm_modules

Bug: 200082547
Bug: 214445388
Test: TH
Signed-off-by: Ramji Jiyani <ramjiyani@google.com>
Change-Id: Ia11b48d6033a39479d71c90159c74809a874893d
2022-01-14 19:58:15 +00:00
Ramji Jiyani
39220e855b ANDROID: GKI: Enable config for module signing
Enabled signed module and Android gki module symbol
protection support.

Bug: 200082547
Bug: 214445388
Test: TH
Signed-off-by: Ramji Jiyani <ramjiyani@google.com>
Change-Id: I0ecfb1df8437c67c00a5bb9bf813d27ff153a2cf
2022-01-14 19:57:39 +00:00
Ramji Jiyani
254d999798 ANDROID: GKI: Do not force select MODULE_SIG_ALL
CONFIG_MODULE_SIG_ALL needs to be set for gki_defconig,
but will require an override via device fragments
to avoid signing the vendor modules at build-time.

It defaults to 'y' so no need to explicitly set for
gki_defconfig.

Bug: 200082547
Bug: 214445388
Fixes: 9ab6a24225 ("ANDROID: GKI: Add module load time protected symbol lookup")
Test: TH, manual builds including P21 mainline
Signed-off-by: Ramji Jiyani <ramjiyani@google.com>
Change-Id: Iafc0936b5e7bfb781b28642d1ec233a7fcf85f09
2022-01-14 19:57:16 +00:00
David Brazdil
d1109f05c3 BACKPORT: FROMLIST: misc: open-dice: Add driver to expose DICE data to userspace
Open Profile for DICE is an open protocol for measured boot compatible
with the Trusted Computing Group's Device Identifier Composition
Engine (DICE) specification. The generated Compound Device Identifier
(CDI) certificates represent the hardware/software combination measured
by DICE, and can be used for remote attestation and sealing.

Add a driver that exposes reserved memory regions populated by firmware
with DICE CDIs and exposes them to userspace via a character device.

Userspace obtains the memory region's size from read() and calls mmap()
to create a mapping of the memory region in its address space. The
mapping is not allowed to be write+shared, giving userspace a guarantee
that the data were not overwritten by another process.

Userspace can also call write(), which triggers a wipe of the DICE data
by the driver. Because both the kernel and userspace mappings use
write-combine semantics, all clients observe the memory as zeroed after
the syscall has returned.

Acked-by: Rob Herring <robh@kernel.org>
Cc: Andrew Scull <ascull@google.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: David Brazdil <dbrazdil@google.com>
Link: https://lore.kernel.org/r/20220104100645.1810028-3-dbrazdil@google.com
Bug: 198197082
[willdeacon@: Fixed context conflicts in reserved_mem_matches[] and Makefile]
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 209580772
Change-Id: If1160c8cc3a39ea822e089d1b80c837aec8075fa
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:28 +00:00
David Brazdil
3d914125b2 FROMLIST: dt-bindings: reserved-memory: Open Profile for DICE
Add DeviceTree bindings for Open Profile for DICE, an open protocol for
measured boot. Firmware uses DICE to measure the hardware/software
combination and generates Compound Device Identifier (CDI) certificates.
These are stored in memory and the buffer is described in the DT as
a reserved memory region compatible with 'google,open-dice'.

Signed-off-by: David Brazdil <dbrazdil@google.com>
Link: https://lore.kernel.org/r/20220104100645.1810028-2-dbrazdil@google.com
Bug: 198197082
Bug: 209580772
Signed-off-by: Will Deacon <willdeacon@google.com>
Change-Id: If318ad91ef1ae26ff639f99a4349e8c737d286b6
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:28 +00:00
Will Deacon
c02620fb25 ANDROID: KVM: arm64: relay entropy requests from protected guests directly to secure
As pKVM does not trust the host, it should not be involved in the
handling of, or be able to observe the response to entropy requests
issues by protected guests.

When an SMC-based implementation of the ARM SMCCC TRNG interface is
present, pass any HVC-based requests directly on to the secure firmware.

Co-developed-by: Ard Biesheuvel <ardb@google.com>
Signed-off-by: Ard Biesheuvel <ardb@google.com>
Signed-off-by: Will Deacon <will@kernel.org>
Bug: 209580772
Change-Id: Ica492ce49fd059a62ecc31bb7ac13c9adb773a08
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:28 +00:00
Will Deacon
d01a90c858 ANDROID: KVM: arm64: Create EL2 copy of __icache_flags for pKVM instead of alias
Using an alias of the host's `__icache_flags` variable at EL2 for pKVM
is risky, as it provides the host with a mechanism to elide cache
maintenance of guest pages by causing functions such as icache_is_vpipt()
to erroneously return false.

Create a private copy of the __icache_flags variable at EL2 and
initialise it using the host's version during pKVM init.

Signed-off-by: Will Deacon <will@kernel.org>
Bug: 209580772
Change-Id: I595f11d1e336dadae0eb82222e4da79a1069012a
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:28 +00:00
Marc Zyngier
ec2585f588 ANDROID: arm64: Register earlycon fixmap with the MMIO guard
On initialising the MMIO guard infrastructure, register the
earlycon mapping if present.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: I379387253d08e2414fa386a3360a45391da7d90d
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:27 +00:00
Marc Zyngier
f6edd58a0c ANDROID: arm64: Add a helper to retrieve the PTE of a fixmap
In order to transfer the early mapping state into KVM's MMIO
guard infrastucture, provide a small helper that will retrieve
the associated PTE.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: Iefc1c57d5e9476b718a8a68f60e562a57b09fb6a
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:27 +00:00
Marc Zyngier
8e744844c6 ANDROID: arm64: Enroll into KVM's MMIO guard if required
Should a guest desire to enroll into the MMIO guard, allow it to
do so with a command-line option.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: Ia9a77f693531740500739693c52b4959abacafd4
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:27 +00:00
Marc Zyngier
f89d2055a3 ANDROID: arm64: Implement ioremap/iounmap hooks calling into KVM's MMIO guard
Implement the previously defined ioremap/iounmap hooks for arm64,
calling into KVM's MMIO guard if available.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: I86a78f8941fb60078fb873a34c5eb32830a00259
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:27 +00:00
Marc Zyngier
bd1474cd4c ANDROID: BACKPORT: mm/vmalloc: Add arch-specific callbacks to track io{remap,unmap} physical pages
Add a pair of hooks (ioremap_phys_range_hook/iounmap_phys_range_hook)
that can be implemented by an architecture. Contrary to the existing
arch_sync_kernel_mappings(), this one tracks things at the physical
address level.

This is specially useful in these virtualised environments where
the guest has to tell the host whether (and how) it intends to use
a MMIO device.

Signed-off-by: Marc Zyngier <maz@kernel.org>
[willdeacon@: Hook ioremap_page_range() in mm/ioremap.c]
Bug: 209580772
Change-Id: I970c2e632cb2b01060d5e66e4194fa9248188f43
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:23 +00:00
Marc Zyngier
be179b64d0 ANDROID: KVM: arm64: Add some documentation for the MMIO guard feature
Document the hypercalls user for the MMIO guard infrastructure.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: I927bcd6c5e3ef932265d817288ff2b46b0e0db66
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:23 +00:00
Marc Zyngier
a0841f8b50 ANDROID: KVM: arm64: Plumb MMIO checking into the fault handling
Plumb the MMIO checking code into the MMIO fault handling code.
Any fault hitting outside of an MMIO region will now report
an invalid syndrome, and won't leak any data from the guest.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: I68bef2d0211a804aa1e598aeaa0c85dc4098f61e
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:23 +00:00
Marc Zyngier
1b72ff723d ANDROID: KVM: arm64: pkvm: Wire MMIO guard hypercalls
Plumb in the hypercall interface to allow a guest to discover,
enroll, map and unmap MMIO regions.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: I0390456ffde8ceca351d3d8e82fd1dddeb747fac
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:23 +00:00
Marc Zyngier
0cf8258626 ANDROID: KVM: arm64: pkvm: Add MMIO guard infrastructure
Introduce the infrastructure required to identify an IPA region
that is expected to be used as an MMIO window.

This include mapping, unmapping and checking the regions. Nothing
calls into it yet, so no expected functional change.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: I227eaa28b98e067e3daae4f9e1071eb37a6761cc
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:23 +00:00
Marc Zyngier
b7bef27e71 ANDROID: KVM: arm64: Introduce KVM_ARCH_FLAG_MMIO_GUARD flag
Add a per-VM flag indicating that the guest has bought into the
MMIO guard enforcement framework.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: If60b2b38a419a9f44ebe9029f55dd016fd2444b5
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:22 +00:00
Marc Zyngier
fc38ca626f ANDROID: KVM: arm64: Expose topup_hyp_memcache() to the rest of KVM
In order to simplify the implementation of an EL2-only version of
MMIO guard, expose topup_hyp_memcache() and simplify its usage
by only requiring a vcpu.

While we're at it, make free_hyp_memcache() visible in kvm_host.h

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: I4f54c57a9693cf7a3450f99fedc15ae32af09a31
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:22 +00:00
Marc Zyngier
77deb98705 ANDROID: KVM: arm64: Define MMIO guard hypercalls
Define the handful of hypercalls that MMIO guard will require.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: Iac312b2327c31a1532fdb38e8fa8066291d9f611
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:22 +00:00
Marc Zyngier
19b510d531 ANDROID: KVM: arm64: Check for PTE valitity when checking for executable/cacheable
Don't blindly assume that the PTE is valid when checking whether
it describes an executable or cacheable mapping.

This makes sure that we don't issue CMOs for invalid mappings.

Suggested-by: Will Deacon <will@kernel.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: I5b271c91aa6ceb23f7b1e6a571e30d080866d5c9
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:22 +00:00
Marc Zyngier
d760740101 ANDROID: KVM: arm64: Generalise VM features into a set of flags
We currently deal with a set of booleans for VM features,
while they could be better represented as set of flags
contained in an unsigned long, similarily to what we are
doing on the CPU side.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: I86be6bab12287c3eb21bbe03f255e2899edbdffb
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:22 +00:00
Marc Zyngier
000f0c90c4 ANDROID: KVM: arm64: pkvm: Plug in cache invalidation for non-protected guests
Since we must still support the dreaded set/way CMOs for non-protected
VMs (as well as the equivalent operation when vcpus switch their MMU
on), perform an invalidation that will iterate over all the pages
that have been donated to the guest, one after the other.

This requires a minor change to the locking used for donation so
that all donated pages can be seen by a concurrent invalidation.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Signed-off-by: Will Deacon <willdeacon@google.com>
Change-Id: I1780127722bda7bdc884bb4e68db6ae47d042822
2022-01-14 16:43:22 +00:00
Marc Zyngier
21b5ab1b19 ANDROID: KVM: arm64: pkvm: Allow the shadows to be destroyed on teardown
There is no difference between protected and non-protected guests
when it comes to shadow structures, and we want these shadow
structures to have the same life cycle.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: I7e9bf366aae6bd0542d0038d24e2350a9dd23cd0
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:22 +00:00
Marc Zyngier
70f68991b3 ANDROID: KVM: arm64: pkvm: Don't init pvm traps non non-protected guests
We want the host to handle everything as usual.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: Icf8ee146917e886bca258815cf948a1b12540353
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:22 +00:00
Marc Zyngier
3336b8073a ANDROID: KVM: arm64: pkvm: Share memory with non-protected guests
Instead of donating memory to non-pVMs, share the memory, which
gives us a good enough approximation of the usual behaviour.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: I47213754613110a6fb8157806eb96ddf92ead346
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:21 +00:00
Marc Zyngier
4fe4fd6746 ANDROID: KVM: arm64: pkvm: Manage the non-protected guest dirty state from EL1
In order to deal with state synchronisation between EL1 and EL2,
we use the following setup:

- On exit from EL2, the state is forcefully marked clean.
- Should a trap be handled, the state is synchronised and immediately
  marked dirty
- On vcpu_put(), the state is also marked dirty, since it can be
  modified by userspace

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: I47a889ca5432566f236de4630d81753348632f8a
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:21 +00:00
Marc Zyngier
3e7b59fb60 ANDROID: KVM: arm64: pkvm: State sync primitives for non-protected guests
In order for a non-protected guest to be functionnal, userspace
has to be able to query its state, which means that the host view
of the vcpu has to be kept up to date.

In order to achieve this, we establish the following scheme for EL2:

- On entering vcpu_run(), we check for the KVM_ARM64_PKVM_STATE_DIRTY
  flag in the host vcpu. If set, we sync the state *from* the host
  to the shadow version.

- On exiting vcpu_run(), we don't do anything, but let the host
  issue a synch hypercall if required.

- On vcpu_put(), we force a synchronisation *to* the host.

The El1 host will have a complementary approach in the following
patches.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: I42811a25d2e176d6c7d9a66ade6e9149a96e9256
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:21 +00:00
Marc Zyngier
520514c341 ANDROID: KVM: arm64: pkvm: Introduce entry/exit handlers for non-protected guests
A non-protected guest requires a lot less handling than a protected
one when dealing with entries/exits from/to EL2.

Since we already indiredct those, introduce new entry/exit tables
for non-pVMs.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: I66602bc491a4a87d6482b12e4eaf7aa53a7dbfd9
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:21 +00:00
Marc Zyngier
a1ab3b544a ANDROID: KVM: arm64: pkvm: Make {flush,sync}_shadow_state() take the full state
As we're about to need to copy some state back and forth for
non0-protected guests, pass the full loaded state to the flush/sync
functions.

No functionnal change.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: I7ad6a00a7500e91237fcc0981261c819b2224ee0
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:21 +00:00
Marc Zyngier
4262892c41 ANDROID: KVM: arm64: pkvm: Replace pkvm_loaded_state.is_shadow with is_protected
When pKVM is enabled, all the vcpus must have a shadow structure
managed by the hypervisor, irrespective of theur protection status.

This field thus represents the wrong abstraction. Replace it with
'pkvm_loaded_state.is_protected', which tracks whether a vcpu is
part of a protected VM.

pkvm_loaded_state gets also moved around for convenience with the
following patches.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: Ic9876fde543abb350fe8969d5b4661e30092f553
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:21 +00:00
Marc Zyngier
5106d405c6 ANDROID: KVM: arm64: Generate hyp-constants.o as an nVHE object
A number of KVM definitions are keyd on _KVM_NVHE_HYPERVISOR__
being defined or not. Make sure we advertise this #define when
compiling hyp-constants.o, so that we get the right stuff.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: Ied191c0a18274258cffede72b06b0fb5bba5604e
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:21 +00:00
Marc Zyngier
c0dc717dca ANDROID: KVM: arm64: Introduce vcpu_is_protected() helper
Instead of poking into the internals of the host KVM structure,
stick to the shadow structures when trying to work out whether
a vcpu is part of a protected VM or not.

Take this opportunity to sprinkle a couple of unlikely(), just
because.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: I22a096e1e3cfe34cd2658684b02d8bac486416c4
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:20 +00:00
Marc Zyngier
c496a48855 ANDROID: KVM: arm64: pkvm: Update the shadow view of pkvm.enabled at creation time
As we can't really rely on the host side for the protection status,
snapshot the expected status at VM creation time.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: I0943eadba25e6c9fe718f29e749b9fcc8fbb79ba
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:20 +00:00
Marc Zyngier
8598c42c28 ANDROID: KVM: arm64: pkvm: Store vcpus in donated PGD at shadow-creation time
As KVM is moving to using an xarray to hold the vcpus instead of
the fixed size array that has been the norm so far, we are faced
with two options: either teach the EL2 code to parse an xarray
when building the shadow structures, or find an alternative way
of communicating the vcpus to the EL2 code.

An easy way to deal with the second approach is to use the page
that EL1 donates to HYP to hold the VM S2 PDG. Instead of just
giving the memory, let's copy the pointers to the vcpus in this
page. The overhead is acceptable (it happens only at VM creation
time), and in most cases we only have a handful of vcpus.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: Id0264f0960821563c4b3c0dfcbc43598b85a1f3b
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:20 +00:00
Marc Zyngier
8273903998 ANDROID: KVM: arm64: pkvm: Rerge get_num_hvc_args into handle_pvm_exit_hvc64
There really isn't much point in keeping these separate.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: I78b5c2d33bd4178415d51b2bccabfb5a7590d2c2
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:20 +00:00
Marc Zyngier
24ccade039 ANDROID: KVM: arm64: pkvm: Move memcache topup into a helper
Move the vcpu memcache topup into its own helper, as we will
eventually need it for the MMIO guard page table updates
(which uses the exact same mechanism).

No functionnal change.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 209580772
Change-Id: I72bac5e8be91acbb696a1428fc5cc6cc84d2df66
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:20 +00:00
Will Deacon
6f48cee5aa ANDROID: KVM: arm64: Introduce KVM_CAP_ARM_PROTECTED_VM to set/query PVM firmware
Expose a new capability, KVM_CAP_ARM_PROTECTED_VM, for protected VMs
which allows the size of the PVM firmware region to be discovered from
userspace and for the firmware load address to be specified if it is
required.

Signed-off-by: Will Deacon <will@kernel.org>
Bug: 209580772
Change-Id: I819b9b2cfa227f1a0607a8f683aa01d4ae50704f
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:20 +00:00
Will Deacon
20e053c891 ANDROID: BACKPORT: KVM: arm64: Introduce KVM_VM_TYPE_ARM_PROTECTED machine type for PVMs
Introduce a new virtual machine type, KVM_VM_TYPE_ARM_PROTECTED, which
specifies that the guest memory pages are to be unmapped from the host
stage-2 by the hypervisor.

Signed-off-by: Will Deacon <will@kernel.org>
[willdeacon@: Changed UAPI constants to reduce change of upstream collisions]
Bug: 209580772
Change-Id: I9de1ad96fec4f62434a81101749435f8b0596162
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:16 +00:00
Will Deacon
0ba692e7af ANDROID: KVM: arm64: Reset primary vCPU according to PVM firmware boot protocol
When a PVM firmware image is present for a protected VM, treat the first
running vCPU as the "primary" vCPU and reset its registers accordingly,
in particular by initialising its PC to enter the firmware at startup.

Signed-off-by: Will Deacon <will@kernel.org>
Bug: 209580772
Change-Id: I26676637145c7d809c5dc5ac0ad0e1fadaf275d2
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:16 +00:00
Will Deacon
adee75e0a4 ANDROID: KVM: arm64: Copy pvmfw into guest pages during donation from the host
When the host donates a page to a protected guest at an IPA which
coincides with the PVM firmware load address, copy-in the relevant
firmware page after unmapping it from the host but before mapping it
into the guest.

Signed-off-by: Will Deacon <will@kernel.org>
Bug: 209580772
Change-Id: I8cec813fa52938945f3122655deb785523a96ec8
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:16 +00:00
Will Deacon
9e2ddae4d3 ANDROID: KVM: arm64: Unmap PVM firmware from host stage-2 during de-privilege
Unmap the PVM firmware memory from the pKVM host by transferring
ownership of the pages to the hypervisor when the host deprivileges
itself during boot.

Signed-off-by: Will Deacon <will@kernel.org>
Bug: 209580772
Change-Id: I311642f543c0c73d0e0cf2ec051e8e2d9759c5d1
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:16 +00:00
Will Deacon
fb01b29bae ANDROID: BACKPORT: KVM: arm64: Parse reserved-memory node for pkvm guest firmware region
Add support for a "linux,pkvm-guest-firmware-memory" reserved memory
region, which can be used to identify a firmware image for protected
VMs. If pKVM fails to initialise and a firmware region is advertised,
then the memory is cleared during boot.

Signed-off-by: Will Deacon <will@kernel.org>
[willdeacon@: Include linux/io.h for memremap() and friends]
Bug: 209580772
Change-Id: Ibfcc0ff00d4b8a42747452047856cb9ba8def4c4
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:12 +00:00
Will Deacon
6e8a01f8d7 ANDROID: KVM: arm64: Extend comment in has_vhe()
has_vhe() expands to a compile-time constant when evaluated from the VHE
or nVHE code, alternatively checking a static key when called from
elsewhere in the kernel. On face value, this looks like a case of
premature optimization, but in fact this allows symbol references on
VHE-specific code paths to be dropped from the nVHE object.

Expand the comment in has_vhe() to make this clearer, hopefully
discouraging anybody from simplifying the code.

Cc: David Brazdil <dbrazdil@google.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Will Deacon <will@kernel.org>
Bug: 209580772
Change-Id: Icce36e192cafa14d388cb1d0a24585b6fcf6e46e
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:12 +00:00
Will Deacon
cd188a87f2 ANDROID: KVM: arm64: Ignore 'kvm-arm.mode=protected' when using VHE
Ignore 'kvm-arm.mode=protected' when using VHE so that kvm_get_mode()
only returns KVM_MODE_PROTECTED on systems where the feature is available.

Cc: David Brazdil <dbrazdil@google.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Will Deacon <will@kernel.org>
Bug: 209580772
Change-Id: I4854d299f4c5aebe7ed33020ac014b24154fdb52
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:11 +00:00
Will Deacon
003b19bae8 ANDROID: KVM: arm64: Create EL2 shadow for VMs when pKVM is enabled
Regardless of whether a given VM is protected or unprotected, when pKVM
is enabled we must create an EL2 shadow for each VM so that the stage-2
page-tables are managed by the hypervisor instead of the host.

Create the EL2 shadow for a VM on the first-run of a vCPU when a shadow
is not already present.

Signed-off-by: Will Deacon <will@kernel.org>
Bug: 209580772
Change-Id: I3e0ec8907f46b17d74623b84a029a5b50aeaf14f
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:11 +00:00
Will Deacon
c144439fa9 ANDROID: BACKPORT: arm64: mm: Implement memory encryption API using KVM sharing hypercalls
When running as a protected guest, the KVM host does not have access to
any pages mapped into the guest. Consequently, KVM exposes hypercalls to
the guest so that pages can be shared back with the host for the purposes
of shared memory communication such as virtio.

Detect the presence of these hypercalls when running as a guest and use
them to implement the memory encryption interfaces gated by
CONFIG_ARCH_HAS_MEM_ENCRYPT which are called from the DMA layer to share
SWIOTLB bounce buffers for virtio.

Although no encryption is actually performed, "sharing" a page is akin
to decryption, whereas "unsharing" a page maps to encryption, albeit
without destruction of the underlying page contents.

Signed-off-by: Will Deacon <will@kernel.org>
[willdeacon@: Use asm/mem_encrypt.h instead of asm/set_memory.h; Implement mem_encrypt_active()]
Bug: 209580772
Change-Id: I5955ff0dca65561183f9a60e94be87f28fbf14ec
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:08 +00:00
Marc Zyngier
be06c4567f FROMLIST: firmware/smccc: Call arch-specific hook on discovering KVM services
arm64 will soon require its own callback to initialise services
that are only availably on this architecture. Introduce a hook
that can be overloaded by the architecture.

Link: https://lore.kernel.org/r/20211004174849.2831548-12-maz@kernel.org
Signed-off-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Will Deacon <will@kernel.org>
Bug: 209580772
Change-Id: I743e1786df1477b3c9fab0fe2e5ea52a7dcdf01f
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:07 +00:00
Quentin Perret
49eccab7c3 ANDROID: BACKPORT: KVM: arm64: Zero protected guest pages on teardown
When a protected guest is torn down, the hypervisor currently
transitions the ownership of all the guest pages back to the host
without further intervention, which might leak guest secrets. To prevent
this, let's have the hypervisor zero the page before they can be
reclaimed by the host.

Signed-off-by: Quentin Perret <qperret@google.com>
[willdeacon@: Move pkvm_host_poison to mem_protect.h]
Bug: 209580772
Change-Id: Ib39de531284fef02c1cb84b83f0819f9e6f36f9b
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:04 +00:00
Quentin Perret
0465525457 ANDROID: KVM: arm64: Donate pages to protected guests
Now that we have all the infrastructure in place to allow guest-to-host
sharing of pages in protected mode, let's stop sharing the pages from
the host on guest memory aborts and switch to a proper donation instead.

Signed-off-by Quentin Perret <qperret@google.com>

Bug: 209580772
Change-Id: Ib37625172e24950cd74913a20bff8ce29a72f45b
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:04 +00:00
Will Deacon
7f19cf521f ANDROID: KVM: arm64: Allow userspace to receive SHARE and UNSHARE notifications
Expose MEM_SHARE and MEM_UNSHARE hypercalls to the KVM_CAP_EXIT_HYPERCALL
capability, allowing userspace (i.e. the VMM) to mprotect() its own
mapping of the pages based upon changes to the host permissions.

Signed-off-by: Will Deacon <will@kernel.org>
Bug: 209580772
Change-Id: I95890595f8cc5493a5a67636bd22da3cc90a95fc
Signed-off-by: Will Deacon <willdeacon@google.com>
2022-01-14 16:43:04 +00:00