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.5 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 1590DC433B4 for ; Wed, 28 Apr 2021 06:25:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E350D61412 for ; Wed, 28 Apr 2021 06:25:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236106AbhD1G0f (ORCPT ); Wed, 28 Apr 2021 02:26:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:22565 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235991AbhD1G0a (ORCPT ); Wed, 28 Apr 2021 02:26:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619591125; 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=v0drg1VHfipH5003vzixu1Xfr6Q82RdEZBTA4Npc/7s=; b=Nx7YrRMiv8ip5Vs2MmxfUsJWRTgfrP+I2CqA35HeDPpT+qekIy6A3AERg+TFZvyiVJ/2U6 9446x/K8p1ZFC23u7Dp2Tgf7vc3IVC8+3Zncw0us6xp6sw7jzA/lZAY2d5cocfoVrhBqWJ HzAouvHxBA2YXbaGpwmIzB1c6frF+h0= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-252-Swu6IY-qNoyFRJCy4zBvog-1; Wed, 28 Apr 2021 02:25:24 -0400 X-MC-Unique: Swu6IY-qNoyFRJCy4zBvog-1 Received: by mail-ej1-f71.google.com with SMTP id f15-20020a170906738fb029037c94426fffso12005250ejl.22 for ; Tue, 27 Apr 2021 23:25:23 -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=v0drg1VHfipH5003vzixu1Xfr6Q82RdEZBTA4Npc/7s=; b=KugPKX+y8IPjUkjxEkwWLGasGWCMDEXGgZqF+S4H0CgVRZqrK8N6/pi/5PXcyZKHDt DQZUE41XFyAGdh5ZWOUhVhAs/yCY7AoXoVDSLwzCGJmWsxBJ/s2g+vVbfWdkUIKOhvk3 pWjEW09QIqG2/fW/aH5iXTg3UdHe/EkIErUckUkUSNbki3vdScXxcnCSMrdlVU2SJyqh lQR4W888d186zntgjp9IlHEeoItZJvah3GceG6ugzrfJbkpCuTLWKDeO92wKUVLDA6lW cFcbF41VQdSC0F/EjE6BZ1+X60FNMGIZ+La95hbSeSGxvtD6VaZOdFCaA9iM+a2Vc54L Lgzg== X-Gm-Message-State: AOAM531C2v6/++P1bxlZAgUSVjPibfgS0j7aFY5TZIyDkzYwAcosuIrr GJuZXKuFnFzN0gTCrc6Lr5+GdTerxLJG2oQZAaBobLcysTErb1+augz4ugq1ClhlyMO69vV7dAw nppEo04yW4FctTSPf9x6zKmED X-Received: by 2002:a17:907:daa:: with SMTP id go42mr27083718ejc.120.1619591122835; Tue, 27 Apr 2021 23:25:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfJKK/7NS8s2qR0C9EInsE0sUkN0nqgW1XP1hhavLbbRD2SK/F6z2RAt3f2yLMVaFqLr0UeQ== X-Received: by 2002:a17:907:daa:: with SMTP id go42mr27083699ejc.120.1619591122628; Tue, 27 Apr 2021 23:25:22 -0700 (PDT) Received: from [192.168.10.118] ([93.56.169.140]) by smtp.gmail.com with ESMTPSA id kx3sm1264228ejc.44.2021.04.27.23.25.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 27 Apr 2021 23:25:22 -0700 (PDT) To: Ben Gardon , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Peter Xu , Sean Christopherson , Peter Shier , Junaid Shahid , Jim Mattson , Yulei Zhang , Wanpeng Li , Vitaly Kuznetsov , Xiao Guangrong References: <20210427223635.2711774-1-bgardon@google.com> <20210427223635.2711774-6-bgardon@google.com> From: Paolo Bonzini Subject: Re: [PATCH 5/6] KVM: x86/mmu: Protect kvm->memslots with a mutex Message-ID: <997f9fe3-847b-8216-c629-1ad5fdd2ffae@redhat.com> Date: Wed, 28 Apr 2021 08:25:20 +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: <20210427223635.2711774-6-bgardon@google.com> 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 28/04/21 00:36, Ben Gardon wrote: > +void kvm_arch_assign_memslots(struct kvm *kvm, int as_id, > + struct kvm_memslots *slots) > +{ > + mutex_lock(&kvm->arch.memslot_assignment_lock); > + rcu_assign_pointer(kvm->memslots[as_id], slots); > + mutex_unlock(&kvm->arch.memslot_assignment_lock); > +} Does the assignment also needs the lock, or only the rmap allocation? I would prefer the hook to be something like kvm_arch_setup_new_memslots. (Also it is useful to have a comment somewhere explaining why the slots_lock does not work. IIUC there would be a deadlock because you'd be taking the slots_lock inside an SRCU critical region, while usually the slots_lock critical section is the one that includes a synchronize_srcu; I should dig that up and document that ordering in Documentation/virt/kvm too). Paolo