From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA2F2C433FE for ; Mon, 7 Nov 2022 17:14:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E5A36B0075; Mon, 7 Nov 2022 12:14:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 296566B0078; Mon, 7 Nov 2022 12:14:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1374B6B007B; Mon, 7 Nov 2022 12:14:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 02DE46B0075 for ; Mon, 7 Nov 2022 12:14:26 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id CC9BC4066A for ; Mon, 7 Nov 2022 17:14:25 +0000 (UTC) X-FDA: 80107294890.15.77DE1A7 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by imf16.hostedemail.com (Postfix) with ESMTP id 3E54B18000B for ; Mon, 7 Nov 2022 17:14:24 +0000 (UTC) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id A9A985C01CE; Mon, 7 Nov 2022 12:14:23 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 07 Nov 2022 12:14:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov.name; h=cc:cc:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1667841263; x=1667927663; bh=Dm yUXNZ+fiVM/sdn2N2qusiIy/T/bjR57f0aptB5wzY=; b=dofw4hdBQYT/oaVaV+ mFQR7GiWpyb7KjE4AoeN1GQr14+srrdklWpZ1lP1ZV7tCnbopYv02d+CfUj7Vkkg mlkdHpx6bMC+t2ffOs3mJYk9E4NhE35fPwgfGhDy7xtsgjw5OhGqVvViWOaytp6+ syae99VdGonliJNkfljWiWTPCnnbDwLpoLyA3CZE3nPpCyJimLC8QjyGUa79jt4B XP1QFQPqAu03moh/QGehDg2ROFIBPsoOAbX9D4sfVXDSgc9Kdy7elVZwU33cPLIQ axP5T5Xztn4gjHcalwXYbbrs1uiexVMARIfz0Zg8vWSbqCzATFqHRNfYJuaWnefn x5zQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1667841263; x=1667927663; bh=DmyUXNZ+fiVM/sdn2N2qusiIy/T/ bjR57f0aptB5wzY=; b=atcQUgLybH0wFkJud2+BfAwPf6dqd3EYt3LEjCpvF8Kg n0TD/H+l5C9RexVIBbUZdBwXiFL+HfuHrNl7VqLNYrjM6XAqoHdnOR8Vl7dwwCjc DBp0b0/ix9TJcsM/mdSGLm/YUmLKIG+qU/Va+qLlp2MwJ19i1lTdYNbtp16gghTC rG+mc5u55pAkvWrDBqbacnY8k2xv12uMYQxKpRHgI0uKvCTnV3DFMZoua8LhqVo9 tbTgFS2eurWQvcRa7SOG/gfOnPauW7M7/q4hl7OZp6T/W/BnaubWxm5DumnY3zMH 8N98tLTsF8MY++74BbjWhgzU12tDZ7668x3+bDTB8g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrvdekgdeljecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehttddttddttddvnecuhfhrohhmpedfmfhirhhi lhhlucetrdcuufhhuhhtvghmohhvfdcuoehkihhrihhllhesshhhuhhtvghmohhvrdhnrg hmvgeqnecuggftrfgrthhtvghrnhephfeigefhtdefhedtfedthefghedutddvueehtedt tdehjeeukeejgeeuiedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepkhhirhhilhhlsehshhhuthgvmhhovhdrnhgrmhgv X-ME-Proxy: Feedback-ID: ie3994620:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 7 Nov 2022 12:14:22 -0500 (EST) Received: by box.shutemov.name (Postfix, from userid 1000) id B757010964A; Mon, 7 Nov 2022 20:14:19 +0300 (+03) Date: Mon, 7 Nov 2022 20:14:19 +0300 From: "Kirill A. Shutemov" To: Andy Lutomirski Cc: "Kirill A. Shutemov" , Dave Hansen , Peter Zijlstra , x86@kernel.org, Kostya Serebryany , Andrey Ryabinin , Andrey Konovalov , Alexander Potapenko , Taras Madan , Dmitry Vyukov , "H . J . Lu" , Andi Kleen , Rick Edgecombe , Bharata B Rao , Jacob Pan , Ashok Raj , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCHv11 04/16] x86/mm: Handle LAM on context switch Message-ID: <20221107171419.k33qd4rz3tyfrovs@box.shutemov.name> References: <20221025001722.17466-1-kirill.shutemov@linux.intel.com> <20221025001722.17466-5-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=shutemov.name header.s=fm2 header.b=dofw4hdB; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=atcQUgLy; spf=pass (imf16.hostedemail.com: domain of kirill@shutemov.name designates 66.111.4.26 as permitted sender) smtp.mailfrom=kirill@shutemov.name; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667841264; a=rsa-sha256; cv=none; b=GWPtVh2wFF8kBa81sWDX9p/e9YO4hfbQ2STccODlTwLpUPugVTZ2irFjcgwHnsg9BHMtQu GQyZZgMGnPfIV9jO3zbFWypJOqbpA5Pslx/gntPNHer69ZfMLN3ny6r4xCVlapoKAabex1 MAmabhPl0u2Sz3Tzs35gUkdGgsqh6J0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667841264; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DmyUXNZ+fiVM/sdn2N2qusiIy/T/bjR57f0aptB5wzY=; b=MICkQX6pP6APzWOaB10h0DgaTvdvgc36K4iMJRa/Pl9C8wu23170e4aa3rn6Zr9t/P/xsL bpEpJM0iSTt2kclWqXpmDcncduclalAEiq+jjqE/TWgJTuPTdBsJ3I+nspuLW9XWp0zBQg ltJvlAzD5IIV4UbdJuAmxy3ykXuyyYs= X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3E54B18000B Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=shutemov.name header.s=fm2 header.b=dofw4hdB; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=atcQUgLy; spf=pass (imf16.hostedemail.com: domain of kirill@shutemov.name designates 66.111.4.26 as permitted sender) smtp.mailfrom=kirill@shutemov.name; dmarc=none X-Stat-Signature: qkka1433euj5ozc35j3fs1y1c6dr9rdf X-Rspam-User: X-HE-Tag: 1667841264-827995 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Nov 07, 2022 at 06:58:59AM -0800, Andy Lutomirski wrote: > > @@ -554,6 +561,7 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, > > if (real_prev == next) { > > VM_WARN_ON(this_cpu_read(cpu_tlbstate.ctxs[prev_asid].ctx_id) != > > next->context.ctx_id); > > + VM_WARN_ON(prev_lam != new_lam); > > What prevents this warning from firing if a remote cpu does > prctl_enable_tagged_addr() and this cpu hits this code path before getting > the LAM-enabling IPI? Conceptually this would be like if we asserted that > LDTR matched the mm_context's ldt setting in this code path. > > I think (haven't really verified) that you can fix this by removing the > warning and adding a comment explaining that CR3 can be out of sync due to a > race against changes to LAM settings. I don't think there's any way to > eliminate the race -- there is no lock you can take while changing lam that > prevents a remote CPU from switching mm or scheduling. Something like this? diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index d6c9c15d2ad2..c6cac1a1bc64 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -561,7 +561,15 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, if (real_prev == next) { VM_WARN_ON(this_cpu_read(cpu_tlbstate.ctxs[prev_asid].ctx_id) != next->context.ctx_id); - VM_WARN_ON(prev_lam != new_lam); + + /* + * 'prev_lam' does not necessary match 'new_lam' here. In case + * of race with LAM enabling, the updated 'lam_cr3_mask' can be + * been before LAM-enabling IPI kicks in. + * + * The race is harmless: it is okay to update CR3 with new LAM + * mode. The IPI will rewrite CR3 shortly. + */ /* * Even in lazy TLB mode, the CPU should stay set in the -- Kiryl Shutsemau / Kirill A. Shutemov