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 55953C433FE for ; Tue, 22 Nov 2022 19:24:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E3AAD6B0071; Tue, 22 Nov 2022 14:24:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DC45F8E0002; Tue, 22 Nov 2022 14:24:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C3D4A8E0001; Tue, 22 Nov 2022 14:24:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id AFF1F6B0071 for ; Tue, 22 Nov 2022 14:24:57 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 6F059AB1E1 for ; Tue, 22 Nov 2022 19:24:57 +0000 (UTC) X-FDA: 80162055834.19.A1E9C5F Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by imf05.hostedemail.com (Postfix) with ESMTP id D046A100006 for ; Tue, 22 Nov 2022 19:24:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669145095; x=1700681095; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=OKm7UJo5SyFqT5YmYkDdQ5nt3mpnIZkSEfunTTVs3qE=; b=IcHV/HhBduTuR4agR4gn8MMrTc4zebjYrp0pxY2k8lXq7Yir/QzV6eDY MtydoT/+tU0YR6Dg4EYI1Sb3KZ7SJDD3aBOAQbIg45FjCrpxtomAWlyhZ TIosFU66XyOaVUSZ8a/DsablBYlITIlquMUnTMnfD+wznlPvGK/pRUm8y soY6sdalIxVq7VWDaJV3FFbP9alw0p89eIm3zp1DCEQku+1lqMtoSMyd9 snFUXQ7vJN+kABlQc1A4SoItgaY1J2pGoQ7mf5YzEImNrfqeO40L6Zq+I dgdpr2p/rEwnDzRLfs3BbMp+p3wYxj5YweIoSv4oT1aULq3BAuXLMTZmp w==; X-IronPort-AV: E=McAfee;i="6500,9779,10539"; a="340769543" X-IronPort-AV: E=Sophos;i="5.96,184,1665471600"; d="scan'208";a="340769543" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Nov 2022 11:24:53 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10539"; a="641525771" X-IronPort-AV: E=Sophos;i="5.96,184,1665471600"; d="scan'208";a="641525771" Received: from coltsavx-mobl1.amr.corp.intel.com (HELO [10.255.0.114]) ([10.255.0.114]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Nov 2022 11:24:47 -0800 Message-ID: Date: Tue, 22 Nov 2022 11:24:48 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH v7 06/20] x86/virt/tdx: Shut down TDX module in case of error Content-Language: en-US To: Peter Zijlstra Cc: Kai Huang , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, seanjc@google.com, pbonzini@redhat.com, dan.j.williams@intel.com, rafael.j.wysocki@intel.com, kirill.shutemov@linux.intel.com, ying.huang@intel.com, reinette.chatre@intel.com, len.brown@intel.com, tony.luck@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: <48505089b645019a734d85c2c29f3c8ae2dbd6bd.1668988357.git.kai.huang@intel.com> <52b2be9b-defd-63ce-4cb2-96cd624a95a6@intel.com> From: Dave Hansen In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669145096; a=rsa-sha256; cv=none; b=uAokwQPjb0dDue28ncTNtQqBf+rHW4VNJT415TCgsDIdesWnyGFWniSpA4pfU6ujykpRmf jm2RGc6jDK8IZbeMXWQWFDnMZrc9DpRNuU6uJJvoZLtSx9yqLQnJqqwTZT57hiOdIz7tjW pu5rOh68odLlExtj4eJg80ZHFv+FjQk= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b="IcHV/HhB"; spf=pass (imf05.hostedemail.com: domain of dave.hansen@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=dave.hansen@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669145096; 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=TQ2oYOCkAVOLLBk0Jc0TMRAsnF9lAP6pDmS4odvrolk=; b=ydejbwN84miwMiG6MwcN2cuAitGmIIjFtTlSBZlR1knRRPJvcJp8iHWNP2uVS+r2ZrqpVi czhYKkXsL6nxbM02NQhUXRkGu5a89CkCnp0QxlbeH5LM7Lwk6CUD79VEyCCv/m0Dknrp/q zeAS8AKwjCqzAHqVDVJb11VdyAHZLWI= X-Stat-Signature: tb48jpsch6zya8aq7rxo7pcxurpirmkh X-Rspamd-Queue-Id: D046A100006 X-Rspam-User: Authentication-Results: imf05.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b="IcHV/HhB"; spf=pass (imf05.hostedemail.com: domain of dave.hansen@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=dave.hansen@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspamd-Server: rspam02 X-HE-Tag: 1669145095-672166 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 11/22/22 11:13, Peter Zijlstra wrote: > On Tue, Nov 22, 2022 at 07:14:14AM -0800, Dave Hansen wrote: >> On 11/22/22 01:13, Peter Zijlstra wrote: >>> On Mon, Nov 21, 2022 at 01:26:28PM +1300, Kai Huang wrote: >>>> +/* >>>> + * Call the SEAMCALL on all online CPUs concurrently. Caller to check >>>> + * @sc->err to determine whether any SEAMCALL failed on any cpu. >>>> + */ >>>> +static void seamcall_on_each_cpu(struct seamcall_ctx *sc) >>>> +{ >>>> + on_each_cpu(seamcall_smp_call_function, sc, true); >>>> +} >>> >>> Suppose the user has NOHZ_FULL configured, and is already running >>> userspace that will terminate on interrupt (this is desired feature for >>> NOHZ_FULL), guess how happy they'll be if someone, on another parition, >>> manages to tickle this TDX gunk? >> >> Yeah, they'll be none too happy. >> >> But, what do we do? > > Not intialize TDX on busy NOHZ_FULL cpus and hard-limit the cpumask of > all TDX using tasks. I don't think that works. As I mentioned to Thomas elsewhere, you don't just need to initialize TDX on the CPUs where it is used. Before the module will start working you need to initialize it on *all* the CPUs it knows about. The module itself has a little counter where it tracks this and will refuse to start being useful until it gets called thoroughly enough. >> There are technical solutions like detecting if NOHZ_FULL is in play and >> refusing to initialize TDX. There are also non-technical solutions like >> telling folks in the documentation that they better modprobe kvm early >> if they want to do TDX, or their NOHZ_FULL apps will pay. > > Surely modprobe kvm isn't the point where TDX gets loaded? Because > that's on boot for everybody due to all the auto-probing nonsense. > > I was expecting TDX to not get initialized until the first TDX using KVM > instance is created. Am I wrong? I went looking for it in this series to prove you wrong. I failed. :) tdx_enable() is buried in here somewhere: > https://lore.kernel.org/lkml/CAAhR5DFrwP+5K8MOxz5YK7jYShhaK4A+2h1Pi31U_9+Z+cz-0A@mail.gmail.com/T/ I don't have the patience to dig it out today, so I guess we'll have Kai tell us. >> We could also force the TDX module to be loaded early in boot before >> NOHZ_FULL is in play, but that would waste memory on TDX metadata even >> if TDX is never used. > > I'm thikning it makes sense to have a tdx={off,on-demand,force} toggle > anyway. Yep, that makes total sense. Kai had one in an earlier version but I made him throw it out because it wasn't *strictly* required and this set is fat enough. >> How do NOHZ_FULL folks deal with late microcode updates, for example? >> Those are roughly equally disruptive to all CPUs. > > I imagine they don't do that -- in fact I would recommend we make the > whole late loading thing mutually exclusive with nohz_full; can't have > both. So, if we just use schedule_on_cpu() for now and have the TDX code wait, will a NOHZ_FULL task just block the schedule_on_cpu() indefinitely? That doesn't seem like _horrible_ behavior to start off with for a minimal series.