From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw1-x112e.google.com (mail-yw1-x112e.google.com [IPv6:2607:f8b0:4864:20::112e]) by sourceware.org (Postfix) with ESMTPS id 11C523858C50 for ; Sat, 16 Mar 2024 22:06:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 11C523858C50 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 11C523858C50 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710626781; cv=none; b=a/CRDvjKdIJYmXgJ2IuVPKQsP1U9kmhV6dAZApw5vAg7e4zts0uTDhbIbiHTB+yOQ956tz59g7SldG0GKPbI1fehgpOFRPU83sx1/z2JFYXM17fu5pCXgC0JrWAF41z8lkbG1dCMjn1MDTxkBK4Vvma98jomKpIqKXL77zygppU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710626781; c=relaxed/simple; bh=6+uubEZXKV4ra9LPurWX2IkZTkADSL9LDlSUVi+tR2I=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=fpNiKyjCqz7mPXY1RxmQTunYBj6PZQtGCGS2KSSFtCabRmqlqDW8dINeV3f8OfiW4BijjLpHjFHldkNK+qRZAY8eNYrN3QAzyHhDwkyC9tFJ+ZMUPfzt5SY0nQn8I7+9iQozyXRNhuvjXw2+Qo4fMtJkZW6gFEkUctaCPos7tMo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-60a046c5262so30927417b3.2 for ; Sat, 16 Mar 2024 15:06:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710626778; x=1711231578; darn=sourceware.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=hMS38L9NG//q/npJX/b1crMTgTDTKEjDMsyWj9RLBYg=; b=F+PRP/Rr1ma4UigasxBM/B7WxncglProtsX6PwpfanWq+Nt2PjVJAh4RsIRlXF1Pj+ KPzPjFYJ4goTu5EEPMSG/mQZYzj6r242s0c0o4Q0Q5qrVXaRHRpEobvfDUfZVSBzURy+ dMmpbv+DcjVBEw4OFK1x1LLpgWaw0+NquD+bBYMN52UCgonELP+P85ao/9x908aFc86c K8IsCsBMuJQHWVIL2c0GIzOgG9NJpwoVYlN19fVHuYv7+TK6yfKJzbtEmPMPhOQAn3xs 7ns8cFErY8O+cRqfK15Lbzzp1m6byzMoUJSPnNaFI/aXWwwYH9SXGDhXBuBoyLM6T971 6xMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710626778; x=1711231578; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hMS38L9NG//q/npJX/b1crMTgTDTKEjDMsyWj9RLBYg=; b=xEM9A3vPf1/pJ+fKQMBIpR9ggVUGKzD3aNnpdyZklV2GZu4EQFG2njjt7OJPpzz5kA FsI3I2oHFe9Xg5b+JcEmcoecKLBppefVj5IomGlaOBD4Za5IW8fP+kwz0nG/te3mkEfS diP+wgjPffbcQn5l7INOPAfp34OHGTOigWEI8p/9HclCtwoeMMTvrYqXmnpdjcyZFuGc Va+wgSIBlsZbukhPYAe9wLG4moy2xgbSA8aHxgJHh+K1lyWhB7ea1qZRA/GkRwy8vn1Y A3CF7bwKuoLNj/S6I65mk5WUELuaIvZDnqYhizCkhNKl/ovqBuJJ3evjUkbblnvC0mCQ /ayw== X-Gm-Message-State: AOJu0YzkoRf1TAIBfS2wQwbkoFUU9ivIIxpiqz2oox5jfYJPzUTCB8Je SzJouH8yQs0QnA6cy9cyTiORHPBzFB3FaI+PJb1XBEvkw90t22qeInUj8dMmp9c2vuVGNsb/0jK IHiqurznBi5Hu1iE/1nuubEBYGhI= X-Google-Smtp-Source: AGHT+IERzLg1yR2t4RaXeoWEJaEjAJswazXVEm4gl//aE54hqddd1mFt3GMUigpMLHR6CxBji1cFUz/RrgMXUtRFVdc= X-Received: by 2002:a81:9111:0:b0:60a:1587:cf18 with SMTP id i17-20020a819111000000b0060a1587cf18mr8154239ywg.42.1710626778097; Sat, 16 Mar 2024 15:06:18 -0700 (PDT) MIME-Version: 1.0 References: <878r2ifdrx.fsf@oldenburg.str.redhat.com> <87y1aidxq6.fsf@oldenburg.str.redhat.com> <87h6h6dqem.fsf@oldenburg.str.redhat.com> In-Reply-To: From: "H.J. Lu" Date: Sat, 16 Mar 2024 15:05:41 -0700 Message-ID: Subject: Re: [PATCH] x86-64: Stack alignment in _dl_tlsdesc_dynamic and red zone usage (bug 31501) To: Florian Weimer Cc: libc-alpha@sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3019.9 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,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Sat, Mar 16, 2024 at 10:51=E2=80=AFAM H.J. Lu wrot= e: > > On Sat, Mar 16, 2024 at 10:42=E2=80=AFAM Florian Weimer wrote: > > > > * H. J. Lu: > > > > > Please verify if this is the right testcase. > > > > Test case works (fails without my fix, succeeds with my fix). Some > > comments below. > > > > > diff --git a/sysdeps/x86_64/tst-gnu2-tls2-x86-64-mod0.S b/sysdeps/x86= _64/tst-gnu2-tls2-x86-64-mod0.S > > > new file mode 100644 > > > index 0000000000..8129b28061 > > > --- /dev/null > > > +++ b/sysdeps/x86_64/tst-gnu2-tls2-x86-64-mod0.S > > > @@ -0,0 +1,57 @@ > > > > > + .text > > > + .p2align 4 > > > + .globl apply_tls > > > + .type apply_tls, @function > > > +apply_tls: > > > + .cfi_startproc > > > > Missing CET marker. > > > > > + subq $24, %rsp > > > + .cfi_def_cfa_offset 32 > > > + movdqu (%rdi), %xmm0 > > > + movq %fs:40, %rax > > > + movq %rax, 8(%rsp) > > > + xorl %eax, %eax > > > + leaq tls_var0@TLSDESC(%rip), %rax > > > + call *tls_var0@TLSCALL(%rax) > > > + addq %fs:0, %rax > > > + movups %xmm0, (%rax) > > > + movdqu 16(%rdi), %xmm1 > > > + movups %xmm1, 16(%rax) > > > + movq 8(%rsp), %rdx > > > + subq %fs:40, %rdx > > > + jne .L5 > > > + addq $24, %rsp > > > + .cfi_remember_state > > > + .cfi_def_cfa_offset 8 > > > + ret > > > +.L5: > > > + .cfi_restore_state > > > + call __stack_chk_fail@PLT > > > > Not sure if we need this? > > > > Maybe add some comment what exactly this subtest is exercising? > > > > These are present in the other TLS modules as well. > > > > > diff --git a/sysdeps/x86_64/tst-gnu2-tls2-x86-64-mod1.S b/sysdeps/x86= _64/tst-gnu2-tls2-x86-64-mod1.S > > > new file mode 100644 > > > index 0000000000..af4b7ca761 > > > --- /dev/null > > > +++ b/sysdeps/x86_64/tst-gnu2-tls2-x86-64-mod1.S > > > > > +/* Select an offset which will cause _dl_tlsdesc_dynamic_xsavec to > > > + clobber %rbx. */ > > > +#define OFFSET (56 + 16 + 16 + 16) > > > + > > > + .text > > > + .p2align 4 > > > + .globl apply_tls > > > + .type apply_tls, @function > > > +apply_tls: > > > + .cfi_startproc > > > + pushq %rbp > > > + .cfi_def_cfa_offset 16 > > > + .cfi_offset 6, -16 > > > + movq %rsp, %rbp > > > + .cfi_def_cfa_register 6 > > > + /* Align stack to 64 bytes. */ > > > + andq $-64, %rsp > > > + pushq %rbx > > > + subq $OFFSET, %rsp > > > > The offset could be loaded from a global variable or something like > > that. We should exercise a wide range of stack alignments=E2=80=94the > > individual tests are cheap. And maybe check extra registers. > > I will clean it up with a different fix. > I submitted a patch with a testase: https://patchwork.sourceware.org/project/glibc/list/?series=3D31963 My patch allocates 64 more bytes to avoid clobbering saved RDI, RSI and RBX values on stack by xsave. It avoids 2 stack adjustments. Either my fix or Florian's fix should fix the issue. I don't have a strong preference as long as my testcase is included. Thanks. --=20 H.J.