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=-1.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,SUBJ_ALL_CAPS,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 49C94C10F14 for ; Thu, 3 Oct 2019 15:44:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 186D721783 for ; Thu, 3 Oct 2019 15:44:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 186D721783 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A25BB6B0005; Thu, 3 Oct 2019 11:44:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D54E6B0006; Thu, 3 Oct 2019 11:44:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C46B6B0007; Thu, 3 Oct 2019 11:44:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0008.hostedemail.com [216.40.44.8]) by kanga.kvack.org (Postfix) with ESMTP id 6AC436B0005 for ; Thu, 3 Oct 2019 11:44:01 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 07418824CA1F for ; Thu, 3 Oct 2019 15:44:01 +0000 (UTC) X-FDA: 76002894282.29.fall80_400453c954236 X-HE-Tag: fall80_400453c954236 X-Filterd-Recvd-Size: 5276 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Thu, 3 Oct 2019 15:43:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CD2AD3082231; Thu, 3 Oct 2019 15:43:58 +0000 (UTC) Received: from redhat.com (ovpn-112-54.rdu2.redhat.com [10.10.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3DB7119C69; Thu, 3 Oct 2019 15:43:49 +0000 (UTC) Date: Thu, 3 Oct 2019 11:42:33 -0400 From: Jerome Glisse To: Paolo Bonzini Cc: Mircea CIRJALIU - MELIU , Adalbert =?utf-8?B?TGF6xINy?= , Matthew Wilcox , "kvm@vger.kernel.org" , "linux-mm@kvack.org" , "virtualization@lists.linux-foundation.org" , Radim =?utf-8?B?S3LEjW3DocWZ?= , Konrad Rzeszutek Wilk , Tamas K Lengyel , Mathieu Tarral , Samuel =?iso-8859-1?Q?Laur=E9n?= , Patrick Colp , Jan Kiszka , Stefan Hajnoczi , Weijiang Yang , Yu C , Mihai =?utf-8?B?RG9uyJt1?= Subject: Re: DANGER WILL ROBINSON, DANGER Message-ID: <20191003154233.GA4421@redhat.com> References: <20190905180955.GA3251@redhat.com> <5b0966de-b690-fb7b-5a72-bc7906459168@redhat.com> <20191002192714.GA5020@redhat.com> <20191002141542.GA5669@redhat.com> <20191002170429.GA8189@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.1 (2019-06-15) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 03 Oct 2019 15:43:59 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Oct 02, 2019 at 10:10:18PM +0200, Paolo Bonzini wrote: > On 02/10/19 19:04, Jerome Glisse wrote: > > On Wed, Oct 02, 2019 at 06:18:06PM +0200, Paolo Bonzini wrote: > >>>> If the mapping of the source VMA changes, mirroring can update the > >>>> target VMA via insert_pfn. But what ensures that KVM's MMU notifi= er > >>>> dismantles its own existing page tables (so that they can be recre= ated > >>>> with the new mapping from the source VMA)? > >> > >> The KVM inspector process is also (or can be) a QEMU that will have = to > >> create its own KVM guest page table. So if a page in the source VMA= is > >> unmapped we want: > >> > >> - the source KVM to invalidate its guest page table (done by the KVM= MMU > >> notifier) > >> > >> - the target VMA to be invalidated (easy using mirroring) > >> > >> - the target KVM to invalidate its guest page table, as a result of > >> invalidation of the target VMA > >=20 > > You can do the target KVM invalidation inside the mirroring invalidat= ion > > code. >=20 > Why should the source and target KVMs behave differently? If the sourc= e > invalidates its guest page table via MMU notifiers, so should the targe= t. >=20 > The KVM MMU notifier exists so that nothing (including mirroring) needs > to know that there is KVM on the other side. Any interaction between > KVM page tables and VMAs must be mediated by MMU notifiers, anything > else is unacceptable. >=20 > If it is possible to invoke the MMU notifiers around the calls to > insert_pfn, that of course would be perfect. Ok and yes you can do that exactly ie inside the mmu notifier callback from the target. For instance it is as easy as: target_mirror_notifier_start_callback(start, end) { struct kvm_mirror_struct *kvmms =3D from_mmun(...); unsigned long target_foff, size; size =3D end - start; target_foff =3D kvmms_convert_mirror_address(start); take_lock(kvmms->mirror_fault_exclusion_lock); unmap_mapping_range(kvmms->address_space, target_foff, size, 1); drop_lock(kvmms->mirror_fault_exclusion_lock); } All that is needed is to make sure that vm_normal_page() will see those pte (inside the process that is mirroring the other process) as special which is the case either because insert_pfn() mark the pte as special or the kvm device driver which control the vm_operation struct set a find_special_page() callback that always return NULL, or the vma has either VM_PFNMAP or VM_MIXEDMAP set (which is the case with insert_pfn). So you can keep the existing kvm code unmodified. Cheers, J=E9r=F4me