From patchwork Tue Jan 12 16:52:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 8019201 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1605FBEEE5 for ; Tue, 12 Jan 2016 16:55:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2E78E202EC for ; Tue, 12 Jan 2016 16:55:53 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E6FC920145 for ; Tue, 12 Jan 2016 16:55:48 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aJ2Bx-000798-08; Tue, 12 Jan 2016 16:53:09 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aJ2Bv-000791-6z for xen-devel@lists.xensource.com; Tue, 12 Jan 2016 16:53:07 +0000 Received: from [85.158.143.35] by server-3.bemta-4.messagelabs.com id 87/CA-31122-27F25965; Tue, 12 Jan 2016 16:53:06 +0000 X-Env-Sender: prvs=81289c7df=Stefano.Stabellini@citrix.com X-Msg-Ref: server-7.tower-21.messagelabs.com!1452617584!9823133!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 54031 invoked from network); 12 Jan 2016 16:53:05 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-7.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 12 Jan 2016 16:53:05 -0000 X-IronPort-AV: E=Sophos;i="5.20,558,1444694400"; d="scan'208";a="330690733" Date: Tue, 12 Jan 2016 16:52:35 +0000 From: Stefano Stabellini X-X-Sender: sstabellini@kaball.uk.xensource.com To: Message-ID: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 X-DLP: MIA1 Cc: Wei Liu , Ian Jackson , Ian Campbell , Stefano Stabellini Subject: [Xen-devel] [PATCH] QEMU as non-root and PCI passthrough do not mix X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP PCI passthrough cannot work if QEMU is run as a non-root process today, as QEMU needs to open /dev/mem to mmap the MSI-X table of the device and read/write relevant nodes on sysfs. Update the docs to reflect that. Run QEMU as root and print a warning if at least one PCI device has been assigned to the guest at domain creation. Print a debug message on pci hotplug. Signed-off-by: Stefano Stabellini diff --git a/docs/misc/qemu-deprivilege.txt b/docs/misc/qemu-deprivilege.txt index dde74ab..cf52547 100644 --- a/docs/misc/qemu-deprivilege.txt +++ b/docs/misc/qemu-deprivilege.txt @@ -29,3 +29,13 @@ adduser --no-create-home --system xen-qemuuser-shared 3) root As a last resort, libxl will start QEMU as root. + + +Please note that QEMU will still be run as root when PCI devices are +assigned to the virtual machine (if you specified pci=["$PCI_BDF"] in +your VM config file, where $PCI_BDF is the PCI BDF of the device you +want to assign). If you want to hotplug a PCI device sometime after the +VM has started, you need to make sure that the QEMU instance of that VM +has root privileges (for example by not specifying either +xen-qemuuser-shared or xen-qemuuser-domid$domid, or by giving root +privileges to xen-qemuuser-domid$domid). diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index 0aaefd9..6b98750 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -1254,6 +1254,12 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, break; } + /* Do not run QEMU as non-root if PCI devices are assigned */ + if (guest_config->num_pcidevs > 0) { + LOG(WARN, "Cannot run QEMU as non-root when PCI devices are being assigned to the guest VM"); + goto end_search; + } + if (b_info->device_model_user) { user = b_info->device_model_user; goto end_search; diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index dc10cb7..04d0dd4 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -1176,6 +1176,9 @@ int libxl_device_pci_add(libxl_ctx *ctx, uint32_t domid, { AO_CREATE(ctx, domid, ao_how); int rc; + + LOG(DEBUG, "QEMU needs to be run as root for PCI passthrough to work"); + rc = libxl__device_pci_add(gc, domid, pcidev, 0); libxl__ao_complete(egc, ao, rc); return AO_INPROGRESS;