From nobody Mon Feb 9 09:53:52 2026 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=1621499263; cv=none; d=zohomail.com; s=zohoarc; b=SlUc/Vx3IRr1yZ8fKhCRa5GIcyPD1cLwzZfXFJ4vzm/KIfzyDEW0FRUarlSkS95CawoQ+iDliOOx1CIn+mvgb2sBSECuguqVdsMn0xj6+HVh8O0TfSsRW9w3Q/wyOgmHIVec1a4ibEhD33boxBYoyI7IeTRBmscxjeQP0OHs+ls= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621499263; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Dm9fdtL6t7afNY/kOhuKcUr0Mn8HCiKEsUB/elQwJdU=; b=K/c8AeSXYSKSdlGptcaqQa08NNM+i2vH4dlaSjFuc2ju31l8jSn6GJ+spBWgA89O7EDoWrYC2ynhdV1Nvi97v6To0QOV+v29i5lpag0oLMMIFbimVgLWlILuTcqmo+nHiuXzGB9rjAiWEXyeXPtQY0Cybw9S1CVLZYyxMi3ipxo= 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 1621499263178560.5276367908501; Thu, 20 May 2021 01:27:43 -0700 (PDT) Received: from localhost ([::1]:58642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lje1u-0005uP-35 for importer@patchew.org; Thu, 20 May 2021 04:27:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50466) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljdxf-0005OF-8n for qemu-devel@nongnu.org; Thu, 20 May 2021 04:23:20 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:39929) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ljdxY-0001Wp-12 for qemu-devel@nongnu.org; Thu, 20 May 2021 04:23:15 -0400 Received: by mail-wr1-x434.google.com with SMTP id v12so16672602wrq.6 for ; Thu, 20 May 2021 01:23:06 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id v10sm2603506wrq.0.2021.05.20.01.23.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 01:23:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Dm9fdtL6t7afNY/kOhuKcUr0Mn8HCiKEsUB/elQwJdU=; b=Xpv16JC1lI0DEFy3A6clqgPyC7qz5Yh7uJxqWnohJnudKrIPDlSbO765USVlStTM9U 99rzmQM/AoH/At4S4HPF4Ln/9RGAj/Kp2DtaN2st814CwDLG4vy0CXPRrmO4bUomfV3n PTOV5xiaKFjrFMJ2oNpZFsAn9zki+7VN3NqwSdzirxN/l0hm1Zpgfu7kJpUlpLZWSDrK WnDc3F3652YAOLDEcOE2XDw1FlpwaGig08dd8lMihxmOPS4vnVp/IV1Z7N+YlmbCwZma nADSD7iNAdFne7n1ObuAyHrQ4hF9K4eAit8/CCmh09Xukgx8AHlIUWbwh7lXWw2peszw g8Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Dm9fdtL6t7afNY/kOhuKcUr0Mn8HCiKEsUB/elQwJdU=; b=gGTGYcpRV/f6dxzU2HmnrSjCymcdQ7Gl7lNRLCkjwZjvH3KL3JvDc3HEFVGInnt9aM zHCYFnTjqN+fpjkETs1VPdSQ0vJfuLhvEiEdRccGbF5npIZkG/oUWvLaTfbESAx2M2o0 5QYsTGHfZ21Phc2EMhkDgSmvnjJfhwlcyJ5YVGNzo4g2GYKF9xZM58Sc/iPbQ0a2z6p4 5szGcAi0p/QdLGC9aosMNxZhMZS4h1hvCTP85qwu6mM+hdkXbvvjFj2M6mLb0ajJRGX1 7ldQDY1fTZ4i7w1Z/k4OYTJye4vSuGv5UDB7JoQhTYF1f9ggX9Xw3npuY0jyN2GZGR9K bYmw== X-Gm-Message-State: AOAM532+FFvm3DBLJUZjHkZHWAYRNpQJktq9MUNyCuo7f9ZC+a7UaM4S 4ns06Y6bsQ7TWN276EDCnwjTbT3cISMQJA== X-Google-Smtp-Source: ABdhPJzTDHqCoJkxq0PkvXsAs1XqBinMf2MenqZ840+6dmmpCI/x69uSKFga9QsLUX3xc3O45CJ1GA== X-Received: by 2002:a5d:570c:: with SMTP id a12mr2926498wrv.354.1621498985740; Thu, 20 May 2021 01:23:05 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 11/26] KVM: Use a big lock to replace per-kml slots_lock Date: Thu, 20 May 2021 10:22:42 +0200 Message-Id: <20210520082257.187061-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520082257.187061-1-pbonzini@redhat.com> References: <20210520082257.187061-1-pbonzini@redhat.com> MIME-Version: 1.0 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=2a00:1450:4864:20::434; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x434.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: Peter Xu 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" From: Peter Xu Per-kml slots_lock will bring some trouble if we want to take all slots_loc= k of all the KMLs, especially when we're in a context that we could have taken s= ome of the KML slots_lock, then we even need to figure out what we've taken and what we need to take. Make this simple by merging all KML slots_lock into a single slots lock. Per-kml slots_lock isn't anything that helpful anyway - so far only x86 has= two address spaces (so, two slots_locks). All the rest archs will be having one address space always, which means there's actually one slots_lock so it wil= l be the same as before. Signed-off-by: Peter Xu Message-Id: <20210506160549.130416-3-peterx@redhat.com> Signed-off-by: Paolo Bonzini --- accel/kvm/kvm-all.c | 33 ++++++++++++++++++--------------- include/sysemu/kvm_int.h | 2 -- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 54c0860979..f8980e155b 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -172,8 +172,10 @@ typedef struct KVMResampleFd KVMResampleFd; static QLIST_HEAD(, KVMResampleFd) kvm_resample_fd_list =3D QLIST_HEAD_INITIALIZER(kvm_resample_fd_list); =20 -#define kvm_slots_lock(kml) qemu_mutex_lock(&(kml)->slots_lock) -#define kvm_slots_unlock(kml) qemu_mutex_unlock(&(kml)->slots_lock) +static QemuMutex kml_slots_lock; + +#define kvm_slots_lock() qemu_mutex_lock(&kml_slots_lock) +#define kvm_slots_unlock() qemu_mutex_unlock(&kml_slots_lock) =20 static inline void kvm_resample_fd_remove(int gsi) { @@ -239,9 +241,9 @@ bool kvm_has_free_slot(MachineState *ms) bool result; KVMMemoryListener *kml =3D &s->memory_listener; =20 - kvm_slots_lock(kml); + kvm_slots_lock(); result =3D !!kvm_get_free_slot(kml); - kvm_slots_unlock(kml); + kvm_slots_unlock(); =20 return result; } @@ -307,7 +309,7 @@ int kvm_physical_memory_addr_from_host(KVMState *s, voi= d *ram, KVMMemoryListener *kml =3D &s->memory_listener; int i, ret =3D 0; =20 - kvm_slots_lock(kml); + kvm_slots_lock(); for (i =3D 0; i < s->nr_slots; i++) { KVMSlot *mem =3D &kml->slots[i]; =20 @@ -317,7 +319,7 @@ int kvm_physical_memory_addr_from_host(KVMState *s, voi= d *ram, break; } } - kvm_slots_unlock(kml); + kvm_slots_unlock(); =20 return ret; } @@ -513,7 +515,7 @@ static int kvm_section_update_flags(KVMMemoryListener *= kml, return 0; } =20 - kvm_slots_lock(kml); + kvm_slots_lock(); =20 while (size && !ret) { slot_size =3D MIN(kvm_max_slot_size, size); @@ -529,7 +531,7 @@ static int kvm_section_update_flags(KVMMemoryListener *= kml, } =20 out: - kvm_slots_unlock(kml); + kvm_slots_unlock(); return ret; } =20 @@ -810,7 +812,7 @@ static int kvm_physical_log_clear(KVMMemoryListener *km= l, return ret; } =20 - kvm_slots_lock(kml); + kvm_slots_lock(); =20 for (i =3D 0; i < s->nr_slots; i++) { mem =3D &kml->slots[i]; @@ -836,7 +838,7 @@ static int kvm_physical_log_clear(KVMMemoryListener *km= l, } } =20 - kvm_slots_unlock(kml); + kvm_slots_unlock(); =20 return ret; } @@ -1141,7 +1143,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, ram =3D memory_region_get_ram_ptr(mr) + section->offset_within_region + (start_addr - section->offset_within_address_space); =20 - kvm_slots_lock(kml); + kvm_slots_lock(); =20 if (!add) { do { @@ -1199,7 +1201,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, } while (size); =20 out: - kvm_slots_unlock(kml); + kvm_slots_unlock(); } =20 static void kvm_region_add(MemoryListener *listener, @@ -1226,9 +1228,9 @@ static void kvm_log_sync(MemoryListener *listener, KVMMemoryListener *kml =3D container_of(listener, KVMMemoryListener, l= istener); int r; =20 - kvm_slots_lock(kml); + kvm_slots_lock(); r =3D kvm_physical_sync_dirty_bitmap(kml, section); - kvm_slots_unlock(kml); + kvm_slots_unlock(); if (r < 0) { abort(); } @@ -1328,7 +1330,6 @@ void kvm_memory_listener_register(KVMState *s, KVMMem= oryListener *kml, { int i; =20 - qemu_mutex_init(&kml->slots_lock); kml->slots =3D g_malloc0(s->nr_slots * sizeof(KVMSlot)); kml->as_id =3D as_id; =20 @@ -2001,6 +2002,8 @@ static int kvm_init(MachineState *ms) int type =3D 0; uint64_t dirty_log_manual_caps; =20 + qemu_mutex_init(&kml_slots_lock); + s =3D KVM_STATE(ms->accelerator); =20 /* diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index ccb8869f01..1da30e1884 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -27,8 +27,6 @@ typedef struct KVMSlot =20 typedef struct KVMMemoryListener { MemoryListener listener; - /* Protects the slots and all inside them */ - QemuMutex slots_lock; KVMSlot *slots; int as_id; } KVMMemoryListener; --=20 2.31.1