Received: by 2002:ab2:5d18:0:b0:1ef:7a0f:c32d with SMTP id j24csp356054lqk; Sat, 9 Mar 2024 13:37:57 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVhiIlBwTWi41s/GYt+K2eAKcclBNqi2xZZDFXFK0UwqSydOthopKGzT3aLOlsXZQG6TuhNsf9QxQ8gUuGhqY0NFJYslGg8DnCmXt+z3A== X-Google-Smtp-Source: AGHT+IEfBvrWAl7q96yekF1me+YNcHKOioJ2jx0PaWFoflnKA6ed0w/aWONjI0FDRHKb3EUWSJ7C X-Received: by 2002:a17:903:22c5:b0:1dd:611d:3be3 with SMTP id y5-20020a17090322c500b001dd611d3be3mr3560376plg.17.1710020277106; Sat, 09 Mar 2024 13:37:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1710020277; cv=pass; d=google.com; s=arc-20160816; b=Vwz7m/l4Y+un3gFOzTi7bhBiQXlFWIJY26BWPISQYEEEkmk6PzMSYAoTF23/TKY18d XyxvejW/gKhTo09VwwH6K0CXLyNonjqkl/RswmjgjDnkgGLXocmpT2JCUbhRNf1GsEm8 yTDD7FZ8IlRqJO4tv8S1yQ7nLw+SZKyV9WGw8oPinKUbkn3vZFgG0XHs8TQho3RjUdIf 8FAdvF0zUT1mcl7KNdfvJxrjeIYkdrMHQ105H0DZf3CGO1Eu+MpNtxvqy7mdkpVkHE1r c6bUQ6L2ot4ulJZVuDegrcKfMjWWua2vaWOoFl8jWpNNS7FEGhLlzDCPyrmHQim7PbEv 8kmQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=slLuHbk3WtakpcBqnee9gqaMqDn9FcyIy1Pde24rTWg=; fh=3TJKh76yOaWWducKFi73C35RciwZH9KzcN2hlKsGAD4=; b=gScCOjIGp1FcSkg2o1qnGbwCvGMkYgZMzHVUR6OMeEOgkALt5F/Y3yDW/23HAi08/c FqdUI2GlwJSv9Fcb3bvrOtI+aBWfGGkbDAOn3qJc5yIaZeES94n0X1LTfMfk72+5JWAj hWlOVy6wtqfiH1hvfKaN6UFyRkcFVGGBL5y7cHn6VDUZ0XPXhZR10PWPEvRyzNxnTTcu adACWcfcYy3zoHhNoOs023MBcI7HNbmJcSrsU2Dps10hBp0ok1Xq5Tf8yUokRdqtd7qH cMNnjrMhb4qMEGKH8UXB58/MAjuZj6z7H/tlGEBvI0gFNOlVNExUe0ST+XyTkLRq0qyu 88IA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1lhF684D; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-98048-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98048-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id me11-20020a170902fc4b00b001dbe25ce67dsi111197plb.28.2024.03.09.13.37.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Mar 2024 13:37:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-98048-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1lhF684D; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-98048-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98048-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B35B6281A81 for ; Sat, 9 Mar 2024 21:37:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B2D8650A9D; Sat, 9 Mar 2024 21:37:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1lhF684D" Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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 3C611364AE for ; Sat, 9 Mar 2024 21:37:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710020269; cv=none; b=LX/VefKCAPkY6Z9tAqrwZjLJ3gA62SpvdaWXyCr1zrHZDKIMORAeuM85Nxiic4HmzXzDB8J4AbtH+bpcSYDcsU5CCVqaDdHDyxJbXKz/g+xoY9Y4bUryHCOyoMWFNGMk8WfdRyCrlQhE8xaL/Q7O8iTYurQbXxzapn8W4PemLAk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710020269; c=relaxed/simple; bh=slLuHbk3WtakpcBqnee9gqaMqDn9FcyIy1Pde24rTWg=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=hFruywjn8mr3MxI8+jTPo5mcNYAvMjcKqDFz9PfXft1XSE0Q8vwKHO+ouLs+ix0E1niLWhC1C/b3cI7NB3ePrh4iVZ4VO6ptSkvL3Vo3WflVgx3o8R+j9jr0ceCZGUDf/NA0kJJ9rcgIXb6ccUZgByPSqpWu7tlsgUmVbftbSRc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=1lhF684D; arc=none smtp.client-ip=209.85.167.42 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=google.com Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-51340e89df1so3444280e87.1 for ; Sat, 09 Mar 2024 13:37:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710020266; x=1710625066; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=slLuHbk3WtakpcBqnee9gqaMqDn9FcyIy1Pde24rTWg=; b=1lhF684DEO/nqsAoDxd98cQsdqZ1VHPJrgVS24YX6lZFIwvoKv4JWnxF0nj8lTYO2R BLSt2IhcNfGswKapPgK7nh/j/SEahZ+C+fnYLNhsnBrEY73nZ1ua2pyETNTdCWvTmK33 bdq/ImGEwrnQ9my7yAS3V03MmVDEh8V04Vb9wQusVB2KwNr2F4pbXVSn7H4beXBWU1qs JQdIYWf7qvwNtJYNdZuFULmcm4CLAJduBGmQepb+GdXKvw57A9RYLS4kaLtun5GbtjdB TKsQHsQlCVc1FE6jCvEW/MFoQkZbyuvNgjbggwUZJjWo0hs1+A3ERdLrru1Qjfhm4b3p ZoUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710020266; x=1710625066; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=slLuHbk3WtakpcBqnee9gqaMqDn9FcyIy1Pde24rTWg=; b=gddAJyjY9rpl0lpZMQMJiyZK4qrR+VG4qWwLhPrkqvK8n9dexd1xwWT/xWK8eWLHRg rCtflTU+NJsWgtj9E891ygOkBoVgurtP0xou+7GfucvkKP0NwDhAszfLgnr47pFQGJtT jdTGggZHQRFfUXO8onAzNb8gFai1Y+jovjGbH+VfQkfJBkEMiP8/I3BnvakAA2vE42Zy mgtwEShD9UBPIWcMpTzwCWfZSP6NYEoe5/bpTur1Ac4WMuRGrND1i3pQOAMEQksWjv2a ntz4kWk+8ayU5ZpbNn13nkaTAZgxMxfG8UbgTi2y0RfFzngPJUMdUXQvjAybaAyXavbs /s3g== X-Forwarded-Encrypted: i=1; AJvYcCWsE9AmEEnwoYT778WVM4LmrvEVdS6orTEdWQ7h/ckmwrY1GZA98JjlgisHZAkAE+bvkBRT0m2x+BniuD62q6AHSTJR3+NAVL5jZ0c4 X-Gm-Message-State: AOJu0Yw3XRrQAkHgETZTDN3TUytsSnl8VW+Q0HLAdrCiBcg86fXL7Rga 8PFzTzo+24islCqiVMbVRc1VDgBqI5J9Y86z2Ng6eM9/TMzWLEvhy8VFTjN417BijJxNt97yqnE USzb0EUZCqZFRMYlfn5G4bTXELsxg1ar6lJRE X-Received: by 2002:a05:6512:2823:b0:512:fe1f:da5b with SMTP id cf35-20020a056512282300b00512fe1fda5bmr2306933lfb.57.1710020266087; Sat, 09 Mar 2024 13:37:46 -0800 (PST) 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> <420fcb06-c3c3-4e8f-a82d-be2fb2ef444d@app.fastmail.com> <35b670e2-9ef5-4d3a-b6ea-f8016dfa088d@intel.com> In-Reply-To: From: Yosry Ahmed Date: Sat, 9 Mar 2024 13:37:06 -0800 Message-ID: Subject: Re: [RFC PATCH 2/3] x86/mm: make sure LAM is up-to-date during context switching To: "Kirill A. Shutemov" Cc: Dave Hansen , Andy Lutomirski , Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "Peter Zijlstra (Intel)" , "the arch/x86 maintainers" , linux-mm@kvack.org, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Mar 9, 2024 at 8:34=E2=80=AFAM Kirill A. Shutemov wrote: > > On Sat, Mar 09, 2024 at 02:19:19AM +0000, Yosry Ahmed wrote: > > I don't see how skipping set_tlbstate_lam_mode() for kthreads fixes thi= s > > problem. Do you mind elaborating? > > Define what problem is. > > Yes, in this scenario kthread gets more permissive LAM mode than it needs= . > But nothing breaks. The problem here is not how the kthread runs at all. It is the fact that if that kthread context switches into the user process that has enabled LAM, it may not update CR3 because the mm doesn't change. switch_mm_irqs_off() will only update CR3 in this case if there is a pending TLB flush. Otherwise, we just return, even if the LAM for this mm has changed. This can cause the process that has enabled LAM to run with LAM disabled and fault on tagged addresses, right? Did I miss something?