Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp605467lqp; Wed, 12 Jun 2024 10:32:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXJ9sYTFsjFa/6ec/Ton6EuAgLl+ebSOQyNwH1Ccc/loac1y7dV/CIPnOPOxv2e9D4rU1pAXOueVPe1mkUsj7rDusH0GJ/LhzqM3js/LA== X-Google-Smtp-Source: AGHT+IEuw5e2Bdob7DCowdoQ0MJOeyB5g5DpS5XAhKfEyt/GBhWDH/YhK5FDmYtyODhF+lG7yYN8 X-Received: by 2002:a05:6a21:615:b0:1b6:e885:1bc8 with SMTP id adf61e73a8af0-1b8a9be884emr2255644637.28.1718213544455; Wed, 12 Jun 2024 10:32:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718213544; cv=pass; d=google.com; s=arc-20160816; b=f7oyh6Hal+ExYBn0UeaoC6GI0DBK4gapSzzCSLAv1WQrpXBKaNSOzRB7GLTiWPwR1f reLR4RjVyuaT0936qSawkC/zuDpx8T8LDVJ/FguYiQHe3YXUAqU+nTBIQz1XVHlon2Ze qk5G+ZhiVXOtPRi8YZYjPSwxpV6+j0hzHz2oy+R4Abx1DfR2RNSQncJ6N+nTySI049xt uV5E5moXYqziO5WGT9eKYy+hR9Kz29y6aNMP1wnRMchw0I/tQkZ3950DSQ2mwgrxheka xjAxMl4oNZpRd3lBINfPzv3fEy6x9taISW+7eUL17yDVj5ddDFt1bDEETZxGTVPa7ZwL 9b2A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=ZttrWbEybPZrU6j9LIdJZge1/Pd2kmv/UPX9FdzbJ4o=; fh=0qB9wwM3lVU/95XSweps3XwFQEAKbvZKx5GQsWNKdiU=; b=jJycg3qoH7WF+iTFDBb6W+Jdvof62v6c32Hy1JhVCz0GQ7CCaApau8Mxf0JBl1E3eN aePIB/SFjcV5vxJ927m9XUYZ4I/DTSTJTBMzjErdBcliNy1xeT2zyCB8UlxjEJ/3EqGJ lkwpVcgv+AZxq2k8tMojCBqdYwUTFd/HNG15LHSSGp20V++Q80C9B+6E2nGGt5FR19QF RTNoY/3UkA5chvhx99TX921FkLQiUdExD6IxvFdfrPpuS2VWCMt3kcMCzg1AmMA1fkfO 2zzfduyrsonOccKBrE6xbJtXeH9J+oBUFUNz55SKkGqqlTCMj9S3pla4ygJRnj4eIeza rbrQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=yZgdmIRv; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-212010-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212010-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f6bd760694si113909515ad.11.2024.06.12.10.32.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 10:32:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212010-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=yZgdmIRv; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-212010-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212010-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 45F4F283D27 for ; Wed, 12 Jun 2024 17:31:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3B9921822DE; Wed, 12 Jun 2024 17:31:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yZgdmIRv" Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E7AD155CA3 for ; Wed, 12 Jun 2024 17:31:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718213492; cv=none; b=TQ0if0tPY5LHcroBZizB+DT3UWcNLKzg1E1B7N4+MPGazo/9RcB4wTa1r5RRMs6OPpkPWkFyqwyRqOCuNoPsOE7enSCBLRQiDHDXqosEmIUnP7mbPVg6Dc8EesKQaG3biNCC4ctwlu8iJVS8jKOj1NHMTBQSaLpUwCZ4RHyAewU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718213492; c=relaxed/simple; bh=BVxVglBu/aJdIm8zaMwOg3iRpiLrT6XOkxr2cN79Qtg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=e4HgCJZvdnYayysDROLD96eQZoz8Yc6zspl4ud88fYhWhVIVffpRgdxm54zih0j/klw/wACAxlWVc6GzhKdMqrhRQX5cXlhtatYw0vy03zFakqczQcVM08Y9S6N0pQFCyH1ap+Zibj9i9jUGkg+FD45kQio993kWAUTpbVE5hZ0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=yZgdmIRv; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-1f71d5a85f9so1532985ad.0 for ; Wed, 12 Jun 2024 10:31:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718213489; x=1718818289; darn=vger.kernel.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=ZttrWbEybPZrU6j9LIdJZge1/Pd2kmv/UPX9FdzbJ4o=; b=yZgdmIRv2moEI8Zld6u/VkhMeDaPNBowLD5mqzgUawyckf+6uKgiEpnvneIfP4v8FV WOmAWW33+keA4TocyR7SUMJNYlJpph+hMQPsIC1mrHssbSFAHZTXAqQI2k+94Z3JGRZn ssrk2ZmjVaV6UA0nwa0tJ4gqdz4iSiDj1mEE2QfORsmHVs/vuIIHBKIISR8+YIwFMihi uWyFttAx4xGdHXoGdh0ZviEmhP6pdwqNgaKk7Jk1eMhE78nW8BaFAkeky4PAgXWNl+0N cPERpKsYDxaqxIt6hjIe2mhbLo4cc0aMRh490Ha3fAaChpygl6QgWdjucY1jWosdeXr3 b4Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718213489; x=1718818289; 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=ZttrWbEybPZrU6j9LIdJZge1/Pd2kmv/UPX9FdzbJ4o=; b=IbK2vK5ttWVGwOb2UMEcL2KU88oP2L/SAtrxbTa/cPJzwPg9iJ6DszKvxqmYVG90SJ dmJLOJGjggM74ZeaWkvUOyhdctS/fBjTgTk++Ff3Gn2J/SoOVxKl7JoR9PrJqkCt672w sy31s8yrJsp+syFNns/UHnBRTK5s27JxhiUNPDPBBu5Pc1u275P+4wKhbi0JFW3otD1w jqbonl/5/oead3lKof6ziMQ9c+crX0PkDvgpYnbwCs8m2HWtvH1EqRymCAFKFaTsrhvM fdN4STTwvkc3QnDr7TfgUc8JqdBw4TE+u4EwcCgMc63nVT7ZTZ7QO/dMQIYOC7PwE90X 0SrQ== X-Forwarded-Encrypted: i=1; AJvYcCWZ3aJp4R0v5UF5v8UZvaURhmx4eWDXe0usju2vjt7t6vevDQfbpsHFDscuKXHqsvFrkw+r17HLCYlLA8Hfv1D4XlubwD6yvnPyc0fz X-Gm-Message-State: AOJu0YxK+8E3im7/vaViyfyMpeyWQ4vlYoqpL6YTv3ION3kc5icPQVky CYxHP0NVmkE5e7HZFzInu3Wqku7l3+pgcKE9lxMpjXTeAnvDSXBa1txQKIZ0Z4Erx0fooNwBZQl xEw== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:903:182:b0:1f3:4b2a:1acb with SMTP id d9443c01a7336-1f83b23ddb1mr79315ad.0.1718213489334; Wed, 12 Jun 2024 10:31:29 -0700 (PDT) Date: Wed, 12 Jun 2024 10:31:27 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240405115815.3226315-2-pbonzini@redhat.com> <20240412104408.GA27645@willie-the-truck> <86jzl2sovz.wl-maz@kernel.org> <86h6g5si0m.wl-maz@kernel.org> <20240418141932.GA1855@willie-the-truck> <20240419112432.GB2972@willie-the-truck> Message-ID: Subject: Re: [PATCH 1/4] KVM: delete .change_pte MMU notifier callback From: Sean Christopherson To: Will Deacon Cc: Marc Zyngier , 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 Content-Type: text/plain; charset="us-ascii" On Wed, Jun 12, 2024, Sean Christopherson wrote: > On Fri, Apr 19, 2024, Will Deacon wrote: > > On Thu, Apr 18, 2024 at 12:53:26PM -0700, Sean Christopherson wrote: > > > On Thu, Apr 18, 2024, Will Deacon wrote: > > > > > I assume the idea would be to let arch code do single-page invalidations of > > > > > stage-2 entries for each gfn? > > > > > > > > Right, as it's the only code which knows which ptes actually ended up > > > > being aged. > > > > > > > > > Unless I'm having a brain fart, x86 can't make use of that functionality. Intel > > > > > doesn't provide any way to do targeted invalidation of stage-2 mappings. AMD > > > > > provides an instruction to do broadcast invalidations, but it takes a virtual > > > > > address, i.e. a stage-1 address. I can't tell if it's a host virtual address or > > > > > a guest virtual address, but it's a moot point because KVM doen't have the guest > > > > > virtual address, and if it's a host virtual address, there would need to be valid > > > > > mappings in the host page tables for it to work, which KVM can't guarantee. > > > > > > > > Ah, so it sounds like it would need to be an arch opt-in then. > > > > > > Even if x86 (or some other arch code) could use the precise tracking, I think it > > > would make sense to have the behavior be arch specific. Adding infrastructure > > > to get information from arch code, only to turn around and give it back to arch > > > code would be odd. > > > > Sorry, yes, that's what I had in mind. Basically, a way for the arch code > > to say "I've handled the TLBI, don't worry about it." > > > > > Unless arm64 can't do the invalidation immediately after aging the stage-2 PTE, > > > the best/easiest solution would be to let arm64 opt out of the common TLB flush > > > when a SPTE is made young. > > > > > > With the range-based flushing bundled in, this? > > > > > > --- > > > include/linux/kvm_host.h | 2 ++ > > > virt/kvm/kvm_main.c | 40 +++++++++++++++++++++++++--------------- > > > 2 files changed, 27 insertions(+), 15 deletions(-) > > > > > > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > > > index afbc99264ffa..8fe5f5e16919 100644 > > > --- a/include/linux/kvm_host.h > > > +++ b/include/linux/kvm_host.h > > > @@ -2010,6 +2010,8 @@ extern const struct kvm_stats_header kvm_vcpu_stats_header; > > > extern const struct _kvm_stats_desc kvm_vcpu_stats_desc[]; > > > > > > #ifdef CONFIG_KVM_GENERIC_MMU_NOTIFIER > > > +int kvm_arch_flush_tlb_if_young(void); > > > + > > > static inline int mmu_invalidate_retry(struct kvm *kvm, unsigned long mmu_seq) > > > { > > > if (unlikely(kvm->mmu_invalidate_in_progress)) > > > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > > > index 38b498669ef9..5ebef8ef239c 100644 > > > --- a/virt/kvm/kvm_main.c > > > +++ b/virt/kvm/kvm_main.c > > > @@ -595,6 +595,11 @@ static void kvm_null_fn(void) > > > } > > > #define IS_KVM_NULL_FN(fn) ((fn) == (void *)kvm_null_fn) > > > > > > +int __weak kvm_arch_flush_tlb_if_young(void) > > > +{ > > > + return true; > > > +} > > > > I tend to find __weak functions a little ugly, but I think the gist of the > > diff looks good to me. Thanks for putting it together! > > Circling back to this, I don't think we should pursue this specific tweak, at > least not without hard data for a concrete use case. Ha, I spoke too soon. Based on the learning from the KVM+MGLRU thread[*], it looks like KVM should omit the TLB flush when aging pages whenever possible. If that's not doable on all architectures for whatever reason, then something like this is probably the way to go. [*] https://lore.kernel.org/all/CAOUHufYCmYNngmS=rOSAQRB0N9ai+mA0aDrB9RopBvPHEK42Ng@mail.gmail.com