Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5668628pxj; Wed, 23 Jun 2021 06:33:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkIesmgl6HXjYTPV2jmUhZiyYeAx88b3dDEkI1lFsAAVZy+1VPnWIhn4NZUNkzhVewZYTT X-Received: by 2002:a05:6402:1c8e:: with SMTP id cy14mr12631964edb.271.1624455206950; Wed, 23 Jun 2021 06:33:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624455206; cv=none; d=google.com; s=arc-20160816; b=n76g6HzmwTNMrqBGHv/KW2w9e3jrpV4rgo9R7oW7KOehB3gAzKfFIkd5nxmbmVIdax CRPqUOgZ93XhhFYKPQfDA+4oi9Z2aLesoM0iCjGmEMJ/XCTLDoPKOpIRFsgWNurTAC9E GZYWmp+C0w9/Q2iD+L/VRk5DpX8WhdXAbBZoTw7Srn3n6z2dwFl2y+vizD+PlZ0IlZSR F52cI34kbJfuzD8s6k2yevs+h7Xv24z5XCi/bzTLbQyeZZ/hNNcD0HXhr6WF2tM2TGC2 Q3IqjNlDI4MGATVcM4xqWFB7RaRxee6x0h+55xtrBLbGdKmcSfsMwApdOJMRSHqm6JBr Rywg== 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=Rn3X0P1PeaKx5vV8NkbVvkWr2Q/ZvUpN5+guslJTPbs=; b=kRnpMK9Yi9qvdpC+aaJldCJFyM7DQIBsYaDjPT1JMkyFhceuEOsiO+4/E+exxmg/j2 SOEdFhqotEOni7He5qJoAm6jPfDPJp2stlOKUL2giCrOnj4Dx7tsWPqpCSSqxxDR8usP PveO3LOVCvhYtJCQLVFKWiOqG5e37Sz6OnBR3aEgB+UkNQR4HkKGs0rVDBZ1zGWvlpYQ AvetAUV+cvcaMcdbF8dEXxrkgd+IFlQYSFc6hfHRz4vTaJ/4alJUQjckVarBhoa0FSqh DZACAj9lzWpuXY6ERUemrgDOWC/o2hxWjdSvRflygqskZEz8BAZpeYsXwjRIYWfk1le3 PIjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KV2mB1Rh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g14si8042899edp.270.2021.06.23.06.33.04; Wed, 23 Jun 2021 06:33:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KV2mB1Rh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S230308AbhFWNeQ (ORCPT + 99 others); Wed, 23 Jun 2021 09:34:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:43408 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230182AbhFWNeP (ORCPT ); Wed, 23 Jun 2021 09:34:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6FB036100A; Wed, 23 Jun 2021 13:31:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624455117; bh=OdXBWIQy2zDURmOwfGymFrpL27m/aqRVaBhRTmRpY4c=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KV2mB1RhKO/jNUgubZsZe3NXAx74Y8blNL+FKdARI5ix7vPlBJTZ2SVmw4yM1IOfK prYKF6ITQ4oNo9e9t+t3snwrsq9fzDw9BbAWS2MwRjzDmqjB+lk2N0+qX5cv5TI3nR 26Dq2TpwvIu7PJ+9vIjjSt4IMBgXD1v2WWjD5mwgk36avigmipIvAyK/6kZHtUKxWL AESaBCkDLJgQhaPXm+ixmfdJU7O6ixWc6dAE+O8TV0yVBkq4yFO0w889+jQgWNEY5F CScVx2/cuUFYzXprq2Qm2YtVo8iPOKc7Oc2/HUXv09cIbRTBIlU8L4trOZVjswR4Lh CPyL+xA4ugXCg== Date: Wed, 23 Jun 2021 16:31:55 +0300 From: Jarkko Sakkinen To: Sean Christopherson Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, Dave Hansen , "H. Peter Anvin" , linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org, Du Cheng Subject: Re: [PATCH] x86/sgx: Suppress WARN on inability to sanitize EPC if ksgxd is stopped Message-ID: <20210623133155.ea6pohm2nfpybwzo@kernel.org> References: <20210616004458.2192889-1-seanjc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210616004458.2192889-1-seanjc@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 15, 2021 at 05:44:58PM -0700, Sean Christopherson wrote: > Don't WARN on having unsanitized EPC pages if ksgxd is stopped early, > e.g. if sgx_init() realizes there will be no downstream consumers of EPC. > If ksgxd is stopped early, EPC pages may be left on the dirty list, but > that's ok because ksgxd is only stopped if SGX initialization failed or > if the kernel is going down. In either case, the EPC won't be used. > > This bug was exposed by the addition of KVM support, but has existed and > was hittable since the original sanitization code was added. Prior to > adding KVM support, if Launch Control was not fully enabled, e.g. when > running on older hardware, sgx_init() bailed immediately before spawning > ksgxd because X86_FEATURE_SGX was cleared if X86_FEATURE_SGX_LC was > unsupported. > > With KVM support, sgx_drv_init() handles the X86_FEATURE_SGX_LC check > manually, so now there's any easy-to-hit case where sgx_init() will spawn > ksgxd and _then_ fail to initialize, which results in sgx_init() stopping > ksgxd before it finishes sanitizing the EPC. > > Prior to KVM support, the bug was much harder to hit because it basically > required char device registration to fail. > > Reported-by: Du Cheng > Fixes: e7e0545299d8 ("x86/sgx: Initialize metadata for Enclave Page Cache (EPC) sections") > Signed-off-by: Sean Christopherson > --- Thank you. Reviewed-by: Jarkko Sakkinen > Lightly tested due to lack of hardware. I hacked the flow to verify that > stopping early will leave work pending, and that rechecking should_stop() > suppress the resulting WARN. > > arch/x86/kernel/cpu/sgx/main.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c > index ad904747419e..fbad2b9625a5 100644 > --- a/arch/x86/kernel/cpu/sgx/main.c > +++ b/arch/x86/kernel/cpu/sgx/main.c > @@ -425,7 +425,7 @@ static int ksgxd(void *p) > __sgx_sanitize_pages(&sgx_dirty_page_list); > > /* sanity check: */ > - WARN_ON(!list_empty(&sgx_dirty_page_list)); > + WARN_ON(!list_empty(&sgx_dirty_page_list) && !kthread_should_stop()); > > while (!kthread_should_stop()) { > if (try_to_freeze()) > -- > 2.32.0.272.g935e593368-goog > > /Jarkko