From patchwork Thu Oct 20 13:38:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 13013524 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3117DC433FE for ; Thu, 20 Oct 2022 13:49:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=rnkgl8VDnfIjuhhxGJZ1pRIy/4VcVrFCbKI7BYO9l3w=; b=SfuDe6cdOGEPAb zPak+kx1eLS+S5gDgl9LoHyR6xmF4wJ731Ff/d2vcAnMkpKe7i0DX+yaqfCg5xNup6tGmkhMxqcwE uISu0qx1heJ9tE3J2yJHlKn/p538LrtPSbsg5zQcnLGISouQigskM15ou8Rh5/DFCDfQ8qj5kNO6q 2JDEQjhe5flEm1Ds9Kxcjz/W/yFv0NkB+rOkMmxoa9Hq5Pc9g+mfsAdT1Os6aUYHoFscewk7244GY t9DKg/HghGUSR+W9pAgU7ljQSaquV3AtcLPHHgh0i75zFCjcMUKrjwIkZqxRCqZiZKo2iRKAEtDsL q6AJRHPFScAcMgCqfvow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1olVtq-00FjBi-Nt; Thu, 20 Oct 2022 13:47:54 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1olVl0-00FZsf-48 for linux-arm-kernel@lists.infradead.org; Thu, 20 Oct 2022 13:38:47 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8760E61B91; Thu, 20 Oct 2022 13:38:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE94EC433C1; Thu, 20 Oct 2022 13:38:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666273124; bh=yEAREzQrE4OzDm8tjXcid5kmoNA03bQzioyQnganDwc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tEHsRZXhzQn+r6DoXSFcumpw2J5k3r8/IEfKJoSHXDkYf1PpwLJGiLPqYDes2oZ5i pf+wqSSLUjtbEfBSh+AzfkNWACnuHyYlNJTRgqKmS6TA8B7OynVat6B+4/6sZNsRH8 a+hPTaV408RCOlYOGat1lrGAwT9cobp0tcab0E4D5PxOeDDilPxeC/BgKCbtUbiSLz MbamArJ7aMZ5JPgFuuaTHWWlTkElRTUhDu0c7BxMYp4OXnquv03up1L6UEYc0q/bZk dyJ+FNnB6i0u02ZrZTg/eJStUKMqToWTXtCEtEjSQyQ/wx6Kjm1K7TWNPbxgf9Bxd6 R74QKyZJp2SxA== From: Will Deacon To: kvmarm@lists.linux.dev Cc: Will Deacon , Sean Christopherson , Vincent Donnefort , Alexandru Elisei , Catalin Marinas , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , James Morse , Chao Peng , Quentin Perret , Suzuki K Poulose , Mark Rutland , Fuad Tabba , Oliver Upton , Marc Zyngier , kernel-team@android.com, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 02/25] KVM: arm64: Allow attaching of non-coalescable pages to a hyp pool Date: Thu, 20 Oct 2022 14:38:04 +0100 Message-Id: <20221020133827.5541-3-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221020133827.5541-1-will@kernel.org> References: <20221020133827.5541-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221020_063846_277027_3C23DC0B X-CRM114-Status: GOOD ( 15.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Quentin Perret All the contiguous pages used to initialize a 'struct hyp_pool' are considered coalescable, which means that the hyp page allocator will actively try to merge them with their buddies on the hyp_put_page() path. However, using hyp_put_page() on a page that is not part of the inital memory range given to a hyp_pool() is currently unsupported. In order to allow dynamically extending hyp pools at run-time, add a check to __hyp_attach_page() to allow inserting 'external' pages into the free-list of order 0. This will be necessary to allow lazy donation of pages from the host to the hypervisor when allocating guest stage-2 page-table pages at EL2. Tested-by: Vincent Donnefort Signed-off-by: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/nvhe/page_alloc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm64/kvm/hyp/nvhe/page_alloc.c b/arch/arm64/kvm/hyp/nvhe/page_alloc.c index 1ded09fc9b10..0d15227aced8 100644 --- a/arch/arm64/kvm/hyp/nvhe/page_alloc.c +++ b/arch/arm64/kvm/hyp/nvhe/page_alloc.c @@ -93,11 +93,15 @@ static inline struct hyp_page *node_to_page(struct list_head *node) static void __hyp_attach_page(struct hyp_pool *pool, struct hyp_page *p) { + phys_addr_t phys = hyp_page_to_phys(p); unsigned short order = p->order; struct hyp_page *buddy; memset(hyp_page_to_virt(p), 0, PAGE_SIZE << p->order); + if (phys < pool->range_start || phys >= pool->range_end) + goto insert; + /* * Only the first struct hyp_page of a high-order page (otherwise known * as the 'head') should have p->order set. The non-head pages should @@ -116,6 +120,7 @@ static void __hyp_attach_page(struct hyp_pool *pool, p = min(p, buddy); } +insert: /* Mark the new head, and insert it */ p->order = order; page_add_to_list(p, &pool->free_area[order]);