Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1825042lql; Wed, 13 Mar 2024 09:07:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUR4shKzHQCFm3iuT2hERlWfb5vLu6jCVfqkun4atYkd02pnLO5ZF7rFikrD0dP9vpIfQdLZBXLHdSQKtiqAVHPY+N6tVAilOQDUzyl3Q== X-Google-Smtp-Source: AGHT+IGxaNErij5gS1wxYRqTDYfi2dNHLuLWnBCPwGt83+KJiwot9SD7mcO7uYf9jKp0WGeEabeJ X-Received: by 2002:a05:6a20:c116:b0:1a3:e86:561c with SMTP id bh22-20020a056a20c11600b001a30e86561cmr4009505pzb.17.1710346045051; Wed, 13 Mar 2024 09:07:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710346045; cv=pass; d=google.com; s=arc-20160816; b=bGBFCqFKCvU91Zu5SmPw943aVP5aO3rnOIA+jS1hvpU6QKMPA9Wdtrh3Z+VqonpmgF kTO6+q7jUT+5cPU6aYgLdm03lXEgQTtQfTV6QN6Me+HL3Um8A3w6uGcwoi0SEwL65nCl wxBYviMwgbrJQAZkilpQrM8RH1qen1NWYzTT6bxXfECckk0Ytx+eiFBUOdTj+SwGHLlu doyV2nMRRaKhIK5xgzi9NvmC0ULq9KpNf3GdauaSfk/AMPs1d0SRGXrZRZMu69iQrMqy ZwSSAR6xkPc1u59APeFz65aTFbFAtkcDhxkgXkto6RnagNWLq1m0jw/ZiQBk/JFIxhGd 68bQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=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=0Z1VbgMrCZDZJdjoAYJr71bb6LFVjJIHEsteH/3CjyM=; fh=BSBbTJquq2grMKgwp1ACEd/EKIn62NX55fQ47ANICbI=; b=aAmfZsE8EVspON45Xx40BZCxmodcaQLhN891gD3c4J1bJPp1J83xCwrJLiFppY32TV 7fRcGvn79bnAtKVzJwpyQtK626LaQuhpJ1hWrQ2odUwqp5lvIKlsHiJEjiE1l1XqUriP iTKp6CCExUplexlO2U86SiLA2ZgF+Jpt9bymwnu9nCsWh9Ns+kdjAwgi0FtlrZjRS+rb TpYU2KefGsFt5Elfkq3/skTdy95xby0H16INJ/QgtJ39Q8rAr+F1A9FWF89cfYscdjiX R+gPRBLJ1o0OZktz9OuoR5QgadjE+zlnkbsJmXRFCGMAb2b35wWLEfy/QG9MwwYO/yEA o/1g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dYlXAwbn; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-101546-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101546-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id g2-20020aa79dc2000000b006e6729cca83si9231920pfq.172.2024.03.13.09.07.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 09:07:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101546-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dYlXAwbn; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-101546-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101546-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 74149B21A49 for ; Wed, 13 Mar 2024 13:39:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E6F9F4120B; Wed, 13 Mar 2024 13:38:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dYlXAwbn" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) (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 302A51DFFC for ; Wed, 13 Mar 2024 13:38:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710337134; cv=none; b=V/2XVGMJt6Ckwygz4RC1UYu4A1stdNW099IH0LcY7fq7M94gRj/1WyR/RTuNRJaDO4wgxdaGIag7TgSMq7GJanl2wJZIGXvqrBm+E7cSYQMffWZc3Y76u0fN9QRQ2wH8o+JCs8yYPETplOEfFsX0pNGwOWBtTAUwSSaYJogv+M8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710337134; c=relaxed/simple; bh=BOcy5v8jTDEf4Uwi1cewwmZO/FeGeMFiYXTFAhC4WZk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Z5u9qaQaV0vRncyoy44+i/C5RtzWUIEU0Y6u2neYSOd7WKMOWeQU94g1ooEIDAbWG9sUgwjwyg20/vPaJ6Sf0LtwysojkOtkMvIFS7SENv/8MjHRl3eFbCT0phqQ3wYmPp+cuhRx16BjsqhbfakT5uxR5UhWmqfPohn4kwOvQhE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=dYlXAwbn; arc=none smtp.client-ip=192.198.163.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1710337132; x=1741873132; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=BOcy5v8jTDEf4Uwi1cewwmZO/FeGeMFiYXTFAhC4WZk=; b=dYlXAwbnZ9NPMF757OQKEEqK2vB93PnHQxWm5ZvzNqou7syrWTq/HwE4 EQQPeBUCKAEjl+Grn04FXXm7SAVi0vsks7/uy6b4HSuVnDcZ+kergV14N OEdI7e17tXpd1iUcJcIVlmlJIXKY2c8088wF/0n1lFppmTNwX4H0u5rQe Vh1P9dUpoAhyZLCGy6xNeG25F7ccIw2NtjeI8/hgR4mJju/IUNgM1C00f Oy+dr0yPk50qqQlWgfdISz2cO+qYQepO1EZiON5W6FYPAsyUrXDsQEq0P NBQ6fEd5w7rtAAFaVyr/DaW8ukl0ibJenxkZgSiwV/JL0pPvBC/JS6Q2T A==; X-IronPort-AV: E=McAfee;i="6600,9927,11011"; a="5708196" X-IronPort-AV: E=Sophos;i="6.07,122,1708416000"; d="scan'208";a="5708196" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2024 06:38:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11011"; a="937054147" X-IronPort-AV: E=Sophos;i="6.07,122,1708416000"; d="scan'208";a="937054147" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 13 Mar 2024 06:38:48 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 18FE91057; Wed, 13 Mar 2024 15:38:46 +0200 (EET) Date: Wed, 13 Mar 2024 15:38:46 +0200 From: "Kirill A. Shutemov" To: Yosry Ahmed Cc: x86@kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Rick Edgecombe , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/3] x86/mm: Fix LAM inconsistency during context switch Message-ID: References: <20240312155641.4003683-1-yosryahmed@google.com> <20240312155641.4003683-2-yosryahmed@google.com> 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: <20240312155641.4003683-2-yosryahmed@google.com> On Tue, Mar 12, 2024 at 03:56:40PM +0000, Yosry Ahmed wrote: > LAM can only be enabled when a process is single-threaded. But _kernel_ > threads can temporarily use a single-threaded process's mm. That means > that a context-switching kernel thread can race and observe the mm's LAM > metadata (mm->context.lam_cr3_mask) change. > > The context switch code does two logical things with that metadata: > populate CR3 and populate 'cpu_tlbstate.lam'. If it hits this race, > 'cpu_tlbstate.lam' and CR3 can end up out of sync. > > This de-synchronization is currently harmless. But it is confusing and > might lead to warnings or real bugs. > > Update set_tlbstate_lam_mode() to take in the LAM mask and untag mask > instead of an mm_struct pointer, and while we are at it, rename it to > cpu_tlbstate_update_lam(). This should also make it clearer that we are > updating cpu_tlbstate. In switch_mm_irqs_off(), read the LAM mask once > and use it for both the cpu_tlbstate update and the CR3 update. > > Signed-off-by: Yosry Ahmed Reviewed-by: Kirill A. Shutemov -- Kiryl Shutsemau / Kirill A. Shutemov