Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PF driver and LM commands #5

Merged
merged 10 commits into from
Jul 19, 2022
Merged

Add PF driver and LM commands #5

merged 10 commits into from
Jul 19, 2022

Conversation

GavinLi-NV
Copy link
Collaborator

  1. Add PF driver
  2. Add Admin Q and message sending command API
  3. Add LM commands for suspend/resume, save/restore state and save pending bytes

@GavinLi-NV GavinLi-NV force-pushed the main branch 3 times, most recently from 5da14fa to b1a2687 Compare May 31, 2022 01:37
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. */
#include <linux/types.h>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should not rely on linux types, use DPDK types

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -62,6 +64,7 @@ struct virtio_vdpa_priv {

#define VIRTIO_VDPA_INTR_RETRIES_USEC 1000
#define VIRTIO_VDPA_INTR_RETRIES 256
#include <virtio_lm.h>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file had included in line 14

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

.get_mi_by_bdf = NULL,
};

void
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

/* check pf_priv before use it, might be null if not set */
priv->pf_priv = pf_priv;
if (!priv->pf_priv)
DRV_LOG(WARNING, "PF was not set");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return error if no pf
DRV_LOG(ERR, "dev:%s no pf driver found",
devname);
rte_errno = EINVAL;
return -rte_errno;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return 0;
}

#define VIRTIO_ARG_VDPA "vdpa"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can move this marco to virtio_api.h, both pf driver and vpda driver use this parameter

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{
char devname[RTE_DEV_NAME_MAX_LEN] = {0};
struct virtio_vdpa_pf_priv *priv = NULL;
int vdpa = 0, ret = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just ret;
no need =0

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

virtio_pci_dev_features_get(priv->vpdev, &priv->guest_features);
if (!(priv->guest_features & (VIRTIO_VDPA_MI_SUPPORTED_FEATURE))) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guest_features should name device_features

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

virtio_pci_dev_reset(priv->vpdev);

/* Tell the host we've noticed this device. */
virtio_pci_dev_set_status(priv->vpdev, VIRTIO_CONFIG_STATUS_ACK);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove needn't set ack and driver status

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

uint16_t i, queue_idx;
int ret;

hw->max_queue_pairs = priv->vpdev->common_cfg->num_queues / 2;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max_queue_pairs can be get from virtio_net_config, should not caculate like this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about blk device?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@GavinLi-NV GavinLi-NV force-pushed the main branch 3 times, most recently from 82edfc4 to 60ffbc7 Compare June 8, 2022 07:51
int ret;

hw->max_queue_pairs = virtio_pci_dev_nr_vq_get(priv->vpdev) / 2;
priv->hw_nr_virtqs = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use callback function to net and blk. get admin queue indx.
then init admin queue

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

…ures

These commands will be used to control the migration process and the
dirty page tracking process by the parent device for its managed
devices. For now, there is only one type of managed devices in the PCI
transport - the VFs.

Signed-off-by: Gavin Li <gavinl@nvidia.com>
Signed-off-by: Gavin Li <gavinl@nvidia.com>
Signed-off-by: Gavin Li <gavinl@nvidia.com>
Add a new vdpa PF driver for net devices

Signed-off-by: Gavin Li <gavinl@nvidia.com>
Signed-off-by: Gavin Li <gavinl@nvidia.com>
Admin virtqueues are used to send administrative commands to manipulate
various features of the device which would not easily map into the
configuration space.

Use of Admin virtqueues is negotiated by the VIRTIO_F_ADMIN_VQ feature bit.

Admin queue will be initialized by PF driver if the virtio device support
admin queue

Signed-off-by: Gavin Li <gavinl@nvidia.com>
Expose adminq command sending functions.

The message format will be like below:
struct virtio_admin_cmd {
	/* Device-readable part */
	u8 class;
	u8 command;
	u8 command-specific-data[];
	/* Device-writable part */
	u8 command-specific-result[];
	u8 status;
};

Signed-off-by: Gavin Li <gavinl@nvidia.com>
uint16_t hw_nr_virtqs; /* number of vq device supported*/
};

struct sge_iova {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

align to spec
diff --git a/content.tex b/content.tex
index c1cb60c..d82d399 100644
--- a/content.tex
+++ b/content.tex
@@ -2116,6 +2116,7 @@ \subsubsection{Dirty page track ctrl}\label{sec:Virtio Transport Options / Virti
struct virtio_sge {
le64 addr;
le32 len;

  •    le32 reserved;
    

};

enum virtio_internal_status status)
{
struct virtio_hw *hw;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not expose set status, suspend and resume had no different

}

int
virtio_vdpa_cmd_suspend(struct virtio_vdpa_pf_priv *priv, uint16_t vdev_id,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should also have get status API
VIRTIO_ADMIN_PCI_MIGRATION_GET_INTERNAL_STATUS

Signed-off-by: Gavin Li <gavinl@nvidia.com>
Add PRC APIs for adding/removing/listing PF

Signed-off-by: Gavin Li <gavinl@nvidia.com>
Signed-off-by: Gavin Li <gavinl@nvidia.com>
@kailiangz1 kailiangz1 merged commit a9dfb12 into Mellanox:main Jul 19, 2022
yajwu added a commit to yajwu/dpdk-vhost-vfe that referenced this pull request Sep 11, 2023
When MSIX configured less then queue number, quit testpmd in VM,
cause vDPA crash.

	Mellanox#3  0x00007fbc8421b489 in _int_free () from /lib64/libc.so.6
	Mellanox#4  0x0000000001a471c5 in virtio_vdpa_virtq_doorbell_relay_disable (vq_idx=vq_idx@entry=11, priv=<optimized out>, priv=<optimized out>) at ../drivers/vdpa/virtio/virtio_vdpa.c:349
	Mellanox#5  0x0000000001a47275 in virtio_vdpa_virtq_disable () at ../drivers/vdpa/virtio/virtio_vdpa.c:413
	Mellanox#6  0x0000000001a47a5a in virtio_vdpa_vring_state_set () at ../drivers/vdpa/virtio/virtio_vdpa.c:588
	Mellanox#7  0x00000000005ad8af in vhost_user_notify_queue_state (dev=0x17ffcd000, index=11, enable=0) at ../lib/vhost/vhost_user.c:283
	Mellanox#8  0x00000000005b0414 in vhost_user_msg_handler (vid=<optimized out>, fd=<optimized out>) at ../lib/vhost/vhost_user.c:3164
	Mellanox#9  0x00000000012f812f in vhost_user_read_cb () at ../lib/vhost/socket.c:310

When callfd == -1, virtio_pci_dev_interrupt_enable is skilled. But in
virtio_vdpa_virtq_disable, no such check to skip virtio_pci_dev_interrupt_disable.
virtio_vdpa_virtq_disable return error without changing queue state to disable.
Double free is caused by this wrong queue state.

The fix is to add/check vector_enable variable for virtio_pci_dev_interrupt_disable.
And remove error return in virtio_vdpa_virtq_disable.

RM: 3587409
Signed-off-by: Yajun Wu <yajunw@nvidia.com>
yajwu added a commit to yajwu/dpdk-vhost-vfe that referenced this pull request Sep 11, 2023
When MSIX configured less then queue number, quit testpmd in VM,
cause vDPA crash.

	Mellanox#3  0x00007fbc8421b489 in _int_free () from /lib64/libc.so.6
	Mellanox#4  0x0000000001a471c5 in virtio_vdpa_virtq_doorbell_relay_disable (vq_idx=vq_idx@entry=11, priv=<optimized out>, priv=<optimized out>) at ../drivers/vdpa/virtio/virtio_vdpa.c:349
	Mellanox#5  0x0000000001a47275 in virtio_vdpa_virtq_disable () at ../drivers/vdpa/virtio/virtio_vdpa.c:413
	Mellanox#6  0x0000000001a47a5a in virtio_vdpa_vring_state_set () at ../drivers/vdpa/virtio/virtio_vdpa.c:588
	Mellanox#7  0x00000000005ad8af in vhost_user_notify_queue_state (dev=0x17ffcd000, index=11, enable=0) at ../lib/vhost/vhost_user.c:283
	Mellanox#8  0x00000000005b0414 in vhost_user_msg_handler (vid=<optimized out>, fd=<optimized out>) at ../lib/vhost/vhost_user.c:3164
	Mellanox#9  0x00000000012f812f in vhost_user_read_cb () at ../lib/vhost/socket.c:310

When callfd == -1, virtio_pci_dev_interrupt_enable is skipped. But in
virtio_vdpa_virtq_disable, no such check to skip virtio_pci_dev_interrupt_disable.
virtio_vdpa_virtq_disable return error without changing queue state to disable.
Double free is caused by this wrong queue state.

The fix is to add/check vector_enable variable for virtio_pci_dev_interrupt_disable.
And remove error return in virtio_vdpa_virtq_disable.

RM: 3587409
Signed-off-by: Yajun Wu <yajunw@nvidia.com>
kailiangz1 pushed a commit that referenced this pull request Sep 18, 2023
When MSIX configured less then queue number, quit testpmd in VM,
cause vDPA crash.

	#3  0x00007fbc8421b489 in _int_free () from /lib64/libc.so.6
	#4  0x0000000001a471c5 in virtio_vdpa_virtq_doorbell_relay_disable (vq_idx=vq_idx@entry=11, priv=<optimized out>, priv=<optimized out>) at ../drivers/vdpa/virtio/virtio_vdpa.c:349
	#5  0x0000000001a47275 in virtio_vdpa_virtq_disable () at ../drivers/vdpa/virtio/virtio_vdpa.c:413
	#6  0x0000000001a47a5a in virtio_vdpa_vring_state_set () at ../drivers/vdpa/virtio/virtio_vdpa.c:588
	#7  0x00000000005ad8af in vhost_user_notify_queue_state (dev=0x17ffcd000, index=11, enable=0) at ../lib/vhost/vhost_user.c:283
	#8  0x00000000005b0414 in vhost_user_msg_handler (vid=<optimized out>, fd=<optimized out>) at ../lib/vhost/vhost_user.c:3164
	#9  0x00000000012f812f in vhost_user_read_cb () at ../lib/vhost/socket.c:310

When callfd == -1, virtio_pci_dev_interrupt_enable is skipped. But in
virtio_vdpa_virtq_disable, no such check to skip virtio_pci_dev_interrupt_disable.
virtio_vdpa_virtq_disable return error without changing queue state to disable.
Double free is caused by this wrong queue state.

The fix is to add/check vector_enable variable for virtio_pci_dev_interrupt_disable.
And remove error return in virtio_vdpa_virtq_disable.

RM: 3587409
Signed-off-by: Yajun Wu <yajunw@nvidia.com>
Ch3n60x pushed a commit to Ch3n60x/dpdk-vhost-vfe that referenced this pull request Mar 27, 2024
[ upstream commit 1c80a40 ]

The net/vhost pmd currently provides a -1 vid when disabling interrupt
after a virtio port got disconnected.

This can be caught when running with ASan.

First, start dpdk-l3fwd-power in interrupt mode with a net/vhost port.

$ ./build-clang/examples/dpdk-l3fwd-power -l0,1 --in-memory \
	-a 0000:00:00.0 \
	--vdev net_vhost0,iface=plop.sock,client=1\
	-- \
	-p 0x1 \
	--interrupt-only \
	--config '(0,0,1)' \
	--parse-ptype 0

Then start testpmd with virtio-user.

$ ./build-clang/app/dpdk-testpmd -l0,2 --single-file-segment --in-memory \
	-a 0000:00:00.0 \
	--vdev net_virtio_user0,path=plop.sock,server=1 \
	-- \
	-i

Finally stop testpmd.
ASan then splats in dpdk-l3fwd-power:

=================================================================
==3641005==ERROR: AddressSanitizer: global-buffer-overflow on address
	0x000005ed0778 at pc 0x000001270f81 bp 0x7fddbd2eee20
	sp 0x7fddbd2eee18
READ of size 8 at 0x000005ed0778 thread T2
    #0 0x1270f80 in get_device .../lib/vhost/vhost.h:801:27
    Mellanox#1 0x1270f80 in rte_vhost_get_vhost_vring .../lib/vhost/vhost.c:951:8
    Mellanox#2 0x3ac95cb in eth_rxq_intr_disable
	.../drivers/net/vhost/rte_eth_vhost.c:647:8
    Mellanox#3 0x170e0bf in rte_eth_dev_rx_intr_disable
	.../lib/ethdev/rte_ethdev.c:5443:25
    Mellanox#4 0xf72ba7 in turn_on_off_intr .../examples/l3fwd-power/main.c:881:4
    Mellanox#5 0xf71045 in main_intr_loop .../examples/l3fwd-power/main.c:1061:6
    Mellanox#6 0x17f9292 in eal_thread_loop
	.../lib/eal/common/eal_common_thread.c:210:9
    Mellanox#7 0x18373f5 in eal_worker_thread_loop .../lib/eal/linux/eal.c:915:2
    Mellanox#8 0x7fddc16ae12c in start_thread (/lib64/libc.so.6+0x8b12c)
	(BuildId: 81daba31ee66dbd63efdc4252a872949d874d136)
    Mellanox#9 0x7fddc172fbbf in __GI___clone3 (/lib64/libc.so.6+0x10cbbf)
	(BuildId: 81daba31ee66dbd63efdc4252a872949d874d136)

0x000005ed0778 is located 8 bytes to the left of global variable
	'vhost_devices' defined in '.../lib/vhost/vhost.c:24'
	(0x5ed0780) of size 8192
0x000005ed0778 is located 20 bytes to the right of global variable
	'vhost_config_log_level' defined in '.../lib/vhost/vhost.c:2174'
	(0x5ed0760) of size 4
SUMMARY: AddressSanitizer: global-buffer-overflow
	.../lib/vhost/vhost.h:801:27 in get_device
Shadow bytes around the buggy address:
  0x000080bd2090: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
  0x000080bd20a0: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
  0x000080bd20b0: f9 f9 f9 f9 00 f9 f9 f9 00 f9 f9 f9 00 f9 f9 f9
  0x000080bd20c0: 00 00 00 00 00 00 00 f9 f9 f9 f9 f9 04 f9 f9 f9
  0x000080bd20d0: 00 00 00 00 00 f9 f9 f9 f9 f9 f9 f9 00 00 00 00
=>0x000080bd20e0: 00 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 04 f9 f9[f9]
  0x000080bd20f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x000080bd2100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x000080bd2110: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x000080bd2120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x000080bd2130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
Thread T2 created by T0 here:
    #0 0xe98996 in __interceptor_pthread_create
	(.examples/dpdk-l3fwd-power+0xe98996)
	(BuildId: d0b984a3b0287b9e0f301b73426fa921aeecca3a)
    Mellanox#1 0x1836767 in eal_worker_thread_create .../lib/eal/linux/eal.c:952:6
    Mellanox#2 0x1834b83 in rte_eal_init .../lib/eal/linux/eal.c:1257:9
    Mellanox#3 0xf68902 in main .../examples/l3fwd-power/main.c:2496:8
    Mellanox#4 0x7fddc164a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f)
	(BuildId: 81daba31ee66dbd63efdc4252a872949d874d136)

==3641005==ABORTING

More generally, any application passing an incorrect vid would trigger
such an OOB access.

Fixes: 4796ad6 ("examples/vhost: import userspace vhost application")

Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants