Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2715770lqp; Mon, 25 Mar 2024 07:24:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV2SvVhiWJTEtU6iVgK4nJO5tUY4+FvBxEZWjAv90oGbs9I+1eLroaz95vTtIUYxFFcd7Npkvl4msrTPDmHSqORxrhAT8a6IUOpH0N0Cg== X-Google-Smtp-Source: AGHT+IHpP29OG++XLB2mUbS6ScS6u/Srot/UhhlwQLRNthMP5IrfDdUdZvR6EFWz9JgYZoFWTUmn X-Received: by 2002:a05:620a:318c:b0:78a:3b55:f6a3 with SMTP id bi12-20020a05620a318c00b0078a3b55f6a3mr13231204qkb.0.1711376641459; Mon, 25 Mar 2024 07:24:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711376641; cv=pass; d=google.com; s=arc-20160816; b=ZxV+yJOs0sLNunmHcS7SaJQVWMAiBu3mwuUrXaZvwqAJU7WhalhPr8/E9e7jCbP+ri 8Kt2ledzV8FmLdt+Z1x6XAlFefgCtH9M44E+tYBUIJYzRUfRhmmBvtdTYolWraX8zh42 mgAxZ2zyE4nns02MaNLRZkWHAknE3sdrww6vh96heB1fy0E7LSbQoMWbTKytaFHezfHv q9e8kDS16uezP2U/6F0zDd17CdSPP9TZeVoSkAa8clXLlSC6VFeAmkMsvfIF3JJEh43H HHT1vVggYkwqI9qoRVtE4NxminhRd5IHqrLTnL/6VqkyDkhGHN3vRBRo8R1JkK7hZrDk b1qg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:content-transfer-encoding:references:in-reply-to:date:cc :to:from:subject:message-id:dkim-signature; bh=pYSLKMEsmM13vj9wkVZ4b+vQkBicPZvMHF9ByXfyXVw=; fh=4txSB7SlDkCTIiHweog6ADSjvzX0flo8GI3OHNa0J/s=; b=eir7Ms0u3t7ZgPg9faZbp7wYrzfKTYgRBkJnTIzkORLIRjIJVsBUv0Ej8fZvCuJRoZ 12Gsr6L6PuqcS5v3JUUZzKgJ1zP+udyQk4Pw22EDl08bGBRQi4Fqawml9FEDqlEmoslf iOngczG8+uyCtozluENRW2GH+pOS1NIHqNgHriP8mCxDp7H817jnqOwbyRuAFyp+MPu8 2TfjFUSRpFqaez2bQHpDL24x8xtxCtRx1+t3nk2mzE+IQkSLyGANiR2pmVtov6veUipF UdqjytxjGuEk3ap49+ASZ5XLDXihGCq5JEa3n7/wMY8PNaF+i1y4c10CM5EwLzxWCB58 9LGw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b=aedx3Los; arc=pass (i=1 spf=pass spfdomain=xry111.site dkim=pass dkdomain=xry111.site dmarc=pass fromdomain=xry111.site); spf=pass (google.com: domain of linux-kernel+bounces-116821-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116821-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id oq8-20020a05620a610800b0078a452f518bsi5079696qkn.480.2024.03.25.07.24.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 07:24:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116821-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=@xry111.site header.s=default header.b=aedx3Los; arc=pass (i=1 spf=pass spfdomain=xry111.site dkim=pass dkdomain=xry111.site dmarc=pass fromdomain=xry111.site); spf=pass (google.com: domain of linux-kernel+bounces-116821-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116821-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site 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 399261C3B99D for ; Mon, 25 Mar 2024 14:22:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2882818E0E3; Mon, 25 Mar 2024 10:50:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xry111.site header.i=@xry111.site header.b="aedx3Los" Received: from xry111.site (xry111.site [89.208.246.23]) (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 9B6801292C1 for ; Mon, 25 Mar 2024 10:21:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=89.208.246.23 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711362078; cv=none; b=mkn1WmthCn493pijKfOWaHqLVhueE9Fgx1X8dn7Ni1EYCgjuoUkjtQi5InYm5J+eS4DvXC0/3V/gbWwaPHfmxUKYMXmGbJAmQaFh0Phv/6CLmvxw6XZVEVwTeUbMFC2+81EFbK2Qcy9hGI00rl9o+o5UGxo/IvPTw2qpAztXCy0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711362078; c=relaxed/simple; bh=8oHCVzt5yIb74wmNUTV10DqPItz7YPxCF7swqVQr49U=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=MLPkxFuuvzeguligD8qv7sEkPyjDpPXOgHee4ToU7F0ynP1ndfv1wlZ9EA5JqNUcyTdoWWkRtCvpUYT4/3rGGvClqOeDF2avAfOUw8JbKeX/iU7D1+u0X1dU6F3JPCAWFavsQ5BdNxkTq6ZJWbapCcVnC/zmdo9nJIz7BlNc5iI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=xry111.site; spf=pass smtp.mailfrom=xry111.site; dkim=pass (1024-bit key) header.d=xry111.site header.i=@xry111.site header.b=aedx3Los; arc=none smtp.client-ip=89.208.246.23 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xry111.site DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1711362074; bh=8oHCVzt5yIb74wmNUTV10DqPItz7YPxCF7swqVQr49U=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=aedx3LosWnycWhoUKUQxWcO43FLghyNrBU94sTqD/bVbqnIBu2geV+Lcc/rHZahmh isBB2Ab7IWqvIVUXqlfC0Mu+YFX7wk1NRG4Uj3jGHdJ5BIQfH1IaWTJBnl4IFxGnwE QODllf9B7qaP4bg6uvCSRA/i8tHf/zMqaQ1IZc/g= Received: from [IPv6:240e:358:11fe:a000:dc73:854d:832e:8] (unknown [IPv6:240e:358:11fe:a000:dc73:854d:832e:8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 7BCDF66EE2; Mon, 25 Mar 2024 06:21:09 -0400 (EDT) Message-ID: Subject: Re: [PATCH v2] x86/mm: Don't disable INVLPG if "incomplete Global INVLPG flushes" is fixed by microcode From: Xi Ruoyao To: Michael Kelley , Dave Hansen Cc: Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , "x86@kernel.org" , "linux-kernel@vger.kernel.org" , Dexuan Cui Date: Mon, 25 Mar 2024 18:21:04 +0800 In-Reply-To: References: <20240324190503.116160-1-xry111@xry111.site> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Mon, 2024-03-25 at 04:57 +0000, Michael Kelley wrote: > From: Xi Ruoyao Sent: Sunday, March 24, 2024 12:05 P= M > >=20 > > Per the "Processor Specification Update" documentations referred by the > > intel-microcode-20240312 release note, this microcode release has fixed > > the issue for all affected models. > >=20 > > So don't disable INVLPG if the microcode is new enough. > >=20 > > Cc: Dave Hansen > > Signed-off-by: Xi Ruoyao > > --- > > =C2=A0arch/x86/mm/init.c | 32 ++++++++++++++++++++------------ > > =C2=A01 file changed, 20 insertions(+), 12 deletions(-) > >=20 > > diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c > > index 679893ea5e68..c52be4e66e44 100644 > > --- a/arch/x86/mm/init.c > > +++ b/arch/x86/mm/init.c > > @@ -261,33 +261,41 @@ static void __init probe_page_size_mask(void) > > =C2=A0 } > > =C2=A0} > >=20 > > -#define INTEL_MATCH(_model) { .vendor=C2=A0 =3D X86_VENDOR_INTEL, \ > > - =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .family=C2=A0 =3D 6, \ > > - =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .model =3D _model, \ > > - =C2=A0=C2=A0=C2=A0 } > > +#define INTEL_MATCH(_model, _fixed_microcode) \ > > +=C2=A0=C2=A0=C2=A0 { .vendor =3D X86_VENDOR_INTEL, \ > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .family =3D 6, \ > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .model =3D _model, \ > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .driver_data =3D _fixed_microcode, \ > > +=C2=A0=C2=A0=C2=A0 } > > + > > =C2=A0/* > > =C2=A0 * INVLPG may not properly flush Global entries > > - * on these CPUs when PCIDs are enabled. > > + * on these CPUs when PCIDs are enabled and the > > + * microcode is not updated to fix the issue. > > =C2=A0 */ > > =C2=A0static const struct x86_cpu_id invlpg_miss_ids[] =3D { > > - INTEL_MATCH(INTEL_FAM6_ALDERLAKE=C2=A0=C2=A0 ), > > - INTEL_MATCH(INTEL_FAM6_ALDERLAKE_L ), > > - INTEL_MATCH(INTEL_FAM6_ATOM_GRACEMONT ), > > - INTEL_MATCH(INTEL_FAM6_RAPTORLAKE=C2=A0 ), > > - INTEL_MATCH(INTEL_FAM6_RAPTORLAKE_P), > > - INTEL_MATCH(INTEL_FAM6_RAPTORLAKE_S), > > + INTEL_MATCH(INTEL_FAM6_ALDERLAKE, 0x34), > > + INTEL_MATCH(INTEL_FAM6_ALDERLAKE_L, 0x432), > > + INTEL_MATCH(INTEL_FAM6_ATOM_GRACEMONT, 0x15), > > + INTEL_MATCH(INTEL_FAM6_RAPTORLAKE, 0x122), > > + INTEL_MATCH(INTEL_FAM6_RAPTORLAKE_P, 0x4121), > > + INTEL_MATCH(INTEL_FAM6_RAPTORLAKE_S, 0x34), > > =C2=A0 {} > > =C2=A0}; > >=20 > > =C2=A0static void setup_pcid(void) > > =C2=A0{ > > + const struct x86_cpu_id *invlpg_miss_match; > > + > > =C2=A0 if (!IS_ENABLED(CONFIG_X86_64)) > > =C2=A0 return; > >=20 > > =C2=A0 if (!boot_cpu_has(X86_FEATURE_PCID)) > > =C2=A0 return; > >=20 > > - if (x86_match_cpu(invlpg_miss_ids)) { > > + invlpg_miss_match =3D x86_match_cpu(invlpg_miss_ids); > > + if (invlpg_miss_match && > > + =C2=A0=C2=A0=C2=A0 invlpg_miss_match->driver_data > boot_cpu_data.mic= rocode) { > > =C2=A0 pr_info("Incomplete global flushes, disabling PCID"); > > =C2=A0 setup_clear_cpu_cap(X86_FEATURE_PCID); > > =C2=A0 return; >=20 > As noted in similar places where microcode versions are > checked, hypervisors often lie to guests about microcode versions. > For example, see comments in bad_spectre_microcode().=C2=A0 I > know Hyper-V guests always see the microcode version as > 0xFFFFFFFF (max u32 value).=C2=A0 So in a Hyper-V guest the above > code will always leave PCID enabled. >=20 > Maybe the above should have a check for running on a > hypervisor and always disable PCID without checking the > microcode version.=C2=A0 That's the safe approach, though there are > other similar cases like bad_spectre_microcode() that take > the unsafe approach when running as a guest.=C2=A0 I don't know > what's best here ..... Then generally maybe we should set boot_cpu_data.microcode to 0 if a hypervisor is detected? Or checking against hypervisors at every place where we check the microcode revision will be nasty. And I'd prefer they say 0 instead if 0xffffffffu if they must lie about the microcode revision. --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University