dfghdgh

Setting up your environment

Creating a VM

1. **Download the latest Fedora-Cloud-Base image** - The website for Fedora is http://fedora.inode.at/releases/. If the download link below is not available, please refer to this website and get a new one:

````

[user@host ~]# wget http://fedora.inode.at//32/Cloud/x86_64/images/Fedora-Cloud-Base-32-1.6.x86_64.qcow2

````

2. **Prepare the qcow2 image** - Use the cleaning command install the related package and change the password to your own:

````

[user@host ~]# sudo virt-sysprep --root-password password:changeme --uninstall cloud-init --network --install ethtool,pciutils,kernel-modules-internal --selinux-relabel -a Fedora-Cloud-Base-32-1.6.x86_64.qcow2

````

Compile the kernel

For some linux distros, the vDPA kernel framework was not enabled by default, we need to download the linux source code and compile it. Below are the steps to compile the linux kernel. (The kernel version should be 5.4 or above)

You can get more information about how to compile linux kernels from how-to-compile-linux-kernel. You can skip this part if you are familiar with it.

````

[user@host ~]# git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

[user@host ~]# cd linux

[user@host ~]# git checkout v5.8

[user@host ~]# cp /boot/config-$(uname -r) .config

[user@host ~]# vim .config

      (please refer to **Note1** to enable vDPA kernel framework)

[user@host ~]# make -j

[user@host ~]# sudo make modules_install

[user@host ~]# sudo make install

````

And reboot to the newly installed kernel.

**Note1**: We need to set the following lines in the **.config** file to enable vDPA kernel framework:

CONFIG_VIRTIO_VDPA=m

CONFIG_VDPA=y

CONFIG_VDPA_SIM=m

CONFIG_VHOST_VDPA=m

**Note2**: If you prefer to use `make menuconfig`, you can find these options under section `Device Drivers`, named `vDPA drivers`, `Virtio drivers` and `VHOST drivers` as kernel 5.8.

Compile and install the QEMU

1. **Download the qemu code** - The support for vhost-vdpa backend was merged in v5.1.0 thus you should use that version or above:

````

[user@host ~]# git clone https://github.com/qemu/qemu.git

````

2. **Compile the qemu** - Follow the commands below (see the README.rst in qemu for more information):

````

[user@host ~]# cd qemu/

[user@host ~]# git checkout v5.1.0-rc3

[user@host ~]# mkdir build

[user@host ~]# cd build/

[user@host ~]#../configure --enable-vhost-vdpa --target-list=x86_64-softmmu

[user@host ~]# make

````

Configuring the host 

1. **Load all the related kmod** - You should now load the kmod with the following commands:

````

[user@host ~]# modprobe vdpa

[user@host ~]# modprobe vhost_vdpa

[user@host ~]# modprobe vdpa_sim

````

2. **Verify vhost_vdpa is loaded correctly** - Ensure the bus driver is indeed vhost_vdpa using the following commands: 

````

[user@host ~]# ls -l  /sys/bus/vdpa/drivers

drwxr-xr-x 2 root root 0 Sep  5 16:54 vhost_vdpa

#ls -l /sys/bus/vdpa/devices/vdpa0/

total 0

lrwxrwxrwx. 1 root root    0 Sep 21 12:24 driver -> ../../bus/vdpa/drivers/vhost_vdpa

drwxr-xr-x. 2 root root    0 Sep 21 12:25 power

lrwxrwxrwx. 1 root root    0 Sep 21 12:25 subsystem -> ../../bus/vdpa

-rw-r--r--. 1 root root 4096 Sep 21 12:24 uevent

drwxr-xr-x. 3 root root    0 Sep 21 12:25 vhost-vdpa-0

[user@host ~]# ls -l /dev/ |grep vdpa

crw-------   1 root root    239,   0 Sep  5 16:54 vhost-vdpa-0

````

3. **Set the ulimit -l unlimited** - ulimit -l means the maximum size that may be locked into memory. In this case we need to set it to **unlimited**, since vhost-vDPA needs to lock pages for making sure the hardware DMA works correctly:

````

[user@host ~]# ulimit -l unlimited

````

if you forget to set this, you may get the error message from qemu as following:

````

qemu-system-x86_64: failed to write, fd=12, errno=14 (Bad address)

qemu-system-x86_64: vhost vdpa map fail!

qemu-system-x86_64: vhost-vdpa: DMA mapping failed, unable to continue

````

4. **Launch the guest VM** -The device **/dev/vhost-vdpa-0** is the vDPA device we can use. The following is a simple example of using QEMU to launch a VM with vhost_vdpa: 

````

[user@host ~]# sudo x86_64-softmmu/qemu-system-x86_64 \

 -hda Fedora-Cloud-Base-32-1.6.x86_64.qcow2 \

 -netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-0,id=vhost-vdpa1 \

 -device virtio-net-pci,netdev=vhost-vdpa1,mac=00:e8:ca:33:ba:05,\

 disable-modern=off,page-per-vq=on \

 -enable-kvm \

 -nographic \

 -m 2G \

 -cpu host \

 2>&1 | tee vm.log

````

5. **Verify the port was created successfully** - After the guest boots up, we can then login in to it. We should verify that the port has been bounded successfully to  the virtio driver. This is since the backend of the virtio_net driver is vhost_vdpa and if something went wrong the driver will not be created. 

````

guest login: root

Password:

Last login: Tue Sep 29 12:03:03 on ttyS0

[root@guest ~]# ip -s link show eth0

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT gro0

 link/ether fa:46:73:e7:7d:78 brd ff:ff:ff:ff:ff:ff

RX: bytes  packets  errors  dropped overrun mcast   

12006996   200043   0       0       0       0       

TX: bytes  packets  errors  dropped carrier collsns 

12006996   200043   0       0       0       0    

[root@guest ~]# ethtool -i eth0

**driver: virtio_net**

version: 1.0.0

firmware-version: 

expansion-rom-version: 

bus-info: 0000:00:04.0

supports-statistics: yes

supports-test: no

supports-eeprom-access: no

supports-register-dump: no

supports-priv-flags: no

[user@guest ~]# lspci |grep 00:04.0 

00:04.0 Ethernet controller: Red Hat, Inc. Virtio network device

````

Running traffic with vhost_vdpa

Now that we have a vdpa_sim port with the loopback function. we can generate traffic using **pktgen** to verify it. Pktgen is a packet generator integrated with Linux kernel. For more information please refer to the pktgen doc and sample test script

````

[root@guest ~]# ip -s link show eth0

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT gro0

    link/ether fa:46:73:e7:7d:78 brd ff:ff:ff:ff:ff:ff

    RX: bytes  packets  errors  dropped overrun mcast   

    18013078   300081   0       0       0       0       

    TX: bytes  packets  errors  dropped carrier collsns 

    18013078   300081   0       0       0       0       

[root@guest ~]# ./pktgen_sample01_simple.sh -i eth0 -m 00:e8:ca:33:ba:05

                (you can get this script from sample test script)

[root@guest ~]# ip -s link show eth0

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT gro0

    link/ether fa:46:73:e7:7d:78 brd ff:ff:ff:ff:ff:ff

    RX: bytes  packets  errors  dropped overrun mcast   

    24013078   400081   0       0       0       0       

    TX: bytes  packets  errors  dropped carrier collsns 

    24013078   400081   0       0       0       0   

````

You can see the **RX packets** are increasing together with **TX packets** which means the vdpa_sim is working as expected.

Use Case B: Experimenting with virtio_vdpa bus driver

Overview of the datapath 

Virtio_vdpa driver is a transport implementation for kernel virtio drivers on top of vDPA bus operations. Virtio_vdpa will create a virtio device in the virtio bus. For more information on the virtio_vdpa bus see here

The following diagram shows the datapath for virtio-vDPA using a vdpa_sim (the vDPA simulator device):

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 201,924评论 5 474
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,781评论 2 378
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 148,813评论 0 335
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,264评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,273评论 5 363
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,383评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,800评论 3 393
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,482评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,673评论 1 295
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,497评论 2 318
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,545评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,240评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,802评论 3 304
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,866评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,101评论 1 258
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,673评论 2 348
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,245评论 2 341