From patchwork Tue Jan 16 18:53:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 10167941 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3EA3F600CA for ; Tue, 16 Jan 2018 18:54:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B17D20223 for ; Tue, 16 Jan 2018 18:54:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1FCEA204FD; Tue, 16 Jan 2018 18:54:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C204820223 for ; Tue, 16 Jan 2018 18:54:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751451AbeAPSyn (ORCPT ); Tue, 16 Jan 2018 13:54:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:62251 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751118AbeAPSym (ORCPT ); Tue, 16 Jan 2018 13:54:42 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 714ABC070E30; Tue, 16 Jan 2018 18:54:42 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.43.2.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7B5E609B4; Tue, 16 Jan 2018 18:54:31 +0000 (UTC) From: Andrew Jones To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, cdall@linaro.org, david@redhat.com, lvivier@redhat.com, thuth@redhat.com Subject: [PATCH kvm-unit-tests 06/11] phys_alloc: ensure we account all allocations Date: Tue, 16 Jan 2018 19:53:07 +0100 Message-Id: <20180116185312.7257-7-drjones@redhat.com> In-Reply-To: <20180116185312.7257-1-drjones@redhat.com> References: <20180116185312.7257-1-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 16 Jan 2018 18:54:42 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Also throw another assert into phys_alloc_aligned_safe. Signed-off-by: Andrew Jones --- lib/alloc_phys.c | 10 ++++++++++ lib/alloc_phys.h | 6 ++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/alloc_phys.c b/lib/alloc_phys.c index d09395d1010c..736c3129fc02 100644 --- a/lib/alloc_phys.c +++ b/lib/alloc_phys.c @@ -81,6 +81,8 @@ static phys_addr_t phys_alloc_aligned_safe(phys_addr_t size, if (safe && sizeof(long) == 4) top_safe = MIN(top_safe, 1ULL << 32); + assert(base < top_safe); + addr = ALIGN(base, align); size += addr - base; @@ -116,6 +118,14 @@ void phys_alloc_get_unused(phys_addr_t *p_base, phys_addr_t *p_top) { *p_base = base; *p_top = top; + if (base == top) + return; + spin_lock(&lock); + regions[nr_regions].base = base; + regions[nr_regions].size = top - base; + ++nr_regions; + base = top; + spin_unlock(&lock); } static void *early_memalign(size_t alignment, size_t size) diff --git a/lib/alloc_phys.h b/lib/alloc_phys.h index 848d3db23a1e..7cf59a661180 100644 --- a/lib/alloc_phys.h +++ b/lib/alloc_phys.h @@ -37,8 +37,10 @@ extern void phys_alloc_set_minimum_alignment(phys_addr_t align); extern void phys_alloc_show(void); /* - * phys_alloc_get_unused returns the addresses for the still-unused part - * of the initial free memory region passed to phys_alloc_init. + * phys_alloc_get_unused allocates all remaining memory from the region + * passed to phys_alloc_init, returning the newly allocated memory's base + * and top addresses. phys_allo_get_unused will still return base and top + * when no free memory is remaining, but base will equal top. */ extern void phys_alloc_get_unused(phys_addr_t *p_base, phys_addr_t *p_top);