Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4105378rwb; Tue, 8 Nov 2022 12:09:34 -0800 (PST) X-Google-Smtp-Source: AMsMyM4Vlr0bavx3LnyK1SsV45S282fTYRXktBgZdu1zi1uBjkLgVojoS5PAfLrjHIU9mYG8DG1B X-Received: by 2002:a63:ff4f:0:b0:439:61d6:197 with SMTP id s15-20020a63ff4f000000b0043961d60197mr48210347pgk.67.1667938173969; Tue, 08 Nov 2022 12:09:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667938173; cv=none; d=google.com; s=arc-20160816; b=Dv/Tbg1mCe+3u8aFUk6NjW5sfb4ljUTTGzvGBCWD04xw1w2HCu01W8tX/0fDUlmPAq DFketuHfKuJAHI3Y6tVl9IFnaZ8qHbJ2PI+87W73pDJpit207arNPuTLFWE5gjpKiKIX JE6ZgYh3T0Irwbni33ygloJj/eQrRezEsl5qvyyoVL1giRqSGGXNE+eRdYSTBOPinl32 0z6wMyDSlX4uwg9eONJ+Fj4OhBk8W1ZSrp1+pQlsoCb+3fgJGRAW7eSckKQj4yPW/cb/ 5NFSVOpgHU/SviNvRfQ8ytiuQ4JwPJIL72mBTmofAPcNOK1XQk7Cc+0fxmS7xxlIijPo 6Kwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=jDjuzw5LjjhnHlmh63nX+G4JQyv9t3hJPs7UDj0L9/s=; b=agCYIoYtjsj0CgGErflnUW4fnr6kJyyOLHOruocbgLwd7kmDXPMvn83qz3ohttWkpg 7HM8kGqlfDtq2/GEl+9g/PNGTKawUb8hpOIDXdMSf+X6DULrY8E1Bl8qevFHgimZooMv Fu7ETx5rhxKt52sHA5mDEmGYT6yH9fqFLZeSTW4o9tYlvFO8aROI0siUTWRYTOOQ6RWB dv53vfJraULM7RWEJz+IxvFbI6uI/M65MjD1QaRoGpL2A1lMv3udNbrxFZGuQm8qNuRd WRKI1XcAQw/rO93oiZ7etHP0WE7f7xdRx41ETntjmHzPU9r+egGqEQLx1it+DZnKhUEb vu7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YHAHMJ2I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 2-20020a630d42000000b004702c91aed7si15508007pgn.309.2022.11.08.12.09.19; Tue, 08 Nov 2022 12:09:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YHAHMJ2I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229571AbiKHToE (ORCPT + 92 others); Tue, 8 Nov 2022 14:44:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229464AbiKHToB (ORCPT ); Tue, 8 Nov 2022 14:44:01 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9BDB1F61D; Tue, 8 Nov 2022 11:44:00 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 473A061778; Tue, 8 Nov 2022 19:44:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3ABEEC433C1; Tue, 8 Nov 2022 19:43:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667936639; bh=TDfsayD9ryRTKjmv0QhM0LrZ1U9kaiTGn71emQM6pQs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YHAHMJ2IkPUtqZ2sYM6jpbMgr73KvofUpOrvu5VF+KvBViIKE8xX/Bj5ppBFxQyGz qVHjK39G+6QLkA8Kn8tbX7PuznMbCo88naPNtrU8ZrFXz/xbd9I1AeNP5T0Zi+UrKx UbMMnKDQWJjFbwEpt4YxVzL/V7c2rdVFgN5Xf7QB8DwlfS8v/uyneyqhwrkXq2upFa 4scOfvTod85bk1OYq+Ih6m99zPHu/BMO9NpF0Hgkhxdfm89LfZepELWLIzgXogMWMM 9T2+JclwKyDY1pbAJhBUfD5xohxXU4GpD67Ec7DVN/qK8f+MjkPkth2WPSpbnj4lfw B9RvBeafIPq6w== Date: Tue, 8 Nov 2022 12:43:57 -0700 From: Nathan Chancellor To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, thomas.lendacky@amd.com, andrew.cooper3@citrix.com, peterz@infradead.org, jmattson@google.com, seanjc@google.com Subject: Re: [PATCH v2 0/8] KVM: SVM: fixes for vmentry code Message-ID: References: <20221108151532.1377783-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221108151532.1377783-1-pbonzini@redhat.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 08, 2022 at 10:15:24AM -0500, Paolo Bonzini wrote: > This series comprises two related fixes: > > - the FILL_RETURN_BUFFER macro in -next needs to access percpu data, > hence the GS segment base needs to be loaded before FILL_RETURN_BUFFER. > This means moving guest vmload/vmsave and host vmload to assembly > (patches 5 and 6). > > - because AMD wants the OS to set STIBP to 1 before executing the > return thunk (un)training sequence, IA32_SPEC_CTRL must be restored > before UNTRAIN_RET, too. This must also be moved to assembly and, > for consistency, the guest SPEC_CTRL is also loaded in there > (patch 7). > > Neither is particularly hard, however because of 32-bit systems one needs > to keep the number of arguments to __svm_vcpu_run to three or fewer. > One is taken for whether IA32_SPEC_CTRL is intercepted, and one for the > host save area, so all accesses to the vcpu_svm struct have to be done > from assembly too. This is done in patches 2 to 4, and it turns out > not to be that bad; in fact I think the code is simpler than before > after these prerequisites, and even at the end of the series it is not > much harder to follow despite doing a lot more stuff. Care has been > taken to keep the "normal" and SEV-ES code as similar as possible, > even though the latter would not hit the three argument barrier. > > The above summary leaves out the more mundane patches 1 and 8. The > former introduces a separate asm-offsets.c file for KVM, so that > kernel/asm-offsets.c does not have to do ugly includes with ../ paths. > The latter is dead code removal. > > Thanks, > > Paolo > > v1->v2: use a separate asm-offsets.c file instead of hacking around > the arch/x86/kvm/svm/svm.h file; this could have been done > also with just a "#ifndef COMPILE_OFFSETS", but Sean's > suggestion is cleaner and there is a precedent in > drivers/memory/ for private asm-offsets files > > keep preparatory cleanups together at the beginning of the > series > > move SPEC_CTRL save/restore out of line [Jim] > > Paolo Bonzini (8): > KVM: x86: use a separate asm-offsets.c file > KVM: SVM: replace regs argument of __svm_vcpu_run with vcpu_svm > KVM: SVM: adjust register allocation for __svm_vcpu_run > KVM: SVM: retrieve VMCB from assembly > KVM: SVM: move guest vmsave/vmload to assembly > KVM: SVM: restore host save area from assembly > KVM: SVM: move MSR_IA32_SPEC_CTRL save/restore to assembly > x86, KVM: remove unnecessary argument to x86_virt_spec_ctrl and > callers > > arch/x86/include/asm/spec-ctrl.h | 10 +- > arch/x86/kernel/asm-offsets.c | 6 - > arch/x86/kernel/cpu/bugs.c | 15 +- > arch/x86/kvm/Makefile | 12 ++ > arch/x86/kvm/kvm-asm-offsets.c | 28 ++++ > arch/x86/kvm/svm/svm.c | 53 +++---- > arch/x86/kvm/svm/svm.h | 4 +- > arch/x86/kvm/svm/svm_ops.h | 5 - > arch/x86/kvm/svm/vmenter.S | 241 ++++++++++++++++++++++++------- > arch/x86/kvm/vmx/vmenter.S | 2 +- > 10 files changed, 259 insertions(+), 117 deletions(-) > create mode 100644 arch/x86/kvm/kvm-asm-offsets.c > > -- > 2.31.1 > > I applied this series on next-20221108, which has the call depth tracking patches, and I no longer see the panic when starting a guest on my AMD test system and I can still start a simple nested guest without any problems, which is about the extent of my regular KVM testing. I did test the same kernel on my Intel systems and saw no problems there but that seems expected given the diffstat. Thank you for the quick response and fixes! Tested-by: Nathan Chancellor One small nit I noticed: kvm-asm-offsets.h should be added to a .gitignore file in arch/x86/kvm. $ git status --short ?? arch/x86/kvm/kvm-asm-offsets.h Cheers, Nathan