Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp144393lqc; Thu, 7 Mar 2024 12:51:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVzxm8NdckgAD50Uj7+uQ5JZgpYkYrOl+Q70tZWSsV84TNpHgtWAFukT7i/eqv7hv7mzyuLXpW56iKhhsTVDFltbkSzltld+BuA9TVJMw== X-Google-Smtp-Source: AGHT+IFoZJIsG3bPOidLqBzWJ6VabCjXxug5NdwJIaUZCB0nf//7/w/+ezVH81pyihe5yJ8mXKif X-Received: by 2002:a05:6a20:12ca:b0:1a1:4d0e:6e70 with SMTP id v10-20020a056a2012ca00b001a14d0e6e70mr9623335pzg.61.1709844708051; Thu, 07 Mar 2024 12:51:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709844708; cv=pass; d=google.com; s=arc-20160816; b=B6Uw2dUo8peWhcLshyi7xfWQ1mshJqPR7Lb/h3XN5KrX7ru6993H73PfKUoDEBNAkF LhqIaDySQ5Xe2ObetHg0Q2Oxm1n8lUMGcu7EixBCSAZQgYg7ZcQxUsLDtTVQZSYLllvw ZUDc+nNf6nDnvfzO3Scst1fJTSL/ezmPKSCWNSF/oZ8MpyPz3iv+FyYrE4nclj0OCGZz /hXWJVa4abU2kjq58qNUDWtwVr0dUxFF099Qns1KNA1ESEyfz0e+NbLt8OVfbM6XcBCj 810KrSm3u9J/hQ1SkKFxDYgU5q7f3PHyg/NISMZePGFQBy+NY/z3B1bWE1R8K6o/jlw1 myeg== 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=bl6KQ7zqxCRRy7mV9HLzLwrJU3k8ZyxTlFOkk6jrrGQ=; fh=FUn6ks4L8RGn9JiAvA2eBiEvjIgZXhP0+y8gW4orZrM=; b=Z+oF7jd1SsX5feFsQlBee2AShXYFCSFT/sDC9biTAB/Cy9pdtrpqcyr44JTPppNvCZ TpwSBfXqiJJbYyVdxaCzA7VbA9FI2D+rNo3VfI4/B/3hyvriFg9TZQVRBRrXwA/iJVmt Gtpc2rVonBUDcHv6wcAQqsHjb69HKQsr/G1DM7FfQCUf1KZ/OrKLLdXa3FvfMEZDKIUw XT5rWVwvbEPh6TK4fhH8xasNrvLwBtgcB8/yMY/2YZLajoijP9MpRAW8JDSPTpiv2zQl APGlsCUxvOWzW9xkrIumYe05DY3cAm3Sp5ffcgkNC8CoRZo2LqYLFDXOkoqwMcaCa/ew YTWQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=lGAsX7yy; 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-96198-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96198-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id q22-20020a056a00089600b006e653744116si3164532pfj.188.2024.03.07.12.51.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 12:51:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96198-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=lGAsX7yy; 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-96198-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96198-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 9D776B23A03 for ; Thu, 7 Mar 2024 20:32:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 341AF51C45; Thu, 7 Mar 2024 20:31:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="lGAsX7yy" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 DA7834E1C3 for ; Thu, 7 Mar 2024 20:31:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709843511; cv=none; b=A3PZrSRIM226Zz6y1eqxvmpsjGROhK2alck0nQhdOxOFPgc4toh9PhKG3G7VcbAiTGHuar1QWtvaaSPAnPJz/+oJeRmvi3tekwgxzZohDSzADckzNBRiJ7fmrAjpqtVjlgHIcjTh/jFPDAXR8QpAX/E9rBtsNfW51Nsp1fTuIIg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709843511; c=relaxed/simple; bh=B6jTRt15Ay+YE96kV68Fuqz0cpG6G9QiBhLFa45Ajbk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=oB0W1UwlkU7cFrOSKFn9ZhG7TbFr/BOJCm5v73n63F3HqiRit6H7Dd6xV0MvEF/q3iexEtTcxbm7NmcbJ2DEusRquD+RVs1U4TVUA3xyJkROZkFxiTNRQUkgv6eCBFMsQLN6nNHJwxIQPhiAt7rEgdHWQlKGBzo0gqsYv+358wM= 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=lGAsX7yy; arc=none smtp.client-ip=209.85.128.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-yw1-f201.google.com with SMTP id 00721157ae682-60802b0afd2so12653567b3.1 for ; Thu, 07 Mar 2024 12:31:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709843509; x=1710448309; 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=bl6KQ7zqxCRRy7mV9HLzLwrJU3k8ZyxTlFOkk6jrrGQ=; b=lGAsX7yyzp8GG46dHNbIoSl1UQJaMPStyehKmcIMhjeiFWZNqxXAu7QxTKXfXd0aRs D8VE+CKwxw4YlTPQDPsH8odw5m23/wqXZJHo7CsltotDZ8vgxoqcDRdjQWH2c6ijV+dk /G9MkKYeHCwgfOply9CR5GsMmNBJeC5A9UM8zCkPmbwdBBGZpaKyaoD8F0wQEj6OojZD FdRqFQI5Glz7yTGjKVWuUAzUyjBc3eqjvMQMha6SgCc3mNsDrH9hpsHqc+j2IvDRueE1 mW02UcKmZd2DStffYEGZ91wGx94mDpnWrflx5UP8kiVJcd3hxeVA4h4Pg+i2rpnMcDkv 7Ypg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709843509; x=1710448309; 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=bl6KQ7zqxCRRy7mV9HLzLwrJU3k8ZyxTlFOkk6jrrGQ=; b=U6d/zPdNPJpbgjy7gtT6hfs03tFPxAV+SufhmEHiXA6svZvEuz5Iq9cpCyZElxzWzs zJ6ysWjRbIxF8fM2rbqsPLEOgSAtPH2FxSKJfN1uHwqZhR+yWsrG3ZSPEJGFgzo54XpM 7peIDDyxNS4BhPG7jaVPX7MTj9uKeAzX+tiyWH8U37ppcwdX+qlDWrlSh9+nW5i6IOoD rKoixajV2uIDfcQUlRFftnPMuSZrfLt/vnX97Uu5haIMVWKh1pN+ggHZ3x7S1DkkqQ/y KWdDQPvttIQb2brT8dvcinoirW6VUwP9hMEohMt8tRgVbwCRUHaI7FoXWbxnlJIrrDrQ RVxw== X-Forwarded-Encrypted: i=1; AJvYcCUqazw+gETiPl2iYSV9+85aKUIp7FeOAPHFqRnH3+qhP7k301RJwHu+0MF9TAMly502rAWN7oIQxnltNMFKq0ebXamalsvqZ6pPYHRU X-Gm-Message-State: AOJu0YxziZ44HmKgZlT0Jzvkj0RvChszYtCyzBNSSdh0Hy1+DSWQ1UbX oXvYN/CBdatiMIvQrJCAKUjSaYLtJLE7xoX665JsdBqMi9kT58JV8aGcXRWImyCd9g8qDpmRWRP 1s+x3ZXUG/EIZeVcY+g== X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a0d:df0f:0:b0:607:8f65:5433 with SMTP id i15-20020a0ddf0f000000b006078f655433mr545462ywe.4.1709843508926; Thu, 07 Mar 2024 12:31:48 -0800 (PST) Date: Thu, 7 Mar 2024 20:31:46 +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-2-yosryahmed@google.com> Message-ID: Subject: Re: [RFC PATCH 1/3] x86/mm: fix LAM cr3 mask inconsistency during context switch From: Yosry Ahmed To: "Kirill A. Shutemov" Cc: Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , 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 07:22:36PM +0200, Kirill A. Shutemov wrote: > On Thu, Mar 07, 2024 at 01:39:14PM +0000, Yosry Ahmed wrote: > > In switch_mm_irqs_off(), we read the 'mm->context.lam_cr3_mask' into > > 'new_lam', which is later passed to load_new_mm_cr3(). However, there is > > a call to set_tlbstate_lam_mode() in between which will read > > 'mm->context.lam_cr3_mask' again and set 'cpu_tlbstate.lam' accordingly. > > If we race with another thread updating 'mm->context.lam_cr3_mask', the > > value in 'cpu_tlbstate.lam' could end up being different from CR3. > > What other thread? LAM can only be enabled when the process has single > thread. And cannot be disabled. See MM_CONTEXT_LOCK_LAM. Right, but a kthread may run with that single-threaded process's mm IIUC. I think this can happen via kthread_use_mm() or if we context switch directly from the user process to the kthread (context_switch() doesn't seem to update the mm in this case). > > > While we are at it, remove the misguiding comment that states that > > 'new_lam' may not match tlbstate_lam_cr3_mask() if a race occurs. > > The comment is indeed misguiding, but for different reason. It is leftover > from the earlier version of LAM patchset.