Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp886520iog; Mon, 13 Jun 2022 15:22:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxypvk2i4HQbYY3KXSdRj9NSehs5EO/jNcPJv5Ho47NNafkuSTtfgbt+5y5UikOM9dtUPkB X-Received: by 2002:a17:906:38d0:b0:715:8483:e01e with SMTP id r16-20020a17090638d000b007158483e01emr1646065ejd.265.1655158950406; Mon, 13 Jun 2022 15:22:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655158950; cv=none; d=google.com; s=arc-20160816; b=tP7S3WJArnjkA0yf6YH1Da4iwV8XtryhKI7z2nPk7jOUDBGD5cwqHwtFbOGTLET8/k QoXjU+B/NatwSUD0URHuSi1ZR217raRqSuu9qyRts+fPZTqnz5WSptqss/xxzAm2j/2r tYGOJCwkqq5xVhQBtUTFj7JlXLSbYJ4xtBOCEitYeEAn0UHwHrWh/dZyl+mbA1afTqEc idGdJfdLzALYBwLueUQkIGWPhz/oXnxQoCAHAhdDxlejdT9sd9yWsJ1v60lYuEu5h/3F YGpLhzHWvIVPDMGYWEy4s/4GlWJLuH1UR35u3M02SE4Kw56dpF/t3uhdzUljYr6aSj8J WTFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=43SFCJXVN7+IAKZSqw8pITCdLVA3g3heXQJR5kHfKTU=; b=Sm0kFWqkd8ehGkS8HWM9dIX8Y8UTsMr1rrojJOl4C7rJu6APJlAzLxqc5OG7dAS2Ar JTR7IeHpvy9jbyJxmVfQoaV9iI7zDYZVewvUqN0cjwJTZJgtH8SiISJMkt+NSlxkZXMl 1q2cDBiznV+KNdLoj2+jrb8UgTF3/F8gd7dNsZ2KtvN7l1keN+uws+n2VBK9iEepnKaK T9Fh8tCXptvfcXB8w1xlC0PXjQ3Cf5yu33yLA48c+dRYYxqMmDCsxaUBGJcCqiJquC1N qsaiPtUJSiFBbT64tjavLSy4H4ClyxrP/EtJPduNEQHA/wPSiScv5UccW5frIja8ijzH H1PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ufD63Bee; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j7-20020a05640211c700b0042bd2c39f07si9840065edw.596.2022.06.13.15.22.05; Mon, 13 Jun 2022 15:22:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ufD63Bee; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244172AbiFMVvv (ORCPT + 99 others); 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> X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 > >