cuse(3): Remove PAGE_SIZE from libcuse.

To allow for a dynamic page size on arm64 remove the static value from libcuse.

Differential Revision:	https://reviews.freebsd.org/D35585
MFC after:	1 week
Sponsored by:	NVIDIA Networking
This commit is contained in:
Hans Petter Selasky 2022-06-23 22:34:45 +02:00
parent 6c4b6f55f7
commit 2c28cd09d9
3 changed files with 22 additions and 13 deletions

View File

@ -1,6 +1,6 @@
/* $FreeBSD$ */
/*-
* Copyright (c) 2010-2012 Hans Petter Selasky. All rights reserved.
* Copyright (c) 2010-2022 Hans Petter Selasky. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -142,7 +142,7 @@ cuse_vmoffset(void *_ptr)
uint8_t *ptr_max;
uint8_t *ptr = _ptr;
unsigned long remainder;
int n;
unsigned long n;
CUSE_LOCK();
for (n = 0; n != CUSE_ALLOC_UNIT_MAX; n++) {
@ -158,9 +158,10 @@ cuse_vmoffset(void *_ptr)
remainder = (ptr - ptr_min);
remainder -= remainder % PAGE_SIZE;
remainder -= remainder %
(unsigned long)getpagesize();
return ((n * PAGE_SIZE * CUSE_ALLOC_PAGES_MAX) + remainder);
return ((n * CUSE_ALLOC_BYTES_MAX) + remainder);
}
}
CUSE_UNLOCK();
@ -172,9 +173,10 @@ void *
cuse_vmalloc(int size)
{
struct cuse_alloc_info info;
unsigned long pgsize;
unsigned long n;
void *ptr;
int error;
int n;
if (f_cuse < 0)
return (NULL);
@ -184,7 +186,8 @@ cuse_vmalloc(int size)
if (size < 1)
return (NULL);
info.page_count = howmany(size, PAGE_SIZE);
pgsize = getpagesize();
info.page_count = howmany(size, pgsize);
CUSE_LOCK();
for (n = 0; n != CUSE_ALLOC_UNIT_MAX; n++) {
@ -212,10 +215,9 @@ cuse_vmalloc(int size)
else
break;
}
ptr = mmap(NULL, info.page_count * PAGE_SIZE,
ptr = mmap(NULL, info.page_count * pgsize,
PROT_READ | PROT_WRITE,
MAP_SHARED, f_cuse, CUSE_ALLOC_PAGES_MAX *
PAGE_SIZE * n);
MAP_SHARED, f_cuse, CUSE_ALLOC_BYTES_MAX * n);
if (ptr == MAP_FAILED) {

View File

@ -1,6 +1,6 @@
/* $FreeBSD$ */
/*-
* Copyright (c) 2010-2020 Hans Petter Selasky. All rights reserved.
* Copyright (c) 2010-2022 Hans Petter Selasky. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -64,6 +64,13 @@
#include <fs/cuse/cuse_defs.h>
#include <fs/cuse/cuse_ioctl.h>
#define CUSE_ALLOC_PAGES_MAX \
(CUSE_ALLOC_BYTES_MAX / PAGE_SIZE)
#if (CUSE_ALLOC_PAGES_MAX == 0)
#error "PAGE_SIZE is too big!"
#endif
static int
cuse_modevent(module_t mod, int type, void *data)
{

View File

@ -1,6 +1,6 @@
/* $FreeBSD$ */
/*-
* Copyright (c) 2014 Hans Petter Selasky. All rights reserved.
* Copyright (c) 2014-2022 Hans Petter Selasky. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -30,13 +30,13 @@
#include <sys/ioccom.h>
#include <sys/types.h>
#define CUSE_BUFFER_MAX PAGE_SIZE
#define CUSE_BUFFER_MAX (1 << 12) /* bytes */
#define CUSE_DEVICES_MAX 64 /* units */
#define CUSE_BUF_MIN_PTR 0x10000UL
#define CUSE_BUF_MAX_PTR 0x20000UL
#define CUSE_ALLOC_UNIT_MAX 128 /* units */
/* All memory allocations must be less than the following limit */
#define CUSE_ALLOC_PAGES_MAX (((16UL * 1024UL * 1024UL) + PAGE_SIZE - 1) / PAGE_SIZE)
#define CUSE_ALLOC_BYTES_MAX (1UL << 24) /* bytes */
struct cuse_dev;