Loading...
Note: File does not exist in v4.6.
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Implementation of the memory encryption/decryption API.
4 *
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
8 * registered.
9 *
10 * Author: Will Deacon <will@kernel.org>
11 * Copyright (C) 2024 Google LLC
12 *
13 * "Hello, boils and ghouls!"
14 */
15
16#include <linux/bug.h>
17#include <linux/compiler.h>
18#include <linux/err.h>
19#include <linux/mm.h>
20
21#include <asm/mem_encrypt.h>
22
23static const struct arm64_mem_crypt_ops *crypt_ops;
24
25int arm64_mem_crypt_ops_register(const struct arm64_mem_crypt_ops *ops)
26{
27 if (WARN_ON(crypt_ops))
28 return -EBUSY;
29
30 crypt_ops = ops;
31 return 0;
32}
33
34int set_memory_encrypted(unsigned long addr, int numpages)
35{
36 if (likely(!crypt_ops) || WARN_ON(!PAGE_ALIGNED(addr)))
37 return 0;
38
39 return crypt_ops->encrypt(addr, numpages);
40}
41EXPORT_SYMBOL_GPL(set_memory_encrypted);
42
43int set_memory_decrypted(unsigned long addr, int numpages)
44{
45 if (likely(!crypt_ops) || WARN_ON(!PAGE_ALIGNED(addr)))
46 return 0;
47
48 return crypt_ops->decrypt(addr, numpages);
49}
50EXPORT_SYMBOL_GPL(set_memory_decrypted);