<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 2024-04-22 10:56, Christian König
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:c8e4a839-7f39-4cd9-a519-ce3c164464b5@amd.com">Am
      22.04.24 um 15:57 schrieb Philip Yang:
      <br>
      <blockquote type="cite">To test RDMA using dummy driver on the
        system without NIC/RDMA
        <br>
        device, the get/put dma pages pass in null device pointer, skip
        the
        <br>
        dma map/unmap resource and sg table to avoid null pointer
        access.
        <br>
      </blockquote>
      <br>
      Well that is completely illegal and would break IOMMU.
      <br>
      <br>
      Why does the RDMA driver does that in the first place?
      <br>
    </blockquote>
    <p>That is the amdp2ptest driver, part of KFDTest rdma test. The
      simple rdma test app and driver is used to test the driver path,
      without actually transferring data b/w machines.</p>
    <p>Regards,</p>
    <p>Philip<br>
    </p>
    <blockquote type="cite" cite="mid:c8e4a839-7f39-4cd9-a519-ce3c164464b5@amd.com">
      <br>
      Regards,
      <br>
      Christian.
      <br>
      <br>
      <blockquote type="cite">
        <br>
        Signed-off-by: Philip Yang <a class="moz-txt-link-rfc2396E" href="mailto:Philip.Yang@amd.com"><Philip.Yang@amd.com></a>
        <br>
        ---
        <br>
          drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 33
        +++++++++++---------
        <br>
          1 file changed, 19 insertions(+), 14 deletions(-)
        <br>
        <br>
        diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
        b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
        <br>
        index 9fe56a21ef88..0caf2c89ef1d 100644
        <br>
        --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
        <br>
        +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
        <br>
        @@ -705,12 +705,15 @@ int amdgpu_vram_mgr_alloc_sgt(struct
        amdgpu_device *adev,
        <br>
                  unsigned long size = min(cursor.size,
        MAX_SG_SEGMENT_SIZE);
        <br>
                  dma_addr_t addr;
        <br>
          -        addr = dma_map_resource(dev, phys, size, dir,
        <br>
        -                    DMA_ATTR_SKIP_CPU_SYNC);
        <br>
        -        r = dma_mapping_error(dev, addr);
        <br>
        -        if (r)
        <br>
        -            goto error_unmap;
        <br>
        -
        <br>
        +        if (dev) {
        <br>
        +            addr = dma_map_resource(dev, phys, size, dir,
        <br>
        +                        DMA_ATTR_SKIP_CPU_SYNC);
        <br>
        +            r = dma_mapping_error(dev, addr);
        <br>
        +            if (r)
        <br>
        +                goto error_unmap;
        <br>
        +        } else {
        <br>
        +            addr = phys;
        <br>
        +        }
        <br>
                  sg_set_page(sg, NULL, size, 0);
        <br>
                  sg_dma_address(sg) = addr;
        <br>
                  sg_dma_len(sg) = size;
        <br>
        @@ -724,10 +727,10 @@ int amdgpu_vram_mgr_alloc_sgt(struct
        amdgpu_device *adev,
        <br>
              for_each_sgtable_sg((*sgt), sg, i) {
        <br>
                  if (!sg->length)
        <br>
                      continue;
        <br>
        -
        <br>
        -        dma_unmap_resource(dev, sg->dma_address,
        <br>
        -                   sg->length, dir,
        <br>
        -                   DMA_ATTR_SKIP_CPU_SYNC);
        <br>
        +        if (dev)
        <br>
        +            dma_unmap_resource(dev, sg->dma_address,
        <br>
        +                       sg->length, dir,
        <br>
        +                       DMA_ATTR_SKIP_CPU_SYNC);
        <br>
              }
        <br>
              sg_free_table(*sgt);
        <br>
          @@ -752,10 +755,12 @@ void amdgpu_vram_mgr_free_sgt(struct
        device *dev,
        <br>
              struct scatterlist *sg;
        <br>
              int i;
        <br>
          -    for_each_sgtable_sg(sgt, sg, i)
        <br>
        -        dma_unmap_resource(dev, sg->dma_address,
        <br>
        -                   sg->length, dir,
        <br>
        -                   DMA_ATTR_SKIP_CPU_SYNC);
        <br>
        +    if (dev) {
        <br>
        +        for_each_sgtable_sg(sgt, sg, i)
        <br>
        +            dma_unmap_resource(dev, sg->dma_address,
        <br>
        +                       sg->length, dir,
        <br>
        +                       DMA_ATTR_SKIP_CPU_SYNC);
        <br>
        +    }
        <br>
              sg_free_table(sgt);
        <br>
              kfree(sgt);
        <br>
          }
        <br>
      </blockquote>
      <br>
    </blockquote>
  </body>
</html>