On 04.06.20 10:01, Miles Chen wrote:
> To build this driver as a kernel module, we cannot use
> the unexported symbol "max_pfn" to setup enable_4GB.
> 
> Use totalram_pages() instead to setup enable_4GB.
> 
> Suggested-by: Mike Rapoport <r...@linux.ibm.com>
> Signed-off-by: Miles Chen <miles.c...@mediatek.com>
> Cc: David Hildenbrand <da...@redhat.com>
> Cc: Yong Wu <yong...@mediatek.com>
> Cc: Chao Hao <chao....@mediatek.com>
> ---
>  drivers/iommu/mtk_iommu.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
> index 5f4d6df59cf6..c2798a6e0e38 100644
> --- a/drivers/iommu/mtk_iommu.c
> +++ b/drivers/iommu/mtk_iommu.c
> @@ -3,7 +3,6 @@
>   * Copyright (c) 2015-2016 MediaTek Inc.
>   * Author: Yong Wu <yong...@mediatek.com>
>   */
> -#include <linux/memblock.h>
>  #include <linux/bug.h>
>  #include <linux/clk.h>
>  #include <linux/component.h>
> @@ -626,8 +625,8 @@ static int mtk_iommu_probe(struct platform_device *pdev)
>               return -ENOMEM;
>       data->protect_base = ALIGN(virt_to_phys(protect), MTK_PROTECT_PA_ALIGN);
>  
> -     /* Whether the current dram is over 4GB */
> -     data->enable_4GB = !!(max_pfn > (BIT_ULL(32) >> PAGE_SHIFT));
> +     /* Whether the current dram is over 4GB, note: DRAM start at 1GB  */
> +     data->enable_4GB = !!(totalram_pages() > ((SZ_2G + SZ_1G) >> 
> PAGE_SHIFT));

A similar thing seems to be done by
drivers/media/platform/mtk-vpu/mtk_vpu.c:
        vpu->enable_4GB = !!(totalram_pages() > (SZ_2G >> PAGE_SHIFT));

I do wonder if some weird memory hotplug setups might give you false
negatives.

E.g., start a VM with 1GB and hotplug 1GB - it will be hotplugged on
x86-64 above 4GB, turning max_pfn into 5GB. totalram_pages() should
return something < 2GB.

Same can happen when you have a VM and use ballooning to fake-unplug
memory, making totalram_pages() return something < 4GB, but leaving
usable pfns >= 4GB.

but
... I don't know if I understood what "enable_4GB" needs/implies
... I don't know if this is applicable to VMs at all (on real HW such
    memory hotplug setups should not exist)
... I don't know how this code would react to memory hotplug, so if the
    condition changes after the driver loaded and enable_4GB would
    suddenly apply. Again, most probably not relevant on real HW, only
    for VMs.

-- 
Thanks,

David / dhildenb

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

Reply via email to