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 6F2ABC00140 for ; Mon, 15 Aug 2022 17:49:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA2396B0073; Mon, 15 Aug 2022 13:49:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B515F8D0001; Mon, 15 Aug 2022 13:49:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A18FF6B0078; Mon, 15 Aug 2022 13:49:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 922956B0073 for ; Mon, 15 Aug 2022 13:49:57 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6687C160621 for ; Mon, 15 Aug 2022 17:49:57 +0000 (UTC) X-FDA: 79802565234.27.4792D1F Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by imf18.hostedemail.com (Postfix) with ESMTP id E184D1C0016 for ; Mon, 15 Aug 2022 17:49:56 +0000 (UTC) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 0BEAE3200988; Mon, 15 Aug 2022 13:49:53 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 15 Aug 2022 13:49:55 -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=1660585792; x=1660672192; bh=QE 4xvdOORCkc8PPrFCkYq5enDGn2qK9OQMp2lhKzGVQ=; b=mya5ACVAN5qT1X/W2Y jCCqH/1im6kdrTA0XtFs7BsDwRSJZVnqwqgmI5qVlHIA8UtkjKabCOCa5lhPJYVp cQzDGJXPGQSPV7oYBGxN1C2RP4idlT5u/OpFNSQz+HdRp4jD4T9gGbp/Vl1/ikaM fgUGY5dfVMLcvEQiDk/2rctR603ExhV/rf5GVmOF5Z/602Ce6w/OhtJt/qcUitt7 dnp16m2xbjDTMk+joZW1qjvP+IHc06WeHPhmwZeWx5jSqclX+n7Vkmuu/eeJIQXZ 09CI+ejm7AZ9ZtzBRcbTkpT3S3YRp9rW7T2wOfljv+llG/P4MPtFlhGOtdVrDm52 lSlQ== 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=1660585792; x=1660672192; bh=QE4xvdOORCkc8PPrFCkYq5enDGn2 qK9OQMp2lhKzGVQ=; b=wsZILPh2C+viSRkVWCNxJy+im1EuErXftj+inD9bovx/ F0fZ4Xz3VM/dUQEfx2xmepB0E+6sSd4JVPjcFUyWSlk0AP+zFxH8mU5ZHZF59wBP G0nRLpSk3GtiBg4nl17FyhgMNnJtUgN9VIfUDXAltHQzwJU1zggczvaiwwcawgcd XGQIVWKxMX0Qhmk7GgrewCSKrPHaiHytBHSuVRSrrPc5R1ZTFx3ENP1UK4S/JJrf MzCRxfL7qBkujlA1WT639L9F6uePB/2gvO7ximLVQeUO9ok8Wa+RKT73VuPxQsW6 JsQ76sGfZ/NLsmFFMQ0rJwOXJbE/yOd6BOGHGWpAFg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdehvddguddulecutefuodetggdotefrod 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:49:51 -0400 (EDT) Received: by box.shutemov.name (Postfix, from userid 1000) id D69D6104A4B; Mon, 15 Aug 2022 20:52:54 +0300 (+03) Date: Mon, 15 Aug 2022 20:52:54 +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 06/11] x86/mm: Provide arch_prctl() interface for LAM Message-ID: <20220815175254.jwogd3civiny6kas@box.shutemov.name> References: <20220815041803.17954-1-kirill.shutemov@linux.intel.com> <20220815041803.17954-7-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660585797; a=rsa-sha256; cv=none; b=EXaHeoKlxFphlaP5nwtbxICjITTtiXxLcbYMopKXAqVy2BF3rdes3U7mTdmSVyvt85bnoG I9vwUECbxzN1Uh2V7OXxdw7WMuG3d2XltqEXxtf9zfJltwFCDW/2boXSewTj4LclayRBap C9aM8C5clxYLAMdWERu5c0N5/6yuAd4= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=shutemov.name header.s=fm2 header.b=mya5ACVA; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=wsZILPh2; dmarc=none; spf=pass (imf18.hostedemail.com: domain of kirill@shutemov.name designates 64.147.123.19 as permitted sender) smtp.mailfrom=kirill@shutemov.name ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660585797; 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=QE4xvdOORCkc8PPrFCkYq5enDGn2qK9OQMp2lhKzGVQ=; b=KvWdxDKuq/d3whPsgeM0Mggflq7UoNY4UbMXh1yjt181fvPei6Afa5/A+63b1xcM0VQAeZ /D/WXQcl7kNiMjjtqM6q2M0MKWnojaS1sPAKpj5BajV7shcMmpNJN+jUM57+eDZejfqHPK TWbCYfOBMjvswe3/45mbhECXpGoarpg= X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: E184D1C0016 X-Rspam-User: Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=shutemov.name header.s=fm2 header.b=mya5ACVA; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=wsZILPh2; dmarc=none; spf=pass (imf18.hostedemail.com: domain of kirill@shutemov.name designates 64.147.123.19 as permitted sender) smtp.mailfrom=kirill@shutemov.name X-Stat-Signature: q3sckmgu8r7ayhu55bagfxy9o4xq95yh X-HE-Tag: 1660585796-26828 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, Aug 15, 2022 at 03:37:16PM +0200, Peter Zijlstra wrote: > On Mon, Aug 15, 2022 at 07:17:58AM +0300, Kirill A. Shutemov wrote: > > > +static void enable_lam_func(void *mm) > > +{ > > + struct mm_struct *loaded_mm = this_cpu_read(cpu_tlbstate.loaded_mm); > > + unsigned long lam_mask; > > + unsigned long cr3; > > + > > + if (loaded_mm != mm) > > + return; > > + > > + lam_mask = READ_ONCE(loaded_mm->context.lam_cr3_mask); > > + > > + /* Update CR3 to get LAM active on the CPU */ > > + cr3 = __read_cr3(); > > + cr3 &= ~(X86_CR3_LAM_U48 | X86_CR3_LAM_U57); > > + cr3 |= lam_mask; > > + write_cr3(cr3); > > + set_tlbstate_cr3_lam_mask(lam_mask); > > +} > > + > > +static int prctl_enable_tagged_addr(struct mm_struct *mm, unsigned long nr_bits) > > +{ > > + int ret = 0; > > + > > + if (!cpu_feature_enabled(X86_FEATURE_LAM)) > > + return -ENODEV; > > + > > + mutex_lock(&mm->context.lock); > > + > > + /* Already enabled? */ > > + if (mm->context.lam_cr3_mask) { > > + ret = -EBUSY; > > + goto out; > > + } > > + > > + if (!nr_bits) { > > + ret = -EINVAL; > > + goto out; > > + } else if (nr_bits <= 6) { > > + mm->context.lam_cr3_mask = X86_CR3_LAM_U57; > > + mm->context.untag_mask = ~GENMASK(62, 57); > > + } else { > > + ret = -EINVAL; > > + goto out; > > + } > > + > > + /* Make lam_cr3_mask and untag_mask visible on other CPUs */ > > + smp_mb(); > > smp_mb() doesn't make visible -- it is about ordering, what does it > order against that the below on_each_cpu_mask() doesn't already take > care of? You are right it is redundant. I will drop it. -- Kiryl Shutsemau / Kirill A. Shutemov