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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DBE8E77188 for ; Fri, 10 Jan 2025 19:46:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB7ED6B00D4; Fri, 10 Jan 2025 14:46:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A67AF6B00DA; Fri, 10 Jan 2025 14:46:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 909546B00DC; Fri, 10 Jan 2025 14:46:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6A03E6B00D4 for ; Fri, 10 Jan 2025 14:46:36 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D88CA1A0C9C for ; Fri, 10 Jan 2025 19:46:35 +0000 (UTC) X-FDA: 82992574350.17.40E3AED Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf20.hostedemail.com (Postfix) with ESMTP id 3E6311C0010 for ; Fri, 10 Jan 2025 19:46:32 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf20.hostedemail.com: domain of riel@shelob.surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@shelob.surriel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736538392; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0eF//gM1W+KvxSXMn2C8YEIl0z+GhBcbndXroO0BFvU=; b=mMP3gaqVALwveRyHGrfBjpIqEni0JimFVhD5WUUeKlGJPNWccZUufA+Rpud6zF/NKaORfz Ht7GmJI9uWx1nFcRfKt0RdxMpJiMQ3UCIGrINks2P9NHxPS2BHDjZQWXoQykucT4WvRwzr 4LPKJ8BsGIvlWmevIDcrZ9dV2th78OI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736538392; a=rsa-sha256; cv=none; b=Utbnx14WZPJBFLWrR9aLoiP6QLUB7Aa4K5Ge8AZMCy4Javy/Sa9hb4iSPuCPAiW2RA9NYq j3V/gKZ0VUZXj+6N6/74hHn3ayW82PVP/O14U6FYCpbcrnHgHQqpZyZwjbSKJt1pYjVJZU S04IHAfxuD0uH4XuIbiIsyO13a0f/BM= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf20.hostedemail.com: domain of riel@shelob.surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@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 1tWKwh-000000006Cj-1VSw; Fri, 10 Jan 2025 14:45:27 -0500 Message-ID: <8a8765c3d4f6154d38e00219cae739245d15cc1e.camel@surriel.com> Subject: Re: [PATCH 11/12] x86/mm: enable AMD translation cache extensions From: Rik van Riel To: Tom Lendacky , x86@kernel.org Cc: 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, 10 Jan 2025 14:45:27 -0500 In-Reply-To: <2cf92ecf-cd14-734a-6dd9-bd489321651e@amd.com> References: <20241230175550.4046587-1-riel@surriel.com> <20241230175550.4046587-12-riel@surriel.com> <2cf92ecf-cd14-734a-6dd9-bd489321651e@amd.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.54.1 (3.54.1-1.fc41) MIME-Version: 1.0 X-Stat-Signature: bdqecw9c5oxc5y8chyse641xbe8j34nm X-Rspamd-Queue-Id: 3E6311C0010 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1736538392-713159 X-HE-Meta: U2FsdGVkX1/+mYwuQPejJnvCphsBcD7GJB3TPNriL3m0Vd1uuxiWqouGHksAW0pRusamdRBMfHRM0jJZxPe6XjsVEjpNj5rdJfYeH5ljZrrtCh5O3aiWrROTYkfiKQ0fgQMle0+3Rfu9gbn+B5bLx2h6r67RmUUSBY2iS3W/3x30Ea0caMlqQBtvPBJIYhLp8fWFpHoRLQAfiUsLL2IBV+toIQ5bBgbziTqBC8XT7Iy0SOHFqCLayb4IcZR0iBeMKL8hW4E9eTwFgAlma7imSwjyrVzsR46zr9/LcBAmZ0FcJpeAfzqwN265sjwzylScVgZEg4Uhw8y2GzwzW2izCQwE7yEl1pIZrIueDAozTySx1IOMhjp2+oxkLnzoi5RnSS5Z7pa3ZQyQJCvVTHSxkhftd+UlSsDJnKOor200knhbE7y8uewgTFHZf5/gmPRjnyaKd/nRqv4cMqggcx9JAy9y+X9n1KJGP3mtbSLz3w2sBNstYB+BhsSMXTv8MFsfRqbQnipF/fzv57SI9TGsi446hi9pey3ecafsWVKekuT8wTA++xBrvNPvH9pxOZRJmvkASXwFpUHdyyzY+yj9ysgJ9o7jnws01p8sYVkv6JHkOa0N/qrS17xyG5boHCzSlSQvsfzeNAqJIlmCt0eJEgYXJlu4YgoRuwk18YRwylWElj8sdtHM5qKfhZHNdCfLS9GZbHNHfu+HZVHHR8i6oJKiWFPzTet0dHceoriz3b3zTNZ/SSWXFlbdeusQ1etzA5FmYySBTb8OfIuLuDjY+rOXvq2WQFMs9FWQIrSb++zQSLeS+/RqAkFFQ0odRIqjFta1p6zIagGwWGQ49zSGbpop56A/wZMyUMJL1+ZNpGZyXkT66WnJdw9adoh9X1BqyS4AsFKr7Unr0FO1xQBiV20YTNMxO5FnfKSgLYdBDPbKyWeeNFt8B7Nl1OtnBXecJ6HHI3GFsnlUgTqTlc3 RUaGvBo1 kXWOu2L7j6bT6rUITSpCrgIjrNYuZ4Oeqllr9l6DbxnWOGC8QUYumZMxAf5RhhM+7zrA3bqh7luCCNc2lSijzAhvQR5mpt1YsvfGi+bZ7wgHygINeYvfC1XckUC/j2mIgnOSef+Dww0rKFnqGzB9ntAA4eFmgZbBXL+Dj5DCaBX3Pez77RrrrDez2Fz9QAZf12gbu7lKaDGRPWWC9Cd051zfbcqAHfgxvPdlafwiKqN8eeDygVZ1m3jlEDWrhry7EVlohqcbcA9zuvDPWYi5+8VsbUFH98r9oBkaH0J2qxen/xeUl/we/dTPryhg7YpLDw4TC+Pv7WoNWEzPP6mEY7vlNtg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Fri, 2025-01-10 at 13:34 -0600, Tom Lendacky wrote: >=20 > > +++ b/arch/x86/kernel/cpu/amd.c > > @@ -1143,6 +1143,14 @@ static void cpu_detect_tlb_amd(struct > > cpuinfo_x86 *c) > > =C2=A0 > > =C2=A0 /* Max number of pages INVLPGB can invalidate in one shot > > */ > > =C2=A0 invlpgb_count_max =3D (edx & 0xffff) + 1; > > + > > + /* If supported, enable translation cache extensions (TCE) > > */ > > + cpuid(0x80000001, &eax, &ebx, &ecx, &edx); > > + if (ecx & BIT(17)) { >=20 > Back to my comment from patch #4, you can put this under the > cpu_feature_enabled() check and just set it. >=20 Ohhh nice, so I can just add a CPUID feature bit for TCE, and then have this? if(cpu_feature_enabled(X86_FEATURE_TCE)) msr_set_bit(MSR_EFER, EFER_TCE); That is much nicer. Is this the right location for that code, or do I need to move it somewhere else to guarantee TCE gets enabled on every CPU? > > + u64 msr =3D native_read_msr(MSR_EFER);; > > + msr |=3D BIT(15); > > + wrmsrl(MSR_EFER, msr); >=20 > msr_set_bit() ? >=20 > Thanks, > Tom >=20 > > + } > > =C2=A0} > > =C2=A0 > > =C2=A0static const struct cpu_dev amd_cpu_dev =3D { > > 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 if (info->stride_shift > PMD_SHIFT) > > =C2=A0 maxnr =3D 1; > > =C2=A0 > > - if (info->end =3D=3D TLB_FLUSH_ALL) { > > + if (info->end =3D=3D TLB_FLUSH_ALL || info->freed_tables) { > > =C2=A0 invlpgb_flush_single_pcid(kern_pcid(asid)); > > =C2=A0 /* Do any CPUs supporting INVLPGB need PTI? */ > > =C2=A0 if (static_cpu_has(X86_FEATURE_PTI)) > > @@ -1110,7 +1110,7 @@ static void flush_tlb_func(void *info) > > =C2=A0 * > > =C2=A0 * The only question is whether to do a full or partial > > flush. > > =C2=A0 * > > - * We do a partial flush if requested and two extra > > conditions > > + * We do a partial flush if requested and three extra > > conditions > > =C2=A0 * are met: > > =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 date.=C2=A0 By doing a full flush instead, = we can > > increase > > =C2=A0 *=C2=A0=C2=A0=C2=A0 local_tlb_gen all the way to mm_tlb_gen and= we can > > probably > > =C2=A0 *=C2=A0=C2=A0=C2=A0 avoid another flush in the very near future= . > > + * > > + * 3. No page tables were freed. If page tables were > > freed, a full > > + *=C2=A0=C2=A0=C2=A0 flush ensures intermediate translations in the T= LB > > get flushed. > > =C2=A0 */ > > =C2=A0 if (f->end !=3D TLB_FLUSH_ALL && > > =C2=A0 =C2=A0=C2=A0=C2=A0 f->new_tlb_gen =3D=3D local_tlb_gen + 1 && > > - =C2=A0=C2=A0=C2=A0 f->new_tlb_gen =3D=3D mm_tlb_gen) { > > + =C2=A0=C2=A0=C2=A0 f->new_tlb_gen =3D=3D mm_tlb_gen && > > + =C2=A0=C2=A0=C2=A0 !f->freed_tables) { > > =C2=A0 /* Partial flush */ > > =C2=A0 unsigned long addr =3D f->start; > > =C2=A0 >=20 --=20 All Rights Reversed.