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.
Signed-off-by: Alexey Kardashevskiy <redacted>
---
arch/powerpc/platforms/powernv/pci-ioda.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
@@ -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 */
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:
@@ -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 */
From: Michael Ellerman <mpe@ellerman.id.au> Date: 2017-11-06 10:45:36
Alexey Kardashevskiy [off-list ref] writes:
quoted hunk
On 31/10/17 15:04, Alexey Kardashevskiy wrote:
quoted
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:
@@ -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?
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
From: Jonas Pfefferle1 <hidden> Date: 2017-11-06 11:51:54
Michael Ellerman [off-list ref] wrote on 11/06/2017 11:45:34 AM:
From: Michael Ellerman <mpe@ellerman.id.au>
To: Alexey Kardashevskiy <redacted>, David Gibson
[off-list ref]
Cc: linuxppc-dev@lists.ozlabs.org, Jonas Pfefferle1
[off-list ref], Nicholas Piggin [off-list ref]
Date: 11/06/2017 11:45 AM
Subject: Re: [PATCH kernel] powerpc/powernv/ioda: Relax max DMA
window size check
Alexey Kardashevskiy [off-list ref] writes:
quoted
On 31/10/17 15:04, Alexey Kardashevskiy wrote:
quoted
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
quoted
mostly. KVM guests are less likely to be affected as usually guests
get
quoted
quoted
less than half of hosts RAM.
It was pointed out that this check is quite useless anyway as the
vm_locked
quoted
memory limit should hit first, and if that is not set or the user got
the
quoted
root privilege level, then there are easier ways to crash the host so I
@@ -2769,7 +2769,7 @@ static long pnv_pci_ioda2_table_alloc_pages(int
nid,
quoted
__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?
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
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:
@@ -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?
Sounds reasonable.
Execpt where is the vm_locked check? I think it's in the VFIO driver?
Yes, as Jonas already said.
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.
--
Alexey