[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAMe9rOog8r_qR1PBb-W3G+ma5zUX+YDeR3QnuE-xU3mL_=ywSg@mail.gmail.com>
Date: Tue, 6 Feb 2024 13:10:18 -0800
From: "H.J. Lu" <hjl.tools@...il.com>
To: "H. Peter Anvin" <hpa@...or.com>
Cc: Xin Li <xin@...or.com>, linux-kernel@...r.kernel.org,
tip-bot2 for Xin Li <tip-bot2@...utronix.de>, linux-tip-commits@...r.kernel.org,
Thomas Gleixner <tglx@...utronix.de>, "Borislav Petkov (AMD)" <bp@...en8.de>, Shan Kang <shan.kang@...el.com>,
x86@...nel.org
Subject: Re: [tip: x86/fred] x86/ptrace: Cleanup the definition of the pt_regs structure
On Tue, Feb 6, 2024 at 12:45 PM H. Peter Anvin <hpa@...or.com> wrote:
>
> On February 6, 2024 11:04:13 AM PST, Xin Li <xin@...or.com> wrote:
> >On 2/3/2024 3:52 PM, H. Peter Anvin wrote:
> >> On January 31, 2024 1:14:52 PM PST, tip-bot2 for Xin Li <tip-bot2@...utronix.de> wrote:
> >>> The following commit has been merged into the x86/fred branch of tip:
> >>>
> >>> Commit-ID: ee63291aa8287cb7ded767d340155fe8681fc075
> >>> Gitweb: https://git.kernel.org/tip/ee63291aa8287cb7ded767d340155fe8681fc075
> >>> Author: Xin Li <xin3.li@...el.com>
> >>> AuthorDate: Tue, 05 Dec 2023 02:50:02 -08:00
> >>> Committer: Borislav Petkov (AMD) <bp@...en8.de>
> >>> CommitterDate: Wed, 31 Jan 2024 22:01:13 +01:00
> >>>
> >>> x86/ptrace: Cleanup the definition of the pt_regs structure
> >>>
> >>> struct pt_regs is hard to read because the member or section related
> >>> comments are not aligned with the members.
> >>>
> >>> The 'cs' and 'ss' members of pt_regs are type of 'unsigned long' while
> >>> in reality they are only 16-bit wide. This works so far as the
> >>> remaining space is unused, but FRED will use the remaining bits for
> >>> other purposes.
> >>>
> >>> To prepare for FRED:
> >>>
> >>> - Cleanup the formatting
> >>> - Convert 'cs' and 'ss' to u16 and embed them into an union
> >>> with a u64
> >>> - Fixup the related printk() format strings
> >>>
> >>> Suggested-by: Thomas Gleixner <tglx@...utronix.de>
> >>> Originally-by: H. Peter Anvin (Intel) <hpa@...or.com>
> >>> Signed-off-by: Xin Li <xin3.li@...el.com>
> >>> Signed-off-by: Thomas Gleixner <tglx@...utronix.de>
> >>> Signed-off-by: Borislav Petkov (AMD) <bp@...en8.de>
> >>> Tested-by: Shan Kang <shan.kang@...el.com>
> >>> Link: https://lore.kernel.org/r/20231205105030.8698-14-xin3.li@intel.com
> >
> >[...]
> >
> >>> diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
> >>> index 33b2687..0f78b58 100644
> >>> --- a/arch/x86/kernel/process_64.c
> >>> +++ b/arch/x86/kernel/process_64.c
> >>> @@ -117,7 +117,7 @@ void __show_regs(struct pt_regs *regs, enum show_regs_mode mode,
> >>>
> >>> printk("%sFS: %016lx(%04x) GS:%016lx(%04x) knlGS:%016lx\n",
> >>> log_lvl, fs, fsindex, gs, gsindex, shadowgs);
> >>> - printk("%sCS: %04lx DS: %04x ES: %04x CR0: %016lx\n",
> >>> + printk("%sCS: %04x DS: %04x ES: %04x CR0: %016lx\n",
> >>> log_lvl, regs->cs, ds, es, cr0);
> >>> printk("%sCR2: %016lx CR3: %016lx CR4: %016lx\n",
> >>> log_lvl, cr2, cr3, cr4);
> >>
> >> Incidentally, the comment about callee-saved registers is long since both obsolete and is now outright wrong.
> >>
> >> The next version of gcc (14 I think) will have an attribute to turn off saving registers which we can use for top-level C functions.
__attribute__((no_callee_saved_registers))) has been added to GCC 14.
> >
> >Forgive my ignorance, do we have an official definition for "top-level C functions"?
> >
> >Thanks!
> > Xin
> >
>
> (Adding H.J., who did the gcc implementation of __attribute__((no_callee_saved_registers))).
>
> The top level C functions are the ones whose stack frame are immediately below the exception/syscall frame, i.e. the C function called from the entry assembly code and functions tailcalled from those (unless they set up a stack frame for things like memory structures passed to the called function.)
>
> Note that the implementation should properly handle the case when calling these functions from C (accidentally, or because it is a rare case that can be validly pessimized.)
GCC 14 should handle it properly. If not, please open a GCC bug.
--
H.J.
Powered by blists - more mailing lists