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 X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF8DEC433E6 for ; Wed, 3 Feb 2021 23:12:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6DF2164F5C for ; Wed, 3 Feb 2021 23:12:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233522AbhBCXL7 (ORCPT ); Wed, 3 Feb 2021 18:11:59 -0500 Received: from mga04.intel.com ([192.55.52.120]:38758 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233427AbhBCXLx (ORCPT ); Wed, 3 Feb 2021 18:11:53 -0500 IronPort-SDR: HnWjrkITVVPXofg1I/pds9U23ziJsnvJ4aFqjWXaFJqaVtG+hiE9PR5Hn1IqEv/6cVe9DzhFNr VTUEC9XpnXnQ== X-IronPort-AV: E=McAfee;i="6000,8403,9884"; a="178573697" X-IronPort-AV: E=Sophos;i="5.79,399,1602572400"; d="scan'208";a="178573697" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2021 15:11:12 -0800 IronPort-SDR: jBv23RtswQXmbmaklkEgNsCN/lssnr17GBfN6Bu97a5wr99aBmLcVEMiFWwUPbaYq42DHJCXof 4hvQ5nvpzOww== X-IronPort-AV: E=Sophos;i="5.79,399,1602572400"; d="scan'208";a="576071191" Received: from rvchebia-mobl.amr.corp.intel.com ([10.251.7.104]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2021 15:11:08 -0800 Message-ID: <61fd68c4f03881596331c663040b92751bd67832.camel@intel.com> Subject: Re: [RFC PATCH v3 23/27] KVM: VMX: Add SGX ENCLS[ECREATE] handler to enforce CPUID restrictions From: Kai Huang To: Sean Christopherson Cc: "Edgecombe, Rick P" , "linux-sgx@vger.kernel.org" , "kvm@vger.kernel.org" , "x86@kernel.org" , "Huang, Haitao" , "luto@kernel.org" , "jarkko@kernel.org" , "Hansen, Dave" , "vkuznets@redhat.com" , "bp@alien8.de" , "mingo@redhat.com" , "tglx@linutronix.de" , "hpa@zytor.com" , "pbonzini@redhat.com" , "joro@8bytes.org" , "wanpengli@tencent.com" , "jmattson@google.com" Date: Thu, 04 Feb 2021 12:11:05 +1300 In-Reply-To: References: <20210203221110.c50ec5cd50a77d269c3656bd@intel.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.3 (3.38.3-1.fc33) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-sgx@vger.kernel.org On Wed, 2021-02-03 at 09:07 -0800, Sean Christopherson wrote: > On Wed, Feb 03, 2021, Kai Huang wrote: > > On Tue, 2 Feb 2021 17:36:12 -0800 Sean Christopherson wrote: > > > On Wed, Feb 03, 2021, Edgecombe, Rick P wrote: > > > > On Tue, 2021-01-26 at 22:31 +1300, Kai Huang wrote: > > > > > +       /* > > > > > +        * Verify alignment early.  This conveniently avoids having > > > > > to worry > > > > > +        * about page splits on userspace addresses. > > > > > +        */ > > > > > +       if (!IS_ALIGNED(pageinfo.metadata, 64) || > > > > > +           !IS_ALIGNED(pageinfo.contents, 4096)) { > > > > > +               kvm_inject_gp(vcpu, 0); > > > > > +               return 1; > > > > > +       } > > > > > + > > > > > +       /* > > > > > +        * Translate the SECINFO, SOURCE and SECS pointers from GVA > > > > > to GPA. > > > > > +        * Resume the guest on failure to inject a #PF. > > > > > +        */ > > > > > +       if (sgx_gva_to_gpa(vcpu, pageinfo.metadata, false, > > > > > &metadata_gpa) || > > > > > +           sgx_gva_to_gpa(vcpu, pageinfo.contents, false, > > > > > &contents_gpa) || > > > > > +           sgx_gva_to_gpa(vcpu, secs_gva, true, &secs_gpa)) > > > > > +               return 1; > > > > > + > > > > > > > > Do pageinfo.metadata and pageinfo.contents need cannonical checks here? > > > > > > Bugger, yes. So much boilerplate needed in this code :-/ > > > > > > Maybe add yet another helper to do alignment+canonical checks, up where the > > > IS_ALIGNED() calls are? > > > > sgx_get_encls_gva() already does canonical check. Couldn't we just use it? > > After rereading the SDM for the bajillionth time, yes, these should indeed use > sgx_get_encls_gva(). Originally I was thinking they were linear addresses, but > they are effective addresses that use DS, i.e. not using the helper to avoid the > DS.base adjustment for 32-bit mode was also wrong. Agreed. > > > For instance: > > > > if (sgx_get_encls_gva(vcpu, pageinfo.metadata, 64, 64 &metadata_gva) || > > sgx_get_encls_gva(vcpu, pageinfo.contents, 4096, 4096, > >                              &contents_gva)) > > return 1;