From patchwork Thu Mar 16 21:14:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 13178319 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id A667FC74A5B for ; Thu, 16 Mar 2023 21:15:23 +0000 (UTC) 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=qgyivPrPioeqsCCHCXUXyZkw9PlkK9p2Pk2ZGOOJwto=; b=IwhTid1M8iZ5+F MJeBeQk2wi4KMd8nxuUekx9xHS8U9yPdS1fl8n3L09gQbQw2VHLZsvqfgpINmVTG+934ikDwGo86p K+91F7t0fD4H3HeM7txkeCptJxUzm6uuVkfHfQciv6nnkj103xlg/KiQ1ZbBykU0JCL/AMBf2E+h7 4oPqmdTht/26912VXGufCqmxCg7eOXrm9PVTgi83Y4/I9qwTj0cp6+T9NDb+I9oQ+qN5mPnftyvyH /5RROCs2Pm463f9hLcrPADJ3JVt7gLDQZHSwu1DAKQXysf3lb6eMrzWlkMF2ZC+SSypRrL3FtbAqJ meOYDkcbjhh/2DoLnRvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcuvi-0000ae-0r; Thu, 16 Mar 2023 21:14:34 +0000 Received: from out-48.mta1.migadu.com ([2001:41d0:203:375::30]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcuvf-0000Yf-01 for linux-arm-kernel@lists.infradead.org; Thu, 16 Mar 2023 21:14:33 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1679001265; 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=1YvQL41zYrATTU0Luq6nSMyn7+ylWGdh70Ui67rDKGE=; b=Jn8eQfS8Aeyuvk+lHWpWVSAkcidsRIcEvCBjwq77VzYkm0qIpgiayEliE9evOLXw4SqQjP lxVPSBFvP4BiGtcxNa3rLbAKd218kByPHam2JyLAtVmaZF8ImT6R/WSr+mDWXJ22bjZ5ti WFD6ms6klL7pKC5zg4TJv9WVfLv0QIU= From: Oliver Upton To: Marc Zyngier Cc: James Morse , Suzuki K Poulose , kvmarm@lists.linux.dev, Zenghui Yu , linux-arm-kernel@lists.infradead.org, Sean Christopherson , Oliver Upton Subject: [PATCH v2 0/4] KVM: arm64: Fix vcpu->mutex v. kvm->lock inversion Date: Thu, 16 Mar 2023 21:14:08 +0000 Message-Id: <20230316211412.2651555-1-oliver.upton@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230316_141431_497174_A65D8FB4 X-CRM114-Status: UNSURE ( 9.01 ) X-CRM114-Notice: Please train this message. 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 As it so happens, lock ordering in KVM/arm64 is completely backwards. There's a significant amount of VM-wide state that needs to be accessed from the context of a vCPU. Until now, this was accomplished by acquiring the kvm->lock, but that cannot be nested within vcpu->mutex. This series fixes the issue with some fine-grained locking for MP state and a new, dedicated mutex that can nest with both kvm->lock and vcpu->mutex. Tested with kvmtool and QEMU scaled up to 64 vCPUs on a kernel w/ lockdep enabled. Applies to kvmarm/next. v1: http://lore.kernel.org/kvmarm/20230308083947.3760066-1-oliver.upton@linux.dev v1 -> v2: - Add a dedicated lock for serializing writes to MP state - Inform lockdep of acquisition order at time of VM/vCPU creation - Plug a race with GIC creation (Sean) - Use the config_lock in GIC ITS flows as well. There is now a single (valid) use of kvm->lock when enabling MTE. Oliver Upton (4): KVM: arm64: Avoid vcpu->mutex v. kvm->lock inversion in CPU_ON KVM: arm64: Avoid lock inversion when setting the VM register width KVM: arm64: Use config_lock to protect data ordered against KVM_RUN KVM: arm64: Use config_lock to protect vgic state arch/arm64/include/asm/kvm_host.h | 4 ++ arch/arm64/kvm/arm.c | 45 +++++++++++++++++++---- arch/arm64/kvm/guest.c | 2 + arch/arm64/kvm/hypercalls.c | 4 +- arch/arm64/kvm/pmu-emul.c | 23 +++--------- arch/arm64/kvm/psci.c | 19 +++++----- arch/arm64/kvm/reset.c | 16 ++++---- arch/arm64/kvm/vgic/vgic-debug.c | 8 ++-- arch/arm64/kvm/vgic/vgic-init.c | 33 ++++++++++------- arch/arm64/kvm/vgic/vgic-its.c | 29 ++++++--------- arch/arm64/kvm/vgic/vgic-kvm-device.c | 53 ++++++++++++--------------- arch/arm64/kvm/vgic/vgic-mmio-v3.c | 4 +- arch/arm64/kvm/vgic/vgic-mmio.c | 12 +++--- arch/arm64/kvm/vgic/vgic-v4.c | 11 +++--- arch/arm64/kvm/vgic/vgic.c | 2 +- 15 files changed, 146 insertions(+), 119 deletions(-) Tested-by: Jeremy Linton