Received: by 10.223.185.116 with SMTP id b49csp1393470wrg; Wed, 14 Feb 2018 16:50:11 -0800 (PST) X-Google-Smtp-Source: AH8x2261LXe//DzXFE8EvH74oASTRhNMl+1o9ksQg3P0AcsXzRm9VDWRjocp/AE3zUUAnXzhmMs2 X-Received: by 10.99.131.198 with SMTP id h189mr702456pge.25.1518655811792; Wed, 14 Feb 2018 16:50:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518655811; cv=none; d=google.com; s=arc-20160816; b=ytYvKDuUkl0MoYFUpSkjwu2/2Vp70ZdNelCSFTgLoEES7lHHp5Di/hBO7UdGFiQeV0 ZiXkI+c23UfV6wOFHvyoj3zePmW9AZ9pM49IIIG+bjrM24klREp6IZlzSHD6t941ePav +YekNKpXCDwiI88cZjHUkUtf5lI5PLa9cSbmXOOlcWKoRaZWtylYADoX4+B+nDX915uY u0IQIf5X49//pK8H+vc15Nk1zKdp2W8dg/EMQPJmgASArs00qroT5CeldPzQosF48vAR cGuLlrNnUt+gVkExxglMNFWxuRE2TTNSfeW5NFKac0BupW88RbI0jmivjJm5dxM1Pli3 Sg+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=VB3KFXs+LF9/XBnyaRFgtYropEycOyC+3tczcXVhqcs=; b=Bf6n9/SXstT8O/Z4VzLwKztaZQCowHxdL1NlT+zqpX2HNAFuxfOlPaa8Fxk6w/5jSa JRw8F3w8mWsOyISIh+Kp9+oPwG26R3OMJhFxITcTZpHThTX/GnO6uW6u1cl9yYM8OvhM 3EwRRAW1tzsYvuqcIIZkxw26SLlHv9VMM3xPqcm4cDOdF9uCWf9xtihpj7JN746kqAQe 40gvMb8qDEWSxVfM+a+e1FRXTbnIvNplX7P6YAPwBlSx4cCGg0ztRTgS/70YCa7kNww8 AfdMr4HHf2moaU1myhzlsM6RHV4rweo8TxtZVQf2r5YuieD3R6CBK+TLwiSguvMPNGPL YdJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mMj5kEq3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i10si657055pgs.375.2018.02.14.16.49.57; Wed, 14 Feb 2018 16:50:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mMj5kEq3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1032536AbeBOAsv (ORCPT + 99 others); Wed, 14 Feb 2018 19:48:51 -0500 Received: from mail-it0-f65.google.com ([209.85.214.65]:34862 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032447AbeBOAsq (ORCPT ); Wed, 14 Feb 2018 19:48:46 -0500 Received: by mail-it0-f65.google.com with SMTP id e1so17103806ita.0 for ; Wed, 14 Feb 2018 16:48:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=VB3KFXs+LF9/XBnyaRFgtYropEycOyC+3tczcXVhqcs=; b=mMj5kEq3bqw+moCjJRwPAz+6PFsUM0ttzDaxuhR5Yk78s4aA7gJWHdLN09DTbCXqz+ lkQL0ZxMF8Ij1KPlSY8e541Xx2jhZgWbhBKdyR2+YKEMyGvqL/WweHZMz2sLEBrPImBG RAahwJ97FzBvzmnhfVlTJFrAOu0G91/tAWEpj1llCYJSRfKOf25p9+gQTJ+FVoYG3Xaz 9yQvzuqd4Nvf0lU++R/gQpfp52eQkZPH2UQ6EKPygEcmDiZEfLBvcw6ELg9Zu/t4TLOs u0De0HGp1FbsJrRpfc71EeNkduKs1Dhr7wiJds0op4Ltwms47gDyjUlp097pjXHUzQYY 8vrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=VB3KFXs+LF9/XBnyaRFgtYropEycOyC+3tczcXVhqcs=; b=OLFG0oFPMqkcO/h/dsf/S2k+1z6+29Z8F1SCHT734QVAKrd9Z8ELZYTEcsMk2eLHUc 4pc5fSqwqw71zzNJd19tWA6B1JrbR0zAL4Hp+hf/TgYPmUSi5JcSYKTSr4JEkj8pP7/N cNOvqye0fgU4rqqBk1jAm+w5GnZkgXSRfwq95XHuFHg293c7Iay9DCRx09as9lMycUIr L6Z0Gc8U+140KUnrue6PcuKM0wTObCvjLGtoFyAyTdTFRYSTwC6dYv8O6krYqL+jJX8h 85OToeB6/ChQ/DzE44Sb5W1FBkbqcmXHqg5Xogywxn9WhxwFQ9wtf/xCp7UnTxAkm+co 6Yqw== X-Gm-Message-State: APf1xPBdS8yuN8zpNDXFjgqgus7XvSyRVKAAX9IpXv0BX2X0utzI105m bTLZr0t5U9v/5YNBlKi1myZciViRKVK4bj6wDw== X-Received: by 10.36.60.203 with SMTP id m194mr1180316ita.96.1518655725688; Wed, 14 Feb 2018 16:48:45 -0800 (PST) MIME-Version: 1.0 Received: by 10.2.118.212 with HTTP; Wed, 14 Feb 2018 16:48:45 -0800 (PST) In-Reply-To: References: <20180214182113.27247-1-linux@dominikbrodowski.net> <20180214182113.27247-3-linux@dominikbrodowski.net> From: Brian Gerst Date: Wed, 14 Feb 2018 19:48:45 -0500 Message-ID: Subject: Re: [RFC PATCH 2/4] x86/entry/64: move ENTER_IRQ_STACK from interrupt macro to helper function To: Andy Lutomirski Cc: Dominik Brodowski , LKML , Ingo Molnar , X86 ML , Linus Torvalds , Andi Kleen , Thomas Gleixner , Dan Williams Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 14, 2018 at 7:17 PM, Andy Lutomirski wrote: > On Wed, Feb 14, 2018 at 6:21 PM, Dominik Brodowski > wrote: >> Moving the switch to IRQ stack from the interrupt macro to the helper >> function requires some trickery: All ENTER_IRQ_STACK really cares about >> is where the "original" stack -- meaning the GP registers etc. -- is >> stored. Therefore, we need to offset the stored RSP value by 8 whenever >> ENTER_IRQ_STACK is called from within a function. In such cases, and >> after switching to the IRQ stack, we need to push the "original" return >> address (i.e. the return address from the call to the interrupt entry >> function) to the IRQ stack. >> >> This trickery allows us to carve another 1k from the text size: >> >> text data bss dec hex filename >> 17905 0 0 17905 45f1 entry_64.o-orig >> 16897 0 0 16897 4201 entry_64.o >> >> Signed-off-by: Dominik Brodowski >> --- >> arch/x86/entry/entry_64.S | 53 +++++++++++++++++++++++++++++++---------------- >> 1 file changed, 35 insertions(+), 18 deletions(-) >> >> diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S >> index de8a0da0d347..3046b12a1acb 100644 >> --- a/arch/x86/entry/entry_64.S >> +++ b/arch/x86/entry/entry_64.S >> @@ -449,10 +449,18 @@ END(irq_entries_start) >> * >> * The invariant is that, if irq_count != -1, then the IRQ stack is in use. >> */ >> -.macro ENTER_IRQ_STACK regs=1 old_rsp >> +.macro ENTER_IRQ_STACK regs=1 old_rsp save_ret=0 >> DEBUG_ENTRY_ASSERT_IRQS_OFF >> movq %rsp, \old_rsp >> >> + .if \save_ret >> + /* >> + * If save_ret is set, the original stack contains one additional >> + * entry -- the return address. >> + */ >> + addq $8, \old_rsp >> + .endif >> + > > This is a bit alarming in that you now have live data below RSP. For > x86_32, this would be a big no-no due to NMI. For x86_64, it might > still be bad if there are code paths where NMI is switched to non-IST > temporarily, which was the case at some point and might still be the > case. (I think it is.) Remember that the x86_64 *kernel* ABI has no > red zone. > > It also means that, if you manage to hit vmalloc_fault() in here when > you touch the IRQ stack, you're dead. IOW you hit: > > movq \old_rsp, PER_CPU_VAR(irq_stack_union + IRQ_STACK_SIZE - 8) > > which gets #PF and eats your return pointer. Debugging this will be > quite nasty because you'll only hit it on really huge systems after a > thread gets migrated, and even then only if you get unlucky on your > stack alignment. > > So can you find another way to do this? It's adding 8 to the temp register, not %rsp. -- Brian Gerst