From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753240AbbC0Mbx (ORCPT ); Fri, 27 Mar 2015 08:31:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39469 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752690AbbC0Mbu (ORCPT ); Fri, 27 Mar 2015 08:31:50 -0400 Message-ID: <55154DB3.9000008@redhat.com> Date: Fri, 27 Mar 2015 13:31:47 +0100 From: Denys Vlasenko User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Ingo Molnar CC: Brian Gerst , Andy Lutomirski , Borislav Petkov , the arch/x86 maintainers , Linux Kernel Mailing List , Linus Torvalds Subject: Re: [PATCH] x86/asm/entry/64: better check for canonical address References: <1427373731-13056-1-git-send-email-dvlasenk@redhat.com> <20150327081141.GA9526@gmail.com> <551534B1.6090908@redhat.com> <20150327111738.GA8749@gmail.com> <20150327113430.GC14778@gmail.com> <551549AF.50808@redhat.com> <20150327121645.GC15631@gmail.com> In-Reply-To: <20150327121645.GC15631@gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/27/2015 01:16 PM, Ingo Molnar wrote: >>> Indeed, an IRET ought to be pretty cheap for same-ring interrupt >>> returns in any case. >> >> Unfortunately, it is not. Try attached program. >> >> On this CPU, 1 ns ~= 3 cycles. >> >> $ ./timing_test64 callret >> 10000 loops in 0.00008s = 7.87 nsec/loop for callret >> 100000 loops in 0.00076s = 7.56 nsec/loop for callret >> 1000000 loops in 0.00548s = 5.48 nsec/loop for callret >> 10000000 loops in 0.02882s = 2.88 nsec/loop for callret >> 100000000 loops in 0.18334s = 1.83 nsec/loop for callret >> 200000000 loops in 0.36051s = 1.80 nsec/loop for callret >> 400000000 loops in 0.71632s = 1.79 nsec/loop for callret >> >> Near call + near ret = 5 cycles >> >> $ ./timing_test64 lret >> 10000 loops in 0.00034s = 33.95 nsec/loop for lret >> 100000 loops in 0.00328s = 32.83 nsec/loop for lret >> 1000000 loops in 0.04541s = 45.41 nsec/loop for lret >> 10000000 loops in 0.32130s = 32.13 nsec/loop for lret >> 20000000 loops in 0.64191s = 32.10 nsec/loop for lret >> >> push my_cs + push next_label + far ret = ~90 cycles >> >> $ ./timing_test64 iret >> 10000 loops in 0.00344s = 343.90 nsec/loop for iret >> 100000 loops in 0.01890s = 188.97 nsec/loop for iret >> 1000000 loops in 0.08228s = 82.28 nsec/loop for iret >> 10000000 loops in 0.77910s = 77.91 nsec/loop for iret >> >> This is the "same-ring interrupt return". ~230 cycles! :( > > Ugh, that's really expensive! Why is that so? Same-ring irqs are > supposedly a lot simpler. Descriptor checks for restored CS and SS, checking canonical-ness of RIP, supporting "return to TSS" (flags.NT bit), "return to VM86" (flags.VM bit), complex logic around restoring RFLAGS ("don't allow CPL3 to be able to disable interrupts... ...unless their flags.IOPL is 3." Gasp) return to 16-bit code ("do not touch high 16 bits") All of this is a giant PITA to encode in microcode.