From: Klaus Jensen <its@irrelevant.dk>
To: Changqi Lu <luchangqi.123@bytedance.com>
Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org, kwolf@redhat.com,
hreitz@redhat.com, stefanha@redhat.com, fam@euphon.net,
ronniesahlberg@gmail.com, pbonzini@redhat.com, pl@dlhnet.de,
kbusch@kernel.org, foss@defmacro.it, philmd@linaro.org,
pizhenwei@bytedance.com, Klaus Jensen <k.jensen@samsung.com>
Subject: Re: [PATCH v9 09/10] hw/nvme: add reservation protocal command
Date: Wed, 28 Aug 2024 08:10:40 +0200 [thread overview]
Message-ID: <Zs6_YDFJOmEvPTAT@cormorant.local> (raw)
In-Reply-To: <20240712023650.45626-10-luchangqi.123@bytedance.com>
[-- Attachment #1: Type: text/plain, Size: 3798 bytes --]
On Jul 12 10:36, Changqi Lu wrote:
> Add reservation acquire, reservation register,
> reservation release and reservation report commands
> in the nvme device layer.
>
> By introducing these commands, this enables the nvme
> device to perform reservation-related tasks, including
> querying keys, querying reservation status, registering
> reservation keys, initiating and releasing reservations,
> as well as clearing and preempting reservations held by
> other keys.
>
> These commands are crucial for management and control of
> shared storage resources in a persistent manner.
> Signed-off-by: Changqi Lu <luchangqi.123@bytedance.com>
> Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
> Acked-by: Klaus Jensen <k.jensen@samsung.com>
> ---
> hw/nvme/ctrl.c | 318 +++++++++++++++++++++++++++++++++++++++++++
> hw/nvme/nvme.h | 4 +
> include/block/nvme.h | 37 +++++
> 3 files changed, 359 insertions(+)
>
> +static int nvme_read_reservation_cb(NvmeReadReservation *reservation)
> +{
> + int rc;
> + NvmeReservationStatus *nvme_status;
> + NvmeRequest *req = reservation->req;
> + NvmeCtrl *n = req->sq->ctrl;
> + NvmeResvKeys *keys_info = reservation->keys_info;
> + int len = sizeof(NvmeReservationStatusHeader) +
> + sizeof(NvmeRegisteredCtrl) * keys_info->num_keys;
> +
> + nvme_status = g_malloc(len);
> + nvme_status->header.gen = reservation->generation;
> + nvme_status->header.rtype = block_pr_type_to_nvme(reservation->type);
> + nvme_status->header.regctl = keys_info->num_keys;
> + for (int i = 0; i < keys_info->num_keys; i++) {
> + nvme_status->regctl_ds[i].cntlid = nvme_ctrl(req)->cntlid;
> + nvme_status->regctl_ds[i].rkey = keys_info->keys[i];
> + nvme_status->regctl_ds[i].rcsts = keys_info->keys[i] ==
> + reservation->key ? 1 : 0;
> + /* hostid is not supported currently */
> + memset(&nvme_status->regctl_ds[i].hostid, 0, 8);
> + }
> +
> + rc = nvme_c2h(n, (uint8_t *)nvme_status, len, req);
> + g_free(nvme_status);
> + return rc;
> +}
> +
> +static int nvme_read_reservation_ext_cb(NvmeReadReservation *reservation)
> +{
> + int rc;
> + NvmeReservationStatusExt *nvme_status_ext;
> + NvmeRequest *req = reservation->req;
> + NvmeCtrl *n = req->sq->ctrl;
> + NvmeResvKeys *keys_info = reservation->keys_info;
> + int len = sizeof(NvmeReservationStatusHeader) +
> + sizeof(uint8_t) * 40 +
> + sizeof(NvmeRegisteredCtrlExt) * keys_info->num_keys;
> +
> + nvme_status_ext = g_malloc(len);
This leaks heap memory due to uninitialized reserved fields in
NvmeReservationStatusExt. Prefer g_malloc0.
The one above in nvme_read_reservation_cb looks safe, but prefer
g_malloc0 there anyway.
> + nvme_status_ext->header.gen = cpu_to_be32(reservation->generation);
> + nvme_status_ext->header.rtype = block_pr_type_to_nvme(reservation->type);
> + nvme_status_ext->header.regctl = cpu_to_be16(keys_info->num_keys);
> +
> + for (int i = 0; i < keys_info->num_keys; i++) {
> + uint16_t ctnlid = nvme_ctrl(req)->cntlid;
> + nvme_status_ext->regctl_eds[i].cntlid = cpu_to_be16(ctnlid);
> + nvme_status_ext->regctl_eds[i].rkey = cpu_to_be64(keys_info->keys[i]);
> + nvme_status_ext->regctl_eds[i].rcsts = keys_info->keys[i] ==
> + reservation->key ? 1 : 0;
> + /* hostid is not supported currently */
> + memset(&nvme_status_ext->regctl_eds[i].hostid, 0, 16);
> + }
> +
> + rc = nvme_c2h(n, (uint8_t *)nvme_status_ext, len, req);
> + g_free(nvme_status_ext);
> + return rc;
> +}
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2024-08-28 6:11 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-12 2:36 [PATCH v9 00/10] Support persistent reservation operations Changqi Lu
2024-07-12 2:36 ` [PATCH v9 01/10] block: add persistent reservation in/out api Changqi Lu
2024-07-12 2:36 ` [PATCH v9 02/10] block/raw: add persistent reservation in/out driver Changqi Lu
2024-07-12 2:36 ` [PATCH v9 03/10] scsi/constant: add persistent reservation in/out protocol constants Changqi Lu
2024-07-12 2:36 ` [PATCH v9 04/10] scsi/util: add helper functions for persistent reservation types conversion Changqi Lu
2024-07-12 2:36 ` [PATCH v9 05/10] hw/scsi: add persistent reservation in/out api for scsi device Changqi Lu
2024-07-12 2:36 ` [PATCH v9 06/10] block/nvme: add reservation command protocol constants Changqi Lu
2024-07-12 2:36 ` [PATCH v9 07/10] hw/nvme: add helper functions for converting reservation types Changqi Lu
2024-07-12 2:36 ` [PATCH v9 08/10] hw/nvme: enable ONCS and rescap function Changqi Lu
2024-07-12 2:36 ` [PATCH v9 09/10] hw/nvme: add reservation protocal command Changqi Lu
2024-07-15 10:09 ` Klaus Jensen
2024-07-17 9:04 ` 卢长奇
[not found] ` <58383d65-83df-4527-81e4-b4d12c409b22@bytedance.com>
2024-07-26 2:42 ` 卢长奇
2024-07-26 6:25 ` Klaus Jensen
2024-07-26 9:54 ` [External] " 卢长奇
2024-08-28 6:05 ` Klaus Jensen
[not found] ` <3a799eb6-3350-4b35-8e75-68d9020443cb@bytedance.com>
2024-08-06 2:56 ` Ping: " 卢长奇
2024-08-18 16:57 ` Klaus Jensen
2024-08-28 6:10 ` Klaus Jensen [this message]
2024-08-28 6:27 ` [External] " 卢长奇
2024-08-28 6:51 ` Klaus Jensen
2024-08-28 7:20 ` [External] " 卢长奇
2024-08-28 7:27 ` Klaus Jensen
2024-07-12 2:36 ` [PATCH v9 10/10] block/iscsi: add persistent reservation in/out driver Changqi Lu
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=Zs6_YDFJOmEvPTAT@cormorant.local \
--to=its@irrelevant.dk \
--cc=fam@euphon.net \
--cc=foss@defmacro.it \
--cc=hreitz@redhat.com \
--cc=k.jensen@samsung.com \
--cc=kbusch@kernel.org \
--cc=kwolf@redhat.com \
--cc=luchangqi.123@bytedance.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=pizhenwei@bytedance.com \
--cc=pl@dlhnet.de \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=ronniesahlberg@gmail.com \
--cc=stefanha@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 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).