Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2927408pxb; Tue, 24 Aug 2021 10:48:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgUSuI6XueL7Crn8ZE4wohRB23hf/wGU0c7ph2E0FzJhylqtr68FFUxATsg4/9PNaQPyKs X-Received: by 2002:a17:907:92c:: with SMTP id au12mr6936075ejc.523.1629827311782; Tue, 24 Aug 2021 10:48:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629827311; cv=none; d=google.com; s=arc-20160816; b=zSD8CfjbKpGY/I3xdfjcVnLMoKmV1BUOrdDCOwD3GvMNzAkSs/B0d/UtLTd19GUu74 4mqbvYFhpjXCwz+0NFLiHIFU2KDNMah1xipGW2BfAVez39Xw2Sf87cNTGsQ08km/GrWV 80ir/0pjFu9O04lxGfPR81Uh+V4yh2X8wM1EEYanabcf7qiWHpOPnSarLUCHJTSDfqM3 sHTUgPxGyzC6qxyuwzGMwFh/EqymGoBeZ+6aiCwlM//zd3bQlVA/vvUR8fqTX7B3X0w2 N5TAE5REwuCltGkuGOKz91jJVFsrZ8xmRyby4ekVg22C+KTZObrrzMcvDNxqHrTf/FgD B6ug== 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=qShZRrzjjeqrXkEDa2CcaImpQNvC7HvyJb2K96tiEao=; b=bnhVJ/rGyaY2BcEeoWyh6VzhhANY/WnLAvw8PjmHFE81KU40JMoGbn90lmekwdjleb qngJ7hIdTIsI9x3kJDWGoKeUa6uJuNo4ehVq/VoinCXMeD1/dl4+W306pW+QF9tB9nZr zBp37/Gbu1pvHk7uRrIGcPsd/mlocvnqoX3z2e8Jj/KC+Sd18cKffQVrh6pZX0ZgX25l FolD5WUvf2QHiQ7kgEl6/Jr8UhRLzi7kk3udV5xFojDruB23T7F24T0RSxMZDKXuSVlv zam82JjRYvYW9gpOO4Im1MA9+jaAL46MOkIT/jz+YJActmsJlH2U/DYz0Li65sS/ChyY UdrQ== 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 f16si19240093edf.596.2021.08.24.10.48.07; Tue, 24 Aug 2021 10:48:31 -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 S241716AbhHXRrQ (ORCPT + 99 others); Tue, 24 Aug 2021 13:47:16 -0400 Received: from mga17.intel.com ([192.55.52.151]:20523 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241444AbhHXRqx (ORCPT ); Tue, 24 Aug 2021 13:46:53 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10086"; a="197609725" X-IronPort-AV: E=Sophos;i="5.84,347,1620716400"; d="scan'208";a="197609725" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2021 10:35:33 -0700 X-IronPort-AV: E=Sophos;i="5.84,347,1620716400"; d="scan'208";a="597659443" 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 10:35:33 -0700 Subject: Re: [PATCH v5 08/12] x86/tdx: Add HLT support for TDX guest To: Borislav Petkov Cc: Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Andy Lutomirski , Peter H Anvin , Dave Hansen , Tony Luck , Dan Williams , Andi Kleen , Kirill Shutemov , Sean Christopherson , 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 10:35:33 -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 9:10 AM, Borislav Petkov wrote: > On Wed, Aug 04, 2021 at 11:13:25AM -0700, Kuppuswamy Sathyanarayanan wrote: >> @@ -240,6 +243,32 @@ 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. > > <-- newline in the comment here for better readability. Ok. I will add it in next version. > >> There leads to significant difference in > > "There leads..." ? Will fix this in next version. "This leads" > >> + * 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, > > s/sti/STI/g will fix this in next version. > >> + * 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 >> + sti >> +skip_sti: >> tdcall > > ... > >> +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. It is a bug in this submission. After adding STI fix, this local_irq_enable() had to be removed. Somehow I have missed to do it. I will fix this in next version. > >> + */ >> + local_irq_enable(); >> + >> + /* IRQ is enabled, So set R12 as 0 */ >> + ret = _tdx_hypercall(EXIT_REASON_HLT, 0, 0, 0, 1, NULL); >> + >> + /* It should never fail */ >> + BUG_ON(ret); >> +} > -- Sathyanarayanan Kuppuswamy Linux Kernel Developer