All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Kent Overstreet <kent.overstreet@gmail.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-block <linux-block@vger.kernel.org>,
	Jens Axboe <axboe@kernel.dk>,
	Christoph Hellwig <hch@infradead.org>,
	colyli@suse.de, Mike Snitzer <snitzer@redhat.com>,
	"Darrick J. Wong" <darrick.wong@oracle.com>,
	Chris Mason <clm@fb.com>,
	bacik@fb.com, linux-xfs <linux-xfs@vger.kernel.org>,
	drbd-dev@lists.linbit.com,
	linux-btrfs <linux-btrfs@vger.kernel.org>,
	"open list:SOFTWARE RAID (Multiple Disks) SUPPORT"
	<linux-raid@vger.kernel.org>, NeilBrown <neilb@suse.com>
Subject: Re: [PATCH 06/12] md: convert to bioset_init()/mempool_init()
Date: Fri, 1 Jun 2018 12:51:59 +0200	[thread overview]
Message-ID: <CAK8P3a2mO1OaZOtB97-GtP4gDcmqgL1SMdwT7HJLdFrUutK4ZA@mail.gmail.com> (raw)
In-Reply-To: <20180520222558.7053-7-kent.overstreet@gmail.com>

On Mon, May 21, 2018 at 12:25 AM, Kent Overstreet
<kent.overstreet@gmail.com> wrote:

> @@ -510,7 +510,10 @@ static void mddev_delayed_delete(struct work_struct *ws);
>
>  static void mddev_put(struct mddev *mddev)
>  {
> -       struct bio_set *bs = NULL, *sync_bs = NULL;
> +       struct bio_set bs, sync_bs;
> +
> +       memset(&bs, 0, sizeof(bs));
> +       memset(&sync_bs, 0, sizeof(sync_bs));
>
>         if (!atomic_dec_and_lock(&mddev->active, &all_mddevs_lock))
>                 return;
> @@ -521,8 +524,8 @@ static void mddev_put(struct mddev *mddev)
>                 list_del_init(&mddev->all_mddevs);
>                 bs = mddev->bio_set;
>                 sync_bs = mddev->sync_set;
> -               mddev->bio_set = NULL;
> -               mddev->sync_set = NULL;
> +               memset(&mddev->bio_set, 0, sizeof(mddev->bio_set));
> +               memset(&mddev->sync_set, 0, sizeof(mddev->sync_set));
>                 if (mddev->gendisk) {
>                         /* We did a probe so need to clean up.  Call
>                          * queue_work inside the spinlock so that
> @@ -535,10 +538,8 @@ static void mddev_put(struct mddev *mddev)
>                         kfree(mddev);
>         }
>         spin_unlock(&all_mddevs_lock);
> -       if (bs)
> -               bioset_free(bs);
> -       if (sync_bs)
> -               bioset_free(sync_bs);
> +       bioset_exit(&bs);
> +       bioset_exit(&sync_bs);
>  }

This has triggered a new warning in randconfig builds for me, on 32-bit:

drivers/md/md.c: In function 'mddev_put':
drivers/md/md.c:564:1: error: the frame size of 1096 bytes is larger
than 1024 bytes [-Werror=frame-larger-than=]

and on 64-bit:

drivers/md/md.c: In function 'mddev_put':
drivers/md/md.c:564:1: error: the frame size of 2112 bytes is larger
than 2048 bytes [-Werror=frame-larger-than=]

The size of bio_set is a bit configuration dependent, but it looks like this is
a bit too big to put on the stack either way, epsecially when you traverse
a list and copy two of them with assignments for each loop in 'bs =
mddev->bio_set'.

A related problem is that calling bioset_exit on a copy of the bio_set
might not do the right thing. The function is defined as

void bioset_exit(struct bio_set *bs)
{
        if (bs->rescue_workqueue)
                destroy_workqueue(bs->rescue_workqueue);
        bs->rescue_workqueue = NULL;

        mempool_exit(&bs->bio_pool);
        mempool_exit(&bs->bvec_pool);

        bioset_integrity_free(bs);
        if (bs->bio_slab)
                bio_put_slab(bs);
        bs->bio_slab = NULL;
}

So it calls a couple of functions (detroy_workqueue, mempool_exit,
bioset_integrity_free, bio_put_slab), each of which might rely on
a the structure being the same one that was originally allocated.
If the structure contains any kind of linked list entry, passing a copy
into the list management functions would guarantee corruption.

I could not come up with an obvious fix, but maybe it's possible
to change mddev_put() to do call bioset_exit() before the
structure gets freed? Something like the (completely untested
and probably wrong somewhere) patch below

Signed-off-by: Arnd Bergmann <arnd@arndb.de>

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 411f60d591d1..3bf54591ddcd 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -531,11 +531,6 @@ static void mddev_delayed_delete(struct work_struct *ws);

 static void mddev_put(struct mddev *mddev)
 {
-       struct bio_set bs, sync_bs;
-
-       memset(&bs, 0, sizeof(bs));
-       memset(&sync_bs, 0, sizeof(sync_bs));
-
        if (!atomic_dec_and_lock(&mddev->active, &all_mddevs_lock))
                return;
        if (!mddev->raid_disks && list_empty(&mddev->disks) &&
@@ -543,10 +538,14 @@ static void mddev_put(struct mddev *mddev)
                /* Array is not configured at all, and not held active,
                 * so destroy it */
                list_del_init(&mddev->all_mddevs);
-               bs = mddev->bio_set;
-               sync_bs = mddev->sync_set;
+               spin_unlock(&all_mddevs_lock);
+
+               bioset_exit(&mddev->bio_set);
                memset(&mddev->bio_set, 0, sizeof(mddev->bio_set));
+
+               bioset_exit(&mddev->sync_set);
                memset(&mddev->sync_set, 0, sizeof(mddev->sync_set));
+
                if (mddev->gendisk) {
                        /* We did a probe so need to clean up.  Call
                         * queue_work inside the spinlock so that
@@ -557,10 +556,9 @@ static void mddev_put(struct mddev *mddev)
                        queue_work(md_misc_wq, &mddev->del_work);
                } else
                        kfree(mddev);
+       } else {
+               spin_unlock(&all_mddevs_lock);
        }
-       spin_unlock(&all_mddevs_lock);
-       bioset_exit(&bs);
-       bioset_exit(&sync_bs);
 }

 static void md_safemode_timeout(struct timer_list *t);

  reply	other threads:[~2018-06-01 10:51 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-20 22:25 [PATCH 00/13] convert block layer to bioset_init()/mempool_init() Kent Overstreet
2018-05-20 22:25 ` [PATCH 01/12] block: convert bounce, q->bio_split " Kent Overstreet
2018-05-22 10:08   ` Christoph Hellwig
2018-05-20 22:25 ` [PATCH 02/12] drbd: convert " Kent Overstreet
2018-05-20 22:25 ` [PATCH 03/12] pktcdvd: " Kent Overstreet
2018-05-20 22:25 ` [PATCH 04/12] lightnvm: " Kent Overstreet
2018-05-22 10:10   ` Javier Gonzalez
2018-05-20 22:25 ` [PATCH 05/12] bcache: " Kent Overstreet
2018-05-21  3:58   ` Coly Li
2018-05-20 22:25 ` [PATCH 06/12] md: " Kent Overstreet
2018-06-01 10:51   ` Arnd Bergmann [this message]
2018-05-20 22:25 ` [PATCH 07/12] dm: " Kent Overstreet
     [not found]   ` <20180520222558.7053-8-kent.overstreet-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-05-30 19:27     ` Mike Snitzer
2018-05-30 19:27       ` Mike Snitzer
2018-05-20 22:25 ` [PATCH 08/12] target: " Kent Overstreet
2018-05-22 10:09   ` Christoph Hellwig
2018-05-20 22:25 ` [PATCH 09/12] fs: convert block_dev.c to bioset_init() Kent Overstreet
2018-05-22 10:09   ` Christoph Hellwig
2018-05-20 22:25 ` [PATCH 10/12] btrfs: convert to bioset_init()/mempool_init() Kent Overstreet
2018-05-30 21:30   ` Chris Mason
2018-05-30 21:30     ` Chris Mason
2018-05-20 22:25 ` [PATCH 11/12] xfs: " Kent Overstreet
2018-05-21 18:39   ` Darrick J. Wong
     [not found]   ` <20180520222558.7053-12-kent.overstreet-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-05-22 10:10     ` Christoph Hellwig
2018-05-22 10:10       ` Christoph Hellwig
2018-05-20 22:25 ` [PATCH 12/12] block: Drop bioset_create() Kent Overstreet
2018-05-22 10:10   ` Christoph Hellwig
2018-05-20 23:08 ` [PATCH 00/13] convert block layer to bioset_init()/mempool_init() NeilBrown
2018-05-20 23:08   ` NeilBrown
2018-05-20 23:11   ` Kent Overstreet
     [not found] ` <20180520222558.7053-1-kent.overstreet-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-05-21 14:03   ` Mike Snitzer
2018-05-21 14:03     ` Mike Snitzer
2018-05-21 14:19     ` Jens Axboe
     [not found]       ` <686d7df6-c7d1-48a6-b7ff-48dc8aff6a62-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2018-05-21 14:31         ` Mike Snitzer
2018-05-21 14:31           ` Mike Snitzer
2018-05-21 14:36           ` Jens Axboe
     [not found]             ` <2bbeeb1a-8b99-b06a-eb9b-eb8523c16460-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2018-05-21 14:47               ` Mike Snitzer
2018-05-21 14:47                 ` Mike Snitzer
     [not found]                 ` <20180521144703.GA19303-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-05-21 14:52                   ` Jens Axboe
2018-05-21 14:52                     ` Jens Axboe
     [not found]                     ` <4b343aef-e11c-73ba-1d88-7e73ca838cad-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2018-05-21 15:04                       ` Mike Snitzer
2018-05-21 15:04                         ` Mike Snitzer
     [not found]                         ` <20180521150439.GA19379-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-05-21 15:09                           ` Jens Axboe
2018-05-21 15:09                             ` Jens Axboe
     [not found]                             ` <61e30dcf-a01c-f47d-087a-12930caf9aef-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2018-05-21 15:18                               ` Mike Snitzer
2018-05-21 15:18                                 ` Mike Snitzer
     [not found]                                 ` <20180521151817.GA19454-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-05-21 15:36                                   ` Jens Axboe
2018-05-21 15:36                                     ` Jens Axboe
     [not found]                                     ` <d01a150a-7752-f6ce-78f2-17a65c1e6fa5-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2018-05-21 16:09                                       ` Mike Snitzer
2018-05-21 16:09                                         ` Mike Snitzer
     [not found]                                         ` <20180521160907.GA19553-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-05-21 16:20                                           ` Jens Axboe
2018-05-21 16:20                                             ` Jens Axboe
     [not found]                                             ` <f9e3714c-b7c9-d5f6-4018-2a87dd5babb2-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2018-05-30 13:36                                               ` Mike Snitzer
2018-05-30 13:36                                                 ` Mike Snitzer
     [not found]                                                 ` <20180530133629.GC5157-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-05-30 18:55                                                   ` Jens Axboe
2018-05-30 18:55                                                     ` Jens Axboe
2018-05-30 19:34                                                     ` Kent Overstreet
2018-05-30 19:36                                                       ` Jens Axboe
2018-05-30 19:36                                                         ` Jens Axboe
2018-05-30 19:37                                                     ` Mike Snitzer
     [not found]                                                       ` <20180530193707.GB6568-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-05-30 19:38                                                         ` Jens Axboe
2018-05-30 19:38                                                           ` Jens Axboe
2018-05-21 17:37                                         ` Kent Overstreet
2018-05-21 18:24                                           ` Mike Snitzer
2018-05-21 18:24                                             ` Mike Snitzer
2018-05-21 23:38                                             ` Kent Overstreet
2018-05-22  6:41                                               ` Christoph Hellwig
     [not found]                                                 ` <20180522064118.GA18704-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2018-05-22 19:09                                                   ` Mike Snitzer
2018-05-22 19:09                                                     ` Mike Snitzer
2018-05-21 15:12       ` David Sterba
2018-05-21 15:18         ` Jens Axboe
2018-05-21 14:20 ` Jens Axboe
2018-05-30 22:24 ` Jens Axboe
2018-05-20 23:11 [PATCH 06/12] md: convert " Kent Overstreet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAK8P3a2mO1OaZOtB97-GtP4gDcmqgL1SMdwT7HJLdFrUutK4ZA@mail.gmail.com \
    --to=arnd@arndb.de \
    --cc=axboe@kernel.dk \
    --cc=bacik@fb.com \
    --cc=clm@fb.com \
    --cc=colyli@suse.de \
    --cc=darrick.wong@oracle.com \
    --cc=drbd-dev@lists.linbit.com \
    --cc=hch@infradead.org \
    --cc=kent.overstreet@gmail.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=neilb@suse.com \
    --cc=snitzer@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.