From patchwork Wed Nov 17 17:39:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 12692983 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0884DC433F5 for ; Wed, 17 Nov 2021 17:49:59 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C224361BA2 for ; Wed, 17 Nov 2021 17:49:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C224361BA2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=3ewVSDiiTL7jou0rOVd2UA2HrxOu0OydxyqJAt5HcAs=; b=Tl+r0YImPNSv5m WC2AL6rm4n5biyQf2v/zu98vzLV4Gqj+RpoX0n4HjkHLLtRSaDUgAlCckK8wXj0GrAWd9sCAxRoA9 Mx1y6vLwm+zQrtdR5E25oD9WKamt4/wVlXov261JTPu03lTuZwiQM7q7H6sVeRycFTo+aZpkPsvUJ DGhCEFmI3pr3ZihF3o803xCc3LJn06tTEzd7fTtGgBCGeoE4YbXpdBj6I1kYdsLR7nRwlGAyAXlJb hQE8q8VcOSH7B9jIse2X2IXhbPaGED7Gc+RhkKc1P/Io3Og5JmrxAwtI8MLz/IEXCIpaNtVwnUHd8 1LyTCq9F4nFAP5PD1bUw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnP2M-005w1l-4W; Wed, 17 Nov 2021 17:47:58 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnOv2-005tTB-LN; Wed, 17 Nov 2021 17:40:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To: Content-ID:Content-Description:In-Reply-To:References; bh=1uTmVWceFyeFzFF12Kb1AEwgWDvyhf/Bhrlut32WigU=; b=FA7jlDlOgsISqwIPXDH2Ot6bQj wU8RQi496K1TElvPccyBBkKObng9I/ztfWUm9if2d0ZlgxdzXERI2F2w16p/G1N+LGJK5gQ55Imt3 2LYwOYo2ej6ez/YUwJUICBTPIlDyM00AjzcfyJECnVvr8A3VHa5mfauKjfLPgQ8XmaOqXVST4VkC9 r7vEjmROPKF5D0aOb28MqmMJbqbNCReEZmjntJIXE3Y/yclHKPpzWp0maRBd4xwuDjPqeRN3G0j8j ua317PE4jft5Ek/d1EkWWz/6UQpufMevbcHTjYgB9ErEGup9Yv1zpvhbF1t4S1ODBCKh/vuqTwoAr Apx47PCA==; Received: from i7.infradead.org ([2001:8b0:10b:1:21e:67ff:fecb:7a92]) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnOum-00GXWZ-Cq; Wed, 17 Nov 2021 17:40:08 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnOum-001GxB-2V; Wed, 17 Nov 2021 17:40:08 +0000 From: David Woodhouse To: Paolo Bonzini , kvm Cc: Boris Ostrovsky , Joao Martins , "jmattson @ google . com" , "wanpengli @ tencent . com" , "seanjc @ google . com" , "vkuznets @ redhat . com" , "mtosatti @ redhat . com" , "joro @ 8bytes . org" , karahmed@amazon.com, Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon , Huacai Chen , Aleksandar Markovic , Michael Ellerman , Benjamin Herrenschmidt , Anup Patel , Christian Borntraeger , kvmarm@lists.cs.columbia.edu, linux-arm-kernel , linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-s390@vger.kernel.org Subject: [PATCH v3 00/12] KVM: x86/xen: Add in-kernel Xen event channel delivery Date: Wed, 17 Nov 2021 17:39:51 +0000 Message-Id: <20211117174003.297096-1-dwmw2@infradead.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by desiato.infradead.org. See http://www.infradead.org/rpr.html X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Event channels, yeah. That really is where I started. It was all so simple in Joao and Ankur's original version at https://www.spinics.net/lists/kvm/msg182556.html — just a handful of simple test_and_set_bit() calls on the mapped page. When I posted v1 I didn't quite understand how steal time and nesting were safely using the kvm_map_gfn() function, and I posted the Xen part declaring that I had "reduced it to a previously solved problem". Then I frowned at kvm_map_gfn() for a bit longer, concluded it was basically impossible to use it safely on its own because the page it maps might belong to another guest by the time it even returns to its caller, and posted a v2 in which I did something safer for myself by hooking into the MMU notifiers. I then fixed the steal time reporting, and killed gfn_to_pfn_cache, under separate cover. In v3 of this series I re-introduce a saner gfn_to_pfn_cache with MMU notifier support to give it proper invalidation semantics. This can now be used for the Xen event channel support and should also be usable for fixing the various use-after-free races in the nesting code too — the last patch in this series being an untested proof of concept attempt at fixing one such. Since adding a C file in virt/kvm/ was somewhat more painful than it really should have been, there is a small detour into all the arch specific Makefiles to make them include a common one. Intended for merging up to patch 11. Patch 12 is for illustration. David Woodhouse (12): KVM: Introduce CONFIG_HAVE_KVM_DIRTY_RING KVM: Add Makefile.kvm for common files, use it for x86 KVM: s390: Use Makefile.kvm for common files KVM: mips: Use Makefile.kvm for common files KVM: RISC-V: Use Makefile.kvm for common files KVM: powerpc: Use Makefile.kvm for common files KVM: arm64: Use Makefile.kvm for common files KVM: Propagate vcpu explicitly to mark_page_dirty_in_slot() KVM: Reinstate gfn_to_pfn_cache with invalidation support KVM: x86/xen: Maintain valid mapping of Xen shared_info page KVM: x86/xen: Add KVM_IRQ_ROUTING_XEN_EVTCHN and event channel delivery KVM: x86: First attempt at converting nested virtual APIC page to gpc Documentation/virt/kvm/api.rst | 21 ++ arch/arm64/kvm/Makefile | 6 +- arch/arm64/kvm/mmu.c | 2 +- arch/mips/kvm/Makefile | 3 +- arch/powerpc/kvm/Makefile | 6 +- arch/riscv/kvm/Makefile | 6 +- arch/s390/kvm/Makefile | 6 +- arch/x86/include/asm/kvm_host.h | 4 +- arch/x86/kvm/Kconfig | 2 + arch/x86/kvm/Makefile | 7 +- arch/x86/kvm/irq_comm.c | 12 + arch/x86/kvm/mmu/mmu.c | 2 +- arch/x86/kvm/mmu/spte.c | 2 +- arch/x86/kvm/mmu/tdp_mmu.c | 2 +- arch/x86/kvm/vmx/nested.c | 50 +++- arch/x86/kvm/vmx/vmx.c | 12 +- arch/x86/kvm/vmx/vmx.h | 2 +- arch/x86/kvm/x86.c | 17 +- arch/x86/kvm/xen.c | 287 +++++++++++++++++++-- arch/x86/kvm/xen.h | 9 + include/linux/kvm_dirty_ring.h | 14 +- include/linux/kvm_host.h | 100 ++++++- include/linux/kvm_types.h | 18 ++ include/uapi/linux/kvm.h | 11 + .../testing/selftests/kvm/x86_64/xen_shinfo_test.c | 112 +++++++- virt/kvm/Kconfig | 6 + virt/kvm/Makefile.kvm | 14 + virt/kvm/dirty_ring.c | 10 +- virt/kvm/kvm_main.c | 34 ++- virt/kvm/{mmu_lock.h => kvm_mm.h} | 23 +- virt/kvm/pfncache.c | 281 ++++++++++++++++++++ 31 files changed, 992 insertions(+), 89 deletions(-)