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=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=unavailable 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 08324C433B4 for ; Fri, 2 Apr 2021 15:43:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DAB0F61151 for ; Fri, 2 Apr 2021 15:43:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236341AbhDBPnB (ORCPT ); Fri, 2 Apr 2021 11:43:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235366AbhDBPm5 (ORCPT ); Fri, 2 Apr 2021 11:42:57 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D4EEC061788 for ; Fri, 2 Apr 2021 08:42:56 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id x21-20020a17090a5315b029012c4a622e4aso2742889pjh.2 for ; Fri, 02 Apr 2021 08:42:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=948hixTMO4Bse84quoCDDTDU0D12jquiYBG/MaisshI=; b=rOfzGVulAMSSNZLnXpdUSnMz9qp59WaXkf1bCdPbisSUQcE4FmyzPoa+HvgeMbj93l //LpXDGPZI8qPxMgCAS6emI3JB6MgLd+ue+Goct+Ff5JnWOJ/IGdVtXmD0e4/Cc63KKG t4yGRDQLmbduzsmnr5fiZ4St2SqOfotviZn9dnz2VJvtVIMUpcxdWoyKu3+VV18pB5wl CX8dkPraIbgDYjb8M5mAPt5amM2hKhn76EoylG44tkrLJiAIVmlSNRwEThBmZKoE8JsK 54Ku+GKrgI+qkfOWbbS+65murE5mtumEh1yNijnkqVPO0ipQhRCl5n1kcSfY6MC+HWCc A20g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=948hixTMO4Bse84quoCDDTDU0D12jquiYBG/MaisshI=; b=EG2233byQf9XllURtX4/XWbfcVLv6WE0F8Ux12R4Lz+ogqiS753M3KDriKHvY27Iv/ cAhpgaWVEcNYik82c9CqODmPX0gP90JYHdXaQqvcdWFoRdDeP6WhlmPw/W3DnIzvTqzE Ugf4GDGmgk0KJ2pmlj+50vaIWbqvbYGBV+XJ7f8e9Qnt7+tr55RJ2b13nl9xVGCXzN6g qC0UApVshGWj494R0KrWtwDw8QGz5Z5uzGL0RFy/WQhdjRduqGW5wfs+NPB9+6PUZdhZ mC09ZSf5mnWZxAkNuQTeH7DJYbVxBharY3eNr0qlsaXlnvXLsmdRwbBU2LpJ/wl0Fvau Lgcg== X-Gm-Message-State: AOAM530FMdSKdDNjhnJBw2kk3SNTKD6kj9equBQf3gU7AJ6J3ENC+Xsf bJUGDBpIGnJ1R5e3N7YFHb/HGA== X-Google-Smtp-Source: ABdhPJzEm9zD9QFj85ocvRmTmxRm0r8hRGMzuCeiZsQ/utPofnN/IZWYdnpG9T/w7AaWUS60aALNuA== X-Received: by 2002:a17:90b:201:: with SMTP id fy1mr14122204pjb.108.1617378175466; Fri, 02 Apr 2021 08:42:55 -0700 (PDT) Received: from google.com (240.111.247.35.bc.googleusercontent.com. [35.247.111.240]) by smtp.gmail.com with ESMTPSA id v9sm9211979pfc.108.2021.04.02.08.42.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Apr 2021 08:42:54 -0700 (PDT) Date: Fri, 2 Apr 2021 15:42:51 +0000 From: Sean Christopherson To: Borislav Petkov Cc: Kai Huang , kvm@vger.kernel.org, linux-sgx@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, jarkko@kernel.org, luto@kernel.org, dave.hansen@intel.com, rick.p.edgecombe@intel.com, haitao.huang@intel.com, pbonzini@redhat.com, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com Subject: Re: [PATCH v3 07/25] x86/sgx: Initialize virtual EPC driver even when SGX driver is disabled Message-ID: References: <20210402094816.GC28499@zn.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210402094816.GC28499@zn.tnic> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 02, 2021, Borislav Petkov wrote: > On Fri, Mar 19, 2021 at 08:23:02PM +1300, Kai Huang wrote: > > Modify sgx_init() to always try to initialize the virtual EPC driver, > > even if the SGX driver is disabled. The SGX driver might be disabled > > if SGX Launch Control is in locked mode, or not supported in the > > hardware at all. This allows (non-Linux) guests that support non-LC > > configurations to use SGX. > > > > Acked-by: Dave Hansen > > Reviewed-by: Sean Christopherson > > Signed-off-by: Kai Huang > > --- > > arch/x86/kernel/cpu/sgx/main.c | 10 +++++++++- > > 1 file changed, 9 insertions(+), 1 deletion(-) > > > > diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c > > index 6a734f484aa7..b73114150ff8 100644 > > --- a/arch/x86/kernel/cpu/sgx/main.c > > +++ b/arch/x86/kernel/cpu/sgx/main.c > > @@ -743,7 +743,15 @@ static int __init sgx_init(void) > > goto err_page_cache; > > } > > > > - ret = sgx_drv_init(); > > + /* > > + * Always try to initialize the native *and* KVM drivers. > > + * The KVM driver is less picky than the native one and > > + * can function if the native one is not supported on the > > + * current system or fails to initialize. > > + * > > + * Error out only if both fail to initialize. > > + */ > > + ret = !!sgx_drv_init() & !!sgx_vepc_init(); > > This is a silly way of writing: > > if (sgx_drv_init() && sgx_vepc_init()) > goto err_kthread; > > methinks. Nope! That's wrong, as sgx_epc_init() will not be called if sgx_drv_init() succeeds. And writing it as "if (sgx_drv_init() || sgx_vepc_init())" is also wrong since that would kill SGX when one of the drivers is alive and well.