Skip to content

crypto: ccp - Make sev_cmd_mutex more granular

Michael Roth linux-crypto 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest1 patch 4 repliesIn review
  2. v29 patches 10 repliesSuperseded
  3. v14 patches 6 repliesSuperseded

Changes in v3 from the cover letter

- drop all unnecessary refactorings to make patches more appropriate for 7.4 (Herbert, Sean)
- retest CCP both with and without kvm/queue in-place conversion support present, re-verify no deadlocks/regressions. Testing done primarilly with the following kselftest:

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/1crypto: ccp - Make usage of sev_cmd_mutex more granulardrivers/crypto/ccp/sev-dev.c+76 -253 replies

Reviews trailers per patch

The patch has a Reviewed-by or Acked-by.

PatchSean ChristophersonTom Lendacky
1/1T-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 0/1] crypto: ccp - Make sev_cmd_mutex more granular

This patchset is also available at:

https://github.com/amdese/linux/commits/ccp-mutex-rework-v3

and is based on cryptodev-2.6 master (178aff4cf425).

v1: https://lore.kernel.org/linux-crypto/[email protected]/
v2: https://lore.kernel.org/linux-crypto/[email protected]/
v3:
- drop all unnecessary refactorings to make patches more appropriate for 7.4 (Herbert, Sean)
- retest CCP both with and without kvm/queue in-place conversion support present, re-verify no deadlocks/regressions. Testing done primarilly with the following kselftest:

     https://github.com/AMDESE/linux/commit/33ddcbd756b3db5bd2bd5737e48c9084e715cd38

- rebase on latest cryptodev master (178aff4cf425)

OVERVIEW
--------

The current code makes very coarse usage of the sev_cmd_mutex; for SEV firmware ioctls, it is essentially taken upon entry, and ends up wrapping a lot of potentially time-consuming prep/cleanup work that may need to be done before/after issuing the actual firmware call, which is the main thing the mutex is meant to protect.

Additionally, some of that prep work involves copy_from_user()/copy_to_user() calls which can generate page faults and unecessarily lead to potential deadlock scenarios. No known case exists in current upstream, but with the upcoming KVM/guest_memfd support for in-place conversion of the same PFN between shared/private state (which is currently targeted for kernel 7.4), a special fault handler is added that could theoretically deadlock if a malicious user tries to use guest_memfd pages as the source/target of target of said copy_from_user()/copy_to_user() scenarios[1].

So this series is a prereq to enabling the above-mentioned KVM/guest_memfd in-place conversion support on SNP-enabled hosts, as well as a cleanup for SEV ioctls in general.

Thank you to Sean for suggesting this approach and Ackerley for wrangling the changes into a (hopefully) presentable patchset.

REFERENCES
----------

[1] https://lore.kernel.org/kvm/[email protected]/

Thanks!

-Mike

----------------------------------------------------------------
Michael Roth (1):
crypto: ccp - Make usage of sev_cmd_mutex more granular

 drivers/crypto/ccp/sev-dev.c | 101 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 76 insertions(+), 25 deletions(-)