SlideShare ist ein Scribd-Unternehmen logo
1 von 41
Downloaden Sie, um offline zu lesen
QEMU AND DEVICE EMULATION
Yan Vugenfirer, yan@daynix.com
Daynix Computing LTD
Daynix Computing LTD
AGENDA
• Introduction to QEMU
• Development environment
• Examples of existing devices
• Adding a new device to
QEMU
Daynix Computing LTD
WHAT IS QEMU?
• Open source project (GPLv2.0+ license)
• Machine emulator
• Virtualizer
• Works together with KVM and Xen
Daynix Computing LTD
WHY SHOULDYOU CARE?
• Open source
• Easy to add additional devices
• Emulates different HW architectures
• Can be used for SW development long before
HW is ready
Daynix Computing LTD
GET IT NOW
• Project website: http://wiki.qemu.org/Main_Page
• Code repository: git clone git://git.qemu-
project.org/qemu.git
Daynix Computing LTD
PREPARING DEVELOPMENT
ENVIRONMENT
• Installing the packages on Ubuntu
• sudo apt-get update
• sudo apt-get install git
• sudo apt-get install build-essential
• sudo apt-get install pkg-config
• sudo apt-get install zlib zlib-dev
• sudo apt-get install zlib1g-dev zlib1g
• sudo apt-get install glib2.0
• sudo apt-get install libpixman-1-0
• sudo apt-get install libtool
• sudo apt-get install dh-autoreconf
• sudo apt-get install bridge-utils
Daynix Computing LTD
COMPILING QEMU
• git clone https://github.com/qemu/qemu.git
• cd qemu
• git submodule update --init pixman
• ./configure --disable-docs —target-list=x86_64-softmmu
• make -j 8
• Skip if development version only: make install
Daynix Computing LTD
NETWORK CONFIGURATION
Linux host
Virtual machine
QEMU process
NIC
Linux bridge
Physical NIC
Daynix Computing LTD
NETWORK CONFIGURATION
• On the host edit /etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
#auto eth0
#iface eth0 inet dhcp
iface eth0 inet manual
auto br0
iface br0 inet dhcp
bridge_ports eth0
Daynix Computing LTD
#!/bin/sh
switch=br0
/sbin/ifconfig $1 promisc 0.0.0.0
/sbin/brctl addif ${switch} $1
QEMU-IFUP SCRIPT
• Create qemu-ifup script with following content
Daynix Computing LTD
STORAGE
• Download Ubuntu server - http://
www.ubuntu.com/download/server
• CreateVM image
• qemu-img create -f qcow ubuntu.qcow 8G
Daynix Computing LTD
RUNNINGYOU FIRSTVIRTUAL
MACHINE
./qemu/x86_64-softmmu/qemu-system-x86_64 
-M pc -name Test_VM -smp 2 -m 512M 
-drive file=/home/qemu/images/ubuntu.qcow,if=ide 
-usbdevice tablet 
-boot order=cdn,once=c,menu=on 
-netdev tap,id=hostnet1,script=/home/qemu/dev/qemu-
ifup,ifname=testvm_nic 
-device e1000,netdev=hostnet1,mac=56:54:46:6b:64:22,bus=pci.
0,id=e1000_01 
-cdrom /ISO/ubuntu-14.04.1-server-amd64.iso 
-vnc :5
Daynix Computing LTD
CONNECTINGTOVM
• Use theVNC viewer of your choice
• ssh after you configured networking
Daynix Computing LTD
CODETREE
• cd qemu/HW
Daynix Computing LTD
QEMU DEVICE MODEL
• QDev device model abstraction
• Tree of devices connected by buses
• Represented by DeviceState and BusState
• Devices have common API
• Devices have properties
• Check include/hw/qdev-core.h for more info
Daynix Computing LTD
EXAMPLES OF EXISTING
DEVICES
• e1000
• qemu/hw/net/e1000.c
• virtio family -base code
• qemu/hw/virtio/virtio-pci.c, qemu/hw/virtio/virtio-rng.c
• virtio-net
• qemu/hw/net/virtio-net.c
• vmxnet3
• qemu/hw/net/vmxnet3.c
LET’S CODE!
Daynix Computing LTD
ADDING NEW DEVICE
• Basic source file for the device
• Enable the compilation of the device
• Command line options
• Step by step enhancement of the device
Daynix Computing LTD
ADDING NEW DEVICE
• In qemu/HW/net/ let’s create devix.c
• Add CONFIG_DEVIX_PCI option to default-configs/
pci.mak
• Add devix.o to hw/net/Makefile.objs
Daynix Computing LTD
COMPILATION
diff --git a/default-configs/pci.mak b/default-configs/
pci.mak
index 91b1e92..fcf2cf2 100644
--- a/default-configs/pci.mak
+++ b/default-configs/pci.mak
@@ -30,3 +30,4 @@ CONFIG_IPACK=y
CONFIG_WDT_IB6300ESB=y
CONFIG_PCI_TESTDEV=y
CONFIG_NVME_PCI=y
+CONFIG_DEVIX_PCI=y
Daynix Computing LTD
COMPILATION
diff --git a/hw/net/Makefile.objs b/hw/net/Makefile.objs
index ea93293..7800755 100644
--- a/hw/net/Makefile.objs
+++ b/hw/net/Makefile.objs
@@ -10,6 +10,7 @@ common-obj-$(CONFIG_E1000_PCI) += e1000.o
common-obj-$(CONFIG_RTL8139_PCI) += rtl8139.o
common-obj-$(CONFIG_VMXNET3_PCI) += vmxnet_tx_pkt.o
vmxnet_rx_pkt.o
common-obj-$(CONFIG_VMXNET3_PCI) += vmxnet3.o
+common-obj-$(CONFIG_DEVIX_PCI) += devix.o
Daynix Computing LTD
REGISTERYOUR DEVICETYPE
static const TypeInfo devix_info = {
.name = TYPE_DEVIX,
.parent = TYPE_PCI_DEVICE,
.instance_size = sizeof(DEVIXState),
.class_init = devix_class_init,
.instance_init = devix_instance_init,
};
static void devix_register_types(void)
{
DVX_CBPRN("devix_register_types called...");
type_register_static(&devix_info);
}
type_init(devix_register_types)
Daynix Computing LTD
DEVICETYPE INITIALIZATION
static void devix_class_init(ObjectClass *class, void *data)
{
DeviceClass *dc = DEVICE_CLASS(class);
PCIDeviceClass *c = PCI_DEVICE_CLASS(class);
c->init = devix_pci_init;
c->exit = devix_pci_uninit;
c->vendor_id = PCI_VENDOR_ID_DAYNIX;
c->device_id = PCI_DEVICE_ID_DAYNIX_DEVIX;
c->revision = PCI_DEVICE_ID_DAYNIX_DEVIX_REVISION;
c->class_id = PCI_CLASS_NETWORK_ETHERNET;
c->subsystem_vendor_id = PCI_VENDOR_ID_DAYNIX;
c->subsystem_id = PCI_DEVICE_ID_DAYNIX_DEVIX;
c->config_write = devix_write_config;
c->config_read = devix_read_config;
dc->desc = "Daynix educational device v1";
dc->reset = devix_qdev_reset;
dc->vmsd = &vmstate_devix;
dc->props = devix_properties;
set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
}
Daynix Computing LTD
PCI CONFIGURATION SPACE
ACCESS CALLBACKS
static void uint32_t devix_read_config(PCIDevice *pci_dev,
uint32_t address, int len)
{
return pci_default_read_config(pci_dev, address, len);
}
static void
devix_write_config(PCIDevice *pci_dev, uint32_t address, uint32_t val,
int len)
{
pci_default_write_config(pci_dev, address, val, len);
}
• At this point we have PCI device
• No BARs or Interrupts… yet
Daynix Computing LTD
VM POINT OFVIEW
00:04.0 Ethernet controller: Device 9696:1234
(rev 01)
Subsystem: Device 9696:1234
Physical Slot: 4
Control: I/O+ Mem+ BusMaster- SpecCycle-
MemWINV- VGASnoop- ParErr- Stepping- SERR+
FastB2B- DisINTx-
Status: Cap- 66MHz- UDF- FastB2B- ParErr-
DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR-
<PERR- INTx-
• sudo lspci -vv
Daynix Computing LTD
• Register IO and memory space
• Configure interrupts
• Our own device initializations
PCI INITIALIZATION
Daynix Computing LTD
MEMORY REGIONS
typedef struct {
PCIDevice parent_obj;
MemoryRegion bar0;
MemoryRegion bar1;
} DEVIXState;
• Add placeholders for memory regions into device
state structure
Daynix Computing LTD
REGISTER MEMORY REGIONS
static int devix_pci_init(PCIDevice *pci_dev)
{
DeviceState *dev = DEVICE(pci_dev);
DEVIXState *s = DEVIX(pci_dev);
DVX_CBPRN("Starting init...");
memory_region_init_io(&s->bar0, OBJECT(s), &b0_ops, s,
"devix-b0", DEVIX_BAR0_SIZE);
pci_register_bar(pci_dev, DEVIX_BAR0_IDX,
PCI_BASE_ADDRESS_SPACE_MEMORY, &s->bar0);
memory_region_init_io(&s->bar1, OBJECT(s), &b1_ops, s,
"devix-b1", DEVIX_BAR1_SIZE);
pci_register_bar(pci_dev, DEVIX_BAR1_IDX,
PCI_BASE_ADDRESS_SPACE_IO, &s->bar1);
devix_net_init(s);
return 0;
}
Daynix Computing LTD
ACCESS CALLBACKS
static const MemoryRegionOps b0_ops = {
.read = devix_io_bar0_read,
.write = devix_io_bar0_write,
.endianness = DEVICE_LITTLE_ENDIAN,
.impl = {
.min_access_size = 4,
.max_access_size = 4,
},
};
Daynix Computing LTD
ACCESS CALLBACKS - WRITE
static void
devix_io_bar0_write(void *opaque, hwaddr addr,
uint64_t val, unsigned size)
{
DEVIXState *s = opaque;
DVX_WRPRN("BAR0 write [%" PRIx64 "] = %"
PRIx64 ", size %d",
(uint64_t) addr, val, size);
}
• Size
• Address
• Value
Daynix Computing LTD
ACCESS CALLBACKS - READ
static uint64_t
devix_io_bar0_read(void *opaque, hwaddr addr,
unsigned size)
{
DEVIXState *s = opaque;
uint64_t ret = 0;
DVX_CBPRN("Read BAR0 [%" PRIx64 "], size
%d",(uint64_t) addr, size);
return ret; /* Returns value of the read
register */
}
• Size
• Address
• Return the
value
Daynix Computing LTD
VM POINT OFVIEW
00:04.0 Ethernet controller: Device 9696:1234
(rev 01)
Subsystem: Device 9696:1234
Physical Slot: 4
Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV-
VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx-
Status: Cap- 66MHz- UDF- FastB2B- ParErr-
DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR-
INTx-
Region 0: Memory at febd2000 (32-bit, non-
prefetchable) [size=4K]
Region 1: I/O ports at c000 [size=512]
• sudo lspci -vv
Daynix Computing LTD
LEGACY INTERRUPTS
• Add interrupt line in pci_init
/* Interrupt pin A */
pci_dev->config[PCI_INTERRUPT_PIN] = 0x01;
Daynix Computing LTD
LEGACY INTERRUPTS
• Call to void pci_irq_assert(PCIDevice *pci_dev)
when you want to raise interrupt
• Call void pci_irq_deassert(PCIDevice *pci_dev) to
de-assert interrupt from one of your registers
callback depending on clear interrupt logic
Daynix Computing LTD
VM POINT OFVIEW
00:04.0 Ethernet controller: Device 9696:1234
(rev 01)
Subsystem: Device 9696:1234
Physical Slot: 4
Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV-
VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx-
Status: Cap- 66MHz- UDF- FastB2B- ParErr-
DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR-
INTx-
Interrupt: pin A routed to IRQ 11
Region 0: Memory at febd2000 (32-bit, non-
prefetchable) [size=4K]
Region 1: I/O ports at c000 [size=512]
• sudo lspci -vv
Daynix Computing LTD
“DMA”
• Actually guest memory access
• Synchronous
• void cpu_physical_memory_read(hwaddr addr, void *buf, int len)
• void cpu_physical_memory_write(hwaddr addr, const void *buf, int len)
• iov_xxx functions
• Check include/exec/cpu-common.h for more access functions
DEMO
Daynix Computing LTD
WHAT’S NEXT?
• Add network back end
• Add MSI and MSI-x support
• Littlebig endian
considerations
Q&A
Daynix Computing LTD
LINKS
• Project website: http://wiki.qemu.org/Main_Page
• Code repository: git clone git://git.qemu-project.org/
qemu.git
• QEMU new device model - http://www.linux-kvm.org/
wiki/images/f/fe/2010-forum-armbru-qdev.pdf
• Daynix - www.daynix.com

Weitere ähnliche Inhalte

Was ist angesagt?

Linux Kernel Image
Linux Kernel ImageLinux Kernel Image
Linux Kernel Image
艾鍗科技
 
U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoC
Macpaul Lin
 

Was ist angesagt? (20)

Bootstrap process of u boot (NDS32 RISC CPU)
Bootstrap process of u boot (NDS32 RISC CPU)Bootstrap process of u boot (NDS32 RISC CPU)
Bootstrap process of u boot (NDS32 RISC CPU)
 
from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Worksfrom Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Works
 
What Can Compilers Do for Us?
What Can Compilers Do for Us?What Can Compilers Do for Us?
What Can Compilers Do for Us?
 
Linux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKBLinux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKB
 
Linux Kernel Module - For NLKB
Linux Kernel Module - For NLKBLinux Kernel Module - For NLKB
Linux Kernel Module - For NLKB
 
Linux Kernel Image
Linux Kernel ImageLinux Kernel Image
Linux Kernel Image
 
Embedded Virtualization applied in Mobile Devices
Embedded Virtualization applied in Mobile DevicesEmbedded Virtualization applied in Mobile Devices
Embedded Virtualization applied in Mobile Devices
 
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all startedKernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all started
 
Reconnaissance of Virtio: What’s new and how it’s all connected?
Reconnaissance of Virtio: What’s new and how it’s all connected?Reconnaissance of Virtio: What’s new and how it’s all connected?
Reconnaissance of Virtio: What’s new and how it’s all connected?
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)
 
I2c drivers
I2c driversI2c drivers
I2c drivers
 
Static partitioning virtualization on RISC-V
Static partitioning virtualization on RISC-VStatic partitioning virtualization on RISC-V
Static partitioning virtualization on RISC-V
 
Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device Drivers
 
U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoC
 
Qemu Pcie
Qemu PcieQemu Pcie
Qemu Pcie
 
syzkaller: the next gen kernel fuzzer
syzkaller: the next gen kernel fuzzersyzkaller: the next gen kernel fuzzer
syzkaller: the next gen kernel fuzzer
 
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven RostedtKernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
 
Linux Network Stack
Linux Network StackLinux Network Stack
Linux Network Stack
 
U-Boot presentation 2013
U-Boot presentation  2013U-Boot presentation  2013
U-Boot presentation 2013
 
Qemu Introduction
Qemu IntroductionQemu Introduction
Qemu Introduction
 

Ähnlich wie Qemu device prototyping

Rmll Virtualization As Is Tool 20090707 V1.0
Rmll Virtualization As Is Tool 20090707 V1.0Rmll Virtualization As Is Tool 20090707 V1.0
Rmll Virtualization As Is Tool 20090707 V1.0
guest72e8c1
 
Quick-and-Easy Deployment of a Ceph Storage Cluster with SLES
Quick-and-Easy Deployment of a Ceph Storage Cluster with SLESQuick-and-Easy Deployment of a Ceph Storage Cluster with SLES
Quick-and-Easy Deployment of a Ceph Storage Cluster with SLES
Jan Kalcic
 
Storage-Performance-Tuning-for-FAST-Virtual-Machines_Fam-Zheng.pdf
Storage-Performance-Tuning-for-FAST-Virtual-Machines_Fam-Zheng.pdfStorage-Performance-Tuning-for-FAST-Virtual-Machines_Fam-Zheng.pdf
Storage-Performance-Tuning-for-FAST-Virtual-Machines_Fam-Zheng.pdf
aaajjj4
 
Advanced Diagnostics 2
Advanced Diagnostics 2Advanced Diagnostics 2
Advanced Diagnostics 2
Aero Plane
 

Ähnlich wie Qemu device prototyping (20)

RMLL / LSM 2009
RMLL / LSM 2009RMLL / LSM 2009
RMLL / LSM 2009
 
Rmll Virtualization As Is Tool 20090707 V1.0
Rmll Virtualization As Is Tool 20090707 V1.0Rmll Virtualization As Is Tool 20090707 V1.0
Rmll Virtualization As Is Tool 20090707 V1.0
 
NetBSD on Google Compute Engine (en)
NetBSD on Google Compute Engine (en)NetBSD on Google Compute Engine (en)
NetBSD on Google Compute Engine (en)
 
Quick-and-Easy Deployment of a Ceph Storage Cluster with SLES
Quick-and-Easy Deployment of a Ceph Storage Cluster with SLESQuick-and-Easy Deployment of a Ceph Storage Cluster with SLES
Quick-and-Easy Deployment of a Ceph Storage Cluster with SLES
 
Delivering Docker & K3s worloads to IoT Edge devices
Delivering Docker & K3s worloads to IoT Edge devicesDelivering Docker & K3s worloads to IoT Edge devices
Delivering Docker & K3s worloads to IoT Edge devices
 
Presentation1.pptx
Presentation1.pptxPresentation1.pptx
Presentation1.pptx
 
Introction to docker swarm
Introction to docker swarmIntroction to docker swarm
Introction to docker swarm
 
Kernel Recipes 2015 - Kernel dump analysis
Kernel Recipes 2015 - Kernel dump analysisKernel Recipes 2015 - Kernel dump analysis
Kernel Recipes 2015 - Kernel dump analysis
 
LSA2 - 02 Namespaces
LSA2 - 02  NamespacesLSA2 - 02  Namespaces
LSA2 - 02 Namespaces
 
Razor, the Provisioning Toolbox - PuppetConf 2014
Razor, the Provisioning Toolbox - PuppetConf 2014Razor, the Provisioning Toolbox - PuppetConf 2014
Razor, the Provisioning Toolbox - PuppetConf 2014
 
Storage-Performance-Tuning-for-FAST-Virtual-Machines_Fam-Zheng.pdf
Storage-Performance-Tuning-for-FAST-Virtual-Machines_Fam-Zheng.pdfStorage-Performance-Tuning-for-FAST-Virtual-Machines_Fam-Zheng.pdf
Storage-Performance-Tuning-for-FAST-Virtual-Machines_Fam-Zheng.pdf
 
Labs_BT_20221017.pptx
Labs_BT_20221017.pptxLabs_BT_20221017.pptx
Labs_BT_20221017.pptx
 
9 creating cent_os 7_mages_for_dpdk_training
9 creating cent_os 7_mages_for_dpdk_training9 creating cent_os 7_mages_for_dpdk_training
9 creating cent_os 7_mages_for_dpdk_training
 
Advanced Diagnostics 2
Advanced Diagnostics 2Advanced Diagnostics 2
Advanced Diagnostics 2
 
Achieving the Ultimate Performance with KVM
Achieving the Ultimate Performance with KVMAchieving the Ultimate Performance with KVM
Achieving the Ultimate Performance with KVM
 
See what happened with real time kvm when building real time cloud pezhang@re...
See what happened with real time kvm when building real time cloud pezhang@re...See what happened with real time kvm when building real time cloud pezhang@re...
See what happened with real time kvm when building real time cloud pezhang@re...
 
Known basic of NFV Features
Known basic of NFV FeaturesKnown basic of NFV Features
Known basic of NFV Features
 
Achieving the Ultimate Performance with KVM
Achieving the Ultimate Performance with KVMAchieving the Ultimate Performance with KVM
Achieving the Ultimate Performance with KVM
 
Scaling Docker Containers using Kubernetes and Azure Container Service
Scaling Docker Containers using Kubernetes and Azure Container ServiceScaling Docker Containers using Kubernetes and Azure Container Service
Scaling Docker Containers using Kubernetes and Azure Container Service
 
Kvm setup
Kvm setupKvm setup
Kvm setup
 

Mehr von Yan Vugenfirer

Advanced NDISTest options
Advanced NDISTest optionsAdvanced NDISTest options
Advanced NDISTest options
Yan Vugenfirer
 

Mehr von Yan Vugenfirer (14)

HCK-CI: Enabling CI for Windows Guest Paravirtualized Drivers - Kostiantyn Ko...
HCK-CI: Enabling CI for Windows Guest Paravirtualized Drivers - Kostiantyn Ko...HCK-CI: Enabling CI for Windows Guest Paravirtualized Drivers - Kostiantyn Ko...
HCK-CI: Enabling CI for Windows Guest Paravirtualized Drivers - Kostiantyn Ko...
 
Receive side scaling (RSS) with eBPF in QEMU and virtio-net
Receive side scaling (RSS) with eBPF in QEMU and virtio-netReceive side scaling (RSS) with eBPF in QEMU and virtio-net
Receive side scaling (RSS) with eBPF in QEMU and virtio-net
 
Implementing SR-IOv failover for Windows guests during live migration
Implementing SR-IOv failover for Windows guests during live migrationImplementing SR-IOv failover for Windows guests during live migration
Implementing SR-IOv failover for Windows guests during live migration
 
Windows network teaming
Windows network teamingWindows network teaming
Windows network teaming
 
Rebuild presentation - IoT Israel MeetUp
Rebuild presentation - IoT Israel MeetUpRebuild presentation - IoT Israel MeetUp
Rebuild presentation - IoT Israel MeetUp
 
Rebuild presentation during Docker's Birthday party
Rebuild presentation during Docker's Birthday partyRebuild presentation during Docker's Birthday party
Rebuild presentation during Docker's Birthday party
 
Contributing to open source using Git
Contributing to open source using GitContributing to open source using Git
Contributing to open source using Git
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Microsoft Hardware Certification Kit (HCK) setup
Microsoft Hardware Certification Kit (HCK) setupMicrosoft Hardware Certification Kit (HCK) setup
Microsoft Hardware Certification Kit (HCK) setup
 
UsbDk at a Glance 
UsbDk at a Glance UsbDk at a Glance 
UsbDk at a Glance 
 
Building “old” Windows drivers (XP, Vista, 2003 and 2008) with Visual Studio ...
Building “old” Windows drivers (XP, Vista, 2003 and 2008) with Visual Studio ...Building “old” Windows drivers (XP, Vista, 2003 and 2008) with Visual Studio ...
Building “old” Windows drivers (XP, Vista, 2003 and 2008) with Visual Studio ...
 
Advanced NDISTest options
Advanced NDISTest optionsAdvanced NDISTest options
Advanced NDISTest options
 
QEMU Development and Testing Automation Using MS HCK - Anton Nayshtut and Yan...
QEMU Development and Testing Automation Using MS HCK - Anton Nayshtut and Yan...QEMU Development and Testing Automation Using MS HCK - Anton Nayshtut and Yan...
QEMU Development and Testing Automation Using MS HCK - Anton Nayshtut and Yan...
 
Windows guest debugging presentation from KVM Forum 2012
Windows guest debugging presentation from KVM Forum 2012Windows guest debugging presentation from KVM Forum 2012
Windows guest debugging presentation from KVM Forum 2012
 

Kürzlich hochgeladen

Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 

Kürzlich hochgeladen (20)

Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 

Qemu device prototyping

  • 1. QEMU AND DEVICE EMULATION Yan Vugenfirer, yan@daynix.com Daynix Computing LTD
  • 2. Daynix Computing LTD AGENDA • Introduction to QEMU • Development environment • Examples of existing devices • Adding a new device to QEMU
  • 3. Daynix Computing LTD WHAT IS QEMU? • Open source project (GPLv2.0+ license) • Machine emulator • Virtualizer • Works together with KVM and Xen
  • 4. Daynix Computing LTD WHY SHOULDYOU CARE? • Open source • Easy to add additional devices • Emulates different HW architectures • Can be used for SW development long before HW is ready
  • 5. Daynix Computing LTD GET IT NOW • Project website: http://wiki.qemu.org/Main_Page • Code repository: git clone git://git.qemu- project.org/qemu.git
  • 6. Daynix Computing LTD PREPARING DEVELOPMENT ENVIRONMENT • Installing the packages on Ubuntu • sudo apt-get update • sudo apt-get install git • sudo apt-get install build-essential • sudo apt-get install pkg-config • sudo apt-get install zlib zlib-dev • sudo apt-get install zlib1g-dev zlib1g • sudo apt-get install glib2.0 • sudo apt-get install libpixman-1-0 • sudo apt-get install libtool • sudo apt-get install dh-autoreconf • sudo apt-get install bridge-utils
  • 7. Daynix Computing LTD COMPILING QEMU • git clone https://github.com/qemu/qemu.git • cd qemu • git submodule update --init pixman • ./configure --disable-docs —target-list=x86_64-softmmu • make -j 8 • Skip if development version only: make install
  • 8. Daynix Computing LTD NETWORK CONFIGURATION Linux host Virtual machine QEMU process NIC Linux bridge Physical NIC
  • 9. Daynix Computing LTD NETWORK CONFIGURATION • On the host edit /etc/network/interfaces # The loopback network interface auto lo iface lo inet loopback # The primary network interface #auto eth0 #iface eth0 inet dhcp iface eth0 inet manual auto br0 iface br0 inet dhcp bridge_ports eth0
  • 10. Daynix Computing LTD #!/bin/sh switch=br0 /sbin/ifconfig $1 promisc 0.0.0.0 /sbin/brctl addif ${switch} $1 QEMU-IFUP SCRIPT • Create qemu-ifup script with following content
  • 11. Daynix Computing LTD STORAGE • Download Ubuntu server - http:// www.ubuntu.com/download/server • CreateVM image • qemu-img create -f qcow ubuntu.qcow 8G
  • 12. Daynix Computing LTD RUNNINGYOU FIRSTVIRTUAL MACHINE ./qemu/x86_64-softmmu/qemu-system-x86_64 -M pc -name Test_VM -smp 2 -m 512M -drive file=/home/qemu/images/ubuntu.qcow,if=ide -usbdevice tablet -boot order=cdn,once=c,menu=on -netdev tap,id=hostnet1,script=/home/qemu/dev/qemu- ifup,ifname=testvm_nic -device e1000,netdev=hostnet1,mac=56:54:46:6b:64:22,bus=pci. 0,id=e1000_01 -cdrom /ISO/ubuntu-14.04.1-server-amd64.iso -vnc :5
  • 13. Daynix Computing LTD CONNECTINGTOVM • Use theVNC viewer of your choice • ssh after you configured networking
  • 15. Daynix Computing LTD QEMU DEVICE MODEL • QDev device model abstraction • Tree of devices connected by buses • Represented by DeviceState and BusState • Devices have common API • Devices have properties • Check include/hw/qdev-core.h for more info
  • 16. Daynix Computing LTD EXAMPLES OF EXISTING DEVICES • e1000 • qemu/hw/net/e1000.c • virtio family -base code • qemu/hw/virtio/virtio-pci.c, qemu/hw/virtio/virtio-rng.c • virtio-net • qemu/hw/net/virtio-net.c • vmxnet3 • qemu/hw/net/vmxnet3.c
  • 18. Daynix Computing LTD ADDING NEW DEVICE • Basic source file for the device • Enable the compilation of the device • Command line options • Step by step enhancement of the device
  • 19. Daynix Computing LTD ADDING NEW DEVICE • In qemu/HW/net/ let’s create devix.c • Add CONFIG_DEVIX_PCI option to default-configs/ pci.mak • Add devix.o to hw/net/Makefile.objs
  • 20. Daynix Computing LTD COMPILATION diff --git a/default-configs/pci.mak b/default-configs/ pci.mak index 91b1e92..fcf2cf2 100644 --- a/default-configs/pci.mak +++ b/default-configs/pci.mak @@ -30,3 +30,4 @@ CONFIG_IPACK=y CONFIG_WDT_IB6300ESB=y CONFIG_PCI_TESTDEV=y CONFIG_NVME_PCI=y +CONFIG_DEVIX_PCI=y
  • 21. Daynix Computing LTD COMPILATION diff --git a/hw/net/Makefile.objs b/hw/net/Makefile.objs index ea93293..7800755 100644 --- a/hw/net/Makefile.objs +++ b/hw/net/Makefile.objs @@ -10,6 +10,7 @@ common-obj-$(CONFIG_E1000_PCI) += e1000.o common-obj-$(CONFIG_RTL8139_PCI) += rtl8139.o common-obj-$(CONFIG_VMXNET3_PCI) += vmxnet_tx_pkt.o vmxnet_rx_pkt.o common-obj-$(CONFIG_VMXNET3_PCI) += vmxnet3.o +common-obj-$(CONFIG_DEVIX_PCI) += devix.o
  • 22. Daynix Computing LTD REGISTERYOUR DEVICETYPE static const TypeInfo devix_info = { .name = TYPE_DEVIX, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(DEVIXState), .class_init = devix_class_init, .instance_init = devix_instance_init, }; static void devix_register_types(void) { DVX_CBPRN("devix_register_types called..."); type_register_static(&devix_info); } type_init(devix_register_types)
  • 23. Daynix Computing LTD DEVICETYPE INITIALIZATION static void devix_class_init(ObjectClass *class, void *data) { DeviceClass *dc = DEVICE_CLASS(class); PCIDeviceClass *c = PCI_DEVICE_CLASS(class); c->init = devix_pci_init; c->exit = devix_pci_uninit; c->vendor_id = PCI_VENDOR_ID_DAYNIX; c->device_id = PCI_DEVICE_ID_DAYNIX_DEVIX; c->revision = PCI_DEVICE_ID_DAYNIX_DEVIX_REVISION; c->class_id = PCI_CLASS_NETWORK_ETHERNET; c->subsystem_vendor_id = PCI_VENDOR_ID_DAYNIX; c->subsystem_id = PCI_DEVICE_ID_DAYNIX_DEVIX; c->config_write = devix_write_config; c->config_read = devix_read_config; dc->desc = "Daynix educational device v1"; dc->reset = devix_qdev_reset; dc->vmsd = &vmstate_devix; dc->props = devix_properties; set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); }
  • 24. Daynix Computing LTD PCI CONFIGURATION SPACE ACCESS CALLBACKS static void uint32_t devix_read_config(PCIDevice *pci_dev, uint32_t address, int len) { return pci_default_read_config(pci_dev, address, len); } static void devix_write_config(PCIDevice *pci_dev, uint32_t address, uint32_t val, int len) { pci_default_write_config(pci_dev, address, val, len); }
  • 25. • At this point we have PCI device • No BARs or Interrupts… yet
  • 26. Daynix Computing LTD VM POINT OFVIEW 00:04.0 Ethernet controller: Device 9696:1234 (rev 01) Subsystem: Device 9696:1234 Physical Slot: 4 Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx- Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx- • sudo lspci -vv
  • 27. Daynix Computing LTD • Register IO and memory space • Configure interrupts • Our own device initializations PCI INITIALIZATION
  • 28. Daynix Computing LTD MEMORY REGIONS typedef struct { PCIDevice parent_obj; MemoryRegion bar0; MemoryRegion bar1; } DEVIXState; • Add placeholders for memory regions into device state structure
  • 29. Daynix Computing LTD REGISTER MEMORY REGIONS static int devix_pci_init(PCIDevice *pci_dev) { DeviceState *dev = DEVICE(pci_dev); DEVIXState *s = DEVIX(pci_dev); DVX_CBPRN("Starting init..."); memory_region_init_io(&s->bar0, OBJECT(s), &b0_ops, s, "devix-b0", DEVIX_BAR0_SIZE); pci_register_bar(pci_dev, DEVIX_BAR0_IDX, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->bar0); memory_region_init_io(&s->bar1, OBJECT(s), &b1_ops, s, "devix-b1", DEVIX_BAR1_SIZE); pci_register_bar(pci_dev, DEVIX_BAR1_IDX, PCI_BASE_ADDRESS_SPACE_IO, &s->bar1); devix_net_init(s); return 0; }
  • 30. Daynix Computing LTD ACCESS CALLBACKS static const MemoryRegionOps b0_ops = { .read = devix_io_bar0_read, .write = devix_io_bar0_write, .endianness = DEVICE_LITTLE_ENDIAN, .impl = { .min_access_size = 4, .max_access_size = 4, }, };
  • 31. Daynix Computing LTD ACCESS CALLBACKS - WRITE static void devix_io_bar0_write(void *opaque, hwaddr addr, uint64_t val, unsigned size) { DEVIXState *s = opaque; DVX_WRPRN("BAR0 write [%" PRIx64 "] = %" PRIx64 ", size %d", (uint64_t) addr, val, size); } • Size • Address • Value
  • 32. Daynix Computing LTD ACCESS CALLBACKS - READ static uint64_t devix_io_bar0_read(void *opaque, hwaddr addr, unsigned size) { DEVIXState *s = opaque; uint64_t ret = 0; DVX_CBPRN("Read BAR0 [%" PRIx64 "], size %d",(uint64_t) addr, size); return ret; /* Returns value of the read register */ } • Size • Address • Return the value
  • 33. Daynix Computing LTD VM POINT OFVIEW 00:04.0 Ethernet controller: Device 9696:1234 (rev 01) Subsystem: Device 9696:1234 Physical Slot: 4 Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx- Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx- Region 0: Memory at febd2000 (32-bit, non- prefetchable) [size=4K] Region 1: I/O ports at c000 [size=512] • sudo lspci -vv
  • 34. Daynix Computing LTD LEGACY INTERRUPTS • Add interrupt line in pci_init /* Interrupt pin A */ pci_dev->config[PCI_INTERRUPT_PIN] = 0x01;
  • 35. Daynix Computing LTD LEGACY INTERRUPTS • Call to void pci_irq_assert(PCIDevice *pci_dev) when you want to raise interrupt • Call void pci_irq_deassert(PCIDevice *pci_dev) to de-assert interrupt from one of your registers callback depending on clear interrupt logic
  • 36. Daynix Computing LTD VM POINT OFVIEW 00:04.0 Ethernet controller: Device 9696:1234 (rev 01) Subsystem: Device 9696:1234 Physical Slot: 4 Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx- Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx- Interrupt: pin A routed to IRQ 11 Region 0: Memory at febd2000 (32-bit, non- prefetchable) [size=4K] Region 1: I/O ports at c000 [size=512] • sudo lspci -vv
  • 37. Daynix Computing LTD “DMA” • Actually guest memory access • Synchronous • void cpu_physical_memory_read(hwaddr addr, void *buf, int len) • void cpu_physical_memory_write(hwaddr addr, const void *buf, int len) • iov_xxx functions • Check include/exec/cpu-common.h for more access functions
  • 38. DEMO
  • 39. Daynix Computing LTD WHAT’S NEXT? • Add network back end • Add MSI and MSI-x support • Littlebig endian considerations
  • 40. Q&A
  • 41. Daynix Computing LTD LINKS • Project website: http://wiki.qemu.org/Main_Page • Code repository: git clone git://git.qemu-project.org/ qemu.git • QEMU new device model - http://www.linux-kvm.org/ wiki/images/f/fe/2010-forum-armbru-qdev.pdf • Daynix - www.daynix.com