Link: https://lore.kernel.org/r/20260217200002.683975158@linuxfoundation.org Tested-by: Florian Fainelli <florian.fainelli@broadcom.com> Tested-by: Takeshi Ogasawara <takeshi.ogasawara@futuring-girl.com> Tested-by: Peter Schneider <pschneider1968@googlemail.com> Tested-by: Jon Hunter <jonathanh@nvidia.com> Tested-by: Salvatore Bonaccorso <carnil@debian.org> Tested-by: Brett A C Sheffield <bacs@librecast.net> Tested-by: Mark Brown <broonie@kernel.org> Tested-by: Luna Jernberg <droidbittin@gmail.com> Tested-by: Ronald Warsow <rwarsow@gmx.de> Tested-by: Justin M. Forbes <jforbes@fedoraproject.org> Tested-by: Ron Economos <re@w6rz.net> Tested-by: Miguel Ojeda <ojeda@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
51 lines
1.2 KiB
C
51 lines
1.2 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Implementation of the memory encryption/decryption API.
|
|
*
|
|
* Since the low-level details of the operation depend on the
|
|
* Confidential Computing environment (e.g. pKVM, CCA, ...), this just
|
|
* acts as a top-level dispatcher to whatever hooks may have been
|
|
* registered.
|
|
*
|
|
* Author: Will Deacon <will@kernel.org>
|
|
* Copyright (C) 2024 Google LLC
|
|
*
|
|
* "Hello, boils and ghouls!"
|
|
*/
|
|
|
|
#include <linux/bug.h>
|
|
#include <linux/compiler.h>
|
|
#include <linux/err.h>
|
|
#include <linux/mm.h>
|
|
|
|
#include <asm/mem_encrypt.h>
|
|
|
|
static const struct arm64_mem_crypt_ops *crypt_ops;
|
|
|
|
int arm64_mem_crypt_ops_register(const struct arm64_mem_crypt_ops *ops)
|
|
{
|
|
if (WARN_ON(crypt_ops))
|
|
return -EBUSY;
|
|
|
|
crypt_ops = ops;
|
|
return 0;
|
|
}
|
|
|
|
int set_memory_encrypted(unsigned long addr, int numpages)
|
|
{
|
|
if (likely(!crypt_ops) || WARN_ON(!PAGE_ALIGNED(addr)))
|
|
return 0;
|
|
|
|
return crypt_ops->encrypt(addr, numpages);
|
|
}
|
|
EXPORT_SYMBOL_GPL(set_memory_encrypted);
|
|
|
|
int set_memory_decrypted(unsigned long addr, int numpages)
|
|
{
|
|
if (likely(!crypt_ops) || WARN_ON(!PAGE_ALIGNED(addr)))
|
|
return 0;
|
|
|
|
return crypt_ops->decrypt(addr, numpages);
|
|
}
|
|
EXPORT_SYMBOL_GPL(set_memory_decrypted);
|