Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp190544lqc; Thu, 7 Mar 2024 14:30:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX+GMdTkuJolUsfJiPiUFPvS+FtKx16vR025NsiDBwPMvjWcBSJ7erVfqkBTOb63T8HWb5YfMcZHeyDaya/7vLzqELFZruDG+SUU8nJ0w== X-Google-Smtp-Source: AGHT+IHJ7ZgZglo4c5tMJk/7ws2u8Lu5kwMTHyd+nX/hOnXkzrjfs7fK2WmXBB79D+gABIvlg1CH X-Received: by 2002:ac5:ce9e:0:b0:4c0:254f:75d5 with SMTP id 30-20020ac5ce9e000000b004c0254f75d5mr9358657vke.10.1709850621073; Thu, 07 Mar 2024 14:30:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709850621; cv=pass; d=google.com; s=arc-20160816; b=irsvALOd1/iEVwePVw4ar+jYGpe2I5xmOLkAVXzABYQJHEvCpKLvVvNt9dr5I/fY2c 01dAE4HOeOCT3RSOmDYU3DaP4UWMQwatGoKvwiyAPu6rxdhA2CwY1qSD/HRiJWihgP4k UsiBo/ZWSYuiRcmmSW0to8Sdm91EdxpLh+aqt0g/X01/8BsIl5myt2XnwpzIu17VTibs o0Hj6DytmnLxsufFMORG3cZ9ihW7mDwJSPsgdZfmVLmm43ZoeUCsfvdA2ypOYss5St7b uKX5/uw6vsLPBb1ODEplRZovueG7oTqLPzvo7qcl+ePeAzz50M0cCvrQd7NiWlizRas/ cXoA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=p4U6/xi3Ize/Gq+5zcGCk+1frkvpk205kMxRiv4nKJY=; fh=Mg2gjqF12ERGNVXXYWT27PZ32CDr6nOdoBvzTg644gU=; b=VcIjtRXTXtBlb0X4UpqPq0YW3lj5KJpUlbcG2npRMffQzurfJmz5t46HaHHI0WDrzL mTpKrHwYKstn51SRY2zF1tvtWjEZwuiOWbVR/zDgJNLxAmsQr9yf8w+6fmdSJpWq6GSy Hg3B6LIiiD9wANaDfslmSwAx/odeQ2ca/qW3VYXBFmZguv4pX2J6g0lHgHwqeP9olcEF 9HL0qn6cb66BjsvBD1G9O2Ws7jhZtFwgJ1qSckCHzmvm4TlG/nuyzrv9O7ebyK3xUxg0 yJIcAGbO2C0GjqkRe7RtVa5ex/I+WwGg+PV8m8khWH+VjTaHsdMdOQGT9kkt6IDQDbIs m+wg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="qCAOyD/u"; arc=pass (i=1 spf=pass spfdomain=flex--yosryahmed.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-96329-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96329-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id w3-20020ac857c3000000b0042ef031146esi10587658qta.67.2024.03.07.14.30.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 14:30:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96329-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="qCAOyD/u"; arc=pass (i=1 spf=pass spfdomain=flex--yosryahmed.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-96329-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96329-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id CB2681C20C15 for ; Thu, 7 Mar 2024 22:30:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 61581140361; Thu, 7 Mar 2024 22:30:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qCAOyD/u" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35101131E3C for ; Thu, 7 Mar 2024 22:30:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709850616; cv=none; b=DPbduP3Pc1OAEa6kYhrYLC2MnmaSNl45FBeoro0FfidvCjVBZQ1V8HlLe3kCFsfk1pCnhsu8pPPBzfVa6P1owOrFCHpZcuDN87eR06y9ZJTNxgFh/5KgJ42zE+kVPnZcggkkXenaeRyTYy7Jwl9DfnGiWzR+oIIKkM56Ghi3Rdc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709850616; c=relaxed/simple; bh=pDhFnSH+2GnqjFRhyAcXHT7DAiUPUVzbSyDK+ovWPUo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=RTmc4s0ukSemY4GTnwVryDdvfuJBE//67DRF7xtCSzJxZC8Y9IQ0dm2/Gof4S16n4aqbIx1t47dwxYpb++uii//3+QkBVwbp3+k8lAtCne/DKpaQkeDPKtqFYSh6EHaOR6CJHNUoMqhsyrERDwD/ymUJcjFVhQh1cNLyqnjFrFQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yosryahmed.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=qCAOyD/u; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yosryahmed.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dcbee93a3e1so484697276.3 for ; Thu, 07 Mar 2024 14:30:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709850614; x=1710455414; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=p4U6/xi3Ize/Gq+5zcGCk+1frkvpk205kMxRiv4nKJY=; b=qCAOyD/u13OpTwhUT37m85wZ+NCuVuhBWpXN8kVM6aNc3pG6+rzMtoTb/7swaOYNkj azmfCrXWR6xTkZRNRBokQnRl40hUaz3T0q5vJHzVPwfkxjAMKLpUevVworluuSAe11YC H8jkAGD7WGV2pvYYsWBnfEcWQPWx104Z3D8yqnLnho2OwvsSSvslqv805BjwMaLvNNYr AhuHyUK9Gp4HKETaeg44fILEMoD34Tw+YFTCh7amrX1NWwY7aED8TIzm0JGsy71AkIVV YJHIGSVExcqCLo1hVrt+aiEnSFMH6O/yewwetkcXvS1nroxFcF7jNbG++xB1kq7RT22C jgmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709850614; x=1710455414; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=p4U6/xi3Ize/Gq+5zcGCk+1frkvpk205kMxRiv4nKJY=; b=LM21N8Hd+Ef00Bv6+AaMdeEAgWInVxvzjY5b425WF50ocnCimv0erbVE0udxAIKgoU R/QSjG7mv4vlEWlA6bYKNg5araZDoiW9CcoQC+q84bA5kljJ4U+yhyJ2WXpQY7AnD5Dy mSfgUdi5+aGyQZ2u+kR6hhGncWRaTOfVGeD/fgV/yikn8OiymCln+tLvT5eVZ4/cUAD2 HQVqDPs48IRHl4HiuGXcF3+4P5EtaMbIrkpRhP66L31QntOt8SVFY8n/b8NHLEvmXVTE y5mdNFe5mA0ppWfZ7mKQEBw+3OjP3gFm7CfsrU5NtSXZ13zqCL2frEW+DLfDQsCW0IVP wdfQ== X-Forwarded-Encrypted: i=1; AJvYcCXFj+hGUxTmZlI+4qNjFoXVaWIoFPjIm493Sl+LhavV4HGKPNU5pLbq+/6F4xiMeTRxRRNEbrlhIl1LYDkWbkt2jxLcbKpkp5/uWPx9 X-Gm-Message-State: AOJu0YyvBLgwxk+bzcNE0iVMDKnRfBQP7uWc7XBN/oovIVZtX0Ffa0aH M2Ov/b47CTUWx9mRUB0V2l1AUXTej5/pdGy7FDiVVPjZ8SuxBgGCbmJBxSRZ/0YJD8owafKyork qQ2sPlar9SUylw3YCnw== X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a25:c585:0:b0:dc2:2ace:860 with SMTP id v127-20020a25c585000000b00dc22ace0860mr701571ybe.2.1709850614208; Thu, 07 Mar 2024 14:30:14 -0800 (PST) Date: Thu, 7 Mar 2024 22:30:12 +0000 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240307133916.3782068-1-yosryahmed@google.com> <20240307133916.3782068-3-yosryahmed@google.com> <034466a4-0917-47c4-934b-9549c3076624@intel.com> Message-ID: Subject: Re: [RFC PATCH 2/3] x86/mm: make sure LAM is up-to-date during context switching From: Yosry Ahmed To: Dave Hansen Cc: "Kirill A. Shutemov" , Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Peter Zijlstra , Andy Lutomirski , x86@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="us-ascii" On Thu, Mar 07, 2024 at 01:48:28PM -0800, Dave Hansen wrote: > On 3/7/24 13:08, Yosry Ahmed wrote: > > CPU 1 CPU 2 > > /* user thread running */ > > context_switch() /* to kthread */ > > /* user thread enables LAM */ > > context_switch() > > context_switch() /* to user thread */ > > > > In this case, there are no races, but the second context switch on CPU 1 > > may not write CR3 (if TLB is up-to-date), in which case we will run the > > user thread with CR3 having the wrong LAM mask. This could cause bigger > > problems, right? > > Yes, but this is precisely the kind of thing that we should solve with > mm generations. Its sole purpose is to thwart optimization where the > mm_prev==mm_next and might not rewrite CR3. I think it's clearer to have an explicit check for oudated LAM in switch_mm_irqs_off(), as I mentioned in my other reply.