From patchwork Thu Apr 21 05:12:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 12821058 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 5413FC433FE for ; Thu, 21 Apr 2022 05:13:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384232AbiDUFPr (ORCPT ); Thu, 21 Apr 2022 01:15:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384234AbiDUFPp (ORCPT ); Thu, 21 Apr 2022 01:15:45 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 00190DEC4 for ; Wed, 20 Apr 2022 22:12:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650517976; 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=gw2WgO3NdEKefNIzU7OyyGWhN8RKFPXQkhGeUbUxcYw=; b=NSuwvCJ+FexfoiS6r1ezvXpShvzKtvq2cBl+PBS8RDWyxrMBcVihfpwx8sut3yL7eyfu52 O6hdawqVBVVDmF+ZaseYwJsJSCSsj8sY7Z3EQ2YDZNUDNJAMr2xf5sk9nuyBcqq9uMJ3TN Xwmdb2Ot6b/IlXio/CwHILvTTaa4rXs= 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-10-L9HPRdJxNBmr5i5MKpw9hg-1; Thu, 21 Apr 2022 01:12:53 -0400 X-MC-Unique: L9HPRdJxNBmr5i5MKpw9hg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D1D6880A0AD; Thu, 21 Apr 2022 05:12:51 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id AEF55145B96B; Thu, 21 Apr 2022 05:12:45 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Rodrigo Vivi , Paolo Bonzini , intel-gfx@lists.freedesktop.org, Joonas Lahtinen , Jani Nikula , Thomas Gleixner , linux-kernel@vger.kernel.org, Wanpeng Li , Jim Mattson , Tvrtko Ursulin , "H. Peter Anvin" , Vitaly Kuznetsov , Zhi Wang , Daniel Vetter , intel-gvt-dev@lists.freedesktop.org, dri-devel@lists.freedesktop.org, x86@kernel.org, David Airlie , Sean Christopherson , Ingo Molnar , Joerg Roedel , Dave Hansen , Borislav Petkov , Zhenyu Wang , Maxim Levitsky Subject: [RFC PATCH v2 00/10] RFCv2: nested AVIC Date: Thu, 21 Apr 2022 08:12:34 +0300 Message-Id: <20220421051244.187733-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This patch series implement everything that is needed to use AMD's AVIC while a nested guest is running including ability of the nested guest to use it, and brings feature parity vs APICv. Compared to v1 of the series, there are lot of fixes, and refactoring. This version still use unconditional read-only apic id, which will be addressed in the next version. For the last patch, which allows to avoid cleaning is_running bit in physid pages as long as it is possible, I measured what would happen in a worst case: - A malicious guest runs with 2 vCPUs pinned, its first vCPU pounds on ICR sending IPIs to the 2nd vCPU and 2nd vCPU scheduled out forever and not halted (something that should not happen with Qemu though) - A normal guest with single vCPU is pinned to run on the same CPU as the 2nd vCPU of the first guest. The normal guest continued to run, but was observed to run about 40% slower. Therefore AVIC doorbel is strict by default but if the admin policy is to pin guests and not allow them to share a physical cpu, then strict doorbel can be set to false and that does improves the nested (and not nested as well) AVIC perf futher. Suggestions, comments are welcome. Best regards, Maxim Levitsky Maxim Levitsky (10): KVM: x86: mmu: allow to enable write tracking externally x86: KVMGT: use kvm_page_track_write_tracking_enable KVM: x86: mmu: add gfn_in_memslot helper KVM: x86: mmu: tweak fast path for emulation of access to nested NPT pages KVM: x86: lapic: don't allow to change APIC ID when apic acceleration is enabled KVM: x86: SVM: remove avic's broken code that updated APIC ID KVM: x86: SVM: move avic state to separate struct KVM: x86: rename .set_apic_access_page_addr to reload_apic_access_page KVM: nSVM: implement support for nested AVIC KVM: SVM: allow to avoid not needed updates to is_running arch/x86/include/asm/kvm-x86-ops.h | 2 +- arch/x86/include/asm/kvm_host.h | 5 +- arch/x86/include/asm/kvm_page_track.h | 1 + arch/x86/kvm/Kconfig | 3 - arch/x86/kvm/lapic.c | 28 +- arch/x86/kvm/mmu.h | 8 +- arch/x86/kvm/mmu/mmu.c | 21 +- arch/x86/kvm/mmu/page_track.c | 10 +- arch/x86/kvm/svm/avic.c | 949 ++++++++++++++++++++++++-- arch/x86/kvm/svm/nested.c | 131 +++- arch/x86/kvm/svm/svm.c | 31 +- arch/x86/kvm/svm/svm.h | 165 ++++- arch/x86/kvm/trace.h | 140 +++- arch/x86/kvm/vmx/vmx.c | 8 +- arch/x86/kvm/x86.c | 17 +- drivers/gpu/drm/i915/Kconfig | 1 - drivers/gpu/drm/i915/gvt/kvmgt.c | 5 + include/linux/kvm_host.h | 10 +- 18 files changed, 1413 insertions(+), 122 deletions(-)