Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp142387rwb; Tue, 4 Oct 2022 01:44:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM45q6WAdkd7t9rlFk7C9KOWcYsj3IhRmwLh2OPPiosft+IAQPairDF08Zm3zIXuXoFLQ/Ud X-Received: by 2002:a05:6a00:114c:b0:528:2c7a:630e with SMTP id b12-20020a056a00114c00b005282c7a630emr26192034pfm.86.1664873077188; Tue, 04 Oct 2022 01:44:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664873077; cv=none; d=google.com; s=arc-20160816; b=Zj+oTHGJgV2FEeRVEDsA31tvj8EwFcadtcmx6TLKioT1cDCPgCrL3kwqhTmQxhIWCf UqpThDjRlCMm/sXKbXBKeHJDQKtAmW8VxMNC2tQMj/IvJryMEzx+gpY5TvxSFYnnmjIv 45bHTekdOu8/RkP6Bl+7d8CIl31yRj5VTlZ9u+bhwE0cw88/bMYA+I53dnRny1sPr5/+ ZNo6qdfaPPtyeXwdlv3qiTuKsjia/nvM139K7HMMyHPPwVYo+ylPaw3BsqiVbm7VkAkN QyEp0cIt62fwZpugxwzgMmxrnU/opMWXgBBk5+Ir6XJhquG9/m5HONPCBlWyGpeZtGPS sm0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=KqsrzYor1IDL/G5WqsCeBXOgqDBaPz5BJOPsr1Ggbuo=; b=gQ3XmGglK5FKVs2FKHEv2plilVs2Pps3nKLwA/t+wm7jW09185gmM0+kkBwNMWJu90 W0VWRPu5MyjiebQEDTlF2dOMg/oRau8ynKrD7bec82h6SZWxP7DDNsm1kPcJv4bD3xm9 u35f/GXluPMU5LCmra3QC/HnZfhcoGCH2k9BulvDQ1O3EcvRpS0caAFtLZCuczDs2TXB zpuUmWKYmILBJLvSDcRrulZV2Hng6OVPqLlQjpqniDtfj7wUPSSUjESm2K0jD34F8h2D JPJ9GAiRmuP1owzQXhTA7SBz0Kizn07POfNnZAnsrflH0c3f8nGuY68O1mQp37EjynDL iaEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pngbARxc; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 e2-20020a17090301c200b0017776235445si12356397plh.36.2022.10.04.01.44.23; Tue, 04 Oct 2022 01:44:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=pngbARxc; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 S229998AbiJDI2V (ORCPT + 99 others); Tue, 4 Oct 2022 04:28:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229927AbiJDI2T (ORCPT ); Tue, 4 Oct 2022 04:28:19 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6621F22BD5 for ; Tue, 4 Oct 2022 01:28:17 -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 ams.source.kernel.org (Postfix) with ESMTPS id A87D4B81919 for ; Tue, 4 Oct 2022 08:28:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64A19C43470 for ; Tue, 4 Oct 2022 08:28:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664872094; bh=KqsrzYor1IDL/G5WqsCeBXOgqDBaPz5BJOPsr1Ggbuo=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=pngbARxco8iNl6GM133fTehcx9wHc8W181B8vvWchhR0dgyTbhfiZpKkAX08J2b// AHc7TSIWWdUGLjxYrIwcgkFH2/OP5SW/ooTZDoM5u9VJEY0LWu/aXHyDRkAuVPouvN 7h2PUbWCI8K/2p4bU81BtBECJlBdV/h4fhml6jjmEfUWBcXknr8l4Axe2wzE8G9ZDe 1mrnLYMkHRX/yb5ZYFKK32kHqEgUxVv0/XvXb1aYH0cNTSZm0FmoJ42uU+Y7Yo+LMt 204oZo0X1rZVCfbD/xYaVVNkPkv++QntIUWlWCGe8Pc/Tr9X1w6hvGGgOMGe2q4yQO o5IWnxn6RqO0g== Received: by mail-lf1-f47.google.com with SMTP id 25so9802741lft.9 for ; Tue, 04 Oct 2022 01:28:14 -0700 (PDT) X-Gm-Message-State: ACrzQf2BV4UQ5dF+QW+g80nHSsczPxVWyE7Flu4FZGQyVVO2sZ671zeZ WYw+Vs2kkWUIOilSKiFNqG1sTjKfl14zeUvGIbM= X-Received: by 2002:a05:6512:150e:b0:492:d9fd:9bdf with SMTP id bq14-20020a056512150e00b00492d9fd9bdfmr8274973lfb.583.1664872092433; Tue, 04 Oct 2022 01:28:12 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ard Biesheuvel Date: Tue, 4 Oct 2022 10:28:01 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Early init for few crypto modules for Secure Guests To: "Nikunj A. Dadhania" Cc: herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org, Tom Lendacky , ketanch@iitk.ac.in Content-Type: text/plain; charset="UTF-8" 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 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-crypto@vger.kernel.org On Tue, 4 Oct 2022 at 10:24, Ard Biesheuvel wrote: > > On Tue, 4 Oct 2022 at 06:41, Nikunj A. Dadhania wrote: > > > > Hi! > > > > We are trying to implement Secure TSC feature for AMD SNP guests [1]. During the boot-up of the > > secondary cpus, SecureTSC enabled guests need to query TSC info from Security processor (PSP). > > This communication channel is encrypted between the security processor and the guest, > > hypervisor is just the conduit to deliver the guest messages to the security processor. > > Each message is protected with an AEAD (AES-256 GCM). > > > > As the TSC info is needed during the smpboot phase, few crypto modules need to be loaded early > > to use the crypto api for encryption/decryption of SNP Guest messages. > > > > I was able to get the SNP Guest messages working with initializing few crypto modules using > > early_initcall() instead of subsys_initcall(). > > > > Require suggestion/inputs if this is acceptable. List of modules that was changed > > to early_initcall: > > > > early_initcall(aes_init); > > early_initcall(cryptomgr_init); > > early_initcall(crypto_ctr_module_init); > > early_initcall(crypto_gcm_module_init); > > early_initcall(ghash_mod_init); > > > > I understand the need for this, but I think it is a bad idea. These > will run even before SMP bringup, and before pure initcalls, which are > documented as /* * A "pure" initcall has no dependencies on anything else, and purely * initializes variables that couldn't be statically initialized. */ So basically, you should not be relying on any global infrastructure to have been initialized. This is also something that may cause different problems on different architectures, and doing this only for x86 seems like a problem as well. Can you elaborate a bit on the use case? AES in GCM mode seems like a thing that we might be able to add to the crypto library API without much hassle (which already has a minimal implementation of AES)