Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753673AbdDQL0O (ORCPT ); Mon, 17 Apr 2017 07:26:14 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:33748 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750776AbdDQL0L (ORCPT ); Mon, 17 Apr 2017 07:26:11 -0400 Subject: Re: [PATCH] x86, kvm: Handle PFNs outside of kernel reach when touching GPTEs To: "Sironi, Filippo" , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= References: <1491397622-16665-1-git-send-email-sironi@amazon.de> <20170406142201.GA2817@potion> <0C489207-F1C0-4D54-A55D-0983229F79E1@amazon.de> Cc: "Liguori, Anthony" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" From: Xiao Guangrong Message-ID: <1b77a9a3-6fc0-1258-026e-5977a6e9dba6@gmail.com> Date: Mon, 17 Apr 2017 19:26:09 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <0C489207-F1C0-4D54-A55D-0983229F79E1@amazon.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1617 Lines: 39 On 04/12/2017 09:16 PM, Sironi, Filippo wrote: > Thanks for taking the time and sorry for the delay. > >> On 6. Apr 2017, at 16:22, Radim Krčmář wrote: >> >> 2017-04-05 15:07+0200, Filippo Sironi: >>> cmpxchg_gpte() calls get_user_pages_fast() to retrieve the number of >>> pages and the respective struct pages for mapping in the kernel virtual >>> address space. >>> This doesn't work if get_user_pages_fast() is invoked with a userspace >>> virtual address that's backed by PFNs outside of kernel reach (e.g., >>> when limiting the kernel memory with mem= in the command line and using >>> /dev/mem to map memory). >>> >>> If get_user_pages_fast() fails, look up the VMA that backs the userspace >>> virtual address, compute the PFN and the physical address, and map it in >>> the kernel virtual address space with memremap(). >> >> What is the reason for a configuration that voluntarily restricts access >> to memory that it needs? > > By using /dev/mem to provide VM memory, one can avoid the overhead of allocating struct page(s) for the whole memory, which is wasteful when using a server entirely for hosting VMs. > Sounds reasonable, however it is incomplete so far as there are some code paths still do not support non-page backend memory, e.g, emulator_cmpxchg_emulated(). I would suggest to unify the code introduced in this patch with existing hva_to_pfn(), also we can introduce a common API, maybe named kvm_map_hva(), to improve the caller sides. BTW, i do not know why we used kmap_atomic() rather than kmap(), the path of cmpxchg_gpte() is sleep-able anyway. Thanks!