Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp517097pxj; Thu, 27 May 2021 05:52:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4DS9HVVbU6rBi/nbDYzYpm3sjRcQqhluyzo8Kd17QV2yGMEUEMmXRbDTDAggUhKg/zXuE X-Received: by 2002:a5d:8a16:: with SMTP id w22mr2670094iod.186.1622119971569; Thu, 27 May 2021 05:52:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622119971; cv=none; d=google.com; s=arc-20160816; b=CdT6X17tM3ZLEgJeC9wQY3mcCRmGrmdwLk/ES+IAl5KAREbW8A+v+PbvKHD2vFLGXz xkiXx6mXJ4iWTjs/ULA9Qaduaw1lurCRT7WvEEn9VcfkwrnuWB9/1jNiq6bDXmRlJcOF yE9w63wh80LKH/upmJgsheLhR60k5D3ajQzzCreFJUxoVzCtwzsKODLq5i9L3SJMdkVA yAlZE65qdp16FD++Y/sW+XqHjFYrxX/JFCYaehMtD2EpJl5mHyU4hfs6c2xPY27XxgHB l9UJQvZkYljHmbS1yP9Q8xpJz9/Irpif13nAFYfhTlTBxMd/moOoVLJMClDaXJc/FGH2 /Wlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=gi5cRmDtyloWJMITCIj/sPnhDqshqX/If7D8pZ+Fco8=; b=L/B0OSV07K76XyUfLKnKhYM7WHGQ5S/h2ZD4bYuMMjJ9IH6GS4GfBlDAWqTHlBbRXm aGwq9eswm8uAFoDPkoza/oHB/hJ1RM2Y9psllpJn3qqs95tBt0+gw3npDM/ZP2PujEZW WbcV4VVdR38+v09c+38PkFb0dHXZr04hI+BD/Y+uMTTPWJXFbyOVp+8ZXipgEhBKncaz KhlAxjZ6snRo3jc37ZHXr5wnEgNhCns1yNrmRD6ddwXf42ah0BCN1zPPI375YtaEyCxy WoCB/UA0lJ8V6mDxFwYzDfvUGMLd0qtrrRC0gWQVXCFm+R2w714fV/rIErUuvhjY8pA8 msSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="DMh/Pwje"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j13si2038459ilk.14.2021.05.27.05.52.37; Thu, 27 May 2021 05:52:51 -0700 (PDT) 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=@google.com header.s=20161025 header.b="DMh/Pwje"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235914AbhE0Mx2 (ORCPT + 99 others); Thu, 27 May 2021 08:53:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235854AbhE0MxS (ORCPT ); Thu, 27 May 2021 08:53:18 -0400 Received: from mail-ed1-x549.google.com (mail-ed1-x549.google.com [IPv6:2a00:1450:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB9A9C061763 for ; Thu, 27 May 2021 05:51:44 -0700 (PDT) Received: by mail-ed1-x549.google.com with SMTP id s20-20020a0564025214b029038752a2d8f3so274385edd.2 for ; Thu, 27 May 2021 05:51:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=gi5cRmDtyloWJMITCIj/sPnhDqshqX/If7D8pZ+Fco8=; b=DMh/PwjeROpCuIsXL8vRKNGEi9sHS19ekOOPLJW/yYZpcAXKCDh4kFuF6iI/aU1kMl Gd3tI584HoLn+kctQ7quFOApvKA4kHemuJ26RXQjx3fbsek7WyRVBTy4z/hDTF8/7CEL zxQX0nPp35II7RVacLFWT/l/To+3fVcczDHqZzs1XFABFaNr9SgLwX30EBRUuUMGhiEz 5euHTt9w+mN6fCrPAsZ1YWV8quDogTUAATc6+C9p/KeVUkcsAtPRHini8QK1D0L79neA NUHURMi7p+5iRahsNBMDoS6FlUOqIo57NM1IYG8tkhwHWec9RAnj7z1x/hxWSkIx0PPp axhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=gi5cRmDtyloWJMITCIj/sPnhDqshqX/If7D8pZ+Fco8=; b=AKCbKvj4VnGGoMVAXMPwmKUtEtYEKVEPkAYCmj2n0BBDRwlVKbPO926CC/G1InhFoj 0MfaaA5Ym5XiRrZ7Yc6sMlbwUmX+VP3FqyFvvzi3W6TPIkGc0u9IbwC/qE7Bg48bQ6lJ 6QgVFEnEAWnWWNYVJCNEZpT3o3AHutl+trO3BuHqZggtJ0OrNPo6PN17QyozGFfE3m5l t9eicceS1TIAO1/AyLQbTkcjBXUh0qWuurgoPPpcBKkayoLc9+JSqaKTm5fqcX72C127 EU6qOLF0NQP9X9glGuyMrua/bIGdGV/q2EBPOHR3ZRhvC5OKPCvMJT5/irAN1sh1QzqA J09g== X-Gm-Message-State: AOAM530v7yA8JOPzcokZISSKLciRCs//AI8PQhJymgWgXvtIGTNa6Rcj d72UoIH5fHytu+/AKf51h6J241705xM+ X-Received: from r2d2-qp.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1652]) (user=qperret job=sendgmr) by 2002:a17:907:770a:: with SMTP id kw10mr3675153ejc.213.1622119903222; Thu, 27 May 2021 05:51:43 -0700 (PDT) Date: Thu, 27 May 2021 12:51:30 +0000 In-Reply-To: <20210527125134.2116404-1-qperret@google.com> Message-Id: <20210527125134.2116404-4-qperret@google.com> Mime-Version: 1.0 References: <20210527125134.2116404-1-qperret@google.com> X-Mailer: git-send-email 2.31.1.818.g46aad6cb9e-goog Subject: [PATCH 3/7] KVM: arm64: Remove list_head from hyp_page From: Quentin Perret To: maz@kernel.org, will@kernel.org, james.morse@arm.com, alexandru.elisei@arm.com, catalin.marinas@arm.com, suzuki.poulose@arm.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kernel-team@android.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The list_head member of struct hyp_page is only needed when the page is attached to a free-list, which by definition implies the page is free. As such, nothing prevents us from using the page itself to store the list_head, hence reducing the size of the vmemmap. Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/include/nvhe/memory.h | 1 - arch/arm64/kvm/hyp/nvhe/page_alloc.c | 39 ++++++++++++++++++++---- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/nvhe/memory.h b/arch/arm64/kvm/hyp/include/nvhe/memory.h index fd78bde939ee..7691ab495eb4 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/memory.h +++ b/arch/arm64/kvm/hyp/include/nvhe/memory.h @@ -12,7 +12,6 @@ struct hyp_page { unsigned int refcount; unsigned int order; struct hyp_pool *pool; - struct list_head node; }; extern u64 __hyp_vmemmap; diff --git a/arch/arm64/kvm/hyp/nvhe/page_alloc.c b/arch/arm64/kvm/hyp/nvhe/page_alloc.c index 7ee882f36767..ce7379f1480b 100644 --- a/arch/arm64/kvm/hyp/nvhe/page_alloc.c +++ b/arch/arm64/kvm/hyp/nvhe/page_alloc.c @@ -62,6 +62,34 @@ static struct hyp_page *__find_buddy_avail(struct hyp_pool *pool, } +/* + * Pages that are available for allocation are tracked in free-lists, so we use + * the pages themselves to store the list nodes to avoid wasting space. As the + * allocator always returns zeroed pages (which are zeroed on the hyp_put_page() + * path to optimize allocation speed), we also need to clean-up the list node in + * each page when we take it out of the list. + */ +static inline void page_remove_from_list(struct hyp_page *p) +{ + struct list_head *node = (struct list_head *)hyp_page_to_virt(p); + + __list_del_entry(node); + memset(node, 0, sizeof(*node)); +} + +static inline void page_add_to_list(struct hyp_page *p, struct list_head *head) +{ + struct list_head *node = (struct list_head *)hyp_page_to_virt(p); + + INIT_LIST_HEAD(node); + list_add_tail(node, head); +} + +static inline struct hyp_page *node_to_page(struct list_head *node) +{ + return (struct hyp_page *)hyp_virt_to_page(node); +} + static void __hyp_attach_page(struct hyp_pool *pool, struct hyp_page *p) { @@ -83,14 +111,14 @@ static void __hyp_attach_page(struct hyp_pool *pool, break; /* Take the buddy out of its list, and coallesce with @p */ - list_del_init(&buddy->node); + page_remove_from_list(buddy); buddy->order = HYP_NO_ORDER; p = min(p, buddy); } /* Mark the new head, and insert it */ p->order = order; - list_add_tail(&p->node, &pool->free_area[order]); + page_add_to_list(p, &pool->free_area[order]); } static struct hyp_page *__hyp_extract_page(struct hyp_pool *pool, @@ -99,7 +127,7 @@ static struct hyp_page *__hyp_extract_page(struct hyp_pool *pool, { struct hyp_page *buddy; - list_del_init(&p->node); + page_remove_from_list(p); while (p->order > order) { /* * The buddy of order n - 1 currently has HYP_NO_ORDER as it @@ -110,7 +138,7 @@ static struct hyp_page *__hyp_extract_page(struct hyp_pool *pool, p->order--; buddy = __find_buddy_nocheck(pool, p, p->order); buddy->order = p->order; - list_add_tail(&buddy->node, &pool->free_area[buddy->order]); + page_add_to_list(buddy, &pool->free_area[buddy->order]); } return p; @@ -158,7 +186,7 @@ void *hyp_alloc_pages(struct hyp_pool *pool, unsigned int order) } /* Extract it from the tree at the right order */ - p = list_first_entry(&pool->free_area[i], struct hyp_page, node); + p = node_to_page(pool->free_area[i].next); p = __hyp_extract_page(pool, p, order); hyp_set_page_refcounted(p); @@ -186,7 +214,6 @@ int hyp_pool_init(struct hyp_pool *pool, u64 pfn, unsigned int nr_pages, for (i = 0; i < nr_pages; i++) { p[i].pool = pool; p[i].order = 0; - INIT_LIST_HEAD(&p[i].node); hyp_set_page_refcounted(&p[i]); } -- 2.31.1.818.g46aad6cb9e-goog