From nobody Sat May 18 12:12:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1587486165; cv=none; d=zohomail.com; s=zohoarc; b=EAqscrqKDNJ8mKiUT4XNZwDqVNrRSwfm/r+sl0f55AHXpTAUEpnvkLuBeChuohVvR6p4JIQpkqplVzV50knwsZhpG3E/32g+YEJCY3GW2O40tDflNmSbkmrjiHqubmp4yQN0QvpE5o1zUYtEHJ1rpWUVQTUBE4elyrticiJeFjg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587486165; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=I0YrSfJZG3OCin0XwLpQsE2WSkg0EXuV6HT6X0zjKVY=; b=OqfpC6eU6Wkj9aaAu8wFwYB9+HqMqDb3rG5/VbXfjIntHrgCYEfcY84GUzm8LqjHQa4C8xnlVLFn2wRmrqCEgxJLKW85IOQv8rBkhXxUR49C45gLfnKMuPIJXN0R05e42UkQlfWPSHA2ImLjrY76gCmYEDJeaAkCtTIsdvSxPy4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587486165725725.521130491634; Tue, 21 Apr 2020 09:22:45 -0700 (PDT) Received: from localhost ([::1]:32776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQvfX-0001x8-DW for importer@patchew.org; Tue, 21 Apr 2020 12:22:43 -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 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 Received: by mail-qt1-f197.google.com with SMTP id f56so15324186qte.18 for ; Tue, 21 Apr 2020 09:21:16 -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) 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= X-MC-Unique: bTONjKJXMB-TwcXF8KhEnQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" memory_region_transaction_{begin|commit}() could be too big when finalizing= a memory region. E.g., we should never attempt to update address space topol= ogy during the finalize() of a memory region. Provide helpers for further use. Signed-off-by: Peter Xu --- 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(AddressSp= ace *as) address_space_set_flatview(as); } =20 +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(); } =20 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()); =20 - --memory_region_transaction_depth; + memory_region_transaction_pop(); if (!memory_region_transaction_depth) { if (memory_region_update_pending) { flatviews_reset(); --=20 2.24.1 From nobody Sat May 18 12:12:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1587486165; cv=none; d=zohomail.com; s=zohoarc; b=Z1LMYNEqiSrqs/Iz8T7ApkvdJDFznaM75aD4OsH82g3uKEGPZaOCTq6M36uCuliZS0NRPdJOfGGYzBhVUMyuu2S9zE4kX3udgwI8WZZySOSM4ml3Ces23mLXSTKNi9sr/pwD2+fSNs00ngQPQqJyU8bHqots5taLePXXtCXTfBw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587486165; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZWARAODmBStGiYrFPvbCFJNkPOytrLfsKcpWRULN7JI=; b=GqydZmzwImMY9U6QdatDUslUDwwatPQOzUwGsIGojmk7ZRQpv3snohHWNqEuiiVmzO9EI0WE/25976IKiDHB0J+HV0pHtmcqHPtwrUTKoc8Fdn6sS2JDJy1K0e+jdvx1G8d9Q0t3xueucrqIqNHtIrCTYbmsr/kYUXAz/zvQrfE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587486165598541.2821615877565; Tue, 21 Apr 2020 09:22:45 -0700 (PDT) Received: from localhost ([::1]:32778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQvfW-0001xM-Dp for importer@patchew.org; Tue, 21 Apr 2020 12:22:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54008) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQveI-0000mf-Gl 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 1jQveD-00046X-EP for qemu-devel@nongnu.org; Tue, 21 Apr 2020 12:21:26 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:55633 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 1jQveD-00046F-2x for qemu-devel@nongnu.org; Tue, 21 Apr 2020 12:21:21 -0400 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-230-w_v2Gy5NPiOCpfR1i78Bcg-1; Tue, 21 Apr 2020 12:21:18 -0400 Received: by mail-qk1-f200.google.com with SMTP id a187so14579401qkg.18 for ; Tue, 21 Apr 2020 09:21:18 -0700 (PDT) Received: from xz-x1.redhat.com ([2607:9880:19c0:32::2]) by smtp.gmail.com with ESMTPSA id h2sm2043688qkh.91.2020.04.21.09.21.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 09:21:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587486080; 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=ZWARAODmBStGiYrFPvbCFJNkPOytrLfsKcpWRULN7JI=; b=PSRR2OhwcWkW6Ig5qrCmQqUmw9Ac/ckFRA0kCEzHQybdY8/xo05oyNDTV5Vb4jnozQAaVC oyQsHd57ppccsob/okAC5uGDvZbJmYc8+H+qRp4RnnjkATWIJkCktiUjGCMruZBhcfpoBH NrO/6YOXTItzhD7ARi88LTZHPC6lJ54= X-MC-Unique: w_v2Gy5NPiOCpfR1i78Bcg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O9l/BvBydUlEJUjD9a9P0sgBp3L6+LGe0OTTKmSjbXg=; b=bKus1GnmzFSuur0nj5DTS/UNgZAA/uxRJ7jz8BTSXQpPdLulOPNlpPQ7kjTeU9eNdL glomsxa7cEvz9IIxiKfEZ3GYalr7lZUo3IcaAeKeFOUZmwXqIWhO5z1w6TQaATTRZhiB k21wGwWtVrS6/Qd3iq84XGkXCgEMz6e56Aft7dLX1O/o4SXHZtmfDx+EGWuTCa4oIZe2 X1OrUNd3fRW3/M7sTBAVD7AO8MbJzNqKgg3aBoq5iNNPwb0sXE+EjN4fBnil0FI4rQ0G MFihFhX7UzmYmXMWX+gA2fxq2QJvtrQZD2TMo881Le4dHr/i/l2I0oqbgmVzZ+kUOqiI lwUw== X-Gm-Message-State: AGi0PuYvhzRjHxr6tERzUGOBoJosO6wJ+aleRSD3RFUB21ccq28p8/4a FE6XnI8KzsZQkptwyNduuCdSVI9gOdAdJJ8fOdw27GFDLbZtS5fUUBMEv0Fq36EfwFtBBscVdch 8Qu0kamf5GLA8PjI= X-Received: by 2002:a05:620a:228:: with SMTP id u8mr22773764qkm.309.1587486077885; Tue, 21 Apr 2020 09:21:17 -0700 (PDT) X-Google-Smtp-Source: APiQypJwmIMZM1MbMcC9Qf5/Wp3f7cgLATEQeVTID+i/5dJRNXJOjG/HWTnMlDs5xF3EQ1P+tlfhWA== X-Received: by 2002:a05:620a:228:: with SMTP id u8mr22773736qkm.309.1587486077630; Tue, 21 Apr 2020 09:21:17 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 2/8] memory: Don't do topology update in memory finalize() Date: Tue, 21 Apr 2020 12:21:02 -0400 Message-Id: <20200421162108.594796-3-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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Topology update could be wrongly triggered in memory region finalize() if there's bug somewhere else. It'll be a very confusing stack when it happens (e.g., sending KVM ioctl within the RCU thread, and we'll observe it only until it fails!). Instead of that, we use the push()/pop() helper to avoid memory transaction commit, at the same time we use assertions to make sure there's no pending updates or it's a nested transaction, so it could fail even earlier and in a more explicit way. Suggested-by: Paolo Bonzini Signed-off-by: Peter Xu --- memory.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/memory.c b/memory.c index e5d634d648..fea427f43f 100644 --- a/memory.c +++ b/memory.c @@ -171,6 +171,12 @@ struct MemoryRegionIoeventfd { EventNotifier *e; }; =20 +/* Returns whether there's any pending memory updates */ +static bool memory_region_has_pending_update(void) +{ + return memory_region_update_pending || ioeventfd_update_pending; +} + static bool memory_region_ioeventfd_before(MemoryRegionIoeventfd *a, MemoryRegionIoeventfd *b) { @@ -1730,12 +1736,25 @@ static void memory_region_finalize(Object *obj) * and cause an infinite loop. */ mr->enabled =3D false; - memory_region_transaction_begin(); + + /* + * Use push()/pop() instead of begin()/commit() to make sure below blo= ck + * won't trigger any topology update (which should never happen, but i= t's + * still a safety belt). + */ + memory_region_transaction_push(); while (!QTAILQ_EMPTY(&mr->subregions)) { MemoryRegion *subregion =3D QTAILQ_FIRST(&mr->subregions); memory_region_del_subregion(mr, subregion); } - memory_region_transaction_commit(); + memory_region_transaction_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()); =20 mr->destructor(mr); memory_region_clear_coalescing(mr); --=20 2.24.1 From nobody Sat May 18 12:12:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1587486256; cv=none; d=zohomail.com; s=zohoarc; b=TsFLuzLfBLVDsDAlGwRbLjB+66G/3eHz603+VnVhyqYfxDKrc2cPkFBQZ5fdaXhuKnmMaN56ft8EKWpWBhswdU56g9O6ltpJ1cZG0jOaxMLwXCQic07nKezycQUPRc62RmyK8Cuc01RisoeAYLms4r23EmgYA7acNQGD7SQEqwk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587486256; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2H+OgQwZ9zhEE73FazNnzT/qTkBaiVyceFFMEZU4064=; b=RgIuTVmWaA1u/N9OjiPFhr6n3KbKLpM8HwDaU9vD1GTZONlPmWB26piQa4xD5KhPTNC6805lP3B2IdTtyB2spYfzUAUpJQElhBdCAT3JHAymoFqr6YWuPrxfQpMJWBKvuluOOlACliBARdToRfa8GmlJ1sLAKk2btfLnYBlc3Tk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587486256543200.40673301611025; Tue, 21 Apr 2020 09:24:16 -0700 (PDT) Received: from localhost ([::1]:32814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQvh0-0004d8-MK for importer@patchew.org; Tue, 21 Apr 2020 12:24:14 -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 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 Received: by mail-qv1-f72.google.com with SMTP id b4so14286828qvt.15 for ; Tue, 21 Apr 2020 09:21:23 -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) 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= X-MC-Unique: 8khLdJz-PnKbUjBtPie0tg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The helper is introduced but we've still got plenty of places that are dire= ctly referencing the qemu_global_mutex itself. Spread the usage. 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) =20 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); } =20 start_tcg_kick_timer(); @@ -1200,7 +1200,7 @@ static void qemu_wait_io_event(CPUState *cpu) slept =3D true; qemu_plugin_vcpu_idle_cb(cpu); } - qemu_cond_wait(cpu->halt_cond, &qemu_global_mutex); + qemu_cond_wait_iothread(cpu->halt_cond); } if (slept) { qemu_plugin_vcpu_resume_cb(cpu); @@ -1456,7 +1456,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg) =20 /* 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); =20 /* 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(); =20 while (!all_vcpus_paused()) { - qemu_cond_wait(&qemu_pause_cond, &qemu_global_mutex); + qemu_cond_wait_iothread(&qemu_pause_cond); CPU_FOREACH(cpu) { qemu_cpu_kick(cpu); } @@ -2087,7 +2087,7 @@ void qemu_init_vcpu(CPUState *cpu) } =20 while (!cpu->created) { - qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex); + qemu_cond_wait_iothread(&qemu_cpu_cond); } } =20 --=20 2.24.1 From nobody Sat May 18 12:12:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1587486371; cv=none; d=zohomail.com; s=zohoarc; b=lymBLnt9tgFh0FUpD5EL+LtR5NrB6gNRQaDX07zxyONkIv1+Rv5ivBmkvPKQM/MxMksdJaKXkSuKK753EJQbMUDT9zl8T+QO1MK1vwWMYMU58dJaNadnxfAGUNa/PS9zPI1zywBXM8SvpK1ditnsD2W41cvVvPxS/yldYYxeF/4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587486371; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wfxPjer3693hNyeNhfCTsgqPk6evPUCTajLlOJ7juug=; b=mGnEA1+7XwrHQrHsjCsCWbZh7lLmg4MtNlFQt62eOazLbvQxBhOxZhjGefC44rRFD7LZIOCOH2MZkfAGq9AkgG5liAhkWqgVNIgkpQLij3R2vXV72k7K5PU7gIe1vKsODzlabmQZJZLPMQUd+GCm6jAsXmR0hhiRWvLCE/eics8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587486371295169.3254114715579; Tue, 21 Apr 2020 09:26:11 -0700 (PDT) Received: from localhost ([::1]:32870 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQvis-0007J5-0B for importer@patchew.org; Tue, 21 Apr 2020 12:26:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54038) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQveL-0000qS-Cj 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 1jQveK-0004BI-L6 for qemu-devel@nongnu.org; Tue, 21 Apr 2020 12:21:29 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:43958 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 1jQveK-00049p-7e for qemu-devel@nongnu.org; Tue, 21 Apr 2020 12:21:28 -0400 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-228-Cw98MCrjM6O0BF4Wks1YIA-1; Tue, 21 Apr 2020 12:21:24 -0400 Received: by mail-qk1-f197.google.com with SMTP id f187so14601955qkd.11 for ; Tue, 21 Apr 2020 09:21:24 -0700 (PDT) Received: from xz-x1.redhat.com ([2607:9880:19c0:32::2]) by smtp.gmail.com with ESMTPSA id u17sm2065530qka.0.2020.04.21.09.21.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 09:21:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587486086; 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=wfxPjer3693hNyeNhfCTsgqPk6evPUCTajLlOJ7juug=; b=Xb6DoRYKa3qZd9WzVEw9m+aTDPfZsH/B62tLa89BV1ZYlohXg+ds01JpAhevddaJTVa3K5 CuUj9Hu6qLBRuRZAUfzfKuC4eW/FAHyodwVhk2fMTmFHhENZuSA0cvdWJ7tCM5Bz6OOfg4 pinZGTmZ7FudUW7P6n3w58MafZpVwCo= X-MC-Unique: Cw98MCrjM6O0BF4Wks1YIA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ul0LDfa/tHiLxLabo660k4W93ALf8ff07OzkSYpgBqo=; b=q9P0fx6hWfqgHYWbrzCidDvcyt8lSKE2arTzaGHCTLihRZGPtutiOJQVHKgQfRaaz9 Smsv/f5TU9+BteCM/bX7rWwloJW4rPgHKMuqbwM6io8LM3qeGl3Mw9HFeFhTUvqMBlhc 45Uro+gtJxB3wfq8iVs/jsPWlcIBGrxTyYDz9pN63FKNyZnIyP5FmkOe/e86lS0OJGrN t8QHqsn6tye+yID7emTgfsbI/w7C0h/74DHBO2U/5G1eyh/5eSWbu/8zrtpsJLzLdWoA MLSmFTwrAQ9EzTbtfO8a34GN8c7ICCCtzJfZgIwxzLt5c8B0C9nb8kOLaA3cYeeXmxm2 MYyw== X-Gm-Message-State: AGi0PubA0CeRL1ntmDmyjveGQS0NXQ3PI17Vv660OMRkdmYko7XWaNbc dfKyxB72+e3Kjt4mnSeuY96y51VRmPl65cvgIe0aaIhNA2Lbq4lCz4C6u0w2Olu3azejjI0CcMM 5ev4tjFTF7duej0s= X-Received: by 2002:a37:9f47:: with SMTP id i68mr22316537qke.356.1587486084251; Tue, 21 Apr 2020 09:21:24 -0700 (PDT) X-Google-Smtp-Source: APiQypLLDAMpxE+jbOaakotFGhzVpCp0dQ3NIYrW9cCU826rFnBmgn1FJZN/LXc9VBILD0WxKjJ/UA== X-Received: by 2002:a37:9f47:: with SMTP id i68mr22316510qke.356.1587486084027; Tue, 21 Apr 2020 09:21:24 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 4/8] cpus: Introduce qemu_cond_timedwait_iothread() Date: Tue, 21 Apr 2020 12:21:04 -0400 Message-Id: <20200421162108.594796-5-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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This is the sister function of qemu_cond_wait_iothread(). Use it at the on= ly place where we do cond_timedwait() on BQL. Signed-off-by: Peter Xu --- cpus.c | 9 +++++++-- include/qemu/main-loop.h | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cpus.c b/cpus.c index 00f6e361af..263eddc8b0 100644 --- a/cpus.c +++ b/cpus.c @@ -726,8 +726,8 @@ static void cpu_throttle_thread(CPUState *cpu, run_on_c= pu_data opaque) endtime_ns =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + sleeptime_ns; while (sleeptime_ns > 0 && !cpu->stop) { if (sleeptime_ns > SCALE_MS) { - qemu_cond_timedwait(cpu->halt_cond, &qemu_global_mutex, - sleeptime_ns / SCALE_MS); + qemu_cond_timedwait_iothread(cpu->halt_cond, + sleeptime_ns / SCALE_MS); } else { qemu_mutex_unlock_iothread(); g_usleep(sleeptime_ns / SCALE_US); @@ -1844,6 +1844,11 @@ void qemu_cond_wait_iothread(QemuCond *cond) qemu_cond_wait(cond, &qemu_global_mutex); } =20 +void qemu_cond_timedwait_iothread(QemuCond *cond, int ms) +{ + qemu_cond_timedwait(cond, &qemu_global_mutex, ms); +} + static bool all_vcpus_paused(void) { CPUState *cpu; diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h index a6d20b0719..a0e59c5563 100644 --- a/include/qemu/main-loop.h +++ b/include/qemu/main-loop.h @@ -303,6 +303,13 @@ void qemu_mutex_unlock_iothread(void); */ void qemu_cond_wait_iothread(QemuCond *cond); =20 +/* + * qemu_cond_timedwait_iothread: Wait on condition for the main loop mutex + * + * This is the same as qemu_cond_wait_iothread() but allows a timeout. + */ +void qemu_cond_timedwait_iothread(QemuCond *cond, int ms); + /* internal interfaces */ =20 void qemu_fd_register(int fd); --=20 2.24.1 From nobody Sat May 18 12:12:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1587486176; cv=none; d=zohomail.com; s=zohoarc; b=Lz500QLEjd5G9bpQ0mwF9i4xFCC0uw/jjLRTxqEbkV11eT2VaqJ2APfT22y//QcaLe1K2QOC3hKlESU3Q+hj/iIsIJACCHI2sGxhx09nhRXp0IYUrulwjatdvWPAfrL5+1YDegcUD6OZQ5VytrENTK7Liabp0tEWQZjBkuZSgaY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587486176; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=122YOYw144hc6vkPSvZo4NtonS9ahelmjBfjzv+fw7s=; b=jfA3mPOjVClw3MOq/DKhmhxvvs6dEf2sBVY1WvVSd3ifPUGrgteWfilMIO70/AYwd8is385pq/sTFEa8CJVGroduYz/iYCjqncl1eqOS4P/q1cOfs0pil4esjtpNprdtvJUTC8JjJoPiEvLGeMk5jQ4VEPCbc5ZOo3sxFcaQa3c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587486176865516.2972142717706; Tue, 21 Apr 2020 09:22:56 -0700 (PDT) Received: from localhost ([::1]:32780 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQvfh-0002Gd-4E for importer@patchew.org; Tue, 21 Apr 2020 12:22:53 -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 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 Received: by mail-qt1-f199.google.com with SMTP id z3so1824873qtb.6 for ; Tue, 21 Apr 2020 09:21:28 -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) 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= X-MC-Unique: ULJNS5A2NWu3yyjC7oTesg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We must use the BQL for do_run_on_cpu() without much choice, it means the parameter is 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 qem= u_work_item *wi) qemu_cpu_kick(cpu); } =20 -void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data da= ta, - QemuMutex *mutex) +void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data da= ta) { struct qemu_work_item wi; =20 @@ -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 =3D current_cpu; =20 - qemu_cond_wait(&qemu_work_cond, mutex); + qemu_cond_wait_iothread(&qemu_work_cond); current_cpu =3D 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) =20 void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data) { - do_run_on_cpu(cpu, func, data, &qemu_global_mutex); + do_run_on_cpu(cpu, func, data); } =20 static void qemu_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 da= ta, - QemuMutex *mutex); +void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data da= ta); =20 /** * run_on_cpu: --=20 2.24.1 From nobody Sat May 18 12:12:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1587486483; cv=none; d=zohomail.com; s=zohoarc; b=FBHcE56eZaw8y+5jolzNo/3TfJOCGM2bJz/eW8v0y5kdqzrhnHvKBGPR8aOlQwMpQxTJZ84f8FJTW3cGfZMqgsFeyAKG52iFiX+jCj0SpZeFOitAQZtMIzMoxVguk5EHhG765SlGoXl+ctxks8ldeY+ZIu/A4cLXOxyD7Gim080= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587486483; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OK+DIsPslG72w2IO6pbi47ldoAbHvOu1kXaqnZ0hY+0=; b=mwjCISeBiGnc7sPoZ4Q1a1+iu2mbXXmbo90wRfAvo2t8pDblv1cylzXHg50HvpvKHVzwE01NWSiD6R/ET97FXhLq0TLMDr+zMsfGIE1+tHz0JcPMjJhEiWKSrPBS+3YfgoBAgER0tNAy5cbIDzDtQSor7yajGuHyAtzKWMJFQDA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587486483237834.4580357947589; Tue, 21 Apr 2020 09:28:03 -0700 (PDT) Received: from localhost ([::1]:32934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQvkg-0001Rp-03 for importer@patchew.org; Tue, 21 Apr 2020 12:28:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54084) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQveR-00011J-8m for qemu-devel@nongnu.org; Tue, 21 Apr 2020 12:21:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQveQ-0004DU-Lb for qemu-devel@nongnu.org; Tue, 21 Apr 2020 12:21:35 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:22107 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 1jQveQ-0004Cz-7Y for qemu-devel@nongnu.org; Tue, 21 Apr 2020 12:21:34 -0400 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-169-mbqNGD1CO82q49E-ozeCcw-1; Tue, 21 Apr 2020 12:21:31 -0400 Received: by mail-qv1-f70.google.com with SMTP id f4so14336537qvu.19 for ; Tue, 21 Apr 2020 09:21:31 -0700 (PDT) Received: from xz-x1.redhat.com ([2607:9880:19c0:32::2]) by smtp.gmail.com with ESMTPSA id n10sm1888503qkk.105.2020.04.21.09.21.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 09:21:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587486093; 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=OK+DIsPslG72w2IO6pbi47ldoAbHvOu1kXaqnZ0hY+0=; b=JnMIJDw9A3YKQa2ndHEPLR++TcJ9mdxdtTEF5OwBsvsR1VRuJkcEehg/HiKzFowssE4dYT MftHRWYpcuXEBbWtHXrDbjepj31Q5LngMGVr9xKKyra9AYz2vodoDwc+jipumK+z1VxWAO rtdSEDtKE37XPNkbiqJ69foN/uISabc= X-MC-Unique: mbqNGD1CO82q49E-ozeCcw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fRMHDItsx9hNNfR+euE1kI/dNdII4x7dwM+Q4RAjUSc=; b=aVuDdUIqcN5kUkxHEuGAopMeOYoCJ56OalqXqvTU/Y4cjIIcsu5VlGmHxl5GJCLCFM pMfT8Xm6CbrevRG2K0Hq7bHE6knFMIZsk+36bNb3h0FqVaXrn0bN+9DLLI54+MhOXUwi QB2DJgXDl7O42CEC8qv9suqh5Fpacr5anjRI1AlIcPtHrmPvps/vlCzpXapDV2E4/hEm 3ToEOv9LbtJQ6+VyNPB5Ru/CoBWcWQWVpKwVbljvS2ICXEfF+HUiwXEozHLNENVd6rGY WMjueYHWP7M0ImsVijsLYcD8UbZkKc8G3B++H1YAPRkzxxy2TDnNULZXSdpbiqiLKrIS HNgw== X-Gm-Message-State: AGi0Pub68w5TH4iqy85YFSiNtUh91f2zGh6B/A9Jb2OlFh7HvT1u+DuM EQdcAjI0XHC4S+IcbzpVXvbaqJf30WZe5FsIvsWpe02mnELEOYycZLTAPnKBL9fFiaDtm3nAlDw D4d0UmN1r/FwvN2g= X-Received: by 2002:a0c:f70c:: with SMTP id w12mr21187007qvn.28.1587486090495; Tue, 21 Apr 2020 09:21:30 -0700 (PDT) X-Google-Smtp-Source: APiQypLkeQXvii5i6XbB/9MmopgbcRFNkqUjk07cE6Av4jZKy9ipmw+U72L7n+JYe6pzAUEgj1z44A== X-Received: by 2002:a0c:f70c:: with SMTP id w12mr21186980qvn.28.1587486090289; Tue, 21 Apr 2020 09:21:30 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 6/8] cpus: Introduce qemu_mutex_unlock_iothread_prepare() Date: Tue, 21 Apr 2020 12:21:06 -0400 Message-Id: <20200421162108.594796-7-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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 --- cpus.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cpus.c b/cpus.c index 5cbc3f30de..48aa295fea 100644 --- a/cpus.c +++ b/cpus.c @@ -1832,20 +1832,27 @@ void qemu_mutex_lock_iothread_impl(const char *file= , int line) iothread_locked =3D true; } =20 +static void qemu_mutex_unlock_iothread_prepare(void) +{ +} + void qemu_mutex_unlock_iothread(void) { g_assert(qemu_mutex_iothread_locked()); iothread_locked =3D false; + qemu_mutex_unlock_iothread_prepare(); qemu_mutex_unlock(&qemu_global_mutex); } =20 void qemu_cond_wait_iothread(QemuCond *cond) { + qemu_mutex_unlock_iothread_prepare(); qemu_cond_wait(cond, &qemu_global_mutex); } =20 void qemu_cond_timedwait_iothread(QemuCond *cond, int ms) { + qemu_mutex_unlock_iothread_prepare(); qemu_cond_timedwait(cond, &qemu_global_mutex, ms); } =20 --=20 2.24.1 From nobody Sat May 18 12:12:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1587486367; cv=none; d=zohomail.com; s=zohoarc; b=RIqe/Bh59te9tOjwZB2V/sXACpzNRRl0+WsDxFCtn830H/XOeKF1YHEj2xF8JeAJq2AjYG2Oen61niCASREBULh1mlCWPSfRqzOA6MNoyqbtigmfbfZHeBZuemhZa4WUc1d8o6+uipZcwIZlD02ERkH1SUkzlTmehEHVQyXCqCM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587486367; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BDz7lahVpSsYjchGZFQF0Q24z99LRn1XXRfOl+p2CyQ=; b=IwHkAbtUF7EaTnj6BWRyMfwKT9uWa37CvdIV+OYoRuatjBoPF59uooE+e2VHRqPbX7Rvj2OpizFSUm6yXLqnQl23gvGgOz86l4h0xwrYnycGP9x/zNneOs8uqxprfbNE5a8Fk5Lr0pGFDvTpNbBkIyPaNibWddv//3rEa3/36Xg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587486367992143.27685509446974; Tue, 21 Apr 2020 09:26:07 -0700 (PDT) Received: from localhost ([::1]:32868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQvio-0007Cu-Iv for importer@patchew.org; Tue, 21 Apr 2020 12:26:06 -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 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 Received: by mail-qv1-f71.google.com with SMTP id ck5so14259883qvb.18 for ; Tue, 21 Apr 2020 09:21:34 -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) 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= X-MC-Unique: U_NGFeJjPsevu8n8VQpUKQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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" =20 #include "qemu/thread.h" #include "qemu/plugin.h" @@ -1834,6 +1835,7 @@ void qemu_mutex_lock_iothread_impl(const char *file, = int line) =20 static void qemu_mutex_unlock_iothread_prepare(void) { + assert(!memory_region_has_pending_transaction()); } =20 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_disp= atch(AddressSpace *as) =20 FlatView *address_space_get_flatview(AddressSpace *as); void flatview_unref(FlatView *view); +bool memory_region_has_pending_transaction(void); =20 extern const MemoryRegionOps unassigned_mem_ops; =20 diff --git a/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; } =20 +bool memory_region_has_pending_transaction(void) +{ + return memory_region_transaction_depth || + memory_region_has_pending_update(); +} + static bool memory_region_ioeventfd_before(MemoryRegionIoeventfd *a, MemoryRegionIoeventfd *b) { --=20 2.24.1 From nobody Sat May 18 12:12:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1587486475; cv=none; d=zohomail.com; s=zohoarc; b=Yvl6Kdvxi6JsxFzILLExpW4JNi5geoU3CqqUexPnV+wZsecAZjVLH8wXVtL7V0zHACwZr6Lbr3M3pKjhzsCziRem3Ev/XMZEx0rjjc2ScfWEZAtlYfcCd4vdUrf8Lj0Nw5D1rLf0c3sGIpJirutLpFwcyuvGZRo2bnws4mfb/qM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587486475; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FoAyx/faVahlrymiqKqLC0TBQQ5qCmKH51d5hFH8O+s=; b=P+PcjNmodYGEASwZXYvZ5ENfw1uM9jzL9MYZhS6o46SJmsYa4giTE2mrFPEjlI5MaTvTQF+yVMkN18W9KMtXDKnJOm/JH6tboP+ZByRD/U5Z/nnGF9TAs7RALwKCx4oFHpMggp2XdYSPxnkIuTWzjNu2atlxcBIVjOzSMv3fLuM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587486475931784.6303457563546; Tue, 21 Apr 2020 09:27:55 -0700 (PDT) Received: from localhost ([::1]:32933 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQvkX-0001Ju-P2 for importer@patchew.org; Tue, 21 Apr 2020 12:27:53 -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 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 Received: by mail-qv1-f69.google.com with SMTP id f4so14336880qvu.19 for ; Tue, 21 Apr 2020 09:21:37 -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) 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= X-MC-Unique: tubhFZVjPbibSjKo6ihItw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This should be functionally the same as before, but this allows the memory_region_transaction_depth to be non-zero during commit, which can hel= p us to do sanity check on misuses. Since at it, fix an indentation issue on the bracket. Signed-off-by: Peter Xu --- 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()); =20 - memory_region_transaction_pop(); - if (!memory_region_transaction_depth) { + if (memory_region_transaction_depth =3D=3D 1) { if (memory_region_update_pending) { flatviews_reset(); =20 @@ -1109,7 +1108,14 @@ void memory_region_transaction_commit(void) } ioeventfd_update_pending =3D 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 s= anity + * check within the process of committing. + */ + memory_region_transaction_pop(); } =20 static void memory_region_destructor_none(MemoryRegion *mr) --=20 2.24.1