Commit e9d1d2bb authored by Tom Lendacky's avatar Tom Lendacky Committed by Borislav Petkov
Browse files

treewide: Replace the use of mem_encrypt_active() with cc_platform_has()



Replace uses of mem_encrypt_active() with calls to cc_platform_has() with
the CC_ATTR_MEM_ENCRYPT attribute.

Remove the implementation of mem_encrypt_active() across all arches.

For s390, since the default implementation of the cc_platform_has()
matches the s390 implementation of mem_encrypt_active(), cc_platform_has()
does not need to be implemented in s390 (the config option
ARCH_HAS_CC_PLATFORM is not set).

Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20210928191009.32551-9-bp@alien8.de
parent 6283f2ef
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -10,11 +10,6 @@

#include <asm/svm.h>

static inline bool mem_encrypt_active(void)
{
	return is_secure_guest();
}

static inline bool force_dma_unencrypted(struct device *dev)
{
	return is_secure_guest();
+3 −2
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@

#include <linux/mm.h>
#include <linux/memblock.h>
#include <linux/cc_platform.h>
#include <asm/machdep.h>
#include <asm/svm.h>
#include <asm/swiotlb.h>
@@ -63,7 +64,7 @@ void __init svm_swiotlb_init(void)

int set_memory_encrypted(unsigned long addr, int numpages)
{
	if (!mem_encrypt_active())
	if (!cc_platform_has(CC_ATTR_MEM_ENCRYPT))
		return 0;

	if (!PAGE_ALIGNED(addr))
@@ -76,7 +77,7 @@ int set_memory_encrypted(unsigned long addr, int numpages)

int set_memory_decrypted(unsigned long addr, int numpages)
{
	if (!mem_encrypt_active())
	if (!cc_platform_has(CC_ATTR_MEM_ENCRYPT))
		return 0;

	if (!PAGE_ALIGNED(addr))
+0 −2
Original line number Diff line number Diff line
@@ -4,8 +4,6 @@

#ifndef __ASSEMBLY__

static inline bool mem_encrypt_active(void) { return false; }

int set_memory_encrypted(unsigned long addr, int numpages);
int set_memory_decrypted(unsigned long addr, int numpages);

+0 −5
Original line number Diff line number Diff line
@@ -96,11 +96,6 @@ static inline void mem_encrypt_free_decrypted_mem(void) { }

extern char __start_bss_decrypted[], __end_bss_decrypted[], __start_bss_decrypted_unused[];

static inline bool mem_encrypt_active(void)
{
	return sme_me_mask;
}

static inline u64 sme_get_me_mask(void)
{
	return sme_me_mask;
+7 −2
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@
#include <linux/start_kernel.h>
#include <linux/io.h>
#include <linux/memblock.h>
#include <linux/mem_encrypt.h>
#include <linux/cc_platform.h>
#include <linux/pgtable.h>

#include <asm/processor.h>
@@ -284,8 +284,13 @@ unsigned long __head __startup_64(unsigned long physaddr,
	 * The bss section will be memset to zero later in the initialization so
	 * there is no need to zero it after changing the memory encryption
	 * attribute.
	 *
	 * This is early code, use an open coded check for SME instead of
	 * using cc_platform_has(). This eliminates worries about removing
	 * instrumentation or checking boot_cpu_data in the cc_platform_has()
	 * function.
	 */
	if (mem_encrypt_active()) {
	if (sme_get_me_mask()) {
		vaddr = (unsigned long)__start_bss_decrypted;
		vaddr_end = (unsigned long)__end_bss_decrypted;
		for (; vaddr < vaddr_end; vaddr += PMD_SIZE) {
Loading