Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12FF9C38142 for ; Fri, 27 Jan 2023 17:25:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235208AbjA0RZW (ORCPT ); Fri, 27 Jan 2023 12:25:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235201AbjA0RZS (ORCPT ); Fri, 27 Jan 2023 12:25:18 -0500 Received: from mail.8bytes.org (mail.8bytes.org [IPv6:2a01:238:42d9:3f00:e505:6202:4f0c:f051]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 464637B423; Fri, 27 Jan 2023 09:25:11 -0800 (PST) Received: from 8bytes.org (p5b006afb.dip0.t-ipconnect.de [91.0.106.251]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.8bytes.org (Postfix) with ESMTPSA id 72C3626302C; Fri, 27 Jan 2023 18:25:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=8bytes.org; s=default; t=1674840309; bh=m4psZ1O0An3xTl3QooT7Oe58TqGhBHCLxfn9vXOdlU8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=zrE2ynIYizjvRY8GpViEkVQam9rf4AdVqeMQjZlOmuakma/M8tuotEHTMcEci3wCK BylnB1ApstdAnimK5NW/O9Sr0SSdiaW1hT/CSUaZSWaq5RXixOpXlZ55co8JR5vb5l +DDW4X+bcwblMYtXa7mJ2jNiZmG/ULbJ1AwfJxjnss3IINTTfet8hnsYgCKpNhXzMs P5HDtynjqYC6jmcLUJt7XzJHjJpuZWEEz0jAgjvRUcpI/QLQ519AS4fYkArCoSLOAx 69Vuz0STiSCcxM9+TudUNOhEc1eoNlOtcO/N+kL/FeOV0w9ws/XwwS+9IHfyPUij1B CQH0AGrE9Oh3A== Date: Fri, 27 Jan 2023 18:25:08 +0100 From: Joerg Roedel To: Alexey Kardashevskiy Cc: Peter Zijlstra , kvm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Sean Christopherson , Jiri Kosina , Ingo Molnar , Dave Hansen , Borislav Petkov , "H. Peter Anvin" , Tom Lendacky Subject: Re: [Question PATCH kernel] x86/amd/sev/nmi+vc: Fix stack handling (why is this happening?) Message-ID: References: <20230127035616.508966-1-aik@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 27, 2023 at 10:56:26PM +1100, Alexey Kardashevskiy wrote: > https://github.com/aik/linux/commit/d0d6bbb58fcd927ddd1f8e9d42ab121920c7eafc Okay, I reproduced the problem here and the root cause turned out to be that the compiler moved the DR7 read instruction before the 5-byte NOP which becomes the call to sev_es_ist_enter() in SEV-ES guests. This is guaranteed to cause #VC exception stack recursion if the NMI was triggered on the #VC stack, and that leads to all kinds of undefined behavior. Regards, Joerg