Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2953932pxb; Tue, 24 Aug 2021 11:23:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfL8Q+lAT22ZTGm4QJLa0ZyH0D5GoCeOr+TYwBYVzl8OVH+j/iH1V4oFN7UmO83XmqVYR3 X-Received: by 2002:a50:ec10:: with SMTP id g16mr21638739edr.35.1629829430508; Tue, 24 Aug 2021 11:23:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629829430; cv=none; d=google.com; s=arc-20160816; b=CNqlfwSurZ/2q6XrPuxsbpMxYeiVAxIOpIRd8tIc3y8ORI4M9K1SGfRWfr+Uz/xXta gE5QfJZh/kBwx8EggET5GKGnAJMj0VS55M8lIyZbFNbfOWpCIA9dwd7c//4lfmrNxTIl b6KRt9Q6z2NO0TRInn4MoP/lguBByNitdrE7vPGZfVkieXJ2oqVkV7ObNCJbFHJRpxmd L6JAa3N7lc0SvVAVhvgs5XyCrA++qAhj1kNXlq14a+/8Tjo6w6lbmGGwYHmctShc+Mmw cdn/wc9nB58iBfhl6jajd4hvCbiPVvSsMaUE6T4bX2Sccx/Ufx4uh47h016cSIWobJT2 Mcbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=uc9qemTGFL4vYaC9vr3C8q6zDYXxeCuW7Rx+VcoE7GQ=; b=coVjDhT6mRmDudTDp5nrYrGUxX/cyLaMTbwIS5eyPcgOuI5j5lE1Fj4MquqlUiT6Rf ks6LRDplyx/lYC1nn2PYVmheNDEp/ZzbsUVk9Z9YEWy/k5q1VFIAvjg2JfzjxoARMNZK 3buST9RA7KpEjoMDAR2b3qppx6xCk9DVGp0b3SAKQZTGcsksAgA9JflhmRPr+L+mRHot fHc9pTzovdjX2NbVPpWH9nvk6CPitx6trtMx1OxrEBgfW0S9kHCUbsI9GAGwA799Wgwt 3n8Q83EmGYJ//BcfBfGXH+3FbIyqbelm+IDwrxvmj5FmvIor6VbzRNWzDNgHa9A1UGGn 2X1Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id da27si3432726edb.317.2021.08.24.11.23.26; Tue, 24 Aug 2021 11:23:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232637AbhHXSTg (ORCPT + 99 others); Tue, 24 Aug 2021 14:19:36 -0400 Received: from mga02.intel.com ([134.134.136.20]:17853 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229548AbhHXSTg (ORCPT ); Tue, 24 Aug 2021 14:19:36 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10086"; a="204570173" X-IronPort-AV: E=Sophos;i="5.84,347,1620716400"; d="scan'208";a="204570173" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2021 11:18:51 -0700 X-IronPort-AV: E=Sophos;i="5.84,347,1620716400"; d="scan'208";a="597672338" Received: from ydevadig-mobl.amr.corp.intel.com (HELO skuppusw-mobl5.amr.corp.intel.com) ([10.209.137.104]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2021 11:18:50 -0700 Subject: Re: [PATCH v5 08/12] x86/tdx: Add HLT support for TDX guest To: Sean Christopherson , Borislav Petkov Cc: Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Andy Lutomirski , Peter H Anvin , Dave Hansen , Tony Luck , Dan Williams , Andi Kleen , Kirill Shutemov , Kuppuswamy Sathyanarayanan , x86@kernel.org, linux-kernel@vger.kernel.org References: <20210804181329.2899708-1-sathyanarayanan.kuppuswamy@linux.intel.com> <20210804181329.2899708-9-sathyanarayanan.kuppuswamy@linux.intel.com> From: "Kuppuswamy, Sathyanarayanan" Message-ID: Date: Tue, 24 Aug 2021 11:18:48 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/24/21 10:06 AM, Sean Christopherson wrote: > On Tue, Aug 24, 2021, Borislav Petkov wrote: >> On Wed, Aug 04, 2021 at 11:13:25AM -0700, Kuppuswamy Sathyanarayanan wrote: >>> +static __cpuidle void tdg_safe_halt(void) >>> +{ >>> + u64 ret; >>> + >>> + /* >>> + * Enable interrupts next to the TDVMCALL to avoid >>> + * performance degradation. >> >> That comment needs some more love to say exactly what the problem is. > > LOL, I guess hanging the vCPU counts as degraded performance. But this comment > can and should go away entirely... > >>> + */ >>> + local_irq_enable(); > > ...because this is broken. It's also disturbing because it suggests that these > patches are not being tested. Sorry, some how we missed this issue before our submission. We do usual boot test before submission. Since this fix does not block the boot process, it did not get caught. But we already found this in full functional testing and also fixed it in github tree. I will remove this in next submission. > > The STI _must_ immediately precede TDCALL, and it _must_ execute with interrupts > disabled. The whole point of the STI blocking shadow is to ensure interrupts are > blocked until _after_ the HLT completes so that a wake event is not recongized > before the HLT, in which case the vCPU will get stuck in HLT because its wake > event alreadyfired. Enabling IRQs well before the TDCALL defeats the purpose of > the STI dance in __tdx_hypercall(). > > There's even a massive comment in __tdx_hypercall() explaining all this... > >>> + >>> + /* IRQ is enabled, So set R12 as 0 */ > > It would be helpful to use local variables to document what's up, e.g. > > const bool irqs_enabled = true; > const bool do_sti = true; > > ret = _tdx_hypercall(EXIT_REASON_HLT, irqs_enabled0, 0, 0, do_sti, NULL); Ok. I can follow your suggestion in next submission. > >>> + ret = _tdx_hypercall(EXIT_REASON_HLT, 0, 0, 0, 1, NULL); >>> + >>> + /* It should never fail */ >>> + BUG_ON(ret); >>> +} >> >> -- >> Regards/Gruss, >> Boris. >> >> https://people.kernel.org/tglx/notes-about-netiquette -- Sathyanarayanan Kuppuswamy Linux Kernel Developer