From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5188C433ED for ; Wed, 31 Mar 2021 21:36:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 95D2861076 for ; Wed, 31 Mar 2021 21:36:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232101AbhCaVgN (ORCPT ); Wed, 31 Mar 2021 17:36:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36960 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230073AbhCaVfn (ORCPT ); Wed, 31 Mar 2021 17:35:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617226543; 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=QQUIznWNci7QLnwuJm69/wWy4z3NEw65AzCUXnTQPwI=; b=eTHDYhMGBgytPSH9Rg2FPWN+wBLgyHgqQVkrA2iAUCHXyx6w0jT8bFlI0SbwYo6VqwE3dV Ckn4diL2140Oj/2MRDhet0M+ZUcXioKEX7gLm7xxfxCHjFw5Dpbkp+yYbVGqP6Ud5X3moY qLWn0bXtFsv0tBVuzvkphuuavRxixdw= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-333-4PHmezCeMreKYZU81n1SjA-1; Wed, 31 Mar 2021 17:35:40 -0400 X-MC-Unique: 4PHmezCeMreKYZU81n1SjA-1 Received: by mail-ej1-f70.google.com with SMTP id r26so1389857eja.22 for ; Wed, 31 Mar 2021 14:35:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:subject:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=QQUIznWNci7QLnwuJm69/wWy4z3NEw65AzCUXnTQPwI=; b=oMOtzV9JNuMdeMJWkynePBu9Ld5lWV1tMdQ0v87dU7YXwkT4KHojLWlP9P7KWKLp+S H7AIIHm8cUU2fzGRkAvifLJrutOaN00RkZhHm20CLtEcclpNXAM7K3f6dJDdxgFEW0PK aUJCjqBaXAKirQi7gHvbU8Le3Knq+3sl3MVR2PSQK3VEFWkQuGtTlq6mf6dZcs53wQS9 BMVhA0+gT5yF9Iqn1iF8dS8W/2f2+YZpAGVb8qLRkFxpmxQuLLxBzzZV2LIVGgvyz87f 5ql07Jpf6AoJd/lDbmFULwkJecBgswxM+SkmoqUTIA98xB5YB0fTar4p+2hj0KKPlw1y 2D0w== X-Gm-Message-State: AOAM531N6trxO9GtcJLbKCRGcb2sheRHUccd2wwp5KgMYvzyHwK/s6nr lG0hmZtDOqoxqnMojBSewYblYYq1J+ct1N/n58ZFcqIsq7Y6Mi4eb2ahGxEHojgkd6GY/jZTuB0 eR+IangeKEPlxOsz2UKYDPWvp X-Received: by 2002:a17:906:4d18:: with SMTP id r24mr5674546eju.493.1617226539414; Wed, 31 Mar 2021 14:35:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqLuIZRAxqmNZY+xbCQNtWOLNhNwqjzyhv1KwZdcnD5ToTgWvG1r7yCpG0AD5klE6UQn/quw== X-Received: by 2002:a17:906:4d18:: with SMTP id r24mr5674529eju.493.1617226539171; Wed, 31 Mar 2021 14:35:39 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id h22sm1846899eji.80.2021.03.31.14.35.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Mar 2021 14:35:38 -0700 (PDT) To: Sean Christopherson Cc: Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , James Morse , Julien Thierry , Suzuki K Poulose , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Gardon References: <20210326021957.1424875-1-seanjc@google.com> <20210326021957.1424875-17-seanjc@google.com> <6e7dc7d0-f5dc-85d9-1c50-d23b761b5ff3@redhat.com> <56ea69fe-87b0-154b-e286-efce9233864e@redhat.com> <0e30625f-934d-9084-e293-cb3bcbc9e4b8@redhat.com> From: Paolo Bonzini Subject: Re: [PATCH 16/18] KVM: Don't take mmu_lock for range invalidation unless necessary Message-ID: <345ab567-386f-9080-f9cb-0e17fa90a852@redhat.com> Date: Wed, 31 Mar 2021 23:35:37 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 31/03/21 23:05, Sean Christopherson wrote: >> Wouldn't it be incorrect to lock a mutex (e.g. inside*another* MMU >> notifier's invalidate callback) while holding an rwlock_t? That makes sense >> because anybody that's busy waiting in write_lock potentially cannot be >> preempted until the other task gets the mutex. This is a potential >> deadlock. > > Yes? I don't think I follow your point though. Nesting a spinlock or rwlock > inside a rwlock is ok, so long as the locks are always taken in the same order, > i.e. it's never mmu_lock -> mmu_notifier_slots_lock. *Another* MMU notifier could nest a mutex inside KVM's rwlock. But... is it correct that the MMU notifier invalidate callbacks are always called with the mmap_sem taken (sometimes for reading, e.g. try_to_merge_with_ksm_page->try_to_merge_one_page->write_protect_page)? We could take it temporarily in install_memslots, since the MMU notifier's mm is stored in kvm->mm. In this case, a pair of kvm_mmu_notifier_lock/unlock functions would be the best way to abstract it. Paolo From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06211C433ED for ; Wed, 31 Mar 2021 21:35:49 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 66B0261075 for ; Wed, 31 Mar 2021 21:35:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 66B0261075 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvmarm-bounces@lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id CB9844B50C; Wed, 31 Mar 2021 17:35:47 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@redhat.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iAxg1EFanD2Q; Wed, 31 Mar 2021 17:35:46 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id C55794B50F; Wed, 31 Mar 2021 17:35:46 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 6DB2D4B50D for ; Wed, 31 Mar 2021 17:35:45 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zXTxiAEKPhqq for ; Wed, 31 Mar 2021 17:35:42 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mm01.cs.columbia.edu (Postfix) with ESMTP id D280A4B50C for ; Wed, 31 Mar 2021 17:35:42 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617226542; 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=QQUIznWNci7QLnwuJm69/wWy4z3NEw65AzCUXnTQPwI=; b=B0t700AwuWfk00HLBYsci5Cw25mSrM6nxdaYPYLNBlYc6cZSCq7r3+SIFALdkG/HjLewUH AypAYgl+7i+1fE8te8y2RnriywZRo5I04C6XQKGmBR4ZWa8uhPrTJ6Bou+ViC2VxLuhSKk ZvsRLkUj7u2JZ0zxJRUjHkVrKb/GBzU= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-333-YPdTcdAnNNCU1UTY3NpUqQ-1; Wed, 31 Mar 2021 17:35:40 -0400 X-MC-Unique: YPdTcdAnNNCU1UTY3NpUqQ-1 Received: by mail-ed1-f70.google.com with SMTP id q25so1786924eds.16 for ; Wed, 31 Mar 2021 14:35:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:subject:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=QQUIznWNci7QLnwuJm69/wWy4z3NEw65AzCUXnTQPwI=; b=ro8NjhPIGtb4P/HU2C1bqHrXHhZz73hjyCi8SIosBRp3d62zv6OzSnlx3rfLDYywI/ HcZCZZHW39mJd76998X6YWgoX/ZhPoJc3c4jTgAakhr2V/AeQYZ6K1p4IoIutH5eCTKM hLovIEW1qGoHOxI8t7XdM2yGXSAto01hpFK1hCftv9+6kfxuvU9qsoXGlVHUu87rkPHr rLIAGQLjzplmk5uoX0b+UmRqy3vk7UJjwhYAHsgPYU63vi36LYP4IYnnRVURgI8s9H/c c13YXuGAurD5sZkdYA4ciDDsDvlifgp4QmunSZMNMbob+RiVliTFOXa3kzzNY9AGCN4L XnGg== X-Gm-Message-State: AOAM533WcHFshPW4fe0ot3JE3JJwhePA+Ftv2xU3FQej7uE+XJZIodXt 9ISzDITrgwvAkEjzgCz16QikgEGhgE4Cz3e5JQRF+SpLkIA3UW4bvPfvTN7ZWopQTUspVG8wUWD dk8jekel/iRl0txPXKG/oBBgj X-Received: by 2002:a17:906:4d18:: with SMTP id r24mr5674567eju.493.1617226539479; Wed, 31 Mar 2021 14:35:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqLuIZRAxqmNZY+xbCQNtWOLNhNwqjzyhv1KwZdcnD5ToTgWvG1r7yCpG0AD5klE6UQn/quw== X-Received: by 2002:a17:906:4d18:: with SMTP id r24mr5674529eju.493.1617226539171; Wed, 31 Mar 2021 14:35:39 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id h22sm1846899eji.80.2021.03.31.14.35.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Mar 2021 14:35:38 -0700 (PDT) To: Sean Christopherson References: <20210326021957.1424875-1-seanjc@google.com> <20210326021957.1424875-17-seanjc@google.com> <6e7dc7d0-f5dc-85d9-1c50-d23b761b5ff3@redhat.com> <56ea69fe-87b0-154b-e286-efce9233864e@redhat.com> <0e30625f-934d-9084-e293-cb3bcbc9e4b8@redhat.com> From: Paolo Bonzini Subject: Re: [PATCH 16/18] KVM: Don't take mmu_lock for range invalidation unless necessary Message-ID: <345ab567-386f-9080-f9cb-0e17fa90a852@redhat.com> Date: Wed, 31 Mar 2021 23:35:37 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Cc: Wanpeng Li , kvm@vger.kernel.org, Marc Zyngier , Joerg Roedel , Huacai Chen , linux-mips@vger.kernel.org, kvm-ppc@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Mackerras , Aleksandar Markovic , linux-arm-kernel@lists.infradead.org, Ben Gardon , Vitaly Kuznetsov , kvmarm@lists.cs.columbia.edu, Jim Mattson X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On 31/03/21 23:05, Sean Christopherson wrote: >> Wouldn't it be incorrect to lock a mutex (e.g. inside*another* MMU >> notifier's invalidate callback) while holding an rwlock_t? That makes sense >> because anybody that's busy waiting in write_lock potentially cannot be >> preempted until the other task gets the mutex. This is a potential >> deadlock. > > Yes? I don't think I follow your point though. Nesting a spinlock or rwlock > inside a rwlock is ok, so long as the locks are always taken in the same order, > i.e. it's never mmu_lock -> mmu_notifier_slots_lock. *Another* MMU notifier could nest a mutex inside KVM's rwlock. But... is it correct that the MMU notifier invalidate callbacks are always called with the mmap_sem taken (sometimes for reading, e.g. try_to_merge_with_ksm_page->try_to_merge_one_page->write_protect_page)? We could take it temporarily in install_memslots, since the MMU notifier's mm is stored in kvm->mm. In this case, a pair of kvm_mmu_notifier_lock/unlock functions would be the best way to abstract it. Paolo _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C84F3C433B4 for ; Wed, 31 Mar 2021 21:37:34 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 397BA60FDC for ; Wed, 31 Mar 2021 21:37:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 397BA60FDC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:Subject: From:References:Cc:To:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=D5hZ7fVMjefSDTVXdEpK6cePX3jCZbzIrNXsiy7lADc=; b=T3bXmr/cUxw+0mMVC9/ZugckZ rsyp2nuAZCuLpczl+eb3dilVDoNXPs9ZKj+/IylojUimlAFwBUo1VM4BU57O904uV1aypRPh8Ftx+ 8GbTR7JpbxAH0OoWtAYNWWtC4jxSrm+w6xoimELWe6zndoi9JBzB57sK10ztUQ8eM4X7/y/X6Ndox lpfarL5JyOPgqN1WeV9TOx9gESeMkX0G6ui2vdWtAslGJ72T3LjNC7FMwCQnuvh1hcS5Z99jgBe5m Lj5e7p8ctrnI0hiLBXsHfSjEU2N9oeJ3p5FNYHu0F03m3B0rwcdU4s/AqRtItZYxhEqrX33KVgYaW M1f4F9H+A==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lRiVG-007htx-D3; Wed, 31 Mar 2021 21:35:54 +0000 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lRiV6-007hqg-2d for linux-arm-kernel@lists.infradead.org; Wed, 31 Mar 2021 21:35:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617226542; 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=QQUIznWNci7QLnwuJm69/wWy4z3NEw65AzCUXnTQPwI=; b=B0t700AwuWfk00HLBYsci5Cw25mSrM6nxdaYPYLNBlYc6cZSCq7r3+SIFALdkG/HjLewUH AypAYgl+7i+1fE8te8y2RnriywZRo5I04C6XQKGmBR4ZWa8uhPrTJ6Bou+ViC2VxLuhSKk ZvsRLkUj7u2JZ0zxJRUjHkVrKb/GBzU= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-325-E-nEq_RoO1OyIvFOEdhZBg-1; Wed, 31 Mar 2021 17:35:40 -0400 X-MC-Unique: E-nEq_RoO1OyIvFOEdhZBg-1 Received: by mail-ej1-f72.google.com with SMTP id bn26so1384752ejb.20 for ; Wed, 31 Mar 2021 14:35:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:subject:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=QQUIznWNci7QLnwuJm69/wWy4z3NEw65AzCUXnTQPwI=; b=sk2BqmNF9UnMGuLBPz9zaNFzW8UNp9KkeYaQzZeV/7ymmI6V6Fl0ynq62mFZREJynu eD+4YGmJIBIqNXKp/HMM3hmNJLDy5hvJvoCwprl/Yac0P6+7U005t5qVGApgFlZK1Kx2 Rrf0Se/ufXuN7uaX0lpd6p+1ok1+5KJxT6+a2FCJQwM8YxGapozVypB6dlaIvcJJf2db FNqrTSq5qk4gYNH3IfmLN6WKRMxXpuids4X6X0PIv5RFwX4X/N86UuU8wYo9E5w+7HIi 78ETF6L/GcO71gKXr2yJo4Ei9ogysBehjwAyuzq0by9ac/HE0xSURSLWFXbWrzhHv+Z0 0emA== X-Gm-Message-State: AOAM533sUSGffup5PyQtBOqICfyfPtmzsVyd/gdYhkoUl8YqG1/0fIkK MreMNgzNKtzqllKdwasUIQNrd5Vzt7tXsEO7jbFTlfsSgS9p7SLMv6sSWQePdZUf3LFRPgIUIz1 Du4XG7WG8dE+uw1/vYMtGeNUP5rkIGWBBr4Q= X-Received: by 2002:a17:906:4d18:: with SMTP id r24mr5674549eju.493.1617226539417; Wed, 31 Mar 2021 14:35:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqLuIZRAxqmNZY+xbCQNtWOLNhNwqjzyhv1KwZdcnD5ToTgWvG1r7yCpG0AD5klE6UQn/quw== X-Received: by 2002:a17:906:4d18:: with SMTP id r24mr5674529eju.493.1617226539171; Wed, 31 Mar 2021 14:35:39 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id h22sm1846899eji.80.2021.03.31.14.35.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Mar 2021 14:35:38 -0700 (PDT) To: Sean Christopherson Cc: Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , James Morse , Julien Thierry , Suzuki K Poulose , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Gardon References: <20210326021957.1424875-1-seanjc@google.com> <20210326021957.1424875-17-seanjc@google.com> <6e7dc7d0-f5dc-85d9-1c50-d23b761b5ff3@redhat.com> <56ea69fe-87b0-154b-e286-efce9233864e@redhat.com> <0e30625f-934d-9084-e293-cb3bcbc9e4b8@redhat.com> From: Paolo Bonzini Subject: Re: [PATCH 16/18] KVM: Don't take mmu_lock for range invalidation unless necessary Message-ID: <345ab567-386f-9080-f9cb-0e17fa90a852@redhat.com> Date: Wed, 31 Mar 2021 23:35:37 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210331_223546_010762_08881ED4 X-CRM114-Status: GOOD ( 12.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 31/03/21 23:05, Sean Christopherson wrote: >> Wouldn't it be incorrect to lock a mutex (e.g. inside*another* MMU >> notifier's invalidate callback) while holding an rwlock_t? That makes sense >> because anybody that's busy waiting in write_lock potentially cannot be >> preempted until the other task gets the mutex. This is a potential >> deadlock. > > Yes? I don't think I follow your point though. Nesting a spinlock or rwlock > inside a rwlock is ok, so long as the locks are always taken in the same order, > i.e. it's never mmu_lock -> mmu_notifier_slots_lock. *Another* MMU notifier could nest a mutex inside KVM's rwlock. But... is it correct that the MMU notifier invalidate callbacks are always called with the mmap_sem taken (sometimes for reading, e.g. try_to_merge_with_ksm_page->try_to_merge_one_page->write_protect_page)? We could take it temporarily in install_memslots, since the MMU notifier's mm is stored in kvm->mm. In this case, a pair of kvm_mmu_notifier_lock/unlock functions would be the best way to abstract it. Paolo _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Date: Wed, 31 Mar 2021 21:35:37 +0000 Subject: Re: [PATCH 16/18] KVM: Don't take mmu_lock for range invalidation unless necessary Message-Id: <345ab567-386f-9080-f9cb-0e17fa90a852@redhat.com> List-Id: References: <20210326021957.1424875-1-seanjc@google.com> <20210326021957.1424875-17-seanjc@google.com> <6e7dc7d0-f5dc-85d9-1c50-d23b761b5ff3@redhat.com> <56ea69fe-87b0-154b-e286-efce9233864e@redhat.com> <0e30625f-934d-9084-e293-cb3bcbc9e4b8@redhat.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Sean Christopherson Cc: Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , James Morse , Julien Thierry , Suzuki K Poulose , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Gardon On 31/03/21 23:05, Sean Christopherson wrote: >> Wouldn't it be incorrect to lock a mutex (e.g. inside*another* MMU >> notifier's invalidate callback) while holding an rwlock_t? That makes sense >> because anybody that's busy waiting in write_lock potentially cannot be >> preempted until the other task gets the mutex. This is a potential >> deadlock. > > Yes? I don't think I follow your point though. Nesting a spinlock or rwlock > inside a rwlock is ok, so long as the locks are always taken in the same order, > i.e. it's never mmu_lock -> mmu_notifier_slots_lock. *Another* MMU notifier could nest a mutex inside KVM's rwlock. But... is it correct that the MMU notifier invalidate callbacks are always called with the mmap_sem taken (sometimes for reading, e.g. try_to_merge_with_ksm_page->try_to_merge_one_page->write_protect_page)? We could take it temporarily in install_memslots, since the MMU notifier's mm is stored in kvm->mm. In this case, a pair of kvm_mmu_notifier_lock/unlock functions would be the best way to abstract it. Paolo