From: Andrew Morton <akpm@linux-foundation.org>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: linux-kernel@vger.kernel.org, tglx@linutronix.de,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
linux-mm@kvack.org, Jens Axboe <axboe@kernel.dk>
Subject: Re: [PATCH 3/6] bdi: Use refcount_t for reference counting instead atomic_t
Date: Mon, 16 Jul 2018 15:57:16 -0700 [thread overview]
Message-ID: <20180716155716.1f7ac43d211133a8cb476637@linux-foundation.org> (raw)
In-Reply-To: <20180703200141.28415-4-bigeasy@linutronix.de>
On Tue, 3 Jul 2018 22:01:38 +0200 Sebastian Andrzej Siewior <bigeasy@linutronix.de> wrote:
> refcount_t type and corresponding API should be used instead of atomic_t when
> the variable is used as a reference counter. This allows to avoid accidental
> refcounter overflows that might lead to use-after-free situations.
>
> ...
>
> --- a/mm/backing-dev.c
> +++ b/mm/backing-dev.c
> @@ -438,10 +438,10 @@ wb_congested_get_create(struct backing_dev_info *bdi, int blkcg_id, gfp_t gfp)
> if (new_congested) {
> /* !found and storage for new one already allocated, insert */
> congested = new_congested;
> - new_congested = NULL;
> rb_link_node(&congested->rb_node, parent, node);
> rb_insert_color(&congested->rb_node, &bdi->cgwb_congested_tree);
> - goto found;
> + spin_unlock_irqrestore(&cgwb_lock, flags);
> + return congested;
> }
>
> spin_unlock_irqrestore(&cgwb_lock, flags);
> @@ -451,13 +451,13 @@ wb_congested_get_create(struct backing_dev_info *bdi, int blkcg_id, gfp_t gfp)
> if (!new_congested)
> return NULL;
>
> - atomic_set(&new_congested->refcnt, 0);
> + refcount_set(&new_congested->refcnt, 1);
> new_congested->__bdi = bdi;
> new_congested->blkcg_id = blkcg_id;
> goto retry;
>
> found:
> - atomic_inc(&congested->refcnt);
> + refcount_inc(&congested->refcnt);
> spin_unlock_irqrestore(&cgwb_lock, flags);
> kfree(new_congested);
> return congested;
>
> ...
>
I'm not sure that the restructuring of wb_congested_get_create() was
desirable and it does make the patch harder to review. But it looks
OK to me.
next prev parent reply other threads:[~2018-07-16 22:57 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-03 20:01 [PATCH 0/6] use irqsafe variant of refcount_dec_and_lock() / atomic_dec_and_lock() Sebastian Andrzej Siewior
2018-07-03 20:01 ` [PATCH 1/6] drivers/md/raid5: Use irqsave variant of atomic_dec_and_lock() Sebastian Andrzej Siewior
2018-07-16 12:27 ` Sebastian Andrzej Siewior
2018-07-17 0:37 ` Shaohua Li
2018-07-18 10:57 ` Sebastian Andrzej Siewior
2018-07-19 2:44 ` Shaohua Li
2018-07-19 7:35 ` Sebastian Andrzej Siewior
2018-07-03 20:01 ` [PATCH 2/6] drivers/md/raid5: Do not disable irq on release_inactive_stripe_list() call Sebastian Andrzej Siewior
2018-07-20 8:29 ` Sebastian Andrzej Siewior
2018-07-03 20:01 ` [PATCH 3/6] bdi: Use refcount_t for reference counting instead atomic_t Sebastian Andrzej Siewior
2018-07-16 12:30 ` Sebastian Andrzej Siewior
2018-07-16 22:57 ` Andrew Morton [this message]
2018-07-17 15:56 ` Sebastian Andrzej Siewior
2018-07-03 20:01 ` [PATCH 4/6] bdi: Use irqsave variant of refcount_dec_and_lock() Sebastian Andrzej Siewior
2018-07-03 20:01 ` [PATCH 5/6] userns: Use refcount_t for reference counting instead atomic_t Sebastian Andrzej Siewior
2018-07-16 12:39 ` Sebastian Andrzej Siewior
2018-07-03 20:01 ` [PATCH 6/6] userns: Use irqsave variant of refcount_dec_and_lock() Sebastian Andrzej Siewior
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=20180716155716.1f7ac43d211133a8cb476637@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=bigeasy@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/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 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).