public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Evan Green <evan@rivosinc.com>
To: libc-alpha@sourceware.org
Cc: Florian Weimer <fweimer@redhat.com>,
	palmer@rivosinc.com, vineetg@rivosinc.com, slewis@rivosinc.com,
	Evan Green <evan@rivosinc.com>
Subject: [PATCH v9 3/6] riscv: Add __riscv_hwprobe pointer to ifunc calls
Date: Thu, 30 Nov 2023 10:32:36 -0800	[thread overview]
Message-ID: <20231130183239.598100-4-evan@rivosinc.com> (raw)
In-Reply-To: <20231130183239.598100-1-evan@rivosinc.com>

The new __riscv_hwprobe() function is designed to be used by ifunc
selector functions. This presents a challenge for applications and
libraries, as ifunc selectors are invoked before all relocations have
been performed, so an external call to __riscv_hwprobe() from an ifunc
selector won't work. To address this, pass a pointer to the
__riscv_hwprobe() vDSO function into ifunc selectors as the second
argument (alongside dl_hwcap, which was already being passed).

Include a typedef as well for convenience, so that ifunc users don't
have to go through contortions to call this routine. Users will need to
remember to check the second argument for NULL, both to account for
older glibcs that don't pass the function, and older kernels that don't
have the vDSO pointer.

Signed-off-by: Evan Green <evan@rivosinc.com>

---

(no changes since v7)

Changes in v7:
 - Remove __THROW from function pointer type, as it creates warnings
   together with __fortified_attr_access.

 sysdeps/riscv/dl-irel.h                     |  8 ++++----
 sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h | 10 ++++++++++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/sysdeps/riscv/dl-irel.h b/sysdeps/riscv/dl-irel.h
index eaeec5467c..2147504458 100644
--- a/sysdeps/riscv/dl-irel.h
+++ b/sysdeps/riscv/dl-irel.h
@@ -31,10 +31,10 @@ static inline ElfW(Addr)
 __attribute ((always_inline))
 elf_ifunc_invoke (ElfW(Addr) addr)
 {
-  /* The second argument is a void pointer to preserve the extension
-     fexibility.  */
-  return ((ElfW(Addr) (*) (uint64_t, void *)) (addr))
-	 (GLRO(dl_hwcap), NULL);
+  /* The third argument is a void pointer to preserve the extension
+     flexibility.  */
+  return ((ElfW(Addr) (*) (uint64_t, void *, void *)) (addr))
+	 (GLRO(dl_hwcap), GLRO(dl_vdso_riscv_hwprobe), NULL);
 }
 
 static inline void
diff --git a/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h b/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h
index aa189a4818..fd3be5a411 100644
--- a/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h
+++ b/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h
@@ -67,6 +67,16 @@ extern int __riscv_hwprobe (struct riscv_hwprobe *__pairs, size_t __pair_count,
      __fortified_attr_access (__read_write__, 1, 2)
      __fortified_attr_access (__read_only__, 4, 3);
 
+/* A pointer to the __riscv_hwprobe vDSO function is passed as the second
+   argument to ifunc selector routines. Include a function pointer type for
+   convenience in calling the function in those settings. */
+typedef int (*__riscv_hwprobe_t) (struct riscv_hwprobe *__pairs, size_t __pair_count,
+				  size_t __cpu_count, unsigned long int *__cpus,
+				  unsigned int __flags)
+     __nonnull ((1)) __wur
+     __fortified_attr_access (__read_write__, 1, 2)
+     __fortified_attr_access (__read_only__, 4, 3);
+
 __END_DECLS
 
 #endif /* sys/hwprobe.h */
-- 
2.34.1


  parent reply	other threads:[~2023-11-30 18:32 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-30 18:32 [PATCH v9 0/6] RISC-V: ifunced memcpy using new kernel hwprobe interface Evan Green
2023-11-30 18:32 ` [PATCH v9 1/6] riscv: Add Linux hwprobe syscall support Evan Green
2023-12-06 17:22   ` Adhemerval Zanella Netto
2023-12-06 17:24     ` Adhemerval Zanella Netto
2023-11-30 18:32 ` [PATCH v9 2/6] riscv: Add hwprobe vdso call support Evan Green
2023-12-06 17:34   ` Adhemerval Zanella Netto
2023-12-11 21:02     ` Evan Green
2023-11-30 18:32 ` Evan Green [this message]
2023-12-06  0:31   ` [PATCH v9 3/6] riscv: Add __riscv_hwprobe pointer to ifunc calls enh
2023-11-30 18:32 ` [PATCH v9 4/6] riscv: Enable multi-arg ifunc resolvers Evan Green
2023-11-30 18:32 ` [PATCH v9 5/6] riscv: Add ifunc helper method to hwprobe.h Evan Green
2023-12-06 17:39   ` Adhemerval Zanella Netto
2023-12-06 18:17   ` enh
2023-12-06 19:42     ` Palmer Dabbelt
2023-12-07  9:46     ` Florian Weimer
2023-12-07 16:32       ` enh
2023-12-07 16:47         ` Florian Weimer
2023-12-07 17:09           ` enh
2023-11-30 18:32 ` [PATCH v9 6/6] riscv: Add and use alignment-ignorant memcpy Evan Green
2023-12-06 17:07 ` [PATCH v9 0/6] RISC-V: ifunced memcpy using new kernel hwprobe interface Palmer Dabbelt

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=20231130183239.598100-4-evan@rivosinc.com \
    --to=evan@rivosinc.com \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=palmer@rivosinc.com \
    --cc=slewis@rivosinc.com \
    --cc=vineetg@rivosinc.com \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).