From patchwork Wed May 27 10:05:46 2020 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: 187226 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp975794ilb; Wed, 27 May 2020 03:07:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOYOTG083EcCygtKnEhxjzXWRxAZFiDFm5O856Zlg5/44Fd5+mOUcvO1DLfle2ThJIYSTf X-Received: by 2002:a05:620a:22d0:: with SMTP id o16mr3001800qki.345.1590574053528; Wed, 27 May 2020 03:07:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590574053; cv=none; d=google.com; s=arc-20160816; b=zDhfrRY3AWGVWmmx0xYk7ydbiM6GX4mZQDGLhQo1F+acXYPqcpEvLJdv+SYbL2famt woEHoBghxmYaD0uMxsqk14JSK+vZQ8EPOIWYru5Cgs87QjvNg7xO3iOiNMtcbYt/A/T+ yhaQklfzwpdILw3icowbxIFDOUgFD0tzE4WkUnt/HyQO3LviRvlyLXV6I/OTsoucCB4a tWaO1GboO06jASusmxwL88dJyhShz5eBCzPvg0tKHQuK+0zezChctYc/V2VaczvWKGZB cyFjcpRcyIDWmgt9z5Sw3hkR6mAg0wLBdc2HhzVP0Tbrp7ZnLmbo4GUcvjk4nEdFdrv1 qy0Q== 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=7BwVQR+RWIzqLy1PIq/KCliSSJ727LeNTpr8QNS3EBg=; b=w714vC4qvseI6+Rf6qx2OlmCJ0OlUT0lkbVjdWjX4PJn8Jxyxybl4dX5zx+92iJkPz QL1lJQpb1fCUQAk8y9q6gC2gubWLdskBsPvrptiK7SKKN4XCZTtbMJWQ4o537lkAXbHr J2kJMNMvh0HewXGXboeEU3YrLrpBPiokLY5PrFuifQlR/ZwHzy+9HvBDU0Am+RI05zIp /Ye6ejN7mdl5YwVQhBBzpuAttdG6L9Qb7Wpaz1WWt2Yb022e1NurSQ0KG7Xe3EUZLoX4 2Eywky7GuxN6RAU3khUBv9DGb0v9lkTr7WClkxa2I+mFDaGPkgoIQ6moQqxEH77cvMfa u4WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=OijwdnFo; 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 p16si1350248qtj.43.2020.05.27.03.07.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 27 May 2020 03:07:33 -0700 (PDT) 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=OijwdnFo; 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]:55100 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jdsyD-0006WN-2K for patch@linaro.org; Wed, 27 May 2020 06:07:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50278) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdswd-0003UU-UM for qemu-devel@nongnu.org; Wed, 27 May 2020 06:05:55 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:41529) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jdswb-0005CZ-Cm for qemu-devel@nongnu.org; Wed, 27 May 2020 06:05:55 -0400 Received: by mail-wr1-x441.google.com with SMTP id j10so7799058wrw.8 for ; Wed, 27 May 2020 03:05:52 -0700 (PDT) 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=7BwVQR+RWIzqLy1PIq/KCliSSJ727LeNTpr8QNS3EBg=; b=OijwdnFog7MJOKgQXuIpzoT9zTo2dRa22snN1e8PLCTgtegtiufaLSHXf31GGRSzo5 i3EmIUqduEqP3s20UJIESHxq2Sy0zkU5gqtWbjJKOz6lqcH9VpTyX3iX4Zz+V++zEPbM nrWxXM6MVBIh9YyzSp12zYwLWdsWad/KhJAJMi29K+8Snk0AvjBPmvUVj3RPyduqeOGf yRRu5ZGGq/gO2hXnEAA2Vdp1PPdaAe0185NhbFZcH4TUfPbw3vSLf9CE7TqoWY2uGtPm Rt3OLk9viPuNE04H6uqTp/Y6NhiNGKB113jJejopfwxKOK0T1lrxS2uiwGQoHxT7VqfR Na7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7BwVQR+RWIzqLy1PIq/KCliSSJ727LeNTpr8QNS3EBg=; b=n9xBy2tdz3ssqYvdt7QBaMWtkRIsA4Ca69bo3zKtfEnqHlP3mJiKhjHxN7QZCS77/k oTaIRBVBbvyfNrg/sm2r8izx6TK9CDI9VQOCpCbppiQgaWW9y7vV9cz8FAifzPn0YCWV LSNHCXvvzkrHQg+aEbh0He6rZSqQ86HZZetvldJ2DG86aMhuiFJypk3PqCjHRnJGBKbK Ry/HPbZo9kyzCewBRFiXufnfob5NJCM+AR39jdlG1II4b6qco6W/mBDa7g+qiXMTwk5h pSmCG+14EGiLZcrk5z6nr9RAliQ+N7dnAoiGK1ZzhwpdBsGMIJBeeYA5wWpFY4vOuSGz 4qcQ== X-Gm-Message-State: AOAM5321Mra5RPHiL7jIovFA6i2Z4Q9PPuvO+rSSyMvVppbgOQAbadwZ 252NTATJR2c4YNk3Ax48D+akdg== X-Received: by 2002:adf:e38e:: with SMTP id e14mr25153823wrm.2.1590573951548; Wed, 27 May 2020 03:05:51 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id t6sm2202636wma.4.2020.05.27.03.05.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2020 03:05:50 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 479B81FF8F; Wed, 27 May 2020 11:05:47 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 3/3] tests/tcg: add simple commpage test case Date: Wed, 27 May 2020 11:05:46 +0100 Message-Id: <20200527100546.29297-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200527100546.29297-1-alex.bennee@linaro.org> References: <20200527100546.29297-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::441; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x441.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The COMMPAGE are a number of kernel provided user-space routines for 32 bit ARM systems. Add a basic series of smoke tests to ensure it is working as it should. Signed-off-by: Alex Bennée --- tests/tcg/arm/commpage.c | 61 +++++++++++++++++++++++++++++++++++ tests/tcg/arm/Makefile.target | 2 ++ 2 files changed, 63 insertions(+) create mode 100644 tests/tcg/arm/commpage.c -- 2.20.1 Reviewed-by: Richard Henderson diff --git a/tests/tcg/arm/commpage.c b/tests/tcg/arm/commpage.c new file mode 100644 index 00000000000..c76e70cb8bd --- /dev/null +++ b/tests/tcg/arm/commpage.c @@ -0,0 +1,61 @@ +/* + * Verify the COMMPAGE emulation + * + * The ARM commpage is a set of user space helper functions provided + * by the kernel in an effort to ease portability of user space code + * between different CPUs with potentially different capabilities. It + * is a 32 bit invention and similar to the vdso segment in many ways. + * + * The ABI is documented in the Linux kernel: + * Documentation/arm/kernel_userspace_helpers.rst + * + * Copyright (c) 2020 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include +#include + +#define ARM_COMMPAGE (0xffff0f00u) +#define ARM_KUSER_VERSION (*(int32_t *)(ARM_COMMPAGE + 0xfc)) +typedef void * (get_tls_fn)(void); +#define ARM_KUSER_GET_TLS (*(get_tls_fn *)(ARM_COMMPAGE + 0xe0)) +typedef int (cmpxchg_fn)(int oldval, int newval, volatile int *ptr); +#define ARM_KUSER_CMPXCHG (*(cmpxchg_fn *)(ARM_COMMPAGE + 0xc0)) +typedef void (dmb_fn)(void); +#define ARM_KUSER_DMB (*(dmb_fn *)(ARM_COMMPAGE + 0xa0)) +typedef int (cmpxchg64_fn)(const int64_t *oldval, + const int64_t *newval, + volatile int64_t *ptr); +#define ARM_KUSER_CMPXCHG64 (*(cmpxchg64_fn *)(ARM_COMMPAGE + 0x60)) + +#define fail_unless(x) \ + do { \ + if (!(x)) { \ + fprintf(stderr, "FAILED at %s:%d\n", __FILE__, __LINE__); \ + exit(EXIT_FAILURE); \ + } \ + } while (0) + + +int main(int argc, char *argv[argc]) +{ + void *kuser_tls; + int val = 1; + const int64_t oldval = 1, newval = 2; + int64_t val64 = 1; + + fail_unless(ARM_KUSER_VERSION == 0x5); + kuser_tls = ARM_KUSER_GET_TLS(); + printf("TLS = %p\n", kuser_tls); + fail_unless(kuser_tls != 0); + fail_unless(ARM_KUSER_CMPXCHG(1, 2, &val) == 0); + printf("val = %d\n", val); + /* this is a crash test, not checking an actual barrier occurs */ + ARM_KUSER_DMB(); + fail_unless(ARM_KUSER_CMPXCHG64(&oldval, &newval, &val64) == 0); + printf("val64 = %lld\n", val64); + return 0; +} diff --git a/tests/tcg/arm/Makefile.target b/tests/tcg/arm/Makefile.target index 11c39c601ea..3da09a38be7 100644 --- a/tests/tcg/arm/Makefile.target +++ b/tests/tcg/arm/Makefile.target @@ -68,6 +68,8 @@ run-semiconsole-arm: semiconsole-arm run-plugin-semiconsole-arm-with-%: $(call skip-test, $<, "MANUAL ONLY") +ARM_TESTS += commpage + TESTS += $(ARM_TESTS) # On ARM Linux only supports 4k pages