Skip to contentSkip to conversation

powerpc/powernv/ioda: Relax max DMA window size check

PATCH Superseded Alexey Kardashevskiy 3 participants 5 messages Oct 31, 2017 – Nov 7, 2017 PowerPC

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/powernv/ioda: Relax max DMA window size check

DMA windows can only have a size of power of two on IODA2 hardware and using memory_hotplug_max() to determine the upper limit won't work correcly if it returns not power of two value.

This relaxes the check by rounding up the value returned by memory_hotplug_max().

It is expected to impact DPDK on machines with non-power-of-two RAM size, mostly. KVM guests are less likely to be affected as usually guests get less than half of hosts RAM.

---
 arch/powerpc/platforms/powernv/pci-ioda.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/platforms/powernv/pci-ioda.c +2 -1
index 269f119e4b3c..4c62162da181 100644
@@ -2769,7 +2769,8 @@ static long pnv_pci_ioda2_table_alloc_pages(int nid, __u64 bus_offset,
 	if (!levels || (levels > POWERNV_IOMMU_MAX_LEVELS))
 		return -EINVAL;
 
-	if ((window_size > memory_hotplug_max()) || !is_power_of_2(window_size))
+	if ((window_size > roundup_pow_of_two(memory_hotplug_max())) ||
+			!is_power_of_2(window_size))
 		return -EINVAL;
 
 	/* Adjust direct table size from window_size and levels */
Signature · 1 line
2.11.0
#1 lore raw
Quoted 10 lines · Alexey Kardashevskiy

DMA windows can only have a size of power of two on IODA2 hardware and using memory_hotplug_max() to determine the upper limit won't work correcly if it returns not power of two value.

This relaxes the check by rounding up the value returned by memory_hotplug_max().

It is expected to impact DPDK on machines with non-power-of-two RAM size, mostly. KVM guests are less likely to be affected as usually guests get less than half of hosts RAM.

It was pointed out that this check is quite useless anyway as the vm_locked memory limit should hit first, and if that is not set or the user got the root privilege level, then there are easier ways to crash the host so I am thinking of:

(quoted diff) +0 -0

b/arch/powerpc/platforms/powernv/pci-ioda.c
index 269f119e4b3c..a47e4cf343b2 100644

arch/powerpc/platforms/powernv/pci-ioda.c +0 -0
@@ -2769,7 +2769,7 @@ static long pnv_pci_ioda2_table_alloc_pages(int nid,

__u64 bus_offset,

        if (!levels || (levels > POWERNV_IOMMU_MAX_LEVELS))
                return -EINVAL;

- if ((window_size > memory_hotplug_max()) ||
!is_power_of_2(window_size))
+ if (!is_power_of_2(window_size))

                return -EINVAL;

Makes sense?

Quoted 21 lines
---
 arch/powerpc/platforms/powernv/pci-ioda.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/platforms/powernv/pci-ioda.c +2 -1
index 269f119e4b3c..4c62162da181 100644
@@ -2769,7 +2769,8 @@ static long pnv_pci_ioda2_table_alloc_pages(int nid, __u64 bus_offset,
 	if (!levels || (levels > POWERNV_IOMMU_MAX_LEVELS))
 		return -EINVAL;
 
-	if ((window_size > memory_hotplug_max()) || !is_power_of_2(window_size))
+	if ((window_size > roundup_pow_of_two(memory_hotplug_max())) ||
+			!is_power_of_2(window_size))
 		return -EINVAL;
 
 	/* Adjust direct table size from window_size and levels */
Signature · 1 line
Alexey
#2 lore raw
Quoted 36 lines · Alexey Kardashevskiy
Quoted 10 lines · Alexey Kardashevskiy

DMA windows can only have a size of power of two on IODA2 hardware and using memory_hotplug_max() to determine the upper limit won't work correcly if it returns not power of two value.

This relaxes the check by rounding up the value returned by memory_hotplug_max().

It is expected to impact DPDK on machines with non-power-of-two RAM size, mostly. KVM guests are less likely to be affected as usually guests get less than half of hosts RAM.

It was pointed out that this check is quite useless anyway as the vm_locked memory limit should hit first, and if that is not set or the user got the root privilege level, then there are easier ways to crash the host so I am thinking of:

arch/powerpc/platforms/powernv/pci-ioda.c +1 -1
index 269f119e4b3c..a47e4cf343b2 100644
@@ -2769,7 +2769,7 @@ static long pnv_pci_ioda2_table_alloc_pages(int nid,
 __u64 bus_offset,
        if (!levels || (levels > POWERNV_IOMMU_MAX_LEVELS))
                return -EINVAL;
 
-       if ((window_size > memory_hotplug_max()) ||
 !is_power_of_2(window_size))
+       if (!is_power_of_2(window_size))
                return -EINVAL;
Quoted 1 line

Makes sense?

Sounds reasonable.

Execpt where is the vm_locked check? I think it's in the VFIO driver? If so I guess the only concern is that this code might be called via some other path that doesn't do that check.

cheers

#3 lore raw

Michael Ellerman <[email protected]> wrote on 11/06/2017 11:45:34 AM:

Quoted 9 lines

From: Michael Ellerman <[email protected]>
To: Alexey Kardashevskiy <[email protected]>, David Gibson <[email protected]>
Cc: [email protected], Jonas Pfefferle1 <[email protected]>, Nicholas Piggin <[email protected]>
Date: 11/06/2017 11:45 AM
Subject: Re: [PATCH kernel] powerpc/powernv/ioda: Relax max DMA window size check

Quoted 11 lines
Quoted 9 lines · Alexey Kardashevskiy
Quoted 8 lines · Alexey Kardashevskiy

DMA windows can only have a size of power of two on IODA2 hardware and using memory_hotplug_max() to determine the upper limit won't work correcly if it returns not power of two value.

This relaxes the check by rounding up the value returned by memory_hotplug_max().

It is expected to impact DPDK on machines with non-power-of-two RAM

size,

Quoted 1 line
Quoted 1 line
Quoted 1 line

mostly. KVM guests are less likely to be affected as usually guests

get

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

less than half of hosts RAM.

It was pointed out that this check is quite useless anyway as the

vm_locked

Quoted 1 line
Quoted 1 line

memory limit should hit first, and if that is not set or the user got

the

Quoted 1 line
Quoted 1 line

root privilege level, then there are easier ways to crash the host so I

am

Quoted 9 lines

arch/powerpc/platforms/powernv/pci-ioda.c static long pnv_pci_ioda2_table_alloc_pages(int

Quoted 9 lines

thinking of:

arch/powerpc/platforms/powernv/pci-ioda.c +0 -0
index 269f119e4b3c..a47e4cf343b2 100644
@@ -2769,7 +2769,7 @@ static long pnv_pci_ioda2_table_alloc_pages(int

nid,

Quoted 13 lines
Quoted 11 lines
arch/powerpc/platforms/powernv/pci-ioda.c +1 -1
 __u64 bus_offset,
        if (!levels || (levels > POWERNV_IOMMU_MAX_LEVELS))
                return -EINVAL;
 
-       if ((window_size > memory_hotplug_max()) ||
 !is_power_of_2(window_size))
+       if (!is_power_of_2(window_size))
                return -EINVAL;
Quoted 1 line

Makes sense?

Quoted 8 lines

Sounds reasonable.

Execpt where is the vm_locked check? I think it's in the VFIO driver? If so I guess the only concern is that this code might be called via some other path that doesn't do that check.

cheers

The vm_locked is incremented here:
http://elixir.free-electrons.com/linux/v4.13.11/source/drivers/vfio/vfio_iommu_spapr_tce.c#L176
resp.
http://elixir.free-electrons.com/linux/v4.13.11/source/arch/powerpc/mm/mmu_context_iommu.c#L124
on VFIO_IOMMU_SPAPR_REGISTER_MEMORY. From my understanding only pages that have been registered through here can be mapped with MAP_DMA.

Cheers,
Jonas

#4 lore raw
In reply to Michael Ellerman
Quoted 38 lines · Michael Ellerman
Quoted 36 lines · Alexey Kardashevskiy
Quoted 10 lines · Alexey Kardashevskiy

DMA windows can only have a size of power of two on IODA2 hardware and using memory_hotplug_max() to determine the upper limit won't work correcly if it returns not power of two value.

This relaxes the check by rounding up the value returned by memory_hotplug_max().

It is expected to impact DPDK on machines with non-power-of-two RAM size, mostly. KVM guests are less likely to be affected as usually guests get less than half of hosts RAM.

It was pointed out that this check is quite useless anyway as the vm_locked memory limit should hit first, and if that is not set or the user got the root privilege level, then there are easier ways to crash the host so I am thinking of:

arch/powerpc/platforms/powernv/pci-ioda.c +1 -1
index 269f119e4b3c..a47e4cf343b2 100644
@@ -2769,7 +2769,7 @@ static long pnv_pci_ioda2_table_alloc_pages(int nid,
 __u64 bus_offset,
        if (!levels || (levels > POWERNV_IOMMU_MAX_LEVELS))
                return -EINVAL;
 
-       if ((window_size > memory_hotplug_max()) ||
 !is_power_of_2(window_size))
+       if (!is_power_of_2(window_size))
                return -EINVAL;
Quoted 5 lines
Quoted 1 line

Makes sense?

Sounds reasonable.

Execpt where is the vm_locked check? I think it's in the VFIO driver?

Yes, as Jonas already said.

Quoted 3 lines

If
so I guess the only concern is that this code might be called via some other path that doesn't do that check.

It is also called from pnv_pci_ioda2_setup_default_config() to create a 32bit DMA window which is limited by __rounddown_pow_of_two(memory_hotplug_max()). I'll repost. Thanks.

Signature · 1 line
Alexey