From: Tejun Heo <tj@kernel.org>
To: Yu Kuai <yukuai1@huaweicloud.com>
Cc: axboe@kernel.dk, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org, yukuai3@huawei.com,
yi.zhang@huawei.com
Subject: Re: [PATCH -next 2/5] blk-iocost: don't release 'ioc->lock' while updating params
Date: Tue, 11 Oct 2022 06:56:50 -1000 [thread overview]
Message-ID: <Y0WgUgfRcKhaXiLx@slm.duckdns.org> (raw)
In-Reply-To: <20221011083547.1831389-3-yukuai1@huaweicloud.com>
On Tue, Oct 11, 2022 at 04:35:44PM +0800, Yu Kuai wrote:
> From: Yu Kuai <yukuai3@huawei.com>
>
> ioc_qos_write() and ioc_cost_model_write() are the same:
>
> 1) hold lock to read 'ioc->params' to local variable;
> 2) update params to local variable without lock;
> 3) hold lock to write local variable to 'ioc->params';
>
> In theroy, if user updates params concurrenty, the params might be lost:
>
> t1: update params a t2: update params b
> spin_lock_irq(&ioc->lock);
> memcpy(qos, ioc->params.qos, sizeof(qos))
> spin_unlock_irq(&ioc->lock);
>
> qos[a] = xxx;
>
> spin_lock_irq(&ioc->lock);
> memcpy(qos, ioc->params.qos, sizeof(qos))
> spin_unlock_irq(&ioc->lock);
>
> qos[b] = xxx;
>
> spin_lock_irq(&ioc->lock);
> memcpy(ioc->params.qos, qos, sizeof(qos));
> ioc_refresh_params(ioc, true);
> spin_unlock_irq(&ioc->lock);
>
> spin_lock_irq(&ioc->lock);
> // updates of a will be lost
> memcpy(ioc->params.qos, qos, sizeof(qos));
> ioc_refresh_params(ioc, true);
> spin_unlock_irq(&ioc->lock);
>
> Althrough this is not common case, the problem can by fixed easily by
> holding the lock through the read, update, write process.
>
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Acked-by: Tejun Heo <tj@kernel.org>
Thanks.
--
tejun
next prev parent reply other threads:[~2022-10-11 16:56 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-11 8:35 [PATCH -next 0/5] blk-iocost: some random patches to improve iocost Yu Kuai
2022-10-11 8:35 ` [PATCH -next 1/5] blk-iocost: disable writeback throttling Yu Kuai
2022-10-11 16:54 ` Tejun Heo
2022-10-11 8:35 ` [PATCH -next 2/5] blk-iocost: don't release 'ioc->lock' while updating params Yu Kuai
2022-10-11 16:56 ` Tejun Heo [this message]
2022-10-11 8:35 ` [PATCH -next 3/5] blk-iocost: prevent configuration update concurrent with io throttling Yu Kuai
2022-10-11 17:03 ` Tejun Heo
2022-10-11 8:35 ` [PATCH -next 4/5] blk-iocost: bypass if only one cgroup issues io Yu Kuai
2022-10-11 17:02 ` Tejun Heo
2022-10-12 1:33 ` Yu Kuai
2022-10-12 8:04 ` Tejun Heo
2022-10-11 8:35 ` [PATCH -next 5/5] blk-iocost: read 'ioc->params' inside 'ioc->lock' in ioc_timer_fn() Yu Kuai
2022-10-11 17:01 ` Tejun Heo
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=Y0WgUgfRcKhaXiLx@slm.duckdns.org \
--to=tj@kernel.org \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=yi.zhang@huawei.com \
--cc=yukuai1@huaweicloud.com \
--cc=yukuai3@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®