iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* DMA error when sg->offset value is greater than PAGE_SIZE in Intel IOMMU
@ 2017-09-16  6:11 Harsh Jain
  2017-09-20  8:01 ` Herbert Xu
  0 siblings, 1 reply; 42+ messages in thread
From: Harsh Jain @ 2017-09-16  6:11 UTC (permalink / raw)
  To: dwmw2, joro, linux-crypto, iommu; +Cc: linux-kernel, leedom

Hi,

While debugging DMA mapping error in chelsio crypto driver we observed that when scatter/gather list received by driver has some entry with page->offset > 4096 (PAGE_SIZE). It starts giving DMA error.  Without IOMMU it works fine.

Before reaching to chelsio crypto driver(driver/crypto/chelsio) following entities change the sg'

1) IN esp_output() "__skb_to_sgvec()" convert skb frags to scatter gather list. At that moment sg->offset was 4094.
2) From esp_output control reaches to "crypto_authenc_encrypt()". Here in "scatterwalk_ffwd()" sg->offset become 4110.
3) Same sg list received by chelsio crypto driver(chcr). When chcr try to do DMA mapping it starts giving DMA errors.

Following error observed. first two prints are added for debugging in chcr. Kernel version used to reproduce is 4.9.28 on x86_64.

Sep 15 12:40:52 heptagon kernel: process_cipher req src ffff8803cb41f0a8
Sep 15 12:40:52 heptagon kernel: ========= issue    hit offset:4110 ======= dma_addr f24b000e ==> DMA mapped address returned by dma_map_sg()

Sep 15 12:40:52 heptagon kernel: DMAR: DRHD: handling fault status reg 2
Sep 15 12:40:52 heptagon kernel: DMAR: [DMA Write] Request device [02:00.4] fault addr f24b0000 [fault reason 05] PTE Write access is not set

 By applying following hack in kernel. Things start working.

diff --git a/crypto/scatterwalk.c b/crypto/scatterwalk.c
index c16c94f8..1d75a3a 100644
--- a/crypto/scatterwalk.c
+++ b/crypto/scatterwalk.c
@@ -78,6 +78,8 @@ struct scatterlist *scatterwalk_ffwd(struct scatterlist dst[2]
                                     struct scatterlist *src,
                                     unsigned int len)
 {
+       unsigned int mod_page_offset;
+
        for (;;) {
                if (!len)
                        return src;
@@ -90,7 +92,9 @@ struct scatterlist *scatterwalk_ffwd(struct scatterlist dst[2]
        }

        sg_init_table(dst, 2);
-       sg_set_page(dst, sg_page(src), src->length - len, src->offset + len);
+        mod_page_offset = (src->offset + len) / PAGE_SIZE;
+       sg_set_page(dst, sg_page(src) + mod_page_offset, src->length - len,
+                   (src->offset + len) - (mod_page_offset * PAGE_SIZE));
        scatterwalk_crypto_chain(dst, sg_next(src), 0, 2);


1) We are not expecting issue in "scatterwalk_ffwd" because it is not the only place where kernel 
updates src->offset without checking page boundary. similar logic used in "__skb_to_sgvec".
 
2) It cannot be driver's responsibilty to update received sg entries to adjust offset and page 
because we are not the only one who directly uses received sg list.

3) Since Without IOMMU every thing works fine. We are expecting IOMMU bugs.

Regards

Harsh Jain

^ permalink raw reply related	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2017-10-01  8:59 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-16  6:11 DMA error when sg->offset value is greater than PAGE_SIZE in Intel IOMMU Harsh Jain
2017-09-20  8:01 ` Herbert Xu
2017-09-20 10:12   ` Robin Murphy
2017-09-20 11:20     ` Harsh Jain
2017-09-25 17:46     ` Casey Leedom
2017-09-25 15:54       ` Raj, Ashok
2017-09-25 18:46         ` Casey Leedom
2017-09-26  3:46           ` Harsh Jain
     [not found]             ` <afa02763-4556-0e14-7d1b-1c044cdc1ff7-ut6Up61K2wZBDgjK7y7TUQ@public.gmane.org>
2017-09-26 12:21               ` Harsh Jain
2017-09-26 14:22                 ` Robin Murphy
2017-09-26 14:34                   ` Raj, Ashok
2017-09-26 14:40                     ` Raj, Ashok
2017-09-26 20:50                       ` Casey Leedom
2017-09-26 18:15                     ` Robin Murphy
     [not found]                   ` <437a9bd8-d4d6-22ca-1a64-1a3e73f1101a-5wv7dgnIgG8@public.gmane.org>
2017-09-26 16:06                     ` Casey Leedom
2017-09-26 16:10                       ` Dan Williams
2017-09-27 16:31                         ` Casey Leedom
     [not found]                           ` <MWHPR12MB160060436AC70CB5BE8C0C6EC8780-Gy0DoCVfaSVsWITs4OkDoAdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-09-27 17:13                             ` Dan Williams
2017-10-01  8:59                               ` Christoph Hellwig
2017-09-27 17:18                           ` Robin Murphy
     [not found]                             ` <20170927181802.3dcd7efb-h2/QxWiDqNo@public.gmane.org>
2017-09-27 14:48                               ` Raj, Ashok
2017-09-27 21:29                                 ` Casey Leedom
     [not found]                                   ` <MWHPR12MB16005D59D7A33F3D5BE43395C8780-Gy0DoCVfaSVsWITs4OkDoAdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-09-27 19:07                                     ` Raj, Ashok
2017-09-27 22:13                                       ` Casey Leedom
2017-09-28  5:01                                         ` Harsh Jain
     [not found]                                         ` <MWHPR12MB16007E5363E79173C52BFA19C8780-Gy0DoCVfaSVsWITs4OkDoAdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-09-28 10:33                                           ` Herbert Xu
     [not found]                                             ` <20170928103312.GB8118-lOAM2aK0SrRLBo1qDEOMRrpzq4S04n8Q@public.gmane.org>
2017-09-28 11:11                                               ` Harsh Jain
2017-09-28 13:38                                     ` Harsh Jain
2017-09-28 13:05                                       ` Raj, Ashok
2017-09-29  5:37                                         ` Harsh Jain
2017-09-27 17:30                             ` Casey Leedom
2017-09-26 17:30                     ` Casey Leedom
2017-09-25 19:31       ` Dan Williams
     [not found]         ` <CAPcyv4j3J41eY2eR07nTvo75F0yCbL9bNHM8GmXEFOHDQUuf8Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-09-25 20:05           ` Casey Leedom
     [not found]             ` <MWHPR12MB1600948B2F57696189FC7C22C87A0-Gy0DoCVfaSVsWITs4OkDoAdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-09-25 20:11               ` Dan Williams
2017-09-25 19:03                 ` Raj, Ashok
2017-09-25 23:41                   ` Casey Leedom
2017-09-26 13:04                 ` Harsh Jain
2017-09-20 11:30   ` Harsh Jain
2017-09-25 18:45   ` David Woodhouse
2017-09-25 20:19     ` Casey Leedom
2017-09-26 11:17     ` Harsh Jain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).