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 AA2ADEB64D7 for ; Wed, 28 Jun 2023 13:09:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 197208D0005; Wed, 28 Jun 2023 09:09:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 146728D0001; Wed, 28 Jun 2023 09:09:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 00E128D0005; Wed, 28 Jun 2023 09:09:06 -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 E2A2E8D0001 for ; Wed, 28 Jun 2023 09:09:06 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A685640AA6 for ; Wed, 28 Jun 2023 13:09:06 +0000 (UTC) X-FDA: 80952187092.01.EA5D4C8 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf03.hostedemail.com (Postfix) with ESMTP id AD60B20068 for ; Wed, 28 Jun 2023 13:08:34 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=PDi20WW3; spf=none (imf03.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687957715; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/wef/ORaePi5rraYqwEm/o3Nv/tMCObZmjkD+rQugnw=; b=NETjnmJr+lqeiq7RHBpOwp5a0wzJeby3fQC2UUcNat+kB2xRICF/LmLzqY9AaDT4R33sfb mM3muIVloc3745NlGkN52xkzw77WmOARgAxiVDEBExr4Alf7yel4gbkN9YrKaeaREV/hiJ hoTM0LOvpZoyvMRSS6/4m/H/1prom8o= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=PDi20WW3; spf=none (imf03.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687957715; a=rsa-sha256; cv=none; b=IAgLvWusVSUOQWYIz7I3nXPuynF4/HjJRl/je3MZ9frKN+IqgSg1+/7MrvcIn+3JVi5LD9 zXJ55rXzJEe+S/NnxMqIzJxHiU5c3mglPeM13R+PwMU/TTNUf+TORKwqA6MRUhbQ96rhAR t+2xLbzooXxr1tLrd5/h8p6ke5WqKbY= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=/wef/ORaePi5rraYqwEm/o3Nv/tMCObZmjkD+rQugnw=; b=PDi20WW3Y1qeIx2VS+PtiQ/riF a1d08NY4ejV640VZefmowE9KddBTfmHnYsiApZPVzGglYLPKeXQOlBRLiql9G8ofhJEBwY5+H2VZf y2cGKzXwgshcigUPgBZQoiFfuSD98Q0I23DrmseJ0k5Oz0lfXp56xozo0UQ9QKvdWMh3rvKW8VqwF 5+Cb+ojDCAlHi6sgYBj4O6K0XMU1KIVtgZ2+qA07W4WXy+PlFmCvzssazUEWK1Ealz9JQ2zfBC7aS X7/a115gTN0JPsxvPFIi9GSSWpxAR9HNgThP/IVFUctW/eqMJuiZv8iiJgd0Nu4Am0OnksPDIY9WP hF9YjD4A==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qEUuF-003nSs-Sq; Wed, 28 Jun 2023 13:08:23 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 17BF33002C5; Wed, 28 Jun 2023 15:08:23 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id F40A527F62BA3; Wed, 28 Jun 2023 15:08:22 +0200 (CEST) Date: Wed, 28 Jun 2023 15:08:22 +0200 From: Peter Zijlstra To: Kai Huang Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, dave.hansen@intel.com, kirill.shutemov@linux.intel.com, tony.luck@intel.com, tglx@linutronix.de, bp@alien8.de, mingo@redhat.com, hpa@zytor.com, seanjc@google.com, pbonzini@redhat.com, david@redhat.com, dan.j.williams@intel.com, rafael.j.wysocki@intel.com, ashok.raj@intel.com, reinette.chatre@intel.com, len.brown@intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, ying.huang@intel.com, chao.gao@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, nik.borisov@suse.com, bagasdotme@gmail.com, sagis@google.com, imammedo@redhat.com Subject: Re: [PATCH v12 07/22] x86/virt/tdx: Add skeleton to enable TDX on demand Message-ID: <20230628130822.GD2438817@hirez.programming.kicks-ass.net> References: <104d324cd68b12e14722ee5d85a660cccccd8892.1687784645.git.kai.huang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <104d324cd68b12e14722ee5d85a660cccccd8892.1687784645.git.kai.huang@intel.com> X-Rspamd-Queue-Id: AD60B20068 X-Rspam-User: X-Stat-Signature: 4gojoe66mg5xjp7scfctuxfcfb9cgymj X-Rspamd-Server: rspam01 X-HE-Tag: 1687957714-580512 X-HE-Meta: U2FsdGVkX1+682T3LE0FVwoqZh0HqH70zVGkuCOoyvn+3y/mKbQqoPnvjXC33brrzQk8ifOBNu/6eIGsZF96W0hZNk1DJVOD+wPpY8Iz+G9Q0ztWfk2eIXp02yptcwt1/UdIm2dL1qcxTR+etRxQDuF5ofU4zqkMyix9oGLYV+d/D5UGC1ofQvpPcVxvCh6hyGzQvc11FhyzG88+whqMh9YGxkvRnAEbw7qjIzQzdagXYuDdp4h2zbT5zfhizF8owlklPEUyU/41zZIq2ICivKn94NkxG5atzNXWxJy+qdD+T2M6PWHBlCt2s+FnUbsniLX1AVWzbf9rAN8xfjKaeEQGsNOBPWbslnu3EZYNH8V1wRZL11CmbVujutIVS0lYkavnj+ZyMuhPZwy/vMov9sKeYjicZM2lww8p4NkrtQaLRwQOzov2l1d1JXLYf/0350QcRbqsrkVEnWL/IIf7hjYNJj+Alxvr8QDc+EoB4YZn8aZF7pkYAWz3mNgE5HACsYUhUdkMRr1Gfa290IS21ILeQqhyeoertEtAf+8/b2PXppe/obXjJSZsm1YNrQ09EahizqAjSwVL+eziWxewAUCdUVJYso9T2jovGjBOxYRmcGq5kq15vztuzDz7hos7o412IhnJbStftse7fHmb1NKxvPVJFaMQJnk5ro6dN+f8HquM/kGNMOPOBwIhZZFH1L7IiLZ5+TKsC4BdSJ2x8preoMAYEzEWdbKmlzk+G/gqmMyCmLjsD1+xoehR1JL2RtCJVXSa4vA6Ka5ZgR+Am5TER4odEqITufcawi9+mU2aD4ujZQaU3vGgLU40UKAWbo7gwdSyUxNQ80X8rkym55gIPZiftbfre2Du2/IwHWiU7NCqZqKc1K6ZqH+FKk2UJb4513lGQwMcQIDmSJp1WE07t71P6PYakXI7RwicK5MjL42aF/4f8iv1BxSrzwat5Yv7KKfaCiNXmsdQl2L FJ1h7TEx BzrQQWwjBLlx3gxDMvRmOXqTZoQhSISBWF+Mzfa4chfkg5V7E+xzDGXV4tS0cClX21ELrmaedPxD/zP31NcRWJ4Xh0HuHxsZJZScgKcIQOM/389gbhq1jyxuaHRud3tG4og1+KWmFQN1gcgw= 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 Tue, Jun 27, 2023 at 02:12:37AM +1200, Kai Huang wrote: > +/* > + * Do the module global initialization if not done yet. > + * It's always called with interrupts and preemption disabled. > + */ > +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); > + > + if (tdx_global_initialized) { > + ret = 0; > + goto out; > + } > + > + /* All '0's are just unused parameters. */ > + ret = seamcall(TDH_SYS_INIT, 0, 0, 0, 0, NULL, NULL); > + if (!ret) > + tdx_global_initialized = true; > +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. > + * > + * Call this function with preemption disabled. > + * > + * Return 0 on success, otherwise errors. > + */ > +int tdx_cpu_enable(void) > +{ > + int ret; > + > + if (!platform_tdx_enabled()) > + return -ENODEV; > + > + lockdep_assert_preemption_disabled(); > + > + /* Already done */ > + if (__this_cpu_read(tdx_lp_initialized)) > + return 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 the per-cpu initialization. > + */ > + ret = try_init_module_global(); > + if (ret) > + return ret; > + > + /* All '0's are just unused parameters */ > + ret = seamcall(TDH_SYS_LP_INIT, 0, 0, 0, 0, NULL, NULL); > + if (ret) > + return ret; And here you do *NOT* have IRQs disabled... so an IRQ can come in here and do the above again. I suspect that's a completely insane thing to have happen, but the way the code is written does not tell me this and might even suggest I should worry about it, per the above thing actually disabling IRQs. > + > + __this_cpu_write(tdx_lp_initialized, true); > + > + return 0; > +}