CAAM operation fails with DMA Error when using global buffers

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CAAM operation fails with DMA Error when using global buffers

Jump to solution
2,309 Views
dhanushkadangam
Contributor III

I'm using CAAM through Linux Crypto API as shown in kernel source tree crypto/tcrypt.c in a kernel module.

See the code segment below. I've changed the test_acipher_speed taken from tcrypt.c in my kernel module implementation to use BUFFSIZE instead of PAGE_SIZE.

When I build this to use memory allocated by kmalloc, the encryption succeeds, but when I build it to use the global array, buf, the encryption fails with the following error:

caam_jr 2142000.jr1: 40001016: DECO: desc idx 16: DMA Error

I'm running this on an iMX6UL with a 3.14.38 kernel. Why does global array test fail? Thank you.

//#define USE_KMALLOC

#define TVMEMSIZE 4

#define BUFFSIZE  128

static char *tvmem[TVMEMSIZE];

static u32 block_sizes[] = { 16, 0 };

static u8 speed_template_16[] = {16};

static char buf[BUFFSIZE*TVMEMSIZE];

static int __init testmodule_init(void)

{

   int i;

#ifndef  USE_KMALLOC

   char* buffer = buf;

#else // USE_KMALLOC

   char* buffer = (char*)kmalloc(BUFFSIZE*TVMEMSIZE, GFP_KERNEL);

#endif   // USE_KMALLOC

   for (i = 0; i < TVMEMSIZE; i++)

   {

      tvmem[i] = buffer + i*BUFFSIZE;

   }

   test_acipher_speed("ecb(aes)", ENCRYPT, 0, NULL, 0, speed_template_16);

#ifdef  USE_KMALLOC

   if (buffer)

   {

      kfree(buffer);

   }

#endif   // USE_KMALLOC

   return 0;

}

Labels (2)
0 Kudos
Reply
1 Solution
1,984 Views
Yuri
NXP Employee
NXP Employee

Hello,

  Yes, it is needed to use the GFP_DMA flag of the kmalloc, which is used to specify that the allocator
must satisfy the request from
ZONE_DMA. This flag is used by device drivers, which need DMA-able
memory for their devices.

Have a great day,
Yuri

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

6 Replies
1,984 Views
dhanushkadangam
Contributor III

I think I figured out the reason for DMA Error.

In linux kernel documentation https://www.kernel.org/doc/Documentation/DMA-API-HOWTO.txt, What memory is DMA'able? section it says

"If you acquired your memory via the page allocator (i.e. __get_free_page*()) or the generic memory allocators (i.e. kmalloc() or kmem_cache_alloc()) then you may DMA to/from that memory using the addresses returned from those routines.

:

This rule also means that you may use neither kernel image addresses (items in data/text/bss segments), nor module image addresses, nor stack addresses for DMA"

1,985 Views
Yuri
NXP Employee
NXP Employee

Hello,

  Yes, it is needed to use the GFP_DMA flag of the kmalloc, which is used to specify that the allocator
must satisfy the request from
ZONE_DMA. This flag is used by device drivers, which need DMA-able
memory for their devices.

Have a great day,
Yuri

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,984 Views
dhanushkadangam
Contributor III

Hi Yuri,

Now I'm trying to use the secure-memory as the source and destination with CAAM async-block ciphers through Linux crypto-API. I obtain the source and destination slots from secure-memory using sm_keystore_slot_alloc as shown below in the code segment. Error checking has been omitted for brevity here, but I do check for errors in the real code.

The crypto operation completes successfully, but when I check the dst location, it's contents remain the same, as if no crypto operation occurred. Why is this happening?

Thank you!

   :

   u8 __iomem *src, *dst;

   struct caam_drv_private_sm *kspriv = dev_get_drvdata(ksdev);

   sm_establish_keystore(ksdev, 1);

  

   sm_keystore_slot_alloc(ksdev, 1, slotsize, &keyslot1);

   src = kspriv->slot_get_address(ksdev, 1, keyslot1);

  

   sm_keystore_slot_alloc(ksdev, 1, slotsize, &keyslot2);

   dst = kspriv->slot_get_address(ksdev, 1, keyslot2);

   // use src and dst with CAAM

   :

0 Kudos
Reply
1,984 Views
Yuri
NXP Employee
NXP Employee

Hello,

perhaps we have the same cache coherence issue ?

Are there CAAM errors ?

Regards,

Yuri.

0 Kudos
Reply
1,984 Views
dhanushkadangam
Contributor III

Hi Yuri,

CAAM doesn't report any error. It says the operation is successful.

Can you please explain how cache coherency could come in here?

Thanks

0 Kudos
Reply
1,984 Views
Yuri
NXP Employee
NXP Employee

Hello,

  As for coherency : all buffers should not be cached.

Regards,

Yuri.

0 Kudos
Reply