Author: scottl
Date: Tue Feb  6 06:55:55 2018
New Revision: 328919
URL: https://svnweb.freebsd.org/changeset/base/328919

Log:
  Fix a case where a request frame can be composed that requires 2 or more
  SGList elements, but there's only enough space in the request frame for
  either 1 element or a chain frame pointer.  Previously, the code would
  hit the wrong case, add the SGList element, but then fail to add the
  chain frame due to lack of space.  Re-arrange the code to catch this case
  earlier and handle it.
  
  Sponsored by: Netflix

Modified:
  head/sys/dev/mps/mps.c

Modified: head/sys/dev/mps/mps.c
==============================================================================
--- head/sys/dev/mps/mps.c      Tue Feb  6 06:42:25 2018        (r328918)
+++ head/sys/dev/mps/mps.c      Tue Feb  6 06:55:55 2018        (r328919)
@@ -2609,6 +2609,17 @@ mps_push_sge(struct mps_command *cm, void *sgep, size_
        if (cm->cm_sglsize < MPS_SGC_SIZE)
                panic("MPS: Need SGE Error Code\n");
 
+       if (segsleft >= 1 && cm->cm_sglsize < len + MPS_SGC_SIZE) {
+               /*
+                * 1 or more segment, enough room for only a chain.
+                * Hope the previous element wasn't a Simple entry
+                * that needed to be marked with
+                * MPI2_SGE_FLAGS_LAST_ELEMENT.  Case (4).
+                */
+               if ((error = mps_add_chain(cm)) != 0)
+                       return (error);
+       }
+
        if (segsleft >= 2 &&
            cm->cm_sglsize < len + MPS_SGC_SIZE + MPS_SGE64_SIZE) {
                /*
@@ -2631,17 +2642,6 @@ mps_push_sge(struct mps_command *cm, void *sgep, size_
                bcopy(sgep, cm->cm_sge, len);
                cm->cm_sge = (MPI2_SGE_IO_UNION *)((uintptr_t)cm->cm_sge + len);
                return (mps_add_chain(cm));
-       }
-
-       if (segsleft >= 1 && cm->cm_sglsize < len + MPS_SGC_SIZE) {
-               /*
-                * 1 or more segment, enough room for only a chain.
-                * Hope the previous element wasn't a Simple entry
-                * that needed to be marked with
-                * MPI2_SGE_FLAGS_LAST_ELEMENT.  Case (4).
-                */
-               if ((error = mps_add_chain(cm)) != 0)
-                       return (error);
        }
 
 #ifdef INVARIANTS
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to