Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp4846645ybf; Wed, 4 Mar 2020 11:53:12 -0800 (PST) X-Google-Smtp-Source: ADFU+vvvhWP3dJHjBYsZ8KV/dDT+/OXqG6XBeVn5PVQ63Jh84Agauvv1Qk1sQRdo2nLBMWSuxpW5 X-Received: by 2002:aca:1a05:: with SMTP id a5mr2010695oia.113.1583351592713; Wed, 04 Mar 2020 11:53:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583351592; cv=none; d=google.com; s=arc-20160816; b=qrRXgToXCciF/hZSXm82/OLuly788ojKJL4xBJ5HRstpbRMgEBtp9E0y2vmYif5nJH zmEjIdxS4OKwn+Ea5QWoWX/qoQryGE5wi1GwyTxjDlCbroj4ga1fCvpBQ8AAx5bJFhUD o99ruNKe/PIx7CWHhpEYfHobS/n7lEloVBBP5Y0YmQKSTH1ThgNPYGLSNj4pwr4XDpxA nQ3fjpGBtRhDqAkDOtmDnbI8puBLaAm4THytC0x7KTnGJT1Q3sAz1jo6HjSqN15VzHLA g9FiVY+VOcu/epLLIbfO6W6U/RPN06zqteD0iZWHIfnuEWDof1yQBoPC40i93x4v8LBj UYTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Ra5c/deVBpeBf2yDXKORW+EsDATadMRlpq+nR2VPF8g=; b=b74Bkgi6+7ve3YNARqcTqjjQ9DaA/MyolN1jatMYOFrmj8v13m6/5AGPByu4udEstS H+4oHYfWpXmbpefa8/IFSkRxTelqec463ymY8+4dpIf4w2KHkyeup02oMQhgDpXGri3Q wnLJYZWJcUcYp7X2cZ7LTcTg3UjIbFESVLHRHP/2XJE3IDW9tLbyZfTknbVupHug7V9e lyqbMmsxB7/vIJ7FVhBcoQ8ypLS1mqGHtjqJ7QFhB9S/Fac3YOnNus6AMYUtCJAlWcN3 XwCg56PUlzeScm6XUNa4SpD79qO50NV1mZFNdOUTflZO9q0ORITvbcvsIm2GXP3G38Iv vhxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=f7Km3cQ4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x20si1978507otq.253.2020.03.04.11.53.00; Wed, 04 Mar 2020 11:53:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=f7Km3cQ4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387505AbgCDTvy (ORCPT + 99 others); Wed, 4 Mar 2020 14:51:54 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:37302 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728278AbgCDTvx (ORCPT ); Wed, 4 Mar 2020 14:51:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583351512; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Ra5c/deVBpeBf2yDXKORW+EsDATadMRlpq+nR2VPF8g=; b=f7Km3cQ4pSUxDVHnTLDDaZnsxzdewnva77C8oYyCSuOzc2QU1HpgUWEneuhZEIOeXsxG6r vcd7hVehNpjQwSfuVlvAUKB8aTCU1bsQRGgCjLtPmmMn/Xj4EKZox8ea6TSOu8DN93u8rz JXhbM1EOPpBbgw/Z6iPCnKYgY+GNQyk= Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-268-eO15Aqt7PheaMdwqoMKLEw-1; Wed, 04 Mar 2020 14:51:51 -0500 X-MC-Unique: eO15Aqt7PheaMdwqoMKLEw-1 Received: by mail-io1-f69.google.com with SMTP id h2so1226283iow.18 for ; Wed, 04 Mar 2020 11:51:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Ra5c/deVBpeBf2yDXKORW+EsDATadMRlpq+nR2VPF8g=; b=N6Ay0nDi/nANd6A8leDpnI2NFN1wDBIk6gQ4nRjcnElfbJQfN0A267WKleFl1yX0no prXisakzZ60WhPGikqCuLXVdP5sJI9ZGcWuJj+b6WYtg7aLz0pLzr56dKqyxafl0vY5o xDwhH230V9A+9IRsy+ZJXIzCuqp5RKQdVsqiU1qIMo4HXDr5N9HXnfTuTSotPEDgfYOg A39m2ePr28eIZFDljCi5SChLf+IczdwS27z7jnH+Iu1Nc/QMh+c/V559BCUed0Ab3qmr d6Vu/fGtDTAf/PEIC1fRQMHQ6H3Z789aOIJIQZ8OMJRsx/eWCYgKATVrDG5jORbugLeZ cFrg== X-Gm-Message-State: ANhLgQ2Vfq+poDIM51Tgvp0dLfa8f58ui2KGt9W1M6aYPx+qI0OMQSX5 8kfMf3HQhYa6VZx2NkLmJjtoD2iE5rsabrxOIlTTwaPGDAyHBGfIwvbA7AaYAwi6M03KD2gLC+u 2aZPKyodcqJByMH6UViZLFtTeX6wYSsBNPenfmy9i X-Received: by 2002:a02:86:: with SMTP id 128mr4197972jaa.3.1583351510744; Wed, 04 Mar 2020 11:51:50 -0800 (PST) X-Received: by 2002:a02:86:: with SMTP id 128mr4197956jaa.3.1583351510519; Wed, 04 Mar 2020 11:51:50 -0800 (PST) MIME-Version: 1.0 References: <20200303233609.713348-1-jarkko.sakkinen@linux.intel.com> <20200303233609.713348-15-jarkko.sakkinen@linux.intel.com> In-Reply-To: <20200303233609.713348-15-jarkko.sakkinen@linux.intel.com> From: Nathaniel McCallum Date: Wed, 4 Mar 2020 14:51:39 -0500 Message-ID: Subject: Re: [PATCH v28 14/22] selftests/x86: Add a selftest for SGX To: Jarkko Sakkinen Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linux-sgx@vger.kernel.org, akpm@linux-foundation.org, dave.hansen@intel.com, "Christopherson, Sean J" , Neil Horman , "Huang, Haitao" , andriy.shevchenko@linux.intel.com, tglx@linutronix.de, "Svahn, Kai" , bp@alien8.de, Josh Triplett , luto@kernel.org, kai.huang@intel.com, rientjes@google.com, cedric.xing@intel.com, Patrick Uiterwijk , linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 3, 2020 at 6:39 PM Jarkko Sakkinen wrote: > diff --git a/tools/testing/selftests/x86/sgx/sgx_call.S b/tools/testing/selftests/x86/sgx/sgx_call.S > new file mode 100644 > index 000000000000..ca4c7893f9d9 > --- /dev/null > +++ b/tools/testing/selftests/x86/sgx/sgx_call.S > @@ -0,0 +1,23 @@ > +/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */ > +/** > +* Copyright(c) 2016-18 Intel Corporation. > +*/ > + > + .text > + > + .macro ENCLU > + .byte 0x0f, 0x01, 0xd7 > + .endm > + > + .text > + > + .global sgx_call_eenter > +sgx_call_eenter: > + push %rbx > + mov $0x02, %rax > + mov %rdx, %rbx > + lea sgx_async_exit(%rip), %rcx > +sgx_async_exit: > + ENCLU > + pop %rbx > + ret You need to push and pop all the callee-saved registers here since the enclave zeros them. This code works today by accident. A future compiler may emit different register allocation which will cause this to break. We might consider making it part of the Linux enclave ABI that the enclave has to save and restore these registers. This would have a slight performance advantage in a critical code-path compared to zeroing and then restoring them. But the VDSO code will need to know what the expectation is.