Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2618257pxk; Mon, 14 Sep 2020 19:45:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCZRnkKj/HyJAUQQr2YavatQN+79LEpsql4Stfg6TcXQIwJXFjKTb8zRh2U55i+3iBhwun X-Received: by 2002:a17:906:c830:: with SMTP id dd16mr18204135ejb.196.1600137916546; Mon, 14 Sep 2020 19:45:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600137916; cv=none; d=google.com; s=arc-20160816; b=R6pw6NQ7LSfffmUWCR/PO7ABH/8jFO4N6Qw2JX4DR/w1HnrC++EKoDAXjzyLrJ7WjZ AhTCgtLk0t1x44i6mRqlETHtCg65zQHIqvGurAOGaRB9TbnZup1lhq5LiVZeBiT96e9P 1WCJPVte93KBFZ5LrMMxgx/seiTryxGFLy+n6LkLC4MbsNRK7HjQLkaUcTNCWffFvXJp ENx0qRBxXN3yLrRutDRuIbAxU6jmLJH5wOL7rhxcIps/f0dKZkwpJboH7/QnixqUN7XL 3fowV9AtO0TFn07jQ+711enqnNoMHe7XK6ac8kdiYA8riYrg6ZEx/ItEuGx1EFw7jTxV MErw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=N5QtWtqqj6iBGFFNB6Isl0MFsgTMVFj6yA49pNNqsW0=; b=TPq7ZygDlJuuLP8u33hENS0iAqsLTq2pC49D9mN4maJNO3j/LFHXHGhkWfAB+rvJSj TkGtuDQFQuyrn4l/KGGZ+7yJ6Zv4Lv7/82pkQGQKelOTYGeXtFfWcQQAoFZK9l7qM37B uJjSN59ahrn5YSNYr+UhYqAFf2uPFfaaSmeFdtYGIzU1rvF752c1of7ILhxAnEeM7D1E fiogorLc5wMJsVfnN9lZHpcg4tY2lH1OIxvgegNfzWQ/l/w3nEfGs/+8MbpBom9kFBGU fu51E4p9iU3MlLsokLkmM5bsSrXD1zg5NskvqBf4derji9tyrXuWlg5O40uvjiii7dI3 B9oA== 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 qt8si7848889ejb.159.2020.09.14.19.44.54; Mon, 14 Sep 2020 19:45:16 -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 S1726120AbgIOCmE (ORCPT + 99 others); Mon, 14 Sep 2020 22:42:04 -0400 Received: from mga02.intel.com ([134.134.136.20]:58954 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726035AbgIOCmC (ORCPT ); Mon, 14 Sep 2020 22:42:02 -0400 IronPort-SDR: AB/2b5g1mhnqbDWad7WIFULemAnflptnRXCzhImn/kBPFYa1zl5ZEB5Sj9gvdHUgZrRmVp2sG9 GRj0JqTciCoA== X-IronPort-AV: E=McAfee;i="6000,8403,9744"; a="146879518" X-IronPort-AV: E=Sophos;i="5.76,428,1592895600"; d="scan'208";a="146879518" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Sep 2020 19:42:02 -0700 IronPort-SDR: BmrQGyB+8l574LwXi+Sq9NLBI0yRDeieQgipDhcbe6Xk0rr16sfhjEsOw1tzOMjx/ct/hoZSqz h14tUu38B/9Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,428,1592895600"; d="scan'208";a="343330939" Received: from tassilo.jf.intel.com (HELO tassilo.localdomain) ([10.54.74.11]) by FMSMGA003.fm.intel.com with ESMTP; 14 Sep 2020 19:42:01 -0700 Received: by tassilo.localdomain (Postfix, from userid 1000) id B4C26301C59; Mon, 14 Sep 2020 19:42:01 -0700 (PDT) Date: Mon, 14 Sep 2020 19:42:01 -0700 From: Andi Kleen To: Sean Christopherson Cc: Josh Poimboeuf , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Uros Bizjak Subject: Re: [PATCH 1/2] KVM: VMX: Move IRQ invocation to assembly subroutine Message-ID: <20200915024201.GA13818@tassilo.jf.intel.com> References: <20200914195634.12881-1-sean.j.christopherson@intel.com> <20200914195634.12881-2-sean.j.christopherson@intel.com> <20200914204024.w3rpjon64d3fesys@treble> <20200914210719.GB7084@sjchrist-ice> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200914210719.GB7084@sjchrist-ice> 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 02:07:19PM -0700, Sean Christopherson wrote: > 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. 16 byte alignment is not needed for the internal kernel ABI because it doesn't use SSE. -Andi > > 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. > > > > + > > > +#ifdef CONFIG_X86_64 > > > + push $__KERNEL_DS > > > + push %_ASM_BP > > > +#endif > > > + pushf > > > + push $__KERNEL_CS > > > + CALL_NOSPEC _ASM_ARG1 > > > + > > > + /* > > > + * "Restore" RSP from RBP, even though IRET has already unwound RSP to > > > + * the correct value. objtool doesn't know the target will IRET and so > > > + * thinks the stack is getting walloped (without the explicit restore). > > > + */ > > > + mov %_ASM_BP, %rsp > > > + pop %_ASM_BP > > > + ret > > > > BTW, there *is* actually an unwind hint for this situation: > > UNWIND_HINT_RET_OFFSET. > > I played with that one, but for the life of me couldn't figure out how to > satisfy both the "stack size" and "cfa.offset" checks. In the code below, > cfa.offset will be 8, stack_size will be 40 and initial_func_cfi.cfa.offset > will be 8. But rereading this, I assume I missed something that would allow > maniuplating cfa.offset? Or maybe I botched my debugging? > > static bool has_modified_stack_frame(struct instruction *insn, struct insn_state *state) > { > ... > > if (cfi->cfa.offset != initial_func_cfi.cfa.offset + ret_offset) > return true; > > if (cfi->stack_size != initial_func_cfi.cfa.offset + ret_offset) > return true; > > ... > } > > > So you might be able to do something like the following (depending on > > what your alignment requirements actually are): > > > > SYM_FUNC_START(vmx_do_interrupt_nmi_irqoff) > > #ifdef CONFIG_X86_64 > > push $__KERNEL_DS > > push %_ASM_BP > > #endif > > pushf > > push $__KERNEL_CS > > CALL_NOSPEC _ASM_ARG1 > > > > /* The call popped the pushes */ > > UNWIND_HINT_RET_OFFSET sp_offset=32 > > > > ret > > SYM_FUNC_END(vmx_do_interrupt_nmi_irqoff) > > > > -- > > Josh > >