Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1433124lqh; Mon, 6 May 2024 07:38:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUYhUsS5E7p2Bt5/lZZ2AjHDJzUx9lEPvfRNmA6+UQI8OCSqWEFMdzXfxW2pEN/MMefl3VRzcsTDwOZ6OKpQBU2/DNFoHWIMgbWvs3QBQ== X-Google-Smtp-Source: AGHT+IFixRxy6xLqPpZwL3TeRq3FTjnam8e75QJ8ySLxrRtXBBNx1PFw1r28rO9awHXkmh27aeUl X-Received: by 2002:a05:6830:10c6:b0:6f0:6ee2:9a64 with SMTP id z6-20020a05683010c600b006f06ee29a64mr1765431oto.27.1715006333534; Mon, 06 May 2024 07:38:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715006333; cv=pass; d=google.com; s=arc-20160816; b=fTgXTMNFmsr6UTbOeVaZHBRFyf09qCb+YlXBHtCDW9QoRlsS2wGyxXXXJt4xUFnweP f/LEmU5MKeZWqjqayzeASNCn14QZDPUL3ymJEQ69YGv0g5DhPo15ztxz1tqjP4ED3vtK dIa1zKS/eXdJXDS4U6Bwh3UZsKIZrs/8NrXhL6Bk4lJqr7uAJxi22PSd6Jsfs3dt0FcP o3ZYVWJ5WtrlcsqQX5nAkwJRlOvhWWDRRyT4tyumhG64/jhTlImjWleNFaGsAC2h0Sbn B1wiG519z5Fec1TJklfgQDvIXRaZ32clbkRipMgzh97EWf92vzZ0Z+OO5n6TzJ6wpKOq zdxg== 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=102JG5apXBGrIa57cE4M29Xyb7pBgwDBKRD4HbgTxuc=; fh=qaDizmgiiqSPETKKQq3CeWU4MCC9SiuEIaI1r/pJPOQ=; b=ajzcisU34osxGLD0PLBSgetu3YcjkVFIPlkZz48pKk6SV5xgJQthSgCI0csMjDT+Q5 ElWj5a1XFafnyzgDvXjcLsGkkrl+7gwc90ZXDWPJ4AHtx5sr/6Xt6ZpHYmLGX+sjB3Yp tjFl9rGHhTDYnWJmK1uQudo5LZhSXHMSqiNEB6wTsqgNWuP8FOJwuRfsH/4KGQfo2vA/ pItrjiVR2GVe+LRocAs8mN4W2KxMpjYogDnbRm36XKjQpz5bNNqR0Fohwj5CQTPvExKz nmOcwpurHMLdpQF+/s7VPtTQjMwEA8P9iyAsN2nlX6K0tvZSmIxaoaKAW1XVa3sxMPJ0 fT7Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=rSRwuZut; 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-170000-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170000-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. [147.75.199.223]) by mx.google.com with ESMTPS id qr10-20020a05620a390a00b0078edf8b7ec7si10191022qkn.747.2024.05.06.07.38.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 07:38:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170000-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=@google.com header.s=20230601 header.b=rSRwuZut; 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-170000-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170000-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 360C71C218EF for ; Mon, 6 May 2024 14:38:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 82EFA153569; Mon, 6 May 2024 14:38:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rSRwuZut" Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (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 1302D152DF1 for ; Mon, 6 May 2024 14:38:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715006319; cv=none; b=MYlrK/XiEWCVpT4OeLoMWRIygytZ9ckv2mYsqYcf5Ysqm4hy7skQKPN+FKogeN3ezv814+HB+/0vALHk+TubQtEHSxsLfBY6Z6f4fq1B8xe22fTeqRNUNC7SscqiWjJmo+4txWmj3MA9FIIiHIaZ/FQlH5NL9Hh4ycjGMyfsSi0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715006319; c=relaxed/simple; bh=xL+slvlMHKNXO7juHQ1bTxdfrJhU58SOc3JoQytqDE8=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=qiyVz0uDAoqpoHnfaNSKMf3C4/BVRHnVVR3HfGekSMf+o6map44m43rYdKAeIT8PeBunDV2/HDQgB4A4Qn01FYn/MFTK1rnpTDxF+nt7avmfGy4r7SJIcQlTMw8lnQpg6Bnrr5hS1ldv98eY1pNrr4+PXwkb9z4c1blyjV7lsCs= 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=rSRwuZut; arc=none smtp.client-ip=209.85.218.47 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-ej1-f47.google.com with SMTP id a640c23a62f3a-a59a0e4b773so461848766b.2 for ; Mon, 06 May 2024 07:38:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715006316; x=1715611116; 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=102JG5apXBGrIa57cE4M29Xyb7pBgwDBKRD4HbgTxuc=; b=rSRwuZutZCX7eg4MS59Kx0nsKunFdsvDbBXgMEXJu/6D4BgdLLXKhw3FLjPXYFbquM 6rHTlxM4IWoXWXhV2Uv0bILHiwz4XjjNZVFMq0k+SJmYqNNheOpOwR2Rp1lRiy2eUEd0 4u0FHEgiy4AtRTMTwYds0tUslLUeky7EwFVMdeI4SmPKcUn9hvszSLmUtF8SYCGFPZUl 12KMFyzQHV07itlpvdalGpIypc0Flcl+EwdGdWpDnyCdhlH3bk4/g2QtWhBbxeu6oqv/ RQsqqDywOlzoRV7b6v645Zv0ydgLAXJRByhuE9Zde+V2IeLJvwQGoMoieEOKNgf0ZYR5 oU1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715006316; x=1715611116; 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=102JG5apXBGrIa57cE4M29Xyb7pBgwDBKRD4HbgTxuc=; b=P6WUERNAkkJ5bsossVxf8BAMSDregeb7IcbpBtW8fgZWMRddbL668l5tYkg/mYY2Bs ge5lI6sscgcO+2MtLLiitUOktAuXr3MqRtku+cI1qnHAqEiiple8IrXgs2Ws9GkFUvGm syIS4e/iRn7DfEIdKGxKKb+Kcb9hW3lX0LtktTDYSDhxBX1T4VUwNBQpE4nZobxqMmfk FAETGbh7TZDD1/Lo79/vrhBi3H3f/VxhlwTQnNKeBiL8vGfWtUi2aSyBbD9WrJrrqjPa S0Rd08d1J+z5u+8cbaq9akojpuFXKgOy85nXiMbd401GHMarQmFlyk0gi3EukhoSDUEd q34A== X-Forwarded-Encrypted: i=1; AJvYcCWWPQ/6mM50A+s42QHwQGC3rxPJ03crGbVM6q8fzTMImnQiXE/HgmTJNpCG3V6aQtAZnPjjR+kH78t16ewbrMHUQ9JNeLYJPfwMOHJ2 X-Gm-Message-State: AOJu0Yw0z6UMmz81nKx6731xt7zPrvDu0mI4Vc4KsUNX497HE2FG7S1I nhy/3NMIpk8b59eHtBc0HparLxfu6p3h5ZtXm2saZFE9LfU3ADbmKCyXHMXgeNhd2yo+cZAbrrp ZG5TkAlWz0Lu9eTrWkcpEKT4Z441Me/uUpvuN X-Received: by 2002:a17:907:100a:b0:a59:a727:1e8b with SMTP id ox10-20020a170907100a00b00a59a7271e8bmr3866049ejb.1.1715006316077; Mon, 06 May 2024 07:38:36 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240418012835.3360429-1-yosryahmed@google.com> In-Reply-To: <20240418012835.3360429-1-yosryahmed@google.com> From: Yosry Ahmed Date: Mon, 6 May 2024 07:37:57 -0700 Message-ID: Subject: Re: [PATCH tip:x86/mm v3 1/3] x86/mm: Use IPIs to synchronize LAM enablement To: x86@kernel.org, Thomas Gleixner , Ingo Molnar Cc: Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , "Kirill A. Shutemov" , Rick Edgecombe , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Apr 17, 2024 at 6:28=E2=80=AFPM 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. > > If LAM is enabled by a userspace process while a kthread is using its > mm, the kthread will not observe LAM enablement (i.e. LAM will be > disabled in CR3). This could be fine for the kthread itself, as LAM only > affects userspace addresses. However, if the kthread context switches to > a thread in the same userspace process, CR3 may or may not be updated > because the mm_struct doesn't change (based on pending TLB flushes). If > CR3 is not updated, the userspace thread will run incorrectly with LAM > disabled, which may cause page faults when using tagged addresses. > Example scenario: > > CPU 1 CPU 2 > /* kthread */ > kthread_use_mm() > /* user thread */ > prctl_enable_tagged_addr() > /* LAM enabled on CPU 2 */ > /* LAM disabled on CPU 1 */ > context_switch() /* to CPU 1 */ > /* Switching to user thread */ > switch_mm_irqs_off() > /* CR3 not updated */ > /* LAM is still disabled on CPU 1 */ > > Synchronize LAM enablement by sending an IPI from > prctl_enable_tagged_addr() to all CPUs running with the mm_struct to > enable LAM. This makes sure LAM is enabled on CPU 1 in the above > scenario before prctl_enable_tagged_addr() returns and userspace starts > using tagged addresses, and before it's possible to run the userspace > process on CPU 1. > > In switch_mm_irqs_off(), move reading the LAM mask until after > mm_cpumask() is updated. This ensures that if an outdated LAM mask is > written to CR3, an IPI is received to update it right after IRQs are > re-enabled. > > Fixes: 82721d8b25d7 ("x86/mm: Handle LAM on context switch") > Suggested-by: Andy Lutomirski > Signed-off-by: Yosry Ahmed > Reviewed-by: Kirill A. Shutemov The merge window is approaching, is this patchset ready to be picked up? Is any further action needed?