Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp305442rdb; Thu, 2 Nov 2023 04:29:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHdfeN7g51k5HyoWLxfDHbLKohDnN42Jr1JdKxmH2ucQmKRls0RVrJyQB2ZpC+Yv7odDTLU X-Received: by 2002:a05:6a21:7742:b0:181:10ee:20ca with SMTP id bc2-20020a056a21774200b0018110ee20camr6956218pzc.30.1698924598769; Thu, 02 Nov 2023 04:29:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698924598; cv=none; d=google.com; s=arc-20160816; b=phCSwGcZu5NxCb1B5rMJWpddJwHUIwH8tz8/aQQPoJdHUHdbdA2ieQSlR4tbwm+nUI inPl3v9VOoqzS7dMt6+jfp97EdNo0L0OunmA0u0JdD5/Nw6WBLuMOd2oNvvCxeuBJMmj CmueK7u3qQGx6wfg/M22GZSSw2L8Vq94EAixB/zx6J5rSCmaxdFIVtoBwHr5ssinlpDW QutvLHnJyYOwsWvQykza3Rn8ISQJGnApGywusCXYz6wgKleKZYMzp3yBR0CltlmhfrKx VKIVN4OdasBgTFgXMxlb38kbfyWgDrqA9qkNhtNKhd/9BQEB71m9PnR8A+U0aX/r1ucz GFbg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tgAqePGVhUCu3U56kTFLSJugpfg6qt/lSZ7uytS2Gf4=; fh=sWK7YOurtkTyaE7aaZtytOmSvUDe8vhU+5hRY6IWLIo=; b=ZxsU020KrxMPgv4FAn9yM2/A5+D+nhh49lV4SrHBpL93hq0rrertRizjxE01HLiJsG g/XCq0rDxMpY9ojiB0kbM2l4BHcJqKHUdV9NpsA/rg0z9zX5FhW5A/r+mabl5kfDRD4I GHg7TWJ7xsUv7f1KG4eu8ZL3wpJWKVclXr2DJ3XrzJPFvjdo8yZfb4RLI8Fs6YvI9Xu8 dXh7zeGDthXnOUovPFAr/bdY/Orp3n4kL52ixuISqBtnciumRP+GMe22rFFcgGbXUfdP QvrtVe+M5S9WTtzK9oZ2DIHcDXcfywYBCt47eATs+rxq4VzZFmVQa5IyZEn/JuXdgpRo piIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BQb08mpb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id q21-20020a056a00089500b00690cd91cee7si3507683pfj.287.2023.11.02.04.29.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 04:29:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BQb08mpb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 604918029321; Thu, 2 Nov 2023 04:29:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229781AbjKBL3P (ORCPT + 99 others); Thu, 2 Nov 2023 07:29:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376270AbjKBL3J (ORCPT ); Thu, 2 Nov 2023 07:29:09 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10578111 for ; Thu, 2 Nov 2023 04:29:07 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-507973f3b65so984015e87.3 for ; Thu, 02 Nov 2023 04:29:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698924545; x=1699529345; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tgAqePGVhUCu3U56kTFLSJugpfg6qt/lSZ7uytS2Gf4=; b=BQb08mpbYh4FwfaddGcZDs6LMGQnnXbzI0le3TBrHcv1i3VvxZ6K4o2jAR9Z81J//U OzR5vtBq+WdIuym23V3smYHtt+mrRKJ012WMHImhqZ9pqo3fUp8gOoiPeqbfS8tEdZOe YiJqlTlegHZkL2SYFi/jpdcvnU/cC26Tts7euW0wYEmE50bQ0KG1SXDdmnfttrjopwlu ZGpzCRQ6/e7a62wj19wkm6oHOxE0GhipaQwJ5w/OU9L8oCKxS/wanYGP8m/5XlTHFSb7 hxPzYr++/0wRXmTuHQ1hnV40jgLrq4qqZ0v7S578+ZiY8rRpe2qddCF4EkWybRak/Dyo WZow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698924545; x=1699529345; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tgAqePGVhUCu3U56kTFLSJugpfg6qt/lSZ7uytS2Gf4=; b=kVcUYyi3QCMHygkg8XU72NlXW8AmSc2iHX1cN1+LguvIifXgFNdUtBvZauT1QqLu6H Vv3kyfibAe0EH8IrKrEeyxWp3/CUvdiX79iTSRCKa6c9P+lyvNM5mXeSyKwYUpanwDaw c5a1lq0Te8cTXihda64h9h3lTcIxU9iRPYkkHyqUG4iyJksM4cso3BRRjIDrJLqMv7+z /wAMp1ULU4tH8C4W+cN3TAW70Kyq9He2/vAAB1fdSESq6nIJn2GV8ZVD08uEe7H5vnwN jhDOwfvTh6rblQJKKsK5cKzI63C2lEdc9sHhRyI24YBvuNljS09ka4tK9GTxiqj+VNDt PMxw== X-Gm-Message-State: AOJu0YxaiEzqDHN4BMupSiBiZamZwZWeIYqEN/rgod60DpBInJzdfztR efXaTBdXlr4UkQ6YMtPwapk= X-Received: by 2002:a05:6512:2248:b0:4fe:7e7f:1328 with SMTP id i8-20020a056512224800b004fe7e7f1328mr17608450lfu.16.1698924544906; Thu, 02 Nov 2023 04:29:04 -0700 (PDT) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id d10-20020a5d4f8a000000b003232f167df5sm2168227wru.108.2023.11.02.04.29.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 04:29:04 -0700 (PDT) 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 3/3] x86/callthunks: Fix and unify call thunks assembly snippets Date: Thu, 2 Nov 2023 12:25:48 +0100 Message-ID: <20231102112850.3448745-4-ubizjak@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231102112850.3448745-1-ubizjak@gmail.com> References: <20231102112850.3448745-1-ubizjak@gmail.com> 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 groat.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 (groat.vger.email [0.0.0.0]); Thu, 02 Nov 2023 04:29:54 -0700 (PDT) Currently thunk debug macros explicitly define %gs: segment register prefix for their percpu variables. This is not compatible with !CONFIG_SMP, which requires non-prefixed percpu variables. Fix call thunks debug macros to use PER_CPU_VAR macro from percpu.h to conditionally use %gs: segment register prefix, depending on CONFIG_SMP. Finally, unify ASM_ prefixed assembly macros with their non-prefixed variants. With support of %rip-relative relocations in place, call thunk templates allow %rip-relative addressing, so unified assembly snippet can be used everywhere. 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/nospec-branch.h | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h index f93e9b96927a..6f677be6bdb9 100644 --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -59,13 +59,13 @@ #ifdef CONFIG_CALL_THUNKS_DEBUG # define CALL_THUNKS_DEBUG_INC_CALLS \ - incq %gs:__x86_call_count; + incq PER_CPU_VAR(__x86_call_count); # define CALL_THUNKS_DEBUG_INC_RETS \ - incq %gs:__x86_ret_count; + incq PER_CPU_VAR(__x86_ret_count); # define CALL_THUNKS_DEBUG_INC_STUFFS \ - incq %gs:__x86_stuffs_count; + incq PER_CPU_VAR(__x86_stuffs_count); # define CALL_THUNKS_DEBUG_INC_CTXSW \ - incq %gs:__x86_ctxsw_count; + incq PER_CPU_VAR(__x86_ctxsw_count); #else # define CALL_THUNKS_DEBUG_INC_CALLS # define CALL_THUNKS_DEBUG_INC_RETS @@ -80,9 +80,6 @@ #define CREDIT_CALL_DEPTH \ movq $-1, PER_CPU_VAR(pcpu_hot + X86_call_depth); -#define ASM_CREDIT_CALL_DEPTH \ - movq $-1, PER_CPU_VAR(pcpu_hot + X86_call_depth); - #define RESET_CALL_DEPTH \ xor %eax, %eax; \ bts $63, %rax; \ @@ -95,20 +92,14 @@ CALL_THUNKS_DEBUG_INC_CALLS #define INCREMENT_CALL_DEPTH \ - sarq $5, %gs:pcpu_hot + X86_call_depth; \ - CALL_THUNKS_DEBUG_INC_CALLS - -#define ASM_INCREMENT_CALL_DEPTH \ sarq $5, PER_CPU_VAR(pcpu_hot + X86_call_depth); \ CALL_THUNKS_DEBUG_INC_CALLS #else #define CREDIT_CALL_DEPTH -#define ASM_CREDIT_CALL_DEPTH #define RESET_CALL_DEPTH -#define INCREMENT_CALL_DEPTH -#define ASM_INCREMENT_CALL_DEPTH #define RESET_CALL_DEPTH_FROM_CALL +#define INCREMENT_CALL_DEPTH #endif /* @@ -158,7 +149,7 @@ jnz 771b; \ /* barrier for jnz misprediction */ \ lfence; \ - ASM_CREDIT_CALL_DEPTH \ + CREDIT_CALL_DEPTH \ CALL_THUNKS_DEBUG_INC_CTXSW #else /* @@ -311,7 +302,7 @@ .macro CALL_DEPTH_ACCOUNT #ifdef CONFIG_CALL_DEPTH_TRACKING ALTERNATIVE "", \ - __stringify(ASM_INCREMENT_CALL_DEPTH), X86_FEATURE_CALL_DEPTH + __stringify(INCREMENT_CALL_DEPTH), X86_FEATURE_CALL_DEPTH #endif .endm -- 2.41.0