Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4721935ioa; Wed, 27 Apr 2022 09:39:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyKgG5oEhxd5P3xJTl/WxyOAF3w/xxrrqVkr5Y7lDH7pivfYMYdplaQBIx7vCXeYQFAh8P X-Received: by 2002:a17:90b:4cd2:b0:1d9:7a88:402f with SMTP id nd18-20020a17090b4cd200b001d97a88402fmr18119377pjb.151.1651077564239; Wed, 27 Apr 2022 09:39:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651077564; cv=none; d=google.com; s=arc-20160816; b=Xr9BA6xG63Af0Wd7baSLssQeaQTOM2Dqarl3XHubI+9LuhcHEWbPUxI/SH9uFaWC47 qrM0SmHPZxjQ5AwfJih8MFF0fT7Z97kiu8k24R/lX1OnUVawdW55pgFxVo4bvuuAqJaS TciQx4hCrsQNKhtcuFJvQayhKWtiJbbgmaV418N5f2GY1TfoV20Wi4mJIRxGJbO+8VA1 /4Yl5EJGQGZGs6qJnAIAnWHahN4BZxHlCROJswCDaOAjCyVNe8b64WVp5lp3qcl8VloG 8KkPmIfnB07esBlJTD1Bjj1x2rH7CfQjpnKovuoxPcTkj99NFYPcCaaPVmFQjOtIKkJH kddQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :from:references:cc:to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=KnIiu4aHbqX/cEMaulV4w/SJ9uqmiCPjBFKvPiEFRe0=; b=gw/6vCz7pPTiMo04WM90eSObay96fdOnaVsXw84NOTpXVfikAm/loQHmf3jPxS1CRY EVyPVI3QMvUlvWfEqUgTL/i/O48/V5acATK3yDUF/tQ4QoqXwcdYMISLF5Fr2rImZX84 qiLoQ7sMXTH8FA+gRnR3Bylnclhh9dSuxTq7w+qRJwS/Nl4aXWhdAwuL2RWIfWSTwzuo FrIfh+ZtcK4RbG7ldhyPRft2w0Crt67S2uh1hM4pN+C+T7O931iZ27mz/C6X7xavFx1+ B1gb78TSDvkyjHd0orfU16KjTx+uZ+/t0Gljbw85I2g53iz+9t7B9ssA6fVf5tXZe4t8 SOew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="ZbM/bSao"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id ot7-20020a17090b3b4700b001caa6143ea5si6673851pjb.10.2022.04.27.09.39.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:39:24 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="ZbM/bSao"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5E8B6C44C7; Wed, 27 Apr 2022 09:08:54 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242040AbiD0QL2 (ORCPT + 99 others); Wed, 27 Apr 2022 12:11:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241941AbiD0QKO (ORCPT ); Wed, 27 Apr 2022 12:10:14 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 99DA84928A0 for ; Wed, 27 Apr 2022 09:06:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651075469; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KnIiu4aHbqX/cEMaulV4w/SJ9uqmiCPjBFKvPiEFRe0=; b=ZbM/bSao9pb6CIyufmGWRbOYzGhbLIef3frQ9X1tGTYW+3npTBwObhtXj4skWlzQXUX+bP eLX25AbfoZy7jOiwabf2+uHI5CAyzth621QjgcMF5xFHSfViXLDVkq4pvlsCDdme2nH7Xc kVpxpUXrMFmrQKPbQRgP6qnMZ51OtYU= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-402-MRH8tKArMmmMWd6vgyN90Q-1; Wed, 27 Apr 2022 12:04:27 -0400 X-MC-Unique: MRH8tKArMmmMWd6vgyN90Q-1 Received: by mail-ej1-f71.google.com with SMTP id nd34-20020a17090762a200b006e0ef16745cso1403704ejc.20 for ; Wed, 27 Apr 2022 09:04:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:subject:in-reply-to :content-transfer-encoding; bh=KnIiu4aHbqX/cEMaulV4w/SJ9uqmiCPjBFKvPiEFRe0=; b=STezYEe0da2Bn2f6bBUbQ+SHTKa3eCZc+lOX7cHBN2Wse1avOWsnSNgwCb2Pg1adm0 FvY/NzAJXr6XOL7yXlNYhqXzRtUwQgR2AjX3dUU2R1VV7vD2lIvqbkN6nWQWVfeSNV/8 LWib6aGwSy090VgoVQA90/AQobk1s0Y+RZV4PcBeyIMuXXVE7lza+eLipYIyhn1kLdV+ ix+G2XPrRq2kSj3cU3ZT48l/VmbKvM5Ad+M2p9aWdqMl4K1EWv9g8YQ+E+zno1xyjTvl SffB8Dd5GYmX8JfAGAtKz0aW+Gu+rmKYbYexYWJ14l4kDAxum7x7qPDjmPeaSrM3u0Ag ZX+w== X-Gm-Message-State: AOAM530Pd53kadlx0PLkN5CeQsHWaVkfSW/77ZucouOzaJvGuiqTCrm0 gRfY51eEN4yaJsH7D+jLjrIYotWuGh+ktrS7w1o0n6xAFioQjPv2651tGGBF/B2Gr2P+nRhP0C/ 85/7O8uCKmIYzR5zx+L04ch90 X-Received: by 2002:a17:907:7ea3:b0:6e8:92eb:3dcc with SMTP id qb35-20020a1709077ea300b006e892eb3dccmr27624645ejc.75.1651075466149; Wed, 27 Apr 2022 09:04:26 -0700 (PDT) X-Received: by 2002:a17:907:7ea3:b0:6e8:92eb:3dcc with SMTP id qb35-20020a1709077ea300b006e892eb3dccmr27624614ejc.75.1651075465846; Wed, 27 Apr 2022 09:04:25 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:1c09:f536:3de6:228c? ([2001:b07:6468:f312:1c09:f536:3de6:228c]) by smtp.googlemail.com with ESMTPSA id z12-20020a50f14c000000b00425d61cbb0esm6345687edl.22.2022.04.27.09.04.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Apr 2022 09:04:24 -0700 (PDT) Message-ID: <4c0edc90-36a1-4f4c-1923-4b20e7bdbb4c@redhat.com> Date: Wed, 27 Apr 2022 18:04:23 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Content-Language: en-US To: Peter Gonda Cc: John Sperbeck , kvm list , David Rientjes , Sean Christopherson , LKML References: <20220407195908.633003-1-pgonda@google.com> <62e9ece1-5d71-f803-3f65-2755160cf1d1@redhat.com> From: Paolo Bonzini Subject: Re: [PATCH v3] KVM: SEV: Mark nested locking of vcpu->lock In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE 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 On 4/26/22 21:06, Peter Gonda wrote: > On Thu, Apr 21, 2022 at 9:56 AM Paolo Bonzini wrote: >> >> On 4/20/22 22:14, Peter Gonda wrote: >>>>>> svm_vm_migrate_from() uses sev_lock_vcpus_for_migration() to lock all >>>>>> source and target vcpu->locks. Mark the nested subclasses to avoid false >>>>>> positives from lockdep. >>>> Nope. Good catch, I didn't realize there was a limit 8 subclasses: >>> Does anyone have thoughts on how we can resolve this vCPU locking with >>> the 8 subclass max? >> >> The documentation does not have anything. Maybe you can call >> mutex_release manually (and mutex_acquire before unlocking). >> >> Paolo > > Hmm this seems to be working thanks Paolo. To lock I have been using: > > ... > if (mutex_lock_killable_nested( > &vcpu->mutex, i * SEV_NR_MIGRATION_ROLES + role)) > goto out_unlock; > mutex_release(&vcpu->mutex.dep_map, _THIS_IP_); > ... > > To unlock: > ... > mutex_acquire(&vcpu->mutex.dep_map, 0, 0, _THIS_IP_); > mutex_unlock(&vcpu->mutex); > ... > > If I understand correctly we are fully disabling lockdep by doing > this. If this is the case should I just remove all the '_nested' usage > so switch to mutex_lock_killable() and remove the per vCPU subclass? Yes, though you could also do: bool acquired = false; kvm_for_each_vcpu(...) { if (acquired) mutex_release(&vcpu->mutex.dep_map, _THIS_IP_); if (mutex_lock_killable_nested(&vcpu->mutex, role) goto out_unlock; acquired = true; ... and to unlock: bool acquired = true; kvm_for_each_vcpu(...) { if (!acquired) mutex_acquire(&vcpu->mutex.dep_map, 0, role, _THIS_IP_); mutex_unlock(&vcpu->mutex); acquired = false; } where role is either 0 or SINGLE_DEPTH_NESTING and is passed to sev_{,un}lock_vcpus_for_migration. That coalesces all the mutexes for a vm in a single subclass, essentially. Paolo