public inbox for development@lists.ipfire.org
 help / color / mirror / Atom feed
From: Michael Tremer <michael.tremer@ipfire.org>
To: development@lists.ipfire.org
Subject: [PATCH] smt: Fix check to detect if a system is running virtually
Date: Fri, 21 Aug 2020 11:51:10 +0200	[thread overview]
Message-ID: <20200821095110.9090-1-michael.tremer@ipfire.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 1217 bytes --]

/sys/hypervisor exists when a host has loaded the kvm modules.

Fixes: #12472
Signed-off-by: Michael Tremer <michael.tremer(a)ipfire.org>
---
 src/initscripts/system/functions | 5 +++++
 src/initscripts/system/smt       | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/initscripts/system/functions b/src/initscripts/system/functions
index 30119918c..234b798cf 100644
--- a/src/initscripts/system/functions
+++ b/src/initscripts/system/functions
@@ -784,6 +784,11 @@ umount_ramdisk() {
 	rm -rf "${path_tmpfs}"
 }
 
+# Returns true when this system running in a virtual environment
+running_on_hypervisor() {
+	grep -qE "^flags\s+:.*hypervisor" /proc/cpuinfo
+}
+
 # https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/identify_ec2_instances.html
 running_on_ec2() {
 	local uuid
diff --git a/src/initscripts/system/smt b/src/initscripts/system/smt
index bfa7d57b3..274ec4bba 100644
--- a/src/initscripts/system/smt
+++ b/src/initscripts/system/smt
@@ -21,7 +21,7 @@ case "${1}" in
 		fi 2>/dev/null
 
 		# Do not disable SMT inside virtual machines
-		if [ -d "/sys/hypervisor" ]; then
+		if running_on_hypervisor; then
 			exit 0
 		fi
 
-- 
2.12.2


                 reply	other threads:[~2020-08-21  9:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200821095110.9090-1-michael.tremer@ipfire.org \
    --to=michael.tremer@ipfire.org \
    --cc=development@lists.ipfire.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox