From nobody Thu Nov 6 15:16:46 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489085522358118.70296127378174; Thu, 9 Mar 2017 10:52:02 -0800 (PST) Received: from localhost ([::1]:35807 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cm3AO-0005sq-Nh for importer@patchew.org; Thu, 09 Mar 2017 13:52:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47953) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cm39T-0005p7-3Z for qemu-devel@nongnu.org; Thu, 09 Mar 2017 13:51:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cm39O-0005g3-AM for qemu-devel@nongnu.org; Thu, 09 Mar 2017 13:51:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52778) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cm39O-0005fv-4v for qemu-devel@nongnu.org; Thu, 09 Mar 2017 13:50:58 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1658815561 for ; Thu, 9 Mar 2017 18:50:57 +0000 (UTC) Received: from localhost (ovpn-116-55.gru2.redhat.com [10.97.116.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82C5B2D5D3; Thu, 9 Mar 2017 18:50:52 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Thu, 9 Mar 2017 15:50:46 -0300 Message-Id: <20170309185046.17555-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 09 Mar 2017 18:50:57 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.9] kvmclock: Don't crash QEMU if KVM is disabled X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Most machines don't allow sysbus devices like "kvmclock" to be created from the command-line, but some of them do (the ones with has_dynamic_sysbus=3Dtrue). In those cases, it's possible to manually create a kvmclock device without KVM being enabled, making QEMU crash: $ qemu-system-x86_64 -machine q35,accel=3Dtcg -device kvmclock Segmentation fault (core dumped) This changes kvmclock's realize method to return an error if KVM is disabled, to ensure it won't crash QEMU. Signed-off-by: Eduardo Habkost --- hw/i386/kvm/clock.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c index ef9d560f9c..13eca374cd 100644 --- a/hw/i386/kvm/clock.c +++ b/hw/i386/kvm/clock.c @@ -22,6 +22,7 @@ #include "kvm_i386.h" #include "hw/sysbus.h" #include "hw/kvm/clock.h" +#include "qapi/error.h" =20 #include #include @@ -208,6 +209,11 @@ static void kvmclock_realize(DeviceState *dev, Error *= *errp) { KVMClockState *s =3D KVM_CLOCK(dev); =20 + if (!kvm_enabled()) { + error_setg(errp, "kvmclock device requires KVM"); + return; + } + kvm_update_clock(s); =20 qemu_add_vm_change_state_handler(kvmclock_vm_state_change, s); --=20 2.11.0.259.g40922b1