Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1578893rwb; Sun, 18 Sep 2022 09:53:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7tevQ/xArHlxVyVK3cWOL3LJZ+YKHYuN/fsXtOej6dg/YQ+SKE3kL/8TeU42o2c+LrcxNb X-Received: by 2002:a62:84c6:0:b0:538:3c39:5819 with SMTP id k189-20020a6284c6000000b005383c395819mr15060219pfd.4.1663520026715; Sun, 18 Sep 2022 09:53:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663520026; cv=none; d=google.com; s=arc-20160816; b=LvzfSeleHPGe9+XMCfWYwc7vhflH6DfvqRCnXu1+MwYaXJ6y6j0qeKLQR0B5VWQYmM 1kxpW+B5/EFKQzNbHRYW8muIpLo7DnjvMEoV57ZZvd+p4wf/CHaLsG6PQssY2+ZXGQDJ v3L+MF30Ma2lqH4T9e3nZ+kjrYLnL4LmGqllU0pmFHLRWXqs70yVVyCTWXgFCWJ1hlPJ tuG8pFc5PwBv/7q+KofTO0dANf0SYXmWMbIdv4CPhFXxA2G6OM9bEeC4lubjEPc23vYT 99hNJX/CIll2qlX3ZjJfvUoHNrNpiTFniRX1L1TCJYFMJeRCAanFN2dAAUVVPAxrXLoQ jqUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=LBfOixkOjHpC0SlW/myuMM+eEQ6CMURRJUP0DN9jWbI=; b=zIWQ31gQ4hcLAPVIc+/AIqSNsLbJ0Ei1dQAkJ/+PSBAV3ZlVjeNTBHzFR3glPFo//0 p6ENBXzfkvkE/KQPV0QXhUt4NQjEGMyq04d+1c1Sardgge0YqM7INyP/ip4myX4PkfAZ imwjIln8O8RWBIV9Y27THXV0zNEQhVbuq5TGItfAiMEAPbiwU6FJjxCzP4Jw1RW50GVR tPtd1zEVx1SadGC5VnhJy27D7daWzDJpRmmKdimMkG8PR/jPwG+dFgXOTUgbpf2DEcrb VW2dVpDMkXYBSswOnu7JaGiKHs3B+WtkOmPaLTsWGKfdIscuigfFlyZ1ri9WgStfUvnp ncHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=E+3cPXCm; 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 2-20020a621902000000b0053e661ed60fsi24385845pfz.181.2022.09.18.09.53.35; Sun, 18 Sep 2022 09:53:46 -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=E+3cPXCm; 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 S229781AbiIRQSf (ORCPT + 99 others); Sun, 18 Sep 2022 12:18:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229779AbiIRQSd (ORCPT ); Sun, 18 Sep 2022 12:18:33 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 379955F4C for ; Sun, 18 Sep 2022 09:18:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663517911; 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=LBfOixkOjHpC0SlW/myuMM+eEQ6CMURRJUP0DN9jWbI=; b=E+3cPXCmaPjO4IPF6/idlty0tCZvmSS9rV6xu+mzO8tXBO9y6ZZmUO4XSnjU5Eu3xWLHa5 hoByYL9sYmWrg1LyItPVrfvVMnVo9KV1wKOTrXLAh+1QeZNqMIO34RwNeQ9iPiyiCcFlw8 yenmxIt6y4n3fo8r2Wy/htbNDQHZzoE= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-290-A9s1tydjMq2lknQa6EiDrQ-1; Sun, 18 Sep 2022 12:18:28 -0400 X-MC-Unique: A9s1tydjMq2lknQa6EiDrQ-1 Received: by mail-qt1-f199.google.com with SMTP id cb22-20020a05622a1f9600b0035bb51792d2so14842779qtb.5 for ; Sun, 18 Sep 2022 09:18:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=LBfOixkOjHpC0SlW/myuMM+eEQ6CMURRJUP0DN9jWbI=; b=OPOr6J68Gu/eQavJNciCkOgTYwG5dkiofK/EOW0eqHNjDZmFugYUspPAjMFOb+84dA SYeRCO+CM5z+J74Lf1tAhl7hwIAl2ynpPKqrYQUEWfUofRzzeHPLcgz9QWmsU6hLE/ui +bOWNFux/jPNr952nYT/m6xpMRCkAMnCVP5lCschXZX3VSyXcg6wz1TP1L1wGerumhY3 DhHd2TEKt5yiCjgTyLqws+xQ5qcPcc/XAtv8JOztavlCcaMXRwdJHeRzgNkKUkU+0sN2 /BlEihcwWXsPQ9sdHD2zj7j4TuHm6CuQNihNnjaRdbSeomFFWc5YLDCsPcYz0JAXB6xm DWXA== X-Gm-Message-State: ACrzQf1l0VXo7+QhMrN5ufPmvcgxGZ8TrM1fXsdMeJ0gU/Iwde8fvwGP N/Nl0o3N+x0K4zJCX+bx2f1bEFidTuAKuy0XzZx0PWqrFF9JAfY3kFXeXuWKXdweDzy0mZMD1f0 JNESPiV8bfVuVIVUJ76u1KYbx X-Received: by 2002:a05:620a:2a0c:b0:6ce:7f98:d7a5 with SMTP id o12-20020a05620a2a0c00b006ce7f98d7a5mr10228425qkp.713.1663517907677; Sun, 18 Sep 2022 09:18:27 -0700 (PDT) X-Received: by 2002:a05:620a:2a0c:b0:6ce:7f98:d7a5 with SMTP id o12-20020a05620a2a0c00b006ce7f98d7a5mr10228399qkp.713.1663517907447; Sun, 18 Sep 2022 09:18:27 -0700 (PDT) Received: from ?IPV6:2a04:ee41:4:31cb:e591:1e1e:abde:a8f1? ([2a04:ee41:4:31cb:e591:1e1e:abde:a8f1]) by smtp.gmail.com with ESMTPSA id v16-20020a05620a441000b006ceafb1aa92sm8124430qkp.96.2022.09.18.09.18.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 18 Sep 2022 09:18:26 -0700 (PDT) Message-ID: Date: Sun, 18 Sep 2022 18:18:23 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [RFC PATCH 9/9] kvm_main.c: handle atomic memslot update Content-Language: en-US To: "Yang, Weijiang" , kvm@vger.kernel.org Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , David Hildenbrand , Maxim Levitsky , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org References: <20220909104506.738478-1-eesposit@redhat.com> <20220909104506.738478-10-eesposit@redhat.com> <7e64d472-fbce-6640-033a-51b8906b7924@intel.com> From: Emanuele Giuseppe Esposito In-Reply-To: <7e64d472-fbce-6640-033a-51b8906b7924@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, 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 Am 13/09/2022 um 04:30 schrieb Yang, Weijiang: > > On 9/9/2022 6:45 PM, Emanuele Giuseppe Esposito wrote: >> When kvm_vm_ioctl_set_memory_region_list() is invoked, we need >> to make sure that all memslots are updated in the inactive list >> and then swap (preferreably only once) the lists, so that all >> changes are visible immediately. > [...] >> +static int kvm_vm_ioctl_set_memory_region_list(struct kvm *kvm, >> +               struct kvm_userspace_memory_region_list *list, >> +               struct kvm_userspace_memory_region_entry __user *mem_arg) >> +{ >> +    struct kvm_userspace_memory_region_entry *mem, *m_iter; >> +    struct kvm_userspace_memory_region *mem_region; >> +    struct kvm_internal_memory_region_list *batch, *b_iter; >> +    int i, r = 0; >> +    bool *as_to_swap; >> + >> +    /* TODO: limit the number of mem to a max? */ >> + >> +    if (!list->nent) >> +        return r; >> + >> +    mem = vmemdup_user(mem_arg, array_size(sizeof(*mem), list->nent)); >> +    if (IS_ERR(mem)) { >> +        r = PTR_ERR(mem); >> +        goto out; >> +    } > > IMO, it's more natural to dup the user memory at the first place, i.e., > kvm_vm_ioctl, > > it also makes the outlets shorter. > I followed the same pattern as kvm_vcpu_ioctl_set_cpuid2, which performs the user memory dup inside the call :) I see your point but I guess it's better to keep all ioctl implementations similar. Thank you, Emanuele