From nobody Thu Nov 13 21:52:16 2025 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583245308; cv=none; d=zohomail.com; s=zohoarc; b=m6pAuzdgoS3uAa4O/B7rFt9iwRWGRvqZGG+uUzN1kLvgjihH3YtQD1NHxc2TQyII537SzUofsOTOLKxB5pusuRyQ/NS7JjDh0Rm7Fr9gzxDxxXYLs/qPOb2U0HZUMd+Ihd5w84gSWTFz0hEmpJKFGl3fZ1+A74x5m+kJQR1BWm4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583245308; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SN3TdLXEozv3aKuWj82IQWSxiC0o/xgTHn+zkTgCfoM=; b=NFuf8jqW5sISrBYu55C5MQoYQC3GObf0IP5Hp1EgoZG7SryqGccak4A5QhDWK3gAXvdZP1BN9GXFOCNh7uYJToDa/cRPb2nSDVk+DU38OqqyeFBltPOhUGHwkcbg6qP2zteybU9bD5ipEUvGAu0z4RNdmFiUJwfxWnLld8ZAXcU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1583245308841891.7285229009941; Tue, 3 Mar 2020 06:21:48 -0800 (PST) Received: from localhost ([::1]:48000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j98Qd-0004Ll-N5 for importer@patchew.org; Tue, 03 Mar 2020 09:21:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34088) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j98PK-0001kY-Ks for qemu-devel@nongnu.org; Tue, 03 Mar 2020 09:20:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j98PJ-0006Fq-DB for qemu-devel@nongnu.org; Tue, 03 Mar 2020 09:20:26 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:26691 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j98PJ-0006Fh-8v for qemu-devel@nongnu.org; Tue, 03 Mar 2020 09:20:25 -0500 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-110-c2ddP0TsMqSVcnmgBBntAg-1; Tue, 03 Mar 2020 09:20:22 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4FFF18017CC; Tue, 3 Mar 2020 14:20:21 +0000 (UTC) Received: from t480s.redhat.com (ovpn-117-113.ams2.redhat.com [10.36.117.113]) by smtp.corp.redhat.com (Postfix) with ESMTP id 697B261069; Tue, 3 Mar 2020 14:20:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583245224; h=from:from: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: in-reply-to:in-reply-to:references:references; bh=SN3TdLXEozv3aKuWj82IQWSxiC0o/xgTHn+zkTgCfoM=; b=hf6Hk6FwuJwP7+Cm+inFsoxocVGyBrLXhBFLcUXjkOrkcQWz6BohMRf9oBO0LYS06Ux+4e BCyP6F6xjilTNHjuOwc3UoXNNbP/UfRFBUmxQcd1QvrKJJiKWcnj2RFuoIjJzBmMDakFJ4 xiQc3wTjqLzqDmpvGeud1tZGS33RuXg= X-MC-Unique: c2ddP0TsMqSVcnmgBBntAg-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH RFC 1/4] openpic_kvm: Use kvm_device_ioctl() instead of ioctl() Date: Tue, 3 Mar 2020 15:19:36 +0100 Message-Id: <20200303141939.352319-2-david@redhat.com> In-Reply-To: <20200303141939.352319-1-david@redhat.com> References: <20200303141939.352319-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , David Hildenbrand , "Dr . David Alan Gilbert" , Peter Xu , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Igor Mammedov , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Let's use the official variant, which will e.g., trace the call. Cc: Markus Armbruster Cc: "Philippe Mathieu-Daud=C3=A9" Cc: "Marc-Andr=C3=A9 Lureau" Cc: Paolo Bonzini Signed-off-by: David Hildenbrand --- hw/intc/openpic_kvm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/intc/openpic_kvm.c b/hw/intc/openpic_kvm.c index e4bf47d885..0d8abc1604 100644 --- a/hw/intc/openpic_kvm.c +++ b/hw/intc/openpic_kvm.c @@ -70,7 +70,7 @@ static void kvm_openpic_write(void *opaque, hwaddr addr, = uint64_t val, attr.attr =3D addr; attr.addr =3D (uint64_t)(unsigned long)&val32; =20 - ret =3D ioctl(opp->fd, KVM_SET_DEVICE_ATTR, &attr); + ret =3D kvm_device_ioctl(opp->fd, KVM_SET_DEVICE_ATTR, &attr); if (ret < 0) { qemu_log_mask(LOG_UNIMP, "%s: %s %" PRIx64 "\n", __func__, strerror(errno), attr.attr); @@ -96,7 +96,7 @@ static uint64_t kvm_openpic_read(void *opaque, hwaddr add= r, unsigned size) attr.attr =3D addr; attr.addr =3D (uint64_t)(unsigned long)&val; =20 - ret =3D ioctl(opp->fd, KVM_GET_DEVICE_ATTR, &attr); + ret =3D kvm_device_ioctl(opp->fd, KVM_GET_DEVICE_ATTR, &attr); if (ret < 0) { qemu_log_mask(LOG_UNIMP, "%s: %s %" PRIx64 "\n", __func__, strerror(errno), attr.attr); @@ -145,7 +145,7 @@ static void kvm_openpic_region_add(MemoryListener *list= ener, attr.attr =3D KVM_DEV_MPIC_BASE_ADDR; attr.addr =3D (uint64_t)(unsigned long)®_base; =20 - ret =3D ioctl(opp->fd, KVM_SET_DEVICE_ATTR, &attr); + ret =3D kvm_device_ioctl(opp->fd, KVM_SET_DEVICE_ATTR, &attr); if (ret < 0) { fprintf(stderr, "%s: %s %" PRIx64 "\n", __func__, strerror(errno), reg_base); @@ -179,7 +179,7 @@ static void kvm_openpic_region_del(MemoryListener *list= ener, attr.attr =3D KVM_DEV_MPIC_BASE_ADDR; attr.addr =3D (uint64_t)(unsigned long)®_base; =20 - ret =3D ioctl(opp->fd, KVM_SET_DEVICE_ATTR, &attr); + ret =3D kvm_device_ioctl(opp->fd, KVM_SET_DEVICE_ATTR, &attr); if (ret < 0) { fprintf(stderr, "%s: %s %" PRIx64 "\n", __func__, strerror(errno), reg_base); --=20 2.24.1 From nobody Thu Nov 13 21:52:16 2025 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583245292; cv=none; d=zohomail.com; s=zohoarc; b=c/MxBbODhIZ7DvqhrRpv77u8IosVEE4grPbdINbzaFBlA5u8FNELNzCrOMthubEad8IzPEjgsnvrPTCNwoCfTrM9cRg118tFKnvRqjJgAHKTXFgvzh5uHBuOdcki2TDS8jmFki7UVexV9g3MEne9DRGUMGq5kJDBw4dBOqe/Zjw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583245292; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4/E9HgzB+lV/cMtbYS5Hbxyo5pA+Tb9UQGfmWLIzQvI=; b=Z2sKVSGTT861KLBTGBvuREEZEbDKrZ/RM2zkEiqDkvMgvtEiSh1WQuQwXeijE+HJ5vzj480ZUk++w5gffhtlN5mmHzNGm8lILPC+YrR/ti4O348Sk+g5j4A4yV1iTLcMgrq61XWIsII1RBygCR1AeKP7VwYV1VMwMITdm2b2L6Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1583245292597260.3869996586111; Tue, 3 Mar 2020 06:21:32 -0800 (PST) Received: from localhost ([::1]:47992 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j98QN-0003dV-GL for importer@patchew.org; Tue, 03 Mar 2020 09:21:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34111) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j98PM-0001nf-M9 for qemu-devel@nongnu.org; Tue, 03 Mar 2020 09:20:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j98PL-0006GQ-9d for qemu-devel@nongnu.org; Tue, 03 Mar 2020 09:20:28 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:43925 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j98PL-0006GE-55 for qemu-devel@nongnu.org; Tue, 03 Mar 2020 09:20:27 -0500 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-253-fbGEd60YOI2Icpw3GjgHqg-1; Tue, 03 Mar 2020 09:20:25 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 043A6801E76; Tue, 3 Mar 2020 14:20:24 +0000 (UTC) Received: from t480s.redhat.com (ovpn-117-113.ams2.redhat.com [10.36.117.113]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9AF4C60FC1; Tue, 3 Mar 2020 14:20:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583245226; h=from:from: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: in-reply-to:in-reply-to:references:references; bh=4/E9HgzB+lV/cMtbYS5Hbxyo5pA+Tb9UQGfmWLIzQvI=; b=GDaMf8w5Ta9IvAfCWNHRkzBZoGasf1HoF7OaeMNHnarbmhnCJK4ZhUqBbgd11lJaYpNLLr 5YdKmbbXqSr92FyT7FALJ0QazQH51QBvj9oJWa26yZnSBfh8KrHkqAa9HqTlcJfG6EnjG1 t/36Wh+bFQrk2yLCB/8oxfcX9uKR314= X-MC-Unique: fbGEd60YOI2Icpw3GjgHqg-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH RFC 2/4] intc/s390_flic_kvm.c: Use kvm_device_ioctl() instead of ioctl() Date: Tue, 3 Mar 2020 15:19:37 +0100 Message-Id: <20200303141939.352319-3-david@redhat.com> In-Reply-To: <20200303141939.352319-1-david@redhat.com> References: <20200303141939.352319-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , David Hildenbrand , Cornelia Huck , "Dr . David Alan Gilbert" , Peter Xu , Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org, Igor Mammedov , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Let's use the official variant, which will e.g., trace the call. Cc: Cornelia Huck Cc: Halil Pasic Cc: Christian Borntraeger Cc: qemu-s390x@nongnu.org Signed-off-by: David Hildenbrand --- hw/intc/s390_flic_kvm.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/hw/intc/s390_flic_kvm.c b/hw/intc/s390_flic_kvm.c index a306b26faa..5151582ba0 100644 --- a/hw/intc/s390_flic_kvm.c +++ b/hw/intc/s390_flic_kvm.c @@ -68,7 +68,7 @@ static int flic_get_all_irqs(KVMS390FLICState *flic, }; int rc; =20 - rc =3D ioctl(flic->fd, KVM_GET_DEVICE_ATTR, &attr); + rc =3D kvm_device_ioctl(flic->fd, KVM_GET_DEVICE_ATTR, &attr); =20 return rc =3D=3D -1 ? -errno : rc; } @@ -80,7 +80,7 @@ static void flic_enable_pfault(KVMS390FLICState *flic) }; int rc; =20 - rc =3D ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr); + rc =3D kvm_device_ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr); =20 if (rc) { fprintf(stderr, "flic: couldn't enable pfault\n"); @@ -94,7 +94,7 @@ static void flic_disable_wait_pfault(KVMS390FLICState *fl= ic) }; int rc; =20 - rc =3D ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr); + rc =3D kvm_device_ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr); =20 if (rc) { fprintf(stderr, "flic: couldn't disable pfault\n"); @@ -118,7 +118,7 @@ static int flic_enqueue_irqs(void *buf, uint64_t len, .attr =3D len, }; =20 - rc =3D ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr); + rc =3D kvm_device_ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr); =20 return rc ? -errno : 0; } @@ -197,7 +197,7 @@ static int kvm_s390_clear_io_flic(S390FLICState *fs, ui= nt16_t subchannel_id, if (unlikely(!flic->clear_io_supported)) { return -ENOSYS; } - rc =3D ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr); + rc =3D kvm_device_ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr); return rc ? -errno : 0; } =20 @@ -218,7 +218,7 @@ static int kvm_s390_modify_ais_mode(S390FLICState *fs, = uint8_t isc, return -ENOSYS; } =20 - return ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr) ? -errno : 0; + return kvm_device_ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr) ? -errno= : 0; } =20 static int kvm_s390_inject_airq(S390FLICState *fs, uint8_t type, @@ -235,7 +235,7 @@ static int kvm_s390_inject_airq(S390FLICState *fs, uint= 8_t type, return -ENOSYS; } =20 - return ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr) ? -errno : 0; + return kvm_device_ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr) ? -errno= : 0; } =20 /** @@ -296,7 +296,7 @@ static int kvm_s390_register_io_adapter(S390FLICState *= fs, uint32_t id, return 0; } =20 - r =3D ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr); + r =3D kvm_device_ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr); =20 return r ? -errno : 0; } @@ -321,7 +321,7 @@ static int kvm_s390_io_adapter_map(S390FLICState *fs, u= int32_t id, return 0; } =20 - r =3D ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr); + r =3D kvm_device_ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr); return r ? -errno : 0; } =20 @@ -519,7 +519,7 @@ static int kvm_flic_ais_post_load(void *opaque, int ver= sion_id) return -ENOSYS; } =20 - return ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr) ? -errno : 0; + return kvm_device_ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr) ? -errno= : 0; } =20 static const VMStateDescription kvm_s390_flic_ais_tmp =3D { @@ -636,7 +636,7 @@ static void kvm_s390_flic_reset(DeviceState *dev) } } =20 - rc =3D ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr); + rc =3D kvm_device_ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr); if (rc) { trace_flic_reset_failed(errno); } --=20 2.24.1 From nobody Thu Nov 13 21:52:16 2025 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583245296; cv=none; d=zohomail.com; s=zohoarc; b=eaYxiObzgY+UYohaTsl6qGc7V4C7k6mzNmSz5YbHN3d7C8XvHsRSU9eRQF9pdqvXWUhi6X7urmgj39VOd8S0S3OxJPnhAwNA2pmo8XObzik/6X7vePDWXk5XWTq++/HhdBqnSPxqsx2yr2BMXYfX/Sx0rfZ6GjpIxRdA8jukSww= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583245296; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Z7Ux+hft2bjNmRhZXzv82rPU0Rif6f5eByKMYnOSff8=; b=n4+PME46WL/Bzuht1CU6GMb+T2OuKpjS1X/yoi6RB8hNAOlAoAoe1KAu/Ew3FzHECY3lCQTwc/TPVX7qki1EVLGvxn3gTr3RuYKr3PLQeMwfDXbbxWvdRlvCe/z01m4Va+mAPHuK852WipOgcbH3hAjLdwbxf9WDVoWy1q2/VF0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1583245296445247.58109920890297; Tue, 3 Mar 2020 06:21:36 -0800 (PST) Received: from localhost ([::1]:47994 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j98QR-0003px-Av for importer@patchew.org; Tue, 03 Mar 2020 09:21:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34135) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j98PO-0001qU-Hh for qemu-devel@nongnu.org; Tue, 03 Mar 2020 09:20:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j98PN-0006H7-5m for qemu-devel@nongnu.org; Tue, 03 Mar 2020 09:20:30 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:24510 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j98PN-0006Gy-1l for qemu-devel@nongnu.org; Tue, 03 Mar 2020 09:20:29 -0500 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-216-6pLxu-cWPzyl-8a30pbqfQ-1; Tue, 03 Mar 2020 09:20:27 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 32D82100550E; Tue, 3 Mar 2020 14:20:26 +0000 (UTC) Received: from t480s.redhat.com (ovpn-117-113.ams2.redhat.com [10.36.117.113]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E50E60BE1; Tue, 3 Mar 2020 14:20:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583245228; h=from:from: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: in-reply-to:in-reply-to:references:references; bh=Z7Ux+hft2bjNmRhZXzv82rPU0Rif6f5eByKMYnOSff8=; b=KGeluI6SsrNhXiN+lsJn52yhsWb/RUPj4jIiEjRjQrKCcvl/FNkn4bhqMyrh5q61j//Q9I rg0VsQ5vkgQDJcTbtbH3QolSQ3/Wi8QSrX1dKc+M3AxaDSCyuyv9Mma60Ve+kAo6GqSgZ9 jAqotaSyo+sA3sRXzcgAp2AVabt2tps= X-MC-Unique: 6pLxu-cWPzyl-8a30pbqfQ-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH RFC 3/4] memory: Add region_resize() callback to memory notifier Date: Tue, 3 Mar 2020 15:19:38 +0100 Message-Id: <20200303141939.352319-4-david@redhat.com> In-Reply-To: <20200303141939.352319-1-david@redhat.com> References: <20200303141939.352319-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , David Hildenbrand , "Dr . David Alan Gilbert" , Peter Xu , Igor Mammedov , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Let's provide a way for memory notifiers to get notified about a resize. If the region_resize() callback is not implemented by a notifier, we mimic the old behavior by removing the old section and adding the new, resized section. This callback is helpful when backends (like KVM) want to implement atomic resizes of memory sections (e.g., resize while VCPUs are running and using the section). For now, we won't bother about a resize() callback for coalesced MMIO regions. The main future use case is for virtio-mem to resize ram memory regions while the guest is running. Cc: Richard Henderson Cc: Paolo Bonzini Cc: "Dr. David Alan Gilbert" Cc: Eduardo Habkost Cc: Marcel Apfelbaum Cc: Igor Mammedov Signed-off-by: David Hildenbrand --- include/exec/memory.h | 18 +++++++++++ memory.c | 72 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 85 insertions(+), 5 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 74805dd448..704eb64d75 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -492,6 +492,24 @@ struct MemoryListener { */ void (*region_nop)(MemoryListener *listener, MemoryRegionSection *sect= ion); =20 + /** + * @region_resize: + * + * Called during an address space update transaction, + * for a section of the address space that is in the same place in the + * address space as in the last transaction, however, the size changed. + * Dirty memory logging can change as well. + * + * Note: If this callback is not implemented, the resize is communicat= ed + * via a region_del(), followed by a region_add() instead. + * + * @listener: The #MemoryListener. + * @section: The old #MemoryRegionSection. + * @new: The new size. + */ + void (*region_resize)(MemoryListener *listener, + MemoryRegionSection *section, Int128 new); + /** * @log_start: * diff --git a/memory.c b/memory.c index 09be40edd2..097b0db0e4 100644 --- a/memory.c +++ b/memory.c @@ -246,6 +246,17 @@ static bool flatrange_equal(FlatRange *a, FlatRange *b) && a->nonvolatile =3D=3D b->nonvolatile; } =20 +static bool flatrange_resized(FlatRange *a, FlatRange *b) +{ + return a->mr =3D=3D b->mr + && int128_eq(a->addr.start, b->addr.start) + && int128_ne(a->addr.size, b->addr.size) + && a->offset_in_region =3D=3D b->offset_in_region + && a->romd_mode =3D=3D b->romd_mode + && a->readonly =3D=3D b->readonly + && a->nonvolatile =3D=3D b->nonvolatile; +} + static FlatView *flatview_new(MemoryRegion *mr_root) { FlatView *view; @@ -887,6 +898,45 @@ static void flat_range_coalesced_io_add(FlatRange *fr,= AddressSpace *as) } } =20 +static void memory_listener_resize_region(FlatRange *fr, AddressSpace *as, + Int128 new, bool adding) +{ + FlatView *as_view =3D address_space_to_flatview(as); + MemoryRegionSection old_mrs =3D section_from_flat_range(fr, as_view); + MemoryRegionSection new_mrs =3D old_mrs; + MemoryListener *listener; + + new_mrs.size =3D new; + + if (adding) { + QTAILQ_FOREACH(listener, &as->listeners, link_as) { + if (listener->region_resize) { + /* Grow in the adding phase. */ + if (int128_lt(fr->addr.size, new)) { + listener->region_resize(listener, &old_mrs, new); + } + continue; + } + if (listener->region_add) { + listener->region_add(listener, &new_mrs); + } + } + } else { + QTAILQ_FOREACH_REVERSE(listener, &as->listeners, link_as) { + if (listener->region_resize) { + /* Shrink in the removal phase. */ + if (int128_gt(fr->addr.size, new)) { + listener->region_resize(listener, &old_mrs, new); + } + continue; + } + if (listener->region_del) { + listener->region_del(listener, &old_mrs); + } + } + } +} + static void address_space_update_topology_pass(AddressSpace *as, const FlatView *old_view, const FlatView *new_view, @@ -911,11 +961,23 @@ static void address_space_update_topology_pass(Addres= sSpace *as, frnew =3D NULL; } =20 - if (frold - && (!frnew - || int128_lt(frold->addr.start, frnew->addr.start) - || (int128_eq(frold->addr.start, frnew->addr.start) - && !flatrange_equal(frold, frnew)))) { + if (frold && frnew && flatrange_resized(frold, frnew)) { + /* In both and only the size (+ eventually logging) changed. */ + + memory_listener_resize_region(frold, as, frnew->addr.size, + adding); + if (adding) { + flat_range_coalesced_io_add(frnew, as); + } else { + flat_range_coalesced_io_del(frold, as); + } + + ++iold; + ++inew; + } else if (frold && (!frnew + || int128_lt(frold->addr.start, frnew->addr.s= tart) + || (int128_eq(frold->addr.start, frnew->addr.= start) + && !flatrange_equal(frold, frnew)))) { /* In old but not in new, or in both but attributes changed. */ =20 if (!adding) { --=20 2.24.1 From nobody Thu Nov 13 21:52:16 2025 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583245367; cv=none; d=zohomail.com; s=zohoarc; b=Oi7qvKmfJTrmehnUrUGPd+73iBm4vyQsQhzxqpemeHt2usgzcLkqKYW9m33GkIlWyQlNPz6hnGm1fYtHuyftLFAxruy8OR6R64AJ4GEWXdvJkWPP0IcPYkYuMyN+YUWm6OrCUfmM+9HIFuTyLKZ8a60P/pD0C6fO61qBcWTqxIE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583245367; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fO4uZMYE82gtwCvsu4xnQfm16x7G0X5NKbdPHitYWJ0=; b=RcLuwZTQEW4N8dtHLozng5yhxC0a2n2a9CX35reL/O6jyCSdZrm6Ddn/8tJGTzJ1FeBm0Hieg1S814izGPpaeM7H6/OlGyqYpe7dqxBldjx/0AhE9pfO0uT+IZ47pNaWWnHKBdO4D63IHUXN5PXOWdJHncN4Dc1acfDtoen83nw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1583245367669611.6162385537809; Tue, 3 Mar 2020 06:22:47 -0800 (PST) Received: from localhost ([::1]:48014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j98Ra-00068J-Gi for importer@patchew.org; Tue, 03 Mar 2020 09:22:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34170) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j98PT-0001xd-HF for qemu-devel@nongnu.org; Tue, 03 Mar 2020 09:20:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j98PR-0006ID-Nz for qemu-devel@nongnu.org; Tue, 03 Mar 2020 09:20:35 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:50912 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j98PR-0006I8-Jh for qemu-devel@nongnu.org; Tue, 03 Mar 2020 09:20:33 -0500 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-356-VNP-6lTlN_axUtd7OtkI2Q-1; Tue, 03 Mar 2020 09:20:29 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8DC60107ACCA; Tue, 3 Mar 2020 14:20:28 +0000 (UTC) Received: from t480s.redhat.com (ovpn-117-113.ams2.redhat.com [10.36.117.113]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8279C60BE1; Tue, 3 Mar 2020 14:20:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583245233; 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=fO4uZMYE82gtwCvsu4xnQfm16x7G0X5NKbdPHitYWJ0=; b=iAib/YejvtQ24O64c8RWwGxlFxHmDXOpUF71I6uvRGKBsrbjdDtAHT/ieumuLY5Fgs7SvI B8/Pjttazn+9YfES8+XV1W/EKt3F2DiAp8XJBz1JsvkRIgZi4m2HTqKcMYNMA4D3e/ptd1 kkJ8KdbPKe4TH6RgFg0tXX09nOQRfpY= X-MC-Unique: VNP-6lTlN_axUtd7OtkI2Q-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH RFC 4/4] kvm: Implement atomic memory region resizes via region_resize() Date: Tue, 3 Mar 2020 15:19:39 +0100 Message-Id: <20200303141939.352319-5-david@redhat.com> In-Reply-To: <20200303141939.352319-1-david@redhat.com> References: <20200303141939.352319-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , kvm@vger.kernel.org, David Hildenbrand , "Dr . David Alan Gilbert" , Peter Xu , Igor Mammedov , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" virtio-mem wants to resize (esp. grow) ram memory regions while the guest is already aware of them and makes use of them. Resizing a KVM slot can only currently be done by removing it and re-adding it. While the kvm slot is temporarily removed, VCPUs that try to read from these slots will fault. But also, other ioctls might depend on all slots being in place. Let's inhibit most KVM ioctls while performing the resize. Once we have an ioctl that can perform atomic resizes (e.g., KVM_SET_USER_MEMORY_REGION extensions), we can make inhibiting optional at runtime. Also, make sure to hold the kvm_slots_lock while performing both actions (removing+re-adding). Note: Resizes of memory regions currently seems to happen during bootup only, so I don't think any existing RT users should be affected. Cc: Richard Henderson Cc: Paolo Bonzini Cc: "Dr. David Alan Gilbert" Cc: Eduardo Habkost Cc: Marcel Apfelbaum Cc: Igor Mammedov Cc: kvm@vger.kernel.org Signed-off-by: David Hildenbrand --- accel/kvm/kvm-all.c | 121 +++++++++++++++++++++++++++++++++++++++--- include/hw/core/cpu.h | 3 ++ 2 files changed, 117 insertions(+), 7 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 439a4efe52..bba58db098 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -149,6 +149,21 @@ bool kvm_msi_use_devid; static bool kvm_immediate_exit; static hwaddr kvm_max_slot_size =3D ~0; =20 +/* + * While holding this lock in write, no new KVM ioctls can be started, but + * kvm ioctl inhibitors will have to wait for existing ones to finish + * (indicated by cpu->in_ioctl and kvm_in_ioctl, both updated with this lo= ck + * held in read when entering the ioctl). + */ +pthread_rwlock_t kvm_ioctl_lock; +/* + * Atomic counter of active KVM ioctls except + * - The KVM ioctl inhibitor is doing an ioctl + * - kvm_ioctl(): Harmless and not interesting for inhibitors. + * - kvm_vcpu_ioctl(): Tracked via cpu->in_ioctl. + */ +static int kvm_in_ioctl; + static const KVMCapabilityInfo kvm_required_capabilites[] =3D { KVM_CAP_INFO(USER_MEMORY), KVM_CAP_INFO(DESTROY_MEMORY_REGION_WORKS), @@ -1023,6 +1038,7 @@ void kvm_set_max_memslot_size(hwaddr max_slot_size) kvm_max_slot_size =3D max_slot_size; } =20 +/* Called with KVMMemoryListener.slots_lock held */ static void kvm_set_phys_mem(KVMMemoryListener *kml, MemoryRegionSection *section, bool add) { @@ -1052,14 +1068,12 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, ram =3D memory_region_get_ram_ptr(mr) + section->offset_within_region + (start_addr - section->offset_within_address_space); =20 - kvm_slots_lock(kml); - if (!add) { do { slot_size =3D MIN(kvm_max_slot_size, size); mem =3D kvm_lookup_matching_slot(kml, start_addr, slot_size); if (!mem) { - goto out; + return; } if (mem->flags & KVM_MEM_LOG_DIRTY_PAGES) { kvm_physical_sync_dirty_bitmap(kml, section); @@ -1079,7 +1093,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, start_addr +=3D slot_size; size -=3D slot_size; } while (size); - goto out; + return; } =20 /* register the new slot */ @@ -1108,9 +1122,6 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, ram +=3D slot_size; size -=3D slot_size; } while (size); - -out: - kvm_slots_unlock(kml); } =20 static void kvm_region_add(MemoryListener *listener, @@ -1119,7 +1130,9 @@ static void kvm_region_add(MemoryListener *listener, KVMMemoryListener *kml =3D container_of(listener, KVMMemoryListener, l= istener); =20 memory_region_ref(section->mr); + kvm_slots_lock(kml); kvm_set_phys_mem(kml, section, true); + kvm_slots_unlock(kml); } =20 static void kvm_region_del(MemoryListener *listener, @@ -1127,10 +1140,68 @@ static void kvm_region_del(MemoryListener *listener, { KVMMemoryListener *kml =3D container_of(listener, KVMMemoryListener, l= istener); =20 + kvm_slots_lock(kml); kvm_set_phys_mem(kml, section, false); + kvm_slots_unlock(kml); memory_region_unref(section->mr); } =20 +/* + * Certain updates (e.g., resizing memory regions) require temporarily rem= oving + * kvm memory slots. Make sure any ioctl sees a consistent memory slot sta= te. + */ +static void kvm_ioctl_inhibit_begin(void) +{ + CPUState *cpu; + + /* + * We allow to inhibit only when holding the BQL, so we can identify + * when an inhibitor wants to issue an ioctl easily. + */ + g_assert(qemu_mutex_iothread_locked()); + + pthread_rwlock_wrlock(&kvm_ioctl_lock); + + /* Inhibiting happens rarely, we can keep things simple and spin here.= */ + while (true) { + bool any_cpu_in_ioctl =3D false; + + CPU_FOREACH(cpu) { + if (atomic_read(&cpu->in_ioctl)) { + any_cpu_in_ioctl =3D true; + qemu_cpu_kick(cpu); + } + } + if (!any_cpu_in_ioctl && !atomic_read(&kvm_in_ioctl)) { + break; + } + g_usleep(100); + } +} + +static void kvm_ioctl_inhibit_end(void) +{ + pthread_rwlock_unlock(&kvm_ioctl_lock); +} + +static void kvm_region_resize(MemoryListener *listener, + MemoryRegionSection *section, Int128 new) +{ + KVMMemoryListener *kml =3D container_of(listener, KVMMemoryListener, + listener); + MemoryRegionSection new_section =3D *section; + + new_section.size =3D new; + + kvm_slots_lock(kml); + /* Inhibit KVM ioctls while temporarily removing slots. */ + kvm_ioctl_inhibit_begin(); + kvm_set_phys_mem(kml, section, false); + kvm_set_phys_mem(kml, &new_section, true); + kvm_ioctl_inhibit_end(); + kvm_slots_unlock(kml); +} + static void kvm_log_sync(MemoryListener *listener, MemoryRegionSection *section) { @@ -1249,6 +1320,7 @@ void kvm_memory_listener_register(KVMState *s, KVMMem= oryListener *kml, =20 kml->listener.region_add =3D kvm_region_add; kml->listener.region_del =3D kvm_region_del; + kml->listener.region_resize =3D kvm_region_resize; kml->listener.log_start =3D kvm_log_start; kml->listener.log_stop =3D kvm_log_stop; kml->listener.log_sync =3D kvm_log_sync; @@ -1894,6 +1966,7 @@ static int kvm_init(MachineState *ms) assert(TARGET_PAGE_SIZE <=3D qemu_real_host_page_size); =20 s->sigmask_len =3D 8; + pthread_rwlock_init(&kvm_ioctl_lock, NULL); =20 #ifdef KVM_CAP_SET_GUEST_DEBUG QTAILQ_INIT(&s->kvm_sw_breakpoints); @@ -2304,6 +2377,34 @@ static void kvm_eat_signals(CPUState *cpu) } while (sigismember(&chkset, SIG_IPI)); } =20 +static void kvm_cpu_set_in_ioctl(CPUState *cpu, bool in_ioctl) +{ + if (unlikely(qemu_mutex_iothread_locked())) { + return; + } + if (in_ioctl) { + pthread_rwlock_rdlock(&kvm_ioctl_lock); + atomic_set(&cpu->in_ioctl, true); + pthread_rwlock_unlock(&kvm_ioctl_lock); + } else { + atomic_set(&cpu->in_ioctl, false); + } +} + +static void kvm_set_in_ioctl(bool in_ioctl) +{ + if (likely(qemu_mutex_iothread_locked())) { + return; + } + if (in_ioctl) { + pthread_rwlock_rdlock(&kvm_ioctl_lock); + atomic_inc(&kvm_in_ioctl); + pthread_rwlock_unlock(&kvm_ioctl_lock); + } else { + atomic_dec(&kvm_in_ioctl); + } +} + int kvm_cpu_exec(CPUState *cpu) { struct kvm_run *run =3D cpu->kvm_run; @@ -2488,7 +2589,9 @@ int kvm_vm_ioctl(KVMState *s, int type, ...) va_end(ap); =20 trace_kvm_vm_ioctl(type, arg); + kvm_set_in_ioctl(true); ret =3D ioctl(s->vmfd, type, arg); + kvm_set_in_ioctl(false); if (ret =3D=3D -1) { ret =3D -errno; } @@ -2506,7 +2609,9 @@ int kvm_vcpu_ioctl(CPUState *cpu, int type, ...) va_end(ap); =20 trace_kvm_vcpu_ioctl(cpu->cpu_index, type, arg); + kvm_cpu_set_in_ioctl(cpu, true); ret =3D ioctl(cpu->kvm_fd, type, arg); + kvm_cpu_set_in_ioctl(cpu, false); if (ret =3D=3D -1) { ret =3D -errno; } @@ -2524,7 +2629,9 @@ int kvm_device_ioctl(int fd, int type, ...) va_end(ap); =20 trace_kvm_device_ioctl(fd, type, arg); + kvm_set_in_ioctl(true); ret =3D ioctl(fd, type, arg); + kvm_set_in_ioctl(false); if (ret =3D=3D -1) { ret =3D -errno; } diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 73e9a869a4..4fbff6f3d7 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -431,6 +431,9 @@ struct CPUState { /* shared by kvm, hax and hvf */ bool vcpu_dirty; =20 + /* kvm only for now: CPU is in kvm_vcpu_ioctl() (esp. KVM_RUN) */ + bool in_ioctl; + /* Used to keep track of an outstanding cpu throttle thread for migrat= ion * autoconverge */ --=20 2.24.1