Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp779191rdb; Thu, 30 Nov 2023 19:55:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IE6oKEiefKPIqGTR5dHT3ZwKK0hxPbEiaKsE8aY5dMSMChqzWJE6Fh5OBFoCQexSX992H8U X-Received: by 2002:a05:6a00:23c4:b0:6cb:cd66:2102 with SMTP id g4-20020a056a0023c400b006cbcd662102mr33031374pfc.4.1701402924057; Thu, 30 Nov 2023 19:55:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701402924; cv=none; d=google.com; s=arc-20160816; b=zhgvBxMZmV14EZqvtmiiHS0Qvt2Mghyx86mtDCCLRQikI4/o9ylMokkuYk8hxm3dgb IUjw6UZmLhLj0bANLrzZvq70wfVDmPffgMWagTmOXlk4Y1tf+rz4jWBfbaMV5adTZkY6 E8yD4poPhiDHRrXYT7crPkR4XcjX087OVxKVGT52TcWr/N4gTQvVI8mbCfzCPG/sPgrA 1Sn1EyQWd9/VV4iF6hJ4ZAb83hAyaWJh72R3yNWF0DDpz8GUsRVLmJidD+86mwK34Y7q I8DfNppvfbLxUtjv2W2dVD3b9u7TTx1wDGZ630oBfcY8EfFfufAHh/zYgwqcJ6suRPwk qeXw== 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=jOSXlOtKFBD1Mep2uCedee2kxXEhGTZ+xXDcj/gtww8=; fh=YZEWlm2YTAqSOyfma7jTQNtfyf8nEnj/QaDdigBuZEc=; b=t0ryqOR3H+wSc+y8Cd/zblnY4mG1LC6D3KlTAd6KlBg9g3scNqOJYOOihdUhEvQU83 QNVpG/huWgbf8h0iKsyf/nPWNNuEstg0iCLrk7qYhjS6tS0mt+D4qC2dovUSr1hv8r8g NptPy3qrnlZbiOrxF0C6S4S5XCqHWPqy/uPlChPng0f0yv/ZcBjkdrPxuQOoS49uWdFt oXvO1LqFJ6sSUzPDewPK8s0wkAblZoWiq/D73Ly1tD/Wbap7BA6qfp2PY3h6f8xN4fxW jkgqotDz4sXD2+JBbGPVelXZl1VNRy6N1m3g2rBjFM2Q0G7IT3WcHGPe8NrEz3JZp8ZI QoYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NpE2SaUi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id e69-20020a636948000000b005bdf597ed49si2561848pgc.56.2023.11.30.19.55.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 19:55:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NpE2SaUi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 8976980E762A; Thu, 30 Nov 2023 19:55:10 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230098AbjLADyz (ORCPT + 99 others); Thu, 30 Nov 2023 22:54:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229505AbjLADyy (ORCPT ); Thu, 30 Nov 2023 22:54:54 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAD4210D7 for ; Thu, 30 Nov 2023 19:55:00 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62ABAC433C8; Fri, 1 Dec 2023 03:54:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701402900; bh=2eDs4rq/o2XffOF2c3AbganMdUEvcgwhvDkUuTL6Ks8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NpE2SaUiW5ZvDrhOhXYzsnU0dePt+6ngyVmnyYun5XctDO7RXcU4oK7xE/D0OMSgz 8h+ykVLnUyskKTFsDzUnI6nQ/CJ1jJDD/498a1t5g5XIgW2Y6+4xiI7gYpJiEQHsar hpy3NZLDmU170gwZYh8+RK9/jRHsZLppceiP02vJ7mrDdM8W39b6scSgNdTdpFlGiN pzzdPALI87+hTO4qTDpT0jgDpDXKWyelpdkSfbdHvnSRXGXd3UMb911N45DQ4tfuFM sGDy13+zlv4uaAhmNdAuLV6BTHmpRFcFb8TVN2Ejf4VWTPep6eaLInU7YzaiA18bSS 9QJe/Ec5oDwqQ== Date: Thu, 30 Nov 2023 20:54:57 -0700 From: Nathan Chancellor To: Uros Bizjak Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Peter Zijlstra , llvm@lists.linux.dev Subject: Re: [PATCH -tip v2 2/3] x86/callthunks: Handle %rip-relative relocations in call thunk template Message-ID: <20231201035457.GA321497@dev-arch.thelio-3990X> References: <20231105213731.1878100-1-ubizjak@gmail.com> <20231105213731.1878100-3-ubizjak@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231105213731.1878100-3-ubizjak@gmail.com> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 30 Nov 2023 19:55:10 -0800 (PST) Hi Uros, On Sun, Nov 05, 2023 at 10:34:36PM +0100, Uros Bizjak wrote: > Contrary to alternatives, relocations are currently not supported in > call thunk templates. Re-use the existing infrastructure from > alternative.c to allow %rip-relative relocations when copying call > thunk template from its storage location. > > The patch allows unification of ASM_INCREMENT_CALL_DEPTH, which already > uses PER_CPU_VAR macro, with INCREMENT_CALL_DEPTH, used in call thunk > template, which is currently limited to use absolute address. > > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: Borislav Petkov > Cc: Dave Hansen > Cc: "H. Peter Anvin" > Cc: Peter Zijlstra > Signed-off-by: Uros Bizjak ... > diff --git a/arch/x86/kernel/callthunks.c b/arch/x86/kernel/callthunks.c > index e9ad518a5003..ef9c04707b3c 100644 > --- a/arch/x86/kernel/callthunks.c > +++ b/arch/x86/kernel/callthunks.c ... > @@ -291,20 +298,27 @@ void *callthunks_translate_call_dest(void *dest) > static bool is_callthunk(void *addr) > { > unsigned int tmpl_size = SKL_TMPL_SIZE; > - void *tmpl = skl_call_thunk_template; > + u8 insn_buff[MAX_PATCH_LEN]; > unsigned long dest; > + u8 *pad; > > dest = roundup((unsigned long)addr, CONFIG_FUNCTION_ALIGNMENT); > if (!thunks_initialized || skip_addr((void *)dest)) > return false; > > - return !bcmp((void *)(dest - tmpl_size), tmpl, tmpl_size); > + *pad = dest - tmpl_size; Clang warns (or errors with CONFIG_WERROR=y): arch/x86/kernel/callthunks.c:315:3: error: variable 'pad' is uninitialized when used here [-Werror,-Wuninitialized] 315 | *pad = dest - tmpl_size; | ^~~ arch/x86/kernel/callthunks.c:309:9: note: initialize the variable 'pad' to silence this warning 309 | u8 *pad; | ^ | = NULL 1 error generated. which came from our continuous integration: https://github.com/ClangBuiltLinux/continuous-integration2/actions/runs/7054081453/job/19205345548 https://storage.tuxsuite.com/public/clangbuiltlinux/continuous-integration2/builds/2Yv1FATZZIeD3P7S57ZkHYhyZ8A/build.log > + > + memcpy(insn_buff, skl_call_thunk_template, tmpl_size); > + apply_relocation(insn_buff, tmpl_size, pad, > + skl_call_thunk_template, tmpl_size); > + > + return !bcmp(pad, insn_buff, tmpl_size); > } Cheers, Nathan