From patchwork Tue Sep 22 21:10:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 11793173 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 41981112C for ; Tue, 22 Sep 2020 21:10:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 206AA206FB for ; Tue, 22 Sep 2020 21:10:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ekIwuyE4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726716AbgIVVKf (ORCPT ); Tue, 22 Sep 2020 17:10:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:27967 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726625AbgIVVKf (ORCPT ); Tue, 22 Sep 2020 17:10:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600809034; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=bNjVgWpgtIkPhRa8XVCPnausw2GfEoBb82DdGdZXVvc=; b=ekIwuyE46DrYdAaRR3VUm9LJ6r86ZyXtW9vna51dozcxfWozLSzNT6srwE2a0xuuuUv4XQ AEg5PntS9WxpfXwePKBvt4KyJRAGcL9RvrB036MI35X+RjLHN8wY7TVNG517Fc9UqGOOIU ahdkDAwhtTWQKy7OVlzx6mYY3DHOA3k= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-91-EmSHZr1ePa6cO30n87NEuA-1; Tue, 22 Sep 2020 17:10:32 -0400 X-MC-Unique: EmSHZr1ePa6cO30n87NEuA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E4AE01007B36; Tue, 22 Sep 2020 21:10:30 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.154]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF02155768; Tue, 22 Sep 2020 21:10:26 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: "H. Peter Anvin" , Ingo Molnar , Borislav Petkov , Vitaly Kuznetsov , Sean Christopherson , Joerg Roedel , Paolo Bonzini , Wanpeng Li , Thomas Gleixner , linux-kernel@vger.kernel.org, Jim Mattson , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), Maxim Levitsky Subject: [PATCH v6 0/4] KVM: nSVM: ondemand nested state allocation Date: Wed, 23 Sep 2020 00:10:21 +0300 Message-Id: <20200922211025.175547-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is the next version of this patch series. In V5 I adopted Sean Christopherson's suggestion to make .set_efer return a negative error (-ENOMEM in this case) which in most cases in kvm propagates to the userspace. I noticed though that wrmsr emulation code doesn't do this and instead it injects #GP to the guest on _any_ error. So I fixed the wrmsr code to behave in a similar way to the rest of the kvm code. (#GP only on a positive error value, and forward the negative error to the userspace) I had to adjust one wrmsr handler (xen_hvm_config) to stop it from returning negative values so that new WRMSR emulation behavior doesn't break it. This patch was only compile tested. The memory allocation failure was tested by always returning -ENOMEM from svm_allocate_nested. The nested allocation itself was tested by countless attempts to run nested guests, do nested migration on both my AMD and Intel machines. I wasn't able to break it. Changes from V5: addressed Sean Christopherson's review feedback. Best regards, Maxim Levitsky Maxim Levitsky (4): KVM: x86: xen_hvm_config: cleanup return values KVM: x86: report negative values from wrmsr emulation to userspace KVM: x86: allow kvm_x86_ops.set_efer to return an error value KVM: nSVM: implement on demand allocation of the nested state arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/emulate.c | 7 ++-- arch/x86/kvm/svm/nested.c | 42 ++++++++++++++++++++++++ arch/x86/kvm/svm/svm.c | 58 +++++++++++++++++++-------------- arch/x86/kvm/svm/svm.h | 8 ++++- arch/x86/kvm/vmx/vmx.c | 6 ++-- arch/x86/kvm/x86.c | 37 ++++++++++++--------- 7 files changed, 113 insertions(+), 47 deletions(-)