Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp9857406rwl; Wed, 11 Jan 2023 10:57:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXsS7ocIazkJB2sudqbULXLE/uen9ltK7vMH3KEwRO+JjBn+J+idrvpD+wV+HqXV1UBtCcfb X-Received: by 2002:a05:6a20:1017:b0:b3:ed81:9f58 with SMTP id a23-20020a056a20101700b000b3ed819f58mr72523374pzd.52.1673463420465; Wed, 11 Jan 2023 10:57:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673463420; cv=none; d=google.com; s=arc-20160816; b=eCy9uWId+7o2f0UYDrnuwZA8AxnENnl2+HQbk1NBjSX3XgYzXAfuwPdXhbaOnXsAn4 xm86Vx38HK9K1M6p9xDU/gESlGwd7AwlU4fvNDH6E054ohGK0P1392t3Ektxzt2HTVQ3 Iq/HTT3G3nhYivgippRlcrGBDBk1+CEoGwf7Q2OzvVfqcD/41FC/tR2B1U2W40mZRtbZ etIug9qjJGDJkY3AEZ/al6+Dml6b7mu8SQ5C126knhbs8Zrwx6xLiIftVdkIDZeL9Sql JXDWK8k1SCYIDxdUwVW7F3wC3TAburS61rNTGXlxTaHbkPC8mJk199v2FV9dGrER7vDw LlQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=DsHR+gK9NXOoSaKdGDYaK34gTAYNmEFxKqyOr6ZMcO4=; b=rswrP6/P3oynDbMy6tAqTlL7zPR5E+zXSe3UdoAtsWLDkwj7XIk1+kYjLPfP29lLWS JLTL1z6XszsCSwTJ6ml8RqG2HxWBb/nQoKyl2TafK2iSJ/hUj0RlcRZ7TLlaghvBu0Jj xjTZMTcARvFpk2pA6MvrOOtwxozALEogwElbbRVIVBM6p6JVsKaiYxLZZSSIcDtBFWGH 5T4GU4SaKnvsKnu5OmvDRCf/IO3vppZIf32yZ6K2hsfnMnRzhs2WwPI9Z3pdhRXoWGth Ys6qtyJbc9AWg3mT9e01TzeOvox9SZK+Rw7KMmYO60BUMBWbwoH/YlzjJv6smYZNb6Ga 5/AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UPwke6rt; 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 w8-20020a63f508000000b0047907dd2b75si16460537pgh.574.2023.01.11.10.56.53; Wed, 11 Jan 2023 10:57:00 -0800 (PST) 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=UPwke6rt; 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 S232580AbjAKSbe (ORCPT + 53 others); Wed, 11 Jan 2023 13:31:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235353AbjAKSb1 (ORCPT ); Wed, 11 Jan 2023 13:31:27 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDC7837501 for ; Wed, 11 Jan 2023 10:30:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673461838; 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; bh=DsHR+gK9NXOoSaKdGDYaK34gTAYNmEFxKqyOr6ZMcO4=; b=UPwke6rtEqtQI43GqDf4I0gpNViL7naWBTXq5ht6i/evhPKblZAVWAKdXvvfiMlN7n29Y2 UxbW1gMNlhwN3Dv3+t+BdSfgTHlSKq56xOj8uo5KPAdQyAwKreKXXhxx+GyM45E24UAsyj 8MrIz+X9e/1NaNjsQ0hIjH3JfzpUEHw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-589-lodOvzh5NXicVlPIqy2l4A-1; Wed, 11 Jan 2023 13:30:33 -0500 X-MC-Unique: lodOvzh5NXicVlPIqy2l4A-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9B8708030A0; Wed, 11 Jan 2023 18:30:32 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 777C7140EBF5; Wed, 11 Jan 2023 18:30:32 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: dwmw@amazon.co.uk, seanjc@google.com Subject: [PATCH] Documentation: kvm: fix SRCU locking order docs Date: Wed, 11 Jan 2023 13:30:31 -0500 Message-Id: <20230111183031.2449668-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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 kvm->srcu is taken in KVM_RUN and several other vCPU ioctls, therefore vcpu->mutex is susceptible to the same deadlock that is documented for kvm->slots_lock. The same holds for kvm->lock, since kvm->lock is held outside vcpu->mutex. Fix the documentation and rearrange it to highlight the difference between these locks and kvm->slots_arch_lock, and how kvm->slots_arch_lock can be useful while processing a vmexit. Signed-off-by: Paolo Bonzini --- Documentation/virt/kvm/locking.rst | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Documentation/virt/kvm/locking.rst b/Documentation/virt/kvm/locking.rst index 897ca39b72bf..53826098183e 100644 --- a/Documentation/virt/kvm/locking.rst +++ b/Documentation/virt/kvm/locking.rst @@ -24,17 +24,18 @@ The acquisition orders for mutexes are as follows: For SRCU: -- ``synchronize_srcu(&kvm->srcu)`` is called _inside_ - the kvm->slots_lock critical section, therefore kvm->slots_lock - cannot be taken inside a kvm->srcu read-side critical section. - Instead, kvm->slots_arch_lock is released before the call - to ``synchronize_srcu()`` and _can_ be taken inside a - kvm->srcu read-side critical section. - -- kvm->lock is taken inside kvm->srcu, therefore - ``synchronize_srcu(&kvm->srcu)`` cannot be called inside - a kvm->lock critical section. If you cannot delay the - call until after kvm->lock is released, use ``call_srcu``. +- ``synchronize_srcu(&kvm->srcu)`` is called inside critical sections + for kvm->lock, vcpu->mutex and kvm->slots_lock. These locks _cannot_ + be taken inside a kvm->srcu read-side critical section; that is, the + following is broken:: + + srcu_read_lock(&kvm->srcu); + mutex_lock(&kvm->slots_lock); + +- kvm->slots_arch_lock instead is released before the call to + ``synchronize_srcu()``. It _can_ therefore be taken inside a + kvm->srcu read-side critical section, for example while processing + a vmexit. On x86: -- 2.39.0