Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp1384853ima; Fri, 1 Feb 2019 23:08:33 -0800 (PST) X-Google-Smtp-Source: ALg8bN67VP8fy6tyvLNMnk3zaWRbLtlbAwHURiG+9iUeIp3yXRcyfj2NFf8nHbwT9CFcLiT0jYd5 X-Received: by 2002:aa7:8286:: with SMTP id s6mr41805044pfm.63.1549091313654; Fri, 01 Feb 2019 23:08:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549091313; cv=none; d=google.com; s=arc-20160816; b=Qhtk4ca+aqEDqeLX8Dul2V421YFR4m9If5hso9k/0Ap10sPioesv9q+7Am2YbaWzdP /o5ORax1p6oFHbunCPoFUfDB/FMpHFAAFbdWrUTLx04QdYlF0ePj2xrdQRm2ViF8htia esvT0vGBicXrLR7SbgL5F3/4vKsNbJoUHYMQ5vqkBmCp4a7QPJ87inu2bCgoHdKcPRDN LSFeGCbdktrUGdyrzcGB09a/cdcf49Kadih9gZsPpX0GRHcNQ2CXnPSt3Ioh5J2rOq/4 MP2yUe6dnDnPLHN0YcR2JCIH4b1CCYcIfCdoQfV6QuBY0YLhuMbqXwOBqx217gUZnlJX DhyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=+r2/nz6E9bzJ8BapN2IMO+3bxDXPVlT/LkkJKlmeSng=; b=FxKCpSNB3omzcWOpHYKHIWm9MPnqQICx5QtZVzoYmVdTfAQtHd3v5kVeVprQ4zLnlH SOLjOqZ1TLCUp7aooPcz37ze7wFviH8hs9STg4utmho1u5+LLMJEuPoqAAq5f/TIYTsA HkgIdkIPY7geTWO4yXDFGQMCDEAeI3deF3OCb3h3Rz9jtuSaRqyZZ/Nc+sXg5OjsZdOL OELKfloko05JUujJLMCqMz3kKS1nkx2cASZsL2iv/ShVDhzNn+ec8o1iQpm2k67VX5pZ oteSuJyvTCYBUZxcNKcOWNq3a3ozXO4wA9Kj6cyrpNBxxTcplOmUre3qF0zRmPyAEGHC xSew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q19si9596293pfh.138.2019.02.01.23.08.17; Fri, 01 Feb 2019 23:08:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727635AbfBBG5y (ORCPT + 99 others); Sat, 2 Feb 2019 01:57:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41460 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727006AbfBBG5x (ORCPT ); Sat, 2 Feb 2019 01:57:53 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 022E989AE6; Sat, 2 Feb 2019 06:57:53 +0000 (UTC) Received: from xz-x1 (ovpn-12-23.pek2.redhat.com [10.72.12.23]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B6F7C5C20D; Sat, 2 Feb 2019 06:57:43 +0000 (UTC) Date: Sat, 2 Feb 2019 14:57:41 +0800 From: Peter Xu To: Fengguang Wu Cc: Andrew Morton , Linux Memory Management List , Nikita Leshenko , Christian Borntraeger , kvm@vger.kernel.org, LKML , Fan Du , Yao Yuan , Peng Dong , Huang Ying , Liu Jingqi , Dong Eddie , Dave Hansen , Zhang Yi , Dan Williams , Paolo Bonzini Subject: Re: [RFC][PATCH v2 14/21] kvm: register in mm_struct Message-ID: <20190202065741.GA1011@xz-x1> References: <20181226131446.330864849@intel.com> <20181226133351.894160986@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20181226133351.894160986@intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 02 Feb 2019 06:57:53 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 26, 2018 at 09:15:00PM +0800, Fengguang Wu wrote: > VM is associated with an address space and not a specific thread. > > >From Documentation/virtual/kvm/api.txt: > Only run VM ioctls from the same process (address space) that was used > to create the VM. Hi, Fengguang, AFAIU the commit message only explains why a kvm object needs to bind to a single mm object (say, the reason why there is kvm->mm) however not the reverse (say, the reason why there is mm->kvm), while the latter is what this patch really needs? I'm thinking whether it's legal for multiple VMs to run on a single mm address space. I don't see a limitation so far but it's very possible I am just missing something there (if there is, IMHO they might be something nice to put into the commit message?). Thanks, > > CC: Nikita Leshenko > CC: Christian Borntraeger > Signed-off-by: Fengguang Wu > --- > include/linux/mm_types.h | 11 +++++++++++ > virt/kvm/kvm_main.c | 3 +++ > 2 files changed, 14 insertions(+) > > --- linux.orig/include/linux/mm_types.h 2018-12-23 19:58:06.993417137 +0800 > +++ linux/include/linux/mm_types.h 2018-12-23 19:58:06.993417137 +0800 > @@ -27,6 +27,7 @@ typedef int vm_fault_t; > struct address_space; > struct mem_cgroup; > struct hmm; > +struct kvm; > > /* > * Each physical page in the system has a struct page associated with > @@ -496,6 +497,10 @@ struct mm_struct { > /* HMM needs to track a few things per mm */ > struct hmm *hmm; > #endif > + > +#if IS_ENABLED(CONFIG_KVM) > + struct kvm *kvm; > +#endif > } __randomize_layout; > > /* > @@ -507,6 +512,12 @@ struct mm_struct { > > extern struct mm_struct init_mm; > > +#if IS_ENABLED(CONFIG_KVM) > +static inline struct kvm *mm_kvm(struct mm_struct *mm) { return mm->kvm; } > +#else > +static inline struct kvm *mm_kvm(struct mm_struct *mm) { return NULL; } > +#endif > + > /* Pointer magic because the dynamic array size confuses some compilers. */ > static inline void mm_init_cpumask(struct mm_struct *mm) > { > --- linux.orig/virt/kvm/kvm_main.c 2018-12-23 19:58:06.993417137 +0800 > +++ linux/virt/kvm/kvm_main.c 2018-12-23 19:58:06.993417137 +0800 > @@ -727,6 +727,7 @@ static void kvm_destroy_vm(struct kvm *k > struct mm_struct *mm = kvm->mm; > > kvm_uevent_notify_change(KVM_EVENT_DESTROY_VM, kvm); > + mm->kvm = NULL; > kvm_destroy_vm_debugfs(kvm); > kvm_arch_sync_events(kvm); > spin_lock(&kvm_lock); > @@ -3224,6 +3225,8 @@ static int kvm_dev_ioctl_create_vm(unsig > fput(file); > return -ENOMEM; > } > + > + kvm->mm->kvm = kvm; > kvm_uevent_notify_change(KVM_EVENT_CREATE_VM, kvm); > > fd_install(r, file); > > Regards, -- Peter Xu