1 // SPDX-License-Identifier: GPL-2.0-only
3 * Implementation of the memory encryption/decryption API.
5 * Since the low-level details of the operation depend on the
6 * Confidential Computing environment (e.g. pKVM, CCA, ...), this just
7 * acts as a top-level dispatcher to whatever hooks may have been
10 * Author: Will Deacon <will@kernel.org>
11 * Copyright (C) 2024 Google LLC
13 * "Hello, boils and ghouls!"
16 #include <linux/bug.h>
17 #include <linux/compiler.h>
18 #include <linux/err.h>
21 #include <asm/mem_encrypt.h>
23 static const struct arm64_mem_crypt_ops
*crypt_ops
;
25 int arm64_mem_crypt_ops_register(const struct arm64_mem_crypt_ops
*ops
)
27 if (WARN_ON(crypt_ops
))
34 int set_memory_encrypted(unsigned long addr
, int numpages
)
36 if (likely(!crypt_ops
) || WARN_ON(!PAGE_ALIGNED(addr
)))
39 return crypt_ops
->encrypt(addr
, numpages
);
41 EXPORT_SYMBOL_GPL(set_memory_encrypted
);
43 int set_memory_decrypted(unsigned long addr
, int numpages
)
45 if (likely(!crypt_ops
) || WARN_ON(!PAGE_ALIGNED(addr
)))
48 return crypt_ops
->decrypt(addr
, numpages
);
50 EXPORT_SYMBOL_GPL(set_memory_decrypted
);