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 178EAC43460 for ; Wed, 31 Mar 2021 20:43:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D501C6108D for ; Wed, 31 Mar 2021 20:43:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236595AbhCaUnB (ORCPT ); Wed, 31 Mar 2021 16:43:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:41084 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236594AbhCaUmg (ORCPT ); Wed, 31 Mar 2021 16:42:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617223355; 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=NNGnbExYiLuLZaTb/olJYdDzkOfEQoR57OqAJHWnBDw=; b=UqcaIi/ABRlSq9nJyxYJJQJT/dIvZs3QdWSTDWMhT8X2i2eR4zmZs9C9dqwZAFg3Z9hNmm Q9vphi5WXHoNNjiHDLJXV7/LwkWaumx8poQAqmMWbrNRw95uXGCKew2zWnyVZ8heL9s+ff Uk8RoS7ma/c+bMK5/xa6kjWkYJeusw0= 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-142-m_m1oq87PI6cgmiQh1-p5Q-1; Wed, 31 Mar 2021 16:42:33 -0400 X-MC-Unique: m_m1oq87PI6cgmiQh1-p5Q-1 Received: by mail-ej1-f72.google.com with SMTP id mj6so1341529ejb.11 for ; Wed, 31 Mar 2021 13:42:33 -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=NNGnbExYiLuLZaTb/olJYdDzkOfEQoR57OqAJHWnBDw=; b=MRWYkhUYhHgWCXeCSncIRKq6Cwq//lStKU4MsSUPHt+5Gr6+jjrSN/Q/D33vRXGmQ3 Bxr1JXxkPr4EVRVAvb7tsyIyU+0uQ77c/EXDUAZ/19t6tvYJ/9M6/d9uMYrVoISEBvaX MM5PDLiK35dCVYUqAg2W/d41eevIdmBsh9m3fcBpCVCTDac7e2fPWYHU9Q0EXpKf9K0j B2JE9AniKkBl0SMffdvlTjLqSNIaTsaOJNg7lT4Gu5VmteikKZvLSJm1bQTADO77OKoN vjjRDg5ZbB7qUJIVpNi129IR2t5szxE2J/zpq4LtN7IxS9T5lZsguR284lihaCdr23yZ lR4w== X-Gm-Message-State: AOAM53225MP0gSopBntBdgVfP6M4LQUbAAoahpdV6HT1HF8CaiYnfnbm bWbxBg7bETlgZvKzokUYlESfc5AbcoHfxqbChgdcE3oodEZ7ZnqmdtO0wsC3GJQcevhOoi5n/Th 6ZDJqEIgbCXQHE1Sm0QeLxek1 X-Received: by 2002:a17:906:b2cd:: with SMTP id cf13mr5620133ejb.181.1617223352346; Wed, 31 Mar 2021 13:42:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqxL3J7jbjShgrs5EgrNAd2B78hY43Jwyx1rE3bLvbATiArdEjVf/0Kcaqy2JK8oqTSMxLyw== X-Received: by 2002:a17:906:b2cd:: with SMTP id cf13mr5620121ejb.181.1617223352197; Wed, 31 Mar 2021 13:42:32 -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 ak20sm1761857ejc.72.2021.03.31.13.42.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Mar 2021 13:42:31 -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> From: Paolo Bonzini Subject: Re: [PATCH 16/18] KVM: Don't take mmu_lock for range invalidation unless necessary Message-ID: <0e30625f-934d-9084-e293-cb3bcbc9e4b8@redhat.com> Date: Wed, 31 Mar 2021 22:42:30 +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 21:47, Sean Christopherson wrote: > Rereading things, a small chunk of the rwsem nastiness can go away. I don't see > any reason to use rw_semaphore instead of rwlock_t. 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. I also thought of busy waiting on down_read_trylock if the MMU notifier cannot block, but that would also be invalid for the opposite reason (the down_write task might be asleep, waiting for other readers to release the task, and the down_read_trylock busy loop might not let that task run). > And that's _already_ the worst case since notifications are currently > serialized by mmu_lock. But right now notifications are not a single critical section, they're two, aren't they? 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 E88DEC433B4 for ; Wed, 31 Mar 2021 20:42:40 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 3F22B61073 for ; Wed, 31 Mar 2021 20:42:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3F22B61073 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 988E74B4DE; Wed, 31 Mar 2021 16:42:39 -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 atfGtMyzsJSf; Wed, 31 Mar 2021 16:42:38 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 6EB204B4F6; Wed, 31 Mar 2021 16:42:38 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 0B1CC4B4DE for ; Wed, 31 Mar 2021 16:42:37 -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 JllIjvSxmpu0 for ; Wed, 31 Mar 2021 16:42:36 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 386634B36D for ; Wed, 31 Mar 2021 16:42:36 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617223356; 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=NNGnbExYiLuLZaTb/olJYdDzkOfEQoR57OqAJHWnBDw=; b=jB5Mut5bRNfcGg/ZtfE+V4n+LmeFqEtNMUT1aKjcRc6yTpcg/Dl95RJ7Vtu3yRz0qtt6KK LSPhRUyxitGjU40FCMp0F5lhgxmIaUmVKl6Uk4c2Y13wiieg2GnJRUDTF5oKvskjRyHXWE EZhQjQzLV3FND/2GNzMND7H8dWIej0E= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-142-H2td8RI1PK2YLu9yrxnpYg-1; Wed, 31 Mar 2021 16:42:33 -0400 X-MC-Unique: H2td8RI1PK2YLu9yrxnpYg-1 Received: by mail-ed1-f72.google.com with SMTP id h2so1732803edw.10 for ; Wed, 31 Mar 2021 13:42:33 -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=NNGnbExYiLuLZaTb/olJYdDzkOfEQoR57OqAJHWnBDw=; b=SBd8VIHqiWRNzmHSQy8vgbmdHZQib0WCISp7BypqI/hnZkcMwziiKdb5lx/Kz3FPtk lXNjGMQtwqZtICUJ8nLm2iWb5Pdpbt5sAajMDCm3cQ0It6jSXTAXmfmZrALSgf4HwGek qQY0OztYwhu5zQJIOOI621xBXAnTgZKGii9ElB+AnlVkvQKK4n9EjXTt3+cHXMRjKx4O sFlFsMQHVYkUZNMOYzZ4YhPcyIwt5tok6AvXfK3df0fXJaTV+XHdJC9lRIIZE1BCjkGB LcHc1hHu6ArJExAbJH35rFvkkOLEWxWx76RIW/GB8o8Xey6f5rZ4NRzf674iVTDx8Hcx qPiQ== X-Gm-Message-State: AOAM533qiDasNa9tnxi0g4ph3jNv4wA+dwLERlAUmRwId2sy6qaebA4q HzFayFM8wTsA2KvMIDFfZVgFm8vBR07Vu4fPbPQle6OD+zSOtek5nvhzS4X88/DRN8jKeX1Kt2T FyKf0x/4loSHT4bPq/O0GYpD/ X-Received: by 2002:a17:906:b2cd:: with SMTP id cf13mr5620149ejb.181.1617223352355; Wed, 31 Mar 2021 13:42:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqxL3J7jbjShgrs5EgrNAd2B78hY43Jwyx1rE3bLvbATiArdEjVf/0Kcaqy2JK8oqTSMxLyw== X-Received: by 2002:a17:906:b2cd:: with SMTP id cf13mr5620121ejb.181.1617223352197; Wed, 31 Mar 2021 13:42:32 -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 ak20sm1761857ejc.72.2021.03.31.13.42.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Mar 2021 13:42:31 -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> From: Paolo Bonzini Subject: Re: [PATCH 16/18] KVM: Don't take mmu_lock for range invalidation unless necessary Message-ID: <0e30625f-934d-9084-e293-cb3bcbc9e4b8@redhat.com> Date: Wed, 31 Mar 2021 22:42:30 +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 21:47, Sean Christopherson wrote: > Rereading things, a small chunk of the rwsem nastiness can go away. I don't see > any reason to use rw_semaphore instead of rwlock_t. 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. I also thought of busy waiting on down_read_trylock if the MMU notifier cannot block, but that would also be invalid for the opposite reason (the down_write task might be asleep, waiting for other readers to release the task, and the down_read_trylock busy loop might not let that task run). > And that's _already_ the worst case since notifications are currently > serialized by mmu_lock. But right now notifications are not a single critical section, they're two, aren't they? 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 F24D8C433B4 for ; Wed, 31 Mar 2021 20:44:21 +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 71DFC61059 for ; Wed, 31 Mar 2021 20:44:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 71DFC61059 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=Emu8he8l0LGdo0r1rsLwraY0OkcAbPTUkIARIEOqB/M=; b=aoKuktmph9x+nUcA7txPSxLEQ T3KLysIuQispcnQ/34l6OHkXh6kPk85efG7Q3OCaPMRjmHhnyO/JS51wYsfcKdZjoiJiuiw+HyVqY 5QStGZ3q+6T74iFnOWgdKfqkRXzIacy6PavlrwG80Q7n2XSbW8Dz7Sczino3aVkt7qW9b5NqPwnLu VIwI5d5Joz/W2/XLhC8VWH2C6KiiZfDhuf1aKOgGYWGChYmJ7AopthDrVXGO+NcFPiy9uIE3S8Q22 fPkT+RTV1Ib92YlF7QVE2aF6P30q8jtjXfM4JRclNgzGrU00+mhbOEPm8ZdayGRd5PhPfROX2aiZw ptxs6GJ5Q==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lRhfn-007Wgo-4U; Wed, 31 Mar 2021 20:42:43 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lRhfh-007Wg5-Ck for linux-arm-kernel@lists.infradead.org; Wed, 31 Mar 2021 20:42:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617223356; 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=NNGnbExYiLuLZaTb/olJYdDzkOfEQoR57OqAJHWnBDw=; b=jB5Mut5bRNfcGg/ZtfE+V4n+LmeFqEtNMUT1aKjcRc6yTpcg/Dl95RJ7Vtu3yRz0qtt6KK LSPhRUyxitGjU40FCMp0F5lhgxmIaUmVKl6Uk4c2Y13wiieg2GnJRUDTF5oKvskjRyHXWE EZhQjQzLV3FND/2GNzMND7H8dWIej0E= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-328-7AFX_2bwPq-h4CdzqP78vw-1; Wed, 31 Mar 2021 16:42:33 -0400 X-MC-Unique: 7AFX_2bwPq-h4CdzqP78vw-1 Received: by mail-ej1-f69.google.com with SMTP id bg7so1345088ejb.12 for ; Wed, 31 Mar 2021 13:42:33 -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=NNGnbExYiLuLZaTb/olJYdDzkOfEQoR57OqAJHWnBDw=; b=V4c2ipJJiU9hrVp++CAIPEYPkzJFKlbNH98UBO5zZ1JLRfBqqjT++99zxowDx1TnjO xU13hQy8BIInPvaAplZPih8lHcY9EKA+CrMRRM+wNnmoJDBFVS9PI4ECceTOWbCi5Bs5 1DfRKFo1dQS9MlqpXVWNJI5HYh4Ar1F9F0pV9sp/F4c3IBgGHtGKVXtH7Qx2fXhkL4Gh cd25DWJwUMlf20XuAhG+RDMhD3X0w8ix6KXcwBfr2CYEyJwv3cI6hIOjh5GYjk7jZ63J Xs3+6KRbR2IszlcZ+7p0N6gIYlbM/SOrshTNbX/g3Z+wWoGAVmCDpwPzu6cDlMBB84bU mt9Q== X-Gm-Message-State: AOAM5306EU9zlFVhGS0qkJbuJH33nHJTzt/TzztEw/tS59Cu3hCIr0+z h3gXmqA7Q017G6agYNKKhSbfMGvV8Zm/Q95XrPNj6U+d7lpQErrid7WNZLVTx/rAOr+wy9oAOdj lQCaFw6wiFGUuQk8MK/34eovrQRBGcIqcxa8= X-Received: by 2002:a17:906:b2cd:: with SMTP id cf13mr5620143ejb.181.1617223352347; Wed, 31 Mar 2021 13:42:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqxL3J7jbjShgrs5EgrNAd2B78hY43Jwyx1rE3bLvbATiArdEjVf/0Kcaqy2JK8oqTSMxLyw== X-Received: by 2002:a17:906:b2cd:: with SMTP id cf13mr5620121ejb.181.1617223352197; Wed, 31 Mar 2021 13:42:32 -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 ak20sm1761857ejc.72.2021.03.31.13.42.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Mar 2021 13:42:31 -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> From: Paolo Bonzini Subject: Re: [PATCH 16/18] KVM: Don't take mmu_lock for range invalidation unless necessary Message-ID: <0e30625f-934d-9084-e293-cb3bcbc9e4b8@redhat.com> Date: Wed, 31 Mar 2021 22:42:30 +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_214237_751100_E82D3ED9 X-CRM114-Status: GOOD ( 11.24 ) 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 21:47, Sean Christopherson wrote: > Rereading things, a small chunk of the rwsem nastiness can go away. I don't see > any reason to use rw_semaphore instead of rwlock_t. 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. I also thought of busy waiting on down_read_trylock if the MMU notifier cannot block, but that would also be invalid for the opposite reason (the down_write task might be asleep, waiting for other readers to release the task, and the down_read_trylock busy loop might not let that task run). > And that's _already_ the worst case since notifications are currently > serialized by mmu_lock. But right now notifications are not a single critical section, they're two, aren't they? 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 20:42:30 +0000 Subject: Re: [PATCH 16/18] KVM: Don't take mmu_lock for range invalidation unless necessary Message-Id: <0e30625f-934d-9084-e293-cb3bcbc9e4b8@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> 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 21:47, Sean Christopherson wrote: > Rereading things, a small chunk of the rwsem nastiness can go away. I don't see > any reason to use rw_semaphore instead of rwlock_t. 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. I also thought of busy waiting on down_read_trylock if the MMU notifier cannot block, but that would also be invalid for the opposite reason (the down_write task might be asleep, waiting for other readers to release the task, and the down_read_trylock busy loop might not let that task run). > And that's _already_ the worst case since notifications are currently > serialized by mmu_lock. But right now notifications are not a single critical section, they're two, aren't they? Paolo