From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A2E9C433EF for ; Wed, 30 Mar 2022 20:42:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344195AbiC3Unq (ORCPT ); Wed, 30 Mar 2022 16:43:46 -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 Precedence: bulk List-ID: X-Mailing-List: linux-sgx@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