tools/macros: adjust ROUNDUP() interface to match hypervisor

Adjust user-space callers to use the new interface.  No functional change
intended.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Release-Acked-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
This commit is contained in:
Roger Pau Monne committed 2026-06-05 17:40:21 +02:00
1 parent bf90a4aa5e
commit ce17dc6742
22 files changed
+45 -45

No files matched your search

+1 -1
View File
@@ -1233,7 +1233,7 @@ static int set_fds(int fd, short events)
/* Round up to 2^8 boundary, in practice this just
* make newsize larger than current_array_size.
*/
newsize = ROUNDUP(nr_fds + 1, 8);
newsize = ROUNDUP(nr_fds + 1, 1U << 8);
new_fds = realloc(fds, sizeof(struct pollfd)*newsize);
if (!new_fds)
+1 -3
View File
@@ -68,9 +68,7 @@
})
#endif
#ifndef ROUNDUP
#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
#endif
#define ROUNDUP(x, a) (((x) + (a) - 1) & ~((a) - 1))
#define MASK_EXTR(v, m) (((v) & (m)) / ((m) & -(m)))
#define MASK_INSR(v, m) (((v) * ((m) & -(m))) & (m))
+2 -1
View File
@@ -155,7 +155,8 @@ struct allocation_header {
void *xencall_alloc_buffer(xencall_handle *xcall, size_t size)
{
size_t actual_size = ROUNDUP(size + sizeof(struct allocation_header), PAGE_SHIFT);
size_t actual_size = ROUNDUP(size + sizeof(struct allocation_header),
PAGE_SIZE);
int nr_pages = actual_size >> PAGE_SHIFT;
struct allocation_header *hdr;
+1 -1
View File
@@ -198,7 +198,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
*/
privcmd_mmapbatch_t ioctlx;
xen_pfn_t *pfn;
unsigned int pfn_arr_size = ROUNDUP((num * sizeof(*pfn)), XC_PAGE_SHIFT);
unsigned int pfn_arr_size = ROUNDUP(num * sizeof(*pfn), XC_PAGE_SIZE);
int os_page_size = sysconf(_SC_PAGESIZE);
if ( pfn_arr_size <= os_page_size )
+1 -1
View File
@@ -74,7 +74,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt,
int domids_stride;
unsigned int refs_size = ROUNDUP(count *
sizeof(struct ioctl_gntdev_grant_ref),
XC_PAGE_SHIFT);
XC_PAGE_SIZE);
int os_page_size = getpagesize();
domids_stride = (flags & XENGNTTAB_GRANT_MAP_SINGLE_DOMAIN) ? 0 : 1;
+1 -1
View File
@@ -101,7 +101,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt,
map = alloca(map_size);
else
{
map_size = ROUNDUP(map_size, XC_PAGE_SHIFT);
map_size = ROUNDUP(map_size, XC_PAGE_SIZE);
map = mmap(NULL, map_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON | MAP_POPULATE, -1, 0);
if ( map == MAP_FAILED )
+1 -1
View File
@@ -696,7 +696,7 @@ xc_domain_dumpcore_via_callback(xc_interface *xch,
for ( i = 1; i < sheaders->num; i++ )
sheaders->shdrs[i].sh_offset += fixup;
offset += fixup;
dummy_len = ROUNDUP(offset, PAGE_SHIFT) - offset; /* padding length */
dummy_len = ROUNDUP(offset, PAGE_SIZE) - offset; /* padding length */
offset += dummy_len;
/* pages */
+3 -3
View File
@@ -364,12 +364,12 @@ static int meminit(struct xc_dom_image *dom)
/* Convenient */
const uint64_t kernbase = dom->kernel_seg.vstart;
const uint64_t kernend = ROUNDUP(dom->kernel_seg.vend, 21/*2MB*/);
const uint64_t kernend = ROUNDUP(dom->kernel_seg.vend, MB(2));
const uint64_t kernsize = kernend - kernbase;
const uint64_t dtb_size = dom->devicetree_blob ?
ROUNDUP(dom->devicetree_size, XC_PAGE_SHIFT) : 0;
ROUNDUP(dom->devicetree_size, XC_PAGE_SIZE) : 0;
const uint64_t ramdisk_size = dom->modules[0].blob ?
ROUNDUP(dom->modules[0].size, XC_PAGE_SHIFT) : 0;
ROUNDUP(dom->modules[0].size, XC_PAGE_SIZE) : 0;
const uint64_t modsize = dtb_size + ramdisk_size;
const uint64_t ram128mb = bankbase[0] + (128<<20);
+1 -1
View File
@@ -678,7 +678,7 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom)
{
if ( dom->cmdline )
{
dom->cmdline_size = ROUNDUP(strlen(dom->cmdline) + 1, 3);
dom->cmdline_size = ROUNDUP(strlen(dom->cmdline) + 1, 8);
start_info_size += dom->cmdline_size;
}
}
+2 -2
View File
@@ -135,7 +135,7 @@ typedef uint64_t x86_pgentry_t;
#define PAGE_SIZE_X86 (1UL << PAGE_SHIFT_X86)
#define PAGE_MASK_X86 (~(PAGE_SIZE_X86-1))
#define NRPAGES(x) (ROUNDUP(x, PAGE_SHIFT) >> PAGE_SHIFT)
#define NRPAGES(x) (ROUNDUP(x, PAGE_SIZE) >> PAGE_SHIFT)
static inline xen_pfn_t xc_pfn_to_mfn(xen_pfn_t pfn, xen_pfn_t *p2m,
unsigned gwidth)
@@ -167,7 +167,7 @@ int pin_table(xc_interface *xch, unsigned int type, unsigned long mfn,
*/
#define M2P_SHIFT L2_PAGETABLE_SHIFT_PAE
#define M2P_CHUNK_SIZE (1 << M2P_SHIFT)
#define M2P_SIZE(_m) ROUNDUP(((_m) * sizeof(xen_pfn_t)), M2P_SHIFT)
#define M2P_SIZE(_m) ROUNDUP(((_m) * sizeof(xen_pfn_t)), M2P_CHUNK_SIZE)
#define M2P_CHUNKS(_m) (M2P_SIZE((_m)) >> M2P_SHIFT)
#if defined(__x86_64__) || defined(__i386__)
+3 -3
View File
@@ -56,11 +56,11 @@ const char *rec_type_to_str(uint32_t type)
int write_split_record(struct xc_sr_context *ctx, struct xc_sr_record *rec,
void *buf, size_t sz)
{
static const char zeroes[(1u << REC_ALIGN_ORDER) - 1] = { 0 };
static const char zeroes[REC_ALIGN] = {};
xc_interface *xch = ctx->xch;
typeof(rec->length) combined_length = rec->length + sz;
size_t record_length = ROUNDUP(combined_length, REC_ALIGN_ORDER);
size_t record_length = ROUNDUP(combined_length, REC_ALIGN);
struct iovec parts[] = {
{ &rec->type, sizeof(rec->type) },
{ &combined_length, sizeof(combined_length) },
@@ -110,7 +110,7 @@ int read_record(struct xc_sr_context *ctx, int fd, struct xc_sr_record *rec)
return -1;
}
datasz = ROUNDUP(rhdr.length, REC_ALIGN_ORDER);
datasz = ROUNDUP(rhdr.length, REC_ALIGN);
if ( datasz )
{
+1 -1
View File
@@ -53,7 +53,7 @@ struct xc_sr_rhdr
};
/* All records must be aligned up to an 8 octet boundary */
#define REC_ALIGN_ORDER (3U)
#define REC_ALIGN 8
/* Somewhat arbitrary - 128MB */
#define REC_LENGTH_MAX (128U << 20)
+12 -12
View File
@@ -107,12 +107,12 @@ int libxl__get_acpi_size(libxl__gc *gc,
if (rc < 0)
goto out;
*out = ROUNDUP(size, 3) +
ROUNDUP(sizeof(struct acpi_table_rsdp), 3) +
ROUNDUP(sizeof(struct acpi_table_xsdt), 3) +
ROUNDUP(sizeof(struct acpi_table_gtdt), 3) +
ROUNDUP(sizeof(struct acpi_table_fadt), 3) +
ROUNDUP(sizeof(dsdt_anycpu_arm_len), 3);
*out = ROUNDUP(size, 8) +
ROUNDUP(sizeof(struct acpi_table_rsdp), 8) +
ROUNDUP(sizeof(struct acpi_table_xsdt), 8) +
ROUNDUP(sizeof(struct acpi_table_gtdt), 8) +
ROUNDUP(sizeof(struct acpi_table_fadt), 8) +
ROUNDUP(sizeof(dsdt_anycpu_arm_len), 8);
out:
return rc;
@@ -128,7 +128,7 @@ static int libxl__allocate_acpi_tables(libxl__gc *gc,
acpitables[RSDP].addr = GUEST_ACPI_BASE;
acpitables[RSDP].size = sizeof(struct acpi_table_rsdp);
dom->acpi_modules[0].length += ROUNDUP(acpitables[RSDP].size, 3);
dom->acpi_modules[0].length += ROUNDUP(acpitables[RSDP].size, 8);
acpitables[XSDT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
/*
@@ -137,11 +137,11 @@ static int libxl__allocate_acpi_tables(libxl__gc *gc,
*/
acpitables[XSDT].size = sizeof(struct acpi_table_xsdt) +
sizeof(uint64_t) * 2;
dom->acpi_modules[0].length += ROUNDUP(acpitables[XSDT].size, 3);
dom->acpi_modules[0].length += ROUNDUP(acpitables[XSDT].size, 8);
acpitables[GTDT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
acpitables[GTDT].size = sizeof(struct acpi_table_gtdt);
dom->acpi_modules[0].length += ROUNDUP(acpitables[GTDT].size, 3);
dom->acpi_modules[0].length += ROUNDUP(acpitables[GTDT].size, 8);
acpitables[MADT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
@@ -150,15 +150,15 @@ static int libxl__allocate_acpi_tables(libxl__gc *gc,
goto out;
acpitables[MADT].size = size;
dom->acpi_modules[0].length += ROUNDUP(acpitables[MADT].size, 3);
dom->acpi_modules[0].length += ROUNDUP(acpitables[MADT].size, 8);
acpitables[FADT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
acpitables[FADT].size = sizeof(struct acpi_table_fadt);
dom->acpi_modules[0].length += ROUNDUP(acpitables[FADT].size, 3);
dom->acpi_modules[0].length += ROUNDUP(acpitables[FADT].size, 8);
acpitables[DSDT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
acpitables[DSDT].size = dsdt_anycpu_arm_len;
dom->acpi_modules[0].length += ROUNDUP(acpitables[DSDT].size, 3);
dom->acpi_modules[0].length += ROUNDUP(acpitables[DSDT].size, 8);
assert(dom->acpi_modules[0].length <= GUEST_ACPI_SIZE);
dom->acpi_modules[0].data = libxl__zalloc(gc, dom->acpi_modules[0].length);
+1 -1
View File
@@ -600,7 +600,7 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config,
.opts = 0, /* .opts will be set below */
.nr = b_info->altp2m_count,
},
.vmtrace_size = ROUNDUP(b_info->vmtrace_buf_kb << 10, XC_PAGE_SHIFT),
.vmtrace_size = ROUNDUP(b_info->vmtrace_buf_kb << 10, XC_PAGE_SIZE),
.cpupool_id = info->poolid,
};
+1 -1
View File
@@ -29,7 +29,7 @@ typedef struct libxl__sr_rec_hdr
} libxl__sr_rec_hdr;
/* All records must be aligned up to an 8 octet boundary */
#define REC_ALIGN_ORDER 3U
#define REC_ALIGN 8
#define REC_TYPE_END 0x00000000U
#define REC_TYPE_LIBXC_CONTEXT 0x00000001U
+1 -1
View File
@@ -511,7 +511,7 @@ static void record_header_done(libxl__egc *egc,
return;
}
size_t bytes_to_read = ROUNDUP(rec->hdr.length, REC_ALIGN_ORDER);
size_t bytes_to_read = ROUNDUP(rec->hdr.length, REC_ALIGN);
rec->body = libxl__malloc(NOGC, bytes_to_read);
rc = setup_read(stream, "record body",
+2 -2
View File
@@ -119,7 +119,7 @@ static void setup_generic_write(libxl__egc *egc,
void *body,
sws_record_done_cb cb)
{
static const uint8_t zero_padding[1U << REC_ALIGN_ORDER] = { 0 };
static const uint8_t zero_padding[REC_ALIGN] = {};
libxl__datacopier_state *dc = &stream->dc;
int rc;
@@ -136,7 +136,7 @@ static void setup_generic_write(libxl__egc *egc,
return;
}
size_t padsz = ROUNDUP(hdr->length, REC_ALIGN_ORDER) - hdr->length;
size_t padsz = ROUNDUP(hdr->length, REC_ALIGN) - hdr->length;
uint32_t length = hdr->length;
/* Insert header */
+1 -1
View File
@@ -10,7 +10,7 @@
#include <xen-tools/common-macros.h>
#define M2P_SIZE(_m) ROUNDUP(((_m) * sizeof(xen_pfn_t)), 21)
#define M2P_SIZE(_m) ROUNDUP(((_m) * sizeof(xen_pfn_t)), MB(2))
#define is_mapped(pfn_type) (!((pfn_type) & 0x80000000UL))
#define ERROR(msg, args...) fprintf(stderr, msg, ## args)
+1 -1
View File
@@ -221,7 +221,7 @@ CAMLprim value stub_xc_domain_create(value xch_val, value wanted_domid, value co
if ( altp2m_nr != (uint16_t)altp2m_nr )
caml_invalid_argument("altp2m_count");
vmtrace_size = ROUNDUP(vmtrace_size << 10, XC_PAGE_SHIFT);
vmtrace_size = ROUNDUP(vmtrace_size << 10, XC_PAGE_SIZE);
if ( vmtrace_size != (uint32_t)vmtrace_size )
caml_invalid_argument("vmtrace_buf_kb");
+2 -2
View File
@@ -466,7 +466,7 @@ int set_fd(int fd, short events)
/* Round up to 2^8 boundary, in practice this just
* make newsize larger than current_array_size.
*/
newsize = ROUNDUP(nr_fds + 1, 8);
newsize = ROUNDUP(nr_fds + 1, 1U << 8);
new_fds = realloc(poll_fds, sizeof(struct pollfd)*newsize);
if (!new_fds)
@@ -3067,7 +3067,7 @@ static int dump_state_node(const void *ctx, struct connection *conn,
head.length += node->hdr.num_perms * sizeof(*sn.perms);
head.length += pathlen;
head.length += node->hdr.datalen;
head.length = ROUNDUP(head.length, 3);
head.length = ROUNDUP(head.length, 8);
if (fwrite(&head, sizeof(head), 1, fp) != 1)
return dump_state_node_err(data, "Dump node head error");
+5 -4
View File
@@ -2159,7 +2159,7 @@ const char *dump_state_connections(FILE *fp)
if (ret)
return ret;
head.length += sc.data_in_len + sc.data_out_len;
head.length = ROUNDUP(head.length, 3);
head.length = ROUNDUP(head.length, 8);
if (c->domain) {
sc.fields |= XS_STATE_CONN_FIELDS_UNIQ_ID;
head.length += sizeof(uint64_t);
@@ -2232,7 +2232,8 @@ void read_state_connection(const void *ctx, const void *state)
unsigned long off;
off = sizeof(*sc) + sc->data_in_len + sc->data_out_len;
domain->unique_id = *(uint64_t *)(state + ROUNDUP(off, 3));
domain->unique_id =
*(uint64_t *)(state + ROUNDUP(off, 8));
}
}
@@ -2308,7 +2309,7 @@ static int dump_state_domain(const void *k, void *v, void *arg)
n_quota = get_quota_size(domain->acc, &rec_len);
rec_len += n_quota * sizeof(sd->quota_val[0]);
rec_len += sizeof(*sd);
rec_len = ROUNDUP(rec_len, 3);
rec_len = ROUNDUP(rec_len, 8);
record = talloc_size(NULL, rec_len + sizeof(*head));
if (!record)
@@ -2372,7 +2373,7 @@ const char *dump_state_glb_quota(FILE *fp)
n_quota = get_quota_size(quotas, &rec_len);
rec_len += n_quota * sizeof(glb->quota_val[0]);
rec_len += sizeof(*glb);
rec_len = ROUNDUP(rec_len, 3);
rec_len = ROUNDUP(rec_len, 8);
record = talloc_size(NULL, rec_len + sizeof(*head));
if (!record)
+1 -1
View File
@@ -349,7 +349,7 @@ const char *dump_state_watches(FILE *fp, struct connection *conn,
}
head.length += path_len + token_len;
head.length = ROUNDUP(head.length, 3);
head.length = ROUNDUP(head.length, 8);
if (fwrite(&head, sizeof(head), 1, fp) != 1)
return "Dump watch state error";
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.