Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1154403lql; Tue, 12 Mar 2024 08:43:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVq/I7u/ZPBi6TlKEwL5pANYixmDCfWOnC8PoAH3T7eFLD0UqqvvlylrF4SUQKFt1oMk/8Y35YH4QmRkri2h6N7KsOAP+KuPVG4ShwrAQ== X-Google-Smtp-Source: AGHT+IGS8rBUL6Px9x04iedYuNMts8+jsMxUv7osa3k2OnphBeDHJyqrSYjRhicLXWxOl8FYhKXJ X-Received: by 2002:a05:6a21:3942:b0:1a1:4aa9:96df with SMTP id ac2-20020a056a21394200b001a14aa996dfmr8814001pzc.30.1710258231459; Tue, 12 Mar 2024 08:43:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710258231; cv=pass; d=google.com; s=arc-20160816; b=EU2NVMMn/meozkrv3CVzBwCoAAqiIC2S5gMpd1aJjwKDKZqmUwatHViTqn9j8n/s7H mgQEjUpsoNWFtffumNUwaIqKmIAIG+AQ0NYHhvYioow3/OjKJPUV+Iq3iYCCtkWvlJLm GH+Uf/5c99al0+WcW681Srk7LGfpv9DOJ23Vqjn071hkQCEU9usK6q5T3GYRGI8TCjqp 1PB/AJWXtZ/8j4P7da2/7ctOQvC6/8EkbUggrjmq8147hwqTHMVzhY+7hFG3ISjuRHSK P4NuK4b7sJUE5K2ZtaacgobnLW4Sh18hdimCF3blPu1fYKqDSPxFhVe2Ibx918GxY2hq gdVw== 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=KzR+McFxR/OTQhr4rH9hfsDERCQOrw3TFBf8AroZgQI=; fh=CO2rcqFF1pJjYcPHdHnn4xogi61xohCgjKKgtZzSxHw=; b=Ted39e+VZDgcSL8R1zWRIlfWpucpm9jyAfBTrzMMMQe0RqUnO+0S7J8jGzYvTMVywS mV6Rtd6n7gEOWGyH+2Y1a1wEIby/UM3s34garhW83rFkdQDxago5gWj2woXb01d/m7Co r3sHeUUb/+FG9wbq7u3caw5p5HnVQUPxqleC28Wx/odQ8o7ZaHgLjd19jJShIFrqZpLT +hWKLeH+PCI2MCbA4nx/RWM7iPLDN9xg+2/gOiK6E/xfXv2XmRl3AmCVVWIP6L7Paq0Z Z2UwVu9Mzjmn7kaKrLtEv/GKxM3Kx+AOG/DpwfBS6nMpr41xh6UbIkyiRr1GF1ipcE0d 7ToQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=h7H0+sAP; 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-100446-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100446-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. [139.178.88.99]) by mx.google.com with ESMTPS id p126-20020a625b84000000b006e6b2879ef3si381036pfb.236.2024.03.12.08.43.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 08:43:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-100446-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=h7H0+sAP; 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-100446-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100446-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 481742885B5 for ; Tue, 12 Mar 2024 15:35:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C24737C09F; Tue, 12 Mar 2024 15:35:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="h7H0+sAP" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 904C27BB08 for ; Tue, 12 Mar 2024 15:34:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710257700; cv=none; b=IrvXlFz94B4Eyp1fyzj6UZHlDrRVM7Q3z1798kK54K3undLoEyIGd4bM2DLxJNggT3wNk/Pk2BuP7ph2wkgONzwNhBO6mG3w4IrS074WFKyVai8oydpHNsjIZ9VMzgvFQRYvwhHbArEtiSvXWIn5HN2+z4p8ErIIxcqlhV4ojjo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710257700; c=relaxed/simple; bh=pGUcJmWXTyukCSFUwFhKmbOeTOCsHmo7jhwLVc+Cn1Q=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=uPbmzUhwkV6ZwRoIOIwFbsVduy2RWW/t1ZMsePsn367thKf2ThV1jt4nfAJ3DfQ4CgP2iDKounu68w9gev6EBbltNBR5tjzdcovAMsCyPXUPALtm6Xqo0C0wtv+HrHx0/0x6Jd35mLBZWb0nuPKxG8YKUFHpO3ZPB963uCaY8dw= 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=h7H0+sAP; arc=none smtp.client-ip=209.85.128.202 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-f202.google.com with SMTP id 00721157ae682-60a20c33f07so53493567b3.3 for ; Tue, 12 Mar 2024 08:34:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710257697; x=1710862497; 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=KzR+McFxR/OTQhr4rH9hfsDERCQOrw3TFBf8AroZgQI=; b=h7H0+sAPdWkwtaf1rBloG8YY2RYJePQDHUw+/Ln416MjI0ZhiykkdVpzpWTY8ujAzc 9LA8u9JJzxo/oRG3BoR8XHkKH7Iw/9SXJ2MMkBDqumw8hPd+y70aMbN5nuTsrTYgA3jR +X2iBksEUh8XwDcOFWzX08BsFDDORQ6w9YB7vjioJ1HRJ9GkopDNwmJBnnfQMqKudcS8 n29CXBxhvv9uK/x2XkIQHXMaGkLVv/b721j21xavCM1pm0ISx81A0lDGDhRAIAXx8N1y ybY8NsAkv4iOrDmmwCI4RhsG00NqqVndrwP/pHEPMNrWdnk8UdkPn4O4RcFWONzCapGA 3FfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710257697; x=1710862497; 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=KzR+McFxR/OTQhr4rH9hfsDERCQOrw3TFBf8AroZgQI=; b=v+vyrnoFETvphXA9h3tLrW3uhWYajoOYo80eFkvH68/VOXcFklQEBZTlimLS5dGy/5 2Var0E2SQDzPFC5yxqeNlFWf1nNCT+qy1gLeGQ41GG53o09dqaz6gTMSiUzcqiZho8DJ Bi0DDlhpnzlkE3uSlIgnXCpHpGVl7AcK3pE9FRmnv31PdAsTPZumqVLr5bAi5H3OyPhp Ps4AvJCTU43xFZwFJ0UW8UUSpBbfztb8zcLdiRBj01XaQ8kGxMRmmBRVCiw4CCgfSz5A dh2qUK19vRkdFXCOoBrCEOrrqspBgufw9IsTa1A4JhyOOPPUd3S33lQV9ebQjP5AGkao 9M5w== X-Forwarded-Encrypted: i=1; AJvYcCU9U8tibnqU5PSoTbSa2DuUe0UAYW6wN4rfdPJhz5Ee2Asx77qdZibhtRTI95C+vnT5RY0S/0k52Urm1ub+bfBG1NEXLYwuMuFyXMLQ X-Gm-Message-State: AOJu0YxLNVApp/k9P2RHfDj+nNHOZ1tbKPLMHrK7YUKG9UQ3Y3MWxk78 Y0HWACbIB7hbfNYkr2dGEPSd3y6ZDGP4Y/l9E1+1RJr/CHCV9zzKpnpzwRwEqASIv6T2s2viwbj O22en56g6qmTjElpizw== X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:98a:b0:dc9:5ef8:2b2d with SMTP id bv10-20020a056902098a00b00dc95ef82b2dmr2524948ybb.4.1710257697643; Tue, 12 Mar 2024 08:34:57 -0700 (PDT) Date: Tue, 12 Mar 2024 15:34:55 +0000 In-Reply-To: <3a56vovcqy7ju5og76nqlekfruq42i56wmp4oek3jgkffvzjby@q5guufebkpzr> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240312035951.3535980-1-yosryahmed@google.com> <20240312035951.3535980-2-yosryahmed@google.com> <3a56vovcqy7ju5og76nqlekfruq42i56wmp4oek3jgkffvzjby@q5guufebkpzr> Message-ID: Subject: Re: [PATCH 2/3] x86/mm: Fix LAM inconsistency during context switch From: Yosry Ahmed To: "Kirill A. Shutemov" 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 Content-Type: text/plain; charset="us-ascii" On Tue, Mar 12, 2024 at 02:35:46PM +0200, Kirill A. Shutemov wrote: > On Tue, Mar 12, 2024 at 03:59:50AM +0000, Yosry Ahmed wrote: > > diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c > > index 76e91fc68c5f3..748d2b3bdb985 100644 > > --- a/arch/x86/kernel/process_64.c > > +++ b/arch/x86/kernel/process_64.c > > @@ -753,10 +753,12 @@ static long prctl_map_vdso(const struct vdso_image *image, unsigned long addr) > > static void enable_lam_func(void *__mm) > > { > > struct mm_struct *mm = __mm; > > + unsigned long lam = mm_lam_cr3_mask(mm); > > + u64 untag_mask = mm_untag_mask(mm); > > > > Maybe push these mm dereferences inside the if block below? > I am not sure if compiler can re-order operations past this_cpu_read(). I am not sure either, so I will push them inside. Better safe than sorry. Will send a v2 shortly, thanks for the reviews! > > > if (this_cpu_read(cpu_tlbstate.loaded_mm) == mm) { > > - write_cr3(__read_cr3() | mm->context.lam_cr3_mask); > > - set_tlbstate_lam_mode(mm); > > + write_cr3(__read_cr3() | lam); > > + cpu_tlbstate_update_lam(lam, untag_mask); > > } > > } > > > > -- > Kiryl Shutsemau / Kirill A. Shutemov