Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp395657rdb; Fri, 17 Nov 2023 01:46:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IHNDTGivxFYq8IXg3+85askTNeR8oOdxc0lmHFdwuOk0iESMtri/zd7UIp4k1JwlqG2/xLk X-Received: by 2002:a05:6a00:2da4:b0:6c4:cff9:a6e3 with SMTP id fb36-20020a056a002da400b006c4cff9a6e3mr17538290pfb.22.1700214387903; Fri, 17 Nov 2023 01:46:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700214387; cv=none; d=google.com; s=arc-20160816; b=vCehCzT8DQuYx00j4QMIoGKrqygyDmEyaVCndRYzTHaAUz1MOCi8z3rT5FbmiafHU2 /c56qHFg79jFcVLlnJQgfpePNMsD6p+eXHywjPzOrRASEfRnXBBYp/L3JqRZzTWoigGj Pv4yj4QSqSYA/8ziPkZmKXt7TJD+0DAr/hORGxY750esGN03S5/MAuvQMPkbbYnui8DC oddem4MgmpE1nkygQo7hGIvcjJ4x8cFfpZB1Wd3VTOJBgvPn7qOqkbV2A6EKfFnX57kt kscWIETusFhvtGMHjp5//Cn6Fb3H8pDh9q71MuXirA8JrsV8H81iEqRgXITKrnLkJFhT cYEg== 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=pXuCWcFMMyNm3tQDni1BukKDks9Oa0qI5QFUTW5eN8U=; fh=9PIG14ykZQ+S70hPmqPPFhmJ0dFEGw53xPeLesR9dqs=; b=CycN8Sq2/XqQVCuLY3FM5W0KFIrNrjoZnxzYVh79cpXU5yjMDsnapuFw6PHNxRvSzk 9usc//B95gmwx/FCDMm54WS9jyUHZdlkHvnGpo6CKJyDjNMe54UzdMpXFwTniYPEwAYv MeRBKpd1eGkpmpc8ChzVoTsacn2KUaGBpNRXedYtZjIwpUzbGofy4YLIGTZ2Ez5zmoBb JfNBcdLVtZ8DDIAjk7ze41M0oFQ9b37aKZgfMxdfR7d0euSvhXni19lDFfxKotKHi4Wj iN3ciT7TYuEzBLyYLOkTgOlMvUVuBki6BVJffVio8IaV0uYcVTE/+zjbMEqgFEnkfV4F trdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=JwfecIc3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id q6-20020a656846000000b005b99c0dae65si1496785pgt.357.2023.11.17.01.46.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 01:46:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=JwfecIc3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 1586C827A772; Fri, 17 Nov 2023 01:46:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345722AbjKQJpF (ORCPT + 99 others); Fri, 17 Nov 2023 04:45:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345881AbjKQJoj (ORCPT ); Fri, 17 Nov 2023 04:44:39 -0500 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AD56171D for ; Fri, 17 Nov 2023 01:43:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=pXuCWcFMMyNm3tQDni1BukKDks9Oa0qI5QFUTW5eN8U=; b=JwfecIc3SNWc5QSq5CmXKQA0f2 DOu48zzXFAWzzBIG86ozmTfe3qEZCZaE67GH4j2AlmsZBjMPuxUnAMWCCUY68PUQQReK5hBE174QZ +Q5mk6uFwVyh/d1O5C6Y1hSUb4gyGTv/gD+4/1IRQkEz/L0ApIL5wgJHfKV92AvMbIk6gDW1bTEQb YpKkuRhR0tSPwxTpToazFw8aC6YqcxEhkzMh3fgq9zh+5YGB24aKnrSftpF7xj4T8rk3gedURjsSP gZWPuSufNirqQuOQI+Dn/BuvFi0vQITUax8cFM0CmcntN/Rd0qC0EZ0dPPzNi6d/ONbXu+Zd6OFOC GTN0Jq3Q==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1r3vLU-007BRO-04; Fri, 17 Nov 2023 09:43:04 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id AD124300478; Fri, 17 Nov 2023 10:41:03 +0100 (CET) Date: Fri, 17 Nov 2023 10:41:03 +0100 From: Peter Zijlstra To: Uros Bizjak Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , kirill.shutemov@linux.intel.com Subject: Re: [PATCH -tip] x86/mm: Use %RIP-relative address in untagged_addr() Message-ID: <20231117094103.GM8262@noisy.programming.kicks-ass.net> References: <20231116191127.3446476-1-ubizjak@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231116191127.3446476-1-ubizjak@gmail.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 17 Nov 2023 01:46:15 -0800 (PST) On Thu, Nov 16, 2023 at 08:10:59PM +0100, Uros Bizjak wrote: > %RIP-relative addresses are nowadays correctly handled in alternative > instructions, so remove misleading comment and improve assembly to > use %RIP-relative address. Ha!, it might've been this exact case (and Kirill grumbling) that got me to fix the alternative code :-) > Also, explicitly using %gs: prefix will segfault for non-SMP builds. > Use macros from percpu.h which will DTRT with segment prefix register > as far as SMP/non-SMP builds are concerned. > Signed-off-by: Uros Bizjak Acked-byL Peter Zijlstra (Intel) > --- > arch/x86/include/asm/uaccess_64.h | 11 ++++------- > 1 file changed, 4 insertions(+), 7 deletions(-) > > diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h > index f2c02e4469cc..01455c0b070c 100644 > --- a/arch/x86/include/asm/uaccess_64.h > +++ b/arch/x86/include/asm/uaccess_64.h > @@ -11,6 +11,7 @@ > #include > #include > #include > +#include > > #ifdef CONFIG_ADDRESS_MASKING > /* > @@ -18,14 +19,10 @@ > */ > static inline unsigned long __untagged_addr(unsigned long addr) > { > - /* > - * Refer tlbstate_untag_mask directly to avoid RIP-relative relocation > - * in alternative instructions. The relocation gets wrong when gets > - * copied to the target place. > - */ > asm (ALTERNATIVE("", > - "and %%gs:tlbstate_untag_mask, %[addr]\n\t", X86_FEATURE_LAM) > - : [addr] "+r" (addr) : "m" (tlbstate_untag_mask)); > + "and " __percpu_arg([mask]) ", %[addr]", X86_FEATURE_LAM) > + : [addr] "+r" (addr) > + : [mask] "m" (__my_cpu_var(tlbstate_untag_mask))); > > return addr; > } > -- > 2.41.0 >