public inbox for [email protected]
 help / color / mirror / Atom feed
From: Ammar Faizi <[email protected]>
To: Jens Axboe <[email protected]>
Cc: Ammar Faizi <[email protected]>,
	Alviro Iskandar Setiawan <[email protected]>,
	Fernanda Ma'rouf <[email protected]>,
	Hao Xu <[email protected]>,
	Pavel Begunkov <[email protected]>,
	io-uring Mailing List <[email protected]>,
	GNU/Weeb Mailing List <[email protected]>
Subject: [PATCH liburing v3 05/10] arch/aarch64: lib: Add `get_page_size()` function
Date: Tue,  5 Jul 2022 00:54:31 +0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

From: Ammar Faizi <[email protected]>

A prep patch to add aarch64 nolibc support.

aarch64 supports three values of page size: 4K, 16K, and 64K which are
selected at kernel compilation time. Therefore, we can't hard code the
page size for this arch. Utilize open(), read() and close() syscall to
find the page size from /proc/self/auxv. For more details about the
auxv data structure, check the link below [1].

v3:
  - Split open/read/close in get_page_size() into a new function.
  - Cache the fallback value when we fail on the syscalls.
  - No need to init the static var to zero.

v2:
  - Fallback to 4K if the syscall fails.
  - Cache the page size after read as suggested by Jens.

Link: https://github.com/torvalds/linux/blob/v5.19-rc4/fs/binfmt_elf.c#L260 [1]
Link: https://lore.kernel.org/io-uring/[email protected]
Link: https://lore.kernel.org/io-uring/[email protected]
Link: https://lore.kernel.org/io-uring/[email protected]
Suggested-by: Jens Axboe <[email protected]>
Signed-off-by: Ammar Faizi <[email protected]>
---
 src/arch/aarch64/lib.h | 51 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 src/arch/aarch64/lib.h

diff --git a/src/arch/aarch64/lib.h b/src/arch/aarch64/lib.h
new file mode 100644
index 0000000..eb7e4cb
--- /dev/null
+++ b/src/arch/aarch64/lib.h
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: MIT */
+
+#ifndef LIBURING_ARCH_AARCH64_LIB_H
+#define LIBURING_ARCH_AARCH64_LIB_H
+
+#include <elf.h>
+#include <sys/auxv.h>
+#include "../../syscall.h"
+
+static inline long __get_page_size(void)
+{
+	static const long fallback_ret = 4096;
+	Elf64_Off buf[2];
+	long ret;
+	int fd;
+
+	fd = __sys_open("/proc/self/auxv", O_RDONLY, 0);
+	if (fd < 0)
+		return fallback_ret;
+
+	while (1) {
+		ssize_t x;
+
+		x = __sys_read(fd, buf, sizeof(buf));
+		if (x < sizeof(buf)) {
+			ret = fallback_ret;
+			break;
+		}
+
+		if (buf[0] == AT_PAGESZ) {
+			ret = buf[1];
+			break;
+		}
+	}
+
+	__sys_close(fd);
+	return ret;
+}
+
+static inline long get_page_size(void)
+{
+	static long cache_val;
+
+	if (cache_val)
+		return cache_val;
+
+	cache_val = __get_page_size();
+	return cache_val;
+}
+
+#endif /* #ifndef LIBURING_ARCH_AARCH64_LIB_H */
-- 
Ammar Faizi


  parent reply	other threads:[~2022-07-04 17:55 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-04 17:54 [PATCH liburing v3 00/10] aarch64 support Ammar Faizi
2022-07-04 17:54 ` [PATCH liburing v3 01/10] CHANGELOG: Fixup missing space Ammar Faizi
2022-07-04 17:54 ` [PATCH liburing v3 02/10] arch: syscall: Add `__sys_open()` syscall Ammar Faizi
2022-07-04 18:07   ` Alviro Iskandar Setiawan
2022-07-04 17:54 ` [PATCH liburing v3 03/10] arch: syscall: Add `__sys_read()` syscall Ammar Faizi
2022-07-04 18:12   ` Alviro Iskandar Setiawan
2022-07-04 18:16     ` Ammar Faizi
2022-07-04 17:54 ` [PATCH liburing v3 04/10] arch: Remove `__INTERNAL__LIBURING_LIB_H` checks Ammar Faizi
2022-07-04 17:54 ` Ammar Faizi [this message]
2022-07-04 18:18   ` [PATCH liburing v3 05/10] arch/aarch64: lib: Add `get_page_size()` function Alviro Iskandar Setiawan
2022-07-04 18:23     ` Ammar Faizi
2022-07-04 17:54 ` [PATCH liburing v3 06/10] lib: Style fixup for #if / #elif / #else / #endif Ammar Faizi
2022-07-04 17:54 ` [PATCH liburing v3 07/10] lib: Enable nolibc support for aarch64 Ammar Faizi
2022-07-04 17:54 ` [PATCH liburing v3 08/10] test: Add nolibc test Ammar Faizi
2022-07-04 17:54 ` [PATCH liburing v3 09/10] .github: Enable aarch64 nolibc build for GitHub bot Ammar Faizi
2022-07-04 17:54 ` [PATCH liburing v3 10/10] CHANGELOG: Note about aarch64 support Ammar Faizi

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 \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /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