From mboxrd@z Thu Jan 1 00:00:00 1970 From: Arnd Bergmann Subject: Re: [PATCH v6 04/10] arm64: hyperv: Add memory alloc/free functions for Hyper-V size pages Date: Mon, 16 Mar 2020 09:32:34 +0100 Message-ID: References: <1584200119-18594-1-git-send-email-mikelley@microsoft.com> <1584200119-18594-5-git-send-email-mikelley@microsoft.com> <632eb459dbe53a9b69df2a4f030a755b@kernel.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Return-path: Received: from mout.kundenserver.de ([217.72.192.74]:45621 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729978AbgCPIcy (ORCPT ); Mon, 16 Mar 2020 04:32:54 -0400 In-Reply-To: <632eb459dbe53a9b69df2a4f030a755b@kernel.org> Sender: linux-arch-owner@vger.kernel.org List-ID: To: Marc Zyngier Cc: Michael Kelley , Will Deacon , Ard Biesheuvel , Catalin Marinas , Mark Rutland , Linux ARM , gregkh , "linux-kernel@vger.kernel.org" , linux-hyperv@vger.kernel.org, linux-efi , linux-arch , olaf@aepfle.de, Andy Whitcroft , Vitaly Kuznetsov , Jason Wang , marcelo.cerri@canonical.com, "K. Y. Srinivasan" , sunilmut@microsoft.com, Boqun Feng On Mon, Mar 16, 2020 at 9:30 AM Marc Zyngier wrote: > On 2020-03-16 08:22, Arnd Bergmann wrote: > > On Sat, Mar 14, 2020 at 4:36 PM Michael Kelley > > wrote: > >> /* > >> + * Functions for allocating and freeing memory with size and > >> + * alignment HV_HYP_PAGE_SIZE. These functions are needed because > >> + * the guest page size may not be the same as the Hyper-V page > >> + * size. We depend upon kmalloc() aligning power-of-two size > >> + * allocations to the allocation size boundary, so that the > >> + * allocated memory appears to Hyper-V as a page of the size > >> + * it expects. > >> + * > >> + * These functions are used by arm64 specific code as well as > >> + * arch independent Hyper-V drivers. > >> + */ > >> + > >> +void *hv_alloc_hyperv_page(void) > >> +{ > >> + BUILD_BUG_ON(PAGE_SIZE < HV_HYP_PAGE_SIZE); > >> + return kmalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL); > >> +} > >> +EXPORT_SYMBOL_GPL(hv_alloc_hyperv_page); > > > > I don't think there is any guarantee that kmalloc() returns > > page-aligned > > allocations in general. > > I believe that guarantee came with 59bb47985c1db ("mm, sl[aou]b: > guarantee > natural alignment for kmalloc(power-of-two)"). > > > How about using get_free_pages() to implement this? > > This would certainly work, at the expense of a lot of wasted memory when > PAGE_SIZE isn't 4k. I'm sure this is the least of your problems when the guest runs with a large base page size, you've already wasted most of your memory otherwise then. Arnd