Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp706356rwb; Tue, 27 Sep 2022 03:39:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6dD3nAyHM0EIqCoJ5VnmR4euFbaAGjvrNoNMgP/AiPDpuaZTP70Y/OBL74W+cpzoB7dVFk X-Received: by 2002:a17:90b:38c9:b0:205:e2e2:9ea6 with SMTP id nn9-20020a17090b38c900b00205e2e29ea6mr571480pjb.114.1664275154815; Tue, 27 Sep 2022 03:39:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664275154; cv=none; d=google.com; s=arc-20160816; b=iYzFJ6YDb9KEWfod0AZdZO92qnyR79JVmCg+WanlKnUB1WZ4oCjjaGSxnXq0r14+mE JHhE1ZVPY7D3lwH9rOEAh9IdPvwZACT4mEHcAUtQ4FP5ohNOY6uyfJUndf2vUutxBpsj 8BXibx7AyCFXafnQ+1IWHHmA5DV5BE9C5u3cGZ4Np/pv2kiD5QKS+T8ivIgf12bTSooc ZaJpLrWsU6k1Xw+a+IMhIBVUOg9LF3nmsXYWiNT7YLJNGY74yfRmq6nUHbD488VzXZmJ L+HRAceehnIS/x91noUWkeMMORsNEvhu6yBG+8XfgmywdpMCg+FmZYp2UZW2YMSy1nhz hugA== 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=SWzvIWhu2p5oGZsL7YjmEHhgIgzvZ3iiY7FpFO/QMaY=; b=SchSFSpwnXQ0c1tpB7oBW8Xac31i7yNxeSq0RrpJa32gE6YNn6TjrizuslzKgp3J1J bVIp7stml2FqLD/mKqMD3zKqW46rnawuNDc+lMWSeddKbfiR5xd7hgHgKL9TT/ixmuhu ub0wJxnhPzAt8ZSGP9fO7tDe+Mtjj98wptJmeLozLjMBPeQJ4mRBRwVf3UbAtdYBpqTz AIBD2Us1f//Ww6CKkf7nFqL47T8B4EHJ2bRQm9PGQoZuqQLG0PjX/HbfUIfGUu1Z0rZ4 sWYVufj/yyBiLVnNsMQlgMooH8pQtjIRQ2oJ31x20r5dpjdWECs/MAmPbquqj7FoGu57 8f1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bWjfRPj3; 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 j1-20020a63ec01000000b0041aaa841692si1555352pgh.108.2022.09.27.03.39.03; Tue, 27 Sep 2022 03:39:14 -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=bWjfRPj3; 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 S231397AbiI0Jcw (ORCPT + 99 others); Tue, 27 Sep 2022 05:32:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229847AbiI0Jct (ORCPT ); Tue, 27 Sep 2022 05:32:49 -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 7AB643CBD1 for ; Tue, 27 Sep 2022 02:32:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664271167; 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=SWzvIWhu2p5oGZsL7YjmEHhgIgzvZ3iiY7FpFO/QMaY=; b=bWjfRPj38PcZX9Tw3XfICb0R8sWbDv8NGQjk6sXxGnEdMRVD8HHqP//8c1ODXw2OfBw75P tVr+rsFu/+jiwkHs1CPvUmJ59LJlOw4Z0hyl8wrLja/yt9mBRoDAhWuygDJth2TzsphzPp dsg3DIhZ3qEBgAdK1Dklvn5/G+dSKfk= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-202-kPsBc1PNOI6r9PXcouFtkA-1; Tue, 27 Sep 2022 05:32:46 -0400 X-MC-Unique: kPsBc1PNOI6r9PXcouFtkA-1 Received: by mail-wr1-f71.google.com with SMTP id j16-20020adfa550000000b0022cbdfcea2dso401633wrb.19 for ; Tue, 27 Sep 2022 02:32:46 -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=SWzvIWhu2p5oGZsL7YjmEHhgIgzvZ3iiY7FpFO/QMaY=; b=k0wVLWLqU0FGxEvhX58Zw2fmMmR3CNSMWSLoTaZUSCn2iaTHjaWXtN7DRwtt9YV6LF PspRPZtL8fHUtDOd5GR+A6rp4IvOQTe2ppenSvCpD/zVESfAUhrZJbGaNcRishEAwCXO t2plSEGJ820W0BHyJ5HbAJJsLuiX0xiK6Izo93JAyGax6ou6yxad583HYBGQIDUaYyEP 5RDxjW8qc0Tnzs+4enwQwbDD2GXfh7r3eNG85Y4AI6BjS6gGHSvG70w2sDJNTh5xrIXV OLCAyO0FeomB4l4Q3WxtHYRCJguevQk7mjz6onYzbaPDKIjNO9r9f+oqdhhBm5UqBmpD Ikhg== X-Gm-Message-State: ACrzQf1SxMEugHbGN3FtfWxR66hXV3iDilIaAzDzLFRAOajNL90nMUbg dLm0OetCoO+JdHNWF/w5FJ8BtFpWVWdxFx7v3/s3i/ptEMuuxL/zExnzfm/B4jCtxO0UWOmtAFs Hk2iLc3dFmDNPQPhqlYAQEH0u X-Received: by 2002:adf:fa83:0:b0:205:c0cb:33c6 with SMTP id h3-20020adffa83000000b00205c0cb33c6mr17004728wrr.39.1664271165244; Tue, 27 Sep 2022 02:32:45 -0700 (PDT) X-Received: by 2002:adf:fa83:0:b0:205:c0cb:33c6 with SMTP id h3-20020adffa83000000b00205c0cb33c6mr17004711wrr.39.1664271164966; Tue, 27 Sep 2022 02:32:44 -0700 (PDT) Received: from [192.168.149.123] (58.254.164.109.static.wline.lns.sme.cust.swisscom.ch. [109.164.254.58]) by smtp.gmail.com with ESMTPSA id i6-20020a05600c354600b003b47b80cec3sm14617665wmq.42.2022.09.27.02.32.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 27 Sep 2022 02:32:44 -0700 (PDT) Message-ID: <81c235cc-1198-9765-d1e7-a158ea63eac4@redhat.com> Date: Tue, 27 Sep 2022 11:32:43 +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: David Hildenbrand , 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 , 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> <07014070-5186-ca95-7028-82f77612dedd@redhat.com> From: Emanuele Giuseppe Esposito In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.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_NONE,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 27/09/2022 um 11:22 schrieb David Hildenbrand: > On 27.09.22 10:35, Emanuele Giuseppe Esposito wrote: >> >> >> Am 27/09/2022 um 09:46 schrieb David Hildenbrand: >>> On 09.09.22 12:45, 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. >>>> >>>> The only issue is that DELETE and MOVE need to perform 2 swaps: >>>> firstly replace old memslot with invalid, and then remove invalid. >>>> >>> >>> I'm curious, how would a resize (grow/shrink) or a split be handled? >>> >> >> There are only 4 operations possible in KVM: KVM_MR_{DELETE, MOVE, >> CREATE, FLAGS_ONLY}. >> >> A resize should be implemented in QEMU as DELETE+CREATE. >> >> Therefore a resize on memslot X will be implemented as: >> First pass on the userspace operations: >>     invalidate memslot X; >>     swap_memslot_list(); // NOW it is visible to the guest >> >> What guest sees: memslot X is invalid, so MMU keeps retrying the page >> fault >> >> Second pass: >>     create new memslot X >>     delete old memslot X > > Thanks a lot for the very nice explanation! Anytime :) > Does the invalidation already free up memslot metadata (especially the > rmaps) or will we end up temporarily allocating twice the memslot metadata? > Invalidation creates a new temporary identical memslot, I am not sure about the rmaps. It is anyways the same code as it was done before and if I understand correctly, a new slot is required to keep the old intact, in case something goes wrong and we need to revert. Thanks, Emanuele