Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp976259rwn; Thu, 15 Sep 2022 08:45:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6wHC+82t4lQUUZNKAbbaGLTRWxa/cJjQ5C2nEmsieiHeR7XL7LB6HCm8ngqHPNT9X4Tp9l X-Received: by 2002:a17:902:8e84:b0:178:71f2:113c with SMTP id bg4-20020a1709028e8400b0017871f2113cmr171495plb.79.1663256739925; Thu, 15 Sep 2022 08:45:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663256739; cv=none; d=google.com; s=arc-20160816; b=MaOoOflXPx0PWg9+JRfT1ejVanQGtPsNFiWUl1U1oCFe8P0nkbJDKxpx0RcCFud8uj u+2kade06JJZrHb5mG0CgZFIjEQwKcKGvDPx4GBcEpVC6rBj0fwnrF2kA83iXPCZ4WQg +nknhq3KRBpzHamE6g8c4XEhK9DV/FNVLm2xZeE1Z1JD7WLUuv1/AQvso7KczkyBJ85D RQlcfjScUhh08aCS/b3uWSjd3Lk6G68m/exl6oTc80FNOov7HBgnt6pxUcwpzBp/G6Uf R3cZiNh7zFiG2PF0gX9BL6325fbiz97nZowmTK3hQS78acuePXjn4kGauCjUP3apLX4e A9sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=BLTdVz1r3jk7cXRJVXyJPydoKG18ONVwvgekxlD//VY=; b=l9hnJ9HGB2uRTX5mMTeQbRgGL400Et1hkrDoU2HJ5XpHkikLAYIh2okA4QAaFYPN1H F0XFoE6A8NW0fv9o7q84eo14PJbH+UJ1WoOGK1IUjEvuIyLm+Tg8S6WdQ2FNmdRT5AgK r5EfoRvVJAvP5iGsPbxifrZ/6QLeNKOJ7036H76t+F2iHIKNuFSjrtoo79md55FlL5Kw 85K1U7OahjpIIcruY24yzJz2usCVmuSz8lRQerUlG9Jd9KTB0v+SsiYRcuqmRuVpuJFX 9qG13TbAchsPHhvnrulKAn6AdmzTyyWLD6sXIgOxUAMymAtclyT7rcEfqGjwF/kATD7i DWmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WLKsNPDz; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ob15-20020a17090b390f00b00202b6975a96si17398934pjb.56.2022.09.15.08.45.25; Thu, 15 Sep 2022 08:45:39 -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=@intel.com header.s=Intel header.b=WLKsNPDz; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229644AbiIOPXx (ORCPT + 99 others); Thu, 15 Sep 2022 11:23:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230468AbiIOPXW (ORCPT ); Thu, 15 Sep 2022 11:23:22 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE6B81E3F2; Thu, 15 Sep 2022 08:22:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1663255360; x=1694791360; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=2mRF8w8hL1HBMWIlqV+SFW8gKa3TqIUcCL/Ln8KWTlo=; b=WLKsNPDzK7AXBjvTZpnJuif9g9Fg9x3PHxdrOWnoLElToOhTkXdWqk8y KrLTqd2tBQ4ttorZyhNNvLuqfHiSV8eIvyqq9MDDvZlgLke4UunkHpXlk XDn41iaJ3WyWI6Z8mCn9iGijUFOPrVRBApCasdtiYM0rX5RWmk3dEArmb MwkfW7At6qq+lyqxFiy5OyfSTx80fZwNbUNH4zXt6TftWwF+gLy4pCsVc FjXvEVj2JuRVpT1y4Dz9VZhM2I4yIH7C96JLDI3MDdSzzEkw7Ki3LhxJ3 4jTuGmq0EziPYJvEblIvUD8f6hzU8evUFWQwuXUpBrL8e2aay1403tOeK Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10471"; a="285785144" X-IronPort-AV: E=Sophos;i="5.93,318,1654585200"; d="scan'208";a="285785144" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Sep 2022 08:22:38 -0700 X-IronPort-AV: E=Sophos;i="5.93,318,1654585200"; d="scan'208";a="679560931" Received: from vasanth1-mobl.amr.corp.intel.com (HELO [10.255.231.111]) ([10.255.231.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Sep 2022 08:22:37 -0700 Message-ID: <208a847e-92eb-0590-b498-e34d59b1cf34@linux.intel.com> Date: Thu, 15 Sep 2022 08:22:37 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0 Thunderbird/91.11.0 Subject: Re: [PATCH v13 1/3] x86/tdx: Add TDX Guest attestation interface driver Content-Language: en-US To: Greg Kroah-Hartman Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Shuah Khan , "H . Peter Anvin" , "Kirill A . Shutemov" , Tony Luck , Andi Kleen , Kai Huang , Wander Lairson Costa , Isaku Yamahata , marcelo.cerri@canonical.com, tim.gardner@canonical.com, khalid.elmously@canonical.com, philip.cox@canonical.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org References: <20220909192708.1113126-1-sathyanarayanan.kuppuswamy@linux.intel.com> <20220909192708.1113126-2-sathyanarayanan.kuppuswamy@linux.intel.com> From: Sathyanarayanan Kuppuswamy In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE 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 Hi, On 9/15/22 4:09 AM, Greg Kroah-Hartman wrote: > On Fri, Sep 09, 2022 at 12:27:06PM -0700, Kuppuswamy Sathyanarayanan wrote: >> +static int __init tdx_guest_init(void) >> +{ >> + int ret; >> + >> + if (!cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) >> + return -EIO; >> + >> + ret = misc_register(&tdx_misc_dev); >> + if (ret) { >> + pr_err("misc device registration failed\n"); >> + return ret; >> + } >> + >> + return 0; >> +} >> +device_initcall(tdx_guest_init) > > As mentioned elsewhere, make this a normal module_init() format and only > load the module if the hardware is present. Don't just always be This feature needs to be enabled by default for all valid TDX guests. If TDX support is enabled and the guest is a valid TDX guest, the "X86 FEATURE TDX GUEST" feature flag will be set. So looking for "if(!cpu feature enabled(X86 FEATURE TDX GUEST))" will ensure that the interface is only created in a valid TDX guest. Even if we make it into a separate driver and use module init(), we'll have to use the same "if(!cpu feature enabled(X86 FEATURE TDX GUEST))" check to create and load the device. This approach was used in earlier versions of this driver. We later changed it to initcall because it appeared to be a roundabout approach. Let me know if you still suggest to use module_init() model. Following is the sample implementation with module_init() and this code will be compiled with CONFIG_INTEL_TDX_GUEST=y. +static struct platform_driver tdx_attest_driver = { + .probe = tdx_attest_probe, + .remove = tdx_attest_remove, + .driver = { + .name = DRIVER_NAME, + }, +}; + +static int __init tdx_attest_init(void) +{ + int ret; + + /* Make sure we are in a valid TDX platform */ + if (!cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return -EIO; + + ret = platform_driver_register(&tdx_attest_driver); + if (ret) { + pr_err("failed to register driver, err=%d\n", ret); + return ret; + } + + pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0); + if (IS_ERR(pdev)) { + ret = PTR_ERR(pdev); + pr_err("failed to allocate device, err=%d\n", ret); + platform_driver_unregister(&tdx_attest_driver); + return ret; + } + + return 0; +} + +static void __exit tdx_attest_exit(void) +{ + platform_device_unregister(pdev); + platform_driver_unregister(&tdx_attest_driver); +} + +module_init(tdx_attest_init); +module_exit(tdx_attest_exit); > built/loaded, that's not ok. > > thanks, > > greg k-h -- Sathyanarayanan Kuppuswamy Linux Kernel Developer