From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (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 1F004248166; Tue, 14 Apr 2026 18:05:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776189935; cv=none; b=mlEyw3vWEKXgwrz9PGgYVVl6+cBI96bQllImt16GB2jG31Z5QapS/hzvaQ8LA7PCQEHoFWiE+VlBOuGbfheEDTh2Q6zkSqQARBoqua3fb8kpj4fLV4V2L+LBbgUzcfzYiZyGTsVrxe/8gPa+8PhOSWOoGnUc+An0cunb5lmqN2g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776189935; c=relaxed/simple; bh=q2DrsFnuxK1fHmNxOuRECS2OWVI0HZxW9voN9duT66w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nC7RQ4BIU5k5FsSynqhC/jW1S4IlvJK9cKy0uXFp6Gjn9TY7Idy+8KIrq0gXw7wGv/ipj0Z6ZWbNopBKBwldZMMZTmsWoTh61SXifIaTyYXLEsY6nkFJp9r4E3i+XULbqZ9MNYXl+vNwJ4sOGHEKJK6koAuhvGZ/Vc4HOrTOzj0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=EAGTSUYk; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="EAGTSUYk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1776189935; x=1807725935; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=q2DrsFnuxK1fHmNxOuRECS2OWVI0HZxW9voN9duT66w=; b=EAGTSUYkUJ758mdy2h8UrDVyHnUMN9shwpNX6JEty7mEMS3i1XGqrNpA k6LDouC1f8LLJ1KoKZyAGt63oZs7X9kYiA//Wx6WSJk1gHn62+QGBwk3J qv8b+7qTI5zObK7B2foun4U9NOjfoKe12pS+IAt+FHi9MZ3VZ2QbAuzrM 0LhJRu7yODrcJiCngHf89UWEFJzbwiCWFkVymFVaHtt7NXGAvhu9Vcpq9 niT5A7Fzqki6TmCI1rcifEiVtleWObiXP5f7B4Uq0y42uCxrDsGDiJvhM 8go0720F84xmSgU2ezn5RXEHwVEXb5bp5ICMbN6LoeV5SQdPLvDuer2XV Q==; X-CSE-ConnectionGUID: deWxrDmaRoe1bH65EFtpLg== X-CSE-MsgGUID: 5a6cH/lmSgaZsTqq6ybFDA== X-IronPort-AV: E=McAfee;i="6800,10657,11759"; a="80751352" X-IronPort-AV: E=Sophos;i="6.23,179,1770624000"; d="scan'208";a="80751352" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Apr 2026 11:05:34 -0700 X-CSE-ConnectionGUID: E6+mn6gRRpCxIi3eA8k+Gg== X-CSE-MsgGUID: 8cAOYDHdTKawlZGUMUgCbQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,179,1770624000"; d="scan'208";a="235119082" Received: from guptapa-desk.jf.intel.com (HELO desk) ([10.165.239.46]) by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Apr 2026 11:05:33 -0700 Date: Tue, 14 Apr 2026 11:05:00 -0700 From: Pawan Gupta To: x86@kernel.org, Jon Kohler , Nikolay Borisov , "H. Peter Anvin" , Josh Poimboeuf , David Kaplan , Sean Christopherson , Borislav Petkov , Dave Hansen , Peter Zijlstra , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , KP Singh , Jiri Olsa , "David S. Miller" , David Laight , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , David Ahern , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , Stanislav Fomichev , Hao Luo , Paolo Bonzini , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Asit Mallick , Tao Zhang , bpf@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org Subject: Re: [PATCH v10 01/12] x86/bhi: x86/vmscape: Move LFENCE out of clear_bhb_loop() Message-ID: <20260414180442.gcio7h6zjwjcayrs@desk> References: <20260414-vmscape-bhb-v10-0-efa924abae5f@linux.intel.com> <20260414-vmscape-bhb-v10-1-efa924abae5f@linux.intel.com> Precedence: bulk X-Mailing-List: netdev@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: <20260414-vmscape-bhb-v10-1-efa924abae5f@linux.intel.com> On Tue, Apr 14, 2026 at 12:05:28AM -0700, Pawan Gupta wrote: > Currently, the BHB clearing sequence is followed by an LFENCE to prevent > transient execution of subsequent indirect branches prematurely. However, > the LFENCE barrier could be unnecessary in certain cases. For example, when > the kernel is using the BHI_DIS_S mitigation, and BHB clearing is only > needed for userspace. In such cases, the LFENCE is redundant because ring > transitions would provide the necessary serialization. > > Below is a quick recap of BHI mitigation options: > > On Alder Lake and newer > > BHI_DIS_S: Hardware control to mitigate BHI in ring0. This has low > performance overhead. > > Long loop: Alternatively, a longer version of the BHB clearing sequence > can be used to mitigate BHI. It can also be used to mitigate the BHI > variant of VMSCAPE. This is not yet implemented in Linux. > > On older CPUs > > Short loop: Clears BHB at kernel entry and VMexit. The "Long loop" is > effective on older CPUs as well, but should be avoided because of > unnecessary overhead. > > On Alder Lake and newer CPUs, eIBRS isolates the indirect targets between > guest and host. But when affected by the BHI variant of VMSCAPE, a guest's > branch history may still influence indirect branches in userspace. This > also means the big hammer IBPB could be replaced with a cheaper option that > clears the BHB at exit-to-userspace after a VMexit. > > In preparation for adding the support for the BHB sequence (without LFENCE) > on newer CPUs, move the LFENCE to the caller side after clear_bhb_loop() is > executed. Allow callers to decide whether they need the LFENCE or not. This > adds a few extra bytes to the call sites, but it obviates the need for > multiple variants of clear_bhb_loop(). > > Suggested-by: Dave Hansen > Tested-by: Jon Kohler > Reviewed-by: Nikolay Borisov > Signed-off-by: Pawan Gupta > --- Sorry this is missing Boris's Ack, I will fix. > Acked-by: Borislav Petkov (AMD)