Skip to content

Commit

Permalink
Fix 12.2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
allanjude committed Jul 21, 2021
1 parent 23db61a commit bab2f7a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
15 changes: 13 additions & 2 deletions include/x86/_rdtsc_ordered.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#ifndef _X86__RDTSC_ORDERED_H_
#define _X86__RDTSC_ORDERED_H_

#include <sys/param.h>
#include <sys/types.h>
#include <machine/cpufunc.h>
#include <machine/cputypes.h>
Expand Down Expand Up @@ -74,9 +75,14 @@
}

#ifdef _KERNEL
#if __FreeBSD_version >= 1300000
#define KVM_IFUNC DEFINE_IFUNC(, uint64_t, rdtsc_ordered, (void))
#else
#define KVM_IFUNC DEFINE_IFUNC(, uint64_t, rdtsc_ordered, (void), static)
#endif
#define DEFINE_RDTSC_ORDERED() \
DEFINE_RDTSC_ORDERED_COMMON() \
DEFINE_IFUNC(, uint64_t, rdtsc_ordered, (void)) \
KVM_IFUNC \
{ \
bool cpu_is_amd = cpu_vendor_id == CPU_VENDOR_AMD || \
cpu_vendor_id == CPU_VENDOR_HYGON; \
Expand All @@ -85,9 +91,14 @@
cpu_is_amd)); \
}
#else /* !_KERNEL */
#if __FreeBSD_version >= 1300000
#define KVM_UIFUNC DEFINE_UIFUNC(, uint64_t, rdtsc_ordered, (void))
#else
#define KVM_UIFUNC DEFINE_UIFUNC(, uint64_t, rdtsc_ordered, (void), static)
#endif
#define DEFINE_RDTSC_ORDERED() \
DEFINE_RDTSC_ORDERED_COMMON() \
DEFINE_UIFUNC(, uint64_t, rdtsc_ordered, (void)) \
KVM_UIFUNC \
{ \
u_int amd_feature, cpu_exthigh, p[4], v[3]; \
static const char amd_id[] = "AuthenticAMD"; \
Expand Down
33 changes: 33 additions & 0 deletions kvm_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,39 @@ kvm_clock_probe(device_t dev)
return (BUS_PROBE_DEFAULT);
}

#if __FreeBSD_version <= 1202000
static void *
malloc_domainset_aligned(size_t size, size_t align,
struct malloc_type *mtp, struct domainset *ds, int flags)
{
void *res;
size_t asize;

KASSERT(align != 0 && powerof2(align),
("malloc_domainset_aligned: wrong align %#zx size %#zx",
align, size));
KASSERT(align <= PAGE_SIZE,
("malloc_domainset_aligned: align %#zx (size %#zx) too large",
align, size));

/*
* Round the allocation size up to the next power of 2,
* because we can only guarantee alignment for
* power-of-2-sized allocations. Further increase the
* allocation size to align if the rounded size is less than
* align, since malloc zones provide alignment equal to their
* size.
*/
asize = size <= align ? align : 1UL << flsl(size - 1);

res = malloc_domainset(asize, mtp, ds, flags);
KASSERT(res == NULL || ((uintptr_t)res & (align - 1)) == 0,
("malloc_domainset_aligned: result not aligned %p size %#zx "
"allocsize %#zx align %#zx", res, size, asize, align));
return (res);
}
#endif

static int
kvm_clock_attach(device_t dev)
{
Expand Down

0 comments on commit bab2f7a

Please sign in to comment.