summary refs log tree commit diff
path: root/x86_64
Commit message (Collapse)AuthorAge
* crosvm: pstore works for ARCVM on x86_64Kansho Nishida2020-02-03
| | | | | | | | | | | | | | | | Adds support for pstore on ARCVM on x86_64. The backend file of the buffer will be passed via argument of the crosvm. BUG=b:144962428 TEST=kernel crash on eve-arcvm, check /sys/fs/pstore/console-ramoops-0 Launch crostini manually on eve-arcvm Change-Id: I29492ac7a9067aa2ae23eb03fbb942ab7dd3aa8d Signed-off-by: Kansho Nishida <kansho@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1973391 Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Kansho Nishida <kansho@chromium.org>
* x86_64: fix warning on 1.40Dylan Reid2020-01-12
| | | | | | | | | | | The extra parens crept back in during a recent refactoring. Change-Id: Iaba13ddea9b7bada09f6079db7e7f8133cbfc896 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1994726 Reviewed-by: Dylan Reid <dgreid@chromium.org> Commit-Queue: Dylan Reid <dgreid@chromium.org> Tested-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: remove user_command from proxy deviceZach Reizner2020-01-09
| | | | | | | | | | | | | | | | | | The only device that used user_command was Serial. This change makes Serial device use a thread to read from its input instead of using user_command. BUG=chromium:1033787 TEST=./build_test run crosvm with stdio serial with and without sandbox Change-Id: Ia0f2ee83d94ad2fee3f1f4f89aa734b976e33507 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1966435 Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org> Commit-Queue: Zach Reizner <zachr@chromium.org> Auto-Submit: Zach Reizner <zachr@chromium.org>
* devices: fix warning about extra parensDylan Reid2019-12-23
| | | | | | | | | | | rust 1.40 has a new warning when there are extra parens, soRemove them. Change-Id: Ibb565cac41ba8d72879f4cb8b949f2be30e55167 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1978140 Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Dylan Reid <dgreid@chromium.org> Commit-Queue: Dylan Reid <dgreid@chromium.org>
* x86_64: add tsc_deadline_timer supportZhuocheng Ding2019-12-13
| | | | | | | | | | | | | | | Support TSC deadline mode of LAPIC timer, this can potentially increase the precision of guest timer. BUG=None TEST=launch linux guest and run `lscpu`, tsc_deadline_timer is present in the output. Change-Id: I7adc87827a51ba8d1866ebee201759f2769ba664 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1951429 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Zhuocheng Ding <zhuocheng.ding@intel.corp-partner.google.com>
* crosvm: PIT: use full address and avoid conflictZhuocheng Ding2019-12-10
| | | | | | | | | | | | | | | | The PIT implementation has the assumption that addresses are I/O port numbers, so we should use full address mode. i8042 is also changed to full address mode to avoid the conflict on port 0x61. BUG=chromium:908689 TEST=None Change-Id: Ibbb851e3a46ac7fc71576990a1618196de92e33c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1945794 Commit-Queue: Zhuocheng Ding <zhuocheng.ding@intel.corp-partner.google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* Setup vcpu's MTRRXiong Zhang2019-11-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | When vfio pass-through is enabled, guest will be very slow. The root casue is gfn is uncachable in EPT. From the comments in kernel vmx_get_mt_mask(vcpu, gfn, is_mmio) function, EPT memory type with VT-d, VT-d without snooping control feature: can't guarantee the result, try to trust guest through kvm_mtrr_get_guest_memory_type(vcpu, gfn). But crosvm doesn't set mtrr, so host kernel will set uncachable for all gfn in ept. This patch set the default cache type as WB, and set mmio cache type as UC, so the guest ram is WB. BUG=chromium:992270 TEST=crosvm --vfio /sys/devices/pci0000:00/0000:00:02.0, pass through host igd into linux guest, the guest runs smoothly and guest desktop could be shown on physical local display. Change-Id: I151aae7835910cfbc9e38464ee901e5da281de1e Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1813458 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* x86_64: fix the incorrect parameter for disabling ACPIChuanxiao Dong2019-11-22
| | | | | | | | | | | | | | noacpi is not used by the current guest linux kernel to disable ACPI. Instead, acpi=off is the right parameter to be used. BUG=chromium:1026497 TEST=launch crosvm linux guest and ACPI is disabled Change-Id: I9c9001146abb57ea9dbc078ee6188b8c60cb056e Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1925999 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* Vfio: Suitably allocate bar for vfio deviceXiong Zhang2019-11-11
| | | | | | | | | | | | | Use 64bit flag in vfio device's bar to get correct mmio allocator. BUG=chromium:992270 TEST=none Change-Id: I8f3dab48eb6dc0b92071803aa3526cadda8034c7 Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1581143 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* resource: Rename device memory to mmioXiong Zhang2019-11-10
| | | | | | | | | | | | | | Since unified allocator is used to allocate mmio, this patch remove the device memory name, and rename device to mmio. BUG=chromium:992270 TEST=this patch doesn't change function, run build_test Change-Id: I234b0db4b3c5de8cfee372ace5212a980564d0c7 Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1895234 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* arch: replace is_some + unwrap with `if let`Daniel Verkamp2019-11-08
| | | | | | | | | | | BUG=None TEST=emerge-kevin crosvm Change-Id: I78aa9f4fb4fb46de3394bb9bc2fa5a53e210fa0b Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1896085 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* x86_64: Correct the start address of device memoryXiong Zhang2019-11-05
| | | | | | | | | | | | | | | | | | | When guest ram >= 4G, as mmio hole exists in ram GuestMemory, GuestMemory->end_addr() is larger than memsize, if memsize is used as start address of device memory, device memory will overlap with Guest ram. This patch use GuestMemory->end_addr() as the start address of device memory. BUG=None TEST=Boot vm with guest memory above 4G, and enable vGPU, and run vGPU benchmark. Change-Id: Ifc28f3a022cb0a179d16fee4056016a192f2acbd Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1895232 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* x86_64: Correct guest ram memory region layoutXiong Zhang2019-11-04
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When guest boot with -m 4096, guest e820 is: BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable BIOS-e820: [mem 0x0000000000200000-0x00000000cfffffff] usable so guest usable ram is 3.25G which is smaller than specified 4G. 3.25G~4G is assigned to pci device as mmio, this range should be relocated to 4G above like 4G to 4.75G. So guest could see the full 4G usable ram. With this patch, guest e820 is: BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable BIOS-e820: [mem 0x0000000000200000-0x00000000cfffffff] usable BIOS-e820: [mem 0x0000000100000000-0x000000012fffffff] usable The guest could use 4G ram equal to specified 4G. Then mmio hole exists in guest ram's regions, GuestMemory's end_addr is larger than the memsize. end_addr couldn't be used to judge an address in a guest memory or not We should iterate all the regions to avoid the address in the hole; end_addr couldn't be used for checked_offset() also, it may faill into mmio hole. BUG=none TEST=build_test; Boot vm with different guest memory size, and check vm's e820 table Change-Id: I2cd7c3223173ab635041875b9d8b49c2800c8dab Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1895231 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: jail serial deviceZach Reizner2019-10-10
| | | | | | | | | | | | | | | | | | This change plumbs the jail throughout the arch specific device creation process. It also adds a custom callback support for the ProxyDevice so that the main process can interrupt the child serial process when it has incoming bytes. TEST=crosvm run BUG=None Change-Id: I6af7d2cb0acbba9bf42eaeeb294cee2bce4a1f36 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1752589 Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Zach Reizner <zachr@chromium.org> Commit-Queue: Zach Reizner <zachr@chromium.org>
* x86_64: replace byteorder with {to,from}_le_bytes()Daniel Verkamp2019-08-26
| | | | | | | | | | | BUG=None TEST=./build_test Change-Id: Ic7873c6b70d9a0e9f34b7a2977845552144934ea Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1761152 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* crosvm: virtio-pmem deviceJakub Staron2019-06-05
| | | | | | | | | | | | | | | | | | | | Adds support for virtio-pmem device as an alternative for virtio-blk. Exposing disk image to guest as virtio-blk device results in both guest and host independently caching the disk I/O. Using virtio-pmem device allows to mount disk image as direct access (DAX) in the guest and thus bypass the guest cache. This will reduce memory foodprint of the VMs. BUG=None TEST=cargo test TEST=Boot patched termina kernel in crosvm; mount virtio-pmem device as DAX and run xfstests. Change-Id: I935fc8fc7527f79e5169f07ec7927e4ea4fa6027 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1605517 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Commit-Queue: Jakub Staroń <jstaron@google.com>
* eliminate mut from non-mut referencesZach Reizner2019-06-04
| | | | | | | | | | | | | | | | | | | | | | | This manifested itself in a couple places that were turning shared memory buffers into slices for the purposes of passing these slices to `Read` and `Write` trait methods. However, this required the removal of the methods that took `Read` and `Write` instances. This was a convenient interface but impossible to implement safely because making slices from raw pointers without enforcing safety guarantees causes undefined behaviour in Rust. It turns out lots of code in crosvm was using these interfaces indirectly, which explains why this CL touches so much. TEST=crosvm run BUG=chromium:938767 Change-Id: I4ff40c98da6ed08a4a42f4c31f0717f81b1c5863 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1636685 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Zach Reizner <zachr@chromium.org>
* Initial BIOS support.Cody Schuffelen2019-05-31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The --bios argument is added as an alternative to the kernel positional argument. The BIOS runs in unreal mode (16-bit cs selector set to the end of 32-bit address space), which matches the default state KVM puts the segment and data registers into. Example usage: Build u-boot with "make qemu-x86_defconfig && make" Run crosvm with "crosvm_wrapper.sh run --bios=u-boot.rom" This produces the following message: """ U-Boot 2019.01-00017-gdc76aabe6a-dirty (May 21 2019 - 12:17:02 -0700) CPU: DRAM: 16 MiB unable to get online cpu number: -19 Warning: MP init failure Model: QEMU x86 (I440FX) Net: No ethernet found. error: can't find etc/table-loader Hit any key to stop autoboot: 0 => """ At this point the u-boot shell works with stdin/stdout, but virtual disks passed with --rwdisk weren't immediately visible from running "virtio scan" and "virtio info". This change puts the bios loading together with the linux kernel loading code since there is a lot of overlap in functionality. Bug: b/133358982 Test: ./crosvm_wrapper.sh run --mem=4097 --bios=u-boot.rom Change-Id: I65b0e1044233af662a642c592d35b106217f3c13 Reviewed-on: https://chromium-review.googlesource.com/1622648 Commit-Ready: Daniel Verkamp <dverkamp@chromium.org> Tested-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* x86_64: regenerate bootparam bindings without unionsZach Reizner2019-05-23
| | | | | | | | | | | | TEST=crosvm run still works BUG=chromium:761517 Change-Id: I6e95dde573febb5e498107b84b574373d1685c9a Reviewed-on: https://chromium-review.googlesource.com/1625947 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* devices: cmos: report memory size in CMOSDaniel Verkamp2019-05-23
| | | | | | | | | | | | | | | This matches the QEMU CMOS implementation and is used by BIOSes to determine the valid memory regions to add to the e820 map. BUG=b:133358982 TEST=Boot u-boot qemu build; observe memory size Change-Id: I27956bc05738b5dd5b84240d5137cb06846aaab9 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1625330 Tested-by: kokoro <noreply+kokoro@google.com> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* smbios: fix clippy warningsDaniel Verkamp2019-05-22
| | | | | | | | | | | | | | | | | Resolve a couple of minor clippy warnings: - const implies static lifetime, so it can be omitted - dereference bytes of str instead of clone() BUG=None TEST=bin/clippy TEST=cargo build; boot vm_kernel+vm_rootfs.img Change-Id: I29ff9bf7fdecd64286c2199e8e45c21103de9ce1 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1618284 Tested-by: kokoro <noreply+kokoro@google.com> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* x86_64: load initrd at max addressDaniel Verkamp2019-05-20
| | | | | | | | | | | | | | | | | This matches behavior of other bootloaders (grub2, iPXE), and the kernel seems to be relying on this; decompression of the initrd fails if the initrd is loaded right after the kernel as before, but succeeds if loaded at the maximum address. BUG=None TEST=Boot Debian kernel + initrd on workstation Change-Id: If7712efb05f55ef413a419dfe276ed3f68c335b7 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1616989 Tested-by: kokoro <noreply+kokoro@google.com> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* crosvm: add cmdline flags for configuring serial outputs in guest machineTrent Begin2019-05-15
| | | | | | | | | | | | | | | | This change allows an output to be set for each serial device for a guest machine (stdout, syslog, or sink). BUG=chromium:953983 TEST=FEATURES=test emerge-sarien crosvm; cd sys_util; cargo test; ./build_test; manual testing on x86_64 and aarch_64 Change-Id: I9e7fcb0b296c0f8a5aa8d54b1a74ae801f6badc8 Reviewed-on: https://chromium-review.googlesource.com/1572813 Commit-Ready: Trent Begin <tbegin@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Trent Begin <tbegin@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* x86_64: support loading bzImage kernelsDaniel Verkamp2019-05-14
| | | | | | | | | | | | | | | | | | | | | | | | | | | The current kernel loader expects an extracted ELF kernel; this adds complexity to the build and test process for the guest kernel, since the normal output of a Linux kernel build is a bzImage-format kernel. bzImage also supports compressed kernels, which are smaller on disk and potentially quicker to load, depending on disk and CPU speed. Add support for loading of bzImage-format kernels, and use the 64-bit boot protocol as described in the official Linux/x86 boot protocol: https://www.kernel.org/doc/Documentation/x86/boot.txt The existing ELF loader is kept for compatibility with shipping kernel images; if a kernel image doesn't have the ELF signature, it is passed to the bzImage loader as a fallback. BUG=None TEST=Boot bzImage and extracted ELF kernels on x86-64 Change-Id: I90be4cd597d15bc89e63f0f6cbc781c5c8c2eaeb Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1609969 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* Add Android fstab support to aarch64, based on x86_64 versionGreg Hartman2019-05-02
| | | | | | | | | | | Test: cargo test on x86_64 and aarch64, boot on aarch64 Change-Id: I29fb269abedaaca4168581aa7f92d413d51e9232 Reviewed-on: https://chromium-review.googlesource.com/1585279 Commit-Ready: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Greg Hartman <ghartman@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Greg Hartman <ghartman@google.com>
* crosvm: Fix misleading field name in VmComponents struct.Jakub Staron2019-04-29
| | | | | | | | | | | | | | | Renames field memory_mb to memory_size. All usages of this field treat it as a memory size in bytes, not megabytes. BUG=None TEST=cargo check TEST=cargo check --package aarch64 --target aarch64-unknown-linux-gnu Change-Id: I7b1aefe4f0b612d5eeb2987dc2a0fce6db0dd228 Reviewed-on: https://chromium-review.googlesource.com/1585617 Commit-Ready: Jakub Staroń <jstaron@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* crosvm: add license blurb to all filesStephen Barber2019-04-24
| | | | | | | | | | | | | | A few files were missing license blurbs at the top, so update them all to include them. BUG=none TEST=none Change-Id: Ida101be2e5c255b8cffeb15f5b93f63bfd1b130b Reviewed-on: https://chromium-review.googlesource.com/1577900 Commit-Ready: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* Add rudimentary support for SMBIOS 3.0.Philipp Kern2019-04-19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | SMBIOS allows to pass down system information from the BIOS to the OS. Its information is used on Linux to construct modalias entries for the system in order to facilite module autoloading on specific hardware. Adding it also allows package management software to target specific packages when crosvm is used as the hypervisor (e.g. to pre-install the helper daemons or a special vTPM driver). This change has only been tested with Linux and implements the bare minimum necessary to make a crosvm hypervisor detectable through DMI data. As such it also skips over some required structures like BIOS information that do not technically apply. The result is a hodgepodge of standards: SMBIOS 3.0 provides a convenient 64-bit entrypoint that we implement. However the structures are cut short to SMBIOS 2.0 standards as most of the fields are skipped. Linux deals just fine with this, although some of the dmi/id files in sysfs will be empty as a result. The resulting modalias looks like this: dmi:bvncrosvm:bvr0:bd:svnChromiumOS:pncrosvm:pvr: The kernel prints this as part of startup: SMBIOS 3.2.0 present. DMI: ChromiumOS crosvm, BIOS 0 And for oops/panic: Hardware name: ChromiumOS crosvm, BIOS 0 dmidecode's view on the tables (which uses its own parser): Getting SMBIOS data from sysfs. SMBIOS 3.2.0 present. Table at 0x000F0018. Handle 0x0001, DMI type 0, 20 bytes BIOS Information Vendor: crosvm Version: 0 Release Date: Not Specified ROM Size: 64 kB Characteristics: PCI is supported System is a virtual machine Handle 0x0002, DMI type 1, 27 bytes System Information Manufacturer: ChromiumOS Product Name: crosvm Version: Not Specified Serial Number: Not Specified UUID: Not Settable Wake-up Type: Reserved SKU Number: Not Specified Family: Not Specified TEST=cargo test Change-Id: Ie27105711a9bc14941d387b720da350349dff265 Reviewed-on: https://chromium-review.googlesource.com/1571565 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* clippy: Resolve cast_ptr_alignmentDavid Tolnay2019-04-18
| | | | | | | | | | | | | | | | | | | | | | | | | | This CL fixes four cases of what I believe are undefined behavior: - In vhost where the original code allocates a Vec<u8> with 1-byte alignment and casts the Vec's data pointer to a &mut vhost_memory which is required to be 8-byte aligned. Underaligned references of type &T or &mut T are always undefined behavior in Rust. - Same pattern in x86_64. - Same pattern in plugin::vcpu. - Code in crosvm_plugin that dereferences a potentially underaligned pointer. This is always undefined behavior in Rust. TEST=bin/clippy TEST=cargo test sys_util Change-Id: I926f17b1fe022a798f69d738f9990d548f40c59b Reviewed-on: https://chromium-review.googlesource.com/1566736 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* clippy: Iterate without calling .iter()David Tolnay2019-04-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | See: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_iter_loop https://rust-lang.github.io/rust-clippy/master/index.html#explicit_into_iter_loop Before: for element in slice.iter() {...} After: for element in slice {...} TEST=grep -r '\.iter() {' TEST=grep -r '\.iter_mut() {' TEST=grep -r '\.into_iter() {' TEST=cargo check --all-features TEST=local kokoro Change-Id: I27f0df7cfa1064b2c8b162cba263513926a433a9 Reviewed-on: https://chromium-review.googlesource.com/1568525 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* resources: add build method to SystemAllocatorDaniel Prilik2019-04-17
| | | | | | | | | | | | | | | | | | AddressRanges' name doesn't suggest that it's a SystemAllocator builder. This CL renames it to SystemAllocatorBuilder, and adds a SystemAllocator::builder() that removes the need to have a separate import for the Builder. A minor change, but it cleans up the interface a bit. BUG=chromium:936567 TEST=cargo test -p resources && cargo build Change-Id: I6d14368490c0d3c4018858f541e4ae5390995878 Reviewed-on: https://chromium-review.googlesource.com/1540398 Commit-Ready: Daniel Prilik <prilik@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* edition: Eliminate blocks superseded by NLLDavid Tolnay2019-04-17
| | | | | | | | | | | | | | | | | | | | Before the new borrow checker in the 2018 edition, we sometimes used to have to manually insert curly braced blocks to limit the scope of borrows. These are no longer needed. Details in: https://doc.rust-lang.org/edition-guide/rust-2018/ownership-and-lifetimes/non-lexical-lifetimes.html TEST=cargo check --all-features TEST=local kokoro Change-Id: I59f9f98dcc03c8790c53e080a527ad9b68c8d6f3 Reviewed-on: https://chromium-review.googlesource.com/1568075 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* clippy: Switch to tool attributes for suppressing lintsDavid Tolnay2019-04-15
| | | | | | | | | | | | | | | | | | | | | | | Tool attributes were stabilized in Rust 1.31: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html#tool-lints Before: #[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment)] After: #[allow(clippy::cast_ptr_alignment)] TEST=cargo check --all-features Change-Id: If2f1511f6231d60578b5e0d5bd4210a68eb08caf Reviewed-on: https://chromium-review.googlesource.com/1566651 Commit-Ready: David Tolnay <dtolnay@chromium.org> Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* edition: Remove extern crate linesDavid Tolnay2019-04-15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In Rust 2018 edition, `extern crate` is no longer required for importing from other crates. Instead of writing: extern crate dep; use dep::Thing; we write: use dep::Thing; In this approach, macros are imported individually from the declaring crate rather than through #[macro_use]. Before: #[macro_use] extern crate sys_util; After: use sys_util::{debug, error}; The only place that `extern crate` continues to be required is in importing the compiler's proc_macro API into a procedural macro crate. This will hopefully be fixed in a future Rust release. extern crate proc_macro; TEST=cargo check TEST=cargo check --all-features TEST=cargo check --target aarch64-unknown-linux-gnu TEST=local kokoro Change-Id: I0b43768c0d81f2a250b1959fb97ba35cbac56293 Reviewed-on: https://chromium-review.googlesource.com/1565302 Commit-Ready: David Tolnay <dtolnay@chromium.org> Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* lints: Enforce sorted order for enum variantsDavid Tolnay2019-04-13
| | | | | | | | | | | | | | | | | | | | | | | | | To avoid wasting time re-sorting these things (CL:1492612). https://docs.rs/remain Disclaimer: I wrote the macro. This CL adds #[sorted] attributes to those Error enums that seemed to have made some effort to be in sorted order. TEST=cargo check TEST=cargo check --all-features TEST=cargo check --target aarch64-unknown-linux-gnu TEST=emerge-nami crosvm TEST=local kokoro CQ-DEPEND=CL:1524247 Change-Id: I89685ced05e2f149fa189ca509bc14c70aebb531 Reviewed-on: https://chromium-review.googlesource.com/1515998 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* main: add --cpu-affinity option to pin VCPUsDaniel Verkamp2019-04-09
| | | | | | | | | | | | | | | | | | This allows setting the affinity of the VCPU threads to specific host CPUs. Note that each individual CPU has its affinity set to the full set of CPUs specified, so the host kernel may still reschedule VCPU threads on whichever host CPUs it sees fit (within the specified set). BUG=chromium:909793 TEST=build_test Change-Id: I09b893901caf91368b64f5329a6e9f39027fef23 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1554865 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* cargo: Sort all dependency lists in Cargo.tomlDavid Tolnay2019-04-09
| | | | | | | | | | | | | | | This may help reduce cases of conflicts between independent CLs each appending a dependency at the bottom of the list, of which I hit two today rebasing some of my open CLs. TEST=cargo check --all-features Change-Id: Ief10bb004cc7b44b107dc3841ce36c6b23632aed Reviewed-on: https://chromium-review.googlesource.com/1557172 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* edition: Use dyn syntax for trait objectsDavid Tolnay2019-04-08
| | | | | | | | | | | | | | | | | | | | | Found by running: `cargo rustc -- -D bare_trait_objects` Bare trait objects like `&Trait` and `Box<Trait>` are soft-deprecated in 2018 edition and will start warning at some point. As part of this, I replaced `Box<Trait + 'static>` with `Box<dyn Trait>` because the 'static bound is implied for boxed trait objects. TEST=cargo check --all-features TEST=cargo check --target aarch64-unknown-linux-gnu TEST=local kokoro Change-Id: I41c4f13530bece8a34a8ed1c1afd7035b8f86f19 Reviewed-on: https://chromium-review.googlesource.com/1513059 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* edition: Update x86_64 crate to 2018 editionDavid Tolnay2019-04-07
| | | | | | | | | | | | | | | | | | Separated out of CL:1513058 to make it possible to land parts individually while the affected crate has no other significant CLs pending. This avoids repeatedly introducing non-textual conflicts with new code that adds `use` statements. TEST=cargo check TEST=cargo check --all-features TEST=cargo check --target aarch64-unknown-linux-gnu Change-Id: Iec5cc762f38f18196a6147473ac093f474b00794 Reviewed-on: https://chromium-review.googlesource.com/1520075 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* crosvm: add memfd for GuestMemoryDaniel Prilik2019-03-25
| | | | | | | | | | | | | | | | | Building off CL:1290293 Instead of having a seperate GuestMemoryManager, this adds SharedMemory as a Arc'd member of GuestMemory. This is nice since it removes the need to plumb the Manager struct throughout the codebase. BUG=chromium:936567 TEST=cargo test -p sys_util Change-Id: I6fa5d73f7e0db495c2803a040479818445660345 Reviewed-on: https://chromium-review.googlesource.com/1493013 Commit-Ready: Daniel Prilik <prilik@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* Move split_irqchip_common to devices/.Miriam Zimmerman2019-03-20
| | | | | | | | | | | | | | | Previously, code in devices/ couldn't use split_irqchip_common, since x86_64/ already has a dependency on devices/. TEST=Built. BUG=chromium:908689 Change-Id: I481514ae6bbd68e47feecc6f364ca8f4fd798e67 Reviewed-on: https://chromium-review.googlesource.com/1526762 Commit-Ready: Miriam Zimmerman <mutexlox@chromium.org> Tested-by: Miriam Zimmerman <mutexlox@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* bitfield: Support BitFieldSpecifier for enumsDavid Tolnay2019-03-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, the getter and setter functions generated for a bitfield struct by #[bitfield] all operated on primitive types like bool, u8, u16 etc. This CL adds support for getters and setters defined in terms of user-defined enums. We make an enum bitfield-compatible by adding #[bitfield]. The number of variants must be a power of 2. #[bitfield] enum TwoBits { Zero = 0b00, One = 0b01, Two = 0b10, Three = 0b11, } And then it may be used to specify a field in a bitfield struct. #[bitfield] struct Struct { prefix: BitField1, two_bits: TwoBits, suffix: BitField5, } The generated getters and setters for this struct would have the following signatures: impl Struct { fn get_prefix(&self) -> u8; fn set_prefix(&mut self, val: u8); fn get_two_bits(&self) -> TwoBits; fn set_two_bits(&mut self, val: TwoBits); fn get_suffix(&self) -> u8; fn set_suffix(&mut self, val: u8); } TEST=`cargo test` the bit_field and bit_field_derive crates TEST=`cargo check` crosvm Change-Id: Ibc8923e2877fda6ae8da5767731edcb68721a434 Reviewed-on: https://chromium-review.googlesource.com/1519686 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* edition: Update absolute paths to 2018 styleDavid Tolnay2019-03-13
| | | | | | | | | | | | | | | | | | | | | | | | | | This is an easy step toward adopting 2018 edition eventually, and will make any future CL that sets `edition = "2018"` this much smaller. The module system changes in Rust 2018 are described here: https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html Generated by running: cargo fix --edition --all in each workspace, followed by bin/fmt. TEST=cargo check TEST=cargo check --all-features TEST=cargo check --target aarch64-unknown-linux-gnu Change-Id: I000ab5e69d69aa222c272fae899464bbaf65f6d8 Reviewed-on: https://chromium-review.googlesource.com/1513054 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* Add common types and constants for split IRQ chip.Miriam Zimmerman2019-03-13
| | | | | | | | | | | | | | | These will come in handy for reducing code duplication and simplifying PIC/IOAPIC/PIT/interrupt routing code. TEST=Built BUG=chromium:908689 Change-Id: I696e9f51231a8e39640f1fd0af055b48048bc134 Reviewed-on: https://chromium-review.googlesource.com/1518557 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Miriam Zimmerman <mutexlox@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* arch: Replace Box<dyn Error> with error enumDavid Tolnay2019-03-09
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Avoiding Box<dyn Error> makes it less likely that we display errors with insufficient context by accident. Many of the errors touched in this CL already had helpful message written! But those corresponding enum variants were never being instantiated, and that bug was masked by Box<dyn Error>. For example see the Error::LoadCmdline and Error::LoadKernel. pub enum Error { LoadCmdline(kernel_loader::Error), ... } Before this CL: // Bug: boxes the underlying error without adding LoadCmdline kernel_loader::load_cmdline(...)?; After this CL: kernel_loader::load_cmdline(...).map_err(Error::LoadCmdline)?; TEST=cargo check TEST=cargo check --all-features TEST=cargo check --target aarch64-unknown-linux-gnu Change-Id: I7c0cff843c2211565226b9dfb4142ad6b7fa15ac Reviewed-on: https://chromium-review.googlesource.com/1502112 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* linux: use panic=-1 to reboot immediately on panicDaniel Verkamp2019-03-05
| | | | | | | | | | | | | | | | | | | | This changes the default Linux kernel command line from panic=1 (reboot one second after panic) to panic=-1 (reboot immediately on panic). The kernel should not normally panic; this is just to improve quality of life for developer workflows, such as running bash as init and exiting the shell to shut down the VM. BUG=None TEST=crosvm run -r vm_rootfs.img -p init=/bin/bash vm_kernel; exit shell Change-Id: I7c9084ccf1786cd4455fd748512078e02fdb17fa Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1500872 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* error: Consistently use Display instead of error description()David Tolnay2019-03-02
| | | | | | | | | | | | | | | | The description method is deprecated and its signature forces less helpful error messages than what Display can provide. BUG=none TEST=cargo check --all-features TEST=cargo check --target aarch64-unknown-linux-gnu Change-Id: I27fc99d59d0ef457c5273dc53e4c563ef439c2c0 Reviewed-on: https://chromium-review.googlesource.com/1497735 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* linux: rename function of device creationJianxun Zhang2019-03-01
| | | | | | | | | | | | | | | | | Rename functions and parameters that had 'virtio' in their names because we also create non-virtio devices like audio. BUG=none TEST=emerge-eve crosvm and deploy it to the device, verify some of devices are still created at /sys/bus/virtio/devices/ Change-Id: I3ea75159a865e5f00ecef349725b3c12f94afaca Signed-off-by: Jianxun Zhang <jianxun.zhang@intel.com> Reviewed-on: https://chromium-review.googlesource.com/1480739 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* linux: add support for loading an initrdDaniel Verkamp2019-02-07
| | | | | | | | | | | | | | Based on Linux boot protocol references: - x86: Documentation/x86/boot.txt - arm: Documentation/devicetree/bindings/chosen.txt BUG=None TEST=Boot Alpine Linux netboot initrd on x86_64 and aarch64 Change-Id: If4730765638f0a0b8bb8f63203c98e4765a354ee Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1407221 Tested-by: kokoro <noreply+kokoro@google.com>
* x86_64: return fdt size from create_fdt()Daniel Verkamp2019-02-07
| | | | | | | | | | | | | | | | | | This will allow placement of the initrd after the end of the device tree blob in the next patch. This also moves the load of the fdt into setup_system_memory() so that the position of the initrd can be calculated (in the next patch) before calling configure_system(). BUG=None TEST=Boot Termina on x86-64 Change-Id: I6dcfce3aa48ae0932157a40fa28ea9fb384263c8 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1443634 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>