From: Yishai Hadas via Virtualization <virtualization@lists.linux-foundation.org>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: kvm@vger.kernel.org, maorg@nvidia.com,
virtualization@lists.linux-foundation.org, jgg@nvidia.com,
jiri@nvidia.com, leonro@nvidia.com
Subject: Re: [PATCH V2 vfio 5/9] virtio-pci: Initialize the supported admin commands
Date: Mon, 30 Oct 2023 18:06:45 +0200 [thread overview]
Message-ID: <4e95d66c-c382-4612-8d4b-7ff2b0acd3fb@nvidia.com> (raw)
In-Reply-To: <20231030115541-mutt-send-email-mst@kernel.org>
On 30/10/2023 17:57, Michael S. Tsirkin wrote:
> On Mon, Oct 30, 2023 at 05:27:50PM +0200, Yishai Hadas wrote:
>> On 29/10/2023 22:17, Michael S. Tsirkin wrote:
>>> On Sun, Oct 29, 2023 at 05:59:48PM +0200, Yishai Hadas wrote:
>>>> Initialize the supported admin commands upon activating the admin queue.
>>>>
>>>> The supported commands are saved as part of the admin queue context, it
>>>> will be used by the next patches from this series.
>>>>
>>>> Note:
>>>> As we don't want to let upper layers to execute admin commands before
>>>> that this initialization step was completed, we set ref count to 1 only
>>>> post of that flow and use a non ref counted version command for this
>>>> internal flow.
>>>>
>>>> Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
>>>> ---
>>>> drivers/virtio/virtio_pci_common.h | 1 +
>>>> drivers/virtio/virtio_pci_modern.c | 77 +++++++++++++++++++++++++++++-
>>>> 2 files changed, 77 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/virtio/virtio_pci_common.h b/drivers/virtio/virtio_pci_common.h
>>>> index a21b9ba01a60..9e07e556a51a 100644
>>>> --- a/drivers/virtio/virtio_pci_common.h
>>>> +++ b/drivers/virtio/virtio_pci_common.h
>>>> @@ -46,6 +46,7 @@ struct virtio_pci_admin_vq {
>>>> struct virtio_pci_vq_info info;
>>>> struct completion flush_done;
>>>> refcount_t refcount;
>>>> + u64 supported_cmds;
>>>> /* Name of the admin queue: avq.$index. */
>>>> char name[10];
>>>> u16 vq_index;
>>>> diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c
>>>> index ccd7a4d9f57f..25e27aa79cab 100644
>>>> --- a/drivers/virtio/virtio_pci_modern.c
>>>> +++ b/drivers/virtio/virtio_pci_modern.c
>>>> @@ -19,6 +19,9 @@
>>>> #define VIRTIO_RING_NO_LEGACY
>>>> #include "virtio_pci_common.h"
>>>> +static int vp_modern_admin_cmd_exec(struct virtio_device *vdev,
>>>> + struct virtio_admin_cmd *cmd);
>>>> +
>>> I don't much like forward declarations. Just order functions sensibly
>>> and they will not be needed.
>> OK, will be part of V3.
>>
>>>> static u64 vp_get_features(struct virtio_device *vdev)
>>>> {
>>>> struct virtio_pci_device *vp_dev = to_vp_device(vdev);
>>>> @@ -59,6 +62,42 @@ vp_modern_avq_set_abort(struct virtio_pci_admin_vq *admin_vq, bool abort)
>>>> WRITE_ONCE(admin_vq->abort, abort);
>>>> }
>>>> +static void virtio_pci_admin_init_cmd_list(struct virtio_device *virtio_dev)
>>>> +{
>>>> + struct virtio_pci_device *vp_dev = to_vp_device(virtio_dev);
>>>> + struct virtio_admin_cmd cmd = {};
>>>> + struct scatterlist result_sg;
>>>> + struct scatterlist data_sg;
>>>> + __le64 *data;
>>>> + int ret;
>>>> +
>>>> + data = kzalloc(sizeof(*data), GFP_KERNEL);
>>>> + if (!data)
>>>> + return;
>>>> +
>>>> + sg_init_one(&result_sg, data, sizeof(*data));
>>>> + cmd.opcode = cpu_to_le16(VIRTIO_ADMIN_CMD_LIST_QUERY);
>>>> + cmd.group_type = cpu_to_le16(VIRTIO_ADMIN_GROUP_TYPE_SRIOV);
>>>> + cmd.result_sg = &result_sg;
>>>> +
>>>> + ret = vp_modern_admin_cmd_exec(virtio_dev, &cmd);
>>>> + if (ret)
>>>> + goto end;
>>>> +
>>>> + sg_init_one(&data_sg, data, sizeof(*data));
>>>> + cmd.opcode = cpu_to_le16(VIRTIO_ADMIN_CMD_LIST_USE);
>>>> + cmd.data_sg = &data_sg;
>>>> + cmd.result_sg = NULL;
>>>> +
>>>> + ret = vp_modern_admin_cmd_exec(virtio_dev, &cmd);
>>>> + if (ret)
>>>> + goto end;
>>>> +
>>>> + vp_dev->admin_vq.supported_cmds = le64_to_cpu(*data);
>>>> +end:
>>>> + kfree(data);
>>>> +}
>>>> +
>>>> static void vp_modern_avq_activate(struct virtio_device *vdev)
>>>> {
>>>> struct virtio_pci_device *vp_dev = to_vp_device(vdev);
>>>> @@ -67,6 +106,7 @@ static void vp_modern_avq_activate(struct virtio_device *vdev)
>>>> if (!virtio_has_feature(vdev, VIRTIO_F_ADMIN_VQ))
>>>> return;
>>>> + virtio_pci_admin_init_cmd_list(vdev);
>>>> init_completion(&admin_vq->flush_done);
>>>> refcount_set(&admin_vq->refcount, 1);
>>>> vp_modern_avq_set_abort(admin_vq, false);
>>>> @@ -562,6 +602,35 @@ static bool vp_get_shm_region(struct virtio_device *vdev,
>>>> return true;
>>>> }
>>>> +static int __virtqueue_exec_admin_cmd(struct virtio_pci_admin_vq *admin_vq,
>>>> + struct scatterlist **sgs,
>>>> + unsigned int out_num,
>>>> + unsigned int in_num,
>>>> + void *data,
>>>> + gfp_t gfp)
>>>> +{
>>>> + struct virtqueue *vq;
>>>> + int ret, len;
>>>> +
>>>> + vq = admin_vq->info.vq;
>>>> +
>>>> + ret = virtqueue_add_sgs(vq, sgs, out_num, in_num, data, gfp);
>>>> + if (ret < 0)
>>>> + return ret;
>>>> +
>>>> + if (unlikely(!virtqueue_kick(vq)))
>>>> + return -EIO;
>>>> +
>>>> + while (!virtqueue_get_buf(vq, &len) &&
>>>> + !virtqueue_is_broken(vq))
>>>> + cpu_relax();
>>>> +
>>>> + if (virtqueue_is_broken(vq))
>>>> + return -EIO;
>>>> +
>>>> + return 0;
>>>> +}
>>>> +
>>> This is tolerable I guess but it might pin the CPU for a long time.
>>> The difficulty is handling suprize removal well which we currently
>>> don't do with interrupts. I would say it's ok as is but add
>>> a TODO comments along the lines of /* TODO: use interrupts once these virtqueue_is_broken */
>> I assume that you asked for adding the below comment before the while loop:
>> /* TODO use interrupts to reduce cpu cycles in the future */
>>
>> Right ?
>>
>> Yishai
> Well I wrote what I meant. in the future is redundant - everyone knows
> we can't change the past.
I agree, no need for 'in the future'.
However, in your suggestion you mentioned "once these virtqueue_is_broken".
What does that mean in current polling mode ?
Yishai
>
>>>> static int virtqueue_exec_admin_cmd(struct virtio_pci_admin_vq *admin_vq,
>>>> struct scatterlist **sgs,
>>>> unsigned int out_num,
>>>> @@ -653,7 +722,13 @@ static int vp_modern_admin_cmd_exec(struct virtio_device *vdev,
>>>> in_num++;
>>>> }
>>>> - ret = virtqueue_exec_admin_cmd(&vp_dev->admin_vq, sgs,
>>>> + if (cmd->opcode == VIRTIO_ADMIN_CMD_LIST_QUERY ||
>>>> + cmd->opcode == VIRTIO_ADMIN_CMD_LIST_USE)
>>>> + ret = __virtqueue_exec_admin_cmd(&vp_dev->admin_vq, sgs,
>>>> + out_num, in_num,
>>>> + sgs, GFP_KERNEL);
>>>> + else
>>>> + ret = virtqueue_exec_admin_cmd(&vp_dev->admin_vq, sgs,
>>>> out_num, in_num,
>>>> sgs, GFP_KERNEL);
>>>> if (ret) {
>>>> --
>>>> 2.27.0
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
next prev parent reply other threads:[~2023-10-30 16:07 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-29 15:59 [PATCH V2 vfio 0/9] Introduce a vfio driver over virtio devices Yishai Hadas via Virtualization
2023-10-29 15:59 ` [PATCH V2 vfio 1/9] virtio: Define feature bit for administration virtqueue Yishai Hadas via Virtualization
2023-10-29 15:59 ` [PATCH V2 vfio 2/9] virtio-pci: Introduce admin virtqueue Yishai Hadas via Virtualization
2023-10-29 20:22 ` Michael S. Tsirkin
2023-10-30 15:51 ` Parav Pandit via Virtualization
2023-10-30 15:59 ` Michael S. Tsirkin
2023-10-30 18:10 ` Parav Pandit via Virtualization
2023-10-30 23:31 ` Michael S. Tsirkin
2023-10-31 3:11 ` Parav Pandit via Virtualization
2023-10-31 7:59 ` Michael S. Tsirkin
2023-10-31 12:11 ` Parav Pandit via Virtualization
2023-10-29 15:59 ` [PATCH V2 vfio 3/9] virtio-pci: Introduce admin command sending function Yishai Hadas via Virtualization
2023-10-29 20:26 ` Michael S. Tsirkin
2023-10-29 15:59 ` [PATCH V2 vfio 4/9] virtio-pci: Introduce admin commands Yishai Hadas via Virtualization
2023-10-29 15:59 ` [PATCH V2 vfio 5/9] virtio-pci: Initialize the supported " Yishai Hadas via Virtualization
2023-10-29 20:17 ` Michael S. Tsirkin
2023-10-30 15:27 ` Yishai Hadas via Virtualization
2023-10-30 15:57 ` Michael S. Tsirkin
2023-10-30 16:06 ` Yishai Hadas via Virtualization [this message]
2023-10-30 23:30 ` Michael S. Tsirkin
2023-11-03 0:33 ` kernel test robot
2023-11-03 7:39 ` Michael S. Tsirkin
2023-10-29 15:59 ` [PATCH V2 vfio 6/9] virtio-pci: Introduce APIs to execute legacy IO " Yishai Hadas via Virtualization
2023-10-31 8:09 ` Michael S. Tsirkin
2023-10-31 8:30 ` Yishai Hadas via Virtualization
2023-10-31 9:00 ` Michael S. Tsirkin
2023-10-29 15:59 ` [PATCH V2 vfio 7/9] vfio/pci: Expose vfio_pci_core_setup_barmap() Yishai Hadas via Virtualization
2023-10-29 15:59 ` [PATCH V2 vfio 8/9] vfio/pci: Expose vfio_pci_iowrite/read##size() Yishai Hadas via Virtualization
2023-10-29 15:59 ` [PATCH V2 vfio 9/9] vfio/virtio: Introduce a vfio driver over virtio devices Yishai Hadas via Virtualization
[not found] ` <4a5ab8d6-1138-4f4f-bb61-9ec0309d46e6@intel.com>
2023-10-31 8:23 ` Michael S. Tsirkin
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=4e95d66c-c382-4612-8d4b-7ff2b0acd3fb@nvidia.com \
--to=virtualization@lists.linux-foundation.org \
--cc=jgg@nvidia.com \
--cc=jiri@nvidia.com \
--cc=kvm@vger.kernel.org \
--cc=leonro@nvidia.com \
--cc=maorg@nvidia.com \
--cc=mst@redhat.com \
--cc=yishaih@nvidia.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).