Re: [PATCH 1/2] nvme: fix racy access to FDP placement ID array
From: Kanchan Joshi
Date: Mon Jul 27 2026 - 09:57:47 EST
On 7/25/2026 7:21 PM, Hari Mishal wrote:
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -1018,15 +1018,19 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,
> if (req->cmd_flags & REQ_RAHEAD)
> dsmgmt |= NVME_RW_DSM_FREQ_PREFETCH;
>
> - if (op == nvme_cmd_write && ns->head->nr_plids) {
> - u16 write_stream = req->bio->bi_write_stream;
> -
> - if (WARN_ON_ONCE(write_stream > ns->head->nr_plids))
> - return BLK_STS_INVAL;
> -
> - if (write_stream) {
> - dsmgmt |= ns->head->plids[write_stream - 1] << 16;
> - control |= NVME_RW_DTYPE_DPLCMT;
> + if (op == nvme_cmd_write) {
> + scoped_guard(spinlock, &ns->head->fdp_lock) {
> + u16 write_stream = req->bio->bi_write_stream;
> +
> + if (ns->head->nr_plids) {
> + if (WARN_ON_ONCE(write_stream > ns->head->nr_plids))
> + return BLK_STS_INVAL;
> +
> + if (write_stream) {
> + dsmgmt |= ns->head->plids[write_stream - 1] << 16;
> + control |= NVME_RW_DTYPE_DPLCMT;
> + }
> + }
It will be nice not to have the impact on the fast-path performance.
The spin-lock is being taken for each write, regardless of FDP-enabled
config. And for fdp-enabled config also, bi_write_stream may just be 0.