Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3665071ybt; Tue, 23 Jun 2020 07:56:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/w/ObNVgdho/qLHQw8PGfcyJX6pqiNObT02Ih7n93+bNv4csOtRLXxj7mDifAvJP8wqhl X-Received: by 2002:a17:906:3041:: with SMTP id d1mr21084428ejd.7.1592924196881; Tue, 23 Jun 2020 07:56:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592924196; cv=none; d=google.com; s=arc-20160816; b=mCul8sEHTb8B4W7+5lwZE7ee5qrPwaCoZHmeR9Cs1jD32BotNyZUqAFXHC8S4ro3km DofwQfjcBqCpR6BkdPrjn6vC2Dy1WpAiDHpRTjOLyCjJ6+pI7/29HD2lSGVL/GKJCmrz 9BFSB+YGqdNCkBqwArqSLhBEz70QYUvdBdGcmPFup1HWAs3Sb1vV/ndG+bhBMGI2/TaT qfVvPDk9jEWNKgdQKhj6qwpSDqxDUTZpZSeZNy6bGYqsELCzK3Bb1mXXGqvVp2cFh3G6 fcjDX1pWWL9v6ZKflk/eku4Zphdy69Gz6Q6iohwiRNz7Fwf6uCmH1sP2TQ9He9b4q2Ck yR0g== 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 :dkim-signature; bh=HULhaI+b5XJqnnihDW5C9Ggk4Cp4Adw7G89+l/htg0I=; b=KGpguDMMpXZhkalXD7pLRHQv7yw/BZrJnr8xjwAvIajMKvW9SAFSRIYYouLeUvTYnT EDRdAcfzNNOcfbmUfVxzqt29KHdu54x80/Cu4mC5GVw3QYysxKI8vg1TA2qpqtRVKXQs zGMbYGQypoJ01bQ343eEA5cu2wsKlsXoaDInkLKH8IeBwUchWQoec4HcDB+ci6emxKjz O57rY988AGL9ssS8tbvL1L4sDVrmfFwsZxvUOw+fbAVAFpzNtafW7Rtxv7m9RAPLjYaU wDWnThceo+h4t2xI0lA28PW1BvW8q7DM/U2GdgGYty5+hb78SRthzl/b2WOcaf0MTGMD /WEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=jJTrms2h; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a24si6319484ejg.331.2020.06.23.07.56.13; Tue, 23 Jun 2020 07:56:36 -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=fail header.i=@infradead.org header.s=casper.20170209 header.b=jJTrms2h; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732880AbgFWOyR (ORCPT + 99 others); Tue, 23 Jun 2020 10:54:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732840AbgFWOyQ (ORCPT ); Tue, 23 Jun 2020 10:54:16 -0400 Received: from casper.infradead.org (unknown [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A65BC061573; Tue, 23 Jun 2020 07:54:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=HULhaI+b5XJqnnihDW5C9Ggk4Cp4Adw7G89+l/htg0I=; b=jJTrms2hoV5Nzz7Wo9AaUII+sw 2zCeUAXIjhAFqBTeIVysOW8tr+I1cq0WsZ3lg+qYSSCEttqsd40hQ44w4Jb0/b7p9n9EuwLHZUGw9 VXaPwrIBRTP+ncvgGvke5TZe4297oUsZ6v+pOOO0Xdli7QEUP7NUDDaFIcHbpe3aKKy5VHZ8q8BGB gjco2dlW4zQJgFht29uUVdhszPfFQ+nZNew7IQU3vHNhE7hdYxDmswTkGkty6GKA9PgvhWRJu1nlE Ct0a2jSe9Ylu4gQVerv+8fbLzvGxE1U8jGZw4hbOwzvQb+kF/q2QDj1OLouPmZ3NaFf7RCMZ16/DE iC6FndYA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jnkIz-00066t-Uk; Tue, 23 Jun 2020 14:53:46 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 836FC30477A; Tue, 23 Jun 2020 16:53:44 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 7108C23CD6142; Tue, 23 Jun 2020 16:53:44 +0200 (CEST) Date: Tue, 23 Jun 2020 16:53:44 +0200 From: Peter Zijlstra To: Joerg Roedel Cc: Andy Lutomirski , Joerg Roedel , Dave Hansen , Tom Lendacky , Mike Stunes , Dan Williams , Dave Hansen , "H. Peter Anvin" , Juergen Gross , Jiri Slaby , Kees Cook , kvm list , LKML , Thomas Hellstrom , Linux Virtualization , X86 ML , Sean Christopherson , Andrew Cooper Subject: Re: Should SEV-ES #VC use IST? (Re: [PATCH] Allow RDTSC and RDTSCP from userspace) Message-ID: <20200623145344.GA117543@hirez.programming.kicks-ass.net> References: <20200428075512.GP30814@suse.de> <20200623110706.GB4817@hirez.programming.kicks-ass.net> <20200623113007.GH31822@suse.de> <20200623114818.GD4817@hirez.programming.kicks-ass.net> <20200623120433.GB14101@suse.de> <20200623125201.GG4817@hirez.programming.kicks-ass.net> <20200623134003.GD14101@suse.de> <20200623135916.GI4817@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200623135916.GI4817@hirez.programming.kicks-ass.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 23, 2020 at 03:59:16PM +0200, Peter Zijlstra wrote: > So basically when your exception frame points to your own IST, you die. > That sounds like something we should have in generic IST code. Something like this... #DF already dies and NMI is 'magic' --- arch/x86/entry/common.c | 7 +++++++ arch/x86/include/asm/idtentry.h | 12 +++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c index af0d57ed5e69..e38e4f34c90c 100644 --- a/arch/x86/entry/common.c +++ b/arch/x86/entry/common.c @@ -742,6 +742,13 @@ noinstr void idtentry_exit_nmi(struct pt_regs *regs, bool restore) __nmi_exit(); } +noinstr void idtentry_validate_ist(struct pt_regs *regs) +{ + if ((regs->sp & ~(EXCEPTION_STKSZ-1)) == + (_RET_IP_ & ~(EXCEPTION_STKSZ-1))) + die("IST stack recursion", regs, 0); +} + #ifdef CONFIG_XEN_PV #ifndef CONFIG_PREEMPTION /* diff --git a/arch/x86/include/asm/idtentry.h b/arch/x86/include/asm/idtentry.h index 4e399f120ff8..974c1a4eacbb 100644 --- a/arch/x86/include/asm/idtentry.h +++ b/arch/x86/include/asm/idtentry.h @@ -19,6 +19,8 @@ void idtentry_exit_cond_rcu(struct pt_regs *regs, bool rcu_exit); bool idtentry_enter_nmi(struct pt_regs *regs); void idtentry_exit_nmi(struct pt_regs *regs, bool irq_state); +void idtentry_validate_ist(struct pt_regs *regs); + /** * DECLARE_IDTENTRY - Declare functions for simple IDT entry points * No error code pushed by hardware @@ -322,7 +324,15 @@ static __always_inline void __##func(struct pt_regs *regs) * Maps to DEFINE_IDTENTRY_RAW */ #define DEFINE_IDTENTRY_IST(func) \ - DEFINE_IDTENTRY_RAW(func) +static __always_inline void __##func(struct pt_regs *regs); \ + \ +__visible noinstr void func(struct pt_regs *regs) \ +{ \ + idtentry_validate_ist(regs); \ + __##func(regs); \ +} \ + \ +static __always_inline void __##func(struct pt_regs *regs) /** * DEFINE_IDTENTRY_NOIST - Emit code for NOIST entry points which