Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1793322rwn; Fri, 9 Sep 2022 04:17:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR5Q+1r5IGdXcsTcH6Ckq4NSxgk9Qi5g3MoqacbPdVxcAcQb5Ut3Uxf1ctJGHBaQgpHkSNRz X-Received: by 2002:a17:902:f548:b0:178:44b:4ea9 with SMTP id h8-20020a170902f54800b00178044b4ea9mr3942427plf.77.1662722242934; Fri, 09 Sep 2022 04:17:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662722242; cv=none; d=google.com; s=arc-20160816; b=CriuGDFNYZMf6k+hHfWnCiB3TySlnOL1w40/EagGwfVzamX+vveg9SoLPbbTKe2QA4 dUH7C1tffB6BWg0NUsfZG0TgSWYE8G78CLzpYbAGoRtvuvF82IK9BVqr0l7BeKhNKE6X ovQl+KfKyNDw5FYeq6avEItmRkg11bRSWxTapdzyesCw9Z4wMP1EQ3sJn5nErZyLPLkN FQ4TAStfknTEPDvB03S6kjpW3tN1OPjNwP4LOviwPzLrs3sv4cNrUfFjZx0r2rddOA5F JVI7jWEwL9PYYSK4J2q3Y4lQOyQCzoghLUd6qNBSWouGymtJjih/5C3A27WYPP7T/ETb KBlQ== 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 :dkim-signature; bh=eUVXlYDwK0/TqR7ADYfBnKPJM99YoNpijZnP7G2Z+Ds=; b=rR/v8viqN88UVfOKRqpTZSvFMUvVtWh5AgfD76Cv8ywGLScOpiuTPSEEHDbgsNGgrF QBkDmKQKi48R59EA+PyWeQ8EvESIed4N35OGG1EHzA/NgVN/vLiXlpFm0v1tCyZ+5jJ0 lnuz9ckIV+VIteglfr37dS/OVIYs+3Yqmqt9/C5nzIiFd2DjOaJmflzUXR4I4l4OHx60 9XH4VQBJc7UPlvbWEABMO8bzWaHZUxStt/fQ1W+S9qGZy8swRSN21GjGPNN3wrswGDyq 4KMyVfVLQ/ITkstyIhotkiljivxDF+JU/HmgqMaZ6ktgEJRqHFRCfv5OpYWbEx/GFHKi 4U3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AZm8lDSX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t9-20020a17090a3e4900b001fbc6ba91besi287023pjm.96.2022.09.09.04.17.10; Fri, 09 Sep 2022 04:17:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AZm8lDSX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231348AbiIIKpy (ORCPT + 99 others); Fri, 9 Sep 2022 06:45:54 -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: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 = mem->slot >> 16; id = (u16)mem->slot; - slots = __kvm_memslots(kvm, as_id); + slots = kvm_get_inactive_memslots(kvm, as_id); /* * Note, the old memslot (and the pointer itself!) may be invalidated -- 2.31.1