From patchwork Tue Aug 3 04:14:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 490875 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:396:0:0:0:0 with SMTP id y22csp316090jap; Mon, 2 Aug 2021 21:35:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzL+ioZbI9E+qXWGaP83Fc1i3SeEQcTRHQN21AUrj1JWAoTSf55o93WVvW8UD0cKNPXjpig X-Received: by 2002:a92:cd0c:: with SMTP id z12mr216274iln.190.1627965354182; Mon, 02 Aug 2021 21:35:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627965354; cv=none; d=google.com; s=arc-20160816; b=wpDO9y44Nh/9Vm3GDhSHsOl9JqjcCIM17LjIbpBYPPm++qS/GA8MPvK1NmON/VcLZD 6dVEXfAO54R/wMnNADp1HGbk5d3KdPHU/ubdVjMU4Ycx2CFtXZ/k+muAzQbX9ksw20Py sozec91xXZiJX+rYd9xAXhXBV/93jo+QkFPA67JUZDxRCzQG5J+Y3ElOnCg3dg51++mP mXHgUjvsVmlf9O9AbfCDkCiyJeKWvmQtgasLsdfuAEXguwRAUNPnFTqnJEDW7WqrhRsz TaXOoSLI8WrNw4nmb5fjV/FnC1tfPYsnyroKL5OY1VxmlvFiTDBs6DaL/mu+E3Gx6SRo 2fDA== 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=JIetkDNF0hUxNCUbjxONnVA4FM9jR3eRc2gITJ2P7KjBNL/wm6uSxj0y27hKcuxtQh 2ML8sOqy5JJ2RXy7yxoysRjwPsSjItg5fJOQ13e53VjlB0LHZozpX9E9Y8MxBT9c1V0p fkER+r04OOTIZ0rY5OFSeFBe2kKpdjlyp0DGCipe5JLU+MgNlaL9PXAOZBZVgDvo3mpK e5UjlGKQUvMtUBSDzJZVgxHHV6KEg+GXYFUwDAW48dg4w+u+VlLm8xc13W4HhXkJljtE dTP9u82nf0uaLVTJLttrPRN1lgwL97vLb1vEKvyNSXqI0s+DpJcnPHS5dB3OWqSK9zlX 8qLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uaLES6g5; 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 a24si15600389iol.81.2021.08.02.21.35.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 02 Aug 2021 21:35:54 -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=uaLES6g5; 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]:44062 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mAm9h-0000X1-L2 for patch@linaro.org; Tue, 03 Aug 2021 00:35:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57532) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mAlt5-0005YD-FV for qemu-devel@nongnu.org; Tue, 03 Aug 2021 00:18:43 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]:42797) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mAlt2-0005Eh-Uf for qemu-devel@nongnu.org; Tue, 03 Aug 2021 00:18:43 -0400 Received: by mail-pl1-x632.google.com with SMTP id t3so20049094plg.9 for ; Mon, 02 Aug 2021 21:18:40 -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=uaLES6g5HOysHgzE5iXrqj9z7/HswoB9aGJdJ5g/rGBriGRdcSqVrRhqGTMFDCorJB EOXD32pIuWrPLJg97vwgzyziZG0adoWvzNkpc5SJi3f2J9CoXdLuKwcZ5Af1rUps22/N 9Hh8rjx8nQs938JHSUwrZLxzn4dsCTKI3WdjZSvEXe1PNpIc/IVi7GSVtJ3JoZxTxv+A zLzyBJuMNMpHrJNFxSaPYsb5P+VLNtRhpBBZNfEqU7SkNtrFUJGBvTiE+1h8rv/XTdmi YpShGLfudmIV4lSk+J9qnQzArfVmP8wCt6ulUuvmIR2KOENCOGVEwy79mhF1EllkZgQb yd7Q== 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=in3uI2H6w4tfegN9x6qH3+sN3tm44ex6ixl9Wg9I6AMculVjVwNv1//JC7xf1mvKmo fmI0Hmz675IQp6ji1hbVF3nmbMUoCX13nz+12EcNYh2cp7Wkv4ArCFoFhz7QwN+RHK7L xMkS0WER1AhHsWsJsmH68Hf/hjcveOV9hzs+gsTYSZIqqMKOMbQXLM3NwygwBc3efpMB MM/THCNWgYLx1Y9mt6NbCPfHd3iTLmScuH+n2NNEDm/iQti3sdKH2lBv/IZyG9dBheOc FVuKCoZ6GokO3QKcEYiev5y+gDmwIS4ZRwOGIGGNO0GsUri2m2DiLdBntJ5wX90v5FLH aDRg== X-Gm-Message-State: AOAM531iTgxCbIatlIzaRcwIzT6v61SJ/jiatbzybsPkp8c5/dl5VSND 8r6VChNeDZOHqbp89ZAsCqYAj9I21C4g9w== X-Received: by 2002:a63:6e83:: with SMTP id j125mr290260pgc.12.1627964319258; Mon, 02 Aug 2021 21:18:39 -0700 (PDT) Received: from localhost.localdomain (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id ns18sm12091020pjb.31.2021.08.02.21.18.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Aug 2021 21:18:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 44/55] tests/tcg/multiarch: Add sigbus.c Date: Mon, 2 Aug 2021 18:14:32 -1000 Message-Id: <20210803041443.55452-45-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210803041443.55452-1-richard.henderson@linaro.org> References: <20210803041443.55452-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.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; +}