Received: by 2002:a05:7208:2204:b0:82:bbfa:f723 with SMTP id s4csp345920rbb; Thu, 18 Apr 2024 07:24:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVxpvoSqdRkV07BaEtV3RFXz1bnDeUHseeB7mfNIKFiAvE/OPfuHzur9widB5YeHg/+rOtZsxVi3Z3XtrmoJzeNykqGMVvsJBSMQloboQ== X-Google-Smtp-Source: AGHT+IGHq93i2ZGCg/2RiS/HGM72jpxPZrdRr8vJfKD52hzXnDq5FtYkdSFuEu4zOv+A11Yf9NKn X-Received: by 2002:a05:690c:38b:b0:61a:b00a:ff9 with SMTP id bh11-20020a05690c038b00b0061ab00a0ff9mr3068559ywb.13.1713450268715; Thu, 18 Apr 2024 07:24:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713450268; cv=pass; d=google.com; s=arc-20160816; b=MGPGgjohHksceVvgOykqeojQl0CDhfokG5iBOBZzQTYFr/owST/ezFtBIxzQ5UllG5 7ozbmZtqOx7rZEyVPyGZwtmNruELHB5x29CvznKLkd28zLoGvq71WcZGa5z2vN5vw9XH EcSrIrafqKN/FGakcy48tVLL8bKdPtssjP6DO4FjcVpVuXm02riLKZjXFxMv7QMegLAF IzKGK+ICnnk1YoxkX0GXEejUdiDw/aJvdk2b78ZjvZzT7cA/WeNMjcauJy+AvbzD+vxj cn/DrcFNvyc3Uyg05WT2+mo7K6XtfHY6Idls+r360zx21BKxdRkIlVVBxgIONDp1Nwho KEpA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature; bh=JHM9gWRrmHbAaM2SOH4J5dGK7Jtzwfox31fBgMl6LAM=; fh=jz13G+pdU2xQO/ro6uf9dJ25/TK8UuXFNok3tiNhR9s=; b=0ffVBwaWsisnKcQzR3xto75ckPyi2J1cDuTgcD0Ix7BGj2LunTom1VHl7FYw1TGy6+ oxoVN+wyQ7Gg+3CbVymchxqIv1Y1MJ1yb9cAwcRablTHJXXZXvj0ojn9pETEznLU7QKA 4v5GCUXskCrvaKzPLa2rnl8cu8Wh5XAGao9d4DTCGXGHipmCpm32nv8sgWWixCWx/8q9 Izg50VNf6TNgNHcPEtpghecPKAECNGYnSajNqFaIse4wdpPlzLTkrJbZsUU2Ua0u6zJA kWkigK4Jt3mjH/n96G/Dxa2IOnMg3vC9YRZ4uz4aJSd41+yJIzHBvLmqUfmw6ugOXBko ZCSw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="B2pNwg/h"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-150288-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150288-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g19-20020a05620a109300b0078ecc362509si1506857qkk.759.2024.04.18.07.24.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 07:24:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150288-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="B2pNwg/h"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-150288-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150288-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 522D01C2378C for ; Thu, 18 Apr 2024 14:23:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A59616C436; Thu, 18 Apr 2024 14:19:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="B2pNwg/h" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9EF921635C8; Thu, 18 Apr 2024 14:19:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713449980; cv=none; b=VK+zdNN+9gG4MnwGWVWkh6fw8mulMI9fIbD/YVff/D8vuFEJorj+KlP1fxSkB7ZVwZd0U7epelTj1OEO5BBG2OyVArhx4Ivl63HGJnegazSRmKUJ4X82X+p88oQW1SuSHQGmbhu2Hx1dU7cfx1SHL3kgC59V8is+gUj3lsdYgow= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713449980; c=relaxed/simple; bh=AUt0AvjyUjML6ZxpdeebsS26lKqvFMfvN3N/sVPtRcY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fD6ZJUe5UvWgYnHyQmPd8l8WrJ9o2nHqnHqI+A4xy9v+/+OC85Z2YOlzElmR6jEvbEEXbgqz4xnn5Gv7S7v4eHL6DxFKuYY9X7PEoEjCGk31B6lPaESl9jxdajBoLf6OI9TkYmcTHCUd3ZneBtlTkuXbP8W78XhIya5ZEVocnk0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=B2pNwg/h; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03DADC32781; Thu, 18 Apr 2024 14:19:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713449980; bh=AUt0AvjyUjML6ZxpdeebsS26lKqvFMfvN3N/sVPtRcY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=B2pNwg/hwD4GFU+j3nK1XWEUYARxusswHne4K6Z5OpMVZCZ5ULburdPwHrZg5I4iu U/y9G2YsiGlibZSfkHi7l9Xc1A1byzgoT5FVOk+X4RFIoKyf/9F5r8tzdINa6Ps8CK NPuSjycgX6VTiF+iVSS1slG1ZPMnyNtYdJWJVNkY44ow8evHMgw76zaMNBUTb1gBOc nj3GHa4KAPMpDuvEycIrwcKhHJVzFpCFK7p7pG+gbOJbi5QsNN4n2gti59vuYtfqHK aaq8X28NwfZ8l26T0x1HIRhf7nZrUbo6m75mqZ305iGTMgwp0/oNpia09G3VtqBot9 UR6a8YKfras6w== Date: Thu, 18 Apr 2024 15:19:32 +0100 From: Will Deacon To: Sean Christopherson 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 Subject: Re: [PATCH 1/4] KVM: delete .change_pte MMU notifier callback Message-ID: <20240418141932.GA1855@willie-the-truck> References: <20240405115815.3226315-1-pbonzini@redhat.com> <20240405115815.3226315-2-pbonzini@redhat.com> <20240412104408.GA27645@willie-the-truck> <86jzl2sovz.wl-maz@kernel.org> <86h6g5si0m.wl-maz@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) On Mon, Apr 15, 2024 at 10:03:51AM -0700, Sean Christopherson wrote: > On Sat, Apr 13, 2024, Marc Zyngier wrote: > > On Fri, 12 Apr 2024 15:54:22 +0100, Sean Christopherson wrote: > > > > > > 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. > > ... > > > I think this works for us on HW that has range invalidation, which > > would already be a positive move. > > > > For the lesser HW that isn't range capable, it also gives the > > opportunity to perform the iteration ourselves or go for the nuclear > > option if the range is larger than some arbitrary constant (though > > this is additional work). > > > > But this still considers the whole range as being affected by > > range->handler(). It'd be interesting to try and see whether more > > precise tracking is (or isn't) generally beneficial. > > 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. Will