8301050: Detect Xen Virtualization on Linux aarch64

Reviewed-by: dholmes, clanger
This commit is contained in:
Matthias Baesken 2023-02-03 07:54:33 +00:00
parent b504c9411e
commit 11804b246e
2 changed files with 28 additions and 13 deletions

View File

@ -564,26 +564,40 @@ void VM_Version::initialize() {
check_virtualizations();
}
void VM_Version::check_virtualizations() {
#if defined(LINUX)
const char* info_file = "/sys/devices/virtual/dmi/id/product_name";
// check for various strings in the dmi data indicating virtualizations
static bool check_info_file(const char* fpath,
const char* virt1, VirtualizationType vt1,
const char* virt2, VirtualizationType vt2) {
char line[500];
FILE* fp = os::fopen(info_file, "r");
FILE* fp = os::fopen(fpath, "r");
if (fp == nullptr) {
return;
return false;
}
while (fgets(line, sizeof(line), fp) != nullptr) {
if (strcasestr(line, "KVM") != 0) {
Abstract_VM_Version::_detected_virtualization = KVM;
break;
if (strcasestr(line, virt1) != 0) {
Abstract_VM_Version::_detected_virtualization = vt1;
fclose(fp);
return true;
}
if (strcasestr(line, "VMware") != 0) {
Abstract_VM_Version::_detected_virtualization = VMWare;
break;
if (virt2 != NULL && strcasestr(line, virt2) != 0) {
Abstract_VM_Version::_detected_virtualization = vt2;
fclose(fp);
return true;
}
}
fclose(fp);
return false;
}
#endif
void VM_Version::check_virtualizations() {
#if defined(LINUX)
const char* pname_file = "/sys/devices/virtual/dmi/id/product_name";
const char* tname_file = "/sys/hypervisor/type";
if (check_info_file(pname_file, "KVM", KVM, "VMWare", VMWare)) {
return;
}
check_info_file(tname_file, "Xen", XenHVM, NULL, NoDetectedVirtualization);
#endif
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -71,9 +71,10 @@ class Abstract_VM_Version: AllStatic {
static int _vm_build_number;
static unsigned int _data_cache_line_flush_size;
public:
static VirtualizationType _detected_virtualization;
public:
// Called as part of the runtime services initialization which is
// called from the management module initialization (via init_globals())
// after argument parsing and attaching of the main thread has