From nobody Fri May 10 15:18:18 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16274972330371005.0106748416028; Wed, 28 Jul 2021 11:33:53 -0700 (PDT) Received: from localhost ([::1]:34882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m8oNL-0000Bg-Ai for importer@patchew.org; Wed, 28 Jul 2021 14:33:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53488) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m8oLf-0005qh-WB for qemu-devel@nongnu.org; Wed, 28 Jul 2021 14:32:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:43879) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m8oLc-0006zp-63 for qemu-devel@nongnu.org; Wed, 28 Jul 2021 14:32:06 -0400 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-276-jy3wCNUrNEOccmUYJzBpKw-1; Wed, 28 Jul 2021 14:31:58 -0400 Received: by mail-qk1-f200.google.com with SMTP id 13-20020a370e0d0000b02903a5eee61155so2166145qko.9 for ; Wed, 28 Jul 2021 11:31:58 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-65-184-144-111-238.dsl.bell.ca. [184.144.111.238]) by smtp.gmail.com with ESMTPSA id n5sm417528qkp.116.2021.07.28.11.31.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 11:31:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627497121; 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=PToPelZrDy393gYxKc24vHrF2ftEKJxS7b4elQKZrGw=; b=TzgPsl5G60Xe0NDEXal8ePcHchSQDHN94YVD4oXtYa6pM0n9VfCAEnnqKaE84DcZYdgjMM F4wxB4yf/le7brixIKoUoD5zFQV12oq7xU+4Ii2B/e622sXA34WLQqDA6uFxotG7yH7xzU vnwiZPc4jLSeyB5ZfUN9wNlrkGnZV44= X-MC-Unique: jy3wCNUrNEOccmUYJzBpKw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PToPelZrDy393gYxKc24vHrF2ftEKJxS7b4elQKZrGw=; b=WqPHeljzRWhEcPKWgs/BtBImgAnJzosKTZt8XaDecKJgNXuR/dRaPyv5GceOHbdeL+ iB0dWCqBDB56/DleVTVMnBvYfzWGyVzMc6TMLTsXmu/BaEHi4fvakAPkrKT2NwksU1Ap pmeS/FtZgyODK0o+utzrG5De/QWIuFqGim9y5Sa3KkTgkj2P7YDv2bsNcBUDn5wREO3G CDppY37RG6A7w4b6EtaX5OxsHDQvPeDzQFP3+Byo53u/HmT8USguMZJoAqWnWLXhWGMa npAuOo15nlCpk60PwCfw7HkSHy/AzsHkXx7adFFZn6FglC1Ztjr36NfaCWntwr13GZq2 lvKg== X-Gm-Message-State: AOAM533r9LILF+bx9BGF/eN8Du6wWOXxtzSpyHsZXbicCSiuJwLD+mTu ywNw5ixFCj32TqrecpRUUNkTvavkbG1Z6KI2J+WC7GGe6dfhMmGsB1lNKiQXvGjmY/6OY5lDFrr Nhe5gheGV3r/nZmEXNo27CofTCBntYd+4N858Jvlh8lTfRZFqNrcwQ3KAY/0ik90Y X-Received: by 2002:a05:622a:283:: with SMTP id z3mr848286qtw.312.1627497117392; Wed, 28 Jul 2021 11:31:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRYZ1PzRkY+wrj568q7uy5hPCl2ndE7Rkhek9jtRYc5CTKoeHIYGHB4bOLgegb9WnxNSm0rg== X-Received: by 2002:a05:622a:283:: with SMTP id z3mr848260qtw.312.1627497117100; Wed, 28 Jul 2021 11:31:57 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v3 1/8] cpus: Export queue work related fields to cpu.h Date: Wed, 28 Jul 2021 14:31:44 -0400 Message-Id: <20210728183151.195139-2-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210728183151.195139-1-peterx@redhat.com> References: <20210728183151.195139-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.719, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , peterx@redhat.com, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1627497235380100001 Content-Type: text/plain; charset="utf-8" This patch has no functional change, but prepares for moving the function do_run_on_cpu() into softmmu/cpus.c. It does: 1. Move qemu_work_item into hw/core/cpu.h. 2. Export queue_work_on_cpu()/qemu_work_cond. All of them will be used by softmmu/cpus.c later. Reviewed-by: David Hildenbrand Signed-off-by: Peter Xu Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- cpus-common.c | 11 ++--------- include/hw/core/cpu.h | 10 +++++++++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cpus-common.c b/cpus-common.c index 6e73d3e58d..d814b2439a 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -27,7 +27,7 @@ static QemuMutex qemu_cpu_list_lock; static QemuCond exclusive_cond; static QemuCond exclusive_resume; -static QemuCond qemu_work_cond; +QemuCond qemu_work_cond; =20 /* >=3D 1 if a thread is inside start_exclusive/end_exclusive. Written * under qemu_cpu_list_lock, read with atomic operations. @@ -114,14 +114,7 @@ CPUState *qemu_get_cpu(int index) /* current CPU in the current thread. It is only valid inside cpu_exec() */ __thread CPUState *current_cpu; =20 -struct qemu_work_item { - QSIMPLEQ_ENTRY(qemu_work_item) node; - run_on_cpu_func func; - run_on_cpu_data data; - bool free, exclusive, done; -}; - -static void queue_work_on_cpu(CPUState *cpu, struct qemu_work_item *wi) +void queue_work_on_cpu(CPUState *cpu, struct qemu_work_item *wi) { qemu_mutex_lock(&cpu->work_mutex); QSIMPLEQ_INSERT_TAIL(&cpu->work_list, wi, node); diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index bc864564ce..f62ae88524 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -243,7 +243,15 @@ typedef union { =20 typedef void (*run_on_cpu_func)(CPUState *cpu, run_on_cpu_data data); =20 -struct qemu_work_item; +struct qemu_work_item { + QSIMPLEQ_ENTRY(qemu_work_item) node; + run_on_cpu_func func; + run_on_cpu_data data; + bool free, exclusive, done; +}; + +void queue_work_on_cpu(CPUState *cpu, struct qemu_work_item *wi); +extern QemuCond qemu_work_cond; =20 #define CPU_UNSET_NUMA_NODE_ID -1 #define CPU_TRACE_DSTATE_MAX_EVENTS 32 --=20 2.31.1 From nobody Fri May 10 15:18:18 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162749730108512.37089075807853; Wed, 28 Jul 2021 11:35:01 -0700 (PDT) Received: from localhost ([::1]:37270 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m8oOR-0001oV-M9 for importer@patchew.org; Wed, 28 Jul 2021 14:34:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53524) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m8oLg-0005sp-Vg for qemu-devel@nongnu.org; Wed, 28 Jul 2021 14:32:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53300) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m8oLc-00074q-Un for qemu-devel@nongnu.org; Wed, 28 Jul 2021 14:32:08 -0400 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-75-faFzZJVvNfGWDLA-mM0iSQ-1; Wed, 28 Jul 2021 14:32:02 -0400 Received: by mail-qk1-f200.google.com with SMTP id 18-20020a05620a0792b02903b8e915ccceso2130557qka.18 for ; Wed, 28 Jul 2021 11:31:59 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-65-184-144-111-238.dsl.bell.ca. [184.144.111.238]) by smtp.gmail.com with ESMTPSA id n5sm417528qkp.116.2021.07.28.11.31.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 11:31:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627497124; 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=BnurmMofQyRZNu14FFqXtCfqMjzhNHVTjd0gZ+853yw=; b=Xos9/UgoVWLRYDAPOcGCq5Z8FP13pjy1a9eXGYtSbdTvLIqA/Dcr0alZcNJ46g835VFhnD IDO4H0tpBz9q+jK5QwJ7kfn/U/KZmBU+eJ4NHc8RpcoBk9oHy6lzn+LryDwkX1aWizP6TJ 3/3d7kITlQOHFEgnGuUP+AnOg+NlInc= X-MC-Unique: faFzZJVvNfGWDLA-mM0iSQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BnurmMofQyRZNu14FFqXtCfqMjzhNHVTjd0gZ+853yw=; b=hpraokv5FLNgheWOcuLOOk4oexafVJZQUDlIedSDQp0ieRkGWq33NZLve4aT0C1VGy lzcj+03cbig0ppwn8hk3nPcDNETVzX98n1Ar5m3mJ1H1BbaI8W8NmT1+LVnSYP8vJoks eslNv6pmzo9781ufjN8H8XQ2bt6z+s5fq2tvJMpZhK3/AHBCwlswjyFfAlXLF3RRDBtk oCCWiGdyx4Vs0f5Kzs1P7wqRrAWJ/TPZinGepoafA1AezCOXt4/8fqynrjZwKjzmlNP7 PniIcvj9O9zkSxoJqDjYRIQ6eoi091YsZcrBIzZMjUvGT6nGnKA0T5zTyh8r8yg6HZgo Vafg== X-Gm-Message-State: AOAM531NGrA9egK+SmurQyecjycSQqO9A1dIFJGsdtNC+NlEzWBU+QDG 8n8jsAbkA9KqLQMaD6j+837SBGo0YAkBmiQImyzATNv9aCdGx1G0Udmn9cS0b8xklxhOltBSntV aEfftoY5kqjk+2zUBy1DkAFC7SuqT4BH9n12Y7CFHkGnRwgE8KLxztus+G1JiKpOu X-Received: by 2002:a37:a8d3:: with SMTP id r202mr1059759qke.216.1627497118782; Wed, 28 Jul 2021 11:31:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFSZrLLzcNQAimKCszO+vO5fYfQGD92Z0QKhwVg1n1nZ1IpsNLzIpBh88oDBm8uXCBR9BSzQ== X-Received: by 2002:a37:a8d3:: with SMTP id r202mr1059726qke.216.1627497118508; Wed, 28 Jul 2021 11:31:58 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v3 2/8] cpus: Move do_run_on_cpu into softmmu/cpus.c Date: Wed, 28 Jul 2021 14:31:45 -0400 Message-Id: <20210728183151.195139-3-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210728183151.195139-1-peterx@redhat.com> References: <20210728183151.195139-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.719, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , peterx@redhat.com, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1627497301732100001 Content-Type: text/plain; charset="utf-8" It's only used by softmmu binaries not linux-user ones. Make it static and drop the definition in the header too. Since at it, initialize variable "wi" with less loc. Reviewed-by: David Hildenbrand Signed-off-by: Peter Xu Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- cpus-common.c | 25 ------------------------- include/hw/core/cpu.h | 12 ------------ softmmu/cpus.c | 23 +++++++++++++++++++++++ 3 files changed, 23 insertions(+), 37 deletions(-) diff --git a/cpus-common.c b/cpus-common.c index d814b2439a..670826363f 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -124,31 +124,6 @@ void queue_work_on_cpu(CPUState *cpu, struct qemu_work= _item *wi) qemu_cpu_kick(cpu); } =20 -void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data da= ta, - QemuMutex *mutex) -{ - struct qemu_work_item wi; - - if (qemu_cpu_is_self(cpu)) { - func(cpu, data); - return; - } - - wi.func =3D func; - wi.data =3D data; - wi.done =3D false; - wi.free =3D false; - wi.exclusive =3D false; - - queue_work_on_cpu(cpu, &wi); - while (!qatomic_mb_read(&wi.done)) { - CPUState *self_cpu =3D current_cpu; - - qemu_cond_wait(&qemu_work_cond, mutex); - current_cpu =3D self_cpu; - } -} - void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data= data) { struct qemu_work_item *wi; diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index f62ae88524..711ecad62f 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -689,18 +689,6 @@ void qemu_cpu_kick(CPUState *cpu); */ bool cpu_is_stopped(CPUState *cpu); =20 -/** - * do_run_on_cpu: - * @cpu: The vCPU to run on. - * @func: The function to be executed. - * @data: Data to pass to the function. - * @mutex: Mutex to release while waiting for @func to run. - * - * Used internally in the implementation of run_on_cpu. - */ -void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data da= ta, - QemuMutex *mutex); - /** * run_on_cpu: * @cpu: The vCPU to run on. diff --git a/softmmu/cpus.c b/softmmu/cpus.c index 071085f840..49e0368438 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -382,6 +382,29 @@ void qemu_init_cpu_loop(void) qemu_thread_get_self(&io_thread); } =20 +static void +do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data, + QemuMutex *mutex) +{ + struct qemu_work_item wi =3D { + .func =3D func, + .data =3D data, + }; + + if (qemu_cpu_is_self(cpu)) { + func(cpu, data); + return; + } + + queue_work_on_cpu(cpu, &wi); + while (!qatomic_mb_read(&wi.done)) { + CPUState *self_cpu =3D current_cpu; + + qemu_cond_wait(&qemu_work_cond, mutex); + current_cpu =3D self_cpu; + } +} + void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data) { do_run_on_cpu(cpu, func, data, &qemu_global_mutex); --=20 2.31.1 From nobody Fri May 10 15:18:18 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1627497235503147.87217098635665; Wed, 28 Jul 2021 11:33:55 -0700 (PDT) Received: from localhost ([::1]:35014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m8oNO-0000HZ-DV for importer@patchew.org; Wed, 28 Jul 2021 14:33:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53522) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m8oLg-0005sM-Is for qemu-devel@nongnu.org; Wed, 28 Jul 2021 14:32:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:33927) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m8oLc-00073H-8O for qemu-devel@nongnu.org; Wed, 28 Jul 2021 14:32:08 -0400 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-49--Suu1hjnMXeEd_taNQ7YGQ-1; Wed, 28 Jul 2021 14:32:02 -0400 Received: by mail-qv1-f69.google.com with SMTP id v16-20020a0562140510b029032511e85975so2424007qvw.23 for ; Wed, 28 Jul 2021 11:32:01 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-65-184-144-111-238.dsl.bell.ca. [184.144.111.238]) by smtp.gmail.com with ESMTPSA id n5sm417528qkp.116.2021.07.28.11.31.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 11:31:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627497123; 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=cv//UpWaAePYoX9vAmEeSqOa6nYsBvCOheG0gcBITT0=; b=bVo/9MfWW/CfooNM8tNRP+Vp01evH0FkZmejkL7T67IYyg1u/7Y9Imus7StHY6QyhsJs/H Ch92gqcsngZ2+Uadw0RA38mLsTjM94OzORHQL3P/Uj5UcpYXHnlTwMxAesgpzK98mGUpHU qJXTWVal3SbfOY3GnwobmzbEfJjtygo= X-MC-Unique: -Suu1hjnMXeEd_taNQ7YGQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cv//UpWaAePYoX9vAmEeSqOa6nYsBvCOheG0gcBITT0=; b=ODGaO+7/DDKehS0xp0zevZyTH48xR879Y8hWqfkHEQzpzxgPALaunFqeQJipNzTWP2 yOBPRNz0jZLQo4EalYK8gAxnjyZaLDc9XtsYjIQVa2OV5Wrntu22JvqYylq+eIS3vqzS hHZ6N9OquHUQQ2udzsQ2oUlHCCXgBXxIsi9sf7j5675xwoaeWO3XVtXMTXekCZ0ORnmE pLTxMnQnJ+lE5e0AlBvfYW7mtNXg5liwPe/+jEu8e8bUU53xJzg3LvGZip2r0+7U2qcg PXEnlgWF9UIveIVKEh7oGYi0fwba4jAYghsYU+prKW+BT7miS9LxQF+zXzAXjaxZFSq6 OZDg== X-Gm-Message-State: AOAM533Z5/IuL2b0bh0s+lZH3mmLPbvfAxkcKQdDImNvloa0kl+nt3xK MJGS6FSVK0fnHdFJ8ZErbfIPptyLXA3Tclg7OLuaomI951DGdt7JT4KxciFtY1rhblsVvKwBLtt nBGOzaaaE6x2LBdUoh5QVbAHbeiDX6VwE/2qCpyAtGzw98ny+bIzngIAB7HjmWqgq X-Received: by 2002:a37:e15:: with SMTP id 21mr1082172qko.184.1627497120153; Wed, 28 Jul 2021 11:32:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFNq9xBhqGgHL2NL9jbxxACJukPayGvMwPXlAz4MAKETMuQPXBw428TOxc9IhjFOmyhkje0A== X-Received: by 2002:a37:e15:: with SMTP id 21mr1082140qko.184.1627497119883; Wed, 28 Jul 2021 11:31:59 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v3 3/8] memory: Introduce memory_region_transaction_depth_{inc|dec}() Date: Wed, 28 Jul 2021 14:31:46 -0400 Message-Id: <20210728183151.195139-4-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210728183151.195139-1-peterx@redhat.com> References: <20210728183151.195139-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.719, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , peterx@redhat.com, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1627497237598100001 Content-Type: text/plain; charset="utf-8" memory_region_transaction_{begin|commit}() could be too big when finalizing= a memory region. E.g., we should never attempt to update address space topol= ogy during the finalize() of a memory region. Provide helpers for further use. Signed-off-by: Peter Xu Reviewed-by: David Hildenbrand --- softmmu/memory.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/softmmu/memory.c b/softmmu/memory.c index bfedaf9c4d..725d57ec17 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1079,10 +1079,20 @@ static void address_space_update_topology(AddressSp= ace *as) address_space_set_flatview(as); } =20 +static void memory_region_transaction_depth_inc(void) +{ + memory_region_transaction_depth++; +} + +static void memory_region_transaction_depth_dec(void) +{ + memory_region_transaction_depth--; +} + void memory_region_transaction_begin(void) { qemu_flush_coalesced_mmio_buffer(); - ++memory_region_transaction_depth; + memory_region_transaction_depth_inc(); } =20 void memory_region_transaction_commit(void) @@ -1092,7 +1102,7 @@ void memory_region_transaction_commit(void) assert(memory_region_transaction_depth); assert(qemu_mutex_iothread_locked()); =20 - --memory_region_transaction_depth; + memory_region_transaction_depth_dec(); if (!memory_region_transaction_depth) { if (memory_region_update_pending) { flatviews_reset(); --=20 2.31.1 From nobody Fri May 10 15:18:18 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1627497377239414.0360366770716; Wed, 28 Jul 2021 11:36:17 -0700 (PDT) Received: from localhost ([::1]:43364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m8oPg-0005w1-70 for importer@patchew.org; Wed, 28 Jul 2021 14:36:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53536) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m8oLh-0005ty-QK for qemu-devel@nongnu.org; Wed, 28 Jul 2021 14:32:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58103) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m8oLd-00074t-2M for qemu-devel@nongnu.org; Wed, 28 Jul 2021 14:32:09 -0400 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-79-mSwf1zMhMZitO-rm1cr_UQ-1; Wed, 28 Jul 2021 14:32:03 -0400 Received: by mail-qk1-f199.google.com with SMTP id b9-20020a05620a1269b02903b8bd5c7d95so2159204qkl.12 for ; Wed, 28 Jul 2021 11:32:03 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-65-184-144-111-238.dsl.bell.ca. [184.144.111.238]) by smtp.gmail.com with ESMTPSA id n5sm417528qkp.116.2021.07.28.11.32.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 11:32:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627497124; 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=9ZYp/arNlLB7CqHGh2xkLop1S0WBzyFyzBFrA9ouUuQ=; b=e5iMZo77op+On9Vk43O5u4lJGVL9/WAWoZW7Th9LmyE9BCOV7rMLOQSI+9+3AJSu9B+WH+ jfNzMjGWDiVykYoVugy9Cs4J0Fwa5SQl2xU03/IXI/Jyiu35vrUaXFbbDLRtbj0GwUGX6a IDgDtoehjuFiYXZN0K4esai/ILaYrHk= X-MC-Unique: mSwf1zMhMZitO-rm1cr_UQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9ZYp/arNlLB7CqHGh2xkLop1S0WBzyFyzBFrA9ouUuQ=; b=eQdf/ra+NNEj2lViTGeVFWLWgkeXU5KYiQ9KjP3jT9eCBgc3pjjw/x8LvTGBVC9Uw9 EQ9epuA6j4/MlnBj8kpAeVHCnHz4cA+srbsCtTxpOIEjw2NbDSTPWRhufIEaMG1Zp3fA vmSpb9S5prWiDBJ5HJ9uV0ps3aJMLEud7/Q1C5Lfuj1E3ORnlPDf5tLYpMqjtdUCNxrU DdXsjxXZ586PcqsD0LpCMtrmtq/Rs5kVulfOAwJYVt0J/si+EIznIYPWi877jrzxzCEK yaPE+ttaWd267VXO81xZVT2Pd/YRskhsDiu+T9FuuF9byte0fXwsrpI64DLETHLKr5H+ 12oA== X-Gm-Message-State: AOAM532T5WiLYiTNUHCsumHLA0gHFirRcRewyfoCV7vfrbjZhZRdpfdZ YSgFiNi/sMTFca5x0EN9GGPyIqrxTkRqIAAskJVYlCGCk1jdKVDZMBA2539SZIneTRxQtp/Y374 LijiSTM+o5FH+8/fx/xRqS9OdzeNhE8LvqgrhKyGsdSvBQEe8V+XZqGEAVpYuKpZt X-Received: by 2002:a05:6214:948:: with SMTP id dn8mr1432986qvb.30.1627497122002; Wed, 28 Jul 2021 11:32:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkgQB1tM8v5jUcFkzgaQyc1V8f0EjTx+96KjHCwXEHG/IIy7RocZvRZKjT6hW0VGsagYSwTQ== X-Received: by 2002:a05:6214:948:: with SMTP id dn8mr1432962qvb.30.1627497121740; Wed, 28 Jul 2021 11:32:01 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v3 4/8] memory: Don't do topology update in memory finalize() Date: Wed, 28 Jul 2021 14:31:47 -0400 Message-Id: <20210728183151.195139-5-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210728183151.195139-1-peterx@redhat.com> References: <20210728183151.195139-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.719, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , peterx@redhat.com, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1627497378511100001 Content-Type: text/plain; charset="utf-8" Topology update could be wrongly triggered in memory region finalize() if there's bug somewhere else. It'll be a very confusing stack when it happens (e.g., sending KVM ioctl within the RCU thread, and we'll observe it only until it fails!). Instead of that, we use the push()/pop() helper to avoid memory transaction commit, at the same time we use assertions to make sure there's no pending updates or it's a nested transaction, so it could fail even earlier and in a more explicit way. Suggested-by: Paolo Bonzini Acked-by: David Hildenbrand Signed-off-by: Peter Xu --- softmmu/memory.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/softmmu/memory.c b/softmmu/memory.c index 725d57ec17..35b2568fc2 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -170,6 +170,12 @@ struct MemoryRegionIoeventfd { EventNotifier *e; }; =20 +/* Returns whether there's any pending memory updates */ +static bool memory_region_has_pending_update(void) +{ + return memory_region_update_pending || ioeventfd_update_pending; +} + static bool memory_region_ioeventfd_before(MemoryRegionIoeventfd *a, MemoryRegionIoeventfd *b) { @@ -1756,12 +1762,25 @@ static void memory_region_finalize(Object *obj) * and cause an infinite loop. */ mr->enabled =3D false; - memory_region_transaction_begin(); + + /* + * Use depth_inc()/depth_dec() instead of begin()/commit() to make sure + * below block won't trigger any topology update (which should never + * happen, but it's still a safety belt). + */ + memory_region_transaction_depth_inc(); while (!QTAILQ_EMPTY(&mr->subregions)) { MemoryRegion *subregion =3D QTAILQ_FIRST(&mr->subregions); memory_region_del_subregion(mr, subregion); } - memory_region_transaction_commit(); + memory_region_transaction_depth_dec(); + + /* + * Make sure we're either in a nested transaction or there must have no + * pending updates due to memory_region_del_subregion() above. + */ + assert(memory_region_transaction_depth || + !memory_region_has_pending_update()); =20 mr->destructor(mr); memory_region_clear_coalescing(mr); --=20 2.31.1 From nobody Fri May 10 15:18:18 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1627497422366145.5863219610451; Wed, 28 Jul 2021 11:37:02 -0700 (PDT) Received: from localhost ([::1]:45152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m8oQP-00078Q-Cl for importer@patchew.org; Wed, 28 Jul 2021 14:37:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m8oLi-0005um-3J for qemu-devel@nongnu.org; Wed, 28 Jul 2021 14:32:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55468) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m8oLf-000764-3g for qemu-devel@nongnu.org; Wed, 28 Jul 2021 14:32:09 -0400 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-446-N1u-VKVROU62AjNaEuyJiQ-1; Wed, 28 Jul 2021 14:32:04 -0400 Received: by mail-qk1-f197.google.com with SMTP id x12-20020a05620a14acb02903b8f9d28c19so2109554qkj.23 for ; Wed, 28 Jul 2021 11:32:04 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-65-184-144-111-238.dsl.bell.ca. [184.144.111.238]) by smtp.gmail.com with ESMTPSA id n5sm417528qkp.116.2021.07.28.11.32.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 11:32:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627497126; 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=u1Bbhy9FxQTFvhtC24q8Zh262TZNyYALI7nv979a/e0=; b=M+nVBBkq8E1l7Q63db5Iv9DOqki2kWVSjAaz0wxrXcXVtNUrhY6rpK7rfXfepYWCYB+0QX qVU0pa2FJnoTRmsrauIDjOfqhXbbeA0egY0OqGdkFMypcJnhlLsEYFG8KQ1B19Y2bosule l50W3fl8hftlvxe6DQ01ivR1/eiQ53g= X-MC-Unique: N1u-VKVROU62AjNaEuyJiQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u1Bbhy9FxQTFvhtC24q8Zh262TZNyYALI7nv979a/e0=; b=UrDNDryCe1Df8seOngBUzZ941hxlNbqk+HC0W2nqtag8u7uef2J4hCogn7pKJSgICz Rf4U7BHvQhhb7WZ2e7I1W6mJeVZUk6+w2kS2/Sx6+Dh/OS8Bar4DL/Wmi7A/bP1Hc5OV X1ltML363KjB/+oQnxPWGtRTcnxofZqEYP2y2Fo2AS0b1wEEyRYYCJId2AwM7GbK/Hbb NwQ18en7XRUNsKgN346/7Uk7qfQypHHb+PGJQuXiDBulOL9t4MQztY/obZf5LK0dlr6c P2fJaQ9l9wgyBA3y3bkNPxkBPKXU54zvVtiIH0cAlFBdt3eDzWWJ/AmUdE/JSVMOaHOP Ep0A== X-Gm-Message-State: AOAM532nH9nGYmvV2wOqR5riyuai1y1kNaXb9jj2R70S7Ax2ofBiC2Mi 4/nhyQVYggvgOBZwUnkJ12f+uPyX+/Rd35F4pYIS0NK6uMe8aVal0awizepa7lL1CbXbcdtCQvQ 9bILJbPU8qCvFQRBLdC5h4Wsqw7tjBIQJV1OEm/768DsofT1BmxV9OBfeVJ1yxDxp X-Received: by 2002:ad4:5b85:: with SMTP id 5mr1413915qvp.24.1627497123790; Wed, 28 Jul 2021 11:32:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkK1SQ5P7mMO2LBJA3bSxDOY3Ycl0Ju/N/WQ7U6xpjCVPQ5rjeWT4QZfsQobrECcG1KTPcNQ== X-Received: by 2002:ad4:5b85:: with SMTP id 5mr1413891qvp.24.1627497123532; Wed, 28 Jul 2021 11:32:03 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v3 5/8] cpus: Use qemu_cond_wait_iothread() where proper Date: Wed, 28 Jul 2021 14:31:48 -0400 Message-Id: <20210728183151.195139-6-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210728183151.195139-1-peterx@redhat.com> References: <20210728183151.195139-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.719, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , peterx@redhat.com, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1627497424435100001 Content-Type: text/plain; charset="utf-8" The helper is introduced but we've still got plenty of places that are dire= ctly referencing the qemu_global_mutex itself. Spread the usage. Reviewed-by: David Hildenbrand Signed-off-by: Peter Xu Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- softmmu/cpus.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/softmmu/cpus.c b/softmmu/cpus.c index 49e0368438..e714dfbf2b 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -439,7 +439,7 @@ void qemu_wait_io_event(CPUState *cpu) slept =3D true; qemu_plugin_vcpu_idle_cb(cpu); } - qemu_cond_wait(cpu->halt_cond, &qemu_global_mutex); + qemu_cond_wait_iothread(cpu->halt_cond); } if (slept) { qemu_plugin_vcpu_resume_cb(cpu); @@ -582,7 +582,7 @@ void pause_all_vcpus(void) replay_mutex_unlock(); =20 while (!all_vcpus_paused()) { - qemu_cond_wait(&qemu_pause_cond, &qemu_global_mutex); + qemu_cond_wait_iothread(&qemu_pause_cond); CPU_FOREACH(cpu) { qemu_cpu_kick(cpu); } @@ -653,7 +653,7 @@ void qemu_init_vcpu(CPUState *cpu) cpus_accel->create_vcpu_thread(cpu); =20 while (!cpu->created) { - qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex); + qemu_cond_wait_iothread(&qemu_cpu_cond); } } =20 --=20 2.31.1 From nobody Fri May 10 15:18:18 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162749732201524.74553959854336; Wed, 28 Jul 2021 11:35:22 -0700 (PDT) Received: from localhost ([::1]:38036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m8oOm-0002KO-TW for importer@patchew.org; Wed, 28 Jul 2021 14:35:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m8oLk-00062u-MJ for qemu-devel@nongnu.org; Wed, 28 Jul 2021 14:32:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54314) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m8oLi-00078m-Vp for qemu-devel@nongnu.org; Wed, 28 Jul 2021 14:32:12 -0400 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-445-A6AyVB4kMwGAb0U-bNRyhg-1; Wed, 28 Jul 2021 14:32:06 -0400 Received: by mail-qk1-f197.google.com with SMTP id w2-20020a3794020000b02903b54f40b442so2225869qkd.0 for ; Wed, 28 Jul 2021 11:32:06 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-65-184-144-111-238.dsl.bell.ca. [184.144.111.238]) by smtp.gmail.com with ESMTPSA id n5sm417528qkp.116.2021.07.28.11.32.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 11:32:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627497130; 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=SXpNOomr22RdeatA9jpHJ9wvEFvZE1pzhOgYIChMKV8=; b=S8aqyUjAYKWO1qlqCcgCGJidXLhcltWg2ER7qQnjPdK0i/IKJDmfQJjIYtioh31Zuw0aFx 3S3mmRESdO26o6FKeR6HbcqudL2ejCQCOvA7+NPkRjNbj4Vf/CI9qQSxhrhhJVN+uDhK+6 aXWAz3fZlmB6mDUzTe3KTSkv0ZKfyj8= X-MC-Unique: A6AyVB4kMwGAb0U-bNRyhg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SXpNOomr22RdeatA9jpHJ9wvEFvZE1pzhOgYIChMKV8=; b=GlnllzDXJSFJBm9BYDJvfiPQWxvUKWifJ6QEdxO4RpinkWKLVUF6pSdTgvv0JIEVDY 85AdBygORA7tzk+XH+HLGlmu/N+SjDKQkIAVxDjnXc6PNPNxssg1TrM9UIA8To6CQuUa JYSTn/GLx845GanyxYB1Qo+wZcBWdQ7E05KVPS0qGPFG0XhcqLqhsy+Tx9u9psMA6wOM 4yRkEEa0Imn7bgHnXhGKmOBuE4SFdGkBxsjEUpkf+iQTuCc3ky8GQR0756rp6iKjRKg+ TZOYKQ9K932RIkIDAiJDoe46kUfEaeGFMc1vuR4sogj0oET/Ji/2eUfqQvV/kt6Xlupq q9HQ== X-Gm-Message-State: AOAM5337/JUILaDue4smXAoagOAxA8KVZHoFjPV7SEXpx4jvLGeLqboh YA2qpkAiMTpV6MH75x+jloR4ti++GbANVoxOf+zkfRNVsH8wLuu3o8UK9IxLRqf9v6dCn9u9xRQ eE5I9BN03NmP/H4cFpOfiUxbZ7q0HFD+aMyukVLhiFl5b7e1pOWbCeY/LRJTPPa4Q X-Received: by 2002:a37:8407:: with SMTP id g7mr1074779qkd.123.1627497125411; Wed, 28 Jul 2021 11:32:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7PbICOhDrVu2c50VCaRsQAl8z33SOyrpmQs4cR3MndNYXNPwLYRp6NEWmIzhM7ZgXkQga8g== X-Received: by 2002:a37:8407:: with SMTP id g7mr1074747qkd.123.1627497125159; Wed, 28 Jul 2021 11:32:05 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v3 6/8] cpus: Remove the mutex parameter from do_run_on_cpu() Date: Wed, 28 Jul 2021 14:31:49 -0400 Message-Id: <20210728183151.195139-7-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210728183151.195139-1-peterx@redhat.com> References: <20210728183151.195139-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.719, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , peterx@redhat.com, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1627497323887100001 Content-Type: text/plain; charset="utf-8" We must use the BQL for do_run_on_cpu() without much choice, it means the parameter is useless. Remove it. Meanwhile use the newly introduced qemu_cond_wait_iothread() in do_run_on_cpu(). Reviewed-by: David Hildenbrand Signed-off-by: Peter Xu Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- softmmu/cpus.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/softmmu/cpus.c b/softmmu/cpus.c index e714dfbf2b..9154cd7e78 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -383,8 +383,7 @@ void qemu_init_cpu_loop(void) } =20 static void -do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data, - QemuMutex *mutex) +do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data) { struct qemu_work_item wi =3D { .func =3D func, @@ -400,14 +399,14 @@ do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, ru= n_on_cpu_data data, while (!qatomic_mb_read(&wi.done)) { CPUState *self_cpu =3D current_cpu; =20 - qemu_cond_wait(&qemu_work_cond, mutex); + qemu_cond_wait_iothread(&qemu_work_cond); current_cpu =3D self_cpu; } } =20 void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data) { - do_run_on_cpu(cpu, func, data, &qemu_global_mutex); + do_run_on_cpu(cpu, func, data); } =20 static void qemu_cpu_stop(CPUState *cpu, bool exit) --=20 2.31.1 From nobody Fri May 10 15:18:18 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1627497513769535.70694752611; Wed, 28 Jul 2021 11:38:33 -0700 (PDT) Received: from localhost ([::1]:49874 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m8oRs-0001ra-Gm for importer@patchew.org; Wed, 28 Jul 2021 14:38:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53580) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m8oLn-0006EP-MK for qemu-devel@nongnu.org; Wed, 28 Jul 2021 14:32:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:33919) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m8oLj-00079p-QX for qemu-devel@nongnu.org; Wed, 28 Jul 2021 14:32:15 -0400 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-13-Zw1IQQxGMj6kF2ezpFuBgQ-1; Wed, 28 Jul 2021 14:32:08 -0400 Received: by mail-qv1-f72.google.com with SMTP id j13-20020a0cf30d0000b029032dd803a7edso2489307qvl.2 for ; Wed, 28 Jul 2021 11:32:08 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-65-184-144-111-238.dsl.bell.ca. [184.144.111.238]) by smtp.gmail.com with ESMTPSA id n5sm417528qkp.116.2021.07.28.11.32.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 11:32:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627497131; 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=o5Slmf2i54K2urMqTX3wgmu72x7kFks3at6kBlMJW5o=; b=X+6OOHhlFD3HGTVwtmDtjjx5GoCE4vyCnA+5lSKPCdTw9IgV/PCRTZZ2AVNSTMIWNVF66B AKJZvGjji3KAd0QCLd69Zy3z+UH2Qq/Dn+ml9p1Qsfj1nfhVRYnM4uKgvMDfR/+IhDOgkj KWsVhJQl+QmkBWhUxHQWoksIUC1EeXs= X-MC-Unique: Zw1IQQxGMj6kF2ezpFuBgQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o5Slmf2i54K2urMqTX3wgmu72x7kFks3at6kBlMJW5o=; b=d41YRFG1Z81xrupNUNPL4pUQkt6bRVAElc4ttQvtKyl8obKBqcJl4GSRizK9/fHCWg Kh3uqFbGNj1z6nZGtbMPD04tsUJ/aWH4aNMDBnxH6vkX4sG/MMxgwpGq1JQ17h6iJhRE KO455Fs9Jvjm7E/AVwcXk+96UUSmOh/t3SibA8xKnXVgdKGgvYfL4WgVkLvVrH/xXqmZ Bv5b2VUPEicYpT5KleGp8NFBr0dRAMb87Wt03ELl0zArJl6eKtXfupnthWAcgdZQflpu WgWxSQL2lTRv4i9KSl8jDwnSuC7SWwRp7T/0/2jjGo8p5p+tVazKgQWcbVWkCUKdp42H fnyg== X-Gm-Message-State: AOAM532t7sh6BO/jiR8UqNhYoYlp76KYOocMsVwbezxDNEA2ENWe+Tz3 /Gg/CGPIXrkTvkSW2RRIGqp3bdMeHbNb0DTHDzFgByYu/vzUSNZagVN+wdL1v1jCj1P1PE7Iw3Q Xz8+/6DVfWg3n2HmASnFENAMKj0AD+qBGrSQ3z6lPThTtiWSViEpwPdIE1ba1kFLr X-Received: by 2002:ad4:4442:: with SMTP id l2mr1080170qvt.2.1627497127101; Wed, 28 Jul 2021 11:32:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZe5u2WJsfh9BacRTr3laH/AP0S2k1YYGAMpHiBEhLlsaQGmazmvIBrvDu3JwujMWeNRuGYQ== X-Received: by 2002:ad4:4442:: with SMTP id l2mr1080153qvt.2.1627497126860; Wed, 28 Jul 2021 11:32:06 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v3 7/8] memory: Assert on no ongoing memory transaction before release BQL Date: Wed, 28 Jul 2021 14:31:50 -0400 Message-Id: <20210728183151.195139-8-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210728183151.195139-1-peterx@redhat.com> References: <20210728183151.195139-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.719, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , peterx@redhat.com, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1627497514360100001 Content-Type: text/plain; charset="utf-8" Firstly, add a "prepare" function before unlocking BQL. There're only three places that can release the BQL: unlock(), cond_wait() or cond_timedwait(). Make sure we don't have any more ongoing memory transaction when releasing = the BQL. This will trigger an abort if we misuse the QEMU memory model, e.g., = when calling run_on_cpu() during a memory commit. Reviewed-by: David Hildenbrand Signed-off-by: Peter Xu --- include/exec/memory-internal.h | 1 + softmmu/cpus.c | 9 +++++++++ softmmu/memory.c | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h index 9fcc2af25c..3124b91c4b 100644 --- a/include/exec/memory-internal.h +++ b/include/exec/memory-internal.h @@ -35,6 +35,7 @@ static inline AddressSpaceDispatch *address_space_to_disp= atch(AddressSpace *as) =20 FlatView *address_space_get_flatview(AddressSpace *as); void flatview_unref(FlatView *view); +bool memory_region_has_pending_transaction(void); =20 extern const MemoryRegionOps unassigned_mem_ops; =20 diff --git a/softmmu/cpus.c b/softmmu/cpus.c index 9154cd7e78..4d190f9076 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -31,6 +31,7 @@ #include "qapi/qapi-events-run-state.h" #include "qapi/qmp/qerror.h" #include "exec/gdbstub.h" +#include "exec/memory-internal.h" #include "sysemu/hw_accel.h" #include "exec/exec-all.h" #include "qemu/thread.h" @@ -66,6 +67,11 @@ =20 static QemuMutex qemu_global_mutex; =20 +static void qemu_mutex_unlock_iothread_prepare(void) +{ + assert(!memory_region_has_pending_transaction()); +} + bool cpu_is_stopped(CPUState *cpu) { return cpu->stopped || !runstate_is_running(); @@ -520,16 +526,19 @@ void qemu_mutex_unlock_iothread(void) { g_assert(qemu_mutex_iothread_locked()); iothread_locked =3D false; + qemu_mutex_unlock_iothread_prepare(); qemu_mutex_unlock(&qemu_global_mutex); } =20 void qemu_cond_wait_iothread(QemuCond *cond) { + qemu_mutex_unlock_iothread_prepare(); qemu_cond_wait(cond, &qemu_global_mutex); } =20 void qemu_cond_timedwait_iothread(QemuCond *cond, int ms) { + qemu_mutex_unlock_iothread_prepare(); qemu_cond_timedwait(cond, &qemu_global_mutex, ms); } =20 diff --git a/softmmu/memory.c b/softmmu/memory.c index 35b2568fc2..62ec00b52d 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -176,6 +176,12 @@ static bool memory_region_has_pending_update(void) return memory_region_update_pending || ioeventfd_update_pending; } =20 +bool memory_region_has_pending_transaction(void) +{ + return memory_region_transaction_depth || + memory_region_has_pending_update(); +} + static bool memory_region_ioeventfd_before(MemoryRegionIoeventfd *a, MemoryRegionIoeventfd *b) { --=20 2.31.1 From nobody Fri May 10 15:18:18 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1627497531129860.3469050796435; Wed, 28 Jul 2021 11:38:51 -0700 (PDT) Received: from localhost ([::1]:50974 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m8oSA-0002br-2m for importer@patchew.org; Wed, 28 Jul 2021 14:38:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53566) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m8oLk-00063x-Vx for qemu-devel@nongnu.org; Wed, 28 Jul 2021 14:32:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54981) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m8oLj-00078t-9h for qemu-devel@nongnu.org; Wed, 28 Jul 2021 14:32:12 -0400 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-550-yMzLitcWPQSYwj5HOtQ-Uw-1; Wed, 28 Jul 2021 14:32:09 -0400 Received: by mail-qt1-f198.google.com with SMTP id w11-20020ac857cb0000b029024e7e455d67so1466793qta.16 for ; Wed, 28 Jul 2021 11:32:09 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-65-184-144-111-238.dsl.bell.ca. [184.144.111.238]) by smtp.gmail.com with ESMTPSA id n5sm417528qkp.116.2021.07.28.11.32.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 11:32:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627497130; 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=fb7boGznPNdqHR4r5s4Z41glvCy2kdt/HM9+C0Br1Os=; b=YBg4cKUfwwU7mavoillWw2Bl+eGxsiMNrK0JMLT/Ey9GR918tMV6rMEZzt65yrl5jomxv2 m5W5xOva30MBzvQuX2kD9KKGZm5rqVqwzqirIabzl9cTV3EqHTHOKcEvRqwMsogg+OzL9y DMdZ0ws05z1pyF28y+6jYQ+yrpS+AsE= X-MC-Unique: yMzLitcWPQSYwj5HOtQ-Uw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fb7boGznPNdqHR4r5s4Z41glvCy2kdt/HM9+C0Br1Os=; b=pWslHNx8imVDg+zBInvhBL0xwEBcY6/iCfhVBOEKuDjPlVIhShW21hpI4xhfHX1rUm 1GnliCUVs98omCT4zQvPLfwBAewMzzktG3KPg+MieeBswGHqEkLeEPWoKI/Y61kG00w9 t0WeEuzxFx8hKc2A5LBixggA2AN+ETTttv05vRt8ND5mP6160E57OStlCbIkvbGes9Nj ou3/cnqpP0NVniNqhHltUL//UdWMwPQnEuuj4VhEtP0Fmrh3+4GYLb5KKEUH8Z8aLZpd OZ04LTrXQIRF70iuhqSmFxYWLtdmpWa8Pwb8M4qRFxr3MxjGiZ0V+pXDKLZP47dGe4P5 ++/Q== X-Gm-Message-State: AOAM532fY+uPM6sMIFg7Z5c7ghfvVKX4HO0JBdPdPQtoIenkD7nTNKlw XBpNh6rywMyLucLnhihvZl3q+6MDLVpj3YmnqdSjNep0VZsChcRLYjbai1AlR6GNp7ooK/YHa2t p25a6IluARrlq3zcwGKRa4wFPhJtP58uLXGrkRp1A65zWV5sdjn91RePTEc0x7Fm+ X-Received: by 2002:ac8:7d52:: with SMTP id h18mr805344qtb.179.1627497128694; Wed, 28 Jul 2021 11:32:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGtG+AnCJGQxnn5R1T+o0/0I0mcmwnHL1R/lh3Y6iPzaTOgdIx5QPZSF3dMEQzU+Z/UJkI/g== X-Received: by 2002:ac8:7d52:: with SMTP id h18mr805315qtb.179.1627497128428; Wed, 28 Jul 2021 11:32:08 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v3 8/8] memory: Delay the transaction pop() until commit completed Date: Wed, 28 Jul 2021 14:31:51 -0400 Message-Id: <20210728183151.195139-9-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210728183151.195139-1-peterx@redhat.com> References: <20210728183151.195139-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.719, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , peterx@redhat.com, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1627497531905100001 Content-Type: text/plain; charset="utf-8" This should be functionally the same as before, but this allows the memory_region_transaction_depth to be non-zero during commit, which can hel= p us to do sanity check on misuses. Since at it, fix an indentation issue on the bracket. Signed-off-by: Peter Xu --- softmmu/memory.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/softmmu/memory.c b/softmmu/memory.c index 62ec00b52d..e830649011 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1114,8 +1114,7 @@ void memory_region_transaction_commit(void) assert(memory_region_transaction_depth); assert(qemu_mutex_iothread_locked()); =20 - memory_region_transaction_depth_dec(); - if (!memory_region_transaction_depth) { + if (memory_region_transaction_depth =3D=3D 1) { if (memory_region_update_pending) { flatviews_reset(); =20 @@ -1134,7 +1133,14 @@ void memory_region_transaction_commit(void) } ioeventfd_update_pending =3D false; } - } + } + + /* + * Decrease the depth at last, so that memory_region_transaction_depth= will + * still be non-zero during committing. This can help us to do some s= anity + * check within the process of committing. + */ + memory_region_transaction_depth_dec(); } =20 static void memory_region_destructor_none(MemoryRegion *mr) --=20 2.31.1