From nobody Sun Feb 8 18:48:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1576185141; cv=none; d=zohomail.com; s=zohoarc; b=C4OZzfU/QNDzM7jfTgHiNh90B0S85q1AqTWlgxN6dmNKNxl8LlpedtwW6nN2GOVyABNI27oakgiY/pUqgeThcogHjYXc/ebFPfOPpMHExMmV89JwjootL3uTt6NUZn/7PGlkI4fLpXXld+ab2he0whWtvLWv7cRmsQ8TzuqFG6k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576185141; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=lKpONihYcMSrS+voHaAjCCTPCXj6vgXQYv6SB3/FeQg=; b=S1+6TvN47Y7MeACugQZKo2sATiDWA0d/1sb5+ivPQ8BkGFSlJsik/ZAdkZvjXbdwTnJFIKYeynve2aUGAaZyuJssvEYW9ieVtZGlNITPkFY/oOVAMxX5KrJ1kfov4LhPVLEvAeTml1r2MEsIbD3s/ZjlpF00L8IYFXp/QEoWkb0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1576185141315376.7185628186744; Thu, 12 Dec 2019 13:12:21 -0800 (PST) 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-383-2PAkCEIaPuWFlEslDPaJsQ-1; Thu, 12 Dec 2019 16:12:18 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id EE86D801E76; Thu, 12 Dec 2019 21:12:11 +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 0AD61620A0; Thu, 12 Dec 2019 21:12:11 +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 41B641803C33; Thu, 12 Dec 2019 21:12:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xBCLC6jT007525 for ; Thu, 12 Dec 2019 16:12:06 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3C6B013BF20; Thu, 12 Dec 2019 21:12:06 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3635713BF2C for ; Thu, 12 Dec 2019 21:12:04 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 49D07800C51 for ; Thu, 12 Dec 2019 21:12:04 +0000 (UTC) Received: from mail-qv1-f67.google.com (mail-qv1-f67.google.com [209.85.219.67]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-116-j7AxHhsaM5-ZBjEscocs8g-1; Thu, 12 Dec 2019 16:12:00 -0500 Received: by mail-qv1-f67.google.com with SMTP id b18so1541781qvo.8; Thu, 12 Dec 2019 13:12:00 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:2f19:a73a:b6c3:c24a:90f3]) by smtp.gmail.com with ESMTPSA id b191sm2152476qkg.43.2019.12.12.13.11.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Dec 2019 13:11:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576185139; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=lKpONihYcMSrS+voHaAjCCTPCXj6vgXQYv6SB3/FeQg=; b=d8xl6rcSUUJmrCsn1H+Qpf1pCyFozYIPB0NbC8LKIlkz6xI+FClLtbSihbHnrI/Q7PzOEw tpEHuoGg5hAL6s1iHPLCfEnpoeKVXw4lCT0Mt78nYdU8ptIaoyxpWI7Nc9Zg7j0qLutKXf tan3C5K0LXCNMViMSYJe3k/gbQ5ndo0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=NbqekqY9KoTK7X0mho0aYCTZ5oXQkrsmzR0OGNFqqBM=; b=QB24VFO8SlIBineqzTAN3hAL6vBkryW3oTCO86UsJt6IU1YF5ZJV0X0BkoVRn9Qqzl yWujLtfCvt4vqCRXRWG79w/eA0QKeO9usUys6cqfTJFfNjo51skcsRn/K3Tk/CfwYrEy wNRlkJasmIdtAElOmAvRoRMV+wrBBEZ0zH4WArGF9BSLKb1UKk4osWa3YyLWqlgkByQL ckVqz/1PFw1vp6Bs3ZL7ZXKh+MmA9f0MY38AIgUOoZG4RU3lde0PbFkZTPi53gsJmQM9 ydJbOtz8+gqRCGf+bODov3NHaoBN60cBlb1ait8czx0koBzt8Wn8i6nTvG81f2mUOxIC nH2Q== X-Gm-Message-State: APjAAAUGk2aftLzQ4w1YP774k0Nk+oWXaKWQxLQBal1fHQ90wy5bZn5a lhCORtrtUWOwKF1Ifk+uqmVBo+wy X-Google-Smtp-Source: APXvYqzMgkVW2y/viLmjB5+pPaIbpmvXwmQI3cOJ7LDn8DEXbsT6f6NK6CBI6B+4z7fC1skT7g379g== X-Received: by 2002:a0c:9e65:: with SMTP id z37mr10002452qve.152.1576185119505; Thu, 12 Dec 2019 13:11:59 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Thu, 12 Dec 2019 18:11:50 -0300 Message-Id: <20191212211150.2750564-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: j7AxHhsaM5-ZBjEscocs8g-1 X-MC-Unique: 2PAkCEIaPuWFlEslDPaJsQ-1 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id xBCLC6jT007525 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , abologna@redhat.com Subject: [libvirt] [PATCH] virt-host-validate: warn if kvm_hv is not loaded for POWER hosts 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-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" POWER hosts does not implement CPU virtualization extensions like x86 or s390x. Instead, all bare-metal POWER hosts are considered to be virtualization ready. For POWER, the validation is done by checking the virtualization kernel modules, kvm_hv and kvm_pr, to see if they are either not installed or not loaded in the host. If the KVM modules aren't present, we should not just warn but fail to validate. This patch implements this support. If kvm_hv is not installed, which can be determined by 'modinfo' returning not-zero return code, fail the verification. If kvm_hv is installed but not loaded, show a warning. The exception are POWER8 hosts, which can work with kvm_pr. In its case, ACK the use of kvm_pr if kvm_hv is not loaded/present. Signed-off-by: Daniel Henrique Barboza --- tools/virt-host-validate-common.c | 136 ++++++++++++++++++++++++++++++ tools/virt-host-validate-common.h | 2 + tools/virt-host-validate-qemu.c | 6 ++ 3 files changed, 144 insertions(+) diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-c= ommon.c index bce0f14917..e6d7986758 100644 --- a/tools/virt-host-validate-common.c +++ b/tools/virt-host-validate-common.c @@ -411,3 +411,139 @@ int virHostValidateIOMMU(const char *hvname, virHostMsgPass(); return 0; } + + +static bool virHostCPUIsPower8(void) +{ + FILE *fp; + bool ret =3D false; + + if (!(fp =3D fopen("/proc/cpuinfo", "r"))) + return false; + + do { + char line[1024]; + + if (!fgets(line, sizeof(line), fp)) + break; + + /* Looks for the 'model name' line. This is more common for + * Intel /proc/cpuinfo formats, but let's account for it + * too. */ + if (STRPREFIX(line, "model name")) { + if (strstr(line, "POWER8")) + ret =3D true; + break; + } + + /* Looks for the 'cpu:' line which is more commonly present + * in /proc/cpuinfo Power systems. To ensure this is not + * 'cpu id' or any other cpu attribute, peek at the next char + * after the first whitespace. A tab, whitespace or ':' + * indicates we're on the right line */ + if (STRPREFIX(line, "cpu") && + (line[3] =3D=3D '\t' || line[3] =3D=3D ':' || line[3] =3D=3D '= ')) { + if (strstr(line, "POWER8")) + ret =3D true; + break; + } + + } while (1); + + VIR_FORCE_FCLOSE(fp); + + return ret; +} + + +static bool virHostKernelModuleExists(const char *module) +{ + g_autofree char *cmd =3D g_strdup_printf("modinfo %s", module); + g_autofree char *stdout =3D NULL; + g_autofree char *stderr =3D NULL; + g_autoptr(GError) err =3D NULL; + int errStatus; + + if (g_spawn_command_line_sync(cmd, &stdout, &stderr, &errStatus, &err)) + return true; + + return false; +} + + +static bool virHostKernelModuleIsLoaded(const char *module) +{ + FILE *fp; + bool ret =3D false; + + if (!(fp =3D fopen("/proc/modules", "r"))) + return false; + + do { + char line[1024]; + + if (!fgets(line, sizeof(line), fp)) + break; + + if (STRPREFIX(line, module)) { + ret =3D true; + break; + } + + } while (1); + + VIR_FORCE_FCLOSE(fp); + + return ret; +} + + +int virHostValidatePowerPCModules(void) +{ + bool kvm_pr_exists =3D virHostKernelModuleExists("kvm_pr"); + bool kvm_pr_loaded =3D kvm_pr_exists && virHostKernelModuleIsLoaded("k= vm_pr"); + bool kvm_hv_exists =3D virHostKernelModuleExists("kvm_hv"); + bool kvm_hv_loaded =3D kvm_hv_exists && virHostKernelModuleIsLoaded("k= vm_hv"); + bool hostIsP8 =3D virHostCPUIsPower8(); + + virHostMsgCheck("QEMU", "%s", _("for PowerPC KVM modules loaded")); + + /* No Power KVM virtualization modules present on the host. */ + if (!kvm_hv_exists && !kvm_pr_exists) { + virHostMsgFail(VIR_HOST_VALIDATE_FAIL, + _("No kvm_hv or kvm_pr module present in " + "the host")); + return -1; + } + + /* Bail out for all non-Power8 CPUs if kvm_hv is not present. */ + if (!kvm_hv_exists && !hostIsP8) { + virHostMsgFail(VIR_HOST_VALIDATE_FAIL, + _("No kvm_hv module present in the host")); + return -1; + } + + /* Power8 CPUs virtualization works with any of kvm_hv and kvm_pr. + * Issue a warning if none are loaded. */ + if (hostIsP8) { + if (!kvm_hv_loaded && !kvm_pr_loaded) { + virHostMsgFail(VIR_HOST_VALIDATE_WARN, + _("Load kvm_hv or kvm_pr module " + "for better performance")); + return 0; + } + + virHostMsgPass(); + return 0; + } + + /* For non-Power8 hosts, show a warning if kvm_hv is not loaded. */ + if (!kvm_hv_loaded) { + virHostMsgFail(VIR_HOST_VALIDATE_WARN, + _("Load kvm_hv for better performance")); + return 0; + } + + virHostMsgPass(); + return 0; +} diff --git a/tools/virt-host-validate-common.h b/tools/virt-host-validate-c= ommon.h index 1b7e93e520..7a2933c8fd 100644 --- a/tools/virt-host-validate-common.h +++ b/tools/virt-host-validate-common.h @@ -83,3 +83,5 @@ int virHostValidateCGroupControllers(const char *hvname, =20 int virHostValidateIOMMU(const char *hvname, virHostValidateLevel level); + +int virHostValidatePowerPCModules(void); \ No newline at end of file diff --git a/tools/virt-host-validate-qemu.c b/tools/virt-host-validate-qem= u.c index ff3c1f0231..8753c6a31d 100644 --- a/tools/virt-host-validate-qemu.c +++ b/tools/virt-host-validate-qemu.c @@ -57,6 +57,12 @@ int virHostValidateQEMU(void) if (virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_SIE)) hasHwVirt =3D true; break; + case VIR_ARCH_PPC64: + case VIR_ARCH_PPC64LE: + hasVirtFlag =3D true; + if (virHostValidatePowerPCModules() =3D=3D 0) + hasHwVirt =3D true; + break; default: hasHwVirt =3D false; } --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list