From nobody Sat May 18 11:26:02 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=1666570064; cv=none; d=zohomail.com; s=zohoarc; b=CoK9RJlEEN8pz9Yi+c70QGZBivwnKWtUNg8JYo1yW04tmSsFlloU1F5ivlxJohjFBcdwjq7L2AonRNoh/r2HRPZuhoW/S4qAklcXBx0CpzFA86mqWVnmJBdIfYKABSy1gA/YgBhO4EqWHvM1ICSarMpPcjxSd4mVUyEmAs/3B8k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666570064; 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=uNjRaph9W6dgO7kgHkY9avmuf/bCsD1foX0HoT0P6sA=; b=i+/UQCaO33VI5CFf2NUdgEGJAFSzuVhBMkudSybYjKFvNJ71P2lSeKLmB/UVJPgApTWxkJ7mJs6oWCmVn9x5IsXWdTvALj5JfrFGNECJWutV24Ul2ZXQlZRqQQgYyv/dpWFrhN5dI88gGWDvpMAZqvOadSB6yPGzvFbSeneL2Xw= 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 1666570064234181.73546208516143; Sun, 23 Oct 2022 17:07:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1omi7K-0006V0-H7 for importer@patchew.org; Sun, 23 Oct 2022 17:02:46 -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 1omGjh-0002Sx-2M for qemu-devel@nongnu.org; Sat, 22 Oct 2022 11:48:33 -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 1omGjf-00084y-CX for qemu-devel@nongnu.org; Sat, 22 Oct 2022 11:48:32 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-147-FWE20gQhOru02AGSyFIP0Q-1; Sat, 22 Oct 2022 11:48:27 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C69DF38060EC; Sat, 22 Oct 2022 15:48:26 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8737D40C6E15; Sat, 22 Oct 2022 15:48:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666453709; 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=uNjRaph9W6dgO7kgHkY9avmuf/bCsD1foX0HoT0P6sA=; b=W8VxXgbXmx8D2Ek9OMiV4dFwGS8Dnlqnb5r3BecVfiS3uD28qZIKSUO8fiV5K0grcoTEb4 fljepOdX3Qd6PwR7DoDkUY0HMvdEHJM4I+2WEu4GUFmY/A37aKsx8f9JHR+jESlGLFwFy9 WO2PxAlZXEVf//bxgWD23GQVL3PaU24= X-MC-Unique: FWE20gQhOru02AGSyFIP0Q-1 From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Maxim Levitsky , "Michael S. Tsirkin" , Cornelia Huck , David Hildenbrand , kvm@vger.kernel.org, Emanuele Giuseppe Esposito Subject: [PATCH 1/2] linux-headers/linux/kvm.h: introduce kvm_userspace_memory_region_list ioctl Date: Sat, 22 Oct 2022 11:48:22 -0400 Message-Id: <20221022154823.1823193-2-eesposit@redhat.com> In-Reply-To: <20221022154823.1823193-1-eesposit@redhat.com> References: <20221022154823.1823193-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.251, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666570065020100001 Content-Type: text/plain; charset="utf-8" Introduce new KVM_KICK_ALL_RUNNING_VCPUS and KVM_RESUME_ALL_KICKED_VCPUS ioctl that will be used respectively to pause and then resume all vcpus currently executing KVM_RUN in kvm. Signed-off-by: Emanuele Giuseppe Esposito --- linux-headers/linux/kvm.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index f089349149..1fcf69f903 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -2067,4 +2067,7 @@ struct kvm_stats_desc { /* Available with KVM_CAP_XSAVE2 */ #define KVM_GET_XSAVE2 _IOR(KVMIO, 0xcf, struct kvm_xsave) =20 +#define KVM_KICK_ALL_RUNNING_VCPUS _IO(KVMIO, 0xd2) +#define KVM_RESUME_ALL_KICKED_VCPUS _IO(KVMIO, 0xd3) + #endif /* __LINUX_KVM_H */ --=20 2.31.1 From nobody Sat May 18 11:26:02 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=1666591151; cv=none; d=zohomail.com; s=zohoarc; b=QfG6Lj26wmXMNxASNFliVX/VhUP/ASkhXh05AIgarXjEkX6rgyqpWbjYqw6rCJek1v61VYHwqVJWt5wmwCifzekeAM4eJz8ETaFTGqAS+Orf7gXH4lSnjPR5G3bixpwS9O+EkPbsRajtYyVKZ1X3tMcPvPQ2t08/VnByrMe8KiQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666591151; 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=6dbzyM+9g9fjSLtaxfcxeYNDxW4iMiSOGFthjgPIStQ=; b=XWumI0Fee/hYqMQiKQmJx9WDK16anH60Sao8B6hc7Mu2Ppvv8q73LHZJBVrwLzRhEdrUneuKfEqB3lNcFiV4sfim3CtFk5tu2sWdBAgdakCtymWtyFc97Z6nR1ruj7AAWlYgqA1uL12EWwGiyreulzPkyzsudbTWYo4JeDNNylo= 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 1666591151981527.3257503598926; Sun, 23 Oct 2022 22:59:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1omi9k-0006tK-P5 for importer@patchew.org; Sun, 23 Oct 2022 17:05:16 -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 1omGji-0002TC-Ge for qemu-devel@nongnu.org; Sat, 22 Oct 2022 11:48:35 -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 1omGjg-0008LN-Vl for qemu-devel@nongnu.org; Sat, 22 Oct 2022 11:48:34 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-177-UIIhHk5sP4-sgGnYe7LgDA-1; Sat, 22 Oct 2022 11:48:28 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2EAA5811E75; Sat, 22 Oct 2022 15:48:28 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id CEC8140C6E14; Sat, 22 Oct 2022 15:48:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666453712; 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=6dbzyM+9g9fjSLtaxfcxeYNDxW4iMiSOGFthjgPIStQ=; b=ZCmUJx7v/yKmnw7jPuEawHltPsjwKyjkyfMVxz4HnvMwm7WMKCxPPE/5LvwTCERw8DbMSu R+eeQLSaxD6Wd9MtGZqXsmmiMB8FOk1PBOvl22z+ozkt3shcmfamGrO0kCgI/Lo6t19BTv xZGh6pANAP0fWVeqH2anLHJX7hJfuiU= X-MC-Unique: UIIhHk5sP4-sgGnYe7LgDA-1 From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Maxim Levitsky , "Michael S. Tsirkin" , Cornelia Huck , David Hildenbrand , kvm@vger.kernel.org, Emanuele Giuseppe Esposito Subject: [PATCH 2/2] accel/kvm: introduce begin/commit listener callbacks Date: Sat, 22 Oct 2022 11:48:23 -0400 Message-Id: <20221022154823.1823193-3-eesposit@redhat.com> In-Reply-To: <20221022154823.1823193-1-eesposit@redhat.com> References: <20221022154823.1823193-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.251, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666591154346100001 Content-Type: text/plain; charset="utf-8" These callback make sure that all vcpus are blocked before performing memslot updates, and resumed once we are finished. They rely on kvm support for KVM_KICK_ALL_RUNNING_VCPUS and KVM_RESUME_ALL_KICKED_VCPUS ioctls to respectively pause and resume all vcpus that are in KVM_RUN state. Signed-off-by: Emanuele Giuseppe Esposito --- accel/kvm/kvm-all.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 645f0a249a..bd0dfa8613 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -178,6 +178,8 @@ bool kvm_has_guest_debug; int kvm_sstep_flags; static bool kvm_immediate_exit; static hwaddr kvm_max_slot_size =3D ~0; +static QemuEvent mem_transaction_proceed; + =20 static const KVMCapabilityInfo kvm_required_capabilites[] =3D { KVM_CAP_INFO(USER_MEMORY), @@ -1523,6 +1525,38 @@ static void kvm_region_del(MemoryListener *listener, memory_region_unref(section->mr); } =20 +static void kvm_begin(MemoryListener *listener) +{ + KVMState *s =3D kvm_state; + + /* + * Make sure BQL is taken so cpus in kvm_cpu_exec that just exited from + * KVM_RUN do not continue, since many run->exit_reason take it anyway= s. + */ + assert(qemu_mutex_iothread_locked()); + + /* + * Stop incoming cpus that want to execute KVM_RUN from running. + * Makes cpus calling qemu_event_wait() in kvm_cpu_exec() block. + */ + qemu_event_reset(&mem_transaction_proceed); + + /* Ask KVM to stop all vcpus that are currently running KVM_RUN */ + kvm_vm_ioctl(s, KVM_KICK_ALL_RUNNING_VCPUS); +} + +static void kvm_commit(MemoryListener *listener) +{ + KVMState *s =3D kvm_state; + assert(qemu_mutex_iothread_locked()); + + /* Ask KVM to resume all vcpus that are currently blocked in KVM_RUN */ + kvm_vm_ioctl(s, KVM_RESUME_ALL_KICKED_VCPUS); + + /* Resume cpus waiting in qemu_event_wait() in kvm_cpu_exec() */ + qemu_event_set(&mem_transaction_proceed); +} + static void kvm_log_sync(MemoryListener *listener, MemoryRegionSection *section) { @@ -1668,6 +1702,8 @@ void kvm_memory_listener_register(KVMState *s, KVMMem= oryListener *kml, kml->listener.region_del =3D kvm_region_del; kml->listener.log_start =3D kvm_log_start; kml->listener.log_stop =3D kvm_log_stop; + kml->listener.begin =3D kvm_begin; + kml->listener.commit =3D kvm_commit; kml->listener.priority =3D 10; kml->listener.name =3D name; =20 @@ -2611,6 +2647,7 @@ static int kvm_init(MachineState *ms) } =20 kvm_state =3D s; + qemu_event_init(&mem_transaction_proceed, false); =20 ret =3D kvm_arch_init(ms, s); if (ret < 0) { @@ -2875,6 +2912,19 @@ int kvm_cpu_exec(CPUState *cpu) } =20 qemu_mutex_unlock_iothread(); + + /* + * Wait that a running memory transaction (memslot update) is conclude= d. + * + * If the event state is EV_SET, it means kvm_commit() has already fin= ished + * and called qemu_event_set(), therefore cpu can execute. + * + * If it's EV_FREE, it means kvm_begin() has already called + * qemu_event_reset(), therefore a memory transaction is happening and= the + * cpu must wait. + */ + qemu_event_wait(&mem_transaction_proceed); + cpu_exec_start(cpu); =20 do { --=20 2.31.1