From patchwork Fri Mar 19 10:01:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12150519 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.0 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 57875C433E6 for ; Fri, 19 Mar 2021 10:04:55 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 8F00064EF6 for ; Fri, 19 Mar 2021 10:04:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8F00064EF6 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=desiato.20200630; 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=GwtprJ+MG75VG6bIoYFuvP59jfP5ozaJTgJmomHJuoU=; b=P3/Y9hmcArBhmT pUd+bsXAIz5X2+OVAfMzoBb8PNeeCBGDapPM0CYrPuc7YUTrxrtCHaoSaUaUcbDKzFZ/3YZHAte1B eNpRfSpYMTme1DZIbzZvqqf8cjOIPkeW8TLnxDze59Uze/rzhevz08pwExQmpQlmPHYt5YKcOkSbA +ym1Br23wcyw7vi0C6xozQ3obY/qZBNPBtXUEz9r/ZX9WAsXhKBZTjbf1Cfc309YvvNreuRBC2lHe tWHT57W28QpvZaw66PN0ieeurxAI5cXK5+1vhrgHW6CQFzXgK+BSEdmoLbIqDE/YTtNSC2SqRNQSs ugg0KciN9coKIf/cud4g==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lNBy6-0070UH-9R; Fri, 19 Mar 2021 10:02:58 +0000 Received: from mail-qv1-xf49.google.com ([2607:f8b0:4864:20::f49]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lNBxB-00707z-St for linux-arm-kernel@lists.infradead.org; Fri, 19 Mar 2021 10:02:05 +0000 Received: by mail-qv1-xf49.google.com with SMTP id s16so31787195qvw.3 for ; Fri, 19 Mar 2021 03:02:01 -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=TccyldlGh8jyXKeMFND/Hm+ER293Gl9fJb4reK7MIeI=; b=aMJKsUpMZtoc6Vo/NUkiAkgYytwPwSWdxjtMAs/nwSVhtmr7fkCBs4zK4jrX9Yto1t 74J9Oa4XC1AXlMHlxsjiWj0R+BJ/BW71UzD9HCCF5luXJ6jarXUOYwcVVJiF/gr8VTqx myolrurPb6MIli6tKDX09K3FlNugO6bAL+YGGRoS0if+l6Ke09o0IeRRed9bXZwdSsc7 2NpwMa0ikNeXDOX4HRkuwwDYa/uvCiM4/rq5BHexXiim5y6aSnWh0wLRHXcKZAqE+7je 7ENBURMGCufhIVy84m7LAuCtnB/TvZ8pLGRbR8xZBGQYsyFEAC6sVdPK5f6txbQ0Em3n Rliw== 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=TccyldlGh8jyXKeMFND/Hm+ER293Gl9fJb4reK7MIeI=; b=faqM1wTvZj0f02Tb3vRuwinq8QBs74zXLXpdaSHLmPvcJoxFcxUA7sa97RW7uj6Fj0 lTXexTkX1W+8B52uClef+R9ir82TROZqUXc2vqt+lTJV/TZtFYnBGPjWeKyTY7fq6vv9 NAuOZn+gbtU1IAgpxGTJmtE5fKYXPkwMoeiePGfJlNo1y6uhtPEx12vhH9VYcvhOX+hp mnx6aeNJdgBfpZZGDRd7BEfsqAZ0QConOD38hOa4tjneJyXc3XUuxfMzup8lUqPCEo3H RjtouvqxrKkpdlpVfESReFnFsmEf7WM31B2ujmSSsbwHFJ60ZGM0GiRJVTeYhibVYOvI WheA== X-Gm-Message-State: AOAM5323X7QU14Ug06IVohlQQn8ZuW6NthhDlpgFMCarqpJzm3M4rHV9 zk1KFIIjfUVmd0UVo6KEuzs5/WQzXK7f X-Google-Smtp-Source: ABdhPJyAfHPltOr6Ii1E0fGpZSgU/xa1c+709JNQ28p9DHhYeGy8ayWuxcmcxY1y7/l8XTGyuuWxYQ0eD4Sf X-Received: from r2d2-qp.c.googlers.com ([fda3:e722:ac3:10:28:9cb1:c0a8:1652]) (user=qperret job=sendgmr) by 2002:a0c:df02:: with SMTP id g2mr8475100qvl.40.1616148120563; Fri, 19 Mar 2021 03:02:00 -0700 (PDT) Date: Fri, 19 Mar 2021 10:01:13 +0000 In-Reply-To: <20210319100146.1149909-1-qperret@google.com> Message-Id: <20210319100146.1149909-6-qperret@google.com> Mime-Version: 1.0 References: <20210319100146.1149909-1-qperret@google.com> X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH v6 05/38] KVM: arm64: Avoid free_page() in page-table allocator From: Quentin Perret To: catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com Cc: android-kvm@google.com, seanjc@google.com, mate.toth-pal@arm.com, linux-kernel@vger.kernel.org, robh+dt@kernel.org, linux-arm-kernel@lists.infradead.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, tabba@google.com, ardb@kernel.org, mark.rutland@arm.com, dbrazdil@google.com, qperret@google.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210319_100202_044074_56EFCA06 X-CRM114-Status: GOOD ( 12.89 ) 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 Currently, the KVM page-table allocator uses a mix of put_page() and free_page() calls depending on the context even though page-allocation is always achieved using variants of __get_free_page(). Make the code consistent by using put_page() throughout, and reduce the memory management API surface used by the page-table code. This will ease factoring out page-allocation from pgtable.c, which is a pre-requisite to creating page-tables at EL2. Acked-by: Will Deacon Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/pgtable.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 926fc07074f5..0990fda19198 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -414,7 +414,7 @@ int kvm_pgtable_hyp_init(struct kvm_pgtable *pgt, u32 va_bits) static int hyp_free_walker(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, enum kvm_pgtable_walk_flags flag, void * const arg) { - free_page((unsigned long)kvm_pte_follow(*ptep)); + put_page(virt_to_page(kvm_pte_follow(*ptep))); return 0; } @@ -426,7 +426,7 @@ void kvm_pgtable_hyp_destroy(struct kvm_pgtable *pgt) }; WARN_ON(kvm_pgtable_walk(pgt, 0, BIT(pgt->ia_bits), &walker)); - free_page((unsigned long)pgt->pgd); + put_page(virt_to_page(pgt->pgd)); pgt->pgd = NULL; } @@ -578,7 +578,7 @@ static int stage2_map_walk_table_post(u64 addr, u64 end, u32 level, if (!data->anchor) return 0; - free_page((unsigned long)kvm_pte_follow(*ptep)); + put_page(virt_to_page(kvm_pte_follow(*ptep))); put_page(virt_to_page(ptep)); if (data->anchor == ptep) { @@ -701,7 +701,7 @@ static int stage2_unmap_walker(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, } if (childp) - free_page((unsigned long)childp); + put_page(virt_to_page(childp)); return 0; } @@ -898,7 +898,7 @@ static int stage2_free_walker(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, put_page(virt_to_page(ptep)); if (kvm_pte_table(pte, level)) - free_page((unsigned long)kvm_pte_follow(pte)); + put_page(virt_to_page(kvm_pte_follow(pte))); return 0; }