Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2811724rwb; Mon, 15 Aug 2022 11:50:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR64cOxWPil4V/9qJc7r0Gg/CmUNNz5fDbonvAGtkZISBOxNxTl7kV4tJd0LYBXF7bt+YUgR X-Received: by 2002:a17:907:1dd2:b0:730:b687:adf1 with SMTP id og18-20020a1709071dd200b00730b687adf1mr11614221ejc.183.1660589399935; Mon, 15 Aug 2022 11:49:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660589399; cv=none; d=google.com; s=arc-20160816; b=M8o1LZb/p/Q8fOdaAnREONmzs4D0UNU8cLW849W7yRlIimxO3DW1xl85dn6ujS1GDr 35SwfNlxJO6JFX+oVY1YmkjUCY0r2H9bEIq7AfAQMFJCQvDjZ+Mo8F5+GRskBN1yU9n+ MUq5wBdITjvOlVsCv95h20R5BtHqBvxLqlFavtTWsAVyVMtQoDPhFPtU3PJ7zg/vO/NE vDIKApgZvd79IRO8NLAqa7QXb41nfjpvrBK0ztGZhBSnQ2bPB0etla4aVZ8aFtVHRn9d nczKeGXVH/zqx5JJso2oOESYkieXz59ON5URwkyhdW6RItXcZnyE2B3UyaR4w7LpwBo2 04Lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature:dkim-signature; bh=s8F5Li3vLXtiHsgPNRcWkpFl7ut43BURsDBMgZOTsU8=; b=qRMw4qK0+nrPyNQcQt8hME1TUu+iGxYvLto218RytV78sCOliqsP/BIyKNac6IZVdJ FbC7CgiQSU+nVsmmI9DesFaRxtVb2XcgB6q5/BPICpoXTjREh8QZFoge/RJFYXyQ9u7M hWgSpEUMMty/pq7wSfcui4pTPVajHTi87v6wKbwezCyHVnHTjEmewrs8oGyiFLVZ1qaz u2/s8omwxR+cf1S4iUm/3nVS8QmOKVOMmH2/6tSnC2APPBLImQ6lChSVRsKgmryXmpAV oOfQUM+A7TYiPWbVIxYAHFhxg01YC6rn3F4PuJtrd+P9Uak3kFdD0lZVpMC3UiddPmYP gHDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov.name header.s=fm2 header.b=DHsHchme; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=bp4pJT2Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z7-20020a056402274700b0043d552deb37si8929102edd.14.2022.08.15.11.49.33; Mon, 15 Aug 2022 11:49:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@shutemov.name header.s=fm2 header.b=DHsHchme; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=bp4pJT2Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231171AbiHORe3 (ORCPT + 99 others); Mon, 15 Aug 2022 13:34:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229475AbiHORe1 (ORCPT ); Mon, 15 Aug 2022 13:34:27 -0400 Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E63EF24098 for ; Mon, 15 Aug 2022 10:34:26 -0700 (PDT) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 355FB3200978; Mon, 15 Aug 2022 13:34:24 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 15 Aug 2022 13:34:25 -0400 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=1660584863; x=1660671263; bh=s8 F5Li3vLXtiHsgPNRcWkpFl7ut43BURsDBMgZOTsU8=; b=DHsHchmeMXQCRyU3aM jlgJK7s49Lft57hqXe0uWIZHN/kg1Ax2mynbSaBkHuCzuZ4xEYU0flcw3CpQblID 0jaqwrjiTD5mhBczkgm00mg9sLvqAkYalWHtYfOnU3JalKNldaYzMjiJ/JgH1jy1 npa9ANx3eL37kYoY/29vdqecJ1eUA4562ZNAGeLCkFjfe5wRJXW6++eG6Hz+Rooi J4zRs/tOOoFEcX1nZlyprspioJMVf5wSYnS/7ud56zYegS61KINMBoV239zGQxMu eHWvgU0pifa41kNe8XFnHKdswe9zLRqM80R+HRP4iKKiFhXtcvFF0hLVvgyytQRM P1GQ== 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=1660584863; x=1660671263; bh=s8F5Li3vLXtiHsgPNRcWkpFl7ut4 3BURsDBMgZOTsU8=; b=bp4pJT2YbiY6d4r7eCyBP33QhuR3vchYjmgT1pFZI5/G t0PuyUkiSpSroZQNlN516Sh8RdI29lBLDAQ+Go4Yz5MI1YLoUK0xyvapX2aQofHJ RVAyPsWRq1z6E8O18hstgsV9k1mWwq1d4XjtzHZX9RTijjqGzpSHLfwoHkHqo6Sy wskaCoWTxDnO5iTunxMEKxCiem17W42rkPUfUox11vIdy7aiXfbjhdNQSH07tzZU +O0OOVnFXjuY6Cc9bL6H2DpC78vNSGRGX5h57oA9RkUdiYOn/3TsC7eQ7Fuc59zv uMBF0WPAreIXTqNBg4kEWx9mxhpcAgyGUSWHMowVBg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdehvddgudduhecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehttddttddttddvnecuhfhrohhmpedfmfhi rhhilhhlucetrdcuufhhuhhtvghmohhvfdcuoehkihhrihhllhesshhhuhhtvghmohhvrd hnrghmvgeqnecuggftrfgrthhtvghrnhephfeigefhtdefhedtfedthefghedutddvueeh tedttdehjeeukeejgeeuiedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrg hmpehmrghilhhfrhhomhepkhhirhhilhhlsehshhhuthgvmhhovhdrnhgrmhgv X-ME-Proxy: Feedback-ID: ie3994620:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 15 Aug 2022 13:34:22 -0400 (EDT) Received: by box.shutemov.name (Postfix, from userid 1000) id 0F94E104A4B; Mon, 15 Aug 2022 20:37:25 +0300 (+03) Date: Mon, 15 Aug 2022 20:37:25 +0300 From: "Kirill A. Shutemov" To: Peter Zijlstra Cc: "Kirill A. Shutemov" , Dave Hansen , Andy Lutomirski , x86@kernel.org, Kostya Serebryany , Andrey Ryabinin , Andrey Konovalov , Alexander Potapenko , Taras Madan , Dmitry Vyukov , "H . J . Lu" , Andi Kleen , Rick Edgecombe , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCHv6 04/11] x86/mm: Handle LAM on context switch Message-ID: <20220815173725.ph6ogtqneiqwqek7@box.shutemov.name> References: <20220815041803.17954-1-kirill.shutemov@linux.intel.com> <20220815041803.17954-5-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 15, 2022 at 03:42:25PM +0200, Peter Zijlstra wrote: > On Mon, Aug 15, 2022 at 07:17:56AM +0300, Kirill A. Shutemov wrote: > > diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c > > index c1e31e9a85d7..fdc0b69b5da7 100644 > > --- a/arch/x86/mm/tlb.c > > +++ b/arch/x86/mm/tlb.c > > @@ -154,17 +154,18 @@ static inline u16 user_pcid(u16 asid) > > return ret; > > } > > > > -static inline unsigned long build_cr3(pgd_t *pgd, u16 asid) > > +static inline unsigned long build_cr3(pgd_t *pgd, u16 asid, unsigned long lam) > > { > > if (static_cpu_has(X86_FEATURE_PCID)) { > > - return __sme_pa(pgd) | kern_pcid(asid); > > + return __sme_pa(pgd) | kern_pcid(asid) | lam; > > } else { > > VM_WARN_ON_ONCE(asid != 0); > > - return __sme_pa(pgd); > > + return __sme_pa(pgd) | lam; > > } > > } > > > > -static inline unsigned long build_cr3_noflush(pgd_t *pgd, u16 asid) > > +static inline unsigned long build_cr3_noflush(pgd_t *pgd, u16 asid, > > + unsigned long lam) > > { > > VM_WARN_ON_ONCE(asid > MAX_ASID_AVAILABLE); > > /* > > @@ -173,7 +174,7 @@ static inline unsigned long build_cr3_noflush(pgd_t *pgd, u16 asid) > > * boot because all CPU's the have same capabilities: > > */ > > VM_WARN_ON_ONCE(!boot_cpu_has(X86_FEATURE_PCID)); > > - return __sme_pa(pgd) | kern_pcid(asid) | CR3_NOFLUSH; > > + return __sme_pa(pgd) | kern_pcid(asid) | lam | CR3_NOFLUSH; > > } > > Looking at this; I wonder if we want something like this: > > --- a/arch/x86/mm/tlb.c > +++ b/arch/x86/mm/tlb.c > @@ -157,6 +157,7 @@ static inline u16 user_pcid(u16 asid) > static inline unsigned long build_cr3(pgd_t *pgd, u16 asid, unsigned long lam) > { > if (static_cpu_has(X86_FEATURE_PCID)) { > + VM_WARN_ON_ONCE(asid > MAX_ASID_AVAILABLE); > return __sme_pa(pgd) | kern_pcid(asid) | lam; > } else { > VM_WARN_ON_ONCE(asid != 0); > @@ -167,14 +168,13 @@ static inline unsigned long build_cr3(pg > static inline unsigned long build_cr3_noflush(pgd_t *pgd, u16 asid, > unsigned long lam) > { > - VM_WARN_ON_ONCE(asid > MAX_ASID_AVAILABLE); > /* > * Use boot_cpu_has() instead of this_cpu_has() as this function > * might be called during early boot. This should work even after > * boot because all CPU's the have same capabilities: > */ > VM_WARN_ON_ONCE(!boot_cpu_has(X86_FEATURE_PCID)); > - return __sme_pa(pgd) | kern_pcid(asid) | lam | CR3_NOFLUSH; > + return build_cr3(pgd, asid, lam) | CR3_NOFLUSH; > } Looks sane, but seems unrelated to the patch. Is it okay to fold it anyway? -- Kiryl Shutsemau / Kirill A. Shutemov