From patchwork Thu Dec 10 21:20:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1414551 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=U2KN6yAL; dkim-atps=neutral Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CsRfX47fzz9sW1 for ; Fri, 11 Dec 2020 08:20:51 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 105C7385782C; Thu, 10 Dec 2020 21:20:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 105C7385782C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1607635248; bh=zYF0HyMgO7+JXQhoR0+avlQq4d7k95O8+fGjxg2mCgE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=U2KN6yALjvrPTVFH0gIwsIS3Hz1vCGmLlbpm29yjsB8KMOBYpQy9c4ebCp3UbBxY5 fe/uphUWy6wLt/z20y0S2Xh1z9VfapJaPNalpXMxGoaIQSt1I6LDPHQEbTizPb2uQd lRN1scAhFYrtgEyHZM0Io/06wfDOzZiL9uOkvIkc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id AA470385782C for ; Thu, 10 Dec 2020 21:20:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AA470385782C Received: by mail-pl1-x62e.google.com with SMTP id p6so3439865plr.7 for ; Thu, 10 Dec 2020 13:20:44 -0800 (PST) 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:mime-version :content-transfer-encoding; bh=zYF0HyMgO7+JXQhoR0+avlQq4d7k95O8+fGjxg2mCgE=; b=f965Zg7gz5oCdYJY8W5yEc7FBUX/uPez+dARHVnfoOQL8dCIBg+YfA3s/b+PMsXvqt VlvClHyww86lOC7AM1zOlaKNfmzGyybA68tjfWGa7jjdlCxpxBPLzwQUC2IgobcEp25U wA3fRfQuJ79LcxWLECr1kAu82AoIHuJviFS+jMX5mLOh+s+/SR4EB6zkXHUQhRIfayWq az4yMOPkqsIG6gQ/W2js7t4HVKKRoyCw+b56VVS2TRGVxdm+vNZtEHSB8ibaY6UsyUr1 w7c6zMrtKnmobM21zVam4Grz9rQusFSlgpfzJD1PqeELW5ELn2CFDX7DhTSZZ1dowvIF sduA== X-Gm-Message-State: AOAM5322YR4sRqrxJYSKTyxszHW2KLAE176Ve6jrC6MH+iLYaizEu96X GB99YMvAauBn2Rrd/SNQOQkBnEQB1I4= X-Google-Smtp-Source: ABdhPJx5641qPjEbW5iQO6Sc40GzfouYjIuDz3r5RG7r5SDjLOukgz01whpNzMeVlKqkde7oOF3wgQ== X-Received: by 2002:a17:902:694c:b029:da:afba:beab with SMTP id k12-20020a170902694cb02900daafbabeabmr8177069plt.32.1607635243245; Thu, 10 Dec 2020 13:20:43 -0800 (PST) Received: from gnu-cfl-2.localdomain (c-69-181-90-243.hsd1.ca.comcast.net. [69.181.90.243]) by smtp.gmail.com with ESMTPSA id w63sm7277043pfc.20.2020.12.10.13.20.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Dec 2020 13:20:42 -0800 (PST) Received: from gnu-cfl-2.localdomain (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 88A3C1A016E; Thu, 10 Dec 2020 13:20:41 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] x86: Update user interrupt handler stack frame Date: Thu, 10 Dec 2020 13:20:39 -0800 Message-Id: <20201210212039.2618674-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-Spam-Status: No, score=-3040.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Gcc-patches" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: Uros Bizjak Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" User interrupt handler stack frame is similar to exception interrupt handler stack frame. Instead of error code, the second argument is user interrupt request register vector. gcc/ PR target/98219 * config/i386/uintrintrin.h (__uintr_frame): Remove uirrv. gcc/testsuite/ PR target/98219 * gcc.dg/guality/pr98219-1.c: New test. * gcc.dg/guality/pr98219-2.c: Likewise. * gcc.dg/torture/pr98219-1.c: Likewise. * gcc.dg/torture/pr98219-2.c: Likewise. * gcc.target/i386/uintr-2.c: Scan "add[lq] $8, %[er]sp". (foo): Add an unsigned long long argument. (UINTR_hanlder): Likewise. * gcc.target/i386/uintr-3.c: Scan "add[lq] $8, %[er]sp". (UINTR_hanlder): Add an unsigned long long argument. * gcc.target/i386/uintr-4.c (UINTR_hanlder): Likewise. * gcc.target/i386/uintr-5.c (UINTR_hanlder): Likewise. --- gcc/config/i386/uintrintrin.h | 3 -- gcc/testsuite/gcc.dg/guality/pr98219-1.c | 48 ++++++++++++++++++ gcc/testsuite/gcc.dg/guality/pr98219-2.c | 63 ++++++++++++++++++++++++ gcc/testsuite/gcc.dg/torture/pr98219-1.c | 44 +++++++++++++++++ gcc/testsuite/gcc.dg/torture/pr98219-2.c | 59 ++++++++++++++++++++++ gcc/testsuite/gcc.target/i386/uintr-2.c | 5 +- gcc/testsuite/gcc.target/i386/uintr-3.c | 4 +- gcc/testsuite/gcc.target/i386/uintr-4.c | 4 +- gcc/testsuite/gcc.target/i386/uintr-5.c | 2 +- 9 files changed, 223 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/guality/pr98219-1.c create mode 100644 gcc/testsuite/gcc.dg/guality/pr98219-2.c create mode 100644 gcc/testsuite/gcc.dg/torture/pr98219-1.c create mode 100644 gcc/testsuite/gcc.dg/torture/pr98219-2.c diff --git a/gcc/config/i386/uintrintrin.h b/gcc/config/i386/uintrintrin.h index 991f6427971..4606caf8582 100644 --- a/gcc/config/i386/uintrintrin.h +++ b/gcc/config/i386/uintrintrin.h @@ -38,9 +38,6 @@ struct __uintr_frame { - /* The position of the most significant bit set in user-interrupt - request register. */ - unsigned long long uirrv; /* RIP of the interrupted user process. */ unsigned long long rip; /* RFLAGS of the interrupted user process. */ diff --git a/gcc/testsuite/gcc.dg/guality/pr98219-1.c b/gcc/testsuite/gcc.dg/guality/pr98219-1.c new file mode 100644 index 00000000000..8d695080fd8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/guality/pr98219-1.c @@ -0,0 +1,48 @@ +/* { dg-do run { target { { i?86-*-* x86_64-*-* } && { ! { ia32 } } } } } */ +/* { dg-options "-g -muintr -mgeneral-regs-only" } */ + +#include + +extern void exit (int); + +#define UIRRV 0x12345670 +#define RIP 0x12345671 +#define RFLAGS 0x12345672 +#define RSP 0x12345673 + +#define STRING(x) XSTRING(x) +#define XSTRING(x) #x +#define ASMNAME(cname) ASMNAME2 (__USER_LABEL_PREFIX__, cname) +#define ASMNAME2(prefix, cname) XSTRING (prefix) cname + +__attribute__((interrupt, used)) +void +fn (struct __uintr_frame *frame, unsigned long long uirrv) +{ + if (UIRRV != uirrv) /* BREAK */ + __builtin_abort (); + if (RIP != frame->rip) + __builtin_abort (); + if (RFLAGS != frame->rflags) + __builtin_abort (); + if (RSP != frame->rsp) + __builtin_abort (); + + exit (0); +} + +int +main () +{ + asm ("push $" STRING (RSP) "; \ + push $" STRING (RFLAGS) "; \ + push $" STRING (RIP) "; \ + push $" STRING (UIRRV) "; \ + jmp " ASMNAME ("fn")); + return 0; +} + +/* { dg-final { gdb-test 22 "uirrv" "0x12345670" } } */ +/* { dg-final { gdb-test 22 "frame->rip" "0x12345671" } } */ +/* { dg-final { gdb-test 22 "frame->rflags" "0x12345672" } } */ +/* { dg-final { gdb-test 22 "frame->rsp" "0x12345673" } } */ diff --git a/gcc/testsuite/gcc.dg/guality/pr98219-2.c b/gcc/testsuite/gcc.dg/guality/pr98219-2.c new file mode 100644 index 00000000000..c0e48c981de --- /dev/null +++ b/gcc/testsuite/gcc.dg/guality/pr98219-2.c @@ -0,0 +1,63 @@ +/* { dg-do run { target { { i?86-*-* x86_64-*-* } && { ! { ia32 } } } } } */ +/* { dg-options "-g -muintr -mgeneral-regs-only" } */ + +#include + +extern void exit (int); +typedef int aligned __attribute__((aligned(64))); + +#define UIRRV 0x12345670 +#define RIP 0x12345671 +#define RFLAGS 0x12345672 +#define RSP 0x12345673 + +#define STRING(x) XSTRING(x) +#define XSTRING(x) #x +#define ASMNAME(cname) ASMNAME2 (__USER_LABEL_PREFIX__, cname) +#define ASMNAME2(prefix, cname) XSTRING (prefix) cname + +int +check_int (int *i, int align) +{ + *i = 20; + if ((((ptrdiff_t) i) & (align - 1)) != 0) + __builtin_abort (); + return *i; +} + +__attribute__((interrupt, used)) +__attribute__((interrupt, used)) +void +fn (struct __uintr_frame *frame, unsigned long long uirrv) +{ + aligned i; + if (check_int (&i, __alignof__(i)) != i) + __builtin_abort (); + + if (UIRRV != uirrv) /* BREAK */ + __builtin_abort (); + if (RIP != frame->rip) + __builtin_abort (); + if (RFLAGS != frame->rflags) + __builtin_abort (); + if (RSP != frame->rsp) + __builtin_abort (); + + exit (0); +} + +int +main () +{ + asm ("push $" STRING (RSP) "; \ + push $" STRING (RFLAGS) "; \ + push $" STRING (RIP) "; \ + push $" STRING (UIRRV) "; \ + jmp " ASMNAME ("fn")); + return 0; +} + +/* { dg-final { gdb-test 34 "uirrv" "0x12345670" } } */ +/* { dg-final { gdb-test 34 "frame->rip" "0x12345671" } } */ +/* { dg-final { gdb-test 34 "frame->rflags" "0x12345672" } } */ +/* { dg-final { gdb-test 34 "frame->rsp" "0x12345673" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/pr98219-1.c b/gcc/testsuite/gcc.dg/torture/pr98219-1.c new file mode 100644 index 00000000000..c78495cc1c0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr98219-1.c @@ -0,0 +1,44 @@ +/* { dg-do run { target { { i?86-*-* x86_64-*-* } && { ! { ia32 } } } } } */ +/* { dg-skip-if "PR81210 sp not aligned to 16 bytes" { *-*-darwin* } } */ +/* { dg-options "-muintr -mgeneral-regs-only" } */ + +#include + +extern void exit (int); + +#define UIRRV 0x12345670 +#define RIP 0x12345671 +#define RFLAGS 0x12345672 +#define RSP 0x12345673 + +#define STRING(x) XSTRING(x) +#define XSTRING(x) #x +#define ASMNAME(cname) ASMNAME2 (__USER_LABEL_PREFIX__, cname) +#define ASMNAME2(prefix, cname) XSTRING (prefix) cname + +__attribute__((interrupt, used)) +void +fn (struct __uintr_frame *frame, unsigned long long uirrv) +{ + if (UIRRV != uirrv) + __builtin_abort (); + if (RIP != frame->rip) + __builtin_abort (); + if (RFLAGS != frame->rflags) + __builtin_abort (); + if (RSP != frame->rsp) + __builtin_abort (); + + exit (0); +} + +int +main () +{ + asm ("push $" STRING (RSP) "; \ + push $" STRING (RFLAGS) "; \ + push $" STRING (RIP) "; \ + push $" STRING (UIRRV) "; \ + jmp " ASMNAME ("fn")); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr98219-2.c b/gcc/testsuite/gcc.dg/torture/pr98219-2.c new file mode 100644 index 00000000000..176fb78e42e --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr98219-2.c @@ -0,0 +1,59 @@ +/* { dg-do run { target { { i?86-*-* x86_64-*-* } && { ! { ia32 } } } } } */ +/* { dg-skip-if "PR81210 sp not aligned to 16 bytes" { *-*-darwin* } } */ +/* { dg-options "-muintr -mgeneral-regs-only" } */ + +#include + +extern void exit (int); +typedef int aligned __attribute__((aligned(64))); + +#define UIRRV 0x12345670 +#define RIP 0x12345671 +#define RFLAGS 0x12345672 +#define RSP 0x12345673 + +#define STRING(x) XSTRING(x) +#define XSTRING(x) #x +#define ASMNAME(cname) ASMNAME2 (__USER_LABEL_PREFIX__, cname) +#define ASMNAME2(prefix, cname) XSTRING (prefix) cname + +int +check_int (int *i, int align) +{ + *i = 20; + if ((((ptrdiff_t) i) & (align - 1)) != 0) + __builtin_abort (); + return *i; +} + +__attribute__((interrupt, used)) +__attribute__((interrupt, used)) +void +fn (struct __uintr_frame *frame, unsigned long long uirrv) +{ + aligned i; + if (check_int (&i, __alignof__(i)) != i) + __builtin_abort (); + + if (UIRRV != uirrv) + __builtin_abort (); + if (RIP != frame->rip) + __builtin_abort (); + if (RFLAGS != frame->rflags) + __builtin_abort (); + if (RSP != frame->rsp) + __builtin_abort (); + + exit (0); +} + +int +main () +{ + asm ("push $" STRING (RSP) "; \ + push $" STRING (RFLAGS) "; \ + push $" STRING (RIP) "; \ + push $" STRING (UIRRV) "; \ + jmp " ASMNAME ("fn")); + return 0; +} diff --git a/gcc/testsuite/gcc.target/i386/uintr-2.c b/gcc/testsuite/gcc.target/i386/uintr-2.c index e705732c1bd..2ff32640827 100644 --- a/gcc/testsuite/gcc.target/i386/uintr-2.c +++ b/gcc/testsuite/gcc.target/i386/uintr-2.c @@ -1,17 +1,18 @@ /* { dg-do compile { target { ! ia32 } } } */ /* { dg-options "-O2 -muintr -mgeneral-regs-only" } */ /* { dg-final { scan-assembler-times "uiret" "2" } } */ +/* { dg-final { scan-assembler-times "add\[lq]\[ \t]\+\\\$8, %\[er\]sp" "2" } } */ #include void __attribute__((interrupt)) -foo (void *frame) +foo (void *frame, unsigned long long uirrv) { } void __attribute__((interrupt)) -UINTR_hanlder (struct __uintr_frame *frame) +UINTR_hanlder (struct __uintr_frame *frame, unsigned long long uirrv) { } diff --git a/gcc/testsuite/gcc.target/i386/uintr-3.c b/gcc/testsuite/gcc.target/i386/uintr-3.c index d2843495158..0b925066668 100644 --- a/gcc/testsuite/gcc.target/i386/uintr-3.c +++ b/gcc/testsuite/gcc.target/i386/uintr-3.c @@ -1,9 +1,11 @@ /* { dg-do compile { target { ! ia32 } } } */ /* { dg-options "-O2 -muintr" } */ /* { dg-final { scan-assembler "uiret" } } */ +/* { dg-final { scan-assembler "add\[lq]\[ \t]\+\\\$8, %\[er\]sp" } } */ + #include void __attribute__ ((target("general-regs-only"), interrupt)) -UINTR_handler (struct __uintr_frame *p) +UINTR_handler (struct __uintr_frame *p, unsigned long long uirrv) { } diff --git a/gcc/testsuite/gcc.target/i386/uintr-4.c b/gcc/testsuite/gcc.target/i386/uintr-4.c index f3b371b4231..60478b126a7 100644 --- a/gcc/testsuite/gcc.target/i386/uintr-4.c +++ b/gcc/testsuite/gcc.target/i386/uintr-4.c @@ -4,6 +4,6 @@ #include void __attribute__ ((interrupt)) -UINTR_handler (struct __uintr_frame *p) -{ /* { dg-message "SSE instructions aren't allowed in an interrupt service routine" } */ +UINTR_handler (struct __uintr_frame *p, unsigned long long uirrv) +{ /* { dg-message "SSE instructions aren't allowed in an exception service routine" } */ } diff --git a/gcc/testsuite/gcc.target/i386/uintr-5.c b/gcc/testsuite/gcc.target/i386/uintr-5.c index ac44be0a706..d49e54d3134 100644 --- a/gcc/testsuite/gcc.target/i386/uintr-5.c +++ b/gcc/testsuite/gcc.target/i386/uintr-5.c @@ -5,6 +5,6 @@ #include void -UINTR_hanlder (struct __uintr_frame *frame) +UINTR_hanlder (struct __uintr_frame *frame, unsigned long long uirrv) { }