Received: by 2002:a05:6512:2355:0:0:0:0 with SMTP id p21csp207729lfu; Wed, 30 Mar 2022 21:00:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLGj2WtXlSkNKvxJ4KMMVVa6flYhciX4e5Is84jdK3BPMMogpCGruCTax089Fmqp4lazvJ X-Received: by 2002:a17:90a:e7d2:b0:1c7:b410:ccfc with SMTP id kb18-20020a17090ae7d200b001c7b410ccfcmr3654993pjb.209.1648699237916; Wed, 30 Mar 2022 21:00:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648699237; cv=none; d=google.com; s=arc-20160816; b=PffGBn1MGRweoDl8FrSXHtGBXDqhmwQUTmTkQIjnzIy9oAeSmAxxrbUXTb0SpXJwy3 A6wx44emdd47jsv+lzNZoj898SxUVYWB2obVbRup9DkQuZ5qeDhZFTuHcvCz5RoEOvpC XWbsQ/QDlbswLAav347RHKrNqfHkK6A48iqHxyv60nvsXOfqLXViJIFfE1GVqE5HRPEC biLP2+ErU3x3NNclFgY9qWGRf1Luz51GWIuD21hZCi3sK9m6PjJ85HOuB20Kv/3edogN av8xNLqVTPNQZrb+fUuEbzHNanCOfR84L/+hSQN2d0iT4oFm2TNuZx6tkfH2vA7fbydL QSRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=KGi00FHUN9pql2Fy3ESgO8WTRBNNeTwGaF+L4l3I7t0=; b=p5tZx4jUEd5NNgSDMEMlIZGUCPsFHSP3UEcx0xTmzKHwSvkkwwJ0WyQEMabEkb8Y4J CJe3Lm4KKMtxYtLucGFNsXpaDR/lH7DJNb/UwBUMA4lsRM4S2FZJXirsYaMWzp6Sxhpv /6Qc0zZkJce7mZ7Gc2kRkfWFwfYZ6jbqbnOv4KtFb7KoeV7DVMzD8IaeNzz82+vl59Nx WRl70lOk1/Ssiu/o0GwzmnoWmrDIhtCUbOefPui+hc7ewYU2b5No4mFD7i7QIoUUYRUo pkECy1pOWQ22eZggFkmV59SJJYewKx+njPZ36FOu9iwUX9Z519x1PivLg6qDSP9WIzp2 L94g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ViHSiG1a; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id d18-20020a170903231200b0015489a635b9si24974422plh.605.2022.03.30.21.00.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 21:00:37 -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=@kernel.org header.s=k20201202 header.b=ViHSiG1a; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 309CD16BCD1; Wed, 30 Mar 2022 20:08:14 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351073AbiC3Unr (ORCPT + 99 others); Wed, 30 Mar 2022 16:43:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232155AbiC3Unp (ORCPT ); Wed, 30 Mar 2022 16:43:45 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D964B21265; Wed, 30 Mar 2022 13:41:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8B4FCB81E0B; Wed, 30 Mar 2022 20:41:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A404AC340F0; Wed, 30 Mar 2022 20:41:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648672917; bh=YoLEiYr7FjK+HfANJQQoei+ci9f7JQj4Iv0FSLnVaU0=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=ViHSiG1ajt3kn0PkxITnrxY+gbQsNZmldVedxzj8ca92V/aOMjh73kziyWAlF+6VH I/Amj1lssTRnjGnhRLYxmUv0QvXiXKykyOUXAE/2TwJZoDUkEGoNDeUfZpyBrj9Mgd RxH0IeN30ZnBFoqUJY1+dxD1LZI9TRo/HRr42WfyErtZu2yQKytiD+XjeWeYNMtOst wp6++of/YotGQ1emtvWAZmN6o0UHLca3x4KRLsJs0Wt9+KgdytHfK3HjhgbAMg95Z0 Q4V5sTFMr29vza6LsH0R9EI2OEFM260E2dU2pzuGNzf258gpcotcEvhqz3PeYZnc8F lzjIF7t1CiKIQ== Message-ID: Subject: Re: [PATCH v2 1/2] selftests/sgx: Use rip relative addressing for encl_stack From: Jarkko Sakkinen To: Reinette Chatre Cc: Shuah Khan , Dave Hansen , Shuah Khan , "open list:INTEL SGX" , "open list:KERNEL SELFTEST FRAMEWORK" , open list Date: Wed, 30 Mar 2022 23:40:56 +0300 In-Reply-To: References: <20220322074313.7444-1-jarkko@kernel.org> <7b7732ec-c7ff-cf92-510f-64c83ed985cd@intel.com> <0031a4f0-75f6-3104-1825-dcc2528f61b0@intel.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.42.4 MIME-Version: 1.0 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2022-03-30 at 13:05 -0700, Reinette Chatre wrote: >=20 >=20 > On 3/30/2022 12:03 PM, Jarkko Sakkinen wrote: > > On Wed, 2022-03-30 at 10:40 -0700, Reinette Chatre wrote: > > > Could you please elaborate how the compiler will fix it up? > >=20 > > Sure. > >=20 > > Here's the disassembly of the RBX version: > >=20 > > [0x000021a9]> pi 1 > > lea rax, [rbx + loc.encl_stack] > >=20 > > Here's the same with s/RBX/RIP/: > >=20 > > [0x000021a9]> pi 5 > > lea rax, loc.encl_stack > >=20 > > Compiler will substitute correct offset relative to the RIP, > > well, because it can and it makes sense. >=20 > It does not make sense to me because, as proven with my test, > the two threads end up sharing the same stack memory. I see, I need to correct my patch, thanks! RBX gives correct results because of the binary organization, i.e. TCS's are placed to zero offset and forward, and=20 unrelocated symbol is just compiled in as an untranslated offset. RPI is given correct results but how the semantics work right now is incompatible. Still, even for kselftest, I would consider a switch because that way: 1. You can layout binary however you wan and things won't break. 2. You can point to any symbol not just stack, if ever need. =20 I admit it works semantically but it just super unrobust. BR, Jarkko