From mboxrd@z Thu Jan 1 00:00:00 1970 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 6B664CCA47B for ; Mon, 13 Jun 2022 21:51:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240114AbiFMVvv (ORCPT ); Mon, 13 Jun 2022 17:51:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230444AbiFMVvt (ORCPT ); Mon, 13 Jun 2022 17:51:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8805E18B38; Mon, 13 Jun 2022 14:51:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1A3C8614A3; Mon, 13 Jun 2022 21:51:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7D2BC34114; Mon, 13 Jun 2022 21:51:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655157107; bh=DCjyDdz9XYX5R8qanr7z720XrBNBAxLhIEwjktiLU3A=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ufD63Beez0sbUqWjHqSRuRzUM3wI+6aAZlh1bK20GbnupnMOR0wVBO/ywvRFxQ4ut 6n4ABCHvgK9RZkoWgY1TMIBxnXndt4Msa2/NR4+ep30Wly+k1odvnzo6EMTAp6Np9W H+HCbf78dvTgeIw6kgtdy3Kavy+QJFRlNBN/62WkOXZ+AhnBW4HYft42wOzgJtSxV6 qXE20pNb4cPUTyRdSgcpnpxgDsi1IehVvDQvJgbpkXpGEMWpFBnAAeUxp73fJK1iCl pSYpvVUqg/InWfwMOv5Z6h2XMeKe3s80Jxfs9UiIwGaHkit3iXD8IB6abzzjrmRUa/ qCj4vll7VWYJQ== Date: Mon, 13 Jun 2022 14:51:45 -0700 From: Nathan Chancellor To: Sean Christopherson Cc: Paolo Bonzini , Nick Desaulniers , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Tom Rix , kvm@vger.kernel.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org, Peter Gonda Subject: Re: [PATCH] KVM: SVM: Hide SEV migration lockdep goo behind CONFIG_DEBUG_LOCK_ALLOC Message-ID: References: <20220613214237.2538266-1-seanjc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220613214237.2538266-1-seanjc@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 13, 2022 at 09:42:37PM +0000, Sean Christopherson wrote: > Wrap the manipulation of @role and the manual mutex_{release,acquire}() > invocations in CONFIG_PROVE_LOCKING=y to squash a clang-15 warning. When > building with -Wunused-but-set-parameter and CONFIG_DEBUG_LOCK_ALLOC=n, > clang-15 seees there's no usage of @role in mutex_lock_killable_nested() > and yells. PROVE_LOCKING selects DEBUG_LOCK_ALLOC, and the only reason > KVM manipulates @role is to make PROVE_LOCKING happy. > > To avoid true ugliness, use "i" and "j" to detect the first pass in the > loops; the "idx" field that's used by kvm_for_each_vcpu() is guaranteed > to be '0' on the first pass as it's simply the first entry in the vCPUs > XArray, which is fully KVM controlled. kvm_for_each_vcpu() passes '0' > for xa_for_each_range()'s "start", and xa_for_each_range() will not enter > the loop if there's no entry at '0'. > > Fixes: 0c2c7c069285 ("KVM: SEV: Mark nested locking of vcpu->lock") > Reported-by: kernel test robot > Cc: Peter Gonda > Signed-off-by: Sean Christopherson > --- > > Compile tested only, still haven't figured out why SEV is busted on our > test systems with upstream kernels. I also haven't verified this squashes > the clang-15 warning, so a thumbs up on that end would be helpful. I can confirm that with the config that the kernel test robot provided, the warning disappears with this patch. If it is useful: Tested-by: Nathan Chancellor # build > arch/x86/kvm/svm/sev.c | 17 +++++++---------- > 1 file changed, 7 insertions(+), 10 deletions(-) > > diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c > index 51fd985cf21d..309bcdb2f929 100644 > --- a/arch/x86/kvm/svm/sev.c > +++ b/arch/x86/kvm/svm/sev.c > @@ -1606,38 +1606,35 @@ static int sev_lock_vcpus_for_migration(struct kvm *kvm, > { > struct kvm_vcpu *vcpu; > unsigned long i, j; > - bool first = true; > > kvm_for_each_vcpu(i, vcpu, kvm) { > if (mutex_lock_killable_nested(&vcpu->mutex, role)) > goto out_unlock; > > - if (first) { > +#ifdef CONFIG_PROVE_LOCKING > + if (!i) > /* > * Reset the role to one that avoids colliding with > * the role used for the first vcpu mutex. > */ > role = SEV_NR_MIGRATION_ROLES; > - first = false; > - } else { > + else > mutex_release(&vcpu->mutex.dep_map, _THIS_IP_); > - } > +#endif > } > > return 0; > > out_unlock: > > - first = true; > kvm_for_each_vcpu(j, vcpu, kvm) { > if (i == j) > break; > > - if (first) > - first = false; > - else > +#ifdef CONFIG_PROVE_LOCKING > + if (j) > mutex_acquire(&vcpu->mutex.dep_map, role, 0, _THIS_IP_); > - > +#endif > > mutex_unlock(&vcpu->mutex); > } > > base-commit: 8baacf67c76c560fed954ac972b63e6e59a6fba0 > -- > 2.36.1.476.g0c4daa206d-goog > >