From patchwork Thu Jul 29 00:46:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 488649 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:1185:0:0:0:0 with SMTP id f5csp1716642jas; Wed, 28 Jul 2021 18:16:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/8pXpWJmADNKQ2ldbY2XLgDexSCq5gKqVQrNJS+BpO+aKPFxD18noP1fbMgv6146V+Vgw X-Received: by 2002:a05:6102:c0e:: with SMTP id x14mr2713410vss.47.1627521372793; Wed, 28 Jul 2021 18:16:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627521372; cv=none; d=google.com; s=arc-20160816; b=GVLQlslg/t1FFNcCDHo54ykFz/giuoVL9iPv+2VHUVKx0PH+pqSj6riAHuewhA4WbF DA0opB1tAYA8rFjadYC1m/jytNrPdQ3T3KUSvZ63nTGW9nlgp3QEL6lpskyFs+1IP96g Utnx8ZLX+DlvAsvI1YsD6NHXjlDf1LMEzAbY/jVNl3QQ0Jj6CrjSNnFRB8KW1GUPAFM5 w69eA5jF9dI5V/fZrzAc3t/y9e4VCPTmmMfo08eBbzAZmesJVP3ngG6brYt+djdMDTe9 YMsyPuUycbx+onkI57WKqcylDPr3g9v057MT93D1u9SaptqE3fs1vDwVjOWnYSX9/HgY hwTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=JXEm0LQzBp7FYdF62IKS2HTHAwaTAwDqUq6VzQ5+a94=; b=fRxpjIatJdRD4D7xqe/IxJZRGjcD3HWK6GGjk/EuV+/KiHNj9dmR3ZBjOtQZY6ix1m coQABLzdvmsQcGHcgC27iJxDtOXyg5BbWs3PboGbSBNPHV5mNyDwXBMNnV71bE8RMJ0Y KIH3MiqzosXlR4olRzPthvycXl6AfkP4bT6DpdMKK4C5TYo8Mol5oHcWyFScxFHeHnri mg3DoV7Mv2V+ZwU+EGiFb+jl55LSm/8t2NBznNaCWCrvNSGDA60azDFDBc1s5c2wGlOk 4vJQG59+YHWdwzxOyWTtHd2llfUog5a+47M8xc3bpZqE7zmR5EDtn6VN/9WO5X2cBuLx jnog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="h9U1jAz/"; 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=pass (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 z16si1103947uaa.137.2021.07.28.18.16.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Jul 2021 18:16:12 -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=pass header.i=@linaro.org header.s=google header.b="h9U1jAz/"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m8uei-0003gD-7B for patch@linaro.org; Wed, 28 Jul 2021 21:16:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38182) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m8uG6-00011L-Vd for qemu-devel@nongnu.org; Wed, 28 Jul 2021 20:50:48 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:36742) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m8uG4-0004qT-3W for qemu-devel@nongnu.org; Wed, 28 Jul 2021 20:50:46 -0400 Received: by mail-pl1-x630.google.com with SMTP id i10so4887643pla.3 for ; Wed, 28 Jul 2021 17:50:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=JXEm0LQzBp7FYdF62IKS2HTHAwaTAwDqUq6VzQ5+a94=; b=h9U1jAz/cbR1Vu6b2JV5sTg3+g9p63KkSUhM5QBA7Wluuf50ZX2yp/ZG5S2m7M1w+s yiVn7qNPA14mu2M4u87T2bYszEqOO28oB3o6L8U6kpW0tbDC+gZckQ45+vdS3xVzoW4p Pd5bMZbPLkW32qzcROJ9jyUn5ewLWJoUM+sUbJF+xNveamBZ+F+SBN+CqM58UXUI2MrR Wf0sHXgW+hjnwjeT28w4iNpWeCN8QgTu85YyBU78OQsCVmwqarUEDGXU83Q5SAPapG1Y cCAXP3K5hW/7KX+Z5Kt79ViFO2WoFv8FIbeBW4lUJ+bgmUYx034OWYjaXhxYemERwTmE LQFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JXEm0LQzBp7FYdF62IKS2HTHAwaTAwDqUq6VzQ5+a94=; b=AyZMzZLaln7M47x4PPPRnqGj8/8LtzZMJRaDxgApp+3R6nnTqB6SL/jZ4xt5W8Htsl NdCgKrjUqILpdDHtEzcswi6nEYlGu7J1r9UVleHSmp7QpE22vJNSbXyTo8d/Peugo/cG 6Z7xnHG2Uh1i9NLYov6Atnfko1ghTVwqwyqpgX7wfmEE2FZ/8AohY3ZL2Mro++cFPclm lG+UDwJU8xqiMltW302HGbsICox5Bm1XAYo82bpLTqN01tUMRqGA1sTEEQf+XTs7RpTM nJ375FQq0yrjKJKRe29JVlsj7iAwYg1K2HXu7i8VYDdCdkRvVtU+WIf8pbatft1ivfDc D9Ow== X-Gm-Message-State: AOAM532VVmBu6MpVcuGXbDtLSaS5LbolmN1mHA7gdXvzPg2KQ/vnvmWJ udWiNHw7guRLQSRLBasWkNWVywB7cDJE6w== X-Received: by 2002:a17:90b:1297:: with SMTP id fw23mr2413619pjb.115.1627519842785; Wed, 28 Jul 2021 17:50:42 -0700 (PDT) Received: from cloudburst.home (2603-800c-3202-ffa7-dcaa-9e71-a2b2-2604.res6.spectrum.com. [2603:800c:3202:ffa7:dcaa:9e71:a2b2:2604]) by smtp.gmail.com with ESMTPSA id gg3sm947137pjb.35.2021.07.28.17.50.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 17:50:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH for-6.2 43/43] tests/tcg/multiarch: Add sigbus.c Date: Wed, 28 Jul 2021 14:46:47 -1000 Message-Id: <20210729004647.282017-44-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210729004647.282017-1-richard.henderson@linaro.org> References: <20210729004647.282017-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.google.com 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_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" A mostly generic test for unaligned access raising SIGBUS. Signed-off-by: Richard Henderson --- tests/tcg/multiarch/sigbus.c | 68 ++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/tcg/multiarch/sigbus.c -- 2.25.1 diff --git a/tests/tcg/multiarch/sigbus.c b/tests/tcg/multiarch/sigbus.c new file mode 100644 index 0000000000..8134c5fd56 --- /dev/null +++ b/tests/tcg/multiarch/sigbus.c @@ -0,0 +1,68 @@ +#define _GNU_SOURCE 1 + +#include +#include +#include +#include + + +unsigned long long x = 0x8877665544332211ull; +void * volatile p = (void *)&x + 1; + +void sigbus(int sig, siginfo_t *info, void *uc) +{ + assert(sig == SIGBUS); + assert(info->si_signo == SIGBUS); +#ifdef BUS_ADRALN + assert(info->si_code == BUS_ADRALN); +#endif + assert(info->si_addr == p); + exit(EXIT_SUCCESS); +} + +int main() +{ + struct sigaction sa = { + .sa_sigaction = sigbus, + .sa_flags = SA_SIGINFO + }; + int allow_fail = 0; + int tmp; + + tmp = sigaction(SIGBUS, &sa, NULL); + assert(tmp == 0); + + /* + * Select an operation that's likely to enforce alignment. + * On many guests that support unaligned accesses by default, + * this is often an atomic operation. + */ +#if defined(__aarch64__) + asm volatile("ldxr %w0,[%1]" : "=r"(tmp) : "r"(p) : "memory"); +#elif defined(__alpha__) + asm volatile("ldl_l %0,0(%1)" : "=r"(tmp) : "r"(p) : "memory"); +#elif defined(__arm__) + asm volatile("ldrex %0,[%1]" : "=r"(tmp) : "r"(p) : "memory"); +#elif defined(__powerpc__) + asm volatile("lwarx %0,0,%1" : "=r"(tmp) : "r"(p) : "memory"); +#elif defined(__riscv_atomic) + asm volatile("lr.w %0,(%1)" : "=r"(tmp) : "r"(p) : "memory"); +#else + /* No insn known to fault unaligned -- try for a straight load. */ + allow_fail = 1; + tmp = *(volatile int *)p; +#endif + + assert(allow_fail); + + /* + * We didn't see a signal. + * We might as well validate the unaligned load worked. + */ + if (BYTE_ORDER == LITTLE_ENDIAN) { + assert(tmp == 0x55443322); + } else { + assert(tmp == 0x77665544); + } + return EXIT_SUCCESS; +}