Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2375648pxb; Mon, 20 Sep 2021 20:38:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLR3eBQ1ND5isAl6y8OIli9POmXGrioGoxRvRnWsDRImwFp1eUud9biKNNOF9IfspXPc2V X-Received: by 2002:a17:906:5d6:: with SMTP id t22mr32155176ejt.98.1632195495914; Mon, 20 Sep 2021 20:38:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632195495; cv=none; d=google.com; s=arc-20160816; b=uy9wYg1/HcK5wQEbkZKtXlDwlB/MQrWAKDvYBo/C49YBruaiZlsjdC/yg+LOGWIXsL C+zSFJAsSkusYcPcLtpW52qVAYo6m/7LrEvsOTC8cxwx01j1raPgo90pUZfrtlr0bHJE XjCDaHfGSTtcHax2X6uXT063+rgChXcsf8fyl6xI1iQuHbkaBbA+cOmVAkxh/F2IoLTT GdzycXWYIlFIJq4MihosKf+as1k/BH4RDJLZrAEUwz2omHBiqE8XoG8vD3F72QQ6Lu3s T7pxVw98lT9xsKBEh/rF73S+U0FZlznNC3HN5eqs0eF3GMbKdR+9BXTp/xeWk57eAS23 bf8w== 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=qET6mtVBBVZ9rK50T6feRacymT+f/v4uYzu8ASPoWoA=; b=k94TjxVIfZjAglru0JfWVTGYvhNt/Lhe3Y/xh1F+1JU8FfGylIg0ZbV5Gl+Qn0mC3s Mix+ypx+U04IV5aWt1iCeM81dr6XzZzBb2gqIGp80wh9MKh1WBF+hp3Yfi57jkCotjTc bn4N0/9koN09zYk6EuYKNByr3gGL+FKYKZWSK2JlhNtzrCTTxK36+jOROVvOe1FVvcQL Mg5XnOvC/m3JVn7kAlvtc5S458yG+TOyyZWBGgEke8RUT1LBP7YD2FqYU5PwMJsF7iqw +PJDrR6vvnU3wUu+7VIWtDalLj1sBW29fLgv0HUBAxCoZNzbC+vcNIOHB46frty40yfD dH1A== 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 k9si23708289eje.548.2021.09.20.20.37.52; Mon, 20 Sep 2021 20:38:15 -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 S239692AbhITVnj (ORCPT + 99 others); Mon, 20 Sep 2021 17:43:39 -0400 Received: from vps-vb.mhejs.net ([37.28.154.113]:45542 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237356AbhITVlb (ORCPT ); Mon, 20 Sep 2021 17:41:31 -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 1mSR0q-0006RA-Mm; Mon, 20 Sep 2021 23:39:44 +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 v5 07/13] KVM: Just resync arch fields when slots_arch_lock gets reacquired Date: Mon, 20 Sep 2021 23:38:55 +0200 Message-Id: <311810ebd1111bed50d931d424297384171afc36.1632171479.git.maciej.szmigiero@oracle.com> X-Mailer: git-send-email 2.33.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 348fae880189..48d182840060 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1482,6 +1482,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 @@ -1567,10 +1576,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); @@ -1587,8 +1596,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);