From minios-devel-bounces@lists.xenproject.org Wed Jul 01 11:26:28 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 01 Jul 2020 11:26:28 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jqasj-0000SU-PF; Wed, 01 Jul 2020 11:26:25 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=mN/Q=AM=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jqasi-0000SE-LJ
 for minios-devel@lists.xenproject.org; Wed, 01 Jul 2020 11:26:24 +0000
X-Inumbo-ID: b04f5d9b-bb8d-11ea-86f3-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id b04f5d9b-bb8d-11ea-86f3-12813bfff9fa;
 Wed, 01 Jul 2020 11:26:23 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id D692DF2003;
 Wed,  1 Jul 2020 13:26:21 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 8wglNfmPaMes; Wed,  1 Jul 2020 13:26:21 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id AA87BF2002
 for <minios-devel@lists.xenproject.org>; Wed,  1 Jul 2020 13:26:19 +0200 (CEST)
Received: from N-1237.office.hd (192.168.24.96) by titania.office.hd
 (192.168.24.89) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 1 Jul 2020
 13:26:19 +0200
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: <minios-devel@lists.xenproject.org>
Subject: [UNIKRAFT/LIBTINYALLOC PATCH] Initial port of tinyalloc
Date: Wed, 1 Jul 2020 13:26:09 +0200
Message-ID: <cover.1593602546.git.hugo.lefeuvre@neclab.eu>
X-Mailer: git-send-email 2.7.4
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi,

this is the initial port of the tinyalloc [0] general-purpose memory
allocator as an external library. This patch requires the ifmalloc
compatibility interface [1].

regards,
Hugo

[0] https://github.com/thi-ng/tinyalloc
[1] https://patchwork.unikraft.org/project/unikraft/list/?series=1435

Hugo Lefeuvre (1):
  Initial port of tinyalloc to Unikraft



From minios-devel-bounces@lists.xenproject.org Wed Jul 01 11:26:30 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 01 Jul 2020 11:26:30 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jqaso-0000Sw-Qq; Wed, 01 Jul 2020 11:26:30 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=mN/Q=AM=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jqasn-0000SE-EE
 for minios-devel@lists.xenproject.org; Wed, 01 Jul 2020 11:26:29 +0000
X-Inumbo-ID: b22dc5de-bb8d-11ea-86f3-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id b22dc5de-bb8d-11ea-86f3-12813bfff9fa;
 Wed, 01 Jul 2020 11:26:24 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id E9BF2F2004;
 Wed,  1 Jul 2020 13:26:23 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 4n6oDmaxCrgZ; Wed,  1 Jul 2020 13:26:23 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id B34AAF2002
 for <minios-devel@lists.xenproject.org>; Wed,  1 Jul 2020 13:26:21 +0200 (CEST)
Received: from N-1237.office.hd (192.168.24.96) by titania.office.hd
 (192.168.24.89) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 1 Jul 2020
 13:26:20 +0200
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: <minios-devel@lists.xenproject.org>
Subject: [UNIKRAFT/LIBTINYALLOC PATCH] Initial port of tinyalloc to Unikraft
Date: Wed, 1 Jul 2020 13:26:10 +0200
Message-ID: <41d946015ecaa34e0f93ebc433506d95fb7f9469.1593602546.git.hugo.lefeuvre@neclab.eu>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <cover.1593602546.git.hugo.lefeuvre@neclab.eu>
References: <cover.1593602546.git.hugo.lefeuvre@neclab.eu>
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
---
 Config.uk                                          |  32 +++
 Makefile.uk                                        |  73 +++++
 glue.c                                             | 101 +++++++
 include/uk/tinyalloc.h                             |  48 ++++
 main-tree.patch                                    |  45 +++
 .../0001-do-not-store-heap-info-statically.patch   | 312 +++++++++++++++++++++
 6 files changed, 611 insertions(+)
 create mode 100644 Config.uk
 create mode 100644 Makefile.uk
 create mode 100644 glue.c
 create mode 100644 include/uk/tinyalloc.h
 create mode 100644 main-tree.patch
 create mode 100644 patches/0001-do-not-store-heap-info-statically.patch

diff --git a/Config.uk b/Config.uk
new file mode 100644
index 0000000..4b9d127
--- /dev/null
+++ b/Config.uk
@@ -0,0 +1,32 @@
+menuconfig LIBTINYALLOC
+	   bool "tinyalloc - sequential fit, linked list based tiny allocator"
+	   default y
+
+if LIBTINYALLOC
+	config LIBTINYALLOC_DISABLE_SPLIT
+		bool "Disable block splitting"
+		default n
+		help
+			If splitting is enabled, split blocks according to split
+			threshold.
+
+	config LIBTINYALLOC_DISABLE_COMPACT
+		bool "Disable block compaction"
+		default n
+		help
+			If compaction is enabled, sort blocks into the free
+			list, merge if appropriate. Otherwise blocks are just
+			added as new head of the free list.
+
+	config LIBTINYALLOC_HEAP_BLOCKS
+		int "Number of available heap blocks"
+		default 2048
+
+	config LIBTINYALLOC_SPLIT_THRESH
+		int "Split threshold, in bytes"
+		default 16
+
+	config LIBTINYALLOC_ALIGNMENT
+		int "Standard allocation alignment, in bytes"
+		default 8
+endif
diff --git a/Makefile.uk b/Makefile.uk
new file mode 100644
index 0000000..21aa8fe
--- /dev/null
+++ b/Makefile.uk
@@ -0,0 +1,73 @@
+#  libtinyalloc Makefile.uc
+#
+#  Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+#
+#  Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+#
+#  Redistribution and use in source and binary forms, with or without
+#  modification, are permitted provided that the following conditions
+#  are met:
+#
+#  1. Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+#  2. Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in the
+#     documentation and/or other materials provided with the distribution.
+#  3. Neither the name of the copyright holder nor the names of its
+#     contributors may be used to endorse or promote products derived from
+#     this software without specific prior written permission.
+#
+#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+#  POSSIBILITY OF SUCH DAMAGE.
+
+################################################################################
+# Library registration
+################################################################################
+$(eval $(call addlib_s,libtinyalloc,$(CONFIG_LIBTINYALLOC)))
+
+################################################################################
+# Sources
+################################################################################
+LIBTINYALLOC_VERSION=96450f32d80fe7d23f6aa5426046143e57801bc4
+LIBTINYALLOC_URL=https://github.com/thi-ng/tinyalloc/archive/$(LIBTINYALLOC_VERSION).zip
+LIBTINYALLOC_DIR=tinyalloc-$(LIBTINYALLOC_VERSION)
+
+LIBTINYALLOC_PATCHDIR=$(LIBTINYALLOC_BASE)/patches
+$(eval $(call fetch,libtinyalloc,$(LIBTINYALLOC_URL),$(LIBTINYALLOC_VERSION).zip))
+$(eval $(call patch,libtinyalloc,$(LIBTINYALLOC_PATCHDIR),$(LIBTINYALLOC_DIR)))
+
+################################################################################
+# Helpers
+################################################################################
+LIBTINYALLOC=$(LIBTINYALLOC_ORIGIN)/$(LIBTINYALLOC_DIR)
+
+################################################################################
+# Library includes
+################################################################################
+CINCLUDES-$(CONFIG_LIBTINYALLOC) += -I$(LIBTINYALLOC_BASE)     \
+                                    -I$(LIBTINYALLOC_BASE)/include \
+			            -I$(LIBTINYALLOC)
+
+################################################################################
+# Global flags
+################################################################################
+#LIBTINYALLOC_CFLAGS-y += -D_POSIX_SOURCE -D_GNU_SOURCE -D__GNU__
+
+################################################################################
+# Glue code
+################################################################################
+LIBTINYALLOC_SRCS-y += $(LIBTINYALLOC_BASE)/glue.c
+
+################################################################################
+# Sources
+################################################################################
+LIBTINYALLOC_SRCS-y += $(LIBTINYALLOC)/tinyalloc.c
diff --git a/glue.c b/glue.c
new file mode 100644
index 0000000..9266e92
--- /dev/null
+++ b/glue.c
@@ -0,0 +1,101 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <uk/tinyalloc.h>
+#include <uk/alloc_impl.h>
+#include <string.h> /* for memset */
+#include <tinyalloc.h>
+
+static void *uk_tinyalloc_malloc(struct uk_alloc *a, size_t size)
+{
+	struct tinyalloc *b;
+
+	b = (struct tinyalloc *)&a->priv;
+	return ta_alloc(b, size);
+}
+
+static void uk_tinyalloc_free(struct uk_alloc *a, void *ptr)
+{
+	struct tinyalloc *b;
+
+	b = (struct tinyalloc *)&a->priv;
+	ta_free(b, ptr);
+}
+
+/* initialization */
+
+struct uk_alloc *uk_tinyalloc_init(void *base, size_t len)
+{
+	struct uk_alloc *a;
+	struct tinyalloc *b;
+	size_t metalen;
+
+	/* TODO: This port does not support multiple memory regions yet. Because
+	 * of the multiboot layout, the first region might be a single page, so
+	 * we simply ignore it.
+	 */
+	if (len <= __PAGE_SIZE)
+		return NULL;
+
+	/* Allocate space for allocator descriptor */
+	metalen = sizeof(*a) + sizeof(*b);
+
+	/* enough space for allocator available? */
+	if (metalen > len) {
+		uk_pr_err("Not enough space for allocator: %"__PRIsz
+			  " B required but only %"__PRIuptr" B usable\n",
+			  metalen, len);
+		return NULL;
+	}
+
+	/* store allocator metadata on the heap, just before the memory pool */
+	a = (struct uk_alloc *)base;
+	b = (struct tinyalloc *)&a->priv;
+	memset(a, 0, metalen);
+
+	uk_pr_info("Initialize tinyalloc allocator @ 0x%" __PRIuptr ", len %"
+			__PRIsz"\n", (uintptr_t)a, len);
+
+	ta_init(b, base + metalen, base + len, CONFIG_LIBTINYALLOC_HEAP_BLOCKS,
+		CONFIG_LIBTINYALLOC_SPLIT_THRESH,
+		CONFIG_LIBTINYALLOC_ALIGNMENT);
+
+	if (!a) {
+		uk_pr_err("Failed to allocate memory for uk_alloc structure!\n");
+		return NULL;
+	}
+
+	uk_alloc_init_malloc_ifmalloc(a, uk_tinyalloc_malloc,
+					 uk_tinyalloc_free, NULL);
+
+	return a;
+}
diff --git a/include/uk/tinyalloc.h b/include/uk/tinyalloc.h
new file mode 100644
index 0000000..87290ed
--- /dev/null
+++ b/include/uk/tinyalloc.h
@@ -0,0 +1,48 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __LIBTINYALLOC_H__
+#define __LIBTINYALLOC_H__
+
+#include <uk/alloc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct uk_alloc *uk_tinyalloc_init(void *base, size_t len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LIBTINYALLOC_H__ */
diff --git a/main-tree.patch b/main-tree.patch
new file mode 100644
index 0000000..40bb096
--- /dev/null
+++ b/main-tree.patch
@@ -0,0 +1,45 @@
+From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+Subject: Add tinyalloc entry to the menuconfig and initialize it
+diff --git a/lib/ukboot/Config.uk b/lib/ukboot/Config.uk
+index a888bc1c..694762fa 100644
+--- a/lib/ukboot/Config.uk
++++ b/lib/ukboot/Config.uk
+@@ -32,6 +32,16 @@ if LIBUKBOOT
+ 		  Satisfy allocation as fast as possible. No support for free().
+ 		  Refer to help in ukallocregion for more information.
+ 
++		config LIBUKBOOT_INITTINYALLOC
++		bool "tinyalloc"
++		select LIBTINYALLOC
++		help
++		  Minimalist allocator implementation, meant for use in systems
++		  with unmanaged linear memory such as WebAssembly or embedded
++		  systems. tinyalloc is highly configurable and offers high
++		  performance and reasonable memory usage when used and
++		  configured appropriately.
++
+ 		config LIBUKBOOT_NOALLOC
+ 		bool "No memory allocator"
+ 
+diff --git a/lib/ukboot/boot.c b/lib/ukboot/boot.c
+index 4e749aa5..b8bf0a20 100644
+--- a/lib/ukboot/boot.c
++++ b/lib/ukboot/boot.c
+@@ -45,6 +45,8 @@
+ #include <uk/allocbbuddy.h>
+ #elif CONFIG_LIBUKBOOT_INITREGION
+ #include <uk/allocregion.h>
++#elif CONFIG_LIBUKBOOT_INITTINYALLOC
++#include <uk/tinyalloc.h>
+ #endif
+ #if CONFIG_LIBUKSCHED
+ #include <uk/sched.h>
+@@ -233,6 +235,8 @@ void ukplat_entry(int argc, char *argv[])
+ 			a = uk_allocbbuddy_init(md.base, md.len);
+ #elif CONFIG_LIBUKBOOT_INITREGION
+ 			a = uk_allocregion_init(md.base, md.len);
++#elif CONFIG_LIBUKBOOT_INITTINYALLOC
++			a = uk_tinyalloc_init(md.base, md.len);
+ #endif
+ 		} else {
+ 			uk_alloc_addmem(a, md.base, md.len);
diff --git a/patches/0001-do-not-store-heap-info-statically.patch b/patches/0001-do-not-store-heap-info-statically.patch
new file mode 100644
index 0000000..fd7b953
--- /dev/null
+++ b/patches/0001-do-not-store-heap-info-statically.patch
@@ -0,0 +1,312 @@
+From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+Subject: Adapt tinyalloc interface to Unikraft
+ - avoid statics: create a struct tinyalloc to store allocator metadata
+ - pass struct metadata as argument to allocation functions
+diff -urNp tinyalloc-orig/tinyalloc.c tinyalloc-patched/tinyalloc.c
+--- tinyalloc-orig/tinyalloc.c	2019-08-17 23:56:45.000000000 +0200
++++ tinyalloc-patched/tinyalloc.c	2020-06-30 10:34:24.945558078 +0200
+@@ -9,36 +9,16 @@ extern void print_i(size_t);
+ #define print_i(X)
+ #endif
+ 
+-typedef struct Block Block;
+-
+-struct Block {
+-    void *addr;
+-    Block *next;
+-    size_t size;
+-};
+-
+-typedef struct {
+-    Block *free;   // first free block
+-    Block *used;   // first used block
+-    Block *fresh;  // first available blank block
+-    size_t top;    // top free addr
+-    Block *blocks;
+-} Heap;
+-
+-static Heap *heap = NULL;
+-static void *heap_limit = NULL;
+-static size_t heap_split_thresh;
+-static size_t heap_alignment;
+-static size_t heap_max_blocks;
+-
+ /**
+  * If compaction is enabled, inserts block
+  * into free list, sorted by addr.
+  * If disabled, add block has new head of
+  * the free list.
+  */
+-static void insert_block(Block *block) {
+-#ifndef TA_DISABLE_COMPACT
++static void insert_block(struct tinyalloc *a, Block *block) {
++    Heap *heap = a->heap;
++
++#ifndef CONFIG_LIBTINYALLOC_DISABLE_COMPACT
+     Block *ptr  = heap->free;
+     Block *prev = NULL;
+     while (ptr != NULL) {
+@@ -66,8 +46,10 @@ static void insert_block(Block *block) {
+ #endif
+ }
+ 
+-#ifndef TA_DISABLE_COMPACT
+-static void release_blocks(Block *scan, Block *to) {
++#ifndef CONFIG_LIBTINYALLOC_DISABLE_COMPACT
++static void release_blocks(struct tinyalloc *a, Block *scan, Block *to) {
++    Heap *heap = a->heap;
++
+     Block *scan_next;
+     while (scan != to) {
+         print_s("release");
+@@ -81,7 +63,9 @@ static void release_blocks(Block *scan,
+     }
+ }
+ 
+-static void compact() {
++static void compact(struct tinyalloc *a) {
++    Heap *heap = a->heap;
++
+     Block *ptr = heap->free;
+     Block *prev;
+     Block *scan;
+@@ -103,7 +87,7 @@ static void compact() {
+             ptr->size   = new_size;
+             Block *next = prev->next;
+             // make merged blocks available
+-            release_blocks(ptr->next, prev->next);
++            release_blocks(a, ptr->next, prev->next);
+             // relink
+             ptr->next = next;
+         }
+@@ -112,30 +96,36 @@ static void compact() {
+ }
+ #endif
+ 
+-bool ta_init(const void *base, const void *limit, const size_t heap_blocks, const size_t split_thresh, const size_t alignment) {
+-    heap = (Heap *)base;
+-    heap_limit = limit;
+-    heap_split_thresh = split_thresh;
+-    heap_alignment = alignment;
+-    heap_max_blocks = heap_blocks;
++void ta_init(struct tinyalloc *a, const void *base, const void *limit,
++             const size_t heap_blocks, const size_t split_thresh,
++             const size_t alignment) {
++    Heap *heap;
++
++    a->heap = (Heap *)base;
++    a->heap_limit = limit;
++    a->heap_split_thresh = split_thresh;
++    a->heap_alignment = alignment;
++    a->heap_max_blocks = heap_blocks;
+ 
++    heap = a->heap;
+     heap->free   = NULL;
+     heap->used   = NULL;
++    heap->blocks = (Block*) ((size_t)base + sizeof(Heap));
+     heap->fresh  = heap->blocks;
+     heap->top    = (size_t)base + sizeof(Heap) + heap_blocks * sizeof(Block);
+-    heap->blocks = base + sizeof(Heap);
+ 
+     Block *block = heap->blocks;
+-    size_t i     = heap_max_blocks - 1;
++    size_t i     = a->heap_max_blocks - 1;
+     while (i--) {
+         block->next = block + 1;
+         block++;
+     }
+     block->next = NULL;
+-    return true;
+ }
+ 
+-bool ta_free(void *free) {
++void ta_free(struct tinyalloc *a, void *free) {
++    Heap *heap = a->heap;
++
+     Block *block = heap->used;
+     Block *prev  = NULL;
+     while (block != NULL) {
+@@ -145,25 +135,28 @@ bool ta_free(void *free) {
+             } else {
+                 heap->used = block->next;
+             }
+-            insert_block(block);
+-#ifndef TA_DISABLE_COMPACT
+-            compact();
++            insert_block(a, block);
++#ifndef CONFIG_LIBTINYALLOC_DISABLE_COMPACT
++            compact(a);
+ #endif
+-            return true;
++            return;
+         }
+         prev  = block;
+         block = block->next;
+     }
+-    return false;
++    return;
+ }
+ 
+-static Block *alloc_block(size_t num) {
++static Block *alloc_block(struct tinyalloc *a, size_t num) {
++    Heap *heap = a->heap;
++
+     Block *ptr  = heap->free;
+     Block *prev = NULL;
+     size_t top  = heap->top;
+-    num         = (num + heap_alignment - 1) & -heap_alignment;
++    num         = (num + a->heap_alignment - 1) & - a->heap_alignment;
+     while (ptr != NULL) {
+-        const int is_top = ((size_t)ptr->addr + ptr->size >= top) && ((size_t)ptr->addr + num <= heap_limit);
++        const int is_top = ((size_t)ptr->addr + ptr->size >= top)
++		        && ((size_t)ptr->addr + num <= a->heap_limit);
+         if (is_top || ptr->size >= num) {
+             if (prev != NULL) {
+                 prev->next = ptr->next;
+@@ -176,10 +169,10 @@ static Block *alloc_block(size_t num) {
+                 print_s("resize top block");
+                 ptr->size = num;
+                 heap->top = (size_t)ptr->addr + num;
+-#ifndef TA_DISABLE_SPLIT
++#ifndef CONFIG_LIBTINYALLOC_DISABLE_SPLIT
+             } else if (heap->fresh != NULL) {
+                 size_t excess = ptr->size - num;
+-                if (excess >= heap_split_thresh) {
++                if (excess >= a->heap_split_thresh) {
+                     ptr->size    = num;
+                     Block *split = heap->fresh;
+                     heap->fresh  = split->next;
+@@ -187,9 +180,9 @@ static Block *alloc_block(size_t num) {
+                     print_s("split");
+                     print_i((size_t)split->addr);
+                     split->size = excess;
+-                    insert_block(split);
+-#ifndef TA_DISABLE_COMPACT
+-                    compact();
++                    insert_block(a, split);
++#ifndef CONFIG_LIBTINYALLOC_DISABLE_COMPACT
++                    compact(a);
+ #endif
+                 }
+ #endif
+@@ -199,10 +192,11 @@ static Block *alloc_block(size_t num) {
+         prev = ptr;
+         ptr  = ptr->next;
+     }
++
+     // no matching free blocks
+     // see if any other blocks available
+     size_t new_top = top + num;
+-    if (heap->fresh != NULL && new_top <= heap_limit) {
++    if (heap->fresh != NULL && new_top <= (size_t)a->heap_limit) {
+         ptr         = heap->fresh;
+         heap->fresh = ptr->next;
+         ptr->addr   = (void *)top;
+@@ -212,11 +206,12 @@ static Block *alloc_block(size_t num) {
+         heap->top   = new_top;
+         return ptr;
+     }
++
+     return NULL;
+ }
+ 
+-void *ta_alloc(size_t num) {
+-    Block *block = alloc_block(num);
++void *ta_alloc(struct tinyalloc *a, size_t num) {
++    Block *block = alloc_block(a, num);
+     if (block != NULL) {
+         return block->addr;
+     }
+@@ -236,9 +231,9 @@ static void memclear(void *ptr, size_t n
+     }
+ }
+ 
+-void *ta_calloc(size_t num, size_t size) {
++void *ta_calloc(struct tinyalloc *a, size_t num, size_t size) {
+     num *= size;
+-    Block *block = alloc_block(num);
++    Block *block = alloc_block(a, num);
+     if (block != NULL) {
+         memclear(block->addr, num);
+         return block->addr;
+@@ -255,18 +250,21 @@ static size_t count_blocks(Block *ptr) {
+     return num;
+ }
+ 
+-size_t ta_num_free() {
++size_t ta_num_free(struct tinyalloc *a) {
++    Heap *heap = a->heap;
+     return count_blocks(heap->free);
+ }
+ 
+-size_t ta_num_used() {
++size_t ta_num_used(struct tinyalloc *a) {
++    Heap *heap = a->heap;
+     return count_blocks(heap->used);
+ }
+ 
+-size_t ta_num_fresh() {
++size_t ta_num_fresh(struct tinyalloc *a) {
++    Heap *heap = a->heap;
+     return count_blocks(heap->fresh);
+ }
+ 
+-bool ta_check() {
+-    return heap_max_blocks == ta_num_free() + ta_num_used() + ta_num_fresh();
++bool ta_check(struct tinyalloc *a) {
++    return a->heap_max_blocks == ta_num_free(a) + ta_num_used(a) + ta_num_fresh(a);
+ }
+diff -urNp tinyalloc-orig/tinyalloc.h tinyalloc-patched/tinyalloc.h
+--- tinyalloc-orig/tinyalloc.h	2019-08-17 23:56:45.000000000 +0200
++++ tinyalloc-patched/tinyalloc.h	2020-06-30 10:38:59.734724059 +0200
+@@ -1,12 +1,41 @@
+ #include <stdbool.h>
+ #include <stddef.h>
+ 
+-bool ta_init(const void *base, const void *limit, const size_t heap_blocks, const size_t split_thresh, const size_t alignment);
+-void *ta_alloc(size_t num);
+-void *ta_calloc(size_t num, size_t size);
+-bool ta_free(void *ptr);
+-
+-size_t ta_num_free();
+-size_t ta_num_used();
+-size_t ta_num_fresh();
+-bool ta_check();
++typedef struct Block Block;
++
++struct Block {
++    void *addr;
++    Block *next;
++    size_t size;
++};
++
++typedef struct {
++    Block *free;   // first free block
++    Block *used;   // first used block
++    Block *fresh;  // first available blank block
++    size_t top;    // top free addr
++    Block *blocks;
++} Heap;
++
++struct tinyalloc {
++    Heap *heap;
++    void *heap_limit;
++    size_t heap_split_thresh;
++    size_t heap_alignment;
++    size_t heap_max_blocks;
++};
++
++void ta_init(struct tinyalloc *a, const void *base, const void *limit,
++             const size_t heap_blocks, const size_t split_thresh,
++             const size_t alignment);
++
++void *ta_alloc(struct tinyalloc *a, size_t num);
++void *ta_calloc(struct tinyalloc *a, size_t num, size_t size);
++void  ta_free(struct tinyalloc *a, void *ptr);
++int   ta_posix_memalign(struct tinyalloc *a, void **memptr, size_t align,
++			size_t size);
++
++size_t ta_num_free(struct tinyalloc *a);
++size_t ta_num_used(struct tinyalloc *a);
++size_t ta_num_fresh(struct tinyalloc *a);
++bool   ta_check(struct tinyalloc *a);
-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Wed Jul 01 11:38:11 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 01 Jul 2020 11:38:11 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jqb45-0001Sg-3p; Wed, 01 Jul 2020 11:38:09 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=mN/Q=AM=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jqb43-0001SY-R1
 for minios-devel@lists.xenproject.org; Wed, 01 Jul 2020 11:38:07 +0000
X-Inumbo-ID: 541d9abc-bb8f-11ea-bb8b-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 541d9abc-bb8f-11ea-bb8b-bc764e2007e4;
 Wed, 01 Jul 2020 11:38:06 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 15A8EF2003;
 Wed,  1 Jul 2020 13:38:05 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id ioFb-Q5h0u2W; Wed,  1 Jul 2020 13:38:04 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id E2A56F2002
 for <minios-devel@lists.xenproject.org>; Wed,  1 Jul 2020 13:38:02 +0200 (CEST)
Received: from N-1237.office.hd (192.168.24.96) by titania.office.hd
 (192.168.24.89) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 1 Jul 2020
 13:38:02 +0200
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: <minios-devel@lists.xenproject.org>
Subject: [UNIKRAFT/LIBTLSF PATCH v2] Initial port of libtlsf
Date: Wed, 1 Jul 2020 13:37:55 +0200
Message-ID: <cover.1593603111.git.hugo.lefeuvre@neclab.eu>
X-Mailer: git-send-email 2.7.4
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi,

this is the initial port of the TLSF [0] general-purpose memory allocator
for Unikraft as an external library.

Changed since v1:
 - add missing Signed-off line
 - fix errors/warnings reported by checkpatch
 - rename compile guards in include/uk/tlsf.h

regards,
Hugo

[0] http://www.gii.upv.es/tlsf/

Hugo Lefeuvre (1):
  Initial port of TLSF to Unikraft



From minios-devel-bounces@lists.xenproject.org Wed Jul 01 11:38:14 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 01 Jul 2020 11:38:14 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jqb4A-0001TR-6L; Wed, 01 Jul 2020 11:38:14 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=mN/Q=AM=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jqb48-0001SY-Pe
 for minios-devel@lists.xenproject.org; Wed, 01 Jul 2020 11:38:12 +0000
X-Inumbo-ID: 55593440-bb8f-11ea-bca7-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 55593440-bb8f-11ea-bca7-bc764e2007e4;
 Wed, 01 Jul 2020 11:38:08 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 39294F2004;
 Wed,  1 Jul 2020 13:38:07 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id v7StAqLdjjBB; Wed,  1 Jul 2020 13:38:07 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id EBAA3F2002
 for <minios-devel@lists.xenproject.org>; Wed,  1 Jul 2020 13:38:04 +0200 (CEST)
Received: from N-1237.office.hd (192.168.24.96) by titania.office.hd
 (192.168.24.89) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 1 Jul 2020
 13:38:04 +0200
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: <minios-devel@lists.xenproject.org>
Subject: [UNIKRAFT/LIBTLSF PATCH v2] Initial port of TLSF to Unikraft
Date: Wed, 1 Jul 2020 13:37:56 +0200
Message-ID: <78be00dc6e5eebe282eee77f6373e81028a38c46.1593603394.git.hugo.lefeuvre@neclab.eu>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <cover.1593603394.git.hugo.lefeuvre@neclab.eu>
References: <cover.1593603394.git.hugo.lefeuvre@neclab.eu>
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
---
 Config.uk                                          |  20 +++
 Makefile.uk                                        |  77 ++++++++++
 README.md                                          |  12 ++
 glue.c                                             |  77 ++++++++++
 include/uk/tlsf.h                                  |  48 +++++++
 main-tree.patch                                    |  42 ++++++
 ...onfig-vars-and-parametrize-tlsf-interface.patch | 160 +++++++++++++++++++++
 7 files changed, 436 insertions(+)
 create mode 100644 Config.uk
 create mode 100644 Makefile.uk
 create mode 100644 README.md
 create mode 100644 glue.c
 create mode 100644 include/uk/tlsf.h
 create mode 100644 main-tree.patch
 create mode 100644 patches/config-vars-and-parametrize-tlsf-interface.patch

diff --git a/Config.uk b/Config.uk
new file mode 100644
index 0000000..29732d0
--- /dev/null
+++ b/Config.uk
@@ -0,0 +1,20 @@
+menuconfig LIBTLSF
+	   bool "TLSF - real-time dynamic memory allocator"
+	   select LIBUKALLOC_IFMALLOC
+	   default n
+
+if LIBTLSF
+	config TLSF_LOG2_SLI
+		int "log2 of second level index (SLI)"
+		default 5
+		help
+			The Second Level Index subdivides linearily the first level lists.
+
+			The SLI has to be a power of two and is here represented as log2
+			of the number of second level divisions.
+
+			For instance, TLSF_LOG2_SLI = 5 implies 32 second level divisions.
+
+			Higher values of SLI imply less fragmentation, at the cost of an
+			increased space overhead of metadata.
+endif
diff --git a/Makefile.uk b/Makefile.uk
new file mode 100644
index 0000000..373181e
--- /dev/null
+++ b/Makefile.uk
@@ -0,0 +1,77 @@
+#  libtlsf Makefile.uk
+#
+#  Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+#
+#
+#  Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+#
+#  Redistribution and use in source and binary forms, with or without
+#  modification, are permitted provided that the following conditions
+#  are met:
+#
+#  1. Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+#  2. Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in the
+#     documentation and/or other materials provided with the distribution.
+#  3. Neither the name of the copyright holder nor the names of its
+#     contributors may be used to endorse or promote products derived from
+#     this software without specific prior written permission.
+#
+#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+#  POSSIBILITY OF SUCH DAMAGE.
+
+################################################################################
+# Library registration
+################################################################################
+$(eval $(call addlib_s,libtlsf,$(CONFIG_LIBTLSF)))
+
+################################################################################
+# Sources
+################################################################################
+LIBTLSF_VERSION=2.4.6
+LIBTLSF_URL=http://wks.gii.upv.es/tlsf/files/src/TLSF-$(LIBTLSF_VERSION).tbz2
+LIBTLSF_DIR=TLSF-$(LIBTLSF_VERSION)
+
+LIBTLSF_PATCHDIR=$(LIBTLSF_BASE)/patches
+$(eval $(call fetch,libtlsf,$(LIBTLSF_URL),TLSF-$(LIBTLSF_VERSION).tbz2))
+$(eval $(call patch,libtlsf,$(LIBTLSF_PATCHDIR),$(LIBTLSF_DIR)))
+
+################################################################################
+# Helpers
+################################################################################
+LIBTLSF=$(LIBTLSF_ORIGIN)/$(LIBTLSF_DIR)
+
+################################################################################
+# Library includes
+################################################################################
+
+CINCLUDES-$(CONFIG_LIBTLSF) +=	-I$(LIBTLSF_BASE)		\
+				-I$(LIBTLSF_BASE)/include	\
+				-I$(LIBTLSF)/src
+
+################################################################################
+# Global flags
+################################################################################
+
+# no locks, no sbrk, no mmap
+CFLAGS-$(CONFIG_LIBTLSF) +=  -DTLSF_USE_LOCKS=0 -DUSE_MMAP=0 -DUSE_SBRK=0
+
+################################################################################
+# Glue code
+################################################################################
+LIBTLSF_SRCS-y += $(LIBTLSF_BASE)/glue.c
+
+################################################################################
+# Sources
+################################################################################
+LIBTLSF_SRCS-y += $(LIBTLSF)/src/tlsf.c
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..2e665a3
--- /dev/null
+++ b/README.md
@@ -0,0 +1,12 @@
+TLSF for Unikraft
+=================
+
+This is the port of the TLSF [0] general-purpose memory allocator for Unikraft
+as an external library.
+
+How to use this allocator in your unikernel application:
+
+- apply main-tree.patch to the main tree
+- select "TLSF" in `ukboot > Default memory allocator`
+
+[0] http://www.gii.upv.es/tlsf/
diff --git a/glue.c b/glue.c
new file mode 100644
index 0000000..8becfe9
--- /dev/null
+++ b/glue.c
@@ -0,0 +1,77 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <uk/tlsf.h>
+#include <uk/alloc_impl.h>
+#include <tlsf.h>
+
+/* malloc interface */
+
+static void *uk_tlsf_malloc(struct uk_alloc *a, size_t size)
+{
+	return tlsf_malloc(size, (void *)((uintptr_t) a +
+					sizeof(struct uk_alloc)));
+}
+
+static void uk_tlsf_free(struct uk_alloc *a, void *ptr)
+{
+	tlsf_free(ptr, (void *)((uintptr_t) a + sizeof(struct uk_alloc)));
+}
+
+/* initialization */
+
+struct uk_alloc *uk_tlsf_init(void *base, size_t len)
+{
+	struct uk_alloc *a;
+	size_t res;
+
+	/* enough space for allocator available? */
+	if (sizeof(*a) > len) {
+		uk_pr_err("Not enough space for allocator: %" __PRIsz
+			  " B required but only %" __PRIuptr" B usable\n",
+			  sizeof(*a), len);
+		return NULL;
+	}
+
+	/* store allocator metadata on the heap, just before the memory pool */
+	a = (struct uk_alloc *)base;
+	uk_pr_info("Initialize tlsf allocator @ 0x%" __PRIuptr ", len %"
+			__PRIsz"\n", (uintptr_t)a, len);
+
+	res = init_memory_pool(len - sizeof(*a), base + sizeof(*a));
+	if (res == (size_t)-1)
+		return NULL;
+
+	uk_alloc_init_malloc_ifmalloc(a, uk_tlsf_malloc, uk_tlsf_free, NULL);
+
+	return a;
+}
diff --git a/include/uk/tlsf.h b/include/uk/tlsf.h
new file mode 100644
index 0000000..3e3482a
--- /dev/null
+++ b/include/uk/tlsf.h
@@ -0,0 +1,48 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __LIBTLSF_H__
+#define __LIBTLSF_H__
+
+#include <uk/alloc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct uk_alloc *uk_tlsf_init(void *base, size_t len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LIBTLSF_H__ */
diff --git a/main-tree.patch b/main-tree.patch
new file mode 100644
index 0000000..ca66278
--- /dev/null
+++ b/main-tree.patch
@@ -0,0 +1,42 @@
+From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+Subject: Add TLSF entry to the menuconfig and initialize it
+diff --git a/lib/ukboot/Config.uk b/lib/ukboot/Config.uk
+index a888bc1c..b79b370e 100644
+--- a/lib/ukboot/Config.uk
++++ b/lib/ukboot/Config.uk
+@@ -32,6 +32,13 @@ if LIBUKBOOT
+ 		  Satisfy allocation as fast as possible. No support for free().
+ 		  Refer to help in ukallocregion for more information.
+ 
++		config LIBUKBOOT_INITTLSF
++		bool "TLSF"
++		select LIBTLSF
++		help
++		  Real-time allocator. Bounded fragmentation, allocation, and
++		  deallocation.
++
+ 		config LIBUKBOOT_NOALLOC
+ 		bool "No memory allocator"
+ 
+diff --git a/lib/ukboot/boot.c b/lib/ukboot/boot.c
+index 4e749aa5..37aafd70 100644
+--- a/lib/ukboot/boot.c
++++ b/lib/ukboot/boot.c
+@@ -45,6 +45,8 @@
+ #include <uk/allocbbuddy.h>
+ #elif CONFIG_LIBUKBOOT_INITREGION
+ #include <uk/allocregion.h>
++#elif CONFIG_LIBUKBOOT_INITTLSF
++#include <uk/tlsf.h>
+ #endif
+ #if CONFIG_LIBUKSCHED
+ #include <uk/sched.h>
+@@ -233,6 +235,8 @@ void ukplat_entry(int argc, char *argv[])
+ 			a = uk_allocbbuddy_init(md.base, md.len);
+ #elif CONFIG_LIBUKBOOT_INITREGION
+ 			a = uk_allocregion_init(md.base, md.len);
++#elif CONFIG_LIBUKBOOT_INITTLSF
++			a = uk_tlsf_init(md.base, md.len);
+ #endif
+ 		} else {
+ 			uk_alloc_addmem(a, md.base, md.len);
diff --git a/patches/config-vars-and-parametrize-tlsf-interface.patch b/patches/config-vars-and-parametrize-tlsf-interface.patch
new file mode 100644
index 0000000..e77cf56
--- /dev/null
+++ b/patches/config-vars-and-parametrize-tlsf-interface.patch
@@ -0,0 +1,160 @@
+From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+Subject: Adapt TLSF interface to Unikraft
+ - expose MAX_LOG2_SLI, users might want to modify this
+ - do not rely on static metadata; pass it as argument to the allocation
+   interface
+diff -urNp TLSF-2.4.6/src/tlsf.c TLSF-patched/src/tlsf.c
+--- TLSF-2.4.6/src/tlsf.c	2009-10-06 11:25:15.000000000 +0200
++++ TLSF-patched/src/tlsf.c	2020-06-26 13:49:03.231027270 +0200
+@@ -74,7 +74,6 @@
+ #define	USE_SBRK 	(0)
+ #endif
+ 
+-
+ #if TLSF_USE_LOCKS
+ #include "target.h"
+ #else
+@@ -129,7 +128,7 @@
+ #define BLOCK_ALIGN (sizeof(void *) * 2)
+ 
+ #define MAX_FLI		(30)
+-#define MAX_LOG2_SLI	(5)
++#define MAX_LOG2_SLI	CONFIG_TLSF_LOG2_SLI
+ #define MAX_SLI		(1 << MAX_LOG2_SLI)     /* MAX_SLI = 2^MAX_LOG2_SLI */
+ 
+ #define FLI_OFFSET	(6)     /* tlsf structure just will manage blocks bigger */
+@@ -451,8 +450,6 @@ static __inline__ bhdr_t *process_area(v
+ /******************** Begin of the allocator code *****************/
+ /******************************************************************/
+ 
+-static char *mp = NULL;         /* Default memory pool. */
+-
+ /******************************************************************/
+ size_t init_memory_pool(size_t mem_pool_size, void *mem_pool)
+ {
+@@ -472,13 +469,10 @@ size_t init_memory_pool(size_t mem_pool_
+     tlsf = (tlsf_t *) mem_pool;
+     /* Check if already initialised */
+     if (tlsf->tlsf_signature == TLSF_SIGNATURE) {
+-        mp = mem_pool;
+-        b = GET_NEXT_BLOCK(mp, ROUNDUP_SIZE(sizeof(tlsf_t)));
++        b = GET_NEXT_BLOCK(mem_pool, ROUNDUP_SIZE(sizeof(tlsf_t)));
+         return b->size & BLOCK_SIZE;
+     }
+ 
+-    mp = mem_pool;
+-
+     /* Zeroing the memory pool */
+     memset(mem_pool, 0, sizeof(tlsf_t));
+ 
+@@ -615,13 +609,13 @@ void destroy_memory_pool(void *mem_pool)
+ 
+ 
+ /******************************************************************/
+-void *tlsf_malloc(size_t size)
++void *tlsf_malloc(size_t size, void *mem_pool)
+ {
+ /******************************************************************/
+     void *ret;
+ 
+ #if USE_MMAP || USE_SBRK
+-    if (!mp) {
++    if (!mem_pool) {
+         size_t area_size;
+         void *area;
+ 
+@@ -634,60 +628,60 @@ void *tlsf_malloc(size_t size)
+     }
+ #endif
+ 
+-    TLSF_ACQUIRE_LOCK(&((tlsf_t *)mp)->lock);
++    TLSF_ACQUIRE_LOCK(&((tlsf_t *)mem_pool)->lock);
+ 
+-    ret = malloc_ex(size, mp);
++    ret = malloc_ex(size, mem_pool);
+ 
+-    TLSF_RELEASE_LOCK(&((tlsf_t *)mp)->lock);
++    TLSF_RELEASE_LOCK(&((tlsf_t *)mem_pool)->lock);
+ 
+     return ret;
+ }
+ 
+ /******************************************************************/
+-void tlsf_free(void *ptr)
++void tlsf_free(void *ptr, void *mem_pool)
+ {
+ /******************************************************************/
+ 
+-    TLSF_ACQUIRE_LOCK(&((tlsf_t *)mp)->lock);
++    TLSF_ACQUIRE_LOCK(&((tlsf_t *)mem_pool)->lock);
+ 
+-    free_ex(ptr, mp);
++    free_ex(ptr, mem_pool);
+ 
+-    TLSF_RELEASE_LOCK(&((tlsf_t *)mp)->lock);
++    TLSF_RELEASE_LOCK(&((tlsf_t *)mem_pool)->lock);
+ 
+ }
+ 
+ /******************************************************************/
+-void *tlsf_realloc(void *ptr, size_t size)
++void *tlsf_realloc(void *ptr, size_t size, void *mem_pool)
+ {
+ /******************************************************************/
+     void *ret;
+ 
+ #if USE_MMAP || USE_SBRK
+-	if (!mp) {
+-		return tlsf_malloc(size);
++	if (!mem_pool) {
++		return tlsf_malloc(size, mem_pool);
+ 	}
+ #endif
+ 
+-    TLSF_ACQUIRE_LOCK(&((tlsf_t *)mp)->lock);
++    TLSF_ACQUIRE_LOCK(&((tlsf_t *)mem_pool)->lock);
+ 
+-    ret = realloc_ex(ptr, size, mp);
++    ret = realloc_ex(ptr, size, mem_pool);
+ 
+-    TLSF_RELEASE_LOCK(&((tlsf_t *)mp)->lock);
++    TLSF_RELEASE_LOCK(&((tlsf_t *)mem_pool)->lock);
+ 
+     return ret;
+ }
+ 
+ /******************************************************************/
+-void *tlsf_calloc(size_t nelem, size_t elem_size)
++void *tlsf_calloc(size_t nelem, size_t elem_size, void *mem_pool)
+ {
+ /******************************************************************/
+     void *ret;
+ 
+-    TLSF_ACQUIRE_LOCK(&((tlsf_t *)mp)->lock);
++    TLSF_ACQUIRE_LOCK(&((tlsf_t *)mem_pool)->lock);
+ 
+-    ret = calloc_ex(nelem, elem_size, mp);
++    ret = calloc_ex(nelem, elem_size, mem_pool);
+ 
+-    TLSF_RELEASE_LOCK(&((tlsf_t *)mp)->lock);
++    TLSF_RELEASE_LOCK(&((tlsf_t *)mem_pool)->lock);
+ 
+     return ret;
+ }
+diff -urNp TLSF-2.4.6/src/tlsf.h TLSF-patched/src/tlsf.h
+--- TLSF-2.4.6/src/tlsf.h	2009-10-06 11:25:22.000000000 +0200
++++ TLSF-patched/src/tlsf.h	2020-06-26 09:24:01.159699745 +0200
+@@ -31,9 +31,9 @@ extern void free_ex(void *, void *);
+ extern void *realloc_ex(void *, size_t, void *);
+ extern void *calloc_ex(size_t, size_t, void *);
+ 
+-extern void *tlsf_malloc(size_t size);
+-extern void tlsf_free(void *ptr);
+-extern void *tlsf_realloc(void *ptr, size_t size);
+-extern void *tlsf_calloc(size_t nelem, size_t elem_size);
++extern void *tlsf_malloc(size_t size, void *);
++extern void tlsf_free(void *ptr, void *);
++extern void *tlsf_realloc(void *ptr, size_t size, void *);
++extern void *tlsf_calloc(size_t nelem, size_t elem_size, void *);
+ 
+ #endif
-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Wed Jul 01 12:07:44 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 01 Jul 2020 12:07:44 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jqbWg-000489-DP; Wed, 01 Jul 2020 12:07:42 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=mN/Q=AM=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jqbWf-000482-9f
 for minios-devel@lists.xenproject.org; Wed, 01 Jul 2020 12:07:41 +0000
X-Inumbo-ID: 754adf5c-bb93-11ea-bb8b-bc764e2007e4
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 754adf5c-bb93-11ea-bb8b-bc764e2007e4;
 Wed, 01 Jul 2020 12:07:39 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id D54D6103732;
 Wed,  1 Jul 2020 14:07:38 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id YQmLDRZLvJlV; Wed,  1 Jul 2020 14:07:38 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id A759F101E65
 for <minios-devel@lists.xenproject.org>; Wed,  1 Jul 2020 14:07:38 +0200 (CEST)
Received: from N-1237.office.hd (192.168.24.96) by titania.office.hd
 (192.168.24.89) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 1 Jul 2020
 14:07:38 +0200
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: <minios-devel@lists.xenproject.org>
Subject: [UNIKRAFT/LIBMIMALLOC PATCH v2] Initial port of libmimalloc
Date: Wed, 1 Jul 2020 14:07:32 +0200
Message-ID: <cover.1593605155.git.hugo.lefeuvre@neclab.eu>
X-Mailer: git-send-email 2.7.4
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: titania.office.hd (192.168.24.89) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi,

this is the initial port of the Mimalloc [0] general-purpose memory allocator
for Unikraft as an external library.

Changes since v1:
 - add missing Signed-off line
 - fix errors/warnings reported by checkpatch
 - rename compile guards in include/uk/tlsf.h
 - add missing #include to main-tree.patch
 - fix typos in Makefile.uk copyright header

regards,
Hugo

[0] https://microsoft.github.io/mimalloc/

Hugo Lefeuvre (1):
  Initial port of mimalloc to Unikraft



From minios-devel-bounces@lists.xenproject.org Wed Jul 01 12:07:47 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 01 Jul 2020 12:07:47 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jqbWl-00048g-FF; Wed, 01 Jul 2020 12:07:47 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=mN/Q=AM=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jqbWk-000482-5F
 for minios-devel@lists.xenproject.org; Wed, 01 Jul 2020 12:07:46 +0000
X-Inumbo-ID: 775f7686-bb93-11ea-bca7-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 775f7686-bb93-11ea-bca7-bc764e2007e4;
 Wed, 01 Jul 2020 12:07:43 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 433D4F2004;
 Wed,  1 Jul 2020 14:07:42 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id cTTJCXdzs1SN; Wed,  1 Jul 2020 14:07:42 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 08D7BF2003
 for <minios-devel@lists.xenproject.org>; Wed,  1 Jul 2020 14:07:40 +0200 (CEST)
Received: from N-1237.office.hd (192.168.24.96) by titania.office.hd
 (192.168.24.89) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 1 Jul 2020
 14:07:39 +0200
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: <minios-devel@lists.xenproject.org>
Subject: [UNIKRAFT/LIBMIMALLOC PATCH v2] Initial port of mimalloc to Unikraft
Date: Wed, 1 Jul 2020 14:07:33 +0200
Message-ID: <7c08a3de16702600ea0c8ddc508bfe0b05d78e4a.1593605155.git.hugo.lefeuvre@neclab.eu>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <cover.1593605155.git.hugo.lefeuvre@neclab.eu>
References: <cover.1593605155.git.hugo.lefeuvre@neclab.eu>
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: titania.office.hd (192.168.24.89) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
---
 Config.uk                                 |  16 ++
 Makefile.uk                               |  94 ++++++++++++
 README.md                                 |  13 ++
 glue.c                                    | 246 ++++++++++++++++++++++++++++++
 include/uk/mimalloc.h                     |  49 ++++++
 include/uk/mimalloc_impl.h                |  56 +++++++
 main-tree.patch                           |  39 +++++
 patches/adapt-to-unikraft-interface.patch | 160 +++++++++++++++++++
 8 files changed, 673 insertions(+)
 create mode 100644 Config.uk
 create mode 100644 Makefile.uk
 create mode 100644 README.md
 create mode 100644 glue.c
 create mode 100644 include/uk/mimalloc.h
 create mode 100644 include/uk/mimalloc_impl.h
 create mode 100644 main-tree.patch
 create mode 100644 patches/adapt-to-unikraft-interface.patch

diff --git a/Config.uk b/Config.uk
new file mode 100644
index 0000000..7ee8aee
--- /dev/null
+++ b/Config.uk
@@ -0,0 +1,16 @@
+menuconfig LIBMIMALLOC
+	bool "mimalloc - a compact general purpose allocator with excellent performance"
+	default n
+	select LIBUKSCHED
+	select LIBNEWLIBC
+	select LIBPOSIX_SYSINFO
+	select LIBPTHREAD_EMBEDDED
+	select LIBUKALLOCREGION
+if LIBMIMALLOC
+	config MIMALLOC_DEBUG
+		int "Mimalloc debug level"
+		default 0
+	config MIMALLOC_ASSERT
+		bool "Mimalloc assertions"
+		default n
+endif
diff --git a/Makefile.uk b/Makefile.uk
new file mode 100644
index 0000000..f8b2424
--- /dev/null
+++ b/Makefile.uk
@@ -0,0 +1,94 @@
+#  libmimalloc Makefile.uk
+#
+#  Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+#
+#  Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+#
+#  Redistribution and use in source and binary forms, with or without
+#  modification, are permitted provided that the following conditions
+#  are met:
+#
+#  1. Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+#  2. Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in the
+#     documentation and/or other materials provided with the distribution.
+#  3. Neither the name of the copyright holder nor the names of its
+#     contributors may be used to endorse or promote products derived from
+#     this software without specific prior written permission.
+#
+#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+#  POSSIBILITY OF SUCH DAMAGE.
+#
+
+################################################################################
+# Library registration
+################################################################################
+$(eval $(call addlib_s,libmimalloc,$(CONFIG_LIBMIMALLOC)))
+
+################################################################################
+# Sources
+################################################################################
+LIBMIMALLOC_VERSION=1.6.1
+LIBMIMALLOC_URL=https://github.com/microsoft/mimalloc/archive/v$(LIBMIMALLOC_VERSION).zip
+LIBMIMALLOC_DIR=mimalloc-$(LIBMIMALLOC_VERSION)
+
+LIBMIMALLOC_PATCHDIR=$(LIBMIMALLOC_BASE)/patches
+$(eval $(call fetch,libmimalloc,$(LIBMIMALLOC_URL),v$(LIBMIMALLOC_VERSION).zip))
+$(eval $(call patch,libmimalloc,$(LIBMIMALLOC_PATCHDIR),$(LIBMIMALLOC_DIR)))
+
+################################################################################
+# Helpers
+################################################################################
+LIBMIMALLOC=$(LIBMIMALLOC_ORIGIN)/$(LIBMIMALLOC_DIR)
+
+################################################################################
+# Library includes
+################################################################################
+
+CINCLUDES-$(CONFIG_LIBMIMALLOC) += -I$(LIBMIMALLOC_BASE) \
+                                   -I$(LIBMIMALLOC_BASE)/include \
+                                   -I$(LIBMIMALLOC)/include
+
+################################################################################
+# Global flags
+################################################################################
+LIBMIMALLOC_GLOBAL_FLAGS-$(CONFIG_MIMALLOC_ASSERT) += -DNDEBUG
+LIBMIMALLOC_CFLAGS-y += -Wall -Wextra -Wno-unknown-pragmas -fvisibility=hidden \
+			-Wno-invalid-memory-model \
+			-D'MI_DEBUG=${CONFIG_MIMALLOC_DEBUG}'\
+			${LIBMIMALLOC_GLOBAL_FLAGS-n}
+
+################################################################################
+# Glue code
+################################################################################
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC_BASE)/glue.c
+
+################################################################################
+# Sources
+################################################################################
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/stats.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/random.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/os.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/arena.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/region.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/segment.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/page.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/alloc.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/alloc-aligned.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/alloc-posix.c
+#LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/bitmap.inc.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/heap.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/options.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/init.c
+#LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/alloc-override.c
+#LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/page-queue.c
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..a43779c
--- /dev/null
+++ b/README.md
@@ -0,0 +1,13 @@
+Mimalloc for Unikraft
+=====================
+
+This is the port of the Mimalloc [0] general-purpose memory allocator for
+Unikraft as an external library.
+
+How to use this allocator in your unikernel application:
+
+- apply main-tree.patch to the main tree
+- select "Mimalloc" in `ukboot > Default memory allocator`
+- pass at least 256MiB of memory to the unikernel
+
+[0] https://microsoft.github.io/mimalloc/
diff --git a/glue.c b/glue.c
new file mode 100644
index 0000000..c64e2c8
--- /dev/null
+++ b/glue.c
@@ -0,0 +1,246 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <uk/mimalloc_impl.h>
+#include <uk/mimalloc.h>
+#include <mimalloc.h>
+#include <mimalloc-internal.h> // _mi_options_init()
+#include <uk/alloc_impl.h>
+#include <uk/print.h>
+#include <uk/allocregion.h>
+#include <uk/thread.h>	// uk_thread_current()
+#include <uk/page.h>	// round_pgup()
+#include <uk/sched.h>	// uk_mimalloc_init_internal()
+
+/* Notes of Unikraft's Mimalloc port:
+ *
+ * 1. Minimum heap size required: 256MiB, which is the size of an arena.
+ *
+ * 2. Maximum number of Mimalloc instances:
+ *    Mimalloc's current code base relies strongly on static variables. Instead
+ *    of heavily patching it (and maintaining the patches) we simply restrict
+ *    the maximum number of Mimalloc instances to one.
+ *
+ * 3. Early boot time allocator:
+ *    Mimalloc can only be initialized after pthread. However the early boot
+ *    process including pthread's initialization itself requires a functioning
+ *    memory allocator. We solve this problem by relying on ukallocregion during
+ *    the early boot time. The transition to Mimalloc is triggered as soon as
+ *    _tls_ready() returns true. We expect that this won't cause significant
+ *    memory leak since memory allocated during EBT is typically not freed.
+ *
+ * 4. Transition EBT allocator -> Mimalloc:
+ *    We transition as soon as the TLS has been allocated and the %fs register
+ *    set. This is checked at every EBT allocation by inspecting
+ *    uk_thread_current()->prv which typically points to the thread local
+ *    storage. Since memory allocations might happen during Mimalloc's
+ *    initialization itself (e.g. calls to malloc() by pthread) the early boot
+ *    time allocator continues to satisfy requests until Mimalloc is ready
+ *    (after mi_process_load() returned).
+ */
+
+/* Minimum heap size (size of an arena)
+ * TODO: can Mimalloc be reconfigured/patched to lower/remove this limitation?
+ */
+#define MIN_HEAP_SIZE 268435456L
+
+/* Rely on ukallocregion to satisfy boot-time allocations */
+static struct uk_alloc *__region_alloc;
+
+/* make sure that the transition from boot-time allocation to Mimalloc is done
+ * only once: calls to malloc() during Mimalloc initialization should be
+ * satisfied using the boot-time allocator.
+ */
+static int __initialized;
+
+static inline int _tls_ready(void)
+{
+	/* Is the thread local storage ready? */
+	struct uk_thread *current = uk_thread_current();
+
+	return current && current->prv != NULL;
+}
+
+/* boot-time malloc interface */
+
+static void uk_mimalloc_init_internal(struct uk_alloc *a);
+
+/* NOTE: not static, this is used in the mimalloc code base to request memory
+ * "from the OS"
+ */
+void *uk_mimalloc_region_malloc(struct uk_alloc *a, size_t size)
+{
+	/* detect call from main thread to leave boot time mode */
+	if (_tls_ready() && !__initialized) {
+		uk_pr_debug("%s: leaving early boot-time allocation mode\n",
+			   uk_thread_current()->name);
+		__initialized = 1;
+		uk_mimalloc_init_internal(a);
+
+		/* satisfy request using new malloc interface */
+		return uk_malloc(a, size);
+	}
+
+	uk_pr_debug("allocating %zu from region allocator\n", size);
+
+	return uk_malloc(__region_alloc, size);
+}
+
+static int uk_mimalloc_region_posix_memalign(struct uk_alloc *a __unused,
+					     void **memptr, size_t align,
+					     size_t size)
+{
+	uk_pr_debug("allocating %zu aligned at %zu from region allocator\n",
+			size, align);
+
+	return uk_posix_memalign(__region_alloc, memptr, align, size);
+}
+
+static void uk_mimalloc_region_free(struct uk_alloc *a __unused, void *ptr)
+{
+	uk_pr_info("attempt to free memory during early boot time\n");
+
+	return uk_free(__region_alloc, ptr);
+}
+
+/* malloc interface */
+
+static void *uk_mimalloc_malloc(struct uk_alloc *a __unused, size_t size)
+{
+	return mi_malloc(size);
+}
+
+static void uk_mimalloc_free(struct uk_alloc *a __unused, void *ptr)
+{
+	mi_free(ptr);
+}
+
+static void *uk_mimalloc_realloc(struct uk_alloc *a __unused, void *ptr,
+				 size_t size)
+{
+	return mi_realloc(ptr, size);
+}
+
+static void *uk_mimalloc_calloc(struct uk_alloc *a __unused, size_t nelem,
+				size_t elem_size)
+{
+	return mi_calloc(nelem, elem_size);
+}
+
+static int uk_mimalloc_posix_memalign(struct uk_alloc *a __unused, void **p,
+				      size_t alignment, size_t size)
+{
+	return mi_posix_memalign(p, alignment, size);
+}
+
+static void *uk_mimalloc_memalign(struct uk_alloc *a __unused, size_t alignment,
+				  size_t size)
+{
+	return mi_memalign(alignment, size);
+}
+
+static void uk_mimalloc_init_internal(struct uk_alloc *a)
+{
+	mi_process_load();
+
+	/* rebind interface to actual malloc interface */
+	(a)->malloc         = uk_mimalloc_malloc;
+	(a)->calloc         = uk_mimalloc_calloc;
+	(a)->realloc        = uk_mimalloc_realloc;
+	(a)->posix_memalign = uk_mimalloc_posix_memalign;
+	(a)->memalign       = uk_mimalloc_memalign;
+	(a)->free           = uk_mimalloc_free;
+
+	/* delay this after interface rebinding to avoid using early boot
+	 * time memory.
+	 */
+	_mi_options_init();
+
+	uk_pr_info("Successfully initialized Mimalloc\n");
+}
+
+struct uk_alloc *uk_mimalloc_init(void *base, size_t len)
+{
+	struct uk_alloc *a;
+	size_t metalen;
+
+	/* TODO: This Mimalloc port does not support multiple memory regions
+	 * yet. Because of the multiboot layout, the first region might be a
+	 * single page, so we simply ignore it.
+	 */
+	if (len <= __PAGE_SIZE)
+		return NULL;
+
+	if (__region_alloc) {
+		uk_pr_err("mimalloc already initialized "
+			  "(max number of instances: 1)\n");
+		return NULL;
+	}
+
+	metalen = round_pgup(sizeof(*a));
+
+	/* enough space for allocator available? */
+	if (metalen > len) {
+		uk_pr_err("Not enough space for allocator: %" __PRIsz
+			  " B required but only %" __PRIuptr" B usable\n",
+			  metalen, len);
+		return NULL;
+	}
+
+	/* enough space to allocate arena? */
+	if (len < MIN_HEAP_SIZE) {
+		/* Note: we don't exit, but calls to malloc will return NULL. */
+		uk_pr_err("Not enough space to allocate arena: %lu bytes "
+			  "required but only %" __PRIsz" bytes usable\n",
+			  268435456L, len);
+	}
+
+	/* store allocator metadata on the heap, just before the memory pool */
+	a = (struct uk_alloc *)base;
+	uk_pr_info("Initialize mimalloc allocator (early boot time mode) @ 0x%"
+		   __PRIuptr ", len %"__PRIsz"\n", (uintptr_t)a, len);
+
+	/* register mimalloc *before* initializing the region allocator: in all
+	 * cases we want Mimalloc to be the default allocator.
+	 * FIXME: add uk_allocregion_init_noregister() that initializes a region
+	 * allocator without registering it.
+	 */
+	uk_alloc_init_malloc(a, uk_mimalloc_region_malloc, uk_calloc_compat,
+				uk_realloc_compat, uk_mimalloc_region_free,
+				uk_mimalloc_region_posix_memalign,
+				uk_memalign_compat, NULL);
+
+	__region_alloc = uk_allocregion_init((void *)((uintptr_t) base +
+						metalen), len - metalen);
+
+	return a;
+}
diff --git a/include/uk/mimalloc.h b/include/uk/mimalloc.h
new file mode 100644
index 0000000..b3721fc
--- /dev/null
+++ b/include/uk/mimalloc.h
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __LIBMIMALLOC_H__
+#define __LIBMIMALLOC_H__
+
+#include <uk/alloc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* allocator initialization */
+struct uk_alloc *uk_mimalloc_init(void *base, size_t len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LIBMIMALLOC_H__ */
diff --git a/include/uk/mimalloc_impl.h b/include/uk/mimalloc_impl.h
new file mode 100644
index 0000000..04acfd5
--- /dev/null
+++ b/include/uk/mimalloc_impl.h
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * NOTE: These functions are not part of the public ukmimalloc API.
+ * This interface is used in the mimalloc code base to request memory
+ * "from the OS".
+ */
+
+#ifndef __LIBMIMALLOC_IMPL_H__
+#define __LIBMIMALLOC_IMPL_H__
+
+#include <uk/alloc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* region allocator */
+
+void *uk_mimalloc_region_malloc(struct uk_alloc *a, size_t size);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LIBMIMALLOC_IMPL_H__ */
diff --git a/main-tree.patch b/main-tree.patch
new file mode 100644
index 0000000..99ea037
--- /dev/null
+++ b/main-tree.patch
@@ -0,0 +1,39 @@
+From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+Subject: Add Mimalloc entry to the menuconfig and initialize it
+diff --git a/lib/ukboot/Config.uk b/lib/ukboot/Config.uk
+index a888bc1c..8c9a1dc2 100644
+--- a/lib/ukboot/Config.uk
++++ b/lib/ukboot/Config.uk
+@@ -32,6 +32,10 @@ if LIBUKBOOT
+ 		  Satisfy allocation as fast as possible. No support for free().
+ 		  Refer to help in ukallocregion for more information.
+ 
++		config LIBUKBOOT_INITMIMALLOC
++		bool "Mimalloc"
++		select LIBMIMALLOC
++
+ 		config LIBUKBOOT_NOALLOC
+ 		bool "No memory allocator"
+ 
+diff --git a/lib/ukboot/boot.c b/lib/ukboot/boot.c
+index 4e749aa5..a400749d 100644
+--- a/lib/ukboot/boot.c
++++ b/lib/ukboot/boot.c
+@@ -45,6 +45,8 @@
+ #include <uk/allocbbuddy.h>
+ #elif CONFIG_LIBUKBOOT_INITREGION
+ #include <uk/allocregion.h>
++#elif CONFIG_LIBUKBOOT_INITMIMALLOC
++#include <uk/mimalloc.h>
+ #endif
+ #if CONFIG_LIBUKSCHED
+ #include <uk/sched.h>
+@@ -233,6 +235,8 @@ void ukplat_entry(int argc, char *argv[])
+ 			a = uk_allocbbuddy_init(md.base, md.len);
+ #elif CONFIG_LIBUKBOOT_INITREGION
+ 			a = uk_allocregion_init(md.base, md.len);
++#elif CONFIG_LIBUKBOOT_INITMIMALLOC
++			a = uk_mimalloc_init(md.base, md.len);
+ #endif
+ 		} else {
+ 			uk_alloc_addmem(a, md.base, md.len);
diff --git a/patches/adapt-to-unikraft-interface.patch b/patches/adapt-to-unikraft-interface.patch
new file mode 100644
index 0000000..8a41454
--- /dev/null
+++ b/patches/adapt-to-unikraft-interface.patch
@@ -0,0 +1,160 @@
+From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+Subject: Adapt Mimalloc interface to Unikraft
+ - expose mi_process_load() since it is called in the glue code
+ - remove useless ATOMIC_VAR_INIT calls since they cause problems with newlib
+ - request memory from the OS via mi_unikraft_heap_grow(), which relies
+   internally on uk_mimalloc_region_malloc(), our underlying region manager
+ - at the time where Mimalloc was ported, the support for memory protections
+   by Unikraft was unclear, so it is here disabled. A future update of this
+   port should address this.
+diff -urNp mimalloc-orig/include/mimalloc.h mimalloc-patched/include/mimalloc.h
+--- mimalloc-orig/include/mimalloc.h	2020-02-17 19:10:22.000000000 +0100
++++ mimalloc-patched/include/mimalloc.h	2020-06-24 10:16:31.439830260 +0200
+@@ -144,6 +144,7 @@ mi_decl_export void mi_stats_print(void*
+ mi_decl_export void mi_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept;
+ 
+ mi_decl_export void mi_process_init(void)     mi_attr_noexcept;
++mi_decl_export void mi_process_load(void)     mi_attr_noexcept;
+ mi_decl_export void mi_thread_init(void)      mi_attr_noexcept;
+ mi_decl_export void mi_thread_done(void)      mi_attr_noexcept;
+ mi_decl_export void mi_thread_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept;
+diff -urNp mimalloc-orig/src/init.c mimalloc-patched/src/init.c
+--- mimalloc-orig/src/init.c	2020-02-17 19:10:22.000000000 +0100
++++ mimalloc-patched/src/init.c	2020-06-24 10:16:31.443830218 +0200
+@@ -25,8 +25,8 @@ const mi_page_t _mi_page_empty = {
+   0,       // used
+   0,       // xblock_size
+   NULL,    // local_free
+-  ATOMIC_VAR_INIT(0), // xthread_free
+-  ATOMIC_VAR_INIT(0), // xheap
++  0, // xthread_free
++  0, // xheap
+   NULL, NULL
+ };
+ 
+@@ -91,7 +91,7 @@ const mi_heap_t _mi_heap_empty = {
+   NULL,
+   MI_SMALL_PAGES_EMPTY,
+   MI_PAGE_QUEUES_EMPTY,
+-  ATOMIC_VAR_INIT(NULL),
++  NULL,
+   0,                // tid
+   0,                // cookie
+   { 0, 0 },         // keys
+@@ -125,7 +125,7 @@ mi_heap_t _mi_heap_main = {
+   &tld_main,
+   MI_SMALL_PAGES_EMPTY,
+   MI_PAGE_QUEUES_EMPTY,
+-  ATOMIC_VAR_INIT(NULL),
++  NULL,
+   0,                // thread id
+   0,                // initial cookie
+   { 0, 0 },         // the key of the main heap can be fixed (unlike page keys that need to be secure!)
+@@ -430,7 +430,7 @@ static void mi_allocator_done() {
+ #endif
+ 
+ // Called once by the process loader
+-static void mi_process_load(void) {
++void mi_process_load(void) {
+   mi_heap_main_init();
+   #if defined(MI_TLS_RECURSE_GUARD)
+   volatile mi_heap_t* dummy = _mi_heap_default; // access TLS to allocate it before setting tls_initialized to true;
+@@ -438,7 +438,9 @@ static void mi_process_load(void) {
+   #endif
+   os_preloading = false;
+   atexit(&mi_process_done);
+-  _mi_options_init();
++  // delay _mi_options_init() after initialization as it allocates a lot of
++  // memory and we want to avoid doing that with the early boot time allocator
++  //_mi_options_init();
+   mi_process_init();
+   //mi_stats_reset();-
+   if (mi_redirected) _mi_verbose_message("malloc is redirected.\n");
+@@ -519,6 +521,8 @@ static void mi_process_done(void) {
+   }
+   static bool mi_initialized = _mi_process_init();
+ 
++#elif defined(CONFIG_LIBMIMALLOC)
++  // called by uk_init_mimalloc()
+ #elif defined(__GNUC__) || defined(__clang__)
+   // GCC,Clang: use the constructor attribute
+   static void __attribute__((constructor)) _mi_process_init(void) {
+diff -urNp mimalloc-orig/src/os.c mimalloc-patched/src/os.c
+--- mimalloc-orig/src/os.c	2020-02-17 19:10:22.000000000 +0100
++++ mimalloc-patched/src/os.c	2020-06-24 14:44:56.745158608 +0200
+@@ -14,11 +14,14 @@ terms of the MIT license. A copy of the
+ 
+ #include <string.h>  // strerror
+ 
++#include <uk/mimalloc_impl.h> // uk_mimalloc_region_malloc
+ 
+ #if defined(_WIN32)
+ #include <windows.h>
+ #elif defined(__wasi__)
+ // stdlib.h is all we need, and has already been included in mimalloc.h
++#elif defined(CONFIG_LIBMIMALLOC)
++#include <unistd.h>    // sysconf
+ #else
+ #include <sys/mman.h>  // mmap
+ #include <unistd.h>    // sysconf
+@@ -184,8 +187,8 @@ static bool mi_os_mem_free(void* addr, s
+   bool err = false;
+ #if defined(_WIN32)
+   err = (VirtualFree(addr, 0, MEM_RELEASE) == 0);
+-#elif defined(__wasi__)
+-  err = 0; // WebAssembly's heap cannot be shrunk
++#elif defined(__wasi__) || defined(CONFIG_LIBMIMALLOC)
++  err = 0; // WebAssembly's/Unikraft's heap cannot be shrunk
+ #else
+   err = (munmap(addr, size) == -1);
+ #endif
+@@ -272,6 +275,10 @@ static void* mi_wasm_heap_grow(size_t si
+   }
+   return (void*)aligned_base;
+ }
++#elif defined(CONFIG_LIBMIMALLOC)
++static void* mi_unikraft_heap_grow(size_t size, size_t try_alignment) {
++  return uk_mimalloc_region_malloc(NULL, size);
++}
+ #else
+ #define MI_OS_USE_MMAP
+ static void* mi_unix_mmapx(void* addr, size_t size, size_t try_alignment, int protect_flags, int flags, int fd) {
+@@ -450,6 +457,9 @@ static void* mi_os_mem_alloc(size_t size
+   #elif defined(__wasi__)
+     *is_large = false;
+     p = mi_wasm_heap_grow(size, try_alignment);
++  #elif defined(CONFIG_LIBMIMALLOC)
++    *is_large = false;
++    p = mi_unikraft_heap_grow(size, try_alignment);
+   #else
+     int protect_flags = (commit ? (PROT_WRITE | PROT_READ) : PROT_NONE);
+     p = mi_unix_mmap(NULL, size, try_alignment, protect_flags, false, allow_large, is_large);
+@@ -638,8 +648,8 @@ static bool mi_os_commitx(void* addr, si
+     BOOL ok = VirtualFree(start, csize, MEM_DECOMMIT);
+     err = (ok ? 0 : GetLastError());
+   }
+-  #elif defined(__wasi__)
+-  // WebAssembly guests can't control memory protection
++  #elif defined(__wasi__) || defined(CONFIG_LIBMIMALLOC)
++  // Unikraft/WebAssembly guests can't control memory protection
+   #elif defined(MAP_FIXED)
+   if (!commit) {
+     // use mmap with MAP_FIXED to discard the existing memory (and reduce commit charge)
+@@ -714,7 +724,7 @@ static bool mi_os_resetx(void* addr, siz
+     advice = MADV_DONTNEED;
+     err = madvise(start, csize, advice);
+   }
+-#elif defined(__wasi__)
++#elif defined(__wasi__) || defined(CONFIG_LIBMIMALLOC)
+   int err = 0;
+ #else
+   int err = madvise(start, csize, MADV_DONTNEED);
+@@ -768,7 +778,7 @@ static  bool mi_os_protectx(void* addr,
+   DWORD oldprotect = 0;
+   BOOL ok = VirtualProtect(start, csize, protect ? PAGE_NOACCESS : PAGE_READWRITE, &oldprotect);
+   err = (ok ? 0 : GetLastError());
+-#elif defined(__wasi__)
++#elif defined(__wasi__) || defined(CONFIG_LIBMIMALLOC)
+   err = 0;
+ #else
+   err = mprotect(start, csize, protect ? PROT_NONE : (PROT_READ | PROT_WRITE));
-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Wed Jul 01 12:35:24 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 01 Jul 2020 12:35:24 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jqbxT-0007CS-65; Wed, 01 Jul 2020 12:35:23 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=iWYX=AM=uliege.be=gaulthier.gain@srs-us1.protection.inumbo.net>)
 id 1jqbxQ-0007CN-Rn
 for minios-devel@lists.xen.org; Wed, 01 Jul 2020 12:35:21 +0000
X-Inumbo-ID: 52506428-bb97-11ea-8708-12813bfff9fa
Received: from serv108.segi.ulg.ac.be (unknown [139.165.32.111])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 52506428-bb97-11ea-8708-12813bfff9fa;
 Wed, 01 Jul 2020 12:35:19 +0000 (UTC)
Received: from gaulthiers-mbp.lan (151.169-240-81.adsl-dyn.isp.belgacom.be
 [81.240.169.151])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (No client certificate requested)
 by serv108.segi.ulg.ac.be (Postfix) with ESMTPSA id F26EC200F4BF;
 Wed,  1 Jul 2020 14:35:17 +0200 (CEST)
DKIM-Filter: OpenDKIM Filter v2.11.0 serv108.segi.ulg.ac.be F26EC200F4BF
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uliege.be;
 s=ulg20190529; t=1593606918;
 bh=T3mWW2J14ELf396VEURWatZfzp7hpHKyXEwW0wwY3UY=;
 h=Subject:From:In-Reply-To:Date:Cc:References:To:From;
 b=liqVUp0Lkc9FShQSrPfNuI7z9M+aGXoZ/kkswgK1cojAr73RtYRD8ig3GRACz0dUT
 ciSCd7B4e8QCNnwXU6MuJeGUckAqBAVrGrNYb+7xeR3NFAu+2rufGYO4v0XHZuJSJ7
 DMenI1RNRT9l1dmCpAP+uKL9hyGQL39jYLf0UyzMHyZKwIMrG9OwMQaISgJnuSGPVl
 DtPMAr2DOGsR8b5VvFBli9KAysQEXLPFlAuB5sMjsGC7fl+PX5ImWohw6dH7PE89ge
 RDgj1oUZXj/pyYmC/AWtUnrvHZp1mRcLG+vtqBT+sTKsNzL5pbaSXiHS1ZVNIXD2RR
 5SCcPUkfO+iUg==
Content-Type: text/plain;
	charset=us-ascii
Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\))
Subject: Re: [UNIKRAFT PATCH] lib/syscall_shim: Include processing of
 $(UK_PROVIDED_SYSCALLS)
From: Gaulthier Gain <Gaulthier.Gain@uliege.be>
In-Reply-To: <20200518143701.2966-1-simon.kuenzer@neclab.eu>
Date: Wed, 1 Jul 2020 14:35:17 +0200
Content-Transfer-Encoding: quoted-printable
Message-Id: <1B3646C7-A8B8-46C2-9363-E8D1049710C4@uliege.be>
References: <20200518143701.2966-1-simon.kuenzer@neclab.eu>
To: Simon Kuenzer <simon.kuenzer@neclab.eu>
X-Mailer: Apple Mail (2.3608.60.0.2.5)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>, minios-devel@lists.xen.org
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Reviewed-by: Gaulthier Gain <gaulthier.gain@uliege.be>

> On 18 May 2020, at 16:37, Simon Kuenzer <simon.kuenzer@neclab.eu> =
wrote:
>=20
> Equivalent to the Unikraft build variables scheme we include
> $(UK_PROVIDED_SYSCALLS) as another variable to define the list of
> system calls. So far $(UK_PROVIDED_SYSCALLS-y) was used only.
>=20
> Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
> ---
> lib/syscall_shim/Makefile.uk | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>=20
> diff --git a/lib/syscall_shim/Makefile.uk =
b/lib/syscall_shim/Makefile.uk
> index b758f830..37805c82 100644
> --- a/lib/syscall_shim/Makefile.uk
> +++ b/lib/syscall_shim/Makefile.uk
> @@ -89,7 +89,7 @@ $(LIBSYSCALL_SHIM_BUILD)/libc_stubs.c: =
$(LIBSYSCALL_SHIM_BASE)/gen_libc_stubs.aw
>=20
> $(LIBSYSCALL_SHIM_BUILD)/provided_syscalls.h.in.new:
> 	$(call build_cmd,GEN,libsyscall_shim,$(notdir $@), \
> -		echo $(UK_PROVIDED_SYSCALLS-y) | tr ' ' '\n' > $@)
> +		echo $(UK_PROVIDED_SYSCALLS-y) $(UK_PROVIDED_SYSCALLS) | =
tr ' ' '\n' > $@)
>=20
> $(LIBSYSCALL_SHIM_INCLUDES_PATH)/syscall_stubs.h.new: =
$(LIBSYSCALL_SHIM_BASE)/gen_stubs.awk $(LIBSYSCALL_SHIM_TEMPL)
> 	$(call build_cmd,GEN,libsyscall_shim,$(notdir $@), \
> --=20
> 2.20.1
>=20
>=20



From minios-devel-bounces@lists.xenproject.org Wed Jul 01 12:35:57 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 01 Jul 2020 12:35:57 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jqby1-0007EZ-KL; Wed, 01 Jul 2020 12:35:57 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=iWYX=AM=uliege.be=gaulthier.gain@srs-us1.protection.inumbo.net>)
 id 1jqby1-0007EU-4C
 for minios-devel@lists.xen.org; Wed, 01 Jul 2020 12:35:57 +0000
X-Inumbo-ID: 64aae5bc-bb97-11ea-bb8b-bc764e2007e4
Received: from serv108.segi.ulg.ac.be (unknown [139.165.32.111])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 64aae5bc-bb97-11ea-bb8b-bc764e2007e4;
 Wed, 01 Jul 2020 12:35:49 +0000 (UTC)
Received: from gaulthiers-mbp.lan (151.169-240-81.adsl-dyn.isp.belgacom.be
 [81.240.169.151])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (No client certificate requested)
 by serv108.segi.ulg.ac.be (Postfix) with ESMTPSA id E53F9200F814;
 Wed,  1 Jul 2020 14:35:48 +0200 (CEST)
DKIM-Filter: OpenDKIM Filter v2.11.0 serv108.segi.ulg.ac.be E53F9200F814
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uliege.be;
 s=ulg20190529; t=1593606949;
 bh=xkgx/uI4AF+pAWxy6vRIpAe69MOiwwCLteb64lZnVAQ=;
 h=Subject:From:In-Reply-To:Date:Cc:References:To:From;
 b=YJOGYR46zvOfKMaDha0KdxVK/zcJxDiUUBgj+MXJowQmL8xx/P7aJ7mC5rkAHIsTo
 wo4qiBXhclERMj9x095numIIL2Q1cQn4ok6/1ykklH2uSsvEiV+7zYu31twR/lshy5
 YIl5yIDYRIGZruFDt0+n9V+wvsScXpv80I4KQyZpTgGg7VnJb/Lw/SjdEzPUR6yOC+
 f+a6BoRJPsSM1vjszD3pmC/xs+qAbufkjGqXTKtQq0uq3lSa2tXdFZZzjmUfDc0lS4
 NyI/edINzavnrjxoAScAJYfOXZUF9ngf0xDrpPU0jbjuwEX8VGq4c3IfLBdxIUhO+T
 I7G10gVYaGFpA==
Content-Type: text/plain;
	charset=us-ascii
Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\))
Subject: Re: [UNIKRAFT PATCH] lib/syscall_shim: Provide 'print-syscalls' build
 target
From: Gaulthier Gain <Gaulthier.Gain@uliege.be>
In-Reply-To: <20200518143717.3034-1-simon.kuenzer@neclab.eu>
Date: Wed, 1 Jul 2020 14:35:48 +0200
Content-Transfer-Encoding: quoted-printable
Message-Id: <FC10A712-AF54-4095-8A03-BBFCFDC85AD9@uliege.be>
References: <20200518143717.3034-1-simon.kuenzer@neclab.eu>
To: Simon Kuenzer <simon.kuenzer@neclab.eu>
X-Mailer: Apple Mail (2.3608.60.0.2.5)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>, minios-devel@lists.xen.org
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Reviewed-by: Gaulthier Gain <gaulthier.gain@uliege.be>

> On 18 May 2020, at 16:37, Simon Kuenzer <simon.kuenzer@neclab.eu> =
wrote:
>=20
> Provides 'print-syscalls' target that lists currently activated
> system calls.
>=20
> Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
> ---
> lib/syscall_shim/Makefile.rules | 9 +++++++++
> 1 file changed, 9 insertions(+)
> create mode 100644 lib/syscall_shim/Makefile.rules
>=20
> diff --git a/lib/syscall_shim/Makefile.rules =
b/lib/syscall_shim/Makefile.rules
> new file mode 100644
> index 00000000..386ff9fe
> --- /dev/null
> +++ b/lib/syscall_shim/Makefile.rules
> @@ -0,0 +1,9 @@
> +.PHONY: print-syscalls
> +
> +ifeq ($(UK_HAVE_DOT_CONFIG),y)
> +print-syscalls:
> +	@echo $(UK_PROVIDED_SYSCALLS-y) $(UK_PROVIDED_SYSCALLS)
> +else
> +print-syscalls:
> +	$(error Do not have a configuration. Please run one of the =
configuration targets first)
> +endif
> --=20
> 2.20.1
>=20
>=20



From minios-devel-bounces@lists.xenproject.org Wed Jul 01 15:37:49 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 01 Jul 2020 15:37:49 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jqeny-000608-Qk; Wed, 01 Jul 2020 15:37:46 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=iWYX=AM=uliege.be=gaulthier.gain@srs-us1.protection.inumbo.net>)
 id 1jqenw-0005zz-CH
 for minios-devel@lists.xen.org; Wed, 01 Jul 2020 15:37:45 +0000
X-Inumbo-ID: c7dc38ac-bbb0-11ea-bca7-bc764e2007e4
Received: from serv108.segi.ulg.ac.be (unknown [139.165.32.111])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id c7dc38ac-bbb0-11ea-bca7-bc764e2007e4;
 Wed, 01 Jul 2020 15:37:33 +0000 (UTC)
Received: from gaulthiers-mbp.lan (151.169-240-81.adsl-dyn.isp.belgacom.be
 [81.240.169.151])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (No client certificate requested)
 by serv108.segi.ulg.ac.be (Postfix) with ESMTPSA id A61B2200EED5;
 Wed,  1 Jul 2020 17:37:32 +0200 (CEST)
DKIM-Filter: OpenDKIM Filter v2.11.0 serv108.segi.ulg.ac.be A61B2200EED5
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uliege.be;
 s=ulg20190529; t=1593617852;
 bh=f9Az697SyjQ6MqVhaNDqhDzPfoytEuYYp24lkXprmiY=;
 h=From:Subject:Date:In-Reply-To:Cc:To:References:From;
 b=JMN486bl1biKt1CRHIMO8KPz1SvaAX1oZB+mAVnDpYQ0+zKfqpdx/q3Jnz894brOw
 tT/RsLDNGVhpgGtwldlC9dVbl0Ku+AyycJYEb6PhKqDI5HbhcyFHdigIjrdYZBi9re
 fvvuxWk1isiv4Bnqq/Q0mU+AbYZg5T/m0AmDu4zuTv6VJJDMkXa2Ay8hHuD2Wul9mX
 SlAKnnI+TvbMsHATbQMfi5ED+Np/ffZVTjEG0W/ijYfdW1LBX17EAdq8UWmZ4mPDwj
 LbM381JcJMbo92j50n8R9ASmU8+ZaGwkBXaQiSdg5em4rum11IMyWsV8ZP/o9fVQ7+
 fWDs2LM22lD6A==
From: Gaulthier Gain <Gaulthier.Gain@uliege.be>
Message-Id: <3BD35E60-5B3F-4B64-BBCE-CAA4A490CE8D@uliege.be>
Content-Type: multipart/alternative;
 boundary="Apple-Mail=_0B833ADE-D937-43A1-9C4F-FAB361626F00"
Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\))
Subject: Re: [UNIKRAFT PATCH] lib/syscall_shim: Add option to enable debugging
Date: Wed, 1 Jul 2020 17:37:32 +0200
In-Reply-To: <20200520164130.14606-1-simon.kuenzer@neclab.eu>
To: Simon Kuenzer <simon.kuenzer@neclab.eu>
References: <20200520164130.14606-1-simon.kuenzer@neclab.eu>
X-Mailer: Apple Mail (2.3608.60.0.2.5)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>, minios-devel@lists.xen.org
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>


--Apple-Mail=_0B833ADE-D937-43A1-9C4F-FAB361626F00
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=us-ascii

Reviewed-by: Gaulthier Gain <gaulthier.gain@uliege.be =
<mailto:gaulthier.gain@uliege.be>>

> On 20 May 2020, at 18:41, Simon Kuenzer <simon.kuenzer@neclab.eu> =
wrote:
>=20
> Adds an option to enable debug messages for the syscall_shim library =
only.
>=20
> Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
> ---
> lib/syscall_shim/Config.uk   | 4 ++++
> lib/syscall_shim/Makefile.uk | 1 +
> 2 files changed, 5 insertions(+)
>=20
> diff --git a/lib/syscall_shim/Config.uk b/lib/syscall_shim/Config.uk
> index 9c39ed2f..1d90cf7f 100644
> --- a/lib/syscall_shim/Config.uk
> +++ b/lib/syscall_shim/Config.uk
> @@ -34,4 +34,8 @@ if LIBSYSCALL_SHIM
> 			requests (e.g., sysenter/sysexit). The handler =
maps
> 			register values accordingly to the Linux ABI =
standard
> 			(see: man syscalls[2]).
> +
> +	config LIBSYSCALL_SHIM_DEBUG
> +		bool "Enable debug messages"
> +		default n
> endif
> diff --git a/lib/syscall_shim/Makefile.uk =
b/lib/syscall_shim/Makefile.uk
> index 37805c82..55d7488e 100644
> --- a/lib/syscall_shim/Makefile.uk
> +++ b/lib/syscall_shim/Makefile.uk
> @@ -102,6 +102,7 @@ CINCLUDES-y   +=3D =
-I$(LIBSYSCALL_SHIM_BASE)/include
> CXXINCLUDES-y +=3D -I$(LIBSYSCALL_SHIM_BASE)/include
>=20
> LIBSYSCALL_SHIM_CINCLUDES +=3D -I$(LIBSYSCALL_SHIM_BASE)
> +LIBSYSCALL_SHIM_COMPFLAGS-$(CONFIG_LIBSYSCALL_SHIM_DEBUG) +=3D =
-DUK_DEBUG
>=20
> LIBSYSCALL_SHIM_SRCS-y +=3D $(LIBSYSCALL_SHIM_BUILD)/uk_syscall.c
> LIBSYSCALL_SHIM_SRCS-y +=3D $(LIBSYSCALL_SHIM_BUILD)/uk_syscall6.c
> --=20
> 2.20.1
>=20
>=20


--Apple-Mail=_0B833ADE-D937-43A1-9C4F-FAB361626F00
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=us-ascii

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; =
charset=3Dus-ascii"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; line-break: after-white-space;" =
class=3D"">Reviewed-by: Gaulthier Gain &lt;<a =
href=3D"mailto:gaulthier.gain@uliege.be" =
class=3D"">gaulthier.gain@uliege.be</a>&gt;<br class=3D""><div =
style=3D""><br class=3D""><blockquote type=3D"cite" class=3D""><div =
class=3D"">On 20 May 2020, at 18:41, Simon Kuenzer &lt;<a =
href=3D"mailto:simon.kuenzer@neclab.eu" =
class=3D"">simon.kuenzer@neclab.eu</a>&gt; wrote:</div><br =
class=3D"Apple-interchange-newline"><div class=3D""><div class=3D"">Adds =
an option to enable debug messages for the syscall_shim library only.<br =
class=3D""><br class=3D"">Signed-off-by: Simon Kuenzer &lt;<a =
href=3D"mailto:simon.kuenzer@neclab.eu" =
class=3D"">simon.kuenzer@neclab.eu</a>&gt;<br class=3D"">---<br =
class=3D""> lib/syscall_shim/<a href=3D"http://Config.uk" =
class=3D"">Config.uk</a> &nbsp;&nbsp;| 4 ++++<br class=3D""> =
lib/syscall_shim/<a href=3D"http://Makefile.uk" class=3D"">Makefile.uk</a>=
 | 1 +<br class=3D""> 2 files changed, 5 insertions(+)<br class=3D""><br =
class=3D"">diff --git a/lib/syscall_shim/<a href=3D"http://Config.uk" =
class=3D"">Config.uk</a> b/lib/syscall_shim/<a href=3D"http://Config.uk" =
class=3D"">Config.uk</a><br class=3D"">index 9c39ed2f..1d90cf7f =
100644<br class=3D"">--- a/lib/syscall_shim/<a href=3D"http://Config.uk" =
class=3D"">Config.uk</a><br class=3D"">+++ b/lib/syscall_shim/<a =
href=3D"http://Config.uk" class=3D"">Config.uk</a><br class=3D"">@@ =
-34,4 +34,8 @@ if LIBSYSCALL_SHIM<br class=3D""> <span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	</span><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	</span><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	</span>requests =
(e.g., sysenter/sysexit). The handler maps<br class=3D""> <span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	</span><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	</span><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	</span>register =
values accordingly to the Linux ABI standard<br class=3D""> <span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	</span><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	</span><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	</span>(see: man =
syscalls[2]).<br class=3D"">+<br class=3D"">+<span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	</span>config =
LIBSYSCALL_SHIM_DEBUG<br class=3D"">+<span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	</span><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	</span>bool "Enable debug messages"<br =
class=3D"">+<span class=3D"Apple-tab-span" style=3D"white-space:pre">	=
</span><span class=3D"Apple-tab-span" style=3D"white-space:pre">	=
</span>default n<br class=3D""> endif<br class=3D"">diff --git =
a/lib/syscall_shim/<a href=3D"http://Makefile.uk" =
class=3D"">Makefile.uk</a> b/lib/syscall_shim/<a =
href=3D"http://Makefile.uk" class=3D"">Makefile.uk</a><br class=3D"">index=
 37805c82..55d7488e 100644<br class=3D"">--- a/lib/syscall_shim/<a =
href=3D"http://Makefile.uk" class=3D"">Makefile.uk</a><br class=3D"">+++ =
b/lib/syscall_shim/<a href=3D"http://Makefile.uk" =
class=3D"">Makefile.uk</a><br class=3D"">@@ -102,6 +102,7 @@ CINCLUDES-y =
&nbsp;&nbsp;+=3D -I$(LIBSYSCALL_SHIM_BASE)/include<br class=3D""> =
CXXINCLUDES-y +=3D -I$(LIBSYSCALL_SHIM_BASE)/include<br class=3D""><br =
class=3D""> LIBSYSCALL_SHIM_CINCLUDES +=3D -I$(LIBSYSCALL_SHIM_BASE)<br =
class=3D"">+LIBSYSCALL_SHIM_COMPFLAGS-$(CONFIG_LIBSYSCALL_SHIM_DEBUG) +=3D=
 -DUK_DEBUG<br class=3D""><br class=3D""> LIBSYSCALL_SHIM_SRCS-y +=3D =
$(LIBSYSCALL_SHIM_BUILD)/uk_syscall.c<br class=3D""> =
LIBSYSCALL_SHIM_SRCS-y +=3D $(LIBSYSCALL_SHIM_BUILD)/uk_syscall6.c<br =
class=3D"">-- <br class=3D"">2.20.1<br class=3D""><br class=3D""><br =
class=3D""></div></div></blockquote></div><br class=3D""></body></html>=

--Apple-Mail=_0B833ADE-D937-43A1-9C4F-FAB361626F00--


From minios-devel-bounces@lists.xenproject.org Wed Jul 01 15:38:24 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 01 Jul 2020 15:38:24 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jqeoa-000639-TZ; Wed, 01 Jul 2020 15:38:24 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=iWYX=AM=uliege.be=gaulthier.gain@srs-us1.protection.inumbo.net>)
 id 1jqeoZ-000633-Ix
 for minios-devel@lists.xen.org; Wed, 01 Jul 2020 15:38:23 +0000
X-Inumbo-ID: e418a190-bbb0-11ea-bb8b-bc764e2007e4
Received: from serv108.segi.ulg.ac.be (unknown [139.165.32.111])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id e418a190-bbb0-11ea-bb8b-bc764e2007e4;
 Wed, 01 Jul 2020 15:38:20 +0000 (UTC)
Received: from gaulthiers-mbp.lan (151.169-240-81.adsl-dyn.isp.belgacom.be
 [81.240.169.151])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (No client certificate requested)
 by serv108.segi.ulg.ac.be (Postfix) with ESMTPSA id 226AE200CD16;
 Wed,  1 Jul 2020 17:38:20 +0200 (CEST)
DKIM-Filter: OpenDKIM Filter v2.11.0 serv108.segi.ulg.ac.be 226AE200CD16
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uliege.be;
 s=ulg20190529; t=1593617900;
 bh=IO1Eky4RYXvFfjj8PJN25dRL4JFaST0Xv87daxDWQ/Y=;
 h=Subject:From:In-Reply-To:Date:Cc:References:To:From;
 b=vVetpjDpfIt521npN6Vei0P4o2/B3AAcLSY6JJrbZbtSJRxVthYrlAHcEI8/YXUY+
 2Ic0J83fFXilGcmHilLtW+MdxUiCVxTHuwg9/FGacy0SAlWj++baPbU0frfCK4DmS3
 t86whxQGmYQHdRD+haIZYAncJs+E9c7amS9lbU6vhOEuexyxvAjRf7Sk2K2FSEmefM
 FgNa/WB7deG0ezR1XeaZiSqUcD0n/ejqi8Bx0KZyNJspqKUa7SHLP/pOJb2GxthJjr
 HPI46SHnOJCGcZ2IdeeWofmeAxNewMZaxmSFTHclGzzjKNlwlPwz/ma1Bkzeei/ker
 6zUX5Ocg3ivpw==
Content-Type: text/plain;
	charset=us-ascii
Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\))
Subject: Re: [UNIKRAFT PATCH] lib/syscall_shim: Enable UK_LIBC_SYSCALLS when
 library is unselected
From: Gaulthier Gain <Gaulthier.Gain@uliege.be>
In-Reply-To: <20200520164148.14680-1-simon.kuenzer@neclab.eu>
Date: Wed, 1 Jul 2020 17:38:19 +0200
Content-Transfer-Encoding: quoted-printable
Message-Id: <A0C0815B-6F58-4C0F-BDDE-80A9E9EAD1E3@uliege.be>
References: <20200520164148.14680-1-simon.kuenzer@neclab.eu>
To: Simon Kuenzer <simon.kuenzer@neclab.eu>
X-Mailer: Apple Mail (2.3608.60.0.2.5)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>, minios-devel@lists.xen.org
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Reviewed-by: Gaulthier Gain <gaulthier.gain@uliege.be>

> On 20 May 2020, at 18:41, Simon Kuenzer <simon.kuenzer@neclab.eu> =
wrote:
>=20
> Always enables UK_LIBC_SYSCALLS as soon as syscall_shim is
> disabled. This enables all libc-style wrapper implementations of
> system calls (e.g., open(), write()) when system calls are not
> enabled. Those wrappers can only be disabled when syscall_shim is
> selected and the hidden option LIBSYSCALL_SHIM_NOWRAPPER is set. This
> is a very special case that may only be caused by some libcs that are
> based on system calls and provide own libc-style wrappers (e.g., =
musl).
>=20
> Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
> ---
> lib/syscall_shim/include/uk/syscall.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>=20
> diff --git a/lib/syscall_shim/include/uk/syscall.h =
b/lib/syscall_shim/include/uk/syscall.h
> index 1be4ab91..ffa9f1ee 100644
> --- a/lib/syscall_shim/include/uk/syscall.h
> +++ b/lib/syscall_shim/include/uk/syscall.h
> @@ -51,11 +51,11 @@
>  * UK_LIBC_SYSCALLS can be set to 0 through compilation flags.
>  */
> #ifndef UK_LIBC_SYSCALLS
> -#if CONFIG_LIBSYSCALL_SHIM_NOWRAPPER
> +#if CONFIG_LIBSYSCALL_SHIM && CONFIG_LIBSYSCALL_SHIM_NOWRAPPER
> #define UK_LIBC_SYSCALLS (0)
> #else
> #define UK_LIBC_SYSCALLS (1)
> -#endif /* CONFIG_LIBSYSCALL_SHIM_NOWRAPPER */
> +#endif /* CONFIG_LIBSYSCALL_SHIM && CONFIG_LIBSYSCALL_SHIM_NOWRAPPER =
*/
> #endif /* UK_LIBC_SYSCALLS */
>=20
> #define __uk_scc(X) ((long) (X))
> --=20
> 2.20.1
>=20
>=20



From minios-devel-bounces@lists.xenproject.org Mon Jul 06 11:22:25 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Mon, 06 Jul 2020 11:22:25 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jsPCZ-0001Ej-3U; Mon, 06 Jul 2020 11:22:23 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=hWA1=AR=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jsPCX-0001Ed-QY
 for minios-devel@lists.xen.org; Mon, 06 Jul 2020 11:22:21 +0000
X-Inumbo-ID: f3f42116-bf7a-11ea-bca7-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id f3f42116-bf7a-11ea-bca7-bc764e2007e4;
 Mon, 06 Jul 2020 11:22:19 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 65669F2003;
 Mon,  6 Jul 2020 13:22:18 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id dRJ--0ONwJhH; Mon,  6 Jul 2020 13:22:18 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 28174F2001;
 Mon,  6 Jul 2020 13:22:14 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Mon, 6 Jul 2020
 13:22:13 +0200
Message-ID: <1594034532.2122.21.camel@neclab.eu>
Subject: Re: [Minios-devel] [UNIKRAFT/LWIP PATCH v2 1/3] init.c: Retrieve IP
 v4 address from device information
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
Date: Mon, 6 Jul 2020 13:22:12 +0200
In-Reply-To: <20200303141445.16116-2-costin.lupu@cs.pub.ro>
References: <20200303141445.16116-1-costin.lupu@cs.pub.ro>
 <20200303141445.16116-2-costin.lupu@cs.pub.ro>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Sharan, Hi Costin,

this patch looks good to me. This is needed for the "ipaddr, netmask
and gwaddr as library argument" series [0] which is ready to be merged.
I have tested it with a static IP address and with DHCP in KVM, both
worked perfectly fine. Having this merged first would be nice.

Reviewed-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>

regards,
Hugo

[0]Â https://patchwork.unikraft.org/project/unikraft/list/?series=1440

On Tue, 2020-03-03 at 16:14 +0200, Costin Lupu wrote:
> IP addresses for netfront devices on Xen may be configured using
> Xenstore.
> Therefore we should first try to get the IP address from device
> before taking
> it from elsewhere.
> 
> Signed-off-by: Costin Lupu <costin.lupu@cs.pub.ro>
> ---
> Â init.c | 59 +++++++++++++++++++++++++++++++++++++++-----------------
> --
> Â 1 file changed, 40 insertions(+), 19 deletions(-)
> 
> diff --git a/init.c b/init.c
> index 1447a2c..4bae724 100644
> --- a/init.c
> +++ b/init.c
> @@ -38,11 +38,13 @@
> Â #include "lwip/tcpip.h"
> Â #include "lwip/init.h"
> Â #include "lwip/dhcp.h"
> +#include "lwip/inet.h"
> Â #if CONFIG_LWIP_NOTHREADS
> Â #include "lwip/timeouts.h"
> Â #else /* CONFIG_LWIP_NOTHREADS */
> Â #include <uk/semaphore.h>
> Â #endif /* CONFIG_LWIP_NOTHREADS */
> +#include <uk/netdev_core.h>
> Â #include "netif/uknetdev.h"
> Â #include <uk/init.h>
> Â 
> @@ -139,11 +141,11 @@ static int liblwip_init(void)
> Â 	uint16_tÂ Â __maybe_unused int16cfg;
> Â 	int is_first_nf;
> Â #if LWIP_IPV4
> -	ip4_addr_t __maybe_unused ip4;
> +	ip4_addr_t ip4;
> Â 	ip4_addr_t *ip4_arg;
> -	ip4_addr_t __maybe_unused mask4;
> +	ip4_addr_t mask4;
> Â 	ip4_addr_t *mask4_arg;
> -	ip4_addr_t __maybe_unused gw4;
> +	ip4_addr_t gw4;
> Â 	ip4_addr_t *gw4_arg;
> Â #endif /* LWIP_IPV4 */
> Â #endif /* CONFIG_LWIP_UKNETDEV && CONFIG_LWIP_AUTOIFACE */
> @@ -188,23 +190,42 @@ static int liblwip_init(void)
> Â 		mask4_arg = NULL;
> Â 		gw4_argÂ Â Â = NULL;
> Â 
> -		/*
> -		Â * TODO: Try to get device configuration from
> -		Â * netdev's econf interface:
> -		Â *
> -		Â * UK_NETDEV_IPV4_ADDR_NINT16;
> -		Â * UK_NETDEV_IPV4_ADDR_STR;
> -		Â * UK_NETDEV_IPV4_MASK_NINT16;
> -		Â * UK_NETDEV_IPV4_MASK_STR;
> -		Â * UK_NETDEV_IPV4_GW_NINT16;
> -		Â * UK_NETDEV_IPV4_GW_STR;
> -		Â *
> -		Â * When successfully done, set
> -		Â *Â Â ip_arg = &ip;
> -		Â *Â Â mask_arg = &mask;
> -		Â *Â Â gw_arg = &gw;
> -		Â */
> +		/* IP */
> +		strcfg = uk_netdev_einfo_get(dev,
> UK_NETDEV_IPV4_ADDR_STR);
> +		if (strcfg) {
> +			if (ip4addr_aton(strcfg, &ip4) != 1) {
> +				uk_pr_err("Error converting IP
> address: %s\n",
> +						strcfg);
> +				goto no_conf;
> +			}
> +		} else
> +			goto no_conf;
> +		ip4_arg = &ip4;
> Â 
> +		/* mask */
> +		strcfg = uk_netdev_einfo_get(dev,
> UK_NETDEV_IPV4_MASK_STR);
> +		if (strcfg) {
> +			if (ip4addr_aton(strcfg, &mask4) != 1) {
> +				uk_pr_err("Error converting net
> mask: %s\n",
> +						strcfg);
> +				goto no_conf;
> +			}
> +		} else
> +			/* default mask */
> +			ip4_addr_set_u32(&mask4,
> lwip_htonl(IP_CLASSC_NET));
> +		mask4_arg = &mask4;
> +
> +		/* gateway */
> +		strcfg = uk_netdev_einfo_get(dev,
> UK_NETDEV_IPV4_GW_STR);
> +		if (strcfg) {
> +			if (ip4addr_aton(strcfg, &gw4) != 1) {
> +				uk_pr_err("Error converting gateway:
> %s\n",
> +						strcfg);
> +				goto no_conf;
> +			}
> +			gw4_arg = &gw4;
> +		}
> +no_conf:
> Â 		nf = uknetdev_addif(dev, ip4_arg, mask4_arg,
> gw4_arg);
> Â #else /* LWIP_IPV4 */
> Â 		/*


From minios-devel-bounces@lists.xenproject.org Mon Jul 06 11:46:11 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Mon, 06 Jul 2020 11:46:11 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jsPZb-0002zY-7Q; Mon, 06 Jul 2020 11:46:11 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=hWA1=AR=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jsPZZ-0002zQ-Se
 for minios-devel@lists.xen.org; Mon, 06 Jul 2020 11:46:09 +0000
X-Inumbo-ID: 477ef3f8-bf7e-11ea-bca7-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 477ef3f8-bf7e-11ea-bca7-bc764e2007e4;
 Mon, 06 Jul 2020 11:46:08 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 0ED12F2003;
 Mon,  6 Jul 2020 13:46:07 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id C7OSBZoAQDGK; Mon,  6 Jul 2020 13:46:06 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id D9426F2001
 for <minios-devel@lists.xen.org>; Mon,  6 Jul 2020 13:46:04 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Mon, 6 Jul 2020
 13:46:04 +0200
Message-ID: <1594035963.2122.26.camel@neclab.eu>
Subject: Re: [UNIKRAFT PATCH v2 2/2] lib/uknetdev: Get the ipaddr, gw_addr
 and subnet
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Sharan Santhanam <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
Date: Mon, 6 Jul 2020 13:46:03 +0200
In-Reply-To: <20200630105123.6727-3-sharan.santhanam@neclab.eu>
References: <20200630105123.6727-1-sharan.santhanam@neclab.eu>
 <20200630105123.6727-3-sharan.santhanam@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Sharan,

this patch looks good to me. Just a few minor comments inline.

regards,
Hugo

On Tue, 2020-06-30 at 12:51 +0200, Sharan Santhanam wrote:
> The user of uknetdev can pass the ipaddr, gw_addr and subnet as a
> library argument. The library argument can be retrieved from the
> network stack using uk_netdev_einfo_get function. The library
> arguments are retrieved only if the driver does not support the
> uk_netdev_einfo_get callback.
> 
> Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
> ---
> Â lib/uknetdev/netdev.c | 21 +++++++++++++++++++++
> Â 1 file changed, 21 insertions(+)
> 
> diff --git a/lib/uknetdev/netdev.c b/lib/uknetdev/netdev.c
> index 85429a8b..8fc7444e 100644
> --- a/lib/uknetdev/netdev.c
> +++ b/lib/uknetdev/netdev.c
> @@ -231,6 +231,25 @@ void uk_netdev_info_get(struct uk_netdev *dev,
> Â 				Â Â Â Â Â Â dev_info->max_tx_queues);
> Â }
> Â 
> +static const void *_netdev_einfo_get(struct uk_netdev *dev,
> +				enum uk_netdev_einfo_type einfo)
> +{
> +	switch (einfo) {
> +	case UK_NETDEV_IPV4_ADDR_STR:
> +		uk_pr_debug("ip_addr: %s\n", dev->_config-
> >ipv4_addr);

AFAIK this is undefined behavior if `dev->_config->ipv4_addr` is a null
pointer. Sensible libc implementations will handle this correctly, but
that's implementation specific.

> +		return dev->_config->ipv4_addr;
> +	case UK_NETDEV_IPV4_MASK_STR:
> +		uk_pr_debug("netmask: %s\n", dev->_config-
> >ipv4_net_mask);

same here.

> +		return dev->_config->ipv4_net_mask;
> +	case UK_NETDEV_IPV4_GW_STR:
> +		uk_pr_debug("Gateway: %s\n", dev->_config-
> >ipv4_gw_addr);

same here.

> +		return dev->_config->ipv4_gw_addr;
> +	default:
> +		uk_pr_warn("Option %d not yet supported\n", einfo);
> +	}
> +	return NULL;
> +}
> +
> Â const void *uk_netdev_einfo_get(struct uk_netdev *dev,
> Â 				enum uk_netdev_einfo_type einfo)
> Â {
> @@ -239,6 +258,8 @@ const void *uk_netdev_einfo_get(struct uk_netdev
> *dev,
> Â 
> Â 	if (!dev->ops->einfo_get) {
> Â 		/* driver does not provide any extra configuration
> */

this comment only applies to `return NULL`, right? If so, I'd move it
after `return _netdev_einfo_get(dev, einfo)` to make this clear.

> +		if (dev->_config)
> +			return _netdev_einfo_get(dev, einfo);
> Â 		return NULL;
> Â 	}
> Â 	return dev->ops->einfo_get(dev, einfo);


From minios-devel-bounces@lists.xenproject.org Mon Jul 06 12:18:00 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Mon, 06 Jul 2020 12:18:00 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jsQ4N-0005q4-GH; Mon, 06 Jul 2020 12:17:59 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=hWA1=AR=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jsQ4M-0005pz-O6
 for minios-devel@lists.xen.org; Mon, 06 Jul 2020 12:17:58 +0000
X-Inumbo-ID: b9416008-bf82-11ea-8c78-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id b9416008-bf82-11ea-8c78-12813bfff9fa;
 Mon, 06 Jul 2020 12:17:57 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id AA7A4F2003;
 Mon,  6 Jul 2020 14:17:55 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id DgGOe8JSRPNE; Mon,  6 Jul 2020 14:17:55 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 69EA9F2001
 for <minios-devel@lists.xen.org>; Mon,  6 Jul 2020 14:17:53 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Mon, 6 Jul 2020
 14:17:53 +0200
Message-ID: <1594037872.2122.38.camel@neclab.eu>
Subject: Re: [UNIKRAFT PATCH v2 1/2] lib/uknetdev: Add ipaddr, netmask &
 gwaddr as arg
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Sharan Santhanam <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
Date: Mon, 6 Jul 2020 14:17:52 +0200
In-Reply-To: <20200630105123.6727-2-sharan.santhanam@neclab.eu>
References: <20200630105123.6727-1-sharan.santhanam@neclab.eu>
 <20200630105123.6727-2-sharan.santhanam@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Sharan,

thanks a lot for this patch series!

This patch should be applied on top of "Poll based receive based on
uk_netdev features". It looks good to me, just a few small-ish issues
that should be fixed for the v2 (inline).

regards,
Hugo

On Tue, 2020-06-30 at 12:51 +0200, Sharan Santhanam wrote:
> The patch adds ip address, netmask and the gateway address as library
> argument. The parameters are list of argument delimited by a space.
> The library user can forward the argument using the following command
> line:
> net.ipv4_addr, net.ipv4_subnet_mask, net.ipv4_gw_addr
> 
> Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
> ---
> Â lib/uknetdev/Config.ukÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |Â Â 1 +
> Â lib/uknetdev/Makefile.ukÂ Â Â Â Â Â Â Â Â Â Â Â Â Â |Â Â 1 +
> Â lib/uknetdev/include/uk/netdev_core.h |Â Â 8 +++
> Â lib/uknetdev/netdev.cÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â | 70
> +++++++++++++++++++++++++++
> Â 4 files changed, 80 insertions(+)
> 
> diff --git a/lib/uknetdev/Config.uk b/lib/uknetdev/Config.uk
> index 618e8e67..186dd462 100644
> --- a/lib/uknetdev/Config.uk
> +++ b/lib/uknetdev/Config.uk
> @@ -4,6 +4,7 @@ menuconfig LIBUKNETDEV
> Â 	select LIBNOLIBC if !HAVE_LIBC
> Â 	select LIBUKDEBUG
> Â 	select LIBUKALLOC
> +	imply LIBUKLIBPARAM
> Â 
> Â if LIBUKNETDEV
> Â 	config LIBUKNETDEV_MAXNBQUEUES
> diff --git a/lib/uknetdev/Makefile.uk b/lib/uknetdev/Makefile.uk
> index ca08b254..abdcd4bc 100644
> --- a/lib/uknetdev/Makefile.uk
> +++ b/lib/uknetdev/Makefile.uk
> @@ -1,4 +1,5 @@
> Â $(eval $(call addlib_s,libuknetdev,$(CONFIG_LIBUKNETDEV)))
> +$(eval $(call addlib_paramprefix,libuknetdev,net))
> Â 
> Â CINCLUDES-$(CONFIG_LIBUKNETDEV)		+=
> -I$(LIBUKNETDEV_BASE)/include
> Â CXXINCLUDES-$(CONFIG_LIBUKNETDEV)	+=
> -I$(LIBUKNETDEV_BASE)/include
> diff --git a/lib/uknetdev/include/uk/netdev_core.h
> b/lib/uknetdev/include/uk/netdev_core.h
> index 954aa8b0..7f157f94 100644
> --- a/lib/uknetdev/include/uk/netdev_core.h
> +++ b/lib/uknetdev/include/uk/netdev_core.h
> @@ -386,6 +386,12 @@ struct uk_netdev_data {
> Â 	const charÂ Â Â Â Â Â Â Â Â Â Â *drv_name;
> Â };
> Â 
> +struct uk_netdev_config {
> +	const char *ipv4_addr;
> +	const char *ipv4_net_mask;
> +	const char *ipv4_gw_addr;
> +};
> +
> Â /**
> Â  * NETDEV
> Â  * A structure used to interact with a network device.
> @@ -413,6 +419,8 @@ struct uk_netdev {
> Â 	struct
> uk_netdev_tx_queueÂ Â Â *_tx_queue[CONFIG_LIBUKNETDEV_MAXNBQUEUES];
> Â 
> Â 	UK_TAILQ_ENTRY(struct uk_netdev) _list;
> +
> +	struct uk_netdev_config	Â Â Â *_config;
> Â #if (CONFIG_UK_NETDEV_SCRATCH_SIZE > 0)
> Â 	char scratch_pad[CONFIG_UK_NETDEV_SCRATCH_SIZE];
> Â #endif /* CONFIG_UK_NETDEV_SCRATCH_SIZE */
> diff --git a/lib/uknetdev/netdev.c b/lib/uknetdev/netdev.c
> index 151e0897..85429a8b 100644
> --- a/lib/uknetdev/netdev.c
> +++ b/lib/uknetdev/netdev.c
> @@ -38,10 +38,59 @@
> Â #include <string.h>
> Â #include <uk/netdev.h>
> Â #include <uk/print.h>
> +#include <uk/libparam.h>
> Â 
> Â struct uk_netdev_list uk_netdev_list =
> Â 	UK_TAILQ_HEAD_INITIALIZER(uk_netdev_list);
> Â static uint16_t netdev_count;
> +/**
> + * TODO: Define Network argument format when multiple driver device
> need to
> + * coexist. For example like:
> + * Driver Name:IP Address:Net Mask
> + */
> +static char *ipv4_addr;
> +static char *ipv4_subnet_mask;
> +static char *ipv4_gw_addr;
> +
> +UK_LIB_PARAM_STR(ipv4_addr);
> +UK_LIB_PARAM_STR(ipv4_subnet_mask);
> +UK_LIB_PARAM_STR(ipv4_gw_addr);
> +
> +static const char *_parse_ipv4_addr(void)
> +{
> +	static char *ip_addr;

If I understand correctly, this is the internal state ofÂ strtok_r. I
would have appreciated a small comment here to make this clear.

> +
> +	if (ip_addr)
> +		return strtok_r(NULL, " ", &ip_addr);
> +	else if (ipv4_addr)
> +		return strtok_r(ipv4_addr, " ", &ip_addr);
> +
> +	return NULL;
> +}
> +
> +static const char *_parse_ipv4_net_mask(void)
> +{
> +	static char *net_mask;
> +
> +	if (net_mask)
> +		return strtok_r(NULL, " ", &net_mask);
> +	else if (ipv4_subnet_mask)
> +		return strtok_r(ipv4_subnet_mask, " ", &net_mask);
> +
> +	return NULL;
> +}
> +
> +static const char *_parse_ipv4_gw_addr(void)
> +{
> +	static char *gw;
> +
> +	if (gw)
> +		return strtok_r(NULL, " ", &gw);
> +	else if (ipv4_gw_addr)
> +		return strtok_r(ipv4_gw_addr, " ", &gw);
> +
> +	return NULL;
> +}
> Â 
> Â static struct uk_netdev_data *_alloc_data(struct uk_alloc *a,
> Â 					Â Â uint16_t netdev_id,
> @@ -64,6 +113,25 @@ static struct uk_netdev_data *_alloc_data(struct
> uk_alloc *a,
> Â 	return data;
> Â }
> Â 
> +static struct uk_netdev_config *_alloc_config(struct uk_alloc *a)
> +{
> +	struct uk_netdev_config *_config = NULL;
> +
> +	if (ipv4_addr) {
> +		_config = uk_zalloc(a, sizeof(*_config));
> +		if (!_config) {
> +			uk_pr_warn("Failed to allocate memory for
> netdev config\n");
> +			return NULL;
> +		}
> +
> +		_config->ipv4_addr = _parse_ipv4_addr();
> +		_config->ipv4_net_mask = _parse_ipv4_net_mask();
> +		_config->ipv4_gw_addr = _parse_ipv4_gw_addr();
> +	}
> +
> +	return _config;
> +}
> +
> Â int uk_netdev_drv_register(struct uk_netdev *dev, struct uk_alloc
> *a,
> Â 			Â Â Â const char *drv_name)
> Â {
> @@ -91,6 +159,8 @@ int uk_netdev_drv_register(struct uk_netdev *dev,
> struct uk_alloc *a,
> Â 	if (!dev->_data)
> Â 		return -ENOMEM;
> Â 
> +	dev->_config = _alloc_config(a);
> +

_alloc_config can return NULL if `uk_zalloc` fails. In this case, we
should probably abort with ENOMEM; otherwise we might crash later when
dereferencing `dev->_config`. e.g.,

if (!dev->_config)
	return -ENOMEM;

> Â 	UK_TAILQ_INSERT_TAIL(&uk_netdev_list, dev, _list);
> Â 	uk_pr_info("Registered netdev%"PRIu16": %p (%s)\n",
> Â 		Â Â Â netdev_count, dev, drv_name);


From minios-devel-bounces@lists.xenproject.org Mon Jul 06 12:26:08 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Mon, 06 Jul 2020 12:26:08 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jsQCE-0006cc-4X; Mon, 06 Jul 2020 12:26:06 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=hWA1=AR=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jsQCD-0006cX-IM
 for minios-devel@lists.xen.org; Mon, 06 Jul 2020 12:26:05 +0000
X-Inumbo-ID: db7f5638-bf83-11ea-8c7d-12813bfff9fa
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id db7f5638-bf83-11ea-8c7d-12813bfff9fa;
 Mon, 06 Jul 2020 12:26:03 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id E53ED103A9A;
 Mon,  6 Jul 2020 14:26:02 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 29Bxfdmm8DoQ; Mon,  6 Jul 2020 14:26:02 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id C222710349B
 for <minios-devel@lists.xen.org>; Mon,  6 Jul 2020 14:26:02 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Mon, 6 Jul 2020
 14:26:02 +0200
Message-ID: <1594038361.2122.43.camel@neclab.eu>
Subject: Re: [UNIKRAFT PATCH v2 0/2] ipaddr, netmask and gwaddr as library
 argument
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Sharan Santhanam <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
Date: Mon, 6 Jul 2020 14:26:01 +0200
In-Reply-To: <20200630105123.6727-1-sharan.santhanam@neclab.eu>
References: <20200630105123.6727-1-sharan.santhanam@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Sharan,

I have sent comments for each of the two patches. I have tested them
and both are working as expected. This is a very nice addition :-)

The v2 should be mergeable as soon as "Poll based receive based on
uk_netdev features" has been upstreamed. We will also need "[Minios-
devel,UNIKRAFT/LWIP,v2,1/3] init.c: Retrieve IP v4 address from device
information" which I reviewed separately.

thanks!

regards,
Hugo

On Tue, 2020-06-30 at 12:51 +0200, Sharan Santhanam wrote:
> The patch series allow user to pass the ip address, net mask and the
> gateway
> address as a library argument to the uknetdev library. The library
> arguments
> are net.ipv4_addr, net.ipv4_subnet_mask and net.ipv4_gw_addr.
> 
> Changes since v1:
> -Make it ipv4 specific
> 
> Sharan Santhanam (2):
> Â  lib/uknetdev: Add ipaddr, netmask & gwaddr as arg
> Â  lib/uknetdev: Get the ipaddr, gw_addr and subnet
> 
> Â lib/uknetdev/Config.ukÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |Â Â 1 +
> Â lib/uknetdev/Makefile.ukÂ Â Â Â Â Â Â Â Â Â Â Â Â Â |Â Â 1 +
> Â lib/uknetdev/include/uk/netdev_core.h |Â Â 8 +++
> Â lib/uknetdev/netdev.cÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â | 91
> +++++++++++++++++++++++++++
> Â 4 files changed, 101 insertions(+)
> 


From minios-devel-bounces@lists.xenproject.org Mon Jul 06 12:44:12 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Mon, 06 Jul 2020 12:44:12 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jsQTi-0008Jx-9q; Mon, 06 Jul 2020 12:44:10 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=hWA1=AR=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jsQTi-0008Js-0Y
 for minios-devel@lists.xen.org; Mon, 06 Jul 2020 12:44:10 +0000
X-Inumbo-ID: 618f0848-bf86-11ea-8c80-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 618f0848-bf86-11ea-8c80-12813bfff9fa;
 Mon, 06 Jul 2020 12:44:07 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 9AA8EF2003;
 Mon,  6 Jul 2020 14:44:06 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 4E4bNH-xz6Mc; Mon,  6 Jul 2020 14:44:06 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 6194AF2001
 for <minios-devel@lists.xen.org>; Mon,  6 Jul 2020 14:44:04 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Mon, 6 Jul 2020
 14:44:04 +0200
Message-ID: <1594039443.2122.52.camel@neclab.eu>
Subject: Re: [UNIKRAFT PATCH v2 2/2] lib/uknetdev: Get feature supported on
 uk_netdev
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Sharan Santhanam <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
Date: Mon, 6 Jul 2020 14:44:03 +0200
In-Reply-To: <20200630104701.6346-3-sharan.santhanam@neclab.eu>
References: <20200630104701.6346-1-sharan.santhanam@neclab.eu>
 <20200630104701.6346-3-sharan.santhanam@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: titania.office.hd (192.168.24.89) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Sharan,

thanks a lot for this patch. It looks good to me. I only a few minor
comments (inline).

Also, I really think that we should rebase this on top of staging and
merge it right away. It is not fundamentally related to the tap driver,
and having it merged now together with the static IP series would be a
good thing.

regards,
Hugo

On Tue, 2020-06-30 at 12:47 +0200, Sharan Santhanam wrote:
> The uk_netdev_info provides a way to forward information on netdevice
> to the network stack. We extend this with a bitmap of the features
> supported on device. The bit 0,1 of the bitmap indicates if the
> device supports interrupt.
> 
> Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
> ---
> Â lib/uknetdev/include/uk/netdev_core.h | 9 +++++++++
> Â plat/drivers/tap/tap.cÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â | 1 +
> Â plat/drivers/virtio/virtio_net.cÂ Â Â Â Â Â | 1 +
> Â 3 files changed, 11 insertions(+)
> 
> diff --git a/lib/uknetdev/include/uk/netdev_core.h
> b/lib/uknetdev/include/uk/netdev_core.h
> index 827f1872..954aa8b0 100644
> --- a/lib/uknetdev/include/uk/netdev_core.h
> +++ b/lib/uknetdev/include/uk/netdev_core.h
> @@ -77,6 +77,14 @@ UK_TAILQ_HEAD(uk_netdev_list, struct uk_netdev);
> Â  */
> Â #define UK_NETDEV_HWADDR_LEN 6 /**< Length of Ethernet address. */
> Â 
> +#define UK_FEATURE_RXQ_INTR_BIT		Â Â Â Â 0
> +#define UK_FEATURE_RXQ_INTR_AVAILABLEÂ Â (1UL <<
> UK_FEATURE_RXQ_INTR_BIT)

I'm missing a comment here. Something like:

/* device supports interrupts for the receive queue */

> +#define UK_FEATURE_TXQ_INTR_BIT		Â Â Â Â 1
> +#define UK_FEATURE_TXQ_INTR_AVAILABLEÂ Â (1UL <<
> UK_FEATURE_TXQ_INTR_BIT)
> 

same here.

/* device supports interrupts for the transmit queue */

> +#define uk_netdev_rxintr_supported(feature)	\
> +	(feature & (UK_FEATURE_RXQ_INTR_AVAILABLE))
> +
> Â struct uk_hwaddr {
> Â 	uint8_t addr_bytes[UK_NETDEV_HWADDR_LEN];
> Â } __packed;
> @@ -91,6 +99,7 @@ struct uk_netdev_info {
> Â 	uint16_t max_mtu;Â Â Â /**< Maximum supported MTU size. */
> Â 	uint16_t nb_encap_tx;Â Â /**< Number of bytes required as
> headroom for tx. */
> Â 	uint16_t nb_encap_rx;Â Â /**< Number of bytes required as
> headroom for rx. */
> +	uint32_t features;

same here.

/* bitmap of the features supported on the device */

> Â };
> Â 
> Â /**
> diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
> index 505f0ccb..fb96785c 100644
> --- a/plat/drivers/tap/tap.c
> +++ b/plat/drivers/tap/tap.c
> @@ -519,6 +519,7 @@ static void tap_netdev_info_get(struct uk_netdev
> *dev __unused,
> Â 	dev_info->max_tx_queues = 1;
> Â 	dev_info->nb_encap_tx = 0;
> Â 	dev_info->nb_encap_rx = 0;
> +	dev_info->features = 0;
> Â }
> Â 

Moving this to a separate patch would allow us to merge this patch
right away without waiting for the tap driver (which will take longer
to review).

> Â static unsigned int tap_netdev_promisc_get(struct uk_netdev *n)
> diff --git a/plat/drivers/virtio/virtio_net.c
> b/plat/drivers/virtio/virtio_net.c
> index 3025ed3f..0a8312d6 100644
> --- a/plat/drivers/virtio/virtio_net.c
> +++ b/plat/drivers/virtio/virtio_net.c
> @@ -1052,6 +1052,7 @@ static void virtio_net_info_get(struct
> uk_netdev *dev,
> Â 	dev_info->max_tx_queues = vndev->max_vqueue_pairs;
> Â 	dev_info->nb_encap_tx = sizeof(struct
> virtio_net_hdr_padded);
> Â 	dev_info->nb_encap_rx = sizeof(struct
> virtio_net_hdr_padded);
> +	dev_info->features = UK_FEATURE_RXQ_INTR_AVAILABLE;
> Â }
> Â 
> Â static int virtio_net_start(struct uk_netdev *n)


From minios-devel-bounces@lists.xenproject.org Mon Jul 06 14:23:17 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Mon, 06 Jul 2020 14:23:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jsS1Z-0008HV-Pv; Mon, 06 Jul 2020 14:23:13 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=hWA1=AR=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jsS1Y-0008HQ-P5
 for minios-devel@lists.xen.org; Mon, 06 Jul 2020 14:23:12 +0000
X-Inumbo-ID: 37dc6c4e-bf94-11ea-bb8b-bc764e2007e4
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 37dc6c4e-bf94-11ea-bb8b-bc764e2007e4;
 Mon, 06 Jul 2020 14:23:10 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id C84B4103BD8;
 Mon,  6 Jul 2020 16:23:09 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id UXQeV3MK6Qdi; Mon,  6 Jul 2020 16:23:09 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id 90980103A9A
 for <minios-devel@lists.xen.org>; Mon,  6 Jul 2020 16:23:09 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Mon, 6 Jul 2020
 16:23:09 +0200
Message-ID: <1594045388.2122.55.camel@neclab.eu>
Subject: Re: [UNIKRAFT PATCH v2 1/2] lib/uknetdev: Save nw_stack data in a
 netdevice
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Sharan Santhanam <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
Date: Mon, 6 Jul 2020 16:23:08 +0200
In-Reply-To: <20200630104701.6346-2-sharan.santhanam@neclab.eu>
References: <20200630104701.6346-1-sharan.santhanam@neclab.eu>
 <20200630104701.6346-2-sharan.santhanam@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Sharan,

thanks a lot for this patch. Looks good to me, works as expected.

regards,
Hugo

Reviewed-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>

On Tue, 2020-06-30 at 12:47 +0200, Sharan Santhanam wrote:
> We extend the uk_netdev to store network stack specific data into
> uk_netdev. The size of the of this data is passed to network stack
> by setting the CONFIG_UK_NETDEV_SCRATCH_SIZE
> 
> Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
> ---
> Â lib/uknetdev/Makefile.rulesÂ Â Â Â Â Â Â Â Â Â Â | 20 ++++++++++++++++++++
> Â lib/uknetdev/include/uk/netdev_core.h |Â Â 7 +++++++
> Â support/build/Makefile.rulesÂ Â Â Â Â Â Â Â Â Â |Â Â 2 +-
> Â 3 files changed, 28 insertions(+), 1 deletion(-)
> Â create mode 100644 lib/uknetdev/Makefile.rules
> 
> diff --git a/lib/uknetdev/Makefile.rules
> b/lib/uknetdev/Makefile.rules
> new file mode 100644
> index 00000000..7894e163
> --- /dev/null
> +++ b/lib/uknetdev/Makefile.rules
> @@ -0,0 +1,20 @@
> +UK_SCRATCH_MEM=0
> +UK_SCRATCH_RULE_SET=
> +
> +.SECONDEXPANSION:
> +FORCE:
> +
> +uk_scratch_mem_set: $$(eval CFLAGS-y+=-
> DCONFIG_UK_NETDEV_SCRATCH_SIZE=$$(UK_SCRATCH_MEM))
> +	@:;
> +
> +.PHONY : uk_scratch_mem_set
> +
> +
> +## reserve memory for the network stack
> +## uknetdev_scratch_mem,bytes_of_memory
> +define uknetdev_scratch_mem =
> +$(if $(strip $(1)),\
> +	$(if $(shell test $(1) -gt $(UK_SCRATCH_MEM) && echo
> "scratch mem set"), $(eval UK_SCRATCH_MEM:=$(1))))
> +
> +$(if $(strip $(UK_SCRATCH_RULE_SET)),,$(eval UK_SCRATCH_RULE_SET:=1)
> $(eval UK_PREPARE-$(CONFIG_LIBUKNETDEV)+=uk_scratch_mem_set))
> +endef
> diff --git a/lib/uknetdev/include/uk/netdev_core.h
> b/lib/uknetdev/include/uk/netdev_core.h
> index dba719fc..827f1872 100644
> --- a/lib/uknetdev/include/uk/netdev_core.h
> +++ b/lib/uknetdev/include/uk/netdev_core.h
> @@ -65,6 +65,10 @@
> Â extern "C" {
> Â #endif
> Â 
> +#ifndef CONFIG_UK_NETDEV_SCRATCH_SIZE
> +#define CONFIG_UK_NETDEV_SCRATCH_SIZE 0
> +#endif /* CONFIG_UK_NETDEV_SCRATCH_SIZE */
> +
> Â struct uk_netdev;
> Â UK_TAILQ_HEAD(uk_netdev_list, struct uk_netdev);
> Â 
> @@ -400,6 +404,9 @@ struct uk_netdev {
> Â 	struct
> uk_netdev_tx_queueÂ Â Â *_tx_queue[CONFIG_LIBUKNETDEV_MAXNBQUEUES];
> Â 
> Â 	UK_TAILQ_ENTRY(struct uk_netdev) _list;
> +#if (CONFIG_UK_NETDEV_SCRATCH_SIZE > 0)
> +	char scratch_pad[CONFIG_UK_NETDEV_SCRATCH_SIZE];
> +#endif /* CONFIG_UK_NETDEV_SCRATCH_SIZE */
> Â };
> Â 
> Â #ifdef __cplusplus
> diff --git a/support/build/Makefile.rules
> b/support/build/Makefile.rules
> index 8c096fa5..5f7db8a3 100644
> --- a/support/build/Makefile.rules
> +++ b/support/build/Makefile.rules
> @@ -450,7 +450,7 @@ $(4): $(2) | prepare
> Â 		Â Â Â Â Â Â Â $($(call vprefix_lib,$(1),CINCLUDES))
> $($(call vprefix_lib,$(1),CINCLUDES-y)) \
> Â 		Â Â Â Â Â Â Â $($(call
> vprefix_src,$(1),$(2),$(3),INCLUDES)) $($(call
> vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
> Â 		Â Â Â Â Â Â Â $($(call vprefix_glb,$(3),ARCHFLAGS))
> $($(call vprefix_glb,$(3),ARCHFLAGS-y)) \
> -		Â Â Â Â Â Â Â $(CFLAGS) $(CFLAGS-y) \
> +		Â Â Â Â Â Â Â $(CFLAGS) $$(CFLAGS-y) \
> Â 		Â Â Â Â Â Â Â $($(call vprefix_lib,$(1),CFLAGS)) $($(call
> vprefix_lib,$(1),CFLAGS-y)) \
> Â 		Â Â Â Â Â Â Â $($(call vprefix_src,$(1),$(2),$(3),FLAGS))
> $($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
> Â 		Â Â Â Â Â Â Â $(5) \


From minios-devel-bounces@lists.xenproject.org Tue Jul 07 08:25:01 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 07 Jul 2020 08:25:01 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jsiuP-0000pe-Np; Tue, 07 Jul 2020 08:24:57 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Pb9O=AS=neclab.eu=simon.kuenzer@srs-us1.protection.inumbo.net>)
 id 1jsiuO-0000pZ-2w
 for minios-devel@lists.xen.org; Tue, 07 Jul 2020 08:24:56 +0000
X-Inumbo-ID: 5565b350-c02b-11ea-bb8b-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 5565b350-c02b-11ea-bb8b-bc764e2007e4;
 Tue, 07 Jul 2020 08:24:54 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 53FFAF2009;
 Tue,  7 Jul 2020 10:24:53 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id cTOu0lPGb8DM; Tue,  7 Jul 2020 10:24:53 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 1A6DDF2008
 for <minios-devel@lists.xen.org>; Tue,  7 Jul 2020 10:24:51 +0200 (CEST)
Received: from puck.office.hd (192.168.24.91) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 7 Jul 2020
 10:24:50 +0200
Received: from puck.office.hd ([192.168.126.12]) by puck.office.hd
 ([192.168.126.12]) with mapi id 15.01.1979.003; Tue, 7 Jul 2020 10:24:50
 +0200
From: Simon Kuenzer <simon.kuenzer@neclab.eu>
To: Sharan Santhanam <Sharan.Santhanam@neclab.eu>,
 "minios-devel@lists.xen.org" <minios-devel@lists.xen.org>
Subject: Re: [UNIKRAFT PATCH v2 1/2] lib/uknetdev: Save nw_stack data in a
 netdevice
Thread-Topic: [UNIKRAFT PATCH v2 1/2] lib/uknetdev: Save nw_stack data in a
 netdevice
Thread-Index: AQHWTsvppLCIiEJd9kWCEoNqD/Sr16j70pCA
Date: Tue, 7 Jul 2020 08:24:50 +0000
Message-ID: <408EA314-50C0-4301-814C-F4EB699E83D2@neclab.eu>
References: <20200630104701.6346-1-sharan.santhanam@neclab.eu>
 <20200630104701.6346-2-sharan.santhanam@neclab.eu>
In-Reply-To: <20200630104701.6346-2-sharan.santhanam@neclab.eu>
Accept-Language: en-GB, gl-ES, en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
user-agent: Microsoft-MacOutlook/10.10.17.200615
x-originating-ip: [192.168.24.96]
Content-Type: text/plain; charset="utf-8"
Content-ID: <DDE2BB9017C72342B7E92CB9691FB0B5@office.hd>
Content-Transfer-Encoding: base64
MIME-Version: 1.0
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

SGV5IFNoYXJhbiwNCg0K77u/T24gMzAuMDYuMjAsIDEyOjQ3LCAiTWluaW9zLWRldmVsIG9uIGJl
aGFsZiBvZiBTaGFyYW4gU2FudGhhbmFtIiA8bWluaW9zLWRldmVsLWJvdW5jZXNAbGlzdHMueGVu
cHJvamVjdC5vcmcgb24gYmVoYWxmIG9mIFNoYXJhbi5TYW50aGFuYW1AbmVjbGFiLmV1PiB3cm90
ZToNCg0KICAgIFdlIGV4dGVuZCB0aGUgdWtfbmV0ZGV2IHRvIHN0b3JlIG5ldHdvcmsgc3RhY2sg
c3BlY2lmaWMgZGF0YSBpbnRvDQogICAgdWtfbmV0ZGV2LiBUaGUgc2l6ZSBvZiB0aGUgb2YgdGhp
cyBkYXRhIGlzIHBhc3NlZCB0byBuZXR3b3JrIHN0YWNrDQogICAgYnkgc2V0dGluZyB0aGUgQ09O
RklHX1VLX05FVERFVl9TQ1JBVENIX1NJWkUNCiAgICANCiAgICBTaWduZWQtb2ZmLWJ5OiBTaGFy
YW4gU2FudGhhbmFtIDxzaGFyYW4uc2FudGhhbmFtQG5lY2xhYi5ldT4NCiAgICAtLS0NCiAgICAg
bGliL3VrbmV0ZGV2L01ha2VmaWxlLnJ1bGVzICAgICAgICAgICB8IDIwICsrKysrKysrKysrKysr
KysrKysrDQogICAgIGxpYi91a25ldGRldi9pbmNsdWRlL3VrL25ldGRldl9jb3JlLmggfCAgNyAr
KysrKysrDQogICAgIHN1cHBvcnQvYnVpbGQvTWFrZWZpbGUucnVsZXMgICAgICAgICAgfCAgMiAr
LQ0KICAgICAzIGZpbGVzIGNoYW5nZWQsIDI4IGluc2VydGlvbnMoKyksIDEgZGVsZXRpb24oLSkN
CiAgICAgY3JlYXRlIG1vZGUgMTAwNjQ0IGxpYi91a25ldGRldi9NYWtlZmlsZS5ydWxlcw0KICAg
IA0KICAgIGRpZmYgLS1naXQgYS9saWIvdWtuZXRkZXYvTWFrZWZpbGUucnVsZXMgYi9saWIvdWtu
ZXRkZXYvTWFrZWZpbGUucnVsZXMNCiAgICBuZXcgZmlsZSBtb2RlIDEwMDY0NA0KICAgIGluZGV4
IDAwMDAwMDAwLi43ODk0ZTE2Mw0KICAgIC0tLSAvZGV2L251bGwNCiAgICArKysgYi9saWIvdWtu
ZXRkZXYvTWFrZWZpbGUucnVsZXMNCiAgICBAQCAtMCwwICsxLDIwIEBADQogICAgK1VLX1NDUkFU
Q0hfTUVNPTANCiAgICArVUtfU0NSQVRDSF9SVUxFX1NFVD0NCiAgICArDQogICAgKy5TRUNPTkRF
WFBBTlNJT046DQogICAgK0ZPUkNFOg0KICAgICsNCiAgICArdWtfc2NyYXRjaF9tZW1fc2V0OiAk
JChldmFsIENGTEFHUy15Kz0tRENPTkZJR19VS19ORVRERVZfU0NSQVRDSF9TSVpFPSQkKFVLX1ND
UkFUQ0hfTUVNKSkNCiAgICArCUA6Ow0KICAgICsNCiAgICArLlBIT05ZIDogdWtfc2NyYXRjaF9t
ZW1fc2V0DQogICAgKw0KICAgICsNCiAgICArIyMgcmVzZXJ2ZSBtZW1vcnkgZm9yIHRoZSBuZXR3
b3JrIHN0YWNrDQogICAgKyMjIHVrbmV0ZGV2X3NjcmF0Y2hfbWVtLGJ5dGVzX29mX21lbW9yeQ0K
ICAgICtkZWZpbmUgdWtuZXRkZXZfc2NyYXRjaF9tZW0gPQ0KICAgICskKGlmICQoc3RyaXAgJCgx
KSksXA0KICAgICsJJChpZiAkKHNoZWxsIHRlc3QgJCgxKSAtZ3QgJChVS19TQ1JBVENIX01FTSkg
JiYgZWNobyAic2NyYXRjaCBtZW0gc2V0IiksICQoZXZhbCBVS19TQ1JBVENIX01FTTo9JCgxKSkp
KQ0KICAgICsNCiAgICArJChpZiAkKHN0cmlwICQoVUtfU0NSQVRDSF9SVUxFX1NFVCkpLCwkKGV2
YWwgVUtfU0NSQVRDSF9SVUxFX1NFVDo9MSkgJChldmFsIFVLX1BSRVBBUkUtJChDT05GSUdfTElC
VUtORVRERVYpKz11a19zY3JhdGNoX21lbV9zZXQpKQ0KICAgICtlbmRlZg0KICAgIGRpZmYgLS1n
aXQgYS9saWIvdWtuZXRkZXYvaW5jbHVkZS91ay9uZXRkZXZfY29yZS5oIGIvbGliL3VrbmV0ZGV2
L2luY2x1ZGUvdWsvbmV0ZGV2X2NvcmUuaA0KICAgIGluZGV4IGRiYTcxOWZjLi44MjdmMTg3MiAx
MDA2NDQNCiAgICAtLS0gYS9saWIvdWtuZXRkZXYvaW5jbHVkZS91ay9uZXRkZXZfY29yZS5oDQog
ICAgKysrIGIvbGliL3VrbmV0ZGV2L2luY2x1ZGUvdWsvbmV0ZGV2X2NvcmUuaA0KICAgIEBAIC02
NSw2ICs2NSwxMCBAQA0KICAgICBleHRlcm4gIkMiIHsNCiAgICAgI2VuZGlmDQogICAgIA0KICAg
ICsjaWZuZGVmIENPTkZJR19VS19ORVRERVZfU0NSQVRDSF9TSVpFDQogICAgKyNkZWZpbmUgQ09O
RklHX1VLX05FVERFVl9TQ1JBVENIX1NJWkUgMA0KICAgICsjZW5kaWYgLyogQ09ORklHX1VLX05F
VERFVl9TQ1JBVENIX1NJWkUgKi8NCiAgICArDQogICAgIHN0cnVjdCB1a19uZXRkZXY7DQogICAg
IFVLX1RBSUxRX0hFQUQodWtfbmV0ZGV2X2xpc3QsIHN0cnVjdCB1a19uZXRkZXYpOw0KICAgICAN
CiAgICBAQCAtNDAwLDYgKzQwNCw5IEBAIHN0cnVjdCB1a19uZXRkZXYgew0KICAgICAJc3RydWN0
IHVrX25ldGRldl90eF9xdWV1ZSAgICpfdHhfcXVldWVbQ09ORklHX0xJQlVLTkVUREVWX01BWE5C
UVVFVUVTXTsNCiAgICAgDQogICAgIAlVS19UQUlMUV9FTlRSWShzdHJ1Y3QgdWtfbmV0ZGV2KSBf
bGlzdDsNCiAgICArI2lmIChDT05GSUdfVUtfTkVUREVWX1NDUkFUQ0hfU0laRSA+IDApDQogICAg
KwljaGFyIHNjcmF0Y2hfcGFkW0NPTkZJR19VS19ORVRERVZfU0NSQVRDSF9TSVpFXTsNCiAgICAr
I2VuZGlmIC8qIENPTkZJR19VS19ORVRERVZfU0NSQVRDSF9TSVpFICovDQogICAgIH07DQogICAg
IA0KICAgICAjaWZkZWYgX19jcGx1c3BsdXMNCiAgICBkaWZmIC0tZ2l0IGEvc3VwcG9ydC9idWls
ZC9NYWtlZmlsZS5ydWxlcyBiL3N1cHBvcnQvYnVpbGQvTWFrZWZpbGUucnVsZXMNCiAgICBpbmRl
eCA4YzA5NmZhNS4uNWY3ZGI4YTMgMTAwNjQ0DQogICAgLS0tIGEvc3VwcG9ydC9idWlsZC9NYWtl
ZmlsZS5ydWxlcw0KICAgICsrKyBiL3N1cHBvcnQvYnVpbGQvTWFrZWZpbGUucnVsZXMNCiAgICBA
QCAtNDUwLDcgKzQ1MCw3IEBAICQoNCk6ICQoMikgfCBwcmVwYXJlDQogICAgIAkJICAgICAgICQo
JChjYWxsIHZwcmVmaXhfbGliLCQoMSksQ0lOQ0xVREVTKSkgJCgkKGNhbGwgdnByZWZpeF9saWIs
JCgxKSxDSU5DTFVERVMteSkpIFwNCiAgICAgCQkgICAgICAgJCgkKGNhbGwgdnByZWZpeF9zcmMs
JCgxKSwkKDIpLCQoMyksSU5DTFVERVMpKSAkKCQoY2FsbCB2cHJlZml4X3NyYywkKDEpLCQoMiks
JCgzKSxJTkNMVURFUy15KSkgXA0KICAgICAJCSAgICAgICAkKCQoY2FsbCB2cHJlZml4X2dsYiwk
KDMpLEFSQ0hGTEFHUykpICQoJChjYWxsIHZwcmVmaXhfZ2xiLCQoMyksQVJDSEZMQUdTLXkpKSBc
DQogICAgLQkJICAgICAgICQoQ0ZMQUdTKSAkKENGTEFHUy15KSBcDQoNCkNvdWxkIHlvdSBhZGQg
YXQgbGVhc3QgYSBjb21tZW50IGFib3V0IHdoeSB0aGUgYCQkYD8gTXkgY29uY2VybiBpcyB0aGF0
IHRoaXMgcnVsZSBpcyBub3QgaW5saW5lIHRvIHRoZSBvdGhlcnMgdGhhdCB3ZSBoYXZlIGFuZCBp
dCBpcyBub3Qgb2J2aW91cyB3aHkuIEluIGdlbmVyYWwgdGhpcyBsb29rcyB0byBtZSBhcyBhbm90
aGVyIHJlYXNvbiB3aHkgSSB3b3VsZCBwcmVmZXIgZ2VuZXJhdGluZyBhIHNpbXBsZSBoZWFkZXIg
ZmlsZSB0aGF0IGdldHMgdGhlIHZhbHVlIHNldCAoYXMgZGlzY3Vzc2VkIG9mZmxpbmUpLiBBbHRl
cm5hdGl2ZWx5LCB3b3VsZCBpdCBtYWtlIHNlbnNlIHRvIGNoYW5nZSBhbGwgdGhlIGJ1aWxkIGZs
YWdzIGluIG91ciBydWxlcyB0byBgJCRgPyBXaGF0IHdvdWxkIGJlIHRoZSBpbXBsaWNhdGlvbj8N
Cg0KDQogICAgKwkJICAgICAgICQoQ0ZMQUdTKSAkJChDRkxBR1MteSkgXA0KICAgICAJCSAgICAg
ICAkKCQoY2FsbCB2cHJlZml4X2xpYiwkKDEpLENGTEFHUykpICQoJChjYWxsIHZwcmVmaXhfbGli
LCQoMSksQ0ZMQUdTLXkpKSBcDQogICAgIAkJICAgICAgICQoJChjYWxsIHZwcmVmaXhfc3JjLCQo
MSksJCgyKSwkKDMpLEZMQUdTKSkgJCgkKGNhbGwgdnByZWZpeF9zcmMsJCgxKSwkKDIpLCQoMyks
RkxBR1MteSkpIFwNCiAgICAgCQkgICAgICAgJCg1KSBcDQogICAgLS0gDQogICAgMi4yMC4xDQog
ICAgDQogICAgDQpUaGFua3MsDQoNClNpbW9uDQoNCg==


From minios-devel-bounces@lists.xenproject.org Tue Jul 07 08:31:01 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 07 Jul 2020 08:31:01 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jsj0G-0001aZ-81; Tue, 07 Jul 2020 08:31:00 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=CpK0=AS=gmail.com=murarugeorgec@srs-us1.protection.inumbo.net>)
 id 1jsj0F-0001aU-5I
 for minios-devel@lists.xen.org; Tue, 07 Jul 2020 08:30:59 +0000
X-Inumbo-ID: 2e8e1a00-c02c-11ea-bca7-bc764e2007e4
Received: from mail-pf1-x444.google.com (unknown [2607:f8b0:4864:20::444])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 2e8e1a00-c02c-11ea-bca7-bc764e2007e4;
 Tue, 07 Jul 2020 08:30:58 +0000 (UTC)
Received: by mail-pf1-x444.google.com with SMTP id 1so426423pfn.9
 for <minios-devel@lists.xen.org>; Tue, 07 Jul 2020 01:30:58 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:references:in-reply-to:from:date:message-id:subject:to
 :cc; bh=5i/eOoqkuMHcJp5S023+WOW54IkS/l2JHoi9OkYmDps=;
 b=SebeoxdAS4hFgVMW636D4VCZkJ3x2Jjs+3irssUlAHkrS+4KomutmrRPfc9hr1KVg+
 sTAGfXqKmFkyp2w5KT10eeJa3q36qDHbEzmszam/u5ogydOsRUUXNE21iiA4225oMq/D
 gpTMFWWKBRUuyfhgLxsgyaiq0Cgtm1xrvJ9Yh99558VwaJry2EwwiQzeXuGj/fRiSGXv
 J75vuOrdjrYKBtbBKd00aYnpzHdDk5KveGZ4yHZtZ5qq67bt9JXyDxp46eAhUJKyhhsV
 xzEWHB5+v88HBuyS4QiV606h2SwfnUtYwfUjg4sI57fgGZ+L494dmo/4AnRK17HUCVcs
 LBVg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:references:in-reply-to:from:date
 :message-id:subject:to:cc;
 bh=5i/eOoqkuMHcJp5S023+WOW54IkS/l2JHoi9OkYmDps=;
 b=KTj1NOwV3mscRfPKbT7XpWyGrPFt1uNpALudXkBlFGy9aoL7tT5hr4RrkcaDld/Nol
 fZ80JbaSUlFdEoZEL5pM4aBySnJZIlby4Z3E1oLbuFym4ynuyzVOhAfVkbXd6hQDBzkL
 gc0LFPC8rZS09OMU1gGWQ4N/c3VmATx6plQMOHBg4lEVGok7oXkFyL+hnBwWK3ZSdRVn
 q/Yd/HY7MRENpRjMlARq+17NSWJdrao5/A0KxH41FxFbIyaCumwpPuSmzvHmya6371As
 8H1TrSgI2VN9b9NwzZzO5f4wgMnuUmDTvyOATHA1Kot+LqfrKANwKViqRF06YFC3Arxd
 HAjA==
X-Gm-Message-State: AOAM532kaU4yaP7yUdYw/j5GEawTweZO5MmLx0zghkOTnObvtjKS/l+3
 ixGbxFQ68ZsgsTg51y8TpY9tTkabnA3pKYC5zUU=
X-Google-Smtp-Source: ABdhPJzIiXgzin8T13e1+HbAgx1Gri8RASNfbyX7mblrNSTvdMCPUgzwl6xiaLeUGp62AKIYy8YUZc9IocxsF3E5pBM=
X-Received: by 2002:a65:5502:: with SMTP id f2mr8364860pgr.375.1594110657526; 
 Tue, 07 Jul 2020 01:30:57 -0700 (PDT)
MIME-Version: 1.0
References: <20200417202315.24133-1-felipe.huici@neclab.eu>
 <CAEX4t-NTYgzZ8PPkSLZEEODVnCs7=qP5cou5Gc8M8=A=b9zpDA@mail.gmail.com>
In-Reply-To: <CAEX4t-NTYgzZ8PPkSLZEEODVnCs7=qP5cou5Gc8M8=A=b9zpDA@mail.gmail.com>
From: George-Cristian Muraru <murarugeorgec@gmail.com>
Date: Tue, 7 Jul 2020 11:30:46 +0300
Message-ID: <CAEbyvw7=vbe6GOGR7inOypHRBx3tBgh97LTS6yfsWyEWJGWuaQ@mail.gmail.com>
Subject: Re: [UNIKRAFT/EIGEN PATCH] Prevent kludgeoning by barrier macro.
To: "felipehuici ." <felipehuici@gmail.com>
Content-Type: multipart/alternative; boundary="000000000000797eda05a9d5cfba"
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>, minios-devel@lists.xen.org
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

--000000000000797eda05a9d5cfba
Content-Type: text/plain; charset="UTF-8"

It looks good to me!

Reviewed-by: George Muraru <murarugeorgec@gmail.com>

On Fri, Apr 24, 2020 at 10:54 PM felipehuici . <felipehuici@gmail.com>
wrote:

> Hi,
>
> Please ignore this patch, the error was a result of my local set up.
>
> Thanks,
>
> -- Felipe
>
> On Fri, Apr 17, 2020 at 10:23 PM Felipe Huici <felipe.huici@neclab.eu>
> wrote:
> >
> > Add patch to prevent the definition of the macro "barrier" in lcpu.h
> > from kludgeoning the use of the word barrier in eigen code.
> >
> > Signed-off-by: Felipe Huici <felipe.huici@neclab.eu
> > ---
> >  patches/0002-prevent-barrier-macro-code-kludge.patch | 10 ++++++++++
> >  1 file changed, 10 insertions(+)
> >  create mode 100644 patches/0002-prevent-barrier-macro-code-kludge.patch
> >
> > diff --git a/patches/0002-prevent-barrier-macro-code-kludge.patch
> b/patches/0002-prevent-barrier-macro-code-kludge.patch
> > new file mode 100644
> > index 0000000..0b3fe78
> > --- /dev/null
> > +++ b/patches/0002-prevent-barrier-macro-code-kludge.patch
> > @@ -0,0 +1,10 @@
> > +--- a/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceThreadPool.h
> 2020-04-17 17:13:19.072796790 +0200
> > ++++ b/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceThreadPool.h
> 2021-04-17 17:13:41.800543414 +0200
> > +@@ -98,6 +98,7 @@
> > +       const char* src_ptr = static_cast<const char*>(src);
> > +       char* dst_ptr = static_cast<char*>(dst);
> > +       const size_t blocksize = (n + (num_threads - 1)) / num_threads;
> > ++#undef barrier
> > +       Barrier barrier(static_cast<int>(num_threads - 1));
> > +       // Launch the last 3 blocks on worker threads.
> > +       for (size_t i = 1; i < num_threads; ++i) {
> > --
> > 2.20.1
> >
> >
>
>

--000000000000797eda05a9d5cfba
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">It looks good to me!<div><br></div><div>Reviewed-by: Georg=
e Muraru &lt;<a href=3D"mailto:murarugeorgec@gmail.com">murarugeorgec@gmail=
.com</a>&gt;</div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" cla=
ss=3D"gmail_attr">On Fri, Apr 24, 2020 at 10:54 PM felipehuici . &lt;<a hre=
f=3D"mailto:felipehuici@gmail.com">felipehuici@gmail.com</a>&gt; wrote:<br>=
</div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;b=
order-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
Please ignore this patch, the error was a result of my local set up.<br>
<br>
Thanks,<br>
<br>
-- Felipe<br>
<br>
On Fri, Apr 17, 2020 at 10:23 PM Felipe Huici &lt;<a href=3D"mailto:felipe.=
huici@neclab.eu" target=3D"_blank">felipe.huici@neclab.eu</a>&gt; wrote:<br=
>
&gt;<br>
&gt; Add patch to prevent the definition of the macro &quot;barrier&quot; i=
n lcpu.h<br>
&gt; from kludgeoning the use of the word barrier in eigen code.<br>
&gt;<br>
&gt; Signed-off-by: Felipe Huici &lt;<a href=3D"mailto:felipe.huici@neclab.=
eu" target=3D"_blank">felipe.huici@neclab.eu</a><br>
&gt; ---<br>
&gt;=C2=A0 patches/0002-prevent-barrier-macro-code-kludge.patch | 10 ++++++=
++++<br>
&gt;=C2=A0 1 file changed, 10 insertions(+)<br>
&gt;=C2=A0 create mode 100644 patches/0002-prevent-barrier-macro-code-kludg=
e.patch<br>
&gt;<br>
&gt; diff --git a/patches/0002-prevent-barrier-macro-code-kludge.patch b/pa=
tches/0002-prevent-barrier-macro-code-kludge.patch<br>
&gt; new file mode 100644<br>
&gt; index 0000000..0b3fe78<br>
&gt; --- /dev/null<br>
&gt; +++ b/patches/0002-prevent-barrier-macro-code-kludge.patch<br>
&gt; @@ -0,0 +1,10 @@<br>
&gt; +--- a/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceThreadPool.h=C2=
=A0 =C2=A0 =C2=A0 2020-04-17 17:13:19.072796790 +0200<br>
&gt; ++++ b/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceThreadPool.h=C2=
=A0 =C2=A0 =C2=A0 2021-04-17 17:13:41.800543414 +0200<br>
&gt; +@@ -98,6 +98,7 @@<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0const char* src_ptr =3D static_cast&lt;con=
st char*&gt;(src);<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0char* dst_ptr =3D static_cast&lt;char*&gt;=
(dst);<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0const size_t blocksize =3D (n + (num_threa=
ds - 1)) / num_threads;<br>
&gt; ++#undef barrier<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0Barrier barrier(static_cast&lt;int&gt;(num=
_threads - 1));<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0// Launch the last 3 blocks on worker thre=
ads.<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0for (size_t i =3D 1; i &lt; num_threads; +=
+i) {<br>
&gt; --<br>
&gt; 2.20.1<br>
&gt;<br>
&gt;<br>
<br>
</blockquote></div>

--000000000000797eda05a9d5cfba--


From minios-devel-bounces@lists.xenproject.org Tue Jul 07 08:57:34 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 07 Jul 2020 08:57:34 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jsjPy-0003VH-5E; Tue, 07 Jul 2020 08:57:34 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Pb9O=AS=neclab.eu=simon.kuenzer@srs-us1.protection.inumbo.net>)
 id 1jsjPx-0003V8-4W
 for minios-devel@lists.xen.org; Tue, 07 Jul 2020 08:57:33 +0000
X-Inumbo-ID: e30a30ec-c02f-11ea-8d34-12813bfff9fa
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id e30a30ec-c02f-11ea-8d34-12813bfff9fa;
 Tue, 07 Jul 2020 08:57:30 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 09295103B70;
 Tue,  7 Jul 2020 10:57:29 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id FCFnpA37RNTb; Tue,  7 Jul 2020 10:57:28 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id D6B67103B50;
 Tue,  7 Jul 2020 10:57:28 +0200 (CEST)
Received: from puck.office.hd (192.168.24.91) by titania.office.hd
 (192.168.24.89) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 7 Jul 2020
 10:57:28 +0200
Received: from puck.office.hd ([192.168.126.12]) by puck.office.hd
 ([192.168.126.12]) with mapi id 15.01.1979.003; Tue, 7 Jul 2020 10:57:28
 +0200
From: Simon Kuenzer <simon.kuenzer@neclab.eu>
To: Alexander Jung <a.jung@lancs.ac.uk>, "minios-devel@lists.xen.org"
 <minios-devel@lists.xen.org>
Subject: Re: [UNIKRAFT/LIB-MUSL PATCH] math: Provide constants to Unikraft
Thread-Topic: [UNIKRAFT/LIB-MUSL PATCH] math: Provide constants to Unikraft
Thread-Index: AQHWTkhCQrNv6IQ2h0+W8QFtIiIBa6j73LaA
Date: Tue, 7 Jul 2020 08:57:28 +0000
Message-ID: <BCEFF7C5-B9DC-4ACA-AD12-D50D22A1E3AF@neclab.eu>
References: <20200629190357.24107-1-a.jung@lancs.ac.uk>
In-Reply-To: <20200629190357.24107-1-a.jung@lancs.ac.uk>
Accept-Language: en-GB, gl-ES, en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
user-agent: Microsoft-MacOutlook/10.10.17.200615
x-originating-ip: [192.168.24.96]
Content-Type: text/plain; charset="utf-8"
Content-ID: <78880F0B1544064381DAB03FA73782BB@office.hd>
Content-Transfer-Encoding: base64
MIME-Version: 1.0
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <Felipe.Huici@neclab.eu>,
 Gaulthier Gain <gaulthier.gain@uliege.be>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

SGV5IEFsZXgsDQoNCndoaWNoIHByb2dyYW0gaGFzIGFuIGlzc3VlIHdpdGggdGhpcz8gU2hvdWxk
bid0IGl0IGRlZmluZSBfWE9QRU5fU09VUkNFLCBfR05VX1NPVVJDRSwgb3IgX0JTRF9TT1VSQ0Ug
aW4gdGhlIHNvdXJjZXMgYmVmb3JlIGluY2x1ZGluZyA8bWF0aC5oPj8gSSB0aGluayB3ZSBzaG91
bGQgbm90IGNoYW5nZSB0aGlzIGxpYmMgc3RhbmRhcmQgc2luY2UgaXQgbWF5IGJyZWFrIG90aGVy
IHByb2dyYW1zLg0KDQpUaGFua3MsDQoNClNpbW9uDQoNCu+7v09uIDI5LjA2LjIwLCAyMTowNSwg
IkFsZXhhbmRlciBKdW5nIiA8YS5qdW5nQGxhbmNzLmFjLnVrPiB3cm90ZToNCg0KICAgIFRoaXMg
cGF0Y2ggbW9kaWZlcyB0aGUgbWF0aCBsaWJyYXJ5IHRvIHByb3ZpZGUgTWF0aGVtYXRpY2FsIGNv
bnN0YW50cw0KICAgIHN1Y2ggYXMgUGkgYW5kIGUgaW4gdGhlIGhlYWRlciA8bWF0aC5oPi4NCiAg
ICANCiAgICBTaWduZWQtb2ZmLWJ5OiBBbGV4YW5kZXIgSnVuZyA8YS5qdW5nQGxhbmNzLmFjLnVr
Pg0KICAgIC0tLQ0KICAgICAuLi4vMDAwOC1tYXRoLVByb3ZpZGUtY29uc3RhbnRzLXRvLVVuaWty
YWZ0LnBhdGNoICB8IDI5ICsrKysrKysrKysrKysrKysrKysrKysNCiAgICAgMSBmaWxlIGNoYW5n
ZWQsIDI5IGluc2VydGlvbnMoKykNCiAgICAgY3JlYXRlIG1vZGUgMTAwNjQ0IHBhdGNoZXMvMDAw
OC1tYXRoLVByb3ZpZGUtY29uc3RhbnRzLXRvLVVuaWtyYWZ0LnBhdGNoDQogICAgDQogICAgZGlm
ZiAtLWdpdCBhL3BhdGNoZXMvMDAwOC1tYXRoLVByb3ZpZGUtY29uc3RhbnRzLXRvLVVuaWtyYWZ0
LnBhdGNoIGIvcGF0Y2hlcy8wMDA4LW1hdGgtUHJvdmlkZS1jb25zdGFudHMtdG8tVW5pa3JhZnQu
cGF0Y2gNCiAgICBuZXcgZmlsZSBtb2RlIDEwMDY0NA0KICAgIGluZGV4IDAwMDAwMDAuLmJhNzI4
MmUNCiAgICAtLS0gL2Rldi9udWxsDQogICAgKysrIGIvcGF0Y2hlcy8wMDA4LW1hdGgtUHJvdmlk
ZS1jb25zdGFudHMtdG8tVW5pa3JhZnQucGF0Y2gNCiAgICBAQCAtMCwwICsxLDI5IEBADQogICAg
K0Zyb20gNGYxOTY0MzQ2YWFkNTEzODY5YTE1NDM4Njg4NDdhZGU3NjcxMzBlMiBNb24gU2VwIDE3
IDAwOjAwOjAwIDIwMDENCiAgICArRnJvbTogQWxleGFuZGVyIEp1bmcgPGFsZXhhbmRlci5qdW5n
QG5lY2xhYi5ldT4NCiAgICArRGF0ZTogTW9uLCAyOSBKdW4gMjAyMCAyMDo1MTozNCArMDIwMA0K
ICAgICtTdWJqZWN0OiBbUEFUQ0hdIG1hdGg6IFByb3ZpZGUgY29uc3RhbnRzIHRvIFVuaWtyYWZ0
DQogICAgKw0KICAgICtUaGlzIHBhdGNoIG1vZGlmZXMgdGhlIG1hdGggbGlicmFyeSB0byBwcm92
aWRlIE1hdGhlbWF0aWNhbCBjb25zdGFudHMNCiAgICArc3VjaCBhcyBQaSBhbmQgZSBpbiB0aGUg
aGVhZGVyIDxtYXRoLmg+Lg0KICAgICsNCiAgICArU2lnbmVkLW9mZi1ieTogQWxleGFuZGVyIEp1
bmcgPGFsZXhhbmRlci5qdW5nQG5lY2xhYi5ldT4NCiAgICArLS0tDQogICAgKyBpbmNsdWRlL21h
dGguaCB8IDIgKy0NCiAgICArIDEgZmlsZSBjaGFuZ2VkLCAxIGluc2VydGlvbigrKSwgMSBkZWxl
dGlvbigtKQ0KICAgICsNCiAgICArZGlmZiAtLWdpdCBhL2luY2x1ZGUvbWF0aC5oIGIvaW5jbHVk
ZS9tYXRoLmgNCiAgICAraW5kZXggNmFjOTFkYS4uZDk1ZTA2ZCAxMDA2NDQNCiAgICArLS0tIGEv
aW5jbHVkZS9tYXRoLmgNCiAgICArKysrIGIvaW5jbHVkZS9tYXRoLmgNCiAgICArQEAgLTM1NCw3
ICszNTQsNyBAQCBsb25nIGRvdWJsZSB0cnVuY2wobG9uZyBkb3VibGUpOw0KICAgICsgI2RlZmlu
ZSBNQVhGTE9BVCAgICAgICAgMy40MDI4MjM0NjYzODUyODg1OTgxMmUrMzhGDQogICAgKyAjZW5k
aWYNCiAgICArIA0KICAgICstI2lmIGRlZmluZWQoX1hPUEVOX1NPVVJDRSkgfHwgZGVmaW5lZChf
R05VX1NPVVJDRSkgfHwgZGVmaW5lZChfQlNEX1NPVVJDRSkNCiAgICArKyNpZiBkZWZpbmVkKF9f
VW5pa3JhZnRfXykNCiAgICArICNkZWZpbmUgTV9FICAgICAgICAgICAgIDIuNzE4MjgxODI4NDU5
MDQ1MjM1NCAgIC8qIGUgKi8NCiAgICArICNkZWZpbmUgTV9MT0cyRSAgICAgICAgIDEuNDQyNjk1
MDQwODg4OTYzNDA3NCAgIC8qIGxvZ18yIGUgKi8NCiAgICArICNkZWZpbmUgTV9MT0cxMEUgICAg
ICAgIDAuNDM0Mjk0NDgxOTAzMjUxODI3NjUgIC8qIGxvZ18xMCBlICovDQogICAgKy0tIA0KICAg
ICsyLjIwLjENCiAgICArDQogICAgLS0gDQogICAgMi4xMS4wDQogICAgDQogICAgDQogICAgDQoN
Cg==


From minios-devel-bounces@lists.xenproject.org Tue Jul 07 09:04:50 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 07 Jul 2020 09:04:50 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jsjWy-0004P4-PP; Tue, 07 Jul 2020 09:04:48 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BSZx=AS=lancaster.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jsjWx-0004Oz-I9
 for minios-devel@lists.xen.org; Tue, 07 Jul 2020 09:04:47 +0000
X-Inumbo-ID: e6b4819c-c030-11ea-8d34-12813bfff9fa
Received: from GBR01-LO2-obe.outbound.protection.outlook.com (unknown
 [40.107.10.131]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id e6b4819c-c030-11ea-8d34-12813bfff9fa;
 Tue, 07 Jul 2020 09:04:45 +0000 (UTC)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=gu6+q9LgIk9kymRVv30m5LxNYb51rS0w0mACd5RsX+jctxGXR58NayebQQxFAmoxI2ArSVqWRaXrTDzRfWiyYs4M1rEAMIGl2ACb82HB+IiCMiJ/copjc7IQNnGGKVDYG4uHQloarr20ZLOVFTEn7TiC/HGIdtu1aaI7dIMdIecuQaJF/jZwT370H4hIoeqKwsalrMa0h9A5RerR5kiyAewgkvaVP6e3t7FFxLjbnC1hiEED4xsGnjg1x5UTBkSdQvFrtiU3yMOQJPHEyyTk6WncnK8VVagf7A2lgOAtH0w5Jg9RDYzgZO48Gq82i36PElwgWSHxqGyEB+FGKI8BDg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; 
 s=arcselector9901;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=pCyVjQpj7aGaFU7UEwahhzA89dnT7y30UtZlCcrQStA=;
 b=FGpnnWXtIyDYw8QQTgkSO+vs3vQhfAX2sq2IoK5GLDt7sg5V8uEy/tIStX1eFT2hzPxU1KvvBoL85ICJOkPvOZ7x4BvrBqeDwz6gIZtes/hLsyR94/z4LrI0Aqvcx99dZ0EwnVat28PTBozmN5byW90ld+hGx1CcqTdRwRjfVacSI98GFWdscjO93I8Nxa2uzbs8dZi7VmWEmWglj06Li1XyPa3qMxge/43p/J+Jw0b6i2phfZ/PnsQjKtZr/F1Y/QHXxaze4WzAn7u4jaRNjnWGhxtjZSAOO2v4X08oCbnUV4aqywo+xs66Bs1Ce5OeS1SbTbRmk2OZx9rqa9pMfA==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
 smtp.mailfrom=lancaster.ac.uk; dmarc=pass action=none
 header.from=lancaster.ac.uk; dkim=pass header.d=lancaster.ac.uk; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=livelancsac.onmicrosoft.com; s=selector2-livelancsac-onmicrosoft-com;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=pCyVjQpj7aGaFU7UEwahhzA89dnT7y30UtZlCcrQStA=;
 b=e7R4GHNZAzSXXzn2+7Mzu9BPvSee0yKeautGSVLUkQDj+yvSCWo0Surbixy1IPfgTDUx1oH6iFY7PJ/Zuq1pKNkdbO++acgq+58QHZIXj1jHEfQzVw/gqgDg6owWUs8ERISiCE70hltHToj0Xt6pEIdcA5biwd46Jo9cUILFYos=
Received: from CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM (2603:10a6:401:17::15)
 by CWXP265MB2006.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:7d::10) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.22; Tue, 7 Jul
 2020 09:04:43 +0000
Received: from CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM
 ([fe80::fcde:79b:21d6:5203]) by CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM
 ([fe80::fcde:79b:21d6:5203%4]) with mapi id 15.20.3174.020; Tue, 7 Jul 2020
 09:04:43 +0000
From: "Jung, Alexander" <a.jung@lancaster.ac.uk>
To: Simon Kuenzer <simon.kuenzer@neclab.eu>, "minios-devel@lists.xen.org"
 <minios-devel@lists.xen.org>
Subject: Re: [UNIKRAFT/LIB-MUSL PATCH] math: Provide constants to Unikraft
Thread-Topic: [UNIKRAFT/LIB-MUSL PATCH] math: Provide constants to Unikraft
Thread-Index: AQHWVD2niUaigKlxE0WqUaqlIxUjWQ==
Date: Tue, 7 Jul 2020 09:04:43 +0000
Message-ID: <5BEE78B9-3E0F-45DA-86B8-0499DF5091A9@lancaster.ac.uk>
References: <20200629190357.24107-1-a.jung@lancs.ac.uk>
 <BCEFF7C5-B9DC-4ACA-AD12-D50D22A1E3AF@neclab.eu>
In-Reply-To: <BCEFF7C5-B9DC-4ACA-AD12-D50D22A1E3AF@neclab.eu>
Accept-Language: en-GB, en-US
Content-Language: en-GB
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
user-agent: Microsoft-MacOutlook/16.38.20061401
authentication-results: neclab.eu; dkim=none (message not signed)
 header.d=none;neclab.eu; dmarc=none action=none header.from=lancaster.ac.uk;
x-originating-ip: [77.190.158.193]
x-ms-publictraffictype: Email
x-ms-office365-filtering-correlation-id: 38a35e88-511d-4671-7616-08d82254ca02
x-ms-traffictypediagnostic: CWXP265MB2006:
x-microsoft-antispam-prvs: <CWXP265MB2006F5F40871E63921DD115CCE660@CWXP265MB2006.GBRP265.PROD.OUTLOOK.COM>
x-ms-oob-tlc-oobclassifiers: OLM:9508;
x-forefront-prvs: 0457F11EAF
x-ms-exchange-senderadcheck: 1
x-microsoft-antispam: BCL:0;
x-microsoft-antispam-message-info: XS5U3ePCo1g4yGr+c8fnZ3EIXC1hAwsf65QEfE64tw9zzc9bmv+43rgcJaeXal5xC+3e9GtSvYDNS3XhgQo30DIh74oktoTsmP6ZhcTZvcqdnhBmeX+O+pqgDs4toOep40osq0Mf/UlN19IwpzkMGktHcWBBFjxBigRpyPobPhyhHzggpeHtTgzMOgMFQ371sD7utuk4dMRtnC+QWiygbrvSSTLfURD3yhh8eOHzlcQvGdEBQ55pYI/p9kqaviRFT6nKkamw75UHbjfKhoXSeLdwdPwkHt/N/c601tFTT1qfuakHhPxI5N9+p3bdi/y3xSg3zDprvA/QDtpmBVNmxA==
x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
 IPV:NLI; SFV:NSPM; H:CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM; PTR:; CAT:NONE;
 SFTY:;
 SFS:(4636009)(39860400002)(136003)(346002)(376002)(396003)(366004)(8936002)(6512007)(54906003)(33656002)(786003)(91956017)(26005)(6506007)(76116006)(71200400001)(19627235002)(36756003)(83380400001)(66946007)(66476007)(64756008)(66556008)(66446008)(2616005)(6486002)(316002)(2906002)(186003)(4326008)(5660300002)(8676002)(86362001)(478600001)(110136005);
 DIR:OUT; SFP:1102; 
x-ms-exchange-antispam-messagedata: 5WsSvEGw5id8eTG80ec2gRzzKrpjtyUPT51A3OWkc/+tRdu3bmEt95pthLj9ePylEIOLoamZzLUji841xoIxbBRwprC7Qr/i63oJUapVJ/KhTvpW9PEY4tYXMWCIiRn60mVX1bUAWbrFQIGoNNX4ZZc3JTQuoGpNbzoPm80MJ9TWTiQ287gU6OZn7quMyAJUxL/kQMBZPiHdsJTdzh+SlAWSeYoPK9k2Aad1RzI3L9KmadwN0rQhiYFRdIfYfYvd3079pQKcW5ntBgd0PCX03wNMOd+LGT6vBA9eseVClgj4iXZf67q4BlvSuI5D7U9dsnO5MNBlOnW7UXLjr7dUKFy25Qx+rK+RdRI6CU0tCMhgh/WrSgDbj/QgYgk/l0hMJokaBkycBi4W78eNMcmscH9jkXM1HT4b0tLyN9dPbHPkMqFAhOzAhlUbLldr2KMM0pVLTrIX/gaL7HlLEF6FGS7KFl0qLHm7mEEX7A3+1bT7UDdPurSvrtls/mpR84g8
x-ms-exchange-transport-forked: True
Content-Type: text/plain; charset="utf-8"
Content-ID: <FAD97E0548BCD8489AD01594AB38DF28@GBRP265.PROD.OUTLOOK.COM>
Content-Transfer-Encoding: base64
MIME-Version: 1.0
X-OriginatorOrg: lancaster.ac.uk
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM
X-MS-Exchange-CrossTenant-Network-Message-Id: 38a35e88-511d-4671-7616-08d82254ca02
X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Jul 2020 09:04:43.4151 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 9c9bcd11-977a-4e9c-a9a0-bc734090164a
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: uZycngmsxOLNE/Hx37JgO0Fk7Pux8Zt8PqpMS7Gh/BhhyiIpZz9McCUYyl/nWmjnqHFCn8G2lmW/cvuQZNFjaQ==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWXP265MB2006
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <Felipe.Huici@neclab.eu>,
 Gaulthier Gain <gaulthier.gain@uliege.be>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

SGksDQoNCkkgd2FzIHRyeWluZyB0byBjb21waWxlIHRoZSBtYXRocyBsaWJyYXJ5IGZyb20gbXVz
bCB3aGVuIHRoaXMgZXJyb3Igb2NjdXJyZWQ6DQoNCi9yb290L3dvcmtzcGFjZS91bmlrcmFmdC9h
cHBzL2FwcC9idWlsZC9saWJtdXNsL29yaWdpbi9tdXNsLTEuMS4xOS8vc3JjL21hdGgvY29zZi5j
OjIxOjEyOiBlcnJvcjog4oCYTV9QSV8y4oCZIHVuZGVjbGFyZWQgaGVyZSAobm90IGluIGEgZnVu
Y3Rpb24pDQpjMXBpbzIgPSAxKk1fUElfMiwgLyogMHgzRkY5MjFGQiwgMHg1NDQ0MkQxOCAqLw0K
ICAgICAgICAgICBefn5+fn4NCg0KVGhpcyBjb25zdGFudCBpcyBvbmx5IHByb3ZpZGVkIHdoZW4g
b25lIG9mIHRob3NlIGRlZmluaXRpb25zIGFyZSBwcm92aWRlZCwgYnV0IEkgY2FuIHNpbXBseSBk
ZWZpbmUgdGhlbSBpZiB0aGlzIGlzIHRoZSBiZXR0ZXIgYXBwcm9hY2guDQoNClRoYW5rcywNCg0K
QWxleA0KDQrvu79PbiAwNy4wNy4yMCwgMTA6NTgsICJNaW5pb3MtZGV2ZWwgb24gYmVoYWxmIG9m
IFNpbW9uIEt1ZW56ZXIiIDxtaW5pb3MtZGV2ZWwtYm91bmNlc0BsaXN0cy54ZW5wcm9qZWN0Lm9y
ZyBvbiBiZWhhbGYgb2Ygc2ltb24ua3VlbnplckBuZWNsYWIuZXU+IHdyb3RlOg0KDQogICAgSGV5
IEFsZXgsDQoNCg0KDQogICAgd2hpY2ggcHJvZ3JhbSBoYXMgYW4gaXNzdWUgd2l0aCB0aGlzPyBT
aG91bGRuJ3QgaXQgZGVmaW5lIF9YT1BFTl9TT1VSQ0UsIF9HTlVfU09VUkNFLCBvciBfQlNEX1NP
VVJDRSBpbiB0aGUgc291cmNlcyBiZWZvcmUgaW5jbHVkaW5nIDxtYXRoLmg+PyBJIHRoaW5rIHdl
IHNob3VsZCBub3QgY2hhbmdlIHRoaXMgbGliYyBzdGFuZGFyZCBzaW5jZSBpdCBtYXkgYnJlYWsg
b3RoZXIgcHJvZ3JhbXMuDQoNCiAgICBUaGFua3MsDQoNCiAgICBTaW1vbg0KDQogICAg77u/T24g
MjkuMDYuMjAsIDIxOjA1LCAiQWxleGFuZGVyIEp1bmciIDxhLmp1bmdAbGFuY3MuYWMudWs+IHdy
b3RlOg0KDQogICAgICAgIFRoaXMgcGF0Y2ggbW9kaWZlcyB0aGUgbWF0aCBsaWJyYXJ5IHRvIHBy
b3ZpZGUgTWF0aGVtYXRpY2FsIGNvbnN0YW50cw0KICAgICAgICBzdWNoIGFzIFBpIGFuZCBlIGlu
IHRoZSBoZWFkZXIgPG1hdGguaD4uDQoNCiAgICAgICAgU2lnbmVkLW9mZi1ieTogQWxleGFuZGVy
IEp1bmcgPGEuanVuZ0BsYW5jcy5hYy51az4NCiAgICAgICAgLS0tDQogICAgICAgICAuLi4vMDAw
OC1tYXRoLVByb3ZpZGUtY29uc3RhbnRzLXRvLVVuaWtyYWZ0LnBhdGNoICB8IDI5ICsrKysrKysr
KysrKysrKysrKysrKysNCiAgICAgICAgIDEgZmlsZSBjaGFuZ2VkLCAyOSBpbnNlcnRpb25zKCsp
DQogICAgICAgICBjcmVhdGUgbW9kZSAxMDA2NDQgcGF0Y2hlcy8wMDA4LW1hdGgtUHJvdmlkZS1j
b25zdGFudHMtdG8tVW5pa3JhZnQucGF0Y2gNCg0KICAgICAgICBkaWZmIC0tZ2l0IGEvcGF0Y2hl
cy8wMDA4LW1hdGgtUHJvdmlkZS1jb25zdGFudHMtdG8tVW5pa3JhZnQucGF0Y2ggYi9wYXRjaGVz
LzAwMDgtbWF0aC1Qcm92aWRlLWNvbnN0YW50cy10by1VbmlrcmFmdC5wYXRjaA0KICAgICAgICBu
ZXcgZmlsZSBtb2RlIDEwMDY0NA0KICAgICAgICBpbmRleCAwMDAwMDAwLi5iYTcyODJlDQogICAg
ICAgIC0tLSAvZGV2L251bGwNCiAgICAgICAgKysrIGIvcGF0Y2hlcy8wMDA4LW1hdGgtUHJvdmlk
ZS1jb25zdGFudHMtdG8tVW5pa3JhZnQucGF0Y2gNCiAgICAgICAgQEAgLTAsMCArMSwyOSBAQA0K
ICAgICAgICArRnJvbSA0ZjE5NjQzNDZhYWQ1MTM4NjlhMTU0Mzg2ODg0N2FkZTc2NzEzMGUyIE1v
biBTZXAgMTcgMDA6MDA6MDAgMjAwMQ0KICAgICAgICArRnJvbTogQWxleGFuZGVyIEp1bmcgPGFs
ZXhhbmRlci5qdW5nQG5lY2xhYi5ldT4NCiAgICAgICAgK0RhdGU6IE1vbiwgMjkgSnVuIDIwMjAg
MjA6NTE6MzQgKzAyMDANCiAgICAgICAgK1N1YmplY3Q6IFtQQVRDSF0gbWF0aDogUHJvdmlkZSBj
b25zdGFudHMgdG8gVW5pa3JhZnQNCiAgICAgICAgKw0KICAgICAgICArVGhpcyBwYXRjaCBtb2Rp
ZmVzIHRoZSBtYXRoIGxpYnJhcnkgdG8gcHJvdmlkZSBNYXRoZW1hdGljYWwgY29uc3RhbnRzDQog
ICAgICAgICtzdWNoIGFzIFBpIGFuZCBlIGluIHRoZSBoZWFkZXIgPG1hdGguaD4uDQogICAgICAg
ICsNCiAgICAgICAgK1NpZ25lZC1vZmYtYnk6IEFsZXhhbmRlciBKdW5nIDxhbGV4YW5kZXIuanVu
Z0BuZWNsYWIuZXU+DQogICAgICAgICstLS0NCiAgICAgICAgKyBpbmNsdWRlL21hdGguaCB8IDIg
Ky0NCiAgICAgICAgKyAxIGZpbGUgY2hhbmdlZCwgMSBpbnNlcnRpb24oKyksIDEgZGVsZXRpb24o
LSkNCiAgICAgICAgKw0KICAgICAgICArZGlmZiAtLWdpdCBhL2luY2x1ZGUvbWF0aC5oIGIvaW5j
bHVkZS9tYXRoLmgNCiAgICAgICAgK2luZGV4IDZhYzkxZGEuLmQ5NWUwNmQgMTAwNjQ0DQogICAg
ICAgICstLS0gYS9pbmNsdWRlL21hdGguaA0KICAgICAgICArKysrIGIvaW5jbHVkZS9tYXRoLmgN
CiAgICAgICAgK0BAIC0zNTQsNyArMzU0LDcgQEAgbG9uZyBkb3VibGUgdHJ1bmNsKGxvbmcgZG91
YmxlKTsNCiAgICAgICAgKyAjZGVmaW5lIE1BWEZMT0FUICAgICAgICAzLjQwMjgyMzQ2NjM4NTI4
ODU5ODEyZSszOEYNCiAgICAgICAgKyAjZW5kaWYNCiAgICAgICAgKyANCiAgICAgICAgKy0jaWYg
ZGVmaW5lZChfWE9QRU5fU09VUkNFKSB8fCBkZWZpbmVkKF9HTlVfU09VUkNFKSB8fCBkZWZpbmVk
KF9CU0RfU09VUkNFKQ0KICAgICAgICArKyNpZiBkZWZpbmVkKF9fVW5pa3JhZnRfXykNCiAgICAg
ICAgKyAjZGVmaW5lIE1fRSAgICAgICAgICAgICAyLjcxODI4MTgyODQ1OTA0NTIzNTQgICAvKiBl
ICovDQogICAgICAgICsgI2RlZmluZSBNX0xPRzJFICAgICAgICAgMS40NDI2OTUwNDA4ODg5NjM0
MDc0ICAgLyogbG9nXzIgZSAqLw0KICAgICAgICArICNkZWZpbmUgTV9MT0cxMEUgICAgICAgIDAu
NDM0Mjk0NDgxOTAzMjUxODI3NjUgIC8qIGxvZ18xMCBlICovDQogICAgICAgICstLSANCiAgICAg
ICAgKzIuMjAuMQ0KICAgICAgICArDQogICAgICAgIC0tIA0KICAgICAgICAyLjExLjANCg0KDQoN
Cg0KDQo=


From minios-devel-bounces@lists.xenproject.org Tue Jul 07 11:01:23 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 07 Jul 2020 11:01:23 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jslLk-00076y-Vc; Tue, 07 Jul 2020 11:01:20 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=pDl4=AS=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jslLj-00076t-Ju
 for minios-devel@lists.xen.org; Tue, 07 Jul 2020 11:01:19 +0000
X-Inumbo-ID: 2e973c9c-c041-11ea-8d4e-12813bfff9fa
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 2e973c9c-c041-11ea-8d4e-12813bfff9fa;
 Tue, 07 Jul 2020 11:01:18 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 0B613103B70;
 Tue,  7 Jul 2020 13:01:17 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id KoIAX80cn_AR; Tue,  7 Jul 2020 13:01:16 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id D0FD9103B50
 for <minios-devel@lists.xen.org>; Tue,  7 Jul 2020 13:01:16 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 7 Jul 2020
 13:01:16 +0200
Message-ID: <1594119675.4397.9.camel@neclab.eu>
Subject: Re: [UNIKRAFT/LIBLWIP PATCH v2 1/3] lib/lwip: Reserve per netdev
 space for lwip
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Sharan Santhanam <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
Date: Tue, 7 Jul 2020 13:01:15 +0200
In-Reply-To: <20200630111535.7877-2-sharan.santhanam@neclab.eu>
References: <20200630111535.7877-1-sharan.santhanam@neclab.eu>
 <20200630111535.7877-2-sharan.santhanam@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Sharan,

thanks a lot for this patch. Having a little bit more documentation
would be nice since this is a non-trivial feature. Comments inline.

regards,
Hugo

On Tue, 2020-06-30 at 13:15 +0200, Sharan Santhanam wrote:
> Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>

I think that a commit message is important here; the purpose of the
scratch pad is not evident. e.g.,

Reserve per-network-device (netdev) space for lwip. This will be later
used to store netdev specific information such as the support of
interrupts. Relying on uknetdev's scratch pad allows us to store this
information contiguously for all devices in the same portion of memory,
thus reducing potential cache and tlb pressure.

> ---
> Â Config.ukÂ Â Â | 7 +++++++
> Â Makefile.uk | 1 +
> Â 2 files changed, 8 insertions(+)
> 
> diff --git a/Config.uk b/Config.uk
> index aaaaae0..d9bd2c8 100644
> --- a/Config.uk
> +++ b/Config.uk
> @@ -22,6 +22,13 @@ config LWIP_UKNETDEV
> Â 		In case threaded mode is selected and the underlying
> device
> Â 		driver does not support receive interrupts the
> network
> Â 		interfaces have to be polled manually
> (uknetdev_poll()).
> +
> +config LWIP_UKNETDEV_SCRATCH
> +	int
> +	default 24
> +	help
> +		The network stack reserves space in the uknetdev
> device for its
> +		use.
> Â endmenu
> Â 

While this option is not present in the menuconfig (invisible), users
can still change it manually in their configuration (or rely on
outdated configuration data!). The help should definitely mention
thatÂ LWIP_UKNETDEV_SCRATCH needs to remain big enough to store lwip's
internal data, and that reducing this without further adaptations to
the glue code will result in undefined behavior and potentially non-
functional unikernels.

> Â config LWIP_AUTOIFACE
> diff --git a/Makefile.uk b/Makefile.uk
> index d3c6c9c..99005a9 100644
> --- a/Makefile.uk
> +++ b/Makefile.uk
> @@ -62,6 +62,7 @@ LIBLWIP_COMMON_INCLUDES-y +=
> -I$(LIBLWIP_BASE)/musl-imported/include
> Â LIBLWIP_COMMON_INCLUDES-y += -I$(LIBLWIP_EXTRACTED)/include
> Â CINCLUDES-$(CONFIG_LIBLWIP)Â Â Â += $(LIBLWIP_COMMON_INCLUDES-y)
> Â CXXINCLUDES-$(CONFIG_LIBLWIP) += $(LIBLWIP_COMMON_INCLUDES-y)
> +$(eval $(call uknetdev_scratch_mem,$(CONFIG_LWIP_UKNETDEV_SCRATCH)))
> Â 
> Â ####################################################################
> ############
> Â # Library flags


From minios-devel-bounces@lists.xenproject.org Tue Jul 07 11:18:06 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 07 Jul 2020 11:18:06 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jslbw-000836-Iq; Tue, 07 Jul 2020 11:18:04 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=pDl4=AS=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jslbv-00082m-D7
 for minios-devel@lists.xen.org; Tue, 07 Jul 2020 11:18:03 +0000
X-Inumbo-ID: 849c4d7e-c043-11ea-8496-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 849c4d7e-c043-11ea-8496-bc764e2007e4;
 Tue, 07 Jul 2020 11:18:01 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 8BF80F2008;
 Tue,  7 Jul 2020 13:18:00 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 316LORZyqUfW; Tue,  7 Jul 2020 13:18:00 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 643F3F2001
 for <minios-devel@lists.xen.org>; Tue,  7 Jul 2020 13:17:58 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 7 Jul 2020
 13:17:57 +0200
Message-ID: <1594120677.4397.21.camel@neclab.eu>
Subject: Re: [UNIKRAFT/LIBLWIP PATCH v2 2/3] lib/lwip: Fetch features
 supported on the netdev
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Sharan Santhanam <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
Date: Tue, 7 Jul 2020 13:17:57 +0200
In-Reply-To: <20200630111535.7877-3-sharan.santhanam@neclab.eu>
References: <20200630111535.7877-1-sharan.santhanam@neclab.eu>
 <20200630111535.7877-3-sharan.santhanam@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: titania.office.hd (192.168.24.89) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Sharan,

thanks for this patch. Here too, a little bit more documentation would
be nice. Comments inline.

regards,
Hugo

On Tue, 2020-06-30 at 13:15 +0200, Sharan Santhanam wrote:
> Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
> ---
> Â uknetdev.c | 11 +++++++++++
> Â 1 file changed, 11 insertions(+)
> 
> diff --git a/uknetdev.c b/uknetdev.c
> index 7047352..ef57014 100644
> --- a/uknetdev.c
> +++ b/uknetdev.c
> @@ -62,6 +62,10 @@
> Â #define UKNETDEV_NETIF_NAME0 'e'
> Â #define UKNETDEV_NETIF_NAME1 'n'
> Â 
> +struct lwip_netdev_data {
> +	uint32_t features;
> +};
> +
> Â /*
> Â  * Global headroom settings for buffer allocations used on receive
> Â  * and transmit. We are taking the maximum of all uknetdev devices
> as
> @@ -372,6 +376,7 @@ err_t uknetdev_init(struct netif *nf)
> Â 	struct uk_netdev_rxqueue_conf rxq_conf;
> Â 	struct uk_netdev_txqueue_conf txq_conf;
> Â 	struct uk_netdev_info info;
> +	struct lwip_netdev_data *lwip_data;
> Â 	const struct uk_hwaddr *hwaddr;
> Â 	unsigned int i;
> Â 	int ret;
> @@ -379,6 +384,11 @@ err_t uknetdev_init(struct netif *nf)
> Â 	UK_ASSERT(nf);
> Â 	dev = netif_to_uknetdev(nf);
> Â 	UK_ASSERT(dev);
> +#if CONFIG_UK_NETDEV_SCRATCH_SIZE < CONFIG_LWIP_UKNETDEV_SCRATCH
> +#error "Insufficient Scratch memory"

This is not supposed to happen, right? Having a comment about this here
would be nice:

/* This should not happen. CONFIG_UK_NETDEV_SCRATCH_SIZE is configured as the max of all scratch pad requirements by the Makefile macro uknetdev_scratch_mem. */

> +#endif
> +
> +	lwip_data = (struct lwip_netdev_data *)dev->scratch_pad;

I don't really like the idea that an outdated
CONFIG_LWIP_UKNETDEV_SCRATCH could lead to insufficient scratch pad
size. This is going to create a lot of trouble if users rely on
outdated config data (this is a realistic case, right?).

What about a compile time guard that checks the size ofÂ struct
lwip_netdev_data and makes sure thatÂ CONFIG_LWIP_UKNETDEV_SCRATCH is
big enough?

In any case, there should be a comment about this here I think. :-)

> Â 
> Â 	LWIP_ASSERT("uknetdev needs an input callback (netif_input
> or tcpip_input)",
> Â 		Â Â Â Â nf->input != NULL);
> @@ -411,6 +421,7 @@ err_t uknetdev_init(struct netif *nf)
> Â 	uk_netdev_info_get(dev, &info);
> Â 	if (!info.max_rx_queues || !info.max_tx_queues)
> Â 		return ERR_IF;
> +	lwip_data->features = info.features;
> Â 
> Â 	/*
> Â 	Â * Update our global (rx|tx)_headroom setting that we use
> for


From minios-devel-bounces@lists.xenproject.org Tue Jul 07 11:21:08 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 07 Jul 2020 11:21:08 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jslet-0000Of-RN; Tue, 07 Jul 2020 11:21:07 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=/lBA=AS=gmail.com=felix.nasch@srs-us1.protection.inumbo.net>)
 id 1jsles-0000Oa-K4
 for minios-devel@lists.xen.org; Tue, 07 Jul 2020 11:21:06 +0000
X-Inumbo-ID: f2c113a2-c043-11ea-b7bb-bc764e2007e4
Received: from mail-wm1-x329.google.com (unknown [2a00:1450:4864:20::329])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id f2c113a2-c043-11ea-b7bb-bc764e2007e4;
 Tue, 07 Jul 2020 11:21:06 +0000 (UTC)
Received: by mail-wm1-x329.google.com with SMTP id g10so1527329wmc.1
 for <minios-devel@lists.xen.org>; Tue, 07 Jul 2020 04:21:06 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:from:date:message-id:subject:to;
 bh=bxtyhGGmPacNi+8ml8ryCsLsv5aLbyy/D0tqVkmW5x4=;
 b=O7MYMQSQ0TXTUeMKZB9xu6cnBHU5X8nbIH203xsgCVTAn3wcI1u1af0Sm/xGrEmWvK
 CDg5F1AOiJ2btFgau5jN4BGNSUUeAjDeiHKkZA9qaGfj1odKFVyc0TTplIkXF+xnpO7z
 ZoaMG8HBR6vRF5lDVDkQID0VdDI34Cvy1zK/B7OojPWhfzBccRA1zZjziG2hpORkuTHS
 So+8+fdpMdL38X6ZNwzKzGlQIFrSxY/B1QAUpv5yWo0q02JuBsBFKpWFAvIvqLWSMSe7
 v8BD+qaE3Zfrq1O/ei+7whgQIX8r9pBbqCpbtFo45HK+uqUExLcT8LMKRv/S4dDMccc1
 29aA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
 bh=bxtyhGGmPacNi+8ml8ryCsLsv5aLbyy/D0tqVkmW5x4=;
 b=B2jGoEW4NAz40akiL1TCYPYMOihMxY0czrHxdolR7qC4BZ8XwDFUU/lGhzjaaicDnV
 hsFqhAJN7/LmUpmSyjmcF4UOD2LT6L9Xknw8ttpIoBPCZ1u5FkPZ2JkIqrnu6p5RVK1H
 F9CN3gkb5UFjrFQ0iSJi+0PFgAJXGxmdym6aIPFvIlQMlVNIhij8WFAfFKv41Vfbk86u
 uWBRdqyNxXp3zhG0CF5NWCBZOSxL67kDCnDICNaEAD6oN8F2CnR2wFFNgvWZ8PiXHmIA
 H7Jqp9K8miZSxqRvWUqlHwC5JkihSkBTS36wgOmlY6SmRGxb3iqzyMqVE8EFT7lc0kjA
 TefQ==
X-Gm-Message-State: AOAM5334JnwUa6M/SGGHMmU2xIjk916qIW21FmB2TS4B8bLCO0sKg6pQ
 dEBFsNZXT4XJ0K5TBZDjeqIHkiRsy0XM6IGctqBd3XVL
X-Google-Smtp-Source: ABdhPJx/qJdn1u0iuNgqNc6J+4/eM/t9tS3q1kI7pfRDSSsnv3P1jJchphBurfNw8BfxKE/xCel21ZsvEgVm77RWVJc=
X-Received: by 2002:a1c:7306:: with SMTP id d6mr3479284wmb.113.1594120864706; 
 Tue, 07 Jul 2020 04:21:04 -0700 (PDT)
MIME-Version: 1.0
From: felix nasch <felix.nasch@gmail.com>
Date: Tue, 7 Jul 2020 13:20:54 +0200
Message-ID: <CAMEmTtXANxmphAj8tOmcqjdHzEqwEzJuY=Se0FbFdMwDvRQFFg@mail.gmail.com>
Subject: Unikraft makefile - how to copy files in Makefile.uk
To: minios-devel@lists.xen.org
Content-Type: text/plain; charset="UTF-8"
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi,

I was hanging out in the IRC channel, but it seems inactive, so I am
asking here, hope that's ok. :)
I am trying to port a library to Unikraft, and as part of the build process I
want to copy around a few files after extracting the source files.
This is to solve these two problems:

1. Some source files have the same name (in different dirs), but the
    unikraft build system places all .obj files into the root directory, thus
    colliding object files overwrite each other.  I want to rename conflicting
    files prior to compilation.

2. Include paths - when extracting the source package, the include path is not
    how consumers of the library expect it. I would want to create an
appropriately
    named subdir and move the header files into it.

However, I can't figure out how to execute a simple "cp <src> <dest>"
in Makefile.uk, since new targets cannot be defined.

How can I do that?

Thanks,
f.


From minios-devel-bounces@lists.xenproject.org Tue Jul 07 11:59:36 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 07 Jul 2020 11:59:36 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jsmG4-0003iv-U9; Tue, 07 Jul 2020 11:59:32 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=WBcW=AS=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jsmG3-0003iq-5t
 for minios-devel@lists.xenproject.org; Tue, 07 Jul 2020 11:59:31 +0000
X-Inumbo-ID: 4fd790a2-c049-11ea-8d56-12813bfff9fa
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 4fd790a2-c049-11ea-8d56-12813bfff9fa;
 Tue, 07 Jul 2020 11:59:30 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id F0DBB10394D;
 Tue,  7 Jul 2020 13:59:28 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 5uVLc6CktWP1; Tue,  7 Jul 2020 13:59:28 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id CCC31101E65
 for <minios-devel@lists.xenproject.org>; Tue,  7 Jul 2020 13:59:28 +0200 (CEST)
Received: from [10.7.1.9] (192.168.24.96) by puck.office.hd (192.168.24.91)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 7 Jul 2020
 13:59:28 +0200
Subject: Re: Unikraft makefile - how to copy files in Makefile.uk
To: <minios-devel@lists.xenproject.org>
References: <CAMEmTtXANxmphAj8tOmcqjdHzEqwEzJuY=Se0FbFdMwDvRQFFg@mail.gmail.com>
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
Message-ID: <714bbaaf-be90-b61d-89a7-731f0de18f26@neclab.eu>
Date: Tue, 7 Jul 2020 13:59:27 +0200
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.8.0
MIME-Version: 1.0
In-Reply-To: <CAMEmTtXANxmphAj8tOmcqjdHzEqwEzJuY=Se0FbFdMwDvRQFFg@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"; format=flowed
Content-Transfer-Encoding: 7bit
Content-Language: en-US
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hello,

Please find the comment inline:

On 7/7/20 1:20 PM, felix nasch wrote:
> Hi,
>
> I was hanging out in the IRC channel, but it seems inactive, so I am
> asking here, hope that's ok. :)
> I am trying to port a library to Unikraft, and as part of the build process I
> want to copy around a few files after extracting the source files.
> This is to solve these two problems:
>
> 1. Some source files have the same name (in different dirs), but the
>      unikraft build system places all .obj files into the root directory, thus
>      colliding object files overwrite each other.  I want to rename conflicting
>      files prior to compilation.

Our approach to solve the problem, has been to resolve name collision 
with a '|' directive. The '|' would prepend the object file with the 
name following the pipe.

For eg, if you look at the Makefile.uk in plat/kvm/

LIBKVMPLAT_SRCS-$(CONFIG_ARCH_X86_64) += 
$(UK_PLAT_COMMON_BASE)/x86/trace.c|common

LIBKVMPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBKVMPLAT_BASE)/x86/trace.c


>
> 2. Include paths - when extracting the source package, the include path is not
>      how consumers of the library expect it. I would want to create an
> appropriately
>      named subdir and move the header files into it.
>
> However, I can't figure out how to execute a simple "cp <src> <dest>"
> in Makefile.uk, since new targets cannot be defined.:

This is a feature we do not support yet. If you believe the problem is 
very specific to a single library, you can do something like [1].

[1] https://github.com/unikraft/lib-lua/blob/master/Makefile.uk 
<https://github.com/unikraft/lib-lua/blob/master/Makefile.uk>


>
> How can I do that?
>
> Thanks,
> f.
>


From minios-devel-bounces@lists.xenproject.org Tue Jul 07 14:08:24 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 07 Jul 2020 14:08:24 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jsoGj-0002Px-Sb; Tue, 07 Jul 2020 14:08:21 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=pDl4=AS=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jsoGi-0002PE-RW
 for minios-devel@lists.xen.org; Tue, 07 Jul 2020 14:08:20 +0000
X-Inumbo-ID: 4e564b58-c05b-11ea-8d79-12813bfff9fa
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 4e564b58-c05b-11ea-8d79-12813bfff9fa;
 Tue, 07 Jul 2020 14:08:18 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 4B416103AE3;
 Tue,  7 Jul 2020 16:08:17 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 93pifH6LSNWB; Tue,  7 Jul 2020 16:08:17 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id 24A9C10394D
 for <minios-devel@lists.xen.org>; Tue,  7 Jul 2020 16:08:17 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 7 Jul 2020
 16:08:16 +0200
Message-ID: <1594130830.4397.30.camel@neclab.eu>
Subject: Re: [UNIKRAFT PATCH v2 14/15] plat/tap: Support tap_netdev_xmit
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Sharan Santhanam <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
In-Reply-To: <20200630095825.4127-15-sharan.santhanam@neclab.eu>
References: <20200630095825.4127-1-sharan.santhanam@neclab.eu>
 <20200630095825.4127-15-sharan.santhanam@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
Date: Tue, 7 Jul 2020 16:07:10 +0200
MIME-Version: 1.0
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: titania.office.hd (192.168.24.89) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Sharan,

thanks a lot for this patch. There are a few issues in tap_write,
comments inline.

regards,
Hugo

On Tue, 2020-06-30 at 11:58 +0200, Sharan Santhanam wrote:
> Implement packet send on a tap device.
> 
> Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
> ---
> Â plat/drivers/include/tap/tap.h |Â Â 1 +
> Â plat/drivers/tap/tap.cÂ Â Â Â Â Â Â Â Â | 18 +++++++++++++++---
> Â plat/linuxu/tap_io.cÂ Â Â Â Â Â Â Â Â Â Â | 20 ++++++++++++++++++++
> Â 3 files changed, 36 insertions(+), 3 deletions(-)
> 
> diff --git a/plat/drivers/include/tap/tap.h
> b/plat/drivers/include/tap/tap.h
> index 797a62e..648f9ef 100644
> --- a/plat/drivers/include/tap/tap.h
> +++ b/plat/drivers/include/tap/tap.h
> @@ -48,5 +48,6 @@ int tap_dev_configure(int fd, __u32 feature_flags,
> void *arg);
> Â int tap_netif_configure(int fd, __u32 request, void *arg);
> Â int tap_netif_create(void);
> Â __ssz tap_read(int fd, void *buf, size_t count);
> +__ssz tap_write(int fd, const void *buf, size_t count);
> Â 
> Â #endif /* __PLAT_DRV_TAP_H */
> diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
> index 998b9e8..505f0cc 100644
> --- a/plat/drivers/tap/tap.c
> +++ b/plat/drivers/tap/tap.c
> @@ -274,14 +274,13 @@ static int tap_netdev_recv(struct uk_netdev
> *dev,
> Â 	rc = queue->alloc_rxpkts(queue->alloc_rxpkts_argp, &_pkt,
> 1);
> Â 	if (rc == 0) {
> Â 		uk_pr_err(DRIVER_NAME": Failed to allocate the
> memory\n");
> -		rc = -ENOMEM;
> Â 		_pkt = NULL;
> -		goto err_exit;
> +		rc = UK_NETDEV_STATUS_UNDERRUN |
> UK_NETDEV_STATUS_MORE;
> +		return 0;
> Â 	}
> Â 	uk_pr_debug(DRIVER_NAME": Receiving on interface %s(%d)
> %p(%d)\n",
> Â 		Â Â Â Â tdev->name, queue->fd, _pkt->data, _pkt->len);
> Â 	rc = tap_read(queue->fd, _pkt->data, _pkt->len);
> -
> Â 	if (rc > 0) {
> Â 		uk_pr_debug(DRIVER_NAME": Recv pkt size: %d\n", rc);
> Â 		/* Setting the length of the packet */
> @@ -313,10 +312,23 @@ static int tap_netdev_xmit(struct uk_netdev
> *dev,
> Â 			Â Â Â struct uk_netbuf *pkt)
> Â {
> Â 	int rc = -EINVAL;
> +	struct tap_net_dev *tdev __unused;
> Â 
> Â 	UK_ASSERT(dev);
> Â 	UK_ASSERT(queue && pkt);
> Â 
> +	tdev = to_tapnetdev(dev);
> +
> +	rc = tap_write(queue->fd, pkt->data, pkt->len);
> +	if (rc > 0) {
> +		uk_pr_info(DRIVER_NAME": Send packet of size %d\n",
> rc);
> +		uk_netbuf_free(pkt);
> +		rc = UK_NETDEV_STATUS_SUCCESS |
> UK_NETDEV_STATUS_MORE;
> +	} else if (rc == -EWOULDBLOCK || rc == -EAGAIN) {
> +		uk_pr_info(DRIVER_NAME": The send queue is full\n");
> +		rc = UK_NETDEV_STATUS_UNDERRUN;
> +	}
> +
> Â 	return rc;
> Â }
> Â 
> diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
> index 01c9bff..030c192 100644
> --- a/plat/linuxu/tap_io.c
> +++ b/plat/linuxu/tap_io.c
> @@ -123,6 +123,26 @@ ssize_t tap_read(int fd, void *buf, size_t
> count)
> Â 	return rc;
> Â }
> Â 
> +ssize_t tap_write(int fd, const void *buf, size_t count)
> +{
> +	ssize_t rc = -EINTR;
> +	int written = 0;

This is a corner case, but `written` might overflow with very large
values of `count`. `size_t written` would be safer.

> +
> +	while (count > 0) {
> +		rc = sys_write(fd, buf, count);

We should write `buf + written` here. If the first sys_write fails, we
will attempt to write the first `count - rc` bytes of the buffer (which
have already been successfully written) instead of the last `count -
rc` bytes.

> +		if (rc == -EINTR)
> +			continue;
> +		else if (rc < 0) {
> +			uk_pr_err("Failed(%ld) to write to the tap
> device\n",
> +				Â Â rc);
> +			return rc;
> +		}
> +		count -= rc;
> +		written += rc;
> +	}
> +	return written;

Missing cast here?

> +}
> +
> Â int tap_close(int fd)
> Â {
> Â 	return sys_close(fd);


From minios-devel-bounces@lists.xenproject.org Tue Jul 07 14:18:54 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 07 Jul 2020 14:18:54 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jsoQt-0003Fc-Iy; Tue, 07 Jul 2020 14:18:51 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=pDl4=AS=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jsoQs-0003FX-Mn
 for minios-devel@lists.xen.org; Tue, 07 Jul 2020 14:18:50 +0000
X-Inumbo-ID: c5e1c62e-c05c-11ea-b7bb-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id c5e1c62e-c05c-11ea-b7bb-bc764e2007e4;
 Tue, 07 Jul 2020 14:18:48 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 58E82F2008;
 Tue,  7 Jul 2020 16:18:47 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id PGj4ZHBGBoQH; Tue,  7 Jul 2020 16:18:47 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 1C229F2001
 for <minios-devel@lists.xen.org>; Tue,  7 Jul 2020 16:18:45 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 7 Jul 2020
 16:18:44 +0200
Message-ID: <1594131523.4397.32.camel@neclab.eu>
Subject: Re: [UNIKRAFT PATCH v2 14/15] plat/tap: Support tap_netdev_xmit
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Sharan Santhanam <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
Date: Tue, 7 Jul 2020 16:18:43 +0200
In-Reply-To: <20200630095825.4127-15-sharan.santhanam@neclab.eu>
References: <20200630095825.4127-1-sharan.santhanam@neclab.eu>
 <20200630095825.4127-15-sharan.santhanam@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Sharan,

well actually I have a few more comments for this patch (inline).

regards,
Hugo

On Tue, 2020-06-30 at 11:58 +0200, Sharan Santhanam wrote:
> Implement packet send on a tap device.
> 
> Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
> ---
> Â plat/drivers/include/tap/tap.h |Â Â 1 +
> Â plat/drivers/tap/tap.cÂ Â Â Â Â Â Â Â Â | 18 +++++++++++++++---
> Â plat/linuxu/tap_io.cÂ Â Â Â Â Â Â Â Â Â Â | 20 ++++++++++++++++++++
> Â 3 files changed, 36 insertions(+), 3 deletions(-)
> 
> diff --git a/plat/drivers/include/tap/tap.h
> b/plat/drivers/include/tap/tap.h
> index 797a62e..648f9ef 100644
> --- a/plat/drivers/include/tap/tap.h
> +++ b/plat/drivers/include/tap/tap.h
> @@ -48,5 +48,6 @@ int tap_dev_configure(int fd, __u32 feature_flags,
> void *arg);
> Â int tap_netif_configure(int fd, __u32 request, void *arg);
> Â int tap_netif_create(void);
> Â __ssz tap_read(int fd, void *buf, size_t count);
> +__ssz tap_write(int fd, const void *buf, size_t count);
> Â 
> Â #endif /* __PLAT_DRV_TAP_H */
> diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
> index 998b9e8..505f0cc 100644
> --- a/plat/drivers/tap/tap.c
> +++ b/plat/drivers/tap/tap.c
> @@ -274,14 +274,13 @@ static int tap_netdev_recv(struct uk_netdev
> *dev,
> Â 	rc = queue->alloc_rxpkts(queue->alloc_rxpkts_argp, &_pkt,
> 1);
> Â 	if (rc == 0) {
> Â 		uk_pr_err(DRIVER_NAME": Failed to allocate the
> memory\n");
> -		rc = -ENOMEM;
> Â 		_pkt = NULL;
> -		goto err_exit;
> +		rc = UK_NETDEV_STATUS_UNDERRUN |
> UK_NETDEV_STATUS_MORE;
> +		return 0;

This should probably be `return rc` and not `return 0`.

> Â 	}
> Â 	uk_pr_debug(DRIVER_NAME": Receiving on interface %s(%d)
> %p(%d)\n",
> Â 		Â Â Â Â tdev->name, queue->fd, _pkt->data, _pkt->len);
> Â 	rc = tap_read(queue->fd, _pkt->data, _pkt->len);
> -
> Â 	if (rc > 0) {
> Â 		uk_pr_debug(DRIVER_NAME": Recv pkt size: %d\n", rc);
> Â 		/* Setting the length of the packet */
> @@ -313,10 +312,23 @@ static int tap_netdev_xmit(struct uk_netdev
> *dev,
> Â 			Â Â Â struct uk_netbuf *pkt)
> Â {
> Â 	int rc = -EINVAL;
> +	struct tap_net_dev *tdev __unused;

This should probably not be __unused.

> Â 
> Â 	UK_ASSERT(dev);
> Â 	UK_ASSERT(queue && pkt);
> Â 
> +	tdev = to_tapnetdev(dev);
> +
> +	rc = tap_write(queue->fd, pkt->data, pkt->len);
> +	if (rc > 0) {
> +		uk_pr_info(DRIVER_NAME": Send packet of size %d\n",
> rc);
> +		uk_netbuf_free(pkt);
> +		rc = UK_NETDEV_STATUS_SUCCESS |
> UK_NETDEV_STATUS_MORE;
> +	} else if (rc == -EWOULDBLOCK || rc == -EAGAIN) {
> +		uk_pr_info(DRIVER_NAME": The send queue is full\n");
> +		rc = UK_NETDEV_STATUS_UNDERRUN;
> +	}
> +
> Â 	return rc;
> Â }
> Â 
> diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
> index 01c9bff..030c192 100644
> --- a/plat/linuxu/tap_io.c
> +++ b/plat/linuxu/tap_io.c
> @@ -123,6 +123,26 @@ ssize_t tap_read(int fd, void *buf, size_t
> count)
> Â 	return rc;
> Â }
> Â 
> +ssize_t tap_write(int fd, const void *buf, size_t count)
> +{
> +	ssize_t rc = -EINTR;
> +	int written = 0;
> +
> +	while (count > 0) {
> +		rc = sys_write(fd, buf, count);
> +		if (rc == -EINTR)
> +			continue;
> +		else if (rc < 0) {
> +			uk_pr_err("Failed(%ld) to write to the tap
> device\n",
> +				Â Â rc);
> +			return rc;
> +		}
> +		count -= rc;
> +		written += rc;
> +	}
> +	return written;
> +}
> +
> Â int tap_close(int fd)
> Â {
> Â 	return sys_close(fd);


From minios-devel-bounces@lists.xenproject.org Tue Jul 07 19:23:09 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 07 Jul 2020 19:23:09 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jstBK-0005by-8O; Tue, 07 Jul 2020 19:23:06 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Sbml=AS=gmail.com=felipehuici@srs-us1.protection.inumbo.net>)
 id 1jstBI-0005bC-Ec
 for minios-devel@lists.xenproject.org; Tue, 07 Jul 2020 19:23:04 +0000
X-Inumbo-ID: 4701ef20-c087-11ea-bca7-bc764e2007e4
Received: from mail-ua1-x944.google.com (unknown [2607:f8b0:4864:20::944])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4701ef20-c087-11ea-bca7-bc764e2007e4;
 Tue, 07 Jul 2020 19:23:03 +0000 (UTC)
Received: by mail-ua1-x944.google.com with SMTP id j21so1705095ual.11
 for <minios-devel@lists.xenproject.org>; Tue, 07 Jul 2020 12:23:03 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:references:in-reply-to:from:date:message-id:subject:to
 :cc; bh=AnptQAJHuCwEbZ0LnQL61h8NwRz97wVEcZhpGd0E3yE=;
 b=RTi4ygOn8uAy7W0mp0KWUg05DfUh8fCIFrSBGoENZiG4vvQZgHu3WdrY8uFOj84SZ/
 dwOpqPNM37k9/tF9WDfF/fl/1dRH5WVagkD1MBSrotRlhKjla4jTsq6/yy84lCcIcUkG
 eKGDou6j6pGNv3ZGisgGqh9ZbUFGJL/kDNrmE1Tk6h5njx4udj/Wocp6QaKti3ZeDUjM
 VJJOICk9d01LxmM/0rmMC3iFH33Am6nOgscC87o8Ex4aH0d0EBO2DFGRVGPmSfAfy7vm
 zwCRRI5EPqt8eM5P9ouxWRDmQDqyhb+yzkcR+awGmq49Curi8+5tgMt/rMNE5em/CoFm
 fmpA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:references:in-reply-to:from:date
 :message-id:subject:to:cc;
 bh=AnptQAJHuCwEbZ0LnQL61h8NwRz97wVEcZhpGd0E3yE=;
 b=MMRGX1myp6a2q4UZjJT8bsAMX0kLY9HLvhI3WxoN5sOwuqBR7PE2S+fsje5bsuLygI
 HD51aGTUvwhmU5LSthTak/1FMy2SGqcBWnbmKMWNXH/ySB7er3FNFheaX9kTz7lweodh
 0mfbA7AQwze5J7u2xth4oQ0F1OcUYwV+UDl2/HMwWtUSGiVwOT0fNbiuCK8qk76PYGS6
 6yKie6O++fHHW8WZZ+hJhQONBLw5WNKAWLCF/G5zKAjONUOWqqjo9CPbC67q+Vl06C1n
 HCxuns1mcpetuZDHoxnPCEayrkyCOkGu31TkugE5DkbyAEoa/cDRJ3HSZb04W2s6WdKL
 97+g==
X-Gm-Message-State: AOAM530cva5wXUlms2NY0soS5y1Xb81lwdGQzD8jiOoPn0g5oJDg48DW
 y/0vXKgme0LuPCcF7Ud/2FP4ioEYDE3GauOcn3bm6OuY
X-Google-Smtp-Source: ABdhPJwgEnXk6jj+DVk4lR2WOxYd7F1kAGrgpFkOzbqyro8NpTlJo8sFDVq09M1QiiI2BkTxNVNXnbXJQ6JAVHNRcVI=
X-Received: by 2002:ab0:6618:: with SMTP id r24mr29304731uam.32.1594149782750; 
 Tue, 07 Jul 2020 12:23:02 -0700 (PDT)
MIME-Version: 1.0
References: <20200515115200.98471-1-murarugeorgec@gmail.com>
 <20200515115200.98471-2-murarugeorgec@gmail.com>
In-Reply-To: <20200515115200.98471-2-murarugeorgec@gmail.com>
From: "felipehuici ." <felipehuici@gmail.com>
Date: Tue, 7 Jul 2020 21:22:51 +0200
Message-ID: <CAEX4t-N+GyPpw17ZTh-6zehgLPFFfO3hrU=xCwTVJSZT5E+4oA@mail.gmail.com>
Subject: Re: [UNIKRAFT/LIBTFLITE PATCH 1/4] Library skeleton
To: George Muraru <murarugeorgec@gmail.com>
Content-Type: text/plain; charset="UTF-8"
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: minios-devel@lists.xenproject.org, Felipe Huici <Felipe.Huici@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi George,

I have a minor comment below that I can fix on upstreaming. Other than that:

Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>

On Fri, May 15, 2020 at 1:52 PM George Muraru <murarugeorgec@gmail.com> wrote:
>
> Signed-off-by: George Muraru <murarugeorgec@gmail.com>
> ---
>  CONTRIBUTING.md |  4 ++++
>  COPYING.md      | 38 ++++++++++++++++++++++++++++++++++
>  Config.uk       | 50 ++++++++++++++++++++++++++++++++++++++++++++
>  MAINTAINERS.md  | 10 +++++++++
>  README.md       | 55 +++++++++++++++++++++++++++++++++++++++++++++++++
>  5 files changed, 157 insertions(+)
>  create mode 100644 CONTRIBUTING.md
>  create mode 100644 COPYING.md
>  create mode 100644 Config.uk
>  create mode 100644 MAINTAINERS.md
>  create mode 100644 README.md
>
> diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
> new file mode 100644
> index 0000000..14f6ac6
> --- /dev/null
> +++ b/CONTRIBUTING.md
> @@ -0,0 +1,4 @@
> +Contributing to Unikraft
> +========================
> +
> +Please refer to the `CONTRIBUTING.md` file in the main Unikraft repository.
> diff --git a/COPYING.md b/COPYING.md
> new file mode 100644
> index 0000000..fd1dc8e
> --- /dev/null
> +++ b/COPYING.md
> @@ -0,0 +1,38 @@
> +License
> +=======
> +
> +Unikraft tensorflowlite wrappers
> +----------------------------------
> +
> +This repository contains wrapper code to build tensorflowlite with Unikraft.
> +Each C code file in this repository should declare who is the
> +copyright owner and under which terms and conditions the code is
> +licensed. If such a licence note is missing, the following copyright
> +notice will apply:
> +
> +       Copyright (c) Year, Institution. All rights reserved.
> +
> +       Redistribution and use in source and binary forms, with or without
> +       modification, are permitted provided that the following conditions
> +       are met:
> +
> +       1. Redistributions of source code must retain the above copyright
> +          notice, this list of conditions and the following disclaimer.
> +       2. Redistributions in binary form must reproduce the above copyright
> +          notice, this list of conditions and the following disclaimer in the
> +          documentation and/or other materials provided with the distribution.
> +       3. Neither the name of the copyright holder nor the names of its
> +          contributors may be used to endorse or promote products derived from
> +          this software without specific prior written permission.
> +
> +       THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
> +       AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> +       IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> +       ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
> +       LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> +       CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> +       SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> +       INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> +       CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> +       ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
> +       POSSIBILITY OF SUCH DAMAGE.
> diff --git a/Config.uk b/Config.uk
> new file mode 100644
> index 0000000..8d483a2
> --- /dev/null
> +++ b/Config.uk
> @@ -0,0 +1,50 @@
> +menuconfig LIBTFLITE
> +    bool "TensorFlowLite - tensorflow lite library"
> +    select LIBCXX
> +    select LIBNEWLIBC
> +    select LIBPOSIX_SYSINFO
> +    select LIBPTHREAD_EMBEDDED
> +    select LIBCOMPILTER_RT
> +    select LIBCOMPILER_RT_ATOMIC
> +    select LIBEIGEN
> +    select LIBFFT2D
> +    select LIBFLATBUFFERS
> +    select LIBGEMMLOWP
> +    select LIBFARMHASH
> +    select LIBUK9P
> +    select LIB9PFS
> +    select LIBDEVFS
> +    select LIBDEVFS_AUTOMOUNT
> +    select LIBVFSCORE_AUTOMOUNT_ROOTFS
> +    select LIBUKLIBPARAM
> +    default n
> +
> +if LIBTFLITE
> +    choice LIBVFSCORE_ROOTFS
> +    default LIBVFSCORE_ROOTFS_9PFS
> +    endchoice
> +endif
> +
> +if LIBTFLITE
> +    config LIBTFLITE_EIGEN_DONT_ALIGN
> +    bool "Do not align the buffers used by eigen library"
> +    default y
> +endif
> +
> +if LIBTFLITE
> +    config LIBTFLITE_BUILD_WITH_RUY
> +    bool "Matrix multiplication library"
> +    default y
> +endif
> +
> +if LIBTFLITE
> +    config LIBTFLITE_BUILD_WITH_NNAPI
> +    bool "Build with Neural Network API"
> +    default n
> +endif
> +
> +if LIBTFLITE
> +    config LIBTFLITE_MAIN_FUNCTION
> +       bool "Provide main function"
> +       default y
> +endif
> diff --git a/MAINTAINERS.md b/MAINTAINERS.md
> new file mode 100644
> index 0000000..f53ffe5
> --- /dev/null
> +++ b/MAINTAINERS.md
> @@ -0,0 +1,10 @@
> +Maintainers List
> +================
> +
> +For notes on how to read this information, please refer to `MAINTAINERS.md` in
> +the main Unikraft repository.
> +
> +       LIBGEMMLOWP-UNIKRAFT
> +       M:      George Muraru <murarugeorgec@gmail.com>
> +       L:      minios-devel@lists.xen.org
> +       F: *
> diff --git a/README.md b/README.md
> new file mode 100644
> index 0000000..cc8cfda
> --- /dev/null
> +++ b/README.md
> @@ -0,0 +1,55 @@
> +TensorFlowLite for Unikraft
> +=============================
> +
> +This is the port of tensorflowlite as external library
> +Please refer to the `README.md` as well as the documentation in the `doc/`
> +subdirectory of the main unikraft repository.
> +
> +## Build
> +TensorFlowLite interpreter depends on the following libraries, that need to
> +be added to `Makefile` in this order:
> +
> +* `pthreads`, e.g. `pthread-embedded`
> +* `libcxx`
> +* `libcxxabi`
> +* `libc`, e.g. `newlib`
> +* `libunwind`
> +* `libcompilerrt`
> +* `libgemmlowp`
> +* `libflatbuffers`
> +* `libfarmhash`
> +* `libeigen`
> +* `libfft2`
> +
> +## Root filesystem
> +### Creating the filesystem
> +TensorFlowLite needs a filesystem which should contain one or more *tflite*
> +models. Therefore, the filesystem needs to be created before running the VM.
> +
> +### Using the filesystem
> +Mounting the filesystem is a transparent operation. All you have to do
> +is to provide the right Qemu parameters in order for Unikraft to mount
> +the filesystem.  We will use the 9pfs support for filesystems and for
> +this you will need to use the following parameters:
> +
> +```bash
> +-fsdev local,id=myid,path=<some directory>,security_model=none \
> +-device virtio-9p-pci,fsdev=myid,mount_tag=rootfs,disable-modern=on,disable-legacy=off

I'll add a sentence on how to launch this using qemu-guest [1], the
script that kraft uses to launch qemu; this is easier to use than a
long qemu line.

[1] https://github.com/unikraft/kraft/blob/master/scripts/qemu-guest

> +```
> +You should also use `vfs.rootdev=rootfs` (set by default) to specify the 9pfs mounting
> +tag to Unikraft. To enable 9pfs, you'll need to select the following
> +menu options, all under `Library Configuration` (this should be already done by the
> +`tflite` config file):
> +
> +* `uk9p: 9p client`
> +* `vfscore: VFS Core Interface`
> +         &rarr; `vfscore: Configuration`
> +         &rarr; `Automatically mount a root filesysytem`
> +         &rarr; `Default root filesystem`
> +         &rarr; `9PFS`
> +
> +## How to run
> +Currently, `main.cpp` contains a minimal example for loading a *tflite* model and
> +printing the interpreter state. The sample program will try to load the model from
> +`mobilenet_v1_1.0_224.tflite` (this model and other models from the same family can
> +be downloaded from [here](https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet_v1.md))
> --
> 2.25.1
>
>


From minios-devel-bounces@lists.xenproject.org Tue Jul 07 19:23:45 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 07 Jul 2020 19:23:45 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jstBx-0005fc-Oe; Tue, 07 Jul 2020 19:23:45 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Sbml=AS=gmail.com=felipehuici@srs-us1.protection.inumbo.net>)
 id 1jstBw-0005fT-QQ
 for minios-devel@lists.xenproject.org; Tue, 07 Jul 2020 19:23:44 +0000
X-Inumbo-ID: 5f319e7e-c087-11ea-8496-bc764e2007e4
Received: from mail-vs1-xe42.google.com (unknown [2607:f8b0:4864:20::e42])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 5f319e7e-c087-11ea-8496-bc764e2007e4;
 Tue, 07 Jul 2020 19:23:43 +0000 (UTC)
Received: by mail-vs1-xe42.google.com with SMTP id o15so23121247vsp.12
 for <minios-devel@lists.xenproject.org>; Tue, 07 Jul 2020 12:23:43 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:references:in-reply-to:from:date:message-id:subject:to
 :cc; bh=PXNScv490vNP0/8W8IEzgvUe7dz4ofI8uWDPtuSa0qs=;
 b=joVeAp0YuL4w2aBd/CfFrc/U/XV+0o5XraIbmLvOrEuSujGsQli0rNYj5/AAzJ3OUm
 BN8LK3Hf/3NeNPDonfj3Pkgr5VdptC3XnpeZrpye/XZjAxH5vz6lQlKh7buTYCsgaC5I
 GYm9PtLBJlmmpA35YU93Pr3F49AsnQXjWON/FKfG3XcvHPTqlSpdcsClJzsifmnJdEsh
 hyzghwSScc2Cmh9lCq+k4HY3eoDdPDXqVzsxf0SLp6W5Vz5CKWfbQJCnnyTVaNKQZJ2+
 glrBH2pNRbJtSM4clNsOOoq7oPap10elr4/qJqhv1UNwA25AaykS9l8PcGnwau8w8ogx
 7RKw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:references:in-reply-to:from:date
 :message-id:subject:to:cc;
 bh=PXNScv490vNP0/8W8IEzgvUe7dz4ofI8uWDPtuSa0qs=;
 b=E2qW5SefIkwB+IoNEKN1EXPPuW9xZ2RVxt+LcnNdDSLFNpK86nsbNo8N8DwcW7FIPH
 ArG6FR5kF+F0CNIbkT29XCk+i+DGU9GozWvwMvY4cHuDv7EH8O4Ks4RANTk6L6uGyIG+
 wTObI3YpH593BQg5EPd8yQr1uuXBqxkLodT3i+PWVcdrx3qIkXh3x5riNm36fmEDPSMj
 zVPN95xddcft3VL912I8Z9ezuwpGqPRO3LOM3CT1dBGAdVxUb298FPpb5HOkAeWrfMQ3
 c7KpaEmUX5e7TWO3ux6mJQxIuNCY0FA3OaT7Ro5w8UeAxyQpbF4G9xTZ9KUSdG7gSWHD
 aQig==
X-Gm-Message-State: AOAM532Hbqo/4O2y/kheLjNvysVQsRJXJT+mEsE8Rz4SDymHKYmu3ek7
 hVQWZeHukxsXitVeK2cIEoBqbLJZjMEDMyf5QU0=
X-Google-Smtp-Source: ABdhPJySef1IMlrFiAEEi2rvR4QNQhTuSkdyNwNjoNT3UFTzqa7izzVVbn19uV0mXOx6QnIrrPqLe+OkkGplvfJqr4o=
X-Received: by 2002:a67:d184:: with SMTP id w4mr22274227vsi.17.1594149823445; 
 Tue, 07 Jul 2020 12:23:43 -0700 (PDT)
MIME-Version: 1.0
References: <20200515115200.98471-1-murarugeorgec@gmail.com>
 <20200515115200.98471-3-murarugeorgec@gmail.com>
In-Reply-To: <20200515115200.98471-3-murarugeorgec@gmail.com>
From: "felipehuici ." <felipehuici@gmail.com>
Date: Tue, 7 Jul 2020 21:23:32 +0200
Message-ID: <CAEX4t-PnfRBzWL5c0Dpkr-OLEACKMRgEkByiMQm4ATQrqhqpeQ@mail.gmail.com>
Subject: Re: [UNIKRAFT/LIBTFLITE PATCH 2/4] Add Makefile.uk
To: George Muraru <murarugeorgec@gmail.com>
Content-Type: text/plain; charset="UTF-8"
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: minios-devel@lists.xenproject.org, Felipe Huici <Felipe.Huici@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>

On Fri, May 15, 2020 at 1:52 PM George Muraru <murarugeorgec@gmail.com> wrote:
>
> Signed-off-by: George Muraru <murarugeorgec@gmail.com>
> ---
>  Makefile.uk | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 167 insertions(+)
>  create mode 100644 Makefile.uk
>
> diff --git a/Makefile.uk b/Makefile.uk
> new file mode 100644
> index 0000000..7223603
> --- /dev/null
> +++ b/Makefile.uk
> @@ -0,0 +1,167 @@
> +#  libtensorflow-lite Makefile.uk
> +#
> +#  Authors: George Muraru <murarugeorgec@gmail.com>
> +#
> +#  Copyright (c) 2020, Politehnica University of Bucharest. All rights reserved.
> +#
> +#  Redistribution and use in source and binary forms, with or without
> +#  modification, are permitted provided that the following conditions
> +#  are met:
> +#
> +#  1. Redistributions of source code must retain the above copyright
> +#     notice, this list of conditions and the following disclaimer.
> +#  2. Redistributions in binary form must reproduce the above copyright
> +#     notice, this list of conditions and the following disclaimer in the
> +#     documentation and/or other materials provided with the distribution.
> +#  3. Neither the name of the copyright holder nor the names of its
> +#     contributors may be used to endorse or promote products derived from
> +#     this software without specific prior written permission.
> +#
> +#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
> +#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> +#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> +#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
> +#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> +#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> +#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> +#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> +#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> +#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
> +#  POSSIBILITY OF SUCH DAMAGE.
> +#
> +#  THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
> +#
> +
> +$(eval $(call addlib_s,libtflite,$(CONFIG_LIBTFLITE)))
> +
> +################################################################################
> +# Sources
> +################################################################################
> +LIBTFLITE_VERSION=2.0.1
> +LIBTFLITE_PATCHDIR=$(LIBTFLITE_BASE)/patches
> +
> +LIBTFLITE_URL=https://github.com/tensorflow/tensorflow/archive/v$(LIBTFLITE_VERSION).tar.gz
> +$(eval $(call fetch,libtflite,$(LIBTFLITE_URL)))
> +$(eval $(call patch,libtflite,$(LIBTFLITE_PATCHDIR),tensorflow-$(LIBTFLITE_VERSION)))
> +
> +################################################################################
> +# Helpers
> +################################################################################
> +LIBTFLITE_SUBDIR=tensorflow-$(LIBTFLITE_VERSION)
> +LIBTFLITE_SRC = $(LIBTFLITE_ORIGIN)/$(LIBTFLITE_SUBDIR)
> +
> +################################################################################
> +# Library includes
> +################################################################################
> +CXXINCLUDES-$(CONFIG_LIBTFLITE) += -I$(LIBTFLITE_SRC)/
> +CXXINCLUDES-$(CONFIG_LIBTFLITE) += -I$(LIBTFLITE_SRC)/tensorflow/lite
> +
> +
> +CINCLUDES-$(CONFIG_LIBTFLITE) += -I$(LIBTFLITE_SRC)/
> +CINCLUDES-$(CONFIG_LIBTFLITE) += -I$(LIBTFLITE_SRC)/tensorflow/lite
> +
> +################################################################################
> +# Main code
> +################################################################################
> +
> +ifdef CONFIG_LIBTFLITE_MAIN_FUNCTION
> +LIBTFLITE_SRCS-$(CONFIG_LIBTFLITE_MAIN_FUNCTION) += $(LIBTFLITE_BASE)/main.cpp
> +endif
> +
> +################################################################################
> +# Global flags
> +################################################################################
> +LIBTFLITE_SUPPRESS_FLAGS += -Wno-sign-compare -Wno-unused-parameter -Wno-comment \
> +                            -Wno-missing-field-initializers -Wno-parantheses \
> +                            -Wno-unused-function -Wno-unknown-pragmas
> +
> +LIBTFLITE_CXXFLAGS-y += $(LIBTFLITE_SUPPRESS_FLAGS)
> +LIBTFLITE_CFLAGS-y += $(LIBTFLITE_SUPPRESS_FLAGS)
> +
> +ifdef CONFIG_LIBTFLITE_BUILD_WITH_RUY
> +LIBTFLITE_CXXFLAGS-y += -D TFLITE_WITH_RUY
> +LIBTFLITE_CFLAGS-y += -D TFLITE_WITH_RUY
> +endif
> +
> +ifdef CONFIG_LIBTFLITE_EIGEN_DONT_ALIGN
> +LIBTFLITE_CXXFLAGS-y += -D EIGEN_DONT_ALIGN
> +LIBTFLITE_CFLAGS-y += -D EIGEN_DONT_ALIGN
> +endif
> +
> +################################################################################
> +# Library sources
> +################################################################################
> +MINIMAL_SRCS := $(LIBTFLITE_SRC)/tensorflow/lite/examples/minimal/minimal.cc
> +
> +
> +CORE_CC_ALL_SRCS := \
> +            $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/*.cc) \
> +            $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/*.c) \
> +            $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/c/*.c) \
> +            $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/core/*.cc) \
> +            $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/core/api/*.cc) \
> +            $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/experimental/resource_variable/*.cc) \
> +            $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/allocator.cc \
> +            $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/block_map.cc \
> +            $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/blocking_counter.cc \
> +            $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/context.cc \
> +            $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/detect_dotprod.cc \
> +            $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/kernel_arm32.cc \
> +            $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/kernel_arm64.cc \
> +            $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/pack_arm.cc \
> +            $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/pmu.cc \
> +            $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/thread_pool.cc \
> +            $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/trace.cc \
> +            $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/trmul.cc \
> +            $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/tune.cc \
> +            $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/wait.cc \
> +            $(LIBTFLITE_SRC)/tensorflow/lite/minimal_logging_default.cc
> +
> +
> +
> +CORE_CC_ALL_SRCS += \
> +             $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/kernels/*.cc) \
> +             $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/kernels/internal/*.cc) \
> +             $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/kernels/internal/optimized/*.cc) \
> +             $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/kernels/internal/reference/*.cc)
> +
> +
> +CORE_CC_ALL_SRCS := $(sort $(CORE_CC_ALL_SRCS))
> +CORE_CC_EXCLUDE_SRCS := \
> +                $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/*test.cc) \
> +                $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/*/*test.cc) \
> +                $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/*/*/*test.cc) \
> +                $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/*/*/*/*test.cc) \
> +                $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/kernels/*test_main.cc) \
> +                $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/kernels/*test_util.cc) \
> +                $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/pmu.cc \
> +                $(LIBTFLITE_SRC)/tensorflow/lite/minimal_logging_android.cc \
> +                $(LIBTFLITE_SRC)/tensorflow/lite/minimal_logging_ios.cc \
> +                $(MINIMAL_SRCS)
> +
> +
> +COMPILE_MANUAL_SRCS := \
> +                $(LIBTFLITE_SRC)/tensorflow/lite/kernels/internal/mfcc.cc \
> +                $(LIBTFLITE_SRC)/tensorflow/lite/kernels/mfcc.cc
> +
> +
> +ifeq ($(CONFIG_LIBUKMMAP),y)
> +CORE_CC_EXCLUDE_SRCS += $(LIBTFLITE_SRC)/tensorflow/lite/mmap_allocation_disabled.cc
> +else
> +CORE_CC_EXCLUDE_SRCS += $(LIBTFLITE_SRC)/tensorflow/lite/mmap_allocation.cc
> +endif
> +
> +ifeq ($(LIBTFLITE_BUILD_WITH_NNAPI),y)
> +CORE_CC_ALL_SRCS += \
> +                $(LIBTFLITE_SRC)/tensorflow/lite/delegates/nnapi/nnapi_delegate.cc \
> +                $(LIBTFLITE_SRC)/tensorflow/lite/delegates/nnapi/quant_lstm_sup.cc \
> +                $(LIBTFLITE_SRC)/tensorflow/lite/nnapi/nnapi_implementation.cc
> +else
> +CORE_CC_ALL_SRCS += \
> +                $(LIBTFLITE_SRC)/tensorflow/lite/delegates/nnapi/nnapi_delegate_disabled.cc \
> +                $(LIBTFLITE_SRC)/tensorflow/lite/nnapi/nnapi_implementation_disabled.cc
> +endif
> +
> +LIBTFLITE_SRCS-y += $(filter-out $(CORE_CC_EXCLUDE_SRCS) $(COMPILE_MANUAL_SRCS), $(CORE_CC_ALL_SRCS))
> +LIBTFLITE_SRCS-y += $(LIBTFLITE_SRC)/tensorflow/lite/kernels/internal/mfcc.cc|internal
> +LIBTFLITE_SRCS-y += $(LIBTFLITE_SRC)/tensorflow/lite/kernels/mfcc.cc|kernels
> --
> 2.25.1
>
>


From minios-devel-bounces@lists.xenproject.org Tue Jul 07 19:24:15 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 07 Jul 2020 19:24:15 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jstCR-0005iU-SB; Tue, 07 Jul 2020 19:24:15 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Sbml=AS=gmail.com=felipehuici@srs-us1.protection.inumbo.net>)
 id 1jstCQ-0005iK-PG
 for minios-devel@lists.xenproject.org; Tue, 07 Jul 2020 19:24:14 +0000
X-Inumbo-ID: 7142a450-c087-11ea-8496-bc764e2007e4
Received: from mail-vs1-xe43.google.com (unknown [2607:f8b0:4864:20::e43])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 7142a450-c087-11ea-8496-bc764e2007e4;
 Tue, 07 Jul 2020 19:24:14 +0000 (UTC)
Received: by mail-vs1-xe43.google.com with SMTP id s20so15767305vsq.5
 for <minios-devel@lists.xenproject.org>; Tue, 07 Jul 2020 12:24:14 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:references:in-reply-to:from:date:message-id:subject:to
 :cc; bh=QaYpSUBSoJJp3wXkEN6jEhTpmP0B+4uAJp3wjsP8irM=;
 b=k+IghbLA6ILI67+pe+cF0ahYl0/gMkEFWm/5tLB9ZoyH/ojyhZkLj9nz70SZq2M57B
 ikl4TERq5nAIh2gbb06tMec7nbJz+XEZP7a/DOwaYVqCtJFFK4r2JH2VAI22m13JJwxq
 /XLCWRNfFpozozv3HDsLv6/N1uSd1D29z9oizpFoe75bMroY2GZAi3V3uPX8J3gPoGBO
 HYppdcr8Ah6AZahB9wmUpJglraMjyyzdmakAWwkXXxqrIV0iZRVLMzdBqk3SZVy7/wnh
 mx8BlJLh0TJhtq8MgxwF8DrPP5REFyvpd/o/76sF/4K9CtyHLulE+j731KCly8GzgYc+
 EUxg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:references:in-reply-to:from:date
 :message-id:subject:to:cc;
 bh=QaYpSUBSoJJp3wXkEN6jEhTpmP0B+4uAJp3wjsP8irM=;
 b=SIOSyHff+AIPgM63vrTBL0F+s3QgjK8czp2mcIEczF3+jI7rLt+5wGjb9IvpHKqcj+
 zFj1L/PXKjDM5Bg8dTT6cgjOdyZckXdmXzDGRX1xzEZqrBp8jkpSaepOQ2ZOYDcxCtsu
 0CCfS1lBsi75iOb/WUwOvIPVf3rjhnLKHL+UCPh/aMMd5m1mdoWnRD1wHwrhWnc48CRI
 BrS+xs3FfecVas7WK4SSdRTuBN2GDfftwqrO2uc0SiBf7VdsmaZ6QwLo+REEm/tKemeV
 KQz/2U8k+dagQP018GqV6FFf3ntpyUHlAtllh9vgYQ/uA09N6JY1vnaOGx7FyKBh7/1Q
 KWxg==
X-Gm-Message-State: AOAM532NmpCo1NjC3RvHOUnRsZrH1EejWv4L1G7nIqmYHbYR+z04wshp
 UnHS1THjvwS2lcJIg4SVUVw9SkoYDL6rRJkcxwNES3L4
X-Google-Smtp-Source: ABdhPJykbUr85bPGnvUwuhB2qGb2DhUOIZk0YHCZGSdsSaUmLgpmv1xZgN/JAmnLRtNjIKbz/e2G/G+VeC7Hhw8bOl0=
X-Received: by 2002:a67:6c84:: with SMTP id
 h126mr37497370vsc.181.1594149853876; 
 Tue, 07 Jul 2020 12:24:13 -0700 (PDT)
MIME-Version: 1.0
References: <20200515115200.98471-1-murarugeorgec@gmail.com>
 <20200515115200.98471-4-murarugeorgec@gmail.com>
In-Reply-To: <20200515115200.98471-4-murarugeorgec@gmail.com>
From: "felipehuici ." <felipehuici@gmail.com>
Date: Tue, 7 Jul 2020 21:24:02 +0200
Message-ID: <CAEX4t-PZQOPd3pRY4FcrGKF-Xbs6pFLCG1r6p56ny9H_Wjv3Ow@mail.gmail.com>
Subject: Re: [UNIKRAFT/LIBTFLITE PATCH 3/4] Add main app if selected
To: George Muraru <murarugeorgec@gmail.com>
Content-Type: text/plain; charset="UTF-8"
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: minios-devel@lists.xenproject.org, Felipe Huici <Felipe.Huici@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>

On Fri, May 15, 2020 at 1:52 PM George Muraru <murarugeorgec@gmail.com> wrote:
>
> Signed-off-by: George Muraru <murarugeorgec@gmail.com>
> ---
>  main.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 56 insertions(+)
>  create mode 100644 main.cpp
>
> diff --git a/main.cpp b/main.cpp
> new file mode 100644
> index 0000000..45f9b07
> --- /dev/null
> +++ b/main.cpp
> @@ -0,0 +1,56 @@
> +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
> +
> +Licensed under the Apache License, Version 2.0 (the "License");
> +you may not use this file except in compliance with the License.
> +You may obtain a copy of the License at
> +
> +    http://www.apache.org/licenses/LICENSE-2.0
> +
> +Unless required by applicable law or agreed to in writing, software
> +distributed under the License is distributed on an "AS IS" BASIS,
> +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> +See the License for the specific language governing permissions and
> +limitations under the License.
> +==============================================================================*/
> +#define __clrsbDI2    __NDW(clrsb,2)
> +
> +#include <cstdio>
> +#include "tensorflow/lite/interpreter.h"
> +#include "tensorflow/lite/kernels/register.h"
> +#include "tensorflow/lite/model.h"
> +#include "tensorflow/lite/optional_debug_tools.h"
> +
> +#include <sys/mount.h>
> +#include <sys/types.h>
> +#include <fcntl.h>
> +
> +// This is an example that is minimal to read a model
> +// from disk and perform inference. There is no data being loaded
> +// that is up to you to add as a user.
> +//
> +// NOTE: Do not add any dependencies to this that cannot be built with
> +// the minimal makefile. This example must remain trivial to build with
> +// the minimal build tool.
> +//
> +// Usage: minimal <tflite model>
> +
> +using namespace tflite;
> +
> +int main() {
> +  const char* filename = "mobilenet_v1_1.0_224.tflite";
> +
> +  // Load model
> +  std::unique_ptr<tflite::FlatBufferModel> model =
> +      tflite::FlatBufferModel::BuildFromFile(filename);
> +
> +  // Build the interpreter
> +  tflite::ops::builtin::BuiltinOpResolver resolver;
> +  InterpreterBuilder builder(*model, resolver);
> +  std::unique_ptr<Interpreter> interpreter;
> +  builder(&interpreter);
> +
> +  printf("=== Interpreter State ===\n");
> +  tflite::PrintInterpreterState(interpreter.get());
> +
> +  return 0;
> +}
> --
> 2.25.1
>
>


From minios-devel-bounces@lists.xenproject.org Tue Jul 07 19:24:40 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 07 Jul 2020 19:24:40 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jstCq-0005l0-V8; Tue, 07 Jul 2020 19:24:40 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Sbml=AS=gmail.com=felipehuici@srs-us1.protection.inumbo.net>)
 id 1jstCp-0005kr-SA
 for minios-devel@lists.xenproject.org; Tue, 07 Jul 2020 19:24:39 +0000
X-Inumbo-ID: 803661d6-c087-11ea-b7bb-bc764e2007e4
Received: from mail-vk1-xa41.google.com (unknown [2607:f8b0:4864:20::a41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 803661d6-c087-11ea-b7bb-bc764e2007e4;
 Tue, 07 Jul 2020 19:24:39 +0000 (UTC)
Received: by mail-vk1-xa41.google.com with SMTP id b205so9412047vkb.8
 for <minios-devel@lists.xenproject.org>; Tue, 07 Jul 2020 12:24:39 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:references:in-reply-to:from:date:message-id:subject:to
 :cc; bh=jlf2REyG3R1zSI6I/FfqM9PPKjE9dlkQcO91SKowNko=;
 b=Se7H5a2QnQpGIM+bIoMkpmLNI/lr8JFojRtmcr1qALLOXvV4JO5ZO8/Pg+2Njz77yT
 cezE1oOKd4iRQrL8vVDJW+8lWCMNFgmkjGMLkejjNg9MAGYA8DG2itzBIxELNoewk45c
 34f7PO4yACT9Zi4HOsR7AAz+T4fUR5nzc4NswU7ote6BruMnLWuVLiPp3BOGocNPIdaS
 W8csqpqD7TXcHQyPeV3nCapei7HpJkjGGqB9r9TCNuloST+GGASrLfEqJuoqkecyIl4i
 raGHhb3p1xSlMoG3F/QCxsJN3zEGL0k6jX1PtRL41NYEg6MTEUGCsch3AKpLB03zZJdD
 QMMA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:references:in-reply-to:from:date
 :message-id:subject:to:cc;
 bh=jlf2REyG3R1zSI6I/FfqM9PPKjE9dlkQcO91SKowNko=;
 b=gHu/eUGx0Nn+G57RnifJ3q/JvNccBtryXe4Go7afQlVY1c19kME7gr/JgH6MOtO2C8
 eP5HFrwBh43jfHwEDoYYflhWLGEri6lxIS/FFAaHC64bcPQzwYMGiQdHXfxwwM5AMVsf
 bKC2t08aD6pR3aNRzHmmLP7PusH4TxflZ0TS3ytK91ESc2A/BeNNkolWOaIOCrvymX24
 uQAtOHQ/tgsXLLxOtWFMUtyeuknxvo6GPnge3OJ2jxtJ4ZZ/VbQTg7FP56j5vD5O9kJr
 0cwJlylw1sotLMkCwYqOYDn8Yu9Ggn/ztjwTcDOSprsYZpxZUfOD/gCu9m43zTllvZwB
 SNgQ==
X-Gm-Message-State: AOAM53169+2Ab0zpTLgR3EssAxOx0YLiJRu2xIhk+oCPGX6Ozu5mjyXs
 a/bWChxAmqKMXULkfGkqVDhd27Z1RigJXSZI1Ps=
X-Google-Smtp-Source: ABdhPJwa3fZE55k8AWflbl3GIpdWVq3UZLv3VPfo1O7+IOg7GvOckLwRkL20B0A/wJVV4aeTanuLBwCtcfAl6N/jPTs=
X-Received: by 2002:ac5:cdf5:: with SMTP id v21mr37977518vkn.1.1594149878819; 
 Tue, 07 Jul 2020 12:24:38 -0700 (PDT)
MIME-Version: 1.0
References: <20200515115200.98471-1-murarugeorgec@gmail.com>
 <20200515115200.98471-5-murarugeorgec@gmail.com>
In-Reply-To: <20200515115200.98471-5-murarugeorgec@gmail.com>
From: "felipehuici ." <felipehuici@gmail.com>
Date: Tue, 7 Jul 2020 21:24:27 +0200
Message-ID: <CAEX4t-P-OnVpg=E25UgstFwKLiEp4z+HM_j_f7Fn7GqBNc8q3Q@mail.gmail.com>
Subject: Re: [UNIKRAFT/LIBTFLITE PATCH 4/4] Add patches
To: George Muraru <murarugeorgec@gmail.com>
Content-Type: text/plain; charset="UTF-8"
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: minios-devel@lists.xenproject.org, Felipe Huici <Felipe.Huici@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>

On Fri, May 15, 2020 at 1:52 PM George Muraru <murarugeorgec@gmail.com> wrote:
>
> Signed-off-by: George Muraru <murarugeorgec@gmail.com>
> ---
>  patches/0001-Change-zu-to-lu.patch | 47 ++++++++++++++++++++++++++++++
>  1 file changed, 47 insertions(+)
>  create mode 100644 patches/0001-Change-zu-to-lu.patch
>
> diff --git a/patches/0001-Change-zu-to-lu.patch b/patches/0001-Change-zu-to-lu.patch
> new file mode 100644
> index 0000000..d68a26e
> --- /dev/null
> +++ b/patches/0001-Change-zu-to-lu.patch
> @@ -0,0 +1,47 @@
> +From f34b41fd728c06517a1223178af2fbb97dce5dfe Mon Sep 17 00:00:00 2001
> +From: George Muraru <murarugeorgec@gmail.com>
> +Date: Tue, 21 Apr 2020 23:16:50 +0300
> +Subject: [PATCH 1/1] Change zu to lu
> +
> +---
> + tensorflow/lite/optional_debug_tools.cc | 8 ++++----
> + 1 file changed, 4 insertions(+), 4 deletions(-)
> +
> +diff --git a/tensorflow/lite/optional_debug_tools.cc b/tensorflow/lite/optional_debug_tools.cc
> +index a59af3d..c9339b0 100644
> +--- a/tensorflow/lite/optional_debug_tools.cc
> ++++ b/tensorflow/lite/optional_debug_tools.cc
> +@@ -80,7 +80,7 @@ const char* AllocTypeName(TfLiteAllocationType type) {
> +
> + // Prints a dump of what tensors and what nodes are in the interpreter.
> + void PrintInterpreterState(Interpreter* interpreter) {
> +-  printf("Interpreter has %zu tensors and %zu nodes\n",
> ++  printf("Interpreter has %lu tensors and %lu nodes\n",
> +          interpreter->tensors_size(), interpreter->nodes_size());
> +   printf("Inputs:");
> +   PrintIntVector(interpreter->inputs());
> +@@ -90,7 +90,7 @@ void PrintInterpreterState(Interpreter* interpreter) {
> +   for (size_t tensor_index = 0; tensor_index < interpreter->tensors_size();
> +        tensor_index++) {
> +     TfLiteTensor* tensor = interpreter->tensor(static_cast<int>(tensor_index));
> +-    printf("Tensor %3zu %-20s %10s %15s %10zu bytes (%4.1f MB) ", tensor_index,
> ++    printf("Tensor %3lu %-20s %10s %15s %10lu bytes (%4.1f MB) ", tensor_index,
> +            tensor->name, TensorTypeName(tensor->type),
> +            AllocTypeName(tensor->allocation_type), tensor->bytes,
> +            (static_cast<float>(tensor->bytes) / (1 << 20)));
> +@@ -104,10 +104,10 @@ void PrintInterpreterState(Interpreter* interpreter) {
> +     const TfLiteNode& node = node_and_reg->first;
> +     const TfLiteRegistration& reg = node_and_reg->second;
> +     if (reg.custom_name != nullptr) {
> +-      printf("Node %3zu Operator Custom Name %s\n", node_index,
> ++      printf("Node %3lu Operator Custom Name %s\n", node_index,
> +              reg.custom_name);
> +     } else {
> +-      printf("Node %3zu Operator Builtin Code %3d\n", node_index,
> ++      printf("Node %3lu Operator Builtin Code %3d\n", node_index,
> +              reg.builtin_code);
> +     }
> +     printf("  Inputs:");
> +--
> +2.17.1
> +
> --
> 2.25.1
>
>


From minios-devel-bounces@lists.xenproject.org Wed Jul 08 11:16:32 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 08 Jul 2020 11:16:32 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jt83w-0004lN-So; Wed, 08 Jul 2020 11:16:28 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=/lBA=AS=gmail.com=felix.nasch@srs-us1.protection.inumbo.net>)
 id 1jsiqo-0000m4-CR
 for minios-devel@lists.xenproject.org; Tue, 07 Jul 2020 08:21:14 +0000
X-Inumbo-ID: d1e15638-c02a-11ea-b7bb-bc764e2007e4
Received: from mail-wr1-x431.google.com (unknown [2a00:1450:4864:20::431])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id d1e15638-c02a-11ea-b7bb-bc764e2007e4;
 Tue, 07 Jul 2020 08:21:13 +0000 (UTC)
Received: by mail-wr1-x431.google.com with SMTP id k6so44199259wrn.3
 for <minios-devel@lists.xenproject.org>; Tue, 07 Jul 2020 01:21:13 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:from:date:message-id:subject:to;
 bh=cRnK8e1U8lWgA1GPUZWYSMdh9lMu7E9/UuDCxUGuKng=;
 b=d7gxzSlNmuCM3XVNDQa71IGhb+lagdG5kRLNEzB/1eHeAyIB+TwvUMdEPaznCg3Sh+
 ouAWGbYe30RXypNaXrqjYW5/NM+R4DrE7gVV40K7iDcDFd5P8cAd3La2x8RZ4HRx9+zV
 q6VWX1V+6vnD8u+R/7l+RWyvYtmVR+sQjahrgVpFpIHuT6PBnI8ZktB7gycAh36lDEIv
 p2pYY4gemPGxey4dxvBYZS202DCaHExRhwJSHNZE5DJoAUOGv11e/uewPDIXUkzbEvJ5
 lXnRdEV1AvWXEsrGf+prCDh3dMGcO7B3zzCANY5jrcGUeZiKgIjKNcLNeFX/GQ1aOuu3
 POyA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
 bh=cRnK8e1U8lWgA1GPUZWYSMdh9lMu7E9/UuDCxUGuKng=;
 b=aK1oObBBl6eM9ifiS/neOiZJ2cnNaC8ULTNMvBx4lQ5nx8qKG3M2fsyFxnXYB+9CFP
 iSb1oHE1w3To5SMC755pKHPqMSeBBmfl911ZQxauUbewkTDkpq8BEjym/GuAunkaRiEn
 ySUHLBoNf+/3ph3RoOnfvehl+NY+0KHXl+WsOElzOplCWEHhLqS9w0J219PjaIifiFy1
 7bqpoZEYboRoZUL/ndK365UrY++jq9h0/8Kh12OYl5uFEGIUX1kiD8cenYDO9mrrsLnW
 6pl279jg32GPhMWnixdJyL7gvhKvDGS1prUoPMyszgdIyb3GNhDX5X+VDQWnGh6qi0zw
 etsQ==
X-Gm-Message-State: AOAM533bpqvZZ5Y9Ql4JlZuobk9Mj5Jb0z+k66mAd9sC8CvKgE3oIfyZ
 fEgjDooNZbPb28tXLHt82adQz1+pBMaQeksL0dv9RQ==
X-Google-Smtp-Source: ABdhPJyYyBgAyBLjebpwMH9wRkZkkyxRSc56fwancuJYZu5S+PI4xE8658sHmJrqpl6H5NdaN1C2VUV4RHvLuujBpXw=
X-Received: by 2002:a5d:4e48:: with SMTP id r8mr51668392wrt.309.1594110072528; 
 Tue, 07 Jul 2020 01:21:12 -0700 (PDT)
MIME-Version: 1.0
From: felix nasch <felix.nasch@gmail.com>
Date: Tue, 7 Jul 2020 10:21:01 +0200
Message-ID: <CAMEmTtVX__Zkk1ahXRS_3hL9yQxom6zJc8jxqO_yMnr31WfO2g@mail.gmail.com>
Subject: Unikraft makefile - how to copy files in Makefile.uk
To: minios-devel@lists.xenproject.org
Content-Type: text/plain; charset="UTF-8"
X-Mailman-Approved-At: Wed, 08 Jul 2020 11:16:27 +0000
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi,

I was hanging out in the IRC channel, but it seems inactive, so I am
asking here, hope that's ok. :)
I am trying to port a library to Unikraft, and as part of the build process I
want to copy around a few files after extracting the source files.
This is to solve these two problems:

1. Some source files have the same name (in different dirs), but the
unikraft build
    system places all .obj files into the root directory, thus
colliding object files
    overwrite each other. I want to rename conflicting files prior to
compilation.

2. Include paths - when extracting the source package, the include path is not
    how consumers of the library expect it. I would want to create an
appropriately
    named subdir and move the header files into it.

However, I can't figure out how to execute a simple "cp <src> <dest>"
in Makefile.uk,
since new targets cannot be defined.

How can I do that?

Thanks,
f.


From minios-devel-bounces@lists.xenproject.org Wed Jul 08 12:04:56 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 08 Jul 2020 12:04:56 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jt8oo-0000mD-0V; Wed, 08 Jul 2020 12:04:54 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dys+=AT=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jt8om-0000m8-MC
 for minios-devel@lists.xen.org; Wed, 08 Jul 2020 12:04:52 +0000
X-Inumbo-ID: 3929dcf0-c113-11ea-b7bb-bc764e2007e4
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 3929dcf0-c113-11ea-b7bb-bc764e2007e4;
 Wed, 08 Jul 2020 12:04:50 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 3E74F103B6D;
 Wed,  8 Jul 2020 14:04:49 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id UVBAoZOTvF7f; Wed,  8 Jul 2020 14:04:49 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id 08A65103A80
 for <minios-devel@lists.xen.org>; Wed,  8 Jul 2020 14:04:49 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 8 Jul 2020
 14:04:48 +0200
Message-ID: <1594209887.7030.6.camel@neclab.eu>
Subject: Re: [UNIKRAFT PATCH v2 05/15] plat/tap: Get/Set hw_addr
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Sharan Santhanam <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
Date: Wed, 8 Jul 2020 14:04:47 +0200
In-Reply-To: <20200630095825.4127-6-sharan.santhanam@neclab.eu>
References: <20200630095825.4127-1-sharan.santhanam@neclab.eu>
 <20200630095825.4127-6-sharan.santhanam@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Sharan,

Looks good to me so far. I only have a comment/question concerning
tap_mac_generate (inline).

regards,
Hugo

On Tue, 2020-06-30 at 11:58 +0200, Sharan Santhanam wrote:
> The patch implements support for generating a default hw_addr. The
> patch also implements get and set netdev api.
> 
> Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
> ---
> Â plat/drivers/include/tap/tap.hÂ Â Â Â Â Â Â Â Â Â Â Â Â Â |Â Â 2 +
> Â plat/drivers/tap/tap.cÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â | 97
> ++++++++++++++++++++++++++++-
> Â plat/linuxu/include/linuxu/syscall-arm_32.h |Â Â 1 +
> Â plat/linuxu/include/linuxu/syscall-x86_64.h |Â Â 1 +
> Â plat/linuxu/include/linuxu/syscall.hÂ Â Â Â Â Â Â Â | 25 ++++++++
> Â plat/linuxu/include/linuxu/tap.hÂ Â Â Â Â Â Â Â Â Â Â Â |Â Â 7 +++
> Â plat/linuxu/tap_io.cÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â | 31 +++++++++
> Â 7 files changed, 161 insertions(+), 3 deletions(-)
> 
> diff --git a/plat/drivers/include/tap/tap.h
> b/plat/drivers/include/tap/tap.h
> index 3aa90b6..686b666 100644
> --- a/plat/drivers/include/tap/tap.h
> +++ b/plat/drivers/include/tap/tap.h
> @@ -45,5 +45,7 @@
> Â int tap_open(__u32 flags);
> Â int tap_close(int fd);
> Â int tap_dev_configure(int fd, __u32 feature_flags, void *arg);
> +int tap_netif_configure(int fd, __u32 request, void *arg);
> +int tap_netif_create(void);
> Â 
> Â #endif /* __PLAT_DRV_TAP_H */
> diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
> index acf958a..d60ca46 100644
> --- a/plat/drivers/tap/tap.c
> +++ b/plat/drivers/tap/tap.c
> @@ -92,12 +92,16 @@ struct tap_net_dev {
> Â 	UK_TAILQ_HEAD(tap_txqs, struct uk_netdev_tx_queue) txqs;
> Â 	/* The list of the tap device */
> Â 	UK_TAILQ_ENTRY(struct tap_net_dev) next;
> +	/* Mac address of the device */
> +	struct uk_hwaddr hw_addr;
> Â 	/* Tap Device identifier */
> Â 	__u16 tid;
> Â 	/* UK Netdevice identifier */
> Â 	__u16 id;
> Â 	/* File Descriptor for the tap device */
> Â 	int tap_fd;
> +	/* Control socket descriptor */
> +	int ctrl_sock;
> Â 	/* Name of the character device */
> Â 	char name[IFNAMSIZ];
> Â 	/* MTU of the device */
> @@ -170,6 +174,7 @@ static int tap_netdev_rxq_info_get(struct
> uk_netdev *dev, __u16 queue_id,
> Â static int tap_netdev_txq_info_get(struct uk_netdev *dev, __u16
> queue_id,
> Â 				Â Â Â struct uk_netdev_queue_info
> *qinfo);
> Â static int tap_device_create(struct tap_net_dev *tdev, __u32
> feature_flags);
> +static int tap_mac_generate(__u8 *addr, int len, __u8 dev_id);
> Â 
> Â /**
> Â  * Local function definitions
> @@ -284,16 +289,78 @@ static int tap_netdev_mtu_set(struct uk_netdev
> *n,Â Â __u16 mtu __unused)
> Â 
> Â static const struct uk_hwaddr *tap_netdev_mac_get(struct uk_netdev
> *n)
> Â {
> +	struct tap_net_dev *tdev;
> +
> Â 	UK_ASSERT(n);
> -	return NULL;
> +	tdev = to_tapnetdev(n);
> +	return &tdev->hw_addr;
> Â }
> Â 
> Â static int tap_netdev_mac_set(struct uk_netdev *n,
> Â 			Â Â Â Â Â Â const struct uk_hwaddr *hwaddr)
> Â {
> -	int rc = -EINVAL;
> +	int rc = 0;
> +	struct tap_net_dev *tdev;
> +	struct uk_ifreq ifrq = {0};
> Â 
> Â 	UK_ASSERT(n && hwaddr);
> +	tdev = to_tapnetdev(n);
> +
> +	snprintf(ifrq.ifr_name, sizeof(ifrq.ifr_name), "%s", tdev-
> >name);
> +	uk_pr_info("Setting mac address on tap device %s\n", tdev-
> >name);
> +
> +#ifdef CONFIG_TAP_DEV_DEBUG
> +	intÂ Â i;
> +
> +	for (i = 0; i < UK_NETDEV_HWADDR_LEN; i++) {
> +		uk_pr_debug("hw_address: %d - %d\n", i,
> +			Â Â Â Â hwaddr->addr_bytes[i] & 0xFF);
> +	}
> +#endif /* CONFIG_TAP_DEV_DEBUG */
> +
> +	ifrq.ifr_hwaddr.sa_family = AF_LOCAL;
> +	memcpy(&ifrq.ifr_hwaddr.sa_data[0], &hwaddr->addr_bytes[0],
> +		UK_NETDEV_HWADDR_LEN);
> +	rc = tap_netif_configure(tdev->ctrl_sock, UK_SIOCSIFHWADDR,
> &ifrq);
> +	if (rc < 0) {
> +		uk_pr_err(DRIVER_NAME": Failed(%d) to set the
> hardware address\n",
> +			Â Â rc);
> +		goto exit;
> +	}
> +	memcpy(&tdev->hw_addr, hwaddr, sizeof(*hwaddr));
> +
> +exit:
> +	return rc;
> +}
> +
> +static int tap_mac_generate(__u8 *addr, int len, __u8 dev_id)
> +{
> +	const char fmt[] = {0x2, 0x0, 0x0, 0x0, 0x0, 0x0};
> +
> +	UK_ASSERT(addr && len > 0);
> +
> +	if (len < UK_NETDEV_HWADDR_LEN) {
> +		uk_pr_err("Failed to generate the mac address\n");
> +		return -ENOSPC;
> +	}

What is the point of this `len` argument?

What happens if `len` is larger thanÂ UK_NETDEV_HWADDR_LEN?

To me this might result in OOB read if the caller assumes that `addr`
contains `len` > UK_NETDEV_HWADDR_LEN bytes of address data upon
returning of this function.

> +	memcpy(addr, fmt, UK_NETDEV_HWADDR_LEN - 1);
> +	*(addr + UK_NETDEV_HWADDR_LEN - 1) = (__u8) (dev_id + 1);
> +	return 0;
> +}
> +
> +static inline int tapdev_ctrlsock_create(struct tap_net_dev *tdev)
> +{
> +	int rc = 0;
> +
> +	rc = tap_netif_create();
> +	if (rc < 0) {
> +		uk_pr_err(DRIVER_NAME":Failed(%d) to create a
> control socket\n",
> +			Â Â rc);
> +		goto exit;
> +	}
> +	tdev->ctrl_sock = rc;
> +	rc = 0;
> +exit:
> Â 	return rc;
> Â }
> Â 
> @@ -328,13 +395,37 @@ static int tap_netdev_configure(struct
> uk_netdev *n,
> Â 		goto exit;
> Â 	}
> Â 
> -	/* Initialize tx/rx queues list */
> +	/* Create a control socket for the network interface */
> +	rc = tapdev_ctrlsock_create(tdev);
> +	if (rc != 0) {
> +		uk_pr_err(DRIVER_NAME": Failed to create a control
> socket\n");
> +		goto close_tap_dev;
> +	}
> +
> +	/* Generate MAC address */
> +	tap_mac_generate(&tdev->hw_addr.addr_bytes[0],
> UK_NETDEV_HWADDR_LEN,
> +			Â tdev->id);
> +
> +	/* MAC Address configuration */
> +	rc = tap_netdev_mac_set(n, &tdev->hw_addr);
> +	if (rc < 0) {
> +		uk_pr_err(DRIVER_NAME": Failed to set the mac
> address\n");
> +		goto close_ctrl_sock;
> +	}
> +
> +	/* Initialize the tx/rx queues */
> Â 	UK_TAILQ_INIT(&tdev->rxqs);
> Â 	tdev->rxq_cnt = 0;
> Â 	UK_TAILQ_INIT(&tdev->txqs);
> Â 	tdev->txq_cnt = 0;
> Â exit:
> Â 	return rc;
> +
> +close_ctrl_sock:
> +	tap_close(tdev->ctrl_sock);
> +close_tap_dev:
> +	tap_close(tdev->tap_fd);
> +	goto exit;
> Â }
> Â 
> Â static int tap_device_create(struct tap_net_dev *tdev, __u32
> feature_flags)
> diff --git a/plat/linuxu/include/linuxu/syscall-arm_32.h
> b/plat/linuxu/include/linuxu/syscall-arm_32.h
> index 093fd62..4b7218b 100644
> --- a/plat/linuxu/include/linuxu/syscall-arm_32.h
> +++ b/plat/linuxu/include/linuxu/syscall-arm_32.h
> @@ -56,6 +56,7 @@
> Â #define __SC_TIMER_GETOVERRUN 260
> Â #define __SC_TIMER_DELETEÂ Â Â Â Â 261
> Â #define __SC_CLOCK_GETTIMEÂ Â Â Â 263
> +#define __SC_SOCKETÂ Â Â Â Â Â Â Â Â Â Â 281
> Â #define __SC_PSELECT6 335
> Â 
> Â #ifndef O_TMPFILE
> diff --git a/plat/linuxu/include/linuxu/syscall-x86_64.h
> b/plat/linuxu/include/linuxu/syscall-x86_64.h
> index c4b88fc..8714c92 100644
> --- a/plat/linuxu/include/linuxu/syscall-x86_64.h
> +++ b/plat/linuxu/include/linuxu/syscall-x86_64.h
> @@ -47,6 +47,7 @@
> Â #define __SC_RT_SIGACTIONÂ Â Â 13
> Â #define __SC_RT_SIGPROCMASK 14
> Â #define __SC_IOCTLÂ Â 16
> +#define __SC_SOCKET 41
> Â #define __SC_EXITÂ Â Â 60
> Â #define __SC_FCNTLÂ Â 72
> Â #define __SC_ARCH_PRCTLÂ Â Â Â Â Â Â 158
> diff --git a/plat/linuxu/include/linuxu/syscall.h
> b/plat/linuxu/include/linuxu/syscall.h
> index 2c613fc..ad6f038 100644
> --- a/plat/linuxu/include/linuxu/syscall.h
> +++ b/plat/linuxu/include/linuxu/syscall.h
> @@ -125,6 +125,31 @@ static inline int sys_close(int fd)
> Â 				Â Â (long) fd);
> Â }
> Â 
> +#ifndef SOCK_STREAM
> +#define SOCK_STREAMÂ Â Â Â 1
> +#endif /* SOCK_STREAM */
> +#ifndef SOCK_DGRAM
> +#define SOCK_DGRAMÂ Â Â Â Â 2
> +#endif /* SOCK_DGRAM */
> +
> +#ifndef SOCK_RAW
> +#define SOCK_RAWÂ Â Â Â Â Â Â 3
> +#endif /* SOCK_RAW */
> +
> +#ifndef AF_LOCAL
> +#define AF_LOCALÂ Â Â Â Â Â Â 1
> +#endif /* AF_LOCAL */
> +#ifndef AF_INET
> +#define AF_INETÂ Â Â Â Â Â Â Â 2
> +#endif /* AF_INET */
> +static inline int sys_socket(int domain, int type, int protocol)
> +{
> +	return (ssize_t) syscall3(__SC_SOCKET,
> +				Â Â (long) domain,
> +				Â Â (long) type,
> +				Â Â (long) protocol);
> +}
> +
> Â static inline int sys_exit(int status)
> Â {
> Â 	return (int) syscall1(__SC_EXIT,
> diff --git a/plat/linuxu/include/linuxu/tap.h
> b/plat/linuxu/include/linuxu/tap.h
> index 65e6eb5..0f3a644 100644
> --- a/plat/linuxu/include/linuxu/tap.h
> +++ b/plat/linuxu/include/linuxu/tap.h
> @@ -58,6 +58,13 @@ struct uk_in_addr {
> Â 	uk_in_addr_t s_addr;
> Â };
> Â 
> +struct uk_sockaddr_in {
> +	uk_sa_family_t sin_family;
> +	uk_in_port_t sin_port;
> +	struct uk_in_addr sin_addr;
> +	__u8 sin_zero[8];
> +};
> +
> Â struct uk_sockaddr {
> Â 	uk_sa_family_t sa_family;
> Â 	char sa_data[14];
> diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
> index 118bee8..888ef83 100644
> --- a/plat/linuxu/tap_io.c
> +++ b/plat/linuxu/tap_io.c
> @@ -61,6 +61,37 @@ int tap_dev_configure(int fd, __u32 feature_flags,
> void *arg)
> Â 	return rc;
> Â }
> Â 
> +int tap_netif_configure(int fd, __u32 request, void *arg)
> +{
> +	int rc;
> +	struct uk_ifreq *usr_ifr = (struct uk_ifreq *) arg;
> +
> +	switch (request) {
> +	case UK_SIOCGIFHWADDR:
> +	case UK_SIOCSIFHWADDR:
> +		break;
> +	default:
> +		rc = -EINVAL;
> +		uk_pr_err("Invalid ioctl request\n");
> +		goto exit_error;
> +	}
> +
> +	if ((rc = sys_ioctl(fd, request, usr_ifr)) < 0) {
> +		uk_pr_err("Failed to set device control %d\n", rc);
> +		goto exit_error;
> +	}
> +
> +	return 0;
> +
> +exit_error:
> +	return rc;
> +}
> +
> +int tap_netif_create(void)
> +{
> +	return sys_socket(AF_INET, SOCK_DGRAM, 0);
> +}
> +
> Â int tap_close(int fd)
> Â {
> Â 	return sys_close(fd);


From minios-devel-bounces@lists.xenproject.org Wed Jul 08 12:37:17 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 08 Jul 2020 12:37:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jt9K6-0003C2-B3; Wed, 08 Jul 2020 12:37:14 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=GT+K=AT=neclab.eu=felipe.huici@srs-us1.protection.inumbo.net>)
 id 1jt9K5-0003Bx-GU
 for minios-devel@lists.xenproject.org; Wed, 08 Jul 2020 12:37:13 +0000
X-Inumbo-ID: b69a9fc2-c117-11ea-b7bb-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id b69a9fc2-c117-11ea-b7bb-bc764e2007e4;
 Wed, 08 Jul 2020 12:36:59 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 9E317F2009;
 Wed,  8 Jul 2020 14:36:57 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id ZEfXDoUz74hH; Wed,  8 Jul 2020 14:36:57 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 6C372F2007;
 Wed,  8 Jul 2020 14:36:53 +0200 (CEST)
Received: from oberon.office.hd (192.168.24.90) by titania.office.hd
 (192.168.24.89) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 8 Jul 2020
 14:36:53 +0200
Received: from oberon.office.hd ([192.168.126.11]) by Oberon.office.hd
 ([192.168.126.11]) with mapi id 15.01.1979.003; Wed, 8 Jul 2020 14:36:53
 +0200
From: Felipe Huici <Felipe.Huici@neclab.eu>
To: felix nasch <felix.nasch@gmail.com>, "minios-devel@lists.xenproject.org"
 <minios-devel@lists.xenproject.org>
Subject: Re: Unikraft makefile - how to copy files in Makefile.uk
Thread-Topic: Unikraft makefile - how to copy files in Makefile.uk
Thread-Index: AQHWVRlU4haHPK8ej0e/mqBYx5q6Qaj9nrYA
Date: Wed, 8 Jul 2020 12:36:52 +0000
Message-ID: <7DB2836F-D3D7-4B32-8452-38AFF654CF39@neclab.eu>
References: <CAMEmTtVX__Zkk1ahXRS_3hL9yQxom6zJc8jxqO_yMnr31WfO2g@mail.gmail.com>
In-Reply-To: <CAMEmTtVX__Zkk1ahXRS_3hL9yQxom6zJc8jxqO_yMnr31WfO2g@mail.gmail.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
user-agent: Microsoft-MacOutlook/10.10.17.200615
x-originating-ip: [192.168.24.96]
Content-Type: text/plain; charset="utf-8"
Content-ID: <157C03F94485CF49913D4FA87958436E@office.hd>
Content-Transfer-Encoding: base64
MIME-Version: 1.0
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

SGkgRmVsaXgsIG5vdCBzdXJlIGlmIHRoaXMgaXMgYSByZS1zZW5kLCBidXQganVzdCBpbiBjYXNl
OiBTaGFyYW4gd3JvdGUgYmFjayB0byB5b3UgeWVzdGVyZGF5Lg0KDQpUaGFua3MsDQoNCi0tIEZl
bGlwZQ0KDQrvu79PbiAwOC4wNy4yMCwgMTM6MTcsICJNaW5pb3MtZGV2ZWwgb24gYmVoYWxmIG9m
IGZlbGl4IG5hc2NoIiA8bWluaW9zLWRldmVsLWJvdW5jZXNAbGlzdHMueGVucHJvamVjdC5vcmcg
b24gYmVoYWxmIG9mIGZlbGl4Lm5hc2NoQGdtYWlsLmNvbT4gd3JvdGU6DQoNCiAgICBIaSwNCiAg
ICANCiAgICBJIHdhcyBoYW5naW5nIG91dCBpbiB0aGUgSVJDIGNoYW5uZWwsIGJ1dCBpdCBzZWVt
cyBpbmFjdGl2ZSwgc28gSSBhbQ0KICAgIGFza2luZyBoZXJlLCBob3BlIHRoYXQncyBvay4gOikN
CiAgICBJIGFtIHRyeWluZyB0byBwb3J0IGEgbGlicmFyeSB0byBVbmlrcmFmdCwgYW5kIGFzIHBh
cnQgb2YgdGhlIGJ1aWxkIHByb2Nlc3MgSQ0KICAgIHdhbnQgdG8gY29weSBhcm91bmQgYSBmZXcg
ZmlsZXMgYWZ0ZXIgZXh0cmFjdGluZyB0aGUgc291cmNlIGZpbGVzLg0KICAgIFRoaXMgaXMgdG8g
c29sdmUgdGhlc2UgdHdvIHByb2JsZW1zOg0KICAgIA0KICAgIDEuIFNvbWUgc291cmNlIGZpbGVz
IGhhdmUgdGhlIHNhbWUgbmFtZSAoaW4gZGlmZmVyZW50IGRpcnMpLCBidXQgdGhlDQogICAgdW5p
a3JhZnQgYnVpbGQNCiAgICAgICAgc3lzdGVtIHBsYWNlcyBhbGwgLm9iaiBmaWxlcyBpbnRvIHRo
ZSByb290IGRpcmVjdG9yeSwgdGh1cw0KICAgIGNvbGxpZGluZyBvYmplY3QgZmlsZXMNCiAgICAg
ICAgb3ZlcndyaXRlIGVhY2ggb3RoZXIuIEkgd2FudCB0byByZW5hbWUgY29uZmxpY3RpbmcgZmls
ZXMgcHJpb3IgdG8NCiAgICBjb21waWxhdGlvbi4NCiAgICANCiAgICAyLiBJbmNsdWRlIHBhdGhz
IC0gd2hlbiBleHRyYWN0aW5nIHRoZSBzb3VyY2UgcGFja2FnZSwgdGhlIGluY2x1ZGUgcGF0aCBp
cyBub3QNCiAgICAgICAgaG93IGNvbnN1bWVycyBvZiB0aGUgbGlicmFyeSBleHBlY3QgaXQuIEkg
d291bGQgd2FudCB0byBjcmVhdGUgYW4NCiAgICBhcHByb3ByaWF0ZWx5DQogICAgICAgIG5hbWVk
IHN1YmRpciBhbmQgbW92ZSB0aGUgaGVhZGVyIGZpbGVzIGludG8gaXQuDQogICAgDQogICAgSG93
ZXZlciwgSSBjYW4ndCBmaWd1cmUgb3V0IGhvdyB0byBleGVjdXRlIGEgc2ltcGxlICJjcCA8c3Jj
PiA8ZGVzdD4iDQogICAgaW4gTWFrZWZpbGUudWssDQogICAgc2luY2UgbmV3IHRhcmdldHMgY2Fu
bm90IGJlIGRlZmluZWQuDQogICAgDQogICAgSG93IGNhbiBJIGRvIHRoYXQ/DQogICAgDQogICAg
VGhhbmtzLA0KICAgIGYuDQogICAgDQogICAgDQoNCg==


From minios-devel-bounces@lists.xenproject.org Wed Jul 08 12:38:24 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 08 Jul 2020 12:38:24 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jt9LD-0003EU-FD; Wed, 08 Jul 2020 12:38:23 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dys+=AT=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jt9LC-0003EP-9p
 for minios-devel@lists.xen.org; Wed, 08 Jul 2020 12:38:22 +0000
X-Inumbo-ID: e74f1c1a-c117-11ea-bca7-bc764e2007e4
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id e74f1c1a-c117-11ea-bca7-bc764e2007e4;
 Wed, 08 Jul 2020 12:38:20 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 73E21103732;
 Wed,  8 Jul 2020 14:38:19 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id kbPHozaudmeb; Wed,  8 Jul 2020 14:38:19 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id 4BEF6FFAD0
 for <minios-devel@lists.xen.org>; Wed,  8 Jul 2020 14:38:19 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 8 Jul 2020
 14:38:18 +0200
Message-ID: <1594211897.7030.14.camel@neclab.eu>
Subject: Re: [UNIKRAFT PATCH v2 05/15] plat/tap: Get/Set hw_addr
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Sharan Santhanam <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
Date: Wed, 8 Jul 2020 14:38:17 +0200
In-Reply-To: <1594209887.7030.6.camel@neclab.eu>
References: <20200630095825.4127-1-sharan.santhanam@neclab.eu>
 <20200630095825.4127-6-sharan.santhanam@neclab.eu>
 <1594209887.7030.6.camel@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi,

update on my comments/questions after a discussion off-list with
Sharan.

thanks!

Hugo

On Wed, 2020-07-08 at 14:04 +0200, Hugo Lefeuvre wrote:
> Hi Sharan,
> 
> Looks good to me so far. I only have a comment/question concerning
> tap_mac_generate (inline).
> 
> regards,
> Hugo
> 
> On Tue, 2020-06-30 at 11:58 +0200, Sharan Santhanam wrote:
> > 
> > The patch implements support for generating a default hw_addr. The
> > patch also implements get and set netdev api.
> > 
> > Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
> > ---
> > Â plat/drivers/include/tap/tap.hÂ Â Â Â Â Â Â Â Â Â Â Â Â Â |Â Â 2 +
> > Â plat/drivers/tap/tap.cÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â | 97
> > ++++++++++++++++++++++++++++-
> > Â plat/linuxu/include/linuxu/syscall-arm_32.h |Â Â 1 +
> > Â plat/linuxu/include/linuxu/syscall-x86_64.h |Â Â 1 +
> > Â plat/linuxu/include/linuxu/syscall.hÂ Â Â Â Â Â Â Â | 25 ++++++++
> > Â plat/linuxu/include/linuxu/tap.hÂ Â Â Â Â Â Â Â Â Â Â Â |Â Â 7 +++
> > Â plat/linuxu/tap_io.cÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â | 31 +++++++++
> > Â 7 files changed, 161 insertions(+), 3 deletions(-)
> > 
> > diff --git a/plat/drivers/include/tap/tap.h
> > b/plat/drivers/include/tap/tap.h
> > index 3aa90b6..686b666 100644
> > --- a/plat/drivers/include/tap/tap.h
> > +++ b/plat/drivers/include/tap/tap.h
> > @@ -45,5 +45,7 @@
> > Â int tap_open(__u32 flags);
> > Â int tap_close(int fd);
> > Â int tap_dev_configure(int fd, __u32 feature_flags, void *arg);
> > +int tap_netif_configure(int fd, __u32 request, void *arg);
> > +int tap_netif_create(void);
> > Â 
> > Â #endif /* __PLAT_DRV_TAP_H */
> > diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
> > index acf958a..d60ca46 100644
> > --- a/plat/drivers/tap/tap.c
> > +++ b/plat/drivers/tap/tap.c
> > @@ -92,12 +92,16 @@ struct tap_net_dev {
> > Â 	UK_TAILQ_HEAD(tap_txqs, struct uk_netdev_tx_queue) txqs;
> > Â 	/* The list of the tap device */
> > Â 	UK_TAILQ_ENTRY(struct tap_net_dev) next;
> > +	/* Mac address of the device */
> > +	struct uk_hwaddr hw_addr;
> > Â 	/* Tap Device identifier */
> > Â 	__u16 tid;
> > Â 	/* UK Netdevice identifier */
> > Â 	__u16 id;
> > Â 	/* File Descriptor for the tap device */
> > Â 	int tap_fd;
> > +	/* Control socket descriptor */
> > +	int ctrl_sock;
> > Â 	/* Name of the character device */
> > Â 	char name[IFNAMSIZ];
> > Â 	/* MTU of the device */
> > @@ -170,6 +174,7 @@ static int tap_netdev_rxq_info_get(struct
> > uk_netdev *dev, __u16 queue_id,
> > Â static int tap_netdev_txq_info_get(struct uk_netdev *dev, __u16
> > queue_id,
> > Â 				Â Â Â struct uk_netdev_queue_info
> > *qinfo);
> > Â static int tap_device_create(struct tap_net_dev *tdev, __u32
> > feature_flags);
> > +static int tap_mac_generate(__u8 *addr, int len, __u8 dev_id);
> > Â 
> > Â /**
> > Â  * Local function definitions
> > @@ -284,16 +289,78 @@ static int tap_netdev_mtu_set(struct
> > uk_netdev
> > *n,Â Â __u16 mtu __unused)
> > Â 
> > Â static const struct uk_hwaddr *tap_netdev_mac_get(struct uk_netdev
> > *n)
> > Â {
> > +	struct tap_net_dev *tdev;
> > +
> > Â 	UK_ASSERT(n);
> > -	return NULL;
> > +	tdev = to_tapnetdev(n);
> > +	return &tdev->hw_addr;
> > Â }
> > Â 
> > Â static int tap_netdev_mac_set(struct uk_netdev *n,
> > Â 			Â Â Â Â Â Â const struct uk_hwaddr *hwaddr)
> > Â {
> > -	int rc = -EINVAL;
> > +	int rc = 0;
> > +	struct tap_net_dev *tdev;
> > +	struct uk_ifreq ifrq = {0};
> > Â 
> > Â 	UK_ASSERT(n && hwaddr);
> > +	tdev = to_tapnetdev(n);
> > +
> > +	snprintf(ifrq.ifr_name, sizeof(ifrq.ifr_name), "%s", tdev-
> > > 
> > > name);
> > +	uk_pr_info("Setting mac address on tap device %s\n", tdev-
> > > 
> > > name);
> > +
> > +#ifdef CONFIG_TAP_DEV_DEBUG
> > +	intÂ Â i;
> > +
> > +	for (i = 0; i < UK_NETDEV_HWADDR_LEN; i++) {
> > +		uk_pr_debug("hw_address: %d - %d\n", i,
> > +			Â Â Â Â hwaddr->addr_bytes[i] & 0xFF);
> > +	}
> > +#endif /* CONFIG_TAP_DEV_DEBUG */
> > +
> > +	ifrq.ifr_hwaddr.sa_family = AF_LOCAL;
> > +	memcpy(&ifrq.ifr_hwaddr.sa_data[0], &hwaddr-
> > >addr_bytes[0],
> > +		UK_NETDEV_HWADDR_LEN);
> > +	rc = tap_netif_configure(tdev->ctrl_sock,
> > UK_SIOCSIFHWADDR,
> > &ifrq);
> > +	if (rc < 0) {
> > +		uk_pr_err(DRIVER_NAME": Failed(%d) to set the
> > hardware address\n",
> > +			Â Â rc);
> > +		goto exit;
> > +	}
> > +	memcpy(&tdev->hw_addr, hwaddr, sizeof(*hwaddr));
> > +
> > +exit:
> > +	return rc;
> > +}
> > +
> > +static int tap_mac_generate(__u8 *addr, int len, __u8 dev_id)
> > +{
> > +	const char fmt[] = {0x2, 0x0, 0x0, 0x0, 0x0, 0x0};
> > +
> > +	UK_ASSERT(addr && len > 0);
> > +
> > +	if (len < UK_NETDEV_HWADDR_LEN) {
> > +		uk_pr_err("Failed to generate the mac address\n");
> > +		return -ENOSPC;
> > +	}
> What is the point of this `len` argument?
> 
> What happens if `len` is larger thanÂ UK_NETDEV_HWADDR_LEN?
> 

The idea of this `len` argument was to pass the size of the addr
buffer. tap_mac_generate can then verify that it is big enough to hold
the mac address.

However, this is an internal function so we can assume that the caller
passes a sufficiently large buffer. And in any case, there's no point
in providing tap_mac_generate with a buffer that is not big enough to
hold a mac address...

Let's just remove this argument altogether?

> To me this might result in OOB read if the caller assumes that `addr`
> contains `len` > UK_NETDEV_HWADDR_LEN bytes of address data upon
> returning of this function.

My bad, this is no OOB read, more a read of uninitialized data.

> 
> > 
> > +	memcpy(addr, fmt, UK_NETDEV_HWADDR_LEN - 1);
> > +	*(addr + UK_NETDEV_HWADDR_LEN - 1) = (__u8) (dev_id + 1);
> > +	return 0;
> > +}
> > +
> > +static inline int tapdev_ctrlsock_create(struct tap_net_dev *tdev)
> > +{
> > +	int rc = 0;
> > +
> > +	rc = tap_netif_create();
> > +	if (rc < 0) {
> > +		uk_pr_err(DRIVER_NAME":Failed(%d) to create a
> > control socket\n",
> > +			Â Â rc);
> > +		goto exit;
> > +	}
> > +	tdev->ctrl_sock = rc;
> > +	rc = 0;
> > +exit:
> > Â 	return rc;
> > Â }
> > Â 
> > @@ -328,13 +395,37 @@ static int tap_netdev_configure(struct
> > uk_netdev *n,
> > Â 		goto exit;
> > Â 	}
> > Â 
> > -	/* Initialize tx/rx queues list */
> > +	/* Create a control socket for the network interface */
> > +	rc = tapdev_ctrlsock_create(tdev);
> > +	if (rc != 0) {
> > +		uk_pr_err(DRIVER_NAME": Failed to create a control
> > socket\n");
> > +		goto close_tap_dev;
> > +	}
> > +
> > +	/* Generate MAC address */
> > +	tap_mac_generate(&tdev->hw_addr.addr_bytes[0],
> > UK_NETDEV_HWADDR_LEN,
> > +			Â tdev->id);
> > +
> > +	/* MAC Address configuration */
> > +	rc = tap_netdev_mac_set(n, &tdev->hw_addr);
> > +	if (rc < 0) {
> > +		uk_pr_err(DRIVER_NAME": Failed to set the mac
> > address\n");
> > +		goto close_ctrl_sock;
> > +	}
> > +
> > +	/* Initialize the tx/rx queues */
> > Â 	UK_TAILQ_INIT(&tdev->rxqs);
> > Â 	tdev->rxq_cnt = 0;
> > Â 	UK_TAILQ_INIT(&tdev->txqs);
> > Â 	tdev->txq_cnt = 0;
> > Â exit:
> > Â 	return rc;
> > +
> > +close_ctrl_sock:
> > +	tap_close(tdev->ctrl_sock);
> > +close_tap_dev:
> > +	tap_close(tdev->tap_fd);
> > +	goto exit;
> > Â }
> > Â 
> > Â static int tap_device_create(struct tap_net_dev *tdev, __u32
> > feature_flags)
> > diff --git a/plat/linuxu/include/linuxu/syscall-arm_32.h
> > b/plat/linuxu/include/linuxu/syscall-arm_32.h
> > index 093fd62..4b7218b 100644
> > --- a/plat/linuxu/include/linuxu/syscall-arm_32.h
> > +++ b/plat/linuxu/include/linuxu/syscall-arm_32.h
> > @@ -56,6 +56,7 @@
> > Â #define __SC_TIMER_GETOVERRUN 260
> > Â #define __SC_TIMER_DELETEÂ Â Â Â Â 261
> > Â #define __SC_CLOCK_GETTIMEÂ Â Â Â 263
> > +#define __SC_SOCKETÂ Â Â Â Â Â Â Â Â Â Â 281
> > Â #define __SC_PSELECT6 335
> > Â 
> > Â #ifndef O_TMPFILE
> > diff --git a/plat/linuxu/include/linuxu/syscall-x86_64.h
> > b/plat/linuxu/include/linuxu/syscall-x86_64.h
> > index c4b88fc..8714c92 100644
> > --- a/plat/linuxu/include/linuxu/syscall-x86_64.h
> > +++ b/plat/linuxu/include/linuxu/syscall-x86_64.h
> > @@ -47,6 +47,7 @@
> > Â #define __SC_RT_SIGACTIONÂ Â Â 13
> > Â #define __SC_RT_SIGPROCMASK 14
> > Â #define __SC_IOCTLÂ Â 16
> > +#define __SC_SOCKET 41
> > Â #define __SC_EXITÂ Â Â 60
> > Â #define __SC_FCNTLÂ Â 72
> > Â #define __SC_ARCH_PRCTLÂ Â Â Â Â Â Â 158
> > diff --git a/plat/linuxu/include/linuxu/syscall.h
> > b/plat/linuxu/include/linuxu/syscall.h
> > index 2c613fc..ad6f038 100644
> > --- a/plat/linuxu/include/linuxu/syscall.h
> > +++ b/plat/linuxu/include/linuxu/syscall.h
> > @@ -125,6 +125,31 @@ static inline int sys_close(int fd)
> > Â 				Â Â (long) fd);
> > Â }
> > Â 
> > +#ifndef SOCK_STREAM
> > +#define SOCK_STREAMÂ Â Â Â 1
> > +#endif /* SOCK_STREAM */
> > +#ifndef SOCK_DGRAM
> > +#define SOCK_DGRAMÂ Â Â Â Â 2
> > +#endif /* SOCK_DGRAM */
> > +
> > +#ifndef SOCK_RAW
> > +#define SOCK_RAWÂ Â Â Â Â Â Â 3
> > +#endif /* SOCK_RAW */
> > +
> > +#ifndef AF_LOCAL
> > +#define AF_LOCALÂ Â Â Â Â Â Â 1
> > +#endif /* AF_LOCAL */
> > +#ifndef AF_INET
> > +#define AF_INETÂ Â Â Â Â Â Â Â 2
> > +#endif /* AF_INET */
> > +static inline int sys_socket(int domain, int type, int protocol)
> > +{
> > +	return (ssize_t) syscall3(__SC_SOCKET,
> > +				Â Â (long) domain,
> > +				Â Â (long) type,
> > +				Â Â (long) protocol);
> > +}
> > +
> > Â static inline int sys_exit(int status)
> > Â {
> > Â 	return (int) syscall1(__SC_EXIT,
> > diff --git a/plat/linuxu/include/linuxu/tap.h
> > b/plat/linuxu/include/linuxu/tap.h
> > index 65e6eb5..0f3a644 100644
> > --- a/plat/linuxu/include/linuxu/tap.h
> > +++ b/plat/linuxu/include/linuxu/tap.h
> > @@ -58,6 +58,13 @@ struct uk_in_addr {
> > Â 	uk_in_addr_t s_addr;
> > Â };
> > Â 
> > +struct uk_sockaddr_in {
> > +	uk_sa_family_t sin_family;
> > +	uk_in_port_t sin_port;
> > +	struct uk_in_addr sin_addr;
> > +	__u8 sin_zero[8];
> > +};
> > +
> > Â struct uk_sockaddr {
> > Â 	uk_sa_family_t sa_family;
> > Â 	char sa_data[14];
> > diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
> > index 118bee8..888ef83 100644
> > --- a/plat/linuxu/tap_io.c
> > +++ b/plat/linuxu/tap_io.c
> > @@ -61,6 +61,37 @@ int tap_dev_configure(int fd, __u32
> > feature_flags,
> > void *arg)
> > Â 	return rc;
> > Â }
> > Â 
> > +int tap_netif_configure(int fd, __u32 request, void *arg)
> > +{
> > +	int rc;
> > +	struct uk_ifreq *usr_ifr = (struct uk_ifreq *) arg;
> > +
> > +	switch (request) {
> > +	case UK_SIOCGIFHWADDR:
> > +	case UK_SIOCSIFHWADDR:
> > +		break;
> > +	default:
> > +		rc = -EINVAL;
> > +		uk_pr_err("Invalid ioctl request\n");
> > +		goto exit_error;
> > +	}
> > +
> > +	if ((rc = sys_ioctl(fd, request, usr_ifr)) < 0) {
> > +		uk_pr_err("Failed to set device control %d\n",
> > rc);
> > +		goto exit_error;
> > +	}
> > +
> > +	return 0;
> > +
> > +exit_error:
> > +	return rc;
> > +}
> > +
> > +int tap_netif_create(void)
> > +{
> > +	return sys_socket(AF_INET, SOCK_DGRAM, 0);
> > +}
> > +
> > Â int tap_close(int fd)
> > Â {
> > Â 	return sys_close(fd);


From minios-devel-bounces@lists.xenproject.org Wed Jul 08 13:25:20 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 08 Jul 2020 13:25:20 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jtA4c-0007im-Dn; Wed, 08 Jul 2020 13:25:18 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dys+=AT=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jtA4a-0007if-J0
 for minios-devel@lists.xen.org; Wed, 08 Jul 2020 13:25:16 +0000
X-Inumbo-ID: 748c85ee-c11e-11ea-b7bb-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 748c85ee-c11e-11ea-b7bb-bc764e2007e4;
 Wed, 08 Jul 2020 13:25:14 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 5649EF200A;
 Wed,  8 Jul 2020 15:25:13 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 9NtkzNMLHgZF; Wed,  8 Jul 2020 15:25:13 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 17B07F2009
 for <minios-devel@lists.xen.org>; Wed,  8 Jul 2020 15:25:11 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 8 Jul 2020
 15:25:10 +0200
Message-ID: <1594214709.7030.25.camel@neclab.eu>
Subject: Re: [UNIKRAFT PATCH v2 15/15] plat/linuxu: Convert linux errno to
 unikraft errno
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Sharan Santhanam <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
Date: Wed, 8 Jul 2020 15:25:09 +0200
In-Reply-To: <20200630095825.4127-16-sharan.santhanam@neclab.eu>
References: <20200630095825.4127-1-sharan.santhanam@neclab.eu>
 <20200630095825.4127-16-sharan.santhanam@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Sharan,

this patch is enough for a first release of the tap driver, however it
should probably not be our final solution. EAGAIN is not the only error
code that has this problem; EDQUOT and EDESTADDRREQ for instance are
both returned by the write system call and differ between Linux and
BSD/Unikraft.

I think that a better solution would be to have a linuxu_errno_conv()
function that converts errno from Linux to Unikraft/BSD in a clean and
generic way.

I added a few more specific comments inline.

thanks!

regards,
Hugo

On Tue, 2020-06-30 at 11:58 +0200, Sharan Santhanam wrote:
> There are differences in errno between linux and unikraft. This patch
> converts EAGAIN which is 11 in linux to unikraft which is 35.
> 
> Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
> ---
> Â plat/linuxu/tap_io.c | 12 ++++++++++--
> Â 1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
> index 030c192..ac1d0ae 100644
> --- a/plat/linuxu/tap_io.c
> +++ b/plat/linuxu/tap_io.c
> @@ -117,7 +117,10 @@ ssize_t tap_read(int fd, void *buf, size_t
> count)
> Â 	while (rc == -EINTR)
> Â 		rc = sys_read(fd, buf, count);
> Â 
> -	if (rc < 0)
> +	if (rc == -11)
> +		/* Explicitly added since linux errno has -11 for
> EAGAIN */
> +		rc = -EWOULDBLOCK;

We should return -EAGAIN to be consistent with the comment and the
commit message.

I would also add a comment:

/* FIXME: EAGAIN is not the only error code affected by this issue
(e.g., EDESTADDRREQ, EDQUOT). We should have a more generic solution
that converts errno from Linux to BSD/Unikraft in a clean and generic
way. */

> +	else if (rc < 0)
> Â 		uk_pr_err("Failed(%ld) to read from the tap
> device\n", rc);
> Â 
> Â 	return rc;
> @@ -132,7 +135,12 @@ ssize_t tap_write(int fd, const void *buf,
> size_t count)
> Â 		rc = sys_write(fd, buf, count);
> Â 		if (rc == -EINTR)
> Â 			continue;
> -		else if (rc < 0) {
> +		else if (rc == -11) {
> +			/*Â 
> +			Â * Explicitly added since linux errno has
> -11 for EAGAIN
> +			Â */
> +			rc = -EWOULDBLOCK;

same: rc =Â Â -EAGAIN.

> +		} else if (rc < 0) {
> Â 			uk_pr_err("Failed(%ld) to write to the tap
> device\n",
> Â 				Â Â rc);
> Â 			return rc;


From minios-devel-bounces@lists.xenproject.org Wed Jul 08 13:30:53 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 08 Jul 2020 13:30:53 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jtAA0-0008UQ-4Y; Wed, 08 Jul 2020 13:30:52 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dys+=AT=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jtA9y-0008UB-Bk
 for minios-devel@lists.xen.org; Wed, 08 Jul 2020 13:30:50 +0000
X-Inumbo-ID: 3af9f2c1-c11f-11ea-8e38-12813bfff9fa
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 3af9f2c1-c11f-11ea-8e38-12813bfff9fa;
 Wed, 08 Jul 2020 13:30:48 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 27232FFB89;
 Wed,  8 Jul 2020 15:30:47 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id oTzXKXrx75D0; Wed,  8 Jul 2020 15:30:47 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id 00C92FFB3E
 for <minios-devel@lists.xen.org>; Wed,  8 Jul 2020 15:30:47 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 8 Jul 2020
 15:30:46 +0200
Message-ID: <1594215045.7030.28.camel@neclab.eu>
Subject: Re: [UNIKRAFT PATCH v2 01/15] plat/linuxu/tap: Introduce tap driver
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Sharan Santhanam <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
Date: Wed, 8 Jul 2020 15:30:45 +0200
In-Reply-To: <20200630095825.4127-2-sharan.santhanam@neclab.eu>
References: <20200630095825.4127-1-sharan.santhanam@neclab.eu>
 <20200630095825.4127-2-sharan.santhanam@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: titania.office.hd (192.168.24.89) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Sharan,

looks good to me, small nitpick in the copyright header (inline).

regards,
Hugo

On Tue, 2020-06-30 at 11:58 +0200, Sharan Santhanam wrote:
> Introduce a tap driver skeleton which implements the uknetdev
> interface.
> 
> Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
> ---
> Â plat/drivers/tap/tap.cÂ Â | 217
> ++++++++++++++++++++++++++++++++++++++++++++++++
> Â plat/linuxu/Config.ukÂ Â Â |Â Â Â 9 ++
> Â plat/linuxu/Makefile.uk |Â Â Â 8 ++
> Â 3 files changed, 234 insertions(+)
> Â create mode 100644 plat/drivers/tap/tap.c
> 
> diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
> new file mode 100644
> index 0000000..9bbf7dd
> --- /dev/null
> +++ b/plat/drivers/tap/tap.c
> @@ -0,0 +1,217 @@
> +/* SPDX-License-Identifier: BSD-3-Clause */
> +/*
> + * Authors: Sharan Santhanam <sharan.santhanam@neclab.eu>
> + *
> + * Copyright (c) 2019, NEC Europe Ltd., NEC Corporation. All rights
> reserved.
> + *
> + * Redistribution and use in source and binary forms, with or
> without
> + * modification, are permitted provided that the following
> conditions
> + * are met:
> + *
> + * 1. Redistributions of source code must retain the above copyright
> + *Â Â Â Â notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above
> copyright
> + *Â Â Â Â notice, this list of conditions and the following disclaimer
> in the
> + *Â Â Â Â documentation and/or other materials provided with the
> distribution.
> + * 3. Neither the name of the copyright holder nor the names of its
> + *Â Â Â Â contributors may be used to endorse or promote products
> derived from
> + *Â Â Â Â this software without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
> CONTRIBUTORS "AS IS"
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
> TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
> PARTICULAR PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
> CONTRIBUTORS BE
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
> OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
> OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
> BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
> WHETHER IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
> OTHERWISE)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
> ADVISED OF THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + *
> + * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.

I think that the last line should be removed.

> + */
> +#include <errno.h>
> +#include <uk/alloc.h>
> +#include <uk/arch/types.h>
> +#include <uk/netdev_core.h>
> +#include <uk/netdev_driver.h>
> +#include <uk/netbuf.h>
> +#include <uk/errptr.h>
> +
> +/**
> + * Module functions
> + */
> +static int tap_netdev_xmit(struct uk_netdev *dev,
> +			Â Â Â struct uk_netdev_tx_queue *queue,
> +			Â Â Â struct uk_netbuf *pkt);
> +static int tap_netdev_recv(struct uk_netdev *dev,
> +			Â Â Â struct uk_netdev_rx_queue *queue,
> +			Â Â Â struct uk_netbuf **pkt);
> +static struct uk_netdev_rx_queue *tap_netdev_rxq_setup(struct
> uk_netdev *dev,
> +					__u16 queue_id, __u16
> nb_desc,
> +					struct
> uk_netdev_rxqueue_conf *conf);
> +static struct uk_netdev_tx_queue *tap_netdev_txq_setup(struct
> uk_netdev *dev,
> +					__u16 queue_id, __u16
> nb_desc,
> +					struct
> uk_netdev_txqueue_conf *conf);
> +static int tap_netdev_configure(struct uk_netdev *n,
> +				const struct uk_netdev_conf *conf);
> +static int tap_netdev_start(struct uk_netdev *n);
> +static const struct uk_hwaddr *tap_netdev_mac_get(struct uk_netdev
> *n);
> +static int tap_netdev_mac_set(struct uk_netdev *n,
> +			Â Â Â Â Â Â const struct uk_hwaddr *hwaddr);
> +static __u16 tap_netdev_mtu_get(struct uk_netdev *n);
> +static int tap_netdev_mtu_set(struct uk_netdev *n,Â Â __u16 mtu);
> +static unsigned int tap_netdev_promisc_get(struct uk_netdev *n);
> +static void tap_netdev_info_get(struct uk_netdev *dev,
> +				struct uk_netdev_info *dev_info);
> +static int tap_netdev_rxq_info_get(struct uk_netdev *dev, __u16
> queue_id,
> +				Â Â Â struct uk_netdev_queue_info
> *qinfo);
> +static int tap_netdev_txq_info_get(struct uk_netdev *dev, __u16
> queue_id,
> +				Â Â Â struct uk_netdev_queue_info
> *qinfo);
> +
> +/**
> + * Local function definitions
> + */
> +
> +static int tap_netdev_recv(struct uk_netdev *dev,
> +			Â Â Â struct uk_netdev_rx_queue *queue,
> +			Â Â Â struct uk_netbuf **pkt)
> +{
> +	int rc = -EINVAL;
> +
> +	UK_ASSERT(dev);
> +	UK_ASSERT(queue && pkt);
> +
> +	return rc;
> +}
> +
> +static int tap_netdev_xmit(struct uk_netdev *dev,
> +			Â Â Â struct uk_netdev_tx_queue *queue,
> +			Â Â Â struct uk_netbuf *pkt)
> +{
> +	int rc = -EINVAL;
> +
> +	UK_ASSERT(dev);
> +	UK_ASSERT(queue && pkt);
> +
> +	return rc;
> +}
> +
> +static int tap_netdev_txq_info_get(struct uk_netdev *dev __unused,
> +				Â Â Â __u16 queue_id __unused,
> +				Â Â Â struct uk_netdev_queue_info
> *qinfo __unused)
> +{
> +	return -EINVAL;
> +}
> +
> +static int tap_netdev_rxq_info_get(struct uk_netdev *dev __unused,
> +				Â Â Â __u16 queue_id __unused,
> +				Â Â Â struct uk_netdev_queue_info
> *qinfo __unused)
> +{
> +	return -EINVAL;
> +}
> +
> +static struct uk_netdev_rx_queue *tap_netdev_rxq_setup(struct
> uk_netdev *dev,
> +						Â Â Â Â Â Â Â __u16
> queue_id __unused,
> +						Â Â Â Â Â Â Â __u16 nb_desc
> __unused,
> +					struct
> uk_netdev_rxqueue_conf *conf)
> +{
> +	int rc = -EINVAL;
> +	struct uk_netdev_rx_queue *rxq = NULL;
> +
> +	UK_ASSERT(dev && conf);
> +
> +	rxq = ERR2PTR(rc);
> +	return rxq;
> +}
> +
> +static struct uk_netdev_tx_queue *tap_netdev_txq_setup(struct
> uk_netdev *dev,
> +						Â Â Â Â Â Â Â __u16
> queue_id __unused,
> +						Â Â Â Â Â Â Â __u16 nb_desc
> __unused,
> +					struct
> uk_netdev_txqueue_conf *conf)
> +{
> +	int rc = -EINVAL;
> +	struct uk_netdev_tx_queue *txq = NULL;
> +
> +	UK_ASSERT(dev && conf);
> +
> +	txq = ERR2PTR(rc);
> +	return txq;
> +}
> +
> +static int tap_netdev_start(struct uk_netdev *n)
> +{
> +	int rc = -EINVAL;
> +
> +	UK_ASSERT(n);
> +	return rc;
> +}
> +
> +static void tap_netdev_info_get(struct uk_netdev *dev __unused,
> +				struct uk_netdev_info *dev_info)
> +{
> +	UK_ASSERT(dev_info);
> +}
> +
> +static unsigned int tap_netdev_promisc_get(struct uk_netdev *n)
> +{
> +
> +	UK_ASSERT(n);
> +
> +	return 0;
> +}
> +
> +static __u16 tap_netdev_mtu_get(struct uk_netdev *n)
> +{
> +	UK_ASSERT(n);
> +	return 0;
> +}
> +
> +static int tap_netdev_mtu_set(struct uk_netdev *n,Â Â __u16 mtu
> __unused)
> +{
> +	int rc = -EINVAL;
> +
> +	UK_ASSERT(n);
> +
> +	return rc;
> +}
> +
> +static const struct uk_hwaddr *tap_netdev_mac_get(struct uk_netdev
> *n)
> +{
> +	UK_ASSERT(n);
> +	return NULL;
> +}
> +
> +static int tap_netdev_mac_set(struct uk_netdev *n,
> +			Â Â Â Â Â Â const struct uk_hwaddr *hwaddr)
> +{
> +	int rc = -EINVAL;
> +
> +	UK_ASSERT(n && hwaddr);
> +	return rc;
> +}
> +
> +static int tap_netdev_configure(struct uk_netdev *n,
> +				const struct uk_netdev_conf *conf)
> +{
> +	int rc = -EINVAL;
> +
> +	UK_ASSERT(n && conf);
> +	return rc;
> +}
> +
> +static const struct uk_netdev_ops tap_netdev_ops = {
> +	.configure = tap_netdev_configure,
> +	.rxq_configure = tap_netdev_rxq_setup,
> +	.txq_configure = tap_netdev_txq_setup,
> +	.start = tap_netdev_start,
> +	.info_get = tap_netdev_info_get,
> +	.promiscuous_get = tap_netdev_promisc_get,
> +	.hwaddr_get = tap_netdev_mac_get,
> +	.hwaddr_set = tap_netdev_mac_set,
> +	.mtu_get = tap_netdev_mtu_get,
> +	.mtu_set = tap_netdev_mtu_set,
> +	.txq_info_get = tap_netdev_txq_info_get,
> +	.rxq_info_get = tap_netdev_rxq_info_get,
> +};
> diff --git a/plat/linuxu/Config.uk b/plat/linuxu/Config.uk
> index d8c86d8..5df48f3 100644
> --- a/plat/linuxu/Config.uk
> +++ b/plat/linuxu/Config.uk
> @@ -17,4 +17,13 @@ if (PLAT_LINUXU)
> Â 		changed by using linuxu.heap_size as a command line
> argument. For more
> Â 		information refer to "Command line arguments in
> Unikraft" sections inÂ 
> Â 		the developers guide
> +
> +	config TAP_NET
> +	bool "Tap driver"
> +	default y if LIBUKNETDEV
> +	depends on LIBUKNETDEV
> +	help
> +		Enable drivers to support tap device on the linuxu
> platform. The
> +		driver implements the uknetdev interface and
> provides an interface
> +		for the network stack to send/receive network
> packets.
> Â endif
> diff --git a/plat/linuxu/Makefile.uk b/plat/linuxu/Makefile.uk
> index 94516ac..0850fd9 100644
> --- a/plat/linuxu/Makefile.uk
> +++ b/plat/linuxu/Makefile.uk
> @@ -7,6 +7,7 @@ $(eval $(call
> addplat_s,linuxu,$(CONFIG_PLAT_LINUXU)))
> Â ## Linux user platform library registration
> Â ##
> Â $(eval $(call addplatlib,linuxu,liblinuxuplat))
> +$(eval $(call
> addplatlib_s,linuxu,liblinuxutapnet,$(CONFIG_TAP_NET)))
> Â 
> Â ## Adding libparam for the linuxu platform
> Â $(eval $(call addlib_paramprefix,liblinuxuplat,linuxu))
> @@ -46,3 +47,10 @@ LIBLINUXUPLAT_SRCS-$(CONFIG_ARCH_X86_64) += \
> Â 			$(LIBLINUXUPLAT_BASE)/x86/link64.lds.S
> Â LIBLINUXUPLAT_SRCS-$(CONFIG_ARCH_ARM_32) += \
> Â 			$(LIBLINUXUPLAT_BASE)/arm/link.lds.S
> +
> +##
> +## LINUXUTAPNET Source
> +LIBLINUXUTAPNET_ASINCLUED-yÂ Â Â Â Â Â Â Â Â +=
> -I$(LIBLINUXUPLAT_BASE)/include
> +LIBLINUXUTAPNET_CINCLUDES-yÂ Â Â Â Â Â Â Â Â +=
> -I$(LIBLINUXUPLAT_BASE)/include
> +
> +LIBLINUXUTAPNET_SRCS-y		Â Â +=
> $(UK_PLAT_DRIVERS_BASE)/tap/tap.c


From minios-devel-bounces@lists.xenproject.org Wed Jul 08 15:06:01 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 08 Jul 2020 15:06:01 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jtBe2-0007cl-Id; Wed, 08 Jul 2020 15:05:58 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=5t2J=AT=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jtBe1-0007cf-EQ
 for minios-devel@lists.xen.org; Wed, 08 Jul 2020 15:05:57 +0000
X-Inumbo-ID: 8521c294-c12c-11ea-b7bb-bc764e2007e4
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 8521c294-c12c-11ea-b7bb-bc764e2007e4;
 Wed, 08 Jul 2020 15:05:55 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 2094A103732;
 Wed,  8 Jul 2020 17:05:54 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id XBQoeIjt7Qx0; Wed,  8 Jul 2020 17:05:54 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id F1F311003CD
 for <minios-devel@lists.xen.org>; Wed,  8 Jul 2020 17:05:53 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 8 Jul 2020
 17:05:53 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 0/2] ipaddr, netmask and gwaddr as library argument
Date: Wed, 8 Jul 2020 17:05:36 +0200
Message-ID: <20200708150538.26234-1-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch series allow user to pass the ip address, net mask and the gateway
address as a library argument to the uknetdev library. The library arguments
are net.ipv4_addr, net.ipv4_subnet_mask and net.ipv4_gw_addr.

Changes since v2:
- Add/Fix code comments
- Fix debug prints

Changes since v1:
-Make it ipv4 specific




Sharan Santhanam (2):
  lib/uknetdev: Add ipaddr, netmask & gwaddr as arg
  lib/uknetdev: Get the ipaddr, gw_addr and subnet

 lib/uknetdev/Config.uk                |   1 +
 lib/uknetdev/Makefile.uk              |   1 +
 lib/uknetdev/include/uk/netdev_core.h |   9 +++
 lib/uknetdev/netdev.c                 | 102 ++++++++++++++++++++++++++
 4 files changed, 113 insertions(+)

-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 08 15:06:03 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 08 Jul 2020 15:06:03 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jtBe7-0007db-KG; Wed, 08 Jul 2020 15:06:03 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=5t2J=AT=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jtBe6-0007cf-5F
 for minios-devel@lists.xen.org; Wed, 08 Jul 2020 15:06:02 +0000
X-Inumbo-ID: 86ab7272-c12c-11ea-bb8b-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 86ab7272-c12c-11ea-bb8b-bc764e2007e4;
 Wed, 08 Jul 2020 15:05:57 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id BA570F2009;
 Wed,  8 Jul 2020 17:05:56 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id hz7P48yNqP7P; Wed,  8 Jul 2020 17:05:56 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 92EE1F2007
 for <minios-devel@lists.xen.org>; Wed,  8 Jul 2020 17:05:54 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 8 Jul 2020
 17:05:53 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 1/2] lib/uknetdev: Add ipaddr,
 netmask & gwaddr as arg
Date: Wed, 8 Jul 2020 17:05:37 +0200
Message-ID: <20200708150538.26234-2-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200708150538.26234-1-sharan.santhanam@neclab.eu>
References: <20200708150538.26234-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch adds ip address, netmask and the gateway address as library
argument. The parameters are list of argument delimited by a space.
The library user can forward the argument using the following command
line:
net.ipv4_addr, net.ipv4_subnet_mask, net.ipv4_gw_addr

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 lib/uknetdev/Config.uk                |  1 +
 lib/uknetdev/Makefile.uk              |  1 +
 lib/uknetdev/include/uk/netdev_core.h |  9 ++++
 lib/uknetdev/netdev.c                 | 78 +++++++++++++++++++++++++++
 4 files changed, 89 insertions(+)

diff --git a/lib/uknetdev/Config.uk b/lib/uknetdev/Config.uk
index 618e8e67..186dd462 100644
--- a/lib/uknetdev/Config.uk
+++ b/lib/uknetdev/Config.uk
@@ -4,6 +4,7 @@ menuconfig LIBUKNETDEV
 	select LIBNOLIBC if !HAVE_LIBC
 	select LIBUKDEBUG
 	select LIBUKALLOC
+	imply LIBUKLIBPARAM
 
 if LIBUKNETDEV
 	config LIBUKNETDEV_MAXNBQUEUES
diff --git a/lib/uknetdev/Makefile.uk b/lib/uknetdev/Makefile.uk
index ca08b254..abdcd4bc 100644
--- a/lib/uknetdev/Makefile.uk
+++ b/lib/uknetdev/Makefile.uk
@@ -1,4 +1,5 @@
 $(eval $(call addlib_s,libuknetdev,$(CONFIG_LIBUKNETDEV)))
+$(eval $(call addlib_paramprefix,libuknetdev,net))
 
 CINCLUDES-$(CONFIG_LIBUKNETDEV)		+= -I$(LIBUKNETDEV_BASE)/include
 CXXINCLUDES-$(CONFIG_LIBUKNETDEV)	+= -I$(LIBUKNETDEV_BASE)/include
diff --git a/lib/uknetdev/include/uk/netdev_core.h b/lib/uknetdev/include/uk/netdev_core.h
index dba719fc..d2e8da05 100644
--- a/lib/uknetdev/include/uk/netdev_core.h
+++ b/lib/uknetdev/include/uk/netdev_core.h
@@ -373,6 +373,12 @@ struct uk_netdev_data {
 	const char           *drv_name;
 };
 
+struct uk_netdev_config {
+	const char *ipv4_addr;
+	const char *ipv4_net_mask;
+	const char *ipv4_gw_addr;
+};
+
 /**
  * NETDEV
  * A structure used to interact with a network device.
@@ -400,6 +406,9 @@ struct uk_netdev {
 	struct uk_netdev_tx_queue   *_tx_queue[CONFIG_LIBUKNETDEV_MAXNBQUEUES];
 
 	UK_TAILQ_ENTRY(struct uk_netdev) _list;
+
+	/** Netdevice address configuration */
+	struct uk_netdev_config	   *_config;
 };
 
 #ifdef __cplusplus
diff --git a/lib/uknetdev/netdev.c b/lib/uknetdev/netdev.c
index 151e0897..e0ee4427 100644
--- a/lib/uknetdev/netdev.c
+++ b/lib/uknetdev/netdev.c
@@ -38,10 +38,62 @@
 #include <string.h>
 #include <uk/netdev.h>
 #include <uk/print.h>
+#include <uk/libparam.h>
 
 struct uk_netdev_list uk_netdev_list =
 	UK_TAILQ_HEAD_INITIALIZER(uk_netdev_list);
 static uint16_t netdev_count;
+/**
+ * TODO: Define Network argument format when multiple driver device need to
+ * coexist. For example like:
+ * Driver Name:IP Address:Net Mask
+ */
+static char *ipv4_addr;
+static char *ipv4_subnet_mask;
+static char *ipv4_gw_addr;
+
+UK_LIB_PARAM_STR(ipv4_addr);
+UK_LIB_PARAM_STR(ipv4_subnet_mask);
+UK_LIB_PARAM_STR(ipv4_gw_addr);
+
+static const char *_parse_ipv4_addr(void)
+{
+	/** Remember the reference to the ip address for successive calls*/
+	static char *ip_addr;
+
+	if (ip_addr)
+		return strtok_r(NULL, " ", &ip_addr);
+	else if (ipv4_addr)
+		return strtok_r(ipv4_addr, " ", &ip_addr);
+
+	return NULL;
+}
+
+static const char *_parse_ipv4_net_mask(void)
+{
+	/** Remember the reference to the netmask for successive calls*/
+	static char *net_mask;
+
+	if (net_mask)
+		return strtok_r(NULL, " ", &net_mask);
+	else if (ipv4_subnet_mask)
+		return strtok_r(ipv4_subnet_mask, " ", &net_mask);
+
+	return NULL;
+}
+
+static const char *_parse_ipv4_gw_addr(void)
+{
+	/** Remember the reference to the gateway address for successive calls*/
+	static char *gw;
+
+	if (gw)
+		return strtok_r(NULL, " ", &gw);
+	else if (ipv4_gw_addr)
+		return strtok_r(ipv4_gw_addr, " ", &gw);
+
+	return NULL;
+}
 
 static struct uk_netdev_data *_alloc_data(struct uk_alloc *a,
 					  uint16_t netdev_id,
@@ -64,6 +116,25 @@ static struct uk_netdev_data *_alloc_data(struct uk_alloc *a,
 	return data;
 }
 
+static struct uk_netdev_config *_alloc_config(struct uk_alloc *a)
+{
+	struct uk_netdev_config *_config = NULL;
+
+	if (ipv4_addr || ipv4_subnet_mask || ipv4_gw_addr) {
+		_config = uk_zalloc(a, sizeof(*_config));
+		if (!_config) {
+			uk_pr_warn("Failed to allocate memory for netdev config\n");
+			return NULL;
+		}
+
+		_config->ipv4_addr = _parse_ipv4_addr();
+		_config->ipv4_net_mask = _parse_ipv4_net_mask();
+		_config->ipv4_gw_addr = _parse_ipv4_gw_addr();
+	}
+
+	return _config;
+}
+
 int uk_netdev_drv_register(struct uk_netdev *dev, struct uk_alloc *a,
 			   const char *drv_name)
 {
@@ -91,6 +162,13 @@ int uk_netdev_drv_register(struct uk_netdev *dev, struct uk_alloc *a,
 	if (!dev->_data)
 		return -ENOMEM;
 
+	/**
+	 * Since the _config is meant to be optional, the boot process should
+	 * still continue if the allocation of config fails instead of reporting
+	 * error.
+	 */
+	dev->_config = _alloc_config(a);
+
 	UK_TAILQ_INSERT_TAIL(&uk_netdev_list, dev, _list);
 	uk_pr_info("Registered netdev%"PRIu16": %p (%s)\n",
 		   netdev_count, dev, drv_name);
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 08 15:06:08 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 08 Jul 2020 15:06:08 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jtBeC-0007eF-Lj; Wed, 08 Jul 2020 15:06:08 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=5t2J=AT=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jtBeB-0007cf-5E
 for minios-devel@lists.xen.org; Wed, 08 Jul 2020 15:06:07 +0000
X-Inumbo-ID: 87e36456-c12c-11ea-8496-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 87e36456-c12c-11ea-8496-bc764e2007e4;
 Wed, 08 Jul 2020 15:06:00 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id C55ECF200A;
 Wed,  8 Jul 2020 17:05:58 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id VBez4y4TvqOF; Wed,  8 Jul 2020 17:05:58 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 9CE20F2007
 for <minios-devel@lists.xen.org>; Wed,  8 Jul 2020 17:05:56 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 8 Jul 2020
 17:05:54 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 2/2] lib/uknetdev: Get the ipaddr,
 gw_addr and subnet
Date: Wed, 8 Jul 2020 17:05:38 +0200
Message-ID: <20200708150538.26234-3-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200708150538.26234-1-sharan.santhanam@neclab.eu>
References: <20200708150538.26234-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The user of uknetdev can pass the ipaddr, gw_addr and subnet as a
library argument. The library argument can be retrieved from the
network stack using uk_netdev_einfo_get function. The library
arguments are retrieved only if the driver does not support the
uk_netdev_einfo_get callback.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 lib/uknetdev/netdev.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/lib/uknetdev/netdev.c b/lib/uknetdev/netdev.c
index e0ee4427..23581f50 100644
--- a/lib/uknetdev/netdev.c
+++ b/lib/uknetdev/netdev.c
@@ -239,6 +239,28 @@ void uk_netdev_info_get(struct uk_netdev *dev,
 				      dev_info->max_tx_queues);
 }
 
+static const void *_netdev_einfo_get(struct uk_netdev *dev,
+				enum uk_netdev_einfo_type einfo)
+{
+	switch (einfo) {
+	case UK_NETDEV_IPV4_ADDR_STR:
+		if (dev->_config->ipv4_addr)
+			uk_pr_debug("ip_addr: %s\n", dev->_config->ipv4_addr);
+		return dev->_config->ipv4_addr;
+	case UK_NETDEV_IPV4_MASK_STR:
+		if (dev->_config->ipv4_net_mask)
+			uk_pr_debug("netmask: %s\n", dev->_config->ipv4_net_mask);
+		return dev->_config->ipv4_net_mask;
+	case UK_NETDEV_IPV4_GW_STR:
+		if (dev->_config->ipv4_gw_addr)
+			uk_pr_debug("Gateway: %s\n", dev->_config->ipv4_gw_addr);
+		return dev->_config->ipv4_gw_addr;
+	default:
+		uk_pr_warn("Option %d not yet supported\n", einfo);
+	}
+	return NULL;
+}
+
 const void *uk_netdev_einfo_get(struct uk_netdev *dev,
 				enum uk_netdev_einfo_type einfo)
 {
@@ -247,6 +269,8 @@ const void *uk_netdev_einfo_get(struct uk_netdev *dev,
 
 	if (!dev->ops->einfo_get) {
 		/* driver does not provide any extra configuration */
+		if (dev->_config)
+			return _netdev_einfo_get(dev, einfo);
 		return NULL;
 	}
 	return dev->ops->einfo_get(dev, einfo);
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Thu Jul 09 07:04:13 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 09 Jul 2020 07:04:13 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jtQbI-0005St-LC; Thu, 09 Jul 2020 07:04:08 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=8/JE=AU=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jtQbH-0005So-TH
 for minios-devel@lists.xen.org; Thu, 09 Jul 2020 07:04:07 +0000
X-Inumbo-ID: 5ff9ad66-c1b2-11ea-8eab-12813bfff9fa
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 5ff9ad66-c1b2-11ea-8eab-12813bfff9fa;
 Thu, 09 Jul 2020 07:04:05 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 4558E1018BF;
 Thu,  9 Jul 2020 09:04:04 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id mGb5ULZQF0-Y; Thu,  9 Jul 2020 09:04:04 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id 1FFDF100073
 for <minios-devel@lists.xen.org>; Thu,  9 Jul 2020 09:04:04 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 9 Jul 2020
 09:04:03 +0200
Message-ID: <1594278242.7030.30.camel@neclab.eu>
Subject: Re: [UNIKRAFT PATCH v3 1/2] lib/uknetdev: Add ipaddr, netmask &
 gwaddr as arg
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Sharan Santhanam <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
Date: Thu, 9 Jul 2020 09:04:02 +0200
In-Reply-To: <20200708150538.26234-2-sharan.santhanam@neclab.eu>
References: <20200708150538.26234-1-sharan.santhanam@neclab.eu>
 <20200708150538.26234-2-sharan.santhanam@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: titania.office.hd (192.168.24.89) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Sharan,

tested, reviewed, looks good to me. This was rebased on top of staging
so we can merge it right away.

regards,
Hugo

Reviewed-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>

On Wed, 2020-07-08 at 17:05 +0200, Sharan Santhanam wrote:
> The patch adds ip address, netmask and the gateway address as library
> argument. The parameters are list of argument delimited by a space.
> The library user can forward the argument using the following command
> line:
> net.ipv4_addr, net.ipv4_subnet_mask, net.ipv4_gw_addr
> 
> Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
> ---
> Â lib/uknetdev/Config.ukÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |Â Â 1 +
> Â lib/uknetdev/Makefile.ukÂ Â Â Â Â Â Â Â Â Â Â Â Â Â |Â Â 1 +
> Â lib/uknetdev/include/uk/netdev_core.h |Â Â 9 ++++
> Â lib/uknetdev/netdev.cÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â | 78
> +++++++++++++++++++++++++++
> Â 4 files changed, 89 insertions(+)
> 
> diff --git a/lib/uknetdev/Config.uk b/lib/uknetdev/Config.uk
> index 618e8e67..186dd462 100644
> --- a/lib/uknetdev/Config.uk
> +++ b/lib/uknetdev/Config.uk
> @@ -4,6 +4,7 @@ menuconfig LIBUKNETDEV
> Â 	select LIBNOLIBC if !HAVE_LIBC
> Â 	select LIBUKDEBUG
> Â 	select LIBUKALLOC
> +	imply LIBUKLIBPARAM
> Â 
> Â if LIBUKNETDEV
> Â 	config LIBUKNETDEV_MAXNBQUEUES
> diff --git a/lib/uknetdev/Makefile.uk b/lib/uknetdev/Makefile.uk
> index ca08b254..abdcd4bc 100644
> --- a/lib/uknetdev/Makefile.uk
> +++ b/lib/uknetdev/Makefile.uk
> @@ -1,4 +1,5 @@
> Â $(eval $(call addlib_s,libuknetdev,$(CONFIG_LIBUKNETDEV)))
> +$(eval $(call addlib_paramprefix,libuknetdev,net))
> Â 
> Â CINCLUDES-$(CONFIG_LIBUKNETDEV)		+=
> -I$(LIBUKNETDEV_BASE)/include
> Â CXXINCLUDES-$(CONFIG_LIBUKNETDEV)	+=
> -I$(LIBUKNETDEV_BASE)/include
> diff --git a/lib/uknetdev/include/uk/netdev_core.h
> b/lib/uknetdev/include/uk/netdev_core.h
> index dba719fc..d2e8da05 100644
> --- a/lib/uknetdev/include/uk/netdev_core.h
> +++ b/lib/uknetdev/include/uk/netdev_core.h
> @@ -373,6 +373,12 @@ struct uk_netdev_data {
> Â 	const charÂ Â Â Â Â Â Â Â Â Â Â *drv_name;
> Â };
> Â 
> +struct uk_netdev_config {
> +	const char *ipv4_addr;
> +	const char *ipv4_net_mask;
> +	const char *ipv4_gw_addr;
> +};
> +
> Â /**
> Â  * NETDEV
> Â  * A structure used to interact with a network device.
> @@ -400,6 +406,9 @@ struct uk_netdev {
> Â 	struct
> uk_netdev_tx_queueÂ Â Â *_tx_queue[CONFIG_LIBUKNETDEV_MAXNBQUEUES];
> Â 
> Â 	UK_TAILQ_ENTRY(struct uk_netdev) _list;
> +
> +	/** Netdevice address configuration */
> +	struct uk_netdev_config	Â Â Â *_config;
> Â };
> Â 
> Â #ifdef __cplusplus
> diff --git a/lib/uknetdev/netdev.c b/lib/uknetdev/netdev.c
> index 151e0897..e0ee4427 100644
> --- a/lib/uknetdev/netdev.c
> +++ b/lib/uknetdev/netdev.c
> @@ -38,10 +38,62 @@
> Â #include <string.h>
> Â #include <uk/netdev.h>
> Â #include <uk/print.h>
> +#include <uk/libparam.h>
> Â 
> Â struct uk_netdev_list uk_netdev_list =
> Â 	UK_TAILQ_HEAD_INITIALIZER(uk_netdev_list);
> Â static uint16_t netdev_count;
> +/**
> + * TODO: Define Network argument format when multiple driver device
> need to
> + * coexist. For example like:
> + * Driver Name:IP Address:Net Mask
> + */
> +static char *ipv4_addr;
> +static char *ipv4_subnet_mask;
> +static char *ipv4_gw_addr;
> +
> +UK_LIB_PARAM_STR(ipv4_addr);
> +UK_LIB_PARAM_STR(ipv4_subnet_mask);
> +UK_LIB_PARAM_STR(ipv4_gw_addr);
> +
> +static const char *_parse_ipv4_addr(void)
> +{
> +	/** Remember the reference to the ip address for successive
> calls*/
> +	static char *ip_addr;
> +
> +	if (ip_addr)
> +		return strtok_r(NULL, " ", &ip_addr);
> +	else if (ipv4_addr)
> +		return strtok_r(ipv4_addr, " ", &ip_addr);
> +
> +	return NULL;
> +}
> +
> +static const char *_parse_ipv4_net_mask(void)
> +{
> +	/** Remember the reference to the netmask for successive
> calls*/
> +	static char *net_mask;
> +
> +	if (net_mask)
> +		return strtok_r(NULL, " ", &net_mask);
> +	else if (ipv4_subnet_mask)
> +		return strtok_r(ipv4_subnet_mask, " ", &net_mask);
> +
> +	return NULL;
> +}
> +
> +static const char *_parse_ipv4_gw_addr(void)
> +{
> +	/** Remember the reference to the gateway address for
> successive calls*/
> +	static char *gw;
> +
> +	if (gw)
> +		return strtok_r(NULL, " ", &gw);
> +	else if (ipv4_gw_addr)
> +		return strtok_r(ipv4_gw_addr, " ", &gw);
> +
> +	return NULL;
> +}
> Â 
> Â static struct uk_netdev_data *_alloc_data(struct uk_alloc *a,
> Â 					Â Â uint16_t netdev_id,
> @@ -64,6 +116,25 @@ static struct uk_netdev_data *_alloc_data(struct
> uk_alloc *a,
> Â 	return data;
> Â }
> Â 
> +static struct uk_netdev_config *_alloc_config(struct uk_alloc *a)
> +{
> +	struct uk_netdev_config *_config = NULL;
> +
> +	if (ipv4_addr || ipv4_subnet_mask || ipv4_gw_addr) {
> +		_config = uk_zalloc(a, sizeof(*_config));
> +		if (!_config) {
> +			uk_pr_warn("Failed to allocate memory for
> netdev config\n");
> +			return NULL;
> +		}
> +
> +		_config->ipv4_addr = _parse_ipv4_addr();
> +		_config->ipv4_net_mask = _parse_ipv4_net_mask();
> +		_config->ipv4_gw_addr = _parse_ipv4_gw_addr();
> +	}
> +
> +	return _config;
> +}
> +
> Â int uk_netdev_drv_register(struct uk_netdev *dev, struct uk_alloc
> *a,
> Â 			Â Â Â const char *drv_name)
> Â {
> @@ -91,6 +162,13 @@ int uk_netdev_drv_register(struct uk_netdev *dev,
> struct uk_alloc *a,
> Â 	if (!dev->_data)
> Â 		return -ENOMEM;
> Â 
> +	/**
> +	Â * Since the _config is meant to be optional, the boot
> process should
> +	Â * still continue if the allocation of config fails instead
> of reporting
> +	Â * error.
> +	Â */
> +	dev->_config = _alloc_config(a);
> +
> Â 	UK_TAILQ_INSERT_TAIL(&uk_netdev_list, dev, _list);
> Â 	uk_pr_info("Registered netdev%"PRIu16": %p (%s)\n",
> Â 		Â Â Â netdev_count, dev, drv_name);


From minios-devel-bounces@lists.xenproject.org Thu Jul 09 07:07:28 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 09 Jul 2020 07:07:28 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jtQeV-0005We-Uc; Thu, 09 Jul 2020 07:07:27 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=8/JE=AU=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jtQeU-0005WZ-Sn
 for minios-devel@lists.xen.org; Thu, 09 Jul 2020 07:07:26 +0000
X-Inumbo-ID: d695a97a-c1b2-11ea-bb8b-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id d695a97a-c1b2-11ea-bb8b-bc764e2007e4;
 Thu, 09 Jul 2020 07:07:24 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 5FB9DF2009;
 Thu,  9 Jul 2020 09:07:23 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id dzr-PndfJszg; Thu,  9 Jul 2020 09:07:23 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 270A8F2007
 for <minios-devel@lists.xen.org>; Thu,  9 Jul 2020 09:07:21 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 9 Jul 2020
 09:07:20 +0200
Message-ID: <1594278439.7030.32.camel@neclab.eu>
Subject: Re: [UNIKRAFT PATCH v3 2/2] lib/uknetdev: Get the ipaddr, gw_addr
 and subnet
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Sharan Santhanam <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
Date: Thu, 9 Jul 2020 09:07:19 +0200
In-Reply-To: <20200708150538.26234-3-sharan.santhanam@neclab.eu>
References: <20200708150538.26234-1-sharan.santhanam@neclab.eu>
 <20200708150538.26234-3-sharan.santhanam@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Sharan,

thanks a lot for this v3. Same a [1/2], tested and reviewed twice, this
looks good to me.

regards,
Hugo

Reviewed-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>

On Wed, 2020-07-08 at 17:05 +0200, Sharan Santhanam wrote:
> The user of uknetdev can pass the ipaddr, gw_addr and subnet as a
> library argument. The library argument can be retrieved from the
> network stack using uk_netdev_einfo_get function. The library
> arguments are retrieved only if the driver does not support the
> uk_netdev_einfo_get callback.
> 
> Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
> ---
> Â lib/uknetdev/netdev.c | 24 ++++++++++++++++++++++++
> Â 1 file changed, 24 insertions(+)
> 
> diff --git a/lib/uknetdev/netdev.c b/lib/uknetdev/netdev.c
> index e0ee4427..23581f50 100644
> --- a/lib/uknetdev/netdev.c
> +++ b/lib/uknetdev/netdev.c
> @@ -239,6 +239,28 @@ void uk_netdev_info_get(struct uk_netdev *dev,
> Â 				Â Â Â Â Â Â dev_info->max_tx_queues);
> Â }
> Â 
> +static const void *_netdev_einfo_get(struct uk_netdev *dev,
> +				enum uk_netdev_einfo_type einfo)
> +{
> +	switch (einfo) {
> +	case UK_NETDEV_IPV4_ADDR_STR:
> +		if (dev->_config->ipv4_addr)
> +			uk_pr_debug("ip_addr: %s\n", dev->_config-
> >ipv4_addr);
> +		return dev->_config->ipv4_addr;
> +	case UK_NETDEV_IPV4_MASK_STR:
> +		if (dev->_config->ipv4_net_mask)
> +			uk_pr_debug("netmask: %s\n", dev->_config-
> >ipv4_net_mask);
> +		return dev->_config->ipv4_net_mask;
> +	case UK_NETDEV_IPV4_GW_STR:
> +		if (dev->_config->ipv4_gw_addr)
> +			uk_pr_debug("Gateway: %s\n", dev->_config-
> >ipv4_gw_addr);
> +		return dev->_config->ipv4_gw_addr;
> +	default:
> +		uk_pr_warn("Option %d not yet supported\n", einfo);
> +	}
> +	return NULL;
> +}
> +
> Â const void *uk_netdev_einfo_get(struct uk_netdev *dev,
> Â 				enum uk_netdev_einfo_type einfo)
> Â {
> @@ -247,6 +269,8 @@ const void *uk_netdev_einfo_get(struct uk_netdev
> *dev,
> Â 
> Â 	if (!dev->ops->einfo_get) {
> Â 		/* driver does not provide any extra configuration
> */
> +		if (dev->_config)
> +			return _netdev_einfo_get(dev, einfo);
> Â 		return NULL;
> Â 	}
> Â 	return dev->ops->einfo_get(dev, einfo);


From minios-devel-bounces@lists.xenproject.org Thu Jul 09 12:28:34 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 09 Jul 2020 12:28:34 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jtVfD-0007jx-B1; Thu, 09 Jul 2020 12:28:31 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=8/JE=AU=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jtVfB-0007js-HF
 for minios-devel@lists.xen.org; Thu, 09 Jul 2020 12:28:29 +0000
X-Inumbo-ID: b03a7616-c1df-11ea-8496-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id b03a7616-c1df-11ea-8496-bc764e2007e4;
 Thu, 09 Jul 2020 12:28:27 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 4FFF5F200A;
 Thu,  9 Jul 2020 14:28:26 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id S6j3Cm7zD3It; Thu,  9 Jul 2020 14:28:26 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 13873F2007
 for <minios-devel@lists.xen.org>; Thu,  9 Jul 2020 14:28:24 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 9 Jul 2020
 14:28:23 +0200
Message-ID: <1594297702.7030.39.camel@neclab.eu>
Subject: Re: [UNIKRAFT/LIBLWIP PATCH v2 3/3] lib/lwip: Enable poll only receive
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Sharan Santhanam <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
Date: Thu, 9 Jul 2020 14:28:22 +0200
In-Reply-To: <20200630111535.7877-4-sharan.santhanam@neclab.eu>
References: <20200630111535.7877-1-sharan.santhanam@neclab.eu>
 <20200630111535.7877-4-sharan.santhanam@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Sharan,

tested, reviewed, looks good to me. Small typo in uknetdev_updown.
Also, some lines are more than 80 characters. I don't really care, but
checkpatch will probably complain.

Overall the series looks almost fit for upstreaming in my opinion. The
v3 will be good I think.

regards,
Hugo

On Tue, 2020-06-30 at 13:15 +0200, Sharan Santhanam wrote:
> The uknetdev library provides the way to check if interrupts are
> supported on a uk_netdev. If the device does not support interrupt
> the lwip stack would create a thread to poll the receive queue for
> packets.
> 
> Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
> ---
> Â uknetdev.c | 91 ++++++++++++++++++++++++++++++++++++++++----------
> ----
> Â 1 file changed, 68 insertions(+), 23 deletions(-)
> 
> diff --git a/uknetdev.c b/uknetdev.c
> index ef57014..0831204 100644
> --- a/uknetdev.c
> +++ b/uknetdev.c
> @@ -64,6 +64,11 @@
> Â 
> Â struct lwip_netdev_data {
> Â 	uint32_t features;
> +#ifdef CONFIG_HAVE_SCHED
> +	struct uk_thread *poll_thread; /* Thread per device */
> +	char *_name; /* Thread name */
> +	struct uk_sched *sched; /* Scheduler information */
> +#endif /* CONFIG_HAVE_SCHED */
> Â };
> Â 
> Â /*
> @@ -325,44 +330,84 @@ void uknetdev_poll_all(void)
> Â 
> Â #else /* CONFIG_LWIP_NOTHREADS */
> Â 
> +static void _poll_netif(void *arg)
> +{
> +	struct netif *nf = (struct netif *) arg;
> +
> +	while (1) {
> +		uknetdev_poll(nf);
> +		uk_sched_yield();
> +	}
> +}
> +
> Â static void uknetdev_updown(struct netif *nf)
> Â {
> Â 	struct uk_netdev *dev;
> Â 	int ret;
> +	struct lwip_netdev_dataÂ Â *lwip_data;
> Â 
> Â 	UK_ASSERT(nf);
> Â 	dev = netif_to_uknetdev(nf);
> Â 	UK_ASSERT(dev);
> +	lwip_data = (struct lwip_netdev_data *)dev->scratch_pad;
> Â 
> Â 	/* Enable and disable interrupts according to netif's
> up/down status */
> +
> Â 	if (nf->flags & NETIF_FLAG_UP) {
> -		ret = uk_netdev_rxq_intr_enable(dev, 0);
> -		if (ret < 0) {
> -			LWIP_DEBUGF(NETIF_DEBUG,
> -				Â Â Â Â ("%s: %c%c%u: Failed to enable
> rx interrrupt mode on netdev %u\n",
> -				Â Â Â Â Â __func__, nf->name[0], nf-
> >name[1],
> -				Â Â Â Â Â nf->num,
> uk_netdev_id_get(dev)));
> +		if (uk_netdev_rxintr_supported(lwip_data->features)) 
> {
> +			ret = uk_netdev_rxq_intr_enable(dev, 0);
> +			if (ret < 0) {
> +				LWIP_DEBUGF(NETIF_DEBUG,
> +						("%s: %c%c%u: Failed
> to enable rx interrupt mode on netdev %u\n",
> +						Â __func__, nf-
> >name[0],
> +						Â nf->name[1],
> +						Â nf->num,
> +						Â uk_netdev_id_get(de
> v)));
> +			} else {
> +				LWIP_DEBUGF(NETIF_DEBUG,
> +					("%s: %c%c%u: Enabled rx
> interrupt mode on netdev %u\n",
> +						Â __func__, nf-
> >name[0],
> +						Â nf->name[1],
> +						Â nf->num,
> +						Â uk_netdev_id_get(de
> v)));
> +			}
> +
> +			if (ret == 1) {
> +				/*
> +				Â * uk_netdev_rxq_intr_enable() told
> us that we
> +				Â * need to flush the receieve queue
> before

s/receieve/receive/

> +				Â * interrupts are enabled. For this
> purpose
> +				Â * we do an initial poll.
> +				Â */
> +				uknetdev_poll(nf);
> +			}
> Â 		} else {
> +#ifdef CONFIG_HAVE_SCHED
> Â 			LWIP_DEBUGF(NETIF_DEBUG,
> -				Â Â Â Â ("%s: %c%c%u: Enabled rx
> interrupt mode on netdev %u\n",
> -				Â Â Â Â Â __func__, nf->name[0], nf-
> >name[1],
> -				Â Â Â Â Â nf->num,
> uk_netdev_id_get(dev)));
> -		}
> -
> -		if (ret == 1) {
> -			/*
> -			Â * uk_netdev_rxq_intr_enable() told us that
> we need to
> -			Â * flush the receieve queue before
> interrupts are
> -			Â * enabled. For this purpose we do an
> initial poll.
> -			Â */
> -			uknetdev_poll(nf);
> +					("%s: Poll receive
> enabled\n",
> +					Â __func__));
> +			/* Create a thread */
> +			lwip_data->sched = uk_sched_get_default();
> +			UK_ASSERT(lwip_data->sched);
> +			lwip_data->poll_thread =
> +				uk_sched_thread_create(lwip_data-
> >sched, NULL,
> +						Â Â Â Â Â Â Â NULL,
> _poll_netif, nf);
> +#else /* CONFIG_HAVE_SCHED */
> +			uk_pr_warn("The netdevice does not support
> interrupt. Ensure the netdevice is polled to receive packets");
> +#endif /* CONFIG_HAVE_SCHED */
> Â 		}
> Â 	} else {
> -		uk_netdev_rxq_intr_disable(dev, 0);
> -		LWIP_DEBUGF(NETIF_DEBUG,
> -			Â Â Â Â ("%s: %c%c%u: Disabled rx interrupts on
> netdev %u\n",
> -			Â Â Â Â Â __func__, nf->name[0], nf->name[1],
> -			Â Â Â Â Â nf->num, uk_netdev_id_get(dev)));
> +		/**
> +		Â * TODO:
> +		Â * Cleanup the thread on stopping the network
> interface.
> +		Â */
> +		if (uk_netdev_rxintr_supported(lwip_data->features)) 
> {
> +			uk_netdev_rxq_intr_disable(dev, 0);
> +			LWIP_DEBUGF(NETIF_DEBUG,
> +					("%s: %c%c%u: Disabled rx
> interrupts on netdev %u\n",
> +					Â __func__, nf->name[0], nf-
> >name[1],
> +					Â nf->num,
> uk_netdev_id_get(dev)));
> +		}
> Â 
> Â 	}
> Â }


From minios-devel-bounces@lists.xenproject.org Thu Jul 09 13:47:41 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 09 Jul 2020 13:47:41 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jtWtm-0005fK-4Y; Thu, 09 Jul 2020 13:47:38 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=SbAQ=AU=neclab.eu=simon.kuenzer@srs-us1.protection.inumbo.net>)
 id 1jtWtk-0005fF-1n
 for minios-devel@lists.xen.org; Thu, 09 Jul 2020 13:47:36 +0000
X-Inumbo-ID: bd2f8f68-c1ea-11ea-bca7-bc764e2007e4
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id bd2f8f68-c1ea-11ea-bca7-bc764e2007e4;
 Thu, 09 Jul 2020 13:47:33 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 80113103BFA;
 Thu,  9 Jul 2020 15:47:32 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id N-nAgy1GF3Tn; Thu,  9 Jul 2020 15:47:32 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from Oberon.office.hd (Oberon.office.hd [192.168.24.90])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id 5A23E100073
 for <minios-devel@lists.xen.org>; Thu,  9 Jul 2020 15:47:32 +0200 (CEST)
Received: from puck.office.hd (192.168.24.91) by Oberon.office.hd
 (192.168.24.90) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 9 Jul 2020
 15:47:31 +0200
Received: from puck.office.hd ([192.168.126.12]) by puck.office.hd
 ([192.168.126.12]) with mapi id 15.01.1979.003; Thu, 9 Jul 2020 15:47:31
 +0200
From: Simon Kuenzer <simon.kuenzer@neclab.eu>
To: Sharan Santhanam <Sharan.Santhanam@neclab.eu>,
 "minios-devel@lists.xen.org" <minios-devel@lists.xen.org>
Subject: Re: [UNIKRAFT PATCH v3 1/2] lib/uknetdev: Add ipaddr, netmask &
 gwaddr as arg
Thread-Topic: [UNIKRAFT PATCH v3 1/2] lib/uknetdev: Add ipaddr, netmask &
 gwaddr as arg
Thread-Index: AQHWVTlp4dRmWOGxLka0u/bErrgS3Kj/RIaA
Date: Thu, 9 Jul 2020 13:47:31 +0000
Message-ID: <4283559B-41B2-4DF8-A701-BF2C31A61179@neclab.eu>
References: <20200708150538.26234-1-sharan.santhanam@neclab.eu>
 <20200708150538.26234-2-sharan.santhanam@neclab.eu>
In-Reply-To: <20200708150538.26234-2-sharan.santhanam@neclab.eu>
Accept-Language: en-GB, gl-ES, en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
user-agent: Microsoft-MacOutlook/10.10.17.200615
x-originating-ip: [192.168.24.96]
Content-Type: text/plain; charset="utf-8"
Content-ID: <FB09E7CE55BEC94590A21C365DDC97ED@office.hd>
Content-Transfer-Encoding: base64
MIME-Version: 1.0
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

SGV5IFNoYXJhbiwNCg0KVGhhbmtzIGEgbG90IGZvciB5b3VyIHdvcmssIHRoaXMgaXMgYSB2ZXJ5
IHVzZWZ1bCBmZWF0dXJlLiBJIGhhdmUgc29tZSBjb21tZW50cyB0byB0aGlzIHBhdGNoLg0KSSBw
dXQgdGhlbiBpbmxpbmUuDQoNClRoYW5rcywNCg0KU2ltb24NCg0K77u/T24gMDguMDcuMjAsIDE3
OjA2LCAiTWluaW9zLWRldmVsIG9uIGJlaGFsZiBvZiBTaGFyYW4gU2FudGhhbmFtIiA8bWluaW9z
LWRldmVsLWJvdW5jZXNAbGlzdHMueGVucHJvamVjdC5vcmcgb24gYmVoYWxmIG9mIFNoYXJhbi5T
YW50aGFuYW1AbmVjbGFiLmV1PiB3cm90ZToNCg0KICAgIFRoZSBwYXRjaCBhZGRzIGlwIGFkZHJl
c3MsIG5ldG1hc2sgYW5kIHRoZSBnYXRld2F5IGFkZHJlc3MgYXMgbGlicmFyeQ0KICAgIGFyZ3Vt
ZW50LiBUaGUgcGFyYW1ldGVycyBhcmUgbGlzdCBvZiBhcmd1bWVudCBkZWxpbWl0ZWQgYnkgYSBz
cGFjZS4NCiAgICBUaGUgbGlicmFyeSB1c2VyIGNhbiBmb3J3YXJkIHRoZSBhcmd1bWVudCB1c2lu
ZyB0aGUgZm9sbG93aW5nIGNvbW1hbmQNCiAgICBsaW5lOg0KICAgIG5ldC5pcHY0X2FkZHIsIG5l
dC5pcHY0X3N1Ym5ldF9tYXNrLCBuZXQuaXB2NF9nd19hZGRyDQogICAgDQogICAgU2lnbmVkLW9m
Zi1ieTogU2hhcmFuIFNhbnRoYW5hbSA8c2hhcmFuLnNhbnRoYW5hbUBuZWNsYWIuZXU+DQogICAg
LS0tDQogICAgIGxpYi91a25ldGRldi9Db25maWcudWsgICAgICAgICAgICAgICAgfCAgMSArDQog
ICAgIGxpYi91a25ldGRldi9NYWtlZmlsZS51ayAgICAgICAgICAgICAgfCAgMSArDQogICAgIGxp
Yi91a25ldGRldi9pbmNsdWRlL3VrL25ldGRldl9jb3JlLmggfCAgOSArKysrDQogICAgIGxpYi91
a25ldGRldi9uZXRkZXYuYyAgICAgICAgICAgICAgICAgfCA3OCArKysrKysrKysrKysrKysrKysr
KysrKysrKysNCiAgICAgNCBmaWxlcyBjaGFuZ2VkLCA4OSBpbnNlcnRpb25zKCspDQogICAgDQog
ICAgZGlmZiAtLWdpdCBhL2xpYi91a25ldGRldi9Db25maWcudWsgYi9saWIvdWtuZXRkZXYvQ29u
ZmlnLnVrDQogICAgaW5kZXggNjE4ZThlNjcuLjE4NmRkNDYyIDEwMDY0NA0KICAgIC0tLSBhL2xp
Yi91a25ldGRldi9Db25maWcudWsNCiAgICArKysgYi9saWIvdWtuZXRkZXYvQ29uZmlnLnVrDQog
ICAgQEAgLTQsNiArNCw3IEBAIG1lbnVjb25maWcgTElCVUtORVRERVYNCiAgICAgCXNlbGVjdCBM
SUJOT0xJQkMgaWYgIUhBVkVfTElCQw0KICAgICAJc2VsZWN0IExJQlVLREVCVUcNCiAgICAgCXNl
bGVjdCBMSUJVS0FMTE9DDQogICAgKwlpbXBseSBMSUJVS0xJQlBBUkFNDQogICAgIA0KICAgICBp
ZiBMSUJVS05FVERFVg0KICAgICAJY29uZmlnIExJQlVLTkVUREVWX01BWE5CUVVFVUVTDQogICAg
ZGlmZiAtLWdpdCBhL2xpYi91a25ldGRldi9NYWtlZmlsZS51ayBiL2xpYi91a25ldGRldi9NYWtl
ZmlsZS51aw0KICAgIGluZGV4IGNhMDhiMjU0Li5hYmRjZDRiYyAxMDA2NDQNCiAgICAtLS0gYS9s
aWIvdWtuZXRkZXYvTWFrZWZpbGUudWsNCiAgICArKysgYi9saWIvdWtuZXRkZXYvTWFrZWZpbGUu
dWsNCiAgICBAQCAtMSw0ICsxLDUgQEANCiAgICAgJChldmFsICQoY2FsbCBhZGRsaWJfcyxsaWJ1
a25ldGRldiwkKENPTkZJR19MSUJVS05FVERFVikpKQ0KICAgICskKGV2YWwgJChjYWxsIGFkZGxp
Yl9wYXJhbXByZWZpeCxsaWJ1a25ldGRldixuZXQpKQ0KICAgICANCiAgICAgQ0lOQ0xVREVTLSQo
Q09ORklHX0xJQlVLTkVUREVWKQkJKz0gLUkkKExJQlVLTkVUREVWX0JBU0UpL2luY2x1ZGUNCiAg
ICAgQ1hYSU5DTFVERVMtJChDT05GSUdfTElCVUtORVRERVYpCSs9IC1JJChMSUJVS05FVERFVl9C
QVNFKS9pbmNsdWRlDQogICAgZGlmZiAtLWdpdCBhL2xpYi91a25ldGRldi9pbmNsdWRlL3VrL25l
dGRldl9jb3JlLmggYi9saWIvdWtuZXRkZXYvaW5jbHVkZS91ay9uZXRkZXZfY29yZS5oDQogICAg
aW5kZXggZGJhNzE5ZmMuLmQyZThkYTA1IDEwMDY0NA0KICAgIC0tLSBhL2xpYi91a25ldGRldi9p
bmNsdWRlL3VrL25ldGRldl9jb3JlLmgNCiAgICArKysgYi9saWIvdWtuZXRkZXYvaW5jbHVkZS91
ay9uZXRkZXZfY29yZS5oDQogICAgQEAgLTM3Myw2ICszNzMsMTIgQEAgc3RydWN0IHVrX25ldGRl
dl9kYXRhIHsNCiAgICAgCWNvbnN0IGNoYXIgICAgICAgICAgICpkcnZfbmFtZTsNCiAgICAgfTsN
CiAgICAgDQogICAgK3N0cnVjdCB1a19uZXRkZXZfY29uZmlnIHsNCiAgICArCWNvbnN0IGNoYXIg
KmlwdjRfYWRkcjsNCiAgICArCWNvbnN0IGNoYXIgKmlwdjRfbmV0X21hc2s7DQogICAgKwljb25z
dCBjaGFyICppcHY0X2d3X2FkZHI7DQogICAgK307DQogICAgKw0KDQpJIHdvdWxkIGNhbGwgaXQg
YHN0cnVjdCB1a19uZXRkZXZfZWluZm9gIG9yIHNpbWlsYXIgYmVjYXVzZSB5b3UgYXJlIGdvaW5n
IHRvIHVzZSBpdCB0byBvdmVyd3JpdGUgdmFsdWVzIGZyb20gb3VyIGV4aXN0aW5nIGBlaW5mb2Ag
aW50ZXJmYWNlLg0KDQogICAgIC8qKg0KICAgICAgKiBORVRERVYNCiAgICAgICogQSBzdHJ1Y3R1
cmUgdXNlZCB0byBpbnRlcmFjdCB3aXRoIGEgbmV0d29yayBkZXZpY2UuDQogICAgQEAgLTQwMCw2
ICs0MDYsOSBAQCBzdHJ1Y3QgdWtfbmV0ZGV2IHsNCiAgICAgCXN0cnVjdCB1a19uZXRkZXZfdHhf
cXVldWUgICAqX3R4X3F1ZXVlW0NPTkZJR19MSUJVS05FVERFVl9NQVhOQlFVRVVFU107DQogICAg
IA0KICAgICAJVUtfVEFJTFFfRU5UUlkoc3RydWN0IHVrX25ldGRldikgX2xpc3Q7DQogICAgKw0K
ICAgICsJLyoqIE5ldGRldmljZSBhZGRyZXNzIGNvbmZpZ3VyYXRpb24gKi8NCiAgICArCXN0cnVj
dCB1a19uZXRkZXZfY29uZmlnCSAgICpfY29uZmlnOw0KDQpJIHdvdWxkIGNhbGwgaXQgYCpfZWlu
Zm9gIG9yIGAqX2VpbmZvX292ZXJ3cml0ZWAgdG8gbWFrZSBpdCBtb3JlIGNsZWFyIHdoYXQgdGhp
cyBpcy4NCg0KICAgICB9Ow0KICAgICANCiAgICAgI2lmZGVmIF9fY3BsdXNwbHVzDQogICAgZGlm
ZiAtLWdpdCBhL2xpYi91a25ldGRldi9uZXRkZXYuYyBiL2xpYi91a25ldGRldi9uZXRkZXYuYw0K
ICAgIGluZGV4IDE1MWUwODk3Li5lMGVlNDQyNyAxMDA2NDQNCiAgICAtLS0gYS9saWIvdWtuZXRk
ZXYvbmV0ZGV2LmMNCiAgICArKysgYi9saWIvdWtuZXRkZXYvbmV0ZGV2LmMNCiAgICBAQCAtMzgs
MTAgKzM4LDYyIEBADQogICAgICNpbmNsdWRlIDxzdHJpbmcuaD4NCiAgICAgI2luY2x1ZGUgPHVr
L25ldGRldi5oPg0KICAgICAjaW5jbHVkZSA8dWsvcHJpbnQuaD4NCiAgICArI2luY2x1ZGUgPHVr
L2xpYnBhcmFtLmg+DQogICAgIA0KICAgICBzdHJ1Y3QgdWtfbmV0ZGV2X2xpc3QgdWtfbmV0ZGV2
X2xpc3QgPQ0KICAgICAJVUtfVEFJTFFfSEVBRF9JTklUSUFMSVpFUih1a19uZXRkZXZfbGlzdCk7
DQogICAgIHN0YXRpYyB1aW50MTZfdCBuZXRkZXZfY291bnQ7DQogICAgKy8qKg0KICAgICsgKiBU
T0RPOiBEZWZpbmUgTmV0d29yayBhcmd1bWVudCBmb3JtYXQgd2hlbiBtdWx0aXBsZSBkcml2ZXIg
ZGV2aWNlIG5lZWQgdG8NCiAgICArICogY29leGlzdC4gRm9yIGV4YW1wbGUgbGlrZToNCiAgICAr
ICogRHJpdmVyIE5hbWU6SVAgQWRkcmVzczpOZXQgTWFzaw0KICAgICsgKi8NCiAgICArc3RhdGlj
IGNoYXIgKmlwdjRfYWRkcjsNCiAgICArc3RhdGljIGNoYXIgKmlwdjRfc3VibmV0X21hc2s7DQog
ICAgK3N0YXRpYyBjaGFyICppcHY0X2d3X2FkZHI7DQogICAgKw0KICAgICtVS19MSUJfUEFSQU1f
U1RSKGlwdjRfYWRkcik7DQogICAgK1VLX0xJQl9QQVJBTV9TVFIoaXB2NF9zdWJuZXRfbWFzayk7
DQogICAgK1VLX0xJQl9QQVJBTV9TVFIoaXB2NF9nd19hZGRyKTsNCiAgICArDQogICAgK3N0YXRp
YyBjb25zdCBjaGFyICpfcGFyc2VfaXB2NF9hZGRyKHZvaWQpDQogICAgK3sNCiAgICArCS8qKiBS
ZW1lbWJlciB0aGUgcmVmZXJlbmNlIHRvIHRoZSBpcCBhZGRyZXNzIGZvciBzdWNjZXNzaXZlIGNh
bGxzKi8NCiAgICArCXN0YXRpYyBjaGFyICppcF9hZGRyOw0KICAgICsNCiAgICArCWlmIChpcF9h
ZGRyKQ0KICAgICsJCXJldHVybiBzdHJ0b2tfcihOVUxMLCAiICIsICZpcF9hZGRyKTsNCiAgICAr
CWVsc2UgaWYgKGlwdjRfYWRkcikNCiAgICArCQlyZXR1cm4gc3RydG9rX3IoaXB2NF9hZGRyLCAi
ICIsICZpcF9hZGRyKTsNCiAgICArDQogICAgKwlyZXR1cm4gTlVMTDsNCiAgICArfQ0KICAgICsN
CiAgICArc3RhdGljIGNvbnN0IGNoYXIgKl9wYXJzZV9pcHY0X25ldF9tYXNrKHZvaWQpDQogICAg
K3sNCiAgICArCS8qKiBSZW1lbWJlciB0aGUgcmVmZXJlbmNlIHRvIHRoZSBuZXRtYXNrIGZvciBz
dWNjZXNzaXZlIGNhbGxzKi8NCiAgICArCXN0YXRpYyBjaGFyICpuZXRfbWFzazsNCiAgICArDQog
ICAgKwlpZiAobmV0X21hc2spDQogICAgKwkJcmV0dXJuIHN0cnRva19yKE5VTEwsICIgIiwgJm5l
dF9tYXNrKTsNCiAgICArCWVsc2UgaWYgKGlwdjRfc3VibmV0X21hc2spDQogICAgKwkJcmV0dXJu
IHN0cnRva19yKGlwdjRfc3VibmV0X21hc2ssICIgIiwgJm5ldF9tYXNrKTsNCiAgICArDQogICAg
KwlyZXR1cm4gTlVMTDsNCiAgICArfQ0KICAgICsNCiAgICArc3RhdGljIGNvbnN0IGNoYXIgKl9w
YXJzZV9pcHY0X2d3X2FkZHIodm9pZCkNCiAgICArew0KICAgICsJLyoqIFJlbWVtYmVyIHRoZSBy
ZWZlcmVuY2UgdG8gdGhlIGdhdGV3YXkgYWRkcmVzcyBmb3Igc3VjY2Vzc2l2ZSBjYWxscyovDQog
ICAgKwlzdGF0aWMgY2hhciAqZ3c7DQogICAgKw0KICAgICsJaWYgKGd3KQ0KICAgICsJCXJldHVy
biBzdHJ0b2tfcihOVUxMLCAiICIsICZndyk7DQogICAgKwllbHNlIGlmIChpcHY0X2d3X2FkZHIp
DQogICAgKwkJcmV0dXJuIHN0cnRva19yKGlwdjRfZ3dfYWRkciwgIiAiLCAmZ3cpOw0KICAgICsN
CiAgICArCXJldHVybiBOVUxMOw0KICAgICt9DQogICAgIA0KICAgICBzdGF0aWMgc3RydWN0IHVr
X25ldGRldl9kYXRhICpfYWxsb2NfZGF0YShzdHJ1Y3QgdWtfYWxsb2MgKmEsDQogICAgIAkJCQkJ
ICB1aW50MTZfdCBuZXRkZXZfaWQsDQogICAgQEAgLTY0LDYgKzExNiwyNSBAQCBzdGF0aWMgc3Ry
dWN0IHVrX25ldGRldl9kYXRhICpfYWxsb2NfZGF0YShzdHJ1Y3QgdWtfYWxsb2MgKmEsDQogICAg
IAlyZXR1cm4gZGF0YTsNCiAgICAgfQ0KICAgICANCiAgICArc3RhdGljIHN0cnVjdCB1a19uZXRk
ZXZfY29uZmlnICpfYWxsb2NfY29uZmlnKHN0cnVjdCB1a19hbGxvYyAqYSkNCiAgICArew0KICAg
ICsJc3RydWN0IHVrX25ldGRldl9jb25maWcgKl9jb25maWcgPSBOVUxMOw0KICAgICsNCiAgICAr
CWlmIChpcHY0X2FkZHIgfHwgaXB2NF9zdWJuZXRfbWFzayB8fCBpcHY0X2d3X2FkZHIpIHsNCiAg
ICArCQlfY29uZmlnID0gdWtfemFsbG9jKGEsIHNpemVvZigqX2NvbmZpZykpOw0KICAgICsJCWlm
ICghX2NvbmZpZykgew0KICAgICsJCQl1a19wcl93YXJuKCJGYWlsZWQgdG8gYWxsb2NhdGUgbWVt
b3J5IGZvciBuZXRkZXYgY29uZmlnXG4iKTsNCiAgICArCQkJcmV0dXJuIE5VTEw7DQoNCkkgZG9u
J3QgdGhpbmsgaXQgaXMgYSBnb29kIGlkZWEgdG8gaWdub3JlIGFuIGFsbG9jYXRpb24gZmFpbHVy
ZS4gSSBhbSBjb25jZXJuZWQgdGhhdCBpdCBsZWFkcyB0byB1bmV4cGVjdGVkIGJlaGF2aW9yLiBZ
b3UgY291bGQgcmV0dXJuIGFuIEVSUlBUUiB2YWx1ZTogPHVrL2VycnB0ci5oPi4NCg0KICAgICsJ
CX0NCiAgICArDQogICAgKwkJX2NvbmZpZy0+aXB2NF9hZGRyID0gX3BhcnNlX2lwdjRfYWRkcigp
Ow0KICAgICsJCV9jb25maWctPmlwdjRfbmV0X21hc2sgPSBfcGFyc2VfaXB2NF9uZXRfbWFzaygp
Ow0KICAgICsJCV9jb25maWctPmlwdjRfZ3dfYWRkciA9IF9wYXJzZV9pcHY0X2d3X2FkZHIoKTsN
CiANClRoaXMgbG9va3MgbGlrZSBjYWNoaW5nIHZhbHVlcyB0byBtZS4gWW91IHByb2JhYmx5IHdh
bnQgdG8gZG8gdGhpcyB3aXRoaW4gYCB1a19uZXRkZXZfZWluZm9fZ2V0KClgIHdoZW4gYWNjZXNz
aW5nIGEgZmllbGQgdGhlIGZpcnN0IHRpbWU/IFRoZSByZWFzb24gaXMgdGhhdCB5b3UgY291bGQg
dGhlbiBhbHNvIGNhY2hlIHRoZSBkcml2ZXIgcmVzcG9uc2Ugd2hlbiBubyBvdmVyd3JpdGUgZXhp
c3RzLg0KDQogICArCX0NCiAgICArDQogICAgKwlyZXR1cm4gX2NvbmZpZzsNCiAgICArfQ0KICAg
ICsNCiAgICAgaW50IHVrX25ldGRldl9kcnZfcmVnaXN0ZXIoc3RydWN0IHVrX25ldGRldiAqZGV2
LCBzdHJ1Y3QgdWtfYWxsb2MgKmEsDQogICAgIAkJCSAgIGNvbnN0IGNoYXIgKmRydl9uYW1lKQ0K
ICAgICB7DQogICAgQEAgLTkxLDYgKzE2MiwxMyBAQCBpbnQgdWtfbmV0ZGV2X2Rydl9yZWdpc3Rl
cihzdHJ1Y3QgdWtfbmV0ZGV2ICpkZXYsIHN0cnVjdCB1a19hbGxvYyAqYSwNCiAgICAgCWlmICgh
ZGV2LT5fZGF0YSkNCiAgICAgCQlyZXR1cm4gLUVOT01FTTsNCiAgICAgDQogICAgKwkvKioNCiAg
ICArCSAqIFNpbmNlIHRoZSBfY29uZmlnIGlzIG1lYW50IHRvIGJlIG9wdGlvbmFsLCB0aGUgYm9v
dCBwcm9jZXNzIHNob3VsZA0KICAgICsJICogc3RpbGwgY29udGludWUgaWYgdGhlIGFsbG9jYXRp
b24gb2YgY29uZmlnIGZhaWxzIGluc3RlYWQgb2YgcmVwb3J0aW5nDQogICAgKwkgKiBlcnJvci4N
CiAgICArCSAqLw0KICAgICsJZGV2LT5fY29uZmlnID0gX2FsbG9jX2NvbmZpZyhhKTsNCiAgICAr
DQogICAgIAlVS19UQUlMUV9JTlNFUlRfVEFJTCgmdWtfbmV0ZGV2X2xpc3QsIGRldiwgX2xpc3Qp
Ow0KICAgICAJdWtfcHJfaW5mbygiUmVnaXN0ZXJlZCBuZXRkZXYlIlBSSXUxNiI6ICVwICglcylc
biIsDQogICAgIAkJICAgbmV0ZGV2X2NvdW50LCBkZXYsIGRydl9uYW1lKTsNCiAgICAtLSANCiAg
ICAyLjIwLjENCiAgICANCiAgICANCiAgICANCg0K


From minios-devel-bounces@lists.xenproject.org Thu Jul 09 13:51:11 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 09 Jul 2020 13:51:11 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jtWxC-0006Mu-Dm; Thu, 09 Jul 2020 13:51:10 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=SbAQ=AU=neclab.eu=simon.kuenzer@srs-us1.protection.inumbo.net>)
 id 1jtWxB-0006Mp-Ab
 for minios-devel@lists.xen.org; Thu, 09 Jul 2020 13:51:09 +0000
X-Inumbo-ID: 3d00612c-c1eb-11ea-b7bb-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 3d00612c-c1eb-11ea-b7bb-bc764e2007e4;
 Thu, 09 Jul 2020 13:51:07 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 0524FF200A;
 Thu,  9 Jul 2020 15:51:07 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 6xkkpip7vq4r; Thu,  9 Jul 2020 15:51:06 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from Oberon.office.hd (Oberon.office.hd [192.168.24.90])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id BF35FF2007
 for <minios-devel@lists.xen.org>; Thu,  9 Jul 2020 15:51:04 +0200 (CEST)
Received: from puck.office.hd (192.168.24.91) by Oberon.office.hd
 (192.168.24.90) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 9 Jul 2020
 15:51:04 +0200
Received: from puck.office.hd ([192.168.126.12]) by puck.office.hd
 ([192.168.126.12]) with mapi id 15.01.1979.003; Thu, 9 Jul 2020 15:51:04
 +0200
From: Simon Kuenzer <simon.kuenzer@neclab.eu>
To: Sharan Santhanam <Sharan.Santhanam@neclab.eu>,
 "minios-devel@lists.xen.org" <minios-devel@lists.xen.org>
Subject: Re: [UNIKRAFT PATCH v3 2/2] lib/uknetdev: Get the ipaddr, gw_addr and
 subnet
Thread-Topic: [UNIKRAFT PATCH v3 2/2] lib/uknetdev: Get the ipaddr, gw_addr
 and subnet
Thread-Index: AQHWVTloP1ec6Y3ZGUOl7p4kcmaqaaj/RYWA
Date: Thu, 9 Jul 2020 13:51:04 +0000
Message-ID: <3BE03A1F-5036-4807-8D13-7E66AC691E29@neclab.eu>
References: <20200708150538.26234-1-sharan.santhanam@neclab.eu>
 <20200708150538.26234-3-sharan.santhanam@neclab.eu>
In-Reply-To: <20200708150538.26234-3-sharan.santhanam@neclab.eu>
Accept-Language: en-GB, gl-ES, en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
user-agent: Microsoft-MacOutlook/10.10.17.200615
x-originating-ip: [192.168.24.96]
Content-Type: text/plain; charset="utf-8"
Content-ID: <46078008611B564CA1878FD7B749EBA2@office.hd>
Content-Transfer-Encoding: base64
MIME-Version: 1.0
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

T24gMDguMDcuMjAsIDE3OjA2LCAiTWluaW9zLWRldmVsIG9uIGJlaGFsZiBvZiBTaGFyYW4gU2Fu
dGhhbmFtIiA8bWluaW9zLWRldmVsLWJvdW5jZXNAbGlzdHMueGVucHJvamVjdC5vcmcgb24gYmVo
YWxmIG9mIFNoYXJhbi5TYW50aGFuYW1AbmVjbGFiLmV1PiB3cm90ZToNCg0KICAgIFRoZSB1c2Vy
IG9mIHVrbmV0ZGV2IGNhbiBwYXNzIHRoZSBpcGFkZHIsIGd3X2FkZHIgYW5kIHN1Ym5ldCBhcyBh
DQogICAgbGlicmFyeSBhcmd1bWVudC4gVGhlIGxpYnJhcnkgYXJndW1lbnQgY2FuIGJlIHJldHJp
ZXZlZCBmcm9tIHRoZQ0KICAgIG5ldHdvcmsgc3RhY2sgdXNpbmcgdWtfbmV0ZGV2X2VpbmZvX2dl
dCBmdW5jdGlvbi4gVGhlIGxpYnJhcnkNCiAgICBhcmd1bWVudHMgYXJlIHJldHJpZXZlZCBvbmx5
IGlmIHRoZSBkcml2ZXIgZG9lcyBub3Qgc3VwcG9ydCB0aGUNCiAgICB1a19uZXRkZXZfZWluZm9f
Z2V0IGNhbGxiYWNrLg0KDQpJIHdvdWxkIG92ZXJ3cml0ZSB0aGUgZHJpdmVyIHZhbHVlcyB3aXRo
IHRoZSBrZXJuZWwgY29tbWFuZCBsaW5lIC0gc28gY2hhbmdpbmcgdGhlIHByaW9yaXR5LiBJIHRo
aW5rIHdlIGhhdmUgYSBzaW1pbGFyIGJlaGF2aW9yIHdpdGggTGludXggZ3Vlc3RzIG9uIFhlbi4g
SVAgYWRkcmVzcyBzZXR0aW5ncyB0aHJvdWdoIHhlbiB0b3JlIGFyZSBpZ25vcmVkIHdoZW4gdGhl
IGtlcm5lbCBjb21tYW5kIGxpbmUgaGFzIGRpZmZlcmVudCBhZGRyZXNzZXMsIHJpZ2h0PyBJIHdv
dWxkIHRyeSB0byBiZSBpbmxpbmUgd2l0aCB0aGF0IGJlaGF2aW9yLg0KICAgIA0KICAgIFNpZ25l
ZC1vZmYtYnk6IFNoYXJhbiBTYW50aGFuYW0gPHNoYXJhbi5zYW50aGFuYW1AbmVjbGFiLmV1Pg0K
ICAgIC0tLQ0KICAgICBsaWIvdWtuZXRkZXYvbmV0ZGV2LmMgfCAyNCArKysrKysrKysrKysrKysr
KysrKysrKysNCiAgICAgMSBmaWxlIGNoYW5nZWQsIDI0IGluc2VydGlvbnMoKykNCiAgICANCiAg
ICBkaWZmIC0tZ2l0IGEvbGliL3VrbmV0ZGV2L25ldGRldi5jIGIvbGliL3VrbmV0ZGV2L25ldGRl
di5jDQogICAgaW5kZXggZTBlZTQ0MjcuLjIzNTgxZjUwIDEwMDY0NA0KICAgIC0tLSBhL2xpYi91
a25ldGRldi9uZXRkZXYuYw0KICAgICsrKyBiL2xpYi91a25ldGRldi9uZXRkZXYuYw0KICAgIEBA
IC0yMzksNiArMjM5LDI4IEBAIHZvaWQgdWtfbmV0ZGV2X2luZm9fZ2V0KHN0cnVjdCB1a19uZXRk
ZXYgKmRldiwNCiAgICAgCQkJCSAgICAgIGRldl9pbmZvLT5tYXhfdHhfcXVldWVzKTsNCiAgICAg
fQ0KICAgICANCiAgICArc3RhdGljIGNvbnN0IHZvaWQgKl9uZXRkZXZfZWluZm9fZ2V0KHN0cnVj
dCB1a19uZXRkZXYgKmRldiwNCiAgICArCQkJCWVudW0gdWtfbmV0ZGV2X2VpbmZvX3R5cGUgZWlu
Zm8pDQogICAgK3sNCiAgICArCXN3aXRjaCAoZWluZm8pIHsNCiAgICArCWNhc2UgVUtfTkVUREVW
X0lQVjRfQUREUl9TVFI6DQogICAgKwkJaWYgKGRldi0+X2NvbmZpZy0+aXB2NF9hZGRyKQ0KICAg
ICsJCQl1a19wcl9kZWJ1ZygiaXBfYWRkcjogJXNcbiIsIGRldi0+X2NvbmZpZy0+aXB2NF9hZGRy
KTsNCiAgICArCQlyZXR1cm4gZGV2LT5fY29uZmlnLT5pcHY0X2FkZHI7DQogICAgKwljYXNlIFVL
X05FVERFVl9JUFY0X01BU0tfU1RSOg0KICAgICsJCWlmIChkZXYtPl9jb25maWctPmlwdjRfbmV0
X21hc2spDQogICAgKwkJCXVrX3ByX2RlYnVnKCJuZXRtYXNrOiAlc1xuIiwgZGV2LT5fY29uZmln
LT5pcHY0X25ldF9tYXNrKTsNCiAgICArCQlyZXR1cm4gZGV2LT5fY29uZmlnLT5pcHY0X25ldF9t
YXNrOw0KICAgICsJY2FzZSBVS19ORVRERVZfSVBWNF9HV19TVFI6DQogICAgKwkJaWYgKGRldi0+
X2NvbmZpZy0+aXB2NF9nd19hZGRyKQ0KICAgICsJCQl1a19wcl9kZWJ1ZygiR2F0ZXdheTogJXNc
biIsIGRldi0+X2NvbmZpZy0+aXB2NF9nd19hZGRyKTsNCiAgICArCQlyZXR1cm4gZGV2LT5fY29u
ZmlnLT5pcHY0X2d3X2FkZHI7DQogICAgKwlkZWZhdWx0Og0KICAgICsJCXVrX3ByX3dhcm4oIk9w
dGlvbiAlZCBub3QgeWV0IHN1cHBvcnRlZFxuIiwgZWluZm8pOw0KICAgICsJfQ0KICAgICsJcmV0
dXJuIE5VTEw7DQogICAgK30NCiAgICArDQogICAgIGNvbnN0IHZvaWQgKnVrX25ldGRldl9laW5m
b19nZXQoc3RydWN0IHVrX25ldGRldiAqZGV2LA0KICAgICAJCQkJZW51bSB1a19uZXRkZXZfZWlu
Zm9fdHlwZSBlaW5mbykNCiAgICAgew0KICAgIEBAIC0yNDcsNiArMjY5LDggQEAgY29uc3Qgdm9p
ZCAqdWtfbmV0ZGV2X2VpbmZvX2dldChzdHJ1Y3QgdWtfbmV0ZGV2ICpkZXYsDQogICAgIA0KICAg
ICAJaWYgKCFkZXYtPm9wcy0+ZWluZm9fZ2V0KSB7DQogICAgIAkJLyogZHJpdmVyIGRvZXMgbm90
IHByb3ZpZGUgYW55IGV4dHJhIGNvbmZpZ3VyYXRpb24gKi8NCiAgICArCQlpZiAoZGV2LT5fY29u
ZmlnKQ0KICAgICsJCQlyZXR1cm4gX25ldGRldl9laW5mb19nZXQoZGV2LCBlaW5mbyk7DQogICAg
IAkJcmV0dXJuIE5VTEw7DQogICAgIAl9DQogICAgIAlyZXR1cm4gZGV2LT5vcHMtPmVpbmZvX2dl
dChkZXYsIGVpbmZvKTsNCiAgICAtLSANCiAgICAyLjIwLjENCiAgICANCiAgICANCiAgICANCg0K


From minios-devel-bounces@lists.xenproject.org Thu Jul 09 15:23:12 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 09 Jul 2020 15:23:12 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jtYOD-0005cz-79; Thu, 09 Jul 2020 15:23:09 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=SbAQ=AU=neclab.eu=simon.kuenzer@srs-us1.protection.inumbo.net>)
 id 1jtYOC-0005cu-Eg
 for minios-devel@lists.xenproject.org; Thu, 09 Jul 2020 15:23:08 +0000
X-Inumbo-ID: 1547f427-c1f8-11ea-8ee5-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 1547f427-c1f8-11ea-8ee5-12813bfff9fa;
 Thu, 09 Jul 2020 15:23:06 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id E0F94F200A;
 Thu,  9 Jul 2020 17:23:04 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 7oQzc8Stc4fG; Thu,  9 Jul 2020 17:23:04 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id AFC03F2007
 for <minios-devel@lists.xenproject.org>; Thu,  9 Jul 2020 17:23:02 +0200 (CEST)
Received: from puck.office.hd (192.168.24.91) by titania.office.hd
 (192.168.24.89) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 9 Jul 2020
 17:23:02 +0200
Received: from puck.office.hd ([192.168.126.12]) by puck.office.hd
 ([192.168.126.12]) with mapi id 15.01.1979.003; Thu, 9 Jul 2020 17:23:02
 +0200
From: Simon Kuenzer <simon.kuenzer@neclab.eu>
To: Sharan Santhanam <Sharan.Santhanam@neclab.eu>,
 "minios-devel@lists.xenproject.org" <minios-devel@lists.xenproject.org>
Subject: Re: Unikraft makefile - how to copy files in Makefile.uk
Thread-Topic: Unikraft makefile - how to copy files in Makefile.uk
Thread-Index: AQHWVFDIHl0cPvPrPkWQau68Byr6s6j74feAgAN/EYA=
Date: Thu, 9 Jul 2020 15:23:02 +0000
Message-ID: <54BD2FAF-6238-4152-8D1C-18941726572F@neclab.eu>
References: <CAMEmTtXANxmphAj8tOmcqjdHzEqwEzJuY=Se0FbFdMwDvRQFFg@mail.gmail.com>
 <714bbaaf-be90-b61d-89a7-731f0de18f26@neclab.eu>
In-Reply-To: <714bbaaf-be90-b61d-89a7-731f0de18f26@neclab.eu>
Accept-Language: en-GB, gl-ES, en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
user-agent: Microsoft-MacOutlook/10.10.17.200615
x-originating-ip: [192.168.24.96]
Content-Type: text/plain; charset="utf-8"
Content-ID: <94580EAE6A844846BBC95974D9812B36@office.hd>
Content-Transfer-Encoding: base64
MIME-Version: 1.0
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

SGkgRmVsaXgsDQoNCu+7v09uIDA3LjA3LjIwLCAxNDowMCwgIk1pbmlvcy1kZXZlbCBvbiBiZWhh
bGYgb2YgU2hhcmFuIFNhbnRoYW5hbSIgPG1pbmlvcy1kZXZlbC1ib3VuY2VzQGxpc3RzLnhlbnBy
b2plY3Qub3JnIG9uIGJlaGFsZiBvZiBTaGFyYW4uU2FudGhhbmFtQG5lY2xhYi5ldT4gd3JvdGU6
DQoNCiAgICBIZWxsbywNCiAgICANCiAgICBQbGVhc2UgZmluZCB0aGUgY29tbWVudCBpbmxpbmU6
DQogICAgDQogICAgT24gNy83LzIwIDE6MjAgUE0sIGZlbGl4IG5hc2NoIHdyb3RlOg0KICAgID4g
SGksDQogICAgPg0KICAgID4gSSB3YXMgaGFuZ2luZyBvdXQgaW4gdGhlIElSQyBjaGFubmVsLCBi
dXQgaXQgc2VlbXMgaW5hY3RpdmUsIHNvIEkgYW0NCiAgICA+IGFza2luZyBoZXJlLCBob3BlIHRo
YXQncyBvay4gOikNCiAgICA+IEkgYW0gdHJ5aW5nIHRvIHBvcnQgYSBsaWJyYXJ5IHRvIFVuaWty
YWZ0LCBhbmQgYXMgcGFydCBvZiB0aGUgYnVpbGQgcHJvY2VzcyBJDQogICAgPiB3YW50IHRvIGNv
cHkgYXJvdW5kIGEgZmV3IGZpbGVzIGFmdGVyIGV4dHJhY3RpbmcgdGhlIHNvdXJjZSBmaWxlcy4N
CiAgICA+IFRoaXMgaXMgdG8gc29sdmUgdGhlc2UgdHdvIHByb2JsZW1zOg0KICAgID4NCiAgICA+
IDEuIFNvbWUgc291cmNlIGZpbGVzIGhhdmUgdGhlIHNhbWUgbmFtZSAoaW4gZGlmZmVyZW50IGRp
cnMpLCBidXQgdGhlDQogICAgPiAgICAgIHVuaWtyYWZ0IGJ1aWxkIHN5c3RlbSBwbGFjZXMgYWxs
IC5vYmogZmlsZXMgaW50byB0aGUgcm9vdCBkaXJlY3RvcnksIHRodXMNCiAgICA+ICAgICAgY29s
bGlkaW5nIG9iamVjdCBmaWxlcyBvdmVyd3JpdGUgZWFjaCBvdGhlci4gIEkgd2FudCB0byByZW5h
bWUgY29uZmxpY3RpbmcNCiAgICA+ICAgICAgZmlsZXMgcHJpb3IgdG8gY29tcGlsYXRpb24uDQog
ICAgDQogICAgT3VyIGFwcHJvYWNoIHRvIHNvbHZlIHRoZSBwcm9ibGVtLCBoYXMgYmVlbiB0byBy
ZXNvbHZlIG5hbWUgY29sbGlzaW9uIA0KICAgIHdpdGggYSAnfCcgZGlyZWN0aXZlLiBUaGUgJ3wn
IHdvdWxkIHByZXBlbmQgdGhlIG9iamVjdCBmaWxlIHdpdGggdGhlIA0KICAgIG5hbWUgZm9sbG93
aW5nIHRoZSBwaXBlLg0KICAgIA0KICAgIEZvciBlZywgaWYgeW91IGxvb2sgYXQgdGhlIE1ha2Vm
aWxlLnVrIGluIHBsYXQva3ZtLw0KICAgIA0KICAgIExJQktWTVBMQVRfU1JDUy0kKENPTkZJR19B
UkNIX1g4Nl82NCkgKz0gDQogICAgJChVS19QTEFUX0NPTU1PTl9CQVNFKS94ODYvdHJhY2UuY3xj
b21tb24NCiAgICANCiAgICBMSUJLVk1QTEFUX1NSQ1MtJChDT05GSUdfQVJDSF9YODZfNjQpICs9
ICQoTElCS1ZNUExBVF9CQVNFKS94ODYvdHJhY2UuYw0KICAgIA0KICAgIA0KICAgID4NCiAgICA+
IDIuIEluY2x1ZGUgcGF0aHMgLSB3aGVuIGV4dHJhY3RpbmcgdGhlIHNvdXJjZSBwYWNrYWdlLCB0
aGUgaW5jbHVkZSBwYXRoIGlzIG5vdA0KICAgID4gICAgICBob3cgY29uc3VtZXJzIG9mIHRoZSBs
aWJyYXJ5IGV4cGVjdCBpdC4gSSB3b3VsZCB3YW50IHRvIGNyZWF0ZSBhbg0KICAgID4gYXBwcm9w
cmlhdGVseQ0KICAgID4gICAgICBuYW1lZCBzdWJkaXIgYW5kIG1vdmUgdGhlIGhlYWRlciBmaWxl
cyBpbnRvIGl0Lg0KICAgID4NCiAgICA+IEhvd2V2ZXIsIEkgY2FuJ3QgZmlndXJlIG91dCBob3cg
dG8gZXhlY3V0ZSBhIHNpbXBsZSAiY3AgPHNyYz4gPGRlc3Q+Ig0KICAgID4gaW4gTWFrZWZpbGUu
dWssIHNpbmNlIG5ldyB0YXJnZXRzIGNhbm5vdCBiZSBkZWZpbmVkLjoNCiAgICANCiAgICBUaGlz
IGlzIGEgZmVhdHVyZSB3ZSBkbyBub3Qgc3VwcG9ydCB5ZXQuIElmIHlvdSBiZWxpZXZlIHRoZSBw
cm9ibGVtIGlzIA0KICAgIHZlcnkgc3BlY2lmaWMgdG8gYSBzaW5nbGUgbGlicmFyeSwgeW91IGNh
biBkbyBzb21ldGhpbmcgbGlrZSBbMV0uDQogICAgDQogICAgWzFdIGh0dHBzOi8vZ2l0aHViLmNv
bS91bmlrcmFmdC9saWItbHVhL2Jsb2IvbWFzdGVyL01ha2VmaWxlLnVrIA0KICAgIDxodHRwczov
L2dpdGh1Yi5jb20vdW5pa3JhZnQvbGliLWx1YS9ibG9iL21hc3Rlci9NYWtlZmlsZS51az4NCiAg
ICANClRoaXMgaXMgcmlnaHQsIGluIGxpYmx1YSB3ZSBjcmVhdGVkIHN5bWJvbGljIGxpbmtzIG9m
IHRoZSBwdWJsaWMgbGlicmFyeSBoZWFkZXIgZmlsZXMgYXMgcGFydCBvZiB0aGUgcHJlcGFyZSBz
dGVwIChsbiAtcyA8c3JjPiA8ZGVzdD4pLiBZb3UgY2FuIHRha2UgU2hhcmFuJ3MgbGluayBhcyBh
biBleGFtcGxlLiBJbiBnZW5lcmFsLCB5b3Ugc2hvdWxkIG1ha2Ugc3VyZSB0aGF0IGV2ZXJ5IGZp
bGUgZ2VuZXJhdGVkLCBjb3BpZWQsIG9yIGxpbmtlZCBzaG91bGQgZ28gdG8gdGhlIGJ1aWxkIHN1
YiBkaXJlY3Rvcnkgb2YgdGhlIGxpYnJhcnkgKExJQk5BTUVfQlVJTEQpLiBJbiB0aGVyZSB5b3Ug
YXJlIGZyZWUgdG8gb3JnYW5pemUgeW91ciBzdWJzdHJ1Y3R1cmUuDQogICAgDQogICAgPg0KICAg
ID4gSG93IGNhbiBJIGRvIHRoYXQ/DQogICAgPg0KICAgID4gVGhhbmtzLA0KICAgID4gZi4NCiAg
ICA+DQogICAgDQpUaGFua3MsDQoNClNpbW9uDQogICAgDQoNCg==


From minios-devel-bounces@lists.xenproject.org Sun Jul 12 22:35:35 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Sun, 12 Jul 2020 22:35:35 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jukZI-0002XQ-Bf; Sun, 12 Jul 2020 22:35:32 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=f8dU=AX=gmail.com=felix.bernasch@srs-us1.protection.inumbo.net>)
 id 1jukZH-0002XL-7p
 for minios-devel@lists.xenproject.org; Sun, 12 Jul 2020 22:35:31 +0000
X-Inumbo-ID: fd0f911c-c48f-11ea-bca7-bc764e2007e4
Received: from mail-lj1-x241.google.com (unknown [2a00:1450:4864:20::241])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id fd0f911c-c48f-11ea-bca7-bc764e2007e4;
 Sun, 12 Jul 2020 22:35:30 +0000 (UTC)
Received: by mail-lj1-x241.google.com with SMTP id z24so13539214ljn.8
 for <minios-devel@lists.xenproject.org>; Sun, 12 Jul 2020 15:35:29 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:references:in-reply-to:from:date:message-id:subject:to
 :cc; bh=zotyAjYmiP0DJra/J8RKyXTq9zi509VdJFnQ1bgYmGw=;
 b=Xr9/SPiyUAsaLGdc/78OK7xbSTMvwnAGQgVnL5Ec7ZRbfhwyp8M457tEOEPspyzZ0Z
 XEOXQVQf6eS6PT8u66/HKyPZ39EVcUsdAVALFQQsJrIWAdL/OGbrlzw+pEazRt/HQQE8
 1TKkqvHLd8KPXihPPihE11ksDS6STtTdXo3TZ7WpLXbah4tw7I79ejZNM0r4/nZgJ8M8
 gcmhL10iTxMtCUNeMPEUwFr1HJbqbRXyzFkL8GdmPCpV/q5aoXPkRYJ55fjO3+YkntV8
 yDAmI7+hn2TpiZMsInnKQ2ejj8T1YHbDlNqDIlQ6lWLFkGXsyj97qa6VY4lbIDc0q+9r
 20iw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:references:in-reply-to:from:date
 :message-id:subject:to:cc;
 bh=zotyAjYmiP0DJra/J8RKyXTq9zi509VdJFnQ1bgYmGw=;
 b=aPzFj/Yi89tGGJ1XSssN0g2t54vWtqLf66gEDrElraZuDzmKXHqdV3HFHzw/rJ2lSm
 dct24A7Lnp4YSSGWRiRPnw1QazEfBDuqYYWQ9gdloyOxJCcU24KlRcO/8CJKvhY71Wbt
 nXbp3QVmgPF17e0eVmOQRh7GuCvEbDxG5kS9Qx+x7HNDY6DkzUqflSdFnG+/qRkO6+9a
 MDiDm3JZMpbgyyYbMvzP5ojVuRsjC8Fbd2Fhanv2XTepU8YevTbPBKBfJiYuHuc/TwJO
 NICAaDmeZMu+4LEESiOcmdANIVP8Oq1dniO2EVVpKZFZCw7djFgG9tSOducd+5mxPhJd
 myuQ==
X-Gm-Message-State: AOAM532/HxoUAUj4jQC4W6e7LVYhAoBw/o4lLWje1oTGre+VOE3cRE7j
 BPOi9lwoxoIFqniIYRAaWgw4f+yzoX/T/eukY5s=
X-Google-Smtp-Source: ABdhPJwxM+4BBof55rnsm+dDRzNYi5jscuI+NmWDTLgv3xdFoc+ToW4Hqtt6dyPv7Zh9mmacJJox6M1hfLALLo12TAM=
X-Received: by 2002:a2e:7804:: with SMTP id t4mr47230617ljc.8.1594593328876;
 Sun, 12 Jul 2020 15:35:28 -0700 (PDT)
MIME-Version: 1.0
References: <CAMEmTtXANxmphAj8tOmcqjdHzEqwEzJuY=Se0FbFdMwDvRQFFg@mail.gmail.com>
 <714bbaaf-be90-b61d-89a7-731f0de18f26@neclab.eu>
 <54BD2FAF-6238-4152-8D1C-18941726572F@neclab.eu>
In-Reply-To: <54BD2FAF-6238-4152-8D1C-18941726572F@neclab.eu>
From: Felix Bernasch <felix.bernasch@gmail.com>
Date: Mon, 13 Jul 2020 00:35:17 +0200
Message-ID: <CA+AX9HRL=7in-Zmp_CV+TFp+HE9vMkEx-3b-6N09dCAGtprJow@mail.gmail.com>
Subject: Re: Unikraft makefile - how to copy files in Makefile.uk
To: Simon Kuenzer <simon.kuenzer@neclab.eu>
Content-Type: multipart/alternative; boundary="000000000000edd3f105aa463069"
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: "minios-devel@lists.xenproject.org" <minios-devel@lists.xenproject.org>,
 Sharan Santhanam <Sharan.Santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

--000000000000edd3f105aa463069
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hi,

Thanks guys, that's what i was looking for. :)
Seems with build_cmd i can execute cp/mv/ln/.. whatever I desire. Very nice=
.

Another question: my library likes to do #include <..>, which can conflict
with headerfiles of another version of the library installed on the system
i build on.
Have you encountered this before? I could change it to #include "..", but
that would be a rather clumsy patch, is there a clever way to specify order
of include paths?

Thanks for your help so far!

-Felix

On Thu, Jul 9, 2020 at 5:23 PM Simon Kuenzer <simon.kuenzer@neclab.eu>
wrote:

> Hi Felix,
>
> =EF=BB=BFOn 07.07.20, 14:00, "Minios-devel on behalf of Sharan Santhanam"=
 <
> minios-devel-bounces@lists.xenproject.org on behalf of
> Sharan.Santhanam@neclab.eu> wrote:
>
>     Hello,
>
>     Please find the comment inline:
>
>     On 7/7/20 1:20 PM, felix nasch wrote:
>     > Hi,
>     >
>     > I was hanging out in the IRC channel, but it seems inactive, so I a=
m
>     > asking here, hope that's ok. :)
>     > I am trying to port a library to Unikraft, and as part of the build
> process I
>     > want to copy around a few files after extracting the source files.
>     > This is to solve these two problems:
>     >
>     > 1. Some source files have the same name (in different dirs), but th=
e
>     >      unikraft build system places all .obj files into the root
> directory, thus
>     >      colliding object files overwrite each other.  I want to rename
> conflicting
>     >      files prior to compilation.
>
>     Our approach to solve the problem, has been to resolve name collision
>     with a '|' directive. The '|' would prepend the object file with the
>     name following the pipe.
>
>     For eg, if you look at the Makefile.uk in plat/kvm/
>
>     LIBKVMPLAT_SRCS-$(CONFIG_ARCH_X86_64) +=3D
>     $(UK_PLAT_COMMON_BASE)/x86/trace.c|common
>
>     LIBKVMPLAT_SRCS-$(CONFIG_ARCH_X86_64) +=3D $(LIBKVMPLAT_BASE)/x86/tra=
ce.c
>
>
>     >
>     > 2. Include paths - when extracting the source package, the include
> path is not
>     >      how consumers of the library expect it. I would want to create
> an
>     > appropriately
>     >      named subdir and move the header files into it.
>     >
>     > However, I can't figure out how to execute a simple "cp <src> <dest=
>"
>     > in Makefile.uk, since new targets cannot be defined.:
>
>     This is a feature we do not support yet. If you believe the problem i=
s
>     very specific to a single library, you can do something like [1].
>
>     [1] https://github.com/unikraft/lib-lua/blob/master/Makefile.uk
>     <https://github.com/unikraft/lib-lua/blob/master/Makefile.uk>
>
> This is right, in liblua we created symbolic links of the public library
> header files as part of the prepare step (ln -s <src> <dest>). You can ta=
ke
> Sharan's link as an example. In general, you should make sure that every
> file generated, copied, or linked should go to the build sub directory of
> the library (LIBNAME_BUILD). In there you are free to organize your
> substructure.
>
>     >
>     > How can I do that?
>     >
>     > Thanks,
>     > f.
>     >
>
> Thanks,
>
> Simon
>
>
>

--000000000000edd3f105aa463069
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hi,</div><div><br></div><div>Thanks guys, that&#39;s =
what i was looking for. :) <br></div><div>Seems with build_cmd i can execut=
e cp/mv/ln/.. whatever I desire. Very nice.</div><div><br></div><div>Anothe=
r question: my library likes to do #include &lt;..&gt;, which can conflict =
with headerfiles of another version of the library installed on the system =
i build on.</div><div>Have you encountered this before? I could change it t=
o #include &quot;..&quot;, but that would be a rather clumsy patch, is ther=
e a clever way to specify order of include paths?</div><div><br></div><div>=
Thanks for your help so far! <br></div><div><br></div><div>-Felix<br></div>=
</div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">=
On Thu, Jul 9, 2020 at 5:23 PM Simon Kuenzer &lt;<a href=3D"mailto:simon.ku=
enzer@neclab.eu">simon.kuenzer@neclab.eu</a>&gt; wrote:<br></div><blockquot=
e class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px s=
olid rgb(204,204,204);padding-left:1ex">Hi Felix,<br>
<br>
=EF=BB=BFOn 07.07.20, 14:00, &quot;Minios-devel on behalf of Sharan Santhan=
am&quot; &lt;<a href=3D"mailto:minios-devel-bounces@lists.xenproject.org" t=
arget=3D"_blank">minios-devel-bounces@lists.xenproject.org</a> on behalf of=
 <a href=3D"mailto:Sharan.Santhanam@neclab.eu" target=3D"_blank">Sharan.San=
thanam@neclab.eu</a>&gt; wrote:<br>
<br>
=C2=A0 =C2=A0 Hello,<br>
<br>
=C2=A0 =C2=A0 Please find the comment inline:<br>
<br>
=C2=A0 =C2=A0 On 7/7/20 1:20 PM, felix nasch wrote:<br>
=C2=A0 =C2=A0 &gt; Hi,<br>
=C2=A0 =C2=A0 &gt;<br>
=C2=A0 =C2=A0 &gt; I was hanging out in the IRC channel, but it seems inact=
ive, so I am<br>
=C2=A0 =C2=A0 &gt; asking here, hope that&#39;s ok. :)<br>
=C2=A0 =C2=A0 &gt; I am trying to port a library to Unikraft, and as part o=
f the build process I<br>
=C2=A0 =C2=A0 &gt; want to copy around a few files after extracting the sou=
rce files.<br>
=C2=A0 =C2=A0 &gt; This is to solve these two problems:<br>
=C2=A0 =C2=A0 &gt;<br>
=C2=A0 =C2=A0 &gt; 1. Some source files have the same name (in different di=
rs), but the<br>
=C2=A0 =C2=A0 &gt;=C2=A0 =C2=A0 =C2=A0 unikraft build system places all .ob=
j files into the root directory, thus<br>
=C2=A0 =C2=A0 &gt;=C2=A0 =C2=A0 =C2=A0 colliding object files overwrite eac=
h other.=C2=A0 I want to rename conflicting<br>
=C2=A0 =C2=A0 &gt;=C2=A0 =C2=A0 =C2=A0 files prior to compilation.<br>
<br>
=C2=A0 =C2=A0 Our approach to solve the problem, has been to resolve name c=
ollision <br>
=C2=A0 =C2=A0 with a &#39;|&#39; directive. The &#39;|&#39; would prepend t=
he object file with the <br>
=C2=A0 =C2=A0 name following the pipe.<br>
<br>
=C2=A0 =C2=A0 For eg, if you look at the Makefile.uk in plat/kvm/<br>
<br>
=C2=A0 =C2=A0 LIBKVMPLAT_SRCS-$(CONFIG_ARCH_X86_64) +=3D <br>
=C2=A0 =C2=A0 $(UK_PLAT_COMMON_BASE)/x86/trace.c|common<br>
<br>
=C2=A0 =C2=A0 LIBKVMPLAT_SRCS-$(CONFIG_ARCH_X86_64) +=3D $(LIBKVMPLAT_BASE)=
/x86/trace.c<br>
<br>
<br>
=C2=A0 =C2=A0 &gt;<br>
=C2=A0 =C2=A0 &gt; 2. Include paths - when extracting the source package, t=
he include path is not<br>
=C2=A0 =C2=A0 &gt;=C2=A0 =C2=A0 =C2=A0 how consumers of the library expect =
it. I would want to create an<br>
=C2=A0 =C2=A0 &gt; appropriately<br>
=C2=A0 =C2=A0 &gt;=C2=A0 =C2=A0 =C2=A0 named subdir and move the header fil=
es into it.<br>
=C2=A0 =C2=A0 &gt;<br>
=C2=A0 =C2=A0 &gt; However, I can&#39;t figure out how to execute a simple =
&quot;cp &lt;src&gt; &lt;dest&gt;&quot;<br>
=C2=A0 =C2=A0 &gt; in Makefile.uk, since new targets cannot be defined.:<br=
>
<br>
=C2=A0 =C2=A0 This is a feature we do not support yet. If you believe the p=
roblem is <br>
=C2=A0 =C2=A0 very specific to a single library, you can do something like =
[1].<br>
<br>
=C2=A0 =C2=A0 [1] <a href=3D"https://github.com/unikraft/lib-lua/blob/maste=
r/Makefile.uk" rel=3D"noreferrer" target=3D"_blank">https://github.com/unik=
raft/lib-lua/blob/master/Makefile.uk</a> <br>
=C2=A0 =C2=A0 &lt;<a href=3D"https://github.com/unikraft/lib-lua/blob/maste=
r/Makefile.uk" rel=3D"noreferrer" target=3D"_blank">https://github.com/unik=
raft/lib-lua/blob/master/Makefile.uk</a>&gt;<br>
<br>
This is right, in liblua we created symbolic links of the public library he=
ader files as part of the prepare step (ln -s &lt;src&gt; &lt;dest&gt;). Yo=
u can take Sharan&#39;s link as an example. In general, you should make sur=
e that every file generated, copied, or linked should go to the build sub d=
irectory of the library (LIBNAME_BUILD). In there you are free to organize =
your substructure.<br>
<br>
=C2=A0 =C2=A0 &gt;<br>
=C2=A0 =C2=A0 &gt; How can I do that?<br>
=C2=A0 =C2=A0 &gt;<br>
=C2=A0 =C2=A0 &gt; Thanks,<br>
=C2=A0 =C2=A0 &gt; f.<br>
=C2=A0 =C2=A0 &gt;<br>
<br>
Thanks,<br>
<br>
Simon<br>
<br>
<br>
</blockquote></div>

--000000000000edd3f105aa463069--


From minios-devel-bounces@lists.xenproject.org Mon Jul 13 07:45:43 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Mon, 13 Jul 2020 07:45:43 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jut9f-00087C-Ea; Mon, 13 Jul 2020 07:45:39 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <SRS0=C18W=AY=suse.com=jgross@srs-us1.protection.inumbo.net>)
 id 1jut9d-000877-Dx
 for minios-devel@lists.xenproject.org; Mon, 13 Jul 2020 07:45:37 +0000
X-Inumbo-ID: d6233408-c4dc-11ea-8496-bc764e2007e4
Received: from mx2.suse.de (unknown [195.135.220.15])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id d6233408-c4dc-11ea-8496-bc764e2007e4;
 Mon, 13 Jul 2020 07:45:35 +0000 (UTC)
X-Virus-Scanned: by amavisd-new at test-mx.suse.de
Received: from relay2.suse.de (unknown [195.135.221.27])
 by mx2.suse.de (Postfix) with ESMTP id C9652AC82;
 Mon, 13 Jul 2020 07:45:36 +0000 (UTC)
From: Juergen Gross <jgross@suse.com>
To: minios-devel@lists.xenproject.org,
	xen-devel@lists.xenproject.org
Subject: [PATCH] mini-os: don't hard-wire xen internal paths
Date: Mon, 13 Jul 2020 09:45:31 +0200
Message-Id: <20200713074531.27547-1-jgross@suse.com>
X-Mailer: git-send-email 2.26.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Juergen Gross <jgross@suse.com>, samuel.thibault@ens-lyon.org, wl@xen.org
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Mini-OS shouldn't use Xen internal paths for building. Import the
needed paths from Xen and fall back to the current values only if
the import was not possible.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 Config.mk | 15 ++++++++++++++-
 Makefile  | 35 ++++++++++++++++++-----------------
 2 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/Config.mk b/Config.mk
index f6a2afa..cb823c2 100644
--- a/Config.mk
+++ b/Config.mk
@@ -33,6 +33,19 @@ endif
 #
 ifneq ($(XEN_ROOT),)
 MINIOS_ROOT=$(XEN_ROOT)/extras/mini-os
+
+-include $(XEN_ROOT)/stubdom/mini-os.mk
+
+XENSTORE_CPPFLAGS ?= -isystem $(XEN_ROOT)/tools/xenstore/include
+TOOLCORE_PATH ?= $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toolcore
+TOOLLOG_PATH ?= $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toollog
+EVTCHN_PATH ?= $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/evtchn
+GNTTAB_PATH ?= $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/gnttab
+CALL_PATH ?= $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/call
+FOREIGNMEMORY_PATH ?= $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/foreignmemory
+DEVICEMODEL_PATH ?= $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/devicemodel
+CTRL_PATH ?= $(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH)
+GUEST_PATH ?= $(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH)
 else
 MINIOS_ROOT=$(TOPLEVEL_DIR)
 endif
@@ -93,7 +106,7 @@ DEF_CPPFLAGS += -D__MINIOS__
 ifeq ($(libc),y)
 DEF_CPPFLAGS += -DHAVE_LIBC
 DEF_CPPFLAGS += -isystem $(MINIOS_ROOT)/include/posix
-DEF_CPPFLAGS += -isystem $(XEN_ROOT)/tools/xenstore/include
+DEF_CPPFLAGS += $(XENSTORE_CPPFLAGS)
 endif
 
 ifneq ($(LWIPDIR),)
diff --git a/Makefile b/Makefile
index be640cd..82422a5 100644
--- a/Makefile
+++ b/Makefile
@@ -125,23 +125,24 @@ OBJS := $(filter-out $(OBJ_DIR)/lwip%.o $(LWO), $(OBJS))
 
 ifeq ($(libc),y)
 ifeq ($(CONFIG_XC),y)
-APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toolcore -whole-archive -lxentoolcore -no-whole-archive
-LIBS += $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toolcore/libxentoolcore.a
-APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toollog -whole-archive -lxentoollog -no-whole-archive
-LIBS += $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toollog/libxentoollog.a
-APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/evtchn -whole-archive -lxenevtchn -no-whole-archive
-LIBS += $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/evtchn/libxenevtchn.a
-APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/gnttab -whole-archive -lxengnttab -no-whole-archive
-LIBS += $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/gnttab/libxengnttab.a
-APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/call -whole-archive -lxencall -no-whole-archive
-LIBS += $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/call/libxencall.a
-APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/foreignmemory -whole-archive -lxenforeignmemory -no-whole-archive
-LIBS += $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/foreignmemory/libxenforeignmemory.a
-APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/devicemodel -whole-archive -lxendevicemodel -no-whole-archive
-LIBS += $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/devicemodel/libxendevicemodel.a
-APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH) -whole-archive -lxenguest -lxenctrl -no-whole-archive
-LIBS += $(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH)/libxenctrl.a
-LIBS += $(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH)/libxenguest.a
+APP_LDLIBS += -L$(TOOLCORE_PATH) -whole-archive -lxentoolcore -no-whole-archive
+LIBS += $(TOOLCORE_PATH)/libxentoolcore.a
+APP_LDLIBS += -L$(TOOLLOG_PATH) -whole-archive -lxentoollog -no-whole-archive
+LIBS += $(TOOLLOG_PATH)/libxentoollog.a
+APP_LDLIBS += -L$(EVTCHN_PATH) -whole-archive -lxenevtchn -no-whole-archive
+LIBS += $(EVTCHN_PATH)/libxenevtchn.a
+APP_LDLIBS += -L$(GNTTAB_PATH) -whole-archive -lxengnttab -no-whole-archive
+LIBS += $(GNTTAB_PATH)/libxengnttab.a
+APP_LDLIBS += -L$(CALL_PATH) -whole-archive -lxencall -no-whole-archive
+LIBS += $(XCALL_PATH)/libxencall.a
+APP_LDLIBS += -L$(FOREIGNMEMORY_PATH) -whole-archive -lxenforeignmemory -no-whole-archive
+LIBS += $(FOREIGNMEMORY_PATH)/libxenforeignmemory.a
+APP_LDLIBS += -L$(DEVICEMODEL_PATH) -whole-archive -lxendevicemodel -no-whole-archive
+LIBS += $(DEVICEMODEL_PATH)/libxendevicemodel.a
+APP_LDLIBS += -L$(GUEST_PATH) -whole-archive -lxenguest -no-whole-archive
+LIBS += $(GUEST_PATH)/libxenguest.a
+APP_LDLIBS += -L$(CTRL_PATH) -whole-archive -lxenctrl -no-whole-archive
+LIBS += $(CTRL_PATH)/libxenctrl.a
 endif
 APP_LDLIBS += -lpci
 APP_LDLIBS += -lz
-- 
2.26.2



From minios-devel-bounces@lists.xenproject.org Mon Jul 13 08:42:39 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Mon, 13 Jul 2020 08:42:39 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1juu2l-00018Q-43; Mon, 13 Jul 2020 08:42:35 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <SRS0=C18W=AY=suse.com=jgross@srs-us1.protection.inumbo.net>)
 id 1juu2j-00018L-P6
 for minios-devel@lists.xenproject.org; Mon, 13 Jul 2020 08:42:33 +0000
X-Inumbo-ID: caa2a39a-c4e4-11ea-8496-bc764e2007e4
Received: from mx2.suse.de (unknown [195.135.220.15])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id caa2a39a-c4e4-11ea-8496-bc764e2007e4;
 Mon, 13 Jul 2020 08:42:32 +0000 (UTC)
X-Virus-Scanned: by amavisd-new at test-mx.suse.de
Received: from relay2.suse.de (unknown [195.135.221.27])
 by mx2.suse.de (Postfix) with ESMTP id 8077CB013;
 Mon, 13 Jul 2020 08:42:33 +0000 (UTC)
From: Juergen Gross <jgross@suse.com>
To: minios-devel@lists.xenproject.org,
	xen-devel@lists.xenproject.org
Subject: [PATCH v2] mini-os: don't hard-wire xen internal paths
Date: Mon, 13 Jul 2020 10:42:30 +0200
Message-Id: <20200713084230.18177-1-jgross@suse.com>
X-Mailer: git-send-email 2.26.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Juergen Gross <jgross@suse.com>, samuel.thibault@ens-lyon.org, wl@xen.org
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Mini-OS shouldn't use Xen internal paths for building. Import the
needed paths from Xen and fall back to the current values only if
the import was not possible.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
V2: correct typo (XCALL_APTH -> CALL_PATH)
---
 Config.mk | 15 ++++++++++++++-
 Makefile  | 35 ++++++++++++++++++-----------------
 2 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/Config.mk b/Config.mk
index f6a2afa..cb823c2 100644
--- a/Config.mk
+++ b/Config.mk
@@ -33,6 +33,19 @@ endif
 #
 ifneq ($(XEN_ROOT),)
 MINIOS_ROOT=$(XEN_ROOT)/extras/mini-os
+
+-include $(XEN_ROOT)/stubdom/mini-os.mk
+
+XENSTORE_CPPFLAGS ?= -isystem $(XEN_ROOT)/tools/xenstore/include
+TOOLCORE_PATH ?= $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toolcore
+TOOLLOG_PATH ?= $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toollog
+EVTCHN_PATH ?= $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/evtchn
+GNTTAB_PATH ?= $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/gnttab
+CALL_PATH ?= $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/call
+FOREIGNMEMORY_PATH ?= $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/foreignmemory
+DEVICEMODEL_PATH ?= $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/devicemodel
+CTRL_PATH ?= $(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH)
+GUEST_PATH ?= $(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH)
 else
 MINIOS_ROOT=$(TOPLEVEL_DIR)
 endif
@@ -93,7 +106,7 @@ DEF_CPPFLAGS += -D__MINIOS__
 ifeq ($(libc),y)
 DEF_CPPFLAGS += -DHAVE_LIBC
 DEF_CPPFLAGS += -isystem $(MINIOS_ROOT)/include/posix
-DEF_CPPFLAGS += -isystem $(XEN_ROOT)/tools/xenstore/include
+DEF_CPPFLAGS += $(XENSTORE_CPPFLAGS)
 endif
 
 ifneq ($(LWIPDIR),)
diff --git a/Makefile b/Makefile
index be640cd..4b76b55 100644
--- a/Makefile
+++ b/Makefile
@@ -125,23 +125,24 @@ OBJS := $(filter-out $(OBJ_DIR)/lwip%.o $(LWO), $(OBJS))
 
 ifeq ($(libc),y)
 ifeq ($(CONFIG_XC),y)
-APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toolcore -whole-archive -lxentoolcore -no-whole-archive
-LIBS += $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toolcore/libxentoolcore.a
-APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toollog -whole-archive -lxentoollog -no-whole-archive
-LIBS += $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toollog/libxentoollog.a
-APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/evtchn -whole-archive -lxenevtchn -no-whole-archive
-LIBS += $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/evtchn/libxenevtchn.a
-APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/gnttab -whole-archive -lxengnttab -no-whole-archive
-LIBS += $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/gnttab/libxengnttab.a
-APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/call -whole-archive -lxencall -no-whole-archive
-LIBS += $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/call/libxencall.a
-APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/foreignmemory -whole-archive -lxenforeignmemory -no-whole-archive
-LIBS += $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/foreignmemory/libxenforeignmemory.a
-APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/devicemodel -whole-archive -lxendevicemodel -no-whole-archive
-LIBS += $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/devicemodel/libxendevicemodel.a
-APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH) -whole-archive -lxenguest -lxenctrl -no-whole-archive
-LIBS += $(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH)/libxenctrl.a
-LIBS += $(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH)/libxenguest.a
+APP_LDLIBS += -L$(TOOLCORE_PATH) -whole-archive -lxentoolcore -no-whole-archive
+LIBS += $(TOOLCORE_PATH)/libxentoolcore.a
+APP_LDLIBS += -L$(TOOLLOG_PATH) -whole-archive -lxentoollog -no-whole-archive
+LIBS += $(TOOLLOG_PATH)/libxentoollog.a
+APP_LDLIBS += -L$(EVTCHN_PATH) -whole-archive -lxenevtchn -no-whole-archive
+LIBS += $(EVTCHN_PATH)/libxenevtchn.a
+APP_LDLIBS += -L$(GNTTAB_PATH) -whole-archive -lxengnttab -no-whole-archive
+LIBS += $(GNTTAB_PATH)/libxengnttab.a
+APP_LDLIBS += -L$(CALL_PATH) -whole-archive -lxencall -no-whole-archive
+LIBS += $(CALL_PATH)/libxencall.a
+APP_LDLIBS += -L$(FOREIGNMEMORY_PATH) -whole-archive -lxenforeignmemory -no-whole-archive
+LIBS += $(FOREIGNMEMORY_PATH)/libxenforeignmemory.a
+APP_LDLIBS += -L$(DEVICEMODEL_PATH) -whole-archive -lxendevicemodel -no-whole-archive
+LIBS += $(DEVICEMODEL_PATH)/libxendevicemodel.a
+APP_LDLIBS += -L$(GUEST_PATH) -whole-archive -lxenguest -no-whole-archive
+LIBS += $(GUEST_PATH)/libxenguest.a
+APP_LDLIBS += -L$(CTRL_PATH) -whole-archive -lxenctrl -no-whole-archive
+LIBS += $(CTRL_PATH)/libxenctrl.a
 endif
 APP_LDLIBS += -lpci
 APP_LDLIBS += -lz
-- 
2.26.2



From minios-devel-bounces@lists.xenproject.org Tue Jul 14 12:04:46 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 14 Jul 2020 12:04:46 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jvJfx-0007TK-0h; Tue, 14 Jul 2020 12:04:45 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Jy/Q=AZ=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jvJfv-0007TA-T0
 for minios-devel@lists.xenproject.org; Tue, 14 Jul 2020 12:04:43 +0000
X-Inumbo-ID: 32ea2b4a-c5ca-11ea-bca7-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 32ea2b4a-c5ca-11ea-bca7-bc764e2007e4;
 Tue, 14 Jul 2020 12:04:42 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 49E33F2003;
 Tue, 14 Jul 2020 14:04:41 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 0eTk7x1CiiTF; Tue, 14 Jul 2020 14:04:41 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from Oberon.office.hd (Oberon.office.hd [192.168.24.90])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 15715F2001
 for <minios-devel@lists.xenproject.org>; Tue, 14 Jul 2020 14:04:39 +0200 (CEST)
Received: from N-1237.office.hd (192.168.24.96) by Oberon.office.hd
 (192.168.24.90) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 14 Jul
 2020 14:04:38 +0200
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: <minios-devel@lists.xenproject.org>
Subject: [UNIKRAFT PATCH] driver/virtio: fix virtqueue_vring allocation
Date: Tue, 14 Jul 2020 14:04:32 +0200
Message-ID: <d2cfd8d7b11ba0856efc8cd9c6bcd5ddc610b4d5.1594728208.git.hugo.lefeuvre@neclab.eu>
X-Mailer: git-send-email 2.7.4
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To Oberon.office.hd
 (192.168.24.90)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

virtqueue_create() allocates virtqueue_vring structures dynamically, but
the amount of memory requested to the memory allocator is incorrect:
sizeof(struct virtqueue) instead of sizeof(struct virtqueue_vring).

This bug is probably due to a simple oversight and has gone unnoticed
because of allocator-specific paddings.

This results in out-of-bounds write in virtqueue_buffer_enqueue.

Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
---
 plat/drivers/virtio/virtio_ring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/plat/drivers/virtio/virtio_ring.c b/plat/drivers/virtio/virtio_ring.c
index ab9287a..0a5c3f3 100644
--- a/plat/drivers/virtio/virtio_ring.c
+++ b/plat/drivers/virtio/virtio_ring.c
@@ -366,7 +366,7 @@ struct virtqueue *virtqueue_create(__u16 queue_id, __u16 nr_descs, __u16 align,
 
 	UK_ASSERT(a);
 
-	vrq = uk_malloc(a, sizeof(struct virtqueue) +
+	vrq = uk_malloc(a, sizeof(*vrq) +
 			nr_descs * sizeof(struct virtqueue_desc_info));
 	if (!vrq) {
 		uk_pr_err("Allocation of virtqueue failed\n");
-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Tue Jul 14 13:00:00 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 14 Jul 2020 13:00:00 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jvKXN-0003bw-Sr; Tue, 14 Jul 2020 12:59:57 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=8/kp=AZ=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jvKXN-0003br-Dw
 for minios-devel@lists.xen.org; Tue, 14 Jul 2020 12:59:57 +0000
X-Inumbo-ID: e9d80e4d-c5d1-11ea-9309-12813bfff9fa
Received: from mh-fa-0.lancs.ac.uk (unknown [148.88.65.130])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id e9d80e4d-c5d1-11ea-9309-12813bfff9fa;
 Tue, 14 Jul 2020 12:59:56 +0000 (UTC)
Received: from p5087e57f.dip0.t-ipconnect.de ([80.135.229.127]
 helo=unknown.fritz.box)
 by mh-fa-0.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jvKXK-000TBP-7K; Tue, 14 Jul 2020 13:59:55 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH] lib/uksched: Add to error message for stack alloc
 failure.
Date: Tue, 14 Jul 2020 14:59:18 +0200
Message-Id: <20200714125930.91234-1-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-fa-0.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Alexander Jung <alexander.jung@neclab.eu>

The reason for failing to allocate the stack is caused by lack of
memory.  This patch adds this information to this error message in
order to ease usage of Unikraft as it is a common question which
requires troubleshooting.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/uksched/sched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/uksched/sched.c b/lib/uksched/sched.c
index ef195c3..4b8e149 100644
--- a/lib/uksched/sched.c
+++ b/lib/uksched/sched.c
@@ -143,7 +143,7 @@ static void *create_stack(struct uk_alloc *allocator)
 
 	if (uk_posix_memalign(allocator, &stack,
 			      STACK_SIZE, STACK_SIZE) != 0) {
-		uk_pr_err("Failed to allocate thread stack\n");
+		uk_pr_err("Failed to allocate thread stack: Not enough memory\n");
 		return NULL;
 	}
 
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 14 13:00:02 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 14 Jul 2020 13:00:02 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jvKXS-0003o0-UQ; Tue, 14 Jul 2020 13:00:02 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=8/kp=AZ=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jvKXS-0003br-AX
 for minios-devel@lists.xen.org; Tue, 14 Jul 2020 13:00:02 +0000
X-Inumbo-ID: ed52073a-c5d1-11ea-9309-12813bfff9fa
Received: from mh-fa-0.lancs.ac.uk (unknown [148.88.65.130])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id ed52073a-c5d1-11ea-9309-12813bfff9fa;
 Tue, 14 Jul 2020 13:00:01 +0000 (UTC)
Received: from p5087e57f.dip0.t-ipconnect.de ([80.135.229.127]
 helo=unknown.fritz.box)
 by mh-fa-0.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jvKXP-000TBP-7p; Tue, 14 Jul 2020 14:00:00 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 0/3] Introduce posix-socket
Date: Tue, 14 Jul 2020 14:59:19 +0200
Message-Id: <20200714125930.91234-2-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200714125930.91234-1-a.jung@lancs.ac.uk>
References: <20200714125930.91234-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-fa-0.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Alexander Jung <alexander.jung@neclab.eu>

This patch series introduces the posix-socket microlibrary within the
Unikraft core in order to facilitate the use of multiple POSIX-
compliant socket implementations which target specific AF family
numbers.

This library allows for the registration of socket interfaces, listed
within `struct posix_socket_ops`, and exposes unikernel-wide 
prototypes for socket(), accept(), bind(), listen(), connect(),
send(), recv() and friends in order to access them via a 
corresponding AF family number.  The implementing library simply needs
to register against the desired interfaces with a glue function:

  #include <uk/socket.h>
  #include "my_socket.h"

  static struct posix_socket_ops mysock_socket_ops = {
    /* The initialization function on socket registration. */
    .init        = mysock_lib_init,
    /* POSIX interfaces */
    .create      = mysock_glue_create,
    .accept      = mysock_glue_accept,
    .bind        = mysock_glue_bind,
    .shutdown    = mysock_glue_shutdown,
    .getpeername = mysock_glue_getpeername,
    .getsockname = mysock_glue_getsockname,
    .getsockopt  = mysock_glue_getsockopt,
    .setsockopt  = mysock_glue_setsockopt,
    .connect     = mysock_glue_connect,
    .listen      = mysock_glue_listen,
    .recv        = mysock_glue_recv,
    .recvfrom    = mysock_glue_recvfrom,
    .recvmsg     = mysock_glue_recvmsg,
    .send        = mysock_glue_send,
    .sendmsg     = mysock_glue_sendmsg,
    .sendto      = mysock_glue_sendto,
    /* vfscore ops */
    .read        = mysock_glue_read,
    .write       = mysock_glue_write,
    .close       = mysock_glue_close,
    .ioctl       = mysock_glue_ioctl,
  };

Each glue function accepts traditional parameters for the POSIX 
interface as side from the file descriptor, traditionally `int fd` or 
`int sock`, which has instead been cast as `void *`.  This allows the
implementing library to use internal socket file descriptor or
reference.  The creation of a socket via socket() and accept() have 
also been cast to return `void *` in line with internal needs of the 
implementing library.  This makes sense for implementing libraries
which use a structure instead of a file descriptor identification 
integer.  An additional parameter, `struct posix_socket_driver`, is 
passed to each interface which can store private data as well as a
preferred memory allocator.  The glue for each interface simply needs
to call the appropriate method internally, for example:

  static int
  mysock_glue_bind(struct posix_socket_driver *d,
          void *sock, const struct sockaddr *addr, socklen_t addr_len)
  {
    int ret = 0;
    struct my_socket *mysock;

    /* Transform the socket descriptor to the my_socket pointer. */
    mysock = (struct my_socket *)sock;
    if (mysock->mysock_fd < 0) {
      ret = -1;
      SOCKET_LIB_ERR(d, ret, "failed to identify socket descriptor");
      goto EXIT;
    }
    
    /* Bind to my socket */
    ret = mysock_bind(mysock->mysock_fd, addr, addr_len);
    if (ret < 0)
      ret = -1;

  EXIT:
    return ret;
  }

The library selects the appropriate implementation based on the AF
family number and registers the required interfaces using a newly
exposed macro:

  POSIX_SOCKET_FAMILY_REGISTER(AF_INET,  &mysock_socket_ops, NULL);

Implementing libraries can register as many AF numbers as desired
or specify new families which are not listed in the <sys/socket.h>
header.  To access the relevant implementation, the application
simply needs to call the socket() method with the relevant AF family
number.

Alexander Jung (3):
  lib/posix-socket: Introduce abstraction for communication sockets
  lib/nolibc: Provide sys/socket.h
  lib/posix-socket: Register library within Unikraft.

 lib/Makefile.uk                             |    1 +
 lib/nolibc/include/sys/socket.h             |  258 +++++
 lib/posix-socket/Config.uk                  |   18 +
 lib/posix-socket/Makefile.uk                |   10 +
 lib/posix-socket/driver.c                   |  154 +++
 lib/posix-socket/exportsyms.uk              |   26 +
 lib/posix-socket/extra.ld                   |    9 +
 lib/posix-socket/include/uk/socket.h        |   45 +
 lib/posix-socket/include/uk/socket_driver.h | 1018 +++++++++++++++++++
 lib/posix-socket/include/uk/socket_vnops.h  |   97 ++
 lib/posix-socket/socket.c                   |  722 +++++++++++++
 lib/posix-socket/socket_vnops.c             |  323 ++++++
 12 files changed, 2681 insertions(+)
 create mode 100644 lib/nolibc/include/sys/socket.h
 create mode 100644 lib/posix-socket/Config.uk
 create mode 100644 lib/posix-socket/Makefile.uk
 create mode 100644 lib/posix-socket/driver.c
 create mode 100644 lib/posix-socket/exportsyms.uk
 create mode 100644 lib/posix-socket/extra.ld
 create mode 100644 lib/posix-socket/include/uk/socket.h
 create mode 100644 lib/posix-socket/include/uk/socket_driver.h
 create mode 100644 lib/posix-socket/include/uk/socket_vnops.h
 create mode 100644 lib/posix-socket/socket.c
 create mode 100644 lib/posix-socket/socket_vnops.c

-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 14 13:00:12 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 14 Jul 2020 13:00:12 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jvKXc-0004J6-02; Tue, 14 Jul 2020 13:00:12 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=8/kp=AZ=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jvKXa-0004Iz-Rt
 for minios-devel@lists.xen.org; Tue, 14 Jul 2020 13:00:10 +0000
X-Inumbo-ID: f1cd3190-c5d1-11ea-b7bb-bc764e2007e4
Received: from mh-fa-0.lancs.ac.uk (unknown [148.88.65.130])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id f1cd3190-c5d1-11ea-b7bb-bc764e2007e4;
 Tue, 14 Jul 2020 13:00:08 +0000 (UTC)
Received: from p5087e57f.dip0.t-ipconnect.de ([80.135.229.127]
 helo=unknown.fritz.box)
 by mh-fa-0.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jvKXW-000TBP-95; Tue, 14 Jul 2020 14:00:08 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 2/3] lib/nolibc: Provide sys/socket.h
Date: Tue, 14 Jul 2020 14:59:21 +0200
Message-Id: <20200714125930.91234-4-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200714125930.91234-1-a.jung@lancs.ac.uk>
References: <20200714125930.91234-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-fa-0.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Alexander Jung <alexander.jung@neclab.eu>

This commit provides the sys/socket.h header in order to list
the available AF family numbers, socket types, and external
structures used by socket implementations.

This header is required by the posix-socket module when there is
no libc implementation provided.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/nolibc/include/sys/socket.h | 258 ++++++++++++++++++++++++++++++++
 1 file changed, 258 insertions(+)
 create mode 100644 lib/nolibc/include/sys/socket.h

diff --git a/lib/nolibc/include/sys/socket.h b/lib/nolibc/include/sys/socket.h
new file mode 100644
index 0000000..14e9780
--- /dev/null
+++ b/lib/nolibc/include/sys/socket.h
@@ -0,0 +1,258 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Alexander Jung <alexander.jung@neclab.eu>
+ *
+ * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
+ *         The Regents of the University of California.  All rights reserved.
+ * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+/* Derived from OpenBSD commit 15b62b7 (22 Jul 2019) */
+
+#ifndef _SYS_SOCKET_H
+#define _SYS_SOCKET_H
+
+#include <uk/config.h>
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define __NEED_socklen_t
+#define __NEED_sa_family_t
+
+#include <nolibc-internal/shareddefs.h>
+
+#if CONFIG_LIBPOSIX_SOCKET
+
+/*
+ * Types
+ */
+#define SOCK_STREAM      1  /* stream socket */
+#define SOCK_DGRAM       2  /* datagram socket */
+#define SOCK_RAW         3  /* raw-protocol interface */
+#define SOCK_RDM         4  /* reliably-delivered message */
+#define SOCK_SEQPACKET	 5  /* sequenced packet stream */
+
+// Move to LWIP
+// /*
+//  * Option flags per-socket.
+//  */
+// #define SO_DEBUG         0x0001  /* turn on debugging info recording */
+// #define SO_ACCEPTCONN    0x0002  /* socket has had listen() */
+// #define SO_REUSEADDR     0x0004  /* allow local address reuse */
+// #define SO_KEEPALIVE     0x0008  /* keep connections alive */
+// #define SO_DONTROUTE     0x0010  /* just use interface addresses */
+// #define SO_BROADCAST     0x0020  /* permit sending of broadcast msgs */
+// #define SO_USELOOPBACK   0x0040  /* bypass hardware when possible */
+// #define SO_LINGER        0x0080  /* linger on close if data present */
+// #define SO_OOBINLINE     0x0100  /* leave received OOB data in line */
+// #define SO_REUSEPORT     0x0200  /* allow local address & port reuse */
+// #define SO_TIMESTAMP     0x0800  /* timestamp received dgram traffic */
+// #define SO_BINDANY       0x1000  /* allow bind to any address */
+// #define SO_ZEROIZE       0x2000  /* zero out all mbufs sent over socket */
+
+// /*
+//  * Additional options, not kept in so_options.
+//  */
+// #define SO_SNDBUF        0x1001  /* send buffer size */
+// #define SO_RCVBUF        0x1002  /* receive buffer size */
+// #define SO_SNDLOWAT      0x1003  /* send low-water mark */
+// #define SO_RCVLOWAT      0x1004  /* receive low-water mark */
+// #define SO_SNDTIMEO      0x1005  /* send timeout */
+// #define SO_RCVTIMEO      0x1006  /* receive timeout */
+// #define SO_ERROR         0x1007  /* get error status and clear */
+// #define SO_TYPE          0x1008  /* get socket type */
+// #define SO_NETPROC       0x1020  /* multiplex; network processing */
+// #define SO_RTABLE        0x1021  /* routing table to be used */
+// #define SO_PEERCRED      0x1022  /* get connect-time credentials */
+// #define SO_SPLICE        0x1023  /* splice data to other socket */
+// #define SO_DOMAIN        0x1024  /* get socket domain */
+// #define SO_PROTOCOL      0x1025  /* get socket protocol */
+
+/*
+ * Level number for (get/set)sockopt() to apply to socket itself.
+ */
+// #define SOL_SOCKET       0xffff		/* options for socket level */
+
+/*
+ * Unikraft defines a definitive list of protocol families which can be
+ * registered by uksocket.  Newer or non-standard protocols should have their
+ * respective AF_ number defined in the library and greater than what is 
+ * defined here.
+ */
+/*
+ * Address families.
+ */
+#define AF_UNSPEC        0        /* unspecified */
+#define AF_UNIX          1        /* local to host */
+#define AF_LOCAL         AF_UNIX  /* draft POSIX compatibility */
+#define AF_INET          2        /* internetwork: UDP, TCP, etc. */
+#define AF_IMPLINK       3        /* arpanet imp addresses */
+#define AF_PUP           4        /* pup protocols: e.g. BSP */
+#define AF_CHAOS         5        /* mit CHAOS protocols */
+#define AF_NS            6        /* XEROX NS protocols */
+#define AF_ISO           7        /* ISO protocols */
+#define AF_OSI           AF_ISO
+#define AF_ECMA          8        /* european computer manufacturers */
+#define AF_DATAKIT       9        /* datakit protocols */
+#define AF_CCITT         10       /* CCITT protocols, X.25 etc */
+#define AF_SNA           11       /* IBM SNA */
+#define AF_DECnet        12       /* DECnet */
+#define AF_DLI           13       /* DEC Direct data link interface */
+#define AF_LAT           14       /* LAT */
+#define AF_HYLINK        15       /* NSC Hyperchannel */
+#define AF_APPLETALK     16       /* Apple Talk */
+#define AF_ROUTE         17       /* Internal Routing Protocol */
+#define AF_LINK          18       /* Link layer interface */
+#define pseudo_AF_XTP    19       /* eXpress Transfer Protocol (no AF) */
+#define AF_COIP          20       /* connection-oriented IP, aka ST II */
+#define AF_CNT           21       /* Computer Network Technology */
+#define pseudo_AF_RTIP   22       /* Help Identify RTIP packets */
+#define AF_IPX           23       /* Novell Internet Protocol */
+#define AF_INET6         24       /* IPv6 */
+#define pseudo_AF_PIP    25       /* Help Identify PIP packets */
+#define AF_ISDN          26       /* Integrated Services Digital Network*/
+#define AF_E164          AF_ISDN  /* CCITT E.164 recommendation */
+#define AF_NATM          27       /* native ATM access */
+#define AF_ENCAP         28
+#define AF_SIP           29       /* Simple Internet Protocol */
+#define AF_KEY           30
+#define pseudo_AF_HDRCM  31       /* Used by BPF to not rewrite headers 
+                                   * in interface output routine */
+#define AF_BLUETOOTH     32       /* Bluetooth */
+#define AF_MPLS          33       /* MPLS */
+#define pseudo_AF_PFLOW  34       /* pflow */
+#define pseudo_AF_PIPEX  35       /* PIPEX */
+#define AF_MAX           36
+
+/*
+ * Protocol families, same as address families for now.
+ */
+#define PF_UNSPEC        AF_UNSPEC
+#define PF_LOCAL         AF_LOCAL
+#define PF_UNIX          AF_UNIX
+#define PF_INET          AF_INET
+#define PF_IMPLINK       AF_IMPLINK
+#define PF_PUP           AF_PUP
+#define PF_CHAOS         AF_CHAOS
+#define PF_NS            AF_NS
+#define PF_ISO           AF_ISO
+#define PF_OSI           AF_ISO
+#define PF_ECMA          AF_ECMA
+#define PF_DATAKIT       AF_DATAKIT
+#define PF_CCITT         AF_CCITT
+#define PF_SNA           AF_SNA
+#define PF_DECnet        AF_DECnet
+#define PF_DLI           AF_DLI
+#define PF_LAT           AF_LAT
+#define PF_HYLINK        AF_HYLINK
+#define PF_APPLETALK     AF_APPLETALK
+#define PF_ROUTE         AF_ROUTE
+#define PF_LINK          AF_LINK
+#define PF_XTP           pseudo_AF_XTP   /* really just proto family, no AF */
+#define PF_COIP          AF_COIP
+#define PF_CNT           AF_CNT
+#define PF_IPX           AF_IPX          /* same format as AF_NS */
+#define PF_INET6         AF_INET6
+#define PF_RTIP          pseudo_AF_RTIP  /* same format as AF_INET */
+#define PF_PIP           pseudo_AF_PIP
+#define PF_ISDN          AF_ISDN
+#define PF_NATM          AF_NATM
+#define PF_ENCAP         AF_ENCAP
+#define PF_SIP           AF_SIP
+#define PF_KEY           AF_KEY
+#define PF_BPF           pseudo_AF_HDRCMPLT
+#define PF_BLUETOOTH     AF_BLUETOOTH
+#define PF_MPLS          AF_MPLS
+#define PF_PFLOW         pseudo_AF_PFLOW
+#define PF_PIPEX         pseudo_AF_PIPEX
+#define PF_MAX           AF_MAX
+
+/*
+ * These are the valid values for the "how" field used by shutdown(2).
+ */
+#define SHUT_RD          0
+#define SHUT_WR          1
+#define SHUT_RDWR        2
+
+/*
+ * Maximum queue length specifiable by listen(2).
+ */
+#define SOMAXCONN        128
+
+struct msghdr;
+
+// /*
+//  * Message header for recvmsg and sendmsg calls.
+//  * Used value-result for recvmsg, value only for sendmsg.
+//  */
+// struct msghdr {
+// 	void                   *msg_name;       /* optional address */
+// 	socklen_t              msg_namelen;     /* size of address */
+// 	struct iovec           *msg_iov;        /* scatter/gather array */
+// 	unsigned int           msg_iovlen;      /* # elements in msg_iov */
+// 	void                   *msg_control;    /* ancillary data, see below */
+// 	socklen_t              msg_controllen;  /* ancillary data buffer len */
+// 	int                    msg_flags;       /* flags on received message */
+// };
+
+// #define MSG_OOB          0x1    /* process out-of-band data */
+// #define MSG_PEEK         0x2    /* peek at incoming message */
+// #define MSG_DONTROUTE    0x4    /* send without using routing tables */
+// #define MSG_EOR          0x8    /* data completes record */
+// #define MSG_TRUNC        0x10   /* data discarded before delivery */
+// #define MSG_CTRUNC       0x20   /* control data lost before delivery */
+// #define MSG_WAITALL      0x40   /* wait for full request or error */
+// #define MSG_DONTWAIT     0x80   /* this message should be nonblocking */
+// #define MSG_BCAST        0x100  /* this message rec'd as broadcast */
+// #define MSG_MCAST        0x200  /* this message rec'd as multicast */
+// #define MSG_NOSIGNAL     0x400  /* do not send SIGPIPE */
+// #define MSG_CMSG_CLOEXEC 0x800  /* set FD_CLOEXEC on received fds */
+
+struct cmsghdr;
+// /*
+//  * Header for ancillary data objects in msg_control buffer.
+//  * Used for additional information with/about a datagram
+//  * not expressible by flags.  The format is a sequence
+//  * of message elements headed by cmsghdr structures.
+//  */
+// struct cmsghdr {
+// 	socklen_t	cmsg_len;	/* data byte count, including hdr */
+// 	int		cmsg_level;	/* originating protocol */
+// 	int		cmsg_type;	/* protocol-specific type */
+// /* followed by	u_char  cmsg_data[]; */
+// };
+
+#endif /* CONFIG_LIBPOSIX_SOCKET */
+
+#ifdef __cplusplus
+extern }
+#endif
+
+#endif /* _SYS_SOCKET_H */
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 14 13:00:14 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 14 Jul 2020 13:00:14 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jvKXe-0004Jb-1l; Tue, 14 Jul 2020 13:00:14 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=8/kp=AZ=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jvKXd-0004JU-85
 for minios-devel@lists.xen.org; Tue, 14 Jul 2020 13:00:13 +0000
X-Inumbo-ID: f42f8064-c5d1-11ea-930a-12813bfff9fa
Received: from mh-fa-0.lancs.ac.uk (unknown [148.88.65.130])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id f42f8064-c5d1-11ea-930a-12813bfff9fa;
 Tue, 14 Jul 2020 13:00:12 +0000 (UTC)
Received: from p5087e57f.dip0.t-ipconnect.de ([80.135.229.127]
 helo=unknown.fritz.box)
 by mh-fa-0.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jvKXa-000TBP-7c; Tue, 14 Jul 2020 14:00:12 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT/LWIP PATCH 0/4] Register socket implementation against
 posix-socket
Date: Tue, 14 Jul 2020 14:59:23 +0200
Message-Id: <20200714125930.91234-6-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200714125930.91234-1-a.jung@lancs.ac.uk>
References: <20200714125930.91234-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-fa-0.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Alexander Jung <alexander.jung@neclab.eu>

This patch series updates LwIP to use Unikraft's posix-socket
microlibrary so as to register its implementation against the AF_INET
and AF_INET6 address family rather than providing globally these same
interfaces.

Alexander Jung (4):
  sockets.c: Register implementation against posix-socket
  Makefile.uk: Remove LwIP getnameinfo
  include/sys/socket.h: Correct prototype definitions
  include/netinet/in.h: Remove LwIP's socket header

 Config.uk            |    4 +-
 Makefile.uk          |    1 -
 include/netinet/in.h |    1 -
 include/sys/socket.h |   14 +-
 sockets.c            | 1252 ++++++++++++++++--------------------------
 5 files changed, 484 insertions(+), 788 deletions(-)

-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 14 13:00:17 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 14 Jul 2020 13:00:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jvKXh-0004KS-4i; Tue, 14 Jul 2020 13:00:17 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=8/kp=AZ=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jvKXf-0004Iz-QH
 for minios-devel@lists.xen.org; Tue, 14 Jul 2020 13:00:15 +0000
X-Inumbo-ID: f2b83e6a-c5d1-11ea-bca7-bc764e2007e4
Received: from mh-fa-0.lancs.ac.uk (unknown [148.88.65.130])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id f2b83e6a-c5d1-11ea-bca7-bc764e2007e4;
 Tue, 14 Jul 2020 13:00:10 +0000 (UTC)
Received: from p5087e57f.dip0.t-ipconnect.de ([80.135.229.127]
 helo=unknown.fritz.box)
 by mh-fa-0.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jvKXY-000TBP-8r; Tue, 14 Jul 2020 14:00:09 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 3/3] lib/posix-socket: Register library within
 Unikraft.
Date: Tue, 14 Jul 2020 14:59:22 +0200
Message-Id: <20200714125930.91234-5-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200714125930.91234-1-a.jung@lancs.ac.uk>
References: <20200714125930.91234-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-fa-0.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Alexander Jung <alexander.jung@neclab.eu>

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/Makefile.uk | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/Makefile.uk b/lib/Makefile.uk
index aa7e730..360fcd8 100644
--- a/lib/Makefile.uk
+++ b/lib/Makefile.uk
@@ -8,6 +8,7 @@ $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukboot))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukswrand))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/posix-user))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/posix-sysinfo))
+$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/posix-socket))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukdebug))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukargparse))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uktimeconv))
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 14 13:00:17 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 14 Jul 2020 13:00:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jvKXh-0004Ka-6v; Tue, 14 Jul 2020 13:00:17 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=8/kp=AZ=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jvKXg-0004JU-7A
 for minios-devel@lists.xen.org; Tue, 14 Jul 2020 13:00:16 +0000
X-Inumbo-ID: f5d12fd0-c5d1-11ea-930a-12813bfff9fa
Received: from mh-fa-0.lancs.ac.uk (unknown [148.88.65.130])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id f5d12fd0-c5d1-11ea-930a-12813bfff9fa;
 Tue, 14 Jul 2020 13:00:15 +0000 (UTC)
Received: from p5087e57f.dip0.t-ipconnect.de ([80.135.229.127]
 helo=unknown.fritz.box)
 by mh-fa-0.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jvKXc-000TBP-8o; Tue, 14 Jul 2020 14:00:14 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT/LWIP PATCH 1/4] sockets.c: Register implementation against
 posix-socket
Date: Tue, 14 Jul 2020 14:59:24 +0200
Message-Id: <20200714125930.91234-7-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200714125930.91234-1-a.jung@lancs.ac.uk>
References: <20200714125930.91234-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-fa-0.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Alexander Jung <alexander.jung@neclab.eu>

This patch registers LwIP's socket implementatin against the
internal Unikraft posix-socket microlibrary and exposes AF_INET
and AF_INET6 implementations.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 Config.uk |    4 +-
 sockets.c | 1252 ++++++++++++++++++++---------------------------------
 2 files changed, 477 insertions(+), 779 deletions(-)

diff --git a/Config.uk b/Config.uk
index debf0c7..64bab89 100644
--- a/Config.uk
+++ b/Config.uk
@@ -157,8 +157,8 @@ config LWIP_DNS_TABLE_SIZE
 endif
 
 config LWIP_SOCKET
-	bool "Socket API"
-	select LIBVFSCORE
+	bool "Provide POSIX socket API"
+	select LIBPOSIX_SOCKET
 	depends on LWIP_THREADS && (LWIP_UDP || LWIP_TCP)
 	default y
 
diff --git a/sockets.c b/sockets.c
index 8fde21a..da1f70d 100644
--- a/sockets.c
+++ b/sockets.c
@@ -1,8 +1,9 @@
 /* SPDX-License-Identifier: BSD-3-Clause */
 /*
  * Authors: Sharan Santhanam <sharan.santhanam@neclab.eu>
+ *          Alexander Jung <alexander.jung@neclab.eu>
  *
- * Copyright (c) 2019, NEC Laboratories Europe GmbH, NEC Corporation.
+ * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation.
  *                     All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,873 +30,570 @@
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
- *
- * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
  */
 
-/* network stub calls */
 #include <uk/config.h>
-#include <sys/time.h>
-#if CONFIG_LWIP_SOCKET_PPOLL
-#include <signal.h>
-#endif
-#include <vfscore/dentry.h>
-#include <vfscore/file.h>
-#include <vfscore/fs.h>
-#include <vfscore/mount.h>
-#include <vfscore/vnode.h>
-#include <uk/alloc.h>
-#include <uk/essentials.h>
-#include <uk/errptr.h>
-#include <stdio.h>
-#include <errno.h>
+#include <uk/assert.h>
+#include <sys/socket.h>
+#include <uk/socket.h>
 #include <lwip/sockets.h>
+#include <uk/print.h>
 
-#define SOCK_NET_SET_ERRNO(errcode) \
-	(errno = -(errcode))
-
-static int sock_net_close(struct vnode *s_vnode,
-			struct vfscore_file *vfscore_file);
-static int sock_net_write(struct vnode *s_vnode,
-			struct uio *buf, int ioflag __unused);
-static int sock_net_read(struct vnode *s_vnode,
-			struct vfscore_file *vfscore_file __unused,
-			struct uio *buf, int ioflag __unused);
-static int sock_net_ioctl(struct vnode *s_vnode,
-			struct vfscore_file *vfscore_file __unused,
-			unsigned long request,
-			void *buf);
-
-#define sock_net_getattr   ((vnop_getattr_t) vfscore_vop_einval)
-#define sock_net_inactive  ((vnop_inactive_t) vfscore_vop_nullop)
-
-static struct vnops sock_net_vnops = {
-	.vop_close = sock_net_close,
-	.vop_write = sock_net_write,
-	.vop_read  = sock_net_read,
-	.vop_ioctl = sock_net_ioctl,
-	.vop_getattr = sock_net_getattr,
-	.vop_inactive = sock_net_inactive
-};
-
-#define sock_net_vget  ((vfsop_vget_t) vfscore_vop_nullop)
-
-static struct vfsops sock_net_vfsops = {
-	.vfs_vget = sock_net_vget,
-	.vfs_vnops = &sock_net_vnops
-};
-
-
-static uint64_t s_inode = 0;
-/*
- * Bogus mount point used by all sockets
- */
-static struct mount s_mount = {
-	.m_op = &sock_net_vfsops
+struct lwip_socket {
+  int lwip_fd;
 };
 
-struct sock_net_file {
-	struct vfscore_file *vfscore_file;
-	int sock_fd;
-};
-
-static inline struct sock_net_file *sock_net_file_get(int fd)
-{
-	struct sock_net_file *file = NULL;
-	struct vfscore_file *fos;
-
-	fos = vfscore_get_file(fd);
-	if (!fos) {
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("failed with invalid descriptor\n"));
-		file = ERR2PTR(-EINVAL);
-		goto EXIT;
-	}
-	if (fos->f_dentry->d_vnode->v_type != VSOCK) {
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("file descriptor is not a socket\n"));
-		file = ERR2PTR(-EBADF);
-		goto EXIT;
-	}
-	file = fos->f_data;
-EXIT:
-	return file;
-}
-
-static int sock_fd_alloc(int sock_fd)
+int
+lwip_lib_socket_init(struct posix_socket_driver *d)
 {
-	int ret = 0;
-	int vfs_fd;
-	struct sock_net_file *file = NULL;
-	struct vfscore_file *vfs_file = NULL;
-	struct dentry *s_dentry;
-	struct vnode *s_vnode;
-
-	/* Reserve file descriptor number */
-	vfs_fd = vfscore_alloc_fd();
-	if (vfs_fd < 0) {
-		ret = -ENFILE;
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("Failed to allocate file descriptor number\n"));
-		goto ERR_EXIT;
-	}
-
-	/* Allocate file, dentry, and vnode */
-	file = uk_calloc(uk_alloc_get_default(), 1, sizeof(*file));
-	if (!file) {
-		ret = -ENOMEM;
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("Failed to allocate socket file: Out of memory\n"));
-		goto ERR_MALLOC_FILE;
-	}
-	vfs_file = uk_calloc(uk_alloc_get_default(), 1, sizeof(*vfs_file));
-	if (!vfs_file) {
-		ret = -ENOMEM;
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-				("Failed to allocate socket vfs_file: Out of memory\n"));
-		goto ERR_MALLOC_VFS_FILE;
-	}
-
-	ret = vfscore_vget(&s_mount, s_inode++, &s_vnode);
-	UK_ASSERT(ret == 0); /* we should not find it in cache */
-
-	if (!s_vnode) {
-		ret = -ENOMEM;
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("Failed to allocate socket vnode: Out of memory\n"));
-		goto ERR_ALLOC_VNODE;
-	}
-
-	uk_mutex_unlock(&s_vnode->v_lock);
-
-	/*
-	 * it doesn't matter that all the dentries have the
-	 * same path since we never lookup for them
-	 */
-	s_dentry = dentry_alloc(NULL, s_vnode, "/");
-
-	if (!s_dentry) {
-		ret = -ENOMEM;
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("Failed to allocate socket dentry: Out of memory\n"));
-		goto ERR_ALLOC_DENTRY;
-	}
-
-	/* Put things together, and fill out necessary fields */
-	vfs_file->fd = vfs_fd;
-	vfs_file->f_flags = UK_FWRITE | UK_FREAD;
-	vfs_file->f_count = 1;
-	vfs_file->f_data = file;
-	vfs_file->f_dentry = s_dentry;
-	vfs_file->f_vfs_flags = UK_VFSCORE_NOPOS;
-
-	s_vnode->v_data = file;
-	s_vnode->v_type = VSOCK;
-
-	file->vfscore_file = vfs_file;
-	file->sock_fd = sock_fd;
-	LWIP_DEBUGF(SOCKETS_DEBUG, ("Allocated socket %d (%x)\n",
-				    file->vfscore_file->fd,
-				    file->sock_fd));
-
-	/* Storing the information within the vfs structure */
-	ret = vfscore_install_fd(vfs_fd, file->vfscore_file);
-	if (ret) {
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("Failed to install socket fd\n"));
-		goto ERR_VFS_INSTALL;
-	}
-
-	/* Only the dentry should hold a reference; release ours */
-	vrele(s_vnode);
-
-	/* Return file descriptor of our socket */
-	return vfs_fd;
-
-ERR_VFS_INSTALL:
-	drele(s_dentry);
-ERR_ALLOC_DENTRY:
-	vrele(s_vnode);
-ERR_ALLOC_VNODE:
-	uk_free(uk_alloc_get_default(), vfs_file);
-ERR_MALLOC_VFS_FILE:
-	uk_free(uk_alloc_get_default(), file);
-ERR_MALLOC_FILE:
-	vfscore_put_fd(vfs_fd);
-ERR_EXIT:
-	UK_ASSERT(ret < 0);
-	return ret;
+  return 0;
 }
 
-static int sock_net_close(struct vnode *s_vnode,
-			struct vfscore_file *vfscore_file)
+static void *
+lwip_glue_create(struct posix_socket_driver *d,
+          int family, int type, int protocol)
 {
-	int ret;
-	struct sock_net_file *file = NULL;
-
-	file = s_vnode->v_data;
-	LWIP_DEBUGF(SOCKETS_DEBUG, ("%s fd:%d lwip_fd:%d\n",
-				    __func__,
-				    file->vfscore_file->fd,
-				    file->sock_fd));
-
-	UK_ASSERT(vfscore_file->f_dentry->d_vnode == s_vnode);
-	UK_ASSERT(s_vnode->v_refcnt == 1);
-
-	/* Close and release the lwip socket */
-	ret = lwip_close(file->sock_fd);
-
-	/*
-	 * Free socket file
-	 * The rest of the resources will be freed by vfs
-	 *
-	 * TODO: vfs ignores close errors right now, so free our file
-	 */
-	uk_free(uk_alloc_get_default(), file);
-
-	/*
-	 * lwip sets errno and returns -1 in case of error, but
-	 * vfs expects us to return a positive errno
-	 */
-	if (ret < 0)
-		return errno;
-
-	return ret;
-}
+  void *ret = NULL;
+  struct lwip_socket *lwip_sock;
+
+  /* Use our socket data store to hold onto LwIP's file descriptor. */
+  lwip_sock = uk_calloc(d->allocator, 1, sizeof(struct lwip_socket));
+  if (!lwip_sock) {
+    ret = NULL;
+    SOCKET_LIB_ERR(d, -1, "could not allocate socket: out of memory");
+    goto EXIT;
+  }
+  
+  /* Create an LwIP socket */
+  lwip_sock->lwip_fd = lwip_socket(family, type, protocol);
+  if (lwip_sock->lwip_fd < 0) {
+    ret = NULL;
+    goto LWIP_SOCKET_CLEANUP;
+  }
+
+  /* Return the whole LwIP socket struct for the driver */
+  ret = lwip_sock;
 
-static int sock_net_write(struct vnode *s_vnode,
-			struct uio *buf, int ioflag __unused)
-{
-	int ret = 0;
-	struct sock_net_file *file = NULL;
-
-	file = s_vnode->v_data;
-	LWIP_DEBUGF(SOCKETS_DEBUG, ("%s fd:%d lwip_fd:%d\n",
-				    __func__,
-				    file->vfscore_file->fd,
-				    file->sock_fd));
-	ret = lwip_writev(file->sock_fd, buf->uio_iov, buf->uio_iovcnt);
-	/*
-	 * lwip sets errno and returns -1 in case of error, but
-	 * vfs expects us to return a positive errno
-	 */
-	if (ret < 0)
-		return errno;
-
-	buf->uio_resid -= ret;
-	return 0;
-}
+EXIT:
+  return ret;
 
-static int sock_net_read(struct vnode *s_vnode,
-			struct vfscore_file *vfscore_file __unused,
-			struct uio *buf, int ioflag __unused)
-{
-	int ret = 0;
-	struct sock_net_file *file = NULL;
-
-	file = s_vnode->v_data;
-	LWIP_DEBUGF(SOCKETS_DEBUG, ("%s fd:%d lwip_fd:%d\n",
-				    __func__,
-				    file->vfscore_file->fd,
-				    file->sock_fd));
-	ret = lwip_readv(file->sock_fd, buf->uio_iov, buf->uio_iovcnt);
-	/*
-	 * lwip sets errno and returns -1 in case of error, but
-	 * vfs expects us to return a positive errno
-	 */
-	if (ret < 0)
-		return errno;
-
-	buf->uio_resid -= ret;
-	return 0;
+LWIP_SOCKET_CLEANUP:
+  uk_free(d->allocator, lwip_sock);
+  goto EXIT;
 }
 
-static int sock_net_ioctl(struct vnode *s_vnode,
-			struct vfscore_file *vfscore_file __unused,
-			unsigned long request,
-			void *buf)
+static void *
+lwip_glue_accept(struct posix_socket_driver *d,
+          void *sock, struct sockaddr *restrict addr,
+          socklen_t *restrict addr_len)
 {
-	struct sock_net_file *file = NULL;
-
-	file = s_vnode->v_data;
-	LWIP_DEBUGF(SOCKETS_DEBUG, ("%s fd:%d lwip_fd:%d\n",
-				    __func__,
-				    file->vfscore_file->fd,
-				    file->sock_fd));
-	return lwip_ioctl(file->sock_fd, request, buf);
-}
+  void *ret = NULL;
+  struct lwip_socket *lwip_sock;
+  struct lwip_socket *new_sock;
+
+  /* Transform the socket descriptor to the lwip_socket pointer. */
+  lwip_sock = (struct lwip_socket *)sock;
+  if (lwip_sock->lwip_fd < 0) {
+    ret = NULL;
+    SOCKET_LIB_ERR(d, -1, "failed to identify socket descriptor");
+    goto EXIT;
+  }
+
+  /* Use our socket data store to hold onto LwIP's file descriptor. */
+  new_sock = uk_calloc(d->allocator, 1, sizeof(struct lwip_socket));
+  if (!new_sock) {
+    ret = NULL;
+    SOCKET_LIB_ERR(d, -1, "could not allocate socket: out of memory");
+    goto EXIT;
+  }
+  
+  /* Create an LwIP socket */
+  new_sock->lwip_fd = lwip_accept(lwip_sock->lwip_fd, addr, addr_len);
+  if (new_sock->lwip_fd < 0) {
+    ret = NULL;
+    goto LWIP_SOCKET_CLEANUP;
+  }
+
+  /* Return the whole LwIP socket struct for the driver */
+  ret = new_sock;
 
-int socket(int domain, int type, int protocol)
-{
-	int ret = 0;
-	int vfs_fd = 0xff;
-	int sock_fd = 0;
-
-	/* Create lwip_socket */
-	sock_fd = lwip_socket(domain, type, protocol);
-	if (sock_fd < 0) {
-		LWIP_DEBUGF(SOCKETS_DEBUG, ("failed to create socket %d\n",
-					    errno));
-		ret = -1;
-		goto EXIT;
-	}
-
-	/* Allocate the file descriptor */
-	vfs_fd = sock_fd_alloc(sock_fd);
-	if (vfs_fd < 0) {
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("failed to allocate descriptor %d\n",
-			     errno));
-		ret = -1;
-		/* Setting the errno */
-		SOCK_NET_SET_ERRNO(vfs_fd);
-		goto LWIP_SOCKET_CLEANUP;
-	}
-
-	/* Returning the file descriptor to the user */
-	ret = vfs_fd;
 EXIT:
-	return ret;
+  return ret;
+
 LWIP_SOCKET_CLEANUP:
-	/* Cleanup the lwip socket */
-	lwip_close(sock_fd);
-	goto EXIT;
+  uk_free(d->allocator, new_sock);
+  goto EXIT;
 }
 
-int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
+static int
+lwip_glue_bind(struct posix_socket_driver *d,
+          void *sock, const struct sockaddr *addr, socklen_t addr_len)
 {
-	int ret = 0;
-	struct sock_net_file *file;
-	int sock_fd, vfs_fd;
-
-	file = sock_net_file_get(s);
-	if (PTRISERR(file)) {
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("failed to accept incoming connection\n"));
-		ret = -1;
-		/* Setting the errno */
-		SOCK_NET_SET_ERRNO(PTR2ERR(file));
-		goto EXIT;
-	}
-
-	/* Accept an incoming connection */
-	sock_fd = lwip_accept(file->sock_fd, addr, addrlen);
-	if (sock_fd < 0) {
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("failed to accept incoming connection\n"));
-		ret = -1;
-		goto EXIT_FDROP;
-	}
-
-	/* Allocate the file descriptor for the accepted connection */
-	vfs_fd = sock_fd_alloc(sock_fd);
-	if (vfs_fd < 0) {
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("failed to allocate descriptor for accepted connection\n"));
-		ret = -1;
-		/* Setting the errno */
-		SOCK_NET_SET_ERRNO(vfs_fd);
-		goto LWIP_SOCKET_CLEANUP;
-	}
-	ret = vfs_fd;
-EXIT_FDROP:
-	vfscore_put_file(file->vfscore_file); /* release refcount */
-EXIT:
-	return ret;
+  int ret = 0;
+  struct lwip_socket *lwip_sock;
+
+  /* Transform the socket descriptor to the lwip_socket pointer. */
+  lwip_sock = (struct lwip_socket *)sock;
+  if (lwip_sock->lwip_fd < 0) {
+    ret = -1;
+    SOCKET_LIB_ERR(d, ret, "failed to identify socket descriptor");
+    goto EXIT;
+  }
+  
+  /* Bind an LwIP socket */
+  ret = lwip_bind(lwip_sock->lwip_fd, addr, addr_len);
+  if (ret < 0)
+    ret = -1;
 
-LWIP_SOCKET_CLEANUP:
-	lwip_close(sock_fd);
-	goto EXIT_FDROP;
+EXIT:
+  return ret;
 }
 
-int bind(int s, const struct sockaddr *name, socklen_t namelen)
+static int
+lwip_glue_shutdown(struct posix_socket_driver *d,
+          void *sock, int how)
 {
-	int ret = 0;
-	struct sock_net_file *file = NULL;
-
-	file = sock_net_file_get(s);
-	if (PTRISERR(file)) {
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("failed to identify socket descriptor\n"));
-		ret = -1;
-		/* Setting the errno */
-		SOCK_NET_SET_ERRNO(PTR2ERR(file));
-		goto EXIT;
-	}
-	/* Bind an incoming connection */
-	ret = lwip_bind(file->sock_fd, name, namelen);
-	if (ret < 0) {
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("failed to bind with socket\n"));
-		ret = -1;
-		goto EXIT_FDROP;
-	}
-EXIT_FDROP:
-	vfscore_put_file(file->vfscore_file); /* release refcount */
+  int ret = 0;
+  struct lwip_socket *lwip_sock;
+
+  /* Transform the socket descriptor to the lwip_socket pointer. */
+  lwip_sock = (struct lwip_socket *)sock;
+  if (lwip_sock->lwip_fd < 0) {
+    ret = -1;
+    SOCKET_LIB_ERR(d, ret, "failed to identify socket descriptor");
+    goto EXIT;
+  }
+  
+  /* Bind an LwIP socket */
+  ret = lwip_shutdown(lwip_sock->lwip_fd, how);
+  if (ret < 0)
+    ret = -1;
+
 EXIT:
-	return ret;
+  return ret;
 }
 
-int poll(struct pollfd fds[], nfds_t nfds, int timeout)
+static int
+lwip_glue_getpeername(struct posix_socket_driver *d,
+          void *sock, struct sockaddr *restrict addr,
+          socklen_t *restrict addr_len)
 {
-	int ret;
-	unsigned int i;
-	struct sock_net_file *file;
-	struct pollfd lwip_fds[nfds];
-
-	for (i = 0; i < nfds; i++) {
-		if (fds[i].fd < 0)
-			lwip_fds[i].fd = fds[i].fd;
-		else {
-			file = sock_net_file_get(fds[i].fd);
-			if (PTRISERR(file)) {
-				LWIP_DEBUGF(SOCKETS_DEBUG,
-					    ("failed to identify socket descriptor\n"));
-				ret = -1;
-				/* Setting the errno */
-				SOCK_NET_SET_ERRNO(PTR2ERR(file));
-				goto EXIT;
-			}
-			lwip_fds[i].fd = file->sock_fd;
-			lwip_fds[i].events = fds[i].events;
-			vfscore_put_file(file->vfscore_file); /* release refcount */
-		}
-	}
-
-	ret = lwip_poll(lwip_fds, nfds, timeout);
-	if (ret < 0)
-		goto EXIT;
-
-	for (i = 0; i < nfds; i++) {
-		if (fds[i].fd < 0)
-			fds[i].revents = 0;
-		else
-			fds[i].revents = lwip_fds[i].revents;
-	}
+  int ret = 0;
+  struct lwip_socket *lwip_sock;
+
+  /* Transform the socket descriptor to the lwip_socket pointer. */
+  lwip_sock = (struct lwip_socket *)sock;
+  if (lwip_sock->lwip_fd < 0) {
+    ret = -1;
+    SOCKET_LIB_ERR(d, ret, "failed to identify socket descriptor");
+    goto EXIT;
+  }
+
+  /* Get the peer name using LwIP */
+  ret = lwip_getpeername(lwip_sock->lwip_fd, addr, addr_len);
+  if (ret < 0)
+    ret = -1;
 
 EXIT:
-	return ret;
+  return ret;
 }
 
-#if CONFIG_LWIP_SOCKET_PPOLL
-#if CONFIG_LIBPTHREAD_EMBEDDED
-#define __sigmask   pthread_sigmask
-#else
-#define __sigmask   sigprocmask
-#endif
-int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p,
-		const sigset_t *sigmask)
+static int
+lwip_glue_getsockname(struct posix_socket_driver *d,
+          void *sock, struct sockaddr *restrict addr,
+          socklen_t *restrict addr_len)
 {
-	sigset_t origmask;
-	int timeout, rc, _rc;
-
-	if (!fds) {
-		errno = EFAULT;
-		rc = -1;
-		goto out;
-	}
-
-	timeout = (tmo_p == NULL) ? -1 :
-		(tmo_p->tv_sec * 1000 + tmo_p->tv_nsec / 1000000);
-	rc = __sigmask(SIG_SETMASK, sigmask, &origmask);
-	if (rc)
-		goto out;
-	rc = poll(fds, nfds, timeout);
-	_rc = __sigmask(SIG_SETMASK, &origmask, NULL);
-	if (rc == 0 && _rc != 0)
-		rc = _rc;
-out:
-	return rc;
+  int ret = 0;
+  struct lwip_socket *lwip_sock;
+
+  /* Transform the socket descriptor to the lwip_socket pointer. */
+  lwip_sock = (struct lwip_socket *)sock;
+  if (lwip_sock->lwip_fd < 0) {
+    ret = -1;
+    SOCKET_LIB_ERR(d, ret, "failed to identify socket descriptor");
+    goto EXIT;
+  }
+
+  /* Get the socket name using LwIP */
+  ret = lwip_getsockname(lwip_sock->lwip_fd, addr, addr_len);
+  if (ret < 0)
+    ret = -1;
+
+EXIT:
+  return ret;
 }
-#endif /* CONFIG_LWIP_SOCKET_PPOLL */
 
-int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
-		struct timeval *timeout)
+static int
+lwip_glue_getsockopt(struct posix_socket_driver *d,
+          void *sock, int level, int optname, void *restrict optval,
+          socklen_t *restrict optlen)
 {
-	uint64_t nsecs;
-	fd_set rd, wr, xc;
-	int i, ret, maxfd;
-	struct sock_net_file *file;
-
-	if (nfds == 0 && timeout != NULL) {
-		nsecs = timeout->tv_sec * 1000000000;
-		nsecs += timeout->tv_usec * 1000;
-		uk_sched_thread_sleep(nsecs);
-		return 0;
-	}
-
-	/* translate the public (vfscore) fds into lwIP socket fds */
-	FD_ZERO(&rd);
-	FD_ZERO(&wr);
-	FD_ZERO(&xc);
-	maxfd = 0;
-	for (i = 0; i < nfds; i++) {
-		if (readfds && FD_ISSET(i, readfds)) {
-			file = sock_net_file_get(i);
-			if (PTRISERR(file)) {
-#if CONFIG_LWIP_SOCKET_SELECT_GENERIC_FDS
-				/* We allow other fd types, but we don't support them */
-				if (PTR2ERR(file) == -EBADF) {
-					FD_CLR(i, readfds);
-					continue;
-				}
-#else
-				LWIP_DEBUGF(SOCKETS_DEBUG,
-					    ("failed to identify socket descriptor\n"));
-				ret = -1;
-				/* Setting the errno */
-				SOCK_NET_SET_ERRNO(PTR2ERR(file));
-				goto EXIT;
-#endif
-			}
-			if (maxfd < file->sock_fd)
-				maxfd = file->sock_fd;
-			FD_SET(file->sock_fd, &rd);
-			vfscore_put_file(file->vfscore_file); /* release refcount */
-		}
-		if (writefds && FD_ISSET(i, writefds)) {
-			file = sock_net_file_get(i);
-			if (PTRISERR(file)) {
-#if CONFIG_LWIP_SOCKET_SELECT_GENERIC_FDS
-				/* We allow other fd types, but we don't support them */
-				if (PTR2ERR(file) == -EBADF) {
-					FD_CLR(i, writefds);
-					continue;
-				}
-#else
-				LWIP_DEBUGF(SOCKETS_DEBUG,
-					    ("failed to identify socket descriptor\n"));
-				ret = -1;
-				/* Setting the errno */
-				SOCK_NET_SET_ERRNO(PTR2ERR(file));
-				goto EXIT;
-#endif
-			}
-			if (maxfd < file->sock_fd)
-				maxfd = file->sock_fd;
-			FD_SET(file->sock_fd, &wr);
-			vfscore_put_file(file->vfscore_file); /* release refcount */
-		}
-		if (exceptfds && FD_ISSET(i, exceptfds)) {
-			file = sock_net_file_get(i);
-			if (PTRISERR(file)) {
-#if CONFIG_LWIP_SOCKET_SELECT_GENERIC_FDS
-				/* We allow other fd types, but we don't support them */
-				if (PTR2ERR(file) == -EBADF) {
-					FD_CLR(i, exceptfds);
-					continue;
-				}
-#else
-				LWIP_DEBUGF(SOCKETS_DEBUG,
-					    ("failed to identify socket descriptor\n"));
-				ret = -1;
-				/* Setting the errno */
-				SOCK_NET_SET_ERRNO(PTR2ERR(file));
-				goto EXIT;
-#endif
-			}
-			if (maxfd < file->sock_fd)
-				maxfd = file->sock_fd;
-			FD_SET(file->sock_fd, &xc);
-			vfscore_put_file(file->vfscore_file); /* release refcount */
-		}
-	}
-
-	ret = lwip_select(maxfd+1, &rd, &wr, &xc, timeout);
-	if (ret < 0)
-		goto EXIT;
-
-	/* translate back from lwIP socket fds to public (vfscore) fds.
-	 * But there's no way to go from lwIP to vfscore, so iterate over
-	 * everything again. Check which ones were set originally, and if
-	 * they aren't also set in lwip_select()'s return, clear them.
-	 */
-	for (i = 0; i < nfds; i++) {
-		if (readfds && FD_ISSET(i, readfds)) {
-			/* This lookup can't fail, or it would already have
-			 * failed during the translation above.
-			 */
-			file = sock_net_file_get(i);
-			if (!FD_ISSET(file->sock_fd, &rd))
-				FD_CLR(i, readfds);
-			vfscore_put_file(file->vfscore_file); /* release refcount */
-		}
-		if (writefds && FD_ISSET(i, writefds)) {
-			/* This lookup can't fail, or it would already have
-			 * failed during the translation above.
-			 */
-			file = sock_net_file_get(i);
-			if (!FD_ISSET(file->sock_fd, &wr))
-				FD_CLR(i, writefds);
-			vfscore_put_file(file->vfscore_file); /* release refcount */
-		}
-		if (exceptfds && FD_ISSET(i, exceptfds)) {
-			/* This lookup can't fail, or it would already have
-			 * failed during the translation above.
-			 */
-			file = sock_net_file_get(i);
-			if (!FD_ISSET(file->sock_fd, &xc))
-				FD_CLR(i, exceptfds);
-			vfscore_put_file(file->vfscore_file); /* release refcount */
-		}
-	}
+  int ret = 0;
+  struct lwip_socket *lwip_sock;
+
+  /* Transform the socket descriptor to the lwip_socket pointer. */
+  lwip_sock = (struct lwip_socket *)sock;
+  if (lwip_sock->lwip_fd < 0) {
+    ret = -1;
+    SOCKET_LIB_ERR(d, ret, "failed to identify socket descriptor");
+    goto EXIT;
+  }
+
+  /* Get the socket options using LwIP */
+  ret = lwip_getsockopt(lwip_sock->lwip_fd, level, optname, optval, optlen);
+  if (ret < 0)
+    ret = -1;
 
 EXIT:
-	return ret;
+  return ret;
 }
 
-int shutdown(int s, int how)
+static int
+lwip_glue_setsockopt(struct posix_socket_driver *d,
+          void *sock, int level, int optname, const void *optval,
+          socklen_t optlen)
 {
-	int ret = 0;
-	struct sock_net_file *file = NULL;
-
-	file = sock_net_file_get(s);
-	if (PTRISERR(file)) {
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("failed to identify socket descriptor\n"));
-		ret = -1;
-		/* Setting the errno */
-		SOCK_NET_SET_ERRNO(PTR2ERR(file));
-		goto EXIT;
-	}
-	/* Shutdown of the descriptor */
-	ret = lwip_shutdown(file->sock_fd, how);
-	vfscore_put_file(file->vfscore_file); /* release refcount */
+  int ret = 0;
+  struct lwip_socket *lwip_sock;
+
+  /* Transform the socket descriptor to the lwip_socket pointer. */
+  lwip_sock = (struct lwip_socket *)sock;
+  if (lwip_sock->lwip_fd < 0) {
+    ret = -1;
+    SOCKET_LIB_ERR(d, ret, "failed to identify socket descriptor");
+    goto EXIT;
+  }
+
+  /* Set the socket options using LwIP */
+  ret = lwip_setsockopt(lwip_sock->lwip_fd, level, optname, optval, optlen);
+  if (ret < 0)
+    ret = -1;
+
 EXIT:
-	return ret;
+  return ret;
 }
 
-int getpeername(int s, struct sockaddr *name, socklen_t *namelen)
+static int
+lwip_glue_connect(struct posix_socket_driver *d,
+          void *sock, const struct sockaddr *addr,
+          socklen_t addr_len)
 {
-	int ret = 0;
-	struct sock_net_file *file = NULL;
-
-	file = sock_net_file_get(s);
-	if (PTRISERR(file)) {
-		LWIP_DEBUGF(SOCKETS_DEBUG, ("failed to identify socket\n"));
-		ret = -1;
-		SOCK_NET_SET_ERRNO(PTR2ERR(file));
-		goto EXIT;
-	}
-	ret = lwip_getpeername(file->sock_fd, name, namelen);
-	vfscore_put_file(file->vfscore_file); /* release refcount */
+  int ret = 0;
+  struct lwip_socket *lwip_sock;
+
+  /* Transform the socket descriptor to the lwip_socket pointer. */
+  lwip_sock = (struct lwip_socket *)sock;
+  if (lwip_sock->lwip_fd < 0) {
+    ret = -1;
+    SOCKET_LIB_ERR(d, ret, "failed to identify socket descriptor");
+    goto EXIT;
+  }
+
+  /* Connect to a socket using LwIP */
+  ret = lwip_connect(lwip_sock->lwip_fd, addr, addr_len);
+  if (ret < 0)
+    ret = -1;
+
 EXIT:
-	return ret;
+  return ret;
 }
 
-int getsockname(int s, struct sockaddr *name, socklen_t *namelen)
+static int
+lwip_glue_listen(struct posix_socket_driver *d,
+          void *sock, int backlog)
 {
-	int ret = 0;
-	struct sock_net_file *file = NULL;
-
-	file = sock_net_file_get(s);
-	if (PTRISERR(file)) {
-		LWIP_DEBUGF(SOCKETS_DEBUG, ("failed to identify socket\n"));
-		ret = -1;
-		SOCK_NET_SET_ERRNO(PTR2ERR(file));
-		goto EXIT;
-	}
-	ret = lwip_getsockname(file->sock_fd, name, namelen);
-	vfscore_put_file(file->vfscore_file); /* release refcount */
+  int ret = 0;
+  struct lwip_socket *lwip_sock;
+
+  /* Transform the socket descriptor to the lwip_socket pointer. */
+  lwip_sock = (struct lwip_socket *)sock;
+  if (lwip_sock->lwip_fd < 0) {
+    ret = -1;
+    SOCKET_LIB_ERR(d, ret, "failed to identify socket descriptor");
+    goto EXIT;
+  }
+  
+  /* Listen usiing LwIP socket */
+  ret = lwip_listen(lwip_sock->lwip_fd, backlog);
+  if (ret < 0)
+    ret = -1;
+
 EXIT:
-	return ret;
+  return ret;
 }
 
-int getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
+static ssize_t
+lwip_glue_recv(struct posix_socket_driver *d,
+          void *sock, void *buf, size_t len, int flags)
 {
-	int ret = 0;
-	struct sock_net_file *file = NULL;
-
-	file = sock_net_file_get(s);
-	if (PTRISERR(file)) {
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("failed to identify socket descriptor\n"));
-		ret = -1;
-		SOCK_NET_SET_ERRNO(PTR2ERR(file));
-		goto EXIT;
-	}
-	ret = lwip_getsockopt(file->sock_fd, level, optname, optval, optlen);
-	vfscore_put_file(file->vfscore_file); /* release refcount */
+  int ret = 0;
+  struct lwip_socket *lwip_sock;
+
+  /* Transform the socket descriptor to the lwip_socket pointer. */
+  lwip_sock = (struct lwip_socket *)sock;
+  if (lwip_sock->lwip_fd < 0) {
+    ret = -1;
+    SOCKET_LIB_ERR(d, ret, "failed to identify socket descriptor");
+    goto EXIT;
+  }
+
+  /* Receive data to a buffer from a socket using LwIP */
+  ret = lwip_recv(lwip_sock->lwip_fd, buf, len, flags);
+  if (ret < 0)
+    ret = -1;
+
 EXIT:
-	return ret;
+  return ret;
+  return 0;
 }
 
-int setsockopt(int s, int level, int optname, const void *optval,
-	       socklen_t optlen)
+static ssize_t
+lwip_glue_recvfrom(struct posix_socket_driver *d,
+          void *sock, void *restrict buf, size_t len, int flags,
+          struct sockaddr *from, socklen_t *restrict fromlen)
 {
-	int ret = 0;
-	struct sock_net_file *file = NULL;
-
-	file = sock_net_file_get(s);
-	if (PTRISERR(file)) {
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("failed to identify socket descriptor\n"));
-		ret = -1;
-		SOCK_NET_SET_ERRNO(PTR2ERR(file));
-		goto EXIT;
-	}
-	ret = lwip_setsockopt(file->sock_fd, level, optname, optval, optlen);
-	vfscore_put_file(file->vfscore_file); /* release refcount */
+  int ret = 0;
+  struct lwip_socket *lwip_sock;
+
+  /* Transform the socket descriptor to the lwip_socket pointer. */
+  lwip_sock = (struct lwip_socket *)sock;
+  if (lwip_sock->lwip_fd < 0) {
+    ret = -1;
+    SOCKET_LIB_ERR(d, ret, "failed to identify socket descriptor");
+    goto EXIT;
+  }
+
+  /* Recieve data to a buffer from a socket using LwIP */
+  ret = lwip_recvfrom(lwip_sock->lwip_fd, buf, len, flags, from, fromlen);
+  if (ret < 0)
+    ret = -1;
+
 EXIT:
-	return ret;
+  return ret;
 }
 
-int connect(int s, const struct sockaddr *name, socklen_t namelen)
+static ssize_t
+lwip_glue_recvmsg(struct posix_socket_driver *d,
+          void *sock, struct msghdr *msg, int flags)
 {
-	int ret = 0;
-	struct sock_net_file *file = NULL;
-
-	file = sock_net_file_get(s);
-	if (PTRISERR(file)) {
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("failed to identify socket descriptor\n"));
-		ret = -1;
-		SOCK_NET_SET_ERRNO(PTR2ERR(file));
-		goto EXIT;
-	}
-	ret = lwip_connect(file->sock_fd, name, namelen);
-	vfscore_put_file(file->vfscore_file); /* release refcount */
+  int ret = 0;
+  struct lwip_socket *lwip_sock;
+
+  /* Transform the socket descriptor to the lwip_socket pointer. */
+  lwip_sock = (struct lwip_socket *)sock;
+  if (lwip_sock->lwip_fd < 0) {
+    ret = -1;
+    SOCKET_LIB_ERR(d, ret, "failed to identify socket descriptor");
+    goto EXIT;
+  }
+
+  /* Receive a structured message from a socket using LwIP */
+  ret = lwip_recvmsg(lwip_sock->lwip_fd, msg, flags);
+  if (ret < 0)
+    ret = -1;
+
 EXIT:
-	return ret;
+  return ret;
 }
 
-int listen(int s, int backlog)
+static ssize_t
+lwip_glue_send(struct posix_socket_driver *d,
+          void *sock, const void *buf, size_t len, int flags)
 {
-	int ret = 0;
-	struct sock_net_file *file = NULL;
-
-	file = sock_net_file_get(s);
-	if (PTRISERR(file)) {
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("failed to identify socket descriptor\n"));
-		ret = -1;
-		SOCK_NET_SET_ERRNO(PTR2ERR(file));
-		goto EXIT;
-	}
-	ret = lwip_listen(file->sock_fd, backlog);
-	vfscore_put_file(file->vfscore_file); /* release refcount */
+  int ret = 0;
+  struct lwip_socket *lwip_sock;
+
+  /* Transform the socket descriptor to the lwip_socket pointer. */
+  lwip_sock = (struct lwip_socket *)sock;
+  if (lwip_sock->lwip_fd < 0) {
+    ret = -1;
+    SOCKET_LIB_ERR(d, ret, "failed to identify socket descriptor");
+    goto EXIT;
+  }
+
+  /* Send data from a buffer to a socket using LwIP */
+  ret = lwip_send(lwip_sock->lwip_fd, buf, len, flags);
+  if (ret < 0)
+    ret = -1;
+
 EXIT:
-	return ret;
+  return ret;
 }
 
-int recv(int s, void *mem, size_t len, int flags)
+static ssize_t
+lwip_glue_sendmsg(struct posix_socket_driver *d,
+          void *sock, const struct msghdr *msg, int flags)
 {
-	int ret = 0;
-	struct sock_net_file *file = NULL;
-
-	file = sock_net_file_get(s);
-	if (PTRISERR(file)) {
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("failed to identify socket descriptor\n"));
-		ret = -1;
-		SOCK_NET_SET_ERRNO(PTR2ERR(file));
-		goto EXIT;
-	}
-	ret = lwip_recv(file->sock_fd, mem, len, flags);
-	vfscore_put_file(file->vfscore_file); /* release refcount */
+  int ret = 0;
+  struct lwip_socket *lwip_sock;
+
+  /* Transform the socket descriptor to the lwip_socket pointer. */
+  lwip_sock = (struct lwip_socket *)sock;
+  if (lwip_sock->lwip_fd < 0) {
+    ret = -1;
+    SOCKET_LIB_ERR(d, ret, "failed to identify socket descriptor");
+    goto EXIT;
+  }
+
+  /* Send a structured message over a socket using LwIP */
+  ret = lwip_sendmsg(lwip_sock->lwip_fd, msg, flags);
+  if (ret < 0)
+    ret = -1;
+
 EXIT:
-	return ret;
+  return ret;
 }
 
-int recvfrom(int s, void *mem, size_t len, int flags,
-		      struct sockaddr *from, socklen_t *fromlen)
+static ssize_t
+lwip_glue_sendto(struct posix_socket_driver *d,
+          void *sock, const void *buf, size_t len, int flags,
+          const struct sockaddr *dest_addr, socklen_t addrlen)
 {
-	int ret = 0;
-	struct sock_net_file *file = NULL;
-
-	file = sock_net_file_get(s);
-	if (PTRISERR(file)) {
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("failed to identify socket descriptor\n"));
-		ret = -1;
-		SOCK_NET_SET_ERRNO(PTR2ERR(file));
-		goto EXIT;
-	}
-	ret = lwip_recvfrom(file->sock_fd, mem, len, flags, from, fromlen);
-	vfscore_put_file(file->vfscore_file); /* release refcount */
+  int ret = 0;
+  struct lwip_socket *lwip_sock;
+
+  /* Transform the socket descriptor to the lwip_socket pointer. */
+  lwip_sock = (struct lwip_socket *)sock;
+  if (lwip_sock->lwip_fd < 0) {
+    ret = -1;
+    SOCKET_LIB_ERR(d, ret, "failed to identify socket descriptor");
+    goto EXIT;
+  }
+
+  /* Send to an address over a socket using LwIP */
+  ret = lwip_sendto(lwip_sock->lwip_fd, buf, len, flags, dest_addr, addrlen);
+  if (ret < 0)
+    ret = -1;
+
 EXIT:
-	return ret;
+  return ret;
 }
 
-int recvmsg(int s, struct msghdr *msg, int flags)
+static int
+lwip_glue_read(struct posix_socket_driver *d,
+          void *sock, void *buf, size_t count)
 {
-	int ret = 0;
-	struct sock_net_file *file = NULL;
-
-	file = sock_net_file_get(s);
-	if (PTRISERR(file)) {
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("failed to identify socket descriptor\n"));
-		ret = -1;
-		SOCK_NET_SET_ERRNO(PTR2ERR(file));
-		goto EXIT;
-	}
-	ret = lwip_recvmsg(file->sock_fd, msg, flags);
-	vfscore_put_file(file->vfscore_file); /* release refcount */
+  int ret = 0;
+  struct lwip_socket *lwip_sock;
+
+  /* Transform the socket descriptor to the lwip_socket pointer. */
+  lwip_sock = (struct lwip_socket *)sock;
+  if (lwip_sock->lwip_fd < 0) {
+    ret = -1;
+    SOCKET_LIB_ERR(d, ret, "failed to identify socket descriptor");
+    goto EXIT;
+  }
+  
+  /* Listen usiing LwIP socket */
+  ret = lwip_readv(lwip_sock->lwip_fd, buf, count);
+  if (ret < 0)
+    ret = -1;
+
 EXIT:
-	return ret;
+  return ret;
 }
 
-int send(int s, const void *dataptr, size_t size, int flags)
+static int
+lwip_glue_write(struct posix_socket_driver *d,
+          void *sock, const void *buf, size_t count)
 {
-	int ret = 0;
-	struct sock_net_file *file = NULL;
-
-	file = sock_net_file_get(s);
-	if (PTRISERR(file)) {
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("failed to identify socket descriptor\n"));
-		ret = -1;
-		SOCK_NET_SET_ERRNO(PTR2ERR(file));
-		goto EXIT;
-	}
-	ret = lwip_send(file->sock_fd, dataptr, size, flags);
-	vfscore_put_file(file->vfscore_file); /* release refcount */
+  int ret = 0;
+  struct lwip_socket *lwip_sock;
+
+  /* Transform the socket descriptor to the lwip_socket pointer. */
+  lwip_sock = (struct lwip_socket *)sock;
+  if (lwip_sock->lwip_fd < 0) {
+    ret = -1;
+    SOCKET_LIB_ERR(d, ret, "failed to identify socket descriptor");
+    goto EXIT;
+  }
+  
+  /* Write to an incomming connection using LwIP */
+  ret = lwip_writev(lwip_sock->lwip_fd, buf, count);
+  if (ret < 0)
+    ret = -1;
+
 EXIT:
-	return ret;
+  return ret;
 }
 
-int sendmsg(int s, const struct msghdr *message, int flags)
+static int
+lwip_glue_close(struct posix_socket_driver *d,
+          void *sock)
 {
-	int ret = 0;
-	struct sock_net_file *file = NULL;
-
-	file = sock_net_file_get(s);
-	if (PTRISERR(file)) {
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("failed to identify socket descriptor\n"));
-		ret = -1;
-		SOCK_NET_SET_ERRNO(PTR2ERR(file));
-		goto EXIT;
-	}
-	ret = lwip_sendmsg(file->sock_fd, message, flags);
-	vfscore_put_file(file->vfscore_file); /* release refcount */
+  int ret = 0;
+  struct lwip_socket *lwip_sock;
+
+  /* Transform the socket descriptor to the lwip_socket pointer. */
+  lwip_sock = (struct lwip_socket *)sock;
+  if (lwip_sock->lwip_fd < 0) {
+    ret = -1;
+    SOCKET_LIB_ERR(d, ret, "failed to identify socket descriptor");
+    goto EXIT;
+  }
+
+  /* Close an incoming connection using LwIP */
+  ret = lwip_close(lwip_sock->lwip_fd);
+  if (ret < 0)
+    ret = -1;
+
 EXIT:
-	return ret;
+  return ret;
 }
 
-int sendto(int s, const void *dataptr, size_t size, int flags,
-		    const struct sockaddr *to, socklen_t tolen)
+static int
+lwip_glue_ioctl(struct posix_socket_driver *d,
+          void *sock, int request, void *argp)
 {
-	int ret = 0;
-	struct sock_net_file *file = NULL;
-
-	file = sock_net_file_get(s);
-	if (PTRISERR(file)) {
-		LWIP_DEBUGF(SOCKETS_DEBUG,
-			    ("failed to identify socket descriptor\n"));
-		ret = -1;
-		SOCK_NET_SET_ERRNO(PTR2ERR(file));
-		goto EXIT;
-	}
-	ret = lwip_sendto(file->sock_fd, dataptr, size, flags, to, tolen);
-	vfscore_put_file(file->vfscore_file); /* release refcount */
+  int ret = 0;
+  struct lwip_socket *lwip_sock;
+
+  /* Transform the socket descriptor to the lwip_socket pointer. */
+  lwip_sock = (struct lwip_socket *)sock;
+  if (lwip_sock->lwip_fd < 0) {
+    ret = -1;
+    SOCKET_LIB_ERR(d, ret, "failed to identify socket descriptor");
+    goto EXIT;
+  }
+
+  /* Close an incoming connection using LwIP */
+  ret = lwip_ioctl(lwip_sock->lwip_fd, request, argp);
+  if (ret < 0)
+    ret = -1;
+
 EXIT:
-	return ret;
+  return ret;
 }
 
-int socketpair(int domain, int type, int protocol, int sv[2])
-{
-	errno = ENOTSUP;
-	return -1;
-}
+static struct posix_socket_ops lwip_socket_ops = {
+  /* The initialization function on socket registration. */
+  .init        = lwip_lib_socket_init,
+  /* POSIX interfaces */
+  .create      = lwip_glue_create,
+  .accept      = lwip_glue_accept,
+  .bind        = lwip_glue_bind,
+  .shutdown    = lwip_glue_shutdown,
+  .getpeername = lwip_glue_getpeername,
+  .getsockname = lwip_glue_getsockname,
+  .getsockopt  = lwip_glue_getsockopt,
+  .setsockopt  = lwip_glue_setsockopt,
+  .connect     = lwip_glue_connect,
+  .listen      = lwip_glue_listen,
+  .recv        = lwip_glue_recv,
+  .recvfrom    = lwip_glue_recvfrom,
+  .recvmsg     = lwip_glue_recvmsg,
+  .send        = lwip_glue_send,
+  .sendmsg     = lwip_glue_sendmsg,
+  .sendto      = lwip_glue_sendto,
+  /* vfscore ops */
+  .read        = lwip_glue_read,
+  .write       = lwip_glue_write,
+  .close       = lwip_glue_close,
+  .ioctl       = lwip_glue_ioctl,
+};
+
+POSIX_SOCKET_FAMILY_REGISTER(AF_INET,  &lwip_socket_ops, NULL);
+
+#ifdef CONFIG_LWIP_IPV6
+POSIX_SOCKET_FAMILY_REGISTER(AF_INET6, &lwip_socket_ops, NULL);
+#endif /* CONFIG_LWIP_IPV6 */
\ No newline at end of file
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 14 13:00:19 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 14 Jul 2020 13:00:19 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jvKXj-0004Ld-9t; Tue, 14 Jul 2020 13:00:19 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=8/kp=AZ=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jvKXi-0004JU-6V
 for minios-devel@lists.xen.org; Tue, 14 Jul 2020 13:00:18 +0000
X-Inumbo-ID: f70c8f8e-c5d1-11ea-930a-12813bfff9fa
Received: from mh-fa-0.lancs.ac.uk (unknown [148.88.65.130])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id f70c8f8e-c5d1-11ea-930a-12813bfff9fa;
 Tue, 14 Jul 2020 13:00:17 +0000 (UTC)
Received: from p5087e57f.dip0.t-ipconnect.de ([80.135.229.127]
 helo=unknown.fritz.box)
 by mh-fa-0.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jvKXf-000TBP-8B; Tue, 14 Jul 2020 14:00:17 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT/LWIP PATCH 2/4] Makefile.uk: Remove LwIP getnameinfo
Date: Tue, 14 Jul 2020 14:59:25 +0200
Message-Id: <20200714125930.91234-8-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200714125930.91234-1-a.jung@lancs.ac.uk>
References: <20200714125930.91234-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-fa-0.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Alexander Jung <alexander.jung@neclab.eu>

Unikraft posix-socket implements a global `getnameinfo` method
and so compilation of this file provided by LwIP is no longer
needed.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 Makefile.uk | 1 -
 1 file changed, 1 deletion(-)

diff --git a/Makefile.uk b/Makefile.uk
index 56ebcfc..27b11ee 100644
--- a/Makefile.uk
+++ b/Makefile.uk
@@ -91,7 +91,6 @@ LIBLWIP_SRCS-y += $(LIBLWIP_BASE)/time.c|unikraft
 LIBLWIP_SRCS-y += $(LIBLWIP_BASE)/sendfile.c|unikraft
 LIBLWIP_SRCS-$(CONFIG_LWIP_SOCKET) += $(LIBLWIP_BASE)/sockets.c|unikraft
 LIBLWIP_SOCKETS_FLAGS-y += -Wno-cast-function-type
-LIBLWIP_SRCS-$(CONFIG_LWIP_DNS) += $(LIBLWIP_BASE)/getnameinfo.c|unikraft
 LIBLWIP_SRCS-y += $(LIBLWIP_EXTRACTED)/core/init.c
 LIBLWIP_SRCS-y += $(LIBLWIP_EXTRACTED)/core/def.c
 LIBLWIP_SRCS-y += $(LIBLWIP_EXTRACTED)/core/inet_chksum.c
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 14 13:00:22 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 14 Jul 2020 13:00:22 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jvKXm-0004Mh-Bi; Tue, 14 Jul 2020 13:00:22 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=8/kp=AZ=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jvKXk-0004Iz-QZ
 for minios-devel@lists.xen.org; Tue, 14 Jul 2020 13:00:20 +0000
X-Inumbo-ID: f0a60328-c5d1-11ea-bca7-bc764e2007e4
Received: from mh-fa-0.lancs.ac.uk (unknown [148.88.65.130])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id f0a60328-c5d1-11ea-bca7-bc764e2007e4;
 Tue, 14 Jul 2020 13:00:07 +0000 (UTC)
Received: from p5087e57f.dip0.t-ipconnect.de ([80.135.229.127]
 helo=unknown.fritz.box)
 by mh-fa-0.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jvKXT-000TBP-7U; Tue, 14 Jul 2020 14:00:06 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 1/3] lib/posix-socket: Introduce abstraction for
 communication sockets
Date: Tue, 14 Jul 2020 14:59:20 +0200
Message-Id: <20200714125930.91234-3-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200714125930.91234-1-a.jung@lancs.ac.uk>
References: <20200714125930.91234-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-fa-0.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Alexander Jung <alexander.jung@neclab.eu>

This initial commit introduces a microlibrary to manage multiple
implementations of POSIX compliant sockets.  By exposing global
prototypes as an abstraction, the microlibrary can interchange
between AF socket families.  For example, an implementation
for AF_INET can register against this microlibrary in order to
communicate over the IP/TCP stack.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/posix-socket/Config.uk                  |   18 +
 lib/posix-socket/Makefile.uk                |   10 +
 lib/posix-socket/driver.c                   |  154 +++
 lib/posix-socket/exportsyms.uk              |   26 +
 lib/posix-socket/extra.ld                   |    9 +
 lib/posix-socket/include/uk/socket.h        |   45 +
 lib/posix-socket/include/uk/socket_driver.h | 1018 +++++++++++++++++++
 lib/posix-socket/include/uk/socket_vnops.h  |   97 ++
 lib/posix-socket/socket.c                   |  722 +++++++++++++
 lib/posix-socket/socket_vnops.c             |  323 ++++++
 10 files changed, 2422 insertions(+)
 create mode 100644 lib/posix-socket/Config.uk
 create mode 100644 lib/posix-socket/Makefile.uk
 create mode 100644 lib/posix-socket/driver.c
 create mode 100644 lib/posix-socket/exportsyms.uk
 create mode 100644 lib/posix-socket/extra.ld
 create mode 100644 lib/posix-socket/include/uk/socket.h
 create mode 100644 lib/posix-socket/include/uk/socket_driver.h
 create mode 100644 lib/posix-socket/include/uk/socket_vnops.h
 create mode 100644 lib/posix-socket/socket.c
 create mode 100644 lib/posix-socket/socket_vnops.c

diff --git a/lib/posix-socket/Config.uk b/lib/posix-socket/Config.uk
new file mode 100644
index 0000000..bf99f17
--- /dev/null
+++ b/lib/posix-socket/Config.uk
@@ -0,0 +1,18 @@
+menuconfig LIBPOSIX_SOCKET
+	bool "posix-socket: Abstraction for communication sockets"
+	default n
+	select LIBUKDEBUG
+	select LIBUKALLOC
+  select LIBFDTABLE
+	help
+		This microlibrary allows other microlibraries to register a socket family 
+		number, such as AF_INET, for their socket implementation and provides the 
+		POSIX socket API unikernel-wide and acts appropriately on a given file 
+		descriptor.  
+		
+		The API includes prototypes for socket(), accept(), bind(), shutdown(), 
+		connect(), listen(), send(), sendmsg(), sendto(), recv(), recvfrom(), 
+		recvmsg(), getpeername(), getsockname(), getsockopt() and setsockopt().
+
+if LIBPOSIX_SOCKET
+endif
diff --git a/lib/posix-socket/Makefile.uk b/lib/posix-socket/Makefile.uk
new file mode 100644
index 0000000..a9beee0
--- /dev/null
+++ b/lib/posix-socket/Makefile.uk
@@ -0,0 +1,10 @@
+$(eval $(call addlib_s,libposix_socket,$(CONFIG_LIBPOSIX_SOCKET)))
+
+LIBPOSIX_SOCKET_COMMON_INCLUDES-y += -I$(LIBPOSIX_SOCKET_BASE)/include
+
+CINCLUDES-$(CONFIG_LIBPOSIX_SOCKET) += $(LIBPOSIX_SOCKET_COMMON_INCLUDES-y)
+CXXINCLUDES-$(CONFIG_LIBPOSIX_SOCKET) += $(LIBPOSIX_SOCKET_COMMON_INCLUDES-y)
+
+LIBPOSIX_SOCKET_SRCS-$(CONFIG_LIBPOSIX_SOCKET) += $(LIBPOSIX_SOCKET_BASE)/driver.c
+LIBPOSIX_SOCKET_SRCS-$(CONFIG_LIBPOSIX_SOCKET) += $(LIBPOSIX_SOCKET_BASE)/socket_vnops.c
+LIBPOSIX_SOCKET_SRCS-$(CONFIG_LIBPOSIX_SOCKET) += $(LIBPOSIX_SOCKET_BASE)/socket.c
diff --git a/lib/posix-socket/driver.c b/lib/posix-socket/driver.c
new file mode 100644
index 0000000..ad01241
--- /dev/null
+++ b/lib/posix-socket/driver.c
@@ -0,0 +1,154 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Alexander Jung <alexander.jung@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR SOCKETINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <inttypes.h>
+#include <uk/alloc.h>
+#include <uk/assert.h>
+#include <uk/print.h>
+#include <uk/list.h>
+#include <uk/socket_driver.h>
+#include <sys/types.h>
+
+/**
+ * List of socket family drivers
+ */
+UK_TAILQ_HEAD(posix_socket_driver_list, struct posix_socket_driver);
+struct posix_socket_driver_list posix_socket_families =
+          UK_TAILQ_HEAD_INITIALIZER(posix_socket_families);
+static uint16_t uk_posix_socket_family_count;
+
+unsigned int
+posix_socket_family_count(void)
+{
+  return uk_posix_socket_family_count;
+}
+
+void _posix_socket_family_register(struct posix_socket_driver *d,
+          int fam,
+          struct posix_socket_ops *ops,
+          struct uk_alloc *alloc)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(ops);
+
+  if (unlikely(fam == 0)) {
+    uk_pr_crit("Cannot register unspecified socket family: %p\n", ops);
+    return;
+  }
+
+  uk_pr_debug("Registering socket handler: library: %s, family: %d: %p...\n", d->libname, fam, ops);
+
+  struct posix_socket_driver *e;
+  UK_TAILQ_FOREACH(e, &posix_socket_families, _list) {
+    if (e->af_family == fam) {
+      uk_pr_warn("Socket family (%d) already registerd to library %s!", fam, e->libname);
+      return;
+    }
+  }
+
+  new_posix_socket_family(d, fam, alloc, ops);
+  UK_TAILQ_INSERT_TAIL(&posix_socket_families, d, _list);
+  uk_posix_socket_family_count++;
+}
+
+void
+_posix_socket_family_unregister(struct posix_socket_driver *d)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(uk_posix_socket_family_count > 0);
+
+  uk_pr_debug("Unregistering socket handler: %d\n", d->af_family);
+
+	UK_TAILQ_REMOVE(&posix_socket_families, d, _list);
+  uk_posix_socket_family_count--;
+}
+
+static int
+posix_socket_family_init(struct posix_socket_driver *d)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops);
+
+  uk_pr_debug("Initializing socket handler: %d\n", d->af_family);
+
+  /* Assign the default allocator if not specified */
+  if (d->allocator == NULL) {
+    d->allocator = uk_alloc_get_default();
+    uk_pr_debug("Using default memory allocator for socket family: %d: %p\n", d->af_family, d->allocator);
+  }
+
+  if (!d->ops->init)
+    return 0;
+
+  return d->ops->init(d);
+}
+
+/* Returns the number of successfully initialized device sockets */
+static int
+posix_socket_family_lib_init(void)
+{
+  uk_pr_info("Initializing socket handlers...\n");
+  
+	struct posix_socket_driver *d;
+  unsigned int ret = 0;
+ 
+  if (posix_socket_family_count() == 0)
+    return 0;
+
+  UK_TAILQ_FOREACH(d, &posix_socket_families, _list) {
+    if (posix_socket_family_init(d) >= 0)
+      ++ret;
+  }
+
+  return ret;
+}
+
+struct posix_socket_driver *
+posix_socket_driver_get(int af_family)
+{
+  struct posix_socket_driver *d;
+
+  UK_TAILQ_FOREACH(d, &posix_socket_families, _list) {
+    if (d->af_family == af_family)
+      return d;
+  }
+
+  return NULL;
+}
+
+struct posix_socket_driver *
+posix_socket_get_family(int sock)
+{
+  return NULL;
+}
+
+uk_initcall_class_prio(posix_socket_family_lib_init, POSIX_SOCKET_FAMILY_INIT_CLASS, POSIX_SOCKET_FAMILY_INIT_PRIO);
diff --git a/lib/posix-socket/exportsyms.uk b/lib/posix-socket/exportsyms.uk
new file mode 100644
index 0000000..f2e2f37
--- /dev/null
+++ b/lib/posix-socket/exportsyms.uk
@@ -0,0 +1,26 @@
+posix_socket
+posix_socket_get_family
+posix_socket_family_count
+_posix_socket_family_register
+_posix_socket_family_unregister
+socket_alloc_fd
+
+# Full socket API
+socket
+accept
+bind
+shutdown
+getpeername
+getsockname
+getnameinfo
+getsockopt
+setsockopt
+connect
+listen
+recv
+recvfrom
+recvmsg
+send
+sendmsg
+sendto
+socketpair
diff --git a/lib/posix-socket/extra.ld b/lib/posix-socket/extra.ld
new file mode 100644
index 0000000..78346f1
--- /dev/null
+++ b/lib/posix-socket/extra.ld
@@ -0,0 +1,9 @@
+SECTIONS
+{
+	.posix_socket_driver_list : {
+		PROVIDE(posix_socket_driver_list_start = .);
+		KEEP (*(.posix_socket_driver_list))
+    PROVIDE(posix_socket_driver_list_end = .);
+	}
+}
+INSERT AFTER .text;
diff --git a/lib/posix-socket/include/uk/socket.h b/lib/posix-socket/include/uk/socket.h
new file mode 100644
index 0000000..9cd420a
--- /dev/null
+++ b/lib/posix-socket/include/uk/socket.h
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Alexander Jung <alexander.jung@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation.
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef __UK_SOCKET__
+#define __UK_SOCKET__
+
+#include <uk/socket_driver.h>
+#include <uk/socket_vnops.h>
+
+#define SOCKET_LIB_ERR(d, errno, msg) \
+  uk_pr_err("%s_err: %d: %s", d->libname, errno, msg)
+
+#define SOCKET_ERR(errno, msg) \
+  uk_pr_err("%d: %s", errno, msg)
+
+#endif /* __UK_SOCKET__ */
diff --git a/lib/posix-socket/include/uk/socket_driver.h b/lib/posix-socket/include/uk/socket_driver.h
new file mode 100644
index 0000000..2a9226f
--- /dev/null
+++ b/lib/posix-socket/include/uk/socket_driver.h
@@ -0,0 +1,1018 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Alexander Jung <alexander.jung@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation.
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __UK_SOCKET_DRIVER_H__
+#define __UK_SOCKET_DRIVER_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <uk/list.h>
+#include <uk/assert.h>
+#include <uk/init.h>
+#include <uk/list.h>
+#include <uk/ctors.h>
+#include <uk/alloc.h>
+#include <uk/essentials.h>
+#include <errno.h>
+#include <sys/socket.h>
+
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+#define __NEED_socklen_t
+#include <bits/alltypes.h>
+#endif
+
+#define POSIX_SOCKET_FAMILY_INIT_CLASS UK_INIT_CLASS_EARLY
+#define POSIX_SOCKET_FAMILY_INIT_PRIO 0
+#define POSIX_SOCKET_FAMILY_REGISTER_PRIO 2
+
+struct posix_socket_ops;
+struct posix_socket_driver;
+
+/**
+ * The POSIX socket driver defines the operations to be used for the
+ * specified AF family as well as the memory allocator.
+ */
+struct posix_socket_driver {
+  /* The AF family ID */
+	const int af_family;
+  const char *libname;
+  /* The interfaces for this socket */
+	const struct posix_socket_ops *ops;
+  /* The memory allocator to be used for this socket driver */
+  struct uk_alloc *allocator;
+  /* Private data for this socket driver. */
+  void *private;
+  /* Entry for list of socket drivers. */
+	UK_TAILQ_ENTRY(struct posix_socket_driver) _list;
+};
+
+
+/**
+ * The initialization function called for this socket family.  It's here that
+ * additional configuration for the driver can be made after it has been
+ * registered.  For instance, an alternative memory allocator can be provided.
+ *
+ * @param d
+ *  The socket driver.
+ */
+typedef int (*posix_socket_driver_init_func_t)(struct posix_socket_driver *d);
+
+/**
+ * Create a connection on a socket.
+ *
+ * @param driver
+ *  The socket driver.
+ * @param family
+ *  Specifies a communication family domain and thus driver.
+ * @param type
+ *  Specifies communication semantics.
+ * @param protocol
+ *  Specifies a particular protocol to be used with the socket. 
+ */
+typedef void *(*posix_socket_create_func_t)(struct posix_socket_driver *d,
+          int family, int type, int protocol);
+
+
+/**
+ * Accept a connection on a socket.
+ *
+ * @param driver
+ *  The socket driver.
+ * @param sock
+ *  Reference to the socket.
+ * @param addr
+ *  The address of the peer socket.
+ * @param addr_len
+ *  Specifies the size, in bytes, of the address structure pointed to by addr.
+ */
+typedef void *(*posix_socket_accept_func_t)(struct posix_socket_driver *d,
+          void *sock, struct sockaddr *restrict addr,
+          socklen_t *restrict addr_len);
+
+
+/**
+ * Bind a name to a socket.
+ *
+ * @param driver
+ *  The socket driver.
+ * @param sock
+ *  Reference to the socket.
+ * @param addr
+ *  The assigned address.
+ * @param addr_len
+ *  Specifies the size, in bytes, of the address structure pointed to by addr.
+ */
+typedef int (*posix_socket_bind_func_t)(struct posix_socket_driver *d,
+          void *sock, const struct sockaddr *addr, socklen_t addr_len);
+
+
+/**
+ * Shut down part of a full-duplex connection.
+ *
+ * @param driver
+ *  The socket driver.
+ * @param sock
+ *  Reference to the socket.
+ * @param how
+ *  The flag to specify the means of shuting down the socket.
+ */
+typedef int (*posix_socket_shutdown_func_t)(struct posix_socket_driver *d,
+          void *sock, int how);
+
+
+/**
+ * Get name of connected peer socket.
+ *
+ * @param driver
+ *  The socket driver.
+ * @param sock
+ *  Reference to the socket.
+ * @param addr
+ *  The assigned address.
+ * @param addr_len
+ *  Specifies the size, in bytes, of the address structure pointed to by addr.
+ */
+typedef int (*posix_socket_getpeername_func_t)(struct posix_socket_driver *d,
+          void *sock, struct sockaddr *restrict addr,
+          socklen_t *restrict addr_len);
+
+
+/**
+ * Get socket name.
+ *
+ * @param driver
+ *  The socket driver.
+ * @param sock
+ *  Reference to the socket.
+ * @param addr
+ *  The assigned address.
+ * @param addr_len
+ *  Specifies the size, in bytes, of the address structure pointed to by addr.
+ */
+typedef int (*posix_socket_getsockname_func_t)(struct posix_socket_driver *d,
+          void *sock, struct sockaddr *restrict addr,
+          socklen_t *restrict addr_len);
+
+/**
+ * Get socket name.
+ *
+ * @param driver
+ *  The socket driver.
+ * @param sock
+ *  Reference to the socket.
+ * @param addr
+ *  The assigned address.
+ * @param addr_len
+ *  Specifies the size, in bytes, of the address structure pointed to by addr.
+ */
+typedef int (*posix_socket_getnameinfo_func_t)(struct posix_socket_driver *d,
+          const struct sockaddr *restrict sa, socklen_t sl, char *restrict node,
+          socklen_t nodelen, char *restrict serv, socklen_t servlen, int flags);
+
+/**
+ * Get options on the socket.
+ *
+ * @param driver
+ *  The socket driver.
+ * @param sock
+ *  Reference to the socket.
+ * @param level
+ *  Maniipulate the socket at either the API level or protocol level.
+ * @param optname
+ *  Any specified options are passed uninterpreted to the appropriate protocol
+ *  module for interpretation.
+ * @param optval
+ *  The option value.
+ * @param optlen
+ *  The option value length.
+ */
+typedef int (*posix_socket_getsockopt_func_t)(struct posix_socket_driver *d,
+          void *sock, int level, int optname, void *restrict optval,
+          socklen_t *restrict optlen);
+
+
+/**
+ * Set options on the socket.
+ *
+ * @param driver
+ *  The socket driver.
+ * @param sock
+ *  Reference to the socket.
+ * @param level
+ *  Maniipulate the socket at either the API level or protocol level.
+ * @param optname
+ *  Any specified options are passed uninterpreted to the appropriate protocol
+ *  module for interpretation.
+ * @param optval
+ *  The option value.
+ * @param optlen
+ *  The option value length.
+ */
+typedef int (*posix_socket_setsockopt_func_t)(struct posix_socket_driver *d,
+          void *sock, int level, int optname, const void *optval,
+          socklen_t optlen);
+
+
+/**
+ * Initiate a connection on a socket.
+ *
+ * @param driver
+ *  The socket driver.
+ * @param sock
+ *  Reference to the socket.
+ * @param addr
+ *  The address to connect to on the socket.
+ * @param addr_len
+ *  Specifies the size, in bytes, of the address structure pointed to by addr.
+ */
+typedef int (*posix_socket_connect_func_t)(struct posix_socket_driver *d,
+          void *sock, const struct sockaddr *addr, socklen_t addr_len);
+
+
+/**
+ * Listen for connections on a socket.
+ *
+ * @param driver
+ *  The socket driver.
+ * @param sock
+ *  Reference to the socket.
+ * @param backlog
+ *  Defines the maximum length to which the queue of pending connections for 
+ *  the socket.
+ */
+typedef int (*posix_socket_listen_func_t)(struct posix_socket_driver *d,
+          void *sock, int backlog);
+
+
+/**
+ * Receive a message from a socket.
+ *
+ * @param driver
+ *  The socket driver.
+ * @param sock
+ *  Reference to the socket.
+ * @param buf
+ *  The buffer for recieved data from the socket.
+ * @param len
+ *  The size of the buffer.
+ * @param flags
+ *  Bitwise OR of zero or more flags for the socket.
+ */
+typedef ssize_t (*posix_socket_recv_func_t)(struct posix_socket_driver *d,
+          void *sock, void *buf, size_t len, int flags);
+
+
+/**
+ * Read from a socket.
+ *
+ * @param driver
+ *  The socket driver.
+ * @param sock
+ *  Reference to the socket.
+ * @param buf
+ *  The buffer for recieved data from the socket.
+ * @param len
+ *  The size of the buffer.
+ * @param flags
+ *  Bitmap of options for receiving a message.
+ * @param from
+ *  The source address.
+ * @param fromlen
+ *  The source address length.
+ */
+typedef ssize_t (*posix_socket_recvfrom_func_t)(struct posix_socket_driver *d,
+          void *sock, void *restrict buf, size_t len, int flags,
+          struct sockaddr *from, socklen_t *restrict fromlen);
+
+
+/**
+ * Read from a socket.
+ *
+ * @param driver
+ *  The socket driver.
+ * @param sock
+ *  Reference to the socket.
+ * @param msg
+ *  Message structure to minimize the number of directly supplied arguments.
+ * @param flags
+ *  Bitwise OR of zero or more flags for the socket.
+ */
+typedef ssize_t (*posix_socket_recvmsg_func_t)(struct posix_socket_driver *d,
+          void *sock, struct msghdr *msg, int flags);
+
+
+/**
+ * Send a message on a socket.
+ *
+ * @param driver
+ *  The socket driver.
+ * @param sock
+ *  Reference to the socket.
+ * @param buf
+ *  The buffer for sending data to the socket.
+ * @param len
+ *  The length of the data to send on the socket.
+ * @param flags
+ *  Bitwise OR of zero or more flags for the socket.
+ */
+typedef ssize_t (*posix_socket_send_func_t)(struct posix_socket_driver *d,
+          void *sock, const void *buf, size_t len, int flags);
+
+
+/**
+ * Send a message on a socket.
+ *
+ * @param driver
+ *  The socket driver.
+ * @param sock
+ *  Reference to the socket.
+ * @param msg
+ *  Message structure to minimize the number of directly supplied arguments.
+ * @param flags
+ *  Bitwise OR of zero or more flags for the socket.
+ */
+typedef ssize_t (*posix_socket_sendmsg_func_t)(struct posix_socket_driver *d,
+          void *sock, const struct msghdr *msg, int flags);
+
+
+/**
+ * Send a message on a socket.
+ *
+ * @param driver
+ *  The socket driver.
+ * @param sock
+ *  Reference to the socket.
+ * @param buf
+ *  The buffer for sending data to the socket.
+ * @param len
+ *  The length of the data to send on the socket.
+ * @param flags
+ *  Bitwise OR of zero or more flags for the socket.
+ * @param dest_addr
+ *  The destination address to send data.
+ * @param addrlen
+ *  The length of the address to send data to.
+ */
+typedef ssize_t (*posix_socket_sendto_func_t)(struct posix_socket_driver *d,
+          void *sock, const void *buf, size_t len, int flags,
+          const struct sockaddr *dest_addr, socklen_t addrlen);
+
+
+/**
+ * Create a pair of connected sockets.
+ *
+ * @param driver
+ *  The socket driver.
+ * @param family
+ *  The domain of the sockets.
+ * @param type
+ *  The specified type of the sockets.
+ * @param protocol
+ *  Optionally the protocol.
+ * @param usockvec
+ *  The structure used in referencing the new sockets are returned in
+ *  usockvec[0] and usockvec[1].
+ */
+typedef int (*posix_socket_socketpair_func_t)(struct posix_socket_driver *d,
+          int family, int type, int protocol, void **usockvec);
+
+
+/**
+ * Read from a socket file descriptor.
+ *
+ * @param driver
+ *  The socket driver.
+ * @param buf
+ *  The buffer to read the data from the socket into.
+ * @param count
+ *  The number of bytes to be read.
+ */
+typedef int (*posix_socket_read_func_t)(struct posix_socket_driver *d,
+          void *sock, void *buf, size_t count);
+
+
+/**
+ * Write to a socket file descriptor.
+ *
+ * @param driver
+ *  The socket driver.
+ * @param buf
+ *  The pointer to the buffer to write to the socket.
+ * @param count
+ *  The number of bytes to be written.
+ */
+typedef int (*posix_socket_write_func_t)(struct posix_socket_driver *d,
+          void *sock, const void *buf, size_t count);
+
+/**
+ * Close the socket.
+ *
+ * @param driver
+ *  The socket driver.
+ * @param sock
+ *  Reference to the socket.
+ */
+typedef int (*posix_socket_close_func_t)(struct posix_socket_driver *d,
+          void *sock);
+
+
+/**
+ * Manipulate the socket.
+ *
+ * @param driver
+ *  The socket driver.
+ * @TODO
+ */
+typedef int (*posix_socket_ioctl_func_t)(struct posix_socket_driver *d,
+          void *sock, int request, void *argp);
+
+
+/**
+ * A structure containing the functions exported by the Unikraft socket driver
+ */
+struct posix_socket_ops {
+  /* The initialization function on socket registration. */
+  posix_socket_driver_init_func_t   init;
+  /* POSIX interfaces */
+  posix_socket_create_func_t        create;
+  posix_socket_accept_func_t        accept;
+  posix_socket_bind_func_t          bind;
+  posix_socket_shutdown_func_t      shutdown;
+  posix_socket_getpeername_func_t   getpeername;
+  posix_socket_getsockname_func_t   getsockname;
+  posix_socket_getnameinfo_func_t   getnameinfo;
+  posix_socket_getsockopt_func_t    getsockopt;
+  posix_socket_setsockopt_func_t    setsockopt;
+  posix_socket_connect_func_t       connect;
+  posix_socket_listen_func_t        listen;
+  posix_socket_recv_func_t          recv;
+  posix_socket_recvfrom_func_t      recvfrom;
+  posix_socket_recvmsg_func_t       recvmsg;
+  posix_socket_send_func_t          send;
+  posix_socket_sendmsg_func_t       sendmsg;
+  posix_socket_sendto_func_t        sendto;
+  posix_socket_socketpair_func_t    socketpair;
+  /* vfscore ops */
+  posix_socket_read_func_t          read;
+  posix_socket_write_func_t         write;
+  posix_socket_close_func_t         close;
+  posix_socket_ioctl_func_t         ioctl;
+};
+
+static inline void *
+posix_socket_do_create(struct posix_socket_driver *d,
+          int family, int type, int protocol)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops->create);
+  return d->ops->create(d, family, type, protocol);
+}
+
+static inline void *
+posix_socket_create(struct posix_socket_driver *d,
+          int family, int type, int protocol)
+{
+  if (unlikely(!d))
+    return NULL;
+
+  return posix_socket_do_create(d, family, type, protocol);
+}
+
+static inline void *
+posix_socket_do_accept(struct posix_socket_driver *d,
+          void *sock, struct sockaddr *restrict addr,
+          socklen_t *restrict addr_len)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops->accept);
+  return d->ops->accept(d, sock, addr, addr_len);
+}
+
+static inline void *
+posix_socket_accept(struct posix_socket_driver *d,
+          void *sock, struct sockaddr *restrict addr,
+          socklen_t *restrict addr_len)
+{
+  if (unlikely(!d))
+    return NULL;
+
+  return posix_socket_do_accept(d, sock, addr, addr_len);
+}
+
+
+static inline int
+posix_socket_do_bind(struct posix_socket_driver *d,
+          void *sock, const struct sockaddr *addr, socklen_t addr_len)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops->bind);
+  return d->ops->bind(d, sock, addr, addr_len);
+}
+
+static inline int
+posix_socket_bind(struct posix_socket_driver *d,
+          void *sock, const struct sockaddr *addr, socklen_t addr_len)
+{
+  if (unlikely(!d))
+    return -ENOSYS;
+
+  return posix_socket_do_bind(d, sock, addr, addr_len);
+}
+
+
+static inline int
+posix_socket_do_shutdown(struct posix_socket_driver *d,
+          void *sock, int how)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops->shutdown);
+	return d->ops->shutdown(d, sock, how);
+}
+
+static inline int
+posix_socket_shutdown(struct posix_socket_driver *d,
+          void *sock, int how)
+{
+  if (unlikely(!d))
+    return -ENOSYS;
+
+  return posix_socket_do_shutdown(d, sock, how);
+}
+
+
+static inline int
+posix_socket_do_getpeername(struct posix_socket_driver *d,
+          void *sock, struct sockaddr *restrict addr,
+          socklen_t *restrict addr_len)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops->getpeername);
+	return d->ops->getpeername(d, sock, addr, addr_len);
+}
+
+static inline int
+posix_socket_getpeername(struct posix_socket_driver *d,
+          void *sock, struct sockaddr *restrict addr,
+          socklen_t *restrict addr_len)
+{
+  if (unlikely(!d))
+    return -ENOSYS;
+
+  return posix_socket_do_getpeername(d, sock, addr, addr_len);
+}
+
+
+static inline int
+posix_socket_do_getsockname(struct posix_socket_driver *d,
+          void *sock, struct sockaddr *restrict addr,
+          socklen_t *restrict addr_len)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops->getsockname);
+	return d->ops->getsockname(d, sock, addr, addr_len);
+}
+
+static inline int
+posix_socket_getsockname(struct posix_socket_driver *d,
+          void *sock, struct sockaddr *restrict addr,
+          socklen_t *restrict addr_len)
+{
+  if (unlikely(!d))
+    return -ENOSYS;
+
+  return posix_socket_do_getsockname(d, sock, addr, addr_len);
+}
+
+
+static inline int
+posix_socket_do_getnameinfo(struct posix_socket_driver *d,
+          const struct sockaddr *restrict sa, socklen_t sl, char *restrict node,
+          socklen_t nodelen, char *restrict serv, socklen_t servlen, int flags)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops->getnameinfo);
+	return d->ops->getnameinfo(d, sa, sl, node, nodelen, serv, servlen, flags);
+}
+
+static inline int
+posix_socket_getnameinfo(struct posix_socket_driver *d,
+          const struct sockaddr *restrict sa, socklen_t sl, char *restrict node,
+          socklen_t nodelen, char *restrict serv, socklen_t servlen, int flags)
+{
+  if (unlikely(!d))
+    return -ENOSYS;
+
+  return posix_socket_do_getnameinfo(d, sa, sl, node, nodelen, serv, servlen,
+          flags);
+}
+
+
+static inline int
+posix_socket_do_getsockopt(struct posix_socket_driver *d,
+          void *sock, int level, int optname, void *restrict optval,
+          socklen_t *restrict optlen)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops->getsockopt);
+  return d->ops->getsockopt(d, sock, level, optname, optval, optlen);
+}
+
+static inline int
+posix_socket_getsockopt(struct posix_socket_driver *d,
+          void *sock, int level, int optname, void *restrict optval,
+          socklen_t *restrict optlen)
+{
+  if (unlikely(!d))
+    return -ENOSYS;
+
+  return posix_socket_do_getsockopt(d, sock, level, optname, optval, optlen);
+}
+
+
+static inline int
+
+posix_socket_do_setsockopt(struct posix_socket_driver *d,
+          void *sock, int level, int optname, const void *optval,
+          socklen_t optlen)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops->setsockopt);
+  return d->ops->setsockopt(d, sock, level, optname, optval, optlen);
+}
+
+static inline int
+posix_socket_setsockopt(struct posix_socket_driver *d,
+          void *sock, int level, int optname, const void *optval,
+          socklen_t optlen)
+{
+  if (unlikely(!d))
+    return -ENOSYS;
+
+  return posix_socket_do_setsockopt(d, sock, level, optname, optval, optlen);
+}
+
+
+static inline int
+posix_socket_do_connect(struct posix_socket_driver *d,
+          void *sock, const struct sockaddr *addr, socklen_t addr_len)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops->connect);
+  return d->ops->connect(d, sock, addr, addr_len);
+}
+
+static inline int
+posix_socket_connect(struct posix_socket_driver *d,
+          void *sock, const struct sockaddr *addr, socklen_t addr_len)
+{
+  if (unlikely(!d))
+    return -ENOSYS;
+
+  return posix_socket_do_connect(d, sock, addr, addr_len);
+}
+
+
+static inline int
+posix_socket_do_listen(struct posix_socket_driver *d,
+          void *sock, int backlog)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops->listen);
+  return d->ops->listen(d, sock, backlog);
+}
+
+static inline int
+posix_socket_listen(struct posix_socket_driver *d,
+          void *sock, int backlog)
+{
+  if (unlikely(!d))
+    return -ENOSYS;
+
+  return posix_socket_do_listen(d, sock, backlog);
+}
+
+
+static inline ssize_t
+posix_socket_do_recv(struct posix_socket_driver *d,
+          void *sock, void *buf, size_t len, int flags)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops->recv);
+  return d->ops->recv(d, sock, buf, len, flags);
+}
+
+static inline ssize_t
+posix_socket_recv(struct posix_socket_driver *d,
+          void *sock, void *buf, size_t len, int flags)
+{
+  if (unlikely(!d))
+    return -ENOSYS;
+
+  return posix_socket_do_recv(d, sock, buf, len, flags);
+}
+
+
+static inline ssize_t
+posix_socket_do_recvfrom(struct posix_socket_driver *d,
+          void *sock, void *buf, size_t len, int flags, struct sockaddr *from, 
+          socklen_t *fromlen)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops->recvfrom);
+  return d->ops->recvfrom(d, sock, buf, len, flags, from, fromlen);
+}
+
+static inline ssize_t
+posix_socket_recvfrom(struct posix_socket_driver *d,
+          void *sock, void *restrict buf, size_t len, int flags,
+          struct sockaddr *from, socklen_t *fromlen)
+{
+  if (unlikely(!d))
+    return -ENOSYS;
+
+  return posix_socket_do_recvfrom(d, sock, buf, len, flags, from, fromlen);
+}
+
+
+static inline ssize_t
+posix_socket_do_recvmsg(struct posix_socket_driver *d,
+          void *sock, struct msghdr *msg, int flags)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops->recvmsg);
+  return d->ops->recvmsg(d, sock, msg, flags);
+}
+
+static inline ssize_t
+posix_socket_recvmsg(struct posix_socket_driver *d,
+          void *sock, struct msghdr *msg, int flags)
+{
+  if (unlikely(!d))
+    return -ENOSYS;
+
+  return posix_socket_do_recvmsg(d, sock, msg, flags);
+}
+
+
+static inline ssize_t
+posix_socket_do_send(struct posix_socket_driver *d,
+          void *sock, const void *buf, size_t len, int flags)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops->send);
+  return d->ops->send(d, sock, buf, len, flags);
+}
+
+static inline ssize_t
+posix_socket_send(struct posix_socket_driver *d,
+          void *sock, const void *buf, size_t len, int flags)
+{
+  if (unlikely(!d))
+    return -ENOSYS;
+
+  return posix_socket_do_send(d, sock, buf, len, flags);
+}
+
+
+static inline ssize_t
+posix_socket_do_sendmsg(struct posix_socket_driver *d,
+          void *sock, const struct msghdr *msg, int flags)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops->sendmsg);
+  return d->ops->sendmsg(d, sock, msg, flags);
+}
+
+static inline ssize_t
+posix_socket_sendmsg(struct posix_socket_driver *d,
+          void *sock, const struct msghdr *msg, int flags)
+{
+  if (unlikely(!d))
+    return -ENOSYS;
+
+  return posix_socket_do_sendmsg(d, sock, msg, flags);
+}
+
+
+static inline ssize_t
+posix_socket_do_sendto(struct posix_socket_driver *d,
+          void *sock, const void *buf, size_t len, int flags,
+          const struct sockaddr *dest_addr, socklen_t addrlen)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops->sendto);
+  return d->ops->sendto(d, sock, buf, len, flags, dest_addr, addrlen);
+}
+
+static inline ssize_t
+posix_socket_sendto(struct posix_socket_driver *d,
+          void *sock, const void *buf, size_t len, int flags,
+          const struct sockaddr *dest_addr, socklen_t addrlen)
+{
+  if (unlikely(!d))
+    return -ENOSYS;
+
+  return posix_socket_do_sendto(d, sock, buf, len, flags, dest_addr, addrlen);
+}
+
+
+static inline int
+posix_socket_do_socketpair(struct posix_socket_driver *d,
+          int family, int type, int protocol, void **usockvec)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops->socketpair);
+  return d->ops->socketpair(d, family, type, protocol, usockvec);
+}
+
+static inline int
+posix_socket_socketpair(struct posix_socket_driver *d,
+          int family, int type, int protocol, void **usockvec)
+{
+  if (unlikely(!d))
+    return -ENOSYS;
+
+  return posix_socket_do_socketpair(d, family, type, protocol, usockvec);
+}
+
+
+static inline int
+posix_socket_do_read(struct posix_socket_driver *d,
+          void *sock, void *buf, size_t count)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops->read);
+  return d->ops->read(d, sock, buf, count);
+}
+
+static inline int
+posix_socket_read(struct posix_socket_driver *d,
+          void *sock, void *buf, size_t count)
+{
+  if (unlikely(!d))
+    return -ENOSYS;
+
+  return posix_socket_do_read(d, sock, buf, count);
+}
+
+
+static inline int
+posix_socket_do_write(struct posix_socket_driver *d,
+          void *sock, const void *buf, size_t count)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops->write);
+  return d->ops->write(d, sock, buf, count); 
+}
+
+static inline int
+posix_socket_write(struct posix_socket_driver *d,
+          void *sock, const void *buf, size_t count)
+{
+  if (unlikely(!d))
+    return -ENOSYS;
+
+  return posix_socket_do_write(d, sock, buf, count);
+}
+
+
+static inline int
+posix_socket_do_close(struct posix_socket_driver *d,
+          void *sock)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops->close);
+  return d->ops->close(d, sock);
+}
+
+static inline int
+posix_socket_close(struct posix_socket_driver *d,
+          void *sock)
+{
+  if (unlikely(!d))
+    return -ENOSYS;
+
+  return posix_socket_do_close(d, sock);
+}
+
+
+static inline int
+posix_socket_do_ioctl(struct posix_socket_driver *d,
+          void *sock, int request, void *argp)
+{
+  UK_ASSERT(d);
+  UK_ASSERT(d->ops->ioctl);
+  return d->ops->ioctl(d, sock, request, argp);
+}
+
+static inline int
+posix_socket_ioctl(struct posix_socket_driver *d,
+          void *sock, int request, void *argp)
+{
+  if (unlikely(!d))
+    return -ENOSYS;
+
+  return posix_socket_do_ioctl(d, sock, request, argp);
+}
+
+/**
+ * Return the driver to the corresponding AF family number
+ *
+ * @param af_family
+ *  Af family number
+ */
+struct posix_socket_driver *
+posix_socket_driver_get(int af_family);
+
+/**
+ * Shortcut for doing a registration a socket to an AF number.
+ */
+#define new_posix_socket_family(d, fam, alloc, ops) \
+  do {                                              \
+    (d)->allocator = (alloc);                       \
+    (d)->ops       = (ops);                         \
+  } while(0)
+
+/**
+ * Returns the number of registered sockets.
+ */
+unsigned int
+posix_socket_family_count(void);
+
+/* Do not use this function directly */
+void
+_posix_socket_family_register(struct posix_socket_driver *d,
+          int fam,
+          struct posix_socket_ops *ops,
+          struct uk_alloc *alloc);
+
+/**
+ * Registers a socket family driver to the socket system.
+ */
+#define _POSIX_SOCKET_FAMILY_REGISTER_CTOR(fam, ctor) \
+  UK_CTOR_PRIO(ctor, POSIX_SOCKET_FAMILY_REGISTER_PRIO)
+
+#define _POSIX_SOCKET_FAMILY_REGFNNAME(x, y) x##_posix_socket_af_##y##_register
+#define _POSIX_SOCKET_FAMILY_DRVRNAME(x, y) x##_posix_socket_af_##y
+
+/*
+ * Creates a static struct posix_socket_driver with a unique name for the AF
+ * family which can later be referenced.
+ */
+#define _POSIX_SOCKET_FAMILY_REGISTER(lib, fam, ops, alloc)                     \
+  static struct posix_socket_driver _POSIX_SOCKET_FAMILY_DRVRNAME(lib, fam) = { \
+    .af_family = fam,                                                           \
+    .libname   = STRINGIFY(lib)                                                 \
+  };                                                                            \
+  static void                                                                   \
+  _POSIX_SOCKET_FAMILY_REGFNNAME(lib, fam)(void)                                \
+  {                                                                             \
+    _posix_socket_family_register(&_POSIX_SOCKET_FAMILY_DRVRNAME(lib, fam),     \
+        fam, ops, alloc);                                                       \
+  }                                                                             \
+  _POSIX_SOCKET_FAMILY_REGISTER_CTOR(fam, _POSIX_SOCKET_FAMILY_REGFNNAME(lib, fam))
+
+#define POSIX_SOCKET_FAMILY_REGISTER(fam, ops, alloc) \
+  _POSIX_SOCKET_FAMILY_REGISTER(__LIBNAME__, fam, ops, alloc)
+
+/* Do not use this function directly: */
+void
+_posix_socket_family_unregister(struct posix_socket_driver *driver);
+
+#ifdef __cplusplus
+}
+
+#endif /* __cplusplus */
+#endif /*  __UK_SOCKET_DRIVER_H__ */
\ No newline at end of file
diff --git a/lib/posix-socket/include/uk/socket_vnops.h b/lib/posix-socket/include/uk/socket_vnops.h
new file mode 100644
index 0000000..243622a
--- /dev/null
+++ b/lib/posix-socket/include/uk/socket_vnops.h
@@ -0,0 +1,97 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Alexander Jung <alexander.jung@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation.
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __UK_SOCKET_VNOPS__
+#define __UK_SOCKET_VNOPS__
+
+#include <vfscore/file.h>
+#include <vfscore/vnode.h>
+
+struct posix_socket_driver;
+
+#define POSIX_SOCKET_SET_ERRNO(errcode) \
+  (errno = -(errcode))
+
+#define SOCKFILE_DATA_AS_INT(data) \
+  *((int *) data)
+
+struct posix_socket_file {
+  /* The fd or data used internaly by the socket implementation. */
+  void *sock_data;
+  /* Internal reference to the vfscore_file when not geenerally available. */
+	struct vfscore_file *vfs_file;
+  /* The driver to use for this socket. */
+  struct posix_socket_driver *driver;
+};
+
+int
+posix_socket_vfscore_close(struct vnode *s_vnode,
+          struct vfscore_file *vfscore_file);
+    
+int
+posix_socket_vfscore_read(struct vnode *s_vnode,
+          struct vfscore_file *vfscore_file __unused,
+          struct uio *buf, int ioflag __unused);
+int
+posix_socket_vfscore_write(struct vnode *s_vnode,
+          struct uio *buf, int ioflag __unused);
+int
+posix_socket_vfscore_ioctl(struct vnode *s_vnode,
+          struct vfscore_file *vfscore_file __unused,
+          unsigned long request,
+          void *buf);
+
+/**
+ *
+ */
+struct posix_socket_file *
+posix_socket_file_get(int sock_fd);
+
+/**
+ * 
+ */
+struct posix_socket_driver *
+posix_socket_get_family(int sock_fd);
+
+/**
+ * Allocate a file descriptor in vfscore for the given socket driver.
+ *
+ * @param d
+ *  The driver used to create the socket.
+ * @param sock_data
+ *  The socket implementation's private data.
+ */
+int
+socket_alloc_fd(struct posix_socket_driver *d, void *sock_data);
+
+#endif /* __UK_SOCKET_VNOPS__ */
diff --git a/lib/posix-socket/socket.c b/lib/posix-socket/socket.c
new file mode 100644
index 0000000..9634e29
--- /dev/null
+++ b/lib/posix-socket/socket.c
@@ -0,0 +1,722 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Alexander Jung <alexander.jung@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation.
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <uk/socket.h>
+#include <uk/errptr.h>
+#include <uk/print.h>
+#include <uk/trace.h>
+#include <errno.h>
+
+UK_TRACEPOINT(trace_posix_socket_create, "%d %d %d", int, int, int);
+UK_TRACEPOINT(trace_posix_socket_create_ret, "%d", int);
+UK_TRACEPOINT(trace_posix_socket_create_err, "%d", int);
+
+int
+socket(int family, int type, int protocol)
+{
+  int ret = 0;
+  int vfs_fd = 0xff;
+  void *sock = NULL;
+  struct posix_socket_driver *d;
+
+  trace_posix_socket_create(family, type, protocol);
+
+  d = posix_socket_driver_get(family);
+  if (d == NULL) {
+    uk_pr_crit("no socket implementation for family: %d\n", family);
+    ret = -ENOSYS;
+    goto EXIT_ERR;
+  }
+
+  /* Create the socket using the driver */
+  sock = posix_socket_create(d, family, type, protocol);
+  if (sock == NULL) {
+    uk_pr_debug("failed to create socket %d\n", errno);
+    ret = -1;
+    goto EXIT_ERR;
+  }
+
+  /* Allocate the file descriptor */
+  vfs_fd = socket_alloc_fd(d, sock);
+  if (vfs_fd < 0) {
+    uk_pr_debug("failed to allocate descriptor %d\n", errno);
+    ret = -1;
+    POSIX_SOCKET_SET_ERRNO(vfs_fd);
+    goto SOCKET_CLEANUP;
+  }
+
+  /* Returning the file descriptor to the user */
+  ret = vfs_fd;
+
+EXIT:
+  trace_posix_socket_create_ret(ret);
+  return ret;
+EXIT_ERR:
+  trace_posix_socket_create_err(ret);
+  return ret;
+SOCKET_CLEANUP:
+  posix_socket_close(d, sock);
+  goto EXIT;
+}
+
+UK_TRACEPOINT(trace_posix_socket_accept, "%d %p %p", int,
+          struct sockaddr *restrict, socklen_t *restrict);
+UK_TRACEPOINT(trace_posix_socket_accept_ret, "%d", int);
+UK_TRACEPOINT(trace_posix_socket_accept_err, "%d", int);
+
+int accept(int sock, struct sockaddr *restrict addr,
+          socklen_t *restrict addr_len)
+{
+  int vfs_fd;
+  int ret = 0;
+  void *new_sock;
+	struct posix_socket_file *file;
+
+  trace_posix_socket_accept(sock, addr, addr_len);
+
+	file = posix_socket_file_get(sock);
+	if (PTRISERR(file)) {
+		uk_pr_debug("failed to retrieve socket file descriptor: %p\n", file);
+		ret = -1;
+		POSIX_SOCKET_SET_ERRNO(PTR2ERR(file));
+		goto EXIT;
+	}
+
+	/* Accept an incoming connection */
+	new_sock = posix_socket_accept(file->driver, file->sock_data, addr, addr_len);
+	if (new_sock == NULL) {
+		uk_pr_debug("failed to accept incoming connection\n");
+		ret = -1;
+		goto EXIT_FDROP;
+	}
+
+	/* Allocate the file descriptor for the accepted connection */
+	vfs_fd = socket_alloc_fd(file->driver, new_sock);
+	if (vfs_fd < 0) {
+		uk_pr_debug("failed to allocate descriptor for accepted connection\n");
+		ret = -1;
+		POSIX_SOCKET_SET_ERRNO(vfs_fd);
+		goto SOCKET_CLEANUP;
+	}
+
+	ret = vfs_fd;
+
+EXIT_FDROP:
+	vfscore_put_file(file->vfs_file); /* release refcount */
+  trace_posix_socket_accept_err(ret);
+  return ret;
+EXIT:
+  trace_posix_socket_accept_ret(ret);
+	return ret;
+SOCKET_CLEANUP:
+  posix_socket_close(file->driver, file->sock_data);
+	goto EXIT_FDROP;
+}
+
+UK_TRACEPOINT(trace_posix_socket_bind, "%d %p %d", int, const struct sockaddr *,
+          socklen_t);
+UK_TRACEPOINT(trace_posix_socket_bind_ret, "%d", int);
+UK_TRACEPOINT(trace_posix_socket_bind_err, "%d", int);
+
+int bind(int sock, const struct sockaddr *addr, socklen_t addr_len)
+{
+  int ret = 0;
+  struct posix_socket_file *file = NULL;
+
+  trace_posix_socket_bind(sock, addr, addr_len);
+
+  file = posix_socket_file_get(sock);
+  if (PTRISERR(file)) {
+    uk_pr_debug("failed to identify socket descriptor\n");
+    ret = -1;
+    POSIX_SOCKET_SET_ERRNO(PTR2ERR(file));
+    goto EXIT_ERR;
+  }
+
+  /* Bind an incoming connection */
+  ret = posix_socket_bind(file->driver, file->sock_data, addr, addr_len);
+
+  /* release refcount */
+  vfscore_put_file(file->vfs_file);
+  
+  if (ret < 0) {
+    uk_pr_debug("driver:%s failed to bind with socket\n", file->driver->libname);
+    goto EXIT_ERR;
+  }
+
+  trace_posix_socket_bind_ret(ret);
+  return ret;
+EXIT_ERR:
+  trace_posix_socket_bind_err(ret);
+  return ret;
+}
+
+UK_TRACEPOINT(trace_posix_socket_shutdown, "%d %d", int, int);
+UK_TRACEPOINT(trace_posix_socket_shutdown_ret, "%d", int);
+UK_TRACEPOINT(trace_posix_socket_shutdown_err, "%d", int);
+
+int shutdown(int sock, int how)
+{
+  int ret = 0;
+  struct posix_socket_file *file = NULL;
+
+  trace_posix_socket_shutdown(sock, how);
+
+  file = posix_socket_file_get(sock);
+  if (PTRISERR(file)) {
+    uk_pr_debug("failed to identify socket descriptor\n");
+    ret = -1;
+    POSIX_SOCKET_SET_ERRNO(PTR2ERR(file));
+    goto EXIT_ERR;
+  }
+
+  /* Shutdown socket */
+  ret = posix_socket_shutdown(file->driver, file->sock_data, how);
+
+  /* release refcount */
+  vfscore_put_file(file->vfs_file);
+
+  if (ret < 0) {
+    uk_pr_debug("driver:%s failed to shutdown socket:%p\n",
+          file->driver->libname, file->sock_data);
+    goto EXIT_ERR;
+  }
+
+  trace_posix_socket_shutdown_ret(ret);
+  return ret;
+EXIT_ERR:
+  trace_posix_socket_shutdown_err(ret);
+  return ret;
+}
+
+UK_TRACEPOINT(trace_posix_socket_getpeername, "%d %p %d", int,
+          struct sockaddr *restrict, socklen_t *restrict);
+UK_TRACEPOINT(trace_posix_socket_getpeername_ret, "%d", int);
+UK_TRACEPOINT(trace_posix_socket_getpeername_err, "%d", int);
+
+int getpeername(int sock, struct sockaddr *restrict addr,
+          socklen_t *restrict addr_len)
+{
+  int ret = 0;
+  struct posix_socket_file *file = NULL;
+
+  trace_posix_socket_getpeername(sock, addr, addr_len);
+
+  file = posix_socket_file_get(sock);
+  if (PTRISERR(file)) {
+    uk_pr_debug("failed to identify socket descriptor\n");
+    ret = -1;
+    POSIX_SOCKET_SET_ERRNO(PTR2ERR(file));
+    goto EXIT_ERR;
+  }
+
+  /* Get peern name of socket */
+  ret = posix_socket_getpeername(file->driver, file->sock_data, addr, addr_len);
+
+  /* release refcount */
+  vfscore_put_file(file->vfs_file);
+
+  if (ret < 0) {
+    uk_pr_debug("driver:%s failed to getpeername of socket\n", file->driver->libname);
+    goto EXIT_ERR;
+  }
+
+  trace_posix_socket_getpeername_ret(ret);
+  return ret;
+EXIT_ERR:
+  trace_posix_socket_getpeername_err(ret);
+  return ret;
+}
+
+UK_TRACEPOINT(trace_posix_socket_getsockname, "%d %p %p", int,
+          struct sockaddr *restrict, socklen_t *restrict);
+UK_TRACEPOINT(trace_posix_socket_getsockname_ret, "%d", int);
+UK_TRACEPOINT(trace_posix_socket_getsockname_err, "%d", int);
+
+int getsockname(int sock, struct sockaddr *restrict addr,
+          socklen_t *restrict addr_len)
+{
+  int ret = 0;
+  struct posix_socket_file *file = NULL;
+
+  trace_posix_socket_getsockname(sock, addr, addr_len);
+
+  file = posix_socket_file_get(sock);
+  if (PTRISERR(file)) {
+    uk_pr_debug("failed to identify socket descriptor\n");
+    ret = -1;
+    POSIX_SOCKET_SET_ERRNO(PTR2ERR(file));
+    goto EXIT_ERR;
+  }
+
+  /* Get socket name of socket */
+  ret = posix_socket_getsockname(file->driver, file->sock_data, addr, addr_len);
+
+  /* release refcount */
+  vfscore_put_file(file->vfs_file);
+
+  if (ret < 0) {
+    uk_pr_debug("driver:%s failed to getsockname of socket:%p\n",
+          file->driver->libname, file->sock_data);
+    goto EXIT_ERR;
+  }
+
+  trace_posix_socket_getsockname_ret(ret);
+  return ret;
+EXIT_ERR:
+  trace_posix_socket_getsockname_err(ret);
+  return ret;
+}
+
+UK_TRACEPOINT(trace_posix_socket_getsockopt, "%d %d %d %p %d", int, int, int,
+          void *, socklen_t *);
+UK_TRACEPOINT(trace_posix_socket_getsockopt_ret, "%d", int);
+UK_TRACEPOINT(trace_posix_socket_getsockopt_err, "%d", int);
+
+int getsockopt(int sock, int level, int optname, void *restrict optval,
+          socklen_t *restrict optlen)
+{
+  int ret = 0;
+  struct posix_socket_file *file = NULL;
+
+  trace_posix_socket_getsockopt(sock, level, optname, optval, optlen);
+
+  file = posix_socket_file_get(sock);
+  if (PTRISERR(file)) {
+    uk_pr_debug("failed to identify socket descriptor\n");
+    ret = -1;
+    POSIX_SOCKET_SET_ERRNO(PTR2ERR(file));
+    goto EXIT_ERR;
+  }
+
+  /* Get socket options */
+  ret = posix_socket_getsockopt(file->driver, file->sock_data, level, optname,
+          optval, optlen);
+
+  /* release refcount */
+  vfscore_put_file(file->vfs_file);
+
+  if (ret < 0) {
+    uk_pr_debug("driver:%s failed to getsockopt of socket:%p\n",
+          file->driver->libname, file->sock_data);
+    goto EXIT_ERR;
+  }
+
+  trace_posix_socket_getsockopt_ret(ret);
+  return ret;
+EXIT_ERR:
+  trace_posix_socket_getsockopt_err(ret);
+  return ret;
+}
+
+UK_TRACEPOINT(trace_posix_socket_setsockopt, "%d %d %d %p %d", int, int, int,
+          const void *, socklen_t);
+UK_TRACEPOINT(trace_posix_socket_setsockopt_ret, "%d", int);
+UK_TRACEPOINT(trace_posix_socket_setsockopt_err, "%d", int);
+
+int setsockopt(int sock, int level, int optname, const void *optval,
+          socklen_t optlen)
+{
+  int ret = 0;
+  struct posix_socket_file *file = NULL;
+
+  trace_posix_socket_setsockopt(sock, level, optname, optval, optlen);
+
+  file = posix_socket_file_get(sock);
+  if (PTRISERR(file)) {
+    uk_pr_debug("failed to identify socket descriptor\n");
+    ret = -1;
+    POSIX_SOCKET_SET_ERRNO(PTR2ERR(file));
+    goto EXIT_ERR;
+  }
+
+  /* Set socket options */
+  ret = posix_socket_setsockopt(file->driver, file->sock_data, level, optname,
+          optval, optlen);
+
+  /* release refcount */
+  vfscore_put_file(file->vfs_file);
+
+  if (ret < 0) {
+    uk_pr_debug("driver:%s failed to setsockopt of socket:%p\n",
+          file->driver->libname, file->sock_data);
+    goto EXIT_ERR;
+  }
+
+  trace_posix_socket_setsockopt_ret(ret);
+  return ret;
+EXIT_ERR:
+  trace_posix_socket_setsockopt_err(ret);
+  return ret;
+}
+
+UK_TRACEPOINT(trace_posix_socket_getnameinfo, "%p %d %s %d %s %d %d",
+          const struct sockaddr *, socklen_t, char *, socklen_t, char *,
+          socklen_t, int);
+UK_TRACEPOINT(trace_posix_socket_getnameinfo_ret, "%d", int);
+UK_TRACEPOINT(trace_posix_socket_getnameinfo_err, "%d", int);
+
+int getnameinfo(const struct sockaddr *restrict sa, socklen_t sl,
+          char *restrict node, socklen_t nodelen, char *restrict serv,
+          socklen_t servlen, int flags)
+{
+  uk_pr_crit("%s: not implemented", __func__);
+  errno = ENOTSUP;
+  return -1;
+}
+
+UK_TRACEPOINT(trace_posix_socket_connect, "%d %p %d", int,
+          const struct sockaddr *, socklen_t);
+UK_TRACEPOINT(trace_posix_socket_connect_ret, "%d", int);
+UK_TRACEPOINT(trace_posix_socket_connect_err, "%d", int);
+
+int connect(int sock, const struct sockaddr *addr, socklen_t addr_len)
+{
+  int ret = 0;
+  struct posix_socket_file *file = NULL;
+
+  trace_posix_socket_connect(sock, addr, addr_len);
+
+  file = posix_socket_file_get(sock);
+  if (PTRISERR(file)) {
+    uk_pr_debug("failed to identify socket descriptor\n");
+    ret = -1;
+    POSIX_SOCKET_SET_ERRNO(PTR2ERR(file));
+    goto EXIT_ERR;
+  }
+
+  /* Connect to the socket */
+  ret = posix_socket_connect(file->driver, file->sock_data, addr, addr_len);
+
+  /* release refcount */
+  vfscore_put_file(file->vfs_file);
+
+  if (ret < 0) {
+    uk_pr_debug("driver:%s failed to connect to socket:%p\n",
+          file->driver->libname, file->sock_data);
+    goto EXIT_ERR;
+  }
+
+  trace_posix_socket_connect_ret(ret);
+  return ret;
+EXIT_ERR:
+  trace_posix_socket_connect_err(ret);
+  return ret;
+}
+
+UK_TRACEPOINT(trace_posix_socket_listen, "%d %d", int, int);
+UK_TRACEPOINT(trace_posix_socket_listen_ret, "%d", int);
+UK_TRACEPOINT(trace_posix_socket_listen_err, "%d", int);
+
+int listen(int sock, int backlog)
+{
+  int ret = 0;
+  struct posix_socket_file *file = NULL;
+
+  trace_posix_socket_listen(sock, backlog);
+
+  file = posix_socket_file_get(sock);
+  if (PTRISERR(file)) {
+    uk_pr_debug("failed to identify socket descriptor\n");
+    ret = -1;
+    POSIX_SOCKET_SET_ERRNO(PTR2ERR(file));
+    goto EXIT_ERR;
+  }
+
+  /* Listen to the socket */
+  ret = posix_socket_listen(file->driver, file->sock_data, backlog);
+
+  /* release refcount */
+  vfscore_put_file(file->vfs_file);
+
+  if (ret < 0) {
+    uk_pr_debug("driver:%s failed to listen to socket:%p\n",
+          file->driver->libname, file->sock_data);
+    goto EXIT_ERR;
+  }
+
+  trace_posix_socket_listen_ret(ret);
+  return ret;
+EXIT_ERR:
+  trace_posix_socket_listen_err(ret);
+  return ret;
+}
+
+UK_TRACEPOINT(trace_posix_socket_recv, "%d %p %d %d", int, void *, size_t, int);
+UK_TRACEPOINT(trace_posix_socket_recv_ret, "%d", int);
+UK_TRACEPOINT(trace_posix_socket_recv_err, "%d", int);
+
+ssize_t recv(int sock, void *buf, size_t len, int flags)
+{
+  int ret = 0;
+  struct posix_socket_file *file = NULL;
+
+  trace_posix_socket_recv(sock, buf, len, flags);
+
+  file = posix_socket_file_get(sock);
+  if (PTRISERR(file)) {
+    uk_pr_debug("failed to identify socket descriptor\n");
+    ret = -1;
+    POSIX_SOCKET_SET_ERRNO(PTR2ERR(file));
+    goto EXIT_ERR;
+  }
+
+  /* Recieve a buffer from a socket */
+  ret = posix_socket_recv(file->driver, file->sock_data, buf, len, flags);
+
+  /* release refcount */
+  vfscore_put_file(file->vfs_file);
+
+  if (ret < 0) {
+    uk_pr_debug("driver:%s failed to recv of socket:%p\n",
+          file->driver->libname, file->sock_data);
+    goto EXIT_ERR;
+  }
+
+  trace_posix_socket_recv_ret(ret);
+  return ret;
+EXIT_ERR:
+  trace_posix_socket_recv_err(ret);
+  return ret;
+}
+
+UK_TRACEPOINT(trace_posix_socket_recvfrom, "%d %p %d %d %p %p", int, void *,
+          size_t, int, struct sockaddr *, socklen_t *);
+UK_TRACEPOINT(trace_posix_socket_recvfrom_ret, "%d", int);
+UK_TRACEPOINT(trace_posix_socket_recvfrom_err, "%d", int);
+
+ssize_t recvfrom(int sock, void *buf, size_t len, int flags,
+          struct sockaddr *from, socklen_t *fromlen)
+{
+  int ret = 0;
+  struct posix_socket_file *file = NULL;
+
+  trace_posix_socket_recvfrom(sock, buf, len, flags, from, fromlen);
+
+  file = posix_socket_file_get(sock);
+  if (PTRISERR(file)) {
+    uk_pr_debug("failed to identify socket descriptor\n");
+    ret = -1;
+    POSIX_SOCKET_SET_ERRNO(PTR2ERR(file));
+    goto EXIT_ERR;
+  }
+
+  /* Recieve a buffer from a socket */
+  ret = posix_socket_recvfrom(file->driver, file->sock_data, buf, len, flags,
+          from, fromlen);
+
+  /* release refcount */
+  vfscore_put_file(file->vfs_file);
+
+  if (ret < 0) {
+    uk_pr_debug("driver:%s failed to recvfrom of socket:%p\n",
+          file->driver->libname, file->sock_data);
+    goto EXIT_ERR;
+  }
+
+  trace_posix_socket_recvfrom_ret(ret);
+  return ret;
+EXIT_ERR:
+  trace_posix_socket_recvfrom_err(ret);
+  return ret;
+}
+
+UK_TRACEPOINT(trace_posix_socket_recvmsg, "%d %p %d", int, struct msghdr*, int);
+UK_TRACEPOINT(trace_posix_socket_recvmsg_ret, "%d", int);
+UK_TRACEPOINT(trace_posix_socket_recvmsg_err, "%d", int);
+
+ssize_t recvmsg(int sock, struct msghdr *msg, int flags)
+{
+  int ret = 0;
+  struct posix_socket_file *file = NULL;
+
+  trace_posix_socket_recvmsg(sock, msg, flags);
+
+  file = posix_socket_file_get(sock);
+  if (PTRISERR(file)) {
+    uk_pr_debug("failed to identify socket descriptor\n");
+    ret = -1;
+    POSIX_SOCKET_SET_ERRNO(PTR2ERR(file));
+    goto EXIT_ERR;
+  }
+
+  /* Recieve a structured message from a socket */
+  ret = posix_socket_recvmsg(file->driver, file->sock_data, msg, flags);
+
+  /* release refcount */
+  vfscore_put_file(file->vfs_file);
+
+  if (ret < 0) {
+    uk_pr_debug("driver:%s failed to recvmsg of socket:%p\n",
+          file->driver->libname, file->sock_data);
+    goto EXIT_ERR;
+  }
+
+  trace_posix_socket_recvmsg_ret(ret);
+  return ret;
+EXIT_ERR:
+  trace_posix_socket_recvmsg_err(ret);
+  return ret;
+}
+
+UK_TRACEPOINT(trace_posix_socket_send, "%d %p %d %d", int, const void *, size_t,
+          int);
+UK_TRACEPOINT(trace_posix_socket_send_ret, "%d", int);
+UK_TRACEPOINT(trace_posix_socket_send_err, "%d", int);
+
+ssize_t send(int sock, const void *buf, size_t len, int flags)
+{
+  int ret = 0;
+  struct posix_socket_file *file = NULL;
+
+  trace_posix_socket_send(sock, buf, len, flags);
+
+  file = posix_socket_file_get(sock);
+  if (PTRISERR(file)) {
+    uk_pr_debug("failed to identify socket descriptor\n");
+    ret = -1;
+    POSIX_SOCKET_SET_ERRNO(PTR2ERR(file));
+    goto EXIT_ERR;
+  }
+
+  /* Send a structured message to a sockets */
+  ret = posix_socket_send(file->driver, file->sock_data, buf, len, flags);
+
+  /* release refcount */
+  vfscore_put_file(file->vfs_file);
+
+  if (ret < 0) {
+    uk_pr_debug("driver:%s failed to send of socket:%p\n",
+          file->driver->libname, file->sock_data);
+    goto EXIT_ERR;
+  }
+
+  trace_posix_socket_send_ret(ret);
+  return ret;
+EXIT_ERR:
+  trace_posix_socket_send_err(ret);
+  return ret;
+}
+
+UK_TRACEPOINT(trace_posix_socket_sendmsg, "%d %p %d", int, const struct msghdr*,
+          int);
+UK_TRACEPOINT(trace_posix_socket_sendmsg_ret, "%d", int);
+UK_TRACEPOINT(trace_posix_socket_sendmsg_err, "%d", int);
+
+ssize_t sendmsg(int sock, const struct msghdr *msg, int flags)
+{
+  int ret = 0;
+  struct posix_socket_file *file = NULL;
+
+  trace_posix_socket_sendmsg(sock, msg, flags);
+
+  file = posix_socket_file_get(sock);
+  if (PTRISERR(file)) {
+    uk_pr_debug("failed to identify socket descriptor\n");
+    ret = -1;
+    POSIX_SOCKET_SET_ERRNO(PTR2ERR(file));
+    goto EXIT_ERR;
+  }
+
+  /* Send a structured message to a sockets */
+  ret = posix_socket_sendmsg(file->driver, file->sock_data, msg, flags);
+
+  /* release refcount */
+  vfscore_put_file(file->vfs_file);
+
+  if (ret < 0) {
+    uk_pr_debug("driver:%s failed to sendmsg of socket:%p\n",
+          file->driver->libname, file->sock_data);
+    goto EXIT_ERR;
+  }
+
+  trace_posix_socket_sendmsg_ret(ret);
+  return ret;
+EXIT_ERR:
+  trace_posix_socket_sendmsg_err(ret);
+  return ret;
+}
+
+UK_TRACEPOINT(trace_posix_socket_sendto, "%d %p %d %d %p %d", int, const void *,
+          size_t, int, const struct sockaddr *, socklen_t);
+UK_TRACEPOINT(trace_posix_socket_sendto_ret, "%d", int);
+UK_TRACEPOINT(trace_posix_socket_sendto_err, "%d", int);
+
+ssize_t sendto(int sock, const void *buf, size_t len, int flags,
+          const struct sockaddr *dest_addr, socklen_t addrlen)
+{
+  int ret = 0;
+  struct posix_socket_file *file = NULL;
+
+  trace_posix_socket_sendto(sock, buf, len, flags, dest_addr, addrlen);
+
+  file = posix_socket_file_get(sock);
+  if (PTRISERR(file)) {
+    uk_pr_debug("failed to identify socket descriptor\n");
+    ret = -1;
+    POSIX_SOCKET_SET_ERRNO(PTR2ERR(file));
+    goto EXIT_ERR;
+  }
+
+  /* Send to an address over a socket */
+  ret = posix_socket_sendto(file->driver, file->sock_data, buf, len, flags,
+          dest_addr, addrlen);
+
+  /* release refcount */
+  vfscore_put_file(file->vfs_file);
+
+  if (ret < 0) {
+    uk_pr_debug("driver:%s failed to sendto of socket:%p\n",
+          file->driver->libname, file->sock_data);
+    goto EXIT_ERR;
+  }
+
+  trace_posix_socket_sendto_ret(ret);  
+  return ret;
+EXIT_ERR:
+  trace_posix_socket_sendto_err(ret);
+  return ret;
+}
+
+UK_TRACEPOINT(trace_posix_socket_socketpair, "%d %d %d %p", int, int, int,
+            int *);
+UK_TRACEPOINT(trace_posix_socket_socketpair_ret, "%d", int);
+UK_TRACEPOINT(trace_posix_socket_socketpair_err, "%d", int);
+
+int socketpair(int family, int type, int protocol, int *usockvec)
+{
+  uk_pr_crit("%s: not implemented", __func__);
+  errno = ENOTSUP;
+  return -1;
+}
diff --git a/lib/posix-socket/socket_vnops.c b/lib/posix-socket/socket_vnops.c
new file mode 100644
index 0000000..6409b27
--- /dev/null
+++ b/lib/posix-socket/socket_vnops.c
@@ -0,0 +1,323 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Sharan Santhanam <sharan.santhanam@neclab.eu>
+ *          Alexander Jung <alexander.jung@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation.
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <uk/socket_driver.h>
+#include <vfscore/vnode.h>
+#include <vfscore/mount.h>
+#include <vfscore/fs.h>
+#include <uk/socket_vnops.h>
+#include <uk/errptr.h>
+#include <inttypes.h>
+
+static uint64_t s_inode = 0;
+
+#define posix_socket_getattr ((vnop_getattr_t) vfscore_vop_einval)
+#define posix_socket_inactive ((vnop_inactive_t) vfscore_vop_nullop)
+
+/* vnode operations */
+struct vnops posix_socket_vnops = {
+  .vop_close = posix_socket_vfscore_close,
+  .vop_read = posix_socket_vfscore_read,
+  .vop_write = posix_socket_vfscore_write,
+  .vop_ioctl = posix_socket_vfscore_ioctl,
+  .vop_getattr = posix_socket_getattr,
+  .vop_inactive = posix_socket_inactive,
+};
+
+#define posix_socket_vget ((vfsop_vget_t) vfscore_nullop)
+
+/* file system operations */
+static struct vfsops posix_socket_vfsops = {
+  .vfs_vget = posix_socket_vget,
+  .vfs_vnops = &posix_socket_vnops,
+};
+
+/* bogus mount point used by all sockets */
+static struct mount posix_socket_mount = {
+  .m_op = &posix_socket_vfsops
+};
+
+struct posix_socket_file *
+posix_socket_file_get(int sock_fd)
+{
+  struct posix_socket_file *file = NULL;
+  struct vfscore_file *fos;
+
+  fos = vfscore_get_file(sock_fd);
+
+  if (!fos) {
+    uk_pr_err("Failed with invalid descriptor\n");
+    file = ERR2PTR(-EINVAL);
+    goto EXIT;
+  }
+  
+  if (fos->f_dentry->d_vnode->v_type != VSOCK) {
+    uk_pr_err("File descriptor is not a socket\n");
+    file = ERR2PTR(-EINVAL);
+    goto EXIT;
+  }
+  
+  file = fos->f_data;
+
+EXIT:
+  return file;
+}
+
+int
+socket_alloc_fd(struct posix_socket_driver *d, void *sock_data)
+{
+  int ret = 0;
+  int vfs_fd;
+  struct posix_socket_file *file = NULL;
+  struct vfscore_file *vfs_file = NULL;
+  struct dentry *s_dentry;
+  struct vnode *s_vnode;
+
+  /* Reserve file descriptor number */
+  vfs_fd = vfscore_alloc_fd();
+  if (vfs_fd < 0) {
+    ret = -ENFILE;
+    uk_pr_err("failed to allocate file descriptor number\n");
+    goto ERR_EXIT;
+  }
+
+  /* Allocate file, dentry, and vnode */
+  file = uk_calloc(d->allocator, 1, sizeof(*file));
+  if (!file) {
+    ret = -ENOMEM;
+    uk_pr_err("failed to allocate socket file: out of memory\n");
+    goto ERR_MALLOC_FILE;
+  }
+
+  vfs_file = uk_calloc(d->allocator, 1, sizeof(*vfs_file));
+  if (!vfs_file) {
+    ret = -ENOMEM;
+    uk_pr_err("failed to allocate socket vfs_file: out of memory\n");
+    goto ERR_MALLOC_VFS_FILE;
+  }
+
+  ret = vfscore_vget(&posix_socket_mount, s_inode++, &s_vnode);
+  UK_ASSERT(ret == 0); /* we should not find it in cache */
+
+  if (!s_vnode) {
+    ret = -ENOMEM;
+    uk_pr_err("failed to allocate socket vnode: out of memory\n");
+    goto ERR_ALLOC_VNODE;
+  }
+
+  uk_mutex_unlock(&s_vnode->v_lock);
+
+  /*
+   * it doesn't matter that all the dentries have the
+   * same path since we never lookup for them
+   */
+  s_dentry = dentry_alloc(NULL, s_vnode, "/");
+
+  if (!s_dentry) {
+    ret = -ENOMEM;
+    uk_pr_err("failed to allocate socket dentry: out of memory\n");
+    goto ERR_ALLOC_DENTRY;
+  }
+
+  /* Put things together, and fill out necessary fields */
+  vfs_file->fd = vfs_fd;
+  vfs_file->f_flags = UK_FWRITE | UK_FREAD;
+  vfs_file->f_count = 1;
+  vfs_file->f_data = file;
+  vfs_file->f_dentry = s_dentry;
+  vfs_file->f_vfs_flags = UK_VFSCORE_NOPOS;
+
+  s_vnode->v_data = file;
+  s_vnode->v_type = VSOCK;
+
+  file->vfs_file = vfs_file;
+  file->sock_data = sock_data;
+  file->driver = d;
+
+  uk_pr_debug("allocated socket %d for %s (%p)\n",
+            vfs_fd,
+            d->libname,
+            file->sock_data);
+
+  /* Store within the vfs structure */
+  ret = vfscore_install_fd(vfs_fd, file->vfs_file);
+  if (ret) {
+    uk_pr_err("failed to install socket fd\n");
+    goto ERR_VFS_INSTALL;
+  }
+
+  /* Only the dentry should hold a reference; release ours */
+  vrele(s_vnode);
+
+  /* Return file descriptor of our socket */
+  return vfs_fd;
+
+ERR_VFS_INSTALL:
+  drele(s_dentry);
+ERR_ALLOC_DENTRY:
+  vrele(s_vnode);
+ERR_ALLOC_VNODE:
+  uk_free(d->allocator, vfs_file);
+ERR_MALLOC_VFS_FILE:
+  uk_free(d->allocator, file);
+ERR_MALLOC_FILE:
+  vfscore_put_fd(vfs_fd);
+ERR_EXIT:
+  UK_ASSERT(ret < 0);
+  return ret;
+}
+
+int
+posix_socket_vfscore_close(struct vnode *s_vnode,
+          struct vfscore_file *vfscore_file)
+{
+  int ret = 0;
+  struct posix_socket_file *file = NULL;
+  file = s_vnode->v_data;
+
+  uk_pr_debug("%s fd:%d driver:%s: sock_data:%p\n",
+            __func__,
+            file->vfs_file->fd,
+            file->driver->libname,
+            file->sock_data);
+
+  /* Close and release the socket */
+  ret = posix_socket_close(file->driver, file->sock_data);
+  
+  /*
+   * Free socket file
+   * The rest of the resources will be freed by vfs
+   *
+   * TODO: vfs ignores close errors right now, so free our file
+   */
+  uk_free(file->driver->allocator, file);
+
+  if (ret < 0)
+    return errno;
+  
+  return ret;
+}
+
+int
+posix_socket_vfscore_write(struct vnode *s_vnode,
+          struct uio *buf, int ioflag __unused)
+{
+  int ret = 0;
+  struct posix_socket_file *file = NULL;
+
+  file = s_vnode->v_data;
+  uk_pr_debug("%s fd:%d driver:%s sock_data:%p\n",
+          __func__,
+          file->vfs_file->fd,
+          file->driver->libname,
+          file->sock_data);
+
+  /* Write to the socket */
+  ret = posix_socket_write(file->driver, file->sock_data, buf->uio_iov, buf->uio_iovcnt);
+  
+  /*
+   * Some socket implementations, such as LwIP, may set the errno and return to 
+   * -1 as an error, but vfs expects us to return a positive errno.
+   */
+  if (ret < 0)
+    return errno;
+
+  buf->uio_resid -= ret;
+  return 0;
+}
+
+int
+posix_socket_vfscore_read(struct vnode *s_vnode,
+          struct vfscore_file *vfscore_file __unused,
+          struct uio *buf, int ioflag __unused)
+{
+  int ret = 0;
+  struct posix_socket_file *file = NULL;
+  
+  file = s_vnode->v_data;
+  if (PTRISERR(file)) {
+    uk_pr_debug("failed to identify socket descriptor\n");
+    ret = -1;
+    POSIX_SOCKET_SET_ERRNO(PTR2ERR(file));
+    goto EXIT;
+  }
+
+  uk_pr_debug("%s fd:%d driver:%s sock_data:%p\n",
+            __func__,
+            file->vfs_file->fd,
+            file->driver->libname,
+            file->sock_data);
+
+  ret = posix_socket_read(file->driver, file->sock_data, buf->uio_iov, buf->uio_iovcnt);
+  if (ret < 0) {
+    ret = errno;
+    goto EXIT;
+  }
+  
+  buf->uio_resid -= ret;
+
+EXIT:
+  return ret;
+}
+
+int
+posix_socket_vfscore_ioctl(struct vnode *s_vnode,
+          struct vfscore_file *vfscore_file __unused,
+          unsigned long request,
+          void *buf)
+{
+  int ret = 0;
+  struct posix_socket_file *file = NULL;
+  
+  file = s_vnode->v_data;
+  if (PTRISERR(file)) {
+    uk_pr_debug("failed to identify socket descriptor\n");
+    ret = -1;
+    POSIX_SOCKET_SET_ERRNO(PTR2ERR(file));
+    goto EXIT;
+  }
+
+  uk_pr_debug("%s fd:%d driver:%s sock_data:%p\n",
+            __func__,
+            file->vfs_file->fd,
+            file->driver->libname,
+            file->sock_data);
+
+  ret = posix_socket_ioctl(file->driver, file->sock_data, request, buf);
+  if (ret < 0)
+    ret = errno;
+
+EXIT:
+  return ret;
+}
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 14 13:00:24 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 14 Jul 2020 13:00:24 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jvKXo-0004Nh-Fh; Tue, 14 Jul 2020 13:00:24 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=8/kp=AZ=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jvKXn-0004JU-6W
 for minios-devel@lists.xen.org; Tue, 14 Jul 2020 13:00:23 +0000
X-Inumbo-ID: f854bf6b-c5d1-11ea-930a-12813bfff9fa
Received: from mh-fa-0.lancs.ac.uk (unknown [148.88.65.130])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id f854bf6b-c5d1-11ea-930a-12813bfff9fa;
 Tue, 14 Jul 2020 13:00:19 +0000 (UTC)
Received: from p5087e57f.dip0.t-ipconnect.de ([80.135.229.127]
 helo=unknown.fritz.box)
 by mh-fa-0.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jvKXi-000TBP-6m; Tue, 14 Jul 2020 14:00:19 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT/LWIP PATCH 3/4] include/sys/socket.h: Correct prototype
 definitions
Date: Tue, 14 Jul 2020 14:59:26 +0200
Message-Id: <20200714125930.91234-9-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200714125930.91234-1-a.jung@lancs.ac.uk>
References: <20200714125930.91234-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-fa-0.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Alexander Jung <alexander.jung@neclab.eu>

LwIP can provide the `sys/socket.h` header file but it must be
POSIX compliant.  This commit corrects the prototype definitions.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 include/sys/socket.h | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/include/sys/socket.h b/include/sys/socket.h
index 8007cb8..edc0bc4 100644
--- a/include/sys/socket.h
+++ b/include/sys/socket.h
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: BSD-3-Clause */
 /*
- * Copyright (c) 2019, NEC Laboratories Europe GmbH, NEC Corporation.
+ * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation.
  *                     All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -91,13 +91,13 @@ int setsockopt(int s, int level, int optname, const void *optval,
 	       socklen_t optlen);
 int connect(int s, const struct sockaddr *name, socklen_t namelen);
 int listen(int s, int backlog);
-int recv(int s, void *mem, size_t len, int flags);
-int recvfrom(int s, void *mem, size_t len, int flags,
+ssize_t recv(int s, void *mem, size_t len, int flags);
+ssize_t recvfrom(int s, void *mem, size_t len, int flags,
 	     struct sockaddr *from, socklen_t *fromlen);
-int recvmsg(int s, struct msghdr *msg, int flags);
-int send(int s, const void *dataptr, size_t size, int flags);
-int sendmsg(int s, const struct msghdr *message, int flags);
-int sendto(int s, const void *dataptr, size_t size, int flags,
+ssize_t recvmsg(int s, struct msghdr *msg, int flags);
+ssize_t send(int s, const void *dataptr, size_t size, int flags);
+ssize_t sendmsg(int s, const struct msghdr *message, int flags);
+ssize_t sendto(int s, const void *dataptr, size_t size, int flags,
 	   const struct sockaddr *to, socklen_t tolen);
 int socketpair(int domain, int type, int protocol, int sv[2]);
 
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 14 13:00:27 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 14 Jul 2020 13:00:27 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jvKXr-0004Og-HR; Tue, 14 Jul 2020 13:00:27 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=8/kp=AZ=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jvKXp-0004Iz-Ql
 for minios-devel@lists.xen.org; Tue, 14 Jul 2020 13:00:25 +0000
X-Inumbo-ID: f9582294-c5d1-11ea-8496-bc764e2007e4
Received: from mh-fa-0.lancs.ac.uk (unknown [148.88.65.130])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id f9582294-c5d1-11ea-8496-bc764e2007e4;
 Tue, 14 Jul 2020 13:00:21 +0000 (UTC)
Received: from p5087e57f.dip0.t-ipconnect.de ([80.135.229.127]
 helo=unknown.fritz.box)
 by mh-fa-0.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jvKXj-000TBP-9B; Tue, 14 Jul 2020 14:00:20 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT/LIB-LWIP PATCH 4/4] include/netinet/in.h: Remove LwIP's
 socket header
Date: Tue, 14 Jul 2020 14:59:27 +0200
Message-Id: <20200714125930.91234-10-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200714125930.91234-1-a.jung@lancs.ac.uk>
References: <20200714125930.91234-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-fa-0.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Alexander Jung <alexander.jung@neclab.eu>

Providing a global `netinet/in.h` header should no longer include
LwIP's socket structures and definitions since this is
implementation specific.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 include/netinet/in.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/netinet/in.h b/include/netinet/in.h
index 18ee075..9192292 100644
--- a/include/netinet/in.h
+++ b/include/netinet/in.h
@@ -4,7 +4,6 @@
 #include <uk/config.h>
 
 #ifdef CONFIG_LWIP_SOCKET
-#include <lwip/sockets.h>
 /* Taken from musl's netinet/in.h */
 #ifdef CONFIG_LWIP_IPV6
 #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 14 13:00:29 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 14 Jul 2020 13:00:29 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jvKXt-0004PW-J1; Tue, 14 Jul 2020 13:00:29 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=8/kp=AZ=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jvKXs-0004JU-6v
 for minios-devel@lists.xen.org; Tue, 14 Jul 2020 13:00:28 +0000
X-Inumbo-ID: fd1f9948-c5d1-11ea-930a-12813bfff9fa
Received: from mh-fa-0.lancs.ac.uk (unknown [148.88.65.130])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id fd1f9948-c5d1-11ea-930a-12813bfff9fa;
 Tue, 14 Jul 2020 13:00:27 +0000 (UTC)
Received: from p5087e57f.dip0.t-ipconnect.de ([80.135.229.127]
 helo=unknown.fritz.box)
 by mh-fa-0.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jvKXq-000TBP-6r; Tue, 14 Jul 2020 14:00:27 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT/MUSL PATCH 2/3] scripts: Add header helper script
Date: Tue, 14 Jul 2020 14:59:29 +0200
Message-Id: <20200714125930.91234-12-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200714125930.91234-1-a.jung@lancs.ac.uk>
References: <20200714125930.91234-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-fa-0.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Alexander Jung <alexander.jung@neclab.eu>

This helper script naively iterates through the source files of a
MUSL subcomponent and outputs the list of headers which it uses.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 scripts/list-headers.sh | 68 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100755 scripts/list-headers.sh

diff --git a/scripts/list-headers.sh b/scripts/list-headers.sh
new file mode 100755
index 0000000..fc40923
--- /dev/null
+++ b/scripts/list-headers.sh
@@ -0,0 +1,68 @@
+#!/bin/bash
+# Generate list of MUSL headers for a given library
+#
+# Authors: Alexander Jung <alexander.jung@neclab.eu>
+#
+# Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 3. Neither the name of the copyright holder nor the names of its
+#    contributors may be used to endorse or promote products derived from
+#    this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+MUSL_SRC=$1
+MUSL_LIB=$2
+
+if [ "x$MUSL_SRC" == "x" ]; then
+  echo "Usage: $0 [MUSL_SRC] [LIBRARY]"
+  exit 1
+elif [ ! -d $MUSL_SRC/src ]; then
+  echo "Could not find: $MUSL_SRC"
+  exit 1
+elif [ ! "x$MUSL_LIB" == "x" ] && [ ! -d $MUSL_SRC/src/$MUSL_LIB ]; then
+  echo "Could not find: $MUSL_SRC/src/$MUSL_LIB"
+  exit 1
+fi
+
+LIB_HDRS=()
+
+FILES=$(find $MUSL_SRC/src/$MUSL_LIB/ -type f -name '*.c')
+
+for FILE in $FILES; do
+  FILE_HDRS=$(grep -oP '#\s*include\s*[<"]\K[\w\/]+.h' $FILE)
+  LIB_HDRS+=($FILE_HDRS)
+done
+
+# Remove duplicates
+IFS=$'\n' LIB_HDRS=($(sort -u <<<"${LIB_HDRS[*]}"))
+unset IFS
+
+for HDR in "${LIB_HDRS[@]}"; do
+  if [ -f $MUSL_SRC/include/$HDR ]; then
+    echo "LIBMUSL_${MUSL_LIB^^}_HDRS-y += \$(LIBMUSL)/include/$HDR"
+  elif [ -f $MUSL_SRC/src/internal/$HDR ]; then
+    echo "LIBMUSL_${MUSL_LIB^^}_HDRS-y += \$(LIBMUSL)/src/internal/$HDR"
+  else
+    echo "# LIBMUSL_${MUSL_LIB^^}_HDRS-y += $HDR # not found"
+  fi
+done
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 14 13:00:34 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 14 Jul 2020 13:00:34 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jvKXy-0004Qu-Kq; Tue, 14 Jul 2020 13:00:34 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=8/kp=AZ=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jvKXx-0004JU-75
 for minios-devel@lists.xen.org; Tue, 14 Jul 2020 13:00:33 +0000
X-Inumbo-ID: fd5a0c0f-c5d1-11ea-930a-12813bfff9fa
Received: from mh-fa-0.lancs.ac.uk (unknown [148.88.65.130])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id fd5a0c0f-c5d1-11ea-930a-12813bfff9fa;
 Tue, 14 Jul 2020 13:00:29 +0000 (UTC)
Received: from p5087e57f.dip0.t-ipconnect.de ([80.135.229.127]
 helo=unknown.fritz.box)
 by mh-fa-0.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jvKXr-000TBP-8l; Tue, 14 Jul 2020 14:00:28 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT/MUSL PATCH 3/3] patches: Update ioctl prototype definition
Date: Tue, 14 Jul 2020 14:59:30 +0200
Message-Id: <20200714125930.91234-13-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200714125930.91234-1-a.jung@lancs.ac.uk>
References: <20200714125930.91234-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-fa-0.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Alexander Jung <alexander.jung@neclab.eu>

This patch updates the `ioctl` prototype with a more precise definition
which is also compliant with vfscore.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 .../0008-Use-compatible-ioctl-prototype.patch | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 patches/0008-Use-compatible-ioctl-prototype.patch

diff --git a/patches/0008-Use-compatible-ioctl-prototype.patch b/patches/0008-Use-compatible-ioctl-prototype.patch
new file mode 100644
index 0000000..85cd3b0
--- /dev/null
+++ b/patches/0008-Use-compatible-ioctl-prototype.patch
@@ -0,0 +1,30 @@
+From 150959f0fd0b04919fb1384abb8998fd8e2c1ca4 Mon Sep 17 00:00:00 2001
+From: Alexander Jung <alexander.jung@neclab.eu>
+Date: Tue, 30 Jun 2020 19:45:36 +0200
+Subject: [PATCH] Use compatible ioctl prototype
+
+This patch updates the `ioctl` prototype with a more precise definition
+which is also compliant with vfscore.
+
+Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
+---
+ include/sys/ioctl.h | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/include/sys/ioctl.h b/include/sys/ioctl.h
+index d0415b3..9929002 100644
+--- a/include/sys/ioctl.h
++++ b/include/sys/ioctl.h
+@@ -6,7 +6,8 @@ extern "C" {
+ 
+ #include <bits/ioctl.h>
+ 
+-int ioctl (int, int, ...);
++// int ioctl (int, int, ...);
++int ioctl(int fd, unsigned long int request, ...);
+ 
+ #ifdef __cplusplus
+ }
+-- 
+2.20.1
+
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 14 13:00:42 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 14 Jul 2020 13:00:42 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jvKY6-0004SZ-OX; Tue, 14 Jul 2020 13:00:42 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=8/kp=AZ=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jvKY4-0004SH-Pl
 for minios-devel@lists.xen.org; Tue, 14 Jul 2020 13:00:40 +0000
X-Inumbo-ID: fc2ba194-c5d1-11ea-b7bb-bc764e2007e4
Received: from mh-fa-0.lancs.ac.uk (unknown [148.88.65.130])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id fc2ba194-c5d1-11ea-b7bb-bc764e2007e4;
 Tue, 14 Jul 2020 13:00:26 +0000 (UTC)
Received: from p5087e57f.dip0.t-ipconnect.de ([80.135.229.127]
 helo=unknown.fritz.box)
 by mh-fa-0.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jvKXl-000TBP-88; Tue, 14 Jul 2020 14:00:25 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT/MUSL PATCH 1/3] Makefile.*, Config.uk: Sub-componentize MUSL
Date: Tue, 14 Jul 2020 14:59:28 +0200
Message-Id: <20200714125930.91234-11-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200714125930.91234-1-a.jung@lancs.ac.uk>
References: <20200714125930.91234-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-fa-0.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Alexander Jung <alexander.jung@neclab.eu>

This commit introduces the ability to select paticular
subcomponents within the MUSL standard library framework through
Unikraft's KConfig system.  In order to achieve distinction
between libraries, additional rules were created to copy the
necessary headers from the subcomponents into the microlibrary's
build directory.  This is achieved by adding to an appropriate
subcomponent list of headers (standarized via `*_HDRS-y`) and
then calling a subcomponent registration macro
`_libmusl_import_lib`.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 Config.uk                  | 211 ++++++++-
 Makefile.rules             |  31 ++
 Makefile.uk                | 123 ++++-
 Makefile.uk.musl.aio       |  22 +-
 Makefile.uk.musl.complex   | 142 +++---
 Makefile.uk.musl.conf      |  22 +-
 Makefile.uk.musl.crypt     |  27 +-
 Makefile.uk.musl.ctype     |  90 ++--
 Makefile.uk.musl.dirent    |  42 +-
 Makefile.uk.musl.env       |  38 +-
 Makefile.uk.musl.errno     |  13 +-
 Makefile.uk.musl.exit      |  27 +-
 Makefile.uk.musl.fcntl     |  20 +-
 Makefile.uk.musl.fenv      |  55 ++-
 Makefile.uk.musl.internal  |  66 ++-
 Makefile.uk.musl.ipc       |  41 +-
 Makefile.uk.musl.ldso      |  68 +--
 Makefile.uk.musl.legacy    |  56 ++-
 Makefile.uk.musl.linux     | 152 +++---
 Makefile.uk.musl.locale    |  82 +++-
 Makefile.uk.musl.malloc    |  32 +-
 Makefile.uk.musl.math      | 926 +++++++++++++++++++------------------
 Makefile.uk.musl.misc      | 117 +++--
 Makefile.uk.musl.mman      |  49 +-
 Makefile.uk.musl.mq        |  32 +-
 Makefile.uk.musl.multibyte |  51 +-
 Makefile.uk.musl.network   | 192 +++++---
 Makefile.uk.musl.passwd    |  60 ++-
 Makefile.uk.musl.prng      |  30 +-
 Makefile.uk.musl.process   |  90 ++--
 Makefile.uk.musl.regex     |  34 +-
 Makefile.uk.musl.sched     |  29 +-
 Makefile.uk.musl.search    |  17 +-
 Makefile.uk.musl.select    |  17 +-
 Makefile.uk.musl.setjmp    |  62 +--
 Makefile.uk.musl.signal    | 155 ++++---
 Makefile.uk.musl.stat      |  51 +-
 Makefile.uk.musl.stdio     | 266 ++++++-----
 Makefile.uk.musl.stdlib    |  60 ++-
 Makefile.uk.musl.string    | 189 ++++----
 Makefile.uk.musl.temp      |  26 +-
 Makefile.uk.musl.termios   |  28 +-
 Makefile.uk.musl.thread    | 412 +++++++++--------
 Makefile.uk.musl.time      | 117 +++--
 Makefile.uk.musl.unistd    | 189 ++++----
 45 files changed, 2815 insertions(+), 1744 deletions(-)
 create mode 100644 Makefile.rules

diff --git a/Config.uk b/Config.uk
index 7862da8..9d4a15a 100644
--- a/Config.uk
+++ b/Config.uk
@@ -1,9 +1,206 @@
 # hidden
 menuconfig LIBMUSL
-        bool "musl - A C standard library"
-        default n
-        select HAVE_LIBC
-        select LIBKUALLOC
-        select LIBSYSCALL_SHIM
-        select LIBVFSCORE
-        select LIBPOSIX_PROCESS
+  bool "musl: A C standard library"
+  default n
+  select HAVE_LIBC
+  select LIBKUALLOC
+  select LIBSYSCALL_SHIM
+  select LIBVFSCORE
+  select LIBPOSIX_PROCESS
+
+  select LIBMUSL_STAT
+  select LIBMUSL_DIRENT
+  select LIBMUSL_TERMIOS
+  select LIBMUSL_LOCALE
+  select LIBMUSL_ERRNO
+  select LIBMUSL_INTERNAL
+  select LIBMUSL_STRING
+  select LIBMUSL_CTYPE
+  select LIBMUSL_STDLIB
+  select LIBMUSL_ENV
+
+if LIBMUSL
+
+config LIBMUSL_AIO
+  bool "libaio"
+  default y
+
+config LIBMUSL_COMPLEX
+  bool "libcomplex"
+  default y
+
+config LIBMUSL_CONF
+  bool "libconf"
+  default y
+
+config LIBMUSL_CRYPT
+  bool "libcrypt"
+  default y
+
+config LIBMUSL_CTYPE
+  bool "libctype"
+  default y
+
+config LIBMUSL_DIRENT
+  bool "libdirent"
+  default y
+
+config LIBMUSL_ENV
+  bool "libenv"
+  default y
+
+config LIBMUSL_ERRNO
+  bool "liberrno"
+  default y
+
+config LIBMUSL_EXIT
+  bool "libexit"
+  default y
+
+config LIBMUSL_FCNTL
+  bool "libfcntl"
+  default y
+
+config LIBMUSL_FENV
+  bool "libfenv"
+  default y
+
+config LIBMUSL_INTERNAL
+  bool "libinternal"
+  default y
+
+config LIBMUSL_IPC
+  bool "libipc"
+  default y
+
+config LIBMUSL_LDSO
+  bool "libldso"
+  default y
+
+config LIBMUSL_LEGACY
+  bool "liblegacy"
+  default y
+
+config LIBMUSL_LINUX
+  bool "liblinux"
+  default y
+
+config LIBMUSL_LOCALE
+  bool "liblocale"
+  default y
+
+config LIBMUSL_MALLOC
+  bool "libmalloc"
+  default y
+
+config LIBMUSL_MATH
+  bool "libmath"
+  default y
+  select LIBMUSL_FENV
+
+config LIBMUSL_MISC
+  bool "libmisc"
+  default y
+
+config LIBMUSL_MMAN
+  bool "libmman"
+  default y
+
+config LIBMUSL_MQ
+  bool "libmq"
+  default y
+
+config LIBMUSL_MULTIBYTE
+  bool "libmultibyte"
+  default y
+
+config LIBMUSL_NETWORK
+  bool "libnetwork"
+  default y
+
+config LIBMUSL_PASSWD
+  bool "libpasswd"
+  default y
+
+config LIBMUSL_PRNG
+  bool "libprng"
+  default y
+
+config LIBMUSL_PROCESS
+  bool "libprocess"
+  default y
+  select LIBMUSL_THREAD
+
+config LIBMUSL_REGEX
+  bool "libregex"
+  default y
+
+config LIBMUSL_SCHED
+  bool "libsched"
+  default y
+
+config LIBMUSL_SEARCH
+  bool "libsearch"
+  default y
+
+config LIBMUSL_SELECT
+  bool "libselect"
+  default y
+
+config LIBMUSL_SETJMP
+  bool "libsetjmp"
+  default y
+
+config LIBMUSL_SIGNAL
+  bool "libsignal"
+  default y
+
+config LIBMUSL_STAT
+  bool "libstat"
+  default y
+
+config LIBMUSL_STDIO
+  bool "libstdio"
+  default y
+  select LIBMUSL_FENV
+  select LIBMUSL_UNISTD
+
+config LIBMUSL_STDLIB
+  bool "libstdlib"
+  default y
+  select LIBMUSL_SIGNAL
+  select LIBMUSL_MULTIBYTE
+
+config LIBMUSL_STRING
+  bool "libstring"
+  default y
+
+config LIBMUSL_TEMP
+  bool "libtemp"
+  default y
+
+config LIBMUSL_TERMIOS
+  bool "libtermios"
+  default y
+
+config LIBMUSL_THREAD
+  bool "libthread"
+  default y
+  select LIBMUSL_SCHED
+  select LIBMUSL_MMAN
+
+config LIBMUSL_FORCE_THREAD
+  bool
+  default y if LIBUKSCHED
+  default n
+  select LIBMUSL_THREAD
+
+config LIBMUSL_TIME
+  bool "libtime"
+  default y
+
+config LIBMUSL_UNISTD
+  bool "libunistd"
+  default y
+
+endif
diff --git a/Makefile.rules b/Makefile.rules
new file mode 100644
index 0000000..53e8477
--- /dev/null
+++ b/Makefile.rules
@@ -0,0 +1,31 @@
+#
+# Import a sub-library of musl
+#
+# @param $(1)
+#   The name of the sub-library within musl.
+# @param $(2)
+#   The headers for this sub-library.
+# @param $(3)
+#   The source files for this sub-library.
+#
+define _libmusl_import_lib
+$(LIBMUSL_BUILD)/include/$(1):
+	$(call verbose_cmd,MKDIR,libmusl: $(subst $(LIBMUSL_BUILD),,$(1)): $(notdir $$@), mkdir -p $$@)
+
+# Make a symbolic link of the original header file to a sub-library directory
+$(LIBMUSL_BUILD)/include/$(1)/%.h:
+	$$(Q)mkdir -p $$(shell dirname $$@)
+	$(call verbose_cmd,HOSTLN,libmusl: $(1): $$(subst $(LIBMUSL_BUILD)/include/$(1)/,,$$@), \
+		ln -sf $$(subst $(LIBMUSL_BUILD)/include/$(1)/,$(LIBMUSL),$$@) $$@)
+
+LIBMUSL_$(call uc,$(1))_INCLUDES-y += -I$(LIBMUSL_BUILD)/include/$(1)/include
+LIBMUSL_$(call uc,$(1))_INCLUDES-y += -I$(LIBMUSL_BUILD)/include/$(1)/src/internal
+LIBMUSL_$(call uc,$(1))_INCLUDES-y += -I$(LIBMUSL_BUILD)/include/$(1)/src/$(1)
+LIBMUSL_SRCS-y += $(3)
+
+CINCLUDES-y += $$(LIBMUSL_$(call uc,$(1))_INCLUDES-y)
+CXXINCLUDES-y += $$(LIBMUSL_$(call uc,$(1))_INCLUDES-y)
+
+# Append the sub library directory to the include path
+$(LIBMUSL_BUILD)/.prepared: $(subst $(LIBMUSL),$(LIBMUSL_BUILD)/include/$(1),$(2))
+endef
diff --git a/Makefile.uk b/Makefile.uk
index 9657bb7..8ef65ff 100644
--- a/Makefile.uk
+++ b/Makefile.uk
@@ -1,6 +1,7 @@
 #  libmusl Makefile.uk
 #
 #  Authors: Felipe Huici <felipe.huici@neclab.eu>
+#           Alexander Jung <alexander.jung@neclab.eu>
 #
 #  Copyright (c) 2017, NEC Europe Ltd., NEC Corporation. All rights reserved.
 #
@@ -36,6 +37,7 @@
 # Library registration
 ################################################################################
 $(eval $(call addlib_s,libmusl,$(CONFIG_LIBMUSL)))
+
 # Additionally, build glue code. This is put into a separate library so that we
 # can apply a thick helping of warning suppressions to musl, which throws
 # lots of compilation warnings, but keep our glue code up to our standards.
@@ -56,13 +58,14 @@ $(eval $(call patch,libmusl,$(LIBMUSL_PATCHDIR),musl-$(LIBMUSL_VERSION)))
 LIBMUSL_SUBDIR=musl-$(LIBMUSL_VERSION)
 LIBMUSL=$(LIBMUSL_ORIGIN)/$(LIBMUSL_SUBDIR)/
 
+# Additional macros for musl sub-libraries
+include $(LIBMUSL_BASE)/Makefile.rules
+
 ################################################################################
 # Library includes
 ################################################################################
 LIBMUSL_GLOBAL_INCLUDES-y   += -I$(LIBMUSL)/arch/$(ARCH)
 LIBMUSL_GLOBAL_INCLUDES-y   += -I$(LIBMUSL)/arch/generic
-LIBMUSL_GLOBAL_INCLUDES-y   += -I$(LIBMUSL)/src/internal
-LIBMUSL_GLOBAL_INCLUDES-y   += -I$(LIBMUSL)/include
 LIBMUSL_GLOBAL_INCLUDES-y   += -I$(LIBMUSL_BASE)/include
 
 CINCLUDES-y    += $(LIBMUSL_GLOBAL_INCLUDES-y)
@@ -87,15 +90,21 @@ $(LIBMUSL)/src/internal/version.h:
 
 UK_PREPARE += $(LIBMUSL)/arch/$(ARCH)/bits/alltypes.h
 UK_PREPARE += $(LIBMUSL)/src/internal/version.h
+UK_PREPARE += $(LIBMUSL_BUILD)/.prepared
 
 LIBMUSL_CLEAN += $(LIBMUSL)/arch/$(ARCH)/bits/alltypes.h
 LIBMUSL_CLEAN += $(LIBMUSL)/src/internal/version.h
+LIBMUSL_CLEAN += $(LIBMUSL_BUILD)/include
 
 ################################################################################
 # Global flags
 ################################################################################
-LIBMUSL_HEADER_FLAGS-y += -Wno-unused-parameter -Wno-unused-value \
-			  -Wno-parentheses
+LIBMUSL_HDRS_FLAGS-y += -Wno-unused-parameter
+LIBMUSL_HDRS_FLAGS-y += -Wno-unused-value
+LIBMUSL_HDRS_FLAGS-y += -Wno-parentheses
+LIBMUSL_HDRS_FLAGS-y += -Wno-builtin-macro-redefined
+LIBMUSL_HDRS_FLAGS-y += -D_POSIX_SOURCE -D_BSD_SOURCE
+
 LIBMUSL_CFLAGS-y += -Wno-implicit-fallthrough
 LIBMUSL_CFLAGS-y += -Wno-restrict
 LIBMUSL_CFLAGS-y += -Wno-unused-but-set-variable
@@ -107,59 +116,159 @@ LIBMUSL_CFLAGS-y += -Wno-missing-braces
 LIBMUSL_CFLAGS-y += -Wno-cast-function-type
 LIBMUSL_CFLAGS-y += -Wno-format-contains-nul
 LIBMUSL_CFLAGS-y += -Wno-type-limits
-LIBMUSL_CFLAGS-y += $(LIBMUSL_HEADER_FLAGS-y)
+LIBMUSL_CFLAGS-y += $(LIBMUSL_HDRS_FLAGS-y)
 
 # We globally switch off warnings that are caused by musl's public headers
-CFLAGS += $(LIBMUSL_HEADER_FLAGS-y)
-CXXFLAGS += $(LIBMUSL_HEADER_FLAGS-y)
+CFLAGS += $(LIBMUSL_HDRS_FLAGS-y)
+CXXFLAGS += $(LIBMUSL_HDRS_FLAGS-y)
 
 ################################################################################
 # OS dependencies code - Glue between Unicore and musl
 ################################################################################
 LIBMUSLGLUE_SRCS-y += $(LIBMUSL_BASE)/mem.c
 
+################################################################################
+# Core Standard Library
+################################################################################
+LIBMUSL_CORE_HDRS-y += $(LIBMUSL)/include/sys/types.h
+LIBMUSL_CORE_HDRS-y += $(LIBMUSL)/include/sys/param.h
+LIBMUSL_CORE_HDRS-y += $(LIBMUSL)/include/sys/time.h
+LIBMUSL_CORE_HDRS-y += $(LIBMUSL)/include/sys/mount.h
+LIBMUSL_CORE_HDRS-y += $(LIBMUSL)/include/sys/sysmacros.h
+LIBMUSL_CORE_HDRS-y += $(LIBMUSL)/include/sys/file.h
+LIBMUSL_CORE_HDRS-y += $(LIBMUSL)/include/alloca.h
+LIBMUSL_CORE_HDRS-y += $(LIBMUSL)/include/stdbool.h
+LIBMUSL_CORE_HDRS-y += $(LIBMUSL)/include/limits.h
+LIBMUSL_CORE_HDRS-y += $(LIBMUSL)/include/assert.h
+
+$(eval $(call _libmusl_import_lib,core,$(LIBMUSL_CORE_HDRS-y),$(LIBMUSL_CORE_SRCS-y)))
+
 ################################################################################
 # musl code -- one external Makefile per sub-lib
 ################################################################################
+ifeq ($(CONFIG_LIBMUSL_MQ),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.mq
+endif
+ifeq ($(CONFIG_LIBMUSL_DIRENT),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.dirent
+endif
+ifeq ($(CONFIG_LIBMUSL_MISC),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.misc
+endif
+ifeq ($(CONFIG_LIBMUSL_TEMP),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.temp
+endif
+ifeq ($(CONFIG_LIBMUSL_MULTIBYTE),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.multibyte
+endif
+ifeq ($(CONFIG_LIBMUSL_PROCESS),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.process
+endif
+ifeq ($(CONFIG_LIBMUSL_MMAN),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.mman
+endif
+ifeq ($(CONFIG_LIBMUSL_STDLIB),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.stdlib
+endif
+ifeq ($(CONFIG_LIBMUSL_FCNTL),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.fcntl
+endif
+ifeq ($(CONFIG_LIBMUSL_STDIO),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.stdio
+endif
+ifeq ($(CONFIG_LIBMUSL_CONF),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.conf
+endif
+ifeq ($(CONFIG_LIBMUSL_MATH),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.math
+endif
+ifeq ($(CONFIG_LIBMUSL_AIO),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.aio
+endif
+ifeq ($(CONFIG_LIBMUSL_STAT),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.stat
+endif
+ifeq ($(CONFIG_LIBMUSL_SEARCH),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.search
+endif
+ifeq ($(CONFIG_LIBMUSL_CRYPT),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.crypt
+endif
+ifeq ($(CONFIG_LIBMUSL_SELECT),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.select
+endif
+ifeq ($(CONFIG_LIBMUSL_MALLOC),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.malloc
+endif
+ifeq ($(CONFIG_LIBMUSL_UNISTD),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.unistd
+endif
+ifeq ($(CONFIG_LIBMUSL_SIGNAL),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.signal
+endif
+ifeq ($(CONFIG_LIBMUSL_THREAD),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.thread
+endif
+ifeq ($(CONFIG_LIBMUSL_LEGACY),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.legacy
+endif
+ifeq ($(CONFIG_LIBMUSL_ENV),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.env
+endif
+ifeq ($(CONFIG_LIBMUSL_TIME),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.time
+endif
+ifeq ($(CONFIG_LIBMUSL_ERRNO),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.errno
+endif
+ifeq ($(CONFIG_LIBMUSL_IPC),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.ipc
+endif
+ifeq ($(CONFIG_LIBMUSL_PRNG),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.prng
+endif
+ifeq ($(CONFIG_LIBMUSL_LDSO),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.ldso
+endif
+ifeq ($(CONFIG_LIBMUSL_PASSWD),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.passwd
+endif
+ifeq ($(CONFIG_LIBMUSL_FENV),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.fenv
+endif
+ifeq ($(CONFIG_LIBMUSL_CTYPE),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.ctype
+endif
+ifeq ($(CONFIG_LIBMUSL_LINUX),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.linux
+endif
+ifeq ($(CONFIG_LIBMUSL_INTERNAL),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.internal
+endif
+ifeq ($(CONFIG_LIBMUSL_NETWORK),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.network
+endif
+ifeq ($(CONFIG_LIBMUSL_SCHED),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.sched
+endif
+ifeq ($(CONFIG_LIBMUSL_STRING),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.string
+endif
+ifeq ($(CONFIG_LIBMUSL_REGEX),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.regex
+endif
+ifeq ($(CONFIG_LIBMUSL_TERMIOS),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.termios
+endif
+ifeq ($(CONFIG_LIBMUSL_EXIT),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.exit
+endif
+ifeq ($(CONFIG_LIBMUSL_SETJMP),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.setjmp
+endif
+ifeq ($(CONFIG_LIBMUSL_LOCALE),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.locale
+endif
+ifeq ($(CONFIG_LIBMUSL_COMPLEX),y)
 include $(LIBMUSL_BASE)/Makefile.uk.musl.complex
+endif
diff --git a/Makefile.uk.musl.aio b/Makefile.uk.musl.aio
index f59397a..ac4ab88 100644
--- a/Makefile.uk.musl.aio
+++ b/Makefile.uk.musl.aio
@@ -1,3 +1,19 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/aio/aio.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/aio/aio_suspend.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/aio/lio_listio.c
+LIBMUSL_AIO_HDRS-y += $(LIBMUSL)/include/aio.h
+LIBMUSL_AIO_HDRS-y += $(LIBMUSL)/src/internal/atomic.h
+LIBMUSL_AIO_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_AIO_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_AIO_HDRS-y += $(LIBMUSL)/include/limits.h
+LIBMUSL_AIO_HDRS-y += $(LIBMUSL)/include/pthread.h
+LIBMUSL_AIO_HDRS-y += $(LIBMUSL)/src/internal/pthread_impl.h
+LIBMUSL_AIO_HDRS-y += $(LIBMUSL)/include/semaphore.h
+LIBMUSL_AIO_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_AIO_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_AIO_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+LIBMUSL_AIO_HDRS-y += $(LIBMUSL)/include/time.h
+LIBMUSL_AIO_HDRS-y += $(LIBMUSL)/include/unistd.h
+
+LIBMUSL_AIO_SRCS-y += $(LIBMUSL)/src/aio/aio.c
+LIBMUSL_AIO_SRCS-y += $(LIBMUSL)/src/aio/aio_suspend.c
+LIBMUSL_AIO_SRCS-y += $(LIBMUSL)/src/aio/lio_listio.c
+
+$(eval $(call _libmusl_import_lib,aio,$(LIBMUSL_AIO_HDRS-y),$(LIBMUSL_AIO_SRCS-y)))
diff --git a/Makefile.uk.musl.complex b/Makefile.uk.musl.complex
index 14ea162..84c8d26 100644
--- a/Makefile.uk.musl.complex
+++ b/Makefile.uk.musl.complex
@@ -1,71 +1,77 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/casinh.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/csinhl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/creal.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/__cexpf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/casinl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cabs.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cexp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/ctanl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/ccosl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/ccoshf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/ccosh.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/csqrt.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/ccos.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cacos.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cacosl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cexpf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cprojf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/conjf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/catanhl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/creall.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/catanf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/csinl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cacosf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/csinh.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cimag.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/ctan.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/casinf.c
+LIBMUSL_COMPLEX_HDRS-y += $(LIBMUSL)/include/complex.h
+LIBMUSL_COMPLEX_HDRS-y += $(LIBMUSL)/include/float.h
+LIBMUSL_COMPLEX_HDRS-y += $(LIBMUSL)/src/intenal/libm.h
+
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/casinh.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/csinhl.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/creal.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/__cexpf.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/casinl.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cabs.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cexp.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/ctanl.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/ccosl.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/ccoshf.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/ccosh.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/csqrt.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/ccos.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cacos.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cacosl.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cexpf.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cprojf.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/conjf.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/catanhl.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/creall.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/catanf.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/csinl.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cacosf.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/csinh.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cimag.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/ctan.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/casinf.c
 # TO DO: missing __mulxc3
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cpowl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cacoshf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/ctanhl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/casinhl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/casinhf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/catanl.c
+#LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cpowl.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cacoshf.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/ctanhl.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/casinhl.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/casinhf.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/catanl.c
 # TO DO: missing __muldc3
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cpow.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/catanh.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/__cexp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/clogl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cacosh.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cargl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/catanhf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cimagl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cprojl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/conj.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cproj.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cargf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/catan.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cacoshl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/clogf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/csqrtf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/clog.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/casin.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/ctanh.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cexpl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/csin.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cabsf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/ctanf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cimagf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/ctanhf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/carg.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/csinhf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/csinf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/crealf.c
+#LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cpow.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/catanh.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/__cexp.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/clogl.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cacosh.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cargl.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/catanhf.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cimagl.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cprojl.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/conj.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cproj.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cargf.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/catan.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cacoshl.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/clogf.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/csqrtf.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/clog.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/casin.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/ctanh.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cexpl.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/csin.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cabsf.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/ctanf.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cimagf.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/ctanhf.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/carg.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/csinhf.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/csinf.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/crealf.c
 # TO DO: missing __mulsc3
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cpowf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/cabsl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/conjl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/ccoshl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/csqrtl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/complex/ccosf.c
+#LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cpowf.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/cabsl.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/conjl.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/ccoshl.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/csqrtl.c
+LIBMUSL_COMPLEX_SRCS-y += $(LIBMUSL)/src/complex/ccosf.c
+
+$(eval $(call _libmusl_import_lib,complex,$(LIBMUSL_COMPLEX_HDRS-y),$(LIBMUSL_COMPLEX_SRCS-y)))
diff --git a/Makefile.uk.musl.conf b/Makefile.uk.musl.conf
index 4e89e81..e4e49de 100644
--- a/Makefile.uk.musl.conf
+++ b/Makefile.uk.musl.conf
@@ -1,5 +1,17 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/conf/confstr.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/conf/fpathconf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/conf/legacy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/conf/pathconf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/conf/sysconf.c
+LIBMUSL_CONF_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_CONF_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_CONF_HDRS-y += $(LIBMUSL)/include/limits.h
+LIBMUSL_CONF_HDRS-y += $(LIBMUSL)/include/signal.h
+LIBMUSL_CONF_HDRS-y += $(LIBMUSL)/include/stdio.h
+LIBMUSL_CONF_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+LIBMUSL_CONF_HDRS-y += $(LIBMUSL)/include/sys/resource.h
+LIBMUSL_CONF_HDRS-y += $(LIBMUSL)/include/sys/sysinfo.h
+LIBMUSL_CONF_HDRS-y += $(LIBMUSL)/include/unistd.h
+
+LIBMUSL_CONF_SRCS-y += $(LIBMUSL)/src/conf/confstr.c
+LIBMUSL_CONF_SRCS-y += $(LIBMUSL)/src/conf/fpathconf.c
+LIBMUSL_CONF_SRCS-y += $(LIBMUSL)/src/conf/legacy.c
+LIBMUSL_CONF_SRCS-y += $(LIBMUSL)/src/conf/pathconf.c
+LIBMUSL_CONF_SRCS-y += $(LIBMUSL)/src/conf/sysconf.c
+
+$(eval $(call _libmusl_import_lib,conf,$(LIBMUSL_CONF_HDRS-y),$(LIBMUSL_CONF_SRCS-y)))
diff --git a/Makefile.uk.musl.crypt b/Makefile.uk.musl.crypt
index 71ceda6..0d491ac 100644
--- a/Makefile.uk.musl.crypt
+++ b/Makefile.uk.musl.crypt
@@ -1,8 +1,19 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/crypt/crypt.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/crypt/crypt_blowfish.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/crypt/crypt_des.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/crypt/crypt_md5.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/crypt/crypt_r.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/crypt/crypt_sha256.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/crypt/crypt_sha512.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/crypt/encrypt.c
+LIBMUSL_CRYPT_HDRS-y += $(LIBMUSL)/include/crypt.h
+LIBMUSL_CRYPT_HDRS-y += $(LIBMUSL)/include/ctype.h
+LIBMUSL_CRYPT_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_CRYPT_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_CRYPT_HDRS-y += $(LIBMUSL)/include/stdio.h
+LIBMUSL_CRYPT_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_CRYPT_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_CRYPT_HDRS-y += $(LIBMUSL)/include/unistd.h
+
+LIBMUSL_CRYPT_SRCS-y += $(LIBMUSL)/src/crypt/crypt.c
+LIBMUSL_CRYPT_SRCS-y += $(LIBMUSL)/src/crypt/crypt_blowfish.c
+LIBMUSL_CRYPT_SRCS-y += $(LIBMUSL)/src/crypt/crypt_des.c
+LIBMUSL_CRYPT_SRCS-y += $(LIBMUSL)/src/crypt/crypt_md5.c
+LIBMUSL_CRYPT_SRCS-y += $(LIBMUSL)/src/crypt/crypt_r.c
+LIBMUSL_CRYPT_SRCS-y += $(LIBMUSL)/src/crypt/crypt_sha256.c
+LIBMUSL_CRYPT_SRCS-y += $(LIBMUSL)/src/crypt/crypt_sha512.c
+LIBMUSL_CRYPT_SRCS-y += $(LIBMUSL)/src/crypt/encrypt.c
+
+$(eval $(call _libmusl_import_lib,crypt,$(LIBMUSL_CRYPT_HDRS-y),$(LIBMUSL_CRYPT_SRCS-y)))
diff --git a/Makefile.uk.musl.ctype b/Makefile.uk.musl.ctype
index c02dfed..0da9391 100644
--- a/Makefile.uk.musl.ctype
+++ b/Makefile.uk.musl.ctype
@@ -1,37 +1,53 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/__ctype_b_loc.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/__ctype_get_mb_cur_max.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/__ctype_tolower_loc.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/__ctype_toupper_loc.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/isalnum.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/isalpha.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/isascii.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/isblank.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/iscntrl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/isdigit.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/isgraph.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/islower.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/isprint.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/ispunct.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/isspace.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/isupper.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/iswalnum.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/iswalpha.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/iswblank.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/iswcntrl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/iswctype.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/iswdigit.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/iswgraph.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/iswlower.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/iswprint.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/iswpunct.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/iswspace.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/iswupper.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/iswxdigit.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/isxdigit.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/toascii.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/tolower.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/toupper.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/towctrans.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/wcswidth.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/wctrans.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ctype/wcwidth.c
+# LIBMUSL_CTYPE_HDRS-y += alpha.h # not found
+LIBMUSL_CTYPE_HDRS-y += $(LIBMUSL)/include/ctype.h
+LIBMUSL_CTYPE_HDRS-y += $(LIBMUSL)/include/endian.h
+LIBMUSL_CTYPE_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_CTYPE_HDRS-y += $(LIBMUSL)/src/internal/locale_impl.h
+LIBMUSL_CTYPE_HDRS-y += $(LIBMUSL)/src/ctype/nonspacing.h
+LIBMUSL_CTYPE_HDRS-y += $(LIBMUSL)/src/ctype/punct.h
+LIBMUSL_CTYPE_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_CTYPE_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_CTYPE_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_CTYPE_HDRS-y += $(LIBMUSL)/include/wchar.h
+LIBMUSL_CTYPE_HDRS-y += $(LIBMUSL)/include/wctype.h
+LIBMUSL_CTYPE_HDRS-y += $(LIBMUSL)/src/ctype/wide.h
+
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/__ctype_b_loc.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/__ctype_get_mb_cur_max.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/__ctype_tolower_loc.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/__ctype_toupper_loc.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/isalnum.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/isalpha.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/isascii.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/isblank.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/iscntrl.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/isdigit.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/isgraph.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/islower.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/isprint.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/ispunct.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/isspace.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/isupper.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/iswalnum.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/iswalpha.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/iswblank.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/iswcntrl.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/iswctype.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/iswdigit.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/iswgraph.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/iswlower.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/iswprint.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/iswpunct.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/iswspace.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/iswupper.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/iswxdigit.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/isxdigit.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/toascii.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/tolower.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/toupper.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/towctrans.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/wcswidth.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/wctrans.c
+LIBMUSL_CTYPE_SRCS-y += $(LIBMUSL)/src/ctype/wcwidth.c
+
+$(eval $(call _libmusl_import_lib,ctype,$(LIBMUSL_CTYPE_HDRS-y),$(LIBMUSL_CTYPE_SRCS-y)))
diff --git a/Makefile.uk.musl.dirent b/Makefile.uk.musl.dirent
index 3bb54a3..c64b2d7 100644
--- a/Makefile.uk.musl.dirent
+++ b/Makefile.uk.musl.dirent
@@ -1,13 +1,29 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/dirent/__getdents.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/dirent/alphasort.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/dirent/closedir.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/dirent/dirfd.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/dirent/fdopendir.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/dirent/opendir.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/dirent/readdir.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/dirent/readdir_r.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/dirent/rewinddir.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/dirent/scandir.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/dirent/seekdir.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/dirent/telldir.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/dirent/versionsort.c
+LIBMUSL_DIRENT_HDRS-y += $(LIBMUSL)/include/sys/stat.h
+LIBMUSL_DIRENT_HDRS-y += $(LIBMUSL)/include/dirent.h
+LIBMUSL_DIRENT_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_DIRENT_HDRS-y += $(LIBMUSL)/include/fcntl.h
+LIBMUSL_DIRENT_HDRS-y += $(LIBMUSL)/include/stddef.h
+LIBMUSL_DIRENT_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_DIRENT_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_DIRENT_HDRS-y += $(LIBMUSL)/include/string.h
+
+LIBMUSL_DIRENT_HDRS-y += $(LIBMUSL)/include/unistd.h
+LIBMUSL_DIRENT_HDRS-y += $(LIBMUSL)/src/dirent/__dirent.h
+LIBMUSL_DIRENT_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_DIRENT_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+
+LIBMUSL_DIRENT_SRCS-y += $(LIBMUSL)/src/dirent/__getdents.c
+LIBMUSL_DIRENT_SRCS-y += $(LIBMUSL)/src/dirent/alphasort.c
+#LIBMUSL_DIRENT_SRCS-y += $(LIBMUSL)/src/dirent/closedir.c
+#LIBMUSL_DIRENT_SRCS-y += $(LIBMUSL)/src/dirent/dirfd.c
+#LIBMUSL_DIRENT_SRCS-y += $(LIBMUSL)/src/dirent/fdopendir.c
+#LIBMUSL_DIRENT_SRCS-y += $(LIBMUSL)/src/dirent/opendir.c
+#LIBMUSL_DIRENT_SRCS-y += $(LIBMUSL)/src/dirent/readdir.c
+#LIBMUSL_DIRENT_SRCS-y += $(LIBMUSL)/src/dirent/readdir_r.c
+#LIBMUSL_DIRENT_SRCS-y += $(LIBMUSL)/src/dirent/rewinddir.c
+#LIBMUSL_DIRENT_SRCS-y += $(LIBMUSL)/src/dirent/scandir.c
+#LIBMUSL_DIRENT_SRCS-y += $(LIBMUSL)/src/dirent/seekdir.c
+#LIBMUSL_DIRENT_SRCS-y += $(LIBMUSL)/src/dirent/telldir.c
+LIBMUSL_DIRENT_SRCS-y += $(LIBMUSL)/src/dirent/versionsort.c
+
+$(eval $(call _libmusl_import_lib,dirent,$(LIBMUSL_DIRENT_HDRS-y),$(LIBMUSL_DIRENT_SRCS-y)))
diff --git a/Makefile.uk.musl.env b/Makefile.uk.musl.env
index b724725..cab319e 100644
--- a/Makefile.uk.musl.env
+++ b/Makefile.uk.musl.env
@@ -1,10 +1,28 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/env/__environ.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/env/__init_tls.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/env/__libc_start_main.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/env/__reset_tls.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/env/__stack_chk_fail.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/env/clearenv.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/env/getenv.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/env/putenv.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/env/setenv.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/env/unsetenv.c
+LIBMUSL_ENV_HDRS-y += $(LIBMUSL)/src/internal/atomic.h
+LIBMUSL_ENV_HDRS-y += $(LIBMUSL)/include/elf.h
+LIBMUSL_ENV_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_ENV_HDRS-y += $(LIBMUSL)/include/fcntl.h
+LIBMUSL_ENV_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_ENV_HDRS-y += $(LIBMUSL)/include/limits.h
+LIBMUSL_ENV_HDRS-y += $(LIBMUSL)/include/poll.h
+LIBMUSL_ENV_HDRS-y += $(LIBMUSL)/src/internal/pthread_impl.h
+LIBMUSL_ENV_HDRS-y += $(LIBMUSL)/include/signal.h
+LIBMUSL_ENV_HDRS-y += $(LIBMUSL)/include/stddef.h
+LIBMUSL_ENV_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_ENV_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_ENV_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_ENV_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+LIBMUSL_ENV_HDRS-y += $(LIBMUSL)/include/sys/mman.h
+
+LIBMUSL_ENV_SRCS-y += $(LIBMUSL)/src/env/__environ.c
+LIBMUSL_ENV_SRCS-y += $(LIBMUSL)/src/env/__init_tls.c
+LIBMUSL_ENV_SRCS-y += $(LIBMUSL)/src/env/__libc_start_main.c
+LIBMUSL_ENV_SRCS-y += $(LIBMUSL)/src/env/__reset_tls.c
+LIBMUSL_ENV_SRCS-y += $(LIBMUSL)/src/env/__stack_chk_fail.c
+LIBMUSL_ENV_SRCS-y += $(LIBMUSL)/src/env/clearenv.c
+LIBMUSL_ENV_SRCS-y += $(LIBMUSL)/src/env/getenv.c
+LIBMUSL_ENV_SRCS-y += $(LIBMUSL)/src/env/putenv.c
+LIBMUSL_ENV_SRCS-y += $(LIBMUSL)/src/env/setenv.c
+LIBMUSL_ENV_SRCS-y += $(LIBMUSL)/src/env/unsetenv.c
+
+$(eval $(call _libmusl_import_lib,env,$(LIBMUSL_ENV_HDRS-y),$(LIBMUSL_ENV_SRCS-y)))
diff --git a/Makefile.uk.musl.errno b/Makefile.uk.musl.errno
index d43226e..985f93a 100644
--- a/Makefile.uk.musl.errno
+++ b/Makefile.uk.musl.errno
@@ -1,2 +1,11 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/errno/__errno_location.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/errno/strerror.c
+LIBMUSL_ERRNO_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_ERRNO_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_ERRNO_HDRS-y += $(LIBMUSL)/src/internal/locale_impl.h
+LIBMUSL_ERRNO_HDRS-y += $(LIBMUSL)/src/internal/pthread_impl.h
+LIBMUSL_ERRNO_HDRS-y += $(LIBMUSL)/src/errno/__strerror.h
+LIBMUSL_ERRNO_HDRS-y += $(LIBMUSL)/include/string.h
+
+LIBMUSL_ERRNO_SRCS-y += $(LIBMUSL)/src/errno/__errno_location.c
+LIBMUSL_ERRNO_SRCS-y += $(LIBMUSL)/src/errno/strerror.c
+
+$(eval $(call _libmusl_import_lib,errno,$(LIBMUSL_ERRNO_HDRS-y),$(LIBMUSL_ERRNO_SRCS-y)))
diff --git a/Makefile.uk.musl.exit b/Makefile.uk.musl.exit
index eea591c..79aa64d 100644
--- a/Makefile.uk.musl.exit
+++ b/Makefile.uk.musl.exit
@@ -1,8 +1,19 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/exit/_Exit.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/exit/abort.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/exit/arm/__aeabi_atexit.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/exit/assert.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/exit/at_quick_exit.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/exit/atexit.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/exit/exit.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/exit/quick_exit.c
+LIBMUSL_EXIT_HDRS-y += $(LIBMUSL)/src/internal/atomic.h
+LIBMUSL_EXIT_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_EXIT_HDRS-y += $(LIBMUSL)/src/internal/pthread_impl.h
+LIBMUSL_EXIT_HDRS-y += $(LIBMUSL)/include/signal.h
+LIBMUSL_EXIT_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_EXIT_HDRS-y += $(LIBMUSL)/include/stdio.h
+LIBMUSL_EXIT_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_EXIT_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+
+LIBMUSL_EXIT_SRCS-y += $(LIBMUSL)/src/exit/_Exit.c
+LIBMUSL_EXIT_SRCS-y += $(LIBMUSL)/src/exit/abort.c
+LIBMUSL_EXIT_SRCS-y += $(LIBMUSL)/src/exit/arm/__aeabi_atexit.c
+LIBMUSL_EXIT_SRCS-y += $(LIBMUSL)/src/exit/assert.c
+LIBMUSL_EXIT_SRCS-y += $(LIBMUSL)/src/exit/at_quick_exit.c
+LIBMUSL_EXIT_SRCS-y += $(LIBMUSL)/src/exit/atexit.c
+LIBMUSL_EXIT_SRCS-y += $(LIBMUSL)/src/exit/exit.c
+LIBMUSL_EXIT_SRCS-y += $(LIBMUSL)/src/exit/quick_exit.c
+
+$(eval $(call _libmusl_import_lib,exit,$(LIBMUSL_EXIT_HDRS-y),$(LIBMUSL_EXIT_SRCS-y)))
diff --git a/Makefile.uk.musl.fcntl b/Makefile.uk.musl.fcntl
index b2f8d2b..78a94c8 100644
--- a/Makefile.uk.musl.fcntl
+++ b/Makefile.uk.musl.fcntl
@@ -1,6 +1,14 @@
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/fcntl/creat.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/fcntl/fcntl.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/fcntl/open.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/fcntl/openat.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/fcntl/posix_fadvise.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/fcntl/posix_fallocate.c
+LIBMUSL_FCNTL_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_FCNTL_HDRS-y += $(LIBMUSL)/include/fcntl.h
+LIBMUSL_FCNTL_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_FCNTL_HDRS-y += $(LIBMUSL)/include/stdarg.h
+LIBMUSL_FCNTL_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+
+#LIBMUSL_FCNTL_SRCS-y += $(LIBMUSL)/src/fcntl/creat.c
+#LIBMUSL_FCNTL_SRCS-y += $(LIBMUSL)/src/fcntl/fcntl.c
+#LIBMUSL_FCNTL_SRCS-y += $(LIBMUSL)/src/fcntl/open.c
+#LIBMUSL_FCNTL_SRCS-y += $(LIBMUSL)/src/fcntl/openat.c
+#LIBMUSL_FCNTL_SRCS-y += $(LIBMUSL)/src/fcntl/posix_fadvise.c
+LIBMUSL_FCNTL_SRCS-y += $(LIBMUSL)/src/fcntl/posix_fallocate.c
+
+$(eval $(call _libmusl_import_lib,fcntl,$(LIBMUSL_FCNTL_HDRS-y),$(LIBMUSL_FCNTL_SRCS-y)))
diff --git a/Makefile.uk.musl.fenv b/Makefile.uk.musl.fenv
index 355beca..62e46b1 100644
--- a/Makefile.uk.musl.fenv
+++ b/Makefile.uk.musl.fenv
@@ -1,32 +1,37 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/__flt_rounds.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/fegetexceptflag.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/feholdexcept.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/fesetexceptflag.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/fesetround.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/feupdateenv.c
+LIBMUSL_FENV_HDRS-y += $(LIBMUSL)/include/fenv.h
+LIBMUSL_FENV_HDRS-y += $(LIBMUSL)/include/float.h
+
+LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/__flt_rounds.c
+LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/fegetexceptflag.c
+LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/feholdexcept.c
+LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/fesetexceptflag.c
+LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/fesetround.c
+LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/feupdateenv.c
 
 ifeq (arm,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/arm/fenv-hf.S|arm
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/arm/fenv.c|arm
+LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/arm/fenv-hf.S|arm
+LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/arm/fenv.c|arm
 else ifeq (x86_32,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/i386/fenv.s|x86_32
+LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/i386/fenv.s|x86_32
 else ifeq (x86_64,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/x86_64/fenv.s|x86_64
+LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/x86_64/fenv.s|x86_64
 else
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/fenv.c
+LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/fenv.c
 endif
 
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/aarch64/fenv.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/mips/fenv-sf.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/mips/fenv.S
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/mips64/fenv-sf.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/mips64/fenv.S
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/mipsn32/fenv-sf.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/mipsn32/fenv.S
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/powerpc/fenv-sf.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/powerpc/fenv.S
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/powerpc64/fenv.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/s390x/fenv.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/sh/fenv-nofpu.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/sh/fenv.S
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/fenv/x32/fenv.s
+#LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/aarch64/fenv.s
+#LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/mips/fenv-sf.c
+#LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/mips/fenv.S
+#LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/mips64/fenv-sf.c
+#LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/mips64/fenv.S
+#LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/mipsn32/fenv-sf.c
+#LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/mipsn32/fenv.S
+#LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/powerpc/fenv-sf.c
+#LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/powerpc/fenv.S
+#LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/powerpc64/fenv.c
+#LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/s390x/fenv.c
+#LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/sh/fenv-nofpu.c
+#LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/sh/fenv.S
+#LIBMUSL_FENV_SRCS-y += $(LIBMUSL)/src/fenv/x32/fenv.s
+
+$(eval $(call _libmusl_import_lib,fenv,$(LIBMUSL_FENV_HDRS-y),$(LIBMUSL_FENV_SRCS-y)))
diff --git a/Makefile.uk.musl.internal b/Makefile.uk.musl.internal
index b65b15b..6f909ff 100644
--- a/Makefile.uk.musl.internal
+++ b/Makefile.uk.musl.internal
@@ -1,32 +1,48 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/floatscan.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/intscan.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/libc.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/procfdname.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/shgetc.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/syscall.c|internal
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/syscall_ret.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/vdso.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/version.c
+LIBMUSL_INTERNAL_HDRS-y += $(LIBMUSL)/include/ctype.h
+LIBMUSL_INTERNAL_HDRS-y += $(LIBMUSL)/include/elf.h
+LIBMUSL_INTERNAL_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_INTERNAL_HDRS-y += $(LIBMUSL)/include/float.h
+LIBMUSL_INTERNAL_HDRS-y += $(LIBMUSL)/src/internal/floatscan.h
+LIBMUSL_INTERNAL_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_INTERNAL_HDRS-y += $(LIBMUSL)/include/limits.h
+LIBMUSL_INTERNAL_HDRS-y += $(LIBMUSL)/include/link.h
+LIBMUSL_INTERNAL_HDRS-y += $(LIBMUSL)/include/math.h
+LIBMUSL_INTERNAL_HDRS-y += $(LIBMUSL)/src/internal/shgetc.h
+LIBMUSL_INTERNAL_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_INTERNAL_HDRS-y += $(LIBMUSL)/include/stdio.h
+LIBMUSL_INTERNAL_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_INTERNAL_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+LIBMUSL_INTERNAL_HDRS-y += $(LIBMUSL)/src/internal/version.h
+
+LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/floatscan.c
+LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/intscan.c
+LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/libc.c
+LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/procfdname.c
+LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/shgetc.c
+LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/syscall.c|internal
+LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/syscall_ret.c
+LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/vdso.c
+LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/version.c
 
 #ifeq (arm,$(CONFIG_UK_ARCH))
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/arm/syscall.s|arm
+#LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/arm/syscall.s|arm
 #else ifeq (x86_32,$(CONFIG_UK_ARCH))
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/i386/syscall.s|i386
+#LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/i386/syscall.s|i386
 #else ifeq (x86_64,$(CONFIG_UK_ARCH))
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/x86_64/syscall.s|x86_64
+#LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/x86_64/syscall.s|x86_64
 #endif
 
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/aarch64/syscall.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/microblaze/syscall.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/mips/syscall.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/mips64/syscall.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/mipsn32/syscall.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/or1k/syscall.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/powerpc/syscall.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/powerpc64/syscall.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/s390x/syscall.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/sh/__shcall.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/sh/syscall.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/internal/x32/syscall.s|x32
-
+#LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/aarch64/syscall.s
+#LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/microblaze/syscall.s
+#LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/mips/syscall.s
+#LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/mips64/syscall.s
+#LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/mipsn32/syscall.s
+#LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/or1k/syscall.s
+#LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/powerpc/syscall.s
+#LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/powerpc64/syscall.s
+#LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/s390x/syscall.s
+#LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/sh/__shcall.c
+#LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/sh/syscall.s
+#LIBMUSL_INTERNAL_SRCS-y += $(LIBMUSL)/src/internal/x32/syscall.s|x32
 
+$(eval $(call _libmusl_import_lib,internal,$(LIBMUSL_INTERNAL_HDRS-y),$(LIBMUSL_INTERNAL_SRCS-y)))
diff --git a/Makefile.uk.musl.ipc b/Makefile.uk.musl.ipc
index 02f4c25..a64d38e 100644
--- a/Makefile.uk.musl.ipc
+++ b/Makefile.uk.musl.ipc
@@ -1,13 +1,28 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ipc/ftok.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ipc/msgctl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ipc/msgget.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ipc/msgrcv.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ipc/msgsnd.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ipc/semctl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ipc/semget.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ipc/semop.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ipc/semtimedop.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ipc/shmat.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ipc/shmctl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ipc/shmdt.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ipc/shmget.c
+LIBMUSL_IPC_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_IPC_HDRS-y += $(LIBMUSL)/src/ipc/ipc.h
+LIBMUSL_IPC_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_IPC_HDRS-y += $(LIBMUSL)/include/limits.h
+LIBMUSL_IPC_HDRS-y += $(LIBMUSL)/include/stdarg.h
+LIBMUSL_IPC_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_IPC_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+LIBMUSL_IPC_HDRS-y += $(LIBMUSL)/include/sys/ipc.h
+LIBMUSL_IPC_HDRS-y += $(LIBMUSL)/include/sys/msg.h
+LIBMUSL_IPC_HDRS-y += $(LIBMUSL)/include/sys/sem.h
+LIBMUSL_IPC_HDRS-y += $(LIBMUSL)/include/sys/shm.h
+LIBMUSL_IPC_HDRS-y += $(LIBMUSL)/include/sys/stat.h
+
+LIBMUSL_IPC_SRCS-y += $(LIBMUSL)/src/ipc/ftok.c
+LIBMUSL_IPC_SRCS-y += $(LIBMUSL)/src/ipc/msgctl.c
+LIBMUSL_IPC_SRCS-y += $(LIBMUSL)/src/ipc/msgget.c
+LIBMUSL_IPC_SRCS-y += $(LIBMUSL)/src/ipc/msgrcv.c
+LIBMUSL_IPC_SRCS-y += $(LIBMUSL)/src/ipc/msgsnd.c
+LIBMUSL_IPC_SRCS-y += $(LIBMUSL)/src/ipc/semctl.c
+LIBMUSL_IPC_SRCS-y += $(LIBMUSL)/src/ipc/semget.c
+LIBMUSL_IPC_SRCS-y += $(LIBMUSL)/src/ipc/semop.c
+LIBMUSL_IPC_SRCS-y += $(LIBMUSL)/src/ipc/semtimedop.c
+LIBMUSL_IPC_SRCS-y += $(LIBMUSL)/src/ipc/shmat.c
+LIBMUSL_IPC_SRCS-y += $(LIBMUSL)/src/ipc/shmctl.c
+LIBMUSL_IPC_SRCS-y += $(LIBMUSL)/src/ipc/shmdt.c
+LIBMUSL_IPC_SRCS-y += $(LIBMUSL)/src/ipc/shmget.c
+
+$(eval $(call _libmusl_import_lib,ipc,$(LIBMUSL_IPC_HDRS-y),$(LIBMUSL_IPC_SRCS-y)))
diff --git a/Makefile.uk.musl.ldso b/Makefile.uk.musl.ldso
index a689004..7e1b74b 100644
--- a/Makefile.uk.musl.ldso
+++ b/Makefile.uk.musl.ldso
@@ -1,35 +1,47 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/__dlsym.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/dl_iterate_phdr.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/dladdr.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/dlclose.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/dlerror.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/dlinfo.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/dlopen.c
+LIBMUSL_LDSO_HDRS-y += $(LIBMUSL)/include/dlfcn.h
+LIBMUSL_LDSO_HDRS-y += $(LIBMUSL)/include/elf.h
+LIBMUSL_LDSO_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_LDSO_HDRS-y += $(LIBMUSL)/include/link.h
+LIBMUSL_LDSO_HDRS-y += $(LIBMUSL)/src/internal/pthread_impl.h
+LIBMUSL_LDSO_HDRS-y += $(LIBMUSL)/include/stdarg.h
+LIBMUSL_LDSO_HDRS-y += $(LIBMUSL)/include/stddef.h
+LIBMUSL_LDSO_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_LDSO_HDRS-y += $(LIBMUSL)/include/stdlib.h
+
+LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/__dlsym.c
+LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/dl_iterate_phdr.c
+LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/dladdr.c
+LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/dlclose.c
+LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/dlerror.c
+LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/dlinfo.c
+LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/dlopen.c
 
 ifeq (arm,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/arm/dlsym.s|arm
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/arm/find_exidx.c|arm
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/tlsdesc.c
+LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/arm/dlsym.s|arm
+LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/arm/find_exidx.c|arm
+LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/tlsdesc.c
 else ifeq (x86_32,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/i386/dlsym.s|x86_32
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/i386/tlsdesc.s|x86_32
+LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/i386/dlsym.s|x86_32
+LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/i386/tlsdesc.s|x86_32
 else ifeq (x86_64,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/x86_64/dlsym.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/x86_64/tlsdesc.s|x86_64
+LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/x86_64/dlsym.s|x86_64
+LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/x86_64/tlsdesc.s|x86_64
 else
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/tlsdesc.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/dlsym.c
+LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/tlsdesc.c
+LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/dlsym.c
 endif
 
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/aarch64/dlsym.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/aarch64/tlsdesc.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/microblaze/dlsym.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/mips/dlsym.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/mips64/dlsym.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/mipsn32/dlsym.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/or1k/dlsym.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/powerpc/dlsym.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/powerpc64/dlsym.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/s390x/dlsym.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/sh/dlsym.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/ldso/x32/dlsym.s
\ No newline at end of file
+#LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/aarch64/dlsym.s
+#LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/aarch64/tlsdesc.s
+#LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/microblaze/dlsym.s
+#LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/mips/dlsym.s
+#LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/mips64/dlsym.s
+#LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/mipsn32/dlsym.s
+#LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/or1k/dlsym.s
+#LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/powerpc/dlsym.s
+#LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/powerpc64/dlsym.s
+#LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/s390x/dlsym.s
+#LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/sh/dlsym.s
+#LIBMUSL_LDSO_SRCS-y += $(LIBMUSL)/src/ldso/x32/dlsym.s
+
+$(eval $(call _libmusl_import_lib,ldso,$(LIBMUSL_LDSO_HDRS-y),$(LIBMUSL_LDSO_SRCS-y)))
diff --git a/Makefile.uk.musl.legacy b/Makefile.uk.musl.legacy
index 9d73217..62b71f5 100644
--- a/Makefile.uk.musl.legacy
+++ b/Makefile.uk.musl.legacy
@@ -1,16 +1,40 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/legacy/cuserid.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/legacy/daemon.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/legacy/err.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/legacy/euidaccess.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/legacy/ftw.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/legacy/futimes.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/legacy/getdtablesize.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/legacy/getloadavg.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/legacy/getpagesize.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/legacy/getpass.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/legacy/getusershell.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/legacy/isastream.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/legacy/lutimes.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/legacy/ulimit.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/legacy/utmpx.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/legacy/valloc.c
+LIBMUSL_LEGACY_HDRS-y += $(LIBMUSL)/include/err.h
+LIBMUSL_LEGACY_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_LEGACY_HDRS-y += $(LIBMUSL)/include/fcntl.h
+LIBMUSL_LEGACY_HDRS-y += $(LIBMUSL)/include/ftw.h
+LIBMUSL_LEGACY_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_LEGACY_HDRS-y += $(LIBMUSL)/include/limits.h
+LIBMUSL_LEGACY_HDRS-y += $(LIBMUSL)/include/pwd.h
+LIBMUSL_LEGACY_HDRS-y += $(LIBMUSL)/include/stdarg.h
+LIBMUSL_LEGACY_HDRS-y += $(LIBMUSL)/include/stddef.h
+LIBMUSL_LEGACY_HDRS-y += $(LIBMUSL)/include/stdio.h
+LIBMUSL_LEGACY_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_LEGACY_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_LEGACY_HDRS-y += $(LIBMUSL)/include/stropts.h
+LIBMUSL_LEGACY_HDRS-y += $(LIBMUSL)/include/sys/resource.h
+LIBMUSL_LEGACY_HDRS-y += $(LIBMUSL)/include/sys/stat.h
+LIBMUSL_LEGACY_HDRS-y += $(LIBMUSL)/include/sys/sysinfo.h
+LIBMUSL_LEGACY_HDRS-y += $(LIBMUSL)/include/sys/time.h
+LIBMUSL_LEGACY_HDRS-y += $(LIBMUSL)/include/termios.h
+LIBMUSL_LEGACY_HDRS-y += $(LIBMUSL)/include/ulimit.h
+LIBMUSL_LEGACY_HDRS-y += $(LIBMUSL)/include/unistd.h
+LIBMUSL_LEGACY_HDRS-y += $(LIBMUSL)/include/utmpx.h
+
+LIBMUSL_LEGACY_SRCS-y += $(LIBMUSL)/src/legacy/cuserid.c
+LIBMUSL_LEGACY_SRCS-y += $(LIBMUSL)/src/legacy/daemon.c
+LIBMUSL_LEGACY_SRCS-y += $(LIBMUSL)/src/legacy/err.c
+#LIBMUSL_LEGACY_SRCS-y += $(LIBMUSL)/src/legacy/euidaccess.c
+LIBMUSL_LEGACY_SRCS-y += $(LIBMUSL)/src/legacy/ftw.c
+#LIBMUSL_LEGACY_SRCS-y += $(LIBMUSL)/src/legacy/futimes.c
+LIBMUSL_LEGACY_SRCS-y += $(LIBMUSL)/src/legacy/getdtablesize.c
+LIBMUSL_LEGACY_SRCS-y += $(LIBMUSL)/src/legacy/getloadavg.c
+#LIBMUSL_LEGACY_SRCS-y += $(LIBMUSL)/src/legacy/getpagesize.c
+LIBMUSL_LEGACY_SRCS-y += $(LIBMUSL)/src/legacy/getpass.c
+LIBMUSL_LEGACY_SRCS-y += $(LIBMUSL)/src/legacy/getusershell.c
+LIBMUSL_LEGACY_SRCS-y += $(LIBMUSL)/src/legacy/isastream.c
+#LIBMUSL_LEGACY_SRCS-y += $(LIBMUSL)/src/legacy/lutimes.c
+LIBMUSL_LEGACY_SRCS-y += $(LIBMUSL)/src/legacy/ulimit.c
+LIBMUSL_LEGACY_SRCS-y += $(LIBMUSL)/src/legacy/utmpx.c
+LIBMUSL_LEGACY_SRCS-y += $(LIBMUSL)/src/legacy/valloc.c
+
+$(eval $(call _libmusl_import_lib,legacy,$(LIBMUSL_LEGACY_HDRS-y),$(LIBMUSL_LEGACY_SRCS-y)))
diff --git a/Makefile.uk.musl.linux b/Makefile.uk.musl.linux
index 510f642..50dd483 100644
--- a/Makefile.uk.musl.linux
+++ b/Makefile.uk.musl.linux
@@ -1,57 +1,97 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/adjtime.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/adjtimex.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/arch_prctl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/brk.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/cache.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/cap.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/chroot.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/clock_adjtime.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/clone.c|linux
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/epoll.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/eventfd.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/fallocate.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/fanotify.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/flock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/inotify.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/ioperm.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/iopl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/klogctl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/module.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/mount.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/personality.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/pivot_root.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/ppoll.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/prctl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/prlimit.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/process_vm.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/ptrace.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/quotactl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/readahead.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/reboot.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/remap_file_pages.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/sbrk.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/sendfile.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/setfsgid.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/setfsuid.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/setgroups.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/sethostname.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/setns.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/settimeofday.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/signalfd.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/splice.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/stime.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/swap.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/sync_file_range.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/syncfs.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/sysinfo.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/tee.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/timerfd.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/unshare.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/utimes.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/vhangup.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/vmsplice.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/wait3.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/wait4.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/xattr.c
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/fcntl.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/poll.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/src/internal/pthread_impl.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sched.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/signal.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/stdarg.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/epoll.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/eventfd.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/fanotify.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/file.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/fsuid.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/inotify.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/io.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/klog.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/mman.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/mount.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/personality.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/prctl.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/ptrace.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/quota.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/reboot.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/resource.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/sendfile.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/signalfd.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/swap.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/sysinfo.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/time.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/timerfd.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/timex.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/uio.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/wait.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/sys/xattr.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/time.h
+LIBMUSL_LINUX_HDRS-y += $(LIBMUSL)/include/unistd.h
 
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/linux/x32/sysinfo.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/adjtime.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/adjtimex.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/arch_prctl.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/brk.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/cache.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/cap.c
+#LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/chroot.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/clock_adjtime.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/clone.c|linux
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/epoll.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/eventfd.c
+#LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/fallocate.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/fanotify.c
+#LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/flock.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/inotify.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/ioperm.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/iopl.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/klogctl.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/module.c
+#LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/mount.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/personality.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/pivot_root.c
+#LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/ppoll.c
+#LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/prctl.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/prlimit.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/process_vm.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/ptrace.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/quotactl.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/readahead.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/reboot.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/remap_file_pages.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/sbrk.c
+#LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/sendfile.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/setfsgid.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/setfsuid.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/setgroups.c
+#LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/sethostname.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/setns.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/settimeofday.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/signalfd.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/splice.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/stime.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/swap.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/sync_file_range.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/syncfs.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/sysinfo.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/tee.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/timerfd.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/unshare.c
+#LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/utimes.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/vhangup.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/vmsplice.c
+#LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/wait3.c
+#LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/wait4.c
+LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/xattr.c
+#LIBMUSL_LINUX_SRCS-y += $(LIBMUSL)/src/linux/x32/sysinfo.c
+
+$(eval $(call _libmusl_import_lib,linux,$(LIBMUSL_LINUX_HDRS-y),$(LIBMUSL_LINUX_SRCS-y)))
diff --git a/Makefile.uk.musl.locale b/Makefile.uk.musl.locale
index fd060d8..bffe0a2 100644
--- a/Makefile.uk.musl.locale
+++ b/Makefile.uk.musl.locale
@@ -1,25 +1,57 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/__lctrans.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/__mo_lookup.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/bind_textdomain_codeset.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/c_locale.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/catclose.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/catgets.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/catopen.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/dcngettext.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/duplocale.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/freelocale.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/iconv.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/iconv_close.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/langinfo.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/locale_map.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/localeconv.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/newlocale.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/pleval.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/setlocale.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/strcoll.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/strfmon.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/strxfrm.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/textdomain.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/uselocale.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/wcscoll.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/locale/wcsxfrm.c
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/src/internal/atomic.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/src/locale/big5.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/src/locale/codepages.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/include/ctype.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/src/locale/gb18030.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/src/locale/hkscs.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/include/iconv.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/src/locale/jis0208.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/src/locale/ksc.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/include/langinfo.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/src/locale/legacychars.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/include/libintl.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/include/limits.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/include/locale.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/src/internal/locale_impl.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/include/monetary.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/include/nl_types.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/src/internal/pthread_impl.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/src/locale/revjis.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/include/stdarg.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/include/stdio.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/include/strings.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/include/sys/stat.h
+LIBMUSL_LOCALE_HDRS-y += $(LIBMUSL)/include/wchar.h
+
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/__lctrans.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/__mo_lookup.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/bind_textdomain_codeset.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/c_locale.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/catclose.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/catgets.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/catopen.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/dcngettext.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/duplocale.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/freelocale.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/iconv.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/iconv_close.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/langinfo.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/locale_map.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/localeconv.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/newlocale.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/pleval.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/setlocale.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/strcoll.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/strfmon.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/strxfrm.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/textdomain.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/uselocale.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/wcscoll.c
+LIBMUSL_LOCALE_SRCS-y += $(LIBMUSL)/src/locale/wcsxfrm.c
+
+$(eval $(call _libmusl_import_lib,locale,$(LIBMUSL_LOCALE_HDRS-y),$(LIBMUSL_LOCALE_SRCS-y)))
diff --git a/Makefile.uk.musl.malloc b/Makefile.uk.musl.malloc
index 1d2c4d5..1ae2fab 100644
--- a/Makefile.uk.musl.malloc
+++ b/Makefile.uk.musl.malloc
@@ -1,9 +1,23 @@
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/malloc/__brk.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/malloc/aligned_alloc.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/malloc/calloc.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/malloc/expand_heap.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/malloc/lite_malloc.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/malloc/malloc.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/malloc/malloc_usable_size.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/malloc/memalign.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/malloc/posix_memalign.c
+# LIBMUSL_MALLOC_HDRS-y += $(LIBMUSL)/src/internal/atomic.h
+# LIBMUSL_MALLOC_HDRS-y += $(LIBMUSL)/include/errno.h
+# LIBMUSL_MALLOC_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+# LIBMUSL_MALLOC_HDRS-y += $(LIBMUSL)/include/limits.h
+# LIBMUSL_MALLOC_HDRS-y += $(LIBMUSL)/include/malloc.h
+# LIBMUSL_MALLOC_HDRS-y += $(LIBMUSL)/src/internal/pthread_impl.h
+# LIBMUSL_MALLOC_HDRS-y += $(LIBMUSL)/include/stdint.h
+# LIBMUSL_MALLOC_HDRS-y += $(LIBMUSL)/include/stdlib.h
+# LIBMUSL_MALLOC_HDRS-y += $(LIBMUSL)/include/string.h
+# LIBMUSL_MALLOC_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+# LIBMUSL_MALLOC_HDRS-y += $(LIBMUSL)/include/sys/mman.h
+
+#LIBMUSL_MALLOC_SRCS-y += $(LIBMUSL)/src/malloc/__brk.c
+#LIBMUSL_MALLOC_SRCS-y += $(LIBMUSL)/src/malloc/aligned_alloc.c
+#LIBMUSL_MALLOC_SRCS-y += $(LIBMUSL)/src/malloc/calloc.c
+#LIBMUSL_MALLOC_SRCS-y += $(LIBMUSL)/src/malloc/expand_heap.c
+#LIBMUSL_MALLOC_SRCS-y += $(LIBMUSL)/src/malloc/lite_malloc.c
+#LIBMUSL_MALLOC_SRCS-y += $(LIBMUSL)/src/malloc/malloc.c
+#LIBMUSL_MALLOC_SRCS-y += $(LIBMUSL)/src/malloc/malloc_usable_size.c
+#LIBMUSL_MALLOC_SRCS-y += $(LIBMUSL)/src/malloc/memalign.c
+#LIBMUSL_MALLOC_SRCS-y += $(LIBMUSL)/src/malloc/posix_memalign.c
+
+$(eval $(call _libmusl_import_lib,malloc,$(LIBMUSL_MALLOC_HDRS-y),$(LIBMUSL_MALLOC_SRCS-y)))
diff --git a/Makefile.uk.musl.math b/Makefile.uk.musl.math
index 682de34..37a4bb2 100644
--- a/Makefile.uk.musl.math
+++ b/Makefile.uk.musl.math
@@ -1,462 +1,478 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__cos.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__cosdf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__cosl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__expo2.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__expo2f.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__fpclassify.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__fpclassifyf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__fpclassifyl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__invtrigl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__polevll.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__rem_pio2.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__rem_pio2_large.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__rem_pio2f.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__rem_pio2l.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__signbit.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__signbitf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__signbitl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__sin.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__sindf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__sinl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__tan.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__tandf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/__tanl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/acos.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/acosf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/acosh.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/acoshf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/acoshl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/asin.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/asinf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/asinh.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/asinhf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/asinhl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/atan.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/atan2.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/atan2f.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/atanf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/atanh.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/atanhf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/atanhl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/cbrt.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/cbrtf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/cbrtl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/ceil.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/ceilf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/copysign.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/copysignf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/copysignl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/cos.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/cosf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/cosh.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/coshf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/coshl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/cosl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/erf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/erff.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/erfl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/exp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/exp10.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/exp10f.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/exp10l.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/exp2.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/exp2f.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/expf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/expm1.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/expm1f.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/fdim.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/fdimf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/fdiml.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/finite.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/finitef.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/floor.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/floorf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/fma.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/fmaf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/fmal.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/fmax.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/fmaxf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/fmaxl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/fmin.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/fminf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/fminl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/fmod.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/fmodf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/frexp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/frexpf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/frexpl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/hypot.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/hypotf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/hypotl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/scalb.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/scalbf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/scalbln.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/scalblnf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/scalblnl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/scalbn.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/scalbnf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/scalbnl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/signgam.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/significand.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/significandf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/sin.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/sincos.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/sincosf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/sincosl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/sinf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/sinh.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/sinhf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/sinhl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/sinl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/tan.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/tanf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/tanh.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/tanhf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/tanhl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/tanl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/tgamma.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/tgammaf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/tgammal.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/trunc.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/truncf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/ilogb.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/ilogbf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/ilogbl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/j0.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/j0f.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/j1.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/j1f.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/jn.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/jnf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/ldexp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/ldexpf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/ldexpl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/lgamma.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/lgamma_r.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/lgammaf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/lgammaf_r.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/lgammal.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/llround.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/llroundf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/llroundl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/log.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/log10.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/log10f.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/log1p.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/log1pf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/log2.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/log2f.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/logb.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/logbf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/logbl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/logf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/lround.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/lroundf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/lroundl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/modf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/modff.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/modfl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/nan.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/nanf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/nanl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/nearbyint.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/nearbyintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/nearbyintl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/nextafter.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/nextafterf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/nextafterl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/nexttoward.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/nexttowardf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/nexttowardl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/pow.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/remainder.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/remainderf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/remquo.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/remquof.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/remquol.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/rint.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/rintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/round.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/roundf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/roundl.c
+LIBMUSL_MATH_HDRS-y += $(LIBMUSL)/src/internal/atomic.h
+LIBMUSL_MATH_HDRS-y += $(LIBMUSL)/include/fenv.h
+LIBMUSL_MATH_HDRS-y += $(LIBMUSL)/include/float.h
+LIBMUSL_MATH_HDRS-y += $(LIBMUSL)/src/math/__invtrigl.h
+LIBMUSL_MATH_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_MATH_HDRS-y += $(LIBMUSL)/src/internal/libm.h
+LIBMUSL_MATH_HDRS-y += $(LIBMUSL)/include/limits.h
+LIBMUSL_MATH_HDRS-y += $(LIBMUSL)/include/math.h
+LIBMUSL_MATH_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_MATH_HDRS-y += $(LIBMUSL)/include/complex.h
+LIBMUSL_MATH_HDRS-y += $(LIBMUSL)/include/endian.h
+
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__cos.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__cosdf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__cosl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__expo2.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__expo2f.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__fpclassify.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__fpclassifyf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__fpclassifyl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__invtrigl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__polevll.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__rem_pio2.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__rem_pio2_large.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__rem_pio2f.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__rem_pio2l.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__signbit.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__signbitf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__signbitl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__sin.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__sindf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__sinl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__tan.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__tandf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/__tanl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/acos.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/acosf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/acosh.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/acoshf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/acoshl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/asin.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/asinf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/asinh.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/asinhf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/asinhl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/atan.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/atan2.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/atan2f.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/atanf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/atanh.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/atanhf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/atanhl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/cbrt.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/cbrtf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/cbrtl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/ceil.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/ceilf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/copysign.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/copysignf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/copysignl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/cos.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/cosf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/cosh.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/coshf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/coshl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/cosl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/erf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/erff.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/erfl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/exp.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/exp10.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/exp10f.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/exp10l.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/exp2.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/exp2f.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/expf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/expm1.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/expm1f.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/fdim.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/fdimf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/fdiml.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/finite.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/finitef.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/floor.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/floorf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/fma.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/fmaf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/fmal.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/fmax.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/fmaxf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/fmaxl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/fmin.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/fminf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/fminl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/fmod.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/fmodf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/frexp.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/frexpf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/frexpl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/hypot.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/hypotf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/hypotl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/scalb.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/scalbf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/scalbln.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/scalblnf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/scalblnl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/scalbn.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/scalbnf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/scalbnl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/signgam.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/significand.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/significandf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/sin.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/sincos.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/sincosf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/sincosl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/sinf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/sinh.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/sinhf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/sinhl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/sinl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/tan.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/tanf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/tanh.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/tanhf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/tanhl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/tanl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/tgamma.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/tgammaf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/tgammal.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/trunc.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/truncf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/ilogb.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/ilogbf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/ilogbl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/j0.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/j0f.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/j1.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/j1f.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/jn.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/jnf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/ldexp.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/ldexpf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/ldexpl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/lgamma.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/lgamma_r.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/lgammaf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/lgammaf_r.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/lgammal.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/llround.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/llroundf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/llroundl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/log.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/log10.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/log10f.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/log1p.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/log1pf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/log2.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/log2f.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/logb.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/logbf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/logbl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/logf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/lround.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/lroundf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/lroundl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/modf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/modff.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/modfl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/nan.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/nanf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/nanl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/nearbyint.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/nearbyintf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/nearbyintl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/nextafter.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/nextafterf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/nextafterl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/nexttoward.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/nexttowardf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/nexttowardl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/pow.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/remainder.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/remainderf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/remquo.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/remquof.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/remquol.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/rint.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/rintf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/round.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/roundf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/roundl.c
 
 ifeq (x86_32,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/__invtrigl.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/acos.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/acosf.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/acosl.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/asin.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/asinf.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/asinl.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/atan.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/atan2.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/atan2f.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/atan2l.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/atanf.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/atanl.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/ceil.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/ceilf.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/ceill.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/exp.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/exp2.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/exp2f.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/exp2l.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/expf.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/expl.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/expm1.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/expm1f.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/expm1l.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/fabs.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/fabsf.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/fabsl.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/floor.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/floorf.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/floorl.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/fmod.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/fmodf.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/fmodl.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/hypot.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/hypotf.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/ldexp.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/ldexpf.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/ldexpl.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/llrint.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/llrintf.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/llrintl.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/log.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/log10.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/log10f.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/log10l.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/log1p.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/log1pf.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/log1pl.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/log2.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/log2f.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/log2l.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/logf.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/logl.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/lrint.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/lrintf.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/lrintl.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/remainder.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/remainderf.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/remainderl.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/remquo.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/remquof.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/remquol.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/rint.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/rintf.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/rintl.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/scalbln.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/scalblnf.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/scalblnl.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/scalbn.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/scalbnf.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/scalbnl.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/sqrt.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/sqrtf.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/sqrtl.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/trunc.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/truncf.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/i386/truncl.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/__invtrigl.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/acos.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/acosf.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/acosl.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/asin.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/asinf.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/asinl.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/atan.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/atan2.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/atan2f.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/atan2l.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/atanf.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/atanl.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/ceil.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/ceilf.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/ceill.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/exp.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/exp2.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/exp2f.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/exp2l.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/expf.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/expl.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/expm1.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/expm1f.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/expm1l.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/fabs.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/fabsf.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/fabsl.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/floor.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/floorf.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/floorl.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/fmod.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/fmodf.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/fmodl.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/hypot.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/hypotf.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/ldexp.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/ldexpf.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/ldexpl.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/llrint.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/llrintf.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/llrintl.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/log.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/log10.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/log10f.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/log10l.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/log1p.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/log1pf.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/log1pl.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/log2.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/log2f.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/log2l.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/logf.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/logl.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/lrint.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/lrintf.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/lrintl.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/remainder.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/remainderf.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/remainderl.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/remquo.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/remquof.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/remquol.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/rint.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/rintf.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/rintl.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/scalbln.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/scalblnf.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/scalblnl.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/scalbn.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/scalbnf.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/scalbnl.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/sqrt.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/sqrtf.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/sqrtl.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/trunc.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/truncf.s|i386
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/i386/truncl.s|i386
 else ifeq (x86_64,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/__invtrigl.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/acosl.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/asinl.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/atan2l.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/atanl.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/ceill.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/exp2l.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/expl.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/expm1l.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/fabs.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/fabsf.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/fabsl.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/floorl.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/fmodl.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/llrint.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/llrintf.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/llrintl.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/log10l.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/log1pl.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/log2l.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/logl.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/lrint.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/lrintf.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/lrintl.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/remainderl.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/rintl.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/sqrt.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/sqrtf.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/sqrtl.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x86_64/truncl.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/__invtrigl.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/acosl.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/asinl.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/atan2l.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/atanl.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/ceill.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/exp2l.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/expl.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/expm1l.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/fabs.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/fabsf.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/fabsl.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/floorl.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/fmodl.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/llrint.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/llrintf.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/llrintl.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/log10l.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/log1pl.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/log2l.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/logl.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/lrint.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/lrintf.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/lrintl.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/remainderl.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/rintl.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/sqrt.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/sqrtf.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/sqrtl.s|x86_64
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x86_64/truncl.s|x86_64
 else ifeq (arm,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/acosl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/asinl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/atan2l.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/atanl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/expm1l.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/exp2l.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/expl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/fabsl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/floorl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/ceill.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/truncl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/fmodl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/lrintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/llrint.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/llrintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/llrintl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/log10l.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/log1pl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/log2l.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/logl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/lrint.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/lrintl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/remainderl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/rintl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/sqrtl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/arm/fabs.c|arm
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/arm/fabsf.c|arm
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/arm/sqrt.c|arm
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/arm/sqrtf.c|arm
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/acosl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/asinl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/atan2l.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/atanl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/expm1l.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/exp2l.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/expl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/fabsl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/floorl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/ceill.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/truncl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/fmodl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/lrintf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/llrint.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/llrintf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/llrintl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/log10l.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/log1pl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/log2l.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/logl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/lrint.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/lrintl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/remainderl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/rintl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/sqrtl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/arm/fabs.c|arm
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/arm/fabsf.c|arm
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/arm/sqrt.c|arm
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/arm/sqrtf.c|arm
 else
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/acosl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/asinl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/atan2l.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/atanl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/expm1l.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/exp2l.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/expl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/fabsl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/floorl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/ceill.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/truncl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/fmodl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/lrintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/llrint.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/llrintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/llrintl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/log10l.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/log1pl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/log2l.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/logl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/lrint.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/lrintl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/remainderl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/rintl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/sqrtl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/fabs.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/fabsf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/sqrt.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/sqrtf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/acosl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/asinl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/atan2l.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/atanl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/expm1l.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/exp2l.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/expl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/fabsl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/floorl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/ceill.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/truncl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/fmodl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/lrintf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/llrint.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/llrintf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/llrintl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/log10l.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/log1pl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/log2l.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/logl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/lrint.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/lrintl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/remainderl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/rintl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/sqrtl.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/fabs.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/fabsf.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/sqrt.c
+LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/sqrtf.c
 endif
 
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/ceil.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/ceilf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/fabs.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/fabsf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/floor.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/floorf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/fma.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/fmaf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/fmax.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/fmaxf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/fmin.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/fminf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/llrint.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/llrintf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/llround.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/llroundf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/lrint.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/lrintf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/lround.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/lroundf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/nearbyint.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/nearbyintf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/rint.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/rintf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/round.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/roundf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/sqrt.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/sqrtf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/trunc.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/aarch64/truncf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powerpc64/ceil.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powerpc64/ceilf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powerpc64/fabs.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powerpc64/fabsf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powerpc64/floor.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powerpc64/floorf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powerpc64/fma.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powerpc64/fmaf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powerpc64/fmax.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powerpc64/fmaxf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powerpc64/fmin.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powerpc64/fminf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powerpc64/lrint.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powerpc64/lrintf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powerpc64/lround.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powerpc64/lroundf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powerpc64/round.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powerpc64/roundf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powerpc64/sqrt.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powerpc64/sqrtf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powerpc64/trunc.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/powerpc64/truncf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/ceil.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/ceilf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/ceill.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/fabs.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/fabsf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/fabsl.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/floor.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/floorf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/floorl.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/nearbyint.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/nearbyintf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/nearbyintl.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/rint.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/rintf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/rintl.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/round.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/roundf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/roundl.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/sqrt.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/sqrtf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/sqrtl.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/trunc.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/truncf.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/s390x/truncl.c
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/__invtrigl.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/acosl.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/asinl.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/atan2l.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/atanl.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/ceill.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/exp2l.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/expl.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/expm1l.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/fabs.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/fabsf.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/fabsl.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/floorl.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/fmodl.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/llrint.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/llrintf.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/llrintl.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/log10l.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/log1pl.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/log2l.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/logl.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/lrint.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/lrintf.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/lrintl.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/remainderl.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/rintl.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/sqrt.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/sqrtf.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/sqrtl.s|x32
-# LIBMUSL_SRCS-y += $(LIBMUSL)/src/math/x32/truncl.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/ceil.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/ceilf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/fabs.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/fabsf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/floor.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/floorf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/fma.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/fmaf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/fmax.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/fmaxf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/fmin.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/fminf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/llrint.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/llrintf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/llround.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/llroundf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/lrint.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/lrintf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/lround.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/lroundf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/nearbyint.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/nearbyintf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/rint.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/rintf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/round.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/roundf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/sqrt.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/sqrtf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/trunc.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/aarch64/truncf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powerpc64/ceil.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powerpc64/ceilf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powerpc64/fabs.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powerpc64/fabsf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powerpc64/floor.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powerpc64/floorf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powerpc64/fma.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powerpc64/fmaf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powerpc64/fmax.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powerpc64/fmaxf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powerpc64/fmin.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powerpc64/fminf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powerpc64/lrint.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powerpc64/lrintf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powerpc64/lround.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powerpc64/lroundf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powerpc64/round.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powerpc64/roundf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powerpc64/sqrt.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powerpc64/sqrtf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powerpc64/trunc.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/powerpc64/truncf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/ceil.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/ceilf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/ceill.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/fabs.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/fabsf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/fabsl.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/floor.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/floorf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/floorl.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/nearbyint.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/nearbyintf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/nearbyintl.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/rint.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/rintf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/rintl.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/round.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/roundf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/roundl.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/sqrt.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/sqrtf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/sqrtl.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/trunc.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/truncf.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/s390x/truncl.c
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/__invtrigl.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/acosl.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/asinl.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/atan2l.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/atanl.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/ceill.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/exp2l.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/expl.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/expm1l.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/fabs.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/fabsf.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/fabsl.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/floorl.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/fmodl.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/llrint.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/llrintf.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/llrintl.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/log10l.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/log1pl.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/log2l.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/logl.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/lrint.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/lrintf.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/lrintl.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/remainderl.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/rintl.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/sqrt.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/sqrtf.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/sqrtl.s|x32
+# LIBMUSL_MATH_SRCS-y += $(LIBMUSL)/src/math/x32/truncl.s|x32
+
+# CINCLUDES-y += -D_GNU_SOURCE
+
+$(eval $(call _libmusl_import_lib,math,$(LIBMUSL_MATH_HDRS-y),$(LIBMUSL_MATH_SRCS-y)))
diff --git a/Makefile.uk.musl.misc b/Makefile.uk.musl.misc
index da54093..d62c1ab 100644
--- a/Makefile.uk.musl.misc
+++ b/Makefile.uk.musl.misc
@@ -1,38 +1,79 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/a64l.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/basename.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/dirname.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/ffs.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/ffsl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/ffsll.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/fmtmsg.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/forkpty.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/get_current_dir_name.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/getauxval.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/getdomainname.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/gethostid.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/getopt.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/getopt_long.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/getpriority.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/getresgid.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/getresuid.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/getrlimit.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/getrusage.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/getsubopt.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/initgroups.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/ioctl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/issetugid.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/lockf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/login_tty.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/mntent.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/nftw.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/openpty.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/ptsname.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/pty.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/realpath.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/setdomainname.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/setpriority.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/setrlimit.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/syscall.c|misc
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/syslog.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/uname.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/misc/wordexp.c
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/src/internal/atomic.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/dirent.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/fcntl.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/fmtmsg.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/ftw.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/getopt.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/grp.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/libgen.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/limits.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/src/internal/locale_impl.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/mntent.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/pthread.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/src/internal/pthread_impl.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/pty.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/signal.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/stdarg.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/stddef.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/stdio.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/strings.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/sys/auxv.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/sys/ioctl.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/syslog.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/sys/resource.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/sys/socket.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/sys/stat.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/sys/utsname.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/sys/wait.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/time.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/unistd.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/utmp.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/wchar.h
+LIBMUSL_MISC_HDRS-y += $(LIBMUSL)/include/wordexp.h
+
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/a64l.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/basename.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/dirname.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/ffs.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/ffsl.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/ffsll.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/fmtmsg.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/forkpty.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/get_current_dir_name.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/getauxval.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/getdomainname.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/gethostid.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/getopt.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/getopt_long.c
+#LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/getpriority.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/getresgid.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/getresuid.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/getrlimit.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/getrusage.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/getsubopt.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/initgroups.c
+#LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/ioctl.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/issetugid.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/lockf.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/login_tty.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/mntent.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/nftw.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/openpty.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/ptsname.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/pty.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/realpath.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/setdomainname.c
+#LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/setpriority.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/setrlimit.c
+#LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/syscall.c|misc
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/syslog.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/uname.c
+LIBMUSL_MISC_SRCS-y += $(LIBMUSL)/src/misc/wordexp.c
+
+$(eval $(call _libmusl_import_lib,misc,$(LIBMUSL_MISC_HDRS-y),$(LIBMUSL_MISC_SRCS-y)))
diff --git a/Makefile.uk.musl.mman b/Makefile.uk.musl.mman
index c989771..c64bc9d 100644
--- a/Makefile.uk.musl.mman
+++ b/Makefile.uk.musl.mman
@@ -1,13 +1,36 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mman/madvise.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mman/mincore.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mman/mlock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mman/mlockall.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mman/mmap.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mman/mprotect.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mman/mremap.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mman/msync.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mman/munlock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mman/munlockall.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mman/munmap.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mman/posix_madvise.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mman/shm_open.c
+LIBMUSL_MMAN_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_MMAN_HDRS-y += $(LIBMUSL)/include/fcntl.h
+LIBMUSL_MMAN_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_MMAN_HDRS-y += $(LIBMUSL)/include/limits.h
+LIBMUSL_MMAN_HDRS-y += $(LIBMUSL)/include/pthread.h
+LIBMUSL_MMAN_HDRS-y += $(LIBMUSL)/include/stdarg.h
+LIBMUSL_MMAN_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_MMAN_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_MMAN_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+LIBMUSL_MMAN_HDRS-y += $(LIBMUSL)/include/sys/syscall.h
+LIBMUSL_MMAN_HDRS-y += $(LIBMUSL)/include/sys/mman.h
+LIBMUSL_MMAN_HDRS-y += $(LIBMUSL)/include/unistd.h
+
+# ifeq (arm,$(ARCH))
+# LIBMUSL_SIGNAL_HDRS-y += $(LIBMUSL)/arch/arm/syscall_arch.h
+# else ifeq (x86_32,$(ARCH))
+# LIBMUSL_SIGNAL_HDRS-y += $(LIBMUSL)/arch/i386/syscall_arch.h
+# else ifeq (x86_64,$(ARCH))
+# LIBMUSL_SIGNAL_HDRS-y += $(LIBMUSL)/arch/x86_64/syscall_arch.h
+# endif
+
+LIBMUSL_MMAN_SRCS-y += $(LIBMUSL)/src/mman/madvise.c
+LIBMUSL_MMAN_SRCS-y += $(LIBMUSL)/src/mman/mincore.c
+LIBMUSL_MMAN_SRCS-y += $(LIBMUSL)/src/mman/mlock.c
+LIBMUSL_MMAN_SRCS-y += $(LIBMUSL)/src/mman/mlockall.c
+LIBMUSL_MMAN_SRCS-y += $(LIBMUSL)/src/mman/mmap.c
+LIBMUSL_MMAN_SRCS-y += $(LIBMUSL)/src/mman/mprotect.c
+LIBMUSL_MMAN_SRCS-y += $(LIBMUSL)/src/mman/mremap.c
+LIBMUSL_MMAN_SRCS-y += $(LIBMUSL)/src/mman/msync.c
+LIBMUSL_MMAN_SRCS-y += $(LIBMUSL)/src/mman/munlock.c
+LIBMUSL_MMAN_SRCS-y += $(LIBMUSL)/src/mman/munlockall.c
+LIBMUSL_MMAN_SRCS-y += $(LIBMUSL)/src/mman/munmap.c
+LIBMUSL_MMAN_SRCS-y += $(LIBMUSL)/src/mman/posix_madvise.c
+LIBMUSL_MMAN_SRCS-y += $(LIBMUSL)/src/mman/shm_open.c
+
+$(eval $(call _libmusl_import_lib,mman,$(LIBMUSL_MMAN_HDRS-y),$(LIBMUSL_MMAN_SRCS-y)))
diff --git a/Makefile.uk.musl.mq b/Makefile.uk.musl.mq
index 24da79c..48ec5f8 100644
--- a/Makefile.uk.musl.mq
+++ b/Makefile.uk.musl.mq
@@ -1,10 +1,22 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mq/mq_close.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mq/mq_getattr.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mq/mq_notify.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mq/mq_open.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mq/mq_receive.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mq/mq_send.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mq/mq_setattr.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mq/mq_timedreceive.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mq/mq_timedsend.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/mq/mq_unlink.c
+LIBMUSL_MQ_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_MQ_HDRS-y += $(LIBMUSL)/include/fcntl.h
+LIBMUSL_MQ_HDRS-y += $(LIBMUSL)/include/mqueue.h
+LIBMUSL_MQ_HDRS-y += $(LIBMUSL)/include/pthread.h
+LIBMUSL_MQ_HDRS-y += $(LIBMUSL)/include/signal.h
+LIBMUSL_MQ_HDRS-y += $(LIBMUSL)/include/stdarg.h
+LIBMUSL_MQ_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+LIBMUSL_MQ_HDRS-y += $(LIBMUSL)/include/sys/socket.h
+LIBMUSL_MQ_HDRS-y += $(LIBMUSL)/include/unistd.h
+
+LIBMUSL_MQ_SRCS-y += $(LIBMUSL)/src/mq/mq_close.c
+LIBMUSL_MQ_SRCS-y += $(LIBMUSL)/src/mq/mq_getattr.c
+LIBMUSL_MQ_SRCS-y += $(LIBMUSL)/src/mq/mq_notify.c
+LIBMUSL_MQ_SRCS-y += $(LIBMUSL)/src/mq/mq_open.c
+LIBMUSL_MQ_SRCS-y += $(LIBMUSL)/src/mq/mq_receive.c
+LIBMUSL_MQ_SRCS-y += $(LIBMUSL)/src/mq/mq_send.c
+LIBMUSL_MQ_SRCS-y += $(LIBMUSL)/src/mq/mq_setattr.c
+LIBMUSL_MQ_SRCS-y += $(LIBMUSL)/src/mq/mq_timedreceive.c
+LIBMUSL_MQ_SRCS-y += $(LIBMUSL)/src/mq/mq_timedsend.c
+LIBMUSL_MQ_SRCS-y += $(LIBMUSL)/src/mq/mq_unlink.c
+
+$(eval $(call _libmusl_import_lib,mq,$(LIBMUSL_MQ_HDRS-y),$(LIBMUSL_MQ_SRCS-y)))
diff --git a/Makefile.uk.musl.multibyte b/Makefile.uk.musl.multibyte
index fed5400..b4418eb 100644
--- a/Makefile.uk.musl.multibyte
+++ b/Makefile.uk.musl.multibyte
@@ -1,20 +1,31 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/multibyte/btowc.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/multibyte/c16rtomb.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/multibyte/c32rtomb.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/multibyte/internal.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/multibyte/mblen.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/multibyte/mbrlen.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/multibyte/mbrtoc16.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/multibyte/mbrtoc32.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/multibyte/mbrtowc.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/multibyte/mbsinit.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/multibyte/mbsnrtowcs.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/multibyte/mbsrtowcs.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/multibyte/mbstowcs.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/multibyte/mbtowc.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/multibyte/wcrtomb.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/multibyte/wcsnrtombs.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/multibyte/wcsrtombs.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/multibyte/wcstombs.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/multibyte/wctob.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/multibyte/wctomb.c
+LIBMUSL_MULTIBYTE_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_MULTIBYTE_HDRS-y += $(LIBMUSL)/src/multibyte/internal.h
+LIBMUSL_MULTIBYTE_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_MULTIBYTE_HDRS-y += $(LIBMUSL)/include/stdio.h
+LIBMUSL_MULTIBYTE_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_MULTIBYTE_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_MULTIBYTE_HDRS-y += $(LIBMUSL)/include/uchar.h
+LIBMUSL_MULTIBYTE_HDRS-y += $(LIBMUSL)/include/wchar.h
+
+LIBMUSL_MULTIBYTE_SRCS-y += $(LIBMUSL)/src/multibyte/btowc.c
+LIBMUSL_MULTIBYTE_SRCS-y += $(LIBMUSL)/src/multibyte/c16rtomb.c
+LIBMUSL_MULTIBYTE_SRCS-y += $(LIBMUSL)/src/multibyte/c32rtomb.c
+LIBMUSL_MULTIBYTE_SRCS-y += $(LIBMUSL)/src/multibyte/internal.c
+LIBMUSL_MULTIBYTE_SRCS-y += $(LIBMUSL)/src/multibyte/mblen.c
+LIBMUSL_MULTIBYTE_SRCS-y += $(LIBMUSL)/src/multibyte/mbrlen.c
+LIBMUSL_MULTIBYTE_SRCS-y += $(LIBMUSL)/src/multibyte/mbrtoc16.c
+LIBMUSL_MULTIBYTE_SRCS-y += $(LIBMUSL)/src/multibyte/mbrtoc32.c
+LIBMUSL_MULTIBYTE_SRCS-y += $(LIBMUSL)/src/multibyte/mbrtowc.c
+LIBMUSL_MULTIBYTE_SRCS-y += $(LIBMUSL)/src/multibyte/mbsinit.c
+LIBMUSL_MULTIBYTE_SRCS-y += $(LIBMUSL)/src/multibyte/mbsnrtowcs.c
+LIBMUSL_MULTIBYTE_SRCS-y += $(LIBMUSL)/src/multibyte/mbsrtowcs.c
+LIBMUSL_MULTIBYTE_SRCS-y += $(LIBMUSL)/src/multibyte/mbstowcs.c
+LIBMUSL_MULTIBYTE_SRCS-y += $(LIBMUSL)/src/multibyte/mbtowc.c
+LIBMUSL_MULTIBYTE_SRCS-y += $(LIBMUSL)/src/multibyte/wcrtomb.c
+LIBMUSL_MULTIBYTE_SRCS-y += $(LIBMUSL)/src/multibyte/wcsnrtombs.c
+LIBMUSL_MULTIBYTE_SRCS-y += $(LIBMUSL)/src/multibyte/wcsrtombs.c
+LIBMUSL_MULTIBYTE_SRCS-y += $(LIBMUSL)/src/multibyte/wcstombs.c
+LIBMUSL_MULTIBYTE_SRCS-y += $(LIBMUSL)/src/multibyte/wctob.c
+LIBMUSL_MULTIBYTE_SRCS-y += $(LIBMUSL)/src/multibyte/wctomb.c
+
+$(eval $(call _libmusl_import_lib,multibyte,$(LIBMUSL_MULTIBYTE_HDRS-y),$(LIBMUSL_MULTIBYTE_SRCS-y)))
diff --git a/Makefile.uk.musl.network b/Makefile.uk.musl.network
index b0879a3..bf65608 100644
--- a/Makefile.uk.musl.network
+++ b/Makefile.uk.musl.network
@@ -1,77 +1,115 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/accept.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/accept4.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/bind.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/connect.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/dn_comp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/dn_expand.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/dn_skipname.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/dns_parse.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/ent.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/ether.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/freeaddrinfo.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/gai_strerror.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/getaddrinfo.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/gethostbyaddr.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/gethostbyaddr_r.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/gethostbyname.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/gethostbyname2.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/gethostbyname2_r.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/gethostbyname_r.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/getifaddrs.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/getnameinfo.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/getpeername.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/getservbyname.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/getservbyname_r.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/getservbyport.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/getservbyport_r.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/getsockname.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/getsockopt.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/h_errno.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/herror.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/hstrerror.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/htonl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/htons.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/if_freenameindex.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/if_indextoname.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/if_nameindex.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/if_nametoindex.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/in6addr_any.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/in6addr_loopback.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/inet_addr.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/inet_aton.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/inet_legacy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/inet_ntoa.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/inet_ntop.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/inet_pton.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/listen.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/lookup_ipliteral.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/lookup_name.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/lookup_serv.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/netlink.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/netname.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/ns_parse.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/ntohl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/ntohs.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/proto.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/recv.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/recvfrom.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/recvmmsg.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/recvmsg.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/res_init.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/res_mkquery.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/res_msend.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/res_query.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/res_querydomain.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/res_send.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/res_state.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/resolvconf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/send.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/sendmmsg.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/sendmsg.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/sendto.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/serv.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/setsockopt.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/shutdown.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/sockatmark.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/socket.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/network/socketpair.c
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/arpa/inet.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/arpa/nameser.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/byteswap.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/ctype.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/fcntl.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/ifaddrs.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/inttypes.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/limits.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/src/internal/locale_impl.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/src/network/lookup.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/netdb.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/net/if.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/netinet/ether.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/netinet/in.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/src/network/netlink.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/poll.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/pthread.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/resolv.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/stddef.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/stdio.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/src/internal/stdio_impl.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/sys/ioctl.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/time.h
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/unistd.h
+
+ifneq ($(CONFIG_LIBPOSIX_SOCKET),y)
+LIBMUSL_NETWORK_HDRS-y += $(LIBMUSL)/include/sys/socket.h
+
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/socket.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/accept.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/accept4.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/bind.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/shutdown.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/getpeername.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/getsockname.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/getsockopt.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/setsockopt.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/connect.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/listen.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/recv.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/recvfrom.c
+# LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/recvmmsg.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/recvmsg.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/send.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/sendmsg.c
+# LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/sendmmsg.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/sendto.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/socketpair.c
+endif
+
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/dn_comp.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/dn_expand.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/dn_skipname.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/dns_parse.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/ent.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/ether.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/freeaddrinfo.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gai_strerror.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/getaddrinfo.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyaddr.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyaddr_r.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyname.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyname2.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyname2_r.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyname_r.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/getifaddrs.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/getnameinfo.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/getservbyname.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/getservbyname_r.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/getservbyport.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/getservbyport_r.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/h_errno.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/herror.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/hstrerror.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/htonl.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/htons.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/if_freenameindex.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/if_indextoname.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/if_nameindex.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/if_nametoindex.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/in6addr_any.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/in6addr_loopback.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/inet_addr.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/inet_aton.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/inet_legacy.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/inet_ntoa.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/inet_ntop.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/inet_pton.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/lookup_ipliteral.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/lookup_name.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/lookup_serv.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/netlink.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/netname.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/ns_parse.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/ntohl.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/ntohs.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/proto.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/res_init.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/res_mkquery.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/res_msend.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/res_query.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/res_querydomain.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/res_send.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/res_state.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/resolvconf.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/serv.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/sockatmark.c
+
+$(eval $(call _libmusl_import_lib,network,$(LIBMUSL_NETWORK_HDRS-y),$(LIBMUSL_NETWORK_SRCS-y)))
diff --git a/Makefile.uk.musl.passwd b/Makefile.uk.musl.passwd
index a08cd6f..dbad5fd 100644
--- a/Makefile.uk.musl.passwd
+++ b/Makefile.uk.musl.passwd
@@ -1,20 +1,40 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/passwd/fgetgrent.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/passwd/fgetpwent.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/passwd/fgetspent.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/passwd/getgr_a.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/passwd/getgr_r.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/passwd/getgrent.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/passwd/getgrent_a.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/passwd/getgrouplist.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/passwd/getpw_a.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/passwd/getpw_r.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/passwd/getpwent.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/passwd/getpwent_a.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/passwd/getspent.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/passwd/getspnam.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/passwd/getspnam_r.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/passwd/lckpwdf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/passwd/nscd_query.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/passwd/putgrent.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/passwd/putpwent.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/passwd/putspent.c
+LIBMUSL_PASSWD_HDRS-y += $(LIBMUSL)/include/byteswap.h
+LIBMUSL_PASSWD_HDRS-y += $(LIBMUSL)/include/ctype.h
+LIBMUSL_PASSWD_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_PASSWD_HDRS-y += $(LIBMUSL)/include/fcntl.h
+LIBMUSL_PASSWD_HDRS-y += $(LIBMUSL)/include/grp.h
+LIBMUSL_PASSWD_HDRS-y += $(LIBMUSL)/include/limits.h
+LIBMUSL_PASSWD_HDRS-y += $(LIBMUSL)/src/passwd/nscd.h
+LIBMUSL_PASSWD_HDRS-y += $(LIBMUSL)/include/pthread.h
+LIBMUSL_PASSWD_HDRS-y += $(LIBMUSL)/include/pwd.h
+LIBMUSL_PASSWD_HDRS-y += $(LIBMUSL)/src/passwd/pwf.h
+LIBMUSL_PASSWD_HDRS-y += $(LIBMUSL)/include/shadow.h
+LIBMUSL_PASSWD_HDRS-y += $(LIBMUSL)/include/stdio.h
+LIBMUSL_PASSWD_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_PASSWD_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_PASSWD_HDRS-y += $(LIBMUSL)/include/sys/socket.h
+LIBMUSL_PASSWD_HDRS-y += $(LIBMUSL)/include/sys/stat.h
+LIBMUSL_PASSWD_HDRS-y += $(LIBMUSL)/include/unistd.h
+
+LIBMUSL_PASSWD_SRCS-y += $(LIBMUSL)/src/passwd/fgetgrent.c
+LIBMUSL_PASSWD_SRCS-y += $(LIBMUSL)/src/passwd/fgetpwent.c
+LIBMUSL_PASSWD_SRCS-y += $(LIBMUSL)/src/passwd/fgetspent.c
+LIBMUSL_PASSWD_SRCS-y += $(LIBMUSL)/src/passwd/getgr_a.c
+LIBMUSL_PASSWD_SRCS-y += $(LIBMUSL)/src/passwd/getgr_r.c
+LIBMUSL_PASSWD_SRCS-y += $(LIBMUSL)/src/passwd/getgrent.c
+LIBMUSL_PASSWD_SRCS-y += $(LIBMUSL)/src/passwd/getgrent_a.c
+LIBMUSL_PASSWD_SRCS-y += $(LIBMUSL)/src/passwd/getgrouplist.c
+LIBMUSL_PASSWD_SRCS-y += $(LIBMUSL)/src/passwd/getpw_a.c
+LIBMUSL_PASSWD_SRCS-y += $(LIBMUSL)/src/passwd/getpw_r.c
+LIBMUSL_PASSWD_SRCS-y += $(LIBMUSL)/src/passwd/getpwent.c
+LIBMUSL_PASSWD_SRCS-y += $(LIBMUSL)/src/passwd/getpwent_a.c
+LIBMUSL_PASSWD_SRCS-y += $(LIBMUSL)/src/passwd/getspent.c
+LIBMUSL_PASSWD_SRCS-y += $(LIBMUSL)/src/passwd/getspnam.c
+LIBMUSL_PASSWD_SRCS-y += $(LIBMUSL)/src/passwd/getspnam_r.c
+LIBMUSL_PASSWD_SRCS-y += $(LIBMUSL)/src/passwd/lckpwdf.c
+LIBMUSL_PASSWD_SRCS-y += $(LIBMUSL)/src/passwd/nscd_query.c
+LIBMUSL_PASSWD_SRCS-y += $(LIBMUSL)/src/passwd/putgrent.c
+LIBMUSL_PASSWD_SRCS-y += $(LIBMUSL)/src/passwd/putpwent.c
+LIBMUSL_PASSWD_SRCS-y += $(LIBMUSL)/src/passwd/putspent.c
+
+$(eval $(call _libmusl_import_lib,passwd,$(LIBMUSL_PASSWD_HDRS-y),$(LIBMUSL_PASSWD_SRCS-y)))
diff --git a/Makefile.uk.musl.prng b/Makefile.uk.musl.prng
index b4b786c..cfcccc2 100644
--- a/Makefile.uk.musl.prng
+++ b/Makefile.uk.musl.prng
@@ -1,11 +1,19 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/prng/__rand48_step.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/prng/__seed48.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/prng/drand48.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/prng/lcong48.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/prng/lrand48.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/prng/mrand48.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/prng/rand.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/prng/rand_r.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/prng/random.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/prng/seed48.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/prng/srand48.c
+LIBMUSL_PRNG_HDRS-y += $(LIBMUSL)/include/inttypes.h
+LIBMUSL_PRNG_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_PRNG_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_PRNG_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_PRNG_HDRS-y += $(LIBMUSL)/include/string.h
+
+LIBMUSL_PRNG_SRCS-y += $(LIBMUSL)/src/prng/__rand48_step.c
+LIBMUSL_PRNG_SRCS-y += $(LIBMUSL)/src/prng/__seed48.c
+LIBMUSL_PRNG_SRCS-y += $(LIBMUSL)/src/prng/drand48.c
+LIBMUSL_PRNG_SRCS-y += $(LIBMUSL)/src/prng/lcong48.c
+LIBMUSL_PRNG_SRCS-y += $(LIBMUSL)/src/prng/lrand48.c
+LIBMUSL_PRNG_SRCS-y += $(LIBMUSL)/src/prng/mrand48.c
+LIBMUSL_PRNG_SRCS-y += $(LIBMUSL)/src/prng/rand.c
+LIBMUSL_PRNG_SRCS-y += $(LIBMUSL)/src/prng/rand_r.c
+LIBMUSL_PRNG_SRCS-y += $(LIBMUSL)/src/prng/random.c
+LIBMUSL_PRNG_SRCS-y += $(LIBMUSL)/src/prng/seed48.c
+LIBMUSL_PRNG_SRCS-y += $(LIBMUSL)/src/prng/srand48.c
+
+$(eval $(call _libmusl_import_lib,prng,$(LIBMUSL_PRNG_HDRS-y),$(LIBMUSL_PRNG_SRCS-y)))
diff --git a/Makefile.uk.musl.process b/Makefile.uk.musl.process
index 1bc77e7..71b4042 100644
--- a/Makefile.uk.musl.process
+++ b/Makefile.uk.musl.process
@@ -1,42 +1,60 @@
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/execl.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/execle.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/execlp.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/execv.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/execve.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/execvp.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/fexecve.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/fork.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/posix_spawn.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/posix_spawn_file_actions_addclose.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/posix_spawn_file_actions_adddup2.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/posix_spawn_file_actions_addopen.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/posix_spawn_file_actions_destroy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/posix_spawn_file_actions_init.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/posix_spawnattr_destroy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/posix_spawnattr_getflags.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/posix_spawnattr_getpgroup.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/posix_spawnattr_getsigdefault.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/posix_spawnattr_getsigmask.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/posix_spawnattr_init.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/posix_spawnattr_sched.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/posix_spawnattr_setflags.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/posix_spawnattr_setpgroup.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/posix_spawnattr_setsigdefault.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/posix_spawnattr_setsigmask.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/posix_spawnp.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/system.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/wait.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/waitid.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/waitpid.c
+LIBMUSL_PROCESS_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_PROCESS_HDRS-y += $(LIBMUSL)/include/fcntl.h
+LIBMUSL_PROCESS_HDRS-y += $(LIBMUSL)/src/process/fdop.h
+LIBMUSL_PROCESS_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_PROCESS_HDRS-y += $(LIBMUSL)/include/limits.h
+LIBMUSL_PROCESS_HDRS-y += $(LIBMUSL)/src/internal/pthread_impl.h
+LIBMUSL_PROCESS_HDRS-y += $(LIBMUSL)/include/sched.h
+LIBMUSL_PROCESS_HDRS-y += $(LIBMUSL)/include/signal.h
+LIBMUSL_PROCESS_HDRS-y += $(LIBMUSL)/include/spawn.h
+LIBMUSL_PROCESS_HDRS-y += $(LIBMUSL)/include/stdarg.h
+LIBMUSL_PROCESS_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_PROCESS_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_PROCESS_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+LIBMUSL_PROCESS_HDRS-y += $(LIBMUSL)/include/sys/wait.h
+LIBMUSL_PROCESS_HDRS-y += $(LIBMUSL)/include/unistd.h
+
+#LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/execl.c
+#LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/execle.c
+#LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/execlp.c
+#LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/execv.c
+#LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/execve.c
+#LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/execvp.c
+#LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/fexecve.c
+#LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/fork.c
+LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/posix_spawn.c
+LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/posix_spawn_file_actions_addclose.c
+LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/posix_spawn_file_actions_adddup2.c
+LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/posix_spawn_file_actions_addopen.c
+LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/posix_spawn_file_actions_destroy.c
+LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/posix_spawn_file_actions_init.c
+LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/posix_spawnattr_destroy.c
+LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/posix_spawnattr_getflags.c
+LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/posix_spawnattr_getpgroup.c
+LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/posix_spawnattr_getsigdefault.c
+LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/posix_spawnattr_getsigmask.c
+LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/posix_spawnattr_init.c
+LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/posix_spawnattr_sched.c
+LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/posix_spawnattr_setflags.c
+LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/posix_spawnattr_setpgroup.c
+LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/posix_spawnattr_setsigdefault.c
+LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/posix_spawnattr_setsigmask.c
+#LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/posix_spawnp.c
+#LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/system.c
+#LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/wait.c
+LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/waitid.c
+#LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/waitpid.c
 
 ifeq (x86_32,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/i386/vfork.s|i386
+LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/i386/vfork.s|i386
 else ifeq (x86_64,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/x86_64/vfork.s|x86_64
+LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/x86_64/vfork.s|x86_64
 else
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/vfork.c
+LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/vfork.c
 endif
 
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/s390x/vfork.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/sh/vfork.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/process/x32/vfork.s
+#LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/s390x/vfork.s
+#LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/sh/vfork.s
+#LIBMUSL_PROCESS_SRCS-y += $(LIBMUSL)/src/process/x32/vfork.s
+
+$(eval $(call _libmusl_import_lib,process,$(LIBMUSL_PROCESS_HDRS-y),$(LIBMUSL_PROCESS_SRCS-y)))
diff --git a/Makefile.uk.musl.regex b/Makefile.uk.musl.regex
index e564903..edd7df1 100644
--- a/Makefile.uk.musl.regex
+++ b/Makefile.uk.musl.regex
@@ -1,6 +1,28 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/regex/fnmatch.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/regex/glob.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/regex/regcomp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/regex/regerror.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/regex/regexec.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/regex/tre-mem.c
+LIBMUSL_REGEX_HDRS-y += $(LIBMUSL)/include/assert.h
+LIBMUSL_REGEX_HDRS-y += $(LIBMUSL)/include/ctype.h
+LIBMUSL_REGEX_HDRS-y += $(LIBMUSL)/include/dirent.h
+LIBMUSL_REGEX_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_REGEX_HDRS-y += $(LIBMUSL)/include/fnmatch.h
+LIBMUSL_REGEX_HDRS-y += $(LIBMUSL)/include/glob.h
+LIBMUSL_REGEX_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_REGEX_HDRS-y += $(LIBMUSL)/include/limits.h
+LIBMUSL_REGEX_HDRS-y += $(LIBMUSL)/src/internal/locale_impl.h
+LIBMUSL_REGEX_HDRS-y += $(LIBMUSL)/include/regex.h
+LIBMUSL_REGEX_HDRS-y += $(LIBMUSL)/include/stddef.h
+LIBMUSL_REGEX_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_REGEX_HDRS-y += $(LIBMUSL)/include/stdio.h
+LIBMUSL_REGEX_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_REGEX_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_REGEX_HDRS-y += $(LIBMUSL)/include/sys/stat.h
+LIBMUSL_REGEX_HDRS-y += $(LIBMUSL)/src/regex/tre.h
+LIBMUSL_REGEX_HDRS-y += $(LIBMUSL)/include/wchar.h
+LIBMUSL_REGEX_HDRS-y += $(LIBMUSL)/include/wctype.h
+
+LIBMUSL_REGEX_SRCS-y += $(LIBMUSL)/src/regex/fnmatch.c
+LIBMUSL_REGEX_SRCS-y += $(LIBMUSL)/src/regex/glob.c
+LIBMUSL_REGEX_SRCS-y += $(LIBMUSL)/src/regex/regcomp.c
+LIBMUSL_REGEX_SRCS-y += $(LIBMUSL)/src/regex/regerror.c
+LIBMUSL_REGEX_SRCS-y += $(LIBMUSL)/src/regex/regexec.c
+LIBMUSL_REGEX_SRCS-y += $(LIBMUSL)/src/regex/tre-mem.c
+
+$(eval $(call _libmusl_import_lib,regex,$(LIBMUSL_REGEX_HDRS-y),$(LIBMUSL_REGEX_SRCS-y)))
diff --git a/Makefile.uk.musl.sched b/Makefile.uk.musl.sched
index efa511e..4fe268d 100644
--- a/Makefile.uk.musl.sched
+++ b/Makefile.uk.musl.sched
@@ -1,10 +1,19 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/sched/affinity.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/sched/sched_cpucount.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/sched/sched_get_priority_max.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/sched/sched_getcpu.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/sched/sched_getparam.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/sched/sched_getscheduler.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/sched/sched_rr_get_interval.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/sched/sched_setparam.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/sched/sched_setscheduler.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/sched/sched_yield.c
+LIBMUSL_SCHED_HDRS-y += $(LIBMUSL)/src/internal/atomic.h
+LIBMUSL_SCHED_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_SCHED_HDRS-y += $(LIBMUSL)/src/internal/pthread_impl.h
+LIBMUSL_SCHED_HDRS-y += $(LIBMUSL)/include/sched.h
+LIBMUSL_SCHED_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_SCHED_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+
+LIBMUSL_SCHED_SRCS-y += $(LIBMUSL)/src/sched/affinity.c
+LIBMUSL_SCHED_SRCS-y += $(LIBMUSL)/src/sched/sched_cpucount.c
+LIBMUSL_SCHED_SRCS-y += $(LIBMUSL)/src/sched/sched_get_priority_max.c
+LIBMUSL_SCHED_SRCS-y += $(LIBMUSL)/src/sched/sched_getcpu.c
+LIBMUSL_SCHED_SRCS-y += $(LIBMUSL)/src/sched/sched_getparam.c
+LIBMUSL_SCHED_SRCS-y += $(LIBMUSL)/src/sched/sched_getscheduler.c
+LIBMUSL_SCHED_SRCS-y += $(LIBMUSL)/src/sched/sched_rr_get_interval.c
+LIBMUSL_SCHED_SRCS-y += $(LIBMUSL)/src/sched/sched_setparam.c
+LIBMUSL_SCHED_SRCS-y += $(LIBMUSL)/src/sched/sched_setscheduler.c
+LIBMUSL_SCHED_SRCS-y += $(LIBMUSL)/src/sched/sched_yield.c
+
+$(eval $(call _libmusl_import_lib,sched,$(LIBMUSL_SCHED_HDRS-y),$(LIBMUSL_SCHED_SRCS-y)))
diff --git a/Makefile.uk.musl.search b/Makefile.uk.musl.search
index 9b34f3b..d611b93 100644
--- a/Makefile.uk.musl.search
+++ b/Makefile.uk.musl.search
@@ -1,5 +1,12 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/search/hsearch.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/search/insque.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/search/lsearch.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/search/tdestroy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/search/tsearch_avl.c
+LIBMUSL_SEARCH_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_SEARCH_HDRS-y += $(LIBMUSL)/include/search.h
+LIBMUSL_SEARCH_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_SEARCH_HDRS-y += $(LIBMUSL)/include/string.h
+
+LIBMUSL_SEARCH_SRCS-y += $(LIBMUSL)/src/search/hsearch.c
+LIBMUSL_SEARCH_SRCS-y += $(LIBMUSL)/src/search/insque.c
+LIBMUSL_SEARCH_SRCS-y += $(LIBMUSL)/src/search/lsearch.c
+LIBMUSL_SEARCH_SRCS-y += $(LIBMUSL)/src/search/tdestroy.c
+LIBMUSL_SEARCH_SRCS-y += $(LIBMUSL)/src/search/tsearch_avl.c
+
+$(eval $(call _libmusl_import_lib,search,$(LIBMUSL_SEARCH_HDRS-y),$(LIBMUSL_SEARCH_SRCS-y)))
diff --git a/Makefile.uk.musl.select b/Makefile.uk.musl.select
index 21c1a9a..3ac5a3f 100644
--- a/Makefile.uk.musl.select
+++ b/Makefile.uk.musl.select
@@ -1,3 +1,14 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/select/poll.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/select/pselect.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/select/select.c
+LIBMUSL_SELECT_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_SELECT_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_SELECT_HDRS-y += $(LIBMUSL)/include/poll.h
+LIBMUSL_SELECT_HDRS-y += $(LIBMUSL)/include/signal.h
+LIBMUSL_SELECT_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_SELECT_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+LIBMUSL_SELECT_HDRS-y += $(LIBMUSL)/include/sys/select.h
+LIBMUSL_SELECT_HDRS-y += $(LIBMUSL)/include/time.h
+
+LIBMUSL_SELECT_SRCS-y += $(LIBMUSL)/src/select/poll.c
+LIBMUSL_SELECT_SRCS-y += $(LIBMUSL)/src/select/pselect.c
+LIBMUSL_SELECT_SRCS-y += $(LIBMUSL)/src/select/select.c
+
+$(eval $(call _libmusl_import_lib,select,$(LIBMUSL_SELECT_HDRS-y),$(LIBMUSL_SELECT_SRCS-y)))
diff --git a/Makefile.uk.musl.setjmp b/Makefile.uk.musl.setjmp
index c4bf289..9a9b267 100644
--- a/Makefile.uk.musl.setjmp
+++ b/Makefile.uk.musl.setjmp
@@ -1,36 +1,38 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/setjmp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/longjmp.c
+LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/setjmp.c
+LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/longjmp.c
 
 ifeq (arm,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/arm/longjmp.s|arm
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/arm/setjmp.s|arm
+LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/arm/longjmp.s|arm
+LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/arm/setjmp.s|arm
 else ifeq (x86_32,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/i386/longjmp.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/i386/setjmp.s|i386
+LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/i386/longjmp.s|i386
+LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/i386/setjmp.s|i386
 else ifeq (x86_64,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/x86_64/longjmp.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/x86_64/setjmp.s|x86_64
+LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/x86_64/longjmp.s|x86_64
+LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/x86_64/setjmp.s|x86_64
 endif
 
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/aarch64/longjmp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/aarch64/setjmp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/microblaze/longjmp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/microblaze/setjmp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/mips/longjmp.S
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/mips/setjmp.S
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/mips64/longjmp.S
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/mips64/setjmp.S
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/mipsn32/longjmp.S
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/mipsn32/setjmp.S
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/or1k/longjmp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/or1k/setjmp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/powerpc/longjmp.S
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/powerpc/setjmp.S
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/powerpc64/longjmp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/powerpc64/setjmp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/s390x/longjmp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/s390x/setjmp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/sh/longjmp.S
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/sh/setjmp.S
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/x32/longjmp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/setjmp/x32/setjmp.s
+#LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/aarch64/longjmp.s
+#LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/aarch64/setjmp.s
+#LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/microblaze/longjmp.s
+#LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/microblaze/setjmp.s
+#LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/mips/longjmp.S
+#LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/mips/setjmp.S
+#LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/mips64/longjmp.S
+#LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/mips64/setjmp.S
+#LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/mipsn32/longjmp.S
+#LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/mipsn32/setjmp.S
+#LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/or1k/longjmp.s
+#LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/or1k/setjmp.s
+#LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/powerpc/longjmp.S
+#LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/powerpc/setjmp.S
+#LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/powerpc64/longjmp.s
+#LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/powerpc64/setjmp.s
+#LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/s390x/longjmp.s
+#LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/s390x/setjmp.s
+#LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/sh/longjmp.S
+#LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/sh/setjmp.S
+#LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/x32/longjmp.s
+#LIBMUSL_SETJMP_SRCS-y += $(LIBMUSL)/src/setjmp/x32/setjmp.s
+
+$(eval $(call _libmusl_import_lib,setjmp,$(LIBMUSL_SETJMP_HDRS-y),$(LIBMUSL_SETJMP_SRCS-y)))
diff --git a/Makefile.uk.musl.signal b/Makefile.uk.musl.signal
index 24969ef..a7af11f 100644
--- a/Makefile.uk.musl.signal
+++ b/Makefile.uk.musl.signal
@@ -1,72 +1,97 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/block.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/getitimer.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/kill.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/killpg.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/psiginfo.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/psignal.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/raise.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/setitimer.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigaction.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigaddset.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigaltstack.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigandset.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigdelset.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigemptyset.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigfillset.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sighold.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigignore.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/siginterrupt.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigisemptyset.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigismember.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/siglongjmp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/signal.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigorset.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigpause.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigpending.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigprocmask.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigqueue.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigrelse.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigrtmax.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigrtmin.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigset.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigsetjmp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigsetjmp_tail.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigsuspend.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigtimedwait.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigwait.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sigwaitinfo.c
+LIBMUSL_SIGNAL_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_SIGNAL_HDRS-y += $(LIBMUSL)/src/internal/ksigaction.h
+LIBMUSL_SIGNAL_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_SIGNAL_HDRS-y += $(LIBMUSL)/include/limits.h
+LIBMUSL_SIGNAL_HDRS-y += $(LIBMUSL)/src/internal/pthread_impl.h
+LIBMUSL_SIGNAL_HDRS-y += $(LIBMUSL)/include/setjmp.h
+LIBMUSL_SIGNAL_HDRS-y += $(LIBMUSL)/include/signal.h
+LIBMUSL_SIGNAL_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_SIGNAL_HDRS-y += $(LIBMUSL)/include/stdio.h
+LIBMUSL_SIGNAL_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_SIGNAL_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+LIBMUSL_SIGNAL_HDRS-y += $(LIBMUSL)/include/sys/syscall.h
+LIBMUSL_SIGNAL_HDRS-y += $(LIBMUSL)/include/sys/time.h
+LIBMUSL_SIGNAL_HDRS-y += $(LIBMUSL)/include/unistd.h
+
+ifeq (arm,$(ARCH))
+LIBMUSL_SIGNAL_HDRS-y += $(LIBMUSL)/arch/arm/bits/signal.h
+else ifeq (x86_32,$(ARCH))
+LIBMUSL_SIGNAL_HDRS-y += $(LIBMUSL)/arch/i386/bits/signal.h
+else ifeq (x86_64,$(ARCH))
+LIBMUSL_SIGNAL_HDRS-y += $(LIBMUSL)/arch/x86_64/bits/signal.h
+endif
+
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/block.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/getitimer.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/kill.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/killpg.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/psiginfo.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/psignal.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/raise.c
+#LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/setitimer.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigaction.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigaddset.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigaltstack.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigandset.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigdelset.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigemptyset.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigfillset.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sighold.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigignore.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/siginterrupt.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigisemptyset.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigismember.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/siglongjmp.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/signal.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigorset.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigpause.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigpending.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigprocmask.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigqueue.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigrelse.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigrtmax.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigrtmin.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigset.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigsetjmp.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigsetjmp_tail.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigsuspend.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigtimedwait.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigwait.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sigwaitinfo.c
 
 ifeq (x86_32,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/i386/restore.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/i386/sigsetjmp.s|i386
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/i386/restore.s|i386
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/i386/sigsetjmp.s|i386
 else ifeq (x86_64,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/x86_64/restore.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/x86_64/sigsetjmp.s|x86_64
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/x86_64/restore.s|x86_64
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/x86_64/sigsetjmp.s|x86_64
 else ifeq (arm,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/arm/restore.s|arm
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/arm/sigsetjmp.s|arm
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/arm/restore.s|arm
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/arm/sigsetjmp.s|arm
 else
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/restore.c
+LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/restore.c
 endif
 
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/aarch64/restore.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/aarch64/sigsetjmp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/microblaze/restore.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/microblaze/sigsetjmp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/mips/restore.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/mips/sigsetjmp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/mips64/restore.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/mips64/sigsetjmp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/mipsn32/restore.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/mipsn32/sigsetjmp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/or1k/sigsetjmp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/powerpc/restore.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/powerpc/sigsetjmp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/powerpc64/restore.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/powerpc64/sigsetjmp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/s390x/restore.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/s390x/sigsetjmp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sh/restore.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/sh/sigsetjmp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/x32/restore.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/signal/x32/sigsetjmp.s
+#LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/aarch64/restore.s
+#LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/aarch64/sigsetjmp.s
+#LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/microblaze/restore.s
+#LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/microblaze/sigsetjmp.s
+#LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/mips/restore.s
+#LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/mips/sigsetjmp.s
+#LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/mips64/restore.s
+#LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/mips64/sigsetjmp.s
+#LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/mipsn32/restore.s
+#LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/mipsn32/sigsetjmp.s
+#LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/or1k/sigsetjmp.s
+#LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/powerpc/restore.s
+#LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/powerpc/sigsetjmp.s
+#LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/powerpc64/restore.s
+#LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/powerpc64/sigsetjmp.s
+#LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/s390x/restore.s
+#LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/s390x/sigsetjmp.s
+#LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sh/restore.s
+#LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/sh/sigsetjmp.s
+#LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/x32/restore.s
+#LIBMUSL_SIGNAL_SRCS-y += $(LIBMUSL)/src/signal/x32/sigsetjmp.s
+
+$(eval $(call _libmusl_import_lib,signal,$(LIBMUSL_SIGNAL_HDRS-y),$(LIBMUSL_SIGNAL_SRCS-y)))
diff --git a/Makefile.uk.musl.stat b/Makefile.uk.musl.stat
index c754192..5ecc50b 100644
--- a/Makefile.uk.musl.stat
+++ b/Makefile.uk.musl.stat
@@ -1,20 +1,31 @@
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/stat/__xstat.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/stat/chmod.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/stat/fchmod.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stat/fchmodat.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/stat/fstat.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/stat/fstatat.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/stat/futimens.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stat/futimesat.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stat/lchmod.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/stat/lstat.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/stat/mkdir.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stat/mkdirat.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/stat/mkfifo.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stat/mkfifoat.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/stat/mknod.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stat/mknodat.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/stat/stat.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/stat/statvfs.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/stat/umask.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/stat/utimensat.c
+LIBMUSL_STAT_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_STAT_HDRS-y += $(LIBMUSL)/include/fcntl.h
+LIBMUSL_STAT_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_STAT_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+LIBMUSL_STAT_HDRS-y += $(LIBMUSL)/include/sys/statfs.h
+LIBMUSL_STAT_HDRS-y += $(LIBMUSL)/include/sys/stat.h
+LIBMUSL_STAT_HDRS-y += $(LIBMUSL)/include/sys/statvfs.h
+LIBMUSL_STAT_HDRS-y += $(LIBMUSL)/include/sys/time.h
+
+#LIBMUSL_STAT_SRCS-y += $(LIBMUSL)/src/stat/__xstat.c
+#LIBMUSL_STAT_SRCS-y += $(LIBMUSL)/src/stat/chmod.c
+#LIBMUSL_STAT_SRCS-y += $(LIBMUSL)/src/stat/fchmod.c
+LIBMUSL_STAT_SRCS-y += $(LIBMUSL)/src/stat/fchmodat.c
+#LIBMUSL_STAT_SRCS-y += $(LIBMUSL)/src/stat/fstat.c
+#LIBMUSL_STAT_SRCS-y += $(LIBMUSL)/src/stat/fstatat.c
+#LIBMUSL_STAT_SRCS-y += $(LIBMUSL)/src/stat/futimens.c
+LIBMUSL_STAT_SRCS-y += $(LIBMUSL)/src/stat/futimesat.c
+LIBMUSL_STAT_SRCS-y += $(LIBMUSL)/src/stat/lchmod.c
+#LIBMUSL_STAT_SRCS-y += $(LIBMUSL)/src/stat/lstat.c
+#LIBMUSL_STAT_SRCS-y += $(LIBMUSL)/src/stat/mkdir.c
+LIBMUSL_STAT_SRCS-y += $(LIBMUSL)/src/stat/mkdirat.c
+#LIBMUSL_STAT_SRCS-y += $(LIBMUSL)/src/stat/mkfifo.c
+LIBMUSL_STAT_SRCS-y += $(LIBMUSL)/src/stat/mkfifoat.c
+#LIBMUSL_STAT_SRCS-y += $(LIBMUSL)/src/stat/mknod.c
+LIBMUSL_STAT_SRCS-y += $(LIBMUSL)/src/stat/mknodat.c
+#LIBMUSL_STAT_SRCS-y += $(LIBMUSL)/src/stat/stat.c
+#LIBMUSL_STAT_SRCS-y += $(LIBMUSL)/src/stat/statvfs.c
+#LIBMUSL_STAT_SRCS-y += $(LIBMUSL)/src/stat/umask.c
+#LIBMUSL_STAT_SRCS-y += $(LIBMUSL)/src/stat/utimensat.c
+
+$(eval $(call _libmusl_import_lib,stat,$(LIBMUSL_STAT_HDRS-y),$(LIBMUSL_STAT_SRCS-y)))
diff --git a/Makefile.uk.musl.stdio b/Makefile.uk.musl.stdio
index 8a9254e..8e4417e 100644
--- a/Makefile.uk.musl.stdio
+++ b/Makefile.uk.musl.stdio
@@ -1,117 +1,149 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/__fclose_ca.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/__fdopen.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/__fmodeflags.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/__fopen_rb_ca.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/__lockfile.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/__overflow.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/__stdio_close.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/__stdio_exit.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/__stdio_read.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/__stdio_seek.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/__stdio_write.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/__stdout_write.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/__string_read.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/__toread.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/__towrite.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/__uflow.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/asprintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/clearerr.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/dprintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/ext.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/ext2.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fclose.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/feof.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/ferror.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fflush.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fgetc.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fgetln.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fgetpos.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fgets.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fgetwc.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fgetws.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fileno.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/flockfile.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fmemopen.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fopen.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fopencookie.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fprintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fputc.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fputs.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fputwc.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fputws.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fread.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/freopen.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fscanf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fseek.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fsetpos.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/ftell.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/ftrylockfile.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/funlockfile.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fwide.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fwprintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fwrite.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/fwscanf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/getc.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/getc_unlocked.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/getchar.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/getchar_unlocked.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/getdelim.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/getline.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/gets.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/getw.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/getwc.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/getwchar.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/ofl.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/ofl_add.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/open_memstream.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/open_wmemstream.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/pclose.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/perror.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/popen.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/printf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/putc.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/putc_unlocked.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/putchar.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/putchar_unlocked.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/puts.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/putw.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/putwc.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/putwchar.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/remove.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/rename.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/rewind.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/scanf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/setbuf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/setbuffer.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/setlinebuf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/setvbuf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/snprintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/sprintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/sscanf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/stderr.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/stdin.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/stdout.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/swprintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/swscanf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/tempnam.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/tmpfile.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/tmpnam.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/ungetc.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/ungetwc.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/vasprintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/vdprintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/vfprintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/vfscanf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/vfwprintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/vfwscanf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/vprintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/vscanf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/vsnprintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/vsprintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/vsscanf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/vswprintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/vswscanf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/vwprintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/vwscanf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/wprintf.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdio/wscanf.c
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/include/ctype.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/include/fcntl.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/include/float.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/src/internal/floatscan.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/src/internal/intscan.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/include/inttypes.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/include/limits.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/src/internal/locale_impl.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/include/math.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/src/internal/pthread_impl.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/src/internal/shgetc.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/include/spawn.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/include/stdarg.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/include/stddef.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/include/stdio_ext.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/include/stdio.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/src/internal/stdio_impl.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/include/sys/ioctl.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/include/sys/stat.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/include/sys/uio.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/include/unistd.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/include/wchar.h
+LIBMUSL_STDIO_HDRS-y += $(LIBMUSL)/include/wctype.h
+
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/__fclose_ca.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/__fdopen.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/__fmodeflags.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/__fopen_rb_ca.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/__lockfile.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/__overflow.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/__stdio_close.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/__stdio_exit.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/__stdio_read.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/__stdio_seek.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/__stdio_write.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/__stdout_write.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/__string_read.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/__toread.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/__towrite.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/__uflow.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/asprintf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/clearerr.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/dprintf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/ext.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/ext2.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fclose.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/feof.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/ferror.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fflush.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fgetc.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fgetln.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fgetpos.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fgets.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fgetwc.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fgetws.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fileno.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/flockfile.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fmemopen.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fopen.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fopencookie.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fprintf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fputc.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fputs.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fputwc.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fputws.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fread.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/freopen.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fscanf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fseek.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fsetpos.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/ftell.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/ftrylockfile.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/funlockfile.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fwide.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fwprintf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fwrite.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/fwscanf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/getc.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/getc_unlocked.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/getchar.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/getchar_unlocked.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/getdelim.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/getline.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/gets.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/getw.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/getwc.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/getwchar.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/ofl.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/ofl_add.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/open_memstream.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/open_wmemstream.c
+#LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/pclose.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/perror.c
+#LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/popen.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/printf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/putc.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/putc_unlocked.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/putchar.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/putchar_unlocked.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/puts.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/putw.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/putwc.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/putwchar.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/remove.c
+#LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/rename.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/rewind.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/scanf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/setbuf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/setbuffer.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/setlinebuf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/setvbuf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/snprintf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/sprintf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/sscanf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/stderr.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/stdin.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/stdout.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/swprintf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/swscanf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/tempnam.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/tmpfile.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/tmpnam.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/ungetc.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/ungetwc.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/vasprintf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/vdprintf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/vfprintf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/vfscanf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/vfwprintf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/vfwscanf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/vprintf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/vscanf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/vsnprintf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/vsprintf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/vsscanf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/vswprintf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/vswscanf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/vwprintf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/vwscanf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/wprintf.c
+LIBMUSL_STDIO_SRCS-y += $(LIBMUSL)/src/stdio/wscanf.c
+
+$(eval $(call _libmusl_import_lib,stdio,$(LIBMUSL_STDIO_HDRS-y),$(LIBMUSL_STDIO_SRCS-y)))
diff --git a/Makefile.uk.musl.stdlib b/Makefile.uk.musl.stdlib
index 21167f1..9529226 100644
--- a/Makefile.uk.musl.stdlib
+++ b/Makefile.uk.musl.stdlib
@@ -1,21 +1,39 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdlib/abs.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdlib/atof.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdlib/atoi.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdlib/atol.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdlib/atoll.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdlib/bsearch.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdlib/div.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdlib/ecvt.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdlib/fcvt.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdlib/gcvt.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdlib/imaxabs.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdlib/imaxdiv.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdlib/labs.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdlib/ldiv.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdlib/llabs.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdlib/lldiv.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdlib/qsort.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdlib/strtod.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdlib/strtol.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdlib/wcstod.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/stdlib/wcstol.c
+LIBMUSL_STDLIB_HDRS-y += $(LIBMUSL)/src/internal/atomic.h
+LIBMUSL_STDLIB_HDRS-y += $(LIBMUSL)/include/ctype.h
+LIBMUSL_STDLIB_HDRS-y += $(LIBMUSL)/src/internal/floatscan.h
+LIBMUSL_STDLIB_HDRS-y += $(LIBMUSL)/src/internal/intscan.h
+LIBMUSL_STDLIB_HDRS-y += $(LIBMUSL)/include/inttypes.h
+LIBMUSL_STDLIB_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_STDLIB_HDRS-y += $(LIBMUSL)/include/limits.h
+LIBMUSL_STDLIB_HDRS-y += $(LIBMUSL)/src/internal/shgetc.h
+LIBMUSL_STDLIB_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_STDLIB_HDRS-y += $(LIBMUSL)/include/stdio.h
+LIBMUSL_STDLIB_HDRS-y += $(LIBMUSL)/src/internal/stdio_impl.h
+LIBMUSL_STDLIB_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_STDLIB_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_STDLIB_HDRS-y += $(LIBMUSL)/include/wchar.h
+LIBMUSL_STDLIB_HDRS-y += $(LIBMUSL)/include/wctype.h
+
+LIBMUSL_STDLIB_SRCS-y += $(LIBMUSL)/src/stdlib/abs.c
+LIBMUSL_STDLIB_SRCS-y += $(LIBMUSL)/src/stdlib/atof.c
+LIBMUSL_STDLIB_SRCS-y += $(LIBMUSL)/src/stdlib/atoi.c
+LIBMUSL_STDLIB_SRCS-y += $(LIBMUSL)/src/stdlib/atol.c
+LIBMUSL_STDLIB_SRCS-y += $(LIBMUSL)/src/stdlib/atoll.c
+LIBMUSL_STDLIB_SRCS-y += $(LIBMUSL)/src/stdlib/bsearch.c
+LIBMUSL_STDLIB_SRCS-y += $(LIBMUSL)/src/stdlib/div.c
+LIBMUSL_STDLIB_SRCS-y += $(LIBMUSL)/src/stdlib/ecvt.c
+LIBMUSL_STDLIB_SRCS-y += $(LIBMUSL)/src/stdlib/fcvt.c
+LIBMUSL_STDLIB_SRCS-y += $(LIBMUSL)/src/stdlib/gcvt.c
+LIBMUSL_STDLIB_SRCS-y += $(LIBMUSL)/src/stdlib/imaxabs.c
+LIBMUSL_STDLIB_SRCS-y += $(LIBMUSL)/src/stdlib/imaxdiv.c
+LIBMUSL_STDLIB_SRCS-y += $(LIBMUSL)/src/stdlib/labs.c
+LIBMUSL_STDLIB_SRCS-y += $(LIBMUSL)/src/stdlib/ldiv.c
+LIBMUSL_STDLIB_SRCS-y += $(LIBMUSL)/src/stdlib/llabs.c
+LIBMUSL_STDLIB_SRCS-y += $(LIBMUSL)/src/stdlib/lldiv.c
+LIBMUSL_STDLIB_SRCS-y += $(LIBMUSL)/src/stdlib/qsort.c
+LIBMUSL_STDLIB_SRCS-y += $(LIBMUSL)/src/stdlib/strtod.c
+LIBMUSL_STDLIB_SRCS-y += $(LIBMUSL)/src/stdlib/strtol.c
+LIBMUSL_STDLIB_SRCS-y += $(LIBMUSL)/src/stdlib/wcstod.c
+LIBMUSL_STDLIB_SRCS-y += $(LIBMUSL)/src/stdlib/wcstol.c
+
+$(eval $(call _libmusl_import_lib,stdlib,$(LIBMUSL_STDLIB_HDRS-y),$(LIBMUSL_STDLIB_SRCS-y)))
diff --git a/Makefile.uk.musl.string b/Makefile.uk.musl.string
index 63794f5..45316b4 100644
--- a/Makefile.uk.musl.string
+++ b/Makefile.uk.musl.string
@@ -1,91 +1,108 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/bcmp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/bcopy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/bzero.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/index.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/memccpy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/memchr.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/memcmp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/memmem.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/mempcpy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/memrchr.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/rindex.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/stpcpy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/stpncpy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strcasecmp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strcasestr.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strcat.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strchr.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strchrnul.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strcmp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strcpy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strcspn.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strdup.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strerror_r.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strlcat.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strlcpy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strlen.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strncasecmp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strncat.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strncmp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strncpy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strndup.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strnlen.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strpbrk.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strrchr.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strsep.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strsignal.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strspn.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strstr.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strtok.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strtok_r.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/strverscmp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/swab.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcpcpy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcpncpy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcscasecmp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcscasecmp_l.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcscat.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcschr.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcscmp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcscpy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcscspn.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcsdup.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcslen.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcsncasecmp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcsncasecmp_l.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcsncat.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcsncmp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcsncpy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcsnlen.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcspbrk.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcsrchr.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcsspn.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcsstr.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcstok.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wcswcs.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wmemchr.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wmemcmp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wmemcpy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wmemmove.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/wmemset.c
+LIBMUSL_STRING_HDRS-y += $(LIBMUSL)/include/ctype.h
+LIBMUSL_STRING_HDRS-y += $(LIBMUSL)/include/endian.h
+LIBMUSL_STRING_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_STRING_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_STRING_HDRS-y += $(LIBMUSL)/include/limits.h
+LIBMUSL_STRING_HDRS-y += $(LIBMUSL)/src/internal/locale_impl.h
+LIBMUSL_STRING_HDRS-y += $(LIBMUSL)/include/signal.h
+LIBMUSL_STRING_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_STRING_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_STRING_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_STRING_HDRS-y += $(LIBMUSL)/include/strings.h
+LIBMUSL_STRING_HDRS-y += $(LIBMUSL)/include/unistd.h
+LIBMUSL_STRING_HDRS-y += $(LIBMUSL)/include/wchar.h
+LIBMUSL_STRING_HDRS-y += $(LIBMUSL)/include/wctype.h
+
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/bcmp.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/bcopy.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/bzero.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/index.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/memccpy.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/memchr.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/memcmp.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/memmem.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/mempcpy.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/memrchr.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/rindex.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/stpcpy.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/stpncpy.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strcasecmp.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strcasestr.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strcat.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strchr.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strchrnul.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strcmp.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strcpy.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strcspn.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strdup.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strerror_r.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strlcat.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strlcpy.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strlen.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strncasecmp.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strncat.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strncmp.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strncpy.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strndup.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strnlen.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strpbrk.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strrchr.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strsep.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strsignal.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strspn.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strstr.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strtok.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strtok_r.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/strverscmp.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/swab.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcpcpy.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcpncpy.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcscasecmp.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcscasecmp_l.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcscat.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcschr.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcscmp.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcscpy.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcscspn.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcsdup.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcslen.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcsncasecmp.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcsncasecmp_l.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcsncat.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcsncmp.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcsncpy.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcsnlen.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcspbrk.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcsrchr.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcsspn.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcsstr.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcstok.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wcswcs.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wmemchr.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wmemcmp.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wmemcpy.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wmemmove.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/wmemset.c
 
 ifeq (arm,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/arm/__aeabi_memcpy.s|arm
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/arm/__aeabi_memset.s|arm
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/arm/memcpy.c|arm
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/arm/memcpy_le.S|arm
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/memmove.c|arm
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/memset.c|arm
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/arm/__aeabi_memcpy.s|arm
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/arm/__aeabi_memset.s|arm
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/arm/memcpy.c|arm
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/arm/memcpy_le.S|arm
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/memmove.c|arm
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/memset.c|arm
 else ifeq (x86_32,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/i386/memcpy.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/i386/memmove.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/i386/memset.s|i386
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/i386/memcpy.s|i386
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/i386/memmove.s|i386
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/i386/memset.s|i386
 else ifeq (x86_64,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/x86_64/memcpy.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/x86_64/memmove.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/x86_64/memset.s|x86_64
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/x86_64/memcpy.s|x86_64
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/x86_64/memmove.s|x86_64
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/x86_64/memset.s|x86_64
 else
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/memcpy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/memmove.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/string/memset.c
-endif
\ No newline at end of file
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/memcpy.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/memmove.c
+LIBMUSL_STRING_SRCS-y += $(LIBMUSL)/src/string/memset.c
+endif
+
+$(eval $(call _libmusl_import_lib,string,$(LIBMUSL_STRING_HDRS-y),$(LIBMUSL_STRING_SRCS-y)))
diff --git a/Makefile.uk.musl.temp b/Makefile.uk.musl.temp
index 1107ffc..3d7f554 100644
--- a/Makefile.uk.musl.temp
+++ b/Makefile.uk.musl.temp
@@ -1,7 +1,19 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/temp/__randname.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/temp/mkdtemp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/temp/mkostemp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/temp/mkostemps.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/temp/mkstemp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/temp/mkstemps.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/temp/mktemp.c
+LIBMUSL_TEMP_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_TEMP_HDRS-y += $(LIBMUSL)/include/fcntl.h
+LIBMUSL_TEMP_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_TEMP_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_TEMP_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_TEMP_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_TEMP_HDRS-y += $(LIBMUSL)/include/sys/stat.h
+LIBMUSL_TEMP_HDRS-y += $(LIBMUSL)/include/time.h
+LIBMUSL_TEMP_HDRS-y += $(LIBMUSL)/include/unistd.h
+
+LIBMUSL_TEMP_SRCS-y += $(LIBMUSL)/src/temp/__randname.c
+LIBMUSL_TEMP_SRCS-y += $(LIBMUSL)/src/temp/mkdtemp.c
+LIBMUSL_TEMP_SRCS-y += $(LIBMUSL)/src/temp/mkostemp.c
+LIBMUSL_TEMP_SRCS-y += $(LIBMUSL)/src/temp/mkostemps.c
+LIBMUSL_TEMP_SRCS-y += $(LIBMUSL)/src/temp/mkstemp.c
+LIBMUSL_TEMP_SRCS-y += $(LIBMUSL)/src/temp/mkstemps.c
+LIBMUSL_TEMP_SRCS-y += $(LIBMUSL)/src/temp/mktemp.c
+
+$(eval $(call _libmusl_import_lib,temp,$(LIBMUSL_TEMP_HDRS-y),$(LIBMUSL_TEMP_SRCS-y)))
diff --git a/Makefile.uk.musl.termios b/Makefile.uk.musl.termios
index 734c13b..318fc92 100644
--- a/Makefile.uk.musl.termios
+++ b/Makefile.uk.musl.termios
@@ -1,10 +1,18 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/termios/cfgetospeed.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/termios/cfmakeraw.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/termios/cfsetospeed.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/termios/tcdrain.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/termios/tcflow.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/termios/tcflush.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/termios/tcgetattr.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/termios/tcgetsid.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/termios/tcsendbreak.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/termios/tcsetattr.c
+LIBMUSL_TERMIOS_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_TERMIOS_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_TERMIOS_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+LIBMUSL_TERMIOS_HDRS-y += $(LIBMUSL)/include/sys/ioctl.h
+LIBMUSL_TERMIOS_HDRS-y += $(LIBMUSL)/include/termios.h
+
+LIBMUSL_TERMIOS_SRCS-y += $(LIBMUSL)/src/termios/cfgetospeed.c
+LIBMUSL_TERMIOS_SRCS-y += $(LIBMUSL)/src/termios/cfmakeraw.c
+LIBMUSL_TERMIOS_SRCS-y += $(LIBMUSL)/src/termios/cfsetospeed.c
+LIBMUSL_TERMIOS_SRCS-y += $(LIBMUSL)/src/termios/tcdrain.c
+LIBMUSL_TERMIOS_SRCS-y += $(LIBMUSL)/src/termios/tcflow.c
+LIBMUSL_TERMIOS_SRCS-y += $(LIBMUSL)/src/termios/tcflush.c
+LIBMUSL_TERMIOS_SRCS-y += $(LIBMUSL)/src/termios/tcgetattr.c
+LIBMUSL_TERMIOS_SRCS-y += $(LIBMUSL)/src/termios/tcgetsid.c
+LIBMUSL_TERMIOS_SRCS-y += $(LIBMUSL)/src/termios/tcsendbreak.c
+LIBMUSL_TERMIOS_SRCS-y += $(LIBMUSL)/src/termios/tcsetattr.c
+
+$(eval $(call _libmusl_import_lib,termios,$(LIBMUSL_TERMIOS_HDRS-y),$(LIBMUSL_TERMIOS_SRCS-y)))
diff --git a/Makefile.uk.musl.thread b/Makefile.uk.musl.thread
index f5e567a..ceab827 100644
--- a/Makefile.uk.musl.thread
+++ b/Makefile.uk.musl.thread
@@ -1,197 +1,229 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/__futex.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/__lock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/__syscall_cp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/__timedwait.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/__tls_get_addr.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/__wait.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/call_once.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/cnd_broadcast.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/cnd_destroy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/cnd_init.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/cnd_signal.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/cnd_timedwait.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/cnd_wait.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/lock_ptc.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/mtx_destroy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/mtx_init.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/mtx_lock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/mtx_timedlock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/mtx_trylock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/mtx_unlock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_atfork.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_attr_destroy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_attr_get.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_attr_init.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_attr_setdetachstate.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_attr_setguardsize.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_attr_setinheritsched.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_attr_setschedparam.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_attr_setschedpolicy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_attr_setscope.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_attr_setstack.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_attr_setstacksize.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_barrier_destroy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_barrier_init.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_barrier_wait.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_barrierattr_destroy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_barrierattr_init.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_barrierattr_setpshared.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_cancel.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_cleanup_push.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_cond_broadcast.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_cond_destroy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_cond_init.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_cond_signal.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_cond_timedwait.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_cond_wait.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_condattr_destroy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_condattr_init.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_condattr_setclock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_condattr_setpshared.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_create.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_detach.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_equal.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_getattr_np.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_getconcurrency.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_getcpuclockid.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_getschedparam.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_getspecific.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_join.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_key_create.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_kill.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutex_consistent.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutex_destroy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutex_getprioceiling.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutex_init.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutex_lock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutex_setprioceiling.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutex_timedlock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutex_trylock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutex_unlock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutexattr_destroy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutexattr_init.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutexattr_setprotocol.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutexattr_setpshared.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutexattr_setrobust.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutexattr_settype.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_once.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlock_destroy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlock_init.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlock_rdlock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlock_timedrdlock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlock_timedwrlock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlock_tryrdlock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlock_trywrlock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlock_unlock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlock_wrlock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlockattr_destroy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlockattr_init.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlockattr_setpshared.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_self.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_setattr_default_np.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_setcancelstate.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_setcanceltype.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_setconcurrency.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_setname_np.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_setschedparam.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_setschedprio.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_setspecific.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_sigmask.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_spin_destroy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_spin_init.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_spin_lock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_spin_trylock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_spin_unlock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/pthread_testcancel.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/sem_destroy.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/sem_getvalue.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/sem_init.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/sem_open.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/sem_post.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/sem_timedwait.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/sem_trywait.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/sem_unlink.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/sem_wait.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/synccall.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/syscall_cp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/thrd_create.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/thrd_exit.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/thrd_join.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/thrd_sleep.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/thrd_yield.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/tls.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/tss_create.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/tss_delete.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/tss_set.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/vmlock.c
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/src/internal/atomic.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/include/ctype.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/include/dirent.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/src/internal/dynlink.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/include/elf.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/include/fcntl.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/src/internal/futex.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/include/limits.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/include/pthread.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/src/internal/pthread_impl.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/include/semaphore.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/include/signal.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/include/stdarg.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/include/stddef.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/include/stdio.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/src/internal/stdio_impl.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/include/sys/mman.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/include/sys/prctl.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/include/sys/stat.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/include/sys/syscall.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/include/threads.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/include/time.h
+LIBMUSL_THREAD_HDRS-y += $(LIBMUSL)/include/unistd.h
+
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/__futex.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/__lock.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/__syscall_cp.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/__timedwait.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/__tls_get_addr.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/__wait.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/call_once.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/cnd_broadcast.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/cnd_destroy.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/cnd_init.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/cnd_signal.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/cnd_timedwait.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/cnd_wait.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/lock_ptc.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/mtx_destroy.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/mtx_init.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/mtx_lock.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/mtx_timedlock.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/mtx_trylock.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/mtx_unlock.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_atfork.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_attr_destroy.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_attr_get.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_attr_init.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_attr_setdetachstate.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_attr_setguardsize.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_attr_setinheritsched.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_attr_setschedparam.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_attr_setschedpolicy.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_attr_setscope.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_attr_setstack.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_attr_setstacksize.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_barrier_destroy.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_barrier_init.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_barrier_wait.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_barrierattr_destroy.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_barrierattr_init.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_barrierattr_setpshared.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_cancel.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_cleanup_push.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_cond_broadcast.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_cond_destroy.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_cond_init.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_cond_signal.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_cond_timedwait.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_cond_wait.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_condattr_destroy.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_condattr_init.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_condattr_setclock.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_condattr_setpshared.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_create.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_detach.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_equal.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_getattr_np.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_getconcurrency.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_getcpuclockid.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_getschedparam.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_getspecific.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_join.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_key_create.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_kill.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutex_consistent.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutex_destroy.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutex_getprioceiling.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutex_init.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutex_lock.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutex_setprioceiling.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutex_timedlock.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutex_trylock.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutex_unlock.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutexattr_destroy.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutexattr_init.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutexattr_setprotocol.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutexattr_setpshared.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutexattr_setrobust.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_mutexattr_settype.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_once.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlock_destroy.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlock_init.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlock_rdlock.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlock_timedrdlock.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlock_timedwrlock.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlock_tryrdlock.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlock_trywrlock.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlock_unlock.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlock_wrlock.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlockattr_destroy.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlockattr_init.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_rwlockattr_setpshared.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_self.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_setattr_default_np.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_setcancelstate.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_setcanceltype.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_setconcurrency.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_setname_np.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_setschedparam.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_setschedprio.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_setspecific.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_sigmask.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_spin_destroy.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_spin_init.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_spin_lock.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_spin_trylock.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_spin_unlock.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/pthread_testcancel.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/sem_destroy.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/sem_getvalue.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/sem_init.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/sem_open.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/sem_post.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/sem_timedwait.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/sem_trywait.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/sem_unlink.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/sem_wait.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/synccall.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/syscall_cp.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/thrd_create.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/thrd_exit.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/thrd_join.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/thrd_sleep.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/thrd_yield.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/tls.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/tss_create.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/tss_delete.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/tss_set.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/vmlock.c
 
 ifeq (x86_32,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/i386/__set_thread_area.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/i386/__unmapself.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/i386/clone.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/i386/syscall_cp.s|i386
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/i386/tls.s|i386
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/i386/__set_thread_area.s|i386
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/i386/__unmapself.s|i386
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/i386/clone.s|i386
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/i386/syscall_cp.s|i386
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/i386/tls.s|i386
 else ifeq (x86_64,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/x86_64/__set_thread_area.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/x86_64/__unmapself.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/x86_64/clone.s|x86_64
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/x86_64/syscall_cp.s|x86_64
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/x86_64/__set_thread_area.s|x86_64
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/x86_64/__unmapself.s|x86_64
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/x86_64/clone.s|x86_64
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/x86_64/syscall_cp.s|x86_64
 else ifeq (arm,$(CONFIG_UK_ARCH))
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/arm/__aeabi_read_tp.s|arm
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/arm/__aeabi_read_tp_c.c|arm
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/arm/__set_thread_area.c|arm
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/arm/__unmapself.s|arm
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/arm/atomics.s|arm
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/arm/clone.s|arm
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/arm/syscall_cp.s|arm
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/arm/__aeabi_read_tp.s|arm
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/arm/__aeabi_read_tp_c.c|arm
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/arm/__set_thread_area.c|arm
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/arm/__unmapself.s|arm
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/arm/atomics.s|arm
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/arm/clone.s|arm
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/arm/syscall_cp.s|arm
 else
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/__set_thread_area.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/__unmapself.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/clone.c|thread
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/__set_thread_area.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/__unmapself.c
+LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/clone.c|thread
 endif
 
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/aarch64/__set_thread_area.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/aarch64/__unmapself.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/aarch64/clone.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/aarch64/syscall_cp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/microblaze/__set_thread_area.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/microblaze/__unmapself.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/microblaze/clone.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/microblaze/syscall_cp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/mips/__unmapself.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/mips/clone.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/mips/syscall_cp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/mips64/__unmapself.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/mips64/clone.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/mips64/syscall_cp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/mipsn32/__unmapself.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/mipsn32/clone.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/mipsn32/syscall_cp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/or1k/__set_thread_area.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/or1k/__unmapself.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/or1k/clone.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/or1k/syscall_cp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/powerpc/__set_thread_area.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/powerpc/__unmapself.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/powerpc/clone.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/powerpc/syscall_cp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/powerpc64/__set_thread_area.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/powerpc64/__unmapself.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/powerpc64/clone.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/powerpc64/syscall_cp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/s390x/__set_thread_area.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/s390x/__tls_get_offset.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/s390x/__unmapself.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/s390x/clone.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/s390x/syscall_cp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/sh/__set_thread_area.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/sh/__unmapself.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/sh/__unmapself_mmu.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/sh/atomics.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/sh/clone.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/sh/syscall_cp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/x32/__set_thread_area.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/x32/__unmapself.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/x32/clone.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/x32/syscall_cp.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/thread/x32/syscall_cp_fixup.c
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/aarch64/__set_thread_area.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/aarch64/__unmapself.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/aarch64/clone.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/aarch64/syscall_cp.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/microblaze/__set_thread_area.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/microblaze/__unmapself.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/microblaze/clone.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/microblaze/syscall_cp.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/mips/__unmapself.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/mips/clone.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/mips/syscall_cp.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/mips64/__unmapself.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/mips64/clone.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/mips64/syscall_cp.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/mipsn32/__unmapself.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/mipsn32/clone.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/mipsn32/syscall_cp.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/or1k/__set_thread_area.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/or1k/__unmapself.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/or1k/clone.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/or1k/syscall_cp.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/powerpc/__set_thread_area.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/powerpc/__unmapself.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/powerpc/clone.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/powerpc/syscall_cp.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/powerpc64/__set_thread_area.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/powerpc64/__unmapself.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/powerpc64/clone.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/powerpc64/syscall_cp.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/s390x/__set_thread_area.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/s390x/__tls_get_offset.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/s390x/__unmapself.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/s390x/clone.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/s390x/syscall_cp.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/sh/__set_thread_area.c
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/sh/__unmapself.c
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/sh/__unmapself_mmu.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/sh/atomics.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/sh/clone.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/sh/syscall_cp.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/x32/__set_thread_area.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/x32/__unmapself.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/x32/clone.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/x32/syscall_cp.s
+#LIBMUSL_THREAD_SRCS-y += $(LIBMUSL)/src/thread/x32/syscall_cp_fixup.c
+
+$(eval $(call _libmusl_import_lib,thread,$(LIBMUSL_THREAD_HDRS-y),$(LIBMUSL_THREAD_SRCS-y)))
diff --git a/Makefile.uk.musl.time b/Makefile.uk.musl.time
index db4a736..7330c96 100644
--- a/Makefile.uk.musl.time
+++ b/Makefile.uk.musl.time
@@ -1,40 +1,77 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/__asctime.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/__map_file.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/__month_to_secs.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/__secs_to_tm.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/__tm_to_secs.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/__tz.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/__year_to_secs.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/asctime.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/asctime_r.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/clock.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/clock_getcpuclockid.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/clock_getres.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/clock_gettime.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/clock_nanosleep.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/clock_settime.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/ctime.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/ctime_r.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/difftime.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/ftime.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/getdate.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/gettimeofday.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/gmtime.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/gmtime_r.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/localtime.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/localtime_r.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/mktime.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/nanosleep.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/strftime.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/strptime.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/time.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/timegm.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/timer_create.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/timer_delete.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/timer_getoverrun.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/timer_gettime.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/timer_settime.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/times.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/timespec_get.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/utime.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/time/wcsftime.c
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/src/internal/atomic.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/ctype.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/fcntl.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/langinfo.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/limits.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/locale.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/src/internal/locale_impl.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/pthread.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/src/internal/pthread_impl.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/setjmp.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/stddef.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/stdint.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/stdio.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/strings.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/sys/mman.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/sys/stat.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/sys/timeb.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/sys/time.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/sys/times.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/time.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/src/time/time_impl.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/unistd.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/utime.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/wchar.h
+LIBMUSL_TIME_HDRS-y += $(LIBMUSL)/include/nl_types.h
+
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/__asctime.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/__map_file.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/__month_to_secs.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/__secs_to_tm.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/__tm_to_secs.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/__tz.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/__year_to_secs.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/asctime.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/asctime_r.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/clock.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/clock_getcpuclockid.c
+#LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/clock_getres.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/clock_gettime.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/clock_nanosleep.c
+#LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/clock_settime.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/ctime.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/ctime_r.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/difftime.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/ftime.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/getdate.c
+#LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/gettimeofday.c
+#LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/gmtime.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/gmtime_r.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/localtime.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/localtime_r.c
+#LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/mktime.c
+#LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/nanosleep.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/strftime.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/strptime.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/time.c
+#LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/timegm.c
+
+ifneq ($(CONFIG_LIBUKTIME),y)
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/timer_create.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/timer_delete.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/timer_gettime.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/timer_settime.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/timer_getoverrun.c
+endif
+
+#LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/times.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/timespec_get.c
+#LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/utime.c
+LIBMUSL_TIME_SRCS-y += $(LIBMUSL)/src/time/wcsftime.c
+
+$(eval $(call _libmusl_import_lib,time,$(LIBMUSL_TIME_HDRS-y),$(LIBMUSL_TIME_SRCS-y)))
diff --git a/Makefile.uk.musl.unistd b/Makefile.uk.musl.unistd
index 1b02a3b..a4378b4 100644
--- a/Makefile.uk.musl.unistd
+++ b/Makefile.uk.musl.unistd
@@ -1,84 +1,107 @@
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/_exit.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/access.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/acct.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/alarm.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/chdir.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/chown.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/close.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/ctermid.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/dup.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/dup2.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/dup3.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/faccessat.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/fchdir.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/fchown.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/fchownat.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/fdatasync.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/fsync.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/ftruncate.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/getcwd.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/getegid.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/geteuid.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/getgid.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/getgroups.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/gethostname.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/getlogin.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/getlogin_r.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/getpgid.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/getpgrp.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/getpid.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/getppid.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/getsid.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/getuid.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/isatty.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/lchown.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/link.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/linkat.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/lseek.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/nice.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/pause.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/pipe.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/pipe2.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/posix_close.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/pread.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/preadv.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/pwrite.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/pwritev.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/read.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/readlink.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/readlinkat.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/readv.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/renameat.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/rmdir.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/setegid.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/seteuid.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/setgid.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/setpgid.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/setpgrp.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/setregid.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/setresgid.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/setresuid.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/setreuid.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/setsid.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/setuid.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/setxid.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/sleep.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/symlink.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/symlinkat.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/sync.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/tcgetpgrp.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/tcsetpgrp.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/truncate.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/ttyname.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/ttyname_r.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/ualarm.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/unlink.c
-LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/unlinkat.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/usleep.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/write.c
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/writev.c
+LIBMUSL_UNISTD_HDRS-y += $(LIBMUSL)/include/errno.h
+LIBMUSL_UNISTD_HDRS-y += $(LIBMUSL)/include/fcntl.h
+LIBMUSL_UNISTD_HDRS-y += $(LIBMUSL)/src/internal/libc.h
+LIBMUSL_UNISTD_HDRS-y += $(LIBMUSL)/include/limits.h
+LIBMUSL_UNISTD_HDRS-y += $(LIBMUSL)/src/internal/pthread_impl.h
+LIBMUSL_UNISTD_HDRS-y += $(LIBMUSL)/include/signal.h
+LIBMUSL_UNISTD_HDRS-y += $(LIBMUSL)/include/stdio.h
+LIBMUSL_UNISTD_HDRS-y += $(LIBMUSL)/include/stdlib.h
+LIBMUSL_UNISTD_HDRS-y += $(LIBMUSL)/include/string.h
+LIBMUSL_UNISTD_HDRS-y += $(LIBMUSL)/src/internal/syscall.h
+LIBMUSL_UNISTD_HDRS-y += $(LIBMUSL)/include/sys/ioctl.h
+LIBMUSL_UNISTD_HDRS-y += $(LIBMUSL)/include/sys/resource.h
+LIBMUSL_UNISTD_HDRS-y += $(LIBMUSL)/include/sys/stat.h
+LIBMUSL_UNISTD_HDRS-y += $(LIBMUSL)/include/sys/time.h
+LIBMUSL_UNISTD_HDRS-y += $(LIBMUSL)/include/sys/uio.h
+LIBMUSL_UNISTD_HDRS-y += $(LIBMUSL)/include/sys/utsname.h
+LIBMUSL_UNISTD_HDRS-y += $(LIBMUSL)/include/sys/wait.h
+LIBMUSL_UNISTD_HDRS-y += $(LIBMUSL)/include/termios.h
+LIBMUSL_UNISTD_HDRS-y += $(LIBMUSL)/include/time.h
+LIBMUSL_UNISTD_HDRS-y += $(LIBMUSL)/include/unistd.h
 
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/mips/pipe.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/mips64/pipe.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/mipsn32/pipe.s
-#LIBMUSL_SRCS-y += $(LIBMUSL)/src/unistd/sh/pipe.s
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/_exit.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/access.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/acct.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/alarm.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/chdir.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/chown.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/close.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/ctermid.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/dup.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/dup2.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/dup3.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/faccessat.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/fchdir.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/fchown.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/fchownat.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/fdatasync.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/fsync.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/ftruncate.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/getcwd.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/getegid.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/geteuid.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/getgid.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/getgroups.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/gethostname.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/getlogin.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/getlogin_r.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/getpgid.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/getpgrp.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/getpid.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/getppid.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/getsid.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/getuid.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/isatty.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/lchown.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/link.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/linkat.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/lseek.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/nice.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/pause.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/pipe.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/pipe2.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/posix_close.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/pread.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/preadv.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/pwrite.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/pwritev.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/read.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/readlink.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/readlinkat.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/readv.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/renameat.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/rmdir.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/setegid.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/seteuid.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/setgid.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/setpgid.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/setpgrp.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/setregid.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/setresgid.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/setresuid.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/setreuid.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/setsid.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/setuid.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/setxid.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/sleep.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/symlink.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/symlinkat.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/sync.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/tcgetpgrp.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/tcsetpgrp.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/truncate.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/ttyname.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/ttyname_r.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/ualarm.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/unlink.c
+LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/unlinkat.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/usleep.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/write.c
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/writev.c
+
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/mips/pipe.s
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/mips64/pipe.s
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/mipsn32/pipe.s
+#LIBMUSL_UNISTD_SRCS-y += $(LIBMUSL)/src/unistd/sh/pipe.s
+
+$(eval $(call _libmusl_import_lib,unistd,$(LIBMUSL_UNISTD_HDRS-y),$(LIBMUSL_UNISTD_SRCS-y)))
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 14 13:08:00 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 14 Jul 2020 13:08:00 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jvKf8-0004cB-G0; Tue, 14 Jul 2020 13:07:58 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=8/kp=AZ=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jvKf7-0004c6-Ge
 for minios-devel@lists.xen.org; Tue, 14 Jul 2020 13:07:57 +0000
X-Inumbo-ID: 080f4015-c5d3-11ea-930a-12813bfff9fa
Received: from mh-fa-0.lancs.ac.uk (unknown [148.88.65.130])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 080f4015-c5d3-11ea-930a-12813bfff9fa;
 Tue, 14 Jul 2020 13:07:55 +0000 (UTC)
Received: from p5087e57f.dip0.t-ipconnect.de ([80.135.229.127]
 helo=unknown.fritz.box)
 by mh-fa-0.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jvKf4-000Ufi-6o; Tue, 14 Jul 2020 14:07:55 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 0/3] Introduce posix-socket
Date: Tue, 14 Jul 2020 15:07:50 +0200
Message-Id: <20200714130750.92051-1-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-fa-0.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Alexander Jung <alexander.jung@neclab.eu>

This patch series introduces the posix-socket microlibrary within the
Unikraft core in order to facilitate the use of multiple POSIX-
compliant socket implementations which target specific AF family
numbers.

This library allows for the registration of socket interfaces, listed
within `struct posix_socket_ops`, and exposes unikernel-wide 
prototypes for socket(), accept(), bind(), listen(), connect(),
send(), recv() and friends in order to access them via a 
corresponding AF family number.  The implementing library simply needs
to register against the desired interfaces with a glue function:

  #include <uk/socket.h>
  #include "my_socket.h"

  static struct posix_socket_ops mysock_socket_ops = {
    /* The initialization function on socket registration. */
    .init        = mysock_lib_init,
    /* POSIX interfaces */
    .create      = mysock_glue_create,
    .accept      = mysock_glue_accept,
    .bind        = mysock_glue_bind,
    .shutdown    = mysock_glue_shutdown,
    .getpeername = mysock_glue_getpeername,
    .getsockname = mysock_glue_getsockname,
    .getsockopt  = mysock_glue_getsockopt,
    .setsockopt  = mysock_glue_setsockopt,
    .connect     = mysock_glue_connect,
    .listen      = mysock_glue_listen,
    .recv        = mysock_glue_recv,
    .recvfrom    = mysock_glue_recvfrom,
    .recvmsg     = mysock_glue_recvmsg,
    .send        = mysock_glue_send,
    .sendmsg     = mysock_glue_sendmsg,
    .sendto      = mysock_glue_sendto,
    /* vfscore ops */
    .read        = mysock_glue_read,
    .write       = mysock_glue_write,
    .close       = mysock_glue_close,
    .ioctl       = mysock_glue_ioctl,
  };

Each glue function accepts traditional parameters for the POSIX 
interface as side from the file descriptor, traditionally `int fd` or 
`int sock`, which has instead been cast as `void *`.  This allows the
implementing library to use internal socket file descriptor or
reference.  The creation of a socket via socket() and accept() have 
also been cast to return `void *` in line with internal needs of the 
implementing library.  This makes sense for implementing libraries
which use a structure instead of a file descriptor identification 
integer.  An additional parameter, `struct posix_socket_driver`, is 
passed to each interface which can store private data as well as a
preferred memory allocator.  The glue for each interface simply needs
to call the appropriate method internally, for example:

  static int
  mysock_glue_bind(struct posix_socket_driver *d,
          void *sock, const struct sockaddr *addr, socklen_t addr_len)
  {
    int ret = 0;
    struct my_socket *mysock;

    /* Transform the socket descriptor to the my_socket pointer. */
    mysock = (struct my_socket *)sock;
    if (mysock->mysock_fd < 0) {
      ret = -1;
      SOCKET_LIB_ERR(d, ret, "failed to identify socket descriptor");
      goto EXIT;
    }
    
    /* Bind to my socket */
    ret = mysock_bind(mysock->mysock_fd, addr, addr_len);
    if (ret < 0)
      ret = -1;

  EXIT:
    return ret;
  }

The library selects the appropriate implementation based on the AF
family number and registers the required interfaces using a newly
exposed macro:

  POSIX_SOCKET_FAMILY_REGISTER(AF_INET,  &mysock_socket_ops, NULL);

Implementing libraries can register as many AF numbers as desired
or specify new families which are not listed in the <sys/socket.h>
header.  To access the relevant implementation, the application
simply needs to call the socket() method with the relevant AF family
number.

Alexander Jung (3):
  lib/posix-socket: Introduce abstraction for communication sockets
  lib/nolibc: Provide sys/socket.h
  lib/posix-socket: Register library within Unikraft.

 lib/Makefile.uk                             |    1 +
 lib/nolibc/include/sys/socket.h             |  258 +++++
 lib/posix-socket/Config.uk                  |   18 +
 lib/posix-socket/Makefile.uk                |   10 +
 lib/posix-socket/driver.c                   |  154 +++
 lib/posix-socket/exportsyms.uk              |   26 +
 lib/posix-socket/extra.ld                   |    9 +
 lib/posix-socket/include/uk/socket.h        |   45 +
 lib/posix-socket/include/uk/socket_driver.h | 1018 +++++++++++++++++++
 lib/posix-socket/include/uk/socket_vnops.h  |   97 ++
 lib/posix-socket/socket.c                   |  722 +++++++++++++
 lib/posix-socket/socket_vnops.c             |  323 ++++++
 12 files changed, 2681 insertions(+)
 create mode 100644 lib/nolibc/include/sys/socket.h
 create mode 100644 lib/posix-socket/Config.uk
 create mode 100644 lib/posix-socket/Makefile.uk
 create mode 100644 lib/posix-socket/driver.c
 create mode 100644 lib/posix-socket/exportsyms.uk
 create mode 100644 lib/posix-socket/extra.ld
 create mode 100644 lib/posix-socket/include/uk/socket.h
 create mode 100644 lib/posix-socket/include/uk/socket_driver.h
 create mode 100644 lib/posix-socket/include/uk/socket_vnops.h
 create mode 100644 lib/posix-socket/socket.c
 create mode 100644 lib/posix-socket/socket_vnops.c

-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Thu Jul 16 16:10:06 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 16 Jul 2020 16:10:06 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jw6SQ-00056D-T2; Thu, 16 Jul 2020 16:10:02 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=ejTe=A3=gmail.com=raducanu.costi@srs-us1.protection.inumbo.net>)
 id 1jw6SP-0004wW-MG
 for minios-devel@lists.xen.org; Thu, 16 Jul 2020 16:10:01 +0000
X-Inumbo-ID: ccf0484a-c77e-11ea-bb8b-bc764e2007e4
Received: from mail-qt1-x841.google.com (unknown [2607:f8b0:4864:20::841])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id ccf0484a-c77e-11ea-bb8b-bc764e2007e4;
 Thu, 16 Jul 2020 16:10:00 +0000 (UTC)
Received: by mail-qt1-x841.google.com with SMTP id i3so5250735qtq.13
 for <minios-devel@lists.xen.org>; Thu, 16 Jul 2020 09:10:00 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:references:in-reply-to:from:date:message-id:subject:to
 :cc; bh=FC3OPI7xpAxJXzlds/p9ATC+G3Xr6gW3qltBfHHy2q8=;
 b=hgOeOqK9piJTooTY4UZqMmY4E96eenuNppA3aPsncX6hk1I7eXTegle2CkzDuGO4ne
 /GemW2dQ+PloPjGkC1DUrVNIp01B3E7x1qg/1LNasN3xap2o1/+GDPwz1MEEWOXIkF0c
 rHAO3O+fgs8qfg/fE3vR3I1Q6y8YQ6oCNLIyFLcMulLdeRaNsSPyH4oTQmIXBzjnGMM3
 aCCqq0/+NMMXxGJNiwdRcaUu2JiJrEmzT+2FL/l3b6jg67F0PNqJ+fcJ3Wb5SszZSVJ7
 MTc1OHXSTwnHfk+F0XOBWmQ/SKhxiaQcX12C4dkmTXcjWDD8jxlSRGihMJV2INc4Wm9J
 lNuQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:references:in-reply-to:from:date
 :message-id:subject:to:cc;
 bh=FC3OPI7xpAxJXzlds/p9ATC+G3Xr6gW3qltBfHHy2q8=;
 b=CWtFNrMTtNEUDagi6GRdhKsd9UEEFN4Wuv1uqfLXnesBdNxRetBgkcfkBrVi1xFJDq
 9yoG8VDezN3aT2XHv0lw726g3FJqEEMxDBiFWheGOT/yb0jG1v5rozmeO/f2NdvL2xhs
 mQsnvWnnW8njPpgf+D0OloAdOHUUT3SL6L8HwSbw/1Id1RhdCl5hxrq14O+t0fk9w9SR
 6ozXMz0g64onjKvEVDwf1CJeq8yWTewSwAQJBGmtwIO2Pi0hvl08U9mF/o2nHFdK5LRO
 QB8u8DGGwboqUn+hGj+22Z0HNk2chrnfa81e3e5UuHFrjFztL6joeylbD+B3lAldrS5S
 qNhA==
X-Gm-Message-State: AOAM530CKQAwYacpneZbl4Iv13hEwE78EqEva8BCEe+Jy6iGYhdPlEYy
 L5I4IfjvKgcofAZvYc5Riu/dBytCDSUbv4HeaVU=
X-Google-Smtp-Source: ABdhPJwnnr2a8EdFt81/yYKiG2Vpi5P6UJhJs0DQ4BnTxOh4Tl6/C1rHZulKTFFo+SvAlbU5PuPyY3Lz8C6ZG6ca+zs=
X-Received: by 2002:ac8:39c7:: with SMTP id v65mr5731526qte.202.1594915800282; 
 Thu, 16 Jul 2020 09:10:00 -0700 (PDT)
MIME-Version: 1.0
References: <20200506100201.22654-1-simon.kuenzer@neclab.eu>
In-Reply-To: <20200506100201.22654-1-simon.kuenzer@neclab.eu>
From: Raducanu Constantin <raducanu.costi@gmail.com>
Date: Thu, 16 Jul 2020 19:09:49 +0300
Message-ID: <CAGR1uXjJq2TUdK0C=91QD4s5m4wbVF+Dx9_X87MLkkj_hqHdhQ@mail.gmail.com>
Subject: Re: [UNIKRAFT PATCH] lib/syscall_shim: Support system calls without
 arguments
To: Simon Kuenzer <simon.kuenzer@neclab.eu>
Content-Type: multipart/alternative; boundary="000000000000b8fa1e05aa91454e"
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>, minios-devel@lists.xen.org
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

--000000000000b8fa1e05aa91454e
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Reviewed-by: Constantin Raducanu <raducanu.costi@gmail.com
<gaulthier.gain@uliege.be>>

=C3=8En mie., 6 mai 2020 la 13:02, Simon Kuenzer <simon.kuenzer@neclab.eu> =
a
scris:

> The macros `UK_SYSCALL_DEFINE()`, `UK_SYSCALL_R_DEFINE()`,
> `UK_LLSYSCALL_DEFINE()`, and `UK_LLSYSCALL_R_DEFINE()` did not support
> defining system calls that do not have input parameters (e.g.,
> `getppid`). The definition for empty argument lists was
> missing (`UK_ARG_MAP0`).
>
> Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
> ---
>  lib/syscall_shim/include/uk/syscall.h | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/lib/syscall_shim/include/uk/syscall.h
> b/lib/syscall_shim/include/uk/syscall.h
> index a3b79d41..1be4ab91 100644
> --- a/lib/syscall_shim/include/uk/syscall.h
> +++ b/lib/syscall_shim/include/uk/syscall.h
> @@ -93,6 +93,7 @@ typedef long uk_syscall_arg_t;
>  #define __UK_NAME2SCALLE_FN(name) UK_CONCAT(uk_syscall_e_, name)
>  #define __UK_NAME2SCALLR_FN(name) UK_CONCAT(uk_syscall_r_, name)
>
> +#define UK_ARG_MAP0(...)
>  #define UK_ARG_MAP1(m, type, arg) m(type, arg)
>  #define UK_ARG_MAP2(m, type, arg, ...) m(type, arg), UK_ARG_MAP1(m,
> __VA_ARGS__)
>  #define UK_ARG_MAP3(m, type, arg, ...) m(type, arg), UK_ARG_MAP2(m,
> __VA_ARGS__)
> --
> 2.20.1
>
>
>

--000000000000b8fa1e05aa91454e
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div id=3D"gmail-:173" class=3D"gmail-a3s gmail-aXjCH"><di=
v style=3D"overflow-wrap: break-word;">Reviewed-by: <span class=3D"gmail-il=
">Constantin Raducanu</span> &lt;<a href=3D"mailto:gaulthier.gain@uliege.be=
" target=3D"_blank"><span class=3D"gmail-il">raducanu.costi@gmail.com</span=
><span class=3D"gmail-il"></span></a>&gt;</div></div></div><br><div class=
=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">=C3=8En mie., 6 mai =
2020 la 13:02, Simon Kuenzer &lt;<a href=3D"mailto:simon.kuenzer@neclab.eu"=
>simon.kuenzer@neclab.eu</a>&gt; a scris:<br></div><blockquote class=3D"gma=
il_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,2=
04,204);padding-left:1ex">The macros `UK_SYSCALL_DEFINE()`, `UK_SYSCALL_R_D=
EFINE()`,<br>
`UK_LLSYSCALL_DEFINE()`, and `UK_LLSYSCALL_R_DEFINE()` did not support<br>
defining system calls that do not have input parameters (e.g.,<br>
`getppid`). The definition for empty argument lists was<br>
missing (`UK_ARG_MAP0`).<br>
<br>
Signed-off-by: Simon Kuenzer &lt;<a href=3D"mailto:simon.kuenzer@neclab.eu"=
 target=3D"_blank">simon.kuenzer@neclab.eu</a>&gt;<br>
---<br>
=C2=A0lib/syscall_shim/include/uk/syscall.h | 1 +<br>
=C2=A01 file changed, 1 insertion(+)<br>
<br>
diff --git a/lib/syscall_shim/include/uk/syscall.h b/lib/syscall_shim/inclu=
de/uk/syscall.h<br>
index a3b79d41..1be4ab91 100644<br>
--- a/lib/syscall_shim/include/uk/syscall.h<br>
+++ b/lib/syscall_shim/include/uk/syscall.h<br>
@@ -93,6 +93,7 @@ typedef long uk_syscall_arg_t;<br>
=C2=A0#define __UK_NAME2SCALLE_FN(name) UK_CONCAT(uk_syscall_e_, name)<br>
=C2=A0#define __UK_NAME2SCALLR_FN(name) UK_CONCAT(uk_syscall_r_, name)<br>
<br>
+#define UK_ARG_MAP0(...)<br>
=C2=A0#define UK_ARG_MAP1(m, type, arg) m(type, arg)<br>
=C2=A0#define UK_ARG_MAP2(m, type, arg, ...) m(type, arg), UK_ARG_MAP1(m, _=
_VA_ARGS__)<br>
=C2=A0#define UK_ARG_MAP3(m, type, arg, ...) m(type, arg), UK_ARG_MAP2(m, _=
_VA_ARGS__)<br>
-- <br>
2.20.1<br>
<br>
<br>
</blockquote></div>

--000000000000b8fa1e05aa91454e--


From minios-devel-bounces@lists.xenproject.org Fri Jul 17 07:18:36 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 17 Jul 2020 07:18:36 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jwKdd-0000OI-2O; Fri, 17 Jul 2020 07:18:33 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=KhHV=A4=gmail.com=2309bmcristi@srs-us1.protection.inumbo.net>)
 id 1jwKdb-0000OD-Gj
 for minios-devel@lists.xen.org; Fri, 17 Jul 2020 07:18:31 +0000
X-Inumbo-ID: b607d3da-c7fd-11ea-b7bb-bc764e2007e4
Received: from mail-ej1-x644.google.com (unknown [2a00:1450:4864:20::644])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id b607d3da-c7fd-11ea-b7bb-bc764e2007e4;
 Fri, 17 Jul 2020 07:18:28 +0000 (UTC)
Received: by mail-ej1-x644.google.com with SMTP id n26so9744141ejx.0
 for <minios-devel@lists.xen.org>; Fri, 17 Jul 2020 00:18:28 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:cc:subject:date:message-id;
 bh=+aP8ysRvUNki9/t0ZHMWND+jeThx1bn8pyQeLERa3rg=;
 b=tEqX3YSzGNBmWz+vvbdVUszB0uV4igvaaqT79t75xtKbX61upgGW4rvIux1vuVxfVf
 8MnsX+ot+2KrF1MHE4qqLSLGdrOhBZSIB/Sthic6zwsAcup8d2p6PmB8ycjggB79UaZI
 V1W4rIDFCRczrifF/RKc44wBvNP3xzwSTWU9e84eyykPmQcYdF2tsrRVhZ9FG6XmHsZw
 vwTD/RHLKeIfq6zWBt8vJXTrLWZGSSmLCMIyK7AkbZqIDnW2+7Hgth/1pFncke8r4Z4b
 8YhGKxgLk0KpDQJ5egAso57AWjvVmKV6g8eH5lAegkiL0fJxG4ZgvCVSNw864QQIZFvP
 YdbA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:date:message-id;
 bh=+aP8ysRvUNki9/t0ZHMWND+jeThx1bn8pyQeLERa3rg=;
 b=LBKksBzR8ZgMBbwjY1ZTAbpSxP3j4oZWRYKCbLi13S2v2xlaigN547uW0xweJUXESw
 FTZqOtcQrMj9YpikG1DoZJqHudzASuWH1ooyaK6SKqZ5eb1Xgu0L/+spEOlL5LHU3d1o
 s/zxWZdRLrflNxaVXUJA8ik/dPydRLlYB2bXStmooT+x5p7NiMupAJKxR9NwTQYkZLp6
 F0Yv67OXcj/pcNvDvX9ILhtXYLp7ITMwz4ZoF82yHYHV2ExUbxeGRcRcGpSBa7OEVYbp
 6cpmawlfUgjfaJhZXJJeuVXNkLG+qaGcrFpJp+rzffsqvo7OsTczLitWLHL+R9oi0YSU
 vq9Q==
X-Gm-Message-State: AOAM531+/Lyohw0hwdfOHJfstiGaWi+Ys74F+UbapgqZkhw2fScWecA3
 Fus9XLQ2L9AWpXS73AgQP1yIuykJ3Qw=
X-Google-Smtp-Source: ABdhPJztod5aARyYod3/QuNwd8GXgil/s+HdyhXFXjL1z4Am2JOTAHUvvPRPHfbeBJoOYBDYLv7rHA==
X-Received: by 2002:a17:906:6d4d:: with SMTP id
 a13mr7112973ejt.146.1594970307012; 
 Fri, 17 Jul 2020 00:18:27 -0700 (PDT)
Received: from localhost.localdomain ([2a02:2f07:8200:d200:e58e:e1b:b419:616c])
 by smtp.gmail.com with ESMTPSA id cw14sm7525729edb.88.2020.07.17.00.18.25
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 17 Jul 2020 00:18:26 -0700 (PDT)
From: Marius-Cristian Baciu <2309bmcristi@gmail.com>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 1/3] libdruntime: Add skeleton for the porting of the
 D Runtime Library
Date: Fri, 17 Jul 2020 10:17:35 +0300
Message-Id: <20200717071737.18555-1-2309bmcristi@gmail.com>
X-Mailer: git-send-email 2.17.1
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: simon.kuenzer@neclab.eu,
 Baciu Marius-Cristian <marius.baciu@stud.acs.upb.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Baciu Marius-Cristian <marius.baciu@stud.acs.upb.ro>

---
 .gitignore      |  27 ++++
 CODING_STYLE.md |   4 +
 CONTRIBUTING.md |   4 +
 COPYING.md      |  39 ++++++
 Config.uk       |  22 +++
 MAINTAINERS.md  |  11 ++
 Makefile.uk     | 346 ++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 453 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 CODING_STYLE.md
 create mode 100644 CONTRIBUTING.md
 create mode 100644 COPYING.md
 create mode 100644 Config.uk
 create mode 100644 MAINTAINERS.md
 create mode 100644 Makefile.uk

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..75d2fd3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,27 @@
+*.depend
+*.o
+*.a
+*.d
+*.so
+*.orig
+*.rej
+*.bak
+*.swp
+*~
+,*
+\#*\#
+.\#*
+\#_*\#
+.\#_*
+!.gitignore
+.*
+
+# gnu global files
+GPATH
+GRTAGS
+GSYMS
+GTAGS
+
+# cscope files
+cscope.*
+ncscope.*
diff --git a/CODING_STYLE.md b/CODING_STYLE.md
new file mode 100644
index 0000000..5730041
--- /dev/null
+++ b/CODING_STYLE.md
@@ -0,0 +1,4 @@
+Coding Style
+============
+
+Please refer to the `CODING_STYLE.md` file in the main Unikraft repository.
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..14f6ac6
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,4 @@
+Contributing to Unikraft
+========================
+
+Please refer to the `CONTRIBUTING.md` file in the main Unikraft repository.
diff --git a/COPYING.md b/COPYING.md
new file mode 100644
index 0000000..b43cf0d
--- /dev/null
+++ b/COPYING.md
@@ -0,0 +1,39 @@
+License
+=======
+
+Unikraft D Runtime wrappers
+----------------------------------
+
+This repository contains wrapper code to build lzma with Unikraft.
+Each C code file in this repository should declare who is the
+copyright owner and under which terms and conditions the code is
+licensed. If such a licence note is missing, the following copyright
+notice will apply:
+
+	Copyright (c) Year, Institution. All rights reserved.
+
+	Redistribution and use in source and binary forms, with or without
+	modification, are permitted provided that the following conditions
+	are met:
+
+	1. Redistributions of source code must retain the above copyright
+	   notice, this list of conditions and the following disclaimer.
+	2. Redistributions in binary form must reproduce the above copyright
+	   notice, this list of conditions and the following disclaimer in the
+	   documentation and/or other materials provided with the distribution.
+	3. Neither the name of the copyright holder nor the names of its
+	   contributors may be used to endorse or promote products derived from
+	   this software without specific prior written permission.
+
+	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+	AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+	ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+	LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+	CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+	POSSIBILITY OF SUCH DAMAGE.
+
diff --git a/Config.uk b/Config.uk
new file mode 100644
index 0000000..eff5bce
--- /dev/null
+++ b/Config.uk
@@ -0,0 +1,22 @@
+menuconfig LIBDRUNTIME
+	bool "D Runtime Library"
+	default n
+	select LIBUKALLOC
+	select LIBPOSIX_SYSINFO
+    select LIBPOSIX_USER
+	select LIBSYSCALL_SHIM
+    select LIBNEWLIBC
+	select LIBUKMMAP
+	select LIBCOMPILER_RT
+	select LIBCOMPILER_RT_ATOMIC
+    select LIBUNWIND
+	select LIBCXX
+	select LIBCXXABI
+	select LIBPTHREAD_EMBEDDED
+	select LIBGCC
+	select LIBBACKTRACE
+	select LIBLWIP
+	select LIBUCONTEXT
+
+if LIBDRUNTIME
+endif
diff --git a/MAINTAINERS.md b/MAINTAINERS.md
new file mode 100644
index 0000000..d83573b
--- /dev/null
+++ b/MAINTAINERS.md
@@ -0,0 +1,11 @@
+Maintainers List
+================
+
+For notes on how to read this information, please refer to `MAINTAINERS.md` in
+the main Unikraft repository.
+
+  LIBDRUNTIME-UNIKRAFT
+  M:  Baciu Marius-Cristian <marius.baciu@stud.acs.upb.ro>
+  M:  Felipe Huici <felipe.huici@neclab.eu>
+  L:  minios-devel@lists.xen.org
+  F:  *
diff --git a/Makefile.uk b/Makefile.uk
new file mode 100644
index 0000000..ed4ee5a
--- /dev/null
+++ b/Makefile.uk
@@ -0,0 +1,346 @@
+#  SPDX-License-Identifier: BSD-3-Clause
+#
+#  druntime Makefile.uk
+#
+#  Authors: Marius-Cristian Baciu <marius.baciu@stud.acs.upb.ro>
+#
+#  Copyright (c) 2020, University Politehnica of Bucharest. All rights reserved.
+#
+#  Redistribution and use in source and binary forms, with or without
+#  modification, are permitted provided that the following conditions
+#  are met:
+#
+#  1. Redistributions of source code must retain the above copyright
+#	 notice, this list of conditions and the following disclaimer.
+#  2. Redistributions in binary form must reproduce the above copyright
+#	 notice, this list of conditions and the following disclaimer in the
+#	 documentation and/or other materials provided with the distribution.
+#  3. Neither the name of the copyright holder nor the names of its
+#	 contributors may be used to endorse or promote products derived from
+#	 this software without specific prior written permission.
+#
+#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+#  POSSIBILITY OF SUCH DAMAGE.
+#
+#  THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+#
+
+################################################################################
+# Library registration
+################################################################################
+$(eval $(call addlib_s,libdruntime,$(CONFIG_LIBDRUNTIME)))
+$(eval $(call addlib_s,libdruntimeglue,$(CONFIG_LIBDRUNTIME)))
+
+################################################################################
+# Original sources
+################################################################################
+LIBDRUNTIME_VERSION=9.3.0
+
+LIBDRUNTIME_URL=https://ftp.gnu.org/gnu/gcc/gcc-$(LIBGCC_VERSION)/gcc-$(LIBGCC_VERSION).tar.gz
+
+LIBDRUNTIME_PATCHDIR=$(LIBDRUNTIME_BASE)/patches
+LIBDRUNTIME_SUBDIR=gcc-$(LIBDRUNTIME_VERSION)
+
+# For now, we will be working with manually-copied sources, so they can be more
+# easily managed
+#$(eval $(call fetch,libdruntime,$(LIBDRUNTIME_URL)))
+
+#$(eval $(call patch,libdruntime,$(LIBDRUNTIME_PATCHDIR),$(LIBDRUNTIME_SUBDIR)))
+
+################################################################################
+# Helpers
+################################################################################
+# This variable will be automatically set during the fetch routine call. For now,
+# hard-coding it should work
+LIBDRUNTIME_ORIGIN = /home/me/Faculty_work/Diploma/unikraft_fork/apps/app-helloworld/build/libdruntime/origin
+LIBDRUNTIME_EXTRACTED = $(LIBDRUNTIME_ORIGIN)/druntime
+################################################################################
+# Library includes
+################################################################################
+LIBDRUNTIME_COMMON_INCLUDES-y = -I$(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime #\
+# The following are includes used in the Go port. It is worth analyzing whether their
+# motivation also applies here
+#	-I$(LIBDRUNTIME_EXTRACTED)/libffi/include \
+#	-I$(LIBDRUNTIME_EXTRACTED)/libgcc \
+#	-I$(LIBDRUNTIME_EXTRACTED)/gcc/include \
+#	-I$(LIBDRUNTIME_EXTRACTED)/gcc/
+#LIBDRUNTIME_COMMON_INCLUDES-$(CONFIG_ARCH_X86_64) += -I$(LIBDRUNTIME_EXTRACTED)/libffi/src/x86
+#LIBDRUNTIME_COMMON_INCLUDES-$(CONFIG_ARCH_X86_64) += -I$(LIBDRUNTIME_EXTRACTED)/gcc/config/i386
+LIBDRUNTIME_ASINCLUDES-y = $(LIBDRUNTIME_COMMON_INCLUDES-y)
+LIBDRUNTIME_CINCLUDES-y  = $(LIBDRUNTIME_COMMON_INCLUDES-y)
+
+LIBDRUNTIME_INCLUDES-y	+= $(LIBDRUNTIME_COMMON_INCLUDES-y)
+
+LIBDRUNTIME_GDCINCLUDES	+= $(LIBDRUNTIME_INCLUDES-y)
+
+
+################################################################################
+# Global flags
+################################################################################
+# Suppress flags
+LIBDRUNTIME_SUPPRESS_FLAGS += -Wno-cast-qual -Wno-unused-value -Wno-unused-parameter
+
+LIBDRUNTIME_CFLAGS-y   += $(LIBDRUNTIME_SUPPRESS_FLAGS)
+LIBDRUNTIME_CFLAGS-y   += -fexceptions -fnon-call-exceptions \
+	-fplan9-extensions -fno-split-stack -Wall -Wextra -Wwrite-strings \
+	-Wcast-qual -Wno-unused-function -minline-all-stringops \
+	-Wno-implicit-function-declaration -D_GNU_SOURCE -D_LARGEFILE_SOURCE \
+	-D_FILE_OFFSET_BITS=64
+
+# Here you may add any version symbols, as needed
+LIBDRUNTIME_GDCFLAGS += #-fversion=CRuntime_Glibc
+LIBDRUNTIME_GDCFLAGS-y +=
+
+################################################################################
+# druntime code
+################################################################################
+
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/object.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/math.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/demangle.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/atomic.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/attribute.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/bitop.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/runtime.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/vararg.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/memory.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/simd.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/time.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/cpuid.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/checkedint.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/exception.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/thread.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/internal/arrayop.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/internal/string.d|internal
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/internal/abort.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/internal/spinlock.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/internal/traits.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/internal/hash.d|internal
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/internal/convert.d
+#LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/math.d|stdc
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/tgmath.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/errno.d|stdc
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/wchar_.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/stddef.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/signal.d|stdc
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/locale.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/time.d|stdc
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/stdlib.d|stdc
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/stdio.d|stdc
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/wctype.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/inttypes.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/string.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/stdint.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/ctype.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/float_.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/limits.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/complex.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/stdarg.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/assert_.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/config.d|stdc
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/fenv.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/errno_.c
+#LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdcpp/exception.d|stdcpp
+#LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdcpp/typeinfo.d|stdcpp
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sync/semaphore.d|sync
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sync/mutex.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sync/barrier.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sync/condition.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sync/rwmutex.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sync/exception.d|sync
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sync/config.d|sync
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/semaphore.d|posix
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/syslog.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/fcntl.d|posix
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/iconv.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/mqueue.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/libgen.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/arpa/inet.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/ucontext.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/netdb.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/utime.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/sched.d|posix
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/signal.d|posix
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/time.d|posix
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/netinet/in_.d|posix
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/netinet/tcp.d|posix
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/net/if_.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/unistd.d|posix
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/stdlib.d|posix
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/stdio.d|posix
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/sys/ttycom.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/sys/resource.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/sys/ioctl.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/sys/filio.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/sys/ioccom.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/sys/stat.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/sys/time.d|posix_sys
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/sys/types.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/sys/un.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/sys/mman.d|posix
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/sys/statvfs.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/sys/socket.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/sys/utsname.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/sys/ipc.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/sys/wait.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/sys/msg.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/sys/uio.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/sys/select.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/sys/shm.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/inttypes.d|posix
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/dirent.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/setjmp.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/aio.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/pwd.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/pthread.d|posix
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/poll.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/dlfcn.d|posix
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/grp.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/termios.d|posix
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/config.d|posix
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/fcntl.d|linux
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/epoll.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/errno.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sched.d|linux
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/tipc.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/elf.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/timerfd.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/time.d|linux
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/netinet/in_.d|linux
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/netinet/tcp.d|linux
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/unistd.d|linux
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/stdio.d|linux
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/xattr.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/eventfd.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/prctl.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/file.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/time.d|linux_sys
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/netinet/tcp.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/mman.d|linux
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/signalfd.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/inotify.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/socket.d|sys
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/sysinfo.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/auxv.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/ifaddrs.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/dlfcn.d|linux
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/termios.d|linux
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/config.d|linux
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/execinfo.d|linux
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/link.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/bionic/fcntl.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/bionic/unistd.d|bionic
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/mach/semaphore.d|mach
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/mach/kern_return.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/mach/getsect.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/mach/loader.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/mach/dyld.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/mach/port.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/mach/thread_act.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/netinet/in_.d|darwin
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/sys/event.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/sys/cdefs.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/sys/mman.d|darwin
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/pthread.d|darwin
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/dlfcn.d|darwin
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/execinfo.d|darwin
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/attribute.d|gcc
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/unwind/package.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/unwind/arm_common.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/unwind/generic.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/unwind/pe.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/unwind/c6x.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/unwind/arm.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/sections/elf_shared.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/sections/package.d|sections
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/builtins.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/backtrace.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/deh.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/drtstuff.c
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/emutls.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/gthread.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gc/os.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gc/proxy.d|gc
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gc/impl/conservative/gc.d|conservative
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gc/impl/manual/gc.d|manual
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gc/gcinterface.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gc/pooltable.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gc/bits.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gc/config.d
+#LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcstub/gc.d|gcstub
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/adi.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_ushort.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_long.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_wchar.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_cfloat.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_ulong.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_Along.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_char.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_Acfloat.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_dchar.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_cent.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_Acdouble.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_short.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_Ag.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_Acreal.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_ifloat.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_Ashort.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_creal.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_C.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_Aint.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_byte.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_ptr.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_Afloat.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_delegate.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_int.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_ubyte.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_ireal.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_idouble.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_n.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_Areal.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_Adouble.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_uint.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_real.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_double.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_ucent.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_float.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_void.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/typeinfo/ti_cdouble.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/tlsgc.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/invariant.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/memory.d|rt
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/aApplyR.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/obj.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/aaA.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/util/array.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/util/container/treap.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/util/container/array.d|container
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/util/container/hashtab.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/util/container/common.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/util/typeinfo.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/util/random.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/util/utf.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/minfo.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/arrayassign.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/arraycast.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/critical_.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/lifetime.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/deh.d|rt
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/dmain2.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/cast_.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/sections.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/switch_.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/config.d|rt
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/arraycat.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/aApply.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/monitor_.d
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/dylib_fixes.c
-- 
2.17.1



From minios-devel-bounces@lists.xenproject.org Fri Jul 17 07:19:02 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 17 Jul 2020 07:19:02 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jwKe6-0000PO-6O; Fri, 17 Jul 2020 07:19:02 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=KhHV=A4=gmail.com=2309bmcristi@srs-us1.protection.inumbo.net>)
 id 1jwKe5-0000PJ-0f
 for minios-devel@lists.xen.org; Fri, 17 Jul 2020 07:19:01 +0000
X-Inumbo-ID: c8808930-c7fd-11ea-b7bb-bc764e2007e4
Received: from mail-ed1-x541.google.com (unknown [2a00:1450:4864:20::541])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id c8808930-c7fd-11ea-b7bb-bc764e2007e4;
 Fri, 17 Jul 2020 07:18:59 +0000 (UTC)
Received: by mail-ed1-x541.google.com with SMTP id bm28so6929777edb.2
 for <minios-devel@lists.xen.org>; Fri, 17 Jul 2020 00:18:59 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:cc:subject:date:message-id:in-reply-to:references;
 bh=3YILZnK5/dfEeBulNGtcvjLFU5uAYhy8qZCL5H7cH+I=;
 b=FPg1E2h0CO5uySIg3GlucWeqh4Lxx/hS4pwh+whI1LEjHMbQ8ZAy7DPqDR0Kaj7POy
 1gKvlSDmPZjIFiGZkh1tVQiSV+12m6SCMFo7dMlsV9xz8Up09sBw2MxTujxFr/W4AlLZ
 8Wd0HNVT0vO05LslFJXF642XOBlzN6WB/BLWcDvlcI83RCvOQnwbg5Two5501mdOp1ZU
 A1/EtdNhq4kOjGIVkeEUyXJFb52BKFsx7Awx7lmh1Ia/epaN1YIddOQrLFENJYOwRN+3
 6/JwypPMq5i/OMcmeevesO+eeoSk5aecwDki69QLKqSzHbKlXgAUA2M7WDRsD7DMD/Dk
 QPlw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
 :references;
 bh=3YILZnK5/dfEeBulNGtcvjLFU5uAYhy8qZCL5H7cH+I=;
 b=ucBNiKF6tDVzLrAqY9XiYFq6FU7bYELBPboWJvG9LogpWaWA8ZAnCCikCyihkTy53M
 B3ABUN+/yItzGHn8RIOyV1rYO4k6JPTx+CKD19gOY+IEui6jfcSvo+7X12f7I5kYsBlQ
 edumeW4HYqb8Lbonydr5m6M47l7U9IA7c4h3iRSEvWbnkUrLaRBN+r+xGrj4yv9D3dij
 2++g7qI+iNTjP+dDaQNtYDEZkymWn7HiLpNHQYq1fBWxH0Ahw5PsF2wf4x7qS0+bJzos
 HJ8qwXmehyjMm2Je18gLnHxb7yuJ4XfcoZiXzPCEkgy35jdAeWca9o45rF+oKNb/IoLO
 Y2Rw==
X-Gm-Message-State: AOAM533zRRA4H9oiv4rfCV7z1OY36MvOHoucFhNKcsQjyfVhsCxGQEYi
 +4rTQ29M2XSQHQVA+C3uNp0u2ofyCf7OVg==
X-Google-Smtp-Source: ABdhPJxW4gNbHzLOfbOT8xM4T2nFheU5HPIYiOCTzuraCUFnb1o10j+42fnjQ/Vk+81MlVg9QeEqLQ==
X-Received: by 2002:aa7:d814:: with SMTP id v20mr7993454edq.296.1594970338407; 
 Fri, 17 Jul 2020 00:18:58 -0700 (PDT)
Received: from localhost.localdomain ([2a02:2f07:8200:d200:e58e:e1b:b419:616c])
 by smtp.gmail.com with ESMTPSA id cw14sm7525729edb.88.2020.07.17.00.18.57
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 17 Jul 2020 00:18:57 -0700 (PDT)
From: Marius-Cristian Baciu <2309bmcristi@gmail.com>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 2/3] libdruntime: Add Makefile.uk
Date: Fri, 17 Jul 2020 10:17:36 +0300
Message-Id: <20200717071737.18555-2-2309bmcristi@gmail.com>
X-Mailer: git-send-email 2.17.1
In-Reply-To: <20200717071737.18555-1-2309bmcristi@gmail.com>
References: <20200717071737.18555-1-2309bmcristi@gmail.com>
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: simon.kuenzer@neclab.eu,
 Baciu Marius-Cristian <marius.baciu@stud.acs.upb.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Baciu Marius-Cristian <marius.baciu@stud.acs.upb.ro>

---
 Makefile.uk | 123 ++++++++++++++++++++--------------------------------
 1 file changed, 48 insertions(+), 75 deletions(-)

diff --git a/Makefile.uk b/Makefile.uk
index ed4ee5a..141cb74 100644
--- a/Makefile.uk
+++ b/Makefile.uk
@@ -1,6 +1,6 @@
 #  SPDX-License-Identifier: BSD-3-Clause
 #
-#  druntime Makefile.uk
+#  D Runtime Library Makefile.uk
 #
 #  Authors: Marius-Cristian Baciu <marius.baciu@stud.acs.upb.ro>
 #
@@ -50,59 +50,63 @@ LIBDRUNTIME_URL=https://ftp.gnu.org/gnu/gcc/gcc-$(LIBGCC_VERSION)/gcc-$(LIBGCC_V
 LIBDRUNTIME_PATCHDIR=$(LIBDRUNTIME_BASE)/patches
 LIBDRUNTIME_SUBDIR=gcc-$(LIBDRUNTIME_VERSION)
 
-# For now, we will be working with manually-copied sources, so they can be more
-# easily managed
-#$(eval $(call fetch,libdruntime,$(LIBDRUNTIME_URL)))
+$(eval $(call fetch,libdruntime,$(LIBDRUNTIME_URL)))
 
-#$(eval $(call patch,libdruntime,$(LIBDRUNTIME_PATCHDIR),$(LIBDRUNTIME_SUBDIR)))
+$(eval $(call patch,libdruntime,$(LIBDRUNTIME_PATCHDIR),$(LIBDRUNTIME_SUBDIR)))
 
 ################################################################################
 # Helpers
 ################################################################################
-# This variable will be automatically set during the fetch routine call. For now,
-# hard-coding it should work
-LIBDRUNTIME_ORIGIN = /home/me/Faculty_work/Diploma/unikraft_fork/apps/app-helloworld/build/libdruntime/origin
 LIBDRUNTIME_EXTRACTED = $(LIBDRUNTIME_ORIGIN)/druntime
+
 ################################################################################
 # Library includes
 ################################################################################
-LIBDRUNTIME_COMMON_INCLUDES-y = -I$(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime #\
-# The following are includes used in the Go port. It is worth analyzing whether their
-# motivation also applies here
-#	-I$(LIBDRUNTIME_EXTRACTED)/libffi/include \
-#	-I$(LIBDRUNTIME_EXTRACTED)/libgcc \
-#	-I$(LIBDRUNTIME_EXTRACTED)/gcc/include \
-#	-I$(LIBDRUNTIME_EXTRACTED)/gcc/
-#LIBDRUNTIME_COMMON_INCLUDES-$(CONFIG_ARCH_X86_64) += -I$(LIBDRUNTIME_EXTRACTED)/libffi/src/x86
-#LIBDRUNTIME_COMMON_INCLUDES-$(CONFIG_ARCH_X86_64) += -I$(LIBDRUNTIME_EXTRACTED)/gcc/config/i386
+LIBDRUNTIME_COMMON_INCLUDES-y = -I$(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime \
+					-I$(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/ \
+					-I$(LIBDRUNTIME_BASE)
+
 LIBDRUNTIME_ASINCLUDES-y = $(LIBDRUNTIME_COMMON_INCLUDES-y)
 LIBDRUNTIME_CINCLUDES-y  = $(LIBDRUNTIME_COMMON_INCLUDES-y)
 
-LIBDRUNTIME_INCLUDES-y	+= $(LIBDRUNTIME_COMMON_INCLUDES-y)
+################################################################################
+# Global flags
+GDCINCLUDES-y += $(LIBDRUNTIME_COMMON_INCLUDES-y)
 
-LIBDRUNTIME_GDCINCLUDES	+= $(LIBDRUNTIME_INCLUDES-y)
+DMDINCLUDES-y += -I$(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/
 
+CFLAGS += -DDRUNTIME
 
-################################################################################
-# Global flags
 ################################################################################
 # Suppress flags
-LIBDRUNTIME_SUPPRESS_FLAGS += -Wno-cast-qual -Wno-unused-value -Wno-unused-parameter
+LIBDRUNTIME_SUPPRESS_FLAGS_C += -Wno-cast-qual -Wno-unused-value -Wno-unused-parameter
+LIBDRUNTIME_SUPPRESS_FLAGS_GDC += -Wno-unused-value -Wno-unused-parameter
 
-LIBDRUNTIME_CFLAGS-y   += $(LIBDRUNTIME_SUPPRESS_FLAGS)
+LIBDRUNTIME_CFLAGS-y   += $(LIBDRUNTIME_SUPPRESS_FLAGS_C)
 LIBDRUNTIME_CFLAGS-y   += -fexceptions -fnon-call-exceptions \
 	-fplan9-extensions -fno-split-stack -Wall -Wextra -Wwrite-strings \
 	-Wcast-qual -Wno-unused-function -minline-all-stringops \
 	-Wno-implicit-function-declaration -D_GNU_SOURCE -D_LARGEFILE_SOURCE \
 	-D_FILE_OFFSET_BITS=64
 
-# Here you may add any version symbols, as needed
-LIBDRUNTIME_GDCFLAGS += #-fversion=CRuntime_Glibc
-LIBDRUNTIME_GDCFLAGS-y +=
+LIBDRUNTIME_GDCFLAGS += $(LIBDRUNTIME_SUPPRESS_FLAGS_GDC)
+LIBDRUNTIME_GDCFLAGS += -fexceptions -fnon-call-exceptions \
+	-fno-split-stack -Wall -Wextra -Wno-unused-function -minline-all-stringops
+LIBDRUNTIME_GDCFLAGS += -fversion=UNIKRAFT
 
 ################################################################################
 # druntime code
 ################################################################################
+ifeq ($(D_COMPILER),gdc)
+
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/config/x86/switchcontext.S
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/config/common/threadasm.S
+
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_BASE)/gluecode.c
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_BASE)/htons_.c
+
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/config.d|gcc
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/libbacktrace.d|gcc
 
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/object.d
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/math.d
@@ -126,7 +130,7 @@ LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/intern
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/internal/traits.d
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/internal/hash.d|internal
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/internal/convert.d
-#LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/math.d|stdc
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/math.d|stdc
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/tgmath.d
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/errno.d|stdc
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/stdc/wchar_.d
@@ -207,52 +211,6 @@ LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/po
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/grp.d
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/termios.d|posix
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/posix/config.d|posix
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/fcntl.d|linux
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/epoll.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/errno.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sched.d|linux
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/tipc.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/elf.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/timerfd.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/time.d|linux
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/netinet/in_.d|linux
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/netinet/tcp.d|linux
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/unistd.d|linux
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/stdio.d|linux
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/xattr.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/eventfd.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/prctl.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/file.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/time.d|linux_sys
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/netinet/tcp.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/mman.d|linux
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/signalfd.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/inotify.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/socket.d|sys
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/sysinfo.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/sys/auxv.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/ifaddrs.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/dlfcn.d|linux
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/termios.d|linux
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/config.d|linux
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/execinfo.d|linux
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/linux/link.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/bionic/fcntl.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/bionic/unistd.d|bionic
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/mach/semaphore.d|mach
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/mach/kern_return.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/mach/getsect.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/mach/loader.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/mach/dyld.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/mach/port.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/mach/thread_act.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/netinet/in_.d|darwin
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/sys/event.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/sys/cdefs.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/sys/mman.d|darwin
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/pthread.d|darwin
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/dlfcn.d|darwin
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/core/sys/darwin/execinfo.d|darwin
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/attribute.d|gcc
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/unwind/package.d
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/unwind/arm_common.d
@@ -265,7 +223,6 @@ LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/section
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/builtins.d
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/backtrace.d
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/deh.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/drtstuff.c
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/emutls.d
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/gthread.d
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gc/os.d
@@ -343,4 +300,20 @@ LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/config.d
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/arraycat.d
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/aApply.d
 LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/monitor_.d
-LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/dylib_fixes.c
+#LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/dylib_fixes.c
+LIBDRUNTIME_SRCS-y += $(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/rt/qsort.d
+
+endif
+
+# Instantiate the config.d.in and libbacktrace.d.in templates
+$(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/config.d: $(LIBDRUNTIME_EXTRACTED)/libphobos/config.status
+	$(call build_cmd,GEN,libdruntime,$(notdir $@),cd $(LIBDRUNTIME_EXTRACTED)/libphobos && ./config.status -q libdruntime/gcc/config.d)
+
+$(LIBDRUNTIME_EXTRACTED)/libphobos/libdruntime/gcc/libbacktrace.d: $(LIBDRUNTIME_EXTRACTED)/libphobos/config.status
+	$(call build_cmd,GEN,libdruntime,$(notdir $@),cd $(LIBDRUNTIME_EXTRACTED)/libphobos && ./config.status -q libdruntime/gcc/libbacktrace.d)
+
+
+# Generate config.status script
+$(LIBDRUNTIME_EXTRACTED)/libphobos/config.status: $(LIBDRUNTIME_EXTRACTED)/libphobos/configure
+	$(call build_cmd,GEN,libdruntime,$(notdir $@),cd $(LIBDRUNTIME_EXTRACTED)/libphobos && ./configure -q --no-create --no-recursion)
+
-- 
2.17.1



From minios-devel-bounces@lists.xenproject.org Fri Jul 17 07:19:11 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 17 Jul 2020 07:19:11 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jwKeF-0000QB-8M; Fri, 17 Jul 2020 07:19:11 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=KhHV=A4=gmail.com=2309bmcristi@srs-us1.protection.inumbo.net>)
 id 1jwKeD-0000Q2-JV
 for minios-devel@lists.xen.org; Fri, 17 Jul 2020 07:19:09 +0000
X-Inumbo-ID: cddd3536-c7fd-11ea-b7bb-bc764e2007e4
Received: from mail-ej1-x631.google.com (unknown [2a00:1450:4864:20::631])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id cddd3536-c7fd-11ea-b7bb-bc764e2007e4;
 Fri, 17 Jul 2020 07:19:08 +0000 (UTC)
Received: by mail-ej1-x631.google.com with SMTP id y10so9715802eje.1
 for <minios-devel@lists.xen.org>; Fri, 17 Jul 2020 00:19:08 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:cc:subject:date:message-id:in-reply-to:references;
 bh=V8nJLEBROhA/PO/M+WLpeZlNgu8KMYy7h4b1/Yl9Uew=;
 b=UWF1aCaO4GPRa64B9TidkUxrPtd3eaede7lJQQpwfEe59EAs1qFvJl64rOMdkZJZQz
 K27SghGX42grJWzAS3cU5T96npyvD4SHSQU//8sHtbXHRkJVRSm3tH3HpemfN1oMO/TJ
 omQy6fqb8kTdo0mo/esf01xNeHrIOjBuQEiIHls7PSI8YnJ7w44GoVZ1S9fgLm8OP/bR
 9DhsLMZLi4syARZOM7A+ZxD9ctWaYvS61R76EEKTgh+FXBbUVz8bGcLlD0CFZdNepxlx
 KL8dieG3odP+sfdcqOn1TLyLN6+ngDiavo3GAUwS0hHUDmQeeVSwvhoePndTqCCTseUJ
 4ncA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
 :references;
 bh=V8nJLEBROhA/PO/M+WLpeZlNgu8KMYy7h4b1/Yl9Uew=;
 b=VSC34vIVObB6z2hrsIXvO77U63E9y3vfGhaDTwX2xtGix19qyNMrImcO1HvG/nC6EY
 VQilecICdcUsBpU1ZBRsVwl1hqFwNTUjw5HNUeKxhTGmBFIolQK5h9wif67SHfDRwO8l
 giS7wKJDX6ALBPDigvIUqk7W3ekpWQyQSAeX6NxJBaxjWGW6KHNoW97Smt/CpemDL5Hw
 jaaKwAYdESCK3W/A78AwBgxveiowIfm+rSYJGNZei7AfBrlytoKhRLx1QriW8eYs2SRL
 9twEuV2Kv/dggH4Mb6zK27p/3Ni3nI4rph8+gd0fzzXvB5MFfwirmRNwIMFwKtyCwcLb
 51aw==
X-Gm-Message-State: AOAM533TW5QXMdGF1KDBpe/PWhe7+6+Gf1vM+05zA38OwYrT3xZC45Ud
 tSa/A+MgSwFDOTRLaQUSN4b9kcL5mfoY1g==
X-Google-Smtp-Source: ABdhPJxPrEk21rt835jnAEvEs3Bhi4DrkWfLb6+w8eBPMMTd3DHNbIz7wWba+7fmLLEQEUHxjR1ePQ==
X-Received: by 2002:a17:906:c007:: with SMTP id
 e7mr7301638ejz.481.1594970347571; 
 Fri, 17 Jul 2020 00:19:07 -0700 (PDT)
Received: from localhost.localdomain ([2a02:2f07:8200:d200:e58e:e1b:b419:616c])
 by smtp.gmail.com with ESMTPSA id cw14sm7525729edb.88.2020.07.17.00.19.06
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 17 Jul 2020 00:19:07 -0700 (PDT)
From: Marius-Cristian Baciu <2309bmcristi@gmail.com>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 3/3] libdruntime: Resolve missing symbols
Date: Fri, 17 Jul 2020 10:17:37 +0300
Message-Id: <20200717071737.18555-3-2309bmcristi@gmail.com>
X-Mailer: git-send-email 2.17.1
In-Reply-To: <20200717071737.18555-1-2309bmcristi@gmail.com>
References: <20200717071737.18555-1-2309bmcristi@gmail.com>
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: simon.kuenzer@neclab.eu,
 Baciu Marius-Cristian <marius.baciu@stud.acs.upb.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Baciu Marius-Cristian <marius.baciu@stud.acs.upb.ro>

---
 gluecode.c | 264 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 htons_.c   |  11 +++
 2 files changed, 275 insertions(+)
 create mode 100644 gluecode.c
 create mode 100644 htons_.c

diff --git a/gluecode.c b/gluecode.c
new file mode 100644
index 0000000..952d14d
--- /dev/null
+++ b/gluecode.c
@@ -0,0 +1,264 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ *
+ * Authors: Marius-Cristian Baciu <marius.baciu@stud.acs.upb.ro>
+ *
+ *
+ * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
+
+
+#include <sys/_sigset.h>
+#include <sys/stat.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <float.h>
+#include <math.h>
+
+
+typedef __sigset_t  sigset_t;
+int sigfillset(sigset_t *set)
+{
+    return 0;
+}
+
+int sigdelset(sigset_t *set, int t)
+{
+    return 0;
+}
+
+int pthread_setschedprio(pthread_t t, int prio)
+{
+    return 0;
+}
+
+struct _pthread_cleanup_buffer {};
+void _pthread_cleanup_push(struct _pthread_cleanup_buffer* buf, void (*function)(void), void* t) {}
+void _pthread_cleanup_pop(struct _pthread_cleanup_buffer* buf, int t) {}
+
+
+uint32_t htonl(uint32_t t)
+{
+    return 0;
+}
+uint32_t ntohl(uint32_t t)
+{
+    return 0;
+}
+
+
+int __libc_current_sigrtmin()
+{
+    return 0;
+}
+int __libc_current_sigrtmax()
+{
+    return 0;
+}
+
+
+struct tls_index {};
+void* __tls_get_addr(struct tls_index* ti)
+{
+    return ti;
+}
+
+int *__errno_location(void)
+{
+    return 0;
+}
+
+#undef weak_alias
+#define weak_alias(old, new) \
+	extern __typeof(old) new __attribute__((weak, alias(#old)))
+char *__progname=0, *__progname_full=0;
+
+weak_alias(__progname, program_invocation_short_name);
+weak_alias(__progname_full, program_invocation_name);
+
+struct msghdr {};
+struct cmsghdr {};
+struct cmsghdr * __cmsg_nxthdr(struct msghdr *msg, struct cmsghdr *cmsg)
+{
+    return NULL;
+}
+
+/*
+ * math.d
+ */
+int __fpclassify(double x)
+{
+    if (x <= FLT_MAX)
+        return __fpclassifyf((float)x);
+    return 0;
+}
+
+int __fpclassifyl(long double x)
+{
+    if (x <= FLT_MAX)
+        return __fpclassifyf((float)x);
+    return 0;
+}
+
+int __isinf(double x)
+{
+    if (x <= FLT_MAX)
+        return __isinff((float)x);
+    return 0;
+}
+
+int __isinfl(long double x)
+{
+    if (x <= FLT_MAX)
+        return __isinff((float)x);
+    return 0;
+}
+
+int __isnan(double x)
+{
+    if (x <= FLT_MAX)
+        return __isnanf((float)x);
+    return 0;
+}
+
+int __isnanl(long double x)
+{
+    if (x <= FLT_MAX)
+        return __isnanf((float)x);
+    return 0;
+}
+
+int __signbit(double x)
+{
+    if (x <= FLT_MAX)
+        return __signbitf((float)x);
+    return 0;
+}
+
+int __signbitl(long double x)
+{
+    if (x <= FLT_MAX)
+        return __signbitf((float)x);
+    return 0;
+}
+
+int __finite(double x)
+{
+    return 0;
+}
+
+int __finitel(long double x)
+{
+    return 0;
+}
+
+int __finitef(float x)
+{
+    return 0;
+}
+
+long lroundl(long double x)
+{
+    if (x <= DBL_MAX)
+        return lround((double)x);
+    return 0;
+}
+
+long double roundl(long double x)
+{
+    if (x <= DBL_MAX)
+        return round((double)x);
+    return 0;
+}
+
+long double logbl(long double x)
+{
+    if (x <= DBL_MAX)
+        return logb((double)x);
+    return 0;
+}
+
+long double modfl(long double value, long double *iptr)
+{
+    return modf((double)value, (double *)iptr);
+}
+
+long double scalbnl(long double x, int n)
+{
+    if (x <= DBL_MAX)
+        return scalbn((double)x, n);
+    return 0;
+}
+
+
+long double cbrtl(long double x)
+{
+    if (x <= DBL_MAX)
+        return cbrt((double)x);
+    return 0;
+}
+
+long double nearbyintl(long double x)
+{
+    if (x <= DBL_MAX)
+        return nearbyint((double)x);
+    return 0;
+}
+
+long double remainderl(long double x, long double y)
+{
+    if (x <= DBL_MAX && y <= DBL_MAX)
+        return remainder((double)x, (double)y);
+    return 0;
+}
+
+long double remquol(long double x, long double y, int *quo)
+{
+    if (x <= DBL_MAX && y <= DBL_MAX)
+        return remquo((double)x, (double)y, quo);
+    return 0;
+}
+
+void flockfile(FILE *fp) {}
+void funlockfile(FILE *fp) {}
+
+ssize_t getdelim (char** lineptr, size_t* n, int delimiter, FILE* stream)
+{
+    return 0;
+}
+
+char *tzname[2];
+
+int msync(void *first, size_t second, int third)
+{
+    return 0;
+}
diff --git a/htons_.c b/htons_.c
new file mode 100644
index 0000000..2084d9a
--- /dev/null
+++ b/htons_.c
@@ -0,0 +1,11 @@
+unsigned short bswap_16(unsigned short __x)
+{
+	return __x<<8 | __x>>8;
+}
+
+
+unsigned short htons(unsigned short n)
+{
+    union { int i; char c; } u = { 1 };
+	return u.c ? bswap_16(n) : n;
+}
-- 
2.17.1



From minios-devel-bounces@lists.xenproject.org Fri Jul 17 07:29:53 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 17 Jul 2020 07:29:53 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jwKoZ-0001Gx-1s; Fri, 17 Jul 2020 07:29:51 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <SRS0=437+=A4=gmail.com=razvand@srs-us1.protection.inumbo.net>)
 id 1jwKoX-0001Gs-ND
 for minios-devel@lists.xen.org; Fri, 17 Jul 2020 07:29:49 +0000
X-Inumbo-ID: 4ae9f3b0-c7ff-11ea-b7bb-bc764e2007e4
Received: from mail-wm1-x344.google.com (unknown [2a00:1450:4864:20::344])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4ae9f3b0-c7ff-11ea-b7bb-bc764e2007e4;
 Fri, 17 Jul 2020 07:29:48 +0000 (UTC)
Received: by mail-wm1-x344.google.com with SMTP id g75so13618507wme.5
 for <minios-devel@lists.xen.org>; Fri, 17 Jul 2020 00:29:48 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=sender:from:to:cc:subject:references:date:in-reply-to:message-id
 :user-agent:mime-version:content-transfer-encoding;
 bh=Gnfhzah9OGfl88zQr/840xCB4EnOKzNE6kNVXR4WFMU=;
 b=R76dV4pSXARQCwBOn5L5zxE5Rv1MSiVjZSd6u7aILd7RH0AdRr1vo1072bby1f6JJz
 0EYs/H0qgZvlEaTfjqEEdy1RaPz/nsNFLxNDcmb4SiZzvLhKkVzbhp3L3HENpq3jr5DO
 NpIdroYr8p4qnDvZgam3VHU1CBxX30bGsVhfnxRoHZlDQfA9DdM/5luDMENwf7N62lLm
 LE7PinGZItJlvMscx1DQwyeuJYZr9LSiC7yeTCpp55tB35aeks6fPLH1gdl66yONyEiM
 y+MfoxWAkcsJOg6TDRerstlWpdAeromFcBPtrD4dPmsXZTUIgURhX3ELBfwk32oQiJu4
 OzdQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:sender:from:to:cc:subject:references:date
 :in-reply-to:message-id:user-agent:mime-version
 :content-transfer-encoding;
 bh=Gnfhzah9OGfl88zQr/840xCB4EnOKzNE6kNVXR4WFMU=;
 b=XhIuPqjpG17XjIK6wQK+slHu1BGes+tyzLomOMgyckXRgBpKq8+oKuzHS0XJpOKlJ3
 zFDwKvLXeW1dgX1pN46b68WzdzxSKIfhMqciA78fawlDM5vfUszAJp2dEu/fmRadfZ+V
 9NellyjL8iORS8EVsJgnlrSpw3gz4AXCZ1hiuiaFd80/4UzxuVd2dol6nP8L3RPvyZyP
 tG/lrKsUpLbQ/nXzeNhwrfiw6Vpba5gqXF1gJYpe1JK2s40jGOcoLmKzxvDelr9iQ+f3
 bHzHAxFDykEf73iGw3qUMeIGXaisXMoaELBeQBLh+/odrnL1pwZKwt7XtU8MxRf/iJA3
 4uCw==
X-Gm-Message-State: AOAM533fF5YR7Dt9s9wHbuyVD2spwDcDe5f6NJXYN9gyQexN3ENq1Oy+
 mWh0doTufJWfFc91m4ijD24=
X-Google-Smtp-Source: ABdhPJwRq6xHdgCmC8DU+zqtcOiggkk8+1MP1XrvDJYtxAys+jnfbyPqTGbCA2Qr2wqKcCDMx45hwQ==
X-Received: by 2002:a1c:2d0c:: with SMTP id t12mr7721107wmt.43.1594970987168; 
 Fri, 17 Jul 2020 00:29:47 -0700 (PDT)
Received: from localhost ([141.85.233.147])
 by smtp.gmail.com with ESMTPSA id l14sm299360wrg.43.2020.07.17.00.29.45
 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256);
 Fri, 17 Jul 2020 00:29:45 -0700 (PDT)
From: Razvan Deaconescu <razvan.deaconescu@cs.pub.ro>
To: Alice Suiu <alicesuiu17@gmail.com>
Subject: Re: [Minios-devel] [UNIKRAFT/NEWLIB PATCH] include/endian.h Define
 the __bswap16, __bswap32,
 __bswap64 builtin functions only if the compilation is done with gcc
References: <20200301191336.24672-1-alicesuiu17@gmail.com>
 <20200301191336.24672-2-alicesuiu17@gmail.com>
 <ca5ecb2f-8f76-9bf0-aac9-72bfa5bb2438@neclab.eu>
 <CAD2TrnC7Z9_bKk5gFx2U=PmyTJyaxfCsVSPY_AG+RsLLAGfLCg@mail.gmail.com>
Date: Fri, 17 Jul 2020 10:29:44 +0300
In-Reply-To: <CAD2TrnC7Z9_bKk5gFx2U=PmyTJyaxfCsVSPY_AG+RsLLAGfLCg@mail.gmail.com>
 (Alice Suiu's message of "Sun, 5 Apr 2020 21:16:34 +0300")
Message-ID: <86lfjioazb.fsf@drone.cs.pub.ro>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: felipe.huici@neclab.eu, florian.schmidt@neclab.eu,
 Simon Kuenzer <simon.kuenzer@neclab.eu>, minios-devel@lists.xen.org,
 costin.lupu@cs.pub.ro
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Alice Suiu <alicesuiu17@gmail.com> writes:
> =C3=8En joi, 2 apr. 2020 la 19:56, Simon Kuenzer <simon.kuenzer@neclab.eu=
> a scris:
>> Hi Alice,
>>
>> I have a question to this patch:
>>
>> On 01.03.20 20:13, alicesuiu wrote:
>> > Signed-off-by: Alice Suiu <alicesuiu17@gmail.com>
>> > ---
>> >   include/endian.h | 2 ++
>> >   1 file changed, 2 insertions(+)
>> >
>> > diff --git a/include/endian.h b/include/endian.h
>> > index 3c8a752..63d3650 100644
>> > --- a/include/endian.h
>> > +++ b/include/endian.h
>> > @@ -41,6 +41,7 @@
>> >
>> >   #include <stdint.h>
>> >
>> > +#ifndef __clang__
>> >   static inline uint16_t __bswap16(uint16_t __x)
>> >   {
>> >       return __x<<8 | __x>>8;
>> > @@ -55,6 +56,7 @@ static inline uint64_t __bswap64(uint64_t __x)
>> >   {
>> >       return (__bswap32(__x)+0ULL)<<32 | __bswap32(__x>>32);
>> >   }
>> > +#endif
>>
>> Doesn't GCC has a builtin for this and does clang has one, too? We also
>> need to make sure that clang is not introducing libc replacements as
>> default. On GCC that broke the printing with nolibc...
>
> Hi Simon,
>
> Yes, GCC doesn't have these builtin functions, but clang has them. When I
> use nolibc + clang, I don't receive errors. But when I use newlib [1] +
> clang [2], I receive errors because both have these builtin functions.

Both GCC and Clang have define the `__builtin_bswapXY()` builtins. The
actual issue is a different behavior between the two compilers: the
simultaneous definition of a macro `__bswapXY` and a function
`__bswapXY`; GCC doesn't complain, but Clang does. See the sample
here[3].

This is happening in Unikraft because the Unikraft core libraries are
using a minimized Unikraft newlib library[4], while the Unikraft app is
using the upstream (complete) newlib library[5]. In the end there are
two `endian.h` files: one in the Unikraft newlib[6], another one in the
upstream newlib (<repo>/newlib/libc/include/machine/endian.h). The
Unikraft newlib version of `endian.h` defines `__bswapXY` as inline
functions, whereas the upstream newlib defines them as macros. This
results in an error from Clang; GCC doesn't mind, though it's an issue
having multiple definitions for the same thing (even if one is a macro
or one is a function).

Ideally you wouldn't have multiple headers with the same content. But
given the way Unikraft is created (with the core libraries not requiring
the upstream newlib version, only the minimal Unikraft newlib) we need
both of them.

The proper way to fix this is to make the two compatible: update the
Unikraft newlib `endian.h` definitions using the ones from the upstream
newlib, as in the patch below[7]. This works for GCC and Clang.

Simon, does this patch look OK to you? If yes, I will send it to the
mailing list and we can reject the current one.

> [1] https://github.com/unikraft/lib-newlib/blob/master/include/endian.h
> [2] https://clang.llvm.org/docs/LanguageExtensions.html
[3] https://github.com/razvand/snippets/tree/master/tests/bswap
[4] https://github.com/unikraft/lib-newlib
[5] https://github.com/unikraft/lib-newlib/blob/master/Makefile.uk#L53
[6] https://github.com/unikraft/lib-newlib/blob/master/include/endian.h#L44
[7]
-----
diff --git a/include/endian.h b/include/endian.h
index 3c8a752..01476bc 100644
--- a/include/endian.h
+++ b/include/endian.h
@@ -41,6 +41,11 @@

 #include <stdint.h>

+#ifdef __GNUC__
+#define        __bswap16(_x)   __builtin_bswap16(_x)
+#define        __bswap32(_x)   __builtin_bswap32(_x)
+#define        __bswap64(_x)   __builtin_bswap64(_x)
+#else /* __GNUC__ */
 static inline uint16_t __bswap16(uint16_t __x)
  {
          return __x<<8 | __x>>8;
          @@ -55,6 +60,7 @@ static inline uint64_t __bswap64(uint64_t
          __x)
           {
                   return (__bswap32(__x)+0ULL)<<32 |
                   __bswap32(__x>>32);
                    }
                    +#endif /* !__GNUC__ */

 #if __BYTE_ORDER =3D=3D __LITTLE_ENDIAN
  #define htobe16(x) __bswap16(x)~
-----

Razvan


From minios-devel-bounces@lists.xenproject.org Fri Jul 17 08:38:20 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 17 Jul 2020 08:38:20 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jwLso-0008S4-1l; Fri, 17 Jul 2020 08:38:18 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <SRS0=437+=A4=gmail.com=razvand@srs-us1.protection.inumbo.net>)
 id 1jwLsm-0008Rz-PL
 for minios-devel@lists.xen.org; Fri, 17 Jul 2020 08:38:17 +0000
X-Inumbo-ID: daf0e334-c808-11ea-bb8b-bc764e2007e4
Received: from mail-wm1-x341.google.com (unknown [2a00:1450:4864:20::341])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id daf0e334-c808-11ea-bb8b-bc764e2007e4;
 Fri, 17 Jul 2020 08:38:15 +0000 (UTC)
Received: by mail-wm1-x341.google.com with SMTP id o2so16035097wmh.2
 for <minios-devel@lists.xen.org>; Fri, 17 Jul 2020 01:38:15 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=sender:from:to:cc:subject:references:date:in-reply-to:message-id
 :user-agent:mime-version;
 bh=dgSUbKb7EMSMNnXjQtQlKBjGGN7n9pH+owbxU/T8w44=;
 b=uA3YaQlr+wyc58SQG5Q0kUDyggmWlhoZTXUTp0wonhQbxKR0zw2w11TvMxF+gB3QO/
 HmP12JlIa6i3g2VrtfXZyTPoV8DwSEReHlNWjY3ESQN4pW/9ywGfl2jVm+PzibjuTXk+
 0gPmrPeD8yCJQZwkULOfzM9DGLMMU6TtRkS6/PTp7PtFj6ikwhRbyXN6bBbDzENx4zQ0
 1lAh/Xq9GAGS9woxrYq+l/UEb/APQ4hmdNg/Duv2SyD8rswq51rRGV8hqGm9TFhNdjZi
 GLuwvanNul14fTGqVdqku1ruPvKApLkd6Ci5zQSWLM28cJ2RdbKdqIhRg4y1WewO7JPj
 UJyw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:sender:from:to:cc:subject:references:date
 :in-reply-to:message-id:user-agent:mime-version;
 bh=dgSUbKb7EMSMNnXjQtQlKBjGGN7n9pH+owbxU/T8w44=;
 b=XF7fulErwGpg3PkDfPnxaIUxP6PBuETMIAoAH5sDfLpUz/CAQESheOUXfum7A7xOGA
 TouTHWUwGZ727vU74soWonCV/QeCdjsGvbPNuCpyZk748cnxLtEW/fIMBlRas2QyqxJD
 7vdpNFtlJk8vMAC+h4t0U/63z4HzD1Tz58PrjFEYfAoqqwsvuXxLL7jv3OhO/Y+ME3DS
 bVIjoEh9yvuN0g4jxWqSelY5W6C2c3fYmno6+dz4eNMnt5c1DNJKZ9yoXPa5YmFB4VuN
 xy8zyaJd10Y2l6xbfKtmwQJ0u408HKIxICotTB+uy9eG4nB6kANj7UFU2TfLnHRlSDQp
 P8kg==
X-Gm-Message-State: AOAM532iMOzfjkpvDOf50QoO7DGWRPaFDWH0J73+Pv1sI4KoOEAmp7YF
 5cti/+x+IXE6wwLwkx5esUA=
X-Google-Smtp-Source: ABdhPJymbMfPsWFPSEhh5K7zVyf3Ii/3Cur0zWsU+RKfsrUUhjnoaEfWqCoSbho2pQmK5iJuKhJC5g==
X-Received: by 2002:a7b:c94a:: with SMTP id i10mr8565847wml.183.1594975094327; 
 Fri, 17 Jul 2020 01:38:14 -0700 (PDT)
Received: from localhost ([141.85.233.147])
 by smtp.gmail.com with ESMTPSA id 1sm12091204wmf.0.2020.07.17.01.38.13
 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256);
 Fri, 17 Jul 2020 01:38:13 -0700 (PDT)
From: Razvan Deaconescu <razvan.deaconescu@cs.pub.ro>
To: Marius-Cristian Baciu <2309bmcristi@gmail.com>
Subject: Re: [UNIKRAFT PATCH 1/3] libdruntime: Add skeleton for the porting of
 the D Runtime Library
References: <20200717071737.18555-1-2309bmcristi@gmail.com>
Date: Fri, 17 Jul 2020 11:38:12 +0300
In-Reply-To: <20200717071737.18555-1-2309bmcristi@gmail.com> (Marius-Cristian
 Baciu's message of "Fri, 17 Jul 2020 10:17:35 +0300")
Message-ID: <86h7u6o7t7.fsf@drone.cs.pub.ro>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: simon.kuenzer@neclab.eu, minios-devel@lists.xen.org,
 Baciu Marius-Cristian <marius.baciu@stud.acs.upb.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Marius-Cristian Baciu <2309bmcristi@gmail.com> writes:
> +Unikraft D Runtime wrappers
> +----------------------------------
> +
> +This repository contains wrapper code to build lzma with Unikraft.
> +Each C code file in this repository should declare who is the
> +copyright owner and under which terms and conditions the code is
> +licensed. If such a licence note is missing, the following copyright

This should be "to build the D runtime library with Unikraft", not lzma.

Razvan


From minios-devel-bounces@lists.xenproject.org Fri Jul 17 08:45:11 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 17 Jul 2020 08:45:11 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jwLzR-0000oY-KT; Fri, 17 Jul 2020 08:45:09 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <SRS0=437+=A4=gmail.com=razvand@srs-us1.protection.inumbo.net>)
 id 1jwLzQ-0000oT-4v
 for minios-devel@lists.xen.org; Fri, 17 Jul 2020 08:45:08 +0000
X-Inumbo-ID: d067fff0-c809-11ea-b7bb-bc764e2007e4
Received: from mail-wr1-x442.google.com (unknown [2a00:1450:4864:20::442])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id d067fff0-c809-11ea-b7bb-bc764e2007e4;
 Fri, 17 Jul 2020 08:45:07 +0000 (UTC)
Received: by mail-wr1-x442.google.com with SMTP id q5so10132654wru.6
 for <minios-devel@lists.xen.org>; Fri, 17 Jul 2020 01:45:06 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=sender:from:to:cc:subject:references:date:in-reply-to:message-id
 :user-agent:mime-version;
 bh=WiKFbp3dzheaTH0ujaIs5huW9Rbd0zhhAxZxYh5ZZe0=;
 b=SGesQJLQNp/djpmlXldaNG9KKRr0df2N23yLGx8NS3CJCkV1V1igOyWpOf9UqOmSsX
 OMhV+xoJFrI4Q+yhjXese2uuZ1r744iipOf5pD7Q3cMC1G/+f/iJp9IQjGmJ+QLQEvZ4
 fRBtlCcEJaVqvhidpkrhM0MNgXtuIS2kwDLA8BK6QIdTSrD9jThBC49V0k1En3KMi32j
 n0YkxK5XRtrUVxjFQ19tdHaowZmCOUVBWPV7Vw4CHBxm1th/++93i+8qG47tr7K8lMk6
 HOohyaIqgL7Uw76k+4rHC0xS7otlxoIVb52SlxopBO14l/Y5oZdGr4adE1eSpP8upQNT
 s/4Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:sender:from:to:cc:subject:references:date
 :in-reply-to:message-id:user-agent:mime-version;
 bh=WiKFbp3dzheaTH0ujaIs5huW9Rbd0zhhAxZxYh5ZZe0=;
 b=pmffWhMtJO/2jxCRqdysMAYh4UpIbcXzZYoQQoPf3OMZUuWddw4inAADkMJ3ShxHZ2
 2AIJ5tOLEjgXz8zTJLCF6AR36mmR+GifZA2/gwYJSPQZMb48h/qL3ridobHpRc2+m0Xa
 +Mee8gTL8KqtzlSfOot0fA48guobgaIko9YQQBnnl09f0od0mT1G8VRxSfYr5mFha9T9
 yRNzsEE72DxahJAZLQVxhsUQ7Cjs8k8zbaqWfM5o/T6pPmxBMKrjFmG9pJwVKbcONKFH
 S9o0KiulA/mOiZlkLFl/cvZjd1iznsoTBhm+zwj0nYmlhci7T4T4Axr0TwFR2g4i5hiM
 r6sg==
X-Gm-Message-State: AOAM533Cu1F+8LiDqc6HsVqAC2frMRDXhwcuEw2Yadn+xsYskFmkZgbG
 WOhQmcfQTif74BXcX8+o7xg=
X-Google-Smtp-Source: ABdhPJySLc/bNdckuK4AP9tLdgpghmAkb/f/8a23M/A6vWpbo3SLBtVca4VhLrGRjq7jZRPHVDAwpA==
X-Received: by 2002:a05:6000:cf:: with SMTP id
 q15mr9382976wrx.203.1594975506086; 
 Fri, 17 Jul 2020 01:45:06 -0700 (PDT)
Received: from localhost ([141.85.233.147])
 by smtp.gmail.com with ESMTPSA id u20sm12041573wmm.15.2020.07.17.01.45.04
 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256);
 Fri, 17 Jul 2020 01:45:04 -0700 (PDT)
From: Razvan Deaconescu <razvan.deaconescu@cs.pub.ro>
To: Felipe Huici <felipe.huici@neclab.eu>
Subject: Re: [UNIKRAFT/LIBICU PATCH 0/2] Introducing libicu port to Unikraft
References: <20200416195724.18620-1-felipe.huici@neclab.eu>
Date: Fri, 17 Jul 2020 11:45:04 +0300
In-Reply-To: <20200416195724.18620-1-felipe.huici@neclab.eu> (Felipe Huici's
 message of "Thu, 16 Apr 2020 21:57:22 +0200")
Message-ID: <86d04uo7hr.fsf@drone.cs.pub.ro>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: minios-devel@lists.xen.org
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi, Felipe.

I built the libicu library, everything is OK.

But the header files are not included in the Makefile commands that
build the application. I used the libicu API in the main.c (application
source code file) and it fails to find header files.

The header files are included in the Makefile commands to build the
library files:
---
... -I/home/razvan/projects/unicore/unikraft/apps/app-helloworld.git/build/libicu/origin/source/common -I/home/razvan/projects/unicore/unikraft/apps/app-helloworld.git/build/libicu/origin/source/i18n ...
---

The Makefile.uk file looks OK to me. Do you know what the problem might be?

Felipe Huici <felipe.huici@neclab.eu> writes:
> This is our initial port of the International Components for Unicode library to Unikraft.
>
> Felipe Huici (2):
>   Introduce icu to Unikraft.
>   Add documentation
>
>  .gitignore      |  27 +++
>  CODING_STYLE.md |   4 +
>  CONTRIBUTING.md |   4 +
>  COPYING.md      |  30 ++++
>  Config.uk       |  14 ++
>  MAINTAINERS.md  |  10 ++
>  Makefile.uk     | 466 ++++++++++++++++++++++++++++++++++++++++++++++++
>  README.md       |  10 ++
>  8 files changed, 565 insertions(+)
>  create mode 100644 .gitignore
>  create mode 100644 CODING_STYLE.md
>  create mode 100644 CONTRIBUTING.md
>  create mode 100644 COPYING.md
>  create mode 100644 Config.uk
>  create mode 100644 MAINTAINERS.md
>  create mode 100644 Makefile.uk
>  create mode 100644 README.md


From minios-devel-bounces@lists.xenproject.org Fri Jul 17 10:53:57 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 17 Jul 2020 10:53:57 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jwO03-00042a-A5; Fri, 17 Jul 2020 10:53:55 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <SRS0=437+=A4=gmail.com=razvand@srs-us1.protection.inumbo.net>)
 id 1jwO01-00042V-EU
 for minios-devel@lists.xenproject.org; Fri, 17 Jul 2020 10:53:53 +0000
X-Inumbo-ID: cceb4384-c81b-11ea-8496-bc764e2007e4
Received: from mail-wr1-x441.google.com (unknown [2a00:1450:4864:20::441])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id cceb4384-c81b-11ea-8496-bc764e2007e4;
 Fri, 17 Jul 2020 10:53:52 +0000 (UTC)
Received: by mail-wr1-x441.google.com with SMTP id r12so10418816wrj.13
 for <minios-devel@lists.xenproject.org>; Fri, 17 Jul 2020 03:53:52 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=sender:from:to:cc:subject:references:date:in-reply-to:message-id
 :user-agent:mime-version;
 bh=/OtnJebVCnZuTI7MKM1AHDepuT93h+4asWfnMuAsZ/g=;
 b=hDEDHwXSI8+Dv5C5EiH+OrdZ6LAdSiyJUX0TshHz+7DhR7SE8Ps0qHIwZLpBQyr1pF
 KI1fnEU4hrz7zu97FV0fiyOankhtapW0KBnfdBa9Bc8JbELJEl0N811rMliVs1+MzCeu
 tkkZ2S5HXgxMjnqzwrBlKWiU0wiJlQkMnN/zRIPMbArmYjRBFOxaZQSpqJjRW38T6eh0
 i2ndzs5Qq9v/3XhLnvVQ2EQwsMgzhExYResqBc37HFYiM796FTHbJoQu3MNFLMSdg6VY
 iiN8/GOoD5WMOXunUA5iWzA4tbo30ffIdSqnkwY+8NFYy4eNfJhlQPcP7M2sjt1mKPNR
 OvtQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:sender:from:to:cc:subject:references:date
 :in-reply-to:message-id:user-agent:mime-version;
 bh=/OtnJebVCnZuTI7MKM1AHDepuT93h+4asWfnMuAsZ/g=;
 b=p/v7Ks7yoCLNaqsOPIaC5IEtfZgqg93o/AJfExBgcjxU8Uisb4GrzjgpAOhSi05ctk
 EzjcH5mbXE4QLWJx5d0CEac/8vE6j2IxT4ZwngWgZSlQE2BjMMM4/OMuDjdY7fLAH520
 llvATPC/BLEC+6Uke8i4/+aYzGyxM0wptya5KaWv8fCTMBdg6dgPac7CG0UcYIiUFINp
 KL0IytIrV9cHaU9Arxz9FAbiqXmoTAqxuXtydM6BjYs7y1gwzecbSWTNCpF0CjKU0Spy
 J5jcGLFZcyC2MhuSeCCxcfIGYUcJP1Ge2KWfdCNOW69oJmQRsviT5hcyD2d64V4nFjmN
 G6ZQ==
X-Gm-Message-State: AOAM531pWpURay+5VccXdbPDT8cTbPOVId7cDZ8Dq/+9NCIurWeT/IbZ
 CsY1MfAo3DcawvYt/TdvZ+o=
X-Google-Smtp-Source: ABdhPJwd7Hzl8xgAmrJyUi0WtA+XpSZdKFPnliL2iWicvG4lVHq1pTU1ACt5u+RLMKXjGrxSCpIdLA==
X-Received: by 2002:a5d:474f:: with SMTP id o15mr9792845wrs.306.1594983231223; 
 Fri, 17 Jul 2020 03:53:51 -0700 (PDT)
Received: from localhost ([141.85.233.147])
 by smtp.gmail.com with ESMTPSA id o21sm12805190wmh.18.2020.07.17.03.53.50
 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256);
 Fri, 17 Jul 2020 03:53:50 -0700 (PDT)
From: Razvan Deaconescu <razvan.deaconescu@cs.pub.ro>
To: Jia He <justin.he@arm.com>
Subject: Re: [UNIKRAFT/NEWLIB PATCH] include/fcntl.h: Replace O_NONBLOCK with
 new one on arm
References: <20200520095603.55457-1-justin.he@arm.com>
Date: Fri, 17 Jul 2020 13:53:49 +0300
In-Reply-To: <20200520095603.55457-1-justin.he@arm.com> (Jia He's message of
 "Wed, 20 May 2020 17:56:03 +0800")
Message-ID: <86blkel8ea.fsf@drone.cs.pub.ro>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>, minios-devel@lists.xenproject.org,
 Kaly Xin <Kaly.Xin@arm.com>, Costin Lupu <costin.lupu@cs.pub.ro>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>, Sharan.Santhanam@neclab.eu
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Thanks, Justin.

I tested this, all good. It can be upstreamed.

Razvan

Jia He <justin.he@arm.com> writes:
> in newlib _default_fcntl.h, it defines O_NONBLOCK as follows:
> \#define _FNONBLOCK      0x4000  /* non blocking I/O (POSIX style) */
> But it is different from linux definition(04000=0x800):
> \#define O_NONBLOCK	00004000
>
> This difference confused virtio-9p open() syscall. If you open a
> file with O_NONBLOCK(is 0x4000 in newlib) and sys_open will regard
> it as O_DIRECTORY. At last it returns a ENOTDIR error.
>
> Signed-off-by: Jia He <justin.he@arm.com>
> ---
>  include/fcntl.h | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/include/fcntl.h b/include/fcntl.h
> index feb4f7c..367c1e6 100644
> --- a/include/fcntl.h
> +++ b/include/fcntl.h
> @@ -15,6 +15,8 @@
>  #define O_DIRECT     040000
>  #define O_NOATIME  01000000
>  #elif ((defined CONFIG_ARCH_ARM_64) || (defined CONFIG_ARCH_ARM_32))
> +#undef O_NONBLOCK
> +#define O_NONBLOCK    04000
>  #define O_NOFOLLOW  0100000
>  #define O_DIRECTORY  040000
>  #define O_CLOEXEC  02000000


From minios-devel-bounces@lists.xenproject.org Fri Jul 17 11:46:11 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 17 Jul 2020 11:46:11 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jwOoc-000086-96; Fri, 17 Jul 2020 11:46:10 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=si1d=A4=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jwOoa-000081-Qf
 for minios-devel@lists.xenproject.org; Fri, 17 Jul 2020 11:46:08 +0000
X-Inumbo-ID: 19ca20e2-c823-11ea-95d4-12813bfff9fa
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 19ca20e2-c823-11ea-95d4-12813bfff9fa;
 Fri, 17 Jul 2020 11:46:07 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id AEC8E10349B;
 Fri, 17 Jul 2020 13:46:06 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 3R7XTTYnh5zo; Fri, 17 Jul 2020 13:46:06 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id 8A6A31003CD
 for <minios-devel@lists.xenproject.org>; Fri, 17 Jul 2020 13:46:06 +0200 (CEST)
Received: from [10.7.1.9] (192.168.24.96) by puck.office.hd (192.168.24.91)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Fri, 17 Jul
 2020 13:46:05 +0200
Subject: Re: [UNIKRAFT PATCH] driver/virtio: fix virtqueue_vring allocation
To: <minios-devel@lists.xenproject.org>
References: <d2cfd8d7b11ba0856efc8cd9c6bcd5ddc610b4d5.1594728208.git.hugo.lefeuvre@neclab.eu>
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
Message-ID: <16825ca0-5925-452b-5591-8f710b37056a@neclab.eu>
Date: Fri, 17 Jul 2020 13:46:03 +0200
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <d2cfd8d7b11ba0856efc8cd9c6bcd5ddc610b4d5.1594728208.git.hugo.lefeuvre@neclab.eu>
Content-Type: text/plain; charset="utf-8"; format=flowed
Content-Transfer-Encoding: 7bit
Content-Language: en-US
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hello Hugo,

Thanks for the fix.

Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>

Thanks & Regards

Sharan

On 7/14/20 2:04 PM, Hugo Lefeuvre wrote:
> virtqueue_create() allocates virtqueue_vring structures dynamically, but
> the amount of memory requested to the memory allocator is incorrect:
> sizeof(struct virtqueue) instead of sizeof(struct virtqueue_vring).
>
> This bug is probably due to a simple oversight and has gone unnoticed
> because of allocator-specific paddings.
>
> This results in out-of-bounds write in virtqueue_buffer_enqueue.
>
> Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> ---
>   plat/drivers/virtio/virtio_ring.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/plat/drivers/virtio/virtio_ring.c b/plat/drivers/virtio/virtio_ring.c
> index ab9287a..0a5c3f3 100644
> --- a/plat/drivers/virtio/virtio_ring.c
> +++ b/plat/drivers/virtio/virtio_ring.c
> @@ -366,7 +366,7 @@ struct virtqueue *virtqueue_create(__u16 queue_id, __u16 nr_descs, __u16 align,
>   
>   	UK_ASSERT(a);
>   
> -	vrq = uk_malloc(a, sizeof(struct virtqueue) +
> +	vrq = uk_malloc(a, sizeof(*vrq) +
>   			nr_descs * sizeof(struct virtqueue_desc_info));
>   	if (!vrq) {
>   		uk_pr_err("Allocation of virtqueue failed\n");


From minios-devel-bounces@lists.xenproject.org Fri Jul 17 12:49:30 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 17 Jul 2020 12:49:30 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jwPns-0005Ht-9g; Fri, 17 Jul 2020 12:49:28 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=TDTS=A4=gmail.com=raducanu.costi@srs-us1.protection.inumbo.net>)
 id 1jwPnr-0005Ho-RH
 for minios-devel@lists.xen.org; Fri, 17 Jul 2020 12:49:27 +0000
X-Inumbo-ID: f23a49f4-c82b-11ea-bb8b-bc764e2007e4
Received: from mail-ej1-x641.google.com (unknown [2a00:1450:4864:20::641])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id f23a49f4-c82b-11ea-bb8b-bc764e2007e4;
 Fri, 17 Jul 2020 12:49:26 +0000 (UTC)
Received: by mail-ej1-x641.google.com with SMTP id o18so10597673eje.7
 for <minios-devel@lists.xen.org>; Fri, 17 Jul 2020 05:49:26 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:cc:subject:date:message-id;
 bh=S4bABZZLxOym0kcqxZiblioOGjvMZjTEIVUGL5UdrHw=;
 b=pO77R4TeVeBINZSIZnDEgHtdy/oPHqs5+rV7Cg/tFZs0LuA9l0o+C7YJBoRAdR7Fwv
 bV2icFphiof7yNRgB4f8vXVkPq+GwC5Ssa8yjS/SL8vaKRrdWV4ztOHcfoh1VQqpujlQ
 4t69bhjUAA7CDnS4BIpyemyUyFC5yz+MSxopj3AftW++9/7DznMJn94vpdqg39un1Xts
 ZdrsZ/RqC1BXQr4wBNGoyXNT5nVo+cPMXU+g8KJuIyjBwQiBza/fytp3Sz0sM+4QZqLr
 nuZl2k3qLFBCz2BnNIYI1Wbj/+yIXUW8farkNChdE15713BqFU6Xc1LHtVkp+wUENZ4h
 jFDw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:date:message-id;
 bh=S4bABZZLxOym0kcqxZiblioOGjvMZjTEIVUGL5UdrHw=;
 b=btos5thGMpHIiGGBMmJKOiwr9JeZsEOFlt5sUxxCbvjeYcuoUIm7Ci5iZMlmaxioyz
 xC742Bl5EqxWtajfF1JcJOliIFh9JWJam9ZWPJmAh1nl5OwrIaDTpUFIYQ4mNjysOrpg
 rEk69vZ78LekZwBvyJrNpaNLuNJW3iYdSZ31MvAOHwZxPW/8fMIu8VUpUZgCTyBX4M73
 xxNN1cXJVxpY/IrCdlX/c58LDkYb5F+DDm3aeWe+Zg3OfEynwYQfKFhYpXfqMZ3qDy/m
 e+ByNnHhL9Kkchr0bsYMf0xr/btcPvdzBJjdrsK86/nbg/nvjXYLp9bSq47brf49HqqC
 7HqA==
X-Gm-Message-State: AOAM530YWfqOaRbeDzYqpbx9x4EbU+I+sz11Agr2WXlun+xqaCHUI6Ya
 9rMjg1+JMtgTJpLaKBHa1wr0VJYElZM=
X-Google-Smtp-Source: ABdhPJzbVGp5U2ZXfu57owfJzKIa3kdpluKrYRgaJmhZ/sJOueGAVjmVajerxRGju1NXzcGymRZfBw==
X-Received: by 2002:a17:906:57c6:: with SMTP id
 u6mr8297211ejr.194.1594990165510; 
 Fri, 17 Jul 2020 05:49:25 -0700 (PDT)
Received: from localhost.localdomain ([82.78.98.52])
 by smtp.gmail.com with ESMTPSA id d5sm8305579eds.40.2020.07.17.05.49.24
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 17 Jul 2020 05:49:25 -0700 (PDT)
From: Constantin Raducanu <raducanu.costi@gmail.com>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 1/5] lib/vfscore: Register `getpid` and `getppid` to
 syscall_shim
Date: Fri, 17 Jul 2020 15:47:14 +0300
Message-Id: <20200717124718.16583-1-raducanu.costi@gmail.com>
X-Mailer: git-send-email 2.17.1
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: simon.kuenzer@neclab.eu, Constantin Raducanu <raducanu.costi@gmail.com>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Registers `getpid` and `getppid` system call to syscall_shim library.

Signed-off-by: Constantin Raducanu <raducanu.costi@gmail.com>
---
 lib/posix-process/Makefile.uk | 2 ++
 lib/posix-process/process.c   | 6 +++---
 lib/posix-user/exportsyms.uk  | 6 ++++++
 3 files changed, 11 insertions(+), 3 deletions(-)
 create mode 100644 lib/posix-user/exportsyms.uk

diff --git a/lib/posix-process/Makefile.uk b/lib/posix-process/Makefile.uk
index f7a623d..0b3ac82 100644
--- a/lib/posix-process/Makefile.uk
+++ b/lib/posix-process/Makefile.uk
@@ -10,3 +10,5 @@ LIBPOSIX_PROCESS_SUPPRESS_FLAGS-y   += -Wno-unused-parameter
 LIBPOSIX_PROCESS_CFLAGS-y           += $(LIBPOSIX_PROCESS_SUPPRESS_FLAGS-y)
 
 LIBPOSIX_PROCESS_SRCS-y += $(LIBPOSIX_PROCESS_BASE)/process.c
+
+UK_PROVIDED_SYSCALLS-$(CONFIG_LIBPOSIX_PROCESS) += getpid-0 getppid-0
\ No newline at end of file
diff --git a/lib/posix-process/process.c b/lib/posix-process/process.c
index 0f3bd53..59b5bb0 100644
--- a/lib/posix-process/process.c
+++ b/lib/posix-process/process.c
@@ -40,7 +40,7 @@
 #include <sys/resource.h>
 #include <uk/process.h>
 #include <uk/print.h>
-
+#include <uk/syscall.h>
 
 int fork(void)
 {
@@ -215,12 +215,12 @@ pid_t wait4(pid_t pid __unused, int *wstatus __unused, int options __unused,
 	return -1;
 }
 
-int getpid(void)
+UK_SYSCALL_R_DEFINE(int, getpid)
 {
 	return UNIKRAFT_PID;
 }
 
-pid_t getppid(void)
+UK_SYSCALL_R_DEFINE(pid_t, getppid)
 {
 	return UNIKRAFT_PPID;
 }
diff --git a/lib/posix-user/exportsyms.uk b/lib/posix-user/exportsyms.uk
new file mode 100644
index 0000000..2acde9d
--- /dev/null
+++ b/lib/posix-user/exportsyms.uk
@@ -0,0 +1,6 @@
+getpid
+uk_syscall_e_getpid
+uk_syscall_r_getpid
+getppid
+uk_syscall_e_getppid
+uk_syscall_r_getppid
-- 
2.17.1



From minios-devel-bounces@lists.xenproject.org Fri Jul 17 12:49:33 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 17 Jul 2020 12:49:33 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jwPnx-0005IY-BK; Fri, 17 Jul 2020 12:49:33 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=TDTS=A4=gmail.com=raducanu.costi@srs-us1.protection.inumbo.net>)
 id 1jwPnw-0005Ho-KH
 for minios-devel@lists.xen.org; Fri, 17 Jul 2020 12:49:32 +0000
X-Inumbo-ID: f2d86544-c82b-11ea-b7bb-bc764e2007e4
Received: from mail-ej1-x642.google.com (unknown [2a00:1450:4864:20::642])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id f2d86544-c82b-11ea-b7bb-bc764e2007e4;
 Fri, 17 Jul 2020 12:49:27 +0000 (UTC)
Received: by mail-ej1-x642.google.com with SMTP id o18so10597739eje.7
 for <minios-devel@lists.xen.org>; Fri, 17 Jul 2020 05:49:27 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:cc:subject:date:message-id:in-reply-to:references;
 bh=gkSrjx1wZ4ovoT6EBy/HHp7/p4SxWOaxnwOR7bpWDUw=;
 b=FMIAfzWT+MDuDqSuKGnY7NFfGSkezb3Fd5grNYrFwu6Rm19C0ISy10IdjpvUH7eB1j
 8TakWo+0WegyWoa1d9V1CXsi2aMqIH/I8jpLdbiYfV1kYYE7yr4TsqvzNC8unAENsE/K
 xmXs1ypC06htw6VQKhKvi4yki6/ZGlvYRBo9q44sqXo2uUffWwJfXrLTkZgoKL5h1s6E
 ZDzKhks36Nd1XucanXjz0IOs0h96QAoyj+Jhu7chLysU4b40vDGe5+vSSir4QOaXWBqN
 K2KvnR42xAay4NVp8q5XeoZ9Hfw3uBGv3gK1MPSTV4pLhIvJtLTykwhwCVlhNl/mB5MU
 xnkA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
 :references;
 bh=gkSrjx1wZ4ovoT6EBy/HHp7/p4SxWOaxnwOR7bpWDUw=;
 b=q2WfxOUhEx9Q3k4EH4okAK+05Gby39Xrh9eB5YyrzrE+XXLddz8AW/AM40qr1vorqj
 EZXi9YpwGGErKohWUwz5gvCNosmo8G5P78/abRgzTzAcFaNhfzE19iKG1g8QwoDlWokt
 A1QrPJLph34pmDAsWoiDfX4s21i7YUdCArUKsHVAlF/G9SLLMz5ue/tns34Za0o36qKn
 6+HZNDq4qv1AAYBKLq9zpA+EiykO078+p09UyCj+xq4cCUxt2nXmXJuCjGWWp6Kp0AjP
 ACoYVkmrCOxvv7ZgcyoX7fUmUF7Qa5ULQHCYiulc/0nhaVH3IFy9egecxCQyzhiAaNkh
 iZiw==
X-Gm-Message-State: AOAM533G5zw6N9w+gdY2kf01A/sKl8zkxUbf+84ikA2Ay2PWpjkn8LQU
 8jbWwEy5eKqlok32TBrcpgQuB1txggE=
X-Google-Smtp-Source: ABdhPJwzajf9NwUlyahYq1rj69xoGwTF5JlpglsSeCoTd3pw9/bCWkSF0dPUbvxhqc3yqp2IQ5nYSw==
X-Received: by 2002:a17:907:212b:: with SMTP id
 qo11mr8243435ejb.452.1594990166615; 
 Fri, 17 Jul 2020 05:49:26 -0700 (PDT)
Received: from localhost.localdomain ([82.78.98.52])
 by smtp.gmail.com with ESMTPSA id d5sm8305579eds.40.2020.07.17.05.49.25
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 17 Jul 2020 05:49:26 -0700 (PDT)
From: Constantin Raducanu <raducanu.costi@gmail.com>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 2/5] lib/ukmmap: Register `mmap` and `munmap` to
 syscall_shim
Date: Fri, 17 Jul 2020 15:47:15 +0300
Message-Id: <20200717124718.16583-2-raducanu.costi@gmail.com>
X-Mailer: git-send-email 2.17.1
In-Reply-To: <20200717124718.16583-1-raducanu.costi@gmail.com>
References: <20200717124718.16583-1-raducanu.costi@gmail.com>
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: simon.kuenzer@neclab.eu, Constantin Raducanu <raducanu.costi@gmail.com>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Registers `mmap` and `munmap` system calls to syscall_shim library.

Signed-off-by: Constantin Raducanu <raducanu.costi@gmail.com>
---
 lib/ukmmap/Makefile.uk   | 2 ++
 lib/ukmmap/exportsyms.uk | 4 ++++
 lib/ukmmap/mmap.c        | 7 ++++---
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/lib/ukmmap/Makefile.uk b/lib/ukmmap/Makefile.uk
index 71ff432..ac49d36 100644
--- a/lib/ukmmap/Makefile.uk
+++ b/lib/ukmmap/Makefile.uk
@@ -1,3 +1,5 @@
 $(eval $(call addlib_s,libukmmap,$(CONFIG_LIBUKMMAP)))
 
 LIBUKMMAP_SRCS-y += $(LIBUKMMAP_BASE)/mmap.c
+
+UK_PROVIDED_SYSCALLS-$(CONFIG_LIBUKMMAP) += mmap-6 munmap-2
diff --git a/lib/ukmmap/exportsyms.uk b/lib/ukmmap/exportsyms.uk
index 6b8c116..eb1c19a 100644
--- a/lib/ukmmap/exportsyms.uk
+++ b/lib/ukmmap/exportsyms.uk
@@ -1,3 +1,7 @@
 mmap
+uk_syscall_e_mmap
+uk_syscall_r_mmap
 munmap
+uk_syscall_e_munmap
+uk_syscall_r_munmap
 mremap
diff --git a/lib/ukmmap/mmap.c b/lib/ukmmap/mmap.c
index 39ecbef..ea0173a 100644
--- a/lib/ukmmap/mmap.c
+++ b/lib/ukmmap/mmap.c
@@ -37,6 +37,7 @@
 #include <sys/mman.h>
 #include <uk/alloc.h>
 #include <string.h>
+#include <uk/syscall.h>
 
 struct mmap_addr {
 	void *begin;
@@ -64,8 +65,8 @@ static struct mmap_addr *mmap_addr;
  *
  */
 
-void *mmap(void *addr, size_t len, int prot,
-		int flags, int fildes, off_t off)
+UK_SYSCALL_DEFINE(void*, mmap, void*, addr, size_t, len, int, prot,
+		int, flags, int, fildes, off_t, off)
 {
 	struct mmap_addr *tmp = mmap_addr, *last = NULL, *new = NULL;
 
@@ -125,7 +126,7 @@ void *mmap(void *addr, size_t len, int prot,
  * Otherwise the initial memory block is replaced by a smaller one.
  */
 
-int munmap(void *addr, size_t len)
+UK_SYSCALL_DEFINE(int, munmap, void*, addr, size_t, len)
 {
 	struct mmap_addr *tmp = mmap_addr, *prev = NULL;
 	size_t remain_mem;
-- 
2.17.1



From minios-devel-bounces@lists.xenproject.org Fri Jul 17 12:49:38 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 17 Jul 2020 12:49:38 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jwPo2-0005K3-Cw; Fri, 17 Jul 2020 12:49:38 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=TDTS=A4=gmail.com=raducanu.costi@srs-us1.protection.inumbo.net>)
 id 1jwPo1-0005Ho-KW
 for minios-devel@lists.xen.org; Fri, 17 Jul 2020 12:49:37 +0000
X-Inumbo-ID: f367557e-c82b-11ea-bca7-bc764e2007e4
Received: from mail-ej1-x644.google.com (unknown [2a00:1450:4864:20::644])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id f367557e-c82b-11ea-bca7-bc764e2007e4;
 Fri, 17 Jul 2020 12:49:28 +0000 (UTC)
Received: by mail-ej1-x644.google.com with SMTP id br7so10604081ejb.5
 for <minios-devel@lists.xen.org>; Fri, 17 Jul 2020 05:49:28 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:cc:subject:date:message-id:in-reply-to:references;
 bh=eZrJ9i00idJ1936hPpwdOyFzGy340MQgYI/M4WPevhc=;
 b=LlirYArFifvgyNEoYkCWjiHNW5KYGHtj6Rd+8NNOitkowLLadCQ+iEG+fGsptaqzLh
 XFE9giAaaX6kVCNCTCW0XO1josS/8M/2vJgREyjsFwWYSj0G9FxLokYXN6OUMFORZsPC
 h2XiGwURCGTg88R7SEJRPAz8P8SQ/bEp/9C6Rd/iyTH+kMxzu75Kw+iD3n5o8bJa2Mhc
 Rpvd9YbMrDrggTjxzz5RwEQcCqY8DfpY7q/Z+XRgNUt6/37LBgcBeOn9cslWCJqIXBst
 GJRjEUw3k6t2wNVMU5TgdkZraUEzFA11f7QcfAQi7r9L8vKAnbPtLa9k24CWy9q7ifPa
 ElIA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
 :references;
 bh=eZrJ9i00idJ1936hPpwdOyFzGy340MQgYI/M4WPevhc=;
 b=V3d3ZEfspQrBvvaKxlrqBX1m3/Lbmplb41prGaqhxweqvTCQ8rfa+HVA+6YLMB3lWK
 i8lBW/zJSfya0MJTbW7o+MFEumxF35QOkonqJ6nFIgZh/+DQBCE5OTLvWqSIH6el6cJ7
 7mDD92rYA3NT8qUY1YkYn+addVg9u31SOQfoPoIHZ42VKnp8DCu1TqOzo7adu2Jttk7J
 uyfK4OBQu/LrgsRZVA2yYU9/NnYonk+SCP3iNgiqfR+slvaukaAj5cL10j9Avo6giXJf
 ADgg4B4Ow8V0I2YvQnLpjUo2Ji+mMq++odo+1K3xHBBlWu5FYN89J8gUNMS7oAvmlQFE
 uRrQ==
X-Gm-Message-State: AOAM530EFht4ZSS8V0Udij8iyhvNxvU7co/ejBktkxt6r7OLun3V7SER
 u/eJFuqsyaCyP7oGiJHIIr6uuny7q3U=
X-Google-Smtp-Source: ABdhPJwWAE5SvW/s6jHVDVqce8Otzi8TiZjhIrSckZb8GmS71o9FAY34sqHg02ock+dP5L0COcOIBw==
X-Received: by 2002:a17:906:3784:: with SMTP id
 n4mr8681690ejc.277.1594990167508; 
 Fri, 17 Jul 2020 05:49:27 -0700 (PDT)
Received: from localhost.localdomain ([82.78.98.52])
 by smtp.gmail.com with ESMTPSA id d5sm8305579eds.40.2020.07.17.05.49.26
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 17 Jul 2020 05:49:27 -0700 (PDT)
From: Constantin Raducanu <raducanu.costi@gmail.com>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 3/5] lib/uktime: Register `gettimeofday` to
 syscall_shim
Date: Fri, 17 Jul 2020 15:47:16 +0300
Message-Id: <20200717124718.16583-3-raducanu.costi@gmail.com>
X-Mailer: git-send-email 2.17.1
In-Reply-To: <20200717124718.16583-1-raducanu.costi@gmail.com>
References: <20200717124718.16583-1-raducanu.costi@gmail.com>
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: simon.kuenzer@neclab.eu, Constantin Raducanu <raducanu.costi@gmail.com>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Registers `gettimeofday` system call to syscall_shim library.
In order to avoid the unused warning for the second parameter,
I had to provide all three system call entry functions manually.

Signed-off-by: Constantin Raducanu <raducanu.costi@gmail.com>
---
 lib/uktime/Makefile.uk   |  2 ++
 lib/uktime/exportsyms.uk |  2 ++
 lib/uktime/time.c        | 32 +++++++++++++++++++++++++++-----
 3 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/lib/uktime/Makefile.uk b/lib/uktime/Makefile.uk
index 2976a10..4fdf282 100644
--- a/lib/uktime/Makefile.uk
+++ b/lib/uktime/Makefile.uk
@@ -12,3 +12,5 @@ LIBUKTIME_SRCS-y += $(LIBUKTIME_BASE)/musl-imported/src/__tm_to_secs.c
 LIBUKTIME_SRCS-y += $(LIBUKTIME_BASE)/musl-imported/src/__year_to_secs.c
 LIBUKTIME_SRCS-y += $(LIBUKTIME_BASE)/time.c
 LIBUKTIME_SRCS-y += $(LIBUKTIME_BASE)/timer.c
+
+UK_PROVIDED_SYSCALLS-$(CONFIG_LIBUKTIME) += gettimeofday-2
\ No newline at end of file
diff --git a/lib/uktime/exportsyms.uk b/lib/uktime/exportsyms.uk
index 82b70b7..90ad7f9 100644
--- a/lib/uktime/exportsyms.uk
+++ b/lib/uktime/exportsyms.uk
@@ -2,6 +2,8 @@ clock_getres
 clock_gettime
 clock_settime
 gettimeofday
+uk_syscall_e_gettimeofday
+uk_syscall_r_gettimeofday
 nanosleep
 setitimer
 sleep
diff --git a/lib/uktime/time.c b/lib/uktime/time.c
index 4d3ba53..e45b6f4 100644
--- a/lib/uktime/time.c
+++ b/lib/uktime/time.c
@@ -43,6 +43,8 @@
 #include <uk/plat/time.h>
 #include <uk/config.h>
 #include <uk/print.h>
+#include <uk/syscall.h>
+
 #if CONFIG_HAVE_SCHED
 #include <uk/sched.h>
 #else
@@ -125,20 +127,40 @@ unsigned int sleep(unsigned int seconds)
 	return 0;
 }
 
-int gettimeofday(struct timeval *tv, void *tz __unused)
+long uk_syscall_r_gettimeofday(long tv, long tz __unused)
 {
 	__nsec now = ukplat_wall_clock();
 
 	if (!tv) {
-		errno = EINVAL;
-		return -1;
+		return -EINVAL;
 	}
 
-	tv->tv_sec = ukarch_time_nsec_to_sec(now);
-	tv->tv_usec = ukarch_time_nsec_to_usec(ukarch_time_subsec(now));
+	((struct timeval*) tv)->tv_sec = ukarch_time_nsec_to_sec(now);
+	((struct timeval*) tv)->tv_usec = 
+		ukarch_time_nsec_to_usec(ukarch_time_subsec(now));
+
 	return 0;
 }
 
+long uk_syscall_e_gettimeofday(long tv, long tz __unused)
+{
+	long ret;
+
+	ret = uk_syscall_r_gettimeofday(tv, tz);
+	if (ret < 0) {
+		errno = (int) -ret;
+		return -1;
+	}
+	return 0;
+}
+
+#if !UK_LIBC_SYSCALL
+int gettimeofday (struct timeval* tv, void* tz __unused)
+{
+	return uk_syscall_e_gettimeofday((long) tv, (long)tz);
+}
+#endif
+
 int clock_getres(clockid_t clk_id __unused, struct timespec *res __unused)
 {
 	return 0;
-- 
2.17.1



From minios-devel-bounces@lists.xenproject.org Fri Jul 17 12:49:43 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 17 Jul 2020 12:49:43 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jwPo7-0005L7-Ec; Fri, 17 Jul 2020 12:49:43 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=TDTS=A4=gmail.com=raducanu.costi@srs-us1.protection.inumbo.net>)
 id 1jwPo6-0005Ho-Ki
 for minios-devel@lists.xen.org; Fri, 17 Jul 2020 12:49:42 +0000
X-Inumbo-ID: f3f8961a-c82b-11ea-b7bb-bc764e2007e4
Received: from mail-ej1-x641.google.com (unknown [2a00:1450:4864:20::641])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id f3f8961a-c82b-11ea-b7bb-bc764e2007e4;
 Fri, 17 Jul 2020 12:49:29 +0000 (UTC)
Received: by mail-ej1-x641.google.com with SMTP id n22so7675838ejy.3
 for <minios-devel@lists.xen.org>; Fri, 17 Jul 2020 05:49:29 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:cc:subject:date:message-id:in-reply-to:references;
 bh=V3vESvJQI+//o6X176FLcAQRmQzgnN1NdOfYiT2iA08=;
 b=kvHe8xmE+49uxrydNgFp4g+lKBNpaDxAJkUqIywI3JWBZb3Z9Df6i2xnp73bL1txKL
 hkJyIO3Pw6aGMsfagL4wJxdlLD9BxEmCz/W/HbncU8VxwCiU1xd3bLeDpUKc2weNzJ7T
 V9KfoQfMRwavpiK03LqLNR9aaZ2sbc1OWZ/8etxBgRpC8RatWjuYrTvpM/nddqsn95N6
 jVEyC8AIo7Q9O6ggvmIFLSFsi/YLrpC+aBwLjbgjGxiWIFBJh7OmEGN8pXDR2TLRFI0H
 L5PhkGNq3EmImgRfv2Sg5t3sytA7JSJ5aQMvBcSJ4VX/GYt2SDTBSeF/HpOXTZA3fLzx
 9NTA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
 :references;
 bh=V3vESvJQI+//o6X176FLcAQRmQzgnN1NdOfYiT2iA08=;
 b=arXk3Bde2dxH//YQrMyAJrjq0ShE9zBUjCFbDHnSNdYoWgJE8oP97x7x+j25WrwbWH
 b0IQkkoSGBKPpOSJsaIRTt40ofySZEZTY+/Ah3cChBcWsFcdjE4eiYoN1kTDf3Ykqaa3
 N7ir0mMr3TqttC25IB5rHcO9e5LtkOTj+m66C4+4XCt5idJ+plh+EYNe2s+VKzRri8TD
 nnIWwb2XvLcg2Xd339HfgU8Vvpqh12WNqNSbddDH89+FXCya5xQnLgIQmxmzME2QupAn
 bLAvVUfDdFnrfGXp1WvfyenNd7tzCSwQNKO66vl+ilzUQ35a4BTXmD3mFNrszWY/8v+g
 2J1w==
X-Gm-Message-State: AOAM531U0DJtwQAi1ilH1dChPBZEwFcz0l4laTHO8M/4qOoPXnlSQWjE
 ccEfp/g3Q3TUX+gHfbKZoEKPnzQyP6Q=
X-Google-Smtp-Source: ABdhPJx6BmVf5fPCzJyZinbpjB+IuqTv7JsgHdscTWaT8TgeRgioxfZDY1XJFgpWjZwfGBFaaW/HWA==
X-Received: by 2002:a17:906:1357:: with SMTP id
 x23mr8946562ejb.148.1594990168469; 
 Fri, 17 Jul 2020 05:49:28 -0700 (PDT)
Received: from localhost.localdomain ([82.78.98.52])
 by smtp.gmail.com with ESMTPSA id d5sm8305579eds.40.2020.07.17.05.49.27
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 17 Jul 2020 05:49:28 -0700 (PDT)
From: Constantin Raducanu <raducanu.costi@gmail.com>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 4/5] lib/uktime: Register `clock_gettime` to
 syscall_shim
Date: Fri, 17 Jul 2020 15:47:17 +0300
Message-Id: <20200717124718.16583-4-raducanu.costi@gmail.com>
X-Mailer: git-send-email 2.17.1
In-Reply-To: <20200717124718.16583-1-raducanu.costi@gmail.com>
References: <20200717124718.16583-1-raducanu.costi@gmail.com>
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: simon.kuenzer@neclab.eu, Constantin Raducanu <raducanu.costi@gmail.com>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Registers `clock_gettime` system call to syscall_shim library.

Signed-off-by: Constantin Raducanu <raducanu.costi@gmail.com>
---
 lib/uktime/Makefile.uk   |  3 ++-
 lib/uktime/exportsyms.uk |  2 ++
 lib/uktime/time.c        | 15 ++++++++++-----
 3 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/lib/uktime/Makefile.uk b/lib/uktime/Makefile.uk
index 4fdf282..fa29f72 100644
--- a/lib/uktime/Makefile.uk
+++ b/lib/uktime/Makefile.uk
@@ -13,4 +13,5 @@ LIBUKTIME_SRCS-y += $(LIBUKTIME_BASE)/musl-imported/src/__year_to_secs.c
 LIBUKTIME_SRCS-y += $(LIBUKTIME_BASE)/time.c
 LIBUKTIME_SRCS-y += $(LIBUKTIME_BASE)/timer.c
 
-UK_PROVIDED_SYSCALLS-$(CONFIG_LIBUKTIME) += gettimeofday-2
\ No newline at end of file
+UK_PROVIDED_SYSCALLS-$(CONFIG_LIBUKTIME) += gettimeofday-2
+UK_PROVIDED_SYSCALLS-$(CONFIG_LIBUKTIME) += clock_gettime-2
\ No newline at end of file
diff --git a/lib/uktime/exportsyms.uk b/lib/uktime/exportsyms.uk
index 90ad7f9..a79034a 100644
--- a/lib/uktime/exportsyms.uk
+++ b/lib/uktime/exportsyms.uk
@@ -1,5 +1,7 @@
 clock_getres
 clock_gettime
+uk_syscall_e_clock_gettime
+uk_syscall_r_clock_gettime
 clock_settime
 gettimeofday
 uk_syscall_e_gettimeofday
diff --git a/lib/uktime/time.c b/lib/uktime/time.c
index e45b6f4..2f1ee84 100644
--- a/lib/uktime/time.c
+++ b/lib/uktime/time.c
@@ -166,30 +166,35 @@ int clock_getres(clockid_t clk_id __unused, struct timespec *res __unused)
 	return 0;
 }
 
-int clock_gettime(clockid_t clk_id __unused, struct timespec *tp __unused)
+UK_SYSCALL_R_DEFINE(int, clock_gettime, clockid_t, clk_id, struct timespec*, tp)
 {
 	__nsec now;
+	int error;
 
 	if (!tp) {
-		errno = EFAULT;
-		return -1;
+		error = EFAULT;
+		goto out_error;
 	}
 
 	switch (clk_id) {
 	case CLOCK_MONOTONIC:
+	case CLOCK_MONOTONIC_COARSE:
 		now = ukplat_monotonic_clock();
 		break;
 	case CLOCK_REALTIME:
 		now = ukplat_wall_clock();
 		break;
 	default:
-		errno = EINVAL;
-		return -1;
+		error = EINVAL;
+		goto out_error;
 	}
 
 	tp->tv_sec = ukarch_time_nsec_to_sec(now);
 	tp->tv_nsec = ukarch_time_subsec(now);
 	return 0;
+
+out_error:
+	return -error;
 }
 
 int clock_settime(clockid_t clk_id __unused, const struct timespec *tp __unused)
-- 
2.17.1



From minios-devel-bounces@lists.xenproject.org Fri Jul 17 12:49:48 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 17 Jul 2020 12:49:48 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jwPoC-0005MF-GF; Fri, 17 Jul 2020 12:49:48 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=TDTS=A4=gmail.com=raducanu.costi@srs-us1.protection.inumbo.net>)
 id 1jwPoB-0005Ho-Kl
 for minios-devel@lists.xen.org; Fri, 17 Jul 2020 12:49:47 +0000
X-Inumbo-ID: f483fb42-c82b-11ea-bca7-bc764e2007e4
Received: from mail-ed1-x542.google.com (unknown [2a00:1450:4864:20::542])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id f483fb42-c82b-11ea-bca7-bc764e2007e4;
 Fri, 17 Jul 2020 12:49:30 +0000 (UTC)
Received: by mail-ed1-x542.google.com with SMTP id by13so7527001edb.11
 for <minios-devel@lists.xen.org>; Fri, 17 Jul 2020 05:49:30 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:cc:subject:date:message-id:in-reply-to:references;
 bh=2xS5VsJdf66p7trybJGwAN8ZoSBxVcyEpBUFYiijUe0=;
 b=c0jpyI6Q8t5HYVpGrAmYrmCaLaNrCk8nxX5yQR7zOxWSAPyqybGCOp7WS7+vSsMPms
 shg/M98BAAGgMEGfWUfxwkG/Tp44vqJkTReeM21LHqdd6y+O4Jf2MfF/sVS9ADofqsLU
 ID9rfq5isaje240NWdtnLtVLom/bfkZFG+SCNR3Q1sMx0CAdP/vsUd9KyS1aEfIFBDTI
 OcWS4K6OP1XIIvEfd5Vqjt8OZvsJjtDGaO+DpyUVH4gpncOPPs4QCJOfadwGerykpqlA
 8kKmikCd2G2wzsgT9NSdiQJquLuUly/jy2VK2rNP6SHas+QRNMrzehzjlxpXlHiw3eUA
 6Wcg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
 :references;
 bh=2xS5VsJdf66p7trybJGwAN8ZoSBxVcyEpBUFYiijUe0=;
 b=tzEcm4Ltq5XWhMyqoh/odTH93Xofd9mdjb81s96gDM4sKSQQh/VM83B/6WroBM0ytL
 YO57i8nJX2nEuF8euxwgD2Jo2Enwe6eOODAm718No23+nhIweCmMJqdVVV5nvc6+Jp2+
 Rk4nLYgEDyV/6beMmDfwlVn8v8fYnAbUUy8ankHUeDm7kUAz+bEllXbS6GwupVI6RemP
 FZF8p6ZmX594So380i0R5xl7EnJmVx1PviB7+2yNWUvsINHsqHCfyyFJ4uV0zHfaPfWL
 hunrojAEVmNRFilkjzxxI9kn6qVmx9zsRv5OguVs9rM5Qzb5SInAWf8OuYmq7kGSud4P
 /fNA==
X-Gm-Message-State: AOAM532ljq5nxHgPeQPUsOpsrzner3YNTaIy/3DjFo4mH4juxlLFSa4+
 9/uOr0k7CoHi/1yWPxCXWaWA6FZsoUo=
X-Google-Smtp-Source: ABdhPJzhTjY421k3UHSM9ArlaVM5epOcPeUKA3LadEihvH8mjvIbtoLiICSaopaUq8iw9+tCCT7faQ==
X-Received: by 2002:a50:9f6a:: with SMTP id b97mr8833892edf.322.1594990169431; 
 Fri, 17 Jul 2020 05:49:29 -0700 (PDT)
Received: from localhost.localdomain ([82.78.98.52])
 by smtp.gmail.com with ESMTPSA id d5sm8305579eds.40.2020.07.17.05.49.28
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 17 Jul 2020 05:49:29 -0700 (PDT)
From: Constantin Raducanu <raducanu.costi@gmail.com>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 5/5] lib/vfscore: Register `getcwd` to syscall_shim
Date: Fri, 17 Jul 2020 15:47:18 +0300
Message-Id: <20200717124718.16583-5-raducanu.costi@gmail.com>
X-Mailer: git-send-email 2.17.1
In-Reply-To: <20200717124718.16583-1-raducanu.costi@gmail.com>
References: <20200717124718.16583-1-raducanu.costi@gmail.com>
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: simon.kuenzer@neclab.eu, Constantin Raducanu <raducanu.costi@gmail.com>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Registers `getcwd` system call to syscall_shim library.

Signed-off-by: Constantin Raducanu <raducanu.costi@gmail.com>
---
 lib/vfscore/Makefile.uk   | 3 ++-
 lib/vfscore/exportsyms.uk | 2 ++
 lib/vfscore/main.c        | 2 +-
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/vfscore/Makefile.uk b/lib/vfscore/Makefile.uk
index 69f612f..4e44400 100644
--- a/lib/vfscore/Makefile.uk
+++ b/lib/vfscore/Makefile.uk
@@ -62,4 +62,5 @@ UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += mkdir-2
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += creat-2
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += symlink-2
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += pipe-1
-UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += pipe2-2
\ No newline at end of file
+UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += pipe2-2
+UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += getcwd-2
\ No newline at end of file
diff --git a/lib/vfscore/exportsyms.uk b/lib/vfscore/exportsyms.uk
index af1b199..dd499f9 100644
--- a/lib/vfscore/exportsyms.uk
+++ b/lib/vfscore/exportsyms.uk
@@ -75,6 +75,8 @@ unlink
 uk_syscall_e_unlink
 uk_syscall_r_unlink
 getcwd
+uk_syscall_e_getcwd
+uk_syscall_r_getcwd
 chown
 chroot
 chdir
diff --git a/lib/vfscore/main.c b/lib/vfscore/main.c
index fa43e0e..742e05c 100644
--- a/lib/vfscore/main.c
+++ b/lib/vfscore/main.c
@@ -1351,7 +1351,7 @@ UK_TRACEPOINT(trace_vfs_getcwd, "%p %d", char*, size_t);
 UK_TRACEPOINT(trace_vfs_getcwd_ret, "\"%s\"", const char*);
 UK_TRACEPOINT(trace_vfs_getcwd_err, "%d", int);
 
-char *getcwd(char *path, size_t size)
+UK_SYSCALL_DEFINE(char*, getcwd, char*, path, size_t, size)
 {
 	trace_vfs_getcwd(path, size);
 	struct task *t = main_task;
-- 
2.17.1



From minios-devel-bounces@lists.xenproject.org Fri Jul 17 14:19:25 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 17 Jul 2020 14:19:25 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jwRCu-0006Ih-4N; Fri, 17 Jul 2020 14:19:24 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <SRS0=437+=A4=gmail.com=razvand@srs-us1.protection.inumbo.net>)
 id 1jwRCt-0006Ic-0x
 for minios-devel@lists.xen.org; Fri, 17 Jul 2020 14:19:23 +0000
X-Inumbo-ID: 81da6d3a-c838-11ea-bca7-bc764e2007e4
Received: from mail-wm1-x342.google.com (unknown [2a00:1450:4864:20::342])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 81da6d3a-c838-11ea-bca7-bc764e2007e4;
 Fri, 17 Jul 2020 14:19:21 +0000 (UTC)
Received: by mail-wm1-x342.google.com with SMTP id g75so15053234wme.5
 for <minios-devel@lists.xen.org>; Fri, 17 Jul 2020 07:19:21 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=sender:from:to:cc:subject:references:date:in-reply-to:message-id
 :user-agent:mime-version;
 bh=5PT6eVJZ2Akc8DiY4Zt/WdsMkAIol1I8sdng9rZjw0E=;
 b=EIk9eHgp29yjlFP5e0QN43Q0eUiKMlMBSo4Q5OnoJVh0fNQyhR645thQemTDERnXVu
 BiCnrAUa1HVvBuNg7bt5w2ZnudTQ9i/KF8wziFaxc8moL+HxWDNgDBpB3zvcNwggk/so
 WXDVuAeA3tRSVElEgEK+qbXxXhmQpWH4AMvT83Qhv9TSIF9SdasVSWdiU5Sld5w9tHOA
 n8E5MBLjkxYVTmdjifjuZzgEO+r0xVnMTGywZYYpikO3V4n20cZE8uAGr66FiAIWNKFQ
 KM7NmlTHmjCrr7j9ACv7T3VmN7EZLaeCUJQZaxcR78JIJy0qSxQSx8jcTyTvLF43QdEL
 WM2g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:sender:from:to:cc:subject:references:date
 :in-reply-to:message-id:user-agent:mime-version;
 bh=5PT6eVJZ2Akc8DiY4Zt/WdsMkAIol1I8sdng9rZjw0E=;
 b=oN6RIF9ZB+ofe/BMTwVI3ntTVP34uAkx5FBnWQfok68JbP163JRN11bnN2bTPOz72J
 e7/FejfiJm853qgQ0qu4XaJS0lb7DuPM6zkDJqAnvyjs9Lz73dGSLb5ERdHINbnKAzwX
 JE18UF0vJtHvI+Ea+sandW98EN/+PDC1hLRtM35dNOeBkWJK18N+zDFWeXLkbE7sw9cV
 Anmymm6XybedbcCKpqARW9YItujg5Nzjg3ZlYELAJMafdTNnyktUHGsr1LAwheVufEFp
 pUQIrm/4zkl0qqeTsI1yAmKV8+LrIf1Sv6v7wJTAklns+nj0rBROe7nsC6xsHOzX8Lmi
 FECA==
X-Gm-Message-State: AOAM5334mVMp7BK3Ji1AxOws/ebY2IarHSxKji947wwhqzO7OOwLEfol
 fZoEmHrgKjVAtgPeitz6Ftg=
X-Google-Smtp-Source: ABdhPJx928TVi8rO4etycC/6wcf2VIoovI64JdPPp8o3PdQx3pGjkNkt84HvpR+Ul1bXtBDfXn7lGQ==
X-Received: by 2002:a1c:e285:: with SMTP id z127mr9549242wmg.162.1594995560411; 
 Fri, 17 Jul 2020 07:19:20 -0700 (PDT)
Received: from localhost ([141.85.233.147])
 by smtp.gmail.com with ESMTPSA id i67sm14228806wma.12.2020.07.17.07.19.16
 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256);
 Fri, 17 Jul 2020 07:19:16 -0700 (PDT)
From: Razvan Deaconescu <razvan.deaconescu@cs.pub.ro>
To: Felipe Huici <felipe.huici@neclab.eu>
Subject: Re: [UNIKRAFT/LIBICU PATCH 0/2] Introducing libicu port to Unikraft
References: <20200416195724.18620-1-felipe.huici@neclab.eu>
 <86d04uo7hr.fsf@drone.cs.pub.ro>
Date: Fri, 17 Jul 2020 17:19:15 +0300
In-Reply-To: <86d04uo7hr.fsf@drone.cs.pub.ro> (Razvan Deaconescu's message of
 "Fri, 17 Jul 2020 11:45:04 +0300")
Message-ID: <867dv2kyvw.fsf@drone.cs.pub.ro>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: minios-devel@lists.xen.org
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Razvan Deaconescu <razvan.deaconescu@cs.pub.ro> writes:
> Hi, Felipe.
>
> I built the libicu library, everything is OK.
>
> But the header files are not included in the Makefile commands that
> build the application. I used the libicu API in the main.c (application
> source code file) and it fails to find header files.
>
> The header files are included in the Makefile commands to build the
> library files:
> ---
> ... -I/home/razvan/projects/unicore/unikraft/apps/app-helloworld.git/build/libicu/origin/source/common
> -I/home/razvan/projects/unicore/unikraft/apps/app-helloworld.git/build/libicu/origin/source/i18n
> ...
> ---
>
> The Makefile.uk file looks OK to me. Do you know what the problem might be?

Simon highlighted the issue in Makefile.uk. It uses CONFIG_ICU instead
of CONFIG_LIBICU. Once this is fixed, everything works OK. Like this:

----
CINCLUDES-$(CONFIG_LIBICU)   += -I$(LIBICU_SRC)/common  
CINCLUDES-$(CONFIG_LIBICU)   += -I$(LIBICU_SRC)/i18n            
CXXINCLUDES-$(CONFIG_LIBICU) += -I$(LIBICU_SRC)/common      
CXXINCLUDES-$(CONFIG_LIBICU) += -I$(LIBICU_SRC)/i18n
---

Razvan

> Felipe Huici <felipe.huici@neclab.eu> writes:
>> This is our initial port of the International Components for Unicode library to Unikraft.
>>
>> Felipe Huici (2):
>>   Introduce icu to Unikraft.
>>   Add documentation
>>
>>  .gitignore      |  27 +++
>>  CODING_STYLE.md |   4 +
>>  CONTRIBUTING.md |   4 +
>>  COPYING.md      |  30 ++++
>>  Config.uk       |  14 ++
>>  MAINTAINERS.md  |  10 ++
>>  Makefile.uk     | 466 ++++++++++++++++++++++++++++++++++++++++++++++++
>>  README.md       |  10 ++
>>  8 files changed, 565 insertions(+)
>>  create mode 100644 .gitignore
>>  create mode 100644 CODING_STYLE.md
>>  create mode 100644 CONTRIBUTING.md
>>  create mode 100644 COPYING.md
>>  create mode 100644 Config.uk
>>  create mode 100644 MAINTAINERS.md
>>  create mode 100644 Makefile.uk
>>  create mode 100644 README.md


From minios-devel-bounces@lists.xenproject.org Fri Jul 17 14:51:28 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 17 Jul 2020 14:51:28 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jwRhv-0001hN-Qh; Fri, 17 Jul 2020 14:51:27 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <SRS0=437+=A4=gmail.com=razvand@srs-us1.protection.inumbo.net>)
 id 1jwRhu-0001hI-Me
 for minios-devel@lists.xen.org; Fri, 17 Jul 2020 14:51:26 +0000
X-Inumbo-ID: fc2a65c8-c83c-11ea-bb8b-bc764e2007e4
Received: from mail-wr1-x443.google.com (unknown [2a00:1450:4864:20::443])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id fc2a65c8-c83c-11ea-bb8b-bc764e2007e4;
 Fri, 17 Jul 2020 14:51:24 +0000 (UTC)
Received: by mail-wr1-x443.google.com with SMTP id r12so11370732wrj.13
 for <minios-devel@lists.xen.org>; Fri, 17 Jul 2020 07:51:24 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=sender:from:to:cc:subject:references:date:in-reply-to:message-id
 :user-agent:mime-version:content-transfer-encoding;
 bh=SuVlvhbVvUrK9JOQL3jXrX2kzMv4+ZZlGnQB7gAAC8k=;
 b=mGm6p7W5PCRnYHZS75NNeOwBj0S5+d2sCbKl30+IAWJ0A9FOxI/zWD2A2ZDhmReoO3
 QBmOU46B328bzTA6aLpI9QmOlgFfQEa12efcA9azwqh3sRjtulmhgbJn/HXtESK14pyO
 Ej+ghyruYvp3mKdGslcuxA8/k0KFjddXH3ja2adapAKf3OArlZdwOgQcD2HBNhjc79W1
 llgHgNrerYUfRkmvNsgr2mVzqDyFF84PAmRhzUmn4NLMbCzSjfGaXBTTgnfbjCX8d7Xq
 ZpfsOdk2s440nDefkz9XatzFOf/hsn3jVF9dgNGrjNFdUr/eBxYkpdzDwJWQ2Dl8fcjp
 ftyg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:sender:from:to:cc:subject:references:date
 :in-reply-to:message-id:user-agent:mime-version
 :content-transfer-encoding;
 bh=SuVlvhbVvUrK9JOQL3jXrX2kzMv4+ZZlGnQB7gAAC8k=;
 b=ZaTiMI4+6y/zXU0dan1QSIL/yBrjr33SUA+dwxJp3q2i5RU/JPcPecdGc5ML/h2tUk
 qUIZBvPJNF1EgHNZJe4MxVVecl69ca9hdOZr6YIQI40AH7IWTaWTGgpSjAD2ltMpujCl
 msqDUtTXOJwLIVfu5xzMKOsEVZhlmuyM3Gf8WuwyXwlVX1Rn12Ju1PhA0EmW9diZo4xc
 znlSki1GtSvVfo2NlZj0nxrIyBEj1EVOYJNl5mnpRBEteCM6qxBi6x40Mf3uiMOuINK/
 XGCHQe6ETo7Yv3UZidMKUn5Bfkh0PUau+N8Ds1B6awBI8wRyZW6zEd0p2+g/8fXYrLU0
 oyFg==
X-Gm-Message-State: AOAM532AYN+ajisl24GEZMg2D1HrIdu4x1YHnQSHo9bRncMZ5a7vj+wp
 V7LbjBQz6ua3f9JOLx8ugW4=
X-Google-Smtp-Source: ABdhPJysWSvcFw4KwPRREW9E1JxXXaPIzBKiJ2RDGNhW0ZZCxpTunv3qLolC8gMessvNd1/td2gLTw==
X-Received: by 2002:adf:dcd0:: with SMTP id x16mr10250917wrm.387.1594997483698; 
 Fri, 17 Jul 2020 07:51:23 -0700 (PDT)
Received: from localhost ([141.85.233.147])
 by smtp.gmail.com with ESMTPSA id g3sm16762845wrb.59.2020.07.17.07.51.21
 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256);
 Fri, 17 Jul 2020 07:51:21 -0700 (PDT)
From: Razvan Deaconescu <razvan.deaconescu@cs.pub.ro>
To: Alice Suiu <alicesuiu17@gmail.com>
Subject: Re: [Minios-devel] [UNIKRAFT/NEWLIB PATCH] include/endian.h Define
 the __bswap16, __bswap32,
 __bswap64 builtin functions only if the compilation is done with gcc
References: <20200301191336.24672-1-alicesuiu17@gmail.com>
 <20200301191336.24672-2-alicesuiu17@gmail.com>
 <ca5ecb2f-8f76-9bf0-aac9-72bfa5bb2438@neclab.eu>
 <CAD2TrnC7Z9_bKk5gFx2U=PmyTJyaxfCsVSPY_AG+RsLLAGfLCg@mail.gmail.com>
 <86lfjioazb.fsf@drone.cs.pub.ro>
Date: Fri, 17 Jul 2020 17:51:21 +0300
In-Reply-To: <86lfjioazb.fsf@drone.cs.pub.ro> (Razvan Deaconescu's message of
 "Fri, 17 Jul 2020 10:29:44 +0300")
Message-ID: <864kq6jity.fsf@drone.cs.pub.ro>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: felipe.huici@neclab.eu, florian.schmidt@neclab.eu,
 Simon Kuenzer <simon.kuenzer@neclab.eu>, minios-devel@lists.xen.org,
 costin.lupu@cs.pub.ro
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Razvan Deaconescu <razvan.deaconescu@cs.pub.ro> writes:
> Alice Suiu <alicesuiu17@gmail.com> writes:
>> =C3=8En joi, 2 apr. 2020 la 19:56, Simon Kuenzer <simon.kuenzer@neclab.e=
u> a scris:
>>> Hi Alice,
>>>
>>> I have a question to this patch:
>>>
>>> On 01.03.20 20:13, alicesuiu wrote:
>>> > Signed-off-by: Alice Suiu <alicesuiu17@gmail.com>
>>> > ---
>>> >   include/endian.h | 2 ++
>>> >   1 file changed, 2 insertions(+)
>>> >
>>> > diff --git a/include/endian.h b/include/endian.h
>>> > index 3c8a752..63d3650 100644
>>> > --- a/include/endian.h
>>> > +++ b/include/endian.h
>>> > @@ -41,6 +41,7 @@
>>> >
>>> >   #include <stdint.h>
>>> >
>>> > +#ifndef __clang__
>>> >   static inline uint16_t __bswap16(uint16_t __x)
>>> >   {
>>> >       return __x<<8 | __x>>8;
>>> > @@ -55,6 +56,7 @@ static inline uint64_t __bswap64(uint64_t __x)
>>> >   {
>>> >       return (__bswap32(__x)+0ULL)<<32 | __bswap32(__x>>32);
>>> >   }
>>> > +#endif
>>>
>>> Doesn't GCC has a builtin for this and does clang has one, too? We also
>>> need to make sure that clang is not introducing libc replacements as
>>> default. On GCC that broke the printing with nolibc...
>>
>> Hi Simon,
>>
>> Yes, GCC doesn't have these builtin functions, but clang has them. When I
>> use nolibc + clang, I don't receive errors. But when I use newlib [1] +
>> clang [2], I receive errors because both have these builtin functions.
>
> Both GCC and Clang have define the `__builtin_bswapXY()` builtins. The
> actual issue is a different behavior between the two compilers: the
> simultaneous definition of a macro `__bswapXY` and a function
> `__bswapXY`; GCC doesn't complain, but Clang does. See the sample
> here[3].
>
> This is happening in Unikraft because the Unikraft core libraries are
> using a minimized Unikraft newlib library[4], while the Unikraft app is
> using the upstream (complete) newlib library[5]. In the end there are
> two `endian.h` files: one in the Unikraft newlib[6], another one in the
> upstream newlib (<repo>/newlib/libc/include/machine/endian.h). The
> Unikraft newlib version of `endian.h` defines `__bswapXY` as inline
> functions, whereas the upstream newlib defines them as macros. This
> results in an error from Clang; GCC doesn't mind, though it's an issue
> having multiple definitions for the same thing (even if one is a macro
> or one is a function).
>
> Ideally you wouldn't have multiple headers with the same content. But
> given the way Unikraft is created (with the core libraries not requiring
> the upstream newlib version, only the minimal Unikraft newlib) we need
> both of them.
>
> The proper way to fix this is to make the two compatible: update the
> Unikraft newlib `endian.h` definitions using the ones from the upstream
> newlib, as in the patch below[7]. This works for GCC and Clang.
>
> Simon, does this patch look OK to you? If yes, I will send it to the
> mailing list and we can reject the current one.

There's a cleaner solution, as we discussed, today: removing the
__bswapXY() parts and including the upstream version of endian.h, as in
the patch below.

There's also the option of removing the endian.h file altogether and
updating the calling functions. I looked into Unikraft core libs, newlib
and lwip, and removing it works; but I don't know about other libraries
that may be using the endian.h file. To be on the safe side, I favor the
patch below.

-----
diff --git a/include/endian.h b/include/endian.h
index 3c8a752..f09c312 100644
--- a/include/endian.h
+++ b/include/endian.h
@@ -27,6 +27,8 @@
 #ifndef _ENDIAN_H
 #define _ENDIAN_H
=20
+#include <machine/endian.h>
+
 #define __LITTLE_ENDIAN 1234
 #define __BIG_ENDIAN 4321
 #define __PDP_ENDIAN 3412
@@ -41,21 +43,6 @@
=20
 #include <stdint.h>
=20
-static inline uint16_t __bswap16(uint16_t __x)
-{
-       return __x<<8 | __x>>8;
-}
-
-static inline uint32_t __bswap32(uint32_t __x)
-{
-       return __x>>24 | (__x>>8&0xff00) | (__x<<8&0xff0000) | __x<<24;
-}
-
-static inline uint64_t __bswap64(uint64_t __x)
-{
-       return (__bswap32(__x)+0ULL)<<32 | __bswap32(__x>>32);
-}
-
 #if __BYTE_ORDER =3D=3D __LITTLE_ENDIAN
 #define htobe16(x) __bswap16(x)
 #define be16toh(x) __bswap16(x)
-----

Razvan


From minios-devel-bounces@lists.xenproject.org Fri Jul 17 16:42:15 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 17 Jul 2020 16:42:15 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jwTR7-0004VP-Jf; Fri, 17 Jul 2020 16:42:13 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=si1d=A4=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jwTR5-0004VJ-TF
 for minios-devel@lists.xen.org; Fri, 17 Jul 2020 16:42:11 +0000
X-Inumbo-ID: 74c856c0-c84c-11ea-bca7-bc764e2007e4
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 74c856c0-c84c-11ea-bca7-bc764e2007e4;
 Fri, 17 Jul 2020 16:42:10 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id BC1F410411A;
 Fri, 17 Jul 2020 18:42:08 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id hFbB3yBV43p0; Fri, 17 Jul 2020 18:42:08 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id 992D21040D5
 for <minios-devel@lists.xen.org>; Fri, 17 Jul 2020 18:42:08 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Fri, 17 Jul
 2020 18:42:08 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 0/3] Poll based receive based on uk_netdev features
Date: Fri, 17 Jul 2020 18:41:55 +0200
Message-ID: <1595004118-27074-1-git-send-email-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.7.4
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

uk_netdev_info provides a way to forward driver information to the network stack.
We extend the uk_netdev_info with the features field that allows the network stack
to perform a poll based received on those driver that do not support interrupt based
receive. The patch series is structured as follows:
- The uk_netdev structure allocates network stack scratch pad.
- The uk_netdev_info provides features field to fetch information on the feature supported
  on a driver.

Changes since v2:
- Enable secondary expansion on the build system
- Decouple from the tap driver
- Add some more comments 

Change since v1:
- Select the max of the scratch size
- Rename from enabled to available for the features

Sharan Santhanam (3):
  build: Enable secondary expansion
  lib/uknetdev: Save nw_stack data in a netdevice
  lib/uknetdev: Get feature supported on uk_netdev

 Makefile                              |  3 +++
 lib/uknetdev/Makefile.rules           | 17 ++++++++++++++
 lib/uknetdev/include/uk/netdev_core.h | 19 +++++++++++++++
 plat/drivers/virtio/virtio_net.c      |  1 +
 support/build/Makefile.rules          | 44 +++++++++++++++++------------------
 5 files changed, 62 insertions(+), 22 deletions(-)
 create mode 100644 lib/uknetdev/Makefile.rules

-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Fri Jul 17 16:42:17 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 17 Jul 2020 16:42:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jwTRB-0004Vn-LD; Fri, 17 Jul 2020 16:42:17 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=si1d=A4=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jwTRA-0004VJ-LS
 for minios-devel@lists.xen.org; Fri, 17 Jul 2020 16:42:16 +0000
X-Inumbo-ID: 767a5644-c84c-11ea-8496-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 767a5644-c84c-11ea-8496-bc764e2007e4;
 Fri, 17 Jul 2020 16:42:12 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 9B670F200C;
 Fri, 17 Jul 2020 18:42:11 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id c4FYMs6bMM6O; Fri, 17 Jul 2020 18:42:11 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 66858F2002
 for <minios-devel@lists.xen.org>; Fri, 17 Jul 2020 18:42:09 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Fri, 17 Jul
 2020 18:42:08 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 1/3] build: Enable secondary expansion
Date: Fri, 17 Jul 2020 18:41:56 +0200
Message-ID: <1595004118-27074-2-git-send-email-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <1595004118-27074-1-git-send-email-sharan.santhanam@neclab.eu>
References: <1595004118-27074-1-git-send-email-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Enable second expansion of the make variables. The build variables
are expanded on execution of the Make rule.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 Makefile                     |  3 +++
 support/build/Makefile.rules | 44 ++++++++++++++++++++++----------------------
 2 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/Makefile b/Makefile
index be8fa8c..1f309b7 100644
--- a/Makefile
+++ b/Makefile
@@ -40,6 +40,9 @@ all:
 # Disable built-in rules
 .SUFFIXES:
 
+# Enable secondary expansion
+.SECONDEXPANSION:
+
 # Save running make version
 RUNNING_MAKE_VERSION := $(MAKE_VERSION)
 
diff --git a/support/build/Makefile.rules b/support/build/Makefile.rules
index 8c096fa..7acce87 100644
--- a/support/build/Makefile.rules
+++ b/support/build/Makefile.rules
@@ -392,17 +392,17 @@ endef
 define buildrule_S_ =
 $(4): $(2) | prepare
 	$(call build_cmd_fixdep,AS,$(1),$(4),\
-		$(AS)  $(COMPFLAGS) $(COMPFLAGS-y) \
+		$(AS)  $$(COMPFLAGS) $$(COMPFLAGS-y) \
 		       $($(call vprefix_lib,$(1),COMPFLAGS)) $($(call vprefix_lib,$(1),COMPFLAGS-y)) \
-		       $(ASINCLUDES) $(ASINCLUDES-y) \
+		       $$(ASINCLUDES) $$(ASINCLUDES-y) \
 		       $($(call vprefix_lib,$(1),ASINCLUDES)) $($(call vprefix_lib,$(1),ASINCLUDES-y)) \
 		       $($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
 		       $($(call vprefix_glb,$(3),ARCHFLAGS)) $($(call vprefix_glb,$(3),ARCHFLAGS-y)) \
-		       $(ASFLAGS) $(ASFLAGS-y) \
+		       $$(ASFLAGS) $$(ASFLAGS-y) \
 		       $($(call vprefix_lib,$(1),ASFLAGS)) $($(call vprefix_lib,$(1),ASFLAGS-y)) \
 		       $($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
 		       $(5) \
-		       $(DBGFLAGS) $(DBGFLAGS-y) \
+		       $$(DBGFLAGS) $$(DBGFLAGS-y) \
 		       -D__LIBNAME__=$(1) -D__BASENAME__=$(notdir $(2)) $(if $(3),-D__VARIANT__=$(3)) \
 		       -c $(2) -o $(4) $(call depflags,$(4))
 	)
@@ -419,17 +419,17 @@ buildrule_sx = $(call buildrule_S_,$(1),$(2),$(3),$(4))
 define buildrule_s =
 $(4): $(2) | prepare
 	$(call build_cmd,AS,$(1),$(4),\
-		$(AS)  $(COMPFLAGS) $(COMPFLAGS-y) \
+		$(AS)  $$(COMPFLAGS) $$(COMPFLAGS-y) \
 		       $($(call vprefix_lib,$(1),COMPFLAGS)) $($(call vprefix_lib,$(1),COMPFLAGS-y)) \
-		       $(ASINCLUDES) $(ASINCLUDES-y) \
+		       $$(ASINCLUDES) $$(ASINCLUDES-y) \
 		       $($(call vprefix_lib,$(1),ASINCLUDES)) $($(call vprefix_lib,$(1),ASINCLUDES-y)) \
 		       $($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
 		       $($(call vprefix_glb,$(3),ARCHFLAGS)) $($(call vprefix_glb,$(3),ARCHFLAGS-y)) \
-		       $(ASFLAGS) $(ASFLAGS-y) \
+		       $$(ASFLAGS) $$(ASFLAGS-y) \
 		       $($(call vprefix_lib,$(1),ASFLAGS)) $($(call vprefix_lib,$(1),ASFLAGS-y)) \
 		       $($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
 		       $(5) \
-		       $(DBGFLAGS) $(DBGFLAGS-y) \
+		       $$(DBGFLAGS) $$(DBGFLAGS-y) \
 		       -D__LIBNAME__=$(1) -D__BASENAME__=$(notdir $(2)) $(if $(3),-D__VARIANT__=$(3)) \
 		       -c $(2) -o $(4)
 	)
@@ -444,17 +444,17 @@ endef
 define buildrule_c =
 $(4): $(2) | prepare
 	$(call build_cmd_fixdep,CC,$(1),$(4),\
-		$(CC)  $(COMPFLAGS) $(COMPFLAGS-y) \
+		$(CC)  $$(COMPFLAGS) $$(COMPFLAGS-y) \
 		       $($(call vprefix_lib,$(1),COMPFLAGS)) $($(call vprefix_lib,$(1),COMPFLAGS-y)) \
-		       $(CINCLUDES) $(CINCLUDES-y) \
+		       $$(CINCLUDES) $$(CINCLUDES-y) \
 		       $($(call vprefix_lib,$(1),CINCLUDES)) $($(call vprefix_lib,$(1),CINCLUDES-y)) \
 		       $($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
 		       $($(call vprefix_glb,$(3),ARCHFLAGS)) $($(call vprefix_glb,$(3),ARCHFLAGS-y)) \
-		       $(CFLAGS) $(CFLAGS-y) \
+		       $$(CFLAGS) $$(CFLAGS-y) \
 		       $($(call vprefix_lib,$(1),CFLAGS)) $($(call vprefix_lib,$(1),CFLAGS-y)) \
 		       $($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
 		       $(5) \
-		       $(DBGFLAGS) $(DBGFLAGS-y) \
+		       $$(DBGFLAGS) $$(DBGFLAGS-y) \
 		       -D__LIBNAME__=$(1) -D__BASENAME__=$(notdir $(2)) $(if $(3),-D__VARIANT__=$(3)) \
 		       -c $(2) -o $(4) $(call depflags,$(4))
 )
@@ -469,16 +469,16 @@ endef
 define buildrule_cxx =
 $(4): $(2) | prepare
 	$(call build_cmd_fixdep,CXX,$(1),$(4),\
-		$(CXX) $(COMPFLAGS) $(COMPFLAGS-y) \
+		$(CXX) $$(COMPFLAGS) $$(COMPFLAGS-y) \
 		       $(CXXINCLUDES) $(CXXINCLUDES-y) \
 		       $($(call vprefix_lib,$(1),CXXINCLUDES)) $($(call vprefix_lib,$(1),CXXINCLUDES-y)) \
 		       $($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
 		       $($(call vprefix_glb,$(3),ARCHFLAGS)) $($(call vprefix_glb,$(3),ARCHFLAGS-y)) \
-		       $(CXXFLAGS) $(CXXFLAGS-y) \
+		       $$(CXXFLAGS) $$(CXXFLAGS-y) \
 		       $($(call vprefix_lib,$(1),CXXFLAGS)) $($(call vprefix_lib,$(1),CXXFLAGS-y)) \
 		       $($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
 		       $(5) \
-		       $(DBGFLAGS) $(DBGFLAGS-y) \
+		       $$(DBGFLAGS) $$(DBGFLAGS-y) \
 		       -D__LIBNAME__=$(1) -D__BASENAME__=$(notdir $(2)) $(if $(3),-D__VARIANT__=$(3)) \
 		       -c $(2) -o $(4) $(call depflags,$(4))
 	)
@@ -501,16 +501,16 @@ buildrule_c$(plus)$(plus) = $(call buildrule_cxx,$(1),$(2),$(3),$(4))
 define buildrule_go =
 $(4): $(2) | prepare
 	$(call build_cmd,GOC,$(1),$(4),\
-		$(GOC) $(COMPFLAGS) $(COMPFLAGS-y) \
-		       $(GOCINCLUDES) $(GOCINCLUDES-y) \
+		$(GOC) $$(COMPFLAGS) $$(COMPFLAGS-y) \
+		       $$(GOCINCLUDES) $$(GOCINCLUDES-y) \
 		       $($(call vprefix_lib,$(1),GOCINCLUDES)) $($(call vprefix_lib,$(1),GOCINCLUDES-y)) \
 		       $($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
 		       $($(call vprefix_glb,$(3),ARCHFLAGS)) $($(call vprefix_glb,$(3),ARCHFLAGS-y)) \
-		       $(GOCFLAGS) $(GOCFLAGS-y) \
+		       $$(GOCFLAGS) $$(GOCFLAGS-y) \
 		       $($(call vprefix_lib,$(1),GOCFLAGS)) $($(call vprefix_lib,$(1),GOCFLAGS-y)) \
 		       $($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
 		       $(5) \
-		       $(DBGFLAGS) $(DBGFLAGS-y) \
+		       $$(DBGFLAGS) $$(DBGFLAGS-y) \
 		       -D__LIBNAME__=$(1) -D__BASENAME__=$(notdir $(2)) $(if $(3),-D__VARIANT__=$(3)) \
 		       -c $(2) -o $(4) $(call depflags,$(4))
 	)
@@ -534,11 +534,11 @@ define buildrule_S_lds =
 $(4): $(2) | prepare
 	$(call build_cmd_fixdep,LDS,$(1),$(4),\
 		$(AS)  -E -P -x assembler-with-cpp $(COMPFLAGS) $(COMPFLAGS-y) \
-		       $(ASINCLUDES) $(ASINCLUDES-y) \
+		       $$(ASINCLUDES) $$(ASINCLUDES-y) \
 		       $($(call vprefix_lib,$(1),ASINCLUDES)) $($(call vprefix_lib,$(1),ASINCLUDES-y)) \
 		       $($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
-		       $(ARCHFLAGS) $(ARCHFLAGS-y) \
-		       $(ASFLAGS) $(ASFLAGS-y) \
+		       $$(ARCHFLAGS) $$(ARCHFLAGS-y) \
+		       $$(ASFLAGS) $$(ASFLAGS-y) \
 		       $($(call vprefix_lib,$(1),ASFLAGS)) $($(call vprefix_lib,$(1),ASFLAGS-y)) \
 		       $($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
 		       $(5) \
-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Fri Jul 17 16:42:19 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 17 Jul 2020 16:42:19 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jwTRD-0004WK-Mg; Fri, 17 Jul 2020 16:42:19 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=si1d=A4=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jwTRC-0004W6-F1
 for minios-devel@lists.xen.org; Fri, 17 Jul 2020 16:42:18 +0000
X-Inumbo-ID: 78c29f89-c84c-11ea-963f-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 78c29f89-c84c-11ea-963f-12813bfff9fa;
 Fri, 17 Jul 2020 16:42:16 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id AC860F200C;
 Fri, 17 Jul 2020 18:42:15 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id qIyZnrjc1q-W; Fri, 17 Jul 2020 18:42:15 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 7F957F2002
 for <minios-devel@lists.xen.org>; Fri, 17 Jul 2020 18:42:13 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Fri, 17 Jul
 2020 18:42:09 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 3/3] lib/uknetdev: Get feature supported on
 uk_netdev
Date: Fri, 17 Jul 2020 18:41:58 +0200
Message-ID: <1595004118-27074-4-git-send-email-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <1595004118-27074-1-git-send-email-sharan.santhanam@neclab.eu>
References: <1595004118-27074-1-git-send-email-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The uk_netdev_info provides a way to forward information on netdevice
to the network stack. We extend this with a bitmap of the features
supported on device. The bit 0,1 of the bitmap indicates if the
device supports interrupt.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 lib/uknetdev/include/uk/netdev_core.h | 12 ++++++++++++
 plat/drivers/virtio/virtio_net.c      |  1 +
 2 files changed, 13 insertions(+)

diff --git a/lib/uknetdev/include/uk/netdev_core.h b/lib/uknetdev/include/uk/netdev_core.h
index e9d9113..c170696 100644
--- a/lib/uknetdev/include/uk/netdev_core.h
+++ b/lib/uknetdev/include/uk/netdev_core.h
@@ -77,6 +77,17 @@ UK_TAILQ_HEAD(uk_netdev_list, struct uk_netdev);
  */
 #define UK_NETDEV_HWADDR_LEN 6 /**< Length of Ethernet address. */
 
+/**
+ * The netdevice support rx/tx interrupt.
+ */
+#define UK_FEATURE_RXQ_INTR_BIT		    0
+#define UK_FEATURE_RXQ_INTR_AVAILABLE  (1UL << UK_FEATURE_RXQ_INTR_BIT)
+#define UK_FEATURE_TXQ_INTR_BIT		    1
+#define UK_FEATURE_TXQ_INTR_AVAILABLE  (1UL << UK_FEATURE_TXQ_INTR_BIT)
+
+#define uk_netdev_rxintr_supported(feature)	\
+	(feature & (UK_FEATURE_RXQ_INTR_AVAILABLE))
+
 struct uk_hwaddr {
 	uint8_t addr_bytes[UK_NETDEV_HWADDR_LEN];
 } __packed;
@@ -91,6 +102,7 @@ struct uk_netdev_info {
 	uint16_t max_mtu;   /**< Maximum supported MTU size. */
 	uint16_t nb_encap_tx;  /**< Number of bytes required as headroom for tx. */
 	uint16_t nb_encap_rx;  /**< Number of bytes required as headroom for rx. */
+	uint32_t features; /**< bitmap of the features supported */
 };
 
 /**
diff --git a/plat/drivers/virtio/virtio_net.c b/plat/drivers/virtio/virtio_net.c
index 3025ed3..0a8312d 100644
--- a/plat/drivers/virtio/virtio_net.c
+++ b/plat/drivers/virtio/virtio_net.c
@@ -1052,6 +1052,7 @@ static void virtio_net_info_get(struct uk_netdev *dev,
 	dev_info->max_tx_queues = vndev->max_vqueue_pairs;
 	dev_info->nb_encap_tx = sizeof(struct virtio_net_hdr_padded);
 	dev_info->nb_encap_rx = sizeof(struct virtio_net_hdr_padded);
+	dev_info->features = UK_FEATURE_RXQ_INTR_AVAILABLE;
 }
 
 static int virtio_net_start(struct uk_netdev *n)
-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Fri Jul 17 16:42:22 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 17 Jul 2020 16:42:22 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jwTRG-0004X8-OH; Fri, 17 Jul 2020 16:42:22 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=si1d=A4=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jwTRF-0004VJ-Ll
 for minios-devel@lists.xen.org; Fri, 17 Jul 2020 16:42:21 +0000
X-Inumbo-ID: 77ab5982-c84c-11ea-8496-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 77ab5982-c84c-11ea-8496-bc764e2007e4;
 Fri, 17 Jul 2020 16:42:14 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 9B108F200E;
 Fri, 17 Jul 2020 18:42:13 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id seM_60BxTuMt; Fri, 17 Jul 2020 18:42:13 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 6FC89F2002
 for <minios-devel@lists.xen.org>; Fri, 17 Jul 2020 18:42:11 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Fri, 17 Jul
 2020 18:42:09 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 2/3] lib/uknetdev: Save nw_stack data in a
 netdevice
Date: Fri, 17 Jul 2020 18:41:57 +0200
Message-ID: <1595004118-27074-3-git-send-email-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <1595004118-27074-1-git-send-email-sharan.santhanam@neclab.eu>
References: <1595004118-27074-1-git-send-email-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

We extend the uk_netdev to store network stack specific data into
uk_netdev. The size of the of this data is passed to network stack
by setting the CONFIG_UK_NETDEV_SCRATCH_SIZE.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Reviewed-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
---
 lib/uknetdev/Makefile.rules           | 17 +++++++++++++++++
 lib/uknetdev/include/uk/netdev_core.h |  7 +++++++
 2 files changed, 24 insertions(+)
 create mode 100644 lib/uknetdev/Makefile.rules

diff --git a/lib/uknetdev/Makefile.rules b/lib/uknetdev/Makefile.rules
new file mode 100644
index 0000000..80997e5
--- /dev/null
+++ b/lib/uknetdev/Makefile.rules
@@ -0,0 +1,17 @@
+UK_SCRATCH_MEM=0
+UK_SCRATCH_RULE_SET=
+
+uk_scratch_mem_set: $$(eval CFLAGS-y+=-DCONFIG_UK_NETDEV_SCRATCH_SIZE=$$(UK_SCRATCH_MEM))
+	@:;
+
+.PHONY : uk_scratch_mem_set
+
+
+## reserve memory for the network stack
+## uknetdev_scratch_mem,bytes_of_memory
+define uknetdev_scratch_mem =
+$(if $(strip $(1)),\
+	$(if $(shell test $(1) -gt $(UK_SCRATCH_MEM) && echo "scratch mem set"), $(eval UK_SCRATCH_MEM:=$(1))))
+
+$(if $(strip $(UK_SCRATCH_RULE_SET)),,$(eval UK_SCRATCH_RULE_SET:=1) $(eval UK_PREPARE-$(CONFIG_LIBUKNETDEV)+=uk_scratch_mem_set))
+endef
diff --git a/lib/uknetdev/include/uk/netdev_core.h b/lib/uknetdev/include/uk/netdev_core.h
index d2e8da0..e9d9113 100644
--- a/lib/uknetdev/include/uk/netdev_core.h
+++ b/lib/uknetdev/include/uk/netdev_core.h
@@ -65,6 +65,10 @@
 extern "C" {
 #endif
 
+#ifndef CONFIG_UK_NETDEV_SCRATCH_SIZE
+#define CONFIG_UK_NETDEV_SCRATCH_SIZE 0
+#endif /* CONFIG_UK_NETDEV_SCRATCH_SIZE */
+
 struct uk_netdev;
 UK_TAILQ_HEAD(uk_netdev_list, struct uk_netdev);
 
@@ -409,6 +413,9 @@ struct uk_netdev {
 
 	/** Netdevice address configuration */
 	struct uk_netdev_config	   *_config;
+#if (CONFIG_UK_NETDEV_SCRATCH_SIZE > 0)
+	char scratch_pad[CONFIG_UK_NETDEV_SCRATCH_SIZE];
+#endif /* CONFIG_UK_NETDEV_SCRATCH_SIZE */
 };
 
 #ifdef __cplusplus
-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Sat Jul 18 18:18:43 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Sat, 18 Jul 2020 18:18:43 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jwrQ0-0002Ji-LE; Sat, 18 Jul 2020 18:18:40 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=+0x8=A5=ens-lyon.org=samuel.thibault@srs-us1.protection.inumbo.net>)
 id 1jwrPy-0002JP-Nt
 for minios-devel@lists.xenproject.org; Sat, 18 Jul 2020 18:18:38 +0000
X-Inumbo-ID: 155b6196-c923-11ea-b7bb-bc764e2007e4
Received: from hera.aquilenet.fr (unknown [2a0c:e300::1])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 155b6196-c923-11ea-b7bb-bc764e2007e4;
 Sat, 18 Jul 2020 18:18:31 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by hera.aquilenet.fr (Postfix) with ESMTP id 64CC32939;
 Sat, 18 Jul 2020 20:18:29 +0200 (CEST)
X-Virus-Scanned: Debian amavisd-new at aquilenet.fr
Received: from hera.aquilenet.fr ([127.0.0.1])
 by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 9Zsg89KWktZu; Sat, 18 Jul 2020 20:18:28 +0200 (CEST)
Received: from function.home (unknown
 [IPv6:2a01:cb19:956:1b00:9eb6:d0ff:fe88:c3c7])
 by hera.aquilenet.fr (Postfix) with ESMTPSA id 1F3C21A5D;
 Sat, 18 Jul 2020 20:18:28 +0200 (CEST)
Received: from samy by function.home with local (Exim 4.94)
 (envelope-from <samuel.thibault@ens-lyon.org>)
 id 1jwrPn-009BGe-23; Sat, 18 Jul 2020 20:18:27 +0200
Date: Sat, 18 Jul 2020 20:18:27 +0200
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
To: Juergen Gross <jgross@suse.com>
Subject: Re: [PATCH v2] mini-os: don't hard-wire xen internal paths
Message-ID: <20200718181827.7jrs5ilutt3jzp4i@function>
Mail-Followup-To: Samuel Thibault <samuel.thibault@ens-lyon.org>,
 Juergen Gross <jgross@suse.com>, minios-devel@lists.xenproject.org,
 xen-devel@lists.xenproject.org, wl@xen.org
References: <20200713084230.18177-1-jgross@suse.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <20200713084230.18177-1-jgross@suse.com>
Organization: I am not organized
User-Agent: NeoMutt/20170609 (1.8.3)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org,
 wl@xen.org
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Juergen Gross, le lun. 13 juil. 2020 10:42:30 +0200, a ecrit:
> Mini-OS shouldn't use Xen internal paths for building. Import the
> needed paths from Xen and fall back to the current values only if
> the import was not possible.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
> V2: correct typo (XCALL_APTH -> CALL_PATH)
> ---
>  Config.mk | 15 ++++++++++++++-
>  Makefile  | 35 ++++++++++++++++++-----------------
>  2 files changed, 32 insertions(+), 18 deletions(-)
> 
> diff --git a/Config.mk b/Config.mk
> index f6a2afa..cb823c2 100644
> --- a/Config.mk
> +++ b/Config.mk
> @@ -33,6 +33,19 @@ endif
>  #
>  ifneq ($(XEN_ROOT),)
>  MINIOS_ROOT=$(XEN_ROOT)/extras/mini-os
> +
> +-include $(XEN_ROOT)/stubdom/mini-os.mk
> +
> +XENSTORE_CPPFLAGS ?= -isystem $(XEN_ROOT)/tools/xenstore/include
> +TOOLCORE_PATH ?= $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toolcore
> +TOOLLOG_PATH ?= $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toollog
> +EVTCHN_PATH ?= $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/evtchn
> +GNTTAB_PATH ?= $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/gnttab
> +CALL_PATH ?= $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/call
> +FOREIGNMEMORY_PATH ?= $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/foreignmemory
> +DEVICEMODEL_PATH ?= $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/devicemodel
> +CTRL_PATH ?= $(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH)
> +GUEST_PATH ?= $(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH)
>  else
>  MINIOS_ROOT=$(TOPLEVEL_DIR)
>  endif
> @@ -93,7 +106,7 @@ DEF_CPPFLAGS += -D__MINIOS__
>  ifeq ($(libc),y)
>  DEF_CPPFLAGS += -DHAVE_LIBC
>  DEF_CPPFLAGS += -isystem $(MINIOS_ROOT)/include/posix
> -DEF_CPPFLAGS += -isystem $(XEN_ROOT)/tools/xenstore/include
> +DEF_CPPFLAGS += $(XENSTORE_CPPFLAGS)
>  endif
>  
>  ifneq ($(LWIPDIR),)
> diff --git a/Makefile b/Makefile
> index be640cd..4b76b55 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -125,23 +125,24 @@ OBJS := $(filter-out $(OBJ_DIR)/lwip%.o $(LWO), $(OBJS))
>  
>  ifeq ($(libc),y)
>  ifeq ($(CONFIG_XC),y)
> -APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toolcore -whole-archive -lxentoolcore -no-whole-archive
> -LIBS += $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toolcore/libxentoolcore.a
> -APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toollog -whole-archive -lxentoollog -no-whole-archive
> -LIBS += $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toollog/libxentoollog.a
> -APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/evtchn -whole-archive -lxenevtchn -no-whole-archive
> -LIBS += $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/evtchn/libxenevtchn.a
> -APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/gnttab -whole-archive -lxengnttab -no-whole-archive
> -LIBS += $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/gnttab/libxengnttab.a
> -APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/call -whole-archive -lxencall -no-whole-archive
> -LIBS += $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/call/libxencall.a
> -APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/foreignmemory -whole-archive -lxenforeignmemory -no-whole-archive
> -LIBS += $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/foreignmemory/libxenforeignmemory.a
> -APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/devicemodel -whole-archive -lxendevicemodel -no-whole-archive
> -LIBS += $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/devicemodel/libxendevicemodel.a
> -APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH) -whole-archive -lxenguest -lxenctrl -no-whole-archive
> -LIBS += $(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH)/libxenctrl.a
> -LIBS += $(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH)/libxenguest.a
> +APP_LDLIBS += -L$(TOOLCORE_PATH) -whole-archive -lxentoolcore -no-whole-archive
> +LIBS += $(TOOLCORE_PATH)/libxentoolcore.a
> +APP_LDLIBS += -L$(TOOLLOG_PATH) -whole-archive -lxentoollog -no-whole-archive
> +LIBS += $(TOOLLOG_PATH)/libxentoollog.a
> +APP_LDLIBS += -L$(EVTCHN_PATH) -whole-archive -lxenevtchn -no-whole-archive
> +LIBS += $(EVTCHN_PATH)/libxenevtchn.a
> +APP_LDLIBS += -L$(GNTTAB_PATH) -whole-archive -lxengnttab -no-whole-archive
> +LIBS += $(GNTTAB_PATH)/libxengnttab.a
> +APP_LDLIBS += -L$(CALL_PATH) -whole-archive -lxencall -no-whole-archive
> +LIBS += $(CALL_PATH)/libxencall.a
> +APP_LDLIBS += -L$(FOREIGNMEMORY_PATH) -whole-archive -lxenforeignmemory -no-whole-archive
> +LIBS += $(FOREIGNMEMORY_PATH)/libxenforeignmemory.a
> +APP_LDLIBS += -L$(DEVICEMODEL_PATH) -whole-archive -lxendevicemodel -no-whole-archive
> +LIBS += $(DEVICEMODEL_PATH)/libxendevicemodel.a
> +APP_LDLIBS += -L$(GUEST_PATH) -whole-archive -lxenguest -no-whole-archive
> +LIBS += $(GUEST_PATH)/libxenguest.a
> +APP_LDLIBS += -L$(CTRL_PATH) -whole-archive -lxenctrl -no-whole-archive
> +LIBS += $(CTRL_PATH)/libxenctrl.a
>  endif
>  APP_LDLIBS += -lpci
>  APP_LDLIBS += -lz
> -- 
> 2.26.2
> 

-- 
Samuel
 MoralitÃ© : le modem et le cablerouteur font comme les filles, ils
 papotent toute la journÃ©e.
 -+- RB in NPC : Et en plus, ils ne parlent que de bits -+-


From minios-devel-bounces@lists.xenproject.org Mon Jul 20 13:28:39 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Mon, 20 Jul 2020 13:28:39 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxVqO-0001Ld-UL; Mon, 20 Jul 2020 13:28:36 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=OzF+=A7=neclab.eu=simon.kuenzer@srs-us1.protection.inumbo.net>)
 id 1jxVqN-0001LY-TB
 for minios-devel@lists.xen.org; Mon, 20 Jul 2020 13:28:35 +0000
X-Inumbo-ID: e84024b1-ca8c-11ea-8492-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id e84024b1-ca8c-11ea-8492-bc764e2007e4;
 Mon, 20 Jul 2020 13:28:33 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 92626F200E;
 Mon, 20 Jul 2020 15:28:32 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 1BW_m4eYwItL; Mon, 20 Jul 2020 15:28:32 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 615C5F200A
 for <minios-devel@lists.xen.org>; Mon, 20 Jul 2020 15:28:30 +0200 (CEST)
Received: from [10.7.1.42] (192.168.24.96) by puck.office.hd (192.168.24.91)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Mon, 20 Jul
 2020 15:28:29 +0200
Subject: Re: [UNIKRAFT PATCH v3 1/3] build: Enable secondary expansion
To: Sharan Santhanam <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
References: <1595004118-27074-1-git-send-email-sharan.santhanam@neclab.eu>
 <1595004118-27074-2-git-send-email-sharan.santhanam@neclab.eu>
From: Simon Kuenzer <simon.kuenzer@neclab.eu>
Message-ID: <afc5d61f-75b7-3fac-ec18-9b2ad492dd9b@neclab.eu>
Date: Mon, 20 Jul 2020 15:28:28 +0200
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0)
 Gecko/20100101 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <1595004118-27074-2-git-send-email-sharan.santhanam@neclab.eu>
Content-Type: text/plain; charset="utf-8"; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hey Sharan,

thanks a lot for this update. It makes much more sense now. Please see 
my comments inline.

Thanks,

Simon

On 17.07.20 18:41, Sharan Santhanam wrote:
> Enable second expansion of the make variables. The build variables
> are expanded on execution of the Make rule.
> 
> Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
> ---
>   Makefile                     |  3 +++
>   support/build/Makefile.rules | 44 ++++++++++++++++++++++----------------------
>   2 files changed, 25 insertions(+), 22 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index be8fa8c..1f309b7 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -40,6 +40,9 @@ all:
>   # Disable built-in rules
>   .SUFFIXES:
>   
> +# Enable secondary expansion
> +.SECONDEXPANSION:
> +
>   # Save running make version
>   RUNNING_MAKE_VERSION := $(MAKE_VERSION)
>   
> diff --git a/support/build/Makefile.rules b/support/build/Makefile.rules
> index 8c096fa..7acce87 100644
> --- a/support/build/Makefile.rules
> +++ b/support/build/Makefile.rules
> @@ -392,17 +392,17 @@ endef
>   define buildrule_S_ =
>   $(4): $(2) | prepare
>   	$(call build_cmd_fixdep,AS,$(1),$(4),\
> -		$(AS)  $(COMPFLAGS) $(COMPFLAGS-y) \
> +		$(AS)  $$(COMPFLAGS) $$(COMPFLAGS-y) \
>   		       $($(call vprefix_lib,$(1),COMPFLAGS)) $($(call vprefix_lib,$(1),COMPFLAGS-y)) \

Also for the focused variables we should enable secondary expansion. 
That way we get the same behavior for _all_ libraries during the build.

> -		       $(ASINCLUDES) $(ASINCLUDES-y) \
> +		       $$(ASINCLUDES) $$(ASINCLUDES-y) \
>   		       $($(call vprefix_lib,$(1),ASINCLUDES)) $($(call vprefix_lib,$(1),ASINCLUDES-y)) \

..same here, of course... etc.

>   		       $($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
>   		       $($(call vprefix_glb,$(3),ARCHFLAGS)) $($(call vprefix_glb,$(3),ARCHFLAGS-y)) \
> -		       $(ASFLAGS) $(ASFLAGS-y) \
> +		       $$(ASFLAGS) $$(ASFLAGS-y) \
>   		       $($(call vprefix_lib,$(1),ASFLAGS)) $($(call vprefix_lib,$(1),ASFLAGS-y)) \
>   		       $($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
>   		       $(5) \
> -		       $(DBGFLAGS) $(DBGFLAGS-y) \
> +		       $$(DBGFLAGS) $$(DBGFLAGS-y) \
>   		       -D__LIBNAME__=$(1) -D__BASENAME__=$(notdir $(2)) $(if $(3),-D__VARIANT__=$(3)) \
>   		       -c $(2) -o $(4) $(call depflags,$(4))
>   	)
> @@ -419,17 +419,17 @@ buildrule_sx = $(call buildrule_S_,$(1),$(2),$(3),$(4))
>   define buildrule_s =
>   $(4): $(2) | prepare
>   	$(call build_cmd,AS,$(1),$(4),\
> -		$(AS)  $(COMPFLAGS) $(COMPFLAGS-y) \
> +		$(AS)  $$(COMPFLAGS) $$(COMPFLAGS-y) \
>   		       $($(call vprefix_lib,$(1),COMPFLAGS)) $($(call vprefix_lib,$(1),COMPFLAGS-y)) \
> -		       $(ASINCLUDES) $(ASINCLUDES-y) \
> +		       $$(ASINCLUDES) $$(ASINCLUDES-y) \
>   		       $($(call vprefix_lib,$(1),ASINCLUDES)) $($(call vprefix_lib,$(1),ASINCLUDES-y)) \
>   		       $($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
>   		       $($(call vprefix_glb,$(3),ARCHFLAGS)) $($(call vprefix_glb,$(3),ARCHFLAGS-y)) \
> -		       $(ASFLAGS) $(ASFLAGS-y) \
> +		       $$(ASFLAGS) $$(ASFLAGS-y) \
>   		       $($(call vprefix_lib,$(1),ASFLAGS)) $($(call vprefix_lib,$(1),ASFLAGS-y)) \
>   		       $($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
>   		       $(5) \
> -		       $(DBGFLAGS) $(DBGFLAGS-y) \
> +		       $$(DBGFLAGS) $$(DBGFLAGS-y) \
>   		       -D__LIBNAME__=$(1) -D__BASENAME__=$(notdir $(2)) $(if $(3),-D__VARIANT__=$(3)) \
>   		       -c $(2) -o $(4)
>   	)
> @@ -444,17 +444,17 @@ endef
>   define buildrule_c =
>   $(4): $(2) | prepare
>   	$(call build_cmd_fixdep,CC,$(1),$(4),\
> -		$(CC)  $(COMPFLAGS) $(COMPFLAGS-y) \
> +		$(CC)  $$(COMPFLAGS) $$(COMPFLAGS-y) \
>   		       $($(call vprefix_lib,$(1),COMPFLAGS)) $($(call vprefix_lib,$(1),COMPFLAGS-y)) \
> -		       $(CINCLUDES) $(CINCLUDES-y) \
> +		       $$(CINCLUDES) $$(CINCLUDES-y) \
>   		       $($(call vprefix_lib,$(1),CINCLUDES)) $($(call vprefix_lib,$(1),CINCLUDES-y)) \
>   		       $($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
>   		       $($(call vprefix_glb,$(3),ARCHFLAGS)) $($(call vprefix_glb,$(3),ARCHFLAGS-y)) \
> -		       $(CFLAGS) $(CFLAGS-y) \
> +		       $$(CFLAGS) $$(CFLAGS-y) \
>   		       $($(call vprefix_lib,$(1),CFLAGS)) $($(call vprefix_lib,$(1),CFLAGS-y)) \
>   		       $($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
>   		       $(5) \
> -		       $(DBGFLAGS) $(DBGFLAGS-y) \
> +		       $$(DBGFLAGS) $$(DBGFLAGS-y) \
>   		       -D__LIBNAME__=$(1) -D__BASENAME__=$(notdir $(2)) $(if $(3),-D__VARIANT__=$(3)) \
>   		       -c $(2) -o $(4) $(call depflags,$(4))
>   )
> @@ -469,16 +469,16 @@ endef
>   define buildrule_cxx =
>   $(4): $(2) | prepare
>   	$(call build_cmd_fixdep,CXX,$(1),$(4),\
> -		$(CXX) $(COMPFLAGS) $(COMPFLAGS-y) \
> +		$(CXX) $$(COMPFLAGS) $$(COMPFLAGS-y) \
>   		       $(CXXINCLUDES) $(CXXINCLUDES-y) \
>   		       $($(call vprefix_lib,$(1),CXXINCLUDES)) $($(call vprefix_lib,$(1),CXXINCLUDES-y)) \
>   		       $($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
>   		       $($(call vprefix_glb,$(3),ARCHFLAGS)) $($(call vprefix_glb,$(3),ARCHFLAGS-y)) \
> -		       $(CXXFLAGS) $(CXXFLAGS-y) \
> +		       $$(CXXFLAGS) $$(CXXFLAGS-y) \
>   		       $($(call vprefix_lib,$(1),CXXFLAGS)) $($(call vprefix_lib,$(1),CXXFLAGS-y)) \
>   		       $($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
>   		       $(5) \
> -		       $(DBGFLAGS) $(DBGFLAGS-y) \
> +		       $$(DBGFLAGS) $$(DBGFLAGS-y) \
>   		       -D__LIBNAME__=$(1) -D__BASENAME__=$(notdir $(2)) $(if $(3),-D__VARIANT__=$(3)) \
>   		       -c $(2) -o $(4) $(call depflags,$(4))
>   	)
> @@ -501,16 +501,16 @@ buildrule_c$(plus)$(plus) = $(call buildrule_cxx,$(1),$(2),$(3),$(4))
>   define buildrule_go =
>   $(4): $(2) | prepare
>   	$(call build_cmd,GOC,$(1),$(4),\
> -		$(GOC) $(COMPFLAGS) $(COMPFLAGS-y) \
> -		       $(GOCINCLUDES) $(GOCINCLUDES-y) \
> +		$(GOC) $$(COMPFLAGS) $$(COMPFLAGS-y) \
> +		       $$(GOCINCLUDES) $$(GOCINCLUDES-y) \
>   		       $($(call vprefix_lib,$(1),GOCINCLUDES)) $($(call vprefix_lib,$(1),GOCINCLUDES-y)) \
>   		       $($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
>   		       $($(call vprefix_glb,$(3),ARCHFLAGS)) $($(call vprefix_glb,$(3),ARCHFLAGS-y)) \
> -		       $(GOCFLAGS) $(GOCFLAGS-y) \
> +		       $$(GOCFLAGS) $$(GOCFLAGS-y) \
>   		       $($(call vprefix_lib,$(1),GOCFLAGS)) $($(call vprefix_lib,$(1),GOCFLAGS-y)) \
>   		       $($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
>   		       $(5) \
> -		       $(DBGFLAGS) $(DBGFLAGS-y) \
> +		       $$(DBGFLAGS) $$(DBGFLAGS-y) \
>   		       -D__LIBNAME__=$(1) -D__BASENAME__=$(notdir $(2)) $(if $(3),-D__VARIANT__=$(3)) \
>   		       -c $(2) -o $(4) $(call depflags,$(4))
>   	)
> @@ -534,11 +534,11 @@ define buildrule_S_lds =
>   $(4): $(2) | prepare
>   	$(call build_cmd_fixdep,LDS,$(1),$(4),\
>   		$(AS)  -E -P -x assembler-with-cpp $(COMPFLAGS) $(COMPFLAGS-y) \
> -		       $(ASINCLUDES) $(ASINCLUDES-y) \
> +		       $$(ASINCLUDES) $$(ASINCLUDES-y) \
>   		       $($(call vprefix_lib,$(1),ASINCLUDES)) $($(call vprefix_lib,$(1),ASINCLUDES-y)) \
>   		       $($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
> -		       $(ARCHFLAGS) $(ARCHFLAGS-y) \
> -		       $(ASFLAGS) $(ASFLAGS-y) \
> +		       $$(ARCHFLAGS) $$(ARCHFLAGS-y) \
> +		       $$(ASFLAGS) $$(ASFLAGS-y) \
>   		       $($(call vprefix_lib,$(1),ASFLAGS)) $($(call vprefix_lib,$(1),ASFLAGS-y)) \
>   		       $($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
>   		       $(5) \
> 


From minios-devel-bounces@lists.xenproject.org Mon Jul 20 16:40:39 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Mon, 20 Jul 2020 16:40:39 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxYqC-0002Vg-JI; Mon, 20 Jul 2020 16:40:36 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=T57I=A7=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxYqB-0002VA-J6
 for minios-devel@lists.xen.org; Mon, 20 Jul 2020 16:40:35 +0000
X-Inumbo-ID: bac597ac-caa7-11ea-9fdf-12813bfff9fa
Received: from mh-fa-1.lancs.ac.uk (unknown [148.88.65.131])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id bac597ac-caa7-11ea-9fdf-12813bfff9fa;
 Mon, 20 Jul 2020 16:40:33 +0000 (UTC)
Received: from p57b864d3.dip0.t-ipconnect.de ([87.184.100.211]
 helo=unknown.fritz.box)
 by mh-fa-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jxYq7-00AECJ-B7; Mon, 20 Jul 2020 17:40:32 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 0/5] Introduce Ring Buffer Implementation
Date: Mon, 20 Jul 2020 18:40:10 +0200
Message-Id: <20200720164015.4715-1-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-fa-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Alexander Jung <alexander.jung@neclab.eu>

This series introduces a port of FreeBSD's buf_ring.{h,c} implementation for use
within Unikraft.  This simple ring buffer can be used for message passing in
queues, for example within a AF_UNIX socket implementation between two 
threads.  The implementation is therefore thread safe and provides a generic 
data field which is initialized to the desired ring buffer length.

The implementation is provided within ukmpi as a new option, LIBUKMPI_RING, 
which exposes the following new methods:

 - uk_ring_alloc
 - uk_ring_free
 - uk_ring_enqueue
 - uk_ring_dequeue
 - uk_ring_dequeue_single
 - uk_ring_advance_single
 - uk_ring_putback_single
 - uk_ring_peek
 - uk_ring_peek_clear_single
 - uk_ring_full
 - uk_ring_empty
 - uk_ring_count

The port is currently limited, with no support for reading atomic values from
ARM{32,64} CPU registers (described in the comments inline).  As a result, use 
of the ring buffer implementation is untested on ARM.

Alexander Jung (5):
  lib/ukmpi: Introduce simple ring interface KConfig option
  lib/ukmpi: Initial port of FreeBSD's buf_ring.h
  lib/ukmpi: Provide ring buffer allocation and free methods
  lib/ukmpi: Include ring buffer into Unikraft build process
  lib/ukmpi: Export the global ring buffer (de)init methods

 lib/ukmpi/Config.uk         |  23 ++-
 lib/ukmpi/Makefile.uk       |   1 +
 lib/ukmpi/exportsyms.uk     |   3 +
 lib/ukmpi/include/uk/ring.h | 474 ++++++++++++++++++++++++++++++++++++++++++++
 lib/ukmpi/ring.c            |  87 ++++++++
 5 files changed, 587 insertions(+), 1 deletion(-)
 create mode 100644 lib/ukmpi/include/uk/ring.h
 create mode 100644 lib/ukmpi/ring.c

-- 
2.11.0



From minios-devel-bounces@lists.xenproject.org Mon Jul 20 16:40:39 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Mon, 20 Jul 2020 16:40:39 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxYqF-0002W4-Kr; Mon, 20 Jul 2020 16:40:39 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=T57I=A7=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxYqF-0002Vq-0g
 for minios-devel@lists.xen.org; Mon, 20 Jul 2020 16:40:39 +0000
X-Inumbo-ID: bcd1dc86-caa7-11ea-84a5-bc764e2007e4
Received: from mh-fa-1.lancs.ac.uk (unknown [148.88.65.131])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id bcd1dc86-caa7-11ea-84a5-bc764e2007e4;
 Mon, 20 Jul 2020 16:40:37 +0000 (UTC)
Received: from p57b864d3.dip0.t-ipconnect.de ([87.184.100.211]
 helo=unknown.fritz.box)
 by mh-fa-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jxYqB-00AECJ-AH; Mon, 20 Jul 2020 17:40:36 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 1/5] lib/ukmpi: Introduce simple ring interface
 KConfig option
Date: Mon, 20 Jul 2020 18:40:11 +0200
Message-Id: <20200720164015.4715-2-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200720164015.4715-1-a.jung@lancs.ac.uk>
References: <20200720164015.4715-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-fa-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Alexander Jung <alexander.jung@neclab.eu>

This commit prepares UKMPI for the inclusion of a simple ring
buffer implementation as a selectable option.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukmpi/Config.uk | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/lib/ukmpi/Config.uk b/lib/ukmpi/Config.uk
index 0c3bb4c..da50ccd 100644
--- a/lib/ukmpi/Config.uk
+++ b/lib/ukmpi/Config.uk
@@ -7,7 +7,8 @@ menuconfig LIBUKMPI
 		Provide inter-thread communication primitives
 
 if LIBUKMPI
-	config LIBUKMPI_MBOX
+
+config LIBUKMPI_MBOX
 	bool "Mailboxes"
 	select LIBUKALLOC
 	select LIBUKLOCK
@@ -15,4 +16,24 @@ if LIBUKMPI
 	default n
 	help
 		Provide mailbox communication interface
+
+config LIBUKMPI_RING
+	bool "Ring buffers"
+	select LIBUKALLOC
+	select LIBUKLOCK
+	select LIBUKLOCK_SEMAPHORE
+	default n
+	help
+		Provide simple ring interface for handling object references
+
+if LIBUKMPI_RING
+
+config LIBUKMPI_RING_DEBUG
+	bool "Debug ring buffer"
+	default n
+	help
+		Debug the ring interface
+
+endif
+
 endif
-- 
2.11.0



From minios-devel-bounces@lists.xenproject.org Mon Jul 20 16:40:44 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Mon, 20 Jul 2020 16:40:44 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxYqK-0002Wr-Mp; Mon, 20 Jul 2020 16:40:44 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=T57I=A7=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxYqJ-0002Vq-Sm
 for minios-devel@lists.xen.org; Mon, 20 Jul 2020 16:40:43 +0000
X-Inumbo-ID: bf53c488-caa7-11ea-84a5-bc764e2007e4
Received: from mh-fa-1.lancs.ac.uk (unknown [148.88.65.131])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id bf53c488-caa7-11ea-84a5-bc764e2007e4;
 Mon, 20 Jul 2020 16:40:41 +0000 (UTC)
Received: from p57b864d3.dip0.t-ipconnect.de ([87.184.100.211]
 helo=unknown.fritz.box)
 by mh-fa-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jxYqE-00AECJ-BX; Mon, 20 Jul 2020 17:40:40 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 2/5] lib/ukmpi: Initial port of FreeBSD's buf_ring.h
Date: Mon, 20 Jul 2020 18:40:12 +0200
Message-Id: <20200720164015.4715-3-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200720164015.4715-1-a.jung@lancs.ac.uk>
References: <20200720164015.4715-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-fa-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Alexander Jung <alexander.jung@neclab.eu>

This commit introduces a Unikraft-centric implementation of
FreeBSD's buf_ring.h message passing ring buffer header.  Most of
the functionality is provided inline with this header.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukmpi/include/uk/ring.h | 474 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 474 insertions(+)
 create mode 100644 lib/ukmpi/include/uk/ring.h

diff --git a/lib/ukmpi/include/uk/ring.h b/lib/ukmpi/include/uk/ring.h
new file mode 100644
index 0000000..6673244
--- /dev/null
+++ b/lib/ukmpi/include/uk/ring.h
@@ -0,0 +1,474 @@
+/* SPDX-License-Identifier: BSD-2-Clause-FreeBSD */
+/*
+ * Authors: Kip Macy <kmacy@freebsd.org>
+ *          Alexander Jung <alexander.jung@neclab.eu>
+ *
+ * Copyright (c) 2007-2009, Kip Macy <kmacy@freebsd.org>
+ *               2020, NEC Laboratories Europe GmbH, NEC Corporation.
+ *               All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+/*
+ * Simple ring implementation to handle object references.
+ *
+ * Inspired by FreeBSD and modified (commit-id: c45cce1).
+ */
+#ifndef __UK_RING_H__
+#define __UK_RING_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#include <errno.h>
+#include <uk/mutex.h>
+#include <uk/print.h>
+#include <uk/config.h>
+#include <uk/assert.h>
+#include <uk/plat/lcpu.h>
+#include <uk/arch/atomic.h>
+
+
+struct uk_ring {
+  volatile uint32_t  prod_head;
+  volatile uint32_t  prod_tail;  
+  int                prod_size;
+  int                prod_mask;
+  uint64_t           drops;
+  volatile uint32_t  cons_head;
+  volatile uint32_t  cons_tail;
+  int                cons_size;
+  int                cons_mask;
+#ifdef CONFIG_LIBUKMPI_RING_DEBUG
+  struct uk_mutex   *lock;
+#endif /* CONFIG_LIBUKMPI_RING_DEBUG */
+  void              *ring[0];
+};
+
+
+/**
+ * Multi-producer safe lock-free ring buffer enqueue.
+ *
+ * @param br
+ *  Reference to the ring structure.
+ * @param buf
+ *  Buffer size for the ring.
+ */
+static __inline int
+uk_ring_enqueue(struct uk_ring *br, void *buf)
+{
+  uint32_t prod_head, prod_next, cons_tail;
+
+#ifdef CONFIG_LIBUKMPI_RING_DEBUG
+  int i;
+  /*
+   * Note: It is possible to encounter an mbuf that was removed via drpeek(),
+   * and then re-added via drputback() and trigger a spurious panic.
+   */
+  for (i = br->cons_head; i != br->prod_head;
+       i = ((i + 1) & br->cons_mask))
+    if(br->ring[i] == buf)
+      uk_pr_crit("buf=%p already enqueue at %d prod=%d cons=%d\n",
+          buf, i, br->prod_tail, br->cons_tail);
+#endif /* CONFIG_LIBUKMPI_RING_DEBUG */
+
+  ukplat_lcpu_disable_irq();
+
+  do {
+    prod_head = br->prod_head;
+    prod_next = (prod_head + 1) & br->prod_mask;
+    cons_tail = br->cons_tail;
+
+    if (prod_next == cons_tail) {
+      rmb();
+      if (prod_head == br->prod_head &&
+          cons_tail == br->cons_tail) {
+        br->drops++;
+        ukplat_lcpu_enable_irq();
+        return -ENOBUFS;
+      }
+      continue;
+    }
+  } while (!ukarch_compare_exchange_sync(&br->prod_head, prod_head, prod_next));
+
+#ifdef CONFIG_LIBUKMPI_RING_DEBUG
+  if (br->ring[prod_head] != NULL)
+    uk_pr_crit("dangling value in enqueue\n");
+#endif /* CONFIG_LIBUKMPI_RING_DEBUG */
+
+  br->ring[prod_head] = buf;
+
+  /*
+   * If there are other enqueues in progress that preceded us, we need to wait
+   * for them to complete.
+   */
+  /* TODO: Provide cpu_spinwait() */
+#if 0
+  while (br->prod_tail != prod_head)
+    cpu_spinwait();
+#endif
+
+  ukarch_store_n(&br->prod_tail, prod_next);
+  ukplat_lcpu_enable_irq();
+
+  return 0;
+}
+
+
+/**
+ * Multi-consumer safe dequeue.
+ *
+ * @param br
+ *  Reference to the ring structure.
+ */
+static __inline void *
+uk_ring_dequeue(struct uk_ring *br)
+{
+  void *buf;
+  uint32_t cons_head, cons_next;
+
+  ukplat_lcpu_disable_irq();
+
+  do {
+    cons_head = br->cons_head;
+    cons_next = (cons_head + 1) & br->cons_mask;
+
+    if (cons_head == br->prod_tail) {
+      ukplat_lcpu_enable_irq();
+      return (NULL);
+    }
+  } while (!ukarch_compare_exchange_sync(&br->cons_head, cons_head, cons_next));
+
+  buf = br->ring[cons_head];
+
+#ifdef CONFIG_LIBUKMPI_RING_DEBUG
+  br->ring[cons_head] = NULL;
+#endif /* CONFIG_LIBUKMPI_RING_DEBUG */
+
+  /*
+   * If there are other dequeues in progress that preceded us, we need to wait
+   * for them to complete.
+   */
+  /* TODO: Provide cpu_spinwait() */
+#if 0
+  while (br->cons_tail != cons_head)
+    cpu_spinwait();
+#endif
+
+  ukarch_store_n(&br->cons_tail, cons_next);
+
+  ukplat_lcpu_enable_irq();
+
+  return buf;
+}
+
+
+/**
+ * Single-consumer dequeue use where dequeue is protected by a lock e.g. a
+ * network driver's tx queue lock.
+ *
+ * @param br
+ *  Reference to the ring structure.
+ */
+static __inline void *
+uk_ring_dequeue_single(struct uk_ring *br)
+{
+  void *buf;
+  uint32_t cons_head, cons_next, prod_tail;
+
+#ifdef PREFETCH_DEFINED
+  uint32_t cons_next_next;
+#endif
+
+  /* TODO: Provide atomic_load_acq_32() */
+#if 0
+  /*
+   * This is a workaround to allow using uk_ring on ARM and ARM64.
+   *
+   * ARM64TODO: Fix uk_ring in a generic way.
+   *
+   * REMARKS: It is suspected that cons_head does not require
+   *   load_acq operation, but this change was extensively tested
+   *   and confirmed it's working. To be reviewed once again in
+   *   FreeBSD-12.
+   *
+   * Preventing following situation:
+   *
+   * | uk_ring_enqueue()                            | uk_ring_dequeue_single()                                   |
+   * |----------------------------------------------+-----------------------------------------------------|
+   * |                                              |                                                     |
+   * |                                              | cons_head = br->cons_head;                          |
+   * | atomic_cmpset_acq_32(&br->prod_head, ...));  |                                                     |
+   * |                                              | buf = br->ring[cons_head];   (see <1>)              |
+   * | br->ring[prod_head] = buf;                   |                                                     |
+   * | atomic_store_rel_32(&br->prod_tail, ...);    |                                                     |
+   * |                                              | prod_tail = br->prod_tail;                          |
+   * |                                              | if (cons_head == prod_tail)                         |
+   * |                                              |   return NULL;                                      |
+   * |                                              | <condition is false and code uses invalid(old) buf> |
+   *
+   * <1> Load (on core 1) from br->ring[cons_head] can be reordered (speculative readed) by CPU.
+   */  
+#if defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64)
+  cons_head = atomic_load_acq_32(&br->cons_head);
+#else
+  cons_head = br->cons_head;
+#endif /* defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64) */
+#else
+  cons_head = br->cons_head;
+#endif /* 0 */
+
+  // prod_tail = atomic_load_acq_32(&br->prod_tail);  
+  prod_tail = br->prod_tail;
+  cons_next = (cons_head + 1) & br->cons_mask;
+  
+  if (cons_head == prod_tail) 
+    return NULL;
+
+  br->cons_head = cons_next;
+  buf = br->ring[cons_head];
+
+#ifdef CONFIG_LIBUKMPI_RING_DEBUG
+  br->ring[cons_head] = NULL;
+
+  if (!uk_mutex_is_locked(br->lock))
+    uk_pr_crit("lock not held on single consumer dequeue\n");
+
+  if (br->cons_tail != cons_head)
+    uk_pr_crit("inconsistent list cons_tail=%d cons_head=%d\n",
+        br->cons_tail, cons_head);
+
+#endif /* CONFIG_LIBUKMPI_RING_DEBUG */
+
+  br->cons_tail = cons_next;
+
+  return buf;
+}
+
+
+/**
+ * Single-consumer advance after a peek use where it is protected by a lock e.g.
+ * a network driver's tx queue lock.
+ *
+ * @param br
+ *  Reference to the ring structure.
+ */
+static __inline void
+uk_ring_advance_single(struct uk_ring *br)
+{
+  uint32_t cons_head, cons_next;
+  uint32_t prod_tail;
+
+  debug_ring(br);
+  
+  cons_head = br->cons_head;
+  prod_tail = br->prod_tail;
+  
+  cons_next = (cons_head + 1) & br->cons_mask;
+
+  if (cons_head == prod_tail) 
+    return;
+
+  br->cons_head = cons_next;
+
+#ifdef CONFIG_LIBUKMPI_RING_DEBUG
+  br->ring[cons_head] = NULL;
+#endif /* CONFIG_LIBUKMPI_RING_DEBUG */
+
+  br->cons_tail = cons_next;
+}
+
+
+/**
+ * Used to return a buffer (most likely already there) to the top of the ring.
+ * The caller should *not* have used any dequeue to pull it out of the ring but
+ * instead should have used the peek() function.  This is normally used where
+ * the transmit queue of a driver is full, and an mbuf must be returned.  Most
+ * likely whats in the ring-buffer is what is being put back (since it was not
+ * removed), but sometimes the lower transmit function may have done a pullup or
+ * other function that will have changed it. As an optimization we always put it
+ * back (since jhb says the store is probably cheaper), if we have to do a
+ * multi-queue version we will need the compare and an atomic.
+ *
+ * @param br
+ *  Reference to the ring structure.
+ * @param new
+ *  
+ */
+static __inline void
+uk_ring_putback_single(struct uk_ring *br, void *new)
+{
+  /* Buffer ring has none in putback */
+  UK_ASSERT(br->cons_head != br->prod_tail);
+  br->ring[br->cons_head] = new;
+}
+
+
+/**
+ * Return a pointer to the first entry in the ring without modifying it, or NULL
+ * if the ring is empty race-prone if not protected by a lock.
+ *
+ * @param br
+ *  Reference to the ring structure.
+ */
+static __inline void *
+uk_ring_peek(struct uk_ring *br)
+{
+#ifdef CONFIG_LIBUKMPI_RING_DEBUG
+  if ((br->lock != NULL) && !uk_mutex_is_locked(br->lock))
+    uk_pr_crit("lock not held on single consumer dequeue\n");
+#endif /* CONFIG_LIBUKMPI_RING_DEBUG */
+
+  /*
+   * It is safe to not have a memory barrier here because we control cons and
+   * tail is worst case a lagging indicator so we worst case we might return
+   * NULL immediately after a buffer has been enqueued.
+   */
+  if (br->cons_head == br->prod_tail)
+    return NULL;
+  
+  return br->ring[br->cons_head];
+}
+
+
+/**
+ * Single-consumer clear the pointer to the first entry of the ring, or NULL if
+ * the ring is empty.
+ *
+ * @param br
+ *  Reference to the ring structure.
+ */
+static __inline void *
+uk_ring_peek_clear_single(struct uk_ring *br)
+{
+#ifdef CONFIG_LIBUKMPI_RING_DEBUG
+  void *ret;
+
+  if (!mtx_owned(br->lock))
+    panic("lock not held on single consumer dequeue");
+#endif /* CONFIG_LIBUKMPI_RING_DEBUG */
+
+  if (br->cons_head == br->prod_tail)
+    return (NULL);
+
+  /* TODO: Provide atomic_thread_fence_acq */
+#if 0
+#if defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64)
+  /*
+   * The barrier is required there on ARM and ARM64 to ensure, that
+   * br->ring[br->cons_head] will not be fetched before the above condition is
+   * checked.  Without the barrier, it is possible, that buffer will be fetched
+   * before the enqueue will put mbuf into br, then, in the meantime, the
+   * enqueue will update the array and the prod_tail, and the conditional check
+   * will be true, so we will return previously fetched (and invalid) buffer.
+   */
+  atomic_thread_fence_acq();
+#endif /* defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64) */
+#endif /* 0 */
+
+#ifdef CONFIG_LIBUKMPI_RING_DEBUG
+  /*
+   * Single consumer, i.e. cons_head will not move while we are
+   * running, so atomic_swap_ptr() is not necessary here.
+   */
+  ret = br->ring[br->cons_head];
+  br->ring[br->cons_head] = NULL;
+  return (ret);
+#else
+  return (br->ring[br->cons_head]);
+#endif /* CONFIG_LIBUKMPI_RING_DEBUG */
+}
+
+
+/**
+ * Return whether the ring buffer is full.
+ *
+ * @param br
+ *  Reference to the ring structure.
+ */
+static __inline int
+uk_ring_full(struct uk_ring *br)
+{
+  return ((br->prod_head + 1) & br->prod_mask) == br->cons_tail;
+}
+
+
+/**
+ * Return whether the ring buffer is empty.
+ *
+ * @param br
+ *  Reference to the ring structure.
+ */
+static __inline int
+uk_ring_empty(struct uk_ring *br)
+{
+  return br->cons_head == br->prod_tail;
+}
+
+
+/**
+ * Return the queue size in the ring buffer.
+ *
+ * @param br
+ *  Reference to the ring structure.
+ */
+static __inline int
+uk_ring_count(struct uk_ring *br)
+{
+  return (br->prod_size + br->prod_tail - br->cons_tail) & br->prod_mask;
+}
+
+
+/**
+ * Create a new ring buffer.
+ *
+ * @param count
+ *  The size of the ring buffer.
+ * @param a
+ *  The memory allocator to use when creating the ring buffer.
+ * @param flags
+ *  Additional flags to specify to the ring.
+ * @param lock
+ *  The mutex to use when debugging the ring buffer.
+ */
+struct uk_ring *
+uk_ring_alloc(int count, struct uk_alloc *a, int flags, struct uk_mutex *lock);
+
+
+/**
+ * Free the ring from use.
+ *
+ * @param br
+ *  Reference to the ring structure.
+ * @param a
+ *  The memory allocator to use when freeing the object.
+ */
+void
+uk_ring_free(struct uk_ring *br, struct uk_alloc *a);
+
+
+#endif /* __UK_RING_H__ */
-- 
2.11.0



From minios-devel-bounces@lists.xenproject.org Mon Jul 20 16:40:46 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Mon, 20 Jul 2020 16:40:46 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxYqM-0002Xd-PU; Mon, 20 Jul 2020 16:40:46 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=T57I=A7=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxYqL-0002XL-CM
 for minios-devel@lists.xen.org; Mon, 20 Jul 2020 16:40:45 +0000
X-Inumbo-ID: c132d370-caa7-11ea-9fdf-12813bfff9fa
Received: from mh-fa-1.lancs.ac.uk (unknown [148.88.65.131])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id c132d370-caa7-11ea-9fdf-12813bfff9fa;
 Mon, 20 Jul 2020 16:40:44 +0000 (UTC)
Received: from p57b864d3.dip0.t-ipconnect.de ([87.184.100.211]
 helo=unknown.fritz.box)
 by mh-fa-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jxYqI-00AECJ-Al; Mon, 20 Jul 2020 17:40:43 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 3/5] lib/ukmpi: Provide ring buffer allocation and
 free methods
Date: Mon, 20 Jul 2020 18:40:13 +0200
Message-Id: <20200720164015.4715-4-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200720164015.4715-1-a.jung@lancs.ac.uk>
References: <20200720164015.4715-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-fa-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Alexander Jung <alexander.jung@neclab.eu>

This commit introduces two new methods for initializing and
de-initializing ring buffers.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukmpi/ring.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)
 create mode 100644 lib/ukmpi/ring.c

diff --git a/lib/ukmpi/ring.c b/lib/ukmpi/ring.c
new file mode 100644
index 0000000..1fbb81e
--- /dev/null
+++ b/lib/ukmpi/ring.c
@@ -0,0 +1,87 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Kip Macy <kmacy@freebsd.org>
+ *          Simon Kuenzer <simon.kuenzer@neclab.eu>
+ *          Alexander Jung <alexander.jung@neclab.eu>
+ *
+ * Copyright (c) 2007-2009, Kip Macy <kmacy@freebsd.org>
+ *               2018-2020, NEC Laboratories Europe GmbH, NEC Corporation.
+ *               All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+/*
+ * Simple ring implementation to handle object references.
+ *
+ * Inspired by FreeBSD and modified (commit-id: c45cce1).
+ */
+
+
+#include <sys/param.h>
+#include <uk/ring.h>
+#include <uk/assert.h>
+#include <uk/alloc.h>
+#include <uk/mutex.h>
+#include <uk/config.h>
+#include <uk/print.h>
+
+#ifndef POWER_OF_2
+#define POWER_OF_2(x)   (((x)) && (!((x) & ((x) - 1))))
+#endif
+
+struct uk_ring *
+uk_ring_alloc(int count, struct uk_alloc *a, int flags, struct uk_mutex *lock)
+{
+  struct uk_ring *br;
+
+  UK_ASSERT(a);
+  /* Buf ring must be size power of 2 */
+  UK_ASSERT(POWER_OF_2(count));
+  
+  br = uk_malloc(a, sizeof(struct uk_ring) + count * sizeof(caddr_t));
+  if (br == NULL) {
+    uk_pr_err("Could not allocate ring: out of memory\n");
+    return NULL;
+  }
+
+#ifdef CONFIG_LIBUKMPI_RING_DEBUG
+  br->lock = lock;
+#endif  
+
+  br->prod_size = br->cons_size = count;
+  br->prod_mask = br->cons_mask = count - 1;
+  br->prod_head = br->cons_head = 0;
+  br->prod_tail = br->cons_tail = 0;
+
+  return br;
+}
+
+void
+uk_ring_free(struct uk_ring *br, struct uk_alloc *a)
+{
+  UK_ASSERT(a);
+  uk_free(a, br);
+}
-- 
2.11.0



From minios-devel-bounces@lists.xenproject.org Mon Jul 20 16:40:49 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Mon, 20 Jul 2020 16:40:49 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxYqP-0002YW-RM; Mon, 20 Jul 2020 16:40:49 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=T57I=A7=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxYqO-0002Vq-Ss
 for minios-devel@lists.xen.org; Mon, 20 Jul 2020 16:40:48 +0000
X-Inumbo-ID: c306f0a0-caa7-11ea-84a5-bc764e2007e4
Received: from mh-fa-1.lancs.ac.uk (unknown [148.88.65.131])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id c306f0a0-caa7-11ea-84a5-bc764e2007e4;
 Mon, 20 Jul 2020 16:40:47 +0000 (UTC)
Received: from p57b864d3.dip0.t-ipconnect.de ([87.184.100.211]
 helo=unknown.fritz.box)
 by mh-fa-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jxYqL-00AECJ-Bd; Mon, 20 Jul 2020 17:40:46 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 4/5] lib/ukmpi: Include ring buffer into Unikraft
 build process
Date: Mon, 20 Jul 2020 18:40:14 +0200
Message-Id: <20200720164015.4715-5-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200720164015.4715-1-a.jung@lancs.ac.uk>
References: <20200720164015.4715-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-fa-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Alexander Jung <alexander.jung@neclab.eu>

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukmpi/Makefile.uk | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/ukmpi/Makefile.uk b/lib/ukmpi/Makefile.uk
index fc8a360..d5dbd71 100644
--- a/lib/ukmpi/Makefile.uk
+++ b/lib/ukmpi/Makefile.uk
@@ -4,3 +4,4 @@ CINCLUDES-$(CONFIG_LIBUKMPI)   += -I$(LIBUKMPI_BASE)/include
 CXXINCLUDES-$(CONFIG_LIBUKMPI) += -I$(LIBUKMPI_BASE)/include
 
 LIBUKMPI_SRCS-$(CONFIG_LIBUKMPI_MBOX) += $(LIBUKMPI_BASE)/mbox.c
+LIBUKMPI_SRCS-$(CONFIG_LIBUKMPI_RING) += $(LIBUKMPI_BASE)/ring.c
-- 
2.11.0



From minios-devel-bounces@lists.xenproject.org Mon Jul 20 16:40:51 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Mon, 20 Jul 2020 16:40:51 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxYqR-0002ZE-Sz; Mon, 20 Jul 2020 16:40:51 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=T57I=A7=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxYqQ-0002Yx-QR
 for minios-devel@lists.xen.org; Mon, 20 Jul 2020 16:40:50 +0000
X-Inumbo-ID: c4a087be-caa7-11ea-9fdf-12813bfff9fa
Received: from mh-fa-1.lancs.ac.uk (unknown [148.88.65.131])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id c4a087be-caa7-11ea-9fdf-12813bfff9fa;
 Mon, 20 Jul 2020 16:40:50 +0000 (UTC)
Received: from p57b864d3.dip0.t-ipconnect.de ([87.184.100.211]
 helo=unknown.fritz.box)
 by mh-fa-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jxYqO-00AECJ-Ad; Mon, 20 Jul 2020 17:40:49 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 5/5] lib/ukmpi: Export the global ring buffer
 (de)init methods
Date: Mon, 20 Jul 2020 18:40:15 +0200
Message-Id: <20200720164015.4715-6-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200720164015.4715-1-a.jung@lancs.ac.uk>
References: <20200720164015.4715-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-fa-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Alexander Jung <alexander.jung@neclab.eu>

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukmpi/exportsyms.uk | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/ukmpi/exportsyms.uk b/lib/ukmpi/exportsyms.uk
index b0d661a..b50e1b2 100644
--- a/lib/ukmpi/exportsyms.uk
+++ b/lib/ukmpi/exportsyms.uk
@@ -6,3 +6,6 @@ uk_mbox_post_to
 uk_mbox_recv
 uk_mbox_recv_try
 uk_mbox_recv_to
+
+uk_ring_alloc
+uk_ring_free
-- 
2.11.0



From minios-devel-bounces@lists.xenproject.org Mon Jul 20 20:54:21 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Mon, 20 Jul 2020 20:54:21 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxcnh-0007q9-Ml; Mon, 20 Jul 2020 20:54:17 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YtxJ=A7=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jxcnh-0007q4-2w
 for minios-devel@lists.xen.org; Mon, 20 Jul 2020 20:54:17 +0000
X-Inumbo-ID: 2af612c2-cacb-11ea-84c3-bc764e2007e4
Received: from mx.upb.ro (unknown [141.85.13.200])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 2af612c2-cacb-11ea-84c3-bc764e2007e4;
 Mon, 20 Jul 2020 20:54:14 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 07C7AB560093;
 Mon, 20 Jul 2020 23:54:13 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id es61JTv7wi76; Mon, 20 Jul 2020 23:54:11 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id EF7F4B56125E;
 Mon, 20 Jul 2020 23:54:10 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id Uq7g70tzEc6O; Mon, 20 Jul 2020 23:54:10 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id 7B8F0B560093;
 Mon, 20 Jul 2020 23:54:10 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH 0/5] Introduce Ring Buffer Implementation
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200720164015.4715-1-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <e80d91f8-b20f-69ee-2955-1146cd76181a@cs.pub.ro>
Date: Mon, 20 Jul 2020 23:54:10 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200720164015.4715-1-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

I have a curiosity. Why don't you put this ring implementation in a
library of its own, e.g. ukring or smth? I thought that library
granularity was one of the strong points of Unikraft. Besides, this ring
implementation may be subject to more configuration options in the
future which would complicate the ukmpi configuration space.

Cheers,
Costin

On 7/20/20 7:40 PM, Alexander Jung wrote:
> From: Alexander Jung <alexander.jung@neclab.eu>
> 
> This series introduces a port of FreeBSD's buf_ring.{h,c} implementation for use
> within Unikraft.  This simple ring buffer can be used for message passing in
> queues, for example within a AF_UNIX socket implementation between two 
> threads.  The implementation is therefore thread safe and provides a generic 
> data field which is initialized to the desired ring buffer length.
> 
> The implementation is provided within ukmpi as a new option, LIBUKMPI_RING, 
> which exposes the following new methods:
> 
>  - uk_ring_alloc
>  - uk_ring_free
>  - uk_ring_enqueue
>  - uk_ring_dequeue
>  - uk_ring_dequeue_single
>  - uk_ring_advance_single
>  - uk_ring_putback_single
>  - uk_ring_peek
>  - uk_ring_peek_clear_single
>  - uk_ring_full
>  - uk_ring_empty
>  - uk_ring_count
> 
> The port is currently limited, with no support for reading atomic values from
> ARM{32,64} CPU registers (described in the comments inline).  As a result, use 
> of the ring buffer implementation is untested on ARM.
> 
> Alexander Jung (5):
>   lib/ukmpi: Introduce simple ring interface KConfig option
>   lib/ukmpi: Initial port of FreeBSD's buf_ring.h
>   lib/ukmpi: Provide ring buffer allocation and free methods
>   lib/ukmpi: Include ring buffer into Unikraft build process
>   lib/ukmpi: Export the global ring buffer (de)init methods
> 
>  lib/ukmpi/Config.uk         |  23 ++-
>  lib/ukmpi/Makefile.uk       |   1 +
>  lib/ukmpi/exportsyms.uk     |   3 +
>  lib/ukmpi/include/uk/ring.h | 474 ++++++++++++++++++++++++++++++++++++++++++++
>  lib/ukmpi/ring.c            |  87 ++++++++
>  5 files changed, 587 insertions(+), 1 deletion(-)
>  create mode 100644 lib/ukmpi/include/uk/ring.h
>  create mode 100644 lib/ukmpi/ring.c
> 


From minios-devel-bounces@lists.xenproject.org Mon Jul 20 21:52:39 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Mon, 20 Jul 2020 21:52:39 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxdiA-0004O1-8d; Mon, 20 Jul 2020 21:52:38 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Zgca=A7=lancaster.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxdi9-0004Nw-2Q
 for minios-devel@lists.xen.org; Mon, 20 Jul 2020 21:52:37 +0000
X-Inumbo-ID: 50ffa2b4-cad3-11ea-84c8-bc764e2007e4
Received: from GBR01-LO2-obe.outbound.protection.outlook.com (unknown
 [40.107.10.94]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 50ffa2b4-cad3-11ea-84c8-bc764e2007e4;
 Mon, 20 Jul 2020 21:52:34 +0000 (UTC)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=SQVP4WaPMqVM3oT0qb3151Ja3Clwrh5uC2nHLumX4q0npHDQfLB0StQfFvmrpI60Iuy8yAjZuyYFYhQmsUqPH4r5UBZZL/4P8MEnHwrtGSBE2PqDIQIlPn4wJqGNizTocSWwRRCJ/3VFzfYMkOqt53KKzrEn05uplFUjFh8Chig/iYs7j+Xi2cR0sVX7j5ukF1w00vpa4l+ZS67uvIWBdfsifonQDrEgcnwdCe3QzJawJK2qQ4vVoINpvQDENGAX2YhlfToZART3jLcK1hlmzBQyfKqDcOvPXpEdZBMYONuVX9ukzU3mklYourtscIaJ4V6N8w6W0Ox/nqWisk/GVw==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; 
 s=arcselector9901;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=j9bvtIRSM4YYyQp2ZdrOyrd8YvRgIoYhIhWZauaO0/4=;
 b=KghzABipxnp/nt+FCXzSneTFcPNCoOoWj2FdXEIHKWDhiYClpLIB9wYpiTK9cyNNOKiB96BsM+vgkPH8OiqNfZuMx0gX1cdGUq+Mekz1OOFW1BucuYup2aMocenSoJDjbBKfR+mE83k6S17S+z+Zmzbpq9uSk1jHPDkkALff0Ja4uKPpjLNt23It6mbQ70xUlwMxzJXvuAt4fnJrFhuGv5UFnNhaMHfjsBeIkW05c94yu/5QIpYaSRg+2Ui9xs1u/d3y4o2nlEfXXzENupiyOuXaunRaY815QSisxKEPbJ5IK+I5cQkuOrQylGqSrggvvoy/UTro+D6cwEuiV8tPog==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
 smtp.mailfrom=lancaster.ac.uk; dmarc=pass action=none
 header.from=lancaster.ac.uk; dkim=pass header.d=lancaster.ac.uk; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=livelancsac.onmicrosoft.com; s=selector2-livelancsac-onmicrosoft-com;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=j9bvtIRSM4YYyQp2ZdrOyrd8YvRgIoYhIhWZauaO0/4=;
 b=sNN/cWawDSQxiSljRKPNYTm3yzROuMmab3Pkodcj1Ms/pR1g5QpBQwFYWpAfsQnXonPWfe7QIIeDBFFZIeWUIOxr+Gn4dyGs+sBcSNx+NW/WLvX1Vis5w3GuEGOGAOtmTS1xv2VN5Q6XAcvXEHM15Q6JaC+7TJOnDJW2Zmp86YY=
Received: from CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM (2603:10a6:401:17::15)
 by CWXP265MB0709.GBRP265.PROD.OUTLOOK.COM (2603:10a6:401:2::23) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.23; Mon, 20 Jul
 2020 21:52:32 +0000
Received: from CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM
 ([fe80::fcde:79b:21d6:5203]) by CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM
 ([fe80::fcde:79b:21d6:5203%4]) with mapi id 15.20.3195.025; Mon, 20 Jul 2020
 21:52:32 +0000
From: "Jung, Alexander" <a.jung@lancaster.ac.uk>
To: Costin Lupu <costin.lupu@cs.pub.ro>, "minios-devel@lists.xen.org"
 <minios-devel@lists.xen.org>
Subject: Re: [UNIKRAFT PATCH 0/5] Introduce Ring Buffer Implementation
Thread-Topic: [UNIKRAFT PATCH 0/5] Introduce Ring Buffer Implementation
Thread-Index: AQHWXuARYZSBEwYhh0KI3dB0dDXIIQ==
Date: Mon, 20 Jul 2020 21:52:32 +0000
Message-ID: <EFB9FD19-4C55-4F66-91F3-09A41E1AA134@lancaster.ac.uk>
References: <20200720164015.4715-1-a.jung@lancs.ac.uk>
 <e80d91f8-b20f-69ee-2955-1146cd76181a@cs.pub.ro>
In-Reply-To: <e80d91f8-b20f-69ee-2955-1146cd76181a@cs.pub.ro>
Accept-Language: en-GB, en-US
Content-Language: en-GB
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
user-agent: Microsoft-MacOutlook/16.38.20061401
authentication-results: cs.pub.ro; dkim=none (message not signed)
 header.d=none;cs.pub.ro; dmarc=none action=none header.from=lancaster.ac.uk;
x-originating-ip: [77.180.176.206]
x-ms-publictraffictype: Email
x-ms-office365-filtering-correlation-id: 39c9ee15-165c-4903-cfa3-08d82cf7347c
x-ms-traffictypediagnostic: CWXP265MB0709:
x-microsoft-antispam-prvs: <CWXP265MB070908A8CADD0998ACE3B501CE7B0@CWXP265MB0709.GBRP265.PROD.OUTLOOK.COM>
x-ms-oob-tlc-oobclassifiers: OLM:10000;
x-ms-exchange-senderadcheck: 1
x-microsoft-antispam: BCL:0;
x-microsoft-antispam-message-info: W9vqkpK0D0tM0XOhfvviWl6Fqj1HVek7R07hYvVjNVPnRL2ebotX+ej1XdbVirGpJFsRYDnD1e7d1pxKsbd+5Mw9m27Pp94l07k7u1lJNgdpbFtACx0BW2F4y53J1QBLBCCtp4L3GKnmAuNvN6+zzam98FtqLST6BAWVttkThJIoEzTSvdf/R9385L6qAkh282vUh5QIIULeTJeFFPO0uRUcoiH+V/YWQohfhx/bv0ZgtrnLkKlf8AU8Nzwm+oNFdKuCTnjGHW9YBroU/b4UMN9EtMtvpBudRa6nQxwwI0XhuizoGVncATYhaPHnCHhH9cdHUdk5EodoJJcWTL38kQ==
x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
 IPV:NLI; SFV:NSPM; H:CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM; PTR:; CAT:NONE;
 SFTY:;
 SFS:(4636009)(136003)(396003)(366004)(39860400002)(346002)(376002)(33656002)(5660300002)(54906003)(110136005)(26005)(71200400001)(76116006)(83380400001)(64756008)(66556008)(36756003)(91956017)(66946007)(66476007)(66446008)(8676002)(6512007)(8936002)(2616005)(4326008)(186003)(478600001)(6486002)(786003)(2906002)(6506007)(53546011)(86362001)(316002);
 DIR:OUT; SFP:1102; 
x-ms-exchange-antispam-messagedata: 2L3g+rGIJgq9swhzWwvgx+HdLHMWNZFnlQO8GDVNbh3Pfq5GS1qtCTlr6b6i8d7RN80KXGcHg1JQCxvsHLx/04fjEUT+1CqykBwxPr+3ROzmfvbB6ysyxWEf1hNnH1/HPoNJs4n5rJHe0zAvS81CELKwVOJd/rNfnQjJjmfU8G/KX7FE91l8LURufYNTb7wHZnlH5jxCxKKZBoLUSDOPv8KPEVHPwmStfqPz9vooGVyzL2G4dikLgqg8gWGM8y5el+2yh0zWKrkL+m8Q4A592Jp/aNrvP63w2xgmagWsoCw/Rqifwk+LM/IS4hOw8eGddFjoG6Pw7E/kTCIcobHqSmVCFhYzKm8BKNS0CWaa75wblSYGay2NzKxhgxuNsxkXpOPa4vpGl31HfsMMXvW051e/q4TUUNTKMcIA95F2tbZf2j7eA8djVt8MCnLpLjkJKSbSW9CdxaoWe2taysGr1QvPyThuFSXatRTvBbQBpBZWOdHQGNMAvHyQZCjOqbTC
x-ms-exchange-transport-forked: True
Content-Type: text/plain; charset="utf-8"
Content-ID: <1B214B74D15E2D4F96AA65CDC6D19E69@GBRP265.PROD.OUTLOOK.COM>
Content-Transfer-Encoding: base64
MIME-Version: 1.0
X-OriginatorOrg: lancaster.ac.uk
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM
X-MS-Exchange-CrossTenant-Network-Message-Id: 39c9ee15-165c-4903-cfa3-08d82cf7347c
X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jul 2020 21:52:32.1314 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 9c9bcd11-977a-4e9c-a9a0-bc734090164a
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: cTm3H+wqFCU1cIu4CfcVFAkFPEiRfgS4eF9FzPmCRi0bgudcYVaZ+ET6d2+CgNO5udXkIZmWm440rNQgWADhqA==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWXP265MB0709
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

SGkgQ29zdGluLA0KDQpGb3IgdGhpcyB2ZXJzaW9uLCBJIHNpbXBseSBjaG9zZSB0byBpbnRyb2R1
Y2UgaXQgaW50byB0aGUgdWttcGkgbGlicmFyeSBzaW5jZSANCml0IGFkb3B0cyBhIHNpbWlsYXIg
dHJhaXQgdG8gbWJveCwgd2hpY2ggaXMgdGhlIGN1cnJlbnQgaW5oYWJpdGFudCBvZiB0aGUgDQpt
aWNyb2xpYnJhcnkuICBNYm94IGlzIGFub3RoZXIgInNpbXBsZSBtZXNzYWdlIHBhc3NpbmciIGlt
cGxlbWVudGF0aW9uIGFuZCwgZm9yIA0KbWUsIGFsb25nIHdpdGggdGhlIG9mZmxpbmUgY29udmVy
c2F0aW9uIEkgaGFkIHdpdGggU2ltb24gKGNjJ2QpLCBpdCBtYWRlIHNlbnNlIA0KdG8gaW5jbHVk
ZSBpdCBoZXJlIGFzIGFuIGFkZGl0aW9uYWwgcHJvdmlzaW9uIG9mIHRoZSBtaWNyb2xpYnJhcnkg
aXRzZWxmLiAgDQoNCkkgdGhpbmsgeW91ciBhcmd1bWVudCBpcyBmYWlyIGluIHRoYXQgaXQgY2Fu
IGV4aXN0IGFzIGl0cyBvd24gbGlicmFyeTogc2ltcGx5IA0KYXMgYHVrcmluZ2AuICBBdCB0aGlz
IHBvaW50LCBpdCBpcyBzaW1wbGUgYSBkZWNpc2lvbiB3LnIudC4gd2hldGhlciB0aGUgbGlicmFy
eSANCmNvbnN0aXR1dGVzIGNyZWF0aW5nIGVub3VnaCBhZGRpdGlvbmFsIG9wdGlvbnMgdGhhdCB3
b3VsZCBkZWdyYWRlIHRoZSBxdWFsaXR5IA0Kb2YgdWttcGkgaXRzZWxmLiAgUGFydGljdWxhcnks
IHlvdSByZWZlciB0byBhZGRpdGlvbmFsIG9wdGlvbnMgd2hpY2ggd2lsbCBiZSANCmJyb3VnaHQg
b3V0IG9mIHRoZSBpbXBsZW1lbnRhdGlvbiBpbiB0aGUgZnV0dXJlLiAgRm9yIG5vdywgSSBkbyBu
b3Qgc2VlIA0KYWRkaXRpb25hbCBvcHRpb25zIHdoaWNoIHdvdWxkIHN1cmZhY2UgdGhlbXNlbHZl
cyBhdCBwcmVzZW50IGluIHRoZSBLQ29uZmlnIA0Kb3B0aW9uIG1lbnUuICBUaGUgZGVjaXNpb24g
aXMgdWx0aW1hdGVseSB3aGV0aGVyIHRoZXNlIG9wdGlvbnMgYXJpc2UgZnJvbSANCmltcGxlbWVu
dGF0aW9uLXNwZWNpZmljIHJlcXVpcmVtZW50cywgaW4gdGhlIGNhc2Ugb2YsIGZvciBpbnN0YW5j
ZSwgbXBfcmluZy57YywNCmh9IGZyb20gRnJlZUJTRCB3aGljaCBpcyB0aGUgcmluZyBidWZmZXIg
aW1wbGVtZW50YXRpb24gZm9yIHRoZSBuZXR3b3JraW5nIA0Kc3RhY2sgKHRoYXQgaXQgaXMgdG8g
c2F5LCAid291bGQgdGhpcyBiZSBwYXJ0IG9mIGB1a3JpbmdgIG9yIGl0J3Mgb3duIGxpYnJhcnk/
IikNCg0KT25lIHRoaW5nIHRvIG5vdGUgaXMgdGhhdCB0aGUgcmluZyBpbXBsZW1lbnRhdGlvbiwg
YWxvbmcgd2l0aCBtYm94LCBhcmUgbm90IA0KUE9TSVgsIGFuZCBzbyBtYm94IGFuZCByaW5nJ3Mg
ImV4cG9ydHN5bXMiIGRvIG5vdCBzaGFyZSBzaW1pbGFyIG1ldGhvZCANCnN0YW5kYXJkaXphdGlv
bi4gIFRoaXMsIGFsb25nIHdpdGggdGhlIGZhY3QgdGhhdCB0aGV5IGFyZSBVbmlrcmFmdC1jZW50
cmljLy1jb3JlIA0KYW5kIG5hbWVzcGFjZWQgZnVuY3Rpb25zIG1lYW4gYXMgaW50ZXJuYWwgY29t
bXVuaWNhdGlvbiBtZWNoYW5pc20gaXRzIHBsYWNlbWVudCANCmlzIHNvbWV3aGF0IGFyYml0cmFy
eS4NCg0KV2hhdCBkbyB5b3UgdGhpbms/DQoNClRoYW5rcywNCg0KQWxleGFuZGVyDQoNCg0K77u/
T24gMjAuMDcuMjAsIDIyOjU1LCAiTWluaW9zLWRldmVsIG9uIGJlaGFsZiBvZiBDb3N0aW4gTHVw
dSIgPG1pbmlvcy1kZXZlbC1ib3VuY2VzQGxpc3RzLnhlbnByb2plY3Qub3JnIG9uIGJlaGFsZiBv
ZiBjb3N0aW4ubHVwdUBjcy5wdWIucm8+IHdyb3RlOg0KDQogICAgSGkgQWxleGFuZGVyLA0KDQog
ICAgSSBoYXZlIGEgY3VyaW9zaXR5LiBXaHkgZG9uJ3QgeW91IHB1dCB0aGlzIHJpbmcgaW1wbGVt
ZW50YXRpb24gaW4gYQ0KICAgIGxpYnJhcnkgb2YgaXRzIG93biwgZS5nLiB1a3Jpbmcgb3Igc210
aD8gSSB0aG91Z2h0IHRoYXQgbGlicmFyeQ0KICAgIGdyYW51bGFyaXR5IHdhcyBvbmUgb2YgdGhl
IHN0cm9uZyBwb2ludHMgb2YgVW5pa3JhZnQuIEJlc2lkZXMsIHRoaXMgcmluZw0KICAgIGltcGxl
bWVudGF0aW9uIG1heSBiZSBzdWJqZWN0IHRvIG1vcmUgY29uZmlndXJhdGlvbiBvcHRpb25zIGlu
IHRoZQ0KICAgIGZ1dHVyZSB3aGljaCB3b3VsZCBjb21wbGljYXRlIHRoZSB1a21waSBjb25maWd1
cmF0aW9uIHNwYWNlLg0KDQogICAgQ2hlZXJzLA0KICAgIENvc3Rpbg0KDQogICAgT24gNy8yMC8y
MCA3OjQwIFBNLCBBbGV4YW5kZXIgSnVuZyB3cm90ZToNCiAgICA+IEZyb206IEFsZXhhbmRlciBK
dW5nIDxhbGV4YW5kZXIuanVuZ0BuZWNsYWIuZXU+DQogICAgPiANCiAgICA+IFRoaXMgc2VyaWVz
IGludHJvZHVjZXMgYSBwb3J0IG9mIEZyZWVCU0QncyBidWZfcmluZy57aCxjfSBpbXBsZW1lbnRh
dGlvbiBmb3IgdXNlDQogICAgPiB3aXRoaW4gVW5pa3JhZnQuICBUaGlzIHNpbXBsZSByaW5nIGJ1
ZmZlciBjYW4gYmUgdXNlZCBmb3IgbWVzc2FnZSBwYXNzaW5nIGluDQogICAgPiBxdWV1ZXMsIGZv
ciBleGFtcGxlIHdpdGhpbiBhIEFGX1VOSVggc29ja2V0IGltcGxlbWVudGF0aW9uIGJldHdlZW4g
dHdvIA0KICAgID4gdGhyZWFkcy4gIFRoZSBpbXBsZW1lbnRhdGlvbiBpcyB0aGVyZWZvcmUgdGhy
ZWFkIHNhZmUgYW5kIHByb3ZpZGVzIGEgZ2VuZXJpYyANCiAgICA+IGRhdGEgZmllbGQgd2hpY2gg
aXMgaW5pdGlhbGl6ZWQgdG8gdGhlIGRlc2lyZWQgcmluZyBidWZmZXIgbGVuZ3RoLg0KICAgID4g
DQogICAgPiBUaGUgaW1wbGVtZW50YXRpb24gaXMgcHJvdmlkZWQgd2l0aGluIHVrbXBpIGFzIGEg
bmV3IG9wdGlvbiwgTElCVUtNUElfUklORywgDQogICAgPiB3aGljaCBleHBvc2VzIHRoZSBmb2xs
b3dpbmcgbmV3IG1ldGhvZHM6DQogICAgPiANCiAgICA+ICAtIHVrX3JpbmdfYWxsb2MNCiAgICA+
ICAtIHVrX3JpbmdfZnJlZQ0KICAgID4gIC0gdWtfcmluZ19lbnF1ZXVlDQogICAgPiAgLSB1a19y
aW5nX2RlcXVldWUNCiAgICA+ICAtIHVrX3JpbmdfZGVxdWV1ZV9zaW5nbGUNCiAgICA+ICAtIHVr
X3JpbmdfYWR2YW5jZV9zaW5nbGUNCiAgICA+ICAtIHVrX3JpbmdfcHV0YmFja19zaW5nbGUNCiAg
ICA+ICAtIHVrX3JpbmdfcGVlaw0KICAgID4gIC0gdWtfcmluZ19wZWVrX2NsZWFyX3NpbmdsZQ0K
ICAgID4gIC0gdWtfcmluZ19mdWxsDQogICAgPiAgLSB1a19yaW5nX2VtcHR5DQogICAgPiAgLSB1
a19yaW5nX2NvdW50DQogICAgPiANCiAgICA+IFRoZSBwb3J0IGlzIGN1cnJlbnRseSBsaW1pdGVk
LCB3aXRoIG5vIHN1cHBvcnQgZm9yIHJlYWRpbmcgYXRvbWljIHZhbHVlcyBmcm9tDQogICAgPiBB
Uk17MzIsNjR9IENQVSByZWdpc3RlcnMgKGRlc2NyaWJlZCBpbiB0aGUgY29tbWVudHMgaW5saW5l
KS4gIEFzIGEgcmVzdWx0LCB1c2UgDQogICAgPiBvZiB0aGUgcmluZyBidWZmZXIgaW1wbGVtZW50
YXRpb24gaXMgdW50ZXN0ZWQgb24gQVJNLg0KICAgID4gDQogICAgPiBBbGV4YW5kZXIgSnVuZyAo
NSk6DQogICAgPiAgIGxpYi91a21waTogSW50cm9kdWNlIHNpbXBsZSByaW5nIGludGVyZmFjZSBL
Q29uZmlnIG9wdGlvbg0KICAgID4gICBsaWIvdWttcGk6IEluaXRpYWwgcG9ydCBvZiBGcmVlQlNE
J3MgYnVmX3JpbmcuaA0KICAgID4gICBsaWIvdWttcGk6IFByb3ZpZGUgcmluZyBidWZmZXIgYWxs
b2NhdGlvbiBhbmQgZnJlZSBtZXRob2RzDQogICAgPiAgIGxpYi91a21waTogSW5jbHVkZSByaW5n
IGJ1ZmZlciBpbnRvIFVuaWtyYWZ0IGJ1aWxkIHByb2Nlc3MNCiAgICA+ICAgbGliL3VrbXBpOiBF
eHBvcnQgdGhlIGdsb2JhbCByaW5nIGJ1ZmZlciAoZGUpaW5pdCBtZXRob2RzDQogICAgPiANCiAg
ICA+ICBsaWIvdWttcGkvQ29uZmlnLnVrICAgICAgICAgfCAgMjMgKystDQogICAgPiAgbGliL3Vr
bXBpL01ha2VmaWxlLnVrICAgICAgIHwgICAxICsNCiAgICA+ICBsaWIvdWttcGkvZXhwb3J0c3lt
cy51ayAgICAgfCAgIDMgKw0KICAgID4gIGxpYi91a21waS9pbmNsdWRlL3VrL3JpbmcuaCB8IDQ3
NCArKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKw0KICAgID4gIGxp
Yi91a21waS9yaW5nLmMgICAgICAgICAgICB8ICA4NyArKysrKysrKw0KICAgID4gIDUgZmlsZXMg
Y2hhbmdlZCwgNTg3IGluc2VydGlvbnMoKyksIDEgZGVsZXRpb24oLSkNCiAgICA+ICBjcmVhdGUg
bW9kZSAxMDA2NDQgbGliL3VrbXBpL2luY2x1ZGUvdWsvcmluZy5oDQogICAgPiAgY3JlYXRlIG1v
ZGUgMTAwNjQ0IGxpYi91a21waS9yaW5nLmMNCiAgICA+IA0KDQo=


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 07:28:05 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 07:28:05 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxmh0-0004mN-QO; Tue, 21 Jul 2020 07:28:02 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=NVI3=BA=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jxmgz-0004mI-1v
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 07:28:01 +0000
X-Inumbo-ID: b333a2aa-cb23-11ea-a08e-12813bfff9fa
Received: from mx.upb.ro (unknown [141.85.13.200])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id b333a2aa-cb23-11ea-a08e-12813bfff9fa;
 Tue, 21 Jul 2020 07:27:58 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 7D5A6B5619E5;
 Tue, 21 Jul 2020 10:27:57 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id SNMEBhlOYx-v; Tue, 21 Jul 2020 10:27:54 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id A0D8EB561CC5;
 Tue, 21 Jul 2020 10:27:54 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id Hp_citEfh0I7; Tue, 21 Jul 2020 10:27:54 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id 395D3B5619E5;
 Tue, 21 Jul 2020 10:27:54 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH 0/5] Introduce Ring Buffer Implementation
To: "Jung, Alexander" <a.jung@lancaster.ac.uk>,
 "minios-devel@lists.xen.org" <minios-devel@lists.xen.org>
References: <20200720164015.4715-1-a.jung@lancs.ac.uk>
 <e80d91f8-b20f-69ee-2955-1146cd76181a@cs.pub.ro>
 <EFB9FD19-4C55-4F66-91F3-09A41E1AA134@lancaster.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <cf7002ba-d88a-bf1d-8937-ddab7c42c3aa@cs.pub.ro>
Date: Tue, 21 Jul 2020 10:27:53 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <EFB9FD19-4C55-4F66-91F3-09A41E1AA134@lancaster.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: quoted-printable
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

For both ukalloc and uksched we used an OOP approach:
- ukalloc is a base class extended by ukallocbuddy lib
- uksched is a base class extended by ukschedcoop lib

Following the same approach it's clear that an mp_ring lib, let's say,
would be a lib of its own. Regarding your comment that mbox is another
message passing implementation, that's true but it should be a lib of
its own on the same level as ring.

Another thing - what if I want to add my own mbox implementation but I
want to use your ring implementation? In that case, along with my mbox
lib I would also have to enable ukmpi (for your ring) which would also
contain the mbox legacy implementation. And viceversa if I implement a
new ring and use the mbox legacy implementation.

The safest design principle in this case would be a classic one (as
always): a lib should do just one thing and one thing only.


Cheers,
Costin


On 7/21/20 12:52 AM, Jung, Alexander wrote:
> Hi Costin,
>=20
> For this version, I simply chose to introduce it into the ukmpi library=
 since=20
> it adopts a similar trait to mbox, which is the current inhabitant of t=
he=20
> microlibrary.  Mbox is another "simple message passing" implementation =
and, for=20
> me, along with the offline conversation I had with Simon (cc'd), it mad=
e sense=20
> to include it here as an additional provision of the microlibrary itsel=
f. =20
>=20
> I think your argument is fair in that it can exist as its own library: =
simply=20
> as `ukring`.  At this point, it is simple a decision w.r.t. whether the=
 library=20
> constitutes creating enough additional options that would degrade the q=
uality=20
> of ukmpi itself.  Particulary, you refer to additional options which wi=
ll be=20
> brought out of the implementation in the future.  For now, I do not see=
=20
> additional options which would surface themselves at present in the KCo=
nfig=20
> option menu.  The decision is ultimately whether these options arise fr=
om=20
> implementation-specific requirements, in the case of, for instance, mp_=
ring.{c,
> h} from FreeBSD which is the ring buffer implementation for the network=
ing=20
> stack (that it is to say, "would this be part of `ukring` or it's own l=
ibrary?")
>=20
> One thing to note is that the ring implementation, along with mbox, are=
 not=20
> POSIX, and so mbox and ring's "exportsyms" do not share similar method=20
> standardization.  This, along with the fact that they are Unikraft-cent=
ric/-core=20
> and namespaced functions mean as internal communication mechanism its p=
lacement=20
> is somewhat arbitrary.
>=20
> What do you think?
>=20
> Thanks,
>=20
> Alexander
>=20
>=20
> =EF=BB=BFOn 20.07.20, 22:55, "Minios-devel on behalf of Costin Lupu" <m=
inios-devel-bounces@lists.xenproject.org on behalf of costin.lupu@cs.pub.=
ro> wrote:
>=20
>     Hi Alexander,
>=20
>     I have a curiosity. Why don't you put this ring implementation in a
>     library of its own, e.g. ukring or smth? I thought that library
>     granularity was one of the strong points of Unikraft. Besides, this=
 ring
>     implementation may be subject to more configuration options in the
>     future which would complicate the ukmpi configuration space.
>=20
>     Cheers,
>     Costin
>=20
>     On 7/20/20 7:40 PM, Alexander Jung wrote:
>     > From: Alexander Jung <alexander.jung@neclab.eu>
>     >=20
>     > This series introduces a port of FreeBSD's buf_ring.{h,c} impleme=
ntation for use
>     > within Unikraft.  This simple ring buffer can be used for message=
 passing in
>     > queues, for example within a AF_UNIX socket implementation betwee=
n two=20
>     > threads.  The implementation is therefore thread safe and provide=
s a generic=20
>     > data field which is initialized to the desired ring buffer length=
.
>     >=20
>     > The implementation is provided within ukmpi as a new option, LIBU=
KMPI_RING,=20
>     > which exposes the following new methods:
>     >=20
>     >  - uk_ring_alloc
>     >  - uk_ring_free
>     >  - uk_ring_enqueue
>     >  - uk_ring_dequeue
>     >  - uk_ring_dequeue_single
>     >  - uk_ring_advance_single
>     >  - uk_ring_putback_single
>     >  - uk_ring_peek
>     >  - uk_ring_peek_clear_single
>     >  - uk_ring_full
>     >  - uk_ring_empty
>     >  - uk_ring_count
>     >=20
>     > The port is currently limited, with no support for reading atomic=
 values from
>     > ARM{32,64} CPU registers (described in the comments inline).  As =
a result, use=20
>     > of the ring buffer implementation is untested on ARM.
>     >=20
>     > Alexander Jung (5):
>     >   lib/ukmpi: Introduce simple ring interface KConfig option
>     >   lib/ukmpi: Initial port of FreeBSD's buf_ring.h
>     >   lib/ukmpi: Provide ring buffer allocation and free methods
>     >   lib/ukmpi: Include ring buffer into Unikraft build process
>     >   lib/ukmpi: Export the global ring buffer (de)init methods
>     >=20
>     >  lib/ukmpi/Config.uk         |  23 ++-
>     >  lib/ukmpi/Makefile.uk       |   1 +
>     >  lib/ukmpi/exportsyms.uk     |   3 +
>     >  lib/ukmpi/include/uk/ring.h | 474 ++++++++++++++++++++++++++++++=
++++++++++++++
>     >  lib/ukmpi/ring.c            |  87 ++++++++
>     >  5 files changed, 587 insertions(+), 1 deletion(-)
>     >  create mode 100644 lib/ukmpi/include/uk/ring.h
>     >  create mode 100644 lib/ukmpi/ring.c
>     >=20
>=20


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 08:44:20 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 08:44:20 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxnso-0003YK-1K; Tue, 21 Jul 2020 08:44:18 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=yM2V=BA=lancaster.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxnsn-0003YF-3z
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 08:44:17 +0000
X-Inumbo-ID: 5a205360-cb2e-11ea-84f8-bc764e2007e4
Received: from GBR01-LO2-obe.outbound.protection.outlook.com (unknown
 [40.107.10.91]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 5a205360-cb2e-11ea-84f8-bc764e2007e4;
 Tue, 21 Jul 2020 08:44:13 +0000 (UTC)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=oNjsXKx2BVOeKvSv+EFV2VppFhLNpZEqWqv5pBD0d7tYueSyfbiaJlMqRwFB2H/B9bCmGa9hfM4JPIWSxvujrXZxIjxzKhhVkSl1bzsh0dxMjooy6jJ9QJG4htx4M63SBJ4+dMvED3ah4uXeO7ZiqhoR351GRqdGCBxl+VrrpmqAPcg4zbOw0nY/aflinHlDW0n283BBPtMdSvrzsNSbKVv+UIlIyHbz5Mefvruc4DTJf+jQyK5fBSVvdz5dVp/2kVyeXPJcoRbVLhe2BtZbA+NLbIc27eD8+PjZXjONNOLOrkY9gUVGM3UrcIPeUxbLnLNKQ2Hs+KwlxEzAWNERjA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; 
 s=arcselector9901;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=+Uem5aiJVjobFKgKRK2HpRUXeBjYUl+nQVhOdv97NCk=;
 b=GtCkkox1KQdXeiwUDhnfkSfhrS0+rJGTp5Eqj2Ff9noQkitDQFnNL0lLmLh7/dRSEfcQfdNQNkG8pac+X+8k7zLzxReHebjRDRn3gH1HWnJXdYPQj2FPoxCVK7aGMPpLUTlXnbuhN03E5O1wpKrCEuJeKbFYyUAzQ/jBnn3LyxcBQQH9iEx/VgQ9n62Cl7PXIM39pmnXQWr03+hWg8CQrbVV4jIC1K1EUKJ8rhgF9k8wfvJ7+diX22gSe0jmR42q6JZAUDKUEqDhJ9xYsTnol98nyONZDsOLeP9bvrSb4sis+xsBpVAJfrQ71VtJL6uh4wzJghVcDYg21697Fpgvtg==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
 smtp.mailfrom=lancaster.ac.uk; dmarc=pass action=none
 header.from=lancaster.ac.uk; dkim=pass header.d=lancaster.ac.uk; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=livelancsac.onmicrosoft.com; s=selector2-livelancsac-onmicrosoft-com;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=+Uem5aiJVjobFKgKRK2HpRUXeBjYUl+nQVhOdv97NCk=;
 b=m+hUjyhMh1rMaprOTs72UeK6BWvp0dLUOxSiyAOHwG+MtjrhEh7fXQVUsCXLx9j01otDn4sLURZDKX5X15GYLJtdQMBppxTYH+K1qDMg4r+vXQbAoWtwlTUIBASPZ53Moh61we31eX6Pfnin0696rh3NsfSQmc6ipiuikO+VmcY=
Received: from CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM (2603:10a6:401:17::15)
 by CWLP265MB1316.GBRP265.PROD.OUTLOOK.COM (2603:10a6:401:26::16) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 21 Jul
 2020 08:44:11 +0000
Received: from CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM
 ([fe80::fcde:79b:21d6:5203]) by CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM
 ([fe80::fcde:79b:21d6:5203%4]) with mapi id 15.20.3195.026; Tue, 21 Jul 2020
 08:44:11 +0000
From: "Jung, Alexander" <a.jung@lancaster.ac.uk>
To: Costin Lupu <costin.lupu@cs.pub.ro>, "minios-devel@lists.xen.org"
 <minios-devel@lists.xen.org>
Subject: Re: [UNIKRAFT PATCH 0/5] Introduce Ring Buffer Implementation
Thread-Topic: [UNIKRAFT PATCH 0/5] Introduce Ring Buffer Implementation
Thread-Index: AQHWXzsb9TW/InumEEWk+XqwluITNw==
Date: Tue, 21 Jul 2020 08:44:11 +0000
Message-ID: <AF719A28-04B9-481E-B52F-B5A34523BB10@lancaster.ac.uk>
References: <20200720164015.4715-1-a.jung@lancs.ac.uk>
 <e80d91f8-b20f-69ee-2955-1146cd76181a@cs.pub.ro>
 <EFB9FD19-4C55-4F66-91F3-09A41E1AA134@lancaster.ac.uk>
 <cf7002ba-d88a-bf1d-8937-ddab7c42c3aa@cs.pub.ro>
In-Reply-To: <cf7002ba-d88a-bf1d-8937-ddab7c42c3aa@cs.pub.ro>
Accept-Language: en-GB, en-US
Content-Language: en-GB
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
user-agent: Microsoft-MacOutlook/16.38.20061401
authentication-results: cs.pub.ro; dkim=none (message not signed)
 header.d=none;cs.pub.ro; dmarc=none action=none header.from=lancaster.ac.uk;
x-originating-ip: [77.182.149.243]
x-ms-publictraffictype: Email
x-ms-office365-filtering-correlation-id: e6c6418f-b538-4e59-bf49-08d82d523da6
x-ms-traffictypediagnostic: CWLP265MB1316:
x-microsoft-antispam-prvs: <CWLP265MB1316123BCF0C19B150E9771FCE780@CWLP265MB1316.GBRP265.PROD.OUTLOOK.COM>
x-ms-oob-tlc-oobclassifiers: OLM:9508;
x-ms-exchange-senderadcheck: 1
x-microsoft-antispam: BCL:0;
x-microsoft-antispam-message-info: PSsA6SSs4ojjH8JZQ3E5iyHIq6ikTX9DeOb2jJlfGNO+N/yB/q3VFpHCVm4I3MoFFw7zntQJGepFDsYwWtD9bgUI/jA2PbnMqjqu6hI3EOo3a02pdwBcK0W9RZABkOfRwC2FXbZ2cWwEjEEPk8jqkkMKF9cn5Z8+e7CE87d+L3dLwNHDZ4DWA7xp8mnqb5YpWIUiWT4vky8Y8G0kC2Qbj08BalVeuGBeG3hGetafWYyULLu1mMnQYzGJxWiqncgzJ614KAxrSnhYlNgY7ybqmqp2sYrBDHmSOh6Vy4JmIxV8SfAX//zi7WTnczq9CdqW4bsCqMsqIZi8HLjXjbSZRQ==
x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
 IPV:NLI; SFV:NSPM; H:CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM; PTR:; CAT:NONE;
 SFTY:;
 SFS:(4636009)(376002)(346002)(366004)(39860400002)(136003)(396003)(76116006)(66446008)(66476007)(64756008)(86362001)(66946007)(66556008)(6512007)(478600001)(91956017)(71200400001)(5660300002)(36756003)(33656002)(54906003)(110136005)(83380400001)(8936002)(2616005)(6486002)(6506007)(53546011)(786003)(4326008)(8676002)(2906002)(26005)(186003)(316002);
 DIR:OUT; SFP:1102; 
x-ms-exchange-antispam-messagedata: TTnGTPe/5gSIMLOw9DSAHHGbTU1CI49mwCwFrW4WgvuP+pNPuzGoSZGSWOyEEF75i6165qGEgRA69kECpSa5C411UyaHU5udTBASkdDw/kiuWrUvlIgymKyA9eJ26LCjw+ADS/2lLQCHUsBx6UZ2IN1YWMoTTASn7OOn2T7IahyZiLjiTbN2MAVUuUeAp19RwVZ4xMffXXlYV4MkH7xgihGw6fQzV8rRXj1EnEqBn6Fr1RIebP5D+5vTGRZy+oJC5yzK91ESegBi4LGIpPuhhKAMfZpXEgzVwnzLLktXErhp2+RIT7dcvbZMqsmSNZp/U/3Y3V6RiIVLmFTxmxy2KmvqDAFw6McVtprVVHmibxfJh7UTMCUFn82xD0B3/uQ42InFqErNu+ogcGirSvwrf3Q4GxOYjeBZTJyTbD9LLNA8+yVlCeFgH43U9Bcpib0UP/2ORf2AQkP3jYyu1BcESguFl3cJarjyVV9wKnZHUuVbrISjBaEB6XpVQzjRex6H
x-ms-exchange-transport-forked: True
Content-Type: text/plain; charset="utf-8"
Content-ID: <E3C4105BAE3AF94C8F23E42F178AEB7D@GBRP265.PROD.OUTLOOK.COM>
Content-Transfer-Encoding: base64
MIME-Version: 1.0
X-OriginatorOrg: lancaster.ac.uk
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM
X-MS-Exchange-CrossTenant-Network-Message-Id: e6c6418f-b538-4e59-bf49-08d82d523da6
X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Jul 2020 08:44:11.7161 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 9c9bcd11-977a-4e9c-a9a0-bc734090164a
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: RQSBom7wju5EQLKmOF9oEQZlSWLFdpumsEpjqWH7VButgaGMiskiscBO0AnQOALDAcByp8YCWkwPMcTUMnZt5w==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWLP265MB1316
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

SGkgQ29zdGluLA0KDQpZb3VyIGFyZ3VtZW50IGlzIHNvdW5kLiAgSSdsbCBiZSBzdXJlIHRvIHB1
c2ggdGhlIHJpbmcgYnVmZmVyIGltcGxlbWVudGF0aW9uIA0KaW50byBpdHMgb3duIG1pY3JvbGli
cmFyeSBvbiB0aGUgdjIgb25jZSBpdCBoYXMgYmVlbiByZXZpZXdlZC4NCg0KVGhhbmtzLA0KDQpB
bGV4YW5kZXINCg0KDQrvu79PbiAyMS4wNy4yMCwgMDk6MzAsICJNaW5pb3MtZGV2ZWwgb24gYmVo
YWxmIG9mIENvc3RpbiBMdXB1IiA8bWluaW9zLWRldmVsLWJvdW5jZXNAbGlzdHMueGVucHJvamVj
dC5vcmcgb24gYmVoYWxmIG9mIGNvc3Rpbi5sdXB1QGNzLnB1Yi5ybz4gd3JvdGU6DQoNCiAgICBI
aSBBbGV4YW5kZXIsDQoNCiAgICBGb3IgYm90aCB1a2FsbG9jIGFuZCB1a3NjaGVkIHdlIHVzZWQg
YW4gT09QIGFwcHJvYWNoOg0KICAgIC0gdWthbGxvYyBpcyBhIGJhc2UgY2xhc3MgZXh0ZW5kZWQg
YnkgdWthbGxvY2J1ZGR5IGxpYg0KICAgIC0gdWtzY2hlZCBpcyBhIGJhc2UgY2xhc3MgZXh0ZW5k
ZWQgYnkgdWtzY2hlZGNvb3AgbGliDQoNCiAgICBGb2xsb3dpbmcgdGhlIHNhbWUgYXBwcm9hY2gg
aXQncyBjbGVhciB0aGF0IGFuIG1wX3JpbmcgbGliLCBsZXQncyBzYXksDQogICAgd291bGQgYmUg
YSBsaWIgb2YgaXRzIG93bi4gUmVnYXJkaW5nIHlvdXIgY29tbWVudCB0aGF0IG1ib3ggaXMgYW5v
dGhlcg0KICAgIG1lc3NhZ2UgcGFzc2luZyBpbXBsZW1lbnRhdGlvbiwgdGhhdCdzIHRydWUgYnV0
IGl0IHNob3VsZCBiZSBhIGxpYiBvZg0KICAgIGl0cyBvd24gb24gdGhlIHNhbWUgbGV2ZWwgYXMg
cmluZy4NCg0KICAgIEFub3RoZXIgdGhpbmcgLSB3aGF0IGlmIEkgd2FudCB0byBhZGQgbXkgb3du
IG1ib3ggaW1wbGVtZW50YXRpb24gYnV0IEkNCiAgICB3YW50IHRvIHVzZSB5b3VyIHJpbmcgaW1w
bGVtZW50YXRpb24/IEluIHRoYXQgY2FzZSwgYWxvbmcgd2l0aCBteSBtYm94DQogICAgbGliIEkg
d291bGQgYWxzbyBoYXZlIHRvIGVuYWJsZSB1a21waSAoZm9yIHlvdXIgcmluZykgd2hpY2ggd291
bGQgYWxzbw0KICAgIGNvbnRhaW4gdGhlIG1ib3ggbGVnYWN5IGltcGxlbWVudGF0aW9uLiBBbmQg
dmljZXZlcnNhIGlmIEkgaW1wbGVtZW50IGENCiAgICBuZXcgcmluZyBhbmQgdXNlIHRoZSBtYm94
IGxlZ2FjeSBpbXBsZW1lbnRhdGlvbi4NCg0KICAgIFRoZSBzYWZlc3QgZGVzaWduIHByaW5jaXBs
ZSBpbiB0aGlzIGNhc2Ugd291bGQgYmUgYSBjbGFzc2ljIG9uZSAoYXMNCiAgICBhbHdheXMpOiBh
IGxpYiBzaG91bGQgZG8ganVzdCBvbmUgdGhpbmcgYW5kIG9uZSB0aGluZyBvbmx5Lg0KDQoNCiAg
ICBDaGVlcnMsDQogICAgQ29zdGluDQoNCg0KICAgIE9uIDcvMjEvMjAgMTI6NTIgQU0sIEp1bmcs
IEFsZXhhbmRlciB3cm90ZToNCiAgICA+IEhpIENvc3RpbiwNCiAgICA+IA0KICAgID4gRm9yIHRo
aXMgdmVyc2lvbiwgSSBzaW1wbHkgY2hvc2UgdG8gaW50cm9kdWNlIGl0IGludG8gdGhlIHVrbXBp
IGxpYnJhcnkgc2luY2UgDQogICAgPiBpdCBhZG9wdHMgYSBzaW1pbGFyIHRyYWl0IHRvIG1ib3gs
IHdoaWNoIGlzIHRoZSBjdXJyZW50IGluaGFiaXRhbnQgb2YgdGhlIA0KICAgID4gbWljcm9saWJy
YXJ5LiAgTWJveCBpcyBhbm90aGVyICJzaW1wbGUgbWVzc2FnZSBwYXNzaW5nIiBpbXBsZW1lbnRh
dGlvbiBhbmQsIGZvciANCiAgICA+IG1lLCBhbG9uZyB3aXRoIHRoZSBvZmZsaW5lIGNvbnZlcnNh
dGlvbiBJIGhhZCB3aXRoIFNpbW9uIChjYydkKSwgaXQgbWFkZSBzZW5zZSANCiAgICA+IHRvIGlu
Y2x1ZGUgaXQgaGVyZSBhcyBhbiBhZGRpdGlvbmFsIHByb3Zpc2lvbiBvZiB0aGUgbWljcm9saWJy
YXJ5IGl0c2VsZi4gIA0KICAgID4gDQogICAgPiBJIHRoaW5rIHlvdXIgYXJndW1lbnQgaXMgZmFp
ciBpbiB0aGF0IGl0IGNhbiBleGlzdCBhcyBpdHMgb3duIGxpYnJhcnk6IHNpbXBseSANCiAgICA+
IGFzIGB1a3JpbmdgLiAgQXQgdGhpcyBwb2ludCwgaXQgaXMgc2ltcGxlIGEgZGVjaXNpb24gdy5y
LnQuIHdoZXRoZXIgdGhlIGxpYnJhcnkgDQogICAgPiBjb25zdGl0dXRlcyBjcmVhdGluZyBlbm91
Z2ggYWRkaXRpb25hbCBvcHRpb25zIHRoYXQgd291bGQgZGVncmFkZSB0aGUgcXVhbGl0eSANCiAg
ICA+IG9mIHVrbXBpIGl0c2VsZi4gIFBhcnRpY3VsYXJ5LCB5b3UgcmVmZXIgdG8gYWRkaXRpb25h
bCBvcHRpb25zIHdoaWNoIHdpbGwgYmUgDQogICAgPiBicm91Z2h0IG91dCBvZiB0aGUgaW1wbGVt
ZW50YXRpb24gaW4gdGhlIGZ1dHVyZS4gIEZvciBub3csIEkgZG8gbm90IHNlZSANCiAgICA+IGFk
ZGl0aW9uYWwgb3B0aW9ucyB3aGljaCB3b3VsZCBzdXJmYWNlIHRoZW1zZWx2ZXMgYXQgcHJlc2Vu
dCBpbiB0aGUgS0NvbmZpZyANCiAgICA+IG9wdGlvbiBtZW51LiAgVGhlIGRlY2lzaW9uIGlzIHVs
dGltYXRlbHkgd2hldGhlciB0aGVzZSBvcHRpb25zIGFyaXNlIGZyb20gDQogICAgPiBpbXBsZW1l
bnRhdGlvbi1zcGVjaWZpYyByZXF1aXJlbWVudHMsIGluIHRoZSBjYXNlIG9mLCBmb3IgaW5zdGFu
Y2UsIG1wX3Jpbmcue2MsDQogICAgPiBofSBmcm9tIEZyZWVCU0Qgd2hpY2ggaXMgdGhlIHJpbmcg
YnVmZmVyIGltcGxlbWVudGF0aW9uIGZvciB0aGUgbmV0d29ya2luZyANCiAgICA+IHN0YWNrICh0
aGF0IGl0IGlzIHRvIHNheSwgIndvdWxkIHRoaXMgYmUgcGFydCBvZiBgdWtyaW5nYCBvciBpdCdz
IG93biBsaWJyYXJ5PyIpDQogICAgPiANCiAgICA+IE9uZSB0aGluZyB0byBub3RlIGlzIHRoYXQg
dGhlIHJpbmcgaW1wbGVtZW50YXRpb24sIGFsb25nIHdpdGggbWJveCwgYXJlIG5vdCANCiAgICA+
IFBPU0lYLCBhbmQgc28gbWJveCBhbmQgcmluZydzICJleHBvcnRzeW1zIiBkbyBub3Qgc2hhcmUg
c2ltaWxhciBtZXRob2QgDQogICAgPiBzdGFuZGFyZGl6YXRpb24uICBUaGlzLCBhbG9uZyB3aXRo
IHRoZSBmYWN0IHRoYXQgdGhleSBhcmUgVW5pa3JhZnQtY2VudHJpYy8tY29yZSANCiAgICA+IGFu
ZCBuYW1lc3BhY2VkIGZ1bmN0aW9ucyBtZWFuIGFzIGludGVybmFsIGNvbW11bmljYXRpb24gbWVj
aGFuaXNtIGl0cyBwbGFjZW1lbnQgDQogICAgPiBpcyBzb21ld2hhdCBhcmJpdHJhcnkuDQogICAg
PiANCiAgICA+IFdoYXQgZG8geW91IHRoaW5rPw0KICAgID4gDQogICAgPiBUaGFua3MsDQogICAg
PiANCiAgICA+IEFsZXhhbmRlcg0KICAgID4gDQogICAgPiANCiAgICA+IO+7v09uIDIwLjA3LjIw
LCAyMjo1NSwgIk1pbmlvcy1kZXZlbCBvbiBiZWhhbGYgb2YgQ29zdGluIEx1cHUiIDxtaW5pb3Mt
ZGV2ZWwtYm91bmNlc0BsaXN0cy54ZW5wcm9qZWN0Lm9yZyBvbiBiZWhhbGYgb2YgY29zdGluLmx1
cHVAY3MucHViLnJvPiB3cm90ZToNCiAgICA+IA0KICAgID4gICAgIEhpIEFsZXhhbmRlciwNCiAg
ICA+IA0KICAgID4gICAgIEkgaGF2ZSBhIGN1cmlvc2l0eS4gV2h5IGRvbid0IHlvdSBwdXQgdGhp
cyByaW5nIGltcGxlbWVudGF0aW9uIGluIGENCiAgICA+ICAgICBsaWJyYXJ5IG9mIGl0cyBvd24s
IGUuZy4gdWtyaW5nIG9yIHNtdGg/IEkgdGhvdWdodCB0aGF0IGxpYnJhcnkNCiAgICA+ICAgICBn
cmFudWxhcml0eSB3YXMgb25lIG9mIHRoZSBzdHJvbmcgcG9pbnRzIG9mIFVuaWtyYWZ0LiBCZXNp
ZGVzLCB0aGlzIHJpbmcNCiAgICA+ICAgICBpbXBsZW1lbnRhdGlvbiBtYXkgYmUgc3ViamVjdCB0
byBtb3JlIGNvbmZpZ3VyYXRpb24gb3B0aW9ucyBpbiB0aGUNCiAgICA+ICAgICBmdXR1cmUgd2hp
Y2ggd291bGQgY29tcGxpY2F0ZSB0aGUgdWttcGkgY29uZmlndXJhdGlvbiBzcGFjZS4NCiAgICA+
IA0KICAgID4gICAgIENoZWVycywNCiAgICA+ICAgICBDb3N0aW4NCiAgICA+IA0KICAgID4gICAg
IE9uIDcvMjAvMjAgNzo0MCBQTSwgQWxleGFuZGVyIEp1bmcgd3JvdGU6DQogICAgPiAgICAgPiBG
cm9tOiBBbGV4YW5kZXIgSnVuZyA8YWxleGFuZGVyLmp1bmdAbmVjbGFiLmV1Pg0KICAgID4gICAg
ID4gDQogICAgPiAgICAgPiBUaGlzIHNlcmllcyBpbnRyb2R1Y2VzIGEgcG9ydCBvZiBGcmVlQlNE
J3MgYnVmX3Jpbmcue2gsY30gaW1wbGVtZW50YXRpb24gZm9yIHVzZQ0KICAgID4gICAgID4gd2l0
aGluIFVuaWtyYWZ0LiAgVGhpcyBzaW1wbGUgcmluZyBidWZmZXIgY2FuIGJlIHVzZWQgZm9yIG1l
c3NhZ2UgcGFzc2luZyBpbg0KICAgID4gICAgID4gcXVldWVzLCBmb3IgZXhhbXBsZSB3aXRoaW4g
YSBBRl9VTklYIHNvY2tldCBpbXBsZW1lbnRhdGlvbiBiZXR3ZWVuIHR3byANCiAgICA+ICAgICA+
IHRocmVhZHMuICBUaGUgaW1wbGVtZW50YXRpb24gaXMgdGhlcmVmb3JlIHRocmVhZCBzYWZlIGFu
ZCBwcm92aWRlcyBhIGdlbmVyaWMgDQogICAgPiAgICAgPiBkYXRhIGZpZWxkIHdoaWNoIGlzIGlu
aXRpYWxpemVkIHRvIHRoZSBkZXNpcmVkIHJpbmcgYnVmZmVyIGxlbmd0aC4NCiAgICA+ICAgICA+
IA0KICAgID4gICAgID4gVGhlIGltcGxlbWVudGF0aW9uIGlzIHByb3ZpZGVkIHdpdGhpbiB1a21w
aSBhcyBhIG5ldyBvcHRpb24sIExJQlVLTVBJX1JJTkcsIA0KICAgID4gICAgID4gd2hpY2ggZXhw
b3NlcyB0aGUgZm9sbG93aW5nIG5ldyBtZXRob2RzOg0KICAgID4gICAgID4gDQogICAgPiAgICAg
PiAgLSB1a19yaW5nX2FsbG9jDQogICAgPiAgICAgPiAgLSB1a19yaW5nX2ZyZWUNCiAgICA+ICAg
ICA+ICAtIHVrX3JpbmdfZW5xdWV1ZQ0KICAgID4gICAgID4gIC0gdWtfcmluZ19kZXF1ZXVlDQog
ICAgPiAgICAgPiAgLSB1a19yaW5nX2RlcXVldWVfc2luZ2xlDQogICAgPiAgICAgPiAgLSB1a19y
aW5nX2FkdmFuY2Vfc2luZ2xlDQogICAgPiAgICAgPiAgLSB1a19yaW5nX3B1dGJhY2tfc2luZ2xl
DQogICAgPiAgICAgPiAgLSB1a19yaW5nX3BlZWsNCiAgICA+ICAgICA+ICAtIHVrX3JpbmdfcGVl
a19jbGVhcl9zaW5nbGUNCiAgICA+ICAgICA+ICAtIHVrX3JpbmdfZnVsbA0KICAgID4gICAgID4g
IC0gdWtfcmluZ19lbXB0eQ0KICAgID4gICAgID4gIC0gdWtfcmluZ19jb3VudA0KICAgID4gICAg
ID4gDQogICAgPiAgICAgPiBUaGUgcG9ydCBpcyBjdXJyZW50bHkgbGltaXRlZCwgd2l0aCBubyBz
dXBwb3J0IGZvciByZWFkaW5nIGF0b21pYyB2YWx1ZXMgZnJvbQ0KICAgID4gICAgID4gQVJNezMy
LDY0fSBDUFUgcmVnaXN0ZXJzIChkZXNjcmliZWQgaW4gdGhlIGNvbW1lbnRzIGlubGluZSkuICBB
cyBhIHJlc3VsdCwgdXNlIA0KICAgID4gICAgID4gb2YgdGhlIHJpbmcgYnVmZmVyIGltcGxlbWVu
dGF0aW9uIGlzIHVudGVzdGVkIG9uIEFSTS4NCiAgICA+ICAgICA+IA0KICAgID4gICAgID4gQWxl
eGFuZGVyIEp1bmcgKDUpOg0KICAgID4gICAgID4gICBsaWIvdWttcGk6IEludHJvZHVjZSBzaW1w
bGUgcmluZyBpbnRlcmZhY2UgS0NvbmZpZyBvcHRpb24NCiAgICA+ICAgICA+ICAgbGliL3VrbXBp
OiBJbml0aWFsIHBvcnQgb2YgRnJlZUJTRCdzIGJ1Zl9yaW5nLmgNCiAgICA+ICAgICA+ICAgbGli
L3VrbXBpOiBQcm92aWRlIHJpbmcgYnVmZmVyIGFsbG9jYXRpb24gYW5kIGZyZWUgbWV0aG9kcw0K
ICAgID4gICAgID4gICBsaWIvdWttcGk6IEluY2x1ZGUgcmluZyBidWZmZXIgaW50byBVbmlrcmFm
dCBidWlsZCBwcm9jZXNzDQogICAgPiAgICAgPiAgIGxpYi91a21waTogRXhwb3J0IHRoZSBnbG9i
YWwgcmluZyBidWZmZXIgKGRlKWluaXQgbWV0aG9kcw0KICAgID4gICAgID4gDQogICAgPiAgICAg
PiAgbGliL3VrbXBpL0NvbmZpZy51ayAgICAgICAgIHwgIDIzICsrLQ0KICAgID4gICAgID4gIGxp
Yi91a21waS9NYWtlZmlsZS51ayAgICAgICB8ICAgMSArDQogICAgPiAgICAgPiAgbGliL3VrbXBp
L2V4cG9ydHN5bXMudWsgICAgIHwgICAzICsNCiAgICA+ICAgICA+ICBsaWIvdWttcGkvaW5jbHVk
ZS91ay9yaW5nLmggfCA0NzQgKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysr
KysrKysNCiAgICA+ICAgICA+ICBsaWIvdWttcGkvcmluZy5jICAgICAgICAgICAgfCAgODcgKysr
KysrKysNCiAgICA+ICAgICA+ICA1IGZpbGVzIGNoYW5nZWQsIDU4NyBpbnNlcnRpb25zKCspLCAx
IGRlbGV0aW9uKC0pDQogICAgPiAgICAgPiAgY3JlYXRlIG1vZGUgMTAwNjQ0IGxpYi91a21waS9p
bmNsdWRlL3VrL3JpbmcuaA0KICAgID4gICAgID4gIGNyZWF0ZSBtb2RlIDEwMDY0NCBsaWIvdWtt
cGkvcmluZy5jDQogICAgPiAgICAgPiANCiAgICA+IA0KDQo=


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 08:51:10 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 08:51:10 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxnzR-0004K2-KN; Tue, 21 Jul 2020 08:51:09 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=zkTt=BA=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jxnzQ-0004Jo-9W
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 08:51:08 +0000
X-Inumbo-ID: 4e2463c0-cb2f-11ea-a09b-12813bfff9fa
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 4e2463c0-cb2f-11ea-a09b-12813bfff9fa;
 Tue, 21 Jul 2020 08:51:03 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 02527103BAA;
 Tue, 21 Jul 2020 10:51:02 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id DmIQo7lD0FPR; Tue, 21 Jul 2020 10:51:01 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id BA5A410187E
 for <minios-devel@lists.xen.org>; Tue, 21 Jul 2020 10:51:01 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 21 Jul
 2020 10:51:00 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v4 0/3] Poll based receive based on uk_netdev features
Date: Tue, 21 Jul 2020 10:50:46 +0200
Message-ID: <1595321449-30403-1-git-send-email-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.7.4
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

uk_netdev_info provides a way to forward driver information to the network stack.
We extend the uk_netdev_info with the features field that allows the network stack
to perform a poll based received on those driver that do not support interrupt based
receive. The patch series is structured as follows:
- The uk_netdev structure allocates network stack scratch pad.
- The uk_netdev_info provides features field to fetch information on the feature supported
  on a driver.

Changes since v3:
- Enable secondary expansion for all library local variable

Changes since v2:
- Enable secondary expansion on the build system
- Decouple from the tap driver
- Add some more comments 

Change since v1:
- Select the max of the scratch size
- Rename from enabled to available for the features

Sharan Santhanam (3):
  build: Enable secondary expansion
  lib/uknetdev: Save nw_stack data in a netdevice
  lib/uknetdev: Get feature supported on uk_netdev

 Makefile                              |   3 +
 lib/uknetdev/Makefile.rules           |  17 ++++++
 lib/uknetdev/include/uk/netdev_core.h |  19 ++++++
 plat/drivers/virtio/virtio_net.c      |   1 +
 support/build/Makefile.rules          | 112 +++++++++++++++++-----------------
 5 files changed, 96 insertions(+), 56 deletions(-)
 create mode 100644 lib/uknetdev/Makefile.rules

-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 08:51:10 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 08:51:10 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxnzR-0004Jx-J6; Tue, 21 Jul 2020 08:51:09 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=zkTt=BA=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jxnzQ-0004Jn-5A
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 08:51:08 +0000
X-Inumbo-ID: 4fa7307e-cb2f-11ea-84fb-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4fa7307e-cb2f-11ea-84fb-bc764e2007e4;
 Tue, 21 Jul 2020 08:51:05 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 9DB4EF2010;
 Tue, 21 Jul 2020 10:51:04 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id IJkTHgyl3Cou; Tue, 21 Jul 2020 10:51:04 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 7841CF200F
 for <minios-devel@lists.xen.org>; Tue, 21 Jul 2020 10:51:02 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 21 Jul
 2020 10:51:01 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v4 1/3] build: Enable secondary expansion
Date: Tue, 21 Jul 2020 10:50:47 +0200
Message-ID: <1595321449-30403-2-git-send-email-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <1595321449-30403-1-git-send-email-sharan.santhanam@neclab.eu>
References: <1595321449-30403-1-git-send-email-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Enable second expansion of the make variables. The build variables
are expanded on execution of the Make rule.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 Makefile                     |   3 ++
 support/build/Makefile.rules | 112 +++++++++++++++++++++----------------------
 2 files changed, 59 insertions(+), 56 deletions(-)

diff --git a/Makefile b/Makefile
index be8fa8c..1f309b7 100644
--- a/Makefile
+++ b/Makefile
@@ -40,6 +40,9 @@ all:
 # Disable built-in rules
 .SUFFIXES:
 
+# Enable secondary expansion
+.SECONDEXPANSION:
+
 # Save running make version
 RUNNING_MAKE_VERSION := $(MAKE_VERSION)
 
diff --git a/support/build/Makefile.rules b/support/build/Makefile.rules
index 8c096fa..9a5963f 100644
--- a/support/build/Makefile.rules
+++ b/support/build/Makefile.rules
@@ -392,17 +392,17 @@ endef
 define buildrule_S_ =
 $(4): $(2) | prepare
 	$(call build_cmd_fixdep,AS,$(1),$(4),\
-		$(AS)  $(COMPFLAGS) $(COMPFLAGS-y) \
-		       $($(call vprefix_lib,$(1),COMPFLAGS)) $($(call vprefix_lib,$(1),COMPFLAGS-y)) \
-		       $(ASINCLUDES) $(ASINCLUDES-y) \
-		       $($(call vprefix_lib,$(1),ASINCLUDES)) $($(call vprefix_lib,$(1),ASINCLUDES-y)) \
-		       $($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
-		       $($(call vprefix_glb,$(3),ARCHFLAGS)) $($(call vprefix_glb,$(3),ARCHFLAGS-y)) \
-		       $(ASFLAGS) $(ASFLAGS-y) \
-		       $($(call vprefix_lib,$(1),ASFLAGS)) $($(call vprefix_lib,$(1),ASFLAGS-y)) \
-		       $($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
+		$(AS)  $$(COMPFLAGS) $$(COMPFLAGS-y) \
+		       $$($(call vprefix_lib,$(1),COMPFLAGS)) $$($(call vprefix_lib,$(1),COMPFLAGS-y)) \
+		       $$(ASINCLUDES) $$(ASINCLUDES-y) \
+		       $$($(call vprefix_lib,$(1),ASINCLUDES)) $$($(call vprefix_lib,$(1),ASINCLUDES-y)) \
+		       $$($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $$($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
+		       $$($(call vprefix_glb,$(3),ARCHFLAGS)) $$($(call vprefix_glb,$(3),ARCHFLAGS-y)) \
+		       $$(ASFLAGS) $$(ASFLAGS-y) \
+		       $$($(call vprefix_lib,$(1),ASFLAGS)) $$($(call vprefix_lib,$(1),ASFLAGS-y)) \
+		       $$($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $$($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
 		       $(5) \
-		       $(DBGFLAGS) $(DBGFLAGS-y) \
+		       $$(DBGFLAGS) $$(DBGFLAGS-y) \
 		       -D__LIBNAME__=$(1) -D__BASENAME__=$(notdir $(2)) $(if $(3),-D__VARIANT__=$(3)) \
 		       -c $(2) -o $(4) $(call depflags,$(4))
 	)
@@ -419,17 +419,17 @@ buildrule_sx = $(call buildrule_S_,$(1),$(2),$(3),$(4))
 define buildrule_s =
 $(4): $(2) | prepare
 	$(call build_cmd,AS,$(1),$(4),\
-		$(AS)  $(COMPFLAGS) $(COMPFLAGS-y) \
-		       $($(call vprefix_lib,$(1),COMPFLAGS)) $($(call vprefix_lib,$(1),COMPFLAGS-y)) \
-		       $(ASINCLUDES) $(ASINCLUDES-y) \
-		       $($(call vprefix_lib,$(1),ASINCLUDES)) $($(call vprefix_lib,$(1),ASINCLUDES-y)) \
-		       $($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
-		       $($(call vprefix_glb,$(3),ARCHFLAGS)) $($(call vprefix_glb,$(3),ARCHFLAGS-y)) \
-		       $(ASFLAGS) $(ASFLAGS-y) \
-		       $($(call vprefix_lib,$(1),ASFLAGS)) $($(call vprefix_lib,$(1),ASFLAGS-y)) \
-		       $($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
+		$(AS)  $$(COMPFLAGS) $$(COMPFLAGS-y) \
+		       $$($(call vprefix_lib,$(1),COMPFLAGS)) $$($(call vprefix_lib,$(1),COMPFLAGS-y)) \
+		       $$(ASINCLUDES) $$(ASINCLUDES-y) \
+		       $$($(call vprefix_lib,$(1),ASINCLUDES)) $$($(call vprefix_lib,$(1),ASINCLUDES-y)) \
+		       $$($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $$($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
+		       $$($(call vprefix_glb,$(3),ARCHFLAGS)) $$($(call vprefix_glb,$(3),ARCHFLAGS-y)) \
+		       $$(ASFLAGS) $$(ASFLAGS-y) \
+		       $$($(call vprefix_lib,$(1),ASFLAGS)) $$($(call vprefix_lib,$(1),ASFLAGS-y)) \
+		       $$($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $$($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
 		       $(5) \
-		       $(DBGFLAGS) $(DBGFLAGS-y) \
+		       $$(DBGFLAGS) $$(DBGFLAGS-y) \
 		       -D__LIBNAME__=$(1) -D__BASENAME__=$(notdir $(2)) $(if $(3),-D__VARIANT__=$(3)) \
 		       -c $(2) -o $(4)
 	)
@@ -444,17 +444,17 @@ endef
 define buildrule_c =
 $(4): $(2) | prepare
 	$(call build_cmd_fixdep,CC,$(1),$(4),\
-		$(CC)  $(COMPFLAGS) $(COMPFLAGS-y) \
-		       $($(call vprefix_lib,$(1),COMPFLAGS)) $($(call vprefix_lib,$(1),COMPFLAGS-y)) \
-		       $(CINCLUDES) $(CINCLUDES-y) \
-		       $($(call vprefix_lib,$(1),CINCLUDES)) $($(call vprefix_lib,$(1),CINCLUDES-y)) \
-		       $($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
-		       $($(call vprefix_glb,$(3),ARCHFLAGS)) $($(call vprefix_glb,$(3),ARCHFLAGS-y)) \
-		       $(CFLAGS) $(CFLAGS-y) \
-		       $($(call vprefix_lib,$(1),CFLAGS)) $($(call vprefix_lib,$(1),CFLAGS-y)) \
-		       $($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
+		$(CC)  $$(COMPFLAGS) $$(COMPFLAGS-y) \
+		       $$($(call vprefix_lib,$(1),COMPFLAGS)) $$($(call vprefix_lib,$(1),COMPFLAGS-y)) \
+		       $$(CINCLUDES) $$(CINCLUDES-y) \
+		       $$($(call vprefix_lib,$(1),CINCLUDES)) $$($(call vprefix_lib,$(1),CINCLUDES-y)) \
+		       $$($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $$($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
+		       $$($(call vprefix_glb,$(3),ARCHFLAGS)) $$($(call vprefix_glb,$(3),ARCHFLAGS-y)) \
+		       $$(CFLAGS) $$(CFLAGS-y) \
+		       $$($(call vprefix_lib,$(1),CFLAGS)) $$($(call vprefix_lib,$(1),CFLAGS-y)) \
+		       $$($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $$($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
 		       $(5) \
-		       $(DBGFLAGS) $(DBGFLAGS-y) \
+		       $$(DBGFLAGS) $$(DBGFLAGS-y) \
 		       -D__LIBNAME__=$(1) -D__BASENAME__=$(notdir $(2)) $(if $(3),-D__VARIANT__=$(3)) \
 		       -c $(2) -o $(4) $(call depflags,$(4))
 )
@@ -469,16 +469,16 @@ endef
 define buildrule_cxx =
 $(4): $(2) | prepare
 	$(call build_cmd_fixdep,CXX,$(1),$(4),\
-		$(CXX) $(COMPFLAGS) $(COMPFLAGS-y) \
-		       $(CXXINCLUDES) $(CXXINCLUDES-y) \
-		       $($(call vprefix_lib,$(1),CXXINCLUDES)) $($(call vprefix_lib,$(1),CXXINCLUDES-y)) \
-		       $($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
-		       $($(call vprefix_glb,$(3),ARCHFLAGS)) $($(call vprefix_glb,$(3),ARCHFLAGS-y)) \
-		       $(CXXFLAGS) $(CXXFLAGS-y) \
-		       $($(call vprefix_lib,$(1),CXXFLAGS)) $($(call vprefix_lib,$(1),CXXFLAGS-y)) \
-		       $($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
+		$(CXX) $$(COMPFLAGS) $$(COMPFLAGS-y) \
+		       $$(CXXINCLUDES) $$(CXXINCLUDES-y) \
+		       $$($(call vprefix_lib,$(1),CXXINCLUDES)) $$($(call vprefix_lib,$(1),CXXINCLUDES-y)) \
+		       $$($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $$($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
+		       $$($(call vprefix_glb,$(3),ARCHFLAGS)) $$($(call vprefix_glb,$(3),ARCHFLAGS-y)) \
+		       $$(CXXFLAGS) $$(CXXFLAGS-y) \
+		       $$($(call vprefix_lib,$(1),CXXFLAGS)) $$($(call vprefix_lib,$(1),CXXFLAGS-y)) \
+		       $$($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $$($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
 		       $(5) \
-		       $(DBGFLAGS) $(DBGFLAGS-y) \
+		       $$(DBGFLAGS) $$(DBGFLAGS-y) \
 		       -D__LIBNAME__=$(1) -D__BASENAME__=$(notdir $(2)) $(if $(3),-D__VARIANT__=$(3)) \
 		       -c $(2) -o $(4) $(call depflags,$(4))
 	)
@@ -501,16 +501,16 @@ buildrule_c$(plus)$(plus) = $(call buildrule_cxx,$(1),$(2),$(3),$(4))
 define buildrule_go =
 $(4): $(2) | prepare
 	$(call build_cmd,GOC,$(1),$(4),\
-		$(GOC) $(COMPFLAGS) $(COMPFLAGS-y) \
-		       $(GOCINCLUDES) $(GOCINCLUDES-y) \
-		       $($(call vprefix_lib,$(1),GOCINCLUDES)) $($(call vprefix_lib,$(1),GOCINCLUDES-y)) \
-		       $($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
-		       $($(call vprefix_glb,$(3),ARCHFLAGS)) $($(call vprefix_glb,$(3),ARCHFLAGS-y)) \
-		       $(GOCFLAGS) $(GOCFLAGS-y) \
-		       $($(call vprefix_lib,$(1),GOCFLAGS)) $($(call vprefix_lib,$(1),GOCFLAGS-y)) \
-		       $($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
+		$(GOC) $$(COMPFLAGS) $$(COMPFLAGS-y) \
+		       $$(GOCINCLUDES) $$(GOCINCLUDES-y) \
+		       $$($(call vprefix_lib,$(1),GOCINCLUDES)) $$($(call vprefix_lib,$(1),GOCINCLUDES-y)) \
+		       $$($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $$($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
+		       $$($(call vprefix_glb,$(3),ARCHFLAGS)) $$($(call vprefix_glb,$(3),ARCHFLAGS-y)) \
+		       $$(GOCFLAGS) $$(GOCFLAGS-y) \
+		       $$($(call vprefix_lib,$(1),GOCFLAGS)) $$($(call vprefix_lib,$(1),GOCFLAGS-y)) \
+		       $$($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $$($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
 		       $(5) \
-		       $(DBGFLAGS) $(DBGFLAGS-y) \
+		       $$(DBGFLAGS) $$(DBGFLAGS-y) \
 		       -D__LIBNAME__=$(1) -D__BASENAME__=$(notdir $(2)) $(if $(3),-D__VARIANT__=$(3)) \
 		       -c $(2) -o $(4) $(call depflags,$(4))
 	)
@@ -533,14 +533,14 @@ endef
 define buildrule_S_lds =
 $(4): $(2) | prepare
 	$(call build_cmd_fixdep,LDS,$(1),$(4),\
-		$(AS)  -E -P -x assembler-with-cpp $(COMPFLAGS) $(COMPFLAGS-y) \
-		       $(ASINCLUDES) $(ASINCLUDES-y) \
-		       $($(call vprefix_lib,$(1),ASINCLUDES)) $($(call vprefix_lib,$(1),ASINCLUDES-y)) \
-		       $($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
-		       $(ARCHFLAGS) $(ARCHFLAGS-y) \
-		       $(ASFLAGS) $(ASFLAGS-y) \
-		       $($(call vprefix_lib,$(1),ASFLAGS)) $($(call vprefix_lib,$(1),ASFLAGS-y)) \
-		       $($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
+		$(AS)  -E -P -x assembler-with-cpp $$(COMPFLAGS) $$(COMPFLAGS-y) \
+		       $$(ASINCLUDES) $$(ASINCLUDES-y) \
+		       $$($(call vprefix_lib,$(1),ASINCLUDES)) $$($(call vprefix_lib,$(1),ASINCLUDES-y)) \
+		       $$($(call vprefix_src,$(1),$(2),$(3),INCLUDES)) $$($(call vprefix_src,$(1),$(2),$(3),INCLUDES-y)) \
+		       $$(ARCHFLAGS) $$(ARCHFLAGS-y) \
+		       $$(ASFLAGS) $$(ASFLAGS-y) \
+		       $$($(call vprefix_lib,$(1),ASFLAGS)) $$($(call vprefix_lib,$(1),ASFLAGS-y)) \
+		       $$($(call vprefix_src,$(1),$(2),$(3),FLAGS)) $$($(call vprefix_src,$(1),$(2),$(3),FLAGS-y)) \
 		       $(5) \
 		       $(2) -o $(4) $(call depflags,$(4))
 	)
-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 08:51:14 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 08:51:14 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxnzW-0004LC-N2; Tue, 21 Jul 2020 08:51:14 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=zkTt=BA=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jxnzV-0004Jn-28
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 08:51:13 +0000
X-Inumbo-ID: 50e9e878-cb2f-11ea-84fb-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 50e9e878-cb2f-11ea-84fb-bc764e2007e4;
 Tue, 21 Jul 2020 08:51:07 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id AAF04F2011;
 Tue, 21 Jul 2020 10:51:06 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id cvkhpwCnktOC; Tue, 21 Jul 2020 10:51:06 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 7FE5DF200F
 for <minios-devel@lists.xen.org>; Tue, 21 Jul 2020 10:51:04 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 21 Jul
 2020 10:51:02 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v4 2/3] lib/uknetdev: Save nw_stack data in a
 netdevice
Date: Tue, 21 Jul 2020 10:50:48 +0200
Message-ID: <1595321449-30403-3-git-send-email-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <1595321449-30403-1-git-send-email-sharan.santhanam@neclab.eu>
References: <1595321449-30403-1-git-send-email-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

We extend the uk_netdev to store network stack specific data into
uk_netdev. The size of the of this data is passed to network stack
by setting the CONFIG_UK_NETDEV_SCRATCH_SIZE.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Reviewed-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
---
 lib/uknetdev/Makefile.rules           | 17 +++++++++++++++++
 lib/uknetdev/include/uk/netdev_core.h |  7 +++++++
 2 files changed, 24 insertions(+)
 create mode 100644 lib/uknetdev/Makefile.rules

diff --git a/lib/uknetdev/Makefile.rules b/lib/uknetdev/Makefile.rules
new file mode 100644
index 0000000..80997e5
--- /dev/null
+++ b/lib/uknetdev/Makefile.rules
@@ -0,0 +1,17 @@
+UK_SCRATCH_MEM=0
+UK_SCRATCH_RULE_SET=
+
+uk_scratch_mem_set: $$(eval CFLAGS-y+=-DCONFIG_UK_NETDEV_SCRATCH_SIZE=$$(UK_SCRATCH_MEM))
+	@:;
+
+.PHONY : uk_scratch_mem_set
+
+
+## reserve memory for the network stack
+## uknetdev_scratch_mem,bytes_of_memory
+define uknetdev_scratch_mem =
+$(if $(strip $(1)),\
+	$(if $(shell test $(1) -gt $(UK_SCRATCH_MEM) && echo "scratch mem set"), $(eval UK_SCRATCH_MEM:=$(1))))
+
+$(if $(strip $(UK_SCRATCH_RULE_SET)),,$(eval UK_SCRATCH_RULE_SET:=1) $(eval UK_PREPARE-$(CONFIG_LIBUKNETDEV)+=uk_scratch_mem_set))
+endef
diff --git a/lib/uknetdev/include/uk/netdev_core.h b/lib/uknetdev/include/uk/netdev_core.h
index d2e8da0..e9d9113 100644
--- a/lib/uknetdev/include/uk/netdev_core.h
+++ b/lib/uknetdev/include/uk/netdev_core.h
@@ -65,6 +65,10 @@
 extern "C" {
 #endif
 
+#ifndef CONFIG_UK_NETDEV_SCRATCH_SIZE
+#define CONFIG_UK_NETDEV_SCRATCH_SIZE 0
+#endif /* CONFIG_UK_NETDEV_SCRATCH_SIZE */
+
 struct uk_netdev;
 UK_TAILQ_HEAD(uk_netdev_list, struct uk_netdev);
 
@@ -409,6 +413,9 @@ struct uk_netdev {
 
 	/** Netdevice address configuration */
 	struct uk_netdev_config	   *_config;
+#if (CONFIG_UK_NETDEV_SCRATCH_SIZE > 0)
+	char scratch_pad[CONFIG_UK_NETDEV_SCRATCH_SIZE];
+#endif /* CONFIG_UK_NETDEV_SCRATCH_SIZE */
 };
 
 #ifdef __cplusplus
-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 08:51:14 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 08:51:14 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxnzW-0004LR-OK; Tue, 21 Jul 2020 08:51:14 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=zkTt=BA=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jxnzV-0004Jo-5C
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 08:51:13 +0000
X-Inumbo-ID: 5220e282-cb2f-11ea-a09b-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 5220e282-cb2f-11ea-a09b-12813bfff9fa;
 Tue, 21 Jul 2020 08:51:09 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id C1D3CF2010;
 Tue, 21 Jul 2020 10:51:08 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id B3Jt-j9qlclN; Tue, 21 Jul 2020 10:51:08 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 8F2A0F200F
 for <minios-devel@lists.xen.org>; Tue, 21 Jul 2020 10:51:06 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 21 Jul
 2020 10:51:02 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v4 3/3] lib/uknetdev: Get feature supported on
 uk_netdev
Date: Tue, 21 Jul 2020 10:50:49 +0200
Message-ID: <1595321449-30403-4-git-send-email-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <1595321449-30403-1-git-send-email-sharan.santhanam@neclab.eu>
References: <1595321449-30403-1-git-send-email-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The uk_netdev_info provides a way to forward information on netdevice
to the network stack. We extend this with a bitmap of the features
supported on device. The bit 0,1 of the bitmap indicates if the
device supports interrupt.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 lib/uknetdev/include/uk/netdev_core.h | 12 ++++++++++++
 plat/drivers/virtio/virtio_net.c      |  1 +
 2 files changed, 13 insertions(+)

diff --git a/lib/uknetdev/include/uk/netdev_core.h b/lib/uknetdev/include/uk/netdev_core.h
index e9d9113..c170696 100644
--- a/lib/uknetdev/include/uk/netdev_core.h
+++ b/lib/uknetdev/include/uk/netdev_core.h
@@ -77,6 +77,17 @@ UK_TAILQ_HEAD(uk_netdev_list, struct uk_netdev);
  */
 #define UK_NETDEV_HWADDR_LEN 6 /**< Length of Ethernet address. */
 
+/**
+ * The netdevice support rx/tx interrupt.
+ */
+#define UK_FEATURE_RXQ_INTR_BIT		    0
+#define UK_FEATURE_RXQ_INTR_AVAILABLE  (1UL << UK_FEATURE_RXQ_INTR_BIT)
+#define UK_FEATURE_TXQ_INTR_BIT		    1
+#define UK_FEATURE_TXQ_INTR_AVAILABLE  (1UL << UK_FEATURE_TXQ_INTR_BIT)
+
+#define uk_netdev_rxintr_supported(feature)	\
+	(feature & (UK_FEATURE_RXQ_INTR_AVAILABLE))
+
 struct uk_hwaddr {
 	uint8_t addr_bytes[UK_NETDEV_HWADDR_LEN];
 } __packed;
@@ -91,6 +102,7 @@ struct uk_netdev_info {
 	uint16_t max_mtu;   /**< Maximum supported MTU size. */
 	uint16_t nb_encap_tx;  /**< Number of bytes required as headroom for tx. */
 	uint16_t nb_encap_rx;  /**< Number of bytes required as headroom for rx. */
+	uint32_t features; /**< bitmap of the features supported */
 };
 
 /**
diff --git a/plat/drivers/virtio/virtio_net.c b/plat/drivers/virtio/virtio_net.c
index 3025ed3..0a8312d 100644
--- a/plat/drivers/virtio/virtio_net.c
+++ b/plat/drivers/virtio/virtio_net.c
@@ -1052,6 +1052,7 @@ static void virtio_net_info_get(struct uk_netdev *dev,
 	dev_info->max_tx_queues = vndev->max_vqueue_pairs;
 	dev_info->nb_encap_tx = sizeof(struct virtio_net_hdr_padded);
 	dev_info->nb_encap_rx = sizeof(struct virtio_net_hdr_padded);
+	dev_info->features = UK_FEATURE_RXQ_INTR_AVAILABLE;
 }
 
 static int virtio_net_start(struct uk_netdev *n)
-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 12:21:35 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 12:21:35 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxrH2-000898-W1; Tue, 21 Jul 2020 12:21:32 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=UXjz=BA=gmail.com=wei.liu.xen@srs-us1.protection.inumbo.net>)
 id 1jxrH2-00088n-5P
 for minios-devel@lists.xenproject.org; Tue, 21 Jul 2020 12:21:32 +0000
X-Inumbo-ID: b1f13745-cb4c-11ea-a0ac-12813bfff9fa
Received: from mail-wr1-f67.google.com (unknown [209.85.221.67])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id b1f13745-cb4c-11ea-a0ac-12813bfff9fa;
 Tue, 21 Jul 2020 12:21:25 +0000 (UTC)
Received: by mail-wr1-f67.google.com with SMTP id f18so21043614wrs.0;
 Tue, 21 Jul 2020 05:21:25 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:date:from:to:subject:message-id:references
 :mime-version:content-disposition:in-reply-to:user-agent;
 bh=SNfWVX5QtpauRhZzF7YTPhpX/9TOAv34XYBcKG6bEMA=;
 b=W+TxOR4CJVPuTDasmFIIOFR4VZ1FsR441fbrjihVH/hF6IA+UlI2s0aTtLNsrrImQW
 KWwxokhCALIbA+d7fTykjFsd2tl4JuE/IJMAAPhQ6EKfEby+KJWnQEPnwk57Vtpprsvt
 PJmarwc5ZsQn0yHX3sIv6x7ixl4qXuCgoPKS7ytgTqkTd+j1F6J6o5WA09xTEjx3BX0r
 rgCLNMzv52Mxz8CkjxCI5/ybURzZHYKROKQNk29xe60Ro5XK1bijk6f9Qhk2bYjjbzwl
 1ES/eNuOHEzNTS8YmLLvtqoE89s5Tp2Uj0N9Vd6jekU7oJPTp/LZtffHGDKPcUt8UZ4N
 /Acg==
X-Gm-Message-State: AOAM533dZUOFORa+/mJx9j785miPTIsr+RMf64Pg2aA9AgIi4ZvhWhuq
 YUNiC5yiTYMWC6RKv6nTtE0=
X-Google-Smtp-Source: ABdhPJyFSP1Hn9ZbFFG9cK9p8i7a/w3/TND65B/M0cuembEqoOaWJ9HSDLMQ2FkNKeZZWnjfkX9C3Q==
X-Received: by 2002:adf:e801:: with SMTP id o1mr27048159wrm.54.1595334084808; 
 Tue, 21 Jul 2020 05:21:24 -0700 (PDT)
Received: from liuwe-devbox-debian-v2 ([51.145.34.42])
 by smtp.gmail.com with ESMTPSA id u2sm3102387wml.16.2020.07.21.05.21.23
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Tue, 21 Jul 2020 05:21:23 -0700 (PDT)
Date: Tue, 21 Jul 2020 12:21:22 +0000
From: Wei Liu <wl@xen.org>
To: Samuel Thibault <samuel.thibault@ens-lyon.org>,
 Juergen Gross <jgross@suse.com>, minios-devel@lists.xenproject.org,
 xen-devel@lists.xenproject.org, wl@xen.org
Subject: Re: [PATCH v2] mini-os: don't hard-wire xen internal paths
Message-ID: <20200721122122.ypuumlnwn4djwevw@liuwe-devbox-debian-v2>
References: <20200713084230.18177-1-jgross@suse.com>
 <20200718181827.7jrs5ilutt3jzp4i@function>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20200718181827.7jrs5ilutt3jzp4i@function>
User-Agent: NeoMutt/20180716
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

On Sat, Jul 18, 2020 at 08:18:27PM +0200, Samuel Thibault wrote:
> Juergen Gross, le lun. 13 juil. 2020 10:42:30 +0200, a ecrit:
> > Mini-OS shouldn't use Xen internal paths for building. Import the
> > needed paths from Xen and fall back to the current values only if
> > the import was not possible.
> > 
> > Signed-off-by: Juergen Gross <jgross@suse.com>
> 
> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

Unfortunately this doesn't apply to staging.

Juergen, can you rebase?

Wei.


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 12:25:01 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 12:25:01 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxrKO-0008QL-TO; Tue, 21 Jul 2020 12:25:00 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <SRS0=d7zm=BA=suse.com=jgross@srs-us1.protection.inumbo.net>)
 id 1jxrKN-0008Pd-SJ
 for minios-devel@lists.xenproject.org; Tue, 21 Jul 2020 12:24:59 +0000
X-Inumbo-ID: 2da11378-cb4d-11ea-a0ac-12813bfff9fa
Received: from mx2.suse.de (unknown [195.135.220.15])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 2da11378-cb4d-11ea-a0ac-12813bfff9fa;
 Tue, 21 Jul 2020 12:24:53 +0000 (UTC)
X-Virus-Scanned: by amavisd-new at test-mx.suse.de
Received: from relay2.suse.de (unknown [195.135.221.27])
 by mx2.suse.de (Postfix) with ESMTP id 22E6BB947;
 Tue, 21 Jul 2020 12:24:59 +0000 (UTC)
Subject: Re: [PATCH v2] mini-os: don't hard-wire xen internal paths
To: Wei Liu <wl@xen.org>, Samuel Thibault <samuel.thibault@ens-lyon.org>,
 minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org
References: <20200713084230.18177-1-jgross@suse.com>
 <20200718181827.7jrs5ilutt3jzp4i@function>
 <20200721122122.ypuumlnwn4djwevw@liuwe-devbox-debian-v2>
From: =?UTF-8?B?SsO8cmdlbiBHcm/Dnw==?= <jgross@suse.com>
Message-ID: <3f8f2da2-552c-c651-5744-dfa01bd9821c@suse.com>
Date: Tue, 21 Jul 2020 14:24:51 +0200
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200721122122.ypuumlnwn4djwevw@liuwe-devbox-debian-v2>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

On 21.07.20 14:21, Wei Liu wrote:
> On Sat, Jul 18, 2020 at 08:18:27PM +0200, Samuel Thibault wrote:
>> Juergen Gross, le lun. 13 juil. 2020 10:42:30 +0200, a ecrit:
>>> Mini-OS shouldn't use Xen internal paths for building. Import the
>>> needed paths from Xen and fall back to the current values only if
>>> the import was not possible.
>>>
>>> Signed-off-by: Juergen Gross <jgross@suse.com>
>>
>> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> 
> Unfortunately this doesn't apply to staging.

Since when does mini-os.git have a staging branch?

> Juergen, can you rebase?

To what?


Juergen


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 12:39:48 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 12:39:48 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxrYg-0001Oe-EU; Tue, 21 Jul 2020 12:39:46 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=UXjz=BA=gmail.com=wei.liu.xen@srs-us1.protection.inumbo.net>)
 id 1jxrYf-0001OZ-4k
 for minios-devel@lists.xenproject.org; Tue, 21 Jul 2020 12:39:45 +0000
X-Inumbo-ID: 40565e04-cb4f-11ea-a0ae-12813bfff9fa
Received: from mail-wr1-f65.google.com (unknown [209.85.221.65])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 40565e04-cb4f-11ea-a0ae-12813bfff9fa;
 Tue, 21 Jul 2020 12:39:43 +0000 (UTC)
Received: by mail-wr1-f65.google.com with SMTP id y3so3697350wrl.4;
 Tue, 21 Jul 2020 05:39:43 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:date:from:to:cc:subject:message-id:references
 :mime-version:content-disposition:content-transfer-encoding
 :in-reply-to:user-agent;
 bh=yYk/n9bSJ9lpUEb/G+eXAQy/jJCRVpTKTHSuMovV7kY=;
 b=R4pKLxpzy5LZTjYYA67Jxg9l28RnXRsWOJwfNGtlQPS0AG8PZ3XFL8ENudop4UreCE
 WKjiLCItKpQ0mVGO6nqO38m0GXSBoyqr8R9XINTkTbSft7wq3/NOQ52mFizKDRU2YmOc
 rP2ZIEXWfGo9UWXfgclCdNZKtSx6FAocz0szVFW//5z1BGiC8iqIZBvCry4nfzQj2Al7
 D7sMqsSNrbn2xGG6lgiBx3/aTXanmad9Q5vW+4rLKo0Eulj4L1jUcOK0/NSsHhUntuQF
 iPASDnD5MTShcXy1IZ0APqIwlCpw/q0Zb14yZClseFH1SMLxpPYj9E/QrrNh+o8a7v6x
 Iv6Q==
X-Gm-Message-State: AOAM53295sUiV6mlLnVoAD5agYYio7ljrErSf/gT+2c/b9t3xITL18ky
 en5cFdSUNKqsXpRWTrWLtyU=
X-Google-Smtp-Source: ABdhPJxQFBI+NVd6cWdmZezxXmsyzRI73/sZyomF7mD/wbR25S6xZBigGFS8km4RSDSPly+vrl2J8g==
X-Received: by 2002:adf:9e8b:: with SMTP id a11mr4100912wrf.309.1595335182708; 
 Tue, 21 Jul 2020 05:39:42 -0700 (PDT)
Received: from liuwe-devbox-debian-v2 ([51.145.34.42])
 by smtp.gmail.com with ESMTPSA id v15sm3239420wmh.24.2020.07.21.05.39.42
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Tue, 21 Jul 2020 05:39:42 -0700 (PDT)
Date: Tue, 21 Jul 2020 12:39:40 +0000
From: Wei Liu <wl@xen.org>
To: =?utf-8?B?SsO8cmdlbiBHcm/Dnw==?= <jgross@suse.com>
Subject: Re: [PATCH v2] mini-os: don't hard-wire xen internal paths
Message-ID: <20200721123940.blw3njlbpzbd5iia@liuwe-devbox-debian-v2>
References: <20200713084230.18177-1-jgross@suse.com>
 <20200718181827.7jrs5ilutt3jzp4i@function>
 <20200721122122.ypuumlnwn4djwevw@liuwe-devbox-debian-v2>
 <3f8f2da2-552c-c651-5744-dfa01bd9821c@suse.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <3f8f2da2-552c-c651-5744-dfa01bd9821c@suse.com>
User-Agent: NeoMutt/20180716
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: minios-devel@lists.xenproject.org,
 Samuel Thibault <samuel.thibault@ens-lyon.org>, Wei Liu <wl@xen.org>,
 xen-devel@lists.xenproject.org
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

On Tue, Jul 21, 2020 at 02:24:51PM +0200, Jürgen Groß wrote:
> On 21.07.20 14:21, Wei Liu wrote:
> > On Sat, Jul 18, 2020 at 08:18:27PM +0200, Samuel Thibault wrote:
> > > Juergen Gross, le lun. 13 juil. 2020 10:42:30 +0200, a ecrit:
> > > > Mini-OS shouldn't use Xen internal paths for building. Import the
> > > > needed paths from Xen and fall back to the current values only if
> > > > the import was not possible.
> > > > 
> > > > Signed-off-by: Juergen Gross <jgross@suse.com>
> > > 
> > > Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> > 
> > Unfortunately this doesn't apply to staging.
> 
> Since when does mini-os.git have a staging branch?
> 
> > Juergen, can you rebase?
> 
> To what?

Urgh, my bad! I thought this was a patch for xen.git. :-p

Wei.

> 
> 
> Juergen


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 12:42:46 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 12:42:46 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxrba-0002BI-A7; Tue, 21 Jul 2020 12:42:46 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=UXjz=BA=gmail.com=wei.liu.xen@srs-us1.protection.inumbo.net>)
 id 1jxrbY-0002AR-Vy
 for minios-devel@lists.xenproject.org; Tue, 21 Jul 2020 12:42:45 +0000
X-Inumbo-ID: a81425da-cb4f-11ea-a0ae-12813bfff9fa
Received: from mail-wm1-f68.google.com (unknown [209.85.128.68])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id a81425da-cb4f-11ea-a0ae-12813bfff9fa;
 Tue, 21 Jul 2020 12:42:37 +0000 (UTC)
Received: by mail-wm1-f68.google.com with SMTP id w3so2717337wmi.4;
 Tue, 21 Jul 2020 05:42:37 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:date:from:to:cc:subject:message-id:references
 :mime-version:content-disposition:content-transfer-encoding
 :in-reply-to:user-agent;
 bh=tELJWANfqx4mlHBXTpXLWhk9GZg3z4LZLshklfe6VAQ=;
 b=Cp1vjdAsUVVDpjtVKHpUGBe4r/3z59eFIqn5WpGDzZOVy3rAQ5oI4DwqFrsPwoVByD
 svVEzmE4AT+2q56oMyVMYiqdUSpr1m5m3xqrt5BxaznpgGuAgHwZtHeG3YXFnWKf5+2L
 DreUH5L4OBpOmGgX8Is1fRCc0BUIr3D0xzwPFI9IauZ4qa8Tr7MN4C4JxWxuDV32+mZj
 p6QdUCVT6s/vivE2zBAUkS+bumazk1zUQxO/mUUAf3YgllDSxLJlLaOtNjrbJdxymK1D
 qCr2pbblpH6oXw1taiVVxHAIhhmInjDRcj0YJNo1yCj1HkGxmPCD0PJ6SW3SWoTNM+jl
 QKyw==
X-Gm-Message-State: AOAM530NLl0g+stKhvWx82gOvLRFTdbpuvzNwY5MOtOrFmFIiIHNBcw2
 8urQy1b/CcruULTefItveZY=
X-Google-Smtp-Source: ABdhPJysXW0HJF3DUf8MVNwlk735cjCrddyvm8JU58tgCSG0CcXRlr232Icr/zmIqv6CUSFjbNtfuA==
X-Received: by 2002:a1c:7ecb:: with SMTP id z194mr3552455wmc.12.1595335356790; 
 Tue, 21 Jul 2020 05:42:36 -0700 (PDT)
Received: from liuwe-devbox-debian-v2 ([51.145.34.42])
 by smtp.gmail.com with ESMTPSA id y6sm37664262wrr.74.2020.07.21.05.42.36
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Tue, 21 Jul 2020 05:42:36 -0700 (PDT)
Date: Tue, 21 Jul 2020 12:42:34 +0000
From: Wei Liu <wl@xen.org>
To: =?utf-8?B?SsO8cmdlbiBHcm/Dnw==?= <jgross@suse.com>
Subject: Re: [PATCH v2] mini-os: don't hard-wire xen internal paths
Message-ID: <20200721124234.y2ly2xgxmqwhobdv@liuwe-devbox-debian-v2>
References: <20200713084230.18177-1-jgross@suse.com>
 <20200718181827.7jrs5ilutt3jzp4i@function>
 <20200721122122.ypuumlnwn4djwevw@liuwe-devbox-debian-v2>
 <3f8f2da2-552c-c651-5744-dfa01bd9821c@suse.com>
 <20200721123940.blw3njlbpzbd5iia@liuwe-devbox-debian-v2>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <20200721123940.blw3njlbpzbd5iia@liuwe-devbox-debian-v2>
User-Agent: NeoMutt/20180716
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: minios-devel@lists.xenproject.org,
 Samuel Thibault <samuel.thibault@ens-lyon.org>, Wei Liu <wl@xen.org>,
 xen-devel@lists.xenproject.org
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

On Tue, Jul 21, 2020 at 12:39:40PM +0000, Wei Liu wrote:
> On Tue, Jul 21, 2020 at 02:24:51PM +0200, Jürgen Groß wrote:
> > On 21.07.20 14:21, Wei Liu wrote:
> > > On Sat, Jul 18, 2020 at 08:18:27PM +0200, Samuel Thibault wrote:
> > > > Juergen Gross, le lun. 13 juil. 2020 10:42:30 +0200, a ecrit:
> > > > > Mini-OS shouldn't use Xen internal paths for building. Import the
> > > > > needed paths from Xen and fall back to the current values only if
> > > > > the import was not possible.
> > > > > 
> > > > > Signed-off-by: Juergen Gross <jgross@suse.com>
> > > > 
> > > > Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> > > 
> > > Unfortunately this doesn't apply to staging.
> > 
> > Since when does mini-os.git have a staging branch?
> > 
> > > Juergen, can you rebase?
> > 
> > To what?
> 
> Urgh, my bad! I thought this was a patch for xen.git. :-p

Applied to mini-os.git.

Wei.


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 12:45:51 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 12:45:51 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxreX-0002Rs-W5; Tue, 21 Jul 2020 12:45:49 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=NVI3=BA=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jxreW-0002Rg-JZ
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 12:45:48 +0000
X-Inumbo-ID: 17c6e84b-cb50-11ea-a0b1-12813bfff9fa
Received: from mx.upb.ro (unknown [141.85.13.220])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 17c6e84b-cb50-11ea-a0b1-12813bfff9fa;
 Tue, 21 Jul 2020 12:45:46 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 720DAB5619E5;
 Tue, 21 Jul 2020 15:45:45 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id ttksUit9DcwJ; Tue, 21 Jul 2020 15:45:41 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 05F01B561CED;
 Tue, 21 Jul 2020 15:45:41 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id kEb2Q9uCh4Cd; Tue, 21 Jul 2020 15:45:40 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id 6B861B561CCE;
 Tue, 21 Jul 2020 15:45:40 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH 2/5] lib/ukmpi: Initial port of FreeBSD's
 buf_ring.h
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200720164015.4715-1-a.jung@lancs.ac.uk>
 <20200720164015.4715-3-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <5b085d46-e500-bafa-a74b-69faa5e1d215@cs.pub.ro>
Date: Tue, 21 Jul 2020 15:45:40 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200720164015.4715-3-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

What we did with other source code imported from FreeBSD was to add a
first commit with exactly the same code, copy-pasted from FreeBSD. See
for example the bitmap imported from FreeBSD [1]. This should be fairly
simple to do. You should also add in the commit message the commit ID
from which you copied the initial code (see as example the first commit
for bitmap).

Next commit would contain the differences between the original code and
what we have here. This second commit would actually represent the
adaptation of the FreeBSD code to Unikraft. That's why you can also
include the changes in 4/5 'lib/ukmpi: Include ring buffer into Unikraft
build process' and even 1/5 lib/ukmpi: Introduce simple ring interface
KConfig option.


[1] https://github.com/unikraft/unikraft/commits/master/include/uk/bitmap.h


Cheers,
Costin

On 7/20/20 7:40 PM, Alexander Jung wrote:
> From: Alexander Jung <alexander.jung@neclab.eu>
> 
> This commit introduces a Unikraft-centric implementation of
> FreeBSD's buf_ring.h message passing ring buffer header.  Most of
> the functionality is provided inline with this header.
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/ukmpi/include/uk/ring.h | 474 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 474 insertions(+)
>  create mode 100644 lib/ukmpi/include/uk/ring.h
> 
> diff --git a/lib/ukmpi/include/uk/ring.h b/lib/ukmpi/include/uk/ring.h
> new file mode 100644
> index 0000000..6673244
> --- /dev/null
> +++ b/lib/ukmpi/include/uk/ring.h
> @@ -0,0 +1,474 @@
> +/* SPDX-License-Identifier: BSD-2-Clause-FreeBSD */
> +/*
> + * Authors: Kip Macy <kmacy@freebsd.org>
> + *          Alexander Jung <alexander.jung@neclab.eu>
> + *
> + * Copyright (c) 2007-2009, Kip Macy <kmacy@freebsd.org>
> + *               2020, NEC Laboratories Europe GmbH, NEC Corporation.
> + *               All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + *
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in the
> + *    documentation and/or other materials provided with the distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> + * SUCH DAMAGE.
> + *
> + * $FreeBSD$
> + */
> +/*
> + * Simple ring implementation to handle object references.
> + *
> + * Inspired by FreeBSD and modified (commit-id: c45cce1).
> + */
> +#ifndef __UK_RING_H__
> +#define __UK_RING_H__
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +
> +#include <errno.h>
> +#include <uk/mutex.h>
> +#include <uk/print.h>
> +#include <uk/config.h>
> +#include <uk/assert.h>
> +#include <uk/plat/lcpu.h>
> +#include <uk/arch/atomic.h>
> +
> +
> +struct uk_ring {
> +  volatile uint32_t  prod_head;
> +  volatile uint32_t  prod_tail;  
> +  int                prod_size;
> +  int                prod_mask;
> +  uint64_t           drops;
> +  volatile uint32_t  cons_head;
> +  volatile uint32_t  cons_tail;
> +  int                cons_size;
> +  int                cons_mask;
> +#ifdef CONFIG_LIBUKMPI_RING_DEBUG
> +  struct uk_mutex   *lock;
> +#endif /* CONFIG_LIBUKMPI_RING_DEBUG */
> +  void              *ring[0];
> +};
> +
> +
> +/**
> + * Multi-producer safe lock-free ring buffer enqueue.
> + *
> + * @param br
> + *  Reference to the ring structure.
> + * @param buf
> + *  Buffer size for the ring.
> + */
> +static __inline int
> +uk_ring_enqueue(struct uk_ring *br, void *buf)
> +{
> +  uint32_t prod_head, prod_next, cons_tail;
> +
> +#ifdef CONFIG_LIBUKMPI_RING_DEBUG
> +  int i;
> +  /*
> +   * Note: It is possible to encounter an mbuf that was removed via drpeek(),
> +   * and then re-added via drputback() and trigger a spurious panic.
> +   */
> +  for (i = br->cons_head; i != br->prod_head;
> +       i = ((i + 1) & br->cons_mask))
> +    if(br->ring[i] == buf)
> +      uk_pr_crit("buf=%p already enqueue at %d prod=%d cons=%d\n",
> +          buf, i, br->prod_tail, br->cons_tail);
> +#endif /* CONFIG_LIBUKMPI_RING_DEBUG */
> +
> +  ukplat_lcpu_disable_irq();
> +
> +  do {
> +    prod_head = br->prod_head;
> +    prod_next = (prod_head + 1) & br->prod_mask;
> +    cons_tail = br->cons_tail;
> +
> +    if (prod_next == cons_tail) {
> +      rmb();
> +      if (prod_head == br->prod_head &&
> +          cons_tail == br->cons_tail) {
> +        br->drops++;
> +        ukplat_lcpu_enable_irq();
> +        return -ENOBUFS;
> +      }
> +      continue;
> +    }
> +  } while (!ukarch_compare_exchange_sync(&br->prod_head, prod_head, prod_next));
> +
> +#ifdef CONFIG_LIBUKMPI_RING_DEBUG
> +  if (br->ring[prod_head] != NULL)
> +    uk_pr_crit("dangling value in enqueue\n");
> +#endif /* CONFIG_LIBUKMPI_RING_DEBUG */
> +
> +  br->ring[prod_head] = buf;
> +
> +  /*
> +   * If there are other enqueues in progress that preceded us, we need to wait
> +   * for them to complete.
> +   */
> +  /* TODO: Provide cpu_spinwait() */
> +#if 0
> +  while (br->prod_tail != prod_head)
> +    cpu_spinwait();
> +#endif
> +
> +  ukarch_store_n(&br->prod_tail, prod_next);
> +  ukplat_lcpu_enable_irq();
> +
> +  return 0;
> +}
> +
> +
> +/**
> + * Multi-consumer safe dequeue.
> + *
> + * @param br
> + *  Reference to the ring structure.
> + */
> +static __inline void *
> +uk_ring_dequeue(struct uk_ring *br)
> +{
> +  void *buf;
> +  uint32_t cons_head, cons_next;
> +
> +  ukplat_lcpu_disable_irq();
> +
> +  do {
> +    cons_head = br->cons_head;
> +    cons_next = (cons_head + 1) & br->cons_mask;
> +
> +    if (cons_head == br->prod_tail) {
> +      ukplat_lcpu_enable_irq();
> +      return (NULL);
> +    }
> +  } while (!ukarch_compare_exchange_sync(&br->cons_head, cons_head, cons_next));
> +
> +  buf = br->ring[cons_head];
> +
> +#ifdef CONFIG_LIBUKMPI_RING_DEBUG
> +  br->ring[cons_head] = NULL;
> +#endif /* CONFIG_LIBUKMPI_RING_DEBUG */
> +
> +  /*
> +   * If there are other dequeues in progress that preceded us, we need to wait
> +   * for them to complete.
> +   */
> +  /* TODO: Provide cpu_spinwait() */
> +#if 0
> +  while (br->cons_tail != cons_head)
> +    cpu_spinwait();
> +#endif
> +
> +  ukarch_store_n(&br->cons_tail, cons_next);
> +
> +  ukplat_lcpu_enable_irq();
> +
> +  return buf;
> +}
> +
> +
> +/**
> + * Single-consumer dequeue use where dequeue is protected by a lock e.g. a
> + * network driver's tx queue lock.
> + *
> + * @param br
> + *  Reference to the ring structure.
> + */
> +static __inline void *
> +uk_ring_dequeue_single(struct uk_ring *br)
> +{
> +  void *buf;
> +  uint32_t cons_head, cons_next, prod_tail;
> +
> +#ifdef PREFETCH_DEFINED
> +  uint32_t cons_next_next;
> +#endif
> +
> +  /* TODO: Provide atomic_load_acq_32() */
> +#if 0
> +  /*
> +   * This is a workaround to allow using uk_ring on ARM and ARM64.
> +   *
> +   * ARM64TODO: Fix uk_ring in a generic way.
> +   *
> +   * REMARKS: It is suspected that cons_head does not require
> +   *   load_acq operation, but this change was extensively tested
> +   *   and confirmed it's working. To be reviewed once again in
> +   *   FreeBSD-12.
> +   *
> +   * Preventing following situation:
> +   *
> +   * | uk_ring_enqueue()                            | uk_ring_dequeue_single()                                   |
> +   * |----------------------------------------------+-----------------------------------------------------|
> +   * |                                              |                                                     |
> +   * |                                              | cons_head = br->cons_head;                          |
> +   * | atomic_cmpset_acq_32(&br->prod_head, ...));  |                                                     |
> +   * |                                              | buf = br->ring[cons_head];   (see <1>)              |
> +   * | br->ring[prod_head] = buf;                   |                                                     |
> +   * | atomic_store_rel_32(&br->prod_tail, ...);    |                                                     |
> +   * |                                              | prod_tail = br->prod_tail;                          |
> +   * |                                              | if (cons_head == prod_tail)                         |
> +   * |                                              |   return NULL;                                      |
> +   * |                                              | <condition is false and code uses invalid(old) buf> |
> +   *
> +   * <1> Load (on core 1) from br->ring[cons_head] can be reordered (speculative readed) by CPU.
> +   */  
> +#if defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64)
> +  cons_head = atomic_load_acq_32(&br->cons_head);
> +#else
> +  cons_head = br->cons_head;
> +#endif /* defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64) */
> +#else
> +  cons_head = br->cons_head;
> +#endif /* 0 */
> +
> +  // prod_tail = atomic_load_acq_32(&br->prod_tail);  
> +  prod_tail = br->prod_tail;
> +  cons_next = (cons_head + 1) & br->cons_mask;
> +  
> +  if (cons_head == prod_tail) 
> +    return NULL;
> +
> +  br->cons_head = cons_next;
> +  buf = br->ring[cons_head];
> +
> +#ifdef CONFIG_LIBUKMPI_RING_DEBUG
> +  br->ring[cons_head] = NULL;
> +
> +  if (!uk_mutex_is_locked(br->lock))
> +    uk_pr_crit("lock not held on single consumer dequeue\n");
> +
> +  if (br->cons_tail != cons_head)
> +    uk_pr_crit("inconsistent list cons_tail=%d cons_head=%d\n",
> +        br->cons_tail, cons_head);
> +
> +#endif /* CONFIG_LIBUKMPI_RING_DEBUG */
> +
> +  br->cons_tail = cons_next;
> +
> +  return buf;
> +}
> +
> +
> +/**
> + * Single-consumer advance after a peek use where it is protected by a lock e.g.
> + * a network driver's tx queue lock.
> + *
> + * @param br
> + *  Reference to the ring structure.
> + */
> +static __inline void
> +uk_ring_advance_single(struct uk_ring *br)
> +{
> +  uint32_t cons_head, cons_next;
> +  uint32_t prod_tail;
> +
> +  debug_ring(br);
> +  
> +  cons_head = br->cons_head;
> +  prod_tail = br->prod_tail;
> +  
> +  cons_next = (cons_head + 1) & br->cons_mask;
> +
> +  if (cons_head == prod_tail) 
> +    return;
> +
> +  br->cons_head = cons_next;
> +
> +#ifdef CONFIG_LIBUKMPI_RING_DEBUG
> +  br->ring[cons_head] = NULL;
> +#endif /* CONFIG_LIBUKMPI_RING_DEBUG */
> +
> +  br->cons_tail = cons_next;
> +}
> +
> +
> +/**
> + * Used to return a buffer (most likely already there) to the top of the ring.
> + * The caller should *not* have used any dequeue to pull it out of the ring but
> + * instead should have used the peek() function.  This is normally used where
> + * the transmit queue of a driver is full, and an mbuf must be returned.  Most
> + * likely whats in the ring-buffer is what is being put back (since it was not
> + * removed), but sometimes the lower transmit function may have done a pullup or
> + * other function that will have changed it. As an optimization we always put it
> + * back (since jhb says the store is probably cheaper), if we have to do a
> + * multi-queue version we will need the compare and an atomic.
> + *
> + * @param br
> + *  Reference to the ring structure.
> + * @param new
> + *  
> + */
> +static __inline void
> +uk_ring_putback_single(struct uk_ring *br, void *new)
> +{
> +  /* Buffer ring has none in putback */
> +  UK_ASSERT(br->cons_head != br->prod_tail);
> +  br->ring[br->cons_head] = new;
> +}
> +
> +
> +/**
> + * Return a pointer to the first entry in the ring without modifying it, or NULL
> + * if the ring is empty race-prone if not protected by a lock.
> + *
> + * @param br
> + *  Reference to the ring structure.
> + */
> +static __inline void *
> +uk_ring_peek(struct uk_ring *br)
> +{
> +#ifdef CONFIG_LIBUKMPI_RING_DEBUG
> +  if ((br->lock != NULL) && !uk_mutex_is_locked(br->lock))
> +    uk_pr_crit("lock not held on single consumer dequeue\n");
> +#endif /* CONFIG_LIBUKMPI_RING_DEBUG */
> +
> +  /*
> +   * It is safe to not have a memory barrier here because we control cons and
> +   * tail is worst case a lagging indicator so we worst case we might return
> +   * NULL immediately after a buffer has been enqueued.
> +   */
> +  if (br->cons_head == br->prod_tail)
> +    return NULL;
> +  
> +  return br->ring[br->cons_head];
> +}
> +
> +
> +/**
> + * Single-consumer clear the pointer to the first entry of the ring, or NULL if
> + * the ring is empty.
> + *
> + * @param br
> + *  Reference to the ring structure.
> + */
> +static __inline void *
> +uk_ring_peek_clear_single(struct uk_ring *br)
> +{
> +#ifdef CONFIG_LIBUKMPI_RING_DEBUG
> +  void *ret;
> +
> +  if (!mtx_owned(br->lock))
> +    panic("lock not held on single consumer dequeue");
> +#endif /* CONFIG_LIBUKMPI_RING_DEBUG */
> +
> +  if (br->cons_head == br->prod_tail)
> +    return (NULL);
> +
> +  /* TODO: Provide atomic_thread_fence_acq */
> +#if 0
> +#if defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64)
> +  /*
> +   * The barrier is required there on ARM and ARM64 to ensure, that
> +   * br->ring[br->cons_head] will not be fetched before the above condition is
> +   * checked.  Without the barrier, it is possible, that buffer will be fetched
> +   * before the enqueue will put mbuf into br, then, in the meantime, the
> +   * enqueue will update the array and the prod_tail, and the conditional check
> +   * will be true, so we will return previously fetched (and invalid) buffer.
> +   */
> +  atomic_thread_fence_acq();
> +#endif /* defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64) */
> +#endif /* 0 */
> +
> +#ifdef CONFIG_LIBUKMPI_RING_DEBUG
> +  /*
> +   * Single consumer, i.e. cons_head will not move while we are
> +   * running, so atomic_swap_ptr() is not necessary here.
> +   */
> +  ret = br->ring[br->cons_head];
> +  br->ring[br->cons_head] = NULL;
> +  return (ret);
> +#else
> +  return (br->ring[br->cons_head]);
> +#endif /* CONFIG_LIBUKMPI_RING_DEBUG */
> +}
> +
> +
> +/**
> + * Return whether the ring buffer is full.
> + *
> + * @param br
> + *  Reference to the ring structure.
> + */
> +static __inline int
> +uk_ring_full(struct uk_ring *br)
> +{
> +  return ((br->prod_head + 1) & br->prod_mask) == br->cons_tail;
> +}
> +
> +
> +/**
> + * Return whether the ring buffer is empty.
> + *
> + * @param br
> + *  Reference to the ring structure.
> + */
> +static __inline int
> +uk_ring_empty(struct uk_ring *br)
> +{
> +  return br->cons_head == br->prod_tail;
> +}
> +
> +
> +/**
> + * Return the queue size in the ring buffer.
> + *
> + * @param br
> + *  Reference to the ring structure.
> + */
> +static __inline int
> +uk_ring_count(struct uk_ring *br)
> +{
> +  return (br->prod_size + br->prod_tail - br->cons_tail) & br->prod_mask;
> +}
> +
> +
> +/**
> + * Create a new ring buffer.
> + *
> + * @param count
> + *  The size of the ring buffer.
> + * @param a
> + *  The memory allocator to use when creating the ring buffer.
> + * @param flags
> + *  Additional flags to specify to the ring.
> + * @param lock
> + *  The mutex to use when debugging the ring buffer.
> + */
> +struct uk_ring *
> +uk_ring_alloc(int count, struct uk_alloc *a, int flags, struct uk_mutex *lock);
> +
> +
> +/**
> + * Free the ring from use.
> + *
> + * @param br
> + *  Reference to the ring structure.
> + * @param a
> + *  The memory allocator to use when freeing the object.
> + */
> +void
> +uk_ring_free(struct uk_ring *br, struct uk_alloc *a);
> +
> +
> +#endif /* __UK_RING_H__ */
> 


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 12:53:09 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 12:53:09 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxrlb-0003GR-Ka; Tue, 21 Jul 2020 12:53:07 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=NVI3=BA=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jxrlZ-0003GM-S7
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 12:53:05 +0000
X-Inumbo-ID: 1db7a04a-cb51-11ea-a0b5-12813bfff9fa
Received: from mx.upb.ro (unknown [141.85.13.220])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 1db7a04a-cb51-11ea-a0b5-12813bfff9fa;
 Tue, 21 Jul 2020 12:53:04 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 85597B561CBF;
 Tue, 21 Jul 2020 15:53:03 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id h7eTM2qxngx4; Tue, 21 Jul 2020 15:53:01 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 95B16B561CCE;
 Tue, 21 Jul 2020 15:53:01 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id 73Pv9UdocorQ; Tue, 21 Jul 2020 15:53:01 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id 20699B561CBF;
 Tue, 21 Jul 2020 15:53:01 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH 1/5] lib/ukmpi: Introduce simple ring interface
 KConfig option
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200720164015.4715-1-a.jung@lancs.ac.uk>
 <20200720164015.4715-2-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <8e25692e-6a1e-60b3-f25a-dae81f99f750@cs.pub.ro>
Date: Tue, 21 Jul 2020 15:53:00 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200720164015.4715-2-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

Please see inline.

On 7/20/20 7:40 PM, Alexander Jung wrote:
> From: Alexander Jung <alexander.jung@neclab.eu>
> 
> This commit prepares UKMPI for the inclusion of a simple ring
> buffer implementation as a selectable option.
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/ukmpi/Config.uk | 23 ++++++++++++++++++++++-
>  1 file changed, 22 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/ukmpi/Config.uk b/lib/ukmpi/Config.uk
> index 0c3bb4c..da50ccd 100644
> --- a/lib/ukmpi/Config.uk
> +++ b/lib/ukmpi/Config.uk
> @@ -7,7 +7,8 @@ menuconfig LIBUKMPI
>  		Provide inter-thread communication primitives
>  
>  if LIBUKMPI
> -	config LIBUKMPI_MBOX
> +
> +config LIBUKMPI_MBOX
>  	bool "Mailboxes"
>  	select LIBUKALLOC
>  	select LIBUKLOCK
> @@ -15,4 +16,24 @@ if LIBUKMPI
>  	default n
>  	help
>  		Provide mailbox communication interface
> +
> +config LIBUKMPI_RING
> +	bool "Ring buffers"
> +	select LIBUKALLOC
> +	select LIBUKLOCK
> +	select LIBUKLOCK_SEMAPHORE
> +	default n
> +	help
> +		Provide simple ring interface for handling object references
> +
> +if LIBUKMPI_RING
> +
> +config LIBUKMPI_RING_DEBUG
> +	bool "Debug ring buffer"
> +	default n
> +	help
> +		Debug the ring interface
> +

AFAIK, debugging should be enabled by instrumenting the lib Makefile (or
the code) by defining the UK_DEBUG macro. I did not find any other lib
defining its own debug config option. Therefore we can get rid of this
option.

> +endif
> +
>  endif
> 


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 12:56:56 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 12:56:56 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxrpH-0003Lp-VY; Tue, 21 Jul 2020 12:56:55 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=NVI3=BA=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jxrpH-0003Lk-2O
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 12:56:55 +0000
X-Inumbo-ID: a682a26c-cb51-11ea-a0b6-12813bfff9fa
Received: from mx.upb.ro (unknown [141.85.13.210])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id a682a26c-cb51-11ea-a0b6-12813bfff9fa;
 Tue, 21 Jul 2020 12:56:54 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 38735B5619E5;
 Tue, 21 Jul 2020 15:56:53 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id lN4A9_SKorup; Tue, 21 Jul 2020 15:56:50 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id C01FBB561CBF;
 Tue, 21 Jul 2020 15:56:50 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id dJA_uu5Y_qHE; Tue, 21 Jul 2020 15:56:50 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id 38721B5619E5;
 Tue, 21 Jul 2020 15:56:50 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH 3/5] lib/ukmpi: Provide ring buffer allocation
 and free methods
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200720164015.4715-1-a.jung@lancs.ac.uk>
 <20200720164015.4715-4-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <3080aeff-0907-3864-3ea8-e215182fc62c@cs.pub.ro>
Date: Tue, 21 Jul 2020 15:56:50 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200720164015.4715-4-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

I don't understand where this is coming from. Was it also taken from
FreeBSD? If so then it should be introduced together with the other
copy-pasted code (that same commit should introduce both buf_ring.h and
ring.c). And the adaption commit would add the differences. If Simon is
also an author then I think you should also add his Signed-off-by.

And please don't forget to run checkpatch (for this one and buf_ring.h).

Cheers,
Costin


On 7/20/20 7:40 PM, Alexander Jung wrote:
> From: Alexander Jung <alexander.jung@neclab.eu>
> 
> This commit introduces two new methods for initializing and
> de-initializing ring buffers.
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/ukmpi/ring.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 87 insertions(+)
>  create mode 100644 lib/ukmpi/ring.c
> 
> diff --git a/lib/ukmpi/ring.c b/lib/ukmpi/ring.c
> new file mode 100644
> index 0000000..1fbb81e
> --- /dev/null
> +++ b/lib/ukmpi/ring.c
> @@ -0,0 +1,87 @@
> +/* SPDX-License-Identifier: BSD-3-Clause */
> +/*
> + * Authors: Kip Macy <kmacy@freebsd.org>
> + *          Simon Kuenzer <simon.kuenzer@neclab.eu>
> + *          Alexander Jung <alexander.jung@neclab.eu>
> + *
> + * Copyright (c) 2007-2009, Kip Macy <kmacy@freebsd.org>
> + *               2018-2020, NEC Laboratories Europe GmbH, NEC Corporation.
> + *               All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + *
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in the
> + *    documentation and/or other materials provided with the distribution.
> + * 3. Neither the name of the copyright holder nor the names of its
> + *    contributors may be used to endorse or promote products derived from
> + *    this software without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + */
> +/*
> + * Simple ring implementation to handle object references.
> + *
> + * Inspired by FreeBSD and modified (commit-id: c45cce1).
> + */
> +
> +
> +#include <sys/param.h>
> +#include <uk/ring.h>
> +#include <uk/assert.h>
> +#include <uk/alloc.h>
> +#include <uk/mutex.h>
> +#include <uk/config.h>
> +#include <uk/print.h>
> +
> +#ifndef POWER_OF_2
> +#define POWER_OF_2(x)   (((x)) && (!((x) & ((x) - 1))))
> +#endif
> +
> +struct uk_ring *
> +uk_ring_alloc(int count, struct uk_alloc *a, int flags, struct uk_mutex *lock)
> +{
> +  struct uk_ring *br;
> +
> +  UK_ASSERT(a);
> +  /* Buf ring must be size power of 2 */
> +  UK_ASSERT(POWER_OF_2(count));
> +  
> +  br = uk_malloc(a, sizeof(struct uk_ring) + count * sizeof(caddr_t));
> +  if (br == NULL) {
> +    uk_pr_err("Could not allocate ring: out of memory\n");
> +    return NULL;
> +  }
> +
> +#ifdef CONFIG_LIBUKMPI_RING_DEBUG
> +  br->lock = lock;
> +#endif  
> +
> +  br->prod_size = br->cons_size = count;
> +  br->prod_mask = br->cons_mask = count - 1;
> +  br->prod_head = br->cons_head = 0;
> +  br->prod_tail = br->cons_tail = 0;
> +
> +  return br;
> +}
> +
> +void
> +uk_ring_free(struct uk_ring *br, struct uk_alloc *a)
> +{
> +  UK_ASSERT(a);
> +  uk_free(a, br);
> +}
> 


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 12:58:05 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 12:58:05 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxrqP-0003Ot-3T; Tue, 21 Jul 2020 12:58:05 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=NVI3=BA=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jxrqN-0003Ok-U0
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 12:58:03 +0000
X-Inumbo-ID: cf58392c-cb51-11ea-a0b6-12813bfff9fa
Received: from mx.upb.ro (unknown [141.85.13.200])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id cf58392c-cb51-11ea-a0b6-12813bfff9fa;
 Tue, 21 Jul 2020 12:58:02 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id B6DF4B5619E5;
 Tue, 21 Jul 2020 15:58:01 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id K3ci40wwPem7; Tue, 21 Jul 2020 15:58:00 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 065E9B561CCE;
 Tue, 21 Jul 2020 15:58:00 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id 4PgQEDrsmi8b; Tue, 21 Jul 2020 15:57:59 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id 64D85B5619E5;
 Tue, 21 Jul 2020 15:57:59 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH 5/5] lib/ukmpi: Export the global ring buffer
 (de)init methods
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200720164015.4715-1-a.jung@lancs.ac.uk>
 <20200720164015.4715-6-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <7df8099d-0421-eec8-6a83-fd7001125ff9@cs.pub.ro>
Date: Tue, 21 Jul 2020 15:57:59 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200720164015.4715-6-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

This patch can be squashed into the integration patch too.

Cheers,
Costin

On 7/20/20 7:40 PM, Alexander Jung wrote:
> From: Alexander Jung <alexander.jung@neclab.eu>
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/ukmpi/exportsyms.uk | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/lib/ukmpi/exportsyms.uk b/lib/ukmpi/exportsyms.uk
> index b0d661a..b50e1b2 100644
> --- a/lib/ukmpi/exportsyms.uk
> +++ b/lib/ukmpi/exportsyms.uk
> @@ -6,3 +6,6 @@ uk_mbox_post_to
>  uk_mbox_recv
>  uk_mbox_recv_try
>  uk_mbox_recv_to
> +
> +uk_ring_alloc
> +uk_ring_free
> 


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 13:37:48 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 13:37:48 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxsSn-00078V-D8; Tue, 21 Jul 2020 13:37:45 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=ETQF=BA=gmail.com=2309bmcristi@srs-us1.protection.inumbo.net>)
 id 1jxsSm-00078Q-G0
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 13:37:44 +0000
X-Inumbo-ID: 5965e6aa-cb57-11ea-851a-bc764e2007e4
Received: from mail-ed1-x52c.google.com (unknown [2a00:1450:4864:20::52c])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 5965e6aa-cb57-11ea-851a-bc764e2007e4;
 Tue, 21 Jul 2020 13:37:41 +0000 (UTC)
Received: by mail-ed1-x52c.google.com with SMTP id by13so15286893edb.11
 for <minios-devel@lists.xen.org>; Tue, 21 Jul 2020 06:37:41 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:cc:subject:date:message-id;
 bh=KVLcIIHmhGvlvHowtHbg358iCfitk/QcUpF69tRnxM0=;
 b=qDCFN91KblmQvlDdRB7IkvtsvqJM20MUhW98ONAQhcIF9f/vy/VK8UfkLhOyZ/ALYS
 A8e3hweXlSuTxmbRHrev9ZPGwcHxXhF64XuDxJ9WhkN0Lbybi3EPssTcrIzHgeD/UNzX
 q8gbVJZfpE4gBGsnB5wlo9rzCf8sODLUkFa7saUx3yfeMQj7XJNKn4uI4NXJ05gL7ljG
 wbz4Zpqn3ul4ZXzYgrQlDNHqnywFFcTf6I2OJHFJ8VX91kXMIDmPdDpwE6IG3f5g6oqY
 aet3jGbNjlG7qM76ghavcT2Tof4RIWkjlEj9nPbcxUMnvYSifHXKlKkBJwGM7aSRM9Z3
 2QGQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:date:message-id;
 bh=KVLcIIHmhGvlvHowtHbg358iCfitk/QcUpF69tRnxM0=;
 b=Wasa5Vk5YJ7+CNZi7EhABi9SZ8b85zF4VF1S07i5ijh7E5encA/pWzrvgbAHsriJpW
 PU3PAEBJGd4JfSJxv7sG7VVQaoMPMycVt5TMmMkbhMDHGg8d7jiYKVsz9wLVLDXnZZkZ
 a0oFuHZrBWil7cLZH+4LI+dKZMGcFUYKoVPDHdVeubNA/HWep7ocvg47v5CRgtqJD6+m
 aY+LL2rIFKttV0h299QY+HGtZhe8U+GhcxeS6MRPIWzZGGBTR1uXKL9aRei5TaDUlyBI
 jQCWeJ3dnCXrKG2gScU8H3zzInKGsKVSVovqV8R6czqK+IFwQNUWLAibXFkl4u3GoE4e
 otdg==
X-Gm-Message-State: AOAM5321ADOvIqpis9Hr6IBKnvwLVsICJEuAotsGoNWFEdUEP7O159PZ
 A0EuHqUTilPmAtCcXWMOHbVdSIwBUWI=
X-Google-Smtp-Source: ABdhPJy+496GqpUK5UYrAak0ohxuECLdnaFex8a9a4SN/CkZDuPuELKu4qmIqtl0k7X+vYEIhXe/jw==
X-Received: by 2002:a50:cc4c:: with SMTP id n12mr12953289edi.234.1595338660177; 
 Tue, 21 Jul 2020 06:37:40 -0700 (PDT)
Received: from localhost.localdomain ([2a02:2f07:8200:d200:e58e:e1b:b419:616c])
 by smtp.gmail.com with ESMTPSA id r5sm17478183edx.32.2020.07.21.06.37.38
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Tue, 21 Jul 2020 06:37:39 -0700 (PDT)
From: Marius-Cristian Baciu <2309bmcristi@gmail.com>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 1/3] libdruntime: Add support for unittests execution
 and solve minor paths-related typo
Date: Tue, 21 Jul 2020 16:37:28 +0300
Message-Id: <20200721133730.27234-1-2309bmcristi@gmail.com>
X-Mailer: git-send-email 2.17.1
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Marius-Cristian Baciu <2309bmcristi@gmail.com>, simon.kuenzer@neclab.eu
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

---
 Config.uk                                     |   7 +
 Makefile.uk                                   |   8 +-
 ...ow-faulty-runtime-internal-unittests.patch | 399 ++++++++++++++++++
 3 files changed, 412 insertions(+), 2 deletions(-)
 create mode 100644 patches/0001-Shadow-faulty-runtime-internal-unittests.patch

diff --git a/Config.uk b/Config.uk
index eff5bce..b17f80a 100644
--- a/Config.uk
+++ b/Config.uk
@@ -19,4 +19,11 @@ menuconfig LIBDRUNTIME
 	select LIBUCONTEXT
 
 if LIBDRUNTIME
+
+config UNITTESTS
+    bool "Run Unittests"
+    default n
+if UNITTESTS
+endif
+
 endif
diff --git a/Makefile.uk b/Makefile.uk
index 141cb74..fbeba3e 100644
--- a/Makefile.uk
+++ b/Makefile.uk
@@ -45,7 +45,7 @@ $(eval $(call addlib_s,libdruntimeglue,$(CONFIG_LIBDRUNTIME)))
 ################################################################################
 LIBDRUNTIME_VERSION=9.3.0
 
-LIBDRUNTIME_URL=https://ftp.gnu.org/gnu/gcc/gcc-$(LIBGCC_VERSION)/gcc-$(LIBGCC_VERSION).tar.gz
+LIBDRUNTIME_URL=https://ftp.gnu.org/gnu/gcc/gcc-$(LIBDRUNTIME_VERSION)/gcc-$(LIBDRUNTIME_VERSION).tar.gz
 
 LIBDRUNTIME_PATCHDIR=$(LIBDRUNTIME_BASE)/patches
 LIBDRUNTIME_SUBDIR=gcc-$(LIBDRUNTIME_VERSION)
@@ -57,7 +57,7 @@ $(eval $(call patch,libdruntime,$(LIBDRUNTIME_PATCHDIR),$(LIBDRUNTIME_SUBDIR)))
 ################################################################################
 # Helpers
 ################################################################################
-LIBDRUNTIME_EXTRACTED = $(LIBDRUNTIME_ORIGIN)/druntime
+LIBDRUNTIME_EXTRACTED = $(LIBDRUNTIME_ORIGIN)/$(LIBDRUNTIME_SUBDIR)
 
 ################################################################################
 # Library includes
@@ -94,6 +94,10 @@ LIBDRUNTIME_GDCFLAGS += -fexceptions -fnon-call-exceptions \
 	-fno-split-stack -Wall -Wextra -Wno-unused-function -minline-all-stringops
 LIBDRUNTIME_GDCFLAGS += -fversion=UNIKRAFT
 
+ifdef CONFIG_UNITTESTS
+	LIBDRUNTIME_GDCFLAGS += -funittest
+endif
+
 ################################################################################
 # druntime code
 ################################################################################
diff --git a/patches/0001-Shadow-faulty-runtime-internal-unittests.patch b/patches/0001-Shadow-faulty-runtime-internal-unittests.patch
new file mode 100644
index 0000000..c7c2788
--- /dev/null
+++ b/patches/0001-Shadow-faulty-runtime-internal-unittests.patch
@@ -0,0 +1,399 @@
+From 049d43f91e8ea7f34b5f6d0172d98a59adc902b2 Mon Sep 17 00:00:00 2001
+From: Marius-Cristian Baciu <2309bmcristi@gmail.com>
+Date: Sat, 18 Jul 2020 23:32:02 +0300
+Subject: [PATCH] Shadow faulty runtime internal unittests
+
+---
+ libphobos/libdruntime/core/atomic.d           |  3 +++
+ libphobos/libdruntime/core/internal/convert.d |  3 +++
+ libphobos/libdruntime/core/memory.d           |  5 ++++-
+ libphobos/libdruntime/core/sync/barrier.d     |  3 +++
+ libphobos/libdruntime/core/sync/condition.d   |  4 +++-
+ libphobos/libdruntime/core/sync/mutex.d       |  7 +++++++
+ libphobos/libdruntime/core/sync/rwmutex.d     |  3 +++
+ libphobos/libdruntime/core/sync/semaphore.d   |  3 +++
+ libphobos/libdruntime/core/thread.d           | 19 ++++++++++++++++++-
+ .../libdruntime/gc/impl/conservative/gc.d     |  4 +++-
+ libphobos/libdruntime/object.d                |  6 +++++-
+ libphobos/libdruntime/rt/minfo.d              |  4 +++-
+ .../libdruntime/rt/util/container/array.d     |  3 +++
+ libphobos/libdruntime/rt/util/typeinfo.d      |  5 ++++-
+ 14 files changed, 65 insertions(+), 7 deletions(-)
+
+diff --git a/libphobos/libdruntime/core/atomic.d b/libphobos/libdruntime/core/atomic.d
+index 1d0a2ea8b..544fc1e6a 100644
+--- a/libphobos/libdruntime/core/atomic.d
++++ b/libphobos/libdruntime/core/atomic.d
+@@ -1801,6 +1801,8 @@ version (unittest)
+         static assert(!__traits(compiles, cas(&ptr2, ifThis2, writeThis2)));
+     }
+ 
++version (ENABLE_FAULTY_UNITTESTS)
++{
+     unittest
+     {
+         import core.thread;
+@@ -1836,6 +1838,7 @@ version (unittest)
+ 
+         assert(*r == 42);
+     }
++}
+ 
+     // === atomicFetchAdd and atomicFetchSub operations ====
+     pure nothrow @nogc @safe unittest
+diff --git a/libphobos/libdruntime/core/internal/convert.d b/libphobos/libdruntime/core/internal/convert.d
+index 3b82010ab..3b89e6b75 100644
+--- a/libphobos/libdruntime/core/internal/convert.d
++++ b/libphobos/libdruntime/core/internal/convert.d
+@@ -708,6 +708,8 @@ const(ubyte)[] toUbyte(T)(const ref T val) if (is(T == enum))
+     }
+ }
+ 
++version (ENABLE_FAULTY_UNITTESTS)
++{
+ nothrow pure @safe unittest
+ {
+     // Issue 19008 - check toUbyte works on enums.
+@@ -716,6 +718,7 @@ nothrow pure @safe unittest
+     const bytes = toUbyte(m);
+     enum ctfe_works = (() => { Month x = Month.jan; return toUbyte(x).length > 0; })();
+ }
++}
+ 
+ @trusted pure nothrow @nogc
+ const(ubyte)[] toUbyte(T)(const ref T val) if (is(T == delegate) || is(T : V*, V) && __traits(getAliasThis, T).length == 0)
+diff --git a/libphobos/libdruntime/core/memory.d b/libphobos/libdruntime/core/memory.d
+index af0fee1a4..9afd93b83 100644
+--- a/libphobos/libdruntime/core/memory.d
++++ b/libphobos/libdruntime/core/memory.d
+@@ -901,9 +901,12 @@ void pureFree(void* ptr) @system pure @nogc nothrow
+ 
+     // subtract 2 because snn.lib adds 2 unconditionally before passing
+     //  the size to the Windows API
+-    void* z = pureMalloc(size_t.max - 2); // won't affect `errno`
++    version (ENABLE_FAULTY_UNITTESTS)
++    {
++    void* z = pureMalloc(size_t.max - 19); // won't affect `errno`
+     assert(errno == fakePureGetErrno()); // errno shouldn't change
+     assert(z is null);
++    }
+ }
+ 
+ // locally purified for internal use here only
+diff --git a/libphobos/libdruntime/core/sync/barrier.d b/libphobos/libdruntime/core/sync/barrier.d
+index dd54d5c75..132a51b4a 100644
+--- a/libphobos/libdruntime/core/sync/barrier.d
++++ b/libphobos/libdruntime/core/sync/barrier.d
+@@ -113,6 +113,8 @@ private:
+ ////////////////////////////////////////////////////////////////////////////////
+ 
+ 
++version (ENABLE_FAULTY_UNITTESTS)
++{
+ version (unittest)
+ {
+     private import core.thread;
+@@ -149,3 +151,4 @@ version (unittest)
+         assert( numReady == numThreads && numPassed == numThreads );
+     }
+ }
++}
+diff --git a/libphobos/libdruntime/core/sync/condition.d b/libphobos/libdruntime/core/sync/condition.d
+index 8afa8f7cc..aa1b806ad 100644
+--- a/libphobos/libdruntime/core/sync/condition.d
++++ b/libphobos/libdruntime/core/sync/condition.d
+@@ -601,7 +601,8 @@ version (unittest)
+         assert( !alertedTwo );
+     }
+ 
+-
++version (ENABLE_FAULTY_UNITTESTS)
++{
+     unittest
+     {
+         testNotify();
+@@ -609,3 +610,4 @@ version (unittest)
+         testWaitTimeout();
+     }
+ }
++}
+diff --git a/libphobos/libdruntime/core/sync/mutex.d b/libphobos/libdruntime/core/sync/mutex.d
+index 024009f48..80c3cb495 100644
+--- a/libphobos/libdruntime/core/sync/mutex.d
++++ b/libphobos/libdruntime/core/sync/mutex.d
+@@ -302,6 +302,9 @@ package:
+ ///
+ /* @safe nothrow -> see druntime PR 1726 */
+ // Test regular usage.
++
++version (ENABLE_FAULTY_UNITTESTS)
++{
+ unittest
+ {
+     import core.thread : Thread;
+@@ -341,6 +344,7 @@ unittest
+     assert (res.cargo == 20042);
+ }
+ 
++}
+ // Test @nogc usage.
+ @system @nogc nothrow unittest
+ {
+@@ -399,6 +403,8 @@ unittest
+     m.unlock();
+ }
+ 
++version (ENABLE_FAULTY_UNITTESTS)
++{
+ unittest
+ {
+     import core.thread;
+@@ -427,3 +433,4 @@ unittest
+     group.joinAll();
+     assert(lockCount == numThreads * numTries);
+ }
++}
+diff --git a/libphobos/libdruntime/core/sync/rwmutex.d b/libphobos/libdruntime/core/sync/rwmutex.d
+index ba94a9ee9..2ac442f77 100644
+--- a/libphobos/libdruntime/core/sync/rwmutex.d
++++ b/libphobos/libdruntime/core/sync/rwmutex.d
+@@ -391,6 +391,8 @@ private:
+ ////////////////////////////////////////////////////////////////////////////////
+ 
+ 
++version (ENABLE_FAULTY_UNITTESTS)
++{
+ unittest
+ {
+     import core.atomic, core.thread, core.sync.semaphore;
+@@ -526,3 +528,4 @@ unittest
+     runTest(ReadWriteMutex.Policy.PREFER_READERS);
+     runTest(ReadWriteMutex.Policy.PREFER_WRITERS);
+ }
++}
+diff --git a/libphobos/libdruntime/core/sync/semaphore.d b/libphobos/libdruntime/core/sync/semaphore.d
+index 56ac7dc36..e1a6af6f5 100644
+--- a/libphobos/libdruntime/core/sync/semaphore.d
++++ b/libphobos/libdruntime/core/sync/semaphore.d
+@@ -448,9 +448,12 @@ version (unittest)
+     }
+ 
+ 
++version (ENABLE_FAULTY_UNITTESTS)
++{
+     unittest
+     {
+         testWait();
+         testWaitTimeout();
+     }
+ }
++}
+diff --git a/libphobos/libdruntime/core/thread.d b/libphobos/libdruntime/core/thread.d
+index 3d2cd287a..edd86b4ac 100644
+--- a/libphobos/libdruntime/core/thread.d
++++ b/libphobos/libdruntime/core/thread.d
+@@ -1210,6 +1210,8 @@ class Thread
+     }
+ 
+ 
++version (ENABLE_FAULTY_UNITTESTS)
++{
+     unittest
+     {
+         auto thr = Thread.getThis();
+@@ -1236,6 +1238,7 @@ class Thread
+         assert(prio >= PRIORITY_MIN && prio <= PRIORITY_MAX);
+     }
+ 
++}
+     ///////////////////////////////////////////////////////////////////////////
+     // Actions on Calling Thread
+     ///////////////////////////////////////////////////////////////////////////
+@@ -1394,6 +1397,8 @@ class Thread
+         return 0;
+     }
+ 
++version (ENABLE_FAULTY_UNITTESTS)
++{
+     unittest
+     {
+         auto t1 = new Thread({
+@@ -1407,6 +1412,7 @@ class Thread
+         t1.join();
+         t2.join();
+     }
++}
+ 
+     private static Thread[] getAllImpl(alias resize)()
+     {
+@@ -1909,6 +1915,8 @@ private:
+ }
+ 
+ ///
++version (ENABLE_FAULTY_UNITTESTS)
++{
+ unittest
+ {
+     class DerivedThread : Thread
+@@ -1968,7 +1976,7 @@ unittest
+         assert( t.msg == MSG );
+     }
+ }
+-
++}
+ 
+ ///////////////////////////////////////////////////////////////////////////////
+ // GC Support Routines
+@@ -2278,6 +2286,8 @@ extern (C) void thread_detachInstance( Thread t ) nothrow @nogc
+ }
+ 
+ 
++version (ENABLE_FAULTY_UNITTESTS)
++{
+ unittest
+ {
+     import core.sync.semaphore;
+@@ -2295,6 +2305,7 @@ unittest
+         assert(t !is t2);
+     t.join();
+ }
++}
+ 
+ 
+ /**
+@@ -3068,6 +3079,8 @@ private void onThreadError(string msg = null, Throwable next = null) nothrow
+ }
+ 
+ 
++version (ENABLE_FAULTY_UNITTESTS)
++{
+ unittest
+ {
+     assert(!thread_inCriticalRegion());
+@@ -3159,6 +3172,7 @@ unittest
+     assert(!inCriticalRegion);
+     thread_resumeAll();
+ }
++}
+ 
+ /**
+  * Indicates whether an address has been marked by the GC.
+@@ -5207,6 +5221,8 @@ private:
+ }
+ 
+ 
++version (ENABLE_FAULTY_UNITTESTS)
++{
+ version (unittest)
+ {
+     class TestFiber : Fiber
+@@ -5681,6 +5697,7 @@ unittest
+     auto thr = new Thread(function{}, 4096 + 1).start();
+     thr.join();
+ }
++}
+ 
+ /**
+  * Represents the ID of a thread, as returned by $(D Thread.)$(LREF id).
+diff --git a/libphobos/libdruntime/gc/impl/conservative/gc.d b/libphobos/libdruntime/gc/impl/conservative/gc.d
+index b7bb9b0c3..1980a410d 100644
+--- a/libphobos/libdruntime/gc/impl/conservative/gc.d
++++ b/libphobos/libdruntime/gc/impl/conservative/gc.d
+@@ -3373,6 +3373,8 @@ unittest
+ }
+ 
+ // improve predictability of coverage of code that is eventually not hit by other tests
++version (ENABLE_FAULTY_UNITTESTS)
++{
+ unittest
+ {
+     import core.memory;
+@@ -3410,4 +3412,4 @@ unittest
+     GC.free(z);
+     GC.minimize(); // release huge pool
+ }
+-
++}
+diff --git a/libphobos/libdruntime/object.d b/libphobos/libdruntime/object.d
+index d7588dccb..78f739b5a 100644
+--- a/libphobos/libdruntime/object.d
++++ b/libphobos/libdruntime/object.d
+@@ -2581,7 +2581,10 @@ unittest
+ 
+ // Test handling of failed postblit
+ // Not nothrow or @safe because of https://issues.dlang.org/show_bug.cgi?id=14242
+-/+ nothrow @safe +/ unittest
++/+ nothrow @safe +/ 
++version (ENABLE_FAULTY_UNITTESTS)
++{
++unittest
+ {
+     static class FailedPostblitException : Exception { this() nothrow @safe { super(null); } }
+     static string[] order;
+@@ -2657,6 +2660,7 @@ unittest
+ 
+     assert(postblitRecurseOrder == order);
+ }
++}
+ 
+ /++
+     Destroys the given object and puts it in an invalid state. It's used to
+diff --git a/libphobos/libdruntime/rt/minfo.d b/libphobos/libdruntime/rt/minfo.d
+index 548bcc71c..e2b2cfd88 100644
+--- a/libphobos/libdruntime/rt/minfo.d
++++ b/libphobos/libdruntime/rt/minfo.d
+@@ -868,6 +868,8 @@ void runModuleFuncsRev(alias getfp)(const(immutable(ModuleInfo)*)[] modules)
+     }
+ }
+ 
++version (ENABLE_FAULTY_UNITTESTS)
++{
+ unittest
+ {
+     static void assertThrown(T : Throwable, E)(lazy E expr, string msg)
+@@ -1109,7 +1111,7 @@ unittest
+         //checkExp("closed ctors cycle", false, [&m0.mi, &m1.mi, &m2.mi], [&m0.mi, &m1.mi, &m2.mi]);
+     }
+ }
+-
++}
+ version (CRuntime_Microsoft)
+ {
+     // Dummy so Win32 code can still call it
+diff --git a/libphobos/libdruntime/rt/util/container/array.d b/libphobos/libdruntime/rt/util/container/array.d
+index f5aa3d753..a64d068f3 100644
+--- a/libphobos/libdruntime/rt/util/container/array.d
++++ b/libphobos/libdruntime/rt/util/container/array.d
+@@ -208,6 +208,8 @@ unittest
+     assert(cnt == 0);
+ }
+ 
++version (ENABLE_FAULTY_UNITTESTS)
++{
+ unittest
+ {
+     import core.exception;
+@@ -230,3 +232,4 @@ unittest
+     {
+     }
+ }
++}
+diff --git a/libphobos/libdruntime/rt/util/typeinfo.d b/libphobos/libdruntime/rt/util/typeinfo.d
+index 2cc1c236c..561efc4b2 100644
+--- a/libphobos/libdruntime/rt/util/typeinfo.d
++++ b/libphobos/libdruntime/rt/util/typeinfo.d
+@@ -225,7 +225,10 @@ unittest
+             assert(f1 == 0 + 0i);
+ 
+             assert(f1 == f2);
+-            assert(f1 !is f2);
++            version (ENABLE_FAULTY_UNITTESTS)
++            {
++                assert(f1 !is f2);
++            }
+             ti = typeid(F);
+             assert(ti.getHash(&f1) == ti.getHash(&f2));
+ 
+-- 
+2.17.1
+
-- 
2.17.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 13:37:50 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 13:37:50 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxsSs-000794-G0; Tue, 21 Jul 2020 13:37:50 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=ETQF=BA=gmail.com=2309bmcristi@srs-us1.protection.inumbo.net>)
 id 1jxsSr-00078Q-E6
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 13:37:49 +0000
X-Inumbo-ID: 5d4670dc-cb57-11ea-851a-bc764e2007e4
Received: from mail-ej1-x62c.google.com (unknown [2a00:1450:4864:20::62c])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 5d4670dc-cb57-11ea-851a-bc764e2007e4;
 Tue, 21 Jul 2020 13:37:48 +0000 (UTC)
Received: by mail-ej1-x62c.google.com with SMTP id w6so21666601ejq.6
 for <minios-devel@lists.xen.org>; Tue, 21 Jul 2020 06:37:48 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:cc:subject:date:message-id:in-reply-to:references;
 bh=i8qw0IVLpOyvVDlxPhv8A6GIGt8Baa3oqZBhc5D/TwU=;
 b=LWlbLOzar+xqnRR31zB3VZ7ifWmrFXAZQK9zJOgMh7WiwFSDH36KplaC178GeDot9g
 2jDPZYQiYijkitOg95TiVh7PrRDHFVIC6V7y3QWSkOEy3QSw8jkUuwyzLxQ4KqTiwj/r
 ZYgAnIgDzG80fRICUhRUCAxypSJm4lUizBadI5Uj80rgIwO65mWwmMPdor9Qmpir7gWS
 QSJeky8kgDMsJiIgaAJrijoPlwnT8vSvV+NYoJc+hu/8K5Cct4adu5a18uHfatcI+oUQ
 tLKqg5DzQcLBUyXcyE0biA70GkdYn35IsIquMnJkynzu4/dwgiSiPd0R3uWfamMnibpq
 0p5w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
 :references;
 bh=i8qw0IVLpOyvVDlxPhv8A6GIGt8Baa3oqZBhc5D/TwU=;
 b=BierzBEGlWStVGDEp6GyDQQPaEvwFuZA5Q8r1hUbqpjUAHCbTZ5olQrZfzDXSovC92
 5+9WQotThZslKtLeCbD4hda3RZ/0n/DEvlBlkFpQZNg+4UA8qEIFfxcYCaX5OVzr9Urv
 KUs++7Oh0MgiwW2hd/JtCSS2ntqqJHYvlPjL+oMNH8ozGL6tIba/+vcBsEgPd+Eo/hFL
 gnVpJ9Fxc2A38F/pRTejAo7cOtRRogK8I2d8W892Zlvs3xXav013HVknOI9H16K6uptS
 g2IO1BkFUwmyMwwjAkiq3QueAIWqewomCRMgC9UtL6VGJAroByYKWNFfgN3wCa0p1FhM
 wwHw==
X-Gm-Message-State: AOAM532mOzf1fsxEfg2WA4K9n1n/LwyloPhzv/1X8O/bmGntWE6E8pC1
 e1w9xFcdHHk5qgjKjV4m0XPlCpX/6cs=
X-Google-Smtp-Source: ABdhPJzq6bNzYm7DmsdaHtN2u7q3urLH1Q7k/V3tV1EfnG8UdMQ1TbRX8ITr2/afh8tmi+YDoit7lA==
X-Received: by 2002:a17:906:9354:: with SMTP id
 p20mr24537583ejw.187.1595338666952; 
 Tue, 21 Jul 2020 06:37:46 -0700 (PDT)
Received: from localhost.localdomain ([2a02:2f07:8200:d200:e58e:e1b:b419:616c])
 by smtp.gmail.com with ESMTPSA id r5sm17478183edx.32.2020.07.21.06.37.45
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Tue, 21 Jul 2020 06:37:46 -0700 (PDT)
From: Marius-Cristian Baciu <2309bmcristi@gmail.com>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 2/3] libdruntime: Expose standard file descriptors
 symbols to the runtime
Date: Tue, 21 Jul 2020 16:37:29 +0300
Message-Id: <20200721133730.27234-2-2309bmcristi@gmail.com>
X-Mailer: git-send-email 2.17.1
In-Reply-To: <20200721133730.27234-1-2309bmcristi@gmail.com>
References: <20200721133730.27234-1-2309bmcristi@gmail.com>
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Marius-Cristian Baciu <2309bmcristi@gmail.com>, simon.kuenzer@neclab.eu
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

---
 gluecode.c                                    | 10 +++
 ...ndard-descriptors-visibility-problem.patch | 62 +++++++++++++++++++
 2 files changed, 72 insertions(+)
 create mode 100644 patches/0002-Solve-standard-descriptors-visibility-problem.patch

diff --git a/gluecode.c b/gluecode.c
index 952d14d..7bd174c 100644
--- a/gluecode.c
+++ b/gluecode.c
@@ -45,6 +45,16 @@
 #include <math.h>
 
 
+FILE *_stdin;
+FILE *_stdout;
+FILE *_stderr;
+
+void initStdIO() {
+    _stdin = stdin;
+    _stdout = stdout;
+    _stderr = stderr;
+}
+
 typedef __sigset_t  sigset_t;
 int sigfillset(sigset_t *set)
 {
diff --git a/patches/0002-Solve-standard-descriptors-visibility-problem.patch b/patches/0002-Solve-standard-descriptors-visibility-problem.patch
new file mode 100644
index 0000000..1b9722f
--- /dev/null
+++ b/patches/0002-Solve-standard-descriptors-visibility-problem.patch
@@ -0,0 +1,62 @@
+From 356f85a077adfcb4a1c66163b7d3a2c38a1667b3 Mon Sep 17 00:00:00 2001
+From: Marius-Cristian Baciu <2309bmcristi@gmail.com>
+Date: Sat, 18 Jul 2020 23:58:35 +0300
+Subject: [PATCH] Solve standard descriptors visibility problem
+
+initStdio() is a routine we have defined in D runtime lib's gluecode.c
+---
+ libphobos/libdruntime/core/stdc/stdio.d | 10 +++++++---
+ libphobos/libdruntime/rt/dmain2.d       |  7 +++++++
+ 2 files changed, 14 insertions(+), 3 deletions(-)
+
+diff --git a/libphobos/libdruntime/core/stdc/stdio.d b/libphobos/libdruntime/core/stdc/stdio.d
+index 6ce3f9d13..8ed585bcb 100644
+--- a/libphobos/libdruntime/core/stdc/stdio.d
++++ b/libphobos/libdruntime/core/stdc/stdio.d
+@@ -907,11 +907,15 @@ else version (CRuntime_Glibc)
+     }
+ 
+     ///
+-    extern shared FILE* stdin;
++    extern shared FILE* _stdin;
+     ///
+-    extern shared FILE* stdout;
++    extern shared FILE* _stdout;
+     ///
+-    extern shared FILE* stderr;
++    extern shared FILE* _stderr;
++
++    alias _stdin    stdin;
++    alias _stdout   stdout;
++    alias _stderr   stderr;
+ }
+ else version (Darwin)
+ {
+diff --git a/libphobos/libdruntime/rt/dmain2.d b/libphobos/libdruntime/rt/dmain2.d
+index f45565c97..7e42b63fb 100644
+--- a/libphobos/libdruntime/rt/dmain2.d
++++ b/libphobos/libdruntime/rt/dmain2.d
+@@ -156,6 +156,10 @@ extern (C) __gshared bool rt_trapExceptions = true;
+ 
+ alias void delegate(Throwable) ExceptionHandler;
+ 
++version (UNIKRAFT) {
++    extern (C) void initStdIO();
++}
++
+ /**
+  * Keep track of how often rt_init/rt_term were called.
+  */
+@@ -168,6 +172,9 @@ shared size_t _initCount;
+  */
+ extern (C) int rt_init()
+ {
++    version (UNIKRAFT) {
++        initStdIO();
++    }
+     /* @@BUG 11380 @@ Need to synchronize rt_init/rt_term calls for
+        version (Shared) druntime, because multiple C threads might
+        initialize different D libraries without knowing about the
+-- 
+2.17.1
+
-- 
2.17.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 13:37:55 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 13:37:55 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxsSx-00079r-Hm; Tue, 21 Jul 2020 13:37:55 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=ETQF=BA=gmail.com=2309bmcristi@srs-us1.protection.inumbo.net>)
 id 1jxsSw-00078Q-EF
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 13:37:54 +0000
X-Inumbo-ID: 5efd2f38-cb57-11ea-851a-bc764e2007e4
Received: from mail-ej1-x643.google.com (unknown [2a00:1450:4864:20::643])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 5efd2f38-cb57-11ea-851a-bc764e2007e4;
 Tue, 21 Jul 2020 13:37:50 +0000 (UTC)
Received: by mail-ej1-x643.google.com with SMTP id w9so7549411ejc.8
 for <minios-devel@lists.xen.org>; Tue, 21 Jul 2020 06:37:50 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:cc:subject:date:message-id:in-reply-to:references;
 bh=AQEyJvAsLz7zlcYcrI5xFBVoPXQYT+RP4PHvnWMptIU=;
 b=CJWAEgM22ZQgfHl4gx+TZOBbOIUdrI76nVsI1oV1J5WUIhnLSVi7k+X+0siUHDyuRl
 M3aW5Z0O7HjSftT4B6dca5anGb6jGtpK1kHnUoIzNVxKyR7UlTY1rXWcqn5tad3+kel6
 0kLGZnAqf1l9afVgx1EjwPkjr6k8q9XESROGIzYiRfaJttYxVDzE2ScMzmHGUTiN7cef
 W4fVtHNwH3OBTvn77X5ECjlMvZsSvph+Wf51P0FxkfMUjoSyNkPFWpT5u5Jv952D7HM1
 rm0WxfeV2hFqjaNx5UNZFwaa72aSZd3eAm3dlEgftKjEuyRX5K6R9aj+qOcOkCYJVauq
 ZFxw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
 :references;
 bh=AQEyJvAsLz7zlcYcrI5xFBVoPXQYT+RP4PHvnWMptIU=;
 b=A34/g13b5o7Gh1bM03UaEvBLpD88h9NIxmdmeGo5i+XL05nHTPfrbCACdQH9awZfzI
 GGJ4viSXKkoI1Y2dAfZo4Bk5Dw8gcx7XbIGuittFH5GawW/Bi7oQtk/qdYizHmaQU3FJ
 l4GOIPnQO753OSivfdYfChIhLMZlV0yzz/37MU+aBZ8Qm8ihRpBFRh46UOLE9PZpKr4+
 Ozexhr/HB0sMSpwEqJu2AOPWhN4H59p6ZwwuLn9Osj9wu1f2OcOfEM/Ri3Wforas3tMv
 F3ZaEtoq3HUf4zxzOpb+Ohh6M45qpug+g8cadh+4vmu9KeMRaZ3JUFdw2c72Dqsgi+Xi
 AhZA==
X-Gm-Message-State: AOAM530p88cd12sdxbagK2ihiE2CW73feeJE0sl6OTGenD5ivwLK7WE9
 BgQDSAAlHvFSpaX+6JFc0qOv4I74Co8=
X-Google-Smtp-Source: ABdhPJx4QkWbBfV59jIyuH5L8gMVsuIz9Cmk9PwIMTXRWhpSzz0t0HHvy32noIMM0S4Fu6bJ1BNqDg==
X-Received: by 2002:a17:906:375a:: with SMTP id
 e26mr26566832ejc.324.1595338669620; 
 Tue, 21 Jul 2020 06:37:49 -0700 (PDT)
Received: from localhost.localdomain ([2a02:2f07:8200:d200:e58e:e1b:b419:616c])
 by smtp.gmail.com with ESMTPSA id r5sm17478183edx.32.2020.07.21.06.37.48
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Tue, 21 Jul 2020 06:37:49 -0700 (PDT)
From: Marius-Cristian Baciu <2309bmcristi@gmail.com>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 3/3] libdruntime: Add patches dealing with bugs and
 various incompatibilities with the platform
Date: Tue, 21 Jul 2020 16:37:30 +0300
Message-Id: <20200721133730.27234-3-2309bmcristi@gmail.com>
X-Mailer: git-send-email 2.17.1
In-Reply-To: <20200721133730.27234-1-2309bmcristi@gmail.com>
References: <20200721133730.27234-1-2309bmcristi@gmail.com>
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Marius-Cristian Baciu <2309bmcristi@gmail.com>, simon.kuenzer@neclab.eu
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

---
 ...0003-Add-builtin-symbols-definitions.patch | 78 +++++++++++++++++++
 patches/0004-Solve-stdio.d-unittest-bug.patch | 27 +++++++
 patches/0005-Solve-clock-routine-bug.patch    | 28 +++++++
 ...patibility-in-clock-related-unittest.patch | 26 +++++++
 ...ilities-in-networking-related-struct.patch | 51 ++++++++++++
 ...0008-Solve-mmap64-missing-dependency.patch | 38 +++++++++
 ...ilities-preventing-the-GC-from-scann.patch | 43 ++++++++++
 7 files changed, 291 insertions(+)
 create mode 100644 patches/0003-Add-builtin-symbols-definitions.patch
 create mode 100644 patches/0004-Solve-stdio.d-unittest-bug.patch
 create mode 100644 patches/0005-Solve-clock-routine-bug.patch
 create mode 100644 patches/0006-Solve-incompatibility-in-clock-related-unittest.patch
 create mode 100644 patches/0007-Solve-incompatibilities-in-networking-related-struct.patch
 create mode 100644 patches/0008-Solve-mmap64-missing-dependency.patch
 create mode 100644 patches/0009-Solve-incompatibilities-preventing-the-GC-from-scann.patch

diff --git a/patches/0003-Add-builtin-symbols-definitions.patch b/patches/0003-Add-builtin-symbols-definitions.patch
new file mode 100644
index 0000000..1133eec
--- /dev/null
+++ b/patches/0003-Add-builtin-symbols-definitions.patch
@@ -0,0 +1,78 @@
+From 4bf8ec9f1ac59ff85f00189f87fc74d67d79caa4 Mon Sep 17 00:00:00 2001
+From: Marius-Cristian Baciu <2309bmcristi@gmail.com>
+Date: Sun, 19 Jul 2020 02:52:02 +0300
+Subject: [PATCH 1/6] Add builtin symbols definitions
+
+---
+ libphobos/libdruntime/core/atomic.d  |  8 ++++----
+ libphobos/libdruntime/gcc/builtins.d | 24 ++++++++++++++++++++++++
+ 2 files changed, 28 insertions(+), 4 deletions(-)
+
+diff --git a/libphobos/libdruntime/core/atomic.d b/libphobos/libdruntime/core/atomic.d
+index 544fc1e6a..bcbfd85e9 100644
+--- a/libphobos/libdruntime/core/atomic.d
++++ b/libphobos/libdruntime/core/atomic.d
+@@ -1374,8 +1374,8 @@ else version (GNU)
+             }
+             else static if (T.sizeof == long.sizeof && GNU_Have_64Bit_Atomics)
+             {
+-                res = __atomic_compare_exchange_8(here, cast(void*) &ifThis, *cast(ulong*) &writeThis,
+-                                                  false, MemoryOrder.seq, MemoryOrder.seq);
++                res = __atomic_compare_exchange(T.sizeof, cast(void *)here, cast(void*)&ifThis,
++                        cast(void *) &writeThis, MemoryOrder.seq, MemoryOrder.seq);
+             }
+             else static if (GNU_Have_LibAtomic)
+             {
+@@ -1458,7 +1458,7 @@ else version (GNU)
+             else static if (GNU_Have_LibAtomic)
+             {
+                 T value;
+-                __atomic_load(T.sizeof, &val, cast(void*)&value, ms);
++                __atomic_load(T.sizeof, cast(void *)&val, cast(void*)&value, ms);
+                 return *cast(HeadUnshared!T*) &value;
+             }
+             else
+@@ -1499,7 +1499,7 @@ else version (GNU)
+             }
+             else static if (GNU_Have_LibAtomic)
+             {
+-                __atomic_store(T.sizeof, &val, cast(void*)&newval, ms);
++                __atomic_store(T.sizeof, cast(void *)&val, cast(void*)&newval, ms);
+             }
+             else
+                 static assert(0, "Invalid template type specified.");
+diff --git a/libphobos/libdruntime/gcc/builtins.d b/libphobos/libdruntime/gcc/builtins.d
+index 0cacf7afc..ce1a6cb24 100644
+--- a/libphobos/libdruntime/gcc/builtins.d
++++ b/libphobos/libdruntime/gcc/builtins.d
+@@ -42,3 +42,27 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+  */
+ 
+ module gcc.builtins;
++
++public alias __builtin_clonglong  = long;
++public alias __builtin_culonglong = ulong;
++
++extern (C) void __atomic_store_c(int size, void *dest, void *src, int model) pure nothrow @nogc;
++
++void __atomic_store(int size, void *dest, void *src, int model) pure nothrow @nogc {
++    __atomic_store_c(size, dest, src, model);
++}
++
++extern (C) int __atomic_compare_exchange_c(int size, void *dest, void *src, void *desired,
++                        int success, int failure) pure nothrow @nogc;
++
++bool __atomic_compare_exchange(int size, void *dest, void *src, void *desired,
++                        int success, int failure) pure nothrow @nogc {
++    return cast(bool)__atomic_compare_exchange_c(size, dest, src, desired, success, failure);
++}
++
++extern (C) void __atomic_load_c(int size, void *dest, void *src, int model) pure nothrow @nogc @trusted;
++
++void __atomic_load(int size, void *dest, void *src, int model) pure nothrow @nogc {
++    __atomic_load_c(size, dest, src, model);
++}
++
+-- 
+2.17.1
+
diff --git a/patches/0004-Solve-stdio.d-unittest-bug.patch b/patches/0004-Solve-stdio.d-unittest-bug.patch
new file mode 100644
index 0000000..ae1a074
--- /dev/null
+++ b/patches/0004-Solve-stdio.d-unittest-bug.patch
@@ -0,0 +1,27 @@
+From b4f89ed1deadd32b000d2cfb11763608acbccc93 Mon Sep 17 00:00:00 2001
+From: Marius-Cristian Baciu <2309bmcristi@gmail.com>
+Date: Sun, 19 Jul 2020 02:53:54 +0300
+Subject: [PATCH 2/6] Solve stdio.d unittest bug
+
+open_wmemstream() guarantees a NULL byte at the end of the buffer,
+but the memcmp() call expects last 4 bytes to be NULL
+---
+ libphobos/libdruntime/core/sys/posix/stdio.d | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/libphobos/libdruntime/core/sys/posix/stdio.d b/libphobos/libdruntime/core/sys/posix/stdio.d
+index 0c6a144f5..7a070aaf6 100644
+--- a/libphobos/libdruntime/core/sys/posix/stdio.d
++++ b/libphobos/libdruntime/core/sys/posix/stdio.d
+@@ -485,7 +485,7 @@ unittest
+     assert(f !is null);
+     assert(fwprintf(f, testdata.ptr) == 5);
+     assert(fflush(f) == 0);
+-    assert(memcmp(ptr, testdata.ptr, testdata.length*wchar_t.sizeof) == 0);
++    assert(memcmp(ptr, testdata.ptr, (testdata.length - 1)*wchar_t.sizeof) == 0);
+     assert(fclose(f) == 0);
+ }
+ 
+-- 
+2.17.1
+
diff --git a/patches/0005-Solve-clock-routine-bug.patch b/patches/0005-Solve-clock-routine-bug.patch
new file mode 100644
index 0000000..53ae32a
--- /dev/null
+++ b/patches/0005-Solve-clock-routine-bug.patch
@@ -0,0 +1,28 @@
+From 18e75c8e7e6b61ed235fa7279b448a4951f09413 Mon Sep 17 00:00:00 2001
+From: Marius-Cristian Baciu <2309bmcristi@gmail.com>
+Date: Sun, 19 Jul 2020 03:05:49 +0300
+Subject: [PATCH 3/6] Solve clock routine bug
+
+clock_getres() returning 0 results in a floating point exception
+---
+ libphobos/libdruntime/core/time.d | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/libphobos/libdruntime/core/time.d b/libphobos/libdruntime/core/time.d
+index a7640ec19..bdcf6cdd6 100644
+--- a/libphobos/libdruntime/core/time.d
++++ b/libphobos/libdruntime/core/time.d
+@@ -2813,8 +2813,8 @@ struct TickDuration
+                     //or worse, but the time is updated much more frequently
+                     //than that). In such cases, we'll just use nanosecond
+                     //resolution.
+-                    ticksPerSec = ts.tv_nsec >= 1000 ? 1_000_000_000
+-                                                     : 1_000_000_000 / ts.tv_nsec;
++                    ticksPerSec = ts.tv_nsec >= 1000 || ts.tv_nsec == 0
++                        ? 1_000_000_000 : 1_000_000_000 / ts.tv_nsec;
+                 }
+             }
+             else
+-- 
+2.17.1
+
diff --git a/patches/0006-Solve-incompatibility-in-clock-related-unittest.patch b/patches/0006-Solve-incompatibility-in-clock-related-unittest.patch
new file mode 100644
index 0000000..f3dd416
--- /dev/null
+++ b/patches/0006-Solve-incompatibility-in-clock-related-unittest.patch
@@ -0,0 +1,26 @@
+From 5c36f87b3c961d8210fc73675360c45ec7eea523 Mon Sep 17 00:00:00 2001
+From: Marius-Cristian Baciu <2309bmcristi@gmail.com>
+Date: Sun, 19 Jul 2020 03:08:19 +0300
+Subject: [PATCH 4/6] Solve incompatibility in clock-related unittest
+
+Not all types of clocks are supported in Unikraft
+---
+ libphobos/libdruntime/core/time.d | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/libphobos/libdruntime/core/time.d b/libphobos/libdruntime/core/time.d
+index bdcf6cdd6..a3c463db2 100644
+--- a/libphobos/libdruntime/core/time.d
++++ b/libphobos/libdruntime/core/time.d
+@@ -2544,6 +2544,8 @@ unittest
+         // common denominator supported by all versions of Linux pre-2.6.12.
+         version (Linux_Pre_2639)
+             return c == ClockType.normal || c == ClockType.precise;
++        else version (UNIKRAFT)
++            return c == ClockType.normal || c == ClockType.precise;
+         else
+             return c != ClockType.second; // second doesn't work with MonoTimeImpl
+ 
+-- 
+2.17.1
+
diff --git a/patches/0007-Solve-incompatibilities-in-networking-related-struct.patch b/patches/0007-Solve-incompatibilities-in-networking-related-struct.patch
new file mode 100644
index 0000000..496dd0c
--- /dev/null
+++ b/patches/0007-Solve-incompatibilities-in-networking-related-struct.patch
@@ -0,0 +1,51 @@
+From 2a75214e0d16fff5e968364f156d7027680a2276 Mon Sep 17 00:00:00 2001
+From: Marius-Cristian Baciu <2309bmcristi@gmail.com>
+Date: Sun, 19 Jul 2020 03:09:57 +0300
+Subject: [PATCH 5/6] Solve incompatibilities in networking-related structures
+ between the runtime and lwip library
+
+---
+ libphobos/libdruntime/core/sys/posix/netinet/in_.d | 4 ++--
+ libphobos/libdruntime/core/sys/posix/sys/socket.d  | 3 ++-
+ 2 files changed, 4 insertions(+), 3 deletions(-)
+
+diff --git a/libphobos/libdruntime/core/sys/posix/netinet/in_.d b/libphobos/libdruntime/core/sys/posix/netinet/in_.d
+index 82da6c702..a24981d80 100644
+--- a/libphobos/libdruntime/core/sys/posix/netinet/in_.d
++++ b/libphobos/libdruntime/core/sys/posix/netinet/in_.d
+@@ -90,13 +90,13 @@ version (CRuntime_Glibc)
+ 
+     struct sockaddr_in
+     {
++        ubyte       sin_len;
+         sa_family_t sin_family;
+         in_port_t   sin_port;
+         in_addr     sin_addr;
+ 
+         /* Pad to size of `struct sockaddr'. */
+-        ubyte[__SOCK_SIZE__ - sa_family_t.sizeof -
+-              in_port_t.sizeof - in_addr.sizeof] __pad;
++        ubyte[8] __pad;
+     }
+ 
+     enum
+diff --git a/libphobos/libdruntime/core/sys/posix/sys/socket.d b/libphobos/libdruntime/core/sys/posix/sys/socket.d
+index 197f1d6f7..743d59f2f 100644
+--- a/libphobos/libdruntime/core/sys/posix/sys/socket.d
++++ b/libphobos/libdruntime/core/sys/posix/sys/socket.d
+@@ -162,10 +162,11 @@ version (CRuntime_Glibc)
+     // Some of the constants below and from the Bionic section are really from
+     // the linux kernel headers.
+     alias uint   socklen_t;
+-    alias ushort sa_family_t;
++    alias ubyte sa_family_t;
+ 
+     struct sockaddr
+     {
++        ubyte       sa_len;
+         sa_family_t sa_family;
+         byte[14]    sa_data;
+     }
+-- 
+2.17.1
+
diff --git a/patches/0008-Solve-mmap64-missing-dependency.patch b/patches/0008-Solve-mmap64-missing-dependency.patch
new file mode 100644
index 0000000..dc8782d
--- /dev/null
+++ b/patches/0008-Solve-mmap64-missing-dependency.patch
@@ -0,0 +1,38 @@
+From 889f9ea51a7158c4fa9fe9efcc3ffaf0e23bd294 Mon Sep 17 00:00:00 2001
+From: Marius-Cristian Baciu <2309bmcristi@gmail.com>
+Date: Mon, 20 Jul 2020 01:01:14 +0300
+Subject: [PATCH 1/2] Solve mmap64() missing dependency
+
+---
+ libphobos/libdruntime/core/sys/posix/sys/mman.d | 15 ++++++++++-----
+ 1 file changed, 10 insertions(+), 5 deletions(-)
+
+diff --git a/libphobos/libdruntime/core/sys/posix/sys/mman.d b/libphobos/libdruntime/core/sys/posix/sys/mman.d
+index c0bee5528..618e9974c 100644
+--- a/libphobos/libdruntime/core/sys/posix/sys/mman.d
++++ b/libphobos/libdruntime/core/sys/posix/sys/mman.d
+@@ -234,11 +234,16 @@ int munmap(void*, size_t);
+ 
+ version (CRuntime_Glibc)
+ {
+-    static if (__USE_LARGEFILE64) void* mmap64(void*, size_t, int, int, int, off_t);
+-    static if (__USE_FILE_OFFSET64)
+-        alias mmap = mmap64;
+-    else
+-        void* mmap(void*, size_t, int, int, int, off_t);
++    version (UNIKRAFT) {
++        void *mmap(void *, size_t, int, int, int, off_t);
++        alias mmap mmap64;
++    } else {
++        static if (__USE_LARGEFILE64) void* mmap64(void*, size_t, int, int, int, off_t);
++        static if (__USE_FILE_OFFSET64)
++            alias mmap = mmap64;
++        else
++            void* mmap(void*, size_t, int, int, int, off_t);
++    }
+     int munmap(void*, size_t);
+ }
+ else version (Darwin)
+-- 
+2.17.1
+
diff --git a/patches/0009-Solve-incompatibilities-preventing-the-GC-from-scann.patch b/patches/0009-Solve-incompatibilities-preventing-the-GC-from-scann.patch
new file mode 100644
index 0000000..5053b32
--- /dev/null
+++ b/patches/0009-Solve-incompatibilities-preventing-the-GC-from-scann.patch
@@ -0,0 +1,43 @@
+From 32e379f4cf43c9542524330fdaef87da2476f38a Mon Sep 17 00:00:00 2001
+From: Marius-Cristian Baciu <2309bmcristi@gmail.com>
+Date: Mon, 20 Jul 2020 19:08:14 +0300
+Subject: [PATCH] Solve incompatibilities preventing the GC from scanning the
+ stack
+
+---
+ libphobos/libdruntime/core/sys/posix/sys/types.d | 6 +++++-
+ libphobos/libdruntime/core/thread.d              | 1 +
+ 2 files changed, 6 insertions(+), 1 deletion(-)
+
+diff --git a/libphobos/libdruntime/core/sys/posix/sys/types.d b/libphobos/libdruntime/core/sys/posix/sys/types.d
+index 060b56f88..c5cc17941 100644
+--- a/libphobos/libdruntime/core/sys/posix/sys/types.d
++++ b/libphobos/libdruntime/core/sys/posix/sys/types.d
+@@ -719,7 +719,11 @@ version (CRuntime_Glibc)
+         c_long __align;
+     }
+ 
+-    alias c_ulong pthread_t;
++    struct pthread_t
++    {
++        void *p;
++        uint x;
++    }
+ }
+ else version (CRuntime_Musl)
+ {
+diff --git a/libphobos/libdruntime/core/thread.d b/libphobos/libdruntime/core/thread.d
+index edd86b4ac..8c95d68da 100644
+--- a/libphobos/libdruntime/core/thread.d
++++ b/libphobos/libdruntime/core/thread.d
+@@ -3276,6 +3276,7 @@ private void* getStackBottom() nothrow @nogc
+         pthread_attr_t attr;
+         void* addr; size_t size;
+ 
++        pthread_attr_init(&attr);
+         pthread_getattr_np(pthread_self(), &attr);
+         pthread_attr_getstack(&attr, &addr, &size);
+         pthread_attr_destroy(&attr);
+-- 
+2.17.1
+
-- 
2.17.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 13:38:09 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 13:38:09 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxsTB-0007DY-K4; Tue, 21 Jul 2020 13:38:09 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=ETQF=BA=gmail.com=2309bmcristi@srs-us1.protection.inumbo.net>)
 id 1jxsTA-0007Cn-H0
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 13:38:08 +0000
X-Inumbo-ID: 68d3ae42-cb57-11ea-851a-bc764e2007e4
Received: from mail-ej1-x644.google.com (unknown [2a00:1450:4864:20::644])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 68d3ae42-cb57-11ea-851a-bc764e2007e4;
 Tue, 21 Jul 2020 13:38:07 +0000 (UTC)
Received: by mail-ej1-x644.google.com with SMTP id n22so18740989ejy.3
 for <minios-devel@lists.xen.org>; Tue, 21 Jul 2020 06:38:07 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:cc:subject:date:message-id;
 bh=hBpkPdidqHBSYKfQYKdae+XCoP8GeOaV7UM4M0l2NzQ=;
 b=NE2cRhKKbfno0p8buFGAbjoHq4CvrMGfc9ImtG1L4XHf8qTAko9L0sUFuZI325Fmt+
 ElpKUHhnvq6X54FZMGA6yiEZ3Bd+LT1+4GiDSCaPCuMr2eEcq/Hz24m9Daz7bhBM1wVP
 K+LQGBgG6Vpmc4l5JW28Gstc6CiM0NmplWfD/Q9vS3FqqCwq+9ya14/PriauqIYxUYVe
 mblEX81j+Bd3ByvwznjjlhCMX63brUUd7DbTPrIs66O1D28aNbQ0E44SEPnymU8vhe8w
 KNmqVTtV+dsOYiD+ewjsKTfyXGzAQnpzneLnbaDoEi/3jdAF+MOhs+kWPSxQKLz3yfyH
 trtA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:date:message-id;
 bh=hBpkPdidqHBSYKfQYKdae+XCoP8GeOaV7UM4M0l2NzQ=;
 b=sfE2waqBw1ucAEtpTH5xPnlc0W9zzixDSN5pi7r9Y6lHm3+yPHDaH8YH7tBDHBengb
 WtQa3mkkuRKBmAoATDEB5bJNPhwyM4mdFZUHYfX4XCHosseo5ZsheGyYNbsm3OGeP+C1
 wmFdZu13agfhfiCDzqKVmCXcr6NQTlxO4fIL6LerGXptT8+PtnaLlFUrBXc/yYPlrSis
 HBx98P8408Xq36XEsnAoeoASRoLdfW2V5B5e1t07Ej+S1DO1CAGTAdqKCj0v+FSaicUT
 tR+O/lojsVC1da4vUWlWCxqFGtO4JMeLq//K19pvKmghW3S58+PCM/7n8YfmM1Vuysm0
 A/KQ==
X-Gm-Message-State: AOAM532K6ReQGkieABo+CHWOD0JS6voalFwNFYp47TiFDsfk7BnxE6HH
 14ZHKnguQw58Hq8MFrJhWVdzHDUI+lI=
X-Google-Smtp-Source: ABdhPJzL83F1qvc2im1+p/uUJI9jIEa7aj3Ho6Faksxb2mSwq0bIt3VChUYFbELD7Z3wzrKj8lM6OA==
X-Received: by 2002:a17:906:80d3:: with SMTP id
 a19mr26494455ejx.217.1595338686160; 
 Tue, 21 Jul 2020 06:38:06 -0700 (PDT)
Received: from localhost.localdomain ([2a02:2f07:8200:d200:e58e:e1b:b419:616c])
 by smtp.gmail.com with ESMTPSA id f16sm16564010ejr.0.2020.07.21.06.38.05
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Tue, 21 Jul 2020 06:38:05 -0700 (PDT)
From: Marius-Cristian Baciu <2309bmcristi@gmail.com>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 1/2] Add support for compilation of D sources
Date: Tue, 21 Jul 2020 16:37:59 +0300
Message-Id: <20200721133800.27291-1-2309bmcristi@gmail.com>
X-Mailer: git-send-email 2.17.1
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Marius-Cristian Baciu <2309bmcristi@gmail.com>, simon.kuenzer@neclab.eu
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Use 'make D_COMPILER=gdc' for compilation of programs using full-language
capabilities and 'make D_COMPILER=dmd' for programs using the betterC subset
---
 Makefile                     | 15 +++++++++--
 Makefile.uk                  | 16 ++++++++++++
 support/build/Makefile.rules | 48 +++++++++++++++++++++++++++++++++++-
 3 files changed, 76 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 725b012..493ac7b 100644
--- a/Makefile
+++ b/Makefile
@@ -277,6 +277,14 @@ GOCFLAGS :=
 GOCFLAGS-y :=
 GOCINCLUDES :=
 GOCINCLUDES-y :=
+DMDFLAGS :=
+DMDFLAGS-y :=
+DMDINCLUDES :=
+DMDINCLUDES-y :=
+GDCFLAGS :=
+GDCFLAGS-y :=
+GDCINCLUDES :=
+GDCINCLUDES-y :=
 DBGFLAGS :=
 DBGFLAGS-y :=
 LDFLAGS :=
@@ -502,6 +510,8 @@ CC		:= $(CONFIG_CROSS_COMPILE)gcc
 CPP		:= $(CC)
 CXX		:= $(CPP)
 GOC		:= $(CONFIG_CROSS_COMPILE)gccgo-7
+DMD		:= $(CONFIG_CROSS_COMPILE)dmd
+GDC		:= $(CONFIG_CROSS_COMPILE)gdc
 AS		:= $(CC)
 AR		:= $(CONFIG_CROSS_COMPILE)gcc-ar
 NM		:= $(CONFIG_CROSS_COMPILE)gcc-nm
@@ -537,7 +547,7 @@ ASFLAGS		+= -DCC_VERSION=$(CC_VERSION)
 CFLAGS		+= -DCC_VERSION=$(CC_VERSION)
 CXXFLAGS	+= -DCC_VERSION=$(CC_VERSION)
 GOCFLAGS	+= -DCC_VERSION=$(CC_VERSION)
-
+GDCFLAGS	+= -DCC_VERSION=$(CC_VERSION)
 # ensure $(BUILD_DIR)/kconfig, $(BUILD_DIR)/include and $(BUILD_DIR)/include/uk exists
 $(call mk_sub_build_dir,kconfig)
 $(call mk_sub_build_dir,include)
@@ -547,7 +557,8 @@ ASINCLUDES            += -I$(UK_GENERATED_INCLUDES)
 CINCLUDES             += -I$(UK_GENERATED_INCLUDES)
 CXXINCLUDES           += -I$(UK_GENERATED_INCLUDES)
 GOCINCLUDES           += -I$(UK_GENERATED_INCLUDES)
-
+DMDINCLUDES           += -I$(UK_GENERATED_INCLUDES)
+GDCINCLUDES           += -I$(UK_GENERATED_INCLUDES)
 ################################################################################
 # Build rules
 ################################################################################
diff --git a/Makefile.uk b/Makefile.uk
index 3f01a25..5356fb2 100644
--- a/Makefile.uk
+++ b/Makefile.uk
@@ -22,6 +22,13 @@ GOCFLAGS    += -fno-stack-protector -fno-omit-frame-pointer -fno-tree-sra
 GOCFLAGS    += -fno-split-stack -Wall -Wextra
 GOCINCLUDES += -nostdinc -nostdlib -I$(CONFIG_UK_BASE)/include
 
+DMDINCLUDES += -I$(CONFIG_UK_BASE)/include
+
+GDCFLAGS    += -U __linux__ -U __FreeBSD__ -U __sun__
+GDCFLAGS    += -fno-stack-protector -fno-omit-frame-pointer -fno-tree-sra
+GDCFLAGS    += -fno-split-stack -Wall -Wextra
+GDCINCLUDES += -nostdinc -nostdlib -nophoboslib -I$(CONFIG_UK_BASE)/include
+
 # Set the text and data sections to be readable and writable. Also,
 # do not page-align the data segment. If the output format supports
 # Unix style magic numbers, mark the output as OMAGIC.
@@ -31,22 +38,27 @@ LDFLAGS     += -nostdinc -nostdlib -Wl,--omagic -Wl,--build-id=none
 CFLAGS-$(CONFIG_OPTIMIZE_NONE)            += -O0 -fno-optimize-sibling-calls -fno-tree-vectorize
 CXXFLAGS-$(CONFIG_OPTIMIZE_NONE)          += -O0 -fno-optimize-sibling-calls -fno-tree-vectorize
 GOCFLAGS-$(CONFIG_OPTIMIZE_NONE)          += -O0 -fno-optimize-sibling-calls -fno-tree-vectorize
+GDCFLAGS-$(CONFIG_OPTIMIZE_NONE)          += -O0 -fno-optimize-sibling-calls -fno-tree-vectorize
 CFLAGS-$(CONFIG_OPTIMIZE_PERF)            += -O2
 CXXFLAGS-$(CONFIG_OPTIMIZE_PERF)          += -O2
 GOCFLAGS-$(CONFIG_OPTIMIZE_PERF)          += -O2
+GDCFLAGS-$(CONFIG_OPTIMIZE_PERF)          += -O2
 CFLAGS-$(CONFIG_OPTIMIZE_SIZE)            += -Os
 CXXFLAGS-$(CONFIG_OPTIMIZE_SIZE)          += -Os
 GOCFLAGS-$(CONFIG_OPTIMIZE_SIZE)          += -Os
+GDCFLAGS-$(CONFIG_OPTIMIZE_SIZE)          += -Os
 
 CFLAGS-$(CONFIG_OPTIMIZE_DEADELIM)        += -fdata-sections -ffunction-sections
 CXXFLAGS-$(CONFIG_OPTIMIZE_DEADELIM)      += -fdata-sections -ffunction-sections
 GOCFLAGS-$(CONFIG_OPTIMIZE_DEADELIM)      += -fdata-sections -ffunction-sections
+GDCFLAGS-$(CONFIG_OPTIMIZE_DEADELIM)      += -fdata-sections -ffunction-sections
 LDFLAGS-$(CONFIG_OPTIMIZE_DEADELIM)       += -Wl,--gc-sections
 
 # LTO requires the compiler flags to be handed over also for linking
 CFLAGS-$(CONFIG_OPTIMIZE_LTO)             += -flto
 CXXFLAGS-$(CONFIG_OPTIMIZE_LTO)           += -flto
 GOCFLAGS-$(CONFIG_OPTIMIZE_LTO)           += -flto
+GDCFLAGS-$(CONFIG_OPTIMIZE_LTO)           += -flto
 LIBLDFLAGS-$(CONFIG_OPTIMIZE_LTO)         += $(CFLAGS) $(CFLAGS-y)
 LDFLAGS-$(CONFIG_OPTIMIZE_LTO)            += $(CFLAGS) $(CFLAGS-y)
 
@@ -67,6 +79,9 @@ CXXFLAGS += -DUK_FULLVERSION=$(UK_FULLVERSION)
 GOCFLAGS += -D __Unikraft__ -DUK_CODENAME="$(UK_CODENAME)"
 GOCFLAGS += -DUK_VERSION=$(UK_VERSION).$(UK_SUBVERSION)
 GOCFLAGS += -DUK_FULLVERSION=$(UK_FULLVERSION)
+GDCFLAGS += -D __Unikraft__ -DUK_CODENAME="$(UK_CODENAME)"
+GDCFLAGS += -DUK_VERSION=$(UK_VERSION).$(UK_SUBVERSION)
+GDCFLAGS += -DUK_FULLVERSION=$(UK_FULLVERSION)
 M4FLAGS  += -D __Unikraft__ -DUK_CODENAME="$(UK_CODENAME)"
 M4FLAGS  += -DUK_VERSION=$(UK_VERSION).$(UK_SUBVERSION)
 
@@ -77,5 +92,6 @@ ASFLAGS-$(call gcc_version_ge,6,1)	+= -no-pie
 CFLAGS-$(call gcc_version_ge,6,1)	+= -no-pie
 CXXFLAGS-$(call gcc_version_ge,6,1)	+= -no-pie
 GOFLAGS-$(call gcc_version_ge,6,1)	+= -no-pie
+GDCFLAGS-$(call gcc_version_ge,6,1)	+= -no-pie
 LIBLDFLAGS-$(call gcc_version_ge,6,1)	+= -no-pie
 LDFLAGS-$(call gcc_version_ge,6,1)	+= -no-pie
diff --git a/support/build/Makefile.rules b/support/build/Makefile.rules
index a13180a..65cc155 100644
--- a/support/build/Makefile.rules
+++ b/support/build/Makefile.rules
@@ -464,6 +464,51 @@ $(eval $(call vprefix_lib,$(1),OBJS-y) += $(3))
 $(eval $(call vprefix_lib,$(1),CLEAN-y) += $(call build_clean,$(3)) $(call out2dep,$(3)))
 endef
 
+define buildrule_dmd =
+$(3): $(2) | prepare
+	$(call build_cmd,DMD,$(1),$(3),\
+		$(DMD) -betterC $(DMDINCLUDES) $(DMDINCLUDES-y) \
+			$($(call vprefix_lib,$(1),DMDINCLUDES)) $($(call vprefix_lib,$(1),DMDINCLUDES-y)) \
+		    $(DMDFLAGS) $(DMDFLAGS-y) $($(call vprefix_lib,$(1),DMDFLAGS)) \
+            $($(call vprefix_lib,$(1),DMDFLAGS-y)) \
+            $(2) -c -od=$(dir $(3))
+	)
+
+UK_SRCS-y += $(2)
+UK_DEPS-y += $(call out2dep,$(3))
+UK_OBJS-y += $(3)
+$(eval $(call vprefix_lib,$(1),OBJS-y) += $(3))
+$(eval $(call vprefix_lib,$(1),CLEAN-y) += $(call build_clean,$(3)) $(call out2dep,$(3)))
+endef
+
+define buildrule_gdc =
+$(3): $(2) | prepare
+	$(call build_cmd,GDC,$(1),$(3),\
+		$(GDC) $(GDCINCLUDES) $(GDCINCLUDES-y) \
+			$($(call vprefix_lib,$(1),GDCINCLUDES)) $($(call vprefix_lib,$(1),GDCINCLUDES-y)) \
+			$(GDCFLAGS) $(GDCFLAGS-y) $(DBGFLAGS) $(DBGFLAGS-y) \
+			$($(call vprefix_lib,$(1),GDCFLAGS)) $($(call vprefix_lib,$(1),GDCFLAGS-y)) \
+			$(4) -D__LIBNAME__=$(1) -D__BASENAME__=$(notdir $(2)) \
+			-c $(2) -o $(3) $(depflags)
+	)
+
+UK_SRCS-y += $(2)
+UK_DEPS-y += $(call out2dep,$(3))
+UK_OBJS-y += $(3)
+$(eval $(call vprefix_lib,$(1),OBJS-y) += $(3))
+$(eval $(call vprefix_lib,$(1),CLEAN-y) += $(call build_clean,$(3)) $(call out2dep,$(3)))
+endef
+
+ifeq ($(D_COMPILER),dmd)
+    define buildrule_d =
+        $(buildrule_dmd)
+    endef
+else
+    define buildrule_d =
+        $(buildrule_gdc)
+    endef
+endif
+
 define add_lds_to_plat =
 $(eval $(call uc,$(2))_LD_SCRIPT-y += $(1))
 endef
@@ -544,8 +589,9 @@ $(if $(filter %.CPP,  $(2)),$(call buildrule_cc ,$(1),$(2),$(3),$(4)),\
 $(if $(filter %.c++,  $(2)),$(call buildrule_cc ,$(1),$(2),$(3),$(4)),\
 $(if $(filter %.C,    $(2)),$(call buildrule_cc ,$(1),$(2),$(3),$(4)),\
 $(if $(filter %.go,   $(2)),$(call buildrule_go ,$(1),$(2),$(3),$(4)),\
+$(if $(filter %.d,   $(2)),$(call buildrule_d ,$(1),$(2),$(3),$(4)),\
 $(error $(3): missing build rule for source type $(suffix $(2))) \
-)))))))))))))))
+))))))))))))))))
 endef
 
 
-- 
2.17.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 13:38:11 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 13:38:11 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxsTD-0007EB-Mk; Tue, 21 Jul 2020 13:38:11 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=ETQF=BA=gmail.com=2309bmcristi@srs-us1.protection.inumbo.net>)
 id 1jxsTD-0007Cn-0A
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 13:38:11 +0000
X-Inumbo-ID: 6a87b0d0-cb57-11ea-851a-bc764e2007e4
Received: from mail-ej1-x642.google.com (unknown [2a00:1450:4864:20::642])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 6a87b0d0-cb57-11ea-851a-bc764e2007e4;
 Tue, 21 Jul 2020 13:38:10 +0000 (UTC)
Received: by mail-ej1-x642.google.com with SMTP id rk21so21695239ejb.2
 for <minios-devel@lists.xen.org>; Tue, 21 Jul 2020 06:38:10 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:cc:subject:date:message-id:in-reply-to:references;
 bh=cI70TqGVnT8o6az8zNGHfDYMJjWNTIbcDFQthFjAiNY=;
 b=GxaMaOmQ1UE3Ftiv6FU4A2lg+6HgYKBeiP4Bq4YvNLFj3j59pkl4dZaS1QWyEoFAWV
 iHwh/qRyEsUKI6nzP8HFtiViK64zXbgqt4Wx6wqvVp0uzvoLAWsa0GcwMFh+SiaRlCSY
 pIOllfK66MuTGbYtWoGBxV3FEn+ruPAD2eBSknzLuT0kDplZa266ENSH/XxoQ22IMtYT
 DphtOdeZZfEAUgag5Bk/UvdpkEdBBrwhWOHTDKiQSOohTvJ3TI1C3zMHTgzM90trDMnJ
 uEsAwsjgbgAlkK9siDcYea41HiO+oZ6xbew1UVjSkBtRX/lyPyXdTdEa3oeXbfegaqC3
 5LUw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
 :references;
 bh=cI70TqGVnT8o6az8zNGHfDYMJjWNTIbcDFQthFjAiNY=;
 b=NkPGExdaZMfHnLpEmX2exbQ0xy6QecF6eplWhrw6FKYsH3shxH5kFCFlezrZD6+0Nv
 iQVecnyPL7rNQuxkDCpDP94qC3VKJ0eIov68D5A7rOsbuzLX0/vIVjpqX+xtENkfzcPS
 zLljs2XyLiFqdiXUjPgqDzcbZCxDY0ImdFM/L9m/fcagMYB1TIX7ybqOs3lDfGTdLAsw
 ySx14+pNVgTqDoPFZ0UqcCsBxTvlvyK5eqGbbmkr4EBwFpUZu9r4TkgPp9LECa4lReqd
 46z2PkQV8piHEFITEAsuqOaVB8SPVh4aK3/XNjoBBWJmReasDWZIGZbNUFJTNU9gW6P+
 QTdQ==
X-Gm-Message-State: AOAM530eV2+TA0tzTa9ltHflVaqPseC95kObVBvVJvQpGdsKcFh2iH7S
 626EIAFQ+db5EIfj4n2UkaH43QuDEdc=
X-Google-Smtp-Source: ABdhPJw14B8LwQ+HMAWu/rz41v1Gx/jLzNVFxUHOg3b5IaVGGb9G9c/OdJXEDRH+23LyFmk+4d7Rdg==
X-Received: by 2002:a17:907:2058:: with SMTP id
 pg24mr26903082ejb.79.1595338689173; 
 Tue, 21 Jul 2020 06:38:09 -0700 (PDT)
Received: from localhost.localdomain ([2a02:2f07:8200:d200:e58e:e1b:b419:616c])
 by smtp.gmail.com with ESMTPSA id f16sm16564010ejr.0.2020.07.21.06.38.08
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Tue, 21 Jul 2020 06:38:08 -0700 (PDT)
From: Marius-Cristian Baciu <2309bmcristi@gmail.com>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 2/2] lib/ukmmap: Add page-alignment support to
 mmap/munmap
Date: Tue, 21 Jul 2020 16:38:00 +0300
Message-Id: <20200721133800.27291-2-2309bmcristi@gmail.com>
X-Mailer: git-send-email 2.17.1
In-Reply-To: <20200721133800.27291-1-2309bmcristi@gmail.com>
References: <20200721133800.27291-1-2309bmcristi@gmail.com>
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Marius-Cristian Baciu <2309bmcristi@gmail.com>, simon.kuenzer@neclab.eu
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The D runtime library is dependent on this property
---
 lib/ukmmap/mmap.c | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/lib/ukmmap/mmap.c b/lib/ukmmap/mmap.c
index 7cee8dc..3422411 100644
--- a/lib/ukmmap/mmap.c
+++ b/lib/ukmmap/mmap.c
@@ -38,6 +38,13 @@
 #include <uk/alloc.h>
 #include <string.h>
 
+#ifdef DRUNTIME
+#include <uk/essentials.h>
+
+#define size_to_num_pages(size) \
+	(ALIGN_UP((unsigned long)(size), __PAGE_SIZE) / __PAGE_SIZE)
+#endif
+
 struct mmap_addr {
 	void *begin;
 	void *end;
@@ -94,8 +101,12 @@ void *mmap(void *addr, size_t len, int prot,
 		last = tmp;
 		tmp = tmp->next;
 	}
-	void *mem = uk_malloc(uk_alloc_get_default(), len);
-
+#ifdef DRUNTIME
+    int num_pages = size_to_num_pages(len);
+	void *mem = uk_palloc(uk_alloc_get_default(), num_pages);
+#else
+    void *mem = uk_malloc(uk_alloc_get_default(), len);
+#endif
 	if (!mem) {
 		errno = ENOMEM;
 		return (void *) -1;
@@ -131,6 +142,7 @@ int munmap(void *addr, size_t len)
 	if (!addr)
 		return 0;
 	while (tmp) {
+#ifndef DRUNTIME
 		if (addr != tmp->begin) {
 			if (tmp->end > addr + len) {
 				errno = EINVAL;
@@ -158,6 +170,19 @@ int munmap(void *addr, size_t len)
 			uk_free(uk_alloc_get_default(), addr);
 			return 0;
 		}
+#else
+        if (addr == tmp->begin) {
+			int num_pages = size_to_num_pages(len);
+
+			if (!prev)
+				mmap_addr = tmp->next;
+			else
+				prev->next = tmp->next;
+			uk_free(uk_alloc_get_default(), tmp);
+			uk_pfree(uk_alloc_get_default(), addr, num_pages);
+			break;
+        }
+#endif
 		prev = tmp;
 		tmp = tmp->next;
 	}
-- 
2.17.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 13:38:48 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 13:38:48 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxsTo-0007Fk-Pj; Tue, 21 Jul 2020 13:38:48 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=ETQF=BA=gmail.com=2309bmcristi@srs-us1.protection.inumbo.net>)
 id 1jxsTn-0007Ff-Sd
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 13:38:47 +0000
X-Inumbo-ID: 8083a164-cb57-11ea-851a-bc764e2007e4
Received: from mail-ej1-x644.google.com (unknown [2a00:1450:4864:20::644])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 8083a164-cb57-11ea-851a-bc764e2007e4;
 Tue, 21 Jul 2020 13:38:47 +0000 (UTC)
Received: by mail-ej1-x644.google.com with SMTP id n22so18743317ejy.3
 for <minios-devel@lists.xen.org>; Tue, 21 Jul 2020 06:38:47 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:cc:subject:date:message-id;
 bh=xbe9VnTbHOKFU0BxH8pmO8winzebzKAGUaB7fXR+r2E=;
 b=pYHQoCjQfauJhMLqT4wD91wGpFg8iXKVirnbZQ58PbQzfi/R9JQcFEmGkVeanwt5yQ
 ePGNfNnyW5nwkf7kJAmIwUe9a+NDQwmXu+lO0lauD+1VTPtXR8ebeRzIvSED6TfA+3xI
 ZOcF1qFVSFHPW9A/MQ/mnO64nQpTjZxHMzaMwCSLf5N7fni3wInCEtj4UoC/hDdr84zs
 VeaBA8Z7wvI+DW8X4vf9I8CYpbWALpmcXyMzXdl6OvWgJ3egPO2bXHNpXyWXiO5Cct6V
 LjEyBLFJ7461F9iDhXAoojnZtwf0Y3ta1azUEdKSNmlpgVRk82b5TM1wW/U6hbjslK1I
 eqoA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:date:message-id;
 bh=xbe9VnTbHOKFU0BxH8pmO8winzebzKAGUaB7fXR+r2E=;
 b=scAY9B1o+RmuD/jlQGZNXHMhAdXgZ0KhNH6tRBMXssvpc8lFlpHxtt6MNu94plS3Mk
 3e/lWQzo1BPdvJQBXUqQL3QwNfBfm47CRqu0F4T00XWyhDsBPIClPTpSelQQD1BvT99l
 xK4ogcMl3kwoaCzVaAaA0GHGrXIYHa9tF3DEUdeQvk2Tu4n1jTh2VPBdkg/Ku3+hfCek
 y7XF/a2YlCL1A9Bb8VSa2F9aPjOjkh8DKYglGbcmrnSZpEvovQ4CuZvVXOTsxpur/uYe
 k+UX2KbqK7jLg2Rp6Vj624We4KK60Hf9cfDXaDlUVYEeOqbZIVzIJ2I7asLMGtLVIL0R
 CMwA==
X-Gm-Message-State: AOAM533jL8jWzhY4YQeloUSvs+kVRq655P78ezt86AUCRHonIvYxSLri
 xvIQYJney9sYeCw+kzHDepMR0kQqXeE=
X-Google-Smtp-Source: ABdhPJwaaidGNnxGEsFxgjkpdDdQBlpS2iKg2delezO7YzGFswPP9IGOW8yTpkYxiolQAibVo2lxYw==
X-Received: by 2002:a17:906:4b46:: with SMTP id
 j6mr24508697ejv.403.1595338726139; 
 Tue, 21 Jul 2020 06:38:46 -0700 (PDT)
Received: from localhost.localdomain ([2a02:2f07:8200:d200:e58e:e1b:b419:616c])
 by smtp.gmail.com with ESMTPSA id w17sm16730513eju.42.2020.07.21.06.38.45
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Tue, 21 Jul 2020 06:38:45 -0700 (PDT)
From: Marius-Cristian Baciu <2309bmcristi@gmail.com>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH] newlib: Add support for static dl_iterate_phdr
Date: Tue, 21 Jul 2020 16:38:43 +0300
Message-Id: <20200721133843.27353-1-2309bmcristi@gmail.com>
X-Mailer: git-send-email 2.17.1
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Marius-Cristian Baciu <2309bmcristi@gmail.com>, simon.kuenzer@neclab.eu
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This will mostly allow the D runtime GC to register the static
data segments to the ranges that are to be scanned for live pointers
---
 link.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/link.c b/link.c
index 204713e..94f9516 100644
--- a/link.c
+++ b/link.c
@@ -35,11 +35,44 @@
 #include <uk/essentials.h>
 #include <stddef.h>
 #include <link.h>
+#include <elf.h>
+
+#include <stdlib.h>
+
+#ifdef DRUNTIME
+struct DG {
+    void * addr;
+    struct dl_phdr_info* result;
+};
+
+extern char __bss_start[];
+extern char _end[];
+#endif
 
 int dl_iterate_phdr(
 		int (*callback)(struct dl_phdr_info *info,
 				size_t size, void *data),
 		void *data)
 {
-	return 0;
+#ifdef DRUNTIME
+    struct DG* temp = (struct DG *)data;
+
+    temp->result->dlpi_addr = (ElfW(Addr))__bss_start;
+    temp->result->dlpi_phnum = 1;
+    temp->result->dlpi_adds  = 0;
+	temp->result->dlpi_subs  = 0;
+	temp->result->dlpi_name = "";
+
+    ElfW(Phdr) *segment_data = (ElfW(Phdr) *)malloc(sizeof(ElfW(Phdr)));
+    segment_data->p_type = PT_LOAD;
+    segment_data->p_flags = PF_W;
+    segment_data->p_vaddr = 0;
+    segment_data->p_memsz = _end - __bss_start;
+
+    temp->result->dlpi_phdr = segment_data;
+
+    return 1;
+#else
+    return 0;
+#endif
 }
-- 
2.17.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 15:33:02 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 15:33:02 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxuGJ-0001Uq-8b; Tue, 21 Jul 2020 15:32:59 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=zkTt=BA=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jxuGI-0001U0-HO
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 15:32:58 +0000
X-Inumbo-ID: 72cd8d72-cb67-11ea-8559-bc764e2007e4
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 72cd8d72-cb67-11ea-8559-bc764e2007e4;
 Tue, 21 Jul 2020 15:32:56 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 50707103998;
 Tue, 21 Jul 2020 17:32:55 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id PfgXrD1dhI1T; Tue, 21 Jul 2020 17:32:55 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id 2C476FFDDE
 for <minios-devel@lists.xen.org>; Tue, 21 Jul 2020 17:32:55 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 21 Jul
 2020 17:32:54 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT/LIBLWIP PATCH v3 0/3] Poll based receive
Date: Tue, 21 Jul 2020 17:32:43 +0200
Message-ID: <1595345566-14752-1-git-send-email-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.7.4
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch series implement poll based packet receive on driver that do not support
rx interrupt. The patch series is structured as follows.
- Lwip network stack store device information into the scratch pad space.
- The stack uses the retrieve the feature field while receiving netdev_info.
- The stack performs a poll based receive.

This patch series depend on the patch set "Poll based receive based on uk_netdev features".

Changes since v2:
- Change netdev size from 24 to 32.
- Add/Fix comments

Changes since v1:
- Perform compile time error check on scratch size instead of UK_ASSERT

Sharan Santhanam (3):
  lib/lwip: Reserve per netdev space for lwip
  lib/lwip: Fetch features supported on the netdev
  lib/lwip: Enable poll only receive

 Config.uk   |   9 +++++
 Makefile.uk |   1 +
 uknetdev.c  | 112 +++++++++++++++++++++++++++++++++++++++++++++++-------------
 3 files changed, 99 insertions(+), 23 deletions(-)

-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 15:33:04 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 15:33:04 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxuGO-0001W2-AG; Tue, 21 Jul 2020 15:33:04 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=zkTt=BA=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jxuGN-0001U0-Bm
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 15:33:03 +0000
X-Inumbo-ID: 74513e00-cb67-11ea-8559-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 74513e00-cb67-11ea-8559-bc764e2007e4;
 Tue, 21 Jul 2020 15:32:58 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id DDB89F200F;
 Tue, 21 Jul 2020 17:32:57 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 9FIzjkrzZNb2; Tue, 21 Jul 2020 17:32:57 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id B8EC2F200E
 for <minios-devel@lists.xen.org>; Tue, 21 Jul 2020 17:32:55 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 21 Jul
 2020 17:32:55 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT/LIBLWIP PATCH v3 1/3] lib/lwip: Reserve per netdev space
 for lwip
Date: Tue, 21 Jul 2020 17:32:44 +0200
Message-ID: <1595345566-14752-2-git-send-email-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <1595345566-14752-1-git-send-email-sharan.santhanam@neclab.eu>
References: <1595345566-14752-1-git-send-email-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Reserves space for per-network-device (uknetdev). This will be later
used to store network stack specific specific information in the netdevice.
Reserving this memory allows us to store the memory continuously in the
netdev instead of additional dereferences.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 Config.uk   | 9 +++++++++
 Makefile.uk | 1 +
 2 files changed, 10 insertions(+)

diff --git a/Config.uk b/Config.uk
index aaaaae0..e2eacb5 100644
--- a/Config.uk
+++ b/Config.uk
@@ -22,6 +22,15 @@ config LWIP_UKNETDEV
 		In case threaded mode is selected and the underlying device
 		driver does not support receive interrupts the network
 		interfaces have to be polled manually (uknetdev_poll()).
+
+config LWIP_UKNETDEV_SCRATCH
+	int
+	default 32
+	help
+		The network stack reserves space in the uknetdev device for its
+		use. Please do not change this value and in case change this
+		value please make sure it is sufficient enough to hold the
+		lwip_netdev_data data structure.
 endmenu
 
 config LWIP_AUTOIFACE
diff --git a/Makefile.uk b/Makefile.uk
index d3c6c9c..99005a9 100644
--- a/Makefile.uk
+++ b/Makefile.uk
@@ -62,6 +62,7 @@ LIBLWIP_COMMON_INCLUDES-y += -I$(LIBLWIP_BASE)/musl-imported/include
 LIBLWIP_COMMON_INCLUDES-y += -I$(LIBLWIP_EXTRACTED)/include
 CINCLUDES-$(CONFIG_LIBLWIP)   += $(LIBLWIP_COMMON_INCLUDES-y)
 CXXINCLUDES-$(CONFIG_LIBLWIP) += $(LIBLWIP_COMMON_INCLUDES-y)
+$(eval $(call uknetdev_scratch_mem,$(CONFIG_LWIP_UKNETDEV_SCRATCH)))
 
 ################################################################################
 # Library flags
-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 15:33:09 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 15:33:09 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxuGT-0001Wq-C7; Tue, 21 Jul 2020 15:33:09 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=zkTt=BA=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jxuGS-0001U0-C3
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 15:33:08 +0000
X-Inumbo-ID: 7588e98a-cb67-11ea-8559-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 7588e98a-cb67-11ea-8559-bc764e2007e4;
 Tue, 21 Jul 2020 15:33:00 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id EA17EF2010;
 Tue, 21 Jul 2020 17:32:59 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id X9wfBjbcjxLI; Tue, 21 Jul 2020 17:32:59 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id C2130F200E
 for <minios-devel@lists.xen.org>; Tue, 21 Jul 2020 17:32:57 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 21 Jul
 2020 17:32:55 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT/LIBLWIP PATCH v3 2/3] lib/lwip: Fetch features supported on
 the netdev
Date: Tue, 21 Jul 2020 17:32:45 +0200
Message-ID: <1595345566-14752-3-git-send-email-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <1595345566-14752-1-git-send-email-sharan.santhanam@neclab.eu>
References: <1595345566-14752-1-git-send-email-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 uknetdev.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/uknetdev.c b/uknetdev.c
index 7047352..fe679e9 100644
--- a/uknetdev.c
+++ b/uknetdev.c
@@ -62,6 +62,10 @@
 #define UKNETDEV_NETIF_NAME0 'e'
 #define UKNETDEV_NETIF_NAME1 'n'
 
+struct lwip_netdev_data {
+	uint32_t features;
+};
+
 /*
  * Global headroom settings for buffer allocations used on receive
  * and transmit. We are taking the maximum of all uknetdev devices as
@@ -372,6 +376,7 @@ err_t uknetdev_init(struct netif *nf)
 	struct uk_netdev_rxqueue_conf rxq_conf;
 	struct uk_netdev_txqueue_conf txq_conf;
 	struct uk_netdev_info info;
+	struct lwip_netdev_data *lwip_data;
 	const struct uk_hwaddr *hwaddr;
 	unsigned int i;
 	int ret;
@@ -379,6 +384,21 @@ err_t uknetdev_init(struct netif *nf)
 	UK_ASSERT(nf);
 	dev = netif_to_uknetdev(nf);
 	UK_ASSERT(dev);
+#if CONFIG_UK_NETDEV_SCRATCH_SIZE < CONFIG_LWIP_UKNETDEV_SCRATCH 
+/**
+ * CONFIG_UK_NETDEV_SCRATCH_SIZE is configured as the max of all scratch pad
+ * requirements by the Makefile.uk macro uknetdev_scratch_mem. This value
+ * should atleast be greater CONFIG_LWIP_UKNETDEV_SCRATCH
+ */
+#error "Insufficient Scratch memory"
+#endif
+
+	/**
+	 * Make sure the CONFIG_LWIP_UKNETDEV_SCRATCH is still sufficient to
+	 * store lwip_data.
+	 */
+	UK_ASSERT(sizeof(*lwip_data) <= CONFIG_LWIP_UKNETDEV_SCRATCH);
+	lwip_data = (struct lwip_netdev_data *)dev->scratch_pad;
 
 	LWIP_ASSERT("uknetdev needs an input callback (netif_input or tcpip_input)",
 		    nf->input != NULL);
@@ -411,6 +431,7 @@ err_t uknetdev_init(struct netif *nf)
 	uk_netdev_info_get(dev, &info);
 	if (!info.max_rx_queues || !info.max_tx_queues)
 		return ERR_IF;
+	lwip_data->features = info.features;
 
 	/*
 	 * Update our global (rx|tx)_headroom setting that we use for
-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 15:33:14 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 15:33:14 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxuGY-0001YH-EB; Tue, 21 Jul 2020 15:33:14 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=zkTt=BA=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jxuGX-0001U0-CT
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 15:33:13 +0000
X-Inumbo-ID: 76bc18cc-cb67-11ea-8559-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 76bc18cc-cb67-11ea-8559-bc764e2007e4;
 Tue, 21 Jul 2020 15:33:02 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 037F6F200F;
 Tue, 21 Jul 2020 17:33:02 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id wrOuonPh1OzM; Tue, 21 Jul 2020 17:33:01 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id CE0F4F200E
 for <minios-devel@lists.xen.org>; Tue, 21 Jul 2020 17:32:59 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 21 Jul
 2020 17:32:56 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT/LIBLWIP PATCH v3 3/3] lib/lwip: Enable poll only receive
Date: Tue, 21 Jul 2020 17:32:46 +0200
Message-ID: <1595345566-14752-4-git-send-email-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <1595345566-14752-1-git-send-email-sharan.santhanam@neclab.eu>
References: <1595345566-14752-1-git-send-email-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The uknetdev library provides the way to check if interrupts are
supported on a uk_netdev. If the device does not support interrupt
the lwip stack would create a thread to poll the receive queue for
packets.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 uknetdev.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 68 insertions(+), 23 deletions(-)

diff --git a/uknetdev.c b/uknetdev.c
index fe679e9..e6c9807 100644
--- a/uknetdev.c
+++ b/uknetdev.c
@@ -64,6 +64,11 @@
 
 struct lwip_netdev_data {
 	uint32_t features;
+#ifdef CONFIG_HAVE_SCHED
+	struct uk_thread *poll_thread; /* Thread per device */
+	char *_name; /* Thread name */
+	struct uk_sched *sched; /* Scheduler information */
+#endif /* CONFIG_HAVE_SCHED */
 };
 
 /*
@@ -325,44 +330,84 @@ void uknetdev_poll_all(void)
 
 #else /* CONFIG_LWIP_NOTHREADS */
 
+static void _poll_netif(void *arg)
+{
+	struct netif *nf = (struct netif *) arg;
+
+	while (1) {
+		uknetdev_poll(nf);
+		uk_sched_yield();
+	}
+}
+
 static void uknetdev_updown(struct netif *nf)
 {
 	struct uk_netdev *dev;
 	int ret;
+	struct lwip_netdev_data  *lwip_data;
 
 	UK_ASSERT(nf);
 	dev = netif_to_uknetdev(nf);
 	UK_ASSERT(dev);
+	lwip_data = (struct lwip_netdev_data *)dev->scratch_pad;
 
 	/* Enable and disable interrupts according to netif's up/down status */
+
 	if (nf->flags & NETIF_FLAG_UP) {
-		ret = uk_netdev_rxq_intr_enable(dev, 0);
-		if (ret < 0) {
-			LWIP_DEBUGF(NETIF_DEBUG,
-				    ("%s: %c%c%u: Failed to enable rx interrrupt mode on netdev %u\n",
-				     __func__, nf->name[0], nf->name[1],
-				     nf->num, uk_netdev_id_get(dev)));
+		if (uk_netdev_rxintr_supported(lwip_data->features)) {
+			ret = uk_netdev_rxq_intr_enable(dev, 0);
+			if (ret < 0) {
+				LWIP_DEBUGF(NETIF_DEBUG,
+						("%s: %c%c%u: Failed to enable rx interrupt mode on netdev %u\n",
+						 __func__, nf->name[0],
+						 nf->name[1],
+						 nf->num,
+						 uk_netdev_id_get(dev)));
+			} else {
+				LWIP_DEBUGF(NETIF_DEBUG,
+					("%s: %c%c%u: Enabled rx interrupt mode on netdev %u\n",
+						 __func__, nf->name[0],
+						 nf->name[1],
+						 nf->num,
+						 uk_netdev_id_get(dev)));
+			}
+
+			if (ret == 1) {
+				/*
+				 * uk_netdev_rxq_intr_enable() told us that we
+				 * need to flush the receive queue before
+				 * interrupts are enabled. For this purpose
+				 * we do an initial poll.
+				 */
+				uknetdev_poll(nf);
+			}
 		} else {
+#ifdef CONFIG_HAVE_SCHED
 			LWIP_DEBUGF(NETIF_DEBUG,
-				    ("%s: %c%c%u: Enabled rx interrupt mode on netdev %u\n",
-				     __func__, nf->name[0], nf->name[1],
-				     nf->num, uk_netdev_id_get(dev)));
-		}
-
-		if (ret == 1) {
-			/*
-			 * uk_netdev_rxq_intr_enable() told us that we need to
-			 * flush the receieve queue before interrupts are
-			 * enabled. For this purpose we do an initial poll.
-			 */
-			uknetdev_poll(nf);
+					("%s: Poll receive enabled\n",
+					 __func__));
+			/* Create a thread */
+			lwip_data->sched = uk_sched_get_default();
+			UK_ASSERT(lwip_data->sched);
+			lwip_data->poll_thread =
+				uk_sched_thread_create(lwip_data->sched, NULL,
+						       NULL, _poll_netif, nf);
+#else /* CONFIG_HAVE_SCHED */
+			uk_pr_warn("The netdevice does not support interrupt. Ensure the netdevice is polled to receive packets");
+#endif /* CONFIG_HAVE_SCHED */
 		}
 	} else {
-		uk_netdev_rxq_intr_disable(dev, 0);
-		LWIP_DEBUGF(NETIF_DEBUG,
-			    ("%s: %c%c%u: Disabled rx interrupts on netdev %u\n",
-			     __func__, nf->name[0], nf->name[1],
-			     nf->num, uk_netdev_id_get(dev)));
+		/**
+		 * TODO:
+		 * Cleanup the thread on stopping the network interface.
+		 */
+		if (uk_netdev_rxintr_supported(lwip_data->features)) {
+			uk_netdev_rxq_intr_disable(dev, 0);
+			LWIP_DEBUGF(NETIF_DEBUG,
+					("%s: %c%c%u: Disabled rx interrupts on netdev %u\n",
+					 __func__, nf->name[0], nf->name[1],
+					 nf->num, uk_netdev_id_get(dev)));
+		}
 
 	}
 }
-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 15:40:22 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 15:40:22 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxuNS-0002KB-0X; Tue, 21 Jul 2020 15:40:22 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=HxHN=BA=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxuNQ-0002K3-VN
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 15:40:20 +0000
X-Inumbo-ID: 7ab14cbc-cb68-11ea-8564-bc764e2007e4
Received: from mh-is-1.lancs.ac.uk (unknown [148.88.65.129])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 7ab14cbc-cb68-11ea-8564-bc764e2007e4;
 Tue, 21 Jul 2020 15:40:18 +0000 (UTC)
Received: from mito.neclab.eu ([195.37.70.39] helo=localhost.localdomain)
 by mh-is-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jxuNM-0008vk-5M; Tue, 21 Jul 2020 16:40:17 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH,v2,00/15] Introduce Ring Buffer Implementation
Date: Tue, 21 Jul 2020 17:39:41 +0200
Message-Id: <20200721153956.13555-1-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Alexander Jung <a.jung@lancs.ac.uk>, Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This series introduces a port of FreeBSD's buf_ring.{h,c} implementation for use
within Unikraft.  This simple ring buffer can be used for message passing in
queues, for example within a AF_UNIX socket implementation between two 
threads.  The implementation is therefore thread safe and provides a generic 
data field which is initialized to the desired ring buffer length.

The implementation is provided within ukmpi as a new option, LIBUKMPI_RING, 
which exposes the following new methods:

 - uk_ring_alloc
 - uk_ring_free
 - uk_ring_enqueue
 - uk_ring_dequeue
 - uk_ring_dequeue_single
 - uk_ring_advance_single
 - uk_ring_putback_single
 - uk_ring_peek
 - uk_ring_peek_clear_single
 - uk_ring_full
 - uk_ring_empty
 - uk_ring_count

The port is currently limited, with no support for reading atomic values from
ARM{32,64} CPU registers (described in the comments inline).  As a result, use 
of the ring buffer implementation is untested on ARM.

Alexander Jung (15):
  lib/ukring: Import simple ring buffer from FreeBSD
  lib/ukring: {ring.c, ring.h} Fix checkpatch errors and spacing.
  lib/ukring: Adapt {ring.c, ring.h} to Unikraft
  lib/ukring: Re-prefix methods and structs from buf_ to uk_
  lib/ukring: Remove br_ prefix and rename br variable
  lib/ukring: Disable use of cpu_spinwait function
  lib/ukring: Rename single and multiple consumer functions.
  lib/ukring: Use Unikraft to enable ring buffer debugging
  lib/ukring: Remove unsupported cache line size
  lib/ukring: Disable use of CPU prefetching
  lib/ukring: Properly commment {ring.c, ring.h}
  lib/ukring: Provide KConfig menu option for microlibrary
  lib/ukring: Target files to build for the microlibrary
  lib/ukring: Register ukring with Unikraft
  lib/ukring: Fix unitialized variable

 lib/Makefile.uk              |   1 +
 lib/ukring/Config.uk         |   7 +
 lib/ukring/Makefile.uk       |   6 +
 lib/ukring/exportsyms.uk     |  12 +
 lib/ukring/include/uk/ring.h | 482 +++++++++++++++++++++++++++++++++++
 lib/ukring/ring.c            |  86 +++++++
 6 files changed, 594 insertions(+)
 create mode 100644 lib/ukring/Config.uk
 create mode 100644 lib/ukring/Makefile.uk
 create mode 100644 lib/ukring/exportsyms.uk
 create mode 100644 lib/ukring/include/uk/ring.h
 create mode 100644 lib/ukring/ring.c

-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 15:40:27 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 15:40:27 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxuNX-0002Kp-2q; Tue, 21 Jul 2020 15:40:27 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=HxHN=BA=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxuNW-0002Kh-7l
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 15:40:26 +0000
X-Inumbo-ID: 7de4ce86-cb68-11ea-8564-bc764e2007e4
Received: from mh-is-1.lancs.ac.uk (unknown [148.88.65.129])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 7de4ce86-cb68-11ea-8564-bc764e2007e4;
 Tue, 21 Jul 2020 15:40:24 +0000 (UTC)
Received: from mito.neclab.eu ([195.37.70.39] helo=localhost.localdomain)
 by mh-is-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jxuNR-0008vk-42; Tue, 21 Jul 2020 16:40:23 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH, v2,
 01/15] lib/ukring: Import simple ring buffer from FreeBSD
Date: Tue, 21 Jul 2020 17:39:42 +0200
Message-Id: <20200721153956.13555-2-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200721153956.13555-1-a.jung@lancs.ac.uk>
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Alexander Jung <a.jung@lancs.ac.uk>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Copied as it is from the official FreeBSD git mirror.

Commit: c45cce178ce658f81901a45c741b7f3c47ce2250

- https://github.com/freebsd/freebsd/blob/c45cce1/sys/sys/buf_ring.h
- https://github.com/freebsd/freebsd/blob/c45cce1/sys/kern/subr_bufring.c

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukring/include/uk/ring.h | 371 +++++++++++++++++++++++++++++++++++
 lib/ukring/ring.c            |  65 ++++++
 2 files changed, 436 insertions(+)
 create mode 100644 lib/ukring/include/uk/ring.h
 create mode 100644 lib/ukring/ring.c

diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
new file mode 100644
index 0000000..899563c
--- /dev/null
+++ b/lib/ukring/include/uk/ring.h
@@ -0,0 +1,371 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2007-2009 Kip Macy <kmacy@freebsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ *
+ */
+
+#ifndef	_SYS_BUF_RING_H_
+#define	_SYS_BUF_RING_H_
+
+#include <machine/cpu.h>
+
+#ifdef DEBUG_BUFRING
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#endif
+
+struct buf_ring {
+	volatile uint32_t	br_prod_head;
+	volatile uint32_t	br_prod_tail;	
+	int              	br_prod_size;
+	int              	br_prod_mask;
+	uint64_t		br_drops;
+	volatile uint32_t	br_cons_head __aligned(CACHE_LINE_SIZE);
+	volatile uint32_t	br_cons_tail;
+	int		 	br_cons_size;
+	int              	br_cons_mask;
+#ifdef DEBUG_BUFRING
+	struct mtx		*br_lock;
+#endif	
+	void			*br_ring[0] __aligned(CACHE_LINE_SIZE);
+};
+
+/*
+ * multi-producer safe lock-free ring buffer enqueue
+ *
+ */
+static __inline int
+buf_ring_enqueue(struct buf_ring *br, void *buf)
+{
+	uint32_t prod_head, prod_next, cons_tail;
+#ifdef DEBUG_BUFRING
+	int i;
+
+	/*
+	 * Note: It is possible to encounter an mbuf that was removed
+	 * via drbr_peek(), and then re-added via drbr_putback() and
+	 * trigger a spurious panic.
+	 */
+	for (i = br->br_cons_head; i != br->br_prod_head;
+	     i = ((i + 1) & br->br_cons_mask))
+		if(br->br_ring[i] == buf)
+			panic("buf=%p already enqueue at %d prod=%d cons=%d",
+			    buf, i, br->br_prod_tail, br->br_cons_tail);
+#endif	
+	critical_enter();
+	do {
+		prod_head = br->br_prod_head;
+		prod_next = (prod_head + 1) & br->br_prod_mask;
+		cons_tail = br->br_cons_tail;
+
+		if (prod_next == cons_tail) {
+			rmb();
+			if (prod_head == br->br_prod_head &&
+			    cons_tail == br->br_cons_tail) {
+				br->br_drops++;
+				critical_exit();
+				return (ENOBUFS);
+			}
+			continue;
+		}
+	} while (!atomic_cmpset_acq_int(&br->br_prod_head, prod_head, prod_next));
+#ifdef DEBUG_BUFRING
+	if (br->br_ring[prod_head] != NULL)
+		panic("dangling value in enqueue");
+#endif	
+	br->br_ring[prod_head] = buf;
+
+	/*
+	 * If there are other enqueues in progress
+	 * that preceded us, we need to wait for them
+	 * to complete 
+	 */   
+	while (br->br_prod_tail != prod_head)
+		cpu_spinwait();
+	atomic_store_rel_int(&br->br_prod_tail, prod_next);
+	critical_exit();
+	return (0);
+}
+
+/*
+ * multi-consumer safe dequeue 
+ *
+ */
+static __inline void *
+buf_ring_dequeue_mc(struct buf_ring *br)
+{
+	uint32_t cons_head, cons_next;
+	void *buf;
+
+	critical_enter();
+	do {
+		cons_head = br->br_cons_head;
+		cons_next = (cons_head + 1) & br->br_cons_mask;
+
+		if (cons_head == br->br_prod_tail) {
+			critical_exit();
+			return (NULL);
+		}
+	} while (!atomic_cmpset_acq_int(&br->br_cons_head, cons_head, cons_next));
+
+	buf = br->br_ring[cons_head];
+#ifdef DEBUG_BUFRING
+	br->br_ring[cons_head] = NULL;
+#endif
+	/*
+	 * If there are other dequeues in progress
+	 * that preceded us, we need to wait for them
+	 * to complete 
+	 */   
+	while (br->br_cons_tail != cons_head)
+		cpu_spinwait();
+
+	atomic_store_rel_int(&br->br_cons_tail, cons_next);
+	critical_exit();
+
+	return (buf);
+}
+
+/*
+ * single-consumer dequeue 
+ * use where dequeue is protected by a lock
+ * e.g. a network driver's tx queue lock
+ */
+static __inline void *
+buf_ring_dequeue_sc(struct buf_ring *br)
+{
+	uint32_t cons_head, cons_next;
+#ifdef PREFETCH_DEFINED
+	uint32_t cons_next_next;
+#endif
+	uint32_t prod_tail;
+	void *buf;
+
+	/*
+	 * This is a workaround to allow using buf_ring on ARM and ARM64.
+	 * ARM64TODO: Fix buf_ring in a generic way.
+	 * REMARKS: It is suspected that br_cons_head does not require
+	 *   load_acq operation, but this change was extensively tested
+	 *   and confirmed it's working. To be reviewed once again in
+	 *   FreeBSD-12.
+	 *
+	 * Preventing following situation:
+	 * Core(0) - buf_ring_enqueue()                                       Core(1) - buf_ring_dequeue_sc()
+	 * -----------------------------------------                                       ----------------------------------------------
+	 *
+	 *                                                                                cons_head = br->br_cons_head;
+	 * atomic_cmpset_acq_32(&br->br_prod_head, ...));
+	 *                                                                                buf = br->br_ring[cons_head];     <see <1>>
+	 * br->br_ring[prod_head] = buf;
+	 * atomic_store_rel_32(&br->br_prod_tail, ...);
+	 *                                                                                prod_tail = br->br_prod_tail;
+	 *                                                                                if (cons_head == prod_tail) 
+	 *                                                                                        return (NULL);
+	 *                                                                                <condition is false and code uses invalid(old) buf>`	
+	 *
+	 * <1> Load (on core 1) from br->br_ring[cons_head] can be reordered (speculative readed) by CPU.
+	 */	
+#if defined(__arm__) || defined(__aarch64__)
+	cons_head = atomic_load_acq_32(&br->br_cons_head);
+#else
+	cons_head = br->br_cons_head;
+#endif
+	prod_tail = atomic_load_acq_32(&br->br_prod_tail);
+	
+	cons_next = (cons_head + 1) & br->br_cons_mask;
+#ifdef PREFETCH_DEFINED
+	cons_next_next = (cons_head + 2) & br->br_cons_mask;
+#endif
+	
+	if (cons_head == prod_tail) 
+		return (NULL);
+
+#ifdef PREFETCH_DEFINED	
+	if (cons_next != prod_tail) {		
+		prefetch(br->br_ring[cons_next]);
+		if (cons_next_next != prod_tail) 
+			prefetch(br->br_ring[cons_next_next]);
+	}
+#endif
+	br->br_cons_head = cons_next;
+	buf = br->br_ring[cons_head];
+
+#ifdef DEBUG_BUFRING
+	br->br_ring[cons_head] = NULL;
+	if (!mtx_owned(br->br_lock))
+		panic("lock not held on single consumer dequeue");
+	if (br->br_cons_tail != cons_head)
+		panic("inconsistent list cons_tail=%d cons_head=%d",
+		    br->br_cons_tail, cons_head);
+#endif
+	br->br_cons_tail = cons_next;
+	return (buf);
+}
+
+/*
+ * single-consumer advance after a peek
+ * use where it is protected by a lock
+ * e.g. a network driver's tx queue lock
+ */
+static __inline void
+buf_ring_advance_sc(struct buf_ring *br)
+{
+	uint32_t cons_head, cons_next;
+	uint32_t prod_tail;
+	
+	cons_head = br->br_cons_head;
+	prod_tail = br->br_prod_tail;
+	
+	cons_next = (cons_head + 1) & br->br_cons_mask;
+	if (cons_head == prod_tail) 
+		return;
+	br->br_cons_head = cons_next;
+#ifdef DEBUG_BUFRING
+	br->br_ring[cons_head] = NULL;
+#endif
+	br->br_cons_tail = cons_next;
+}
+
+/*
+ * Used to return a buffer (most likely already there)
+ * to the top of the ring. The caller should *not*
+ * have used any dequeue to pull it out of the ring
+ * but instead should have used the peek() function.
+ * This is normally used where the transmit queue
+ * of a driver is full, and an mbuf must be returned.
+ * Most likely whats in the ring-buffer is what
+ * is being put back (since it was not removed), but
+ * sometimes the lower transmit function may have
+ * done a pullup or other function that will have
+ * changed it. As an optimization we always put it
+ * back (since jhb says the store is probably cheaper),
+ * if we have to do a multi-queue version we will need
+ * the compare and an atomic.
+ */
+static __inline void
+buf_ring_putback_sc(struct buf_ring *br, void *new)
+{
+	KASSERT(br->br_cons_head != br->br_prod_tail, 
+		("Buf-Ring has none in putback")) ;
+	br->br_ring[br->br_cons_head] = new;
+}
+
+/*
+ * return a pointer to the first entry in the ring
+ * without modifying it, or NULL if the ring is empty
+ * race-prone if not protected by a lock
+ */
+static __inline void *
+buf_ring_peek(struct buf_ring *br)
+{
+
+#ifdef DEBUG_BUFRING
+	if ((br->br_lock != NULL) && !mtx_owned(br->br_lock))
+		panic("lock not held on single consumer dequeue");
+#endif	
+	/*
+	 * I believe it is safe to not have a memory barrier
+	 * here because we control cons and tail is worst case
+	 * a lagging indicator so we worst case we might
+	 * return NULL immediately after a buffer has been enqueued
+	 */
+	if (br->br_cons_head == br->br_prod_tail)
+		return (NULL);
+	
+	return (br->br_ring[br->br_cons_head]);
+}
+
+static __inline void *
+buf_ring_peek_clear_sc(struct buf_ring *br)
+{
+#ifdef DEBUG_BUFRING
+	void *ret;
+
+	if (!mtx_owned(br->br_lock))
+		panic("lock not held on single consumer dequeue");
+#endif	
+
+	if (br->br_cons_head == br->br_prod_tail)
+		return (NULL);
+
+#if defined(__arm__) || defined(__aarch64__)
+	/*
+	 * The barrier is required there on ARM and ARM64 to ensure, that
+	 * br->br_ring[br->br_cons_head] will not be fetched before the above
+	 * condition is checked.
+	 * Without the barrier, it is possible, that buffer will be fetched
+	 * before the enqueue will put mbuf into br, then, in the meantime, the
+	 * enqueue will update the array and the br_prod_tail, and the
+	 * conditional check will be true, so we will return previously fetched
+	 * (and invalid) buffer.
+	 */
+	atomic_thread_fence_acq();
+#endif
+
+#ifdef DEBUG_BUFRING
+	/*
+	 * Single consumer, i.e. cons_head will not move while we are
+	 * running, so atomic_swap_ptr() is not necessary here.
+	 */
+	ret = br->br_ring[br->br_cons_head];
+	br->br_ring[br->br_cons_head] = NULL;
+	return (ret);
+#else
+	return (br->br_ring[br->br_cons_head]);
+#endif
+}
+
+static __inline int
+buf_ring_full(struct buf_ring *br)
+{
+
+	return (((br->br_prod_head + 1) & br->br_prod_mask) == br->br_cons_tail);
+}
+
+static __inline int
+buf_ring_empty(struct buf_ring *br)
+{
+
+	return (br->br_cons_head == br->br_prod_tail);
+}
+
+static __inline int
+buf_ring_count(struct buf_ring *br)
+{
+
+	return ((br->br_prod_size + br->br_prod_tail - br->br_cons_tail)
+	    & br->br_prod_mask);
+}
+
+struct buf_ring *buf_ring_alloc(int count, struct malloc_type *type, int flags,
+    struct mtx *);
+void buf_ring_free(struct buf_ring *br, struct malloc_type *type);
+
+
+
+#endif
\ No newline at end of file
diff --git a/lib/ukring/ring.c b/lib/ukring/ring.c
new file mode 100644
index 0000000..644c3be
--- /dev/null
+++ b/lib/ukring/ring.c
@@ -0,0 +1,65 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2007, 2008 Kip Macy <kmacy@freebsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/ktr.h>
+#include <sys/buf_ring.h>
+
+struct buf_ring *
+buf_ring_alloc(int count, struct malloc_type *type, int flags, struct mtx *lock)
+{
+	struct buf_ring *br;
+
+	KASSERT(powerof2(count), ("buf ring must be size power of 2"));
+	
+	br = malloc(sizeof(struct buf_ring) + count*sizeof(caddr_t),
+	    type, flags|M_ZERO);
+	if (br == NULL)
+		return (NULL);
+#ifdef DEBUG_BUFRING
+	br->br_lock = lock;
+#endif	
+	br->br_prod_size = br->br_cons_size = count;
+	br->br_prod_mask = br->br_cons_mask = count-1;
+	br->br_prod_head = br->br_cons_head = 0;
+	br->br_prod_tail = br->br_cons_tail = 0;
+		
+	return (br);
+}
+
+void
+buf_ring_free(struct buf_ring *br, struct malloc_type *type)
+{
+	free(br, type);
+}
\ No newline at end of file
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 15:40:32 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 15:40:32 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxuNc-0002Lb-4a; Tue, 21 Jul 2020 15:40:32 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=HxHN=BA=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxuNa-0002Kh-S2
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 15:40:30 +0000
X-Inumbo-ID: 8030576e-cb68-11ea-8564-bc764e2007e4
Received: from mh-is-1.lancs.ac.uk (unknown [148.88.65.129])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 8030576e-cb68-11ea-8564-bc764e2007e4;
 Tue, 21 Jul 2020 15:40:28 +0000 (UTC)
Received: from mito.neclab.eu ([195.37.70.39] helo=localhost.localdomain)
 by mh-is-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jxuNV-0008vk-49; Tue, 21 Jul 2020 16:40:27 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH, v2, 02/15] lib/ukring: {ring.c,
 ring.h} Fix checkpatch errors and spacing.
Date: Tue, 21 Jul 2020 17:39:43 +0200
Message-Id: <20200721153956.13555-3-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200721153956.13555-1-a.jung@lancs.ac.uk>
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Alexander Jung <a.jung@lancs.ac.uk>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Converting tabs to spaces and increasing readability.

Also fixes checkpatch errors:

* return is not a function, parentheses are not required
* trailing whitespace
* space required before the open parenthesis '('

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukring/include/uk/ring.h | 420 ++++++++++++++++++-----------------
 lib/ukring/ring.c            |  35 +--
 2 files changed, 236 insertions(+), 219 deletions(-)

diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
index 899563c..4f0d80c 100644
--- a/lib/ukring/include/uk/ring.h
+++ b/lib/ukring/include/uk/ring.h
@@ -29,8 +29,8 @@
  *
  */
 
-#ifndef	_SYS_BUF_RING_H_
-#define	_SYS_BUF_RING_H_
+#ifndef  _SYS_BUF_RING_H_
+#define  _SYS_BUF_RING_H_
 
 #include <machine/cpu.h>
 
@@ -39,22 +39,24 @@
 #include <sys/mutex.h>
 #endif
 
+
 struct buf_ring {
-	volatile uint32_t	br_prod_head;
-	volatile uint32_t	br_prod_tail;	
-	int              	br_prod_size;
-	int              	br_prod_mask;
-	uint64_t		br_drops;
-	volatile uint32_t	br_cons_head __aligned(CACHE_LINE_SIZE);
-	volatile uint32_t	br_cons_tail;
-	int		 	br_cons_size;
-	int              	br_cons_mask;
+  volatile uint32_t  br_prod_head;
+  volatile uint32_t  br_prod_tail;
+  int                br_prod_size;
+  int                br_prod_mask;
+  uint64_t           br_drops;
+  volatile uint32_t  br_cons_head __aligned(CACHE_LINE_SIZE);
+  volatile uint32_t  br_cons_tail;
+  int                br_cons_size;
+  int                br_cons_mask;
 #ifdef DEBUG_BUFRING
-	struct mtx		*br_lock;
-#endif	
-	void			*br_ring[0] __aligned(CACHE_LINE_SIZE);
+  struct mtx        *br_lock;
+#endif
+  void              *br_ring[0] __aligned(CACHE_LINE_SIZE);
 };
 
+
 /*
  * multi-producer safe lock-free ring buffer enqueue
  *
@@ -62,54 +64,60 @@ struct buf_ring {
 static __inline int
 buf_ring_enqueue(struct buf_ring *br, void *buf)
 {
-	uint32_t prod_head, prod_next, cons_tail;
+  uint32_t prod_head, prod_next, cons_tail;
+
 #ifdef DEBUG_BUFRING
-	int i;
-
-	/*
-	 * Note: It is possible to encounter an mbuf that was removed
-	 * via drbr_peek(), and then re-added via drbr_putback() and
-	 * trigger a spurious panic.
-	 */
-	for (i = br->br_cons_head; i != br->br_prod_head;
-	     i = ((i + 1) & br->br_cons_mask))
-		if(br->br_ring[i] == buf)
-			panic("buf=%p already enqueue at %d prod=%d cons=%d",
-			    buf, i, br->br_prod_tail, br->br_cons_tail);
-#endif	
-	critical_enter();
-	do {
-		prod_head = br->br_prod_head;
-		prod_next = (prod_head + 1) & br->br_prod_mask;
-		cons_tail = br->br_cons_tail;
-
-		if (prod_next == cons_tail) {
-			rmb();
-			if (prod_head == br->br_prod_head &&
-			    cons_tail == br->br_cons_tail) {
-				br->br_drops++;
-				critical_exit();
-				return (ENOBUFS);
-			}
-			continue;
-		}
-	} while (!atomic_cmpset_acq_int(&br->br_prod_head, prod_head, prod_next));
+  int i;
+
+  /*
+   * Note: It is possible to encounter an mbuf that was removed
+   * via drbr_peek(), and then re-added via drbr_putback() and
+   * trigger a spurious panic.
+   */
+  for (i = br->br_cons_head; i != br->br_prod_head;
+       i = ((i + 1) & br->br_cons_mask))
+    if (br->br_ring[i] == buf)
+      panic("buf=%p already enqueue at %d prod=%d cons=%d",
+          buf, i, br->br_prod_tail, br->br_cons_tail);
+#endif
+
+  critical_enter();
+
+  do {
+    prod_head = br->br_prod_head;
+    prod_next = (prod_head + 1) & br->br_prod_mask;
+    cons_tail = br->br_cons_tail;
+
+    if (prod_next == cons_tail) {
+      rmb();
+      if (prod_head == br->br_prod_head && cons_tail == br->br_cons_tail) {
+        br->br_drops++;
+        critical_exit();
+        return ENOBUFS;
+      }
+      continue;
+    }
+  } while (!atomic_cmpset_acq_int(&br->br_prod_head, prod_head, prod_next));
+
 #ifdef DEBUG_BUFRING
-	if (br->br_ring[prod_head] != NULL)
-		panic("dangling value in enqueue");
-#endif	
-	br->br_ring[prod_head] = buf;
-
-	/*
-	 * If there are other enqueues in progress
-	 * that preceded us, we need to wait for them
-	 * to complete 
-	 */   
-	while (br->br_prod_tail != prod_head)
-		cpu_spinwait();
-	atomic_store_rel_int(&br->br_prod_tail, prod_next);
-	critical_exit();
-	return (0);
+  if (br->br_ring[prod_head] != NULL)
+    panic("dangling value in enqueue");
+#endif
+
+  br->br_ring[prod_head] = buf;
+
+  /*
+   * If there are other enqueues in progress
+   * that preceded us, we need to wait for them
+   * to complete 
+   */
+  while (br->br_prod_tail != prod_head)
+    cpu_spinwait();
+
+  atomic_store_rel_int(&br->br_prod_tail, prod_next);
+  critical_exit();
+
+  return 0;
 }
 
 /*
@@ -119,36 +127,39 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
 static __inline void *
 buf_ring_dequeue_mc(struct buf_ring *br)
 {
-	uint32_t cons_head, cons_next;
-	void *buf;
+  uint32_t cons_head, cons_next;
+  void *buf;
+
+  critical_enter();
+
+  do {
+    cons_head = br->br_cons_head;
+    cons_next = (cons_head + 1) & br->br_cons_mask;
 
-	critical_enter();
-	do {
-		cons_head = br->br_cons_head;
-		cons_next = (cons_head + 1) & br->br_cons_mask;
+    if (cons_head == br->br_prod_tail) {
+      critical_exit();
+      return NULL;
+    }
+  } while (!atomic_cmpset_acq_int(&br->br_cons_head, cons_head, cons_next));
 
-		if (cons_head == br->br_prod_tail) {
-			critical_exit();
-			return (NULL);
-		}
-	} while (!atomic_cmpset_acq_int(&br->br_cons_head, cons_head, cons_next));
+  buf = br->br_ring[cons_head];
 
-	buf = br->br_ring[cons_head];
 #ifdef DEBUG_BUFRING
-	br->br_ring[cons_head] = NULL;
+  br->br_ring[cons_head] = NULL;
 #endif
-	/*
-	 * If there are other dequeues in progress
-	 * that preceded us, we need to wait for them
-	 * to complete 
-	 */   
-	while (br->br_cons_tail != cons_head)
-		cpu_spinwait();
-
-	atomic_store_rel_int(&br->br_cons_tail, cons_next);
-	critical_exit();
-
-	return (buf);
+
+  /*
+   * If there are other dequeues in progress
+   * that preceded us, we need to wait for them
+   * to complete
+   */
+  while (br->br_cons_tail != cons_head)
+    cpu_spinwait();
+
+  atomic_store_rel_int(&br->br_cons_tail, cons_next);
+  critical_exit();
+
+  return buf;
 }
 
 /*
@@ -159,72 +170,76 @@ buf_ring_dequeue_mc(struct buf_ring *br)
 static __inline void *
 buf_ring_dequeue_sc(struct buf_ring *br)
 {
-	uint32_t cons_head, cons_next;
+  uint32_t cons_head, cons_next;
 #ifdef PREFETCH_DEFINED
-	uint32_t cons_next_next;
+  uint32_t cons_next_next;
 #endif
-	uint32_t prod_tail;
-	void *buf;
-
-	/*
-	 * This is a workaround to allow using buf_ring on ARM and ARM64.
-	 * ARM64TODO: Fix buf_ring in a generic way.
-	 * REMARKS: It is suspected that br_cons_head does not require
-	 *   load_acq operation, but this change was extensively tested
-	 *   and confirmed it's working. To be reviewed once again in
-	 *   FreeBSD-12.
-	 *
-	 * Preventing following situation:
-	 * Core(0) - buf_ring_enqueue()                                       Core(1) - buf_ring_dequeue_sc()
-	 * -----------------------------------------                                       ----------------------------------------------
-	 *
-	 *                                                                                cons_head = br->br_cons_head;
-	 * atomic_cmpset_acq_32(&br->br_prod_head, ...));
-	 *                                                                                buf = br->br_ring[cons_head];     <see <1>>
-	 * br->br_ring[prod_head] = buf;
-	 * atomic_store_rel_32(&br->br_prod_tail, ...);
-	 *                                                                                prod_tail = br->br_prod_tail;
-	 *                                                                                if (cons_head == prod_tail) 
-	 *                                                                                        return (NULL);
-	 *                                                                                <condition is false and code uses invalid(old) buf>`	
-	 *
-	 * <1> Load (on core 1) from br->br_ring[cons_head] can be reordered (speculative readed) by CPU.
-	 */	
+  uint32_t prod_tail;
+  void *buf;
+
+  /*
+   * This is a workaround to allow using buf_ring on ARM and ARM64.
+   * ARM64TODO: Fix buf_ring in a generic way.
+   * REMARKS: It is suspected that br_cons_head does not require
+   *   load_acq operation, but this change was extensively tested
+   *   and confirmed it's working. To be reviewed once again in
+   *   FreeBSD-12.
+   *
+   * Preventing following situation:
+   * Core(0) - buf_ring_enqueue()                                       Core(1) - buf_ring_dequeue_sc()
+   * -----------------------------------------                                       ----------------------------------------------
+   *
+   *                                                                                cons_head = br->br_cons_head;
+   * atomic_cmpset_acq_32(&br->br_prod_head, ...));
+   *                                                                                buf = br->br_ring[cons_head];     <see <1>>
+   * br->br_ring[prod_head] = buf;
+   * atomic_store_rel_32(&br->br_prod_tail, ...);
+   *                                                                                prod_tail = br->br_prod_tail;
+   *                                                                                if (cons_head == prod_tail) 
+   *                                                                                        return (NULL);
+   *                                                                                <condition is false and code uses invalid(old) buf>`  
+   *
+   * <1> Load (on core 1) from br->br_ring[cons_head] can be reordered (speculative readed) by CPU.
+   */
 #if defined(__arm__) || defined(__aarch64__)
-	cons_head = atomic_load_acq_32(&br->br_cons_head);
+  cons_head = atomic_load_acq_32(&br->br_cons_head);
 #else
-	cons_head = br->br_cons_head;
+  cons_head = br->br_cons_head;
 #endif
-	prod_tail = atomic_load_acq_32(&br->br_prod_tail);
-	
-	cons_next = (cons_head + 1) & br->br_cons_mask;
+  prod_tail = atomic_load_acq_32(&br->br_prod_tail);
+
+  cons_next = (cons_head + 1) & br->br_cons_mask;
 #ifdef PREFETCH_DEFINED
-	cons_next_next = (cons_head + 2) & br->br_cons_mask;
+  cons_next_next = (cons_head + 2) & br->br_cons_mask;
 #endif
-	
-	if (cons_head == prod_tail) 
-		return (NULL);
-
-#ifdef PREFETCH_DEFINED	
-	if (cons_next != prod_tail) {		
-		prefetch(br->br_ring[cons_next]);
-		if (cons_next_next != prod_tail) 
-			prefetch(br->br_ring[cons_next_next]);
-	}
+
+  if (cons_head == prod_tail)
+    return NULL;
+
+#ifdef PREFETCH_DEFINED
+  if (cons_next != prod_tail) {
+    prefetch(br->br_ring[cons_next]);
+    if (cons_next_next != prod_tail)
+      prefetch(br->br_ring[cons_next_next]);
+  }
 #endif
-	br->br_cons_head = cons_next;
-	buf = br->br_ring[cons_head];
+
+  br->br_cons_head = cons_next;
+  buf = br->br_ring[cons_head];
 
 #ifdef DEBUG_BUFRING
-	br->br_ring[cons_head] = NULL;
-	if (!mtx_owned(br->br_lock))
-		panic("lock not held on single consumer dequeue");
-	if (br->br_cons_tail != cons_head)
-		panic("inconsistent list cons_tail=%d cons_head=%d",
-		    br->br_cons_tail, cons_head);
+  br->br_ring[cons_head] = NULL;
+
+  if (!mtx_owned(br->br_lock))
+    panic("lock not held on single consumer dequeue");
+
+  if (br->br_cons_tail != cons_head)
+    panic("inconsistent list cons_tail=%d cons_head=%d",
+        br->br_cons_tail, cons_head);
 #endif
-	br->br_cons_tail = cons_next;
-	return (buf);
+
+  br->br_cons_tail = cons_next;
+  return buf;
 }
 
 /*
@@ -235,20 +250,23 @@ buf_ring_dequeue_sc(struct buf_ring *br)
 static __inline void
 buf_ring_advance_sc(struct buf_ring *br)
 {
-	uint32_t cons_head, cons_next;
-	uint32_t prod_tail;
-	
-	cons_head = br->br_cons_head;
-	prod_tail = br->br_prod_tail;
-	
-	cons_next = (cons_head + 1) & br->br_cons_mask;
-	if (cons_head == prod_tail) 
-		return;
-	br->br_cons_head = cons_next;
+  uint32_t cons_head, cons_next;
+  uint32_t prod_tail;
+
+  cons_head = br->br_cons_head;
+  prod_tail = br->br_prod_tail;
+  cons_next = (cons_head + 1) & br->br_cons_mask;
+
+  if (cons_head == prod_tail)
+    return;
+
+  br->br_cons_head = cons_next;
+
 #ifdef DEBUG_BUFRING
-	br->br_ring[cons_head] = NULL;
+  br->br_ring[cons_head] = NULL;
 #endif
-	br->br_cons_tail = cons_next;
+
+  br->br_cons_tail = cons_next;
 }
 
 /*
@@ -270,9 +288,9 @@ buf_ring_advance_sc(struct buf_ring *br)
 static __inline void
 buf_ring_putback_sc(struct buf_ring *br, void *new)
 {
-	KASSERT(br->br_cons_head != br->br_prod_tail, 
-		("Buf-Ring has none in putback")) ;
-	br->br_ring[br->br_cons_head] = new;
+  KASSERT(br->br_cons_head != br->br_prod_tail,
+    ("Buf-Ring has none in putback"));
+  br->br_ring[br->br_cons_head] = new;
 }
 
 /*
@@ -283,89 +301,85 @@ buf_ring_putback_sc(struct buf_ring *br, void *new)
 static __inline void *
 buf_ring_peek(struct buf_ring *br)
 {
-
 #ifdef DEBUG_BUFRING
-	if ((br->br_lock != NULL) && !mtx_owned(br->br_lock))
-		panic("lock not held on single consumer dequeue");
-#endif	
-	/*
-	 * I believe it is safe to not have a memory barrier
-	 * here because we control cons and tail is worst case
-	 * a lagging indicator so we worst case we might
-	 * return NULL immediately after a buffer has been enqueued
-	 */
-	if (br->br_cons_head == br->br_prod_tail)
-		return (NULL);
-	
-	return (br->br_ring[br->br_cons_head]);
+  if ((br->br_lock != NULL) && !mtx_owned(br->br_lock))
+    panic("lock not held on single consumer dequeue");
+#endif
+
+  /*
+   * I believe it is safe to not have a memory barrier
+   * here because we control cons and tail is worst case
+   * a lagging indicator so we worst case we might
+   * return NULL immediately after a buffer has been enqueued
+   */
+  if (br->br_cons_head == br->br_prod_tail)
+    return NULL;
+
+  return br->br_ring[br->br_cons_head];
 }
 
 static __inline void *
 buf_ring_peek_clear_sc(struct buf_ring *br)
 {
 #ifdef DEBUG_BUFRING
-	void *ret;
+  void *ret;
 
-	if (!mtx_owned(br->br_lock))
-		panic("lock not held on single consumer dequeue");
-#endif	
+  if (!mtx_owned(br->br_lock))
+    panic("lock not held on single consumer dequeue");
+#endif
 
-	if (br->br_cons_head == br->br_prod_tail)
-		return (NULL);
+  if (br->br_cons_head == br->br_prod_tail)
+    return NULL;
 
 #if defined(__arm__) || defined(__aarch64__)
-	/*
-	 * The barrier is required there on ARM and ARM64 to ensure, that
-	 * br->br_ring[br->br_cons_head] will not be fetched before the above
-	 * condition is checked.
-	 * Without the barrier, it is possible, that buffer will be fetched
-	 * before the enqueue will put mbuf into br, then, in the meantime, the
-	 * enqueue will update the array and the br_prod_tail, and the
-	 * conditional check will be true, so we will return previously fetched
-	 * (and invalid) buffer.
-	 */
-	atomic_thread_fence_acq();
+  /*
+   * The barrier is required there on ARM and ARM64 to ensure, that
+   * br->br_ring[br->br_cons_head] will not be fetched before the above
+   * condition is checked.
+   * Without the barrier, it is possible, that buffer will be fetched
+   * before the enqueue will put mbuf into br, then, in the meantime, the
+   * enqueue will update the array and the br_prod_tail, and the
+   * conditional check will be true, so we will return previously fetched
+   * (and invalid) buffer.
+   */
+  atomic_thread_fence_acq();
 #endif
 
 #ifdef DEBUG_BUFRING
-	/*
-	 * Single consumer, i.e. cons_head will not move while we are
-	 * running, so atomic_swap_ptr() is not necessary here.
-	 */
-	ret = br->br_ring[br->br_cons_head];
-	br->br_ring[br->br_cons_head] = NULL;
-	return (ret);
+  /*
+   * Single consumer, i.e. cons_head will not move while we are
+   * running, so atomic_swap_ptr() is not necessary here.
+   */
+  ret = br->br_ring[br->br_cons_head];
+  br->br_ring[br->br_cons_head] = NULL;
+
+  return ret;
 #else
-	return (br->br_ring[br->br_cons_head]);
+  return br->br_ring[br->br_cons_head];
 #endif
 }
 
 static __inline int
 buf_ring_full(struct buf_ring *br)
 {
-
-	return (((br->br_prod_head + 1) & br->br_prod_mask) == br->br_cons_tail);
+  return ((br->br_prod_head + 1) & br->br_prod_mask) == br->br_cons_tail;
 }
 
 static __inline int
 buf_ring_empty(struct buf_ring *br)
 {
-
-	return (br->br_cons_head == br->br_prod_tail);
+  return br->br_cons_head == br->br_prod_tail;
 }
 
 static __inline int
 buf_ring_count(struct buf_ring *br)
 {
-
-	return ((br->br_prod_size + br->br_prod_tail - br->br_cons_tail)
-	    & br->br_prod_mask);
+  return (br->br_prod_size + br->br_prod_tail - br->br_cons_tail)
+      & br->br_prod_mask;
 }
 
 struct buf_ring *buf_ring_alloc(int count, struct malloc_type *type, int flags,
     struct mtx *);
 void buf_ring_free(struct buf_ring *br, struct malloc_type *type);
 
-
-
 #endif
\ No newline at end of file
diff --git a/lib/ukring/ring.c b/lib/ukring/ring.c
index 644c3be..ed5e8f7 100644
--- a/lib/ukring/ring.c
+++ b/lib/ukring/ring.c
@@ -39,27 +39,30 @@ __FBSDID("$FreeBSD$");
 struct buf_ring *
 buf_ring_alloc(int count, struct malloc_type *type, int flags, struct mtx *lock)
 {
-	struct buf_ring *br;
+  struct buf_ring *br;
+
+  KASSERT(powerof2(count), ("buf ring must be size power of 2"));
+
+  br = malloc(sizeof(struct buf_ring) + count*sizeof(caddr_t),
+      type, flags|M_ZERO);
+
+  if (br == NULL)
+    return NULL;
 
-	KASSERT(powerof2(count), ("buf ring must be size power of 2"));
-	
-	br = malloc(sizeof(struct buf_ring) + count*sizeof(caddr_t),
-	    type, flags|M_ZERO);
-	if (br == NULL)
-		return (NULL);
 #ifdef DEBUG_BUFRING
-	br->br_lock = lock;
-#endif	
-	br->br_prod_size = br->br_cons_size = count;
-	br->br_prod_mask = br->br_cons_mask = count-1;
-	br->br_prod_head = br->br_cons_head = 0;
-	br->br_prod_tail = br->br_cons_tail = 0;
-		
-	return (br);
+  br->br_lock = lock;
+#endif
+
+  br->br_prod_size = br->br_cons_size = count;
+  br->br_prod_mask = br->br_cons_mask = count - 1;
+  br->br_prod_head = br->br_cons_head = 0;
+  br->br_prod_tail = br->br_cons_tail = 0;
+
+  return br;
 }
 
 void
 buf_ring_free(struct buf_ring *br, struct malloc_type *type)
 {
-	free(br, type);
+  free(br, type);
 }
\ No newline at end of file
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 15:40:38 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 15:40:38 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxuNi-0002Ml-7h; Tue, 21 Jul 2020 15:40:38 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=HxHN=BA=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxuNh-0002MW-12
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 15:40:37 +0000
X-Inumbo-ID: 81ee696a-cb68-11ea-a0f8-12813bfff9fa
Received: from mh-is-1.lancs.ac.uk (unknown [148.88.65.129])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 81ee696a-cb68-11ea-a0f8-12813bfff9fa;
 Tue, 21 Jul 2020 15:40:31 +0000 (UTC)
Received: from mito.neclab.eu ([195.37.70.39] helo=localhost.localdomain)
 by mh-is-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jxuNY-0008vk-5T; Tue, 21 Jul 2020 16:40:30 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH, v2, 03/15] lib/ukring: Adapt {ring.c,
 ring.h} to  Unikraft
Date: Tue, 21 Jul 2020 17:39:44 +0200
Message-Id: <20200721153956.13555-4-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200721153956.13555-1-a.jung@lancs.ac.uk>
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Alexander Jung <a.jung@lancs.ac.uk>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

* Includes Unikraft-centric headers and types; and,
* Disables ARM{32,64}-specific atomic actions as unsupported;

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukring/include/uk/ring.h | 81 +++++++++++++++++++-----------------
 lib/ukring/ring.c            | 39 ++++++++++-------
 2 files changed, 66 insertions(+), 54 deletions(-)

diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
index 4f0d80c..021331a 100644
--- a/lib/ukring/include/uk/ring.h
+++ b/lib/ukring/include/uk/ring.h
@@ -32,13 +32,13 @@
 #ifndef  _SYS_BUF_RING_H_
 #define  _SYS_BUF_RING_H_
 
-#include <machine/cpu.h>
-
-#ifdef DEBUG_BUFRING
-#include <sys/lock.h>
-#include <sys/mutex.h>
-#endif
-
+#include <errno.h>
+#include <uk/mutex.h>
+#include <uk/print.h>
+#include <uk/config.h>
+#include <uk/assert.h>
+#include <uk/plat/lcpu.h>
+#include <uk/arch/atomic.h>
 
 struct buf_ring {
   volatile uint32_t  br_prod_head;
@@ -51,7 +51,7 @@ struct buf_ring {
   int                br_cons_size;
   int                br_cons_mask;
 #ifdef DEBUG_BUFRING
-  struct mtx        *br_lock;
+  struct uk_mutex   *br_lock;
 #endif
   void              *br_ring[0] __aligned(CACHE_LINE_SIZE);
 };
@@ -72,16 +72,16 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
   /*
    * Note: It is possible to encounter an mbuf that was removed
    * via drbr_peek(), and then re-added via drbr_putback() and
-   * trigger a spurious panic.
+   * trigger spurious critical messages.
    */
   for (i = br->br_cons_head; i != br->br_prod_head;
        i = ((i + 1) & br->br_cons_mask))
     if (br->br_ring[i] == buf)
-      panic("buf=%p already enqueue at %d prod=%d cons=%d",
+      uk_pr_crit("buf=%p already enqueue at %d prod=%d cons=%d\n",
           buf, i, br->br_prod_tail, br->br_cons_tail);
 #endif
 
-  critical_enter();
+  ukplat_lcpu_disable_irq();
 
   do {
     prod_head = br->br_prod_head;
@@ -92,16 +92,16 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
       rmb();
       if (prod_head == br->br_prod_head && cons_tail == br->br_cons_tail) {
         br->br_drops++;
-        critical_exit();
+        ukplat_lcpu_enable_irq();
         return ENOBUFS;
       }
       continue;
     }
-  } while (!atomic_cmpset_acq_int(&br->br_prod_head, prod_head, prod_next));
+  } while (!ukarch_compare_exchange_sync(&br->br_prod_head, prod_head, prod_next));
 
 #ifdef DEBUG_BUFRING
   if (br->br_ring[prod_head] != NULL)
-    panic("dangling value in enqueue");
+    uk_pr_crit("dangling value in enqueue\n");
 #endif
 
   br->br_ring[prod_head] = buf;
@@ -114,8 +114,8 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
   while (br->br_prod_tail != prod_head)
     cpu_spinwait();
 
-  atomic_store_rel_int(&br->br_prod_tail, prod_next);
-  critical_exit();
+  ukarch_store_n(&br->br_prod_tail, prod_next);
+  ukplat_lcpu_enable_irq();
 
   return 0;
 }
@@ -130,17 +130,17 @@ buf_ring_dequeue_mc(struct buf_ring *br)
   uint32_t cons_head, cons_next;
   void *buf;
 
-  critical_enter();
+  ukplat_lcpu_disable_irq();
 
   do {
     cons_head = br->br_cons_head;
     cons_next = (cons_head + 1) & br->br_cons_mask;
 
     if (cons_head == br->br_prod_tail) {
-      critical_exit();
+      ukplat_lcpu_enable_irq();
       return NULL;
     }
-  } while (!atomic_cmpset_acq_int(&br->br_cons_head, cons_head, cons_next));
+  } while (!ukarch_compare_exchange_sync(&br->br_cons_head, cons_head, cons_next));
 
   buf = br->br_ring[cons_head];
 
@@ -156,8 +156,8 @@ buf_ring_dequeue_mc(struct buf_ring *br)
   while (br->br_cons_tail != cons_head)
     cpu_spinwait();
 
-  atomic_store_rel_int(&br->br_cons_tail, cons_next);
-  critical_exit();
+  ukarch_store_n(&br->br_cons_tail, cons_next);
+  ukplat_lcpu_enable_irq();
 
   return buf;
 }
@@ -201,12 +201,16 @@ buf_ring_dequeue_sc(struct buf_ring *br)
    *
    * <1> Load (on core 1) from br->br_ring[cons_head] can be reordered (speculative readed) by CPU.
    */
-#if defined(__arm__) || defined(__aarch64__)
-  cons_head = atomic_load_acq_32(&br->br_cons_head);
+#if defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64)
+  /* TODO: Provide atomic_load_acq_32() */
+  /* cons_head = atomic_load_acq_32(&br->br_cons_head); */
+  cons_head = &br->br_cons_head;
 #else
   cons_head = br->br_cons_head;
 #endif
-  prod_tail = atomic_load_acq_32(&br->br_prod_tail);
+  /* TODO: Provide atomic_load_acq_32() */
+  /* prod_tail = atomic_load_acq_32(&br->br_prod_tail); */
+  prod_tail = &br->br_prod_tail;
 
   cons_next = (cons_head + 1) & br->br_cons_mask;
 #ifdef PREFETCH_DEFINED
@@ -230,11 +234,11 @@ buf_ring_dequeue_sc(struct buf_ring *br)
 #ifdef DEBUG_BUFRING
   br->br_ring[cons_head] = NULL;
 
-  if (!mtx_owned(br->br_lock))
-    panic("lock not held on single consumer dequeue");
+  if (!uk_mutex_is_locked(r->lock))
+    uk_pr_crit("lock not held on single consumer dequeue\n");
 
   if (br->br_cons_tail != cons_head)
-    panic("inconsistent list cons_tail=%d cons_head=%d",
+    uk_pr_crit("inconsistent list cons_tail=%d cons_head=%d\n",
         br->br_cons_tail, cons_head);
 #endif
 
@@ -288,8 +292,8 @@ buf_ring_advance_sc(struct buf_ring *br)
 static __inline void
 buf_ring_putback_sc(struct buf_ring *br, void *new)
 {
-  KASSERT(br->br_cons_head != br->br_prod_tail,
-    ("Buf-Ring has none in putback"));
+  /* Buffer ring has none in putback */
+  UK_ASSERT(br->br_cons_head != br->br_prod_tail);
   br->br_ring[br->br_cons_head] = new;
 }
 
@@ -302,8 +306,8 @@ static __inline void *
 buf_ring_peek(struct buf_ring *br)
 {
 #ifdef DEBUG_BUFRING
-  if ((br->br_lock != NULL) && !mtx_owned(br->br_lock))
-    panic("lock not held on single consumer dequeue");
+  if ((r->lock != NULL) && !uk_mutex_is_locked(r->lock))
+    uk_pr_crit("lock not held on single consumer dequeue\n");
 #endif
 
   /*
@@ -324,14 +328,14 @@ buf_ring_peek_clear_sc(struct buf_ring *br)
 #ifdef DEBUG_BUFRING
   void *ret;
 
-  if (!mtx_owned(br->br_lock))
-    panic("lock not held on single consumer dequeue");
+  if (!uk_mutex_is_locked(r->lock))
+    uk_pr_crit("lock not held on single consumer dequeue\n");
 #endif
 
   if (br->br_cons_head == br->br_prod_tail)
     return NULL;
 
-#if defined(__arm__) || defined(__aarch64__)
+#if defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64)
   /*
    * The barrier is required there on ARM and ARM64 to ensure, that
    * br->br_ring[br->br_cons_head] will not be fetched before the above
@@ -342,7 +346,8 @@ buf_ring_peek_clear_sc(struct buf_ring *br)
    * conditional check will be true, so we will return previously fetched
    * (and invalid) buffer.
    */
-  atomic_thread_fence_acq();
+  /* TODO: Provide atomic_thread_fence_acq(); */
+  /* atomic_thread_fence_acq(); */
 #endif
 
 #ifdef DEBUG_BUFRING
@@ -378,8 +383,8 @@ buf_ring_count(struct buf_ring *br)
       & br->br_prod_mask;
 }
 
-struct buf_ring *buf_ring_alloc(int count, struct malloc_type *type, int flags,
-    struct mtx *);
-void buf_ring_free(struct buf_ring *br, struct malloc_type *type);
+struct buf_ring *buf_ring_alloc(struct uk_alloc *a, int count, int flags,
+    struct uk_mutex *);
+void buf_ring_free(struct uk_alloc *a, struct buf_ring *br);
 
 #endif
\ No newline at end of file
diff --git a/lib/ukring/ring.c b/lib/ukring/ring.c
index ed5e8f7..3f3e053 100644
--- a/lib/ukring/ring.c
+++ b/lib/ukring/ring.c
@@ -26,28 +26,35 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 #include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/malloc.h>
-#include <sys/ktr.h>
-#include <sys/buf_ring.h>
+#include <uk/ring.h>
+#include <uk/assert.h>
+#include <uk/alloc.h>
+#include <uk/mutex.h>
+#include <uk/config.h>
+#include <uk/print.h>
+
+#ifndef POWER_OF_2
+#define POWER_OF_2(x)   (((x)) && (!((x) & ((x) - 1))))
+#endif
 
-struct buf_ring *
-buf_ring_alloc(int count, struct malloc_type *type, int flags, struct mtx *lock)
+struct uk_ring *
+uk_ring_alloc(struct uk_alloc *a, int count, int flags, struct uk_mutex *lock)
 {
   struct buf_ring *br;
 
-  KASSERT(powerof2(count), ("buf ring must be size power of 2"));
+  if (a == NULL)
+    a = uk_alloc_get_default();
+
+  /* Buf ring must be size power of 2 */
+  UK_ASSERT(POWER_OF_2(count));
 
-  br = malloc(sizeof(struct buf_ring) + count*sizeof(caddr_t),
-      type, flags|M_ZERO);
+  r = uk_malloc(a, sizeof(struct uk_ring) + count * sizeof(caddr_t));
 
-  if (br == NULL)
+  if (br == NULL) {
+    uk_pr_err("Could not allocate ring: out of memory\n");
     return NULL;
+  }
 
 #ifdef DEBUG_BUFRING
   br->br_lock = lock;
@@ -62,7 +69,7 @@ buf_ring_alloc(int count, struct malloc_type *type, int flags, struct mtx *lock)
 }
 
 void
-buf_ring_free(struct buf_ring *br, struct malloc_type *type)
+uk_ring_free(struct uk_alloc *a, struct uk_ring *r)
 {
-  free(br, type);
+  uk_free(a, br);
 }
\ No newline at end of file
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 15:40:43 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 15:40:43 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxuNn-0002Nc-9g; Tue, 21 Jul 2020 15:40:43 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=HxHN=BA=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxuNl-0002MW-Tl
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 15:40:41 +0000
X-Inumbo-ID: 83981a2c-cb68-11ea-a0f8-12813bfff9fa
Received: from mh-is-1.lancs.ac.uk (unknown [148.88.65.129])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 83981a2c-cb68-11ea-a0f8-12813bfff9fa;
 Tue, 21 Jul 2020 15:40:33 +0000 (UTC)
Received: from mito.neclab.eu ([195.37.70.39] helo=localhost.localdomain)
 by mh-is-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jxuNb-0008vk-5h; Tue, 21 Jul 2020 16:40:33 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH, v2,
 04/15] lib/ukring: Re-prefix methods and structs  from buf_ to uk_
Date: Tue, 21 Jul 2020 17:39:45 +0200
Message-Id: <20200721153956.13555-5-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200721153956.13555-1-a.jung@lancs.ac.uk>
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Alexander Jung <a.jung@lancs.ac.uk>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukring/include/uk/ring.h | 36 ++++++++++++++++++------------------
 lib/ukring/ring.c            |  2 +-
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
index 021331a..e5f5b68 100644
--- a/lib/ukring/include/uk/ring.h
+++ b/lib/ukring/include/uk/ring.h
@@ -29,8 +29,8 @@
  *
  */
 
-#ifndef  _SYS_BUF_RING_H_
-#define  _SYS_BUF_RING_H_
+#ifndef __UK_RING_H__
+#define __UK_RING_H__
 
 #include <errno.h>
 #include <uk/mutex.h>
@@ -40,7 +40,7 @@
 #include <uk/plat/lcpu.h>
 #include <uk/arch/atomic.h>
 
-struct buf_ring {
+struct uk_ring {
   volatile uint32_t  br_prod_head;
   volatile uint32_t  br_prod_tail;
   int                br_prod_size;
@@ -62,7 +62,7 @@ struct buf_ring {
  *
  */
 static __inline int
-buf_ring_enqueue(struct buf_ring *br, void *buf)
+uk_ring_enqueue(struct uk_ring *br, void *buf)
 {
   uint32_t prod_head, prod_next, cons_tail;
 
@@ -125,7 +125,7 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
  *
  */
 static __inline void *
-buf_ring_dequeue_mc(struct buf_ring *br)
+uk_ring_dequeue_mc(struct uk_ring *br)
 {
   uint32_t cons_head, cons_next;
   void *buf;
@@ -168,7 +168,7 @@ buf_ring_dequeue_mc(struct buf_ring *br)
  * e.g. a network driver's tx queue lock
  */
 static __inline void *
-buf_ring_dequeue_sc(struct buf_ring *br)
+uk_ring_dequeue_sc(struct uk_ring *br)
 {
   uint32_t cons_head, cons_next;
 #ifdef PREFETCH_DEFINED
@@ -178,15 +178,15 @@ buf_ring_dequeue_sc(struct buf_ring *br)
   void *buf;
 
   /*
-   * This is a workaround to allow using buf_ring on ARM and ARM64.
-   * ARM64TODO: Fix buf_ring in a generic way.
+   * This is a workaround to allow using uk_ring on ARM and ARM64.
+   * ARM64TODO: Fix uk_ring in a generic way.
    * REMARKS: It is suspected that br_cons_head does not require
    *   load_acq operation, but this change was extensively tested
    *   and confirmed it's working. To be reviewed once again in
    *   FreeBSD-12.
    *
    * Preventing following situation:
-   * Core(0) - buf_ring_enqueue()                                       Core(1) - buf_ring_dequeue_sc()
+   * Core(0) - uk_ring_enqueue()                                       Core(1) - uk_ring_dequeue_sc()
    * -----------------------------------------                                       ----------------------------------------------
    *
    *                                                                                cons_head = br->br_cons_head;
@@ -252,7 +252,7 @@ buf_ring_dequeue_sc(struct buf_ring *br)
  * e.g. a network driver's tx queue lock
  */
 static __inline void
-buf_ring_advance_sc(struct buf_ring *br)
+uk_ring_advance_sc(struct uk_ring *br)
 {
   uint32_t cons_head, cons_next;
   uint32_t prod_tail;
@@ -290,7 +290,7 @@ buf_ring_advance_sc(struct buf_ring *br)
  * the compare and an atomic.
  */
 static __inline void
-buf_ring_putback_sc(struct buf_ring *br, void *new)
+uk_ring_putback_sc(struct uk_ring *br, void *new)
 {
   /* Buffer ring has none in putback */
   UK_ASSERT(br->br_cons_head != br->br_prod_tail);
@@ -303,7 +303,7 @@ buf_ring_putback_sc(struct buf_ring *br, void *new)
  * race-prone if not protected by a lock
  */
 static __inline void *
-buf_ring_peek(struct buf_ring *br)
+uk_ring_peek(struct uk_ring *br)
 {
 #ifdef DEBUG_BUFRING
   if ((r->lock != NULL) && !uk_mutex_is_locked(r->lock))
@@ -323,7 +323,7 @@ buf_ring_peek(struct buf_ring *br)
 }
 
 static __inline void *
-buf_ring_peek_clear_sc(struct buf_ring *br)
+uk_ring_peek_clear_sc(struct uk_ring *br)
 {
 #ifdef DEBUG_BUFRING
   void *ret;
@@ -365,26 +365,26 @@ buf_ring_peek_clear_sc(struct buf_ring *br)
 }
 
 static __inline int
-buf_ring_full(struct buf_ring *br)
+uk_ring_full(struct uk_ring *br)
 {
   return ((br->br_prod_head + 1) & br->br_prod_mask) == br->br_cons_tail;
 }
 
 static __inline int
-buf_ring_empty(struct buf_ring *br)
+uk_ring_empty(struct uk_ring *br)
 {
   return br->br_cons_head == br->br_prod_tail;
 }
 
 static __inline int
-buf_ring_count(struct buf_ring *br)
+uk_ring_count(struct uk_ring *br)
 {
   return (br->br_prod_size + br->br_prod_tail - br->br_cons_tail)
       & br->br_prod_mask;
 }
 
-struct buf_ring *buf_ring_alloc(struct uk_alloc *a, int count, int flags,
+struct uk_ring *uk_ring_alloc(struct uk_alloc *a, int count, int flags,
     struct uk_mutex *);
-void buf_ring_free(struct uk_alloc *a, struct buf_ring *br);
+void uk_ring_free(struct uk_alloc *a, struct uk_ring *br);
 
 #endif
\ No newline at end of file
diff --git a/lib/ukring/ring.c b/lib/ukring/ring.c
index 3f3e053..658130e 100644
--- a/lib/ukring/ring.c
+++ b/lib/ukring/ring.c
@@ -41,7 +41,7 @@
 struct uk_ring *
 uk_ring_alloc(struct uk_alloc *a, int count, int flags, struct uk_mutex *lock)
 {
-  struct buf_ring *br;
+  struct uk_ring *br;
 
   if (a == NULL)
     a = uk_alloc_get_default();
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 15:40:48 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 15:40:48 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxuNs-0002Of-BN; Tue, 21 Jul 2020 15:40:48 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=HxHN=BA=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxuNq-0002MW-VE
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 15:40:47 +0000
X-Inumbo-ID: 84aff291-cb68-11ea-a0f8-12813bfff9fa
Received: from mh-is-1.lancs.ac.uk (unknown [148.88.65.129])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 84aff291-cb68-11ea-a0f8-12813bfff9fa;
 Tue, 21 Jul 2020 15:40:37 +0000 (UTC)
Received: from mito.neclab.eu ([195.37.70.39] helo=localhost.localdomain)
 by mh-is-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jxuNe-0008vk-54; Tue, 21 Jul 2020 16:40:36 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH, v2,
 05/15] lib/ukring: Remove br_ prefix and rename br variable
Date: Tue, 21 Jul 2020 17:39:46 +0200
Message-Id: <20200721153956.13555-6-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200721153956.13555-1-a.jung@lancs.ac.uk>
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Alexander Jung <a.jung@lancs.ac.uk>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This commit removes the br_ prefix from within the `uk_ring`
struct and renames all instances of the br variable to simple r.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukring/include/uk/ring.h | 178 +++++++++++++++++------------------
 lib/ukring/ring.c            |  18 ++--
 2 files changed, 98 insertions(+), 98 deletions(-)

diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
index e5f5b68..26ac2f8 100644
--- a/lib/ukring/include/uk/ring.h
+++ b/lib/ukring/include/uk/ring.h
@@ -41,19 +41,19 @@
 #include <uk/arch/atomic.h>
 
 struct uk_ring {
-  volatile uint32_t  br_prod_head;
-  volatile uint32_t  br_prod_tail;
-  int                br_prod_size;
-  int                br_prod_mask;
-  uint64_t           br_drops;
-  volatile uint32_t  br_cons_head __aligned(CACHE_LINE_SIZE);
-  volatile uint32_t  br_cons_tail;
-  int                br_cons_size;
-  int                br_cons_mask;
+  volatile uint32_t  prod_head;
+  volatile uint32_t  prod_tail;
+  int                prod_size;
+  int                prod_mask;
+  uint64_t           drops;
+  volatile uint32_t  cons_head __aligned(CACHE_LINE_SIZE);
+  volatile uint32_t  cons_tail;
+  int                cons_size;
+  int                cons_mask;
 #ifdef DEBUG_BUFRING
-  struct uk_mutex   *br_lock;
+  struct uk_mutex   *lock;
 #endif
-  void              *br_ring[0] __aligned(CACHE_LINE_SIZE);
+  void              *ring[0] __aligned(CACHE_LINE_SIZE);
 };
 
 
@@ -62,7 +62,7 @@ struct uk_ring {
  *
  */
 static __inline int
-uk_ring_enqueue(struct uk_ring *br, void *buf)
+uk_ring_enqueue(struct uk_ring *r, void *buf)
 {
   uint32_t prod_head, prod_next, cons_tail;
 
@@ -71,50 +71,50 @@ uk_ring_enqueue(struct uk_ring *br, void *buf)
 
   /*
    * Note: It is possible to encounter an mbuf that was removed
-   * via drbr_peek(), and then re-added via drbr_putback() and
+   * via drpeek(), and then re-added via drputback() and
    * trigger spurious critical messages.
    */
-  for (i = br->br_cons_head; i != br->br_prod_head;
-       i = ((i + 1) & br->br_cons_mask))
-    if (br->br_ring[i] == buf)
+  for (i = r->cons_head; i != r->prod_head;
+       i = ((i + 1) & r->cons_mask))
+    if (r->ring[i] == buf)
       uk_pr_crit("buf=%p already enqueue at %d prod=%d cons=%d\n",
-          buf, i, br->br_prod_tail, br->br_cons_tail);
+          buf, i, r->prod_tail, r->cons_tail);
 #endif
 
   ukplat_lcpu_disable_irq();
 
   do {
-    prod_head = br->br_prod_head;
-    prod_next = (prod_head + 1) & br->br_prod_mask;
-    cons_tail = br->br_cons_tail;
+    prod_head = r->prod_head;
+    prod_next = (prod_head + 1) & r->prod_mask;
+    cons_tail = r->cons_tail;
 
     if (prod_next == cons_tail) {
       rmb();
-      if (prod_head == br->br_prod_head && cons_tail == br->br_cons_tail) {
-        br->br_drops++;
+      if (prod_head == r->prod_head && cons_tail == r->cons_tail) {
+        r->drops++;
         ukplat_lcpu_enable_irq();
         return ENOBUFS;
       }
       continue;
     }
-  } while (!ukarch_compare_exchange_sync(&br->br_prod_head, prod_head, prod_next));
+  } while (!ukarch_compare_exchange_sync(&r->prod_head, prod_head, prod_next));
 
 #ifdef DEBUG_BUFRING
-  if (br->br_ring[prod_head] != NULL)
+  if (r->ring[prod_head] != NULL)
     uk_pr_crit("dangling value in enqueue\n");
 #endif
 
-  br->br_ring[prod_head] = buf;
+  r->ring[prod_head] = buf;
 
   /*
    * If there are other enqueues in progress
    * that preceded us, we need to wait for them
    * to complete 
    */
-  while (br->br_prod_tail != prod_head)
+  while (r->prod_tail != prod_head)
     cpu_spinwait();
 
-  ukarch_store_n(&br->br_prod_tail, prod_next);
+  ukarch_store_n(&r->prod_tail, prod_next);
   ukplat_lcpu_enable_irq();
 
   return 0;
@@ -125,7 +125,7 @@ uk_ring_enqueue(struct uk_ring *br, void *buf)
  *
  */
 static __inline void *
-uk_ring_dequeue_mc(struct uk_ring *br)
+uk_ring_dequeue_mc(struct uk_ring *r)
 {
   uint32_t cons_head, cons_next;
   void *buf;
@@ -133,19 +133,19 @@ uk_ring_dequeue_mc(struct uk_ring *br)
   ukplat_lcpu_disable_irq();
 
   do {
-    cons_head = br->br_cons_head;
-    cons_next = (cons_head + 1) & br->br_cons_mask;
+    cons_head = r->cons_head;
+    cons_next = (cons_head + 1) & r->cons_mask;
 
-    if (cons_head == br->br_prod_tail) {
+    if (cons_head == r->prod_tail) {
       ukplat_lcpu_enable_irq();
       return NULL;
     }
-  } while (!ukarch_compare_exchange_sync(&br->br_cons_head, cons_head, cons_next));
+  } while (!ukarch_compare_exchange_sync(&r->cons_head, cons_head, cons_next));
 
-  buf = br->br_ring[cons_head];
+  buf = r->ring[cons_head];
 
 #ifdef DEBUG_BUFRING
-  br->br_ring[cons_head] = NULL;
+  r->ring[cons_head] = NULL;
 #endif
 
   /*
@@ -153,10 +153,10 @@ uk_ring_dequeue_mc(struct uk_ring *br)
    * that preceded us, we need to wait for them
    * to complete
    */
-  while (br->br_cons_tail != cons_head)
+  while (r->cons_tail != cons_head)
     cpu_spinwait();
 
-  ukarch_store_n(&br->br_cons_tail, cons_next);
+  ukarch_store_n(&r->cons_tail, cons_next);
   ukplat_lcpu_enable_irq();
 
   return buf;
@@ -168,7 +168,7 @@ uk_ring_dequeue_mc(struct uk_ring *br)
  * e.g. a network driver's tx queue lock
  */
 static __inline void *
-uk_ring_dequeue_sc(struct uk_ring *br)
+uk_ring_dequeue_sc(struct uk_ring *r)
 {
   uint32_t cons_head, cons_next;
 #ifdef PREFETCH_DEFINED
@@ -180,7 +180,7 @@ uk_ring_dequeue_sc(struct uk_ring *br)
   /*
    * This is a workaround to allow using uk_ring on ARM and ARM64.
    * ARM64TODO: Fix uk_ring in a generic way.
-   * REMARKS: It is suspected that br_cons_head does not require
+   * REMARKS: It is suspected that cons_head does not require
    *   load_acq operation, but this change was extensively tested
    *   and confirmed it's working. To be reviewed once again in
    *   FreeBSD-12.
@@ -189,32 +189,32 @@ uk_ring_dequeue_sc(struct uk_ring *br)
    * Core(0) - uk_ring_enqueue()                                       Core(1) - uk_ring_dequeue_sc()
    * -----------------------------------------                                       ----------------------------------------------
    *
-   *                                                                                cons_head = br->br_cons_head;
-   * atomic_cmpset_acq_32(&br->br_prod_head, ...));
-   *                                                                                buf = br->br_ring[cons_head];     <see <1>>
-   * br->br_ring[prod_head] = buf;
-   * atomic_store_rel_32(&br->br_prod_tail, ...);
-   *                                                                                prod_tail = br->br_prod_tail;
+   *                                                                                cons_head = r->cons_head;
+   * atomic_cmpset_acq_32(&r->prod_head, ...));
+   *                                                                                buf = r->ring[cons_head];     <see <1>>
+   * r->ring[prod_head] = buf;
+   * atomic_store_rel_32(&r->prod_tail, ...);
+   *                                                                                prod_tail = r->prod_tail;
    *                                                                                if (cons_head == prod_tail) 
    *                                                                                        return (NULL);
    *                                                                                <condition is false and code uses invalid(old) buf>`  
    *
-   * <1> Load (on core 1) from br->br_ring[cons_head] can be reordered (speculative readed) by CPU.
+   * <1> Load (on core 1) from r->ring[cons_head] can be reordered (speculative readed) by CPU.
    */
 #if defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64)
   /* TODO: Provide atomic_load_acq_32() */
-  /* cons_head = atomic_load_acq_32(&br->br_cons_head); */
-  cons_head = &br->br_cons_head;
+  /* cons_head = atomic_load_acq_32(&r->cons_head); */
+  cons_head = &r->cons_head;
 #else
-  cons_head = br->br_cons_head;
+  cons_head = r->cons_head;
 #endif
   /* TODO: Provide atomic_load_acq_32() */
-  /* prod_tail = atomic_load_acq_32(&br->br_prod_tail); */
-  prod_tail = &br->br_prod_tail;
+  /* prod_tail = atomic_load_acq_32(&r->prod_tail); */
+  prod_tail = &r->prod_tail;
 
-  cons_next = (cons_head + 1) & br->br_cons_mask;
+  cons_next = (cons_head + 1) & r->cons_mask;
 #ifdef PREFETCH_DEFINED
-  cons_next_next = (cons_head + 2) & br->br_cons_mask;
+  cons_next_next = (cons_head + 2) & r->cons_mask;
 #endif
 
   if (cons_head == prod_tail)
@@ -222,27 +222,27 @@ uk_ring_dequeue_sc(struct uk_ring *br)
 
 #ifdef PREFETCH_DEFINED
   if (cons_next != prod_tail) {
-    prefetch(br->br_ring[cons_next]);
+    prefetch(r->ring[cons_next]);
     if (cons_next_next != prod_tail)
-      prefetch(br->br_ring[cons_next_next]);
+      prefetch(r->ring[cons_next_next]);
   }
 #endif
 
-  br->br_cons_head = cons_next;
-  buf = br->br_ring[cons_head];
+  r->cons_head = cons_next;
+  buf = r->ring[cons_head];
 
 #ifdef DEBUG_BUFRING
-  br->br_ring[cons_head] = NULL;
+  r->ring[cons_head] = NULL;
 
   if (!uk_mutex_is_locked(r->lock))
     uk_pr_crit("lock not held on single consumer dequeue\n");
 
-  if (br->br_cons_tail != cons_head)
+  if (r->cons_tail != cons_head)
     uk_pr_crit("inconsistent list cons_tail=%d cons_head=%d\n",
-        br->br_cons_tail, cons_head);
+        r->cons_tail, cons_head);
 #endif
 
-  br->br_cons_tail = cons_next;
+  r->cons_tail = cons_next;
   return buf;
 }
 
@@ -252,25 +252,25 @@ uk_ring_dequeue_sc(struct uk_ring *br)
  * e.g. a network driver's tx queue lock
  */
 static __inline void
-uk_ring_advance_sc(struct uk_ring *br)
+uk_ring_advance_sc(struct uk_ring *r)
 {
   uint32_t cons_head, cons_next;
   uint32_t prod_tail;
 
-  cons_head = br->br_cons_head;
-  prod_tail = br->br_prod_tail;
-  cons_next = (cons_head + 1) & br->br_cons_mask;
+  cons_head = r->cons_head;
+  prod_tail = r->prod_tail;
+  cons_next = (cons_head + 1) & r->cons_mask;
 
   if (cons_head == prod_tail)
     return;
 
-  br->br_cons_head = cons_next;
+  r->cons_head = cons_next;
 
 #ifdef DEBUG_BUFRING
-  br->br_ring[cons_head] = NULL;
+  r->ring[cons_head] = NULL;
 #endif
 
-  br->br_cons_tail = cons_next;
+  r->cons_tail = cons_next;
 }
 
 /*
@@ -290,11 +290,11 @@ uk_ring_advance_sc(struct uk_ring *br)
  * the compare and an atomic.
  */
 static __inline void
-uk_ring_putback_sc(struct uk_ring *br, void *new)
+uk_ring_putback_sc(struct uk_ring *r, void *new)
 {
   /* Buffer ring has none in putback */
-  UK_ASSERT(br->br_cons_head != br->br_prod_tail);
-  br->br_ring[br->br_cons_head] = new;
+  UK_ASSERT(r->cons_head != r->prod_tail);
+  r->ring[r->cons_head] = new;
 }
 
 /*
@@ -303,7 +303,7 @@ uk_ring_putback_sc(struct uk_ring *br, void *new)
  * race-prone if not protected by a lock
  */
 static __inline void *
-uk_ring_peek(struct uk_ring *br)
+uk_ring_peek(struct uk_ring *r)
 {
 #ifdef DEBUG_BUFRING
   if ((r->lock != NULL) && !uk_mutex_is_locked(r->lock))
@@ -316,14 +316,14 @@ uk_ring_peek(struct uk_ring *br)
    * a lagging indicator so we worst case we might
    * return NULL immediately after a buffer has been enqueued
    */
-  if (br->br_cons_head == br->br_prod_tail)
+  if (r->cons_head == r->prod_tail)
     return NULL;
 
-  return br->br_ring[br->br_cons_head];
+  return r->ring[r->cons_head];
 }
 
 static __inline void *
-uk_ring_peek_clear_sc(struct uk_ring *br)
+uk_ring_peek_clear_sc(struct uk_ring *r)
 {
 #ifdef DEBUG_BUFRING
   void *ret;
@@ -332,17 +332,17 @@ uk_ring_peek_clear_sc(struct uk_ring *br)
     uk_pr_crit("lock not held on single consumer dequeue\n");
 #endif
 
-  if (br->br_cons_head == br->br_prod_tail)
+  if (r->cons_head == r->prod_tail)
     return NULL;
 
 #if defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64)
   /*
    * The barrier is required there on ARM and ARM64 to ensure, that
-   * br->br_ring[br->br_cons_head] will not be fetched before the above
+   * r->ring[r->cons_head] will not be fetched before the above
    * condition is checked.
    * Without the barrier, it is possible, that buffer will be fetched
-   * before the enqueue will put mbuf into br, then, in the meantime, the
-   * enqueue will update the array and the br_prod_tail, and the
+   * before the enqueue will put mbuf into r, then, in the meantime, the
+   * enqueue will update the array and the prod_tail, and the
    * conditional check will be true, so we will return previously fetched
    * (and invalid) buffer.
    */
@@ -355,36 +355,36 @@ uk_ring_peek_clear_sc(struct uk_ring *br)
    * Single consumer, i.e. cons_head will not move while we are
    * running, so atomic_swap_ptr() is not necessary here.
    */
-  ret = br->br_ring[br->br_cons_head];
-  br->br_ring[br->br_cons_head] = NULL;
+  ret = r->ring[r->cons_head];
+  r->ring[r->cons_head] = NULL;
 
   return ret;
 #else
-  return br->br_ring[br->br_cons_head];
+  return r->ring[r->cons_head];
 #endif
 }
 
 static __inline int
-uk_ring_full(struct uk_ring *br)
+uk_ring_full(struct uk_ring *r)
 {
-  return ((br->br_prod_head + 1) & br->br_prod_mask) == br->br_cons_tail;
+  return ((r->prod_head + 1) & r->prod_mask) == r->cons_tail;
 }
 
 static __inline int
-uk_ring_empty(struct uk_ring *br)
+uk_ring_empty(struct uk_ring *r)
 {
-  return br->br_cons_head == br->br_prod_tail;
+  return r->cons_head == r->prod_tail;
 }
 
 static __inline int
-uk_ring_count(struct uk_ring *br)
+uk_ring_count(struct uk_ring *r)
 {
-  return (br->br_prod_size + br->br_prod_tail - br->br_cons_tail)
-      & br->br_prod_mask;
+  return (r->prod_size + r->prod_tail - r->cons_tail)
+      & r->prod_mask;
 }
 
 struct uk_ring *uk_ring_alloc(struct uk_alloc *a, int count, int flags,
     struct uk_mutex *);
-void uk_ring_free(struct uk_alloc *a, struct uk_ring *br);
+void uk_ring_free(struct uk_alloc *a, struct uk_ring *r);
 
 #endif
\ No newline at end of file
diff --git a/lib/ukring/ring.c b/lib/ukring/ring.c
index 658130e..1431cb9 100644
--- a/lib/ukring/ring.c
+++ b/lib/ukring/ring.c
@@ -41,7 +41,7 @@
 struct uk_ring *
 uk_ring_alloc(struct uk_alloc *a, int count, int flags, struct uk_mutex *lock)
 {
-  struct uk_ring *br;
+  struct uk_ring *r;
 
   if (a == NULL)
     a = uk_alloc_get_default();
@@ -51,25 +51,25 @@ uk_ring_alloc(struct uk_alloc *a, int count, int flags, struct uk_mutex *lock)
 
   r = uk_malloc(a, sizeof(struct uk_ring) + count * sizeof(caddr_t));
 
-  if (br == NULL) {
+  if (r == NULL) {
     uk_pr_err("Could not allocate ring: out of memory\n");
     return NULL;
   }
 
 #ifdef DEBUG_BUFRING
-  br->br_lock = lock;
+  r->lock = lock;
 #endif
 
-  br->br_prod_size = br->br_cons_size = count;
-  br->br_prod_mask = br->br_cons_mask = count - 1;
-  br->br_prod_head = br->br_cons_head = 0;
-  br->br_prod_tail = br->br_cons_tail = 0;
+  r->prod_size = r->cons_size = count;
+  r->prod_mask = r->cons_mask = count - 1;
+  r->prod_head = r->cons_head = 0;
+  r->prod_tail = r->cons_tail = 0;
 
-  return br;
+  return r;
 }
 
 void
 uk_ring_free(struct uk_alloc *a, struct uk_ring *r)
 {
-  uk_free(a, br);
+  uk_free(a, r);
 }
\ No newline at end of file
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 15:40:53 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 15:40:53 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxuNx-0002Pt-E2; Tue, 21 Jul 2020 15:40:53 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=HxHN=BA=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxuNv-0002PZ-Pr
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 15:40:51 +0000
X-Inumbo-ID: 8daa5b4c-cb68-11ea-8564-bc764e2007e4
Received: from mh-is-1.lancs.ac.uk (unknown [148.88.65.129])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 8daa5b4c-cb68-11ea-8564-bc764e2007e4;
 Tue, 21 Jul 2020 15:40:50 +0000 (UTC)
Received: from mito.neclab.eu ([195.37.70.39] helo=localhost.localdomain)
 by mh-is-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jxuNs-0008vk-65; Tue, 21 Jul 2020 16:40:49 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH,v2,10/15] lib/ukring: Disable use of CPU prefetching
Date: Tue, 21 Jul 2020 17:39:51 +0200
Message-Id: <20200721153956.13555-11-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200721153956.13555-1-a.jung@lancs.ac.uk>
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Alexander Jung <a.jung@lancs.ac.uk>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukring/include/uk/ring.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
index e1a0387..b51a11a 100644
--- a/lib/ukring/include/uk/ring.h
+++ b/lib/ukring/include/uk/ring.h
@@ -177,7 +177,8 @@ static __inline void *
 uk_ring_dequeue_single(struct uk_ring *r)
 {
   uint32_t cons_head, cons_next;
-#ifdef PREFETCH_DEFINED
+  /* TODO: Support CPU prefetchhing. */
+#if 0
   uint32_t cons_next_next;
 #endif
   uint32_t prod_tail;
@@ -219,14 +220,16 @@ uk_ring_dequeue_single(struct uk_ring *r)
   prod_tail = &r->prod_tail;
 
   cons_next = (cons_head + 1) & r->cons_mask;
-#ifdef PREFETCH_DEFINED
+  /* TODO: Support CPU prefetchhing. */
+#if 0
   cons_next_next = (cons_head + 2) & r->cons_mask;
 #endif
 
   if (cons_head == prod_tail)
     return NULL;
 
-#ifdef PREFETCH_DEFINED
+  /* TODO: Support CPU prefetchhing. */
+#if 0
   if (cons_next != prod_tail) {
     prefetch(r->ring[cons_next]);
     if (cons_next_next != prod_tail)
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 15:40:54 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 15:40:54 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxuNx-0002Q0-Fa; Tue, 21 Jul 2020 15:40:53 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=HxHN=BA=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxuNv-0002MW-Ve
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 15:40:52 +0000
X-Inumbo-ID: 872f824c-cb68-11ea-a0f8-12813bfff9fa
Received: from mh-is-1.lancs.ac.uk (unknown [148.88.65.129])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 872f824c-cb68-11ea-a0f8-12813bfff9fa;
 Tue, 21 Jul 2020 15:40:39 +0000 (UTC)
Received: from mito.neclab.eu ([195.37.70.39] helo=localhost.localdomain)
 by mh-is-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jxuNh-0008vk-6E; Tue, 21 Jul 2020 16:40:39 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH, v2,
 06/15] lib/ukring: Disable use of cpu_spinwait  function
Date: Tue, 21 Jul 2020 17:39:47 +0200
Message-Id: <20200721153956.13555-7-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200721153956.13555-1-a.jung@lancs.ac.uk>
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Alexander Jung <a.jung@lancs.ac.uk>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This is not currently supported by Unikraft.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukring/include/uk/ring.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
index 26ac2f8..f19b13e 100644
--- a/lib/ukring/include/uk/ring.h
+++ b/lib/ukring/include/uk/ring.h
@@ -111,8 +111,11 @@ uk_ring_enqueue(struct uk_ring *r, void *buf)
    * that preceded us, we need to wait for them
    * to complete 
    */
+   /* TODO: Provide cpu_spinwait() */
+#if 0
   while (r->prod_tail != prod_head)
     cpu_spinwait();
+#endif
 
   ukarch_store_n(&r->prod_tail, prod_next);
   ukplat_lcpu_enable_irq();
@@ -153,8 +156,11 @@ uk_ring_dequeue_mc(struct uk_ring *r)
    * that preceded us, we need to wait for them
    * to complete
    */
+   /* TODO: Provide cpu_spinwait() */
+#if 0
   while (r->cons_tail != cons_head)
     cpu_spinwait();
+#endif
 
   ukarch_store_n(&r->cons_tail, cons_next);
   ukplat_lcpu_enable_irq();
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 15:40:58 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 15:40:58 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxuO2-0002RQ-HM; Tue, 21 Jul 2020 15:40:58 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=HxHN=BA=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxuO0-0002MW-Ub
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 15:40:56 +0000
X-Inumbo-ID: 88b4f3e0-cb68-11ea-a0f8-12813bfff9fa
Received: from mh-is-1.lancs.ac.uk (unknown [148.88.65.129])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 88b4f3e0-cb68-11ea-a0f8-12813bfff9fa;
 Tue, 21 Jul 2020 15:40:42 +0000 (UTC)
Received: from mito.neclab.eu ([195.37.70.39] helo=localhost.localdomain)
 by mh-is-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jxuNk-0008vk-4p; Tue, 21 Jul 2020 16:40:41 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH, v2,
 07/15] lib/ukring: Rename single and multiple  consumer functions
Date: Tue, 21 Jul 2020 17:39:48 +0200
Message-Id: <20200721153956.13555-8-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200721153956.13555-1-a.jung@lancs.ac.uk>
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Alexander Jung <a.jung@lancs.ac.uk>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This commit renames the _sc suffix to _single on functions which
are intended for use by a single bufffer ring consumer.
Additionally, removing the _mc suffix from uk_ring_enqueue to
encourage it as the default operation for removing items from
a ring buffer.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukring/include/uk/ring.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
index f19b13e..1cc8982 100644
--- a/lib/ukring/include/uk/ring.h
+++ b/lib/ukring/include/uk/ring.h
@@ -128,7 +128,7 @@ uk_ring_enqueue(struct uk_ring *r, void *buf)
  *
  */
 static __inline void *
-uk_ring_dequeue_mc(struct uk_ring *r)
+uk_ring_dequeue(struct uk_ring *r)
 {
   uint32_t cons_head, cons_next;
   void *buf;
@@ -174,7 +174,7 @@ uk_ring_dequeue_mc(struct uk_ring *r)
  * e.g. a network driver's tx queue lock
  */
 static __inline void *
-uk_ring_dequeue_sc(struct uk_ring *r)
+uk_ring_dequeue_single(struct uk_ring *r)
 {
   uint32_t cons_head, cons_next;
 #ifdef PREFETCH_DEFINED
@@ -192,7 +192,7 @@ uk_ring_dequeue_sc(struct uk_ring *r)
    *   FreeBSD-12.
    *
    * Preventing following situation:
-   * Core(0) - uk_ring_enqueue()                                       Core(1) - uk_ring_dequeue_sc()
+   * Core(0) - uk_ring_enqueue()                                       Core(1) - uk_ring_dequeue_single()
    * -----------------------------------------                                       ----------------------------------------------
    *
    *                                                                                cons_head = r->cons_head;
@@ -258,7 +258,7 @@ uk_ring_dequeue_sc(struct uk_ring *r)
  * e.g. a network driver's tx queue lock
  */
 static __inline void
-uk_ring_advance_sc(struct uk_ring *r)
+uk_ring_advance_single(struct uk_ring *r)
 {
   uint32_t cons_head, cons_next;
   uint32_t prod_tail;
@@ -296,7 +296,7 @@ uk_ring_advance_sc(struct uk_ring *r)
  * the compare and an atomic.
  */
 static __inline void
-uk_ring_putback_sc(struct uk_ring *r, void *new)
+uk_ring_putback_single(struct uk_ring *r, void *new)
 {
   /* Buffer ring has none in putback */
   UK_ASSERT(r->cons_head != r->prod_tail);
@@ -329,7 +329,7 @@ uk_ring_peek(struct uk_ring *r)
 }
 
 static __inline void *
-uk_ring_peek_clear_sc(struct uk_ring *r)
+uk_ring_peek_clear_single(struct uk_ring *r)
 {
 #ifdef DEBUG_BUFRING
   void *ret;
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 15:40:59 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 15:40:59 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxuO3-0002Rr-JC; Tue, 21 Jul 2020 15:40:59 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=HxHN=BA=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxuO2-0002RL-EG
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 15:40:58 +0000
X-Inumbo-ID: 91a54bc6-cb68-11ea-8564-bc764e2007e4
Received: from mh-is-1.lancs.ac.uk (unknown [148.88.65.129])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 91a54bc6-cb68-11ea-8564-bc764e2007e4;
 Tue, 21 Jul 2020 15:40:57 +0000 (UTC)
Received: from mito.neclab.eu ([195.37.70.39] helo=localhost.localdomain)
 by mh-is-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jxuNz-0008vk-5J; Tue, 21 Jul 2020 16:40:56 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH, v2,
 12/15] lib/ukring: Provide KConfig menu option for microlibrary
Date: Tue, 21 Jul 2020 17:39:53 +0200
Message-Id: <20200721153956.13555-13-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200721153956.13555-1-a.jung@lancs.ac.uk>
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Alexander Jung <a.jung@lancs.ac.uk>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This commit introduces Config.uk.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukring/Config.uk | 7 +++++++
 1 file changed, 7 insertions(+)
 create mode 100644 lib/ukring/Config.uk

diff --git a/lib/ukring/Config.uk b/lib/ukring/Config.uk
new file mode 100644
index 0000000..9d16224
--- /dev/null
+++ b/lib/ukring/Config.uk
@@ -0,0 +1,7 @@
+menuconfig LIBUKRING
+  bool "ukring: Simple ring buffer interface"
+  select LIBUKALLOC
+  select LIBUKLOCK
+  default n
+  help
+    Provide simple ring interface for handling object references.
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 15:41:03 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 15:41:03 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxuO7-0002TH-Ko; Tue, 21 Jul 2020 15:41:03 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=HxHN=BA=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxuO5-0002MW-VF
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 15:41:02 +0000
X-Inumbo-ID: 8a6dab82-cb68-11ea-a0f8-12813bfff9fa
Received: from mh-is-1.lancs.ac.uk (unknown [148.88.65.129])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 8a6dab82-cb68-11ea-a0f8-12813bfff9fa;
 Tue, 21 Jul 2020 15:40:45 +0000 (UTC)
Received: from mito.neclab.eu ([195.37.70.39] helo=localhost.localdomain)
 by mh-is-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jxuNn-0008vk-44; Tue, 21 Jul 2020 16:40:44 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH, v2,
 08/15] lib/ukring: Use Unikraft to enable ring  buffer debugging
Date: Tue, 21 Jul 2020 17:39:49 +0200
Message-Id: <20200721153956.13555-9-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200721153956.13555-1-a.jung@lancs.ac.uk>
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Alexander Jung <a.jung@lancs.ac.uk>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This commit uses the flags set from ukdebug to determine whether
to output critical messages from the ring buffer's debug
sequences.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukring/include/uk/ring.h | 18 +++++++++---------
 lib/ukring/ring.c            |  2 +-
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
index 1cc8982..01adaf3 100644
--- a/lib/ukring/include/uk/ring.h
+++ b/lib/ukring/include/uk/ring.h
@@ -50,7 +50,7 @@ struct uk_ring {
   volatile uint32_t  cons_tail;
   int                cons_size;
   int                cons_mask;
-#ifdef DEBUG_BUFRING
+#ifdef CONFIG_LIBUKDEBUG
   struct uk_mutex   *lock;
 #endif
   void              *ring[0] __aligned(CACHE_LINE_SIZE);
@@ -66,7 +66,7 @@ uk_ring_enqueue(struct uk_ring *r, void *buf)
 {
   uint32_t prod_head, prod_next, cons_tail;
 
-#ifdef DEBUG_BUFRING
+#ifdef CONFIG_LIBUKDEBUG_PRINTK_CRIT
   int i;
 
   /*
@@ -99,7 +99,7 @@ uk_ring_enqueue(struct uk_ring *r, void *buf)
     }
   } while (!ukarch_compare_exchange_sync(&r->prod_head, prod_head, prod_next));
 
-#ifdef DEBUG_BUFRING
+#ifdef CONFIG_LIBUKDEBUG_PRINTK_CRIT
   if (r->ring[prod_head] != NULL)
     uk_pr_crit("dangling value in enqueue\n");
 #endif
@@ -147,7 +147,7 @@ uk_ring_dequeue(struct uk_ring *r)
 
   buf = r->ring[cons_head];
 
-#ifdef DEBUG_BUFRING
+#ifdef CONFIG_LIBUKDEBUG
   r->ring[cons_head] = NULL;
 #endif
 
@@ -237,7 +237,7 @@ uk_ring_dequeue_single(struct uk_ring *r)
   r->cons_head = cons_next;
   buf = r->ring[cons_head];
 
-#ifdef DEBUG_BUFRING
+#ifdef CONFIG_LIBUKDEBUG_PRINTK_CRIT
   r->ring[cons_head] = NULL;
 
   if (!uk_mutex_is_locked(r->lock))
@@ -272,7 +272,7 @@ uk_ring_advance_single(struct uk_ring *r)
 
   r->cons_head = cons_next;
 
-#ifdef DEBUG_BUFRING
+#ifdef CONFIG_LIBUKDEBUG
   r->ring[cons_head] = NULL;
 #endif
 
@@ -311,7 +311,7 @@ uk_ring_putback_single(struct uk_ring *r, void *new)
 static __inline void *
 uk_ring_peek(struct uk_ring *r)
 {
-#ifdef DEBUG_BUFRING
+#ifdef CONFIG_LIBUKDEBUG_PRINTK_CRIT
   if ((r->lock != NULL) && !uk_mutex_is_locked(r->lock))
     uk_pr_crit("lock not held on single consumer dequeue\n");
 #endif
@@ -331,7 +331,7 @@ uk_ring_peek(struct uk_ring *r)
 static __inline void *
 uk_ring_peek_clear_single(struct uk_ring *r)
 {
-#ifdef DEBUG_BUFRING
+#ifdef CONFIG_LIBUKDEBUG_PRINTK_CRIT
   void *ret;
 
   if (!uk_mutex_is_locked(r->lock))
@@ -356,7 +356,7 @@ uk_ring_peek_clear_single(struct uk_ring *r)
   /* atomic_thread_fence_acq(); */
 #endif
 
-#ifdef DEBUG_BUFRING
+#ifdef CONFIG_LIBUKDEBUG
   /*
    * Single consumer, i.e. cons_head will not move while we are
    * running, so atomic_swap_ptr() is not necessary here.
diff --git a/lib/ukring/ring.c b/lib/ukring/ring.c
index 1431cb9..db5600f 100644
--- a/lib/ukring/ring.c
+++ b/lib/ukring/ring.c
@@ -56,7 +56,7 @@ uk_ring_alloc(struct uk_alloc *a, int count, int flags, struct uk_mutex *lock)
     return NULL;
   }
 
-#ifdef DEBUG_BUFRING
+#ifdef CONFIG_LIBUKDEBUG
   r->lock = lock;
 #endif
 
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 15:41:08 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 15:41:08 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxuOC-0002Ul-Mr; Tue, 21 Jul 2020 15:41:08 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=HxHN=BA=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxuOA-0002MW-Vf
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 15:41:07 +0000
X-Inumbo-ID: 8c0cb6c2-cb68-11ea-a0f8-12813bfff9fa
Received: from mh-is-1.lancs.ac.uk (unknown [148.88.65.129])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 8c0cb6c2-cb68-11ea-a0f8-12813bfff9fa;
 Tue, 21 Jul 2020 15:40:48 +0000 (UTC)
Received: from mito.neclab.eu ([195.37.70.39] helo=localhost.localdomain)
 by mh-is-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jxuNq-0008vk-3g; Tue, 21 Jul 2020 16:40:47 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH, v2,
 09/15] lib/ukring: Remove unsupported cache line  size
Date: Tue, 21 Jul 2020 17:39:50 +0200
Message-Id: <20200721153956.13555-10-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200721153956.13555-1-a.jung@lancs.ac.uk>
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Alexander Jung <a.jung@lancs.ac.uk>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukring/include/uk/ring.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
index 01adaf3..e1a0387 100644
--- a/lib/ukring/include/uk/ring.h
+++ b/lib/ukring/include/uk/ring.h
@@ -46,14 +46,14 @@ struct uk_ring {
   int                prod_size;
   int                prod_mask;
   uint64_t           drops;
-  volatile uint32_t  cons_head __aligned(CACHE_LINE_SIZE);
+  volatile uint32_t  cons_head;
   volatile uint32_t  cons_tail;
   int                cons_size;
   int                cons_mask;
 #ifdef CONFIG_LIBUKDEBUG
   struct uk_mutex   *lock;
 #endif
-  void              *ring[0] __aligned(CACHE_LINE_SIZE);
+  void              *ring[0];
 };
 
 
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 15:41:13 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 15:41:13 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxuOH-0002WI-OZ; Tue, 21 Jul 2020 15:41:13 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=HxHN=BA=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxuOF-0002MW-VO
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 15:41:12 +0000
X-Inumbo-ID: 8fdf50ac-cb68-11ea-a0f8-12813bfff9fa
Received: from mh-is-1.lancs.ac.uk (unknown [148.88.65.129])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 8fdf50ac-cb68-11ea-a0f8-12813bfff9fa;
 Tue, 21 Jul 2020 15:40:54 +0000 (UTC)
Received: from mito.neclab.eu ([195.37.70.39] helo=localhost.localdomain)
 by mh-is-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jxuNv-0008vk-57; Tue, 21 Jul 2020 16:40:53 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH, v2, 11/15] lib/ukring: Properly commment {ring.c,
 ring.h}
Date: Tue, 21 Jul 2020 17:39:52 +0200
Message-Id: <20200721153956.13555-12-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200721153956.13555-1-a.jung@lancs.ac.uk>
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Alexander Jung <a.jung@lancs.ac.uk>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This commit updates the SPDX header, adds additional authorship,
and properly comments all functions and inlines.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukring/include/uk/ring.h | 257 +++++++++++++++++++++++------------
 lib/ukring/ring.c            |  19 ++-
 2 files changed, 184 insertions(+), 92 deletions(-)

diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
index b51a11a..49f9dfe 100644
--- a/lib/ukring/include/uk/ring.h
+++ b/lib/ukring/include/uk/ring.h
@@ -1,12 +1,16 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+/* SPDX-License-Identifier: BSD-2-Clause-FreeBSD */
+/*
+ * Authors: Kip Macy <kmacy@freebsd.org>
+ *          Alexander Jung <alexander.jung@neclab.eu>
  *
- * Copyright (c) 2007-2009 Kip Macy <kmacy@freebsd.org>
- * All rights reserved.
+ * Copyright (c) 2007-2009, Kip Macy <kmacy@freebsd.org>
+ *               2020, NEC Laboratories Europe GmbH, NEC Corporation.
+ *               All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
+ *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  * 2. Redistributions in binary form must reproduce the above copyright
@@ -26,7 +30,11 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD$
+ */
+/*
+ * Simple ring implementation to handle object references.
  *
+ * Inspired by FreeBSD and modified (commit-id: c45cce1).
  */
 
 #ifndef __UK_RING_H__
@@ -40,6 +48,7 @@
 #include <uk/plat/lcpu.h>
 #include <uk/arch/atomic.h>
 
+
 struct uk_ring {
   volatile uint32_t  prod_head;
   volatile uint32_t  prod_tail;
@@ -52,14 +61,18 @@ struct uk_ring {
   int                cons_mask;
 #ifdef CONFIG_LIBUKDEBUG
   struct uk_mutex   *lock;
-#endif
+#endif /* CONFIG_LIBUKDEBUG */
   void              *ring[0];
 };
 
 
-/*
- * multi-producer safe lock-free ring buffer enqueue
+/**
+ * Multi-producer safe lock-free ring buffer enqueue.
  *
+ * @param br
+ *  Reference to the ring structure.
+ * @param buf
+ *  Buffer size for the ring.
  */
 static __inline int
 uk_ring_enqueue(struct uk_ring *r, void *buf)
@@ -70,16 +83,15 @@ uk_ring_enqueue(struct uk_ring *r, void *buf)
   int i;
 
   /*
-   * Note: It is possible to encounter an mbuf that was removed
-   * via drpeek(), and then re-added via drputback() and
-   * trigger spurious critical messages.
+   * Note: It is possible to encounter an mbuf that was removed via drpeek(),
+   * and then re-added via drputback() and trigger a spurious panic.
    */
   for (i = r->cons_head; i != r->prod_head;
        i = ((i + 1) & r->cons_mask))
     if (r->ring[i] == buf)
       uk_pr_crit("buf=%p already enqueue at %d prod=%d cons=%d\n",
           buf, i, r->prod_tail, r->cons_tail);
-#endif
+#endif /* CONFIG_LIBUKDEBUG_PRINTK_CRIT */
 
   ukplat_lcpu_disable_irq();
 
@@ -102,20 +114,19 @@ uk_ring_enqueue(struct uk_ring *r, void *buf)
 #ifdef CONFIG_LIBUKDEBUG_PRINTK_CRIT
   if (r->ring[prod_head] != NULL)
     uk_pr_crit("dangling value in enqueue\n");
-#endif
+#endif /* CONFIG_LIBUKDEBUG_PRINTK_CRIT */
 
   r->ring[prod_head] = buf;
 
   /*
-   * If there are other enqueues in progress
-   * that preceded us, we need to wait for them
-   * to complete 
+   * If there are other enqueues in progress that preceded us, we need to wait
+   * for them to complete.
    */
    /* TODO: Provide cpu_spinwait() */
 #if 0
   while (r->prod_tail != prod_head)
     cpu_spinwait();
-#endif
+#endif /* 0 */
 
   ukarch_store_n(&r->prod_tail, prod_next);
   ukplat_lcpu_enable_irq();
@@ -123,9 +134,12 @@ uk_ring_enqueue(struct uk_ring *r, void *buf)
   return 0;
 }
 
-/*
- * multi-consumer safe dequeue 
+
+/**
+ * Multi-consumer safe dequeue.
  *
+ * @param br
+ *  Reference to the ring structure.
  */
 static __inline void *
 uk_ring_dequeue(struct uk_ring *r)
@@ -149,18 +163,17 @@ uk_ring_dequeue(struct uk_ring *r)
 
 #ifdef CONFIG_LIBUKDEBUG
   r->ring[cons_head] = NULL;
-#endif
+#endif /* CONFIG_LIBUKDEBUG */
 
   /*
-   * If there are other dequeues in progress
-   * that preceded us, we need to wait for them
-   * to complete
+   * If there are other dequeues in progress that preceded us, we need to wait
+   * for them to complete.
    */
    /* TODO: Provide cpu_spinwait() */
 #if 0
   while (r->cons_tail != cons_head)
     cpu_spinwait();
-#endif
+#endif /* 0 */
 
   ukarch_store_n(&r->cons_tail, cons_next);
   ukplat_lcpu_enable_irq();
@@ -168,10 +181,13 @@ uk_ring_dequeue(struct uk_ring *r)
   return buf;
 }
 
-/*
- * single-consumer dequeue 
- * use where dequeue is protected by a lock
- * e.g. a network driver's tx queue lock
+
+/**
+ * Single-consumer dequeue use where dequeue is protected by a lock e.g. a
+ * network driver's tx queue lock.
+ *
+ * @param br
+ *  Reference to the ring structure.
  */
 static __inline void *
 uk_ring_dequeue_single(struct uk_ring *r)
@@ -180,41 +196,49 @@ uk_ring_dequeue_single(struct uk_ring *r)
   /* TODO: Support CPU prefetchhing. */
 #if 0
   uint32_t cons_next_next;
-#endif
+#endif /* 0 */
   uint32_t prod_tail;
   void *buf;
 
   /*
    * This is a workaround to allow using uk_ring on ARM and ARM64.
+   *
    * ARM64TODO: Fix uk_ring in a generic way.
+   *
    * REMARKS: It is suspected that cons_head does not require
    *   load_acq operation, but this change was extensively tested
    *   and confirmed it's working. To be reviewed once again in
    *   FreeBSD-12.
    *
    * Preventing following situation:
-   * Core(0) - uk_ring_enqueue()                                       Core(1) - uk_ring_dequeue_single()
-   * -----------------------------------------                                       ----------------------------------------------
    *
-   *                                                                                cons_head = r->cons_head;
-   * atomic_cmpset_acq_32(&r->prod_head, ...));
-   *                                                                                buf = r->ring[cons_head];     <see <1>>
-   * r->ring[prod_head] = buf;
-   * atomic_store_rel_32(&r->prod_tail, ...);
-   *                                                                                prod_tail = r->prod_tail;
-   *                                                                                if (cons_head == prod_tail) 
-   *                                                                                        return (NULL);
-   *                                                                                <condition is false and code uses invalid(old) buf>`  
+   * | uk_ring_enqueue()                         | uk_ring_dequeue_single()    |
+   * |-------------------------------------------+-----------------------------|
+   * |                                           |                             |
+   * |                                           | cons_head = r->cons_head;   |
+   * | atomic_cmpset_acq_32(&r->prod_head, ...); |                             |
+   * |                                           | buf = r->ring[cons_head];<1>|
+   * | r->ring[prod_head] = buf;                 |                             |
+   * | atomic_store_rel_32(&r->prod_tail, ...);  |                             |
+   * |                                           | prod_tail = r->prod_tail;   |
+   * |                                           |                             |
+   * |                                           | if (cons_head == prod_tail) |
+   * |                                           |   return NULL;              |
+   * |                                           |                             |
+   * |                                           | <condition is false and     |
+   * |                                           |  code uses invalid(old)     |
+   * |                                           |  buf>                       |
    *
-   * <1> Load (on core 1) from r->ring[cons_head] can be reordered (speculative readed) by CPU.
-   */
+   * <1> Load (on core 1) from r->ring[cons_head] can be reordered (speculative
+   * readed) by CPU.
+   */  
 #if defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64)
   /* TODO: Provide atomic_load_acq_32() */
   /* cons_head = atomic_load_acq_32(&r->cons_head); */
   cons_head = &r->cons_head;
 #else
   cons_head = r->cons_head;
-#endif
+#endif /* defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64) */
   /* TODO: Provide atomic_load_acq_32() */
   /* prod_tail = atomic_load_acq_32(&r->prod_tail); */
   prod_tail = &r->prod_tail;
@@ -223,7 +247,7 @@ uk_ring_dequeue_single(struct uk_ring *r)
   /* TODO: Support CPU prefetchhing. */
 #if 0
   cons_next_next = (cons_head + 2) & r->cons_mask;
-#endif
+#endif /* 0 */
 
   if (cons_head == prod_tail)
     return NULL;
@@ -235,7 +259,7 @@ uk_ring_dequeue_single(struct uk_ring *r)
     if (cons_next_next != prod_tail)
       prefetch(r->ring[cons_next_next]);
   }
-#endif
+#endif /* 0 */
 
   r->cons_head = cons_next;
   buf = r->ring[cons_head];
@@ -249,16 +273,19 @@ uk_ring_dequeue_single(struct uk_ring *r)
   if (r->cons_tail != cons_head)
     uk_pr_crit("inconsistent list cons_tail=%d cons_head=%d\n",
         r->cons_tail, cons_head);
-#endif
+#endif /* CONFIG_LIBUKDEBUG_PRINTK_CRIT */
 
   r->cons_tail = cons_next;
   return buf;
 }
 
-/*
- * single-consumer advance after a peek
- * use where it is protected by a lock
- * e.g. a network driver's tx queue lock
+
+/**
+ * Single-consumer advance after a peek use where it is protected by a lock e.g.
+ * a network driver's tx queue lock.
+ *
+ * @param br
+ *  Reference to the ring structure.
  */
 static __inline void
 uk_ring_advance_single(struct uk_ring *r)
@@ -277,26 +304,27 @@ uk_ring_advance_single(struct uk_ring *r)
 
 #ifdef CONFIG_LIBUKDEBUG
   r->ring[cons_head] = NULL;
-#endif
+#endif /* CONFIG_LIBUKDEBUG */
 
   r->cons_tail = cons_next;
 }
 
-/*
- * Used to return a buffer (most likely already there)
- * to the top of the ring. The caller should *not*
- * have used any dequeue to pull it out of the ring
- * but instead should have used the peek() function.
- * This is normally used where the transmit queue
- * of a driver is full, and an mbuf must be returned.
- * Most likely whats in the ring-buffer is what
- * is being put back (since it was not removed), but
- * sometimes the lower transmit function may have
- * done a pullup or other function that will have
- * changed it. As an optimization we always put it
- * back (since jhb says the store is probably cheaper),
- * if we have to do a multi-queue version we will need
- * the compare and an atomic.
+
+/**
+ * Used to return a buffer (most likely already there) to the top of the ring.
+ * The caller should *not* have used any dequeue to pull it out of the ring but
+ * instead should have used the peek() function.  This is normally used where
+ * the transmit queue of a driver is full, and an mbuf must be returned.  Most
+ * likely whats in the ring-buffer is what is being put back (since it was not
+ * removed), but sometimes the lower transmit function may have done a pullup or
+ * other function that will have changed it. As an optimization we always put it
+ * back (since jhb says the store is probably cheaper), if we have to do a
+ * multi-queue version we will need the compare and an atomic.
+ *
+ * @param br
+ *  Reference to the ring structure.
+ * @param new
+ *  The item to be pushed back into the ring.
  */
 static __inline void
 uk_ring_putback_single(struct uk_ring *r, void *new)
@@ -306,10 +334,13 @@ uk_ring_putback_single(struct uk_ring *r, void *new)
   r->ring[r->cons_head] = new;
 }
 
-/*
- * return a pointer to the first entry in the ring
- * without modifying it, or NULL if the ring is empty
- * race-prone if not protected by a lock
+
+/**
+ * Return a pointer to the first entry in the ring without modifying it, or NULL
+ * if the ring is empty race-prone if not protected by a lock.
+ *
+ * @param br
+ *  Reference to the ring structure.
  */
 static __inline void *
 uk_ring_peek(struct uk_ring *r)
@@ -317,13 +348,12 @@ uk_ring_peek(struct uk_ring *r)
 #ifdef CONFIG_LIBUKDEBUG_PRINTK_CRIT
   if ((r->lock != NULL) && !uk_mutex_is_locked(r->lock))
     uk_pr_crit("lock not held on single consumer dequeue\n");
-#endif
+#endif /* CONFIG_LIBUKDEBUG_PRINTK_CRIT */
 
   /*
-   * I believe it is safe to not have a memory barrier
-   * here because we control cons and tail is worst case
-   * a lagging indicator so we worst case we might
-   * return NULL immediately after a buffer has been enqueued
+   * It is safe to not have a memory barrier here because we control cons and
+   * tail is worst case a lagging indicator so we worst case we might return
+   * NULL immediately after a buffer has been enqueued.
    */
   if (r->cons_head == r->prod_tail)
     return NULL;
@@ -331,6 +361,14 @@ uk_ring_peek(struct uk_ring *r)
   return r->ring[r->cons_head];
 }
 
+
+/**
+ * Single-consumer clear the pointer to the first entry of the ring, or NULL if
+ * the ring is empty.
+ *
+ * @param br
+ *  Reference to the ring structure.
+ */
 static __inline void *
 uk_ring_peek_clear_single(struct uk_ring *r)
 {
@@ -339,7 +377,7 @@ uk_ring_peek_clear_single(struct uk_ring *r)
 
   if (!uk_mutex_is_locked(r->lock))
     uk_pr_crit("lock not held on single consumer dequeue\n");
-#endif
+#endif /* CONFIG_LIBUKDEBUG_PRINTK_CRIT */
 
   if (r->cons_head == r->prod_tail)
     return NULL;
@@ -347,17 +385,15 @@ uk_ring_peek_clear_single(struct uk_ring *r)
 #if defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64)
   /*
    * The barrier is required there on ARM and ARM64 to ensure, that
-   * r->ring[r->cons_head] will not be fetched before the above
-   * condition is checked.
-   * Without the barrier, it is possible, that buffer will be fetched
-   * before the enqueue will put mbuf into r, then, in the meantime, the
-   * enqueue will update the array and the prod_tail, and the
-   * conditional check will be true, so we will return previously fetched
-   * (and invalid) buffer.
+   * br->ring[br->cons_head] will not be fetched before the above condition is
+   * checked.  Without the barrier, it is possible, that buffer will be fetched
+   * before the enqueue will put mbuf into br, then, in the meantime, the
+   * enqueue will update the array and the prod_tail, and the conditional check
+   * will be true, so we will return previously fetched (and invalid) buffer.
    */
   /* TODO: Provide atomic_thread_fence_acq(); */
   /* atomic_thread_fence_acq(); */
-#endif
+#endif /* defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64) */
 
 #ifdef CONFIG_LIBUKDEBUG
   /*
@@ -370,21 +406,42 @@ uk_ring_peek_clear_single(struct uk_ring *r)
   return ret;
 #else
   return r->ring[r->cons_head];
-#endif
+#endif /* CONFIG_LIBUKDEBUG */
 }
 
+
+/**
+ * Return whether the ring buffer is full.
+ *
+ * @param br
+ *  Reference to the ring structure.
+ */
 static __inline int
 uk_ring_full(struct uk_ring *r)
 {
   return ((r->prod_head + 1) & r->prod_mask) == r->cons_tail;
 }
 
+
+/**
+ * Return whether the ring buffer is empty.
+ *
+ * @param br
+ *  Reference to the ring structure.
+ */
 static __inline int
 uk_ring_empty(struct uk_ring *r)
 {
   return r->cons_head == r->prod_tail;
 }
 
+
+/**
+ * Return the queue size in the ring buffer.
+ *
+ * @param br
+ *  Reference to the ring structure.
+ */
 static __inline int
 uk_ring_count(struct uk_ring *r)
 {
@@ -392,8 +449,32 @@ uk_ring_count(struct uk_ring *r)
       & r->prod_mask;
 }
 
-struct uk_ring *uk_ring_alloc(struct uk_alloc *a, int count, int flags,
-    struct uk_mutex *);
-void uk_ring_free(struct uk_alloc *a, struct uk_ring *r);
 
-#endif
\ No newline at end of file
+/**
+ * Create a new ring buffer.
+ *
+ * @param count
+ *  The size of the ring buffer.
+ * @param a
+ *  The memory allocator to use when creating the ring buffer.
+ * @param flags
+ *  Additional flags to specify to the ring.
+ * @param lock
+ *  The mutex to use when debugging the ring buffer.
+ */
+struct uk_ring *
+uk_ring_alloc(struct uk_alloc *a, int count, int flags, struct uk_mutex *lock);
+
+
+/**
+ * Free the ring from use.
+ *
+ * @param br
+ *  Reference to the ring structure.
+ * @param a
+ *  The memory allocator to use when freeing the object.
+ */
+void
+uk_ring_free(struct uk_alloc *a, struct uk_ring *r);
+
+#endif /* __UK_RING_H__ */
diff --git a/lib/ukring/ring.c b/lib/ukring/ring.c
index db5600f..0523648 100644
--- a/lib/ukring/ring.c
+++ b/lib/ukring/ring.c
@@ -1,12 +1,16 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+/* SPDX-License-Identifier: BSD-2-Clause-FreeBSD */
+/*
+ * Authors: Kip Macy <kmacy@freebsd.org>
+ *          Alexander Jung <alexander.jung@neclab.eu>
  *
- * Copyright (c) 2007, 2008 Kip Macy <kmacy@freebsd.org>
- * All rights reserved.
+ * Copyright (c) 2007-2009, Kip Macy <kmacy@freebsd.org>
+ *               2020, NEC Laboratories Europe GmbH, NEC Corporation.
+ *               All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
+ *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  * 2. Redistributions in binary form must reproduce the above copyright
@@ -24,6 +28,13 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+/*
+ * Simple ring implementation to handle object references.
+ *
+ * Inspired by FreeBSD and modified (commit-id: c45cce1).
  */
 
 #include <sys/param.h>
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 15:41:18 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 15:41:18 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxuOM-0002XQ-RS; Tue, 21 Jul 2020 15:41:18 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=HxHN=BA=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxuOK-0002MW-VX
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 15:41:17 +0000
X-Inumbo-ID: 930a7037-cb68-11ea-a0f8-12813bfff9fa
Received: from mh-is-1.lancs.ac.uk (unknown [148.88.65.129])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 930a7037-cb68-11ea-a0f8-12813bfff9fa;
 Tue, 21 Jul 2020 15:41:00 +0000 (UTC)
Received: from mito.neclab.eu ([195.37.70.39] helo=localhost.localdomain)
 by mh-is-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jxuO2-0008vk-3z; Tue, 21 Jul 2020 16:40:59 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH, v2,
 13/15] lib/ukring: Target files to build for the microlibrary
Date: Tue, 21 Jul 2020 17:39:54 +0200
Message-Id: <20200721153956.13555-14-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200721153956.13555-1-a.jung@lancs.ac.uk>
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Alexander Jung <a.jung@lancs.ac.uk>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This commit introduces Makefile.uk which points to the ported
files ring.c and the header, ring.h, now available at uk/ring.h

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukring/Makefile.uk | 6 ++++++
 1 file changed, 6 insertions(+)
 create mode 100644 lib/ukring/Makefile.uk

diff --git a/lib/ukring/Makefile.uk b/lib/ukring/Makefile.uk
new file mode 100644
index 0000000..b1530dd
--- /dev/null
+++ b/lib/ukring/Makefile.uk
@@ -0,0 +1,6 @@
+$(eval $(call addlib_s,libukring,$(CONFIG_LIBUKRING)))
+
+CINCLUDES-$(CONFIG_LIBUKRING)		+= -I$(LIBUKRING_BASE)/include
+CXXINCLUDES-$(CONFIG_LIBUKRING)	+= -I$(LIBUKRING_BASE)/include
+
+LIBUKRING_SRCS-y += $(LIBUKRING_BASE)/ring.c
\ No newline at end of file
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 15:41:24 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 15:41:24 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxuOR-0002YY-TF; Tue, 21 Jul 2020 15:41:23 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=HxHN=BA=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxuOQ-0002MW-0F
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 15:41:22 +0000
X-Inumbo-ID: 94e8d316-cb68-11ea-a0f8-12813bfff9fa
Received: from mh-is-1.lancs.ac.uk (unknown [148.88.65.129])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 94e8d316-cb68-11ea-a0f8-12813bfff9fa;
 Tue, 21 Jul 2020 15:41:02 +0000 (UTC)
Received: from mito.neclab.eu ([195.37.70.39] helo=localhost.localdomain)
 by mh-is-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jxuO4-0008vk-64; Tue, 21 Jul 2020 16:41:02 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH,v2,14/15] lib/ukring: Register ukring with Unikraft
Date: Tue, 21 Jul 2020 17:39:55 +0200
Message-Id: <20200721153956.13555-15-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200721153956.13555-1-a.jung@lancs.ac.uk>
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Alexander Jung <a.jung@lancs.ac.uk>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This commit registers the simple ring buffer implementation micro-
library with Unikraft by including it in the globa library list
and exports the ring buffer's main functions.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/Makefile.uk          |  1 +
 lib/ukring/exportsyms.uk | 12 ++++++++++++
 2 files changed, 13 insertions(+)
 create mode 100644 lib/ukring/exportsyms.uk

diff --git a/lib/Makefile.uk b/lib/Makefile.uk
index 360fcd8..4fd222d 100644
--- a/lib/Makefile.uk
+++ b/lib/Makefile.uk
@@ -25,6 +25,7 @@ $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/devfs))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/9pfs))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uklock))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukmpi))
+$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukring))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukbus))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uksglist))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uknetdev))
diff --git a/lib/ukring/exportsyms.uk b/lib/ukring/exportsyms.uk
new file mode 100644
index 0000000..7561724
--- /dev/null
+++ b/lib/ukring/exportsyms.uk
@@ -0,0 +1,12 @@
+uk_ring_alloc
+uk_ring_free
+uk_ring_enqueue
+uk_ring_dequeue
+uk_ring_dequeue_single
+uk_ring_advance_single
+uk_ring_putback_single
+uk_ring_peek
+uk_ring_peek_clear_single
+uk_ring_full
+uk_ring_empty
+uk_ring_count
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 15:46:27 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 15:46:27 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxuTJ-0002ey-AR; Tue, 21 Jul 2020 15:46:25 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=yM2V=BA=lancaster.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxuTH-0002et-GR
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 15:46:23 +0000
X-Inumbo-ID: 531e1ee0-cb69-11ea-a0fa-12813bfff9fa
Received: from GBR01-CWL-obe.outbound.protection.outlook.com (unknown
 [40.107.11.118]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 531e1ee0-cb69-11ea-a0fa-12813bfff9fa;
 Tue, 21 Jul 2020 15:46:22 +0000 (UTC)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=dfizevHMFFScCdOXJvQkDEhw4jkAOLDsqi4SehBeiYjsSF1djLa+RWswuwNseVfgxlbsCtougHdIZ580N4ZnW67jikSOwdQQ/twX6hQmq3UFJPt0evgCqTJyAP2UuJI1ebz6icvO13f9MNU1xaBjdiHz7uQynGmve0jIC00AbGfiPBRrk0QxKzWRiMcjo3eVt3D/H903nMDHKOPnhwlPMZR0+ZUvAUqlzsv0Cf7AJRPvlsQWh56noaUBP3/Sr4BNC9biihg3KC1ptzv7QFKsx7s9vqIS6/r0r4mD2JrUVmXocHdLq8qdr1Ik4jb08d5Niktt8yNygTTWahx3OzgOHQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; 
 s=arcselector9901;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=YVxjaIzgcvkf3ZVScOnXew00kw/WWD2I390zQb2vbKg=;
 b=NdLUK3IXavRjhI+bJBUlMIql+Wo6m84xMiZC0MPHlXW5V6x8RivT1cZ2QHc8n2KVuai749Qm3EBL73h1IW2w210E4Ei57YC8646SdVDzBEf5jjZmBF+CnxpW5QC9g+e0aEcw3UQOIt0J4dwhcNiyLtshflD6NdV/SGBdyb8BATSLW3MQmT5ofS9PBxPecD5EvHOLKI/tHk1Pzt0dgag88+9/NENv1iUIPiquWXsW8Vs5uSe3iFk6/8TrmfDRzcsP3y9Dr7LYX2EJO0DzcLT2MaYCZwrNcZSAVjClRK5N9hAZm6hWASc8uYlBfU6NtNioKPpPoSltJ+kWA3MOKwgA6A==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
 smtp.mailfrom=lancaster.ac.uk; dmarc=pass action=none
 header.from=lancaster.ac.uk; dkim=pass header.d=lancaster.ac.uk; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=livelancsac.onmicrosoft.com; s=selector2-livelancsac-onmicrosoft-com;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=YVxjaIzgcvkf3ZVScOnXew00kw/WWD2I390zQb2vbKg=;
 b=AI5F26SSKgzIwAsmwGWQJwMLv9aOnPDhFBuAnfDKGrtViSX/0bnPqWP9SSn+Q2MBhxoUbMf9LB5cVUGwG6U5BTC7YMA0NnlmIB2/rInDbL9NT9UqrcEn/m8zqL526ICA9nT2Zhx8bRVxTVvl8WJewowX+ghUGz+m+jOJUGuH3gE=
Received: from CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM (2603:10a6:401:17::15)
 by CWLP265MB2196.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:68::13) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.23; Tue, 21 Jul
 2020 15:46:20 +0000
Received: from CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM
 ([fe80::fcde:79b:21d6:5203]) by CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM
 ([fe80::fcde:79b:21d6:5203%4]) with mapi id 15.20.3195.026; Tue, 21 Jul 2020
 15:46:20 +0000
From: "Jung, Alexander" <a.jung@lancaster.ac.uk>
To: Alexander Jung <a.jung@lancs.ac.uk>, "minios-devel@lists.xen.org"
 <minios-devel@lists.xen.org>
Subject: Re: [External] [UNIKRAFT PATCH,v2,00/15] Introduce Ring Buffer
 Implementation
Thread-Topic: [External] [UNIKRAFT PATCH,v2,00/15] Introduce Ring Buffer
 Implementation
Thread-Index: AQHWX3U9zqa2fxD4wU2Y5wd0/nzOSKkSTsQA
Date: Tue, 21 Jul 2020 15:46:20 +0000
Message-ID: <3C2B79F0-F0AD-4E53-B280-7A1F737AC2D1@lancaster.ac.uk>
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
In-Reply-To: <20200721153956.13555-1-a.jung@lancs.ac.uk>
Accept-Language: en-GB, en-US
Content-Language: en-GB
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
user-agent: Microsoft-MacOutlook/16.38.20061401
authentication-results: lancs.ac.uk; dkim=none (message not signed)
 header.d=none;lancs.ac.uk; dmarc=none action=none
 header.from=lancaster.ac.uk;
x-originating-ip: [195.37.70.39]
x-ms-publictraffictype: Email
x-ms-office365-filtering-correlation-id: 3c2913fd-c42f-463e-7810-08d82d8d36cb
x-ms-traffictypediagnostic: CWLP265MB2196:
x-microsoft-antispam-prvs: <CWLP265MB2196608A039701E5FCF97F84CE780@CWLP265MB2196.GBRP265.PROD.OUTLOOK.COM>
x-ms-oob-tlc-oobclassifiers: OLM:8882;
x-ms-exchange-senderadcheck: 1
x-microsoft-antispam: BCL:0;
x-microsoft-antispam-message-info: CLnX/7a2ChovcyRwCUd9YfOKMYYtROeZjektIgaFm/lhxxrNe4KHsjmoOq+pN0G1t64hiun19Rre9qyqTfLHnfmCESdsw+kiEzMBY8oPtoL5vTPteffLpD00QfrraZKT0kGaPOYj7KcV3HFFrkR0xM+RfpEYygkHHAdhxH0Zfo+5O+alEOFinfhX6TnjfbY73zl3YCUw2rAPu83Dl45/djVE+GrWS/sBRYu7f4do9BlYdYMK3fDoMuTtGJ0h2qiRw8//tDtoVxSn4ysKoIby5jnyC0Crg8bsZIsgK3x4DCq7fk5h3OzIW7PB+YKtVtrGZMGw1TgrhTsst4p2c05Bu0u4uFXiI2Md8anHJaLVgRUjqq7DvPGp94+xPMgonsv9
x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
 IPV:NLI; SFV:NSPM; H:CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM; PTR:; CAT:NONE;
 SFTY:;
 SFS:(4636009)(396003)(376002)(39860400002)(366004)(346002)(136003)(5660300002)(6506007)(2906002)(26005)(186003)(8936002)(54906003)(36756003)(786003)(316002)(4326008)(33656002)(110136005)(91956017)(66446008)(86362001)(66946007)(6486002)(478600001)(6512007)(66476007)(71200400001)(64756008)(2616005)(8676002)(83380400001)(66556008)(76116006)(142933001);
 DIR:OUT; SFP:1102; 
x-ms-exchange-antispam-messagedata: TduyQEAwqTNFBQP/bWNNaf05lBQy/in/S25qdW9eMkbc2mmz4Hraw/2m+P+6BNoWefIfdZDxi9UbW/vs1+BwfST14v6QMjqn8USRHmPMlHG8LMrjl5SqImMhuCcW3fI2Myo0p4lMUTstsJooxBF7cRMSFbgvk/lJL9+Qwf2/b1c80wZXPDUhjIqi+iwdefWdux9MYKKSoSSgSfDqj8nsLnqcVxMLl46X3bji7wnDdjBYa1ntpnZQVTE3aSD2RbpnkNtMB1cl8EnyAZ8PZF7JQ2+Ko0LJIW0bIWL1S7vFHJwwfek4QnDbbiw6NUE2DlxP/v7uUwsLBhJfpl7d9suu6MrzRs4ls/kMQbysYKfSgB+phxPGAAAMVrHA5vIyxvB70FB8gg0QHRBzXupzpG93mlQjCAQ80nQ1Jlmkhi7cwsm+wwk3tYjcNI90FgPF2nWBfbqhWA1I+r6ylwavVS1wlBUCZdR0MmJDX2DL+StNP2A=
x-ms-exchange-transport-forked: True
Content-Type: text/plain; charset="utf-8"
Content-ID: <40C46A4264C7AA48B062B9B76EFB1AA2@GBRP265.PROD.OUTLOOK.COM>
Content-Transfer-Encoding: base64
MIME-Version: 1.0
X-OriginatorOrg: lancaster.ac.uk
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM
X-MS-Exchange-CrossTenant-Network-Message-Id: 3c2913fd-c42f-463e-7810-08d82d8d36cb
X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Jul 2020 15:46:20.4538 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 9c9bcd11-977a-4e9c-a9a0-bc734090164a
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: ILHsjlxNYFQqfcX4G7pYT+JIK4lolLw/qbo4dsYYUQ2k+uYyq1FteJa3iLwBtTGMZZJIg4rkzVfSw+LaBO/ygg==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWLP265MB2196
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

SSd2ZSB1c2VkIHRoZSBvbGQgY292ZXIgbGV0dGVyIGZvciB0aGlzIHBhdGNoIHNlcmllcy4NCg0K
VmVyc2lvbiAyIGNoYW5nZXMgYXJlIGFzIGZvbGxvd3M6DQoNCiAqIE1vcmUgZmluZS1ncmFpbiBn
aXQgY29tbWl0czsNCiAqIE1vdmVkIHRoZSByaW5nIGJ1ZmZlciBpbXBsZW1lbnRhdGlvbiBvdXQg
b2YgdWttcGkgYW5kIGludG8gaXRzIG93bg0KICAgbGlicmFyeSwgdWtyaW5nOw0KICogVXNlIHVr
ZGVidWcgdG8gZGV0ZXJtaW5lIHdoZXRoZXIgdG8gdXNlIHRoZSBpbXBsZW1lbnRhdGlvbidzDQog
ICBpbnRlcm5hbCBkZWJ1Z2dpbmcgbWVjaGFuaWNzOyBhbmQsDQogKiBDb3JyZWN0bHkgcHJvdmlk
ZSB2YXJpYWJsZXMgaW4gYHVrX3JpbmdfcGVla19jbGVhcl9zaW5nbGVgLg0KDQrvu79PbiAyMS4w
Ny4yMCwgMTc6NDAsICJBbGV4YW5kZXIgSnVuZyIgPGEuanVuZ0BsYW5jcy5hYy51az4gd3JvdGU6
DQoNCiAgICBUaGlzIGVtYWlsIG9yaWdpbmF0ZWQgb3V0c2lkZSB0aGUgVW5pdmVyc2l0eS4gQ2hl
Y2sgYmVmb3JlIGNsaWNraW5nIGxpbmtzIG9yIGF0dGFjaG1lbnRzLg0KDQogICAgVGhpcyBzZXJp
ZXMgaW50cm9kdWNlcyBhIHBvcnQgb2YgRnJlZUJTRCdzIGJ1Zl9yaW5nLntoLGN9IGltcGxlbWVu
dGF0aW9uIGZvciB1c2UNCiAgICB3aXRoaW4gVW5pa3JhZnQuICBUaGlzIHNpbXBsZSByaW5nIGJ1
ZmZlciBjYW4gYmUgdXNlZCBmb3IgbWVzc2FnZSBwYXNzaW5nIGluDQogICAgcXVldWVzLCBmb3Ig
ZXhhbXBsZSB3aXRoaW4gYSBBRl9VTklYIHNvY2tldCBpbXBsZW1lbnRhdGlvbiBiZXR3ZWVuIHR3
bw0KICAgIHRocmVhZHMuICBUaGUgaW1wbGVtZW50YXRpb24gaXMgdGhlcmVmb3JlIHRocmVhZCBz
YWZlIGFuZCBwcm92aWRlcyBhIGdlbmVyaWMNCiAgICBkYXRhIGZpZWxkIHdoaWNoIGlzIGluaXRp
YWxpemVkIHRvIHRoZSBkZXNpcmVkIHJpbmcgYnVmZmVyIGxlbmd0aC4NCg0KICAgIFRoZSBpbXBs
ZW1lbnRhdGlvbiBpcyBwcm92aWRlZCB3aXRoaW4gdWttcGkgYXMgYSBuZXcgb3B0aW9uLCBMSUJV
S01QSV9SSU5HLA0KICAgIHdoaWNoIGV4cG9zZXMgdGhlIGZvbGxvd2luZyBuZXcgbWV0aG9kczoN
Cg0KICAgICAtIHVrX3JpbmdfYWxsb2MNCiAgICAgLSB1a19yaW5nX2ZyZWUNCiAgICAgLSB1a19y
aW5nX2VucXVldWUNCiAgICAgLSB1a19yaW5nX2RlcXVldWUNCiAgICAgLSB1a19yaW5nX2RlcXVl
dWVfc2luZ2xlDQogICAgIC0gdWtfcmluZ19hZHZhbmNlX3NpbmdsZQ0KICAgICAtIHVrX3Jpbmdf
cHV0YmFja19zaW5nbGUNCiAgICAgLSB1a19yaW5nX3BlZWsNCiAgICAgLSB1a19yaW5nX3BlZWtf
Y2xlYXJfc2luZ2xlDQogICAgIC0gdWtfcmluZ19mdWxsDQogICAgIC0gdWtfcmluZ19lbXB0eQ0K
ICAgICAtIHVrX3JpbmdfY291bnQNCg0KICAgIFRoZSBwb3J0IGlzIGN1cnJlbnRseSBsaW1pdGVk
LCB3aXRoIG5vIHN1cHBvcnQgZm9yIHJlYWRpbmcgYXRvbWljIHZhbHVlcyBmcm9tDQogICAgQVJN
ezMyLDY0fSBDUFUgcmVnaXN0ZXJzIChkZXNjcmliZWQgaW4gdGhlIGNvbW1lbnRzIGlubGluZSku
ICBBcyBhIHJlc3VsdCwgdXNlDQogICAgb2YgdGhlIHJpbmcgYnVmZmVyIGltcGxlbWVudGF0aW9u
IGlzIHVudGVzdGVkIG9uIEFSTS4NCg0KICAgIEFsZXhhbmRlciBKdW5nICgxNSk6DQogICAgICBs
aWIvdWtyaW5nOiBJbXBvcnQgc2ltcGxlIHJpbmcgYnVmZmVyIGZyb20gRnJlZUJTRA0KICAgICAg
bGliL3VrcmluZzoge3JpbmcuYywgcmluZy5ofSBGaXggY2hlY2twYXRjaCBlcnJvcnMgYW5kIHNw
YWNpbmcuDQogICAgICBsaWIvdWtyaW5nOiBBZGFwdCB7cmluZy5jLCByaW5nLmh9IHRvIFVuaWty
YWZ0DQogICAgICBsaWIvdWtyaW5nOiBSZS1wcmVmaXggbWV0aG9kcyBhbmQgc3RydWN0cyBmcm9t
IGJ1Zl8gdG8gdWtfDQogICAgICBsaWIvdWtyaW5nOiBSZW1vdmUgYnJfIHByZWZpeCBhbmQgcmVu
YW1lIGJyIHZhcmlhYmxlDQogICAgICBsaWIvdWtyaW5nOiBEaXNhYmxlIHVzZSBvZiBjcHVfc3Bp
bndhaXQgZnVuY3Rpb24NCiAgICAgIGxpYi91a3Jpbmc6IFJlbmFtZSBzaW5nbGUgYW5kIG11bHRp
cGxlIGNvbnN1bWVyIGZ1bmN0aW9ucy4NCiAgICAgIGxpYi91a3Jpbmc6IFVzZSBVbmlrcmFmdCB0
byBlbmFibGUgcmluZyBidWZmZXIgZGVidWdnaW5nDQogICAgICBsaWIvdWtyaW5nOiBSZW1vdmUg
dW5zdXBwb3J0ZWQgY2FjaGUgbGluZSBzaXplDQogICAgICBsaWIvdWtyaW5nOiBEaXNhYmxlIHVz
ZSBvZiBDUFUgcHJlZmV0Y2hpbmcNCiAgICAgIGxpYi91a3Jpbmc6IFByb3Blcmx5IGNvbW1tZW50
IHtyaW5nLmMsIHJpbmcuaH0NCiAgICAgIGxpYi91a3Jpbmc6IFByb3ZpZGUgS0NvbmZpZyBtZW51
IG9wdGlvbiBmb3IgbWljcm9saWJyYXJ5DQogICAgICBsaWIvdWtyaW5nOiBUYXJnZXQgZmlsZXMg
dG8gYnVpbGQgZm9yIHRoZSBtaWNyb2xpYnJhcnkNCiAgICAgIGxpYi91a3Jpbmc6IFJlZ2lzdGVy
IHVrcmluZyB3aXRoIFVuaWtyYWZ0DQogICAgICBsaWIvdWtyaW5nOiBGaXggdW5pdGlhbGl6ZWQg
dmFyaWFibGUNCg0KICAgICBsaWIvTWFrZWZpbGUudWsgICAgICAgICAgICAgIHwgICAxICsNCiAg
ICAgbGliL3VrcmluZy9Db25maWcudWsgICAgICAgICB8ICAgNyArDQogICAgIGxpYi91a3Jpbmcv
TWFrZWZpbGUudWsgICAgICAgfCAgIDYgKw0KICAgICBsaWIvdWtyaW5nL2V4cG9ydHN5bXMudWsg
ICAgIHwgIDEyICsNCiAgICAgbGliL3VrcmluZy9pbmNsdWRlL3VrL3JpbmcuaCB8IDQ4MiArKysr
KysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKw0KICAgICBsaWIvdWtyaW5nL3JpbmcuYyAg
ICAgICAgICAgIHwgIDg2ICsrKysrKysNCiAgICAgNiBmaWxlcyBjaGFuZ2VkLCA1OTQgaW5zZXJ0
aW9ucygrKQ0KICAgICBjcmVhdGUgbW9kZSAxMDA2NDQgbGliL3VrcmluZy9Db25maWcudWsNCiAg
ICAgY3JlYXRlIG1vZGUgMTAwNjQ0IGxpYi91a3JpbmcvTWFrZWZpbGUudWsNCiAgICAgY3JlYXRl
IG1vZGUgMTAwNjQ0IGxpYi91a3JpbmcvZXhwb3J0c3ltcy51aw0KICAgICBjcmVhdGUgbW9kZSAx
MDA2NDQgbGliL3VrcmluZy9pbmNsdWRlL3VrL3JpbmcuaA0KICAgICBjcmVhdGUgbW9kZSAxMDA2
NDQgbGliL3VrcmluZy9yaW5nLmMNCg0KICAgIC0tDQogICAgMi4yMC4xDQoNCg0K


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 15:51:06 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 15:51:06 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxuXp-0003OR-NT; Tue, 21 Jul 2020 15:51:05 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=HxHN=BA=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jxuOU-0002MW-WD
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 15:41:27 +0000
X-Inumbo-ID: 968c819a-cb68-11ea-a0f8-12813bfff9fa
Received: from mh-is-1.lancs.ac.uk (unknown [148.88.65.129])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 968c819a-cb68-11ea-a0f8-12813bfff9fa;
 Tue, 21 Jul 2020 15:41:05 +0000 (UTC)
Received: from mito.neclab.eu ([195.37.70.39] helo=localhost.localdomain)
 by mh-is-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jxuO7-0008vk-5m; Tue, 21 Jul 2020 16:41:04 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH,v2,15/15] lib/ukring: Fix unitialized variable
Date: Tue, 21 Jul 2020 17:39:56 +0200
Message-Id: <20200721153956.13555-16-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200721153956.13555-1-a.jung@lancs.ac.uk>
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Alexander Jung <a.jung@lancs.ac.uk>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This fix introduces the `ret` variable within the
`uk_ring_peek_clear_single` function when compiled with ukdebug.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukring/include/uk/ring.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
index 49f9dfe..af113b4 100644
--- a/lib/ukring/include/uk/ring.h
+++ b/lib/ukring/include/uk/ring.h
@@ -372,8 +372,10 @@ uk_ring_peek(struct uk_ring *r)
 static __inline void *
 uk_ring_peek_clear_single(struct uk_ring *r)
 {
-#ifdef CONFIG_LIBUKDEBUG_PRINTK_CRIT
+#ifdef CONFIG_LIBUKDEBUG
   void *ret;
+#endif /* CONFIG_LIBUKDEBUG */
+#ifdef CONFIG_LIBUKDEBUG_PRINTK_CRIT
 
   if (!uk_mutex_is_locked(r->lock))
     uk_pr_crit("lock not held on single consumer dequeue\n");
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 21 17:02:54 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 17:02:54 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxvfG-0001c0-Go; Tue, 21 Jul 2020 17:02:50 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=NVI3=BA=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jxvfF-0001bv-12
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 17:02:49 +0000
X-Inumbo-ID: ff6fa2e0-cb73-11ea-857b-bc764e2007e4
Received: from mx.upb.ro (unknown [141.85.13.200])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id ff6fa2e0-cb73-11ea-857b-bc764e2007e4;
 Tue, 21 Jul 2020 17:02:46 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 2DD07B561CED;
 Tue, 21 Jul 2020 20:02:45 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id clYW8vsamZHi; Tue, 21 Jul 2020 20:02:40 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id D0654B561CCE;
 Tue, 21 Jul 2020 20:02:40 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id sD2jV8chqCQ8; Tue, 21 Jul 2020 20:02:40 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id 3E13FB561CBF;
 Tue, 21 Jul 2020 20:02:40 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH, v2, 01/15] lib/ukring: Import simple ring buffer
 from FreeBSD
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
 <20200721153956.13555-2-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <49a6b440-f581-4edc-cb1a-25a0a131919d@cs.pub.ro>
Date: Tue, 21 Jul 2020 20:02:40 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200721153956.13555-2-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

I keep seeing "simple" ring buffer (it's also in the Kconfig help
message). It doesn't look simple to me. :-)

I think we can get rid of "simple" from the subject. Other than that,

Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>

On 7/21/20 6:39 PM, Alexander Jung wrote:
> Copied as it is from the official FreeBSD git mirror.
> 
> Commit: c45cce178ce658f81901a45c741b7f3c47ce2250
> 
> - https://github.com/freebsd/freebsd/blob/c45cce1/sys/sys/buf_ring.h
> - https://github.com/freebsd/freebsd/blob/c45cce1/sys/kern/subr_bufring.c
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/ukring/include/uk/ring.h | 371 +++++++++++++++++++++++++++++++++++
>  lib/ukring/ring.c            |  65 ++++++
>  2 files changed, 436 insertions(+)
>  create mode 100644 lib/ukring/include/uk/ring.h
>  create mode 100644 lib/ukring/ring.c
> 
> diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
> new file mode 100644
> index 0000000..899563c
> --- /dev/null
> +++ b/lib/ukring/include/uk/ring.h
> @@ -0,0 +1,371 @@
> +/*-
> + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
> + *
> + * Copyright (c) 2007-2009 Kip Macy <kmacy@freebsd.org>
> + * All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in the
> + *    documentation and/or other materials provided with the distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> + * SUCH DAMAGE.
> + *
> + * $FreeBSD$
> + *
> + */
> +
> +#ifndef	_SYS_BUF_RING_H_
> +#define	_SYS_BUF_RING_H_
> +
> +#include <machine/cpu.h>
> +
> +#ifdef DEBUG_BUFRING
> +#include <sys/lock.h>
> +#include <sys/mutex.h>
> +#endif
> +
> +struct buf_ring {
> +	volatile uint32_t	br_prod_head;
> +	volatile uint32_t	br_prod_tail;	
> +	int              	br_prod_size;
> +	int              	br_prod_mask;
> +	uint64_t		br_drops;
> +	volatile uint32_t	br_cons_head __aligned(CACHE_LINE_SIZE);
> +	volatile uint32_t	br_cons_tail;
> +	int		 	br_cons_size;
> +	int              	br_cons_mask;
> +#ifdef DEBUG_BUFRING
> +	struct mtx		*br_lock;
> +#endif	
> +	void			*br_ring[0] __aligned(CACHE_LINE_SIZE);
> +};
> +
> +/*
> + * multi-producer safe lock-free ring buffer enqueue
> + *
> + */
> +static __inline int
> +buf_ring_enqueue(struct buf_ring *br, void *buf)
> +{
> +	uint32_t prod_head, prod_next, cons_tail;
> +#ifdef DEBUG_BUFRING
> +	int i;
> +
> +	/*
> +	 * Note: It is possible to encounter an mbuf that was removed
> +	 * via drbr_peek(), and then re-added via drbr_putback() and
> +	 * trigger a spurious panic.
> +	 */
> +	for (i = br->br_cons_head; i != br->br_prod_head;
> +	     i = ((i + 1) & br->br_cons_mask))
> +		if(br->br_ring[i] == buf)
> +			panic("buf=%p already enqueue at %d prod=%d cons=%d",
> +			    buf, i, br->br_prod_tail, br->br_cons_tail);
> +#endif	
> +	critical_enter();
> +	do {
> +		prod_head = br->br_prod_head;
> +		prod_next = (prod_head + 1) & br->br_prod_mask;
> +		cons_tail = br->br_cons_tail;
> +
> +		if (prod_next == cons_tail) {
> +			rmb();
> +			if (prod_head == br->br_prod_head &&
> +			    cons_tail == br->br_cons_tail) {
> +				br->br_drops++;
> +				critical_exit();
> +				return (ENOBUFS);
> +			}
> +			continue;
> +		}
> +	} while (!atomic_cmpset_acq_int(&br->br_prod_head, prod_head, prod_next));
> +#ifdef DEBUG_BUFRING
> +	if (br->br_ring[prod_head] != NULL)
> +		panic("dangling value in enqueue");
> +#endif	
> +	br->br_ring[prod_head] = buf;
> +
> +	/*
> +	 * If there are other enqueues in progress
> +	 * that preceded us, we need to wait for them
> +	 * to complete 
> +	 */   
> +	while (br->br_prod_tail != prod_head)
> +		cpu_spinwait();
> +	atomic_store_rel_int(&br->br_prod_tail, prod_next);
> +	critical_exit();
> +	return (0);
> +}
> +
> +/*
> + * multi-consumer safe dequeue 
> + *
> + */
> +static __inline void *
> +buf_ring_dequeue_mc(struct buf_ring *br)
> +{
> +	uint32_t cons_head, cons_next;
> +	void *buf;
> +
> +	critical_enter();
> +	do {
> +		cons_head = br->br_cons_head;
> +		cons_next = (cons_head + 1) & br->br_cons_mask;
> +
> +		if (cons_head == br->br_prod_tail) {
> +			critical_exit();
> +			return (NULL);
> +		}
> +	} while (!atomic_cmpset_acq_int(&br->br_cons_head, cons_head, cons_next));
> +
> +	buf = br->br_ring[cons_head];
> +#ifdef DEBUG_BUFRING
> +	br->br_ring[cons_head] = NULL;
> +#endif
> +	/*
> +	 * If there are other dequeues in progress
> +	 * that preceded us, we need to wait for them
> +	 * to complete 
> +	 */   
> +	while (br->br_cons_tail != cons_head)
> +		cpu_spinwait();
> +
> +	atomic_store_rel_int(&br->br_cons_tail, cons_next);
> +	critical_exit();
> +
> +	return (buf);
> +}
> +
> +/*
> + * single-consumer dequeue 
> + * use where dequeue is protected by a lock
> + * e.g. a network driver's tx queue lock
> + */
> +static __inline void *
> +buf_ring_dequeue_sc(struct buf_ring *br)
> +{
> +	uint32_t cons_head, cons_next;
> +#ifdef PREFETCH_DEFINED
> +	uint32_t cons_next_next;
> +#endif
> +	uint32_t prod_tail;
> +	void *buf;
> +
> +	/*
> +	 * This is a workaround to allow using buf_ring on ARM and ARM64.
> +	 * ARM64TODO: Fix buf_ring in a generic way.
> +	 * REMARKS: It is suspected that br_cons_head does not require
> +	 *   load_acq operation, but this change was extensively tested
> +	 *   and confirmed it's working. To be reviewed once again in
> +	 *   FreeBSD-12.
> +	 *
> +	 * Preventing following situation:
> +	 * Core(0) - buf_ring_enqueue()                                       Core(1) - buf_ring_dequeue_sc()
> +	 * -----------------------------------------                                       ----------------------------------------------
> +	 *
> +	 *                                                                                cons_head = br->br_cons_head;
> +	 * atomic_cmpset_acq_32(&br->br_prod_head, ...));
> +	 *                                                                                buf = br->br_ring[cons_head];     <see <1>>
> +	 * br->br_ring[prod_head] = buf;
> +	 * atomic_store_rel_32(&br->br_prod_tail, ...);
> +	 *                                                                                prod_tail = br->br_prod_tail;
> +	 *                                                                                if (cons_head == prod_tail) 
> +	 *                                                                                        return (NULL);
> +	 *                                                                                <condition is false and code uses invalid(old) buf>`	
> +	 *
> +	 * <1> Load (on core 1) from br->br_ring[cons_head] can be reordered (speculative readed) by CPU.
> +	 */	
> +#if defined(__arm__) || defined(__aarch64__)
> +	cons_head = atomic_load_acq_32(&br->br_cons_head);
> +#else
> +	cons_head = br->br_cons_head;
> +#endif
> +	prod_tail = atomic_load_acq_32(&br->br_prod_tail);
> +	
> +	cons_next = (cons_head + 1) & br->br_cons_mask;
> +#ifdef PREFETCH_DEFINED
> +	cons_next_next = (cons_head + 2) & br->br_cons_mask;
> +#endif
> +	
> +	if (cons_head == prod_tail) 
> +		return (NULL);
> +
> +#ifdef PREFETCH_DEFINED	
> +	if (cons_next != prod_tail) {		
> +		prefetch(br->br_ring[cons_next]);
> +		if (cons_next_next != prod_tail) 
> +			prefetch(br->br_ring[cons_next_next]);
> +	}
> +#endif
> +	br->br_cons_head = cons_next;
> +	buf = br->br_ring[cons_head];
> +
> +#ifdef DEBUG_BUFRING
> +	br->br_ring[cons_head] = NULL;
> +	if (!mtx_owned(br->br_lock))
> +		panic("lock not held on single consumer dequeue");
> +	if (br->br_cons_tail != cons_head)
> +		panic("inconsistent list cons_tail=%d cons_head=%d",
> +		    br->br_cons_tail, cons_head);
> +#endif
> +	br->br_cons_tail = cons_next;
> +	return (buf);
> +}
> +
> +/*
> + * single-consumer advance after a peek
> + * use where it is protected by a lock
> + * e.g. a network driver's tx queue lock
> + */
> +static __inline void
> +buf_ring_advance_sc(struct buf_ring *br)
> +{
> +	uint32_t cons_head, cons_next;
> +	uint32_t prod_tail;
> +	
> +	cons_head = br->br_cons_head;
> +	prod_tail = br->br_prod_tail;
> +	
> +	cons_next = (cons_head + 1) & br->br_cons_mask;
> +	if (cons_head == prod_tail) 
> +		return;
> +	br->br_cons_head = cons_next;
> +#ifdef DEBUG_BUFRING
> +	br->br_ring[cons_head] = NULL;
> +#endif
> +	br->br_cons_tail = cons_next;
> +}
> +
> +/*
> + * Used to return a buffer (most likely already there)
> + * to the top of the ring. The caller should *not*
> + * have used any dequeue to pull it out of the ring
> + * but instead should have used the peek() function.
> + * This is normally used where the transmit queue
> + * of a driver is full, and an mbuf must be returned.
> + * Most likely whats in the ring-buffer is what
> + * is being put back (since it was not removed), but
> + * sometimes the lower transmit function may have
> + * done a pullup or other function that will have
> + * changed it. As an optimization we always put it
> + * back (since jhb says the store is probably cheaper),
> + * if we have to do a multi-queue version we will need
> + * the compare and an atomic.
> + */
> +static __inline void
> +buf_ring_putback_sc(struct buf_ring *br, void *new)
> +{
> +	KASSERT(br->br_cons_head != br->br_prod_tail, 
> +		("Buf-Ring has none in putback")) ;
> +	br->br_ring[br->br_cons_head] = new;
> +}
> +
> +/*
> + * return a pointer to the first entry in the ring
> + * without modifying it, or NULL if the ring is empty
> + * race-prone if not protected by a lock
> + */
> +static __inline void *
> +buf_ring_peek(struct buf_ring *br)
> +{
> +
> +#ifdef DEBUG_BUFRING
> +	if ((br->br_lock != NULL) && !mtx_owned(br->br_lock))
> +		panic("lock not held on single consumer dequeue");
> +#endif	
> +	/*
> +	 * I believe it is safe to not have a memory barrier
> +	 * here because we control cons and tail is worst case
> +	 * a lagging indicator so we worst case we might
> +	 * return NULL immediately after a buffer has been enqueued
> +	 */
> +	if (br->br_cons_head == br->br_prod_tail)
> +		return (NULL);
> +	
> +	return (br->br_ring[br->br_cons_head]);
> +}
> +
> +static __inline void *
> +buf_ring_peek_clear_sc(struct buf_ring *br)
> +{
> +#ifdef DEBUG_BUFRING
> +	void *ret;
> +
> +	if (!mtx_owned(br->br_lock))
> +		panic("lock not held on single consumer dequeue");
> +#endif	
> +
> +	if (br->br_cons_head == br->br_prod_tail)
> +		return (NULL);
> +
> +#if defined(__arm__) || defined(__aarch64__)
> +	/*
> +	 * The barrier is required there on ARM and ARM64 to ensure, that
> +	 * br->br_ring[br->br_cons_head] will not be fetched before the above
> +	 * condition is checked.
> +	 * Without the barrier, it is possible, that buffer will be fetched
> +	 * before the enqueue will put mbuf into br, then, in the meantime, the
> +	 * enqueue will update the array and the br_prod_tail, and the
> +	 * conditional check will be true, so we will return previously fetched
> +	 * (and invalid) buffer.
> +	 */
> +	atomic_thread_fence_acq();
> +#endif
> +
> +#ifdef DEBUG_BUFRING
> +	/*
> +	 * Single consumer, i.e. cons_head will not move while we are
> +	 * running, so atomic_swap_ptr() is not necessary here.
> +	 */
> +	ret = br->br_ring[br->br_cons_head];
> +	br->br_ring[br->br_cons_head] = NULL;
> +	return (ret);
> +#else
> +	return (br->br_ring[br->br_cons_head]);
> +#endif
> +}
> +
> +static __inline int
> +buf_ring_full(struct buf_ring *br)
> +{
> +
> +	return (((br->br_prod_head + 1) & br->br_prod_mask) == br->br_cons_tail);
> +}
> +
> +static __inline int
> +buf_ring_empty(struct buf_ring *br)
> +{
> +
> +	return (br->br_cons_head == br->br_prod_tail);
> +}
> +
> +static __inline int
> +buf_ring_count(struct buf_ring *br)
> +{
> +
> +	return ((br->br_prod_size + br->br_prod_tail - br->br_cons_tail)
> +	    & br->br_prod_mask);
> +}
> +
> +struct buf_ring *buf_ring_alloc(int count, struct malloc_type *type, int flags,
> +    struct mtx *);
> +void buf_ring_free(struct buf_ring *br, struct malloc_type *type);
> +
> +
> +
> +#endif
> \ No newline at end of file
> diff --git a/lib/ukring/ring.c b/lib/ukring/ring.c
> new file mode 100644
> index 0000000..644c3be
> --- /dev/null
> +++ b/lib/ukring/ring.c
> @@ -0,0 +1,65 @@
> +/*-
> + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
> + *
> + * Copyright (c) 2007, 2008 Kip Macy <kmacy@freebsd.org>
> + * All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in the
> + *    documentation and/or other materials provided with the distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> + * SUCH DAMAGE.
> + */
> +
> +#include <sys/cdefs.h>
> +__FBSDID("$FreeBSD$");
> +
> +#include <sys/param.h>
> +#include <sys/systm.h>
> +#include <sys/kernel.h>
> +#include <sys/malloc.h>
> +#include <sys/ktr.h>
> +#include <sys/buf_ring.h>
> +
> +struct buf_ring *
> +buf_ring_alloc(int count, struct malloc_type *type, int flags, struct mtx *lock)
> +{
> +	struct buf_ring *br;
> +
> +	KASSERT(powerof2(count), ("buf ring must be size power of 2"));
> +	
> +	br = malloc(sizeof(struct buf_ring) + count*sizeof(caddr_t),
> +	    type, flags|M_ZERO);
> +	if (br == NULL)
> +		return (NULL);
> +#ifdef DEBUG_BUFRING
> +	br->br_lock = lock;
> +#endif	
> +	br->br_prod_size = br->br_cons_size = count;
> +	br->br_prod_mask = br->br_cons_mask = count-1;
> +	br->br_prod_head = br->br_cons_head = 0;
> +	br->br_prod_tail = br->br_cons_tail = 0;
> +		
> +	return (br);
> +}
> +
> +void
> +buf_ring_free(struct buf_ring *br, struct malloc_type *type)
> +{
> +	free(br, type);
> +}
> \ No newline at end of file
> 


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 17:05:09 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 17:05:09 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxvhV-0001jc-8f; Tue, 21 Jul 2020 17:05:09 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=W8eI=BA=gmail.com=costin.lup@srs-us1.protection.inumbo.net>)
 id 1jxvhU-0001jX-Ss
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 17:05:08 +0000
X-Inumbo-ID: 53801c02-cb74-11ea-857e-bc764e2007e4
Received: from mail-ed1-x543.google.com (unknown [2a00:1450:4864:20::543])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 53801c02-cb74-11ea-857e-bc764e2007e4;
 Tue, 21 Jul 2020 17:05:07 +0000 (UTC)
Received: by mail-ed1-x543.google.com with SMTP id d16so15763020edz.12
 for <minios-devel@lists.xen.org>; Tue, 21 Jul 2020 10:05:07 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=subject:to:cc:references:from:message-id:date:user-agent
 :mime-version:in-reply-to:content-language:content-transfer-encoding;
 bh=JcRdt0JIB3y/5RwIRqvdHwy1MJ+aOevPA9yjhPvQDfs=;
 b=TcWmXmX1UBSeHNyqHl8FJpFw3RimgjX+VI/urqJWeP79ULqrk5xs4bF8t8J7RaoS5j
 3pevhNnBc+Cys+08wcp2sFbdXp8LTw1ut7Qj4PQX1lTebktETcA1XqR2sMl5RcliOXzj
 DQTOrPDBj92bqq132YqF9ZikrpaQ3y/SlSp1ubOPD5GTOGL48Og+be/a6BGrobQySY+Z
 147L0MDfTTioeunbegIQB9OxfKF0NUXtuUm31VqX8t8XmpN3n7FKOcIyZ+KfxAnBgsFj
 hdPdk1l37VrC1fznFpXZVdpmLEdf0XrQokmDBp/zH5vvQMs2gKfo5UGdNjy6rbzOlZXe
 K2cQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:subject:to:cc:references:from:message-id:date
 :user-agent:mime-version:in-reply-to:content-language
 :content-transfer-encoding;
 bh=JcRdt0JIB3y/5RwIRqvdHwy1MJ+aOevPA9yjhPvQDfs=;
 b=NYmt6D5Yv/qG4Dq3/baCuQbYRdtEV51gez2zEVzn4Jx6mUrtlrVwxmDmjsHmmDqUTz
 av7zrLXbqtkA+IvAayrVl2dRPfcXFkogH8VbpVOXhM56O917yWYJTNUAVVKwJAGJFDnQ
 eeL/HUjuUI5BE+2BZscypNFsqx0UIjF1XGfn332X9PBTvdbxJpwrkAzLUNmHiIL5BzFh
 CRJ01wz0U/pdYNs/zZBU64pqpFrH2kCZFAeQu66YiXjqZ2Jax1p9BR4DQcWr2PKBZGMn
 SInwo4H2aVgRuYkqPAFPYZH5i5ByNnhtCkG/4MqIBhz6aSyeg8MI/hHy78tqM/qE4lDV
 qz4Q==
X-Gm-Message-State: AOAM530bq3uHRvIQbtVlHJlTPSf9QQVWtbeeMIF2L/JmsJDWoLutPDi9
 lSBNbQUAenToCiqNtbWGegc=
X-Google-Smtp-Source: ABdhPJyxBmeaa5m43JEv8t5Cj4+N2msuGQg1UiJcrvI6ZcZqtVyeqjux3el1AQHBxqwUsEEHAkjJng==
X-Received: by 2002:a05:6402:1687:: with SMTP id
 a7mr26479784edv.358.1595351105949; 
 Tue, 21 Jul 2020 10:05:05 -0700 (PDT)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro.
 [5.12.134.63])
 by smtp.gmail.com with ESMTPSA id o18sm17008257ejr.45.2020.07.21.10.05.04
 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
 Tue, 21 Jul 2020 10:05:05 -0700 (PDT)
Subject: Re: [UNIKRAFT PATCH, v2, 02/15] lib/ukring: {ring.c, ring.h} Fix
 checkpatch errors and spacing.
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
 <20200721153956.13555-3-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lup@gmail.com>
Message-ID: <8a64cf85-e569-6ac3-3488-99239a112b45@gmail.com>
Date: Tue, 21 Jul 2020 20:05:04 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200721153956.13555-3-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

I think you might have some issue with the checkpatch script. The
original files used tabs for indentation (which was ok), but this patch
replace them with spaces (which makes checkpatch script generate lots of
errors).

Costin

On 7/21/20 6:39 PM, Alexander Jung wrote:
> Converting tabs to spaces and increasing readability.
> 
> Also fixes checkpatch errors:
> 
> * return is not a function, parentheses are not required
> * trailing whitespace
> * space required before the open parenthesis '('
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/ukring/include/uk/ring.h | 420 ++++++++++++++++++-----------------
>  lib/ukring/ring.c            |  35 +--
>  2 files changed, 236 insertions(+), 219 deletions(-)
> 
> diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
> index 899563c..4f0d80c 100644
> --- a/lib/ukring/include/uk/ring.h
> +++ b/lib/ukring/include/uk/ring.h
> @@ -29,8 +29,8 @@
>   *
>   */
>  
> -#ifndef	_SYS_BUF_RING_H_
> -#define	_SYS_BUF_RING_H_
> +#ifndef  _SYS_BUF_RING_H_
> +#define  _SYS_BUF_RING_H_
>  
>  #include <machine/cpu.h>
>  
> @@ -39,22 +39,24 @@
>  #include <sys/mutex.h>
>  #endif
>  
> +
>  struct buf_ring {
> -	volatile uint32_t	br_prod_head;
> -	volatile uint32_t	br_prod_tail;	
> -	int              	br_prod_size;
> -	int              	br_prod_mask;
> -	uint64_t		br_drops;
> -	volatile uint32_t	br_cons_head __aligned(CACHE_LINE_SIZE);
> -	volatile uint32_t	br_cons_tail;
> -	int		 	br_cons_size;
> -	int              	br_cons_mask;
> +  volatile uint32_t  br_prod_head;
> +  volatile uint32_t  br_prod_tail;
> +  int                br_prod_size;
> +  int                br_prod_mask;
> +  uint64_t           br_drops;
> +  volatile uint32_t  br_cons_head __aligned(CACHE_LINE_SIZE);
> +  volatile uint32_t  br_cons_tail;
> +  int                br_cons_size;
> +  int                br_cons_mask;
>  #ifdef DEBUG_BUFRING
> -	struct mtx		*br_lock;
> -#endif	
> -	void			*br_ring[0] __aligned(CACHE_LINE_SIZE);
> +  struct mtx        *br_lock;
> +#endif
> +  void              *br_ring[0] __aligned(CACHE_LINE_SIZE);
>  };
>  
> +
>  /*
>   * multi-producer safe lock-free ring buffer enqueue
>   *
> @@ -62,54 +64,60 @@ struct buf_ring {
>  static __inline int
>  buf_ring_enqueue(struct buf_ring *br, void *buf)
>  {
> -	uint32_t prod_head, prod_next, cons_tail;
> +  uint32_t prod_head, prod_next, cons_tail;
> +
>  #ifdef DEBUG_BUFRING
> -	int i;
> -
> -	/*
> -	 * Note: It is possible to encounter an mbuf that was removed
> -	 * via drbr_peek(), and then re-added via drbr_putback() and
> -	 * trigger a spurious panic.
> -	 */
> -	for (i = br->br_cons_head; i != br->br_prod_head;
> -	     i = ((i + 1) & br->br_cons_mask))
> -		if(br->br_ring[i] == buf)
> -			panic("buf=%p already enqueue at %d prod=%d cons=%d",
> -			    buf, i, br->br_prod_tail, br->br_cons_tail);
> -#endif	
> -	critical_enter();
> -	do {
> -		prod_head = br->br_prod_head;
> -		prod_next = (prod_head + 1) & br->br_prod_mask;
> -		cons_tail = br->br_cons_tail;
> -
> -		if (prod_next == cons_tail) {
> -			rmb();
> -			if (prod_head == br->br_prod_head &&
> -			    cons_tail == br->br_cons_tail) {
> -				br->br_drops++;
> -				critical_exit();
> -				return (ENOBUFS);
> -			}
> -			continue;
> -		}
> -	} while (!atomic_cmpset_acq_int(&br->br_prod_head, prod_head, prod_next));
> +  int i;
> +
> +  /*
> +   * Note: It is possible to encounter an mbuf that was removed
> +   * via drbr_peek(), and then re-added via drbr_putback() and
> +   * trigger a spurious panic.
> +   */
> +  for (i = br->br_cons_head; i != br->br_prod_head;
> +       i = ((i + 1) & br->br_cons_mask))
> +    if (br->br_ring[i] == buf)
> +      panic("buf=%p already enqueue at %d prod=%d cons=%d",
> +          buf, i, br->br_prod_tail, br->br_cons_tail);
> +#endif
> +
> +  critical_enter();
> +
> +  do {
> +    prod_head = br->br_prod_head;
> +    prod_next = (prod_head + 1) & br->br_prod_mask;
> +    cons_tail = br->br_cons_tail;
> +
> +    if (prod_next == cons_tail) {
> +      rmb();
> +      if (prod_head == br->br_prod_head && cons_tail == br->br_cons_tail) {
> +        br->br_drops++;
> +        critical_exit();
> +        return ENOBUFS;
> +      }
> +      continue;
> +    }
> +  } while (!atomic_cmpset_acq_int(&br->br_prod_head, prod_head, prod_next));
> +
>  #ifdef DEBUG_BUFRING
> -	if (br->br_ring[prod_head] != NULL)
> -		panic("dangling value in enqueue");
> -#endif	
> -	br->br_ring[prod_head] = buf;
> -
> -	/*
> -	 * If there are other enqueues in progress
> -	 * that preceded us, we need to wait for them
> -	 * to complete 
> -	 */   
> -	while (br->br_prod_tail != prod_head)
> -		cpu_spinwait();
> -	atomic_store_rel_int(&br->br_prod_tail, prod_next);
> -	critical_exit();
> -	return (0);
> +  if (br->br_ring[prod_head] != NULL)
> +    panic("dangling value in enqueue");
> +#endif
> +
> +  br->br_ring[prod_head] = buf;
> +
> +  /*
> +   * If there are other enqueues in progress
> +   * that preceded us, we need to wait for them
> +   * to complete 
> +   */
> +  while (br->br_prod_tail != prod_head)
> +    cpu_spinwait();
> +
> +  atomic_store_rel_int(&br->br_prod_tail, prod_next);
> +  critical_exit();
> +
> +  return 0;
>  }
>  
>  /*
> @@ -119,36 +127,39 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
>  static __inline void *
>  buf_ring_dequeue_mc(struct buf_ring *br)
>  {
> -	uint32_t cons_head, cons_next;
> -	void *buf;
> +  uint32_t cons_head, cons_next;
> +  void *buf;
> +
> +  critical_enter();
> +
> +  do {
> +    cons_head = br->br_cons_head;
> +    cons_next = (cons_head + 1) & br->br_cons_mask;
>  
> -	critical_enter();
> -	do {
> -		cons_head = br->br_cons_head;
> -		cons_next = (cons_head + 1) & br->br_cons_mask;
> +    if (cons_head == br->br_prod_tail) {
> +      critical_exit();
> +      return NULL;
> +    }
> +  } while (!atomic_cmpset_acq_int(&br->br_cons_head, cons_head, cons_next));
>  
> -		if (cons_head == br->br_prod_tail) {
> -			critical_exit();
> -			return (NULL);
> -		}
> -	} while (!atomic_cmpset_acq_int(&br->br_cons_head, cons_head, cons_next));
> +  buf = br->br_ring[cons_head];
>  
> -	buf = br->br_ring[cons_head];
>  #ifdef DEBUG_BUFRING
> -	br->br_ring[cons_head] = NULL;
> +  br->br_ring[cons_head] = NULL;
>  #endif
> -	/*
> -	 * If there are other dequeues in progress
> -	 * that preceded us, we need to wait for them
> -	 * to complete 
> -	 */   
> -	while (br->br_cons_tail != cons_head)
> -		cpu_spinwait();
> -
> -	atomic_store_rel_int(&br->br_cons_tail, cons_next);
> -	critical_exit();
> -
> -	return (buf);
> +
> +  /*
> +   * If there are other dequeues in progress
> +   * that preceded us, we need to wait for them
> +   * to complete
> +   */
> +  while (br->br_cons_tail != cons_head)
> +    cpu_spinwait();
> +
> +  atomic_store_rel_int(&br->br_cons_tail, cons_next);
> +  critical_exit();
> +
> +  return buf;
>  }
>  
>  /*
> @@ -159,72 +170,76 @@ buf_ring_dequeue_mc(struct buf_ring *br)
>  static __inline void *
>  buf_ring_dequeue_sc(struct buf_ring *br)
>  {
> -	uint32_t cons_head, cons_next;
> +  uint32_t cons_head, cons_next;
>  #ifdef PREFETCH_DEFINED
> -	uint32_t cons_next_next;
> +  uint32_t cons_next_next;
>  #endif
> -	uint32_t prod_tail;
> -	void *buf;
> -
> -	/*
> -	 * This is a workaround to allow using buf_ring on ARM and ARM64.
> -	 * ARM64TODO: Fix buf_ring in a generic way.
> -	 * REMARKS: It is suspected that br_cons_head does not require
> -	 *   load_acq operation, but this change was extensively tested
> -	 *   and confirmed it's working. To be reviewed once again in
> -	 *   FreeBSD-12.
> -	 *
> -	 * Preventing following situation:
> -	 * Core(0) - buf_ring_enqueue()                                       Core(1) - buf_ring_dequeue_sc()
> -	 * -----------------------------------------                                       ----------------------------------------------
> -	 *
> -	 *                                                                                cons_head = br->br_cons_head;
> -	 * atomic_cmpset_acq_32(&br->br_prod_head, ...));
> -	 *                                                                                buf = br->br_ring[cons_head];     <see <1>>
> -	 * br->br_ring[prod_head] = buf;
> -	 * atomic_store_rel_32(&br->br_prod_tail, ...);
> -	 *                                                                                prod_tail = br->br_prod_tail;
> -	 *                                                                                if (cons_head == prod_tail) 
> -	 *                                                                                        return (NULL);
> -	 *                                                                                <condition is false and code uses invalid(old) buf>`	
> -	 *
> -	 * <1> Load (on core 1) from br->br_ring[cons_head] can be reordered (speculative readed) by CPU.
> -	 */	
> +  uint32_t prod_tail;
> +  void *buf;
> +
> +  /*
> +   * This is a workaround to allow using buf_ring on ARM and ARM64.
> +   * ARM64TODO: Fix buf_ring in a generic way.
> +   * REMARKS: It is suspected that br_cons_head does not require
> +   *   load_acq operation, but this change was extensively tested
> +   *   and confirmed it's working. To be reviewed once again in
> +   *   FreeBSD-12.
> +   *
> +   * Preventing following situation:
> +   * Core(0) - buf_ring_enqueue()                                       Core(1) - buf_ring_dequeue_sc()
> +   * -----------------------------------------                                       ----------------------------------------------
> +   *
> +   *                                                                                cons_head = br->br_cons_head;
> +   * atomic_cmpset_acq_32(&br->br_prod_head, ...));
> +   *                                                                                buf = br->br_ring[cons_head];     <see <1>>
> +   * br->br_ring[prod_head] = buf;
> +   * atomic_store_rel_32(&br->br_prod_tail, ...);
> +   *                                                                                prod_tail = br->br_prod_tail;
> +   *                                                                                if (cons_head == prod_tail) 
> +   *                                                                                        return (NULL);
> +   *                                                                                <condition is false and code uses invalid(old) buf>`  
> +   *
> +   * <1> Load (on core 1) from br->br_ring[cons_head] can be reordered (speculative readed) by CPU.
> +   */
>  #if defined(__arm__) || defined(__aarch64__)
> -	cons_head = atomic_load_acq_32(&br->br_cons_head);
> +  cons_head = atomic_load_acq_32(&br->br_cons_head);
>  #else
> -	cons_head = br->br_cons_head;
> +  cons_head = br->br_cons_head;
>  #endif
> -	prod_tail = atomic_load_acq_32(&br->br_prod_tail);
> -	
> -	cons_next = (cons_head + 1) & br->br_cons_mask;
> +  prod_tail = atomic_load_acq_32(&br->br_prod_tail);
> +
> +  cons_next = (cons_head + 1) & br->br_cons_mask;
>  #ifdef PREFETCH_DEFINED
> -	cons_next_next = (cons_head + 2) & br->br_cons_mask;
> +  cons_next_next = (cons_head + 2) & br->br_cons_mask;
>  #endif
> -	
> -	if (cons_head == prod_tail) 
> -		return (NULL);
> -
> -#ifdef PREFETCH_DEFINED	
> -	if (cons_next != prod_tail) {		
> -		prefetch(br->br_ring[cons_next]);
> -		if (cons_next_next != prod_tail) 
> -			prefetch(br->br_ring[cons_next_next]);
> -	}
> +
> +  if (cons_head == prod_tail)
> +    return NULL;
> +
> +#ifdef PREFETCH_DEFINED
> +  if (cons_next != prod_tail) {
> +    prefetch(br->br_ring[cons_next]);
> +    if (cons_next_next != prod_tail)
> +      prefetch(br->br_ring[cons_next_next]);
> +  }
>  #endif
> -	br->br_cons_head = cons_next;
> -	buf = br->br_ring[cons_head];
> +
> +  br->br_cons_head = cons_next;
> +  buf = br->br_ring[cons_head];
>  
>  #ifdef DEBUG_BUFRING
> -	br->br_ring[cons_head] = NULL;
> -	if (!mtx_owned(br->br_lock))
> -		panic("lock not held on single consumer dequeue");
> -	if (br->br_cons_tail != cons_head)
> -		panic("inconsistent list cons_tail=%d cons_head=%d",
> -		    br->br_cons_tail, cons_head);
> +  br->br_ring[cons_head] = NULL;
> +
> +  if (!mtx_owned(br->br_lock))
> +    panic("lock not held on single consumer dequeue");
> +
> +  if (br->br_cons_tail != cons_head)
> +    panic("inconsistent list cons_tail=%d cons_head=%d",
> +        br->br_cons_tail, cons_head);
>  #endif
> -	br->br_cons_tail = cons_next;
> -	return (buf);
> +
> +  br->br_cons_tail = cons_next;
> +  return buf;
>  }
>  
>  /*
> @@ -235,20 +250,23 @@ buf_ring_dequeue_sc(struct buf_ring *br)
>  static __inline void
>  buf_ring_advance_sc(struct buf_ring *br)
>  {
> -	uint32_t cons_head, cons_next;
> -	uint32_t prod_tail;
> -	
> -	cons_head = br->br_cons_head;
> -	prod_tail = br->br_prod_tail;
> -	
> -	cons_next = (cons_head + 1) & br->br_cons_mask;
> -	if (cons_head == prod_tail) 
> -		return;
> -	br->br_cons_head = cons_next;
> +  uint32_t cons_head, cons_next;
> +  uint32_t prod_tail;
> +
> +  cons_head = br->br_cons_head;
> +  prod_tail = br->br_prod_tail;
> +  cons_next = (cons_head + 1) & br->br_cons_mask;
> +
> +  if (cons_head == prod_tail)
> +    return;
> +
> +  br->br_cons_head = cons_next;
> +
>  #ifdef DEBUG_BUFRING
> -	br->br_ring[cons_head] = NULL;
> +  br->br_ring[cons_head] = NULL;
>  #endif
> -	br->br_cons_tail = cons_next;
> +
> +  br->br_cons_tail = cons_next;
>  }
>  
>  /*
> @@ -270,9 +288,9 @@ buf_ring_advance_sc(struct buf_ring *br)
>  static __inline void
>  buf_ring_putback_sc(struct buf_ring *br, void *new)
>  {
> -	KASSERT(br->br_cons_head != br->br_prod_tail, 
> -		("Buf-Ring has none in putback")) ;
> -	br->br_ring[br->br_cons_head] = new;
> +  KASSERT(br->br_cons_head != br->br_prod_tail,
> +    ("Buf-Ring has none in putback"));
> +  br->br_ring[br->br_cons_head] = new;
>  }
>  
>  /*
> @@ -283,89 +301,85 @@ buf_ring_putback_sc(struct buf_ring *br, void *new)
>  static __inline void *
>  buf_ring_peek(struct buf_ring *br)
>  {
> -
>  #ifdef DEBUG_BUFRING
> -	if ((br->br_lock != NULL) && !mtx_owned(br->br_lock))
> -		panic("lock not held on single consumer dequeue");
> -#endif	
> -	/*
> -	 * I believe it is safe to not have a memory barrier
> -	 * here because we control cons and tail is worst case
> -	 * a lagging indicator so we worst case we might
> -	 * return NULL immediately after a buffer has been enqueued
> -	 */
> -	if (br->br_cons_head == br->br_prod_tail)
> -		return (NULL);
> -	
> -	return (br->br_ring[br->br_cons_head]);
> +  if ((br->br_lock != NULL) && !mtx_owned(br->br_lock))
> +    panic("lock not held on single consumer dequeue");
> +#endif
> +
> +  /*
> +   * I believe it is safe to not have a memory barrier
> +   * here because we control cons and tail is worst case
> +   * a lagging indicator so we worst case we might
> +   * return NULL immediately after a buffer has been enqueued
> +   */
> +  if (br->br_cons_head == br->br_prod_tail)
> +    return NULL;
> +
> +  return br->br_ring[br->br_cons_head];
>  }
>  
>  static __inline void *
>  buf_ring_peek_clear_sc(struct buf_ring *br)
>  {
>  #ifdef DEBUG_BUFRING
> -	void *ret;
> +  void *ret;
>  
> -	if (!mtx_owned(br->br_lock))
> -		panic("lock not held on single consumer dequeue");
> -#endif	
> +  if (!mtx_owned(br->br_lock))
> +    panic("lock not held on single consumer dequeue");
> +#endif
>  
> -	if (br->br_cons_head == br->br_prod_tail)
> -		return (NULL);
> +  if (br->br_cons_head == br->br_prod_tail)
> +    return NULL;
>  
>  #if defined(__arm__) || defined(__aarch64__)
> -	/*
> -	 * The barrier is required there on ARM and ARM64 to ensure, that
> -	 * br->br_ring[br->br_cons_head] will not be fetched before the above
> -	 * condition is checked.
> -	 * Without the barrier, it is possible, that buffer will be fetched
> -	 * before the enqueue will put mbuf into br, then, in the meantime, the
> -	 * enqueue will update the array and the br_prod_tail, and the
> -	 * conditional check will be true, so we will return previously fetched
> -	 * (and invalid) buffer.
> -	 */
> -	atomic_thread_fence_acq();
> +  /*
> +   * The barrier is required there on ARM and ARM64 to ensure, that
> +   * br->br_ring[br->br_cons_head] will not be fetched before the above
> +   * condition is checked.
> +   * Without the barrier, it is possible, that buffer will be fetched
> +   * before the enqueue will put mbuf into br, then, in the meantime, the
> +   * enqueue will update the array and the br_prod_tail, and the
> +   * conditional check will be true, so we will return previously fetched
> +   * (and invalid) buffer.
> +   */
> +  atomic_thread_fence_acq();
>  #endif
>  
>  #ifdef DEBUG_BUFRING
> -	/*
> -	 * Single consumer, i.e. cons_head will not move while we are
> -	 * running, so atomic_swap_ptr() is not necessary here.
> -	 */
> -	ret = br->br_ring[br->br_cons_head];
> -	br->br_ring[br->br_cons_head] = NULL;
> -	return (ret);
> +  /*
> +   * Single consumer, i.e. cons_head will not move while we are
> +   * running, so atomic_swap_ptr() is not necessary here.
> +   */
> +  ret = br->br_ring[br->br_cons_head];
> +  br->br_ring[br->br_cons_head] = NULL;
> +
> +  return ret;
>  #else
> -	return (br->br_ring[br->br_cons_head]);
> +  return br->br_ring[br->br_cons_head];
>  #endif
>  }
>  
>  static __inline int
>  buf_ring_full(struct buf_ring *br)
>  {
> -
> -	return (((br->br_prod_head + 1) & br->br_prod_mask) == br->br_cons_tail);
> +  return ((br->br_prod_head + 1) & br->br_prod_mask) == br->br_cons_tail;
>  }
>  
>  static __inline int
>  buf_ring_empty(struct buf_ring *br)
>  {
> -
> -	return (br->br_cons_head == br->br_prod_tail);
> +  return br->br_cons_head == br->br_prod_tail;
>  }
>  
>  static __inline int
>  buf_ring_count(struct buf_ring *br)
>  {
> -
> -	return ((br->br_prod_size + br->br_prod_tail - br->br_cons_tail)
> -	    & br->br_prod_mask);
> +  return (br->br_prod_size + br->br_prod_tail - br->br_cons_tail)
> +      & br->br_prod_mask;
>  }
>  
>  struct buf_ring *buf_ring_alloc(int count, struct malloc_type *type, int flags,
>      struct mtx *);
>  void buf_ring_free(struct buf_ring *br, struct malloc_type *type);
>  
> -
> -
>  #endif
> \ No newline at end of file
> diff --git a/lib/ukring/ring.c b/lib/ukring/ring.c
> index 644c3be..ed5e8f7 100644
> --- a/lib/ukring/ring.c
> +++ b/lib/ukring/ring.c
> @@ -39,27 +39,30 @@ __FBSDID("$FreeBSD$");
>  struct buf_ring *
>  buf_ring_alloc(int count, struct malloc_type *type, int flags, struct mtx *lock)
>  {
> -	struct buf_ring *br;
> +  struct buf_ring *br;
> +
> +  KASSERT(powerof2(count), ("buf ring must be size power of 2"));
> +
> +  br = malloc(sizeof(struct buf_ring) + count*sizeof(caddr_t),
> +      type, flags|M_ZERO);
> +
> +  if (br == NULL)
> +    return NULL;
>  
> -	KASSERT(powerof2(count), ("buf ring must be size power of 2"));
> -	
> -	br = malloc(sizeof(struct buf_ring) + count*sizeof(caddr_t),
> -	    type, flags|M_ZERO);
> -	if (br == NULL)
> -		return (NULL);
>  #ifdef DEBUG_BUFRING
> -	br->br_lock = lock;
> -#endif	
> -	br->br_prod_size = br->br_cons_size = count;
> -	br->br_prod_mask = br->br_cons_mask = count-1;
> -	br->br_prod_head = br->br_cons_head = 0;
> -	br->br_prod_tail = br->br_cons_tail = 0;
> -		
> -	return (br);
> +  br->br_lock = lock;
> +#endif
> +
> +  br->br_prod_size = br->br_cons_size = count;
> +  br->br_prod_mask = br->br_cons_mask = count - 1;
> +  br->br_prod_head = br->br_cons_head = 0;
> +  br->br_prod_tail = br->br_cons_tail = 0;
> +
> +  return br;
>  }
>  
>  void
>  buf_ring_free(struct buf_ring *br, struct malloc_type *type)
>  {
> -	free(br, type);
> +  free(br, type);
>  }
> \ No newline at end of file
> 


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 17:40:57 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 17:40:57 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxwG7-000583-H5; Tue, 21 Jul 2020 17:40:55 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=NVI3=BA=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jxwG5-00057y-TL
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 17:40:53 +0000
X-Inumbo-ID: 5173e600-cb79-11ea-a118-12813bfff9fa
Received: from mx.upb.ro (unknown [141.85.13.220])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 5173e600-cb79-11ea-a118-12813bfff9fa;
 Tue, 21 Jul 2020 17:40:51 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 380D0B561CCE;
 Tue, 21 Jul 2020 20:40:50 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id amolEIxF_LSo; Tue, 21 Jul 2020 20:40:46 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 6C4D2B561C89;
 Tue, 21 Jul 2020 20:40:46 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id je8higX2ybJB; Tue, 21 Jul 2020 20:40:46 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id CD889B5617CC;
 Tue, 21 Jul 2020 20:40:45 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH, v2, 03/15] lib/ukring: Adapt {ring.c, ring.h} to
 Unikraft
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
 <20200721153956.13555-4-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <b2aa60e1-0056-bade-8031-07000b62befb@cs.pub.ro>
Date: Tue, 21 Jul 2020 20:40:45 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200721153956.13555-4-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

Please see inline.

On 7/21/20 6:39 PM, Alexander Jung wrote:
> * Includes Unikraft-centric headers and types; and,
> * Disables ARM{32,64}-specific atomic actions as unsupported;
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/ukring/include/uk/ring.h | 81 +++++++++++++++++++-----------------
>  lib/ukring/ring.c            | 39 ++++++++++-------
>  2 files changed, 66 insertions(+), 54 deletions(-)
> 
> diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
> index 4f0d80c..021331a 100644
> --- a/lib/ukring/include/uk/ring.h
> +++ b/lib/ukring/include/uk/ring.h
> @@ -32,13 +32,13 @@
>  #ifndef  _SYS_BUF_RING_H_
>  #define  _SYS_BUF_RING_H_
>  
> -#include <machine/cpu.h>
> -
> -#ifdef DEBUG_BUFRING
> -#include <sys/lock.h>
> -#include <sys/mutex.h>
> -#endif
> -
> +#include <errno.h>
> +#include <uk/mutex.h>
> +#include <uk/print.h>
> +#include <uk/config.h>
> +#include <uk/assert.h>
> +#include <uk/plat/lcpu.h>
> +#include <uk/arch/atomic.h>
>  
>  struct buf_ring {
>    volatile uint32_t  br_prod_head;
> @@ -51,7 +51,7 @@ struct buf_ring {
>    int                br_cons_size;
>    int                br_cons_mask;
>  #ifdef DEBUG_BUFRING
> -  struct mtx        *br_lock;
> +  struct uk_mutex   *br_lock;
>  #endif
>    void              *br_ring[0] __aligned(CACHE_LINE_SIZE);
>  };
> @@ -72,16 +72,16 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
>    /*
>     * Note: It is possible to encounter an mbuf that was removed
>     * via drbr_peek(), and then re-added via drbr_putback() and
> -   * trigger a spurious panic.
> +   * trigger spurious critical messages.

A rule of thumb is that when we import code from elsewhere we try to
change it as little as possible. Given that we should actually trigger a
panic, I thing it would be better to leave this as it was.

>     */
>    for (i = br->br_cons_head; i != br->br_prod_head;
>         i = ((i + 1) & br->br_cons_mask))
>      if (br->br_ring[i] == buf)
> -      panic("buf=%p already enqueue at %d prod=%d cons=%d",
> +      uk_pr_crit("buf=%p already enqueue at %d prod=%d cons=%d\n",
>            buf, i, br->br_prod_tail, br->br_cons_tail);

The 'panic' is a wide spread approach in OS and embedded development.
When we encounter some kind of catastrophic event or context we should
output a message and stop/abort/exit/crash. So, it's not ok to just
print a message and continue running. In unikraft the equivalent for
panic is UK_CRASH().

>  #endif
>  
> -  critical_enter();
> +  ukplat_lcpu_disable_irq();

Actually this is not fine. critical_enter() disables preemption and
calls a memory barrier, not disabling interrupt. We have the same
abstraction in Linux kernel, called preempt_disable() [1], doing the
same thing. If there is no preemption, as it is the case for unikraft
now, preempt_disable() is the same as barrier() [2].

So please define these 2 abstractions in some header under the global
`include/uk` and use them here. Personally I find the `preempt_disable`
name more suggestive, but it's up to you what name you choose. You can
even keep the critical_enter name as a wrapper name used only by code
imported from FreeBSD (e.g. #ifdef FREEBSD_CODE \ #define
critical_enter() preempt_disable()).

[1]
https://elixir.bootlin.com/linux/latest/source/include/linux/preempt.h#L169
[2]
https://elixir.bootlin.com/linux/latest/source/include/linux/preempt.h#L242

>  
>    do {
>      prod_head = br->br_prod_head;
> @@ -92,16 +92,16 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
>        rmb();
>        if (prod_head == br->br_prod_head && cons_tail == br->br_cons_tail) {
>          br->br_drops++;
> -        critical_exit();
> +        ukplat_lcpu_enable_irq();
>          return ENOBUFS;
>        }
>        continue;
>      }
> -  } while (!atomic_cmpset_acq_int(&br->br_prod_head, prod_head, prod_next));
> +  } while (!ukarch_compare_exchange_sync(&br->br_prod_head, prod_head, prod_next));
>  
>  #ifdef DEBUG_BUFRING
>    if (br->br_ring[prod_head] != NULL)
> -    panic("dangling value in enqueue");
> +    uk_pr_crit("dangling value in enqueue\n");

Panic please.

>  #endif
>  
>    br->br_ring[prod_head] = buf;
> @@ -114,8 +114,8 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
>    while (br->br_prod_tail != prod_head)
>      cpu_spinwait();
>  
> -  atomic_store_rel_int(&br->br_prod_tail, prod_next);
> -  critical_exit();
> +  ukarch_store_n(&br->br_prod_tail, prod_next);
> +  ukplat_lcpu_enable_irq();
>  
>    return 0;
>  }
> @@ -130,17 +130,17 @@ buf_ring_dequeue_mc(struct buf_ring *br)
>    uint32_t cons_head, cons_next;
>    void *buf;
>  
> -  critical_enter();
> +  ukplat_lcpu_disable_irq();
>  
>    do {
>      cons_head = br->br_cons_head;
>      cons_next = (cons_head + 1) & br->br_cons_mask;
>  
>      if (cons_head == br->br_prod_tail) {
> -      critical_exit();
> +      ukplat_lcpu_enable_irq();
>        return NULL;
>      }
> -  } while (!atomic_cmpset_acq_int(&br->br_cons_head, cons_head, cons_next));
> +  } while (!ukarch_compare_exchange_sync(&br->br_cons_head, cons_head, cons_next));
>  
>    buf = br->br_ring[cons_head];
>  
> @@ -156,8 +156,8 @@ buf_ring_dequeue_mc(struct buf_ring *br)
>    while (br->br_cons_tail != cons_head)
>      cpu_spinwait();
>  
> -  atomic_store_rel_int(&br->br_cons_tail, cons_next);
> -  critical_exit();
> +  ukarch_store_n(&br->br_cons_tail, cons_next);
> +  ukplat_lcpu_enable_irq();
>  
>    return buf;
>  }
> @@ -201,12 +201,16 @@ buf_ring_dequeue_sc(struct buf_ring *br)
>     *
>     * <1> Load (on core 1) from br->br_ring[cons_head] can be reordered (speculative readed) by CPU.
>     */
> -#if defined(__arm__) || defined(__aarch64__)
> -  cons_head = atomic_load_acq_32(&br->br_cons_head);
> +#if defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64)
> +  /* TODO: Provide atomic_load_acq_32() */
> +  /* cons_head = atomic_load_acq_32(&br->br_cons_head); */
> +  cons_head = &br->br_cons_head;

An approach we used before was to insert an #error message in order to
force the developer to fix the issue if he wanted to use for an
unsupported architecture. Otherwise we will forget for sure to do this
and/or we will lose a lot of time debugging the thing.

>  #else
>    cons_head = br->br_cons_head;
>  #endif
> -  prod_tail = atomic_load_acq_32(&br->br_prod_tail);
> +  /* TODO: Provide atomic_load_acq_32() */
> +  /* prod_tail = atomic_load_acq_32(&br->br_prod_tail); */
> +  prod_tail = &br->br_prod_tail;

But actually we do have atomic operations defined for these ones, it's
ukarch_load_n().

>  
>    cons_next = (cons_head + 1) & br->br_cons_mask;
>  #ifdef PREFETCH_DEFINED
> @@ -230,11 +234,11 @@ buf_ring_dequeue_sc(struct buf_ring *br)
>  #ifdef DEBUG_BUFRING
>    br->br_ring[cons_head] = NULL;
>  
> -  if (!mtx_owned(br->br_lock))
> -    panic("lock not held on single consumer dequeue");
> +  if (!uk_mutex_is_locked(r->lock))
> +    uk_pr_crit("lock not held on single consumer dequeue\n");
>  
>    if (br->br_cons_tail != cons_head)
> -    panic("inconsistent list cons_tail=%d cons_head=%d",
> +    uk_pr_crit("inconsistent list cons_tail=%d cons_head=%d\n",
>          br->br_cons_tail, cons_head);

Panic please.

>  #endif
>  
> @@ -288,8 +292,8 @@ buf_ring_advance_sc(struct buf_ring *br)
>  static __inline void
>  buf_ring_putback_sc(struct buf_ring *br, void *new)
>  {
> -  KASSERT(br->br_cons_head != br->br_prod_tail,
> -    ("Buf-Ring has none in putback"));
> +  /* Buffer ring has none in putback */
> +  UK_ASSERT(br->br_cons_head != br->br_prod_tail);
>    br->br_ring[br->br_cons_head] = new;
>  }
>  
> @@ -302,8 +306,8 @@ static __inline void *
>  buf_ring_peek(struct buf_ring *br)
>  {
>  #ifdef DEBUG_BUFRING
> -  if ((br->br_lock != NULL) && !mtx_owned(br->br_lock))
> -    panic("lock not held on single consumer dequeue");
> +  if ((r->lock != NULL) && !uk_mutex_is_locked(r->lock))
> +    uk_pr_crit("lock not held on single consumer dequeue\n");

Panic please.

>  #endif
>  
>    /*
> @@ -324,14 +328,14 @@ buf_ring_peek_clear_sc(struct buf_ring *br)
>  #ifdef DEBUG_BUFRING
>    void *ret;
>  
> -  if (!mtx_owned(br->br_lock))
> -    panic("lock not held on single consumer dequeue");
> +  if (!uk_mutex_is_locked(r->lock))
> +    uk_pr_crit("lock not held on single consumer dequeue\n");

Panic please.

>  #endif
>  
>    if (br->br_cons_head == br->br_prod_tail)
>      return NULL;
>  
> -#if defined(__arm__) || defined(__aarch64__)
> +#if defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64)
>    /*
>     * The barrier is required there on ARM and ARM64 to ensure, that
>     * br->br_ring[br->br_cons_head] will not be fetched before the above
> @@ -342,7 +346,8 @@ buf_ring_peek_clear_sc(struct buf_ring *br)
>     * conditional check will be true, so we will return previously fetched
>     * (and invalid) buffer.
>     */
> -  atomic_thread_fence_acq();
> +  /* TODO: Provide atomic_thread_fence_acq(); */
> +  /* atomic_thread_fence_acq(); */

Add an #error here please.

>  #endif
>  
>  #ifdef DEBUG_BUFRING
> @@ -378,8 +383,8 @@ buf_ring_count(struct buf_ring *br)
>        & br->br_prod_mask;
>  }
>  
> -struct buf_ring *buf_ring_alloc(int count, struct malloc_type *type, int flags,
> -    struct mtx *);
> -void buf_ring_free(struct buf_ring *br, struct malloc_type *type);
> +struct buf_ring *buf_ring_alloc(struct uk_alloc *a, int count, int flags,
> +    struct uk_mutex *);

Actually I think it would be better to keep the original params order.
More than that, `struct uk_alloc *a` and `struct malloc_type *type` are
kind of semantically equivalent. Same for buf_ring_free().

> +void buf_ring_free(struct uk_alloc *a, struct buf_ring *br);
>  
>  #endif
> \ No newline at end of file
> diff --git a/lib/ukring/ring.c b/lib/ukring/ring.c
> index ed5e8f7..3f3e053 100644
> --- a/lib/ukring/ring.c
> +++ b/lib/ukring/ring.c
> @@ -26,28 +26,35 @@
>   * SUCH DAMAGE.
>   */
>  
> -#include <sys/cdefs.h>
> -__FBSDID("$FreeBSD$");
> -
>  #include <sys/param.h>
> -#include <sys/systm.h>
> -#include <sys/kernel.h>
> -#include <sys/malloc.h>
> -#include <sys/ktr.h>
> -#include <sys/buf_ring.h>
> +#include <uk/ring.h>
> +#include <uk/assert.h>
> +#include <uk/alloc.h>
> +#include <uk/mutex.h>
> +#include <uk/config.h>
> +#include <uk/print.h>
> +
> +#ifndef POWER_OF_2
> +#define POWER_OF_2(x)   (((x)) && (!((x) & ((x) - 1))))
> +#endif

We already have POWER_OF_2() in essentials.h.

>  
> -struct buf_ring *
> -buf_ring_alloc(int count, struct malloc_type *type, int flags, struct mtx *lock)
> +struct uk_ring *
> +uk_ring_alloc(struct uk_alloc *a, int count, int flags, struct uk_mutex *lock)
>  {
>    struct buf_ring *br;
>  
> -  KASSERT(powerof2(count), ("buf ring must be size power of 2"));
> +  if (a == NULL)
> +    a = uk_alloc_get_default();
> +
> +  /* Buf ring must be size power of 2 */
> +  UK_ASSERT(POWER_OF_2(count));
>  
> -  br = malloc(sizeof(struct buf_ring) + count*sizeof(caddr_t),
> -      type, flags|M_ZERO);
> +  r = uk_malloc(a, sizeof(struct uk_ring) + count * sizeof(caddr_t));
>  
> -  if (br == NULL)
> +  if (br == NULL) {
> +    uk_pr_err("Could not allocate ring: out of memory\n");

I keep seeing this 'out of memory' addition. I think it's redundant,
what other reason might be there for allocation failure?

>      return NULL;
> +  }
>  
>  #ifdef DEBUG_BUFRING
>    br->br_lock = lock;
> @@ -62,7 +69,7 @@ buf_ring_alloc(int count, struct malloc_type *type, int flags, struct mtx *lock)
>  }
>  
>  void
> -buf_ring_free(struct buf_ring *br, struct malloc_type *type)
> +uk_ring_free(struct uk_alloc *a, struct uk_ring *r)
>  {
> -  free(br, type);
> +  uk_free(a, br);
>  }
> \ No newline at end of file
> 


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 17:50:31 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 17:50:31 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxwPN-0005xu-9i; Tue, 21 Jul 2020 17:50:29 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=NVI3=BA=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jxwPM-0005xp-28
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 17:50:28 +0000
X-Inumbo-ID: a8a331aa-cb7a-11ea-a119-12813bfff9fa
Received: from mx.upb.ro (unknown [141.85.13.200])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id a8a331aa-cb7a-11ea-a119-12813bfff9fa;
 Tue, 21 Jul 2020 17:50:27 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id E2AB0B561CBF;
 Tue, 21 Jul 2020 20:50:25 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id ZTIB9UpRkCQ2; Tue, 21 Jul 2020 20:50:22 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id E7CD2B561C89;
 Tue, 21 Jul 2020 20:50:21 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id uUv2QEG1QHDz; Tue, 21 Jul 2020 20:50:21 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id 47CAAB5617CC;
 Tue, 21 Jul 2020 20:50:21 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH, v2, 05/15] lib/ukring: Remove br_ prefix and
 rename br variable
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
 <20200721153956.13555-6-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <36a48d36-085d-d377-9798-e4ea70a41d28@cs.pub.ro>
Date: Tue, 21 Jul 2020 20:50:21 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200721153956.13555-6-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

I'm not sure it's worth the struggle to rename these variables. It's
fine that you rename the structures and function names since they are
public (although personally I would have chosen to keep the original
name precisely for showing that the code isn't original unikraft code
but imported from freebsd, but there is not precedent for that).

Other than that I don't see other issues here.

Costin

On 7/21/20 6:39 PM, Alexander Jung wrote:
> This commit removes the br_ prefix from within the `uk_ring`
> struct and renames all instances of the br variable to simple r.
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/ukring/include/uk/ring.h | 178 +++++++++++++++++------------------
>  lib/ukring/ring.c            |  18 ++--
>  2 files changed, 98 insertions(+), 98 deletions(-)
> 
> diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
> index e5f5b68..26ac2f8 100644
> --- a/lib/ukring/include/uk/ring.h
> +++ b/lib/ukring/include/uk/ring.h
> @@ -41,19 +41,19 @@
>  #include <uk/arch/atomic.h>
>  
>  struct uk_ring {
> -  volatile uint32_t  br_prod_head;
> -  volatile uint32_t  br_prod_tail;
> -  int                br_prod_size;
> -  int                br_prod_mask;
> -  uint64_t           br_drops;
> -  volatile uint32_t  br_cons_head __aligned(CACHE_LINE_SIZE);
> -  volatile uint32_t  br_cons_tail;
> -  int                br_cons_size;
> -  int                br_cons_mask;
> +  volatile uint32_t  prod_head;
> +  volatile uint32_t  prod_tail;
> +  int                prod_size;
> +  int                prod_mask;
> +  uint64_t           drops;
> +  volatile uint32_t  cons_head __aligned(CACHE_LINE_SIZE);
> +  volatile uint32_t  cons_tail;
> +  int                cons_size;
> +  int                cons_mask;
>  #ifdef DEBUG_BUFRING
> -  struct uk_mutex   *br_lock;
> +  struct uk_mutex   *lock;
>  #endif
> -  void              *br_ring[0] __aligned(CACHE_LINE_SIZE);
> +  void              *ring[0] __aligned(CACHE_LINE_SIZE);
>  };
>  
>  
> @@ -62,7 +62,7 @@ struct uk_ring {
>   *
>   */
>  static __inline int
> -uk_ring_enqueue(struct uk_ring *br, void *buf)
> +uk_ring_enqueue(struct uk_ring *r, void *buf)
>  {
>    uint32_t prod_head, prod_next, cons_tail;
>  
> @@ -71,50 +71,50 @@ uk_ring_enqueue(struct uk_ring *br, void *buf)
>  
>    /*
>     * Note: It is possible to encounter an mbuf that was removed
> -   * via drbr_peek(), and then re-added via drbr_putback() and
> +   * via drpeek(), and then re-added via drputback() and
>     * trigger spurious critical messages.
>     */
> -  for (i = br->br_cons_head; i != br->br_prod_head;
> -       i = ((i + 1) & br->br_cons_mask))
> -    if (br->br_ring[i] == buf)
> +  for (i = r->cons_head; i != r->prod_head;
> +       i = ((i + 1) & r->cons_mask))
> +    if (r->ring[i] == buf)
>        uk_pr_crit("buf=%p already enqueue at %d prod=%d cons=%d\n",
> -          buf, i, br->br_prod_tail, br->br_cons_tail);
> +          buf, i, r->prod_tail, r->cons_tail);
>  #endif
>  
>    ukplat_lcpu_disable_irq();
>  
>    do {
> -    prod_head = br->br_prod_head;
> -    prod_next = (prod_head + 1) & br->br_prod_mask;
> -    cons_tail = br->br_cons_tail;
> +    prod_head = r->prod_head;
> +    prod_next = (prod_head + 1) & r->prod_mask;
> +    cons_tail = r->cons_tail;
>  
>      if (prod_next == cons_tail) {
>        rmb();
> -      if (prod_head == br->br_prod_head && cons_tail == br->br_cons_tail) {
> -        br->br_drops++;
> +      if (prod_head == r->prod_head && cons_tail == r->cons_tail) {
> +        r->drops++;
>          ukplat_lcpu_enable_irq();
>          return ENOBUFS;
>        }
>        continue;
>      }
> -  } while (!ukarch_compare_exchange_sync(&br->br_prod_head, prod_head, prod_next));
> +  } while (!ukarch_compare_exchange_sync(&r->prod_head, prod_head, prod_next));
>  
>  #ifdef DEBUG_BUFRING
> -  if (br->br_ring[prod_head] != NULL)
> +  if (r->ring[prod_head] != NULL)
>      uk_pr_crit("dangling value in enqueue\n");
>  #endif
>  
> -  br->br_ring[prod_head] = buf;
> +  r->ring[prod_head] = buf;
>  
>    /*
>     * If there are other enqueues in progress
>     * that preceded us, we need to wait for them
>     * to complete 
>     */
> -  while (br->br_prod_tail != prod_head)
> +  while (r->prod_tail != prod_head)
>      cpu_spinwait();
>  
> -  ukarch_store_n(&br->br_prod_tail, prod_next);
> +  ukarch_store_n(&r->prod_tail, prod_next);
>    ukplat_lcpu_enable_irq();
>  
>    return 0;
> @@ -125,7 +125,7 @@ uk_ring_enqueue(struct uk_ring *br, void *buf)
>   *
>   */
>  static __inline void *
> -uk_ring_dequeue_mc(struct uk_ring *br)
> +uk_ring_dequeue_mc(struct uk_ring *r)
>  {
>    uint32_t cons_head, cons_next;
>    void *buf;
> @@ -133,19 +133,19 @@ uk_ring_dequeue_mc(struct uk_ring *br)
>    ukplat_lcpu_disable_irq();
>  
>    do {
> -    cons_head = br->br_cons_head;
> -    cons_next = (cons_head + 1) & br->br_cons_mask;
> +    cons_head = r->cons_head;
> +    cons_next = (cons_head + 1) & r->cons_mask;
>  
> -    if (cons_head == br->br_prod_tail) {
> +    if (cons_head == r->prod_tail) {
>        ukplat_lcpu_enable_irq();
>        return NULL;
>      }
> -  } while (!ukarch_compare_exchange_sync(&br->br_cons_head, cons_head, cons_next));
> +  } while (!ukarch_compare_exchange_sync(&r->cons_head, cons_head, cons_next));
>  
> -  buf = br->br_ring[cons_head];
> +  buf = r->ring[cons_head];
>  
>  #ifdef DEBUG_BUFRING
> -  br->br_ring[cons_head] = NULL;
> +  r->ring[cons_head] = NULL;
>  #endif
>  
>    /*
> @@ -153,10 +153,10 @@ uk_ring_dequeue_mc(struct uk_ring *br)
>     * that preceded us, we need to wait for them
>     * to complete
>     */
> -  while (br->br_cons_tail != cons_head)
> +  while (r->cons_tail != cons_head)
>      cpu_spinwait();
>  
> -  ukarch_store_n(&br->br_cons_tail, cons_next);
> +  ukarch_store_n(&r->cons_tail, cons_next);
>    ukplat_lcpu_enable_irq();
>  
>    return buf;
> @@ -168,7 +168,7 @@ uk_ring_dequeue_mc(struct uk_ring *br)
>   * e.g. a network driver's tx queue lock
>   */
>  static __inline void *
> -uk_ring_dequeue_sc(struct uk_ring *br)
> +uk_ring_dequeue_sc(struct uk_ring *r)
>  {
>    uint32_t cons_head, cons_next;
>  #ifdef PREFETCH_DEFINED
> @@ -180,7 +180,7 @@ uk_ring_dequeue_sc(struct uk_ring *br)
>    /*
>     * This is a workaround to allow using uk_ring on ARM and ARM64.
>     * ARM64TODO: Fix uk_ring in a generic way.
> -   * REMARKS: It is suspected that br_cons_head does not require
> +   * REMARKS: It is suspected that cons_head does not require
>     *   load_acq operation, but this change was extensively tested
>     *   and confirmed it's working. To be reviewed once again in
>     *   FreeBSD-12.
> @@ -189,32 +189,32 @@ uk_ring_dequeue_sc(struct uk_ring *br)
>     * Core(0) - uk_ring_enqueue()                                       Core(1) - uk_ring_dequeue_sc()
>     * -----------------------------------------                                       ----------------------------------------------
>     *
> -   *                                                                                cons_head = br->br_cons_head;
> -   * atomic_cmpset_acq_32(&br->br_prod_head, ...));
> -   *                                                                                buf = br->br_ring[cons_head];     <see <1>>
> -   * br->br_ring[prod_head] = buf;
> -   * atomic_store_rel_32(&br->br_prod_tail, ...);
> -   *                                                                                prod_tail = br->br_prod_tail;
> +   *                                                                                cons_head = r->cons_head;
> +   * atomic_cmpset_acq_32(&r->prod_head, ...));
> +   *                                                                                buf = r->ring[cons_head];     <see <1>>
> +   * r->ring[prod_head] = buf;
> +   * atomic_store_rel_32(&r->prod_tail, ...);
> +   *                                                                                prod_tail = r->prod_tail;
>     *                                                                                if (cons_head == prod_tail) 
>     *                                                                                        return (NULL);
>     *                                                                                <condition is false and code uses invalid(old) buf>`  
>     *
> -   * <1> Load (on core 1) from br->br_ring[cons_head] can be reordered (speculative readed) by CPU.
> +   * <1> Load (on core 1) from r->ring[cons_head] can be reordered (speculative readed) by CPU.
>     */
>  #if defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64)
>    /* TODO: Provide atomic_load_acq_32() */
> -  /* cons_head = atomic_load_acq_32(&br->br_cons_head); */
> -  cons_head = &br->br_cons_head;
> +  /* cons_head = atomic_load_acq_32(&r->cons_head); */
> +  cons_head = &r->cons_head;
>  #else
> -  cons_head = br->br_cons_head;
> +  cons_head = r->cons_head;
>  #endif
>    /* TODO: Provide atomic_load_acq_32() */
> -  /* prod_tail = atomic_load_acq_32(&br->br_prod_tail); */
> -  prod_tail = &br->br_prod_tail;
> +  /* prod_tail = atomic_load_acq_32(&r->prod_tail); */
> +  prod_tail = &r->prod_tail;
>  
> -  cons_next = (cons_head + 1) & br->br_cons_mask;
> +  cons_next = (cons_head + 1) & r->cons_mask;
>  #ifdef PREFETCH_DEFINED
> -  cons_next_next = (cons_head + 2) & br->br_cons_mask;
> +  cons_next_next = (cons_head + 2) & r->cons_mask;
>  #endif
>  
>    if (cons_head == prod_tail)
> @@ -222,27 +222,27 @@ uk_ring_dequeue_sc(struct uk_ring *br)
>  
>  #ifdef PREFETCH_DEFINED
>    if (cons_next != prod_tail) {
> -    prefetch(br->br_ring[cons_next]);
> +    prefetch(r->ring[cons_next]);
>      if (cons_next_next != prod_tail)
> -      prefetch(br->br_ring[cons_next_next]);
> +      prefetch(r->ring[cons_next_next]);
>    }
>  #endif
>  
> -  br->br_cons_head = cons_next;
> -  buf = br->br_ring[cons_head];
> +  r->cons_head = cons_next;
> +  buf = r->ring[cons_head];
>  
>  #ifdef DEBUG_BUFRING
> -  br->br_ring[cons_head] = NULL;
> +  r->ring[cons_head] = NULL;
>  
>    if (!uk_mutex_is_locked(r->lock))
>      uk_pr_crit("lock not held on single consumer dequeue\n");
>  
> -  if (br->br_cons_tail != cons_head)
> +  if (r->cons_tail != cons_head)
>      uk_pr_crit("inconsistent list cons_tail=%d cons_head=%d\n",
> -        br->br_cons_tail, cons_head);
> +        r->cons_tail, cons_head);
>  #endif
>  
> -  br->br_cons_tail = cons_next;
> +  r->cons_tail = cons_next;
>    return buf;
>  }
>  
> @@ -252,25 +252,25 @@ uk_ring_dequeue_sc(struct uk_ring *br)
>   * e.g. a network driver's tx queue lock
>   */
>  static __inline void
> -uk_ring_advance_sc(struct uk_ring *br)
> +uk_ring_advance_sc(struct uk_ring *r)
>  {
>    uint32_t cons_head, cons_next;
>    uint32_t prod_tail;
>  
> -  cons_head = br->br_cons_head;
> -  prod_tail = br->br_prod_tail;
> -  cons_next = (cons_head + 1) & br->br_cons_mask;
> +  cons_head = r->cons_head;
> +  prod_tail = r->prod_tail;
> +  cons_next = (cons_head + 1) & r->cons_mask;
>  
>    if (cons_head == prod_tail)
>      return;
>  
> -  br->br_cons_head = cons_next;
> +  r->cons_head = cons_next;
>  
>  #ifdef DEBUG_BUFRING
> -  br->br_ring[cons_head] = NULL;
> +  r->ring[cons_head] = NULL;
>  #endif
>  
> -  br->br_cons_tail = cons_next;
> +  r->cons_tail = cons_next;
>  }
>  
>  /*
> @@ -290,11 +290,11 @@ uk_ring_advance_sc(struct uk_ring *br)
>   * the compare and an atomic.
>   */
>  static __inline void
> -uk_ring_putback_sc(struct uk_ring *br, void *new)
> +uk_ring_putback_sc(struct uk_ring *r, void *new)
>  {
>    /* Buffer ring has none in putback */
> -  UK_ASSERT(br->br_cons_head != br->br_prod_tail);
> -  br->br_ring[br->br_cons_head] = new;
> +  UK_ASSERT(r->cons_head != r->prod_tail);
> +  r->ring[r->cons_head] = new;
>  }
>  
>  /*
> @@ -303,7 +303,7 @@ uk_ring_putback_sc(struct uk_ring *br, void *new)
>   * race-prone if not protected by a lock
>   */
>  static __inline void *
> -uk_ring_peek(struct uk_ring *br)
> +uk_ring_peek(struct uk_ring *r)
>  {
>  #ifdef DEBUG_BUFRING
>    if ((r->lock != NULL) && !uk_mutex_is_locked(r->lock))
> @@ -316,14 +316,14 @@ uk_ring_peek(struct uk_ring *br)
>     * a lagging indicator so we worst case we might
>     * return NULL immediately after a buffer has been enqueued
>     */
> -  if (br->br_cons_head == br->br_prod_tail)
> +  if (r->cons_head == r->prod_tail)
>      return NULL;
>  
> -  return br->br_ring[br->br_cons_head];
> +  return r->ring[r->cons_head];
>  }
>  
>  static __inline void *
> -uk_ring_peek_clear_sc(struct uk_ring *br)
> +uk_ring_peek_clear_sc(struct uk_ring *r)
>  {
>  #ifdef DEBUG_BUFRING
>    void *ret;
> @@ -332,17 +332,17 @@ uk_ring_peek_clear_sc(struct uk_ring *br)
>      uk_pr_crit("lock not held on single consumer dequeue\n");
>  #endif
>  
> -  if (br->br_cons_head == br->br_prod_tail)
> +  if (r->cons_head == r->prod_tail)
>      return NULL;
>  
>  #if defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64)
>    /*
>     * The barrier is required there on ARM and ARM64 to ensure, that
> -   * br->br_ring[br->br_cons_head] will not be fetched before the above
> +   * r->ring[r->cons_head] will not be fetched before the above
>     * condition is checked.
>     * Without the barrier, it is possible, that buffer will be fetched
> -   * before the enqueue will put mbuf into br, then, in the meantime, the
> -   * enqueue will update the array and the br_prod_tail, and the
> +   * before the enqueue will put mbuf into r, then, in the meantime, the
> +   * enqueue will update the array and the prod_tail, and the
>     * conditional check will be true, so we will return previously fetched
>     * (and invalid) buffer.
>     */
> @@ -355,36 +355,36 @@ uk_ring_peek_clear_sc(struct uk_ring *br)
>     * Single consumer, i.e. cons_head will not move while we are
>     * running, so atomic_swap_ptr() is not necessary here.
>     */
> -  ret = br->br_ring[br->br_cons_head];
> -  br->br_ring[br->br_cons_head] = NULL;
> +  ret = r->ring[r->cons_head];
> +  r->ring[r->cons_head] = NULL;
>  
>    return ret;
>  #else
> -  return br->br_ring[br->br_cons_head];
> +  return r->ring[r->cons_head];
>  #endif
>  }
>  
>  static __inline int
> -uk_ring_full(struct uk_ring *br)
> +uk_ring_full(struct uk_ring *r)
>  {
> -  return ((br->br_prod_head + 1) & br->br_prod_mask) == br->br_cons_tail;
> +  return ((r->prod_head + 1) & r->prod_mask) == r->cons_tail;
>  }
>  
>  static __inline int
> -uk_ring_empty(struct uk_ring *br)
> +uk_ring_empty(struct uk_ring *r)
>  {
> -  return br->br_cons_head == br->br_prod_tail;
> +  return r->cons_head == r->prod_tail;
>  }
>  
>  static __inline int
> -uk_ring_count(struct uk_ring *br)
> +uk_ring_count(struct uk_ring *r)
>  {
> -  return (br->br_prod_size + br->br_prod_tail - br->br_cons_tail)
> -      & br->br_prod_mask;
> +  return (r->prod_size + r->prod_tail - r->cons_tail)
> +      & r->prod_mask;
>  }
>  
>  struct uk_ring *uk_ring_alloc(struct uk_alloc *a, int count, int flags,
>      struct uk_mutex *);
> -void uk_ring_free(struct uk_alloc *a, struct uk_ring *br);
> +void uk_ring_free(struct uk_alloc *a, struct uk_ring *r);
>  
>  #endif
> \ No newline at end of file
> diff --git a/lib/ukring/ring.c b/lib/ukring/ring.c
> index 658130e..1431cb9 100644
> --- a/lib/ukring/ring.c
> +++ b/lib/ukring/ring.c
> @@ -41,7 +41,7 @@
>  struct uk_ring *
>  uk_ring_alloc(struct uk_alloc *a, int count, int flags, struct uk_mutex *lock)
>  {
> -  struct uk_ring *br;
> +  struct uk_ring *r;
>  
>    if (a == NULL)
>      a = uk_alloc_get_default();
> @@ -51,25 +51,25 @@ uk_ring_alloc(struct uk_alloc *a, int count, int flags, struct uk_mutex *lock)
>  
>    r = uk_malloc(a, sizeof(struct uk_ring) + count * sizeof(caddr_t));
>  
> -  if (br == NULL) {
> +  if (r == NULL) {
>      uk_pr_err("Could not allocate ring: out of memory\n");
>      return NULL;
>    }
>  
>  #ifdef DEBUG_BUFRING
> -  br->br_lock = lock;
> +  r->lock = lock;
>  #endif
>  
> -  br->br_prod_size = br->br_cons_size = count;
> -  br->br_prod_mask = br->br_cons_mask = count - 1;
> -  br->br_prod_head = br->br_cons_head = 0;
> -  br->br_prod_tail = br->br_cons_tail = 0;
> +  r->prod_size = r->cons_size = count;
> +  r->prod_mask = r->cons_mask = count - 1;
> +  r->prod_head = r->cons_head = 0;
> +  r->prod_tail = r->cons_tail = 0;
>  
> -  return br;
> +  return r;
>  }
>  
>  void
>  uk_ring_free(struct uk_alloc *a, struct uk_ring *r)
>  {
> -  uk_free(a, br);
> +  uk_free(a, r);
>  }
> \ No newline at end of file
> 


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 17:56:35 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 17:56:35 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxwVE-00064q-Pu; Tue, 21 Jul 2020 17:56:32 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=NVI3=BA=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jxwVD-00064l-D2
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 17:56:31 +0000
X-Inumbo-ID: 801adf5c-cb7b-11ea-858d-bc764e2007e4
Received: from mx.upb.ro (unknown [141.85.13.210])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 801adf5c-cb7b-11ea-858d-bc764e2007e4;
 Tue, 21 Jul 2020 17:56:28 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 4DFC3B561CBF;
 Tue, 21 Jul 2020 20:56:26 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id 0auJejKa3cEC; Tue, 21 Jul 2020 20:56:24 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 691A2B561C89;
 Tue, 21 Jul 2020 20:56:24 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id bBAWtBHBBW86; Tue, 21 Jul 2020 20:56:24 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id C4D91B5617CC;
 Tue, 21 Jul 2020 20:56:23 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH, v2, 06/15] lib/ukring: Disable use of
 cpu_spinwait function
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
 <20200721153956.13555-7-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <1c789309-7d53-c774-b8f6-1f95e7b9ece0@cs.pub.ro>
Date: Tue, 21 Jul 2020 20:56:23 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200721153956.13555-7-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

Please see inline.

On 7/21/20 6:39 PM, Alexander Jung wrote:
> This is not currently supported by Unikraft.
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/ukring/include/uk/ring.h | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
> index 26ac2f8..f19b13e 100644
> --- a/lib/ukring/include/uk/ring.h
> +++ b/lib/ukring/include/uk/ring.h
> @@ -111,8 +111,11 @@ uk_ring_enqueue(struct uk_ring *r, void *buf)
>     * that preceded us, we need to wait for them
>     * to complete 
>     */
> +   /* TODO: Provide cpu_spinwait() */
> +#if 0
>    while (r->prod_tail != prod_head)
>      cpu_spinwait();

Actually waiting for some new ring entry by busy-waiting it's an
important feature of buffer rings shared between different execution
abstractions. So we should keep this and introduce something similar to
cpu_spinwait(). On FreeBSD it actually calls the x86 PAUSE instruction
which is smarter way of busy-waiting.

> +#endif
>  
>    ukarch_store_n(&r->prod_tail, prod_next);
>    ukplat_lcpu_enable_irq();
> @@ -153,8 +156,11 @@ uk_ring_dequeue_mc(struct uk_ring *r)
>     * that preceded us, we need to wait for them
>     * to complete
>     */
> +   /* TODO: Provide cpu_spinwait() */
> +#if 0
>    while (r->cons_tail != cons_head)
>      cpu_spinwait();
> +#endif
>  
>    ukarch_store_n(&r->cons_tail, cons_next);
>    ukplat_lcpu_enable_irq();
> 


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 18:01:17 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 18:01:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxwZp-0006tQ-2n; Tue, 21 Jul 2020 18:01:17 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=NVI3=BA=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jxwZn-0006su-OM
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 18:01:15 +0000
X-Inumbo-ID: 2aa4e756-cb7c-11ea-a11c-12813bfff9fa
Received: from mx.upb.ro (unknown [141.85.13.250])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 2aa4e756-cb7c-11ea-a11c-12813bfff9fa;
 Tue, 21 Jul 2020 18:01:14 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id C0E79B561CBF;
 Tue, 21 Jul 2020 21:01:13 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id H_Yc4hQMXwI6; Tue, 21 Jul 2020 21:01:11 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id A4642B561C89;
 Tue, 21 Jul 2020 21:01:11 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id X9OE-kr7tb3O; Tue, 21 Jul 2020 21:01:11 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id 03E3DB5617CC;
 Tue, 21 Jul 2020 21:01:10 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH, v2, 07/15] lib/ukring: Rename single and
 multiple consumer functions
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
 <20200721153956.13555-8-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <996604e7-9ea9-a7be-f160-be06b3087d90@cs.pub.ro>
Date: Tue, 21 Jul 2020 21:01:10 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200721153956.13555-8-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

Let's just keep the original suffixes because they are more suggestive.
Besides, single and multiple variants are used for different purposes,
so I don't think we should encourage a variant over the other. For
example, the shared IO rings used on Xen between drivers backends and
frontends are all single consumer. It's common case when communicating
via shared memory on kernel level.

So we can simply drop this patch altogether.

Cheers,
Costin

On 7/21/20 6:39 PM, Alexander Jung wrote:
> This commit renames the _sc suffix to _single on functions which
> are intended for use by a single bufffer ring consumer.
> Additionally, removing the _mc suffix from uk_ring_enqueue to
> encourage it as the default operation for removing items from
> a ring buffer.
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/ukring/include/uk/ring.h | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
> index f19b13e..1cc8982 100644
> --- a/lib/ukring/include/uk/ring.h
> +++ b/lib/ukring/include/uk/ring.h
> @@ -128,7 +128,7 @@ uk_ring_enqueue(struct uk_ring *r, void *buf)
>   *
>   */
>  static __inline void *
> -uk_ring_dequeue_mc(struct uk_ring *r)
> +uk_ring_dequeue(struct uk_ring *r)
>  {
>    uint32_t cons_head, cons_next;
>    void *buf;
> @@ -174,7 +174,7 @@ uk_ring_dequeue_mc(struct uk_ring *r)
>   * e.g. a network driver's tx queue lock
>   */
>  static __inline void *
> -uk_ring_dequeue_sc(struct uk_ring *r)
> +uk_ring_dequeue_single(struct uk_ring *r)
>  {
>    uint32_t cons_head, cons_next;
>  #ifdef PREFETCH_DEFINED
> @@ -192,7 +192,7 @@ uk_ring_dequeue_sc(struct uk_ring *r)
>     *   FreeBSD-12.
>     *
>     * Preventing following situation:
> -   * Core(0) - uk_ring_enqueue()                                       Core(1) - uk_ring_dequeue_sc()
> +   * Core(0) - uk_ring_enqueue()                                       Core(1) - uk_ring_dequeue_single()
>     * -----------------------------------------                                       ----------------------------------------------
>     *
>     *                                                                                cons_head = r->cons_head;
> @@ -258,7 +258,7 @@ uk_ring_dequeue_sc(struct uk_ring *r)
>   * e.g. a network driver's tx queue lock
>   */
>  static __inline void
> -uk_ring_advance_sc(struct uk_ring *r)
> +uk_ring_advance_single(struct uk_ring *r)
>  {
>    uint32_t cons_head, cons_next;
>    uint32_t prod_tail;
> @@ -296,7 +296,7 @@ uk_ring_advance_sc(struct uk_ring *r)
>   * the compare and an atomic.
>   */
>  static __inline void
> -uk_ring_putback_sc(struct uk_ring *r, void *new)
> +uk_ring_putback_single(struct uk_ring *r, void *new)
>  {
>    /* Buffer ring has none in putback */
>    UK_ASSERT(r->cons_head != r->prod_tail);
> @@ -329,7 +329,7 @@ uk_ring_peek(struct uk_ring *r)
>  }
>  
>  static __inline void *
> -uk_ring_peek_clear_sc(struct uk_ring *r)
> +uk_ring_peek_clear_single(struct uk_ring *r)
>  {
>  #ifdef DEBUG_BUFRING
>    void *ret;
> 


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 18:10:59 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 18:10:59 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxwjA-0007iF-P0; Tue, 21 Jul 2020 18:10:56 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=NVI3=BA=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jxwj9-0007iA-JS
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 18:10:55 +0000
X-Inumbo-ID: 831213d7-cb7d-11ea-859a-bc764e2007e4
Received: from mx.upb.ro (unknown [141.85.13.250])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 831213d7-cb7d-11ea-859a-bc764e2007e4;
 Tue, 21 Jul 2020 18:10:53 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 5D454B561CBF;
 Tue, 21 Jul 2020 21:10:52 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id e4gjlx0QAYVq; Tue, 21 Jul 2020 21:10:50 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 10263B561C89;
 Tue, 21 Jul 2020 21:10:50 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id D5QAx35O1GxL; Tue, 21 Jul 2020 21:10:49 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id 4FE46B5617CC;
 Tue, 21 Jul 2020 21:10:49 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH, v2, 08/15] lib/ukring: Use Unikraft to enable
 ring buffer debugging
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
 <20200721153956.13555-9-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <83539dcb-7ad1-218a-29ed-11f654f7640c@cs.pub.ro>
Date: Tue, 21 Jul 2020 21:10:49 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200721153956.13555-9-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

I thought about this and I think it would be better to keep
DEBUG_BUFRING. Btw, this is used to debug the buffer ring and it will be
extremely rare enabled when debugging. Besides, it has nothing to do
with the debug printing, there is no debug printing here.

So we can simply drop this patch altogether.

Cheers,
Costin

On 7/21/20 6:39 PM, Alexander Jung wrote:
> This commit uses the flags set from ukdebug to determine whether
> to output critical messages from the ring buffer's debug
> sequences.
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/ukring/include/uk/ring.h | 18 +++++++++---------
>  lib/ukring/ring.c            |  2 +-
>  2 files changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
> index 1cc8982..01adaf3 100644
> --- a/lib/ukring/include/uk/ring.h
> +++ b/lib/ukring/include/uk/ring.h
> @@ -50,7 +50,7 @@ struct uk_ring {
>    volatile uint32_t  cons_tail;
>    int                cons_size;
>    int                cons_mask;
> -#ifdef DEBUG_BUFRING
> +#ifdef CONFIG_LIBUKDEBUG
>    struct uk_mutex   *lock;
>  #endif
>    void              *ring[0] __aligned(CACHE_LINE_SIZE);
> @@ -66,7 +66,7 @@ uk_ring_enqueue(struct uk_ring *r, void *buf)
>  {
>    uint32_t prod_head, prod_next, cons_tail;
>  
> -#ifdef DEBUG_BUFRING
> +#ifdef CONFIG_LIBUKDEBUG_PRINTK_CRIT
>    int i;
>  
>    /*
> @@ -99,7 +99,7 @@ uk_ring_enqueue(struct uk_ring *r, void *buf)
>      }
>    } while (!ukarch_compare_exchange_sync(&r->prod_head, prod_head, prod_next));
>  
> -#ifdef DEBUG_BUFRING
> +#ifdef CONFIG_LIBUKDEBUG_PRINTK_CRIT
>    if (r->ring[prod_head] != NULL)
>      uk_pr_crit("dangling value in enqueue\n");
>  #endif
> @@ -147,7 +147,7 @@ uk_ring_dequeue(struct uk_ring *r)
>  
>    buf = r->ring[cons_head];
>  
> -#ifdef DEBUG_BUFRING
> +#ifdef CONFIG_LIBUKDEBUG
>    r->ring[cons_head] = NULL;
>  #endif
>  
> @@ -237,7 +237,7 @@ uk_ring_dequeue_single(struct uk_ring *r)
>    r->cons_head = cons_next;
>    buf = r->ring[cons_head];
>  
> -#ifdef DEBUG_BUFRING
> +#ifdef CONFIG_LIBUKDEBUG_PRINTK_CRIT
>    r->ring[cons_head] = NULL;
>  
>    if (!uk_mutex_is_locked(r->lock))
> @@ -272,7 +272,7 @@ uk_ring_advance_single(struct uk_ring *r)
>  
>    r->cons_head = cons_next;
>  
> -#ifdef DEBUG_BUFRING
> +#ifdef CONFIG_LIBUKDEBUG
>    r->ring[cons_head] = NULL;
>  #endif
>  
> @@ -311,7 +311,7 @@ uk_ring_putback_single(struct uk_ring *r, void *new)
>  static __inline void *
>  uk_ring_peek(struct uk_ring *r)
>  {
> -#ifdef DEBUG_BUFRING
> +#ifdef CONFIG_LIBUKDEBUG_PRINTK_CRIT
>    if ((r->lock != NULL) && !uk_mutex_is_locked(r->lock))
>      uk_pr_crit("lock not held on single consumer dequeue\n");
>  #endif
> @@ -331,7 +331,7 @@ uk_ring_peek(struct uk_ring *r)
>  static __inline void *
>  uk_ring_peek_clear_single(struct uk_ring *r)
>  {
> -#ifdef DEBUG_BUFRING
> +#ifdef CONFIG_LIBUKDEBUG_PRINTK_CRIT
>    void *ret;
>  
>    if (!uk_mutex_is_locked(r->lock))
> @@ -356,7 +356,7 @@ uk_ring_peek_clear_single(struct uk_ring *r)
>    /* atomic_thread_fence_acq(); */
>  #endif
>  
> -#ifdef DEBUG_BUFRING
> +#ifdef CONFIG_LIBUKDEBUG
>    /*
>     * Single consumer, i.e. cons_head will not move while we are
>     * running, so atomic_swap_ptr() is not necessary here.
> diff --git a/lib/ukring/ring.c b/lib/ukring/ring.c
> index 1431cb9..db5600f 100644
> --- a/lib/ukring/ring.c
> +++ b/lib/ukring/ring.c
> @@ -56,7 +56,7 @@ uk_ring_alloc(struct uk_alloc *a, int count, int flags, struct uk_mutex *lock)
>      return NULL;
>    }
>  
> -#ifdef DEBUG_BUFRING
> +#ifdef CONFIG_LIBUKDEBUG
>    r->lock = lock;
>  #endif
>  
> 


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 18:12:40 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 18:12:40 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxwkp-0007ku-VI; Tue, 21 Jul 2020 18:12:39 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=NVI3=BA=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jxwko-0007kp-V3
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 18:12:38 +0000
X-Inumbo-ID: c0f1df07-cb7d-11ea-859a-bc764e2007e4
Received: from mx.upb.ro (unknown [141.85.13.200])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id c0f1df07-cb7d-11ea-859a-bc764e2007e4;
 Tue, 21 Jul 2020 18:12:37 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 35338B561CCE;
 Tue, 21 Jul 2020 21:12:36 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id 8g9VrBwaMLvA; Tue, 21 Jul 2020 21:12:33 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 5C750B561C89;
 Tue, 21 Jul 2020 21:12:33 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id yrJ3WTeVlJin; Tue, 21 Jul 2020 21:12:33 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id BA0E9B5617CC;
 Tue, 21 Jul 2020 21:12:32 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH, v2, 09/15] lib/ukring: Remove unsupported cache
 line size
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
 <20200721153956.13555-10-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <891131c6-523f-7627-1494-b29d8374f79a@cs.pub.ro>
Date: Tue, 21 Jul 2020 21:12:32 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200721153956.13555-10-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

Please see inline.

On 7/21/20 6:39 PM, Alexander Jung wrote:
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/ukring/include/uk/ring.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
> index 01adaf3..e1a0387 100644
> --- a/lib/ukring/include/uk/ring.h
> +++ b/lib/ukring/include/uk/ring.h
> @@ -46,14 +46,14 @@ struct uk_ring {
>    int                prod_size;
>    int                prod_mask;
>    uint64_t           drops;
> -  volatile uint32_t  cons_head __aligned(CACHE_LINE_SIZE);
> +  volatile uint32_t  cons_head;

Actually we need this since ring buffers are very performance sensitive.
You should define the arch dependent CACHE_LINE_SIZE.

>    volatile uint32_t  cons_tail;
>    int                cons_size;
>    int                cons_mask;
>  #ifdef CONFIG_LIBUKDEBUG
>    struct uk_mutex   *lock;
>  #endif
> -  void              *ring[0] __aligned(CACHE_LINE_SIZE);
> +  void              *ring[0];
>  };
>  
>  
> 


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 18:16:45 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 18:16:45 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxwom-0007r8-I1; Tue, 21 Jul 2020 18:16:44 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=NVI3=BA=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jxwol-0007qq-2J
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 18:16:43 +0000
X-Inumbo-ID: 531f881c-cb7e-11ea-859b-bc764e2007e4
Received: from mx.upb.ro (unknown [141.85.13.200])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 531f881c-cb7e-11ea-859b-bc764e2007e4;
 Tue, 21 Jul 2020 18:16:42 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 4505EB561CBF;
 Tue, 21 Jul 2020 21:16:41 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id 6gyop3pLT7AE; Tue, 21 Jul 2020 21:16:36 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id C03DFB561C89;
 Tue, 21 Jul 2020 21:16:36 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id E_lZhFveJ0zI; Tue, 21 Jul 2020 21:16:36 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id 1C3A3B5617CC;
 Tue, 21 Jul 2020 21:16:36 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH, v2, 11/15] lib/ukring: Properly commment
 {ring.c, ring.h}
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
 <20200721153956.13555-12-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <2c3ac6d7-7836-9636-c57a-f55659c82185@cs.pub.ro>
Date: Tue, 21 Jul 2020 21:16:35 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200721153956.13555-12-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

Please see inline.

On 7/21/20 6:39 PM, Alexander Jung wrote:
> This commit updates the SPDX header, adds additional authorship,
> and properly comments all functions and inlines.
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/ukring/include/uk/ring.h | 257 +++++++++++++++++++++++------------
>  lib/ukring/ring.c            |  19 ++-
>  2 files changed, 184 insertions(+), 92 deletions(-)
> 
> diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
> index b51a11a..49f9dfe 100644
> --- a/lib/ukring/include/uk/ring.h
> +++ b/lib/ukring/include/uk/ring.h
> @@ -1,12 +1,16 @@
> -/*-
> - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
> +/* SPDX-License-Identifier: BSD-2-Clause-FreeBSD */
> +/*
> + * Authors: Kip Macy <kmacy@freebsd.org>
> + *          Alexander Jung <alexander.jung@neclab.eu>
>   *
> - * Copyright (c) 2007-2009 Kip Macy <kmacy@freebsd.org>
> - * All rights reserved.
> + * Copyright (c) 2007-2009, Kip Macy <kmacy@freebsd.org>
> + *               2020, NEC Laboratories Europe GmbH, NEC Corporation.
> + *               All rights reserved.
>   *
>   * Redistribution and use in source and binary forms, with or without
>   * modification, are permitted provided that the following conditions
>   * are met:
> + *
>   * 1. Redistributions of source code must retain the above copyright
>   *    notice, this list of conditions and the following disclaimer.
>   * 2. Redistributions in binary form must reproduce the above copyright
> @@ -26,7 +30,11 @@
>   * SUCH DAMAGE.
>   *
>   * $FreeBSD$
> + */
> +/*
> + * Simple ring implementation to handle object references.
>   *
> + * Inspired by FreeBSD and modified (commit-id: c45cce1).
>   */

I think we should keep the original comments just as they were. We need
only the license and header changes (the changes above), but the changes
bellow we should revert. Remember we should keep the changes to a minimum.

>  
>  #ifndef __UK_RING_H__
> @@ -40,6 +48,7 @@
>  #include <uk/plat/lcpu.h>
>  #include <uk/arch/atomic.h>
>  
> +
>  struct uk_ring {
>    volatile uint32_t  prod_head;
>    volatile uint32_t  prod_tail;
> @@ -52,14 +61,18 @@ struct uk_ring {
>    int                cons_mask;
>  #ifdef CONFIG_LIBUKDEBUG
>    struct uk_mutex   *lock;
> -#endif
> +#endif /* CONFIG_LIBUKDEBUG */
>    void              *ring[0];
>  };
>  
>  
> -/*
> - * multi-producer safe lock-free ring buffer enqueue
> +/**
> + * Multi-producer safe lock-free ring buffer enqueue.
>   *
> + * @param br
> + *  Reference to the ring structure.
> + * @param buf
> + *  Buffer size for the ring.
>   */
>  static __inline int
>  uk_ring_enqueue(struct uk_ring *r, void *buf)
> @@ -70,16 +83,15 @@ uk_ring_enqueue(struct uk_ring *r, void *buf)
>    int i;
>  
>    /*
> -   * Note: It is possible to encounter an mbuf that was removed
> -   * via drpeek(), and then re-added via drputback() and
> -   * trigger spurious critical messages.
> +   * Note: It is possible to encounter an mbuf that was removed via drpeek(),
> +   * and then re-added via drputback() and trigger a spurious panic.
>     */
>    for (i = r->cons_head; i != r->prod_head;
>         i = ((i + 1) & r->cons_mask))
>      if (r->ring[i] == buf)
>        uk_pr_crit("buf=%p already enqueue at %d prod=%d cons=%d\n",
>            buf, i, r->prod_tail, r->cons_tail);
> -#endif
> +#endif /* CONFIG_LIBUKDEBUG_PRINTK_CRIT */
>  
>    ukplat_lcpu_disable_irq();
>  
> @@ -102,20 +114,19 @@ uk_ring_enqueue(struct uk_ring *r, void *buf)
>  #ifdef CONFIG_LIBUKDEBUG_PRINTK_CRIT
>    if (r->ring[prod_head] != NULL)
>      uk_pr_crit("dangling value in enqueue\n");
> -#endif
> +#endif /* CONFIG_LIBUKDEBUG_PRINTK_CRIT */
>  
>    r->ring[prod_head] = buf;
>  
>    /*
> -   * If there are other enqueues in progress
> -   * that preceded us, we need to wait for them
> -   * to complete 
> +   * If there are other enqueues in progress that preceded us, we need to wait
> +   * for them to complete.
>     */
>     /* TODO: Provide cpu_spinwait() */
>  #if 0
>    while (r->prod_tail != prod_head)
>      cpu_spinwait();
> -#endif
> +#endif /* 0 */
>  
>    ukarch_store_n(&r->prod_tail, prod_next);
>    ukplat_lcpu_enable_irq();
> @@ -123,9 +134,12 @@ uk_ring_enqueue(struct uk_ring *r, void *buf)
>    return 0;
>  }
>  
> -/*
> - * multi-consumer safe dequeue 
> +
> +/**
> + * Multi-consumer safe dequeue.
>   *
> + * @param br
> + *  Reference to the ring structure.
>   */
>  static __inline void *
>  uk_ring_dequeue(struct uk_ring *r)
> @@ -149,18 +163,17 @@ uk_ring_dequeue(struct uk_ring *r)
>  
>  #ifdef CONFIG_LIBUKDEBUG
>    r->ring[cons_head] = NULL;
> -#endif
> +#endif /* CONFIG_LIBUKDEBUG */
>  
>    /*
> -   * If there are other dequeues in progress
> -   * that preceded us, we need to wait for them
> -   * to complete
> +   * If there are other dequeues in progress that preceded us, we need to wait
> +   * for them to complete.
>     */
>     /* TODO: Provide cpu_spinwait() */
>  #if 0
>    while (r->cons_tail != cons_head)
>      cpu_spinwait();
> -#endif
> +#endif /* 0 */
>  
>    ukarch_store_n(&r->cons_tail, cons_next);
>    ukplat_lcpu_enable_irq();
> @@ -168,10 +181,13 @@ uk_ring_dequeue(struct uk_ring *r)
>    return buf;
>  }
>  
> -/*
> - * single-consumer dequeue 
> - * use where dequeue is protected by a lock
> - * e.g. a network driver's tx queue lock
> +
> +/**
> + * Single-consumer dequeue use where dequeue is protected by a lock e.g. a
> + * network driver's tx queue lock.
> + *
> + * @param br
> + *  Reference to the ring structure.
>   */
>  static __inline void *
>  uk_ring_dequeue_single(struct uk_ring *r)
> @@ -180,41 +196,49 @@ uk_ring_dequeue_single(struct uk_ring *r)
>    /* TODO: Support CPU prefetchhing. */
>  #if 0
>    uint32_t cons_next_next;
> -#endif
> +#endif /* 0 */
>    uint32_t prod_tail;
>    void *buf;
>  
>    /*
>     * This is a workaround to allow using uk_ring on ARM and ARM64.
> +   *
>     * ARM64TODO: Fix uk_ring in a generic way.
> +   *
>     * REMARKS: It is suspected that cons_head does not require
>     *   load_acq operation, but this change was extensively tested
>     *   and confirmed it's working. To be reviewed once again in
>     *   FreeBSD-12.
>     *
>     * Preventing following situation:
> -   * Core(0) - uk_ring_enqueue()                                       Core(1) - uk_ring_dequeue_single()
> -   * -----------------------------------------                                       ----------------------------------------------
>     *
> -   *                                                                                cons_head = r->cons_head;
> -   * atomic_cmpset_acq_32(&r->prod_head, ...));
> -   *                                                                                buf = r->ring[cons_head];     <see <1>>
> -   * r->ring[prod_head] = buf;
> -   * atomic_store_rel_32(&r->prod_tail, ...);
> -   *                                                                                prod_tail = r->prod_tail;
> -   *                                                                                if (cons_head == prod_tail) 
> -   *                                                                                        return (NULL);
> -   *                                                                                <condition is false and code uses invalid(old) buf>`  
> +   * | uk_ring_enqueue()                         | uk_ring_dequeue_single()    |
> +   * |-------------------------------------------+-----------------------------|
> +   * |                                           |                             |
> +   * |                                           | cons_head = r->cons_head;   |
> +   * | atomic_cmpset_acq_32(&r->prod_head, ...); |                             |
> +   * |                                           | buf = r->ring[cons_head];<1>|
> +   * | r->ring[prod_head] = buf;                 |                             |
> +   * | atomic_store_rel_32(&r->prod_tail, ...);  |                             |
> +   * |                                           | prod_tail = r->prod_tail;   |
> +   * |                                           |                             |
> +   * |                                           | if (cons_head == prod_tail) |
> +   * |                                           |   return NULL;              |
> +   * |                                           |                             |
> +   * |                                           | <condition is false and     |
> +   * |                                           |  code uses invalid(old)     |
> +   * |                                           |  buf>                       |
>     *
> -   * <1> Load (on core 1) from r->ring[cons_head] can be reordered (speculative readed) by CPU.
> -   */
> +   * <1> Load (on core 1) from r->ring[cons_head] can be reordered (speculative
> +   * readed) by CPU.
> +   */  
>  #if defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64)
>    /* TODO: Provide atomic_load_acq_32() */
>    /* cons_head = atomic_load_acq_32(&r->cons_head); */
>    cons_head = &r->cons_head;
>  #else
>    cons_head = r->cons_head;
> -#endif
> +#endif /* defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64) */
>    /* TODO: Provide atomic_load_acq_32() */
>    /* prod_tail = atomic_load_acq_32(&r->prod_tail); */
>    prod_tail = &r->prod_tail;
> @@ -223,7 +247,7 @@ uk_ring_dequeue_single(struct uk_ring *r)
>    /* TODO: Support CPU prefetchhing. */
>  #if 0
>    cons_next_next = (cons_head + 2) & r->cons_mask;
> -#endif
> +#endif /* 0 */
>  
>    if (cons_head == prod_tail)
>      return NULL;
> @@ -235,7 +259,7 @@ uk_ring_dequeue_single(struct uk_ring *r)
>      if (cons_next_next != prod_tail)
>        prefetch(r->ring[cons_next_next]);
>    }
> -#endif
> +#endif /* 0 */
>  
>    r->cons_head = cons_next;
>    buf = r->ring[cons_head];
> @@ -249,16 +273,19 @@ uk_ring_dequeue_single(struct uk_ring *r)
>    if (r->cons_tail != cons_head)
>      uk_pr_crit("inconsistent list cons_tail=%d cons_head=%d\n",
>          r->cons_tail, cons_head);
> -#endif
> +#endif /* CONFIG_LIBUKDEBUG_PRINTK_CRIT */
>  
>    r->cons_tail = cons_next;
>    return buf;
>  }
>  
> -/*
> - * single-consumer advance after a peek
> - * use where it is protected by a lock
> - * e.g. a network driver's tx queue lock
> +
> +/**
> + * Single-consumer advance after a peek use where it is protected by a lock e.g.
> + * a network driver's tx queue lock.
> + *
> + * @param br
> + *  Reference to the ring structure.
>   */
>  static __inline void
>  uk_ring_advance_single(struct uk_ring *r)
> @@ -277,26 +304,27 @@ uk_ring_advance_single(struct uk_ring *r)
>  
>  #ifdef CONFIG_LIBUKDEBUG
>    r->ring[cons_head] = NULL;
> -#endif
> +#endif /* CONFIG_LIBUKDEBUG */
>  
>    r->cons_tail = cons_next;
>  }
>  
> -/*
> - * Used to return a buffer (most likely already there)
> - * to the top of the ring. The caller should *not*
> - * have used any dequeue to pull it out of the ring
> - * but instead should have used the peek() function.
> - * This is normally used where the transmit queue
> - * of a driver is full, and an mbuf must be returned.
> - * Most likely whats in the ring-buffer is what
> - * is being put back (since it was not removed), but
> - * sometimes the lower transmit function may have
> - * done a pullup or other function that will have
> - * changed it. As an optimization we always put it
> - * back (since jhb says the store is probably cheaper),
> - * if we have to do a multi-queue version we will need
> - * the compare and an atomic.
> +
> +/**
> + * Used to return a buffer (most likely already there) to the top of the ring.
> + * The caller should *not* have used any dequeue to pull it out of the ring but
> + * instead should have used the peek() function.  This is normally used where
> + * the transmit queue of a driver is full, and an mbuf must be returned.  Most
> + * likely whats in the ring-buffer is what is being put back (since it was not
> + * removed), but sometimes the lower transmit function may have done a pullup or
> + * other function that will have changed it. As an optimization we always put it
> + * back (since jhb says the store is probably cheaper), if we have to do a
> + * multi-queue version we will need the compare and an atomic.
> + *
> + * @param br
> + *  Reference to the ring structure.
> + * @param new
> + *  The item to be pushed back into the ring.
>   */
>  static __inline void
>  uk_ring_putback_single(struct uk_ring *r, void *new)
> @@ -306,10 +334,13 @@ uk_ring_putback_single(struct uk_ring *r, void *new)
>    r->ring[r->cons_head] = new;
>  }
>  
> -/*
> - * return a pointer to the first entry in the ring
> - * without modifying it, or NULL if the ring is empty
> - * race-prone if not protected by a lock
> +
> +/**
> + * Return a pointer to the first entry in the ring without modifying it, or NULL
> + * if the ring is empty race-prone if not protected by a lock.
> + *
> + * @param br
> + *  Reference to the ring structure.
>   */
>  static __inline void *
>  uk_ring_peek(struct uk_ring *r)
> @@ -317,13 +348,12 @@ uk_ring_peek(struct uk_ring *r)
>  #ifdef CONFIG_LIBUKDEBUG_PRINTK_CRIT
>    if ((r->lock != NULL) && !uk_mutex_is_locked(r->lock))
>      uk_pr_crit("lock not held on single consumer dequeue\n");
> -#endif
> +#endif /* CONFIG_LIBUKDEBUG_PRINTK_CRIT */
>  
>    /*
> -   * I believe it is safe to not have a memory barrier
> -   * here because we control cons and tail is worst case
> -   * a lagging indicator so we worst case we might
> -   * return NULL immediately after a buffer has been enqueued
> +   * It is safe to not have a memory barrier here because we control cons and
> +   * tail is worst case a lagging indicator so we worst case we might return
> +   * NULL immediately after a buffer has been enqueued.
>     */
>    if (r->cons_head == r->prod_tail)
>      return NULL;
> @@ -331,6 +361,14 @@ uk_ring_peek(struct uk_ring *r)
>    return r->ring[r->cons_head];
>  }
>  
> +
> +/**
> + * Single-consumer clear the pointer to the first entry of the ring, or NULL if
> + * the ring is empty.
> + *
> + * @param br
> + *  Reference to the ring structure.
> + */
>  static __inline void *
>  uk_ring_peek_clear_single(struct uk_ring *r)
>  {
> @@ -339,7 +377,7 @@ uk_ring_peek_clear_single(struct uk_ring *r)
>  
>    if (!uk_mutex_is_locked(r->lock))
>      uk_pr_crit("lock not held on single consumer dequeue\n");
> -#endif
> +#endif /* CONFIG_LIBUKDEBUG_PRINTK_CRIT */
>  
>    if (r->cons_head == r->prod_tail)
>      return NULL;
> @@ -347,17 +385,15 @@ uk_ring_peek_clear_single(struct uk_ring *r)
>  #if defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64)
>    /*
>     * The barrier is required there on ARM and ARM64 to ensure, that
> -   * r->ring[r->cons_head] will not be fetched before the above
> -   * condition is checked.
> -   * Without the barrier, it is possible, that buffer will be fetched
> -   * before the enqueue will put mbuf into r, then, in the meantime, the
> -   * enqueue will update the array and the prod_tail, and the
> -   * conditional check will be true, so we will return previously fetched
> -   * (and invalid) buffer.
> +   * br->ring[br->cons_head] will not be fetched before the above condition is
> +   * checked.  Without the barrier, it is possible, that buffer will be fetched
> +   * before the enqueue will put mbuf into br, then, in the meantime, the
> +   * enqueue will update the array and the prod_tail, and the conditional check
> +   * will be true, so we will return previously fetched (and invalid) buffer.
>     */
>    /* TODO: Provide atomic_thread_fence_acq(); */
>    /* atomic_thread_fence_acq(); */
> -#endif
> +#endif /* defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64) */
>  
>  #ifdef CONFIG_LIBUKDEBUG
>    /*
> @@ -370,21 +406,42 @@ uk_ring_peek_clear_single(struct uk_ring *r)
>    return ret;
>  #else
>    return r->ring[r->cons_head];
> -#endif
> +#endif /* CONFIG_LIBUKDEBUG */
>  }
>  
> +
> +/**
> + * Return whether the ring buffer is full.
> + *
> + * @param br
> + *  Reference to the ring structure.
> + */
>  static __inline int
>  uk_ring_full(struct uk_ring *r)
>  {
>    return ((r->prod_head + 1) & r->prod_mask) == r->cons_tail;
>  }
>  
> +
> +/**
> + * Return whether the ring buffer is empty.
> + *
> + * @param br
> + *  Reference to the ring structure.
> + */
>  static __inline int
>  uk_ring_empty(struct uk_ring *r)
>  {
>    return r->cons_head == r->prod_tail;
>  }
>  
> +
> +/**
> + * Return the queue size in the ring buffer.
> + *
> + * @param br
> + *  Reference to the ring structure.
> + */
>  static __inline int
>  uk_ring_count(struct uk_ring *r)
>  {
> @@ -392,8 +449,32 @@ uk_ring_count(struct uk_ring *r)
>        & r->prod_mask;
>  }
>  
> -struct uk_ring *uk_ring_alloc(struct uk_alloc *a, int count, int flags,
> -    struct uk_mutex *);
> -void uk_ring_free(struct uk_alloc *a, struct uk_ring *r);
>  
> -#endif
> \ No newline at end of file
> +/**
> + * Create a new ring buffer.
> + *
> + * @param count
> + *  The size of the ring buffer.
> + * @param a
> + *  The memory allocator to use when creating the ring buffer.
> + * @param flags
> + *  Additional flags to specify to the ring.
> + * @param lock
> + *  The mutex to use when debugging the ring buffer.
> + */
> +struct uk_ring *
> +uk_ring_alloc(struct uk_alloc *a, int count, int flags, struct uk_mutex *lock);
> +
> +
> +/**
> + * Free the ring from use.
> + *
> + * @param br
> + *  Reference to the ring structure.
> + * @param a
> + *  The memory allocator to use when freeing the object.
> + */
> +void
> +uk_ring_free(struct uk_alloc *a, struct uk_ring *r);
> +
> +#endif /* __UK_RING_H__ */
> diff --git a/lib/ukring/ring.c b/lib/ukring/ring.c
> index db5600f..0523648 100644
> --- a/lib/ukring/ring.c
> +++ b/lib/ukring/ring.c
> @@ -1,12 +1,16 @@
> -/*-
> - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
> +/* SPDX-License-Identifier: BSD-2-Clause-FreeBSD */
> +/*
> + * Authors: Kip Macy <kmacy@freebsd.org>
> + *          Alexander Jung <alexander.jung@neclab.eu>
>   *
> - * Copyright (c) 2007, 2008 Kip Macy <kmacy@freebsd.org>
> - * All rights reserved.
> + * Copyright (c) 2007-2009, Kip Macy <kmacy@freebsd.org>
> + *               2020, NEC Laboratories Europe GmbH, NEC Corporation.
> + *               All rights reserved.
>   *
>   * Redistribution and use in source and binary forms, with or without
>   * modification, are permitted provided that the following conditions
>   * are met:
> + *
>   * 1. Redistributions of source code must retain the above copyright
>   *    notice, this list of conditions and the following disclaimer.
>   * 2. Redistributions in binary form must reproduce the above copyright
> @@ -24,6 +28,13 @@
>   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
>   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
>   * SUCH DAMAGE.
> + *
> + * $FreeBSD$
> + */
> +/*
> + * Simple ring implementation to handle object references.
> + *
> + * Inspired by FreeBSD and modified (commit-id: c45cce1).
>   */
>  
>  #include <sys/param.h>
> 


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 18:20:50 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 18:20:50 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxwsj-0000EW-TC; Tue, 21 Jul 2020 18:20:49 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=NVI3=BA=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jxwsi-0000EL-0S
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 18:20:48 +0000
X-Inumbo-ID: e55e5c2e-cb7e-11ea-859c-bc764e2007e4
Received: from mx.upb.ro (unknown [141.85.13.220])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id e55e5c2e-cb7e-11ea-859c-bc764e2007e4;
 Tue, 21 Jul 2020 18:20:47 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 0E7F9B561CED;
 Tue, 21 Jul 2020 21:20:46 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id S2GT7niuYOWS; Tue, 21 Jul 2020 21:20:44 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 1850DB561CCE;
 Tue, 21 Jul 2020 21:20:44 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id b97V0BsATVIv; Tue, 21 Jul 2020 21:20:44 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id 8381CB5617CC;
 Tue, 21 Jul 2020 21:20:43 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH,v2,10/15] lib/ukring: Disable use of CPU
 prefetching
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
 <20200721153956.13555-11-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <6edcbb75-cc7f-fdf5-7042-3d1e5f28ede4@cs.pub.ro>
Date: Tue, 21 Jul 2020 21:20:43 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200721153956.13555-11-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

On FreeBSD prefetch() is defined by each of the native drivers using
this ring buffer implementation. Therefore, we should just keep this as
it is and when some driver will need it then it will define it.

So we can simply drop this patch altogether.

Cheers,
Costin


On 7/21/20 6:39 PM, Alexander Jung wrote:
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/ukring/include/uk/ring.h | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
> index e1a0387..b51a11a 100644
> --- a/lib/ukring/include/uk/ring.h
> +++ b/lib/ukring/include/uk/ring.h
> @@ -177,7 +177,8 @@ static __inline void *
>  uk_ring_dequeue_single(struct uk_ring *r)
>  {
>    uint32_t cons_head, cons_next;
> -#ifdef PREFETCH_DEFINED
> +  /* TODO: Support CPU prefetchhing. */
> +#if 0
>    uint32_t cons_next_next;
>  #endif
>    uint32_t prod_tail;
> @@ -219,14 +220,16 @@ uk_ring_dequeue_single(struct uk_ring *r)
>    prod_tail = &r->prod_tail;
>  
>    cons_next = (cons_head + 1) & r->cons_mask;
> -#ifdef PREFETCH_DEFINED
> +  /* TODO: Support CPU prefetchhing. */
> +#if 0
>    cons_next_next = (cons_head + 2) & r->cons_mask;
>  #endif
>  
>    if (cons_head == prod_tail)
>      return NULL;
>  
> -#ifdef PREFETCH_DEFINED
> +  /* TODO: Support CPU prefetchhing. */
> +#if 0
>    if (cons_next != prod_tail) {
>      prefetch(r->ring[cons_next]);
>      if (cons_next_next != prod_tail)
> 


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 18:22:43 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 18:22:43 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxwuX-0000H0-2j; Tue, 21 Jul 2020 18:22:41 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=NVI3=BA=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jxwuU-0000Gv-W5
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 18:22:39 +0000
X-Inumbo-ID: 279859a0-cb7f-11ea-a122-12813bfff9fa
Received: from mx.upb.ro (unknown [141.85.13.240])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 279859a0-cb7f-11ea-a122-12813bfff9fa;
 Tue, 21 Jul 2020 18:22:38 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id F0596B561CCE;
 Tue, 21 Jul 2020 21:22:36 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id 3PeLdB2IFeYe; Tue, 21 Jul 2020 21:22:35 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 19AC8B561CBF;
 Tue, 21 Jul 2020 21:22:35 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id tspL6B3wTMjs; Tue, 21 Jul 2020 21:22:34 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id 63049B561C89;
 Tue, 21 Jul 2020 21:22:34 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH, v2, 12/15] lib/ukring: Provide KConfig menu
 option for microlibrary
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
 <20200721153956.13555-13-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <eddf5b1e-3ab1-118d-83b2-cce1e388563b@cs.pub.ro>
Date: Tue, 21 Jul 2020 21:22:34 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200721153956.13555-13-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

This commit can be squashed (i.e. git squash) into patch 14/15 because
it's part of registering to Unikraft.

Please see inline.

On 7/21/20 6:39 PM, Alexander Jung wrote:
> This commit introduces Config.uk.
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/ukring/Config.uk | 7 +++++++
>  1 file changed, 7 insertions(+)
>  create mode 100644 lib/ukring/Config.uk
> 
> diff --git a/lib/ukring/Config.uk b/lib/ukring/Config.uk
> new file mode 100644
> index 0000000..9d16224
> --- /dev/null
> +++ b/lib/ukring/Config.uk
> @@ -0,0 +1,7 @@
> +menuconfig LIBUKRING
> +  bool "ukring: Simple ring buffer interface"

I think we can get rid of 'Simple'. :)

> +  select LIBUKALLOC
> +  select LIBUKLOCK
> +  default n
> +  help
> +    Provide simple ring interface for handling object references.
> 


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 18:22:58 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 18:22:58 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxwuo-0000I3-5e; Tue, 21 Jul 2020 18:22:58 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=NVI3=BA=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jxwun-0000Hy-AO
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 18:22:57 +0000
X-Inumbo-ID: 329ac98c-cb7f-11ea-a122-12813bfff9fa
Received: from mx.upb.ro (unknown [141.85.13.210])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 329ac98c-cb7f-11ea-a122-12813bfff9fa;
 Tue, 21 Jul 2020 18:22:56 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 7BE4BB561CBF;
 Tue, 21 Jul 2020 21:22:54 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id nRz3xDf463Qo; Tue, 21 Jul 2020 21:22:52 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id A6C50B561C89;
 Tue, 21 Jul 2020 21:22:52 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id FllRf2D0VmMS; Tue, 21 Jul 2020 21:22:52 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id 19870B5617CC;
 Tue, 21 Jul 2020 21:22:52 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH, v2, 13/15] lib/ukring: Target files to build for
 the microlibrary
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
 <20200721153956.13555-14-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <229b08c9-00c1-f3cc-1e47-179f7d8ddbcd@cs.pub.ro>
Date: Tue, 21 Jul 2020 21:22:51 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200721153956.13555-14-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

This commit can be squashed (i.e. git squash) into patch 14/15 because
it's part of registering to Unikraft.

On 7/21/20 6:39 PM, Alexander Jung wrote:
> This commit introduces Makefile.uk which points to the ported
> files ring.c and the header, ring.h, now available at uk/ring.h
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/ukring/Makefile.uk | 6 ++++++
>  1 file changed, 6 insertions(+)
>  create mode 100644 lib/ukring/Makefile.uk
> 
> diff --git a/lib/ukring/Makefile.uk b/lib/ukring/Makefile.uk
> new file mode 100644
> index 0000000..b1530dd
> --- /dev/null
> +++ b/lib/ukring/Makefile.uk
> @@ -0,0 +1,6 @@
> +$(eval $(call addlib_s,libukring,$(CONFIG_LIBUKRING)))
> +
> +CINCLUDES-$(CONFIG_LIBUKRING)		+= -I$(LIBUKRING_BASE)/include
> +CXXINCLUDES-$(CONFIG_LIBUKRING)	+= -I$(LIBUKRING_BASE)/include
> +
> +LIBUKRING_SRCS-y += $(LIBUKRING_BASE)/ring.c
> \ No newline at end of file
> 


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 18:24:56 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 18:24:56 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxwwi-0000MF-Bs; Tue, 21 Jul 2020 18:24:56 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=NVI3=BA=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jxwwh-0000MA-9j
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 18:24:55 +0000
X-Inumbo-ID: 791a3258-cb7f-11ea-a122-12813bfff9fa
Received: from mx.upb.ro (unknown [141.85.13.240])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 791a3258-cb7f-11ea-a122-12813bfff9fa;
 Tue, 21 Jul 2020 18:24:54 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id DED4DB561CCE;
 Tue, 21 Jul 2020 21:24:53 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id HeK1Urx3C73w; Tue, 21 Jul 2020 21:24:51 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id D33B0B561CBF;
 Tue, 21 Jul 2020 21:24:51 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id JN5SaLUaOMHD; Tue, 21 Jul 2020 21:24:51 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id 31022B5617CC;
 Tue, 21 Jul 2020 21:24:51 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH,v2,14/15] lib/ukring: Register ukring with
 Unikraft
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
 <20200721153956.13555-15-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <df482ac4-d6be-1149-ddfa-87c06d9db090@cs.pub.ro>
Date: Tue, 21 Jul 2020 21:24:51 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200721153956.13555-15-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

We can squash patches 12 and 13 into this one and keep this commit
subject. Together they make the registering to Unikraft of this internal
lib which is almost the same for all the libs.

Costin

On 7/21/20 6:39 PM, Alexander Jung wrote:
> This commit registers the simple ring buffer implementation micro-
> library with Unikraft by including it in the globa library list
> and exports the ring buffer's main functions.
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/Makefile.uk          |  1 +
>  lib/ukring/exportsyms.uk | 12 ++++++++++++
>  2 files changed, 13 insertions(+)
>  create mode 100644 lib/ukring/exportsyms.uk
> 
> diff --git a/lib/Makefile.uk b/lib/Makefile.uk
> index 360fcd8..4fd222d 100644
> --- a/lib/Makefile.uk
> +++ b/lib/Makefile.uk
> @@ -25,6 +25,7 @@ $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/devfs))
>  $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/9pfs))
>  $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uklock))
>  $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukmpi))
> +$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukring))
>  $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukbus))
>  $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uksglist))
>  $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uknetdev))
> diff --git a/lib/ukring/exportsyms.uk b/lib/ukring/exportsyms.uk
> new file mode 100644
> index 0000000..7561724
> --- /dev/null
> +++ b/lib/ukring/exportsyms.uk
> @@ -0,0 +1,12 @@
> +uk_ring_alloc
> +uk_ring_free
> +uk_ring_enqueue
> +uk_ring_dequeue
> +uk_ring_dequeue_single
> +uk_ring_advance_single
> +uk_ring_putback_single
> +uk_ring_peek
> +uk_ring_peek_clear_single
> +uk_ring_full
> +uk_ring_empty
> +uk_ring_count
> 


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 18:26:47 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 18:26:47 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxwyU-0000Od-Hd; Tue, 21 Jul 2020 18:26:46 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=NVI3=BA=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jxwyT-0000OY-ML
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 18:26:45 +0000
X-Inumbo-ID: bae6cb1a-cb7f-11ea-a124-12813bfff9fa
Received: from mx.upb.ro (unknown [141.85.13.210])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id bae6cb1a-cb7f-11ea-a124-12813bfff9fa;
 Tue, 21 Jul 2020 18:26:45 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 4B99BB561CCE;
 Tue, 21 Jul 2020 21:26:44 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id zUokWrRqBSNY; Tue, 21 Jul 2020 21:26:42 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 66482B561CBF;
 Tue, 21 Jul 2020 21:26:42 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id W11DGfznyfN6; Tue, 21 Jul 2020 21:26:42 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id A22BDB5617CC;
 Tue, 21 Jul 2020 21:26:41 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH,v2,15/15] lib/ukring: Fix unitialized variable
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
 <20200721153956.13555-16-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <e2c3e3df-44f3-7a00-8d9d-5cf71e54d4ec@cs.pub.ro>
Date: Tue, 21 Jul 2020 21:26:41 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200721153956.13555-16-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

If we keep DEBUG_BUFRING then we won't need this patch at all.

Cheers,
Costin

On 7/21/20 6:39 PM, Alexander Jung wrote:
> This fix introduces the `ret` variable within the
> `uk_ring_peek_clear_single` function when compiled with ukdebug.
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/ukring/include/uk/ring.h | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
> index 49f9dfe..af113b4 100644
> --- a/lib/ukring/include/uk/ring.h
> +++ b/lib/ukring/include/uk/ring.h
> @@ -372,8 +372,10 @@ uk_ring_peek(struct uk_ring *r)
>  static __inline void *
>  uk_ring_peek_clear_single(struct uk_ring *r)
>  {
> -#ifdef CONFIG_LIBUKDEBUG_PRINTK_CRIT
> +#ifdef CONFIG_LIBUKDEBUG
>    void *ret;
> +#endif /* CONFIG_LIBUKDEBUG */
> +#ifdef CONFIG_LIBUKDEBUG_PRINTK_CRIT
>  
>    if (!uk_mutex_is_locked(r->lock))
>      uk_pr_crit("lock not held on single consumer dequeue\n");
> 


From minios-devel-bounces@lists.xenproject.org Tue Jul 21 18:32:36 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 21 Jul 2020 18:32:36 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jxx47-00019Q-0x; Tue, 21 Jul 2020 18:32:35 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=NVI3=BA=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jxx45-00019L-P0
 for minios-devel@lists.xen.org; Tue, 21 Jul 2020 18:32:33 +0000
X-Inumbo-ID: 8a2a1c56-cb80-11ea-a125-12813bfff9fa
Received: from mx.upb.ro (unknown [141.85.13.230])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 8a2a1c56-cb80-11ea-a125-12813bfff9fa;
 Tue, 21 Jul 2020 18:32:32 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id DE1C7B561CBF;
 Tue, 21 Jul 2020 21:32:31 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id EuHCrikLgjXv; Tue, 21 Jul 2020 21:32:29 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id A7051B561C89;
 Tue, 21 Jul 2020 21:32:29 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id TXFtfgWomvIa; Tue, 21 Jul 2020 21:32:29 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id 1D64DB5617CC;
 Tue, 21 Jul 2020 21:32:29 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH,v2,00/15] Introduce Ring Buffer Implementation
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200721153956.13555-1-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <797ab58a-78f4-bf03-4444-aff424d839a3@cs.pub.ro>
Date: Tue, 21 Jul 2020 21:32:28 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200721153956.13555-1-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Costin Lupu <costin.lupu@cs.pub.ro>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

This is not what I had in mind when I commented for the v1, but in the
end I think it's much better this way because it gives way to a more
precise reviewing.

It is necessary to have this implementation imported as good as possible
because the ring buffer is an important abstraction used for performance
and is very sensitive to changes. We needed this in Unikraft for quite
some time and there are many other libraries that need it. For example
we can use it to improve the pipe() implementation.

My reviewing for this v2 is completed. Those patches to which I didn't
comment anything are fine, but I can't sign them yet because I expect
those to be changed for next versions.

Cheers,
Costin

On 7/21/20 6:39 PM, Alexander Jung wrote:
> This series introduces a port of FreeBSD's buf_ring.{h,c} implementation for use
> within Unikraft.  This simple ring buffer can be used for message passing in
> queues, for example within a AF_UNIX socket implementation between two 
> threads.  The implementation is therefore thread safe and provides a generic 
> data field which is initialized to the desired ring buffer length.
> 
> The implementation is provided within ukmpi as a new option, LIBUKMPI_RING, 
> which exposes the following new methods:
> 
>  - uk_ring_alloc
>  - uk_ring_free
>  - uk_ring_enqueue
>  - uk_ring_dequeue
>  - uk_ring_dequeue_single
>  - uk_ring_advance_single
>  - uk_ring_putback_single
>  - uk_ring_peek
>  - uk_ring_peek_clear_single
>  - uk_ring_full
>  - uk_ring_empty
>  - uk_ring_count
> 
> The port is currently limited, with no support for reading atomic values from
> ARM{32,64} CPU registers (described in the comments inline).  As a result, use 
> of the ring buffer implementation is untested on ARM.
> 
> Alexander Jung (15):
>   lib/ukring: Import simple ring buffer from FreeBSD
>   lib/ukring: {ring.c, ring.h} Fix checkpatch errors and spacing.
>   lib/ukring: Adapt {ring.c, ring.h} to Unikraft
>   lib/ukring: Re-prefix methods and structs from buf_ to uk_
>   lib/ukring: Remove br_ prefix and rename br variable
>   lib/ukring: Disable use of cpu_spinwait function
>   lib/ukring: Rename single and multiple consumer functions.
>   lib/ukring: Use Unikraft to enable ring buffer debugging
>   lib/ukring: Remove unsupported cache line size
>   lib/ukring: Disable use of CPU prefetching
>   lib/ukring: Properly commment {ring.c, ring.h}
>   lib/ukring: Provide KConfig menu option for microlibrary
>   lib/ukring: Target files to build for the microlibrary
>   lib/ukring: Register ukring with Unikraft
>   lib/ukring: Fix unitialized variable
> 
>  lib/Makefile.uk              |   1 +
>  lib/ukring/Config.uk         |   7 +
>  lib/ukring/Makefile.uk       |   6 +
>  lib/ukring/exportsyms.uk     |  12 +
>  lib/ukring/include/uk/ring.h | 482 +++++++++++++++++++++++++++++++++++
>  lib/ukring/ring.c            |  86 +++++++
>  6 files changed, 594 insertions(+)
>  create mode 100644 lib/ukring/Config.uk
>  create mode 100644 lib/ukring/Makefile.uk
>  create mode 100644 lib/ukring/exportsyms.uk
>  create mode 100644 lib/ukring/include/uk/ring.h
>  create mode 100644 lib/ukring/ring.c
> 


From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:04:27 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:04:27 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBbs-0000ei-9P; Wed, 22 Jul 2020 10:04:24 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBbr-0000ed-DA
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:04:23 +0000
X-Inumbo-ID: b620f802-cc02-11ea-a18c-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id b620f802-cc02-11ea-a18c-12813bfff9fa;
 Wed, 22 Jul 2020 10:04:21 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 3FD43F200F;
 Wed, 22 Jul 2020 12:04:20 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id V1tavpk62btC; Wed, 22 Jul 2020 12:04:20 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 144B9F200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:04:18 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:04:17 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT/LIBLWIP PATCH v3 00/16] Introduce a tap driver for Unikraft
Date: Wed, 22 Jul 2020 12:03:47 +0200
Message-ID: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch series introduces a tap driver for the linuxu platform. The series is
structured as follows:
- Introduce the uk_netdev interface implemented by the tap driver
- Introduce pseudo tap bus to initialize the driver and probe a tap device.
- The tap device discovered are registered with the uk_netdev.
- Configure the netdevice by creating tap network interface.
- Configure the hw address on the tap device.
- Attach the tap device to a bridge interface.
- Fetch and configure the MTU.
- Check if the promiscuous mode is set
- Fetch the txq/rxq information.
- Configure the tx queue.
- Configure the rx queue.
- Start the tap interface.
- Implement packet receive on the tap interface
- Implement packet send on the tap interface
- Fix the error code difference between Unikraft and linux.

Changes since v2:
- Fix the tap_write implementation
- Change the mac generate implementation
- Minor fixes
- Make feature independent from the poll patch

Changes since v1:
- Complete the sys_open implementation with support for flags
- Fix bug in calloc usage.
- Move definitions into the required patches
- Add some comments for the library parameters
- Add descriptions to the struct definitions
- Fix some typos.


Sharan Santhanam (16):
  plat/linuxu/tap: Introduce tap driver
  plat/tap: Bus interface for the tap device
  plat/driver: Add tap device to the uk_netdev
  plat/driver: Create a tap dev during configuration
  plat/driver: Set features supported on tap device
  plat/tap: Get/Set hw_addr
  plat/tap: Add tap to the bridge
  plat/tap: Get/Set MTU
  plat/tap: Get promiscuous mode
  plat/tap: Fetch txq and rxq info
  plat/tap: Setup txq
  plat/tap: Setup rxq
  plat/tap: Start a tap device
  plat/tap: Support tap_netdev_recv
  plat/tap: Support tap_netdev_xmit
  plat/linuxu: Convert linux errno to unikraft errno

 plat/drivers/include/tap/tap.h              |  51 ++
 plat/drivers/tap/tap.c                      | 868 ++++++++++++++++++++
 plat/linuxu/Config.uk                       |  18 +
 plat/linuxu/Makefile.uk                     |  15 +
 plat/linuxu/include/linuxu/syscall-arm_32.h |   6 +
 plat/linuxu/include/linuxu/syscall-x86_64.h |   7 +
 plat/linuxu/include/linuxu/syscall.h        |  86 ++
 plat/linuxu/include/linuxu/tap.h            | 152 ++++
 plat/linuxu/tap_io.c                        | 160 ++++
 9 files changed, 1363 insertions(+)
 create mode 100644 plat/drivers/include/tap/tap.h
 create mode 100644 plat/drivers/tap/tap.c
 create mode 100644 plat/linuxu/include/linuxu/tap.h
 create mode 100644 plat/linuxu/tap_io.c

-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:04:27 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:04:27 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBbv-0000eu-BD; Wed, 22 Jul 2020 10:04:27 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBbt-0000ep-NL
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:04:25 +0000
X-Inumbo-ID: b74e6d4a-cc02-11ea-8623-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id b74e6d4a-cc02-11ea-8623-bc764e2007e4;
 Wed, 22 Jul 2020 10:04:23 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 4A9C8F2010;
 Wed, 22 Jul 2020 12:04:22 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id RYoc_1ybyOHi; Wed, 22 Jul 2020 12:04:22 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 20C75F200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:04:20 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:04:18 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT/LIBLWIP PATCH v3 01/16] plat/linuxu/tap: Introduce tap
 driver
Date: Wed, 22 Jul 2020 12:03:48 +0200
Message-ID: <20200722100403.15662-2-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
References: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Introduce a tap driver skeleton which implements the uknetdev
interface.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/tap/tap.c  | 216 ++++++++++++++++++++++++++++++++++++++++
 plat/linuxu/Config.uk   |   9 ++
 plat/linuxu/Makefile.uk |   8 ++
 3 files changed, 233 insertions(+)
 create mode 100644 plat/drivers/tap/tap.c

diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
new file mode 100644
index 00000000..4beb67bd
--- /dev/null
+++ b/plat/drivers/tap/tap.c
@@ -0,0 +1,216 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Sharan Santhanam <sharan.santhanam@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#include <errno.h>
+#include <uk/alloc.h>
+#include <uk/arch/types.h>
+#include <uk/netdev_core.h>
+#include <uk/netdev_driver.h>
+#include <uk/netbuf.h>
+#include <uk/errptr.h>
+
+/**
+ * Module functions
+ */
+static int tap_netdev_xmit(struct uk_netdev *dev,
+			   struct uk_netdev_tx_queue *queue,
+			   struct uk_netbuf *pkt);
+static int tap_netdev_recv(struct uk_netdev *dev,
+			   struct uk_netdev_rx_queue *queue,
+			   struct uk_netbuf **pkt);
+static struct uk_netdev_rx_queue *tap_netdev_rxq_setup(struct uk_netdev *dev,
+					__u16 queue_id, __u16 nb_desc,
+					struct uk_netdev_rxqueue_conf *conf);
+static struct uk_netdev_tx_queue *tap_netdev_txq_setup(struct uk_netdev *dev,
+					__u16 queue_id, __u16 nb_desc,
+					struct uk_netdev_txqueue_conf *conf);
+static int tap_netdev_configure(struct uk_netdev *n,
+				const struct uk_netdev_conf *conf);
+static int tap_netdev_start(struct uk_netdev *n);
+static const struct uk_hwaddr *tap_netdev_mac_get(struct uk_netdev *n);
+static int tap_netdev_mac_set(struct uk_netdev *n,
+			      const struct uk_hwaddr *hwaddr);
+static __u16 tap_netdev_mtu_get(struct uk_netdev *n);
+static int tap_netdev_mtu_set(struct uk_netdev *n,  __u16 mtu);
+static unsigned int tap_netdev_promisc_get(struct uk_netdev *n);
+static void tap_netdev_info_get(struct uk_netdev *dev,
+				struct uk_netdev_info *dev_info);
+static int tap_netdev_rxq_info_get(struct uk_netdev *dev, __u16 queue_id,
+				   struct uk_netdev_queue_info *qinfo);
+static int tap_netdev_txq_info_get(struct uk_netdev *dev, __u16 queue_id,
+				   struct uk_netdev_queue_info *qinfo);
+
+/**
+ * Local function definitions
+ */
+
+static int tap_netdev_recv(struct uk_netdev *dev,
+			   struct uk_netdev_rx_queue *queue,
+			   struct uk_netbuf **pkt)
+{
+	int rc = -EINVAL;
+
+	UK_ASSERT(dev);
+	UK_ASSERT(queue && pkt);
+
+	return rc;
+}
+
+static int tap_netdev_xmit(struct uk_netdev *dev,
+			   struct uk_netdev_tx_queue *queue,
+			   struct uk_netbuf *pkt)
+{
+	int rc = -EINVAL;
+
+	UK_ASSERT(dev);
+	UK_ASSERT(queue && pkt);
+
+	return rc;
+}
+
+static int tap_netdev_txq_info_get(struct uk_netdev *dev __unused,
+				   __u16 queue_id __unused,
+				   struct uk_netdev_queue_info *qinfo __unused)
+{
+	return -EINVAL;
+}
+
+static int tap_netdev_rxq_info_get(struct uk_netdev *dev __unused,
+				   __u16 queue_id __unused,
+				   struct uk_netdev_queue_info *qinfo __unused)
+{
+	return -EINVAL;
+}
+
+static struct uk_netdev_rx_queue *tap_netdev_rxq_setup(struct uk_netdev *dev,
+						       __u16 queue_id __unused,
+						       __u16 nb_desc __unused,
+					struct uk_netdev_rxqueue_conf *conf)
+{
+	int rc = -EINVAL;
+	struct uk_netdev_rx_queue *rxq = NULL;
+
+	UK_ASSERT(dev && conf);
+
+	rxq = ERR2PTR(rc);
+	return rxq;
+}
+
+static struct uk_netdev_tx_queue *tap_netdev_txq_setup(struct uk_netdev *dev,
+						       __u16 queue_id __unused,
+						       __u16 nb_desc __unused,
+					struct uk_netdev_txqueue_conf *conf)
+{
+	int rc = -EINVAL;
+	struct uk_netdev_tx_queue *txq = NULL;
+
+	UK_ASSERT(dev && conf);
+
+	txq = ERR2PTR(rc);
+	return txq;
+}
+
+static int tap_netdev_start(struct uk_netdev *n)
+{
+	int rc = -EINVAL;
+
+	UK_ASSERT(n);
+	return rc;
+}
+
+static void tap_netdev_info_get(struct uk_netdev *dev __unused,
+				struct uk_netdev_info *dev_info)
+{
+	UK_ASSERT(dev_info);
+}
+
+static unsigned int tap_netdev_promisc_get(struct uk_netdev *n)
+{
+
+	UK_ASSERT(n);
+
+	return 0;
+}
+
+static __u16 tap_netdev_mtu_get(struct uk_netdev *n)
+{
+	UK_ASSERT(n);
+	return 0;
+}
+
+static int tap_netdev_mtu_set(struct uk_netdev *n,  __u16 mtu __unused)
+{
+	int rc = -EINVAL;
+
+	UK_ASSERT(n);
+
+	return rc;
+}
+
+static const struct uk_hwaddr *tap_netdev_mac_get(struct uk_netdev *n)
+{
+	UK_ASSERT(n);
+	return NULL;
+}
+
+static int tap_netdev_mac_set(struct uk_netdev *n,
+			      const struct uk_hwaddr *hwaddr)
+{
+	int rc = -EINVAL;
+
+	UK_ASSERT(n && hwaddr);
+	return rc;
+}
+
+static int tap_netdev_configure(struct uk_netdev *n,
+				const struct uk_netdev_conf *conf)
+{
+	int rc = -EINVAL;
+
+	UK_ASSERT(n && conf);
+	return rc;
+}
+
+static const struct uk_netdev_ops tap_netdev_ops = {
+	.configure = tap_netdev_configure,
+	.rxq_configure = tap_netdev_rxq_setup,
+	.txq_configure = tap_netdev_txq_setup,
+	.start = tap_netdev_start,
+	.info_get = tap_netdev_info_get,
+	.promiscuous_get = tap_netdev_promisc_get,
+	.hwaddr_get = tap_netdev_mac_get,
+	.hwaddr_set = tap_netdev_mac_set,
+	.mtu_get = tap_netdev_mtu_get,
+	.mtu_set = tap_netdev_mtu_set,
+	.txq_info_get = tap_netdev_txq_info_get,
+	.rxq_info_get = tap_netdev_rxq_info_get,
+};
diff --git a/plat/linuxu/Config.uk b/plat/linuxu/Config.uk
index d8c86d81..5df48f3f 100644
--- a/plat/linuxu/Config.uk
+++ b/plat/linuxu/Config.uk
@@ -17,4 +17,13 @@ if (PLAT_LINUXU)
 		changed by using linuxu.heap_size as a command line argument. For more
 		information refer to "Command line arguments in Unikraft" sections in 
 		the developers guide
+
+	config TAP_NET
+	bool "Tap driver"
+	default y if LIBUKNETDEV
+	depends on LIBUKNETDEV
+	help
+		Enable drivers to support tap device on the linuxu platform. The
+		driver implements the uknetdev interface and provides an interface
+		for the network stack to send/receive network packets.
 endif
diff --git a/plat/linuxu/Makefile.uk b/plat/linuxu/Makefile.uk
index 94516acd..0850fd99 100644
--- a/plat/linuxu/Makefile.uk
+++ b/plat/linuxu/Makefile.uk
@@ -7,6 +7,7 @@ $(eval $(call addplat_s,linuxu,$(CONFIG_PLAT_LINUXU)))
 ## Linux user platform library registration
 ##
 $(eval $(call addplatlib,linuxu,liblinuxuplat))
+$(eval $(call addplatlib_s,linuxu,liblinuxutapnet,$(CONFIG_TAP_NET)))
 
 ## Adding libparam for the linuxu platform
 $(eval $(call addlib_paramprefix,liblinuxuplat,linuxu))
@@ -46,3 +47,10 @@ LIBLINUXUPLAT_SRCS-$(CONFIG_ARCH_X86_64) += \
 			$(LIBLINUXUPLAT_BASE)/x86/link64.lds.S
 LIBLINUXUPLAT_SRCS-$(CONFIG_ARCH_ARM_32) += \
 			$(LIBLINUXUPLAT_BASE)/arm/link.lds.S
+
+##
+## LINUXUTAPNET Source
+LIBLINUXUTAPNET_ASINCLUED-y         += -I$(LIBLINUXUPLAT_BASE)/include
+LIBLINUXUTAPNET_CINCLUDES-y         += -I$(LIBLINUXUPLAT_BASE)/include
+
+LIBLINUXUTAPNET_SRCS-y		  += $(UK_PLAT_DRIVERS_BASE)/tap/tap.c
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:04:29 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:04:29 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBbx-0000fb-Dx; Wed, 22 Jul 2020 10:04:29 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBbw-0000ed-85
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:04:28 +0000
X-Inumbo-ID: b88424a2-cc02-11ea-a18c-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id b88424a2-cc02-11ea-a18c-12813bfff9fa;
 Wed, 22 Jul 2020 10:04:25 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 55DFCF200F;
 Wed, 22 Jul 2020 12:04:24 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id jC4CA0_2Dmmi; Wed, 22 Jul 2020 12:04:24 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 2DEF0F200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:04:22 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:04:18 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT/LIBLWIP PATCH v3 02/16] plat/tap: Bus interface for the tap
 device
Date: Wed, 22 Jul 2020 12:03:49 +0200
Message-ID: <20200722100403.15662-3-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
References: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The tap driver registers itself with the uk_bus. The uk_bus on
initialization provide the necessary interface to setup the driver.
The probe callback provides necessary interface to setup the tap
device.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/tap/tap.c | 33 +++++++++++++++++++++++++++++++++
 plat/linuxu/Config.uk  |  1 +
 2 files changed, 34 insertions(+)

diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index 4beb67bd..3435e846 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -37,6 +37,17 @@
 #include <uk/netdev_driver.h>
 #include <uk/netbuf.h>
 #include <uk/errptr.h>
+#include <uk/bus.h>
+
+struct tap_net_drv {
+	/* allocator to initialize the driver data structure */
+	struct uk_alloc *a;
+};
+
+/**
+ * Module level variables
+ */
+static struct tap_net_drv tap_drv = {0};
 
 /**
  * Module functions
@@ -214,3 +225,25 @@ static const struct uk_netdev_ops tap_netdev_ops = {
 	.txq_info_get = tap_netdev_txq_info_get,
 	.rxq_info_get = tap_netdev_rxq_info_get,
 };
+
+/**
+ * Register a tap driver as bus. Currently in Unikraft, the uk_bus interface
+ * provides the necessary to provide callbacks for bring a pseudo device. In the
+ * future we might provide interface to support the pseudo device.
+ */
+static int tap_drv_probe(void)
+{
+	return 0;
+}
+
+static int tap_drv_init(struct uk_alloc *_a)
+{
+	tap_drv.a = _a;
+	return 0;
+}
+
+static struct uk_bus tap_bus = {
+	.init = tap_drv_init,
+	.probe = tap_drv_probe,
+};
+UK_BUS_REGISTER(&tap_bus);
diff --git a/plat/linuxu/Config.uk b/plat/linuxu/Config.uk
index 5df48f3f..3900e8bc 100644
--- a/plat/linuxu/Config.uk
+++ b/plat/linuxu/Config.uk
@@ -22,6 +22,7 @@ if (PLAT_LINUXU)
 	bool "Tap driver"
 	default y if LIBUKNETDEV
 	depends on LIBUKNETDEV
+	select LIBUKBUS
 	help
 		Enable drivers to support tap device on the linuxu platform. The
 		driver implements the uknetdev interface and provides an interface
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:04:32 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:04:32 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBc0-0000gV-Fw; Wed, 22 Jul 2020 10:04:32 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBbz-0000g8-2u
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:04:31 +0000
X-Inumbo-ID: baf7642e-cc02-11ea-8623-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id baf7642e-cc02-11ea-8623-bc764e2007e4;
 Wed, 22 Jul 2020 10:04:29 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 7B1FCF200F;
 Wed, 22 Jul 2020 12:04:28 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id cOMjfblsPs8f; Wed, 22 Jul 2020 12:04:28 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 4C0ECF200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:04:26 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:04:19 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT/LIBLWIP PATCH v3 04/16] plat/driver: Create a tap dev
 during configuration
Date: Wed, 22 Jul 2020 12:03:51 +0200
Message-ID: <20200722100403.15662-5-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
References: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch creates a tap device and configures the unikraft net device.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/include/tap/tap.h              |   4 +
 plat/drivers/tap/tap.c                      | 105 +++++++++++++-
 plat/linuxu/Makefile.uk                     |   1 +
 plat/linuxu/include/linuxu/syscall-arm_32.h |   5 +
 plat/linuxu/include/linuxu/syscall-x86_64.h |   6 +
 plat/linuxu/include/linuxu/syscall.h        |  61 ++++++++
 plat/linuxu/include/linuxu/tap.h            | 145 ++++++++++++++++++++
 plat/linuxu/tap_io.c                        |  66 +++++++++
 8 files changed, 392 insertions(+), 1 deletion(-)
 create mode 100644 plat/linuxu/include/linuxu/tap.h
 create mode 100644 plat/linuxu/tap_io.c

diff --git a/plat/drivers/include/tap/tap.h b/plat/drivers/include/tap/tap.h
index 6786e7de..c7ab037c 100644
--- a/plat/drivers/include/tap/tap.h
+++ b/plat/drivers/include/tap/tap.h
@@ -40,4 +40,8 @@
  */
 #define IFNAMSIZ        16
 
+int tap_open(__u32 flags);
+int tap_close(int fd);
+int tap_dev_configure(int fd, __u32 feature_flags, void *arg);
+
 #endif /* __PLAT_DRV_TAP_H */
diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index f817c32a..1a78f610 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -31,6 +31,7 @@
  *
  */
 #include <errno.h>
+#include <stdio.h>
 #include <string.h>
 #include <uk/alloc.h>
 #include <uk/arch/types.h>
@@ -42,6 +43,17 @@
 #include <uk/bus.h>
 #include <tap/tap.h>
 
+/**
+ * The tap driver is supported only on the linuxu platform. Since the driver is
+ * part of the common codebase we add compiler guard to not include the tap
+ * driver from other platforms.
+ */
+#ifdef CONFIG_PLAT_LINUXU
+#include <linuxu/tap.h>
+#else
+#error "The driver is supported on linuxu platform"
+#endif /* CONFIG_PLAT_LINUXU */
+
 #define DRIVER_NAME             "tap-net"
 
 #define ETH_PKT_PAYLOAD_LEN       1500
@@ -50,18 +62,41 @@
  * TODO: Find a better way of forwarding the command line argument to the
  * driver. For now they are defined as macros from this driver.
  */
+
+#define to_tapnetdev(dev) \
+		__containerof(dev, struct tap_net_dev, ndev)
+
+struct uk_netdev_tx_queue {
+	/* tx queue identifier */
+	int queue_id;
+};
+
+struct uk_netdev_rx_queue {
+	/* rx queue identifier */
+	int queue_id;
+};
+
 struct tap_net_dev {
 	/* Net device structure */
 	struct uk_netdev    ndev;
 	/* max number of queues */
 	__u16 max_qpairs;
 	/* Number of rxq configured */
+	__u16 rxq_cnt;
+	/* List of rx queues */
+	UK_TAILQ_HEAD(tap_rxqs, struct uk_netdev_rx_queue) rxqs;
+	/* Number of txq configured */
+	__u16 txq_cnt;
+	/* List of tx queues */
+	UK_TAILQ_HEAD(tap_txqs, struct uk_netdev_tx_queue) txqs;
 	/* The list of the tap device */
 	UK_TAILQ_ENTRY(struct tap_net_dev) next;
 	/* Tap Device identifier */
 	__u16 tid;
 	/* UK Netdevice identifier */
 	__u16 id;
+	/* File Descriptor for the tap device */
+	int tap_fd;
 	/* Name of the character device */
 	char name[IFNAMSIZ];
 	/* MTU of the device */
@@ -133,6 +168,7 @@ static int tap_netdev_rxq_info_get(struct uk_netdev *dev, __u16 queue_id,
 				   struct uk_netdev_queue_info *qinfo);
 static int tap_netdev_txq_info_get(struct uk_netdev *dev, __u16 queue_id,
 				   struct uk_netdev_queue_info *qinfo);
+static int tap_device_create(struct tap_net_dev *tdev, __u32 feature_flags);
 
 /**
  * Local function definitions
@@ -216,6 +252,10 @@ static void tap_netdev_info_get(struct uk_netdev *dev __unused,
 				struct uk_netdev_info *dev_info)
 {
 	UK_ASSERT(dev_info);
+	dev_info->max_rx_queues = 1;
+	dev_info->max_tx_queues = 1;
+	dev_info->nb_encap_tx = 0;
+	dev_info->nb_encap_rx = 0;
 }
 
 static unsigned int tap_netdev_promisc_get(struct uk_netdev *n)
@@ -259,12 +299,75 @@ static int tap_netdev_mac_set(struct uk_netdev *n,
 static int tap_netdev_configure(struct uk_netdev *n,
 				const struct uk_netdev_conf *conf)
 {
-	int rc = -EINVAL;
+	int rc = 0;
+	struct tap_net_dev *tdev = NULL;
+	__u32 feature_flag = 0;
 
 	UK_ASSERT(n && conf);
+	tdev = to_tapnetdev(n);
+
+	if (conf->nb_rx_queues > tdev->max_qpairs
+	    || conf->nb_tx_queues > tdev->max_qpairs) {
+		uk_pr_err(DRIVER_NAME": rx-queue:%d, tx-queue:%d not supported",
+			  conf->nb_rx_queues, conf->nb_tx_queues);
+		return -ENOTSUP;
+	} else if (conf->nb_rx_queues > 1 || conf->nb_tx_queues > 1)
+		/**
+		 * TODO:
+		 * We don't support multi-queues on the uknetdev. Might need to
+		 * revisit this when implementing multi-queue support on
+		 * uknetdev
+		 */
+		feature_flag |= UK_IFF_MULTI_QUEUE;
+
+	/* Open the device and configure the tap interface */
+	rc = tap_device_create(tdev, feature_flag);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed to configure the tap device\n");
+		goto exit;
+	}
+
+	/* Initialize tx/rx queues list */
+	UK_TAILQ_INIT(&tdev->rxqs);
+	tdev->rxq_cnt = 0;
+	UK_TAILQ_INIT(&tdev->txqs);
+	tdev->txq_cnt = 0;
+exit:
 	return rc;
 }
 
+static int tap_device_create(struct tap_net_dev *tdev, __u32 feature_flags)
+{
+	int rc = 0;
+	struct uk_ifreq ifreq = {0};
+
+	/* Open the tap device */
+	rc = tap_open(O_RDWR | O_NONBLOCK);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed(%d) to open the tap device\n",
+			  rc);
+		return rc;
+	}
+
+	tdev->tap_fd = rc;
+
+	rc = tap_dev_configure(tdev->tap_fd, feature_flags, &ifreq);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed to setup the tap device\n");
+		goto close_tap;
+	}
+
+	snprintf(tdev->name, sizeof(tdev->name), "%s", ifreq.ifr_name);
+	uk_pr_info(DRIVER_NAME": Configured tap device %s\n", tdev->name);
+
+exit:
+	return rc;
+close_tap:
+	tap_close(tdev->tap_fd);
+	tdev->tap_fd = -1;
+	goto exit;
+}
+
 static const struct uk_netdev_ops tap_netdev_ops = {
 	.configure = tap_netdev_configure,
 	.rxq_configure = tap_netdev_rxq_setup,
diff --git a/plat/linuxu/Makefile.uk b/plat/linuxu/Makefile.uk
index cdb7cd00..4cfe6219 100644
--- a/plat/linuxu/Makefile.uk
+++ b/plat/linuxu/Makefile.uk
@@ -45,6 +45,7 @@ LIBLINUXUPLAT_SRCS-y              += $(LIBLINUXUPLAT_BASE)/time.c
 LIBLINUXUPLAT_SRCS-y              += $(UK_PLAT_COMMON_BASE)/lcpu.c|common
 LIBLINUXUPLAT_SRCS-y              += $(UK_PLAT_COMMON_BASE)/memory.c|common
 LIBLINUXUPLAT_SRCS-y              += $(LIBLINUXUPLAT_BASE)/io.c
+LIBLINUXUPLAT_SRCS-$(CONFIG_TAP_NET) += $(LIBLINUXUPLAT_BASE)/tap_io.c
 LIBLINUXUPLAT_SRCS-$(CONFIG_ARCH_X86_64) += \
 			$(LIBLINUXUPLAT_BASE)/x86/link64.lds.S
 LIBLINUXUPLAT_SRCS-$(CONFIG_ARCH_ARM_32) += \
diff --git a/plat/linuxu/include/linuxu/syscall-arm_32.h b/plat/linuxu/include/linuxu/syscall-arm_32.h
index ef9323be..093fd629 100644
--- a/plat/linuxu/include/linuxu/syscall-arm_32.h
+++ b/plat/linuxu/include/linuxu/syscall-arm_32.h
@@ -46,6 +46,7 @@
 #define __SC_MUNMAP    91
 #define __SC_EXIT       1
 #define __SC_IOCTL     54
+#define __SC_FCNTL     55
 #define __SC_RT_SIGPROCMASK   126
 #define __SC_ARCH_PRCTL       172
 #define __SC_RT_SIGACTION     174
@@ -57,6 +58,10 @@
 #define __SC_CLOCK_GETTIME    263
 #define __SC_PSELECT6 335
 
+#ifndef O_TMPFILE
+#define O_TMPFILE 020040000
+#endif
+
 /* NOTE: from `man syscall`:
  *
  * ARM/EABI
diff --git a/plat/linuxu/include/linuxu/syscall-x86_64.h b/plat/linuxu/include/linuxu/syscall-x86_64.h
index 553f0ba4..c4b88fc6 100644
--- a/plat/linuxu/include/linuxu/syscall-x86_64.h
+++ b/plat/linuxu/include/linuxu/syscall-x86_64.h
@@ -48,6 +48,7 @@
 #define __SC_RT_SIGPROCMASK 14
 #define __SC_IOCTL  16
 #define __SC_EXIT   60
+#define __SC_FCNTL  72
 #define __SC_ARCH_PRCTL       158
 #define __SC_TIMER_CREATE     222
 #define __SC_TIMER_SETTIME    223
@@ -57,6 +58,11 @@
 #define __SC_CLOCK_GETTIME    228
 #define __SC_PSELECT6 270
 
+
+#ifndef O_TMPFILE
+#define O_TMPFILE 020200000
+#endif
+
 /* NOTE: from linux-4.6.3 (arch/x86/entry/entry_64.S):
  *
  * 64-bit SYSCALL saves rip to rcx, clears rflags.RF, then saves rflags to r11,
diff --git a/plat/linuxu/include/linuxu/syscall.h b/plat/linuxu/include/linuxu/syscall.h
index 0dca7c5c..2c613fc2 100644
--- a/plat/linuxu/include/linuxu/syscall.h
+++ b/plat/linuxu/include/linuxu/syscall.h
@@ -36,6 +36,7 @@
 #ifndef __SYSCALL_H__
 #define __SYSCALL_H__
 
+#include <stdarg.h>
 #include <linuxu/time.h>
 #include <sys/types.h>
 #include <linuxu/signal.h>
@@ -64,6 +65,66 @@ static inline ssize_t sys_write(int fd, const char *buf, size_t len)
 				  (long) (len));
 }
 
+#ifndef O_RDONLY
+#define O_RDONLY                  00000000
+#endif /* O_RDONLY */
+
+#ifndef O_WRONLY
+#define O_WRONLY                  00000001
+#endif /* O_WRONLY */
+#ifndef O_RDWR
+#define O_RDWR                    00000002
+#endif /* O_RDWR */
+
+#ifndef O_NONBLOCK
+#define O_NONBLOCK		 04000
+#endif /* O_NONBLOCK */
+
+#ifndef O_CREAT
+#define O_CREAT        0100
+#endif
+
+
+#ifndef O_CLOEXEC
+#define O_CLOEXEC  02000000
+#endif /* O_CLOEXEC */
+
+
+#ifndef FD_CLOEXEC
+#define FD_CLOEXEC 1
+#endif
+
+#ifndef F_SETFD
+#define F_SETFD  2
+#endif
+
+static inline int sys_open(const char *pathname, int flags, ...)
+{
+	mode_t mode = 0;
+	int fd;
+
+	if ((flags & O_CREAT) || (flags & O_TMPFILE) == O_TMPFILE) {
+		va_list ap;
+
+		va_start(ap, flags);
+		mode = va_arg(ap, mode_t);
+		va_end(ap);
+	}
+
+	fd = syscall3(__SC_OPEN, (long)pathname, (long)flags, (long)mode);
+	if ((fd >= 0) && (flags & O_CLOEXEC))
+		syscall3(__SC_FCNTL, (long) fd, (long)F_SETFD,
+			 (long)FD_CLOEXEC);
+
+	return fd;
+}
+
+static inline int sys_close(int fd)
+{
+	return (ssize_t) syscall1(__SC_CLOSE,
+				  (long) fd);
+}
+
 static inline int sys_exit(int status)
 {
 	return (int) syscall1(__SC_EXIT,
diff --git a/plat/linuxu/include/linuxu/tap.h b/plat/linuxu/include/linuxu/tap.h
new file mode 100644
index 00000000..b408f72b
--- /dev/null
+++ b/plat/linuxu/include/linuxu/tap.h
@@ -0,0 +1,145 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Sharan Santhanam <sharan.santhanam@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#ifndef __PLAT_LINUXU_TAP_H__
+#define __PLAT_LINUXU_TAP_H__
+
+#include <uk/arch/types.h>
+#include <linuxu/syscall.h>
+#include <linuxu/ioctl.h>
+
+/**
+ * TAP Device Path
+ */
+#define TAPDEV_PATH		 "/dev/net/tun"
+/**
+ * Using the musl as reference for the data structure definition
+ * Commit-id: 39ef612aa193
+ */
+#define IFNAMSIZ        16
+
+
+
+typedef __u16 uk_in_port_t;
+typedef __u32 uk_in_addr_t;
+typedef __u16 uk_sa_family_t;
+
+struct uk_in_addr {
+	uk_in_addr_t s_addr;
+};
+
+struct uk_sockaddr {
+	uk_sa_family_t sa_family;
+	char sa_data[14];
+};
+
+struct uk_ifmap {
+	unsigned long int mem_start;
+	unsigned long int mem_end;
+	unsigned short int base_addr;
+	unsigned char irq;
+	unsigned char dma;
+	unsigned char port;
+};
+
+struct uk_ifreq {
+	union {
+		char ifrn_name[IFNAMSIZ];
+	} uk_ifr_ifrn;
+
+	union {
+		struct uk_sockaddr ifru_addr;
+		struct uk_sockaddr ifru_dstaddr;
+		struct uk_sockaddr ifru_broadaddr;
+		struct uk_sockaddr ifru_netmask;
+		struct uk_sockaddr ifru_hwaddr;
+		short int       ifru_flags;
+		int             ifru_ivalue;
+		int             ifru_mtu;
+		struct uk_ifmap    ifru_map;
+		char            ifru_slave[IFNAMSIZ];
+		char            ifru_newname[IFNAMSIZ];
+		char           *ifru_data;
+	} uk_ifr_ifru;
+};
+
+#define ifr_name    uk_ifr_ifrn.ifrn_name
+#define ifr_hwaddr  uk_ifr_ifru.ifru_hwaddr
+#define ifr_addr    uk_ifr_ifru.ifru_addr
+#define ifr_dstaddr uk_ifr_ifru.ifru_dstaddr
+#define ifr_broadaddr   uk_ifr_ifru.ifru_broadaddr
+#define ifr_netmask uk_ifr_ifru.ifru_netmask
+#define ifr_flags   uk_ifr_ifru.ifru_flags
+#define ifr_metric  uk_ifr_ifru.ifru_ivalue
+#define ifr_mtu     uk_ifr_ifru.ifru_mtu
+#define ifr_map     uk_ifr_ifru.ifru_map
+#define ifr_slave   uk_ifr_ifru.ifru_slave
+#define ifr_data    uk_ifr_ifru.ifru_data
+#define ifr_ifindex uk_ifr_ifru.ifru_ivalue
+#define ifr_bandwidth   uk_ifr_ifru.ifru_ivalue
+#define ifr_qlen    uk_ifr_ifru.ifru_ivalue
+#define ifr_newname uk_ifr_ifru.ifru_newname
+
+#define UK_TUNSETIFF     (0x400454ca)
+#define UK_SIOCGIFNAME   (0x8910)
+#define UK_SIOCGIFFLAGS  (0x8913)
+#define UK_SIOCSIFFLAGS  (0x8914)
+#define UK_SIOCGIFADDR   (0x8915)
+#define UK_SIOCSIFADDR   (0x8916)
+#define UK_SIOCGIFMTU    (0x8921)
+#define UK_SIOCSIFMTU    (0x8922)
+#define UK_SIOCSIFHWADDR (0x8924)
+#define UK_SIOCGIFHWADDR (0x8927)
+#define UK_SIOCGIFTXQLEN (0x8942)
+#define UK_SIOCSIFTXQLEN (0x8943)
+#define UK_SIOCGIFINDEX  (0x8933)
+/* TUNSETIFF ifr flags */
+#define UK_IFF_TUN     (0x0001)
+#define UK_IFF_TAP     (0x0002)
+#define UK_IFF_NO_PI   (0x1000)
+/* This flag has no real effect */
+#define UK_IFF_ONE_QUEUE   (0x2000)
+#define UK_IFF_VNET_HDR    (0x4000)
+#define UK_IFF_TUN_EXCL    (0x8000)
+#define UK_IFF_MULTI_QUEUE (0x0100)
+#define UK_IFF_ATTACH_QUEUE (0x0200)
+#define UK_IFF_DETACH_QUEUE (0x0400)
+/* read-only flag */
+#define UK_IFF_PERSIST	(0x0800)
+#define UK_IFF_NOFILTER	(0x1000)
+#define UK_IFF_UP	(0x1)
+#define UK_IFF_PROMISC	(0x100)
+
+/* Adding the bridge interface */
+#define UK_SIOCBRADDIF (0x89a2)
+
+#endif /* __PLAT_LINUXU_TAP_H */
diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
new file mode 100644
index 00000000..fb9adc24
--- /dev/null
+++ b/plat/linuxu/tap_io.c
@@ -0,0 +1,66 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Sharan Santhanam <sharan.santhanam@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <uk/print.h>
+#include <uk/arch/types.h>
+#include <linuxu/tap.h>
+
+int tap_open(__u32 flags)
+{
+	int rc = 0;
+
+	rc = sys_open(TAPDEV_PATH, flags);
+	if (rc < 0)
+		uk_pr_err("Error in opening the tap device\n");
+	return rc;
+}
+
+int tap_dev_configure(int fd, __u32 feature_flags, void *arg)
+{
+	int rc = 0;
+	struct uk_ifreq *ifreq = (struct uk_ifreq *) arg;
+
+	/* Set the tap device configuration */
+	ifreq->ifr_flags = UK_IFF_TAP | UK_IFF_NO_PI | feature_flags;
+	if ((rc = sys_ioctl(fd, UK_TUNSETIFF, ifreq)) < 0)
+		uk_pr_err("Failed(%d) to configure the tap device\n", rc);
+
+	return rc;
+}
+
+int tap_close(int fd)
+{
+	return sys_close(fd);
+}
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:04:34 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:04:34 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBc2-0000h6-I5; Wed, 22 Jul 2020 10:04:34 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBc1-0000ed-8I
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:04:33 +0000
X-Inumbo-ID: b99a0515-cc02-11ea-a18c-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id b99a0515-cc02-11ea-a18c-12813bfff9fa;
 Wed, 22 Jul 2020 10:04:27 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 68231F200F;
 Wed, 22 Jul 2020 12:04:26 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id NFXl2_RPnp2Y; Wed, 22 Jul 2020 12:04:26 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 3AC94F200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:04:24 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:04:18 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT/LIBLWIP PATCH v3 03/16] plat/driver: Add tap device to the
 uk_netdev
Date: Wed, 22 Jul 2020 12:03:50 +0200
Message-ID: <20200722100403.15662-4-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
References: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch provides the implementation to parse the user provided tap
device information. The tap device detected are registered to the
uk_netdev.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/include/tap/tap.h |  43 ++++++++++
 plat/drivers/tap/tap.c         | 140 +++++++++++++++++++++++++++++++++
 plat/linuxu/Config.uk          |   8 ++
 plat/linuxu/Makefile.uk        |   6 ++
 4 files changed, 197 insertions(+)
 create mode 100644 plat/drivers/include/tap/tap.h

diff --git a/plat/drivers/include/tap/tap.h b/plat/drivers/include/tap/tap.h
new file mode 100644
index 00000000..6786e7de
--- /dev/null
+++ b/plat/drivers/include/tap/tap.h
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Sharan Santhanam <sharan.santhanam@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef __PLAT_DRV_TAP_H
+#define __PLAT_DRV_TAP_H
+
+#include <uk/arch/types.h>
+
+/**
+ * Using the musl as reference for the data structure definition
+ * Commit-id: 39ef612aa193
+ */
+#define IFNAMSIZ        16
+
+#endif /* __PLAT_DRV_TAP_H */
diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index 3435e846..f817c32a 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -31,23 +31,77 @@
  *
  */
 #include <errno.h>
+#include <string.h>
 #include <uk/alloc.h>
 #include <uk/arch/types.h>
 #include <uk/netdev_core.h>
 #include <uk/netdev_driver.h>
 #include <uk/netbuf.h>
 #include <uk/errptr.h>
+#include <uk/libparam.h>
 #include <uk/bus.h>
+#include <tap/tap.h>
+
+#define DRIVER_NAME             "tap-net"
+
+#define ETH_PKT_PAYLOAD_LEN       1500
+
+/**
+ * TODO: Find a better way of forwarding the command line argument to the
+ * driver. For now they are defined as macros from this driver.
+ */
+struct tap_net_dev {
+	/* Net device structure */
+	struct uk_netdev    ndev;
+	/* max number of queues */
+	__u16 max_qpairs;
+	/* Number of rxq configured */
+	/* The list of the tap device */
+	UK_TAILQ_ENTRY(struct tap_net_dev) next;
+	/* Tap Device identifier */
+	__u16 tid;
+	/* UK Netdevice identifier */
+	__u16 id;
+	/* Name of the character device */
+	char name[IFNAMSIZ];
+	/* MTU of the device */
+	__u16  mtu;
+	/* RX promiscuous mode */
+	__u8 promisc : 1;
+	/* State of the net device */
+	__u8 state;
+};
 
 struct tap_net_drv {
 	/* allocator to initialize the driver data structure */
 	struct uk_alloc *a;
+	/* list of tap device */
+	UK_TAILQ_HEAD(tdev_list, struct tap_net_dev) tap_dev_list;
+	/* Number of tap devices */
+	__u16 tap_dev_cnt;
+	/* A list of bridges associated with the bridge */
+	char **bridge_ifs;
 };
 
 /**
  * Module level variables
  */
 static struct tap_net_drv tap_drv = {0};
+static const char *drv_name = DRIVER_NAME;
+static int tap_dev_cnt;
+static char *bridgenames;
+
+/**
+ * Module Parameters.
+ */
+/**
+ * tap.tap_dev_cnt=<# of tap device>
+ */
+UK_LIB_PARAM(tap_dev_cnt, __u32);
+/**
+ * tap.bridgenames="br0 br1 ... brn"
+ */
+UK_LIB_PARAM_STR(bridgenames);
 
 /**
  * Module functions
@@ -226,6 +280,52 @@ static const struct uk_netdev_ops tap_netdev_ops = {
 	.rxq_info_get = tap_netdev_rxq_info_get,
 };
 
+/**
+ * Registering the network device.
+ */
+static int tap_dev_init(int id)
+{
+	struct tap_net_dev *tdev;
+	int rc = 0;
+
+	tdev = uk_zalloc(tap_drv.a, sizeof(*tdev));
+	if (!tdev) {
+		uk_pr_err(DRIVER_NAME": Failed to allocate tap_device\n");
+		rc = -ENOMEM;
+		goto exit;
+	}
+	tdev->ndev.rx_one = tap_netdev_recv;
+	tdev->ndev.tx_one = tap_netdev_xmit;
+	tdev->ndev.ops = &tap_netdev_ops;
+	tdev->tid = id;
+	/**
+	 * TODO:
+	 * As an initial implementation we have limit on the number of queues.
+	 */
+	tdev->max_qpairs = 1;
+
+	/* Registering the tap device with libuknet*/
+	rc = uk_netdev_drv_register(&tdev->ndev, tap_drv.a, drv_name);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed to register the network device\n");
+		goto free_tdev;
+	}
+	tdev->id = rc;
+	rc = 0;
+	tdev->mtu = ETH_PKT_PAYLOAD_LEN;
+	tdev->promisc = 0;
+	uk_pr_info(DRIVER_NAME": device(%d) registered with the libuknet\n",
+		   tdev->id);
+
+	/* Adding the list of devices maintained by this driver */
+	UK_TAILQ_INSERT_TAIL(&tap_drv.tap_dev_list, tdev, next);
+exit:
+	return rc;
+free_tdev:
+	uk_free(tap_drv.a, tdev);
+	goto exit;
+}
+
 /**
  * Register a tap driver as bus. Currently in Unikraft, the uk_bus interface
  * provides the necessary to provide callbacks for bring a pseudo device. In the
@@ -233,12 +333,52 @@ static const struct uk_netdev_ops tap_netdev_ops = {
  */
 static int tap_drv_probe(void)
 {
+	int i;
+	int rc = 0;
+	char *idx = NULL, *prev_idx;
+
+	if (tap_dev_cnt > 0) {
+		tap_drv.bridge_ifs = uk_calloc(tap_drv.a, tap_dev_cnt,
+					       sizeof(char *));
+		if (!tap_drv.bridge_ifs) {
+			uk_pr_err(DRIVER_NAME": Failed to allocate brigde_ifs\n");
+			return -ENOMEM;
+		}
+	}
+
+	idx = bridgenames;
+	for (i = 0; i < tap_dev_cnt; i++) {
+		if (idx) {
+			prev_idx = idx;
+			idx = strchr(idx, ' ');
+			if (idx) {
+				*idx = '\0';
+				idx++;
+			}
+			tap_drv.bridge_ifs[i] = prev_idx;
+			uk_pr_debug(DRIVER_NAME": Adding bridge %s\n",
+				    prev_idx);
+		} else {
+			uk_pr_warn(DRIVER_NAME": Adding tap device %d without bridge\n",
+				   i);
+			tap_drv.bridge_ifs[i] = NULL;
+		}
+
+		rc = tap_dev_init(i);
+		if (rc < 0) {
+			uk_pr_err(DRIVER_NAME": Failed to initialize the tap dev id: %d\n",
+				  i);
+			return rc;
+		}
+		tap_drv.tap_dev_cnt++;
+	}
 	return 0;
 }
 
 static int tap_drv_init(struct uk_alloc *_a)
 {
 	tap_drv.a = _a;
+	UK_TAILQ_INIT(&tap_drv.tap_dev_list);
 	return 0;
 }
 
diff --git a/plat/linuxu/Config.uk b/plat/linuxu/Config.uk
index 3900e8bc..9de0364a 100644
--- a/plat/linuxu/Config.uk
+++ b/plat/linuxu/Config.uk
@@ -23,8 +23,16 @@ if (PLAT_LINUXU)
 	default y if LIBUKNETDEV
 	depends on LIBUKNETDEV
 	select LIBUKBUS
+	imply LIBUKLIBPARAM
 	help
 		Enable drivers to support tap device on the linuxu platform. The
 		driver implements the uknetdev interface and provides an interface
 		for the network stack to send/receive network packets.
+
+	config TAP_DEV_DEBUG
+	bool "Tap Device Debug"
+	default n
+	depends on TAP_NET
+	help
+		Enable debug messages from the tap device.
 endif
diff --git a/plat/linuxu/Makefile.uk b/plat/linuxu/Makefile.uk
index 0850fd99..cdb7cd00 100644
--- a/plat/linuxu/Makefile.uk
+++ b/plat/linuxu/Makefile.uk
@@ -11,6 +11,8 @@ $(eval $(call addplatlib_s,linuxu,liblinuxutapnet,$(CONFIG_TAP_NET)))
 
 ## Adding libparam for the linuxu platform
 $(eval $(call addlib_paramprefix,liblinuxuplat,linuxu))
+$(eval $(call addlib_paramprefix,liblinuxutapnet,tap))
+
 ##
 ## Platform library definitions
 ##
@@ -51,6 +53,10 @@ LIBLINUXUPLAT_SRCS-$(CONFIG_ARCH_ARM_32) += \
 ##
 ## LINUXUTAPNET Source
 LIBLINUXUTAPNET_ASINCLUED-y         += -I$(LIBLINUXUPLAT_BASE)/include
+LIBLINUXUTAPNET_ASINCLUDES-y         += -I$(UK_PLAT_DRIVERS_BASE)/include
 LIBLINUXUTAPNET_CINCLUDES-y         += -I$(LIBLINUXUPLAT_BASE)/include
+LIBLINUXUTAPNET_CINCLUDES-y         += -I$(UK_PLAT_DRIVERS_BASE)/include
+
+LIBLINUXUTAPNET_CFLAGS-$(CONFIG_TAP_DEV_DEBUG) += -DUK_DEBUG
 
 LIBLINUXUTAPNET_SRCS-y		  += $(UK_PLAT_DRIVERS_BASE)/tap/tap.c
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:04:37 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:04:37 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBc5-0000iC-LT; Wed, 22 Jul 2020 10:04:37 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBc3-0000g8-LX
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:04:35 +0000
X-Inumbo-ID: bc2f2412-cc02-11ea-8623-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id bc2f2412-cc02-11ea-8623-bc764e2007e4;
 Wed, 22 Jul 2020 10:04:31 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 822E8F2010;
 Wed, 22 Jul 2020 12:04:30 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id VPB3xcz9q2gD; Wed, 22 Jul 2020 12:04:30 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 5D114F200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:04:28 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:04:20 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT/LIBLWIP PATCH v3 05/16] plat/driver: Set features supported
 on tap device
Date: Wed, 22 Jul 2020 12:03:52 +0200
Message-ID: <20200722100403.15662-6-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
References: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/tap/tap.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index 1a78f610..2173095b 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -256,6 +256,7 @@ static void tap_netdev_info_get(struct uk_netdev *dev __unused,
 	dev_info->max_tx_queues = 1;
 	dev_info->nb_encap_tx = 0;
 	dev_info->nb_encap_rx = 0;
+	dev_info->features = 0;
 }
 
 static unsigned int tap_netdev_promisc_get(struct uk_netdev *n)
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:04:39 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:04:39 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBc7-0000is-N5; Wed, 22 Jul 2020 10:04:39 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBc6-0000ed-8W
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:04:38 +0000
X-Inumbo-ID: bd7a09fe-cc02-11ea-a18c-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id bd7a09fe-cc02-11ea-a18c-12813bfff9fa;
 Wed, 22 Jul 2020 10:04:33 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id A6099F200F;
 Wed, 22 Jul 2020 12:04:32 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id LneNyOOLsb65; Wed, 22 Jul 2020 12:04:32 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 68417F200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:04:30 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:04:20 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT/LIBLWIP PATCH v3 06/16] plat/tap: Get/Set hw_addr
Date: Wed, 22 Jul 2020 12:03:53 +0200
Message-ID: <20200722100403.15662-7-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
References: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch implements support for generating a default hw_addr. The
patch also implements get and set netdev api.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/include/tap/tap.h              |  2 +
 plat/drivers/tap/tap.c                      | 93 ++++++++++++++++++++-
 plat/linuxu/include/linuxu/syscall-arm_32.h |  1 +
 plat/linuxu/include/linuxu/syscall-x86_64.h |  1 +
 plat/linuxu/include/linuxu/syscall.h        | 25 ++++++
 plat/linuxu/include/linuxu/tap.h            |  7 ++
 plat/linuxu/tap_io.c                        | 31 +++++++
 7 files changed, 157 insertions(+), 3 deletions(-)

diff --git a/plat/drivers/include/tap/tap.h b/plat/drivers/include/tap/tap.h
index c7ab037c..42c6d7f1 100644
--- a/plat/drivers/include/tap/tap.h
+++ b/plat/drivers/include/tap/tap.h
@@ -43,5 +43,7 @@
 int tap_open(__u32 flags);
 int tap_close(int fd);
 int tap_dev_configure(int fd, __u32 feature_flags, void *arg);
+int tap_netif_configure(int fd, __u32 request, void *arg);
+int tap_netif_create(void);
 
 #endif /* __PLAT_DRV_TAP_H */
diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index 2173095b..5e510759 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -91,12 +91,16 @@ struct tap_net_dev {
 	UK_TAILQ_HEAD(tap_txqs, struct uk_netdev_tx_queue) txqs;
 	/* The list of the tap device */
 	UK_TAILQ_ENTRY(struct tap_net_dev) next;
+	/* Mac address of the device */
+	struct uk_hwaddr hw_addr;
 	/* Tap Device identifier */
 	__u16 tid;
 	/* UK Netdevice identifier */
 	__u16 id;
 	/* File Descriptor for the tap device */
 	int tap_fd;
+	/* Control socket descriptor */
+	int ctrl_sock;
 	/* Name of the character device */
 	char name[IFNAMSIZ];
 	/* MTU of the device */
@@ -169,6 +173,7 @@ static int tap_netdev_rxq_info_get(struct uk_netdev *dev, __u16 queue_id,
 static int tap_netdev_txq_info_get(struct uk_netdev *dev, __u16 queue_id,
 				   struct uk_netdev_queue_info *qinfo);
 static int tap_device_create(struct tap_net_dev *tdev, __u32 feature_flags);
+static int tap_mac_generate(__u8 *addr, __u8 dev_id);
 
 /**
  * Local function definitions
@@ -284,16 +289,74 @@ static int tap_netdev_mtu_set(struct uk_netdev *n,  __u16 mtu __unused)
 
 static const struct uk_hwaddr *tap_netdev_mac_get(struct uk_netdev *n)
 {
+	struct tap_net_dev *tdev;
+
 	UK_ASSERT(n);
-	return NULL;
+	tdev = to_tapnetdev(n);
+	return &tdev->hw_addr;
 }
 
 static int tap_netdev_mac_set(struct uk_netdev *n,
 			      const struct uk_hwaddr *hwaddr)
 {
-	int rc = -EINVAL;
+	int rc = 0;
+	struct tap_net_dev *tdev;
+	struct uk_ifreq ifrq = {0};
 
 	UK_ASSERT(n && hwaddr);
+	tdev = to_tapnetdev(n);
+
+	snprintf(ifrq.ifr_name, sizeof(ifrq.ifr_name), "%s", tdev->name);
+	uk_pr_info("Setting mac address on tap device %s\n", tdev->name);
+
+#ifdef CONFIG_TAP_DEV_DEBUG
+	int  i;
+
+	for (i = 0; i < UK_NETDEV_HWADDR_LEN; i++) {
+		uk_pr_debug("hw_address: %d - %d\n", i,
+			    hwaddr->addr_bytes[i] & 0xFF);
+	}
+#endif /* CONFIG_TAP_DEV_DEBUG */
+
+	ifrq.ifr_hwaddr.sa_family = AF_LOCAL;
+	memcpy(&ifrq.ifr_hwaddr.sa_data[0], &hwaddr->addr_bytes[0],
+		UK_NETDEV_HWADDR_LEN);
+	rc = tap_netif_configure(tdev->ctrl_sock, UK_SIOCSIFHWADDR, &ifrq);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed(%d) to set the hardware address\n",
+			  rc);
+		goto exit;
+	}
+	memcpy(&tdev->hw_addr, hwaddr, sizeof(*hwaddr));
+
+exit:
+	return rc;
+}
+
+static int tap_mac_generate(__u8 *addr, __u8 dev_id)
+{
+	const char fmt[] = {0x2, 0x0, 0x0, 0x0, 0x0, 0x0};
+
+	UK_ASSERT(addr);
+
+	memcpy(addr, fmt, UK_NETDEV_HWADDR_LEN - 1);
+	*(addr + UK_NETDEV_HWADDR_LEN - 1) = (__u8) (dev_id + 1);
+	return 0;
+}
+
+static inline int tapdev_ctrlsock_create(struct tap_net_dev *tdev)
+{
+	int rc = 0;
+
+	rc = tap_netif_create();
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME":Failed(%d) to create a control socket\n",
+			  rc);
+		goto exit;
+	}
+	tdev->ctrl_sock = rc;
+	rc = 0;
+exit:
 	return rc;
 }
 
@@ -328,13 +391,37 @@ static int tap_netdev_configure(struct uk_netdev *n,
 		goto exit;
 	}
 
-	/* Initialize tx/rx queues list */
+	/* Create a control socket for the network interface */
+	rc = tapdev_ctrlsock_create(tdev);
+	if (rc != 0) {
+		uk_pr_err(DRIVER_NAME": Failed to create a control socket\n");
+		goto close_tap_dev;
+	}
+
+	/* Generate MAC address */
+	tap_mac_generate(&tdev->hw_addr.addr_bytes[0],
+			 tdev->id);
+
+	/* MAC Address configuration */
+	rc = tap_netdev_mac_set(n, &tdev->hw_addr);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed to set the mac address\n");
+		goto close_ctrl_sock;
+	}
+
+	/* Initialize the tx/rx queues */
 	UK_TAILQ_INIT(&tdev->rxqs);
 	tdev->rxq_cnt = 0;
 	UK_TAILQ_INIT(&tdev->txqs);
 	tdev->txq_cnt = 0;
 exit:
 	return rc;
+
+close_ctrl_sock:
+	tap_close(tdev->ctrl_sock);
+close_tap_dev:
+	tap_close(tdev->tap_fd);
+	goto exit;
 }
 
 static int tap_device_create(struct tap_net_dev *tdev, __u32 feature_flags)
diff --git a/plat/linuxu/include/linuxu/syscall-arm_32.h b/plat/linuxu/include/linuxu/syscall-arm_32.h
index 093fd629..4b7218bf 100644
--- a/plat/linuxu/include/linuxu/syscall-arm_32.h
+++ b/plat/linuxu/include/linuxu/syscall-arm_32.h
@@ -56,6 +56,7 @@
 #define __SC_TIMER_GETOVERRUN 260
 #define __SC_TIMER_DELETE     261
 #define __SC_CLOCK_GETTIME    263
+#define __SC_SOCKET           281
 #define __SC_PSELECT6 335
 
 #ifndef O_TMPFILE
diff --git a/plat/linuxu/include/linuxu/syscall-x86_64.h b/plat/linuxu/include/linuxu/syscall-x86_64.h
index c4b88fc6..8714c928 100644
--- a/plat/linuxu/include/linuxu/syscall-x86_64.h
+++ b/plat/linuxu/include/linuxu/syscall-x86_64.h
@@ -47,6 +47,7 @@
 #define __SC_RT_SIGACTION   13
 #define __SC_RT_SIGPROCMASK 14
 #define __SC_IOCTL  16
+#define __SC_SOCKET 41
 #define __SC_EXIT   60
 #define __SC_FCNTL  72
 #define __SC_ARCH_PRCTL       158
diff --git a/plat/linuxu/include/linuxu/syscall.h b/plat/linuxu/include/linuxu/syscall.h
index 2c613fc2..ad6f0381 100644
--- a/plat/linuxu/include/linuxu/syscall.h
+++ b/plat/linuxu/include/linuxu/syscall.h
@@ -125,6 +125,31 @@ static inline int sys_close(int fd)
 				  (long) fd);
 }
 
+#ifndef SOCK_STREAM
+#define SOCK_STREAM    1
+#endif /* SOCK_STREAM */
+#ifndef SOCK_DGRAM
+#define SOCK_DGRAM     2
+#endif /* SOCK_DGRAM */
+
+#ifndef SOCK_RAW
+#define SOCK_RAW       3
+#endif /* SOCK_RAW */
+
+#ifndef AF_LOCAL
+#define AF_LOCAL       1
+#endif /* AF_LOCAL */
+#ifndef AF_INET
+#define AF_INET        2
+#endif /* AF_INET */
+static inline int sys_socket(int domain, int type, int protocol)
+{
+	return (ssize_t) syscall3(__SC_SOCKET,
+				  (long) domain,
+				  (long) type,
+				  (long) protocol);
+}
+
 static inline int sys_exit(int status)
 {
 	return (int) syscall1(__SC_EXIT,
diff --git a/plat/linuxu/include/linuxu/tap.h b/plat/linuxu/include/linuxu/tap.h
index b408f72b..ca48841b 100644
--- a/plat/linuxu/include/linuxu/tap.h
+++ b/plat/linuxu/include/linuxu/tap.h
@@ -57,6 +57,13 @@ struct uk_in_addr {
 	uk_in_addr_t s_addr;
 };
 
+struct uk_sockaddr_in {
+	uk_sa_family_t sin_family;
+	uk_in_port_t sin_port;
+	struct uk_in_addr sin_addr;
+	__u8 sin_zero[8];
+};
+
 struct uk_sockaddr {
 	uk_sa_family_t sa_family;
 	char sa_data[14];
diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
index fb9adc24..24094f2b 100644
--- a/plat/linuxu/tap_io.c
+++ b/plat/linuxu/tap_io.c
@@ -60,6 +60,37 @@ int tap_dev_configure(int fd, __u32 feature_flags, void *arg)
 	return rc;
 }
 
+int tap_netif_configure(int fd, __u32 request, void *arg)
+{
+	int rc;
+	struct uk_ifreq *usr_ifr = (struct uk_ifreq *) arg;
+
+	switch (request) {
+	case UK_SIOCGIFHWADDR:
+	case UK_SIOCSIFHWADDR:
+		break;
+	default:
+		rc = -EINVAL;
+		uk_pr_err("Invalid ioctl request\n");
+		goto exit_error;
+	}
+
+	if ((rc = sys_ioctl(fd, request, usr_ifr)) < 0) {
+		uk_pr_err("Failed to set device control %d\n", rc);
+		goto exit_error;
+	}
+
+	return 0;
+
+exit_error:
+	return rc;
+}
+
+int tap_netif_create(void)
+{
+	return sys_socket(AF_INET, SOCK_DGRAM, 0);
+}
+
 int tap_close(int fd)
 {
 	return sys_close(fd);
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:04:41 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:04:41 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBc9-0000jd-Ox; Wed, 22 Jul 2020 10:04:41 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBc8-0000g8-Ld
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:04:40 +0000
X-Inumbo-ID: bfe3e7c8-cc02-11ea-8623-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id bfe3e7c8-cc02-11ea-8623-bc764e2007e4;
 Wed, 22 Jul 2020 10:04:37 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id BB310F200F;
 Wed, 22 Jul 2020 12:04:36 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 6bKLZa5EE9Yh; Wed, 22 Jul 2020 12:04:36 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 94FA4F200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:04:34 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:04:22 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT/LIBLWIP PATCH v3 08/16] plat/tap: Get/Set MTU
Date: Wed, 22 Jul 2020 12:03:55 +0200
Message-ID: <20200722100403.15662-9-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
References: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch implements mtu get and set functions.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/tap/tap.c | 28 +++++++++++++++++++++++++---
 plat/linuxu/tap_io.c   |  2 ++
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index 6b059943..f5b32339 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -327,15 +327,37 @@ static unsigned int tap_netdev_promisc_get(struct uk_netdev *n)
 
 static __u16 tap_netdev_mtu_get(struct uk_netdev *n)
 {
+	int rc = 0;
+	struct tap_net_dev *tdev;
+	struct uk_ifreq ifrq = {0};
+
 	UK_ASSERT(n);
-	return 0;
+	tdev = to_tapnetdev(n);
+	snprintf(ifrq.ifr_name, sizeof(ifrq.ifr_name), "%s", tdev->name);
+
+	rc = tap_netif_configure(tdev->ctrl_sock, UK_SIOCGIFMTU, &ifrq);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed(%d) to get the mtu\n", rc);
+		return rc;
+	}
+
+	return ifrq.ifr_mtu;
 }
 
-static int tap_netdev_mtu_set(struct uk_netdev *n,  __u16 mtu __unused)
+static int tap_netdev_mtu_set(struct uk_netdev *n,  __u16 mtu)
 {
-	int rc = -EINVAL;
+	int rc = 0;
+	struct tap_net_dev *tdev;
+	struct uk_ifreq ifrq = {0};
 
 	UK_ASSERT(n);
+	tdev = to_tapnetdev(n);
+	snprintf(ifrq.ifr_name, sizeof(ifrq.ifr_name), "%s", tdev->name);
+
+	ifrq.ifr_mtu = mtu;
+	rc = tap_netif_configure(tdev->ctrl_sock, UK_SIOCSIFMTU, &ifrq);
+	if (rc < 0)
+		uk_pr_err(DRIVER_NAME": Failed(%d) to set the mtu\n", rc);
 
 	return rc;
 }
diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
index fe1f52a6..896b8cc2 100644
--- a/plat/linuxu/tap_io.c
+++ b/plat/linuxu/tap_io.c
@@ -69,6 +69,8 @@ int tap_netif_configure(int fd, __u32 request, void *arg)
 	case UK_SIOCGIFINDEX:
 	case UK_SIOCGIFHWADDR:
 	case UK_SIOCSIFHWADDR:
+	case UK_SIOCSIFMTU:
+	case UK_SIOCGIFMTU:
 	case UK_SIOCBRADDIF:
 		break;
 	default:
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:04:44 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:04:44 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBcC-0000lR-Qv; Wed, 22 Jul 2020 10:04:44 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBcB-0000ed-8n
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:04:43 +0000
X-Inumbo-ID: beb0f2d8-cc02-11ea-a18c-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id beb0f2d8-cc02-11ea-a18c-12813bfff9fa;
 Wed, 22 Jul 2020 10:04:35 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id AFBF8F200F;
 Wed, 22 Jul 2020 12:04:34 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id WpAwuSc9cXQv; Wed, 22 Jul 2020 12:04:34 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 8A367F200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:04:32 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:04:21 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT/LIBLWIP PATCH v3 07/16] plat/tap: Add tap to the bridge
Date: Wed, 22 Jul 2020 12:03:54 +0200
Message-ID: <20200722100403.15662-8-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
References: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch implements support to add the tap device to a user provided
bridge.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/tap/tap.c | 60 ++++++++++++++++++++++++++++++++++++++++++
 plat/linuxu/tap_io.c   |  2 ++
 2 files changed, 62 insertions(+)

diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index 5e510759..6b059943 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -174,11 +174,64 @@ static int tap_netdev_txq_info_get(struct uk_netdev *dev, __u16 queue_id,
 				   struct uk_netdev_queue_info *qinfo);
 static int tap_device_create(struct tap_net_dev *tdev, __u32 feature_flags);
 static int tap_mac_generate(__u8 *addr, __u8 dev_id);
+static int tap_dev_br_add(struct tap_net_dev *tdev);
+static int tap_dev_index_get(struct tap_net_dev *tdev);
 
 /**
  * Local function definitions
  */
 
+static int tap_dev_index_get(struct tap_net_dev *tdev)
+{
+	int rc = 0;
+	struct uk_ifreq ifrq = {0};
+
+	snprintf(ifrq.ifr_name, sizeof(ifrq.ifr_name), "%s",
+		     tdev->name);
+
+	rc = tap_netif_configure(tdev->ctrl_sock, UK_SIOCGIFINDEX, &ifrq);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed to fetch the index\n");
+		goto exit;
+	}
+
+	rc = ifrq.ifr_ifindex;
+exit:
+	return rc;
+
+}
+
+static int tap_dev_br_add(struct tap_net_dev *tdev)
+{
+	int rc = -EINVAL;
+	struct uk_ifreq ifrq = {0};
+
+	if (!tap_drv.bridge_ifs[tdev->tid])
+		goto exit;
+
+	/**
+	 * Get the bridge name.
+	 */
+	snprintf(ifrq.ifr_name, sizeof(ifrq.ifr_name), "%s",
+		 tap_drv.bridge_ifs[tdev->tid]);
+
+	rc = tap_dev_index_get(tdev);
+	if (rc < 0)
+		return rc;
+
+	ifrq.ifr_ifindex = rc;
+	rc = tap_netif_configure(tdev->ctrl_sock, UK_SIOCBRADDIF, &ifrq);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed to add the interface %s to bridge %s\n",
+			  tdev->name, tap_drv.bridge_ifs[tdev->tid]);
+		goto exit;
+	}
+	rc = 0;
+
+exit:
+	return rc;
+}
+
 static int tap_netdev_recv(struct uk_netdev *dev,
 			   struct uk_netdev_rx_queue *queue,
 			   struct uk_netbuf **pkt)
@@ -409,6 +462,13 @@ static int tap_netdev_configure(struct uk_netdev *n,
 		goto close_ctrl_sock;
 	}
 
+	rc = tap_dev_br_add(tdev);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed(%d) to add the bridge interface\n",
+			  rc);
+		goto close_ctrl_sock;
+	}
+
 	/* Initialize the tx/rx queues */
 	UK_TAILQ_INIT(&tdev->rxqs);
 	tdev->rxq_cnt = 0;
diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
index 24094f2b..fe1f52a6 100644
--- a/plat/linuxu/tap_io.c
+++ b/plat/linuxu/tap_io.c
@@ -66,8 +66,10 @@ int tap_netif_configure(int fd, __u32 request, void *arg)
 	struct uk_ifreq *usr_ifr = (struct uk_ifreq *) arg;
 
 	switch (request) {
+	case UK_SIOCGIFINDEX:
 	case UK_SIOCGIFHWADDR:
 	case UK_SIOCSIFHWADDR:
+	case UK_SIOCBRADDIF:
 		break;
 	default:
 		rc = -EINVAL;
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:04:45 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:04:45 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBcD-0000lz-T9; Wed, 22 Jul 2020 10:04:45 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBcD-0000g8-Lo
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:04:45 +0000
X-Inumbo-ID: c104a1ce-cc02-11ea-8623-bc764e2007e4
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id c104a1ce-cc02-11ea-8623-bc764e2007e4;
 Wed, 22 Jul 2020 10:04:39 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 9C7E4103F92;
 Wed, 22 Jul 2020 12:04:38 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id M1YW2WzVd3Bm; Wed, 22 Jul 2020 12:04:38 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id 7C1D3FFDDE
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:04:38 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:04:37 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT/LIBLWIP PATCH v3 09/16] plat/tap: Get promiscuous mode
Date: Wed, 22 Jul 2020 12:03:56 +0200
Message-ID: <20200722100403.15662-10-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
References: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch implements function to check for promiscuous mode on the
uk_netdev.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/tap/tap.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index f5b32339..439c3c50 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -319,10 +319,12 @@ static void tap_netdev_info_get(struct uk_netdev *dev __unused,
 
 static unsigned int tap_netdev_promisc_get(struct uk_netdev *n)
 {
+	struct tap_net_dev *tdev;
 
 	UK_ASSERT(n);
+	tdev = to_tapnetdev(n);
 
-	return 0;
+	return tdev->promisc;
 }
 
 static __u16 tap_netdev_mtu_get(struct uk_netdev *n)
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:04:49 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:04:49 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBcG-0000n7-Va; Wed, 22 Jul 2020 10:04:48 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBcG-0000ed-8t
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:04:48 +0000
X-Inumbo-ID: c28ccaf8-cc02-11ea-a18c-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id c28ccaf8-cc02-11ea-a18c-12813bfff9fa;
 Wed, 22 Jul 2020 10:04:42 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 375B4F200F;
 Wed, 22 Jul 2020 12:04:41 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 707ooyZTfK93; Wed, 22 Jul 2020 12:04:41 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 0D0C2F200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:04:39 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:04:38 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT/LIBLWIP PATCH v3 10/16] plat/tap: Fetch txq and rxq info
Date: Wed, 22 Jul 2020 12:03:57 +0200
Message-ID: <20200722100403.15662-11-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
References: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch implements functions to retrieve information of the rxq and
txq.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/tap/tap.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index 439c3c50..abcfc877 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -258,18 +258,31 @@ static int tap_netdev_xmit(struct uk_netdev *dev,
 
 static int tap_netdev_txq_info_get(struct uk_netdev *dev __unused,
 				   __u16 queue_id __unused,
-				   struct uk_netdev_queue_info *qinfo __unused)
+				   struct uk_netdev_queue_info *qinfo)
 {
-	return -EINVAL;
+	UK_ASSERT(qinfo);
+
+	qinfo->nb_min = 1;
+	qinfo->nb_max = __U16_MAX;
+	qinfo->nb_align = 4;
+	qinfo->nb_is_power_of_two = 0;
+	return 0;
 }
 
 static int tap_netdev_rxq_info_get(struct uk_netdev *dev __unused,
 				   __u16 queue_id __unused,
-				   struct uk_netdev_queue_info *qinfo __unused)
+				   struct uk_netdev_queue_info *qinfo)
 {
-	return -EINVAL;
+	UK_ASSERT(qinfo);
+
+	qinfo->nb_min = 1;
+	qinfo->nb_max = __U16_MAX;
+	qinfo->nb_align = 4;
+	qinfo->nb_is_power_of_two = 0;
+	return 0;
 }
 
+
 static struct uk_netdev_rx_queue *tap_netdev_rxq_setup(struct uk_netdev *dev,
 						       __u16 queue_id __unused,
 						       __u16 nb_desc __unused,
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:04:51 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:04:51 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBcJ-0000o8-2K; Wed, 22 Jul 2020 10:04:51 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBcI-0000g8-Lq
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:04:50 +0000
X-Inumbo-ID: c3c6ab6e-cc02-11ea-8623-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id c3c6ab6e-cc02-11ea-8623-bc764e2007e4;
 Wed, 22 Jul 2020 10:04:44 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 44071F200F;
 Wed, 22 Jul 2020 12:04:43 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id rUXREXUd4Com; Wed, 22 Jul 2020 12:04:43 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 1CAAEF200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:04:41 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:04:38 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT/LIBLWIP PATCH v3 11/16] plat/tap: Setup txq
Date: Wed, 22 Jul 2020 12:03:58 +0200
Message-ID: <20200722100403.15662-12-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
References: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Tap driver implements the function to setup the txq.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/tap/tap.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index abcfc877..182ace45 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -69,6 +69,12 @@
 struct uk_netdev_tx_queue {
 	/* tx queue identifier */
 	int queue_id;
+	/* List of tx queue */
+	UK_TAILQ_ENTRY(struct uk_netdev_tx_queue) next;
+	/* Allocator for the txq */
+	struct uk_alloc *a;
+	/* Set the file descriptor for the tap device */
+	int fd;
 };
 
 struct uk_netdev_rx_queue {
@@ -298,17 +304,34 @@ static struct uk_netdev_rx_queue *tap_netdev_rxq_setup(struct uk_netdev *dev,
 }
 
 static struct uk_netdev_tx_queue *tap_netdev_txq_setup(struct uk_netdev *dev,
-						       __u16 queue_id __unused,
+						       __u16 queue_id,
 						       __u16 nb_desc __unused,
 					struct uk_netdev_txqueue_conf *conf)
 {
-	int rc = -EINVAL;
+	int rc = 0;
 	struct uk_netdev_tx_queue *txq = NULL;
+	struct tap_net_dev *tdev = NULL;
 
 	UK_ASSERT(dev && conf);
 
-	txq = ERR2PTR(rc);
+	tdev = to_tapnetdev(dev);
+	txq = uk_zalloc(conf->a, sizeof(*txq));
+	if (!txq) {
+		uk_pr_err(DRIVER_NAME": Failed to allocate the tx queue\n");
+		rc = -ENOMEM;
+		goto err_exit;
+	}
+
+	txq->queue_id = queue_id;
+	txq->fd = tdev->tap_fd;
+	txq->a = conf->a;
+	UK_TAILQ_INSERT_TAIL(&tdev->txqs, txq, next);
+	tdev->txq_cnt++;
+exit:
 	return txq;
+err_exit:
+	txq = ERR2PTR(rc);
+	goto exit;
 }
 
 static int tap_netdev_start(struct uk_netdev *n)
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:04:54 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:04:54 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBcM-0000pJ-44; Wed, 22 Jul 2020 10:04:54 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBcL-0000ed-8y
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:04:53 +0000
X-Inumbo-ID: c5064700-cc02-11ea-a18c-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id c5064700-cc02-11ea-a18c-12813bfff9fa;
 Wed, 22 Jul 2020 10:04:46 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 573BAF200F;
 Wed, 22 Jul 2020 12:04:45 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id IX-qhL8BeEjD; Wed, 22 Jul 2020 12:04:45 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 2F042F200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:04:43 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:04:39 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT/LIBLWIP PATCH v3 12/16] plat/tap: Setup rxq
Date: Wed, 22 Jul 2020 12:03:59 +0200
Message-ID: <20200722100403.15662-13-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
References: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Tap driver implements the function to setup the rxq.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/tap/tap.c | 102 +++++++++++++++++++++++++++++++++++++++--
 plat/linuxu/tap_io.c   |   2 +
 2 files changed, 100 insertions(+), 4 deletions(-)

diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index 182ace45..2667fd10 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -80,6 +80,18 @@ struct uk_netdev_tx_queue {
 struct uk_netdev_rx_queue {
 	/* rx queue identifier */
 	int queue_id;
+	/* number of rx descriptors */
+	__u16 nb_desc;
+	/* list of rx queue */
+	UK_TAILQ_ENTRY(struct uk_netdev_rx_queue) next;
+	/* Allocator for the rxq */
+	struct uk_alloc *a;
+	/* Set the file descriptor for the tap device */
+	int fd;
+	/* Callback for filling the buffer */
+	uk_netdev_alloc_rxpkts alloc_rxpkts;
+	/* Reference to a user data */
+	void *alloc_rxpkts_argp;
 };
 
 struct tap_net_dev {
@@ -288,19 +300,101 @@ static int tap_netdev_rxq_info_get(struct uk_netdev *dev __unused,
 	return 0;
 }
 
+static int tap_dev_rxqlen_get(struct tap_net_dev *tdev)
+{
+	int rc = 0;
+	struct uk_ifreq ifrq = {0};
+
+	/* Set the name of the device */
+	snprintf(ifrq.ifr_name, sizeof(ifrq.ifr_name), "%s", tdev->name);
+
+	/* Set the status of the device */
+	rc = tap_netif_configure(tdev->ctrl_sock, UK_SIOCGIFTXQLEN, &ifrq);
+	if (rc < 0) {
+		rc = -errno;
+		uk_pr_err(DRIVER_NAME": Failed(%d) to set the flags of if: %s\n",
+			  rc, tdev->name);
+		return rc;
+	}
+	uk_pr_info(DRIVER_NAME": rxq length is %d\n", ifrq.ifr_qlen);
+	return ifrq.ifr_qlen;
+}
+
+static int tap_dev_rxqlen_set(struct tap_net_dev *tdev, __u16 qlen)
+{
+	int rc = 0;
+	struct uk_ifreq ifrq = {0};
+
+	/* Set the name of the device */
+	snprintf(ifrq.ifr_name, sizeof(ifrq.ifr_name), "%s", tdev->name);
+	ifrq.ifr_qlen = qlen;
+
+	/* Set the status of the device */
+	rc = tap_netif_configure(tdev->ctrl_sock, UK_SIOCSIFTXQLEN, &ifrq);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed(%d) to set the flags of if: %s\n",
+			  rc, tdev->name);
+		return rc;
+	}
+	uk_pr_info(DRIVER_NAME": rxq length is %d\n", ifrq.ifr_qlen);
+	return rc;
+}
 
 static struct uk_netdev_rx_queue *tap_netdev_rxq_setup(struct uk_netdev *dev,
-						       __u16 queue_id __unused,
-						       __u16 nb_desc __unused,
+						       __u16 queue_id,
+						       __u16 nb_desc,
 					struct uk_netdev_rxqueue_conf *conf)
 {
-	int rc = -EINVAL;
+	int rc = 0;
 	struct uk_netdev_rx_queue *rxq = NULL;
+	struct tap_net_dev *tdev = NULL;
+	__u16 qlen = 0;
 
 	UK_ASSERT(dev && conf);
 
-	rxq = ERR2PTR(rc);
+	tdev = to_tapnetdev(dev);
+	/* Fetch the default queue length of the rx queue */
+	rc = tap_dev_rxqlen_get(tdev);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed to fetch the tx queue length\n");
+		goto err_exit;
+	}
+	qlen = rc;
+	rc = 0;
+
+	/* Allocate the rx queue */
+	rxq = uk_zalloc(conf->a, sizeof(*rxq));
+	if  (!rxq) {
+		uk_pr_err(DRIVER_NAME": Failed to allocate the rx queue %d",
+			  queue_id);
+		rc = -ENOMEM;
+		goto err_exit;
+	}
+
+	rxq->queue_id = queue_id;
+	rxq->nb_desc = (nb_desc > 0) ? nb_desc : qlen;
+	if (qlen != rxq->nb_desc) {
+		rc = tap_dev_rxqlen_set(tdev, rxq->nb_desc);
+		if (rc < 0) {
+			uk_pr_err(DRIVER_NAME": Failed to setup the rx queue with %d descriptors\n",
+				  rxq->nb_desc);
+			goto free_rxq;
+		}
+	}
+
+	rxq->a = conf->a;
+	rxq->alloc_rxpkts = conf->alloc_rxpkts;
+	rxq->alloc_rxpkts_argp = conf->alloc_rxpkts_argp;
+	rxq->fd = tdev->tap_fd;
+	UK_TAILQ_INSERT_TAIL(&tdev->rxqs, rxq, next);
+	tdev->rxq_cnt++;
+exit:
 	return rxq;
+free_rxq:
+	uk_free(conf->a, rxq);
+err_exit:
+	rxq = ERR2PTR(rc);
+	goto exit;
 }
 
 static struct uk_netdev_tx_queue *tap_netdev_txq_setup(struct uk_netdev *dev,
diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
index 896b8cc2..4828639d 100644
--- a/plat/linuxu/tap_io.c
+++ b/plat/linuxu/tap_io.c
@@ -71,6 +71,8 @@ int tap_netif_configure(int fd, __u32 request, void *arg)
 	case UK_SIOCSIFHWADDR:
 	case UK_SIOCSIFMTU:
 	case UK_SIOCGIFMTU:
+	case UK_SIOCSIFTXQLEN:
+	case UK_SIOCGIFTXQLEN:
 	case UK_SIOCBRADDIF:
 		break;
 	default:
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:04:56 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:04:56 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBcO-0000qE-5k; Wed, 22 Jul 2020 10:04:56 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBcN-0000g8-Lt
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:04:55 +0000
X-Inumbo-ID: c8b23d28-cc02-11ea-8623-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id c8b23d28-cc02-11ea-8623-bc764e2007e4;
 Wed, 22 Jul 2020 10:04:52 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 84B86F200F;
 Wed, 22 Jul 2020 12:04:51 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id qS8GHdLijEdj; Wed, 22 Jul 2020 12:04:51 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 58B7BF200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:04:49 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:04:41 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT/LIBLWIP PATCH v3 15/16] plat/tap: Support tap_netdev_xmit
Date: Wed, 22 Jul 2020 12:04:02 +0200
Message-ID: <20200722100403.15662-16-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
References: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Implement packet send on a tap device.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/include/tap/tap.h |  1 +
 plat/drivers/tap/tap.c         | 15 +++++++++++++--
 plat/linuxu/tap_io.c           | 20 ++++++++++++++++++++
 3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/plat/drivers/include/tap/tap.h b/plat/drivers/include/tap/tap.h
index f3e1b3eb..8bd1d888 100644
--- a/plat/drivers/include/tap/tap.h
+++ b/plat/drivers/include/tap/tap.h
@@ -46,5 +46,6 @@ int tap_dev_configure(int fd, __u32 feature_flags, void *arg);
 int tap_netif_configure(int fd, __u32 request, void *arg);
 int tap_netif_create(void);
 __ssz tap_read(int fd, void *buf, size_t count);
+__ssz tap_write(int fd, const void *buf, size_t count);
 
 #endif /* __PLAT_DRV_TAP_H */
diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index 03948150..f0257f8f 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -273,7 +273,6 @@ static int tap_netdev_recv(struct uk_netdev *dev,
 	rc = queue->alloc_rxpkts(queue->alloc_rxpkts_argp, &_pkt, 1);
 	if (rc == 0) {
 		uk_pr_err(DRIVER_NAME": Failed to allocate the memory\n");
-		rc = -ENOMEM;
 		_pkt = NULL;
 		rc = UK_NETDEV_STATUS_UNDERRUN | UK_NETDEV_STATUS_MORE;
 		return rc;
@@ -281,7 +280,6 @@ static int tap_netdev_recv(struct uk_netdev *dev,
 	uk_pr_debug(DRIVER_NAME": Receiving on interface %s(%d) %p(%d)\n",
 		    tdev->name, queue->fd, _pkt->data, _pkt->len);
 	rc = tap_read(queue->fd, _pkt->data, _pkt->len);
-
 	if (rc > 0) {
 		uk_pr_debug(DRIVER_NAME": Recv pkt size: %d\n", rc);
 		/* Setting the length of the packet */
@@ -313,10 +311,23 @@ static int tap_netdev_xmit(struct uk_netdev *dev,
 			   struct uk_netbuf *pkt)
 {
 	int rc = -EINVAL;
+	struct tap_net_dev *tdev __unused;
 
 	UK_ASSERT(dev);
 	UK_ASSERT(queue && pkt);
 
+	tdev = to_tapnetdev(dev);
+
+	rc = tap_write(queue->fd, pkt->data, pkt->len);
+	if (rc > 0) {
+		uk_pr_info(DRIVER_NAME": Send packet of size %d\n", rc);
+		uk_netbuf_free(pkt);
+		rc = UK_NETDEV_STATUS_SUCCESS | UK_NETDEV_STATUS_MORE;
+	} else if (rc == -EWOULDBLOCK || rc == -EAGAIN) {
+		uk_pr_info(DRIVER_NAME": The send queue is full\n");
+		rc = UK_NETDEV_STATUS_UNDERRUN;
+	}
+
 	return rc;
 }
 
diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
index 1072c60f..edef18ed 100644
--- a/plat/linuxu/tap_io.c
+++ b/plat/linuxu/tap_io.c
@@ -122,6 +122,26 @@ ssize_t tap_read(int fd, void *buf, size_t count)
 	return rc;
 }
 
+ssize_t tap_write(int fd, const void *buf, size_t count)
+{
+	ssize_t rc = -EINTR;
+	size_t written = 0;
+
+	while (count > 0) {
+		rc = sys_write(fd, buf + written, count);
+		if (rc == -EINTR)
+			continue;
+		else if (rc < 0) {
+			uk_pr_err("Failed(%ld) to write to the tap device\n",
+				  rc);
+			return rc;
+		}
+		count -= rc;
+		written += rc;
+	}
+	return (ssize_t)written;
+}
+
 int tap_close(int fd)
 {
 	return sys_close(fd);
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:04:59 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:04:59 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBcR-0000rU-7T; Wed, 22 Jul 2020 10:04:59 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBcQ-0000ed-8z
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:04:58 +0000
X-Inumbo-ID: c5f3a61d-cc02-11ea-a18c-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id c5f3a61d-cc02-11ea-a18c-12813bfff9fa;
 Wed, 22 Jul 2020 10:04:48 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 6278EF200F;
 Wed, 22 Jul 2020 12:04:47 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id kKEA6fvCIEF1; Wed, 22 Jul 2020 12:04:47 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 3C2B5F200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:04:45 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:04:40 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT/LIBLWIP PATCH v3 13/16] plat/tap: Start a tap device
Date: Wed, 22 Jul 2020 12:04:00 +0200
Message-ID: <20200722100403.15662-14-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
References: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch implements the function to start the tap device

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/tap/tap.c | 21 +++++++++++++++++++--
 plat/linuxu/tap_io.c   | 12 ++++++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index 2667fd10..b7037b64 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -430,10 +430,27 @@ err_exit:
 
 static int tap_netdev_start(struct uk_netdev *n)
 {
-	int rc = -EINVAL;
+	int rc = 0;
+	struct tap_net_dev *tdev = NULL;
+	struct uk_ifreq ifrq = {0};
 
 	UK_ASSERT(n);
-	return rc;
+	tdev = to_tapnetdev(n);
+	/* Set the name of the device */
+	snprintf(ifrq.ifr_name, sizeof(ifrq.ifr_name), "%s", tdev->name);
+
+	ifrq.ifr_flags = UK_IFF_UP | UK_IFF_PROMISC;
+
+	/* Set the status of the device */
+	rc = tap_netif_configure(tdev->ctrl_sock, UK_SIOCSIFFLAGS, &ifrq);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed(%d) to set the flags of if: %s\n",
+			  rc, tdev->name);
+		return rc;
+	}
+	tdev->promisc = 1;
+
+	return 0;
 }
 
 static void tap_netdev_info_get(struct uk_netdev *dev __unused,
diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
index 4828639d..8c44281c 100644
--- a/plat/linuxu/tap_io.c
+++ b/plat/linuxu/tap_io.c
@@ -64,8 +64,20 @@ int tap_netif_configure(int fd, __u32 request, void *arg)
 {
 	int rc;
 	struct uk_ifreq *usr_ifr = (struct uk_ifreq *) arg;
+	struct uk_ifreq ifr = {0};
 
 	switch (request) {
+	case UK_SIOCSIFFLAGS:
+		snprintf(ifr.ifr_name, IFNAMSIZ, "%s", usr_ifr->ifr_name);
+		rc = sys_ioctl(fd, UK_SIOCGIFFLAGS, &ifr);
+		/* fetch current flags to leave other flags untouched */
+		if (rc < 0) {
+			uk_pr_err("Failed to read flags %d\n", rc);
+			goto exit_error;
+		}
+		usr_ifr->ifr_flags |= ifr.ifr_flags;
+		break;
+	case UK_SIOCGIFFLAGS:
 	case UK_SIOCGIFINDEX:
 	case UK_SIOCGIFHWADDR:
 	case UK_SIOCSIFHWADDR:
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:05:04 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:05:04 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBcW-0000sz-9J; Wed, 22 Jul 2020 10:05:04 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBcV-0000ed-9B
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:05:03 +0000
X-Inumbo-ID: c77d080c-cc02-11ea-a18c-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id c77d080c-cc02-11ea-a18c-12813bfff9fa;
 Wed, 22 Jul 2020 10:04:50 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 79E82F200F;
 Wed, 22 Jul 2020 12:04:49 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 6IA29B8v69hS; Wed, 22 Jul 2020 12:04:49 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 478BDF200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:04:47 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:04:41 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT/LIBLWIP PATCH v3 14/16] plat/tap: Support tap_netdev_recv
Date: Wed, 22 Jul 2020 12:04:01 +0200
Message-ID: <20200722100403.15662-15-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
References: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Implement receive on the tap device.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/include/tap/tap.h |  1 +
 plat/drivers/tap/tap.c         | 48 +++++++++++++++++++++++++++++++++-
 plat/linuxu/tap_io.c           | 13 +++++++++
 3 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/plat/drivers/include/tap/tap.h b/plat/drivers/include/tap/tap.h
index 42c6d7f1..f3e1b3eb 100644
--- a/plat/drivers/include/tap/tap.h
+++ b/plat/drivers/include/tap/tap.h
@@ -45,5 +45,6 @@ int tap_close(int fd);
 int tap_dev_configure(int fd, __u32 feature_flags, void *arg);
 int tap_netif_configure(int fd, __u32 request, void *arg);
 int tap_netif_create(void);
+__ssz tap_read(int fd, void *buf, size_t count);
 
 #endif /* __PLAT_DRV_TAP_H */
diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index b7037b64..03948150 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -254,12 +254,58 @@ static int tap_netdev_recv(struct uk_netdev *dev,
 			   struct uk_netdev_rx_queue *queue,
 			   struct uk_netbuf **pkt)
 {
-	int rc = -EINVAL;
+	int rc = 0;
+	struct tap_net_dev *tdev __maybe_unused;
+	struct uk_netbuf *_pkt = NULL;
 
 	UK_ASSERT(dev);
 	UK_ASSERT(queue && pkt);
 
+	tdev = to_tapnetdev(dev);
+
+	if (!queue->alloc_rxpkts)
+		return -EINVAL;
+
+
+	/**
+	 * Allocate the packet in which the packet will be received.
+	 */
+	rc = queue->alloc_rxpkts(queue->alloc_rxpkts_argp, &_pkt, 1);
+	if (rc == 0) {
+		uk_pr_err(DRIVER_NAME": Failed to allocate the memory\n");
+		rc = -ENOMEM;
+		_pkt = NULL;
+		rc = UK_NETDEV_STATUS_UNDERRUN | UK_NETDEV_STATUS_MORE;
+		return rc;
+	}
+	uk_pr_debug(DRIVER_NAME": Receiving on interface %s(%d) %p(%d)\n",
+		    tdev->name, queue->fd, _pkt->data, _pkt->len);
+	rc = tap_read(queue->fd, _pkt->data, _pkt->len);
+
+	if (rc > 0) {
+		uk_pr_debug(DRIVER_NAME": Recv pkt size: %d\n", rc);
+		/* Setting the length of the packet */
+		_pkt->len = rc;
+		rc = UK_NETDEV_STATUS_SUCCESS | UK_NETDEV_STATUS_MORE;
+	} else if (rc == 0 || rc == -EWOULDBLOCK || rc == -EAGAIN) {
+		rc = 0;
+		goto err_exit;
+	} else {
+		uk_pr_err(DRIVER_NAME": Failed(%d) to read the packet\n", rc);
+		goto err_exit;
+	}
+	uk_pr_debug("uk_netdev buf ptr: %p\n", _pkt);
+
+	*pkt = _pkt;
+
+exit:
 	return rc;
+
+err_exit:
+	if (_pkt)
+		uk_netbuf_free(_pkt);
+	*pkt = NULL;
+	goto exit;
 }
 
 static int tap_netdev_xmit(struct uk_netdev *dev,
diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
index 8c44281c..1072c60f 100644
--- a/plat/linuxu/tap_io.c
+++ b/plat/linuxu/tap_io.c
@@ -109,6 +109,19 @@ int tap_netif_create(void)
 	return sys_socket(AF_INET, SOCK_DGRAM, 0);
 }
 
+ssize_t tap_read(int fd, void *buf, size_t count)
+{
+	ssize_t rc = -EINTR;
+
+	while (rc == -EINTR)
+		rc = sys_read(fd, buf, count);
+
+	if (rc < 0)
+		uk_pr_err("Failed(%ld) to read from the tap device\n", rc);
+
+	return rc;
+}
+
 int tap_close(int fd)
 {
 	return sys_close(fd);
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:05:09 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:05:09 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBcb-0000u9-Au; Wed, 22 Jul 2020 10:05:09 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBca-0000ed-9H
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:05:08 +0000
X-Inumbo-ID: c9ed2af4-cc02-11ea-a18c-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id c9ed2af4-cc02-11ea-a18c-12813bfff9fa;
 Wed, 22 Jul 2020 10:04:54 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 90FBFF200F;
 Wed, 22 Jul 2020 12:04:53 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id IA1yglSyZvg9; Wed, 22 Jul 2020 12:04:53 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 6A1C5F200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:04:51 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:04:42 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT/LIBLWIP PATCH v3 16/16] plat/linuxu: Convert linux errno to
 unikraft errno
Date: Wed, 22 Jul 2020 12:04:03 +0200
Message-ID: <20200722100403.15662-17-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
References: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

There are differences in errno between linux and unikraft. This patch
converts EAGAIN which is 11 in linux to unikraft which is 35.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/linuxu/tap_io.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
index edef18ed..efacf5f9 100644
--- a/plat/linuxu/tap_io.c
+++ b/plat/linuxu/tap_io.c
@@ -116,7 +116,10 @@ ssize_t tap_read(int fd, void *buf, size_t count)
 	while (rc == -EINTR)
 		rc = sys_read(fd, buf, count);
 
-	if (rc < 0)
+	if (rc == -11)
+		/* Explicitly added since linux errno has -11 for EAGAIN */
+		rc = -EWOULDBLOCK;
+	else if (rc < 0)
 		uk_pr_err("Failed(%ld) to read from the tap device\n", rc);
 
 	return rc;
@@ -131,7 +134,16 @@ ssize_t tap_write(int fd, const void *buf, size_t count)
 		rc = sys_write(fd, buf + written, count);
 		if (rc == -EINTR)
 			continue;
-		else if (rc < 0) {
+		else if (rc == -11) {
+			/*
+			 * Explicitly added since linux errno has -11 for
+			 * EAGAIN.
+			 * FIXME: EAGAIN is not the only error code affected by
+			 * this issue (eg EDESTADDRREQ, EDQUOT). We should think
+			 * of a more generic solution to address it.
+			 */
+			rc = -EAGAIN;
+		} else if (rc < 0) {
 			uk_pr_err("Failed(%ld) to write to the tap device\n",
 				  rc);
 			return rc;
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:15:37 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:15:37 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBmj-0001qV-HM; Wed, 22 Jul 2020 10:15:37 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBmh-0001qN-PF
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:15:35 +0000
X-Inumbo-ID: 4753f706-cc04-11ea-8624-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4753f706-cc04-11ea-8624-bc764e2007e4;
 Wed, 22 Jul 2020 10:15:34 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 683C6F2010;
 Wed, 22 Jul 2020 12:15:33 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id fCVMvX-x5nRA; Wed, 22 Jul 2020 12:15:33 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 4182FF200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:15:31 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:15:29 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 01/16] plat/linuxu/tap: Introduce tap driver
Date: Wed, 22 Jul 2020 12:14:57 +0200
Message-ID: <20200722101512.16281-2-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
References: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Introduce a tap driver skeleton which implements the uknetdev
interface.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/tap/tap.c  | 216 ++++++++++++++++++++++++++++++++++++++++
 plat/linuxu/Config.uk   |   9 ++
 plat/linuxu/Makefile.uk |   8 ++
 3 files changed, 233 insertions(+)
 create mode 100644 plat/drivers/tap/tap.c

diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
new file mode 100644
index 00000000..4beb67bd
--- /dev/null
+++ b/plat/drivers/tap/tap.c
@@ -0,0 +1,216 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Sharan Santhanam <sharan.santhanam@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#include <errno.h>
+#include <uk/alloc.h>
+#include <uk/arch/types.h>
+#include <uk/netdev_core.h>
+#include <uk/netdev_driver.h>
+#include <uk/netbuf.h>
+#include <uk/errptr.h>
+
+/**
+ * Module functions
+ */
+static int tap_netdev_xmit(struct uk_netdev *dev,
+			   struct uk_netdev_tx_queue *queue,
+			   struct uk_netbuf *pkt);
+static int tap_netdev_recv(struct uk_netdev *dev,
+			   struct uk_netdev_rx_queue *queue,
+			   struct uk_netbuf **pkt);
+static struct uk_netdev_rx_queue *tap_netdev_rxq_setup(struct uk_netdev *dev,
+					__u16 queue_id, __u16 nb_desc,
+					struct uk_netdev_rxqueue_conf *conf);
+static struct uk_netdev_tx_queue *tap_netdev_txq_setup(struct uk_netdev *dev,
+					__u16 queue_id, __u16 nb_desc,
+					struct uk_netdev_txqueue_conf *conf);
+static int tap_netdev_configure(struct uk_netdev *n,
+				const struct uk_netdev_conf *conf);
+static int tap_netdev_start(struct uk_netdev *n);
+static const struct uk_hwaddr *tap_netdev_mac_get(struct uk_netdev *n);
+static int tap_netdev_mac_set(struct uk_netdev *n,
+			      const struct uk_hwaddr *hwaddr);
+static __u16 tap_netdev_mtu_get(struct uk_netdev *n);
+static int tap_netdev_mtu_set(struct uk_netdev *n,  __u16 mtu);
+static unsigned int tap_netdev_promisc_get(struct uk_netdev *n);
+static void tap_netdev_info_get(struct uk_netdev *dev,
+				struct uk_netdev_info *dev_info);
+static int tap_netdev_rxq_info_get(struct uk_netdev *dev, __u16 queue_id,
+				   struct uk_netdev_queue_info *qinfo);
+static int tap_netdev_txq_info_get(struct uk_netdev *dev, __u16 queue_id,
+				   struct uk_netdev_queue_info *qinfo);
+
+/**
+ * Local function definitions
+ */
+
+static int tap_netdev_recv(struct uk_netdev *dev,
+			   struct uk_netdev_rx_queue *queue,
+			   struct uk_netbuf **pkt)
+{
+	int rc = -EINVAL;
+
+	UK_ASSERT(dev);
+	UK_ASSERT(queue && pkt);
+
+	return rc;
+}
+
+static int tap_netdev_xmit(struct uk_netdev *dev,
+			   struct uk_netdev_tx_queue *queue,
+			   struct uk_netbuf *pkt)
+{
+	int rc = -EINVAL;
+
+	UK_ASSERT(dev);
+	UK_ASSERT(queue && pkt);
+
+	return rc;
+}
+
+static int tap_netdev_txq_info_get(struct uk_netdev *dev __unused,
+				   __u16 queue_id __unused,
+				   struct uk_netdev_queue_info *qinfo __unused)
+{
+	return -EINVAL;
+}
+
+static int tap_netdev_rxq_info_get(struct uk_netdev *dev __unused,
+				   __u16 queue_id __unused,
+				   struct uk_netdev_queue_info *qinfo __unused)
+{
+	return -EINVAL;
+}
+
+static struct uk_netdev_rx_queue *tap_netdev_rxq_setup(struct uk_netdev *dev,
+						       __u16 queue_id __unused,
+						       __u16 nb_desc __unused,
+					struct uk_netdev_rxqueue_conf *conf)
+{
+	int rc = -EINVAL;
+	struct uk_netdev_rx_queue *rxq = NULL;
+
+	UK_ASSERT(dev && conf);
+
+	rxq = ERR2PTR(rc);
+	return rxq;
+}
+
+static struct uk_netdev_tx_queue *tap_netdev_txq_setup(struct uk_netdev *dev,
+						       __u16 queue_id __unused,
+						       __u16 nb_desc __unused,
+					struct uk_netdev_txqueue_conf *conf)
+{
+	int rc = -EINVAL;
+	struct uk_netdev_tx_queue *txq = NULL;
+
+	UK_ASSERT(dev && conf);
+
+	txq = ERR2PTR(rc);
+	return txq;
+}
+
+static int tap_netdev_start(struct uk_netdev *n)
+{
+	int rc = -EINVAL;
+
+	UK_ASSERT(n);
+	return rc;
+}
+
+static void tap_netdev_info_get(struct uk_netdev *dev __unused,
+				struct uk_netdev_info *dev_info)
+{
+	UK_ASSERT(dev_info);
+}
+
+static unsigned int tap_netdev_promisc_get(struct uk_netdev *n)
+{
+
+	UK_ASSERT(n);
+
+	return 0;
+}
+
+static __u16 tap_netdev_mtu_get(struct uk_netdev *n)
+{
+	UK_ASSERT(n);
+	return 0;
+}
+
+static int tap_netdev_mtu_set(struct uk_netdev *n,  __u16 mtu __unused)
+{
+	int rc = -EINVAL;
+
+	UK_ASSERT(n);
+
+	return rc;
+}
+
+static const struct uk_hwaddr *tap_netdev_mac_get(struct uk_netdev *n)
+{
+	UK_ASSERT(n);
+	return NULL;
+}
+
+static int tap_netdev_mac_set(struct uk_netdev *n,
+			      const struct uk_hwaddr *hwaddr)
+{
+	int rc = -EINVAL;
+
+	UK_ASSERT(n && hwaddr);
+	return rc;
+}
+
+static int tap_netdev_configure(struct uk_netdev *n,
+				const struct uk_netdev_conf *conf)
+{
+	int rc = -EINVAL;
+
+	UK_ASSERT(n && conf);
+	return rc;
+}
+
+static const struct uk_netdev_ops tap_netdev_ops = {
+	.configure = tap_netdev_configure,
+	.rxq_configure = tap_netdev_rxq_setup,
+	.txq_configure = tap_netdev_txq_setup,
+	.start = tap_netdev_start,
+	.info_get = tap_netdev_info_get,
+	.promiscuous_get = tap_netdev_promisc_get,
+	.hwaddr_get = tap_netdev_mac_get,
+	.hwaddr_set = tap_netdev_mac_set,
+	.mtu_get = tap_netdev_mtu_get,
+	.mtu_set = tap_netdev_mtu_set,
+	.txq_info_get = tap_netdev_txq_info_get,
+	.rxq_info_get = tap_netdev_rxq_info_get,
+};
diff --git a/plat/linuxu/Config.uk b/plat/linuxu/Config.uk
index d8c86d81..5df48f3f 100644
--- a/plat/linuxu/Config.uk
+++ b/plat/linuxu/Config.uk
@@ -17,4 +17,13 @@ if (PLAT_LINUXU)
 		changed by using linuxu.heap_size as a command line argument. For more
 		information refer to "Command line arguments in Unikraft" sections in 
 		the developers guide
+
+	config TAP_NET
+	bool "Tap driver"
+	default y if LIBUKNETDEV
+	depends on LIBUKNETDEV
+	help
+		Enable drivers to support tap device on the linuxu platform. The
+		driver implements the uknetdev interface and provides an interface
+		for the network stack to send/receive network packets.
 endif
diff --git a/plat/linuxu/Makefile.uk b/plat/linuxu/Makefile.uk
index 94516acd..0850fd99 100644
--- a/plat/linuxu/Makefile.uk
+++ b/plat/linuxu/Makefile.uk
@@ -7,6 +7,7 @@ $(eval $(call addplat_s,linuxu,$(CONFIG_PLAT_LINUXU)))
 ## Linux user platform library registration
 ##
 $(eval $(call addplatlib,linuxu,liblinuxuplat))
+$(eval $(call addplatlib_s,linuxu,liblinuxutapnet,$(CONFIG_TAP_NET)))
 
 ## Adding libparam for the linuxu platform
 $(eval $(call addlib_paramprefix,liblinuxuplat,linuxu))
@@ -46,3 +47,10 @@ LIBLINUXUPLAT_SRCS-$(CONFIG_ARCH_X86_64) += \
 			$(LIBLINUXUPLAT_BASE)/x86/link64.lds.S
 LIBLINUXUPLAT_SRCS-$(CONFIG_ARCH_ARM_32) += \
 			$(LIBLINUXUPLAT_BASE)/arm/link.lds.S
+
+##
+## LINUXUTAPNET Source
+LIBLINUXUTAPNET_ASINCLUED-y         += -I$(LIBLINUXUPLAT_BASE)/include
+LIBLINUXUTAPNET_CINCLUDES-y         += -I$(LIBLINUXUPLAT_BASE)/include
+
+LIBLINUXUTAPNET_SRCS-y		  += $(UK_PLAT_DRIVERS_BASE)/tap/tap.c
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:15:38 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:15:38 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBmh-0001qG-Fp; Wed, 22 Jul 2020 10:15:35 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBmg-0001qB-1O
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:15:34 +0000
X-Inumbo-ID: 462770e2-cc04-11ea-a18d-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 462770e2-cc04-11ea-a18d-12813bfff9fa;
 Wed, 22 Jul 2020 10:15:32 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 6278FF200F;
 Wed, 22 Jul 2020 12:15:31 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id R-3SqNxAJSEO; Wed, 22 Jul 2020 12:15:31 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 2FBD9F200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:15:29 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:15:28 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 00/16] Introduce a tap driver for Unikraft
Date: Wed, 22 Jul 2020 12:14:56 +0200
Message-ID: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch series introduces a tap driver for the linuxu platform. The series is
structured as follows:
- Introduce the uk_netdev interface implemented by the tap driver
- Introduce pseudo tap bus to initialize the driver and probe a tap device.
- The tap device discovered are registered with the uk_netdev.
- Configure the netdevice by creating tap network interface.
- Configure the hw address on the tap device.
- Attach the tap device to a bridge interface.
- Fetch and configure the MTU.
- Check if the promiscuous mode is set
- Fetch the txq/rxq information.
- Configure the tx queue.
- Configure the rx queue.
- Start the tap interface.
- Implement packet receive on the tap interface
- Implement packet send on the tap interface
- Fix the error code difference between Unikraft and linux.

Changes since v2:
- Fix the tap_write implementation
- Change the mac generate implementation
- Minor fixes
- Make feature independent from the poll patch

Changes since v1:
- Complete the sys_open implementation with support for flags
- Fix bug in calloc usage.
- Move definitions into the required patches
- Add some comments for the library parameters
- Add descriptions to the struct definitions
- Fix some typos.

Sharan Santhanam (16):
  plat/linuxu/tap: Introduce tap driver
  plat/tap: Bus interface for the tap device
  plat/driver: Add tap device to the uk_netdev
  plat/driver: Create a tap dev during configuration
  plat/driver: Set features supported on tap device
  plat/tap: Get/Set hw_addr
  plat/tap: Add tap to the bridge
  plat/tap: Get/Set MTU
  plat/tap: Get promiscuous mode
  plat/tap: Fetch txq and rxq info
  plat/tap: Setup txq
  plat/tap: Setup rxq
  plat/tap: Start a tap device
  plat/tap: Support tap_netdev_recv
  plat/tap: Support tap_netdev_xmit
  plat/linuxu: Convert linux errno to unikraft errno

 plat/drivers/include/tap/tap.h              |  51 ++
 plat/drivers/tap/tap.c                      | 868 ++++++++++++++++++++
 plat/linuxu/Config.uk                       |  18 +
 plat/linuxu/Makefile.uk                     |  15 +
 plat/linuxu/include/linuxu/syscall-arm_32.h |   6 +
 plat/linuxu/include/linuxu/syscall-x86_64.h |   7 +
 plat/linuxu/include/linuxu/syscall.h        |  86 ++
 plat/linuxu/include/linuxu/tap.h            | 152 ++++
 plat/linuxu/tap_io.c                        | 160 ++++
 9 files changed, 1363 insertions(+)
 create mode 100644 plat/drivers/include/tap/tap.h
 create mode 100644 plat/drivers/tap/tap.c
 create mode 100644 plat/linuxu/include/linuxu/tap.h
 create mode 100644 plat/linuxu/tap_io.c

-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:15:40 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:15:40 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBmm-0001rI-Iv; Wed, 22 Jul 2020 10:15:40 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBmk-0001qB-TY
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:15:38 +0000
X-Inumbo-ID: 48895cd8-cc04-11ea-a18d-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 48895cd8-cc04-11ea-a18d-12813bfff9fa;
 Wed, 22 Jul 2020 10:15:36 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 791F4F200F;
 Wed, 22 Jul 2020 12:15:35 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id Hv0vGIYJrSVX; Wed, 22 Jul 2020 12:15:35 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 4FC41F200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:15:33 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:15:29 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 02/16] plat/tap: Bus interface for the tap device
Date: Wed, 22 Jul 2020 12:14:58 +0200
Message-ID: <20200722101512.16281-3-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
References: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The tap driver registers itself with the uk_bus. The uk_bus on
initialization provide the necessary interface to setup the driver.
The probe callback provides necessary interface to setup the tap
device.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/tap/tap.c | 33 +++++++++++++++++++++++++++++++++
 plat/linuxu/Config.uk  |  1 +
 2 files changed, 34 insertions(+)

diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index 4beb67bd..3435e846 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -37,6 +37,17 @@
 #include <uk/netdev_driver.h>
 #include <uk/netbuf.h>
 #include <uk/errptr.h>
+#include <uk/bus.h>
+
+struct tap_net_drv {
+	/* allocator to initialize the driver data structure */
+	struct uk_alloc *a;
+};
+
+/**
+ * Module level variables
+ */
+static struct tap_net_drv tap_drv = {0};
 
 /**
  * Module functions
@@ -214,3 +225,25 @@ static const struct uk_netdev_ops tap_netdev_ops = {
 	.txq_info_get = tap_netdev_txq_info_get,
 	.rxq_info_get = tap_netdev_rxq_info_get,
 };
+
+/**
+ * Register a tap driver as bus. Currently in Unikraft, the uk_bus interface
+ * provides the necessary to provide callbacks for bring a pseudo device. In the
+ * future we might provide interface to support the pseudo device.
+ */
+static int tap_drv_probe(void)
+{
+	return 0;
+}
+
+static int tap_drv_init(struct uk_alloc *_a)
+{
+	tap_drv.a = _a;
+	return 0;
+}
+
+static struct uk_bus tap_bus = {
+	.init = tap_drv_init,
+	.probe = tap_drv_probe,
+};
+UK_BUS_REGISTER(&tap_bus);
diff --git a/plat/linuxu/Config.uk b/plat/linuxu/Config.uk
index 5df48f3f..3900e8bc 100644
--- a/plat/linuxu/Config.uk
+++ b/plat/linuxu/Config.uk
@@ -22,6 +22,7 @@ if (PLAT_LINUXU)
 	bool "Tap driver"
 	default y if LIBUKNETDEV
 	depends on LIBUKNETDEV
+	select LIBUKBUS
 	help
 		Enable drivers to support tap device on the linuxu platform. The
 		driver implements the uknetdev interface and provides an interface
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:15:43 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:15:43 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBmp-0001sb-Kj; Wed, 22 Jul 2020 10:15:43 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBmo-0001rp-AV
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:15:42 +0000
X-Inumbo-ID: 4ab20520-cc04-11ea-8624-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4ab20520-cc04-11ea-8624-bc764e2007e4;
 Wed, 22 Jul 2020 10:15:40 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id B2D2CF200F;
 Wed, 22 Jul 2020 12:15:39 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id hlQlPsTkSlCw; Wed, 22 Jul 2020 12:15:39 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 73B78F200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:15:37 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:15:30 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 04/16] plat/driver: Create a tap dev during
 configuration
Date: Wed, 22 Jul 2020 12:15:00 +0200
Message-ID: <20200722101512.16281-5-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
References: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch creates a tap device and configures the unikraft net device.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/include/tap/tap.h              |   4 +
 plat/drivers/tap/tap.c                      | 105 +++++++++++++-
 plat/linuxu/Makefile.uk                     |   1 +
 plat/linuxu/include/linuxu/syscall-arm_32.h |   5 +
 plat/linuxu/include/linuxu/syscall-x86_64.h |   6 +
 plat/linuxu/include/linuxu/syscall.h        |  61 ++++++++
 plat/linuxu/include/linuxu/tap.h            | 145 ++++++++++++++++++++
 plat/linuxu/tap_io.c                        |  66 +++++++++
 8 files changed, 392 insertions(+), 1 deletion(-)
 create mode 100644 plat/linuxu/include/linuxu/tap.h
 create mode 100644 plat/linuxu/tap_io.c

diff --git a/plat/drivers/include/tap/tap.h b/plat/drivers/include/tap/tap.h
index 6786e7de..c7ab037c 100644
--- a/plat/drivers/include/tap/tap.h
+++ b/plat/drivers/include/tap/tap.h
@@ -40,4 +40,8 @@
  */
 #define IFNAMSIZ        16
 
+int tap_open(__u32 flags);
+int tap_close(int fd);
+int tap_dev_configure(int fd, __u32 feature_flags, void *arg);
+
 #endif /* __PLAT_DRV_TAP_H */
diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index f817c32a..1a78f610 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -31,6 +31,7 @@
  *
  */
 #include <errno.h>
+#include <stdio.h>
 #include <string.h>
 #include <uk/alloc.h>
 #include <uk/arch/types.h>
@@ -42,6 +43,17 @@
 #include <uk/bus.h>
 #include <tap/tap.h>
 
+/**
+ * The tap driver is supported only on the linuxu platform. Since the driver is
+ * part of the common codebase we add compiler guard to not include the tap
+ * driver from other platforms.
+ */
+#ifdef CONFIG_PLAT_LINUXU
+#include <linuxu/tap.h>
+#else
+#error "The driver is supported on linuxu platform"
+#endif /* CONFIG_PLAT_LINUXU */
+
 #define DRIVER_NAME             "tap-net"
 
 #define ETH_PKT_PAYLOAD_LEN       1500
@@ -50,18 +62,41 @@
  * TODO: Find a better way of forwarding the command line argument to the
  * driver. For now they are defined as macros from this driver.
  */
+
+#define to_tapnetdev(dev) \
+		__containerof(dev, struct tap_net_dev, ndev)
+
+struct uk_netdev_tx_queue {
+	/* tx queue identifier */
+	int queue_id;
+};
+
+struct uk_netdev_rx_queue {
+	/* rx queue identifier */
+	int queue_id;
+};
+
 struct tap_net_dev {
 	/* Net device structure */
 	struct uk_netdev    ndev;
 	/* max number of queues */
 	__u16 max_qpairs;
 	/* Number of rxq configured */
+	__u16 rxq_cnt;
+	/* List of rx queues */
+	UK_TAILQ_HEAD(tap_rxqs, struct uk_netdev_rx_queue) rxqs;
+	/* Number of txq configured */
+	__u16 txq_cnt;
+	/* List of tx queues */
+	UK_TAILQ_HEAD(tap_txqs, struct uk_netdev_tx_queue) txqs;
 	/* The list of the tap device */
 	UK_TAILQ_ENTRY(struct tap_net_dev) next;
 	/* Tap Device identifier */
 	__u16 tid;
 	/* UK Netdevice identifier */
 	__u16 id;
+	/* File Descriptor for the tap device */
+	int tap_fd;
 	/* Name of the character device */
 	char name[IFNAMSIZ];
 	/* MTU of the device */
@@ -133,6 +168,7 @@ static int tap_netdev_rxq_info_get(struct uk_netdev *dev, __u16 queue_id,
 				   struct uk_netdev_queue_info *qinfo);
 static int tap_netdev_txq_info_get(struct uk_netdev *dev, __u16 queue_id,
 				   struct uk_netdev_queue_info *qinfo);
+static int tap_device_create(struct tap_net_dev *tdev, __u32 feature_flags);
 
 /**
  * Local function definitions
@@ -216,6 +252,10 @@ static void tap_netdev_info_get(struct uk_netdev *dev __unused,
 				struct uk_netdev_info *dev_info)
 {
 	UK_ASSERT(dev_info);
+	dev_info->max_rx_queues = 1;
+	dev_info->max_tx_queues = 1;
+	dev_info->nb_encap_tx = 0;
+	dev_info->nb_encap_rx = 0;
 }
 
 static unsigned int tap_netdev_promisc_get(struct uk_netdev *n)
@@ -259,12 +299,75 @@ static int tap_netdev_mac_set(struct uk_netdev *n,
 static int tap_netdev_configure(struct uk_netdev *n,
 				const struct uk_netdev_conf *conf)
 {
-	int rc = -EINVAL;
+	int rc = 0;
+	struct tap_net_dev *tdev = NULL;
+	__u32 feature_flag = 0;
 
 	UK_ASSERT(n && conf);
+	tdev = to_tapnetdev(n);
+
+	if (conf->nb_rx_queues > tdev->max_qpairs
+	    || conf->nb_tx_queues > tdev->max_qpairs) {
+		uk_pr_err(DRIVER_NAME": rx-queue:%d, tx-queue:%d not supported",
+			  conf->nb_rx_queues, conf->nb_tx_queues);
+		return -ENOTSUP;
+	} else if (conf->nb_rx_queues > 1 || conf->nb_tx_queues > 1)
+		/**
+		 * TODO:
+		 * We don't support multi-queues on the uknetdev. Might need to
+		 * revisit this when implementing multi-queue support on
+		 * uknetdev
+		 */
+		feature_flag |= UK_IFF_MULTI_QUEUE;
+
+	/* Open the device and configure the tap interface */
+	rc = tap_device_create(tdev, feature_flag);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed to configure the tap device\n");
+		goto exit;
+	}
+
+	/* Initialize tx/rx queues list */
+	UK_TAILQ_INIT(&tdev->rxqs);
+	tdev->rxq_cnt = 0;
+	UK_TAILQ_INIT(&tdev->txqs);
+	tdev->txq_cnt = 0;
+exit:
 	return rc;
 }
 
+static int tap_device_create(struct tap_net_dev *tdev, __u32 feature_flags)
+{
+	int rc = 0;
+	struct uk_ifreq ifreq = {0};
+
+	/* Open the tap device */
+	rc = tap_open(O_RDWR | O_NONBLOCK);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed(%d) to open the tap device\n",
+			  rc);
+		return rc;
+	}
+
+	tdev->tap_fd = rc;
+
+	rc = tap_dev_configure(tdev->tap_fd, feature_flags, &ifreq);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed to setup the tap device\n");
+		goto close_tap;
+	}
+
+	snprintf(tdev->name, sizeof(tdev->name), "%s", ifreq.ifr_name);
+	uk_pr_info(DRIVER_NAME": Configured tap device %s\n", tdev->name);
+
+exit:
+	return rc;
+close_tap:
+	tap_close(tdev->tap_fd);
+	tdev->tap_fd = -1;
+	goto exit;
+}
+
 static const struct uk_netdev_ops tap_netdev_ops = {
 	.configure = tap_netdev_configure,
 	.rxq_configure = tap_netdev_rxq_setup,
diff --git a/plat/linuxu/Makefile.uk b/plat/linuxu/Makefile.uk
index cdb7cd00..4cfe6219 100644
--- a/plat/linuxu/Makefile.uk
+++ b/plat/linuxu/Makefile.uk
@@ -45,6 +45,7 @@ LIBLINUXUPLAT_SRCS-y              += $(LIBLINUXUPLAT_BASE)/time.c
 LIBLINUXUPLAT_SRCS-y              += $(UK_PLAT_COMMON_BASE)/lcpu.c|common
 LIBLINUXUPLAT_SRCS-y              += $(UK_PLAT_COMMON_BASE)/memory.c|common
 LIBLINUXUPLAT_SRCS-y              += $(LIBLINUXUPLAT_BASE)/io.c
+LIBLINUXUPLAT_SRCS-$(CONFIG_TAP_NET) += $(LIBLINUXUPLAT_BASE)/tap_io.c
 LIBLINUXUPLAT_SRCS-$(CONFIG_ARCH_X86_64) += \
 			$(LIBLINUXUPLAT_BASE)/x86/link64.lds.S
 LIBLINUXUPLAT_SRCS-$(CONFIG_ARCH_ARM_32) += \
diff --git a/plat/linuxu/include/linuxu/syscall-arm_32.h b/plat/linuxu/include/linuxu/syscall-arm_32.h
index ef9323be..093fd629 100644
--- a/plat/linuxu/include/linuxu/syscall-arm_32.h
+++ b/plat/linuxu/include/linuxu/syscall-arm_32.h
@@ -46,6 +46,7 @@
 #define __SC_MUNMAP    91
 #define __SC_EXIT       1
 #define __SC_IOCTL     54
+#define __SC_FCNTL     55
 #define __SC_RT_SIGPROCMASK   126
 #define __SC_ARCH_PRCTL       172
 #define __SC_RT_SIGACTION     174
@@ -57,6 +58,10 @@
 #define __SC_CLOCK_GETTIME    263
 #define __SC_PSELECT6 335
 
+#ifndef O_TMPFILE
+#define O_TMPFILE 020040000
+#endif
+
 /* NOTE: from `man syscall`:
  *
  * ARM/EABI
diff --git a/plat/linuxu/include/linuxu/syscall-x86_64.h b/plat/linuxu/include/linuxu/syscall-x86_64.h
index 553f0ba4..c4b88fc6 100644
--- a/plat/linuxu/include/linuxu/syscall-x86_64.h
+++ b/plat/linuxu/include/linuxu/syscall-x86_64.h
@@ -48,6 +48,7 @@
 #define __SC_RT_SIGPROCMASK 14
 #define __SC_IOCTL  16
 #define __SC_EXIT   60
+#define __SC_FCNTL  72
 #define __SC_ARCH_PRCTL       158
 #define __SC_TIMER_CREATE     222
 #define __SC_TIMER_SETTIME    223
@@ -57,6 +58,11 @@
 #define __SC_CLOCK_GETTIME    228
 #define __SC_PSELECT6 270
 
+
+#ifndef O_TMPFILE
+#define O_TMPFILE 020200000
+#endif
+
 /* NOTE: from linux-4.6.3 (arch/x86/entry/entry_64.S):
  *
  * 64-bit SYSCALL saves rip to rcx, clears rflags.RF, then saves rflags to r11,
diff --git a/plat/linuxu/include/linuxu/syscall.h b/plat/linuxu/include/linuxu/syscall.h
index 0dca7c5c..2c613fc2 100644
--- a/plat/linuxu/include/linuxu/syscall.h
+++ b/plat/linuxu/include/linuxu/syscall.h
@@ -36,6 +36,7 @@
 #ifndef __SYSCALL_H__
 #define __SYSCALL_H__
 
+#include <stdarg.h>
 #include <linuxu/time.h>
 #include <sys/types.h>
 #include <linuxu/signal.h>
@@ -64,6 +65,66 @@ static inline ssize_t sys_write(int fd, const char *buf, size_t len)
 				  (long) (len));
 }
 
+#ifndef O_RDONLY
+#define O_RDONLY                  00000000
+#endif /* O_RDONLY */
+
+#ifndef O_WRONLY
+#define O_WRONLY                  00000001
+#endif /* O_WRONLY */
+#ifndef O_RDWR
+#define O_RDWR                    00000002
+#endif /* O_RDWR */
+
+#ifndef O_NONBLOCK
+#define O_NONBLOCK		 04000
+#endif /* O_NONBLOCK */
+
+#ifndef O_CREAT
+#define O_CREAT        0100
+#endif
+
+
+#ifndef O_CLOEXEC
+#define O_CLOEXEC  02000000
+#endif /* O_CLOEXEC */
+
+
+#ifndef FD_CLOEXEC
+#define FD_CLOEXEC 1
+#endif
+
+#ifndef F_SETFD
+#define F_SETFD  2
+#endif
+
+static inline int sys_open(const char *pathname, int flags, ...)
+{
+	mode_t mode = 0;
+	int fd;
+
+	if ((flags & O_CREAT) || (flags & O_TMPFILE) == O_TMPFILE) {
+		va_list ap;
+
+		va_start(ap, flags);
+		mode = va_arg(ap, mode_t);
+		va_end(ap);
+	}
+
+	fd = syscall3(__SC_OPEN, (long)pathname, (long)flags, (long)mode);
+	if ((fd >= 0) && (flags & O_CLOEXEC))
+		syscall3(__SC_FCNTL, (long) fd, (long)F_SETFD,
+			 (long)FD_CLOEXEC);
+
+	return fd;
+}
+
+static inline int sys_close(int fd)
+{
+	return (ssize_t) syscall1(__SC_CLOSE,
+				  (long) fd);
+}
+
 static inline int sys_exit(int status)
 {
 	return (int) syscall1(__SC_EXIT,
diff --git a/plat/linuxu/include/linuxu/tap.h b/plat/linuxu/include/linuxu/tap.h
new file mode 100644
index 00000000..b408f72b
--- /dev/null
+++ b/plat/linuxu/include/linuxu/tap.h
@@ -0,0 +1,145 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Sharan Santhanam <sharan.santhanam@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#ifndef __PLAT_LINUXU_TAP_H__
+#define __PLAT_LINUXU_TAP_H__
+
+#include <uk/arch/types.h>
+#include <linuxu/syscall.h>
+#include <linuxu/ioctl.h>
+
+/**
+ * TAP Device Path
+ */
+#define TAPDEV_PATH		 "/dev/net/tun"
+/**
+ * Using the musl as reference for the data structure definition
+ * Commit-id: 39ef612aa193
+ */
+#define IFNAMSIZ        16
+
+
+
+typedef __u16 uk_in_port_t;
+typedef __u32 uk_in_addr_t;
+typedef __u16 uk_sa_family_t;
+
+struct uk_in_addr {
+	uk_in_addr_t s_addr;
+};
+
+struct uk_sockaddr {
+	uk_sa_family_t sa_family;
+	char sa_data[14];
+};
+
+struct uk_ifmap {
+	unsigned long int mem_start;
+	unsigned long int mem_end;
+	unsigned short int base_addr;
+	unsigned char irq;
+	unsigned char dma;
+	unsigned char port;
+};
+
+struct uk_ifreq {
+	union {
+		char ifrn_name[IFNAMSIZ];
+	} uk_ifr_ifrn;
+
+	union {
+		struct uk_sockaddr ifru_addr;
+		struct uk_sockaddr ifru_dstaddr;
+		struct uk_sockaddr ifru_broadaddr;
+		struct uk_sockaddr ifru_netmask;
+		struct uk_sockaddr ifru_hwaddr;
+		short int       ifru_flags;
+		int             ifru_ivalue;
+		int             ifru_mtu;
+		struct uk_ifmap    ifru_map;
+		char            ifru_slave[IFNAMSIZ];
+		char            ifru_newname[IFNAMSIZ];
+		char           *ifru_data;
+	} uk_ifr_ifru;
+};
+
+#define ifr_name    uk_ifr_ifrn.ifrn_name
+#define ifr_hwaddr  uk_ifr_ifru.ifru_hwaddr
+#define ifr_addr    uk_ifr_ifru.ifru_addr
+#define ifr_dstaddr uk_ifr_ifru.ifru_dstaddr
+#define ifr_broadaddr   uk_ifr_ifru.ifru_broadaddr
+#define ifr_netmask uk_ifr_ifru.ifru_netmask
+#define ifr_flags   uk_ifr_ifru.ifru_flags
+#define ifr_metric  uk_ifr_ifru.ifru_ivalue
+#define ifr_mtu     uk_ifr_ifru.ifru_mtu
+#define ifr_map     uk_ifr_ifru.ifru_map
+#define ifr_slave   uk_ifr_ifru.ifru_slave
+#define ifr_data    uk_ifr_ifru.ifru_data
+#define ifr_ifindex uk_ifr_ifru.ifru_ivalue
+#define ifr_bandwidth   uk_ifr_ifru.ifru_ivalue
+#define ifr_qlen    uk_ifr_ifru.ifru_ivalue
+#define ifr_newname uk_ifr_ifru.ifru_newname
+
+#define UK_TUNSETIFF     (0x400454ca)
+#define UK_SIOCGIFNAME   (0x8910)
+#define UK_SIOCGIFFLAGS  (0x8913)
+#define UK_SIOCSIFFLAGS  (0x8914)
+#define UK_SIOCGIFADDR   (0x8915)
+#define UK_SIOCSIFADDR   (0x8916)
+#define UK_SIOCGIFMTU    (0x8921)
+#define UK_SIOCSIFMTU    (0x8922)
+#define UK_SIOCSIFHWADDR (0x8924)
+#define UK_SIOCGIFHWADDR (0x8927)
+#define UK_SIOCGIFTXQLEN (0x8942)
+#define UK_SIOCSIFTXQLEN (0x8943)
+#define UK_SIOCGIFINDEX  (0x8933)
+/* TUNSETIFF ifr flags */
+#define UK_IFF_TUN     (0x0001)
+#define UK_IFF_TAP     (0x0002)
+#define UK_IFF_NO_PI   (0x1000)
+/* This flag has no real effect */
+#define UK_IFF_ONE_QUEUE   (0x2000)
+#define UK_IFF_VNET_HDR    (0x4000)
+#define UK_IFF_TUN_EXCL    (0x8000)
+#define UK_IFF_MULTI_QUEUE (0x0100)
+#define UK_IFF_ATTACH_QUEUE (0x0200)
+#define UK_IFF_DETACH_QUEUE (0x0400)
+/* read-only flag */
+#define UK_IFF_PERSIST	(0x0800)
+#define UK_IFF_NOFILTER	(0x1000)
+#define UK_IFF_UP	(0x1)
+#define UK_IFF_PROMISC	(0x100)
+
+/* Adding the bridge interface */
+#define UK_SIOCBRADDIF (0x89a2)
+
+#endif /* __PLAT_LINUXU_TAP_H */
diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
new file mode 100644
index 00000000..fb9adc24
--- /dev/null
+++ b/plat/linuxu/tap_io.c
@@ -0,0 +1,66 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Sharan Santhanam <sharan.santhanam@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <uk/print.h>
+#include <uk/arch/types.h>
+#include <linuxu/tap.h>
+
+int tap_open(__u32 flags)
+{
+	int rc = 0;
+
+	rc = sys_open(TAPDEV_PATH, flags);
+	if (rc < 0)
+		uk_pr_err("Error in opening the tap device\n");
+	return rc;
+}
+
+int tap_dev_configure(int fd, __u32 feature_flags, void *arg)
+{
+	int rc = 0;
+	struct uk_ifreq *ifreq = (struct uk_ifreq *) arg;
+
+	/* Set the tap device configuration */
+	ifreq->ifr_flags = UK_IFF_TAP | UK_IFF_NO_PI | feature_flags;
+	if ((rc = sys_ioctl(fd, UK_TUNSETIFF, ifreq)) < 0)
+		uk_pr_err("Failed(%d) to configure the tap device\n", rc);
+
+	return rc;
+}
+
+int tap_close(int fd)
+{
+	return sys_close(fd);
+}
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:15:45 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:15:45 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBmr-0001tS-Nk; Wed, 22 Jul 2020 10:15:45 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBmp-0001qB-Td
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:15:43 +0000
X-Inumbo-ID: 49c46732-cc04-11ea-a18d-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 49c46732-cc04-11ea-a18d-12813bfff9fa;
 Wed, 22 Jul 2020 10:15:38 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 8C508F200F;
 Wed, 22 Jul 2020 12:15:37 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 7JzDJpvi0LZQ; Wed, 22 Jul 2020 12:15:37 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 611EEF200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:15:35 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:15:30 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 03/16] plat/driver: Add tap device to the uk_netdev
Date: Wed, 22 Jul 2020 12:14:59 +0200
Message-ID: <20200722101512.16281-4-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
References: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch provides the implementation to parse the user provided tap
device information. The tap device detected are registered to the
uk_netdev.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/include/tap/tap.h |  43 ++++++++++
 plat/drivers/tap/tap.c         | 140 +++++++++++++++++++++++++++++++++
 plat/linuxu/Config.uk          |   8 ++
 plat/linuxu/Makefile.uk        |   6 ++
 4 files changed, 197 insertions(+)
 create mode 100644 plat/drivers/include/tap/tap.h

diff --git a/plat/drivers/include/tap/tap.h b/plat/drivers/include/tap/tap.h
new file mode 100644
index 00000000..6786e7de
--- /dev/null
+++ b/plat/drivers/include/tap/tap.h
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Sharan Santhanam <sharan.santhanam@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef __PLAT_DRV_TAP_H
+#define __PLAT_DRV_TAP_H
+
+#include <uk/arch/types.h>
+
+/**
+ * Using the musl as reference for the data structure definition
+ * Commit-id: 39ef612aa193
+ */
+#define IFNAMSIZ        16
+
+#endif /* __PLAT_DRV_TAP_H */
diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index 3435e846..f817c32a 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -31,23 +31,77 @@
  *
  */
 #include <errno.h>
+#include <string.h>
 #include <uk/alloc.h>
 #include <uk/arch/types.h>
 #include <uk/netdev_core.h>
 #include <uk/netdev_driver.h>
 #include <uk/netbuf.h>
 #include <uk/errptr.h>
+#include <uk/libparam.h>
 #include <uk/bus.h>
+#include <tap/tap.h>
+
+#define DRIVER_NAME             "tap-net"
+
+#define ETH_PKT_PAYLOAD_LEN       1500
+
+/**
+ * TODO: Find a better way of forwarding the command line argument to the
+ * driver. For now they are defined as macros from this driver.
+ */
+struct tap_net_dev {
+	/* Net device structure */
+	struct uk_netdev    ndev;
+	/* max number of queues */
+	__u16 max_qpairs;
+	/* Number of rxq configured */
+	/* The list of the tap device */
+	UK_TAILQ_ENTRY(struct tap_net_dev) next;
+	/* Tap Device identifier */
+	__u16 tid;
+	/* UK Netdevice identifier */
+	__u16 id;
+	/* Name of the character device */
+	char name[IFNAMSIZ];
+	/* MTU of the device */
+	__u16  mtu;
+	/* RX promiscuous mode */
+	__u8 promisc : 1;
+	/* State of the net device */
+	__u8 state;
+};
 
 struct tap_net_drv {
 	/* allocator to initialize the driver data structure */
 	struct uk_alloc *a;
+	/* list of tap device */
+	UK_TAILQ_HEAD(tdev_list, struct tap_net_dev) tap_dev_list;
+	/* Number of tap devices */
+	__u16 tap_dev_cnt;
+	/* A list of bridges associated with the bridge */
+	char **bridge_ifs;
 };
 
 /**
  * Module level variables
  */
 static struct tap_net_drv tap_drv = {0};
+static const char *drv_name = DRIVER_NAME;
+static int tap_dev_cnt;
+static char *bridgenames;
+
+/**
+ * Module Parameters.
+ */
+/**
+ * tap.tap_dev_cnt=<# of tap device>
+ */
+UK_LIB_PARAM(tap_dev_cnt, __u32);
+/**
+ * tap.bridgenames="br0 br1 ... brn"
+ */
+UK_LIB_PARAM_STR(bridgenames);
 
 /**
  * Module functions
@@ -226,6 +280,52 @@ static const struct uk_netdev_ops tap_netdev_ops = {
 	.rxq_info_get = tap_netdev_rxq_info_get,
 };
 
+/**
+ * Registering the network device.
+ */
+static int tap_dev_init(int id)
+{
+	struct tap_net_dev *tdev;
+	int rc = 0;
+
+	tdev = uk_zalloc(tap_drv.a, sizeof(*tdev));
+	if (!tdev) {
+		uk_pr_err(DRIVER_NAME": Failed to allocate tap_device\n");
+		rc = -ENOMEM;
+		goto exit;
+	}
+	tdev->ndev.rx_one = tap_netdev_recv;
+	tdev->ndev.tx_one = tap_netdev_xmit;
+	tdev->ndev.ops = &tap_netdev_ops;
+	tdev->tid = id;
+	/**
+	 * TODO:
+	 * As an initial implementation we have limit on the number of queues.
+	 */
+	tdev->max_qpairs = 1;
+
+	/* Registering the tap device with libuknet*/
+	rc = uk_netdev_drv_register(&tdev->ndev, tap_drv.a, drv_name);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed to register the network device\n");
+		goto free_tdev;
+	}
+	tdev->id = rc;
+	rc = 0;
+	tdev->mtu = ETH_PKT_PAYLOAD_LEN;
+	tdev->promisc = 0;
+	uk_pr_info(DRIVER_NAME": device(%d) registered with the libuknet\n",
+		   tdev->id);
+
+	/* Adding the list of devices maintained by this driver */
+	UK_TAILQ_INSERT_TAIL(&tap_drv.tap_dev_list, tdev, next);
+exit:
+	return rc;
+free_tdev:
+	uk_free(tap_drv.a, tdev);
+	goto exit;
+}
+
 /**
  * Register a tap driver as bus. Currently in Unikraft, the uk_bus interface
  * provides the necessary to provide callbacks for bring a pseudo device. In the
@@ -233,12 +333,52 @@ static const struct uk_netdev_ops tap_netdev_ops = {
  */
 static int tap_drv_probe(void)
 {
+	int i;
+	int rc = 0;
+	char *idx = NULL, *prev_idx;
+
+	if (tap_dev_cnt > 0) {
+		tap_drv.bridge_ifs = uk_calloc(tap_drv.a, tap_dev_cnt,
+					       sizeof(char *));
+		if (!tap_drv.bridge_ifs) {
+			uk_pr_err(DRIVER_NAME": Failed to allocate brigde_ifs\n");
+			return -ENOMEM;
+		}
+	}
+
+	idx = bridgenames;
+	for (i = 0; i < tap_dev_cnt; i++) {
+		if (idx) {
+			prev_idx = idx;
+			idx = strchr(idx, ' ');
+			if (idx) {
+				*idx = '\0';
+				idx++;
+			}
+			tap_drv.bridge_ifs[i] = prev_idx;
+			uk_pr_debug(DRIVER_NAME": Adding bridge %s\n",
+				    prev_idx);
+		} else {
+			uk_pr_warn(DRIVER_NAME": Adding tap device %d without bridge\n",
+				   i);
+			tap_drv.bridge_ifs[i] = NULL;
+		}
+
+		rc = tap_dev_init(i);
+		if (rc < 0) {
+			uk_pr_err(DRIVER_NAME": Failed to initialize the tap dev id: %d\n",
+				  i);
+			return rc;
+		}
+		tap_drv.tap_dev_cnt++;
+	}
 	return 0;
 }
 
 static int tap_drv_init(struct uk_alloc *_a)
 {
 	tap_drv.a = _a;
+	UK_TAILQ_INIT(&tap_drv.tap_dev_list);
 	return 0;
 }
 
diff --git a/plat/linuxu/Config.uk b/plat/linuxu/Config.uk
index 3900e8bc..9de0364a 100644
--- a/plat/linuxu/Config.uk
+++ b/plat/linuxu/Config.uk
@@ -23,8 +23,16 @@ if (PLAT_LINUXU)
 	default y if LIBUKNETDEV
 	depends on LIBUKNETDEV
 	select LIBUKBUS
+	imply LIBUKLIBPARAM
 	help
 		Enable drivers to support tap device on the linuxu platform. The
 		driver implements the uknetdev interface and provides an interface
 		for the network stack to send/receive network packets.
+
+	config TAP_DEV_DEBUG
+	bool "Tap Device Debug"
+	default n
+	depends on TAP_NET
+	help
+		Enable debug messages from the tap device.
 endif
diff --git a/plat/linuxu/Makefile.uk b/plat/linuxu/Makefile.uk
index 0850fd99..cdb7cd00 100644
--- a/plat/linuxu/Makefile.uk
+++ b/plat/linuxu/Makefile.uk
@@ -11,6 +11,8 @@ $(eval $(call addplatlib_s,linuxu,liblinuxutapnet,$(CONFIG_TAP_NET)))
 
 ## Adding libparam for the linuxu platform
 $(eval $(call addlib_paramprefix,liblinuxuplat,linuxu))
+$(eval $(call addlib_paramprefix,liblinuxutapnet,tap))
+
 ##
 ## Platform library definitions
 ##
@@ -51,6 +53,10 @@ LIBLINUXUPLAT_SRCS-$(CONFIG_ARCH_ARM_32) += \
 ##
 ## LINUXUTAPNET Source
 LIBLINUXUTAPNET_ASINCLUED-y         += -I$(LIBLINUXUPLAT_BASE)/include
+LIBLINUXUTAPNET_ASINCLUDES-y         += -I$(UK_PLAT_DRIVERS_BASE)/include
 LIBLINUXUTAPNET_CINCLUDES-y         += -I$(LIBLINUXUPLAT_BASE)/include
+LIBLINUXUTAPNET_CINCLUDES-y         += -I$(UK_PLAT_DRIVERS_BASE)/include
+
+LIBLINUXUTAPNET_CFLAGS-$(CONFIG_TAP_DEV_DEBUG) += -DUK_DEBUG
 
 LIBLINUXUTAPNET_SRCS-y		  += $(UK_PLAT_DRIVERS_BASE)/tap/tap.c
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:15:46 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:15:46 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBms-0001u3-Pd; Wed, 22 Jul 2020 10:15:46 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBmr-0001rp-OJ
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:15:45 +0000
X-Inumbo-ID: 4c3e1bde-cc04-11ea-8624-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4c3e1bde-cc04-11ea-8624-bc764e2007e4;
 Wed, 22 Jul 2020 10:15:42 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id B1B65F2010;
 Wed, 22 Jul 2020 12:15:41 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id z9IFSeHgQ3By; Wed, 22 Jul 2020 12:15:41 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 8BED0F200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:15:39 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:15:31 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 05/16] plat/driver: Set features supported on tap
 device
Date: Wed, 22 Jul 2020 12:15:01 +0200
Message-ID: <20200722101512.16281-6-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
References: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/tap/tap.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index 1a78f610..2173095b 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -256,6 +256,7 @@ static void tap_netdev_info_get(struct uk_netdev *dev __unused,
 	dev_info->max_tx_queues = 1;
 	dev_info->nb_encap_tx = 0;
 	dev_info->nb_encap_rx = 0;
+	dev_info->features = 0;
 }
 
 static unsigned int tap_netdev_promisc_get(struct uk_netdev *n)
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:15:51 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:15:51 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBmx-0001vl-RE; Wed, 22 Jul 2020 10:15:51 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBmw-0001rp-OY
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:15:50 +0000
X-Inumbo-ID: 4d798b6e-cc04-11ea-8624-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4d798b6e-cc04-11ea-8624-bc764e2007e4;
 Wed, 22 Jul 2020 10:15:44 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id C0D70F200F;
 Wed, 22 Jul 2020 12:15:43 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id gJJeZx-Ur_2V; Wed, 22 Jul 2020 12:15:43 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 9A4F8F200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:15:41 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:15:32 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 06/16] plat/tap: Get/Set hw_addr
Date: Wed, 22 Jul 2020 12:15:02 +0200
Message-ID: <20200722101512.16281-7-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
References: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch implements support for generating a default hw_addr. The
patch also implements get and set netdev api.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/include/tap/tap.h              |  2 +
 plat/drivers/tap/tap.c                      | 93 ++++++++++++++++++++-
 plat/linuxu/include/linuxu/syscall-arm_32.h |  1 +
 plat/linuxu/include/linuxu/syscall-x86_64.h |  1 +
 plat/linuxu/include/linuxu/syscall.h        | 25 ++++++
 plat/linuxu/include/linuxu/tap.h            |  7 ++
 plat/linuxu/tap_io.c                        | 31 +++++++
 7 files changed, 157 insertions(+), 3 deletions(-)

diff --git a/plat/drivers/include/tap/tap.h b/plat/drivers/include/tap/tap.h
index c7ab037c..42c6d7f1 100644
--- a/plat/drivers/include/tap/tap.h
+++ b/plat/drivers/include/tap/tap.h
@@ -43,5 +43,7 @@
 int tap_open(__u32 flags);
 int tap_close(int fd);
 int tap_dev_configure(int fd, __u32 feature_flags, void *arg);
+int tap_netif_configure(int fd, __u32 request, void *arg);
+int tap_netif_create(void);
 
 #endif /* __PLAT_DRV_TAP_H */
diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index 2173095b..5e510759 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -91,12 +91,16 @@ struct tap_net_dev {
 	UK_TAILQ_HEAD(tap_txqs, struct uk_netdev_tx_queue) txqs;
 	/* The list of the tap device */
 	UK_TAILQ_ENTRY(struct tap_net_dev) next;
+	/* Mac address of the device */
+	struct uk_hwaddr hw_addr;
 	/* Tap Device identifier */
 	__u16 tid;
 	/* UK Netdevice identifier */
 	__u16 id;
 	/* File Descriptor for the tap device */
 	int tap_fd;
+	/* Control socket descriptor */
+	int ctrl_sock;
 	/* Name of the character device */
 	char name[IFNAMSIZ];
 	/* MTU of the device */
@@ -169,6 +173,7 @@ static int tap_netdev_rxq_info_get(struct uk_netdev *dev, __u16 queue_id,
 static int tap_netdev_txq_info_get(struct uk_netdev *dev, __u16 queue_id,
 				   struct uk_netdev_queue_info *qinfo);
 static int tap_device_create(struct tap_net_dev *tdev, __u32 feature_flags);
+static int tap_mac_generate(__u8 *addr, __u8 dev_id);
 
 /**
  * Local function definitions
@@ -284,16 +289,74 @@ static int tap_netdev_mtu_set(struct uk_netdev *n,  __u16 mtu __unused)
 
 static const struct uk_hwaddr *tap_netdev_mac_get(struct uk_netdev *n)
 {
+	struct tap_net_dev *tdev;
+
 	UK_ASSERT(n);
-	return NULL;
+	tdev = to_tapnetdev(n);
+	return &tdev->hw_addr;
 }
 
 static int tap_netdev_mac_set(struct uk_netdev *n,
 			      const struct uk_hwaddr *hwaddr)
 {
-	int rc = -EINVAL;
+	int rc = 0;
+	struct tap_net_dev *tdev;
+	struct uk_ifreq ifrq = {0};
 
 	UK_ASSERT(n && hwaddr);
+	tdev = to_tapnetdev(n);
+
+	snprintf(ifrq.ifr_name, sizeof(ifrq.ifr_name), "%s", tdev->name);
+	uk_pr_info("Setting mac address on tap device %s\n", tdev->name);
+
+#ifdef CONFIG_TAP_DEV_DEBUG
+	int  i;
+
+	for (i = 0; i < UK_NETDEV_HWADDR_LEN; i++) {
+		uk_pr_debug("hw_address: %d - %d\n", i,
+			    hwaddr->addr_bytes[i] & 0xFF);
+	}
+#endif /* CONFIG_TAP_DEV_DEBUG */
+
+	ifrq.ifr_hwaddr.sa_family = AF_LOCAL;
+	memcpy(&ifrq.ifr_hwaddr.sa_data[0], &hwaddr->addr_bytes[0],
+		UK_NETDEV_HWADDR_LEN);
+	rc = tap_netif_configure(tdev->ctrl_sock, UK_SIOCSIFHWADDR, &ifrq);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed(%d) to set the hardware address\n",
+			  rc);
+		goto exit;
+	}
+	memcpy(&tdev->hw_addr, hwaddr, sizeof(*hwaddr));
+
+exit:
+	return rc;
+}
+
+static int tap_mac_generate(__u8 *addr, __u8 dev_id)
+{
+	const char fmt[] = {0x2, 0x0, 0x0, 0x0, 0x0, 0x0};
+
+	UK_ASSERT(addr);
+
+	memcpy(addr, fmt, UK_NETDEV_HWADDR_LEN - 1);
+	*(addr + UK_NETDEV_HWADDR_LEN - 1) = (__u8) (dev_id + 1);
+	return 0;
+}
+
+static inline int tapdev_ctrlsock_create(struct tap_net_dev *tdev)
+{
+	int rc = 0;
+
+	rc = tap_netif_create();
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME":Failed(%d) to create a control socket\n",
+			  rc);
+		goto exit;
+	}
+	tdev->ctrl_sock = rc;
+	rc = 0;
+exit:
 	return rc;
 }
 
@@ -328,13 +391,37 @@ static int tap_netdev_configure(struct uk_netdev *n,
 		goto exit;
 	}
 
-	/* Initialize tx/rx queues list */
+	/* Create a control socket for the network interface */
+	rc = tapdev_ctrlsock_create(tdev);
+	if (rc != 0) {
+		uk_pr_err(DRIVER_NAME": Failed to create a control socket\n");
+		goto close_tap_dev;
+	}
+
+	/* Generate MAC address */
+	tap_mac_generate(&tdev->hw_addr.addr_bytes[0],
+			 tdev->id);
+
+	/* MAC Address configuration */
+	rc = tap_netdev_mac_set(n, &tdev->hw_addr);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed to set the mac address\n");
+		goto close_ctrl_sock;
+	}
+
+	/* Initialize the tx/rx queues */
 	UK_TAILQ_INIT(&tdev->rxqs);
 	tdev->rxq_cnt = 0;
 	UK_TAILQ_INIT(&tdev->txqs);
 	tdev->txq_cnt = 0;
 exit:
 	return rc;
+
+close_ctrl_sock:
+	tap_close(tdev->ctrl_sock);
+close_tap_dev:
+	tap_close(tdev->tap_fd);
+	goto exit;
 }
 
 static int tap_device_create(struct tap_net_dev *tdev, __u32 feature_flags)
diff --git a/plat/linuxu/include/linuxu/syscall-arm_32.h b/plat/linuxu/include/linuxu/syscall-arm_32.h
index 093fd629..4b7218bf 100644
--- a/plat/linuxu/include/linuxu/syscall-arm_32.h
+++ b/plat/linuxu/include/linuxu/syscall-arm_32.h
@@ -56,6 +56,7 @@
 #define __SC_TIMER_GETOVERRUN 260
 #define __SC_TIMER_DELETE     261
 #define __SC_CLOCK_GETTIME    263
+#define __SC_SOCKET           281
 #define __SC_PSELECT6 335
 
 #ifndef O_TMPFILE
diff --git a/plat/linuxu/include/linuxu/syscall-x86_64.h b/plat/linuxu/include/linuxu/syscall-x86_64.h
index c4b88fc6..8714c928 100644
--- a/plat/linuxu/include/linuxu/syscall-x86_64.h
+++ b/plat/linuxu/include/linuxu/syscall-x86_64.h
@@ -47,6 +47,7 @@
 #define __SC_RT_SIGACTION   13
 #define __SC_RT_SIGPROCMASK 14
 #define __SC_IOCTL  16
+#define __SC_SOCKET 41
 #define __SC_EXIT   60
 #define __SC_FCNTL  72
 #define __SC_ARCH_PRCTL       158
diff --git a/plat/linuxu/include/linuxu/syscall.h b/plat/linuxu/include/linuxu/syscall.h
index 2c613fc2..ad6f0381 100644
--- a/plat/linuxu/include/linuxu/syscall.h
+++ b/plat/linuxu/include/linuxu/syscall.h
@@ -125,6 +125,31 @@ static inline int sys_close(int fd)
 				  (long) fd);
 }
 
+#ifndef SOCK_STREAM
+#define SOCK_STREAM    1
+#endif /* SOCK_STREAM */
+#ifndef SOCK_DGRAM
+#define SOCK_DGRAM     2
+#endif /* SOCK_DGRAM */
+
+#ifndef SOCK_RAW
+#define SOCK_RAW       3
+#endif /* SOCK_RAW */
+
+#ifndef AF_LOCAL
+#define AF_LOCAL       1
+#endif /* AF_LOCAL */
+#ifndef AF_INET
+#define AF_INET        2
+#endif /* AF_INET */
+static inline int sys_socket(int domain, int type, int protocol)
+{
+	return (ssize_t) syscall3(__SC_SOCKET,
+				  (long) domain,
+				  (long) type,
+				  (long) protocol);
+}
+
 static inline int sys_exit(int status)
 {
 	return (int) syscall1(__SC_EXIT,
diff --git a/plat/linuxu/include/linuxu/tap.h b/plat/linuxu/include/linuxu/tap.h
index b408f72b..ca48841b 100644
--- a/plat/linuxu/include/linuxu/tap.h
+++ b/plat/linuxu/include/linuxu/tap.h
@@ -57,6 +57,13 @@ struct uk_in_addr {
 	uk_in_addr_t s_addr;
 };
 
+struct uk_sockaddr_in {
+	uk_sa_family_t sin_family;
+	uk_in_port_t sin_port;
+	struct uk_in_addr sin_addr;
+	__u8 sin_zero[8];
+};
+
 struct uk_sockaddr {
 	uk_sa_family_t sa_family;
 	char sa_data[14];
diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
index fb9adc24..24094f2b 100644
--- a/plat/linuxu/tap_io.c
+++ b/plat/linuxu/tap_io.c
@@ -60,6 +60,37 @@ int tap_dev_configure(int fd, __u32 feature_flags, void *arg)
 	return rc;
 }
 
+int tap_netif_configure(int fd, __u32 request, void *arg)
+{
+	int rc;
+	struct uk_ifreq *usr_ifr = (struct uk_ifreq *) arg;
+
+	switch (request) {
+	case UK_SIOCGIFHWADDR:
+	case UK_SIOCSIFHWADDR:
+		break;
+	default:
+		rc = -EINVAL;
+		uk_pr_err("Invalid ioctl request\n");
+		goto exit_error;
+	}
+
+	if ((rc = sys_ioctl(fd, request, usr_ifr)) < 0) {
+		uk_pr_err("Failed to set device control %d\n", rc);
+		goto exit_error;
+	}
+
+	return 0;
+
+exit_error:
+	return rc;
+}
+
+int tap_netif_create(void)
+{
+	return sys_socket(AF_INET, SOCK_DGRAM, 0);
+}
+
 int tap_close(int fd)
 {
 	return sys_close(fd);
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:15:52 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:15:52 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBmy-0001wG-Sq; Wed, 22 Jul 2020 10:15:52 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBmw-0001vR-R9
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:15:50 +0000
X-Inumbo-ID: 5002fc76-cc04-11ea-a18d-12813bfff9fa
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 5002fc76-cc04-11ea-a18d-12813bfff9fa;
 Wed, 22 Jul 2020 10:15:48 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id F1B38103FB2;
 Wed, 22 Jul 2020 12:15:47 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id ykHzfgDETDdP; Wed, 22 Jul 2020 12:15:47 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id D1459102076
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:15:47 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:15:46 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 09/16] plat/tap: Get promiscuous mode
Date: Wed, 22 Jul 2020 12:15:05 +0200
Message-ID: <20200722101512.16281-10-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
References: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch implements function to check for promiscuous mode on the
uk_netdev.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/tap/tap.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index f5b32339..439c3c50 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -319,10 +319,12 @@ static void tap_netdev_info_get(struct uk_netdev *dev __unused,
 
 static unsigned int tap_netdev_promisc_get(struct uk_netdev *n)
 {
+	struct tap_net_dev *tdev;
 
 	UK_ASSERT(n);
+	tdev = to_tapnetdev(n);
 
-	return 0;
+	return tdev->promisc;
 }
 
 static __u16 tap_netdev_mtu_get(struct uk_netdev *n)
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:15:57 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:15:57 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBn2-0001xc-Uo; Wed, 22 Jul 2020 10:15:56 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBn1-0001rp-Oi
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:15:55 +0000
X-Inumbo-ID: 4eb191de-cc04-11ea-8624-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4eb191de-cc04-11ea-8624-bc764e2007e4;
 Wed, 22 Jul 2020 10:15:46 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id CFEB1F2010;
 Wed, 22 Jul 2020 12:15:45 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id Y01rjn8WVEug; Wed, 22 Jul 2020 12:15:45 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id A9E3FF200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:15:43 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:15:32 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 07/16] plat/tap: Add tap to the bridge
Date: Wed, 22 Jul 2020 12:15:03 +0200
Message-ID: <20200722101512.16281-8-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
References: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch implements support to add the tap device to a user provided
bridge.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/tap/tap.c | 60 ++++++++++++++++++++++++++++++++++++++++++
 plat/linuxu/tap_io.c   |  2 ++
 2 files changed, 62 insertions(+)

diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index 5e510759..6b059943 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -174,11 +174,64 @@ static int tap_netdev_txq_info_get(struct uk_netdev *dev, __u16 queue_id,
 				   struct uk_netdev_queue_info *qinfo);
 static int tap_device_create(struct tap_net_dev *tdev, __u32 feature_flags);
 static int tap_mac_generate(__u8 *addr, __u8 dev_id);
+static int tap_dev_br_add(struct tap_net_dev *tdev);
+static int tap_dev_index_get(struct tap_net_dev *tdev);
 
 /**
  * Local function definitions
  */
 
+static int tap_dev_index_get(struct tap_net_dev *tdev)
+{
+	int rc = 0;
+	struct uk_ifreq ifrq = {0};
+
+	snprintf(ifrq.ifr_name, sizeof(ifrq.ifr_name), "%s",
+		     tdev->name);
+
+	rc = tap_netif_configure(tdev->ctrl_sock, UK_SIOCGIFINDEX, &ifrq);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed to fetch the index\n");
+		goto exit;
+	}
+
+	rc = ifrq.ifr_ifindex;
+exit:
+	return rc;
+
+}
+
+static int tap_dev_br_add(struct tap_net_dev *tdev)
+{
+	int rc = -EINVAL;
+	struct uk_ifreq ifrq = {0};
+
+	if (!tap_drv.bridge_ifs[tdev->tid])
+		goto exit;
+
+	/**
+	 * Get the bridge name.
+	 */
+	snprintf(ifrq.ifr_name, sizeof(ifrq.ifr_name), "%s",
+		 tap_drv.bridge_ifs[tdev->tid]);
+
+	rc = tap_dev_index_get(tdev);
+	if (rc < 0)
+		return rc;
+
+	ifrq.ifr_ifindex = rc;
+	rc = tap_netif_configure(tdev->ctrl_sock, UK_SIOCBRADDIF, &ifrq);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed to add the interface %s to bridge %s\n",
+			  tdev->name, tap_drv.bridge_ifs[tdev->tid]);
+		goto exit;
+	}
+	rc = 0;
+
+exit:
+	return rc;
+}
+
 static int tap_netdev_recv(struct uk_netdev *dev,
 			   struct uk_netdev_rx_queue *queue,
 			   struct uk_netbuf **pkt)
@@ -409,6 +462,13 @@ static int tap_netdev_configure(struct uk_netdev *n,
 		goto close_ctrl_sock;
 	}
 
+	rc = tap_dev_br_add(tdev);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed(%d) to add the bridge interface\n",
+			  rc);
+		goto close_ctrl_sock;
+	}
+
 	/* Initialize the tx/rx queues */
 	UK_TAILQ_INIT(&tdev->rxqs);
 	tdev->rxq_cnt = 0;
diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
index 24094f2b..fe1f52a6 100644
--- a/plat/linuxu/tap_io.c
+++ b/plat/linuxu/tap_io.c
@@ -66,8 +66,10 @@ int tap_netif_configure(int fd, __u32 request, void *arg)
 	struct uk_ifreq *usr_ifr = (struct uk_ifreq *) arg;
 
 	switch (request) {
+	case UK_SIOCGIFINDEX:
 	case UK_SIOCGIFHWADDR:
 	case UK_SIOCSIFHWADDR:
+	case UK_SIOCBRADDIF:
 		break;
 	default:
 		rc = -EINVAL;
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:15:57 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:15:57 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBn3-0001xx-15; Wed, 22 Jul 2020 10:15:57 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBn2-0001xS-85
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:15:56 +0000
X-Inumbo-ID: 53fc4f80-cc04-11ea-a18d-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 53fc4f80-cc04-11ea-a18d-12813bfff9fa;
 Wed, 22 Jul 2020 10:15:55 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id ABC9BF200F;
 Wed, 22 Jul 2020 12:15:54 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id Kzc9_iA5EwwY; Wed, 22 Jul 2020 12:15:54 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 83949F200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:15:52 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:15:48 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 13/16] plat/tap: Start a tap device
Date: Wed, 22 Jul 2020 12:15:09 +0200
Message-ID: <20200722101512.16281-14-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
References: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch implements the function to start the tap device

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/tap/tap.c | 21 +++++++++++++++++++--
 plat/linuxu/tap_io.c   | 12 ++++++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index 2667fd10..b7037b64 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -430,10 +430,27 @@ err_exit:
 
 static int tap_netdev_start(struct uk_netdev *n)
 {
-	int rc = -EINVAL;
+	int rc = 0;
+	struct tap_net_dev *tdev = NULL;
+	struct uk_ifreq ifrq = {0};
 
 	UK_ASSERT(n);
-	return rc;
+	tdev = to_tapnetdev(n);
+	/* Set the name of the device */
+	snprintf(ifrq.ifr_name, sizeof(ifrq.ifr_name), "%s", tdev->name);
+
+	ifrq.ifr_flags = UK_IFF_UP | UK_IFF_PROMISC;
+
+	/* Set the status of the device */
+	rc = tap_netif_configure(tdev->ctrl_sock, UK_SIOCSIFFLAGS, &ifrq);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed(%d) to set the flags of if: %s\n",
+			  rc, tdev->name);
+		return rc;
+	}
+	tdev->promisc = 1;
+
+	return 0;
 }
 
 static void tap_netdev_info_get(struct uk_netdev *dev __unused,
diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
index 4828639d..8c44281c 100644
--- a/plat/linuxu/tap_io.c
+++ b/plat/linuxu/tap_io.c
@@ -64,8 +64,20 @@ int tap_netif_configure(int fd, __u32 request, void *arg)
 {
 	int rc;
 	struct uk_ifreq *usr_ifr = (struct uk_ifreq *) arg;
+	struct uk_ifreq ifr = {0};
 
 	switch (request) {
+	case UK_SIOCSIFFLAGS:
+		snprintf(ifr.ifr_name, IFNAMSIZ, "%s", usr_ifr->ifr_name);
+		rc = sys_ioctl(fd, UK_SIOCGIFFLAGS, &ifr);
+		/* fetch current flags to leave other flags untouched */
+		if (rc < 0) {
+			uk_pr_err("Failed to read flags %d\n", rc);
+			goto exit_error;
+		}
+		usr_ifr->ifr_flags |= ifr.ifr_flags;
+		break;
+	case UK_SIOCGIFFLAGS:
 	case UK_SIOCGIFINDEX:
 	case UK_SIOCGIFHWADDR:
 	case UK_SIOCSIFHWADDR:
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:16:00 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:16:00 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBn6-0001z8-2a; Wed, 22 Jul 2020 10:16:00 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBn4-0001xS-U8
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:15:58 +0000
X-Inumbo-ID: 5536c3da-cc04-11ea-a18d-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 5536c3da-cc04-11ea-a18d-12813bfff9fa;
 Wed, 22 Jul 2020 10:15:57 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id B87CCF200F;
 Wed, 22 Jul 2020 12:15:56 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id fblqn8cFhH-l; Wed, 22 Jul 2020 12:15:56 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 94DBBF200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:15:54 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:15:49 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 14/16] plat/tap: Support tap_netdev_recv
Date: Wed, 22 Jul 2020 12:15:10 +0200
Message-ID: <20200722101512.16281-15-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
References: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Implement receive on the tap device.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/include/tap/tap.h |  1 +
 plat/drivers/tap/tap.c         | 48 +++++++++++++++++++++++++++++++++-
 plat/linuxu/tap_io.c           | 13 +++++++++
 3 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/plat/drivers/include/tap/tap.h b/plat/drivers/include/tap/tap.h
index 42c6d7f1..f3e1b3eb 100644
--- a/plat/drivers/include/tap/tap.h
+++ b/plat/drivers/include/tap/tap.h
@@ -45,5 +45,6 @@ int tap_close(int fd);
 int tap_dev_configure(int fd, __u32 feature_flags, void *arg);
 int tap_netif_configure(int fd, __u32 request, void *arg);
 int tap_netif_create(void);
+__ssz tap_read(int fd, void *buf, size_t count);
 
 #endif /* __PLAT_DRV_TAP_H */
diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index b7037b64..03948150 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -254,12 +254,58 @@ static int tap_netdev_recv(struct uk_netdev *dev,
 			   struct uk_netdev_rx_queue *queue,
 			   struct uk_netbuf **pkt)
 {
-	int rc = -EINVAL;
+	int rc = 0;
+	struct tap_net_dev *tdev __maybe_unused;
+	struct uk_netbuf *_pkt = NULL;
 
 	UK_ASSERT(dev);
 	UK_ASSERT(queue && pkt);
 
+	tdev = to_tapnetdev(dev);
+
+	if (!queue->alloc_rxpkts)
+		return -EINVAL;
+
+
+	/**
+	 * Allocate the packet in which the packet will be received.
+	 */
+	rc = queue->alloc_rxpkts(queue->alloc_rxpkts_argp, &_pkt, 1);
+	if (rc == 0) {
+		uk_pr_err(DRIVER_NAME": Failed to allocate the memory\n");
+		rc = -ENOMEM;
+		_pkt = NULL;
+		rc = UK_NETDEV_STATUS_UNDERRUN | UK_NETDEV_STATUS_MORE;
+		return rc;
+	}
+	uk_pr_debug(DRIVER_NAME": Receiving on interface %s(%d) %p(%d)\n",
+		    tdev->name, queue->fd, _pkt->data, _pkt->len);
+	rc = tap_read(queue->fd, _pkt->data, _pkt->len);
+
+	if (rc > 0) {
+		uk_pr_debug(DRIVER_NAME": Recv pkt size: %d\n", rc);
+		/* Setting the length of the packet */
+		_pkt->len = rc;
+		rc = UK_NETDEV_STATUS_SUCCESS | UK_NETDEV_STATUS_MORE;
+	} else if (rc == 0 || rc == -EWOULDBLOCK || rc == -EAGAIN) {
+		rc = 0;
+		goto err_exit;
+	} else {
+		uk_pr_err(DRIVER_NAME": Failed(%d) to read the packet\n", rc);
+		goto err_exit;
+	}
+	uk_pr_debug("uk_netdev buf ptr: %p\n", _pkt);
+
+	*pkt = _pkt;
+
+exit:
 	return rc;
+
+err_exit:
+	if (_pkt)
+		uk_netbuf_free(_pkt);
+	*pkt = NULL;
+	goto exit;
 }
 
 static int tap_netdev_xmit(struct uk_netdev *dev,
diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
index 8c44281c..1072c60f 100644
--- a/plat/linuxu/tap_io.c
+++ b/plat/linuxu/tap_io.c
@@ -109,6 +109,19 @@ int tap_netif_create(void)
 	return sys_socket(AF_INET, SOCK_DGRAM, 0);
 }
 
+ssize_t tap_read(int fd, void *buf, size_t count)
+{
+	ssize_t rc = -EINTR;
+
+	while (rc == -EINTR)
+		rc = sys_read(fd, buf, count);
+
+	if (rc < 0)
+		uk_pr_err("Failed(%ld) to read from the tap device\n", rc);
+
+	return rc;
+}
+
 int tap_close(int fd)
 {
 	return sys_close(fd);
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:16:01 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:16:01 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBn7-0001zk-4B; Wed, 22 Jul 2020 10:16:01 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBn6-0001rp-Ov
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:16:00 +0000
X-Inumbo-ID: 4fee429a-cc04-11ea-8624-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4fee429a-cc04-11ea-8624-bc764e2007e4;
 Wed, 22 Jul 2020 10:15:48 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id E157CF200F;
 Wed, 22 Jul 2020 12:15:47 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id G4nWnAx11uW7; Wed, 22 Jul 2020 12:15:47 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id B97E9F200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:15:45 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:15:33 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 08/16] plat/tap: Get/Set MTU
Date: Wed, 22 Jul 2020 12:15:04 +0200
Message-ID: <20200722101512.16281-9-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
References: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch implements mtu get and set functions.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/tap/tap.c | 28 +++++++++++++++++++++++++---
 plat/linuxu/tap_io.c   |  2 ++
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index 6b059943..f5b32339 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -327,15 +327,37 @@ static unsigned int tap_netdev_promisc_get(struct uk_netdev *n)
 
 static __u16 tap_netdev_mtu_get(struct uk_netdev *n)
 {
+	int rc = 0;
+	struct tap_net_dev *tdev;
+	struct uk_ifreq ifrq = {0};
+
 	UK_ASSERT(n);
-	return 0;
+	tdev = to_tapnetdev(n);
+	snprintf(ifrq.ifr_name, sizeof(ifrq.ifr_name), "%s", tdev->name);
+
+	rc = tap_netif_configure(tdev->ctrl_sock, UK_SIOCGIFMTU, &ifrq);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed(%d) to get the mtu\n", rc);
+		return rc;
+	}
+
+	return ifrq.ifr_mtu;
 }
 
-static int tap_netdev_mtu_set(struct uk_netdev *n,  __u16 mtu __unused)
+static int tap_netdev_mtu_set(struct uk_netdev *n,  __u16 mtu)
 {
-	int rc = -EINVAL;
+	int rc = 0;
+	struct tap_net_dev *tdev;
+	struct uk_ifreq ifrq = {0};
 
 	UK_ASSERT(n);
+	tdev = to_tapnetdev(n);
+	snprintf(ifrq.ifr_name, sizeof(ifrq.ifr_name), "%s", tdev->name);
+
+	ifrq.ifr_mtu = mtu;
+	rc = tap_netif_configure(tdev->ctrl_sock, UK_SIOCSIFMTU, &ifrq);
+	if (rc < 0)
+		uk_pr_err(DRIVER_NAME": Failed(%d) to set the mtu\n", rc);
 
 	return rc;
 }
diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
index fe1f52a6..896b8cc2 100644
--- a/plat/linuxu/tap_io.c
+++ b/plat/linuxu/tap_io.c
@@ -69,6 +69,8 @@ int tap_netif_configure(int fd, __u32 request, void *arg)
 	case UK_SIOCGIFINDEX:
 	case UK_SIOCGIFHWADDR:
 	case UK_SIOCSIFHWADDR:
+	case UK_SIOCSIFMTU:
+	case UK_SIOCGIFMTU:
 	case UK_SIOCBRADDIF:
 		break;
 	default:
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:16:05 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:16:05 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBnB-00021B-69; Wed, 22 Jul 2020 10:16:05 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBn9-0001xS-UE
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:16:03 +0000
X-Inumbo-ID: 57aa2dbe-cc04-11ea-a18d-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 57aa2dbe-cc04-11ea-a18d-12813bfff9fa;
 Wed, 22 Jul 2020 10:16:01 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id D696FF200F;
 Wed, 22 Jul 2020 12:16:00 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id Kg7DC7H50s44; Wed, 22 Jul 2020 12:16:00 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id AE2ADF200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:15:58 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:15:50 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 16/16] plat/linuxu: Convert linux errno to
 unikraft errno
Date: Wed, 22 Jul 2020 12:15:12 +0200
Message-ID: <20200722101512.16281-17-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
References: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

There are differences in errno between linux and unikraft. This patch
converts EAGAIN which is 11 in linux to unikraft which is 35.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/linuxu/tap_io.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
index edef18ed..efacf5f9 100644
--- a/plat/linuxu/tap_io.c
+++ b/plat/linuxu/tap_io.c
@@ -116,7 +116,10 @@ ssize_t tap_read(int fd, void *buf, size_t count)
 	while (rc == -EINTR)
 		rc = sys_read(fd, buf, count);
 
-	if (rc < 0)
+	if (rc == -11)
+		/* Explicitly added since linux errno has -11 for EAGAIN */
+		rc = -EWOULDBLOCK;
+	else if (rc < 0)
 		uk_pr_err("Failed(%ld) to read from the tap device\n", rc);
 
 	return rc;
@@ -131,7 +134,16 @@ ssize_t tap_write(int fd, const void *buf, size_t count)
 		rc = sys_write(fd, buf + written, count);
 		if (rc == -EINTR)
 			continue;
-		else if (rc < 0) {
+		else if (rc == -11) {
+			/*
+			 * Explicitly added since linux errno has -11 for
+			 * EAGAIN.
+			 * FIXME: EAGAIN is not the only error code affected by
+			 * this issue (eg EDESTADDRREQ, EDQUOT). We should think
+			 * of a more generic solution to address it.
+			 */
+			rc = -EAGAIN;
+		} else if (rc < 0) {
 			uk_pr_err("Failed(%ld) to write to the tap device\n",
 				  rc);
 			return rc;
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:16:06 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:16:06 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBnC-00021m-80; Wed, 22 Jul 2020 10:16:06 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBnB-0001rp-P6
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:16:05 +0000
X-Inumbo-ID: 4fd43988-cc04-11ea-8624-bc764e2007e4
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4fd43988-cc04-11ea-8624-bc764e2007e4;
 Wed, 22 Jul 2020 10:15:48 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 12BFE102076;
 Wed, 22 Jul 2020 12:15:48 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id GtEoFJDz36Dv; Wed, 22 Jul 2020 12:15:47 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id D8CC0103F92
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:15:47 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:15:47 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 10/16] plat/tap: Fetch txq and rxq info
Date: Wed, 22 Jul 2020 12:15:06 +0200
Message-ID: <20200722101512.16281-11-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
References: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch implements functions to retrieve information of the rxq and
txq.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/tap/tap.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index 439c3c50..abcfc877 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -258,18 +258,31 @@ static int tap_netdev_xmit(struct uk_netdev *dev,
 
 static int tap_netdev_txq_info_get(struct uk_netdev *dev __unused,
 				   __u16 queue_id __unused,
-				   struct uk_netdev_queue_info *qinfo __unused)
+				   struct uk_netdev_queue_info *qinfo)
 {
-	return -EINVAL;
+	UK_ASSERT(qinfo);
+
+	qinfo->nb_min = 1;
+	qinfo->nb_max = __U16_MAX;
+	qinfo->nb_align = 4;
+	qinfo->nb_is_power_of_two = 0;
+	return 0;
 }
 
 static int tap_netdev_rxq_info_get(struct uk_netdev *dev __unused,
 				   __u16 queue_id __unused,
-				   struct uk_netdev_queue_info *qinfo __unused)
+				   struct uk_netdev_queue_info *qinfo)
 {
-	return -EINVAL;
+	UK_ASSERT(qinfo);
+
+	qinfo->nb_min = 1;
+	qinfo->nb_max = __U16_MAX;
+	qinfo->nb_align = 4;
+	qinfo->nb_is_power_of_two = 0;
+	return 0;
 }
 
+
 static struct uk_netdev_rx_queue *tap_netdev_rxq_setup(struct uk_netdev *dev,
 						       __u16 queue_id __unused,
 						       __u16 nb_desc __unused,
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:16:11 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:16:11 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBnH-00023L-9d; Wed, 22 Jul 2020 10:16:11 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBnG-0001rp-PO
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:16:10 +0000
X-Inumbo-ID: 517fa25c-cc04-11ea-8624-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 517fa25c-cc04-11ea-8624-bc764e2007e4;
 Wed, 22 Jul 2020 10:15:51 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 8996CF200F;
 Wed, 22 Jul 2020 12:15:50 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id mksuqoLffh7V; Wed, 22 Jul 2020 12:15:50 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 6001FF200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:15:48 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:15:47 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 11/16] plat/tap: Setup txq
Date: Wed, 22 Jul 2020 12:15:07 +0200
Message-ID: <20200722101512.16281-12-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
References: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Tap driver implements the function to setup the txq.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/tap/tap.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index abcfc877..182ace45 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -69,6 +69,12 @@
 struct uk_netdev_tx_queue {
 	/* tx queue identifier */
 	int queue_id;
+	/* List of tx queue */
+	UK_TAILQ_ENTRY(struct uk_netdev_tx_queue) next;
+	/* Allocator for the txq */
+	struct uk_alloc *a;
+	/* Set the file descriptor for the tap device */
+	int fd;
 };
 
 struct uk_netdev_rx_queue {
@@ -298,17 +304,34 @@ static struct uk_netdev_rx_queue *tap_netdev_rxq_setup(struct uk_netdev *dev,
 }
 
 static struct uk_netdev_tx_queue *tap_netdev_txq_setup(struct uk_netdev *dev,
-						       __u16 queue_id __unused,
+						       __u16 queue_id,
 						       __u16 nb_desc __unused,
 					struct uk_netdev_txqueue_conf *conf)
 {
-	int rc = -EINVAL;
+	int rc = 0;
 	struct uk_netdev_tx_queue *txq = NULL;
+	struct tap_net_dev *tdev = NULL;
 
 	UK_ASSERT(dev && conf);
 
-	txq = ERR2PTR(rc);
+	tdev = to_tapnetdev(dev);
+	txq = uk_zalloc(conf->a, sizeof(*txq));
+	if (!txq) {
+		uk_pr_err(DRIVER_NAME": Failed to allocate the tx queue\n");
+		rc = -ENOMEM;
+		goto err_exit;
+	}
+
+	txq->queue_id = queue_id;
+	txq->fd = tdev->tap_fd;
+	txq->a = conf->a;
+	UK_TAILQ_INSERT_TAIL(&tdev->txqs, txq, next);
+	tdev->txq_cnt++;
+exit:
 	return txq;
+err_exit:
+	txq = ERR2PTR(rc);
+	goto exit;
 }
 
 static int tap_netdev_start(struct uk_netdev *n)
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:16:16 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:16:16 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBnM-00024h-BI; Wed, 22 Jul 2020 10:16:16 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBnL-0001rp-SE
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:16:15 +0000
X-Inumbo-ID: 524a01b6-cc04-11ea-8624-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 524a01b6-cc04-11ea-8624-bc764e2007e4;
 Wed, 22 Jul 2020 10:15:53 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 9A567F200F;
 Wed, 22 Jul 2020 12:15:52 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id NP6DoVAuTSCK; Wed, 22 Jul 2020 12:15:52 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 72801F200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:15:50 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:15:48 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 12/16] plat/tap: Setup rxq
Date: Wed, 22 Jul 2020 12:15:08 +0200
Message-ID: <20200722101512.16281-13-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
References: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Tap driver implements the function to setup the rxq.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/tap/tap.c | 102 +++++++++++++++++++++++++++++++++++++++--
 plat/linuxu/tap_io.c   |   2 +
 2 files changed, 100 insertions(+), 4 deletions(-)

diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index 182ace45..2667fd10 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -80,6 +80,18 @@ struct uk_netdev_tx_queue {
 struct uk_netdev_rx_queue {
 	/* rx queue identifier */
 	int queue_id;
+	/* number of rx descriptors */
+	__u16 nb_desc;
+	/* list of rx queue */
+	UK_TAILQ_ENTRY(struct uk_netdev_rx_queue) next;
+	/* Allocator for the rxq */
+	struct uk_alloc *a;
+	/* Set the file descriptor for the tap device */
+	int fd;
+	/* Callback for filling the buffer */
+	uk_netdev_alloc_rxpkts alloc_rxpkts;
+	/* Reference to a user data */
+	void *alloc_rxpkts_argp;
 };
 
 struct tap_net_dev {
@@ -288,19 +300,101 @@ static int tap_netdev_rxq_info_get(struct uk_netdev *dev __unused,
 	return 0;
 }
 
+static int tap_dev_rxqlen_get(struct tap_net_dev *tdev)
+{
+	int rc = 0;
+	struct uk_ifreq ifrq = {0};
+
+	/* Set the name of the device */
+	snprintf(ifrq.ifr_name, sizeof(ifrq.ifr_name), "%s", tdev->name);
+
+	/* Set the status of the device */
+	rc = tap_netif_configure(tdev->ctrl_sock, UK_SIOCGIFTXQLEN, &ifrq);
+	if (rc < 0) {
+		rc = -errno;
+		uk_pr_err(DRIVER_NAME": Failed(%d) to set the flags of if: %s\n",
+			  rc, tdev->name);
+		return rc;
+	}
+	uk_pr_info(DRIVER_NAME": rxq length is %d\n", ifrq.ifr_qlen);
+	return ifrq.ifr_qlen;
+}
+
+static int tap_dev_rxqlen_set(struct tap_net_dev *tdev, __u16 qlen)
+{
+	int rc = 0;
+	struct uk_ifreq ifrq = {0};
+
+	/* Set the name of the device */
+	snprintf(ifrq.ifr_name, sizeof(ifrq.ifr_name), "%s", tdev->name);
+	ifrq.ifr_qlen = qlen;
+
+	/* Set the status of the device */
+	rc = tap_netif_configure(tdev->ctrl_sock, UK_SIOCSIFTXQLEN, &ifrq);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed(%d) to set the flags of if: %s\n",
+			  rc, tdev->name);
+		return rc;
+	}
+	uk_pr_info(DRIVER_NAME": rxq length is %d\n", ifrq.ifr_qlen);
+	return rc;
+}
 
 static struct uk_netdev_rx_queue *tap_netdev_rxq_setup(struct uk_netdev *dev,
-						       __u16 queue_id __unused,
-						       __u16 nb_desc __unused,
+						       __u16 queue_id,
+						       __u16 nb_desc,
 					struct uk_netdev_rxqueue_conf *conf)
 {
-	int rc = -EINVAL;
+	int rc = 0;
 	struct uk_netdev_rx_queue *rxq = NULL;
+	struct tap_net_dev *tdev = NULL;
+	__u16 qlen = 0;
 
 	UK_ASSERT(dev && conf);
 
-	rxq = ERR2PTR(rc);
+	tdev = to_tapnetdev(dev);
+	/* Fetch the default queue length of the rx queue */
+	rc = tap_dev_rxqlen_get(tdev);
+	if (rc < 0) {
+		uk_pr_err(DRIVER_NAME": Failed to fetch the tx queue length\n");
+		goto err_exit;
+	}
+	qlen = rc;
+	rc = 0;
+
+	/* Allocate the rx queue */
+	rxq = uk_zalloc(conf->a, sizeof(*rxq));
+	if  (!rxq) {
+		uk_pr_err(DRIVER_NAME": Failed to allocate the rx queue %d",
+			  queue_id);
+		rc = -ENOMEM;
+		goto err_exit;
+	}
+
+	rxq->queue_id = queue_id;
+	rxq->nb_desc = (nb_desc > 0) ? nb_desc : qlen;
+	if (qlen != rxq->nb_desc) {
+		rc = tap_dev_rxqlen_set(tdev, rxq->nb_desc);
+		if (rc < 0) {
+			uk_pr_err(DRIVER_NAME": Failed to setup the rx queue with %d descriptors\n",
+				  rxq->nb_desc);
+			goto free_rxq;
+		}
+	}
+
+	rxq->a = conf->a;
+	rxq->alloc_rxpkts = conf->alloc_rxpkts;
+	rxq->alloc_rxpkts_argp = conf->alloc_rxpkts_argp;
+	rxq->fd = tdev->tap_fd;
+	UK_TAILQ_INSERT_TAIL(&tdev->rxqs, rxq, next);
+	tdev->rxq_cnt++;
+exit:
 	return rxq;
+free_rxq:
+	uk_free(conf->a, rxq);
+err_exit:
+	rxq = ERR2PTR(rc);
+	goto exit;
 }
 
 static struct uk_netdev_tx_queue *tap_netdev_txq_setup(struct uk_netdev *dev,
diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
index 896b8cc2..4828639d 100644
--- a/plat/linuxu/tap_io.c
+++ b/plat/linuxu/tap_io.c
@@ -71,6 +71,8 @@ int tap_netif_configure(int fd, __u32 request, void *arg)
 	case UK_SIOCSIFHWADDR:
 	case UK_SIOCSIFMTU:
 	case UK_SIOCGIFMTU:
+	case UK_SIOCSIFTXQLEN:
+	case UK_SIOCGIFTXQLEN:
 	case UK_SIOCBRADDIF:
 		break;
 	default:
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:16:21 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:16:21 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBnR-00025s-E4; Wed, 22 Jul 2020 10:16:21 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBnQ-0001rp-Pk
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:16:20 +0000
X-Inumbo-ID: 562b6432-cc04-11ea-8624-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 562b6432-cc04-11ea-8624-bc764e2007e4;
 Wed, 22 Jul 2020 10:15:59 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id C552CF200F;
 Wed, 22 Jul 2020 12:15:58 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id BKqNctuF7o2Z; Wed, 22 Jul 2020 12:15:58 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id A19CAF200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:15:56 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:15:49 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v3 15/16] plat/tap: Support tap_netdev_xmit
Date: Wed, 22 Jul 2020 12:15:11 +0200
Message-ID: <20200722101512.16281-16-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
References: <20200722101512.16281-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Implement packet send on a tap device.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 plat/drivers/include/tap/tap.h |  1 +
 plat/drivers/tap/tap.c         | 15 +++++++++++++--
 plat/linuxu/tap_io.c           | 20 ++++++++++++++++++++
 3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/plat/drivers/include/tap/tap.h b/plat/drivers/include/tap/tap.h
index f3e1b3eb..8bd1d888 100644
--- a/plat/drivers/include/tap/tap.h
+++ b/plat/drivers/include/tap/tap.h
@@ -46,5 +46,6 @@ int tap_dev_configure(int fd, __u32 feature_flags, void *arg);
 int tap_netif_configure(int fd, __u32 request, void *arg);
 int tap_netif_create(void);
 __ssz tap_read(int fd, void *buf, size_t count);
+__ssz tap_write(int fd, const void *buf, size_t count);
 
 #endif /* __PLAT_DRV_TAP_H */
diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index 03948150..f0257f8f 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -273,7 +273,6 @@ static int tap_netdev_recv(struct uk_netdev *dev,
 	rc = queue->alloc_rxpkts(queue->alloc_rxpkts_argp, &_pkt, 1);
 	if (rc == 0) {
 		uk_pr_err(DRIVER_NAME": Failed to allocate the memory\n");
-		rc = -ENOMEM;
 		_pkt = NULL;
 		rc = UK_NETDEV_STATUS_UNDERRUN | UK_NETDEV_STATUS_MORE;
 		return rc;
@@ -281,7 +280,6 @@ static int tap_netdev_recv(struct uk_netdev *dev,
 	uk_pr_debug(DRIVER_NAME": Receiving on interface %s(%d) %p(%d)\n",
 		    tdev->name, queue->fd, _pkt->data, _pkt->len);
 	rc = tap_read(queue->fd, _pkt->data, _pkt->len);
-
 	if (rc > 0) {
 		uk_pr_debug(DRIVER_NAME": Recv pkt size: %d\n", rc);
 		/* Setting the length of the packet */
@@ -313,10 +311,23 @@ static int tap_netdev_xmit(struct uk_netdev *dev,
 			   struct uk_netbuf *pkt)
 {
 	int rc = -EINVAL;
+	struct tap_net_dev *tdev __unused;
 
 	UK_ASSERT(dev);
 	UK_ASSERT(queue && pkt);
 
+	tdev = to_tapnetdev(dev);
+
+	rc = tap_write(queue->fd, pkt->data, pkt->len);
+	if (rc > 0) {
+		uk_pr_info(DRIVER_NAME": Send packet of size %d\n", rc);
+		uk_netbuf_free(pkt);
+		rc = UK_NETDEV_STATUS_SUCCESS | UK_NETDEV_STATUS_MORE;
+	} else if (rc == -EWOULDBLOCK || rc == -EAGAIN) {
+		uk_pr_info(DRIVER_NAME": The send queue is full\n");
+		rc = UK_NETDEV_STATUS_UNDERRUN;
+	}
+
 	return rc;
 }
 
diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
index 1072c60f..edef18ed 100644
--- a/plat/linuxu/tap_io.c
+++ b/plat/linuxu/tap_io.c
@@ -122,6 +122,26 @@ ssize_t tap_read(int fd, void *buf, size_t count)
 	return rc;
 }
 
+ssize_t tap_write(int fd, const void *buf, size_t count)
+{
+	ssize_t rc = -EINTR;
+	size_t written = 0;
+
+	while (count > 0) {
+		rc = sys_write(fd, buf + written, count);
+		if (rc == -EINTR)
+			continue;
+		else if (rc < 0) {
+			uk_pr_err("Failed(%ld) to write to the tap device\n",
+				  rc);
+			return rc;
+		}
+		count -= rc;
+		written += rc;
+	}
+	return (ssize_t)written;
+}
+
 int tap_close(int fd)
 {
 	return sys_close(fd);
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 10:18:11 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 10:18:11 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyBpC-00029p-Jq; Wed, 22 Jul 2020 10:18:10 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyBpB-00029k-RX
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 10:18:09 +0000
X-Inumbo-ID: a37dc7dc-cc04-11ea-a18d-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id a37dc7dc-cc04-11ea-a18d-12813bfff9fa;
 Wed, 22 Jul 2020 10:18:08 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 00D3EF200F;
 Wed, 22 Jul 2020 12:18:08 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id vh-Ux_A3Css2; Wed, 22 Jul 2020 12:18:07 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id B9FC1F200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 12:18:05 +0200 (CEST)
Received: from [10.7.1.9] (192.168.24.96) by puck.office.hd (192.168.24.91)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 12:18:05 +0200
Subject: Re: [UNIKRAFT/LIBLWIP PATCH v3 00/16] Introduce a tap driver for
 Unikraft
References: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
To: "minios-devel@lists.xen.org" <minios-devel@lists.xen.org>
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
Message-ID: <6db6ba63-3d47-0379-d8c5-4b5ef0fc0ff2@neclab.eu>
Date: Wed, 22 Jul 2020 12:18:03 +0200
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200722100403.15662-1-sharan.santhanam@neclab.eu>
Content-Type: text/plain; charset="utf-8"; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: titania.office.hd (192.168.24.89) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Please ignore this patch series. The patch series is intended for the 
Unikraft and not lwip.

Thanks & Regards
Sharan

On 7/22/20 12:03 PM, Sharan Santhanam wrote:
> The patch series introduces a tap driver for the linuxu platform. The series is
> structured as follows:
> - Introduce the uk_netdev interface implemented by the tap driver
> - Introduce pseudo tap bus to initialize the driver and probe a tap device.
> - The tap device discovered are registered with the uk_netdev.
> - Configure the netdevice by creating tap network interface.
> - Configure the hw address on the tap device.
> - Attach the tap device to a bridge interface.
> - Fetch and configure the MTU.
> - Check if the promiscuous mode is set
> - Fetch the txq/rxq information.
> - Configure the tx queue.
> - Configure the rx queue.
> - Start the tap interface.
> - Implement packet receive on the tap interface
> - Implement packet send on the tap interface
> - Fix the error code difference between Unikraft and linux.
> 
> Changes since v2:
> - Fix the tap_write implementation
> - Change the mac generate implementation
> - Minor fixes
> - Make feature independent from the poll patch
> 
> Changes since v1:
> - Complete the sys_open implementation with support for flags
> - Fix bug in calloc usage.
> - Move definitions into the required patches
> - Add some comments for the library parameters
> - Add descriptions to the struct definitions
> - Fix some typos.
> 
> 
> Sharan Santhanam (16):
>    plat/linuxu/tap: Introduce tap driver
>    plat/tap: Bus interface for the tap device
>    plat/driver: Add tap device to the uk_netdev
>    plat/driver: Create a tap dev during configuration
>    plat/driver: Set features supported on tap device
>    plat/tap: Get/Set hw_addr
>    plat/tap: Add tap to the bridge
>    plat/tap: Get/Set MTU
>    plat/tap: Get promiscuous mode
>    plat/tap: Fetch txq and rxq info
>    plat/tap: Setup txq
>    plat/tap: Setup rxq
>    plat/tap: Start a tap device
>    plat/tap: Support tap_netdev_recv
>    plat/tap: Support tap_netdev_xmit
>    plat/linuxu: Convert linux errno to unikraft errno
> 
>   plat/drivers/include/tap/tap.h              |  51 ++
>   plat/drivers/tap/tap.c                      | 868 ++++++++++++++++++++
>   plat/linuxu/Config.uk                       |  18 +
>   plat/linuxu/Makefile.uk                     |  15 +
>   plat/linuxu/include/linuxu/syscall-arm_32.h |   6 +
>   plat/linuxu/include/linuxu/syscall-x86_64.h |   7 +
>   plat/linuxu/include/linuxu/syscall.h        |  86 ++
>   plat/linuxu/include/linuxu/tap.h            | 152 ++++
>   plat/linuxu/tap_io.c                        | 160 ++++
>   9 files changed, 1363 insertions(+)
>   create mode 100644 plat/drivers/include/tap/tap.h
>   create mode 100644 plat/drivers/tap/tap.c
>   create mode 100644 plat/linuxu/include/linuxu/tap.h
>   create mode 100644 plat/linuxu/tap_io.c
> 


From minios-devel-bounces@lists.xenproject.org Wed Jul 22 13:27:33 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 13:27:33 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyEmP-0002WR-Ib; Wed, 22 Jul 2020 13:27:29 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyEmO-0002WM-Li
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 13:27:28 +0000
X-Inumbo-ID: 14e274bd-cc1f-11ea-864b-bc764e2007e4
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 14e274bd-cc1f-11ea-864b-bc764e2007e4;
 Wed, 22 Jul 2020 13:27:26 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 06259103A52;
 Wed, 22 Jul 2020 15:27:26 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id cn5iT2fKz6kn; Wed, 22 Jul 2020 15:27:25 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id D66B1103968
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 15:27:25 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 15:27:25 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v4 0/2] ipaddr, netmask and gwaddr as library argument
Date: Wed, 22 Jul 2020 15:27:11 +0200
Message-ID: <20200722132713.23989-1-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch series allow user to pass the ip address, net mask and the gateway
address as a library argument to the uknetdev library. The library arguments
are net.ipv4_addr, net.ipv4_subnet_mask and net.ipv4_gw_addr.

Changes since v3:
- Name changes
- Priority of the command line argument

Changes since v2:
- Add/Fix code comments
- Fix debug prints

Changes since v1:
-Make it ipv4 specific

Sharan Santhanam (2):
  lib/uknetdev: Add ipaddr, netmask & gwaddr as arg
  lib/uknetdev: Get the ipaddr, gw_addr and subnet

 lib/uknetdev/Config.uk                |   1 +
 lib/uknetdev/Makefile.uk              |   1 +
 lib/uknetdev/include/uk/netdev_core.h |   9 +++
 lib/uknetdev/netdev.c                 | 107 ++++++++++++++++++++++++--
 4 files changed, 113 insertions(+), 5 deletions(-)

-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 13:27:34 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 13:27:34 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyEmU-0002Wr-KD; Wed, 22 Jul 2020 13:27:34 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyEmT-0002WM-HN
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 13:27:33 +0000
X-Inumbo-ID: 16fdde44-cc1f-11ea-864b-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 16fdde44-cc1f-11ea-864b-bc764e2007e4;
 Wed, 22 Jul 2020 13:27:29 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id B4CB7F200F;
 Wed, 22 Jul 2020 15:27:28 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id d9JzrA1IU-lP; Wed, 22 Jul 2020 15:27:28 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 7CEDDF200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 15:27:26 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 15:27:26 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v4 1/2] lib/uknetdev: Add ipaddr,
 netmask & gwaddr as arg
Date: Wed, 22 Jul 2020 15:27:12 +0200
Message-ID: <20200722132713.23989-2-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722132713.23989-1-sharan.santhanam@neclab.eu>
References: <20200722132713.23989-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The patch adds ip address, netmask and the gateway address as library
argument. The parameters are list of argument delimited by a space.
The library user can forward the argument using the following command
line:
net.ipv4_addr, net.ipv4_subnet_mask, net.ipv4_gw_addr

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 lib/uknetdev/Config.uk                |  1 +
 lib/uknetdev/Makefile.uk              |  1 +
 lib/uknetdev/include/uk/netdev_core.h |  9 ++++
 lib/uknetdev/netdev.c                 | 75 +++++++++++++++++++++++++++
 4 files changed, 86 insertions(+)

diff --git a/lib/uknetdev/Config.uk b/lib/uknetdev/Config.uk
index 618e8e67..186dd462 100644
--- a/lib/uknetdev/Config.uk
+++ b/lib/uknetdev/Config.uk
@@ -4,6 +4,7 @@ menuconfig LIBUKNETDEV
 	select LIBNOLIBC if !HAVE_LIBC
 	select LIBUKDEBUG
 	select LIBUKALLOC
+	imply LIBUKLIBPARAM
 
 if LIBUKNETDEV
 	config LIBUKNETDEV_MAXNBQUEUES
diff --git a/lib/uknetdev/Makefile.uk b/lib/uknetdev/Makefile.uk
index ca08b254..abdcd4bc 100644
--- a/lib/uknetdev/Makefile.uk
+++ b/lib/uknetdev/Makefile.uk
@@ -1,4 +1,5 @@
 $(eval $(call addlib_s,libuknetdev,$(CONFIG_LIBUKNETDEV)))
+$(eval $(call addlib_paramprefix,libuknetdev,net))
 
 CINCLUDES-$(CONFIG_LIBUKNETDEV)		+= -I$(LIBUKNETDEV_BASE)/include
 CXXINCLUDES-$(CONFIG_LIBUKNETDEV)	+= -I$(LIBUKNETDEV_BASE)/include
diff --git a/lib/uknetdev/include/uk/netdev_core.h b/lib/uknetdev/include/uk/netdev_core.h
index dba719fc..1fe5f2a5 100644
--- a/lib/uknetdev/include/uk/netdev_core.h
+++ b/lib/uknetdev/include/uk/netdev_core.h
@@ -373,6 +373,12 @@ struct uk_netdev_data {
 	const char           *drv_name;
 };
 
+struct uk_netdev_einfo {
+	const char *ipv4_addr;
+	const char *ipv4_net_mask;
+	const char *ipv4_gw_addr;
+};
+
 /**
  * NETDEV
  * A structure used to interact with a network device.
@@ -400,6 +406,9 @@ struct uk_netdev {
 	struct uk_netdev_tx_queue   *_tx_queue[CONFIG_LIBUKNETDEV_MAXNBQUEUES];
 
 	UK_TAILQ_ENTRY(struct uk_netdev) _list;
+
+	/** Netdevice address configuration */
+	struct uk_netdev_einfo *_einfo;
 };
 
 #ifdef __cplusplus
diff --git a/lib/uknetdev/netdev.c b/lib/uknetdev/netdev.c
index 151e0897..096973a3 100644
--- a/lib/uknetdev/netdev.c
+++ b/lib/uknetdev/netdev.c
@@ -38,10 +38,62 @@
 #include <string.h>
 #include <uk/netdev.h>
 #include <uk/print.h>
+#include <uk/libparam.h>
 
 struct uk_netdev_list uk_netdev_list =
 	UK_TAILQ_HEAD_INITIALIZER(uk_netdev_list);
 static uint16_t netdev_count;
+/**
+ * TODO: Define Network argument format when multiple driver device need to
+ * coexist. For example like:
+ * Driver Name:IP Address:Net Mask
+ */
+static char *ipv4_addr;
+static char *ipv4_subnet_mask;
+static char *ipv4_gw_addr;
+
+UK_LIB_PARAM_STR(ipv4_addr);
+UK_LIB_PARAM_STR(ipv4_subnet_mask);
+UK_LIB_PARAM_STR(ipv4_gw_addr);
+
+static const char *_parse_ipv4_addr(void)
+{
+	/** Remember the reference to the ip address for successive calls*/
+	static char *ip_addr;
+
+	if (ip_addr)
+		return strtok_r(NULL, " ", &ip_addr);
+	else if (ipv4_addr)
+		return strtok_r(ipv4_addr, " ", &ip_addr);
+
+	return NULL;
+}
+
+static const char *_parse_ipv4_net_mask(void)
+{
+	/** Remember the reference to the netmask for successive calls*/
+	static char *net_mask;
+
+	if (net_mask)
+		return strtok_r(NULL, " ", &net_mask);
+	else if (ipv4_subnet_mask)
+		return strtok_r(ipv4_subnet_mask, " ", &net_mask);
+
+	return NULL;
+}
+
+static const char *_parse_ipv4_gw_addr(void)
+{
+	/** Remember the reference to the gateway address for successive calls*/
+	static char *gw;
+
+	if (gw)
+		return strtok_r(NULL, " ", &gw);
+	else if (ipv4_gw_addr)
+		return strtok_r(ipv4_gw_addr, " ", &gw);
+
+	return NULL;
+}
 
 static struct uk_netdev_data *_alloc_data(struct uk_alloc *a,
 					  uint16_t netdev_id,
@@ -64,6 +116,25 @@ static struct uk_netdev_data *_alloc_data(struct uk_alloc *a,
 	return data;
 }
 
+static struct uk_netdev_einfo *_alloc_einfo(struct uk_alloc *a)
+{
+	struct uk_netdev_einfo *_einfo = NULL;
+
+	if (ipv4_addr || ipv4_subnet_mask || ipv4_gw_addr) {
+		_einfo = uk_zalloc(a, sizeof(*_einfo));
+		if (!_einfo) {
+			uk_pr_warn("Failed to allocate memory for netdev config\n");
+			return NULL;
+		}
+
+		_einfo->ipv4_addr = _parse_ipv4_addr();
+		_einfo->ipv4_net_mask = _parse_ipv4_net_mask();
+		_einfo->ipv4_gw_addr = _parse_ipv4_gw_addr();
+	}
+
+	return _einfo;
+}
+
 int uk_netdev_drv_register(struct uk_netdev *dev, struct uk_alloc *a,
 			   const char *drv_name)
 {
@@ -91,6 +162,10 @@ int uk_netdev_drv_register(struct uk_netdev *dev, struct uk_alloc *a,
 	if (!dev->_data)
 		return -ENOMEM;
 
+	dev->_einfo = _alloc_einfo(a);
+	if (!dev->_einfo)
+		return -ENOMEM;
+
 	UK_TAILQ_INSERT_TAIL(&uk_netdev_list, dev, _list);
 	uk_pr_info("Registered netdev%"PRIu16": %p (%s)\n",
 		   netdev_count, dev, drv_name);
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 13:27:34 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 13:27:34 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyEmU-0002X5-Lt; Wed, 22 Jul 2020 13:27:34 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=vsaZ=BB=neclab.eu=sharan.santhanam@srs-us1.protection.inumbo.net>)
 id 1jyEmT-0002Wj-Q4
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 13:27:33 +0000
X-Inumbo-ID: 182d7202-cc1f-11ea-a1a5-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 182d7202-cc1f-11ea-a1a5-12813bfff9fa;
 Wed, 22 Jul 2020 13:27:31 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id B4AC7F2010;
 Wed, 22 Jul 2020 15:27:30 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id UyyKlO_ZTFoa; Wed, 22 Jul 2020 15:27:30 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 88F7FF200E
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 15:27:28 +0200 (CEST)
Received: from N-1309.office.hd (192.168.24.96) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul
 2020 15:27:26 +0200
From: Sharan Santhanam <sharan.santhanam@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH v4 2/2] lib/uknetdev: Get the ipaddr,
 gw_addr and subnet
Date: Wed, 22 Jul 2020 15:27:13 +0200
Message-ID: <20200722132713.23989-3-sharan.santhanam@neclab.eu>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200722132713.23989-1-sharan.santhanam@neclab.eu>
References: <20200722132713.23989-1-sharan.santhanam@neclab.eu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The user of uknetdev can pass the ipaddr, gw_addr and subnet as a
library argument. The library argument can be retrieved from the
network stack using uk_netdev_einfo_get function. The library
arguments are retrieved only if the driver does not support the
uk_netdev_einfo_get callback.

Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
---
 lib/uknetdev/netdev.c | 32 +++++++++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 5 deletions(-)

diff --git a/lib/uknetdev/netdev.c b/lib/uknetdev/netdev.c
index 096973a3..74be618a 100644
--- a/lib/uknetdev/netdev.c
+++ b/lib/uknetdev/netdev.c
@@ -236,17 +236,39 @@ void uk_netdev_info_get(struct uk_netdev *dev,
 				      dev_info->max_tx_queues);
 }
 
+static const void *_netdev_einfo_get(struct uk_netdev *dev,
+				enum uk_netdev_einfo_type einfo)
+{
+	switch (einfo) {
+	case UK_NETDEV_IPV4_ADDR_STR:
+		if (dev->_einfo->ipv4_addr)
+			uk_pr_debug("ip_addr: %s\n", dev->_einfo->ipv4_addr);
+		return dev->_einfo->ipv4_addr;
+	case UK_NETDEV_IPV4_MASK_STR:
+		if (dev->_einfo->ipv4_net_mask)
+			uk_pr_debug("netmask: %s\n", dev->_einfo->ipv4_net_mask);
+		return dev->_einfo->ipv4_net_mask;
+	case UK_NETDEV_IPV4_GW_STR:
+		if (dev->_einfo->ipv4_gw_addr)
+			uk_pr_debug("Gateway: %s\n", dev->_einfo->ipv4_gw_addr);
+		return dev->_einfo->ipv4_gw_addr;
+	default:
+		uk_pr_warn("Option %d not yet supported\n", einfo);
+	}
+	return NULL;
+}
+
 const void *uk_netdev_einfo_get(struct uk_netdev *dev,
 				enum uk_netdev_einfo_type einfo)
 {
 	UK_ASSERT(dev);
 	UK_ASSERT(dev->ops);
 
-	if (!dev->ops->einfo_get) {
-		/* driver does not provide any extra configuration */
-		return NULL;
-	}
-	return dev->ops->einfo_get(dev, einfo);
+	if (dev->_einfo)
+		return _netdev_einfo_get(dev, einfo);
+	else if (dev->ops->einfo_get)
+		return dev->ops->einfo_get(dev, einfo);
+	return NULL;
 }
 
 int uk_netdev_rxq_info_get(struct uk_netdev *dev, uint16_t queue_id,
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Wed Jul 22 20:22:34 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 20:22:34 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyLG2-0006ot-7H; Wed, 22 Jul 2020 20:22:30 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=+B0Z=BB=gmail.com=dincadaniel97@srs-us1.protection.inumbo.net>)
 id 1jyLG0-0006oo-QN
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 20:22:28 +0000
X-Inumbo-ID: 0ff290e2-cc59-11ea-86a7-bc764e2007e4
Received: from mail-il1-x12f.google.com (unknown [2607:f8b0:4864:20::12f])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 0ff290e2-cc59-11ea-86a7-bc764e2007e4;
 Wed, 22 Jul 2020 20:22:28 +0000 (UTC)
Received: by mail-il1-x12f.google.com with SMTP id p15so2418702ilh.13
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 13:22:28 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:from:date:message-id:subject:to:cc;
 bh=CywKgmsCjI40iBUkoc07tGqdl+cDOimPMu8/QVs0ZPU=;
 b=pJ8AJS5XoALaaRv/o7/OizrUBpvnzBZAmVHZeLEiw3bDo94lwht9VSBinMUkSB0j3b
 U/xPbqUGu1szd1AE22iW1T905a58j+TrYHjYEwIds7PfsZgU17afFunBkWg9185SezK5
 AsWUaOBJ/RsKz7a+EulYdeKv8DEDkzbZLfXAdiOxWkQFFXIqE6+x/kFrJq1uoRNvNHp/
 w3jUeYzf4ygHARimBrfxh461LgFdixtMTeOOk/62s1EOibENP0aRrWrv1WhNMkMNA7Ex
 pV7BqmDtJGtJVo0HHB+wZql54EBANHgsxjhNk+oqsWXlkxryCLbuz0l8SwZg5tozUv3b
 KItQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc;
 bh=CywKgmsCjI40iBUkoc07tGqdl+cDOimPMu8/QVs0ZPU=;
 b=Pc8G6YeMpvrszuv8c1VjzjxovBo0nBHZlDu7qwF1K3ci8+xTa0vWmX5DbVszhQwDW4
 1eY0Y921rI7juaPEeYgdJMN2eIIs+sgV+FRCfhKgRJaDvp8HJwl8BO2kRCTvIMuhEWQL
 6IxQlERtqlK2E/WmspjFxjIxUcBZyRKM4nKyyisROEU3Hq9A/qGHI4ONzI+aB905Z9ZY
 B3KpZc+onXEnpmNplG/rXYEL2U1uY5oCRl8YqfIphhc6x58OoNCrWDPMW/1mVdEENtMg
 61P69vBAyPdn4E2urXUcfuHMs8hf3+KZQFRuVyP9k71z2UFW0mouTLYFrBAHBZ9RoluR
 ECNA==
X-Gm-Message-State: AOAM533e8FZ/CqW9pF0HPLxw3Qso11Tl56VMpDiFwX8YA3fHVIrbO7UH
 3HhqsmeKU9YrxIVF9GxohcxIZn1R8vhMukr4ra5angPm
X-Google-Smtp-Source: ABdhPJzEw702FQFoNoHSZIOQI+24j7r4QJjnRe3TTum52a/GHe9iU7bg22P6oE+9vY70dIvBmNuLF9+zp6Dq5gNYzsk=
X-Received: by 2002:a92:41c9:: with SMTP id o192mr1518399ila.21.1595449347527; 
 Wed, 22 Jul 2020 13:22:27 -0700 (PDT)
MIME-Version: 1.0
From: Daniel Dinca <dincadaniel97@gmail.com>
Date: Wed, 22 Jul 2020 23:22:16 +0300
Message-ID: <CALjJXS4=Vf+CaGyFj1Sz4+cFqRB1=YeiWweWkgY5jXHJ72uxfg@mail.gmail.com>
Subject: [UNIKRAFT PATCH] lib/ukdebug: expose trace buffer size to the
 menuconfig
To: minios-devel@lists.xen.org
Content-Type: multipart/alternative; boundary="0000000000009dda1c05ab0d7f33"
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: dincadaniel97@gmail.com
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

--0000000000009dda1c05ab0d7f33
Content-Type: text/plain; charset="UTF-8"

This mail refers to this patch:
https://lists.xenproject.org/archives/html/minios-devel/2020-06/msg00007.html
(I
was not on the mailing list when this patch was sent, so I can't directly
reply to it)

Reviewed-by: Daniel Dinca
<dincadaniel97@gmail.com>

--0000000000009dda1c05ab0d7f33
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">This mail refers to this patch:=C2=A0<a href=3D"https://li=
sts.xenproject.org/archives/html/minios-devel/2020-06/msg00007.html">https:=
//lists.xenproject.org/archives/html/minios-devel/2020-06/msg00007.html</a>=
=C2=A0(I was not on the mailing list when this patch was sent, so I can&#39=
;t directly reply to it)<div><br></div><div>Reviewed-by: Daniel Dinca</div>=
<div>&lt;<a href=3D"mailto:dincadaniel97@gmail.com">dincadaniel97@gmail.com=
</a>&gt;</div></div>

--0000000000009dda1c05ab0d7f33--


From minios-devel-bounces@lists.xenproject.org Wed Jul 22 20:31:23 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 22 Jul 2020 20:31:23 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyLOc-0007lQ-Cc; Wed, 22 Jul 2020 20:31:22 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=+B0Z=BB=gmail.com=dincadaniel97@srs-us1.protection.inumbo.net>)
 id 1jyLOa-0007lK-V1
 for minios-devel@lists.xen.org; Wed, 22 Jul 2020 20:31:21 +0000
X-Inumbo-ID: 4d1d882c-cc5a-11ea-86a7-bc764e2007e4
Received: from mail-io1-xd35.google.com (unknown [2607:f8b0:4864:20::d35])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4d1d882c-cc5a-11ea-86a7-bc764e2007e4;
 Wed, 22 Jul 2020 20:31:20 +0000 (UTC)
Received: by mail-io1-xd35.google.com with SMTP id v6so3985903iob.4
 for <minios-devel@lists.xen.org>; Wed, 22 Jul 2020 13:31:20 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:from:date:message-id:subject:to:cc;
 bh=m3v/K01or5IbFHkWnfAuxCXUR8DeyPbqxW7hbOP+k6w=;
 b=HoNqZd0wzRoHUESeuEKdtr9E3ctO8aj2ffTembzeZz/zddM0gCCbykX+DTS5XDZSX3
 jxXgXQa8fRx2lyqQTCMfhDchXK17PkoDD+OSZ+697Egxtzm3qSAaLznMnEZ1/4tp6IGv
 aeQhTmMfd3jiD78aZ26Y68+TAlr2O0GX0RRuCa3617Gsi7ggHxPvndywxSFRdegoY5I/
 2RAwbi7s5IhdqjyKfsUwqB7/wnNKDjXoAIM/aZsjRCewYusTHAbUcUT/9CXRfvL0CXbv
 8sPipuqLOCToyxjJv+gjxjOonEtxp7yoMEIqypP6LuSjiWp7xzTGZ6K/lWgKegPR6hlX
 WWmw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc;
 bh=m3v/K01or5IbFHkWnfAuxCXUR8DeyPbqxW7hbOP+k6w=;
 b=fJNX9g4Sqn0VVdpzPZbvcKG1SbBuz/Og49doNwfcayK1RIsvKaBbTOuhuVZYZKVKSW
 mrcNmRyJu+Vy3lysQPcnV/DeT5yhd+8iVz2SYC4oe8eskqF4sz4+VUb9TNyamTcaIr1b
 3MPJSNxT2PY0SKOttG6+kafBAg4YytQ9kaIZYy9RSshpWbSamYdJJrEz8m16KRuCioWy
 NkrtJfeTKZkk4ZFEQolaEapIOsUNbGE+oIsCcLF1EIpzOU1nQdoxIZWZEn8wwMWlJSae
 Em5sBuDZtJIYwsn2gVjN5Pm9O8Ljn04pfTE3qVm/ExYqwEIp7kKVmAOu3ISOLpjhwDKP
 KOOg==
X-Gm-Message-State: AOAM533oE6HP0X35CuMIJStyegfTpOzKpkAEXZC04T/+Y55F5/wrOwKz
 hTAOnRK3UP5iPorW/vF2jUTuLf7Fxr5y2nA4d5ztFKJB
X-Google-Smtp-Source: ABdhPJzjyaBRicR82BX3qD4YzPkKjFmCk7+VWrDZTSsimvstztboNA4B8dseekE89CVxUf6x11ppKCNQGGF1ygOUGYk=
X-Received: by 2002:a05:6638:594:: with SMTP id
 a20mr1043848jar.127.1595449879659; 
 Wed, 22 Jul 2020 13:31:19 -0700 (PDT)
MIME-Version: 1.0
From: Daniel Dinca <dincadaniel97@gmail.com>
Date: Wed, 22 Jul 2020 23:31:08 +0300
Message-ID: <CALjJXS6x3q=b3bGYkcTyHZ9X8UPp3UGSAehBa-zENhpKP-q0Pg@mail.gmail.com>
Subject: [UNIKRAFT PATCH] pci_bus: implement recursive PCI bus enumeration
To: minios-devel@lists.xen.org
Content-Type: multipart/alternative; boundary="00000000000055879205ab0d9f21"
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: dincadaniel97@gmail.com
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

--00000000000055879205ab0d9f21
Content-Type: text/plain; charset="UTF-8"

This mail refers to this patch:
https://lists.xenproject.org/archives/html/minios-devel/2020-06/msg00004.html
(I
was not on the mailing list when this patch was sent, so I can't directly
reply to it)

Reviewed-by: Daniel Dinca
<dincadaniel97@gmail.com>

--00000000000055879205ab0d9f21
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">This mail refers to this patch:=C2=A0<a href=3D"https://li=
sts.xenproject.org/archives/html/minios-devel/2020-06/msg00004.html">https:=
//lists.xenproject.org/archives/html/minios-devel/2020-06/msg00004.html</a>=
=C2=A0(I was not on the mailing list when this patch was sent, so I can&#39=
;t directly reply to it)<div><br></div><div>Reviewed-by: Daniel Dinca</div>=
<div>&lt;<a href=3D"mailto:dincadaniel97@gmail.com" target=3D"_blank">dinca=
daniel97@gmail.com</a>&gt;</div></div>

--00000000000055879205ab0d9f21--


From minios-devel-bounces@lists.xenproject.org Thu Jul 23 08:15:39 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 08:15:39 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyWO7-0003Ok-PR; Thu, 23 Jul 2020 08:15:35 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=gEn1=BC=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jyWO6-0003Of-LC
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 08:15:34 +0000
X-Inumbo-ID: ada6644a-ccbc-11ea-a267-12813bfff9fa
Received: from mh-is-0.lancs.ac.uk (unknown [148.88.65.128])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id ada6644a-ccbc-11ea-a267-12813bfff9fa;
 Thu, 23 Jul 2020 08:15:33 +0000 (UTC)
Received: from p57b866f1.dip0.t-ipconnect.de ([87.184.102.241]
 helo=unknown.fritz.box)
 by mh-is-0.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jyWO3-000CvU-0F; Thu, 23 Jul 2020 09:15:32 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 0/2] Introduce ukarch_spinwait()
Date: Thu, 23 Jul 2020 10:15:24 +0200
Message-Id: <20200723081526.50677-1-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-0.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>, Costin Lupu <costin.lupu@cs.pub.ro>,
 Alexander Jung <a.jung@lancs.ac.uk>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This series introduces `ukarch_spinwait` methods across architectures
as a mechanic during busy wait loops.  For x86, it calls the `pause`
instruction which improves the performance of spin-wait loops.

The same method is provided for ARM architectures however this
instruction is not supported and so the method is blank.

Alexander Jung (2):
  arch/x86: Provide ukarch_spinwait pause instruction
  arch/arm: Provide ukarch_spinwait noop for ARM

 arch/arm/arm/include/uk/asm/lcpu.h    | 5 +++++
 arch/arm/arm64/include/uk/asm/lcpu.h  | 5 +++++
 arch/x86/x86_64/include/uk/asm/lcpu.h | 6 ++++++
 3 files changed, 16 insertions(+)

-- 
2.11.0



From minios-devel-bounces@lists.xenproject.org Thu Jul 23 08:15:39 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 08:15:39 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyWOB-0003PC-R6; Thu, 23 Jul 2020 08:15:39 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=gEn1=BC=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jyWOA-0003Ou-Io
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 08:15:38 +0000
X-Inumbo-ID: af5df460-ccbc-11ea-86e9-bc764e2007e4
Received: from mh-is-0.lancs.ac.uk (unknown [148.88.65.128])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id af5df460-ccbc-11ea-86e9-bc764e2007e4;
 Thu, 23 Jul 2020 08:15:36 +0000 (UTC)
Received: from p57b866f1.dip0.t-ipconnect.de ([87.184.102.241]
 helo=unknown.fritz.box)
 by mh-is-0.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jyWO5-000CvU-2e; Thu, 23 Jul 2020 09:15:35 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 1/2] arch/x86: Provide ukarch_spinwait pause
 instruction
Date: Thu, 23 Jul 2020 10:15:25 +0200
Message-Id: <20200723081526.50677-2-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200723081526.50677-1-a.jung@lancs.ac.uk>
References: <20200723081526.50677-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-0.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>, Costin Lupu <costin.lupu@cs.pub.ro>,
 Alexander Jung <a.jung@lancs.ac.uk>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This commit introduces the new global `ukarch_spinwait` for x86
which calls the instruction `pause`.  It's a more intelligent
instruction to call during a spinwait-type operation preventing
over utilization of an x86 CPU and so increases performance.

More details on the instruction can be found at [0].

[0]: https://c9x.me/x86/html/file_module_x86_id_232.html

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 arch/x86/x86_64/include/uk/asm/lcpu.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/x86/x86_64/include/uk/asm/lcpu.h b/arch/x86/x86_64/include/uk/asm/lcpu.h
index 6a471a1..f1fd463 100644
--- a/arch/x86/x86_64/include/uk/asm/lcpu.h
+++ b/arch/x86/x86_64/include/uk/asm/lcpu.h
@@ -118,4 +118,10 @@ static inline unsigned long ukarch_read_sp(void)
 	__asm__ __volatile__("mov %%rsp, %0" : "=r"(sp));
 	return sp;
 }
+
+static inline void ukarch_spinwait(void)
+{
+	__asm__ __volatile__("pause" : : : "memory");
+}
+
 #endif /* !__ASSEMBLY__ */
-- 
2.11.0



From minios-devel-bounces@lists.xenproject.org Thu Jul 23 08:15:40 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 08:15:40 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyWOC-0003Pd-TT; Thu, 23 Jul 2020 08:15:40 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=gEn1=BC=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jyWOB-0003Of-GV
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 08:15:39 +0000
X-Inumbo-ID: b0f646ba-ccbc-11ea-a267-12813bfff9fa
Received: from mh-is-0.lancs.ac.uk (unknown [148.88.65.128])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id b0f646ba-ccbc-11ea-a267-12813bfff9fa;
 Thu, 23 Jul 2020 08:15:38 +0000 (UTC)
Received: from p57b866f1.dip0.t-ipconnect.de ([87.184.102.241]
 helo=unknown.fritz.box)
 by mh-is-0.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jyWO8-000CvU-35; Thu, 23 Jul 2020 09:15:38 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH 2/2] arch/arm: Provide ukarch_spinwait noop for ARM
Date: Thu, 23 Jul 2020 10:15:26 +0200
Message-Id: <20200723081526.50677-3-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200723081526.50677-1-a.jung@lancs.ac.uk>
References: <20200723081526.50677-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-0.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>, Costin Lupu <costin.lupu@cs.pub.ro>,
 Alexander Jung <a.jung@lancs.ac.uk>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

ARM does not support a pause-type instruction for busy spin wait
operations.  This commit provides the same alias to be used in
instances where it is required but defaults to a blank operation.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 arch/arm/arm/include/uk/asm/lcpu.h   | 5 +++++
 arch/arm/arm64/include/uk/asm/lcpu.h | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/arch/arm/arm/include/uk/asm/lcpu.h b/arch/arm/arm/include/uk/asm/lcpu.h
index cdeffc3..f38ffb9 100644
--- a/arch/arm/arm/include/uk/asm/lcpu.h
+++ b/arch/arm/arm/include/uk/asm/lcpu.h
@@ -57,3 +57,8 @@ struct __regs {
 #ifndef wmb
 #define wmb() __asm__("dsb" : : : "memory")
 #endif
+
+static inline void ukarch_spinwait(void)
+{
+	/* Intelligent busy wait not supported on arm. */
+}
diff --git a/arch/arm/arm64/include/uk/asm/lcpu.h b/arch/arm/arm64/include/uk/asm/lcpu.h
index 45d1b23..51e17ad 100644
--- a/arch/arm/arm64/include/uk/asm/lcpu.h
+++ b/arch/arm/arm64/include/uk/asm/lcpu.h
@@ -146,4 +146,9 @@ static inline unsigned long ukarch_read_sp(void)
 	return sp;
 }
 
+static inline void ukarch_spinwait(void)
+{
+	/* Intelligent busy wait not supported on arm64. */
+}
+
 #endif /* __ASSEMBLY__ */
-- 
2.11.0



From minios-devel-bounces@lists.xenproject.org Thu Jul 23 09:04:27 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 09:04:27 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyX9M-0007xn-4L; Thu, 23 Jul 2020 09:04:24 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=u2GH=BC=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jyX9K-0007xi-VY
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 09:04:23 +0000
X-Inumbo-ID: 7e69d598-ccc3-11ea-a26b-12813bfff9fa
Received: from mx.upb.ro (unknown [141.85.13.200])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 7e69d598-ccc3-11ea-a26b-12813bfff9fa;
 Thu, 23 Jul 2020 09:04:20 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 74FE9B5617CC;
 Thu, 23 Jul 2020 12:04:19 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id nIppK-Aysf6G; Thu, 23 Jul 2020 12:04:17 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 4D557B561CBF;
 Thu, 23 Jul 2020 12:04:17 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id QXKCCzPt_YGh; Thu, 23 Jul 2020 12:04:17 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id CF237B5617CC;
 Thu, 23 Jul 2020 12:04:16 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH 1/2] arch/x86: Provide ukarch_spinwait pause
 instruction
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200723081526.50677-1-a.jung@lancs.ac.uk>
 <20200723081526.50677-2-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <b09e6c3e-4367-b3ad-173d-bce5c259bf3c@cs.pub.ro>
Date: Thu, 23 Jul 2020 12:04:16 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200723081526.50677-2-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>

On 7/23/20 11:15 AM, Alexander Jung wrote:
> This commit introduces the new global `ukarch_spinwait` for x86
> which calls the instruction `pause`.  It's a more intelligent
> instruction to call during a spinwait-type operation preventing
> over utilization of an x86 CPU and so increases performance.
> 
> More details on the instruction can be found at [0].
> 
> [0]: https://c9x.me/x86/html/file_module_x86_id_232.html
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  arch/x86/x86_64/include/uk/asm/lcpu.h | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/arch/x86/x86_64/include/uk/asm/lcpu.h b/arch/x86/x86_64/include/uk/asm/lcpu.h
> index 6a471a1..f1fd463 100644
> --- a/arch/x86/x86_64/include/uk/asm/lcpu.h
> +++ b/arch/x86/x86_64/include/uk/asm/lcpu.h
> @@ -118,4 +118,10 @@ static inline unsigned long ukarch_read_sp(void)
>  	__asm__ __volatile__("mov %%rsp, %0" : "=r"(sp));
>  	return sp;
>  }
> +
> +static inline void ukarch_spinwait(void)
> +{
> +	__asm__ __volatile__("pause" : : : "memory");
> +}
> +
>  #endif /* !__ASSEMBLY__ */
> 


From minios-devel-bounces@lists.xenproject.org Thu Jul 23 09:04:36 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 09:04:36 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyX9Y-0007yU-6K; Thu, 23 Jul 2020 09:04:36 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=u2GH=BC=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jyX9W-0007yO-OZ
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 09:04:34 +0000
X-Inumbo-ID: 8588e314-ccc3-11ea-86e9-bc764e2007e4
Received: from mx.upb.ro (unknown [141.85.13.200])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 8588e314-ccc3-11ea-86e9-bc764e2007e4;
 Thu, 23 Jul 2020 09:04:32 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id ABD50B561CBF;
 Thu, 23 Jul 2020 12:04:31 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id bkJYy2mBesYd; Thu, 23 Jul 2020 12:04:29 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id C76ECB561D12;
 Thu, 23 Jul 2020 12:04:29 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id TaH_pTe868OH; Thu, 23 Jul 2020 12:04:29 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id 4D1EAB561CBF;
 Thu, 23 Jul 2020 12:04:29 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH 2/2] arch/arm: Provide ukarch_spinwait noop for
 ARM
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200723081526.50677-1-a.jung@lancs.ac.uk>
 <20200723081526.50677-3-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <ba1bc73a-b7b0-6eb7-1857-a0243368509d@cs.pub.ro>
Date: Thu, 23 Jul 2020 12:04:29 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200723081526.50677-3-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>

On 7/23/20 11:15 AM, Alexander Jung wrote:
> ARM does not support a pause-type instruction for busy spin wait
> operations.  This commit provides the same alias to be used in
> instances where it is required but defaults to a blank operation.
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  arch/arm/arm/include/uk/asm/lcpu.h   | 5 +++++
>  arch/arm/arm64/include/uk/asm/lcpu.h | 5 +++++
>  2 files changed, 10 insertions(+)
> 
> diff --git a/arch/arm/arm/include/uk/asm/lcpu.h b/arch/arm/arm/include/uk/asm/lcpu.h
> index cdeffc3..f38ffb9 100644
> --- a/arch/arm/arm/include/uk/asm/lcpu.h
> +++ b/arch/arm/arm/include/uk/asm/lcpu.h
> @@ -57,3 +57,8 @@ struct __regs {
>  #ifndef wmb
>  #define wmb() __asm__("dsb" : : : "memory")
>  #endif
> +
> +static inline void ukarch_spinwait(void)
> +{
> +	/* Intelligent busy wait not supported on arm. */
> +}
> diff --git a/arch/arm/arm64/include/uk/asm/lcpu.h b/arch/arm/arm64/include/uk/asm/lcpu.h
> index 45d1b23..51e17ad 100644
> --- a/arch/arm/arm64/include/uk/asm/lcpu.h
> +++ b/arch/arm/arm64/include/uk/asm/lcpu.h
> @@ -146,4 +146,9 @@ static inline unsigned long ukarch_read_sp(void)
>  	return sp;
>  }
>  
> +static inline void ukarch_spinwait(void)
> +{
> +	/* Intelligent busy wait not supported on arm64. */
> +}
> +
>  #endif /* __ASSEMBLY__ */
> 


From minios-devel-bounces@lists.xenproject.org Thu Jul 23 09:39:02 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 09:39:02 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyXgp-0002I0-8M; Thu, 23 Jul 2020 09:38:59 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=gEn1=BC=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jyXgn-0002Hv-Mf
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 09:38:57 +0000
X-Inumbo-ID: 531bf7b8-ccc8-11ea-86eb-bc764e2007e4
Received: from mh-fa-0.lancs.ac.uk (unknown [148.88.65.130])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 531bf7b8-ccc8-11ea-86eb-bc764e2007e4;
 Thu, 23 Jul 2020 09:38:55 +0000 (UTC)
Received: from p57b866f1.dip0.t-ipconnect.de ([87.184.102.241]
 helo=localhost.localdomain)
 by mh-fa-0.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jyXgi-000LlL-8P; Thu, 23 Jul 2020 10:38:54 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH] include: Introduce uk/preemmpt.h
Date: Thu, 23 Jul 2020 11:38:47 +0200
Message-Id: <20200723093847.65020-1-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-fa-0.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>, Costin Lupu <costin.lupu@cs.pub.ro>,
 Alexander Jung <a.jung@lancs.ac.uk>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This commit adds an additional header with two new methods:

 - preempt_disable()
 - preempt_enable()

These methods enable and disable preemption by calling a memory
barrier only.  Their names are derived from the Linux Kernel[1].

Whilst currently unimplemented, pre-emptive scheduling requires
additional notarization when called.  This means that future
enhancements to Unikraft's pre-emptive scheduler will need to
modify these methods to increase a counter within the thread
to indicate whether the thread is pre-emptible or not.

[0]: https://elixir.bootlin.com/linux/latest/source/include/linux/preempt.h#L169

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 include/uk/preempt.h | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 include/uk/preempt.h

diff --git a/include/uk/preempt.h b/include/uk/preempt.h
new file mode 100644
index 0000000..d45623d
--- /dev/null
+++ b/include/uk/preempt.h
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Alexander Jung <alexander.jung@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation.
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __UK_PREEMPT_H__
+#define __UK_PREEMPT_H__
+
+#define preempt_disable()	barrier()
+#define preempt_enable()	barrier()
+
+#endif /* __UK_PREEMPT_H__ */
-- 
2.11.0



From minios-devel-bounces@lists.xenproject.org Thu Jul 23 11:10:59 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 11:10:59 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyZ7p-000350-Gi; Thu, 23 Jul 2020 11:10:57 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=u2GH=BC=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jyZ7p-00034v-2e
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 11:10:57 +0000
X-Inumbo-ID: 2c7b57ea-ccd5-11ea-86ee-bc764e2007e4
Received: from mx.upb.ro (unknown [141.85.13.250])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 2c7b57ea-ccd5-11ea-86ee-bc764e2007e4;
 Thu, 23 Jul 2020 11:10:54 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 1A12DB561D1A;
 Thu, 23 Jul 2020 14:10:53 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id OeVHdrQ-b2Yp; Thu, 23 Jul 2020 14:10:50 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 730DAB561D39;
 Thu, 23 Jul 2020 14:10:50 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id ARoBa6bKOQ7J; Thu, 23 Jul 2020 14:10:50 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id E7CDEB561D1A;
 Thu, 23 Jul 2020 14:10:49 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH] include: Introduce uk/preemmpt.h
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200723093847.65020-1-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <fcf902f4-ab1a-2cca-ba2d-7fcdc6c38ea5@cs.pub.ro>
Date: Thu, 23 Jul 2020 14:10:49 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200723093847.65020-1-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

As agreed offline, I'll add on upstreaming `uk_` prefixes.

Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>

On 7/23/20 12:38 PM, Alexander Jung wrote:
> This commit adds an additional header with two new methods:
> 
>  - preempt_disable()
>  - preempt_enable()
> 
> These methods enable and disable preemption by calling a memory
> barrier only.  Their names are derived from the Linux Kernel[1].
> 
> Whilst currently unimplemented, pre-emptive scheduling requires
> additional notarization when called.  This means that future
> enhancements to Unikraft's pre-emptive scheduler will need to
> modify these methods to increase a counter within the thread
> to indicate whether the thread is pre-emptible or not.
> 
> [0]: https://elixir.bootlin.com/linux/latest/source/include/linux/preempt.h#L169
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  include/uk/preempt.h | 40 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
>  create mode 100644 include/uk/preempt.h
> 
> diff --git a/include/uk/preempt.h b/include/uk/preempt.h
> new file mode 100644
> index 0000000..d45623d
> --- /dev/null
> +++ b/include/uk/preempt.h
> @@ -0,0 +1,40 @@
> +/* SPDX-License-Identifier: BSD-3-Clause */
> +/*
> + * Authors: Alexander Jung <alexander.jung@neclab.eu>
> + *
> + * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation.
> + *                     All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + *
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in the
> + *    documentation and/or other materials provided with the distribution.
> + * 3. Neither the name of the copyright holder nor the names of its
> + *    contributors may be used to endorse or promote products derived from
> + *    this software without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#ifndef __UK_PREEMPT_H__
> +#define __UK_PREEMPT_H__
> +
> +#define preempt_disable()	barrier()
> +#define preempt_enable()	barrier()
> +
> +#endif /* __UK_PREEMPT_H__ */
> 


From minios-devel-bounces@lists.xenproject.org Thu Jul 23 11:19:57 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 11:19:57 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyZGV-0003Zc-0s; Thu, 23 Jul 2020 11:19:55 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=gEn1=BC=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jyZGU-0003ZO-Bc
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 11:19:54 +0000
X-Inumbo-ID: 6d270ce9-ccd6-11ea-86ee-bc764e2007e4
Received: from mh-is-0.lancs.ac.uk (unknown [148.88.65.128])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 6d270ce9-ccd6-11ea-86ee-bc764e2007e4;
 Thu, 23 Jul 2020 11:19:52 +0000 (UTC)
Received: from p57b866f1.dip0.t-ipconnect.de ([87.184.102.241]
 helo=unknown.fritz.box)
 by mh-is-0.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jyZGQ-0004Ay-2M; Thu, 23 Jul 2020 12:19:51 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH] arch: Provide cache line size KConfig option
Date: Thu, 23 Jul 2020 13:19:47 +0200
Message-Id: <20200723111947.79634-1-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-0.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>, Costin Lupu <costin.lupu@cs.pub.ro>,
 Alexander Jung <a.jung@lancs.ac.uk>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This patch introduces `CONFIG_CACHE_LINE_SIZE` for statically
describing the CPU d-cache line size in bytes.

The d-cache line size can also be detected automatically at the
expense of using more memory and CPU cycles during boot time by
querying the `CPUID` instruction for `CLFLUSH`.

Signed-off-by: Alexander Jung <a.jung@lancs.ac.uk>
---
 arch/Config.uk | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/Config.uk b/arch/Config.uk
index 79097cf..3018518 100644
--- a/arch/Config.uk
+++ b/arch/Config.uk
@@ -33,3 +33,9 @@ config STACK_SIZE_PAGE_ORDER
 		Indirectly configures the stack size by changing the stack size page
 		order. Stack size is equal with 2^order * page size (e.g. 4KB).
 		Only change this if you know what you're doing.
+
+config CACHE_LINE_SIZE
+	int "Cache line size"
+	default 32
+	help
+		Size in bytes of a CPU d-cache line.
-- 
2.11.0



From minios-devel-bounces@lists.xenproject.org Thu Jul 23 11:48:08 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 11:48:08 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyZhm-0006rd-Va; Thu, 23 Jul 2020 11:48:06 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=gEn1=BC=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jyZhm-0006rY-1H
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 11:48:06 +0000
X-Inumbo-ID: 5dd38d9e-ccda-11ea-86f7-bc764e2007e4
Received: from mh-is-0.lancs.ac.uk (unknown [148.88.65.128])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 5dd38d9e-ccda-11ea-86f7-bc764e2007e4;
 Thu, 23 Jul 2020 11:48:04 +0000 (UTC)
Received: from p57b866f1.dip0.t-ipconnect.de ([87.184.102.241]
 helo=unknown.fritz.box)
 by mh-is-0.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jyZhh-0008kw-0h; Thu, 23 Jul 2020 12:48:03 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH] arch: Define the cache line size for each
 architecture
Date: Thu, 23 Jul 2020 13:47:47 +0200
Message-Id: <20200723114747.84030-1-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-0.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>, Costin Lupu <costin.lupu@cs.pub.ro>,
 Alexander Jung <a.jung@lancs.ac.uk>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This definition statically describes the d-cache line size in
bytes for {x86_64,arm,arm64}.

The d-cache line is a L1 data cache nearest to the processor and
the line size refers to the data memory block.

The d-line cache size can also be discovered by querying the
d-cache build egister at the expense of using more memory and
instruction cycles during boot.  Defining this size statically
increases performance since it is already known for the
respective architecture.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 arch/arm/arm/include/uk/asm/lcpu.h    | 2 ++
 arch/arm/arm64/include/uk/asm/lcpu.h  | 2 ++
 arch/x86/x86_64/include/uk/asm/lcpu.h | 2 ++
 3 files changed, 6 insertions(+)

diff --git a/arch/arm/arm/include/uk/asm/lcpu.h b/arch/arm/arm/include/uk/asm/lcpu.h
index cdeffc3..33f3a6b 100644
--- a/arch/arm/arm/include/uk/asm/lcpu.h
+++ b/arch/arm/arm/include/uk/asm/lcpu.h
@@ -29,6 +29,8 @@
 #error Do not include this header directly
 #endif
 
+#define CACHE_LINE_SIZE	32
+
 struct __regs {
 	unsigned long r0;
 	unsigned long r1;
diff --git a/arch/arm/arm64/include/uk/asm/lcpu.h b/arch/arm/arm64/include/uk/asm/lcpu.h
index 45d1b23..4597e40 100644
--- a/arch/arm/arm64/include/uk/asm/lcpu.h
+++ b/arch/arm/arm64/include/uk/asm/lcpu.h
@@ -30,6 +30,8 @@
 #error Do not include this header directly
 #endif
 
+#define CACHE_LINE_SIZE	64
+
 #ifdef __ASSEMBLY__
 /*
  * Stack size to save general purpose registers and essential system
diff --git a/arch/x86/x86_64/include/uk/asm/lcpu.h b/arch/x86/x86_64/include/uk/asm/lcpu.h
index 6a471a1..ff137f8 100644
--- a/arch/x86/x86_64/include/uk/asm/lcpu.h
+++ b/arch/x86/x86_64/include/uk/asm/lcpu.h
@@ -32,6 +32,8 @@
 #error Do not include this header directly
 #endif
 
+#define CACHE_LINE_SIZE	64
+
 #ifndef __ASSEMBLY__
 struct __regs {
 	unsigned long pad; /* 8 bytes to make struct size multiple of 16 */
-- 
2.11.0



From minios-devel-bounces@lists.xenproject.org Thu Jul 23 11:51:47 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 11:51:47 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyZlL-0007cZ-AY; Thu, 23 Jul 2020 11:51:47 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=u2GH=BC=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jyZlK-0007cU-5U
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 11:51:46 +0000
X-Inumbo-ID: e0e50708-ccda-11ea-a284-12813bfff9fa
Received: from mx.upb.ro (unknown [141.85.13.220])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id e0e50708-ccda-11ea-a284-12813bfff9fa;
 Thu, 23 Jul 2020 11:51:44 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 34DBDB561CBF;
 Thu, 23 Jul 2020 14:51:43 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id qVV9Qaj-VJzZ; Thu, 23 Jul 2020 14:51:41 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 2BCF3B561D1A;
 Thu, 23 Jul 2020 14:51:41 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id 7mj6yHn87uz2; Thu, 23 Jul 2020 14:51:41 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id 9023EB561CBF;
 Thu, 23 Jul 2020 14:51:40 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH] arch: Define the cache line size for each
 architecture
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200723114747.84030-1-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <71c8ea3c-ee38-b186-6f53-7773d2a5c53d@cs.pub.ro>
Date: Thu, 23 Jul 2020 14:51:40 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200723114747.84030-1-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>

On 7/23/20 2:47 PM, Alexander Jung wrote:
> This definition statically describes the d-cache line size in
> bytes for {x86_64,arm,arm64}.
> 
> The d-cache line is a L1 data cache nearest to the processor and
> the line size refers to the data memory block.
> 
> The d-line cache size can also be discovered by querying the
> d-cache build egister at the expense of using more memory and
> instruction cycles during boot.  Defining this size statically
> increases performance since it is already known for the
> respective architecture.
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  arch/arm/arm/include/uk/asm/lcpu.h    | 2 ++
>  arch/arm/arm64/include/uk/asm/lcpu.h  | 2 ++
>  arch/x86/x86_64/include/uk/asm/lcpu.h | 2 ++
>  3 files changed, 6 insertions(+)
> 
> diff --git a/arch/arm/arm/include/uk/asm/lcpu.h b/arch/arm/arm/include/uk/asm/lcpu.h
> index cdeffc3..33f3a6b 100644
> --- a/arch/arm/arm/include/uk/asm/lcpu.h
> +++ b/arch/arm/arm/include/uk/asm/lcpu.h
> @@ -29,6 +29,8 @@
>  #error Do not include this header directly
>  #endif
>  
> +#define CACHE_LINE_SIZE	32
> +
>  struct __regs {
>  	unsigned long r0;
>  	unsigned long r1;
> diff --git a/arch/arm/arm64/include/uk/asm/lcpu.h b/arch/arm/arm64/include/uk/asm/lcpu.h
> index 45d1b23..4597e40 100644
> --- a/arch/arm/arm64/include/uk/asm/lcpu.h
> +++ b/arch/arm/arm64/include/uk/asm/lcpu.h
> @@ -30,6 +30,8 @@
>  #error Do not include this header directly
>  #endif
>  
> +#define CACHE_LINE_SIZE	64
> +
>  #ifdef __ASSEMBLY__
>  /*
>   * Stack size to save general purpose registers and essential system
> diff --git a/arch/x86/x86_64/include/uk/asm/lcpu.h b/arch/x86/x86_64/include/uk/asm/lcpu.h
> index 6a471a1..ff137f8 100644
> --- a/arch/x86/x86_64/include/uk/asm/lcpu.h
> +++ b/arch/x86/x86_64/include/uk/asm/lcpu.h
> @@ -32,6 +32,8 @@
>  #error Do not include this header directly
>  #endif
>  
> +#define CACHE_LINE_SIZE	64
> +
>  #ifndef __ASSEMBLY__
>  struct __regs {
>  	unsigned long pad; /* 8 bytes to make struct size multiple of 16 */
> 


From minios-devel-bounces@lists.xenproject.org Thu Jul 23 12:49:31 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 12:49:31 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyaf9-0004JX-Jc; Thu, 23 Jul 2020 12:49:27 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=gEn1=BC=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jyaf7-0004JS-VH
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 12:49:25 +0000
X-Inumbo-ID: eefee220-cce2-11ea-a28e-12813bfff9fa
Received: from mh-is-1.lancs.ac.uk (unknown [148.88.65.129])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id eefee220-cce2-11ea-a28e-12813bfff9fa;
 Thu, 23 Jul 2020 12:49:23 +0000 (UTC)
Received: from p57b866f1.dip0.t-ipconnect.de ([87.184.102.241]
 helo=unknown.fritz.box)
 by mh-is-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jyaf3-000GXc-4o; Thu, 23 Jul 2020 13:49:22 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH v3 0/5] Introduce Ring Buffer Implementation
Date: Thu, 23 Jul 2020 14:48:58 +0200
Message-Id: <20200723124903.95372-1-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>, Costin Lupu <costin.lupu@cs.pub.ro>,
 Alexander Jung <a.jung@lancs.ac.uk>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This series introduces a port of FreeBSD's buf_ring.{h,c} implementation for use
within Unikraft.  This ring buffer can be used for message passing in queues, 
for example within a AF_UNIX socket implementation between two  threads.  The 
implementation is therefore thread safe and provides a generic  data field 
which is initialized to the desired ring buffer length.

 - uk_ring_alloc
 - uk_ring_free
 - uk_ring_enqueue
 - uk_ring_dequeue
 - uk_ring_dequeue_single
 - uk_ring_advance_single
 - uk_ring_putback_single
 - uk_ring_peek
 - uk_ring_peek_clear_single
 - uk_ring_full
 - uk_ring_empty
 - uk_ring_count

Changes in v3:

 * This patch series relies on changes made available in the following patch
   series': #1474, #1475 and #1477.  These series' introduce primitives for
   cpu_spinwait across architecturs; pre-emptive scheduling, namely 
   `uk_preempt_enable` and uk_preempt_disable`; and, the global architecture cache line size, respectively.
 * Squahes some verbose commits on library registration.

Alexander Jung (5):
  lib/ukring: Import ring buffer from FreeBSD
  lib/ukring: Fix formatting issues {ring.c, ring.h}
  lib/ukring: Adapt {ring.c, ring.h} to Unikraft
  lib/ukring: Re-prefix methods and structs from buf_ to uk_
  lib/ukring: Register ukring with Unikraft

 lib/Makefile.uk              |   1 +
 lib/ukring/Config.uk         |  23 +++
 lib/ukring/Makefile.uk       |   6 +
 lib/ukring/exportsyms.uk     |  12 ++
 lib/ukring/include/uk/ring.h | 392 +++++++++++++++++++++++++++++++++++++++++++
 lib/ukring/ring.c            |  67 ++++++++
 6 files changed, 501 insertions(+)
 create mode 100644 lib/ukring/Config.uk
 create mode 100644 lib/ukring/Makefile.uk
 create mode 100644 lib/ukring/exportsyms.uk
 create mode 100644 lib/ukring/include/uk/ring.h
 create mode 100644 lib/ukring/ring.c

-- 
2.11.0



From minios-devel-bounces@lists.xenproject.org Thu Jul 23 12:49:31 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 12:49:31 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyafD-0004Jt-L8; Thu, 23 Jul 2020 12:49:31 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=gEn1=BC=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jyafC-0004Je-9C
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 12:49:30 +0000
X-Inumbo-ID: f165b85e-cce2-11ea-8702-bc764e2007e4
Received: from mh-is-1.lancs.ac.uk (unknown [148.88.65.129])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id f165b85e-cce2-11ea-8702-bc764e2007e4;
 Thu, 23 Jul 2020 12:49:27 +0000 (UTC)
Received: from p57b866f1.dip0.t-ipconnect.de ([87.184.102.241]
 helo=unknown.fritz.box)
 by mh-is-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jyaf6-000GXc-5T; Thu, 23 Jul 2020 13:49:27 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH v3 1/5] lib/ukring: Import ring buffer from FreeBSD
Date: Thu, 23 Jul 2020 14:48:59 +0200
Message-Id: <20200723124903.95372-2-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200723124903.95372-1-a.jung@lancs.ac.uk>
References: <20200723124903.95372-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>, Costin Lupu <costin.lupu@cs.pub.ro>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Alexander Jung <alexander.jung@neclab.eu>

Copied as it is from the official FreeBSD git mirror.

Commit: c45cce178ce658f81901a45c741b7f3c47ce2250

- https://github.com/freebsd/freebsd/blob/c45cce1/sys/sys/buf_ring.h
- https://github.com/freebsd/freebsd/blob/c45cce1/sys/kern/subr_bufring.c

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukring/include/uk/ring.h | 371 +++++++++++++++++++++++++++++++++++++++++++
 lib/ukring/ring.c            |  65 ++++++++
 2 files changed, 436 insertions(+)
 create mode 100644 lib/ukring/include/uk/ring.h
 create mode 100644 lib/ukring/ring.c

diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
new file mode 100644
index 0000000..899563c
--- /dev/null
+++ b/lib/ukring/include/uk/ring.h
@@ -0,0 +1,371 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2007-2009 Kip Macy <kmacy@freebsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ *
+ */
+
+#ifndef	_SYS_BUF_RING_H_
+#define	_SYS_BUF_RING_H_
+
+#include <machine/cpu.h>
+
+#ifdef DEBUG_BUFRING
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#endif
+
+struct buf_ring {
+	volatile uint32_t	br_prod_head;
+	volatile uint32_t	br_prod_tail;	
+	int              	br_prod_size;
+	int              	br_prod_mask;
+	uint64_t		br_drops;
+	volatile uint32_t	br_cons_head __aligned(CACHE_LINE_SIZE);
+	volatile uint32_t	br_cons_tail;
+	int		 	br_cons_size;
+	int              	br_cons_mask;
+#ifdef DEBUG_BUFRING
+	struct mtx		*br_lock;
+#endif	
+	void			*br_ring[0] __aligned(CACHE_LINE_SIZE);
+};
+
+/*
+ * multi-producer safe lock-free ring buffer enqueue
+ *
+ */
+static __inline int
+buf_ring_enqueue(struct buf_ring *br, void *buf)
+{
+	uint32_t prod_head, prod_next, cons_tail;
+#ifdef DEBUG_BUFRING
+	int i;
+
+	/*
+	 * Note: It is possible to encounter an mbuf that was removed
+	 * via drbr_peek(), and then re-added via drbr_putback() and
+	 * trigger a spurious panic.
+	 */
+	for (i = br->br_cons_head; i != br->br_prod_head;
+	     i = ((i + 1) & br->br_cons_mask))
+		if(br->br_ring[i] == buf)
+			panic("buf=%p already enqueue at %d prod=%d cons=%d",
+			    buf, i, br->br_prod_tail, br->br_cons_tail);
+#endif	
+	critical_enter();
+	do {
+		prod_head = br->br_prod_head;
+		prod_next = (prod_head + 1) & br->br_prod_mask;
+		cons_tail = br->br_cons_tail;
+
+		if (prod_next == cons_tail) {
+			rmb();
+			if (prod_head == br->br_prod_head &&
+			    cons_tail == br->br_cons_tail) {
+				br->br_drops++;
+				critical_exit();
+				return (ENOBUFS);
+			}
+			continue;
+		}
+	} while (!atomic_cmpset_acq_int(&br->br_prod_head, prod_head, prod_next));
+#ifdef DEBUG_BUFRING
+	if (br->br_ring[prod_head] != NULL)
+		panic("dangling value in enqueue");
+#endif	
+	br->br_ring[prod_head] = buf;
+
+	/*
+	 * If there are other enqueues in progress
+	 * that preceded us, we need to wait for them
+	 * to complete 
+	 */   
+	while (br->br_prod_tail != prod_head)
+		cpu_spinwait();
+	atomic_store_rel_int(&br->br_prod_tail, prod_next);
+	critical_exit();
+	return (0);
+}
+
+/*
+ * multi-consumer safe dequeue 
+ *
+ */
+static __inline void *
+buf_ring_dequeue_mc(struct buf_ring *br)
+{
+	uint32_t cons_head, cons_next;
+	void *buf;
+
+	critical_enter();
+	do {
+		cons_head = br->br_cons_head;
+		cons_next = (cons_head + 1) & br->br_cons_mask;
+
+		if (cons_head == br->br_prod_tail) {
+			critical_exit();
+			return (NULL);
+		}
+	} while (!atomic_cmpset_acq_int(&br->br_cons_head, cons_head, cons_next));
+
+	buf = br->br_ring[cons_head];
+#ifdef DEBUG_BUFRING
+	br->br_ring[cons_head] = NULL;
+#endif
+	/*
+	 * If there are other dequeues in progress
+	 * that preceded us, we need to wait for them
+	 * to complete 
+	 */   
+	while (br->br_cons_tail != cons_head)
+		cpu_spinwait();
+
+	atomic_store_rel_int(&br->br_cons_tail, cons_next);
+	critical_exit();
+
+	return (buf);
+}
+
+/*
+ * single-consumer dequeue 
+ * use where dequeue is protected by a lock
+ * e.g. a network driver's tx queue lock
+ */
+static __inline void *
+buf_ring_dequeue_sc(struct buf_ring *br)
+{
+	uint32_t cons_head, cons_next;
+#ifdef PREFETCH_DEFINED
+	uint32_t cons_next_next;
+#endif
+	uint32_t prod_tail;
+	void *buf;
+
+	/*
+	 * This is a workaround to allow using buf_ring on ARM and ARM64.
+	 * ARM64TODO: Fix buf_ring in a generic way.
+	 * REMARKS: It is suspected that br_cons_head does not require
+	 *   load_acq operation, but this change was extensively tested
+	 *   and confirmed it's working. To be reviewed once again in
+	 *   FreeBSD-12.
+	 *
+	 * Preventing following situation:
+	 * Core(0) - buf_ring_enqueue()                                       Core(1) - buf_ring_dequeue_sc()
+	 * -----------------------------------------                                       ----------------------------------------------
+	 *
+	 *                                                                                cons_head = br->br_cons_head;
+	 * atomic_cmpset_acq_32(&br->br_prod_head, ...));
+	 *                                                                                buf = br->br_ring[cons_head];     <see <1>>
+	 * br->br_ring[prod_head] = buf;
+	 * atomic_store_rel_32(&br->br_prod_tail, ...);
+	 *                                                                                prod_tail = br->br_prod_tail;
+	 *                                                                                if (cons_head == prod_tail) 
+	 *                                                                                        return (NULL);
+	 *                                                                                <condition is false and code uses invalid(old) buf>`	
+	 *
+	 * <1> Load (on core 1) from br->br_ring[cons_head] can be reordered (speculative readed) by CPU.
+	 */	
+#if defined(__arm__) || defined(__aarch64__)
+	cons_head = atomic_load_acq_32(&br->br_cons_head);
+#else
+	cons_head = br->br_cons_head;
+#endif
+	prod_tail = atomic_load_acq_32(&br->br_prod_tail);
+	
+	cons_next = (cons_head + 1) & br->br_cons_mask;
+#ifdef PREFETCH_DEFINED
+	cons_next_next = (cons_head + 2) & br->br_cons_mask;
+#endif
+	
+	if (cons_head == prod_tail) 
+		return (NULL);
+
+#ifdef PREFETCH_DEFINED	
+	if (cons_next != prod_tail) {		
+		prefetch(br->br_ring[cons_next]);
+		if (cons_next_next != prod_tail) 
+			prefetch(br->br_ring[cons_next_next]);
+	}
+#endif
+	br->br_cons_head = cons_next;
+	buf = br->br_ring[cons_head];
+
+#ifdef DEBUG_BUFRING
+	br->br_ring[cons_head] = NULL;
+	if (!mtx_owned(br->br_lock))
+		panic("lock not held on single consumer dequeue");
+	if (br->br_cons_tail != cons_head)
+		panic("inconsistent list cons_tail=%d cons_head=%d",
+		    br->br_cons_tail, cons_head);
+#endif
+	br->br_cons_tail = cons_next;
+	return (buf);
+}
+
+/*
+ * single-consumer advance after a peek
+ * use where it is protected by a lock
+ * e.g. a network driver's tx queue lock
+ */
+static __inline void
+buf_ring_advance_sc(struct buf_ring *br)
+{
+	uint32_t cons_head, cons_next;
+	uint32_t prod_tail;
+	
+	cons_head = br->br_cons_head;
+	prod_tail = br->br_prod_tail;
+	
+	cons_next = (cons_head + 1) & br->br_cons_mask;
+	if (cons_head == prod_tail) 
+		return;
+	br->br_cons_head = cons_next;
+#ifdef DEBUG_BUFRING
+	br->br_ring[cons_head] = NULL;
+#endif
+	br->br_cons_tail = cons_next;
+}
+
+/*
+ * Used to return a buffer (most likely already there)
+ * to the top of the ring. The caller should *not*
+ * have used any dequeue to pull it out of the ring
+ * but instead should have used the peek() function.
+ * This is normally used where the transmit queue
+ * of a driver is full, and an mbuf must be returned.
+ * Most likely whats in the ring-buffer is what
+ * is being put back (since it was not removed), but
+ * sometimes the lower transmit function may have
+ * done a pullup or other function that will have
+ * changed it. As an optimization we always put it
+ * back (since jhb says the store is probably cheaper),
+ * if we have to do a multi-queue version we will need
+ * the compare and an atomic.
+ */
+static __inline void
+buf_ring_putback_sc(struct buf_ring *br, void *new)
+{
+	KASSERT(br->br_cons_head != br->br_prod_tail, 
+		("Buf-Ring has none in putback")) ;
+	br->br_ring[br->br_cons_head] = new;
+}
+
+/*
+ * return a pointer to the first entry in the ring
+ * without modifying it, or NULL if the ring is empty
+ * race-prone if not protected by a lock
+ */
+static __inline void *
+buf_ring_peek(struct buf_ring *br)
+{
+
+#ifdef DEBUG_BUFRING
+	if ((br->br_lock != NULL) && !mtx_owned(br->br_lock))
+		panic("lock not held on single consumer dequeue");
+#endif	
+	/*
+	 * I believe it is safe to not have a memory barrier
+	 * here because we control cons and tail is worst case
+	 * a lagging indicator so we worst case we might
+	 * return NULL immediately after a buffer has been enqueued
+	 */
+	if (br->br_cons_head == br->br_prod_tail)
+		return (NULL);
+	
+	return (br->br_ring[br->br_cons_head]);
+}
+
+static __inline void *
+buf_ring_peek_clear_sc(struct buf_ring *br)
+{
+#ifdef DEBUG_BUFRING
+	void *ret;
+
+	if (!mtx_owned(br->br_lock))
+		panic("lock not held on single consumer dequeue");
+#endif	
+
+	if (br->br_cons_head == br->br_prod_tail)
+		return (NULL);
+
+#if defined(__arm__) || defined(__aarch64__)
+	/*
+	 * The barrier is required there on ARM and ARM64 to ensure, that
+	 * br->br_ring[br->br_cons_head] will not be fetched before the above
+	 * condition is checked.
+	 * Without the barrier, it is possible, that buffer will be fetched
+	 * before the enqueue will put mbuf into br, then, in the meantime, the
+	 * enqueue will update the array and the br_prod_tail, and the
+	 * conditional check will be true, so we will return previously fetched
+	 * (and invalid) buffer.
+	 */
+	atomic_thread_fence_acq();
+#endif
+
+#ifdef DEBUG_BUFRING
+	/*
+	 * Single consumer, i.e. cons_head will not move while we are
+	 * running, so atomic_swap_ptr() is not necessary here.
+	 */
+	ret = br->br_ring[br->br_cons_head];
+	br->br_ring[br->br_cons_head] = NULL;
+	return (ret);
+#else
+	return (br->br_ring[br->br_cons_head]);
+#endif
+}
+
+static __inline int
+buf_ring_full(struct buf_ring *br)
+{
+
+	return (((br->br_prod_head + 1) & br->br_prod_mask) == br->br_cons_tail);
+}
+
+static __inline int
+buf_ring_empty(struct buf_ring *br)
+{
+
+	return (br->br_cons_head == br->br_prod_tail);
+}
+
+static __inline int
+buf_ring_count(struct buf_ring *br)
+{
+
+	return ((br->br_prod_size + br->br_prod_tail - br->br_cons_tail)
+	    & br->br_prod_mask);
+}
+
+struct buf_ring *buf_ring_alloc(int count, struct malloc_type *type, int flags,
+    struct mtx *);
+void buf_ring_free(struct buf_ring *br, struct malloc_type *type);
+
+
+
+#endif
\ No newline at end of file
diff --git a/lib/ukring/ring.c b/lib/ukring/ring.c
new file mode 100644
index 0000000..644c3be
--- /dev/null
+++ b/lib/ukring/ring.c
@@ -0,0 +1,65 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2007, 2008 Kip Macy <kmacy@freebsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/ktr.h>
+#include <sys/buf_ring.h>
+
+struct buf_ring *
+buf_ring_alloc(int count, struct malloc_type *type, int flags, struct mtx *lock)
+{
+	struct buf_ring *br;
+
+	KASSERT(powerof2(count), ("buf ring must be size power of 2"));
+	
+	br = malloc(sizeof(struct buf_ring) + count*sizeof(caddr_t),
+	    type, flags|M_ZERO);
+	if (br == NULL)
+		return (NULL);
+#ifdef DEBUG_BUFRING
+	br->br_lock = lock;
+#endif	
+	br->br_prod_size = br->br_cons_size = count;
+	br->br_prod_mask = br->br_cons_mask = count-1;
+	br->br_prod_head = br->br_cons_head = 0;
+	br->br_prod_tail = br->br_cons_tail = 0;
+		
+	return (br);
+}
+
+void
+buf_ring_free(struct buf_ring *br, struct malloc_type *type)
+{
+	free(br, type);
+}
\ No newline at end of file
-- 
2.11.0



From minios-devel-bounces@lists.xenproject.org Thu Jul 23 12:49:36 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 12:49:36 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyafI-0004Kk-Mx; Thu, 23 Jul 2020 12:49:36 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=gEn1=BC=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jyafH-0004Je-4e
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 12:49:35 +0000
X-Inumbo-ID: f33aecda-cce2-11ea-8702-bc764e2007e4
Received: from mh-is-1.lancs.ac.uk (unknown [148.88.65.129])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id f33aecda-cce2-11ea-8702-bc764e2007e4;
 Thu, 23 Jul 2020 12:49:30 +0000 (UTC)
Received: from p57b866f1.dip0.t-ipconnect.de ([87.184.102.241]
 helo=unknown.fritz.box)
 by mh-is-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jyafA-000GXc-58; Thu, 23 Jul 2020 13:49:30 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH v3 2/5] lib/ukring: Fix formatting issues {ring.c,
 ring.h}
Date: Thu, 23 Jul 2020 14:49:00 +0200
Message-Id: <20200723124903.95372-3-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200723124903.95372-1-a.jung@lancs.ac.uk>
References: <20200723124903.95372-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>, Costin Lupu <costin.lupu@cs.pub.ro>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

From: Alexander Jung <alexander.jung@neclab.eu>

This commit addresses issues found using checkpatch:

* return is not a function, parentheses are not required;
* trailing whitespace;
* space required before the open parenthesis '(';
* return of an errno should typically be negative; and,
* missing a blank line after declarations.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukring/include/uk/ring.h | 140 ++++++++++++++++++++++++-------------------
 lib/ukring/ring.c            |  17 +++---
 2 files changed, 87 insertions(+), 70 deletions(-)

diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
index 899563c..abc95fe 100644
--- a/lib/ukring/include/uk/ring.h
+++ b/lib/ukring/include/uk/ring.h
@@ -29,8 +29,8 @@
  *
  */
 
-#ifndef	_SYS_BUF_RING_H_
-#define	_SYS_BUF_RING_H_
+#ifndef _SYS_BUF_RING_H_
+#define _SYS_BUF_RING_H_
 
 #include <machine/cpu.h>
 
@@ -39,22 +39,24 @@
 #include <sys/mutex.h>
 #endif
 
+
 struct buf_ring {
-	volatile uint32_t	br_prod_head;
-	volatile uint32_t	br_prod_tail;	
-	int              	br_prod_size;
-	int              	br_prod_mask;
-	uint64_t		br_drops;
-	volatile uint32_t	br_cons_head __aligned(CACHE_LINE_SIZE);
-	volatile uint32_t	br_cons_tail;
-	int		 	br_cons_size;
-	int              	br_cons_mask;
+	volatile uint32_t br_prod_head;
+	volatile uint32_t br_prod_tail;
+	int               br_prod_size;
+	int               br_prod_mask;
+	uint64_t          br_drops;
+	volatile uint32_t br_cons_head __aligned(CACHE_LINE_SIZE);
+	volatile uint32_t br_cons_tail;
+	int               br_cons_size;
+	int               br_cons_mask;
 #ifdef DEBUG_BUFRING
-	struct mtx		*br_lock;
-#endif	
-	void			*br_ring[0] __aligned(CACHE_LINE_SIZE);
+	struct mtx       *br_lock;
+#endif
+	void             *br_ring[0] __aligned(CACHE_LINE_SIZE);
 };
 
+
 /*
  * multi-producer safe lock-free ring buffer enqueue
  *
@@ -63,6 +65,7 @@ static __inline int
 buf_ring_enqueue(struct buf_ring *br, void *buf)
 {
 	uint32_t prod_head, prod_next, cons_tail;
+
 #ifdef DEBUG_BUFRING
 	int i;
 
@@ -72,12 +75,14 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
 	 * trigger a spurious panic.
 	 */
 	for (i = br->br_cons_head; i != br->br_prod_head;
-	     i = ((i + 1) & br->br_cons_mask))
-		if(br->br_ring[i] == buf)
+			 i = ((i + 1) & br->br_cons_mask))
+		if (br->br_ring[i] == buf)
 			panic("buf=%p already enqueue at %d prod=%d cons=%d",
-			    buf, i, br->br_prod_tail, br->br_cons_tail);
-#endif	
+					buf, i, br->br_prod_tail, br->br_cons_tail);
+#endif
+
 	critical_enter();
+
 	do {
 		prod_head = br->br_prod_head;
 		prod_next = (prod_head + 1) & br->br_prod_mask;
@@ -85,31 +90,34 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
 
 		if (prod_next == cons_tail) {
 			rmb();
-			if (prod_head == br->br_prod_head &&
-			    cons_tail == br->br_cons_tail) {
+			if (prod_head == br->br_prod_head && cons_tail == br->br_cons_tail) {
 				br->br_drops++;
 				critical_exit();
-				return (ENOBUFS);
+				return -ENOBUFS;
 			}
 			continue;
 		}
 	} while (!atomic_cmpset_acq_int(&br->br_prod_head, prod_head, prod_next));
+
 #ifdef DEBUG_BUFRING
 	if (br->br_ring[prod_head] != NULL)
 		panic("dangling value in enqueue");
-#endif	
+#endif
+
 	br->br_ring[prod_head] = buf;
 
 	/*
 	 * If there are other enqueues in progress
 	 * that preceded us, we need to wait for them
 	 * to complete 
-	 */   
+	 */
 	while (br->br_prod_tail != prod_head)
 		cpu_spinwait();
+
 	atomic_store_rel_int(&br->br_prod_tail, prod_next);
 	critical_exit();
-	return (0);
+
+	return 0;
 }
 
 /*
@@ -123,32 +131,35 @@ buf_ring_dequeue_mc(struct buf_ring *br)
 	void *buf;
 
 	critical_enter();
+
 	do {
 		cons_head = br->br_cons_head;
 		cons_next = (cons_head + 1) & br->br_cons_mask;
 
 		if (cons_head == br->br_prod_tail) {
 			critical_exit();
-			return (NULL);
+			return NULL;
 		}
 	} while (!atomic_cmpset_acq_int(&br->br_cons_head, cons_head, cons_next));
 
 	buf = br->br_ring[cons_head];
+
 #ifdef DEBUG_BUFRING
 	br->br_ring[cons_head] = NULL;
 #endif
+
 	/*
 	 * If there are other dequeues in progress
 	 * that preceded us, we need to wait for them
-	 * to complete 
-	 */   
+	 * to complete
+	 */
 	while (br->br_cons_tail != cons_head)
 		cpu_spinwait();
 
 	atomic_store_rel_int(&br->br_cons_tail, cons_next);
 	critical_exit();
 
-	return (buf);
+	return buf;
 }
 
 /*
@@ -186,45 +197,49 @@ buf_ring_dequeue_sc(struct buf_ring *br)
 	 *                                                                                prod_tail = br->br_prod_tail;
 	 *                                                                                if (cons_head == prod_tail) 
 	 *                                                                                        return (NULL);
-	 *                                                                                <condition is false and code uses invalid(old) buf>`	
+	 *                                                                                <condition is false and code uses invalid(old) buf>`
 	 *
 	 * <1> Load (on core 1) from br->br_ring[cons_head] can be reordered (speculative readed) by CPU.
-	 */	
+	 */
 #if defined(__arm__) || defined(__aarch64__)
 	cons_head = atomic_load_acq_32(&br->br_cons_head);
 #else
 	cons_head = br->br_cons_head;
 #endif
 	prod_tail = atomic_load_acq_32(&br->br_prod_tail);
-	
+
 	cons_next = (cons_head + 1) & br->br_cons_mask;
 #ifdef PREFETCH_DEFINED
 	cons_next_next = (cons_head + 2) & br->br_cons_mask;
 #endif
-	
-	if (cons_head == prod_tail) 
-		return (NULL);
 
-#ifdef PREFETCH_DEFINED	
-	if (cons_next != prod_tail) {		
+	if (cons_head == prod_tail)
+		return NULL;
+
+#ifdef PREFETCH_DEFINED
+	if (cons_next != prod_tail) {
 		prefetch(br->br_ring[cons_next]);
-		if (cons_next_next != prod_tail) 
+		if (cons_next_next != prod_tail)
 			prefetch(br->br_ring[cons_next_next]);
 	}
 #endif
+
 	br->br_cons_head = cons_next;
 	buf = br->br_ring[cons_head];
 
 #ifdef DEBUG_BUFRING
 	br->br_ring[cons_head] = NULL;
+
 	if (!mtx_owned(br->br_lock))
 		panic("lock not held on single consumer dequeue");
+
 	if (br->br_cons_tail != cons_head)
 		panic("inconsistent list cons_tail=%d cons_head=%d",
-		    br->br_cons_tail, cons_head);
+				br->br_cons_tail, cons_head);
 #endif
+
 	br->br_cons_tail = cons_next;
-	return (buf);
+	return buf;
 }
 
 /*
@@ -237,17 +252,20 @@ buf_ring_advance_sc(struct buf_ring *br)
 {
 	uint32_t cons_head, cons_next;
 	uint32_t prod_tail;
-	
+
 	cons_head = br->br_cons_head;
 	prod_tail = br->br_prod_tail;
-	
 	cons_next = (cons_head + 1) & br->br_cons_mask;
-	if (cons_head == prod_tail) 
+
+	if (cons_head == prod_tail)
 		return;
+
 	br->br_cons_head = cons_next;
+
 #ifdef DEBUG_BUFRING
 	br->br_ring[cons_head] = NULL;
 #endif
+
 	br->br_cons_tail = cons_next;
 }
 
@@ -270,8 +288,8 @@ buf_ring_advance_sc(struct buf_ring *br)
 static __inline void
 buf_ring_putback_sc(struct buf_ring *br, void *new)
 {
-	KASSERT(br->br_cons_head != br->br_prod_tail, 
-		("Buf-Ring has none in putback")) ;
+	KASSERT(br->br_cons_head != br->br_prod_tail,
+		("Buf-Ring has none in putback"));
 	br->br_ring[br->br_cons_head] = new;
 }
 
@@ -283,11 +301,11 @@ buf_ring_putback_sc(struct buf_ring *br, void *new)
 static __inline void *
 buf_ring_peek(struct buf_ring *br)
 {
-
 #ifdef DEBUG_BUFRING
 	if ((br->br_lock != NULL) && !mtx_owned(br->br_lock))
 		panic("lock not held on single consumer dequeue");
-#endif	
+#endif
+
 	/*
 	 * I believe it is safe to not have a memory barrier
 	 * here because we control cons and tail is worst case
@@ -295,9 +313,9 @@ buf_ring_peek(struct buf_ring *br)
 	 * return NULL immediately after a buffer has been enqueued
 	 */
 	if (br->br_cons_head == br->br_prod_tail)
-		return (NULL);
-	
-	return (br->br_ring[br->br_cons_head]);
+		return NULL;
+
+	return br->br_ring[br->br_cons_head];
 }
 
 static __inline void *
@@ -308,10 +326,10 @@ buf_ring_peek_clear_sc(struct buf_ring *br)
 
 	if (!mtx_owned(br->br_lock))
 		panic("lock not held on single consumer dequeue");
-#endif	
+#endif
 
 	if (br->br_cons_head == br->br_prod_tail)
-		return (NULL);
+		return NULL;
 
 #if defined(__arm__) || defined(__aarch64__)
 	/*
@@ -334,38 +352,34 @@ buf_ring_peek_clear_sc(struct buf_ring *br)
 	 */
 	ret = br->br_ring[br->br_cons_head];
 	br->br_ring[br->br_cons_head] = NULL;
-	return (ret);
+
+	return ret;
 #else
-	return (br->br_ring[br->br_cons_head]);
+	return br->br_ring[br->br_cons_head];
 #endif
 }
 
 static __inline int
 buf_ring_full(struct buf_ring *br)
 {
-
-	return (((br->br_prod_head + 1) & br->br_prod_mask) == br->br_cons_tail);
+	return ((br->br_prod_head + 1) & br->br_prod_mask) == br->br_cons_tail;
 }
 
 static __inline int
 buf_ring_empty(struct buf_ring *br)
 {
-
-	return (br->br_cons_head == br->br_prod_tail);
+	return br->br_cons_head == br->br_prod_tail;
 }
 
 static __inline int
 buf_ring_count(struct buf_ring *br)
 {
-
-	return ((br->br_prod_size + br->br_prod_tail - br->br_cons_tail)
-	    & br->br_prod_mask);
+	return (br->br_prod_size + br->br_prod_tail - br->br_cons_tail)
+			& br->br_prod_mask;
 }
 
 struct buf_ring *buf_ring_alloc(int count, struct malloc_type *type, int flags,
-    struct mtx *);
+		struct mtx *);
 void buf_ring_free(struct buf_ring *br, struct malloc_type *type);
 
-
-
 #endif
\ No newline at end of file
diff --git a/lib/ukring/ring.c b/lib/ukring/ring.c
index 644c3be..e327bd7 100644
--- a/lib/ukring/ring.c
+++ b/lib/ukring/ring.c
@@ -42,20 +42,23 @@ buf_ring_alloc(int count, struct malloc_type *type, int flags, struct mtx *lock)
 	struct buf_ring *br;
 
 	KASSERT(powerof2(count), ("buf ring must be size power of 2"));
-	
+
 	br = malloc(sizeof(struct buf_ring) + count*sizeof(caddr_t),
-	    type, flags|M_ZERO);
+			type, flags|M_ZERO);
+
 	if (br == NULL)
-		return (NULL);
+		return NULL;
+
 #ifdef DEBUG_BUFRING
 	br->br_lock = lock;
-#endif	
+#endif
+
 	br->br_prod_size = br->br_cons_size = count;
-	br->br_prod_mask = br->br_cons_mask = count-1;
+	br->br_prod_mask = br->br_cons_mask = count - 1;
 	br->br_prod_head = br->br_cons_head = 0;
 	br->br_prod_tail = br->br_cons_tail = 0;
-		
-	return (br);
+
+	return br;
 }
 
 void
-- 
2.11.0



From minios-devel-bounces@lists.xenproject.org Thu Jul 23 12:49:39 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 12:49:39 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyafL-0004LY-Pr; Thu, 23 Jul 2020 12:49:39 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=gEn1=BC=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jyafK-0004LK-Li
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 12:49:38 +0000
X-Inumbo-ID: f6bfe0c2-cce2-11ea-a28e-12813bfff9fa
Received: from mh-is-1.lancs.ac.uk (unknown [148.88.65.129])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id f6bfe0c2-cce2-11ea-a28e-12813bfff9fa;
 Thu, 23 Jul 2020 12:49:36 +0000 (UTC)
Received: from p57b866f1.dip0.t-ipconnect.de ([87.184.102.241]
 helo=unknown.fritz.box)
 by mh-is-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jyafG-000GXc-5d; Thu, 23 Jul 2020 13:49:36 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH v3 4/5] lib/ukring: Re-prefix methods and structs
 from buf_ to uk_
Date: Thu, 23 Jul 2020 14:49:02 +0200
Message-Id: <20200723124903.95372-5-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200723124903.95372-1-a.jung@lancs.ac.uk>
References: <20200723124903.95372-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>, Costin Lupu <costin.lupu@cs.pub.ro>,
 Alexander Jung <a.jung@lancs.ac.uk>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukring/include/uk/ring.h | 36 ++++++++++++++++++------------------
 lib/ukring/ring.c            | 10 +++++-----
 2 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
index 6bc789d..a787807 100644
--- a/lib/ukring/include/uk/ring.h
+++ b/lib/ukring/include/uk/ring.h
@@ -29,8 +29,8 @@
  *
  */
 
-#ifndef _SYS_BUF_RING_H_
-#define _SYS_BUF_RING_H_
+#ifndef __UK_RING_H__
+#define __UK_RING_H__
 
 #include <errno.h>
 #include <uk/mutex.h>
@@ -44,7 +44,7 @@
 
 
 
-struct buf_ring {
+struct uk_ring {
 	volatile uint32_t br_prod_head;
 	volatile uint32_t br_prod_tail;
 	int               br_prod_size;
@@ -66,7 +66,7 @@ struct buf_ring {
  *
  */
 static __inline int
-buf_ring_enqueue(struct buf_ring *br, void *buf)
+uk_ring_enqueue(struct uk_ring *br, void *buf)
 {
 	uint32_t prod_head, prod_next, cons_tail;
 
@@ -130,7 +130,7 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
  *
  */
 static __inline void *
-buf_ring_dequeue_mc(struct buf_ring *br)
+uk_ring_dequeue_mc(struct uk_ring *br)
 {
 	uint32_t cons_head, cons_next;
 	void *buf;
@@ -174,7 +174,7 @@ buf_ring_dequeue_mc(struct buf_ring *br)
  * e.g. a network driver's tx queue lock
  */
 static __inline void *
-buf_ring_dequeue_sc(struct buf_ring *br)
+uk_ring_dequeue_sc(struct uk_ring *br)
 {
 	uint32_t cons_head, cons_next;
 #ifdef PREFETCH_DEFINED
@@ -184,15 +184,15 @@ buf_ring_dequeue_sc(struct buf_ring *br)
 	void *buf;
 
 	/*
-	 * This is a workaround to allow using buf_ring on ARM and ARM64.
-	 * ARM64TODO: Fix buf_ring in a generic way.
+	 * This is a workaround to allow using uk_ring on ARM and ARM64.
+	 * ARM64TODO: Fix uk_ring in a generic way.
 	 * REMARKS: It is suspected that br_cons_head does not require
 	 *   load_acq operation, but this change was extensively tested
 	 *   and confirmed it's working. To be reviewed once again in
 	 *   FreeBSD-12.
 	 *
 	 * Preventing following situation:
-	 * Core(0) - buf_ring_enqueue()                                       Core(1) - buf_ring_dequeue_sc()
+	 * Core(0) - uk_ring_enqueue()                                       Core(1) - uk_ring_dequeue_sc()
 	 * -----------------------------------------                                       ----------------------------------------------
 	 *
 	 *                                                                                cons_head = br->br_cons_head;
@@ -254,7 +254,7 @@ buf_ring_dequeue_sc(struct buf_ring *br)
  * e.g. a network driver's tx queue lock
  */
 static __inline void
-buf_ring_advance_sc(struct buf_ring *br)
+uk_ring_advance_sc(struct uk_ring *br)
 {
 	uint32_t cons_head, cons_next;
 	uint32_t prod_tail;
@@ -292,7 +292,7 @@ buf_ring_advance_sc(struct buf_ring *br)
  * the compare and an atomic.
  */
 static __inline void
-buf_ring_putback_sc(struct buf_ring *br, void *new)
+uk_ring_putback_sc(struct uk_ring *br, void *new)
 {
 	/* Buffer ring has none in putback */
 	UK_ASSERT(br->br_cons_head != br->br_prod_tail);
@@ -305,7 +305,7 @@ buf_ring_putback_sc(struct buf_ring *br, void *new)
  * race-prone if not protected by a lock
  */
 static __inline void *
-buf_ring_peek(struct buf_ring *br)
+uk_ring_peek(struct uk_ring *br)
 {
 #ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
 	if (!uk_mutex_is_locked(br->br_lock))
@@ -325,7 +325,7 @@ buf_ring_peek(struct buf_ring *br)
 }
 
 static __inline void *
-buf_ring_peek_clear_sc(struct buf_ring *br)
+uk_ring_peek_clear_sc(struct uk_ring *br)
 {
 #ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
 	void *ret;
@@ -367,26 +367,26 @@ buf_ring_peek_clear_sc(struct buf_ring *br)
 }
 
 static __inline int
-buf_ring_full(struct buf_ring *br)
+uk_ring_full(struct uk_ring *br)
 {
 	return ((br->br_prod_head + 1) & br->br_prod_mask) == br->br_cons_tail;
 }
 
 static __inline int
-buf_ring_empty(struct buf_ring *br)
+uk_ring_empty(struct uk_ring *br)
 {
 	return br->br_cons_head == br->br_prod_tail;
 }
 
 static __inline int
-buf_ring_count(struct buf_ring *br)
+uk_ring_count(struct uk_ring *br)
 {
 	return (br->br_prod_size + br->br_prod_tail - br->br_cons_tail)
 			& br->br_prod_mask;
 }
 
-struct buf_ring *buf_ring_alloc(int count, struct uk_alloc *a, int flags,
+struct uk_ring *uk_ring_alloc(int count, struct uk_alloc *a, int flags,
 		struct uk_mutex *lock);
-void buf_ring_free(struct buf_ring *br, struct uk_alloc *a);
+void uk_ring_free(struct uk_ring *br, struct uk_alloc *a);
 
 #endif
diff --git a/lib/ukring/ring.c b/lib/ukring/ring.c
index 2badb79..ea46107 100644
--- a/lib/ukring/ring.c
+++ b/lib/ukring/ring.c
@@ -34,15 +34,15 @@
 #include <uk/print.h>
 #include <uk/essentials.h>
 
-struct buf_ring *
-buf_ring_alloc(int count, struct uk_alloc *a, int flags, struct uk_mutex *lock)
+struct uk_ring *
+uk_ring_alloc(int count, struct uk_alloc *a, int flags, struct uk_mutex *lock)
 {
-	struct buf_ring *br;
+	struct uk_ring *br;
 
 	/* buf ring must be size power of 2 */
 	UK_ASSERT(POWER_OF_2(count));
 
-	br = uk_malloc(a, sizeof(struct buf_ring) + count * sizeof(caddr_t));
+	br = uk_malloc(a, sizeof(struct uk_ring) + count * sizeof(caddr_t));
 	if (br == NULL) {
 		uk_pr_err("could not allocate ring\n");
 		return NULL;
@@ -61,7 +61,7 @@ buf_ring_alloc(int count, struct uk_alloc *a, int flags, struct uk_mutex *lock)
 }
 
 void
-buf_ring_free(struct buf_ring *br, struct uk_alloc *a)
+uk_ring_free(struct uk_ring *br, struct uk_alloc *a)
 {
 	uk_free(a, br);
 }
-- 
2.11.0



From minios-devel-bounces@lists.xenproject.org Thu Jul 23 12:49:41 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 12:49:41 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyafN-0004MG-RQ; Thu, 23 Jul 2020 12:49:41 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=gEn1=BC=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jyafM-0004Je-4l
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 12:49:40 +0000
X-Inumbo-ID: f48741cf-cce2-11ea-8702-bc764e2007e4
Received: from mh-is-1.lancs.ac.uk (unknown [148.88.65.129])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id f48741cf-cce2-11ea-8702-bc764e2007e4;
 Thu, 23 Jul 2020 12:49:33 +0000 (UTC)
Received: from p57b866f1.dip0.t-ipconnect.de ([87.184.102.241]
 helo=unknown.fritz.box)
 by mh-is-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jyafD-000GXc-5R; Thu, 23 Jul 2020 13:49:33 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH v3 3/5] lib/ukring: Adapt {ring.c, ring.h} to Unikraft
Date: Thu, 23 Jul 2020 14:49:01 +0200
Message-Id: <20200723124903.95372-4-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200723124903.95372-1-a.jung@lancs.ac.uk>
References: <20200723124903.95372-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>, Costin Lupu <costin.lupu@cs.pub.ro>,
 Alexander Jung <a.jung@lancs.ac.uk>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This includes Unikraft-centric headers and types.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/ukring/include/uk/ring.h | 101 +++++++++++++++++++++++--------------------
 lib/ukring/ring.c            |  37 ++++++++--------
 2 files changed, 72 insertions(+), 66 deletions(-)

diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
index abc95fe..6bc789d 100644
--- a/lib/ukring/include/uk/ring.h
+++ b/lib/ukring/include/uk/ring.h
@@ -32,12 +32,16 @@
 #ifndef _SYS_BUF_RING_H_
 #define _SYS_BUF_RING_H_
 
-#include <machine/cpu.h>
+#include <errno.h>
+#include <uk/mutex.h>
+#include <uk/print.h>
+#include <uk/config.h>
+#include <uk/assert.h>
+#include <uk/plat/lcpu.h>
+#include <uk/arch/atomic.h>
+#include <uk/essentials.h>
+#include <uk/preempt.h>
 
-#ifdef DEBUG_BUFRING
-#include <sys/lock.h>
-#include <sys/mutex.h>
-#endif
 
 
 struct buf_ring {
@@ -50,8 +54,8 @@ struct buf_ring {
 	volatile uint32_t br_cons_tail;
 	int               br_cons_size;
 	int               br_cons_mask;
-#ifdef DEBUG_BUFRING
-	struct mtx       *br_lock;
+#ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
+	struct uk_mutex  *br_lock;
 #endif
 	void             *br_ring[0] __aligned(CACHE_LINE_SIZE);
 };
@@ -66,7 +70,7 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
 {
 	uint32_t prod_head, prod_next, cons_tail;
 
-#ifdef DEBUG_BUFRING
+#ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
 	int i;
 
 	/*
@@ -77,11 +81,11 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
 	for (i = br->br_cons_head; i != br->br_prod_head;
 			 i = ((i + 1) & br->br_cons_mask))
 		if (br->br_ring[i] == buf)
-			panic("buf=%p already enqueue at %d prod=%d cons=%d",
+			UK_CRASH("buf=%p already enqueue at %d prod=%d cons=%d",
 					buf, i, br->br_prod_tail, br->br_cons_tail);
 #endif
 
-	critical_enter();
+	uk_preempt_enable();
 
 	do {
 		prod_head = br->br_prod_head;
@@ -92,16 +96,17 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
 			rmb();
 			if (prod_head == br->br_prod_head && cons_tail == br->br_cons_tail) {
 				br->br_drops++;
-				critical_exit();
+				uk_preempt_disable();
 				return -ENOBUFS;
 			}
 			continue;
 		}
-	} while (!atomic_cmpset_acq_int(&br->br_prod_head, prod_head, prod_next));
+	} while (!ukarch_compare_exchange_sync(&br->br_prod_head, prod_head,
+					prod_next));
 
-#ifdef DEBUG_BUFRING
+#ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
 	if (br->br_ring[prod_head] != NULL)
-		panic("dangling value in enqueue");
+		UK_CRASH("dangling value in enqueue");
 #endif
 
 	br->br_ring[prod_head] = buf;
@@ -112,10 +117,10 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
 	 * to complete 
 	 */
 	while (br->br_prod_tail != prod_head)
-		cpu_spinwait();
+		ukarch_spinwait();
 
-	atomic_store_rel_int(&br->br_prod_tail, prod_next);
-	critical_exit();
+	ukarch_store_n(&br->br_prod_tail, prod_next);
+	uk_preempt_disable();
 
 	return 0;
 }
@@ -130,21 +135,22 @@ buf_ring_dequeue_mc(struct buf_ring *br)
 	uint32_t cons_head, cons_next;
 	void *buf;
 
-	critical_enter();
+	uk_preempt_enable();
 
 	do {
 		cons_head = br->br_cons_head;
 		cons_next = (cons_head + 1) & br->br_cons_mask;
 
 		if (cons_head == br->br_prod_tail) {
-			critical_exit();
+			uk_preempt_disable();
 			return NULL;
 		}
-	} while (!atomic_cmpset_acq_int(&br->br_cons_head, cons_head, cons_next));
+	} while (!ukarch_compare_exchange_sync(&br->br_cons_head, cons_head,
+					cons_next));
 
 	buf = br->br_ring[cons_head];
 
-#ifdef DEBUG_BUFRING
+#ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
 	br->br_ring[cons_head] = NULL;
 #endif
 
@@ -154,10 +160,10 @@ buf_ring_dequeue_mc(struct buf_ring *br)
 	 * to complete
 	 */
 	while (br->br_cons_tail != cons_head)
-		cpu_spinwait();
+		ukarch_spinwait();
 
-	atomic_store_rel_int(&br->br_cons_tail, cons_next);
-	critical_exit();
+	ukarch_store_n(&br->br_cons_tail, cons_next);
+	uk_preempt_disable();
 
 	return buf;
 }
@@ -201,12 +207,12 @@ buf_ring_dequeue_sc(struct buf_ring *br)
 	 *
 	 * <1> Load (on core 1) from br->br_ring[cons_head] can be reordered (speculative readed) by CPU.
 	 */
-#if defined(__arm__) || defined(__aarch64__)
-	cons_head = atomic_load_acq_32(&br->br_cons_head);
+#if defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64)
+	cons_head = ukarch_load_n(&br->br_cons_head);
 #else
 	cons_head = br->br_cons_head;
 #endif
-	prod_tail = atomic_load_acq_32(&br->br_prod_tail);
+	prod_tail = ukarch_load_n(&br->br_prod_tail);
 
 	cons_next = (cons_head + 1) & br->br_cons_mask;
 #ifdef PREFETCH_DEFINED
@@ -227,14 +233,14 @@ buf_ring_dequeue_sc(struct buf_ring *br)
 	br->br_cons_head = cons_next;
 	buf = br->br_ring[cons_head];
 
-#ifdef DEBUG_BUFRING
+#ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
 	br->br_ring[cons_head] = NULL;
 
-	if (!mtx_owned(br->br_lock))
-		panic("lock not held on single consumer dequeue");
+	if (!uk_mutex_is_locked(br->br_lock))
+		UK_CRASH("lock not held on single consumer dequeue: %d", br->br_lock->lock_count);
 
 	if (br->br_cons_tail != cons_head)
-		panic("inconsistent list cons_tail=%d cons_head=%d",
+		UK_CRASH("inconsistent list cons_tail=%d cons_head=%d",
 				br->br_cons_tail, cons_head);
 #endif
 
@@ -262,7 +268,7 @@ buf_ring_advance_sc(struct buf_ring *br)
 
 	br->br_cons_head = cons_next;
 
-#ifdef DEBUG_BUFRING
+#ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
 	br->br_ring[cons_head] = NULL;
 #endif
 
@@ -288,8 +294,8 @@ buf_ring_advance_sc(struct buf_ring *br)
 static __inline void
 buf_ring_putback_sc(struct buf_ring *br, void *new)
 {
-	KASSERT(br->br_cons_head != br->br_prod_tail,
-		("Buf-Ring has none in putback"));
+	/* Buffer ring has none in putback */
+	UK_ASSERT(br->br_cons_head != br->br_prod_tail);
 	br->br_ring[br->br_cons_head] = new;
 }
 
@@ -301,9 +307,9 @@ buf_ring_putback_sc(struct buf_ring *br, void *new)
 static __inline void *
 buf_ring_peek(struct buf_ring *br)
 {
-#ifdef DEBUG_BUFRING
-	if ((br->br_lock != NULL) && !mtx_owned(br->br_lock))
-		panic("lock not held on single consumer dequeue");
+#ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
+	if (!uk_mutex_is_locked(br->br_lock))
+		UK_CRASH("lock not held on single consumer dequeue");
 #endif
 
 	/*
@@ -321,17 +327,17 @@ buf_ring_peek(struct buf_ring *br)
 static __inline void *
 buf_ring_peek_clear_sc(struct buf_ring *br)
 {
-#ifdef DEBUG_BUFRING
+#ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
 	void *ret;
 
-	if (!mtx_owned(br->br_lock))
-		panic("lock not held on single consumer dequeue");
+	if (!uk_mutex_is_locked(br->br_lock))
+		UK_CRASH("lock not held on single consumer dequeue");
 #endif
 
 	if (br->br_cons_head == br->br_prod_tail)
 		return NULL;
 
-#if defined(__arm__) || defined(__aarch64__)
+#if defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64)
 	/*
 	 * The barrier is required there on ARM and ARM64 to ensure, that
 	 * br->br_ring[br->br_cons_head] will not be fetched before the above
@@ -342,10 +348,11 @@ buf_ring_peek_clear_sc(struct buf_ring *br)
 	 * conditional check will be true, so we will return previously fetched
 	 * (and invalid) buffer.
 	 */
-	atomic_thread_fence_acq();
+	#error "unsupported: atomic_thread_fence_acq()"
+	/* atomic_thread_fence_acq(); */
 #endif
 
-#ifdef DEBUG_BUFRING
+#ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
 	/*
 	 * Single consumer, i.e. cons_head will not move while we are
 	 * running, so atomic_swap_ptr() is not necessary here.
@@ -378,8 +385,8 @@ buf_ring_count(struct buf_ring *br)
 			& br->br_prod_mask;
 }
 
-struct buf_ring *buf_ring_alloc(int count, struct malloc_type *type, int flags,
-		struct mtx *);
-void buf_ring_free(struct buf_ring *br, struct malloc_type *type);
+struct buf_ring *buf_ring_alloc(int count, struct uk_alloc *a, int flags,
+		struct uk_mutex *lock);
+void buf_ring_free(struct buf_ring *br, struct uk_alloc *a);
 
-#endif
\ No newline at end of file
+#endif
diff --git a/lib/ukring/ring.c b/lib/ukring/ring.c
index e327bd7..2badb79 100644
--- a/lib/ukring/ring.c
+++ b/lib/ukring/ring.c
@@ -26,30 +26,29 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/malloc.h>
-#include <sys/ktr.h>
-#include <sys/buf_ring.h>
+#include <uk/ring.h>
+#include <uk/assert.h>
+#include <uk/alloc.h>
+#include <uk/mutex.h>
+#include <uk/config.h>
+#include <uk/print.h>
+#include <uk/essentials.h>
 
 struct buf_ring *
-buf_ring_alloc(int count, struct malloc_type *type, int flags, struct mtx *lock)
+buf_ring_alloc(int count, struct uk_alloc *a, int flags, struct uk_mutex *lock)
 {
 	struct buf_ring *br;
 
-	KASSERT(powerof2(count), ("buf ring must be size power of 2"));
-
-	br = malloc(sizeof(struct buf_ring) + count*sizeof(caddr_t),
-			type, flags|M_ZERO);
+	/* buf ring must be size power of 2 */
+	UK_ASSERT(POWER_OF_2(count));
 
-	if (br == NULL)
+	br = uk_malloc(a, sizeof(struct buf_ring) + count * sizeof(caddr_t));
+	if (br == NULL) {
+		uk_pr_err("could not allocate ring\n");
 		return NULL;
+	}
 
-#ifdef DEBUG_BUFRING
+#ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
 	br->br_lock = lock;
 #endif
 
@@ -62,7 +61,7 @@ buf_ring_alloc(int count, struct malloc_type *type, int flags, struct mtx *lock)
 }
 
 void
-buf_ring_free(struct buf_ring *br, struct malloc_type *type)
+buf_ring_free(struct buf_ring *br, struct uk_alloc *a)
 {
-	free(br, type);
-}
\ No newline at end of file
+	uk_free(a, br);
+}
-- 
2.11.0



From minios-devel-bounces@lists.xenproject.org Thu Jul 23 12:49:41 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 12:49:41 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyafN-0004MW-Ss; Thu, 23 Jul 2020 12:49:41 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=gEn1=BC=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jyafM-0004LK-9l
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 12:49:40 +0000
X-Inumbo-ID: f8684d9c-cce2-11ea-a28e-12813bfff9fa
Received: from mh-is-1.lancs.ac.uk (unknown [148.88.65.129])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id f8684d9c-cce2-11ea-a28e-12813bfff9fa;
 Thu, 23 Jul 2020 12:49:39 +0000 (UTC)
Received: from p57b866f1.dip0.t-ipconnect.de ([87.184.102.241]
 helo=unknown.fritz.box)
 by mh-is-1.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1jyafJ-000GXc-5N; Thu, 23 Jul 2020 13:49:38 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH v3 5/5] lib/ukring: Register ukring with Unikraft
Date: Thu, 23 Jul 2020 14:49:03 +0200
Message-Id: <20200723124903.95372-6-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
In-Reply-To: <20200723124903.95372-1-a.jung@lancs.ac.uk>
References: <20200723124903.95372-1-a.jung@lancs.ac.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-is-1.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>, Costin Lupu <costin.lupu@cs.pub.ro>,
 Alexander Jung <a.jung@lancs.ac.uk>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This commit registers the ring buffer implementation micro-library
with Unikraft by including it in the global library list, exports
the ring buffer's main functions and includes the relevant initial
Makefile.uk and Config.uk library files.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 lib/Makefile.uk          |  1 +
 lib/ukring/Config.uk     | 23 +++++++++++++++++++++++
 lib/ukring/Makefile.uk   |  6 ++++++
 lib/ukring/exportsyms.uk | 12 ++++++++++++
 4 files changed, 42 insertions(+)
 create mode 100644 lib/ukring/Config.uk
 create mode 100644 lib/ukring/Makefile.uk
 create mode 100644 lib/ukring/exportsyms.uk

diff --git a/lib/Makefile.uk b/lib/Makefile.uk
index 360fcd8..4fd222d 100644
--- a/lib/Makefile.uk
+++ b/lib/Makefile.uk
@@ -25,6 +25,7 @@ $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/devfs))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/9pfs))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uklock))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukmpi))
+$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukring))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukbus))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uksglist))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uknetdev))
diff --git a/lib/ukring/Config.uk b/lib/ukring/Config.uk
new file mode 100644
index 0000000..2481c62
--- /dev/null
+++ b/lib/ukring/Config.uk
@@ -0,0 +1,23 @@
+menuconfig LIBUKRING
+  bool "ukring: Ring buffer interface"
+  select LIBUKALLOC
+  select LIBUKLOCK
+  default n
+  help
+    Provide ring interface for handling object references.
+
+if LIBUKRING
+
+config LIBUKRING_CACHE_LINE_SIZE
+  int "Cache line size"
+  default 32
+  help
+    Size in bytes of a CPU d-cache line.
+
+config CONFIG_LIBUKRING_DEBUG_BUFRING
+  bool "Debug the ring interface"
+  default n
+  help
+    When debugging, this library stores some per-ring statistic counters about the number of enqueues/dequeues.  These statistics require a mutex to avoid concurrent accesses or atomic operations.
+
+endif
diff --git a/lib/ukring/Makefile.uk b/lib/ukring/Makefile.uk
new file mode 100644
index 0000000..7874ca2
--- /dev/null
+++ b/lib/ukring/Makefile.uk
@@ -0,0 +1,6 @@
+$(eval $(call addlib_s,libukring,$(CONFIG_LIBUKRING)))
+
+CINCLUDES-$(CONFIG_LIBUKRING)   += -I$(LIBUKRING_BASE)/include
+CXXINCLUDES-$(CONFIG_LIBUKRING) += -I$(LIBUKRING_BASE)/include
+
+LIBUKRING_SRCS-y += $(LIBUKRING_BASE)/ring.c
diff --git a/lib/ukring/exportsyms.uk b/lib/ukring/exportsyms.uk
new file mode 100644
index 0000000..098f25a
--- /dev/null
+++ b/lib/ukring/exportsyms.uk
@@ -0,0 +1,12 @@
+uk_ring_alloc
+uk_ring_free
+uk_ring_enqueue
+uk_ring_dequeue_mc
+uk_ring_dequeue_sc
+uk_ring_advance_sc
+uk_ring_putback_sc
+uk_ring_peek
+uk_ring_peek_clear_sc
+uk_ring_full
+uk_ring_empty
+uk_ring_count
-- 
2.11.0



From minios-devel-bounces@lists.xenproject.org Thu Jul 23 13:28:08 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 13:28:08 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jybGZ-0008Pq-NA; Thu, 23 Jul 2020 13:28:07 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=u2GH=BC=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jybGY-0008Ph-BU
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 13:28:06 +0000
X-Inumbo-ID: 55ad46ec-cce8-11ea-a298-12813bfff9fa
Received: from mx.upb.ro (unknown [141.85.13.220])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 55ad46ec-cce8-11ea-a298-12813bfff9fa;
 Thu, 23 Jul 2020 13:28:03 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 93F6BB561D1A;
 Thu, 23 Jul 2020 16:28:02 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id KwWHachYDCGD; Thu, 23 Jul 2020 16:27:58 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 4E6ABB561D40;
 Thu, 23 Jul 2020 16:27:58 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id 4SbEyrm6LeV0; Thu, 23 Jul 2020 16:27:58 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id BA205B561D1A;
 Thu, 23 Jul 2020 16:27:57 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH v3 1/5] lib/ukring: Import ring buffer from
 FreeBSD
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200723124903.95372-1-a.jung@lancs.ac.uk>
 <20200723124903.95372-2-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <122d07a0-f1ba-9d10-0993-d847712e5d39@cs.pub.ro>
Date: Thu, 23 Jul 2020 16:27:57 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200723124903.95372-2-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>

On 7/23/20 3:48 PM, Alexander Jung wrote:
> From: Alexander Jung <alexander.jung@neclab.eu>
> 
> Copied as it is from the official FreeBSD git mirror.
> 
> Commit: c45cce178ce658f81901a45c741b7f3c47ce2250
> 
> - https://github.com/freebsd/freebsd/blob/c45cce1/sys/sys/buf_ring.h
> - https://github.com/freebsd/freebsd/blob/c45cce1/sys/kern/subr_bufring.c
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/ukring/include/uk/ring.h | 371 +++++++++++++++++++++++++++++++++++++++++++
>  lib/ukring/ring.c            |  65 ++++++++
>  2 files changed, 436 insertions(+)
>  create mode 100644 lib/ukring/include/uk/ring.h
>  create mode 100644 lib/ukring/ring.c
> 
> diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
> new file mode 100644
> index 0000000..899563c
> --- /dev/null
> +++ b/lib/ukring/include/uk/ring.h
> @@ -0,0 +1,371 @@
> +/*-
> + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
> + *
> + * Copyright (c) 2007-2009 Kip Macy <kmacy@freebsd.org>
> + * All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in the
> + *    documentation and/or other materials provided with the distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> + * SUCH DAMAGE.
> + *
> + * $FreeBSD$
> + *
> + */
> +
> +#ifndef	_SYS_BUF_RING_H_
> +#define	_SYS_BUF_RING_H_
> +
> +#include <machine/cpu.h>
> +
> +#ifdef DEBUG_BUFRING
> +#include <sys/lock.h>
> +#include <sys/mutex.h>
> +#endif
> +
> +struct buf_ring {
> +	volatile uint32_t	br_prod_head;
> +	volatile uint32_t	br_prod_tail;	
> +	int              	br_prod_size;
> +	int              	br_prod_mask;
> +	uint64_t		br_drops;
> +	volatile uint32_t	br_cons_head __aligned(CACHE_LINE_SIZE);
> +	volatile uint32_t	br_cons_tail;
> +	int		 	br_cons_size;
> +	int              	br_cons_mask;
> +#ifdef DEBUG_BUFRING
> +	struct mtx		*br_lock;
> +#endif	
> +	void			*br_ring[0] __aligned(CACHE_LINE_SIZE);
> +};
> +
> +/*
> + * multi-producer safe lock-free ring buffer enqueue
> + *
> + */
> +static __inline int
> +buf_ring_enqueue(struct buf_ring *br, void *buf)
> +{
> +	uint32_t prod_head, prod_next, cons_tail;
> +#ifdef DEBUG_BUFRING
> +	int i;
> +
> +	/*
> +	 * Note: It is possible to encounter an mbuf that was removed
> +	 * via drbr_peek(), and then re-added via drbr_putback() and
> +	 * trigger a spurious panic.
> +	 */
> +	for (i = br->br_cons_head; i != br->br_prod_head;
> +	     i = ((i + 1) & br->br_cons_mask))
> +		if(br->br_ring[i] == buf)
> +			panic("buf=%p already enqueue at %d prod=%d cons=%d",
> +			    buf, i, br->br_prod_tail, br->br_cons_tail);
> +#endif	
> +	critical_enter();
> +	do {
> +		prod_head = br->br_prod_head;
> +		prod_next = (prod_head + 1) & br->br_prod_mask;
> +		cons_tail = br->br_cons_tail;
> +
> +		if (prod_next == cons_tail) {
> +			rmb();
> +			if (prod_head == br->br_prod_head &&
> +			    cons_tail == br->br_cons_tail) {
> +				br->br_drops++;
> +				critical_exit();
> +				return (ENOBUFS);
> +			}
> +			continue;
> +		}
> +	} while (!atomic_cmpset_acq_int(&br->br_prod_head, prod_head, prod_next));
> +#ifdef DEBUG_BUFRING
> +	if (br->br_ring[prod_head] != NULL)
> +		panic("dangling value in enqueue");
> +#endif	
> +	br->br_ring[prod_head] = buf;
> +
> +	/*
> +	 * If there are other enqueues in progress
> +	 * that preceded us, we need to wait for them
> +	 * to complete 
> +	 */   
> +	while (br->br_prod_tail != prod_head)
> +		cpu_spinwait();
> +	atomic_store_rel_int(&br->br_prod_tail, prod_next);
> +	critical_exit();
> +	return (0);
> +}
> +
> +/*
> + * multi-consumer safe dequeue 
> + *
> + */
> +static __inline void *
> +buf_ring_dequeue_mc(struct buf_ring *br)
> +{
> +	uint32_t cons_head, cons_next;
> +	void *buf;
> +
> +	critical_enter();
> +	do {
> +		cons_head = br->br_cons_head;
> +		cons_next = (cons_head + 1) & br->br_cons_mask;
> +
> +		if (cons_head == br->br_prod_tail) {
> +			critical_exit();
> +			return (NULL);
> +		}
> +	} while (!atomic_cmpset_acq_int(&br->br_cons_head, cons_head, cons_next));
> +
> +	buf = br->br_ring[cons_head];
> +#ifdef DEBUG_BUFRING
> +	br->br_ring[cons_head] = NULL;
> +#endif
> +	/*
> +	 * If there are other dequeues in progress
> +	 * that preceded us, we need to wait for them
> +	 * to complete 
> +	 */   
> +	while (br->br_cons_tail != cons_head)
> +		cpu_spinwait();
> +
> +	atomic_store_rel_int(&br->br_cons_tail, cons_next);
> +	critical_exit();
> +
> +	return (buf);
> +}
> +
> +/*
> + * single-consumer dequeue 
> + * use where dequeue is protected by a lock
> + * e.g. a network driver's tx queue lock
> + */
> +static __inline void *
> +buf_ring_dequeue_sc(struct buf_ring *br)
> +{
> +	uint32_t cons_head, cons_next;
> +#ifdef PREFETCH_DEFINED
> +	uint32_t cons_next_next;
> +#endif
> +	uint32_t prod_tail;
> +	void *buf;
> +
> +	/*
> +	 * This is a workaround to allow using buf_ring on ARM and ARM64.
> +	 * ARM64TODO: Fix buf_ring in a generic way.
> +	 * REMARKS: It is suspected that br_cons_head does not require
> +	 *   load_acq operation, but this change was extensively tested
> +	 *   and confirmed it's working. To be reviewed once again in
> +	 *   FreeBSD-12.
> +	 *
> +	 * Preventing following situation:
> +	 * Core(0) - buf_ring_enqueue()                                       Core(1) - buf_ring_dequeue_sc()
> +	 * -----------------------------------------                                       ----------------------------------------------
> +	 *
> +	 *                                                                                cons_head = br->br_cons_head;
> +	 * atomic_cmpset_acq_32(&br->br_prod_head, ...));
> +	 *                                                                                buf = br->br_ring[cons_head];     <see <1>>
> +	 * br->br_ring[prod_head] = buf;
> +	 * atomic_store_rel_32(&br->br_prod_tail, ...);
> +	 *                                                                                prod_tail = br->br_prod_tail;
> +	 *                                                                                if (cons_head == prod_tail) 
> +	 *                                                                                        return (NULL);
> +	 *                                                                                <condition is false and code uses invalid(old) buf>`	
> +	 *
> +	 * <1> Load (on core 1) from br->br_ring[cons_head] can be reordered (speculative readed) by CPU.
> +	 */	
> +#if defined(__arm__) || defined(__aarch64__)
> +	cons_head = atomic_load_acq_32(&br->br_cons_head);
> +#else
> +	cons_head = br->br_cons_head;
> +#endif
> +	prod_tail = atomic_load_acq_32(&br->br_prod_tail);
> +	
> +	cons_next = (cons_head + 1) & br->br_cons_mask;
> +#ifdef PREFETCH_DEFINED
> +	cons_next_next = (cons_head + 2) & br->br_cons_mask;
> +#endif
> +	
> +	if (cons_head == prod_tail) 
> +		return (NULL);
> +
> +#ifdef PREFETCH_DEFINED	
> +	if (cons_next != prod_tail) {		
> +		prefetch(br->br_ring[cons_next]);
> +		if (cons_next_next != prod_tail) 
> +			prefetch(br->br_ring[cons_next_next]);
> +	}
> +#endif
> +	br->br_cons_head = cons_next;
> +	buf = br->br_ring[cons_head];
> +
> +#ifdef DEBUG_BUFRING
> +	br->br_ring[cons_head] = NULL;
> +	if (!mtx_owned(br->br_lock))
> +		panic("lock not held on single consumer dequeue");
> +	if (br->br_cons_tail != cons_head)
> +		panic("inconsistent list cons_tail=%d cons_head=%d",
> +		    br->br_cons_tail, cons_head);
> +#endif
> +	br->br_cons_tail = cons_next;
> +	return (buf);
> +}
> +
> +/*
> + * single-consumer advance after a peek
> + * use where it is protected by a lock
> + * e.g. a network driver's tx queue lock
> + */
> +static __inline void
> +buf_ring_advance_sc(struct buf_ring *br)
> +{
> +	uint32_t cons_head, cons_next;
> +	uint32_t prod_tail;
> +	
> +	cons_head = br->br_cons_head;
> +	prod_tail = br->br_prod_tail;
> +	
> +	cons_next = (cons_head + 1) & br->br_cons_mask;
> +	if (cons_head == prod_tail) 
> +		return;
> +	br->br_cons_head = cons_next;
> +#ifdef DEBUG_BUFRING
> +	br->br_ring[cons_head] = NULL;
> +#endif
> +	br->br_cons_tail = cons_next;
> +}
> +
> +/*
> + * Used to return a buffer (most likely already there)
> + * to the top of the ring. The caller should *not*
> + * have used any dequeue to pull it out of the ring
> + * but instead should have used the peek() function.
> + * This is normally used where the transmit queue
> + * of a driver is full, and an mbuf must be returned.
> + * Most likely whats in the ring-buffer is what
> + * is being put back (since it was not removed), but
> + * sometimes the lower transmit function may have
> + * done a pullup or other function that will have
> + * changed it. As an optimization we always put it
> + * back (since jhb says the store is probably cheaper),
> + * if we have to do a multi-queue version we will need
> + * the compare and an atomic.
> + */
> +static __inline void
> +buf_ring_putback_sc(struct buf_ring *br, void *new)
> +{
> +	KASSERT(br->br_cons_head != br->br_prod_tail, 
> +		("Buf-Ring has none in putback")) ;
> +	br->br_ring[br->br_cons_head] = new;
> +}
> +
> +/*
> + * return a pointer to the first entry in the ring
> + * without modifying it, or NULL if the ring is empty
> + * race-prone if not protected by a lock
> + */
> +static __inline void *
> +buf_ring_peek(struct buf_ring *br)
> +{
> +
> +#ifdef DEBUG_BUFRING
> +	if ((br->br_lock != NULL) && !mtx_owned(br->br_lock))
> +		panic("lock not held on single consumer dequeue");
> +#endif	
> +	/*
> +	 * I believe it is safe to not have a memory barrier
> +	 * here because we control cons and tail is worst case
> +	 * a lagging indicator so we worst case we might
> +	 * return NULL immediately after a buffer has been enqueued
> +	 */
> +	if (br->br_cons_head == br->br_prod_tail)
> +		return (NULL);
> +	
> +	return (br->br_ring[br->br_cons_head]);
> +}
> +
> +static __inline void *
> +buf_ring_peek_clear_sc(struct buf_ring *br)
> +{
> +#ifdef DEBUG_BUFRING
> +	void *ret;
> +
> +	if (!mtx_owned(br->br_lock))
> +		panic("lock not held on single consumer dequeue");
> +#endif	
> +
> +	if (br->br_cons_head == br->br_prod_tail)
> +		return (NULL);
> +
> +#if defined(__arm__) || defined(__aarch64__)
> +	/*
> +	 * The barrier is required there on ARM and ARM64 to ensure, that
> +	 * br->br_ring[br->br_cons_head] will not be fetched before the above
> +	 * condition is checked.
> +	 * Without the barrier, it is possible, that buffer will be fetched
> +	 * before the enqueue will put mbuf into br, then, in the meantime, the
> +	 * enqueue will update the array and the br_prod_tail, and the
> +	 * conditional check will be true, so we will return previously fetched
> +	 * (and invalid) buffer.
> +	 */
> +	atomic_thread_fence_acq();
> +#endif
> +
> +#ifdef DEBUG_BUFRING
> +	/*
> +	 * Single consumer, i.e. cons_head will not move while we are
> +	 * running, so atomic_swap_ptr() is not necessary here.
> +	 */
> +	ret = br->br_ring[br->br_cons_head];
> +	br->br_ring[br->br_cons_head] = NULL;
> +	return (ret);
> +#else
> +	return (br->br_ring[br->br_cons_head]);
> +#endif
> +}
> +
> +static __inline int
> +buf_ring_full(struct buf_ring *br)
> +{
> +
> +	return (((br->br_prod_head + 1) & br->br_prod_mask) == br->br_cons_tail);
> +}
> +
> +static __inline int
> +buf_ring_empty(struct buf_ring *br)
> +{
> +
> +	return (br->br_cons_head == br->br_prod_tail);
> +}
> +
> +static __inline int
> +buf_ring_count(struct buf_ring *br)
> +{
> +
> +	return ((br->br_prod_size + br->br_prod_tail - br->br_cons_tail)
> +	    & br->br_prod_mask);
> +}
> +
> +struct buf_ring *buf_ring_alloc(int count, struct malloc_type *type, int flags,
> +    struct mtx *);
> +void buf_ring_free(struct buf_ring *br, struct malloc_type *type);
> +
> +
> +
> +#endif
> \ No newline at end of file
> diff --git a/lib/ukring/ring.c b/lib/ukring/ring.c
> new file mode 100644
> index 0000000..644c3be
> --- /dev/null
> +++ b/lib/ukring/ring.c
> @@ -0,0 +1,65 @@
> +/*-
> + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
> + *
> + * Copyright (c) 2007, 2008 Kip Macy <kmacy@freebsd.org>
> + * All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in the
> + *    documentation and/or other materials provided with the distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> + * SUCH DAMAGE.
> + */
> +
> +#include <sys/cdefs.h>
> +__FBSDID("$FreeBSD$");
> +
> +#include <sys/param.h>
> +#include <sys/systm.h>
> +#include <sys/kernel.h>
> +#include <sys/malloc.h>
> +#include <sys/ktr.h>
> +#include <sys/buf_ring.h>
> +
> +struct buf_ring *
> +buf_ring_alloc(int count, struct malloc_type *type, int flags, struct mtx *lock)
> +{
> +	struct buf_ring *br;
> +
> +	KASSERT(powerof2(count), ("buf ring must be size power of 2"));
> +	
> +	br = malloc(sizeof(struct buf_ring) + count*sizeof(caddr_t),
> +	    type, flags|M_ZERO);
> +	if (br == NULL)
> +		return (NULL);
> +#ifdef DEBUG_BUFRING
> +	br->br_lock = lock;
> +#endif	
> +	br->br_prod_size = br->br_cons_size = count;
> +	br->br_prod_mask = br->br_cons_mask = count-1;
> +	br->br_prod_head = br->br_cons_head = 0;
> +	br->br_prod_tail = br->br_cons_tail = 0;
> +		
> +	return (br);
> +}
> +
> +void
> +buf_ring_free(struct buf_ring *br, struct malloc_type *type)
> +{
> +	free(br, type);
> +}
> \ No newline at end of file
> 


From minios-devel-bounces@lists.xenproject.org Thu Jul 23 13:28:27 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 13:28:27 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jybGt-0008Sp-QM; Thu, 23 Jul 2020 13:28:27 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=u2GH=BC=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jybGs-0008Se-Kv
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 13:28:26 +0000
X-Inumbo-ID: 618c5872-cce8-11ea-870d-bc764e2007e4
Received: from mx.upb.ro (unknown [141.85.13.200])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 618c5872-cce8-11ea-870d-bc764e2007e4;
 Thu, 23 Jul 2020 13:28:23 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id AA771B561D40;
 Thu, 23 Jul 2020 16:28:22 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id u-BClLpLPlSo; Thu, 23 Jul 2020 16:28:19 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 39A5EB561D48;
 Thu, 23 Jul 2020 16:28:19 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id Zfq7XAqNhgFK; Thu, 23 Jul 2020 16:28:19 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id A8B08B561D1A;
 Thu, 23 Jul 2020 16:28:18 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH v3 2/5] lib/ukring: Fix formatting issues
 {ring.c, ring.h}
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200723124903.95372-1-a.jung@lancs.ac.uk>
 <20200723124903.95372-3-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <3f3db1cd-01d1-fbdb-4732-b38554c32f86@cs.pub.ro>
Date: Thu, 23 Jul 2020 16:28:18 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200723124903.95372-3-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>

On 7/23/20 3:49 PM, Alexander Jung wrote:
> From: Alexander Jung <alexander.jung@neclab.eu>
> 
> This commit addresses issues found using checkpatch:
> 
> * return is not a function, parentheses are not required;
> * trailing whitespace;
> * space required before the open parenthesis '(';
> * return of an errno should typically be negative; and,
> * missing a blank line after declarations.
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/ukring/include/uk/ring.h | 140 ++++++++++++++++++++++++-------------------
>  lib/ukring/ring.c            |  17 +++---
>  2 files changed, 87 insertions(+), 70 deletions(-)
> 
> diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
> index 899563c..abc95fe 100644
> --- a/lib/ukring/include/uk/ring.h
> +++ b/lib/ukring/include/uk/ring.h
> @@ -29,8 +29,8 @@
>   *
>   */
>  
> -#ifndef	_SYS_BUF_RING_H_
> -#define	_SYS_BUF_RING_H_
> +#ifndef _SYS_BUF_RING_H_
> +#define _SYS_BUF_RING_H_
>  
>  #include <machine/cpu.h>
>  
> @@ -39,22 +39,24 @@
>  #include <sys/mutex.h>
>  #endif
>  
> +
>  struct buf_ring {
> -	volatile uint32_t	br_prod_head;
> -	volatile uint32_t	br_prod_tail;	
> -	int              	br_prod_size;
> -	int              	br_prod_mask;
> -	uint64_t		br_drops;
> -	volatile uint32_t	br_cons_head __aligned(CACHE_LINE_SIZE);
> -	volatile uint32_t	br_cons_tail;
> -	int		 	br_cons_size;
> -	int              	br_cons_mask;
> +	volatile uint32_t br_prod_head;
> +	volatile uint32_t br_prod_tail;
> +	int               br_prod_size;
> +	int               br_prod_mask;
> +	uint64_t          br_drops;
> +	volatile uint32_t br_cons_head __aligned(CACHE_LINE_SIZE);
> +	volatile uint32_t br_cons_tail;
> +	int               br_cons_size;
> +	int               br_cons_mask;
>  #ifdef DEBUG_BUFRING
> -	struct mtx		*br_lock;
> -#endif	
> -	void			*br_ring[0] __aligned(CACHE_LINE_SIZE);
> +	struct mtx       *br_lock;
> +#endif
> +	void             *br_ring[0] __aligned(CACHE_LINE_SIZE);
>  };
>  
> +
>  /*
>   * multi-producer safe lock-free ring buffer enqueue
>   *
> @@ -63,6 +65,7 @@ static __inline int
>  buf_ring_enqueue(struct buf_ring *br, void *buf)
>  {
>  	uint32_t prod_head, prod_next, cons_tail;
> +
>  #ifdef DEBUG_BUFRING
>  	int i;
>  
> @@ -72,12 +75,14 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
>  	 * trigger a spurious panic.
>  	 */
>  	for (i = br->br_cons_head; i != br->br_prod_head;
> -	     i = ((i + 1) & br->br_cons_mask))
> -		if(br->br_ring[i] == buf)
> +			 i = ((i + 1) & br->br_cons_mask))
> +		if (br->br_ring[i] == buf)
>  			panic("buf=%p already enqueue at %d prod=%d cons=%d",
> -			    buf, i, br->br_prod_tail, br->br_cons_tail);
> -#endif	
> +					buf, i, br->br_prod_tail, br->br_cons_tail);
> +#endif
> +
>  	critical_enter();
> +
>  	do {
>  		prod_head = br->br_prod_head;
>  		prod_next = (prod_head + 1) & br->br_prod_mask;
> @@ -85,31 +90,34 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
>  
>  		if (prod_next == cons_tail) {
>  			rmb();
> -			if (prod_head == br->br_prod_head &&
> -			    cons_tail == br->br_cons_tail) {
> +			if (prod_head == br->br_prod_head && cons_tail == br->br_cons_tail) {
>  				br->br_drops++;
>  				critical_exit();
> -				return (ENOBUFS);
> +				return -ENOBUFS;
>  			}
>  			continue;
>  		}
>  	} while (!atomic_cmpset_acq_int(&br->br_prod_head, prod_head, prod_next));
> +
>  #ifdef DEBUG_BUFRING
>  	if (br->br_ring[prod_head] != NULL)
>  		panic("dangling value in enqueue");
> -#endif	
> +#endif
> +
>  	br->br_ring[prod_head] = buf;
>  
>  	/*
>  	 * If there are other enqueues in progress
>  	 * that preceded us, we need to wait for them
>  	 * to complete 
> -	 */   
> +	 */
>  	while (br->br_prod_tail != prod_head)
>  		cpu_spinwait();
> +
>  	atomic_store_rel_int(&br->br_prod_tail, prod_next);
>  	critical_exit();
> -	return (0);
> +
> +	return 0;
>  }
>  
>  /*
> @@ -123,32 +131,35 @@ buf_ring_dequeue_mc(struct buf_ring *br)
>  	void *buf;
>  
>  	critical_enter();
> +
>  	do {
>  		cons_head = br->br_cons_head;
>  		cons_next = (cons_head + 1) & br->br_cons_mask;
>  
>  		if (cons_head == br->br_prod_tail) {
>  			critical_exit();
> -			return (NULL);
> +			return NULL;
>  		}
>  	} while (!atomic_cmpset_acq_int(&br->br_cons_head, cons_head, cons_next));
>  
>  	buf = br->br_ring[cons_head];
> +
>  #ifdef DEBUG_BUFRING
>  	br->br_ring[cons_head] = NULL;
>  #endif
> +
>  	/*
>  	 * If there are other dequeues in progress
>  	 * that preceded us, we need to wait for them
> -	 * to complete 
> -	 */   
> +	 * to complete
> +	 */
>  	while (br->br_cons_tail != cons_head)
>  		cpu_spinwait();
>  
>  	atomic_store_rel_int(&br->br_cons_tail, cons_next);
>  	critical_exit();
>  
> -	return (buf);
> +	return buf;
>  }
>  
>  /*
> @@ -186,45 +197,49 @@ buf_ring_dequeue_sc(struct buf_ring *br)
>  	 *                                                                                prod_tail = br->br_prod_tail;
>  	 *                                                                                if (cons_head == prod_tail) 
>  	 *                                                                                        return (NULL);
> -	 *                                                                                <condition is false and code uses invalid(old) buf>`	
> +	 *                                                                                <condition is false and code uses invalid(old) buf>`
>  	 *
>  	 * <1> Load (on core 1) from br->br_ring[cons_head] can be reordered (speculative readed) by CPU.
> -	 */	
> +	 */
>  #if defined(__arm__) || defined(__aarch64__)
>  	cons_head = atomic_load_acq_32(&br->br_cons_head);
>  #else
>  	cons_head = br->br_cons_head;
>  #endif
>  	prod_tail = atomic_load_acq_32(&br->br_prod_tail);
> -	
> +
>  	cons_next = (cons_head + 1) & br->br_cons_mask;
>  #ifdef PREFETCH_DEFINED
>  	cons_next_next = (cons_head + 2) & br->br_cons_mask;
>  #endif
> -	
> -	if (cons_head == prod_tail) 
> -		return (NULL);
>  
> -#ifdef PREFETCH_DEFINED	
> -	if (cons_next != prod_tail) {		
> +	if (cons_head == prod_tail)
> +		return NULL;
> +
> +#ifdef PREFETCH_DEFINED
> +	if (cons_next != prod_tail) {
>  		prefetch(br->br_ring[cons_next]);
> -		if (cons_next_next != prod_tail) 
> +		if (cons_next_next != prod_tail)
>  			prefetch(br->br_ring[cons_next_next]);
>  	}
>  #endif
> +
>  	br->br_cons_head = cons_next;
>  	buf = br->br_ring[cons_head];
>  
>  #ifdef DEBUG_BUFRING
>  	br->br_ring[cons_head] = NULL;
> +
>  	if (!mtx_owned(br->br_lock))
>  		panic("lock not held on single consumer dequeue");
> +
>  	if (br->br_cons_tail != cons_head)
>  		panic("inconsistent list cons_tail=%d cons_head=%d",
> -		    br->br_cons_tail, cons_head);
> +				br->br_cons_tail, cons_head);
>  #endif
> +
>  	br->br_cons_tail = cons_next;
> -	return (buf);
> +	return buf;
>  }
>  
>  /*
> @@ -237,17 +252,20 @@ buf_ring_advance_sc(struct buf_ring *br)
>  {
>  	uint32_t cons_head, cons_next;
>  	uint32_t prod_tail;
> -	
> +
>  	cons_head = br->br_cons_head;
>  	prod_tail = br->br_prod_tail;
> -	
>  	cons_next = (cons_head + 1) & br->br_cons_mask;
> -	if (cons_head == prod_tail) 
> +
> +	if (cons_head == prod_tail)
>  		return;
> +
>  	br->br_cons_head = cons_next;
> +
>  #ifdef DEBUG_BUFRING
>  	br->br_ring[cons_head] = NULL;
>  #endif
> +
>  	br->br_cons_tail = cons_next;
>  }
>  
> @@ -270,8 +288,8 @@ buf_ring_advance_sc(struct buf_ring *br)
>  static __inline void
>  buf_ring_putback_sc(struct buf_ring *br, void *new)
>  {
> -	KASSERT(br->br_cons_head != br->br_prod_tail, 
> -		("Buf-Ring has none in putback")) ;
> +	KASSERT(br->br_cons_head != br->br_prod_tail,
> +		("Buf-Ring has none in putback"));
>  	br->br_ring[br->br_cons_head] = new;
>  }
>  
> @@ -283,11 +301,11 @@ buf_ring_putback_sc(struct buf_ring *br, void *new)
>  static __inline void *
>  buf_ring_peek(struct buf_ring *br)
>  {
> -
>  #ifdef DEBUG_BUFRING
>  	if ((br->br_lock != NULL) && !mtx_owned(br->br_lock))
>  		panic("lock not held on single consumer dequeue");
> -#endif	
> +#endif
> +
>  	/*
>  	 * I believe it is safe to not have a memory barrier
>  	 * here because we control cons and tail is worst case
> @@ -295,9 +313,9 @@ buf_ring_peek(struct buf_ring *br)
>  	 * return NULL immediately after a buffer has been enqueued
>  	 */
>  	if (br->br_cons_head == br->br_prod_tail)
> -		return (NULL);
> -	
> -	return (br->br_ring[br->br_cons_head]);
> +		return NULL;
> +
> +	return br->br_ring[br->br_cons_head];
>  }
>  
>  static __inline void *
> @@ -308,10 +326,10 @@ buf_ring_peek_clear_sc(struct buf_ring *br)
>  
>  	if (!mtx_owned(br->br_lock))
>  		panic("lock not held on single consumer dequeue");
> -#endif	
> +#endif
>  
>  	if (br->br_cons_head == br->br_prod_tail)
> -		return (NULL);
> +		return NULL;
>  
>  #if defined(__arm__) || defined(__aarch64__)
>  	/*
> @@ -334,38 +352,34 @@ buf_ring_peek_clear_sc(struct buf_ring *br)
>  	 */
>  	ret = br->br_ring[br->br_cons_head];
>  	br->br_ring[br->br_cons_head] = NULL;
> -	return (ret);
> +
> +	return ret;
>  #else
> -	return (br->br_ring[br->br_cons_head]);
> +	return br->br_ring[br->br_cons_head];
>  #endif
>  }
>  
>  static __inline int
>  buf_ring_full(struct buf_ring *br)
>  {
> -
> -	return (((br->br_prod_head + 1) & br->br_prod_mask) == br->br_cons_tail);
> +	return ((br->br_prod_head + 1) & br->br_prod_mask) == br->br_cons_tail;
>  }
>  
>  static __inline int
>  buf_ring_empty(struct buf_ring *br)
>  {
> -
> -	return (br->br_cons_head == br->br_prod_tail);
> +	return br->br_cons_head == br->br_prod_tail;
>  }
>  
>  static __inline int
>  buf_ring_count(struct buf_ring *br)
>  {
> -
> -	return ((br->br_prod_size + br->br_prod_tail - br->br_cons_tail)
> -	    & br->br_prod_mask);
> +	return (br->br_prod_size + br->br_prod_tail - br->br_cons_tail)
> +			& br->br_prod_mask;
>  }
>  
>  struct buf_ring *buf_ring_alloc(int count, struct malloc_type *type, int flags,
> -    struct mtx *);
> +		struct mtx *);
>  void buf_ring_free(struct buf_ring *br, struct malloc_type *type);
>  
> -
> -
>  #endif
> \ No newline at end of file
> diff --git a/lib/ukring/ring.c b/lib/ukring/ring.c
> index 644c3be..e327bd7 100644
> --- a/lib/ukring/ring.c
> +++ b/lib/ukring/ring.c
> @@ -42,20 +42,23 @@ buf_ring_alloc(int count, struct malloc_type *type, int flags, struct mtx *lock)
>  	struct buf_ring *br;
>  
>  	KASSERT(powerof2(count), ("buf ring must be size power of 2"));
> -	
> +
>  	br = malloc(sizeof(struct buf_ring) + count*sizeof(caddr_t),
> -	    type, flags|M_ZERO);
> +			type, flags|M_ZERO);
> +
>  	if (br == NULL)
> -		return (NULL);
> +		return NULL;
> +
>  #ifdef DEBUG_BUFRING
>  	br->br_lock = lock;
> -#endif	
> +#endif
> +
>  	br->br_prod_size = br->br_cons_size = count;
> -	br->br_prod_mask = br->br_cons_mask = count-1;
> +	br->br_prod_mask = br->br_cons_mask = count - 1;
>  	br->br_prod_head = br->br_cons_head = 0;
>  	br->br_prod_tail = br->br_cons_tail = 0;
> -		
> -	return (br);
> +
> +	return br;
>  }
>  
>  void
> 


From minios-devel-bounces@lists.xenproject.org Thu Jul 23 13:31:25 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 13:31:25 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jybJk-0000qq-3p; Thu, 23 Jul 2020 13:31:24 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=u2GH=BC=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jybJi-0000ql-U6
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 13:31:22 +0000
X-Inumbo-ID: caf37476-cce8-11ea-870e-bc764e2007e4
Received: from mx.upb.ro (unknown [141.85.13.210])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id caf37476-cce8-11ea-870e-bc764e2007e4;
 Thu, 23 Jul 2020 13:31:20 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 83A51B561D1A;
 Thu, 23 Jul 2020 16:31:19 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id pfGxzzbKyit8; Thu, 23 Jul 2020 16:31:16 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 215B7B561D40;
 Thu, 23 Jul 2020 16:31:16 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id Xbz4d_rhYcHD; Thu, 23 Jul 2020 16:31:16 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id 5A462B561D1A;
 Thu, 23 Jul 2020 16:31:15 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH v3 3/5] lib/ukring: Adapt {ring.c, ring.h} to
 Unikraft
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200723124903.95372-1-a.jung@lancs.ac.uk>
 <20200723124903.95372-4-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <2f0ddf92-4787-1fa0-aad2-6e540df245b7@cs.pub.ro>
Date: Thu, 23 Jul 2020 16:31:15 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200723124903.95372-4-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

I'm gonna fix the uk_preempt_*() calls on upstreaming:

critical_enter -> uk_preempt_disable
critical_exit  -> uk_preempt_enable

Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>

On 7/23/20 3:49 PM, Alexander Jung wrote:
> This includes Unikraft-centric headers and types.
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/ukring/include/uk/ring.h | 101 +++++++++++++++++++++++--------------------
>  lib/ukring/ring.c            |  37 ++++++++--------
>  2 files changed, 72 insertions(+), 66 deletions(-)
> 
> diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
> index abc95fe..6bc789d 100644
> --- a/lib/ukring/include/uk/ring.h
> +++ b/lib/ukring/include/uk/ring.h
> @@ -32,12 +32,16 @@
>  #ifndef _SYS_BUF_RING_H_
>  #define _SYS_BUF_RING_H_
>  
> -#include <machine/cpu.h>
> +#include <errno.h>
> +#include <uk/mutex.h>
> +#include <uk/print.h>
> +#include <uk/config.h>
> +#include <uk/assert.h>
> +#include <uk/plat/lcpu.h>
> +#include <uk/arch/atomic.h>
> +#include <uk/essentials.h>
> +#include <uk/preempt.h>
>  
> -#ifdef DEBUG_BUFRING
> -#include <sys/lock.h>
> -#include <sys/mutex.h>
> -#endif
>  
>  
>  struct buf_ring {
> @@ -50,8 +54,8 @@ struct buf_ring {
>  	volatile uint32_t br_cons_tail;
>  	int               br_cons_size;
>  	int               br_cons_mask;
> -#ifdef DEBUG_BUFRING
> -	struct mtx       *br_lock;
> +#ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
> +	struct uk_mutex  *br_lock;
>  #endif
>  	void             *br_ring[0] __aligned(CACHE_LINE_SIZE);
>  };
> @@ -66,7 +70,7 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
>  {
>  	uint32_t prod_head, prod_next, cons_tail;
>  
> -#ifdef DEBUG_BUFRING
> +#ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
>  	int i;
>  
>  	/*
> @@ -77,11 +81,11 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
>  	for (i = br->br_cons_head; i != br->br_prod_head;
>  			 i = ((i + 1) & br->br_cons_mask))
>  		if (br->br_ring[i] == buf)
> -			panic("buf=%p already enqueue at %d prod=%d cons=%d",
> +			UK_CRASH("buf=%p already enqueue at %d prod=%d cons=%d",
>  					buf, i, br->br_prod_tail, br->br_cons_tail);
>  #endif
>  
> -	critical_enter();
> +	uk_preempt_enable();
>  
>  	do {
>  		prod_head = br->br_prod_head;
> @@ -92,16 +96,17 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
>  			rmb();
>  			if (prod_head == br->br_prod_head && cons_tail == br->br_cons_tail) {
>  				br->br_drops++;
> -				critical_exit();
> +				uk_preempt_disable();
>  				return -ENOBUFS;
>  			}
>  			continue;
>  		}
> -	} while (!atomic_cmpset_acq_int(&br->br_prod_head, prod_head, prod_next));
> +	} while (!ukarch_compare_exchange_sync(&br->br_prod_head, prod_head,
> +					prod_next));
>  
> -#ifdef DEBUG_BUFRING
> +#ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
>  	if (br->br_ring[prod_head] != NULL)
> -		panic("dangling value in enqueue");
> +		UK_CRASH("dangling value in enqueue");
>  #endif
>  
>  	br->br_ring[prod_head] = buf;
> @@ -112,10 +117,10 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
>  	 * to complete 
>  	 */
>  	while (br->br_prod_tail != prod_head)
> -		cpu_spinwait();
> +		ukarch_spinwait();
>  
> -	atomic_store_rel_int(&br->br_prod_tail, prod_next);
> -	critical_exit();
> +	ukarch_store_n(&br->br_prod_tail, prod_next);
> +	uk_preempt_disable();
>  
>  	return 0;
>  }
> @@ -130,21 +135,22 @@ buf_ring_dequeue_mc(struct buf_ring *br)
>  	uint32_t cons_head, cons_next;
>  	void *buf;
>  
> -	critical_enter();
> +	uk_preempt_enable();
>  
>  	do {
>  		cons_head = br->br_cons_head;
>  		cons_next = (cons_head + 1) & br->br_cons_mask;
>  
>  		if (cons_head == br->br_prod_tail) {
> -			critical_exit();
> +			uk_preempt_disable();
>  			return NULL;
>  		}
> -	} while (!atomic_cmpset_acq_int(&br->br_cons_head, cons_head, cons_next));
> +	} while (!ukarch_compare_exchange_sync(&br->br_cons_head, cons_head,
> +					cons_next));
>  
>  	buf = br->br_ring[cons_head];
>  
> -#ifdef DEBUG_BUFRING
> +#ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
>  	br->br_ring[cons_head] = NULL;
>  #endif
>  
> @@ -154,10 +160,10 @@ buf_ring_dequeue_mc(struct buf_ring *br)
>  	 * to complete
>  	 */
>  	while (br->br_cons_tail != cons_head)
> -		cpu_spinwait();
> +		ukarch_spinwait();
>  
> -	atomic_store_rel_int(&br->br_cons_tail, cons_next);
> -	critical_exit();
> +	ukarch_store_n(&br->br_cons_tail, cons_next);
> +	uk_preempt_disable();
>  
>  	return buf;
>  }
> @@ -201,12 +207,12 @@ buf_ring_dequeue_sc(struct buf_ring *br)
>  	 *
>  	 * <1> Load (on core 1) from br->br_ring[cons_head] can be reordered (speculative readed) by CPU.
>  	 */
> -#if defined(__arm__) || defined(__aarch64__)
> -	cons_head = atomic_load_acq_32(&br->br_cons_head);
> +#if defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64)
> +	cons_head = ukarch_load_n(&br->br_cons_head);
>  #else
>  	cons_head = br->br_cons_head;
>  #endif
> -	prod_tail = atomic_load_acq_32(&br->br_prod_tail);
> +	prod_tail = ukarch_load_n(&br->br_prod_tail);
>  
>  	cons_next = (cons_head + 1) & br->br_cons_mask;
>  #ifdef PREFETCH_DEFINED
> @@ -227,14 +233,14 @@ buf_ring_dequeue_sc(struct buf_ring *br)
>  	br->br_cons_head = cons_next;
>  	buf = br->br_ring[cons_head];
>  
> -#ifdef DEBUG_BUFRING
> +#ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
>  	br->br_ring[cons_head] = NULL;
>  
> -	if (!mtx_owned(br->br_lock))
> -		panic("lock not held on single consumer dequeue");
> +	if (!uk_mutex_is_locked(br->br_lock))
> +		UK_CRASH("lock not held on single consumer dequeue: %d", br->br_lock->lock_count);
>  
>  	if (br->br_cons_tail != cons_head)
> -		panic("inconsistent list cons_tail=%d cons_head=%d",
> +		UK_CRASH("inconsistent list cons_tail=%d cons_head=%d",
>  				br->br_cons_tail, cons_head);
>  #endif
>  
> @@ -262,7 +268,7 @@ buf_ring_advance_sc(struct buf_ring *br)
>  
>  	br->br_cons_head = cons_next;
>  
> -#ifdef DEBUG_BUFRING
> +#ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
>  	br->br_ring[cons_head] = NULL;
>  #endif
>  
> @@ -288,8 +294,8 @@ buf_ring_advance_sc(struct buf_ring *br)
>  static __inline void
>  buf_ring_putback_sc(struct buf_ring *br, void *new)
>  {
> -	KASSERT(br->br_cons_head != br->br_prod_tail,
> -		("Buf-Ring has none in putback"));
> +	/* Buffer ring has none in putback */
> +	UK_ASSERT(br->br_cons_head != br->br_prod_tail);
>  	br->br_ring[br->br_cons_head] = new;
>  }
>  
> @@ -301,9 +307,9 @@ buf_ring_putback_sc(struct buf_ring *br, void *new)
>  static __inline void *
>  buf_ring_peek(struct buf_ring *br)
>  {
> -#ifdef DEBUG_BUFRING
> -	if ((br->br_lock != NULL) && !mtx_owned(br->br_lock))
> -		panic("lock not held on single consumer dequeue");
> +#ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
> +	if (!uk_mutex_is_locked(br->br_lock))
> +		UK_CRASH("lock not held on single consumer dequeue");
>  #endif
>  
>  	/*
> @@ -321,17 +327,17 @@ buf_ring_peek(struct buf_ring *br)
>  static __inline void *
>  buf_ring_peek_clear_sc(struct buf_ring *br)
>  {
> -#ifdef DEBUG_BUFRING
> +#ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
>  	void *ret;
>  
> -	if (!mtx_owned(br->br_lock))
> -		panic("lock not held on single consumer dequeue");
> +	if (!uk_mutex_is_locked(br->br_lock))
> +		UK_CRASH("lock not held on single consumer dequeue");
>  #endif
>  
>  	if (br->br_cons_head == br->br_prod_tail)
>  		return NULL;
>  
> -#if defined(__arm__) || defined(__aarch64__)
> +#if defined(CONFIG_ARCH_ARM_32) || defined(CONFIG_ARCH_ARM_64)
>  	/*
>  	 * The barrier is required there on ARM and ARM64 to ensure, that
>  	 * br->br_ring[br->br_cons_head] will not be fetched before the above
> @@ -342,10 +348,11 @@ buf_ring_peek_clear_sc(struct buf_ring *br)
>  	 * conditional check will be true, so we will return previously fetched
>  	 * (and invalid) buffer.
>  	 */
> -	atomic_thread_fence_acq();
> +	#error "unsupported: atomic_thread_fence_acq()"
> +	/* atomic_thread_fence_acq(); */
>  #endif
>  
> -#ifdef DEBUG_BUFRING
> +#ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
>  	/*
>  	 * Single consumer, i.e. cons_head will not move while we are
>  	 * running, so atomic_swap_ptr() is not necessary here.
> @@ -378,8 +385,8 @@ buf_ring_count(struct buf_ring *br)
>  			& br->br_prod_mask;
>  }
>  
> -struct buf_ring *buf_ring_alloc(int count, struct malloc_type *type, int flags,
> -		struct mtx *);
> -void buf_ring_free(struct buf_ring *br, struct malloc_type *type);
> +struct buf_ring *buf_ring_alloc(int count, struct uk_alloc *a, int flags,
> +		struct uk_mutex *lock);
> +void buf_ring_free(struct buf_ring *br, struct uk_alloc *a);
>  
> -#endif
> \ No newline at end of file
> +#endif
> diff --git a/lib/ukring/ring.c b/lib/ukring/ring.c
> index e327bd7..2badb79 100644
> --- a/lib/ukring/ring.c
> +++ b/lib/ukring/ring.c
> @@ -26,30 +26,29 @@
>   * SUCH DAMAGE.
>   */
>  
> -#include <sys/cdefs.h>
> -__FBSDID("$FreeBSD$");
> -
> -#include <sys/param.h>
> -#include <sys/systm.h>
> -#include <sys/kernel.h>
> -#include <sys/malloc.h>
> -#include <sys/ktr.h>
> -#include <sys/buf_ring.h>
> +#include <uk/ring.h>
> +#include <uk/assert.h>
> +#include <uk/alloc.h>
> +#include <uk/mutex.h>
> +#include <uk/config.h>
> +#include <uk/print.h>
> +#include <uk/essentials.h>
>  
>  struct buf_ring *
> -buf_ring_alloc(int count, struct malloc_type *type, int flags, struct mtx *lock)
> +buf_ring_alloc(int count, struct uk_alloc *a, int flags, struct uk_mutex *lock)
>  {
>  	struct buf_ring *br;
>  
> -	KASSERT(powerof2(count), ("buf ring must be size power of 2"));
> -
> -	br = malloc(sizeof(struct buf_ring) + count*sizeof(caddr_t),
> -			type, flags|M_ZERO);
> +	/* buf ring must be size power of 2 */
> +	UK_ASSERT(POWER_OF_2(count));
>  
> -	if (br == NULL)
> +	br = uk_malloc(a, sizeof(struct buf_ring) + count * sizeof(caddr_t));
> +	if (br == NULL) {
> +		uk_pr_err("could not allocate ring\n");
>  		return NULL;
> +	}
>  
> -#ifdef DEBUG_BUFRING
> +#ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
>  	br->br_lock = lock;
>  #endif
>  
> @@ -62,7 +61,7 @@ buf_ring_alloc(int count, struct malloc_type *type, int flags, struct mtx *lock)
>  }
>  
>  void
> -buf_ring_free(struct buf_ring *br, struct malloc_type *type)
> +buf_ring_free(struct buf_ring *br, struct uk_alloc *a)
>  {
> -	free(br, type);
> -}
> \ No newline at end of file
> +	uk_free(a, br);
> +}
> 


From minios-devel-bounces@lists.xenproject.org Thu Jul 23 13:31:43 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 13:31:43 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jybK3-0000sQ-65; Thu, 23 Jul 2020 13:31:43 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=u2GH=BC=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jybK1-0000sK-Sb
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 13:31:41 +0000
X-Inumbo-ID: d6e256c6-cce8-11ea-870e-bc764e2007e4
Received: from mx.upb.ro (unknown [141.85.13.200])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id d6e256c6-cce8-11ea-870e-bc764e2007e4;
 Thu, 23 Jul 2020 13:31:40 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 8A393B561D1A;
 Thu, 23 Jul 2020 16:31:39 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id wxSdZCRbWITv; Thu, 23 Jul 2020 16:31:37 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id F1E0BB561D40;
 Thu, 23 Jul 2020 16:31:36 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id NQ3N5NR4ESKl; Thu, 23 Jul 2020 16:31:36 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id 67681B561D1A;
 Thu, 23 Jul 2020 16:31:36 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH v3 4/5] lib/ukring: Re-prefix methods and structs
 from buf_ to uk_
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200723124903.95372-1-a.jung@lancs.ac.uk>
 <20200723124903.95372-5-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <d6e1e616-5cbf-e3cd-128a-52e66fa620ff@cs.pub.ro>
Date: Thu, 23 Jul 2020 16:31:36 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200723124903.95372-5-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>

On 7/23/20 3:49 PM, Alexander Jung wrote:
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/ukring/include/uk/ring.h | 36 ++++++++++++++++++------------------
>  lib/ukring/ring.c            | 10 +++++-----
>  2 files changed, 23 insertions(+), 23 deletions(-)
> 
> diff --git a/lib/ukring/include/uk/ring.h b/lib/ukring/include/uk/ring.h
> index 6bc789d..a787807 100644
> --- a/lib/ukring/include/uk/ring.h
> +++ b/lib/ukring/include/uk/ring.h
> @@ -29,8 +29,8 @@
>   *
>   */
>  
> -#ifndef _SYS_BUF_RING_H_
> -#define _SYS_BUF_RING_H_
> +#ifndef __UK_RING_H__
> +#define __UK_RING_H__
>  
>  #include <errno.h>
>  #include <uk/mutex.h>
> @@ -44,7 +44,7 @@
>  
>  
>  
> -struct buf_ring {
> +struct uk_ring {
>  	volatile uint32_t br_prod_head;
>  	volatile uint32_t br_prod_tail;
>  	int               br_prod_size;
> @@ -66,7 +66,7 @@ struct buf_ring {
>   *
>   */
>  static __inline int
> -buf_ring_enqueue(struct buf_ring *br, void *buf)
> +uk_ring_enqueue(struct uk_ring *br, void *buf)
>  {
>  	uint32_t prod_head, prod_next, cons_tail;
>  
> @@ -130,7 +130,7 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
>   *
>   */
>  static __inline void *
> -buf_ring_dequeue_mc(struct buf_ring *br)
> +uk_ring_dequeue_mc(struct uk_ring *br)
>  {
>  	uint32_t cons_head, cons_next;
>  	void *buf;
> @@ -174,7 +174,7 @@ buf_ring_dequeue_mc(struct buf_ring *br)
>   * e.g. a network driver's tx queue lock
>   */
>  static __inline void *
> -buf_ring_dequeue_sc(struct buf_ring *br)
> +uk_ring_dequeue_sc(struct uk_ring *br)
>  {
>  	uint32_t cons_head, cons_next;
>  #ifdef PREFETCH_DEFINED
> @@ -184,15 +184,15 @@ buf_ring_dequeue_sc(struct buf_ring *br)
>  	void *buf;
>  
>  	/*
> -	 * This is a workaround to allow using buf_ring on ARM and ARM64.
> -	 * ARM64TODO: Fix buf_ring in a generic way.
> +	 * This is a workaround to allow using uk_ring on ARM and ARM64.
> +	 * ARM64TODO: Fix uk_ring in a generic way.
>  	 * REMARKS: It is suspected that br_cons_head does not require
>  	 *   load_acq operation, but this change was extensively tested
>  	 *   and confirmed it's working. To be reviewed once again in
>  	 *   FreeBSD-12.
>  	 *
>  	 * Preventing following situation:
> -	 * Core(0) - buf_ring_enqueue()                                       Core(1) - buf_ring_dequeue_sc()
> +	 * Core(0) - uk_ring_enqueue()                                       Core(1) - uk_ring_dequeue_sc()
>  	 * -----------------------------------------                                       ----------------------------------------------
>  	 *
>  	 *                                                                                cons_head = br->br_cons_head;
> @@ -254,7 +254,7 @@ buf_ring_dequeue_sc(struct buf_ring *br)
>   * e.g. a network driver's tx queue lock
>   */
>  static __inline void
> -buf_ring_advance_sc(struct buf_ring *br)
> +uk_ring_advance_sc(struct uk_ring *br)
>  {
>  	uint32_t cons_head, cons_next;
>  	uint32_t prod_tail;
> @@ -292,7 +292,7 @@ buf_ring_advance_sc(struct buf_ring *br)
>   * the compare and an atomic.
>   */
>  static __inline void
> -buf_ring_putback_sc(struct buf_ring *br, void *new)
> +uk_ring_putback_sc(struct uk_ring *br, void *new)
>  {
>  	/* Buffer ring has none in putback */
>  	UK_ASSERT(br->br_cons_head != br->br_prod_tail);
> @@ -305,7 +305,7 @@ buf_ring_putback_sc(struct buf_ring *br, void *new)
>   * race-prone if not protected by a lock
>   */
>  static __inline void *
> -buf_ring_peek(struct buf_ring *br)
> +uk_ring_peek(struct uk_ring *br)
>  {
>  #ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
>  	if (!uk_mutex_is_locked(br->br_lock))
> @@ -325,7 +325,7 @@ buf_ring_peek(struct buf_ring *br)
>  }
>  
>  static __inline void *
> -buf_ring_peek_clear_sc(struct buf_ring *br)
> +uk_ring_peek_clear_sc(struct uk_ring *br)
>  {
>  #ifdef CONFIG_LIBUKRING_DEBUG_BUFRING
>  	void *ret;
> @@ -367,26 +367,26 @@ buf_ring_peek_clear_sc(struct buf_ring *br)
>  }
>  
>  static __inline int
> -buf_ring_full(struct buf_ring *br)
> +uk_ring_full(struct uk_ring *br)
>  {
>  	return ((br->br_prod_head + 1) & br->br_prod_mask) == br->br_cons_tail;
>  }
>  
>  static __inline int
> -buf_ring_empty(struct buf_ring *br)
> +uk_ring_empty(struct uk_ring *br)
>  {
>  	return br->br_cons_head == br->br_prod_tail;
>  }
>  
>  static __inline int
> -buf_ring_count(struct buf_ring *br)
> +uk_ring_count(struct uk_ring *br)
>  {
>  	return (br->br_prod_size + br->br_prod_tail - br->br_cons_tail)
>  			& br->br_prod_mask;
>  }
>  
> -struct buf_ring *buf_ring_alloc(int count, struct uk_alloc *a, int flags,
> +struct uk_ring *uk_ring_alloc(int count, struct uk_alloc *a, int flags,
>  		struct uk_mutex *lock);
> -void buf_ring_free(struct buf_ring *br, struct uk_alloc *a);
> +void uk_ring_free(struct uk_ring *br, struct uk_alloc *a);
>  
>  #endif
> diff --git a/lib/ukring/ring.c b/lib/ukring/ring.c
> index 2badb79..ea46107 100644
> --- a/lib/ukring/ring.c
> +++ b/lib/ukring/ring.c
> @@ -34,15 +34,15 @@
>  #include <uk/print.h>
>  #include <uk/essentials.h>
>  
> -struct buf_ring *
> -buf_ring_alloc(int count, struct uk_alloc *a, int flags, struct uk_mutex *lock)
> +struct uk_ring *
> +uk_ring_alloc(int count, struct uk_alloc *a, int flags, struct uk_mutex *lock)
>  {
> -	struct buf_ring *br;
> +	struct uk_ring *br;
>  
>  	/* buf ring must be size power of 2 */
>  	UK_ASSERT(POWER_OF_2(count));
>  
> -	br = uk_malloc(a, sizeof(struct buf_ring) + count * sizeof(caddr_t));
> +	br = uk_malloc(a, sizeof(struct uk_ring) + count * sizeof(caddr_t));
>  	if (br == NULL) {
>  		uk_pr_err("could not allocate ring\n");
>  		return NULL;
> @@ -61,7 +61,7 @@ buf_ring_alloc(int count, struct uk_alloc *a, int flags, struct uk_mutex *lock)
>  }
>  
>  void
> -buf_ring_free(struct buf_ring *br, struct uk_alloc *a)
> +uk_ring_free(struct uk_ring *br, struct uk_alloc *a)
>  {
>  	uk_free(a, br);
>  }
> 


From minios-devel-bounces@lists.xenproject.org Thu Jul 23 13:32:34 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 13:32:34 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jybKs-0000tx-AW; Thu, 23 Jul 2020 13:32:34 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=u2GH=BC=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jybKr-0000ts-9m
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 13:32:33 +0000
X-Inumbo-ID: f5ef431c-cce8-11ea-a299-12813bfff9fa
Received: from mx.upb.ro (unknown [141.85.13.200])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id f5ef431c-cce8-11ea-a299-12813bfff9fa;
 Thu, 23 Jul 2020 13:32:32 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id A5807B561D1A;
 Thu, 23 Jul 2020 16:32:31 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id jwGng0_vWBni; Thu, 23 Jul 2020 16:32:29 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 7BD8CB561D38;
 Thu, 23 Jul 2020 16:32:29 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id rEu-0QNhGpMC; Thu, 23 Jul 2020 16:32:29 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id E372DB561D1A;
 Thu, 23 Jul 2020 16:32:28 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH v3 5/5] lib/ukring: Register ukring with Unikraft
To: Alexander Jung <a.jung@lancs.ac.uk>, minios-devel@lists.xen.org
References: <20200723124903.95372-1-a.jung@lancs.ac.uk>
 <20200723124903.95372-6-a.jung@lancs.ac.uk>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <66cc9b8c-7f83-029e-2b56-a26ccf11aaf9@cs.pub.ro>
Date: Thu, 23 Jul 2020 16:32:28 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <20200723124903.95372-6-a.jung@lancs.ac.uk>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Alexander,

I'm gonna drop both LIBUKRING_CACHE_LINE_SIZE and
CONFIG_LIBUKRING_DEBUG_BUFRING on upstreaming.

Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>

On 7/23/20 3:49 PM, Alexander Jung wrote:
> This commit registers the ring buffer implementation micro-library
> with Unikraft by including it in the global library list, exports
> the ring buffer's main functions and includes the relevant initial
> Makefile.uk and Config.uk library files.
> 
> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
> ---
>  lib/Makefile.uk          |  1 +
>  lib/ukring/Config.uk     | 23 +++++++++++++++++++++++
>  lib/ukring/Makefile.uk   |  6 ++++++
>  lib/ukring/exportsyms.uk | 12 ++++++++++++
>  4 files changed, 42 insertions(+)
>  create mode 100644 lib/ukring/Config.uk
>  create mode 100644 lib/ukring/Makefile.uk
>  create mode 100644 lib/ukring/exportsyms.uk
> 
> diff --git a/lib/Makefile.uk b/lib/Makefile.uk
> index 360fcd8..4fd222d 100644
> --- a/lib/Makefile.uk
> +++ b/lib/Makefile.uk
> @@ -25,6 +25,7 @@ $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/devfs))
>  $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/9pfs))
>  $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uklock))
>  $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukmpi))
> +$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukring))
>  $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukbus))
>  $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uksglist))
>  $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uknetdev))
> diff --git a/lib/ukring/Config.uk b/lib/ukring/Config.uk
> new file mode 100644
> index 0000000..2481c62
> --- /dev/null
> +++ b/lib/ukring/Config.uk
> @@ -0,0 +1,23 @@
> +menuconfig LIBUKRING
> +  bool "ukring: Ring buffer interface"
> +  select LIBUKALLOC
> +  select LIBUKLOCK
> +  default n
> +  help
> +    Provide ring interface for handling object references.
> +
> +if LIBUKRING
> +
> +config LIBUKRING_CACHE_LINE_SIZE
> +  int "Cache line size"
> +  default 32
> +  help
> +    Size in bytes of a CPU d-cache line.
> +
> +config CONFIG_LIBUKRING_DEBUG_BUFRING
> +  bool "Debug the ring interface"
> +  default n
> +  help
> +    When debugging, this library stores some per-ring statistic counters about the number of enqueues/dequeues.  These statistics require a mutex to avoid concurrent accesses or atomic operations.
> +
> +endif
> diff --git a/lib/ukring/Makefile.uk b/lib/ukring/Makefile.uk
> new file mode 100644
> index 0000000..7874ca2
> --- /dev/null
> +++ b/lib/ukring/Makefile.uk
> @@ -0,0 +1,6 @@
> +$(eval $(call addlib_s,libukring,$(CONFIG_LIBUKRING)))
> +
> +CINCLUDES-$(CONFIG_LIBUKRING)   += -I$(LIBUKRING_BASE)/include
> +CXXINCLUDES-$(CONFIG_LIBUKRING) += -I$(LIBUKRING_BASE)/include
> +
> +LIBUKRING_SRCS-y += $(LIBUKRING_BASE)/ring.c
> diff --git a/lib/ukring/exportsyms.uk b/lib/ukring/exportsyms.uk
> new file mode 100644
> index 0000000..098f25a
> --- /dev/null
> +++ b/lib/ukring/exportsyms.uk
> @@ -0,0 +1,12 @@
> +uk_ring_alloc
> +uk_ring_free
> +uk_ring_enqueue
> +uk_ring_dequeue_mc
> +uk_ring_dequeue_sc
> +uk_ring_advance_sc
> +uk_ring_putback_sc
> +uk_ring_peek
> +uk_ring_peek_clear_sc
> +uk_ring_full
> +uk_ring_empty
> +uk_ring_count
> 


From minios-devel-bounces@lists.xenproject.org Thu Jul 23 13:36:29 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 13:36:29 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jybOd-0000zS-Lw; Thu, 23 Jul 2020 13:36:27 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BMUt=BC=lancaster.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1jybOc-0000zN-Hx
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 13:36:26 +0000
X-Inumbo-ID: 801e74a4-cce9-11ea-8711-bc764e2007e4
Received: from GBR01-LO2-obe.outbound.protection.outlook.com (unknown
 [40.107.10.121]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 801e74a4-cce9-11ea-8711-bc764e2007e4;
 Thu, 23 Jul 2020 13:36:24 +0000 (UTC)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=n3hvv7ZcJbJlNw1iSXbYOjcoje2Q312E5xyDx1ysc3y8xMyKsXHBDmEIaTfqxZoI+nce2qa/WHUvL2+K7slaH4acPaghY/94k8W3iEQqbs9U7hHkP2moVIMvaOHF6p2FkAzX1cjklsVcUQkfDmr2NlZ33UIvFdUzv4AaWMGvKMYM75Xz5Fu4ZEvK0cdriw7PgYNxA6/JhKUhpRihDGNjsXkTt6KV5HFdBwC8+pUFqb8GKtejIBKGzxtvsFQylOn6m9WHDodYLcnljs4WS+TnCxaCVqdGnMipD5UNHDuoT7Y7tfvQWISauAzIKdc/trbhGSpNjyeC2xtq09Ka5ATqDQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; 
 s=arcselector9901;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=xnEg7w8vrdKiEVW4E+s0nyn1J9UaOW/WlsR0JEe69VI=;
 b=W7Cx0l3AvjFg1CvSPD0Y468yiEXPsEa12GU67dhuZVoqFWnSMrxN254ku5m5gsPZow+DI5m41PYuhjPpyeSrtkHN51nzcPgbaP7eIZrzpZeTyIjNn45UENmHotBjow+4NynPMJklfb85y2JTZp42mEzHjyZF2rq8wEBSNqWOBsha/TkJfdyYFwXcrIX5uBYt4I9+OUNfdQ+WgJ9re7ydPAQNZxJ5rFp23uX85feZboSXUdAjsTSXhb+jYfowKSkZX3VNecSPbYuWxO4SJxoKS5KPBvWk7Pl8iXPX2dQJv3g94Y3YvE8DCSa8OGKVd+CKdKJ/TPvm3PD+lMhq/ykwZA==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
 smtp.mailfrom=lancaster.ac.uk; dmarc=pass action=none
 header.from=lancaster.ac.uk; dkim=pass header.d=lancaster.ac.uk; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=livelancsac.onmicrosoft.com; s=selector2-livelancsac-onmicrosoft-com;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=xnEg7w8vrdKiEVW4E+s0nyn1J9UaOW/WlsR0JEe69VI=;
 b=yVs9mlRwVmlzivwzgzb9O2aSScpwoPFmyvP+rl1K7m0mpLJxIRNHGsEzDc2e0i2PqAK1JvwjQZfD2boQxcmvu2+fwyL9w/ioOPjyjZaahJeT0I8bHYBUqZEOCalBSKopAz5MV2FrVXWjkaZFyi9gvCOnnOHhqudASJK+PGBb0cE=
Received: from CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM (2603:10a6:401:17::15)
 by CWXP265MB2454.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:9c::14) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23; Thu, 23 Jul
 2020 13:36:23 +0000
Received: from CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM
 ([fe80::fcde:79b:21d6:5203]) by CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM
 ([fe80::fcde:79b:21d6:5203%4]) with mapi id 15.20.3216.020; Thu, 23 Jul 2020
 13:36:22 +0000
From: "Jung, Alexander" <a.jung@lancaster.ac.uk>
To: Costin Lupu <costin.lupu@cs.pub.ro>, Alexander Jung <a.jung@lancs.ac.uk>, 
 "minios-devel@lists.xen.org" <minios-devel@lists.xen.org>
Subject: Re: [UNIKRAFT PATCH v3 5/5] lib/ukring: Register ukring with Unikraft
Thread-Topic: [UNIKRAFT PATCH v3 5/5] lib/ukring: Register ukring with Unikraft
Thread-Index: AQHWYPZBNWMakEDsvUy0mGmfe/Q6Sw==
Date: Thu, 23 Jul 2020 13:36:22 +0000
Message-ID: <51EB4F7B-6DF7-487B-8ED9-AA3BAA84B4FC@lancaster.ac.uk>
References: <20200723124903.95372-1-a.jung@lancs.ac.uk>
 <20200723124903.95372-6-a.jung@lancs.ac.uk>
 <66cc9b8c-7f83-029e-2b56-a26ccf11aaf9@cs.pub.ro>
In-Reply-To: <66cc9b8c-7f83-029e-2b56-a26ccf11aaf9@cs.pub.ro>
Accept-Language: en-GB, en-US
Content-Language: en-GB
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
user-agent: Microsoft-MacOutlook/16.38.20061401
authentication-results: cs.pub.ro; dkim=none (message not signed)
 header.d=none;cs.pub.ro; dmarc=none action=none header.from=lancaster.ac.uk;
x-originating-ip: [87.184.102.241]
x-ms-publictraffictype: Email
x-ms-office365-filtering-correlation-id: 003ab79b-3f61-47e9-2cfa-08d82f0d63df
x-ms-traffictypediagnostic: CWXP265MB2454:
x-microsoft-antispam-prvs: <CWXP265MB245468638F0FE1558A47057ACE760@CWXP265MB2454.GBRP265.PROD.OUTLOOK.COM>
x-ms-oob-tlc-oobclassifiers: OLM:597;
x-ms-exchange-senderadcheck: 1
x-microsoft-antispam: BCL:0;
x-microsoft-antispam-message-info: EcW/oLR27FEdwDT/+l3pV++keemaLODIIZMXBQNIDqFDaW8wHgpSsQAXysLKK3gleyCMij0lle//BojmD4F4/I/JyQ+FJfHRx5rkZtoCx2+sxr+RMllka9nRuBeF3SlkFLj87ShJPlVjR7QNcvjfEg/UlgHKUgEOE+VOrlLPkFzMIzUues4TH2nrCr8DoMSgB7KzdD0To/AonfwlGGqzB//c5yDIATrzL6Gp4bvHcHJvxNRToHUvvTDPpPFy6DaJw88uPvpSRRvJ63WyVMwKMvjfkHTBSQCak1WkXOr+ykUWJgML/exZCMjQ4ic0fkkt2m2EXPOyk3JUrStrjudL6g==
x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
 IPV:NLI; SFV:NSPM; H:CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM; PTR:; CAT:NONE;
 SFTY:;
 SFS:(4636009)(376002)(39860400002)(396003)(136003)(346002)(366004)(8936002)(33656002)(786003)(316002)(2906002)(86362001)(6486002)(8676002)(71200400001)(186003)(83380400001)(53546011)(4326008)(66476007)(66946007)(110136005)(478600001)(66446008)(66556008)(26005)(6506007)(5660300002)(54906003)(91956017)(6512007)(2616005)(64756008)(36756003)(76116006);
 DIR:OUT; SFP:1102; 
x-ms-exchange-antispam-messagedata: C3XTNd7x5UVy/FMzFaOgbd0+rvewWvOQqCJrCck4dHcstReFLI5jaL06GcHQjUJzcwmrmwiqtWid0mpeVe33lTxSenM1ujbXGgt2u+8CE1shO7X7Tx602c4gxUcA5K0wIO93Xb1gfEWVFU9iDFH03t1cv8sWxujh+NIcV47NMpBLc40UYlc2HB0kwSs/sXd4AQ2zq26xmBKi+mVj/eu+LUi8TZfgU/ppMklCzYXIZJjE/Hnkf+qwfqAYtuudlPAAL8nJJ05AArc0EwSTGIGNxntMLpabVu3CTs3nc5y6rrXO72pvv6Cd44snVHpzLMPa9PdnbEbOO9deQy/CBVSlwyhdAboxrjuU80LGyUN0bdzkmZ1J3ELAT23YZhgj1EG9+YdN9QfHk+S8kHWtC+l+pz5uqpxIMV3RhJgBa9JOooErnzwjjwgfPtDi9eVpHRaxdng/5tMfXF3JqdnsDdPnRGZ+08ouZFMYgRiGnaLSMY0IaGkEpHl3U4oZ6HKVdAo3
x-ms-exchange-transport-forked: True
Content-Type: text/plain; charset="utf-8"
Content-ID: <0D462ADC75509149865D2EBB6D83908B@GBRP265.PROD.OUTLOOK.COM>
Content-Transfer-Encoding: base64
MIME-Version: 1.0
X-OriginatorOrg: lancaster.ac.uk
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: CWLP265MB0387.GBRP265.PROD.OUTLOOK.COM
X-MS-Exchange-CrossTenant-Network-Message-Id: 003ab79b-3f61-47e9-2cfa-08d82f0d63df
X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Jul 2020 13:36:22.8266 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 9c9bcd11-977a-4e9c-a9a0-bc734090164a
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: e8c6kMFE1OtLqV/iZzQfIJinN4USIbqp1oMzf6+JhJWocUSk8rvE3f+UBFp3xH/xLpTm7NyyZJMcnsBHwPCSUw==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWXP265MB2454
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

VGhhbmtzIGZvciB0aGUgaGVscCBhbmQgcmV2aWV3LiA6KQ0KDQrvu79PbiAyMy4wNy4yMCwgMTU6
MzUsICJNaW5pb3MtZGV2ZWwgb24gYmVoYWxmIG9mIENvc3RpbiBMdXB1IiA8bWluaW9zLWRldmVs
LWJvdW5jZXNAbGlzdHMueGVucHJvamVjdC5vcmcgb24gYmVoYWxmIG9mIGNvc3Rpbi5sdXB1QGNz
LnB1Yi5ybz4gd3JvdGU6DQoNCiAgICBIaSBBbGV4YW5kZXIsDQoNCiAgICBJJ20gZ29ubmEgZHJv
cCBib3RoIExJQlVLUklOR19DQUNIRV9MSU5FX1NJWkUgYW5kDQogICAgQ09ORklHX0xJQlVLUklO
R19ERUJVR19CVUZSSU5HIG9uIHVwc3RyZWFtaW5nLg0KDQogICAgUmV2aWV3ZWQtYnk6IENvc3Rp
biBMdXB1IDxjb3N0aW4ubHVwdUBjcy5wdWIucm8+DQoNCiAgICBPbiA3LzIzLzIwIDM6NDkgUE0s
IEFsZXhhbmRlciBKdW5nIHdyb3RlOg0KICAgID4gVGhpcyBjb21taXQgcmVnaXN0ZXJzIHRoZSBy
aW5nIGJ1ZmZlciBpbXBsZW1lbnRhdGlvbiBtaWNyby1saWJyYXJ5DQogICAgPiB3aXRoIFVuaWty
YWZ0IGJ5IGluY2x1ZGluZyBpdCBpbiB0aGUgZ2xvYmFsIGxpYnJhcnkgbGlzdCwgZXhwb3J0cw0K
ICAgID4gdGhlIHJpbmcgYnVmZmVyJ3MgbWFpbiBmdW5jdGlvbnMgYW5kIGluY2x1ZGVzIHRoZSBy
ZWxldmFudCBpbml0aWFsDQogICAgPiBNYWtlZmlsZS51ayBhbmQgQ29uZmlnLnVrIGxpYnJhcnkg
ZmlsZXMuDQogICAgPiANCiAgICA+IFNpZ25lZC1vZmYtYnk6IEFsZXhhbmRlciBKdW5nIDxhbGV4
YW5kZXIuanVuZ0BuZWNsYWIuZXU+DQogICAgPiAtLS0NCiAgICA+ICBsaWIvTWFrZWZpbGUudWsg
ICAgICAgICAgfCAgMSArDQogICAgPiAgbGliL3VrcmluZy9Db25maWcudWsgICAgIHwgMjMgKysr
KysrKysrKysrKysrKysrKysrKysNCiAgICA+ICBsaWIvdWtyaW5nL01ha2VmaWxlLnVrICAgfCAg
NiArKysrKysNCiAgICA+ICBsaWIvdWtyaW5nL2V4cG9ydHN5bXMudWsgfCAxMiArKysrKysrKysr
KysNCiAgICA+ICA0IGZpbGVzIGNoYW5nZWQsIDQyIGluc2VydGlvbnMoKykNCiAgICA+ICBjcmVh
dGUgbW9kZSAxMDA2NDQgbGliL3VrcmluZy9Db25maWcudWsNCiAgICA+ICBjcmVhdGUgbW9kZSAx
MDA2NDQgbGliL3VrcmluZy9NYWtlZmlsZS51aw0KICAgID4gIGNyZWF0ZSBtb2RlIDEwMDY0NCBs
aWIvdWtyaW5nL2V4cG9ydHN5bXMudWsNCiAgICA+IA0KICAgID4gZGlmZiAtLWdpdCBhL2xpYi9N
YWtlZmlsZS51ayBiL2xpYi9NYWtlZmlsZS51aw0KICAgID4gaW5kZXggMzYwZmNkOC4uNGZkMjIy
ZCAxMDA2NDQNCiAgICA+IC0tLSBhL2xpYi9NYWtlZmlsZS51aw0KICAgID4gKysrIGIvbGliL01h
a2VmaWxlLnVrDQogICAgPiBAQCAtMjUsNiArMjUsNyBAQCAkKGV2YWwgJChjYWxsIF9pbXBvcnRf
bGliLCQoQ09ORklHX1VLX0JBU0UpL2xpYi9kZXZmcykpDQogICAgPiAgJChldmFsICQoY2FsbCBf
aW1wb3J0X2xpYiwkKENPTkZJR19VS19CQVNFKS9saWIvOXBmcykpDQogICAgPiAgJChldmFsICQo
Y2FsbCBfaW1wb3J0X2xpYiwkKENPTkZJR19VS19CQVNFKS9saWIvdWtsb2NrKSkNCiAgICA+ICAk
KGV2YWwgJChjYWxsIF9pbXBvcnRfbGliLCQoQ09ORklHX1VLX0JBU0UpL2xpYi91a21waSkpDQog
ICAgPiArJChldmFsICQoY2FsbCBfaW1wb3J0X2xpYiwkKENPTkZJR19VS19CQVNFKS9saWIvdWty
aW5nKSkNCiAgICA+ICAkKGV2YWwgJChjYWxsIF9pbXBvcnRfbGliLCQoQ09ORklHX1VLX0JBU0Up
L2xpYi91a2J1cykpDQogICAgPiAgJChldmFsICQoY2FsbCBfaW1wb3J0X2xpYiwkKENPTkZJR19V
S19CQVNFKS9saWIvdWtzZ2xpc3QpKQ0KICAgID4gICQoZXZhbCAkKGNhbGwgX2ltcG9ydF9saWIs
JChDT05GSUdfVUtfQkFTRSkvbGliL3VrbmV0ZGV2KSkNCiAgICA+IGRpZmYgLS1naXQgYS9saWIv
dWtyaW5nL0NvbmZpZy51ayBiL2xpYi91a3JpbmcvQ29uZmlnLnVrDQogICAgPiBuZXcgZmlsZSBt
b2RlIDEwMDY0NA0KICAgID4gaW5kZXggMDAwMDAwMC4uMjQ4MWM2Mg0KICAgID4gLS0tIC9kZXYv
bnVsbA0KICAgID4gKysrIGIvbGliL3VrcmluZy9Db25maWcudWsNCiAgICA+IEBAIC0wLDAgKzEs
MjMgQEANCiAgICA+ICttZW51Y29uZmlnIExJQlVLUklORw0KICAgID4gKyAgYm9vbCAidWtyaW5n
OiBSaW5nIGJ1ZmZlciBpbnRlcmZhY2UiDQogICAgPiArICBzZWxlY3QgTElCVUtBTExPQw0KICAg
ID4gKyAgc2VsZWN0IExJQlVLTE9DSw0KICAgID4gKyAgZGVmYXVsdCBuDQogICAgPiArICBoZWxw
DQogICAgPiArICAgIFByb3ZpZGUgcmluZyBpbnRlcmZhY2UgZm9yIGhhbmRsaW5nIG9iamVjdCBy
ZWZlcmVuY2VzLg0KICAgID4gKw0KICAgID4gK2lmIExJQlVLUklORw0KICAgID4gKw0KICAgID4g
K2NvbmZpZyBMSUJVS1JJTkdfQ0FDSEVfTElORV9TSVpFDQogICAgPiArICBpbnQgIkNhY2hlIGxp
bmUgc2l6ZSINCiAgICA+ICsgIGRlZmF1bHQgMzINCiAgICA+ICsgIGhlbHANCiAgICA+ICsgICAg
U2l6ZSBpbiBieXRlcyBvZiBhIENQVSBkLWNhY2hlIGxpbmUuDQogICAgPiArDQogICAgPiArY29u
ZmlnIENPTkZJR19MSUJVS1JJTkdfREVCVUdfQlVGUklORw0KICAgID4gKyAgYm9vbCAiRGVidWcg
dGhlIHJpbmcgaW50ZXJmYWNlIg0KICAgID4gKyAgZGVmYXVsdCBuDQogICAgPiArICBoZWxwDQog
ICAgPiArICAgIFdoZW4gZGVidWdnaW5nLCB0aGlzIGxpYnJhcnkgc3RvcmVzIHNvbWUgcGVyLXJp
bmcgc3RhdGlzdGljIGNvdW50ZXJzIGFib3V0IHRoZSBudW1iZXIgb2YgZW5xdWV1ZXMvZGVxdWV1
ZXMuICBUaGVzZSBzdGF0aXN0aWNzIHJlcXVpcmUgYSBtdXRleCB0byBhdm9pZCBjb25jdXJyZW50
IGFjY2Vzc2VzIG9yIGF0b21pYyBvcGVyYXRpb25zLg0KICAgID4gKw0KICAgID4gK2VuZGlmDQog
ICAgPiBkaWZmIC0tZ2l0IGEvbGliL3VrcmluZy9NYWtlZmlsZS51ayBiL2xpYi91a3JpbmcvTWFr
ZWZpbGUudWsNCiAgICA+IG5ldyBmaWxlIG1vZGUgMTAwNjQ0DQogICAgPiBpbmRleCAwMDAwMDAw
Li43ODc0Y2EyDQogICAgPiAtLS0gL2Rldi9udWxsDQogICAgPiArKysgYi9saWIvdWtyaW5nL01h
a2VmaWxlLnVrDQogICAgPiBAQCAtMCwwICsxLDYgQEANCiAgICA+ICskKGV2YWwgJChjYWxsIGFk
ZGxpYl9zLGxpYnVrcmluZywkKENPTkZJR19MSUJVS1JJTkcpKSkNCiAgICA+ICsNCiAgICA+ICtD
SU5DTFVERVMtJChDT05GSUdfTElCVUtSSU5HKSAgICs9IC1JJChMSUJVS1JJTkdfQkFTRSkvaW5j
bHVkZQ0KICAgID4gK0NYWElOQ0xVREVTLSQoQ09ORklHX0xJQlVLUklORykgKz0gLUkkKExJQlVL
UklOR19CQVNFKS9pbmNsdWRlDQogICAgPiArDQogICAgPiArTElCVUtSSU5HX1NSQ1MteSArPSAk
KExJQlVLUklOR19CQVNFKS9yaW5nLmMNCiAgICA+IGRpZmYgLS1naXQgYS9saWIvdWtyaW5nL2V4
cG9ydHN5bXMudWsgYi9saWIvdWtyaW5nL2V4cG9ydHN5bXMudWsNCiAgICA+IG5ldyBmaWxlIG1v
ZGUgMTAwNjQ0DQogICAgPiBpbmRleCAwMDAwMDAwLi4wOThmMjVhDQogICAgPiAtLS0gL2Rldi9u
dWxsDQogICAgPiArKysgYi9saWIvdWtyaW5nL2V4cG9ydHN5bXMudWsNCiAgICA+IEBAIC0wLDAg
KzEsMTIgQEANCiAgICA+ICt1a19yaW5nX2FsbG9jDQogICAgPiArdWtfcmluZ19mcmVlDQogICAg
PiArdWtfcmluZ19lbnF1ZXVlDQogICAgPiArdWtfcmluZ19kZXF1ZXVlX21jDQogICAgPiArdWtf
cmluZ19kZXF1ZXVlX3NjDQogICAgPiArdWtfcmluZ19hZHZhbmNlX3NjDQogICAgPiArdWtfcmlu
Z19wdXRiYWNrX3NjDQogICAgPiArdWtfcmluZ19wZWVrDQogICAgPiArdWtfcmluZ19wZWVrX2Ns
ZWFyX3NjDQogICAgPiArdWtfcmluZ19mdWxsDQogICAgPiArdWtfcmluZ19lbXB0eQ0KICAgID4g
K3VrX3JpbmdfY291bnQNCiAgICA+IA0KDQo=


From minios-devel-bounces@lists.xenproject.org Thu Jul 23 14:55:19 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 14:55:19 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jyccw-0000SR-Ej; Thu, 23 Jul 2020 14:55:18 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=c5bV=BC=gmail.com=dincadaniel97@srs-us1.protection.inumbo.net>)
 id 1jyccv-0000SL-85
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 14:55:17 +0000
X-Inumbo-ID: 84826612-ccf4-11ea-872e-bc764e2007e4
Received: from mail-ej1-x62b.google.com (unknown [2a00:1450:4864:20::62b])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 84826612-ccf4-11ea-872e-bc764e2007e4;
 Thu, 23 Jul 2020 14:55:16 +0000 (UTC)
Received: by mail-ej1-x62b.google.com with SMTP id f12so6688060eja.9
 for <minios-devel@lists.xen.org>; Thu, 23 Jul 2020 07:55:16 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=in-reply-to:to:cc:from:subject:message-id:date:user-agent
 :mime-version:content-language;
 bh=1dTNI2qkz1e6SDZ5s1W0qNioApnxRSeMRzmKiZ2K+Lc=;
 b=c+uDuqcWp/oaOUAJ/6Y5Yedlu7k/PoaCXpZNBCgBpDQA18HujB9i2Cb5T/PhsICyez
 FQsvDfSSBtDBTjx0rU+RuCEpfZ1/ltYZUku05daT+Ya0dgnog55vBQqd0+5I21zvjk90
 KFNDr+aDg3ddcTMpn0LL1ieMlVAdCqQVfarxwitklw8puWdICOYdXWZ+35BbZVX2iFTv
 rsELwGiHJZQPs/6Ry0mBIixdTiMziCrMT3KN5Jnbu94ep7rP6LtdzbPovSp59w677g1v
 hrncyt28bS5eAuKfoM4PS33eVnp0balF+7KCVfZdqAqTZZLvBJzniyJ+gDlEWla8zKtv
 n6Cw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:in-reply-to:to:cc:from:subject:message-id:date
 :user-agent:mime-version:content-language;
 bh=1dTNI2qkz1e6SDZ5s1W0qNioApnxRSeMRzmKiZ2K+Lc=;
 b=Xt1T+1lY/YgpMlvoAHQ1nTkFyLiDOCHO25Stn5/q9vhmi8/FKL6v95qTVKWLXKNNT5
 ILWNpWUJnYaga+R7TNwtkWermmFztMValDG1Ph4yB7gKfxXBZIR214nzShjASkBmLlXt
 U/bORIK/f8LmyN+x3Md84VWQ004cDdlI0nrZgJikRQWKtaf44L6B6/JMaM89AY1MZIUM
 wgBWNztStt1UfSMqSmMcptVzb5Bb7aPzXfWdP5gZMNyVskMKIbJYVhlJT0LnoBkMrI99
 flZTwTK2n7Ayh9IG7E2BicFIBAuz14O95YQQK1lO//FytcKWtTnzN7ZevF1nDobFMXVv
 0nOA==
X-Gm-Message-State: AOAM533kZaekSv4VqBUHkxJODdDQyM9c/ULeQbngbktdGLcN9XxjelDK
 LyZKLUsk7H5G2hVlepgoLno=
X-Google-Smtp-Source: ABdhPJzCzOBBAy748/KTqqsRTeHTNjgE4ritToMLq0TBy8alN1TSBVvS/qGLhqPAOnh1R7X5+vf6JQ==
X-Received: by 2002:a17:907:2170:: with SMTP id
 rl16mr4975236ejb.422.1595516115170; 
 Thu, 23 Jul 2020 07:55:15 -0700 (PDT)
Received: from [192.168.0.102] ([82.77.177.192])
 by smtp.gmail.com with ESMTPSA id h10sm2208720eds.0.2020.07.23.07.55.14
 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
 Thu, 23 Jul 2020 07:55:14 -0700 (PDT)
In-Reply-To: <d8186de8e40bf89f4205d74f3459f33b0227c6e5.1592485170.git.hugo.lefeuvre@neclab.eu>
To: minios-devel@lists.xen.org
From: Daniel Dinca <dincadaniel97@gmail.com>
Subject: [UNIKRAFT PATCH] pci_bus: implement recursive PCI bus enumeration
Message-ID: <518b9cb3-563c-cc74-bae4-f0d5d2a54291@gmail.com>
Date: Thu, 23 Jul 2020 17:55:13 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
Content-Type: multipart/alternative;
 boundary="------------DF27EA23AD05D1E2C4379B2A"
Content-Language: en-US
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: dincadaniel97@gmail.com
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This is a multi-part message in MIME format.
--------------DF27EA23AD05D1E2C4379B2A
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit

Sorry for re-sending this, I added the In-Reply-To field to the mail so 
patchwork will consider this review.

Reviewed-by: Daniel Dinca
<dincadaniel97@gmail.com <mailto:dincadaniel97@gmail.com>>

--------------DF27EA23AD05D1E2C4379B2A
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit

<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <div style="color: rgb(34, 34, 34); font-family: Arial, Helvetica,
      sans-serif; font-size: small; font-style: normal;
      font-variant-ligatures: normal; font-variant-caps: normal;
      font-weight: 400; letter-spacing: normal; orphans: 2; text-align:
      start; text-indent: 0px; text-transform: none; white-space:
      normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width:
      0px; background-color: rgb(255, 255, 255); text-decoration-style:
      initial; text-decoration-color: initial;">Sorry for re-sending
      this, I added the In-Reply-To field to the mail so patchwork will
      consider this review.<br>
    </div>
    <div style="color: rgb(34, 34, 34); font-family: Arial, Helvetica,
      sans-serif; font-size: small; font-style: normal;
      font-variant-ligatures: normal; font-variant-caps: normal;
      font-weight: 400; letter-spacing: normal; orphans: 2; text-align:
      start; text-indent: 0px; text-transform: none; white-space:
      normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width:
      0px; background-color: rgb(255, 255, 255); text-decoration-style:
      initial; text-decoration-color: initial;"><br>
    </div>
    <div style="color: rgb(34, 34, 34); font-family: Arial, Helvetica,
      sans-serif; font-size: small; font-style: normal;
      font-variant-ligatures: normal; font-variant-caps: normal;
      font-weight: 400; letter-spacing: normal; orphans: 2; text-align:
      start; text-indent: 0px; text-transform: none; white-space:
      normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width:
      0px; background-color: rgb(255, 255, 255); text-decoration-style:
      initial; text-decoration-color: initial;">Reviewed-by: Daniel
      Dinca</div>
    <div style="color: rgb(34, 34, 34); font-family: Arial, Helvetica,
      sans-serif; font-size: small; font-style: normal;
      font-variant-ligatures: normal; font-variant-caps: normal;
      font-weight: 400; letter-spacing: normal; orphans: 2; text-align:
      start; text-indent: 0px; text-transform: none; white-space:
      normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width:
      0px; background-color: rgb(255, 255, 255); text-decoration-style:
      initial; text-decoration-color: initial;">&lt;<a
        href="mailto:dincadaniel97@gmail.com" target="_blank"
        style="color: rgb(17, 85, 204);">dincadaniel97@gmail.com</a>&gt;</div>
  </body>
</html>

--------------DF27EA23AD05D1E2C4379B2A--


From minios-devel-bounces@lists.xenproject.org Thu Jul 23 14:59:30 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 14:59:30 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jycgz-0000Yj-QM; Thu, 23 Jul 2020 14:59:29 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=c5bV=BC=gmail.com=dincadaniel97@srs-us1.protection.inumbo.net>)
 id 1jycgy-0000Ye-E9
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 14:59:28 +0000
X-Inumbo-ID: 1a8efdd2-ccf5-11ea-872e-bc764e2007e4
Received: from mail-ed1-x52b.google.com (unknown [2a00:1450:4864:20::52b])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 1a8efdd2-ccf5-11ea-872e-bc764e2007e4;
 Thu, 23 Jul 2020 14:59:27 +0000 (UTC)
Received: by mail-ed1-x52b.google.com with SMTP id d16so4715393edz.12
 for <minios-devel@lists.xen.org>; Thu, 23 Jul 2020 07:59:27 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=in-reply-to:to:cc:from:subject:message-id:date:user-agent
 :mime-version:content-language;
 bh=mEbOilCImQ6TmuhsgMlxlfNHmX/PnAeiHODdLKLq++I=;
 b=fUmnb/pxhOPaPWc1dU9WKQMwZqpHdZiiQa67KfDTVcpaFJWlvWvFCwuQxcnZjZGc7P
 lRFrP+gC822xDw5CdNjGSyBPU6M7Kbuvf6J1jXeCRW8+8AVlS3e5luAxfg2r6OOEIB2q
 Pu1E6EOza4+OmIfJAqDFPUZ7nM3tKTg/i63FUtq3HOl/VlSsWxi6XMranBGRw+PqOy3r
 sKEsi1TjLiLZ4QD53VNo/o7QKNurADPwW/IlSxqfh7O9MPBA1v9u+P+WJQKWH+g07U7e
 kTWpuCjpFTIiOZvac3KsI9srwkapoupz6SNS2x1zXDjVND8bTsJtl25XMPiNz7qql88O
 YBCg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:in-reply-to:to:cc:from:subject:message-id:date
 :user-agent:mime-version:content-language;
 bh=mEbOilCImQ6TmuhsgMlxlfNHmX/PnAeiHODdLKLq++I=;
 b=MGlivqyavUJ7mkfBeqJXEVwZTvBXIBjhK2Imo7cQ2XXye3LZOUwd1We7y+Z7eMC6Qb
 U2E7HLzTwBLPvEh4mtENPQHhW1mun5sSPmD+z2jIP/SbYPfYKzr6gCIKRwUwUAXGXsWD
 f5WyqcwIHwWe8PQZUcAJHGcJ7R3R1rfcN38UMCV8oWzUCl8agEGxv/ugoeqo/GkaWfLT
 8Kk+ybJw3oyJRTlGMbSgMIUCgpkHS8unjI9ucm/guN/NCkAR6OnhMEwDzpemV+NT4zzn
 T9QKppTM+bYm5VrYyvEK9kYlVlhhuhjIo3hxf94FlF44SUhEbDRvn2HxrS5SxFvrw78q
 kGbA==
X-Gm-Message-State: AOAM532dbsnYe9C0crc1puMVNAokHkC5Lsgf5h78+D6O4/g7BdajU0/y
 HK1VMw4miTVtoR7mPEA6cfI=
X-Google-Smtp-Source: ABdhPJxAnykdsK7Iv8GUVVQNFaPqMPsnvWfwNiTHuR2A9ZAi4EhuDioQbDvJTzNcSdpADFDB/Ry0CA==
X-Received: by 2002:aa7:cc98:: with SMTP id p24mr1206689edt.333.1595516366951; 
 Thu, 23 Jul 2020 07:59:26 -0700 (PDT)
Received: from [192.168.0.102] ([82.77.177.192])
 by smtp.gmail.com with ESMTPSA id m13sm2254586ejc.1.2020.07.23.07.59.26
 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
 Thu, 23 Jul 2020 07:59:26 -0700 (PDT)
In-Reply-To: <687d2dd8ab9ccd876329ef337a7ff33e0e89d40f.1592488273.git.hugo.lefeuvre@neclab.eu>
To: minios-devel@lists.xen.org
From: Daniel Dinca <dincadaniel97@gmail.com>
Subject: [UNIKRAFT PATCH] lib/ukdebug: expose trace buffer size to the
 menuconfig
Message-ID: <78cdd4f1-9905-517a-d2c5-201fc80fc76a@gmail.com>
Date: Thu, 23 Jul 2020 17:59:25 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
Content-Type: multipart/alternative;
 boundary="------------32DAC5844C7EBFE0EB3ED813"
Content-Language: en-US
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: dincadaniel97@gmail.com
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This is a multi-part message in MIME format.
--------------32DAC5844C7EBFE0EB3ED813
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit

Reviewed-by: Daniel Dinca
<dincadaniel97@gmail.com <mailto:dincadaniel97@gmail.com>>

--------------32DAC5844C7EBFE0EB3ED813
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit

<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <div style="color: rgb(34, 34, 34); font-family: Arial, Helvetica,
      sans-serif; font-size: small; font-style: normal;
      font-variant-ligatures: normal; font-variant-caps: normal;
      font-weight: 400; letter-spacing: normal; orphans: 2; text-align:
      start; text-indent: 0px; text-transform: none; white-space:
      normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width:
      0px; background-color: rgb(255, 255, 255); text-decoration-style:
      initial; text-decoration-color: initial;">Reviewed-by: Daniel
      Dinca</div>
    <div style="color: rgb(34, 34, 34); font-family: Arial, Helvetica,
      sans-serif; font-size: small; font-style: normal;
      font-variant-ligatures: normal; font-variant-caps: normal;
      font-weight: 400; letter-spacing: normal; orphans: 2; text-align:
      start; text-indent: 0px; text-transform: none; white-space:
      normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width:
      0px; background-color: rgb(255, 255, 255); text-decoration-style:
      initial; text-decoration-color: initial;">&lt;<a
        href="mailto:dincadaniel97@gmail.com" target="_blank"
        style="color: rgb(17, 85, 204);">dincadaniel97@gmail.com</a>&gt;</div>
  </body>
</html>

--------------32DAC5844C7EBFE0EB3ED813--


From minios-devel-bounces@lists.xenproject.org Thu Jul 23 15:32:13 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 15:32:13 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jydCd-0004I3-Hp; Thu, 23 Jul 2020 15:32:11 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=35hh=BC=neclab.eu=simon.kuenzer@srs-us1.protection.inumbo.net>)
 id 1jydCc-0004Hy-Ce
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 15:32:10 +0000
X-Inumbo-ID: aaeb9fbc-ccf9-11ea-873a-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id aaeb9fbc-ccf9-11ea-873a-bc764e2007e4;
 Thu, 23 Jul 2020 15:32:08 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 14E57F200C;
 Thu, 23 Jul 2020 17:32:07 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id Ee7R0N-1gB1a; Thu, 23 Jul 2020 17:32:06 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id DBA83F2002;
 Thu, 23 Jul 2020 17:32:00 +0200 (CEST)
Received: from puck.office.hd (192.168.24.91) by puck.office.hd
 (192.168.24.91) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 23 Jul
 2020 17:32:00 +0200
Received: from puck.office.hd ([192.168.126.12]) by puck.office.hd
 ([192.168.126.12]) with mapi id 15.01.1979.003; Thu, 23 Jul 2020 17:32:00
 +0200
From: Simon Kuenzer <simon.kuenzer@neclab.eu>
To: Alexander Jung <a.jung@lancs.ac.uk>, "minios-devel@lists.xen.org"
 <minios-devel@lists.xen.org>
Subject: Re: [UNIKRAFT PATCH] include: Introduce uk/preemmpt.h
Thread-Topic: [UNIKRAFT PATCH] include: Introduce uk/preemmpt.h
Thread-Index: AQHWYNUXZ8HvjjeOy0+lnWgeq/4imqkVSyYA
Date: Thu, 23 Jul 2020 15:32:00 +0000
Message-ID: <971DEF62-5AC0-4C8C-98EF-037C80D12DEE@neclab.eu>
References: <20200723093847.65020-1-a.jung@lancs.ac.uk>
In-Reply-To: <20200723093847.65020-1-a.jung@lancs.ac.uk>
Accept-Language: en-GB, gl-ES, en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
user-agent: Microsoft-MacOutlook/10.10.18.200713
x-originating-ip: [192.168.24.96]
Content-Type: text/plain; charset="utf-8"
Content-ID: <22B760DF5316EC41A2D243D2C8F300C1@office.hd>
Content-Transfer-Encoding: base64
MIME-Version: 1.0
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <Felipe.Huici@neclab.eu>,
 Alexander Jung <Alexander.Jung@neclab.eu>, Costin Lupu <costin.lupu@cs.pub.ro>,
 Sharan Santhanam <Sharan.Santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

SGV5IENvc3RpbiwgaGV5IEFsZXhhbmRlciwNCg0KYSBxdWVzdGlvbiBmcm9tIG15IHNpZGUgYXMg
Y2xhcmlmaWNhdGlvbi4gSSB1bmRlcnN0YW5kIHRoaXMgaXMga2luZCBvZiBhbiBhZG9wdGVkIGNv
bmNlcHQgZnJvbSBMaW51eC4gSG93ZXZlciwgaXMgaXQgaW50ZW5kZWQgdGhhdCBpbnRlcnJ1cHRz
IGRvIG5vdCBjb3VudCBhcyBwcmVlbXB0aW9uPyBXaGVuIGRvIEkgdXNlIHVrX3ByZWVtcHRfZGlz
YWJsZSgpIGFuZCB3aGVuIGxjcHVfaXJxZl9zYXZlKCk/DQpXaGVuIHNjaGVkdWxpbmcgaXMgdGhl
cmUsIGRvZXMgdGhpcyBnZW5lcmFsIGhlYWRlciBnZXQgYSBkZXBlbmRlbmN5IHRvIHVrc2NoZWQ/
IEluIHN1Y2ggYSBjYXNlLCBzaG91bGRuJ3QgdGhpcyBoZWFkZXIgZ28gdG8gdWtzY2hlZCBhbmQg
aW4gdWtyaW5nIHdlIGluY2x1ZGUgaXQgYXMgc29vbiBhcyB1a3NjaGVkIGlzIHNlbGVjdGVkPw0K
DQpUaGFua3MsDQoNClNpbW9uDQoNCu+7v09uIDIzLjA3LjIwLCAxMTozOSwgIkFsZXhhbmRlciBK
dW5nIiA8YS5qdW5nQGxhbmNzLmFjLnVrPiB3cm90ZToNCg0KICAgIFRoaXMgY29tbWl0IGFkZHMg
YW4gYWRkaXRpb25hbCBoZWFkZXIgd2l0aCB0d28gbmV3IG1ldGhvZHM6DQogICAgDQogICAgIC0g
cHJlZW1wdF9kaXNhYmxlKCkNCiAgICAgLSBwcmVlbXB0X2VuYWJsZSgpDQogICAgDQogICAgVGhl
c2UgbWV0aG9kcyBlbmFibGUgYW5kIGRpc2FibGUgcHJlZW1wdGlvbiBieSBjYWxsaW5nIGEgbWVt
b3J5DQogICAgYmFycmllciBvbmx5LiAgVGhlaXIgbmFtZXMgYXJlIGRlcml2ZWQgZnJvbSB0aGUg
TGludXggS2VybmVsWzFdLg0KICAgIA0KICAgIFdoaWxzdCBjdXJyZW50bHkgdW5pbXBsZW1lbnRl
ZCwgcHJlLWVtcHRpdmUgc2NoZWR1bGluZyByZXF1aXJlcw0KICAgIGFkZGl0aW9uYWwgbm90YXJp
emF0aW9uIHdoZW4gY2FsbGVkLiAgVGhpcyBtZWFucyB0aGF0IGZ1dHVyZQ0KICAgIGVuaGFuY2Vt
ZW50cyB0byBVbmlrcmFmdCdzIHByZS1lbXB0aXZlIHNjaGVkdWxlciB3aWxsIG5lZWQgdG8NCiAg
ICBtb2RpZnkgdGhlc2UgbWV0aG9kcyB0byBpbmNyZWFzZSBhIGNvdW50ZXIgd2l0aGluIHRoZSB0
aHJlYWQNCiAgICB0byBpbmRpY2F0ZSB3aGV0aGVyIHRoZSB0aHJlYWQgaXMgcHJlLWVtcHRpYmxl
IG9yIG5vdC4NCiAgICANCiAgICBbMF06IGh0dHBzOi8vZWxpeGlyLmJvb3RsaW4uY29tL2xpbnV4
L2xhdGVzdC9zb3VyY2UvaW5jbHVkZS9saW51eC9wcmVlbXB0LmgjTDE2OQ0KICAgIA0KICAgIFNp
Z25lZC1vZmYtYnk6IEFsZXhhbmRlciBKdW5nIDxhbGV4YW5kZXIuanVuZ0BuZWNsYWIuZXU+DQog
ICAgLS0tDQogICAgIGluY2x1ZGUvdWsvcHJlZW1wdC5oIHwgNDAgKysrKysrKysrKysrKysrKysr
KysrKysrKysrKysrKysrKysrKysrKw0KICAgICAxIGZpbGUgY2hhbmdlZCwgNDAgaW5zZXJ0aW9u
cygrKQ0KICAgICBjcmVhdGUgbW9kZSAxMDA2NDQgaW5jbHVkZS91ay9wcmVlbXB0LmgNCiAgICAN
CiAgICBkaWZmIC0tZ2l0IGEvaW5jbHVkZS91ay9wcmVlbXB0LmggYi9pbmNsdWRlL3VrL3ByZWVt
cHQuaA0KICAgIG5ldyBmaWxlIG1vZGUgMTAwNjQ0DQogICAgaW5kZXggMDAwMDAwMC4uZDQ1NjIz
ZA0KICAgIC0tLSAvZGV2L251bGwNCiAgICArKysgYi9pbmNsdWRlL3VrL3ByZWVtcHQuaA0KICAg
IEBAIC0wLDAgKzEsNDAgQEANCiAgICArLyogU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IEJTRC0z
LUNsYXVzZSAqLw0KICAgICsvKg0KICAgICsgKiBBdXRob3JzOiBBbGV4YW5kZXIgSnVuZyA8YWxl
eGFuZGVyLmp1bmdAbmVjbGFiLmV1Pg0KICAgICsgKg0KICAgICsgKiBDb3B5cmlnaHQgKGMpIDIw
MjAsIE5FQyBMYWJvcmF0b3JpZXMgRXVyb3BlIEdtYkgsIE5FQyBDb3Jwb3JhdGlvbi4NCiAgICAr
ICogICAgICAgICAgICAgICAgICAgICBBbGwgcmlnaHRzIHJlc2VydmVkLg0KICAgICsgKg0KICAg
ICsgKiBSZWRpc3RyaWJ1dGlvbiBhbmQgdXNlIGluIHNvdXJjZSBhbmQgYmluYXJ5IGZvcm1zLCB3
aXRoIG9yIHdpdGhvdXQNCiAgICArICogbW9kaWZpY2F0aW9uLCBhcmUgcGVybWl0dGVkIHByb3Zp
ZGVkIHRoYXQgdGhlIGZvbGxvd2luZyBjb25kaXRpb25zDQogICAgKyAqIGFyZSBtZXQ6DQogICAg
KyAqDQogICAgKyAqIDEuIFJlZGlzdHJpYnV0aW9ucyBvZiBzb3VyY2UgY29kZSBtdXN0IHJldGFp
biB0aGUgYWJvdmUgY29weXJpZ2h0DQogICAgKyAqICAgIG5vdGljZSwgdGhpcyBsaXN0IG9mIGNv
bmRpdGlvbnMgYW5kIHRoZSBmb2xsb3dpbmcgZGlzY2xhaW1lci4NCiAgICArICogMi4gUmVkaXN0
cmlidXRpb25zIGluIGJpbmFyeSBmb3JtIG11c3QgcmVwcm9kdWNlIHRoZSBhYm92ZSBjb3B5cmln
aHQNCiAgICArICogICAgbm90aWNlLCB0aGlzIGxpc3Qgb2YgY29uZGl0aW9ucyBhbmQgdGhlIGZv
bGxvd2luZyBkaXNjbGFpbWVyIGluIHRoZQ0KICAgICsgKiAgICBkb2N1bWVudGF0aW9uIGFuZC9v
ciBvdGhlciBtYXRlcmlhbHMgcHJvdmlkZWQgd2l0aCB0aGUgZGlzdHJpYnV0aW9uLg0KICAgICsg
KiAzLiBOZWl0aGVyIHRoZSBuYW1lIG9mIHRoZSBjb3B5cmlnaHQgaG9sZGVyIG5vciB0aGUgbmFt
ZXMgb2YgaXRzDQogICAgKyAqICAgIGNvbnRyaWJ1dG9ycyBtYXkgYmUgdXNlZCB0byBlbmRvcnNl
IG9yIHByb21vdGUgcHJvZHVjdHMgZGVyaXZlZCBmcm9tDQogICAgKyAqICAgIHRoaXMgc29mdHdh
cmUgd2l0aG91dCBzcGVjaWZpYyBwcmlvciB3cml0dGVuIHBlcm1pc3Npb24uDQogICAgKyAqDQog
ICAgKyAqIFRISVMgU09GVFdBUkUgSVMgUFJPVklERUQgQlkgVEhFIENPUFlSSUdIVCBIT0xERVJT
IEFORCBDT05UUklCVVRPUlMgIkFTIElTIg0KICAgICsgKiBBTkQgQU5ZIEVYUFJFU1MgT1IgSU1Q
TElFRCBXQVJSQU5USUVTLCBJTkNMVURJTkcsIEJVVCBOT1QgTElNSVRFRCBUTywgVEhFDQogICAg
KyAqIElNUExJRUQgV0FSUkFOVElFUyBPRiBNRVJDSEFOVEFCSUxJVFkgQU5EIEZJVE5FU1MgRk9S
IEEgUEFSVElDVUxBUiBQVVJQT1NFDQogICAgKyAqIEFSRSBESVNDTEFJTUVELiBJTiBOTyBFVkVO
VCBTSEFMTCBUSEUgQ09QWVJJR0hUIEhPTERFUiBPUiBDT05UUklCVVRPUlMgQkUNCiAgICArICog
TElBQkxFIEZPUiBBTlkgRElSRUNULCBJTkRJUkVDVCwgSU5DSURFTlRBTCwgU1BFQ0lBTCwgRVhF
TVBMQVJZLCBPUg0KICAgICsgKiBDT05TRVFVRU5USUFMIERBTUFHRVMgKElOQ0xVRElORywgQlVU
IE5PVCBMSU1JVEVEIFRPLCBQUk9DVVJFTUVOVCBPRg0KICAgICsgKiBTVUJTVElUVVRFIEdPT0RT
IE9SIFNFUlZJQ0VTOyBMT1NTIE9GIFVTRSwgREFUQSwgT1IgUFJPRklUUzsgT1IgQlVTSU5FU1MN
CiAgICArICogSU5URVJSVVBUSU9OKSBIT1dFVkVSIENBVVNFRCBBTkQgT04gQU5ZIFRIRU9SWSBP
RiBMSUFCSUxJVFksIFdIRVRIRVIgSU4NCiAgICArICogQ09OVFJBQ1QsIFNUUklDVCBMSUFCSUxJ
VFksIE9SIFRPUlQgKElOQ0xVRElORyBORUdMSUdFTkNFIE9SIE9USEVSV0lTRSkNCiAgICArICog
QVJJU0lORyBJTiBBTlkgV0FZIE9VVCBPRiBUSEUgVVNFIE9GIFRISVMgU09GVFdBUkUsIEVWRU4g
SUYgQURWSVNFRCBPRiBUSEUNCiAgICArICogUE9TU0lCSUxJVFkgT0YgU1VDSCBEQU1BR0UuDQog
ICAgKyAqLw0KICAgICsNCiAgICArI2lmbmRlZiBfX1VLX1BSRUVNUFRfSF9fDQogICAgKyNkZWZp
bmUgX19VS19QUkVFTVBUX0hfXw0KICAgICsNCiAgICArI2RlZmluZSBwcmVlbXB0X2Rpc2FibGUo
KQliYXJyaWVyKCkNCiAgICArI2RlZmluZSBwcmVlbXB0X2VuYWJsZSgpCWJhcnJpZXIoKQ0KICAg
ICsNCiAgICArI2VuZGlmIC8qIF9fVUtfUFJFRU1QVF9IX18gKi8NCiAgICAtLSANCiAgICAyLjEx
LjANCiAgICANCiAgICANCg0K


From minios-devel-bounces@lists.xenproject.org Thu Jul 23 15:59:35 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 23 Jul 2020 15:59:35 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jydd6-0007kw-9T; Thu, 23 Jul 2020 15:59:32 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=u2GH=BC=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1jydd5-0007kr-45
 for minios-devel@lists.xen.org; Thu, 23 Jul 2020 15:59:31 +0000
X-Inumbo-ID: 7c86c6f2-ccfd-11ea-873e-bc764e2007e4
Received: from mx.upb.ro (unknown [141.85.13.200])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 7c86c6f2-ccfd-11ea-873e-bc764e2007e4;
 Thu, 23 Jul 2020 15:59:28 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 2E98AB561D38;
 Thu, 23 Jul 2020 18:59:27 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id KJwkQyYt5es9; Thu, 23 Jul 2020 18:59:25 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id EEF94B561D39;
 Thu, 23 Jul 2020 18:59:24 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id x1UGwth2dC4q; Thu, 23 Jul 2020 18:59:24 +0300 (EEST)
Received: from [192.168.1.35] (5-12-134-63.residential.rdsnet.ro [5.12.134.63])
 by mx.upb.ro (Postfix) with ESMTPSA id 7E68EB561D38;
 Thu, 23 Jul 2020 18:59:24 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH] include: Introduce uk/preemmpt.h
To: Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <a.jung@lancs.ac.uk>,
 "minios-devel@lists.xen.org" <minios-devel@lists.xen.org>
References: <20200723093847.65020-1-a.jung@lancs.ac.uk>
 <971DEF62-5AC0-4C8C-98EF-037C80D12DEE@neclab.eu>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <e121e463-0956-96f0-6bf4-932465ae0f02@cs.pub.ro>
Date: Thu, 23 Jul 2020 18:59:24 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <971DEF62-5AC0-4C8C-98EF-037C80D12DEE@neclab.eu>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <Felipe.Huici@neclab.eu>,
 Alexander Jung <Alexander.Jung@neclab.eu>,
 Sharan Santhanam <Sharan.Santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

On 7/23/20 6:32 PM, Simon Kuenzer wrote:
> Hey Costin, hey Alexander,
> 
> a question from my side as clarification. I understand this is kind
> of an adopted concept from Linux.

Well, it's actually about critical sections which is an old systems
concept. [1]

> However, is it intended that interrupts do not count as preemption?
> When do I use uk_preempt_disable() and when lcpu_irqf_save()?
Disabling interrupts does disable preemption. However, here we need to
disable only preemption in order to keep the current thread running on
the current CPU. But the advantage here is we can also continue to
handle interrupts.

If for example the current thread is the ring consumer and the ring is
filled in interrupt context then we must leave the interrupts enabled.

> When scheduling is there, does this general header get a dependency
> to uksched?

That's right. More precisely, when preemptive scheduling is there.

> In such a case, shouldn't this header go to uksched and in ukring we
> include it as soon as uksched is selected?

Well, not necessarily. In the ring implementation you just need to
define critical sections. The ring implementation doesn't care whether
there is a scheduler around or not. It just needs to make the calls that
helps it define the critical sections. That's why I don't think it's
necessary to directly link the ring with the scheduler.

[1]
https://en.wikipedia.org/wiki/Critical_section#Kernel-level_critical_sections

Cheers,
Costin


From minios-devel-bounces@lists.xenproject.org Fri Jul 24 09:11:56 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 24 Jul 2020 09:11:56 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jytk9-00069Z-1w; Fri, 24 Jul 2020 09:11:53 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=gjyE=BD=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jytk7-00069U-ES
 for minios-devel@lists.xen.org; Fri, 24 Jul 2020 09:11:51 +0000
X-Inumbo-ID: b35e3e86-cd8d-11ea-a38e-12813bfff9fa
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id b35e3e86-cd8d-11ea-a38e-12813bfff9fa;
 Fri, 24 Jul 2020 09:11:48 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id CE5BD103ACD;
 Fri, 24 Jul 2020 11:11:46 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id XbRI98ns6_Ja; Fri, 24 Jul 2020 11:11:46 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id A06AE10187E
 for <minios-devel@lists.xen.org>; Fri, 24 Jul 2020 11:11:46 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Fri, 24 Jul
 2020 11:11:46 +0200
Message-ID: <1595581897.11746.4.camel@neclab.eu>
Subject: Re: [UNIKRAFT PATCH v4 1/2] lib/uknetdev: Add ipaddr, netmask &
 gwaddr as arg
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Sharan Santhanam <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
In-Reply-To: <20200722132713.23989-2-sharan.santhanam@neclab.eu>
References: <20200722132713.23989-1-sharan.santhanam@neclab.eu>
 <20200722132713.23989-2-sharan.santhanam@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
Date: Fri, 24 Jul 2020 11:11:37 +0200
MIME-Version: 1.0
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: titania.office.hd (192.168.24.89) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Sharan,

thanks a lot for this patch.

As discuss off-list, we will do a minor change during upstreaming: the
namespace for ipv4_* arguments should be netdev and not net.

Otherwise fine to me.

regards,
Hugo

Reviewed-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>

On Wed, 2020-07-22 at 15:27 +0200, Sharan Santhanam wrote:
> The patch adds ip address, netmask and the gateway address as library
> argument. The parameters are list of argument delimited by a space.
> The library user can forward the argument using the following command
> line:
> net.ipv4_addr, net.ipv4_subnet_mask, net.ipv4_gw_addr
> 
> Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
> ---
> Â lib/uknetdev/Config.ukÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |Â Â 1 +
> Â lib/uknetdev/Makefile.ukÂ Â Â Â Â Â Â Â Â Â Â Â Â Â |Â Â 1 +
> Â lib/uknetdev/include/uk/netdev_core.h |Â Â 9 ++++
> Â lib/uknetdev/netdev.cÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â | 75
> +++++++++++++++++++++++++++
> Â 4 files changed, 86 insertions(+)
> 
> diff --git a/lib/uknetdev/Config.uk b/lib/uknetdev/Config.uk
> index 618e8e67..186dd462 100644
> --- a/lib/uknetdev/Config.uk
> +++ b/lib/uknetdev/Config.uk
> @@ -4,6 +4,7 @@ menuconfig LIBUKNETDEV
> Â 	select LIBNOLIBC if !HAVE_LIBC
> Â 	select LIBUKDEBUG
> Â 	select LIBUKALLOC
> +	imply LIBUKLIBPARAM
> Â 
> Â if LIBUKNETDEV
> Â 	config LIBUKNETDEV_MAXNBQUEUES
> diff --git a/lib/uknetdev/Makefile.uk b/lib/uknetdev/Makefile.uk
> index ca08b254..abdcd4bc 100644
> --- a/lib/uknetdev/Makefile.uk
> +++ b/lib/uknetdev/Makefile.uk
> @@ -1,4 +1,5 @@
> Â $(eval $(call addlib_s,libuknetdev,$(CONFIG_LIBUKNETDEV)))
> +$(eval $(call addlib_paramprefix,libuknetdev,net))

net -> netdev

> Â 
> Â CINCLUDES-$(CONFIG_LIBUKNETDEV)		+=
> -I$(LIBUKNETDEV_BASE)/include
> Â CXXINCLUDES-$(CONFIG_LIBUKNETDEV)	+=
> -I$(LIBUKNETDEV_BASE)/include
> diff --git a/lib/uknetdev/include/uk/netdev_core.h
> b/lib/uknetdev/include/uk/netdev_core.h
> index dba719fc..1fe5f2a5 100644
> --- a/lib/uknetdev/include/uk/netdev_core.h
> +++ b/lib/uknetdev/include/uk/netdev_core.h
> @@ -373,6 +373,12 @@ struct uk_netdev_data {
> Â 	const charÂ Â Â Â Â Â Â Â Â Â Â *drv_name;
> Â };
> Â 
> +struct uk_netdev_einfo {
> +	const char *ipv4_addr;
> +	const char *ipv4_net_mask;
> +	const char *ipv4_gw_addr;
> +};
> +
> Â /**
> Â  * NETDEV
> Â  * A structure used to interact with a network device.
> @@ -400,6 +406,9 @@ struct uk_netdev {
> Â 	struct
> uk_netdev_tx_queueÂ Â Â *_tx_queue[CONFIG_LIBUKNETDEV_MAXNBQUEUES];
> Â 
> Â 	UK_TAILQ_ENTRY(struct uk_netdev) _list;
> +
> +	/** Netdevice address configuration */
> +	struct uk_netdev_einfo *_einfo;
> Â };
> Â 
> Â #ifdef __cplusplus
> diff --git a/lib/uknetdev/netdev.c b/lib/uknetdev/netdev.c
> index 151e0897..096973a3 100644
> --- a/lib/uknetdev/netdev.c
> +++ b/lib/uknetdev/netdev.c
> @@ -38,10 +38,62 @@
> Â #include <string.h>
> Â #include <uk/netdev.h>
> Â #include <uk/print.h>
> +#include <uk/libparam.h>
> Â 
> Â struct uk_netdev_list uk_netdev_list =
> Â 	UK_TAILQ_HEAD_INITIALIZER(uk_netdev_list);
> Â static uint16_t netdev_count;
> +/**
> + * TODO: Define Network argument format when multiple driver device
> need to
> + * coexist. For example like:
> + * Driver Name:IP Address:Net Mask
> + */
> +static char *ipv4_addr;
> +static char *ipv4_subnet_mask;
> +static char *ipv4_gw_addr;
> +
> +UK_LIB_PARAM_STR(ipv4_addr);
> +UK_LIB_PARAM_STR(ipv4_subnet_mask);
> +UK_LIB_PARAM_STR(ipv4_gw_addr);
> +
> +static const char *_parse_ipv4_addr(void)
> +{
> +	/** Remember the reference to the ip address for successive
> calls*/
> +	static char *ip_addr;
> +
> +	if (ip_addr)
> +		return strtok_r(NULL, " ", &ip_addr);
> +	else if (ipv4_addr)
> +		return strtok_r(ipv4_addr, " ", &ip_addr);
> +
> +	return NULL;
> +}
> +
> +static const char *_parse_ipv4_net_mask(void)
> +{
> +	/** Remember the reference to the netmask for successive
> calls*/
> +	static char *net_mask;
> +
> +	if (net_mask)
> +		return strtok_r(NULL, " ", &net_mask);
> +	else if (ipv4_subnet_mask)
> +		return strtok_r(ipv4_subnet_mask, " ", &net_mask);
> +
> +	return NULL;
> +}
> +
> +static const char *_parse_ipv4_gw_addr(void)
> +{
> +	/** Remember the reference to the gateway address for
> successive calls*/
> +	static char *gw;
> +
> +	if (gw)
> +		return strtok_r(NULL, " ", &gw);
> +	else if (ipv4_gw_addr)
> +		return strtok_r(ipv4_gw_addr, " ", &gw);
> +
> +	return NULL;
> +}
> Â 
> Â static struct uk_netdev_data *_alloc_data(struct uk_alloc *a,
> Â 					Â Â uint16_t netdev_id,
> @@ -64,6 +116,25 @@ static struct uk_netdev_data *_alloc_data(struct
> uk_alloc *a,
> Â 	return data;
> Â }
> Â 
> +static struct uk_netdev_einfo *_alloc_einfo(struct uk_alloc *a)
> +{
> +	struct uk_netdev_einfo *_einfo = NULL;
> +
> +	if (ipv4_addr || ipv4_subnet_mask || ipv4_gw_addr) {
> +		_einfo = uk_zalloc(a, sizeof(*_einfo));
> +		if (!_einfo) {
> +			uk_pr_warn("Failed to allocate memory for
> netdev config\n");
> +			return NULL;
> +		}
> +
> +		_einfo->ipv4_addr = _parse_ipv4_addr();
> +		_einfo->ipv4_net_mask = _parse_ipv4_net_mask();
> +		_einfo->ipv4_gw_addr = _parse_ipv4_gw_addr();
> +	}
> +
> +	return _einfo;
> +}
> +
> Â int uk_netdev_drv_register(struct uk_netdev *dev, struct uk_alloc
> *a,
> Â 			Â Â Â const char *drv_name)
> Â {
> @@ -91,6 +162,10 @@ int uk_netdev_drv_register(struct uk_netdev *dev,
> struct uk_alloc *a,
> Â 	if (!dev->_data)
> Â 		return -ENOMEM;
> Â 
> +	dev->_einfo = _alloc_einfo(a);
> +	if (!dev->_einfo)
> +		return -ENOMEM;
> +
> Â 	UK_TAILQ_INSERT_TAIL(&uk_netdev_list, dev, _list);
> Â 	uk_pr_info("Registered netdev%"PRIu16": %p (%s)\n",
> Â 		Â Â Â netdev_count, dev, drv_name);


From minios-devel-bounces@lists.xenproject.org Fri Jul 24 09:14:38 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 24 Jul 2020 09:14:38 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jytmn-0006KH-MQ; Fri, 24 Jul 2020 09:14:37 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=gjyE=BD=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jytmm-0006KC-UK
 for minios-devel@lists.xen.org; Fri, 24 Jul 2020 09:14:36 +0000
X-Inumbo-ID: 170193f2-cd8e-11ea-87e7-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 170193f2-cd8e-11ea-87e7-bc764e2007e4;
 Fri, 24 Jul 2020 09:14:35 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 1095FF2016;
 Fri, 24 Jul 2020 11:14:34 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id XoU2PJVappSD; Fri, 24 Jul 2020 11:14:33 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id DCEDCF2005
 for <minios-devel@lists.xen.org>; Fri, 24 Jul 2020 11:14:31 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Fri, 24 Jul
 2020 11:14:31 +0200
Message-ID: <1595582070.11746.5.camel@neclab.eu>
Subject: Re: [UNIKRAFT PATCH v4 2/2] lib/uknetdev: Get the ipaddr, gw_addr
 and subnet
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Sharan Santhanam <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
Date: Fri, 24 Jul 2020 11:14:30 +0200
In-Reply-To: <20200722132713.23989-3-sharan.santhanam@neclab.eu>
References: <20200722132713.23989-1-sharan.santhanam@neclab.eu>
 <20200722132713.23989-3-sharan.santhanam@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Sharan,

Looks good to me.

regards,
Hugo

Reviewed-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>

On Wed, 2020-07-22 at 15:27 +0200, Sharan Santhanam wrote:
> The user of uknetdev can pass the ipaddr, gw_addr and subnet as a
> library argument. The library argument can be retrieved from the
> network stack using uk_netdev_einfo_get function. The library
> arguments are retrieved only if the driver does not support the
> uk_netdev_einfo_get callback.
> 
> Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
> ---
> Â lib/uknetdev/netdev.c | 32 +++++++++++++++++++++++++++-----
> Â 1 file changed, 27 insertions(+), 5 deletions(-)
> 
> diff --git a/lib/uknetdev/netdev.c b/lib/uknetdev/netdev.c
> index 096973a3..74be618a 100644
> --- a/lib/uknetdev/netdev.c
> +++ b/lib/uknetdev/netdev.c
> @@ -236,17 +236,39 @@ void uk_netdev_info_get(struct uk_netdev *dev,
> Â 				Â Â Â Â Â Â dev_info->max_tx_queues);
> Â }
> Â 
> +static const void *_netdev_einfo_get(struct uk_netdev *dev,
> +				enum uk_netdev_einfo_type einfo)
> +{
> +	switch (einfo) {
> +	case UK_NETDEV_IPV4_ADDR_STR:
> +		if (dev->_einfo->ipv4_addr)
> +			uk_pr_debug("ip_addr: %s\n", dev->_einfo-
> >ipv4_addr);
> +		return dev->_einfo->ipv4_addr;
> +	case UK_NETDEV_IPV4_MASK_STR:
> +		if (dev->_einfo->ipv4_net_mask)
> +			uk_pr_debug("netmask: %s\n", dev->_einfo-
> >ipv4_net_mask);
> +		return dev->_einfo->ipv4_net_mask;
> +	case UK_NETDEV_IPV4_GW_STR:
> +		if (dev->_einfo->ipv4_gw_addr)
> +			uk_pr_debug("Gateway: %s\n", dev->_einfo-
> >ipv4_gw_addr);
> +		return dev->_einfo->ipv4_gw_addr;
> +	default:
> +		uk_pr_warn("Option %d not yet supported\n", einfo);
> +	}
> +	return NULL;
> +}
> +
> Â const void *uk_netdev_einfo_get(struct uk_netdev *dev,
> Â 				enum uk_netdev_einfo_type einfo)
> Â {
> Â 	UK_ASSERT(dev);
> Â 	UK_ASSERT(dev->ops);
> Â 
> -	if (!dev->ops->einfo_get) {
> -		/* driver does not provide any extra configuration
> */
> -		return NULL;
> -	}
> -	return dev->ops->einfo_get(dev, einfo);
> +	if (dev->_einfo)
> +		return _netdev_einfo_get(dev, einfo);
> +	else if (dev->ops->einfo_get)
> +		return dev->ops->einfo_get(dev, einfo);
> +	return NULL;
> Â }
> Â 
> Â int uk_netdev_rxq_info_get(struct uk_netdev *dev, uint16_t queue_id,


From minios-devel-bounces@lists.xenproject.org Fri Jul 24 09:20:12 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 24 Jul 2020 09:20:12 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jytsA-000756-4H; Fri, 24 Jul 2020 09:20:10 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=gjyE=BD=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jyts9-000751-Gj
 for minios-devel@lists.xen.org; Fri, 24 Jul 2020 09:20:09 +0000
X-Inumbo-ID: dd75df2a-cd8e-11ea-87e7-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id dd75df2a-cd8e-11ea-87e7-bc764e2007e4;
 Fri, 24 Jul 2020 09:20:07 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 97600F2016;
 Fri, 24 Jul 2020 11:20:06 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id U9DfUcAsNYzl; Fri, 24 Jul 2020 11:20:06 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 6AB92F2005
 for <minios-devel@lists.xen.org>; Fri, 24 Jul 2020 11:20:04 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Fri, 24 Jul
 2020 11:20:04 +0200
Message-ID: <1595582403.11746.7.camel@neclab.eu>
Subject: Re: [UNIKRAFT/LIBLWIP PATCH v3 3/3] lib/lwip: Enable poll only receive
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Sharan Santhanam <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
Date: Fri, 24 Jul 2020 11:20:03 +0200
In-Reply-To: <1595345566-14752-4-git-send-email-sharan.santhanam@neclab.eu>
References: <1595345566-14752-1-git-send-email-sharan.santhanam@neclab.eu>
 <1595345566-14752-4-git-send-email-sharan.santhanam@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Sharan,

looks good to me, thanks!

Reviewed-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>

On Tue, 2020-07-21 at 17:32 +0200, Sharan Santhanam wrote:
> The uknetdev library provides the way to check if interrupts are
> supported on a uk_netdev. If the device does not support interrupt
> the lwip stack would create a thread to poll the receive queue for
> packets.
> 
> Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
> ---
> Â uknetdev.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++----
> ------------
> Â 1 file changed, 68 insertions(+), 23 deletions(-)
> 
> diff --git a/uknetdev.c b/uknetdev.c
> index fe679e9..e6c9807 100644
> --- a/uknetdev.c
> +++ b/uknetdev.c
> @@ -64,6 +64,11 @@
> Â 
> Â struct lwip_netdev_data {
> Â 	uint32_t features;
> +#ifdef CONFIG_HAVE_SCHED
> +	struct uk_thread *poll_thread; /* Thread per device */
> +	char *_name; /* Thread name */
> +	struct uk_sched *sched; /* Scheduler information */
> +#endif /* CONFIG_HAVE_SCHED */
> Â };
> Â 
> Â /*
> @@ -325,44 +330,84 @@ void uknetdev_poll_all(void)
> Â 
> Â #else /* CONFIG_LWIP_NOTHREADS */
> Â 
> +static void _poll_netif(void *arg)
> +{
> +	struct netif *nf = (struct netif *) arg;
> +
> +	while (1) {
> +		uknetdev_poll(nf);
> +		uk_sched_yield();
> +	}
> +}
> +
> Â static void uknetdev_updown(struct netif *nf)
> Â {
> Â 	struct uk_netdev *dev;
> Â 	int ret;
> +	struct lwip_netdev_dataÂ Â *lwip_data;
> Â 
> Â 	UK_ASSERT(nf);
> Â 	dev = netif_to_uknetdev(nf);
> Â 	UK_ASSERT(dev);
> +	lwip_data = (struct lwip_netdev_data *)dev->scratch_pad;
> Â 
> Â 	/* Enable and disable interrupts according to netif's
> up/down status */
> +
> Â 	if (nf->flags & NETIF_FLAG_UP) {
> -		ret = uk_netdev_rxq_intr_enable(dev, 0);
> -		if (ret < 0) {
> -			LWIP_DEBUGF(NETIF_DEBUG,
> -				Â Â Â Â ("%s: %c%c%u: Failed to enable
> rx interrrupt mode on netdev %u\n",
> -				Â Â Â Â Â __func__, nf->name[0], nf-
> >name[1],
> -				Â Â Â Â Â nf->num,
> uk_netdev_id_get(dev)));
> +		if (uk_netdev_rxintr_supported(lwip_data->features)) 
> {
> +			ret = uk_netdev_rxq_intr_enable(dev, 0);
> +			if (ret < 0) {
> +				LWIP_DEBUGF(NETIF_DEBUG,
> +						("%s: %c%c%u: Failed
> to enable rx interrupt mode on netdev %u\n",
> +						Â __func__, nf-
> >name[0],
> +						Â nf->name[1],
> +						Â nf->num,
> +						Â uk_netdev_id_get(de
> v)));
> +			} else {
> +				LWIP_DEBUGF(NETIF_DEBUG,
> +					("%s: %c%c%u: Enabled rx
> interrupt mode on netdev %u\n",
> +						Â __func__, nf-
> >name[0],
> +						Â nf->name[1],
> +						Â nf->num,
> +						Â uk_netdev_id_get(de
> v)));
> +			}
> +
> +			if (ret == 1) {
> +				/*
> +				Â * uk_netdev_rxq_intr_enable() told
> us that we
> +				Â * need to flush the receive queue
> before
> +				Â * interrupts are enabled. For this
> purpose
> +				Â * we do an initial poll.
> +				Â */
> +				uknetdev_poll(nf);
> +			}
> Â 		} else {
> +#ifdef CONFIG_HAVE_SCHED
> Â 			LWIP_DEBUGF(NETIF_DEBUG,
> -				Â Â Â Â ("%s: %c%c%u: Enabled rx
> interrupt mode on netdev %u\n",
> -				Â Â Â Â Â __func__, nf->name[0], nf-
> >name[1],
> -				Â Â Â Â Â nf->num,
> uk_netdev_id_get(dev)));
> -		}
> -
> -		if (ret == 1) {
> -			/*
> -			Â * uk_netdev_rxq_intr_enable() told us that
> we need to
> -			Â * flush the receieve queue before
> interrupts are
> -			Â * enabled. For this purpose we do an
> initial poll.
> -			Â */
> -			uknetdev_poll(nf);
> +					("%s: Poll receive
> enabled\n",
> +					Â __func__));
> +			/* Create a thread */
> +			lwip_data->sched = uk_sched_get_default();
> +			UK_ASSERT(lwip_data->sched);
> +			lwip_data->poll_thread =
> +				uk_sched_thread_create(lwip_data-
> >sched, NULL,
> +						Â Â Â Â Â Â Â NULL,
> _poll_netif, nf);
> +#else /* CONFIG_HAVE_SCHED */
> +			uk_pr_warn("The netdevice does not support
> interrupt. Ensure the netdevice is polled to receive packets");
> +#endif /* CONFIG_HAVE_SCHED */
> Â 		}
> Â 	} else {
> -		uk_netdev_rxq_intr_disable(dev, 0);
> -		LWIP_DEBUGF(NETIF_DEBUG,
> -			Â Â Â Â ("%s: %c%c%u: Disabled rx interrupts on
> netdev %u\n",
> -			Â Â Â Â Â __func__, nf->name[0], nf->name[1],
> -			Â Â Â Â Â nf->num, uk_netdev_id_get(dev)));
> +		/**
> +		Â * TODO:
> +		Â * Cleanup the thread on stopping the network
> interface.
> +		Â */
> +		if (uk_netdev_rxintr_supported(lwip_data->features)) 
> {
> +			uk_netdev_rxq_intr_disable(dev, 0);
> +			LWIP_DEBUGF(NETIF_DEBUG,
> +					("%s: %c%c%u: Disabled rx
> interrupts on netdev %u\n",
> +					Â __func__, nf->name[0], nf-
> >name[1],
> +					Â nf->num,
> uk_netdev_id_get(dev)));
> +		}
> Â 
> Â 	}
> Â }


From minios-devel-bounces@lists.xenproject.org Fri Jul 24 09:22:38 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 24 Jul 2020 09:22:38 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jytuY-0007Ef-EH; Fri, 24 Jul 2020 09:22:38 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=gjyE=BD=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jytuX-0007Ea-PX
 for minios-devel@lists.xen.org; Fri, 24 Jul 2020 09:22:37 +0000
X-Inumbo-ID: 35a67664-cd8f-11ea-a38e-12813bfff9fa
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 35a67664-cd8f-11ea-a38e-12813bfff9fa;
 Fri, 24 Jul 2020 09:22:35 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 0E9AD103928;
 Fri, 24 Jul 2020 11:22:35 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 5-Wx1ptYqtSY; Fri, 24 Jul 2020 11:22:34 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id DF75510187E
 for <minios-devel@lists.xen.org>; Fri, 24 Jul 2020 11:22:34 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Fri, 24 Jul
 2020 11:22:34 +0200
Message-ID: <1595582553.11746.10.camel@neclab.eu>
Subject: Re: [UNIKRAFT/LIBLWIP PATCH v3 2/3] lib/lwip: Fetch features
 supported on the netdev
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Sharan Santhanam <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
Date: Fri, 24 Jul 2020 11:22:33 +0200
In-Reply-To: <1595345566-14752-3-git-send-email-sharan.santhanam@neclab.eu>
References: <1595345566-14752-1-git-send-email-sharan.santhanam@neclab.eu>
 <1595345566-14752-3-git-send-email-sharan.santhanam@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: titania.office.hd (192.168.24.89) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Sharan,

As discussed off-list, we will do a minor modification while
upstreaming: UK_CTASSERT should be used instead of UK_ASSERT, see
comment below.

otherwise, looks good to me.

Reviewed-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>

On Tue, 2020-07-21 at 17:32 +0200, Sharan Santhanam wrote:
> Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
> ---
> Â uknetdev.c | 21 +++++++++++++++++++++
> Â 1 file changed, 21 insertions(+)
> 
> diff --git a/uknetdev.c b/uknetdev.c
> index 7047352..fe679e9 100644
> --- a/uknetdev.c
> +++ b/uknetdev.c
> @@ -62,6 +62,10 @@
> Â #define UKNETDEV_NETIF_NAME0 'e'
> Â #define UKNETDEV_NETIF_NAME1 'n'
> Â 
> +struct lwip_netdev_data {
> +	uint32_t features;
> +};
> +
> Â /*
> Â  * Global headroom settings for buffer allocations used on receive
> Â  * and transmit. We are taking the maximum of all uknetdev devices
> as
> @@ -372,6 +376,7 @@ err_t uknetdev_init(struct netif *nf)
> Â 	struct uk_netdev_rxqueue_conf rxq_conf;
> Â 	struct uk_netdev_txqueue_conf txq_conf;
> Â 	struct uk_netdev_info info;
> +	struct lwip_netdev_data *lwip_data;
> Â 	const struct uk_hwaddr *hwaddr;
> Â 	unsigned int i;
> Â 	int ret;
> @@ -379,6 +384,21 @@ err_t uknetdev_init(struct netif *nf)
> Â 	UK_ASSERT(nf);
> Â 	dev = netif_to_uknetdev(nf);
> Â 	UK_ASSERT(dev);
> +#if CONFIG_UK_NETDEV_SCRATCH_SIZE < CONFIG_LWIP_UKNETDEV_SCRATCHÂ 
> +/**
> + * CONFIG_UK_NETDEV_SCRATCH_SIZE is configured as the max of all
> scratch pad
> + * requirements by the Makefile.uk macro uknetdev_scratch_mem. This
> value
> + * should atleast be greater CONFIG_LWIP_UKNETDEV_SCRATCH
> + */
> +#error "Insufficient Scratch memory"
> +#endif
> +
> +	/**
> +	Â * Make sure the CONFIG_LWIP_UKNETDEV_SCRATCH is still
> sufficient to
> +	Â * store lwip_data.
> +	Â */
> +	UK_ASSERT(sizeof(*lwip_data) <=
> CONFIG_LWIP_UKNETDEV_SCRATCH);

this can be done at compile time, we should useÂ UK_CTASSERT.

> +	lwip_data = (struct lwip_netdev_data *)dev->scratch_pad;
> Â 
> Â 	LWIP_ASSERT("uknetdev needs an input callback (netif_input
> or tcpip_input)",
> Â 		Â Â Â Â nf->input != NULL);
> @@ -411,6 +431,7 @@ err_t uknetdev_init(struct netif *nf)
> Â 	uk_netdev_info_get(dev, &info);
> Â 	if (!info.max_rx_queues || !info.max_tx_queues)
> Â 		return ERR_IF;
> +	lwip_data->features = info.features;
> Â 
> Â 	/*
> Â 	Â * Update our global (rx|tx)_headroom setting that we use
> for


From minios-devel-bounces@lists.xenproject.org Fri Jul 24 09:23:19 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 24 Jul 2020 09:23:19 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1jytvC-0007Hg-HC; Fri, 24 Jul 2020 09:23:18 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=gjyE=BD=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1jytvB-0007Hb-Lj
 for minios-devel@lists.xen.org; Fri, 24 Jul 2020 09:23:17 +0000
X-Inumbo-ID: 4ddaacbe-cd8f-11ea-a38e-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 4ddaacbe-cd8f-11ea-a38e-12813bfff9fa;
 Fri, 24 Jul 2020 09:23:16 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 8ABDBF2016;
 Fri, 24 Jul 2020 11:23:15 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 6DVBvk7ACtpV; Fri, 24 Jul 2020 11:23:15 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 52E6CF2005
 for <minios-devel@lists.xen.org>; Fri, 24 Jul 2020 11:23:13 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Fri, 24 Jul
 2020 11:23:12 +0200
Message-ID: <1595582592.11746.11.camel@neclab.eu>
Subject: Re: [UNIKRAFT/LIBLWIP PATCH v3 1/3] lib/lwip: Reserve per netdev
 space for lwip
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Sharan Santhanam <sharan.santhanam@neclab.eu>, <minios-devel@lists.xen.org>
Date: Fri, 24 Jul 2020 11:23:12 +0200
In-Reply-To: <1595345566-14752-2-git-send-email-sharan.santhanam@neclab.eu>
References: <1595345566-14752-1-git-send-email-sharan.santhanam@neclab.eu>
 <1595345566-14752-2-git-send-email-sharan.santhanam@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Sharan,

looks good, thanks!

Reviewed-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>

On Tue, 2020-07-21 at 17:32 +0200, Sharan Santhanam wrote:
> Reserves space for per-network-device (uknetdev). This will be later
> used to store network stack specific specific information in the
> netdevice.
> Reserving this memory allows us to store the memory continuously in
> the
> netdev instead of additional dereferences.
> 
> Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
> ---
> Â Config.ukÂ Â Â | 9 +++++++++
> Â Makefile.uk | 1 +
> Â 2 files changed, 10 insertions(+)
> 
> diff --git a/Config.uk b/Config.uk
> index aaaaae0..e2eacb5 100644
> --- a/Config.uk
> +++ b/Config.uk
> @@ -22,6 +22,15 @@ config LWIP_UKNETDEV
> Â 		In case threaded mode is selected and the underlying
> device
> Â 		driver does not support receive interrupts the
> network
> Â 		interfaces have to be polled manually
> (uknetdev_poll()).
> +
> +config LWIP_UKNETDEV_SCRATCH
> +	int
> +	default 32
> +	help
> +		The network stack reserves space in the uknetdev
> device for its
> +		use. Please do not change this value and in case
> change this
> +		value please make sure it is sufficient enough to
> hold the
> +		lwip_netdev_data data structure.
> Â endmenu
> Â 
> Â config LWIP_AUTOIFACE
> diff --git a/Makefile.uk b/Makefile.uk
> index d3c6c9c..99005a9 100644
> --- a/Makefile.uk
> +++ b/Makefile.uk
> @@ -62,6 +62,7 @@ LIBLWIP_COMMON_INCLUDES-y +=
> -I$(LIBLWIP_BASE)/musl-imported/include
> Â LIBLWIP_COMMON_INCLUDES-y += -I$(LIBLWIP_EXTRACTED)/include
> Â CINCLUDES-$(CONFIG_LIBLWIP)Â Â Â += $(LIBLWIP_COMMON_INCLUDES-y)
> Â CXXINCLUDES-$(CONFIG_LIBLWIP) += $(LIBLWIP_COMMON_INCLUDES-y)
> +$(eval $(call uknetdev_scratch_mem,$(CONFIG_LWIP_UKNETDEV_SCRATCH)))
> Â 
> Â ####################################################################
> ############
> Â # Library flags


From minios-devel-bounces@lists.xenproject.org Mon Jul 27 13:22:58 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Mon, 27 Jul 2020 13:22:58 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k035j-0001QR-3T; Mon, 27 Jul 2020 13:22:55 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dtGT=BG=gmail.com=alicesuiu17@srs-us1.protection.inumbo.net>)
 id 1k035i-0001QM-9Z
 for minios-devel@lists.xen.org; Mon, 27 Jul 2020 13:22:54 +0000
X-Inumbo-ID: 4643be9e-d00c-11ea-8abe-bc764e2007e4
Received: from mail-vk1-xa43.google.com (unknown [2607:f8b0:4864:20::a43])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4643be9e-d00c-11ea-8abe-bc764e2007e4;
 Mon, 27 Jul 2020 13:22:52 +0000 (UTC)
Received: by mail-vk1-xa43.google.com with SMTP id 66so3743393vka.13
 for <minios-devel@lists.xen.org>; Mon, 27 Jul 2020 06:22:52 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:references:in-reply-to:from:date:message-id:subject:to
 :cc; bh=nHjGoSr1HDlABB/0hIzP2XN8D0e7N9rXKH48n3pDCVk=;
 b=RvxgXCQsNplDL08HIfEWVao/dJeaTwZ9MVA7kWBEbFEi4YxNAqxtWW4FuHJ6xFlDGZ
 lBcNN3ZK6sg0neL0jUkNcBwsHqkZgemFNnMjFTiTTKzbhsIRi/2H4w/JyXXih+1Qk8PJ
 22+QcZ3HYJ4pPp6gC9CLNtS9wUFAYuGklDwJvFLeoa3fFe9HHnsvpONX/xjBdB2/GWNU
 lWNlZtkWkhHl6InTEVrWAOQLQo3+LHIZfilu1WA9DkDAaFaNn3z2B412bQbEFklen1gn
 u0tTaiRgfOOPsCFtgbRET5oHW+UCChxWd+QCFNm3DRAmcegLD0mNhDxrX6K7yxAY37/d
 0+Uw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:references:in-reply-to:from:date
 :message-id:subject:to:cc;
 bh=nHjGoSr1HDlABB/0hIzP2XN8D0e7N9rXKH48n3pDCVk=;
 b=hoTJBTYJr9wMhpy0oGenNPk5vxa//uq3iM4B4UitHplx2L/jAhh0hnOnT4J+wGFNoh
 pSoeafS9N+KPApAZtR+h3fhLcpSDV4/8MB89ItQOw+cwSMDcebKMG3QaGISI1Re+mnSs
 0qhx5mqUsojwhiadIyFMCY4pMuX0JvMPWhCHZ6eYhOOr7peqlzAYEhkPO6FX/Yw2T4TE
 fQqaGuiS32oa2OHE71Bv+Qe6nbtoFCp27jDrwJgQzZMhPo+1ErKQzftxVvK96StGpbaD
 meSnxjJ6Fw0PqJvuj9EoX+xn3EIaqG7+Kb6wjqXUBlpjf8ZbtLW48vfF3B2tcGeZ4XkV
 /4Dw==
X-Gm-Message-State: AOAM5309JMgHPmSV2cOZKKbDy6gxvz4AI6NXXfYGTLRRgC2p+aCX3lD2
 lz0/6YYVpxTN1nlTumEKYxaSAzpjEsyT/oO6Rr8=
X-Google-Smtp-Source: ABdhPJyK7GJfBHqG22Q1I6rLqhOHHdCLufIOOVQeG9SrsPOLSnqLdhp2o9/NKC60i89EFVjUfMWqslLYHW++MTXh0sw=
X-Received: by 2002:a1f:32cf:: with SMTP id y198mr16419251vky.64.1595856172170; 
 Mon, 27 Jul 2020 06:22:52 -0700 (PDT)
MIME-Version: 1.0
References: <20200504233506.7573-1-vlad_andrei.badoiu@upb.ro>
 <20200504233506.7573-2-vlad_andrei.badoiu@upb.ro>
In-Reply-To: <20200504233506.7573-2-vlad_andrei.badoiu@upb.ro>
From: Alice Suiu <alicesuiu17@gmail.com>
Date: Mon, 27 Jul 2020 16:22:40 +0300
Message-ID: <CAD2TrnA5o7tzhuBryQgWOJAmRD-4_csfvg0VoAbjAD8mop7wzg@mail.gmail.com>
Subject: Re: [UNIKRAFT PATCH v5 1/3] lib/uksp: Introduce uksp library
To: Vlad-Andrei Badoiu <vlad_andrei.badoiu@upb.ro>
Content-Type: multipart/alternative; boundary="00000000000041433605ab6c3826"
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: =?UTF-8?B?VmxhZC1BbmRyZWkgQsSCRE9JVSAoNzg2OTIp?=
 <vlad_andrei.badoiu@stud.acs.upb.ro>, Simon Kuenzer <simon.kuenzer@neclab.eu>,
 minios-devel@lists.xen.org
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

--00000000000041433605ab6c3826
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Reviewed-by: Alice Suiu
<alicesuiu17@gmail.com <dincadaniel97@gmail.com>>

=C3=8En mar., 5 mai 2020 la 02:35, Vlad-Andrei Badoiu <vlad_andrei.badoiu@u=
pb.ro>
a scris:

> From: Vlad-Andrei B=C4=82DOIU (78692) <vlad_andrei.badoiu@stud.acs.upb.ro=
>
>
> This library provides the necessary functionalities for the stack
> protector.
>
> A make clean is required when toggling the stack smashing protection
> option.
>
> Signed-off-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@stud.acs.upb.ro>
> Signed-off-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@upb.ro>
> ---
>  lib/Makefile.uk          |  1 +
>  lib/uksp/Config.uk       | 46 +++++++++++++++++++++++++++++++++
>  lib/uksp/Makefile.uk     |  9 +++++++
>  lib/uksp/exportsyms.uk   |  2 ++
>  lib/uksp/include/uk/sp.h | 56 ++++++++++++++++++++++++++++++++++++++++
>  lib/uksp/ssp.c           | 52 +++++++++++++++++++++++++++++++++++++
>  6 files changed, 166 insertions(+)
>  create mode 100644 lib/uksp/Config.uk
>  create mode 100644 lib/uksp/Makefile.uk
>  create mode 100644 lib/uksp/exportsyms.uk
>  create mode 100644 lib/uksp/include/uk/sp.h
>  create mode 100644 lib/uksp/ssp.c
>
> diff --git a/lib/Makefile.uk b/lib/Makefile.uk
> index aa7e7302..c02a3c50 100644
> --- a/lib/Makefile.uk
> +++ b/lib/Makefile.uk
> @@ -34,3 +34,4 @@ $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uktime)=
)
>  $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukmmap))
>  $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukblkdev))
>  $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/posix-process))
> +$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uksp))
> diff --git a/lib/uksp/Config.uk b/lib/uksp/Config.uk
> new file mode 100644
> index 00000000..0881ddec
> --- /dev/null
> +++ b/lib/uksp/Config.uk
> @@ -0,0 +1,46 @@
> +config LIBUKSP
> +       bool "uksp: Stack protector"
> +       select HAVE_STACKPROTECTOR
> +       default n
> +
> +if LIBUKSP
> +choice
> +       prompt "Stack protector level"
> +       default STACKPROTECTOR_REGULAR
> +       help
> +         Set the stack protector level
> +
> +config STACKPROTECTOR_REGULAR
> +       bool "Regular"
> +       help
> +               Regular stack protector, use -fstack-protector.
> +
> +config STACKPROTECTOR_STRONG
> +       bool "Strong"
> +       help
> +               Strong stack protector, use -fstack-protector-strong.
> +
> +config STACKPROTECTOR_ALL
> +       bool "All"
> +       help
> +               Protect all functions, use -fstack-protector-all.
> +endchoice
> +
> +choice
> +       prompt "Canary Value"
> +       default LIBUKSP_VALUE_USECONSTANT
> +
> +config LIBUKSP_VALUE_USECONSTANT
> +       bool "Compiled-in constant"
> +
> +config LIBUKSP_VALUE_RANDOM
> +       bool "Random variable"
> +       select LIBUKSWRAND
> +endchoice
> +
> +config LIBUKSP_VALUE_CONSTANT
> +       int "Canary value"
> +       depends on LIBUKSP_VALUE_USECONSTANT
> +       default 42
> +
> +endif
> diff --git a/lib/uksp/Makefile.uk b/lib/uksp/Makefile.uk
> new file mode 100644
> index 00000000..4e591231
> --- /dev/null
> +++ b/lib/uksp/Makefile.uk
> @@ -0,0 +1,9 @@
> +$(eval $(call addlib_s,libuksp,$(CONFIG_LIBUKSP)))
> +
> +CINCLUDES-y +=3D -I$(LIBUKSP_BASE)/include
> +
> +LIBUKSP_SRCS-y +=3D $(LIBUKSP_BASE)/ssp.c
> +
> +COMPFLAGS-$(CONFIG_STACKPROTECTOR_REGULAR)     +=3D -fstack-protector
> -mstack-protector-guard=3Dglobal
> +COMPFLAGS-$(CONFIG_STACKPROTECTOR_STRONG)      +=3D
> -fstack-protector-strong -mstack-protector-guard=3Dglobal
> +COMPFLAGS-$(CONFIG_STACKPROTECTOR_ALL)         +=3D -fstack-protector-al=
l
> -mstack-protector-guard=3Dglobal
> diff --git a/lib/uksp/exportsyms.uk b/lib/uksp/exportsyms.uk
> new file mode 100644
> index 00000000..fbc319e7
> --- /dev/null
> +++ b/lib/uksp/exportsyms.uk
> @@ -0,0 +1,2 @@
> +__stack_chk_fail
> +__stack_chk_guard
> diff --git a/lib/uksp/include/uk/sp.h b/lib/uksp/include/uk/sp.h
> new file mode 100644
> index 00000000..f1da724d
> --- /dev/null
> +++ b/lib/uksp/include/uk/sp.h
> @@ -0,0 +1,56 @@
> +/* SPDX-License-Identifier: BSD-3-Clause */
> +/*
> + * Authors: Vlad-Andrei Badoiu <vlad_andrei.badoiu@stud.acs.upb.ro>
> + *
> + * Copyright (c) 2019, University Politehnica of Bucharest. All rights
> reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + *
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in th=
e
> + *    documentation and/or other materials provided with the distributio=
n.
> + * 3. Neither the name of the copyright holder nor the names of its
> + *    contributors may be used to endorse or promote products derived fr=
om
> + *    this software without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> "AS IS"
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
> THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
> PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTOR=
S
> BE
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
> BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER =
IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS=
E)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED O=
F
> THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#ifndef __UK_STACKPROTECTOR_H__
> +#define __UK_STACKPROTECTOR_H__
> +
> +#include <uk/swrand.h>
> +#include <uk/config.h>
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +extern const unsigned long __stack_chk_guard;
> +
> +#ifdef CONFIG_LIBUKSP_VALUE_RANDOM
> +#define UKSP_INIT_CANARY() (*(DECONST(unsigned long *,
> &__stack_chk_guard)) \
> +               =3D uk_swrand_randr())
> +#else
> +#define UKSP_INIT_CANARY()
> +#endif
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +#endif /* __UK_STACKPROTECTOR_H__ */
> diff --git a/lib/uksp/ssp.c b/lib/uksp/ssp.c
> new file mode 100644
> index 00000000..d0d10114
> --- /dev/null
> +++ b/lib/uksp/ssp.c
> @@ -0,0 +1,52 @@
> +/* SPDX-License-Identifier: BSD-3-Clause */
> +/*
> + * Authors: Badoiu Vlad-Andrei <vlad_andrei.badoiu@stud.acs.upb.ro>
> + *
> + * Copyright (c) 2019, University Politehnica of Bucharest. All rights
> reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + *
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in th=
e
> + *    documentation and/or other materials provided with the distributio=
n.
> + * 3. Neither the name of the copyright holder nor the names of its
> + *    contributors may be used to endorse or promote products derived fr=
om
> + *    this software without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> "AS IS"
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
> THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
> PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTOR=
S
> BE
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
> BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER =
IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS=
E)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED O=
F
> THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#include <uk/assert.h>
> +#include <uk/swrand.h>
> +#include <uk/config.h>
> +#include <uk/ctors.h>
> +#include <uk/thread.h>
> +
> +#ifdef CONFIG_LIBUKSP_VALUE_USECONSTANT
> +const unsigned long __stack_chk_guard =3D CONFIG_LIBUKSP_VALUE_CONSTANT;
> +#else
> +const unsigned long __stack_chk_guard =3D 0xDEADBEEF;
> +#endif
> +
> +__attribute__((noreturn))
> +void __stack_chk_fail(void)
> +{
> +       unsigned long sp;
> +
> +       sp =3D ukarch_read_sp() & STACK_MASK_TOP;
> +       UK_CRASH("Stack smashing detected. SP %p\n", (void *) sp);
> +}
> --
> 2.20.1
>
>
>

--00000000000041433605ab6c3826
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div style=3D"color:rgb(34,34,34);font-family:Arial,Helvet=
ica,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:nor=
mal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-ali=
gn:start;text-indent:0px;text-transform:none;white-space:normal;word-spacin=
g:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-=
decoration-color:initial">Reviewed-by: Alice Suiu<br></div>
    <div style=3D"color:rgb(34,34,34);font-family:Arial,Helvetica,sans-seri=
f;font-size:small;font-style:normal;font-variant-ligatures:normal;font-vari=
ant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text=
-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;backgro=
und-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-co=
lor:initial">&lt;<a href=3D"mailto:dincadaniel97@gmail.com" style=3D"color:=
rgb(17,85,204)" target=3D"_blank">alicesuiu17@gmail.com</a>&gt;</div></div>=
<br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">=C3=8E=
n mar., 5 mai 2020 la 02:35, Vlad-Andrei Badoiu &lt;<a href=3D"mailto:vlad_=
andrei.badoiu@upb.ro" target=3D"_blank">vlad_andrei.badoiu@upb.ro</a>&gt; a=
 scris:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px =
0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">From: Vl=
ad-Andrei B=C4=82DOIU (78692) &lt;<a href=3D"mailto:vlad_andrei.badoiu@stud=
.acs.upb.ro" target=3D"_blank">vlad_andrei.badoiu@stud.acs.upb.ro</a>&gt;<b=
r>
<br>
This library provides the necessary functionalities for the stack<br>
protector.<br>
<br>
A make clean is required when toggling the stack smashing protection<br>
option.<br>
<br>
Signed-off-by: Vlad-Andrei Badoiu &lt;<a href=3D"mailto:vlad_andrei.badoiu@=
stud.acs.upb.ro" target=3D"_blank">vlad_andrei.badoiu@stud.acs.upb.ro</a>&g=
t;<br>
Signed-off-by: Vlad-Andrei Badoiu &lt;<a href=3D"mailto:vlad_andrei.badoiu@=
upb.ro" target=3D"_blank">vlad_andrei.badoiu@upb.ro</a>&gt;<br>
---<br>
=C2=A0lib/Makefile.uk=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 1 +<br>
=C2=A0lib/uksp/Config.uk=C2=A0 =C2=A0 =C2=A0 =C2=A0| 46 +++++++++++++++++++=
++++++++++++++<br>
=C2=A0lib/uksp/Makefile.uk=C2=A0 =C2=A0 =C2=A0|=C2=A0 9 +++++++<br>
=C2=A0lib/uksp/<a href=3D"http://exportsyms.uk" rel=3D"noreferrer" target=
=3D"_blank">exportsyms.uk</a>=C2=A0 =C2=A0|=C2=A0 2 ++<br>
=C2=A0lib/uksp/include/uk/sp.h | 56 +++++++++++++++++++++++++++++++++++++++=
+<br>
=C2=A0lib/uksp/ssp.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| 52 +++++++++=
++++++++++++++++++++++++++++<br>
=C2=A06 files changed, 166 insertions(+)<br>
=C2=A0create mode 100644 lib/uksp/Config.uk<br>
=C2=A0create mode 100644 lib/uksp/Makefile.uk<br>
=C2=A0create mode 100644 lib/uksp/<a href=3D"http://exportsyms.uk" rel=3D"n=
oreferrer" target=3D"_blank">exportsyms.uk</a><br>
=C2=A0create mode 100644 lib/uksp/include/uk/sp.h<br>
=C2=A0create mode 100644 lib/uksp/ssp.c<br>
<br>
diff --git a/lib/Makefile.uk b/lib/Makefile.uk<br>
index aa7e7302..c02a3c50 100644<br>
--- a/lib/Makefile.uk<br>
+++ b/lib/Makefile.uk<br>
@@ -34,3 +34,4 @@ $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uktime))<=
br>
=C2=A0$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukmmap))<br>
=C2=A0$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukblkdev))<br>
=C2=A0$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/posix-process))<br>
+$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uksp))<br>
diff --git a/lib/uksp/Config.uk b/lib/uksp/Config.uk<br>
new file mode 100644<br>
index 00000000..0881ddec<br>
--- /dev/null<br>
+++ b/lib/uksp/Config.uk<br>
@@ -0,0 +1,46 @@<br>
+config LIBUKSP<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0bool &quot;uksp: Stack protector&quot;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0select HAVE_STACKPROTECTOR<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0default n<br>
+<br>
+if LIBUKSP<br>
+choice<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0prompt &quot;Stack protector level&quot;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0default STACKPROTECTOR_REGULAR<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0help<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Set the stack protector level<br>
+<br>
+config STACKPROTECTOR_REGULAR<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0bool &quot;Regular&quot;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0help<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Regular stack prote=
ctor, use -fstack-protector.<br>
+<br>
+config STACKPROTECTOR_STRONG<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0bool &quot;Strong&quot;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0help<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Strong stack protec=
tor, use -fstack-protector-strong.<br>
+<br>
+config STACKPROTECTOR_ALL<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0bool &quot;All&quot;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0help<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Protect all functio=
ns, use -fstack-protector-all.<br>
+endchoice<br>
+<br>
+choice<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0prompt &quot;Canary Value&quot;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0default LIBUKSP_VALUE_USECONSTANT<br>
+<br>
+config LIBUKSP_VALUE_USECONSTANT<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0bool &quot;Compiled-in constant&quot;<br>
+<br>
+config LIBUKSP_VALUE_RANDOM<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0bool &quot;Random variable&quot;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0select LIBUKSWRAND<br>
+endchoice<br>
+<br>
+config LIBUKSP_VALUE_CONSTANT<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0int &quot;Canary value&quot;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0depends on LIBUKSP_VALUE_USECONSTANT<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0default 42<br>
+<br>
+endif<br>
diff --git a/lib/uksp/Makefile.uk b/lib/uksp/Makefile.uk<br>
new file mode 100644<br>
index 00000000..4e591231<br>
--- /dev/null<br>
+++ b/lib/uksp/Makefile.uk<br>
@@ -0,0 +1,9 @@<br>
+$(eval $(call addlib_s,libuksp,$(CONFIG_LIBUKSP)))<br>
+<br>
+CINCLUDES-y +=3D -I$(LIBUKSP_BASE)/include<br>
+<br>
+LIBUKSP_SRCS-y +=3D $(LIBUKSP_BASE)/ssp.c<br>
+<br>
+COMPFLAGS-$(CONFIG_STACKPROTECTOR_REGULAR)=C2=A0 =C2=A0 =C2=A0+=3D -fstack=
-protector -mstack-protector-guard=3Dglobal<br>
+COMPFLAGS-$(CONFIG_STACKPROTECTOR_STRONG)=C2=A0 =C2=A0 =C2=A0 +=3D -fstack=
-protector-strong -mstack-protector-guard=3Dglobal<br>
+COMPFLAGS-$(CONFIG_STACKPROTECTOR_ALL)=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0+=
=3D -fstack-protector-all -mstack-protector-guard=3Dglobal<br>
diff --git a/lib/uksp/<a href=3D"http://exportsyms.uk" rel=3D"noreferrer" t=
arget=3D"_blank">exportsyms.uk</a> b/lib/uksp/<a href=3D"http://exportsyms.=
uk" rel=3D"noreferrer" target=3D"_blank">exportsyms.uk</a><br>
new file mode 100644<br>
index 00000000..fbc319e7<br>
--- /dev/null<br>
+++ b/lib/uksp/<a href=3D"http://exportsyms.uk" rel=3D"noreferrer" target=
=3D"_blank">exportsyms.uk</a><br>
@@ -0,0 +1,2 @@<br>
+__stack_chk_fail<br>
+__stack_chk_guard<br>
diff --git a/lib/uksp/include/uk/sp.h b/lib/uksp/include/uk/sp.h<br>
new file mode 100644<br>
index 00000000..f1da724d<br>
--- /dev/null<br>
+++ b/lib/uksp/include/uk/sp.h<br>
@@ -0,0 +1,56 @@<br>
+/* SPDX-License-Identifier: BSD-3-Clause */<br>
+/*<br>
+ * Authors: Vlad-Andrei Badoiu &lt;<a href=3D"mailto:vlad_andrei.badoiu@st=
ud.acs.upb.ro" target=3D"_blank">vlad_andrei.badoiu@stud.acs.upb.ro</a>&gt;=
<br>
+ *<br>
+ * Copyright (c) 2019, University Politehnica of Bucharest. All rights res=
erved.<br>
+ *<br>
+ * Redistribution and use in source and binary forms, with or without<br>
+ * modification, are permitted provided that the following conditions<br>
+ * are met:<br>
+ *<br>
+ * 1. Redistributions of source code must retain the above copyright<br>
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.<br>
+ * 2. Redistributions in binary form must reproduce the above copyright<br=
>
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the<br>
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.<br>
+ * 3. Neither the name of the copyright holder nor the names of its<br>
+ *=C2=A0 =C2=A0 contributors may be used to endorse or promote products de=
rived from<br>
+ *=C2=A0 =C2=A0 this software without specific prior written permission.<b=
r>
+ *<br>
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &qu=
ot;AS IS&quot;<br>
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, T=
HE<br>
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP=
OSE<br>
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS =
BE<br>
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br=
>
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINES=
S<br>
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN=
<br>
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)=
<br>
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF =
THE<br>
+ * POSSIBILITY OF SUCH DAMAGE.<br>
+ */<br>
+<br>
+#ifndef __UK_STACKPROTECTOR_H__<br>
+#define __UK_STACKPROTECTOR_H__<br>
+<br>
+#include &lt;uk/swrand.h&gt;<br>
+#include &lt;uk/config.h&gt;<br>
+<br>
+#ifdef __cplusplus<br>
+extern &quot;C&quot; {<br>
+#endif<br>
+<br>
+extern const unsigned long __stack_chk_guard;<br>
+<br>
+#ifdef CONFIG_LIBUKSP_VALUE_RANDOM<br>
+#define UKSP_INIT_CANARY() (*(DECONST(unsigned long *, &amp;__stack_chk_gu=
ard)) \<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=3D uk_swrand_randr=
())<br>
+#else<br>
+#define UKSP_INIT_CANARY()<br>
+#endif<br>
+<br>
+#ifdef __cplusplus<br>
+}<br>
+#endif<br>
+<br>
+#endif /* __UK_STACKPROTECTOR_H__ */<br>
diff --git a/lib/uksp/ssp.c b/lib/uksp/ssp.c<br>
new file mode 100644<br>
index 00000000..d0d10114<br>
--- /dev/null<br>
+++ b/lib/uksp/ssp.c<br>
@@ -0,0 +1,52 @@<br>
+/* SPDX-License-Identifier: BSD-3-Clause */<br>
+/*<br>
+ * Authors: Badoiu Vlad-Andrei &lt;<a href=3D"mailto:vlad_andrei.badoiu@st=
ud.acs.upb.ro" target=3D"_blank">vlad_andrei.badoiu@stud.acs.upb.ro</a>&gt;=
<br>
+ *<br>
+ * Copyright (c) 2019, University Politehnica of Bucharest. All rights res=
erved.<br>
+ *<br>
+ * Redistribution and use in source and binary forms, with or without<br>
+ * modification, are permitted provided that the following conditions<br>
+ * are met:<br>
+ *<br>
+ * 1. Redistributions of source code must retain the above copyright<br>
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.<br>
+ * 2. Redistributions in binary form must reproduce the above copyright<br=
>
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the<br>
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.<br>
+ * 3. Neither the name of the copyright holder nor the names of its<br>
+ *=C2=A0 =C2=A0 contributors may be used to endorse or promote products de=
rived from<br>
+ *=C2=A0 =C2=A0 this software without specific prior written permission.<b=
r>
+ *<br>
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &qu=
ot;AS IS&quot;<br>
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, T=
HE<br>
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP=
OSE<br>
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS =
BE<br>
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br=
>
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINES=
S<br>
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN=
<br>
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)=
<br>
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF =
THE<br>
+ * POSSIBILITY OF SUCH DAMAGE.<br>
+ */<br>
+<br>
+#include &lt;uk/assert.h&gt;<br>
+#include &lt;uk/swrand.h&gt;<br>
+#include &lt;uk/config.h&gt;<br>
+#include &lt;uk/ctors.h&gt;<br>
+#include &lt;uk/thread.h&gt;<br>
+<br>
+#ifdef CONFIG_LIBUKSP_VALUE_USECONSTANT<br>
+const unsigned long __stack_chk_guard =3D CONFIG_LIBUKSP_VALUE_CONSTANT;<b=
r>
+#else<br>
+const unsigned long __stack_chk_guard =3D 0xDEADBEEF;<br>
+#endif<br>
+<br>
+__attribute__((noreturn))<br>
+void __stack_chk_fail(void)<br>
+{<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned long sp;<br>
+<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0sp =3D ukarch_read_sp() &amp; STACK_MASK_TOP;<b=
r>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0UK_CRASH(&quot;Stack smashing detected. SP %p\n=
&quot;, (void *) sp);<br>
+}<br>
-- <br>
2.20.1<br>
<br>
<br>
</blockquote></div>

--00000000000041433605ab6c3826--


From minios-devel-bounces@lists.xenproject.org Mon Jul 27 14:22:00 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Mon, 27 Jul 2020 14:22:00 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k040r-00074u-OP; Mon, 27 Jul 2020 14:21:57 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=+vMC=BG=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1k040q-00074B-CV
 for minios-devel@lists.xenproject.org; Mon, 27 Jul 2020 14:21:56 +0000
X-Inumbo-ID: 84dd5fe0-d014-11ea-a7d9-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 84dd5fe0-d014-11ea-a7d9-12813bfff9fa;
 Mon, 27 Jul 2020 14:21:54 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 2CD1BF2020;
 Mon, 27 Jul 2020 16:21:53 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id a2SyOdyNj-9v; Mon, 27 Jul 2020 16:21:52 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id DF1FAF2011
 for <minios-devel@lists.xenproject.org>; Mon, 27 Jul 2020 16:21:50 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Mon, 27 Jul
 2020 16:21:50 +0200
Message-ID: <1595859709.4796.9.camel@neclab.eu>
Subject: Re: [UNIKRAFT PATCH 1/2] lib/ukallocregion: add region-based allocator
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: <minios-devel@lists.xenproject.org>
Date: Mon, 27 Jul 2020 16:21:49 +0200
In-Reply-To: <0bcc2440af348d578c39c520c481666d4227d81f.1592835388.git.hugo.lefeuvre@neclab.eu>
References: <cover.1592835388.git.hugo.lefeuvre@neclab.eu>
 <0bcc2440af348d578c39c520c481666d4227d81f.1592835388.git.hugo.lefeuvre@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: simon.kuenzer@neclab.eu
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Simon,

it looks like region.c is missing an #include (inline).

We might want to fix this with a v2 after your review (or while
upstreaming).

regards,
Hugo

On Mon, 2020-06-22 at 16:23 +0200, Hugo Lefeuvre wrote:
> Add ukallocregion, a minimalist region-based allocator.
> 
> Note that deallocation is not supported. This makes sense because
> regions
> only allow for deallocation at region-granularity. In our case, this
> would
> imply the freeing of the entire heap, which is generally not
> possible.
> 
> Obviously, the lack of deallocation support makes ukallocregion a
> fairly
> bad general-purpose allocator. This allocator is interesting in that
> it
> offers maximum speed allocation and deallocation (bounded O(1), no
> bookkeeping). It can be used as a baseline for measurements (e.g.,
> boot
> time) or as a first-level allocator in a nested context.
> 
> Refer to Gay & Aiken, `Memory management with explicit regions'
> (PLDI'98)
> for an introduction to region-based memory management.
> 
> Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> ---
> Â lib/Makefile.ukÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |Â Â Â 1 +
> Â lib/ukallocregion/Config.ukÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |Â Â 13 +++
> Â lib/ukallocregion/Makefile.ukÂ Â Â Â Â Â Â Â Â Â Â Â Â Â |Â Â Â 6 +
> Â lib/ukallocregion/exportsyms.ukÂ Â Â Â Â Â Â Â Â Â Â Â |Â Â Â 1 +
> Â lib/ukallocregion/include/uk/allocregion.h |Â Â 49 +++++++++
> Â lib/ukallocregion/region.cÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â | 169
> +++++++++++++++++++++++++++++
> Â 6 files changed, 239 insertions(+)
> Â create mode 100644 lib/ukallocregion/Config.uk
> Â create mode 100644 lib/ukallocregion/Makefile.uk
> Â create mode 100644 lib/ukallocregion/exportsyms.uk
> Â create mode 100644 lib/ukallocregion/include/uk/allocregion.h
> Â create mode 100644 lib/ukallocregion/region.c
> 
> diff --git a/lib/Makefile.uk b/lib/Makefile.uk
> index aa7e730..1f223d2 100644
> --- a/lib/Makefile.uk
> +++ b/lib/Makefile.uk
> @@ -14,6 +14,7 @@ $(eval $(call
> _import_lib,$(CONFIG_UK_BASE)/lib/uktimeconv))
> Â $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/nolibc))
> Â $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukalloc))
> Â $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukallocbbuddy))
> +$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukallocregion))
> Â $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uksched))
> Â $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukschedcoop))
> Â $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/fdt))
> diff --git a/lib/ukallocregion/Config.uk
> b/lib/ukallocregion/Config.uk
> new file mode 100644
> index 0000000..0bbc69f
> --- /dev/null
> +++ b/lib/ukallocregion/Config.uk
> @@ -0,0 +1,13 @@
> +config LIBUKALLOCREGION
> +	bool "ukallocregion - Region-based allocator"
> +	default n
> +	select LIBNOLIBC if !HAVE_LIBC
> +	select LIBUKDEBUG
> +	select LIBUKALLOC
> +	help
> +	Â Â Satisfy allocations as fast as possible, without
> bookkeeping. No
> +	Â Â support for free(): when the end of the allocation pool is
> reached,
> +	Â Â the allocator runs out-of-memory. This allocator is useful
> for
> +	Â Â experimentation, as baseline, or as first-level allocator
> in a nested
> +	Â Â context. Note that this allocator does not provide optimal
> locality of
> +	Â Â reference.
> diff --git a/lib/ukallocregion/Makefile.uk
> b/lib/ukallocregion/Makefile.uk
> new file mode 100644
> index 0000000..05a3d67
> --- /dev/null
> +++ b/lib/ukallocregion/Makefile.uk
> @@ -0,0 +1,6 @@
> +$(eval $(call addlib_s,libukallocregion,$(CONFIG_LIBUKALLOCREGION)))
> +
> +CINCLUDES-$(CONFIG_LIBUKALLOCREGION)	+=
> -I$(LIBUKALLOCREGION_BASE)/include
> +CXXINCLUDES-$(CONFIG_LIBUKALLOCREGION)	+=
> -I$(LIBUKALLOCREGION_BASE)/include
> +
> +LIBUKALLOCREGION_SRCS-y += $(LIBUKALLOCREGION_BASE)/region.c
> diff --git a/lib/ukallocregion/exportsyms.uk
> b/lib/ukallocregion/exportsyms.uk
> new file mode 100644
> index 0000000..481bc10
> --- /dev/null
> +++ b/lib/ukallocregion/exportsyms.uk
> @@ -0,0 +1 @@
> +uk_allocregion_init
> diff --git a/lib/ukallocregion/include/uk/allocregion.h
> b/lib/ukallocregion/include/uk/allocregion.h
> new file mode 100644
> index 0000000..1fc12db
> --- /dev/null
> +++ b/lib/ukallocregion/include/uk/allocregion.h
> @@ -0,0 +1,49 @@
> +/* SPDX-License-Identifier: BSD-3-Clause */
> +/*
> + * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> + *
> + * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights
> reserved.
> + *
> + * Redistribution and use in source and binary forms, with or
> without
> + * modification, are permitted provided that the following
> conditions
> + * are met:
> + *
> + * 1. Redistributions of source code must retain the above copyright
> + *Â Â Â Â notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above
> copyright
> + *Â Â Â Â notice, this list of conditions and the following disclaimer
> in the
> + *Â Â Â Â documentation and/or other materials provided with the
> distribution.
> + * 3. Neither the name of the copyright holder nor the names of its
> + *Â Â Â Â contributors may be used to endorse or promote products
> derived from
> + *Â Â Â Â this software without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
> CONTRIBUTORS "AS IS"
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
> TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
> PARTICULAR PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
> CONTRIBUTORS BE
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
> OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
> OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
> BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
> WHETHER IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
> OTHERWISE)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
> ADVISED OF THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#ifndef __LIBUKALLOCREGION_H__
> +#define __LIBUKALLOCREGION_H__
> +
> +#include <uk/alloc.h>
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +/* allocator initialization */
> +struct uk_alloc *uk_allocregion_init(void *base, size_t len);
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +#endif /* __LIBUKALLOCREGION_H__ */
> diff --git a/lib/ukallocregion/region.c b/lib/ukallocregion/region.c
> new file mode 100644
> index 0000000..6760b4c
> --- /dev/null
> +++ b/lib/ukallocregion/region.c
> @@ -0,0 +1,169 @@
> +/* SPDX-License-Identifier: BSD-3-Clause */
> +/*
> + * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> + *
> + * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights
> reserved.
> + *
> + * Redistribution and use in source and binary forms, with or
> without
> + * modification, are permitted provided that the following
> conditions
> + * are met:
> + *
> + * 1. Redistributions of source code must retain the above copyright
> + *Â Â Â Â notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above
> copyright
> + *Â Â Â Â notice, this list of conditions and the following disclaimer
> in the
> + *Â Â Â Â documentation and/or other materials provided with the
> distribution.
> + * 3. Neither the name of the copyright holder nor the names of its
> + *Â Â Â Â contributors may be used to endorse or promote products
> derived from
> + *Â Â Â Â this software without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
> CONTRIBUTORS "AS IS"
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
> TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
> PARTICULAR PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
> CONTRIBUTORS BE
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
> OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
> OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
> BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
> WHETHER IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
> OTHERWISE)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
> ADVISED OF THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +/* ukallocregion is a minimalist region implementation.
> + *
> + * Note that deallocation is not supported. This makes sense because
> regions
> + * only allow for deallocation at region-granularity. In our case,
> this would
> + * imply the freeing of the entire heap, which is generally not
> possible.
> + *
> + * Obviously, the lack of deallocation support makes ukallocregion a
> fairly bad
> + * general-purpose allocator. This allocator is interesting in that
> it offers
> + * maximum speed allocation and deallocation (no bookkeeping). It
> can be used as
> + * a baseline for measurements (e.g., boot time) or as a first-level 
> allocator
> + * in a nested context.
> + *
> + * Refer to Gay & Aiken, `Memory management with explicit regions'
> (PLDI'98) for
> + * an introduction to region-based memory management.
> + */
> +
> +#include <uk/allocregion.h>
> +#include <uk/alloc_impl.h>
> +#include <uk/page.h>	// round_pgup()

#include <limits.h> is needed for __PAGE_SIZE.

> +
> +struct uk_allocregion {
> +	void *heap_top;
> +	void *heap_base;
> +};
> +
> +void *uk_allocregion_malloc(struct uk_alloc *a, size_t size)
> +{
> +	struct uk_allocregion *b;
> +	void *newbase, *prevbase;
> +
> +	UK_ASSERT(a != NULL);
> +
> +	b = (struct uk_allocregion *)&a->priv;
> +
> +	/* return aligned pointers: this is a requirement for some
> +	Â * embedded systems archs, and more generally good for
> performance
> +	Â */
> +	newbaseÂ Â = (void *) ALIGN_UP(((uintptr_t) b->heap_base +
> size),
> +					(uintptr_t) sizeof(void *));
> +	prevbase = b->heap_base;
> +
> +	UK_ASSERT(newbase >= b->heap_base);
> +	UK_ASSERT(newbase <= b->heap_top);
> +
> +	b->heap_base = newbase;
> +
> +	return prevbase;
> +}
> +
> +int uk_allocregion_posix_memalign(struct uk_alloc *a, void **memptr,
> +					size_t align, size_t size)
> +{
> +	struct uk_allocregion *b;
> +	uintptr_t intptr;
> +
> +	UK_ASSERT(a != NULL);
> +
> +	b = (struct uk_allocregion *)&a->priv;
> +
> +	/* align must be a power of two */
> +	UK_ASSERT(((align - 1) & align) == 0);
> +
> +	/* align must be larger than pointer size */
> +	UK_ASSERT((align % sizeof(void *)) == 0);
> +
> +	if (!size) {
> +		*memptr = NULL;
> +		return EINVAL;
> +	}
> +
> +	intptr = ALIGN_UP((uintptr_t) b->heap_base, (uintptr_t)
> align);
> +
> +	if (intptr > (uintptr_t) b->heap_top)
> +		return ENOMEM; /* out-of-memory */
> +
> +	*memptr = (void *)intptr;
> +	b->heap_base = (void *)(intptr + size);
> +
> +	return 0;
> +}
> +
> +void uk_allocregion_free(struct uk_alloc *a __unused, void *ptr
> __unused)
> +{
> +	uk_pr_debug("%p: Releasing of memory is not supported by "
> +			"ukallocregion\n", a);
> +}
> +
> +int uk_allocregion_addmem(struct uk_alloc *a __unused, void *base
> __unused,
> +				size_t size __unused)
> +{
> +	/* TODO: support multiple regions */
> +	uk_pr_debug("%p: ukallocregion does not support multiple
> memory "
> +			"regions\n", a);
> +	return 0;
> +}
> +
> +struct uk_alloc *uk_allocregion_init(void *base, size_t len)
> +{
> +	struct uk_alloc *a;
> +	struct uk_allocregion *b;
> +	size_t metalen = sizeof(*a) + sizeof(*b);
> +
> +	/* TODO: ukallocregion does not support multiple memory
> regions yet.
> +	Â * Because of the multiboot layout, the first region might
> be a single
> +	Â * page, so we simply ignore it.
> +	Â */
> +	if (len <= __PAGE_SIZE)
> +		return NULL;
> +
> +	/* enough space for allocator available? */
> +	if (metalen > len) {
> +		uk_pr_err("Not enough space for allocator: %"__PRIsz
> +			Â Â " B required but only %"__PRIuptr" B
> usable\n",
> +			Â Â metalen, len);
> +		return NULL;
> +	}
> +
> +	/* store allocator metadata on the heap, just before the
> memory pool */
> +	a = (struct uk_alloc *)base;
> +	b = (struct uk_allocregion *)&a->priv;
> +
> +	uk_pr_info("Initialize allocregion allocator @ 0x%"
> +		Â Â Â __PRIuptr ", len %"__PRIsz"\n", (uintptr_t)a,
> len);
> +
> +	b->heap_topÂ Â = (void *)((uintptr_t) base + len);
> +	b->heap_base = (void *)((uintptr_t) base + metalen);
> +
> +	/* use exclusively "compat" wrappers for calloc, realloc,
> memalign,
> +	Â * palloc and pfree as those do not add additional metadata.
> +	Â */
> +	uk_alloc_init_malloc(a, uk_allocregion_malloc,
> uk_calloc_compat,
> +				uk_realloc_compat,
> uk_allocregion_free,
> +				uk_allocregion_posix_memalign,
> +				uk_memalign_compat, NULL);
> +
> +	return a;
> +}


From minios-devel-bounces@lists.xenproject.org Tue Jul 28 11:04:58 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 28 Jul 2020 11:04:58 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k0NPi-0003V0-OD; Tue, 28 Jul 2020 11:04:54 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=AfNs=BH=neclab.eu=simon.kuenzer@srs-us1.protection.inumbo.net>)
 id 1k0NPi-0003Uv-9X
 for minios-devel@lists.xenproject.org; Tue, 28 Jul 2020 11:04:54 +0000
X-Inumbo-ID: 28c9159c-d0c2-11ea-a89e-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 28c9159c-d0c2-11ea-a89e-12813bfff9fa;
 Tue, 28 Jul 2020 11:04:52 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 2BA7CF2010;
 Tue, 28 Jul 2020 13:04:51 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id R6EQQBtTsGpU; Tue, 28 Jul 2020 13:04:51 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id ED60AF200F
 for <minios-devel@lists.xenproject.org>; Tue, 28 Jul 2020 13:04:48 +0200 (CEST)
Received: from [10.7.1.42] (192.168.24.96) by puck.office.hd (192.168.24.91)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 28 Jul
 2020 13:04:48 +0200
Subject: Re: [UNIKRAFT PATCH v2] lib/ukalloc: make uk_alloc_get_default static
 inline
To: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>,
 <minios-devel@lists.xenproject.org>
References: <cover.1592998228.git.hugo.lefeuvre@neclab.eu>
 <cb4d87657d0c4404c3b2c886b7b752bb04049c74.1592998228.git.hugo.lefeuvre@neclab.eu>
From: Simon Kuenzer <simon.kuenzer@neclab.eu>
Message-ID: <04aa976e-9b31-5022-2103-1c6c2b699bda@neclab.eu>
Date: Tue, 28 Jul 2020 13:04:47 +0200
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0)
 Gecko/20100101 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <cb4d87657d0c4404c3b2c886b7b752bb04049c74.1592998228.git.hugo.lefeuvre@neclab.eu>
Content-Type: text/plain; charset="utf-8"; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Thanks a lot for the changes!

Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>

On 24.06.20 13:42, Hugo Lefeuvre wrote:
> Every allocation done through the libc malloc wrapper triggers a function
> call to uk_alloc_get_default in order to get a pointer to the default
> allocator.  This is not great, because the allocation path is performance
> critical, and we should avoid any superflous overhead there.
> 
> This patch removes the capability to change the default allocator once it
> has been set. This never really worked anyways... the libc wrapper would
> forward free() calls to the new allocator, potentially resulting in memory
> corruption if the new allocator doesn't handle these foreign pointers
> correctly, and memory leaks because these pointers won't be freed anymore.
> 
> We make the uk_alloc_head variable global and uk_alloc_get_default static
> inline. We rename uk_alloc_head to _uk_alloc_head -- it should preferably
> be accessed through uk_alloc_get_default.
> 
> Setting aside compiler optimizations, retrieving the default allocator
> becomes less expensive: a single memory read instead of a function call +
> memory read.
> 
> It appears that uk_alloc_set_default was not called anywhere, so this patch
> does not require any additional changes in external libraries.
> 
> Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> ---
>   lib/ukalloc/alloc.c            | 45 ++++--------------------------------------
>   lib/ukalloc/exportsyms.uk      |  2 +-
>   lib/ukalloc/include/uk/alloc.h | 10 +++++++---
>   3 files changed, 12 insertions(+), 45 deletions(-)
> 
> diff --git a/lib/ukalloc/alloc.c b/lib/ukalloc/alloc.c
> index 437bc4b..127bc6f 100644
> --- a/lib/ukalloc/alloc.c
> +++ b/lib/ukalloc/alloc.c
> @@ -57,14 +57,14 @@
>   	(ALIGN_UP((unsigned long)(size), __PAGE_SIZE) / __PAGE_SIZE)
>   #define page_off(x) ((unsigned long)(x) & (__PAGE_SIZE - 1))
>   
> -static struct uk_alloc *uk_alloc_head;
> +struct uk_alloc *_uk_alloc_head;
>   
>   int uk_alloc_register(struct uk_alloc *a)
>   {
> -	struct uk_alloc *this = uk_alloc_head;
> +	struct uk_alloc *this = _uk_alloc_head;
>   
> -	if (!uk_alloc_head) {
> -		uk_alloc_head = a;
> +	if (!_uk_alloc_head) {
> +		_uk_alloc_head = a;
>   		a->next = NULL;
>   		return 0;
>   	}
> @@ -76,43 +76,6 @@ int uk_alloc_register(struct uk_alloc *a)
>   	return 0;
>   }
>   
> -struct uk_alloc *uk_alloc_get_default(void)
> -{
> -	return uk_alloc_head;
> -}
> -
> -int uk_alloc_set_default(struct uk_alloc *a)
> -{
> -	struct uk_alloc *head, *this, *prev;
> -
> -	head = uk_alloc_get_default();
> -
> -	if (a == head)
> -		return 0;
> -
> -	if (!head) {
> -		uk_alloc_head = a;
> -		return 0;
> -	}
> -
> -	this = head;
> -	while (this->next) {
> -		prev = this;
> -		this = this->next;
> -		if (a == this) {
> -			prev->next = this->next;
> -			this->next = head->next;
> -			head = this;
> -			return 0;
> -		}
> -	}
> -
> -	/* a is not registered yet. Add in front of the queue. */
> -	a->next = head;
> -	uk_alloc_head = a;
> -	return 0;
> -}
> -
>   struct metadata_ifpages {
>   	unsigned long	num_pages;
>   	void		*base;
> diff --git a/lib/ukalloc/exportsyms.uk b/lib/ukalloc/exportsyms.uk
> index 2357501..2c8a90f 100644
> --- a/lib/ukalloc/exportsyms.uk
> +++ b/lib/ukalloc/exportsyms.uk
> @@ -1,6 +1,5 @@
>   uk_alloc_register
>   uk_alloc_get_default
> -uk_alloc_set_default
>   uk_malloc_ifpages
>   uk_free_ifpages
>   uk_realloc_ifpages
> @@ -10,3 +9,4 @@ uk_memalign_compat
>   uk_realloc_compat
>   uk_palloc_compat
>   uk_pfree_compat
> +_uk_alloc_head
> diff --git a/lib/ukalloc/include/uk/alloc.h b/lib/ukalloc/include/uk/alloc.h
> index 8ab41d6..5bfa2f2 100644
> --- a/lib/ukalloc/include/uk/alloc.h
> +++ b/lib/ukalloc/include/uk/alloc.h
> @@ -53,9 +53,6 @@ extern "C" {
>   #define uk_zalloc(a, size)  uk_calloc(a, 1, size)
>   #define uk_do_zalloc(a, size) uk_do_calloc(a, 1, size)
>   
> -struct uk_alloc *uk_alloc_get_default(void);
> -int uk_alloc_set_default(struct uk_alloc *a);
> -
>   typedef void* (*uk_alloc_malloc_func_t)
>   		(struct uk_alloc *a, size_t size);
>   typedef void* (*uk_alloc_calloc_func_t)
> @@ -103,6 +100,13 @@ struct uk_alloc {
>   	int8_t priv[];
>   };
>   
> +extern struct uk_alloc *_uk_alloc_head;
> +
> +static inline struct uk_alloc *uk_alloc_get_default(void)
> +{
> +	return _uk_alloc_head;
> +}
> +
>   /* wrapper functions */
>   static inline void *uk_do_malloc(struct uk_alloc *a, size_t size)
>   {
> 


From minios-devel-bounces@lists.xenproject.org Tue Jul 28 11:14:34 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 28 Jul 2020 11:14:34 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k0NZ3-0004QO-SF; Tue, 28 Jul 2020 11:14:33 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=AfNs=BH=neclab.eu=simon.kuenzer@srs-us1.protection.inumbo.net>)
 id 1k0NZ2-0004QJ-UF
 for minios-devel@lists.xen.org; Tue, 28 Jul 2020 11:14:32 +0000
X-Inumbo-ID: 81f7fc36-d0c3-11ea-a8a2-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 81f7fc36-d0c3-11ea-a8a2-12813bfff9fa;
 Tue, 28 Jul 2020 11:14:31 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 3DE7EF2010;
 Tue, 28 Jul 2020 13:14:30 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id VtJOTjOp7L_G; Tue, 28 Jul 2020 13:14:30 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 18E07F200F
 for <minios-devel@lists.xen.org>; Tue, 28 Jul 2020 13:14:28 +0200 (CEST)
Received: from localhost (192.168.24.96) by puck.office.hd (192.168.24.91)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 28 Jul
 2020 13:14:27 +0200
From: Simon Kuenzer <simon.kuenzer@neclab.eu>
To: <minios-devel@lists.xen.org>
Subject: [UNIKRAFT PATCH] include: uk/page.h: Provide __PAGE_SIZE
Date: Tue, 28 Jul 2020 13:14:25 +0200
Message-ID: <20200728111425.28417-1-simon.kuenzer@neclab.eu>
X-Mailer: git-send-email 2.20.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Simon Kuenzer <simon.kuenzer@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Provides __PAGE_SIZE with the uk/page.h header.

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
---
 include/uk/page.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uk/page.h b/include/uk/page.h
index 48ae9602..4e95f1b6 100644
--- a/include/uk/page.h
+++ b/include/uk/page.h
@@ -35,6 +35,7 @@
 #ifndef __UK_PAGE_H__
 #define __UK_PAGE_H__
 
+#include <uk/asm/limits.h>
 #include <uk/essentials.h>
 
 #ifdef __cplusplus
-- 
2.20.1



From minios-devel-bounces@lists.xenproject.org Tue Jul 28 11:41:40 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 28 Jul 2020 11:41:40 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k0NzH-0007Xm-FN; Tue, 28 Jul 2020 11:41:39 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=AfNs=BH=neclab.eu=simon.kuenzer@srs-us1.protection.inumbo.net>)
 id 1k0NzF-0007Xh-Ku
 for minios-devel@lists.xenproject.org; Tue, 28 Jul 2020 11:41:37 +0000
X-Inumbo-ID: 494fdea5-d0c7-11ea-8b28-bc764e2007e4
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 494fdea5-d0c7-11ea-8b28-bc764e2007e4;
 Tue, 28 Jul 2020 11:41:35 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 41CB610189D;
 Tue, 28 Jul 2020 13:41:34 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 1pWeNy3fDYZM; Tue, 28 Jul 2020 13:41:34 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id 1DF9D101371
 for <minios-devel@lists.xenproject.org>; Tue, 28 Jul 2020 13:41:34 +0200 (CEST)
Received: from [10.7.1.42] (192.168.24.96) by puck.office.hd (192.168.24.91)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 28 Jul
 2020 13:41:33 +0200
Subject: Re: [UNIKRAFT PATCH 2/2] lib/ukboot: initialize ukallocregion
To: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>,
 <minios-devel@lists.xenproject.org>
References: <cover.1592835388.git.hugo.lefeuvre@neclab.eu>
 <e98fa21fb4868efa5557713aed5ff75579ea29da.1592835388.git.hugo.lefeuvre@neclab.eu>
From: Simon Kuenzer <simon.kuenzer@neclab.eu>
Message-ID: <c1cf0a8d-a898-3dad-da53-6ef2dbdad622@neclab.eu>
Date: Tue, 28 Jul 2020 13:41:32 +0200
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0)
 Gecko/20100101 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <e98fa21fb4868efa5557713aed5ff75579ea29da.1592835388.git.hugo.lefeuvre@neclab.eu>
Content-Type: text/plain; charset="utf-8"; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: titania.office.hd (192.168.24.89) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Besides few minor comments, this patch looks very good. Thanks a lot!

On 22.06.20 16:23, Hugo Lefeuvre wrote:
> Add menuconfig bindings to select a system-wide allocator.
> Initialize the selected allocator in ukboot.
> 
> Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> ---
>   lib/ukboot/Config.uk | 26 ++++++++++++++++++++++----
>   lib/ukboot/boot.c    | 19 +++++++++++++------
>   2 files changed, 35 insertions(+), 10 deletions(-)
> 
> diff --git a/lib/ukboot/Config.uk b/lib/ukboot/Config.uk
> index 841a876..e4b356b 100644
> --- a/lib/ukboot/Config.uk
> +++ b/lib/ukboot/Config.uk
> @@ -17,8 +17,26 @@ if LIBUKBOOT
>   	int "Maximum number of arguments (max. size of argv)"
>   	default 60
>   
> -	config LIBUKBOOT_INITALLOC
> -	bool "Initialize ukallocbbuddy as allocator"
> -	default y
> -	select LIBUKALLOCBBUDDY
> +	choice LIBUKBOOT_INITALLOC
> +	prompt "Default memory allocator"

How about calling this "Initialize memory allocator" instead. I think 
this would make it a bit more obvious to a user what this option is 
doing behind the scenes.


> +	default LIBUKBOOT_INITBBUDDY
> +
> +		config LIBUKBOOT_INITBBUDDY
> +		bool "Binary buddy allocator"
> +		default y

Yes, remove these options 'defaul y/n', as you pointed out.

> +		select LIBUKALLOCBBUDDY
> +
> +		config LIBUKBOOT_INITREGION
> +		bool "Region allocator"
> +		default n
> +		select LIBUKALLOCREGION
> +		help
> +		  Satisfy allocation as fast as possible. No support for free().
> +		  Refer to help in ukallocregion for more information.
> +
> +		config LIBUKBOOT_NOALLOC
> +		bool "No memory allocator"

If you change the prompt of the choice as I mentioned, you can call this 
bool "None" instead of "No memory allocator". This makes it a bit shorter.

> +		default n
> +
> +	endchoice
>   endif
> diff --git a/lib/ukboot/boot.c b/lib/ukboot/boot.c
> index e8a2ac7..4e749aa 100644
> --- a/lib/ukboot/boot.c
> +++ b/lib/ukboot/boot.c
> @@ -41,8 +41,10 @@
>   #include <stdio.h>
>   #include <errno.h>
>   
> -#if CONFIG_LIBUKALLOC && CONFIG_LIBUKALLOCBBUDDY && CONFIG_LIBUKBOOT_INITALLOC
> +#if CONFIG_LIBUKBOOT_INITBBUDDY
>   #include <uk/allocbbuddy.h>
> +#elif CONFIG_LIBUKBOOT_INITREGION
> +#include <uk/allocregion.h>
>   #endif
>   #if CONFIG_LIBUKSCHED
>   #include <uk/sched.h>
> @@ -178,7 +180,7 @@ void ukplat_entry(int argc, char *argv[])
>   #if CONFIG_LIBUKALLOC
>   	struct uk_alloc *a = NULL;
>   #endif
> -#if CONFIG_LIBUKALLOC && CONFIG_LIBUKALLOCBBUDDY && CONFIG_LIBUKBOOT_INITALLOC
> +#if !CONFIG_LIBUKBOOT_NOALLOC
>   	struct ukplat_memregion_desc md;
>   #endif
>   #if CONFIG_LIBUKSCHED
> @@ -205,9 +207,9 @@ void ukplat_entry(int argc, char *argv[])
>   	}
>   #endif /* CONFIG_LIBUKLIBPARAM */
>   
> -#if CONFIG_LIBUKALLOC && CONFIG_LIBUKALLOCBBUDDY && CONFIG_LIBUKBOOT_INITALLOC
> +#if !CONFIG_LIBUKBOOT_NOALLOC
>   	/* initialize memory allocator
> -	 * FIXME: ukallocbbuddy is hard-coded for now
> +	 * FIXME: allocators are hard-coded for now
>   	 */
>   	uk_pr_info("Initialize memory allocator...\n");
>   	ukplat_memregion_foreach(&md, UKPLAT_MEMRF_ALLOCATABLE) {
> @@ -226,10 +228,15 @@ void ukplat_entry(int argc, char *argv[])
>   		 * As soon we have an allocator, we simply add every
>   		 * subsequent region to it
>   		 */
> -		if (unlikely(!a))
> +		if (!a) {
> +#if CONFIG_LIBUKBOOT_INITBBUDDY
>   			a = uk_allocbbuddy_init(md.base, md.len);
> -		else
> +#elif CONFIG_LIBUKBOOT_INITREGION
> +			a = uk_allocregion_init(md.base, md.len);
> +#endif
> +		} else {
>   			uk_alloc_addmem(a, md.base, md.len);
> +		}
>   	}
>   	if (unlikely(!a))
>   		uk_pr_warn("No suitable memory region for memory allocator. Continue without heap\n");
> 


From minios-devel-bounces@lists.xenproject.org Tue Jul 28 13:12:06 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 28 Jul 2020 13:12:06 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k0POl-0006ko-77; Tue, 28 Jul 2020 13:12:03 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=AfNs=BH=neclab.eu=simon.kuenzer@srs-us1.protection.inumbo.net>)
 id 1k0POk-0006kj-6n
 for minios-devel@lists.xenproject.org; Tue, 28 Jul 2020 13:12:02 +0000
X-Inumbo-ID: eae50efe-d0d3-11ea-a8d1-12813bfff9fa
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id eae50efe-d0d3-11ea-a8d1-12813bfff9fa;
 Tue, 28 Jul 2020 13:11:59 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 58B3B101371;
 Tue, 28 Jul 2020 15:11:58 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id SeFbVAf-T-HD; Tue, 28 Jul 2020 15:11:58 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id 30ACA1002CD
 for <minios-devel@lists.xenproject.org>; Tue, 28 Jul 2020 15:11:58 +0200 (CEST)
Received: from [10.7.1.42] (192.168.24.96) by puck.office.hd (192.168.24.91)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 28 Jul
 2020 15:11:57 +0200
Subject: Re: [UNIKRAFT PATCH 1/2] lib/ukallocregion: add region-based allocator
To: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>,
 <minios-devel@lists.xenproject.org>
References: <cover.1592835388.git.hugo.lefeuvre@neclab.eu>
 <0bcc2440af348d578c39c520c481666d4227d81f.1592835388.git.hugo.lefeuvre@neclab.eu>
 <1595859709.4796.9.camel@neclab.eu>
From: Simon Kuenzer <simon.kuenzer@neclab.eu>
Message-ID: <3f977b17-905a-75ca-7fbd-7abdef6815ce@neclab.eu>
Date: Tue, 28 Jul 2020 15:11:56 +0200
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0)
 Gecko/20100101 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <1595859709.4796.9.camel@neclab.eu>
Content-Type: text/plain; charset="utf-8"; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Hugo,

thanks a lot for your work. I have few comments inline. If you address 
them I am happy to take the allocator upstream. Really useful...

Thanks,

Simon

On 27.07.20 16:21, Hugo Lefeuvre wrote:
> Hi Simon,
> 
> it looks like region.c is missing an #include (inline).

I think the problem should be actually fixed within page.h header. I 
sent out a patch for this. The page.h header should not use undefined 
things and should actually be self-contained and include its dependencies.

> 
> We might want to fix this with a v2 after your review (or while
> upstreaming).
> 
> regards,
> Hugo
> 
> On Mon, 2020-06-22 at 16:23 +0200, Hugo Lefeuvre wrote:
>> Add ukallocregion, a minimalist region-based allocator.
>>
>> Note that deallocation is not supported. This makes sense because
>> regions
>> only allow for deallocation at region-granularity. In our case, this
>> would
>> imply the freeing of the entire heap, which is generally not
>> possible.
>>
>> Obviously, the lack of deallocation support makes ukallocregion a
>> fairly
>> bad general-purpose allocator. This allocator is interesting in that
>> it
>> offers maximum speed allocation and deallocation (bounded O(1), no
>> bookkeeping). It can be used as a baseline for measurements (e.g.,
>> boot
>> time) or as a first-level allocator in a nested context.
>>
>> Refer to Gay & Aiken, `Memory management with explicit regions'
>> (PLDI'98)
>> for an introduction to region-based memory management.
>>
>> Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
>> ---
>>  Â lib/Makefile.ukÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |Â Â Â 1 +
>>  Â lib/ukallocregion/Config.ukÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |Â Â 13 +++
>>  Â lib/ukallocregion/Makefile.ukÂ Â Â Â Â Â Â Â Â Â Â Â Â Â |Â Â Â 6 +
>>  Â lib/ukallocregion/exportsyms.ukÂ Â Â Â Â Â Â Â Â Â Â Â |Â Â Â 1 +
>>  Â lib/ukallocregion/include/uk/allocregion.h |Â Â 49 +++++++++
>>  Â lib/ukallocregion/region.cÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â | 169
>> +++++++++++++++++++++++++++++
>>  Â 6 files changed, 239 insertions(+)
>>  Â create mode 100644 lib/ukallocregion/Config.uk
>>  Â create mode 100644 lib/ukallocregion/Makefile.uk
>>  Â create mode 100644 lib/ukallocregion/exportsyms.uk
>>  Â create mode 100644 lib/ukallocregion/include/uk/allocregion.h
>>  Â create mode 100644 lib/ukallocregion/region.c
>>
>> diff --git a/lib/Makefile.uk b/lib/Makefile.uk
>> index aa7e730..1f223d2 100644
>> --- a/lib/Makefile.uk
>> +++ b/lib/Makefile.uk
>> @@ -14,6 +14,7 @@ $(eval $(call
>> _import_lib,$(CONFIG_UK_BASE)/lib/uktimeconv))
>>  Â $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/nolibc))
>>  Â $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukalloc))
>>  Â $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukallocbbuddy))
>> +$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukallocregion))
>>  Â $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uksched))
>>  Â $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukschedcoop))
>>  Â $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/fdt))
>> diff --git a/lib/ukallocregion/Config.uk
>> b/lib/ukallocregion/Config.uk
>> new file mode 100644
>> index 0000000..0bbc69f
>> --- /dev/null
>> +++ b/lib/ukallocregion/Config.uk
>> @@ -0,0 +1,13 @@
>> +config LIBUKALLOCREGION
>> +	bool "ukallocregion - Region-based allocator"

Use a ":" instead of a "-". This is to make it inline with the other 
menu items. I am going to do it while upstreaming.

>> +	default n
>> +	select LIBNOLIBC if !HAVE_LIBC
>> +	select LIBUKDEBUG
>> +	select LIBUKALLOC
>> +	help
>> +	Â Â Satisfy allocations as fast as possible, without
>> bookkeeping. No
>> +	Â Â support for free(): when the end of the allocation pool is
>> reached,
>> +	Â Â the allocator runs out-of-memory. This allocator is useful
>> for
>> +	Â Â experimentation, as baseline, or as first-level allocator
>> in a nested
>> +	Â Â context. Note that this allocator does not provide optimal
>> locality of
>> +	Â Â reference.

I think the last sentence can be removed. It probably confused more than 
it helps. bbuddy is also not considering locality and it somehow also 
depends how you allocator is initialized.

>> diff --git a/lib/ukallocregion/Makefile.uk
>> b/lib/ukallocregion/Makefile.uk
>> new file mode 100644
>> index 0000000..05a3d67
>> --- /dev/null
>> +++ b/lib/ukallocregion/Makefile.uk
>> @@ -0,0 +1,6 @@
>> +$(eval $(call addlib_s,libukallocregion,$(CONFIG_LIBUKALLOCREGION)))
>> +
>> +CINCLUDES-$(CONFIG_LIBUKALLOCREGION)	+=
>> -I$(LIBUKALLOCREGION_BASE)/include
>> +CXXINCLUDES-$(CONFIG_LIBUKALLOCREGION)	+=
>> -I$(LIBUKALLOCREGION_BASE)/include
>> +
>> +LIBUKALLOCREGION_SRCS-y += $(LIBUKALLOCREGION_BASE)/region.c
>> diff --git a/lib/ukallocregion/exportsyms.uk
>> b/lib/ukallocregion/exportsyms.uk
>> new file mode 100644
>> index 0000000..481bc10
>> --- /dev/null
>> +++ b/lib/ukallocregion/exportsyms.uk
>> @@ -0,0 +1 @@
>> +uk_allocregion_init
>> diff --git a/lib/ukallocregion/include/uk/allocregion.h
>> b/lib/ukallocregion/include/uk/allocregion.h
>> new file mode 100644
>> index 0000000..1fc12db
>> --- /dev/null
>> +++ b/lib/ukallocregion/include/uk/allocregion.h
>> @@ -0,0 +1,49 @@
>> +/* SPDX-License-Identifier: BSD-3-Clause */
>> +/*
>> + * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
>> + *
>> + * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights
>> reserved.
>> + *
>> + * Redistribution and use in source and binary forms, with or
>> without
>> + * modification, are permitted provided that the following
>> conditions
>> + * are met:
>> + *
>> + * 1. Redistributions of source code must retain the above copyright
>> + *Â Â Â Â notice, this list of conditions and the following disclaimer.
>> + * 2. Redistributions in binary form must reproduce the above
>> copyright
>> + *Â Â Â Â notice, this list of conditions and the following disclaimer
>> in the
>> + *Â Â Â Â documentation and/or other materials provided with the
>> distribution.
>> + * 3. Neither the name of the copyright holder nor the names of its
>> + *Â Â Â Â contributors may be used to endorse or promote products
>> derived from
>> + *Â Â Â Â this software without specific prior written permission.
>> + *
>> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
>> CONTRIBUTORS "AS IS"
>> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
>> TO, THE
>> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
>> PARTICULAR PURPOSE
>> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
>> CONTRIBUTORS BE
>> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
>> OR
>> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
>> OF
>> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
>> BUSINESS
>> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
>> WHETHER IN
>> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
>> OTHERWISE)
>> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
>> ADVISED OF THE
>> + * POSSIBILITY OF SUCH DAMAGE.
>> + */
>> +
>> +#ifndef __LIBUKALLOCREGION_H__
>> +#define __LIBUKALLOCREGION_H__
>> +
>> +#include <uk/alloc.h>
>> +
>> +#ifdef __cplusplus
>> +extern "C" {
>> +#endif
>> +
>> +/* allocator initialization */
>> +struct uk_alloc *uk_allocregion_init(void *base, size_t len);
>> +
>> +#ifdef __cplusplus
>> +}
>> +#endif
>> +
>> +#endif /* __LIBUKALLOCREGION_H__ */
>> diff --git a/lib/ukallocregion/region.c b/lib/ukallocregion/region.c
>> new file mode 100644
>> index 0000000..6760b4c
>> --- /dev/null
>> +++ b/lib/ukallocregion/region.c
>> @@ -0,0 +1,169 @@
>> +/* SPDX-License-Identifier: BSD-3-Clause */
>> +/*
>> + * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
>> + *
>> + * Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights
>> reserved.

Oh... this is an old header. It should say "NEC Laboratories Europe 
GmbH" instead of "NEC Europe Ltd.". Please check all your headers.

>> + *
>> + * Redistribution and use in source and binary forms, with or
>> without
>> + * modification, are permitted provided that the following
>> conditions
>> + * are met:
>> + *
>> + * 1. Redistributions of source code must retain the above copyright
>> + *Â Â Â Â notice, this list of conditions and the following disclaimer.
>> + * 2. Redistributions in binary form must reproduce the above
>> copyright
>> + *Â Â Â Â notice, this list of conditions and the following disclaimer
>> in the
>> + *Â Â Â Â documentation and/or other materials provided with the
>> distribution.
>> + * 3. Neither the name of the copyright holder nor the names of its
>> + *Â Â Â Â contributors may be used to endorse or promote products
>> derived from
>> + *Â Â Â Â this software without specific prior written permission.
>> + *
>> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
>> CONTRIBUTORS "AS IS"
>> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
>> TO, THE
>> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
>> PARTICULAR PURPOSE
>> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
>> CONTRIBUTORS BE
>> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
>> OR
>> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
>> OF
>> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
>> BUSINESS
>> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
>> WHETHER IN
>> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
>> OTHERWISE)
>> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
>> ADVISED OF THE
>> + * POSSIBILITY OF SUCH DAMAGE.
>> + */
>> +
>> +/* ukallocregion is a minimalist region implementation.
>> + *
>> + * Note that deallocation is not supported. This makes sense because
>> regions
>> + * only allow for deallocation at region-granularity. In our case,
>> this would
>> + * imply the freeing of the entire heap, which is generally not
>> possible.
>> + *
>> + * Obviously, the lack of deallocation support makes ukallocregion a
>> fairly bad
>> + * general-purpose allocator. This allocator is interesting in that
>> it offers
>> + * maximum speed allocation and deallocation (no bookkeeping). It
>> can be used as
>> + * a baseline for measurements (e.g., boot time) or as a first-level
>> allocator
>> + * in a nested context.
>> + *
>> + * Refer to Gay & Aiken, `Memory management with explicit regions'
>> (PLDI'98) for
>> + * an introduction to region-based memory management.
>> + */
>> +
>> +#include <uk/allocregion.h>
>> +#include <uk/alloc_impl.h>
>> +#include <uk/page.h>	// round_pgup()

checkpatch did not complain because of "//" comments? ;-)

> 
> #include <limits.h> is needed for __PAGE_SIZE.
> 
>> +
>> +struct uk_allocregion {
>> +	void *heap_top;
>> +	void *heap_base;
>> +};
>> +
>> +void *uk_allocregion_malloc(struct uk_alloc *a, size_t size)
>> +{
>> +	struct uk_allocregion *b;
>> +	void *newbase, *prevbase;
>> +
>> +	UK_ASSERT(a != NULL);
>> +
>> +	b = (struct uk_allocregion *)&a->priv;
>> +
>> +	/* return aligned pointers: this is a requirement for some
>> +	Â * embedded systems archs, and more generally good for
>> performance
>> +	Â */
>> +	newbaseÂ Â = (void *) ALIGN_UP(((uintptr_t) b->heap_base +
>> size),
>> +					(uintptr_t) sizeof(void *));
>> +	prevbase = b->heap_base;

Hum, I was thinking a while how to solve the problem that prevbase can 
be unaligned (e.g., first malloc call or malloc call after 
posix_memalign). First I thought, posix_memalign and allocregion_init 
need to be adopted to leave heap_base always aligned. But actually, the 
easier way is to align prevbase instead of newbase (similar to 
posix_memalign). This way all three behave the same: They will leave 
b->heap_base (not unaligned. What do you think?

>> +
>> +	UK_ASSERT(newbase >= b->heap_base);
>> +	UK_ASSERT(newbase <= b->heap_top);
>> +
>> +	b->heap_base = newbase;
>> +
>> +	return prevbase;
>> +}
>> +
>> +int uk_allocregion_posix_memalign(struct uk_alloc *a, void **memptr,
>> +					size_t align, size_t size)
>> +{
>> +	struct uk_allocregion *b;
>> +	uintptr_t intptr;
>> +
>> +	UK_ASSERT(a != NULL);
>> +
>> +	b = (struct uk_allocregion *)&a->priv;
>> +
>> +	/* align must be a power of two */
>> +	UK_ASSERT(((align - 1) & align) == 0);
>> +
>> +	/* align must be larger than pointer size */
>> +	UK_ASSERT((align % sizeof(void *)) == 0);
>> +
>> +	if (!size) {
>> +		*memptr = NULL;
>> +		return EINVAL;
>> +	}
>> +
>> +	intptr = ALIGN_UP((uintptr_t) b->heap_base, (uintptr_t)
>> align);
>> +
>> +	if (intptr > (uintptr_t) b->heap_top)
>> +		return ENOMEM; /* out-of-memory */
>> +
>> +	*memptr = (void *)intptr;
>> +	b->heap_base = (void *)(intptr + size);
>> +
>> +	return 0;
>> +}
>> +
>> +void uk_allocregion_free(struct uk_alloc *a __unused, void *ptr
>> __unused)
>> +{
>> +	uk_pr_debug("%p: Releasing of memory is not supported by "
>> +			"ukallocregion\n", a);
>> +}
>> +
>> +int uk_allocregion_addmem(struct uk_alloc *a __unused, void *base
>> __unused,
>> +				size_t size __unused)
>> +{
>> +	/* TODO: support multiple regions */
>> +	uk_pr_debug("%p: ukallocregion does not support multiple
>> memory "
>> +			"regions\n", a);
>> +	return 0;
>> +}
>> +
>> +struct uk_alloc *uk_allocregion_init(void *base, size_t len)
>> +{
>> +	struct uk_alloc *a;
>> +	struct uk_allocregion *b;
>> +	size_t metalen = sizeof(*a) + sizeof(*b);
>> +
>> +	/* TODO: ukallocregion does not support multiple memory
>> regions yet.
>> +	Â * Because of the multiboot layout, the first region might
>> be a single
>> +	Â * page, so we simply ignore it.
>> +	Â */
>> +	if (len <= __PAGE_SIZE)
>> +		return NULL;
>> +
>> +	/* enough space for allocator available? */
>> +	if (metalen > len) {
>> +		uk_pr_err("Not enough space for allocator: %"__PRIsz
>> +			Â Â " B required but only %"__PRIuptr" B
>> usable\n",
>> +			Â Â metalen, len);
>> +		return NULL;
>> +	}
>> +
>> +	/* store allocator metadata on the heap, just before the
>> memory pool */
>> +	a = (struct uk_alloc *)base;
>> +	b = (struct uk_allocregion *)&a->priv;
>> +
>> +	uk_pr_info("Initialize allocregion allocator @ 0x%"
>> +		Â Â Â __PRIuptr ", len %"__PRIsz"\n", (uintptr_t)a,
>> len);
>> +
>> +	b->heap_topÂ Â = (void *)((uintptr_t) base + len);
>> +	b->heap_base = (void *)((uintptr_t) base + metalen);
>> +
>> +	/* use exclusively "compat" wrappers for calloc, realloc,
>> memalign,
>> +	Â * palloc and pfree as those do not add additional metadata.
>> +	Â */
>> +	uk_alloc_init_malloc(a, uk_allocregion_malloc,
>> uk_calloc_compat,
>> +				uk_realloc_compat,
>> uk_allocregion_free,
>> +				uk_allocregion_posix_memalign,
>> +				uk_memalign_compat, NULL);
>> +
>> +	return a;
>> +}


From minios-devel-bounces@lists.xenproject.org Tue Jul 28 13:20:38 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 28 Jul 2020 13:20:38 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k0PX2-0007Yi-Pk; Tue, 28 Jul 2020 13:20:36 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Rl6p=BH=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1k0PX1-0007Yd-JY
 for minios-devel@lists.xen.org; Tue, 28 Jul 2020 13:20:35 +0000
X-Inumbo-ID: 1d3626ee-d0d5-11ea-a8d4-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 1d3626ee-d0d5-11ea-a8d4-12813bfff9fa;
 Tue, 28 Jul 2020 13:20:33 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 2A78BF2010;
 Tue, 28 Jul 2020 15:20:32 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id jznWfP9VSZLZ; Tue, 28 Jul 2020 15:20:32 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id E79B5F200F
 for <minios-devel@lists.xen.org>; Tue, 28 Jul 2020 15:20:29 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 28 Jul
 2020 15:20:29 +0200
Message-ID: <1595942407.4796.14.camel@neclab.eu>
Subject: Re: [UNIKRAFT PATCH] include: uk/page.h: Provide __PAGE_SIZE
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Simon Kuenzer <simon.kuenzer@neclab.eu>, <minios-devel@lists.xen.org>
In-Reply-To: <20200728111425.28417-1-simon.kuenzer@neclab.eu>
References: <20200728111425.28417-1-simon.kuenzer@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
Date: Tue, 28 Jul 2020 15:20:07 +0200
MIME-Version: 1.0
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: titania.office.hd (192.168.24.89) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Simon,

thanks a lot, this looks good to me. It was confusing to me that
including page.h didn't define __PAGE_SIZE.

regards,
Hugo

Reviewed-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>

On Tue, 2020-07-28 at 13:14 +0200, Simon Kuenzer wrote:
> Provides __PAGE_SIZE with the uk/page.h header.
> 
> Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
> ---
> Â include/uk/page.h | 1 +
> Â 1 file changed, 1 insertion(+)
> 
> diff --git a/include/uk/page.h b/include/uk/page.h
> index 48ae9602..4e95f1b6 100644
> --- a/include/uk/page.h
> +++ b/include/uk/page.h
> @@ -35,6 +35,7 @@
> Â #ifndef __UK_PAGE_H__
> Â #define __UK_PAGE_H__
> Â 
> +#include <uk/asm/limits.h>
> Â #include <uk/essentials.h>
> Â 
> Â #ifdef __cplusplus


From minios-devel-bounces@lists.xenproject.org Tue Jul 28 20:24:24 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Tue, 28 Jul 2020 20:24:24 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k0W97-0003eg-Lj; Tue, 28 Jul 2020 20:24:21 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=ubrj=BH=gmail.com=dincadaniel97@srs-us1.protection.inumbo.net>)
 id 1k0W96-0003eb-Lg
 for minios-devel@lists.xen.org; Tue, 28 Jul 2020 20:24:20 +0000
X-Inumbo-ID: 50a54b50-d110-11ea-8bd8-bc764e2007e4
Received: from mail-ed1-x52f.google.com (unknown [2a00:1450:4864:20::52f])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 50a54b50-d110-11ea-8bd8-bc764e2007e4;
 Tue, 28 Jul 2020 20:24:19 +0000 (UTC)
Received: by mail-ed1-x52f.google.com with SMTP id a8so15773758edy.1
 for <minios-devel@lists.xen.org>; Tue, 28 Jul 2020 13:24:19 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=in-reply-to:to:cc:from:subject:message-id:date:user-agent
 :mime-version:content-transfer-encoding:content-language;
 bh=55Co8l4bYBpuM2M08zGo9a55GHH/Z/nPzi2PJry2Ug8=;
 b=du6lMeBxHLkPG4aRsJ85ykgBygd4OJyCsiUIUaf97fY9mwdfl8bmijWa5JaPM0vZVD
 mtR4kOo/1wk4KsvdoGpUNkwll/LUC9pw7sIcnlJDV4u3N6UljBVdwelRAuq5OoYjvpPz
 C/o6TBU3aoEJLuuLdQLCXzNUnOapsPyuF4aLeDxNg/DERmATbH+h2ZUP+oUEY+k93u4L
 ilpDCOUTvncV+qbObzwQra+JMW8G30rtTHMNPrV/uW+CzCp/I0gAEcyuKNm46yUPQQos
 bO+8bmiyPE61K/rx16A4pIeuRhD6zz+k6F/R9Ub3DlEbMUgE/wZlNvCYx2JQT1MaKy1y
 oXcQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:in-reply-to:to:cc:from:subject:message-id:date
 :user-agent:mime-version:content-transfer-encoding:content-language;
 bh=55Co8l4bYBpuM2M08zGo9a55GHH/Z/nPzi2PJry2Ug8=;
 b=Xn0OWME7+k+dd9imU399wofDkknYFMVBf6L3bzSpfujqGvpbT4vWTfZ8KAVB4Sm+YV
 QsLQ3XlH9Efl4nACQqNCI2C7yDcS3co+NvUcVYKYiWgkPrMNWgN+/YnDIC2WRafjRCPv
 YVqT4E9Fh9cFKDRpBk5DyseOzJV3VIYrHo6JIBNyYcVJn36qd9JKszokJzrU2ydWItCH
 l1iIERSNsvGzTZ8Us14g/dtHtZjnKCyoHRKeVr739zqEBePFF64nhUotr1hYtBSqC6p4
 4ij4Mrypvn9Hv33OB+8JWcqQWfetJmCGs4MdK8cqnjNpF+I4kEUvHIFLUR15wYMUyYv/
 5sDw==
X-Gm-Message-State: AOAM530TepAjDprI+NIz17ZRboc6PtXRLuUUnTy7SjtKtHMKb1NTGWqo
 hG8lkZeHhgC00AgBofUqo3A=
X-Google-Smtp-Source: ABdhPJwFNpFuzGsaIH8gcDhuu1R7nzyJ7+MRg5XynaJTLppnqYxeLQk3SQC+cfYZKa7O23QuQc7Bgw==
X-Received: by 2002:a05:6402:1605:: with SMTP id
 f5mr29238910edv.8.1595967858788; 
 Tue, 28 Jul 2020 13:24:18 -0700 (PDT)
Received: from [192.168.0.102] ([82.77.177.192])
 by smtp.gmail.com with ESMTPSA id ay5sm83851edb.2.2020.07.28.13.24.17
 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
 Tue, 28 Jul 2020 13:24:18 -0700 (PDT)
In-Reply-To: <7c08a3de16702600ea0c8ddc508bfe0b05d78e4a.1593605155.git.hugo.lefeuvre@neclab.eu>
To: minios-devel@lists.xen.org
From: Daniel Dinca <dincadaniel97@gmail.com>
Subject: [UNIKRAFT/LIBMIMALLOC,v2] Initial port of mimalloc to Unikraft
Message-ID: <1b1aeeff-412c-cb60-fa50-edc54c8eebc7@gmail.com>
Date: Tue, 28 Jul 2020 23:24:16 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Content-Language: en-US
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: dincadaniel97@gmail.com
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

The main tree patch will need to be rebased before merge.

Otherwise looks good.


Review-by: Daniel Dinca

<dincadaniel97@gmail.com>



From minios-devel-bounces@lists.xenproject.org Wed Jul 29 08:56:13 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 29 Jul 2020 08:56:13 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k0hsf-0001ux-Uh; Wed, 29 Jul 2020 08:56:09 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=qY7a=BI=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1k0hsd-0001us-Ul
 for minios-devel@lists.xenproject.org; Wed, 29 Jul 2020 08:56:07 +0000
X-Inumbo-ID: 5619f4fa-d179-11ea-8c31-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 5619f4fa-d179-11ea-8c31-bc764e2007e4;
 Wed, 29 Jul 2020 08:56:06 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 0ED80F2010;
 Wed, 29 Jul 2020 10:56:05 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id EnF0GBWOb6TI; Wed, 29 Jul 2020 10:56:04 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id DA000F2004
 for <minios-devel@lists.xenproject.org>; Wed, 29 Jul 2020 10:56:02 +0200 (CEST)
Received: from N-1237.office.hd (192.168.24.96) by titania.office.hd
 (192.168.24.89) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 29 Jul
 2020 10:56:02 +0200
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: <minios-devel@lists.xenproject.org>
Subject: [UNIKRAFT PATCH v2 0/2] lib/ukallocregion: add region-based allocator
Date: Wed, 29 Jul 2020 10:55:53 +0200
Message-ID: <cover.1596012660.git.hugo.lefeuvre@neclab.eu>
X-Mailer: git-send-email 2.7.4
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Add ukallocregion, a minimalist region-based allocator.

ukallocregion is a special-purpose memory allocator. It satisfies
allocation requests contiguously without bookkeeping. Allocations are
therefore realized in O(1), but deallocation is not supported. This
allocator can be useful as a baseline, or as a first level allocator
in a nested context. More information in patch descriptions.

Changes since v1:
 - various minor improvements of menuconfig entries and descriptions
 - fix NEC headers
 - fix remaining // comments
 - align prevbase instead of newbase in uk_allocregion_malloc

Hugo Lefeuvre (2):
  lib/ukallocregion: add region-based allocator
  lib/ukboot: initialize ukallocregion

 lib/Makefile.uk                            |   1 +
 lib/ukallocregion/Config.uk                |  12 ++
 lib/ukallocregion/Makefile.uk              |   6 +
 lib/ukallocregion/exportsyms.uk            |   1 +
 lib/ukallocregion/include/uk/allocregion.h |  50 +++++++++
 lib/ukallocregion/region.c                 | 172 +++++++++++++++++++++++++++++
 lib/ukboot/Config.uk                       |  23 +++-
 lib/ukboot/boot.c                          |  19 +++-
 8 files changed, 274 insertions(+), 10 deletions(-)
 create mode 100644 lib/ukallocregion/Config.uk
 create mode 100644 lib/ukallocregion/Makefile.uk
 create mode 100644 lib/ukallocregion/exportsyms.uk
 create mode 100644 lib/ukallocregion/include/uk/allocregion.h
 create mode 100644 lib/ukallocregion/region.c

-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Wed Jul 29 08:56:14 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 29 Jul 2020 08:56:14 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k0hsk-0001vH-0E; Wed, 29 Jul 2020 08:56:14 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=qY7a=BI=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1k0hsi-0001us-MW
 for minios-devel@lists.xenproject.org; Wed, 29 Jul 2020 08:56:12 +0000
X-Inumbo-ID: 5619f8ce-d179-11ea-8c32-bc764e2007e4
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 5619f8ce-d179-11ea-8c32-bc764e2007e4;
 Wed, 29 Jul 2020 08:56:06 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 32405103941;
 Wed, 29 Jul 2020 10:56:05 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 64uRYG-5dB5r; Wed, 29 Jul 2020 10:56:05 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id 0F812101B8B
 for <minios-devel@lists.xenproject.org>; Wed, 29 Jul 2020 10:56:05 +0200 (CEST)
Received: from N-1237.office.hd (192.168.24.96) by titania.office.hd
 (192.168.24.89) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 29 Jul
 2020 10:56:04 +0200
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: <minios-devel@lists.xenproject.org>
Subject: [UNIKRAFT PATCH v2 1/2] lib/ukallocregion: add region-based allocator
Date: Wed, 29 Jul 2020 10:55:54 +0200
Message-ID: <1a8f3e5dbcb042237ab82db2a4746b09bc80b4a8.1596012660.git.hugo.lefeuvre@neclab.eu>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <cover.1596012660.git.hugo.lefeuvre@neclab.eu>
References: <cover.1596012660.git.hugo.lefeuvre@neclab.eu>
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Add ukallocregion, a minimalist region-based allocator.

Note that deallocation is not supported. This makes sense because regions
only allow for deallocation at region-granularity. In our case, this would
imply the freeing of the entire heap, which is generally not possible.

Obviously, the lack of deallocation support makes ukallocregion a fairly
bad general-purpose allocator. This allocator is interesting in that it
offers maximum speed allocation and deallocation (bounded O(1), no
bookkeeping). It can be used as a baseline for measurements (e.g., boot
time) or as a first-level allocator in a nested context.

Refer to Gay & Aiken, `Memory management with explicit regions' (PLDI'98)
for an introduction to region-based memory management.

Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
---
 lib/Makefile.uk                            |   1 +
 lib/ukallocregion/Config.uk                |  12 ++
 lib/ukallocregion/Makefile.uk              |   6 +
 lib/ukallocregion/exportsyms.uk            |   1 +
 lib/ukallocregion/include/uk/allocregion.h |  50 +++++++++
 lib/ukallocregion/region.c                 | 172 +++++++++++++++++++++++++++++
 6 files changed, 242 insertions(+)
 create mode 100644 lib/ukallocregion/Config.uk
 create mode 100644 lib/ukallocregion/Makefile.uk
 create mode 100644 lib/ukallocregion/exportsyms.uk
 create mode 100644 lib/ukallocregion/include/uk/allocregion.h
 create mode 100644 lib/ukallocregion/region.c

diff --git a/lib/Makefile.uk b/lib/Makefile.uk
index aa7e730..1f223d2 100644
--- a/lib/Makefile.uk
+++ b/lib/Makefile.uk
@@ -14,6 +14,7 @@ $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uktimeconv))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/nolibc))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukalloc))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukallocbbuddy))
+$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukallocregion))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uksched))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukschedcoop))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/fdt))
diff --git a/lib/ukallocregion/Config.uk b/lib/ukallocregion/Config.uk
new file mode 100644
index 0000000..0012677
--- /dev/null
+++ b/lib/ukallocregion/Config.uk
@@ -0,0 +1,12 @@
+config LIBUKALLOCREGION
+	bool "ukallocregion: Region-based allocator"
+	default n
+	select LIBNOLIBC if !HAVE_LIBC
+	select LIBUKDEBUG
+	select LIBUKALLOC
+	help
+	  Satisfy allocations as fast as possible, without bookkeeping. No
+	  support for free(): when the end of the allocation pool is reached,
+	  the allocator runs out-of-memory. This allocator is useful for
+	  experimentation, as baseline, or as first-level allocator in a nested
+	  context.
diff --git a/lib/ukallocregion/Makefile.uk b/lib/ukallocregion/Makefile.uk
new file mode 100644
index 0000000..05a3d67
--- /dev/null
+++ b/lib/ukallocregion/Makefile.uk
@@ -0,0 +1,6 @@
+$(eval $(call addlib_s,libukallocregion,$(CONFIG_LIBUKALLOCREGION)))
+
+CINCLUDES-$(CONFIG_LIBUKALLOCREGION)	+= -I$(LIBUKALLOCREGION_BASE)/include
+CXXINCLUDES-$(CONFIG_LIBUKALLOCREGION)	+= -I$(LIBUKALLOCREGION_BASE)/include
+
+LIBUKALLOCREGION_SRCS-y += $(LIBUKALLOCREGION_BASE)/region.c
diff --git a/lib/ukallocregion/exportsyms.uk b/lib/ukallocregion/exportsyms.uk
new file mode 100644
index 0000000..481bc10
--- /dev/null
+++ b/lib/ukallocregion/exportsyms.uk
@@ -0,0 +1 @@
+uk_allocregion_init
diff --git a/lib/ukallocregion/include/uk/allocregion.h b/lib/ukallocregion/include/uk/allocregion.h
new file mode 100644
index 0000000..863ef6c
--- /dev/null
+++ b/lib/ukallocregion/include/uk/allocregion.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation,
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __LIBUKALLOCREGION_H__
+#define __LIBUKALLOCREGION_H__
+
+#include <uk/alloc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* allocator initialization */
+struct uk_alloc *uk_allocregion_init(void *base, size_t len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LIBUKALLOCREGION_H__ */
diff --git a/lib/ukallocregion/region.c b/lib/ukallocregion/region.c
new file mode 100644
index 0000000..8d2baec
--- /dev/null
+++ b/lib/ukallocregion/region.c
@@ -0,0 +1,172 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation,
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* ukallocregion is a minimalist region implementation.
+ *
+ * Note that deallocation is not supported. This makes sense because regions
+ * only allow for deallocation at region-granularity. In our case, this would
+ * imply the freeing of the entire heap, which is generally not possible.
+ *
+ * Obviously, the lack of deallocation support makes ukallocregion a fairly bad
+ * general-purpose allocator. This allocator is interesting in that it offers
+ * maximum speed allocation and deallocation (no bookkeeping). It can be used as
+ * a baseline for measurements (e.g., boot time) or as a first-level allocator
+ * in a nested context.
+ *
+ * Refer to Gay & Aiken, `Memory management with explicit regions' (PLDI'98) for
+ * an introduction to region-based memory management.
+ */
+
+#include <uk/allocregion.h>
+#include <uk/alloc_impl.h>
+#include <uk/page.h>	/* round_pgup() */
+
+struct uk_allocregion {
+	void *heap_top;
+	void *heap_base;
+};
+
+void *uk_allocregion_malloc(struct uk_alloc *a, size_t size)
+{
+	struct uk_allocregion *b;
+	void *newbase, *prevbase;
+
+	UK_ASSERT(a != NULL);
+
+	b = (struct uk_allocregion *)&a->priv;
+
+	/* return aligned pointers: this is a requirement for some
+	 * embedded systems archs, and more generally good for performance
+	 */
+	b->heap_base = (void *) ALIGN_UP(((uintptr_t) b->heap_base),
+					(uintptr_t) sizeof(void *));
+
+	prevbase = b->heap_base;
+	newbase  = (void *) ((uintptr_t) b->heap_base + size);
+
+	UK_ASSERT(newbase >= b->heap_base);
+	UK_ASSERT(newbase <= b->heap_top);
+
+	b->heap_base = newbase;
+
+	return prevbase;
+}
+
+int uk_allocregion_posix_memalign(struct uk_alloc *a, void **memptr,
+					size_t align, size_t size)
+{
+	struct uk_allocregion *b;
+	uintptr_t intptr;
+
+	UK_ASSERT(a != NULL);
+
+	b = (struct uk_allocregion *)&a->priv;
+
+	/* align must be a power of two */
+	UK_ASSERT(((align - 1) & align) == 0);
+
+	/* align must be larger than pointer size */
+	UK_ASSERT((align % sizeof(void *)) == 0);
+
+	if (!size) {
+		*memptr = NULL;
+		return EINVAL;
+	}
+
+	intptr = ALIGN_UP((uintptr_t) b->heap_base, (uintptr_t) align);
+
+	if (intptr > (uintptr_t) b->heap_top)
+		return ENOMEM; /* out-of-memory */
+
+	*memptr = (void *)intptr;
+	b->heap_base = (void *)(intptr + size);
+
+	return 0;
+}
+
+void uk_allocregion_free(struct uk_alloc *a __unused, void *ptr __unused)
+{
+	uk_pr_debug("%p: Releasing of memory is not supported by "
+			"ukallocregion\n", a);
+}
+
+int uk_allocregion_addmem(struct uk_alloc *a __unused, void *base __unused,
+				size_t size __unused)
+{
+	/* TODO: support multiple regions */
+	uk_pr_debug("%p: ukallocregion does not support multiple memory "
+			"regions\n", a);
+	return 0;
+}
+
+struct uk_alloc *uk_allocregion_init(void *base, size_t len)
+{
+	struct uk_alloc *a;
+	struct uk_allocregion *b;
+	size_t metalen = sizeof(*a) + sizeof(*b);
+
+	/* TODO: ukallocregion does not support multiple memory regions yet.
+	 * Because of the multiboot layout, the first region might be a single
+	 * page, so we simply ignore it.
+	 */
+	if (len <= __PAGE_SIZE)
+		return NULL;
+
+	/* enough space for allocator available? */
+	if (metalen > len) {
+		uk_pr_err("Not enough space for allocator: %"__PRIsz
+			  " B required but only %"__PRIuptr" B usable\n",
+			  metalen, len);
+		return NULL;
+	}
+
+	/* store allocator metadata on the heap, just before the memory pool */
+	a = (struct uk_alloc *)base;
+	b = (struct uk_allocregion *)&a->priv;
+
+	uk_pr_info("Initialize allocregion allocator @ 0x%"
+		   __PRIuptr ", len %"__PRIsz"\n", (uintptr_t)a, len);
+
+	b->heap_top  = (void *)((uintptr_t) base + len);
+	b->heap_base = (void *)((uintptr_t) base + metalen);
+
+	/* use exclusively "compat" wrappers for calloc, realloc, memalign,
+	 * palloc and pfree as those do not add additional metadata.
+	 */
+	uk_alloc_init_malloc(a, uk_allocregion_malloc, uk_calloc_compat,
+				uk_realloc_compat, uk_allocregion_free,
+				uk_allocregion_posix_memalign,
+				uk_memalign_compat, NULL);
+
+	return a;
+}
-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Wed Jul 29 08:56:19 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 29 Jul 2020 08:56:19 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k0hsp-0001wJ-2z; Wed, 29 Jul 2020 08:56:19 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=qY7a=BI=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1k0hsn-0001us-Me
 for minios-devel@lists.xenproject.org; Wed, 29 Jul 2020 08:56:17 +0000
X-Inumbo-ID: 57eacb92-d179-11ea-8c32-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 57eacb92-d179-11ea-8c32-bc764e2007e4;
 Wed, 29 Jul 2020 08:56:09 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 3D0CBF2010;
 Wed, 29 Jul 2020 10:56:08 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id XXeFckwenC7G; Wed, 29 Jul 2020 10:56:08 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 0E1EBF2004
 for <minios-devel@lists.xenproject.org>; Wed, 29 Jul 2020 10:56:06 +0200 (CEST)
Received: from N-1237.office.hd (192.168.24.96) by titania.office.hd
 (192.168.24.89) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 29 Jul
 2020 10:56:05 +0200
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: <minios-devel@lists.xenproject.org>
Subject: [UNIKRAFT PATCH v2 2/2] lib/ukboot: initialize ukallocregion
Date: Wed, 29 Jul 2020 10:55:55 +0200
Message-ID: <3de83ca5275a4730a56a4cf23b3065e3c1055a1d.1596012660.git.hugo.lefeuvre@neclab.eu>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <cover.1596012660.git.hugo.lefeuvre@neclab.eu>
References: <cover.1596012660.git.hugo.lefeuvre@neclab.eu>
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Add menuconfig bindings to select a system-wide allocator.
Initialize the selected allocator in ukboot.

Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
---
 lib/ukboot/Config.uk | 23 +++++++++++++++++++----
 lib/ukboot/boot.c    | 19 +++++++++++++------
 2 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/lib/ukboot/Config.uk b/lib/ukboot/Config.uk
index 841a876..07139e2 100644
--- a/lib/ukboot/Config.uk
+++ b/lib/ukboot/Config.uk
@@ -17,8 +17,23 @@ if LIBUKBOOT
 	int "Maximum number of arguments (max. size of argv)"
 	default 60
 
-	config LIBUKBOOT_INITALLOC
-	bool "Initialize ukallocbbuddy as allocator"
-	default y
-	select LIBUKALLOCBBUDDY
+	choice LIBUKBOOT_INITALLOC
+	prompt "Initialize memory allocator"
+	default LIBUKBOOT_INITBBUDDY
+
+		config LIBUKBOOT_INITBBUDDY
+		bool "Binary buddy allocator"
+		select LIBUKALLOCBBUDDY
+
+		config LIBUKBOOT_INITREGION
+		bool "Region allocator"
+		select LIBUKALLOCREGION
+		help
+		  Satisfy allocation as fast as possible. No support for free().
+		  Refer to help in ukallocregion for more information.
+
+		config LIBUKBOOT_NOALLOC
+		bool "None"
+
+	endchoice
 endif
diff --git a/lib/ukboot/boot.c b/lib/ukboot/boot.c
index e8a2ac7..4e749aa 100644
--- a/lib/ukboot/boot.c
+++ b/lib/ukboot/boot.c
@@ -41,8 +41,10 @@
 #include <stdio.h>
 #include <errno.h>
 
-#if CONFIG_LIBUKALLOC && CONFIG_LIBUKALLOCBBUDDY && CONFIG_LIBUKBOOT_INITALLOC
+#if CONFIG_LIBUKBOOT_INITBBUDDY
 #include <uk/allocbbuddy.h>
+#elif CONFIG_LIBUKBOOT_INITREGION
+#include <uk/allocregion.h>
 #endif
 #if CONFIG_LIBUKSCHED
 #include <uk/sched.h>
@@ -178,7 +180,7 @@ void ukplat_entry(int argc, char *argv[])
 #if CONFIG_LIBUKALLOC
 	struct uk_alloc *a = NULL;
 #endif
-#if CONFIG_LIBUKALLOC && CONFIG_LIBUKALLOCBBUDDY && CONFIG_LIBUKBOOT_INITALLOC
+#if !CONFIG_LIBUKBOOT_NOALLOC
 	struct ukplat_memregion_desc md;
 #endif
 #if CONFIG_LIBUKSCHED
@@ -205,9 +207,9 @@ void ukplat_entry(int argc, char *argv[])
 	}
 #endif /* CONFIG_LIBUKLIBPARAM */
 
-#if CONFIG_LIBUKALLOC && CONFIG_LIBUKALLOCBBUDDY && CONFIG_LIBUKBOOT_INITALLOC
+#if !CONFIG_LIBUKBOOT_NOALLOC
 	/* initialize memory allocator
-	 * FIXME: ukallocbbuddy is hard-coded for now
+	 * FIXME: allocators are hard-coded for now
 	 */
 	uk_pr_info("Initialize memory allocator...\n");
 	ukplat_memregion_foreach(&md, UKPLAT_MEMRF_ALLOCATABLE) {
@@ -226,10 +228,15 @@ void ukplat_entry(int argc, char *argv[])
 		 * As soon we have an allocator, we simply add every
 		 * subsequent region to it
 		 */
-		if (unlikely(!a))
+		if (!a) {
+#if CONFIG_LIBUKBOOT_INITBBUDDY
 			a = uk_allocbbuddy_init(md.base, md.len);
-		else
+#elif CONFIG_LIBUKBOOT_INITREGION
+			a = uk_allocregion_init(md.base, md.len);
+#endif
+		} else {
 			uk_alloc_addmem(a, md.base, md.len);
+		}
 	}
 	if (unlikely(!a))
 		uk_pr_warn("No suitable memory region for memory allocator. Continue without heap\n");
-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Wed Jul 29 08:59:17 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 29 Jul 2020 08:59:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k0hvh-00022E-BG; Wed, 29 Jul 2020 08:59:17 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=qY7a=BI=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1k0hvf-000224-7G
 for minios-devel@lists.xenproject.org; Wed, 29 Jul 2020 08:59:15 +0000
X-Inumbo-ID: c6244962-d179-11ea-8c32-bc764e2007e4
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id c6244962-d179-11ea-8c32-bc764e2007e4;
 Wed, 29 Jul 2020 08:59:14 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 283B1101B8B;
 Wed, 29 Jul 2020 10:59:13 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id Juh27yuzSFgB; Wed, 29 Jul 2020 10:59:13 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id 03D5F1002CD
 for <minios-devel@lists.xenproject.org>; Wed, 29 Jul 2020 10:59:13 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 29 Jul
 2020 10:59:12 +0200
Message-ID: <1596013151.4796.15.camel@neclab.eu>
Subject: Re: [UNIKRAFT PATCH 2/2] lib/ukboot: initialize ukallocregion
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Simon Kuenzer <simon.kuenzer@neclab.eu>,
 <minios-devel@lists.xenproject.org>
Date: Wed, 29 Jul 2020 10:59:11 +0200
In-Reply-To: <c1cf0a8d-a898-3dad-da53-6ef2dbdad622@neclab.eu>
References: <cover.1592835388.git.hugo.lefeuvre@neclab.eu>
 <e98fa21fb4868efa5557713aed5ff75579ea29da.1592835388.git.hugo.lefeuvre@neclab.eu>
 <c1cf0a8d-a898-3dad-da53-6ef2dbdad622@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Simon,

thanks a lot, comments for 1/2 and 2/2 addressed in the v2.

regards,
Hugo

On Tue, 2020-07-28 at 13:41 +0200, Simon Kuenzer wrote:
> Besides few minor comments, this patch looks very good. Thanks a lot!
> 
> On 22.06.20 16:23, Hugo Lefeuvre wrote:
> > 
> > Add menuconfig bindings to select a system-wide allocator.
> > Initialize the selected allocator in ukboot.
> > 
> > Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> > ---
> > Â  lib/ukboot/Config.uk | 26 ++++++++++++++++++++++----
> > Â  lib/ukboot/boot.cÂ Â Â Â | 19 +++++++++++++------
> > Â  2 files changed, 35 insertions(+), 10 deletions(-)
> > 
> > diff --git a/lib/ukboot/Config.uk b/lib/ukboot/Config.uk
> > index 841a876..e4b356b 100644
> > --- a/lib/ukboot/Config.uk
> > +++ b/lib/ukboot/Config.uk
> > @@ -17,8 +17,26 @@ if LIBUKBOOT
> > Â Â 	int "Maximum number of arguments (max. size of argv)"
> > Â Â 	default 60
> > Â Â 
> > -	config LIBUKBOOT_INITALLOC
> > -	bool "Initialize ukallocbbuddy as allocator"
> > -	default y
> > -	select LIBUKALLOCBBUDDY
> > +	choice LIBUKBOOT_INITALLOC
> > +	prompt "Default memory allocator"
> How about calling this "Initialize memory allocator" instead. I
> thinkÂ 
> this would make it a bit more obvious to a user what this option isÂ 
> doing behind the scenes.
> 
> 
> > 
> > +	default LIBUKBOOT_INITBBUDDY
> > +
> > +		config LIBUKBOOT_INITBBUDDY
> > +		bool "Binary buddy allocator"
> > +		default y
> Yes, remove these options 'defaul y/n', as you pointed out.
> 
> > 
> > +		select LIBUKALLOCBBUDDY
> > +
> > +		config LIBUKBOOT_INITREGION
> > +		bool "Region allocator"
> > +		default n
> > +		select LIBUKALLOCREGION
> > +		help
> > +		Â Â Satisfy allocation as fast as possible. No
> > support for free().
> > +		Â Â Refer to help in ukallocregion for more
> > information.
> > +
> > +		config LIBUKBOOT_NOALLOC
> > +		bool "No memory allocator"
> If you change the prompt of the choice as I mentioned, you can call
> thisÂ 
> bool "None" instead of "No memory allocator". This makes it a bit
> shorter.
> 
> > 
> > +		default n
> > +
> > +	endchoice
> > Â  endif
> > diff --git a/lib/ukboot/boot.c b/lib/ukboot/boot.c
> > index e8a2ac7..4e749aa 100644
> > --- a/lib/ukboot/boot.c
> > +++ b/lib/ukboot/boot.c
> > @@ -41,8 +41,10 @@
> > Â  #include <stdio.h>
> > Â  #include <errno.h>
> > Â Â 
> > -#if CONFIG_LIBUKALLOC && CONFIG_LIBUKALLOCBBUDDY &&
> > CONFIG_LIBUKBOOT_INITALLOC
> > +#if CONFIG_LIBUKBOOT_INITBBUDDY
> > Â  #include <uk/allocbbuddy.h>
> > +#elif CONFIG_LIBUKBOOT_INITREGION
> > +#include <uk/allocregion.h>
> > Â  #endif
> > Â  #if CONFIG_LIBUKSCHED
> > Â  #include <uk/sched.h>
> > @@ -178,7 +180,7 @@ void ukplat_entry(int argc, char *argv[])
> > Â  #if CONFIG_LIBUKALLOC
> > Â Â 	struct uk_alloc *a = NULL;
> > Â  #endif
> > -#if CONFIG_LIBUKALLOC && CONFIG_LIBUKALLOCBBUDDY &&
> > CONFIG_LIBUKBOOT_INITALLOC
> > +#if !CONFIG_LIBUKBOOT_NOALLOC
> > Â Â 	struct ukplat_memregion_desc md;
> > Â  #endif
> > Â  #if CONFIG_LIBUKSCHED
> > @@ -205,9 +207,9 @@ void ukplat_entry(int argc, char *argv[])
> > Â Â 	}
> > Â  #endif /* CONFIG_LIBUKLIBPARAM */
> > Â Â 
> > -#if CONFIG_LIBUKALLOC && CONFIG_LIBUKALLOCBBUDDY &&
> > CONFIG_LIBUKBOOT_INITALLOC
> > +#if !CONFIG_LIBUKBOOT_NOALLOC
> > Â Â 	/* initialize memory allocator
> > -	Â * FIXME: ukallocbbuddy is hard-coded for now
> > +	Â * FIXME: allocators are hard-coded for now
> > Â Â 	Â */
> > Â Â 	uk_pr_info("Initialize memory allocator...\n");
> > Â Â 	ukplat_memregion_foreach(&md, UKPLAT_MEMRF_ALLOCATABLE) {
> > @@ -226,10 +228,15 @@ void ukplat_entry(int argc, char *argv[])
> > Â Â 		Â * As soon we have an allocator, we simply add
> > every
> > Â Â 		Â * subsequent region to it
> > Â Â 		Â */
> > -		if (unlikely(!a))
> > +		if (!a) {
> > +#if CONFIG_LIBUKBOOT_INITBBUDDY
> > Â Â 			a = uk_allocbbuddy_init(md.base, md.len);
> > -		else
> > +#elif CONFIG_LIBUKBOOT_INITREGION
> > +			a = uk_allocregion_init(md.base, md.len);
> > +#endif
> > +		} else {
> > Â Â 			uk_alloc_addmem(a, md.base, md.len);
> > +		}
> > Â Â 	}
> > Â Â 	if (unlikely(!a))
> > Â Â 		uk_pr_warn("No suitable memory region for memory
> > allocator. Continue without heap\n");
> > 


From minios-devel-bounces@lists.xenproject.org Wed Jul 29 10:59:25 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 29 Jul 2020 10:59:25 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k0jnu-0003fF-Iq; Wed, 29 Jul 2020 10:59:22 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=B61f=BI=gmail.com=dincadaniel97@srs-us1.protection.inumbo.net>)
 id 1k0jns-0003fA-VK
 for minios-devel@lists.xen.org; Wed, 29 Jul 2020 10:59:21 +0000
X-Inumbo-ID: 8d4733dc-d18a-11ea-8c3e-bc764e2007e4
Received: from mail-ej1-x635.google.com (unknown [2a00:1450:4864:20::635])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 8d4733dc-d18a-11ea-8c3e-bc764e2007e4;
 Wed, 29 Jul 2020 10:59:20 +0000 (UTC)
Received: by mail-ej1-x635.google.com with SMTP id l4so23810436ejd.13
 for <minios-devel@lists.xen.org>; Wed, 29 Jul 2020 03:59:19 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=in-reply-to:to:cc:from:subject:message-id:date:user-agent
 :mime-version:content-language;
 bh=+LqdBQl8tJRvA4a+bHIGv8+G3chWmJ5YPfn6mJj6PMM=;
 b=OnKCP3D6gT5W7oF74cmiQno4WhKNEWbgbucy3P2IIekC0Z9wDLblhte4V0kja+KKBx
 eCPaQD2lAdTGgZtoLm9VKGFQmTRA2pueBtZx8e/g3TdNBxYg/i1ZSBq/gd6rkW8UD3ki
 DMudR6YY3hdRhvANnckqbICzjp8GuEU43sRMi8QQ0U85lM3u27W8v6/BpD6TNqKxcxPm
 gw4BrIgphfc+bY807sro5nzqteYAg7feVgBvaM8do2vPsK5Opw+rPWjnABUqTnRH5xFt
 WVLOs9lGHUF0oHsSCJqtHZYjfCKlyWg8BF+CEb+Y42O5x20bLj92IkGUjQ7yCyXoeRBp
 +GdA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:in-reply-to:to:cc:from:subject:message-id:date
 :user-agent:mime-version:content-language;
 bh=+LqdBQl8tJRvA4a+bHIGv8+G3chWmJ5YPfn6mJj6PMM=;
 b=WyM0cQsseXaAF5wtUZK3wYpf18AlyhWG5jvdsd513ayrLV072lHt8Q/AAkbmDOns25
 sF9WIXZEroC8HYViiM/PDPznALtHRQAcHS6FE9Iku2PZkLnJ2HvHwkgv0ndSXPDoKCoE
 lI/cb2mMePmUJ2OVb0AtKhn8xQGsKkqqTYPR1fv6+f5VLT285cZCHQgQJK9sSrmEghzW
 G4PZXl1SXHRUTCvaWbJw17Pxou+3OulmCVMR5fkRkW/Luf+I4iqbN4JQxPgEJNs4cFRh
 GVuz7lS2vGWge6/gzefMmoq5lA3DXHTAkRSnt3IdUV5aw5ZG1lRedOoCHlXORnTjTM+d
 4/Tw==
X-Gm-Message-State: AOAM532IRAtwatlMRF8wmT/YjC6tfZVIuJvbhE/2TBX6Yyoz/KpsBE92
 vHoBivy6bCLSW7CgLEFUXD0=
X-Google-Smtp-Source: ABdhPJzZlrdtchQtoOJFoB6khHb1ORnBBPh2WQ27yLOAfK+tuB42ChXYFrIva3SFsp4AWcUR4w3OCA==
X-Received: by 2002:a17:906:144b:: with SMTP id
 q11mr28653316ejc.511.1596020359105; 
 Wed, 29 Jul 2020 03:59:19 -0700 (PDT)
Received: from [192.168.0.102] ([86.122.217.196])
 by smtp.gmail.com with ESMTPSA id s5sm134798ejv.67.2020.07.29.03.59.18
 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
 Wed, 29 Jul 2020 03:59:18 -0700 (PDT)
In-Reply-To: <7c08a3de16702600ea0c8ddc508bfe0b05d78e4a.1593605155.git.hugo.lefeuvre@neclab.eu>
To: minios-devel@lists.xen.org
From: Daniel Dinca <dincadaniel97@gmail.com>
Subject: Re: [UNIKRAFT/LIBMIMALLOC,v2] Initial port of mimalloc to Unikraft
Message-ID: <a56813b6-2c40-c43f-cfb1-92f060fa577b@gmail.com>
Date: Wed, 29 Jul 2020 13:59:17 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
Content-Type: multipart/alternative;
 boundary="------------793680EA1594B6F294C0E993"
Content-Language: en-US
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: dincadaniel97@gmail.com
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This is a multi-part message in MIME format.
--------------793680EA1594B6F294C0E993
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit

The main tree patch will need to be rebased before merge.

Otherwise looks good.

Reviewed-by: Daniel Dinca <dincadaniel97@gmail.com>


--------------793680EA1594B6F294C0E993
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit

<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p><span style="color: rgb(34, 34, 34); font-family: Arial,
        Helvetica, sans-serif; font-size: small; font-style: normal;
        font-variant-ligatures: normal; font-variant-caps: normal;
        font-weight: 400; letter-spacing: normal; orphans: 2;
        text-align: start; text-indent: 0px; text-transform: none;
        white-space: normal; widows: 2; word-spacing: 0px;
        -webkit-text-stroke-width: 0px; background-color: rgb(255, 255,
        255); text-decoration-style: initial; text-decoration-color:
        initial; display: inline !important; float: none;">The main tree
        patch will need to be rebased before merge.</span><br
        style="color: rgb(34, 34, 34); font-family: Arial, Helvetica,
        sans-serif; font-size: small; font-style: normal;
        font-variant-ligatures: normal; font-variant-caps: normal;
        font-weight: 400; letter-spacing: normal; orphans: 2;
        text-align: start; text-indent: 0px; text-transform: none;
        white-space: normal; widows: 2; word-spacing: 0px;
        -webkit-text-stroke-width: 0px; background-color: rgb(255, 255,
        255); text-decoration-style: initial; text-decoration-color:
        initial;">
      <br style="color: rgb(34, 34, 34); font-family: Arial, Helvetica,
        sans-serif; font-size: small; font-style: normal;
        font-variant-ligatures: normal; font-variant-caps: normal;
        font-weight: 400; letter-spacing: normal; orphans: 2;
        text-align: start; text-indent: 0px; text-transform: none;
        white-space: normal; widows: 2; word-spacing: 0px;
        -webkit-text-stroke-width: 0px; background-color: rgb(255, 255,
        255); text-decoration-style: initial; text-decoration-color:
        initial;">
      <span style="color: rgb(34, 34, 34); font-family: Arial,
        Helvetica, sans-serif; font-size: small; font-style: normal;
        font-variant-ligatures: normal; font-variant-caps: normal;
        font-weight: 400; letter-spacing: normal; orphans: 2;
        text-align: start; text-indent: 0px; text-transform: none;
        white-space: normal; widows: 2; word-spacing: 0px;
        -webkit-text-stroke-width: 0px; background-color: rgb(255, 255,
        255); text-decoration-style: initial; text-decoration-color:
        initial; display: inline !important; float: none;">Otherwise
        looks good.</span></p>
    <p><span style="color: rgb(34, 34, 34); font-family: Arial,
        Helvetica, sans-serif; font-size: small; font-style: normal;
        font-variant-ligatures: normal; font-variant-caps: normal;
        font-weight: 400; letter-spacing: normal; orphans: 2;
        text-align: start; text-indent: 0px; text-transform: none;
        white-space: normal; widows: 2; word-spacing: 0px;
        -webkit-text-stroke-width: 0px; background-color: rgb(255, 255,
        255); text-decoration-style: initial; text-decoration-color:
        initial; display: inline !important; float: none;"><span
          style="color: rgb(34, 34, 34); font-family: Arial, Helvetica,
          sans-serif; font-size: small; font-style: normal;
          font-variant-ligatures: normal; font-variant-caps: normal;
          font-weight: 400; letter-spacing: normal; orphans: 2;
          text-align: start; text-indent: 0px; text-transform: none;
          white-space: normal; widows: 2; word-spacing: 0px;
          -webkit-text-stroke-width: 0px; background-color: rgb(255,
          255, 255); text-decoration-style: initial;
          text-decoration-color: initial; display: inline !important;
          float: none;">Reviewed-by: Daniel Dinca</span>
        <a class="moz-txt-link-rfc2396E" href="mailto:dincadaniel97@gmail.com">&lt;dincadaniel97@gmail.com&gt;</a><br>
      </span></p>
  </body>
</html>

--------------793680EA1594B6F294C0E993--


From minios-devel-bounces@lists.xenproject.org Wed Jul 29 12:41:36 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 29 Jul 2020 12:41:36 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k0lOm-0004IL-T5; Wed, 29 Jul 2020 12:41:32 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=0vVE=BI=neclab.eu=simon.kuenzer@srs-us1.protection.inumbo.net>)
 id 1k0lOl-0004IG-Hs
 for minios-devel@lists.xenproject.org; Wed, 29 Jul 2020 12:41:31 +0000
X-Inumbo-ID: d23dc614-d198-11ea-8c53-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id d23dc614-d198-11ea-8c53-bc764e2007e4;
 Wed, 29 Jul 2020 12:41:28 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id BBBA4F2010;
 Wed, 29 Jul 2020 14:41:27 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id e5MTnbz5UZ9a; Wed, 29 Jul 2020 14:41:27 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 7DA42F2004
 for <minios-devel@lists.xenproject.org>; Wed, 29 Jul 2020 14:41:25 +0200 (CEST)
Received: from [10.7.1.42] (192.168.24.96) by puck.office.hd (192.168.24.91)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 29 Jul
 2020 14:41:24 +0200
Subject: Re: [UNIKRAFT PATCH v2 1/2] lib/ukallocregion: add region-based
 allocator
To: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>,
 <minios-devel@lists.xenproject.org>
References: <cover.1596012660.git.hugo.lefeuvre@neclab.eu>
 <1a8f3e5dbcb042237ab82db2a4746b09bc80b4a8.1596012660.git.hugo.lefeuvre@neclab.eu>
From: Simon Kuenzer <simon.kuenzer@neclab.eu>
Message-ID: <02b095cc-5e56-ef43-0e9b-3a3ee734935b@neclab.eu>
Date: Wed, 29 Jul 2020 14:41:23 +0200
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0)
 Gecko/20100101 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <1a8f3e5dbcb042237ab82db2a4746b09bc80b4a8.1596012660.git.hugo.lefeuvre@neclab.eu>
Content-Type: text/plain; charset="utf-8"; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: titania.office.hd (192.168.24.89) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Hugo,

two comment to malloc and  posix_memalign. Otherwise, the patch is fine.

Thanks,

Simon

On 29.07.20 10:55, Hugo Lefeuvre wrote:
> Add ukallocregion, a minimalist region-based allocator.
> 
> Note that deallocation is not supported. This makes sense because regions
> only allow for deallocation at region-granularity. In our case, this would
> imply the freeing of the entire heap, which is generally not possible.
> 
> Obviously, the lack of deallocation support makes ukallocregion a fairly
> bad general-purpose allocator. This allocator is interesting in that it
> offers maximum speed allocation and deallocation (bounded O(1), no
> bookkeeping). It can be used as a baseline for measurements (e.g., boot
> time) or as a first-level allocator in a nested context.
> 
> Refer to Gay & Aiken, `Memory management with explicit regions' (PLDI'98)
> for an introduction to region-based memory management.
> 
> Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> ---
>   lib/Makefile.uk                            |   1 +
>   lib/ukallocregion/Config.uk                |  12 ++
>   lib/ukallocregion/Makefile.uk              |   6 +
>   lib/ukallocregion/exportsyms.uk            |   1 +
>   lib/ukallocregion/include/uk/allocregion.h |  50 +++++++++
>   lib/ukallocregion/region.c                 | 172 +++++++++++++++++++++++++++++
>   6 files changed, 242 insertions(+)
>   create mode 100644 lib/ukallocregion/Config.uk
>   create mode 100644 lib/ukallocregion/Makefile.uk
>   create mode 100644 lib/ukallocregion/exportsyms.uk
>   create mode 100644 lib/ukallocregion/include/uk/allocregion.h
>   create mode 100644 lib/ukallocregion/region.c
> 
> diff --git a/lib/Makefile.uk b/lib/Makefile.uk
> index aa7e730..1f223d2 100644
> --- a/lib/Makefile.uk
> +++ b/lib/Makefile.uk
> @@ -14,6 +14,7 @@ $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uktimeconv))
>   $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/nolibc))
>   $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukalloc))
>   $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukallocbbuddy))
> +$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukallocregion))
>   $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uksched))
>   $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukschedcoop))
>   $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/fdt))
> diff --git a/lib/ukallocregion/Config.uk b/lib/ukallocregion/Config.uk
> new file mode 100644
> index 0000000..0012677
> --- /dev/null
> +++ b/lib/ukallocregion/Config.uk
> @@ -0,0 +1,12 @@
> +config LIBUKALLOCREGION
> +	bool "ukallocregion: Region-based allocator"
> +	default n
> +	select LIBNOLIBC if !HAVE_LIBC
> +	select LIBUKDEBUG
> +	select LIBUKALLOC
> +	help
> +	  Satisfy allocations as fast as possible, without bookkeeping. No
> +	  support for free(): when the end of the allocation pool is reached,
> +	  the allocator runs out-of-memory. This allocator is useful for
> +	  experimentation, as baseline, or as first-level allocator in a nested
> +	  context.
> diff --git a/lib/ukallocregion/Makefile.uk b/lib/ukallocregion/Makefile.uk
> new file mode 100644
> index 0000000..05a3d67
> --- /dev/null
> +++ b/lib/ukallocregion/Makefile.uk
> @@ -0,0 +1,6 @@
> +$(eval $(call addlib_s,libukallocregion,$(CONFIG_LIBUKALLOCREGION)))
> +
> +CINCLUDES-$(CONFIG_LIBUKALLOCREGION)	+= -I$(LIBUKALLOCREGION_BASE)/include
> +CXXINCLUDES-$(CONFIG_LIBUKALLOCREGION)	+= -I$(LIBUKALLOCREGION_BASE)/include
> +
> +LIBUKALLOCREGION_SRCS-y += $(LIBUKALLOCREGION_BASE)/region.c
> diff --git a/lib/ukallocregion/exportsyms.uk b/lib/ukallocregion/exportsyms.uk
> new file mode 100644
> index 0000000..481bc10
> --- /dev/null
> +++ b/lib/ukallocregion/exportsyms.uk
> @@ -0,0 +1 @@
> +uk_allocregion_init
> diff --git a/lib/ukallocregion/include/uk/allocregion.h b/lib/ukallocregion/include/uk/allocregion.h
> new file mode 100644
> index 0000000..863ef6c
> --- /dev/null
> +++ b/lib/ukallocregion/include/uk/allocregion.h
> @@ -0,0 +1,50 @@
> +/* SPDX-License-Identifier: BSD-3-Clause */
> +/*
> + * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> + *
> + * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation,
> + *                     All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + *
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in the
> + *    documentation and/or other materials provided with the distribution.
> + * 3. Neither the name of the copyright holder nor the names of its
> + *    contributors may be used to endorse or promote products derived from
> + *    this software without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#ifndef __LIBUKALLOCREGION_H__
> +#define __LIBUKALLOCREGION_H__
> +
> +#include <uk/alloc.h>
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +/* allocator initialization */
> +struct uk_alloc *uk_allocregion_init(void *base, size_t len);
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +#endif /* __LIBUKALLOCREGION_H__ */
> diff --git a/lib/ukallocregion/region.c b/lib/ukallocregion/region.c
> new file mode 100644
> index 0000000..8d2baec
> --- /dev/null
> +++ b/lib/ukallocregion/region.c
> @@ -0,0 +1,172 @@
> +/* SPDX-License-Identifier: BSD-3-Clause */
> +/*
> + * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> + *
> + * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation,
> + *                     All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + *
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in the
> + *    documentation and/or other materials provided with the distribution.
> + * 3. Neither the name of the copyright holder nor the names of its
> + *    contributors may be used to endorse or promote products derived from
> + *    this software without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +/* ukallocregion is a minimalist region implementation.
> + *
> + * Note that deallocation is not supported. This makes sense because regions
> + * only allow for deallocation at region-granularity. In our case, this would
> + * imply the freeing of the entire heap, which is generally not possible.
> + *
> + * Obviously, the lack of deallocation support makes ukallocregion a fairly bad
> + * general-purpose allocator. This allocator is interesting in that it offers
> + * maximum speed allocation and deallocation (no bookkeeping). It can be used as
> + * a baseline for measurements (e.g., boot time) or as a first-level allocator
> + * in a nested context.
> + *
> + * Refer to Gay & Aiken, `Memory management with explicit regions' (PLDI'98) for
> + * an introduction to region-based memory management.
> + */
> +
> +#include <uk/allocregion.h>
> +#include <uk/alloc_impl.h>
> +#include <uk/page.h>	/* round_pgup() */
> +
> +struct uk_allocregion {
> +	void *heap_top;
> +	void *heap_base;
> +};
> +
> +void *uk_allocregion_malloc(struct uk_alloc *a, size_t size)
> +{
> +	struct uk_allocregion *b;
> +	void *newbase, *prevbase;
> +
> +	UK_ASSERT(a != NULL);
> +
> +	b = (struct uk_allocregion *)&a->priv;
> +
> +	/* return aligned pointers: this is a requirement for some
> +	 * embedded systems archs, and more generally good for performance
> +	 */

Please check if there is space left when doing the alignment and return 
NULL otherwise. I would actually change the rest of the function to the 
follwing (I also call the variable now intptr, like you do with 
posix_memalign;... less touching of struct fields):

	/* ... */

	intptr = ALIGN_UP(((uintptr_t) b->heap_base)
                   (uintptr_t) sizeof(void *));
	if (intptr > b->heap_top
	    || intptr + size > b->heap_top)
		return NULL; /* ENOMEM */

	b->heap_base = (void *) (intptr + size)
	return intptr;
}

 > +	b->heap_base = (void *) ALIGN_UP(((uintptr_t) b->heap_base),
 > +					(uintptr_t) sizeof(void *));
> +
> +	prevbase = b->heap_base;
> +	newbase  = (void *) ((uintptr_t) b->heap_base + size);
> +
> +	UK_ASSERT(newbase >= b->heap_base);
> +	UK_ASSERT(newbase <= b->heap_top);
> +
> +	b->heap_base = newbase;
> +
> +	return prevbase;
> +}
> +
> +int uk_allocregion_posix_memalign(struct uk_alloc *a, void **memptr,
> +					size_t align, size_t size)
> +{
> +	struct uk_allocregion *b;
> +	uintptr_t intptr;
> +
> +	UK_ASSERT(a != NULL);
> +
> +	b = (struct uk_allocregion *)&a->priv;
> +
> +	/* align must be a power of two */
> +	UK_ASSERT(((align - 1) & align) == 0);
> +
> +	/* align must be larger than pointer size */
> +	UK_ASSERT((align % sizeof(void *)) == 0);
> +
> +	if (!size) {
> +		*memptr = NULL;
> +		return EINVAL;
> +	}
> +
> +	intptr = ALIGN_UP((uintptr_t) b->heap_base, (uintptr_t) align);
> +
> +	if (intptr > (uintptr_t) b->heap_top)

This if condition should actually include the requested size:

	if (intptr + size > (uintptr_t) b->heap_top

> +		return ENOMEM; /* out-of-memory * > +
> +	*memptr = (void *)intptr;
> +	b->heap_base = (void *)(intptr + size);
> +
> +	return 0;
> +}
> +
> +void uk_allocregion_free(struct uk_alloc *a __unused, void *ptr __unused)
> +{
> +	uk_pr_debug("%p: Releasing of memory is not supported by "
> +			"ukallocregion\n", a);
> +}
> +
> +int uk_allocregion_addmem(struct uk_alloc *a __unused, void *base __unused,
> +				size_t size __unused)
> +{
> +	/* TODO: support multiple regions */
> +	uk_pr_debug("%p: ukallocregion does not support multiple memory "
> +			"regions\n", a);
> +	return 0;
> +}
> +
> +struct uk_alloc *uk_allocregion_init(void *base, size_t len)
> +{
> +	struct uk_alloc *a;
> +	struct uk_allocregion *b;
> +	size_t metalen = sizeof(*a) + sizeof(*b);
> +
> +	/* TODO: ukallocregion does not support multiple memory regions yet.
> +	 * Because of the multiboot layout, the first region might be a single
> +	 * page, so we simply ignore it.
> +	 */
> +	if (len <= __PAGE_SIZE)
> +		return NULL;
> +
> +	/* enough space for allocator available? */
> +	if (metalen > len) {
> +		uk_pr_err("Not enough space for allocator: %"__PRIsz
> +			  " B required but only %"__PRIuptr" B usable\n",
> +			  metalen, len);
> +		return NULL;
> +	}
> +
> +	/* store allocator metadata on the heap, just before the memory pool */
> +	a = (struct uk_alloc *)base;
> +	b = (struct uk_allocregion *)&a->priv;
> +
> +	uk_pr_info("Initialize allocregion allocator @ 0x%"
> +		   __PRIuptr ", len %"__PRIsz"\n", (uintptr_t)a, len);
> +
> +	b->heap_top  = (void *)((uintptr_t) base + len);
> +	b->heap_base = (void *)((uintptr_t) base + metalen);
> +
> +	/* use exclusively "compat" wrappers for calloc, realloc, memalign,
> +	 * palloc and pfree as those do not add additional metadata.
> +	 */
> +	uk_alloc_init_malloc(a, uk_allocregion_malloc, uk_calloc_compat,
> +				uk_realloc_compat, uk_allocregion_free,
> +				uk_allocregion_posix_memalign,
> +				uk_memalign_compat, NULL);
> +
> +	return a;
> +}
> 


From minios-devel-bounces@lists.xenproject.org Wed Jul 29 12:42:56 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 29 Jul 2020 12:42:56 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k0lQ8-0004Jk-1U; Wed, 29 Jul 2020 12:42:56 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=0vVE=BI=neclab.eu=simon.kuenzer@srs-us1.protection.inumbo.net>)
 id 1k0lQ6-0004Jf-Q3
 for minios-devel@lists.xenproject.org; Wed, 29 Jul 2020 12:42:54 +0000
X-Inumbo-ID: 03bef4ec-d199-11ea-a9c1-12813bfff9fa
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 03bef4ec-d199-11ea-a9c1-12813bfff9fa;
 Wed, 29 Jul 2020 12:42:52 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id DACA5103941;
 Wed, 29 Jul 2020 14:42:50 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id zR7P6TJO2-hy; Wed, 29 Jul 2020 14:42:50 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id B68E1101371
 for <minios-devel@lists.xenproject.org>; Wed, 29 Jul 2020 14:42:50 +0200 (CEST)
Received: from [10.7.1.42] (192.168.24.96) by puck.office.hd (192.168.24.91)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 29 Jul
 2020 14:42:50 +0200
Subject: Re: [UNIKRAFT PATCH v2 2/2] lib/ukboot: initialize ukallocregion
To: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>,
 <minios-devel@lists.xenproject.org>
References: <cover.1596012660.git.hugo.lefeuvre@neclab.eu>
 <3de83ca5275a4730a56a4cf23b3065e3c1055a1d.1596012660.git.hugo.lefeuvre@neclab.eu>
From: Simon Kuenzer <simon.kuenzer@neclab.eu>
Message-ID: <efbffb70-c9ab-9dff-e8f1-0a8aeb2da825@neclab.eu>
Date: Wed, 29 Jul 2020 14:42:49 +0200
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0)
 Gecko/20100101 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <3de83ca5275a4730a56a4cf23b3065e3c1055a1d.1596012660.git.hugo.lefeuvre@neclab.eu>
Content-Type: text/plain; charset="utf-8"; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Thanks!

Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>

On 29.07.20 10:55, Hugo Lefeuvre wrote:
> Add menuconfig bindings to select a system-wide allocator.
> Initialize the selected allocator in ukboot.
> 
> Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> ---
>   lib/ukboot/Config.uk | 23 +++++++++++++++++++----
>   lib/ukboot/boot.c    | 19 +++++++++++++------
>   2 files changed, 32 insertions(+), 10 deletions(-)
> 
> diff --git a/lib/ukboot/Config.uk b/lib/ukboot/Config.uk
> index 841a876..07139e2 100644
> --- a/lib/ukboot/Config.uk
> +++ b/lib/ukboot/Config.uk
> @@ -17,8 +17,23 @@ if LIBUKBOOT
>   	int "Maximum number of arguments (max. size of argv)"
>   	default 60
>   
> -	config LIBUKBOOT_INITALLOC
> -	bool "Initialize ukallocbbuddy as allocator"
> -	default y
> -	select LIBUKALLOCBBUDDY
> +	choice LIBUKBOOT_INITALLOC
> +	prompt "Initialize memory allocator"
> +	default LIBUKBOOT_INITBBUDDY
> +
> +		config LIBUKBOOT_INITBBUDDY
> +		bool "Binary buddy allocator"
> +		select LIBUKALLOCBBUDDY
> +
> +		config LIBUKBOOT_INITREGION
> +		bool "Region allocator"
> +		select LIBUKALLOCREGION
> +		help
> +		  Satisfy allocation as fast as possible. No support for free().
> +		  Refer to help in ukallocregion for more information.
> +
> +		config LIBUKBOOT_NOALLOC
> +		bool "None"
> +
> +	endchoice
>   endif
> diff --git a/lib/ukboot/boot.c b/lib/ukboot/boot.c
> index e8a2ac7..4e749aa 100644
> --- a/lib/ukboot/boot.c
> +++ b/lib/ukboot/boot.c
> @@ -41,8 +41,10 @@
>   #include <stdio.h>
>   #include <errno.h>
>   
> -#if CONFIG_LIBUKALLOC && CONFIG_LIBUKALLOCBBUDDY && CONFIG_LIBUKBOOT_INITALLOC
> +#if CONFIG_LIBUKBOOT_INITBBUDDY
>   #include <uk/allocbbuddy.h>
> +#elif CONFIG_LIBUKBOOT_INITREGION
> +#include <uk/allocregion.h>
>   #endif
>   #if CONFIG_LIBUKSCHED
>   #include <uk/sched.h>
> @@ -178,7 +180,7 @@ void ukplat_entry(int argc, char *argv[])
>   #if CONFIG_LIBUKALLOC
>   	struct uk_alloc *a = NULL;
>   #endif
> -#if CONFIG_LIBUKALLOC && CONFIG_LIBUKALLOCBBUDDY && CONFIG_LIBUKBOOT_INITALLOC
> +#if !CONFIG_LIBUKBOOT_NOALLOC
>   	struct ukplat_memregion_desc md;
>   #endif
>   #if CONFIG_LIBUKSCHED
> @@ -205,9 +207,9 @@ void ukplat_entry(int argc, char *argv[])
>   	}
>   #endif /* CONFIG_LIBUKLIBPARAM */
>   
> -#if CONFIG_LIBUKALLOC && CONFIG_LIBUKALLOCBBUDDY && CONFIG_LIBUKBOOT_INITALLOC
> +#if !CONFIG_LIBUKBOOT_NOALLOC
>   	/* initialize memory allocator
> -	 * FIXME: ukallocbbuddy is hard-coded for now
> +	 * FIXME: allocators are hard-coded for now
>   	 */
>   	uk_pr_info("Initialize memory allocator...\n");
>   	ukplat_memregion_foreach(&md, UKPLAT_MEMRF_ALLOCATABLE) {
> @@ -226,10 +228,15 @@ void ukplat_entry(int argc, char *argv[])
>   		 * As soon we have an allocator, we simply add every
>   		 * subsequent region to it
>   		 */
> -		if (unlikely(!a))
> +		if (!a) {
> +#if CONFIG_LIBUKBOOT_INITBBUDDY
>   			a = uk_allocbbuddy_init(md.base, md.len);
> -		else
> +#elif CONFIG_LIBUKBOOT_INITREGION
> +			a = uk_allocregion_init(md.base, md.len);
> +#endif
> +		} else {
>   			uk_alloc_addmem(a, md.base, md.len);
> +		}
>   	}
>   	if (unlikely(!a))
>   		uk_pr_warn("No suitable memory region for memory allocator. Continue without heap\n");
> 


From minios-devel-bounces@lists.xenproject.org Wed Jul 29 12:50:49 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 29 Jul 2020 12:50:49 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k0lXj-00057t-La; Wed, 29 Jul 2020 12:50:47 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=qY7a=BI=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1k0lXj-00057n-0B
 for minios-devel@lists.xenproject.org; Wed, 29 Jul 2020 12:50:47 +0000
X-Inumbo-ID: 1e11e79a-d19a-11ea-8c57-bc764e2007e4
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 1e11e79a-d19a-11ea-8c57-bc764e2007e4;
 Wed, 29 Jul 2020 12:50:45 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 86EA5103941;
 Wed, 29 Jul 2020 14:50:44 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id gVrchUfVmjtV; Wed, 29 Jul 2020 14:50:44 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id 5A2DB101371
 for <minios-devel@lists.xenproject.org>; Wed, 29 Jul 2020 14:50:44 +0200 (CEST)
Received: from N-1237.office.hd (192.168.24.96) by titania.office.hd
 (192.168.24.89) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 29 Jul
 2020 14:50:44 +0200
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: <minios-devel@lists.xenproject.org>
Subject: [UNIKRAFT/LIBMIMALLOC PATCH v3] Initial port of libmimalloc
Date: Wed, 29 Jul 2020 14:50:38 +0200
Message-ID: <cover.1596026460.git.hugo.lefeuvre@neclab.eu>
X-Mailer: git-send-email 2.7.4
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi,

this is the initial port of the Mimalloc [0] general-purpose memory allocator
for Unikraft as an external library.

Changes since v2:
 - improve option names in Config.uk
 - fix minor mistakes in copyright headers
 - rebase main-tree.patch

Changes since v1:
 - add missing Signed-off line
 - fix errors/warnings reported by checkpatch
 - rename compile guards in include/uk/tlsf.h
 - add missing #include to main-tree.patch
 - fix typos in Makefile.uk copyright header

regards,
Hugo

[0] https://microsoft.github.io/mimalloc/

Hugo Lefeuvre (1):
  Initial port of mimalloc to Unikraft



From minios-devel-bounces@lists.xenproject.org Wed Jul 29 12:50:52 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 29 Jul 2020 12:50:52 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k0lXo-00058W-NH; Wed, 29 Jul 2020 12:50:52 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=qY7a=BI=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1k0lXn-00058M-Iq
 for minios-devel@lists.xenproject.org; Wed, 29 Jul 2020 12:50:51 +0000
X-Inumbo-ID: 2005deb2-d19a-11ea-a9c7-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 2005deb2-d19a-11ea-a9c7-12813bfff9fa;
 Wed, 29 Jul 2020 12:50:48 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id BEF37F2011;
 Wed, 29 Jul 2020 14:50:47 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id QJ62z4o_GBtq; Wed, 29 Jul 2020 14:50:47 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 90E89F2004
 for <minios-devel@lists.xenproject.org>; Wed, 29 Jul 2020 14:50:45 +0200 (CEST)
Received: from N-1237.office.hd (192.168.24.96) by titania.office.hd
 (192.168.24.89) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 29 Jul
 2020 14:50:45 +0200
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: <minios-devel@lists.xenproject.org>
Subject: [UNIKRAFT/LIBMIMALLOC PATCH v3] Initial port of mimalloc to Unikraft
Date: Wed, 29 Jul 2020 14:50:39 +0200
Message-ID: <c2fadb5bc56e21b25f304d21f962cc7ffcc41712.1596026460.git.hugo.lefeuvre@neclab.eu>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <cover.1596026460.git.hugo.lefeuvre@neclab.eu>
References: <cover.1596026460.git.hugo.lefeuvre@neclab.eu>
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
---
 Config.uk                                 |  16 ++
 Makefile.uk                               |  95 ++++++++++++
 README.md                                 |  13 ++
 glue.c                                    | 247 ++++++++++++++++++++++++++++++
 include/uk/mimalloc.h                     |  50 ++++++
 include/uk/mimalloc_impl.h                |  57 +++++++
 main-tree.patch                           |  39 +++++
 patches/adapt-to-unikraft-interface.patch | 160 +++++++++++++++++++
 8 files changed, 677 insertions(+)
 create mode 100644 Config.uk
 create mode 100644 Makefile.uk
 create mode 100644 README.md
 create mode 100644 glue.c
 create mode 100644 include/uk/mimalloc.h
 create mode 100644 include/uk/mimalloc_impl.h
 create mode 100644 main-tree.patch
 create mode 100644 patches/adapt-to-unikraft-interface.patch

diff --git a/Config.uk b/Config.uk
new file mode 100644
index 0000000..84f8aea
--- /dev/null
+++ b/Config.uk
@@ -0,0 +1,16 @@
+menuconfig LIBMIMALLOC
+	bool "mimalloc: a compact general purpose allocator with excellent performance"
+	default n
+	select LIBUKSCHED
+	select LIBNEWLIBC
+	select LIBPOSIX_SYSINFO
+	select LIBPTHREAD_EMBEDDED
+	select LIBUKALLOCREGION
+if LIBMIMALLOC
+	config MIMALLOC_DEBUG
+		int "Debug level"
+		default 0
+	config MIMALLOC_ASSERT
+		bool "Enable assertions"
+		default n
+endif
diff --git a/Makefile.uk b/Makefile.uk
new file mode 100644
index 0000000..911ec7a
--- /dev/null
+++ b/Makefile.uk
@@ -0,0 +1,95 @@
+#  libmimalloc Makefile.uk
+#
+#  Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+#
+#  Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation,
+#                      All rights reserved.
+#
+#  Redistribution and use in source and binary forms, with or without
+#  modification, are permitted provided that the following conditions
+#  are met:
+#
+#  1. Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+#  2. Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in the
+#     documentation and/or other materials provided with the distribution.
+#  3. Neither the name of the copyright holder nor the names of its
+#     contributors may be used to endorse or promote products derived from
+#     this software without specific prior written permission.
+#
+#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+#  POSSIBILITY OF SUCH DAMAGE.
+#
+
+################################################################################
+# Library registration
+################################################################################
+$(eval $(call addlib_s,libmimalloc,$(CONFIG_LIBMIMALLOC)))
+
+################################################################################
+# Sources
+################################################################################
+LIBMIMALLOC_VERSION=1.6.1
+LIBMIMALLOC_URL=https://github.com/microsoft/mimalloc/archive/v$(LIBMIMALLOC_VERSION).zip
+LIBMIMALLOC_DIR=mimalloc-$(LIBMIMALLOC_VERSION)
+
+LIBMIMALLOC_PATCHDIR=$(LIBMIMALLOC_BASE)/patches
+$(eval $(call fetch,libmimalloc,$(LIBMIMALLOC_URL),v$(LIBMIMALLOC_VERSION).zip))
+$(eval $(call patch,libmimalloc,$(LIBMIMALLOC_PATCHDIR),$(LIBMIMALLOC_DIR)))
+
+################################################################################
+# Helpers
+################################################################################
+LIBMIMALLOC=$(LIBMIMALLOC_ORIGIN)/$(LIBMIMALLOC_DIR)
+
+################################################################################
+# Library includes
+################################################################################
+
+CINCLUDES-$(CONFIG_LIBMIMALLOC) += -I$(LIBMIMALLOC_BASE) \
+                                   -I$(LIBMIMALLOC_BASE)/include \
+                                   -I$(LIBMIMALLOC)/include
+
+################################################################################
+# Global flags
+################################################################################
+LIBMIMALLOC_GLOBAL_FLAGS-$(CONFIG_MIMALLOC_ASSERT) += -DNDEBUG
+LIBMIMALLOC_CFLAGS-y += -Wall -Wextra -Wno-unknown-pragmas -fvisibility=hidden \
+			-Wno-invalid-memory-model \
+			-D'MI_DEBUG=${CONFIG_MIMALLOC_DEBUG}'\
+			${LIBMIMALLOC_GLOBAL_FLAGS-n}
+
+################################################################################
+# Glue code
+################################################################################
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC_BASE)/glue.c
+
+################################################################################
+# Sources
+################################################################################
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/stats.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/random.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/os.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/arena.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/region.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/segment.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/page.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/alloc.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/alloc-aligned.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/alloc-posix.c
+#LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/bitmap.inc.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/heap.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/options.c
+LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/init.c
+#LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/alloc-override.c
+#LIBMIMALLOC_SRCS-y += $(LIBMIMALLOC)/src/page-queue.c
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..a43779c
--- /dev/null
+++ b/README.md
@@ -0,0 +1,13 @@
+Mimalloc for Unikraft
+=====================
+
+This is the port of the Mimalloc [0] general-purpose memory allocator for
+Unikraft as an external library.
+
+How to use this allocator in your unikernel application:
+
+- apply main-tree.patch to the main tree
+- select "Mimalloc" in `ukboot > Default memory allocator`
+- pass at least 256MiB of memory to the unikernel
+
+[0] https://microsoft.github.io/mimalloc/
diff --git a/glue.c b/glue.c
new file mode 100644
index 0000000..1d23ec5
--- /dev/null
+++ b/glue.c
@@ -0,0 +1,247 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation,
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <uk/mimalloc_impl.h>
+#include <uk/mimalloc.h>
+#include <mimalloc.h>
+#include <mimalloc-internal.h> // _mi_options_init()
+#include <uk/alloc_impl.h>
+#include <uk/print.h>
+#include <uk/allocregion.h>
+#include <uk/thread.h>	// uk_thread_current()
+#include <uk/page.h>	// round_pgup()
+#include <uk/sched.h>	// uk_mimalloc_init_internal()
+
+/* Notes of Unikraft's Mimalloc port:
+ *
+ * 1. Minimum heap size required: 256MiB, which is the size of an arena.
+ *
+ * 2. Maximum number of Mimalloc instances:
+ *    Mimalloc's current code base relies strongly on static variables. Instead
+ *    of heavily patching it (and maintaining the patches) we simply restrict
+ *    the maximum number of Mimalloc instances to one.
+ *
+ * 3. Early boot time allocator:
+ *    Mimalloc can only be initialized after pthread. However the early boot
+ *    process including pthread's initialization itself requires a functioning
+ *    memory allocator. We solve this problem by relying on ukallocregion during
+ *    the early boot time. The transition to Mimalloc is triggered as soon as
+ *    _tls_ready() returns true. We expect that this won't cause significant
+ *    memory leak since memory allocated during EBT is typically not freed.
+ *
+ * 4. Transition EBT allocator -> Mimalloc:
+ *    We transition as soon as the TLS has been allocated and the %fs register
+ *    set. This is checked at every EBT allocation by inspecting
+ *    uk_thread_current()->prv which typically points to the thread local
+ *    storage. Since memory allocations might happen during Mimalloc's
+ *    initialization itself (e.g. calls to malloc() by pthread) the early boot
+ *    time allocator continues to satisfy requests until Mimalloc is ready
+ *    (after mi_process_load() returned).
+ */
+
+/* Minimum heap size (size of an arena)
+ * TODO: can Mimalloc be reconfigured/patched to lower/remove this limitation?
+ */
+#define MIN_HEAP_SIZE 268435456L
+
+/* Rely on ukallocregion to satisfy boot-time allocations */
+static struct uk_alloc *__region_alloc;
+
+/* make sure that the transition from boot-time allocation to Mimalloc is done
+ * only once: calls to malloc() during Mimalloc initialization should be
+ * satisfied using the boot-time allocator.
+ */
+static int __initialized;
+
+static inline int _tls_ready(void)
+{
+	/* Is the thread local storage ready? */
+	struct uk_thread *current = uk_thread_current();
+
+	return current && current->prv != NULL;
+}
+
+/* boot-time malloc interface */
+
+static void uk_mimalloc_init_internal(struct uk_alloc *a);
+
+/* NOTE: not static, this is used in the mimalloc code base to request memory
+ * "from the OS"
+ */
+void *uk_mimalloc_region_malloc(struct uk_alloc *a, size_t size)
+{
+	/* detect call from main thread to leave boot time mode */
+	if (_tls_ready() && !__initialized) {
+		uk_pr_debug("%s: leaving early boot-time allocation mode\n",
+			   uk_thread_current()->name);
+		__initialized = 1;
+		uk_mimalloc_init_internal(a);
+
+		/* satisfy request using new malloc interface */
+		return uk_malloc(a, size);
+	}
+
+	uk_pr_debug("allocating %zu from region allocator\n", size);
+
+	return uk_malloc(__region_alloc, size);
+}
+
+static int uk_mimalloc_region_posix_memalign(struct uk_alloc *a __unused,
+					     void **memptr, size_t align,
+					     size_t size)
+{
+	uk_pr_debug("allocating %zu aligned at %zu from region allocator\n",
+			size, align);
+
+	return uk_posix_memalign(__region_alloc, memptr, align, size);
+}
+
+static void uk_mimalloc_region_free(struct uk_alloc *a __unused, void *ptr)
+{
+	uk_pr_info("attempt to free memory during early boot time\n");
+
+	return uk_free(__region_alloc, ptr);
+}
+
+/* malloc interface */
+
+static void *uk_mimalloc_malloc(struct uk_alloc *a __unused, size_t size)
+{
+	return mi_malloc(size);
+}
+
+static void uk_mimalloc_free(struct uk_alloc *a __unused, void *ptr)
+{
+	mi_free(ptr);
+}
+
+static void *uk_mimalloc_realloc(struct uk_alloc *a __unused, void *ptr,
+				 size_t size)
+{
+	return mi_realloc(ptr, size);
+}
+
+static void *uk_mimalloc_calloc(struct uk_alloc *a __unused, size_t nelem,
+				size_t elem_size)
+{
+	return mi_calloc(nelem, elem_size);
+}
+
+static int uk_mimalloc_posix_memalign(struct uk_alloc *a __unused, void **p,
+				      size_t alignment, size_t size)
+{
+	return mi_posix_memalign(p, alignment, size);
+}
+
+static void *uk_mimalloc_memalign(struct uk_alloc *a __unused, size_t alignment,
+				  size_t size)
+{
+	return mi_memalign(alignment, size);
+}
+
+static void uk_mimalloc_init_internal(struct uk_alloc *a)
+{
+	mi_process_load();
+
+	/* rebind interface to actual malloc interface */
+	(a)->malloc         = uk_mimalloc_malloc;
+	(a)->calloc         = uk_mimalloc_calloc;
+	(a)->realloc        = uk_mimalloc_realloc;
+	(a)->posix_memalign = uk_mimalloc_posix_memalign;
+	(a)->memalign       = uk_mimalloc_memalign;
+	(a)->free           = uk_mimalloc_free;
+
+	/* delay this after interface rebinding to avoid using early boot
+	 * time memory.
+	 */
+	_mi_options_init();
+
+	uk_pr_info("Successfully initialized Mimalloc\n");
+}
+
+struct uk_alloc *uk_mimalloc_init(void *base, size_t len)
+{
+	struct uk_alloc *a;
+	size_t metalen;
+
+	/* TODO: This Mimalloc port does not support multiple memory regions
+	 * yet. Because of the multiboot layout, the first region might be a
+	 * single page, so we simply ignore it.
+	 */
+	if (len <= __PAGE_SIZE)
+		return NULL;
+
+	if (__region_alloc) {
+		uk_pr_err("mimalloc already initialized "
+			  "(max number of instances: 1)\n");
+		return NULL;
+	}
+
+	metalen = round_pgup(sizeof(*a));
+
+	/* enough space for allocator available? */
+	if (metalen > len) {
+		uk_pr_err("Not enough space for allocator: %" __PRIsz
+			  " B required but only %" __PRIuptr" B usable\n",
+			  metalen, len);
+		return NULL;
+	}
+
+	/* enough space to allocate arena? */
+	if (len < MIN_HEAP_SIZE) {
+		/* Note: we don't exit, but calls to malloc will return NULL. */
+		uk_pr_err("Not enough space to allocate arena: %lu bytes "
+			  "required but only %" __PRIsz" bytes usable\n",
+			  268435456L, len);
+	}
+
+	/* store allocator metadata on the heap, just before the memory pool */
+	a = (struct uk_alloc *)base;
+	uk_pr_info("Initialize mimalloc allocator (early boot time mode) @ 0x%"
+		   __PRIuptr ", len %"__PRIsz"\n", (uintptr_t)a, len);
+
+	/* register mimalloc *before* initializing the region allocator: in all
+	 * cases we want Mimalloc to be the default allocator.
+	 * FIXME: add uk_allocregion_init_noregister() that initializes a region
+	 * allocator without registering it.
+	 */
+	uk_alloc_init_malloc(a, uk_mimalloc_region_malloc, uk_calloc_compat,
+				uk_realloc_compat, uk_mimalloc_region_free,
+				uk_mimalloc_region_posix_memalign,
+				uk_memalign_compat, NULL);
+
+	__region_alloc = uk_allocregion_init((void *)((uintptr_t) base +
+						metalen), len - metalen);
+
+	return a;
+}
diff --git a/include/uk/mimalloc.h b/include/uk/mimalloc.h
new file mode 100644
index 0000000..eadeae1
--- /dev/null
+++ b/include/uk/mimalloc.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation,
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __LIBMIMALLOC_H__
+#define __LIBMIMALLOC_H__
+
+#include <uk/alloc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* allocator initialization */
+struct uk_alloc *uk_mimalloc_init(void *base, size_t len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LIBMIMALLOC_H__ */
diff --git a/include/uk/mimalloc_impl.h b/include/uk/mimalloc_impl.h
new file mode 100644
index 0000000..6b237cd
--- /dev/null
+++ b/include/uk/mimalloc_impl.h
@@ -0,0 +1,57 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation,
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * NOTE: These functions are not part of the public ukmimalloc API.
+ * This interface is used in the mimalloc code base to request memory
+ * "from the OS".
+ */
+
+#ifndef __LIBMIMALLOC_IMPL_H__
+#define __LIBMIMALLOC_IMPL_H__
+
+#include <uk/alloc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* region allocator */
+
+void *uk_mimalloc_region_malloc(struct uk_alloc *a, size_t size);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LIBMIMALLOC_IMPL_H__ */
diff --git a/main-tree.patch b/main-tree.patch
new file mode 100644
index 0000000..40f0268
--- /dev/null
+++ b/main-tree.patch
@@ -0,0 +1,39 @@
+From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+Subject: Add Mimalloc entry to the menuconfig and initialize it
+diff --git a/lib/ukboot/Config.uk b/lib/ukboot/Config.uk
+index 07139e2b..cfc306d7 100644
+--- a/lib/ukboot/Config.uk
++++ b/lib/ukboot/Config.uk
+@@ -32,6 +32,10 @@ if LIBUKBOOT
+ 		  Satisfy allocation as fast as possible. No support for free().
+ 		  Refer to help in ukallocregion for more information.
+ 
++		config LIBUKBOOT_INITMIMALLOC
++		bool "Mimalloc"
++		select LIBMIMALLOC
++
+ 		config LIBUKBOOT_NOALLOC
+ 		bool "None"
+ 
+diff --git a/lib/ukboot/boot.c b/lib/ukboot/boot.c
+index 4e749aa5..a400749d 100644
+--- a/lib/ukboot/boot.c
++++ b/lib/ukboot/boot.c
+@@ -45,6 +45,8 @@
+ #include <uk/allocbbuddy.h>
+ #elif CONFIG_LIBUKBOOT_INITREGION
+ #include <uk/allocregion.h>
++#elif CONFIG_LIBUKBOOT_INITMIMALLOC
++#include <uk/mimalloc.h>
+ #endif
+ #if CONFIG_LIBUKSCHED
+ #include <uk/sched.h>
+@@ -233,6 +235,8 @@ void ukplat_entry(int argc, char *argv[])
+ 			a = uk_allocbbuddy_init(md.base, md.len);
+ #elif CONFIG_LIBUKBOOT_INITREGION
+ 			a = uk_allocregion_init(md.base, md.len);
++#elif CONFIG_LIBUKBOOT_INITMIMALLOC
++			a = uk_mimalloc_init(md.base, md.len);
+ #endif
+ 		} else {
+ 			uk_alloc_addmem(a, md.base, md.len);
diff --git a/patches/adapt-to-unikraft-interface.patch b/patches/adapt-to-unikraft-interface.patch
new file mode 100644
index 0000000..8a41454
--- /dev/null
+++ b/patches/adapt-to-unikraft-interface.patch
@@ -0,0 +1,160 @@
+From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+Subject: Adapt Mimalloc interface to Unikraft
+ - expose mi_process_load() since it is called in the glue code
+ - remove useless ATOMIC_VAR_INIT calls since they cause problems with newlib
+ - request memory from the OS via mi_unikraft_heap_grow(), which relies
+   internally on uk_mimalloc_region_malloc(), our underlying region manager
+ - at the time where Mimalloc was ported, the support for memory protections
+   by Unikraft was unclear, so it is here disabled. A future update of this
+   port should address this.
+diff -urNp mimalloc-orig/include/mimalloc.h mimalloc-patched/include/mimalloc.h
+--- mimalloc-orig/include/mimalloc.h	2020-02-17 19:10:22.000000000 +0100
++++ mimalloc-patched/include/mimalloc.h	2020-06-24 10:16:31.439830260 +0200
+@@ -144,6 +144,7 @@ mi_decl_export void mi_stats_print(void*
+ mi_decl_export void mi_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept;
+ 
+ mi_decl_export void mi_process_init(void)     mi_attr_noexcept;
++mi_decl_export void mi_process_load(void)     mi_attr_noexcept;
+ mi_decl_export void mi_thread_init(void)      mi_attr_noexcept;
+ mi_decl_export void mi_thread_done(void)      mi_attr_noexcept;
+ mi_decl_export void mi_thread_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept;
+diff -urNp mimalloc-orig/src/init.c mimalloc-patched/src/init.c
+--- mimalloc-orig/src/init.c	2020-02-17 19:10:22.000000000 +0100
++++ mimalloc-patched/src/init.c	2020-06-24 10:16:31.443830218 +0200
+@@ -25,8 +25,8 @@ const mi_page_t _mi_page_empty = {
+   0,       // used
+   0,       // xblock_size
+   NULL,    // local_free
+-  ATOMIC_VAR_INIT(0), // xthread_free
+-  ATOMIC_VAR_INIT(0), // xheap
++  0, // xthread_free
++  0, // xheap
+   NULL, NULL
+ };
+ 
+@@ -91,7 +91,7 @@ const mi_heap_t _mi_heap_empty = {
+   NULL,
+   MI_SMALL_PAGES_EMPTY,
+   MI_PAGE_QUEUES_EMPTY,
+-  ATOMIC_VAR_INIT(NULL),
++  NULL,
+   0,                // tid
+   0,                // cookie
+   { 0, 0 },         // keys
+@@ -125,7 +125,7 @@ mi_heap_t _mi_heap_main = {
+   &tld_main,
+   MI_SMALL_PAGES_EMPTY,
+   MI_PAGE_QUEUES_EMPTY,
+-  ATOMIC_VAR_INIT(NULL),
++  NULL,
+   0,                // thread id
+   0,                // initial cookie
+   { 0, 0 },         // the key of the main heap can be fixed (unlike page keys that need to be secure!)
+@@ -430,7 +430,7 @@ static void mi_allocator_done() {
+ #endif
+ 
+ // Called once by the process loader
+-static void mi_process_load(void) {
++void mi_process_load(void) {
+   mi_heap_main_init();
+   #if defined(MI_TLS_RECURSE_GUARD)
+   volatile mi_heap_t* dummy = _mi_heap_default; // access TLS to allocate it before setting tls_initialized to true;
+@@ -438,7 +438,9 @@ static void mi_process_load(void) {
+   #endif
+   os_preloading = false;
+   atexit(&mi_process_done);
+-  _mi_options_init();
++  // delay _mi_options_init() after initialization as it allocates a lot of
++  // memory and we want to avoid doing that with the early boot time allocator
++  //_mi_options_init();
+   mi_process_init();
+   //mi_stats_reset();-
+   if (mi_redirected) _mi_verbose_message("malloc is redirected.\n");
+@@ -519,6 +521,8 @@ static void mi_process_done(void) {
+   }
+   static bool mi_initialized = _mi_process_init();
+ 
++#elif defined(CONFIG_LIBMIMALLOC)
++  // called by uk_init_mimalloc()
+ #elif defined(__GNUC__) || defined(__clang__)
+   // GCC,Clang: use the constructor attribute
+   static void __attribute__((constructor)) _mi_process_init(void) {
+diff -urNp mimalloc-orig/src/os.c mimalloc-patched/src/os.c
+--- mimalloc-orig/src/os.c	2020-02-17 19:10:22.000000000 +0100
++++ mimalloc-patched/src/os.c	2020-06-24 14:44:56.745158608 +0200
+@@ -14,11 +14,14 @@ terms of the MIT license. A copy of the
+ 
+ #include <string.h>  // strerror
+ 
++#include <uk/mimalloc_impl.h> // uk_mimalloc_region_malloc
+ 
+ #if defined(_WIN32)
+ #include <windows.h>
+ #elif defined(__wasi__)
+ // stdlib.h is all we need, and has already been included in mimalloc.h
++#elif defined(CONFIG_LIBMIMALLOC)
++#include <unistd.h>    // sysconf
+ #else
+ #include <sys/mman.h>  // mmap
+ #include <unistd.h>    // sysconf
+@@ -184,8 +187,8 @@ static bool mi_os_mem_free(void* addr, s
+   bool err = false;
+ #if defined(_WIN32)
+   err = (VirtualFree(addr, 0, MEM_RELEASE) == 0);
+-#elif defined(__wasi__)
+-  err = 0; // WebAssembly's heap cannot be shrunk
++#elif defined(__wasi__) || defined(CONFIG_LIBMIMALLOC)
++  err = 0; // WebAssembly's/Unikraft's heap cannot be shrunk
+ #else
+   err = (munmap(addr, size) == -1);
+ #endif
+@@ -272,6 +275,10 @@ static void* mi_wasm_heap_grow(size_t si
+   }
+   return (void*)aligned_base;
+ }
++#elif defined(CONFIG_LIBMIMALLOC)
++static void* mi_unikraft_heap_grow(size_t size, size_t try_alignment) {
++  return uk_mimalloc_region_malloc(NULL, size);
++}
+ #else
+ #define MI_OS_USE_MMAP
+ static void* mi_unix_mmapx(void* addr, size_t size, size_t try_alignment, int protect_flags, int flags, int fd) {
+@@ -450,6 +457,9 @@ static void* mi_os_mem_alloc(size_t size
+   #elif defined(__wasi__)
+     *is_large = false;
+     p = mi_wasm_heap_grow(size, try_alignment);
++  #elif defined(CONFIG_LIBMIMALLOC)
++    *is_large = false;
++    p = mi_unikraft_heap_grow(size, try_alignment);
+   #else
+     int protect_flags = (commit ? (PROT_WRITE | PROT_READ) : PROT_NONE);
+     p = mi_unix_mmap(NULL, size, try_alignment, protect_flags, false, allow_large, is_large);
+@@ -638,8 +648,8 @@ static bool mi_os_commitx(void* addr, si
+     BOOL ok = VirtualFree(start, csize, MEM_DECOMMIT);
+     err = (ok ? 0 : GetLastError());
+   }
+-  #elif defined(__wasi__)
+-  // WebAssembly guests can't control memory protection
++  #elif defined(__wasi__) || defined(CONFIG_LIBMIMALLOC)
++  // Unikraft/WebAssembly guests can't control memory protection
+   #elif defined(MAP_FIXED)
+   if (!commit) {
+     // use mmap with MAP_FIXED to discard the existing memory (and reduce commit charge)
+@@ -714,7 +724,7 @@ static bool mi_os_resetx(void* addr, siz
+     advice = MADV_DONTNEED;
+     err = madvise(start, csize, advice);
+   }
+-#elif defined(__wasi__)
++#elif defined(__wasi__) || defined(CONFIG_LIBMIMALLOC)
+   int err = 0;
+ #else
+   int err = madvise(start, csize, MADV_DONTNEED);
+@@ -768,7 +778,7 @@ static  bool mi_os_protectx(void* addr,
+   DWORD oldprotect = 0;
+   BOOL ok = VirtualProtect(start, csize, protect ? PAGE_NOACCESS : PAGE_READWRITE, &oldprotect);
+   err = (ok ? 0 : GetLastError());
+-#elif defined(__wasi__)
++#elif defined(__wasi__) || defined(CONFIG_LIBMIMALLOC)
+   err = 0;
+ #else
+   err = mprotect(start, csize, protect ? PROT_NONE : (PROT_READ | PROT_WRITE));
-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Wed Jul 29 12:57:22 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 29 Jul 2020 12:57:22 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k0le4-0005Gs-AI; Wed, 29 Jul 2020 12:57:20 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=B61f=BI=gmail.com=dincadaniel97@srs-us1.protection.inumbo.net>)
 id 1k0le2-0005Gn-Uq
 for minios-devel@lists.xen.org; Wed, 29 Jul 2020 12:57:19 +0000
X-Inumbo-ID: 0610ccf0-d19b-11ea-8c57-bc764e2007e4
Received: from mail-io1-xd41.google.com (unknown [2607:f8b0:4864:20::d41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 0610ccf0-d19b-11ea-8c57-bc764e2007e4;
 Wed, 29 Jul 2020 12:57:14 +0000 (UTC)
Received: by mail-io1-xd41.google.com with SMTP id w12so10759578iom.4
 for <minios-devel@lists.xen.org>; Wed, 29 Jul 2020 05:57:14 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
 bh=9jzci8ZU6OznwrdYfWsc88wb8oT+eYlZ9sbGZxGDenQ=;
 b=t2ZonFBMjjF3ViYR9bQvQqOm52DhDvKh1bRfECbxiCoMrhT/GMqlrUxtXVqqDqAFaH
 aSaoXz6wMlnaKNRR4D0uJLvmvq+AAb1MU+xkrmlg+2FCIllfUa/pa4H3jlJqh4Ny/rIZ
 gDDlJY8FW4xLUhGiCPiPniS2Dj2YO3zDgJSk7TSFh8PsoB/yqqpU5E7a4T3A67o9YE7M
 n4I1L7xF8Jn2eIHf9wjoKeQlIjcZ8rBNNLxKGgHmWzzwK/ZfslmC0nwbW3f65eI/VdJ3
 ll69LzlITuFS2CbAQIxTaI4NYTfrTWsRZOAK5PEt9I6GXRLLpUiK5UdtWTZ+gfXWp1MH
 uILA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:references:in-reply-to:from:date
 :message-id:subject:to;
 bh=9jzci8ZU6OznwrdYfWsc88wb8oT+eYlZ9sbGZxGDenQ=;
 b=dZtxSO1CFd08rPtmkCeFpL/lbhhGKq5aDNMtehidfyD+EBP+AyxyMbn7/8vWcxodwx
 Gh7oblSv/It6tb0VRAmyfO4yBrPPinl9DLUzjVaKxKUX7H0PyPZfdFIr3KZV5BbHYKsT
 71ztwrQnQ/wmPILxtpLzsIAauas9XyLBXW3+tLDA8OcIBzRSgDmkrfXqZpRIUz9PZeGE
 0qcuRmYmr31gBCtoK1frS4Y+LQdzPzuxlcX5oC2aX1SKFV7LvzHhpjbstR1eww7c4OBV
 007BvATEVkUmp++ZlCbhb83WdPgpAmSatgLZc1Bq1DbYLaq3J+jG+yoNIxwbcP5DO1zJ
 eEVg==
X-Gm-Message-State: AOAM533szBcAZQ6oJ8gVO76tIPH/WR2x2Lo7cY/i5h9ZlvoNjVONAuYg
 jaC+qliVUZ8/tj3O/LItRLzdn1nIdbzC8yM6DFVS9GDabQ0=
X-Google-Smtp-Source: ABdhPJy8VC7EDt89R/7WcJCkI5/oi/OXEmViPd0f1GonuvaZPmbLSxHpA3MQYtQiXxtgYcsVyI2l3LjxJLd/jVe4DX8=
X-Received: by 2002:a6b:d31a:: with SMTP id s26mr33998090iob.48.1596027433540; 
 Wed, 29 Jul 2020 05:57:13 -0700 (PDT)
MIME-Version: 1.0
References: <cover.1596026460.git.hugo.lefeuvre@neclab.eu>
 <c2fadb5bc56e21b25f304d21f962cc7ffcc41712.1596026460.git.hugo.lefeuvre@neclab.eu>
In-Reply-To: <c2fadb5bc56e21b25f304d21f962cc7ffcc41712.1596026460.git.hugo.lefeuvre@neclab.eu>
From: Daniel Dinca <dincadaniel97@gmail.com>
Date: Wed, 29 Jul 2020 15:57:02 +0300
Message-ID: <CALjJXS4X6mDRv5C_NZGhaCJp0g0V0ZDYjvXQFNE=cMgYkJYN9A@mail.gmail.com>
Subject: Re: [UNIKRAFT/LIBMIMALLOC PATCH v3] Initial port of mimalloc to
 Unikraft
To: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>, minios-devel@lists.xen.org
Content-Type: multipart/alternative; boundary="0000000000003a633a05ab9418f2"
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

--0000000000003a633a05ab9418f2
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

The main tree patch will need to be rebased before merge.
Otherwise looks good.

Reviewed-by: Daniel Dinca <dincadaniel97@gmail.com>
<dincadaniel97@gmail.com>


=C3=8En mie., 29 iul. 2020 la 15:51, Hugo Lefeuvre <hugo.lefeuvre@neclab.eu=
> a
scris:

> Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> ---
>  Config.uk                                 |  16 ++
>  Makefile.uk                               |  95 ++++++++++++
>  README.md                                 |  13 ++
>  glue.c                                    | 247
> ++++++++++++++++++++++++++++++
>  include/uk/mimalloc.h                     |  50 ++++++
>  include/uk/mimalloc_impl.h                |  57 +++++++
>  main-tree.patch                           |  39 +++++
>  patches/adapt-to-unikraft-interface.patch | 160 +++++++++++++++++++
>  8 files changed, 677 insertions(+)
>  create mode 100644 Config.uk
>  create mode 100644 Makefile.uk
>  create mode 100644 README.md
>  create mode 100644 glue.c
>  create mode 100644 include/uk/mimalloc.h
>  create mode 100644 include/uk/mimalloc_impl.h
>  create mode 100644 main-tree.patch
>  create mode 100644 patches/adapt-to-unikraft-interface.patch
>
> diff --git a/Config.uk b/Config.uk
> new file mode 100644
> index 0000000..84f8aea
> --- /dev/null
> +++ b/Config.uk
> @@ -0,0 +1,16 @@
> +menuconfig LIBMIMALLOC
> +       bool "mimalloc: a compact general purpose allocator with excellen=
t
> performance"
> +       default n
> +       select LIBUKSCHED
> +       select LIBNEWLIBC
> +       select LIBPOSIX_SYSINFO
> +       select LIBPTHREAD_EMBEDDED
> +       select LIBUKALLOCREGION
> +if LIBMIMALLOC
> +       config MIMALLOC_DEBUG
> +               int "Debug level"
> +               default 0
> +       config MIMALLOC_ASSERT
> +               bool "Enable assertions"
> +               default n
> +endif
> diff --git a/Makefile.uk b/Makefile.uk
> new file mode 100644
> index 0000000..911ec7a
> --- /dev/null
> +++ b/Makefile.uk
> @@ -0,0 +1,95 @@
> +#  libmimalloc Makefile.uk
> +#
> +#  Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> +#
> +#  Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation,
> +#                      All rights reserved.
> +#
> +#  Redistribution and use in source and binary forms, with or without
> +#  modification, are permitted provided that the following conditions
> +#  are met:
> +#
> +#  1. Redistributions of source code must retain the above copyright
> +#     notice, this list of conditions and the following disclaimer.
> +#  2. Redistributions in binary form must reproduce the above copyright
> +#     notice, this list of conditions and the following disclaimer in th=
e
> +#     documentation and/or other materials provided with the distributio=
n.
> +#  3. Neither the name of the copyright holder nor the names of its
> +#     contributors may be used to endorse or promote products derived fr=
om
> +#     this software without specific prior written permission.
> +#
> +#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> "AS IS"
> +#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
> THE
> +#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
> PURPOSE
> +#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTOR=
S
> BE
> +#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> +#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> +#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
> BUSINESS
> +#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER =
IN
> +#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS=
E)
> +#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED O=
F
> THE
> +#  POSSIBILITY OF SUCH DAMAGE.
> +#
> +
>
> +########################################################################=
########
> +# Library registration
>
> +########################################################################=
########
> +$(eval $(call addlib_s,libmimalloc,$(CONFIG_LIBMIMALLOC)))
> +
>
> +########################################################################=
########
> +# Sources
>
> +########################################################################=
########
> +LIBMIMALLOC_VERSION=3D1.6.1
> +LIBMIMALLOC_URL=3D
> https://github.com/microsoft/mimalloc/archive/v$(LIBMIMALLOC_VERSION).zip
> +LIBMIMALLOC_DIR=3Dmimalloc-$(LIBMIMALLOC_VERSION)
> +
> +LIBMIMALLOC_PATCHDIR=3D$(LIBMIMALLOC_BASE)/patches
> +$(eval $(call
> fetch,libmimalloc,$(LIBMIMALLOC_URL),v$(LIBMIMALLOC_VERSION).zip))
> +$(eval $(call
> patch,libmimalloc,$(LIBMIMALLOC_PATCHDIR),$(LIBMIMALLOC_DIR)))
> +
>
> +########################################################################=
########
> +# Helpers
>
> +########################################################################=
########
> +LIBMIMALLOC=3D$(LIBMIMALLOC_ORIGIN)/$(LIBMIMALLOC_DIR)
> +
>
> +########################################################################=
########
> +# Library includes
>
> +########################################################################=
########
> +
> +CINCLUDES-$(CONFIG_LIBMIMALLOC) +=3D -I$(LIBMIMALLOC_BASE) \
> +                                   -I$(LIBMIMALLOC_BASE)/include \
> +                                   -I$(LIBMIMALLOC)/include
> +
>
> +########################################################################=
########
> +# Global flags
>
> +########################################################################=
########
> +LIBMIMALLOC_GLOBAL_FLAGS-$(CONFIG_MIMALLOC_ASSERT) +=3D -DNDEBUG
> +LIBMIMALLOC_CFLAGS-y +=3D -Wall -Wextra -Wno-unknown-pragmas
> -fvisibility=3Dhidden \
> +                       -Wno-invalid-memory-model \
> +                       -D'MI_DEBUG=3D${CONFIG_MIMALLOC_DEBUG}'\
> +                       ${LIBMIMALLOC_GLOBAL_FLAGS-n}
> +
>
> +########################################################################=
########
> +# Glue code
>
> +########################################################################=
########
> +LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC_BASE)/glue.c
> +
>
> +########################################################################=
########
> +# Sources
>
> +########################################################################=
########
> +LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/stats.c
> +LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/random.c
> +LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/os.c
> +LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/arena.c
> +LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/region.c
> +LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/segment.c
> +LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/page.c
> +LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/alloc.c
> +LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/alloc-aligned.c
> +LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/alloc-posix.c
> +#LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/bitmap.inc.c
> +LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/heap.c
> +LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/options.c
> +LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/init.c
> +#LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/alloc-override.c
> +#LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/page-queue.c
> diff --git a/README.md b/README.md
> new file mode 100644
> index 0000000..a43779c
> --- /dev/null
> +++ b/README.md
> @@ -0,0 +1,13 @@
> +Mimalloc for Unikraft
> +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> +
> +This is the port of the Mimalloc [0] general-purpose memory allocator fo=
r
> +Unikraft as an external library.
> +
> +How to use this allocator in your unikernel application:
> +
> +- apply main-tree.patch to the main tree
> +- select "Mimalloc" in `ukboot > Default memory allocator`
> +- pass at least 256MiB of memory to the unikernel
> +
> +[0] https://microsoft.github.io/mimalloc/
> diff --git a/glue.c b/glue.c
> new file mode 100644
> index 0000000..1d23ec5
> --- /dev/null
> +++ b/glue.c
> @@ -0,0 +1,247 @@
> +/* SPDX-License-Identifier: BSD-3-Clause */
> +/*
> + * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> + *
> + * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation,
> + *                     All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + *
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in th=
e
> + *    documentation and/or other materials provided with the distributio=
n.
> + * 3. Neither the name of the copyright holder nor the names of its
> + *    contributors may be used to endorse or promote products derived fr=
om
> + *    this software without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> "AS IS"
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
> THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
> PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTOR=
S
> BE
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
> BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER =
IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS=
E)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED O=
F
> THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#include <uk/mimalloc_impl.h>
> +#include <uk/mimalloc.h>
> +#include <mimalloc.h>
> +#include <mimalloc-internal.h> // _mi_options_init()
> +#include <uk/alloc_impl.h>
> +#include <uk/print.h>
> +#include <uk/allocregion.h>
> +#include <uk/thread.h> // uk_thread_current()
> +#include <uk/page.h>   // round_pgup()
> +#include <uk/sched.h>  // uk_mimalloc_init_internal()
> +
> +/* Notes of Unikraft's Mimalloc port:
> + *
> + * 1. Minimum heap size required: 256MiB, which is the size of an arena.
> + *
> + * 2. Maximum number of Mimalloc instances:
> + *    Mimalloc's current code base relies strongly on static variables.
> Instead
> + *    of heavily patching it (and maintaining the patches) we simply
> restrict
> + *    the maximum number of Mimalloc instances to one.
> + *
> + * 3. Early boot time allocator:
> + *    Mimalloc can only be initialized after pthread. However the early
> boot
> + *    process including pthread's initialization itself requires a
> functioning
> + *    memory allocator. We solve this problem by relying on ukallocregio=
n
> during
> + *    the early boot time. The transition to Mimalloc is triggered as
> soon as
> + *    _tls_ready() returns true. We expect that this won't cause
> significant
> + *    memory leak since memory allocated during EBT is typically not
> freed.
> + *
> + * 4. Transition EBT allocator -> Mimalloc:
> + *    We transition as soon as the TLS has been allocated and the %fs
> register
> + *    set. This is checked at every EBT allocation by inspecting
> + *    uk_thread_current()->prv which typically points to the thread loca=
l
> + *    storage. Since memory allocations might happen during Mimalloc's
> + *    initialization itself (e.g. calls to malloc() by pthread) the earl=
y
> boot
> + *    time allocator continues to satisfy requests until Mimalloc is rea=
dy
> + *    (after mi_process_load() returned).
> + */
> +
> +/* Minimum heap size (size of an arena)
> + * TODO: can Mimalloc be reconfigured/patched to lower/remove this
> limitation?
> + */
> +#define MIN_HEAP_SIZE 268435456L
> +
> +/* Rely on ukallocregion to satisfy boot-time allocations */
> +static struct uk_alloc *__region_alloc;
> +
> +/* make sure that the transition from boot-time allocation to Mimalloc i=
s
> done
> + * only once: calls to malloc() during Mimalloc initialization should be
> + * satisfied using the boot-time allocator.
> + */
> +static int __initialized;
> +
> +static inline int _tls_ready(void)
> +{
> +       /* Is the thread local storage ready? */
> +       struct uk_thread *current =3D uk_thread_current();
> +
> +       return current && current->prv !=3D NULL;
> +}
> +
> +/* boot-time malloc interface */
> +
> +static void uk_mimalloc_init_internal(struct uk_alloc *a);
> +
> +/* NOTE: not static, this is used in the mimalloc code base to request
> memory
> + * "from the OS"
> + */
> +void *uk_mimalloc_region_malloc(struct uk_alloc *a, size_t size)
> +{
> +       /* detect call from main thread to leave boot time mode */
> +       if (_tls_ready() && !__initialized) {
> +               uk_pr_debug("%s: leaving early boot-time allocation
> mode\n",
> +                          uk_thread_current()->name);
> +               __initialized =3D 1;
> +               uk_mimalloc_init_internal(a);
> +
> +               /* satisfy request using new malloc interface */
> +               return uk_malloc(a, size);
> +       }
> +
> +       uk_pr_debug("allocating %zu from region allocator\n", size);
> +
> +       return uk_malloc(__region_alloc, size);
> +}
> +
> +static int uk_mimalloc_region_posix_memalign(struct uk_alloc *a __unused=
,
> +                                            void **memptr, size_t align,
> +                                            size_t size)
> +{
> +       uk_pr_debug("allocating %zu aligned at %zu from region
> allocator\n",
> +                       size, align);
> +
> +       return uk_posix_memalign(__region_alloc, memptr, align, size);
> +}
> +
> +static void uk_mimalloc_region_free(struct uk_alloc *a __unused, void
> *ptr)
> +{
> +       uk_pr_info("attempt to free memory during early boot time\n");
> +
> +       return uk_free(__region_alloc, ptr);
> +}
> +
> +/* malloc interface */
> +
> +static void *uk_mimalloc_malloc(struct uk_alloc *a __unused, size_t size=
)
> +{
> +       return mi_malloc(size);
> +}
> +
> +static void uk_mimalloc_free(struct uk_alloc *a __unused, void *ptr)
> +{
> +       mi_free(ptr);
> +}
> +
> +static void *uk_mimalloc_realloc(struct uk_alloc *a __unused, void *ptr,
> +                                size_t size)
> +{
> +       return mi_realloc(ptr, size);
> +}
> +
> +static void *uk_mimalloc_calloc(struct uk_alloc *a __unused, size_t nele=
m,
> +                               size_t elem_size)
> +{
> +       return mi_calloc(nelem, elem_size);
> +}
> +
> +static int uk_mimalloc_posix_memalign(struct uk_alloc *a __unused, void
> **p,
> +                                     size_t alignment, size_t size)
> +{
> +       return mi_posix_memalign(p, alignment, size);
> +}
> +
> +static void *uk_mimalloc_memalign(struct uk_alloc *a __unused, size_t
> alignment,
> +                                 size_t size)
> +{
> +       return mi_memalign(alignment, size);
> +}
> +
> +static void uk_mimalloc_init_internal(struct uk_alloc *a)
> +{
> +       mi_process_load();
> +
> +       /* rebind interface to actual malloc interface */
> +       (a)->malloc         =3D uk_mimalloc_malloc;
> +       (a)->calloc         =3D uk_mimalloc_calloc;
> +       (a)->realloc        =3D uk_mimalloc_realloc;
> +       (a)->posix_memalign =3D uk_mimalloc_posix_memalign;
> +       (a)->memalign       =3D uk_mimalloc_memalign;
> +       (a)->free           =3D uk_mimalloc_free;
> +
> +       /* delay this after interface rebinding to avoid using early boot
> +        * time memory.
> +        */
> +       _mi_options_init();
> +
> +       uk_pr_info("Successfully initialized Mimalloc\n");
> +}
> +
> +struct uk_alloc *uk_mimalloc_init(void *base, size_t len)
> +{
> +       struct uk_alloc *a;
> +       size_t metalen;
> +
> +       /* TODO: This Mimalloc port does not support multiple memory
> regions
> +        * yet. Because of the multiboot layout, the first region might b=
e
> a
> +        * single page, so we simply ignore it.
> +        */
> +       if (len <=3D __PAGE_SIZE)
> +               return NULL;
> +
> +       if (__region_alloc) {
> +               uk_pr_err("mimalloc already initialized "
> +                         "(max number of instances: 1)\n");
> +               return NULL;
> +       }
> +
> +       metalen =3D round_pgup(sizeof(*a));
> +
> +       /* enough space for allocator available? */
> +       if (metalen > len) {
> +               uk_pr_err("Not enough space for allocator: %" __PRIsz
> +                         " B required but only %" __PRIuptr" B usable\n"=
,
> +                         metalen, len);
> +               return NULL;
> +       }
> +
> +       /* enough space to allocate arena? */
> +       if (len < MIN_HEAP_SIZE) {
> +               /* Note: we don't exit, but calls to malloc will return
> NULL. */
> +               uk_pr_err("Not enough space to allocate arena: %lu bytes =
"
> +                         "required but only %" __PRIsz" bytes usable\n",
> +                         268435456L, len);
> +       }
> +
> +       /* store allocator metadata on the heap, just before the memory
> pool */
> +       a =3D (struct uk_alloc *)base;
> +       uk_pr_info("Initialize mimalloc allocator (early boot time mode) =
@
> 0x%"
> +                  __PRIuptr ", len %"__PRIsz"\n", (uintptr_t)a, len);
> +
> +       /* register mimalloc *before* initializing the region allocator:
> in all
> +        * cases we want Mimalloc to be the default allocator.
> +        * FIXME: add uk_allocregion_init_noregister() that initializes a
> region
> +        * allocator without registering it.
> +        */
> +       uk_alloc_init_malloc(a, uk_mimalloc_region_malloc,
> uk_calloc_compat,
> +                               uk_realloc_compat, uk_mimalloc_region_fre=
e,
> +                               uk_mimalloc_region_posix_memalign,
> +                               uk_memalign_compat, NULL);
> +
> +       __region_alloc =3D uk_allocregion_init((void *)((uintptr_t) base =
+
> +                                               metalen), len - metalen);
> +
> +       return a;
> +}
> diff --git a/include/uk/mimalloc.h b/include/uk/mimalloc.h
> new file mode 100644
> index 0000000..eadeae1
> --- /dev/null
> +++ b/include/uk/mimalloc.h
> @@ -0,0 +1,50 @@
> +/* SPDX-License-Identifier: BSD-3-Clause */
> +/*
> + * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> + *
> + * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation,
> + *                     All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + *
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in th=
e
> + *    documentation and/or other materials provided with the distributio=
n.
> + * 3. Neither the name of the copyright holder nor the names of its
> + *    contributors may be used to endorse or promote products derived fr=
om
> + *    this software without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> "AS IS"
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
> THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
> PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTOR=
S
> BE
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
> BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER =
IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS=
E)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED O=
F
> THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#ifndef __LIBMIMALLOC_H__
> +#define __LIBMIMALLOC_H__
> +
> +#include <uk/alloc.h>
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +/* allocator initialization */
> +struct uk_alloc *uk_mimalloc_init(void *base, size_t len);
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +#endif /* __LIBMIMALLOC_H__ */
> diff --git a/include/uk/mimalloc_impl.h b/include/uk/mimalloc_impl.h
> new file mode 100644
> index 0000000..6b237cd
> --- /dev/null
> +++ b/include/uk/mimalloc_impl.h
> @@ -0,0 +1,57 @@
> +/* SPDX-License-Identifier: BSD-3-Clause */
> +/*
> + * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> + *
> + * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation,
> + *                     All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + *
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in th=
e
> + *    documentation and/or other materials provided with the distributio=
n.
> + * 3. Neither the name of the copyright holder nor the names of its
> + *    contributors may be used to endorse or promote products derived fr=
om
> + *    this software without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> "AS IS"
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
> THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
> PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTOR=
S
> BE
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
> BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER =
IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS=
E)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED O=
F
> THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +/*
> + * NOTE: These functions are not part of the public ukmimalloc API.
> + * This interface is used in the mimalloc code base to request memory
> + * "from the OS".
> + */
> +
> +#ifndef __LIBMIMALLOC_IMPL_H__
> +#define __LIBMIMALLOC_IMPL_H__
> +
> +#include <uk/alloc.h>
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +/* region allocator */
> +
> +void *uk_mimalloc_region_malloc(struct uk_alloc *a, size_t size);
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +#endif /* __LIBMIMALLOC_IMPL_H__ */
> diff --git a/main-tree.patch b/main-tree.patch
> new file mode 100644
> index 0000000..40f0268
> --- /dev/null
> +++ b/main-tree.patch
> @@ -0,0 +1,39 @@
> +From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> +Subject: Add Mimalloc entry to the menuconfig and initialize it
> +diff --git a/lib/ukboot/Config.uk b/lib/ukboot/Config.uk
> +index 07139e2b..cfc306d7 100644
> +--- a/lib/ukboot/Config.uk
> ++++ b/lib/ukboot/Config.uk
> +@@ -32,6 +32,10 @@ if LIBUKBOOT
> +                 Satisfy allocation as fast as possible. No support for
> free().
> +                 Refer to help in ukallocregion for more information.
> +
> ++              config LIBUKBOOT_INITMIMALLOC
> ++              bool "Mimalloc"
> ++              select LIBMIMALLOC
> ++
> +               config LIBUKBOOT_NOALLOC
> +               bool "None"
> +
> +diff --git a/lib/ukboot/boot.c b/lib/ukboot/boot.c
> +index 4e749aa5..a400749d 100644
> +--- a/lib/ukboot/boot.c
> ++++ b/lib/ukboot/boot.c
> +@@ -45,6 +45,8 @@
> + #include <uk/allocbbuddy.h>
> + #elif CONFIG_LIBUKBOOT_INITREGION
> + #include <uk/allocregion.h>
> ++#elif CONFIG_LIBUKBOOT_INITMIMALLOC
> ++#include <uk/mimalloc.h>
> + #endif
> + #if CONFIG_LIBUKSCHED
> + #include <uk/sched.h>
> +@@ -233,6 +235,8 @@ void ukplat_entry(int argc, char *argv[])
> +                       a =3D uk_allocbbuddy_init(md.base, md.len);
> + #elif CONFIG_LIBUKBOOT_INITREGION
> +                       a =3D uk_allocregion_init(md.base, md.len);
> ++#elif CONFIG_LIBUKBOOT_INITMIMALLOC
> ++                      a =3D uk_mimalloc_init(md.base, md.len);
> + #endif
> +               } else {
> +                       uk_alloc_addmem(a, md.base, md.len);
> diff --git a/patches/adapt-to-unikraft-interface.patch
> b/patches/adapt-to-unikraft-interface.patch
> new file mode 100644
> index 0000000..8a41454
> --- /dev/null
> +++ b/patches/adapt-to-unikraft-interface.patch
> @@ -0,0 +1,160 @@
> +From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> +Subject: Adapt Mimalloc interface to Unikraft
> + - expose mi_process_load() since it is called in the glue code
> + - remove useless ATOMIC_VAR_INIT calls since they cause problems with
> newlib
> + - request memory from the OS via mi_unikraft_heap_grow(), which relies
> +   internally on uk_mimalloc_region_malloc(), our underlying region
> manager
> + - at the time where Mimalloc was ported, the support for memory
> protections
> +   by Unikraft was unclear, so it is here disabled. A future update of
> this
> +   port should address this.
> +diff -urNp mimalloc-orig/include/mimalloc.h
> mimalloc-patched/include/mimalloc.h
> +--- mimalloc-orig/include/mimalloc.h   2020-02-17 19:10:22.000000000 +01=
00
> ++++ mimalloc-patched/include/mimalloc.h        2020-06-24
> 10:16:31.439830260 +0200
> +@@ -144,6 +144,7 @@ mi_decl_export void mi_stats_print(void*
> + mi_decl_export void mi_stats_print_out(mi_output_fun* out, void* arg)
> mi_attr_noexcept;
> +
> + mi_decl_export void mi_process_init(void)     mi_attr_noexcept;
> ++mi_decl_export void mi_process_load(void)     mi_attr_noexcept;
> + mi_decl_export void mi_thread_init(void)      mi_attr_noexcept;
> + mi_decl_export void mi_thread_done(void)      mi_attr_noexcept;
> + mi_decl_export void mi_thread_stats_print_out(mi_output_fun* out, void*
> arg) mi_attr_noexcept;
> +diff -urNp mimalloc-orig/src/init.c mimalloc-patched/src/init.c
> +--- mimalloc-orig/src/init.c   2020-02-17 19:10:22.000000000 +0100
> ++++ mimalloc-patched/src/init.c        2020-06-24 10:16:31.443830218 +02=
00
> +@@ -25,8 +25,8 @@ const mi_page_t _mi_page_empty =3D {
> +   0,       // used
> +   0,       // xblock_size
> +   NULL,    // local_free
> +-  ATOMIC_VAR_INIT(0), // xthread_free
> +-  ATOMIC_VAR_INIT(0), // xheap
> ++  0, // xthread_free
> ++  0, // xheap
> +   NULL, NULL
> + };
> +
> +@@ -91,7 +91,7 @@ const mi_heap_t _mi_heap_empty =3D {
> +   NULL,
> +   MI_SMALL_PAGES_EMPTY,
> +   MI_PAGE_QUEUES_EMPTY,
> +-  ATOMIC_VAR_INIT(NULL),
> ++  NULL,
> +   0,                // tid
> +   0,                // cookie
> +   { 0, 0 },         // keys
> +@@ -125,7 +125,7 @@ mi_heap_t _mi_heap_main =3D {
> +   &tld_main,
> +   MI_SMALL_PAGES_EMPTY,
> +   MI_PAGE_QUEUES_EMPTY,
> +-  ATOMIC_VAR_INIT(NULL),
> ++  NULL,
> +   0,                // thread id
> +   0,                // initial cookie
> +   { 0, 0 },         // the key of the main heap can be fixed (unlike
> page keys that need to be secure!)
> +@@ -430,7 +430,7 @@ static void mi_allocator_done() {
> + #endif
> +
> + // Called once by the process loader
> +-static void mi_process_load(void) {
> ++void mi_process_load(void) {
> +   mi_heap_main_init();
> +   #if defined(MI_TLS_RECURSE_GUARD)
> +   volatile mi_heap_t* dummy =3D _mi_heap_default; // access TLS to
> allocate it before setting tls_initialized to true;
> +@@ -438,7 +438,9 @@ static void mi_process_load(void) {
> +   #endif
> +   os_preloading =3D false;
> +   atexit(&mi_process_done);
> +-  _mi_options_init();
> ++  // delay _mi_options_init() after initialization as it allocates a lo=
t
> of
> ++  // memory and we want to avoid doing that with the early boot time
> allocator
> ++  //_mi_options_init();
> +   mi_process_init();
> +   //mi_stats_reset();-
> +   if (mi_redirected) _mi_verbose_message("malloc is redirected.\n");
> +@@ -519,6 +521,8 @@ static void mi_process_done(void) {
> +   }
> +   static bool mi_initialized =3D _mi_process_init();
> +
> ++#elif defined(CONFIG_LIBMIMALLOC)
> ++  // called by uk_init_mimalloc()
> + #elif defined(__GNUC__) || defined(__clang__)
> +   // GCC,Clang: use the constructor attribute
> +   static void __attribute__((constructor)) _mi_process_init(void) {
> +diff -urNp mimalloc-orig/src/os.c mimalloc-patched/src/os.c
> +--- mimalloc-orig/src/os.c     2020-02-17 19:10:22.000000000 +0100
> ++++ mimalloc-patched/src/os.c  2020-06-24 14:44:56.745158608 +0200
> +@@ -14,11 +14,14 @@ terms of the MIT license. A copy of the
> +
> + #include <string.h>  // strerror
> +
> ++#include <uk/mimalloc_impl.h> // uk_mimalloc_region_malloc
> +
> + #if defined(_WIN32)
> + #include <windows.h>
> + #elif defined(__wasi__)
> + // stdlib.h is all we need, and has already been included in mimalloc.h
> ++#elif defined(CONFIG_LIBMIMALLOC)
> ++#include <unistd.h>    // sysconf
> + #else
> + #include <sys/mman.h>  // mmap
> + #include <unistd.h>    // sysconf
> +@@ -184,8 +187,8 @@ static bool mi_os_mem_free(void* addr, s
> +   bool err =3D false;
> + #if defined(_WIN32)
> +   err =3D (VirtualFree(addr, 0, MEM_RELEASE) =3D=3D 0);
> +-#elif defined(__wasi__)
> +-  err =3D 0; // WebAssembly's heap cannot be shrunk
> ++#elif defined(__wasi__) || defined(CONFIG_LIBMIMALLOC)
> ++  err =3D 0; // WebAssembly's/Unikraft's heap cannot be shrunk
> + #else
> +   err =3D (munmap(addr, size) =3D=3D -1);
> + #endif
> +@@ -272,6 +275,10 @@ static void* mi_wasm_heap_grow(size_t si
> +   }
> +   return (void*)aligned_base;
> + }
> ++#elif defined(CONFIG_LIBMIMALLOC)
> ++static void* mi_unikraft_heap_grow(size_t size, size_t try_alignment) {
> ++  return uk_mimalloc_region_malloc(NULL, size);
> ++}
> + #else
> + #define MI_OS_USE_MMAP
> + static void* mi_unix_mmapx(void* addr, size_t size, size_t
> try_alignment, int protect_flags, int flags, int fd) {
> +@@ -450,6 +457,9 @@ static void* mi_os_mem_alloc(size_t size
> +   #elif defined(__wasi__)
> +     *is_large =3D false;
> +     p =3D mi_wasm_heap_grow(size, try_alignment);
> ++  #elif defined(CONFIG_LIBMIMALLOC)
> ++    *is_large =3D false;
> ++    p =3D mi_unikraft_heap_grow(size, try_alignment);
> +   #else
> +     int protect_flags =3D (commit ? (PROT_WRITE | PROT_READ) : PROT_NON=
E);
> +     p =3D mi_unix_mmap(NULL, size, try_alignment, protect_flags, false,
> allow_large, is_large);
> +@@ -638,8 +648,8 @@ static bool mi_os_commitx(void* addr, si
> +     BOOL ok =3D VirtualFree(start, csize, MEM_DECOMMIT);
> +     err =3D (ok ? 0 : GetLastError());
> +   }
> +-  #elif defined(__wasi__)
> +-  // WebAssembly guests can't control memory protection
> ++  #elif defined(__wasi__) || defined(CONFIG_LIBMIMALLOC)
> ++  // Unikraft/WebAssembly guests can't control memory protection
> +   #elif defined(MAP_FIXED)
> +   if (!commit) {
> +     // use mmap with MAP_FIXED to discard the existing memory (and
> reduce commit charge)
> +@@ -714,7 +724,7 @@ static bool mi_os_resetx(void* addr, siz
> +     advice =3D MADV_DONTNEED;
> +     err =3D madvise(start, csize, advice);
> +   }
> +-#elif defined(__wasi__)
> ++#elif defined(__wasi__) || defined(CONFIG_LIBMIMALLOC)
> +   int err =3D 0;
> + #else
> +   int err =3D madvise(start, csize, MADV_DONTNEED);
> +@@ -768,7 +778,7 @@ static  bool mi_os_protectx(void* addr,
> +   DWORD oldprotect =3D 0;
> +   BOOL ok =3D VirtualProtect(start, csize, protect ? PAGE_NOACCESS :
> PAGE_READWRITE, &oldprotect);
> +   err =3D (ok ? 0 : GetLastError());
> +-#elif defined(__wasi__)
> ++#elif defined(__wasi__) || defined(CONFIG_LIBMIMALLOC)
> +   err =3D 0;
> + #else
> +   err =3D mprotect(start, csize, protect ? PROT_NONE : (PROT_READ |
> PROT_WRITE));
> --
> 2.7.4
>
>
>

--0000000000003a633a05ab9418f2
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div class=3D"gmail-gs" style=3D"margin:0=
px;padding:0px 0px 20px;width:1503px;font-family:Roboto,RobotoDraft,Helveti=
ca,Arial,sans-serif;font-size:medium"><div class=3D"gmail-"><div id=3D"gmai=
l-:nj" class=3D"gmail-ii gmail-gt" style=3D"font-size:0.875rem;direction:lt=
r;margin:8px 0px 0px;padding:0px"><div id=3D"gmail-:ne" class=3D"gmail-a3s =
gmail-aXjCH" style=3D"overflow:hidden;font-variant-numeric:normal;font-vari=
ant-east-asian:normal;font-stretch:normal;font-size:small;line-height:1.5;f=
ont-family:Arial,Helvetica,sans-serif"><div><span class=3D"gmail-im" style=
=3D"color:rgb(80,0,80)"><p><span style=3D"color:rgb(34,34,34)">The main tre=
e patch will need to be rebased before merge.</span><br style=3D"color:rgb(=
34,34,34)"><span style=3D"color:rgb(34,34,34)">Otherwise looks good.</span>=
</p></span><p>Reviewed-by: Daniel Dinca=C2=A0<a href=3D"mailto:dincadaniel9=
7@gmail.com" target=3D"_blank">&lt;dincadaniel97@gmail.com&gt;</a><br></p><=
div class=3D"gmail-yj6qo"></div><div class=3D"gmail-adL"></div></div><div c=
lass=3D"gmail-adL"></div></div></div><div class=3D"gmail-hi" style=3D"borde=
r-bottom-left-radius:1px;border-bottom-right-radius:1px;padding:0px;width:a=
uto;background:rgb(242,242,242);margin:0px"></div></div></div><br class=3D"=
gmail-Apple-interchange-newline"></div><br><div class=3D"gmail_quote"><div =
dir=3D"ltr" class=3D"gmail_attr">=C3=8En mie., 29 iul. 2020 la 15:51, Hugo =
Lefeuvre &lt;<a href=3D"mailto:hugo.lefeuvre@neclab.eu">hugo.lefeuvre@necla=
b.eu</a>&gt; a scris:<br></div><blockquote class=3D"gmail_quote" style=3D"m=
argin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left=
:1ex">Signed-off-by: Hugo Lefeuvre &lt;<a href=3D"mailto:hugo.lefeuvre@necl=
ab.eu" target=3D"_blank">hugo.lefeuvre@neclab.eu</a>&gt;<br>
---<br>
=C2=A0Config.uk=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|=C2=A0 16 ++<br=
>
=C2=A0Makefile.uk=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|=C2=A0 95 +++++++++=
+++<br>
=C2=A0README.md=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|=C2=A0 13 ++<br=
>
=C2=A0glue.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | 247 ++++++=
++++++++++++++++++++++++<br>
=C2=A0include/uk/mimalloc.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0|=C2=A0 50 ++++++<br>
=C2=A0include/uk/mimalloc_impl.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 |=C2=A0 57 +++++++<br>
=C2=A0main-tree.patch=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|=C2=A0 39 +++++<br>
=C2=A0patches/adapt-to-unikraft-interface.patch | 160 +++++++++++++++++++<b=
r>
=C2=A08 files changed, 677 insertions(+)<br>
=C2=A0create mode 100644 Config.uk<br>
=C2=A0create mode 100644 Makefile.uk<br>
=C2=A0create mode 100644 README.md<br>
=C2=A0create mode 100644 glue.c<br>
=C2=A0create mode 100644 include/uk/mimalloc.h<br>
=C2=A0create mode 100644 include/uk/mimalloc_impl.h<br>
=C2=A0create mode 100644 main-tree.patch<br>
=C2=A0create mode 100644 patches/adapt-to-unikraft-interface.patch<br>
<br>
diff --git a/Config.uk b/Config.uk<br>
new file mode 100644<br>
index 0000000..84f8aea<br>
--- /dev/null<br>
+++ b/Config.uk<br>
@@ -0,0 +1,16 @@<br>
+menuconfig LIBMIMALLOC<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0bool &quot;mimalloc: a compact general purpose =
allocator with excellent performance&quot;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0default n<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0select LIBUKSCHED<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0select LIBNEWLIBC<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0select LIBPOSIX_SYSINFO<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0select LIBPTHREAD_EMBEDDED<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0select LIBUKALLOCREGION<br>
+if LIBMIMALLOC<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0config MIMALLOC_DEBUG<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0int &quot;Debug lev=
el&quot;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0default 0<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0config MIMALLOC_ASSERT<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0bool &quot;Enable a=
ssertions&quot;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0default n<br>
+endif<br>
diff --git a/Makefile.uk b/Makefile.uk<br>
new file mode 100644<br>
index 0000000..911ec7a<br>
--- /dev/null<br>
+++ b/Makefile.uk<br>
@@ -0,0 +1,95 @@<br>
+#=C2=A0 libmimalloc Makefile.uk<br>
+#<br>
+#=C2=A0 Authors: Hugo Lefeuvre &lt;<a href=3D"mailto:hugo.lefeuvre@neclab.=
eu" target=3D"_blank">hugo.lefeuvre@neclab.eu</a>&gt;<br>
+#<br>
+#=C2=A0 Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation,=
<br>
+#=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 All rights reserved.<br>
+#<br>
+#=C2=A0 Redistribution and use in source and binary forms, with or without=
<br>
+#=C2=A0 modification, are permitted provided that the following conditions=
<br>
+#=C2=A0 are met:<br>
+#<br>
+#=C2=A0 1. Redistributions of source code must retain the above copyright<=
br>
+#=C2=A0 =C2=A0 =C2=A0notice, this list of conditions and the following dis=
claimer.<br>
+#=C2=A0 2. Redistributions in binary form must reproduce the above copyrig=
ht<br>
+#=C2=A0 =C2=A0 =C2=A0notice, this list of conditions and the following dis=
claimer in the<br>
+#=C2=A0 =C2=A0 =C2=A0documentation and/or other materials provided with th=
e distribution.<br>
+#=C2=A0 3. Neither the name of the copyright holder nor the names of its<b=
r>
+#=C2=A0 =C2=A0 =C2=A0contributors may be used to endorse or promote produc=
ts derived from<br>
+#=C2=A0 =C2=A0 =C2=A0this software without specific prior written permissi=
on.<br>
+#<br>
+#=C2=A0 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTOR=
S &quot;AS IS&quot;<br>
+#=C2=A0 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED =
TO, THE<br>
+#=C2=A0 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR=
 PURPOSE<br>
+#=C2=A0 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBU=
TORS BE<br>
+#=C2=A0 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, O=
R<br>
+#=C2=A0 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT =
OF<br>
+#=C2=A0 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BU=
SINESS<br>
+#=C2=A0 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETH=
ER IN<br>
+#=C2=A0 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHER=
WISE)<br>
+#=C2=A0 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISE=
D OF THE<br>
+#=C2=A0 POSSIBILITY OF SUCH DAMAGE.<br>
+#<br>
+<br>
+##########################################################################=
######<br>
+# Library registration<br>
+##########################################################################=
######<br>
+$(eval $(call addlib_s,libmimalloc,$(CONFIG_LIBMIMALLOC)))<br>
+<br>
+##########################################################################=
######<br>
+# Sources<br>
+##########################################################################=
######<br>
+LIBMIMALLOC_VERSION=3D1.6.1<br>
+LIBMIMALLOC_URL=3D<a href=3D"https://github.com/microsoft/mimalloc/archive=
/v$(LIBMIMALLOC_VERSION).zip" rel=3D"noreferrer" target=3D"_blank">https://=
github.com/microsoft/mimalloc/archive/v$(LIBMIMALLOC_VERSION).zip</a><br>
+LIBMIMALLOC_DIR=3Dmimalloc-$(LIBMIMALLOC_VERSION)<br>
+<br>
+LIBMIMALLOC_PATCHDIR=3D$(LIBMIMALLOC_BASE)/patches<br>
+$(eval $(call fetch,libmimalloc,$(LIBMIMALLOC_URL),v$(LIBMIMALLOC_VERSION)=
.zip))<br>
+$(eval $(call patch,libmimalloc,$(LIBMIMALLOC_PATCHDIR),$(LIBMIMALLOC_DIR)=
))<br>
+<br>
+##########################################################################=
######<br>
+# Helpers<br>
+##########################################################################=
######<br>
+LIBMIMALLOC=3D$(LIBMIMALLOC_ORIGIN)/$(LIBMIMALLOC_DIR)<br>
+<br>
+##########################################################################=
######<br>
+# Library includes<br>
+##########################################################################=
######<br>
+<br>
+CINCLUDES-$(CONFIG_LIBMIMALLOC) +=3D -I$(LIBMIMALLOC_BASE) \<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0-I$(LIBMIMALLOC_BASE)/i=
nclude \<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0-I$(LIBMIMALLOC)/includ=
e<br>
+<br>
+##########################################################################=
######<br>
+# Global flags<br>
+##########################################################################=
######<br>
+LIBMIMALLOC_GLOBAL_FLAGS-$(CONFIG_MIMALLOC_ASSERT) +=3D -DNDEBUG<br>
+LIBMIMALLOC_CFLAGS-y +=3D -Wall -Wextra -Wno-unknown-pragmas -fvisibility=
=3Dhidden \<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0-Wno-invalid-memory-model \<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0-D&#39;MI_DEBUG=3D${CONFIG_MIMALLOC_DEBUG}&#39;\<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0${LIBMIMALLOC_GLOBAL_FLAGS-n}<br>
+<br>
+##########################################################################=
######<br>
+# Glue code<br>
+##########################################################################=
######<br>
+LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC_BASE)/glue.c<br>
+<br>
+##########################################################################=
######<br>
+# Sources<br>
+##########################################################################=
######<br>
+LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/stats.c<br>
+LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/random.c<br>
+LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/os.c<br>
+LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/arena.c<br>
+LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/region.c<br>
+LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/segment.c<br>
+LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/page.c<br>
+LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/alloc.c<br>
+LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/alloc-aligned.c<br>
+LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/alloc-posix.c<br>
+#LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/bitmap.inc.c<br>
+LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/heap.c<br>
+LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/options.c<br>
+LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/init.c<br>
+#LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/alloc-override.c<br>
+#LIBMIMALLOC_SRCS-y +=3D $(LIBMIMALLOC)/src/page-queue.c<br>
diff --git a/README.md b/README.md<br>
new file mode 100644<br>
index 0000000..a43779c<br>
--- /dev/null<br>
+++ b/README.md<br>
@@ -0,0 +1,13 @@<br>
+Mimalloc for Unikraft<br>
+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>
+<br>
+This is the port of the Mimalloc [0] general-purpose memory allocator for<=
br>
+Unikraft as an external library.<br>
+<br>
+How to use this allocator in your unikernel application:<br>
+<br>
+- apply main-tree.patch to the main tree<br>
+- select &quot;Mimalloc&quot; in `ukboot &gt; Default memory allocator`<br=
>
+- pass at least 256MiB of memory to the unikernel<br>
+<br>
+[0] <a href=3D"https://microsoft.github.io/mimalloc/" rel=3D"noreferrer" t=
arget=3D"_blank">https://microsoft.github.io/mimalloc/</a><br>
diff --git a/glue.c b/glue.c<br>
new file mode 100644<br>
index 0000000..1d23ec5<br>
--- /dev/null<br>
+++ b/glue.c<br>
@@ -0,0 +1,247 @@<br>
+/* SPDX-License-Identifier: BSD-3-Clause */<br>
+/*<br>
+ * Authors: Hugo Lefeuvre &lt;<a href=3D"mailto:hugo.lefeuvre@neclab.eu" t=
arget=3D"_blank">hugo.lefeuvre@neclab.eu</a>&gt;<br>
+ *<br>
+ * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation,<br>
+ *=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0All rights reserved.<br>
+ *<br>
+ * Redistribution and use in source and binary forms, with or without<br>
+ * modification, are permitted provided that the following conditions<br>
+ * are met:<br>
+ *<br>
+ * 1. Redistributions of source code must retain the above copyright<br>
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.<br>
+ * 2. Redistributions in binary form must reproduce the above copyright<br=
>
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the<br>
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.<br>
+ * 3. Neither the name of the copyright holder nor the names of its<br>
+ *=C2=A0 =C2=A0 contributors may be used to endorse or promote products de=
rived from<br>
+ *=C2=A0 =C2=A0 this software without specific prior written permission.<b=
r>
+ *<br>
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &qu=
ot;AS IS&quot;<br>
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, T=
HE<br>
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP=
OSE<br>
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS =
BE<br>
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br=
>
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINES=
S<br>
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN=
<br>
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)=
<br>
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF =
THE<br>
+ * POSSIBILITY OF SUCH DAMAGE.<br>
+ */<br>
+<br>
+#include &lt;uk/mimalloc_impl.h&gt;<br>
+#include &lt;uk/mimalloc.h&gt;<br>
+#include &lt;mimalloc.h&gt;<br>
+#include &lt;mimalloc-internal.h&gt; // _mi_options_init()<br>
+#include &lt;uk/alloc_impl.h&gt;<br>
+#include &lt;uk/print.h&gt;<br>
+#include &lt;uk/allocregion.h&gt;<br>
+#include &lt;uk/thread.h&gt; // uk_thread_current()<br>
+#include &lt;uk/page.h&gt;=C2=A0 =C2=A0// round_pgup()<br>
+#include &lt;uk/sched.h&gt;=C2=A0 // uk_mimalloc_init_internal()<br>
+<br>
+/* Notes of Unikraft&#39;s Mimalloc port:<br>
+ *<br>
+ * 1. Minimum heap size required: 256MiB, which is the size of an arena.<b=
r>
+ *<br>
+ * 2. Maximum number of Mimalloc instances:<br>
+ *=C2=A0 =C2=A0 Mimalloc&#39;s current code base relies strongly on static=
 variables. Instead<br>
+ *=C2=A0 =C2=A0 of heavily patching it (and maintaining the patches) we si=
mply restrict<br>
+ *=C2=A0 =C2=A0 the maximum number of Mimalloc instances to one.<br>
+ *<br>
+ * 3. Early boot time allocator:<br>
+ *=C2=A0 =C2=A0 Mimalloc can only be initialized after pthread. However th=
e early boot<br>
+ *=C2=A0 =C2=A0 process including pthread&#39;s initialization itself requ=
ires a functioning<br>
+ *=C2=A0 =C2=A0 memory allocator. We solve this problem by relying on ukal=
locregion during<br>
+ *=C2=A0 =C2=A0 the early boot time. The transition to Mimalloc is trigger=
ed as soon as<br>
+ *=C2=A0 =C2=A0 _tls_ready() returns true. We expect that this won&#39;t c=
ause significant<br>
+ *=C2=A0 =C2=A0 memory leak since memory allocated during EBT is typically=
 not freed.<br>
+ *<br>
+ * 4. Transition EBT allocator -&gt; Mimalloc:<br>
+ *=C2=A0 =C2=A0 We transition as soon as the TLS has been allocated and th=
e %fs register<br>
+ *=C2=A0 =C2=A0 set. This is checked at every EBT allocation by inspecting=
<br>
+ *=C2=A0 =C2=A0 uk_thread_current()-&gt;prv which typically points to the =
thread local<br>
+ *=C2=A0 =C2=A0 storage. Since memory allocations might happen during Mima=
lloc&#39;s<br>
+ *=C2=A0 =C2=A0 initialization itself (e.g. calls to malloc() by pthread) =
the early boot<br>
+ *=C2=A0 =C2=A0 time allocator continues to satisfy requests until Mimallo=
c is ready<br>
+ *=C2=A0 =C2=A0 (after mi_process_load() returned).<br>
+ */<br>
+<br>
+/* Minimum heap size (size of an arena)<br>
+ * TODO: can Mimalloc be reconfigured/patched to lower/remove this limitat=
ion?<br>
+ */<br>
+#define MIN_HEAP_SIZE 268435456L<br>
+<br>
+/* Rely on ukallocregion to satisfy boot-time allocations */<br>
+static struct uk_alloc *__region_alloc;<br>
+<br>
+/* make sure that the transition from boot-time allocation to Mimalloc is =
done<br>
+ * only once: calls to malloc() during Mimalloc initialization should be<b=
r>
+ * satisfied using the boot-time allocator.<br>
+ */<br>
+static int __initialized;<br>
+<br>
+static inline int _tls_ready(void)<br>
+{<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0/* Is the thread local storage ready? */<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct uk_thread *current =3D uk_thread_current=
();<br>
+<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return current &amp;&amp; current-&gt;prv !=3D =
NULL;<br>
+}<br>
+<br>
+/* boot-time malloc interface */<br>
+<br>
+static void uk_mimalloc_init_internal(struct uk_alloc *a);<br>
+<br>
+/* NOTE: not static, this is used in the mimalloc code base to request mem=
ory<br>
+ * &quot;from the OS&quot;<br>
+ */<br>
+void *uk_mimalloc_region_malloc(struct uk_alloc *a, size_t size)<br>
+{<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0/* detect call from main thread to leave boot t=
ime mode */<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (_tls_ready() &amp;&amp; !__initialized) {<b=
r>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0uk_pr_debug(&quot;%=
s: leaving early boot-time allocation mode\n&quot;,<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 uk_thread_current()-&gt;name);<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0__initialized =3D 1=
;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0uk_mimalloc_init_in=
ternal(a);<br>
+<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/* satisfy request =
using new malloc interface */<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return uk_malloc(a,=
 size);<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0}<br>
+<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0uk_pr_debug(&quot;allocating %zu from region al=
locator\n&quot;, size);<br>
+<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return uk_malloc(__region_alloc, size);<br>
+}<br>
+<br>
+static int uk_mimalloc_region_posix_memalign(struct uk_alloc *a __unused,<=
br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 void **memptr, size_t align,<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 size_t size)<br>
+{<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0uk_pr_debug(&quot;allocating %zu aligned at %zu=
 from region allocator\n&quot;,<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0size, align);<br>
+<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return uk_posix_memalign(__region_alloc, memptr=
, align, size);<br>
+}<br>
+<br>
+static void uk_mimalloc_region_free(struct uk_alloc *a __unused, void *ptr=
)<br>
+{<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0uk_pr_info(&quot;attempt to free memory during =
early boot time\n&quot;);<br>
+<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return uk_free(__region_alloc, ptr);<br>
+}<br>
+<br>
+/* malloc interface */<br>
+<br>
+static void *uk_mimalloc_malloc(struct uk_alloc *a __unused, size_t size)<=
br>
+{<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return mi_malloc(size);<br>
+}<br>
+<br>
+static void uk_mimalloc_free(struct uk_alloc *a __unused, void *ptr)<br>
+{<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0mi_free(ptr);<br>
+}<br>
+<br>
+static void *uk_mimalloc_realloc(struct uk_alloc *a __unused, void *ptr,<b=
r>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 size_t size)<br>
+{<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return mi_realloc(ptr, size);<br>
+}<br>
+<br>
+static void *uk_mimalloc_calloc(struct uk_alloc *a __unused, size_t nelem,=
<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0size_t elem_size)<br>
+{<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return mi_calloc(nelem, elem_size);<br>
+}<br>
+<br>
+static int uk_mimalloc_posix_memalign(struct uk_alloc *a __unused, void **=
p,<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0size_t alignment=
, size_t size)<br>
+{<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return mi_posix_memalign(p, alignment, size);<b=
r>
+}<br>
+<br>
+static void *uk_mimalloc_memalign(struct uk_alloc *a __unused, size_t alig=
nment,<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0size_t size)<br>
+{<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return mi_memalign(alignment, size);<br>
+}<br>
+<br>
+static void uk_mimalloc_init_internal(struct uk_alloc *a)<br>
+{<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0mi_process_load();<br>
+<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0/* rebind interface to actual malloc interface =
*/<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0(a)-&gt;malloc=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0=3D uk_mimalloc_malloc;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0(a)-&gt;calloc=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0=3D uk_mimalloc_calloc;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0(a)-&gt;realloc=C2=A0 =C2=A0 =C2=A0 =C2=A0 =3D =
uk_mimalloc_realloc;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0(a)-&gt;posix_memalign =3D uk_mimalloc_posix_me=
malign;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0(a)-&gt;memalign=C2=A0 =C2=A0 =C2=A0 =C2=A0=3D =
uk_mimalloc_memalign;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0(a)-&gt;free=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0=3D uk_mimalloc_free;<br>
+<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0/* delay this after interface rebinding to avoi=
d using early boot<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 * time memory.<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 */<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0_mi_options_init();<br>
+<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0uk_pr_info(&quot;Successfully initialized Mimal=
loc\n&quot;);<br>
+}<br>
+<br>
+struct uk_alloc *uk_mimalloc_init(void *base, size_t len)<br>
+{<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct uk_alloc *a;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0size_t metalen;<br>
+<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0/* TODO: This Mimalloc port does not support mu=
ltiple memory regions<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 * yet. Because of the multiboot layout, the fi=
rst region might be a<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 * single page, so we simply ignore it.<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 */<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (len &lt;=3D __PAGE_SIZE)<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return NULL;<br>
+<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (__region_alloc) {<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0uk_pr_err(&quot;mim=
alloc already initialized &quot;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0&quot;(max number of instances: 1)\n&quot;);<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return NULL;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0}<br>
+<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0metalen =3D round_pgup(sizeof(*a));<br>
+<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0/* enough space for allocator available? */<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (metalen &gt; len) {<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0uk_pr_err(&quot;Not=
 enough space for allocator: %&quot; __PRIsz<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0&quot; B required but only %&quot; __PRIuptr&quot; B usabl=
e\n&quot;,<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0metalen, len);<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return NULL;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0}<br>
+<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0/* enough space to allocate arena? */<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (len &lt; MIN_HEAP_SIZE) {<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/* Note: we don&#39=
;t exit, but calls to malloc will return NULL. */<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0uk_pr_err(&quot;Not=
 enough space to allocate arena: %lu bytes &quot;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0&quot;required but only %&quot; __PRIsz&quot; bytes usable=
\n&quot;,<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0268435456L, len);<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0}<br>
+<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0/* store allocator metadata on the heap, just b=
efore the memory pool */<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0a =3D (struct uk_alloc *)base;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0uk_pr_info(&quot;Initialize mimalloc allocator =
(early boot time mode) @ 0x%&quot;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 __PRIuptr &=
quot;, len %&quot;__PRIsz&quot;\n&quot;, (uintptr_t)a, len);<br>
+<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0/* register mimalloc *before* initializing the =
region allocator: in all<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 * cases we want Mimalloc to be the default all=
ocator.<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 * FIXME: add uk_allocregion_init_noregister() =
that initializes a region<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 * allocator without registering it.<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 */<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0uk_alloc_init_malloc(a, uk_mimalloc_region_mall=
oc, uk_calloc_compat,<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0uk_realloc_compat, uk_mimalloc_region=
_free,<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0uk_mimalloc_region_posix_memalign,<br=
>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0uk_memalign_compat, NULL);<br>
+<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0__region_alloc =3D uk_allocregion_init((void *)=
((uintptr_t) base +<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0metalen), len - metalen);<br>
+<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return a;<br>
+}<br>
diff --git a/include/uk/mimalloc.h b/include/uk/mimalloc.h<br>
new file mode 100644<br>
index 0000000..eadeae1<br>
--- /dev/null<br>
+++ b/include/uk/mimalloc.h<br>
@@ -0,0 +1,50 @@<br>
+/* SPDX-License-Identifier: BSD-3-Clause */<br>
+/*<br>
+ * Authors: Hugo Lefeuvre &lt;<a href=3D"mailto:hugo.lefeuvre@neclab.eu" t=
arget=3D"_blank">hugo.lefeuvre@neclab.eu</a>&gt;<br>
+ *<br>
+ * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation,<br>
+ *=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0All rights reserved.<br>
+ *<br>
+ * Redistribution and use in source and binary forms, with or without<br>
+ * modification, are permitted provided that the following conditions<br>
+ * are met:<br>
+ *<br>
+ * 1. Redistributions of source code must retain the above copyright<br>
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.<br>
+ * 2. Redistributions in binary form must reproduce the above copyright<br=
>
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the<br>
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.<br>
+ * 3. Neither the name of the copyright holder nor the names of its<br>
+ *=C2=A0 =C2=A0 contributors may be used to endorse or promote products de=
rived from<br>
+ *=C2=A0 =C2=A0 this software without specific prior written permission.<b=
r>
+ *<br>
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &qu=
ot;AS IS&quot;<br>
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, T=
HE<br>
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP=
OSE<br>
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS =
BE<br>
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br=
>
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINES=
S<br>
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN=
<br>
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)=
<br>
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF =
THE<br>
+ * POSSIBILITY OF SUCH DAMAGE.<br>
+ */<br>
+<br>
+#ifndef __LIBMIMALLOC_H__<br>
+#define __LIBMIMALLOC_H__<br>
+<br>
+#include &lt;uk/alloc.h&gt;<br>
+<br>
+#ifdef __cplusplus<br>
+extern &quot;C&quot; {<br>
+#endif<br>
+<br>
+/* allocator initialization */<br>
+struct uk_alloc *uk_mimalloc_init(void *base, size_t len);<br>
+<br>
+#ifdef __cplusplus<br>
+}<br>
+#endif<br>
+<br>
+#endif /* __LIBMIMALLOC_H__ */<br>
diff --git a/include/uk/mimalloc_impl.h b/include/uk/mimalloc_impl.h<br>
new file mode 100644<br>
index 0000000..6b237cd<br>
--- /dev/null<br>
+++ b/include/uk/mimalloc_impl.h<br>
@@ -0,0 +1,57 @@<br>
+/* SPDX-License-Identifier: BSD-3-Clause */<br>
+/*<br>
+ * Authors: Hugo Lefeuvre &lt;<a href=3D"mailto:hugo.lefeuvre@neclab.eu" t=
arget=3D"_blank">hugo.lefeuvre@neclab.eu</a>&gt;<br>
+ *<br>
+ * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation,<br>
+ *=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0All rights reserved.<br>
+ *<br>
+ * Redistribution and use in source and binary forms, with or without<br>
+ * modification, are permitted provided that the following conditions<br>
+ * are met:<br>
+ *<br>
+ * 1. Redistributions of source code must retain the above copyright<br>
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.<br>
+ * 2. Redistributions in binary form must reproduce the above copyright<br=
>
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the<br>
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.<br>
+ * 3. Neither the name of the copyright holder nor the names of its<br>
+ *=C2=A0 =C2=A0 contributors may be used to endorse or promote products de=
rived from<br>
+ *=C2=A0 =C2=A0 this software without specific prior written permission.<b=
r>
+ *<br>
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &qu=
ot;AS IS&quot;<br>
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, T=
HE<br>
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP=
OSE<br>
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS =
BE<br>
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br=
>
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINES=
S<br>
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN=
<br>
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)=
<br>
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF =
THE<br>
+ * POSSIBILITY OF SUCH DAMAGE.<br>
+ */<br>
+<br>
+/*<br>
+ * NOTE: These functions are not part of the public ukmimalloc API.<br>
+ * This interface is used in the mimalloc code base to request memory<br>
+ * &quot;from the OS&quot;.<br>
+ */<br>
+<br>
+#ifndef __LIBMIMALLOC_IMPL_H__<br>
+#define __LIBMIMALLOC_IMPL_H__<br>
+<br>
+#include &lt;uk/alloc.h&gt;<br>
+<br>
+#ifdef __cplusplus<br>
+extern &quot;C&quot; {<br>
+#endif<br>
+<br>
+/* region allocator */<br>
+<br>
+void *uk_mimalloc_region_malloc(struct uk_alloc *a, size_t size);<br>
+<br>
+#ifdef __cplusplus<br>
+}<br>
+#endif<br>
+<br>
+#endif /* __LIBMIMALLOC_IMPL_H__ */<br>
diff --git a/main-tree.patch b/main-tree.patch<br>
new file mode 100644<br>
index 0000000..40f0268<br>
--- /dev/null<br>
+++ b/main-tree.patch<br>
@@ -0,0 +1,39 @@<br>
+From: Hugo Lefeuvre &lt;<a href=3D"mailto:hugo.lefeuvre@neclab.eu" target=
=3D"_blank">hugo.lefeuvre@neclab.eu</a>&gt;<br>
+Subject: Add Mimalloc entry to the menuconfig and initialize it<br>
+diff --git a/lib/ukboot/Config.uk b/lib/ukboot/Config.uk<br>
+index 07139e2b..cfc306d7 100644<br>
+--- a/lib/ukboot/Config.uk<br>
++++ b/lib/ukboot/Config.uk<br>
+@@ -32,6 +32,10 @@ if LIBUKBOOT<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Satisfy allo=
cation as fast as possible. No support for free().<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Refer to hel=
p in ukallocregion for more information.<br>
+ <br>
++=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 config LIBUKBOOT_INITMIM=
ALLOC<br>
++=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 bool &quot;Mimalloc&quot=
;<br>
++=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 select LIBMIMALLOC<br>
++<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0config LIBUKBOOT_NO=
ALLOC<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0bool &quot;None&quo=
t;<br>
+ <br>
+diff --git a/lib/ukboot/boot.c b/lib/ukboot/boot.c<br>
+index 4e749aa5..a400749d 100644<br>
+--- a/lib/ukboot/boot.c<br>
++++ b/lib/ukboot/boot.c<br>
+@@ -45,6 +45,8 @@<br>
+ #include &lt;uk/allocbbuddy.h&gt;<br>
+ #elif CONFIG_LIBUKBOOT_INITREGION<br>
+ #include &lt;uk/allocregion.h&gt;<br>
++#elif CONFIG_LIBUKBOOT_INITMIMALLOC<br>
++#include &lt;uk/mimalloc.h&gt;<br>
+ #endif<br>
+ #if CONFIG_LIBUKSCHED<br>
+ #include &lt;uk/sched.h&gt;<br>
+@@ -233,6 +235,8 @@ void ukplat_entry(int argc, char *argv[])<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0a =3D uk_allocbbuddy_init(md.base, md.len);<br>
+ #elif CONFIG_LIBUKBOOT_INITREGION<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0a =3D uk_allocregion_init(md.base, md.len);<br>
++#elif CONFIG_LIBUKBOOT_INITMIMALLOC<br>
++=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 a =3D uk_mimalloc_init(md.base, md.len);<br>
+ #endif<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} else {<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0uk_alloc_addmem(a, md.base, md.len);<br>
diff --git a/patches/adapt-to-unikraft-interface.patch b/patches/adapt-to-u=
nikraft-interface.patch<br>
new file mode 100644<br>
index 0000000..8a41454<br>
--- /dev/null<br>
+++ b/patches/adapt-to-unikraft-interface.patch<br>
@@ -0,0 +1,160 @@<br>
+From: Hugo Lefeuvre &lt;<a href=3D"mailto:hugo.lefeuvre@neclab.eu" target=
=3D"_blank">hugo.lefeuvre@neclab.eu</a>&gt;<br>
+Subject: Adapt Mimalloc interface to Unikraft<br>
+ - expose mi_process_load() since it is called in the glue code<br>
+ - remove useless ATOMIC_VAR_INIT calls since they cause problems with new=
lib<br>
+ - request memory from the OS via mi_unikraft_heap_grow(), which relies<br=
>
+=C2=A0 =C2=A0internally on uk_mimalloc_region_malloc(), our underlying reg=
ion manager<br>
+ - at the time where Mimalloc was ported, the support for memory protectio=
ns<br>
+=C2=A0 =C2=A0by Unikraft was unclear, so it is here disabled. A future upd=
ate of this<br>
+=C2=A0 =C2=A0port should address this.<br>
+diff -urNp mimalloc-orig/include/mimalloc.h mimalloc-patched/include/mimal=
loc.h<br>
+--- mimalloc-orig/include/mimalloc.h=C2=A0 =C2=A02020-02-17 19:10:22.00000=
0000 +0100<br>
++++ mimalloc-patched/include/mimalloc.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 2020-06=
-24 10:16:31.439830260 +0200<br>
+@@ -144,6 +144,7 @@ mi_decl_export void mi_stats_print(void*<br>
+ mi_decl_export void mi_stats_print_out(mi_output_fun* out, void* arg) mi_=
attr_noexcept;<br>
+ <br>
+ mi_decl_export void mi_process_init(void)=C2=A0 =C2=A0 =C2=A0mi_attr_noex=
cept;<br>
++mi_decl_export void mi_process_load(void)=C2=A0 =C2=A0 =C2=A0mi_attr_noex=
cept;<br>
+ mi_decl_export void mi_thread_init(void)=C2=A0 =C2=A0 =C2=A0 mi_attr_noex=
cept;<br>
+ mi_decl_export void mi_thread_done(void)=C2=A0 =C2=A0 =C2=A0 mi_attr_noex=
cept;<br>
+ mi_decl_export void mi_thread_stats_print_out(mi_output_fun* out, void* a=
rg) mi_attr_noexcept;<br>
+diff -urNp mimalloc-orig/src/init.c mimalloc-patched/src/init.c<br>
+--- mimalloc-orig/src/init.c=C2=A0 =C2=A02020-02-17 19:10:22.000000000 +01=
00<br>
++++ mimalloc-patched/src/init.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 2020-06-24 10:1=
6:31.443830218 +0200<br>
+@@ -25,8 +25,8 @@ const mi_page_t _mi_page_empty =3D {<br>
+=C2=A0 =C2=A00,=C2=A0 =C2=A0 =C2=A0 =C2=A0// used<br>
+=C2=A0 =C2=A00,=C2=A0 =C2=A0 =C2=A0 =C2=A0// xblock_size<br>
+=C2=A0 =C2=A0NULL,=C2=A0 =C2=A0 // local_free<br>
+-=C2=A0 ATOMIC_VAR_INIT(0), // xthread_free<br>
+-=C2=A0 ATOMIC_VAR_INIT(0), // xheap<br>
++=C2=A0 0, // xthread_free<br>
++=C2=A0 0, // xheap<br>
+=C2=A0 =C2=A0NULL, NULL<br>
+ };<br>
+ <br>
+@@ -91,7 +91,7 @@ const mi_heap_t _mi_heap_empty =3D {<br>
+=C2=A0 =C2=A0NULL,<br>
+=C2=A0 =C2=A0MI_SMALL_PAGES_EMPTY,<br>
+=C2=A0 =C2=A0MI_PAGE_QUEUES_EMPTY,<br>
+-=C2=A0 ATOMIC_VAR_INIT(NULL),<br>
++=C2=A0 NULL,<br>
+=C2=A0 =C2=A00,=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 // =
tid<br>
+=C2=A0 =C2=A00,=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 // =
cookie<br>
+=C2=A0 =C2=A0{ 0, 0 },=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0// keys<br>
+@@ -125,7 +125,7 @@ mi_heap_t _mi_heap_main =3D {<br>
+=C2=A0 =C2=A0&amp;tld_main,<br>
+=C2=A0 =C2=A0MI_SMALL_PAGES_EMPTY,<br>
+=C2=A0 =C2=A0MI_PAGE_QUEUES_EMPTY,<br>
+-=C2=A0 ATOMIC_VAR_INIT(NULL),<br>
++=C2=A0 NULL,<br>
+=C2=A0 =C2=A00,=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 // =
thread id<br>
+=C2=A0 =C2=A00,=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 // =
initial cookie<br>
+=C2=A0 =C2=A0{ 0, 0 },=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0// the key of the =
main heap can be fixed (unlike page keys that need to be secure!)<br>
+@@ -430,7 +430,7 @@ static void mi_allocator_done() {<br>
+ #endif<br>
+ <br>
+ // Called once by the process loader<br>
+-static void mi_process_load(void) {<br>
++void mi_process_load(void) {<br>
+=C2=A0 =C2=A0mi_heap_main_init();<br>
+=C2=A0 =C2=A0#if defined(MI_TLS_RECURSE_GUARD)<br>
+=C2=A0 =C2=A0volatile mi_heap_t* dummy =3D _mi_heap_default; // access TLS=
 to allocate it before setting tls_initialized to true;<br>
+@@ -438,7 +438,9 @@ static void mi_process_load(void) {<br>
+=C2=A0 =C2=A0#endif<br>
+=C2=A0 =C2=A0os_preloading =3D false;<br>
+=C2=A0 =C2=A0atexit(&amp;mi_process_done);<br>
+-=C2=A0 _mi_options_init();<br>
++=C2=A0 // delay _mi_options_init() after initialization as it allocates a=
 lot of<br>
++=C2=A0 // memory and we want to avoid doing that with the early boot time=
 allocator<br>
++=C2=A0 //_mi_options_init();<br>
+=C2=A0 =C2=A0mi_process_init();<br>
+=C2=A0 =C2=A0//mi_stats_reset();-<br>
+=C2=A0 =C2=A0if (mi_redirected) _mi_verbose_message(&quot;malloc is redire=
cted.\n&quot;);<br>
+@@ -519,6 +521,8 @@ static void mi_process_done(void) {<br>
+=C2=A0 =C2=A0}<br>
+=C2=A0 =C2=A0static bool mi_initialized =3D _mi_process_init();<br>
+ <br>
++#elif defined(CONFIG_LIBMIMALLOC)<br>
++=C2=A0 // called by uk_init_mimalloc()<br>
+ #elif defined(__GNUC__) || defined(__clang__)<br>
+=C2=A0 =C2=A0// GCC,Clang: use the constructor attribute<br>
+=C2=A0 =C2=A0static void __attribute__((constructor)) _mi_process_init(voi=
d) {<br>
+diff -urNp mimalloc-orig/src/os.c mimalloc-patched/src/os.c<br>
+--- mimalloc-orig/src/os.c=C2=A0 =C2=A0 =C2=A02020-02-17 19:10:22.00000000=
0 +0100<br>
++++ mimalloc-patched/src/os.c=C2=A0 2020-06-24 14:44:56.745158608 +0200<br=
>
+@@ -14,11 +14,14 @@ terms of the MIT license. A copy of the<br>
+ <br>
+ #include &lt;string.h&gt;=C2=A0 // strerror<br>
+ <br>
++#include &lt;uk/mimalloc_impl.h&gt; // uk_mimalloc_region_malloc<br>
+ <br>
+ #if defined(_WIN32)<br>
+ #include &lt;windows.h&gt;<br>
+ #elif defined(__wasi__)<br>
+ // stdlib.h is all we need, and has already been included in mimalloc.h<b=
r>
++#elif defined(CONFIG_LIBMIMALLOC)<br>
++#include &lt;unistd.h&gt;=C2=A0 =C2=A0 // sysconf<br>
+ #else<br>
+ #include &lt;sys/mman.h&gt;=C2=A0 // mmap<br>
+ #include &lt;unistd.h&gt;=C2=A0 =C2=A0 // sysconf<br>
+@@ -184,8 +187,8 @@ static bool mi_os_mem_free(void* addr, s<br>
+=C2=A0 =C2=A0bool err =3D false;<br>
+ #if defined(_WIN32)<br>
+=C2=A0 =C2=A0err =3D (VirtualFree(addr, 0, MEM_RELEASE) =3D=3D 0);<br>
+-#elif defined(__wasi__)<br>
+-=C2=A0 err =3D 0; // WebAssembly&#39;s heap cannot be shrunk<br>
++#elif defined(__wasi__) || defined(CONFIG_LIBMIMALLOC)<br>
++=C2=A0 err =3D 0; // WebAssembly&#39;s/Unikraft&#39;s heap cannot be shru=
nk<br>
+ #else<br>
+=C2=A0 =C2=A0err =3D (munmap(addr, size) =3D=3D -1);<br>
+ #endif<br>
+@@ -272,6 +275,10 @@ static void* mi_wasm_heap_grow(size_t si<br>
+=C2=A0 =C2=A0}<br>
+=C2=A0 =C2=A0return (void*)aligned_base;<br>
+ }<br>
++#elif defined(CONFIG_LIBMIMALLOC)<br>
++static void* mi_unikraft_heap_grow(size_t size, size_t try_alignment) {<b=
r>
++=C2=A0 return uk_mimalloc_region_malloc(NULL, size);<br>
++}<br>
+ #else<br>
+ #define MI_OS_USE_MMAP<br>
+ static void* mi_unix_mmapx(void* addr, size_t size, size_t try_alignment,=
 int protect_flags, int flags, int fd) {<br>
+@@ -450,6 +457,9 @@ static void* mi_os_mem_alloc(size_t size<br>
+=C2=A0 =C2=A0#elif defined(__wasi__)<br>
+=C2=A0 =C2=A0 =C2=A0*is_large =3D false;<br>
+=C2=A0 =C2=A0 =C2=A0p =3D mi_wasm_heap_grow(size, try_alignment);<br>
++=C2=A0 #elif defined(CONFIG_LIBMIMALLOC)<br>
++=C2=A0 =C2=A0 *is_large =3D false;<br>
++=C2=A0 =C2=A0 p =3D mi_unikraft_heap_grow(size, try_alignment);<br>
+=C2=A0 =C2=A0#else<br>
+=C2=A0 =C2=A0 =C2=A0int protect_flags =3D (commit ? (PROT_WRITE | PROT_REA=
D) : PROT_NONE);<br>
+=C2=A0 =C2=A0 =C2=A0p =3D mi_unix_mmap(NULL, size, try_alignment, protect_=
flags, false, allow_large, is_large);<br>
+@@ -638,8 +648,8 @@ static bool mi_os_commitx(void* addr, si<br>
+=C2=A0 =C2=A0 =C2=A0BOOL ok =3D VirtualFree(start, csize, MEM_DECOMMIT);<b=
r>
+=C2=A0 =C2=A0 =C2=A0err =3D (ok ? 0 : GetLastError());<br>
+=C2=A0 =C2=A0}<br>
+-=C2=A0 #elif defined(__wasi__)<br>
+-=C2=A0 // WebAssembly guests can&#39;t control memory protection<br>
++=C2=A0 #elif defined(__wasi__) || defined(CONFIG_LIBMIMALLOC)<br>
++=C2=A0 // Unikraft/WebAssembly guests can&#39;t control memory protection=
<br>
+=C2=A0 =C2=A0#elif defined(MAP_FIXED)<br>
+=C2=A0 =C2=A0if (!commit) {<br>
+=C2=A0 =C2=A0 =C2=A0// use mmap with MAP_FIXED to discard the existing mem=
ory (and reduce commit charge)<br>
+@@ -714,7 +724,7 @@ static bool mi_os_resetx(void* addr, siz<br>
+=C2=A0 =C2=A0 =C2=A0advice =3D MADV_DONTNEED;<br>
+=C2=A0 =C2=A0 =C2=A0err =3D madvise(start, csize, advice);<br>
+=C2=A0 =C2=A0}<br>
+-#elif defined(__wasi__)<br>
++#elif defined(__wasi__) || defined(CONFIG_LIBMIMALLOC)<br>
+=C2=A0 =C2=A0int err =3D 0;<br>
+ #else<br>
+=C2=A0 =C2=A0int err =3D madvise(start, csize, MADV_DONTNEED);<br>
+@@ -768,7 +778,7 @@ static=C2=A0 bool mi_os_protectx(void* addr,<br>
+=C2=A0 =C2=A0DWORD oldprotect =3D 0;<br>
+=C2=A0 =C2=A0BOOL ok =3D VirtualProtect(start, csize, protect ? PAGE_NOACC=
ESS : PAGE_READWRITE, &amp;oldprotect);<br>
+=C2=A0 =C2=A0err =3D (ok ? 0 : GetLastError());<br>
+-#elif defined(__wasi__)<br>
++#elif defined(__wasi__) || defined(CONFIG_LIBMIMALLOC)<br>
+=C2=A0 =C2=A0err =3D 0;<br>
+ #else<br>
+=C2=A0 =C2=A0err =3D mprotect(start, csize, protect ? PROT_NONE : (PROT_RE=
AD | PROT_WRITE));<br>
-- <br>
2.7.4<br>
<br>
<br>
</blockquote></div></div>

--0000000000003a633a05ab9418f2--


From minios-devel-bounces@lists.xenproject.org Wed Jul 29 16:28:02 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 29 Jul 2020 16:28:02 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k0ovt-0007Ci-Qr; Wed, 29 Jul 2020 16:27:57 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=0vVE=BI=neclab.eu=simon.kuenzer@srs-us1.protection.inumbo.net>)
 id 1k0ovs-0007Cd-Rn
 for minios-devel@lists.xenproject.org; Wed, 29 Jul 2020 16:27:56 +0000
X-Inumbo-ID: 73e3edb2-d1b8-11ea-8c97-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 73e3edb2-d1b8-11ea-8c97-bc764e2007e4;
 Wed, 29 Jul 2020 16:27:54 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 2AB2AF2010;
 Wed, 29 Jul 2020 18:27:53 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id qj5GNd77DUMt; Wed, 29 Jul 2020 18:27:53 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id E2107F2004
 for <minios-devel@lists.xenproject.org>; Wed, 29 Jul 2020 18:27:50 +0200 (CEST)
Received: from [10.7.1.42] (192.168.24.96) by puck.office.hd (192.168.24.91)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 29 Jul
 2020 18:27:50 +0200
Subject: Re: [UNIKRAFT PATCH] lib/ukalloc: add ifmalloc compatibility interface
To: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>,
 <minios-devel@lists.xenproject.org>
References: <cover.1593161335.git.hugo.lefeuvre@neclab.eu>
 <ca1dfaad396d52fb74c9b5d544b434233c0e394a.1593161335.git.hugo.lefeuvre@neclab.eu>
From: Simon Kuenzer <simon.kuenzer@neclab.eu>
Message-ID: <7452aedc-5aee-85b0-a40e-f43399413cee@neclab.eu>
Date: Wed, 29 Jul 2020 18:27:49 +0200
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0)
 Gecko/20100101 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <ca1dfaad396d52fb74c9b5d544b434233c0e394a.1593161335.git.hugo.lefeuvre@neclab.eu>
Content-Type: text/plain; charset="utf-8"; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Hugo,

I think this patch looks pretty fine. I have just a slight suggestions 
but nothing of it is critical. I experienced once on a microcontroller 
architecture that accessing mis-aligned struct allocation can lead to 
opcode crashes. Because of this I would prefer using 
`METADATA_IFMALLOC_SIZE_POW2` instead of using `sizeof()`. The rest of 
comments is beautifying.

Let me know what you think.

Thanks,

Simon

On 26.06.20 10:50, Hugo Lefeuvre wrote:
> Add ifmalloc, the malloc compatibility interface. This interface implements
> a POSIX compliant allocation interface on top of a simple malloc() and
> free() interface. This interface is similar to ifpages, which does the same
> for palloc() and pfree().
> 
> ifmalloc will be used for the port of TLSF and tinyalloc which do not
> support (posix_)memalign().
> 
> Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> ---
>   lib/ukalloc/Config.uk               |   5 ++
>   lib/ukalloc/alloc.c                 | 144 ++++++++++++++++++++++++++++++++++++
>   lib/ukalloc/exportsyms.uk           |   4 +
>   lib/ukalloc/include/uk/alloc.h      |   5 ++
>   lib/ukalloc/include/uk/alloc_impl.h |  27 +++++++
>   5 files changed, 185 insertions(+)
> 
> diff --git a/lib/ukalloc/Config.uk b/lib/ukalloc/Config.uk
> index 0de7464..c965d08 100644
> --- a/lib/ukalloc/Config.uk
> +++ b/lib/ukalloc/Config.uk
> @@ -5,6 +5,11 @@ menuconfig LIBUKALLOC
>   	select LIBUKDEBUG
>   
>   if LIBUKALLOC
> +	config LIBUKALLOC_IFMALLOC
> +		bool "Malloc compatibility interface"
> +		default n
> +		help
> +			Provide helpers for allocators defining exclusively malloc and free
>   	config LIBUKALLOC_IFSTATS
>   		bool "Statistics interface"
>   		default n
> diff --git a/lib/ukalloc/alloc.c b/lib/ukalloc/alloc.c
> index 437bc4b..3b8d8d8 100644
> --- a/lib/ukalloc/alloc.c
> +++ b/lib/ukalloc/alloc.c
> @@ -304,6 +304,150 @@ int uk_posix_memalign_ifpages(struct uk_alloc *a,
>   	return 0;
>   }
>   
> +#if CONFIG_LIBUKALLOC_IFMALLOC
> +
> +struct metadata_ifmalloc {
> +	size_t	size;
> +	void	*base;
> +};
> +
> +#define METADATA_IFMALLOC_SIZE_POW2 16
> +UK_CTASSERT(!(sizeof(struct metadata_ifmalloc) > METADATA_IFMALLOC_SIZE_POW2));
> +
> +static struct metadata_ifmalloc *uk_get_metadata_ifmalloc(const void *ptr)
> +{
> +	return (struct metadata_ifmalloc *)((uintptr_t) ptr -
> +		sizeof(struct metadata_ifmalloc));

Maybe substract METADATA_IFMALLOC_SIZE_POW2 instead of sizeof. THis is 
to make sure that we are not ending up in alignement problems

> +}
> +
> +static size_t uk_getmallocsize_ifmalloc(const void *ptr)
> +{
> +	struct metadata_ifmalloc *metadata = uk_get_metadata_ifmalloc(ptr);
> +	return (size_t) ((uintptr_t) metadata->base + metadata->size -
> +			 (uintptr_t) ptr);
> +}
> +
> +void uk_free_ifmalloc(struct uk_alloc *a, void *ptr)
> +{
> +	struct metadata_ifmalloc *metadata;
> +
> +	UK_ASSERT(a);
> +	UK_ASSERT(a->free_backend);
> +	if (!ptr)
> +		return;
> +
> +	metadata = uk_get_metadata_ifmalloc(ptr);
> +	a->free_backend(a, metadata->base);
> +}
> +
> +void *uk_malloc_ifmalloc(struct uk_alloc *a, size_t size)
> +{
> +	struct metadata_ifmalloc *metadata;
> +	size_t realsize = size + sizeof(*metadata);

METADATA_IFMALLOC_SIZE_POW2 instead of sizeof - just to make sure.

> +	void *ptr;
> +
> +	UK_ASSERT(a);
> +	UK_ASSERT(a->malloc_backend);
> +
> +	/* check for overflow */
> +	if (realsize < size)
> +		return NULL;

This is quiet unlikely. You can put an `unlikely` to let the compiler know.

> +
> +	ptr = a->malloc_backend(a, realsize);
> +	if (!ptr)
> +		return NULL;
> +
> +	metadata = ptr;
> +	metadata->size = realsize;
> +	metadata->base = ptr;
> +
> +	return (void *) ((uintptr_t) ptr + sizeof(*metadata));

sizeof -> METADATA_IFMALLOC_SIZE_POW2

> +}
> +
> +void *uk_realloc_ifmalloc(struct uk_alloc *a, void *ptr, size_t size)
> +{
> +	void *retptr;
> +	size_t mallocsize;
> +
> +	UK_ASSERT(a);
> +	if (!ptr)
> +		return uk_malloc_ifmalloc(a, size);
> +
> +	if (ptr && !size) {
> +		uk_free_ifmalloc(a, ptr);
> +		return NULL;
> +	}
> +
> +	retptr = uk_malloc_ifmalloc(a, size);
> +	if (!retptr)
> +		return NULL;
> +
> +	mallocsize = uk_getmallocsize_ifmalloc(ptr);
> +
> +	if (size < mallocsize)
> +		memcpy(retptr, ptr, size);
> +	else
> +		memcpy(retptr, ptr, mallocsize);

you could also use MIN instead of the ifcase (but this is just for beauty):

memcpy(retptr, ptr, MIN(size, mallocsize));

> +
> +	uk_free_ifmalloc(a, ptr);
> +	return retptr;
> +}
> +
> +int uk_posix_memalign_ifmalloc(struct uk_alloc *a,
> +				     void **memptr, size_t align, size_t size)
> +{
> +	struct metadata_ifmalloc *metadata;
> +	size_t realsize, padding;
> +	uintptr_t intptr;
> +
> +	UK_ASSERT(a);
> +	if (((align - 1) & align) != 0
> +	    || (align % sizeof(void *)) != 0)

Maybe take a different check than using slow `%` operation. The previous 
check tested already for power of 2, right? So we are fine to do the 
check with:
	align < sizeof(void *)
right?

> +		return EINVAL;
> +
> +	if (!size) {
> +		*memptr = NULL;
> +		return EINVAL;
> +	}
> +
> +	/* Store size information preceeding the memory block. Since we return
> +	 * pointers aligned at `align` we need to reserve at least that much
> +	 * space for the size information.
> +	 */
> +	if (align < METADATA_IFMALLOC_SIZE_POW2) {
> +		align = METADATA_IFMALLOC_SIZE_POW2;
> +		padding = 0;
> +	} else {
> +		padding = sizeof(*metadata);

sizeof -> METADATA_IFMALLOC_SIZE_POW2

> +	}
> +
> +	realsize = size + padding + align;
> +
> +	/* check for overflow */
> +	if (realsize < size)
> +		return NULL;

unlikely

> +
> +	intptr = (uintptr_t) a->malloc_backend(a, realsize);
> +
> +	if (!intptr)
> +		return ENOMEM;
> +
> +	*memptr = (void *) ALIGN_UP(intptr + sizeof(*metadata),
> +				    (uintptr_t) align);

sizeof -> METADATA_IFMALLOC_SIZE_POW2

> +
> +	metadata = uk_get_metadata_ifmalloc(*memptr);
> +
> +	/* check for underflow */
> +	UK_ASSERT(intptr <= (uintptr_t) metadata);
> +
> +	metadata->size = realsize;
> +	metadata->base = (void *) intptr;
> +
> +	return 0;
> +}
> +
> +#endif
> +
>   void uk_pfree_compat(struct uk_alloc *a, void *ptr,
>   		     unsigned long num_pages __unused)
>   {
> diff --git a/lib/ukalloc/exportsyms.uk b/lib/ukalloc/exportsyms.uk
> index 2357501..594999f 100644
> --- a/lib/ukalloc/exportsyms.uk
> +++ b/lib/ukalloc/exportsyms.uk
> @@ -5,6 +5,10 @@ uk_malloc_ifpages
>   uk_free_ifpages
>   uk_realloc_ifpages
>   uk_posix_memalign_ifpages
> +uk_malloc_ifmalloc
> +uk_realloc_ifmalloc
> +uk_posix_memalign_ifmalloc
> +uk_free_ifmalloc
>   uk_calloc_compat
>   uk_memalign_compat
>   uk_realloc_compat
> diff --git a/lib/ukalloc/include/uk/alloc.h b/lib/ukalloc/include/uk/alloc.h
> index 8ab41d6..73b3a45 100644
> --- a/lib/ukalloc/include/uk/alloc.h
> +++ b/lib/ukalloc/include/uk/alloc.h
> @@ -88,6 +88,11 @@ struct uk_alloc {
>   	uk_alloc_memalign_func_t memalign;
>   	uk_alloc_free_func_t free;
>   
> +#if CONFIG_LIBUKALLOC_IFMALLOC
> +	uk_alloc_free_func_t free_backend;
> +	uk_alloc_malloc_func_t malloc_backend;
> +#endif
> +
>   	/* page allocation interface */
>   	uk_alloc_palloc_func_t palloc;
>   	uk_alloc_pfree_func_t pfree;
> diff --git a/lib/ukalloc/include/uk/alloc_impl.h b/lib/ukalloc/include/uk/alloc_impl.h
> index 8bcca94..b15f49e 100644
> --- a/lib/ukalloc/include/uk/alloc_impl.h
> +++ b/lib/ukalloc/include/uk/alloc_impl.h
> @@ -62,6 +62,14 @@ int uk_posix_memalign_ifpages(struct uk_alloc *a, void **memptr,
>   				size_t align, size_t size);
>   void uk_free_ifpages(struct uk_alloc *a, void *ptr);
>   
> +#if CONFIG_LIBUKALLOC_IFMALLOC
> +void *uk_malloc_ifmalloc(struct uk_alloc *a, size_t size);
> +void *uk_realloc_ifmalloc(struct uk_alloc *a, void *ptr, size_t size);
> +int uk_posix_memalign_ifmalloc(struct uk_alloc *a, void **memptr,
> +				     size_t align, size_t size);
> +void uk_free_ifmalloc(struct uk_alloc *a, void *ptr);
> +#endif
> +
>   /* Functionality that is provided based on malloc() and posix_memalign() */
>   void *uk_calloc_compat(struct uk_alloc *a, size_t num, size_t len);
>   void *uk_realloc_compat(struct uk_alloc *a, void *ptr, size_t size);
> @@ -88,6 +96,25 @@ void uk_pfree_compat(struct uk_alloc *a, void *ptr, unsigned long num_pages);
>   		uk_alloc_register((a));					\
>   	} while (0)
>   
> +#if CONFIG_LIBUKALLOC_IFMALLOC
> +#define uk_alloc_init_malloc_ifmalloc(a, malloc_f, free_f, addmem_f) 	\
> +	do {								\
> +		(a)->malloc         = uk_malloc_ifmalloc;		\
> +		(a)->calloc         = uk_calloc_compat;			\
> +		(a)->realloc        = uk_realloc_ifmalloc;		\
> +		(a)->posix_memalign = uk_posix_memalign_ifmalloc;	\
> +		(a)->memalign       = uk_memalign_compat;		\
> +		(a)->malloc_backend = (malloc_f);			\
> +		(a)->free_backend   = (free_f);				\
> +		(a)->free           = uk_free_ifmalloc;			\
> +		(a)->palloc         = uk_palloc_compat;			\
> +		(a)->pfree          = uk_pfree_compat;			\
> +		(a)->addmem         = (addmem_f);			\
> +									\
> +		uk_alloc_register((a));					\
> +	} while (0)
> +#endif
> +
>   /* Shortcut for doing a registration of an allocator that only
>    * implements palloc(), pfree(), addmem()
>    */
> 


From minios-devel-bounces@lists.xenproject.org Thu Jul 30 09:41:22 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 30 Jul 2020 09:41:22 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k153v-0006OI-Ex; Thu, 30 Jul 2020 09:41:19 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=rNVe=BJ=lancs.ac.uk=a.jung@srs-us1.protection.inumbo.net>)
 id 1k153u-0006OA-E8
 for minios-devel@lists.xen.org; Thu, 30 Jul 2020 09:41:18 +0000
X-Inumbo-ID: cfe7f2f8-d248-11ea-8d26-bc764e2007e4
Received: from mh-fa-0.lancs.ac.uk (unknown [148.88.65.130])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id cfe7f2f8-d248-11ea-8d26-bc764e2007e4;
 Thu, 30 Jul 2020 09:41:16 +0000 (UTC)
Received: from x4dbda693.dyn.telefonica.de ([77.189.166.147]
 helo=localhost.localdomain)
 by mh-fa-0.lancs.ac.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128)
 (Exim 4.92.3) (envelope-from <a.jung@lancs.ac.uk>)
 id 1k153q-000Dbd-6p; Thu, 30 Jul 2020 10:41:15 +0100
From: Alexander Jung <a.jung@lancs.ac.uk>
To: minios-devel@lists.xen.org
Subject: [UNIKRAFT PATCH] include: Move UK_NARGS into essentials.h
Date: Thu, 30 Jul 2020 11:41:00 +0200
Message-Id: <20200730094100.1473-1-a.jung@lancs.ac.uk>
X-Mailer: git-send-email 2.26.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.0 (-)
X-Spam-Bar: -
X-Spam-Report: Spam detection software, running on the system
 "mh-fa-0.lancs.ac.uk", has processed this message.
 The results are shown below. .
 Content analysis details:   (-1.0 points, 4.1 required) .
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>,
 Alexander Jung <a.jung@lancs.ac.uk>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

This macro counts the number of arguments passed into a macro and
is useful outside of the ukdebug library.

Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
---
 include/uk/essentials.h        | 5 +++++
 lib/ukdebug/include/uk/trace.h | 3 ---
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/include/uk/essentials.h b/include/uk/essentials.h
index 6989c97..6bcee2e 100644
--- a/include/uk/essentials.h
+++ b/include/uk/essentials.h
@@ -291,6 +291,11 @@ extern "C" {
 	char __assert_ ## y [(x) ? 1 : -1]
 #endif /* UK_CTASSERT */
 
+#ifndef UK_NARGS
+#define __UK_NARGS_X(a, b, c, d, e, f, g, h, n, ...) n
+#define UK_NARGS(...)  __UK_NARGS_X(, ##__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0)
+#endif /* UK_NARGS */
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/ukdebug/include/uk/trace.h b/lib/ukdebug/include/uk/trace.h
index 8745382..bc8da43 100644
--- a/lib/ukdebug/include/uk/trace.h
+++ b/lib/ukdebug/include/uk/trace.h
@@ -66,9 +66,6 @@ struct uk_tracepoint_header {
 extern size_t uk_trace_buffer_free;
 extern char *uk_trace_buffer_writep;
 
-#define __UK_NARGS_X(a, b, c, d, e, f, g, h, n, ...) n
-#define UK_NARGS(...)  __UK_NARGS_X(, ##__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0)
-
 
 static inline void __uk_trace_save_arg(char **pbuff,
 				      size_t *pfree,
-- 
2.11.0



From minios-devel-bounces@lists.xenproject.org Thu Jul 30 13:08:05 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 30 Jul 2020 13:08:05 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k18Hz-0006yP-GX; Thu, 30 Jul 2020 13:08:03 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=ZlbQ=BJ=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1k18Hy-0006yC-IY
 for minios-devel@lists.xenproject.org; Thu, 30 Jul 2020 13:08:02 +0000
X-Inumbo-ID: b17dbeb6-d265-11ea-8d46-bc764e2007e4
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id b17dbeb6-d265-11ea-8d46-bc764e2007e4;
 Thu, 30 Jul 2020 13:08:00 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id B373B103A92;
 Thu, 30 Jul 2020 15:07:59 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id Sm2I05pDWShx; Thu, 30 Jul 2020 15:07:59 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id 8FE6F1038E0
 for <minios-devel@lists.xenproject.org>; Thu, 30 Jul 2020 15:07:59 +0200 (CEST)
Received: from N-1237.office.hd (192.168.24.96) by titania.office.hd
 (192.168.24.89) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 30 Jul
 2020 15:07:59 +0200
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: <minios-devel@lists.xenproject.org>
Subject: [UNIKRAFT PATCH v3 0/2] lib/ukallocregion: add region-based allocator
Date: Thu, 30 Jul 2020 15:07:45 +0200
Message-ID: <cover.1596113182.git.hugo.lefeuvre@neclab.eu>
X-Mailer: git-send-email 2.7.4
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Add ukallocregion, a minimalist region-based allocator.

ukallocregion is a special-purpose memory allocator. It satisfies
allocation requests contiguously without bookkeeping. Allocations are
therefore realized in O(1), but deallocation is not supported. This
allocator can be useful as a baseline, or as a first level allocator
in a nested context. More information in patch descriptions.

Changes since v2:
 - improve OOM and integer overflow checks in malloc() and posix_memalign()

Changes since v1:
 - various minor improvements of menuconfig entries and descriptions
 - fix NEC headers
 - fix remaining // comments
 - align prevbase instead of newbase in uk_allocregion_malloc

Hugo Lefeuvre (2):
  lib/ukallocregion: add region-based allocator
  lib/ukboot: initialize ukallocregion

 lib/Makefile.uk                            |   1 +
 lib/ukallocregion/Config.uk                |  12 ++
 lib/ukallocregion/Makefile.uk              |   6 +
 lib/ukallocregion/exportsyms.uk            |   1 +
 lib/ukallocregion/include/uk/allocregion.h |  50 ++++++++
 lib/ukallocregion/region.c                 | 179 +++++++++++++++++++++++++++++
 lib/ukboot/Config.uk                       |  23 +++-
 lib/ukboot/boot.c                          |  19 ++-
 8 files changed, 281 insertions(+), 10 deletions(-)
 create mode 100644 lib/ukallocregion/Config.uk
 create mode 100644 lib/ukallocregion/Makefile.uk
 create mode 100644 lib/ukallocregion/exportsyms.uk
 create mode 100644 lib/ukallocregion/include/uk/allocregion.h
 create mode 100644 lib/ukallocregion/region.c

-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Thu Jul 30 13:08:08 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 30 Jul 2020 13:08:08 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k18I4-0006zB-I7; Thu, 30 Jul 2020 13:08:08 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=ZlbQ=BJ=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1k18I3-0006yC-Dq
 for minios-devel@lists.xenproject.org; Thu, 30 Jul 2020 13:08:07 +0000
X-Inumbo-ID: b2c185b5-d265-11ea-8d46-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id b2c185b5-d265-11ea-8d46-bc764e2007e4;
 Thu, 30 Jul 2020 13:08:04 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 555A7F2014;
 Thu, 30 Jul 2020 15:08:03 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id o_MiGIg5fXon; Thu, 30 Jul 2020 15:08:03 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 2E0F2F2013
 for <minios-devel@lists.xenproject.org>; Thu, 30 Jul 2020 15:08:01 +0200 (CEST)
Received: from N-1237.office.hd (192.168.24.96) by titania.office.hd
 (192.168.24.89) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 30 Jul
 2020 15:08:00 +0200
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: <minios-devel@lists.xenproject.org>
Subject: [UNIKRAFT PATCH v3 1/2] lib/ukallocregion: add region-based allocator
Date: Thu, 30 Jul 2020 15:07:46 +0200
Message-ID: <9e12ebeca5ac39fafdb2a8f501dc18114b913bfc.1596113182.git.hugo.lefeuvre@neclab.eu>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <cover.1596113182.git.hugo.lefeuvre@neclab.eu>
References: <cover.1596113182.git.hugo.lefeuvre@neclab.eu>
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Add ukallocregion, a minimalist region-based allocator.

Note that deallocation is not supported. This makes sense because regions
only allow for deallocation at region-granularity. In our case, this would
imply the freeing of the entire heap, which is generally not possible.

Obviously, the lack of deallocation support makes ukallocregion a fairly
bad general-purpose allocator. This allocator is interesting in that it
offers maximum speed allocation and deallocation (bounded O(1), no
bookkeeping). It can be used as a baseline for measurements (e.g., boot
time) or as a first-level allocator in a nested context.

Refer to Gay & Aiken, `Memory management with explicit regions' (PLDI'98)
for an introduction to region-based memory management.

Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
---
 lib/Makefile.uk                            |   1 +
 lib/ukallocregion/Config.uk                |  12 ++
 lib/ukallocregion/Makefile.uk              |   6 +
 lib/ukallocregion/exportsyms.uk            |   1 +
 lib/ukallocregion/include/uk/allocregion.h |  50 ++++++++
 lib/ukallocregion/region.c                 | 179 +++++++++++++++++++++++++++++
 6 files changed, 249 insertions(+)
 create mode 100644 lib/ukallocregion/Config.uk
 create mode 100644 lib/ukallocregion/Makefile.uk
 create mode 100644 lib/ukallocregion/exportsyms.uk
 create mode 100644 lib/ukallocregion/include/uk/allocregion.h
 create mode 100644 lib/ukallocregion/region.c

diff --git a/lib/Makefile.uk b/lib/Makefile.uk
index aa7e730..1f223d2 100644
--- a/lib/Makefile.uk
+++ b/lib/Makefile.uk
@@ -14,6 +14,7 @@ $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uktimeconv))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/nolibc))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukalloc))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukallocbbuddy))
+$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukallocregion))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uksched))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukschedcoop))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/fdt))
diff --git a/lib/ukallocregion/Config.uk b/lib/ukallocregion/Config.uk
new file mode 100644
index 0000000..0012677
--- /dev/null
+++ b/lib/ukallocregion/Config.uk
@@ -0,0 +1,12 @@
+config LIBUKALLOCREGION
+	bool "ukallocregion: Region-based allocator"
+	default n
+	select LIBNOLIBC if !HAVE_LIBC
+	select LIBUKDEBUG
+	select LIBUKALLOC
+	help
+	  Satisfy allocations as fast as possible, without bookkeeping. No
+	  support for free(): when the end of the allocation pool is reached,
+	  the allocator runs out-of-memory. This allocator is useful for
+	  experimentation, as baseline, or as first-level allocator in a nested
+	  context.
diff --git a/lib/ukallocregion/Makefile.uk b/lib/ukallocregion/Makefile.uk
new file mode 100644
index 0000000..05a3d67
--- /dev/null
+++ b/lib/ukallocregion/Makefile.uk
@@ -0,0 +1,6 @@
+$(eval $(call addlib_s,libukallocregion,$(CONFIG_LIBUKALLOCREGION)))
+
+CINCLUDES-$(CONFIG_LIBUKALLOCREGION)	+= -I$(LIBUKALLOCREGION_BASE)/include
+CXXINCLUDES-$(CONFIG_LIBUKALLOCREGION)	+= -I$(LIBUKALLOCREGION_BASE)/include
+
+LIBUKALLOCREGION_SRCS-y += $(LIBUKALLOCREGION_BASE)/region.c
diff --git a/lib/ukallocregion/exportsyms.uk b/lib/ukallocregion/exportsyms.uk
new file mode 100644
index 0000000..481bc10
--- /dev/null
+++ b/lib/ukallocregion/exportsyms.uk
@@ -0,0 +1 @@
+uk_allocregion_init
diff --git a/lib/ukallocregion/include/uk/allocregion.h b/lib/ukallocregion/include/uk/allocregion.h
new file mode 100644
index 0000000..863ef6c
--- /dev/null
+++ b/lib/ukallocregion/include/uk/allocregion.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation,
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __LIBUKALLOCREGION_H__
+#define __LIBUKALLOCREGION_H__
+
+#include <uk/alloc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* allocator initialization */
+struct uk_alloc *uk_allocregion_init(void *base, size_t len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LIBUKALLOCREGION_H__ */
diff --git a/lib/ukallocregion/region.c b/lib/ukallocregion/region.c
new file mode 100644
index 0000000..5fbeebf
--- /dev/null
+++ b/lib/ukallocregion/region.c
@@ -0,0 +1,179 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
+ *
+ * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation,
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* ukallocregion is a minimalist region implementation.
+ *
+ * Note that deallocation is not supported. This makes sense because regions
+ * only allow for deallocation at region-granularity. In our case, this would
+ * imply the freeing of the entire heap, which is generally not possible.
+ *
+ * Obviously, the lack of deallocation support makes ukallocregion a fairly bad
+ * general-purpose allocator. This allocator is interesting in that it offers
+ * maximum speed allocation and deallocation (no bookkeeping). It can be used as
+ * a baseline for measurements (e.g., boot time) or as a first-level allocator
+ * in a nested context.
+ *
+ * Refer to Gay & Aiken, `Memory management with explicit regions' (PLDI'98) for
+ * an introduction to region-based memory management.
+ */
+
+#include <uk/allocregion.h>
+#include <uk/alloc_impl.h>
+#include <uk/page.h>	/* round_pgup() */
+
+struct uk_allocregion {
+	void *heap_top;
+	void *heap_base;
+};
+
+void *uk_allocregion_malloc(struct uk_alloc *a, size_t size)
+{
+	struct uk_allocregion *b;
+	uintptr_t intptr, newbase;
+
+	UK_ASSERT(a != NULL);
+
+	b = (struct uk_allocregion *)&a->priv;
+
+	/* return aligned pointers: this is a requirement for some
+	 * embedded systems archs, and more generally good for performance
+	 */
+	intptr = ALIGN_UP(((uintptr_t) b->heap_base),
+			     (uintptr_t) sizeof(void *));
+
+	newbase  = intptr + size;
+	if (newbase > (uintptr_t) b->heap_top)
+		return NULL; /* OOM */
+
+	/* Check for overflow, handle malloc(0) */
+	if (newbase <= b->heap_base)
+		return NULL;
+
+	b->heap_base = (void *)(newbase);
+
+	return (void *) intptr;
+}
+
+int uk_allocregion_posix_memalign(struct uk_alloc *a, void **memptr,
+					size_t align, size_t size)
+{
+	struct uk_allocregion *b;
+	uintptr_t intptr, newbase;
+
+	UK_ASSERT(a != NULL);
+
+	b = (struct uk_allocregion *)&a->priv;
+
+	/* align must be a power of two */
+	UK_ASSERT(((align - 1) & align) == 0);
+
+	/* align must be larger than pointer size */
+	UK_ASSERT((align % sizeof(void *)) == 0);
+
+	if (!size) {
+		*memptr = NULL;
+		return EINVAL;
+	}
+
+	intptr = ALIGN_UP((uintptr_t) b->heap_base, (uintptr_t) align);
+
+	newbase  = intptr + size;
+	if (newbase > (uintptr_t) b->heap_top)
+		return ENOMEM; /* out-of-memory */
+
+	/* Check for overflow */
+	if (newbase <= b->heap_base)
+		return EINVAL;
+
+	*memptr = (void *)intptr;
+	b->heap_base = (void *)(newbase);
+
+	return 0;
+}
+
+void uk_allocregion_free(struct uk_alloc *a __unused, void *ptr __unused)
+{
+	uk_pr_debug("%p: Releasing of memory is not supported by "
+			"ukallocregion\n", a);
+}
+
+int uk_allocregion_addmem(struct uk_alloc *a __unused, void *base __unused,
+				size_t size __unused)
+{
+	/* TODO: support multiple regions */
+	uk_pr_debug("%p: ukallocregion does not support multiple memory "
+			"regions\n", a);
+	return 0;
+}
+
+struct uk_alloc *uk_allocregion_init(void *base, size_t len)
+{
+	struct uk_alloc *a;
+	struct uk_allocregion *b;
+	size_t metalen = sizeof(*a) + sizeof(*b);
+
+	/* TODO: ukallocregion does not support multiple memory regions yet.
+	 * Because of the multiboot layout, the first region might be a single
+	 * page, so we simply ignore it.
+	 */
+	if (len <= __PAGE_SIZE)
+		return NULL;
+
+	/* enough space for allocator available? */
+	if (metalen > len) {
+		uk_pr_err("Not enough space for allocator: %"__PRIsz
+			  " B required but only %"__PRIuptr" B usable\n",
+			  metalen, len);
+		return NULL;
+	}
+
+	/* store allocator metadata on the heap, just before the memory pool */
+	a = (struct uk_alloc *)base;
+	b = (struct uk_allocregion *)&a->priv;
+
+	uk_pr_info("Initialize allocregion allocator @ 0x%"
+		   __PRIuptr ", len %"__PRIsz"\n", (uintptr_t)a, len);
+
+	b->heap_top  = (void *)((uintptr_t) base + len);
+	b->heap_base = (void *)((uintptr_t) base + metalen);
+
+	/* use exclusively "compat" wrappers for calloc, realloc, memalign,
+	 * palloc and pfree as those do not add additional metadata.
+	 */
+	uk_alloc_init_malloc(a, uk_allocregion_malloc, uk_calloc_compat,
+				uk_realloc_compat, uk_allocregion_free,
+				uk_allocregion_posix_memalign,
+				uk_memalign_compat, NULL);
+
+	return a;
+}
-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Thu Jul 30 13:08:13 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 30 Jul 2020 13:08:13 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k18I9-00070A-Js; Thu, 30 Jul 2020 13:08:13 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=ZlbQ=BJ=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1k18I8-0006yC-E6
 for minios-devel@lists.xenproject.org; Thu, 30 Jul 2020 13:08:12 +0000
X-Inumbo-ID: b4e3d1d0-d265-11ea-8d46-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id b4e3d1d0-d265-11ea-8d46-bc764e2007e4;
 Thu, 30 Jul 2020 13:08:06 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 60975F2015;
 Thu, 30 Jul 2020 15:08:05 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id pF72Z2hxoI5w; Thu, 30 Jul 2020 15:08:05 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 3739DF2013
 for <minios-devel@lists.xenproject.org>; Thu, 30 Jul 2020 15:08:03 +0200 (CEST)
Received: from N-1237.office.hd (192.168.24.96) by titania.office.hd
 (192.168.24.89) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 30 Jul
 2020 15:08:01 +0200
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: <minios-devel@lists.xenproject.org>
Subject: [UNIKRAFT PATCH v3 2/2] lib/ukboot: initialize ukallocregion
Date: Thu, 30 Jul 2020 15:07:47 +0200
Message-ID: <e4105a0b6c3a7a7c9a1584758d1c0e328aefa6b9.1596113182.git.hugo.lefeuvre@neclab.eu>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <cover.1596113182.git.hugo.lefeuvre@neclab.eu>
References: <cover.1596113182.git.hugo.lefeuvre@neclab.eu>
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Add menuconfig bindings to select a system-wide allocator.
Initialize the selected allocator in ukboot.

Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
---
 lib/ukboot/Config.uk | 23 +++++++++++++++++++----
 lib/ukboot/boot.c    | 19 +++++++++++++------
 2 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/lib/ukboot/Config.uk b/lib/ukboot/Config.uk
index 841a876..07139e2 100644
--- a/lib/ukboot/Config.uk
+++ b/lib/ukboot/Config.uk
@@ -17,8 +17,23 @@ if LIBUKBOOT
 	int "Maximum number of arguments (max. size of argv)"
 	default 60
 
-	config LIBUKBOOT_INITALLOC
-	bool "Initialize ukallocbbuddy as allocator"
-	default y
-	select LIBUKALLOCBBUDDY
+	choice LIBUKBOOT_INITALLOC
+	prompt "Initialize memory allocator"
+	default LIBUKBOOT_INITBBUDDY
+
+		config LIBUKBOOT_INITBBUDDY
+		bool "Binary buddy allocator"
+		select LIBUKALLOCBBUDDY
+
+		config LIBUKBOOT_INITREGION
+		bool "Region allocator"
+		select LIBUKALLOCREGION
+		help
+		  Satisfy allocation as fast as possible. No support for free().
+		  Refer to help in ukallocregion for more information.
+
+		config LIBUKBOOT_NOALLOC
+		bool "None"
+
+	endchoice
 endif
diff --git a/lib/ukboot/boot.c b/lib/ukboot/boot.c
index e8a2ac7..4e749aa 100644
--- a/lib/ukboot/boot.c
+++ b/lib/ukboot/boot.c
@@ -41,8 +41,10 @@
 #include <stdio.h>
 #include <errno.h>
 
-#if CONFIG_LIBUKALLOC && CONFIG_LIBUKALLOCBBUDDY && CONFIG_LIBUKBOOT_INITALLOC
+#if CONFIG_LIBUKBOOT_INITBBUDDY
 #include <uk/allocbbuddy.h>
+#elif CONFIG_LIBUKBOOT_INITREGION
+#include <uk/allocregion.h>
 #endif
 #if CONFIG_LIBUKSCHED
 #include <uk/sched.h>
@@ -178,7 +180,7 @@ void ukplat_entry(int argc, char *argv[])
 #if CONFIG_LIBUKALLOC
 	struct uk_alloc *a = NULL;
 #endif
-#if CONFIG_LIBUKALLOC && CONFIG_LIBUKALLOCBBUDDY && CONFIG_LIBUKBOOT_INITALLOC
+#if !CONFIG_LIBUKBOOT_NOALLOC
 	struct ukplat_memregion_desc md;
 #endif
 #if CONFIG_LIBUKSCHED
@@ -205,9 +207,9 @@ void ukplat_entry(int argc, char *argv[])
 	}
 #endif /* CONFIG_LIBUKLIBPARAM */
 
-#if CONFIG_LIBUKALLOC && CONFIG_LIBUKALLOCBBUDDY && CONFIG_LIBUKBOOT_INITALLOC
+#if !CONFIG_LIBUKBOOT_NOALLOC
 	/* initialize memory allocator
-	 * FIXME: ukallocbbuddy is hard-coded for now
+	 * FIXME: allocators are hard-coded for now
 	 */
 	uk_pr_info("Initialize memory allocator...\n");
 	ukplat_memregion_foreach(&md, UKPLAT_MEMRF_ALLOCATABLE) {
@@ -226,10 +228,15 @@ void ukplat_entry(int argc, char *argv[])
 		 * As soon we have an allocator, we simply add every
 		 * subsequent region to it
 		 */
-		if (unlikely(!a))
+		if (!a) {
+#if CONFIG_LIBUKBOOT_INITBBUDDY
 			a = uk_allocbbuddy_init(md.base, md.len);
-		else
+#elif CONFIG_LIBUKBOOT_INITREGION
+			a = uk_allocregion_init(md.base, md.len);
+#endif
+		} else {
 			uk_alloc_addmem(a, md.base, md.len);
+		}
 	}
 	if (unlikely(!a))
 		uk_pr_warn("No suitable memory region for memory allocator. Continue without heap\n");
-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Thu Jul 30 14:48:51 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 30 Jul 2020 14:48:51 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k19rU-00084i-4j; Thu, 30 Jul 2020 14:48:48 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=ZlbQ=BJ=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1k19rT-00084d-HP
 for minios-devel@lists.xenproject.org; Thu, 30 Jul 2020 14:48:47 +0000
X-Inumbo-ID: c3a08868-d273-11ea-aad8-12813bfff9fa
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id c3a08868-d273-11ea-aad8-12813bfff9fa;
 Thu, 30 Jul 2020 14:48:44 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id F1FF4103EAE;
 Thu, 30 Jul 2020 16:48:42 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id FLaQjnsJxHeR; Thu, 30 Jul 2020 16:48:42 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id D0D12103A92
 for <minios-devel@lists.xenproject.org>; Thu, 30 Jul 2020 16:48:42 +0200 (CEST)
Received: from N-1237.office.hd (192.168.24.96) by titania.office.hd
 (192.168.24.89) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 30 Jul
 2020 16:48:42 +0200
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: <minios-devel@lists.xenproject.org>
Subject: [UNIKRAFT PATCH v2] lib/ukalloc: add ifmalloc compatibility interface
Date: Thu, 30 Jul 2020 16:48:35 +0200
Message-ID: <7fa75a41526504326a646e28e57eba0b18d2c10b.1596120236.git.hugo.lefeuvre@neclab.eu>
X-Mailer: git-send-email 2.7.4
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: oberon.office.hd (192.168.24.90) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Add ifmalloc, the malloc compatibility interface. This interface implements
a POSIX compliant allocation interface on top of a simple malloc() and
free() interface. This interface is similar to ifpages, which does the same
for palloc() and pfree().

ifmalloc will be used for the port of TLSF and tinyalloc which do not
support (posix_)memalign().

Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
---
Changed since v1:
 - update alloc.c file header
 - use METADATA_IFMALLOC_SIZE_POW2 instead of sizeof(struct metadata_ifmalloc)
 - add unlikely where appropriate
 - use align < sizeof(void *) instead of (align % sizeof(void *)) != 0
 - minor optimizations and style-related changes

 lib/ukalloc/Config.uk               |   5 ++
 lib/ukalloc/alloc.c                 | 148 +++++++++++++++++++++++++++++++++++-
 lib/ukalloc/exportsyms.uk           |   4 +
 lib/ukalloc/include/uk/alloc.h      |   5 ++
 lib/ukalloc/include/uk/alloc_impl.h |  27 +++++++
 5 files changed, 186 insertions(+), 3 deletions(-)

diff --git a/lib/ukalloc/Config.uk b/lib/ukalloc/Config.uk
index 0de7464..c965d08 100644
--- a/lib/ukalloc/Config.uk
+++ b/lib/ukalloc/Config.uk
@@ -5,6 +5,11 @@ menuconfig LIBUKALLOC
 	select LIBUKDEBUG
 
 if LIBUKALLOC
+	config LIBUKALLOC_IFMALLOC
+		bool "Malloc compatibility interface"
+		default n
+		help
+			Provide helpers for allocators defining exclusively malloc and free
 	config LIBUKALLOC_IFSTATS
 		bool "Statistics interface"
 		default n
diff --git a/lib/ukalloc/alloc.c b/lib/ukalloc/alloc.c
index 127bc6f..160a0a4 100644
--- a/lib/ukalloc/alloc.c
+++ b/lib/ukalloc/alloc.c
@@ -1,8 +1,10 @@
 /* SPDX-License-Identifier: BSD-3-Clause */
 /*
  * Authors: Florian Schmidt <florian.schmidt@neclab.eu>
+ *          Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
  *
- * Copyright (c) 2017, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ * Copyright (c) 2017-2020, NEC Laboratories Europe GmbH, NEC Corporation,
+ *                          All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -28,8 +30,6 @@
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
- *
- * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
  */
 
 /* This is a very simple, naive implementation of malloc.
@@ -52,6 +52,7 @@
 #include <uk/essentials.h>
 #include <uk/assert.h>
 #include <uk/arch/limits.h>
+#include <uk/arch/lcpu.h>
 
 #define size_to_num_pages(size) \
 	(ALIGN_UP((unsigned long)(size), __PAGE_SIZE) / __PAGE_SIZE)
@@ -267,6 +268,147 @@ int uk_posix_memalign_ifpages(struct uk_alloc *a,
 	return 0;
 }
 
+#if CONFIG_LIBUKALLOC_IFMALLOC
+
+struct metadata_ifmalloc {
+	size_t	size;
+	void	*base;
+};
+
+#define METADATA_IFMALLOC_SIZE_POW2 16
+UK_CTASSERT(!(sizeof(struct metadata_ifmalloc) > METADATA_IFMALLOC_SIZE_POW2));
+
+static struct metadata_ifmalloc *uk_get_metadata_ifmalloc(const void *ptr)
+{
+	return (struct metadata_ifmalloc *)((uintptr_t) ptr -
+		METADATA_IFMALLOC_SIZE_POW2);
+}
+
+static size_t uk_getmallocsize_ifmalloc(const void *ptr)
+{
+	struct metadata_ifmalloc *metadata = uk_get_metadata_ifmalloc(ptr);
+	return (size_t) ((uintptr_t) metadata->base + metadata->size -
+			 (uintptr_t) ptr);
+}
+
+void uk_free_ifmalloc(struct uk_alloc *a, void *ptr)
+{
+	struct metadata_ifmalloc *metadata;
+
+	UK_ASSERT(a);
+	UK_ASSERT(a->free_backend);
+	if (!ptr)
+		return;
+
+	metadata = uk_get_metadata_ifmalloc(ptr);
+	a->free_backend(a, metadata->base);
+}
+
+void *uk_malloc_ifmalloc(struct uk_alloc *a, size_t size)
+{
+	struct metadata_ifmalloc *metadata;
+	size_t realsize = size + METADATA_IFMALLOC_SIZE_POW2;
+	void *ptr;
+
+	UK_ASSERT(a);
+	UK_ASSERT(a->malloc_backend);
+
+	/* check for overflow */
+	if (unlikely(realsize < size))
+		return NULL;
+
+	ptr = a->malloc_backend(a, realsize);
+	if (!ptr)
+		return NULL;
+
+	metadata = ptr;
+	metadata->size = realsize;
+	metadata->base = ptr;
+
+	return (void *) ((uintptr_t) ptr + METADATA_IFMALLOC_SIZE_POW2);
+}
+
+void *uk_realloc_ifmalloc(struct uk_alloc *a, void *ptr, size_t size)
+{
+	void *retptr;
+	size_t mallocsize;
+
+	UK_ASSERT(a);
+	if (!ptr)
+		return uk_malloc_ifmalloc(a, size);
+
+	if (ptr && !size) {
+		uk_free_ifmalloc(a, ptr);
+		return NULL;
+	}
+
+	retptr = uk_malloc_ifmalloc(a, size);
+	if (!retptr)
+		return NULL;
+
+	mallocsize = uk_getmallocsize_ifmalloc(ptr);
+
+	memcpy(retptr, ptr, MIN(size, mallocsize));
+
+	uk_free_ifmalloc(a, ptr);
+	return retptr;
+}
+
+int uk_posix_memalign_ifmalloc(struct uk_alloc *a,
+				     void **memptr, size_t align, size_t size)
+{
+	struct metadata_ifmalloc *metadata;
+	size_t realsize, padding;
+	uintptr_t intptr;
+
+	UK_ASSERT(a);
+	if (((align - 1) & align) != 0
+	    || align < sizeof(void *))
+		return EINVAL;
+
+	if (!size) {
+		*memptr = NULL;
+		return EINVAL;
+	}
+
+	/* Store size information preceeding the memory block. Since we return
+	 * pointers aligned at `align` we need to reserve at least that much
+	 * space for the size information.
+	 */
+	if (align < METADATA_IFMALLOC_SIZE_POW2) {
+		align = METADATA_IFMALLOC_SIZE_POW2;
+		padding = 0;
+	} else {
+		padding = METADATA_IFMALLOC_SIZE_POW2;
+	}
+
+	realsize = size + padding + align;
+
+	/* check for overflow */
+	if (unlikely(realsize < size))
+		return NULL;
+
+	intptr = (uintptr_t) a->malloc_backend(a, realsize);
+
+	if (!intptr)
+		return ENOMEM;
+
+	*memptr = (void *) ALIGN_UP(intptr + METADATA_IFMALLOC_SIZE_POW2,
+				    (uintptr_t) align);
+
+	metadata = uk_get_metadata_ifmalloc(*memptr);
+
+	/* check for underflow */
+	UK_ASSERT(intptr <= (uintptr_t) metadata);
+
+	metadata->size = realsize;
+	metadata->base = (void *) intptr;
+
+	return 0;
+}
+
+#endif
+
 void uk_pfree_compat(struct uk_alloc *a, void *ptr,
 		     unsigned long num_pages __unused)
 {
diff --git a/lib/ukalloc/exportsyms.uk b/lib/ukalloc/exportsyms.uk
index 2c8a90f..21c1996 100644
--- a/lib/ukalloc/exportsyms.uk
+++ b/lib/ukalloc/exportsyms.uk
@@ -4,6 +4,10 @@ uk_malloc_ifpages
 uk_free_ifpages
 uk_realloc_ifpages
 uk_posix_memalign_ifpages
+uk_malloc_ifmalloc
+uk_realloc_ifmalloc
+uk_posix_memalign_ifmalloc
+uk_free_ifmalloc
 uk_calloc_compat
 uk_memalign_compat
 uk_realloc_compat
diff --git a/lib/ukalloc/include/uk/alloc.h b/lib/ukalloc/include/uk/alloc.h
index 5bfa2f2..1457922 100644
--- a/lib/ukalloc/include/uk/alloc.h
+++ b/lib/ukalloc/include/uk/alloc.h
@@ -85,6 +85,11 @@ struct uk_alloc {
 	uk_alloc_memalign_func_t memalign;
 	uk_alloc_free_func_t free;
 
+#if CONFIG_LIBUKALLOC_IFMALLOC
+	uk_alloc_free_func_t free_backend;
+	uk_alloc_malloc_func_t malloc_backend;
+#endif
+
 	/* page allocation interface */
 	uk_alloc_palloc_func_t palloc;
 	uk_alloc_pfree_func_t pfree;
diff --git a/lib/ukalloc/include/uk/alloc_impl.h b/lib/ukalloc/include/uk/alloc_impl.h
index 8bcca94..b15f49e 100644
--- a/lib/ukalloc/include/uk/alloc_impl.h
+++ b/lib/ukalloc/include/uk/alloc_impl.h
@@ -62,6 +62,14 @@ int uk_posix_memalign_ifpages(struct uk_alloc *a, void **memptr,
 				size_t align, size_t size);
 void uk_free_ifpages(struct uk_alloc *a, void *ptr);
 
+#if CONFIG_LIBUKALLOC_IFMALLOC
+void *uk_malloc_ifmalloc(struct uk_alloc *a, size_t size);
+void *uk_realloc_ifmalloc(struct uk_alloc *a, void *ptr, size_t size);
+int uk_posix_memalign_ifmalloc(struct uk_alloc *a, void **memptr,
+				     size_t align, size_t size);
+void uk_free_ifmalloc(struct uk_alloc *a, void *ptr);
+#endif
+
 /* Functionality that is provided based on malloc() and posix_memalign() */
 void *uk_calloc_compat(struct uk_alloc *a, size_t num, size_t len);
 void *uk_realloc_compat(struct uk_alloc *a, void *ptr, size_t size);
@@ -88,6 +96,25 @@ void uk_pfree_compat(struct uk_alloc *a, void *ptr, unsigned long num_pages);
 		uk_alloc_register((a));					\
 	} while (0)
 
+#if CONFIG_LIBUKALLOC_IFMALLOC
+#define uk_alloc_init_malloc_ifmalloc(a, malloc_f, free_f, addmem_f) 	\
+	do {								\
+		(a)->malloc         = uk_malloc_ifmalloc;		\
+		(a)->calloc         = uk_calloc_compat;			\
+		(a)->realloc        = uk_realloc_ifmalloc;		\
+		(a)->posix_memalign = uk_posix_memalign_ifmalloc;	\
+		(a)->memalign       = uk_memalign_compat;		\
+		(a)->malloc_backend = (malloc_f);			\
+		(a)->free_backend   = (free_f);				\
+		(a)->free           = uk_free_ifmalloc;			\
+		(a)->palloc         = uk_palloc_compat;			\
+		(a)->pfree          = uk_pfree_compat;			\
+		(a)->addmem         = (addmem_f);			\
+									\
+		uk_alloc_register((a));					\
+	} while (0)
+#endif
+
 /* Shortcut for doing a registration of an allocator that only
  * implements palloc(), pfree(), addmem()
  */
-- 
2.7.4



From minios-devel-bounces@lists.xenproject.org Thu Jul 30 15:32:34 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 30 Jul 2020 15:32:34 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k1AXn-0003jW-Me; Thu, 30 Jul 2020 15:32:31 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=u4H1=BJ=neclab.eu=simon.kuenzer@srs-us1.protection.inumbo.net>)
 id 1k1AXn-0003jR-1u
 for minios-devel@lists.xenproject.org; Thu, 30 Jul 2020 15:32:31 +0000
X-Inumbo-ID: df33c90f-d279-11ea-aae4-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id df33c90f-d279-11ea-aae4-12813bfff9fa;
 Thu, 30 Jul 2020 15:32:28 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 3E5CAF2016;
 Thu, 30 Jul 2020 17:32:27 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id G-zw4Vpf2QEV; Thu, 30 Jul 2020 17:32:27 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 01D4BF2013
 for <minios-devel@lists.xenproject.org>; Thu, 30 Jul 2020 17:32:24 +0200 (CEST)
Received: from [10.7.1.42] (192.168.24.96) by puck.office.hd (192.168.24.91)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 30 Jul
 2020 17:32:24 +0200
Subject: Re: [UNIKRAFT PATCH v3 1/2] lib/ukallocregion: add region-based
 allocator
To: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>,
 <minios-devel@lists.xenproject.org>
References: <cover.1596113182.git.hugo.lefeuvre@neclab.eu>
 <9e12ebeca5ac39fafdb2a8f501dc18114b913bfc.1596113182.git.hugo.lefeuvre@neclab.eu>
From: Simon Kuenzer <simon.kuenzer@neclab.eu>
Message-ID: <28e11470-803b-afd5-ecb6-61a69c9037fd@neclab.eu>
Date: Thu, 30 Jul 2020 17:32:11 +0200
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0)
 Gecko/20100101 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <9e12ebeca5ac39fafdb2a8f501dc18114b913bfc.1596113182.git.hugo.lefeuvre@neclab.eu>
Content-Type: text/plain; charset="utf-8"; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hey Hugo,

this patch looks good. During upstreaming, I am going to add another 
assertion and a missing type cast to get the compiler quiet.

Thanks a lot for your work,

Simon

Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>

On 30.07.20 15:07, Hugo Lefeuvre wrote:
> Add ukallocregion, a minimalist region-based allocator.
> 
> Note that deallocation is not supported. This makes sense because regions
> only allow for deallocation at region-granularity. In our case, this would
> imply the freeing of the entire heap, which is generally not possible.
> 
> Obviously, the lack of deallocation support makes ukallocregion a fairly
> bad general-purpose allocator. This allocator is interesting in that it
> offers maximum speed allocation and deallocation (bounded O(1), no
> bookkeeping). It can be used as a baseline for measurements (e.g., boot
> time) or as a first-level allocator in a nested context.
> 
> Refer to Gay & Aiken, `Memory management with explicit regions' (PLDI'98)
> for an introduction to region-based memory management.
> 
> Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> ---
>   lib/Makefile.uk                            |   1 +
>   lib/ukallocregion/Config.uk                |  12 ++
>   lib/ukallocregion/Makefile.uk              |   6 +
>   lib/ukallocregion/exportsyms.uk            |   1 +
>   lib/ukallocregion/include/uk/allocregion.h |  50 ++++++++
>   lib/ukallocregion/region.c                 | 179 +++++++++++++++++++++++++++++
>   6 files changed, 249 insertions(+)
>   create mode 100644 lib/ukallocregion/Config.uk
>   create mode 100644 lib/ukallocregion/Makefile.uk
>   create mode 100644 lib/ukallocregion/exportsyms.uk
>   create mode 100644 lib/ukallocregion/include/uk/allocregion.h
>   create mode 100644 lib/ukallocregion/region.c
> 
> diff --git a/lib/Makefile.uk b/lib/Makefile.uk
> index aa7e730..1f223d2 100644
> --- a/lib/Makefile.uk
> +++ b/lib/Makefile.uk
> @@ -14,6 +14,7 @@ $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uktimeconv))
>   $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/nolibc))
>   $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukalloc))
>   $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukallocbbuddy))
> +$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukallocregion))
>   $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uksched))
>   $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukschedcoop))
>   $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/fdt))
> diff --git a/lib/ukallocregion/Config.uk b/lib/ukallocregion/Config.uk
> new file mode 100644
> index 0000000..0012677
> --- /dev/null
> +++ b/lib/ukallocregion/Config.uk
> @@ -0,0 +1,12 @@
> +config LIBUKALLOCREGION
> +	bool "ukallocregion: Region-based allocator"
> +	default n
> +	select LIBNOLIBC if !HAVE_LIBC
> +	select LIBUKDEBUG
> +	select LIBUKALLOC
> +	help
> +	  Satisfy allocations as fast as possible, without bookkeeping. No
> +	  support for free(): when the end of the allocation pool is reached,
> +	  the allocator runs out-of-memory. This allocator is useful for
> +	  experimentation, as baseline, or as first-level allocator in a nested
> +	  context.
> diff --git a/lib/ukallocregion/Makefile.uk b/lib/ukallocregion/Makefile.uk
> new file mode 100644
> index 0000000..05a3d67
> --- /dev/null
> +++ b/lib/ukallocregion/Makefile.uk
> @@ -0,0 +1,6 @@
> +$(eval $(call addlib_s,libukallocregion,$(CONFIG_LIBUKALLOCREGION)))
> +
> +CINCLUDES-$(CONFIG_LIBUKALLOCREGION)	+= -I$(LIBUKALLOCREGION_BASE)/include
> +CXXINCLUDES-$(CONFIG_LIBUKALLOCREGION)	+= -I$(LIBUKALLOCREGION_BASE)/include
> +
> +LIBUKALLOCREGION_SRCS-y += $(LIBUKALLOCREGION_BASE)/region.c
> diff --git a/lib/ukallocregion/exportsyms.uk b/lib/ukallocregion/exportsyms.uk
> new file mode 100644
> index 0000000..481bc10
> --- /dev/null
> +++ b/lib/ukallocregion/exportsyms.uk
> @@ -0,0 +1 @@
> +uk_allocregion_init
> diff --git a/lib/ukallocregion/include/uk/allocregion.h b/lib/ukallocregion/include/uk/allocregion.h
> new file mode 100644
> index 0000000..863ef6c
> --- /dev/null
> +++ b/lib/ukallocregion/include/uk/allocregion.h
> @@ -0,0 +1,50 @@
> +/* SPDX-License-Identifier: BSD-3-Clause */
> +/*
> + * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> + *
> + * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation,
> + *                     All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + *
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in the
> + *    documentation and/or other materials provided with the distribution.
> + * 3. Neither the name of the copyright holder nor the names of its
> + *    contributors may be used to endorse or promote products derived from
> + *    this software without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#ifndef __LIBUKALLOCREGION_H__
> +#define __LIBUKALLOCREGION_H__
> +
> +#include <uk/alloc.h>
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +/* allocator initialization */
> +struct uk_alloc *uk_allocregion_init(void *base, size_t len);
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +#endif /* __LIBUKALLOCREGION_H__ */
> diff --git a/lib/ukallocregion/region.c b/lib/ukallocregion/region.c
> new file mode 100644
> index 0000000..5fbeebf
> --- /dev/null
> +++ b/lib/ukallocregion/region.c
> @@ -0,0 +1,179 @@
> +/* SPDX-License-Identifier: BSD-3-Clause */
> +/*
> + * Authors: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> + *
> + * Copyright (c) 2020, NEC Laboratories Europe GmbH, NEC Corporation,
> + *                     All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + *
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in the
> + *    documentation and/or other materials provided with the distribution.
> + * 3. Neither the name of the copyright holder nor the names of its
> + *    contributors may be used to endorse or promote products derived from
> + *    this software without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +/* ukallocregion is a minimalist region implementation.
> + *
> + * Note that deallocation is not supported. This makes sense because regions
> + * only allow for deallocation at region-granularity. In our case, this would
> + * imply the freeing of the entire heap, which is generally not possible.
> + *
> + * Obviously, the lack of deallocation support makes ukallocregion a fairly bad
> + * general-purpose allocator. This allocator is interesting in that it offers
> + * maximum speed allocation and deallocation (no bookkeeping). It can be used as
> + * a baseline for measurements (e.g., boot time) or as a first-level allocator
> + * in a nested context.
> + *
> + * Refer to Gay & Aiken, `Memory management with explicit regions' (PLDI'98) for
> + * an introduction to region-based memory management.
> + */
> +
> +#include <uk/allocregion.h>
> +#include <uk/alloc_impl.h>
> +#include <uk/page.h>	/* round_pgup() */
> +
> +struct uk_allocregion {
> +	void *heap_top;
> +	void *heap_base;
> +};
> +
> +void *uk_allocregion_malloc(struct uk_alloc *a, size_t size)
> +{
> +	struct uk_allocregion *b;
> +	uintptr_t intptr, newbase;
> +
> +	UK_ASSERT(a != NULL);
> +
> +	b = (struct uk_allocregion *)&a->priv;
> +

I am going to add another assertion that makes sure (b != NULL).

> +	/* return aligned pointers: this is a requirement for some
> +	 * embedded systems archs, and more generally good for performance
> +	 */
> +	intptr = ALIGN_UP(((uintptr_t) b->heap_base),
> +			     (uintptr_t) sizeof(void *));
> +
> +	newbase  = intptr + size;
> +	if (newbase > (uintptr_t) b->heap_top)
> +		return NULL; /* OOM */
> +
> +	/* Check for overflow, handle malloc(0) */
> +	if (newbase <= b->heap_base)

A cast to (uintptr_t) is missing which causes a compiler warning. I am 
adding it while upstreaming.

> +		return NULL;
> +
> +	b->heap_base = (void *)(newbase);
> +
> +	return (void *) intptr;
> +}
> +
> +int uk_allocregion_posix_memalign(struct uk_alloc *a, void **memptr,
> +					size_t align, size_t size)
> +{
> +	struct uk_allocregion *b;
> +	uintptr_t intptr, newbase;
> +
> +	UK_ASSERT(a != NULL);
> +
> +	b = (struct uk_allocregion *)&a->priv;

I am adding another assertion here regarding b.

> +
> +	/* align must be a power of two */
> +	UK_ASSERT(((align - 1) & align) == 0);
> +
> +	/* align must be larger than pointer size */
> +	UK_ASSERT((align % sizeof(void *)) == 0);
> +
> +	if (!size) {
> +		*memptr = NULL;
> +		return EINVAL;
> +	}
> +
> +	intptr = ALIGN_UP((uintptr_t) b->heap_base, (uintptr_t) align);
> +
> +	newbase  = intptr + size;
> +	if (newbase > (uintptr_t) b->heap_top)
> +		return ENOMEM; /* out-of-memory */
> +
> +	/* Check for overflow */
> +	if (newbase <= b->heap_base)

Another missing cast (uintptr_t) that I will add while upstreaming. ;-)

> +		return EINVAL;
> +
> +	*memptr = (void *)intptr;
> +	b->heap_base = (void *)(newbase);
> +
> +	return 0;
> +}
> +
> +void uk_allocregion_free(struct uk_alloc *a __unused, void *ptr __unused)
> +{
> +	uk_pr_debug("%p: Releasing of memory is not supported by "
> +			"ukallocregion\n", a);
> +}
> +
> +int uk_allocregion_addmem(struct uk_alloc *a __unused, void *base __unused,
> +				size_t size __unused)
> +{
> +	/* TODO: support multiple regions */
> +	uk_pr_debug("%p: ukallocregion does not support multiple memory "
> +			"regions\n", a);
> +	return 0;
> +}
> +
> +struct uk_alloc *uk_allocregion_init(void *base, size_t len)
> +{
> +	struct uk_alloc *a;
> +	struct uk_allocregion *b;
> +	size_t metalen = sizeof(*a) + sizeof(*b);
> +
> +	/* TODO: ukallocregion does not support multiple memory regions yet.
> +	 * Because of the multiboot layout, the first region might be a single
> +	 * page, so we simply ignore it.
> +	 */
> +	if (len <= __PAGE_SIZE)
> +		return NULL;
> +
> +	/* enough space for allocator available? */
> +	if (metalen > len) {
> +		uk_pr_err("Not enough space for allocator: %"__PRIsz
> +			  " B required but only %"__PRIuptr" B usable\n",
> +			  metalen, len);
> +		return NULL;
> +	}
> +
> +	/* store allocator metadata on the heap, just before the memory pool */
> +	a = (struct uk_alloc *)base;
> +	b = (struct uk_allocregion *)&a->priv;
> +
> +	uk_pr_info("Initialize allocregion allocator @ 0x%"
> +		   __PRIuptr ", len %"__PRIsz"\n", (uintptr_t)a, len);
> +
> +	b->heap_top  = (void *)((uintptr_t) base + len);
> +	b->heap_base = (void *)((uintptr_t) base + metalen);
> +
> +	/* use exclusively "compat" wrappers for calloc, realloc, memalign,
> +	 * palloc and pfree as those do not add additional metadata.
> +	 */
> +	uk_alloc_init_malloc(a, uk_allocregion_malloc, uk_calloc_compat,
> +				uk_realloc_compat, uk_allocregion_free,
> +				uk_allocregion_posix_memalign,
> +				uk_memalign_compat, NULL);
> +
> +	return a;
> +}
> 


From minios-devel-bounces@lists.xenproject.org Thu Jul 30 15:32:53 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 30 Jul 2020 15:32:53 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k1AY9-0003kk-Oq; Thu, 30 Jul 2020 15:32:53 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=u4H1=BJ=neclab.eu=simon.kuenzer@srs-us1.protection.inumbo.net>)
 id 1k1AY8-0003kD-Ot
 for minios-devel@lists.xenproject.org; Thu, 30 Jul 2020 15:32:52 +0000
X-Inumbo-ID: ed8f559a-d279-11ea-aae4-12813bfff9fa
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id ed8f559a-d279-11ea-aae4-12813bfff9fa;
 Thu, 30 Jul 2020 15:32:51 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 7947A103BFA;
 Thu, 30 Jul 2020 17:32:50 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id odHnryq08IHi; Thu, 30 Jul 2020 17:32:50 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id 474FD103A92
 for <minios-devel@lists.xenproject.org>; Thu, 30 Jul 2020 17:32:50 +0200 (CEST)
Received: from [10.7.1.42] (192.168.24.96) by puck.office.hd (192.168.24.91)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 30 Jul
 2020 17:32:49 +0200
Subject: Re: [UNIKRAFT PATCH v3 2/2] lib/ukboot: initialize ukallocregion
To: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>,
 <minios-devel@lists.xenproject.org>
References: <cover.1596113182.git.hugo.lefeuvre@neclab.eu>
 <e4105a0b6c3a7a7c9a1584758d1c0e328aefa6b9.1596113182.git.hugo.lefeuvre@neclab.eu>
From: Simon Kuenzer <simon.kuenzer@neclab.eu>
Message-ID: <d8056705-f485-04bf-0bc9-2f62f7e61823@neclab.eu>
Date: Thu, 30 Jul 2020 17:32:48 +0200
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0)
 Gecko/20100101 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <e4105a0b6c3a7a7c9a1584758d1c0e328aefa6b9.1596113182.git.hugo.lefeuvre@neclab.eu>
Content-Type: text/plain; charset="utf-8"; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: titania.office.hd (192.168.24.89) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>

On 30.07.20 15:07, Hugo Lefeuvre wrote:
> Add menuconfig bindings to select a system-wide allocator.
> Initialize the selected allocator in ukboot.
> 
> Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> ---
>   lib/ukboot/Config.uk | 23 +++++++++++++++++++----
>   lib/ukboot/boot.c    | 19 +++++++++++++------
>   2 files changed, 32 insertions(+), 10 deletions(-)
> 
> diff --git a/lib/ukboot/Config.uk b/lib/ukboot/Config.uk
> index 841a876..07139e2 100644
> --- a/lib/ukboot/Config.uk
> +++ b/lib/ukboot/Config.uk
> @@ -17,8 +17,23 @@ if LIBUKBOOT
>   	int "Maximum number of arguments (max. size of argv)"
>   	default 60
>   
> -	config LIBUKBOOT_INITALLOC
> -	bool "Initialize ukallocbbuddy as allocator"
> -	default y
> -	select LIBUKALLOCBBUDDY
> +	choice LIBUKBOOT_INITALLOC
> +	prompt "Initialize memory allocator"
> +	default LIBUKBOOT_INITBBUDDY
> +
> +		config LIBUKBOOT_INITBBUDDY
> +		bool "Binary buddy allocator"
> +		select LIBUKALLOCBBUDDY
> +
> +		config LIBUKBOOT_INITREGION
> +		bool "Region allocator"
> +		select LIBUKALLOCREGION
> +		help
> +		  Satisfy allocation as fast as possible. No support for free().
> +		  Refer to help in ukallocregion for more information.
> +
> +		config LIBUKBOOT_NOALLOC
> +		bool "None"
> +
> +	endchoice
>   endif
> diff --git a/lib/ukboot/boot.c b/lib/ukboot/boot.c
> index e8a2ac7..4e749aa 100644
> --- a/lib/ukboot/boot.c
> +++ b/lib/ukboot/boot.c
> @@ -41,8 +41,10 @@
>   #include <stdio.h>
>   #include <errno.h>
>   
> -#if CONFIG_LIBUKALLOC && CONFIG_LIBUKALLOCBBUDDY && CONFIG_LIBUKBOOT_INITALLOC
> +#if CONFIG_LIBUKBOOT_INITBBUDDY
>   #include <uk/allocbbuddy.h>
> +#elif CONFIG_LIBUKBOOT_INITREGION
> +#include <uk/allocregion.h>
>   #endif
>   #if CONFIG_LIBUKSCHED
>   #include <uk/sched.h>
> @@ -178,7 +180,7 @@ void ukplat_entry(int argc, char *argv[])
>   #if CONFIG_LIBUKALLOC
>   	struct uk_alloc *a = NULL;
>   #endif
> -#if CONFIG_LIBUKALLOC && CONFIG_LIBUKALLOCBBUDDY && CONFIG_LIBUKBOOT_INITALLOC
> +#if !CONFIG_LIBUKBOOT_NOALLOC
>   	struct ukplat_memregion_desc md;
>   #endif
>   #if CONFIG_LIBUKSCHED
> @@ -205,9 +207,9 @@ void ukplat_entry(int argc, char *argv[])
>   	}
>   #endif /* CONFIG_LIBUKLIBPARAM */
>   
> -#if CONFIG_LIBUKALLOC && CONFIG_LIBUKALLOCBBUDDY && CONFIG_LIBUKBOOT_INITALLOC
> +#if !CONFIG_LIBUKBOOT_NOALLOC
>   	/* initialize memory allocator
> -	 * FIXME: ukallocbbuddy is hard-coded for now
> +	 * FIXME: allocators are hard-coded for now
>   	 */
>   	uk_pr_info("Initialize memory allocator...\n");
>   	ukplat_memregion_foreach(&md, UKPLAT_MEMRF_ALLOCATABLE) {
> @@ -226,10 +228,15 @@ void ukplat_entry(int argc, char *argv[])
>   		 * As soon we have an allocator, we simply add every
>   		 * subsequent region to it
>   		 */
> -		if (unlikely(!a))
> +		if (!a) {
> +#if CONFIG_LIBUKBOOT_INITBBUDDY
>   			a = uk_allocbbuddy_init(md.base, md.len);
> -		else
> +#elif CONFIG_LIBUKBOOT_INITREGION
> +			a = uk_allocregion_init(md.base, md.len);
> +#endif
> +		} else {
>   			uk_alloc_addmem(a, md.base, md.len);
> +		}
>   	}
>   	if (unlikely(!a))
>   		uk_pr_warn("No suitable memory region for memory allocator. Continue without heap\n");
> 


From minios-devel-bounces@lists.xenproject.org Thu Jul 30 16:20:54 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 30 Jul 2020 16:20:54 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k1BIZ-0008Qq-2E; Thu, 30 Jul 2020 16:20:51 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=u4H1=BJ=neclab.eu=simon.kuenzer@srs-us1.protection.inumbo.net>)
 id 1k1BIY-0008Qk-JN
 for minios-devel@lists.xenproject.org; Thu, 30 Jul 2020 16:20:50 +0000
X-Inumbo-ID: 9f8c3687-d280-11ea-aae8-12813bfff9fa
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 9f8c3687-d280-11ea-aae8-12813bfff9fa;
 Thu, 30 Jul 2020 16:20:48 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 3D598103BFA;
 Thu, 30 Jul 2020 18:20:47 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id JePsHTbrAjDl; Thu, 30 Jul 2020 18:20:47 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id 151A8103A92
 for <minios-devel@lists.xenproject.org>; Thu, 30 Jul 2020 18:20:47 +0200 (CEST)
Received: from [10.7.1.42] (192.168.24.96) by puck.office.hd (192.168.24.91)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 30 Jul
 2020 18:20:46 +0200
Subject: Re: [UNIKRAFT PATCH v2] lib/ukalloc: add ifmalloc compatibility
 interface
To: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>,
 <minios-devel@lists.xenproject.org>
References: <7fa75a41526504326a646e28e57eba0b18d2c10b.1596120236.git.hugo.lefeuvre@neclab.eu>
From: Simon Kuenzer <simon.kuenzer@neclab.eu>
Message-ID: <24279ec1-fab9-ab32-d5cc-bbca97fe23ae@neclab.eu>
Date: Thu, 30 Jul 2020 18:20:45 +0200
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0)
 Gecko/20100101 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <7fa75a41526504326a646e28e57eba0b18d2c10b.1596120236.git.hugo.lefeuvre@neclab.eu>
Content-Type: text/plain; charset="utf-8"; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hey, I found to open questions. Let me know what you think.

Thanks,

Simon

On 30.07.20 16:48, Hugo Lefeuvre wrote:
> Add ifmalloc, the malloc compatibility interface. This interface implements
> a POSIX compliant allocation interface on top of a simple malloc() and
> free() interface. This interface is similar to ifpages, which does the same
> for palloc() and pfree().
> 
> ifmalloc will be used for the port of TLSF and tinyalloc which do not
> support (posix_)memalign().
> 
> Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> ---
> Changed since v1:
>   - update alloc.c file header
>   - use METADATA_IFMALLOC_SIZE_POW2 instead of sizeof(struct metadata_ifmalloc)
>   - add unlikely where appropriate
>   - use align < sizeof(void *) instead of (align % sizeof(void *)) != 0
>   - minor optimizations and style-related changes
> 
>   lib/ukalloc/Config.uk               |   5 ++
>   lib/ukalloc/alloc.c                 | 148 +++++++++++++++++++++++++++++++++++-
>   lib/ukalloc/exportsyms.uk           |   4 +
>   lib/ukalloc/include/uk/alloc.h      |   5 ++
>   lib/ukalloc/include/uk/alloc_impl.h |  27 +++++++
>   5 files changed, 186 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/ukalloc/Config.uk b/lib/ukalloc/Config.uk
> index 0de7464..c965d08 100644
> --- a/lib/ukalloc/Config.uk
> +++ b/lib/ukalloc/Config.uk
> @@ -5,6 +5,11 @@ menuconfig LIBUKALLOC
>   	select LIBUKDEBUG
>   
>   if LIBUKALLOC
> +	config LIBUKALLOC_IFMALLOC
> +		bool "Malloc compatibility interface"
> +		default n
> +		help
> +			Provide helpers for allocators defining exclusively malloc and free
>   	config LIBUKALLOC_IFSTATS
>   		bool "Statistics interface"
>   		default n
> diff --git a/lib/ukalloc/alloc.c b/lib/ukalloc/alloc.c
> index 127bc6f..160a0a4 100644
> --- a/lib/ukalloc/alloc.c
> +++ b/lib/ukalloc/alloc.c
> @@ -1,8 +1,10 @@
>   /* SPDX-License-Identifier: BSD-3-Clause */
>   /*
>    * Authors: Florian Schmidt <florian.schmidt@neclab.eu>
> + *          Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
>    *
> - * Copyright (c) 2017, NEC Europe Ltd., NEC Corporation. All rights reserved.
> + * Copyright (c) 2017-2020, NEC Laboratories Europe GmbH, NEC Corporation,
> + *                          All rights reserved.
>    *
>    * Redistribution and use in source and binary forms, with or without
>    * modification, are permitted provided that the following conditions
> @@ -28,8 +30,6 @@
>    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
>    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
>    * POSSIBILITY OF SUCH DAMAGE.
> - *
> - * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
>    */
>   
>   /* This is a very simple, naive implementation of malloc.
> @@ -52,6 +52,7 @@
>   #include <uk/essentials.h>
>   #include <uk/assert.h>
>   #include <uk/arch/limits.h>
> +#include <uk/arch/lcpu.h>
>   
>   #define size_to_num_pages(size) \
>   	(ALIGN_UP((unsigned long)(size), __PAGE_SIZE) / __PAGE_SIZE)
> @@ -267,6 +268,147 @@ int uk_posix_memalign_ifpages(struct uk_alloc *a,
>   	return 0;
>   }
>   
> +#if CONFIG_LIBUKALLOC_IFMALLOC
> +
> +struct metadata_ifmalloc {
> +	size_t	size;
> +	void	*base;
> +};
> +
> +#define METADATA_IFMALLOC_SIZE_POW2 16
> +UK_CTASSERT(!(sizeof(struct metadata_ifmalloc) > METADATA_IFMALLOC_SIZE_POW2));
> +
> +static struct metadata_ifmalloc *uk_get_metadata_ifmalloc(const void *ptr)
> +{
> +	return (struct metadata_ifmalloc *)((uintptr_t) ptr -
> +		METADATA_IFMALLOC_SIZE_POW2);
> +}
> +
> +static size_t uk_getmallocsize_ifmalloc(const void *ptr)
> +{
> +	struct metadata_ifmalloc *metadata = uk_get_metadata_ifmalloc(ptr);
> +	return (size_t) ((uintptr_t) metadata->base + metadata->size -
> +			 (uintptr_t) ptr);
> +}
> +
> +void uk_free_ifmalloc(struct uk_alloc *a, void *ptr)
> +{
> +	struct metadata_ifmalloc *metadata;
> +
> +	UK_ASSERT(a);
> +	UK_ASSERT(a->free_backend);
> +	if (!ptr)
> +		return;
> +
> +	metadata = uk_get_metadata_ifmalloc(ptr);
> +	a->free_backend(a, metadata->base);
> +}
> +
> +void *uk_malloc_ifmalloc(struct uk_alloc *a, size_t size)
> +{
> +	struct metadata_ifmalloc *metadata;
> +	size_t realsize = size + METADATA_IFMALLOC_SIZE_POW2;
> +	void *ptr;
> +
> +	UK_ASSERT(a);
> +	UK_ASSERT(a->malloc_backend);
> +
> +	/* check for overflow */
> +	if (unlikely(realsize < size))
> +		return NULL;
> +
> +	ptr = a->malloc_backend(a, realsize);
> +	if (!ptr)
> +		return NULL;
> +
> +	metadata = ptr;
> +	metadata->size = realsize;
> +	metadata->base = ptr;
> +
> +	return (void *) ((uintptr_t) ptr + METADATA_IFMALLOC_SIZE_POW2);
> +}
> +
> +void *uk_realloc_ifmalloc(struct uk_alloc *a, void *ptr, size_t size)
> +{
> +	void *retptr;
> +	size_t mallocsize;
> +
> +	UK_ASSERT(a);
> +	if (!ptr)
> +		return uk_malloc_ifmalloc(a, size);
> +
> +	if (ptr && !size) {
> +		uk_free_ifmalloc(a, ptr);
> +		return NULL;
> +	}
> +
> +	retptr = uk_malloc_ifmalloc(a, size);
> +	if (!retptr)
> +		return NULL;
> +
> +	mallocsize = uk_getmallocsize_ifmalloc(ptr);
> +
> +	memcpy(retptr, ptr, MIN(size, mallocsize));
> +
> +	uk_free_ifmalloc(a, ptr);
> +	return retptr;
> +}
> +
> +int uk_posix_memalign_ifmalloc(struct uk_alloc *a,
> +				     void **memptr, size_t align, size_t size)
> +{
> +	struct metadata_ifmalloc *metadata;
> +	size_t realsize, padding;
> +	uintptr_t intptr;
> +
> +	UK_ASSERT(a);
> +	if (((align - 1) & align) != 0
> +	    || align < sizeof(void *))
> +		return EINVAL;
> +
> +	if (!size) {
> +		*memptr = NULL;

Should we touch *memptr in case of failures? You seem not to do it in 
the other cases.
https://man7.org/linux/man-pages/man3/posix_memalign.3.html

> +		return EINVAL;
> +	}
> +
> +	/* Store size information preceeding the memory block. Since we return
> +	 * pointers aligned at `align` we need to reserve at least that much
> +	 * space for the size information.
> +	 */
> +	if (align < METADATA_IFMALLOC_SIZE_POW2) {
> +		align = METADATA_IFMALLOC_SIZE_POW2;
> +		padding = 0;
> +	} else {
> +		padding = METADATA_IFMALLOC_SIZE_POW2;
> +	}
> +
> +	realsize = size + padding + align;
> +
> +	/* check for overflow */
> +	if (unlikely(realsize < size))
> +		return NULL;

Hum, you should return an errno. I would choose ENOMEM, thats closer 
inline with malloc:

		return ENOMEM;

> +
> +	intptr = (uintptr_t) a->malloc_backend(a, realsize);
> +
> +	if (!intptr)
> +		return ENOMEM;
> +
> +	*memptr = (void *) ALIGN_UP(intptr + METADATA_IFMALLOC_SIZE_POW2,
> +				    (uintptr_t) align);
> +
> +	metadata = uk_get_metadata_ifmalloc(*memptr);
> +
> +	/* check for underflow */
> +	UK_ASSERT(intptr <= (uintptr_t) metadata);
> +
> +	metadata->size = realsize;
> +	metadata->base = (void *) intptr;
> +
> +	return 0;
> +}
> +
> +#endif
> +
>   void uk_pfree_compat(struct uk_alloc *a, void *ptr,
>   		     unsigned long num_pages __unused)
>   {
> diff --git a/lib/ukalloc/exportsyms.uk b/lib/ukalloc/exportsyms.uk
> index 2c8a90f..21c1996 100644
> --- a/lib/ukalloc/exportsyms.uk
> +++ b/lib/ukalloc/exportsyms.uk
> @@ -4,6 +4,10 @@ uk_malloc_ifpages
>   uk_free_ifpages
>   uk_realloc_ifpages
>   uk_posix_memalign_ifpages
> +uk_malloc_ifmalloc
> +uk_realloc_ifmalloc
> +uk_posix_memalign_ifmalloc
> +uk_free_ifmalloc
>   uk_calloc_compat
>   uk_memalign_compat
>   uk_realloc_compat
> diff --git a/lib/ukalloc/include/uk/alloc.h b/lib/ukalloc/include/uk/alloc.h
> index 5bfa2f2..1457922 100644
> --- a/lib/ukalloc/include/uk/alloc.h
> +++ b/lib/ukalloc/include/uk/alloc.h
> @@ -85,6 +85,11 @@ struct uk_alloc {
>   	uk_alloc_memalign_func_t memalign;
>   	uk_alloc_free_func_t free;
>   
> +#if CONFIG_LIBUKALLOC_IFMALLOC
> +	uk_alloc_free_func_t free_backend;
> +	uk_alloc_malloc_func_t malloc_backend;
> +#endif
> +
>   	/* page allocation interface */
>   	uk_alloc_palloc_func_t palloc;
>   	uk_alloc_pfree_func_t pfree;
> diff --git a/lib/ukalloc/include/uk/alloc_impl.h b/lib/ukalloc/include/uk/alloc_impl.h
> index 8bcca94..b15f49e 100644
> --- a/lib/ukalloc/include/uk/alloc_impl.h
> +++ b/lib/ukalloc/include/uk/alloc_impl.h
> @@ -62,6 +62,14 @@ int uk_posix_memalign_ifpages(struct uk_alloc *a, void **memptr,
>   				size_t align, size_t size);
>   void uk_free_ifpages(struct uk_alloc *a, void *ptr);
>   
> +#if CONFIG_LIBUKALLOC_IFMALLOC
> +void *uk_malloc_ifmalloc(struct uk_alloc *a, size_t size);
> +void *uk_realloc_ifmalloc(struct uk_alloc *a, void *ptr, size_t size);
> +int uk_posix_memalign_ifmalloc(struct uk_alloc *a, void **memptr,
> +				     size_t align, size_t size);
> +void uk_free_ifmalloc(struct uk_alloc *a, void *ptr);
> +#endif
> +
>   /* Functionality that is provided based on malloc() and posix_memalign() */
>   void *uk_calloc_compat(struct uk_alloc *a, size_t num, size_t len);
>   void *uk_realloc_compat(struct uk_alloc *a, void *ptr, size_t size);
> @@ -88,6 +96,25 @@ void uk_pfree_compat(struct uk_alloc *a, void *ptr, unsigned long num_pages);
>   		uk_alloc_register((a));					\
>   	} while (0)
>   
> +#if CONFIG_LIBUKALLOC_IFMALLOC
> +#define uk_alloc_init_malloc_ifmalloc(a, malloc_f, free_f, addmem_f) 	\
> +	do {								\
> +		(a)->malloc         = uk_malloc_ifmalloc;		\
> +		(a)->calloc         = uk_calloc_compat;			\
> +		(a)->realloc        = uk_realloc_ifmalloc;		\
> +		(a)->posix_memalign = uk_posix_memalign_ifmalloc;	\
> +		(a)->memalign       = uk_memalign_compat;		\
> +		(a)->malloc_backend = (malloc_f);			\
> +		(a)->free_backend   = (free_f);				\
> +		(a)->free           = uk_free_ifmalloc;			\
> +		(a)->palloc         = uk_palloc_compat;			\
> +		(a)->pfree          = uk_pfree_compat;			\
> +		(a)->addmem         = (addmem_f);			\
> +									\
> +		uk_alloc_register((a));					\
> +	} while (0)
> +#endif
> +
>   /* Shortcut for doing a registration of an allocator that only
>    * implements palloc(), pfree(), addmem()
>    */
> 


From minios-devel-bounces@lists.xenproject.org Thu Jul 30 21:54:03 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 30 Jul 2020 21:54:03 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k1GUy-0006vL-Kn; Thu, 30 Jul 2020 21:54:00 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=ZlbQ=BJ=neclab.eu=hugo.lefeuvre@srs-us1.protection.inumbo.net>)
 id 1k1GUx-0006vG-Bb
 for minios-devel@lists.xenproject.org; Thu, 30 Jul 2020 21:53:59 +0000
X-Inumbo-ID: 2a475c0a-d2af-11ea-ab3b-12813bfff9fa
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 2a475c0a-d2af-11ea-ab3b-12813bfff9fa;
 Thu, 30 Jul 2020 21:53:56 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 9CC921038E0;
 Thu, 30 Jul 2020 23:53:55 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id Z8QHIyk1-Fnt; Thu, 30 Jul 2020 23:53:55 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from titania.office.hd (titania.office.hd [192.168.24.89])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id 761F3101B8B
 for <minios-devel@lists.xenproject.org>; Thu, 30 Jul 2020 23:53:55 +0200 (CEST)
Received: from N-1237 (192.168.24.96) by titania.office.hd (192.168.24.89)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 30 Jul
 2020 23:53:55 +0200
Message-ID: <1596146034.4698.18.camel@neclab.eu>
Subject: Re: [UNIKRAFT PATCH v2] lib/ukalloc: add ifmalloc compatibility
 interface
From: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
To: Simon Kuenzer <simon.kuenzer@neclab.eu>,
 <minios-devel@lists.xenproject.org>
Date: Thu, 30 Jul 2020 23:53:54 +0200
In-Reply-To: <24279ec1-fab9-ab32-d5cc-bbca97fe23ae@neclab.eu>
References: <7fa75a41526504326a646e28e57eba0b18d2c10b.1596120236.git.hugo.lefeuvre@neclab.eu>
 <24279ec1-fab9-ab32-d5cc-bbca97fe23ae@neclab.eu>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: titania.office.hd (192.168.24.89) To titania.office.hd
 (192.168.24.89)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Simon,

thanks a lot for your comments, answers inline.

regards,
Hugo

On Thu, 2020-07-30 at 18:20 +0200, Simon Kuenzer wrote:
> 
> Hey, I found to open questions. Let me know what you think.
> 
> Thanks,
> 
> Simon
> 
> On 30.07.20 16:48, Hugo Lefeuvre wrote:
> > 
> > 
> > Add ifmalloc, the malloc compatibility interface. This interface
> > implements
> > a POSIX compliant allocation interface on top of a simple malloc()
> > and
> > free() interface. This interface is similar to ifpages, which does
> > the same
> > for palloc() and pfree().
> > 
> > ifmalloc will be used for the port of TLSF and tinyalloc which do
> > not
> > support (posix_)memalign().
> > 
> > Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> > ---
> > Changed since v1:
> > Â  - update alloc.c file header
> > Â  - use METADATA_IFMALLOC_SIZE_POW2 instead of sizeof(struct
> > metadata_ifmalloc)
> > Â  - add unlikely where appropriate
> > Â  - use align < sizeof(void *) instead of (align % sizeof(void *))
> > != 0
> > Â  - minor optimizations and style-related changes
> > 
> > Â  lib/ukalloc/Config.ukÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â |Â Â Â 5 ++
> > Â  lib/ukalloc/alloc.cÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â | 148
> > +++++++++++++++++++++++++++++++++++-
> > Â  lib/ukalloc/exportsyms.ukÂ Â Â Â Â Â Â Â Â Â Â |Â Â Â 4 +
> > Â  lib/ukalloc/include/uk/alloc.hÂ Â Â Â Â Â |Â Â Â 5 ++
> > Â  lib/ukalloc/include/uk/alloc_impl.h |Â Â 27 +++++++
> > Â  5 files changed, 186 insertions(+), 3 deletions(-)
> > 
> > diff --git a/lib/ukalloc/Config.uk b/lib/ukalloc/Config.uk
> > index 0de7464..c965d08 100644
> > --- a/lib/ukalloc/Config.uk
> > +++ b/lib/ukalloc/Config.uk
> > @@ -5,6 +5,11 @@ menuconfig LIBUKALLOC
> > Â Â 	select LIBUKDEBUG
> > Â Â 
> > Â  if LIBUKALLOC
> > +	config LIBUKALLOC_IFMALLOC
> > +		bool "Malloc compatibility interface"
> > +		default n
> > +		help
> > +			Provide helpers for allocators defining
> > exclusively malloc and free
> > Â Â 	config LIBUKALLOC_IFSTATS
> > Â Â 		bool "Statistics interface"
> > Â Â 		default n
> > diff --git a/lib/ukalloc/alloc.c b/lib/ukalloc/alloc.c
> > index 127bc6f..160a0a4 100644
> > --- a/lib/ukalloc/alloc.c
> > +++ b/lib/ukalloc/alloc.c
> > @@ -1,8 +1,10 @@
> > Â  /* SPDX-License-Identifier: BSD-3-Clause */
> > Â  /*
> > Â Â Â * Authors: Florian Schmidt <florian.schmidt@neclab.eu>
> > + *Â Â Â Â Â Â Â Â Â Â Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
> > Â Â Â *
> > - * Copyright (c) 2017, NEC Europe Ltd., NEC Corporation. All
> > rights reserved.
> > + * Copyright (c) 2017-2020, NEC Laboratories Europe GmbH, NEC
> > Corporation,
> > + *Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â All rights reserved.
> > Â Â Â *
> > Â Â Â * Redistribution and use in source and binary forms, with or
> > without
> > Â Â Â * modification, are permitted provided that the following
> > conditions
> > @@ -28,8 +30,6 @@
> > Â Â Â * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
> > OTHERWISE)
> > Â Â Â * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
> > ADVISED OF THE
> > Â Â Â * POSSIBILITY OF SUCH DAMAGE.
> > - *
> > - * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
> > Â Â Â */
> > Â Â 
> > Â  /* This is a very simple, naive implementation of malloc.
> > @@ -52,6 +52,7 @@
> > Â  #include <uk/essentials.h>
> > Â  #include <uk/assert.h>
> > Â  #include <uk/arch/limits.h>
> > +#include <uk/arch/lcpu.h>
> > Â Â 
> > Â  #define size_to_num_pages(size) \
> > Â Â 	(ALIGN_UP((unsigned long)(size), __PAGE_SIZE) /
> > __PAGE_SIZE)
> > @@ -267,6 +268,147 @@ int uk_posix_memalign_ifpages(struct uk_alloc
> > *a,
> > Â Â 	return 0;
> > Â  }
> > Â Â 
> > +#if CONFIG_LIBUKALLOC_IFMALLOC
> > +
> > +struct metadata_ifmalloc {
> > +	size_t	size;
> > +	void	*base;
> > +};
> > +
> > +#define METADATA_IFMALLOC_SIZE_POW2 16
> > +UK_CTASSERT(!(sizeof(struct metadata_ifmalloc) >
> > METADATA_IFMALLOC_SIZE_POW2));
> > +
> > +static struct metadata_ifmalloc *uk_get_metadata_ifmalloc(const
> > void *ptr)
> > +{
> > +	return (struct metadata_ifmalloc *)((uintptr_t) ptr -
> > +		METADATA_IFMALLOC_SIZE_POW2);
> > +}
> > +
> > +static size_t uk_getmallocsize_ifmalloc(const void *ptr)
> > +{
> > +	struct metadata_ifmalloc *metadata =
> > uk_get_metadata_ifmalloc(ptr);
> > +	return (size_t) ((uintptr_t) metadata->base + metadata-
> > > 
> > > size -
> > +			Â (uintptr_t) ptr);
> > +}
> > +
> > +void uk_free_ifmalloc(struct uk_alloc *a, void *ptr)
> > +{
> > +	struct metadata_ifmalloc *metadata;
> > +
> > +	UK_ASSERT(a);
> > +	UK_ASSERT(a->free_backend);
> > +	if (!ptr)
> > +		return;
> > +
> > +	metadata = uk_get_metadata_ifmalloc(ptr);
> > +	a->free_backend(a, metadata->base);
> > +}
> > +
> > +void *uk_malloc_ifmalloc(struct uk_alloc *a, size_t size)
> > +{
> > +	struct metadata_ifmalloc *metadata;
> > +	size_t realsize = size + METADATA_IFMALLOC_SIZE_POW2;
> > +	void *ptr;
> > +
> > +	UK_ASSERT(a);
> > +	UK_ASSERT(a->malloc_backend);
> > +
> > +	/* check for overflow */
> > +	if (unlikely(realsize < size))
> > +		return NULL;
> > +
> > +	ptr = a->malloc_backend(a, realsize);
> > +	if (!ptr)
> > +		return NULL;
> > +
> > +	metadata = ptr;
> > +	metadata->size = realsize;
> > +	metadata->base = ptr;
> > +
> > +	return (void *) ((uintptr_t) ptr +
> > METADATA_IFMALLOC_SIZE_POW2);
> > +}
> > +
> > +void *uk_realloc_ifmalloc(struct uk_alloc *a, void *ptr, size_t
> > size)
> > +{
> > +	void *retptr;
> > +	size_t mallocsize;
> > +
> > +	UK_ASSERT(a);
> > +	if (!ptr)
> > +		return uk_malloc_ifmalloc(a, size);
> > +
> > +	if (ptr && !size) {
> > +		uk_free_ifmalloc(a, ptr);
> > +		return NULL;
> > +	}
> > +
> > +	retptr = uk_malloc_ifmalloc(a, size);
> > +	if (!retptr)
> > +		return NULL;
> > +
> > +	mallocsize = uk_getmallocsize_ifmalloc(ptr);
> > +
> > +	memcpy(retptr, ptr, MIN(size, mallocsize));
> > +
> > +	uk_free_ifmalloc(a, ptr);
> > +	return retptr;
> > +}
> > +
> > +int uk_posix_memalign_ifmalloc(struct uk_alloc *a,
> > +				Â Â Â Â Â void **memptr, size_t align,
> > size_t size)
> > +{
> > +	struct metadata_ifmalloc *metadata;
> > +	size_t realsize, padding;
> > +	uintptr_t intptr;
> > +
> > +	UK_ASSERT(a);
> > +	if (((align - 1) & align) != 0
> > +	Â Â Â Â || align < sizeof(void *))
> > +		return EINVAL;
> > +
> > +	if (!size) {
> > +		*memptr = NULL;
> Should we touch *memptr in case of failures? You seem not to do it
> inÂ 
> the other cases.
> https://man7.org/linux/man-pages/man3/posix_memalign.3.html

Taking a look atÂ https://pubs.opengroup.org/onlinepubs/9699919799/funct
ions/posix_memalign.html, specifically:

"If size is 0, either:

Â * posix_memalign() shall not attempt to allocate any space, in which
case either an implementation-defined error number shall be returned,
or zero shall be returned with a null pointer returned in memptr, or

Â * posix_memalign() shall attempt to allocate some space and, if the
allocation succeeds, zero shall be returned and a pointer to the
allocated space shall be returned in memptr. The application shall
ensure that the pointer is not used to access an object."

Indeed, I prefer to return an error code instead of setting memptr and
returning zero. My fear is that some users might dereference memptr
after observing a zero return value. Do you think EINVAL is fine in
this case? In this case we could just remove `*memptr = NULL;`.

Note that this bug was already present inÂ uk_posix_memalign_ifpages, I
intentionally reproduced it in the ifmalloc wrapper. It was introduced
inÂ https://github.com/unikraft/unikraft/commit/a323fbd67ac3cb21139633b3
00a024538167493e

> > +		return EINVAL;
> > +}	
> > +
> > +	/* Store size information preceeding the memory block.
> > Since we return
> > +	Â * pointers aligned at `align` we need to reserve at least
> > that much
> > +	Â * space for the size information.
> > +	Â */
> > +	if (align < METADATA_IFMALLOC_SIZE_POW2) {
> > +		align = METADATA_IFMALLOC_SIZE_POW2;
> > +		padding = 0;
> > +	} else {
> > +		padding = METADATA_IFMALLOC_SIZE_POW2;
> > +	}
> > +
> > +	realsize = size + padding + align;
> > +
> > +	/* check for overflow */
> > +	if (unlikely(realsize < size))
> > +		return NULL;
> Hum, you should return an errno. I would choose ENOMEM, thats closerÂ 
> inline with malloc:
> 
> 		return ENOMEM;
Sounds good.

> 
> > 
> > 
> > +
> > +	intptr = (uintptr_t) a->malloc_backend(a, realsize);
> > +
> > +	if (!intptr)
> > +		return ENOMEM;
> > +
> > +	*memptr = (void *) ALIGN_UP(intptr +
> > METADATA_IFMALLOC_SIZE_POW2,
> > +				Â Â Â Â (uintptr_t) align);
> > +
> > +	metadata = uk_get_metadata_ifmalloc(*memptr);
> > +
> > +	/* check for underflow */
> > +	UK_ASSERT(intptr <= (uintptr_t) metadata);
> > +
> > +	metadata->size = realsize;
> > +	metadata->base = (void *) intptr;
> > +
> > +	return 0;
> > +}
> > +
> > +#endif
> > +
> > Â  void uk_pfree_compat(struct uk_alloc *a, void *ptr,
> > Â Â 		Â Â Â Â Â unsigned long num_pages __unused)
> > Â  {
> > diff --git a/lib/ukalloc/exportsyms.uk b/lib/ukalloc/exportsyms.uk
> > index 2c8a90f..21c1996 100644
> > --- a/lib/ukalloc/exportsyms.uk
> > +++ b/lib/ukalloc/exportsyms.uk
> > @@ -4,6 +4,10 @@ uk_malloc_ifpages
> > Â  uk_free_ifpages
> > Â  uk_realloc_ifpages
> > Â  uk_posix_memalign_ifpages
> > +uk_malloc_ifmalloc
> > +uk_realloc_ifmalloc
> > +uk_posix_memalign_ifmalloc
> > +uk_free_ifmalloc
> > Â  uk_calloc_compat
> > Â  uk_memalign_compat
> > Â  uk_realloc_compat
> > diff --git a/lib/ukalloc/include/uk/alloc.h
> > b/lib/ukalloc/include/uk/alloc.h
> > index 5bfa2f2..1457922 100644
> > --- a/lib/ukalloc/include/uk/alloc.h
> > +++ b/lib/ukalloc/include/uk/alloc.h
> > @@ -85,6 +85,11 @@ struct uk_alloc {
> > Â Â 	uk_alloc_memalign_func_t memalign;
> > Â Â 	uk_alloc_free_func_t free;
> > Â Â 
> > +#if CONFIG_LIBUKALLOC_IFMALLOC
> > +	uk_alloc_free_func_t free_backend;
> > +	uk_alloc_malloc_func_t malloc_backend;
> > +#endif
> > +
> > Â Â 	/* page allocation interface */
> > Â Â 	uk_alloc_palloc_func_t palloc;
> > Â Â 	uk_alloc_pfree_func_t pfree;
> > diff --git a/lib/ukalloc/include/uk/alloc_impl.h
> > b/lib/ukalloc/include/uk/alloc_impl.h
> > index 8bcca94..b15f49e 100644
> > --- a/lib/ukalloc/include/uk/alloc_impl.h
> > +++ b/lib/ukalloc/include/uk/alloc_impl.h
> > @@ -62,6 +62,14 @@ int uk_posix_memalign_ifpages(struct uk_alloc
> > *a, void **memptr,
> > Â Â 				size_t align, size_t size);
> > Â  void uk_free_ifpages(struct uk_alloc *a, void *ptr);
> > Â Â 
> > +#if CONFIG_LIBUKALLOC_IFMALLOC
> > +void *uk_malloc_ifmalloc(struct uk_alloc *a, size_t size);
> > +void *uk_realloc_ifmalloc(struct uk_alloc *a, void *ptr, size_t
> > size);
> > +int uk_posix_memalign_ifmalloc(struct uk_alloc *a, void **memptr,
> > +				Â Â Â Â Â size_t align, size_t size);
> > +void uk_free_ifmalloc(struct uk_alloc *a, void *ptr);
> > +#endif
> > +
> > Â  /* Functionality that is provided based on malloc() and
> > posix_memalign() */
> > Â  void *uk_calloc_compat(struct uk_alloc *a, size_t num, size_t
> > len);
> > Â  void *uk_realloc_compat(struct uk_alloc *a, void *ptr, size_t
> > size);
> > @@ -88,6 +96,25 @@ void uk_pfree_compat(struct uk_alloc *a, void
> > *ptr, unsigned long num_pages);
> > Â Â 		uk_alloc_register((a));				
> > 	\
> > Â Â 	} while (0)
> > Â Â 
> > +#if CONFIG_LIBUKALLOC_IFMALLOC
> > +#define uk_alloc_init_malloc_ifmalloc(a, malloc_f, free_f,
> > addmem_f)Â 	\
> > +	do {							
> > 	\
> > +		(a)->mallocÂ Â Â Â Â Â Â Â Â = uk_malloc_ifmalloc;		
> > \
> > +		(a)->callocÂ Â Â Â Â Â Â Â Â = uk_calloc_compat;		
> > 	\
> > +		(a)->reallocÂ Â Â Â Â Â Â Â = uk_realloc_ifmalloc;		
> > \
> > +		(a)->posix_memalign = uk_posix_memalign_ifmalloc;	
> > \
> > +		(a)->memalignÂ Â Â Â Â Â Â = uk_memalign_compat;		
> > \
> > +		(a)->malloc_backend = (malloc_f);			
> > \
> > +		(a)->free_backendÂ Â Â = (free_f);			
> > 	\
> > +		(a)->freeÂ Â Â Â Â Â Â Â Â Â Â = uk_free_ifmalloc;		
> > 	\
> > +		(a)->pallocÂ Â Â Â Â Â Â Â Â = uk_palloc_compat;		
> > 	\
> > +		(a)->pfreeÂ Â Â Â Â Â Â Â Â Â = uk_pfree_compat;		
> > 	\
> > +		(a)->addmemÂ Â Â Â Â Â Â Â Â = (addmem_f);			
> > \
> > +									
> > \
> > +		uk_alloc_register((a));				
> > 	\
> > +	} while (0)
> > +#endif
> > +
> > Â  /* Shortcut for doing a registration of an allocator that only
> > Â Â Â * implements palloc(), pfree(), addmem()
> > Â Â Â */


From minios-devel-bounces@lists.xenproject.org Thu Jul 30 23:18:50 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 30 Jul 2020 23:18:50 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k1Hp0-0005Gf-Pu; Thu, 30 Jul 2020 23:18:46 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=u4H1=BJ=neclab.eu=simon.kuenzer@srs-us1.protection.inumbo.net>)
 id 1k1Hoz-0005Ga-9c
 for minios-devel@lists.xenproject.org; Thu, 30 Jul 2020 23:18:45 +0000
X-Inumbo-ID: 01e34934-d2bb-11ea-8def-bc764e2007e4
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 01e34934-d2bb-11ea-8def-bc764e2007e4;
 Thu, 30 Jul 2020 23:18:42 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id AB57DF201A;
 Fri, 31 Jul 2020 01:18:41 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id dP49og4cgh4B; Fri, 31 Jul 2020 01:18:41 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from Oberon.office.hd (Oberon.office.hd [192.168.24.90])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id 7C8BBF2013
 for <minios-devel@lists.xenproject.org>; Fri, 31 Jul 2020 01:18:39 +0200 (CEST)
Received: from puck.office.hd (192.168.24.91) by Oberon.office.hd
 (192.168.24.90) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Fri, 31 Jul
 2020 01:18:39 +0200
Received: from puck.office.hd ([192.168.126.12]) by puck.office.hd
 ([192.168.126.12]) with mapi id 15.01.1979.003; Fri, 31 Jul 2020 01:18:38
 +0200
From: Simon Kuenzer <simon.kuenzer@neclab.eu>
To: Hugo Lefeuvre <Hugo.Lefeuvre@neclab.eu>,
 "minios-devel@lists.xenproject.org" <minios-devel@lists.xenproject.org>
Subject: Re: [UNIKRAFT PATCH v2] lib/ukalloc: add ifmalloc compatibility
 interface
Thread-Topic: [UNIKRAFT PATCH v2] lib/ukalloc: add ifmalloc compatibility
 interface
Thread-Index: AQHWZoCYfLMyqqUl10egt02Xvxsg0qkgTb+AgAA7jgCAADj/AA==
Date: Thu, 30 Jul 2020 23:18:38 +0000
Message-ID: <1B3456DE-CA8F-4F0B-B001-A11EE6B69E06@neclab.eu>
References: <7fa75a41526504326a646e28e57eba0b18d2c10b.1596120236.git.hugo.lefeuvre@neclab.eu>
 <24279ec1-fab9-ab32-d5cc-bbca97fe23ae@neclab.eu>
 <1596146034.4698.18.camel@neclab.eu>
In-Reply-To: <1596146034.4698.18.camel@neclab.eu>
Accept-Language: en-GB, gl-ES, en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
user-agent: Microsoft-MacOutlook/10.10.18.200713
x-originating-ip: [192.168.24.96]
Content-Type: text/plain; charset="utf-8"
Content-ID: <079FEB68CC3F4E48A8D9498887E82163@office.hd>
Content-Transfer-Encoding: base64
MIME-Version: 1.0
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

T24gMzAuMDcuMjAsIDIzOjUzLCAiSHVnbyBMZWZldXZyZSIgPEh1Z28uTGVmZXV2cmVAbmVjbGFi
LmV1PiB3cm90ZToNCg0KICAgIEhpIFNpbW9uLA0KICAgIA0KICAgIHRoYW5rcyBhIGxvdCBmb3Ig
eW91ciBjb21tZW50cywgYW5zd2VycyBpbmxpbmUuDQogICAgDQogICAgcmVnYXJkcywNCiAgICBI
dWdvDQogICAgDQogICAgT24gVGh1LCAyMDIwLTA3LTMwIGF0IDE4OjIwICswMjAwLCBTaW1vbiBL
dWVuemVyIHdyb3RlOg0KICAgID4gDQogICAgPiBIZXksIEkgZm91bmQgdG8gb3BlbiBxdWVzdGlv
bnMuIExldCBtZSBrbm93IHdoYXQgeW91IHRoaW5rLg0KICAgID4gDQogICAgPiBUaGFua3MsDQog
ICAgPiANCiAgICA+IFNpbW9uDQogICAgPiANCiAgICA+IE9uIDMwLjA3LjIwIDE2OjQ4LCBIdWdv
IExlZmV1dnJlIHdyb3RlOg0KICAgID4gPiANCiAgICA+ID4gDQogICAgPiA+IEFkZCBpZm1hbGxv
YywgdGhlIG1hbGxvYyBjb21wYXRpYmlsaXR5IGludGVyZmFjZS4gVGhpcyBpbnRlcmZhY2UNCiAg
ICA+ID4gaW1wbGVtZW50cw0KICAgID4gPiBhIFBPU0lYIGNvbXBsaWFudCBhbGxvY2F0aW9uIGlu
dGVyZmFjZSBvbiB0b3Agb2YgYSBzaW1wbGUgbWFsbG9jKCkNCiAgICA+ID4gYW5kDQogICAgPiA+
IGZyZWUoKSBpbnRlcmZhY2UuIFRoaXMgaW50ZXJmYWNlIGlzIHNpbWlsYXIgdG8gaWZwYWdlcywg
d2hpY2ggZG9lcw0KICAgID4gPiB0aGUgc2FtZQ0KICAgID4gPiBmb3IgcGFsbG9jKCkgYW5kIHBm
cmVlKCkuDQogICAgPiA+IA0KICAgID4gPiBpZm1hbGxvYyB3aWxsIGJlIHVzZWQgZm9yIHRoZSBw
b3J0IG9mIFRMU0YgYW5kIHRpbnlhbGxvYyB3aGljaCBkbw0KICAgID4gPiBub3QNCiAgICA+ID4g
c3VwcG9ydCAocG9zaXhfKW1lbWFsaWduKCkuDQogICAgPiA+IA0KICAgID4gPiBTaWduZWQtb2Zm
LWJ5OiBIdWdvIExlZmV1dnJlIDxodWdvLmxlZmV1dnJlQG5lY2xhYi5ldT4NCiAgICA+ID4gLS0t
DQogICAgPiA+IENoYW5nZWQgc2luY2UgdjE6DQogICAgPiA+ICAgLSB1cGRhdGUgYWxsb2MuYyBm
aWxlIGhlYWRlcg0KICAgID4gPiAgIC0gdXNlIE1FVEFEQVRBX0lGTUFMTE9DX1NJWkVfUE9XMiBp
bnN0ZWFkIG9mIHNpemVvZihzdHJ1Y3QNCiAgICA+ID4gbWV0YWRhdGFfaWZtYWxsb2MpDQogICAg
PiA+ICAgLSBhZGQgdW5saWtlbHkgd2hlcmUgYXBwcm9wcmlhdGUNCiAgICA+ID4gICAtIHVzZSBh
bGlnbiA8IHNpemVvZih2b2lkICopIGluc3RlYWQgb2YgKGFsaWduICUgc2l6ZW9mKHZvaWQgKikp
DQogICAgPiA+ICE9IDANCiAgICA+ID4gICAtIG1pbm9yIG9wdGltaXphdGlvbnMgYW5kIHN0eWxl
LXJlbGF0ZWQgY2hhbmdlcw0KICAgID4gPiANCiAgICA+ID4gICBsaWIvdWthbGxvYy9Db25maWcu
dWsgICAgICAgICAgICAgICB8ICAgNSArKw0KICAgID4gPiAgIGxpYi91a2FsbG9jL2FsbG9jLmMg
ICAgICAgICAgICAgICAgIHwgMTQ4DQogICAgPiA+ICsrKysrKysrKysrKysrKysrKysrKysrKysr
KysrKysrKysrLQ0KICAgID4gPiAgIGxpYi91a2FsbG9jL2V4cG9ydHN5bXMudWsgICAgICAgICAg
IHwgICA0ICsNCiAgICA+ID4gICBsaWIvdWthbGxvYy9pbmNsdWRlL3VrL2FsbG9jLmggICAgICB8
ICAgNSArKw0KICAgID4gPiAgIGxpYi91a2FsbG9jL2luY2x1ZGUvdWsvYWxsb2NfaW1wbC5oIHwg
IDI3ICsrKysrKysNCiAgICA+ID4gICA1IGZpbGVzIGNoYW5nZWQsIDE4NiBpbnNlcnRpb25zKCsp
LCAzIGRlbGV0aW9ucygtKQ0KICAgID4gPiANCiAgICA+ID4gZGlmZiAtLWdpdCBhL2xpYi91a2Fs
bG9jL0NvbmZpZy51ayBiL2xpYi91a2FsbG9jL0NvbmZpZy51aw0KICAgID4gPiBpbmRleCAwZGU3
NDY0Li5jOTY1ZDA4IDEwMDY0NA0KICAgID4gPiAtLS0gYS9saWIvdWthbGxvYy9Db25maWcudWsN
CiAgICA+ID4gKysrIGIvbGliL3VrYWxsb2MvQ29uZmlnLnVrDQogICAgPiA+IEBAIC01LDYgKzUs
MTEgQEAgbWVudWNvbmZpZyBMSUJVS0FMTE9DDQogICAgPiA+ICAgCXNlbGVjdCBMSUJVS0RFQlVH
DQogICAgPiA+ICAgDQogICAgPiA+ICAgaWYgTElCVUtBTExPQw0KICAgID4gPiArCWNvbmZpZyBM
SUJVS0FMTE9DX0lGTUFMTE9DDQogICAgPiA+ICsJCWJvb2wgIk1hbGxvYyBjb21wYXRpYmlsaXR5
IGludGVyZmFjZSINCiAgICA+ID4gKwkJZGVmYXVsdCBuDQogICAgPiA+ICsJCWhlbHANCiAgICA+
ID4gKwkJCVByb3ZpZGUgaGVscGVycyBmb3IgYWxsb2NhdG9ycyBkZWZpbmluZw0KICAgID4gPiBl
eGNsdXNpdmVseSBtYWxsb2MgYW5kIGZyZWUNCiAgICA+ID4gICAJY29uZmlnIExJQlVLQUxMT0Nf
SUZTVEFUUw0KICAgID4gPiAgIAkJYm9vbCAiU3RhdGlzdGljcyBpbnRlcmZhY2UiDQogICAgPiA+
ICAgCQlkZWZhdWx0IG4NCiAgICA+ID4gZGlmZiAtLWdpdCBhL2xpYi91a2FsbG9jL2FsbG9jLmMg
Yi9saWIvdWthbGxvYy9hbGxvYy5jDQogICAgPiA+IGluZGV4IDEyN2JjNmYuLjE2MGEwYTQgMTAw
NjQ0DQogICAgPiA+IC0tLSBhL2xpYi91a2FsbG9jL2FsbG9jLmMNCiAgICA+ID4gKysrIGIvbGli
L3VrYWxsb2MvYWxsb2MuYw0KICAgID4gPiBAQCAtMSw4ICsxLDEwIEBADQogICAgPiA+ICAgLyog
U1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IEJTRC0zLUNsYXVzZSAqLw0KICAgID4gPiAgIC8qDQog
ICAgPiA+ICAgICogQXV0aG9yczogRmxvcmlhbiBTY2htaWR0IDxmbG9yaWFuLnNjaG1pZHRAbmVj
bGFiLmV1Pg0KICAgID4gPiArICogICAgICAgICAgSHVnbyBMZWZldXZyZSA8aHVnby5sZWZldXZy
ZUBuZWNsYWIuZXU+DQogICAgPiA+ICAgICoNCiAgICA+ID4gLSAqIENvcHlyaWdodCAoYykgMjAx
NywgTkVDIEV1cm9wZSBMdGQuLCBORUMgQ29ycG9yYXRpb24uIEFsbA0KICAgID4gPiByaWdodHMg
cmVzZXJ2ZWQuDQogICAgPiA+ICsgKiBDb3B5cmlnaHQgKGMpIDIwMTctMjAyMCwgTkVDIExhYm9y
YXRvcmllcyBFdXJvcGUgR21iSCwgTkVDDQogICAgPiA+IENvcnBvcmF0aW9uLA0KICAgID4gPiAr
ICogICAgICAgICAgICAgICAgICAgICAgICAgIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQogICAgPiA+
ICAgICoNCiAgICA+ID4gICAgKiBSZWRpc3RyaWJ1dGlvbiBhbmQgdXNlIGluIHNvdXJjZSBhbmQg
YmluYXJ5IGZvcm1zLCB3aXRoIG9yDQogICAgPiA+IHdpdGhvdXQNCiAgICA+ID4gICAgKiBtb2Rp
ZmljYXRpb24sIGFyZSBwZXJtaXR0ZWQgcHJvdmlkZWQgdGhhdCB0aGUgZm9sbG93aW5nDQogICAg
PiA+IGNvbmRpdGlvbnMNCiAgICA+ID4gQEAgLTI4LDggKzMwLDYgQEANCiAgICA+ID4gICAgKiBD
T05UUkFDVCwgU1RSSUNUIExJQUJJTElUWSwgT1IgVE9SVCAoSU5DTFVESU5HIE5FR0xJR0VOQ0Ug
T1INCiAgICA+ID4gT1RIRVJXSVNFKQ0KICAgID4gPiAgICAqIEFSSVNJTkcgSU4gQU5ZIFdBWSBP
VVQgT0YgVEhFIFVTRSBPRiBUSElTIFNPRlRXQVJFLCBFVkVOIElGDQogICAgPiA+IEFEVklTRUQg
T0YgVEhFDQogICAgPiA+ICAgICogUE9TU0lCSUxJVFkgT0YgU1VDSCBEQU1BR0UuDQogICAgPiA+
IC0gKg0KICAgID4gPiAtICogVEhJUyBIRUFERVIgTUFZIE5PVCBCRSBFWFRSQUNURUQgT1IgTU9E
SUZJRUQgSU4gQU5ZIFdBWS4NCiAgICA+ID4gICAgKi8NCiAgICA+ID4gICANCiAgICA+ID4gICAv
KiBUaGlzIGlzIGEgdmVyeSBzaW1wbGUsIG5haXZlIGltcGxlbWVudGF0aW9uIG9mIG1hbGxvYy4N
CiAgICA+ID4gQEAgLTUyLDYgKzUyLDcgQEANCiAgICA+ID4gICAjaW5jbHVkZSA8dWsvZXNzZW50
aWFscy5oPg0KICAgID4gPiAgICNpbmNsdWRlIDx1ay9hc3NlcnQuaD4NCiAgICA+ID4gICAjaW5j
bHVkZSA8dWsvYXJjaC9saW1pdHMuaD4NCiAgICA+ID4gKyNpbmNsdWRlIDx1ay9hcmNoL2xjcHUu
aD4NCiAgICA+ID4gICANCiAgICA+ID4gICAjZGVmaW5lIHNpemVfdG9fbnVtX3BhZ2VzKHNpemUp
IFwNCiAgICA+ID4gICAJKEFMSUdOX1VQKCh1bnNpZ25lZCBsb25nKShzaXplKSwgX19QQUdFX1NJ
WkUpIC8NCiAgICA+ID4gX19QQUdFX1NJWkUpDQogICAgPiA+IEBAIC0yNjcsNiArMjY4LDE0NyBA
QCBpbnQgdWtfcG9zaXhfbWVtYWxpZ25faWZwYWdlcyhzdHJ1Y3QgdWtfYWxsb2MNCiAgICA+ID4g
KmEsDQogICAgPiA+ICAgCXJldHVybiAwOw0KICAgID4gPiAgIH0NCiAgICA+ID4gICANCiAgICA+
ID4gKyNpZiBDT05GSUdfTElCVUtBTExPQ19JRk1BTExPQw0KICAgID4gPiArDQogICAgPiA+ICtz
dHJ1Y3QgbWV0YWRhdGFfaWZtYWxsb2Mgew0KICAgID4gPiArCXNpemVfdAlzaXplOw0KICAgID4g
PiArCXZvaWQJKmJhc2U7DQogICAgPiA+ICt9Ow0KICAgID4gPiArDQogICAgPiA+ICsjZGVmaW5l
IE1FVEFEQVRBX0lGTUFMTE9DX1NJWkVfUE9XMiAxNg0KICAgID4gPiArVUtfQ1RBU1NFUlQoIShz
aXplb2Yoc3RydWN0IG1ldGFkYXRhX2lmbWFsbG9jKSA+DQogICAgPiA+IE1FVEFEQVRBX0lGTUFM
TE9DX1NJWkVfUE9XMikpOw0KICAgID4gPiArDQogICAgPiA+ICtzdGF0aWMgc3RydWN0IG1ldGFk
YXRhX2lmbWFsbG9jICp1a19nZXRfbWV0YWRhdGFfaWZtYWxsb2MoY29uc3QNCiAgICA+ID4gdm9p
ZCAqcHRyKQ0KICAgID4gPiArew0KICAgID4gPiArCXJldHVybiAoc3RydWN0IG1ldGFkYXRhX2lm
bWFsbG9jICopKCh1aW50cHRyX3QpIHB0ciAtDQogICAgPiA+ICsJCU1FVEFEQVRBX0lGTUFMTE9D
X1NJWkVfUE9XMik7DQogICAgPiA+ICt9DQogICAgPiA+ICsNCiAgICA+ID4gK3N0YXRpYyBzaXpl
X3QgdWtfZ2V0bWFsbG9jc2l6ZV9pZm1hbGxvYyhjb25zdCB2b2lkICpwdHIpDQogICAgPiA+ICt7
DQogICAgPiA+ICsJc3RydWN0IG1ldGFkYXRhX2lmbWFsbG9jICptZXRhZGF0YSA9DQogICAgPiA+
IHVrX2dldF9tZXRhZGF0YV9pZm1hbGxvYyhwdHIpOw0KICAgID4gPiArCXJldHVybiAoc2l6ZV90
KSAoKHVpbnRwdHJfdCkgbWV0YWRhdGEtPmJhc2UgKyBtZXRhZGF0YS0NCiAgICA+ID4gPiANCiAg
ICA+ID4gPiBzaXplIC0NCiAgICA+ID4gKwkJCSAodWludHB0cl90KSBwdHIpOw0KICAgID4gPiAr
fQ0KICAgID4gPiArDQogICAgPiA+ICt2b2lkIHVrX2ZyZWVfaWZtYWxsb2Moc3RydWN0IHVrX2Fs
bG9jICphLCB2b2lkICpwdHIpDQogICAgPiA+ICt7DQogICAgPiA+ICsJc3RydWN0IG1ldGFkYXRh
X2lmbWFsbG9jICptZXRhZGF0YTsNCiAgICA+ID4gKw0KICAgID4gPiArCVVLX0FTU0VSVChhKTsN
CiAgICA+ID4gKwlVS19BU1NFUlQoYS0+ZnJlZV9iYWNrZW5kKTsNCiAgICA+ID4gKwlpZiAoIXB0
cikNCiAgICA+ID4gKwkJcmV0dXJuOw0KICAgID4gPiArDQogICAgPiA+ICsJbWV0YWRhdGEgPSB1
a19nZXRfbWV0YWRhdGFfaWZtYWxsb2MocHRyKTsNCiAgICA+ID4gKwlhLT5mcmVlX2JhY2tlbmQo
YSwgbWV0YWRhdGEtPmJhc2UpOw0KICAgID4gPiArfQ0KICAgID4gPiArDQogICAgPiA+ICt2b2lk
ICp1a19tYWxsb2NfaWZtYWxsb2Moc3RydWN0IHVrX2FsbG9jICphLCBzaXplX3Qgc2l6ZSkNCiAg
ICA+ID4gK3sNCiAgICA+ID4gKwlzdHJ1Y3QgbWV0YWRhdGFfaWZtYWxsb2MgKm1ldGFkYXRhOw0K
ICAgID4gPiArCXNpemVfdCByZWFsc2l6ZSA9IHNpemUgKyBNRVRBREFUQV9JRk1BTExPQ19TSVpF
X1BPVzI7DQogICAgPiA+ICsJdm9pZCAqcHRyOw0KICAgID4gPiArDQogICAgPiA+ICsJVUtfQVNT
RVJUKGEpOw0KICAgID4gPiArCVVLX0FTU0VSVChhLT5tYWxsb2NfYmFja2VuZCk7DQogICAgPiA+
ICsNCiAgICA+ID4gKwkvKiBjaGVjayBmb3Igb3ZlcmZsb3cgKi8NCiAgICA+ID4gKwlpZiAodW5s
aWtlbHkocmVhbHNpemUgPCBzaXplKSkNCiAgICA+ID4gKwkJcmV0dXJuIE5VTEw7DQogICAgPiA+
ICsNCiAgICA+ID4gKwlwdHIgPSBhLT5tYWxsb2NfYmFja2VuZChhLCByZWFsc2l6ZSk7DQogICAg
PiA+ICsJaWYgKCFwdHIpDQogICAgPiA+ICsJCXJldHVybiBOVUxMOw0KICAgID4gPiArDQogICAg
PiA+ICsJbWV0YWRhdGEgPSBwdHI7DQogICAgPiA+ICsJbWV0YWRhdGEtPnNpemUgPSByZWFsc2l6
ZTsNCiAgICA+ID4gKwltZXRhZGF0YS0+YmFzZSA9IHB0cjsNCiAgICA+ID4gKw0KICAgID4gPiAr
CXJldHVybiAodm9pZCAqKSAoKHVpbnRwdHJfdCkgcHRyICsNCiAgICA+ID4gTUVUQURBVEFfSUZN
QUxMT0NfU0laRV9QT1cyKTsNCiAgICA+ID4gK30NCiAgICA+ID4gKw0KICAgID4gPiArdm9pZCAq
dWtfcmVhbGxvY19pZm1hbGxvYyhzdHJ1Y3QgdWtfYWxsb2MgKmEsIHZvaWQgKnB0ciwgc2l6ZV90
DQogICAgPiA+IHNpemUpDQogICAgPiA+ICt7DQogICAgPiA+ICsJdm9pZCAqcmV0cHRyOw0KICAg
ID4gPiArCXNpemVfdCBtYWxsb2NzaXplOw0KICAgID4gPiArDQogICAgPiA+ICsJVUtfQVNTRVJU
KGEpOw0KICAgID4gPiArCWlmICghcHRyKQ0KICAgID4gPiArCQlyZXR1cm4gdWtfbWFsbG9jX2lm
bWFsbG9jKGEsIHNpemUpOw0KICAgID4gPiArDQogICAgPiA+ICsJaWYgKHB0ciAmJiAhc2l6ZSkg
ew0KICAgID4gPiArCQl1a19mcmVlX2lmbWFsbG9jKGEsIHB0cik7DQogICAgPiA+ICsJCXJldHVy
biBOVUxMOw0KICAgID4gPiArCX0NCiAgICA+ID4gKw0KICAgID4gPiArCXJldHB0ciA9IHVrX21h
bGxvY19pZm1hbGxvYyhhLCBzaXplKTsNCiAgICA+ID4gKwlpZiAoIXJldHB0cikNCiAgICA+ID4g
KwkJcmV0dXJuIE5VTEw7DQogICAgPiA+ICsNCiAgICA+ID4gKwltYWxsb2NzaXplID0gdWtfZ2V0
bWFsbG9jc2l6ZV9pZm1hbGxvYyhwdHIpOw0KICAgID4gPiArDQogICAgPiA+ICsJbWVtY3B5KHJl
dHB0ciwgcHRyLCBNSU4oc2l6ZSwgbWFsbG9jc2l6ZSkpOw0KICAgID4gPiArDQogICAgPiA+ICsJ
dWtfZnJlZV9pZm1hbGxvYyhhLCBwdHIpOw0KICAgID4gPiArCXJldHVybiByZXRwdHI7DQogICAg
PiA+ICt9DQogICAgPiA+ICsNCiAgICA+ID4gK2ludCB1a19wb3NpeF9tZW1hbGlnbl9pZm1hbGxv
YyhzdHJ1Y3QgdWtfYWxsb2MgKmEsDQogICAgPiA+ICsJCQkJICAgICB2b2lkICoqbWVtcHRyLCBz
aXplX3QgYWxpZ24sDQogICAgPiA+IHNpemVfdCBzaXplKQ0KICAgID4gPiArew0KICAgID4gPiAr
CXN0cnVjdCBtZXRhZGF0YV9pZm1hbGxvYyAqbWV0YWRhdGE7DQogICAgPiA+ICsJc2l6ZV90IHJl
YWxzaXplLCBwYWRkaW5nOw0KICAgID4gPiArCXVpbnRwdHJfdCBpbnRwdHI7DQogICAgPiA+ICsN
CiAgICA+ID4gKwlVS19BU1NFUlQoYSk7DQogICAgPiA+ICsJaWYgKCgoYWxpZ24gLSAxKSAmIGFs
aWduKSAhPSAwDQogICAgPiA+ICsJICAgIHx8IGFsaWduIDwgc2l6ZW9mKHZvaWQgKikpDQogICAg
PiA+ICsJCXJldHVybiBFSU5WQUw7DQogICAgPiA+ICsNCiAgICA+ID4gKwlpZiAoIXNpemUpIHsN
CiAgICA+ID4gKwkJKm1lbXB0ciA9IE5VTEw7DQogICAgPiBTaG91bGQgd2UgdG91Y2ggKm1lbXB0
ciBpbiBjYXNlIG9mIGZhaWx1cmVzPyBZb3Ugc2VlbSBub3QgdG8gZG8gaXQNCiAgICA+IGluIA0K
ICAgID4gdGhlIG90aGVyIGNhc2VzLg0KICAgID4gaHR0cHM6Ly9tYW43Lm9yZy9saW51eC9tYW4t
cGFnZXMvbWFuMy9wb3NpeF9tZW1hbGlnbi4zLmh0bWwNCiAgICANCiAgICBUYWtpbmcgYSBsb29r
IGF0IGh0dHBzOi8vcHVicy5vcGVuZ3JvdXAub3JnL29ubGluZXB1YnMvOTY5OTkxOTc5OS9mdW5j
dA0KICAgIGlvbnMvcG9zaXhfbWVtYWxpZ24uaHRtbCwgc3BlY2lmaWNhbGx5Og0KICAgIA0KICAg
ICJJZiBzaXplIGlzIDAsIGVpdGhlcjoNCiAgICANCiAgICAgKiBwb3NpeF9tZW1hbGlnbigpIHNo
YWxsIG5vdCBhdHRlbXB0IHRvIGFsbG9jYXRlIGFueSBzcGFjZSwgaW4gd2hpY2gNCiAgICBjYXNl
IGVpdGhlciBhbiBpbXBsZW1lbnRhdGlvbi1kZWZpbmVkIGVycm9yIG51bWJlciBzaGFsbCBiZSBy
ZXR1cm5lZCwNCiAgICBvciB6ZXJvIHNoYWxsIGJlIHJldHVybmVkIHdpdGggYSBudWxsIHBvaW50
ZXIgcmV0dXJuZWQgaW4gbWVtcHRyLCBvcg0KICAgIA0KICAgICAqIHBvc2l4X21lbWFsaWduKCkg
c2hhbGwgYXR0ZW1wdCB0byBhbGxvY2F0ZSBzb21lIHNwYWNlIGFuZCwgaWYgdGhlDQogICAgYWxs
b2NhdGlvbiBzdWNjZWVkcywgemVybyBzaGFsbCBiZSByZXR1cm5lZCBhbmQgYSBwb2ludGVyIHRv
IHRoZQ0KICAgIGFsbG9jYXRlZCBzcGFjZSBzaGFsbCBiZSByZXR1cm5lZCBpbiBtZW1wdHIuIFRo
ZSBhcHBsaWNhdGlvbiBzaGFsbA0KICAgIGVuc3VyZSB0aGF0IHRoZSBwb2ludGVyIGlzIG5vdCB1
c2VkIHRvIGFjY2VzcyBhbiBvYmplY3QuIg0KICAgIA0KICAgIEluZGVlZCwgSSBwcmVmZXIgdG8g
cmV0dXJuIGFuIGVycm9yIGNvZGUgaW5zdGVhZCBvZiBzZXR0aW5nIG1lbXB0ciBhbmQNCiAgICBy
ZXR1cm5pbmcgemVyby4gTXkgZmVhciBpcyB0aGF0IHNvbWUgdXNlcnMgbWlnaHQgZGVyZWZlcmVu
Y2UgbWVtcHRyDQogICAgYWZ0ZXIgb2JzZXJ2aW5nIGEgemVybyByZXR1cm4gdmFsdWUuIERvIHlv
dSB0aGluayBFSU5WQUwgaXMgZmluZSBpbg0KICAgIHRoaXMgY2FzZT8gSW4gdGhpcyBjYXNlIHdl
IGNvdWxkIGp1c3QgcmVtb3ZlIGAqbWVtcHRyID0gTlVMTDtgLg0KICAgIA0KICAgIE5vdGUgdGhh
dCB0aGlzIGJ1ZyB3YXMgYWxyZWFkeSBwcmVzZW50IGluIHVrX3Bvc2l4X21lbWFsaWduX2lmcGFn
ZXMsIEkNCiAgICBpbnRlbnRpb25hbGx5IHJlcHJvZHVjZWQgaXQgaW4gdGhlIGlmbWFsbG9jIHdy
YXBwZXIuIEl0IHdhcyBpbnRyb2R1Y2VkDQogICAgaW4gaHR0cHM6Ly9naXRodWIuY29tL3VuaWty
YWZ0L3VuaWtyYWZ0L2NvbW1pdC9hMzIzZmJkNjdhYzNjYjIxMTM5NjMzYjMNCiAgICAwMGEwMjQ1
MzgxNjc0OTNlDQogICAgDQpHb29kIHBvaW50LiBQZXJzb25hbGx5LCBJIHByZWZlciByZXR1cm5p
bmcgYW4gZXJyb3IgYW5kIG5vdCB0b3VjaGluZyBtZW1wdHIsDQpzaW5jZSB3ZSBoYXZlIGNob2lj
ZS4gVGhhdCBmZWVscyBhIGJpdCBtb3JlIHdlbGwtZGVmaW5lZCB0aGFuIHRoZSBvdGhlciBiZWhh
dmlvci4NCkluIGNhc2Ugd2Ugd2lsbCBjb21lIGFjcm9zcyB3aGlsZSBwb3J0aW5nIGFuIGFwcGxp
Y2F0aW9uIHRoYXQgZXhwZWN0IHRoZSBvdGhlcg0KYmVoYXZpb3IsIHdlIG1heSB0aGluayBvZiBh
ZGRpbmcgYSBtZW51IGNvbmZpZyBvcHRpb24gdG8gc3dpdGNoIGJldHdlZW4gdGhlbS4NCkkgcmVh
bGx5IGhvcGUgaXQgaXMgcmFyZSB0aGF0IHNvbWVvbmUgY2FsbHMgcG9zaXhfbWVtYWxpZ24oKSB3
aXRoIHNpemUgMC4uLg0KDQpDYW4geW91IGFkZCBhIGJyaWVmIGNvbW1lbnQgdGhhdCB0d28gZGVz
Y3JpYmVkIGJlaGF2aW9yIGV4aXN0IGZvciBzaXplID0gMD8NCkluIG9yZGVyIHRvIGtlZXAgdWtf
cG9zaXhfbWVtYWxpZ25faWZwYWdlcygpIGVxdWl2YWxlbnQsIGNhbiB5b3UgcmVtb3ZlDQpzZXR0
aW5nIG1lbXB0ciBhbHNvIHRoZXJlIGZvciB0aGlzIGNhc2U/IFdpdGggaGF2aW5nIHRoZSBjb21t
ZW50IGl0IGlzDQpmaW5lIHRvIGRvIHRoaXMgaW4gdGhlIHNhbWUgcGF0Y2guDQoNCiAgICA+ID4g
KwkJcmV0dXJuIEVJTlZBTDsNCiAgICA+ID4gK30JDQogICAgPiA+ICsNCiAgICA+ID4gKwkvKiBT
dG9yZSBzaXplIGluZm9ybWF0aW9uIHByZWNlZWRpbmcgdGhlIG1lbW9yeSBibG9jay4NCiAgICA+
ID4gU2luY2Ugd2UgcmV0dXJuDQogICAgPiA+ICsJICogcG9pbnRlcnMgYWxpZ25lZCBhdCBgYWxp
Z25gIHdlIG5lZWQgdG8gcmVzZXJ2ZSBhdCBsZWFzdA0KICAgID4gPiB0aGF0IG11Y2gNCiAgICA+
ID4gKwkgKiBzcGFjZSBmb3IgdGhlIHNpemUgaW5mb3JtYXRpb24uDQogICAgPiA+ICsJICovDQog
ICAgPiA+ICsJaWYgKGFsaWduIDwgTUVUQURBVEFfSUZNQUxMT0NfU0laRV9QT1cyKSB7DQogICAg
PiA+ICsJCWFsaWduID0gTUVUQURBVEFfSUZNQUxMT0NfU0laRV9QT1cyOw0KICAgID4gPiArCQlw
YWRkaW5nID0gMDsNCiAgICA+ID4gKwl9IGVsc2Ugew0KICAgID4gPiArCQlwYWRkaW5nID0gTUVU
QURBVEFfSUZNQUxMT0NfU0laRV9QT1cyOw0KICAgID4gPiArCX0NCiAgICA+ID4gKw0KICAgID4g
PiArCXJlYWxzaXplID0gc2l6ZSArIHBhZGRpbmcgKyBhbGlnbjsNCiAgICA+ID4gKw0KICAgID4g
PiArCS8qIGNoZWNrIGZvciBvdmVyZmxvdyAqLw0KICAgID4gPiArCWlmICh1bmxpa2VseShyZWFs
c2l6ZSA8IHNpemUpKQ0KICAgID4gPiArCQlyZXR1cm4gTlVMTDsNCiAgICA+IEh1bSwgeW91IHNo
b3VsZCByZXR1cm4gYW4gZXJybm8uIEkgd291bGQgY2hvb3NlIEVOT01FTSwgdGhhdHMgY2xvc2Vy
IA0KICAgID4gaW5saW5lIHdpdGggbWFsbG9jOg0KICAgID4gDQogICAgPiAJCXJldHVybiBFTk9N
RU07DQogICAgU291bmRzIGdvb2QuDQogICAgPiANCiAgICA+ID4gDQogICAgPiA+IA0KICAgID4g
PiArDQogICAgPiA+ICsJaW50cHRyID0gKHVpbnRwdHJfdCkgYS0+bWFsbG9jX2JhY2tlbmQoYSwg
cmVhbHNpemUpOw0KICAgID4gPiArDQogICAgPiA+ICsJaWYgKCFpbnRwdHIpDQogICAgPiA+ICsJ
CXJldHVybiBFTk9NRU07DQogICAgPiA+ICsNCiAgICA+ID4gKwkqbWVtcHRyID0gKHZvaWQgKikg
QUxJR05fVVAoaW50cHRyICsNCiAgICA+ID4gTUVUQURBVEFfSUZNQUxMT0NfU0laRV9QT1cyLA0K
ICAgID4gPiArCQkJCSAgICAodWludHB0cl90KSBhbGlnbik7DQogICAgPiA+ICsNCiAgICA+ID4g
KwltZXRhZGF0YSA9IHVrX2dldF9tZXRhZGF0YV9pZm1hbGxvYygqbWVtcHRyKTsNCiAgICA+ID4g
Kw0KICAgID4gPiArCS8qIGNoZWNrIGZvciB1bmRlcmZsb3cgKi8NCiAgICA+ID4gKwlVS19BU1NF
UlQoaW50cHRyIDw9ICh1aW50cHRyX3QpIG1ldGFkYXRhKTsNCiAgICA+ID4gKw0KICAgID4gPiAr
CW1ldGFkYXRhLT5zaXplID0gcmVhbHNpemU7DQogICAgPiA+ICsJbWV0YWRhdGEtPmJhc2UgPSAo
dm9pZCAqKSBpbnRwdHI7DQogICAgPiA+ICsNCiAgICA+ID4gKwlyZXR1cm4gMDsNCiAgICA+ID4g
K30NCiAgICA+ID4gKw0KICAgID4gPiArI2VuZGlmDQogICAgPiA+ICsNCiAgICA+ID4gICB2b2lk
IHVrX3BmcmVlX2NvbXBhdChzdHJ1Y3QgdWtfYWxsb2MgKmEsIHZvaWQgKnB0ciwNCiAgICA+ID4g
ICAJCSAgICAgdW5zaWduZWQgbG9uZyBudW1fcGFnZXMgX191bnVzZWQpDQogICAgPiA+ICAgew0K
ICAgID4gPiBkaWZmIC0tZ2l0IGEvbGliL3VrYWxsb2MvZXhwb3J0c3ltcy51ayBiL2xpYi91a2Fs
bG9jL2V4cG9ydHN5bXMudWsNCiAgICA+ID4gaW5kZXggMmM4YTkwZi4uMjFjMTk5NiAxMDA2NDQN
CiAgICA+ID4gLS0tIGEvbGliL3VrYWxsb2MvZXhwb3J0c3ltcy51aw0KICAgID4gPiArKysgYi9s
aWIvdWthbGxvYy9leHBvcnRzeW1zLnVrDQogICAgPiA+IEBAIC00LDYgKzQsMTAgQEAgdWtfbWFs
bG9jX2lmcGFnZXMNCiAgICA+ID4gICB1a19mcmVlX2lmcGFnZXMNCiAgICA+ID4gICB1a19yZWFs
bG9jX2lmcGFnZXMNCiAgICA+ID4gICB1a19wb3NpeF9tZW1hbGlnbl9pZnBhZ2VzDQogICAgPiA+
ICt1a19tYWxsb2NfaWZtYWxsb2MNCiAgICA+ID4gK3VrX3JlYWxsb2NfaWZtYWxsb2MNCiAgICA+
ID4gK3VrX3Bvc2l4X21lbWFsaWduX2lmbWFsbG9jDQogICAgPiA+ICt1a19mcmVlX2lmbWFsbG9j
DQogICAgPiA+ICAgdWtfY2FsbG9jX2NvbXBhdA0KICAgID4gPiAgIHVrX21lbWFsaWduX2NvbXBh
dA0KICAgID4gPiAgIHVrX3JlYWxsb2NfY29tcGF0DQogICAgPiA+IGRpZmYgLS1naXQgYS9saWIv
dWthbGxvYy9pbmNsdWRlL3VrL2FsbG9jLmgNCiAgICA+ID4gYi9saWIvdWthbGxvYy9pbmNsdWRl
L3VrL2FsbG9jLmgNCiAgICA+ID4gaW5kZXggNWJmYTJmMi4uMTQ1NzkyMiAxMDA2NDQNCiAgICA+
ID4gLS0tIGEvbGliL3VrYWxsb2MvaW5jbHVkZS91ay9hbGxvYy5oDQogICAgPiA+ICsrKyBiL2xp
Yi91a2FsbG9jL2luY2x1ZGUvdWsvYWxsb2MuaA0KICAgID4gPiBAQCAtODUsNiArODUsMTEgQEAg
c3RydWN0IHVrX2FsbG9jIHsNCiAgICA+ID4gICAJdWtfYWxsb2NfbWVtYWxpZ25fZnVuY190IG1l
bWFsaWduOw0KICAgID4gPiAgIAl1a19hbGxvY19mcmVlX2Z1bmNfdCBmcmVlOw0KICAgID4gPiAg
IA0KICAgID4gPiArI2lmIENPTkZJR19MSUJVS0FMTE9DX0lGTUFMTE9DDQogICAgPiA+ICsJdWtf
YWxsb2NfZnJlZV9mdW5jX3QgZnJlZV9iYWNrZW5kOw0KICAgID4gPiArCXVrX2FsbG9jX21hbGxv
Y19mdW5jX3QgbWFsbG9jX2JhY2tlbmQ7DQogICAgPiA+ICsjZW5kaWYNCiAgICA+ID4gKw0KICAg
ID4gPiAgIAkvKiBwYWdlIGFsbG9jYXRpb24gaW50ZXJmYWNlICovDQogICAgPiA+ICAgCXVrX2Fs
bG9jX3BhbGxvY19mdW5jX3QgcGFsbG9jOw0KICAgID4gPiAgIAl1a19hbGxvY19wZnJlZV9mdW5j
X3QgcGZyZWU7DQogICAgPiA+IGRpZmYgLS1naXQgYS9saWIvdWthbGxvYy9pbmNsdWRlL3VrL2Fs
bG9jX2ltcGwuaA0KICAgID4gPiBiL2xpYi91a2FsbG9jL2luY2x1ZGUvdWsvYWxsb2NfaW1wbC5o
DQogICAgPiA+IGluZGV4IDhiY2NhOTQuLmIxNWY0OWUgMTAwNjQ0DQogICAgPiA+IC0tLSBhL2xp
Yi91a2FsbG9jL2luY2x1ZGUvdWsvYWxsb2NfaW1wbC5oDQogICAgPiA+ICsrKyBiL2xpYi91a2Fs
bG9jL2luY2x1ZGUvdWsvYWxsb2NfaW1wbC5oDQogICAgPiA+IEBAIC02Miw2ICs2MiwxNCBAQCBp
bnQgdWtfcG9zaXhfbWVtYWxpZ25faWZwYWdlcyhzdHJ1Y3QgdWtfYWxsb2MNCiAgICA+ID4gKmEs
IHZvaWQgKiptZW1wdHIsDQogICAgPiA+ICAgCQkJCXNpemVfdCBhbGlnbiwgc2l6ZV90IHNpemUp
Ow0KICAgID4gPiAgIHZvaWQgdWtfZnJlZV9pZnBhZ2VzKHN0cnVjdCB1a19hbGxvYyAqYSwgdm9p
ZCAqcHRyKTsNCiAgICA+ID4gICANCiAgICA+ID4gKyNpZiBDT05GSUdfTElCVUtBTExPQ19JRk1B
TExPQw0KICAgID4gPiArdm9pZCAqdWtfbWFsbG9jX2lmbWFsbG9jKHN0cnVjdCB1a19hbGxvYyAq
YSwgc2l6ZV90IHNpemUpOw0KICAgID4gPiArdm9pZCAqdWtfcmVhbGxvY19pZm1hbGxvYyhzdHJ1
Y3QgdWtfYWxsb2MgKmEsIHZvaWQgKnB0ciwgc2l6ZV90DQogICAgPiA+IHNpemUpOw0KICAgID4g
PiAraW50IHVrX3Bvc2l4X21lbWFsaWduX2lmbWFsbG9jKHN0cnVjdCB1a19hbGxvYyAqYSwgdm9p
ZCAqKm1lbXB0ciwNCiAgICA+ID4gKwkJCQkgICAgIHNpemVfdCBhbGlnbiwgc2l6ZV90IHNpemUp
Ow0KICAgID4gPiArdm9pZCB1a19mcmVlX2lmbWFsbG9jKHN0cnVjdCB1a19hbGxvYyAqYSwgdm9p
ZCAqcHRyKTsNCiAgICA+ID4gKyNlbmRpZg0KICAgID4gPiArDQogICAgPiA+ICAgLyogRnVuY3Rp
b25hbGl0eSB0aGF0IGlzIHByb3ZpZGVkIGJhc2VkIG9uIG1hbGxvYygpIGFuZA0KICAgID4gPiBw
b3NpeF9tZW1hbGlnbigpICovDQogICAgPiA+ICAgdm9pZCAqdWtfY2FsbG9jX2NvbXBhdChzdHJ1
Y3QgdWtfYWxsb2MgKmEsIHNpemVfdCBudW0sIHNpemVfdA0KICAgID4gPiBsZW4pOw0KICAgID4g
PiAgIHZvaWQgKnVrX3JlYWxsb2NfY29tcGF0KHN0cnVjdCB1a19hbGxvYyAqYSwgdm9pZCAqcHRy
LCBzaXplX3QNCiAgICA+ID4gc2l6ZSk7DQogICAgPiA+IEBAIC04OCw2ICs5NiwyNSBAQCB2b2lk
IHVrX3BmcmVlX2NvbXBhdChzdHJ1Y3QgdWtfYWxsb2MgKmEsIHZvaWQNCiAgICA+ID4gKnB0ciwg
dW5zaWduZWQgbG9uZyBudW1fcGFnZXMpOw0KICAgID4gPiAgIAkJdWtfYWxsb2NfcmVnaXN0ZXIo
KGEpKTsJCQkJDQogICAgPiA+IAlcDQogICAgPiA+ICAgCX0gd2hpbGUgKDApDQogICAgPiA+ICAg
DQogICAgPiA+ICsjaWYgQ09ORklHX0xJQlVLQUxMT0NfSUZNQUxMT0MNCiAgICA+ID4gKyNkZWZp
bmUgdWtfYWxsb2NfaW5pdF9tYWxsb2NfaWZtYWxsb2MoYSwgbWFsbG9jX2YsIGZyZWVfZiwNCiAg
ICA+ID4gYWRkbWVtX2YpIAlcDQogICAgPiA+ICsJZG8gewkJCQkJCQkNCiAgICA+ID4gCVwNCiAg
ICA+ID4gKwkJKGEpLT5tYWxsb2MgICAgICAgICA9IHVrX21hbGxvY19pZm1hbGxvYzsJCQ0KICAg
ID4gPiBcDQogICAgPiA+ICsJCShhKS0+Y2FsbG9jICAgICAgICAgPSB1a19jYWxsb2NfY29tcGF0
OwkJDQogICAgPiA+IAlcDQogICAgPiA+ICsJCShhKS0+cmVhbGxvYyAgICAgICAgPSB1a19yZWFs
bG9jX2lmbWFsbG9jOwkJDQogICAgPiA+IFwNCiAgICA+ID4gKwkJKGEpLT5wb3NpeF9tZW1hbGln
biA9IHVrX3Bvc2l4X21lbWFsaWduX2lmbWFsbG9jOwkNCiAgICA+ID4gXA0KICAgID4gPiArCQko
YSktPm1lbWFsaWduICAgICAgID0gdWtfbWVtYWxpZ25fY29tcGF0OwkJDQogICAgPiA+IFwNCiAg
ICA+ID4gKwkJKGEpLT5tYWxsb2NfYmFja2VuZCA9IChtYWxsb2NfZik7CQkJDQogICAgPiA+IFwN
CiAgICA+ID4gKwkJKGEpLT5mcmVlX2JhY2tlbmQgICA9IChmcmVlX2YpOwkJCQ0KICAgID4gPiAJ
XA0KICAgID4gPiArCQkoYSktPmZyZWUgICAgICAgICAgID0gdWtfZnJlZV9pZm1hbGxvYzsJCQ0K
ICAgID4gPiAJXA0KICAgID4gPiArCQkoYSktPnBhbGxvYyAgICAgICAgID0gdWtfcGFsbG9jX2Nv
bXBhdDsJCQ0KICAgID4gPiAJXA0KICAgID4gPiArCQkoYSktPnBmcmVlICAgICAgICAgID0gdWtf
cGZyZWVfY29tcGF0OwkJDQogICAgPiA+IAlcDQogICAgPiA+ICsJCShhKS0+YWRkbWVtICAgICAg
ICAgPSAoYWRkbWVtX2YpOwkJCQ0KICAgID4gPiBcDQogICAgPiA+ICsJCQkJCQkJCQkNCiAgICA+
ID4gXA0KICAgID4gPiArCQl1a19hbGxvY19yZWdpc3RlcigoYSkpOwkJCQkNCiAgICA+ID4gCVwN
CiAgICA+ID4gKwl9IHdoaWxlICgwKQ0KICAgID4gPiArI2VuZGlmDQogICAgPiA+ICsNCiAgICA+
ID4gICAvKiBTaG9ydGN1dCBmb3IgZG9pbmcgYSByZWdpc3RyYXRpb24gb2YgYW4gYWxsb2NhdG9y
IHRoYXQgb25seQ0KICAgID4gPiAgICAqIGltcGxlbWVudHMgcGFsbG9jKCksIHBmcmVlKCksIGFk
ZG1lbSgpDQogICAgPiA+ICAgICovDQoNClRoYW5rcywNCg0KU2ltb24NCiAgICANCg0K


From minios-devel-bounces@lists.xenproject.org Fri Jul 31 12:27:10 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 31 Jul 2020 12:27:10 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k1U7v-0006Bx-M1; Fri, 31 Jul 2020 12:27:07 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=hJwr=BK=gmail.com=cristianvijelie@srs-us1.protection.inumbo.net>)
 id 1k1Sr0-0002dk-OA
 for minios-devel@lists.xenproject.org; Fri, 31 Jul 2020 11:05:34 +0000
X-Inumbo-ID: bfc6af56-d31d-11ea-8e24-bc764e2007e4
Received: from mail-ej1-x62c.google.com (unknown [2a00:1450:4864:20::62c])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id bfc6af56-d31d-11ea-8e24-bc764e2007e4;
 Fri, 31 Jul 2020 11:05:31 +0000 (UTC)
Received: by mail-ej1-x62c.google.com with SMTP id bo3so8391175ejb.11
 for <minios-devel@lists.xenproject.org>; Fri, 31 Jul 2020 04:05:31 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:subject:date:message-id:mime-version
 :content-transfer-encoding;
 bh=UX008zcuOX9lUC2yosqX9ct4/vhxf1O81rMzGvpvsMA=;
 b=pmWGz0T1jAGp14d2kQ9QqTH3B7gumq8iUP82KXHFto+tywJ784W6kf6inS0TdJxLEf
 RPiyBlbX8W8ZuC1j2SixYzmrKOQmupddx0xPONrUJmZw0uCVqcr9IM7wrg2y/QvDrnj8
 cBSTaDpNsjQk8HWwIcrg8eXcaH1c6wgXVeQLBI5KUcbP5LrH5w3PfC8eV8CRyiQTUpbM
 JpmKHbhPjsfPsnWjh9Zr8NYxkvICDgYsHFIaRr1AjcIONUWKkh9J1AJ0WGwwu4LTgPyF
 E3o2DQ2Eqlhb/H2hkrJrwioCe8WP1Q0JTwIRDlLW4w7ZPN/IlMbe7kt99V3aDcjvOh6+
 DN3Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:subject:date:message-id:mime-version
 :content-transfer-encoding;
 bh=UX008zcuOX9lUC2yosqX9ct4/vhxf1O81rMzGvpvsMA=;
 b=M2IBTWos1a2ds8P1tLxe3hj2uApivMvpo+TNTmZp5CSFivLSE2Fxks8hT5Dc/HW47E
 aYetbepxg1QQNh/eokkWHvtYg2mXJuAVs8ikxu3KoRAgSIXZF1yuQQ9e0FH2QAEGpRlj
 Q3WBnhcYzojggavjS+GAr+hXp4mvuq2Mlbwvr1cTV6moqU9EDld1iDmOHyNCXiPGNfmW
 5qs2Qklk2xtmPVS9xFIXpnXVDVfO4AbPqJIrRGFyI96NYwUQwkmkJolW9fHgwCOWRYIB
 /nlS/eIH4iZvIIUapfl1+qjc2uHiJ6jtTe8phWSCWfVRex5/KkqIhicguRRtybARvIDA
 cNtg==
X-Gm-Message-State: AOAM532HVYpSzgHzo87cnVnLrKym+Yl69Ks/W6lN6GiXtUdt86JOwkUK
 gFvvnd7Kfk09ndW2S/WaLuTI/VkLeos=
X-Google-Smtp-Source: ABdhPJwKnCom0aodufhEUxznPsoqLpXFOl+0PJSH1HkS/koC0HzzZ+08miZVoh9X3iYnmluLmhTw+A==
X-Received: by 2002:a17:906:430a:: with SMTP id
 j10mr3551275ejm.163.1596193529719; 
 Fri, 31 Jul 2020 04:05:29 -0700 (PDT)
Received: from localhost.localdomain ([2a02:2f0b:450d:d00:c04e:b922:7f9a:24f4])
 by smtp.gmail.com with ESMTPSA id r9sm9368596edt.1.2020.07.31.04.05.28
 for <minios-devel@lists.xenproject.org>
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 31 Jul 2020 04:05:29 -0700 (PDT)
From: cristian-vijelie <cristianvijelie@gmail.com>
To: minios-devel@lists.xenproject.org
Subject: [UNIKRAFT RFC PATCH] Added the irq-safe (I hope) memcpy in isrlibc
Date: Fri, 31 Jul 2020 14:05:27 +0300
Message-Id: <20200731110527.51514-1-cristianvijelie@gmail.com>
X-Mailer: git-send-email 2.25.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Mailman-Approved-At: Fri, 31 Jul 2020 12:27:07 +0000
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

---
 lib/Makefile.uk                               |   1 +
 lib/isrlibc/Config.uk                         |  16 ++
 lib/isrlibc/Makefile.uk                       |  28 ++++
 lib/isrlibc/arch/arm/bits/fcntl.h             |  40 +++++
 lib/isrlibc/arch/arm64/bits/fcntl.h           |  38 +++++
 lib/isrlibc/arch/x86_64/bits/fcntl.h          |  40 +++++
 lib/isrlibc/exportsyms.uk                     |   2 +
 .../include/isrlibc-internal/shareddefs.h     | 146 ++++++++++++++++++
 lib/isrlibc/include/string.h                  |  53 +++++++
 lib/isrlibc/include/sys/file.h                |  21 +++
 lib/isrlibc/include/sys/mount.h               | 109 +++++++++++++
 lib/isrlibc/include/sys/param.h               |  38 +++++
 lib/isrlibc/include/sys/select.h              |  82 ++++++++++
 lib/isrlibc/include/sys/stat.h                | 135 ++++++++++++++++
 lib/isrlibc/include/sys/statfs.h              |  36 +++++
 lib/isrlibc/include/sys/statvfs.h             |  54 +++++++
 lib/isrlibc/include/sys/types.h               |  69 +++++++++
 lib/isrlibc/include/sys/uio.h                 |  76 +++++++++
 lib/isrlibc/string.c                          |  16 ++
 19 files changed, 1000 insertions(+)
 create mode 100644 lib/isrlibc/Config.uk
 create mode 100644 lib/isrlibc/Makefile.uk
 create mode 100644 lib/isrlibc/arch/arm/bits/fcntl.h
 create mode 100644 lib/isrlibc/arch/arm64/bits/fcntl.h
 create mode 100644 lib/isrlibc/arch/x86_64/bits/fcntl.h
 create mode 100644 lib/isrlibc/exportsyms.uk
 create mode 100644 lib/isrlibc/include/isrlibc-internal/shareddefs.h
 create mode 100644 lib/isrlibc/include/string.h
 create mode 100644 lib/isrlibc/include/sys/file.h
 create mode 100644 lib/isrlibc/include/sys/mount.h
 create mode 100644 lib/isrlibc/include/sys/param.h
 create mode 100644 lib/isrlibc/include/sys/select.h
 create mode 100644 lib/isrlibc/include/sys/stat.h
 create mode 100644 lib/isrlibc/include/sys/statfs.h
 create mode 100644 lib/isrlibc/include/sys/statvfs.h
 create mode 100644 lib/isrlibc/include/sys/types.h
 create mode 100644 lib/isrlibc/include/sys/uio.h
 create mode 100644 lib/isrlibc/string.c

diff --git a/lib/Makefile.uk b/lib/Makefile.uk
index aa7e730..b43234b 100644
--- a/lib/Makefile.uk
+++ b/lib/Makefile.uk
@@ -11,6 +11,7 @@ $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/posix-sysinfo))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukdebug))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukargparse))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uktimeconv))
+$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/isrlibc))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/nolibc))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukalloc))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukallocbbuddy))
diff --git a/lib/isrlibc/Config.uk b/lib/isrlibc/Config.uk
new file mode 100644
index 0000000..b4d4b5a
--- /dev/null
+++ b/lib/isrlibc/Config.uk
@@ -0,0 +1,16 @@
+menuconfig LIBISRLIBC
+	bool "isrlibc: IRQ-safe subset of libc functionality"
+	depends on !HAVE_LIBC
+	default y if !HAVE_LIBC
+	imply LIBUKTIME
+
+if LIBISRLIBC
+	config LIBISRLIBC_UKDEBUG_ASSERT
+		bool "Implement assertions with libukdebug"
+		default y if LIBUKDEBUG
+		default n
+		help
+			Assertions (`assert()` defined in `<assert.h>`) are mapped to `UK_ASSERT()`.
+			If selected, please note that libc assertions are also removed from the code
+			when assertions are disabled in libukdebug.
+endif
diff --git a/lib/isrlibc/Makefile.uk b/lib/isrlibc/Makefile.uk
new file mode 100644
index 0000000..42e0e85
--- /dev/null
+++ b/lib/isrlibc/Makefile.uk
@@ -0,0 +1,28 @@
+$(eval $(call addlib_s,libisrlibc,$(CONFIG_LIBISRLIBC)))
+
+LIBISRLIBC_NO_EXTENDED          += -mno-mmx
+LIBISRLIBC_NO_EXTENDED          += -mno-sse
+LIBISRLIBC_NO_EXTENDED          += -mno-sse2
+LIBISRLIBC_NO_EXTENDED          += -mno-sse3
+LIBISRLIBC_NO_EXTENDED          += -mno-ssse3
+LIBISRLIBC_NO_EXTENDED          += -mno-sse4
+LIBISRLIBC_NO_EXTENDED          += -mno-sse4a
+LIBISRLIBC_NO_EXTENDED          += -mno-sse4.1
+LIBISRLIBC_NO_EXTENDED          += -mno-sse4.2
+LIBISRLIBC_NO_EXTENDED          += -mno-avx
+LIBISRLIBC_NO_EXTENDED          += -mfpmath=387
+
+CFLAGS-$(CONFIG_LIBISRLIBC)		+= $(LIBISRLIBC_NO_EXTENDED)
+CXXFLAGS-$(CONFIG_LIBISRLIBC)	+= $(LIBISRLIBC_NO_EXTENDED)
+
+LIBISRLIBC_GLOBAL_INCLUDES-y     += -I$(LIBISRLIBC_BASE)/include
+LIBISRLIBC_GLOBAL_INCLUDES-y     += -I$(LIBISRLIBC_BASE)/arch/$(ARCH)
+LIBISRLIBC_GLOBAL_INCLUDES-y     += -I$(LIBISRLIBC_BASE)/musl-imported/include
+LIBISRLIBC_GLOBAL_INCLUDES-y     += -I$(LIBISRLIBC_BASE)/musl-imported/arch/generic
+CINCLUDES-$(CONFIG_LIBISRLIBC)   += $(LIBISRLIBC_GLOBAL_INCLUDES-y)
+CXXINCLUDES-$(CONFIG_LIBISRLIBC) += $(LIBISRLIBC_GLOBAL_INCLUDES-y)
+
+LIBISRLIBC_SRCS-y += $(LIBISRLIBC_BASE)/string.c
+
+# Localize internal symbols (starting with __*)
+LIBISRLIBC_OBJCFLAGS-y += -w -L __*
diff --git a/lib/isrlibc/arch/arm/bits/fcntl.h b/lib/isrlibc/arch/arm/bits/fcntl.h
new file mode 100644
index 0000000..4cb1753
--- /dev/null
+++ b/lib/isrlibc/arch/arm/bits/fcntl.h
@@ -0,0 +1,40 @@
+#define O_CREAT        0100
+#define O_EXCL         0200
+#define O_NOCTTY       0400
+#define O_TRUNC       01000
+#define O_APPEND      02000
+#define O_NONBLOCK    04000
+#define O_DSYNC      010000
+#define O_SYNC     04010000
+#define O_RSYNC    04010000
+#define O_DIRECTORY  040000
+#define O_NOFOLLOW  0100000
+#define O_CLOEXEC  02000000
+
+#define O_ASYNC      020000
+#define O_DIRECT    0200000
+#define O_LARGEFILE 0400000
+#define O_NOATIME  01000000
+#define O_PATH    010000000
+#define O_TMPFILE 020040000
+#define O_NDELAY O_NONBLOCK
+
+#define F_DUPFD  0
+#define F_GETFD  1
+#define F_SETFD  2
+#define F_GETFL  3
+#define F_SETFL  4
+
+#define F_SETOWN 8
+#define F_GETOWN 9
+#define F_SETSIG 10
+#define F_GETSIG 11
+
+#define F_GETLK 12
+#define F_SETLK 13
+#define F_SETLKW 14
+
+#define F_SETOWN_EX 15
+#define F_GETOWN_EX 16
+
+#define F_GETOWNER_UIDS 17
diff --git a/lib/isrlibc/arch/arm64/bits/fcntl.h b/lib/isrlibc/arch/arm64/bits/fcntl.h
new file mode 100644
index 0000000..9278797
--- /dev/null
+++ b/lib/isrlibc/arch/arm64/bits/fcntl.h
@@ -0,0 +1,38 @@
+#define O_CREAT        0100
+#define O_EXCL         0200
+#define O_NOCTTY       0400
+#define O_TRUNC       01000
+#define O_APPEND      02000
+#define O_NONBLOCK    04000
+#define O_DSYNC      010000
+#define O_SYNC     04010000
+#define O_RSYNC    04010000
+#define O_DIRECTORY  040000
+#define O_NOFOLLOW  0100000
+#define O_CLOEXEC  02000000
+
+#define O_ASYNC      020000
+#define O_DIRECT    0200000
+#define O_LARGEFILE 0400000
+#define O_NOATIME  01000000
+#define O_PATH    010000000
+#define O_TMPFILE 020040000
+#define O_NDELAY O_NONBLOCK
+
+#define F_DUPFD  0
+#define F_GETFD  1
+#define F_SETFD  2
+#define F_GETFL  3
+#define F_SETFL  4
+#define F_GETLK  5
+#define F_SETLK  6
+#define F_SETLKW 7
+#define F_SETOWN 8
+#define F_GETOWN 9
+#define F_SETSIG 10
+#define F_GETSIG 11
+
+#define F_SETOWN_EX 15
+#define F_GETOWN_EX 16
+
+#define F_GETOWNER_UIDS 17
diff --git a/lib/isrlibc/arch/x86_64/bits/fcntl.h b/lib/isrlibc/arch/x86_64/bits/fcntl.h
new file mode 100644
index 0000000..1b88ad3
--- /dev/null
+++ b/lib/isrlibc/arch/x86_64/bits/fcntl.h
@@ -0,0 +1,40 @@
+#define O_CREAT        0100
+#define O_EXCL         0200
+#define O_NOCTTY       0400
+#define O_TRUNC       01000
+#define O_APPEND      02000
+#define O_NONBLOCK    04000
+#define O_DSYNC      010000
+#define O_SYNC     04010000
+#define O_RSYNC    04010000
+#define O_DIRECTORY 0200000
+#define O_NOFOLLOW  0400000
+#define O_CLOEXEC  02000000
+
+#define O_ASYNC      020000
+#define O_DIRECT     040000
+#define O_LARGEFILE       0
+#define O_NOATIME  01000000
+#define O_PATH    010000000
+#define O_TMPFILE 020200000
+#define O_NDELAY O_NONBLOCK
+
+#define F_DUPFD  0
+#define F_GETFD  1
+#define F_SETFD  2
+#define F_GETFL  3
+#define F_SETFL  4
+
+#define F_SETOWN 8
+#define F_GETOWN 9
+#define F_SETSIG 10
+#define F_GETSIG 11
+
+#define F_GETLK 5
+#define F_SETLK 6
+#define F_SETLKW 7
+
+#define F_SETOWN_EX 15
+#define F_GETOWN_EX 16
+
+#define F_GETOWNER_UIDS 17
diff --git a/lib/isrlibc/exportsyms.uk b/lib/isrlibc/exportsyms.uk
new file mode 100644
index 0000000..5986f7e
--- /dev/null
+++ b/lib/isrlibc/exportsyms.uk
@@ -0,0 +1,2 @@
+# string
+isr_memcpy
diff --git a/lib/isrlibc/include/isrlibc-internal/shareddefs.h b/lib/isrlibc/include/isrlibc-internal/shareddefs.h
new file mode 100644
index 0000000..d386820
--- /dev/null
+++ b/lib/isrlibc/include/isrlibc-internal/shareddefs.h
@@ -0,0 +1,146 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Florian Schmidt <florian.schmidt@neclab.eu>
+ *
+ * Copyright (c) 2018, NEC Labs Europe, NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
+/* This header does by design not have include guards, so that it can be
+ * included from multiple files. The __NEED_x macros instead make sure that
+ * only those definitions are included that are required by that specific
+ * file, and only if they haven't been defined on a previous pass through
+ * this file.
+ */
+
+#include <uk/config.h>
+#include <uk/arch/types.h>
+
+#if (defined __NEED_NULL && !defined __DEFINED_NULL)
+#ifdef __cplusplus
+#define NULL 0L
+#else
+#define NULL ((void *) 0)
+#endif
+#define __DEFINED__NULL
+#endif
+
+#if (defined __NEED_size_t && !defined __DEFINED_size_t)
+typedef __sz size_t;
+#define __DEFINED_size_t
+#endif
+
+#if (defined __NEED_ssize_t && !defined __DEFINED_ssize_t)
+typedef __ssz ssize_t;
+#define __DEFINED_ssize_t
+#endif
+
+#if (defined __NEED_off_t && !defined __DEFINED_off_t)
+typedef __off off_t;
+#define __DEFINED_off_t
+#endif
+
+#if CONFIG_HAVE_TIME
+#include <uk/time_types.h>
+#endif
+
+#if (defined __NEED_mode_t && !defined __DEFINED_mode_t)
+typedef unsigned mode_t;
+#define __DEFINED_mode_t
+#endif
+
+#if defined(__NEED_uid_t) && !defined(__DEFINED_uid_t)
+typedef unsigned uid_t;
+#define __DEFINED_uid_t
+#endif
+
+#if defined(__NEED_gid_t) && !defined(__DEFINED_gid_t)
+typedef unsigned gid_t;
+#define __DEFINED_gid_t
+#endif
+
+#if defined(__NEED_useconds_t) && !defined(__DEFINED_useconds_t)
+typedef unsigned useconds_t;
+#define __DEFINED_useconds_t
+#endif
+
+#if defined(__NEED_pid_t) && !defined(__DEFINED_pid_t)
+typedef int pid_t;
+#define __DEFINED_pid_t
+#endif
+
+#if defined(__NEED_id_t) && !defined(__DEFINED_id_t)
+typedef unsigned id_t;
+#define __DEFINED_id_t
+#endif
+
+#if defined(__NEED_dev_t) && !defined(__DEFINED_dev_t)
+typedef __u64 dev_t;
+#define __DEFINED_dev_t
+#endif
+
+#if defined(__NEED_ino_t) && !defined(__DEFINED_ino_t)
+typedef __u64 ino_t;
+#define __DEFINED_ino_t
+#endif
+
+#if defined(__NEED_nlink_t) && !defined(__DEFINED_nlink_t)
+typedef __u32 nlink_t;
+#define __DEFINED_nlink_t
+#endif
+
+#if defined(__NEED_blkcnt_t) && !defined(__DEFINED_blkcnt_t)
+typedef __s64 blkcnt_t;
+#define __DEFINED_blkcnt_t
+#endif
+
+#if defined(__NEED_blksize_t) && !defined(__DEFINED_blksize_t)
+typedef long blksize_t;
+#define __DEFINED_blksize_t
+#endif
+
+#if defined(__NEED_locale_t) && !defined(__DEFINED_locale_t)
+typedef struct __locale_struct *locale_t;
+#define __DEFINED_locale_t
+#endif
+
+#if defined(__NEED_struct_iovec) && !defined(__DEFINED_struct_iovec)
+struct iovec { void *iov_base; size_t iov_len; };
+#define __DEFINED_struct_iovec
+#endif
+
+#if defined(__NEED_fsblkcnt_t) && !defined(__DEFINED_fsblkcnt_t)
+typedef unsigned long long fsblkcnt_t;
+#define __DEFINED_fsblkcnt_t
+#endif
+
+#if defined(__NEED_fsfilcnt_t) && !defined(__DEFINED_fsfilcnt_t)
+typedef unsigned long long fsfilcnt_t;
+#define __DEFINED_fsfilcnt_t
+#endif
diff --git a/lib/isrlibc/include/string.h b/lib/isrlibc/include/string.h
new file mode 100644
index 0000000..84e4acf
--- /dev/null
+++ b/lib/isrlibc/include/string.h
@@ -0,0 +1,53 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Simon Kuenzer <simon.kuenzer@neclab.eu>
+ *
+ *
+ * Copyright (c) 2017, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
+#ifndef __STRING_H__
+#define __STRING_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define __NEED_NULL
+#define __NEED_size_t
+#include <isrlibc-internal/shareddefs.h>
+
+void *memcpy_isr(void *dst, const void *src, size_t len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STRING_H__ */
diff --git a/lib/isrlibc/include/sys/file.h b/lib/isrlibc/include/sys/file.h
new file mode 100644
index 0000000..4fc83b9
--- /dev/null
+++ b/lib/isrlibc/include/sys/file.h
@@ -0,0 +1,21 @@
+#ifndef _SYS_FILE_H
+#define _SYS_FILE_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define LOCK_SH	1
+#define LOCK_EX	2
+#define LOCK_NB	4
+#define LOCK_UN	8
+
+#define L_SET 0
+#define L_INCR 1
+#define L_XTND 2
+
+int flock(int, int);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/lib/isrlibc/include/sys/mount.h b/lib/isrlibc/include/sys/mount.h
new file mode 100644
index 0000000..c8b1fe2
--- /dev/null
+++ b/lib/isrlibc/include/sys/mount.h
@@ -0,0 +1,109 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (C) 2013 Cloudius Systems, Ltd.
+ * Copyright (c) 2019, NEC Europe Ltd., NEC Corporation.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
+#ifndef _SYS_MOUNT_H
+#define _SYS_MOUNT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#define BLKROSET      _IO(0x12,  93)
+#define BLKROGET      _IO(0x12,  94)
+#define BLKRRPART     _IO(0x12,  95)
+#define BLKGETSIZE    _IO(0x12,  96)
+#define BLKFLSBUF     _IO(0x12,  97)
+#define BLKRASET      _IO(0x12,  98)
+#define BLKRAGET      _IO(0x12,  99)
+#define BLKFRASET     _IO(0x12, 100)
+#define BLKFRAGET     _IO(0x12, 101)
+#define BLKSECTSET    _IO(0x12, 102)
+#define BLKSECTGET    _IO(0x12, 103)
+#define BLKSSZGET     _IO(0x12, 104)
+#define BLKBSZGET    _IOR(0x12, 112, size_t)
+#define BLKBSZSET    _IOW(0x12, 113, size_t)
+#define BLKGETSIZE64 _IOR(0x12, 114, size_t)
+
+#define MS_RDONLY      1
+#define MS_NOSUID      2
+#define MS_NODEV       4
+#define MS_NOEXEC      8
+#define MS_SYNCHRONOUS 16
+#define MS_REMOUNT     32
+#define MS_MANDLOCK    64
+#define MS_DIRSYNC     128
+#define MS_NOATIME     1024
+#define MS_NODIRATIME  2048
+#define MS_BIND        4096
+#define MS_MOVE        8192
+#define MS_REC         16384
+#define MS_SILENT      32768
+#define MS_POSIXACL    (1<<16)
+#define MS_UNBINDABLE  (1<<17)
+#define MS_PRIVATE     (1<<18)
+#define MS_SLAVE       (1<<19)
+#define MS_SHARED      (1<<20)
+#define MS_RELATIME    (1<<21)
+#define MS_KERNMOUNT   (1<<22)
+#define MS_I_VERSION   (1<<23)
+#define MS_STRICTATIME (1<<24)
+#define MS_LAZYTIME    (1<<25)
+#define MS_NOREMOTELOCK (1<<27)
+#define MS_NOSEC       (1<<28)
+#define MS_BORN        (1<<29)
+#define MS_ACTIVE      (1<<30)
+#define MS_NOUSER      (1U<<31)
+
+#define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION|MS_LAZYTIME)
+
+#define MS_MGC_VAL 0xc0ed0000
+#define MS_MGC_MSK 0xffff0000
+
+#define MNT_FORCE       0x00000001
+#define MNT_DETACH      0x00000002
+#define MNT_EXPIRE      0x00000004
+#define UMOUNT_NOFOLLOW 0x00000008
+
+int mount(const char *dev, const char *dir, const char *fsname,
+	  unsigned long flags, const void *data);
+int umount(const char *path);
+int umount2(const char *path, int flags);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/isrlibc/include/sys/param.h b/lib/isrlibc/include/sys/param.h
new file mode 100644
index 0000000..f5928d0
--- /dev/null
+++ b/lib/isrlibc/include/sys/param.h
@@ -0,0 +1,38 @@
+#ifndef _SYS_PARAM_H
+#define _SYS_PARAM_H
+
+#define MAXSYMLINKS 20
+#define MAXHOSTNAMELEN 64
+#define MAXNAMLEN 255
+#define MAXPATHLEN 4096
+#define NBBY 8
+#define NGROUPS 32
+#define CANBSIZ 255
+#define NOFILE 256
+#define NCARGS 131072
+#define DEV_BSIZE 512
+#define NOGROUP (-1)
+
+#undef MIN
+#undef MAX
+#define MIN(a, b) (((a) < (b)) ? (a) : (b))
+#define MAX(a, b) (((a) > (b)) ? (a) : (b))
+
+#define __bitop(x, i, o) ((x)[(i) / 8] o(1 << (i) % 8))
+#define setbit(x, i) __bitop(x, i, |=)
+#define clrbit(x, i) __bitop(x, i, &= ~)
+#define isset(x, i) __bitop(x, i, &)
+#define isclr(x, i) !isset(x, i)
+
+#define howmany(n, d) (((n) + ((d) - 1)) / (d))
+#define roundup(n, d) (howmany(n, d) * (d))
+#define powerof2(n) !(((n) - 1) & (n))
+
+/* TODO: This includes are not needed currently. Lets leave them
+ * commented out as a reminder
+ */
+/* #include <sys/resource.h> */
+/* #include <endian.h> */
+#include <limits.h>
+
+#endif
diff --git a/lib/isrlibc/include/sys/select.h b/lib/isrlibc/include/sys/select.h
new file mode 100644
index 0000000..e981b7c
--- /dev/null
+++ b/lib/isrlibc/include/sys/select.h
@@ -0,0 +1,82 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California.  All rights reserved.
+ * Copyright (c) 2017, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/* Derived from FreeBSD commit 4736ccf (Nov 20, 2017) */
+
+#ifndef __SYS_SELECT_H__
+#define __SYS_SELECT_H__
+
+#include <sys/param.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define __NEED_time_t
+#define __NEED_suseconds_t
+#define __NEED_struct_timespec
+#include <nolibc-internal/shareddefs.h>
+
+typedef unsigned long __fd_mask;
+
+/*
+ * Select uses bit masks of file descriptors in longs. These macros
+ * manipulate such bit fields (the filesystem macros use chars).
+ * FD_SETSIZE may be defined by the user, but the default here should
+ * be enough for most uses.
+ */
+#ifndef FD_SETSIZE
+#define FD_SETSIZE 64
+#endif
+
+#define _NFDBITS (sizeof(__fd_mask) * 8) /* bits per mask */
+
+typedef struct fd_set {
+	__fd_mask __fds_bits[howmany(FD_SETSIZE, _NFDBITS)];
+} fd_set;
+
+#define	__fdset_mask(n)	((__fd_mask)1 << ((n) % _NFDBITS))
+#define	FD_CLR(n, p)	((p)->__fds_bits[(n)/_NFDBITS] &= ~__fdset_mask(n))
+#define	FD_ISSET(n, p)	(((p)->__fds_bits[(n)/_NFDBITS] & __fdset_mask(n)) != 0)
+#define	FD_SET(n, p)	((p)->__fds_bits[(n)/_NFDBITS] |= __fdset_mask(n))
+#define	FD_ZERO(p) do {					\
+	fd_set *_p;					\
+	__ssz _n;					\
+							\
+	_p = (p);					\
+	_n = howmany(FD_SETSIZE, _NFDBITS);		\
+	while (_n > 0)					\
+		_p->__fds_bits[--_n] = 0;		\
+} while (0)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SYS_SELECT_H__ */
diff --git a/lib/isrlibc/include/sys/stat.h b/lib/isrlibc/include/sys/stat.h
new file mode 100644
index 0000000..407bc20
--- /dev/null
+++ b/lib/isrlibc/include/sys/stat.h
@@ -0,0 +1,135 @@
+#ifndef	_SYS_STAT_H
+#define	_SYS_STAT_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* #include <features.h> */
+
+#define __NEED_dev_t
+#define __NEED_ino_t
+#define __NEED_mode_t
+#define __NEED_nlink_t
+#define __NEED_uid_t
+#define __NEED_gid_t
+#define __NEED_off_t
+#define __NEED_time_t
+#define __NEED_blksize_t
+#define __NEED_blkcnt_t
+#define __NEED_struct_timespec
+
+#include <nolibc-internal/shareddefs.h>
+
+struct stat {
+	dev_t st_dev;
+	ino_t st_ino;
+	nlink_t st_nlink;
+
+	mode_t st_mode;
+	uid_t st_uid;
+	gid_t st_gid;
+	unsigned int    __pad0;
+	dev_t st_rdev;
+	off_t st_size;
+	blksize_t st_blksize;
+	blkcnt_t st_blocks;
+
+	struct timespec st_atim;
+	struct timespec st_mtim;
+	struct timespec st_ctim;
+};
+
+#define st_atime st_atim.tv_sec
+#define st_mtime st_mtim.tv_sec
+#define st_ctime st_ctim.tv_sec
+
+#define S_IFMT  0170000
+
+#define S_IFDIR 0040000
+#define S_IFCHR 0020000
+#define S_IFBLK 0060000
+#define S_IFREG 0100000
+#define S_IFIFO 0010000
+#define S_IFLNK 0120000
+#define S_IFSOCK 0140000
+
+#define S_TYPEISMQ(buf)  0
+#define S_TYPEISSEM(buf) 0
+#define S_TYPEISSHM(buf) 0
+#define S_TYPEISTMO(buf) 0
+
+#define S_ISDIR(mode)  (((mode) & S_IFMT) == S_IFDIR)
+#define S_ISCHR(mode)  (((mode) & S_IFMT) == S_IFCHR)
+#define S_ISBLK(mode)  (((mode) & S_IFMT) == S_IFBLK)
+#define S_ISREG(mode)  (((mode) & S_IFMT) == S_IFREG)
+#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
+#define S_ISLNK(mode)  (((mode) & S_IFMT) == S_IFLNK)
+#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
+
+#ifndef S_IRUSR
+#define S_ISUID 04000
+#define S_ISGID 02000
+#define S_ISVTX 01000
+#define S_IRUSR 0400
+#define S_IWUSR 0200
+#define S_IXUSR 0100
+#define S_IRWXU 0700
+#define S_IRGRP 0040
+#define S_IWGRP 0020
+#define S_IXGRP 0010
+#define S_IRWXG 0070
+#define S_IROTH 0004
+#define S_IWOTH 0002
+#define S_IXOTH 0001
+#define S_IRWXO 0007
+#endif
+
+#define UTIME_NOW  0x3fffffff
+#define UTIME_OMIT 0x3ffffffe
+
+int stat(const char *__restrict, struct stat *__restrict);
+int fstat(int, struct stat *);
+int lstat(const char *__restrict, struct stat *__restrict);
+int fstatat(int, const char *__restrict, struct stat *__restrict, int);
+int chmod(const char *, mode_t);
+int fchmod(int, mode_t);
+int fchmodat(int, const char *, mode_t, int);
+mode_t umask(mode_t);
+int mkdir(const char *, mode_t);
+int mkfifo(const char *, mode_t);
+int mkdirat(int, const char *, mode_t);
+int mkfifoat(int, const char *, mode_t);
+
+#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+int mknod(const char *, mode_t, dev_t);
+int mknodat(int, const char *, mode_t, dev_t);
+#endif
+
+int futimens(int, const struct timespec [2]);
+int utimensat(int, const char *, const struct timespec [2], int);
+
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+int lchmod(const char *, mode_t);
+#define S_IREAD S_IRUSR
+#define S_IWRITE S_IWUSR
+#define S_IEXEC S_IXUSR
+#endif
+
+#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
+#define stat64 stat
+#define fstat64 fstat
+#define lstat64 lstat
+#define fstatat64 fstatat
+#define blkcnt64_t blkcnt_t
+#define fsblkcnt64_t fsblkcnt_t
+#define fsfilcnt64_t fsfilcnt_t
+#define ino64_t ino_t
+#define off64_t off_t
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+#endif
+
+
diff --git a/lib/isrlibc/include/sys/statfs.h b/lib/isrlibc/include/sys/statfs.h
new file mode 100644
index 0000000..59de629
--- /dev/null
+++ b/lib/isrlibc/include/sys/statfs.h
@@ -0,0 +1,36 @@
+#ifndef	_SYS_STATFS_H
+#define	_SYS_STATFS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <sys/statvfs.h>
+
+typedef struct __fsid_t {
+	int __val[2];
+} fsid_t;
+
+struct statfs {
+	unsigned long f_type, f_bsize;
+	fsblkcnt_t f_blocks, f_bfree, f_bavail;
+	fsfilcnt_t f_files, f_ffree;
+	fsid_t f_fsid;
+	unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
+};
+
+int statfs(const char *path, struct statfs *buf);
+int fstatfs(int fd, struct statfs *buf);
+
+#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
+#define statfs64 statfs
+#define fstatfs64 fstatfs
+#define fsblkcnt64_t fsblkcnt_t
+#define fsfilcnt64_t fsfilcnt_t
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/isrlibc/include/sys/statvfs.h b/lib/isrlibc/include/sys/statvfs.h
new file mode 100644
index 0000000..85a2ff9
--- /dev/null
+++ b/lib/isrlibc/include/sys/statvfs.h
@@ -0,0 +1,54 @@
+#ifndef	_SYS_STATVFS_H
+#define	_SYS_STATVFS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define __NEED_fsblkcnt_t
+#define __NEED_fsfilcnt_t
+#include <nolibc-internal/shareddefs.h>
+
+struct statvfs {
+	unsigned long f_bsize, f_frsize;
+	fsblkcnt_t f_blocks, f_bfree, f_bavail;
+	fsfilcnt_t f_files, f_ffree, f_favail;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+	unsigned long f_fsid;
+	unsigned :8*(2*sizeof(int)-sizeof(long));
+#else
+	unsigned :8*(2*sizeof(int)-sizeof(long));
+	unsigned long f_fsid;
+#endif
+	unsigned long f_flag, f_namemax;
+	int __reserved[6];
+};
+
+int statvfs (const char *__restrict, struct statvfs *__restrict);
+int fstatvfs (int, struct statvfs *);
+
+#define ST_RDONLY 1
+#define ST_NOSUID 2
+#define ST_NODEV  4
+#define ST_NOEXEC 8
+#define ST_SYNCHRONOUS 16
+#define ST_MANDLOCK    64
+#define ST_WRITE       128
+#define ST_APPEND      256
+#define ST_IMMUTABLE   512
+#define ST_NOATIME     1024
+#define ST_NODIRATIME  2048
+#define ST_RELATIME    4096
+
+#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
+#define statvfs64 statvfs
+#define fstatvfs64 fstatvfs
+#define fsblkcnt64_t fsblkcnt_t
+#define fsfilcnt64_t fsfilcnt_t
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/isrlibc/include/sys/types.h b/lib/isrlibc/include/sys/types.h
new file mode 100644
index 0000000..4da777c
--- /dev/null
+++ b/lib/isrlibc/include/sys/types.h
@@ -0,0 +1,69 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Simon Kuenzer <simon.kuenzer@neclab.eu>
+ *
+ *
+ * Copyright (c) 2017, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
+
+#ifndef __SYS_TYPES_H__
+#define __SYS_TYPES_H__
+
+#include <uk/arch/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define __NEED_size_t
+#define __NEED_ssize_t
+#define __NEED_off_t
+#define __NEED_time_t
+#define __NEED_timer_t
+#define __NEED_suseconds_t
+#define __NEED_clock_t
+#define __NEED_clockid_t
+#define __NEED_locale_t
+#define __NEED_mode_t
+#define __NEED_uid_t
+#define __NEED_gid_t
+#define __NEED_pid_t
+#define __NEED_id_t
+#define __NEED_dev_t
+#define __NEED_ino_t
+#define __NEED_nlink_t
+#include <nolibc-internal/shareddefs.h>
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SYS_TYPES_H__ */
diff --git a/lib/isrlibc/include/sys/uio.h b/lib/isrlibc/include/sys/uio.h
new file mode 100644
index 0000000..d1a4b48
--- /dev/null
+++ b/lib/isrlibc/include/sys/uio.h
@@ -0,0 +1,76 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (C) 2013 Cloudius Systems, Ltd.
+ * Copyright (c) 2019, NEC Europe Ltd., NEC Corporation.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
+#ifndef _SYS_UIO_H
+#define _SYS_UIO_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define __NEED_size_t
+#define __NEED_ssize_t
+#define __NEED_struct_iovec
+
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+#define __NEED_off_t
+#endif
+
+#ifdef _GNU_SOURCE
+#define __NEED_pid_t
+#endif
+
+#include <nolibc-internal/shareddefs.h>
+
+#define UIO_MAXIOV 1024
+
+ssize_t readv(int fd, const struct iovec *iov, int iovcnt);
+ssize_t writev(int fd, const struct iovec *iov, int iovcnt);
+
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+ssize_t preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset);
+ssize_t pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset);
+#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
+#define preadv64 preadv
+#define pwritev64 pwritev
+#define off64_t off_t
+#endif
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/isrlibc/string.c b/lib/isrlibc/string.c
new file mode 100644
index 0000000..8425202
--- /dev/null
+++ b/lib/isrlibc/string.c
@@ -0,0 +1,16 @@
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <limits.h>
+#include <errno.h>
+#include <stdio.h>
+
+void *memcpy_isr(void *dst, const void *src, size_t len)
+{
+	size_t p;
+
+	for (p = 0; p < len; ++p)
+		*((__u8 *)(((__uptr)dst) + p)) = *((__u8 *)(((__uptr)src) + p));
+
+	return dst;
+}
\ No newline at end of file
-- 
2.25.1



From minios-devel-bounces@lists.xenproject.org Fri Jul 31 13:09:50 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 31 Jul 2020 13:09:50 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k1UnD-0003kA-NZ; Fri, 31 Jul 2020 13:09:47 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <SRS0=YSF3=BK=gmail.com=razvand@srs-us1.protection.inumbo.net>)
 id 1k1UnC-0003k5-DY
 for minios-devel@lists.xenproject.org; Fri, 31 Jul 2020 13:09:46 +0000
X-Inumbo-ID: 1982d63a-d32f-11ea-8e30-bc764e2007e4
Received: from mail-wm1-x344.google.com (unknown [2a00:1450:4864:20::344])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 1982d63a-d32f-11ea-8e30-bc764e2007e4;
 Fri, 31 Jul 2020 13:09:43 +0000 (UTC)
Received: by mail-wm1-x344.google.com with SMTP id k20so9166067wmi.5
 for <minios-devel@lists.xenproject.org>; Fri, 31 Jul 2020 06:09:43 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=sender:from:to:cc:subject:references:date:in-reply-to:message-id
 :user-agent:mime-version;
 bh=qMKWfzgUy6rKh0tCeNauhENhTk/5U4pJueUEx6ek/V8=;
 b=pSvgJ/Nb/zK8qy4sq9+oVjrhvpKX65CioTBZTtX4WzvhzNMJsVHQ1AfoiY4CmI3Ouc
 Ni2Tfj6d/Lvt7BYizcTnFwpsach+Di6mc2Hh1hX2Xsc6slZOk5WkSU/m6Kwq3hGru8qm
 tIeGR/HI459/JFDzA89vT+vlw8uaZkeZhGBm8IlEXDAS/qyvzMM3Ox6UaFe2xdtDcNcv
 G5YYevC2zS6IK53NB3TXgDtKmOVW/IW2pj01dzbDHi8Ox65Gl9tp0dUyqKoFW1LpOjE5
 Forybz1LfnHvW68pG1X/4qMRlxJPkA6X1pHPd57GrpghFZQLmLqutM1MGY7jLAhN7bZH
 IGXQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:sender:from:to:cc:subject:references:date
 :in-reply-to:message-id:user-agent:mime-version;
 bh=qMKWfzgUy6rKh0tCeNauhENhTk/5U4pJueUEx6ek/V8=;
 b=kElWpQ9AEyrjwcGfa4XXKKLX9nNFb8NLJm5B5ej4Y21u9DWhRwf864HQuXr1nPRp2P
 kosSW/G47JFSMzkbxgiJSqOCsBZEB9ZccjnA6HOUfCRAW7ulLpypgjYMxUirFaYP75uH
 vZPYEWu4GzA8dfoj0CCF5gCq/7ru4Cj1Aiy/se1WSLkR9pXjvNRxUOpPm68gAQ35jvXD
 YLVmjW10FgGWelc5Grp7poV4faCu1HRgHTA2O35hX3KSUpRDrYN2xXOc8sVm82PHndtX
 46D6oWNzv17NiYDasCoWwJJLCAfmSjBTKZF1DKnC8ZCFZqh/AwMetGSosij4r23E+f8z
 3eiQ==
X-Gm-Message-State: AOAM532Phi2Te/gpqHVp1/dPaBPj0Z2oXKjUcAQw+iRZzYl31eT4nXTR
 PHeiijG8mRa4lHEMjior+ws=
X-Google-Smtp-Source: ABdhPJziz270x9PWB/tVQQ/S8kcVPtS13leWyQ+EjDM4JsjWAVOzJuomLi0JjXpTUC0uEX2aXn8udQ==
X-Received: by 2002:a05:600c:2302:: with SMTP id
 2mr3968577wmo.151.1596200982941; 
 Fri, 31 Jul 2020 06:09:42 -0700 (PDT)
Received: from localhost ([141.85.233.147])
 by smtp.gmail.com with ESMTPSA id 62sm13948317wrq.31.2020.07.31.06.09.41
 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256);
 Fri, 31 Jul 2020 06:09:42 -0700 (PDT)
From: Razvan Deaconescu <razvan.deaconescu@cs.pub.ro>
To: Jia He <justin.he@arm.com>
Subject: Re: [UNIKRAFT/NEWLIB PATCH] include/fcntl.h: Replace O_NONBLOCK with
 new one on arm
References: <20200520095603.55457-1-justin.he@arm.com>
 <86blkel8ea.fsf@drone.cs.pub.ro>
Date: Fri, 31 Jul 2020 16:09:41 +0300
In-Reply-To: <86blkel8ea.fsf@drone.cs.pub.ro> (Razvan Deaconescu's message of
 "Fri, 17 Jul 2020 13:53:49 +0300")
Message-ID: <86sgd7suei.fsf@drone.cs.pub.ro>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>, minios-devel@lists.xenproject.org,
 Kaly Xin <Kaly.Xin@arm.com>, Costin Lupu <costin.lupu@cs.pub.ro>,
 Simon Kuenzer <simon.kuenzer@neclab.eu>, Sharan.Santhanam@neclab.eu
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

All good.

Reviewed-by: Razvan Deaconescu <razvan.deaconescu@cs.pub.ro>

Razvan

Razvan Deaconescu <razvan.deaconescu@cs.pub.ro> writes:
> Thanks, Justin.
>
> I tested this, all good. It can be upstreamed.
>
> Razvan
>
> Jia He <justin.he@arm.com> writes:
>> in newlib _default_fcntl.h, it defines O_NONBLOCK as follows:
>> \#define _FNONBLOCK      0x4000  /* non blocking I/O (POSIX style) */
>> But it is different from linux definition(04000=0x800):
>> \#define O_NONBLOCK	00004000
>>
>> This difference confused virtio-9p open() syscall. If you open a
>> file with O_NONBLOCK(is 0x4000 in newlib) and sys_open will regard
>> it as O_DIRECTORY. At last it returns a ENOTDIR error.
>>
>> Signed-off-by: Jia He <justin.he@arm.com>
>> ---
>>  include/fcntl.h | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/include/fcntl.h b/include/fcntl.h
>> index feb4f7c..367c1e6 100644
>> --- a/include/fcntl.h
>> +++ b/include/fcntl.h
>> @@ -15,6 +15,8 @@
>>  #define O_DIRECT     040000
>>  #define O_NOATIME  01000000
>>  #elif ((defined CONFIG_ARCH_ARM_64) || (defined CONFIG_ARCH_ARM_32))
>> +#undef O_NONBLOCK
>> +#define O_NONBLOCK    04000
>>  #define O_NOFOLLOW  0100000
>>  #define O_DIRECTORY  040000
>>  #define O_CLOEXEC  02000000


From minios-devel-bounces@lists.xenproject.org Fri Jul 31 15:48:43 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 31 Jul 2020 15:48:43 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k1XGz-0004KO-Hx; Fri, 31 Jul 2020 15:48:41 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=fp3k=BK=neclab.eu=simon.kuenzer@srs-us1.protection.inumbo.net>)
 id 1k1XGz-0004KJ-6V
 for minios-devel@lists.xen.org; Fri, 31 Jul 2020 15:48:41 +0000
X-Inumbo-ID: 4cfdc7fc-d345-11ea-abde-12813bfff9fa
Received: from mailer2.neclab.eu (unknown [195.37.70.41])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 4cfdc7fc-d345-11ea-abde-12813bfff9fa;
 Fri, 31 Jul 2020 15:48:39 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer2.neclab.eu (Postfix) with ESMTP id 2EBD8F2021;
 Fri, 31 Jul 2020 17:48:38 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-b.office.hd)
Received: from mailer2.neclab.eu ([127.0.0.1])
 by localhost (atlas-b.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id AP5uBRZH1jX9; Fri, 31 Jul 2020 17:48:38 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer2.neclab.eu (Postfix) with ESMTPS id E5C04F200A;
 Fri, 31 Jul 2020 17:48:31 +0200 (CEST)
Received: from [10.7.1.42] (192.168.24.96) by puck.office.hd (192.168.24.91)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Fri, 31 Jul
 2020 17:48:30 +0200
Subject: Re: [UNIKRAFT PATCH] arch: Define the cache line size for each
 architecture
To: Costin Lupu <costin.lupu@cs.pub.ro>, Alexander Jung <a.jung@lancs.ac.uk>, 
 <minios-devel@lists.xen.org>
References: <20200723114747.84030-1-a.jung@lancs.ac.uk>
 <71c8ea3c-ee38-b186-6f53-7773d2a5c53d@cs.pub.ro>
From: Simon Kuenzer <simon.kuenzer@neclab.eu>
Message-ID: <4ee46b74-b805-8240-447b-18df39a1e40a@neclab.eu>
Date: Fri, 31 Jul 2020 17:48:29 +0200
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0)
 Gecko/20100101 Thunderbird/68.11.0
MIME-Version: 1.0
In-Reply-To: <71c8ea3c-ee38-b186-6f53-7773d2a5c53d@cs.pub.ro>
Content-Type: text/plain; charset="utf-8"; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: puck.office.hd (192.168.24.91) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <felipe.huici@neclab.eu>,
 Alexander Jung <alexander.jung@neclab.eu>,
 Sharan Santhanam <sharan.santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hey,

we should be careful with name spacing. A reason why we prefixed low 
definition like this with `__` (e.g., PAGE_SIZE, PAGE_SHIFT) is that 
those low-level headers get included by a lot of lib headers. We may 
easily run into name clashes. I propose to use __CACHELINE_SIZE instead 
for this header.

Thanks,

Simon

On 23.07.20 13:51, Costin Lupu wrote:
> Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>
> 
> On 7/23/20 2:47 PM, Alexander Jung wrote:
>> This definition statically describes the d-cache line size in
>> bytes for {x86_64,arm,arm64}.
>>
>> The d-cache line is a L1 data cache nearest to the processor and
>> the line size refers to the data memory block.
>>
>> The d-line cache size can also be discovered by querying the
>> d-cache build egister at the expense of using more memory and
>> instruction cycles during boot.  Defining this size statically
>> increases performance since it is already known for the
>> respective architecture.
>>
>> Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
>> ---
>>   arch/arm/arm/include/uk/asm/lcpu.h    | 2 ++
>>   arch/arm/arm64/include/uk/asm/lcpu.h  | 2 ++
>>   arch/x86/x86_64/include/uk/asm/lcpu.h | 2 ++
>>   3 files changed, 6 insertions(+)
>>
>> diff --git a/arch/arm/arm/include/uk/asm/lcpu.h b/arch/arm/arm/include/uk/asm/lcpu.h
>> index cdeffc3..33f3a6b 100644
>> --- a/arch/arm/arm/include/uk/asm/lcpu.h
>> +++ b/arch/arm/arm/include/uk/asm/lcpu.h
>> @@ -29,6 +29,8 @@
>>   #error Do not include this header directly
>>   #endif
>>   
>> +#define CACHE_LINE_SIZE	32
>> +
>>   struct __regs {
>>   	unsigned long r0;
>>   	unsigned long r1;
>> diff --git a/arch/arm/arm64/include/uk/asm/lcpu.h b/arch/arm/arm64/include/uk/asm/lcpu.h
>> index 45d1b23..4597e40 100644
>> --- a/arch/arm/arm64/include/uk/asm/lcpu.h
>> +++ b/arch/arm/arm64/include/uk/asm/lcpu.h
>> @@ -30,6 +30,8 @@
>>   #error Do not include this header directly
>>   #endif
>>   
>> +#define CACHE_LINE_SIZE	64
>> +
>>   #ifdef __ASSEMBLY__
>>   /*
>>    * Stack size to save general purpose registers and essential system
>> diff --git a/arch/x86/x86_64/include/uk/asm/lcpu.h b/arch/x86/x86_64/include/uk/asm/lcpu.h
>> index 6a471a1..ff137f8 100644
>> --- a/arch/x86/x86_64/include/uk/asm/lcpu.h
>> +++ b/arch/x86/x86_64/include/uk/asm/lcpu.h
>> @@ -32,6 +32,8 @@
>>   #error Do not include this header directly
>>   #endif
>>   
>> +#define CACHE_LINE_SIZE	64
>> +
>>   #ifndef __ASSEMBLY__
>>   struct __regs {
>>   	unsigned long pad; /* 8 bytes to make struct size multiple of 16 */
>>


From minios-devel-bounces@lists.xenproject.org Fri Jul 31 16:06:53 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 31 Jul 2020 16:06:53 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k1XYY-0006ez-Cm; Fri, 31 Jul 2020 16:06:50 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=fp3k=BK=neclab.eu=simon.kuenzer@srs-us1.protection.inumbo.net>)
 id 1k1XYW-0006eu-PU
 for minios-devel@lists.xen.org; Fri, 31 Jul 2020 16:06:48 +0000
X-Inumbo-ID: d4ee9fe0-d347-11ea-abed-12813bfff9fa
Received: from mailer1.neclab.eu (unknown [195.37.70.40])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id d4ee9fe0-d347-11ea-abed-12813bfff9fa;
 Fri, 31 Jul 2020 16:06:46 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mailer1.neclab.eu (Postfix) with ESMTP id 57A5E104A3E;
 Fri, 31 Jul 2020 18:06:45 +0200 (CEST)
X-Virus-Scanned: Amavisd on Debian GNU/Linux (atlas-a.office.hd)
Received: from mailer1.neclab.eu ([127.0.0.1])
 by localhost (atlas-a.office.hd [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id v7ujBMsfsUlu; Fri, 31 Jul 2020 18:06:45 +0200 (CEST)
X-ENC: Last-Hop-TLS-encrypted
X-ENC: Last-Hop-TLS-encrypted
Received: from puck.office.hd (puck.office.hd [192.168.24.91])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by mailer1.neclab.eu (Postfix) with ESMTPS id 31262103A93;
 Fri, 31 Jul 2020 18:06:45 +0200 (CEST)
Received: from [10.7.1.42] (192.168.24.96) by puck.office.hd (192.168.24.91)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Fri, 31 Jul
 2020 18:06:44 +0200
Subject: Re: [UNIKRAFT PATCH] include: Introduce uk/preemmpt.h
To: Costin Lupu <costin.lupu@cs.pub.ro>, Alexander Jung <a.jung@lancs.ac.uk>, 
 "minios-devel@lists.xen.org" <minios-devel@lists.xen.org>
References: <20200723093847.65020-1-a.jung@lancs.ac.uk>
 <971DEF62-5AC0-4C8C-98EF-037C80D12DEE@neclab.eu>
 <e121e463-0956-96f0-6bf4-932465ae0f02@cs.pub.ro>
From: Simon Kuenzer <simon.kuenzer@neclab.eu>
Message-ID: <7cd460da-d629-e086-d8dc-e8c93f77a54d@neclab.eu>
Date: Fri, 31 Jul 2020 18:06:43 +0200
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0)
 Gecko/20100101 Thunderbird/68.11.0
MIME-Version: 1.0
In-Reply-To: <e121e463-0956-96f0-6bf4-932465ae0f02@cs.pub.ro>
Content-Type: text/plain; charset="utf-8"; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-Originating-IP: [192.168.24.96]
X-ClientProxiedBy: titania.office.hd (192.168.24.89) To puck.office.hd
 (192.168.24.91)
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <Felipe.Huici@neclab.eu>,
 Alexander Jung <Alexander.Jung@neclab.eu>,
 Sharan Santhanam <Sharan.Santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Costin,

fair enough. It makes sense what you say. With this in mind, I propose 
the following improvement for this header:

We distinguish with CONFIG_HAVE_SCHED if we need to do something 
regarding scheduling or not. This option indicates if the platform 
library is compiled with context switch capabilities.

For !CONFIG_HAVE_SCHED:
	We use only memory barriers.

For CONFIG_HAVE_SCHED:
	We do another check for CONFIG_LIBUKSCHED. If uksched is not there, we 
use interrupts on/off + memory barriers. For the case uksched is there, 
I expect that an API call in uksched is provided to do this nesting 
count and disable preemption (this will probably be mapped to a no-op 
for the cooperative scheduler and an actrual function to preemptive 
schedulers). The memory barrier should stay within the preempt.h header.

Of course a brief description should be in the header that says that 
this is not about irqs on/off but disabling thread context migration to 
different CPU cores and thread interruption.

We can put the check for CONFIG_LIBUKSCHED as a TODO for now, because I 
think preempted scheduling needs to be upstreamed first. So I would go 
for irq on/off for now. Later we will implement the uksched case properly.

All-in-all, I see this as a kind of a compromise, but we would cover all 
cases including a good enough support for non-uksched scheduling with 
irqs on/off (which may happen for robotics use cases).

What do you think?

Thanks,

Simon

On 23.07.20 17:59, Costin Lupu wrote:
> On 7/23/20 6:32 PM, Simon Kuenzer wrote:
>> Hey Costin, hey Alexander,
>>
>> a question from my side as clarification. I understand this is kind
>> of an adopted concept from Linux.
> 
> Well, it's actually about critical sections which is an old systems
> concept. [1]
> 
>> However, is it intended that interrupts do not count as preemption?
>> When do I use uk_preempt_disable() and when lcpu_irqf_save()?
> Disabling interrupts does disable preemption. However, here we need to
> disable only preemption in order to keep the current thread running on
> the current CPU. But the advantage here is we can also continue to
> handle interrupts.
> 
> If for example the current thread is the ring consumer and the ring is
> filled in interrupt context then we must leave the interrupts enabled.
> 
>> When scheduling is there, does this general header get a dependency
>> to uksched?
> 
> That's right. More precisely, when preemptive scheduling is there.
> 
>> In such a case, shouldn't this header go to uksched and in ukring we
>> include it as soon as uksched is selected?
> 
> Well, not necessarily. In the ring implementation you just need to
> define critical sections. The ring implementation doesn't care whether
> there is a scheduler around or not. It just needs to make the calls that
> helps it define the critical sections. That's why I don't think it's
> necessary to directly link the ring with the scheduler.
> 
> [1]
> https://en.wikipedia.org/wiki/Critical_section#Kernel-level_critical_sections
> 
> Cheers,
> Costin
> 


From minios-devel-bounces@lists.xenproject.org Fri Jul 31 17:08:49 2020
Return-path: <minios-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 31 Jul 2020 17:08:49 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <minios-devel-bounces@lists.xenproject.org>)
	id 1k1YWT-0003N8-SD; Fri, 31 Jul 2020 17:08:45 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=stDn=BK=cs.pub.ro=costin.lupu@srs-us1.protection.inumbo.net>)
 id 1k1YWS-0003N3-Jr
 for minios-devel@lists.xen.org; Fri, 31 Jul 2020 17:08:44 +0000
X-Inumbo-ID: 7b2254b2-d350-11ea-8e73-bc764e2007e4
Received: from mx.upb.ro (unknown [141.85.13.200])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 7b2254b2-d350-11ea-8e73-bc764e2007e4;
 Fri, 31 Jul 2020 17:08:41 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id 03B72B5617CC;
 Fri, 31 Jul 2020 20:08:40 +0300 (EEST)
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id ooliU8GlxRyC; Fri, 31 Jul 2020 20:08:37 +0300 (EEST)
Received: from localhost (localhost [127.0.0.1])
 by mx.upb.ro (Postfix) with ESMTP id DEB7AB5619E5;
 Fri, 31 Jul 2020 20:08:37 +0300 (EEST)
X-Virus-Scanned: amavisd-new at upb.ro
Received: from mx.upb.ro ([127.0.0.1])
 by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id 3Hue_pd-f4Wc; Fri, 31 Jul 2020 20:08:37 +0300 (EEST)
Received: from [192.168.1.35] (unknown [188.26.180.216])
 by mx.upb.ro (Postfix) with ESMTPSA id C1F35B5617CC;
 Fri, 31 Jul 2020 20:08:36 +0300 (EEST)
Subject: Re: [UNIKRAFT PATCH] include: Introduce uk/preemmpt.h
To: Simon Kuenzer <simon.kuenzer@neclab.eu>,
 Alexander Jung <a.jung@lancs.ac.uk>,
 "minios-devel@lists.xen.org" <minios-devel@lists.xen.org>
References: <20200723093847.65020-1-a.jung@lancs.ac.uk>
 <971DEF62-5AC0-4C8C-98EF-037C80D12DEE@neclab.eu>
 <e121e463-0956-96f0-6bf4-932465ae0f02@cs.pub.ro>
 <7cd460da-d629-e086-d8dc-e8c93f77a54d@neclab.eu>
From: Costin Lupu <costin.lupu@cs.pub.ro>
Message-ID: <7d1cdf4c-c73c-9962-b922-ebc62092353a@cs.pub.ro>
Date: Fri, 31 Jul 2020 20:08:36 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.10.0
MIME-Version: 1.0
In-Reply-To: <7cd460da-d629-e086-d8dc-e8c93f77a54d@neclab.eu>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: quoted-printable
X-BeenThere: minios-devel@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Mini-os development list <minios-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:minios-devel@lists.xenproject.org>
List-Help: <mailto:minios-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/minios-devel>, 
 <mailto:minios-devel-request@lists.xenproject.org?subject=subscribe>
Cc: Felipe Huici <Felipe.Huici@neclab.eu>,
 Alexander Jung <Alexander.Jung@neclab.eu>,
 Sharan Santhanam <Sharan.Santhanam@neclab.eu>
Errors-To: minios-devel-bounces@lists.xenproject.org
Sender: "Minios-devel" <minios-devel-bounces@lists.xenproject.org>

Hi Simon,

Please see inline.

On 7/31/20 7:06 PM, Simon Kuenzer wrote:
> Hi Costin,
>=20
> fair enough. It makes sense what you say. With this in mind, I propose
> the following improvement for this header:
>=20
> We distinguish with CONFIG_HAVE_SCHED if we need to do something
> regarding scheduling or not. This option indicates if the platform
> library is compiled with context switch capabilities.
>=20
> For !CONFIG_HAVE_SCHED:
> =C2=A0=C2=A0=C2=A0=C2=A0We use only memory barriers.
>=20

I would be more specific here and I would use `!CONFIG_HAVE_SCHED_PREEMPT=
`.

> For CONFIG_HAVE_SCHED:
> =C2=A0=C2=A0=C2=A0=C2=A0We do another check for CONFIG_LIBUKSCHED. If u=
ksched is not there,
> we use interrupts on/off + memory barriers.=20

I repeat, we do not disable interrupts here, it has nothing to do with
disabling interrupts. We disable only preemption. As I said in the
previous email, there might be cases (and actually those can be quite
common) where we would encounter deadlocks if we had disabled interrupts.

Therefore it's enough to use the memory barriers, just as it is in the
upstreamed code.

> For the case uksched is there, I expect that an API call in uksched
> is provided to do this nesting count and disable preemption (this
> will probably be mapped to a no-op for the cooperative scheduler and
> an actrual function to preemptive schedulers). The memory barrier
> should stay within the preempt.h header.

If we use `!CONFIG_HAVE_SCHED_PREEMPT` then there is no need to deal
with the uksched + schedcoop case.

>=20
> Of course a brief description should be in the header that says that
> this is not about irqs on/off but disabling thread context migration to
> different CPU cores and thread interruption.
>=20
> We can put the check for CONFIG_LIBUKSCHED as a TODO for now, because I
> think preempted scheduling needs to be upstreamed first. So I would go
> for irq on/off for now. Later we will implement the uksched case proper=
ly.
>=20

Again, we don't deal with IRQs here.

> All-in-all, I see this as a kind of a compromise, but we would cover al=
l
> cases including a good enough support for non-uksched scheduling with
> irqs on/off (which may happen for robotics use cases).

Again, we don't deal with IRQs here.

There is no need to complicate this header now given that we should
(hopefully) upstream the preemptive scheduling patches soon and we will
enhance it then.

Cheers,
Costin




