diff mbox series

[3/4] um: add mmap/mremap/munmap OS calls

Message ID 20231110195255.711150d60a27.Ic2da1d3a983fe57340c1b693badfa9c5bd2d8c61@changeid
State Needs Review / ACK
Headers show
Series time-travel broadcast and shared memory | expand

Commit Message

Johannes Berg Nov. 10, 2023, 6:52 p.m. UTC
From: Johannes Berg <johannes.berg@intel.com>

For the upcoming shared-memory time-travel external
optimisations, we need to be able to mmap/mremap
(and on error munmap). Add the necessary OS calls.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 arch/um/include/shared/os.h |  3 +++
 arch/um/os-Linux/file.c     | 28 ++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

Comments

Anton Ivanov Nov. 10, 2023, 8:40 p.m. UTC | #1
On 10/11/2023 18:52, Johannes Berg wrote:
> From: Johannes Berg <johannes.berg@intel.com>
> 
> For the upcoming shared-memory time-travel external
> optimisations, we need to be able to mmap/mremap
> (and on error munmap). Add the necessary OS calls.
> 
> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
> ---
>   arch/um/include/shared/os.h |  3 +++
>   arch/um/os-Linux/file.c     | 28 ++++++++++++++++++++++++++++
>   2 files changed, 31 insertions(+)
> 
> diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h
> index 4fbe574eff4c..1a82c6548dd5 100644
> --- a/arch/um/include/shared/os.h
> +++ b/arch/um/include/shared/os.h
> @@ -180,6 +180,9 @@ extern int os_eventfd(unsigned int initval, int flags);
>   extern int os_sendmsg_fds(int fd, const void *buf, unsigned int len,
>   			  const int *fds, unsigned int fds_num);
>   int os_poll(unsigned int n, const int *fds);
> +void *os_mmap_rw_shared(int fd, size_t size);
> +void *os_mremap_rw_shared(void *old_addr, size_t old_size, size_t new_size);
> +void os_munmap(void *addr, size_t size);
>   
>   /* start_up.c */
>   extern void os_early_checks(void);
> diff --git a/arch/um/os-Linux/file.c b/arch/um/os-Linux/file.c
> index c972dfeab9a3..c482850f27d8 100644
> --- a/arch/um/os-Linux/file.c
> +++ b/arch/um/os-Linux/file.c
> @@ -17,6 +17,7 @@
>   #include <sys/stat.h>
>   #include <sys/sysmacros.h>
>   #include <sys/un.h>
> +#include <sys/mman.h>
>   #include <sys/types.h>
>   #include <sys/eventfd.h>
>   #include <poll.h>
> @@ -708,3 +709,30 @@ int os_poll(unsigned int n, const int *fds)
>   
>   	return -EIO;
>   }
> +
> +void *os_mmap_rw_shared(int fd, size_t size)
> +{
> +	void *res = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
> +
> +	if (res == MAP_FAILED)
> +		return NULL;
> +
> +	return res;
> +}
> +
> +void *os_mremap_rw_shared(void *old_addr, size_t old_size, size_t new_size)
> +{
> +	void *res;
> +
> +	res = mremap(old_addr, old_size, new_size, MREMAP_MAYMOVE, NULL);
> +
> +	if (res == MAP_FAILED)
> +		return NULL;
> +
> +	return res;
> +}
> +
> +void os_munmap(void *addr, size_t size)
> +{
> +	munmap(addr, size);
> +}


os_munmap already exists as os_munmap_memory

The other two are OK.
Johannes Berg Nov. 10, 2023, 8:43 p.m. UTC | #2
On Fri, 2023-11-10 at 20:40 +0000, Anton Ivanov wrote:
> os_munmap already exists as os_munmap_memory
> 

Hah, oops. Thanks :)

johannes
diff mbox series

Patch

diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h
index 4fbe574eff4c..1a82c6548dd5 100644
--- a/arch/um/include/shared/os.h
+++ b/arch/um/include/shared/os.h
@@ -180,6 +180,9 @@  extern int os_eventfd(unsigned int initval, int flags);
 extern int os_sendmsg_fds(int fd, const void *buf, unsigned int len,
 			  const int *fds, unsigned int fds_num);
 int os_poll(unsigned int n, const int *fds);
+void *os_mmap_rw_shared(int fd, size_t size);
+void *os_mremap_rw_shared(void *old_addr, size_t old_size, size_t new_size);
+void os_munmap(void *addr, size_t size);
 
 /* start_up.c */
 extern void os_early_checks(void);
diff --git a/arch/um/os-Linux/file.c b/arch/um/os-Linux/file.c
index c972dfeab9a3..c482850f27d8 100644
--- a/arch/um/os-Linux/file.c
+++ b/arch/um/os-Linux/file.c
@@ -17,6 +17,7 @@ 
 #include <sys/stat.h>
 #include <sys/sysmacros.h>
 #include <sys/un.h>
+#include <sys/mman.h>
 #include <sys/types.h>
 #include <sys/eventfd.h>
 #include <poll.h>
@@ -708,3 +709,30 @@  int os_poll(unsigned int n, const int *fds)
 
 	return -EIO;
 }
+
+void *os_mmap_rw_shared(int fd, size_t size)
+{
+	void *res = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+
+	if (res == MAP_FAILED)
+		return NULL;
+
+	return res;
+}
+
+void *os_mremap_rw_shared(void *old_addr, size_t old_size, size_t new_size)
+{
+	void *res;
+
+	res = mremap(old_addr, old_size, new_size, MREMAP_MAYMOVE, NULL);
+
+	if (res == MAP_FAILED)
+		return NULL;
+
+	return res;
+}
+
+void os_munmap(void *addr, size_t size)
+{
+	munmap(addr, size);
+}