Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp847035rwe; Wed, 31 Aug 2022 12:06:42 -0700 (PDT) X-Google-Smtp-Source: AA6agR7uDLxu0wekSA2CrFwzli7pdMsQQf2LI/UpzMZSJkaX1NNRzVLI8zOLAOdVujyR0ux5Frb/ X-Received: by 2002:a63:4714:0:b0:42b:82d9:b617 with SMTP id u20-20020a634714000000b0042b82d9b617mr20353116pga.223.1661972801859; Wed, 31 Aug 2022 12:06:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661972801; cv=none; d=google.com; s=arc-20160816; b=PV22liWRs9HfsP1fDLTryJMBwo7AiaM8omZ0dIGLQkXh/eADE/LLmU8jUXoZKEjq59 OJZRON4lRqwerO3fk416H6oPF535xBKrB3EnKKwaumZMIgNdzTJC12kjUFwEXfxz+cjG eBFYoDvn3D6ex9trAQQGRTU4NocZJTQMOrwFsHbYdumBO/8+ayArMaHzJ7ukhLpaOfiZ FY2Fy3dEjeRhoAeH2jfJ30dKOwUcEJ+SEJp32FM0i4I7Fp0WDzjIYj/QDwwlNsZnmtkx y72dyIHJhVBfZxDTUuv9jOe/ze3zbNCx30xrANiBf0GHMLhRLPgjJywqu5k2D9dKD3Zs JxOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=6FiKl+N/NJJOugJxoBlHP3dmH0/6vGbk8NE3xDDl55Y=; b=0ujvitfLivB+FSMZuvr+E5olK/Ku2nL1EAFiL/3fcTtr04u6cQ22RjNL03lUIT6Bv/ SBTvmK13ks8z9BfwEihG8qabTCoDKM0OV63VOaQ8Y3QXx9ZCZG+SsfSyO9anxxqt889R 7+6Muq8tvEdTUyJnNdA2r4CMqWQTbomnmpCfTVe+eopdWT5bilClHeEhL2oCvA5wdmi4 KBwJUqicqL0RLqHXVoBzMXTz7ipe9Ycy7Ykua0/4izAA9MTNtX62Y4ivr7RNlkXKfQX1 yD0oYEwSeclwpeo94BCWVz7Pd/zBr1f4JCHYZ6OSqI2dwLwiVbQE1RwigsjOp77V4zuu HN7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rAoVdWs6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v12-20020a1709028d8c00b00172dd2494cfsi14393193plo.103.2022.08.31.12.06.31; Wed, 31 Aug 2022 12:06:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rAoVdWs6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233227AbiHaSeE (ORCPT + 99 others); Wed, 31 Aug 2022 14:34:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231784AbiHaSd3 (ORCPT ); Wed, 31 Aug 2022 14:33:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9747F10401C; Wed, 31 Aug 2022 11:28:53 -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 dfw.source.kernel.org (Postfix) with ESMTPS id ED65D61CD4; Wed, 31 Aug 2022 18:28:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0491AC433D7; Wed, 31 Aug 2022 18:28:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661970507; bh=+ENo/svJBBC8Oy4/G43ZPL5LzEhYc0IYqehWhykl2uQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=rAoVdWs61ULAlNVAt01rj/N33V4akfFULiD7EYlyIwssgT2ZKXJDGWU2EAkD8zhMH 1VflqdgaiooFjmthhZ/iRz0umOa+4Vnj1YsL8KOuTcC6acXmka4to+u7XSAjBx0QVB UpYqVZqOmXazQw+TnhE82NS/E0UxEBtHinl144vltTzkNgQNpv1hTLUs+ZLrjO4VLw f5n0qP6EtZik5PxRxhmSkYj79/t2iFWcojSxPrEfl4CAeYneblrt3NZrKQp2WNg8WU E1y+EivfKecc1G7jjN9tl2GSQ0fkmRONTJnXzekju8OzR5B7M8jGmaFjMkeZd/Bgbx HLu0dAuA6Nc/w== Date: Wed, 31 Aug 2022 21:28:23 +0300 From: "jarkko@kernel.org" To: Haitao Huang Cc: "Huang, Kai" , "pmenzel@molgen.mpg.de" , "linux-sgx@vger.kernel.org" , "x86@kernel.org" , "dave.hansen@linux.intel.com" , "Dhanraj, Vijay" , "Chatre, Reinette" , "mingo@redhat.com" , "tglx@linutronix.de" , "bp@alien8.de" , "hpa@zytor.com" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 1/6] x86/sgx: Do not consider unsanitized pages an error Message-ID: References: <20220830031206.13449-2-jarkko@kernel.org> <1f43e7b9-c101-3872-bd1b-add66933b285@intel.com> <1b3308a364317d36ad41961ea9cfee24aa122f02.camel@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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, Aug 31, 2022 at 10:18:00AM -0500, Haitao Huang wrote: > Hi Kai > On Tue, 30 Aug 2022 22:17:08 -0500, Huang, Kai wrote: > > > On Wed, 2022-08-31 at 05:57 +0300, jarkko@kernel.org wrote: > > > On Wed, Aug 31, 2022 at 02:55:52AM +0000, Huang, Kai wrote: > > > > On Wed, 2022-08-31 at 05:44 +0300, jarkko@kernel.org wrote: > > > > > On Wed, Aug 31, 2022 at 02:35:53AM +0000, Huang, Kai wrote: > > > > > > On Wed, 2022-08-31 at 05:15 +0300, jarkko@kernel.org wrote: > > > > > > > On Wed, Aug 31, 2022 at 01:27:58AM +0000, Huang, Kai wrote: > > > > > > > > On Tue, 2022-08-30 at 15:54 -0700, Reinette Chatre wrote: > > > > > > > > > Hi Jarkko, > > > > > > > > > > > > > > > > > > On 8/29/2022 8:12 PM, Jarkko Sakkinen wrote: > > > > > > > > > > In sgx_init(), if misc_register() for the provision > > > device fails, and > > > > > > > > > > neither sgx_drv_init() nor sgx_vepc_init() succeeds, > > > then ksgxd will be > > > > > > > > > > prematurely stopped. > > > > > > > > > > > > > > > > > > I do not think misc_register() is required to fail for > > > the scenario to > > > > > > > > > be triggered (rather use "or" than "and"?). Perhaps just > > > > > > > > > "In sgx_init(), if a failure is encountered after ksgxd > > > is started > > > > > > > > > (via sgx_page_reclaimer_init()) ...". > > > > > > > > > > > > > > > > IMHO "a failure" might be too vague. For instance, > > > failure to sgx_drv_init() > > > > > > > > won't immediately result in ksgxd to stop prematurally. > > > As long as KVM SGX can > > > > > > > > be initialized successfully, sgx_init() still returns 0. > > > > > > > > > > > > > > > > Btw I was thinking whether we should move > > > sgx_page_reclaimer_init() to the end > > > > > > > > of sgx_init(), after we make sure at least one of the > > > driver and the KVM SGX is > > > > > > > > initialized successfully. Then the code change in this > > > patch won't be necessary > > > > > > > > if I understand correctly. AFAICT there's no good reason > > > to start the ksgxd at > > > > > > > > early stage before we are sure either the driver or KVM > > > SGX will work. > > > > > > > > > > > > > > I would focus fixing the existing flow rather than > > > reinventing the flow. > > > > > > > > > > > > > > It can be made to work, and therefore it is IMHO correct > > > action to take. > > > > > > > > > > > > From another perspective, the *existing flow* is the reason > > > which causes this > > > > > > bug. A real fix is to fix the flow itself. > > > > > > > > > > Any existing flow in part of the kernel can have a bug. That > > > > > does not mean that switching flow would be proper way to fix > > > > > a bug. > > > > > > > > > > BR, Jarkko > > > > > > > > Yes but I think this is only true when the flow is reasonable. If > > > the flow > > > > itself isn't reasonable, we should fix the flow (given it's easy > > > to fix AFAICT). > > > > > > > > Anyway, let us also hear from others. > > > > > > The flow can be made to work without issues, which in the > > > context of a bug fix is exactly what a bug fix should do. > > > Not more or less. > > > > No. To me the flow itself is buggy. There's no reason to start ksgxd() > > before > > at least SGX driver is initialized to work. > > > > Will it cause racing if we expose dev nodes to user space before > ksgxd is started and sensitization done? I'll to explain this. So the point is to fix the issue at hand, and fix it locally. Changing initialization order is simply out of context. It's not really an argument for or against changing it We are fixing sanitization here, and only that with zero side-effects to any other semantics. It's dictated by the development process [*] but more importantly it's also just plain common sense. [*] https://www.kernel.org/doc/html/v5.19/process/submitting-patches.html#separate-your-changes BR, Jarkko