Skip to contentSkip to conversation

treewide: Rename "unencrypted" to "decrypted"

PATCH In review Borislav Petkov 9 participants 18 messages Mar 17, 2020 – Mar 19, 2020

Subsystems (6)
x86 PowerPC s390 x86 MM +2 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 treewide: Rename "unencrypted" to "decrypted"

Hi all,

this hasn't been fully tested yet but it is mechanical rename only so there shouldn't be any problems (famous last words :-)).

I'll run it through the randconfig bench today and take it through tip if there are no objections.

Thx.

---

Back then when the whole SME machinery started getting mainlined, it was agreed that for simplicity, clarity and sanity's sake, the terms denoting encrypted and not-encrypted memory should be "encrypted" and "decrypted". And the majority of the code sticks to that convention except those two. So rename them.

No functional changes.

---
 arch/powerpc/platforms/pseries/Kconfig |  2 +-
 arch/s390/Kconfig                      |  2 +-
 arch/x86/Kconfig                       |  2 +-
 arch/x86/mm/mem_encrypt.c              |  4 ++--
 include/linux/dma-direct.h             |  8 ++++----
 kernel/dma/Kconfig                     |  2 +-
 kernel/dma/direct.c                    | 14 +++++++-------
 kernel/dma/mapping.c                   |  2 +-
 8 files changed, 18 insertions(+), 18 deletions(-)
arch/powerpc/platforms/pseries/Kconfig +1 -1
index 24c18362e5ea..a78e2c3e1d92 100644
@@ -151,7 +151,7 @@ config PPC_SVM
 	depends on PPC_PSERIES
 	select SWIOTLB
 	select ARCH_HAS_MEM_ENCRYPT
-	select ARCH_HAS_FORCE_DMA_UNENCRYPTED
+	select ARCH_HAS_FORCE_DMA_DECRYPTED
 	help
 	 There are certain POWER platforms which support secure guests using
 	 the Protected Execution Facility, with the help of an Ultravisor
arch/s390/Kconfig +1 -1
index 8abe77536d9d..ab1dbb7415b4 100644
@@ -192,7 +192,7 @@ config S390
 	select VIRT_CPU_ACCOUNTING
 	select ARCH_HAS_SCALED_CPUTIME
 	select HAVE_NMI
-	select ARCH_HAS_FORCE_DMA_UNENCRYPTED
+	select ARCH_HAS_FORCE_DMA_DECRYPTED
 	select SWIOTLB
 	select GENERIC_ALLOCATOR
 
arch/x86/Kconfig +1 -1
index beea77046f9b..2ae904f505e1 100644
@@ -1525,7 +1525,7 @@ config AMD_MEM_ENCRYPT
 	depends on X86_64 && CPU_SUP_AMD
 	select DYNAMIC_PHYSICAL_MASK
 	select ARCH_USE_MEMREMAP_PROT
-	select ARCH_HAS_FORCE_DMA_UNENCRYPTED
+	select ARCH_HAS_FORCE_DMA_DECRYPTED
 	---help---
 	  Say yes to enable support for the encryption of system memory.
 	  This requires an AMD processor that supports Secure Memory
arch/x86/mm/mem_encrypt.c +2 -2
index a03614bd3e1a..66d09f269e6d 100644
@@ -350,8 +350,8 @@ bool sev_active(void)
 	return sme_me_mask && sev_enabled;
 }
 
-/* Override for DMA direct allocation check - ARCH_HAS_FORCE_DMA_UNENCRYPTED */
-bool force_dma_unencrypted(struct device *dev)
+/* Override for DMA direct allocation check - ARCH_HAS_FORCE_DMA_DECRYPTED */
+bool force_dma_decrypted(struct device *dev)
 {
 	/*
 	 * For SEV, all DMA must be to unencrypted addresses.
include/linux/dma-direct.h +4 -4
index 24b8684aa21d..9f955844e9c7 100644
@@ -26,14 +26,14 @@ static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dev_addr)
 }
 #endif /* !CONFIG_ARCH_HAS_PHYS_TO_DMA */
 
-#ifdef CONFIG_ARCH_HAS_FORCE_DMA_UNENCRYPTED
-bool force_dma_unencrypted(struct device *dev);
+#ifdef CONFIG_ARCH_HAS_FORCE_DMA_DECRYPTED
+bool force_dma_decrypted(struct device *dev);
 #else
-static inline bool force_dma_unencrypted(struct device *dev)
+static inline bool force_dma_decrypted(struct device *dev)
 {
 	return false;
 }
-#endif /* CONFIG_ARCH_HAS_FORCE_DMA_UNENCRYPTED */
+#endif /* CONFIG_ARCH_HAS_FORCE_DMA_DECRYPTED */
 
 /*
  * If memory encryption is supported, phys_to_dma will set the memory encryption
kernel/dma/Kconfig +1 -1
index 4c103a24e380..55c4147bb2b1 100644
@@ -51,7 +51,7 @@ config ARCH_HAS_SYNC_DMA_FOR_CPU_ALL
 config ARCH_HAS_DMA_PREP_COHERENT
 	bool
 
-config ARCH_HAS_FORCE_DMA_UNENCRYPTED
+config ARCH_HAS_FORCE_DMA_DECRYPTED
 	bool
 
 config DMA_NONCOHERENT_CACHE_SYNC
kernel/dma/direct.c +7 -7
index ac7956c38f69..a0576c0ccacd 100644
@@ -26,7 +26,7 @@ unsigned int zone_dma_bits __ro_after_init = 24;
 static inline dma_addr_t phys_to_dma_direct(struct device *dev,
 		phys_addr_t phys)
 {
-	if (force_dma_unencrypted(dev))
+	if (force_dma_decrypted(dev))
 		return __phys_to_dma(dev, phys);
 	return phys_to_dma(dev, phys);
 }
@@ -49,7 +49,7 @@ static gfp_t __dma_direct_optimal_gfp_mask(struct device *dev, u64 dma_mask,
 {
 	u64 dma_limit = min_not_zero(dma_mask, dev->bus_dma_limit);
 
-	if (force_dma_unencrypted(dev))
+	if (force_dma_decrypted(dev))
 		*phys_limit = __dma_to_phys(dev, dma_limit);
 	else
 		*phys_limit = dma_to_phys(dev, dma_limit);
@@ -138,7 +138,7 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
 		return NULL;
 
 	if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) &&
-	    !force_dma_unencrypted(dev)) {
+	    !force_dma_decrypted(dev)) {
 		/* remove any dirty cache lines on the kernel alias */
 		if (!PageHighMem(page))
 			arch_dma_prep_coherent(page, size);
@@ -179,7 +179,7 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
 	}
 
 	ret = page_address(page);
-	if (force_dma_unencrypted(dev))
+	if (force_dma_decrypted(dev))
 		set_memory_decrypted((unsigned long)ret, 1 << get_order(size));
 
 	memset(ret, 0, size);
@@ -190,7 +190,7 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
 		ret = uncached_kernel_address(ret);
 	}
 done:
-	if (force_dma_unencrypted(dev))
+	if (force_dma_decrypted(dev))
 		*dma_handle = __phys_to_dma(dev, page_to_phys(page));
 	else
 		*dma_handle = phys_to_dma(dev, page_to_phys(page));
@@ -203,7 +203,7 @@ void dma_direct_free_pages(struct device *dev, size_t size, void *cpu_addr,
 	unsigned int page_order = get_order(size);
 
 	if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) &&
-	    !force_dma_unencrypted(dev)) {
+	    !force_dma_decrypted(dev)) {
 		/* cpu_addr is a struct page cookie, not a kernel address */
 		dma_free_contiguous(dev, cpu_addr, size);
 		return;
@@ -213,7 +213,7 @@ void dma_direct_free_pages(struct device *dev, size_t size, void *cpu_addr,
 	    dma_free_from_pool(cpu_addr, PAGE_ALIGN(size)))
 		return;
 
-	if (force_dma_unencrypted(dev))
+	if (force_dma_decrypted(dev))
 		set_memory_encrypted((unsigned long)cpu_addr, 1 << page_order);
 
 	if (IS_ENABLED(CONFIG_DMA_REMAP) && is_vmalloc_addr(cpu_addr))
kernel/dma/mapping.c +1 -1
index 98e3d873792e..dbd0605a39c5 100644
@@ -154,7 +154,7 @@ EXPORT_SYMBOL(dma_get_sgtable_attrs);
  */
 pgprot_t dma_pgprot(struct device *dev, pgprot_t prot, unsigned long attrs)
 {
-	if (force_dma_unencrypted(dev))
+	if (force_dma_decrypted(dev))
 		prot = pgprot_decrypted(prot);
 	if (dev_is_dma_coherent(dev) ||
 	    (IS_ENABLED(CONFIG_DMA_NONCOHERENT_CACHE_SYNC) &&
Signature · 7 lines
2.21.0

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#1 lore raw
Quoted 5 lines · Borislav Petkov

Back then when the whole SME machinery started getting mainlined, it was agreed that for simplicity, clarity and sanity's sake, the terms denoting encrypted and not-encrypted memory should be "encrypted" and "decrypted". And the majority of the code sticks to that convention except those two. So rename them.

Don't "unencrypted" and "decrypted" mean different things?

Unencrypted to me means "encryption was never used for this data".

Decrypted means "this was/is encrypted but here is a plaintext copy".

This, for instance:

kernel/dma/direct.c unsigned int zone_dma_bits __ro_after_init = 24; · line 30

Quoted 8 lines

+++ b/kernel/dma/direct.c

kernel/dma/direct.c +1 -1
@@ -26,7 +26,7 @@ unsigned int zone_dma_bits __ro_after_init = 24;
 static inline dma_addr_t phys_to_dma_direct(struct device *dev,
 		phys_addr_t phys)
 {
-	if (force_dma_unencrypted(dev))
+	if (force_dma_decrypted(dev))
 		return __phys_to_dma(dev, phys);

is referring to DMA that is not and never was encrypted. It's skipping the encryption altogether. There's no act of "decryption" anywhere.

This, on the other hand, seems named wrong to me:

Quoted 5 lines
(quoted diff) +0 -0
 /*
 * Macros to add or remove encryption attribute

*/
#define pgprot_encrypted(prot) __pgprot(__sme_set(pgprot_val(prot))) #define pgprot_decrypted(prot) __pgprot(__sme_clr(pgprot_val(prot)))

This seems like it would be better named pgprot_unencrypted().

maintainer
#2 lore raw
Quoted 7 lines · Dave Hansen
Quoted 5 lines · Borislav Petkov

Back then when the whole SME machinery started getting mainlined, it was agreed that for simplicity, clarity and sanity's sake, the terms denoting encrypted and not-encrypted memory should be "encrypted" and "decrypted". And the majority of the code sticks to that convention except those two. So rename them.

Quoted 5 lines

Don't "unencrypted" and "decrypted" mean different things?

Unencrypted to me means "encryption was never used for this data".

Decrypted means "this was/is encrypted but here is a plaintext copy".

Maybe but linguistical semantics is not the point here.

The idea is to represent a "binary" concept of memory being encrypted or memory being not encrypted. And at the time we decided to use "encrypted" and "decrypted" for those two things.

Do you see the need to differentiate a third "state", so to speak, of memory which was never encrypted?

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#3 lore raw
Quoted 9 lines · Borislav Petkov
Quoted 8 lines · Dave Hansen
Quoted 5 lines · Borislav Petkov

Back then when the whole SME machinery started getting mainlined, it was agreed that for simplicity, clarity and sanity's sake, the terms denoting encrypted and not-encrypted memory should be "encrypted" and "decrypted". And the majority of the code sticks to that convention except those two. So rename them.

Don't "unencrypted" and "decrypted" mean different things?

Quoted 8 lines
Quoted 3 lines

Unencrypted to me means "encryption was never used for this data".

Decrypted means "this was/is encrypted but here is a plaintext copy".

Maybe but linguistical semantics is not the point here.

The idea is to represent a "binary" concept of memory being encrypted or memory being not encrypted. And at the time we decided to use "encrypted" and "decrypted" for those two things.

Yeah, agreed. We're basically trying to name "!encrypted".

Quoted 2 lines

Do you see the need to differentiate a third "state", so to speak, of memory which was never encrypted?

No, there are just two states. I just think the "!encrypted" case should not be called "decrypted".

maintainer
#4 lore raw
Quoted 2 lines · Dave Hansen

No, there are just two states. I just think the "!encrypted" case should not be called "decrypted".

Yeah, we suck at naming - news at 11! :-)

I believe we even considered things like "encrypted" vs "clear" but that sucked too. ;-\

In any case, that ship has sailed now and having two as differently as possible looking words to denote the two "states" should be good enough for our purposes...

Oh well.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#5 lore raw
In reply to Dave Hansen
Quoted 19 lines · Dave Hansen
Quoted 9 lines · Borislav Petkov
Quoted 8 lines · Dave Hansen
Quoted 5 lines · Borislav Petkov

Back then when the whole SME machinery started getting mainlined, it was agreed that for simplicity, clarity and sanity's sake, the terms denoting encrypted and not-encrypted memory should be "encrypted" and "decrypted". And the majority of the code sticks to that convention except those two. So rename them.

Don't "unencrypted" and "decrypted" mean different things?

Quoted 8 lines
Quoted 3 lines

Unencrypted to me means "encryption was never used for this data".

Decrypted means "this was/is encrypted but here is a plaintext copy".

Maybe but linguistical semantics is not the point here.

The idea is to represent a "binary" concept of memory being encrypted or memory being not encrypted. And at the time we decided to use "encrypted" and "decrypted" for those two things.

Quoted 7 lines

Yeah, agreed. We're basically trying to name "!encrypted".

Quoted 2 lines

Do you see the need to differentiate a third "state", so to speak, of memory which was never encrypted?

No, there are just two states. I just think the "!encrypted" case should not be called "decrypted".

Nor do I, it's completely misleading.

#6 lore raw
In reply to Borislav Petkov
Quoted 14 lines · Borislav Petkov
Quoted 7 lines · Dave Hansen
Quoted 5 lines · Borislav Petkov

Back then when the whole SME machinery started getting mainlined, it was agreed that for simplicity, clarity and sanity's sake, the terms denoting encrypted and not-encrypted memory should be "encrypted" and "decrypted". And the majority of the code sticks to that convention except those two. So rename them.

Quoted 5 lines

Don't "unencrypted" and "decrypted" mean different things?

Unencrypted to me means "encryption was never used for this data".

Decrypted means "this was/is encrypted but here is a plaintext copy".

Quoted 8 lines

Maybe but linguistical semantics is not the point here.

The idea is to represent a "binary" concept of memory being encrypted or memory being not encrypted. And at the time we decided to use "encrypted" and "decrypted" for those two things.

Do you see the need to differentiate a third "state", so to speak, of memory which was never encrypted?

I think so.

encrypted data is something you can't use without having the key

decrypted data is the plaintext copy of something encrypted, so it might be of sensible nature.

unencrypted data can still be sensible, but nothing ever bothered to encrypt it in the first place.

So having this distinction is useful in terms of setting the context straight.

Thanks,

tglx
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

#7 lore raw
In reply to Borislav Petkov
I love your patch! Yet something to improve:

Hi Borislav,

I love your patch! Yet something to improve:

[auto build test ERROR on tip/x86/mm]
[cannot apply to linux/master powerpc/next s390/features tip/x86/core linus/master v5.6-rc6 next-20200317] [if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Borislav-Petkov/treewide-Rename-unencrypted-to-decrypted/20200318-015738
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 17c4a2ae15a7aaefe84bdb271952678c5c9cd8e1
config: s390-zfcpdump_defconfig (attached as .config)
compiler: s390-linux-gcc (GCC) 9.2.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=9.2.0 make.cross ARCH=s390

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

s390-linux-ld: kernel/dma/mapping.o: in function `dma_pgprot':
mapping.c:(.text+0x144): undefined reference to `force_dma_decrypted'
s390-linux-ld: kernel/dma/mapping.o: in function `dma_common_mmap':
mapping.c:(.text+0x1a4): undefined reference to `force_dma_decrypted'
s390-linux-ld: kernel/dma/direct.o: in function `dma_direct_get_required_mask':
direct.c:(.text+0xae): undefined reference to `force_dma_decrypted'
s390-linux-ld: kernel/dma/direct.o: in function `__dma_direct_alloc_pages':
direct.c:(.text+0x152): undefined reference to `force_dma_decrypted'

>> s390-linux-ld: direct.c:(.text+0x1e8): undefined reference to `force_dma_decrypted'

s390-linux-ld: kernel/dma/direct.o:direct.c:(.text+0x2e0): more undefined references to `force_dma_decrypted' follow

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#8 lore raw
In reply to Borislav Petkov
I love your patch! Yet something to improve:

Hi Borislav,

I love your patch! Yet something to improve:

[auto build test ERROR on tip/x86/mm]
[cannot apply to linux/master powerpc/next s390/features tip/x86/core linus/master v5.6-rc6 next-20200317] [if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Borislav-Petkov/treewide-Rename-unencrypted-to-decrypted/20200318-015738
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 17c4a2ae15a7aaefe84bdb271952678c5c9cd8e1
config: powerpc-defconfig (attached as .config)
compiler: powerpc64-linux-gcc (GCC) 9.2.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=9.2.0 make.cross ARCH=powerpc

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

powerpc64-linux-ld: warning: orphan section .gnu.hash' from linker stubs' being placed in section `.gnu.hash'
powerpc64-linux-ld: kernel/dma/mapping.o: in function `.dma_pgprot':

>> mapping.c:(.text+0xc5c): undefined reference to `.force_dma_decrypted'
   powerpc64-linux-ld: kernel/dma/mapping.o: in function `.dma_common_mmap':
   mapping.c:(.text+0xcfc): undefined reference to `.force_dma_decrypted'
   powerpc64-linux-ld: kernel/dma/direct.o: in function `.dma_direct_get_required_mask':
>> direct.c:(.text+0x920): undefined reference to `.force_dma_decrypted'
   powerpc64-linux-ld: kernel/dma/direct.o: in function `.__dma_direct_alloc_pages':
   direct.c:(.text+0x9fc): undefined reference to `.force_dma_decrypted'
>> powerpc64-linux-ld: direct.c:(.text+0xaa8): undefined reference to `.force_dma_decrypted'

powerpc64-linux-ld: kernel/dma/direct.o:direct.c:(.text+0xb28): more undefined references to `.force_dma_decrypted' follow

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

maintainer
#9 lore raw

PATCH 1/1 treewide: Rename "unencrypted" to "decrypted"

In reply to Borislav Petkov

Hi,

here's v2 with build breakage fixed on ppc and s390 (obviously I can't grep :-\) and commit message extended to explain more why.

Thx.

---
From: Borislav Petkov <[email protected]>
Date: Tue, 17 Mar 2020 12:03:05 +0100

Back then when the whole SME machinery started getting mainlined, it was agreed that for simplicity, clarity and sanity's sake, the terms denoting encrypted and not-encrypted memory should be "encrypted" and "decrypted". And the majority of the code sticks to that convention except those two. So rename them.

The intent of "encrypted" and "decrypted" is to represent the binary concept of memory which is encrypted and of memory which is not.

The further differentiation between decrypted and unencrypted memory is not needed in the code (for now) and therefore keep things simple by using solely the two terms.

No functional changes.

[ Convert forgotten s390 and ppc function variants. ]
---
 arch/powerpc/include/asm/mem_encrypt.h |  2 +-
 arch/powerpc/platforms/pseries/Kconfig |  2 +-
 arch/s390/Kconfig                      |  2 +-
 arch/s390/mm/init.c                    |  2 +-
 arch/x86/Kconfig                       |  2 +-
 arch/x86/mm/mem_encrypt.c              |  4 ++--
 include/linux/dma-direct.h             |  8 ++++----
 kernel/dma/Kconfig                     |  2 +-
 kernel/dma/direct.c                    | 14 +++++++-------
 kernel/dma/mapping.c                   |  2 +-
 10 files changed, 20 insertions(+), 20 deletions(-)
arch/powerpc/include/asm/mem_encrypt.h +1 -1
index ba9dab07c1be..f0705cd3b079 100644
@@ -15,7 +15,7 @@ static inline bool mem_encrypt_active(void)
 	return is_secure_guest();
 }
 
-static inline bool force_dma_unencrypted(struct device *dev)
+static inline bool force_dma_decrypted(struct device *dev)
 {
 	return is_secure_guest();
 }
arch/powerpc/platforms/pseries/Kconfig +1 -1
index 24c18362e5ea..a78e2c3e1d92 100644
@@ -151,7 +151,7 @@ config PPC_SVM
 	depends on PPC_PSERIES
 	select SWIOTLB
 	select ARCH_HAS_MEM_ENCRYPT
-	select ARCH_HAS_FORCE_DMA_UNENCRYPTED
+	select ARCH_HAS_FORCE_DMA_DECRYPTED
 	help
 	 There are certain POWER platforms which support secure guests using
 	 the Protected Execution Facility, with the help of an Ultravisor
arch/s390/Kconfig +1 -1
index 8abe77536d9d..ab1dbb7415b4 100644
@@ -192,7 +192,7 @@ config S390
 	select VIRT_CPU_ACCOUNTING
 	select ARCH_HAS_SCALED_CPUTIME
 	select HAVE_NMI
-	select ARCH_HAS_FORCE_DMA_UNENCRYPTED
+	select ARCH_HAS_FORCE_DMA_DECRYPTED
 	select SWIOTLB
 	select GENERIC_ALLOCATOR
 
arch/s390/mm/init.c +1 -1
index ac44bd76db4b..5fed85f9fea6 100644
@@ -157,7 +157,7 @@ int set_memory_decrypted(unsigned long addr, int numpages)
 }
 
 /* are we a protected virtualization guest? */
-bool force_dma_unencrypted(struct device *dev)
+bool force_dma_decrypted(struct device *dev)
 {
 	return is_prot_virt_guest();
 }
arch/x86/Kconfig +1 -1
index beea77046f9b..2ae904f505e1 100644
@@ -1525,7 +1525,7 @@ config AMD_MEM_ENCRYPT
 	depends on X86_64 && CPU_SUP_AMD
 	select DYNAMIC_PHYSICAL_MASK
 	select ARCH_USE_MEMREMAP_PROT
-	select ARCH_HAS_FORCE_DMA_UNENCRYPTED
+	select ARCH_HAS_FORCE_DMA_DECRYPTED
 	---help---
 	  Say yes to enable support for the encryption of system memory.
 	  This requires an AMD processor that supports Secure Memory
arch/x86/mm/mem_encrypt.c +2 -2
index a03614bd3e1a..66d09f269e6d 100644
@@ -350,8 +350,8 @@ bool sev_active(void)
 	return sme_me_mask && sev_enabled;
 }
 
-/* Override for DMA direct allocation check - ARCH_HAS_FORCE_DMA_UNENCRYPTED */
-bool force_dma_unencrypted(struct device *dev)
+/* Override for DMA direct allocation check - ARCH_HAS_FORCE_DMA_DECRYPTED */
+bool force_dma_decrypted(struct device *dev)
 {
 	/*
 	 * For SEV, all DMA must be to unencrypted addresses.
include/linux/dma-direct.h +4 -4
index 24b8684aa21d..9f955844e9c7 100644
@@ -26,14 +26,14 @@ static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dev_addr)
 }
 #endif /* !CONFIG_ARCH_HAS_PHYS_TO_DMA */
 
-#ifdef CONFIG_ARCH_HAS_FORCE_DMA_UNENCRYPTED
-bool force_dma_unencrypted(struct device *dev);
+#ifdef CONFIG_ARCH_HAS_FORCE_DMA_DECRYPTED
+bool force_dma_decrypted(struct device *dev);
 #else
-static inline bool force_dma_unencrypted(struct device *dev)
+static inline bool force_dma_decrypted(struct device *dev)
 {
 	return false;
 }
-#endif /* CONFIG_ARCH_HAS_FORCE_DMA_UNENCRYPTED */
+#endif /* CONFIG_ARCH_HAS_FORCE_DMA_DECRYPTED */
 
 /*
  * If memory encryption is supported, phys_to_dma will set the memory encryption
kernel/dma/Kconfig +1 -1
index 4c103a24e380..55c4147bb2b1 100644
@@ -51,7 +51,7 @@ config ARCH_HAS_SYNC_DMA_FOR_CPU_ALL
 config ARCH_HAS_DMA_PREP_COHERENT
 	bool
 
-config ARCH_HAS_FORCE_DMA_UNENCRYPTED
+config ARCH_HAS_FORCE_DMA_DECRYPTED
 	bool
 
 config DMA_NONCOHERENT_CACHE_SYNC
kernel/dma/direct.c +7 -7
index ac7956c38f69..a0576c0ccacd 100644
@@ -26,7 +26,7 @@ unsigned int zone_dma_bits __ro_after_init = 24;
 static inline dma_addr_t phys_to_dma_direct(struct device *dev,
 		phys_addr_t phys)
 {
-	if (force_dma_unencrypted(dev))
+	if (force_dma_decrypted(dev))
 		return __phys_to_dma(dev, phys);
 	return phys_to_dma(dev, phys);
 }
@@ -49,7 +49,7 @@ static gfp_t __dma_direct_optimal_gfp_mask(struct device *dev, u64 dma_mask,
 {
 	u64 dma_limit = min_not_zero(dma_mask, dev->bus_dma_limit);
 
-	if (force_dma_unencrypted(dev))
+	if (force_dma_decrypted(dev))
 		*phys_limit = __dma_to_phys(dev, dma_limit);
 	else
 		*phys_limit = dma_to_phys(dev, dma_limit);
@@ -138,7 +138,7 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
 		return NULL;
 
 	if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) &&
-	    !force_dma_unencrypted(dev)) {
+	    !force_dma_decrypted(dev)) {
 		/* remove any dirty cache lines on the kernel alias */
 		if (!PageHighMem(page))
 			arch_dma_prep_coherent(page, size);
@@ -179,7 +179,7 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
 	}
 
 	ret = page_address(page);
-	if (force_dma_unencrypted(dev))
+	if (force_dma_decrypted(dev))
 		set_memory_decrypted((unsigned long)ret, 1 << get_order(size));
 
 	memset(ret, 0, size);
@@ -190,7 +190,7 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
 		ret = uncached_kernel_address(ret);
 	}
 done:
-	if (force_dma_unencrypted(dev))
+	if (force_dma_decrypted(dev))
 		*dma_handle = __phys_to_dma(dev, page_to_phys(page));
 	else
 		*dma_handle = phys_to_dma(dev, page_to_phys(page));
@@ -203,7 +203,7 @@ void dma_direct_free_pages(struct device *dev, size_t size, void *cpu_addr,
 	unsigned int page_order = get_order(size);
 
 	if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) &&
-	    !force_dma_unencrypted(dev)) {
+	    !force_dma_decrypted(dev)) {
 		/* cpu_addr is a struct page cookie, not a kernel address */
 		dma_free_contiguous(dev, cpu_addr, size);
 		return;
@@ -213,7 +213,7 @@ void dma_direct_free_pages(struct device *dev, size_t size, void *cpu_addr,
 	    dma_free_from_pool(cpu_addr, PAGE_ALIGN(size)))
 		return;
 
-	if (force_dma_unencrypted(dev))
+	if (force_dma_decrypted(dev))
 		set_memory_encrypted((unsigned long)cpu_addr, 1 << page_order);
 
 	if (IS_ENABLED(CONFIG_DMA_REMAP) && is_vmalloc_addr(cpu_addr))
kernel/dma/mapping.c +1 -1
index 98e3d873792e..dbd0605a39c5 100644
@@ -154,7 +154,7 @@ EXPORT_SYMBOL(dma_get_sgtable_attrs);
  */
 pgprot_t dma_pgprot(struct device *dev, pgprot_t prot, unsigned long attrs)
 {
-	if (force_dma_unencrypted(dev))
+	if (force_dma_decrypted(dev))
 		prot = pgprot_decrypted(prot);
 	if (dev_is_dma_coherent(dev) ||
 	    (IS_ENABLED(CONFIG_DMA_NONCOHERENT_CACHE_SYNC) &&
Signature · 8 lines
2.21.0


-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#10 lore raw
Quoted 4 lines · Borislav Petkov

Hi,

here's v2 with build breakage fixed on ppc and s390 (obviously I can't grep :-\) and commit message extended to explain more why.

I thought we agreed that decrypted is absolutely the wrong term.

So NAK - if you want to change things it needs to go the other way.

maintainer
#11 lore raw
Quoted 1 line · Christoph Hellwig

I thought we agreed that decrypted is absolutely the wrong term.

I don't think we did. At least I don't know where we did that.

Quoted 1 line

So NAK - if you want to change things it needs to go the other way.

We are already using "decrypted" everywhere in arch/x86/. Changing that would be a *lot* more churn.

And it is just a term, for chrissakes, to denote memory which is not encrypted. And it would make our lifes easier if we had only *two* terms instead of three or more. Especially if the concept we denote with this is a binary one: encrypted memory and *not* encrypted memory.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
reviewer
#12 lore raw

[since this is in my inbox...]

Quoted 7 lines · Borislav Petkov
Quoted 1 line · Christoph Hellwig

I thought we agreed that decrypted is absolutely the wrong term.

I don't think we did. At least I don't know where we did that.

Quoted 1 line

So NAK - if you want to change things it needs to go the other way.

Quoted 7 lines

We are already using "decrypted" everywhere in arch/x86/. Changing that would be a *lot* more churn.

And it is just a term, for chrissakes, to denote memory which is not encrypted. And it would make our lifes easier if we had only *two* terms instead of three or more. Especially if the concept we denote with this is a binary one: encrypted memory and *not* encrypted memory.

Let me add another vote from a native English speaker that "unencrypted" is the appropriate term to imply the *absence* of encryption, whereas "decrypted" implies the *reversal* of applied encryption.

Naming things is famously hard, for good reason - names are *important* for understanding. Just because a decision was already made one way doesn't mean that that decision was necessarily right. Churning one area to be consistently inaccurate just because it's less work than churning another area to be consistently accurate isn't really the best excuse.

Robin.

maintainer
#13 lore raw
Quoted 9 lines · Robin Murphy

Let me add another vote from a native English speaker that "unencrypted" is the appropriate term to imply the *absence* of encryption, whereas "decrypted" implies the *reversal* of applied encryption.

Naming things is famously hard, for good reason - names are *important* for understanding. Just because a decision was already made one way doesn't mean that that decision was necessarily right. Churning one area to be consistently inaccurate just because it's less work than churning another area to be consistently accurate isn't really the best excuse.

Well, the reason we chose "decrypted" vs something else is so to be as different from "encrypted" as possible. If we called it "unencrypted" you'd have stuff like:

       if (force_dma_unencrypted(dev))
                set_memory_encrypted((unsigned long)cpu_addr, 1 << page_order);

and I *betcha* people will misread this and maybe even introduce bugs.

So I don't think renaming it to "unencrypted" is better. And yes, I'm deliberately putting the language semantics here on a second place because of readability examples like the one above.

But ok, since people don't want this, we can leave it as is. It's not like I don't have anything better to do.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#14 lore raw
Quoted 11 lines · Borislav Petkov
Quoted 9 lines · Robin Murphy

Let me add another vote from a native English speaker that "unencrypted" is the appropriate term to imply the *absence* of encryption, whereas "decrypted" implies the *reversal* of applied encryption.

Naming things is famously hard, for good reason - names are *important* for understanding. Just because a decision was already made one way doesn't mean that that decision was necessarily right. Churning one area to be consistently inaccurate just because it's less work than churning another area to be consistently accurate isn't really the best excuse.

Quoted 6 lines

Well, the reason we chose "decrypted" vs something else is so to be as different from "encrypted" as possible. If we called it "unencrypted" you'd have stuff like:

       if (force_dma_unencrypted(dev))
                set_memory_encrypted((unsigned long)cpu_addr, 1 << page_order);

TBH, I don't see how

	if (force_dma_decrypted(dev))
		set_memory_encrypted((unsigned long)cpu_addr, 1 << page_order);

makes more sense than the above. It's both non-sensical unless there is a big fat comment explaining what this is about.

Thanks,

tglx

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

maintainer
#15 lore raw
Quoted 6 lines · Thomas Gleixner

TBH, I don't see how

	if (force_dma_decrypted(dev))
		set_memory_encrypted((unsigned long)cpu_addr, 1 << page_order);

makes more sense than the above. It's both non-sensical unless there is

9087c37584fb ("dma-direct: Force unencrypted DMA under SME for certain DMA masks")

Quoted 1 line

a big fat comment explaining what this is about.

ACK to that.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#17 lore raw
In reply to Thomas Gleixner
Quoted 6 lines · Thomas Gleixner
Quoted 4 lines · Borislav Petkov
Quoted 3 lines · Robin Murphy

Let me add another vote from a native English speaker that "unencrypted" is the appropriate term to imply the *absence* of encryption, whereas "decrypted" implies the *reversal* of applied encryption.

Even as a non-native speaker I can clearly see the distinction.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

Naming things is famously hard, for good reason - names are *important* for understanding. Just because a decision was already made one way doesn't mean that that decision was necessarily right. Churning one area to be consistently inaccurate just because it's less work than churning another area to be consistently accurate isn't really the best excuse.

Quoted 6 lines
Quoted 6 lines

Well, the reason we chose "decrypted" vs something else is so to be as different from "encrypted" as possible. If we called it "unencrypted" you'd have stuff like:

       if (force_dma_unencrypted(dev))
                set_memory_encrypted((unsigned long)cpu_addr, 1 << page_order);

If you want something with high edit distance from 'encrypted' meaning the opposite there is already 'cleartext' which was designed for this exact purpose.

Thanks

Michal

#16 lore raw
In reply to Borislav Petkov
Quoted 9 lines · Borislav Petkov
Quoted 6 lines · Thomas Gleixner

TBH, I don't see how

	if (force_dma_decrypted(dev))
		set_memory_encrypted((unsigned long)cpu_addr, 1 << page_order);

makes more sense than the above. It's both non-sensical unless there is

9087c37584fb ("dma-direct: Force unencrypted DMA under SME for certain DMA masks")

Reading the changelog again...

I have to say that force_dma_unencrypted() makes way more sense in that context than force_dma_decrypted(). It still wants a comment.

Linguistical semantics and correctness matters a lot. Consistency is required as well, but not for the price of ambiguous wording.

Thanks,

tglx

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu