Commit Graph

1061601 Commits

Author SHA1 Message Date
Ramji Jiyani
44e9b82e01 ANDROID: GKI: x86_64: zram & zsmalloc as modules
Enable zram and zsmalloc as modules to be in sync
with the aarch64 builds.

Bug: 232431151
Test: TH
Signed-off-by: Ramji Jiyani <ramjiyani@google.com>
Change-Id: I55053eeb6beda342689c854f95f4307871a3729b
2022-10-27 02:54:40 +00:00
Ramji Jiyani
316cffd398 ANDROID: GKI: Convert zram & zsmalloc as protected
Remove zram & zsmalloc symbols from  abi_gki_aarch64.
This makes these modules as protected until some partner
adds these symbols in their symbol list to override them.

This also cleans up the generic symbol list as per the
GKI modules symbol handling i.e. GKI modules don't contribute
to the KMIs until they are being override by the partners.

Bug: 232431151
Test: TH
Signed-off-by: Ramji Jiyani <ramjiyani@google.com>
Change-Id: I30fb0a46f306d1efdc7e174725066dcc86040e80
2022-10-27 01:15:59 +00:00
Wenchao Chen
736a02437c UPSTREAM: mmc: sdhci: Fix host->cmd is null
commit faded9b557 upstream

When data crc occurs, the kernel will panic because host->cmd is null.

Signed-off-by: Wenchao Chen <wenchao.chen@unisoc.com>

Fixes: 6f0f720466f6 ("mmc: sdhci: Capture eMMC and SD card errors")
Change-Id: Ibb69655762c00ba9ee252888c6ff2b8999e7e7d1
Cc: stable@vger.kernel.org
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Link: https://lore.kernel.org/r/20220907035847.13783-1-wenchao.chen666@gmail.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Bug: 254605504
Signed-off-by: Wenchao Chen <wenchao.chen@unisoc.com>
2022-10-26 16:05:40 +00:00
Yifan Hong
3d56edf4a9 ANDROID: kleaf: Initial list of ddk_headers (2: virtual_device_x86_64)
This CL includes headers used by the external modules
of virtual_device_x86_64.

Allowlist: This is a list of headers and a list of
include directories that are known to be safe
to be used by modules.

- This list includes:
  - Everything under
    - arch/x86/include
    - include

Unsafe list: This is the list of headers that are known to be used
by the external modules of virtual_device_x86_64, minus allowlist.
This means, with the allowlist and unsafe list, the certain Pixel
device kernel build can be transitioned to DDK without any change
to the source code.

- Note that for cleaness of DDK modules, we may want to
  remove some items in the allowlist of includes and
  require device source code to #include from the
  correct directory.

The command to generate this list is:

bazel run //build/kernel/kleaf:gen_ddk_headers \
  --gen_ddk_headers_target=//common-modules/virtual-device:virtual_device_x86_64_modules_install \
  --gen_ddk_headers_input_archives=//common:kernel_x86_64_ddk_allowlist_headers \
  -- -k

Manual edits:
- arch/arm64/include/ is added back. This is due to a limitation
  of the generation script that globs aren't properly handled.

Bug: 248351908

Signed-off-by: Yifan Hong <elsk@google.com>
Change-Id: I0eae9213493d78a6899aa15c8096f3c7694328a3
2022-10-25 22:58:43 +00:00
Eric Biggers
93f55093bb ANDROID: scsi: ufs: add vendor hook to override key reprogramming
Some hardware has a way to restore all keyslots at once that is
significantly faster than restoring each keyslot individually, as is
done by blk_ksm_reprogram_all_keys().  Add a hook
"android_rvh_ufs_reprogram_all_keys" that allows overriding the
restoration of all keyslots after UFS reset.  This may sleep, so this
must be a "restricted" Android vendor hook rather than a regular one.

Note that currently this functionality can't be upstreamed, as support
for the hardware that needs it would need to be upstreamed first.

(cherry picked from commit e2e063f507)

Bug: 162257402
Bug: 181905172
Bug: 241106918
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Kenny Root <kroot@google.com>
Change-Id: I0b25393a5131941f085892560e08a64e63cd1369
2022-10-25 18:12:46 +00:00
Will Deacon
3cf954ca25 ANDROID: BACKPORT: 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>
[willdeacon@: Fix trivial conflict in include/uapi/linux/kvm.h with
 other KVM_CAP_* definitions from upstream]
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 254819795
Change-Id: I819b9b2cfa227f1a0607a8f683aa01d4ae50704f
2022-10-25 14:05:50 +01:00
Will Deacon
f19614d0a0 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>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 254819795
Change-Id: I26676637145c7d809c5dc5ac0ad0e1fadaf275d2
2022-10-25 14:05:50 +01:00
Will Deacon
f8516f3e3a 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>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 254819795
Change-Id: I8cec813fa52938945f3122655deb785523a96ec8
2022-10-25 14:05:50 +01:00
Will Deacon
4b06a6a33d ANDROID: KVM: arm64: Clear pvmfw pages on clean host shutdown
When the host shuts down cleanly under pKVM, it is EL2's responsibility
to clear the pvmfw pages before forwarding the PSCI call onto EL3.

Wipe the pvmfw pages on SYSTEM_OFF, SYSTEM_RESET and SYSTEM_RESET2 calls
from the host, cleaning the zeroed memory to the PoC for good measure.

Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 254819795
Change-Id: I0dd2757e355f384813319034c6eed0fa2c2328c2
2022-10-25 14:05:50 +01:00
Will Deacon
f92a7cd932 ANDROID: KVM: arm64: Ignore length of 0 in kvm_flush_dcache_to_poc()
kvm_flush_dcache_to_poc() converts its (start,len) parameters into
(start,end) parameters for dcache_clean_inval_poc(). This mostly works
out except for the case when 'len == 0', where dcache_clean_inval_poc()
will still issue cache maintenance for the cache line containing 'start'.
If 'start' is not mapped, then this can generate an unexpected fault.

In preparation for cleaning the pvmfw memory pages to the PoC on
system reset, tweak kvm_flush_dcache_to_poc() to act as a no-op when
the supplied length is 0 and avoid having to check for this corner case
in the caller.

Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 254819795
Change-Id: Idae2b22289398e941938821d1d3b3a5a1da3fd8f
2022-10-25 14:05:50 +01:00
Will Deacon
622befc7e3 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>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 254819795
Change-Id: I311642f543c0c73d0e0cf2ec051e8e2d9759c5d1
2022-10-25 14:05:50 +01:00
Will Deacon
27b23af252 ANDROID: 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>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 254819795
Change-Id: Ibfcc0ff00d4b8a42747452047856cb9ba8def4c4
2022-10-25 14:05:50 +01:00
Yifan Hong
14e14cc4e9 ANDROID: kleaf: Initial list of ddk_headers (1: Pixel)
This CL includes headers used by the external modules of
a real Pixel device.

Allowlist: This is a list of headers and a list of
include directories that are known to be safe
to be used by modules.

- This list includes:
  - Everything under
    - arch/arm64/include
    - include

Unsafe list: This is the list of headers that are known to be used
by a certain Pixel device kernel build, minus allowlist.
This means, with the allowlist and unsafe list, the certain Pixel
device kernel build can be transitioned to DDK without any change
to the source code.

- Note that for cleaness of DDK modules, we may want to
  remove some items in the allowlist of includes and
  require device source code to #include from the
  correct directory.

The command to generate this list is:

bazel run //build/kernel/kleaf:gen_ddk_headers \
  --gen_ddk_headers_target=//gs/google-modules/soc-modules:slider_modules_install
  -- -k

Manual edits:

- manually removed the following headers that no longer exist on
android14-5.15:

remove hdrs arch/arm64/kvm/hyp/include/nvhe/ffa.h|//common:all_headers_unsafe
remove hdrs arch/arm64/kvm/hyp/include/nvhe/iommu.h|//common:all_headers_unsafe
remove hdrs arch/arm64/kvm/hyp/include/nvhe/pkvm.h|//common:all_headers_unsafe
remove hdrs drivers/scsi/ufs/ufs.h|//common:all_headers_unsafe
remove hdrs drivers/scsi/ufs/ufs_quirks.h|//common:all_headers_unsafe
remove hdrs drivers/scsi/ufs/ufshcd.h|//common:all_headers_unsafe
remove hdrs drivers/scsi/ufs/ufshcd-crypto.h|//common:all_headers_unsafe
remove hdrs drivers/scsi/ufs/ufshcd-pltfrm.h|//common:all_headers_unsafe
remove hdrs drivers/scsi/ufs/ufshci.h|//common:all_headers_unsafe
remove hdrs drivers/scsi/ufs/unipro.h|//common:all_headers_unsafe

- manually remove a source:

remove hdrs lib/vdso/gettimeofday.c|//common:all_headers_unsafe

Bug: 248351908

Change-Id: Ie75c45f1646ec6055dcdb6f49d3001691581c046
Signed-off-by: Yifan Hong <elsk@google.com>
2022-10-24 20:29:13 +00:00
Yifan Hong
ede1fd38ee ANDROID: kleaf: Initial list of ddk_headers (0: skeleton)
Create the skeleton rules for DDK headers, and write comments
with hands.

This CL has no real effect; all targets are declared empty
and content is filled in in follow up CLs.

Allowlist: This is a list of headers and a list of
include directories that are known to be safe
to be used by modules.

Unsafe list: This is the list of headers that are known to be used
by some device kernel build, minus allowlist.
This means, with the allowlist and unsafe list, an unspecified
device kernel build can be transitioned to DDK without any change
to the source code.

- Note that for cleaness of DDK modules, we may want to
  remove some items in the allowlist of includes and
  require device source code to #include from the
  correct directory.

Bug: 248351908

Signed-off-by: Yifan Hong <elsk@google.com>
Change-Id: I4f15d2fac703bc3b7100a72e90f289236db3e7e5
2022-10-24 20:28:48 +00:00
Eric Ren
b5a50b82c8 UPSTREAM: KVM: arm64: vgic: Fix exit condition in scan_its_table()
With some PCIe topologies, restoring a guest fails while
parsing the ITS device tables.

Reproducer hints:
1. Create ARM virt VM with pxb-pcie bus which adds
   extra host bridges, with qemu command like:

```
  -device pxb-pcie,bus_nr=8,id=pci.x,numa_node=0,bus=pcie.0 \
  -device pcie-root-port,..,bus=pci.x \
  ...
  -device pxb-pcie,bus_nr=37,id=pci.y,numa_node=1,bus=pcie.0 \
  -device pcie-root-port,..,bus=pci.y \
  ...

```
2. Ensure the guest uses 2-level device table
3. Perform VM migration which calls save/restore device tables

In that setup, we get a big "offset" between 2 device_ids,
which makes unsigned "len" round up a big positive number,
causing the scan loop to continue with a bad GPA. For example:

1. L1 table has 2 entries;
2. and we are now scanning at L2 table entry index 2075 (pointed
   to by L1 first entry)
3. if next device id is 9472, we will get a big offset: 7397;
4. with unsigned 'len', 'len -= offset * esz', len will underflow to a
   positive number, mistakenly into next iteration with a bad GPA;
   (It should break out of the current L2 table scanning, and jump
   into the next L1 table entry)
5. that bad GPA fails the guest read.

Fix it by stopping the L2 table scan when the next device id is
outside of the current table, allowing the scan to continue from
the next L1 table entry.

Thanks to Eric Auger for the fix suggestion.

Fixes: 920a7a8fa9 ("KVM: arm64: vgic-its: Add infrastructure for tableookup")
Suggested-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Eric Ren <renzhengeek@gmail.com>
[maz: commit message tidy-up]
Signed-off-by: Marc Zyngier <maz@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/d9c3a564af9e2c5bf63f48a7dcbf08cd593c5c0b.1665802985.git.renzhengeek@gmail.com
(cherry picked from commit c000a26071)
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Bug: 233588291
Change-Id: I451a60515a68e2f5386b190c0c09e6a476bd5e90
2022-10-24 10:54:19 +01:00
Denis Nikitin
bb2ade6a3b UPSTREAM: KVM: arm64: nvhe: Fix build with profile optimization
Kernel build with clang and KCFLAGS=-fprofile-sample-use=<profile> fails with:

error: arch/arm64/kvm/hyp/nvhe/kvm_nvhe.tmp.o: Unexpected SHT_REL
section ".rel.llvm.call-graph-profile"

Starting from 13.0.0 llvm can generate SHT_REL section, see
https://reviews.llvm.org/rGca3bdb57fa1ac98b711a735de048c12b5fdd8086.
gen-hyprel does not support SHT_REL relocation section.

Filter out profile use flags to fix the build with profile optimization.

Signed-off-by: Denis Nikitin <denik@chromium.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20221014184532.3153551-1-denik@chromium.org
(cherry picked from commit bde971a83b)
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Bug: 233588291
Change-Id: I863917d8f6b3440e3bba5daba865df34da394541
2022-10-24 10:54:19 +01:00
Will Deacon
0dd068cba2 Revert "Revert "ANDROID: gki_defconfig: Ensure KVM is configured in "protected" mode""
This reverts commit 17ff52af66.

With basic support for protected VMs, we can once again boot with KVM in
protected mode.

Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I15c41462b7fad4d3c5d5310674c0da385086d1c5
2022-10-21 10:30:26 +01:00
Will Deacon
39d08ecff2 ANDROID: Documentation: KVM: Add some documentation for Protected KVM on arm64
Add some initial documentation for the Protected KVM (pKVM) feature on
arm64, describing the user ABI for creating protected VMs as well as
their limitations.

Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I152af404f24b9aba3cc9be6acd8e26afcfa4b0a5
2022-10-21 10:26:21 +01:00
Will Deacon
52bf3ffd0b 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@: Align KVM_VM_TYPE_ARM_PROTECTED value with android13 kernels]
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: Iabcd03865aed4a41637597ac247897fd185bfc4d
2022-10-21 10:26:20 +01:00
Will Deacon
2818b69cdf ANDROID: KVM: arm64: Expose memory sharing hypercalls to protected guests
Extend our KVM "vendor" hypercalls to expose three new hypercalls to
protected guests for the purpose of opening and closing shared memory
windows with the host:

  MEMINFO:	Query the stage-2 page size (i.e. the minimum granule at
		which memory can be shared)

  MEM_SHARE:	Share a page RWX with the host, faulting the page in if
  		necessary.

  MEM_UNSHARE:	Unshare a page with the host. Subsequent host accesses
		to the page will result in a fault being injected by the
		hypervisor.

Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I80fe8af0bc0b3a40460c5065eabe26b1d9f634f2
2022-10-21 10:26:20 +01:00
Will Deacon
a6e11005e5 ANDROID: KVM: arm64: Reformat/beautify PTP hypercall documentation
The PTP hypercall documentation doesn't produce the best-looking table
when formatting in HTML as all of the return value definitions end up
on the same line.

Reformat the PTP hypercall documentation to follow the formatting used
by hypercalls.rst.

Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: Ic77cea5a621a9278d098afd80ef4c0e125760814
2022-10-21 10:26:20 +01:00
Will Deacon
48998724f8 ANDROID: KVM: arm64: Document the KVM/arm64-specific calls in hypercalls.rst
KVM/arm64 makes use of the SMCCC "Vendor Specific Hypervisor Service
Call Range" to expose KVM-specific hypercalls to guests in a
discoverable and extensible fashion.

Document the existence of this interface and the discovery hypercall.

Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I5754589b1b695828eab7cb41c7aa6a0fb55ad273
2022-10-21 10:26:20 +01:00
Will Deacon
82a33bfcac ANDROID: KVM: arm64: Rename firmware pseudo-register documentation file
In preparation for describing the guest view of KVM/arm64 hypercalls in
hypercalls.rst, move the existing contents of the file concerning the
firmware pseudo-registers elsewhere.

Cc: Raghavendra Rao Ananta <rananta@google.com>
Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: Ie8931290b291c0ffd2f1f11265babe2475972868
2022-10-21 10:26:20 +01:00
Will Deacon
dbd3c00d77 ANDROID: KVM: arm64: Extend memory sharing to allow guest-to-host transitions
A guest that can only operate on private memory is pretty useless, as it
has no way to share buffers with the host for things like virtio.

Extend our memory protection mechanisms to support the sharing and
unsharing of guest pages from the guest to the host. For now, this
functionality is unused but will later be exposed to the guest via
hypercalls.

Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I6b0d6f63348f3a2a847acf4d7bb87bd6e9742af0
2022-10-21 10:26:20 +01:00
Will Deacon
66751b515c ANDROID: KVM: arm64: Avoid BBM when changing only s/w bits in Stage-2 PTE
Break-before-make (BBM) can be expensive, as transitioning via an
invalid mapping (i.e. the "break" step) requires the completion of TLB
invalidation and can also cause other agents to fault concurrently on
the invalid mapping.

Since BBM is not required when changing only the software bits of a PTE,
avoid the sequence in this case and just update the PTE directly.

Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I91ec043a75154fa2ca732f5269c6ae1bceea4a93
2022-10-21 10:26:19 +01:00
Will Deacon
e815dfc6c6 ANDROID: KVM: arm64: Support TLB invalidation in guest context
Typically, TLB invalidation of guest stage-2 mappings using nVHE is
performed by a hypercall originating from the host. For the invalidation
instruction to be effective, therefore, __tlb_switch_to_{guest,host}()
swizzle the active stage-2 context around the TLBI instruction.

With guest-to-host memory sharing and unsharing hypercalls originating
from the guest under pKVM, there is now a need to support both guest
and host VMID invalidations issued from guest context.

Replace the __tlb_switch_to_{guest,host}() functions with a more general
{enter,exit}_vmid_context() implementation which supports being invoked
from guest context and acts as a no-op if the target context matches the
running context.

Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I92c6f48eb4c4b6286b930c2f0cda245bccc1927b
2022-10-21 10:26:19 +01:00
Quentin Perret
acf6566449 ANDROID: KVM: arm64: Inject SIGSEGV on illegal accesses
The pKVM hypervisor will currently panic if the host tries to access
memory that it doesn't own (e.g. protected guest memory). Sadly, as
guest memory can still be mapped into the VMM's address space, userspace
can trivially crash the kernel/hypervisor by poking into guest memory.

To prevent this, inject the abort back in the host with S1PTW set in the
ESR, hence allowing the host to differentiate this abort from normal
userspace faults and inject a SIGSEGV cleanly.

Signed-off-by: Quentin Perret <qperret@google.com>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I09ee54fbf4c202dc3ac2e1b5eea264d4dc84f613
2022-10-21 10:26:19 +01:00
Quentin Perret
c99d2131c5 ANDROID: KVM: arm64: Refactor enter_exception64()
In order to simplify the injection of exceptions in the host in pkvm
context, let's factor out of enter_exception64() the code calculating
the exception offset from VBAR_EL1 and the cpsr.

Signed-off-by: Quentin Perret <qperret@google.com>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I50a2510b59311717c6e17ea4e45fc634b4b43073
2022-10-21 10:26:19 +01:00
Quentin Perret
c0bc03b025 ANDROID: KVM: arm64: Add is_pkvm_initialized() helper
Add a helper allowing to check when the pkvm static key is enabled to
ease the introduction of pkvm hooks in other parts of the code.

Signed-off-by: Quentin Perret <qperret@google.com>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I8995021768def73bd7636a84059bdc43fa7ab2fc
2022-10-21 10:26:19 +01:00
Will Deacon
6392b3a883 ANDROID: KVM: arm64: Don't expose TLBI hypercalls after de-privilege
Now that TLBI invalidation is handled entirely at EL2 for both protected
and non-protected guests when protected KVM has initialised, unplug the
unused TLBI hypercalls.

Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I50ad4cb930c43f88e00320e47b358613224dd1cc
2022-10-21 10:26:18 +01:00
Fuad Tabba
1d5bbb9c14 ANDROID: KVM: arm64: Handle PSCI for protected VMs in EL2
Add PSCI 1.1 support for protected VMs at EL2.

Signed-off-by: Fuad Tabba <tabba@google.com>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I0e23fdc1f2d62563fd806400aff70be49337dd22
2022-10-21 10:26:18 +01:00
Fuad Tabba
421d5cc5c4 ANDROID: KVM: arm64: Factor out vcpu_reset code for core registers and PSCI
Factor out logic that resets a vcpu's core registers, including
additional PSCI handling. This code will be reused when resetting
VMs in protected mode.

Signed-off-by: Fuad Tabba <tabba@google.com>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I22468be1d382e05e39557e32ea09a023173dbf48
2022-10-21 10:26:18 +01:00
Fuad Tabba
fcd82a2bcf ANDROID: KVM: arm64: Move some kvm_psci functions to a shared header
Move some PSCI functions and macros to a shared header to be used
by hyp in protected mode.

No functional change intended.

Signed-off-by: Fuad Tabba <tabba@google.com>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: Ibe84564f423cd0281f3dc33d9801b474fe8f2db9
2022-10-21 10:26:18 +01:00
Fuad Tabba
41791a8c00 ANDROID: KVM: arm64: Move pstate reset values to kvm_arm.h
Move the macro defines of the pstate reset values to a shared
header to be used by hyp in protected mode.

No functional change intended.

Signed-off-by: Fuad Tabba <tabba@google.com>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: Ib98734d2ced07a958427c6552a9c22d159b85ad1
2022-10-21 10:26:18 +01:00
Fuad Tabba
e781b3cf0f ANDROID: KVM: arm64: Add HVC handling for protected guests at EL2
Rather than forwarding guest hypercalls back to the host for handling,
implement some basic handling at EL2 which will later be extending to
provide additional functionality such as PSCI.

Signed-off-by: Fuad Tabba <tabba@google.com>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I14613c416078818b25bb29ed8899d7b71f8c40cc
2022-10-21 10:26:18 +01:00
Marc Zyngier
c63694a9a0 ANDROID: KVM: arm64: Track the SVE state in the hypervisor vcpu structure
When dealing with a guest with SVE enabled, make sure the host SVE
state is pinned at EL2 S1, and that the hypervisor vCPU state is
correctly initialised (and then unpinned on teardown).

Signed-off-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: Ic4d0ef9a6124701026cd56f6725ab4737857ed5b
2022-10-21 10:26:17 +01:00
Fuad Tabba
36e2fd0eac ANDROID: KVM: arm64: Initialize hypervisor vm state at EL2
Do not rely on the state of the vm as provided by the host, but
initialize it instead at EL2 to a known good and safe state.

Signed-off-by: Fuad Tabba <tabba@google.com>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I8e0e9fd7cdf0b5b4d422260be06920d0550d5f91
2022-10-21 10:26:17 +01:00
Fuad Tabba
478b1a78e7 ANDROID: KVM: arm64: Refactor kvm_vcpu_enable_ptrauth() for hyp use
Move kvm_vcpu_enable_ptrauth() to a shared header to be used by
hyp in protected mode.

No functional change intended.

Signed-off-by: Fuad Tabba <tabba@google.com>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: Idb90ae3228fc3acb1fe310227a4f606f47b026a5
2022-10-21 10:26:17 +01:00
Marc Zyngier
f400a5aadd ANDROID: KVM: arm64: Do not update virtual timer state for protected VMs
Protected vCPUs always run with a virtual counter offset of 0, so don't
bother trying to update it from the host.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I02a30687e36886aa5c97439874e3e4cf066fe6e7
2022-10-21 10:26:17 +01:00
Marc Zyngier
221497c558 ANDROID: KVM: arm64: Move vgic state between host and hypervisor vcpu structures
Since the world switch vgic code operates on the hypervisor data
structure, move the state back and forth between the host and
hypervisor vcpu.

This is currently limited to the VMCR and APR registers, but further
patches will deal with the rest of the state.

Note that some of the control settings (such as SRE) are always
set to the same value. This will eventually be moved to initialisation
time for the hypervisor structures.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I8a3a9009ce3408fe06ea272504f4f71c3d47b7bf
2022-10-21 10:26:17 +01:00
Fuad Tabba
c86b8a4a5e ANDROID: KVM: arm64: Add EL2 entry/exit handlers for pKVM guests
Introduce separate El2 entry/exit handlers for protected and
non-protected guests under pKVM and hook up the protected handlers to
expose the minimum amount of data to the host required for EL1 handling.

Signed-off-by: Fuad Tabba <tabba@google.com>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I6788edabb3849b661c05c4ce63ab17198f4ed1cd
2022-10-21 10:26:17 +01:00
Marc Zyngier
5c41ce5227 ANDROID: KVM: arm64: Donate memory to protected guests
Instead of sharing memory with protected guests, which still leaves the
host with r/w access, donate the underlying pages so that they are
unmapped from the host stage-2.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I3e0d1d31877acf3978e82350ebbe92136919507c
2022-10-21 10:26:16 +01:00
Marc Zyngier
2ab0cf79ec ANDROID: KVM: arm64: Force injection of a data abort on NISV MMIO exit
If a vcpu exits for a data abort with an invalid syndrome, the
expectations are that userspace has a chance to save the day if
it has requested to see such exits.

However, this is completely futile in the case of a protected VM,
as none of the state is available. In this particular case, inject
a data abort directly into the vcpu, consistent with what userspace
could do.

This also helps with pKVM, which discards all syndrome information when
forwarding data aborts that are not known to be MMIO.

Finally, hide the RETURN_NISV_IO_ABORT_TO_USER cap from userspace on
protected VMs, and document this tweak to the API.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: Ie081cf0b2fdd1ab374d479e3e355ab3cb536c960
2022-10-21 10:26:16 +01:00
Will Deacon
697fe62abb ANDROID: KVM: arm64: Advertise GICv3 sysreg interface to protected guests
Advertise the system register GICv3 CPU interface to protected guests
as that is the only supported configuration under pKVM.

Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: Iea2aeaae7776424727f6833c21597b6236284796
2022-10-21 10:26:16 +01:00
Fuad Tabba
82e11002e1 ANDROID: KVM: arm64: Fix initializing traps in protected mode
The values of the trapping registers for protected VMs should be
computed from the ground up, and not depend on potentially
preexisting values.

Moreover, non-protected VMs should not be restricted in protected
mode in the same manner as protected VMs.

Signed-off-by: Fuad Tabba <tabba@google.com>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I689c6d48e8ebb533a86b78ebd6e1a1416cb8729b
2022-10-21 10:26:16 +01:00
Fuad Tabba
cab2379b5e ANDROID: KVM: arm64: Move pkvm_vcpu_init_traps to hyp vcpu init
Move the initialization of traps to the initialization of the
hyp vcpu, and remove the associated hypercall.

No functional change intended.

Signed-off-by: Fuad Tabba <tabba@google.com>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I2e79a6cb494d9a778b46e481206d5c8fde6890fe
2022-10-21 10:26:16 +01:00
Fuad Tabba
d8b682176f ANDROID: KVM: arm64: Reset sysregs for protected VMs
Create a framework for resetting protected VM system registers to
their architecturally defined reset values.

No functional change intended as these are not hooked in yet.

Signed-off-by: Fuad Tabba <tabba@google.com>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: Id812d1bbe81c7c0a544aba91b35831f486c208ba
2022-10-21 10:26:16 +01:00
Fuad Tabba
e0eb426cfa ANDROID: KVM: arm64: Refactor reset_mpidr to extract its computation
Move the computation of the mpidr to its own function in a shared
header, as the computation will be used by hyp in protected mode.

No functional change intended.

Signed-off-by: Fuad Tabba <tabba@google.com>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I48c36ebb430c3322a6991eeb391d617903525304
2022-10-21 10:26:15 +01:00
Fuad Tabba
e545f7a8a9 ANDROID: KVM: arm64: Do not support MTE for protected VMs
Return an error (-EINVAL) if trying to enable MTE on a protected
vm.

Signed-off-by: Fuad Tabba <tabba@google.com>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I036282854169a341253869d67a3e55e6cec8f040
2022-10-21 10:26:15 +01:00
Fuad Tabba
b042ff6f1c ANDROID: KVM: arm64: Restrict protected VM capabilities
Restrict protected VM capabilities based on the
fixed-configuration for protected VMs.

No functional change intended in current KVM-supported modes
(nVHE, VHE).

Signed-off-by: Fuad Tabba <tabba@google.com>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: I1df873d512754207decf9eedb50135ee2ae76b29
2022-10-21 10:26:15 +01:00