Skip to content

Commit

Permalink
soc: apple: rtkit: Do not copy the reg state structure to the stack
Browse files Browse the repository at this point in the history
The register state struct is 848 bytes, which ends up bloating the
apple_rtkit_crashlog_dump_regs stack frame beyond 1024 on some
32-bit platforms, triggering compile warnings.

This doesn't matter for 64BIT/ARM64, but there's also no good reason to
copy the structure to the stack in this case. We can use __packed to
avoid alignment issues, there are no double-read hazards, and this is a
fatal error path so performance does not matter.

Fixes: 22991d8 ("soc: apple: rtkit: Add register dump decoding to crashlog")
Signed-off-by: Asahi Lina <lina@asahilina.net>
Reviewed-by: Eric Curtin <ecurtin@redhat.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
  • Loading branch information
Asahi Lina authored and Arnd Bergmann committed Feb 13, 2023
1 parent 6890717 commit 4ec98e6
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions drivers/soc/apple/rtkit-crashlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct apple_rtkit_crashlog_regs {
u64 unk_X;
u64 esr;
u64 unk_Z;
};
} __packed;
static_assert(sizeof(struct apple_rtkit_crashlog_regs) == 0x350);

static void apple_rtkit_crashlog_dump_str(struct apple_rtkit *rtk, u8 *bfr,
Expand Down Expand Up @@ -126,18 +126,18 @@ static void apple_rtkit_crashlog_dump_mailbox(struct apple_rtkit *rtk, u8 *bfr,
static void apple_rtkit_crashlog_dump_regs(struct apple_rtkit *rtk, u8 *bfr,
size_t size)
{
struct apple_rtkit_crashlog_regs regs;
struct apple_rtkit_crashlog_regs *regs;
const char *el;
int i;

if (size < sizeof(regs)) {
if (size < sizeof(*regs)) {
dev_warn(rtk->dev, "RTKit: Regs section too small: 0x%zx", size);
return;
}

memcpy(&regs, bfr, sizeof(regs));
regs = (struct apple_rtkit_crashlog_regs *)bfr;

switch (regs.psr & PSR_MODE_MASK) {
switch (regs->psr & PSR_MODE_MASK) {
case PSR_MODE_EL0t:
el = "EL0t";
break;
Expand All @@ -160,24 +160,24 @@ static void apple_rtkit_crashlog_dump_regs(struct apple_rtkit *rtk, u8 *bfr,

dev_warn(rtk->dev, "RTKit: Exception dump:");
dev_warn(rtk->dev, " == Exception taken from %s ==", el);
dev_warn(rtk->dev, " PSR = 0x%llx", regs.psr);
dev_warn(rtk->dev, " PC = 0x%llx\n", regs.pc);
dev_warn(rtk->dev, " ESR = 0x%llx\n", regs.esr);
dev_warn(rtk->dev, " FAR = 0x%llx\n", regs.far);
dev_warn(rtk->dev, " SP = 0x%llx\n", regs.sp);
dev_warn(rtk->dev, " PSR = 0x%llx", regs->psr);
dev_warn(rtk->dev, " PC = 0x%llx\n", regs->pc);
dev_warn(rtk->dev, " ESR = 0x%llx\n", regs->esr);
dev_warn(rtk->dev, " FAR = 0x%llx\n", regs->far);
dev_warn(rtk->dev, " SP = 0x%llx\n", regs->sp);
dev_warn(rtk->dev, "\n");

for (i = 0; i < 31; i += 4) {
if (i < 28)
dev_warn(rtk->dev,
" x%02d-x%02d = %016llx %016llx %016llx %016llx\n",
i, i + 3,
regs.regs[i], regs.regs[i + 1],
regs.regs[i + 2], regs.regs[i + 3]);
regs->regs[i], regs->regs[i + 1],
regs->regs[i + 2], regs->regs[i + 3]);
else
dev_warn(rtk->dev,
" x%02d-x%02d = %016llx %016llx %016llx\n", i, i + 3,
regs.regs[i], regs.regs[i + 1], regs.regs[i + 2]);
regs->regs[i], regs->regs[i + 1], regs->regs[i + 2]);
}

dev_warn(rtk->dev, "\n");
Expand Down

0 comments on commit 4ec98e6

Please sign in to comment.