From: Simon Horman <horms@kernel.org>
To: Yahui Cao <yahui.cao@intel.com>
Cc: kevin.tian@intel.com, yishaih@nvidia.com, brett.creeley@amd.com,
kvm@vger.kernel.org, netdev@vger.kernel.org, edumazet@google.com,
shameerali.kolothum.thodi@huawei.com, alex.williamson@redhat.com,
madhu.chittim@intel.com, intel-wired-lan@lists.osuosl.org,
jgg@nvidia.com, sridhar.samudrala@intel.com, kuba@kernel.org,
pabeni@redhat.com, davem@davemloft.net
Subject: Re: [Intel-wired-lan] [PATCH iwl-next v4 05/12] ice: Log virtual channel messages in PF
Date: Wed, 29 Nov 2023 17:12:22 +0000 [thread overview]
Message-ID: <20231129171222.GF43811@kernel.org> (raw)
In-Reply-To: <20231121025111.257597-6-yahui.cao@intel.com>
On Tue, Nov 21, 2023 at 02:51:04AM +0000, Yahui Cao wrote:
> From: Lingyu Liu <lingyu.liu@intel.com>
>
> Save the virtual channel messages sent by VF on the source side during
> runtime. The logged virtchnl messages will be transferred and loaded
> into the device on the destination side during the device resume stage.
>
> For the feature which can not be migrated yet, it must be disabled or
> blocked to prevent from being abused by VF. Otherwise, it may introduce
> functional and security issue. Mask unsupported VF capability flags in
> the VF-PF negotiaion stage.
>
> Signed-off-by: Lingyu Liu <lingyu.liu@intel.com>
> Signed-off-by: Yahui Cao <yahui.cao@intel.com>
Hi Lingyu Liu and Yahui Cao,
some minor feedback from my side.
...
> diff --git a/drivers/net/ethernet/intel/ice/ice_migration.c b/drivers/net/ethernet/intel/ice/ice_migration.c
...
> +/**
> + * ice_migration_log_vf_msg - Log request message from VF
> + * @vf: pointer to the VF structure
> + * @event: pointer to the AQ event
> + *
> + * Log VF message for later device state loading during live migration
> + *
> + * Return 0 for success, negative for error
> + */
> +int ice_migration_log_vf_msg(struct ice_vf *vf,
> + struct ice_rq_event_info *event)
> +{
> + struct ice_migration_virtchnl_msg_listnode *msg_listnode;
> + u32 v_opcode = le32_to_cpu(event->desc.cookie_high);
> + struct device *dev = ice_pf_to_dev(vf->pf);
> + u16 msglen = event->msg_len;
> + u8 *msg = event->msg_buf;
> +
> + if (!ice_migration_is_loggable_msg(v_opcode))
> + return 0;
> +
> + if (vf->virtchnl_msg_num >= VIRTCHNL_MSG_MAX) {
> + dev_warn(dev, "VF %d has maximum number virtual channel commands\n",
> + vf->vf_id);
> + return -ENOMEM;
> + }
> +
> + msg_listnode = (struct ice_migration_virtchnl_msg_listnode *)
> + kzalloc(struct_size(msg_listnode,
> + msg_slot.msg_buffer,
> + msglen),
> + GFP_KERNEL);
nit: there is no need to cast the void * pointer returned by kzalloc().
Flagged by Coccinelle.
> + if (!msg_listnode) {
> + dev_err(dev, "VF %d failed to allocate memory for msg listnode\n",
> + vf->vf_id);
> + return -ENOMEM;
> + }
> + dev_dbg(dev, "VF %d save virtual channel command, op code: %d, len: %d\n",
> + vf->vf_id, v_opcode, msglen);
> + msg_listnode->msg_slot.opcode = v_opcode;
> + msg_listnode->msg_slot.msg_len = msglen;
> + memcpy(msg_listnode->msg_slot.msg_buffer, msg, msglen);
> + list_add_tail(&msg_listnode->node, &vf->virtchnl_msg_list);
> + vf->virtchnl_msg_num++;
> + vf->virtchnl_msg_size += struct_size(&msg_listnode->msg_slot,
> + msg_buffer,
> + msglen);
> + return 0;
> +}
> +
> +/**
> + * ice_migration_unlog_vf_msg - revert logged message
> + * @vf: pointer to the VF structure
> + * @v_opcode: virtchnl message operation code
> + *
> + * Remove the last virtual channel message logged before.
> + */
> +void ice_migration_unlog_vf_msg(struct ice_vf *vf, u32 v_opcode)
> +{
> + struct ice_migration_virtchnl_msg_listnode *msg_listnode;
> +
> + if (!ice_migration_is_loggable_msg(v_opcode))
> + return;
> +
> + if (WARN_ON_ONCE(list_empty(&vf->virtchnl_msg_list)))
> + return;
> +
> + msg_listnode =
> + list_last_entry(&vf->virtchnl_msg_list,
> + struct ice_migration_virtchnl_msg_listnode,
> + node);
> + if (WARN_ON_ONCE(msg_listnode->msg_slot.opcode != v_opcode))
> + return;
> +
> + list_del(&msg_listnode->node);
> + kfree(msg_listnode);
msg_listnode is freed on the line above,
but dereferenced in the usage of struct_size() below.
As flagged by Smatch and Coccinelle.
> + vf->virtchnl_msg_num--;
> + vf->virtchnl_msg_size -= struct_size(&msg_listnode->msg_slot,
> + msg_buffer,
> + msg_listnode->msg_slot.msg_len);
> +}
...
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan@osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
WARNING: multiple messages have this Message-ID (diff)
From: Simon Horman <horms@kernel.org>
To: Yahui Cao <yahui.cao@intel.com>
Cc: intel-wired-lan@lists.osuosl.org, kvm@vger.kernel.org,
netdev@vger.kernel.org, lingyu.liu@intel.com,
kevin.tian@intel.com, madhu.chittim@intel.com,
sridhar.samudrala@intel.com, alex.williamson@redhat.com,
jgg@nvidia.com, yishaih@nvidia.com,
shameerali.kolothum.thodi@huawei.com, brett.creeley@amd.com,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com
Subject: Re: [PATCH iwl-next v4 05/12] ice: Log virtual channel messages in PF
Date: Wed, 29 Nov 2023 17:12:22 +0000 [thread overview]
Message-ID: <20231129171222.GF43811@kernel.org> (raw)
In-Reply-To: <20231121025111.257597-6-yahui.cao@intel.com>
On Tue, Nov 21, 2023 at 02:51:04AM +0000, Yahui Cao wrote:
> From: Lingyu Liu <lingyu.liu@intel.com>
>
> Save the virtual channel messages sent by VF on the source side during
> runtime. The logged virtchnl messages will be transferred and loaded
> into the device on the destination side during the device resume stage.
>
> For the feature which can not be migrated yet, it must be disabled or
> blocked to prevent from being abused by VF. Otherwise, it may introduce
> functional and security issue. Mask unsupported VF capability flags in
> the VF-PF negotiaion stage.
>
> Signed-off-by: Lingyu Liu <lingyu.liu@intel.com>
> Signed-off-by: Yahui Cao <yahui.cao@intel.com>
Hi Lingyu Liu and Yahui Cao,
some minor feedback from my side.
...
> diff --git a/drivers/net/ethernet/intel/ice/ice_migration.c b/drivers/net/ethernet/intel/ice/ice_migration.c
...
> +/**
> + * ice_migration_log_vf_msg - Log request message from VF
> + * @vf: pointer to the VF structure
> + * @event: pointer to the AQ event
> + *
> + * Log VF message for later device state loading during live migration
> + *
> + * Return 0 for success, negative for error
> + */
> +int ice_migration_log_vf_msg(struct ice_vf *vf,
> + struct ice_rq_event_info *event)
> +{
> + struct ice_migration_virtchnl_msg_listnode *msg_listnode;
> + u32 v_opcode = le32_to_cpu(event->desc.cookie_high);
> + struct device *dev = ice_pf_to_dev(vf->pf);
> + u16 msglen = event->msg_len;
> + u8 *msg = event->msg_buf;
> +
> + if (!ice_migration_is_loggable_msg(v_opcode))
> + return 0;
> +
> + if (vf->virtchnl_msg_num >= VIRTCHNL_MSG_MAX) {
> + dev_warn(dev, "VF %d has maximum number virtual channel commands\n",
> + vf->vf_id);
> + return -ENOMEM;
> + }
> +
> + msg_listnode = (struct ice_migration_virtchnl_msg_listnode *)
> + kzalloc(struct_size(msg_listnode,
> + msg_slot.msg_buffer,
> + msglen),
> + GFP_KERNEL);
nit: there is no need to cast the void * pointer returned by kzalloc().
Flagged by Coccinelle.
> + if (!msg_listnode) {
> + dev_err(dev, "VF %d failed to allocate memory for msg listnode\n",
> + vf->vf_id);
> + return -ENOMEM;
> + }
> + dev_dbg(dev, "VF %d save virtual channel command, op code: %d, len: %d\n",
> + vf->vf_id, v_opcode, msglen);
> + msg_listnode->msg_slot.opcode = v_opcode;
> + msg_listnode->msg_slot.msg_len = msglen;
> + memcpy(msg_listnode->msg_slot.msg_buffer, msg, msglen);
> + list_add_tail(&msg_listnode->node, &vf->virtchnl_msg_list);
> + vf->virtchnl_msg_num++;
> + vf->virtchnl_msg_size += struct_size(&msg_listnode->msg_slot,
> + msg_buffer,
> + msglen);
> + return 0;
> +}
> +
> +/**
> + * ice_migration_unlog_vf_msg - revert logged message
> + * @vf: pointer to the VF structure
> + * @v_opcode: virtchnl message operation code
> + *
> + * Remove the last virtual channel message logged before.
> + */
> +void ice_migration_unlog_vf_msg(struct ice_vf *vf, u32 v_opcode)
> +{
> + struct ice_migration_virtchnl_msg_listnode *msg_listnode;
> +
> + if (!ice_migration_is_loggable_msg(v_opcode))
> + return;
> +
> + if (WARN_ON_ONCE(list_empty(&vf->virtchnl_msg_list)))
> + return;
> +
> + msg_listnode =
> + list_last_entry(&vf->virtchnl_msg_list,
> + struct ice_migration_virtchnl_msg_listnode,
> + node);
> + if (WARN_ON_ONCE(msg_listnode->msg_slot.opcode != v_opcode))
> + return;
> +
> + list_del(&msg_listnode->node);
> + kfree(msg_listnode);
msg_listnode is freed on the line above,
but dereferenced in the usage of struct_size() below.
As flagged by Smatch and Coccinelle.
> + vf->virtchnl_msg_num--;
> + vf->virtchnl_msg_size -= struct_size(&msg_listnode->msg_slot,
> + msg_buffer,
> + msg_listnode->msg_slot.msg_len);
> +}
...
next prev parent reply other threads:[~2023-11-29 17:12 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-21 2:50 [Intel-wired-lan] [PATCH iwl-next v4 00/12] Add E800 live migration driver Yahui Cao
2023-11-21 2:50 ` Yahui Cao
2023-11-21 2:51 ` [Intel-wired-lan] [PATCH iwl-next v4 01/12] ice: Add function to get RX queue context Yahui Cao
2023-11-21 2:51 ` Yahui Cao
2023-12-08 22:01 ` [Intel-wired-lan] " Brett Creeley
2023-12-08 22:01 ` Brett Creeley
2023-11-21 2:51 ` [Intel-wired-lan] [PATCH iwl-next v4 02/12] ice: Add function to get and set TX " Yahui Cao
2023-11-21 2:51 ` Yahui Cao
2023-12-08 22:14 ` [Intel-wired-lan] " Brett Creeley
2023-12-08 22:14 ` Brett Creeley
2023-11-21 2:51 ` [Intel-wired-lan] [PATCH iwl-next v4 03/12] ice: Introduce VF state ICE_VF_STATE_REPLAYING_VC for migration Yahui Cao
2023-11-21 2:51 ` Yahui Cao
2023-12-08 22:28 ` [Intel-wired-lan] " Brett Creeley
2023-12-08 22:28 ` Brett Creeley
2024-02-12 23:07 ` [Intel-wired-lan] " Jacob Keller
2024-02-12 23:07 ` Jacob Keller
2023-11-21 2:51 ` [Intel-wired-lan] [PATCH iwl-next v4 04/12] ice: Add fundamental migration init and exit function Yahui Cao
2023-11-21 2:51 ` Yahui Cao
2023-11-21 2:51 ` [Intel-wired-lan] [PATCH iwl-next v4 05/12] ice: Log virtual channel messages in PF Yahui Cao
2023-11-21 2:51 ` Yahui Cao
2023-11-29 17:12 ` Simon Horman [this message]
2023-11-29 17:12 ` Simon Horman
2023-12-01 8:27 ` [Intel-wired-lan] " Cao, Yahui
2023-12-01 8:27 ` Cao, Yahui
2023-12-07 7:33 ` [Intel-wired-lan] " Tian, Kevin
2023-12-07 7:33 ` Tian, Kevin
2023-12-08 1:53 ` [Intel-wired-lan] " Brett Creeley
2023-12-08 1:53 ` Brett Creeley
2024-01-18 22:14 ` [Intel-wired-lan] " Jacob Keller
2023-11-21 2:51 ` [Intel-wired-lan] [PATCH iwl-next v4 06/12] ice: Add device state save/load function for migration Yahui Cao
2023-11-21 2:51 ` Yahui Cao
2023-12-07 7:39 ` [Intel-wired-lan] " Tian, Kevin
2023-12-07 7:39 ` Tian, Kevin
2023-11-21 2:51 ` [Intel-wired-lan] [PATCH iwl-next v4 07/12] ice: Fix VSI id in virtual channel message " Yahui Cao
2023-11-21 2:51 ` Yahui Cao
2023-12-07 7:42 ` [Intel-wired-lan] " Tian, Kevin
2023-12-07 7:42 ` Tian, Kevin
2023-11-21 2:51 ` [Intel-wired-lan] [PATCH iwl-next v4 08/12] ice: Save and load RX Queue head Yahui Cao
2023-11-21 2:51 ` Yahui Cao
2023-12-07 7:55 ` [Intel-wired-lan] " Tian, Kevin
2023-12-07 7:55 ` Tian, Kevin
2023-12-07 14:46 ` [Intel-wired-lan] " Jason Gunthorpe
2023-12-07 14:46 ` Jason Gunthorpe
2023-12-08 2:53 ` [Intel-wired-lan] " Tian, Kevin
2023-12-08 2:53 ` Tian, Kevin
2024-01-18 22:17 ` [Intel-wired-lan] " Jacob Keller
2023-11-21 2:51 ` [Intel-wired-lan] [PATCH iwl-next v4 09/12] ice: Save and load TX " Yahui Cao
2023-11-21 2:51 ` Yahui Cao
2023-12-07 8:22 ` [Intel-wired-lan] " Tian, Kevin
2023-12-07 8:22 ` Tian, Kevin
2023-12-07 14:48 ` [Intel-wired-lan] " Jason Gunthorpe
2023-12-07 14:48 ` Jason Gunthorpe
2023-11-21 2:51 ` [Intel-wired-lan] [PATCH iwl-next v4 10/12] ice: Add device suspend function for migration Yahui Cao
2023-11-21 2:51 ` Yahui Cao
2023-11-21 2:51 ` [Intel-wired-lan] [PATCH iwl-next v4 11/12] ice: Save and load mmio registers Yahui Cao
2023-11-21 2:51 ` Yahui Cao
2023-11-21 2:51 ` [Intel-wired-lan] [PATCH iwl-next v4 12/12] vfio/ice: Implement vfio_pci driver for E800 devices Yahui Cao
2023-11-21 2:51 ` Yahui Cao
2023-12-07 22:43 ` [Intel-wired-lan] " Alex Williamson
2023-12-07 22:43 ` Alex Williamson
2023-12-08 3:42 ` [Intel-wired-lan] " Tian, Kevin
2023-12-08 3:42 ` Tian, Kevin
2023-12-08 3:42 ` [Intel-wired-lan] " Tian, Kevin
2023-12-08 3:42 ` Tian, Kevin
2023-12-04 11:18 ` [Intel-wired-lan] [PATCH iwl-next v4 00/12] Add E800 live migration driver Cao, Yahui
2023-12-04 11:18 ` Cao, Yahui
2024-01-18 22:09 ` [Intel-wired-lan] " Jacob Keller
2024-01-18 22:09 ` Jacob Keller
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=20231129171222.GF43811@kernel.org \
--to=horms@kernel.org \
--cc=alex.williamson@redhat.com \
--cc=brett.creeley@amd.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=jgg@nvidia.com \
--cc=kevin.tian@intel.com \
--cc=kuba@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=madhu.chittim@intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shameerali.kolothum.thodi@huawei.com \
--cc=sridhar.samudrala@intel.com \
--cc=yahui.cao@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.