The branch stable/13 has been updated by markj:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=14c0cde468e136a007a5a7e1bcb7b3a50a2a8b57

commit 14c0cde468e136a007a5a7e1bcb7b3a50a2a8b57
Author:     Mark Johnston <[email protected]>
AuthorDate: 2022-01-27 14:53:02 +0000
Commit:     Mark Johnston <[email protected]>
CommitDate: 2022-02-10 13:46:12 +0000

    shsec: Allocate data blocks only for BIO_READ/WRITE requests
    
    In particular, there is no need to allocate a data block when passing
    BIO_FLUSH requests to child providers, and g_io_request() asserts that
    bp->bio_data == NULL for such requests.
    
    PR:             255131
    Reported and tested by: [email protected]
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit a2dfffb98917a57bfacb155b9d7d423c3e8ff792)
---
 sys/geom/shsec/g_shsec.c | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/sys/geom/shsec/g_shsec.c b/sys/geom/shsec/g_shsec.c
index a3b2f59d0555..2b9e127ce350 100644
--- a/sys/geom/shsec/g_shsec.c
+++ b/sys/geom/shsec/g_shsec.c
@@ -272,8 +272,10 @@ g_shsec_done(struct bio *bp)
                            (ssize_t)pbp->bio_length);
                }
        }
-       explicit_bzero(bp->bio_data, bp->bio_length);
-       uma_zfree(g_shsec_zone, bp->bio_data);
+       if (bp->bio_data != NULL) {
+               explicit_bzero(bp->bio_data, bp->bio_length);
+               uma_zfree(g_shsec_zone, bp->bio_data);
+       }
        g_destroy_bio(bp);
        pbp->bio_inbed++;
        if (pbp->bio_children == pbp->bio_inbed) {
@@ -351,20 +353,22 @@ g_shsec_start(struct bio *bp)
                 * Fill in the component buf structure.
                 */
                cbp->bio_done = g_shsec_done;
-               cbp->bio_data = uma_zalloc(g_shsec_zone, M_NOWAIT);
-               if (cbp->bio_data == NULL) {
-                       g_shsec_alloc_failed++;
-                       error = ENOMEM;
-                       goto failure;
-               }
                cbp->bio_caller2 = sc->sc_disks[no];
-               if (bp->bio_cmd == BIO_WRITE) {
-                       if (no == 0) {
-                               dst = (uint32_t *)cbp->bio_data;
-                               bcopy(bp->bio_data, dst, len);
-                       } else {
-                               g_shsec_xor2((uint32_t *)cbp->bio_data, dst,
-                                   len);
+               if (bp->bio_cmd == BIO_READ || bp->bio_cmd == BIO_WRITE) {
+                       cbp->bio_data = uma_zalloc(g_shsec_zone, M_NOWAIT);
+                       if (cbp->bio_data == NULL) {
+                               g_shsec_alloc_failed++;
+                               error = ENOMEM;
+                               goto failure;
+                       }
+                       if (bp->bio_cmd == BIO_WRITE) {
+                               if (no == 0) {
+                                       dst = (uint32_t *)cbp->bio_data;
+                                       bcopy(bp->bio_data, dst, len);
+                               } else {
+                                       g_shsec_xor2((uint32_t *)cbp->bio_data,
+                                           dst, len);
+                               }
                        }
                }
        }

Reply via email to