Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp37634rdb; Thu, 16 Nov 2023 11:11:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IEReWbdLn9g3cxGEzJKR1riaaNI7M0FwPs4FZD4n29mY+bM0tdNr/Kv/2y9KtBqI0/rlOwP X-Received: by 2002:a17:90b:314c:b0:280:72b:397d with SMTP id ip12-20020a17090b314c00b00280072b397dmr3798445pjb.20.1700161914788; Thu, 16 Nov 2023 11:11:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700161914; cv=none; d=google.com; s=arc-20160816; b=Bd1fNxytyM1wNTQkwlBMdvIagOD7DhJaasAvuu/Ik64wfENuPsQ0haplvUSHv86m8L lj9aFZ5A2XH36lfJswXDhDOvjQYunGf6xqECz9qlHHO8aVN9w9QJFkOliwilyZwGtLci 8KsCOq73zmKH4fyuuJtF5Kib7hER1vnn65Ae/61WlOevvp2PYUFCnLUBoMWxGVGvOowD JFvR8GivG8RWz4F8RTXGi5Lrg7uLN1A7gkl+IX6VZYzbjXce2V3pNDlZm8+58XXy3pFl 0boJeu9OYZJfqeg8bUE1uTvPFqzV2LMib1eugcQ1aQpqH7W32MuWy7kTMyjfhabs1u7l XmcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=GwQUpHrldieb9q/f898qx9fwKE9eO/IChKWvTMHwjHs=; fh=sWK7YOurtkTyaE7aaZtytOmSvUDe8vhU+5hRY6IWLIo=; b=YvtjJK4Ia//CoimUG1DavcUy7FNejkSCA/taKnHcQyZez5VkKPGl9b7TDyZnbWR49Q Mc2DdyRi1LmX24j/Ae0bA534Vrwrd6W0kG+QTSrFhc7u9TAJQnKh5UjC1c7ix5wij13Y GEeiPJxvyvISp8eHutMAeDS9xtv2/Bo50H+iLj0igBWXPQi0qsGjF1f5Ypb22FCqWMiG HqZnxqniQsfUFhABno+nnYzeq3NdSA9pk0YXHo3tTZwL+e7xdz9ffaa3uCo4ORrkzlTq hdvgcddNOdyupFEkASlxXzzHujHXWZXVRqZZYaQskNfyFff1+dDyG6i2kQRg3FXmvOQp psrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=NA5xmWzM; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id jf17-20020a170903269100b001c9e0fcf90esi42753plb.60.2023.11.16.11.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 11:11:54 -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=@gmail.com header.s=20230601 header.b=NA5xmWzM; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 1CD1A80A4ADF; Thu, 16 Nov 2023 11:11:52 -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 S229841AbjKPTLo (ORCPT + 99 others); Thu, 16 Nov 2023 14:11:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229510AbjKPTLn (ORCPT ); Thu, 16 Nov 2023 14:11:43 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD02CD4E for ; Thu, 16 Nov 2023 11:11:39 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-9d216597f64so165351666b.3 for ; Thu, 16 Nov 2023 11:11:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700161898; x=1700766698; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=GwQUpHrldieb9q/f898qx9fwKE9eO/IChKWvTMHwjHs=; b=NA5xmWzMRF1SZmLb55xWj52IAqnlpEQ6IfUPLi5kP3PmUG6gI+dHhk8sLXbpkd/Sdb PHDrOBGbnSQfMQ+cJCdVZJ2SZZE9P9utsiviAP0J9gwv1J11BDCHoVHnOKacVK72ajDN RDMAnu58mCZwv++hegCuP+Uhlkv3vXfBznx0b31KnXsk++Npt4mloxDS9/P4/PUtyGnI 7Mynwee8CxJV3zt7anCV/OhunnDGlwL4nLk5BtvyxbC658tkwoDMQJvY9Ts9wvJQ3Wow lDfENoVPWfIMMjWTaejHxrCSmWqBsjwy+bQ3mzU3fdfqjoxVoMwXX+ZdrWZ6RdKPYUK6 19fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700161898; x=1700766698; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GwQUpHrldieb9q/f898qx9fwKE9eO/IChKWvTMHwjHs=; b=o7Y5qUXITdgK1uHXaaiOKtTiQjFj3SimevrLaIgv1cGVRz7MT3fdGPRuxbMUMuJlGS 1mVejuWaCTnUs3J/tKCj9szQYWIsqR48zISpWFA+C2KdZ/xQNb4gguR7H9mjGszsWcWM UQLoP25W7I1VOOGM5Ee37tBe8/PGAgIMKKjDXkNYqC+sn6GQge5xmECvTSaobTX1fnr+ qBZEaDsBgGFdhV6ZAVVex8CjLyq9qmDK8nOoDKCXJhv5rSXrPgKn8NaYBuqzkxE9LqdU RDF+KwoKjuNbowrORTxARUoRxMsDuahoWsv7lkh9N7+ht4rw3WYoUJhF2yjitHBcqZgP jX8A== X-Gm-Message-State: AOJu0YxvMwZEFaS3mZ0me+6iEisp+122J485A5K9s6idARToUIm0CTsx eKKF0z5fhAtmU1uARhxWnMI= X-Received: by 2002:a17:906:234d:b0:9d3:f436:6809 with SMTP id m13-20020a170906234d00b009d3f4366809mr12531752eja.39.1700161897905; Thu, 16 Nov 2023 11:11:37 -0800 (PST) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id mb24-20020a170906eb1800b00992e14af9c3sm8899951ejb.143.2023.11.16.11.11.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 11:11:37 -0800 (PST) From: Uros Bizjak To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Peter Zijlstra Subject: [PATCH -tip] x86/mm: Use %RIP-relative address in untagged_addr() Date: Thu, 16 Nov 2023 20:10:59 +0100 Message-ID: <20231116191127.3446476-1-ubizjak@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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]); Thu, 16 Nov 2023 11:11:52 -0800 (PST) %RIP-relative addresses are nowadays correctly handled in alternative instructions, so remove misleading comment and improve assembly to use %RIP-relative address. 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. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Peter Zijlstra Signed-off-by: Uros Bizjak --- 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