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=-3.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 4B1B9C433E0 for ; Tue, 14 Jul 2020 08:56:32 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (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 89DEB20BED for ; Tue, 14 Jul 2020 08:56:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=pm.me header.i=@pm.me header.b="dGWvypy7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 89DEB20BED Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=pm.me Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernelnewbies-bounces@kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94) (envelope-from ) id 1jvGix-00060M-TX; Tue, 14 Jul 2020 04:55:39 -0400 Received: from mail-40133.protonmail.ch ([185.70.40.133]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from <0x60@pm.me>) id 1jvGis-00060E-Fq for kernelnewbies@kernelnewbies.org; Tue, 14 Jul 2020 04:55:34 -0400 Date: Tue, 14 Jul 2020 08:55:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1594716930; bh=twdi4emNOl6DNGtDRWQzH01/Gy/PMI9jM/TOoIwH1Js=; h=Date:To:From:Reply-To:Subject:From; b=dGWvypy7xW6AmSolvDk1FfudxO3w8fHrKg2xg8+9ShqlWQIXuurn3BtdzuirYEawh EwBzWCQiUBoKRLRTljCt2ZO66o//fxQ9xf5sCiMI5CtmTMRKxtPDsfPt5hx15yQcFp xAR0xaiWRwZXLkcRSM803894uK67ElboVQwx1ncGynZQ8a0eVtor+EkLVgOdXLz4A6 o+n7QNOEhQbtM9/x9VAdJan9oSTN1km5DVK2X16n2Znd84BJ/Ixv06aaU/ui2Dpql3 mXPfO2yAKl+Jr+mGjfQFhRryoBhzajBvxcRa1/CQ4PWSXsASl0jXryhOH8VDIOtNH7 tMbt7DqsM4pew== To: "kernelnewbies@kernelnewbies.org" From: heep <0x60@pm.me> Subject: Re: Turn private hugetlb mapping into VM_SHARED Message-ID: MIME-Version: 1.0 X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: heep <0x60@pm.me> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kernelnewbies-bounces@kernelnewbies.org > Hello, list, > > I am working on a tool to introspect live memory of KVM machines, and mmapping its memory, instead of calling process_vm_readv on every read, would increase its performance significantly. Understandably, almost all virtual machine monitors (like QEMU) create private mappings for the memory. So, trying to understand the memory managment subsystem I am hoping to write a kernel module to do the remappings, and conversion from private, to shared mappings. > > My current focus is on hugetlb pages. At first, I remapped the pages using remap_pfn_range, but there is a memory safety risk when the VM shuts off, and that memory gets used elsewhere. Now, I am trying to turn the underlying mapping into a shared one, so that the kernel can keep track of the memory used. What would be the best way to do so? > > I noticed there is resv_map that stores represented mappings, and while on private mappings it's on vma, on the shared ones - it is in the inode, but making the inode point to the VMAs map leads to a bus error in userspace. I must be missing some key pieces. > > Does anyone know how to best achieve what I am trying to? Or is it something fundamentally wrong to do? > > Many thanks, > Auri B. It appears I have been mistaken when it came to remap_pfn_range being memory unsafe, I just haven't read get_user_pages_remote documentation attentively enough. Sorry for that, this whole unshared -> shared mapping change is very much not the right thing to do. _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies