From patchwork Fri Jul 23 19:34:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12396859 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 1B217C4338F for ; Fri, 23 Jul 2021 19:36:28 +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 9EAF060F38 for ; Fri, 23 Jul 2021 19:36:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9EAF060F38 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:32910 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m70yA-0000Id-Df for qemu-devel@archiver.kernel.org; Fri, 23 Jul 2021 15:36:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39398) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m70wi-0006Cl-9X for qemu-devel@nongnu.org; Fri, 23 Jul 2021 15:34:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45698) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m70wf-0002M3-GR for qemu-devel@nongnu.org; Fri, 23 Jul 2021 15:34:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627068892; 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=a+1Gg6Qd3Ft2AlRxiHvpmsB+B0uldsPLxouTTAZo0PI=; b=Rq67QRnx8zG+FjjK0/2Ww91GIqL5NLc4rO7gZk1+bXA7BlnGUiMy7AnDEr7glBMFbTQ1H3 5XqP3tzFu3HlHVjzcImbKtD9Z+a6PyYe9GJaXZ/+Km7NK5bNIaSpCI6AEE/UW2DC7nJGx5 zoRc0dv/Ll/ByzBnvy/hSy39tL721RE= 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-23-dRRlGShJPP6Z8wfaQbyslg-1; Fri, 23 Jul 2021 15:34:51 -0400 X-MC-Unique: dRRlGShJPP6Z8wfaQbyslg-1 Received: by mail-qv1-f71.google.com with SMTP id 15-20020a0562140dcfb02902e558bb7a04so2453302qvt.10 for ; Fri, 23 Jul 2021 12:34:51 -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=a+1Gg6Qd3Ft2AlRxiHvpmsB+B0uldsPLxouTTAZo0PI=; b=OY751rltg72WPnNbG4hRw2eAzrNDwRQrM81nPXRmOCOcyJ3VTgsyihW/n+N2xoOC0n vzJ9EffC2dVy7kpFNKz4pTJPOpIHvz14NUhE55ne9DWjWcpvCehK/FXEqbM6qpzAhJiq UxGZkMjqBMHPSg1iTWC8hXILZaOin9gmwYYpGQ2WiNFXCuZ0Y3HYE9/5w04ieINIuvVM bXe7r9OJZ6RhBsxvnzw76YUD9QLQV+rnJc4Sf74pFZ/KmuyWTRSKR42sOfsA7ZiG79TM lGpvAC2NxOPtyIl0c/o0Y7CPwNWYu8nCtgEUPqQ5e24JsPLczX/8ba7DCBq/EZlynKmE oAtQ== X-Gm-Message-State: AOAM530ISrAKEIkJjlTepFjQxq9G4iXYvoTcO6iAjN4nuQotCHpNdk6M K9mcjw7wcZD2gAtofQhjcmVTJwNtk7JPaeBFyZl0ZRFowCPRC1sE+6Pz4lYtGtFil1KH/gEcLpP UCicE68eYCH/qn2Ismfg8Ea4IuVSFjBk9qfWYa2oSC17N5d+fqnVPhqUxYolEgjw7 X-Received: by 2002:ac8:5546:: with SMTP id o6mr5393563qtr.69.1627068890676; Fri, 23 Jul 2021 12:34:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynU7kl1qIcfZA9Ydi42l2IddQ51VSSTc8+/qUuRaDgW9Kj+uTEmXI1CPy72LcvW5ETsAq4VQ== X-Received: by 2002:ac8:5546:: with SMTP id o6mr5393539qtr.69.1627068890387; Fri, 23 Jul 2021 12:34:50 -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 o2sm12659104qkm.109.2021.07.23.12.34.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 12:34:49 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v2 1/9] cpus: Export queue work related fields to cpu.h Date: Fri, 23 Jul 2021 15:34:36 -0400 Message-Id: <20210723193444.133412-2-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210723193444.133412-1-peterx@redhat.com> References: <20210723193444.133412-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 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: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.472, 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 , David Hildenbrand , peterx@redhat.com, Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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. Signed-off-by: Peter Xu Reviewed-by: David Hildenbrand --- 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; /* >= 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; -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 { typedef void (*run_on_cpu_func)(CPUState *cpu, run_on_cpu_data data); -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; #define CPU_UNSET_NUMA_NODE_ID -1 #define CPU_TRACE_DSTATE_MAX_EVENTS 32 From patchwork Fri Jul 23 19:34:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12396861 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 A97AAC4320A for ; Fri, 23 Jul 2021 19:36:28 +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 32E1C60E99 for ; Fri, 23 Jul 2021 19:36:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 32E1C60E99 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:32958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m70yB-0000Ke-4d for qemu-devel@archiver.kernel.org; Fri, 23 Jul 2021 15:36:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39414) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m70wj-0006D1-8E for qemu-devel@nongnu.org; Fri, 23 Jul 2021 15:34:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50962) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m70wh-0002MX-LW for qemu-devel@nongnu.org; Fri, 23 Jul 2021 15:34:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627068895; 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=cNXEr+T+XapNQFW5Dh4TjsXCTgxO/qnoJkHQYagRHIo=; b=dqIeMfk6Ob9Dj+xXiKNWMXSwVmt47oEA/3JJLhBg665yeW9AnA/NSIp/wZINZ1ZE4j67s9 KWkbhiJRzzBHEzyl4XV9fuzkHWFpuKL8xS/xOzskw52il77R2ZccTLPMg9vzi/r7KsnOoX KBzzXWpv8rwItWMJf3+z53zt+P/ssko= 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-289-LU8ejLzrP4SWbm3Oh3S7Hw-1; Fri, 23 Jul 2021 15:34:53 -0400 X-MC-Unique: LU8ejLzrP4SWbm3Oh3S7Hw-1 Received: by mail-qk1-f200.google.com with SMTP id k5-20020a05620a4145b02903b8eff05707so1934339qko.5 for ; Fri, 23 Jul 2021 12:34:53 -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=cNXEr+T+XapNQFW5Dh4TjsXCTgxO/qnoJkHQYagRHIo=; b=s9aX0FnFO4djDGBdMHpebP/8q46WuxV3raLO/Wf8fDmLfQiKLm/H6XhQYBIgtO/gfv swdTmRqWS5p4xtphEb4h2E9Cj7EXGwHEFBImCazlgiu9jAGeOcqbfsEkBnm/cNAEW2Dx +S/eOlLhnhLvXejiex7wzEVhOw1woki62l8/dm8XZuuFGyfYtMYPnWhmA93beo8lb8xl cNctCrnV1Jkf2A8Ct2581lwDNCZWbkzhxW4+NNgU67SFO5FVcvJJeDKRjwljKr/VTqI+ C7o7dUs/PgR0bJnBPHNpw3uOam1fg16VbCVQ1wiFjOFL+0H1SLaA5an1zNNp3r92pODE 4hxA== X-Gm-Message-State: AOAM530pFGBtUSZGcGiqNgnR9A5xW0Y/pKUCv7+hlonCM4xsD0Stuuhp TtmXzPZLj24r9gDpqau4FYsR0uKmd9WlfWWS+UjAW5cjEebN9ksNWmz4X0KLs6TV7rngeGTt4Q5 R0VrS+ATMEeX63pNsC1PEa/Xkl3pcKkPpsFrR9db5znNyj0uZ4ILAvICaGwEtm06t X-Received: by 2002:a05:622a:1995:: with SMTP id u21mr5379597qtc.77.1627068892357; Fri, 23 Jul 2021 12:34:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVFEj+pRNDkG5aMg/y96+Jory/NmN8qzGAfjNytehFwJt4SJBOfrK1mlaJKFa4EKJbiKpQ/g== X-Received: by 2002:a05:622a:1995:: with SMTP id u21mr5379579qtc.77.1627068892112; Fri, 23 Jul 2021 12:34:52 -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 o2sm12659104qkm.109.2021.07.23.12.34.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 12:34:50 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v2 2/9] cpus: Move do_run_on_cpu into softmmu/cpus.c Date: Fri, 23 Jul 2021 15:34:37 -0400 Message-Id: <20210723193444.133412-3-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210723193444.133412-1-peterx@redhat.com> References: <20210723193444.133412-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 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: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.472, 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 , David Hildenbrand , peterx@redhat.com, Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" It's only used by softmmu binaries not linux-user ones. Make it static and drop the definition in the header too. Signed-off-by: Peter Xu Reviewed-by: David Hildenbrand --- cpus-common.c | 25 ------------------------- include/hw/core/cpu.h | 12 ------------ softmmu/cpus.c | 26 ++++++++++++++++++++++++++ 3 files changed, 26 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); } -void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data, - QemuMutex *mutex) -{ - struct qemu_work_item wi; - - if (qemu_cpu_is_self(cpu)) { - func(cpu, data); - return; - } - - wi.func = func; - wi.data = data; - wi.done = false; - wi.free = false; - wi.exclusive = false; - - queue_work_on_cpu(cpu, &wi); - while (!qatomic_mb_read(&wi.done)) { - CPUState *self_cpu = current_cpu; - - qemu_cond_wait(&qemu_work_cond, mutex); - current_cpu = 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); -/** - * 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 data, - QemuMutex *mutex); - /** * run_on_cpu: * @cpu: The vCPU to run on. diff --git a/softmmu/cpus.c b/softmmu/cpus.c index 071085f840..52adc98d39 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -382,6 +382,32 @@ void qemu_init_cpu_loop(void) qemu_thread_get_self(&io_thread); } +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; + + if (qemu_cpu_is_self(cpu)) { + func(cpu, data); + return; + } + + wi.func = func; + wi.data = data; + wi.done = false; + wi.free = false; + wi.exclusive = false; + + queue_work_on_cpu(cpu, &wi); + while (!qatomic_mb_read(&wi.done)) { + CPUState *self_cpu = current_cpu; + + qemu_cond_wait(&qemu_work_cond, mutex); + current_cpu = 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); From patchwork Fri Jul 23 19:34:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12396871 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 E98D2C4338F for ; Fri, 23 Jul 2021 19:39:20 +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 B22F660F38 for ; Fri, 23 Jul 2021 19:39:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B22F660F38 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:45314 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m710x-0008WI-Tq for qemu-devel@archiver.kernel.org; Fri, 23 Jul 2021 15:39:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39424) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m70wk-0006EY-BL for qemu-devel@nongnu.org; Fri, 23 Jul 2021 15:34:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45114) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m70wj-0002NI-0g for qemu-devel@nongnu.org; Fri, 23 Jul 2021 15:34:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627068896; 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=5nJr1OIK9JzzTcb6zN39xsOpq6xGnkL38wz1B933W1o=; b=QO++jyhs9+ju9iEq44XNhqHao/0kolVHX62wHrWnBAfLZVXRTQtS6T0mRbB21WzxypnrrD ueScEa5xgAGu0YJvc7lunamKbUWJJuf4gUWh2vEf8T2UzvynZb3t/hZGGz3duhHDaRpVVI ciVm5da+ydMoN1YDKWaKzJcw8B2m1mI= 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-577-DxTyuV3qPx-UEnQgH4Gj3g-1; Fri, 23 Jul 2021 15:34:55 -0400 X-MC-Unique: DxTyuV3qPx-UEnQgH4Gj3g-1 Received: by mail-qv1-f69.google.com with SMTP id kl8-20020a0562145188b02902e01fc8ee77so2350950qvb.21 for ; Fri, 23 Jul 2021 12:34:55 -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=5nJr1OIK9JzzTcb6zN39xsOpq6xGnkL38wz1B933W1o=; b=Azfi2T++nngwtCtBIVoRTEDS1ooqPGbEszuucU7/nCjuAd0ffIx+wBAbU2eNePBtED PJ3oEmLLAXbAV6XIHaW4AGZB2x8trnzMoA+B+f7YBtHdPGIMvhLmOW7dBz8m9NL65/7t 7HPIQ64Lhh7OmLCD+FbuyklHOAaNS+r7hQFUjLi1eet8P5M+ipXReYNJlzkREI71oN+k ObsRrVx/+4nXZUylGzzZif3BXUxg8BcsDgIb6JCErfxKZMIqvpXEDnUz8p8bk3YRINnd 5Q6JswpXs7cBrUCTKxS2ryWUcL/+mJwVN7A3RG6rXAum42KdUU7bX5cjm6YaS34Kl6JG f6Xw== X-Gm-Message-State: AOAM530DidLV9qHe8bXvMVjjMjZNqI/DGm92cb73TyXrIuXp3FSbWADn J2+3i/XOSBpm4zzj0ALQLBQMa7bWeNNLJ9CtWE7f+Y/30JZCjIJbtWyG9lOnlOTuiZ6T4JO5M7L geCY36YFSAhrfre6q7oti49N6B1WNQqK6VZvmfV8kHJR6gubqHD/+tlijYKqHedul X-Received: by 2002:a05:622a:118b:: with SMTP id m11mr5365852qtk.4.1627068894235; Fri, 23 Jul 2021 12:34:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVgx/1MPdWQqQu5JCFh8k64eflGOMGofHgj5uGDlwt6au7QdIxNaC0Jb6i7Lz7xsHNvX9gnQ== X-Received: by 2002:a05:622a:118b:: with SMTP id m11mr5365835qtk.4.1627068893946; Fri, 23 Jul 2021 12:34:53 -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 o2sm12659104qkm.109.2021.07.23.12.34.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 12:34:52 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v2 3/9] memory: Introduce memory_region_transaction_{push|pop}() Date: Fri, 23 Jul 2021 15:34:38 -0400 Message-Id: <20210723193444.133412-4-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210723193444.133412-1-peterx@redhat.com> References: <20210723193444.133412-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 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: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.472, 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 , David Hildenbrand , 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 --- softmmu/memory.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/softmmu/memory.c b/softmmu/memory.c index bfedaf9c4d..1a3e9ff8ad 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1079,10 +1079,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) @@ -1092,7 +1102,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 Fri Jul 23 19:34:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12396863 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 10911C4338F for ; Fri, 23 Jul 2021 19:36:34 +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 A564360E99 for ; Fri, 23 Jul 2021 19:36:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A564360E99 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:33572 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m70yG-0000lc-SW for qemu-devel@archiver.kernel.org; Fri, 23 Jul 2021 15:36:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39450) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m70wo-0006O6-3H for qemu-devel@nongnu.org; Fri, 23 Jul 2021 15:35:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48975) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m70wm-0002QU-JG for qemu-devel@nongnu.org; Fri, 23 Jul 2021 15:35:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627068900; 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=g6S0/tR0WMas8i+0FqgBbnpbGUceg0X5GOSPvU0OplU=; b=OtgZvFf8XKu42y1k2b0LqjIKQYuY35SNuvZoU4l27Yr7QTN6SPxQPfjKzsnl2fcfHuQEmQ zH3ggpd+1R1g1tj9y9jCAMHWLlGINYoVTmoBPEHmZXyFOkcRH6qsOQFk2jW9XFlJ8g7M+G D7WA8WabTY2JnqF2dU1JMsWiu1uhmMw= 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-201-I_gMe9HWO3upq10_j3LUXQ-1; Fri, 23 Jul 2021 15:34:57 -0400 X-MC-Unique: I_gMe9HWO3upq10_j3LUXQ-1 Received: by mail-qv1-f72.google.com with SMTP id gm10-20020a056214268ab02902eaed054a57so2408925qvb.15 for ; Fri, 23 Jul 2021 12:34:57 -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=g6S0/tR0WMas8i+0FqgBbnpbGUceg0X5GOSPvU0OplU=; b=H7WBgDwjflz+dCshTOqOqn8yNZruEjhr0FoMn4WbjOyo1uWT98WQEe+dRzFQpAbbpl VrvNtoGcY98LI46/uwESGNtveEdcl99aM5X745Zf+RLvcUcDzPTWX3JdwJuoyvept0Ul w3VkjgkpZsd85vVetbtWMsl7K5CCLupCarUkvIr3DpI9L4wgxkazCfAKiSvPBee/w745 uDTnw+K0tUlJ9gye01ZijWJiAPuq1fONe9dXXBIAeE5/gSs9s6R+TKzTUypDIhxjWLWD KMRvoBGXW+RzkeBljq9n6qeEGoEcmfV25NL2fjS7ci+Klmth9tbMs4Lf+bdMWKUuG1Kk 3VAQ== X-Gm-Message-State: AOAM5323s5KXJ0k7+vsE7jGayap6l019o9Lv+ecKThpLBb/CUUYtf8XK IsBHrNzhsQow2mKl7obCqivwBtzBF96WPlVqu+3gvn+rR9l1LgRR4neb7jb7zaGVwXGypGVBpg4 aXI/9uxib/8n7N/9fmirVmpQ8iY87J+Q6kZh7NWtaxCSOtX1e9LMxw12M/YDJ9/sv X-Received: by 2002:a05:622a:54e:: with SMTP id m14mr5339545qtx.74.1627068896268; Fri, 23 Jul 2021 12:34:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOeO7kYn5EQqrIOVXeXxU0dTmjJmttRBnf4OW4ka4eTc/C1wvtHuAt+YlheW18hqOdTqKuRA== X-Received: by 2002:a05:622a:54e:: with SMTP id m14mr5339523qtx.74.1627068895967; Fri, 23 Jul 2021 12:34:55 -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 o2sm12659104qkm.109.2021.07.23.12.34.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 12:34:55 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v2 4/9] memory: Don't do topology update in memory finalize() Date: Fri, 23 Jul 2021 15:34:39 -0400 Message-Id: <20210723193444.133412-5-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210723193444.133412-1-peterx@redhat.com> References: <20210723193444.133412-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 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: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.472, 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 , David Hildenbrand , peterx@redhat.com, Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 Signed-off-by: Peter Xu Acked-by: David Hildenbrand --- softmmu/memory.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/softmmu/memory.c b/softmmu/memory.c index 1a3e9ff8ad..dfce4a2bda 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -170,6 +170,12 @@ struct MemoryRegionIoeventfd { EventNotifier *e; }; +/* 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 = false; - memory_region_transaction_begin(); + + /* + * Use push()/pop() 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_push(); while (!QTAILQ_EMPTY(&mr->subregions)) { MemoryRegion *subregion = QTAILQ_FIRST(&mr->subregions); memory_region_del_subregion(mr, subregion); } - memory_region_transaction_commit(); + memory_region_transaction_pop(); + + /* + * 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()); mr->destructor(mr); memory_region_clear_coalescing(mr); From patchwork Fri Jul 23 19:34:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12396865 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 EC04DC4338F for ; Fri, 23 Jul 2021 19:36:36 +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 AECDD60F37 for ; Fri, 23 Jul 2021 19:36:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AECDD60F37 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:33740 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m70yJ-0000sy-RA for qemu-devel@archiver.kernel.org; Fri, 23 Jul 2021 15:36:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39446) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m70wn-0006NC-Fw for qemu-devel@nongnu.org; Fri, 23 Jul 2021 15:35:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20683) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m70wm-0002Q8-2g for qemu-devel@nongnu.org; Fri, 23 Jul 2021 15:35:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627068899; 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=jDJuGytz2IzGkl27XsjXnAQtzsd9r+txZlchoEebT5o=; b=PmWI3Oj8qU15PuGMQ1yXynYl2Ysrv80hQ+MM/4pCU3ix39vq3Hp0WcbUUsVgZxvBzWLqjC Pj8clxUI0C6txzj2OibjJHza9/RL6RGw7A8fXXJcvq3Fq35xv/h0+Y255/QAq5eI0CZnly FrUB+/BCs+2Vu1jbQHjpjeIPmn3aSFY= 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-591-57faYHM_MBOG1wpYtjscRQ-1; Fri, 23 Jul 2021 15:34:58 -0400 X-MC-Unique: 57faYHM_MBOG1wpYtjscRQ-1 Received: by mail-qk1-f200.google.com with SMTP id h5-20020a05620a0525b02903b861bec838so1920834qkh.7 for ; Fri, 23 Jul 2021 12:34:58 -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=jDJuGytz2IzGkl27XsjXnAQtzsd9r+txZlchoEebT5o=; b=eUMN8iuMmknoEFAGTcbDTQf6jp/+3FaH4VFO+D1V8WK/cJu75a0Oerc0djetoZ4C/0 A+QYhcKylhOsGboh6dARoNmkAHFVDHQdzgba/4Lhs9KlRIf12k5LAEwAuVZgVOGiL4MK fooSBe+koelWwPq0SzWQXvAya8og7FH/HMqGdlh4e1TTrROhLch89PFGfMEQctKC/9qg GV8wouXZeqk9oDY6Lo+PtwhGCABMUbHA5oMyXIDMNYFOfCWRCkodgNSCMdkSbe/gb4zL mvhMIY73u5WOue72y4cfaocQfmeJ76rLYovup9YGGG3s0OSg06PvETNuB8n5IzvtUBVV j7Vw== X-Gm-Message-State: AOAM532/8JsUv6mbWHfwMvcmfNk44EsqrtpARNy9RX4qXWstFOd6Tzsi SkV9g6jYe1aWHabuc7ufeT7EpS6ha7YROQkImP3N3R8giMjW0ucoO9Fsqy125rKO5AJD4LyIYx+ ssyt7ghxVNXVUWL6Uq+XUW1VN3WopXCzLDCQrTWBGrTDq6olMBqgQ1FFdU63sTMmT X-Received: by 2002:ac8:7ed9:: with SMTP id x25mr5391221qtj.202.1627068897655; Fri, 23 Jul 2021 12:34:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7uOpMFIgPmsLxTiFcubEW0MZm704OjA8gxpe4J0a2XHJDZ9pgaL7+fa9y7WJXni0JZgikxw== X-Received: by 2002:ac8:7ed9:: with SMTP id x25mr5391201qtj.202.1627068897386; Fri, 23 Jul 2021 12:34:57 -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 o2sm12659104qkm.109.2021.07.23.12.34.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 12:34:56 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v2 5/9] cpus: Use qemu_cond_wait_iothread() where proper Date: Fri, 23 Jul 2021 15:34:40 -0400 Message-Id: <20210723193444.133412-6-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210723193444.133412-1-peterx@redhat.com> References: <20210723193444.133412-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 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: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.472, 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 , David Hildenbrand , 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 Reviewed-by: David Hildenbrand --- softmmu/cpus.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/softmmu/cpus.c b/softmmu/cpus.c index 52adc98d39..94c2804192 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -442,7 +442,7 @@ 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); @@ -585,7 +585,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); } @@ -656,7 +656,7 @@ void qemu_init_vcpu(CPUState *cpu) cpus_accel->create_vcpu_thread(cpu); while (!cpu->created) { - qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex); + qemu_cond_wait_iothread(&qemu_cpu_cond); } } From patchwork Fri Jul 23 19:34:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12396869 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 94BFBC4320A for ; Fri, 23 Jul 2021 19:38:18 +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 3A5F660F38 for ; Fri, 23 Jul 2021 19:38:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3A5F660F38 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:41112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m70zx-0005kF-EW for qemu-devel@archiver.kernel.org; Fri, 23 Jul 2021 15:38:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m70wq-0006V2-CS for qemu-devel@nongnu.org; Fri, 23 Jul 2021 15:35:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:41519) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m70wo-0002RM-SE for qemu-devel@nongnu.org; Fri, 23 Jul 2021 15:35:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627068902; 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=YvPN0aH3/5SMjris6GibIvLCqdDoM69TD+/vZGC1aH4=; b=HIa+DsB7JfBONrID03YpKPSdo3RkU3HJfs5sWZ2mhRn/T6AI+2Ih2+XN1Gwx5Fmau2TKAc y6X3vI2JwvlNm9AILeqLiZY8Ss0qTW3N+jUrlJMFKedn+dDt+rZ9p63n3e+w6FnuBKJq3A DKsfABqrrmfV+tmNG8u9dLxY53ynQ24= 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-252-PaD_ZgVDNYSAI2qHwjcM9g-1; Fri, 23 Jul 2021 15:34:59 -0400 X-MC-Unique: PaD_ZgVDNYSAI2qHwjcM9g-1 Received: by mail-qk1-f200.google.com with SMTP id u22-20020ae9c0160000b02903b488f9d348so1850704qkk.20 for ; Fri, 23 Jul 2021 12:34:59 -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=YvPN0aH3/5SMjris6GibIvLCqdDoM69TD+/vZGC1aH4=; b=tmnImGP+Y3DBakyTj+nw2MsEy8YZ8CI1uyn+jrY7tXF/BWr3L8nMz6kIggwqxMlCoV 3EUVmsw8IfARAT1xxSZRra+UD5gh6aGxsOvjFNEzZ6orwvOLUqEDJ9LM0VSQ+iN/4rnO MDEve9+d/P1cc+1fVE3NVCW4MbHXVsG9gCiSRksOsBzjq/+TVDriG8oygZ/zZui9rvUP ck6gWV9pyheSQujVN28bUeWvz/1DFCUwLG0ZKR0/yHfu/Hg5nrgzX+iOIAFqy9ayKGLD Dg9IFAPZDPbLICr/D/Fn1wMMMg6FeJexe+3aBKSo1JZALT6Le4sXDJy3Hw9R5CRpaeoI 1clQ== X-Gm-Message-State: AOAM532xvgx2L2tBGY4qmgBtsR5yQfg3Y6/bbBjTsl9B7YT+7UXBoqdg 7JAUGLjiwK1u8ilkIL6K53/VFS/V/J09vZ17K1Cln0xHVXhuHR+zI4IITIAA/od1sz5qno5vCLe 2p74y1jStL/Ycx0KAjG2bH5Edf0IQLuqkgCoxvXw7DFHpqp9BuKdFBpGGSplUBRVw X-Received: by 2002:ac8:7ca3:: with SMTP id z3mr5360148qtv.118.1627068898858; Fri, 23 Jul 2021 12:34:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrbQQAKvQjPe2AATj7zCpz5jN1uGJMGcAp0AgL85MDJ145MoJVIYZ7RDkDvaLgwKUG+wDQ9A== X-Received: by 2002:ac8:7ca3:: with SMTP id z3mr5360126qtv.118.1627068898603; Fri, 23 Jul 2021 12:34: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 o2sm12659104qkm.109.2021.07.23.12.34.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 12:34:57 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v2 6/9] cpus: Remove the mutex parameter from do_run_on_cpu() Date: Fri, 23 Jul 2021 15:34:41 -0400 Message-Id: <20210723193444.133412-7-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210723193444.133412-1-peterx@redhat.com> References: <20210723193444.133412-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 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: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.472, 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 , David Hildenbrand , 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 Reviewed-by: David Hildenbrand --- softmmu/cpus.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/softmmu/cpus.c b/softmmu/cpus.c index 94c2804192..9131f77f87 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -383,8 +383,7 @@ void qemu_init_cpu_loop(void) } 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; @@ -403,14 +402,14 @@ do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data, while (!qatomic_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; } } 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_cpu_stop(CPUState *cpu, bool exit) From patchwork Fri Jul 23 19:34:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12396877 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 3EA7DC4338F for ; Fri, 23 Jul 2021 19:41:18 +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 C069160EAF for ; Fri, 23 Jul 2021 19:41:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C069160EAF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:49732 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m712q-00038L-T4 for qemu-devel@archiver.kernel.org; Fri, 23 Jul 2021 15:41:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39488) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m70wq-0006Vx-L5 for qemu-devel@nongnu.org; Fri, 23 Jul 2021 15:35:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:35091) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m70wo-0002RR-WD for qemu-devel@nongnu.org; Fri, 23 Jul 2021 15:35:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627068902; 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=QMg0qB0xoJcBQNJ7ML75cem+ABD+BhEtcoCp8aunrsI=; b=N1s+SFWecTTaUAcTmPmnubtzHqltAA7M4v/nKO9fxO5HFwAm9s2ExF5Ko+tK/+mKNbhbzu eqeLtWpD5p28ulxVqWIxDtk0d9bZFJko0iPqffelEWakYI1CNS4wfIoppTnbIVCycls8mP 3ROqiHDrX/IR8mugdh3JP5aArxWoB7M= 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-208-oFh2Ztc3OgKNCx-mA8wOSQ-1; Fri, 23 Jul 2021 15:35:01 -0400 X-MC-Unique: oFh2Ztc3OgKNCx-mA8wOSQ-1 Received: by mail-qt1-f199.google.com with SMTP id e16-20020ac867100000b0290257b7db4a28so1719407qtp.9 for ; Fri, 23 Jul 2021 12:35:01 -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=QMg0qB0xoJcBQNJ7ML75cem+ABD+BhEtcoCp8aunrsI=; b=PjFtMCDyomvqEOMEHIYYlhok3ICnIaYdtW5NvQVQ8gRcLph8s65S5NWluMw4mYwZej /kvD/Ueb2RlUR1QybxcRmgotleqBUNqm891OtU+akgtRpXquUl3X5ONW66o41NVafRKT q13TzTJsD7WdEoxitI0XIZK6qEu8tsYbsa041dg03Aek8mTD2g3qjgRvJYEL1rFfauku ogMEGoiR9nPB2R01zQXlcCQJdD6muUb/CbXKIiZuARSN79z6DrOhUO7RlBo6UCVh6JQD 3k3ez6J+G6xdXShWPuaiyle4Eex+2+mK27oCv/YqBG91jUibqKMm+ODlFK+JfjGGr5aN lC+A== X-Gm-Message-State: AOAM532O8YNCDXtQ9QDf6TsGcDtiS729JHOqUSB4D78kLn/U4pbtULIY 4LkDUsdUypzmX+5oI6yXjXOdJcLBF8uGKveXpEiJJ2GpMplvM4vsA9ae5iEpeydwHCuDu+gH1E4 RzeJsrZftt9P9+oc7M+HDdrDsRWyADh0SSUAvExUEOFeZ3hBOL9CnZti3jVNGMNxK X-Received: by 2002:a37:af84:: with SMTP id y126mr6244203qke.448.1627068900297; Fri, 23 Jul 2021 12:35:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwU4kG86Sfik4q0KCkLzzZF61DSrf2SX8hJegsv3o89r0TgiQhJrBiHqC89+clAOdS3KQiG5g== X-Received: by 2002:a37:af84:: with SMTP id y126mr6244175qke.448.1627068900020; Fri, 23 Jul 2021 12:35:00 -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 o2sm12659104qkm.109.2021.07.23.12.34.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 12:34:59 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v2 7/9] cpus: Introduce qemu_mutex_unlock_iothread_prepare() Date: Fri, 23 Jul 2021 15:34:42 -0400 Message-Id: <20210723193444.133412-8-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210723193444.133412-1-peterx@redhat.com> References: <20210723193444.133412-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 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: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.472, 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 , David Hildenbrand , peterx@redhat.com, Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The prepare function before unlocking BQL. There're only three places that can release the BQL: unlock(), cond_wait() or cond_timedwait(). Signed-off-by: Peter Xu --- softmmu/cpus.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/softmmu/cpus.c b/softmmu/cpus.c index 9131f77f87..6085f8edbe 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -66,6 +66,10 @@ static QemuMutex qemu_global_mutex; +static void qemu_mutex_unlock_iothread_prepare(void) +{ +} + bool cpu_is_stopped(CPUState *cpu) { return cpu->stopped || !runstate_is_running(); @@ -523,16 +527,19 @@ void qemu_mutex_unlock_iothread(void) { g_assert(qemu_mutex_iothread_locked()); iothread_locked = false; + qemu_mutex_unlock_iothread_prepare(); qemu_mutex_unlock(&qemu_global_mutex); } void qemu_cond_wait_iothread(QemuCond *cond) { + qemu_mutex_unlock_iothread_prepare(); qemu_cond_wait(cond, &qemu_global_mutex); } void qemu_cond_timedwait_iothread(QemuCond *cond, int ms) { + qemu_mutex_unlock_iothread_prepare(); qemu_cond_timedwait(cond, &qemu_global_mutex, ms); } From patchwork Fri Jul 23 19:34:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12396873 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 59C5DC432BE for ; Fri, 23 Jul 2021 19:39:22 +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 2677860F37 for ; Fri, 23 Jul 2021 19:39:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2677860F37 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:45392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m710z-00008c-Bz for qemu-devel@archiver.kernel.org; Fri, 23 Jul 2021 15:39:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39496) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m70wr-0006Zm-PD for qemu-devel@nongnu.org; Fri, 23 Jul 2021 15:35:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32983) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m70wp-0002SS-Tq for qemu-devel@nongnu.org; Fri, 23 Jul 2021 15:35:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627068903; 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=n60YpD2jRfME+kNkqr3g07wbTXEad9D8JchKCn5/hoA=; b=iyTP3rYqRZ8+xKjyjrNKlm+Cog4YCpOAW9QUu4XhBELOfR6RfCdYaL15FEm9LYK10EVjx9 lSlDSfigV7Bw6ArxQb5Y32gwr/Yi296UfYUQd0uOt7+smIQJDZRS0DqlEBESgsa/hGfiK0 kUzHumQoa+j1+Knf0CgCVl0qdnAiX34= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-360-b0Mb_9OBMeGaAjrhS8Nxzw-1; Fri, 23 Jul 2021 15:35:02 -0400 X-MC-Unique: b0Mb_9OBMeGaAjrhS8Nxzw-1 Received: by mail-qk1-f198.google.com with SMTP id bm25-20020a05620a1999b02903a9c3f8b89fso1954680qkb.2 for ; Fri, 23 Jul 2021 12:35:02 -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=n60YpD2jRfME+kNkqr3g07wbTXEad9D8JchKCn5/hoA=; b=Hcwo1Tfzp/uPP4zbnYtYpC1rjn241faz6LiRhl9z/BAMtTS/yshzm9C0FyS/Sh9ds9 1KC/8KDNZ2AbqmlKwagC7zibBii6Dt0W+iE2oaDRjXEGno0k6p6juyXqHo/z+P0woP3K NqIFYrUVUQMRmPlPNn/hfs32GsAxUCmPHwph/Jjtxu/QIzB+7Q4ZsSM9Et8Wg+SAbnwF 4p5edaoS9aD92CvyZQOI2vHW4+9dcWIbV/sTFVYUh5xL4ZZZV9ajp69C+gASfm3CoXfq V5kTwU4BKu0d52T+aNWjeuMAaCH5S9VXGeoippiGJlxXQDQ0hINE3zU1BTw7bTlJafL7 ZYvQ== X-Gm-Message-State: AOAM532A/H2Qtvh6LGkyG8lfSdbE4Uh3yxmiLkZstvKcxJz6ii1U7ggw qcjKBjwkiJdnbFTcQIEk8PHuEkypdVxeRTRyxOCBEEZ73WGwDM7T9re17tk79leLOrbjoq23Hyh I4r9jAljxau33zOXZVTWBcDYjEfe0q3JoA+WJSZegphK8PC14C5+rUogvaknK2ak3 X-Received: by 2002:a37:a004:: with SMTP id j4mr6056020qke.499.1627068901581; Fri, 23 Jul 2021 12:35:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVbMrmd/d7C9Rp+Q9dZEWzGkMxXzQlHED0HbByvYXvbD4Ri0a6G59ZjvzFdsSPxOUoIxWUbQ== X-Received: by 2002:a37:a004:: with SMTP id j4mr6055996qke.499.1627068901341; Fri, 23 Jul 2021 12:35: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 o2sm12659104qkm.109.2021.07.23.12.35.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 12:35:00 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v2 8/9] memory: Assert on no ongoing memory transaction before release BQL Date: Fri, 23 Jul 2021 15:34:43 -0400 Message-Id: <20210723193444.133412-9-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210723193444.133412-1-peterx@redhat.com> References: <20210723193444.133412-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 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: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.472, 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 , David Hildenbrand , 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 Reviewed-by: David Hildenbrand --- include/exec/memory-internal.h | 1 + softmmu/cpus.c | 2 ++ softmmu/memory.c | 6 ++++++ 3 files changed, 9 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_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/softmmu/cpus.c b/softmmu/cpus.c index 6085f8edbe..14a50289f8 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" @@ -68,6 +69,7 @@ static QemuMutex qemu_global_mutex; static void qemu_mutex_unlock_iothread_prepare(void) { + assert(!memory_region_has_pending_transaction()); } bool cpu_is_stopped(CPUState *cpu) diff --git a/softmmu/memory.c b/softmmu/memory.c index dfce4a2bda..08327c22e2 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; } +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 Fri Jul 23 19:34:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12396879 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 6013FC4320A for ; Fri, 23 Jul 2021 19:41:22 +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 11D2760F4D for ; Fri, 23 Jul 2021 19:41:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 11D2760F4D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:49814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m712r-0003BP-Te for qemu-devel@archiver.kernel.org; Fri, 23 Jul 2021 15:41:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m70wv-0006ah-KM for qemu-devel@nongnu.org; Fri, 23 Jul 2021 15:35:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:25643) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m70wr-0002Tb-OC for qemu-devel@nongnu.org; Fri, 23 Jul 2021 15:35:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627068905; 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=cgE+pvg8R5s4SHNQFQzuWvFk/uzjmRfZhE2Kfnw38pE=; b=NERryiga/tMYOR6qrVmn8DzAGQUUYl9vsy6Nd3Sy0smJ8d6/QPQuw4eV81n0lRnvR84Vr1 KxCwlqir03Qczz2ho5aOWWVdae+8h9hNro07TnBDDCcHWI4eltzHmMyna6Dspc464VbGSn EcMn7tfTuEU6CYhYO9YXuqjLnAhXglw= 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-358-L4ONzdobO3WioQ5VIHchHg-1; Fri, 23 Jul 2021 15:35:04 -0400 X-MC-Unique: L4ONzdobO3WioQ5VIHchHg-1 Received: by mail-qv1-f69.google.com with SMTP id gg10-20020a056214252ab02902f3a4c41d77so2388145qvb.18 for ; Fri, 23 Jul 2021 12:35:04 -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=cgE+pvg8R5s4SHNQFQzuWvFk/uzjmRfZhE2Kfnw38pE=; b=ni0wziH6cGInzcOkpuJKdEAvvqfFJ6yxuwxhjwRNhCyTHw/NNqOjwLTc/DZxmCUU4F DHyvkrG0MdcxYQWICcVBpCLu7stonVHz6RDKF+K+m4WOgjnrDv1D10DLEFTTB2HClJ9b ibTnxm5J3jrPvqmurTEUpK2dYWX0S2Q5f89gZ/eaT2l8RKKWMPu0t3f1+t+a+5zxVGWw pa/CV8b2rwaFWENL7qcjf70VQm4TT+V49TQyL3uajsTW6yJHq9D0yMofWe/042DIWg3c fPQAHXK9wcHTS4NtKjxSEM/8Zx45nsExPsZ5JgMhoxaBZF+6objKvEw/yWS9HyP4ESxo TbEw== X-Gm-Message-State: AOAM531T9vWf8rlofmmD67qxJrScbM/Mtf/y0zJY/3EiMABhdqGKFMWR AvGReymGZHhTG51lBC2ruZWxV3b3FtQuILqBlJEXe5LF6YamI+U0dAdtOTY21UjLUL51AorBTPJ 42ygNxGZQpP0v/awpMVYdQZdJxa0cs6loiuT0uCvQXleeYisHqRA+mdgLT5TU2B4U X-Received: by 2002:ae9:ef10:: with SMTP id d16mr6221479qkg.264.1627068903285; Fri, 23 Jul 2021 12:35:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3v4szRKKyZvFCXF17io+sQcR8o99rvmJzp6qfRKRgE7hIwBxJr/VHLbbF+CUzruP7EyDV9w== X-Received: by 2002:ae9:ef10:: with SMTP id d16mr6221454qkg.264.1627068903027; Fri, 23 Jul 2021 12:35: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 o2sm12659104qkm.109.2021.07.23.12.35.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 12:35:01 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v2 9/9] memory: Delay the transaction pop() until commit completed Date: Fri, 23 Jul 2021 15:34:44 -0400 Message-Id: <20210723193444.133412-10-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210723193444.133412-1-peterx@redhat.com> References: <20210723193444.133412-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 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: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.472, 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 , David Hildenbrand , 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 --- softmmu/memory.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/softmmu/memory.c b/softmmu/memory.c index 08327c22e2..cf7943c02c 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()); - memory_region_transaction_pop(); - if (!memory_region_transaction_depth) { + if (memory_region_transaction_depth == 1) { if (memory_region_update_pending) { flatviews_reset(); @@ -1134,7 +1133,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)