From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sean Christopherson Date: Fri, 12 Nov 2021 00:51:03 +0000 Subject: [PATCH v5.5 26/30] KVM: Keep memslots in tree-based structures instead of array-based ones In-Reply-To: <5f5c80ce-9189-def3-9c50-d5a504925253@oracle.com> References: <20211104002531.1176691-1-seanjc@google.com> <20211104002531.1176691-27-seanjc@google.com> <5f5c80ce-9189-def3-9c50-d5a504925253@oracle.com> Message-ID: List-Id: To: kvm-riscv@lists.infradead.org MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On Fri, Nov 12, 2021, Maciej S. Szmigiero wrote: > On 04.11.2021 01:25, Sean Christopherson wrote: > > - /* > > - * Remove the old memslot from the hash list and interval tree, copying > > - * the node data would corrupt the structures. > > - */ > > + int as_id = kvm_memslots_get_as_id(old, new); > > + struct kvm_memslots *slots = kvm_get_inactive_memslots(kvm, as_id); > > + int idx = slots->node_idx; > > + > > if (old) { > > - hash_del(&old->id_node); > > - interval_tree_remove(&old->hva_node, &slots->hva_tree); > > + hash_del(&old->id_node[idx]); > > + interval_tree_remove(&old->hva_node[idx], &slots->hva_tree); > > - if (!new) > > + if ((long)old == atomic_long_read(&slots->last_used_slot)) > > + atomic_long_set(&slots->last_used_slot, (long)new); > > Open-coding cmpxchg() is way less readable than a direct call. Doh, I meant to call this out and/or add a comment. My objection to cmpxchg() is that it implies atomicity is required (the kernel's version adds the lock), which is very much not the case. So this isn't strictly an open-coded version of cmpxchg(). > The open-coded version also compiles on x86 to multiple instructions with > a branch, instead of just a single instruction. Yeah. The lock can't be contended, so that part of cmpxchg is a non-issue. But that's also why I don't love using cmpxchg. I don't have a strong preference, I just got briefly confused by the atomicity part. > > +static void kvm_invalidate_memslot(struct kvm *kvm, > > + struct kvm_memory_slot *old, > > + struct kvm_memory_slot *working_slot) > > +{ > > + /* > > + * Mark the current slot INVALID. As with all memslot modifications, > > + * this must be done on an unreachable slot to avoid modifying the > > + * current slot in the active tree. > > + */ > > + kvm_copy_memslot(working_slot, old); > > + working_slot->flags |= KVM_MEMSLOT_INVALID; > > + kvm_replace_memslot(kvm, old, working_slot); > > + > > + /* > > + * Activate the slot that is now marked INVALID, but don't propagate > > + * the slot to the now inactive slots. The slot is either going to be > > + * deleted or recreated as a new slot. > > + */ > > + kvm_swap_active_memslots(kvm, old->as_id); > > + > > + /* > > + * From this point no new shadow pages pointing to a deleted, or moved, > > + * memslot will be created. Validation of sp->gfn happens in: > > + * - gfn_to_hva (kvm_read_guest, gfn_to_pfn) > > + * - kvm_is_visible_gfn (mmu_check_root) > > + */ > > + kvm_arch_flush_shadow_memslot(kvm, old); > > This should flush the currently active slot (that is, "working_slot", > not "old") to not introduce a behavior change with respect to the existing > code. > > That's also what the previous version of this patch set did. Eww. I would much prefer to "fix" the existing code in a prep patch. It shouldn't matter, but arch code really should not get passed an INVALID slot. From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sean Christopherson Date: Fri, 12 Nov 2021 00:51:03 +0000 Subject: Re: [PATCH v5.5 26/30] KVM: Keep memslots in tree-based structures instead of array-based ones Message-Id: List-Id: References: <20211104002531.1176691-1-seanjc@google.com> <20211104002531.1176691-27-seanjc@google.com> <5f5c80ce-9189-def3-9c50-d5a504925253@oracle.com> In-Reply-To: <5f5c80ce-9189-def3-9c50-d5a504925253@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: "Maciej S. Szmigiero" Cc: James Morse , Alexandru Elisei , Suzuki K Poulose , Atish Patra , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Ben Gardon , Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Paolo Bonzini On Fri, Nov 12, 2021, Maciej S. Szmigiero wrote: > On 04.11.2021 01:25, Sean Christopherson wrote: > > - /* > > - * Remove the old memslot from the hash list and interval tree, copying > > - * the node data would corrupt the structures. > > - */ > > + int as_id = kvm_memslots_get_as_id(old, new); > > + struct kvm_memslots *slots = kvm_get_inactive_memslots(kvm, as_id); > > + int idx = slots->node_idx; > > + > > if (old) { > > - hash_del(&old->id_node); > > - interval_tree_remove(&old->hva_node, &slots->hva_tree); > > + hash_del(&old->id_node[idx]); > > + interval_tree_remove(&old->hva_node[idx], &slots->hva_tree); > > - if (!new) > > + if ((long)old = atomic_long_read(&slots->last_used_slot)) > > + atomic_long_set(&slots->last_used_slot, (long)new); > > Open-coding cmpxchg() is way less readable than a direct call. Doh, I meant to call this out and/or add a comment. My objection to cmpxchg() is that it implies atomicity is required (the kernel's version adds the lock), which is very much not the case. So this isn't strictly an open-coded version of cmpxchg(). > The open-coded version also compiles on x86 to multiple instructions with > a branch, instead of just a single instruction. Yeah. The lock can't be contended, so that part of cmpxchg is a non-issue. But that's also why I don't love using cmpxchg. I don't have a strong preference, I just got briefly confused by the atomicity part. > > +static void kvm_invalidate_memslot(struct kvm *kvm, > > + struct kvm_memory_slot *old, > > + struct kvm_memory_slot *working_slot) > > +{ > > + /* > > + * Mark the current slot INVALID. As with all memslot modifications, > > + * this must be done on an unreachable slot to avoid modifying the > > + * current slot in the active tree. > > + */ > > + kvm_copy_memslot(working_slot, old); > > + working_slot->flags |= KVM_MEMSLOT_INVALID; > > + kvm_replace_memslot(kvm, old, working_slot); > > + > > + /* > > + * Activate the slot that is now marked INVALID, but don't propagate > > + * the slot to the now inactive slots. The slot is either going to be > > + * deleted or recreated as a new slot. > > + */ > > + kvm_swap_active_memslots(kvm, old->as_id); > > + > > + /* > > + * From this point no new shadow pages pointing to a deleted, or moved, > > + * memslot will be created. Validation of sp->gfn happens in: > > + * - gfn_to_hva (kvm_read_guest, gfn_to_pfn) > > + * - kvm_is_visible_gfn (mmu_check_root) > > + */ > > + kvm_arch_flush_shadow_memslot(kvm, old); > > This should flush the currently active slot (that is, "working_slot", > not "old") to not introduce a behavior change with respect to the existing > code. > > That's also what the previous version of this patch set did. Eww. I would much prefer to "fix" the existing code in a prep patch. It shouldn't matter, but arch code really should not get passed an INVALID slot. From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5599C433EF for ; Fri, 12 Nov 2021 00:51:14 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 33C1B614C8 for ; Fri, 12 Nov 2021 00:51:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 33C1B614C8 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id A1BD04B17B; Thu, 11 Nov 2021 19:51:13 -0500 (EST) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@google.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EcPfQ33-0gQr; Thu, 11 Nov 2021 19:51:12 -0500 (EST) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 287204B1E3; Thu, 11 Nov 2021 19:51:12 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 74C614B177 for ; Thu, 11 Nov 2021 19:51:10 -0500 (EST) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YDrT3UfBd9ba for ; Thu, 11 Nov 2021 19:51:09 -0500 (EST) Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 379614B17B for ; Thu, 11 Nov 2021 19:51:09 -0500 (EST) Received: by mail-pl1-f170.google.com with SMTP id y7so7238704plp.0 for ; Thu, 11 Nov 2021 16:51:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=7VoEwbSPzrTyOh3w99mGEcK1Otv61yXE8VpDyQ7XU/Q=; b=aR0iTUNTxKf6faFpqVLtDxLZ+Z93VjgfuMSy8Y9h3wnwVUTL/oHfhEOsrg0V7yOdYT 7fq8GTKIKG9OH6zETAjAXEzMtYxKZ4n8vzmgKUi//wtyVazuE6xgdlSVa2YM1WXEZK7o ckgTdbQk1CrwriNKigDb1ZxyhMDgLtfKnE3RIVuAKQjcg2mMhNzjvwVYycKmLb0GnSZ1 GYcRaJBvetbHNGisq5tuHOigfRUZHZConfP9luv9GZtaibkXsyjw/cHwj8DSAwBW3aaZ 7VyKPKnacS2ZdpG3N5SRXdGPcXpnFm1QD3uLEDYX71FQ35qKY9q+/DI/dPGPqFGBB6ib ajeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7VoEwbSPzrTyOh3w99mGEcK1Otv61yXE8VpDyQ7XU/Q=; b=F7Lgy6TdKl5Xul20GTT8U+SKZ06QbNJXBJ9DqKnOOffpvQ9VsmJbVwN8HXfD5curzH dzqW5ZKsR4866ZhQhSS1TuB4tjN5tQn2EWYoFMJCbv36JMxZ3EV5y3zV/l1K4fmsL0fN 6l5qWcRvvaHFhj5EB+YGBl5KMcpNTAMHRgTXgebSqN7FdU3LKZ2J0AiWtTyqrlw+jPz+ X+193OBV3nBtbkD4awAUEy/XnezOtu68jZQtALZahOfnxeeIkCg0eikg8RD0bkydfq3o m3IuzLd+aZ3LQdB7r7/Xk8ej08huYAuH6oFZ5hkzCPQNwvPpbCA4kBb5QV4UiBkxwtoZ bQPQ== X-Gm-Message-State: AOAM5329LyykH73mykn8DgSQaLax9D3/UJJyTHmwRrrWfEBt1zPLNX9/ gNFFm//pNjUpTPSmMstMoUGuuA== X-Google-Smtp-Source: ABdhPJxC4jGH9js/28DTzQpRvZ4IBLyKiJDKoUfHaiXaxCscmtOSb6+KYszrts8CNNHGQNLMJ/jO0g== X-Received: by 2002:a17:90a:c58f:: with SMTP id l15mr12870593pjt.168.1636678268099; Thu, 11 Nov 2021 16:51:08 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id s21sm4279773pfk.3.2021.11.11.16.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 16:51:07 -0800 (PST) Date: Fri, 12 Nov 2021 00:51:03 +0000 From: Sean Christopherson To: "Maciej S. Szmigiero" Subject: Re: [PATCH v5.5 26/30] KVM: Keep memslots in tree-based structures instead of array-based ones Message-ID: References: <20211104002531.1176691-1-seanjc@google.com> <20211104002531.1176691-27-seanjc@google.com> <5f5c80ce-9189-def3-9c50-d5a504925253@oracle.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <5f5c80ce-9189-def3-9c50-d5a504925253@oracle.com> Cc: Anup Patel , Wanpeng Li , kvm@vger.kernel.org, David Hildenbrand , linux-kernel@vger.kernel.org, Paul Mackerras , Atish Patra , Ben Gardon , linux-riscv@lists.infradead.org, Claudio Imbrenda , kvmarm@lists.cs.columbia.edu, Janosch Frank , Marc Zyngier , Joerg Roedel , Huacai Chen , Christian Borntraeger , Aleksandar Markovic , Palmer Dabbelt , Albert Ou , kvm-ppc@vger.kernel.org, Paul Walmsley , linux-arm-kernel@lists.infradead.org, Jim Mattson , Cornelia Huck , linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, Paolo Bonzini , Vitaly Kuznetsov X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On Fri, Nov 12, 2021, Maciej S. Szmigiero wrote: > On 04.11.2021 01:25, Sean Christopherson wrote: > > - /* > > - * Remove the old memslot from the hash list and interval tree, copying > > - * the node data would corrupt the structures. > > - */ > > + int as_id = kvm_memslots_get_as_id(old, new); > > + struct kvm_memslots *slots = kvm_get_inactive_memslots(kvm, as_id); > > + int idx = slots->node_idx; > > + > > if (old) { > > - hash_del(&old->id_node); > > - interval_tree_remove(&old->hva_node, &slots->hva_tree); > > + hash_del(&old->id_node[idx]); > > + interval_tree_remove(&old->hva_node[idx], &slots->hva_tree); > > - if (!new) > > + if ((long)old == atomic_long_read(&slots->last_used_slot)) > > + atomic_long_set(&slots->last_used_slot, (long)new); > > Open-coding cmpxchg() is way less readable than a direct call. Doh, I meant to call this out and/or add a comment. My objection to cmpxchg() is that it implies atomicity is required (the kernel's version adds the lock), which is very much not the case. So this isn't strictly an open-coded version of cmpxchg(). > The open-coded version also compiles on x86 to multiple instructions with > a branch, instead of just a single instruction. Yeah. The lock can't be contended, so that part of cmpxchg is a non-issue. But that's also why I don't love using cmpxchg. I don't have a strong preference, I just got briefly confused by the atomicity part. > > +static void kvm_invalidate_memslot(struct kvm *kvm, > > + struct kvm_memory_slot *old, > > + struct kvm_memory_slot *working_slot) > > +{ > > + /* > > + * Mark the current slot INVALID. As with all memslot modifications, > > + * this must be done on an unreachable slot to avoid modifying the > > + * current slot in the active tree. > > + */ > > + kvm_copy_memslot(working_slot, old); > > + working_slot->flags |= KVM_MEMSLOT_INVALID; > > + kvm_replace_memslot(kvm, old, working_slot); > > + > > + /* > > + * Activate the slot that is now marked INVALID, but don't propagate > > + * the slot to the now inactive slots. The slot is either going to be > > + * deleted or recreated as a new slot. > > + */ > > + kvm_swap_active_memslots(kvm, old->as_id); > > + > > + /* > > + * From this point no new shadow pages pointing to a deleted, or moved, > > + * memslot will be created. Validation of sp->gfn happens in: > > + * - gfn_to_hva (kvm_read_guest, gfn_to_pfn) > > + * - kvm_is_visible_gfn (mmu_check_root) > > + */ > > + kvm_arch_flush_shadow_memslot(kvm, old); > > This should flush the currently active slot (that is, "working_slot", > not "old") to not introduce a behavior change with respect to the existing > code. > > That's also what the previous version of this patch set did. Eww. I would much prefer to "fix" the existing code in a prep patch. It shouldn't matter, but arch code really should not get passed an INVALID slot. _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 891F2C433EF for ; Fri, 12 Nov 2021 00:51:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7179C61284 for ; Fri, 12 Nov 2021 00:51:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234638AbhKLAx7 (ORCPT ); Thu, 11 Nov 2021 19:53:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234630AbhKLAx6 (ORCPT ); Thu, 11 Nov 2021 19:53:58 -0500 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2C53C06127A for ; Thu, 11 Nov 2021 16:51:08 -0800 (PST) Received: by mail-pl1-x636.google.com with SMTP id n8so7127178plf.4 for ; Thu, 11 Nov 2021 16:51:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=7VoEwbSPzrTyOh3w99mGEcK1Otv61yXE8VpDyQ7XU/Q=; b=aR0iTUNTxKf6faFpqVLtDxLZ+Z93VjgfuMSy8Y9h3wnwVUTL/oHfhEOsrg0V7yOdYT 7fq8GTKIKG9OH6zETAjAXEzMtYxKZ4n8vzmgKUi//wtyVazuE6xgdlSVa2YM1WXEZK7o ckgTdbQk1CrwriNKigDb1ZxyhMDgLtfKnE3RIVuAKQjcg2mMhNzjvwVYycKmLb0GnSZ1 GYcRaJBvetbHNGisq5tuHOigfRUZHZConfP9luv9GZtaibkXsyjw/cHwj8DSAwBW3aaZ 7VyKPKnacS2ZdpG3N5SRXdGPcXpnFm1QD3uLEDYX71FQ35qKY9q+/DI/dPGPqFGBB6ib ajeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7VoEwbSPzrTyOh3w99mGEcK1Otv61yXE8VpDyQ7XU/Q=; b=fBcE8AGj+ZalTVALzxzE3C47mx8r1reSWi9JsN8Lpl3IJ/RpfKN7cpvcTvigunGFZQ Oh9+LBi7B2h3aHexlV1XWMDIY0SRRGdzpyNdS6hP5DhVWAvvreB0pyYWHGMAx4FK9LJ2 4azENcRor92Adg659KQKvZK1HVMhnpBVJxTAAyo+Za1ORy01t7UFMRrTx6jzzBUYx+54 t4K6p8YgbGfoYfZ04Q7Nal92ey3QjXva4YiVSOgBrSSvPwNqhYLgrf+Lt7NWQlE34nBi dlQnrxjYzV2Vd3qHYwInBdfcop1BTxZInZmOvOHIImaFfUoVRssJPOfV5/4+duML7Kka VPBw== X-Gm-Message-State: AOAM532vszamoSvGEWrLTHBa5tB30k0qXn4hZKtG6LVZwJcFuqGiZKx0 UJAQYVRTdsGcHjsPKRJpq92glQ== X-Google-Smtp-Source: ABdhPJxC4jGH9js/28DTzQpRvZ4IBLyKiJDKoUfHaiXaxCscmtOSb6+KYszrts8CNNHGQNLMJ/jO0g== X-Received: by 2002:a17:90a:c58f:: with SMTP id l15mr12870593pjt.168.1636678268099; Thu, 11 Nov 2021 16:51:08 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id s21sm4279773pfk.3.2021.11.11.16.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 16:51:07 -0800 (PST) Date: Fri, 12 Nov 2021 00:51:03 +0000 From: Sean Christopherson To: "Maciej S. Szmigiero" Cc: James Morse , Alexandru Elisei , Suzuki K Poulose , Atish Patra , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Ben Gardon , Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Paolo Bonzini Subject: Re: [PATCH v5.5 26/30] KVM: Keep memslots in tree-based structures instead of array-based ones Message-ID: References: <20211104002531.1176691-1-seanjc@google.com> <20211104002531.1176691-27-seanjc@google.com> <5f5c80ce-9189-def3-9c50-d5a504925253@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5f5c80ce-9189-def3-9c50-d5a504925253@oracle.com> Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org On Fri, Nov 12, 2021, Maciej S. Szmigiero wrote: > On 04.11.2021 01:25, Sean Christopherson wrote: > > - /* > > - * Remove the old memslot from the hash list and interval tree, copying > > - * the node data would corrupt the structures. > > - */ > > + int as_id = kvm_memslots_get_as_id(old, new); > > + struct kvm_memslots *slots = kvm_get_inactive_memslots(kvm, as_id); > > + int idx = slots->node_idx; > > + > > if (old) { > > - hash_del(&old->id_node); > > - interval_tree_remove(&old->hva_node, &slots->hva_tree); > > + hash_del(&old->id_node[idx]); > > + interval_tree_remove(&old->hva_node[idx], &slots->hva_tree); > > - if (!new) > > + if ((long)old == atomic_long_read(&slots->last_used_slot)) > > + atomic_long_set(&slots->last_used_slot, (long)new); > > Open-coding cmpxchg() is way less readable than a direct call. Doh, I meant to call this out and/or add a comment. My objection to cmpxchg() is that it implies atomicity is required (the kernel's version adds the lock), which is very much not the case. So this isn't strictly an open-coded version of cmpxchg(). > The open-coded version also compiles on x86 to multiple instructions with > a branch, instead of just a single instruction. Yeah. The lock can't be contended, so that part of cmpxchg is a non-issue. But that's also why I don't love using cmpxchg. I don't have a strong preference, I just got briefly confused by the atomicity part. > > +static void kvm_invalidate_memslot(struct kvm *kvm, > > + struct kvm_memory_slot *old, > > + struct kvm_memory_slot *working_slot) > > +{ > > + /* > > + * Mark the current slot INVALID. As with all memslot modifications, > > + * this must be done on an unreachable slot to avoid modifying the > > + * current slot in the active tree. > > + */ > > + kvm_copy_memslot(working_slot, old); > > + working_slot->flags |= KVM_MEMSLOT_INVALID; > > + kvm_replace_memslot(kvm, old, working_slot); > > + > > + /* > > + * Activate the slot that is now marked INVALID, but don't propagate > > + * the slot to the now inactive slots. The slot is either going to be > > + * deleted or recreated as a new slot. > > + */ > > + kvm_swap_active_memslots(kvm, old->as_id); > > + > > + /* > > + * From this point no new shadow pages pointing to a deleted, or moved, > > + * memslot will be created. Validation of sp->gfn happens in: > > + * - gfn_to_hva (kvm_read_guest, gfn_to_pfn) > > + * - kvm_is_visible_gfn (mmu_check_root) > > + */ > > + kvm_arch_flush_shadow_memslot(kvm, old); > > This should flush the currently active slot (that is, "working_slot", > not "old") to not introduce a behavior change with respect to the existing > code. > > That's also what the previous version of this patch set did. Eww. I would much prefer to "fix" the existing code in a prep patch. It shouldn't matter, but arch code really should not get passed an INVALID slot. From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90D07C433EF for ; Fri, 12 Nov 2021 00:51:39 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4C11361268 for ; Fri, 12 Nov 2021 00:51:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4C11361268 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YzqEhxsILDYCC5Vr1B3Ra05Hx6Sj2K2e0PzdQd3KYKA=; b=oPbo+OvzyvsVOe w3ULNclW6eSu7UwG8sa83XeOrJgQdpwplee1syadJM4bbc4fv+K9v15YSA5Do+wjwMYbdzm4PCsfv f+DN/X3wL/fazmNO4D2VWw9mbcjf5eDF3JtYH+RG42QN8fh4Okz3vMoE9hhfXNBsBnHMYTCgmZO3r YTBIewYHj2h+NDB4ncWx9VBHrrmNpHzjB+gj+q39I9tnh0Ulj3RaiAgQtZBAGuZgSgkDSdzqmbv1y zDMlBKLtMVx4vB/i/Zp4aXI4YPKMA+Y7uBhKW+jJhK4tfOYXyB3O+d+YU6d+D/+AI/wbsUh2TEaHW 4rTO5xv/CQQtx6fsLDTA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mlKmr-009655-99; Fri, 12 Nov 2021 00:51:25 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mlKme-009626-6r for linux-riscv@lists.infradead.org; Fri, 12 Nov 2021 00:51:13 +0000 Received: by mail-pl1-x62f.google.com with SMTP id u11so7153264plf.3 for ; Thu, 11 Nov 2021 16:51:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=7VoEwbSPzrTyOh3w99mGEcK1Otv61yXE8VpDyQ7XU/Q=; b=aR0iTUNTxKf6faFpqVLtDxLZ+Z93VjgfuMSy8Y9h3wnwVUTL/oHfhEOsrg0V7yOdYT 7fq8GTKIKG9OH6zETAjAXEzMtYxKZ4n8vzmgKUi//wtyVazuE6xgdlSVa2YM1WXEZK7o ckgTdbQk1CrwriNKigDb1ZxyhMDgLtfKnE3RIVuAKQjcg2mMhNzjvwVYycKmLb0GnSZ1 GYcRaJBvetbHNGisq5tuHOigfRUZHZConfP9luv9GZtaibkXsyjw/cHwj8DSAwBW3aaZ 7VyKPKnacS2ZdpG3N5SRXdGPcXpnFm1QD3uLEDYX71FQ35qKY9q+/DI/dPGPqFGBB6ib ajeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7VoEwbSPzrTyOh3w99mGEcK1Otv61yXE8VpDyQ7XU/Q=; b=0dFstrMS5JIJfQNk/mkKBwV1KiwlQE3H0F74FKO4B3ErKlyzA86MhbQXSw5BJHAkuj dh67fPDrNuR0VZXtitYpbu03Invgti8hrn+vNMZHX5x5Bh9D3tZc0intc7mjJ1Qvg2Vr UnSjbGmbiMTCKJTaVsoEFd3FIbUpRWBsYl9NVkea4l/jcSeMFp3FMhoLdbVA2Owt8NQa I45dp+UxJqEY1/cZFUpN78NDvO+Hw2ktsBKhzrxRGfxSCQT/aNp7olwfpzjJ5UtoLUFv Bhq2NHnYvgtxf2rkNALM1R8eGpDrDyRZYNw1UMrZmTnJxKrblJGb53KfeN52+dAfx43d lS2w== X-Gm-Message-State: AOAM532/fFl/MRQtPENbCGMc3UDI29QsGHNQgtyZ9f/+d63oSlAuOT7/ agHaGEFJB/nvpq21fWA7JAw5CQ== X-Google-Smtp-Source: ABdhPJxC4jGH9js/28DTzQpRvZ4IBLyKiJDKoUfHaiXaxCscmtOSb6+KYszrts8CNNHGQNLMJ/jO0g== X-Received: by 2002:a17:90a:c58f:: with SMTP id l15mr12870593pjt.168.1636678268099; Thu, 11 Nov 2021 16:51:08 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id s21sm4279773pfk.3.2021.11.11.16.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 16:51:07 -0800 (PST) Date: Fri, 12 Nov 2021 00:51:03 +0000 From: Sean Christopherson To: "Maciej S. Szmigiero" Cc: James Morse , Alexandru Elisei , Suzuki K Poulose , Atish Patra , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Ben Gardon , Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Paolo Bonzini Subject: Re: [PATCH v5.5 26/30] KVM: Keep memslots in tree-based structures instead of array-based ones Message-ID: References: <20211104002531.1176691-1-seanjc@google.com> <20211104002531.1176691-27-seanjc@google.com> <5f5c80ce-9189-def3-9c50-d5a504925253@oracle.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <5f5c80ce-9189-def3-9c50-d5a504925253@oracle.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211111_165112_282690_5C010CF2 X-CRM114-Status: GOOD ( 23.68 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Fri, Nov 12, 2021, Maciej S. Szmigiero wrote: > On 04.11.2021 01:25, Sean Christopherson wrote: > > - /* > > - * Remove the old memslot from the hash list and interval tree, copying > > - * the node data would corrupt the structures. > > - */ > > + int as_id = kvm_memslots_get_as_id(old, new); > > + struct kvm_memslots *slots = kvm_get_inactive_memslots(kvm, as_id); > > + int idx = slots->node_idx; > > + > > if (old) { > > - hash_del(&old->id_node); > > - interval_tree_remove(&old->hva_node, &slots->hva_tree); > > + hash_del(&old->id_node[idx]); > > + interval_tree_remove(&old->hva_node[idx], &slots->hva_tree); > > - if (!new) > > + if ((long)old == atomic_long_read(&slots->last_used_slot)) > > + atomic_long_set(&slots->last_used_slot, (long)new); > > Open-coding cmpxchg() is way less readable than a direct call. Doh, I meant to call this out and/or add a comment. My objection to cmpxchg() is that it implies atomicity is required (the kernel's version adds the lock), which is very much not the case. So this isn't strictly an open-coded version of cmpxchg(). > The open-coded version also compiles on x86 to multiple instructions with > a branch, instead of just a single instruction. Yeah. The lock can't be contended, so that part of cmpxchg is a non-issue. But that's also why I don't love using cmpxchg. I don't have a strong preference, I just got briefly confused by the atomicity part. > > +static void kvm_invalidate_memslot(struct kvm *kvm, > > + struct kvm_memory_slot *old, > > + struct kvm_memory_slot *working_slot) > > +{ > > + /* > > + * Mark the current slot INVALID. As with all memslot modifications, > > + * this must be done on an unreachable slot to avoid modifying the > > + * current slot in the active tree. > > + */ > > + kvm_copy_memslot(working_slot, old); > > + working_slot->flags |= KVM_MEMSLOT_INVALID; > > + kvm_replace_memslot(kvm, old, working_slot); > > + > > + /* > > + * Activate the slot that is now marked INVALID, but don't propagate > > + * the slot to the now inactive slots. The slot is either going to be > > + * deleted or recreated as a new slot. > > + */ > > + kvm_swap_active_memslots(kvm, old->as_id); > > + > > + /* > > + * From this point no new shadow pages pointing to a deleted, or moved, > > + * memslot will be created. Validation of sp->gfn happens in: > > + * - gfn_to_hva (kvm_read_guest, gfn_to_pfn) > > + * - kvm_is_visible_gfn (mmu_check_root) > > + */ > > + kvm_arch_flush_shadow_memslot(kvm, old); > > This should flush the currently active slot (that is, "working_slot", > not "old") to not introduce a behavior change with respect to the existing > code. > > That's also what the previous version of this patch set did. Eww. I would much prefer to "fix" the existing code in a prep patch. It shouldn't matter, but arch code really should not get passed an INVALID slot. _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1726EC433F5 for ; Fri, 12 Nov 2021 00:52:31 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D19F260F55 for ; Fri, 12 Nov 2021 00:52:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D19F260F55 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SslLTIzZ4RFOZlokAF4qgxoK4yUxBmmU5LTtHxGbls0=; b=GeVaB5ibHubdZJ SeEsU9KpwqAsX1UVHxtPW9QF88A6s4VbsQ33SgUhGkr1V00VRXZ+4FExI/OGDgN022ozhxWyTH/hZ C1sBLylC4WEjxdUpEPMH+0/wRxLOFrvuDmJdmtDT15ZmV8feNrRsV8TUpmiR2YlOi7fNDLgQWRTK6 jqL3acMbnnadVL7O0NTBq3cfwTIOqP4gVwJacgcWThJtny7OayFSMfFRcS3hYeFCZNu+xdru9b7yI cnaaWvEgyfrEau9nEor9TcN5BBt1qVib33q2nhnUkRnnAK+1EJ3T+fpVmwqGStHfbj1hFMdH1NAxh GIAaBAQVySCqW+8NPF4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mlKmh-00964D-SO; Fri, 12 Nov 2021 00:51:16 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mlKme-009628-6S for linux-arm-kernel@lists.infradead.org; Fri, 12 Nov 2021 00:51:13 +0000 Received: by mail-pl1-x62b.google.com with SMTP id p18so7049049plf.13 for ; Thu, 11 Nov 2021 16:51:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=7VoEwbSPzrTyOh3w99mGEcK1Otv61yXE8VpDyQ7XU/Q=; b=aR0iTUNTxKf6faFpqVLtDxLZ+Z93VjgfuMSy8Y9h3wnwVUTL/oHfhEOsrg0V7yOdYT 7fq8GTKIKG9OH6zETAjAXEzMtYxKZ4n8vzmgKUi//wtyVazuE6xgdlSVa2YM1WXEZK7o ckgTdbQk1CrwriNKigDb1ZxyhMDgLtfKnE3RIVuAKQjcg2mMhNzjvwVYycKmLb0GnSZ1 GYcRaJBvetbHNGisq5tuHOigfRUZHZConfP9luv9GZtaibkXsyjw/cHwj8DSAwBW3aaZ 7VyKPKnacS2ZdpG3N5SRXdGPcXpnFm1QD3uLEDYX71FQ35qKY9q+/DI/dPGPqFGBB6ib ajeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7VoEwbSPzrTyOh3w99mGEcK1Otv61yXE8VpDyQ7XU/Q=; b=7AE6/ZhYkN3gbTLZSWA6XJLyPvR9AVI66KlsHeUApSL1SKnMKqYkU1stYVvzTY6NKc JzlnBg0Hoc5QI2vX0YOlslLFpWXdscAu0YobaaY5fLZh92IFAYOZdJ30G5zYump58PPK StkMIlvUXPWW1MCsD0/s57nU16TQ2Z1H6qvXgYIJNqDX9jGLDQXFWkDxyz+ij1gSr7fy jigq/rmZjnl+6rEIAs99lyHO11PScjgfokFrI85YANVl+V1QdHm7Adx6TLBSru44E4gE BHTmCEIMgJ41Yow4NTTT/5mtb+cML7ZCR7n6hVSna6AFkihil0EjzWVLGBpJGLBeGEC8 AoxA== X-Gm-Message-State: AOAM5303E7PGne6gkgALkSBfBaVuOgLMVa0pLZPnQA9n3hLhsO/FIOko X16p2L0zVGlcFv/yHYDSaiUDng== X-Google-Smtp-Source: ABdhPJxC4jGH9js/28DTzQpRvZ4IBLyKiJDKoUfHaiXaxCscmtOSb6+KYszrts8CNNHGQNLMJ/jO0g== X-Received: by 2002:a17:90a:c58f:: with SMTP id l15mr12870593pjt.168.1636678268099; Thu, 11 Nov 2021 16:51:08 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id s21sm4279773pfk.3.2021.11.11.16.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 16:51:07 -0800 (PST) Date: Fri, 12 Nov 2021 00:51:03 +0000 From: Sean Christopherson To: "Maciej S. Szmigiero" Cc: James Morse , Alexandru Elisei , Suzuki K Poulose , Atish Patra , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Ben Gardon , Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Paolo Bonzini Subject: Re: [PATCH v5.5 26/30] KVM: Keep memslots in tree-based structures instead of array-based ones Message-ID: References: <20211104002531.1176691-1-seanjc@google.com> <20211104002531.1176691-27-seanjc@google.com> <5f5c80ce-9189-def3-9c50-d5a504925253@oracle.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <5f5c80ce-9189-def3-9c50-d5a504925253@oracle.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211111_165112_279569_F7733044 X-CRM114-Status: GOOD ( 25.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Nov 12, 2021, Maciej S. Szmigiero wrote: > On 04.11.2021 01:25, Sean Christopherson wrote: > > - /* > > - * Remove the old memslot from the hash list and interval tree, copying > > - * the node data would corrupt the structures. > > - */ > > + int as_id = kvm_memslots_get_as_id(old, new); > > + struct kvm_memslots *slots = kvm_get_inactive_memslots(kvm, as_id); > > + int idx = slots->node_idx; > > + > > if (old) { > > - hash_del(&old->id_node); > > - interval_tree_remove(&old->hva_node, &slots->hva_tree); > > + hash_del(&old->id_node[idx]); > > + interval_tree_remove(&old->hva_node[idx], &slots->hva_tree); > > - if (!new) > > + if ((long)old == atomic_long_read(&slots->last_used_slot)) > > + atomic_long_set(&slots->last_used_slot, (long)new); > > Open-coding cmpxchg() is way less readable than a direct call. Doh, I meant to call this out and/or add a comment. My objection to cmpxchg() is that it implies atomicity is required (the kernel's version adds the lock), which is very much not the case. So this isn't strictly an open-coded version of cmpxchg(). > The open-coded version also compiles on x86 to multiple instructions with > a branch, instead of just a single instruction. Yeah. The lock can't be contended, so that part of cmpxchg is a non-issue. But that's also why I don't love using cmpxchg. I don't have a strong preference, I just got briefly confused by the atomicity part. > > +static void kvm_invalidate_memslot(struct kvm *kvm, > > + struct kvm_memory_slot *old, > > + struct kvm_memory_slot *working_slot) > > +{ > > + /* > > + * Mark the current slot INVALID. As with all memslot modifications, > > + * this must be done on an unreachable slot to avoid modifying the > > + * current slot in the active tree. > > + */ > > + kvm_copy_memslot(working_slot, old); > > + working_slot->flags |= KVM_MEMSLOT_INVALID; > > + kvm_replace_memslot(kvm, old, working_slot); > > + > > + /* > > + * Activate the slot that is now marked INVALID, but don't propagate > > + * the slot to the now inactive slots. The slot is either going to be > > + * deleted or recreated as a new slot. > > + */ > > + kvm_swap_active_memslots(kvm, old->as_id); > > + > > + /* > > + * From this point no new shadow pages pointing to a deleted, or moved, > > + * memslot will be created. Validation of sp->gfn happens in: > > + * - gfn_to_hva (kvm_read_guest, gfn_to_pfn) > > + * - kvm_is_visible_gfn (mmu_check_root) > > + */ > > + kvm_arch_flush_shadow_memslot(kvm, old); > > This should flush the currently active slot (that is, "working_slot", > not "old") to not introduce a behavior change with respect to the existing > code. > > That's also what the previous version of this patch set did. Eww. I would much prefer to "fix" the existing code in a prep patch. It shouldn't matter, but arch code really should not get passed an INVALID slot. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel