Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4602774pxv; Tue, 27 Jul 2021 11:19:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUEXr4Yaehwvg1KYbdHU31GWooG3vVBTyvEg/9IwFZh65XXhCqUKQ3wZLPOYMz2r9d1Q9s X-Received: by 2002:a05:6e02:96a:: with SMTP id q10mr17262827ilt.235.1627409987006; Tue, 27 Jul 2021 11:19:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627409986; cv=none; d=google.com; s=arc-20160816; b=jR+4nFxnLsYcqIwaBf+LJKJS4Ib7E92iWxVzCq+JLatR0NYzFX93u775wl8ZTfH5vi meW5GttLpncYxrdUoH42FsgmiUyGd2c24YTwZSN6Z2swWLIVoOIF+agPBctqC8Xd0Utx nvHukuZmZA+WpGZrnrBRBiiMJQ79TaX6rtOoIKu+0qi8iXdfMu2fQUpTt3FhO8loQHiB wWKAmxSpVMCHfwBQh5JofTDOpZMYNPilBelHdBUXARfuO6KsaOlhYDDABY1IlYwdZ093 kNAkJII2716OPF332ta2vgZzkkWlb0sI/aP93YQDQ03v09i1hqxglw3qV9Bxiagpnd62 E1cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=+s15nut/2SxrGQ322z8+gWVFmP+vDGNZBfdbvFgLxUE=; b=ipD0qz+qucVqleRiDsTJWDcAcChH9uF0lGwa2xY6mkre5Dnpa0QDi+7rqmL+djvqxU mxC8EExfXuL1VkI14NILL+Vs5n3JiOM3ohCNcIfnLhX6oHq6TB1sBonXBkNsCzSbQfeZ KzzqJOn1ZNB37UXHZ2s8nESd5WwwnjPDY03ThTZAw1dAk45Y4bXbIUCCT0HJWed4h+wb Pc6YaXp5EssleioSipA6kwwWvbECSHDAYCxl3U3aTMeihUWKBuciC5ya/tWxSO/bitzg csxDxdeSrvDeygmK6uk0pSB4VvalnD/lkYaqENTMPGJk8uUTWm4+1ydJTO9yjvR+HMns R17w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Itw6lhNN; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s14si4008727jar.33.2021.07.27.11.19.36; Tue, 27 Jul 2021 11:19:46 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=Itw6lhNN; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231956AbhG0SRl (ORCPT + 99 others); Tue, 27 Jul 2021 14:17:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbhG0SRi (ORCPT ); Tue, 27 Jul 2021 14:17:38 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF3EBC061760 for ; Tue, 27 Jul 2021 11:17:37 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id e21so12259864pla.5 for ; Tue, 27 Jul 2021 11:17:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=+s15nut/2SxrGQ322z8+gWVFmP+vDGNZBfdbvFgLxUE=; b=Itw6lhNN5TGYy0Peur2pD3tsj4JAjzMGqY1gicu3nnEiQigCTChrZwCUEoe3sNQr0f M1aym5fGw5OL4WEUnWMiYnQ0tHR+YjyiwuM7iCtbm0/FWYtlmIC5EbncykR0nQ5KbEHZ MGPfxxSH7sxTTAOJfKUJHTP33N46xStQmPCjKu08VetOHx+Ry/CDTD1M+hUskSWieV7r 4SVbAbf6oQV3eS9qGiwAikzN//gkbd+2il7Oa0y0yKKF7YtQweFyQw/s/1ey2cejdWUG G00EqJ97Ai7+bzGNtBgp6hp8fIY97Hs4c0Vdakp+ZH9ECCpSQXSM1CT1zS/RvphLrKMh 9Cvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=+s15nut/2SxrGQ322z8+gWVFmP+vDGNZBfdbvFgLxUE=; b=JxE9rGaX9i/TqwbRX7Uq1hzHGPun4q2wJwDghoYlNNEW5+QSwAf+tx8OV5BTnf2GgI FzHr/T3G5AGcbzc9LVGiZYqayhniwUvLT6JrUu6ske2XOxWWDqnv04ZLkAoxeGuzYVS1 m0zjMy6t6Bki8jxOq4hSs65E/NWi2SxU17TEW/tA+CVJz8G3K+U590B+VJkM5NQSdDgw V6vPrp6LXooLFOJUyjWbZBvvzixTdW2ZmRBWYwQ3Hk5fPKd1VSgSdTuLg/7LlLwK2HTA g2IXyopRqSGxpZcD7qKwsNrqBJGeHu/xtKfdJqvrx60pM7mWS2YRw0hDNUJJk3czc7hA cC2Q== X-Gm-Message-State: AOAM530nc6IFkeTz94v/W4psiQO3kToKXAqiWX7BYIAWlj2b11CnEoYb 64U/ralvrRp3I+QnvjDz+H9iwvvq8PDyeA== X-Received: by 2002:a17:90a:19c2:: with SMTP id 2mr23625400pjj.233.1627409857193; Tue, 27 Jul 2021 11:17:37 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id k198sm4509280pfd.148.2021.07.27.11.17.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jul 2021 11:17:36 -0700 (PDT) Date: Tue, 27 Jul 2021 18:17:32 +0000 From: Sean Christopherson To: Ben Gardon Cc: Maxim Levitsky , kvm , "open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Jim Mattson , Joerg Roedel , Borislav Petkov , Vitaly Kuznetsov , Wanpeng Li , Paolo Bonzini , Thomas Gleixner , "H. Peter Anvin" , Ingo Molnar , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" Subject: Re: [PATCH v2 8/8] KVM: x86: hyper-v: Deactivate APICv only when AutoEOI feature is in use Message-ID: References: <20210713142023.106183-1-mlevitsk@redhat.com> <20210713142023.106183-9-mlevitsk@redhat.com> <64ed28249c1895a59c9f2e2aa2e4c09a381f69e5.camel@redhat.com> <714b56eb83e94aca19e35a8c258e6f28edc0a60d.camel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 27, 2021, Ben Gardon wrote: > On Tue, Jul 27, 2021 at 6:06 AM Maxim Levitsky wrote: > > > > On Thu, 2021-07-22 at 19:06 +0000, Sean Christopherson wrote: > > > The elevated mmu_notifier_count and/or changed mmu_notifier_seq will cause vCPU1 > > > to bail and resume the guest without fixing the #NPF. After acquiring mmu_lock, > > > vCPU1 will see the elevated mmu_notifier_count (if kvm_zap_gfn_range() is about > > > to be called, or just finised) and/or a modified mmu_notifier_seq (after the > > > count was decremented). > > > > > > This is why kvm_zap_gfn_range() needs to take mmu_lock for write. If it's allowed > > > to run in parallel with the page fault handler, there's no guarantee that the > > > correct apic_access_memslot_enabled will be observed. > > > > I understand now. > > > > So, Paolo, Ben Gardon, what do you think. Do you think this approach is feasable? > > Do you agree to revert the usage of the read lock? > > > > I will post a new series using this approach very soon, since I already have > > msot of the code done. > > > > Best regards, > > Maxim Levitsky > > From reading through this thread, it seems like switching from read > lock to write lock is only necessary for a small range of GFNs, (i.e. > the APIC access page) is that correct? For the APICv case, yes, literally a single GFN (the default APIC base). > My initial reaction was that switching kvm_zap_gfn_range back to the > write lock would be terrible for performance, but given its only two > callers, I think it would actually be fine. And more importantly, the two callers are gated by kvm_arch_has_noncoherent_dma() and are very rare flows for the guest (updating MTRRs, toggling CR0.CD). > If you do that though, you should pass shared=false to > kvm_tdp_mmu_zap_gfn_range in that function, so that it knows it's > operating with exclusive access to the MMU lock. Ya, my suggested revert was to drop @shared entirely since kvm_zap_gfn_range() is the only caller that passes @shared=true.