<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.freebsd.org/bugzilla/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.freebsd.org/bugzilla/"
          
          maintainer="bugmeister@FreeBSD.org"
>

    <bug>
          <bug_id>251462</bug_id>
          
          <creation_ts>2020-11-29 18:33:22 +0000</creation_ts>
          <short_desc>Failing transfers over nfsv4 with krb5i on CPU with SHA acceleration</short_desc>
          <delta_ts>2021-05-27 13:51:44 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>Base System</product>
          <component>kern</component>
          <version>12.2-RELEASE</version>
          <rep_platform>amd64</rep_platform>
          <op_sys>Any</op_sys>
          <bug_status>Closed</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>---</priority>
          <bug_severity>Affects Some People</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Žilvinas Žaltiena">zaltys</reporter>
          <assigned_to name="Mark Johnston">markj</assigned_to>
          <cc>kib</cc>
    
    <cc>markj</cc>
    
    <cc>mav</cc>
    
    <cc>pen</cc>
    
    <cc>zaltys</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1133993</commentid>
    <comment_count>0</comment_count>
    <who name="Žilvinas Žaltiena">zaltys</who>
    <bug_when>2020-11-29 18:33:22 +0000</bug_when>
    <thetext>Initially I stumbled on this problem on TrueNAS12, but for debug purposes reproduced it on FreeBSD 12.0, 12.1, and 12.2, because TrueNAS uses FreeBSD as upstream/base OS.

I have setup an FreeBSD 12.x nfsv4 server requiring krb5i (note &quot;i&quot; - with integrity). Clients are Linux 5.8. Everything is joined to Active Directory and using aes256-cts-hmac-sha1-96 as cipher suite for kerberos. 

The problem:

If I run FreeBSD server inside VM on Intel Atom C3558 CPU, only small file  transfers succeed. Files transfers over 200MB become increasingly unreliable: they either hang (server timeout) or terminate with input/output error. After network traffic ceases, gssd on server still has high CPU usage for a while. Server side logs do not contain anything related. This CPU has AES-NI and SHA support.

What I have tried to narrow the culprit down:
1) Downgrading the security to krb5 (no integrity, just auth) fixed the transfers and saturated gigabit link.
2) Disabling aesni module fixed the failing transfers with krb5i.
3) Patching aesni module (so that detection of CPU support for SHA always failed) also fixed the failing transfers even with aesni module loaded.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1136494</commentid>
    <comment_count>1</comment_count>
    <who name="Žilvinas Žaltiena">zaltys</who>
    <bug_when>2020-12-15 11:52:07 +0000</bug_when>
    <thetext>I reproduced this on AMD Ryzen 7 3800X CPU too, which also has SHA extensions. NFS transfers fail with krb5i, if aesni modules is loaded.

I tried running crypto tests from FreeBSD tests suite. They passed successfully.

One interesting thing is forcing sync on NFS mount on Linux client makes transfers succeed even with aesni module loaded on FreeBSD server, but at 2-3x lower speed (80-100MB/s vs 25MB/s). Normally Linux client piles the data in the memory until application closes/locks/flushes the file or there is no more memory, and only then client starts sending it to server.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1137102</commentid>
    <comment_count>2</comment_count>
    <who name="Žilvinas Žaltiena">zaltys</who>
    <bug_when>2020-12-18 19:55:43 +0000</bug_when>
    <thetext>If nfsd on FreeBSD is explicitly limited to single thread, i.e. rc.conf with:

nfs_server_flags=&quot;-t -n 1&quot;

then transfers succeed with kr5i/krb5p and aesni module loaded even if linux client does not use sync mount option. If thread count is set to &gt; 1, original problem reappears. Some sort of thread safety / locking issue in sha part of aesni module?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1145036</commentid>
    <comment_count>3</comment_count>
    <who name="Konstantin Belousov">kib</who>
    <bug_when>2021-02-04 18:16:51 +0000</bug_when>
    <thetext>Try https://reviews.freebsd.org/D28485</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1154953</commentid>
    <comment_count>4</comment_count>
    <who name="Žilvinas Žaltiena">zaltys</who>
    <bug_when>2021-04-07 19:06:24 +0000</bug_when>
    <thetext>I am sorry for not replying earlier. I haven&apos;t got any email about update on this bug.

I tried patching aesni_cipher_setup() and leaving only

kt = is_fpu_kern_thread(0);

as per D28485, but it didn&apos;t help. Note, that I am on 12.2 and that line looked a bit different than in D28485, however I think idea behind it was the same anyways.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1158509</commentid>
    <comment_count>5</comment_count>
    <who name="Mark Johnston">markj</who>
    <bug_when>2021-04-27 00:20:28 +0000</bug_when>
    <thetext>(In reply to Žilvinas Žaltiena from comment #4)
Could you try https://reviews.freebsd.org/D30001 ?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1158545</commentid>
    <comment_count>6</comment_count>
    <who name="Žilvinas Žaltiena">zaltys</who>
    <bug_when>2021-04-27 11:52:00 +0000</bug_when>
    <thetext>I can confirm applying patch from https://reviews.freebsd.org/D30001 has fixed the failing krb5i/krb5p transfers on my system.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1158625</commentid>
    <comment_count>7</comment_count>
    <who name="Mark Johnston">markj</who>
    <bug_when>2021-04-27 21:39:23 +0000</bug_when>
    <thetext>(In reply to Žilvinas Žaltiena from comment #6)
Thanks, it is fixed in stable/12 now.  I think this should be an EN candidate for 12.2, meaning that we&apos;ll release a binary patch for it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1163386</commentid>
    <comment_count>8</comment_count>
    <who name="Mark Johnston">markj</who>
    <bug_when>2021-05-27 13:51:44 +0000</bug_when>
    <thetext>Fixed in FreeBSD-EN-21:11.aesni.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>