Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1224636lql; Tue, 12 Mar 2024 10:36:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXvXEwyHttQcYug3yf6/ZtkxTKpEr9PejsTeFqLHpHE2LSQg812UCtv3ZcS5mlDRA9+btj3r8vhPa1oTpl8ag8f41XNPIc6M4XpSNtQfw== X-Google-Smtp-Source: AGHT+IErXCLJFQcAEFxDqCbZ7SLLsRkI2C0TZuf5UVYXOo9quigtHoGPFAWnRqVvZXx029VwDEzQ X-Received: by 2002:a17:903:24e:b0:1dc:df24:e321 with SMTP id j14-20020a170903024e00b001dcdf24e321mr12071749plh.6.1710264979944; Tue, 12 Mar 2024 10:36:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710264979; cv=pass; d=google.com; s=arc-20160816; b=Cf0TvX4bABiXge1cMxWkhR999M0R0jbVToVs04aU2+RItan1IaQxCgcE6stEAS2N9U rSBXVnxHf/rvKOuoSKTi400k/i1XmM53nx3XnCoU4CIHYcjc8PpnJDG0e3kuVM5Np2VT LNSsgz4yE1shxs4IRGO9mLRoafr9kOuERPb87/Cyo6RMmqiwMurBWDlPRTK9wieVcETU mAYTOB3c6lQc+9WDq42lflbGuy87oRlxLQH9C36AAV0IFVBfONr0jFugWOCRBT9jRioD UDaKfRpQJrYPDzjoHrCdKucdMM9RYU5ZrL2OkyPw8+Bo7neAQJP0vrGzLVcq11aDnilt fhaQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=CRQk3qzq6hSXni4Rtmha+bf4h4hFWmf9Iqg3gcehnJ8=; fh=BSBbTJquq2grMKgwp1ACEd/EKIn62NX55fQ47ANICbI=; b=Q2uMG/08TMEp4vD1dRN1BF7SZUcuk2cUFdEAnW4jifqZY8wu6Equ+JO/tqtYqoYVsE kmQ2crioQA3/1yaAqqyQZnbEEzljlDMHUqIJ8d/Y6Q1LBlfnWTP+wi/JV8evWQbNDFcZ qpa44OHRN97E+RmhmApnH2Hf8z/VKjD6066WfM/1iw3puAmLS5AobcirLpMNDsc1V8mU PouJ2oIbCjrlhgUV8lGITb6UcDimIUT+V3dLQ3FzCoM2KHXc6NOEdzdRwhwOcLbHJSzc oEhBCbCYZqYe1wbrko5LFkYyIAyuilEVucVdgJXr7ckt+XzBMXRrcDXPbdzekDDgrFf6 IZfQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ub5jhZKg; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-100263-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100263-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id t7-20020a170902bc4700b001db70a99e90si7206192plz.430.2024.03.12.10.36.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 10:36:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-100263-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ub5jhZKg; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-100263-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100263-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 21E23B23077 for ; Tue, 12 Mar 2024 12:36:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 288A656457; Tue, 12 Mar 2024 12:35:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Ub5jhZKg" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1373811 for ; Tue, 12 Mar 2024 12:35:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710246953; cv=none; b=Ef41JX2x+TqyHF8AmRKLGFwO+kGOmi9lSYnLHXAESPCAt+Eu+nI9uSYsBN3x+jluW87eE0A42AiBNhJzGq2TifvfJBRIU/bnwi77ENLWb13uoNelOW46fS+sGy4dbidAVIG3DYIneW89RDSRCfx0aeqIc9LToYDvORnFRzGhgDI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710246953; c=relaxed/simple; bh=qYQ0JG/iS1IbYFpGyQjCg6wBVOUOXL3yCkQafpIV1Eg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NYFoc5C99p5UF5rRGOnj1m777x0vc6O/ld9vNC95PdZ1QUIr3AISdUYTukjDgoBxxggk72EzRL8CKB33bP62oSq/mBqk6mFac87cDh3TV+EK/LP/9ArNBMuu/Vwm5pHvk8Vobq2kTtpdgIdqrxhETKVeCJtRvwGjplTaezZp5Os= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Ub5jhZKg; arc=none smtp.client-ip=198.175.65.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1710246952; x=1741782952; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=qYQ0JG/iS1IbYFpGyQjCg6wBVOUOXL3yCkQafpIV1Eg=; b=Ub5jhZKgntWjVim1zM4rlmVOMeAsrnB7q63Tkl/r+p6S2vhAa4/AyZPW Af8rZPSfUTh4iUw3w3ZPW47NeGChYUh956A76v+zGo0K8um6cglmcJpoC U92CimqcTgubEzqOQzNKemQRUIXD69msBWpkLUfJVpvIbElkX1QrRJhry MNeeIrp01tVUTaLlEcwQrNKnD4aeOYDquR+L2R7S18CLCxIjkqlRhyy0F eezLWj+MSs2VBNvqxShRtEtxwoKMgHSPs1sIa+Df8N77eLATSiASBhgRj 1dTyoEtIuxyDe6aUOjdgfuNmMt1K0Ld5ibbNc36t00wpZZNA6P3FcimKd g==; X-IronPort-AV: E=McAfee;i="6600,9927,11010"; a="4823961" X-IronPort-AV: E=Sophos;i="6.07,119,1708416000"; d="scan'208";a="4823961" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Mar 2024 05:35:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11010"; a="937051832" X-IronPort-AV: E=Sophos;i="6.07,119,1708416000"; d="scan'208";a="937051832" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 12 Mar 2024 05:35:47 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id AD4CA27D; Tue, 12 Mar 2024 14:35:46 +0200 (EET) Date: Tue, 12 Mar 2024 14:35:46 +0200 From: "Kirill A. Shutemov" To: Yosry Ahmed 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 Subject: Re: [PATCH 2/3] x86/mm: Fix LAM inconsistency during context switch Message-ID: <3a56vovcqy7ju5og76nqlekfruq42i56wmp4oek3jgkffvzjby@q5guufebkpzr> References: <20240312035951.3535980-1-yosryahmed@google.com> <20240312035951.3535980-2-yosryahmed@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240312035951.3535980-2-yosryahmed@google.com> 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(). > 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