Received: by 2002:a19:7b1b:0:0:0:0:0 with SMTP id w27csp2863627lfc; Mon, 26 Jul 2021 06:19:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy540L1y4euldrzKOtOuN8nSNI/UEBWkeGwRQ9HMHnCHlsuKYT6NPLLCDeZ5fm+l1x0lTpI X-Received: by 2002:a05:6122:c55:: with SMTP id i21mr10150021vkr.0.1627305597648; Mon, 26 Jul 2021 06:19:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627305597; cv=none; d=google.com; s=arc-20160816; b=xFeE4ykNPPy0B/mPTzfE11dljHA/HzFr6Nur3dQ6MVaxJ+ZONosotXBjJgncZbM9BZ raIXbsnnIGvDqxrEEHkUdwC8wyOfIcOhKRzMWApRA1TbvfylZ5LP0oOk/HQu9c6XHN1F lPfxv/BgKFZXabC+LUUROIdMCwvRy+8W9ckIAZOkZgNcomySq9wKf7HlGK6mBidB6MOg UU/OBLjX4QOW6u/eA4DxVPJptoyhxqLDsq8BeFpjxcQSIlISYMutxU9wXVR0sSPtgUA5 Y20Y/gzA3d7LfBnixsRcRE3d9QeLACN+orece+mBBDt/uHQsC6HpGLeFnj4wm0sza9dc /1cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject; bh=UmP1j1Xnu4zP61GgaNA65sSUuh3zNsKrFE31bum+5jc=; b=Lha7nAKdPWThz5vsy7m01iynRR23hhgVm1UZy8o0/3dW9T8EjdZFHFdDTfV6MvtS8j NXm1D+JB2xIimXznepVLjefAhbpiEil7H3uHmkJT4zRVw1GDH1gIdQm5S67RxX8JULN/ kY6k1hDGpVr7exKjTiMhUMzb9V+Tt3Hao7MJ8KvbD8P//tgtUrxubiFsEhmq+zu7ZykF /09COu9ljoabDslnEQ8FwGEm0tmXWgMN3IyueSKqG++nbkavY+utj5ANCQ7zTzAVwXM6 WjXgJomDM+ecT+2Yvw1RLgeNW+o9zEdgG7MYZLk37Sw7tQeZW/kvPCpJZsj+3OYXD7Nf eEeA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l12si9590489vse.294.2021.07.26.06.19.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Jul 2021 06:19:57 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: from localhost ([::1]:41618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m80WS-0002om-Sl for alex.bennee@linaro.org; Mon, 26 Jul 2021 09:19:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52100) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m80Vt-0002oO-UE; Mon, 26 Jul 2021 09:19:21 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2447) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m80Vq-0003JU-R1; Mon, 26 Jul 2021 09:19:21 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GYL5R09bQzZt61; Mon, 26 Jul 2021 21:15:39 +0800 (CST) Received: from dggema765-chm.china.huawei.com (10.1.198.207) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Mon, 26 Jul 2021 21:19:05 +0800 Received: from [10.174.185.210] (10.174.185.210) by dggema765-chm.china.huawei.com (10.1.198.207) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Mon, 26 Jul 2021 21:19:05 +0800 Subject: Re: [question] Shall we flush ITS tables into guest RAM when shutdown the VM? To: , Peter Maydell , "open list:ARM cores" , "open list:All patches CC here" References: <82c78e1f-98ef-982e-fbcc-34da6b8aaad7@redhat.com> <91d179e0-8365-e3b4-cee6-d05ce918a32d@huawei.com> <1d9123e9-705a-36ef-3286-b2f347ec5894@redhat.com> <5ccf2a18-0615-8f1c-47cb-163f80037feb@huawei.com> From: Kunkun Jiang Message-ID: <1e77ca5d-0fd9-156f-7183-446246c391ab@huawei.com> Date: Mon, 26 Jul 2021 21:19:04 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Originating-IP: [10.174.185.210] X-ClientProxiedBy: dggeme718-chm.china.huawei.com (10.1.199.114) To dggema765-chm.china.huawei.com (10.1.198.207) X-CFilter-Loop: Reflected Received-SPF: pass client-ip=45.249.212.187; envelope-from=jiangkunkun@huawei.com; helo=szxga01-in.huawei.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-0.438, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: wanghaibin.wang@huawei.com, lushenming@huawei.com, "Dr. David Alan Gilbert" , Peter Xu , Juan Quintela Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: WdieSS6evTzf Hi Eric, On 2021/7/6 21:52, Eric Auger wrote: > Hi, > > On 7/6/21 10:18 AM, Kunkun Jiang wrote: >> Hi Eric, >> >> On 2021/6/30 17:16, Eric Auger wrote: >>> On 6/30/21 3:38 AM, Kunkun Jiang wrote: >>>> On 2021/6/30 4:14, Eric Auger wrote: >>>>> Hi Kunkun, >>>>> >>>>> On 6/29/21 11:33 AM, Kunkun Jiang wrote: >>>>>> Hi all, >>>>>> >>>>>> Accroding to the patch cddafd8f353d2d251b1a5c6c948a577a85838582, >>>>>> our original intention is to flush the ITS tables into guest RAM at >>>>>> the point >>>>>> RUN_STATE_FINISH_MIGRATE, but sometimes the VM gets stopped before >>>>>> migration launch so let's simply flush the tables each time the VM >>>>>> gets >>>>>> stopped. >>>>>> >>>>>> But I encountered an error when I shut down the virtual machine. >>>>>> >>>>>>> qemu-system-aarch64: KVM_SET_DEVICE_ATTR failed: Group 4 attr >>>>>>> 0x0000000000000001: Permission denied >>>>>> Shall we need to flush ITS tables into guest RAM when 'shutdown' the >>>>>> VM? >>>>>> Or do you think this error is normal? >>>>> yes we determined in the past this was the right moment do save the >>>>> tables >>>>> >>>>> "with a live migration the guest is still running after >>>>> the RAM has been first saved, and so the tables may still change >>>>> during the iterative RAM save. You would actually need to do this >>>>> at just the point we stop the VM before the final RAM save; that >>>>> *might* >>>>> be possible by using a notifier hook a vm run state change to >>>>> RUN_STATE_FINISH_MIGRATE >>>>> - if you can do the changes just as the migration flips into that mode >>>>> it *should* work. " said David. >>>>> >>>>> But sometimes as the commit msg says, the VM is stopped before the >>>>> migration launch - I do not remember the exact scenario tbh -. >>>> Well, I initially wanted to know more about this scenario to determine >>>> whether >>>> a normal shutdown would fall into it.😂 >>> I think it was for save/restore use case. In that case you need to flush >>> the KVM cache in memory on VM shutdown. >> Sorry for late reply. >> >> Can we distinguish from the 'RunState'? >> When we stop the VM, the RunState will be set. There are many types of >> RunState, such as RUN_STATE_FINISH_MIGRATE/RUN_STATE_SAVE_VM/ >> RUN_STATE_SHUTDOWN/RUN_STATE_GUEST_PANICKED, etc. >> >> Maybe RUN_STATE_SHUTDOWN doesn't belong to save/restore use case, >> right? > Adding Dave, Juan and Peter in the loop for migration expertise. > > At the moment we save the ARM ITS MSI controller tables whenever the VM > gets stopped. Saving the tables from KVM caches into the guest RAM is > needed for migration and save/restore use cases. > However with GICv4 this fails at KVM level because some MSIs are > forwarded and saving their state is not supported with GICv4. > > While GICv4 migration is not supported we would like the VM to work > properly, ie. being stoppable without taking care of table saving. > > So could we be more precise and identifiy the save/restore and migration > use cases instead of saving the tables on each VM shutdown. > > The tables are saved into guest RAM so when need the CPUs and devices to > be stopped but we need the guest RAM to be saved after the ITS save > operation. > > Kunkun, by the way you currently just get an error from qemu, ie. qemu > does not exit? Couldn't we just ignore -EACCESS error? Sorry for late reply. There is something wrong with my mailbox, so I didn't receive your email... Yeah, just get an error. I just wanted to know if you have a good way to solve it. It's not causing any other problems, so ignoring it should be OK. Thanks, Kunkun Jiang > > Thanks > > Eric > > > > >>>> In my opinion, when the virtual machine is normally shutdown, flushing >>>> the >>>> ITS tables is not necessary. If we can't tell the difference between >>>> 'normal shutdown' >>>> and the above scenario, then this 'error' is inevitable. >>>>> So each time the VM is stopped we flush the caches into guest RAM. >>>>> >>>>> >>>>> >>>>>> This error occurs in the following scenario: >>>>>> Kunpeng 920 、enable GICv4、passthrough a accelerator Hisilicon SEC >>>>>> to >>>>>> the VM. >>>>>> >>>>>> The flow is as follows: >>>>>> >>>>>> QEMU: >>>>>> vm_shutdown >>>>>>       do_vm_stop(RUN_STATE_SHUTDOWN) >>>>>>           vm_state_notify >>>>>>               ... >>>>>>               vm_change_state_handler (hw/intc/arm_gicv3_its_kvm.c) >>>>>>                   kvm_device_access >>>>>> >>>>>> Kernel: >>>>>>       vgic_its_save_tables_v0 >>>>>>           vgic_its_save_device_tables >>>>>>               vgic_its_save_itt >>>>>> >>>>>> There is such a code in vgic_its_save_itt(): >>>>>>> /* >>>>>>>    * If an LPI carries the HW bit, this means that this >>>>>>>    * interrupt is controlled by GICv4, and we do not >>>>>>>    * have direct access to that state without GICv4.1. >>>>>>>    * Let's simply fail the save operation... >>>>>>>    */ >>>>>>> if (ite->irq->hw && !kvm_vgic_global_state.has_gicv4_1) >>>>>>>             return -EACCES; >>> Maybe we miss a piece of code for 4.0 that unsets the forwarding. The >>> only way to handle this is to make sure  ite->irq->hw is not set on >>> shutdown, no? >> It's not going to return -EACCES here, if we unset the forwarding >> first. But >> this may cause problems in save/restore scenarios. The GICv4 architecture >> doesn't give any guarantee that the pending state is written into the >> pending table. >> >> Thanks, >> Kunkun Jiang >>> Thanks >>> >>> Eric >>>>> As far as I understand you need a v4.1 to migrate, >>>>> following Shenming's series >>>>> [PATCH v5 0/6] KVM: arm64: Add VLPI migration support on GICv4.1 >>>>> Maybe sync with him? >>>> Yes, GICv4 does not support live migrate. >>>> >>>> Thanks, >>>> Kunkun Jiang >>>>> Thanks >>>>> >>>>> Eric >>>>> >>>>> >>>>>> Looking forward to your reply. >>>>>> >>>>>> Thanks, >>>>>> Kunkun Jiang >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>> . >>> . >> > > .