From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (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 5486836C for ; Sat, 4 Jan 2025 03:08:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=96.67.55.147 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735960107; cv=none; b=YBoElL4fs236ndkRjnPJy9cEvFDSROqkJ4VTfaBmCq1dbM9tasUi0lr0BwiutSJdDUaWQ35P9G6U99hhhVKmYLIzwUDeKcG5B5dZoU2xNVIBXtaoNjHh9f8sxU00PU0mFWFaDwM3t2iJ2eSBSRzTmDCb3p+iX94+YT3bWHRnBbs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735960107; c=relaxed/simple; bh=i0yhxDmQOeyIw8vfXaCGj5Eh6WuFs2uMOQxEPu5sfvU=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=CTWe8p0O9ncHwNvRW+aC2n8qEKATBAbSnKTtS7+SoDQ2ZYidhW/RGa+X+3+o2nQ+iTDVy69VCn7FxyN0REPTjOr0SwwJowC+M9g7Mvic8t7lSBzf4wLeX6JdSZo0pyk2EGyIMfZoJS4+sN7qEOmiyKnerP3YYnmORxzfyZ3Q2u4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=surriel.com; spf=pass smtp.mailfrom=shelob.surriel.com; arc=none smtp.client-ip=96.67.55.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=surriel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shelob.surriel.com Received: from fangorn.home.surriel.com ([10.0.13.7]) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1tTuWI-000000000z1-1zWE; Fri, 03 Jan 2025 22:08:10 -0500 Message-ID: <287e8a60e302929588eaf095584838fa745d69ac.camel@surriel.com> Subject: Re: [PATCH 11/12] x86/mm: enable AMD translation cache extensions From: Rik van Riel To: Jann Horn Cc: x86@kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, akpm@linux-foundation.org, nadav.amit@gmail.com, zhengqi.arch@bytedance.com, linux-mm@kvack.org Date: Fri, 03 Jan 2025 22:08:06 -0500 In-Reply-To: References: <20241230175550.4046587-1-riel@surriel.com> <20241230175550.4046587-12-riel@surriel.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.54.1 (3.54.1-1.fc41) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Sender: riel@surriel.com On Fri, 2025-01-03 at 18:49 +0100, Jann Horn wrote: > On Mon, Dec 30, 2024 at 6:53=E2=80=AFPM Rik van Riel = =20 > > only those upper-level entries that lead to the target PTE in > > the page table hierarchy, leaving unrelated upper-level entries > > intact. >=20 > How does this patch interact with KVM SVM guests? > In particular, will this patch cause TLB flushes performed by guest > kernels to behave differently? >=20 That is a good question. A Linux guest should be fine, since Linux already flushes the parts of the TLB where page tables are being freed. I don't know whether this could potentially break some non-Linux guests, though. > [...] > > diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c > > index 454a370494d3..585d0731ca9f 100644 > > --- a/arch/x86/mm/tlb.c > > +++ b/arch/x86/mm/tlb.c > > @@ -477,7 +477,7 @@ static void broadcast_tlb_flush(struct > > flush_tlb_info *info) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (info->stride_shift > PMD= _SHIFT) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 maxnr =3D 1; > >=20 > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (info->end =3D=3D TLB_FLUSH_AL= L) { > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (info->end =3D=3D TLB_FLUSH_AL= L || info->freed_tables) { > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 invlpgb_flush_single_pcid(kern_pcid(asid)); > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 /* Do any CPUs supporting INVLPGB need PTI? */ > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 if (static_cpu_has(X86_FEATURE_PTI)) > > @@ -1110,7 +1110,7 @@ static void flush_tlb_func(void *info) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * The only question is= whether to do a full or partial > > flush. > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * We do a partial flush if = requested and two extra > > conditions > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * We do a partial flush if = requested and three extra > > conditions > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * are met: > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * 1. f->new_tlb_gen = =3D=3D local_tlb_gen + 1.=C2=A0 We have an > > invariant that > > @@ -1137,10 +1137,14 @@ static void flush_tlb_func(void *info) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 *=C2=A0=C2=A0=C2=A0 da= te.=C2=A0 By doing a full flush instead, we can increase > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 *=C2=A0=C2=A0=C2=A0 lo= cal_tlb_gen all the way to mm_tlb_gen and we can > > probably > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 *=C2=A0=C2=A0=C2=A0 av= oid another flush in the very near future. > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * 3. No page tables were fr= eed. If page tables were freed, > > a full > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 *=C2=A0=C2=A0=C2=A0 flush e= nsures intermediate translations in the TLB > > get flushed. > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 */ >=20 > Why is this necessary - do we ever issue TLB flushes that are > intended > to zap upper-level entries which are not covered by the specified > address range? >=20 > When, for example, free_pmd_range() gets rid of a page table, it > calls > pmd_free_tlb(), which sets tlb->freed_tables and does > tlb_flush_pud_range(tlb, address, PAGE_SIZE). >=20 I missed those calls. It looks like this change is not needed. Of course, the way pmd_free_tlb() operates, the partial zaps done in that code will exceed the (default 33 pages) value of tlb_single_page_flush_ceiling, and the code in flush_tlb_mm_range() will already do a full flush by default today. I'll leave out these unnecessary changes in the next version. --=20 All Rights Reversed.