Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp462491pxb; Wed, 27 Jan 2021 12:03:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJy/E46/3Kfqm8Vc1bae5mz+HXApEKkd8vtYK7dO6mOawRbeg3YWzaPxz1dNbj1SnK14kLU4 X-Received: by 2002:a17:906:3285:: with SMTP id 5mr7144451ejw.356.1611777819043; Wed, 27 Jan 2021 12:03:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611777819; cv=none; d=google.com; s=arc-20160816; b=1CPLb5SmXdBVCGfXQcvL/CmF2BeTL4Ks7lxWm+gf4qnFHbfLzXTYmbgjwTteDaIXtB wsbjITTcfMp7GwjtmCmdn2NePf8vngZvQYlGY4W9VvUz65GhunPGqBUw29Xkc9VSXP0M nkVDugNEp9FdMOQFFiA1TId5qQFFoV2mRXEth6JKH/Ws0/XVHtUpMgLI/86/KhjjVgAI Ux09ieMrDKi9n1MaVVHgOhFfsye7pxqSU11rY5YKU4D+w9mgs8kMB2a5V2wmfrlSiT5i E8M0msZJwUtouYuJWb6djnErePTzc9q2AUlTonU4qsn4gH6++1aSI9OHglfouRsZXw8s nlKw== 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=ehN8g8luuF2BKLiZYDz35HTGbUgrzlwEK0VyDMRc1bE=; b=FcVv5zEYKVQ90Tv5X/PHoL6Ii/0GGNk6maa40fXbp+lHS34CNm3UIDFlWPcRcCqvtN 67TjfKK44rEAqQyXFoM0LsPMcTKlXJo/p3PPKTcN3xuvDl9ocn+cEG6LQYwOh+IK6XTy TIpa5ESVjLMF/qiVIUU5n/B5oSi47I2+lDWH8pJyjo7+SwVya346ujPJy1BiUHwzhSG8 izYWPWD2zmCNYGHwmxQKukzuHaIEuYYXTjbxsmjrmbcq8jZsuUPYa7A0WEyntrqJjvlE b4KdEt5w9JO81315+XrgFeXg+iD4hc4nWUTgLLmlzY8YNOD5mvHSJMsQWINWo9QFnWY2 27Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=u+tGmLta; 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 s16si1265407ejf.641.2021.01.27.12.03.13; Wed, 27 Jan 2021 12:03:39 -0800 (PST) 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=u+tGmLta; 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 S237204AbhA0Dsr (ORCPT + 99 others); Tue, 26 Jan 2021 22:48:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389646AbhA0AGp (ORCPT ); Tue, 26 Jan 2021 19:06:45 -0500 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C40ABC061794 for ; Tue, 26 Jan 2021 16:04:41 -0800 (PST) Received: by mail-pl1-x635.google.com with SMTP id r4so25237pls.11 for ; Tue, 26 Jan 2021 16:04:41 -0800 (PST) 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=ehN8g8luuF2BKLiZYDz35HTGbUgrzlwEK0VyDMRc1bE=; b=u+tGmLtats3b8HsEfxKVQgMK0GXcYfxMRPArDpxJoYSxVOHzNMkczWTT9UKc+iuL5c 1i80Ybhtd+JjjT+hrlRpf+r1Oti1xkqj1SSUkApAb7iuqNc0hAkpN+PYw76+kF30zXuT xKNeJ0v6+/QBYk7eVYWEZTsCW8IasRNlBF9OpHVGxlio9+VdQohz9RpJPqPxKapSecTH XpaQaL94Nfi9thSv44/gpO6nt2eB1Ocr0Vtnc3sPmSduLvYB3U07MvoJrdF3T7Y1+n08 NfLW9PKtYmJe5bubHPO75UGFwYTmQBwPme6NriQsLx5/PJNyd+X6U36wepGK/wdj+iNS wuJA== 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=ehN8g8luuF2BKLiZYDz35HTGbUgrzlwEK0VyDMRc1bE=; b=ZLzjIKSxb6dGodReNCl+TOOXTOGFtLsDl7FRK2bRoykp2U2Bhw3cWJywPkK0yOIa57 jBP3hleRagFwLz55O+vnjWDXLdYrp8TwCjwQER31HsW6BkwaxFVRo08XzSwKWsEAUQnP an3BxNqdUvVczdPms802uAY9EpjEFcGOIPZix7FjJjvtjxoBIhg6Muge8b+N84IT7509 WH3pSK0vCs1Ocke11Lcq+ynGYQHz6sKCkAuBE2gufS9fzqowWlGLrnHoc728hfJLf7zw CX8tPUR06d/7DEk8H1LnrGTViURgvsoOKP53xKda27wTQGsvWKcBuioQrZqYLjXy/Zx0 YhJw== X-Gm-Message-State: AOAM532/ozjVXugy/yZQBGNm9oNj+HNsZ+BUowy6mv3PchFTjKXKmTzv /1a0abtcjpCAFHw87qqRPBDBxQ== X-Received: by 2002:a17:90b:4a09:: with SMTP id kk9mr2478013pjb.15.1611705881203; Tue, 26 Jan 2021 16:04:41 -0800 (PST) Received: from google.com ([2620:15c:f:10:1ea0:b8ff:fe73:50f5]) by smtp.gmail.com with ESMTPSA id y4sm75088pji.34.2021.01.26.16.04.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 16:04:40 -0800 (PST) Date: Tue, 26 Jan 2021 16:04:33 -0800 From: Sean Christopherson To: David Stevens Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, open list , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, Huacai Chen , Aleksandar Markovic , linux-mips@vger.kernel.org, Paul Mackerras , kvm-ppc@vger.kernel.org, Christian Borntraeger , Janosch Frank , David Hildenbrand , Cornelia Huck , Claudio Imbrenda Subject: Re: [PATCH] KVM: x86/mmu: consider the hva in mmu_notifer retry Message-ID: References: <20210125064234.2078146-1-stevensd@google.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, Jan 26, 2021, David Stevens wrote: > > This needs a comment to explicitly state that 'count > 1' cannot be done at > > this time. My initial thought is that it would be more intuitive to check for > > 'count > 1' here, but that would potentially check the wrong wrange when count > > goes from 2->1. The comment about persistence in invalidate_range_start() is a > > good hint, but I think it's worth being explicit to avoid bad "cleanup" in the > > future. > > > > > + if (unlikely(kvm->mmu_notifier_count)) { > > > + if (kvm->mmu_notifier_range_start <= hva && > > > + hva < kvm->mmu_notifier_range_end) > > I'm not sure I understand what you're suggesting here. How exactly > would 'count > 1' be used incorrectly here? I'm fine with adding a > comment, but I'm not sure what the comment needs to clarify. There's no guarantee that the remaining in-progress invalidation when the count goes from 2->1 is the same invalidation call that set range_start/range_end. E.g. given two invalidations, A and B, the order of calls could be: kvm_mmu_notifier_invalidate_range_start(A) kvm_mmu_notifier_invalidate_range_start(B) kvm_mmu_notifier_invalidate_range_end(A) kvm_mmu_notifier_invalidate_range_end(B) <-- ??? or kvm_mmu_notifier_invalidate_range_start(A) kvm_mmu_notifier_invalidate_range_start(B) kvm_mmu_notifier_invalidate_range_end(B) kvm_mmu_notifier_invalidate_range_end(A) <-- ??? In the first case, "A" is in-progress when the count goes 2->1, in the second case "B" is still in-progress. Checking for "count > 1" in the consumer instead of handling it in the producer (as you did) would lead to the consumer checking against the wrong range. I don't see a way to solve that without adding some amount of history, which I agree is unnecessary.