From nobody Sun Nov 24 07:36:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1725367387; cv=none; d=zohomail.com; s=zohoarc; b=DDzlg3WTSX8gPv7Mqk8YUnPAH+pCyz6nHk1hCTem4MavyLRj41dYRFe08QtXAr0KiFu5ueGz9+5sX2lbzJG1CPg5X58ezLH3jyF7WdV495YJe/EiOt7dFcJSzhP1umypKCGAQlxYrpug41M/xO/AcW4RCDaFf/qKGHSWIPxlL9s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725367387; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=r0as5Ez9pDXfQjAecZyDf6B3cpNpbSgXo6vc2nKXViw=; b=HXgL+fOLEAck2M7PDXKsMnoNWD3A42OuUbLSUjN3BW8NKUV2Tf4AqrS3FCgKHQbY7xYCSCT+X+o3X84WfaCBEBMt7XrvZAcbWNPmyYblcYzORxJWABFCO/RtefuEqIacLTXRCDW4gUHWeHufQagNrDxAQ2GKFx1zEBDx5C8x1WI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172536738771991.58824287936147; Tue, 3 Sep 2024 05:43:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1slSrW-0000q5-BX; Tue, 03 Sep 2024 08:42:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1slSrU-0000kn-QS for qemu-devel@nongnu.org; Tue, 03 Sep 2024 08:42:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1slSrS-0007N5-M0 for qemu-devel@nongnu.org; Tue, 03 Sep 2024 08:42:20 -0400 Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-645-to02W86xOWa3WaSakk0TZw-1; Tue, 03 Sep 2024 08:42:11 -0400 Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-2052a68430fso40442245ad.2 for ; Tue, 03 Sep 2024 05:42:11 -0700 (PDT) Received: from localhost.localdomain ([115.96.207.26]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-20515542350sm80222025ad.213.2024.09.03.05.42.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 05:42:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725367333; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r0as5Ez9pDXfQjAecZyDf6B3cpNpbSgXo6vc2nKXViw=; b=aKSqUx9Bt32NRgbfIHaNVWT58YDH4xCfDVIZaqwU0lvRecFfTLAxUBk5GFmHvye15cQq+z jKYuhrXyXMHGLxq0oMmVQEbtx+TFGYoIsreFazmydV+FgwBwf3Cgarjpqz0fdrVFwQOix7 T3MV7n81cMYnVD5Q2prKBJO7hmD3H3s= X-MC-Unique: to02W86xOWa3WaSakk0TZw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725367330; x=1725972130; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r0as5Ez9pDXfQjAecZyDf6B3cpNpbSgXo6vc2nKXViw=; b=vui8zp9WsjsuPT2cneV6F0w/P0cqM7qBU8B2JrO7eKM56k0Wn92ncezzzRM45TCbEB e3Z8hoW8UmKEX7gaQcIf830pGTOGfnV17EbVQAEwpbuEjSdhm8mu6RLni3tB8LIGXA1U +1Sihy7S8sKEkRRfwNeVK/tm1gYNoD5egy8umZmeb+OZVQytfatrPTsGHJIqhQv+zVqd e9oUxxKI8+ZBb8LqHnG2wTAlusPhHf/edPF9S+vr3Uco+gHA9H1Edbxe4fkFpVrVp6WL /fpTMaELEnv9i0BgS8ZaxuM3X6XJEBNKOzrqKJUFfWx/l8+J/hZ2+KBWvWHwTW0fvqZz jn+g== X-Forwarded-Encrypted: i=1; AJvYcCXOvUNnIx6JSL4qfJadnojMA7AtvhGJRkuGHVBqVvaXK2NSh9YRXNLYMdhfsS+I07Rv0U9v4M6w1cy2@nongnu.org X-Gm-Message-State: AOJu0Yytk3iMzOOc7GZIqS57FPCbM18rpJJ7zzyuwo5hVN0/OgxgmHuL RuXjtmqYKDUSBD4FexaozvtJeURlcjcB50zfN9bjF+L2ebPMuzaaWtO1uCE/KcG46bTfLiZxlFU 17ML4d30LZIe/0dgdm6otErFf13KpisojRQ294XoWnipuH3oK2bmq X-Received: by 2002:a17:902:d4c1:b0:205:913b:d9ad with SMTP id d9443c01a7336-205913bdac2mr36643235ad.0.1725367330562; Tue, 03 Sep 2024 05:42:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGCl+LUoIJ3NX3VDoM316o1YCzocSyWl6ld5saLqH8chhArfps0WZWWhnAXMrWx4D3Fy/8NPw== X-Received: by 2002:a17:902:d4c1:b0:205:913b:d9ad with SMTP id d9443c01a7336-205913bdac2mr36643035ad.0.1725367330107; Tue, 03 Sep 2024 05:42:10 -0700 (PDT) From: Ani Sinha To: Paolo Bonzini , Marcelo Tosatti Cc: Ani Sinha , kvm@vger.kernel.org, qemu-devel@nongnu.org Subject: [PATCH 1/2] kvm/i386: refactor kvm_arch_init and split it into smaller functions Date: Tue, 3 Sep 2024 18:11:42 +0530 Message-ID: <20240903124143.39345-2-anisinha@redhat.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240903124143.39345-1-anisinha@redhat.com> References: <20240903124143.39345-1-anisinha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=anisinha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1725367389225116600 Content-Type: text/plain; charset="utf-8" kvm_arch_init() enables a lot of vm capabilities. Refactor them into separa= te smaller functions. Energy MSR related operations also moved to its own function. There should be no functional impact. Signed-off-by: Ani Sinha --- target/i386/kvm/kvm.c | 337 ++++++++++++++++++++++++++---------------- 1 file changed, 211 insertions(+), 126 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 503e8d956e..574c62c21a 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -2997,10 +2997,197 @@ int kvm_arch_get_default_type(MachineState *ms) return 0; } =20 +static int kvm_vm_enable_exception_payload(KVMState *s) +{ + int ret =3D 0; + has_exception_payload =3D kvm_check_extension(s, KVM_CAP_EXCEPTION_PAY= LOAD); + if (has_exception_payload) { + ret =3D kvm_vm_enable_cap(s, KVM_CAP_EXCEPTION_PAYLOAD, 0, true); + if (ret < 0) { + error_report("kvm: Failed to enable exception payload cap: %s", + strerror(-ret)); + } + } + + return ret; +} + +static int kvm_vm_enable_triple_fault_event(KVMState *s) +{ + int ret =3D 0; + has_triple_fault_event =3D \ + kvm_check_extension(s, + KVM_CAP_X86_TRIPLE_FAULT_EVENT); + if (has_triple_fault_event) { + ret =3D kvm_vm_enable_cap(s, KVM_CAP_X86_TRIPLE_FAULT_EVENT, 0, tr= ue); + if (ret < 0) { + error_report("kvm: Failed to enable triple fault event cap: %s= ", + strerror(-ret)); + } + } + return ret; +} + +static int kvm_vm_set_identity_map_addr(KVMState *s, uint64_t *identity_ba= se) +{ + /* + * On older Intel CPUs, KVM uses vm86 mode to emulate 16-bit code dire= ctly. + * In order to use vm86 mode, an EPT identity map and a TSS are neede= d. + * Since these must be part of guest physical memory, we need to alloc= ate + * them, both by setting their start addresses in the kernel and by + * creating a corresponding e820 entry. We need 4 pages before the BIO= S, + * so this value allows up to 16M BIOSes. + */ + *identity_base =3D 0xfeffc000; + return kvm_vm_ioctl(s, KVM_SET_IDENTITY_MAP_ADDR, identity_base); +} + +static int kvm_vm_set_nr_mmu_pages(KVMState *s) +{ + uint64_t shadow_mem; + int ret =3D 0; + shadow_mem =3D object_property_get_int(OBJECT(s), + "kvm-shadow-mem", + &error_abort); + if (shadow_mem !=3D -1) { + shadow_mem /=3D 4096; + ret =3D kvm_vm_ioctl(s, KVM_SET_NR_MMU_PAGES, shadow_mem); + } + return ret; +} + +static int kvm_vm_set_tss_addr(KVMState *s, uint64_t identity_base) +{ + /* Set TSS base one page after EPT identity map. */ + return kvm_vm_ioctl(s, KVM_SET_TSS_ADDR, identity_base); +} + +static int kvm_vm_enable_disable_exits(KVMState *s) +{ + int disable_exits =3D kvm_check_extension(s, KVM_CAP_X86_DISABLE_EXITS= ); +/* Work around for kernel header with a typo. TODO: fix header and drop. */ +#if defined(KVM_X86_DISABLE_EXITS_HTL) && !defined(KVM_X86_DISABLE_EXITS_H= LT) +#define KVM_X86_DISABLE_EXITS_HLT KVM_X86_DISABLE_EXITS_HTL +#endif + if (disable_exits) { + disable_exits &=3D (KVM_X86_DISABLE_EXITS_MWAIT | + KVM_X86_DISABLE_EXITS_HLT | + KVM_X86_DISABLE_EXITS_PAUSE | + KVM_X86_DISABLE_EXITS_CSTATE); + } + + return kvm_vm_enable_cap(s, KVM_CAP_X86_DISABLE_EXITS, 0, + disable_exits); +} + +static int kvm_vm_enable_bus_lock_exit(KVMState *s) +{ + int ret =3D 0; + ret =3D kvm_check_extension(s, KVM_CAP_X86_BUS_LOCK_EXIT); + if (!(ret & KVM_BUS_LOCK_DETECTION_EXIT)) { + error_report("kvm: bus lock detection unsupported"); + return -ENOTSUP; + } + ret =3D kvm_vm_enable_cap(s, KVM_CAP_X86_BUS_LOCK_EXIT, 0, + KVM_BUS_LOCK_DETECTION_EXIT); + if (ret < 0) { + error_report("kvm: Failed to enable bus lock detection cap: %s", + strerror(-ret)); + } + + return ret; +} + +static int kvm_vm_enable_notify_vmexit(KVMState *s) +{ + int ret =3D 0; + if (!kvm_check_extension(s, KVM_CAP_X86_NOTIFY_VMEXIT)) { + error_report("kvm: notify vmexit unsupported"); + return -ENOTSUP; + } + + if (s->notify_vmexit !=3D NOTIFY_VMEXIT_OPTION_DISABLE) { + uint64_t notify_window_flags =3D + ((uint64_t)s->notify_window << 32) | + KVM_X86_NOTIFY_VMEXIT_ENABLED | + KVM_X86_NOTIFY_VMEXIT_USER; + ret =3D kvm_vm_enable_cap(s, KVM_CAP_X86_NOTIFY_VMEXIT, 0, + notify_window_flags); + if (ret < 0) { + error_report("kvm: Failed to enable notify vmexit cap: %s", + strerror(-ret)); + } + } + return ret; +} + +static int kvm_vm_enable_userspace_msr(KVMState *s) +{ + int ret; + + if (!kvm_vm_check_extension(s, KVM_CAP_X86_USER_SPACE_MSR)) { + error_report("kvm: userspace MSR not supported"); + return -ENOTSUP; + } + + ret =3D kvm_vm_enable_cap(s, KVM_CAP_X86_USER_SPACE_MSR, 0, + KVM_MSR_EXIT_REASON_FILTER); + if (ret < 0) { + error_report("Could not enable user space MSRs: %s", + strerror(-ret)); + exit(1); + } + + if (!kvm_filter_msr(s, MSR_CORE_THREAD_COUNT, + kvm_rdmsr_core_thread_count, NULL)) { + error_report("Could not install MSR_CORE_THREAD_COUNT handler!"); + exit(1); + } + + return 0; +} + +static void kvm_vm_enable_energy_msrs(KVMState *s) +{ + bool r; + if (s->msr_energy.enable =3D=3D true) { + r =3D kvm_filter_msr(s, MSR_RAPL_POWER_UNIT, + kvm_rdmsr_rapl_power_unit, NULL); + if (!r) { + error_report("Could not install MSR_RAPL_POWER_UNIT \ + handler"); + exit(1); + } + + r =3D kvm_filter_msr(s, MSR_PKG_POWER_LIMIT, + kvm_rdmsr_pkg_power_limit, NULL); + if (!r) { + error_report("Could not install MSR_PKG_POWER_LIMIT \ + handler"); + exit(1); + } + + r =3D kvm_filter_msr(s, MSR_PKG_POWER_INFO, + kvm_rdmsr_pkg_power_info, NULL); + if (!r) { + error_report("Could not install MSR_PKG_POWER_INFO \ + handler"); + exit(1); + } + r =3D kvm_filter_msr(s, MSR_PKG_ENERGY_STATUS, + kvm_rdmsr_pkg_energy_status, NULL); + if (!r) { + error_report("Could not install MSR_PKG_ENERGY_STATUS \ + handler"); + exit(1); + } + } + return; +} + int kvm_arch_init(MachineState *ms, KVMState *s) { uint64_t identity_base =3D 0xfffbc000; - uint64_t shadow_mem; int ret; struct utsname utsname; Error *local_err =3D NULL; @@ -3030,24 +3217,14 @@ int kvm_arch_init(MachineState *ms, KVMState *s) =20 hv_vpindex_settable =3D kvm_check_extension(s, KVM_CAP_HYPERV_VP_INDEX= ); =20 - has_exception_payload =3D kvm_check_extension(s, KVM_CAP_EXCEPTION_PAY= LOAD); - if (has_exception_payload) { - ret =3D kvm_vm_enable_cap(s, KVM_CAP_EXCEPTION_PAYLOAD, 0, true); - if (ret < 0) { - error_report("kvm: Failed to enable exception payload cap: %s", - strerror(-ret)); - return ret; - } + ret =3D kvm_vm_enable_exception_payload(s); + if (ret < 0) { + return ret; } =20 - has_triple_fault_event =3D kvm_check_extension(s, KVM_CAP_X86_TRIPLE_F= AULT_EVENT); - if (has_triple_fault_event) { - ret =3D kvm_vm_enable_cap(s, KVM_CAP_X86_TRIPLE_FAULT_EVENT, 0, tr= ue); - if (ret < 0) { - error_report("kvm: Failed to enable triple fault event cap: %s= ", - strerror(-ret)); - return ret; - } + ret =3D kvm_vm_enable_triple_fault_event(s); + if (ret < 0) { + return ret; } =20 if (s->xen_version) { @@ -3078,22 +3255,12 @@ int kvm_arch_init(MachineState *ms, KVMState *s) uname(&utsname); lm_capable_kernel =3D strcmp(utsname.machine, "x86_64") =3D=3D 0; =20 - /* - * On older Intel CPUs, KVM uses vm86 mode to emulate 16-bit code dire= ctly. - * In order to use vm86 mode, an EPT identity map and a TSS are neede= d. - * Since these must be part of guest physical memory, we need to alloc= ate - * them, both by setting their start addresses in the kernel and by - * creating a corresponding e820 entry. We need 4 pages before the BIO= S, - * so this value allows up to 16M BIOSes. - */ - identity_base =3D 0xfeffc000; - ret =3D kvm_vm_ioctl(s, KVM_SET_IDENTITY_MAP_ADDR, &identity_base); + ret =3D kvm_vm_set_identity_map_addr(s, &identity_base); if (ret < 0) { return ret; } =20 - /* Set TSS base one page after EPT identity map. */ - ret =3D kvm_vm_ioctl(s, KVM_SET_TSS_ADDR, identity_base + 0x1000); + ret =3D kvm_vm_set_tss_addr(s, identity_base + 0x1000); if (ret < 0) { return ret; } @@ -3101,13 +3268,9 @@ int kvm_arch_init(MachineState *ms, KVMState *s) /* Tell fw_cfg to notify the BIOS to reserve the range. */ e820_add_entry(identity_base, 0x4000, E820_RESERVED); =20 - shadow_mem =3D object_property_get_int(OBJECT(s), "kvm-shadow-mem", &e= rror_abort); - if (shadow_mem !=3D -1) { - shadow_mem /=3D 4096; - ret =3D kvm_vm_ioctl(s, KVM_SET_NR_MMU_PAGES, shadow_mem); - if (ret < 0) { - return ret; - } + ret =3D kvm_vm_set_nr_mmu_pages(s); + if (ret < 0) { + return ret; } =20 if (kvm_check_extension(s, KVM_CAP_X86_SMM) && @@ -3118,20 +3281,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) } =20 if (enable_cpu_pm) { - int disable_exits =3D kvm_check_extension(s, KVM_CAP_X86_DISABLE_E= XITS); -/* Work around for kernel header with a typo. TODO: fix header and drop. */ -#if defined(KVM_X86_DISABLE_EXITS_HTL) && !defined(KVM_X86_DISABLE_EXITS_H= LT) -#define KVM_X86_DISABLE_EXITS_HLT KVM_X86_DISABLE_EXITS_HTL -#endif - if (disable_exits) { - disable_exits &=3D (KVM_X86_DISABLE_EXITS_MWAIT | - KVM_X86_DISABLE_EXITS_HLT | - KVM_X86_DISABLE_EXITS_PAUSE | - KVM_X86_DISABLE_EXITS_CSTATE); - } - - ret =3D kvm_vm_enable_cap(s, KVM_CAP_X86_DISABLE_EXITS, 0, - disable_exits); + ret =3D kvm_vm_enable_disable_exits(s); if (ret < 0) { error_report("kvm: guest stopping CPU not supported: %s", strerror(-ret)); @@ -3142,16 +3292,8 @@ int kvm_arch_init(MachineState *ms, KVMState *s) X86MachineState *x86ms =3D X86_MACHINE(ms); =20 if (x86ms->bus_lock_ratelimit > 0) { - ret =3D kvm_check_extension(s, KVM_CAP_X86_BUS_LOCK_EXIT); - if (!(ret & KVM_BUS_LOCK_DETECTION_EXIT)) { - error_report("kvm: bus lock detection unsupported"); - return -ENOTSUP; - } - ret =3D kvm_vm_enable_cap(s, KVM_CAP_X86_BUS_LOCK_EXIT, 0, - KVM_BUS_LOCK_DETECTION_EXIT); + ret =3D kvm_vm_enable_bus_lock_exit(s); if (ret < 0) { - error_report("kvm: Failed to enable bus lock detection cap= : %s", - strerror(-ret)); return ret; } ratelimit_init(&bus_lock_ratelimit_ctrl); @@ -3160,80 +3302,23 @@ int kvm_arch_init(MachineState *ms, KVMState *s) } } =20 - if (s->notify_vmexit !=3D NOTIFY_VMEXIT_OPTION_DISABLE && - kvm_check_extension(s, KVM_CAP_X86_NOTIFY_VMEXIT)) { - uint64_t notify_window_flags =3D - ((uint64_t)s->notify_window << 32) | - KVM_X86_NOTIFY_VMEXIT_ENABLED | - KVM_X86_NOTIFY_VMEXIT_USER; - ret =3D kvm_vm_enable_cap(s, KVM_CAP_X86_NOTIFY_VMEXIT, 0, - notify_window_flags); - if (ret < 0) { - error_report("kvm: Failed to enable notify vmexit cap: %s", - strerror(-ret)); - return ret; - } + ret =3D kvm_vm_enable_notify_vmexit(s); + if (ret < 0) { + return ret; } - if (kvm_vm_check_extension(s, KVM_CAP_X86_USER_SPACE_MSR)) { - bool r; =20 - ret =3D kvm_vm_enable_cap(s, KVM_CAP_X86_USER_SPACE_MSR, 0, - KVM_MSR_EXIT_REASON_FILTER); - if (ret) { - error_report("Could not enable user space MSRs: %s", - strerror(-ret)); - exit(1); - } - - r =3D kvm_filter_msr(s, MSR_CORE_THREAD_COUNT, - kvm_rdmsr_core_thread_count, NULL); - if (!r) { - error_report("Could not install MSR_CORE_THREAD_COUNT handler:= %s", - strerror(-ret)); - exit(1); + if (kvm_vm_check_extension(s, KVM_CAP_X86_USER_SPACE_MSR)) { + ret =3D kvm_vm_enable_userspace_msr(s); + if (ret < 0) { + return ret; } =20 if (s->msr_energy.enable =3D=3D true) { - r =3D kvm_filter_msr(s, MSR_RAPL_POWER_UNIT, - kvm_rdmsr_rapl_power_unit, NULL); - if (!r) { - error_report("Could not install MSR_RAPL_POWER_UNIT \ - handler: %s", - strerror(-ret)); - exit(1); - } - - r =3D kvm_filter_msr(s, MSR_PKG_POWER_LIMIT, - kvm_rdmsr_pkg_power_limit, NULL); - if (!r) { - error_report("Could not install MSR_PKG_POWER_LIMIT \ - handler: %s", - strerror(-ret)); - exit(1); - } - - r =3D kvm_filter_msr(s, MSR_PKG_POWER_INFO, - kvm_rdmsr_pkg_power_info, NULL); - if (!r) { - error_report("Could not install MSR_PKG_POWER_INFO \ - handler: %s", - strerror(-ret)); + kvm_vm_enable_energy_msrs(s); + if (kvm_msr_energy_thread_init(s, ms)) { + error_report("kvm : error RAPL feature requirement not met= "); exit(1); } - r =3D kvm_filter_msr(s, MSR_PKG_ENERGY_STATUS, - kvm_rdmsr_pkg_energy_status, NULL); - if (!r) { - error_report("Could not install MSR_PKG_ENERGY_STATUS \ - handler: %s", - strerror(-ret)); - exit(1); - } - r =3D kvm_msr_energy_thread_init(s, ms); - if (r) { - error_report("kvm : error RAPL feature requirement not mee= t"); - exit(1); - } - } } =20 --=20 2.42.0 From nobody Sun Nov 24 07:36:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1725367399; cv=none; d=zohomail.com; s=zohoarc; b=knuZ3IaoWhgmUXVC1IxkMb66YMgjIq34cNMbqdJEkTapFm5cnPaC+n0WJPoW1Ll7IPDi2DNRvIS162ibGCKUYChXv1vTAst03D1Y93Iz9KAYJQLPAcLHX3U1Qu2NwZUu3Y+xYdtzaQB8nSnJST7MBFIslrIgvEx+vVL7ayBUFLE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725367399; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QrIEiVhLJ9bUrmnEnLksh9UeyYXSB1B5dyjmrN1LcAo=; b=GqLXIMjoaAPKiVric8LTyPezqnga1Org7LPd1LZrkwT/eDEMQjrQaeEQp6/LLpOWhObXVZhJD5xKd91ouUlKRIsrkSu9bpNM81waS4pZ+ZCmHZ/lTsKXjDY6KrrDAVy8EtBYYGJTYGFxcmMDfm20v7IB+pKwJoS/Kq1H4rDluF4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1725367399043137.71441091272106; Tue, 3 Sep 2024 05:43:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1slSrT-0000g1-Jr; Tue, 03 Sep 2024 08:42:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1slSrR-0000fI-Ux for qemu-devel@nongnu.org; Tue, 03 Sep 2024 08:42:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1slSrQ-0007NF-Cf for qemu-devel@nongnu.org; Tue, 03 Sep 2024 08:42:17 -0400 Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-677-lJEh-N45PymoUxbjBg-oTQ-1; Tue, 03 Sep 2024 08:42:14 -0400 Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-2056364914eso17993225ad.3 for ; Tue, 03 Sep 2024 05:42:14 -0700 (PDT) Received: from localhost.localdomain ([115.96.207.26]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-20515542350sm80222025ad.213.2024.09.03.05.42.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 05:42:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725367335; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QrIEiVhLJ9bUrmnEnLksh9UeyYXSB1B5dyjmrN1LcAo=; b=Ep74w+/ncHP9+mYmjT4oJhbfEg7687yYEz1Ya9sA9qoYS0YD4XJS0vAsD1JUugmMCOlIns Pa1hZYKnayNsRMvCr5jP3bD6hsIcryspKnUG2I3Z4bKE3O8Z6CecmLxcPimdlefxZT8U2Y LJMn/QXQJ4ezjw8P2mZYjUhzvrhK6TM= X-MC-Unique: lJEh-N45PymoUxbjBg-oTQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725367333; x=1725972133; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QrIEiVhLJ9bUrmnEnLksh9UeyYXSB1B5dyjmrN1LcAo=; b=hvD0WfTEZZpRJxMtI/Z5k4G79cZrVmgviWW1xKXQo/jWHqTYeBw1j2hMO53MBdhWrQ 4wOWg+Ns8uFFAJvbM8KeRrVYQNaTPSX7JWflOgNr61OES+NFKjMZb6P6dMh8NooC8jpM 8NbzQGIm7AnQCOON3BJpX6Y6xnoZlSpo9VIXP2EVK+D4CDviev9isrKlX2BLWBHvsnCk lQF/62WL5UsXkFrZSOZ0bpAp0kIy9Xb4C33zWYUiXFWnDb8RaRtTdQ6BBjNdX4cS6zRZ uh6NN9fdWIJ8FhGAIVFPOUHXF7/LrR5G9GM4KDtJb4MLDuezwOUBfuf7YZBe8W0nJlRO XdHw== X-Forwarded-Encrypted: i=1; AJvYcCWHqQwZBt9OKsNZmfFBXIPQ37BXD28MUwplQM0lPFjVlgkNcGGePERNIW4ZkDHoQVC764AWJFgYqC9N@nongnu.org X-Gm-Message-State: AOJu0Yymq2H2uvIDgjM3n3vHxQXeN0aB8/YkEcwqzc/7DEqxAcPPAVLY 8GbRKzZCrjJ0eFoVNm0P1HYErW+R8Dk7aQRjWk7vdMVc7OHMtx34v+yqs8EPDHEw8JXTlLeX9zo DokhaV3d5GjaqdTCozC5cIlnz8oBu/HtiCdpLgzKLPh5XH00fgmrq X-Received: by 2002:a17:902:e5c3:b0:205:951b:5636 with SMTP id d9443c01a7336-205951b590fmr39929265ad.47.1725367333556; Tue, 03 Sep 2024 05:42:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFeUiEaFLE5xXFPPRXAqOYMGgp5Lxxy1rmWivLg51XXli2/ChgQ0liP3LPA9T2uchXW0oL+Jw== X-Received: by 2002:a17:902:e5c3:b0:205:951b:5636 with SMTP id d9443c01a7336-205951b590fmr39929065ad.47.1725367333140; Tue, 03 Sep 2024 05:42:13 -0700 (PDT) From: Ani Sinha To: Paolo Bonzini , Marcelo Tosatti Cc: Ani Sinha , kvm@vger.kernel.org, qemu-devel@nongnu.org Subject: [PATCH 2/2] kvm/i386: do not initialize identity_base variable Date: Tue, 3 Sep 2024 18:11:43 +0530 Message-ID: <20240903124143.39345-3-anisinha@redhat.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240903124143.39345-1-anisinha@redhat.com> References: <20240903124143.39345-1-anisinha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=anisinha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1725367401192116600 Content-Type: text/plain; charset="utf-8" identity_base variable is first initialzied to address 0xfffbc000 and then kvm_vm_set_identity_map_addr() overrides this value to address 0xfeffc000. The initial address to which the variable was initialized was never used. C= lean it up. Signed-off-by: Ani Sinha --- target/i386/kvm/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 574c62c21a..c8face0eeb 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -3187,7 +3187,7 @@ static void kvm_vm_enable_energy_msrs(KVMState *s) =20 int kvm_arch_init(MachineState *ms, KVMState *s) { - uint64_t identity_base =3D 0xfffbc000; + uint64_t identity_base; int ret; struct utsname utsname; Error *local_err =3D NULL; --=20 2.42.0