Re: git: cc21f6e53f43 - main - amd64: Make a comment less confusing
Date: Mon, 21 Jul 2025 16:43:06 UTC
On Mon, Jul 21, 2025 at 12:37:23PM -0400, John Baldwin wrote:
> On 7/21/25 10:58, Mark Johnston wrote:
> > The branch main has been updated by markj:
> >
> > URL: https://cgit.FreeBSD.org/src/commit/?id=cc21f6e53f43f0e4c082222460d90ea581f3e2d6
> >
> > commit cc21f6e53f43f0e4c082222460d90ea581f3e2d6
> > Author: Mark Johnston <markj@FreeBSD.org>
> > AuthorDate: 2025-07-21 13:33:31 +0000
> > Commit: Mark Johnston <markj@FreeBSD.org>
> > CommitDate: 2025-07-21 14:57:58 +0000
> >
> > amd64: Make a comment less confusing
> > Also merge two printf()s. No functional change intended.
> > Reviewed by: kib
> > MFC after: 1 week
> > Differential Revision: https://reviews.freebsd.org/D51452
> > ---
> > sys/amd64/amd64/trap.c | 13 ++++++-------
> > 1 file changed, 6 insertions(+), 7 deletions(-)
> >
> > diff --git a/sys/amd64/amd64/trap.c b/sys/amd64/amd64/trap.c
> > index d9a5f7096a6e..f3469ed5e2bc 100644
> > --- a/sys/amd64/amd64/trap.c
> > +++ b/sys/amd64/amd64/trap.c
> > @@ -37,7 +37,6 @@
> > * SUCH DAMAGE.
> > */
> > -#include <sys/cdefs.h>
> > /*
> > * AMD64 Trap and System call handling
> > */
> > @@ -898,9 +897,9 @@ trap_diag(struct trapframe *frame, vm_offset_t eva)
> > printf("\n\nFatal trap %d: %s while in %s mode\n", type,
> > type < nitems(trap_msg) ? trap_msg[type] : UNKNOWN,
> > TRAPF_USERMODE(frame) ? "user" : "kernel");
> > - /* two separate prints in case of a trap on an unmapped page */
> > - printf("cpuid = %d; ", PCPU_GET(cpuid));
> > - printf("apic id = %02x\n", PCPU_GET(apic_id));
> > + /* Print these separately in case pcpu accesses trap. */
> > + printf("cpuid = %d; apic id = %02x\n", PCPU_GET(cpuid),
> > + PCPU_GET(apic_id));
> > if (type == T_PAGEFLT) {
> > printf("fault virtual address = 0x%lx\n", eva);
> > printf("fault code = %s %s %s%s%s, %s\n",
> > @@ -1021,9 +1020,9 @@ dblfault_handler(struct trapframe *frame)
> > frame->tf_cs, frame->tf_ss, frame->tf_ds, frame->tf_es,
> > frame->tf_fs, frame->tf_gs,
> > rdmsr(MSR_FSBASE), rdmsr(MSR_GSBASE), rdmsr(MSR_KGSBASE));
> > - /* two separate prints in case of a trap on an unmapped page */
> > - printf("cpuid = %d; ", PCPU_GET(cpuid));
> > - printf("apic id = %02x\n", PCPU_GET(apic_id));
> > + /* Print these separately in case pcpu accesses trap. */
> > + printf("cpuid = %d; apic id = %02x\n", PCPU_GET(cpuid),
> > + PCPU_GET(apic_id));
> > panic("double fault");
>
> Eh, if any of the accesses fault you don't get any of the printf,
Right, but I believe the comment is referring to the preceding printf,
which doesn't print any PCPU fields. In what situation would
PCPU_GET(apic_id) fault while PCPU_GET(cpuid) succeeds?
(Yes, my commit message here should have been better.)
> so once
> you've merged these, the comment is wrong and should just be removed.
> FWIW, pre-5.0 (maybe pre-4.0?) per-CPU data on i386 used a fixed virtual
> address that was mapped to different backing pages on each CPU instead of
> %gs which is why the comment was probably worded that way originally.
>
> (This meant, btw, that each CPU had its own set of top-level kernel page
> table and that cpu_switch had to munge the kernel-half of the top-level
> page table of a process, which precluded multiple threads in a process.)
>
> --
> John Baldwin
>