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 7EFF8C38145 for ; Tue, 6 Sep 2022 08:39:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 055A18026D; Tue, 6 Sep 2022 04:39:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0043280224; Tue, 6 Sep 2022 04:39:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E0E378026D; Tue, 6 Sep 2022 04:39:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D0EA080224 for ; Tue, 6 Sep 2022 04:39:48 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9F0891201E6 for ; Tue, 6 Sep 2022 08:39:48 +0000 (UTC) X-FDA: 79881012456.23.7872284 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf06.hostedemail.com (Postfix) with ESMTP id 62FAC180064 for ; Tue, 6 Sep 2022 08:39:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=gRAbSu+qYZ/sJhD3A71yXMZFADBWv+Eht0jraA34zZ4=; b=Jfdik1W1RQN3C9DTIjLDt1yPyQ xrp/njvpvvpQGvRIoNSFZuoCgEUIkFtfq4uN4CVyijur36UsUyIlm7Z+yn8bI+3fA512uDEQ145Fc WdLNav/S5knTNwvCTFwMwbk5ucuY8UFbNP1ssklhydwR3JyLY9lC9bASRLUHTzn5Umw/qh+oaVmmv mLaiiT+PGFhIdxtfwaubrfFiMGgS48nQKQ10po2jrN9eLv1sB7IJxWaqV5vRBMT3rXcXf7+mxzhgg kn2PmXuGvv34DdLA7hvUS54o3lnU8RDS9AHG5IyRWRDn0rjUdnV5vNiNMnpo4r1AFt/tF4xfvh21Z eMZtlx/g==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1oVU7H-00AEiY-40; Tue, 06 Sep 2022 08:39:31 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id CBCDD300244; Tue, 6 Sep 2022 10:39:27 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id ADD5E209D2D1D; Tue, 6 Sep 2022 10:39:27 +0200 (CEST) Date: Tue, 6 Sep 2022 10:39:27 +0200 From: Peter Zijlstra To: "Kirill A. Shutemov" Cc: Bharata B Rao , ananth.narayan@amd.com, "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: [PATCHv8 00/11] Linear Address Masking enabling Message-ID: References: <20220830010104.1282-1-kirill.shutemov@linux.intel.com> <20220904010001.knlcejmw4lg2uzy3@box.shutemov.name> <64519d0b-b696-db47-52c2-303451e10c09@amd.com> <20220905134457.a2f7uluq42frsgwe@box.shutemov.name> <20220905153517.k6ctaqqtkcyu2zmn@box.shutemov.name> <20220905164708.ewx5lulbqdjrk3mx@box.shutemov.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220905164708.ewx5lulbqdjrk3mx@box.shutemov.name> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662453587; a=rsa-sha256; cv=none; b=qXPOtYDZYjKYuag89AMWLcLB4rDqttzQMvkcVcurvzl3/wgK59+HjbekzhmKtQMXul3pon 6ol9+UU/5SQ+r2U75W0JbNljpI72Wm70UkVj1A5ea4YxEOlnMFtntZymYf5LIzdADjIUDI FLxwyRRp7XoMJu4g9Msy+3tTjhD0jTM= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Jfdik1W1; spf=none (imf06.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662453587; 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=gRAbSu+qYZ/sJhD3A71yXMZFADBWv+Eht0jraA34zZ4=; b=xFwT4U25pJd626sq+2m9ijdO7M4wUweDEtZPwuCALb5K4PggHRiyvZJjATjjw4YZrzlRAc hKifcgFV5ad5MNuRXxbPVr9QNuiV3r3sDhdFzU22jDfhXXElE/Pyz4PBrHMgafsOTglEhg 2UKgyMoFUKkEIUNLUoaMuMOjBKDiud0= X-Stat-Signature: 5a1587ypytng6bmz415jhsy1ieaoukjr X-Rspamd-Queue-Id: 62FAC180064 Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Jfdik1W1; spf=none (imf06.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1662453586-508078 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, Sep 05, 2022 at 07:47:08PM +0300, Kirill A. Shutemov wrote: > Fair enough. How about this? > > diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h > index 803241dfc473..1a03c65a9c0f 100644 > --- a/arch/x86/include/asm/uaccess.h > +++ b/arch/x86/include/asm/uaccess.h > @@ -22,6 +22,8 @@ static inline bool pagefault_disabled(void); > #endif > > #ifdef CONFIG_X86_64 > +DECLARE_STATIC_KEY_FALSE(tagged_addr_key); > + > /* > * Mask out tag bits from the address. > * > @@ -30,8 +32,10 @@ static inline bool pagefault_disabled(void); > */ > #define untagged_addr(mm, addr) ({ \ > u64 __addr = (__force u64)(addr); \ > - s64 sign = (s64)__addr >> 63; \ > - __addr &= (mm)->context.untag_mask | sign; \ > + if (static_branch_unlikely(&tagged_addr_key)) { \ > + s64 sign = (s64)__addr >> 63; \ > + __addr &= (mm)->context.untag_mask | sign; \ > + } \ > (__force __typeof__(addr))__addr; \ > }) > > diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c > index 337f80a0862f..63194bf43c9a 100644 > --- a/arch/x86/kernel/process_64.c > +++ b/arch/x86/kernel/process_64.c > @@ -742,6 +742,9 @@ static long prctl_map_vdso(const struct vdso_image *image, unsigned long addr) > } > #endif > > +DEFINE_STATIC_KEY_FALSE(tagged_addr_key); So here you use the: false-unlikely scenario which seems suboptimal in this case, I was thinking the false-likely case would generate better code (see the comment in linux/jump_label.h). > +EXPORT_SYMBOL_GPL(tagged_addr_key); > + > static void enable_lam_func(void *mm) > { > struct mm_struct *loaded_mm = this_cpu_read(cpu_tlbstate.loaded_mm); > @@ -813,6 +816,7 @@ static int prctl_enable_tagged_addr(struct mm_struct *mm, unsigned long nr_bits) > } > > on_each_cpu_mask(mm_cpumask(mm), enable_lam_func, mm, true); > + static_branch_enable(&tagged_addr_key); > out: > mutex_unlock(&mm->context.lock); > mmap_write_unlock(mm); Aside from the one nit above, this looks about right.