<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#008000;margin:15pt;" align="Left">
[Public]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Reviewed-by: Alex Deucher <alexander.deucher@amd.com><br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Grodzovsky, Andrey <Andrey.Grodzovsky@amd.com><br>
<b>Sent:</b> Tuesday, May 18, 2021 10:01 AM<br>
<b>To:</b> dri-devel@lists.freedesktop.org <dri-devel@lists.freedesktop.org>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org>; linux-pci@vger.kernel.org <linux-pci@vger.kernel.org>; ckoenig.leichtzumerken@gmail.com <ckoenig.leichtzumerken@gmail.com>;
 daniel.vetter@ffwll.ch <daniel.vetter@ffwll.ch>; Wentland, Harry <Harry.Wentland@amd.com><br>
<b>Cc:</b> ppaalanen@gmail.com <ppaalanen@gmail.com>; Deucher, Alexander <Alexander.Deucher@amd.com>; gregkh@linuxfoundation.org <gregkh@linuxfoundation.org>; helgaas@kernel.org <helgaas@kernel.org>; Kuehling, Felix <Felix.Kuehling@amd.com><br>
<b>Subject:</b> Re: [PATCH] drm/amdgpu: Unmap all MMIO mappings</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Ping<br>
<br>
Andrey<br>
<br>
On 2021-05-17 3:31 p.m., Andrey Grodzovsky wrote:<br>
> Access to those must be prevented post pci_remove<br>
> <br>
> v6: Drop BOs list, unampping VRAM BAR is enough.<br>
> v8:<br>
> Add condition of xgmi.connected_to_cpu to MTTR<br>
> handling and remove MTTR handling from the old place.<br>
> <br>
> Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com><br>
> ---<br>
>   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 26 +++++++++++++++++++---<br>
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c |  4 ----<br>
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |  4 ----<br>
>   3 files changed, 23 insertions(+), 11 deletions(-)<br>
> <br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
> index f7cca25c0fa0..8b50315d1fe1 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
> @@ -3666,6 +3666,27 @@ int amdgpu_device_init(struct amdgpu_device *adev,<br>
>        return r;<br>
>   }<br>
>   <br>
> +static void amdgpu_device_unmap_mmio(struct amdgpu_device *adev)<br>
> +{<br>
> +     /* Clear all CPU mappings pointing to this device */<br>
> +     unmap_mapping_range(adev->ddev.anon_inode->i_mapping, 0, 0, 1);<br>
> +<br>
> +     /* Unmap all mapped bars - Doorbell, registers and VRAM */<br>
> +     amdgpu_device_doorbell_fini(adev);<br>
> +<br>
> +     iounmap(adev->rmmio);<br>
> +     adev->rmmio = NULL;<br>
> +     if (adev->mman.aper_base_kaddr)<br>
> +             iounmap(adev->mman.aper_base_kaddr);<br>
> +     adev->mman.aper_base_kaddr = NULL;<br>
> +<br>
> +     /* Memory manager related */<br>
> +     if (!adev->gmc.xgmi.connected_to_cpu) {<br>
> +             arch_phys_wc_del(adev->gmc.vram_mtrr);<br>
> +             arch_io_free_memtype_wc(adev->gmc.aper_base, adev->gmc.aper_size);<br>
> +     }<br>
> +}<br>
> +<br>
>   /**<br>
>    * amdgpu_device_fini - tear down the driver<br>
>    *<br>
> @@ -3712,6 +3733,8 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)<br>
>        amdgpu_device_ip_fini_early(adev);<br>
>   <br>
>        amdgpu_gart_dummy_page_fini(adev);<br>
> +<br>
> +     amdgpu_device_unmap_mmio(adev);<br>
>   }<br>
>   <br>
>   void amdgpu_device_fini_sw(struct amdgpu_device *adev)<br>
> @@ -3739,9 +3762,6 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)<br>
>        }<br>
>        if ((adev->pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA)<br>
>                vga_client_register(adev->pdev, NULL, NULL, NULL);<br>
> -     iounmap(adev->rmmio);<br>
> -     adev->rmmio = NULL;<br>
> -     amdgpu_device_doorbell_fini(adev);<br>
>   <br>
>        if (IS_ENABLED(CONFIG_PERF_EVENTS))<br>
>                amdgpu_pmu_fini(adev);<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c<br>
> index 0adffcace326..8eabe3c9ad17 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c<br>
> @@ -1107,10 +1107,6 @@ int amdgpu_bo_init(struct amdgpu_device *adev)<br>
>   void amdgpu_bo_fini(struct amdgpu_device *adev)<br>
>   {<br>
>        amdgpu_ttm_fini(adev);<br>
> -     if (!adev->gmc.xgmi.connected_to_cpu) {<br>
> -             arch_phys_wc_del(adev->gmc.vram_mtrr);<br>
> -             arch_io_free_memtype_wc(adev->gmc.aper_base, adev->gmc.aper_size);<br>
> -     }<br>
>   }<br>
>   <br>
>   /**<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
> index 0d54e70278ca..58ad2fecc9e3 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
> @@ -1841,10 +1841,6 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)<br>
>        amdgpu_bo_free_kernel(&adev->mman.discovery_memory, NULL, NULL);<br>
>        amdgpu_ttm_fw_reserve_vram_fini(adev);<br>
>   <br>
> -     if (adev->mman.aper_base_kaddr)<br>
> -             iounmap(adev->mman.aper_base_kaddr);<br>
> -     adev->mman.aper_base_kaddr = NULL;<br>
> -<br>
>        amdgpu_vram_mgr_fini(adev);<br>
>        amdgpu_gtt_mgr_fini(adev);<br>
>        ttm_range_man_fini(&adev->mman.bdev, AMDGPU_PL_GDS);<br>
> <br>
</div>
</span></font></div>
</div>
</body>
</html>