lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <94059f5c-10dd-4d75-a69c-76b21ff49546@amd.com>
Date:   Fri, 27 Oct 2023 19:05:17 +0530
From:   "NK, JESHWANTHKUMAR" <jeshwanthkumar.nk@....com>
To:     Christoph Hellwig <hch@...radead.org>
Cc:     thomas.lendacky@....com, john.allen@....com,
        herbert@...dor.apana.org.au, davem@...emloft.net,
        jens.wiklander@...aro.org, sumit.garg@...aro.org,
        jarkko.nikula@...ux.intel.com, mario.limonciello@....com,
        linux-crypto@...r.kernel.org, linux-kernel@...r.kernel.org,
        op-tee@...ts.trustedfirmware.org,
        Mythri.Pandeshwarakrishna@....com, Devaraj.Rangasamy@....com,
        Rijo-john.Thomas@....com, nimesh.easow@....com
Subject: Re: [PATCH 1/3] crypto: ccp - Add function to allocate and free
 memory using DMA APIs


On 27-Oct-23 10:54 AM, Christoph Hellwig wrote:
> On Wed, Oct 25, 2023 at 12:26:58PM +0530, jeshwank wrote:
>> +	tee_buf->vaddr = dma_alloc_coherent(psp->dev, size, &tee_buf->dma, gfp);
>> +	if (!tee_buf->vaddr || !tee_buf->dma) {
>> +		kfree(tee_buf);
>> +		return NULL;
>> +	}
>> +
>> +	tee_buf->size = size;
>> +
>> +	/* Check whether IOMMU is present. If present, translate IOVA
>> +	 * to physical address, else the dma handle is the physical
>> +	 * address.
>> +	 */
>> +	dom = iommu_get_domain_for_dev(psp->dev);
>> +	if (dom)
>> +		tee_buf->paddr = iommu_iova_to_phys(dom, tee_buf->dma);
>> +	else
> No, you can't mix the DMA API and iommu API.  You need to stick to one
> or the other.

Can you please elaborate a bit more? Is it because in the presence of IOMMU,
a contiguous DMA or bus-address-space "buffer" may be mapped non-contiguously
into the physical address space? As a result, for buffers larger than a page
size, when PSP tries to map the physical address into it's address space, the
PSP Trusted OS will not be able to read back the entire buffer data.

                CPU                  CPU                  Bus
              Virtual              Physical             Address
              Address              Address               Space
               Space                Space

             +-------+             +------+             +------+
             |       |             |MMIO  |   Offset    |      |
             |       |  Virtual    |Space |   applied   |      |
           C +-------+ --------> B +------+ ----------> +------+ A
             |       |  mapping    |      |   by host   |      |
   +-----+   |       |             |      |   bridge    |      |   +--------+
   |     |   |       |             +------+             |      |   |        |
   | CPU |   |       |             | RAM  |             |      |   | Device |
   |     |   |       |             |      |             |      |   |        |
   +-----+   +-------+             +------+             +------+   +--------+
             |       |  Virtual    |Buffer|   Mapping   |      |
           X +-------+ --------> Y +------+ <---------- +------+ Z
             |       |  mapping    | RAM  |   by IOMMU
             |       |             |      |
             |       |             |      |
             +-------+             +------+

Reference diagram from: 
https://www.kernel.org/doc/Documentation/DMA-API-HOWTO.txt


Regards,

Jeshwanth

>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ