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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E393C77B7A for ; Wed, 7 Jun 2023 15:22:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8E72E8E0003; Wed, 7 Jun 2023 11:22:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 897598E0002; Wed, 7 Jun 2023 11:22:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 75EFC8E0003; Wed, 7 Jun 2023 11:22:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 645E28E0002 for ; Wed, 7 Jun 2023 11:22:47 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 01548A033C for ; Wed, 7 Jun 2023 15:22:42 +0000 (UTC) X-FDA: 80876319006.14.98F09A0 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by imf02.hostedemail.com (Postfix) with ESMTP id EE9398001C for ; Wed, 7 Jun 2023 15:22:39 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Qy4wSPmT; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf02.hostedemail.com: domain of dave.hansen@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=dave.hansen@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686151360; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TC6enVl7pV3+C7E00D/2LXwpUxWW5Rrr9C/Je9HKqE4=; b=gnO2QSJyGbht2RPSBcKqsc/mzLOp0TYbhINfJJIpcyDX1oxqsqvRYtURkgs7fTDhafGW4A pbE0UZXgk7Cq5T1X/RJ+IeAfyGx3rGJBJ9S785jy6o3paXkn/+jMsW8dbtcM9FpFK+vlLG 1IqWfpBHyUv9lKDE0Je2/K4uvlxwyXw= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Qy4wSPmT; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf02.hostedemail.com: domain of dave.hansen@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=dave.hansen@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686151360; a=rsa-sha256; cv=none; b=J1v6pXeWYNDFT82IJePT9zXYVr8xLTN+0g7tC40jsgtWq72pudtrDnoq0ZaYxDsUEZBEXP 3nE4viKQy7AuINMtbgUCcRrJvnQZQY76e83R4E80DsPtLXwucOrdvZ5QDqqjt6tPAbjpeR yhJUiKPVrDby6m6OyCB7ZKrAHAsZPr4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686151360; x=1717687360; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=Ac2EGXwaf9hbH3WLYBdv8zMnn+CvdHzS452aCXzYo7k=; b=Qy4wSPmTNtexGvbYJH9ynvPf+q/jSN7UDdzmZ67SXG2sjpnCT6J4q372 hdzWBGmU5dYXd6KaLQJLr2HoSOKAToTC0hkBef9WJoWyTjAaw21Av38Y9 2Gzy0I4wPZLG6lfTLesYXJZRj+tGMvUhEG8l2/d1/G44dgG5uWW89u+e5 xyjIEntVjspZIYP17xwzU+xYmBVunl+jTkWiu0gFo7iJHe8obATFKeukj isnI5o0IauNGdlkbABxAwl9ZvGWBmLjF5Kygyos6VTI2X9ruEXwwrWGiM FHStrY9l7nPuhHCnygAbiYeUKooSERnhV4Kupowm3iIS1DkZPT2naXd3z w==; X-IronPort-AV: E=McAfee;i="6600,9927,10734"; a="341676654" X-IronPort-AV: E=Sophos;i="6.00,224,1681196400"; d="scan'208";a="341676654" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jun 2023 08:22:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10734"; a="822206808" X-IronPort-AV: E=Sophos;i="6.00,224,1681196400"; d="scan'208";a="822206808" Received: from vsmyers-mobl2.amr.corp.intel.com (HELO [10.212.146.233]) ([10.212.146.233]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jun 2023 08:22:36 -0700 Message-ID: Date: Wed, 7 Jun 2023 08:22:36 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH v11 07/20] x86/virt/tdx: Add skeleton to enable TDX on demand Content-Language: en-US To: Kai Huang , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: linux-mm@kvack.org, kirill.shutemov@linux.intel.com, tony.luck@intel.com, peterz@infradead.org, tglx@linutronix.de, seanjc@google.com, pbonzini@redhat.com, david@redhat.com, dan.j.williams@intel.com, rafael.j.wysocki@intel.com, ying.huang@intel.com, reinette.chatre@intel.com, len.brown@intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, chao.gao@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, bagasdotme@gmail.com, sagis@google.com, imammedo@redhat.com References: <21b3a45cb73b4e1917c1eba75b7769781a15aa14.1685887183.git.kai.huang@intel.com> From: Dave Hansen In-Reply-To: <21b3a45cb73b4e1917c1eba75b7769781a15aa14.1685887183.git.kai.huang@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: EE9398001C X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 8g1pf6tr4r68rysrhxy8instyptezeai X-HE-Tag: 1686151359-946821 X-HE-Meta: U2FsdGVkX1/dAlkcfPUutT8fPklxQRN2XeofTIGQKnIJZyBBZnHS2fMtjYMSSNKhrVjmyHjOre62pt0OBJU12cyYyyYyJubCefMnZ5FcsvLFdNY9yMdj10y+BShOJ/O19MiTTtLyWk+KzQ7r8psGHFSokSdSerbI9yd2uor+k9EhW0xDp14E2yivR4hVFxPkIZVhddAv6RV9WN0Is08dcuTXoETAtRXG2EDeZLy+UI/REUcRXWQFB+iLxq2qovwUMJejxvu7flLDNujECH7uWjizikVg69TCiCdMyHi3ixGN+vVofr/f7Zhw5M660fxfam/UylqU4JBk7kQ8c536DrKf06ID3KWCf0Nj+0JJuQpuURI3/sHxD1qUdx4yJzeoqFDPK4vCEZ/tOrCUmde0+xcIKW8UHlgFI5/Zt5IcDKYHJiqrQaBXyQc2JcOFCxRVVyS7iw6eZH19enxlgeVK/lJ8YLZbFW/w2D4lcyoP1LyjYaEldFVmRYe0S4fTl0yVmlTFI8KLyA/D4uSCFKEO2eQQU1DjfntaMuwj4ppYoS/HFcQIUaHYAWl2ocerwFUlGSvw6IU/pM+FkMMy0EvkLkNi2dkrCofflUgqrVW2dVKEm8TgDJuOCGuCmEWhUO2CnlYUTx1qQu9yy/fOZnRlZ4U5MIP28DS66if18llAu+fX/vpfVi9FYRATqmSvHveFIUYn5MUUAB4kubUNHtEreVZoBqPjVc44ka7eUehli0t/hPL3Qazw3++BGN9gZd5KqHmexR9GtMze/oRN06+lQhl7W+rEIILd9O+eGk/CmGpYY5AIX0dECN3JseeA73Yt162VrvgcQs/Xlbr4D0ZqbVp9JjdPquL7UddZ9QWcGkGFivOe6ZYCtwYEnfGjf4AccKqMdCAC91dP5x+05334IDfAzIF7m+WmOo0KNu5QX/GUwjQ9hbxn98ZIBebiPkrrZUmc2FgGMjx6s40S+vo nsJCASvZ BzuA5+Amup5FlCbV2klFtKbaU0rgriomir4r1Df6otugea3B62/eRQKmvPZHi2lbuJnTXeK7PVoMQla2Xherwddweys1VwoTsoYGXYU10sx8Zb+a29kmxm8sGYCD7EGuCGWmy0Rk/UziVNhX6XEHfN8zVsg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 6/4/23 07:27, Kai Huang wrote: ... > +static int try_init_module_global(void) > +{ > + unsigned long flags; > + int ret; > + > + /* > + * The TDX module global initialization only needs to be done > + * once on any cpu. > + */ > + raw_spin_lock_irqsave(&tdx_global_init_lock, flags); Why is this "raw_"? There's zero mention of it anywhere. > + if (tdx_global_init_status & TDX_GLOBAL_INIT_DONE) { > + ret = tdx_global_init_status & TDX_GLOBAL_INIT_FAILED ? > + -EINVAL : 0; > + goto out; > + } > + > + /* All '0's are just unused parameters. */ > + ret = seamcall(TDH_SYS_INIT, 0, 0, 0, 0, NULL, NULL); > + > + tdx_global_init_status = TDX_GLOBAL_INIT_DONE; > + if (ret) > + tdx_global_init_status |= TDX_GLOBAL_INIT_FAILED; > +out: > + raw_spin_unlock_irqrestore(&tdx_global_init_lock, flags); > + > + return ret; > +} > + > +/** > + * tdx_cpu_enable - Enable TDX on local cpu > + * > + * Do one-time TDX module per-cpu initialization SEAMCALL (and TDX module > + * global initialization SEAMCALL if not done) on local cpu to make this > + * cpu be ready to run any other SEAMCALLs. > + * > + * Note this function must be called when preemption is not possible > + * (i.e. via SMP call or in per-cpu thread). It is not IRQ safe either > + * (i.e. cannot be called in per-cpu thread and via SMP call from remote > + * cpu simultaneously). lockdep_assert_*() are your friends. Unlike comments, they will actually tell you if this goes wrong. > +int tdx_cpu_enable(void) > +{ > + unsigned int lp_status; > + int ret; > + > + if (!platform_tdx_enabled()) > + return -EINVAL; > + > + lp_status = __this_cpu_read(tdx_lp_init_status); > + > + /* Already done */ > + if (lp_status & TDX_LP_INIT_DONE) > + return lp_status & TDX_LP_INIT_FAILED ? -EINVAL : 0; > + > + /* > + * The TDX module global initialization is the very first step > + * to enable TDX. Need to do it first (if hasn't been done) > + * before doing the per-cpu initialization. > + */ > + ret = try_init_module_global(); > + > + /* > + * If the module global initialization failed, there's no point > + * to do the per-cpu initialization. Just mark it as done but > + * failed. > + */ > + if (ret) > + goto update_status; > + > + /* All '0's are just unused parameters */ > + ret = seamcall(TDH_SYS_LP_INIT, 0, 0, 0, 0, NULL, NULL); > + > +update_status: > + lp_status = TDX_LP_INIT_DONE; > + if (ret) > + lp_status |= TDX_LP_INIT_FAILED; > + > + this_cpu_write(tdx_lp_init_status, lp_status); > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(tdx_cpu_enable); You danced around it in the changelog, but the reason for the exports is not clear. > +static int init_tdx_module(void) > +{ > + /* > + * TODO: > + * > + * - Get TDX module information and TDX-capable memory regions. > + * - Build the list of TDX-usable memory regions. > + * - Construct a list of "TD Memory Regions" (TDMRs) to cover > + * all TDX-usable memory regions. > + * - Configure the TDMRs and the global KeyID to the TDX module. > + * - Configure the global KeyID on all packages. > + * - Initialize all TDMRs. > + * > + * Return error before all steps are done. > + */ > + return -EINVAL; > +} > + > +static int __tdx_enable(void) > +{ > + int ret; > + > + ret = init_tdx_module(); > + if (ret) { > + pr_err("TDX module initialization failed (%d)\n", ret); Have you actually gone any looked at how this pr_*()'s look? Won't they say: tdx: TDX module initialized Isn't that a _bit_ silly? Why not just say: pr_info("module initialized.\n");