Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp499686pxf; Thu, 11 Mar 2021 08:18:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJybpE6/EOQ1E5k9qo1nT4rPdfuxtYOnYz9daLiwW/2boSDK5o5ffJWERg5g0THXn3RigrBV X-Received: by 2002:a50:9dcd:: with SMTP id l13mr9363531edk.220.1615479538141; Thu, 11 Mar 2021 08:18:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615479538; cv=none; d=google.com; s=arc-20160816; b=ZTj6OzMCGa4xdyg57NV11CACWsvvx0WhVUk0hw3Ksj5oeYhAoprwyQ9GASbO5v/kVW EWmaSN+1dR6VELO3e4Cz3pAu3VYDeePXEtGwoLslP4wrMAM0PlCWvU76Cziho1OqYcsw MInQZzFXhF7yE2LzvH/jq9H7SM2j0UnNMzZGMLkrDe+2w27oGsCxJh8gTRV7i1Q73as8 1NspkcL32r51GYHLlB4NEqGz1bfmQkeqQuptQ/fbHO2uHsCgMEBzC2ul4Y+ozOEwDRev TW7KzxExsp3keigOC65m8FDQ/eQDAsrowNhPaD2Rljw5SBmUnWHftECmz1UY7K5oBzaf Hfvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=zbgVlpYJ7bSQq/29bODLI5wXwZaknloK8stz4phPzfM=; b=k7oRqwBz0FTewwnYrtpCdmyZwzTLl4Oi16Cu23E9cB/Qql/4/jQHL5k6Jg5t3Vg4Yl Z8IijQr2SbUwTI/+3lKuM1J+cLfqE77QfgvIFn4V2v8KiDddEBgHcCTvwvUSdAHbq525 gWan8V1ywYFMficvrR4Evq7OGlx2F1JJmdKfma9Kgs3PCirG3ry8L1xRfAszbfc59xsq i93HdJKryD6uPcAT4Q31pYsJJcwv5sQ2YY8+2usqkxK4Lf+kTLJeVzZKB6KW+HXZ/PTu vmvQhMw3uBh7XabrdEUWjXNKkaQGYBCGykLT2qN40sPsNUwOyfFXxVlwfC9J8XHHSgE6 4oPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i8MnI3+2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y40si2194631ede.204.2021.03.11.08.18.35; Thu, 11 Mar 2021 08:18:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i8MnI3+2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234526AbhCKQPI (ORCPT + 99 others); Thu, 11 Mar 2021 11:15:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:51134 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234431AbhCKQOt (ORCPT ); Thu, 11 Mar 2021 11:14:49 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id AFD5464F88; Thu, 11 Mar 2021 16:14:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615479288; bh=qYDGWCW64bxyZudXVN5dkVQ3DwMt7Dn8FEVKXvpunG4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=i8MnI3+2/a4u7kdasK8yp0GaOhcv8jnkA0X0v12U8iXfzM0yXF00qlOJQJ8BLfxR5 SnPL1CygmdEkO3n6m167qfRXk7n9zJx/PGswMJN3JnCgolPkglroyEnbPjel4Fq5LP 1yHs7VglYuyH6+Eh34R9mwABULkfgq9200BQns63jNQjRiJATlopDnbhkoPGNlq66y ruNVpmIy/icGq9PgJjCT8YCHy4irUwrh0eyvmpmb0QZt7fz/XlOMiRbrRVgbCud2js 0MrnSAz1IeSLEuIJbhrD54+im2PZkuBoIndFzApzln30phdH25lNkXlpxqIENZCiCV D+iGWJPBqZCCQ== Date: Thu, 11 Mar 2021 16:14:42 +0000 From: Will Deacon To: Quentin Perret Cc: catalin.marinas@arm.com, maz@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, android-kvm@google.com, linux-kernel@vger.kernel.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, tabba@google.com, mark.rutland@arm.com, dbrazdil@google.com, mate.toth-pal@arm.com, seanjc@google.com, robh+dt@kernel.org, ardb@kernel.org Subject: Re: [PATCH v4 12/34] KVM: arm64: Introduce a Hyp buddy page allocator Message-ID: <20210311161441.GC31206@willie-the-truck> References: <20210310175751.3320106-1-qperret@google.com> <20210310175751.3320106-13-qperret@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210310175751.3320106-13-qperret@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 10, 2021 at 05:57:29PM +0000, Quentin Perret wrote: > When memory protection is enabled, the hyp code will require a basic > form of memory management in order to allocate and free memory pages at > EL2. This is needed for various use-cases, including the creation of hyp > mappings or the allocation of stage 2 page tables. > > To address these use-case, introduce a simple memory allocator in the > hyp code. The allocator is designed as a conventional 'buddy allocator', > working with a page granularity. It allows to allocate and free > physically contiguous pages from memory 'pools', with a guaranteed order > alignment in the PA space. Each page in a memory pool is associated > with a struct hyp_page which holds the page's metadata, including its > refcount, as well as its current order, hence mimicking the kernel's > buddy system in the GFP infrastructure. The hyp_page metadata are made > accessible through a hyp_vmemmap, following the concept of > SPARSE_VMEMMAP in the kernel. > > Signed-off-by: Quentin Perret > --- > arch/arm64/kvm/hyp/include/nvhe/gfp.h | 68 ++++++++ > arch/arm64/kvm/hyp/include/nvhe/memory.h | 28 ++++ > arch/arm64/kvm/hyp/nvhe/Makefile | 2 +- > arch/arm64/kvm/hyp/nvhe/page_alloc.c | 195 +++++++++++++++++++++++ > 4 files changed, 292 insertions(+), 1 deletion(-) > create mode 100644 arch/arm64/kvm/hyp/include/nvhe/gfp.h > create mode 100644 arch/arm64/kvm/hyp/nvhe/page_alloc.c Eventually, we can replace the refcount with refcount_t, but for now this looks pretty good: Acked-by: Will Deacon Will