From patchwork Thu May 27 12:51:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12284085 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7571BC4707F for ; Thu, 27 May 2021 12:56:35 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 41E1B60FE6 for ; Thu, 27 May 2021 12:56:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 41E1B60FE6 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=NnzesJTVu0SClWry7roBhTXT51NT0JTRlp6CkSkKu38=; b=HSWkSmm8TNmisAjssm6ay4sMiV QULaSVCaHlrIoErIcgkXNv0x/tBLbmoLODqi5U85vHpA1e9QWoc+/A4UavQCX7T62PN/DFYHrBKzK FkZRJXb8X+6o4pj9NUzvdNC83xKDng6dhlHPpUyWVpvRKD4L0Qh8dC613ME/bBHQzNTjvUVjDXzbi AmANhn0uCg201/N20GrPk12z5Xsd9q4Bd6QUKEUDCBwwHXz4XvAeevDcSP0BIZXAisDdFu2JlWoS5 4g4Q1GRMvB+L348FOf8H9TBkTv0aGtjVAdd/sglSo3qqyNITAyp5ZC8L5z3J6Uh6rl3jGG+uVy9Tg LMSxQz+Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lmFWF-005uVE-O3; Thu, 27 May 2021 12:53:48 +0000 Received: from mail-qt1-x849.google.com ([2607:f8b0:4864:20::849]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lmFUM-005tUN-S1 for linux-arm-kernel@lists.infradead.org; Thu, 27 May 2021 12:51:52 +0000 Received: by mail-qt1-x849.google.com with SMTP id j19-20020ac85f930000b029021f033edf60so53438qta.10 for ; Thu, 27 May 2021 05:51:49 -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=ehs1oQ+8oLxIXVrBNHuhZcAo+D2g9l++j8BZLV6gtTA=; b=a+FtUAFPFyiW0uYlgwR0eSULr6xYa8BpYbZNF6URd1JNP9Jw9Hd23+lAYigwVkhKoW lyFAkrD2tp/8dk2Rn0LshAJLDfuuF3tyfte6wErSyLZlahexM9sr15qTiMWbRy54SmxA CXiqPJ+PxMN1vY+PA3Qkvfqu2y/7s+tGazebtbYsQ+NKZbUxq46OS/xDMwFrSHKhJI8N Q50Hl2GkR08amV3wg4iJhrweLLG/4tHzM6TtJFHyR9LfjuSmNPtKWyKL4Ik1TCtRVESm 4i4sOBb2IvH511qCVxCI/ubxHWCHIZCq9RxmfVeCzmQC4cK/P8RVV750oUvTNGoiuWHm IDYQ== 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=ehs1oQ+8oLxIXVrBNHuhZcAo+D2g9l++j8BZLV6gtTA=; b=AnMHjZv4/cfmiu89VKwNJJd6u7QYwp0jeu2sau6wmu9v5a5NxdBQo1JsapwYK7dFzM EFNUs3OvjX6wGUeXCnukS1aXKPBxxeGGZm5SnnCnpLpLT5XcQZ/7tzQfGy5HT2GA2Snw slc18UrsFH0HGE57tMpZ6M5bIsuPAQL3Jqkk0SdoNRtkwZ9XsXcnFbqD/mgAi/gocM/W Q75lpajmzIVCnCWMoGQaeLS2TgnNIkabh4fSCGa0dieesoASjPHEF5ng9xsPj/oX5sns 1tc5Qp/7tGaCoHIcgOyYc7kDjxUEJmH+hUX0UYVjTMapwh37TaWQ2MPywRlPiQhSeJ5J IMXg== X-Gm-Message-State: AOAM530828nndPkhXeo0hWICFa/FJlrWH56G0qlD4ZfgPH824rGqqJOV PEThe2nMyCSyYFErq9wYe+7TSuCGhVJ1 X-Google-Smtp-Source: ABdhPJyaKy4GEnKIJ/S5dR75Z6Sp8g/ueH5v6TANNcDxhzHPzuTTPn0wYyWBm/8d245iHVbNGmkmL9vYBxK9 X-Received: from r2d2-qp.c.googlers.com ([fda3:e722:ac3:10:28:9cb1:c0a8:1652]) (user=qperret job=sendgmr) by 2002:a0c:9e4e:: with SMTP id z14mr3459560qve.31.1622119907499; Thu, 27 May 2021 05:51:47 -0700 (PDT) Date: Thu, 27 May 2021 12:51:32 +0000 In-Reply-To: <20210527125134.2116404-1-qperret@google.com> Message-Id: <20210527125134.2116404-6-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 5/7] KVM: arm64: Remove hyp_pool pointer from struct 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210527_055150_948144_6760A83B 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 Each struct hyp_page currently contains a pointer to a hyp_pool struct where the page should be freed if its refcount reaches 0. However, this information can always be inferred from the context in the EL2 code, so drop the pointer to save a few bytes in the vmemmap. Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/include/nvhe/gfp.h | 4 ++-- arch/arm64/kvm/hyp/include/nvhe/memory.h | 2 -- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 13 +++++++++++-- arch/arm64/kvm/hyp/nvhe/page_alloc.c | 7 ++----- arch/arm64/kvm/hyp/nvhe/setup.c | 14 ++++++++++++-- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/nvhe/gfp.h b/arch/arm64/kvm/hyp/include/nvhe/gfp.h index aada4d97de49..9ed374648364 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/gfp.h +++ b/arch/arm64/kvm/hyp/include/nvhe/gfp.h @@ -42,8 +42,8 @@ static inline void hyp_set_page_refcounted(struct hyp_page *p) /* Allocation */ void *hyp_alloc_pages(struct hyp_pool *pool, unsigned int order); -void hyp_get_page(void *addr); -void hyp_put_page(void *addr); +void hyp_get_page(void *addr, struct hyp_pool *pool); +void hyp_put_page(void *addr, struct hyp_pool *pool); /* Used pages cannot be freed */ int hyp_pool_init(struct hyp_pool *pool, u64 pfn, unsigned int nr_pages, diff --git a/arch/arm64/kvm/hyp/include/nvhe/memory.h b/arch/arm64/kvm/hyp/include/nvhe/memory.h index 7691ab495eb4..991636be2f46 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/memory.h +++ b/arch/arm64/kvm/hyp/include/nvhe/memory.h @@ -7,11 +7,9 @@ #include -struct hyp_pool; struct hyp_page { unsigned int refcount; unsigned int order; - struct hyp_pool *pool; }; extern u64 __hyp_vmemmap; diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index fdd5b5702e8a..3603311eb41c 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -42,6 +42,15 @@ static void *host_s2_zalloc_page(void *pool) { return hyp_alloc_pages(pool, 0); } +static void host_s2_get_page(void *addr) +{ + hyp_get_page(addr, &host_s2_pool); +} + +static void host_s2_put_page(void *addr) +{ + hyp_put_page(addr, &host_s2_pool); +} static int prepare_s2_pool(void *pgt_pool_base) { @@ -60,8 +69,8 @@ static int prepare_s2_pool(void *pgt_pool_base) .phys_to_virt = hyp_phys_to_virt, .virt_to_phys = hyp_virt_to_phys, .page_count = hyp_page_count, - .get_page = hyp_get_page, - .put_page = hyp_put_page, + .get_page = host_s2_get_page, + .put_page = host_s2_put_page, }; return 0; diff --git a/arch/arm64/kvm/hyp/nvhe/page_alloc.c b/arch/arm64/kvm/hyp/nvhe/page_alloc.c index ce7379f1480b..e453108a2d95 100644 --- a/arch/arm64/kvm/hyp/nvhe/page_alloc.c +++ b/arch/arm64/kvm/hyp/nvhe/page_alloc.c @@ -150,20 +150,18 @@ static void __hyp_put_page(struct hyp_pool *pool, struct hyp_page *p) __hyp_attach_page(pool, p); } -void hyp_put_page(void *addr) +void hyp_put_page(void *addr, struct hyp_pool *pool) { struct hyp_page *p = hyp_virt_to_page(addr); - struct hyp_pool *pool = hyp_page_to_pool(p); hyp_spin_lock(&pool->lock); __hyp_put_page(pool, p); hyp_spin_unlock(&pool->lock); } -void hyp_get_page(void *addr) +void hyp_get_page(void *addr, struct hyp_pool *pool) { struct hyp_page *p = hyp_virt_to_page(addr); - struct hyp_pool *pool = hyp_page_to_pool(p); hyp_spin_lock(&pool->lock); hyp_page_ref_inc(p); @@ -212,7 +210,6 @@ int hyp_pool_init(struct hyp_pool *pool, u64 pfn, unsigned int nr_pages, /* Init the vmemmap portion */ p = hyp_phys_to_page(phys); for (i = 0; i < nr_pages; i++) { - p[i].pool = pool; p[i].order = 0; hyp_set_page_refcounted(&p[i]); } diff --git a/arch/arm64/kvm/hyp/nvhe/setup.c b/arch/arm64/kvm/hyp/nvhe/setup.c index 709cb3d19eb7..bf61abd4a330 100644 --- a/arch/arm64/kvm/hyp/nvhe/setup.c +++ b/arch/arm64/kvm/hyp/nvhe/setup.c @@ -137,6 +137,16 @@ static void *hyp_zalloc_hyp_page(void *arg) return hyp_alloc_pages(&hpool, 0); } +static void hpool_get_page(void *addr) +{ + hyp_get_page(addr, &hpool); +} + +static void hpool_put_page(void *addr) +{ + hyp_put_page(addr, &hpool); +} + void __noreturn __pkvm_init_finalise(void) { struct kvm_host_data *host_data = this_cpu_ptr(&kvm_host_data); @@ -160,8 +170,8 @@ void __noreturn __pkvm_init_finalise(void) .zalloc_page = hyp_zalloc_hyp_page, .phys_to_virt = hyp_phys_to_virt, .virt_to_phys = hyp_virt_to_phys, - .get_page = hyp_get_page, - .put_page = hyp_put_page, + .get_page = hpool_get_page, + .put_page = hpool_put_page, }; pkvm_pgtable.mm_ops = &pkvm_pgtable_mm_ops;