Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp876422iog; Mon, 13 Jun 2022 15:06:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9vStpHBupBF7ZY7UrqPXYhYQBaFKRIctYFkEUjbU6hNrzbgbcRuLi3VLb2AraiDP5POsU X-Received: by 2002:a05:6a00:c5:b0:51b:c452:47ce with SMTP id e5-20020a056a0000c500b0051bc45247cemr1427110pfj.52.1655158012803; Mon, 13 Jun 2022 15:06:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655158012; cv=none; d=google.com; s=arc-20160816; b=yeVMPAmYUlFfHUNv/R1I4d77AuhJLROSwVSvy3zIoqtIvcJhVBAQN5mEON4gyxMGj+ uwF3b5LmWkZWb0fje5FO+q3d2juBXX6ph2Dlrur8A2o8umidUbRqU9bVI5teAo3p2fm2 7DVm169//2yslFtIQX/OoWQkK9v0YanxCPXA/FHQlDzc69jqBDq6DZ4eqYvjf10UQncM zB2dyCVMXo8TgqQ9kOIOjErCaflMm41fgvpc7CBzyC3CYh7527GRw/bwkQZY1Up8KT0E 2s9UK3E/BJTGlExtGny1FjTxa0eUNdyE+oLjSNaqpL8ndyEMq4GktguNDP2eC4s2NARw /uew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :reply-to:dkim-signature; bh=RVy85ULONsPMosb1NmFt3NRY87u30o0irh/ZWjWjAQQ=; b=urrJopu5e5t0z3tT7weZ5tuAl8dDq5DgiZ9XKLS8P9/dc5cMZlInRAWw4fAI9uPQyL irSX1azWiy3TQrDnQHtfvhBfOZlA7gHRAkFoOwUldzP3ZIOnukzvJHBHJJzCiB7Zo8vF M6bikBEMC6OdOIg98YTyHStjTwcoyG6YSBdizImWR2Btog1RHmB7NEiKpY5XAlJsKh5y 6UL858Z1t2478AivFukEFgf09juaFMRkIzMD8LlzUGBbL3+GlSjeQ/zbzBoe55C/7bL0 lfg9cOFo3tTT9RKSM5+X7cBA2QXyRUyt2bJX2Ai3DnpY9r8DG/zPim5B4jBa+IAfYCFe 3TQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=SEpiP60S; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l63-20020a638842000000b0040628bc8591si6769871pgd.506.2022.06.13.15.06.40; Mon, 13 Jun 2022 15:06:52 -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=@google.com header.s=20210112 header.b=SEpiP60S; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240307AbiFMVmu (ORCPT + 99 others); Mon, 13 Jun 2022 17:42:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244210AbiFMVmr (ORCPT ); Mon, 13 Jun 2022 17:42:47 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4114C60FC for ; Mon, 13 Jun 2022 14:42:46 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id b9-20020a656689000000b003f672946300so3927892pgw.16 for ; Mon, 13 Jun 2022 14:42:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:message-id:mime-version:subject:from:to:cc; bh=RVy85ULONsPMosb1NmFt3NRY87u30o0irh/ZWjWjAQQ=; b=SEpiP60SyyDEf/Tnm3zpDuQbs8gKvGqZQWxGmHhqNnIx2TWH/CkGAZ9qantBF7CRk6 a+mFjO2HObwDwvtZzU62OBzinGjx0MP01SfwVdRTRSFOoyxBVLH29eEbdeRYE423f9xF Kl7aaN0WWWwrEbZ7SzaEYVhle5y6gfBRLn2dRSuMQwWAIbtMaDQaJqEINEK1YclQi3Pq gwdYCsX72hMjPUGj7PQXWFrDRhuhvPK47GWICbL/v/nmgRvnjGnJuKVSx2r4BxQkgEno NMC7vp5Op6Ui4qJahNYCLavsZN7o7hfmv147En8DCOyi82LSOxm6QHeXQnKRAFt/NOHi n0Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:message-id:mime-version:subject :from:to:cc; bh=RVy85ULONsPMosb1NmFt3NRY87u30o0irh/ZWjWjAQQ=; b=cgOluZGVfxUjLl8O3TaZyDS4u2QZGcOeCN+SsaQnSoG7DVt90asurj5DAx+Kn7jtxg FeRfpO6eswRWrC2T6DqwAzLYZ4N2HeL/kTGQvQ9hVCCtb59usG85pbAbkitEIeFAnsAN w6sBOlJXVHUxcAt7iw7b8hfvn914uXNvE9W5uiUTlitqvNc0UeaS3c4M1QGblsj4gzZi xWJ96tXKFVswpHpCxp0ob7mp7A4h80OBsQsrB9v7ODrID8gvYMQUb6lQvTqMRxQVUN52 fi5x8+GungyAvqzI+YyXag9lE1vsIGGdewY3f3bIL6VGQ1i8mSux3bdVRc6Ny9GoyEZK Yisw== X-Gm-Message-State: AJIora/GP+Q5jporh08VvPTTmK87Z3BVcJtXP6PnQxdwYhc3u4BHJ4ml on2s9XwWhYsJNuNDYGXpFZqnNYF2VF4= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:90a:178f:b0:1e3:3ba:c185 with SMTP id q15-20020a17090a178f00b001e303bac185mr47660pja.1.1655156565067; Mon, 13 Jun 2022 14:42:45 -0700 (PDT) Reply-To: Sean Christopherson Date: Mon, 13 Jun 2022 21:42:37 +0000 Message-Id: <20220613214237.2538266-1-seanjc@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH] KVM: SVM: Hide SEV migration lockdep goo behind CONFIG_DEBUG_LOCK_ALLOC From: Sean Christopherson To: Paolo Bonzini , Nathan Chancellor , Nick Desaulniers Cc: Sean Christopherson , 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 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. 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