Skip to content

Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.

C

audio DSP, battery, cpufreq: the DSP's lengths are checked, the shutdown cannot hang on them (docs/driver-review/adsp-battery-cpufreq.md)

shimoku5429d38c4226
diff --git a/docs/driver-review/adsp-battery-cpufreq.md b/docs/driver-review/adsp-battery-cpufreq.md
index 3806568..5ac01fc 100644
--- a/docs/driver-review/adsp-battery-cpufreq.md
+++ b/docs/driver-review/adsp-battery-cpufreq.md
@@ -292,3 +292,25 @@ Memory-safety items traced and fine:
- Hardware facts, all NEEDS-HARDWARE: that EPSS has 40 rows, its register layout, and thermal limiting of the top row (I found no software thermal path for the CPUs in these files); RPMh command timing and what clearing a TCS while a request is in flight does; whether `ml_io_map` returns NULL on failure (none of `smem`, `cmd_db`, `dsp_memory`, `ipcc.base` is checked for NULL); cache and WC-mapping coherence of the reserved DSP memory against the kernel's own linear map; TrustZone behaviour on a failed AUTH_AND_RESET (whether a PAS shutdown is needed).
- The loader side of the battery cache (`xnuloader`) and the QEMU build.
- Not built or run; all findings are from reading the code.
+
+## Fix status
+
+- F1: FIXED. adsp.c `glink_pump()`: the message length is worked out in 64 bits (`wide`) and checked against the queue before it is narrowed, so it cannot wrap to 0 and the loop always makes progress; an oversize message sets `glink.broken` as before.
+- F2: FIXED. adsp.c `smem_items()` (both loops): stop at an entry with `padding_data > size` or whose item ends beyond its partition; `glink_find()` and `glink_reset()`: descriptor and both queues must lie inside the SMEM window (64-bit sums).
+- F3: FIXED. adsp.c `apr_input()`: a packet whose size is below its header length is dropped before `payload` is computed.
+- F4: FIXED. adsp.c `qrtr_input()`: the check is now `at > length || header.size > length - at`.
+- F5: SKIPPED. A freshness limit or a "stale means unknown" value needs a policy decision, and the guard (`torch.c`, not one of my files) treats -273 as safe, so only a fail-closed change there would help. The signed overflow in the temperature rounding is fixed under F16.
+- F6: FIXED. adsp.c `mailbox_open()`: `box >= aoss.size || size > aoss.size - box` instead of `box + size > aoss.size`.
+- F7: (a) FIXED: on a file size mismatch the real allocation size is stored before the cleanup (`step_firmware()`); (c) FIXED: `size < 5` is tested before the `memcmp` and the log line prints from a bounded copy; (b) SKIPPED: PLAUSIBLE only, needs a per-file "came from the root" flag and knowledge of what `hakios_image_file()` returns.
+- F8: FIXED. adsp.c `our_item_find()` requires the item to end inside the SMEM window; the F2 fix also bounds the offset.
+- F9: FIXED. adsp.c `rails()` takes and drops `hakios_rsc_lock` only when `!leaving`, as `mailbox_send()` does.
+- F10: SKIPPED. Needs hardware knowledge (whether and where a `dmb ld` is needed on this Normal-NC mapping); report says NEEDS-HARDWARE.
+- F11: PARTLY FIXED. The intent buffers are given back in `link_stop()` and a buffer of another size is freed before it is replaced in `glink_offer()`. SKIPPED: the `step_header` page (when TrustZone is done with it is unknown). `step_image` is not a leak: the image is freed at the next `step_firmware()`.
+- F12: FIXED. adsp.c `apr_input()` publishes `apr_answer.there` with `os_atomic_store(..., release)` and `hakios_adsp_apr()` reads it with `os_atomic_load(..., acquire)`.
+- F13: FIXED. cpufreq.c `hakios_cpufreq_init()`: `membench` has its own variable, so `cpufreq=2` no longer starts the all-core benchmark.
+- F14: SKIPPED. PLAUSIBLE only (the effect on other boards is not shown), and a platform gate would silently turn cpufreq off if the SoC base value differed; the owner should decide.
+- F15: FIXED. cpufreq.c `ddr_look()`: the data read check now counts the header (`sizeof(*db) + ... <= CMD_DB_SIZE`). The dead `header_offset` checks (`ddr_look()`, `cmd_db_address()`) are harmless and left as they are.
+- F16: FIXED in part. The `+50` roundings are done in 64 bits (battery.c `hakios_battery_report()`, battery.cpp `report()` and the log line), and a negative voltage becomes 0 before the unsigned `setVoltage()`. SKIPPED: clamping current, voltage and temperature to plausible ranges (hardware knowledge) and the negative temperature in the unsigned OSNumber (whether powerd reads it as signed is unverified).
+- F17: FIXED. battery.c `hakios_battery_init()` rejects a `battery_shared_pa` whose struct would cross the end of the mapped page.
+- F18: SKIPPED. NEEDS-HARDWARE (effect of a stale IPCC enable bit).
+- S-13: FIXED. Same fix as F3 (adsp.c `apr_input()`): the packet is dropped when `header.size` is below the header length, and the copies are bounded by `min(header.size, length) - header_length`.
diff --git a/drivers/audio/hakios.adsp.c b/drivers/audio/hakios.adsp.c
index 438953e..d98c3b7 100644
--- a/drivers/audio/hakios.adsp.c
+++ b/drivers/audio/hakios.adsp.c
@@ -402,6 +402,14 @@ smem_items(uint32_t partition, uint32_t cacheline, struct smem_item *found, unsi
if (!smem_peek(partition + at, &entry, sizeof(entry)) || entry.canary != SMEM_CANARY || entry.size > header.size) {
break;
}
+ /*
+ * The DSP can write this header: padding larger than the item would make the size below wrap to about 4 GB,
+ * and an item that ends beyond its partition would send the readers out of the shared memory. Stop at it.
+ */
+ if (entry.padding_data > entry.size ||
+ (uint64_t)at + sizeof(entry) + entry.padding_header + entry.size > header.size) {
+ break;
+ }
if (count < max) {
found[count].item = entry.item;
found[count].offset = partition + at + sizeof(entry) + entry.padding_header;
@@ -415,7 +423,9 @@ smem_items(uint32_t partition, uint32_t cacheline, struct smem_item *found, unsi
}
step_back = ((uint32_t)sizeof(entry) + cacheline - 1) & ~(cacheline - 1);
for (at = header.size - step_back; at > header.free_cached && at < header.size;) {
- if (!smem_peek(partition + at, &entry, sizeof(entry)) || entry.canary != SMEM_CANARY || entry.size > at) {
+ /* (padding larger than the item would make the size below wrap to about 4 GB) */
+ if (!smem_peek(partition + at, &entry, sizeof(entry)) || entry.canary != SMEM_CANARY || entry.size > at ||
+ entry.padding_data > entry.size) {
break;
}
if (count < max) {
@@ -683,7 +693,8 @@ mailbox_open(void)
}
box = get(&aoss, "our mailbox", QMP_OUR_BOX);
size = get(&aoss, "our mailbox's size", QMP_OUR_BOX_SIZE);
- if (size < QMP_MESSAGE + 4 || box < 0x3c || box + size > aoss.size || (box & 3)) {
+ /* (box and size come from the always-on processor: "box + size" could wrap in 32 bits and pass, so it is compared as a difference) */
+ if (size < QMP_MESSAGE + 4 || box < 0x3c || box >= aoss.size || size > aoss.size - box || (box & 3)) {
printf("adsp: %u: our mailbox is not where a message fits\n", step);
return false;
}
@@ -897,12 +908,17 @@ rails(uint32_t level)
values[r] = (uint32_t)position;
}
need(&rsc);
- lck_mtx_lock(&hakios_rsc_lock);
+ /* (on a panic's way back to the loader no lock is taken: the other processors are stopped, and one of them may hold this one for good) */
+ if (!leaving) {
+ lck_mtx_lock(&hakios_rsc_lock);
+ }
/* (the boot loader leaves the trigger set after its last request, done: idle is what the status says) */
if (rd(rsc.base + RSC_TCS(RPMH_TCS) + TCS_STATUS) == 0) {
printf("adsp: %u: TCS %u of the sequencer is busy (status %#x, control %#x): the rails are not asked\n", step, RPMH_TCS,
rd(rsc.base + RSC_TCS(RPMH_TCS) + TCS_STATUS), rd(rsc.base + RSC_TCS(RPMH_TCS) + TCS_CONTROL));
- lck_mtx_unlock(&hakios_rsc_lock);
+ if (!leaving) {
+ lck_mtx_unlock(&hakios_rsc_lock);
+ }
return false;
}
printf("adsp: %u: about to ask RPMh, through TCS %u, for lcx.lvl (%#x) = %u and lmx.lvl (%#x) = %u (level %u%s)\n", step,
@@ -935,7 +951,9 @@ rails(uint32_t level)
wr(rsc.base + RSC_IRQ_CLEAR, 1u << RPMH_TCS);
wr(rsc.base + RSC_TCS(RPMH_TCS) + TCS_CONTROL, rd(rsc.base + RSC_TCS(RPMH_TCS) + TCS_CONTROL) & ~(TCS_TRIGGER | TCS_ACTIVE_MODE));
wr(rsc.base + RSC_TCS(RPMH_TCS) + TCS_ENABLED, 0);
- lck_mtx_unlock(&hakios_rsc_lock);
+ if (!leaving) {
+ lck_mtx_unlock(&hakios_rsc_lock);
+ }
return done != 0;
}
@@ -1109,6 +1127,7 @@ step_firmware(void)
const uint8_t *header;
uint64_t size = 0, files = 0;
uint32_t count, hashes = 0, lowest = ~0u, highest = 0;
+ uint8_t first[4] = { 0 };
announce("find the audio DSP's image in the small image or on the root, and check it against its own header");
image_forget();
@@ -1120,9 +1139,12 @@ step_firmware(void)
image.header = header;
image.header_size = size;
count = size >= 52 + 2 * 32 ? header[44] | header[45] << 8 : 0;
- if (memcmp(header, "\177ELF\1", 5) != 0 || count < 3 || count > MAX_SEGMENTS || 52 + 32 * count > size || size > PAGE_SIZE) {
- printf("adsp: %u: fw/adsp.mdt is not such a header (%02x %02x %02x %02x, %u segments, %llu bytes)\n", step, header[0],
- header[1], header[2], header[3], count, size);
+ /* (a file of 1 to 4 bytes is shorter than what is compared and printed: both look only at what is there) */
+ memcpy(first, header, size < sizeof(first) ? size : sizeof(first));
+ if (size < 5 || memcmp(header, "\177ELF\1", 5) != 0 || count < 3 || count > MAX_SEGMENTS || 52 + 32 * count > size ||
+ size > PAGE_SIZE) {
+ printf("adsp: %u: fw/adsp.mdt is not such a header (%02x %02x %02x %02x, %u segments, %llu bytes)\n", step, first[0],
+ first[1], first[2], first[3], count, size);
goto fail;
}
for (uint32_t i = 0; i < count; i++) {
@@ -1155,6 +1177,8 @@ step_firmware(void)
}
if (file_size != segment.file_size) {
printf("adsp: %u: fw/%s has %llu bytes, the header says %u\n", step, name, file_size, segment.file_size);
+ /* (the file is given back with the size it was allocated with, not the header's: kfree_data() needs that) */
+ image.segment[image.segments].file_size = (uint32_t)file_size;
image.segments++; /* (for its file to be given back) */
goto fail;
}
@@ -1254,7 +1278,8 @@ our_item_find(void)
{
uint32_t size = 0, at = smem_item(ITEM_SMP2P_OURS, &size);
- return at != 0 && size >= sizeof(struct smp2p) ? at : 0;
+ /* (step_our_item() writes the whole struct there without a bounds check: it has to lie inside the SMEM window) */
+ return at != 0 && size >= sizeof(struct smp2p) && (uint64_t)at + sizeof(struct smp2p) <= SMEM_SIZE ? at : 0;
}
/* What Linux does when the DSP rings for SMP2P: agree on the features once, and answer a restart. */
@@ -1858,13 +1883,15 @@ glink_find(void)
uint32_t size = 0;
glink.descriptor = smem_item(ITEM_GLINK_DESCRIPTOR, &size);
- if (glink.descriptor == 0 || size != 32) {
+ /* (the descriptor and both queues are read and written without further checks: all three must lie inside the SMEM window) */
+ if (glink.descriptor == 0 || size != 32 || (uint64_t)glink.descriptor + size > SMEM_SIZE) {
return false;
}
glink.ours = smem_item(ITEM_GLINK_OUR_QUEUE, &glink.ours_size);
glink.theirs = smem_item(ITEM_GLINK_THEIR_QUEUE, &glink.theirs_size);
return glink.ours != 0 && glink.theirs != 0 && glink.ours_size >= 1024 && glink.theirs_size >= 1024 &&
- !(glink.ours_size & 7) && !(glink.theirs_size & 7);
+ !(glink.ours_size & 7) && !(glink.theirs_size & 7) &&
+ (uint64_t)glink.ours + glink.ours_size <= SMEM_SIZE && (uint64_t)glink.theirs + glink.theirs_size <= SMEM_SIZE;
}
static void
@@ -1872,7 +1899,8 @@ glink_reset(void)
{
uint32_t size = 0, descriptor = smem_item(ITEM_GLINK_DESCRIPTOR, &size);
- if (descriptor == 0 || size != 32) {
+ /* (and inside the SMEM window: the words below are read and written without a bounds check) */
+ if (descriptor == 0 || size != 32 || (uint64_t)descriptor + size > SMEM_SIZE) {
printf("adsp: %u: GLINK's descriptor (item %u) is not there: nothing to reset\n", step, ITEM_GLINK_DESCRIPTOR);
return;
}
@@ -1980,6 +2008,11 @@ glink_offer(struct glink_channel *channel, uint32_t size)
return false;
}
if (channel->our_intents[i].data == NULL || channel->our_intents[i].size != size) {
+ /* (a buffer of another size from an earlier run is given back first: replacing the pointer would leak it) */
+ if (channel->our_intents[i].data != NULL) {
+ kfree_data(channel->our_intents[i].data, channel->our_intents[i].size);
+ channel->our_intents[i].data = NULL;
+ }
channel->our_intents[i].data = kalloc_data(size, Z_WAITOK | Z_ZERO);
}
if (channel->our_intents[i].data == NULL) {
@@ -2002,30 +2035,36 @@ glink_pump(void)
char name[33];
while (glink.up && !glink.broken) {
- uint32_t waiting = glink_waiting(), length = sizeof(message);
+ uint32_t waiting = glink_waiting(), length;
+ /*
+ * The length is worked out in 64 bits: the DSP writes the fields it comes from, and in 32 bits a value such as
+ * 0xfffffff8 wrapped it to 0, so that the message was never taken out and this loop never ended (with glink_lock held).
+ */
+ uint64_t wide = sizeof(message);
if (waiting < sizeof(message)) {
return;
}
glink_peek(&message, 0, sizeof(message));
if (message.command == GLINK_OPEN) {
- length += message.param2;
+ wide += message.param2;
} else if (message.command == GLINK_INTENT) {
- length += 8 * message.param2;
+ wide += 8ull * message.param2;
} else if (message.command == GLINK_DATA || message.command == GLINK_DATA_MORE) {
if (waiting < 16) {
return;
}
glink_peek(words, 8, 8);
- length = 16 + words[0];
+ wide = 16ull + words[0];
}
- length = (length + 7) & ~7u;
- if (length > glink.theirs_size - 8) {
- printf("adsp: glink: A MESSAGE OF %u BYTES (%s %u %#x): not believed, and nothing more is read\n", length,
+ wide = (wide + 7) & ~7ull;
+ if (wide > glink.theirs_size - 8) {
+ printf("adsp: glink: A MESSAGE OF %llu BYTES (%s %u %#x): not believed, and nothing more is read\n", wide,
glink_name(message.command), message.param1, message.param2);
glink.broken = true;
return;
}
+ length = (uint32_t)wide;
if (waiting < length) {
return;
}
@@ -2397,7 +2436,8 @@ qrtr_input(const uint8_t *data, uint32_t length)
printf("adsp: qrtr: %u bytes that are no datagram (they begin %#x)\n", length, length ? data[0] : 0);
return;
}
- if (header.size == 0 || at + header.size > length) {
+ /* (the datagram's size is the DSP's word: "at + size" could wrap in 32 bits and pass, so it is compared as a difference) */
+ if (header.size == 0 || at > length || header.size > length - at) {
printf("adsp: qrtr: a datagram of %u bytes in a message of %u: dropped\n", header.size, length);
return;
}
@@ -2485,6 +2525,15 @@ apr_input(const uint8_t *data, uint32_t length)
printf("adsp: apr: a header of %u bytes in a packet of %u: dropped\n", header_length, length);
return;
}
+ /*
+ * The packet's own size is the DSP's word: below the header it would make the payload wrap to about 4 GB, and the copies
+ * below would then read 256 bytes from beyond this packet. Such a packet is dropped.
+ */
+ if ((header.size < length ? header.size : length) < header_length) {
+ printf("adsp: apr: a packet of %u bytes with a header of %u: dropped\n", header.size < length ? header.size : length,
+ header_length);
+ return;
+ }
payload = (header.size < length ? header.size : length) - header_length;
apr_in++;
if (header.token != apr_waited_for || apr_waited_for == 0) {
@@ -2516,7 +2565,8 @@ apr_input(const uint8_t *data, uint32_t length)
apr_answer.length = payload;
apr_answer.opcode = header.opcode;
apr_answer.token = header.token;
- apr_answer.there = true;
+ /* (released: the thread that waits must not see "there" before the words and the token above, as with battmgr's answers) */
+ os_atomic_store(&apr_answer.there, true, release);
}
/*
@@ -2572,7 +2622,7 @@ hakios_adsp_apr(uint8_t service, uint16_t port, uint32_t token, uint32_t opcode,
} else {
apr_out++;
for (uint32_t waited = 0; waited < ms && !answered; waited++) {
- if (apr_answer.there && apr_answer.token == token) {
+ if (os_atomic_load(&apr_answer.there, acquire) && apr_answer.token == token) {
answered = true;
if (answer != NULL) {
answer->opcode = apr_answer.opcode;
@@ -2922,6 +2972,18 @@ link_stop(void)
kfree_data(packet, sizeof(*packet) + packet->length);
}
channel->last = NULL;
+ /*
+ * The buffers we offered the DSP are given back too, so that they do not stay allocated for good: only
+ * glink_pump() uses them, under this lock, and it does nothing while glink.up is false.
+ */
+ for (unsigned i = 0; i < sizeof(channel->our_intents) / sizeof(channel->our_intents[0]); i++) {
+ if (channel->our_intents[i].data != NULL) {
+ kfree_data(channel->our_intents[i].data, channel->our_intents[i].size);
+ channel->our_intents[i].data = NULL;
+ }
+ channel->our_intents[i].size = channel->our_intents[i].fill = 0;
+ }
+ channel->our_intent_count = 0;
}
lck_mtx_unlock(&glink_lock);
bzero(qrtr_servers, sizeof(qrtr_servers));
diff --git a/drivers/power/hakios.battery.c b/drivers/power/hakios.battery.c
index 4507b4b..82e44aa 100644
--- a/drivers/power/hakios.battery.c
+++ b/drivers/power/hakios.battery.c
@@ -131,12 +131,14 @@ extern void HakiosBatteryReport(const void *state, unsigned size); /* driver
void
hakios_battery_report(const struct hakios_battery_state *b)
{
- int percent = (b->percent_hundredths + 50) / 100;
+ /* (rounded in 64 bits: the DSP's value near INT32_MAX plus 50 would overflow an int, and a full battery would read 0%) */
+ int percent = (int)(((int64_t)b->percent_hundredths + 50) / 100);
battery_soc_percent = percent < 0 ? 0 : percent > 100 ? 100 : percent;
battery_voltage_mv = b->voltage_uv / 1000;
battery_current_ma = b->current_ua / 1000;
- battery_temperature_c = (b->temperature_hundredths + 50) / 100;
+ /* (in 64 bits for the same reason: an overflow here would make a hot battery read as cold) */
+ battery_temperature_c = (int)(((int64_t)b->temperature_hundredths + 50) / 100);
battery_present = b->present != 0;
battery_charger_present = b->external != 0;
battery_charging = b->status == 1; /* POWER_SUPPLY_STATUS_CHARGING */
@@ -185,6 +187,11 @@ hakios_battery_init(void)
printf("battery: xnuloader did not provide battery_shared_pa\n");
return;
}
+ /* The cache must lie inside the one page that is mapped: an address near its end would be read past the mapping. */
+ if ((shared_pa & (LOADER_PAGE_SIZE - 1)) + sizeof(struct loader_battery) > LOADER_PAGE_SIZE) {
+ printf("battery: battery_shared_pa %#llx: the cache would cross the end of its page\n", shared_pa);
+ return;
+ }
page = ml_io_map((vm_offset_t)(shared_pa & ~(LOADER_PAGE_SIZE - 1)), LOADER_PAGE_SIZE);
shared_battery = (volatile struct loader_battery *)(page + (shared_pa & (LOADER_PAGE_SIZE - 1)));
if (shared_battery->magic != LOADER_BATTERY_MAGIC || shared_battery->version != LOADER_BATTERY_VERSION ||
diff --git a/drivers/power/hakios.battery.cpp b/drivers/power/hakios.battery.cpp
index 4d35f87..88abe5d 100644
--- a/drivers/power/hakios.battery.cpp
+++ b/drivers/power/hakios.battery.cpp
@@ -115,7 +115,8 @@ family_code(int usb_type)
void
HakiosBattery::report(const struct hakios_battery_state * b)
{
- int percent = (b->percent_hundredths + 50) / 100;
+ /* (rounded in 64 bits: the DSP's value near INT32_MAX plus 50 would overflow an int) */
+ int percent = (int) (((int64_t) b->percent_hundredths + 50) / 100);
bool charging = b->external && b->status == 1; /* POWER_SUPPLY_STATUS_CHARGING */
percent = percent < 0 ? 0 : percent > 100 ? 100 : percent;
@@ -127,7 +128,8 @@ HakiosBattery::report(const struct hakios_battery_state * b)
flag("AppleRawExternalConnected", b->external != 0);
setCurrentCapacity((unsigned) percent);
setMaxCapacity(100);
- setVoltage((unsigned) (b->voltage_uv / 1000));
+ /* (a negative voltage from the DSP would become about 4 million mV as an unsigned number: 0 instead) */
+ setVoltage(b->voltage_uv > 0 ? (unsigned) (b->voltage_uv / 1000) : 0);
setAmperage(b->current_ua / 1000);
number("InstantAmperage", b->current_ua / 1000);
number("Temperature", b->temperature_hundredths);
@@ -222,7 +224,8 @@ HakiosBatteryReport(const void * state, unsigned size)
}
made->registerService();
battery = made;
- IOLog("HakiosBattery: the battery's power source is up: %d%%, %s\n", (b->percent_hundredths + 50) / 100,
+ /* (64-bit rounding, as in report(): no signed overflow on a large value from the DSP) */
+ IOLog("HakiosBattery: the battery's power source is up: %d%%, %s\n", (int) (((int64_t) b->percent_hundredths + 50) / 100),
b->external ? (b->status == 1 ? "charging" : "on a charger, not charging") : "not on a charger");
return;
}
diff --git a/drivers/power/hakios.cpufreq.c b/drivers/power/hakios.cpufreq.c
index 4251e34..8b04828 100644
--- a/drivers/power/hakios.cpufreq.c
+++ b/drivers/power/hakios.cpufreq.c
@@ -363,7 +363,9 @@ ddr_look(void)
char name[9] = { 0 };
memcpy(name, entry[i].id, 8);
- if (entry[i].length >= sizeof(aux) && slave->data_offset + entry[i].offset + sizeof(aux) < CMD_DB_SIZE - 0x40) {
+ /* (the data starts after the header, so the header counts: this keeps the read inside the mapped database) */
+ if (entry[i].length >= sizeof(aux) &&
+ sizeof(*db) + slave->data_offset + entry[i].offset + sizeof(aux) <= CMD_DB_SIZE) {
memcpy(&aux, db->data + slave->data_offset + entry[i].offset, sizeof(aux));
}
tell("ddr: BCM %-8s at %#x: unit %u, width %u, vcd %u (aux %u bytes)\n", name, entry[i].address, aux.unit,
@@ -558,7 +560,7 @@ void
hakios_cpufreq_init(void)
{
const ml_topology_info_t *topology = ml_get_topology_info();
- uint32_t enabled = 0, cores[EPSS_DOMAINS] = { 0 }, before, here;
+ uint32_t enabled = 0, membench = 0, cores[EPSS_DOMAINS] = { 0 }, before, here;
load_start();
enabled = 2;
@@ -585,9 +587,11 @@ hakios_cpufreq_init(void)
}
}
printf("cpufreq: on core %u a loop ran at %u, now at %u\n", here, before, loop_speed());
- if (PE_parse_boot_argn("membench", &enabled, sizeof(enabled)) && enabled == 1) {
+ /* membench has its own variable: when the boot-arg is absent, the cpufreq value (2 means on) must not start the benchmark */
+ PE_parse_boot_argn("membench", &membench, sizeof(membench));
+ if (membench == 1) {
memory_bench();
- } else if (enabled == 2) {
+ } else if (membench == 2) {
thread_t thread;
if (kernel_thread_start(bench_all, NULL, &thread) == KERN_SUCCESS) {