Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp2585912pxb; Fri, 8 Oct 2021 10:42:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyw76SRa2jufjXbQVIOjKahYtuIJyMaX7JXvDvN5RkMCSNNAwh7plAizsNjkl1oJJLqhmle X-Received: by 2002:a17:906:16d0:: with SMTP id t16mr5755038ejd.199.1633714943854; Fri, 08 Oct 2021 10:42:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633714943; cv=none; d=google.com; s=arc-20160816; b=lwTdZF2e+S0iV3rMgLH/RUlD8W78zklfMekuJpiZy5/z/TxiP+rFX/xg49ppdM/G+O ybLIv5BCgOaIgPNuBYVezdNi71JOR7O46WVZbyOGADHBkl4P6+AER3HhpZ02px1rbXaJ ACv5p0nFXYfj8VVNOCGBj8yiFUVkHjredGsTilDgK+QY6sXVnKgOqDhKrmH+ienHhcRn 5JD8QLteiYljVfzWIPrEvqK/nSFU/M0eUuapbYn//cinYnRyceOlkeRlHKVRIUcRERcF na+f1subjZbartK6muVcx4jKLAo0gYNCQ82RYPBdtgqZb6Qz9EwQLSJyyKHKEpyda/Cx nMuA== 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=if4SADJ9iZXvQsMXqMT6BH4xmDNgY7LEbXso5GpgQ+A=; b=fBvNJlNxhd6tijj3EXfdgzHPGBJujTgpb+LHi6jxxSYgcbjQGUGn8StJaXkWSpkGKm 4qN2G9o/Sroxz38g4JaRuZNdY12CHolUC6Jq+CYq6Uxah0LIlWLuRlMlsPPxoQX+ZOFn /VEGvcJhAWKjKsC95Mjtel4SamuY0jVyUVzdY//qdelbE+XEAdPMIJ0imLGJhsOek853 SgXxlJ0QvVSIif8feIP60/gj/vSOgA2+WLALeBFXByRRvyVLpgzNkxnKdjBvXFTrmrFA OQsr43D06CwfGo+EW4+Vhn1lboCwRlJGJQi9kyVW0KusJrjZL9B5E7sqAi9HINXO+Xy7 LRfw== 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 de1si3710945edb.375.2021.10.08.10.41.59; Fri, 08 Oct 2021 10:42:23 -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 S231245AbhJHRkW (ORCPT + 99 others); Fri, 8 Oct 2021 13:40:22 -0400 Received: from mga17.intel.com ([192.55.52.151]:49065 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231217AbhJHRkV (ORCPT ); Fri, 8 Oct 2021 13:40:21 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10131"; a="207365699" X-IronPort-AV: E=Sophos;i="5.85,358,1624345200"; d="scan'208";a="207365699" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2021 10:38:25 -0700 X-IronPort-AV: E=Sophos;i="5.85,358,1624345200"; d="scan'208";a="479056181" Received: from jmapas-mobl1.amr.corp.intel.com (HELO skuppusw-mobl5.amr.corp.intel.com) ([10.209.3.48]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2021 10:38:24 -0700 Subject: Re: [PATCH v8 07/11] x86/tdx: Add HLT support for TDX guest To: Borislav Petkov Cc: Thomas Gleixner , Ingo Molnar , x86@kernel.org, Paolo Bonzini , David Hildenbrand , Andrea Arcangeli , Josh Poimboeuf , Juergen Gross , Deep Shah , VMware Inc , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Peter H Anvin , Dave Hansen , Tony Luck , Dan Williams , Andi Kleen , Kirill Shutemov , Sean Christopherson , Kuppuswamy Sathyanarayanan , linux-kernel@vger.kernel.org References: <20211005025205.1784480-1-sathyanarayanan.kuppuswamy@linux.intel.com> <20211005025205.1784480-8-sathyanarayanan.kuppuswamy@linux.intel.com> From: "Kuppuswamy, Sathyanarayanan" Message-ID: Date: Fri, 8 Oct 2021 10:38:22 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0 Thunderbird/78.13.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 10/8/21 10:31 AM, Borislav Petkov wrote: > On Mon, Oct 04, 2021 at 07:52:01PM -0700, Kuppuswamy Sathyanarayanan wrote: >> @@ -240,6 +243,33 @@ SYM_FUNC_START(__tdx_hypercall) >> >> movl $TDVMCALL_EXPOSE_REGS_MASK, %ecx >> >> + /* >> + * For the idle loop STI needs to be called directly before >> + * the TDCALL that enters idle (EXIT_REASON_HLT case). STI >> + * enables interrupts only one instruction later. If there >> + * are any instructions between the STI and the TDCALL for >> + * HLT then an interrupt could happen in that time, but the >> + * code would go back to sleep afterwards, which can cause >> + * longer delays. >> + * >> + * This leads to significant difference in network performance >> + * benchmarks. So add a special case for EXIT_REASON_HLT to >> + * trigger STI before TDCALL. But this change is not required >> + * for all HLT cases. So use R15 register value to identify the >> + * case which needs STI. So, if R11 is EXIT_REASON_HLT and R15 >> + * is 1, then call STI before TDCALL instruction. Note that R15 >> + * register is not required by TDCALL ABI when triggering the >> + * hypercall for EXIT_REASON_HLT case. So use it in software to >> + * select the STI case. >> + */ >> + cmpl $EXIT_REASON_HLT, %r11d >> + jne skip_sti >> + cmpl $1, %r15d >> + jne skip_sti >> + /* Set R15 register to 0, it is unused in EXIT_REASON_HLT case */ >> + xor %r15, %r15 > > Then you don't need to clear it either, right? Yes. As per ABI, I don't need to clear it. It will not be used by VMM. But since that register content is shared with VMM, I tried to keep the unused register values to '0' (consistent with other hypercall use cases). I am fine with removing it if you think it is unnecessary. > >> + sti >> +skip_sti: >> tdcall >> >> /* Restore output pointer to R9 */ > > ... > >> +static __cpuidle void tdx_halt(void) >> +{ >> + const bool irq_disabled = irqs_disabled(); >> + const bool do_sti = false; >> + >> + /* >> + * Non safe halt is mainly used in CPU off-lining >> + * and the guest will stay in halt state. So, >> + * STI instruction call is not required (set >> + * do_sti as false). >> + */ > > Just like you've done below, put the comment over the variable assignment: > > /* > * Non safe halt is mainly used in CPU offlining and the guest will stay in halt > * state. So, STI instruction call is not required. > */ > const bool do_sti = false; Will move it above in next version. > > >> + _tdx_halt(irq_disabled, do_sti); >> +} >> + >> +static __cpuidle void tdx_safe_halt(void) >> +{ >> + /* >> + * Since STI instruction will be called in __tdx_hypercall() >> + * set irq_disabled as false. >> + */ >> + const bool irq_disabled = false; >> + const bool do_sti = true; >> + >> + _tdx_halt(irq_disabled, do_sti); >> +} >> + >> unsigned long tdx_get_ve_info(struct ve_info *ve) >> { >> struct tdx_module_output out = {0}; > -- Sathyanarayanan Kuppuswamy Linux Kernel Developer