From: Gollu Appalanaidu <anaidu.gollu@samsung.com>
To: Klaus Jensen <its@irrelevant.dk>
Cc: Kevin Wolf <kwolf@redhat.com>,
qemu-block@nongnu.org, Klaus Jensen <k.jensen@samsung.com>,
qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>,
Keith Busch <kbusch@kernel.org>
Subject: Re: [PATCH v2 2/2] hw/block/nvme: fix ref counting in nvme_format_ns
Date: Mon, 29 Mar 2021 18:14:10 +0530 [thread overview]
Message-ID: <20210329124410.GA20319@2030045822> (raw)
In-Reply-To: <20210322120944.225643-3-its@irrelevant.dk>
[-- Attachment #1: Type: text/plain, Size: 1621 bytes --]
On Mon, Mar 22, 2021 at 01:09:44PM +0100, Klaus Jensen wrote:
>From: Klaus Jensen <k.jensen@samsung.com>
>
>Max noticed that since blk_aio_pwrite_zeroes() may invoke the callback
>before returning, the callbacks will never see *count == 0 and thus
>never free the count variable or decrement num_formats causing a CQE to
>never be posted.
>
>Coverity (CID 1451082) also picked up on the fact that count would not
>be free'ed if the namespace was of zero size.
>
>Fix both of these issues by explicitly checking *count and finalize for
>the given namespace if --(*count) is zero. Enqueing a CQE if there are
>no AIOs outstanding after this case is already handled by nvme_format()
>by inspecting *num_formats.
>
>Reported-by: Max Reitz <mreitz@redhat.com>
>Reported-by: Coverity (CID 1451082)
>Fixes: dc04d25e2f3f ("hw/block/nvme: add support for the format nvm command")
>Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
>---
> hw/block/nvme.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
>diff --git a/hw/block/nvme.c b/hw/block/nvme.c
>index 6842b01ab58b..c54ec3c9523c 100644
>--- a/hw/block/nvme.c
>+++ b/hw/block/nvme.c
>@@ -5009,9 +5009,15 @@ static uint16_t nvme_format_ns(NvmeCtrl *n, NvmeNamespace *ns, uint8_t lbaf,
>
> }
>
>- (*count)--;
>+ if (--(*count)) {
>+ return NVME_NO_COMPLETE;
>+ }
>
>- return NVME_NO_COMPLETE;
>+ g_free(count);
>+ ns->status = 0x0;
>+ (*num_formats)--;
>+
>+ return NVME_SUCCESS;
> }
Reviewed-by: Gollu Appalanaidu <anaidu.gollu@samsung.com>
>
> static uint16_t nvme_format(NvmeCtrl *n, NvmeRequest *req)
>--
>2.31.0
>
>
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
next prev parent reply other threads:[~2021-03-29 13:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-22 12:09 [PATCH v2 0/2] hw/block/nvme: coverity fixes Klaus Jensen
2021-03-22 12:09 ` [PATCH v2 1/2] hw/block/nvme: fix resource leak in nvme_dif_rw Klaus Jensen
[not found] ` <CGME20210329112015epcas5p4dc86c66a4f27d13d3689923d381c5fa6@epcas5p4.samsung.com>
2021-03-29 11:17 ` Gollu Appalanaidu
2021-03-22 12:09 ` [PATCH v2 2/2] hw/block/nvme: fix ref counting in nvme_format_ns Klaus Jensen
[not found] ` <CGME20210329124718epcas5p4781757a155f3fd07f8280c388f6fc073@epcas5p4.samsung.com>
2021-03-29 12:44 ` Gollu Appalanaidu [this message]
2021-03-24 20:04 ` [PATCH v2 0/2] hw/block/nvme: coverity fixes Klaus Jensen
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=20210329124410.GA20319@2030045822 \
--to=anaidu.gollu@samsung.com \
--cc=its@irrelevant.dk \
--cc=k.jensen@samsung.com \
--cc=kbusch@kernel.org \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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).