From patchwork Fri Feb 25 17:20:21 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: 545913 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp518159imf; Fri, 25 Feb 2022 09:59:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJzrJUG+Ubji1PtkkhWcaqgbCYzNEbX6L0AiiQNONW6IqRdW4TRybxMSqa2R8kMXCh93vinu X-Received: by 2002:a0c:ffb4:0:b0:432:5198:f398 with SMTP id d20-20020a0cffb4000000b004325198f398mr6813806qvv.12.1645811980613; Fri, 25 Feb 2022 09:59:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645811980; cv=none; d=google.com; s=arc-20160816; b=BYL+WVKkV2R1/w6oD3qD1hHIwTmGf/pzWQ5b44rWvGFIqYPyHEXOxGiSFA67RWqjyM Wg5/Z4iqX2QSswaJbzA8v2D67DjoTSObfm7NCHmhnLCHPdxtkufcZ6j9eH0eAI+Ujfts 4U9Kg0I2qyNGPMgz3L+A6KrD3qJ1zFRNDKcPbrX39XD/mteb7GZR8ohQuxnpptzogPll EPI+Aduhk0as54qQa6pcd2FFlx4HqGPj1ZCNFsqYhAx2SE/3DrCmy7A8FH+jR/5DhbgP wWQVlNPMyIR1Rs7x8TGo/LMB7NXqk/BQ310DU340W7PZv58wHB48/8xjkIx9KbanYDKR cFdA== 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=JR//9KiItwNd050+o2fTFYSPa/InsS8zg93yxzEMbvU=; b=sp13TzcYQzOAccUpOWA2bsM/3/Cl8gm5af7+XBmESbvrYddWODFtyGMiea0tcWdhM+ omjERa5G5o98PzmqqH8/mx373sDN2IrFW1Ewps1q6hfM5PCnUinM9xNNq4T8JVbwnDH+ An/gRwTOXpPvfpPeGSU0QBpB8ZNhClKFkYOudf3EBgVeATMql6fxGiVk1IAvBFMjPt+f I4S7frGiNNGn0EWFTAyFUJFUxrGRrc0zUHhwL4eGwgYPPigPbYGVGtU2+w+fnPXNd4HE jf5H7g8toha0bI7ZvIyA64o6O72QAaPBxdqNHG1OgqEqMy6m3A4S3TiXn6sFl1Z74hAs vz0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MIR9fjQG; 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 m9-20020a05620a214900b006626a423fdbsi989631qkm.393.2022.02.25.09.59.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 25 Feb 2022 09:59:40 -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=MIR9fjQG; 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]:56136 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nNesW-0002Id-4m for patch@linaro.org; Fri, 25 Feb 2022 12:59:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNeH7-0004ML-BO for qemu-devel@nongnu.org; Fri, 25 Feb 2022 12:21:01 -0500 Received: from [2a00:1450:4864:20::635] (port=33665 helo=mail-ej1-x635.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nNeGz-0002Ph-68 for qemu-devel@nongnu.org; Fri, 25 Feb 2022 12:21:01 -0500 Received: by mail-ej1-x635.google.com with SMTP id vz16so12272807ejb.0 for ; Fri, 25 Feb 2022 09:20:44 -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=JR//9KiItwNd050+o2fTFYSPa/InsS8zg93yxzEMbvU=; b=MIR9fjQGObmfYVyPs8RiTn1Gyn9PhdLYqKP9mjQ0tWCU60JtVv/OPe9COr5aNqlT8n N2b3AsAmKY4Pb1qXDiahycL+UB25K4w2C018tf+BSaPvBaOLL8bg9s4TYolwBrgjVEYE SaqC8UyUW2blolstwkuHd8n6FRa6jzAlUa20jnTQtSAYsCiotc2UX9gaJTvOn9O6aJoa hJoQCgqlBD5gnr+RT7Mr97hoqOMBbkYEFSGR8tHD5IuA1i5F4BrHV45L/4Yu1PQE/MtI Gx+tzyKAKIzyC7lCW+8/dc0lVNaEFjUvONo0BO5K+KYAaIE8m++u5kUKXExkOKCfWFRt wXvg== 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=JR//9KiItwNd050+o2fTFYSPa/InsS8zg93yxzEMbvU=; b=J+snzyW8OUJYSIelNPdxH9EyiN1FqSnzaC6dNfaTpRdcnMB2C9QQLe/AJMzmnqVpok zmrnWk8ijSpZz706hqIalVA7DQJ2Wze7h5hjcyr0kN6xqrJkJQYYqoFRvA/VzZtY3wo1 mAdkebLwAeR0YzFB+sFd66YpWNsvQBwjDX64oPZXUpqpxAO1VyW8m4brdolGTXH6OY9H PnF9nxBUfDcuTDvXuzu/X5o0tdQ2XJFZik8o/fK7FZZHEBAzvfwncsuPsdWuJtyEXxnM sa79Kir+LmSynWYWszO79KUMF9SQBQ2fzPWlKd2Bt1bu8ix6qTsbH+w6gKaoU8u0ZSkA 6t1Q== X-Gm-Message-State: AOAM532iCop/bd2Bdz4j/I8NoZ7L/kbTvJwuBQDXBaKKTiRnFR6TVw1s uTgDPUBfUb8rUYkTLNeXRsuYzg== X-Received: by 2002:a17:906:3803:b0:6cf:56b9:60a9 with SMTP id v3-20020a170906380300b006cf56b960a9mr6613981ejc.716.1645809643944; Fri, 25 Feb 2022 09:20:43 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id r3-20020aa7cb83000000b0040decce18bdsm1571180edt.99.2022.02.25.09.20.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 09:20:39 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id D2AA61FFCA; Fri, 25 Feb 2022 17:20:23 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 18/18] tests/tcg: port SYS_HEAPINFO to a system test Date: Fri, 25 Feb 2022 17:20:21 +0000 Message-Id: <20220225172021.3493923-19-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220225172021.3493923-1-alex.bennee@linaro.org> References: <20220225172021.3493923-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::635 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::635; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x635.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: fam@euphon.net, Peter Maydell , berrange@redhat.com, sw@weilnetz.de, richard.henderson@linaro.org, f4bug@amsat.org, qemu-arm@nongnu.org, stefanha@redhat.com, crosa@redhat.com, pbonzini@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= , aurelien@aurel32.net 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: <20220210113021.3799514-3-alex.bennee@linaro.org> --- tests/tcg/aarch64/system/semiheap.c | 93 +++++++++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 94 insertions(+) create mode 100644 tests/tcg/aarch64/system/semiheap.c 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