From nobody Thu Apr 25 23:17:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1633645084481406.54099202814484; Thu, 7 Oct 2021 15:18:04 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-293--TFTBbmrPbq5eXa4e5D0tQ-1; Thu, 07 Oct 2021 18:18:01 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6A2511162637; Thu, 7 Oct 2021 22:05:02 +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 62EAF10013D7; Thu, 7 Oct 2021 22:05:00 +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 0D2F0181A1CF; Thu, 7 Oct 2021 21:57:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 197Lvksn015680 for ; Thu, 7 Oct 2021 17:57:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 20FB32026D48; Thu, 7 Oct 2021 21:57:46 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1B9562029F6D for ; Thu, 7 Oct 2021 21:57:41 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6FDFA185A7A4 for ; Thu, 7 Oct 2021 21:57:41 +0000 (UTC) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by relay.mimecast.com with ESMTP id us-mta-40-Gq1k9bHuPBSMona4traV5w-1; Thu, 07 Oct 2021 17:57:38 -0400 Received: from prapal-ch2.oiwy50ateaxezb1sqsoezlib2f.xx.internal.cloudapp.net (unknown [20.80.162.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 3310620B8008; Thu, 7 Oct 2021 14:49:43 -0700 (PDT) X-MC-Unique: -TFTBbmrPbq5eXa4e5D0tQ-1 X-MC-Unique: Gq1k9bHuPBSMona4traV5w-1 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3310620B8008 From: Praveen K Paladugu To: libvir-list@redhat.com, prapal@linux.microsoft.com Subject: [PATCH v1] tools: add virt-host-validate-ch for ch driver Date: Thu, 7 Oct 2021 21:49:37 +0000 Message-Id: <20211007214937.1716538-1-prapal@linux.microsoft.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 197Lvksn015680 X-loop: libvir-list@redhat.com 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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1633645085995100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Wei-Chen Chen Signed-off-by: Praveen K Paladugu Reviewed-by: Michal Privoznik --- po/POTFILES.in | 1 + tools/meson.build | 5 +++ tools/virt-host-validate-ch.c | 85 +++++++++++++++++++++++++++++++++++ tools/virt-host-validate-ch.h | 24 ++++++++++ tools/virt-host-validate.c | 12 +++++ 5 files changed, 127 insertions(+) create mode 100644 tools/virt-host-validate-ch.c create mode 100644 tools/virt-host-validate-ch.h diff --git a/po/POTFILES.in b/po/POTFILES.in index c200d7452a..b554cf08ca 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -369,6 +369,7 @@ @SRCDIR@tools/virsh.h @SRCDIR@tools/virt-admin.c @SRCDIR@tools/virt-host-validate-bhyve.c +@SRCDIR@tools/virt-host-validate-ch.c @SRCDIR@tools/virt-host-validate-common.c @SRCDIR@tools/virt-host-validate-lxc.c @SRCDIR@tools/virt-host-validate-qemu.c diff --git a/tools/meson.build b/tools/meson.build index 2acf7b0aaf..bf0eab8b6b 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -58,6 +58,11 @@ if conf.has('WITH_HOST_VALIDATE') 'virt-host-validate-bhyve.c', ] endif + if conf.has('WITH_CH') + virt_host_validate_sources +=3D [ + 'virt-host-validate-ch.c', + ] + endif =20 executable( 'virt-host-validate', diff --git a/tools/virt-host-validate-ch.c b/tools/virt-host-validate-ch.c new file mode 100644 index 0000000000..a6d8a01d1b --- /dev/null +++ b/tools/virt-host-validate-ch.c @@ -0,0 +1,85 @@ +/* + * Copyright Microsoft Corp. 2020-2021 + * + * virt-host-validate-ch.c: Sanity check a CH hypervisor host + * + * 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 "virarch.h" +#include "virbitmap.h" +#include "virt-host-validate-ch.h" +#include "virt-host-validate-common.h" + +int virHostValidateCh(void) +{ + int ret =3D 0; + virBitmap *flags; + bool hasHwVirt =3D false; + bool hasVirtFlag =3D false; + virArch arch =3D virArchFromHost(); + const char *kvmhint =3D + _("Check that CPU and firmware supports virtualization " + "and kvm module is loaded"); + + if (!(flags =3D virHostValidateGetCPUFlags())) + return -1; + + // Cloud-Hypervisor only supports x86_64 and aarch64 + switch ((int)arch) { + case VIR_ARCH_X86_64: + hasVirtFlag =3D true; + kvmhint =3D _("Check that the 'kvm-intel' or 'kvm-amd' modules are " + "loaded & the BIOS has enabled virtualization"); + if (virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_SVM) || + virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_VMX)) + hasHwVirt =3D true; + break; + case VIR_ARCH_AARCH64: + hasVirtFlag =3D true; + hasHwVirt =3D true; + break; + default: + hasHwVirt =3D false; + break; + } + + if (hasVirtFlag) { + virHostMsgCheck("CH", "%s", _("for hardware virtualization")); + if (hasHwVirt) { + virHostMsgPass(); + } else { + virHostMsgFail(VIR_HOST_VALIDATE_FAIL, + _("Only emulated CPUs are available, performance will= be " + "significantly limited")); + ret =3D -1; + } + } + + if (hasHwVirt || !hasVirtFlag) { + if (virHostValidateDeviceExists("CH", "/dev/kvm", VIR_HOST_VALIDATE_FA= IL, + kvmhint) < 0) + ret =3D -1; + else if (virHostValidateDeviceAccessible( + "CH", "/dev/kvm", VIR_HOST_VALIDATE_FAIL, + _("Check /dev/kvm is world writable or you are in " + "a group that is allowed to access it")) < 0) + ret =3D -1; + } + + return ret; +} diff --git a/tools/virt-host-validate-ch.h b/tools/virt-host-validate-ch.h new file mode 100644 index 0000000000..b16e7d36ab --- /dev/null +++ b/tools/virt-host-validate-ch.h @@ -0,0 +1,24 @@ +/* + * virt-host-validate-ch.h: Sanity check a CH hypervisor host + * + * Copyright Microsoft Corp. 2020-2021 + * + * 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 + +int virHostValidateCh(void); diff --git a/tools/virt-host-validate.c b/tools/virt-host-validate.c index 806d61bc8e..4dae97910a 100644 --- a/tools/virt-host-validate.c +++ b/tools/virt-host-validate.c @@ -40,6 +40,9 @@ #if WITH_BHYVE # include "virt-host-validate-bhyve.h" #endif +#if WITH_CH +# include "virt-host-validate-ch.h" +#endif =20 static void show_help(FILE *out, const char *argv0) @@ -53,6 +56,7 @@ show_help(FILE *out, const char *argv0) " - qemu\n" " - lxc\n" " - bhyve\n" + " - ch\n" "\n" " Options:\n" " -h, --help Display command line help\n" @@ -146,6 +150,14 @@ main(int argc, char **argv) } #endif =20 +#if WITH_CH + if (!hvname || STREQ(hvname, "ch")) { + usedHvname =3D true; + if (virHostValidateCh() < 0) + ret =3D EXIT_FAILURE; + } +#endif + if (hvname && !usedHvname) { fprintf(stderr, _("%s: unsupported hypervisor name %s\n"), argv[0], hvname); --=20 2.27.0