From patchwork Fri Aug 23 16:21:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 172111 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp885704ily; Fri, 23 Aug 2019 09:22:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqyXuzwXFiqXLdbg2GpuoKdak1s5hzrpkmIj4y9jowZrIOFL/ZgBpbKq8odWntELr3njo7tn X-Received: by 2002:ad4:4950:: with SMTP id o16mr4603386qvy.149.1566577330763; Fri, 23 Aug 2019 09:22:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566577330; cv=none; d=google.com; s=arc-20160816; b=NRtBHLl6GnyhuA2BJI73NRxbhq1pai4Qlnw7NKWUZClaHSF6/9gB5QZssPsYCpJiN6 W8CMOBkCo4TfsxPHwTgSLoV/pFDxSqyVgr40mk/5mGpjgcjIsBkfzPn/Wfd801iPpFq0 Set8CYc+e6jBifNOaXhhJ7UC95QDwsmUXp9P3K0Sms1DpOHWd0W3NhxhI6+fiZi5tbO6 9TBh7usRRMiQ35oT2XnqzlY/ZOE2FGc98jy+lgA5FIq99x8sDVzSBtc6WpGzoazukJaC JOHyyxlp8uX/8AahuKx7czbad6IZEIIr/Du50MZ1jv7k7iC41VP2UMpHT/4x2x5yNDbO glEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=3dlm0jdNYplLWDJo7y+x4dhE3Qs0gY7qc7hKobfueoA=; b=ASFMWQPdS4xa/qiua7DAXE22FYsg+lipB9P4eJUdd58I4bQ3M0k0e+Q66mwco5WJ1n +D6UmgczL20MTrE94iIBU0mvlBK4EyLvp+M4jP6HafBq99XKz7cmGeEJH91/EdD8DGE/ hkk5ZzACSp3I1708wKr9Yq0kLQcbnNXMuMefRUuu21QT64sf51CyXrVT/BOLyHU3NwDy ENZ8vqYZxSogNNkPUjvAhj7bKaAGRU2pQwYeCElQNonmEmbULqjU6uvQpzftV3pJacOL 6LEenXU7ESsWg76x5zOg5pnwjtR33hGwxQ6DQVN+iG/aMJOTQVULvQQZP6UEBESRDqH/ g+wA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id l6si2145552qkb.204.2019.08.23.09.22.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Aug 2019 09:22:10 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 725FE10F23F6; Fri, 23 Aug 2019 16:22:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 156C81001B17; Fri, 23 Aug 2019 16:22:09 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8C9E524F2F; Fri, 23 Aug 2019 16:22:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7NGM41a005977 for ; Fri, 23 Aug 2019 12:22:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4FF8B6092D; Fri, 23 Aug 2019 16:22:04 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.redhat.com (ovpn-122-169.rdu2.redhat.com [10.10.122.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 888F260605; Fri, 23 Aug 2019 16:22:03 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Fri, 23 Aug 2019 12:21:45 -0400 Message-Id: <56d8740d08f75e7f722c027391921c9c2ea43d35.1566576129.git.crobinso@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [libvirt] [PATCH v2 01/16] qemu: extract out qemuFetchConfigs from firmware X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.66]); Fri, 23 Aug 2019 16:22:09 +0000 (UTC) From: Marc-André Lureau The same config files disovery & priority rules are used for vhost-user backends. Signed-off-by: Marc-André Lureau Signed-off-by: Cole Robinson --- src/qemu/Makefile.inc.am | 2 + src/qemu/qemu_configs.c | 183 +++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_configs.h | 28 ++++++ src/qemu/qemu_firmware.c | 144 +----------------------------- 4 files changed, 215 insertions(+), 142 deletions(-) create mode 100644 src/qemu/qemu_configs.c create mode 100644 src/qemu/qemu_configs.h diff --git a/src/qemu/Makefile.inc.am b/src/qemu/Makefile.inc.am index 30a9751cfd..f7a0fa4a84 100644 --- a/src/qemu/Makefile.inc.am +++ b/src/qemu/Makefile.inc.am @@ -30,6 +30,8 @@ QEMU_DRIVER_SOURCES = \ qemu/qemu_hotplugpriv.h \ qemu/qemu_conf.c \ qemu/qemu_conf.h \ + qemu/qemu_configs.c \ + qemu/qemu_configs.h \ qemu/qemu_process.c \ qemu/qemu_process.h \ qemu/qemu_processpriv.h \ diff --git a/src/qemu/qemu_configs.c b/src/qemu/qemu_configs.c new file mode 100644 index 0000000000..39b8906be5 --- /dev/null +++ b/src/qemu/qemu_configs.c @@ -0,0 +1,183 @@ +/* + * qemu_configs.c: QEMU firmware/vhost-user etc configs + * + * Copyright (C) 2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "qemu_configs.h" +#include "configmake.h" +#include "viralloc.h" +#include "virenum.h" +#include "virfile.h" +#include "virhash.h" +#include "virlog.h" +#include "virstring.h" + +#define VIR_FROM_THIS VIR_FROM_QEMU + +VIR_LOG_INIT("qemu.qemu_configs"); + +static int +qemuBuildFileList(virHashTablePtr files, const char *dir) +{ + DIR *dirp; + struct dirent *ent = NULL; + int rc; + int ret = -1; + + if ((rc = virDirOpenIfExists(&dirp, dir)) < 0) + return -1; + + if (rc == 0) + return 0; + + while ((rc = virDirRead(dirp, &ent, dir)) > 0) { + VIR_AUTOFREE(char *) filename = NULL; + VIR_AUTOFREE(char *) path = NULL; + struct stat sb; + + if (STRPREFIX(ent->d_name, ".")) + continue; + + if (VIR_STRDUP(filename, ent->d_name) < 0) + goto cleanup; + + if (virAsprintf(&path, "%s/%s", dir, filename) < 0) + goto cleanup; + + if (stat(path, &sb) < 0) { + virReportSystemError(errno, _("Unable to access %s"), path); + goto cleanup; + } + + if (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode)) + continue; + + if (virHashUpdateEntry(files, filename, path) < 0) + goto cleanup; + + path = NULL; + } + + if (rc < 0) + goto cleanup; + + ret = 0; + cleanup: + virDirClose(&dirp); + return ret; +} + +static int +qemuConfigFilesSorter(const virHashKeyValuePair *a, + const virHashKeyValuePair *b) +{ + return strcmp(a->key, b->key); +} + +#define QEMU_SYSTEM_LOCATION PREFIX "/share/qemu" +#define QEMU_ETC_LOCATION SYSCONFDIR "/qemu" + +int +qemuFetchConfigs(const char *name, + char ***configs, + bool privileged) +{ + VIR_AUTOPTR(virHashTable) files = NULL; + VIR_AUTOFREE(char *) homeConfig = NULL; + VIR_AUTOFREE(char *) xdgConfig = NULL; + VIR_AUTOFREE(char *) sysLocation = virFileBuildPath(QEMU_SYSTEM_LOCATION, name, NULL); + VIR_AUTOFREE(char *) etcLocation = virFileBuildPath(QEMU_ETC_LOCATION, name, NULL); + VIR_AUTOFREE(virHashKeyValuePairPtr) pairs = NULL; + virHashKeyValuePairPtr tmp = NULL; + + *configs = NULL; + + if (!privileged) { + /* This is a slight divergence from the specification. + * Since the system daemon runs as root, it doesn't make + * much sense to parse files in root's home directory. It + * makes sense only for session daemon which runs under + * regular user. */ + if (VIR_STRDUP(xdgConfig, getenv("XDG_CONFIG_HOME")) < 0) + return -1; + + if (!xdgConfig) { + VIR_AUTOFREE(char *) home = virGetUserDirectory(); + + if (!home) + return -1; + + if (virAsprintf(&xdgConfig, "%s/.config", home) < 0) + return -1; + } + + if (virAsprintf(&homeConfig, "%s/qemu/%s", xdgConfig, name) < 0) + return -1; + } + + if (!(files = virHashCreate(10, virHashValueFree))) + return -1; + + if (qemuBuildFileList(files, sysLocation) < 0) + return -1; + + if (qemuBuildFileList(files, etcLocation) < 0) + return -1; + + if (homeConfig && + qemuBuildFileList(files, homeConfig) < 0) + return -1; + + /* At this point, the @files hash table contains unique set of filenames + * where each filename (as key) has the highest priority full pathname + * associated with it. */ + + if (virHashSize(files) == 0) + return 0; + + if (!(pairs = virHashGetItems(files, qemuConfigFilesSorter))) + return -1; + + for (tmp = pairs; tmp->key; tmp++) { + const char *path = tmp->value; + off_t len; + + if ((len = virFileLength(path, -1)) < 0) { + virReportSystemError(errno, + _("unable to get size of '%s'"), + path); + return -1; + } + + VIR_DEBUG("%s description path '%s' len=%jd", + name, path, (intmax_t) len); + + if (len == 0) { + /* Empty files are used to mask less specific instances + * of the same file. */ + continue; + } + + if (virStringListAdd(configs, path) < 0) + return -1; + } + + return 0; +} diff --git a/src/qemu/qemu_configs.h b/src/qemu/qemu_configs.h new file mode 100644 index 0000000000..5c113752d0 --- /dev/null +++ b/src/qemu/qemu_configs.h @@ -0,0 +1,28 @@ +/* + * qemu_configs.h: QEMU firmware/vhost-user etc configs + * + * Copyright (C) 2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#pragma once + +#include "internal.h" + +int +qemuFetchConfigs(const char *name, + char ***configs, + bool privileged); diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c index 983a7c83b2..f0a6953d8b 100644 --- a/src/qemu/qemu_firmware.c +++ b/src/qemu/qemu_firmware.c @@ -23,13 +23,12 @@ #include #include "qemu_firmware.h" +#include "qemu_configs.h" #include "configmake.h" #include "qemu_capabilities.h" #include "qemu_domain.h" #include "qemu_process.h" #include "virarch.h" -#include "virfile.h" -#include "virhash.h" #include "virjson.h" #include "virlog.h" #include "virstring.h" @@ -907,150 +906,11 @@ qemuFirmwareFormat(qemuFirmwarePtr fw) } -static int -qemuFirmwareBuildFileList(virHashTablePtr files, const char *dir) -{ - DIR *dirp; - struct dirent *ent = NULL; - int rc; - int ret = -1; - - if ((rc = virDirOpenIfExists(&dirp, dir)) < 0) - return -1; - - if (rc == 0) - return 0; - - while ((rc = virDirRead(dirp, &ent, dir)) > 0) { - VIR_AUTOFREE(char *) filename = NULL; - VIR_AUTOFREE(char *) path = NULL; - struct stat sb; - - if (STRPREFIX(ent->d_name, ".")) - continue; - - if (VIR_STRDUP(filename, ent->d_name) < 0) - goto cleanup; - - if (virAsprintf(&path, "%s/%s", dir, filename) < 0) - goto cleanup; - - if (stat(path, &sb) < 0) { - virReportSystemError(errno, _("Unable to access %s"), path); - goto cleanup; - } - - if (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode)) - continue; - - if (virHashUpdateEntry(files, filename, path) < 0) - goto cleanup; - - path = NULL; - } - - if (rc < 0) - goto cleanup; - - ret = 0; - cleanup: - virDirClose(&dirp); - return ret; -} - -static int -qemuFirmwareFilesSorter(const virHashKeyValuePair *a, - const virHashKeyValuePair *b) -{ - return strcmp(a->key, b->key); -} - -#define QEMU_FIRMWARE_SYSTEM_LOCATION PREFIX "/share/qemu/firmware" -#define QEMU_FIRMWARE_ETC_LOCATION SYSCONFDIR "/qemu/firmware" - int qemuFirmwareFetchConfigs(char ***firmwares, bool privileged) { - VIR_AUTOPTR(virHashTable) files = NULL; - VIR_AUTOFREE(char *) homeConfig = NULL; - VIR_AUTOFREE(char *) xdgConfig = NULL; - VIR_AUTOFREE(virHashKeyValuePairPtr) pairs = NULL; - virHashKeyValuePairPtr tmp = NULL; - - *firmwares = NULL; - - if (!privileged) { - /* This is a slight divergence from the specification. - * Since the system daemon runs as root, it doesn't make - * much sense to parse files in root's home directory. It - * makes sense only for session daemon which runs under - * regular user. */ - if (VIR_STRDUP(xdgConfig, getenv("XDG_CONFIG_HOME")) < 0) - return -1; - - if (!xdgConfig) { - VIR_AUTOFREE(char *) home = virGetUserDirectory(); - - if (!home) - return -1; - - if (virAsprintf(&xdgConfig, "%s/.config", home) < 0) - return -1; - } - - if (virAsprintf(&homeConfig, "%s/qemu/firmware", xdgConfig) < 0) - return -1; - } - - if (!(files = virHashCreate(10, virHashValueFree))) - return -1; - - if (qemuFirmwareBuildFileList(files, QEMU_FIRMWARE_SYSTEM_LOCATION) < 0) - return -1; - - if (qemuFirmwareBuildFileList(files, QEMU_FIRMWARE_ETC_LOCATION) < 0) - return -1; - - if (homeConfig && - qemuFirmwareBuildFileList(files, homeConfig) < 0) - return -1; - - /* At this point, the @files hash table contains unique set of filenames - * where each filename (as key) has the highest priority full pathname - * associated with it. */ - - if (virHashSize(files) == 0) - return 0; - - if (!(pairs = virHashGetItems(files, qemuFirmwareFilesSorter))) - return -1; - - for (tmp = pairs; tmp->key; tmp++) { - const char *path = tmp->value; - off_t len; - - if ((len = virFileLength(path, -1)) < 0) { - virReportSystemError(errno, - _("unable to get size of '%s'"), - path); - return -1; - } - - VIR_DEBUG("firmware description path '%s' len=%jd", - path, (intmax_t) len); - - if (len == 0) { - /* Empty files are used to mask less specific instances - * of the same file. */ - continue; - } - - if (virStringListAdd(firmwares, path) < 0) - return -1; - } - - return 0; + return qemuFetchConfigs("firmware", firmwares, privileged); } From patchwork Fri Aug 23 16:21:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 172112 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp885714ily; Fri, 23 Aug 2019 09:22:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqySOUeZ3bbHm2nogKx2OYV/FHsMzppR2KQJquLDT/qblggljR9XwFNhjXTlzT/Si+oSBf9i X-Received: by 2002:a05:6214:561:: with SMTP id cj1mr4692653qvb.50.1566577331015; Fri, 23 Aug 2019 09:22:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566577331; cv=none; d=google.com; s=arc-20160816; b=g6Jgxf3ze0i4YMj4mxFk+TKgI9QJ0z/pwx9+YRbn6GlvhQ3sYjbNfgTvJ3W3KgJiQJ 3/wPxkWoMT94DGqraCceNiNfIrt/bBOEeFVSoNlmIg+KV89tJIHUtceN0heTrEX3KIZA H1FMwwOHunyuDAk8jheW00jYXDwWnP9J1SrEoVnUv4BUPPIJs9HFMHOrpIfMLmrDUb1B lJbhHuN6A1pUyIHNG80COvcmsih6AF0VRcJyRINZE/9tRRgN+siE8M2zjaJnm7BRjzkp u39P3RYtpjd8xuuiDp+BNmvlKDfWa/29WAcxyAgSemBkVG66qxe7ShAe5Q9n3y22kPFK +s1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=AU1kwMhv3k0LIn3YvkuXKA6Cwtzzl6l0+lWUOTPKBfs=; b=VXBorI8Qef6+VIkV45ge6NTlG1lOjkpVj+H+3BSJX5hKsuFT6FAvucsU6Ifejyy1zf HeT7S5Ay2Hl+Xlvt6Gsq4gRb8h1Q8XEbGp8KqaLLe4P91XvHV3rolbDVv+4VKKoi1vqY 946Fs2srNXzzILli0TUsqVf6itYXjUVuNLcZ+alN47wCl/N7DR9acflJNT6K5X0QOAVm Z4xyP2pQopA/tLp/nsLJK1l5bO5CyCz4hmZIqZAgFgLZHQcW2POLdwUkI73AYdea0th5 slEhw14tbMqSpiyi5IBXdRXsUZMUBKn+kYaMvHWO/RXAEJQsRadGHVfChsez1fjpB7rl nqGA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id 124si2098437qkh.244.2019.08.23.09.22.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Aug 2019 09:22:11 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9492618DE768; Fri, 23 Aug 2019 16:22:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 171A24142; Fri, 23 Aug 2019 16:22:09 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5137324F35; Fri, 23 Aug 2019 16:22:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7NGM51R005984 for ; Fri, 23 Aug 2019 12:22:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0724C60605; Fri, 23 Aug 2019 16:22:05 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.redhat.com (ovpn-122-169.rdu2.redhat.com [10.10.122.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89E0F6092D; Fri, 23 Aug 2019 16:22:04 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Fri, 23 Aug 2019 12:21:46 -0400 Message-Id: <76dadadc00b9c519e4b25f321776347672781cb9.1566576129.git.crobinso@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [libvirt] [PATCH v2 02/16] domain: add "vhostuser" attribute to virtio video model X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.63]); Fri, 23 Aug 2019 16:22:10 +0000 (UTC) From: Marc-André Lureau Accept a new attribute to specify usage of helper process, ex: Signed-off-by: Marc-André Lureau Signed-off-by: Cole Robinson --- docs/formatdomain.html.in | 6 ++++++ docs/schemas/domaincommon.rng | 11 ++++++++++- src/conf/domain_conf.c | 14 ++++++++++++++ src/conf/domain_conf.h | 1 + 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index fcb7c59c00..ec650fbe17 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -7039,6 +7039,12 @@ qemu-kvm -net nic,model=? /dev/null Attribute vram64 (since 1.3.3) extends secondary bar and makes it addressable as 64bit memory.

+

+ For guest type "kvm" and model type "virtio" there are + optional attributes. Attribute vhost-user + (since 5.5.0) specify that a + vhost-user helper process should be associated with the GPU. +

acceleration
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index c48f8c4f56..bac566855d 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -3581,7 +3581,6 @@ vmvga xen vbox - virtio gop none bochs @@ -3607,6 +3606,16 @@ + + + virtio + + + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b7a342bb91..f51575d57d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15358,6 +15358,7 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt, xmlNodePtr cur; VIR_XPATH_NODE_AUTORESTORE(ctxt); VIR_AUTOFREE(char *) type = NULL; + VIR_AUTOFREE(char *) vhostuser = NULL; VIR_AUTOFREE(char *) heads = NULL; VIR_AUTOFREE(char *) vram = NULL; VIR_AUTOFREE(char *) vram64 = NULL; @@ -15376,6 +15377,7 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt, if (!type && !vram && !ram && !heads && virXMLNodeNameEqual(cur, "model")) { type = virXMLPropString(cur, "type"); + vhostuser = virXMLPropString(cur, "vhostuser"); ram = virXMLPropString(cur, "ram"); vram = virXMLPropString(cur, "vram"); vram64 = virXMLPropString(cur, "vram64"); @@ -15408,6 +15410,16 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt, def->type = virDomainVideoDefaultType(dom); } + if (vhostuser != NULL) { + if (virStringParseYesNo(vhostuser, &def->vhostuser) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unknown vhostuser value '%s'"), vhostuser); + goto cleanup; + } + } else { + def->vhostuser = false; + } + if (ram) { if (def->type != VIR_DOMAIN_VIDEO_TYPE_QXL) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -26486,6 +26498,8 @@ virDomainVideoDefFormat(virBufferPtr buf, virBufferAsprintf(buf, " heads='%u'", def->heads); if (def->primary) virBufferAddLit(buf, " primary='yes'"); + if (def->vhostuser) + virBufferAddLit(buf, " vhostuser='yes'"); if (def->accel) { virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 33cef5b75c..bc2450f25e 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1424,6 +1424,7 @@ struct _virDomainVideoDef { virDomainVideoDriverDefPtr driver; virDomainDeviceInfo info; virDomainVirtioOptionsPtr virtio; + bool vhostuser; }; /* graphics console modes */ From patchwork Fri Aug 23 16:21:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 172114 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp885976ily; Fri, 23 Aug 2019 09:22:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqy3oBBM4hcDvd7rCjWBHdc5nP02rGEUusuaFX573zQdy8v7+RvknFiD2M9wquxjv8a3KsjH X-Received: by 2002:aed:2e24:: with SMTP id j33mr5658729qtd.179.1566577347099; Fri, 23 Aug 2019 09:22:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566577347; cv=none; d=google.com; s=arc-20160816; b=cSoavWayk02cLqLjzWENyWgx82XCvd8Y57OA+qh9hk/OfD/mzbyZAHO61Yx5KkRnJz alSFqSZViQK7eIX7GnwSk9YcUqmNNuwOeVRvsQmMdjGrYyfzu+AV6AndPFeI1eZaCQbr ZkrB+ikd7BRGPNpyDBYei4skW9nwTQOAi0DDwSc/g8Ii8obkxtisuymt9Pdhev/ZObZG PKAB9o3PvRa1hEMDd6LoBusV0RjVxaeE/6GAyHp+5ZSIHLAqA+VojLqMvZdaYbh9OJqN P4dHDXrXVKjcT5yEy/uJMf+Zz4T3i5uz7FUjArwO467tWZmUPdvR5QfrVqJ7kMbrDQLL vm0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=UHRQzObOpVvU0jfgn71csAfJ83VE4aCGzVCZC2cdleI=; b=iFsokf7XnmKKdLhOWrHX2z3+g9pnUY4lWhzYjauusyI8lAhQg39zzhpRtey9IQyQeR EwmY9I5LxoGWzftV5/VAg8fLW3/Wa/f16ep0sOxdmB9CrVjwNtA+hNqLt4dbDGbZ5Y4l ++VuzZR/b1N9xnCOp9+zlMDhVGSoQkW7FzJlSMSzW8FF9/TfeYhiMTGd7tF9X2sxvTxS IwOfsDwvb4QFlf6UB6+RkqDSg8+pr3v4i8VCsu0+sI0P3bcE7+h3YFghcHrq8+rmhS2w qhBGzjhi4XH6wOp49A4CDGQBWTf/JBMaa4llqOZ6OiZ0j4Dc6Rs8uuhly9+Ufr86ms1c kipg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id b37si2390950qtb.269.2019.08.23.09.22.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Aug 2019 09:22:27 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D61FC3CA16; Fri, 23 Aug 2019 16:22:25 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B56465D784; Fri, 23 Aug 2019 16:22:25 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 790531802220; Fri, 23 Aug 2019 16:22:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7NGM5tc005992 for ; Fri, 23 Aug 2019 12:22:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id A3A7760605; Fri, 23 Aug 2019 16:22:05 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.redhat.com (ovpn-122-169.rdu2.redhat.com [10.10.122.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3045160872; Fri, 23 Aug 2019 16:22:05 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Fri, 23 Aug 2019 12:21:47 -0400 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [libvirt] [PATCH v2 03/16] domain: add rendernode attribute on X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 23 Aug 2019 16:22:26 +0000 (UTC) From: Marc-André Lureau vhost-user-gpu helper may accept --render-node option to specify on which GPU should the renderning be done. (by comparison rendernode is the target/display rendering) Signed-off-by: Marc-André Lureau Signed-off-by: Cole Robinson --- docs/formatdomain.html.in | 5 +++++ docs/schemas/domaincommon.rng | 5 +++++ src/conf/domain_conf.c | 18 +++++++++++++++++- src/conf/domain_conf.h | 1 + 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index ec650fbe17..5a4807d937 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -7059,6 +7059,11 @@ qemu-kvm -net nic,model=? /dev/null
Enable 3D acceleration (for vbox driver since 0.7.1, qemu driver since 1.3.0)
+ +
rendernode
+
Absolute path to a host's DRI device to be used for + rendering (for vhost-user driver only, since 5.5.0)
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index bac566855d..6e91fe6cef 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -3644,6 +3644,11 @@
+ + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f51575d57d..2cc055491d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2832,6 +2832,8 @@ virDomainVideoDefClear(virDomainVideoDefPtr def) virDomainDeviceInfoClear(&def->info); + if (def->accel) + VIR_FREE(def->accel->rendernode); VIR_FREE(def->accel); VIR_FREE(def->virtio); VIR_FREE(def->driver); @@ -15270,6 +15272,7 @@ virDomainVideoAccelDefParseXML(xmlNodePtr node) int val; VIR_AUTOFREE(char *) accel2d = NULL; VIR_AUTOFREE(char *) accel3d = NULL; + VIR_AUTOFREE(char *) rendernode = NULL; cur = node->children; while (cur != NULL) { @@ -15278,12 +15281,13 @@ virDomainVideoAccelDefParseXML(xmlNodePtr node) virXMLNodeNameEqual(cur, "acceleration")) { accel3d = virXMLPropString(cur, "accel3d"); accel2d = virXMLPropString(cur, "accel2d"); + rendernode = virXMLPropString(cur, "rendernode"); } } cur = cur->next; } - if (!accel3d && !accel2d) + if (!accel3d && !accel2d && !rendernode) return NULL; if (VIR_ALLOC(def) < 0) @@ -15307,6 +15311,9 @@ virDomainVideoAccelDefParseXML(xmlNodePtr node) def->accel2d = val; } + if (VIR_STRDUP(def->rendernode, rendernode) < 0) + goto cleanup; + cleanup: return def; } @@ -15474,6 +15481,11 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; } } + if (!def->vhostuser && def->accel && def->accel->rendernode) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("unsupported rendernode accel attribute without 'vhost-user'")); + goto error; + } if (virDomainDeviceInfoParseXML(xmlopt, node, &def->info, flags) < 0) goto error; @@ -26452,6 +26464,10 @@ virDomainVideoAccelDefFormat(virBufferPtr buf, virBufferAsprintf(buf, " accel2d='%s'", virTristateBoolTypeToString(def->accel2d)); } + if (def->rendernode) { + virBufferAsprintf(buf, " rendernode='%s'", + def->rendernode); + } virBufferAddLit(buf, "/>\n"); } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index bc2450f25e..707fbd1cd3 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1405,6 +1405,7 @@ VIR_ENUM_DECL(virDomainVideoVGAConf); struct _virDomainVideoAccelDef { int accel2d; /* enum virTristateBool */ int accel3d; /* enum virTristateBool */ + char *rendernode; }; From patchwork Fri Aug 23 16:21:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 172115 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp885984ily; Fri, 23 Aug 2019 09:22:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqwae4ynb4PTfsIL/jQai/TEoNFYlJFJoe2D+/GnjVfW+kPSXoyfpVnl7tG0QwHHtll2hHSg X-Received: by 2002:ac8:341d:: with SMTP id u29mr5371758qtb.320.1566577347375; Fri, 23 Aug 2019 09:22:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566577347; cv=none; d=google.com; s=arc-20160816; b=SrsjiUwsVQcT/JWgnjqr7h2eA4jtU7eWFJN+H+mA4dS03jzMYwyEf60P+UUuWYnwk3 WwhV/QbdoyZpR95JWsWB8fTHJaob3g+uhV8C5fYuiMXue2e6o05uOt+95VmV5gTSPNhW MO+hcQIT1mzQJ6BJWFK5mKcZ5vsrTmosvc7F6OQMWeCi6NzFPKhI+I2RiaLWrFITj3b1 UtwRlELnFzboFVTKBI1CT5T1JNA1WIAUwSl1j2El0sqI5lugfnvck8aDRYxu0Y/xDvNx eY2+KcdzSImKx8WNIBN7bIvGbs9gf/mfReaf+n6o/226+ykdPAvKSre3kZUoUgmBUu0j X+Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=x53LEDDYOGDvRskIUKw103kFla+HOQZzlWoA+lZTcYM=; b=IxXcfojXvE1H1eHxEwPf5AVrmm+UxnmeYfLh8ptHlLScUn0RamJujUksNPOlcZIg7B dGtzMnHG/L7cFx4sKUYIj8luDnTmSsbPXmvYxVzrBW0Nq7nNtONwN/ksGyItd2Bn0v2t QYaNqzv66DQMFnQYUHoOKzqb3x9VjNuWEv4ojzCt8LY6a7jI4xq4XIpm9uY6KRTF1urO KB4bB+lY6/mVIArUcSwmtSkrgXShivHJmcxaFFN9iH+LEekPhUnsgtLjfcI3Y0yz/yI6 Nj0DIbwnOXEzkU8td8UUJi+Ut4qKPuUN+PBPMD/Gfn6FpT1ZFJYMpm/W65iDrviU5W3T Z+iQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id t5si2187393qkh.43.2019.08.23.09.22.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Aug 2019 09:22:27 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DFBB818C427C; Fri, 23 Aug 2019 16:22:25 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B8CA86012D; Fri, 23 Aug 2019 16:22:25 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 79BB724F33; Fri, 23 Aug 2019 16:22:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7NGM6rW005999 for ; Fri, 23 Aug 2019 12:22:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 49DE360628; Fri, 23 Aug 2019 16:22:06 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.redhat.com (ovpn-122-169.rdu2.redhat.com [10.10.122.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC01260872; Fri, 23 Aug 2019 16:22:05 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Fri, 23 Aug 2019 12:21:48 -0400 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [libvirt] [PATCH v2 04/16] qemu-cgroup: allow accel rendernode access X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.62]); Fri, 23 Aug 2019 16:22:26 +0000 (UTC) From: Marc-André Lureau Signed-off-by: Marc-André Lureau Signed-off-by: Cole Robinson Reviewed-by: Ján Tomko --- src/qemu/qemu_cgroup.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index ecd96efb0a..eb6f993d8e 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -503,6 +503,25 @@ qemuSetupGraphicsCgroup(virDomainObjPtr vm, } +static int +qemuSetupVideoAccelCgroup(virDomainObjPtr vm, + virDomainVideoAccelDefPtr def) +{ + qemuDomainObjPrivatePtr priv = vm->privateData; + int ret; + + if (!def->rendernode || + !virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) + return 0; + + ret = virCgroupAllowDevicePath(priv->cgroup, def->rendernode, + VIR_CGROUP_DEVICE_RW, false); + virDomainAuditCgroupPath(vm, priv->cgroup, "allow", def->rendernode, + "rw", ret); + return ret; +} + + static int qemuSetupBlkioCgroup(virDomainObjPtr vm) { @@ -803,6 +822,11 @@ qemuSetupDevicesCgroup(virDomainObjPtr vm) goto cleanup; } + for (i = 0; i < vm->def->nvideos; i++) { + if (qemuSetupVideoAccelCgroup(vm, vm->def->videos[i]->accel) < 0) + goto cleanup; + } + for (i = 0; i < vm->def->ninputs; i++) { if (qemuSetupInputCgroup(vm, vm->def->inputs[i]) < 0) goto cleanup; From patchwork Fri Aug 23 16:21:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 172113 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp885974ily; Fri, 23 Aug 2019 09:22:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqzmA0AzIFCbugG7byfbNRL460aoNBA2+22YoxZsMDd/7KO5yMPfukRzuyElHDdoY3MPeCIR X-Received: by 2002:a05:620a:1345:: with SMTP id c5mr4709516qkl.109.1566577347075; Fri, 23 Aug 2019 09:22:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566577347; cv=none; d=google.com; s=arc-20160816; b=OMAW6o8ho0o4RRpK33yJM11rrEFD+kEs//Y1ybYJws0jNwYxIEse19UjQBRp0+yLE3 gBcRb0UTBgo7sDNtcwtnobaB2SSL4gWgkunO7rpGnhcBOP1cJv10ZgJSX6Ot1tNFqf1x MviWU9cn331axPQ48pvgF3kG6+0evF5w93z2f8F9IW74rPn7mqKG+iZ6YaG5Cgpz90z3 8GoQV7mMz9JXoa2lAnwl43OmbCPHM5d4+LhjSiWdWs3YNUPCumwtCb3sjEFrklkNaswK 5Om/t9cPfls1+/IKwV1YFhTkY31ewliZXGn7pOR0PvMrW4ZVJIxGHMLtd3lOyitBjyP4 +Fkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=zYiL0PmFcv/Ngi+rcEYNYb+jqB988T/9G81b1XUz1ok=; b=eHfbAHQN8Rv7qsVBEgMEw4Bj8T29Okzy0OTVVCMUF1NYBm///p2BBt9PMR8ETFPdjy PmuE+g5moS4GIw+Cc0OxRMWAkYCV1SBAkogpUx94JhAda3vlqZCpmLhnEJ/pr7RHooCk iCCPXB/InXnlCsTCFCW9K35nJ+3sOmV07iQ2HhUg8ddDbwcgvdoMzre1OU1l6Pn21sTc MiIMnoWxMptFS6wEZ9GTOZzMh1XoCBOcTgk94FPsDCEF0dQ1bnFv7EmumPgkeyY+Yi2s IbpPILrHA+hlrSIZhokwV6RGtnEd7H+Qk/r7AZ9vx9kE1VEbC+ywoiDyqUt4sVK124QT 3tQQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id c31si2458296qtc.234.2019.08.23.09.22.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Aug 2019 09:22:27 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D5B33881361; Fri, 23 Aug 2019 16:22:25 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B10492634D; Fri, 23 Aug 2019 16:22:25 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 76ABA180221F; Fri, 23 Aug 2019 16:22:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7NGM6oe006004 for ; Fri, 23 Aug 2019 12:22:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id E3DE660606; Fri, 23 Aug 2019 16:22:06 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.redhat.com (ovpn-122-169.rdu2.redhat.com [10.10.122.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71AEB60872; Fri, 23 Aug 2019 16:22:06 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Fri, 23 Aug 2019 12:21:49 -0400 Message-Id: <662e7bc629a2b549b4be48471e36fb798ca08d22.1566576129.git.crobinso@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [libvirt] [PATCH v2 05/16] qemu: add vhost-user-gpu capabilities checks X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Fri, 23 Aug 2019 16:22:26 +0000 (UTC) From: Marc-André Lureau Those new devices are merged for QEMU 4.1. Signed-off-by: Marc-André Lureau Signed-off-by: Cole Robinson Reviewed-by: Ján Tomko --- src/qemu/qemu_capabilities.c | 4 ++++ src/qemu/qemu_capabilities.h | 2 ++ tests/qemucapabilitiesdata/caps_4.1.0.x86_64.xml | 2 ++ 3 files changed, 8 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 73300128ea..d27f54d16e 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -537,6 +537,8 @@ VIR_ENUM_IMPL(virQEMUCaps, /* 335 */ "bochs-display", "migration-file-drop-cache", + "vhost-user-gpu", + "vhost-user-vga", ); @@ -1127,6 +1129,8 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = { { "virtio-serial-pci-non-transitional", QEMU_CAPS_VIRTIO_PCI_TRANSITIONAL }, { "max-x86_64-cpu", QEMU_CAPS_X86_MAX_CPU }, { "bochs-display", QEMU_CAPS_DEVICE_BOCHS_DISPLAY }, + { "vhost-user-gpu", QEMU_CAPS_DEVICE_VHOST_USER_GPU }, + { "vhost-user-vga", QEMU_CAPS_DEVICE_VHOST_USER_VGA }, }; static struct virQEMUCapsStringFlags virQEMUCapsDevicePropsVirtioBalloon[] = { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 68ef6c49b4..6f1e1dd2f3 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -518,6 +518,8 @@ typedef enum { /* virQEMUCapsFlags grouping marker for syntax-check */ /* 335 */ QEMU_CAPS_DEVICE_BOCHS_DISPLAY, /* -device bochs-display */ QEMU_CAPS_MIGRATION_FILE_DROP_CACHE, /* migration with disk cache on is safe for type='file' disks */ + QEMU_CAPS_DEVICE_VHOST_USER_GPU, /* -device vhost-user-gpu */ + QEMU_CAPS_DEVICE_VHOST_USER_VGA, /* -device vhost-user-vga */ QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; diff --git a/tests/qemucapabilitiesdata/caps_4.1.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_4.1.0.x86_64.xml index f4583d7fe7..5d4540b3f7 100644 --- a/tests/qemucapabilitiesdata/caps_4.1.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_4.1.0.x86_64.xml @@ -209,6 +209,8 @@ + + 4000050 0 43100759 From patchwork Fri Aug 23 16:21:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 172117 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp886065ily; Fri, 23 Aug 2019 09:22:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqxsri1nIKPfRvkpQm3c2+2x1pVJluWQkb44sqm9dPC9t5b4OyKl01HD0TGzuHvVflpUgGqU X-Received: by 2002:ac8:21bd:: with SMTP id 58mr5663463qty.192.1566577351629; Fri, 23 Aug 2019 09:22:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566577351; cv=none; d=google.com; s=arc-20160816; b=GpSWcE6gYHp8gO4R3HvcY46DOgZa8gIsHWKluWrl/ShhwYJE+9o2+wjSWA9y2QCRmk IGO7tAybM28hNGiieRO4HkhZhEEImGfBcCtg9NPXZUnfRJwwsmAsbrBQfENjMqwIDyHm eRY27IDoEgHbVmU5hw5DHLmqUO17TsAZdkkGDokCWqYPsWbRFye+Y2lhsq4hNLNM/9Ky 5qDRhkUf7IDhp7fZJOwI1i/GQ4GcfrG8ruDmrxoftMIjb5uXU/f2TgU9annzYkrdG3rh TmBdCd1/OqPiluPP1xyvocgEtE2pNbXzJQCVHZe9H9Yf4uGhWOvVws3LHU+URhRqseSF /Cww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=OhJ4aSjXADNqQ07RCTV5gV91e9QW/Q50WeIbFeyAsa4=; b=BD4jqyJt9LG9o0cJ2DMjxxGN6/WtB3uQ/+vfy9M9yFHdoOXjrFl1eWPJGUy68t0LUa RR3u+YCtSQqEd4EncoVQ59Djs+0dBZ2G9xFmUEFg6WidOraITI/pSWCMny/EsT/EqnVq XSxjDNd2rsC7xJ7daDZwkWzMp+2d4t+RCCJzvRuc/zWxU6c+1ou2wRRPo2QZqUR1zbJN CCalR1Gg/psKnWuP6yHrVJ4iLnNEVNOZTLiTHwSCsjIb8ogdo10JePLl50oZlMrXeN8G rzHN4bO2JFSPgZMf4gE7sP3Ba0e78c95/xTgNDAYIYcKsIZ7IHbgzRmyDwuhAZbpObzr 2ghg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id t13si2385928qkj.183.2019.08.23.09.22.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Aug 2019 09:22:31 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4A60F30860BE; Fri, 23 Aug 2019 16:22:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C12C60A9F; Fri, 23 Aug 2019 16:22:30 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DF5FC24F34; Fri, 23 Aug 2019 16:22:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7NGM7sd006012 for ; Fri, 23 Aug 2019 12:22:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8BEEA60605; Fri, 23 Aug 2019 16:22:07 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.redhat.com (ovpn-122-169.rdu2.redhat.com [10.10.122.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1969F6092D; Fri, 23 Aug 2019 16:22:07 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Fri, 23 Aug 2019 12:21:50 -0400 Message-Id: <58e9b4aefdd87f77f681955746ff93e62bb98c5c.1566576129.git.crobinso@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [libvirt] [PATCH v2 06/16] qemu: check that qemu is vhost-user-vga capable X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 23 Aug 2019 16:22:30 +0000 (UTC) From: Marc-André Lureau To support virtio VGA with vhost-user, vhost-user-vga device is necessary. Signed-off-by: Marc-André Lureau Signed-off-by: Cole Robinson Reviewed-by: Ján Tomko --- src/qemu/qemu_domain.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d0722f8761..bf0531126d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -12386,9 +12386,14 @@ bool qemuDomainSupportsVideoVga(virDomainVideoDefPtr video, virQEMUCapsPtr qemuCaps) { - if (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_VGA)) - return false; + if (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO) { + if (video->vhostuser) { + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VHOST_USER_VGA)) + return false; + } else if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_VGA)) { + return false; + } + } return true; } From patchwork Fri Aug 23 16:21:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 172119 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp886160ily; Fri, 23 Aug 2019 09:22:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqzRyzL4z9cjGXMHX/sf0X2POfYonPsBN42yA64U6ex8j7evU1pVO8UuegdeTMaXFarXUTOs X-Received: by 2002:a37:9802:: with SMTP id a2mr4948373qke.346.1566577355895; Fri, 23 Aug 2019 09:22:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566577355; cv=none; d=google.com; s=arc-20160816; b=IGP9kkVTTqjAkZewXi3Ds5ui+rEgC+OuTXq6WQP4omQqrSVAXmw/ZdJo0+FQwTMbh5 N3z1vSarrKJdlnm/KZoYzGaGLQk/D2R0AGMW++bGw1ew0lu0/bYkDLqNafRjpQc+nl7C 9/rTpc1vd995Dvg/W+4voYB6Ct8AsEb+7ywWVikqbZRBX1r9Y4CTV2lSE7/ARQqotrQA ymjCAzY5Ef5yd2VAXLRUUORGYZTu/YSEITk9bILeTJz8AUA1f2RE7zuL4UqwYfBdJXbq cJTf4JZHHEZYwuk/YmH7tViJVHEktKfk7bC2BZedgW+7DcYu6VVZlnrzU3u8g/n/kDbz GmIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=2djRaFfMhbkMmqYV32xS5dyMrC2v0LIsrbV1xRX88Ys=; b=KDjvOsQg/W/E13asoG3BPP3KnjrB5hlomxEGcWJ6t+wlGXv9dVff9HWdbuGYdIptq3 psrCKjcGr6iUtJ9mK5OWyh9N4udQoIJbHlDiCXTYxxZkWG9fjzWfdbbgj/AyvRyaP7/b HgBUFXVQH+olzuTYWqhucypyYtaZosNu1Xa/GQehP8gEt69Tnf3VaR38bAT9S7rZHtv+ VnXc5oZI6k9Xx0y8NUyWwnbvQx9ZKSNibXXcVZ3G7AGoJN96uBUQRncMjMR3Ms4J6BwQ JjV/T7kYOqDZdxZXRAw9WxzeMkm1KqVs+rIuIuLvcQoq7oV4m/vFdBdETcnckm4NECgI Xo7Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id h23si2137730qkk.212.2019.08.23.09.22.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Aug 2019 09:22:35 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8A6A210C030C; Fri, 23 Aug 2019 16:22:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5F84DBA8A; Fri, 23 Aug 2019 16:22:34 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 19700180BA99; Fri, 23 Aug 2019 16:22:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7NGM8HZ006022 for ; Fri, 23 Aug 2019 12:22:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 33E8260605; Fri, 23 Aug 2019 16:22:08 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.redhat.com (ovpn-122-169.rdu2.redhat.com [10.10.122.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id B3C186092D; Fri, 23 Aug 2019 16:22:07 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Fri, 23 Aug 2019 12:21:51 -0400 Message-Id: <96949c1e9b5df8c986a9b36f640dd3dec8dcb0c9.1566576129.git.crobinso@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [libvirt] [PATCH v2 07/16] qemu: validate virtio-gpu with vhost-user X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.65]); Fri, 23 Aug 2019 16:22:35 +0000 (UTC) From: Marc-André Lureau Check qemu capability, and accept 3d acceleration. 3d acceleration support is checked when looking for a suitable vhost-user helper. Signed-off-by: Marc-André Lureau Signed-off-by: Cole Robinson --- src/qemu/qemu_process.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index c9921646e9..c439f17011 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5274,8 +5274,10 @@ qemuProcessStartValidateVideo(virDomainObjPtr vm, !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VMWARE_SVGA)) || (video->type == VIR_DOMAIN_VIDEO_TYPE_QXL && !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_QXL)) || - (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO && + (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO && !video->vhostuser && !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_GPU)) || + (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO && video->vhostuser && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VHOST_USER_GPU)) || (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO && video->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW && !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_GPU_CCW))) { @@ -5285,7 +5287,15 @@ qemuProcessStartValidateVideo(virDomainObjPtr vm, return -1; } - if (video->accel) { + if (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO && + video->vhostuser && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VHOST_USER_GPU)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("this QEMU does not support vhost-user backed video device")); + return -1; + } + + if (!video->vhostuser && video->accel) { if (video->accel->accel3d == VIR_TRISTATE_SWITCH_ON && (video->type != VIR_DOMAIN_VIDEO_TYPE_VIRTIO || !virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_GPU_VIRGL))) { From patchwork Fri Aug 23 16:21:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 172116 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp886040ily; Fri, 23 Aug 2019 09:22:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqyp6U81tk0xOoi5hCX+n59sG3tVG1ljp6n9lu7zWebMYt1/qLz6UJFr+YusUkuTy0qb55kT X-Received: by 2002:ac8:7314:: with SMTP id x20mr5606793qto.239.1566577350452; Fri, 23 Aug 2019 09:22:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566577350; cv=none; d=google.com; s=arc-20160816; b=we6wYIs8VxdkjQ+2BcAx/9RF4elyCWL75eRkl0yfzJsZy5G9VRBJ6SbsuRJdYIrqKX DiHiq9VnXRXKGghDYeT20X3xPAGGIMLOkOtqZMl+9zDFXx42U8aaQiYsLL7M3y2R+tXh h1bh8J4TdMMBtwaLjBK45496fOn0IP7Im3m769vy8yPVNd26GzX1uCBoJeBf7iTtV/te YO7mOYKc7onvuadLs3ZcFZ5a2pxH4jNb3Kf8GfFiqdoTfjp2gdtmWtBJNuOLSOh2Mk4b dOKz3QxVTvgyWHASRtYTJZFQyDRZI4lqXppiUhNhoRwdgfpgbp0GMRs9GWN1Oo/dZxBy Cytg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=QDtDM6fTz95wXv3XUI2/+5jRWctaTqsxW10wafluDuw=; b=uVzSGbVVqHU165zwuXAQVFX3QXPHf7Mg2cGCbjvmwekOhKdOPiTvoStg6bOgrVo6z/ QJQUN2DOmGEBrTqbWOYEfGpM3/5NGZ/JkY4bbiySgp6kV0xekosrOlqQeWPWBtecMJju 7dlIploa6x3lz/wGlPXmqS28kn/aTyVtlVTrOh+tFYf+pPsaWzk2IBWTlW2lEbTmipxZ cyqgvRfmkMGj+61y/HgO2Bi7IfQiqYbVqVGupG5RlIApfXYdOGRTiDusrGL60GBTyizS q1Y5m3kNWYX4Pfp2JRAenHhGScrgKUkeQAXkTZywi99a7qx8zzHYOfn3HD8ZbWdMLgwn 0FJg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id j4si2140585qkg.224.2019.08.23.09.22.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Aug 2019 09:22:30 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 02357A35FE5; Fri, 23 Aug 2019 16:22:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D2ADA60623; Fri, 23 Aug 2019 16:22:28 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 97F5C18034E0; Fri, 23 Aug 2019 16:22:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7NGM8Jw006032 for ; Fri, 23 Aug 2019 12:22:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id CE80A60A9F; Fri, 23 Aug 2019 16:22:08 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.redhat.com (ovpn-122-169.rdu2.redhat.com [10.10.122.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5CA5660872; Fri, 23 Aug 2019 16:22:08 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Fri, 23 Aug 2019 12:21:52 -0400 Message-Id: <4d4c6ee46622dbfaf84cef5dfd2471111e9a5723.1566576129.git.crobinso@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [libvirt] [PATCH v2 08/16] qemu: restrict 'virgl=' option to non-vhostuser video type X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.68]); Fri, 23 Aug 2019 16:22:29 +0000 (UTC) From: Marc-André Lureau vhost-user device doesn't have a virgl option, it is passed to the vhost-user-gpu helper process instead. Signed-off-by: Marc-André Lureau Signed-off-by: Cole Robinson --- src/qemu/qemu_command.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 49652a8565..8bef103f68 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4683,9 +4683,11 @@ qemuBuildDeviceVideoStr(const virDomainDef *def, virBufferAsprintf(&buf, ",id=%s", video->info.alias); - if (video->accel && video->accel->accel3d == VIR_TRISTATE_SWITCH_ON) { - virBufferAsprintf(&buf, ",virgl=%s", - virTristateSwitchTypeToString(video->accel->accel3d)); + if (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO && !video->vhostuser) { + if (video->accel && video->accel->accel3d == VIR_TRISTATE_SWITCH_ON) { + virBufferAsprintf(&buf, ",virgl=%s", + virTristateSwitchTypeToString(video->accel->accel3d)); + } } if (video->type == VIR_DOMAIN_VIDEO_TYPE_QXL) { From patchwork Fri Aug 23 16:21:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 172122 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp886234ily; Fri, 23 Aug 2019 09:22:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpTIE206nvPfpYx1CvSkIciFf7FJowvYpSFE6DZNQUzOw+5zlXwt3n410U3cCA3kX1je2F X-Received: by 2002:a0c:8c8f:: with SMTP id p15mr4556972qvb.57.1566577359108; Fri, 23 Aug 2019 09:22:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566577359; cv=none; d=google.com; s=arc-20160816; b=nFQaMQSZIsKay7ug6gnxMMf10Jl2y5FGKW+TQJzMNVKIhqWoJy3Q+qcKSVnvcK42N6 GV46arQbqA1xnuN8ZfjeT76VqT0y7Hez22nLDFYDUq3oZhJUgdxhwtKTz2JxWI2mvtUa Xh/OUY4frQzm6q+5BUdzaasJxx2zOCjMlsM/TgL8uZ/sHR8VBPLWHDT4g7QphY+DZog7 CtsezwZASbSQnnpXTY4jnOO1trwnb1nlHe/mO0OPuolDSE0nQt7r3a4v2VHgWQnsSdJx ka6dNhQnnAHw5ZRSs5Ld3OUBY8Q3Bd60m9af9iphp4NJ3PdmZJ/pR9Xxg7J/f8kIvJog gspg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=zjgVAFOjv1nQTZqwVoT7tM/hAAiRIIDkR0tztELJA3M=; b=doaWQXPM6Qd3zbwaxsmNtAgup26Nvd6JCYEaKooSZJZna4Wgx5tV77gAa2gysAdbzJ lnUNWZ/+v+XfGA3tiYofeuq01K7N5MC7fVCnPMZSG/XEZa84fKz1v5rsSLItcqH2kg4H nvXZjYJuzJxqKNPZISGXKn59gNHtZVEMn/Fvd/tyTVKRSHPXnWi0LZsU0qf9YmCc/DFL J8J8O64jXB1O0221qQGOXSmCbhDqqgMejJieXphi5ECevTECl0ZAabDWlBiltBJflQgw d61iPrJIWEVfrfGOXeJBt7SHieIlDnyAWD6ekM6LWjYF0bQ2PH1lZBD2VoEMe0l87o0U 5+Cg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id m39si2272197qte.139.2019.08.23.09.22.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Aug 2019 09:22:39 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E4FEB898101; Fri, 23 Aug 2019 16:22:37 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C29A160872; Fri, 23 Aug 2019 16:22:37 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8863224C10; Fri, 23 Aug 2019 16:22:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7NGM9kC006042 for ; Fri, 23 Aug 2019 12:22:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8ACBB60606; Fri, 23 Aug 2019 16:22:09 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.redhat.com (ovpn-122-169.rdu2.redhat.com [10.10.122.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03D5C60872; Fri, 23 Aug 2019 16:22:08 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Fri, 23 Aug 2019 12:21:53 -0400 Message-Id: <0c6d743253400594ad567d4f255ff30a80c62c4e.1566576129.git.crobinso@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [libvirt] [PATCH v2 09/16] qemu: add vhost-user helpers X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.67]); Fri, 23 Aug 2019 16:22:38 +0000 (UTC) From: Marc-André Lureau Add qemuVhostUserFetchConfigs() to discover vhost-user helpers. qemuVhostUserFillDomainGPU() will find the first matching GPU helper with the required capabilities and set the associated vhost_user_binary. Signed-off-by: Marc-André Lureau Signed-off-by: Cole Robinson --- src/conf/device_conf.c | 1 + src/conf/device_conf.h | 1 + src/qemu/Makefile.inc.am | 2 + src/qemu/qemu_vhost_user.c | 394 ++++++++++++++++++ src/qemu/qemu_vhost_user.h | 48 +++ tests/Makefile.am | 9 + .../etc/qemu/vhost-user/40-gpu.json | 1 + .../etc/qemu/vhost-user/50-gpu.json | 0 .../qemu/vhost-user/test-vhost-user-gpu | 11 + .../usr/share/qemu/vhost-user/30-gpu.json | 1 + .../usr/share/qemu/vhost-user/50-gpu.json | 8 + .../usr/share/qemu/vhost-user/60-gpu.json | 1 + tests/qemuvhostusertest.c | 132 ++++++ 13 files changed, 609 insertions(+) create mode 100644 src/qemu/qemu_vhost_user.c create mode 100644 src/qemu/qemu_vhost_user.h create mode 120000 tests/qemuvhostuserdata/etc/qemu/vhost-user/40-gpu.json create mode 100644 tests/qemuvhostuserdata/etc/qemu/vhost-user/50-gpu.json create mode 100755 tests/qemuvhostuserdata/usr/libexec/qemu/vhost-user/test-vhost-user-gpu create mode 120000 tests/qemuvhostuserdata/usr/share/qemu/vhost-user/30-gpu.json create mode 100644 tests/qemuvhostuserdata/usr/share/qemu/vhost-user/50-gpu.json create mode 120000 tests/qemuvhostuserdata/usr/share/qemu/vhost-user/60-gpu.json create mode 100644 tests/qemuvhostusertest.c diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index 4c57f0995f..2f7077ddc4 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -96,6 +96,7 @@ virDomainDeviceInfoClear(virDomainDeviceInfoPtr info) VIR_FREE(info->loadparm); info->isolationGroup = 0; info->isolationGroupLocked = false; + VIR_FREE(info->vhost_user_binary); } void diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h index d0854925e3..0b0c525ad8 100644 --- a/src/conf/device_conf.h +++ b/src/conf/device_conf.h @@ -179,6 +179,7 @@ struct _virDomainDeviceInfo { * cases we might want to prevent that from happening by * locking the isolation group */ bool isolationGroupLocked; + char *vhost_user_binary; }; void virDomainDeviceInfoClear(virDomainDeviceInfoPtr info); diff --git a/src/qemu/Makefile.inc.am b/src/qemu/Makefile.inc.am index f7a0fa4a84..18a9220d01 100644 --- a/src/qemu/Makefile.inc.am +++ b/src/qemu/Makefile.inc.am @@ -60,6 +60,8 @@ QEMU_DRIVER_SOURCES = \ qemu/qemu_qapi.h \ qemu/qemu_tpm.c \ qemu/qemu_tpm.h \ + qemu/qemu_vhost_user.c \ + qemu/qemu_vhost_user.h \ $(NULL) diff --git a/src/qemu/qemu_vhost_user.c b/src/qemu/qemu_vhost_user.c new file mode 100644 index 0000000000..7a97052ab9 --- /dev/null +++ b/src/qemu/qemu_vhost_user.c @@ -0,0 +1,394 @@ +/* + * qemu_vhost_user.c: QEMU vhost-user + * + * Copyright (C) 2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "qemu_vhost_user.h" +#include "qemu_configs.h" +#include "virjson.h" +#include "virlog.h" +#include "virstring.h" +#include "viralloc.h" +#include "virenum.h" + +#define VIR_FROM_THIS VIR_FROM_QEMU + +VIR_LOG_INIT("qemu.qemu_vhost_user"); + +typedef enum { + QEMU_VHOST_USER_TYPE_NONE = 0, + QEMU_VHOST_USER_TYPE_9P, + QEMU_VHOST_USER_TYPE_BALLOON, + QEMU_VHOST_USER_TYPE_BLOCK, + QEMU_VHOST_USER_TYPE_CAIF, + QEMU_VHOST_USER_TYPE_CONSOLE, + QEMU_VHOST_USER_TYPE_CRYPTO, + QEMU_VHOST_USER_TYPE_GPU, + QEMU_VHOST_USER_TYPE_INPUT, + QEMU_VHOST_USER_TYPE_NET, + QEMU_VHOST_USER_TYPE_RNG, + QEMU_VHOST_USER_TYPE_RPMSG, + QEMU_VHOST_USER_TYPE_RPROC_SERIAL, + QEMU_VHOST_USER_TYPE_SCSI, + QEMU_VHOST_USER_TYPE_VSOCK, + + QEMU_VHOST_USER_TYPE_LAST +} qemuVhostUserType; + +VIR_ENUM_DECL(qemuVhostUserType); +VIR_ENUM_IMPL(qemuVhostUserType, + QEMU_VHOST_USER_TYPE_LAST, + "", + "9p", + "balloon", + "block", + "caif", + "console", + "crypto", + "gpu", + "input", + "net", + "rng", + "rpmsg", + "rproc-serial", + "scsi", + "vsock", +); + +typedef enum { + QEMU_VHOST_USER_GPU_FEATURE_NONE = 0, + QEMU_VHOST_USER_GPU_FEATURE_VIRGL, + QEMU_VHOST_USER_GPU_FEATURE_RENDER_NODE, + + QEMU_VHOST_USER_GPU_FEATURE_LAST +} qemuVhostUserGPUFeature; + +VIR_ENUM_DECL(qemuVhostUserGPUFeature); +VIR_ENUM_IMPL(qemuVhostUserGPUFeature, + QEMU_VHOST_USER_GPU_FEATURE_LAST, + "", + "virgl", + "render-node", +); + +typedef struct _qemuVhostUserGPU qemuVhostUserGPU; +typedef qemuVhostUserGPU *qemuVhostUserGPUPtr; +struct _qemuVhostUserGPU { + size_t nfeatures; + qemuVhostUserGPUFeature *features; +}; + +struct _qemuVhostUser { + /* Description intentionally not parsed. */ + qemuVhostUserType type; + char *binary; + /* Tags intentionally not parsed. */ + + union { + qemuVhostUserGPU gpu; + } capabilities; +}; + +static void +qemuVhostUserGPUFeatureFree(qemuVhostUserGPUFeature *features) +{ + VIR_FREE(features); +} + + +VIR_DEFINE_AUTOPTR_FUNC(qemuVhostUserGPUFeature, qemuVhostUserGPUFeatureFree); + +void +qemuVhostUserFree(qemuVhostUserPtr vu) +{ + if (!vu) + return; + + if (vu->type == QEMU_VHOST_USER_TYPE_GPU) + VIR_FREE(vu->capabilities.gpu.features); + + VIR_FREE(vu->binary); + + VIR_FREE(vu); +} + +/* 1MiB should be enough for everybody (TM) */ +#define DOCUMENT_SIZE (1024 * 1024) + +static int +qemuVhostUserTypeParse(const char *path, + virJSONValuePtr doc, + qemuVhostUserPtr vu) +{ + const char *type = virJSONValueObjectGetString(doc, "type"); + int tmp; + + VIR_DEBUG("vhost-user description path '%s' type : %s", + path, type); + + if ((tmp = qemuVhostUserTypeTypeFromString(type)) <= 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unknown vhost-user type: '%s'"), + type); + return -1; + } + + vu->type = tmp; + + return 0; +} + +static int +qemuVhostUserBinaryParse(const char *path, + virJSONValuePtr doc, + qemuVhostUserPtr vu) +{ + const char *binary = virJSONValueObjectGetString(doc, "binary"); + + VIR_DEBUG("vhost-user description path '%s' binary : %s", + path, binary); + + if (VIR_STRDUP(vu->binary, binary) < 0) + return -1; + + return 0; +} + +qemuVhostUserPtr +qemuVhostUserParse(const char *path) +{ + VIR_AUTOFREE(char *) cont = NULL; + VIR_AUTOPTR(virJSONValue) doc = NULL; + VIR_AUTOPTR(qemuVhostUser) vu = NULL; + qemuVhostUserPtr ret = NULL; + + if (virFileReadAll(path, DOCUMENT_SIZE, &cont) < 0) + return NULL; + + if (!(doc = virJSONValueFromString(cont))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unable to parse json file '%s'"), + path); + return NULL; + } + + if (VIR_ALLOC(vu) < 0) + return NULL; + + if (qemuVhostUserTypeParse(path, doc, vu) < 0) + return NULL; + + if (qemuVhostUserBinaryParse(path, doc, vu) < 0) + return NULL; + + VIR_STEAL_PTR(ret, vu); + return ret; +} + +char * +qemuVhostUserFormat(qemuVhostUserPtr vu) +{ + VIR_AUTOPTR(virJSONValue) doc = NULL; + + if (!vu) + return NULL; + + if (!(doc = virJSONValueNewObject())) + return NULL; + + if (virJSONValueObjectAppendString(doc, "type", + qemuVhostUserTypeTypeToString(vu->type)) < 0) + return NULL; + + if (virJSONValueObjectAppendString(doc, "binary", vu->binary) < 0) + return NULL; + + return virJSONValueToString(doc, true); +} + +int +qemuVhostUserFetchConfigs(char ***configs, + bool privileged) +{ + return qemuFetchConfigs("vhost-user", configs, privileged); +} + +static ssize_t +qemuVhostUserFetchParsedConfigs(bool privileged, + qemuVhostUserPtr **vhostuserRet, + char ***pathsRet) +{ + VIR_AUTOSTRINGLIST paths = NULL; + size_t npaths; + qemuVhostUserPtr *vus = NULL; + size_t i; + + if (qemuVhostUserFetchConfigs(&paths, privileged) < 0) + return -1; + + npaths = virStringListLength((const char **)paths); + + if (VIR_ALLOC_N(vus, npaths) < 0) + return -1; + + for (i = 0; i < npaths; i++) { + if (!(vus[i] = qemuVhostUserParse(paths[i]))) + goto error; + } + + VIR_STEAL_PTR(*vhostuserRet, vus); + if (pathsRet) + VIR_STEAL_PTR(*pathsRet, paths); + return npaths; + + error: + while (i > 0) + qemuVhostUserFree(vus[--i]); + VIR_FREE(vus); + return -1; +} + + +static int +qemuVhostUserGPUFillCapabilities(qemuVhostUserPtr vu, + virJSONValuePtr doc) +{ + qemuVhostUserGPUPtr gpu = &vu->capabilities.gpu; + virJSONValuePtr featuresJSON; + size_t nfeatures; + size_t i; + VIR_AUTOPTR(qemuVhostUserGPUFeature) features = NULL; + + if (!(featuresJSON = virJSONValueObjectGetArray(doc, "features"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to get features from '%s'"), + vu->binary); + return -1; + } + + nfeatures = virJSONValueArraySize(featuresJSON); + if (VIR_ALLOC_N(features, nfeatures) < 0) + return -1; + + for (i = 0; i < nfeatures; i++) { + virJSONValuePtr item = virJSONValueArrayGet(featuresJSON, i); + const char *tmpStr = virJSONValueGetString(item); + int tmp; + + if ((tmp = qemuVhostUserGPUFeatureTypeFromString(tmpStr)) <= 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unknown feature %s"), + tmpStr); + continue; + } + + features[i] = tmp; + } + + VIR_STEAL_PTR(gpu->features, features); + gpu->nfeatures = nfeatures; + + return 0; +} + + +static bool +qemuVhostUserGPUHasFeature(qemuVhostUserGPUPtr gpu, + qemuVhostUserGPUFeature feature) +{ + size_t i; + + for (i = 0; i < gpu->nfeatures; i++) { + if (gpu->features[i] == feature) + return true; + } + + return false; +} + + +int +qemuVhostUserFillDomainGPU(virQEMUDriverPtr driver, + virDomainVideoDefPtr video) +{ + qemuVhostUserPtr *vus = NULL; + ssize_t nvus = 0; + ssize_t i; + int ret = -1; + + if ((nvus = qemuVhostUserFetchParsedConfigs(driver->privileged, + &vus, NULL)) < 0) + goto end; + + for (i = 0; i < nvus; i++) { + qemuVhostUserPtr vu = vus[i]; + VIR_AUTOPTR(virJSONValue) doc = NULL; + VIR_AUTOFREE(char *) output = NULL; + VIR_AUTOPTR(virCommand) cmd = NULL; + + if (vu->type != QEMU_VHOST_USER_TYPE_GPU) + continue; + + cmd = virCommandNewArgList(vu->binary, "--print-capabilities", NULL); + virCommandSetOutputBuffer(cmd, &output); + if (virCommandRun(cmd, NULL) < 0) + continue; + + if (!(doc = virJSONValueFromString(output))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unable to parse json capabilities '%s'"), + vu->binary); + continue; + } + + if (qemuVhostUserGPUFillCapabilities(vu, doc) < 0) + continue; + + if (video->accel) { + if (video->accel->accel3d && + !qemuVhostUserGPUHasFeature(&vu->capabilities.gpu, + QEMU_VHOST_USER_GPU_FEATURE_VIRGL)) + continue; + + if (video->accel->rendernode && + !qemuVhostUserGPUHasFeature(&vu->capabilities.gpu, + QEMU_VHOST_USER_GPU_FEATURE_RENDER_NODE)) + continue; + } + + VIR_FREE(video->info.vhost_user_binary); + if (VIR_STRDUP(video->info.vhost_user_binary, vu->binary) < 0) + goto end; + + ret = 0; + break; + } + + if (i == nvus) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("Unable to find a satisfying vhost-user-gpu")); + } + + end: + for (i = 0; i < nvus; i++) + qemuVhostUserFree(vus[i]); + VIR_FREE(vus); + return ret; +} diff --git a/src/qemu/qemu_vhost_user.h b/src/qemu/qemu_vhost_user.h new file mode 100644 index 0000000000..76701dd1fa --- /dev/null +++ b/src/qemu/qemu_vhost_user.h @@ -0,0 +1,48 @@ +/* + * qemu_vhost_user.h: QEMU vhost-user + * + * Copyright (C) 2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#pragma once + +#include "domain_conf.h" +#include "qemu_conf.h" +#include "virautoclean.h" +#include "virarch.h" + +typedef struct _qemuVhostUser qemuVhostUser; +typedef qemuVhostUser *qemuVhostUserPtr; + +void +qemuVhostUserFree(qemuVhostUserPtr fw); + +VIR_DEFINE_AUTOPTR_FUNC(qemuVhostUser, qemuVhostUserFree); + +qemuVhostUserPtr +qemuVhostUserParse(const char *path); + +char * +qemuVhostUserFormat(qemuVhostUserPtr fw); + +int +qemuVhostUserFetchConfigs(char ***configs, + bool privileged); + +int +qemuVhostUserFillDomainGPU(virQEMUDriverPtr driver, + virDomainVideoDefPtr video); diff --git a/tests/Makefile.am b/tests/Makefile.am index f92710db43..4f4a5236ea 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -290,6 +290,7 @@ test_programs += qemuxml2argvtest qemuxml2xmltest \ qemumigparamstest \ qemusecuritytest \ qemufirmwaretest \ + qemuvhostusertest \ $(NULL) test_helpers += qemucapsprobe test_libraries += libqemumonitortestutils.la \ @@ -692,6 +693,13 @@ qemufirmwaretest_SOURCES = \ $(NULL) qemufirmwaretest_LDADD = $(qemu_LDADDS) +qemuvhostusertest_SOURCES = \ + qemuvhostusertest.c \ + testutils.h testutils.c \ + virfilewrapper.c virfilewrapper.h \ + $(NULL) +qemuvhostusertest_LDADD = $(qemu_LDADDS) + else ! WITH_QEMU EXTRA_DIST += qemuxml2argvtest.c qemuxml2xmltest.c \ qemudomaincheckpointxml2xmltest.c qemudomainsnapshotxml2xmltest.c \ @@ -706,6 +714,7 @@ EXTRA_DIST += qemuxml2argvtest.c qemuxml2xmltest.c \ qemusecuritytest.c qemusecuritytest.h \ qemusecuritymock.c \ qemufirmwaretest.c \ + qemuvhostusertest.c \ $(QEMUMONITORTESTUTILS_SOURCES) endif ! WITH_QEMU diff --git a/tests/qemuvhostuserdata/etc/qemu/vhost-user/40-gpu.json b/tests/qemuvhostuserdata/etc/qemu/vhost-user/40-gpu.json new file mode 120000 index 0000000000..aa93864aa7 --- /dev/null +++ b/tests/qemuvhostuserdata/etc/qemu/vhost-user/40-gpu.json @@ -0,0 +1 @@ +../../../usr/share/qemu/vhost-user/50-gpu.json \ No newline at end of file diff --git a/tests/qemuvhostuserdata/etc/qemu/vhost-user/50-gpu.json b/tests/qemuvhostuserdata/etc/qemu/vhost-user/50-gpu.json new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qemuvhostuserdata/usr/libexec/qemu/vhost-user/test-vhost-user-gpu b/tests/qemuvhostuserdata/usr/libexec/qemu/vhost-user/test-vhost-user-gpu new file mode 100755 index 0000000000..a2c2ee0713 --- /dev/null +++ b/tests/qemuvhostuserdata/usr/libexec/qemu/vhost-user/test-vhost-user-gpu @@ -0,0 +1,11 @@ +#!/bin/sh + +cat < + +#include + +#include "testutils.h" +#include "virfilewrapper.h" +#include "qemu/qemu_vhost_user.h" +#include "configmake.h" + +#define VIR_FROM_THIS VIR_FROM_QEMU + +/* A very basic test. Parse given JSON vhostuser description into + * an internal structure, format it back and compare with the + * contents of the file (minus some keys that are not parsed). + */ +static int +testParseFormatVU(const void *opaque) +{ + const char *filename = opaque; + VIR_AUTOFREE(char *) path = NULL; + VIR_AUTOPTR(qemuVhostUser) vu = NULL; + VIR_AUTOFREE(char *) buf = NULL; + VIR_AUTOPTR(virJSONValue) json = NULL; + VIR_AUTOFREE(char *) expected = NULL; + VIR_AUTOFREE(char *) actual = NULL; + + if (virAsprintf(&path, "%s/qemuvhostuserdata/%s", + abs_srcdir, filename) < 0) + return -1; + + if (!(vu = qemuVhostUserParse(path))) + return -1; + + if (virFileReadAll(path, + 1024 * 1024, /* 1MiB */ + &buf) < 0) + return -1; + + if (!(json = virJSONValueFromString(buf))) + return -1; + + /* Description and tags are not parsed. */ + if (virJSONValueObjectRemoveKey(json, "description", NULL) < 0 || + virJSONValueObjectRemoveKey(json, "tags", NULL) < 0) + return -1; + + if (!(expected = virJSONValueToString(json, true))) + return -1; + + if (!(actual = qemuVhostUserFormat(vu))) + return -1; + + return virTestCompareToString(expected, actual); +} + + +static int +testVUPrecedence(const void *opaque ATTRIBUTE_UNUSED) +{ + VIR_AUTOFREE(char *) fakehome = NULL; + VIR_AUTOSTRINGLIST vuList = NULL; + size_t nvuList; + size_t i; + const char *expected[] = { + PREFIX "/share/qemu/vhost-user/30-gpu.json", + SYSCONFDIR "/qemu/vhost-user/40-gpu.json", + PREFIX "/share/qemu/vhost-user/60-gpu.json", + }; + const size_t nexpected = ARRAY_CARDINALITY(expected); + + if (VIR_STRDUP(fakehome, abs_srcdir "/qemuvhostuserdata/home/user/.config") < 0) + return -1; + + setenv("XDG_CONFIG_HOME", fakehome, 1); + + if (qemuVhostUserFetchConfigs(&vuList, false) < 0) + return -1; + + if (!vuList) { + fprintf(stderr, "Expected a non-NULL result, but got a NULL result\n"); + return -1; + } + + nvuList = virStringListLength((const char **)vuList); + + for (i = 0; i < MAX(nvuList, nexpected); i++) { + const char *e = i < nexpected ? expected[i] : NULL; + const char *f = i < nvuList ? vuList[i] : NULL; + + if (STRNEQ_NULLABLE(e, f)) { + fprintf(stderr, + "Unexpected path (i=%zu). Expected %s got %s \n", + i, NULLSTR(e), NULLSTR(f)); + return -1; + } + } + + return 0; +} + + +static int +mymain(void) +{ + int ret = 0; + + virFileWrapperAddPrefix(SYSCONFDIR "/qemu/vhost-user", + abs_srcdir "/qemuvhostuserdata/etc/qemu/vhost-user"); + virFileWrapperAddPrefix(PREFIX "/share/qemu/vhost-user", + abs_srcdir "/qemuvhostuserdata/usr/share/qemu/vhost-user"); + virFileWrapperAddPrefix("/home/user/.config/qemu/vhost-user", + abs_srcdir "/qemuvhostuserdata/home/user/.config/qemu/vhost-user"); + +#define DO_PARSE_TEST(filename) \ + do { \ + if (virTestRun("QEMU vhost-user " filename, \ + testParseFormatVU, filename) < 0) \ + ret = -1; \ + } while (0) + + DO_PARSE_TEST("usr/share/qemu/vhost-user/50-gpu.json"); + + if (virTestRun("QEMU vhost-user precedence test", testVUPrecedence, NULL) < 0) + ret = -1; + + virFileWrapperClearPrefixes(); + + return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + + +VIR_TEST_MAIN(mymain) From patchwork Fri Aug 23 16:21:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 172118 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp886118ily; Fri, 23 Aug 2019 09:22:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqzxaOFNrHhKm4Rl/nO2w5sgIZMg709EA55vnzBA+WbSuYencFi5G2hSkqh52J+P2H6znxxL X-Received: by 2002:a05:6214:11b3:: with SMTP id u19mr4691010qvv.46.1566577353639; Fri, 23 Aug 2019 09:22:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566577353; cv=none; d=google.com; s=arc-20160816; b=NWQ+C5w8kMj1XRcaeAN7u04uY7iqqTusyj2E42pRrdtDI/ap0KROswbnoSRxUxWi0c OAf2om5Pn7xIIe9fXkQDc9ttB0ZUq31fzAsYFSnYFMLhEBVd/bSW/dV3IvrnEiejjYdC HVecxeESp76DvrxlTdMjHV1MetNpuneYG/qiJRQt5magu6/UvqSkwdXOLeK+tpiOEskT KgdT4QjSxeT67Ei86A6CZrJ9PgYSO7Zv7xJGxXZuzZ96WTztjN7zfHlOJevev4wPVtAZ ph2BDBDqm4rLg0TG+9SN/q99T8hUisyQV9If1TpT7jbtTDzFKkj/U8xmuQjYxj73Q0n/ /TdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=hzpVpgOP76dE6UcEe4UsIQepP48OHBmVWtJrHIc1M18=; b=P8+Iyn3KEW7LXrcLM865+nYcsUIy1FYaYMka4NZeJxYMuKtCmIv6fCcUdsSaJIdMy1 HQWg6UWFLS/HKTbUMkA+cYCy3HGlC3lG+w8xFSYFXQVJ+kTU2lQRKo7KCtVn0w2mQ13K 1Ziiev0uI42dfeAxeyAz4w2BJUbsymIpNv+FYxLzUYmpBg8xSUumKCEIJWDRBKVZYDQp JrxpLS7r/pREDl0W8XvweR9NTb7/JeojiMcQSA+VEBC59QwMwcmssUOZ0gRSqaW5Qb9W B944hYEU21Lf48FFIKPN0Z3tMBSGfYsOvr/mYTERFsPBr7NUaJGD44P5xvQzQNEh32fE YC9g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id h1si2107086qkg.311.2019.08.23.09.22.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Aug 2019 09:22:33 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 324D0335C1; Fri, 23 Aug 2019 16:22:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0BEBA1001B35; Fri, 23 Aug 2019 16:22:32 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C974124F37; Fri, 23 Aug 2019 16:22:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7NGMA8q006048 for ; Fri, 23 Aug 2019 12:22:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 339BE60605; Fri, 23 Aug 2019 16:22:10 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.redhat.com (ovpn-122-169.rdu2.redhat.com [10.10.122.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5DAE60872; Fri, 23 Aug 2019 16:22:09 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Fri, 23 Aug 2019 12:21:54 -0400 Message-Id: <0d43c27193a39be9ef207e8b7f476d30e883e53c.1566576129.git.crobinso@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [libvirt] [PATCH v2 10/16] qemu: add qemuSecurityStartVhostUserGPU helper X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 23 Aug 2019 16:22:32 +0000 (UTC) From: Marc-André Lureau See function documentation. Used in a following patch. Signed-off-by: Marc-André Lureau Signed-off-by: Cole Robinson --- src/qemu/qemu_security.c | 47 ++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_security.h | 6 +++++ 2 files changed, 53 insertions(+) diff --git a/src/qemu/qemu_security.c b/src/qemu/qemu_security.c index 3cd6d9bd3d..86b06594f6 100644 --- a/src/qemu/qemu_security.c +++ b/src/qemu/qemu_security.c @@ -433,6 +433,53 @@ qemuSecurityRestoreChardevLabel(virQEMUDriverPtr driver, } +/* + * qemuSecurityStartVhostUserGPU: + * + * @driver: the QEMU driver + * @vm: the domain object + * @cmd: the command to run + * @existstatus: pointer to int returning exit status of process + * @cmdret: pointer to int returning result of virCommandRun + * + * Start the vhost-user-gpu process with approriate labels. + * This function returns -1 on security setup error, 0 if all the + * setup was done properly. In case the virCommand failed to run + * 0 is returned but cmdret is set appropriately with the process + * exitstatus also set. + */ +int +qemuSecurityStartVhostUserGPU(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virCommandPtr cmd, + int *exitstatus, + int *cmdret) +{ + int ret = -1; + + if (virSecurityManagerSetChildProcessLabel(driver->securityManager, + vm->def, cmd) < 0) + goto cleanup; + + if (virSecurityManagerPreFork(driver->securityManager) < 0) + goto cleanup; + + ret = 0; + + *cmdret = virCommandRun(cmd, exitstatus); + + virSecurityManagerPostFork(driver->securityManager); + + if (*cmdret < 0) + goto cleanup; + + return 0; + + cleanup: + return ret; +} + + /* * qemuSecurityStartTPMEmulator: * diff --git a/src/qemu/qemu_security.h b/src/qemu/qemu_security.h index 68e377f418..a48ed8ec78 100644 --- a/src/qemu/qemu_security.h +++ b/src/qemu/qemu_security.h @@ -77,6 +77,12 @@ int qemuSecurityRestoreChardevLabel(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainChrDefPtr chr); +int qemuSecurityStartVhostUserGPU(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virCommandPtr cmd, + int *exitstatus, + int *cmdret); + int qemuSecurityStartTPMEmulator(virQEMUDriverPtr driver, virDomainObjPtr vm, virCommandPtr cmd, From patchwork Fri Aug 23 16:21:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 172121 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp886200ily; Fri, 23 Aug 2019 09:22:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqz4wTSCNfssMdxH/PHHCUUtnMz18grJTYH5U7xZ8wTinloaQEwWto8RTv+VNeZRbKpgX2+R X-Received: by 2002:ac8:7552:: with SMTP id b18mr5561096qtr.235.1566577357866; Fri, 23 Aug 2019 09:22:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566577357; cv=none; d=google.com; s=arc-20160816; b=bAQ65IlRDCIkPm+G502W/JOFr5Wd5k1CPt+8blCkxIF8pJZCpz9wY6g46/AP1+j9NF 02FLy5Owa6CnTjMSrzPlKVjr0BP1H6b8iIA6QkOknBYAepsDcArToagQr1LoeLqxKD0M xOsPNH6QPrMynoVv8rkQvTY9RQlhyCEf0wFtF1EaLeAocOmlE+snVC32jjdhcrgtAlNj 6Mu5A1ptVbPBv0U2sfmxSVUl10397wkqMbLl/7pW+obOlAob3ie/lDSMus3VmyluuUzx Yhcib74foNJCmJdvhi//Ku6fm9/Nymyb+oksjaeRXJSf9M9FsKwWzN0w8Qxa06Xeos3x yZ0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=szTQEPzxbYBLOl+FNcB6bKGpHpUn8fGcvb2Tj99QtpA=; b=ZyBaCswDpORCy9+UGfm0XIcvc1Yuz5twochueX4AjN5jt8EbXQ2mNuyhoc9fsh/OvC F/XLYGKCos2fZY0iYq6EGaE6TaE+q5oWyLiOwlX5j7izLGloUS0EcssNtiH5M1LOVEB0 yqCIXlPdOWgErTcx+bve1pE0UKAIX3D/yGK2hdEphyfw0vsuhBv6EXXl+TRA4Bq1fHzg ylrLO9NXo8SipVV0omvnhlLs21U4DXSmo4Npdo0Qsk4Ua+J/Q2TEXmuakcdPFi32fC+z pF/XuDoFUuyCubrRlGul5fEwWcBgAl5bTBVV2R82JTgPhDFQ36jtyLxLQEiEdOYDFu+S bysQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id b78si2120001qkg.21.2019.08.23.09.22.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Aug 2019 09:22:37 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7CF763B71F; Fri, 23 Aug 2019 16:22:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 582C2BA8A; Fri, 23 Aug 2019 16:22:36 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1C57A180BA9C; Fri, 23 Aug 2019 16:22:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7NGMAXR006056 for ; Fri, 23 Aug 2019 12:22:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id D061160A9F; Fri, 23 Aug 2019 16:22:10 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.redhat.com (ovpn-122-169.rdu2.redhat.com [10.10.122.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C87060872; Fri, 23 Aug 2019 16:22:10 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Fri, 23 Aug 2019 12:21:55 -0400 Message-Id: <556480400e3d312cc3310fe27d04253d4d98f024.1566576129.git.crobinso@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [libvirt] [PATCH v2 11/16] qemu: add vhost-user-gpu helper unit X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 23 Aug 2019 16:22:36 +0000 (UTC) From: Marc-André Lureau Similar to the qemu_tpm.c, add a unit with a few functions to start/stop and setup the cgroup of the external vhost-user-gpu process. See function documentation. Since the vhost-user connection fd isn't necessarily specific to QEMU, it was easier to add it to virDomainDeviceInfo, although a reasonable place could be qemuDomainObjPrivate (with an associate hashtable device-info -> qemu-device-info for example). Signed-off-by: Marc-André Lureau Signed-off-by: Cole Robinson --- src/conf/device_conf.h | 1 + src/qemu/Makefile.inc.am | 2 + src/qemu/qemu_vhost_user_gpu.c | 305 +++++++++++++++++++++++++++++++++ src/qemu/qemu_vhost_user_gpu.h | 50 ++++++ 4 files changed, 358 insertions(+) create mode 100644 src/qemu/qemu_vhost_user_gpu.c create mode 100644 src/qemu/qemu_vhost_user_gpu.h diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h index 0b0c525ad8..23cc2e9ba6 100644 --- a/src/conf/device_conf.h +++ b/src/conf/device_conf.h @@ -180,6 +180,7 @@ struct _virDomainDeviceInfo { * locking the isolation group */ bool isolationGroupLocked; char *vhost_user_binary; + int vhost_user_fd; }; void virDomainDeviceInfoClear(virDomainDeviceInfoPtr info); diff --git a/src/qemu/Makefile.inc.am b/src/qemu/Makefile.inc.am index 18a9220d01..d394eab957 100644 --- a/src/qemu/Makefile.inc.am +++ b/src/qemu/Makefile.inc.am @@ -62,6 +62,8 @@ QEMU_DRIVER_SOURCES = \ qemu/qemu_tpm.h \ qemu/qemu_vhost_user.c \ qemu/qemu_vhost_user.h \ + qemu/qemu_vhost_user_gpu.c \ + qemu/qemu_vhost_user_gpu.h \ $(NULL) diff --git a/src/qemu/qemu_vhost_user_gpu.c b/src/qemu/qemu_vhost_user_gpu.c new file mode 100644 index 0000000000..0735af1473 --- /dev/null +++ b/src/qemu/qemu_vhost_user_gpu.c @@ -0,0 +1,305 @@ +/* + * qemu_vhost_user_gpu.c: QEMU vhost-user GPU support + * + * Copyright (C) 2018 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "qemu_vhost_user_gpu.h" +#include "qemu_vhost_user.h" +#include "qemu_extdevice.h" + +#include "conf/domain_conf.h" +#include "configmake.h" +#include "vircommand.h" +#include "viralloc.h" +#include "virlog.h" +#include "virutil.h" +#include "virfile.h" +#include "virstring.h" +#include "virtime.h" +#include "virpidfile.h" + +#define VIR_FROM_THIS VIR_FROM_NONE + +VIR_LOG_INIT("qemu.vhost-user-gpu"); + + +static char * +qemuVhostUserGPUCreatePidFilename(const char *stateDir, + const char *shortName, + const char *alias) +{ + char *pidfile = NULL; + char *devicename = NULL; + + if (virAsprintf(&devicename, "%s-%s-vhost-user-gpu", shortName, alias) < 0) + return NULL; + + pidfile = virPidFileBuildPath(stateDir, devicename); + + VIR_FREE(devicename); + + return pidfile; +} + + +/* + * qemuVhostUserGPUGetPid: + * @binpath: path of executable associated with the pidfile + * @stateDir: the directory where vhost-user-gpu writes the pidfile into + * @shortName: short name of the domain + * @alias: video device alias + * @pid: pointer to pid + * + * Return -errno upon error, or zero on successful reading of the pidfile. + * If the PID was not still alive, zero will be returned, and @pid will be + * set to -1; + */ +static int +qemuVhostUserGPUGetPid(const char *binPath, + const char *stateDir, + const char *shortName, + const char *alias, + pid_t *pid) +{ + int ret; + char *pidfile = qemuVhostUserGPUCreatePidFilename(stateDir, shortName, alias); + if (!pidfile) + return -ENOMEM; + + ret = virPidFileReadPathIfAlive(pidfile, pid, binPath); + + VIR_FREE(pidfile); + + return ret; +} + + +int qemuExtVhostUserGPUPrepareDomain(virQEMUDriverPtr driver, + virDomainVideoDefPtr video) +{ + return qemuVhostUserFillDomainGPU(driver, video); +} + + +/* + * qemuExtVhostUserGPUStart: + * @driver: QEMU driver + * @vm: the VM domain + * @video: the video device + * @logCtxt: log context + * + * Start the external vhost-user-gpu process: + * - open a socketpair for vhost-user communication + * - have the command line built + * - start the external process and sync with it before QEMU start + */ +int qemuExtVhostUserGPUStart(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainVideoDefPtr video, + qemuDomainLogContextPtr logCtxt) +{ + int ret = -1; + virCommandPtr cmd = NULL; + int exitstatus = 0; + char *errbuf = NULL; + virQEMUDriverConfigPtr cfg; + char *pidfile = NULL, *shortName = virDomainDefGetShortName(vm->def); + virTimeBackOffVar timebackoff; + const unsigned long long timeout = 500 * 1000; /* ms */ + int cmdret = 0, rc; + int pair[2] = { -1, -1 }; + + pid_t pid; + + if (!shortName) + return -1; + + cfg = virQEMUDriverGetConfig(driver); + + /* stop any left-over for this VM */ + qemuExtVhostUserGPUStop(driver, vm, video); + + if (!(pidfile = qemuVhostUserGPUCreatePidFilename( + cfg->stateDir, shortName, video->info.alias))) + goto error; + + if (qemuSecuritySetSocketLabel(driver->securityManager, vm->def) < 0) + goto cleanup; + + if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) < 0) { + virReportSystemError(errno, "%s", _("failed to create socket")); + goto error; + } + + if (qemuSecurityClearSocketLabel(driver->securityManager, vm->def) < 0) + goto cleanup; + + cmd = virCommandNew(video->info.vhost_user_binary); + if (!cmd) + goto error; + + virCommandClearCaps(cmd); + virCommandSetPidFile(cmd, pidfile); + virCommandDaemonize(cmd); + + if (qemuExtDeviceLogCommand(logCtxt, cmd, "vhost-user-gpu") < 0) + goto error; + + virCommandAddArgFormat(cmd, "--fd=%d", pair[0]); + virCommandPassFD(cmd, pair[0], VIR_COMMAND_PASS_FD_CLOSE_PARENT); + pair[0] = -1; + + if (video->accel) { + if (video->accel->accel3d) + virCommandAddArg(cmd, "--virgl"); + + if (video->accel->rendernode) + virCommandAddArgFormat(cmd, "--render-node=%s", video->accel->rendernode); + } + if (qemuSecurityStartVhostUserGPU(driver, vm, cmd, + &exitstatus, &cmdret) < 0) + goto error; + + if (cmdret < 0 || exitstatus != 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not start 'vhost-user-gpu'. exitstatus: %d, " + "error: %s"), exitstatus, errbuf); + goto cleanup; + } + + /* check that the helper has written its pid into the file */ + if (virTimeBackOffStart(&timebackoff, 1, timeout) < 0) + goto error; + while (virTimeBackOffWait(&timebackoff)) { + rc = qemuVhostUserGPUGetPid(video->info.vhost_user_binary, + cfg->stateDir, shortName, video->info.alias, &pid); + if (rc < 0) + continue; + if (rc == 0 && pid == (pid_t)-1) + goto error; + break; + } + + ret = 0; + video->info.vhost_user_fd = pair[1]; + pair[1] = -1; + + cleanup: + VIR_FORCE_CLOSE(pair[0]); + VIR_FORCE_CLOSE(pair[1]); + virObjectUnref(cfg); + VIR_FREE(pidfile); + virCommandFree(cmd); + + return ret; + + error: + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("vhost-user-gpu failed to start")); + goto cleanup; +} + + +/* + * qemuExtVhostUserGPUStop: + * + * @driver: QEMU driver + * @vm: the VM domain + * @video: the video device + * + * Check if vhost-user process pidfile is around, kill the process, + * and remove the pidfile. + */ +void qemuExtVhostUserGPUStop(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainVideoDefPtr video) +{ + virErrorPtr orig_err; + char *pidfile, *shortName = virDomainDefGetShortName(vm->def); + virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); + + if (!(pidfile = qemuVhostUserGPUCreatePidFilename( + cfg->stateDir, shortName, video->info.alias))) { + VIR_WARN("Unable to construct vhost-user-gpu pidfile path"); + return; + } + + virErrorPreserveLast(&orig_err); + if (virPidFileForceCleanupPath(pidfile) < 0) { + VIR_WARN("Unable to kill vhost-user-gpu process"); + } else { + if (unlink(pidfile) < 0 && + errno != ENOENT) { + virReportSystemError(errno, + _("Unable to remove stale pidfile %s"), + pidfile); + } + } + virErrorRestore(&orig_err); + + VIR_FREE(pidfile); +} + + +/* + * qemuExtVhostUserGPUSetupCgroup: + * + * @driver: QEMU driver + * @def: domain definition + * @video: the video device + * @cgroupe: a cgroup + * + * Add the vhost-user-gpu PID to the given cgroup. + */ +int +qemuExtVhostUserGPUSetupCgroup(virQEMUDriverPtr driver, + virDomainDefPtr def, + virDomainVideoDefPtr video, + virCgroupPtr cgroup) +{ + virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); + char *pidfile = NULL; + char *shortName = NULL; + int ret = -1, rc; + pid_t pid; + + shortName = virDomainDefGetShortName(def); + if (!shortName) + goto cleanup; + + rc = qemuVhostUserGPUGetPid(video->info.vhost_user_binary, + cfg->stateDir, shortName, video->info.alias, &pid); + if (rc < 0 || (rc == 0 && pid == (pid_t)-1)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not get process id of vhost-user-gpu")); + goto cleanup; + } + if (virCgroupAddProcess(cgroup, pid) < 0) + goto cleanup; + + ret = 0; + + cleanup: + VIR_FREE(pidfile); + VIR_FREE(shortName); + virObjectUnref(cfg); + + return ret; +} diff --git a/src/qemu/qemu_vhost_user_gpu.h b/src/qemu/qemu_vhost_user_gpu.h new file mode 100644 index 0000000000..85054894fd --- /dev/null +++ b/src/qemu/qemu_vhost_user_gpu.h @@ -0,0 +1,50 @@ +/* + * qemu_vhost_user_gpu.h: QEMU vhost-user GPU support + * + * Copyright (C) 2018 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#pragma once + +#include "domain_conf.h" +#include "qemu_domain.h" +#include "qemu_security.h" + +int qemuExtVhostUserGPUPrepareDomain(virQEMUDriverPtr driver, + virDomainVideoDefPtr video) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) + ATTRIBUTE_RETURN_CHECK; + +int qemuExtVhostUserGPUStart(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainVideoDefPtr video, + qemuDomainLogContextPtr logCtxt) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) + ATTRIBUTE_RETURN_CHECK; + +void qemuExtVhostUserGPUStop(virQEMUDriverPtr driver, + virDomainObjPtr def, + virDomainVideoDefPtr video) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + +int +qemuExtVhostUserGPUSetupCgroup(virQEMUDriverPtr driver, + virDomainDefPtr def, + virDomainVideoDefPtr video, + virCgroupPtr cgroup) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) + ATTRIBUTE_RETURN_CHECK; From patchwork Fri Aug 23 16:21:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 172120 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp886186ily; Fri, 23 Aug 2019 09:22:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqzN/1U+hmW/bwadViCEgpZqa+soNlDSVIZgjEPAc004RVCLeOR/gml+dduBaG15gnFvc8a7 X-Received: by 2002:aed:3f47:: with SMTP id q7mr5556097qtf.209.1566577357009; Fri, 23 Aug 2019 09:22:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566577357; cv=none; d=google.com; s=arc-20160816; b=PoWa8N2ijw36Hq9vMoM4giX73UbcKKl6GOwwBK7z5PCThaLbXJ7Wi9hT11OcDwSlKp 3FaL40OKlTHBUpC7Ohz9nQSqd54nkx9xGMVjHzbvUKP/Vn/KNx/U0RWFbrmYj8tl+3pS n8SqOaWZrVf4bsh4yXbbWkCni+rk1EHTP7LCqQL8XO5qmg7yiMMYa4la3qEt1RuUwmbU kgc7F3pESifDLb2XMiyXoPpNJUdUK1u8cVYYMp8nIx0mYQMj35xO5NgiXHQxQJOKdbwQ rwDPSpBnBn9614ZpFskTTZfrt2PbyU0S5BJYkSvd7YKH3n5DRWJ/YJAGIc4rRiPCdrlE 5T4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=CZSTzLxG3IIVlltJ0sS2ngM32kw/yJ4UpNGYx2Y0+nA=; b=Ao1fdiIll27Zv/KmS4BX/usTKOxJxEeZ9GzaNV6JbT5RKdmy0VZN3omBu1stvHK3DP XW9Yv91z8nbXuUMbKXAlf/WsT3cghI1Mq8lR6YXuyjxC8ZjETAek8Ci9xOIqkscefsNz Du+jYP2pFYZNYbPtXmIn6mATBlXesfzrP3hWNC2zI3QnHdHcRJXE2qKx0KwBY2q1sWhi vs7mN+W33c454k0ju8AGmOpw5UFT0vtmQImfVGOoL7APxr2EI3uYPqo204z0YnyjG8nP PLHpTVCLBWNwYd1NqEfoQEc66aunBcVLZeII8qC2TdLLSMktuJrGx6Jly9xWkvdLoM0T +1Rw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id f43si2263467qte.71.2019.08.23.09.22.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Aug 2019 09:22:36 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BAC448BA01; Fri, 23 Aug 2019 16:22:35 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 93D155C1B5; Fri, 23 Aug 2019 16:22:35 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5A76C24F3B; Fri, 23 Aug 2019 16:22:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7NGMBpb006067 for ; Fri, 23 Aug 2019 12:22:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7975160A9F; Fri, 23 Aug 2019 16:22:11 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.redhat.com (ovpn-122-169.rdu2.redhat.com [10.10.122.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0478860872; Fri, 23 Aug 2019 16:22:10 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Fri, 23 Aug 2019 12:21:56 -0400 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [libvirt] [PATCH v2 12/16] qemu: prepare domain for vhost-user GPU X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 23 Aug 2019 16:22:36 +0000 (UTC) From: Marc-André Lureau Call qemuExtVhostUserGPUPrepareDomain() to fill the domain with the location of the vhost-user binary to start. Signed-off-by: Marc-André Lureau Signed-off-by: Cole Robinson --- src/qemu/qemu_extdevice.c | 29 +++++++++++++++++++++++++++++ src/qemu/qemu_extdevice.h | 5 +++++ src/qemu/qemu_process.c | 4 ++++ 3 files changed, 38 insertions(+) diff --git a/src/qemu/qemu_extdevice.c b/src/qemu/qemu_extdevice.c index dc032aa60c..5c55aba006 100644 --- a/src/qemu/qemu_extdevice.c +++ b/src/qemu/qemu_extdevice.c @@ -21,6 +21,7 @@ #include #include "qemu_extdevice.h" +#include "qemu_vhost_user_gpu.h" #include "qemu_domain.h" #include "qemu_tpm.h" @@ -92,6 +93,34 @@ qemuExtDevicesInitPaths(virQEMUDriverPtr driver, } +/* + * qemuExtDevicesPrepareDomain: + * + * @driver: QEMU driver + * @vm: domain + * + * Code that modifies live XML of a domain which is about to start. + */ +int +qemuExtDevicesPrepareDomain(virQEMUDriverPtr driver, + virDomainObjPtr vm) +{ + int ret = 0; + size_t i; + + for (i = 0; i < vm->def->nvideos; i++) { + virDomainVideoDefPtr video = vm->def->videos[i]; + + if (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO && video->vhostuser) { + if ((ret = qemuExtVhostUserGPUPrepareDomain(driver, video) < 0)) + break; + } + } + + return ret; +} + + /* * qemuExtDevicesPrepareHost: * diff --git a/src/qemu/qemu_extdevice.h b/src/qemu/qemu_extdevice.h index 039b3e60dd..2412244d60 100644 --- a/src/qemu/qemu_extdevice.h +++ b/src/qemu/qemu_extdevice.h @@ -29,6 +29,11 @@ int qemuExtDeviceLogCommand(qemuDomainLogContextPtr logCtxt, ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; +int qemuExtDevicesPrepareDomain(virQEMUDriverPtr driver, + virDomainObjPtr vm) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) + ATTRIBUTE_RETURN_CHECK; + int qemuExtDevicesPrepareHost(virQEMUDriverPtr driver, virDomainDefPtr def) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index c439f17011..ed767b0807 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6358,6 +6358,10 @@ qemuProcessPrepareDomain(virQEMUDriverPtr driver, if (qemuFirmwareFillDomain(driver, vm, flags) < 0) goto cleanup; + VIR_DEBUG("Preparing external devices"); + if (qemuExtDevicesPrepareDomain(driver, vm) < 0) + goto cleanup; + for (i = 0; i < vm->def->nchannels; i++) { if (qemuDomainPrepareChannel(vm->def->channels[i], priv->channelTargetDir) < 0) From patchwork Fri Aug 23 16:21:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 172123 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp886268ily; Fri, 23 Aug 2019 09:22:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqyS/bmwAorBqkGnxFHAX8YpGtAKaYjWeLVzi4nzSG8R4Gr8heXaqf0I0JvxGvgVBGOR6qKU X-Received: by 2002:a37:94d:: with SMTP id 74mr4858729qkj.101.1566577361056; Fri, 23 Aug 2019 09:22:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566577361; cv=none; d=google.com; s=arc-20160816; b=OM5/UwkZ5ARhLx8mDNoGPlBEjuGIJS4fCcydPfbmJg8Y4tOOnS7sbIE3+rwE1ubQwW fcVyMcXCfjIOmZdznF+niRCwsoiKS7pr2Hhh35svp17BRWxngZrWFI/1mINwjyMh/Tns QlcfMqNSRecpwWCTv4ZWjxC4rprWaOc1xeAlkiByGr6yUrTZFT+IRKNeJcl7IB8s4os7 v3/WuN0mvA7fNeZ+IdHVVd/7ohtE+oCXAw6FDFWuXp5soCUZoVDeikSQBIpwyvDI8hob L3/sg9NpaTCbagIkYVUxWDZMrr+T5mjscDfNSNHlrWIWDDtygymUJmNaEzjO7B7d8zfx irwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=6jVRExrwbAHpiKbghfXaHksd0Peusj/zEJ6jpglAkfs=; b=ZARL9cyUECTUAvHOMURofvNC5PlqlMqBuTcKdH/8LyNwTnJ3tQ19VEkgFTKD2A1VU0 mXYuQSF+ITD1gcOOpZXCx/1DLcLMwYz9dkG6PUZLVOj++zyzRteC2SGVeuJhn1gjxrSn ahbnaewMYP1B6wvy16dL5SbWOxttR7Bmf0gFmE1gDmZQv4IyX3yZ2TWY0Q96IU0NbqqH 7voNyPyo3pgN+bwoNV+ONK9Q5aXvTg9y69RPUehb7UDH2wyNvLZJyo5YbNFJGVox8NWk mrue/EUN/OaFr4uz0dgzShd/xprSPllxmFtbXva7DTmQ3ckG500JTQhZBDnvRVcFSRQd vP8Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id k37si2358782qte.6.2019.08.23.09.22.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Aug 2019 09:22:41 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D2CB88D6CAA; Fri, 23 Aug 2019 16:22:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AE00F1813D; Fri, 23 Aug 2019 16:22:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 693DB24AD6; Fri, 23 Aug 2019 16:22:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7NGMCx0006081 for ; Fri, 23 Aug 2019 12:22:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 204F660605; Fri, 23 Aug 2019 16:22:12 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.redhat.com (ovpn-122-169.rdu2.redhat.com [10.10.122.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id A267B6092D; Fri, 23 Aug 2019 16:22:11 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Fri, 23 Aug 2019 12:21:57 -0400 Message-Id: <4d239a3b4ce0dbd10672fee6c78121dfbf4a5b76.1566576129.git.crobinso@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [libvirt] [PATCH v2 13/16] qemu: start/stop the vhost-user-gpu external device X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Fri, 23 Aug 2019 16:22:40 +0000 (UTC) From: Marc-André Lureau Each vhost-user-gpu needs its own helper gpu process. Start/stop them, and apply the emulator cgroup controller. Signed-off-by: Marc-André Lureau Signed-off-by: Cole Robinson --- src/qemu/qemu_extdevice.c | 46 +++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_extdevice.c b/src/qemu/qemu_extdevice.c index 5c55aba006..3dbcec3546 100644 --- a/src/qemu/qemu_extdevice.c +++ b/src/qemu/qemu_extdevice.c @@ -161,10 +161,21 @@ qemuExtDevicesStart(virQEMUDriverPtr driver, bool incomingMigration) { int ret = 0; + size_t i; if (qemuExtDevicesInitPaths(driver, vm->def) < 0) return -1; + for (i = 0; i < vm->def->nvideos; i++) { + virDomainVideoDefPtr video = vm->def->videos[i]; + + if (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO && video->vhostuser) { + ret = qemuExtVhostUserGPUStart(driver, vm, video, logCtxt); + if (ret < 0) + return ret; + } + } + if (vm->def->tpm) ret = qemuExtTPMStart(driver, vm, logCtxt, incomingMigration); @@ -176,9 +187,18 @@ void qemuExtDevicesStop(virQEMUDriverPtr driver, virDomainObjPtr vm) { + size_t i; + if (qemuExtDevicesInitPaths(driver, vm->def) < 0) return; + for (i = 0; i < vm->def->nvideos; i++) { + virDomainVideoDefPtr video = vm->def->videos[i]; + + if (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO && video->vhostuser) + qemuExtVhostUserGPUStop(driver, vm, video); + } + if (vm->def->tpm) qemuExtTPMStop(driver, vm); } @@ -187,6 +207,14 @@ qemuExtDevicesStop(virQEMUDriverPtr driver, bool qemuExtDevicesHasDevice(virDomainDefPtr def) { + size_t i; + + for (i = 0; i < def->nvideos; i++) { + if (def->videos[i]->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO && + def->videos[i]->vhostuser) + return true; + } + if (def->tpm && def->tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR) return true; @@ -199,10 +227,20 @@ qemuExtDevicesSetupCgroup(virQEMUDriverPtr driver, virDomainDefPtr def, virCgroupPtr cgroup) { - int ret = 0; + size_t i; - if (def->tpm) - ret = qemuExtTPMSetupCgroup(driver, def, cgroup); + for (i = 0; i < def->nvideos; i++) { + virDomainVideoDefPtr video = def->videos[i]; - return ret; + if (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO && + video->vhostuser && + qemuExtVhostUserGPUSetupCgroup(driver, def, video, cgroup) < 0) + return -1; + } + + if (def->tpm && + qemuExtTPMSetupCgroup(driver, def, cgroup) < 0) + return -1; + + return 0; } From patchwork Fri Aug 23 16:21:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 172125 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp886357ily; Fri, 23 Aug 2019 09:22:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqyXNGWZuFiEtbRrhynSEFAkl+2gpPhD+0WJfl82oNEciCZriZtb0uJ0zrRdOmQraXoi526u X-Received: by 2002:a05:620a:1287:: with SMTP id w7mr4820709qki.25.1566577365018; Fri, 23 Aug 2019 09:22:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566577365; cv=none; d=google.com; s=arc-20160816; b=hBsGjPK1rrtPdQqrXgIdq2j2ku6SbOlbni3a9QRYHEGRxdRWuStQwQRThBmXT467MD YIoWAJRROXrrsk6m0upB0flsXYMKsDOWG0sWWi2FS/GJZvxcbN/vzkItpr+z57ZkkQnL 3XfLntlTDCH9J3KMvQ+WlT+5iCmu6BrNeKjH933XA2ZTzxQaXGYh16Pq4uMk8NH1An0b KV5MsTr0IERzXkQfryVhwFMyL9jr57V8qAeie53apTX45qJ3giGkoVDeNDt5JM7Ssn2V ToQwjXlSc1wppNO/IZg3ALGiTq5nCuTptfq/A9kZz4izIa+TzZNOz+oCysINi18nvdFe f6YQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=/QW/Zi8t//W0D2Ss0PBdY0fqCCq7AqvpmDiJ0ltUtIY=; b=s7INu5XDSJc1eVe5oX4CTP0DkAc4oNMY/6oJw3AFMnfkCuqtrpjaDjrA6o1opHrdyx EyOaaVb5ocNsg0jcVms3G3QFeLTMdvsrWQc19++orx6jyitgBwl2Vlrsumh6H+Xjewr2 ZhhmVjV+1WRxC0s99/bHo/UzhG8OlGEwIvoDqswUVHJAKgwDhvvo9Eh/37sdgmjtwM/9 sZo12tbPt9Ns+l9/fUjuZu2lfyWvR4+nFO5USWIB4NHzi+nkH7pR2PP+yvmwtRjQ6Ry3 5vQ0a1B4YDaU4vlj6IVIPlQ+TDEhQmkaTWaLhRX1ru/E0FybD+2ktAjHRZxiqE7HCl+G VGLg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id f1si2239112qtk.51.2019.08.23.09.22.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Aug 2019 09:22:45 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 84F1410576E0; Fri, 23 Aug 2019 16:22:43 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5B0B11901F; Fri, 23 Aug 2019 16:22:43 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1F40C180BAA4; Fri, 23 Aug 2019 16:22:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7NGMCjl006091 for ; Fri, 23 Aug 2019 12:22:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id BB3806092D; Fri, 23 Aug 2019 16:22:12 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.redhat.com (ovpn-122-169.rdu2.redhat.com [10.10.122.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 49DB960605; Fri, 23 Aug 2019 16:22:12 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Fri, 23 Aug 2019 12:21:58 -0400 Message-Id: <98d3ca86997a6171090d1a6cc544fcafc31305b7.1566576129.git.crobinso@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [libvirt] [PATCH v2 14/16] qemu: build vhost-user GPU devices X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Fri, 23 Aug 2019 16:22:44 +0000 (UTC) From: Marc-André Lureau For each vhost-user GPUs, - build a socket chardev, and pass the vhost-user socket to it - build a vhost-user video device and associate it with the chardev Signed-off-by: Marc-André Lureau Signed-off-by: Cole Robinson --- src/qemu/qemu_command.c | 46 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 8bef103f68..0e1d9510e5 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4672,8 +4672,15 @@ qemuBuildDeviceVideoStr(const virDomainDef *def, goto error; } - if (STREQ(model, "virtio-gpu")) { - if (qemuBuildVirtioDevStr(&buf, "virtio-gpu", qemuCaps, + if (video->vhostuser) { + if (STREQ(model, "virtio-vga")) + model = "vhost-user-vga"; + if (STREQ(model, "virtio-gpu")) + model = "vhost-user-gpu"; + } + + if (STREQ(model, "virtio-gpu") || STREQ(model, "vhost-user-gpu")) { + if (qemuBuildVirtioDevStr(&buf, model, qemuCaps, VIR_DOMAIN_DEVICE_VIDEO, video) < 0) { goto error; } @@ -4715,6 +4722,10 @@ qemuBuildDeviceVideoStr(const virDomainDef *def, if (video->heads) virBufferAsprintf(&buf, ",max_outputs=%u", video->heads); } + } else if (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO && video->vhostuser) { + if (video->heads) + virBufferAsprintf(&buf, ",max_outputs=%u", video->heads); + virBufferAsprintf(&buf, ",chardev=chr-vu-%s", video->info.alias); } else if (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO) { if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_GPU_MAX_OUTPUTS)) { if (video->heads) @@ -4830,6 +4841,23 @@ qemuBuildVgaVideoCommand(virCommandPtr cmd, } +static char * +qemuBuildVhostUserChardevStr(const char *alias, + int *fd, + virCommandPtr cmd) +{ + char *chardev = NULL; + + if (virAsprintf(&chardev, "socket,id=chr-vu-%s,fd=%d", alias, *fd) < 0) + return NULL; + + virCommandPassFD(cmd, *fd, VIR_COMMAND_PASS_FD_CLOSE_PARENT); + *fd = -1; + + return chardev; +} + + static int qemuBuildVideoCommandLine(virCommandPtr cmd, const virDomainDef *def, @@ -4837,6 +4865,20 @@ qemuBuildVideoCommandLine(virCommandPtr cmd, { size_t i; + for (i = 0; i < def->nvideos; i++) { + VIR_AUTOFREE(char *) chardev = NULL; + virDomainVideoDefPtr video = def->videos[i]; + + if (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO && video->vhostuser) { + if (!(chardev = qemuBuildVhostUserChardevStr(video->info.alias, + &video->info.vhost_user_fd, + cmd))) + return -1; + + virCommandAddArgList(cmd, "-chardev", chardev, NULL); + } + } + for (i = 0; i < def->nvideos; i++) { char *str = NULL; virDomainVideoDefPtr video = def->videos[i]; From patchwork Fri Aug 23 16:21:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 172124 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp886303ily; Fri, 23 Aug 2019 09:22:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqzfFig2SRm86Tidft7ynU9lIY1eYS827fTqGdHNEvMDFEMKPc2JmlUgG9aa/d4AhPPvVT2D X-Received: by 2002:ae9:e118:: with SMTP id g24mr4895249qkm.378.1566577362632; Fri, 23 Aug 2019 09:22:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566577362; cv=none; d=google.com; s=arc-20160816; b=f2SJhouKRzYvhfsxfjBdFRSywxd2e+c+PkMs8pwuA3Qa07F0HqJpgs2Hplb9oKyX93 ZPP+LB6CkIV+GD9WI2vhCeq3Jfmvxr5tp0f/L9sqaLIh6GMBUa39fhGj2PZsEPmJXZMi dz9qfzbz+yzO4OuIUh7IvZmwNPccFJQVSkLP9xKwLExQ7IDBFpMnEwcuSmjhupzHRdpd XNTw8KpMgtNeUs1jH+Sz4noFjWP11eZdAdNjHWRifRIJXvHLGSTuC2Km5qtTpDzwbfd3 csji0hbxvA25CW1DOvsiNd57zTVTit1FCL73LjXXZI60Wioy3hnBvh7aPrlr7pLJ9gG/ cwNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=9+OOeBSZ4nvRKdUERdgyMf+CDN8VvXsDiaJzWqqqhWY=; b=gcjTg8twViKc7/+UcIHp2sIgSVX3D+1pvYvSIai6W3oMcYnwrax7F9vBq07uL3IIBA rZJ482JbrKipjE6Evas8zq8Umz7C8kXEcldgvFVaMSXcI2aSz6NqcR4GbcEhi5kcefqq 8KEfAB81lVGB453acWtRZ8/7ctOGEygXR3XuoWh2xD1LT2fawLXAX8jcEXBIIP4jep4/ fzLYVaptbTxtrcrd2puXsM4wNq2ePzN5drlfih5QYLgTYuCxDgLSwt90oAyRENXtXjlS s1rt5M0ITAFvGXCcgSoCokLFIV8xRHknj/jnu2TgHhGA2nXMYwYbS7apeBh1KzsZ97Uz l8Tw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id g17si2100895qkl.306.2019.08.23.09.22.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Aug 2019 09:22:42 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 60CD01E2029; Fri, 23 Aug 2019 16:22:41 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3A6A3BA8F; Fri, 23 Aug 2019 16:22:41 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id F12ED180BAA2; Fri, 23 Aug 2019 16:22:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7NGMDeC006098 for ; Fri, 23 Aug 2019 12:22:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6275460605; Fri, 23 Aug 2019 16:22:13 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.redhat.com (ovpn-122-169.rdu2.redhat.com [10.10.122.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3BDE60872; Fri, 23 Aug 2019 16:22:12 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Fri, 23 Aug 2019 12:21:59 -0400 Message-Id: <91200df1c0012490e08a68101b1ec4c362dee6b8.1566576129.git.crobinso@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [libvirt] [PATCH v2 15/16] tests: mock execv/execve X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.71]); Fri, 23 Aug 2019 16:22:41 +0000 (UTC) From: Marc-André Lureau Learn to override the paths to the program to execute (vhost-user helpers are executed to check for runtime capabilities). Signed-off-by: Marc-André Lureau Signed-off-by: Cole Robinson --- tests/virfilewrapper.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/virfilewrapper.c b/tests/virfilewrapper.c index 160cd571e0..3d3f319f2c 100644 --- a/tests/virfilewrapper.c +++ b/tests/virfilewrapper.c @@ -44,6 +44,8 @@ static FILE *(*real_fopen)(const char *path, const char *mode); static int (*real_access)(const char *path, int mode); static int (*real_mkdir)(const char *path, mode_t mode); static DIR *(*real_opendir)(const char *path); +static int (*real_execv)(const char *path, char *const argv[]); +static int (*real_execve)(const char *path, char *const argv[], char *const envp[]); static void init_syms(void) { @@ -55,6 +57,8 @@ static void init_syms(void) VIR_MOCK_REAL_INIT(mkdir); VIR_MOCK_REAL_INIT(open); VIR_MOCK_REAL_INIT(opendir); + VIR_MOCK_REAL_INIT(execv); + VIR_MOCK_REAL_INIT(execve); } @@ -191,4 +195,22 @@ DIR *opendir(const char *path) return real_opendir(newpath ? newpath : path); } +int execv(const char *path, char *const argv[]) +{ + VIR_AUTOFREE(char *) newpath = NULL; + + PATH_OVERRIDE(newpath, path); + + return real_execv(newpath ? newpath : path, argv); +} + +int execve(const char *path, char *const argv[], char *const envp[]) +{ + VIR_AUTOFREE(char *) newpath = NULL; + + PATH_OVERRIDE(newpath, path); + + return real_execve(newpath ? newpath : path, argv, envp); +} + #endif From patchwork Fri Aug 23 16:22:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 172126 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp886397ily; Fri, 23 Aug 2019 09:22:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqyrXPUa0XI/PQPLyRkDiq8j5WOHp/PfPZLGiXiwKopmObGBrreM5XaueGe+EOI9Rgy8DkuQ X-Received: by 2002:a0c:d84b:: with SMTP id i11mr4667344qvj.86.1566577366335; Fri, 23 Aug 2019 09:22:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566577366; cv=none; d=google.com; s=arc-20160816; b=zeKCPYEmmOE8cyfSoNyGtA6XhsL1bT9rpeECEDVf5owWizi0jE8NFTbTsVpBstZrWG vt67GGX6ktnMNNMc9lJL+piVchAlQ1fNWpXdbL/+me2cnSeVqI391GH6Om1dc/euAF1C hlVSUvBXKD58a8U2VdJMPiiuSLo1X2hYmAezlwnhGJL+95wYAhIE9BDIr2qHcixe7ekW TAWVNKCknIxst1HeP/MgahVji+g/QOwuKsa+AUcEk7A6tWpC99jIaXtzYJJmv6GLSJiJ Dx6NwC12eYCMYzaDpEtmp3msdA3ZHCHe402eP4kCAIkQn4tVtdKWWONBIk/lgYTbYtwl DkHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=ys6oxaVXvoN+zmwY6sbH8YjQCQXlpCkv36a5MMB86y0=; b=yfmFsl7mcM/evo888dQ3z3D7DBixLN4wv0luEBZhcV3xAHNMBIGXWyHiK4UziyXgKv aqWE5EnGJJly8Baf3BQO5D4Rj0CRrKmDAEVN0SzPEwKlT4j1E7tMWs836MW92rG3X4lo PuH+xNgM0Zc2wrlEjPSNvMMdYFEw0pcUnlSryBPrVufGE07AejKUgdZh8Eb9xCwca83U pxz2jZRVaLZ58mJXXmsgnZEJX+fkRZNpHufv76709CPlX4uDdUJplSvYnQkrMGw5glzZ uoweXmQ4mPVj4kC/0dG41xpdMRAaqaDO6YciICjb9sNjs1SXlDUxB2Rp2mstwuSIkajK fHJA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id e3si2340495qtb.241.2019.08.23.09.22.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Aug 2019 09:22:46 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1275118C892F; Fri, 23 Aug 2019 16:22:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF3C417168; Fri, 23 Aug 2019 16:22:44 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A5419180BAA8; Fri, 23 Aug 2019 16:22:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7NGMEl4006106 for ; Fri, 23 Aug 2019 12:22:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0E2B760A9F; Fri, 23 Aug 2019 16:22:14 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.redhat.com (ovpn-122-169.rdu2.redhat.com [10.10.122.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E3AF60872; Fri, 23 Aug 2019 16:22:13 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Fri, 23 Aug 2019 12:22:00 -0400 Message-Id: <979d2cf172bda54e7a56724a64099a11733a37c3.1566576129.git.crobinso@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [libvirt] [PATCH v2 16/16] tests: add vhost-user-gpu xml2argv tests X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.70]); Fri, 23 Aug 2019 16:22:45 +0000 (UTC) From: Marc-André Lureau Signed-off-by: Marc-André Lureau Signed-off-by: Cole Robinson --- .../vhost-user-gpu-secondary.args | 38 ++++++++++++++++ .../vhost-user-gpu-secondary.xml | 44 +++++++++++++++++++ tests/qemuxml2argvdata/vhost-user-vga.args | 35 +++++++++++++++ tests/qemuxml2argvdata/vhost-user-vga.xml | 41 +++++++++++++++++ tests/qemuxml2argvtest.c | 21 +++++++++ 5 files changed, 179 insertions(+) create mode 100644 tests/qemuxml2argvdata/vhost-user-gpu-secondary.args create mode 100644 tests/qemuxml2argvdata/vhost-user-gpu-secondary.xml create mode 100644 tests/qemuxml2argvdata/vhost-user-vga.args create mode 100644 tests/qemuxml2argvdata/vhost-user-vga.xml diff --git a/tests/qemuxml2argvdata/vhost-user-gpu-secondary.args b/tests/qemuxml2argvdata/vhost-user-gpu-secondary.args new file mode 100644 index 0000000000..5d41edad6b --- /dev/null +++ b/tests/qemuxml2argvdata/vhost-user-gpu-secondary.args @@ -0,0 +1,38 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-QEMUGuest1 \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu-system-i686 \ +-name QEMUGuest1 \ +-S \ +-machine pc,accel=tcg,usb=off,dump-guest-core=off \ +-m 214 \ +-realtime mlock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-object memory-backend-memfd,id=ram-node0,share=yes,size=224395264 \ +-numa node,nodeid=0,cpus=0,memdev=ram-node0 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,\ +server,nowait \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-no-acpi \ +-usb \ +-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \ +-device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \ +-chardev socket,id=chr-vu-video0,fd=0 \ +-chardev socket,id=chr-vu-video1,fd=0 \ +-device vhost-user-vga,id=video0,max_outputs=1,chardev=chr-vu-video0,bus=pci.0,\ +addr=0x2 \ +-device vhost-user-gpu-pci,id=video1,max_outputs=1,chardev=chr-vu-video1,\ +bus=pci.0,addr=0x4 \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 diff --git a/tests/qemuxml2argvdata/vhost-user-gpu-secondary.xml b/tests/qemuxml2argvdata/vhost-user-gpu-secondary.xml new file mode 100644 index 0000000000..2142497d6e --- /dev/null +++ b/tests/qemuxml2argvdata/vhost-user-gpu-secondary.xml @@ -0,0 +1,44 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + + + + + 1 + + + + + + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + +
+ + + + + + + + + + + diff --git a/tests/qemuxml2argvdata/vhost-user-vga.args b/tests/qemuxml2argvdata/vhost-user-vga.args new file mode 100644 index 0000000000..ce690e4f21 --- /dev/null +++ b/tests/qemuxml2argvdata/vhost-user-vga.args @@ -0,0 +1,35 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-QEMUGuest1 \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu-system-i686 \ +-name QEMUGuest1 \ +-S \ +-machine pc,accel=tcg,usb=off,dump-guest-core=off \ +-m 214 \ +-realtime mlock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-object memory-backend-memfd,id=ram-node0,share=yes,size=224395264 \ +-numa node,nodeid=0,cpus=0,memdev=ram-node0 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,\ +server,nowait \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-no-acpi \ +-usb \ +-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \ +-device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \ +-chardev socket,id=chr-vu-video0,fd=0 \ +-device vhost-user-vga,id=video0,max_outputs=1,chardev=chr-vu-video0,bus=pci.0,\ +addr=0x2 \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 diff --git a/tests/qemuxml2argvdata/vhost-user-vga.xml b/tests/qemuxml2argvdata/vhost-user-vga.xml new file mode 100644 index 0000000000..81b1e7643e --- /dev/null +++ b/tests/qemuxml2argvdata/vhost-user-vga.xml @@ -0,0 +1,41 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + + + + + 1 + + + + + + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + +
+ + + + + + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 1799eb3387..b4d705f721 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -674,6 +674,15 @@ mymain(void) virFileWrapperAddPrefix("/home/user/.config/qemu/firmware", abs_srcdir "/qemufirmwaredata/home/user/.config/qemu/firmware"); + virFileWrapperAddPrefix(SYSCONFDIR "/qemu/vhost-user", + abs_srcdir "/qemuvhostuserdata/etc/qemu/vhost-user"); + virFileWrapperAddPrefix(PREFIX "/share/qemu/vhost-user", + abs_srcdir "/qemuvhostuserdata/usr/share/qemu/vhost-user"); + virFileWrapperAddPrefix("/home/user/.config/qemu/vhost-user", + abs_srcdir "/qemuvhostuserdata/home/user/.config/qemu/vhost-user"); + virFileWrapperAddPrefix("/usr/libexec/qemu/vhost-user", + abs_srcdir "/qemuvhostuserdata/usr/libexec/qemu/vhost-user"); + /** * The following set of macros allows testing of XML -> argv conversion with a * real set of capabilities gathered from a real qemu copy. It is desired to use @@ -2981,6 +2990,18 @@ mymain(void) DO_TEST_CAPS_LATEST("os-firmware-efi-secboot"); DO_TEST_CAPS_ARCH_LATEST("aarch64-os-firmware-efi", "aarch64"); + DO_TEST("vhost-user-vga", + QEMU_CAPS_OBJECT_MEMORY_MEMFD, + QEMU_CAPS_DEVICE_VIDEO_PRIMARY, + QEMU_CAPS_DEVICE_VHOST_USER_GPU, + QEMU_CAPS_DEVICE_VHOST_USER_VGA); + + DO_TEST("vhost-user-gpu-secondary", + QEMU_CAPS_OBJECT_MEMORY_MEMFD, + QEMU_CAPS_DEVICE_VIDEO_PRIMARY, + QEMU_CAPS_DEVICE_VHOST_USER_GPU, + QEMU_CAPS_DEVICE_VHOST_USER_VGA); + if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL) virFileDeleteTree(fakerootdir);