From patchwork Tue Mar 1 09:47:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 547258 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp3537698imf; Tue, 1 Mar 2022 02:23:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJzYFddehVbyDl6MprSsPXA4z0nHZEuwZYlx+YX1wowHb8Gcz77PJzEOqDTgxYaA5e8lj8KE X-Received: by 2002:a05:620a:2183:b0:648:cd3f:b255 with SMTP id g3-20020a05620a218300b00648cd3fb255mr13315656qka.86.1646130182688; Tue, 01 Mar 2022 02:23:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646130182; cv=none; d=google.com; s=arc-20160816; b=gzQi6KffxGzGr2O2mAVLPIXcoESlSDvuX6a4XBlwF4bNLRc9D3UcDxOP3muhT+uQhz D0Emv0CJPE82IsP1Y3BKchH0UGW+sy8wo9Ub1O8FxW7/w/F/TAXElItxkuOdRRD4ppH0 GP6UZjDKakSbMvzXjJRIMhjGwXlKYi9qGv+PjFCX3cmOefGsbr3VOANMIuztPgHp0rvu +BkqjRwYK2edNbWScWp6HQ6NWq618GUATB/AfVXVTnftjLNJF/oERU65Eoo0BgUKmVnH oqK6EXvAYRK5/+S1PPE8qdXQpFB9+dr/vfUI4ddbbt9mWfzDV+BMTY7M3+IwO7xKQxi9 yRcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=9R6z4B4mLQw367uaJ4iZig/x1Xw1bFRMsLiBv+G2ki8=; b=XSQ9FF0sOl+qdXrzPWAHXnJ+MknaBZ7z0dhlFUG3zOXrQZkyyxrBQXVX8WtRYt0bVl tYM5inOUn38cFyyT0dZBiceQgE57BwpF773G42HH7wa1YrmWqfwftbj6h0W11OqsU7hl X4tqO/c8SuNdLObdEy3wxE7dseTeqjvL2Up2EK2xp4hiKXsd8e09Npgij/pZW+cPV/6/ Uki8yOq8dha7eO1x4jmB+eTItbvP5YN5BWu+OL6wO/lDykRUnVYK/iuN+glq5nulCx8n OP8JFeDpwMNvxFqgZ5n4jeYN64o3BPGzSoyqlm4BJCB0nUhqDwkvgKpSEs/wiwmmGRFY Wmqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=TQq3gcfz; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o27-20020a05620a22db00b00648e88ee67fsi4241454qki.707.2022.03.01.02.23.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 01 Mar 2022 02:23:02 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=TQq3gcfz; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nOzeo-0003OR-7l for patch@linaro.org; Tue, 01 Mar 2022 05:23:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:49566) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nOzEz-0007yk-UQ for qemu-devel@nongnu.org; Tue, 01 Mar 2022 04:56:22 -0500 Received: from [2a00:1450:4864:20::62f] (port=33567 helo=mail-ej1-x62f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nOzEx-0001xO-9j for qemu-devel@nongnu.org; Tue, 01 Mar 2022 04:56:21 -0500 Received: by mail-ej1-x62f.google.com with SMTP id kt27so1247039ejb.0 for ; Tue, 01 Mar 2022 01:56:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9R6z4B4mLQw367uaJ4iZig/x1Xw1bFRMsLiBv+G2ki8=; b=TQq3gcfzRziqDVVKW7ML8jejLp+dF63fMJ5uHLXDBMSjq4cnh9EfLlUUrHpYbyR4sL eJm1zKwqV3WVd/crcfaZzXop9okmDtyWNRcYwRpwTHXXtg8y0sERTFGBTiaELNRqgxLw 6/2nPpWnB6zpa+rH4H+z1D0Xik/Ez4VIzTrXfnpzSR0+2nOb+cYJBgf/XNpAGK6O/UR/ xzTBmZQEZCxzYWeix4g8+OzBpk6XJhsEzl4nT1MCo61ExCKxxIL9pfazKjGTar9PJf57 RfkBplejo2pVv93GWBM1U5VFDHTewAkImz2FUmbVUzXM+VMROBGmBQHune7PcTedYk1c /ZDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9R6z4B4mLQw367uaJ4iZig/x1Xw1bFRMsLiBv+G2ki8=; b=lMauhKCerAD38y0KRIWsOg6gC510k+KO+FOg5XPYCiZZJ4XSvp8+cehbFBIx6bJ920 N3dyNWTSofH+/y/svQl8BcMHMZMbzw3Fbmw6XPwCL/rxn6tHg+MHWG1u+SxemBf2PXhr uztOAd/JUIiotj5UiQOHent2800lYsg4qYdoEG6TID+w0ddgS5Ny6E+ZcwAn/bcA0u+6 XdBlDbPbu4pxj2qsqiJGFZMWBZ26fbcCSa1FgeXUDGR5gDdMCBTD0oIMCKP3/vBeC67u B/3wN+o96IQh+0e05BI1tnsVRh3KyEzAN8qQ41LzrGtXhYE7DkSRXRc7JA6lT/C5sHBu /thQ== X-Gm-Message-State: AOAM532f3OB2MZeMpprxxkGvIv55iF/MUyIlKoktYe8E3VoZQNJHrcrd nhCaNHOYgl+l2jDjlqZr3of8lQ== X-Received: by 2002:a17:906:743:b0:6d0:7f19:d737 with SMTP id z3-20020a170906074300b006d07f19d737mr18550517ejb.11.1646128576865; Tue, 01 Mar 2022 01:56:16 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id ov6-20020a170906fc0600b006cf54ef58ddsm5256400ejb.149.2022.03.01.01.56.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Mar 2022 01:56:16 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 04F4E1FFCA; Tue, 1 Mar 2022 09:47:17 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Subject: [PULL 18/18] tests/tcg: port SYS_HEAPINFO to a system test Date: Tue, 1 Mar 2022 09:47:15 +0000 Message-Id: <20220301094715.550871-19-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220301094715.550871-1-alex.bennee@linaro.org> References: <20220301094715.550871-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::62f (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::62f; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x62f.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "open list:ARM TCG CPUs" , =?utf-8?q?Alex_Benn?= =?utf-8?q?=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This allows us to check our new SYS_HEAPINFO implementation generates sane values. Signed-off-by: Alex Bennée Reviewed-by: Peter Maydell Message-Id: <20220225172021.3493923-19-alex.bennee@linaro.org> diff --git a/tests/tcg/aarch64/system/semiheap.c b/tests/tcg/aarch64/system/semiheap.c new file mode 100644 index 0000000000..4ed258476d --- /dev/null +++ b/tests/tcg/aarch64/system/semiheap.c @@ -0,0 +1,93 @@ +/* + * Semihosting System HEAPINFO Test + * + * Copyright (c) 2021 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include +#include + +#define SYS_HEAPINFO 0x16 + +uintptr_t __semi_call(uintptr_t type, uintptr_t arg0) +{ + register uintptr_t t asm("x0") = type; + register uintptr_t a0 asm("x1") = arg0; + asm("hlt 0xf000" + : "=r" (t) + : "r" (t), "r" (a0) + : "memory" ); + + return t; +} + +int main(int argc, char *argv[argc]) +{ + struct { + void *heap_base; + void *heap_limit; + void *stack_base; + void *stack_limit; + } info = { }; + void *ptr_to_info = (void *) &info; + uint32_t *ptr_to_heap; + int i; + + ml_printf("Semihosting Heap Info Test\n"); + + __semi_call(SYS_HEAPINFO, (uintptr_t) &ptr_to_info); + + if (info.heap_base == NULL || info.heap_limit == NULL) { + ml_printf("null heap: %p -> %p\n", info.heap_base, info.heap_limit); + return -1; + } + + /* Error if heap base is above limit */ + if ((uintptr_t) info.heap_base >= (uintptr_t) info.heap_limit) { + ml_printf("heap base %p >= heap_limit %p\n", + info.heap_base, info.heap_limit); + return -2; + } + + if (info.stack_base == NULL) { + ml_printf("null stack: %p -> %p\n", info.stack_base, info.stack_limit); + return -3; + } + + /* + * boot.S put our stack somewhere inside the data segment of the + * ELF file, and we know that SYS_HEAPINFO won't pick a range + * that overlaps with part of a loaded ELF file. So the info + * struct (on the stack) should not be inside the reported heap. + */ + if (ptr_to_info > info.heap_base && ptr_to_info < info.heap_limit) { + ml_printf("info appears to be inside the heap: %p in %p:%p\n", + ptr_to_info, info.heap_base, info.heap_limit); + return -4; + } + + ml_printf("heap: %p -> %p\n", info.heap_base, info.heap_limit); + ml_printf("stack: %p <- %p\n", info.stack_limit, info.stack_base); + + /* finally can we read/write the heap */ + ptr_to_heap = (uint32_t *) info.heap_base; + for (i = 0; i < 512; i++) { + *ptr_to_heap++ = i; + } + ptr_to_heap = (uint32_t *) info.heap_base; + for (i = 0; i < 512; i++) { + uint32_t tmp = *ptr_to_heap; + if (tmp != i) { + ml_printf("unexpected value in heap: %d @ %p", tmp, ptr_to_heap); + return -5; + } + ptr_to_heap++; + } + ml_printf("r/w to heap upto %p\n", ptr_to_heap); + + ml_printf("Passed HeapInfo checks\n"); + return 0; +} diff --git a/MAINTAINERS b/MAINTAINERS index fa8adc2618..68adaac373 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3549,6 +3549,7 @@ S: Maintained F: semihosting/ F: include/semihosting/ F: tests/tcg/multiarch/arm-compat-semi/ +F: tests/tcg/aarch64/system/semiheap.c Multi-process QEMU M: Elena Ufimtseva