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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id BF9C3C4345F for ; Fri, 12 Apr 2024 14:54:40 +0000 (UTC) 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:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=0orLHior4HmzLkNDErWqEzRDjGTlnXqEonFWA0XDWOU=; b=yXHXMNVACmScj31X0jXFEcyV4G TCxHtKSEttZUJXJWgxkxDZ5IVZC6I7ZCsIT6p5CVG+0m1bdQiGKUnDvP4W3tALgvchFAeJZMoAQEO blhAUjIoTeFFbmKdG61fkdnjDVDmzvmMC54jWbTeCFghEj5Jz4JZWwgTJ7581ROC4RLQzyBi19Noq 4XO89y/DjeLAOtqM4VAeq5syk5MDM5gxHW+7HbBJcyNXh7wRw9MFjydFFMZtnocA3MbDbKH/QbgMV d9NwOWUz6lP8eANL8l2oEVAF4T9Nf8JXDgfytfZUPI3SEMsst2hqH3bSIhoJAw6R+Hab7oJSq3+AF 7Fx8klAQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rvIIP-00000000693-0l40; Fri, 12 Apr 2024 14:54:29 +0000 Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rvIIL-00000000666-2nrS for linux-arm-kernel@lists.infradead.org; Fri, 12 Apr 2024 14:54:27 +0000 Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-6ed03216b70so956423b3a.3 for ; Fri, 12 Apr 2024 07:54:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712933664; x=1713538464; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ZrmdCrVWtwb7lFW6AyHWbgOgdloa5ymd2fy0iQuLqTo=; b=Etccv77pLe6symyFkJ8pk6AcO9tmZ7IkDPF9aVjutD/10CKymSjYwf3h1xT/Qvc78l 6lzlApYZa2Ha5I5EkD2YbwPY3WVFhHm0337PTH06nsAPjXGifNBnF5ptJELDQHTx9/1M seuXHa+roVVRj4Nu6BwfJF2DNBtMKFI5ReW5gose0PimGWnZalPU9jRuwD7UxQ6Vsug+ PAF3UkfVHLUfLzjUajoOGIwkVTQm1ercLs/EVKkecjP1Nr6hCZpVD8qGn9meuO8frif4 tkrUkrZY8nEPgzU7XWuOdeFiZE63Yvy/PKIV78J4mMQ/9bRqZ7wUkEUp9CkH1PHnElX1 sARg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712933664; x=1713538464; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZrmdCrVWtwb7lFW6AyHWbgOgdloa5ymd2fy0iQuLqTo=; b=hTB+CB6fioK/3vrk4SdjijC2UbMjuUWqBpw4cUm7sR7RdTfyR60SW/A3hDY2CHxVlt vOJnDXtU5TIyhxFC+rQf0BCjbp5cbxb741loLMVJ7ISSXXgyrYITV1D40BayfdvLE6q6 82chWiS3ZZ2J0XNWpOu41BrRRQwb7oyhMr48J3DTZKod+8g3LkI3mzsMkW7+h3qsACUt wVBn+Qyis8al72Du8BDyFoYz0MMTgyRyweM6cVXGkBsrBUtZ7seHPI8UAvB7fjGOe01U 04ssXHRHdxXH5bjguORLNBolbmoS8q3nUOewp/Ei/MAEDJfcKicf1+ovEu+q7hRNmr20 oA6w== X-Forwarded-Encrypted: i=1; AJvYcCXsPgo5hzbaGLIDRWuN4JoUp/y0c94XY6AqegkqmP8IyLAZuFLdrRPPchLUTatO03NOQWROQFg+SyO4in1WWWDyr5WsI7a3BHnGnYazuY9evF3j1Mc= X-Gm-Message-State: AOJu0YziU2I/m7KBx50TxNxnmqR8nNIcm7Hml3yOmSPRxjAVnMlQRO+f ubEeDAXW1wyNufhawqn1w/6hJuNNd3GoV64Zbkt0WnloXz8khhoO9C8zcdTzAHvkFZQcEsjRcOn TTQ== X-Google-Smtp-Source: AGHT+IE8CrGE6yHurBu6oRRUdhNStzcxsQMqGws9O1toyt+VIrjo1lbnGIr3E72VqB9zErBllk+K4v4iLAw= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:2d94:b0:6ed:95ce:3417 with SMTP id fb20-20020a056a002d9400b006ed95ce3417mr191844pfb.5.1712933663717; Fri, 12 Apr 2024 07:54:23 -0700 (PDT) Date: Fri, 12 Apr 2024 07:54:22 -0700 In-Reply-To: <86jzl2sovz.wl-maz@kernel.org> Mime-Version: 1.0 References: <20240405115815.3226315-1-pbonzini@redhat.com> <20240405115815.3226315-2-pbonzini@redhat.com> <20240412104408.GA27645@willie-the-truck> <86jzl2sovz.wl-maz@kernel.org> Message-ID: Subject: Re: [PATCH 1/4] KVM: delete .change_pte MMU notifier callback From: Sean Christopherson To: Marc Zyngier Cc: Will Deacon , Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Oliver Upton , Tianrui Zhao , Bibo Mao , Thomas Bogendoerfer , Nicholas Piggin , Anup Patel , Atish Patra , Andrew Morton , David Hildenbrand , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240412_075425_774115_7E8FD1D4 X-CRM114-Status: GOOD ( 27.13 ) 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, Apr 12, 2024, Marc Zyngier wrote: > On Fri, 12 Apr 2024 11:44:09 +0100, Will Deacon wrote: > > On Fri, Apr 05, 2024 at 07:58:12AM -0400, Paolo Bonzini wrote: > > Also, if you're in the business of hacking the MMU notifier code, it > > would be really great to change the .clear_flush_young() callback so > > that the architecture could handle the TLB invalidation. At the moment, > > the core KVM code invalidates the whole VMID courtesy of 'flush_on_ret' > > being set by kvm_handle_hva_range(), whereas we could do a much > > lighter-weight and targetted TLBI in the architecture page-table code > > when we actually update the ptes for small ranges. > > Indeed, and I was looking at this earlier this week as it has a pretty > devastating effect with NV (it blows the shadow S2 for that VMID, with > costly consequences). > > In general, it feels like the TLB invalidation should stay with the > code that deals with the page tables, as it has a pretty good idea of > what needs to be invalidated and how -- specially on architectures > that have a HW-broadcast facility like arm64. Would this be roughly on par with an in-line flush on arm64? The simpler, more straightforward solution would be to let architectures override flush_on_ret, but I would prefer something like the below as x86 can also utilize a range-based flush when running as a nested hypervisor. diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index ff0a20565f90..b65116294efe 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -601,6 +601,7 @@ static __always_inline kvm_mn_ret_t __kvm_handle_hva_range(struct kvm *kvm, struct kvm_gfn_range gfn_range; struct kvm_memory_slot *slot; struct kvm_memslots *slots; + bool need_flush = false; int i, idx; if (WARN_ON_ONCE(range->end <= range->start)) @@ -653,10 +654,22 @@ static __always_inline kvm_mn_ret_t __kvm_handle_hva_range(struct kvm *kvm, break; } r.ret |= range->handler(kvm, &gfn_range); + + /* + * Use a precise gfn-based TLB flush when possible, as + * most mmu_notifier events affect a small-ish range. + * Fall back to a full TLB flush if the gfn-based flush + * fails, and don't bother trying the gfn-based flush + * if a full flush is already pending. + */ + if (range->flush_on_ret && !need_flush && r.ret && + kvm_arch_flush_remote_tlbs_range(kvm, gfn_range.start + gfn_range.end - gfn_range.start + 1)) + need_flush = true; } } - if (range->flush_on_ret && r.ret) + if (need_flush) kvm_flush_remote_tlbs(kvm); if (r.found_memslot) _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel