Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp1081241pxb; Fri, 13 Aug 2021 13:05:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJWCePqzMcmajgzyFjzqlV22UmpOQTE0TLJHkmbG/uXelnVJedQQoewo2pJ1S0JHdyThai X-Received: by 2002:a05:6602:220e:: with SMTP id n14mr3269626ion.150.1628885101451; Fri, 13 Aug 2021 13:05:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628885101; cv=none; d=google.com; s=arc-20160816; b=YMEPiOL1Hx1N0VnT1CpiV3HVs/p9ThpBFeTWDYEQHRNVXX/3xWGq7gs9wAka1JbJrH TAU8JuhVGB561Piigm/cb1IzoQQCBaM+NnvpZ8PQ9msgANqCdq785V3oXHz3UcJwPSYg XYHRF5msI629BarU++5Mvj3X7Dc+5anGWWP9yvhBgr3u9Gx4YEXM9y3lMcD4yfwtESfM Vrfbv5IzAbcnTaawpPyTmMdAn5yDlZi+7IURP7AsgGIh+ixroaTAPcolFqRfvwoxm8ND 37c2y+b9jT1LqTucwySzqW3Wdm9YlGjqNWNrYB3sEUR88SuJ+S1LHJxQSQ9Dxc5J8YW5 bHhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=j3eAx7qblPlTVld4svRxDwmHESsJpy4YDXEfkEuLX4M=; b=jv4PeQrJlgbHK+VvhDCDSNfc05wG8DLyVTkkf1/d9Q/ElatRRZ8zV18yIAh5FHpgXk h086zok9Vg5q2+LiJR2fIed75Yhpz4NAjmEOdezwYA9z3iS8wE6UsuQq2Nnbo0jGiPNZ pXADLLdplEaCIibYJc8KJg/FcDKPdKKH4tUxncTGE2QF93bewP6gRhuWLG9ynUH1lSWj d+IM+ZeXz+9fgFYqpg6Pg8LgnIkYXsYCTWFR8+Qa8jrMWA/xvS+NB4HjKnhCTcMc6mTd TSXfwRZALFRhkMEcN9TCetG0Rmx0emufGSgtbU0k/5m4QxPtiqBKqaT+HbYi9CYsdyb3 ct2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c1si2325245ilj.76.2021.08.13.13.04.50; Fri, 13 Aug 2021 13:05:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234587AbhHMUCn (ORCPT + 99 others); Fri, 13 Aug 2021 16:02:43 -0400 Received: from vps-vb.mhejs.net ([37.28.154.113]:50414 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234542AbhHMUCj (ORCPT ); Fri, 13 Aug 2021 16:02:39 -0400 Received: from MUA by vps-vb.mhejs.net with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mEcwT-00043h-71; Fri, 13 Aug 2021 21:34:09 +0200 From: "Maciej S. Szmigiero" To: Paolo Bonzini , Vitaly Kuznetsov Cc: Sean Christopherson , Wanpeng Li , Jim Mattson , Igor Mammedov , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Christian Borntraeger , Janosch Frank , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 07/13] KVM: Just resync arch fields when slots_arch_lock gets reacquired Date: Fri, 13 Aug 2021 21:33:20 +0200 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Maciej S. Szmigiero" There is no need to copy the whole memslot data after releasing slots_arch_lock for a moment to install temporary memslots copy in kvm_set_memslot() since this lock only protects the arch field of each memslot. Just resync this particular field after reacquiring slots_arch_lock. Signed-off-by: Maciej S. Szmigiero --- virt/kvm/kvm_main.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 7000efff1425..272bc86a0e69 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1494,6 +1494,15 @@ static void kvm_copy_memslots(struct kvm_memslots *to, memcpy(to, from, kvm_memslots_size(from->used_slots)); } +static void kvm_copy_memslots_arch(struct kvm_memslots *to, + struct kvm_memslots *from) +{ + int i; + + for (i = 0; i < from->used_slots; i++) + to->memslots[i].arch = from->memslots[i].arch; +} + /* * Note, at a minimum, the current number of used slots must be allocated, even * when deleting a memslot, as we need a complete duplicate of the memslots for @@ -1579,10 +1588,10 @@ static int kvm_set_memslot(struct kvm *kvm, /* * The arch-specific fields of the memslots could have changed * between releasing the slots_arch_lock in - * install_new_memslots and here, so get a fresh copy of the - * slots. + * install_new_memslots and here, so get a fresh copy of these + * fields. */ - kvm_copy_memslots(slots, __kvm_memslots(kvm, as_id)); + kvm_copy_memslots_arch(slots, __kvm_memslots(kvm, as_id)); } r = kvm_arch_prepare_memory_region(kvm, old, new, mem, change); @@ -1599,8 +1608,6 @@ static int kvm_set_memslot(struct kvm *kvm, out_slots: if (change == KVM_MR_DELETE || change == KVM_MR_MOVE) { - slot = id_to_memslot(slots, old->id); - slot->flags &= ~KVM_MEMSLOT_INVALID; slots = install_new_memslots(kvm, as_id, slots); } else { mutex_unlock(&kvm->slots_arch_lock);