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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DEB41C4332F for ; Fri, 9 Dec 2022 08:58:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4623F8E0003; Fri, 9 Dec 2022 03:58:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4117C8E0001; Fri, 9 Dec 2022 03:58:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2DAB48E0003; Fri, 9 Dec 2022 03:58:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 1B0D48E0001 for ; Fri, 9 Dec 2022 03:58:12 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id DD3E01C69B9 for ; Fri, 9 Dec 2022 08:58:11 +0000 (UTC) X-FDA: 80222165982.04.C497D62 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) by imf16.hostedemail.com (Postfix) with ESMTP id 3DAE5180010 for ; Fri, 9 Dec 2022 08:58:09 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="E/x8MfyH"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf16.hostedemail.com: domain of tabba@google.com designates 209.85.167.54 as permitted sender) smtp.mailfrom=tabba@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670576290; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Gp1CS7Meiq+pIbSii4z5cXIlLneg3MN7qFdozmHymVI=; b=c9heEzyowr3vqLVb01erzp6Dkl95JdJvs7fXjp5vmQ6TlS9zGePREJlsVBDrlC79AieB1u UZRbsFfzrccfe1MMJfKTCYXbOws5YwQx1I9u+P66s5QljjqGc9RAjeZuXRrKdC4WSfqFRL 9n+hJZB9O+qkxk1cXiWX7nmqKq6c2Eo= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="E/x8MfyH"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf16.hostedemail.com: domain of tabba@google.com designates 209.85.167.54 as permitted sender) smtp.mailfrom=tabba@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670576290; a=rsa-sha256; cv=none; b=BILWb629sY7dKDiROTdrYDaqJQ7xashL7nzzjQwbXkmFt6d4lG6kvpUbZXFoGJFcQ4Mukl y6d5HhgY3935+6EK9YqKGycx72Dv0OwETsOhDG2YzS+Z99RXIiqEui024it/4ZnNc3O8MG 43/2acVS2ANz9AcCjM/8lI+KF76bL6g= Received: by mail-lf1-f54.google.com with SMTP id x28so6008992lfn.6 for ; Fri, 09 Dec 2022 00:58:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Gp1CS7Meiq+pIbSii4z5cXIlLneg3MN7qFdozmHymVI=; b=E/x8MfyHq0pvG76tFAoTpvy7CIl6AZ/DXSktZtUUHx9htZyzZzIyyyejJX+Z5LhNoZ BfbRN8UAevFSOtzp4JppIsvy8NAubeUIHoHXy12LJuicNHsxJ0ywnFBkhhPc0wmIeQWb qcUXLfwjYDJqHZKmmDI4xG32Clrn1p+sZEjlkB8NpHfgUxqZRGgC2sRwQyb7LuDb930C KP/SCBSPi9LZmWY759rSxQzO90/iJms/Iy5PVWFItww2bXmVN5m0QPWs27fPnxDmmAFp rW6dv5i9kdZ7njcnskoLufcW0vlq6jRAQLaWkJ3bzoUVJVyWcssXqX+JaUJ3Qd8tbnae PtoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Gp1CS7Meiq+pIbSii4z5cXIlLneg3MN7qFdozmHymVI=; b=cNm3HtRwcyO6C3yeAqQMZoqsHIPcuWNU2nn3RBDqFcEbpduC61C6SU2eW41kePCZa4 RLENR+lkxdADpnp+uE2coTOL0HVlMM/SCPakfA3lmT5pNgwIqIIwH+eolQkLZZZ9J+V3 8Z6eYhbCMu8sUwj74bqP7Fewbx/WAYzKAzqPK0RAkcWos0oRwTHnm5BSNm8AgODb330F 0ztfQRSRL242cKPtrjyrvk3K2iwA4oCd3vRXandbMPncm0ECWVIt/U/Mprn1HrNgXAEu m4kNMGlRTfqVOMbYPQ7BNE3huCNYNdS93/lUNbxWjvYLqWbd+G6Ry6whraDrQ+dXFP4/ AJMg== X-Gm-Message-State: ANoB5pkzmz+wJhVMrmrFfyKCJi7hPjbRM8NC37peKvwIA+1oCpmJTy0U QzoLy+Lql/sEUUb0YhvSmQF98YhI0ouFm3OnZGMCfw== X-Google-Smtp-Source: AA0mqf6DXGi83+EtVqrYOPd7DkCwuGXo4btVdvKWiVU8r9LgbIx2JZR0SIbABL87tZxVPowMY+gUHClt3SoCihIF5Fw= X-Received: by 2002:a05:6512:3287:b0:4b5:65e6:7ba2 with SMTP id p7-20020a056512328700b004b565e67ba2mr7947255lfe.598.1670576288101; Fri, 09 Dec 2022 00:58:08 -0800 (PST) MIME-Version: 1.0 References: <20221202061347.1070246-1-chao.p.peng@linux.intel.com> <20221202061347.1070246-7-chao.p.peng@linux.intel.com> <20221208111336.GA1304936@chaop.bj.intel.com> In-Reply-To: <20221208111336.GA1304936@chaop.bj.intel.com> From: Fuad Tabba Date: Fri, 9 Dec 2022 08:57:31 +0000 Message-ID: Subject: Re: [PATCH v10 6/9] KVM: Unmap existing mappings when change the memory attributes To: Chao Peng Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, qemu-devel@nongnu.org, Paolo Bonzini , Jonathan Corbet , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Arnd Bergmann , Naoya Horiguchi , Miaohe Lin , x86@kernel.org, "H . Peter Anvin" , Hugh Dickins , Jeff Layton , "J . Bruce Fields" , Andrew Morton , Shuah Khan , Mike Rapoport , Steven Price , "Maciej S . Szmigiero" , Vlastimil Babka , Vishal Annapurve , Yu Zhang , "Kirill A . Shutemov" , luto@kernel.org, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, david@redhat.com, aarcange@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, Quentin Perret , Michael Roth , mhocko@suse.com, wei.w.wang@intel.com Content-Type: text/plain; charset="UTF-8" X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 3DAE5180010 X-Stat-Signature: rtmbqgfdei15dc9oe11nsspx6gu1xsd7 X-HE-Tag: 1670576289-585523 X-HE-Meta: U2FsdGVkX19nttO1+QerZVXPNaGJls4phnLzUvJ3j3+4g/hp/ZxrNAKRnu4cQN4FRHkuvw36rJzC1H+1b6lWsthZlKFEPoWSOn0oDsYyohYjXA5rvYJ4gG4+4kKv5vNhyHg12G5kL+tTorq5ZqsSI4qCpNEzSSUg8b1vtWqIN8bq6Kdmt9c7TRwq/05LrQs8DpfUEKky/Cy2lsbu7nkA/emNVKNUPq8JeK9mWUMwOBdFYRztWXBs0440854cNnFrpW/5KcMEwC//OGnJ3yyXKBRrESfal2Y/tKnkGlJZYoykvLX/PHB1yu5ITk+pUN6UlAJBTjXQJ4eQbywsb5qNTJj80SNAoV443E4H8rMkFoWgfymRMEXBdkFYcWDEsdfq4pBaOqNU/iwaa3tWbSVoG5T/5EpfQG4E8UG6a8UjPY9nJIgP5Cm94lfSo5Y22vVIh8dGjO2QWpOItjfOCez2XfTAJ2KQvNwjDi2pVtZF8IbzjAjxEUrZovWVQx3chwvIwhbvA3x1eghsJ7HKZTDu4GGKmtqls++TiZVIubtyTPqqDoGym20ZY48BDYXbN9X9pqR580SH0cRUSzqQPWvDib4c2iukWkVnUoH4uj+nO3un7nRDklbPU3PDxXfo/iEznC27tbWfUuXNHRLHUsG2LBzRiVMly2+YWUFjl2s4RoCJmD1OW8g6H4kN0+BwFbkhQacOsox3lb9qmO7hdmPvtr1IOraB1We5PY7cDOx0uKNSoVVZZ6Z8FXIP0ngzFJ35mEQ/PXCLeLS336sRvchhcucUaI06a9Edb1rj3OY8u/sDsFaVZ6zO/NfBpDAPwcYn8mmvLTh5kWkKWhA1lKeMgEUcfwvvE8vw52FFuQW3w7m5CazdfuC/nWDGTVbfOxigBrPH5SxaoxEY0MZ6ioDj8h7yzZCEkRShE5qs4uqUkjnAw260DwMWE1Qh43Q+5p1hhjt/BZ9xwhyWLVhhZb/ pXhAjBRO rQA+RowCbAqgVQ+U= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi, On Thu, Dec 8, 2022 at 11:18 AM Chao Peng wrote: > > On Wed, Dec 07, 2022 at 05:16:34PM +0000, Fuad Tabba wrote: > > Hi, > > > > On Fri, Dec 2, 2022 at 6:19 AM Chao Peng wrote: > > > > > > Unmap the existing guest mappings when memory attribute is changed > > > between shared and private. This is needed because shared pages and > > > private pages are from different backends, unmapping existing ones > > > gives a chance for page fault handler to re-populate the mappings > > > according to the new attribute. > > > > > > Only architecture has private memory support needs this and the > > > supported architecture is expected to rewrite the weak > > > kvm_arch_has_private_mem(). > > > > This kind of ties into the discussion of being able to share memory in > > place. For pKVM for example, shared and private memory would have the > > same backend, and the unmapping wouldn't be needed. > > > > So I guess that, instead of kvm_arch_has_private_mem(), can the check > > be done differently, e.g., with a different function, say > > kvm_arch_private_notify_attribute_change() (but maybe with a more > > friendly name than what I suggested :) )? > > Besides controlling the unmapping here, kvm_arch_has_private_mem() is > also used to gate the memslot KVM_MEM_PRIVATE flag in patch09. I know > unmapping is confirmed unnecessary for pKVM, but how about > KVM_MEM_PRIVATE? Will pKVM add its own flag or reuse KVM_MEM_PRIVATE? > If the answer is the latter, then yes we should use a different check > which only works for confidential usages here. I think it makes sense for pKVM to use the same flag (KVM_MEM_PRIVATE) and not to add another one. Thank you, /fuad > > Thanks, > Chao > > > > Thanks, > > /fuad > > > > > > > > Also, during memory attribute changing and the unmapping time frame, > > > page fault handler may happen in the same memory range and can cause > > > incorrect page state, invoke kvm_mmu_invalidate_* helpers to let the > > > page fault handler retry during this time frame. > > > > > > Signed-off-by: Chao Peng > > > --- > > > include/linux/kvm_host.h | 7 +- > > > virt/kvm/kvm_main.c | 168 ++++++++++++++++++++++++++------------- > > > 2 files changed, 116 insertions(+), 59 deletions(-) > > > > > > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > > > index 3d69484d2704..3331c0c92838 100644 > > > --- a/include/linux/kvm_host.h > > > +++ b/include/linux/kvm_host.h > > > @@ -255,7 +255,6 @@ bool kvm_setup_async_pf(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, > > > int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu); > > > #endif > > > > > > -#ifdef KVM_ARCH_WANT_MMU_NOTIFIER > > > struct kvm_gfn_range { > > > struct kvm_memory_slot *slot; > > > gfn_t start; > > > @@ -264,6 +263,8 @@ struct kvm_gfn_range { > > > bool may_block; > > > }; > > > bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range); > > > + > > > +#ifdef KVM_ARCH_WANT_MMU_NOTIFIER > > > bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range); > > > bool kvm_test_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range); > > > bool kvm_set_spte_gfn(struct kvm *kvm, struct kvm_gfn_range *range); > > > @@ -785,11 +786,12 @@ struct kvm { > > > > > > #if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER) > > > struct mmu_notifier mmu_notifier; > > > +#endif > > > unsigned long mmu_invalidate_seq; > > > long mmu_invalidate_in_progress; > > > gfn_t mmu_invalidate_range_start; > > > gfn_t mmu_invalidate_range_end; > > > -#endif > > > + > > > struct list_head devices; > > > u64 manual_dirty_log_protect; > > > struct dentry *debugfs_dentry; > > > @@ -1480,6 +1482,7 @@ bool kvm_arch_dy_has_pending_interrupt(struct kvm_vcpu *vcpu); > > > int kvm_arch_post_init_vm(struct kvm *kvm); > > > void kvm_arch_pre_destroy_vm(struct kvm *kvm); > > > int kvm_arch_create_vm_debugfs(struct kvm *kvm); > > > +bool kvm_arch_has_private_mem(struct kvm *kvm); > > > > > > #ifndef __KVM_HAVE_ARCH_VM_ALLOC > > > /* > > > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > > > index ad55dfbc75d7..4e1e1e113bf0 100644 > > > --- a/virt/kvm/kvm_main.c > > > +++ b/virt/kvm/kvm_main.c > > > @@ -520,6 +520,62 @@ void kvm_destroy_vcpus(struct kvm *kvm) > > > } > > > EXPORT_SYMBOL_GPL(kvm_destroy_vcpus); > > > > > > +void kvm_mmu_invalidate_begin(struct kvm *kvm) > > > +{ > > > + /* > > > + * The count increase must become visible at unlock time as no > > > + * spte can be established without taking the mmu_lock and > > > + * count is also read inside the mmu_lock critical section. > > > + */ > > > + kvm->mmu_invalidate_in_progress++; > > > + > > > + if (likely(kvm->mmu_invalidate_in_progress == 1)) { > > > + kvm->mmu_invalidate_range_start = INVALID_GPA; > > > + kvm->mmu_invalidate_range_end = INVALID_GPA; > > > + } > > > +} > > > + > > > +void kvm_mmu_invalidate_range_add(struct kvm *kvm, gfn_t start, gfn_t end) > > > +{ > > > + WARN_ON_ONCE(!kvm->mmu_invalidate_in_progress); > > > + > > > + if (likely(kvm->mmu_invalidate_in_progress == 1)) { > > > + kvm->mmu_invalidate_range_start = start; > > > + kvm->mmu_invalidate_range_end = end; > > > + } else { > > > + /* > > > + * Fully tracking multiple concurrent ranges has diminishing > > > + * returns. Keep things simple and just find the minimal range > > > + * which includes the current and new ranges. As there won't be > > > + * enough information to subtract a range after its invalidate > > > + * completes, any ranges invalidated concurrently will > > > + * accumulate and persist until all outstanding invalidates > > > + * complete. > > > + */ > > > + kvm->mmu_invalidate_range_start = > > > + min(kvm->mmu_invalidate_range_start, start); > > > + kvm->mmu_invalidate_range_end = > > > + max(kvm->mmu_invalidate_range_end, end); > > > + } > > > +} > > > + > > > +void kvm_mmu_invalidate_end(struct kvm *kvm) > > > +{ > > > + /* > > > + * This sequence increase will notify the kvm page fault that > > > + * the page that is going to be mapped in the spte could have > > > + * been freed. > > > + */ > > > + kvm->mmu_invalidate_seq++; > > > + smp_wmb(); > > > + /* > > > + * The above sequence increase must be visible before the > > > + * below count decrease, which is ensured by the smp_wmb above > > > + * in conjunction with the smp_rmb in mmu_invalidate_retry(). > > > + */ > > > + kvm->mmu_invalidate_in_progress--; > > > +} > > > + > > > #if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER) > > > static inline struct kvm *mmu_notifier_to_kvm(struct mmu_notifier *mn) > > > { > > > @@ -714,45 +770,6 @@ static void kvm_mmu_notifier_change_pte(struct mmu_notifier *mn, > > > kvm_handle_hva_range(mn, address, address + 1, pte, kvm_set_spte_gfn); > > > } > > > > > > -void kvm_mmu_invalidate_begin(struct kvm *kvm) > > > -{ > > > - /* > > > - * The count increase must become visible at unlock time as no > > > - * spte can be established without taking the mmu_lock and > > > - * count is also read inside the mmu_lock critical section. > > > - */ > > > - kvm->mmu_invalidate_in_progress++; > > > - > > > - if (likely(kvm->mmu_invalidate_in_progress == 1)) { > > > - kvm->mmu_invalidate_range_start = INVALID_GPA; > > > - kvm->mmu_invalidate_range_end = INVALID_GPA; > > > - } > > > -} > > > - > > > -void kvm_mmu_invalidate_range_add(struct kvm *kvm, gfn_t start, gfn_t end) > > > -{ > > > - WARN_ON_ONCE(!kvm->mmu_invalidate_in_progress); > > > - > > > - if (likely(kvm->mmu_invalidate_in_progress == 1)) { > > > - kvm->mmu_invalidate_range_start = start; > > > - kvm->mmu_invalidate_range_end = end; > > > - } else { > > > - /* > > > - * Fully tracking multiple concurrent ranges has diminishing > > > - * returns. Keep things simple and just find the minimal range > > > - * which includes the current and new ranges. As there won't be > > > - * enough information to subtract a range after its invalidate > > > - * completes, any ranges invalidated concurrently will > > > - * accumulate and persist until all outstanding invalidates > > > - * complete. > > > - */ > > > - kvm->mmu_invalidate_range_start = > > > - min(kvm->mmu_invalidate_range_start, start); > > > - kvm->mmu_invalidate_range_end = > > > - max(kvm->mmu_invalidate_range_end, end); > > > - } > > > -} > > > - > > > static bool kvm_mmu_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range) > > > { > > > kvm_mmu_invalidate_range_add(kvm, range->start, range->end); > > > @@ -806,23 +823,6 @@ static int kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier *mn, > > > return 0; > > > } > > > > > > -void kvm_mmu_invalidate_end(struct kvm *kvm) > > > -{ > > > - /* > > > - * This sequence increase will notify the kvm page fault that > > > - * the page that is going to be mapped in the spte could have > > > - * been freed. > > > - */ > > > - kvm->mmu_invalidate_seq++; > > > - smp_wmb(); > > > - /* > > > - * The above sequence increase must be visible before the > > > - * below count decrease, which is ensured by the smp_wmb above > > > - * in conjunction with the smp_rmb in mmu_invalidate_retry(). > > > - */ > > > - kvm->mmu_invalidate_in_progress--; > > > -} > > > - > > > static void kvm_mmu_notifier_invalidate_range_end(struct mmu_notifier *mn, > > > const struct mmu_notifier_range *range) > > > { > > > @@ -1140,6 +1140,11 @@ int __weak kvm_arch_create_vm_debugfs(struct kvm *kvm) > > > return 0; > > > } > > > > > > +bool __weak kvm_arch_has_private_mem(struct kvm *kvm) > > > +{ > > > + return false; > > > +} > > > + > > > static struct kvm *kvm_create_vm(unsigned long type, const char *fdname) > > > { > > > struct kvm *kvm = kvm_arch_alloc_vm(); > > > @@ -2349,15 +2354,47 @@ static u64 kvm_supported_mem_attributes(struct kvm *kvm) > > > return 0; > > > } > > > > > > +static void kvm_unmap_mem_range(struct kvm *kvm, gfn_t start, gfn_t end) > > > +{ > > > + struct kvm_gfn_range gfn_range; > > > + struct kvm_memory_slot *slot; > > > + struct kvm_memslots *slots; > > > + struct kvm_memslot_iter iter; > > > + int i; > > > + int r = 0; > > > + > > > + gfn_range.pte = __pte(0); > > > + gfn_range.may_block = true; > > > + > > > + for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++) { > > > + slots = __kvm_memslots(kvm, i); > > > + > > > + kvm_for_each_memslot_in_gfn_range(&iter, slots, start, end) { > > > + slot = iter.slot; > > > + gfn_range.start = max(start, slot->base_gfn); > > > + gfn_range.end = min(end, slot->base_gfn + slot->npages); > > > + if (gfn_range.start >= gfn_range.end) > > > + continue; > > > + gfn_range.slot = slot; > > > + > > > + r |= kvm_unmap_gfn_range(kvm, &gfn_range); > > > + } > > > + } > > > + > > > + if (r) > > > + kvm_flush_remote_tlbs(kvm); > > > +} > > > + > > > static int kvm_vm_ioctl_set_mem_attributes(struct kvm *kvm, > > > struct kvm_memory_attributes *attrs) > > > { > > > gfn_t start, end; > > > unsigned long i; > > > void *entry; > > > + int idx; > > > u64 supported_attrs = kvm_supported_mem_attributes(kvm); > > > > > > - /* flags is currently not used. */ > > > + /* 'flags' is currently not used. */ > > > if (attrs->flags) > > > return -EINVAL; > > > if (attrs->attributes & ~supported_attrs) > > > @@ -2372,6 +2409,13 @@ static int kvm_vm_ioctl_set_mem_attributes(struct kvm *kvm, > > > > > > entry = attrs->attributes ? xa_mk_value(attrs->attributes) : NULL; > > > > > > + if (kvm_arch_has_private_mem(kvm)) { > > > + KVM_MMU_LOCK(kvm); > > > + kvm_mmu_invalidate_begin(kvm); > > > + kvm_mmu_invalidate_range_add(kvm, start, end); > > > + KVM_MMU_UNLOCK(kvm); > > > + } > > > + > > > mutex_lock(&kvm->lock); > > > for (i = start; i < end; i++) > > > if (xa_err(xa_store(&kvm->mem_attr_array, i, entry, > > > @@ -2379,6 +2423,16 @@ static int kvm_vm_ioctl_set_mem_attributes(struct kvm *kvm, > > > break; > > > mutex_unlock(&kvm->lock); > > > > > > + if (kvm_arch_has_private_mem(kvm)) { > > > + idx = srcu_read_lock(&kvm->srcu); > > > + KVM_MMU_LOCK(kvm); > > > + if (i > start) > > > + kvm_unmap_mem_range(kvm, start, i); > > > + kvm_mmu_invalidate_end(kvm); > > > + KVM_MMU_UNLOCK(kvm); > > > + srcu_read_unlock(&kvm->srcu, idx); > > > + } > > > + > > > attrs->address = i << PAGE_SHIFT; > > > attrs->size = (end - i) << PAGE_SHIFT; > > > > > > -- > > > 2.25.1 > > >