diff mbox series

[liburing,v1,7/9] arch/arm64: Add `get_page_size()` function

Message ID 20220629002028.1232579-8-ammar.faizi@intel.com (mailing list archive)
State New
Headers show
Series aarch64 nolibc support | expand

Commit Message

Ammar Faizi June 29, 2022, 12:27 a.m. UTC
From: Ammar Faizi <ammarfaizi2@gnuweeb.org>

This is a preparation 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.

Link: https://github.com/torvalds/linux/blob/v5.19-rc4/fs/binfmt_elf.c#L260
Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
---
 src/arch/arm64/lib.h | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 src/arch/arm64/lib.h

Comments

Ammar Faizi June 29, 2022, 12:31 a.m. UTC | #1
On 6/29/22 7:27 AM, Ammar Faizi wrote:
> +	while (1) {
> +		ssize_t ret;
> +
> +		ret = __sys_read(fd, buf, sizeof(buf));
> +		if (ret < 0) {
> +			page_size = -errno;
> +			break;
> +		}

Oops, this is wrong, I shouldn't use errno here, it should be:
    
    page_size = ret;

Should I resend? Or you can fix it?
Jens Axboe June 29, 2022, 2:49 p.m. UTC | #2
On 6/28/22 6:27 PM, Ammar Faizi wrote:
> From: Ammar Faizi <ammarfaizi2@gnuweeb.org>
> 
> This is a preparation 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.

We should probably cache this value if already read? At least I don't
think we have systems where the page size would differ between
applications.
Ammar Faizi June 29, 2022, 2:52 p.m. UTC | #3
On 6/29/22 9:49 PM, Jens Axboe wrote:
> On 6/28/22 6:27 PM, Ammar Faizi wrote:
>> From: Ammar Faizi <ammarfaizi2@gnuweeb.org>
>>
>> This is a preparation 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.
> 
> We should probably cache this value if already read? At least I don't
> think we have systems where the page size would differ between
> applications.

Good idea, will use a static variable to cache it in v2 then...
diff mbox series

Patch

diff --git a/src/arch/arm64/lib.h b/src/arch/arm64/lib.h
new file mode 100644
index 0000000..4dc39a8
--- /dev/null
+++ b/src/arch/arm64/lib.h
@@ -0,0 +1,44 @@ 
+/* SPDX-License-Identifier: MIT */
+
+#ifndef LIBURING_ARCH_ARM64_LIB_H
+#define LIBURING_ARCH_ARM64_LIB_H
+
+#include <elf.h>
+#include <sys/auxv.h>
+#include "../../syscall.h"
+
+static inline long get_page_size(void)
+{
+	Elf64_Off buf[2];
+	long page_size;
+	int fd;
+
+	fd = __sys_open("/proc/self/auxv", O_RDONLY, 0);
+	if (fd < 0)
+		return fd;
+
+	while (1) {
+		ssize_t ret;
+
+		ret = __sys_read(fd, buf, sizeof(buf));
+		if (ret < 0) {
+			page_size = -errno;
+			break;
+		}
+
+		if (ret < sizeof(buf)) {
+			page_size = -ENOENT;
+			break;
+		}
+
+		if (buf[0] == AT_PAGESZ) {
+			page_size = buf[1];
+			break;
+		}
+	}
+
+	__sys_close(fd);
+	return page_size;
+}
+
+#endif /* #ifndef LIBURING_ARCH_ARM64_LIB_H */