IOMMU Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/3] Remove x86-specific code from generic headers
@ 2019-07-13  4:45 Thiago Jung Bauermann
  2019-07-13  4:45 ` [PATCH 1/3] x86, s390: Move ARCH_HAS_MEM_ENCRYPT definition to arch/Kconfig Thiago Jung Bauermann
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Thiago Jung Bauermann @ 2019-07-13  4:45 UTC (permalink / raw)
  To: x86
  Cc: linux-s390, Konrad Rzeszutek Wilk, Robin Murphy, Mike Anderson,
	Ram Pai, linux-kernel, Alexey Dobriyan, Halil Pasic, iommu,
	Ingo Molnar, Borislav Petkov, Thomas Lendacky, H. Peter Anvin,
	linux-fsdevel, Thomas Gleixner, linuxppc-dev, Christoph Hellwig

Hello,

This version mostly changes patch 2/3, removing dma_check_mask() from
kernel/dma/mapping.c as suggested by Christoph Hellwig, and also adapting
s390's <asm/mem_encrypt.h>. There's also a small change in patch 1/3 as
mentioned in the changelog below.

Patch 3/3 may or may not need to change s390 code depending on how Tom
Lendacky's patch is fixed to avoid breaking that architecture, so I haven't
made any changes for now.

These patches are applied on top of today's master which at the time was at
commit 9787aed57dd3 ("coresight: Make the coresight_device_fwnode_match
declaration's fwnode parameter const"), plus a cherry-pick of commit
e67a5ed1f86f ("dma-direct: Force unencrypted DMA under SME for certain DMA
masks"), which is in dma-mapping/for-next and comes from this patch:

https://lore.kernel.org/linux-iommu/10b83d9ff31bca88e94da2ff34e30619eb396078.1562785123.git.thomas.lendacky@amd.com/

I don't have a way to test SME, SEV, nor s390's PEF so the patches have only
been build tested.

Original cover letter below:

Both powerpc¹ and s390² are adding <asm/mem_encrypt.h> headers. Currently,
they have to supply definitions for functions and macros which only have a
meaning on x86: sme_me_mask, sme_active() and sev_active().

Christoph Hellwig made a suggestion to "clean up the Kconfig and generic
headers bits for memory encryption so that we don't need all this
boilerplate code", and this is what this patch does.

After this patch set, this is powerpc's <asm/mem_encrypt.h>:

    #ifndef _ASM_POWERPC_MEM_ENCRYPT_H
    #define _ASM_POWERPC_MEM_ENCRYPT_H

    #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();
    }

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

    #endif /* _ASM_POWERPC_MEM_ENCRYPT_H */

Changelog

Since v1:

- Patch "x86,s390: Move ARCH_HAS_MEM_ENCRYPT definition to arch/Kconfig"
  - Remove definition of ARCH_HAS_MEM_ENCRYPT from s390/Kconfig as well.
  - Reworded patch title and message a little bit.

- Patch "DMA mapping: Move SME handling to x86-specific files"
  - Adapt s390's <asm/mem_encrypt.h> as well.
  - Remove dma_check_mask() from kernel/dma/mapping.c. Suggested by
    Christoph Hellwig.

-- 

¹ https://lore.kernel.org/linuxppc-dev/20190521044912.1375-12-bauerman@linux.ibm.com/
² https://lore.kernel.org/kvm/20190612111236.99538-2-pasic@linux.ibm.com/

Thiago Jung Bauermann (3):
  x86,s390: Move ARCH_HAS_MEM_ENCRYPT definition to arch/Kconfig
  DMA mapping: Move SME handling to x86-specific files
  fs/core/vmcore: Move sev_active() reference to x86 arch code

 arch/Kconfig                        |  3 +++
 arch/s390/Kconfig                   |  3 ---
 arch/s390/include/asm/mem_encrypt.h |  4 +---
 arch/x86/Kconfig                    |  4 +---
 arch/x86/include/asm/mem_encrypt.h  | 10 ++++++++++
 arch/x86/kernel/crash_dump_64.c     |  5 +++++
 fs/proc/vmcore.c                    |  8 ++++----
 include/linux/crash_dump.h          | 14 ++++++++++++++
 include/linux/mem_encrypt.h         | 15 +--------------
 kernel/dma/mapping.c                |  8 --------
 kernel/dma/swiotlb.c                |  3 +--
 11 files changed, 40 insertions(+), 37 deletions(-)

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 1/3] x86, s390: Move ARCH_HAS_MEM_ENCRYPT definition to arch/Kconfig
  2019-07-13  4:45 [PATCH 0/3] Remove x86-specific code from generic headers Thiago Jung Bauermann
@ 2019-07-13  4:45 ` Thiago Jung Bauermann
  2019-07-13  7:27   ` [PATCH 1/3] x86,s390: " Christoph Hellwig
  2019-07-15 15:23   ` [PATCH 1/3] x86, s390: " janani
  2019-07-13  4:45 ` [PATCH 2/3] DMA mapping: Move SME handling to x86-specific files Thiago Jung Bauermann
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 16+ messages in thread
From: Thiago Jung Bauermann @ 2019-07-13  4:45 UTC (permalink / raw)
  To: x86
  Cc: linux-s390, Konrad Rzeszutek Wilk, Robin Murphy, Mike Anderson,
	Ram Pai, linux-kernel, Alexey Dobriyan, Halil Pasic, iommu,
	Ingo Molnar, Borislav Petkov, Thomas Lendacky, H. Peter Anvin,
	linux-fsdevel, Thomas Gleixner, linuxppc-dev, Christoph Hellwig

powerpc is also going to use this feature, so put it in a generic location.

Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/Kconfig      | 3 +++
 arch/s390/Kconfig | 3 ---
 arch/x86/Kconfig  | 4 +---
 3 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index c47b328eada0..4ef3499d4480 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -927,6 +927,9 @@ config LOCK_EVENT_COUNTS
 	  the chance of application behavior change because of timing
 	  differences. The counts are reported via debugfs.
 
+config ARCH_HAS_MEM_ENCRYPT
+	bool
+
 source "kernel/gcov/Kconfig"
 
 source "scripts/gcc-plugins/Kconfig"
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 5d8570ed6cab..f820e631bf89 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -1,7 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
-config ARCH_HAS_MEM_ENCRYPT
-        def_bool y
-
 config MMU
 	def_bool y
 
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index c9f331bb538b..5d3295f2df94 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -68,6 +68,7 @@ config X86
 	select ARCH_HAS_FORTIFY_SOURCE
 	select ARCH_HAS_GCOV_PROFILE_ALL
 	select ARCH_HAS_KCOV			if X86_64
+	select ARCH_HAS_MEM_ENCRYPT
 	select ARCH_HAS_MEMBARRIER_SYNC_CORE
 	select ARCH_HAS_PMEM_API		if X86_64
 	select ARCH_HAS_PTE_SPECIAL
@@ -1520,9 +1521,6 @@ config X86_CPA_STATISTICS
 	  helps to determine the effectiveness of preserving large and huge
 	  page mappings when mapping protections are changed.
 
-config ARCH_HAS_MEM_ENCRYPT
-	def_bool y
-
 config AMD_MEM_ENCRYPT
 	bool "AMD Secure Memory Encryption (SME) support"
 	depends on X86_64 && CPU_SUP_AMD

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 2/3] DMA mapping: Move SME handling to x86-specific files
  2019-07-13  4:45 [PATCH 0/3] Remove x86-specific code from generic headers Thiago Jung Bauermann
  2019-07-13  4:45 ` [PATCH 1/3] x86, s390: Move ARCH_HAS_MEM_ENCRYPT definition to arch/Kconfig Thiago Jung Bauermann
@ 2019-07-13  4:45 ` Thiago Jung Bauermann
  2019-07-13  7:29   ` Christoph Hellwig
  2019-07-13  4:45 ` [PATCH 3/3] fs/core/vmcore: Move sev_active() reference to x86 arch code Thiago Jung Bauermann
  2019-07-13  5:08 ` [PATCH 0/3] Remove x86-specific code from generic headers Thiago Jung Bauermann
  3 siblings, 1 reply; 16+ messages in thread
From: Thiago Jung Bauermann @ 2019-07-13  4:45 UTC (permalink / raw)
  To: x86
  Cc: linux-s390, Konrad Rzeszutek Wilk, Robin Murphy, Mike Anderson,
	Ram Pai, linux-kernel, Alexey Dobriyan, Halil Pasic, iommu,
	Ingo Molnar, Borislav Petkov, Thomas Lendacky, H. Peter Anvin,
	linux-fsdevel, Thomas Gleixner, linuxppc-dev, Christoph Hellwig

Secure Memory Encryption is an x86-specific feature, so it shouldn't appear
in generic kernel code.

In DMA mapping code, Christoph Hellwig mentioned that "There is no reason
why we should have a special debug printk just for one specific reason why
there is a requirement for a large DMA mask.", so we just remove
dma_check_mask().

In SWIOTLB code, there's no need to mention which memory encryption feature
is active, so just use a more generic warning. Besides, other architectures
will have different names for similar technology.

Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
---
 arch/s390/include/asm/mem_encrypt.h |  4 +---
 arch/x86/include/asm/mem_encrypt.h  | 10 ++++++++++
 include/linux/mem_encrypt.h         | 14 +-------------
 kernel/dma/mapping.c                |  8 --------
 kernel/dma/swiotlb.c                |  3 +--
 5 files changed, 13 insertions(+), 26 deletions(-)

diff --git a/arch/s390/include/asm/mem_encrypt.h b/arch/s390/include/asm/mem_encrypt.h
index 3eb018508190..ff813a56bc30 100644
--- a/arch/s390/include/asm/mem_encrypt.h
+++ b/arch/s390/include/asm/mem_encrypt.h
@@ -4,9 +4,7 @@
 
 #ifndef __ASSEMBLY__
 
-#define sme_me_mask	0ULL
-
-static inline bool sme_active(void) { return false; }
+static inline bool mem_encrypt_active(void) { return false; }
 extern bool sev_active(void);
 
 int set_memory_encrypted(unsigned long addr, int numpages);
diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h
index 0c196c47d621..848ce43b9040 100644
--- a/arch/x86/include/asm/mem_encrypt.h
+++ b/arch/x86/include/asm/mem_encrypt.h
@@ -92,6 +92,16 @@ early_set_memory_encrypted(unsigned long vaddr, unsigned long size) { return 0;
 
 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;
+}
+
 #endif	/* __ASSEMBLY__ */
 
 #endif	/* __X86_MEM_ENCRYPT_H__ */
diff --git a/include/linux/mem_encrypt.h b/include/linux/mem_encrypt.h
index 470bd53a89df..0c5b0ff9eb29 100644
--- a/include/linux/mem_encrypt.h
+++ b/include/linux/mem_encrypt.h
@@ -18,23 +18,11 @@
 
 #else	/* !CONFIG_ARCH_HAS_MEM_ENCRYPT */
 
-#define sme_me_mask	0ULL
-
-static inline bool sme_active(void) { return false; }
+static inline bool mem_encrypt_active(void) { return false; }
 static inline bool sev_active(void) { return false; }
 
 #endif	/* CONFIG_ARCH_HAS_MEM_ENCRYPT */
 
-static inline bool mem_encrypt_active(void)
-{
-	return sme_me_mask;
-}
-
-static inline u64 sme_get_me_mask(void)
-{
-	return sme_me_mask;
-}
-
 #ifdef CONFIG_AMD_MEM_ENCRYPT
 /*
  * The __sme_set() and __sme_clr() macros are useful for adding or removing
diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
index f7afdadb6770..b53fc7ec4914 100644
--- a/kernel/dma/mapping.c
+++ b/kernel/dma/mapping.c
@@ -291,12 +291,6 @@ void dma_free_attrs(struct device *dev, size_t size, void *cpu_addr,
 }
 EXPORT_SYMBOL(dma_free_attrs);
 
-static inline void dma_check_mask(struct device *dev, u64 mask)
-{
-	if (sme_active() && (mask < (((u64)sme_get_me_mask() << 1) - 1)))
-		dev_warn(dev, "SME is active, device will require DMA bounce buffers\n");
-}
-
 int dma_supported(struct device *dev, u64 mask)
 {
 	const struct dma_map_ops *ops = get_dma_ops(dev);
@@ -321,7 +315,6 @@ int dma_set_mask(struct device *dev, u64 mask)
 		return -EIO;
 
 	arch_dma_set_mask(dev, mask);
-	dma_check_mask(dev, mask);
 	*dev->dma_mask = mask;
 	return 0;
 }
@@ -333,7 +326,6 @@ int dma_set_coherent_mask(struct device *dev, u64 mask)
 	if (!dma_supported(dev, mask))
 		return -EIO;
 
-	dma_check_mask(dev, mask);
 	dev->coherent_dma_mask = mask;
 	return 0;
 }
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 62fa5a82a065..e52401f94e91 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -459,8 +459,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev,
 		panic("Can not allocate SWIOTLB buffer earlier and can't now provide you with the DMA bounce buffer");
 
 	if (mem_encrypt_active())
-		pr_warn_once("%s is active and system is using DMA bounce buffers\n",
-			     sme_active() ? "SME" : "SEV");
+		pr_warn_once("Memory encryption is active and system is using DMA bounce buffers\n");
 
 	mask = dma_get_seg_boundary(hwdev);
 
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 3/3] fs/core/vmcore: Move sev_active() reference to x86 arch code
  2019-07-13  4:45 [PATCH 0/3] Remove x86-specific code from generic headers Thiago Jung Bauermann
  2019-07-13  4:45 ` [PATCH 1/3] x86, s390: Move ARCH_HAS_MEM_ENCRYPT definition to arch/Kconfig Thiago Jung Bauermann
  2019-07-13  4:45 ` [PATCH 2/3] DMA mapping: Move SME handling to x86-specific files Thiago Jung Bauermann
@ 2019-07-13  4:45 ` Thiago Jung Bauermann
  2019-07-13  5:08 ` [PATCH 0/3] Remove x86-specific code from generic headers Thiago Jung Bauermann
  3 siblings, 0 replies; 16+ messages in thread
From: Thiago Jung Bauermann @ 2019-07-13  4:45 UTC (permalink / raw)
  To: x86
  Cc: linux-s390, Konrad Rzeszutek Wilk, Robin Murphy, Mike Anderson,
	Ram Pai, linux-kernel, Alexey Dobriyan, Halil Pasic, iommu,
	Ingo Molnar, Borislav Petkov, Thomas Lendacky, H. Peter Anvin,
	linux-fsdevel, Thomas Gleixner, linuxppc-dev, Christoph Hellwig

Secure Encrypted Virtualization is an x86-specific feature, so it shouldn't
appear in generic kernel code because it forces non-x86 architectures to
define the sev_active() function, which doesn't make a lot of sense.

To solve this problem, add an x86 elfcorehdr_read() function to override
the generic weak implementation. To do that, it's necessary to make
read_from_oldmem() public so that it can be used outside of vmcore.c.

Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
---
 arch/x86/kernel/crash_dump_64.c |  5 +++++
 fs/proc/vmcore.c                |  8 ++++----
 include/linux/crash_dump.h      | 14 ++++++++++++++
 include/linux/mem_encrypt.h     |  1 -
 4 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
index 22369dd5de3b..045e82e8945b 100644
--- a/arch/x86/kernel/crash_dump_64.c
+++ b/arch/x86/kernel/crash_dump_64.c
@@ -70,3 +70,8 @@ ssize_t copy_oldmem_page_encrypted(unsigned long pfn, char *buf, size_t csize,
 {
 	return __copy_oldmem_page(pfn, buf, csize, offset, userbuf, true);
 }
+
+ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos)
+{
+	return read_from_oldmem(buf, count, ppos, 0, sev_active());
+}
diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
index 57957c91c6df..ca1f20bedd8c 100644
--- a/fs/proc/vmcore.c
+++ b/fs/proc/vmcore.c
@@ -100,9 +100,9 @@ static int pfn_is_ram(unsigned long pfn)
 }
 
 /* Reads a page from the oldmem device from given offset. */
-static ssize_t read_from_oldmem(char *buf, size_t count,
-				u64 *ppos, int userbuf,
-				bool encrypted)
+ssize_t read_from_oldmem(char *buf, size_t count,
+			 u64 *ppos, int userbuf,
+			 bool encrypted)
 {
 	unsigned long pfn, offset;
 	size_t nr_bytes;
@@ -166,7 +166,7 @@ void __weak elfcorehdr_free(unsigned long long addr)
  */
 ssize_t __weak elfcorehdr_read(char *buf, size_t count, u64 *ppos)
 {
-	return read_from_oldmem(buf, count, ppos, 0, sev_active());
+	return read_from_oldmem(buf, count, ppos, 0, false);
 }
 
 /*
diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h
index f774c5eb9e3c..4664fc1871de 100644
--- a/include/linux/crash_dump.h
+++ b/include/linux/crash_dump.h
@@ -115,4 +115,18 @@ static inline int vmcore_add_device_dump(struct vmcoredd_data *data)
 	return -EOPNOTSUPP;
 }
 #endif /* CONFIG_PROC_VMCORE_DEVICE_DUMP */
+
+#ifdef CONFIG_PROC_VMCORE
+ssize_t read_from_oldmem(char *buf, size_t count,
+			 u64 *ppos, int userbuf,
+			 bool encrypted);
+#else
+static inline ssize_t read_from_oldmem(char *buf, size_t count,
+				       u64 *ppos, int userbuf,
+				       bool encrypted)
+{
+	return -EOPNOTSUPP;
+}
+#endif /* CONFIG_PROC_VMCORE */
+
 #endif /* LINUX_CRASHDUMP_H */
diff --git a/include/linux/mem_encrypt.h b/include/linux/mem_encrypt.h
index 0c5b0ff9eb29..5c4a18a91f89 100644
--- a/include/linux/mem_encrypt.h
+++ b/include/linux/mem_encrypt.h
@@ -19,7 +19,6 @@
 #else	/* !CONFIG_ARCH_HAS_MEM_ENCRYPT */
 
 static inline bool mem_encrypt_active(void) { return false; }
-static inline bool sev_active(void) { return false; }
 
 #endif	/* CONFIG_ARCH_HAS_MEM_ENCRYPT */
 

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/3] Remove x86-specific code from generic headers
  2019-07-13  4:45 [PATCH 0/3] Remove x86-specific code from generic headers Thiago Jung Bauermann
                   ` (2 preceding siblings ...)
  2019-07-13  4:45 ` [PATCH 3/3] fs/core/vmcore: Move sev_active() reference to x86 arch code Thiago Jung Bauermann
@ 2019-07-13  5:08 ` Thiago Jung Bauermann
  3 siblings, 0 replies; 16+ messages in thread
From: Thiago Jung Bauermann @ 2019-07-13  5:08 UTC (permalink / raw)
  To: x86
  Cc: linux-s390, Konrad Rzeszutek Wilk, Robin Murphy, Mike Anderson,
	Ram Pai, linux-kernel, Alexey Dobriyan, Halil Pasic, iommu,
	Ingo Molnar, Borislav Petkov, Thomas Lendacky, H. Peter Anvin,
	linux-fsdevel, Thomas Gleixner, linuxppc-dev, Christoph Hellwig


I forgot to mark this series as v2 when generating the patches.
Sorry for the confusion.

-- 
Thiago Jung Bauermann
IBM Linux Technology Center
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/3] x86,s390: Move ARCH_HAS_MEM_ENCRYPT definition to arch/Kconfig
  2019-07-13  4:45 ` [PATCH 1/3] x86, s390: Move ARCH_HAS_MEM_ENCRYPT definition to arch/Kconfig Thiago Jung Bauermann
@ 2019-07-13  7:27   ` " Christoph Hellwig
  2019-07-15 15:23   ` [PATCH 1/3] x86, s390: " janani
  1 sibling, 0 replies; 16+ messages in thread
From: Christoph Hellwig @ 2019-07-13  7:27 UTC (permalink / raw)
  To: Thiago Jung Bauermann
  Cc: linux-s390, Mike Anderson, Konrad Rzeszutek Wilk, Robin Murphy,
	x86, Ram Pai, linux-kernel, Alexey Dobriyan, Halil Pasic, iommu,
	Ingo Molnar, Borislav Petkov, Thomas Lendacky, H. Peter Anvin,
	linux-fsdevel, Thomas Gleixner, linuxppc-dev, Christoph Hellwig

On Sat, Jul 13, 2019 at 01:45:52AM -0300, Thiago Jung Bauermann wrote:
> powerpc is also going to use this feature, so put it in a generic location.

Looks good,

even without a third arch using it we should never habe symbols defined
under arch/$(ARCH) that are used in common code to start with.

Reviewed-by: Christoph Hellwig <hch@lst.de>
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/3] DMA mapping: Move SME handling to x86-specific files
  2019-07-13  4:45 ` [PATCH 2/3] DMA mapping: Move SME handling to x86-specific files Thiago Jung Bauermann
@ 2019-07-13  7:29   ` Christoph Hellwig
  0 siblings, 0 replies; 16+ messages in thread
From: Christoph Hellwig @ 2019-07-13  7:29 UTC (permalink / raw)
  To: Thiago Jung Bauermann
  Cc: linux-s390, Mike Anderson, Konrad Rzeszutek Wilk, Robin Murphy,
	x86, Ram Pai, linux-kernel, Alexey Dobriyan, Halil Pasic, iommu,
	Ingo Molnar, Borislav Petkov, Thomas Lendacky, H. Peter Anvin,
	linux-fsdevel, Thomas Gleixner, linuxppc-dev, Christoph Hellwig

While this looks generally good to me, I think we want to split this
into three patches:

 1) update the swiotlb printk
 2) removing the dma-mapping check and printk
 3) clean up the mem_encrypt.h interface.

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/3] x86, s390: Move ARCH_HAS_MEM_ENCRYPT definition to arch/Kconfig
  2019-07-13  4:45 ` [PATCH 1/3] x86, s390: Move ARCH_HAS_MEM_ENCRYPT definition to arch/Kconfig Thiago Jung Bauermann
  2019-07-13  7:27   ` [PATCH 1/3] x86,s390: " Christoph Hellwig
@ 2019-07-15 15:23   ` " janani
  2019-07-15 20:00     ` Thiago Jung Bauermann
  1 sibling, 1 reply; 16+ messages in thread
From: janani @ 2019-07-15 15:23 UTC (permalink / raw)
  To: Thiago Jung Bauermann
  Cc: linux-s390, x86, Thomas Gleixner, Linuxppc-dev,
	Konrad Rzeszutek Wilk, linuxppc-dev, Mike Anderson, Ram Pai,
	linux-kernel, Christoph Hellwig, Halil Pasic, iommu, Ingo Molnar,
	Borislav Petkov, H. Peter Anvin, linux-fsdevel, Thomas Lendacky,
	Robin Murphy, Alexey Dobriyan

On 2019-07-12 23:45, Thiago Jung Bauermann wrote:
> powerpc is also going to use this feature, so put it in a generic 
> location.
> 
> Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
> Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
> ---
>  arch/Kconfig      | 3 +++
>  arch/s390/Kconfig | 3 ---
>  arch/x86/Kconfig  | 4 +---
>  3 files changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/Kconfig b/arch/Kconfig
> index c47b328eada0..4ef3499d4480 100644
> --- a/arch/Kconfig
> +++ b/arch/Kconfig
> @@ -927,6 +927,9 @@ config LOCK_EVENT_COUNTS
>  	  the chance of application behavior change because of timing
>  	  differences. The counts are reported via debugfs.
> 
> +config ARCH_HAS_MEM_ENCRYPT
> +	bool
> +
>  source "kernel/gcov/Kconfig"
> 
>  source "scripts/gcc-plugins/Kconfig"
> diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
> index 5d8570ed6cab..f820e631bf89 100644
> --- a/arch/s390/Kconfig
> +++ b/arch/s390/Kconfig
> @@ -1,7 +1,4 @@
>  # SPDX-License-Identifier: GPL-2.0
> -config ARCH_HAS_MEM_ENCRYPT
> -        def_bool y
> -

  Since you are removing the "def_bool y" when ARCH_HAS_MEM_ENCRYPT is 
moved to arch/Kconfig, does the s390/Kconfig need "select 
ARCH_HAS_MEM_ENCRYPT" added like you do for x86/Kconfig?

  - Janani

>  config MMU
>  	def_bool y
> 
> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index c9f331bb538b..5d3295f2df94 100644
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
> @@ -68,6 +68,7 @@ config X86
>  	select ARCH_HAS_FORTIFY_SOURCE
>  	select ARCH_HAS_GCOV_PROFILE_ALL
>  	select ARCH_HAS_KCOV			if X86_64
> +	select ARCH_HAS_MEM_ENCRYPT
>  	select ARCH_HAS_MEMBARRIER_SYNC_CORE
>  	select ARCH_HAS_PMEM_API		if X86_64
>  	select ARCH_HAS_PTE_SPECIAL
> @@ -1520,9 +1521,6 @@ config X86_CPA_STATISTICS
>  	  helps to determine the effectiveness of preserving large and huge
>  	  page mappings when mapping protections are changed.
> 
> -config ARCH_HAS_MEM_ENCRYPT
> -	def_bool y
> -
>  config AMD_MEM_ENCRYPT
>  	bool "AMD Secure Memory Encryption (SME) support"
>  	depends on X86_64 && CPU_SUP_AMD
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/3] x86, s390: Move ARCH_HAS_MEM_ENCRYPT definition to arch/Kconfig
  2019-07-15 15:23   ` [PATCH 1/3] x86, s390: " janani
@ 2019-07-15 20:00     ` Thiago Jung Bauermann
  0 siblings, 0 replies; 16+ messages in thread
From: Thiago Jung Bauermann @ 2019-07-15 20:00 UTC (permalink / raw)
  To: janani
  Cc: linux-s390, x86, Thomas Gleixner, Linuxppc-dev,
	Konrad Rzeszutek Wilk, linuxppc-dev, Mike Anderson, Ram Pai,
	linux-kernel, Christoph Hellwig, Halil Pasic, iommu, Ingo Molnar,
	Borislav Petkov, H. Peter Anvin, linux-fsdevel, Thomas Lendacky,
	Robin Murphy, Alexey Dobriyan


Hello Janani,

Thanks for reviewing the patch.

janani <janani@linux.ibm.com> writes:

> On 2019-07-12 23:45, Thiago Jung Bauermann wrote:
>> powerpc is also going to use this feature, so put it in a generic location.
>>
>> Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
>> Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
>> ---
>>  arch/Kconfig      | 3 +++
>>  arch/s390/Kconfig | 3 ---
>>  arch/x86/Kconfig  | 4 +---
>>  3 files changed, 4 insertions(+), 6 deletions(-)
>>
>> diff --git a/arch/Kconfig b/arch/Kconfig
>> index c47b328eada0..4ef3499d4480 100644
>> --- a/arch/Kconfig
>> +++ b/arch/Kconfig
>> @@ -927,6 +927,9 @@ config LOCK_EVENT_COUNTS
>>  	  the chance of application behavior change because of timing
>>  	  differences. The counts are reported via debugfs.
>>
>> +config ARCH_HAS_MEM_ENCRYPT
>> +	bool
>> +
>>  source "kernel/gcov/Kconfig"
>>
>>  source "scripts/gcc-plugins/Kconfig"
>> diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
>> index 5d8570ed6cab..f820e631bf89 100644
>> --- a/arch/s390/Kconfig
>> +++ b/arch/s390/Kconfig
>> @@ -1,7 +1,4 @@
>>  # SPDX-License-Identifier: GPL-2.0
>> -config ARCH_HAS_MEM_ENCRYPT
>> -        def_bool y
>> -
>
>  Since you are removing the "def_bool y" when ARCH_HAS_MEM_ENCRYPT is moved to
> arch/Kconfig, does the s390/Kconfig need "select ARCH_HAS_MEM_ENCRYPT" added
> like you do for x86/Kconfig?

Indeed, I missed that. Thanks for spotting it!

>
>  - Janani
>
>>  config MMU
>>  	def_bool y
>>
>> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
>> index c9f331bb538b..5d3295f2df94 100644
>> --- a/arch/x86/Kconfig
>> +++ b/arch/x86/Kconfig
>> @@ -68,6 +68,7 @@ config X86
>>  	select ARCH_HAS_FORTIFY_SOURCE
>>  	select ARCH_HAS_GCOV_PROFILE_ALL
>>  	select ARCH_HAS_KCOV			if X86_64
>> +	select ARCH_HAS_MEM_ENCRYPT
>>  	select ARCH_HAS_MEMBARRIER_SYNC_CORE
>>  	select ARCH_HAS_PMEM_API		if X86_64
>>  	select ARCH_HAS_PTE_SPECIAL
>> @@ -1520,9 +1521,6 @@ config X86_CPA_STATISTICS
>>  	  helps to determine the effectiveness of preserving large and huge
>>  	  page mappings when mapping protections are changed.
>>
>> -config ARCH_HAS_MEM_ENCRYPT
>> -	def_bool y
>> -
>>  config AMD_MEM_ENCRYPT
>>  	bool "AMD Secure Memory Encryption (SME) support"
>>  	depends on X86_64 && CPU_SUP_AMD


-- 
Thiago Jung Bauermann
IBM Linux Technology Center

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/3] DMA mapping: Move SME handling to x86-specific files
  2019-07-19  9:05   ` kbuild test robot
@ 2019-07-20  0:22     ` Thiago Jung Bauermann
  0 siblings, 0 replies; 16+ messages in thread
From: Thiago Jung Bauermann @ 2019-07-20  0:22 UTC (permalink / raw)
  To: kbuild test robot
  Cc: linux-s390, Mike Anderson, Konrad Rzeszutek Wilk, Robin Murphy,
	x86, Ram Pai, linux-kernel, Alexey Dobriyan, Halil Pasic, iommu,
	Ingo Molnar, Borislav Petkov, kbuild-all, H. Peter Anvin,
	linux-fsdevel, Thomas Gleixner, linuxppc-dev, Christoph Hellwig


kbuild test robot <lkp@intel.com> writes:

> Hi Thiago,
>
> Thank you for the patch! Yet something to improve:
>
> [auto build test ERROR on linus/master]
> [cannot apply to v5.2 next-20190718]
> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
>
> url:    https://github.com/0day-ci/linux/commits/Thiago-Jung-Bauermann/Remove-x86-specific-code-from-generic-headers/20190715-063006
> config: s390-allnoconfig (attached as .config)
> compiler: s390-linux-gcc (GCC) 7.4.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=7.4.0 make.cross ARCH=s390
>
> If you fix the issue, kindly add following tag
> Reported-by: kbuild test robot <lkp@intel.com>
>
> All errors (new ones prefixed by >>):
>
>    kernel/dma/swiotlb.c: In function 'swiotlb_tbl_map_single':
>>> kernel/dma/swiotlb.c:461:6: error: implicit declaration of function 'mem_encrypt_active'; did you mean 'set_cpu_active'? [-Werror=implicit-function-declaration]
>      if (mem_encrypt_active())
>          ^~~~~~~~~~~~~~~~~~
>          set_cpu_active
>    cc1: some warnings being treated as errors

This error was reported for v1 of the patch series. I wasn't able to
reproduce this problem on v1 but found a similar issue on v2.

I just did a build test of each patch of the latest version (v3) with an
s390 cross-toolchain and the config file from this report and didn't
find any build issues, so I believe this problem is solved.

--
Thiago Jung Bauermann
IBM Linux Technology Center
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/3] DMA mapping: Move SME handling to x86-specific files
  2019-07-12  5:36 ` [PATCH 2/3] DMA mapping: Move SME handling to x86-specific files Thiago Jung Bauermann
  2019-07-12  7:13   ` Christoph Hellwig
  2019-07-12 16:09   ` Thomas Gleixner
@ 2019-07-19  9:05   ` kbuild test robot
  2019-07-20  0:22     ` Thiago Jung Bauermann
  2 siblings, 1 reply; 16+ messages in thread
From: kbuild test robot @ 2019-07-19  9:05 UTC (permalink / raw)
  To: Thiago Jung Bauermann
  Cc: linux-s390, Mike Anderson, Konrad Rzeszutek Wilk, Robin Murphy,
	x86, Ram Pai, linux-kernel, Alexey Dobriyan, Halil Pasic, iommu,
	Ingo Molnar, Borislav Petkov, kbuild-all, H. Peter Anvin,
	linux-fsdevel, Thomas Gleixner, linuxppc-dev, Christoph Hellwig

[-- Warning: decoded text below may be mangled --]
[-- Attachment #1: Type: text/plain; charset=unknown-8bit, Size: 30295 bytes --]

Hi Thiago,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[cannot apply to v5.2 next-20190718]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Thiago-Jung-Bauermann/Remove-x86-specific-code-from-generic-headers/20190715-063006
config: s390-allnoconfig (attached as .config)
compiler: s390-linux-gcc (GCC) 7.4.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=7.4.0 make.cross ARCH=s390 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   kernel/dma/swiotlb.c: In function 'swiotlb_tbl_map_single':
>> kernel/dma/swiotlb.c:461:6: error: implicit declaration of function 'mem_encrypt_active'; did you mean 'set_cpu_active'? [-Werror=implicit-function-declaration]
     if (mem_encrypt_active())
         ^~~~~~~~~~~~~~~~~~
         set_cpu_active
   cc1: some warnings being treated as errors

vim +461 kernel/dma/swiotlb.c

1b548f667c1487d lib/swiotlb.c           Jeremy Fitzhardinge   2008-12-16  442  
e05ed4d1fad9e73 lib/swiotlb.c           Alexander Duyck       2012-10-15  443  phys_addr_t swiotlb_tbl_map_single(struct device *hwdev,
e05ed4d1fad9e73 lib/swiotlb.c           Alexander Duyck       2012-10-15  444  				   dma_addr_t tbl_dma_addr,
e05ed4d1fad9e73 lib/swiotlb.c           Alexander Duyck       2012-10-15  445  				   phys_addr_t orig_addr, size_t size,
0443fa003fa199f lib/swiotlb.c           Alexander Duyck       2016-11-02  446  				   enum dma_data_direction dir,
0443fa003fa199f lib/swiotlb.c           Alexander Duyck       2016-11-02  447  				   unsigned long attrs)
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  448  {
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  449  	unsigned long flags;
e05ed4d1fad9e73 lib/swiotlb.c           Alexander Duyck       2012-10-15  450  	phys_addr_t tlb_addr;
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  451  	unsigned int nslots, stride, index, wrap;
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  452  	int i;
681cc5cd3efbeaf lib/swiotlb.c           FUJITA Tomonori       2008-02-04  453  	unsigned long mask;
681cc5cd3efbeaf lib/swiotlb.c           FUJITA Tomonori       2008-02-04  454  	unsigned long offset_slots;
681cc5cd3efbeaf lib/swiotlb.c           FUJITA Tomonori       2008-02-04  455  	unsigned long max_slots;
53b29c336830db4 kernel/dma/swiotlb.c    Dongli Zhang          2019-04-12  456  	unsigned long tmp_io_tlb_used;
681cc5cd3efbeaf lib/swiotlb.c           FUJITA Tomonori       2008-02-04  457  
ac2cbab21f318e1 lib/swiotlb.c           Yinghai Lu            2013-01-24  458  	if (no_iotlb_memory)
ac2cbab21f318e1 lib/swiotlb.c           Yinghai Lu            2013-01-24  459  		panic("Can not allocate SWIOTLB buffer earlier and can't now provide you with the DMA bounce buffer");
ac2cbab21f318e1 lib/swiotlb.c           Yinghai Lu            2013-01-24  460  
d7b417fa08d1187 lib/swiotlb.c           Tom Lendacky          2017-10-20 @461  	if (mem_encrypt_active())
aa4d0dc3e029b79 kernel/dma/swiotlb.c    Thiago Jung Bauermann 2019-07-12  462  		pr_warn_once("Memory encryption is active and system is using DMA bounce buffers\n");
648babb7078c631 lib/swiotlb.c           Tom Lendacky          2017-07-17  463  
681cc5cd3efbeaf lib/swiotlb.c           FUJITA Tomonori       2008-02-04  464  	mask = dma_get_seg_boundary(hwdev);
681cc5cd3efbeaf lib/swiotlb.c           FUJITA Tomonori       2008-02-04  465  
eb605a5754d050a lib/swiotlb.c           FUJITA Tomonori       2010-05-10  466  	tbl_dma_addr &= mask;
eb605a5754d050a lib/swiotlb.c           FUJITA Tomonori       2010-05-10  467  
eb605a5754d050a lib/swiotlb.c           FUJITA Tomonori       2010-05-10  468  	offset_slots = ALIGN(tbl_dma_addr, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT;
a5ddde4a558b3bd lib/swiotlb.c           Ian Campbell          2008-12-16  469  
a5ddde4a558b3bd lib/swiotlb.c           Ian Campbell          2008-12-16  470  	/*
a5ddde4a558b3bd lib/swiotlb.c           Ian Campbell          2008-12-16  471   	 * Carefully handle integer overflow which can occur when mask == ~0UL.
a5ddde4a558b3bd lib/swiotlb.c           Ian Campbell          2008-12-16  472   	 */
b15a3891c916f32 lib/swiotlb.c           Jan Beulich           2008-03-13  473  	max_slots = mask + 1
b15a3891c916f32 lib/swiotlb.c           Jan Beulich           2008-03-13  474  		    ? ALIGN(mask + 1, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT
b15a3891c916f32 lib/swiotlb.c           Jan Beulich           2008-03-13  475  		    : 1UL << (BITS_PER_LONG - IO_TLB_SHIFT);
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  476  
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  477  	/*
602d9858f07c72e lib/swiotlb.c           Nikita Yushchenko     2017-01-11  478  	 * For mappings greater than or equal to a page, we limit the stride
602d9858f07c72e lib/swiotlb.c           Nikita Yushchenko     2017-01-11  479  	 * (and hence alignment) to a page size.
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  480  	 */
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  481  	nslots = ALIGN(size, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT;
602d9858f07c72e lib/swiotlb.c           Nikita Yushchenko     2017-01-11  482  	if (size >= PAGE_SIZE)
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  483  		stride = (1 << (PAGE_SHIFT - IO_TLB_SHIFT));
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  484  	else
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  485  		stride = 1;
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  486  
34814545890db60 lib/swiotlb.c           Eric Sesterhenn       2006-03-24  487  	BUG_ON(!nslots);
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  488  
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  489  	/*
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  490  	 * Find suitable number of IO TLB entries size that will fit this
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  491  	 * request and allocate a buffer from that IO TLB pool.
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  492  	 */
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  493  	spin_lock_irqsave(&io_tlb_lock, flags);
60513ed06a41049 kernel/dma/swiotlb.c    Dongli Zhang          2019-01-18  494  
60513ed06a41049 kernel/dma/swiotlb.c    Dongli Zhang          2019-01-18  495  	if (unlikely(nslots > io_tlb_nslabs - io_tlb_used))
60513ed06a41049 kernel/dma/swiotlb.c    Dongli Zhang          2019-01-18  496  		goto not_found;
60513ed06a41049 kernel/dma/swiotlb.c    Dongli Zhang          2019-01-18  497  
681cc5cd3efbeaf lib/swiotlb.c           FUJITA Tomonori       2008-02-04  498  	index = ALIGN(io_tlb_index, stride);
681cc5cd3efbeaf lib/swiotlb.c           FUJITA Tomonori       2008-02-04  499  	if (index >= io_tlb_nslabs)
681cc5cd3efbeaf lib/swiotlb.c           FUJITA Tomonori       2008-02-04  500  		index = 0;
b15a3891c916f32 lib/swiotlb.c           Jan Beulich           2008-03-13  501  	wrap = index;
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  502  
b15a3891c916f32 lib/swiotlb.c           Jan Beulich           2008-03-13  503  	do {
a8522509200b460 lib/swiotlb.c           FUJITA Tomonori       2008-04-29  504  		while (iommu_is_span_boundary(index, nslots, offset_slots,
681cc5cd3efbeaf lib/swiotlb.c           FUJITA Tomonori       2008-02-04  505  					      max_slots)) {
681cc5cd3efbeaf lib/swiotlb.c           FUJITA Tomonori       2008-02-04  506  			index += stride;
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  507  			if (index >= io_tlb_nslabs)
681cc5cd3efbeaf lib/swiotlb.c           FUJITA Tomonori       2008-02-04  508  				index = 0;
b15a3891c916f32 lib/swiotlb.c           Jan Beulich           2008-03-13  509  			if (index == wrap)
b15a3891c916f32 lib/swiotlb.c           Jan Beulich           2008-03-13  510  				goto not_found;
681cc5cd3efbeaf lib/swiotlb.c           FUJITA Tomonori       2008-02-04  511  		}
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  512  
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  513  		/*
a7133a15587b892 lib/swiotlb.c           Andrew Morton         2008-04-29  514  		 * If we find a slot that indicates we have 'nslots' number of
a7133a15587b892 lib/swiotlb.c           Andrew Morton         2008-04-29  515  		 * contiguous buffers, we allocate the buffers from that slot
a7133a15587b892 lib/swiotlb.c           Andrew Morton         2008-04-29  516  		 * and mark the entries as '0' indicating unavailable.
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  517  		 */
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  518  		if (io_tlb_list[index] >= nslots) {
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  519  			int count = 0;
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  520  
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  521  			for (i = index; i < (int) (index + nslots); i++)
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  522  				io_tlb_list[i] = 0;
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  523  			for (i = index - 1; (OFFSET(i, IO_TLB_SEGSIZE) != IO_TLB_SEGSIZE - 1) && io_tlb_list[i]; i--)
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  524  				io_tlb_list[i] = ++count;
e05ed4d1fad9e73 lib/swiotlb.c           Alexander Duyck       2012-10-15  525  			tlb_addr = io_tlb_start + (index << IO_TLB_SHIFT);
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  526  
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  527  			/*
a7133a15587b892 lib/swiotlb.c           Andrew Morton         2008-04-29  528  			 * Update the indices to avoid searching in the next
a7133a15587b892 lib/swiotlb.c           Andrew Morton         2008-04-29  529  			 * round.
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  530  			 */
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  531  			io_tlb_index = ((index + nslots) < io_tlb_nslabs
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  532  					? (index + nslots) : 0);
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  533  
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  534  			goto found;
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  535  		}
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  536  		index += stride;
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  537  		if (index >= io_tlb_nslabs)
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  538  			index = 0;
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  539  	} while (index != wrap);
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  540  
b15a3891c916f32 lib/swiotlb.c           Jan Beulich           2008-03-13  541  not_found:
53b29c336830db4 kernel/dma/swiotlb.c    Dongli Zhang          2019-04-12  542  	tmp_io_tlb_used = io_tlb_used;
53b29c336830db4 kernel/dma/swiotlb.c    Dongli Zhang          2019-04-12  543  
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  544  	spin_unlock_irqrestore(&io_tlb_lock, flags);
d0bc0c2a31c9500 lib/swiotlb.c           Christian König       2018-01-04  545  	if (!(attrs & DMA_ATTR_NO_WARN) && printk_ratelimit())
53b29c336830db4 kernel/dma/swiotlb.c    Dongli Zhang          2019-04-12  546  		dev_warn(hwdev, "swiotlb buffer is full (sz: %zd bytes), total %lu (slots), used %lu (slots)\n",
53b29c336830db4 kernel/dma/swiotlb.c    Dongli Zhang          2019-04-12  547  			 size, io_tlb_nslabs, tmp_io_tlb_used);
b907e20508d0246 kernel/dma/swiotlb.c    Christoph Hellwig     2018-12-03  548  	return DMA_MAPPING_ERROR;
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  549  found:
71602fe6d4e9291 kernel/dma/swiotlb.c    Dongli Zhang          2019-01-18  550  	io_tlb_used += nslots;
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  551  	spin_unlock_irqrestore(&io_tlb_lock, flags);
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  552  
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  553  	/*
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  554  	 * Save away the mapping from the original address to the DMA address.
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  555  	 * This is needed when we sync the memory.  Then we sync the buffer if
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  556  	 * needed.
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  557  	 */
bc40ac66988a772 lib/swiotlb.c           Becky Bruce           2008-12-22  558  	for (i = 0; i < nslots; i++)
e05ed4d1fad9e73 lib/swiotlb.c           Alexander Duyck       2012-10-15  559  		io_tlb_orig_addr[index+i] = orig_addr + (i << IO_TLB_SHIFT);
0443fa003fa199f lib/swiotlb.c           Alexander Duyck       2016-11-02  560  	if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) &&
0443fa003fa199f lib/swiotlb.c           Alexander Duyck       2016-11-02  561  	    (dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL))
af51a9f1848ff50 lib/swiotlb.c           Alexander Duyck       2012-10-15  562  		swiotlb_bounce(orig_addr, tlb_addr, size, DMA_TO_DEVICE);
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  563  
e05ed4d1fad9e73 lib/swiotlb.c           Alexander Duyck       2012-10-15  564  	return tlb_addr;
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  565  }
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  566  
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  567  /*
d0c8ba40c6cc0fe lib/swiotlb.c           Yisheng Xie           2018-05-07  568   * tlb_addr is the physical address of the bounce buffer to unmap.
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  569   */
61ca08c3220032d lib/swiotlb.c           Alexander Duyck       2012-10-15  570  void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr,
0443fa003fa199f lib/swiotlb.c           Alexander Duyck       2016-11-02  571  			      size_t size, enum dma_data_direction dir,
0443fa003fa199f lib/swiotlb.c           Alexander Duyck       2016-11-02  572  			      unsigned long attrs)
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  573  {
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  574  	unsigned long flags;
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  575  	int i, count, nslots = ALIGN(size, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT;
61ca08c3220032d lib/swiotlb.c           Alexander Duyck       2012-10-15  576  	int index = (tlb_addr - io_tlb_start) >> IO_TLB_SHIFT;
61ca08c3220032d lib/swiotlb.c           Alexander Duyck       2012-10-15  577  	phys_addr_t orig_addr = io_tlb_orig_addr[index];
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  578  
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  579  	/*
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  580  	 * First, sync the memory before unmapping the entry
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  581  	 */
8e0629c1d4ce86c lib/swiotlb.c           Jan Beulich           2014-06-02  582  	if (orig_addr != INVALID_PHYS_ADDR &&
0443fa003fa199f lib/swiotlb.c           Alexander Duyck       2016-11-02  583  	    !(attrs & DMA_ATTR_SKIP_CPU_SYNC) &&
8e0629c1d4ce86c lib/swiotlb.c           Jan Beulich           2014-06-02  584  	    ((dir == DMA_FROM_DEVICE) || (dir == DMA_BIDIRECTIONAL)))
af51a9f1848ff50 lib/swiotlb.c           Alexander Duyck       2012-10-15  585  		swiotlb_bounce(orig_addr, tlb_addr, size, DMA_FROM_DEVICE);
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  586  
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  587  	/*
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  588  	 * Return the buffer to the free list by setting the corresponding
af901ca181d92aa lib/swiotlb.c           André Goddard Rosa    2009-11-14  589  	 * entries to indicate the number of contiguous entries available.
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  590  	 * While returning the entries to the free list, we merge the entries
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  591  	 * with slots below and above the pool being returned.
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  592  	 */
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  593  	spin_lock_irqsave(&io_tlb_lock, flags);
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  594  	{
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  595  		count = ((index + nslots) < ALIGN(index + 1, IO_TLB_SEGSIZE) ?
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  596  			 io_tlb_list[index + nslots] : 0);
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  597  		/*
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  598  		 * Step 1: return the slots to the free list, merging the
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  599  		 * slots with superceeding slots
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  600  		 */
8e0629c1d4ce86c lib/swiotlb.c           Jan Beulich           2014-06-02  601  		for (i = index + nslots - 1; i >= index; i--) {
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  602  			io_tlb_list[i] = ++count;
8e0629c1d4ce86c lib/swiotlb.c           Jan Beulich           2014-06-02  603  			io_tlb_orig_addr[i] = INVALID_PHYS_ADDR;
8e0629c1d4ce86c lib/swiotlb.c           Jan Beulich           2014-06-02  604  		}
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  605  		/*
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  606  		 * Step 2: merge the returned slots with the preceding slots,
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  607  		 * if available (non zero)
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  608  		 */
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  609  		for (i = index - 1; (OFFSET(i, IO_TLB_SEGSIZE) != IO_TLB_SEGSIZE -1) && io_tlb_list[i]; i--)
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  610  			io_tlb_list[i] = ++count;
71602fe6d4e9291 kernel/dma/swiotlb.c    Dongli Zhang          2019-01-18  611  
71602fe6d4e9291 kernel/dma/swiotlb.c    Dongli Zhang          2019-01-18  612  		io_tlb_used -= nslots;
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  613  	}
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  614  	spin_unlock_irqrestore(&io_tlb_lock, flags);
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  615  }
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  616  
fbfda893eb570bb lib/swiotlb.c           Alexander Duyck       2012-10-15  617  void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr,
fbfda893eb570bb lib/swiotlb.c           Alexander Duyck       2012-10-15  618  			     size_t size, enum dma_data_direction dir,
d7ef1533a90f432 lib/swiotlb.c           Konrad Rzeszutek Wilk 2010-05-28  619  			     enum dma_sync_target target)
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  620  {
fbfda893eb570bb lib/swiotlb.c           Alexander Duyck       2012-10-15  621  	int index = (tlb_addr - io_tlb_start) >> IO_TLB_SHIFT;
fbfda893eb570bb lib/swiotlb.c           Alexander Duyck       2012-10-15  622  	phys_addr_t orig_addr = io_tlb_orig_addr[index];
bc40ac66988a772 lib/swiotlb.c           Becky Bruce           2008-12-22  623  
8e0629c1d4ce86c lib/swiotlb.c           Jan Beulich           2014-06-02  624  	if (orig_addr == INVALID_PHYS_ADDR)
8e0629c1d4ce86c lib/swiotlb.c           Jan Beulich           2014-06-02  625  		return;
fbfda893eb570bb lib/swiotlb.c           Alexander Duyck       2012-10-15  626  	orig_addr += (unsigned long)tlb_addr & ((1 << IO_TLB_SHIFT) - 1);
df336d1c7b6fd51 lib/swiotlb.c           Keir Fraser           2007-07-21  627  
de69e0f0b38a467 lib/swiotlb.c           John W. Linville      2005-09-29  628  	switch (target) {
de69e0f0b38a467 lib/swiotlb.c           John W. Linville      2005-09-29  629  	case SYNC_FOR_CPU:
de69e0f0b38a467 lib/swiotlb.c           John W. Linville      2005-09-29  630  		if (likely(dir == DMA_FROM_DEVICE || dir == DMA_BIDIRECTIONAL))
af51a9f1848ff50 lib/swiotlb.c           Alexander Duyck       2012-10-15  631  			swiotlb_bounce(orig_addr, tlb_addr,
fbfda893eb570bb lib/swiotlb.c           Alexander Duyck       2012-10-15  632  				       size, DMA_FROM_DEVICE);
34814545890db60 lib/swiotlb.c           Eric Sesterhenn       2006-03-24  633  		else
34814545890db60 lib/swiotlb.c           Eric Sesterhenn       2006-03-24  634  			BUG_ON(dir != DMA_TO_DEVICE);
de69e0f0b38a467 lib/swiotlb.c           John W. Linville      2005-09-29  635  		break;
de69e0f0b38a467 lib/swiotlb.c           John W. Linville      2005-09-29  636  	case SYNC_FOR_DEVICE:
de69e0f0b38a467 lib/swiotlb.c           John W. Linville      2005-09-29  637  		if (likely(dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL))
af51a9f1848ff50 lib/swiotlb.c           Alexander Duyck       2012-10-15  638  			swiotlb_bounce(orig_addr, tlb_addr,
fbfda893eb570bb lib/swiotlb.c           Alexander Duyck       2012-10-15  639  				       size, DMA_TO_DEVICE);
34814545890db60 lib/swiotlb.c           Eric Sesterhenn       2006-03-24  640  		else
34814545890db60 lib/swiotlb.c           Eric Sesterhenn       2006-03-24  641  			BUG_ON(dir != DMA_FROM_DEVICE);
de69e0f0b38a467 lib/swiotlb.c           John W. Linville      2005-09-29  642  		break;
de69e0f0b38a467 lib/swiotlb.c           John W. Linville      2005-09-29  643  	default:
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  644  		BUG();
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  645  	}
de69e0f0b38a467 lib/swiotlb.c           John W. Linville      2005-09-29  646  }
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  647  
55897af63091ebc kernel/dma/swiotlb.c    Christoph Hellwig     2018-12-03  648  /*
55897af63091ebc kernel/dma/swiotlb.c    Christoph Hellwig     2018-12-03  649   * Create a swiotlb mapping for the buffer at @phys, and in case of DMAing
55897af63091ebc kernel/dma/swiotlb.c    Christoph Hellwig     2018-12-03  650   * to the device copy the data into it as well.
55897af63091ebc kernel/dma/swiotlb.c    Christoph Hellwig     2018-12-03  651   */
55897af63091ebc kernel/dma/swiotlb.c    Christoph Hellwig     2018-12-03  652  bool swiotlb_map(struct device *dev, phys_addr_t *phys, dma_addr_t *dma_addr,
c4dae366925f929 kernel/dma/swiotlb.c    Christoph Hellwig     2018-08-20  653  		size_t size, enum dma_data_direction dir, unsigned long attrs)
c4dae366925f929 kernel/dma/swiotlb.c    Christoph Hellwig     2018-08-20  654  {
55897af63091ebc kernel/dma/swiotlb.c    Christoph Hellwig     2018-12-03  655  	trace_swiotlb_bounced(dev, *dma_addr, size, swiotlb_force);
c4dae366925f929 kernel/dma/swiotlb.c    Christoph Hellwig     2018-08-20  656  
c4dae366925f929 kernel/dma/swiotlb.c    Christoph Hellwig     2018-08-20  657  	if (unlikely(swiotlb_force == SWIOTLB_NO_FORCE)) {
c4dae366925f929 kernel/dma/swiotlb.c    Christoph Hellwig     2018-08-20  658  		dev_warn_ratelimited(dev,
c4dae366925f929 kernel/dma/swiotlb.c    Christoph Hellwig     2018-08-20  659  			"Cannot do DMA to address %pa\n", phys);
55897af63091ebc kernel/dma/swiotlb.c    Christoph Hellwig     2018-12-03  660  		return false;
c4dae366925f929 kernel/dma/swiotlb.c    Christoph Hellwig     2018-08-20  661  	}
c4dae366925f929 kernel/dma/swiotlb.c    Christoph Hellwig     2018-08-20  662  
c4dae366925f929 kernel/dma/swiotlb.c    Christoph Hellwig     2018-08-20  663  	/* Oh well, have to allocate and map a bounce buffer. */
c4dae366925f929 kernel/dma/swiotlb.c    Christoph Hellwig     2018-08-20  664  	*phys = swiotlb_tbl_map_single(dev, __phys_to_dma(dev, io_tlb_start),
c4dae366925f929 kernel/dma/swiotlb.c    Christoph Hellwig     2018-08-20  665  			*phys, size, dir, attrs);
b907e20508d0246 kernel/dma/swiotlb.c    Christoph Hellwig     2018-12-03  666  	if (*phys == DMA_MAPPING_ERROR)
55897af63091ebc kernel/dma/swiotlb.c    Christoph Hellwig     2018-12-03  667  		return false;
c4dae366925f929 kernel/dma/swiotlb.c    Christoph Hellwig     2018-08-20  668  
c4dae366925f929 kernel/dma/swiotlb.c    Christoph Hellwig     2018-08-20  669  	/* Ensure that the address returned is DMA'ble */
55897af63091ebc kernel/dma/swiotlb.c    Christoph Hellwig     2018-12-03  670  	*dma_addr = __phys_to_dma(dev, *phys);
55897af63091ebc kernel/dma/swiotlb.c    Christoph Hellwig     2018-12-03  671  	if (unlikely(!dma_capable(dev, *dma_addr, size))) {
c4dae366925f929 kernel/dma/swiotlb.c    Christoph Hellwig     2018-08-20  672  		swiotlb_tbl_unmap_single(dev, *phys, size, dir,
c4dae366925f929 kernel/dma/swiotlb.c    Christoph Hellwig     2018-08-20  673  			attrs | DMA_ATTR_SKIP_CPU_SYNC);
55897af63091ebc kernel/dma/swiotlb.c    Christoph Hellwig     2018-12-03  674  		return false;
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  675  	}
309df0c503c35fb lib/swiotlb.c           Arthur Kepner         2008-04-29  676  
55897af63091ebc kernel/dma/swiotlb.c    Christoph Hellwig     2018-12-03  677  	return true;
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  678  }
^1da177e4c3f415 arch/ia64/lib/swiotlb.c Linus Torvalds        2005-04-16  679  
abe420bfae528c9 kernel/dma/swiotlb.c    Joerg Roedel          2019-02-07  680  size_t swiotlb_max_mapping_size(struct device *dev)
abe420bfae528c9 kernel/dma/swiotlb.c    Joerg Roedel          2019-02-07  681  {
abe420bfae528c9 kernel/dma/swiotlb.c    Joerg Roedel          2019-02-07  682  	return ((size_t)1 << IO_TLB_SHIFT) * IO_TLB_SEGSIZE;
abe420bfae528c9 kernel/dma/swiotlb.c    Joerg Roedel          2019-02-07  683  }
492366f7b423725 kernel/dma/swiotlb.c    Joerg Roedel          2019-02-07  684  
492366f7b423725 kernel/dma/swiotlb.c    Joerg Roedel          2019-02-07  685  bool is_swiotlb_active(void)
492366f7b423725 kernel/dma/swiotlb.c    Joerg Roedel          2019-02-07  686  {
492366f7b423725 kernel/dma/swiotlb.c    Joerg Roedel          2019-02-07  687  	/*
492366f7b423725 kernel/dma/swiotlb.c    Joerg Roedel          2019-02-07  688  	 * When SWIOTLB is initialized, even if io_tlb_start points to physical
492366f7b423725 kernel/dma/swiotlb.c    Joerg Roedel          2019-02-07  689  	 * address zero, io_tlb_end surely doesn't.
492366f7b423725 kernel/dma/swiotlb.c    Joerg Roedel          2019-02-07  690  	 */
492366f7b423725 kernel/dma/swiotlb.c    Joerg Roedel          2019-02-07  691  	return io_tlb_end != 0;
492366f7b423725 kernel/dma/swiotlb.c    Joerg Roedel          2019-02-07  692  }
45ba8d5d061b134 kernel/dma/swiotlb.c    Linus Torvalds        2019-03-10  693  
71602fe6d4e9291 kernel/dma/swiotlb.c    Dongli Zhang          2019-01-18  694  #ifdef CONFIG_DEBUG_FS
71602fe6d4e9291 kernel/dma/swiotlb.c    Dongli Zhang          2019-01-18  695  
71602fe6d4e9291 kernel/dma/swiotlb.c    Dongli Zhang          2019-01-18  696  static int __init swiotlb_create_debugfs(void)
71602fe6d4e9291 kernel/dma/swiotlb.c    Dongli Zhang          2019-01-18  697  {
1be51474f99bcfd kernel/dma/swiotlb.c    Greg Kroah-Hartman    2019-06-12  698  	struct dentry *root;
71602fe6d4e9291 kernel/dma/swiotlb.c    Dongli Zhang          2019-01-18  699  
1be51474f99bcfd kernel/dma/swiotlb.c    Greg Kroah-Hartman    2019-06-12  700  	root = debugfs_create_dir("swiotlb", NULL);
1be51474f99bcfd kernel/dma/swiotlb.c    Greg Kroah-Hartman    2019-06-12  701  	debugfs_create_ulong("io_tlb_nslabs", 0400, root, &io_tlb_nslabs);
1be51474f99bcfd kernel/dma/swiotlb.c    Greg Kroah-Hartman    2019-06-12  702  	debugfs_create_ulong("io_tlb_used", 0400, root, &io_tlb_used);
71602fe6d4e9291 kernel/dma/swiotlb.c    Dongli Zhang          2019-01-18  703  	return 0;
71602fe6d4e9291 kernel/dma/swiotlb.c    Dongli Zhang          2019-01-18  704  }
71602fe6d4e9291 kernel/dma/swiotlb.c    Dongli Zhang          2019-01-18  705  
71602fe6d4e9291 kernel/dma/swiotlb.c    Dongli Zhang          2019-01-18  706  late_initcall(swiotlb_create_debugfs);
71602fe6d4e9291 kernel/dma/swiotlb.c    Dongli Zhang          2019-01-18  707  
71602fe6d4e9291 kernel/dma/swiotlb.c    Dongli Zhang          2019-01-18  708  #endif

:::::: The code at line 461 was first introduced by commit
:::::: d7b417fa08d1187923c270bc33a3555c2fcff8b9 x86/mm: Add DMA support for SEV memory encryption

:::::: TO: Tom Lendacky <thomas.lendacky@amd.com>
:::::: CC: Thomas Gleixner <tglx@linutronix.de>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 5848 bytes --]

[-- Attachment #3: Type: text/plain, Size: 156 bytes --]

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/3] DMA mapping: Move SME handling to x86-specific files
  2019-07-12 16:09   ` Thomas Gleixner
@ 2019-07-18 19:47     ` Thiago Jung Bauermann
  0 siblings, 0 replies; 16+ messages in thread
From: Thiago Jung Bauermann @ 2019-07-18 19:47 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: linux-s390, Mike Anderson, Konrad Rzeszutek Wilk, Robin Murphy,
	x86, Ram Pai, linux-kernel, Alexey Dobriyan, Halil Pasic, iommu,
	Ingo Molnar, Borislav Petkov, H. Peter Anvin, linux-fsdevel,
	linuxppc-dev, Christoph Hellwig


Thomas Gleixner <tglx@linutronix.de> writes:

> On Fri, 12 Jul 2019, Thiago Jung Bauermann wrote:
>> diff --git a/include/linux/mem_encrypt.h b/include/linux/mem_encrypt.h
>> index b310a9c18113..f2e399fb626b 100644
>> --- a/include/linux/mem_encrypt.h
>> +++ b/include/linux/mem_encrypt.h
>> @@ -21,23 +21,11 @@
>>  
>>  #else	/* !CONFIG_ARCH_HAS_MEM_ENCRYPT */
>>  
>> -#define sme_me_mask	0ULL
>> -
>> -static inline bool sme_active(void) { return false; }
>>  static inline bool sev_active(void) { return false; }
>
> You want to move out sev_active as well, the only relevant thing is
> mem_encrypt_active(). Everything SME/SEV is an architecture detail.

I'm sure you saw it. I addressed sev_active in a separate patch.

Thanks for reviewing this series!

>> +static inline bool mem_encrypt_active(void) { return false; }
>
> Thanks,
>
> 	tglx


-- 
Thiago Jung Bauermann
IBM Linux Technology Center

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/3] DMA mapping: Move SME handling to x86-specific files
  2019-07-12  7:13   ` Christoph Hellwig
@ 2019-07-12 23:42     ` Thiago Jung Bauermann
  0 siblings, 0 replies; 16+ messages in thread
From: Thiago Jung Bauermann @ 2019-07-12 23:42 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-s390, Mike Anderson, Konrad Rzeszutek Wilk, Robin Murphy,
	x86, Ram Pai, linux-kernel, Halil Pasic, iommu, Ingo Molnar,
	Borislav Petkov, Lendacky, Thomas, H. Peter Anvin, linux-fsdevel,
	Thomas Gleixner, linuxppc-dev, Alexey Dobriyan


[ Cc'ing Tom Lendacky which I forgot to do earlier. Sorry about that. ]

Hello Christoph,

Christoph Hellwig <hch@lst.de> writes:

> Honestly I think this code should go away without any replacement.
> There is no reason why we should have a special debug printk just
> for one specific reason why there is a requirement for a large DMA
> mask.

Makes sense. I'll submit a v2 which just removes this code.

-- 
Thiago Jung Bauermann
IBM Linux Technology Center
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/3] DMA mapping: Move SME handling to x86-specific files
  2019-07-12  5:36 ` [PATCH 2/3] DMA mapping: Move SME handling to x86-specific files Thiago Jung Bauermann
  2019-07-12  7:13   ` Christoph Hellwig
@ 2019-07-12 16:09   ` Thomas Gleixner
  2019-07-18 19:47     ` Thiago Jung Bauermann
  2019-07-19  9:05   ` kbuild test robot
  2 siblings, 1 reply; 16+ messages in thread
From: Thomas Gleixner @ 2019-07-12 16:09 UTC (permalink / raw)
  To: Thiago Jung Bauermann
  Cc: linux-s390, Mike Anderson, Konrad Rzeszutek Wilk, Robin Murphy,
	x86, Ram Pai, linux-kernel, Alexey Dobriyan, Halil Pasic, iommu,
	Ingo Molnar, Borislav Petkov, H. Peter Anvin, linux-fsdevel,
	linuxppc-dev, Christoph Hellwig

On Fri, 12 Jul 2019, Thiago Jung Bauermann wrote:
> diff --git a/include/linux/mem_encrypt.h b/include/linux/mem_encrypt.h
> index b310a9c18113..f2e399fb626b 100644
> --- a/include/linux/mem_encrypt.h
> +++ b/include/linux/mem_encrypt.h
> @@ -21,23 +21,11 @@
>  
>  #else	/* !CONFIG_ARCH_HAS_MEM_ENCRYPT */
>  
> -#define sme_me_mask	0ULL
> -
> -static inline bool sme_active(void) { return false; }
>  static inline bool sev_active(void) { return false; }

You want to move out sev_active as well, the only relevant thing is
mem_encrypt_active(). Everything SME/SEV is an architecture detail.

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

Thanks,

	tglx
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/3] DMA mapping: Move SME handling to x86-specific files
  2019-07-12  5:36 ` [PATCH 2/3] DMA mapping: Move SME handling to x86-specific files Thiago Jung Bauermann
@ 2019-07-12  7:13   ` Christoph Hellwig
  2019-07-12 23:42     ` Thiago Jung Bauermann
  2019-07-12 16:09   ` Thomas Gleixner
  2019-07-19  9:05   ` kbuild test robot
  2 siblings, 1 reply; 16+ messages in thread
From: Christoph Hellwig @ 2019-07-12  7:13 UTC (permalink / raw)
  To: Thiago Jung Bauermann
  Cc: linux-s390, Mike Anderson, Konrad Rzeszutek Wilk, Robin Murphy,
	x86, Ram Pai, linux-kernel, Alexey Dobriyan, Halil Pasic, iommu,
	Ingo Molnar, Borislav Petkov, H. Peter Anvin, linux-fsdevel,
	Thomas Gleixner, linuxppc-dev, Christoph Hellwig

Honestly I think this code should go away without any replacement.
There is no reason why we should have a special debug printk just
for one specific reason why there is a requirement for a large DMA
mask.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 2/3] DMA mapping: Move SME handling to x86-specific files
  2019-07-12  5:36 Thiago Jung Bauermann
@ 2019-07-12  5:36 ` Thiago Jung Bauermann
  2019-07-12  7:13   ` Christoph Hellwig
                     ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Thiago Jung Bauermann @ 2019-07-12  5:36 UTC (permalink / raw)
  To: x86
  Cc: linux-s390, Konrad Rzeszutek Wilk, Robin Murphy, Mike Anderson,
	Ram Pai, linux-kernel, Alexey Dobriyan, Halil Pasic, iommu,
	Ingo Molnar, Borislav Petkov, H. Peter Anvin, linux-fsdevel,
	Thomas Gleixner, linuxppc-dev, Christoph Hellwig

Secure Memory Encryption is an x86-specific feature, so it shouldn't appear
in generic kernel code.

Introduce ARCH_HAS_DMA_CHECK_MASK so that x86 can define its own
dma_check_mask() for the SME check.

In SWIOTLB code, there's no need to mention which memory encryption
feature is active. Also, other architectures will have different names so
this gets unwieldy quickly.

Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
---
 arch/x86/Kconfig                   |  1 +
 arch/x86/include/asm/dma-mapping.h |  7 +++++++
 arch/x86/include/asm/mem_encrypt.h | 10 ++++++++++
 include/linux/mem_encrypt.h        | 14 +-------------
 kernel/dma/Kconfig                 |  3 +++
 kernel/dma/mapping.c               |  4 ++--
 kernel/dma/swiotlb.c               |  3 +--
 7 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 7f4d28da8fe3..dbabe42e7f1c 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -61,6 +61,7 @@ config X86
 	select ARCH_HAS_ACPI_TABLE_UPGRADE	if ACPI
 	select ARCH_HAS_DEBUG_VIRTUAL
 	select ARCH_HAS_DEVMEM_IS_ALLOWED
+	select ARCH_HAS_DMA_CHECK_MASK
 	select ARCH_HAS_ELF_RANDOMIZE
 	select ARCH_HAS_FAST_MULTIPLIER
 	select ARCH_HAS_FILTER_PGPROT
diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
index 6b15a24930e0..55e710ba95a5 100644
--- a/arch/x86/include/asm/dma-mapping.h
+++ b/arch/x86/include/asm/dma-mapping.h
@@ -12,6 +12,7 @@
 #include <asm/io.h>
 #include <asm/swiotlb.h>
 #include <linux/dma-contiguous.h>
+#include <linux/mem_encrypt.h>
 
 extern int iommu_merge;
 extern int panic_on_overflow;
@@ -23,4 +24,10 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
 	return dma_ops;
 }
 
+static inline void dma_check_mask(struct device *dev, u64 mask)
+{
+	if (sme_active() && (mask < (((u64)sme_get_me_mask() << 1) - 1)))
+		dev_warn(dev, "SME is active, device will require DMA bounce buffers\n");
+}
+
 #endif
diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h
index 616f8e637bc3..e4c9e1a57d25 100644
--- a/arch/x86/include/asm/mem_encrypt.h
+++ b/arch/x86/include/asm/mem_encrypt.h
@@ -95,6 +95,16 @@ early_set_memory_encrypted(unsigned long vaddr, unsigned long size) { return 0;
 
 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;
+}
+
 #endif	/* __ASSEMBLY__ */
 
 #endif	/* __X86_MEM_ENCRYPT_H__ */
diff --git a/include/linux/mem_encrypt.h b/include/linux/mem_encrypt.h
index b310a9c18113..f2e399fb626b 100644
--- a/include/linux/mem_encrypt.h
+++ b/include/linux/mem_encrypt.h
@@ -21,23 +21,11 @@
 
 #else	/* !CONFIG_ARCH_HAS_MEM_ENCRYPT */
 
-#define sme_me_mask	0ULL
-
-static inline bool sme_active(void) { return false; }
 static inline bool sev_active(void) { return false; }
+static inline bool mem_encrypt_active(void) { return false; }
 
 #endif	/* CONFIG_ARCH_HAS_MEM_ENCRYPT */
 
-static inline bool mem_encrypt_active(void)
-{
-	return sme_me_mask;
-}
-
-static inline u64 sme_get_me_mask(void)
-{
-	return sme_me_mask;
-}
-
 #ifdef CONFIG_AMD_MEM_ENCRYPT
 /*
  * The __sme_set() and __sme_clr() macros are useful for adding or removing
diff --git a/kernel/dma/Kconfig b/kernel/dma/Kconfig
index 9decbba255fc..34b44bfba372 100644
--- a/kernel/dma/Kconfig
+++ b/kernel/dma/Kconfig
@@ -17,6 +17,9 @@ config ARCH_DMA_ADDR_T_64BIT
 config ARCH_HAS_DMA_COHERENCE_H
 	bool
 
+config ARCH_HAS_DMA_CHECK_MASK
+	bool
+
 config ARCH_HAS_DMA_SET_MASK
 	bool
 
diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
index f7afdadb6770..ed46f88378d4 100644
--- a/kernel/dma/mapping.c
+++ b/kernel/dma/mapping.c
@@ -291,11 +291,11 @@ void dma_free_attrs(struct device *dev, size_t size, void *cpu_addr,
 }
 EXPORT_SYMBOL(dma_free_attrs);
 
+#ifndef CONFIG_ARCH_HAS_DMA_CHECK_MASK
 static inline void dma_check_mask(struct device *dev, u64 mask)
 {
-	if (sme_active() && (mask < (((u64)sme_get_me_mask() << 1) - 1)))
-		dev_warn(dev, "SME is active, device will require DMA bounce buffers\n");
 }
+#endif
 
 int dma_supported(struct device *dev, u64 mask)
 {
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 13f0cb080a4d..67482ad6aab2 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -459,8 +459,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev,
 		panic("Can not allocate SWIOTLB buffer earlier and can't now provide you with the DMA bounce buffer");
 
 	if (mem_encrypt_active())
-		pr_warn_once("%s is active and system is using DMA bounce buffers\n",
-			     sme_active() ? "SME" : "SEV");
+		pr_warn_once("Memory encryption is active and system is using DMA bounce buffers\n");
 
 	mask = dma_get_seg_boundary(hwdev);
 
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, back to index

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-13  4:45 [PATCH 0/3] Remove x86-specific code from generic headers Thiago Jung Bauermann
2019-07-13  4:45 ` [PATCH 1/3] x86, s390: Move ARCH_HAS_MEM_ENCRYPT definition to arch/Kconfig Thiago Jung Bauermann
2019-07-13  7:27   ` [PATCH 1/3] x86,s390: " Christoph Hellwig
2019-07-15 15:23   ` [PATCH 1/3] x86, s390: " janani
2019-07-15 20:00     ` Thiago Jung Bauermann
2019-07-13  4:45 ` [PATCH 2/3] DMA mapping: Move SME handling to x86-specific files Thiago Jung Bauermann
2019-07-13  7:29   ` Christoph Hellwig
2019-07-13  4:45 ` [PATCH 3/3] fs/core/vmcore: Move sev_active() reference to x86 arch code Thiago Jung Bauermann
2019-07-13  5:08 ` [PATCH 0/3] Remove x86-specific code from generic headers Thiago Jung Bauermann
  -- strict thread matches above, loose matches on Subject: below --
2019-07-12  5:36 Thiago Jung Bauermann
2019-07-12  5:36 ` [PATCH 2/3] DMA mapping: Move SME handling to x86-specific files Thiago Jung Bauermann
2019-07-12  7:13   ` Christoph Hellwig
2019-07-12 23:42     ` Thiago Jung Bauermann
2019-07-12 16:09   ` Thomas Gleixner
2019-07-18 19:47     ` Thiago Jung Bauermann
2019-07-19  9:05   ` kbuild test robot
2019-07-20  0:22     ` Thiago Jung Bauermann

IOMMU Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iommu/0 linux-iommu/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iommu linux-iommu/ https://lore.kernel.org/linux-iommu \
		iommu@lists.linux-foundation.org iommu@archiver.kernel.org
	public-inbox-index linux-iommu

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.linux-foundation.lists.iommu


AGPL code for this site: git clone https://public-inbox.org/ public-inbox