From patchwork Tue Apr 21 16:21:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 284130 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03058C54FC9 for ; Tue, 21 Apr 2020 16:22:41 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B140F206F4 for ; Tue, 21 Apr 2020 16:22:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IXMbUQeA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B140F206F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:32776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQvfS-0001x8-RI for qemu-devel@archiver.kernel.org; Tue, 21 Apr 2020 12:22:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54004) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQveG-0000mZ-O7 for qemu-devel@nongnu.org; Tue, 21 Apr 2020 12:21:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQveB-00045y-Tw for qemu-devel@nongnu.org; Tue, 21 Apr 2020 12:21:24 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:28741 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jQveB-00045G-IM for qemu-devel@nongnu.org; Tue, 21 Apr 2020 12:21:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587486078; 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=I0YrSfJZG3OCin0XwLpQsE2WSkg0EXuV6HT6X0zjKVY=; b=IXMbUQeAyP0w2hQa/+ubzem/zA6rxKSMwAFUp9qBFzj3/69c//7yBAnujJsAxPeRNgxMWm tAiPhJkSCDIGBf9U09R4DROXAA1dIEKnFy5r4IQKIdnAwjXHXnQyFb6DLsKFby9mR/SOBK 78ixMGIrWaaYwuhvry9juDV0F5uVHRg= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-305-bTONjKJXMB-TwcXF8KhEnQ-1; Tue, 21 Apr 2020 12:21:16 -0400 X-MC-Unique: bTONjKJXMB-TwcXF8KhEnQ-1 Received: by mail-qt1-f197.google.com with SMTP id f56so15324186qte.18 for ; Tue, 21 Apr 2020 09:21:16 -0700 (PDT) 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=ZpjWesWQtez4RVwbFQXrjywWOT0CDQMzNzTMHASVusg=; b=O01WSumiTLzz4EHYyFzd+jU9zEALDwNITCMz2rzZXwPA9v7LhB+Ow3uTM3yuGhDDnA 7PPnlT0JqcjytwSocnlkFztftYwuBMZMU9DrqgMJN+cSNh722Ya+Q/Z0YKV+ebWtTyEh m+MC+90SgKvs2ptpxNWrX/VXWWW1GlF6ANE6XFcc1o6qp0Kk5FAke0GUuTo4GsaZFZPw 9DxSusHic3kuJhMLW560rqSgiRFSVhxUie8z+YVaQF1AyKpbnCkTC12ing+PPRve34do Af5MknXR0FgtoGpxmDDinJWeBh2hPGVTlBRuyJBnevcBa19nqe0i03tpa778s/bcV/yS HJqQ== X-Gm-Message-State: AGi0PubE/OE5EvKp9tCyF+CycSTxhgPIsSc7iI7O63Ecw+p//JhJFyAx yB92KX15NOS9SHwryW6PrF17UWa28f1PgsWlBoWNcPcZPmRoDb3iJhFqAliWfmNafu42WJF3QqZ wbJQkSfQ30BB4gjw= X-Received: by 2002:a0c:f883:: with SMTP id u3mr20841115qvn.86.1587486075659; Tue, 21 Apr 2020 09:21:15 -0700 (PDT) X-Google-Smtp-Source: APiQypI4ZYxDlkw7lZXId1vwb0Snhu5C16MYvVeIRWGMGcHSua539raQFqse1kuOWbXHqS8a+pp4MQ== X-Received: by 2002:a0c:f883:: with SMTP id u3mr20841022qvn.86.1587486074472; Tue, 21 Apr 2020 09:21:14 -0700 (PDT) Received: from xz-x1.redhat.com ([2607:9880:19c0:32::2]) by smtp.gmail.com with ESMTPSA id k43sm2111531qtk.67.2020.04.21.09.21.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 09:21:13 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 1/8] memory: Introduce memory_region_transaction_{push|pop}() Date: Tue, 21 Apr 2020 12:21:01 -0400 Message-Id: <20200421162108.594796-2-peterx@redhat.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200421162108.594796-1-peterx@redhat.com> References: <20200421162108.594796-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=207.211.31.81; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/21 01:28:51 X-ACL-Warn: Detected OS = 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: Paolo Bonzini , peterx@redhat.com, Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" memory_region_transaction_{begin|commit}() could be too big when finalizing a memory region. E.g., we should never attempt to update address space topology during the finalize() of a memory region. Provide helpers for further use. Signed-off-by: Peter Xu --- memory.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/memory.c b/memory.c index 601b749906..e5d634d648 100644 --- a/memory.c +++ b/memory.c @@ -1054,10 +1054,20 @@ static void address_space_update_topology(AddressSpace *as) address_space_set_flatview(as); } +static void memory_region_transaction_push(void) +{ + memory_region_transaction_depth++; +} + +static void memory_region_transaction_pop(void) +{ + memory_region_transaction_depth--; +} + void memory_region_transaction_begin(void) { qemu_flush_coalesced_mmio_buffer(); - ++memory_region_transaction_depth; + memory_region_transaction_push(); } void memory_region_transaction_commit(void) @@ -1067,7 +1077,7 @@ void memory_region_transaction_commit(void) assert(memory_region_transaction_depth); assert(qemu_mutex_iothread_locked()); - --memory_region_transaction_depth; + memory_region_transaction_pop(); if (!memory_region_transaction_depth) { if (memory_region_update_pending) { flatviews_reset(); From patchwork Tue Apr 21 16:21:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 284128 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A1CCC54FCC for ; Tue, 21 Apr 2020 16:24:13 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A58AD206E9 for ; Tue, 21 Apr 2020 16:24:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VYFfWuw2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A58AD206E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:32814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQvgx-0004d8-Ax for qemu-devel@archiver.kernel.org; Tue, 21 Apr 2020 12:24:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54024) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQveK-0000oe-Dh for qemu-devel@nongnu.org; Tue, 21 Apr 2020 12:21:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQveI-00049U-NT for qemu-devel@nongnu.org; Tue, 21 Apr 2020 12:21:28 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:50373 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jQveI-00048k-B0 for qemu-devel@nongnu.org; Tue, 21 Apr 2020 12:21:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587486084; 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=2H+OgQwZ9zhEE73FazNnzT/qTkBaiVyceFFMEZU4064=; b=VYFfWuw2pFDRNumAr6ffiBj0dqZT02auMWrKQ1J7qyVynIHh5oDTjPIdm3XqIVX/xvv8J8 IYS5ZxnNnkOcQMxzpmFEWljHpOM1AXCYbCQL+wof0XI9/uHbGtY5mrcodKUH+YBJvkhIKE RSZsVtQlsXzrm9pL1SWZEJbAo8dyNT4= 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-428-8khLdJz-PnKbUjBtPie0tg-1; Tue, 21 Apr 2020 12:21:23 -0400 X-MC-Unique: 8khLdJz-PnKbUjBtPie0tg-1 Received: by mail-qv1-f72.google.com with SMTP id b4so14286828qvt.15 for ; Tue, 21 Apr 2020 09:21:23 -0700 (PDT) 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=fpjhpsaQQavZP0ghK24+JAch3X5MLywrjyWB4EFaOlI=; b=nnEA5R8NTTxzYz+umJ1vDaIbXFXdJke9xvuCkK/vdGnP3tobDS0FHuhbhJdOWZXkEp JK8whT4tbo0HYHjLw+lm5CxP5DdMKEQT6jzpR1esay6Xtbu1YNnbvtafXZ5hevuJ06lw ltedjZOG8PESo3ogHy/b5doqfpImEbrRNDQI82q4AcbFuqdPEMlyZWMkiRjoCuloTtYS X26eqHFUVzXmVxJvzAJyKOUcQOKaq2G7vQAza5ivy1pbvLCv+ez+4pN7iIiQEhhGQfWr imBlM8uPL5JzsBxVSGIhuamPpkLu5J88y6UjWTgu1UCbmOcdkVQZi7oo3xUNwuAaOKNo dJwg== X-Gm-Message-State: AGi0PuaBQDRM95mYuOABjvHsr3sljOPmI+QmPAu+eI1krysJz8dtridZ wzit/5QEDI20KPgDVY+UbJCSUjPiaEQWSHS7VNnakpK2w3anqgBvhk0HuBYOkeccnJ6I60FhxZK hWeZcHucxTZzg+Qc= X-Received: by 2002:a37:b1c6:: with SMTP id a189mr6410919qkf.26.1587486081405; Tue, 21 Apr 2020 09:21:21 -0700 (PDT) X-Google-Smtp-Source: APiQypJG0ZnaQW+4qLEUi/pIe4a8e0cOZs8o9iKVUeXHPVefP/RG9yitb3JSU42cQomONHKXU0IAag== X-Received: by 2002:a37:b1c6:: with SMTP id a189mr6410897qkf.26.1587486081179; Tue, 21 Apr 2020 09:21:21 -0700 (PDT) Received: from xz-x1.redhat.com ([2607:9880:19c0:32::2]) by smtp.gmail.com with ESMTPSA id s15sm2110604qtc.31.2020.04.21.09.21.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 09:21:20 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 3/8] cpus: Use qemu_cond_wait_iothread() where proper Date: Tue, 21 Apr 2020 12:21:03 -0400 Message-Id: <20200421162108.594796-4-peterx@redhat.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200421162108.594796-1-peterx@redhat.com> References: <20200421162108.594796-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.61; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/21 03:31:23 X-ACL-Warn: Detected OS = 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: Paolo Bonzini , peterx@redhat.com, Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The helper is introduced but we've still got plenty of places that are directly referencing the qemu_global_mutex itself. Spread the usage. Signed-off-by: Peter Xu --- cpus.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cpus.c b/cpus.c index ef441bdf62..00f6e361af 100644 --- a/cpus.c +++ b/cpus.c @@ -1181,7 +1181,7 @@ static void qemu_tcg_rr_wait_io_event(void) while (all_cpu_threads_idle()) { stop_tcg_kick_timer(); - qemu_cond_wait(first_cpu->halt_cond, &qemu_global_mutex); + qemu_cond_wait_iothread(first_cpu->halt_cond); } start_tcg_kick_timer(); @@ -1200,7 +1200,7 @@ static void qemu_wait_io_event(CPUState *cpu) slept = 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); @@ -1456,7 +1456,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg) /* wait for initial kick-off after machine start */ while (first_cpu->stopped) { - qemu_cond_wait(first_cpu->halt_cond, &qemu_global_mutex); + qemu_cond_wait_iothread(first_cpu->halt_cond); /* process any pending work */ CPU_FOREACH(cpu) { @@ -1657,7 +1657,7 @@ static void *qemu_whpx_cpu_thread_fn(void *arg) } } while (cpu_thread_is_idle(cpu)) { - qemu_cond_wait(cpu->halt_cond, &qemu_global_mutex); + qemu_cond_wait_iothread(cpu->halt_cond); } qemu_wait_io_event_common(cpu); } while (!cpu->unplug || cpu_can_run(cpu)); @@ -1877,7 +1877,7 @@ void pause_all_vcpus(void) replay_mutex_unlock(); 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); } @@ -2087,7 +2087,7 @@ void qemu_init_vcpu(CPUState *cpu) } while (!cpu->created) { - qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex); + qemu_cond_wait_iothread(&qemu_cpu_cond); } } From patchwork Tue Apr 21 16:21:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 284129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA302C54FCC for ; Tue, 21 Apr 2020 16:22:49 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 80058206E9 for ; Tue, 21 Apr 2020 16:22:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FrUmBqap" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 80058206E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:32780 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQvfc-0002Gd-Bl for qemu-devel@archiver.kernel.org; Tue, 21 Apr 2020 12:22:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54062) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQveP-0000xz-GJ for qemu-devel@nongnu.org; Tue, 21 Apr 2020 12:21:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQveN-0004Ce-RH for qemu-devel@nongnu.org; Tue, 21 Apr 2020 12:21:33 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:34482 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jQveN-0004C4-Cf for qemu-devel@nongnu.org; Tue, 21 Apr 2020 12:21:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587486090; 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=122YOYw144hc6vkPSvZo4NtonS9ahelmjBfjzv+fw7s=; b=FrUmBqap3sIw5NYm891rFQr1iuSJHUOWoKeuxFpGU25HjRbnISyXNcL3VGrJTXmBCTVQYY ht1LDo547WMCDHT38DrFW1kmYWNRvW12p0eWeYYiUa/ODCbQitqbT4Xx8MtZ3KXigL9gaY z0YaME+xt5QUbwPEXHuacyiLlfe6RqI= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-332-ULJNS5A2NWu3yyjC7oTesg-1; Tue, 21 Apr 2020 12:21:28 -0400 X-MC-Unique: ULJNS5A2NWu3yyjC7oTesg-1 Received: by mail-qt1-f199.google.com with SMTP id z3so1824873qtb.6 for ; Tue, 21 Apr 2020 09:21:28 -0700 (PDT) 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=Hc5q36gUSYxDngylBJ7eysmU7ygS+hXagQQ/ZJe8Efk=; b=rqgArRHfBX7ox2+g4/xFjbPVqTtE0/mkviTrI6qgTgWDnVBPKPGWjBBfhAlXFiu3V8 7FmzTucszjMjVjYTCKk/D9LlBF8KECdh804p08v2Z7zH3L+vncM1x+IUnq5iLKlRyYNS t6t7oy5CsPWVv79AI9GQd6wln/F+y+a1b6SS/YGxiX99QznJhYsY6DShuY46ID4se/Mb lcnFBFtzBr5TTwoNVItvfjsWnb3vHnwk/2dVNK7RwIPuriPKmvC79UKxMBE+WN2ey+sp gQLWI96y8q9mKZxWA3+G4uMY4oTRLfRv04FjQ73YUPxcF5ABoJIG7jlzeX+BRX+seIUi HLZQ== X-Gm-Message-State: AGi0PuYI5H31jBSvbmb/aJHn7h7IWCbaD5yNZakzC0tkIR9x1DXrKG4j TRTFAYbn0clg2wIamPd0ECHVNXhD3C7aTshtNI9Pj6FSbdh7Zk5RE8IGKW/qaqpeVBDAnMfROKO GAVBa45QIO67hdmY= X-Received: by 2002:aed:3445:: with SMTP id w63mr21724892qtd.183.1587486087444; Tue, 21 Apr 2020 09:21:27 -0700 (PDT) X-Google-Smtp-Source: APiQypIxIGg6zFdz3rLUrny1hQomxwk+/LiFR4emedwHUM5IUYKXKRVTDERRA5i9cgwnIjDks1GIng== X-Received: by 2002:aed:3445:: with SMTP id w63mr21724869qtd.183.1587486087133; Tue, 21 Apr 2020 09:21:27 -0700 (PDT) Received: from xz-x1.redhat.com ([2607:9880:19c0:32::2]) by smtp.gmail.com with ESMTPSA id r128sm2002105qke.95.2020.04.21.09.21.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 09:21:26 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 5/8] cpus: Remove the mutex parameter from do_run_on_cpu() Date: Tue, 21 Apr 2020 12:21:05 -0400 Message-Id: <20200421162108.594796-6-peterx@redhat.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200421162108.594796-1-peterx@redhat.com> References: <20200421162108.594796-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.61; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/21 03:31:23 X-ACL-Warn: Detected OS = 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: Paolo Bonzini , peterx@redhat.com, Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We must use the BQL for do_run_on_cpu() without much choice, it means the parameter is helpless. Remove it. Meanwhile use the newly introduced qemu_cond_wait_iothread() in do_run_on_cpu(). Signed-off-by: Peter Xu --- cpus-common.c | 5 ++--- cpus.c | 2 +- include/hw/core/cpu.h | 4 +--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/cpus-common.c b/cpus-common.c index eaf590cb38..4fc11b4e1c 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -121,8 +121,7 @@ static void queue_work_on_cpu(CPUState *cpu, struct qemu_work_item *wi) qemu_cpu_kick(cpu); } -void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data, - QemuMutex *mutex) +void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data) { struct qemu_work_item wi; @@ -141,7 +140,7 @@ void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data, while (!atomic_mb_read(&wi.done)) { CPUState *self_cpu = current_cpu; - qemu_cond_wait(&qemu_work_cond, mutex); + qemu_cond_wait_iothread(&qemu_work_cond); current_cpu = self_cpu; } } diff --git a/cpus.c b/cpus.c index 263eddc8b0..5cbc3f30de 100644 --- a/cpus.c +++ b/cpus.c @@ -1140,7 +1140,7 @@ void qemu_init_cpu_loop(void) 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); } static void qemu_kvm_destroy_vcpu(CPUState *cpu) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 5bf94d28cf..b26fdb5ab8 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -734,12 +734,10 @@ bool cpu_is_stopped(CPUState *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 data, - QemuMutex *mutex); +void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data); /** * run_on_cpu: From patchwork Tue Apr 21 16:21:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 284127 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8950BC54FCC for ; Tue, 21 Apr 2020 16:26:05 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3DB3F206E9 for ; Tue, 21 Apr 2020 16:26:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="J3X+W+9Y" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3DB3F206E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:32868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQvik-0007Cu-SU for qemu-devel@archiver.kernel.org; Tue, 21 Apr 2020 12:26:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54090) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQveU-00017t-U0 for qemu-devel@nongnu.org; Tue, 21 Apr 2020 12:21:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQveT-0004EF-9V for qemu-devel@nongnu.org; Tue, 21 Apr 2020 12:21:38 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:46842 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jQveS-0004Dr-SK for qemu-devel@nongnu.org; Tue, 21 Apr 2020 12:21:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587486096; 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=BDz7lahVpSsYjchGZFQF0Q24z99LRn1XXRfOl+p2CyQ=; b=J3X+W+9Y15776KKxo6upsaAB5rsb385JVHyMtCoezerUHcQ09eua1ttQh6GouyCmXgxFN6 L2Y/usn9pWRAqYUfZXu+B6q/svfsf555vh1RWVQM86le9i0rnEEa6HTX/C8nhr7aGQkLIA Dx/ZB5y4urN3kP23HXJtCl2AqTGaOQM= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-439-U_NGFeJjPsevu8n8VQpUKQ-1; Tue, 21 Apr 2020 12:21:34 -0400 X-MC-Unique: U_NGFeJjPsevu8n8VQpUKQ-1 Received: by mail-qv1-f71.google.com with SMTP id ck5so14259883qvb.18 for ; Tue, 21 Apr 2020 09:21:34 -0700 (PDT) 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=Xr430nT3TegA7cHuep87EtnygKrdKqkDIQZx40c9Vks=; b=EcukyQoAEHZ9oplOhnfFWtB/eeBtlX4CEreNrsHIPldAr6DBaWRydF9UQj5cV0M77A qo5X4EeFuhfxJ+ltPIFAR9H4PqVvNLDbaZ/K1SDMUiSAHi5cPHrkekWIIl5HOxPyKddS 7R4lPFw4BZQiuAx2xxaKIktGlWgFoeWK+em6V+WMVGr79l1cyIV3jzuu782aHkAbUbX1 gXebepDQcWsS2QGW26i3y4+qKvyJBlRuhYB8V6IDsLp8OyIORvAZ564vY3pb0PXbdX90 mScUHL8WdrUZa68YUJwCGODwMbUF63vtpjTWvXZMMCqwXrAFnK18BmjEwrZDgvwc5YNf znhQ== X-Gm-Message-State: AGi0PuajuppigOyXOkIuMOLF6ojvzwAQivI4jZAymPJts0bVklToUii0 xn6A/v+NuPYyPwJr3XAoaTa6/okErlE4Q8G5SwihjPoMll4xw1r7QROFg+zBqNBpKIeBmmqKtFS zcyhEcbWIcjeHcn8= X-Received: by 2002:a37:8a87:: with SMTP id m129mr7695450qkd.250.1587486093605; Tue, 21 Apr 2020 09:21:33 -0700 (PDT) X-Google-Smtp-Source: APiQypIwFZPkauDJAzhQKNhpSqCPX+CMXXtH4VIYb3UHXOy6bqkE6uZXNcrK9yZf1DZEY9lEM/ex6g== X-Received: by 2002:a37:8a87:: with SMTP id m129mr7695432qkd.250.1587486093386; Tue, 21 Apr 2020 09:21:33 -0700 (PDT) Received: from xz-x1.redhat.com ([2607:9880:19c0:32::2]) by smtp.gmail.com with ESMTPSA id i42sm2106688qtc.83.2020.04.21.09.21.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 09:21:32 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 7/8] memory: Assert on no ongoing memory transaction before release BQL Date: Tue, 21 Apr 2020 12:21:07 -0400 Message-Id: <20200421162108.594796-8-peterx@redhat.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200421162108.594796-1-peterx@redhat.com> References: <20200421162108.594796-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=207.211.31.81; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/21 01:28:51 X-ACL-Warn: Detected OS = 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: Paolo Bonzini , peterx@redhat.com, Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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. Signed-off-by: Peter Xu --- cpus.c | 2 ++ include/exec/memory-internal.h | 1 + memory.c | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/cpus.c b/cpus.c index 48aa295fea..8c82556ff4 100644 --- a/cpus.c +++ b/cpus.c @@ -43,6 +43,7 @@ #include "sysemu/hvf.h" #include "sysemu/whpx.h" #include "exec/exec-all.h" +#include "exec/memory-internal.h" #include "qemu/thread.h" #include "qemu/plugin.h" @@ -1834,6 +1835,7 @@ void qemu_mutex_lock_iothread_impl(const char *file, int line) static void qemu_mutex_unlock_iothread_prepare(void) { + assert(!memory_region_has_pending_transaction()); } void qemu_mutex_unlock_iothread(void) 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_dispatch(AddressSpace *as) FlatView *address_space_get_flatview(AddressSpace *as); void flatview_unref(FlatView *view); +bool memory_region_has_pending_transaction(void); extern const MemoryRegionOps unassigned_mem_ops; diff --git a/memory.c b/memory.c index fea427f43f..2f8dc9721f 100644 --- a/memory.c +++ b/memory.c @@ -177,6 +177,12 @@ static bool memory_region_has_pending_update(void) return memory_region_update_pending || ioeventfd_update_pending; } +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) { From patchwork Tue Apr 21 16:21:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 284126 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AAFB2C54FCC for ; Tue, 21 Apr 2020 16:27:50 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 42ADE206E9 for ; Tue, 21 Apr 2020 16:27:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iLgukEaz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 42ADE206E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:32933 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQvkR-0001Ju-IA for qemu-devel@archiver.kernel.org; Tue, 21 Apr 2020 12:27:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54096) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQveW-0001AW-ER for qemu-devel@nongnu.org; Tue, 21 Apr 2020 12:21:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQveW-0004GO-0c for qemu-devel@nongnu.org; Tue, 21 Apr 2020 12:21:40 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:27612 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jQveV-0004FY-KL for qemu-devel@nongnu.org; Tue, 21 Apr 2020 12:21:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587486099; 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=FoAyx/faVahlrymiqKqLC0TBQQ5qCmKH51d5hFH8O+s=; b=iLgukEazfGyBxn2a8K0X1z6KutGfEuFohbz5isO5vX/4Ndx4SSm2fPFCplXyyzh/ZanaHd Onp5SyzW37wkESC26/VuS26hNx7tQtz26ixtYp9GjIrGz8KQmdVq9NYoDL2s0lCL1zwQ23 TQlMYb4t8bHacAYS9maVelRB0u4tHlE= 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-281-tubhFZVjPbibSjKo6ihItw-1; Tue, 21 Apr 2020 12:21:37 -0400 X-MC-Unique: tubhFZVjPbibSjKo6ihItw-1 Received: by mail-qv1-f69.google.com with SMTP id f4so14336880qvu.19 for ; Tue, 21 Apr 2020 09:21:37 -0700 (PDT) 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=mrsxtz6M3n9ykP7SzORGfdZlM7nc/uxySWadcjQY4u8=; b=G5ak33C7DS/jzOjch/PejhVab/CCp4zc7wGgt6Na+kdEuO1YuffWy9I8jQOeMIC8V3 0eP/Du+zaSlw5vXtaB3onxje2MYbzer0B08k7wPjk3FPAhpQZdxBoyZFBpp8B7buKMP4 nRXllRKOyrbx+lC2Wxniao4q0XpYFs52saYyVXIIzskSf6d/0AeQY2Z3GRt52alAEvW5 WpmzjKYGD5IDx31rT6H0B1mIwmhOV+6FzGSzheEEsyCF0pFyU8NxJlONFPxxPv0fq0JO vYzIJNQfhpeeWd/1eAXjtWUlZRWTl9My13K1Q81dH+0bv1R+qDwGop2X6fqUwUqXwwt2 ntXw== X-Gm-Message-State: AGi0PuaQSar/7PXikJX87YIE8ppDcm94kwZ/EGfTUIHkbCng6ZknvgLh I+E8DWKkUswtUaW1Pt9/nkO91ErZQBD5oUDGeq8IqdklvJJ0A1r0F+yaaaU5BLskkGTbIDf46Ab C7VO21XeZ+m/Hj6I= X-Received: by 2002:ac8:6f0d:: with SMTP id g13mr21843442qtv.328.1587486096560; Tue, 21 Apr 2020 09:21:36 -0700 (PDT) X-Google-Smtp-Source: APiQypLaoyJsoVjkhMvfPHx+qU5GHgTmn2Pa9J9KC3AqJd4l3B6nxvw9g2ONkSbhpYgOUC3C71JLFQ== X-Received: by 2002:ac8:6f0d:: with SMTP id g13mr21843421qtv.328.1587486096332; Tue, 21 Apr 2020 09:21:36 -0700 (PDT) Received: from xz-x1.redhat.com ([2607:9880:19c0:32::2]) by smtp.gmail.com with ESMTPSA id k2sm2106359qta.39.2020.04.21.09.21.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 09:21:35 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 8/8] memory: Delay the transaction pop() until commit completed Date: Tue, 21 Apr 2020 12:21:08 -0400 Message-Id: <20200421162108.594796-9-peterx@redhat.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200421162108.594796-1-peterx@redhat.com> References: <20200421162108.594796-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=207.211.31.81; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/21 01:28:51 X-ACL-Warn: Detected OS = 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: Paolo Bonzini , peterx@redhat.com, Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This should be functionally the same as before, but this allows the memory_region_transaction_depth to be non-zero during commit, which can help us to do sanity check on misuses. Since at it, fix an indentation issue on the bracket. Signed-off-by: Peter Xu --- memory.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/memory.c b/memory.c index 2f8dc9721f..357f7276ee 100644 --- a/memory.c +++ b/memory.c @@ -1089,8 +1089,7 @@ void memory_region_transaction_commit(void) assert(memory_region_transaction_depth); assert(qemu_mutex_iothread_locked()); - memory_region_transaction_pop(); - if (!memory_region_transaction_depth) { + if (memory_region_transaction_depth == 1) { if (memory_region_update_pending) { flatviews_reset(); @@ -1109,7 +1108,14 @@ void memory_region_transaction_commit(void) } ioeventfd_update_pending = false; } - } + } + + /* + * Pop the depth at last, so that memory_region_transaction_depth will + * still be non-zero during committing. This can help us to do some sanity + * check within the process of committing. + */ + memory_region_transaction_pop(); } static void memory_region_destructor_none(MemoryRegion *mr)