From patchwork Mon Jun 13 21:42:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12880235 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 0BC8BC43334 for ; Mon, 13 Jun 2022 21:42:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348713AbiFMVms (ORCPT ); Mon, 13 Jun 2022 17:42:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240307AbiFMVmr (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 1BD2360F7 for ; Mon, 13 Jun 2022 14:42:46 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id y2-20020a655b42000000b0040014afa54cso3921939pgr.21 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=n7xmqYontuBaoCFxUDuOec6VTBV1EhzfihmYPj4+GBQapy/lHukMn3DBI053uSJDZa 5iqUp52Llv6Tj+j15bsCRkEPRHzurJRObPA6aW7Xa9e6SkaUGAxoHhY26lkm6he1SmEn JUSrvmoGZKdVdBik54ZQJ7+YdLlC7Oahz/EKaZCuboj7F9/nBzWIRRodUt2JeXZp4cvk eVdvM6XVWXphLxNE3jbu9iaZF+S8bj5ogyPyhIE/LaSH8fpcgBH5npDn8hGFsTqywake QL8HNKJjLC4CYLVDwPqwfb7EDWHrlnK6XMTC3GMiMidMk/csRQ3oYrrZuhh2ArjKBlAJ 7hwA== X-Gm-Message-State: AJIora9WyPJRRVQC7aThg2JP/at9XTZT2w50e1areTuhlh9GtB57o2sd DDIJsNn0CHQ626FvqJsLDSi0uBl0KeU= X-Google-Smtp-Source: AGRyM1urKA7NScvmeBtxVRmnJcZPpHOq5ewz3AmNrW84SUP+NUFAo6x/+herBNp05LNlC6l+fSWyWo0gPnY= 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 Precedence: bulk List-ID: X-Mailing-List: kvm@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 Tested-by: Nathan Chancellor # build --- 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(-) base-commit: 8baacf67c76c560fed954ac972b63e6e59a6fba0 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); }