Message ID | 20221028230723.3254250-1-pbonzini@redhat.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1087978wru; Fri, 28 Oct 2022 16:11:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4RriRtamp5+KjGv9645dZlURgfADdEXu1g6LDjuvJ0/YNBHsQ+iAkEVc/+Dq8+SEsPVo6K X-Received: by 2002:a17:906:5d04:b0:722:f46c:b891 with SMTP id g4-20020a1709065d0400b00722f46cb891mr1532314ejt.4.1666998665115; Fri, 28 Oct 2022 16:11:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666998665; cv=none; d=google.com; s=arc-20160816; b=OFJqzmrqbc6AXUbK4c/rBwnpYl2HwDt3G91M1v27kbhmZJw1OLVRCCcG9ZrxXUYik7 egtUDlfz9IV2xMPvtuildWuaQyeQffxoRgxD9JJcHfYPNVADvsMwjNCk66lOidEseIPo ELDWnOvIyEt9720gqLqptkVuA35KfFNUmcA4KxNVmjqqc2j7Pcp2k6oTB8VRs+38NWz0 YYZfjVUXRv5epIZ96dsswvw/zdUdLtlfkMmfybwd+29WJtLfgH99BSw8RAKiSnFcXlmv Z3vphgMdC1Ar5fdTG2pSAwvkIpDyKDG+SkGy65v1ZCBOZv4AsRBUWbthP2S0pTHjkq5v X38Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=A2c8ymd1GFvLBVMNdJ9tI50soRavZnzeQUSNcQq0dMs=; b=jYeWsV5JqjvoP/ggdHotQspbZuOgi8BohYCuyV1pU1yR6ApYoMilvxhIDV7vWyS7gv pGFCY8Pvq6zn9LPkgnErVFaItQMV8D6h2QobhMnlM2ApU4rl2NCBA/QcvuF7Cy+wesLF NcZ7/fGyXUMzDN+2toHpk8vcL++C2lU1EHiGnT/4fa97qzlyaFrws8VEHEDxHRIVsgXW F9IfFHseSdv9BqPHbc6hgJzGtsRyrCQZ1Gp+MkPZ7Dc6pO21ZwsVRNP233XW1vPUMnRI 16FrEAyLcjhnsyT1663L6I0CIerZ22wLKRKIVv5s2v1P3L/uhkakkUoMeQADG6gXrvMc I7Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FGTGwBp7; 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=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d4-20020aa7c1c4000000b00459f6d1be02si5418126edp.387.2022.10.28.16.10.41; Fri, 28 Oct 2022 16:11:05 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=FGTGwBp7; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229616AbiJ1XIm (ORCPT <rfc822;pusanteemu@gmail.com> + 99 others); Fri, 28 Oct 2022 19:08:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229531AbiJ1XIk (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 28 Oct 2022 19:08:40 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20B9A23797A for <linux-kernel@vger.kernel.org>; Fri, 28 Oct 2022 16:07:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666998472; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=A2c8ymd1GFvLBVMNdJ9tI50soRavZnzeQUSNcQq0dMs=; b=FGTGwBp7M0d02EniqDmPYaiiK4e93zjFJI/Cl41ah7bXwTgf2b1A9oWw4TvBI+hIe0bS4q QCyxUhGB6CjzRFUfNhpCZmuErSdwA6ci7EUg3/StYne+6CflNVeBbnnD2SXQossMIh48qW c+osX1yVQl65M549NKG8HaD0PwSD5Zk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-455-LZJSepqpOAikHMAm8TLHDg-1; Fri, 28 Oct 2022 19:07:50 -0400 X-MC-Unique: LZJSepqpOAikHMAm8TLHDg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E9579857D0D; Fri, 28 Oct 2022 23:07:39 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7CC540C6EC3; Fri, 28 Oct 2022 23:07:25 +0000 (UTC) From: Paolo Bonzini <pbonzini@redhat.com> To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: jmattson@google.com, seanjc@google.com, jpoimboe@kernel.org Subject: [RFC PATCH 0/7] KVM: SVM: move MSR_IA32_SPEC_CTRL save/restore to assembly Date: Fri, 28 Oct 2022 19:07:16 -0400 Message-Id: <20221028230723.3254250-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747974792028048241?= X-GMAIL-MSGID: =?utf-8?q?1747974792028048241?= |
Series |
KVM: SVM: move MSR_IA32_SPEC_CTRL save/restore to assembly
|
|
Message
Paolo Bonzini
Oct. 28, 2022, 11:07 p.m. UTC
On the Intel side, restoration of the guest's IA32_SPEC_CTRL is done as late as possible before vmentry, with the comment: * IMPORTANT: To avoid RSB underflow attacks and any other nastiness, * there must not be any returns or indirect branches between this code * and vmentry. On AMD, there is no need to avoid returns or indirect branches between wrmsr and vmrun because Linux doesn't use IBRS; however, restoration of the host IA32_SPEC_CTRL value is definitely way too late. With respect to the user/kernel boundary, AMD says, "If software chooses to toggle STIBP (e.g., set STIBP on kernel entry, and clear it on kernel exit), software should set STIBP to 1 before executing the return thunk training sequence." Assuming the same requirements apply to the guest/host boundary, KVM does not respect this recommendation: the return thunk training sequence is in vmenter.S, quite close to the VM-exit, while the host's IA32_SPEC_CTRL value is only restored much later for hosts without V_SPEC_CTRL. In the absence of clarifications for AMD, move all the SPEC_CTRL handling to assembly code and, in passing, also make the Intel and AMD code a bit more similar to each other. Patches 1-2 are the Intel side, which is just a cleanup. Patch 3 prepares for adding asm-offsets.c entries in arch/x86/kvm/svm/svm.h, and patches 4-5 are a similar cleanup to the earlier VMX ones. Patch 6 is the bulk of the change, and finally patch 7 removes now dead code in asm/spec-ctrl.h and arch/x86/kernel/. This is RFC because I haven't tested SEV-ES or 32-bit yet. Paolo Paolo Bonzini (7): KVM: VMX: remove regs argument of __vmx_vcpu_run KVM: VMX: more cleanups to __vmx_vcpu_run KVM: SVM: extract VMCB accessors to a new file KVM: SVM: replace argument of __svm_vcpu_run with vcpu_svm KVM: SVM: adjust register allocation for __svm_vcpu_run 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 | 8 ++ arch/x86/kernel/cpu/bugs.c | 15 +-- arch/x86/kvm/svm/avic.c | 1 + arch/x86/kvm/svm/nested.c | 1 + arch/x86/kvm/svm/sev.c | 1 + arch/x86/kvm/svm/svm.c | 39 +++--- arch/x86/kvm/svm/svm.h | 204 +----------------------------- arch/x86/kvm/svm/svm_onhyperv.c | 1 + arch/x86/kvm/svm/vmcb.h | 211 +++++++++++++++++++++++++++++++ arch/x86/kvm/svm/vmenter.S | 164 ++++++++++++++++++------ arch/x86/kvm/vmx/nested.c | 3 +- arch/x86/kvm/vmx/vmenter.S | 92 ++++++-------- arch/x86/kvm/vmx/vmx.c | 3 +- arch/x86/kvm/vmx/vmx.h | 3 +- 15 files changed, 419 insertions(+), 337 deletions(-) create mode 100644 arch/x86/kvm/svm/vmcb.h