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=-2.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 272BCC3A5A6 for ; Fri, 20 Sep 2019 01:20:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (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 F16F1214AF for ; Fri, 20 Sep 2019 01:20:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F16F1214AF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:50444 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iB7au-0006Ho-OL for qemu-devel@archiver.kernel.org; Thu, 19 Sep 2019 21:20:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49621) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iB7Zl-000594-DO for qemu-devel@nongnu.org; Thu, 19 Sep 2019 21:19:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iB7Zj-0005G4-SF for qemu-devel@nongnu.org; Thu, 19 Sep 2019 21:19:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46654) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iB7Zj-0005Fs-KT for qemu-devel@nongnu.org; Thu, 19 Sep 2019 21:19:07 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C0BC0C024AEC; Fri, 20 Sep 2019 01:19:06 +0000 (UTC) Received: from [10.72.12.88] (ovpn-12-88.pek2.redhat.com [10.72.12.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFCB95D9CD; Fri, 20 Sep 2019 01:18:59 +0000 (UTC) Subject: Re: [Qemu-devel] vhost, iova, and dirty page tracking To: "Tian, Kevin" , Paolo Bonzini , "Zhao, Yan Y" References: <60110ea3-9228-7e5d-ea32-05c72a95af0b@redhat.com> <8302a4ae-1914-3046-b3b5-b3234d7dda02@redhat.com> <6d73572e-1e89-b04a-bdd6-98ac73798083@redhat.com> <204219fa-ee72-ca60-52a4-fb4bbc887773@redhat.com> <20190919052819.GA18391@joy-OptiPlex-7040> <7b6d6343-33de-ebd7-9846-af54a45a82a2@redhat.com> <20190919061756.GB18391@joy-OptiPlex-7040> <1ec55b2e-6a59-f1df-0604-5b524da0f001@redhat.com> From: Jason Wang Message-ID: <51578ae6-cc36-3b1a-9184-70a847e58712@redhat.com> Date: Fri, 20 Sep 2019 09:18:57 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 20 Sep 2019 01:19:06 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 'Alex Williamson' , "qemu-devel@nongnu.org" , "mst@redhat.com" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 2019/9/20 =E4=B8=8A=E5=8D=886:54, Tian, Kevin wrote: >> From: Paolo Bonzini [mailto:pbonzini@redhat.com] >> Sent: Thursday, September 19, 2019 7:14 PM >> >> On 19/09/19 09:16, Tian, Kevin wrote: >>>>> why GPA1 and GPA2 should be both dirty? >>>>> even they have the same HVA due to overlaping virtual address space >> in >>>>> two processes, they still correspond to two physical pages. >>>>> don't get what's your meaning :) >>>> The point is not leave any corner case that is hard to debug or fix = in >>>> the future. >>>> >>>> Let's just start by a single process, the API allows userspace to ma= ps >>>> HVA to both GPA1 and GPA2. Since it knows GPA1 and GPA2 are >> equivalent, >>>> it's ok to sync just through GPA1. That means if you only log GPA2, = it >>>> won't work. >>> I noted KVM itself doesn't consider such situation (one HVA is mapped >>> to multiple GPAs), when doing its dirty page tracking. If you look at >>> kvm_vcpu_mark_page_dirty, it simply finds the unique memslot which >>> contains the dirty gfn and then set the dirty bit within that slot. I= t >>> doesn't attempt to walk all memslots to find out any other GPA which >>> may be mapped to the same HVA. >>> >>> So there must be some disconnect here. let's hear from Paolo first an= d >>> understand the rationale behind such situation. >> In general, userspace cannot assume that it's okay to sync just throug= h >> GPA1. It must sync the host page if *either* GPA1 or GPA2 are marked >> dirty. > Agree. In this case the kernel only needs to track whether GPA1 or > GPA2 is dirtied by guest operations. Not necessarily guest operations. > The reason why vhost has to > set both GPA1 and GPA2 is due to its own design - it maintains > IOVA->HVA and GPA->HVA mappings thus given a IOVA you have > to reverse lookup GPA->HVA memTable which gives multiple possible > GPAs. So if userspace need to track both GPA1 and GPA2, vhost can just stop=20 when it found a one HVA->GPA mapping there. > But in concept if vhost can maintain a IOVA->GPA mapping, > then it is straightforward to set the right GPA every time when a IOVA > is tracked. That means, the translation is done twice by software, IOVA->GPA and=20 GPA->HVA for each packet. Thanks > >> The situation really only arises in special cases. For example, >> 0xfffe0000..0xffffffff and 0xe0000..0xfffff might be the same memory. >> From "info mtree" before the guest boots: >> >> 0000000000000000-ffffffffffffffff (prio -1, i/o): pci >> 00000000000e0000-00000000000fffff (prio 1, i/o): alias isa-bios >> @pc.bios 0000000000020000-000000000003ffff >> 00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios >> >> However, non-x86 machines may have other cases of aliased memory so >> it's >> a case that you should cover. >> > Above example is read-only, thus won't be touched in logdirty path. > But now I agree that a specific architecture may define two > writable GPA ranges with one as the alias to the other, as long as > such case is explicitly documented so guest OS won't treat them as > separate memory pages. > > Thanks > Kevin