From nobody Wed Apr 8 12:11:35 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A97BECAAD3 for ; Fri, 9 Sep 2022 10:46:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230077AbiIIKp5 (ORCPT ); Fri, 9 Sep 2022 06:45:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231178AbiIIKpT (ORCPT ); Fri, 9 Sep 2022 06:45:19 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A84664F6A9 for ; Fri, 9 Sep 2022 03:45:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662720316; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eUVXlYDwK0/TqR7ADYfBnKPJM99YoNpijZnP7G2Z+Ds=; b=AZm8lDSX0eggR0U9ANhNfOwcLFcE4LNFQabalsoZ+7HzgKDAi2v1z4N1u+Y2z+ik4vDgBq hMGFnEPGOXyDM6Y5pGCU98LeltInCM70qPSXMB7WGTaw0a0vyaXRJmlcbYK8IbYLolg8mz 3MdXIxrjsTt3SydTQd79sz59MGGtR6I= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-649-Jxe2dHiBOQ-FzA5qflBSeg-1; Fri, 09 Sep 2022 06:45:13 -0400 X-MC-Unique: Jxe2dHiBOQ-FzA5qflBSeg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EEA911C05AE6; Fri, 9 Sep 2022 10:45:12 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B5F740D282E; Fri, 9 Sep 2022 10:45:12 +0000 (UTC) From: Emanuele Giuseppe Esposito To: kvm@vger.kernel.org Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , David Hildenbrand , Maxim Levitsky , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, Emanuele Giuseppe Esposito Subject: [RFC PATCH 8/9] kvm_main.c: find memslots from the inactive memslot list Date: Fri, 9 Sep 2022 06:45:05 -0400 Message-Id: <20220909104506.738478-9-eesposit@redhat.com> In-Reply-To: <20220909104506.738478-1-eesposit@redhat.com> References: <20220909104506.738478-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Instead of looking at the active list, look at the inactive. This causes no harm to the current code, as active and inactive lists are identical at this point. In addition, provide flexibility for atomic memslot updates, because in that case we want to perform multiple updates in the inactive list first, and then perform a single swap only. If we were to use the active list, previous updates that were not yet swapped won't be seen, and the following logic in kvm_prepare_batch() could for example find an old memslot that was deleted in the inactive but not in the active, thus wrongly assuming that the coming request is a MOVE and not a CREATE. Note that this also causes no harm to the invalidate memslot, since we are already inserting it as replacement in both active and inactive list. Signed-off-by: Emanuele Giuseppe Esposito --- virt/kvm/kvm_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 31e46f9a06fa..ecd43560281c 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1948,7 +1948,7 @@ static int kvm_prepare_batch(struct kvm *kvm, as_id =3D mem->slot >> 16; id =3D (u16)mem->slot; =20 - slots =3D __kvm_memslots(kvm, as_id); + slots =3D kvm_get_inactive_memslots(kvm, as_id); =20 /* * Note, the old memslot (and the pointer itself!) may be invalidated --=20 2.31.1