From patchwork Tue Jan 10 15:25:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 13095293 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 101C3C46467 for ; Tue, 10 Jan 2023 15:26:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238891AbjAJP0X (ORCPT ); Tue, 10 Jan 2023 10:26:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238936AbjAJPZ4 (ORCPT ); Tue, 10 Jan 2023 10:25:56 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A95D08F28D for ; Tue, 10 Jan 2023 07:25:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=MIME-Version:Content-Type:Date:Cc:To: From:Subject:Message-ID:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:In-Reply-To:References; bh=T8Obw+7sjFmbKysBeUKTza7vyg9gBvKU2wHfICs3Syc=; b=RsAejYPzPUIkQLba5Ot9s2f1dT 8wu5KzgGfebovUBs9s9arHC5bW6d+V0mj4/R9Oyi8V4bcnj/5xIUBQWgOJd93ixxuHeizy+iu2BfH 0Un4EUi6AQ3ZCW/yl3M0mj1MBrM/YXvxHQYEIOrVWiTrbruOoZjw4Cmd/bMPufVMi7VHOZsDu04Lb GD9wASEDtPytUB8VP/sZ1SvZ0Mm2CIt075zLIH5X6GtnKrOruoD7yfZYXLiUacUxv+B+CFaI5tKfH UE4klWlyIZKEyhX0XxlH9lRyUxhqNU3VdzVndlnx7DGwCd4YUOgSvR9tU8xeo4N3FVya3hAIRjuih vg2pNr6w==; Received: from [2001:8b0:10b:5::bb3] (helo=u3832b3a9db3152.ant.amazon.com) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFGVO-003K6I-FX; Tue, 10 Jan 2023 15:25:38 +0000 Message-ID: <99b1da6ca8293b201fe0a89fd973a9b2f70dc450.camel@infradead.org> Subject: [PATCH] KVM: x86/xen: Fix lockdep warning on "recursive" gpc locking From: David Woodhouse To: Paolo Bonzini , paul , Sean Christopherson Cc: kvm , Peter Zijlstra Date: Tue, 10 Jan 2023 15:25:24 +0000 User-Agent: Evolution 3.44.4-0ubuntu1 MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: David Woodhouse In commit 5ec3289b31 ("KVM: x86/xen: Compatibility fixes for shared runstate area") we declared it safe to obtain two gfn_to_pfn_cache locks at the same time: /* * The guest's runstate_info is split across two pages and we * need to hold and validate both GPCs simultaneously. We can * declare a lock ordering GPC1 > GPC2 because nothing else * takes them more than one at a time. */ However, we forgot to tell lockdep. Do so, by setting a subclass on the first lock before taking the second. Fixes: 5ec3289b31 ("KVM: x86/xen: Compatibility fixes for shared runstate area") Suggested-by: Peter Zijlstra Signed-off-by: David Woodhouse --- arch/x86/kvm/xen.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index 402d9a34552c..07e61cc9881e 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -305,8 +305,10 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic) * The guest's runstate_info is split across two pages and we * need to hold and validate both GPCs simultaneously. We can * declare a lock ordering GPC1 > GPC2 because nothing else - * takes them more than one at a time. + * takes them more than one at a time. Set a subclass on the + * gpc1 lock to make lockdep shut up about it. */ + lock_set_subclass(&gpc1->lock.dep_map, 1, _THIS_IP_); read_lock(&gpc2->lock); if (!kvm_gpc_check(gpc2, user_len2)) {