qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: gaosong <gaosong@loongson.cn>
To: qemu-devel@nongnu.org
Cc: richard.henderson@linaro.org, philmd@redhat.com,
	maobibo@loongson.cn, laurent@vivier.eu, deller@gmx.de,
	"Alex Bennée" <alex.bennee@linaro.org>
Subject: Re: [PATCH v1 0/6] linux-user/loongarch64: Add LSX/LASX sigcontext
Date: Mon, 23 Oct 2023 10:47:07 +0800	[thread overview]
Message-ID: <701f6866-0e52-e4f9-89b7-201a2feed321@loongson.cn> (raw)
In-Reply-To: <20231010033701.385725-1-gaosong@loongson.cn>

Ping !

在 2023/10/10 上午11:36, Song Gao 写道:
> Hi, All.
>
> This series adds save/restore sigcontext.
>
> We use extctx_flags to choces which sigcontext need save/restore.
>
> The extctx_flags default value is EXTCTX_FLAGS_FPU, we need
> save/restore fpu context.
>
> After a LSX/LASX instruction is execed, extctx_flags value change to
> EXTCTX_FLAGS_LSX/LASX, we always need save/restore lsx/lasx context.
>
>
> The test_signal.c is a simple test.
>
> The default vreg len is 64. After execed a LSX instruction, the vreg len is
> 128, and then we exec a FPU instruction, the vreg len is also 128. After
> execed a LASX instruction, the vreg len is 256, and then we exec a FPU
> instruction, the vreg len is also 256.
>
> test_signal.c:
>
> #include <unistd.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <errno.h>
> #include <signal.h>
> #include <asm/ucontext.h>
> #include <setjmp.h>
> #include <stdint.h>
> #include <string.h>
>
> static sigjmp_buf jmpbuf;
>
> struct _ctx_layout {
>          struct sctx_info *addr;
>          unsigned int size;
> };
>
> struct extctx_layout {
>          unsigned long size;
>          unsigned int flags;
>          struct _ctx_layout fpu;
>          struct _ctx_layout lsx;
>          struct _ctx_layout lasx;
>          struct _ctx_layout end;
> };
> static int parse_extcontext(struct sigcontext *sc, struct extctx_layout *extctx)
> {
>      uint32_t magic, size;
>      struct sctx_info *info = (struct sctx_info *)&sc->sc_extcontext;
>
>      while(1) {
>          magic = (uint32_t)info->magic;
>          size =  (uint32_t)info->size;
>
>          printf("magic is %lx\n", magic);
>          printf("size is %lx\n", size);
>          switch (magic) {
>          case 0: /* END*/
>              return 0;
>          case FPU_CTX_MAGIC:
>              if (size < (sizeof(struct sctx_info) +
>                          sizeof(struct fpu_context))) {
>                  return -1;
>              }
>              extctx->fpu.addr = info;
>              break;
>          case LSX_CTX_MAGIC:
>              if (size < (sizeof(struct sctx_info) +
>                          sizeof(struct lsx_context))) {
>                  return -1;
>              }
>              extctx->lsx.addr = info;
>              break;
>          case LASX_CTX_MAGIC:
>              if (size < (sizeof(struct sctx_info) +
>                          sizeof(struct lasx_context))) {
>                  return -1;
>              }
>              extctx->lasx.addr = info;
>              break;
>          default:
>              return -1;
>          }
>          info = (struct sctx_info *)((char *)info +size);
>      }
>      return 0;
> }
>
> static int n = 0;
>
> static void do_signal(int sig, siginfo_t *info, void *ucontext)
> {
>      int i;
>      struct ucontext *uc = (struct ucontext *)ucontext;
>      struct extctx_layout extctx;
>
>      memset(&extctx, 0, sizeof(struct extctx_layout));
>
>      printf("pc        : %016lx\n", uc->uc_mcontext.sc_pc);
>
>      parse_extcontext(&uc->uc_mcontext, &extctx);
>
>      if (n < 5) {
>          printf("extctx.lasx.addr is %lx\n", extctx.lasx.addr);
>          printf("extctx.lsx.addr  is %lx\n", extctx.lsx.addr);
>          printf("extctx.fpu.addr  is %lx\n", extctx.fpu.addr);
>
>          if (extctx.lasx.addr) {
>              struct sctx_info *info = extctx.lasx.addr;
>              struct lasx_context *lasx_ctx = (struct lasx_context *)((char *)info +
>                                              sizeof(struct sctx_info));
>              printf("vl        : %016lx\n", 256);
>          } else if (extctx.lsx.addr) {
>              struct sctx_info *info = extctx.lsx.addr;
>              struct lsx_context *lsx_ctx = (struct lsx_context *)((char *)info +
>                                            sizeof(struct sctx_info));
>              printf("vl        : %016lx\n", 128);
>          } else if (extctx.fpu.addr) {
>              struct sctx_info *info = extctx.fpu.addr;
>              struct fpu_context *fpu_ctx = (struct fpu_context *)((char *)info +
>                                            sizeof(struct sctx_info));
>              printf("vl        : %016lx\n", 64);
>          }
>      }
>      n++;
>
>      printf("n is -------------- %d\n", n);
>      if (n == 1) {
>          // vaddwev.w.hu    $vr27, $vr22, $vr29
>          asm volatile(".word 0x702ef6db");
>          printf("After execed LSX instructons  vaddwev.w.hu\n");
>      }
>
>      if (n == 2) {
>          // 0101395e        fadd.d          $fs6, $ft2, $ft6
>          asm volatile(".word 0x0101395e");
>          printf("After execed FPU instructions fadd\n");
>      }
>
>      if (n == 3) {
>          // xvextrins.d     $xr13, $xr15, 0x59
>          asm volatile(".word 0x778165ed");
>          printf("After execed LASX instructions xvextrins.d\n");
>      }
>
>      if (n == 4) {
>          // 0101395e        fadd.d          $fs6, $ft2, $ft6
>          asm volatile(".word 0x0101395e");
>          printf("After execed FPU instructions fadd\n");
>      }
>
>      if (n == 5) {
>          exit(0);
>      }
>
>      siglongjmp(jmpbuf, 1);
> }
>
> static int setup_signal(int sig, void (*fn) (int, siginfo_t *, void *))
> {
>      struct sigaction my_act;
>      int ret;
>
>      my_act.sa_sigaction = fn;
>      my_act.sa_flags = SA_SIGINFO;
>      sigemptyset(&my_act.sa_mask);
>
>      ret = sigaction(sig, &my_act, NULL);
>      if (ret != 0) {
>          printf("FAIL: signal %d\n", sig);
>          return SIG_ERR;
>      }
> }
>
> int main()
> {
>      setup_signal(SIGSEGV, do_signal);
>
>      sigsetjmp(jmpbuf, 1);
>
>      int result = 0;
>      void *addr = 0x00012;
>      result = *(int *)addr;
>
>      return 0;
> }
>
>
> On 3A5000 machine:
>
> [root@archlinux LASX]# ./test_signal
> pc        : 0000000120000b44
> magic is 46505501
> size is 120
> magic is 0
> size is 0
> extctx.lasx.addr is 0
> extctx.lsx.addr  is 0
> extctx.fpu.addr  is 7ffffbdd2120
> vl        : 0000000000000040
> n is -------------- 1
> After execed LSX instructons  vaddwev.w.hu
> pc        : 0000000120000b44
> magic is 53580001
> size is 220
> magic is 0
> size is 0
> extctx.lasx.addr is 0
> extctx.lsx.addr  is 7ffffbdd2020
> extctx.fpu.addr  is 0
> vl        : 0000000000000080
> n is -------------- 2
> After execed FPU instructions fadd
> pc        : 0000000120000b44
> magic is 53580001
> size is 220
> magic is 0
> size is 0
> extctx.lasx.addr is 0
> extctx.lsx.addr  is 7ffffbdd2020
> extctx.fpu.addr  is 0
> vl        : 0000000000000080
> n is -------------- 3
> After execed LASX instructions xvextrins.d
> pc        : 0000000120000b44
> magic is 41535801
> size is 430
> magic is 0
> size is 0
> extctx.lasx.addr is 7ffffbdd1e10
> extctx.lsx.addr  is 0
> extctx.fpu.addr  is 0
> vl        : 0000000000000100
> n is -------------- 4
> After execed FPU instructions fadd
> pc        : 0000000120000b44
> magic is 41535801
> size is 430
> magic is 0
> size is 0
> extctx.lasx.addr is 7ffffbdd1e10
> extctx.lsx.addr  is 0
> extctx.fpu.addr  is 0
> vl        : 0000000000000100
> n is -------------- 5
>
> QEMU user-mode on X86:
>
> root@loongson-KVM:~/work/code/qemu# ./build/qemu-loongarch64 test_signal
> pc        : 0000000120000b44
> magic is 46505501
> size is 120
> magic is 0
> size is 0
> extctx.lasx.addr is 0
> extctx.lsx.addr  is 0
> extctx.fpu.addr  is 7fd92279f110
> vl        : 0000000000000040
> n is -------------- 1
> After exec LSX instructons  vaddwev.w.hu
> pc        : 0000000120000b44
> magic is 53580001
> size is 220
> magic is 0
> size is 0
> extctx.lasx.addr is 0
> extctx.lsx.addr  is 7fd92279f010
> extctx.fpu.addr  is 0
> vl        : 0000000000000080
> n is -------------- 2
> After execed FPU instructions fadd
> pc        : 0000000120000b44
> magic is 53580001
> size is 220
> magic is 0
> size is 0
> extctx.lasx.addr is 0
> extctx.lsx.addr  is 7fd92279f010
> extctx.fpu.addr  is 0
> vl        : 0000000000000080
> n is -------------- 3
> After execed LASX instructions xvextrins.d
> pc        : 0000000120000b44
> magic is 41535801
> size is 430
> magic is 0
> size is 0
> extctx.lasx.addr is 7fd92279ee00
> extctx.lsx.addr  is 0
> extctx.fpu.addr  is 0
> vl        : 0000000000000100
> n is -------------- 4
> After execed FPU instructions fadd
> pc        : 0000000120000b44
> magic is 41535801
> size is 430
> magic is 0
> size is 0
> extctx.lasx.addr is 7fd92279ee00
> extctx.lsx.addr  is 0
> extctx.fpu.addr  is 0
> vl        : 0000000000000100
> n is -------------- 5
>
>
> Please review, thanks.
>
> Song Gao (6):
>    target/loongarch: Add env->extctx_flags for user-mode setup extcontext
>    target/loongarch: Add set_vec_extctx to set LSX/LASX instructions
>      extctx_flags
>    linux-user/loongarch64: Fix setup_extcontext alloc wrong fpu_context
>      size
>    linux-user/loongarch64: setup_sigframe() set 'end' context size 0
>    linux-user/loongarch64: Add LSX sigcontext save/restore
>    linux-user/loongarch64: Add LASX sigcontext save/restore
>
>   linux-user/loongarch64/signal.c             | 168 +++++++++++++++++---
>   target/loongarch/cpu.c                      |   2 +
>   target/loongarch/cpu.h                      |   2 +
>   target/loongarch/insn_trans/trans_vec.c.inc |  12 ++
>   target/loongarch/internals.h                |   4 +
>   target/loongarch/translate.c                |   3 +
>   target/loongarch/translate.h                |   1 +
>   7 files changed, 170 insertions(+), 22 deletions(-)
>



      parent reply	other threads:[~2023-10-23  2:47 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-10  3:36 [PATCH v1 0/6] linux-user/loongarch64: Add LSX/LASX sigcontext Song Gao
2023-10-10  3:36 ` [PATCH v1 1/6] target/loongarch: Add env->extctx_flags for user-mode setup extcontext Song Gao
2023-10-10  3:36 ` [PATCH v1 2/6] target/loongarch: Add set_vec_extctx to set LSX/LASX instructions extctx_flags Song Gao
2023-10-28 21:40   ` Richard Henderson
2023-10-30  3:28     ` gaosong
2023-10-30 15:30       ` Richard Henderson
2023-10-31  6:16         ` gaosong
2023-10-31 14:50           ` Richard Henderson
2023-11-01  1:49             ` gaosong
2023-10-10  3:36 ` [PATCH v1 3/6] linux-user/loongarch64: Fix setup_extcontext alloc wrong fpu_context size Song Gao
2023-10-28 21:18   ` Richard Henderson
2023-10-10  3:36 ` [PATCH v1 4/6] linux-user/loongarch64: setup_sigframe() set 'end' context size 0 Song Gao
2023-10-28 21:20   ` Richard Henderson
2023-10-10  3:37 ` [PATCH v1 5/6] linux-user/loongarch64: Add LSX sigcontext save/restore Song Gao
2023-10-28 21:35   ` Richard Henderson
2023-10-30  3:28     ` gaosong
2023-10-10  3:37 ` [PATCH v1 6/6] linux-user/loongarch64: Add LASX " Song Gao
2023-10-23  2:47 ` gaosong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=701f6866-0e52-e4f9-89b7-201a2feed321@loongson.cn \
    --to=gaosong@loongson.cn \
    --cc=alex.bennee@linaro.org \
    --cc=deller@gmx.de \
    --cc=laurent@vivier.eu \
    --cc=maobibo@loongson.cn \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).