Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2469108pxk; Mon, 14 Sep 2020 14:23:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwYl6C4NHgraQ/geOPBB7KESTcb4EXmz4y+evGosnsX8TBDcTsD6WkJNtdIkh2Lybr+/kk X-Received: by 2002:a50:ee15:: with SMTP id g21mr19455077eds.47.1600118630576; Mon, 14 Sep 2020 14:23:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600118630; cv=none; d=google.com; s=arc-20160816; b=Y0y/R8y4geZq48CzEU1Fl6QiNm0+UmoS/e8BMHAyqmQnJcnLnhsuR7NOet8XezSlar F++yWmMbC0rfjUiL0EdM+c0J9xn/4y0qisArCKQTeJzou0DP+78cmNtZ/faNXlA2QdF9 LLd7NznPKYZxAOD6o6yvRbDtJixqZBl96YrjAnhzrvOKASadnoKaN74fVznT9rdD2Q5+ C677NP6x5psxYghoX75g8zIXb1UG2iMJpG8BajDuF2EurdzulKOBUpErvuWa831SjZA8 +A1xQhf8ln+zBoRAnPfqx666iwwc4sNm2upZsRVPEYnSrj6mLdJziIbJXxCSX/0KbW7m Nuxw== 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 :in-reply-to:references:mime-version:dkim-signature; bh=GiOBvH13WvdSWhELrU2Dx+x+3G1sac0Kq9zW3R8hwho=; b=Ns6cow48wUVOpq3n3hL8LiXaCHQcyj3tMDmQZrtpg/B5Ogv54JR244m0N2cba5HLWm OnEMGcMohqQ9sTQSPsO6dY7W7yLKuMbyNR7Xz/62IEZ6zwceh266BZSmqNxutpOcnazh Nemmo5+sZ+/yRDRaW7qfUZdBXp7gfCZ6YO12CI50ae8koSeXy3roQs4brg5WrWJ248Nt KiWEf//eLfBtaZ3+yNLMUsw/jlQFJa0nrlTeTsPO+DOaVjo+vgjPb7FHZ7VJx4tndLBZ eGHSn2v+HsOhkwjleV9fIoaPJ5l5HZqbS0b8O4XjvXIG9T9bGanbBKO7YyZ4vqgnDMjY PkSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HnELad8Y; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y7si8236223edw.23.2020.09.14.14.23.28; Mon, 14 Sep 2020 14:23:50 -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=@gmail.com header.s=20161025 header.b=HnELad8Y; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726087AbgINVVh (ORCPT + 99 others); Mon, 14 Sep 2020 17:21:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726031AbgINVV1 (ORCPT ); Mon, 14 Sep 2020 17:21:27 -0400 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 786B1C06174A; Mon, 14 Sep 2020 14:21:26 -0700 (PDT) Received: by mail-qk1-x744.google.com with SMTP id f142so1852184qke.13; Mon, 14 Sep 2020 14:21:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GiOBvH13WvdSWhELrU2Dx+x+3G1sac0Kq9zW3R8hwho=; b=HnELad8YKNRNHTJSFzXMAznwqWJeZMiT7DzWwq1p0kCJFncXjUo1TwUrIILdvbe5I8 1hWX6svpSKqFW1hFn2bfanvvQUqfAyKtSSNJIRlHdG9oEItoeF3gvq1YLmLfJqQMv/nN 7s8/5xKSnBko5289iuSxIDzKE48l9idRroUc/CWr8mrdJeFNELzq8TZ1psToDKDwOEZW EebMPwBlHIaqSI2Po3HpkDU/lGhYdsijkvDxfHMxk8rcph08kf4Ck3hblKVDy+8ivteg dJrCh8Lh0DOABiaQqWCMTun71PJLlpJQPQtOSs5FQ3Iqc/KfyGfiBfSMno/Wwo9iIyE/ iF3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GiOBvH13WvdSWhELrU2Dx+x+3G1sac0Kq9zW3R8hwho=; b=NcRRhZQTT6BcxESRkHRDa/HUDwXwekbc2aW0ZDcPPRGcodr2b9hCiRpgO+QvVpy0XI jhli1K5mID0JahtkHBeqKAaLCMg/cXDE6KXuBjGoG9UDgKe2/vONz/Ut/7mTe8a6k2dW vS3dF8E1u602H85Sq9BY2s59gU5TRIdmGOWQb2g9aarPqSZ/h7ErUdXDUfudeSI4q+3r 6j+MSryYhYuGzDdWCEqe26+xuFfltYukeD76mCimlskU2a5F+pxD0XJQ75GhbAVMQXmH ExS1iE+dH/qO5a7bh9BAOOOyoKEMY0g6dhwI3sd/fF/JqnO7AKqfzKhgPfTwuq/UpYXb DpYA== X-Gm-Message-State: AOAM531jfO9ZDXlxiHgZbQ5mWzjlk1+htAdSqZEcv7F7yuy4zptIwdZ7 wh1sMxFPxWjbIoInvHarDRdIUB08NpnP2U6g4C8= X-Received: by 2002:a37:9d8:: with SMTP id 207mr14254489qkj.465.1600118485597; Mon, 14 Sep 2020 14:21:25 -0700 (PDT) MIME-Version: 1.0 References: <20200914195634.12881-1-sean.j.christopherson@intel.com> <20200914195634.12881-2-sean.j.christopherson@intel.com> <20200914204024.w3rpjon64d3fesys@treble> <20200914210719.GB7084@sjchrist-ice> In-Reply-To: <20200914210719.GB7084@sjchrist-ice> From: Uros Bizjak Date: Mon, 14 Sep 2020 23:21:14 +0200 Message-ID: Subject: Re: [PATCH 1/2] KVM: VMX: Move IRQ invocation to assembly subroutine To: Sean Christopherson Cc: Josh Poimboeuf , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, LKML , Andi Kleen 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 Mon, Sep 14, 2020 at 11:07 PM Sean Christopherson wrote: > > On Mon, Sep 14, 2020 at 03:40:24PM -0500, Josh Poimboeuf wrote: > > On Mon, Sep 14, 2020 at 12:56:33PM -0700, Sean Christopherson wrote: > > > Move the asm blob that invokes the appropriate IRQ handler after VM-Exit > > > into a proper subroutine. Slightly rework the blob so that it plays > > > nice with objtool without any additional hints (existing hints aren't > > > able to handle returning with a seemingly modified stack size). > > > > > > Suggested-by: Josh Poimboeuf > > > Cc: Uros Bizjak > > > Signed-off-by: Sean Christopherson > > > --- > > > arch/x86/kvm/vmx/vmenter.S | 28 ++++++++++++++++++++++++++++ > > > arch/x86/kvm/vmx/vmx.c | 33 +++------------------------------ > > > 2 files changed, 31 insertions(+), 30 deletions(-) > > > > > > diff --git a/arch/x86/kvm/vmx/vmenter.S b/arch/x86/kvm/vmx/vmenter.S > > > index 799db084a336..baec1e0fefc5 100644 > > > --- a/arch/x86/kvm/vmx/vmenter.S > > > +++ b/arch/x86/kvm/vmx/vmenter.S > > > @@ -4,6 +4,7 @@ > > > #include > > > #include > > > #include > > > +#include > > > > > > #define WORD_SIZE (BITS_PER_LONG / 8) > > > > > > @@ -294,3 +295,30 @@ SYM_FUNC_START(vmread_error_trampoline) > > > > > > ret > > > SYM_FUNC_END(vmread_error_trampoline) > > > + > > > +SYM_FUNC_START(vmx_do_interrupt_nmi_irqoff) > > > + /* > > > + * Unconditionally create a stack frame. RSP needs to be aligned for > > > + * x86-64, getting the correct RSP on the stack (for x86-64) would take > > > + * two instructions anyways, and it helps make objtool happy (see below). > > > + */ > > > + push %_ASM_BP > > > + mov %rsp, %_ASM_BP > > > > RSP needs to be aligned to what? How would this align the stack, other > > than by accident? > > Ah, yeah, that's lacking info. > > 16-byte aligned to correctly mimic CPU behavior when vectoring an IRQ/NMI. > When not changing stack, the CPU aligns RSP before pushing the frame. > > The above shenanigans work because the x86-64 ABI also requires RSP to be > 16-byte aligned prior to CALL. RSP is thus 8-byte aligned due to CALL > pushing the return IP, and so creating the stack frame by pushing RBP makes > it 16-byte aliagned again. IIRC, the kernel violates x86_64 ABI and aligns RSP to 8 bytes prior to CALL. Please note -mpreferred-stack-boundary=3 in the compile flags. Uros.