Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3664800iob; Mon, 2 May 2022 02:20:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0j/dzy4UCPhHYVyBRge91C53cJVll3Tll+X4ZYcT3dv1+vTIe7NOhrHfQXYrj3kT5zPNH X-Received: by 2002:a05:6512:3ed:b0:472:3d9:7bdd with SMTP id n13-20020a05651203ed00b0047203d97bddmr8228483lfq.111.1651483238492; Mon, 02 May 2022 02:20:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651483238; cv=none; d=google.com; s=arc-20160816; b=QR6HX9Q6DKRLbMuw5Sa8O41CSyqcyD95rgMwIGhQmIRnIrgzhuBnX8nRBjv/ame0gA GWJAPSzwhF+eOqQFL0cDSynzWdBC3Ja1ml+8CobNTaZumprp4mVylnMR+dx7LJFVVBeN Xqu/luPStyVX1lfhA42nYkNyqs22UfB5uly5HIk28gQav4l1Gef2sTyDKKSC8LdZ+ilD Nk67Du82ptLBP57fyxwL+QGnMv/rhHegXSqpJDZu7BohhGv8F8B+9uFNTN2MRJJXbOBe CvFGl/a5EHMs+5gvpQBSv0mdWiPJ6reCjmCvKKCYQnD+BunLVXcFkrqoJAuJnSRszY2K Koag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=qfPh0kjKV7Wz4rw1eQJIM18yZvKQM4d4G44x6rYSMsU=; b=01L7266t81SafT8yoZK51vR/4TRDgbrk08IlZfNUkv5XoP5osvuM1FpmIH/yBj9G2u 6lhFUg/bxaRw2muI882EnuJziIkGn5QXE8wCmieKbDBqaveFyHbvtzveUYhXrKsYcSdo ctb9BTucAaX6VmlH4/a3fD6c8UDC+0odVPDq56wZwfv8IAhUNUfk6dmkNrXfc8RzR75U cUqko7bRIdM3UoPByIvFQa/QIvMmaLZrRXTtsQcTEzSe8aK1j9qXu9BUObpIYdU8sF8l XDD1pcmowySdhw63QhPxm5G9gwWYAqo/IHfhIpNBegh8P9O8MfQiExJ2QgRYNOYGdefR mcmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ak3wnRHL; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p12-20020a2eb98c000000b0024f0b1ce363si13081194ljp.514.2022.05.02.02.20.11; Mon, 02 May 2022 02:20:38 -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=@redhat.com header.s=mimecast20190719 header.b=Ak3wnRHL; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379656AbiD2RZY (ORCPT + 99 others); Fri, 29 Apr 2022 13:25:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379661AbiD2RZP (ORCPT ); Fri, 29 Apr 2022 13:25:15 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5FB0CC8642 for ; Fri, 29 Apr 2022 10:21:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651252907; 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: in-reply-to:in-reply-to:references:references; bh=qfPh0kjKV7Wz4rw1eQJIM18yZvKQM4d4G44x6rYSMsU=; b=Ak3wnRHLiHYnZVxdA3lHlaz7pKFMOD4jMLmbdXrVY2tgR9LUw2QidIx6lyNouLURV1TEss Dnb0VqA5X8Sqt+q2hxH9GoP/ffxVT8C7sQkp/AxJhH8VFZlo3UHxgrjWpo4HFdrqobP9WY kFrgd18gx+aPRjzhKh4dnxZYSZtbvKA= Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-83-dZZqh0KqMHmcIjaqKQ81kQ-1; Fri, 29 Apr 2022 13:21:46 -0400 X-MC-Unique: dZZqh0KqMHmcIjaqKQ81kQ-1 Received: by mail-pj1-f71.google.com with SMTP id gg5-20020a17090b0a0500b001d9852bd129so4339580pjb.9 for ; Fri, 29 Apr 2022 10:21:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=qfPh0kjKV7Wz4rw1eQJIM18yZvKQM4d4G44x6rYSMsU=; b=A5e3g6sb1TjjKIYbfrtQeeG0IlxkRqDnFf/64FtLtyvn8CTev+NtiOvfKnxbj06x4Y qwgv9Nsz8Fzk0tagseUdSwcemfzFPqHHGtC9ePf57I9s7gPd9Kttc6G9xRsMJVGSWJml Rx1uJMTjDSqU9NFwm/41f926uq9IlG6+GvthPi3UOrvJiCJiEiqgzTSQFNcTo38gZPUQ ojaf9fDfdf/aoc0BVsn89mgkDiBoQVqwezaEX94eF2mPeA1jzWJZzV83ohncEZqKEZ/q zR55BVOezF71522d4GynWmjgYKPYT+iTZCQ/8iDtvLWZmTAEZOdKp0o2TW8sJUbVB0De pJBQ== X-Gm-Message-State: AOAM532aoFBAKpNc6hp+7sl2gxcOrb6AtQBDp+PeaM44aJ8utC56264D w9/xVf7joq/54dSIi+59QjMpnNBWofE/wU2bfioW5PTamXpj+ufpO5PAM+xiOWMijueGIGaFmSZ bJespMz5f9DRvQmZsvweZeQYtwo0dhRiDXinYuZNV X-Received: by 2002:a17:90a:8591:b0:1b9:da10:2127 with SMTP id m17-20020a17090a859100b001b9da102127mr5054432pjn.13.1651252905188; Fri, 29 Apr 2022 10:21:45 -0700 (PDT) X-Received: by 2002:a17:90a:8591:b0:1b9:da10:2127 with SMTP id m17-20020a17090a859100b001b9da102127mr5054410pjn.13.1651252904923; Fri, 29 Apr 2022 10:21:44 -0700 (PDT) MIME-Version: 1.0 References: <20220407195908.633003-1-pgonda@google.com> <62e9ece1-5d71-f803-3f65-2755160cf1d1@redhat.com> <4c0edc90-36a1-4f4c-1923-4b20e7bdbb4c@redhat.com> <0d282be4-d612-374d-84ba-067994321bab@redhat.com> <8a2c5f8c-503c-b4f0-75e7-039533c9852d@redhat.com> <4afce434-ab25-66d6-76f4-3a987f64e88e@redhat.com> In-Reply-To: From: Paolo Bonzini Date: Fri, 29 Apr 2022 19:21:33 +0200 Message-ID: Subject: Re: [PATCH v3] KVM: SEV: Mark nested locking of vcpu->lock To: Peter Gonda Cc: John Sperbeck , kvm list , David Rientjes , Sean Christopherson , LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_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 Fri, Apr 29, 2022 at 7:12 PM Peter Gonda wrote: > Sounds good. Instead of doing this prev_vcpu solution we could just > keep the 1st vcpu for source and target. I think this could work since > all the vcpu->mutex.dep_maps do not point to the same string. > > Lock: > bool acquired = false; > kvm_for_each_vcpu(...) { > if (mutex_lock_killable_nested(&vcpu->mutex, role) > goto out_unlock; > acquired = true; > if (acquired) > mutex_release(&vcpu->mutex, role) > } Almost: bool first = true; kvm_for_each_vcpu(...) { if (mutex_lock_killable_nested(&vcpu->mutex, role) goto out_unlock; if (first) ++role, first = false; else mutex_release(&vcpu->mutex, role); } and to unlock: bool first = true; kvm_for_each_vcpu(...) { if (first) first = false; else mutex_acquire(&vcpu->mutex, role); mutex_unlock(&vcpu->mutex); acquired = false; } because you cannot use the first vCPU's role again when locking. Paolo