Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp997440iob; Fri, 13 May 2022 19:04:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxltAfHGsgEbdvAojP40S2zRA1nCwLn1oWEOPdz1uLCqZKPZOeeoDKYKU2uT06uwV79TlfU X-Received: by 2002:a05:6000:1d8e:b0:20c:cb51:4162 with SMTP id bk14-20020a0560001d8e00b0020ccb514162mr5859135wrb.626.1652493857320; Fri, 13 May 2022 19:04:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652493857; cv=none; d=google.com; s=arc-20160816; b=LDYNRb9NivF9930PDsr0f+35VyCBrIjh/66qxdkbbgBB+cz08fq6f6zDdV+POiFsVD V+2jHqFQtzKCMQTcBe1NjQVkJW6/8kASjoLofTKHDqy63WunVHTJMeo0I9Vu9B9s606W sgTUY3jPmvG+5doQo/lt+VkYOlEUmPWUaIWS46WF2nqbU4RL+Hzg4QE0VY1VfaOTrf0/ 6liiQxqQVH7FdzUCi2Ksq/W3CEJsTE9vdNizF8/089Zw+jlovptisa11f/JmD6LN9Xgz tMcA9LXoF6i2Ac2E//tJgVI5si89TtYBtBwipw2f3aLwRirDUwKMHyWZctdCm6lzzoc7 q6SA== 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:dkim-signature; bh=YrWjE8pxTZS4ai7lrBpjOGo4601LIK1+MZr7SV8ukAo=; b=qoM3kWfU8rq+aJ/FUzgkx8YVVOl3ikUwvMtUxExiYMIW+u41TA1k5/aWSg+m2Z3lzS v802kHbPCkUj1t2/YR/2Z9ot1Gq8rKEZDRu/oplXGvzFpFhgLBqfRCpo0bDONbynTwzU vwlCYL5P9439/TNfUwj51iPyTUw82NBjYooto1tR0Lhh/IM1S86uJGC/bsXV5NBPmvFT MchXrMstKRRUkwyT66FJdcE8b2npThNaOttRjX0VexbCDDU3CXnARZ2Hy9lckn+BkgQ4 I/mIbeLfm/Ni4Zp4kz5v2RxLCG7kDOCWRIhPmFw1P3I3YZvZ3LEWroYpbUyLZJNwgJ2+ BGCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=sqDm4UsI; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id g8-20020a5d64e8000000b0020ac8d7a3a3si4552880wri.549.2022.05.13.19.04.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 19:04:17 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=sqDm4UsI; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4A204481B25; Fri, 13 May 2022 17:25:36 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355235AbiELOYR (ORCPT + 99 others); Thu, 12 May 2022 10:24:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351101AbiELOYO (ORCPT ); Thu, 12 May 2022 10:24:14 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2BCD24FD9D for ; Thu, 12 May 2022 07:24:13 -0700 (PDT) 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=YrWjE8pxTZS4ai7lrBpjOGo4601LIK1+MZr7SV8ukAo=; b=sqDm4UsITF7vwCZCR+zqU6VG0I IV5VKLdd6Q4R7A6B+TVsGcYVieV9cD8g5+DbOkEJ4Unto2Sm9i2eqlkx1pmbRTVJ70Le/iJsWViJy SOhI60WRkF/ZFD0s3E6sRbKAqIvHYWBPjtQASM8NTukifoR4AogyHNQVuYrPKgBlpxc5PWwzywwg+ g8X7LTM6eKkBx3oRBgt2WsU4dr0iLxjzoFtZetEK2uIzUTV36DQKlahm8X2H2OY7hyl6uOmKeKcZj KsmT/2t+4/XzE2feu41R3W+NkTcNUwN7HvozI0mxAtBBUwn/JVP+GTpiSxxj724+bgoDdzFHVgW/d Y86CY9NQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1np9jP-006T4R-F4; Thu, 12 May 2022 14:23:55 +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 979E03001DD; Thu, 12 May 2022 16:23:48 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 84837201E235D; Thu, 12 May 2022 16:23:48 +0200 (CEST) Date: Thu, 12 May 2022 16:23:48 +0200 From: Peter Zijlstra To: Thomas Gleixner Cc: "Kirill A. Shutemov" , Dave Hansen , Andy Lutomirski , x86@kernel.org, Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , "H . J . Lu" , Andi Kleen , Rick Edgecombe , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [RFCv2 05/10] x86/mm: Provide untagged_addr() helper Message-ID: References: <20220511022751.65540-1-kirill.shutemov@linux.intel.com> <20220511022751.65540-7-kirill.shutemov@linux.intel.com> <87a6bmx5lt.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87a6bmx5lt.ffs@tglx> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Thu, May 12, 2022 at 03:06:38PM +0200, Thomas Gleixner wrote: > #define untagged_addr(addr) ({ \ > u64 __addr = (__force u64)(addr); \ > \ > __addr &= current->thread.lam_untag_mask; \ > (__force __typeof__(addr))__addr; \ > }) > > No conditionals, fast _and_ correct. Setting this untag mask up once > when LAM is enabled is not rocket science. But that goes wrong if someone ever wants to untag a kernel address and not use the result for access_ok(). I'd feel better about something like: s64 __addr = (addr); s64 __sign = __addr; __sign >>= 63; __sign &= lam_untag_mask; __addr &= lam_untag_mask; __addr |= __sign; __addr; Which simply extends bit 63 downwards -- although possibly there's an easier way to do that, this is pretty gross.