SlideShare una empresa de Scribd logo
1 de 41
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

Profiling your Applications using the Linux Perf Tools
Profiling your Applications using the Linux Perf ToolsProfiling your Applications using the Linux Perf Tools
Profiling your Applications using the Linux Perf Tools
emBO_Conference
 

La actualidad más candente (20)

LISA2019 Linux Systems Performance
LISA2019 Linux Systems PerformanceLISA2019 Linux Systems Performance
LISA2019 Linux Systems Performance
 
Computing Performance: On the Horizon (2021)
Computing Performance: On the Horizon (2021)Computing Performance: On the Horizon (2021)
Computing Performance: On the Horizon (2021)
 
Vmlinux: anatomy of bzimage and how x86 64 processor is booted
Vmlinux: anatomy of bzimage and how x86 64 processor is bootedVmlinux: anatomy of bzimage and how x86 64 processor is booted
Vmlinux: anatomy of bzimage and how x86 64 processor is booted
 
Linux Crash Dump Capture and Analysis
Linux Crash Dump Capture and AnalysisLinux Crash Dump Capture and Analysis
Linux Crash Dump Capture and Analysis
 
UEFI HTTP/HTTPS Boot
UEFI HTTP/HTTPS BootUEFI HTTP/HTTPS Boot
UEFI HTTP/HTTPS Boot
 
Static partitioning virtualization on RISC-V
Static partitioning virtualization on RISC-VStatic partitioning virtualization on RISC-V
Static partitioning virtualization on RISC-V
 
Ixgbe internals
Ixgbe internalsIxgbe internals
Ixgbe internals
 
OpenWrt From Top to Bottom
OpenWrt From Top to BottomOpenWrt From Top to Bottom
OpenWrt From Top to Bottom
 
Profiling your Applications using the Linux Perf Tools
Profiling your Applications using the Linux Perf ToolsProfiling your Applications using the Linux Perf Tools
Profiling your Applications using the Linux Perf Tools
 
Systems@Scale 2021 BPF Performance Getting Started
Systems@Scale 2021 BPF Performance Getting StartedSystems@Scale 2021 BPF Performance Getting Started
Systems@Scale 2021 BPF Performance Getting Started
 
qemu + gdb + sample_code: Run sample code in QEMU OS and observe Linux Kernel...
qemu + gdb + sample_code: Run sample code in QEMU OS and observe Linux Kernel...qemu + gdb + sample_code: Run sample code in QEMU OS and observe Linux Kernel...
qemu + gdb + sample_code: Run sample code in QEMU OS and observe Linux Kernel...
 
Meet cute-between-ebpf-and-tracing
Meet cute-between-ebpf-and-tracingMeet cute-between-ebpf-and-tracing
Meet cute-between-ebpf-and-tracing
 
Physical Memory Models.pdf
Physical Memory Models.pdfPhysical Memory Models.pdf
Physical Memory Models.pdf
 
Qemu JIT Code Generator and System Emulation
Qemu JIT Code Generator and System EmulationQemu JIT Code Generator and System Emulation
Qemu JIT Code Generator and System Emulation
 
Slab Allocator in Linux Kernel
Slab Allocator in Linux KernelSlab Allocator in Linux Kernel
Slab Allocator in Linux Kernel
 
Qemu Introduction
Qemu IntroductionQemu Introduction
Qemu Introduction
 
Advanced Namespaces and cgroups
Advanced Namespaces and cgroupsAdvanced Namespaces and cgroups
Advanced Namespaces and cgroups
 
Launch the First Process in Linux System
Launch the First Process in Linux SystemLaunch the First Process in Linux System
Launch the First Process in Linux System
 
Linux kernel tracing
Linux kernel tracingLinux kernel tracing
Linux kernel tracing
 
eBPF maps 101
eBPF maps 101eBPF maps 101
eBPF maps 101
 

Similar a 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
 

Similar a 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
 
syzkaller: the next gen kernel fuzzer
syzkaller: the next gen kernel fuzzersyzkaller: the next gen kernel fuzzer
syzkaller: the next gen kernel fuzzer
 
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
 

Más de Yan Vugenfirer

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

Más de 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
 

Último

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Último (20)

8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
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
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
%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
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 

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