[PATCH v4 0/6] Support SEV firmware hotloading

Dionna Glaze posted 6 patches 2 weeks, 5 days ago
arch/x86/kvm/svm/sev.c                      |  10 +-
drivers/base/firmware_loader/sysfs_upload.c |  16 +-
drivers/crypto/ccp/Kconfig                  |   2 +
drivers/crypto/ccp/Makefile                 |   1 +
drivers/crypto/ccp/sev-dev.c                |  83 ++++-
drivers/crypto/ccp/sev-dev.h                |  31 ++
drivers/crypto/ccp/sev-fw.c                 | 330 ++++++++++++++++++++
include/linux/psp-sev.h                     |  26 ++
include/uapi/linux/psp-sev.h                |   5 +
9 files changed, 480 insertions(+), 24 deletions(-)
create mode 100644 drivers/crypto/ccp/sev-fw.c
[PATCH v4 0/6] Support SEV firmware hotloading
Posted by Dionna Glaze 2 weeks, 5 days ago
The SEV-SNP API specifies a command for hotloading the SEV firmware.
when no SEV or SEV-ES guests are running. The firmware hotloading
support is dependent on the firmware_upload API for better ease-of-use,
and to not necessarily require SEV firmware hotloading support when
building the ccp driver.

For safety, there are steps the kernel should take before allowing a
firmware to be committed:

1. Writeback invalidate all.
2. Data fabric flush.
3. All GCTX pages must be updated successfully with SNP_GUEST_STATUS

The snp_context_create function had the possibility to leak GCTX pages,
so the first patch fixes that bug in KVM.

The ccp driver must continue to be unloadable, so the second patch in
this series fixes a cyclic refcount bug in firmware_loader.

The third patch tracks GCTX pages created and bound to ASIDs at the end
of __sev_do_cmd_locked. These pages are necessary to know at firmware
update time since any running VM must have their context pages updated
before the firmware can be committed.

The fourth patch adds SEV_CMD_DOWNLOAD_FIRMWARE_EX support with its
required cache invalidation steps, but without a means of calling it
from user space.

The fifth patch uses the added command from an instantiation of the
firmware_upload API. When the firmware successfully updates, the GCTX
pages are all refreshed. If any single page's update fails, the driver
treats itself as if the firmware were in a bad state and needs an
immediate restore. All commands that are not DOWNLOAD_FIRMWARE_EX will
fail with RESTORE_REQUIRED, similar to SEV FW on older PSP bootloaders.

The sixth patch avoids platform initialization for KVM VM guests when
vm_type is not legacy SEV/SEV-ES.

The KVM_EXIT for requesting certificates on extended guest request is
not part of this patch series. Any such support must be designed with
races between SNP_COMMIT and servicing extended guest requests such that
the REPORTED_TCB in an attestation_report always correctly corresponds
to the certificates returned by the extended guest request handler.

Changes from v3:
  - Removed added init_args field since it was duplicative of probe.
  - Split ccp change into three changes.
Changes from v2:
  - Fix download_firmware_ex struct definition to be the proper size,
    and clear to 0 before using. Thanks to Alexey Kardashevskiy.
Changes from v1:
  - Fix double-free with incorrect goto label on error.
  - checkpatch cleanup.
  - firmware_loader comment cleanup and one-use local variable inlining.

CC: Sean Christopherson <seanjc@google.com>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Ingo Molnar <mingo@redhat.com>
CC: Borislav Petkov <bp@alien8.de>
CC: Dave Hansen <dave.hansen@linux.intel.com>
CC: Ashish Kalra <ashish.kalra@amd.com>
CC: Tom Lendacky <thomas.lendacky@amd.com>
CC: John Allen <john.allen@amd.com>
CC: Herbert Xu <herbert@gondor.apana.org.au>
CC: "David S. Miller" <davem@davemloft.net>
CC: Michael Roth <michael.roth@amd.com>
CC: Luis Chamberlain <mcgrof@kernel.org>
CC: Russ Weight <russ.weight@linux.dev>
CC: Danilo Krummrich <dakr@redhat.com>
CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
CC: "Rafael J. Wysocki" <rafael@kernel.org>
CC: Tianfei zhang <tianfei.zhang@intel.com>
CC: Alexey Kardashevskiy <aik@amd.com>

Dionna Glaze (6):
  kvm: svm: Fix gctx page leak on invalid inputs
  firmware_loader: Move module refcounts to allow unloading
  crypto: ccp: Track GCTX through sev commands
  crypto: ccp: Add DOWNLOAD_FIRMWARE_EX support
  crypto: ccp: Use firmware_upload API for SNP firmware
  KVM: SVM: Delay legacy platform initialization on SNP

 arch/x86/kvm/svm/sev.c                      |  10 +-
 drivers/base/firmware_loader/sysfs_upload.c |  16 +-
 drivers/crypto/ccp/Kconfig                  |   2 +
 drivers/crypto/ccp/Makefile                 |   1 +
 drivers/crypto/ccp/sev-dev.c                |  83 ++++-
 drivers/crypto/ccp/sev-dev.h                |  31 ++
 drivers/crypto/ccp/sev-fw.c                 | 330 ++++++++++++++++++++
 include/linux/psp-sev.h                     |  26 ++
 include/uapi/linux/psp-sev.h                |   5 +
 9 files changed, 480 insertions(+), 24 deletions(-)
 create mode 100644 drivers/crypto/ccp/sev-fw.c

-- 
2.47.0.199.ga7371fff76-goog