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 5A61FC54EB4 for ; Tue, 24 Jan 2023 01:21:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232742AbjAXBVf (ORCPT ); Mon, 23 Jan 2023 20:21:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232512AbjAXBVd (ORCPT ); Mon, 23 Jan 2023 20:21:33 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33F988A7A for ; Mon, 23 Jan 2023 17:21:29 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id b24-20020a17090a551800b0022beefa7a23so230103pji.5 for ; Mon, 23 Jan 2023 17:21:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=wgGa5wrgAdo2NeUwkpPTr8VHG2ztyXDjbUcIQKILZZQ=; b=Fj59aztvZsI93KqVdNsaBYgt0ezKwdgNzsUWuwRdK3YtJgfxyhWeV0YpdCsA254hdh WNYQaNlZiuY31AdjFsdXMb2hOYwhdOxjeVXeI48dRt+far/UCt0p6INt1pEFeJWaEdvH QNwTW9ViwWmLYRMlGlTofNZMRnlovWq8+qA2wm0RoPBtYuBHGIvQOQrrOgUB+Elmp/at i+FZEXyRNNAVO5kKKpkgVoFIWBJfYTEYcZllDATZ+N4p9SEVumhM1oAYbm5Sf3GzkYL1 wVZuBCXqpFZZgWGzPRk2R3cY9F7Ca1V9tZSFMG+t9ypHjIYnWhroNO20jiQaP/vqypQT /LVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=wgGa5wrgAdo2NeUwkpPTr8VHG2ztyXDjbUcIQKILZZQ=; b=L05KgiPZMSz8bziB2klJ3xoLBd//SJ5uMqBIWRo/2ySxADZJi6d3pHTZeyUXc5QYvy s062jXs++83PYBCpY1QBTFM+SS1zn7sctAf+KJb5WEeE302DA2TMccmx3AQaot5Kfwph Xcn3k4nX3D0E7Sh1kNBTj2gH8eCCR6271worsx8V+1ASp4/4btENtM7okdXGtkjlaQ7F OeD9DITnnl8xmJ5ofRFxrQLpbxJgRp/vB1lL0Sd+439+nzMz/b1RyUJxHeTvLQP7zOIl 660BB6HPCVCU8Di7/grvj+TdCtpGugnKJjV1ArxMqNXeBvppYOUB+aQOCCZYiCYnPZQc EWyA== X-Gm-Message-State: AO0yUKVInWlOgyrlam4gRJRL4ausSzUqCo0mYPygkuxtNQpe/Sd1C39Z EzPW/xwVWDEUa3cCZn7Qn7t7mw== X-Google-Smtp-Source: AK7set/9pywbGEv0WlLYt3ONqn8dxZuuJBmeuykZqm87ZDRWGqgG45nB8eagGTlznEd5u4nG4ID0Ug== X-Received: by 2002:a17:902:7891:b0:191:4367:7fde with SMTP id q17-20020a170902789100b0019143677fdemr15867pll.0.1674523288475; Mon, 23 Jan 2023 17:21:28 -0800 (PST) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id jf1-20020a170903268100b001960690b5d4sm359391plb.59.2023.01.23.17.21.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 17:21:28 -0800 (PST) Date: Tue, 24 Jan 2023 01:21:24 +0000 From: Sean Christopherson To: Erdem Aktas Cc: "Maciej S. Szmigiero" , Ackerley Tng , linux-kselftest@vger.kernel.org, pbonzini@redhat.com, isaku.yamahata@intel.com, sagis@google.com, afranji@google.com, runanwang@google.com, shuah@kernel.org, drjones@redhat.com, maz@kernel.org, bgardon@google.com, jmattson@google.com, dmatlack@google.com, peterx@redhat.com, oupton@google.com, ricarkol@google.com, yang.zhong@intel.com, wei.w.wang@intel.com, xiaoyao.li@intel.com, pgonda@google.com, marcorr@google.com, eesposit@redhat.com, borntraeger@de.ibm.com, eric.auger@redhat.com, wangyanan55@huawei.com, aaronlewis@google.com, vkuznets@redhat.com, pshier@google.com, axelrasmussen@google.com, zhenzhong.duan@intel.com, like.xu@linux.intel.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [RFC PATCH v3 08/31] KVM: selftests: Require GCC to realign stacks on function entry Message-ID: References: <20230121001542.2472357-1-ackerleytng@google.com> <20230121001542.2472357-9-ackerleytng@google.com> <99a36eed-e4e5-60ec-0f88-a33d1842a0d6@maciej.szmigiero.name> 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 Mon, Jan 23, 2023, Erdem Aktas wrote: > On Mon, Jan 23, 2023 at 10:53 AM Sean Christopherson wrote: > > > > On Mon, Jan 23, 2023, Maciej S. Szmigiero wrote: > > > On 23.01.2023 19:30, Erdem Aktas wrote: > > > > On Fri, Jan 20, 2023 at 4:28 PM Sean Christopherson wrote: > > > > > > > > > > On Sat, Jan 21, 2023, Ackerley Tng wrote: > > > > > > Some SSE instructions assume a 16-byte aligned stack, and GCC compiles > > > > > > assuming the stack is aligned: > > > > > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40838. This combination > > > > > > results in a #GP in guests. > > > > > > > > > > > > Adding this compiler flag will generate an alternate prologue and > > > > > > epilogue to realign the runtime stack, which makes selftest code > > > > > > slower and bigger, but this is okay since we do not need selftest code > > > > > > to be extremely performant. > > > > > > > > > > Huh, I had completely forgotten that this is why SSE is problematic. I ran into > > > > > this with the base UPM selftests and just disabled SSE. /facepalm. > > > > > > > > > > We should figure out exactly what is causing a misaligned stack. As you've noted, > > > > > the x86-64 ABI requires a 16-byte aligned RSP. Unless I'm misreading vm_arch_vcpu_add(), > > > > > the starting stack should be page aligned, which means something is causing the > > > > > stack to become unaligned at runtime. I'd rather hunt down that something than > > > > > paper over it by having the compiler force realignment. > > > > > > > > Is not it due to the 32bit execution part of the guest code at boot > > > > time. Any push/pop of 32bit registers might make it a 16-byte > > > > unaligned stack. > > > > > > 32-bit stack needs to be 16-byte aligned, too (at function call boundaries) - > > > see [1] chapter 2.2.2 "The Stack Frame" > > > > And this showing up in the non-TDX selftests rules that out as the sole problem; > > the selftests stuff 64-bit mode, i.e. don't have 32-bit boot code. > > Thanks Maciej and Sean for the clarification. I was suspecting the > hand-coded assembly part that we have for TDX tests but it being > happening in the non-TDX selftests disproves it. Not necessarily, it could be both. Goofs in the handcoded assembly and PEBKAC on my end :-)