Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2929353pxb; Tue, 24 Aug 2021 10:50:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw22HndHBOSeI65HsAkJDM50iFnZ3ng3IpiAlrRq3rWVwtiFsyyA5rwhejRzKYlFyqMc5Tw X-Received: by 2002:a02:1083:: with SMTP id 125mr35302221jay.34.1629827424028; Tue, 24 Aug 2021 10:50:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629827424; cv=none; d=google.com; s=arc-20160816; b=Qsyw9FJBb83vBQaKUMZMUYFGx4npszLYk9C1EFLR1T1rrFUIE8al2W3o+cGhepWUnQ 5E57auYkpNJzJY73KLiH5VK9UVzZcoMlK/EihdKzkpIjwPbN3U+qOWBGskYfiGoScc3E LbOM4Bg2ULpXI6rDfgIVwCMo1BB/uWmC+y/MiR2B0Zgrf8SuvgxFQ4KgWkP9PGlkauX2 PnDA0iMARYn0G1pMNKJBj87jKxkOjTwsK7hPY9081Fe9Rlj4BrIFOsbBWvDhGE4QyKp6 a0EF1H/d3yD2DhnrhmPuq1/uTIOB5HO8MSKOSNFag0OPJ3Al6/yt9MnZ5svFYs5xhVOs d7xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=MQ6pXiB5RbqFmCzc7qkdRUQBBhu9mgPy2yl/Odr1B+Q=; b=VPbMZejrbdRD1Jx5sE5ei2CQEwetWf8QinkiEkHnbnE/+qhtryvvz/pbkmy5j8R0lB TYGS+D1oVdLJmSJKM48aDTTaPfhUVsAwrdCkP0eoDyrVeBl0tefOAPEL08Idro1suUDn kEtNZhPraHQ7evJJVmkHtXv0zEEyFBchbi9o2FkstyagNtWhph7EUOQnec1HcB7aZiZJ YDntf2czFhTZ39lq3GS0sHXN2cRmEiNVmCzj4xzCd4itlM2N4+d9XBaKZBU6QD9CIFJn tf1eMiK9BxOYnpMS4YSJfZmI/bzAHUgKsGHSOj4SCw+BLtNbcoFYzqqqQIh6a7Vy+eQU s1hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=arNOw650; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r13si1461809jac.86.2021.08.24.10.50.12; Tue, 24 Aug 2021 10:50:24 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=arNOw650; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241235AbhHXRsk (ORCPT + 99 others); Tue, 24 Aug 2021 13:48:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240962AbhHXRsg (ORCPT ); Tue, 24 Aug 2021 13:48:36 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 611F2C06122E for ; Tue, 24 Aug 2021 10:06:28 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id h1so8824472pjs.2 for ; Tue, 24 Aug 2021 10:06:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=MQ6pXiB5RbqFmCzc7qkdRUQBBhu9mgPy2yl/Odr1B+Q=; b=arNOw650gSkcbEsvJpHrW/uy+OQxY+AcLl5Euoqp5R6HG9rZbCmLJW2cKyaDzM/7uB Lhb0UrfOXBsXZAivsHGs71QGfyC/E9aTNBTFOGKbkZvQKnel45nvxEemnXHXdXsHQdUP 8mSAMY6/PSbk9MU31fO9543Fdgd/ebGS1cXSQjZxMJnx+jODpRA6J73VXcmftH2uV3HT ejiiuYab3GUhMcrrSqvoSpRV8/uzEUaK8kqokVNOZbUWkTEKYMLYwfssey1Gl/aUC5WD zsqvlEbSB1QCgCX3E8LgaO2rdPydvsviTTJtjPBVjCnMAlVlF30GMVAKexwoGJFFJWA5 zoNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=MQ6pXiB5RbqFmCzc7qkdRUQBBhu9mgPy2yl/Odr1B+Q=; b=UN+xKXHlNrXcrVjSmDuB/56wqhuQawMk/ZqyMtVV2f+HZ8ld3otCUXCp21SxvcOnN3 Ye/uZwHEa5L2QDzTNL7kMrUYFqb3LJ4ApF+J8RpQsjz/Vzkv48yA8bnexy7zYo19BHCC 3ZO+Z3qMbGIMUorZjosE11+mOGvGEI2aZXhCKSYpV6H2Ep86W4aNmrq8a3GrujCqw8jg olULV+GAWZySMq/fSFqB2/qslfyWJBRlGwbyPnO+xO0MWAGX3wmYuu7jL+kUUoZikykh Cx9TT/SRcPzV7W1OPWrX3cM5cezdPdmefvFSvSBcUjfyahxD3+2rRdFahbZrhjFquKx5 eY+g== X-Gm-Message-State: AOAM533tMJWZuMk9ul5OANQs7cyrF/RiErY3Q57J4f0aTZ57eo358TwD J7EAevHZHYidJjmwWuhKqBdZzw== X-Received: by 2002:a17:90a:8a84:: with SMTP id x4mr4605274pjn.72.1629824787648; Tue, 24 Aug 2021 10:06:27 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id t4sm9553131pfe.166.2021.08.24.10.06.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 10:06:27 -0700 (PDT) Date: Tue, 24 Aug 2021 17:06:21 +0000 From: Sean Christopherson To: Borislav Petkov Cc: Kuppuswamy Sathyanarayanan , 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 Subject: Re: [PATCH v5 08/12] x86/tdx: Add HLT support for TDX guest Message-ID: References: <20210804181329.2899708-1-sathyanarayanan.kuppuswamy@linux.intel.com> <20210804181329.2899708-9-sathyanarayanan.kuppuswamy@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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); > > + 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