Message ID | 170673569232.398.15041548048531772130.tip-bot2@tip-bot2 |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-47139-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp31784dyc; Wed, 31 Jan 2024 13:21:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IF4AaVVw4xLy/Ftcu1CMVCNeKaCBqjPr7xm8yRRetfzTAoq4flhuvXopNKXDI4JD0QStdWB X-Received: by 2002:ac8:7f4f:0:b0:42a:aa02:a05f with SMTP id g15-20020ac87f4f000000b0042aaa02a05fmr3813368qtk.21.1706736095993; Wed, 31 Jan 2024 13:21:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706736095; cv=pass; d=google.com; s=arc-20160816; b=qeScCX6M3/aGp51VuFYMACeutp9AW/AL/RQ9TvaGvnDl7pMT78tBDM4R4vlWqQw+I3 1hesSiEUvGNXwinG+tl6E/XockJWsaXeyXg4FkcKN2UrRgxo1CqcpW8nuxdLSFqA4cYt AtybSU1TM5Ffr3Z6qu/dS/n9rb7VXtMyw3+SUICenyjsKeLGBOdVArrzFVDzoQfrUGat xqtAUYPwGDzICh531q3S6+OMxKgb+j5KHbzRKLaYcehXQBXNAQfCDcOjPvWQSMqqcjyZ e8qIZZ8GzBSGi4aHEruIGu8Gs4qpw11UzS8ew3LDJGLTvs/H3xR6O1hnyDap9Wx2afdL /WCw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=2U/lCZCwL+2FAHIhxbeD9lfDkGem1U769P92nVw7ehY=; fh=lx7Lqm1xtTg1Vp8oGeilUz2qycxX8Dpo+LG8I3ngPcY=; b=e+rUV1SbDhf8+JEAqMvfQuy+Xni6Dr3SB2a5bd4SWhy/xNyHOGU9GV7feKCNL0ze0m oHN05NKjYSHU6gONmH9RAAeQgtO+3QkLVFHQnXfYJT9hhDUJmWQ6Gn8CKXnnhPjsYbVi 95EZ94rCP4ZgXAugT4XkamZnUDMOOjHeyWRnESG8eQn3w12t3FrvFjJqESAcVE5BVuwC lGXWAI7ZwhzUkalN4ENJZsQQLHqk4PjQgpaoS1hnvguOerIdMFo+J/rqSNgXkvHgpito FCXhduub4qzu/y8nK1PdUYrfngFLGeIkCHwBRCjHWJUgmW0Q6Alx0g96xqMuwywxwJk7 5iEQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=w4xwKNWt; dkim=neutral (no key) header.i=@linutronix.de; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-47139-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47139-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=1; AJvYcCUeuqFD/E+dOlJD/k7r+at5gREp+hL9F7lwZFGndcwZeTGP7JCHJv1zxCdZmtsTvdInMzREhpt9f0WyhN3nsG/CjQsdmA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f2-20020a05622a104200b0042bec7f516esi1436412qte.521.2024.01.31.13.21.35 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 13:21:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47139-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=w4xwKNWt; dkim=neutral (no key) header.i=@linutronix.de; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-47139-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47139-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B26941C2336D for <ouuuleilei@gmail.com>; Wed, 31 Jan 2024 21:21:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6000D47F5F; Wed, 31 Jan 2024 21:15:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="w4xwKNWt"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="FwUc9Rxx" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 79A573CF74; Wed, 31 Jan 2024 21:14:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706735697; cv=none; b=FjxPulS0EVtrJeCTE3pdn6uw6gfoBrIuOblxrkw7AOi9yL4lNDQhTnfL1R/DsoRo+ljtu4dtKy+gS2h+/Yd/5gHhADV9SZVtJc5kVTevNymRxM2YzH5z3rT7lX7O96uDjhygq+QbrKDh536rGc1uJRWIH+9EHVJaixHlLNNEdrE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706735697; c=relaxed/simple; bh=VVz8dOebOAgCfSQ+VzBYxFRzibalIQS6UOwLDee9riw=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=tBYytML7nbHTT985hO8gBDUJDAKkpIdBsXhz056POUlyqzTwykpwz51kEganNgndZKoFWic33OSJeKHRMU41rXbBP9nCS/eVBr2NLRh93Wg4J0z1i/jDEaoSHLLU1en+KiEQbZTP44BLiqKijELhYLQ5t90bbfQQ+3BMUQnh31s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=w4xwKNWt; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=FwUc9Rxx; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Wed, 31 Jan 2024 21:14:52 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706735693; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2U/lCZCwL+2FAHIhxbeD9lfDkGem1U769P92nVw7ehY=; b=w4xwKNWt7tlZKX8/hYbGIvRBII67ZWJBioeQGUnS82p2KDgh9u0QmdVtyyk3lpQOsQPsvx UXaUYdyVx0zTSkZSRpqYo9ss65OJLzbYVzlssnjtGoY4CtQih1IOkmeD72neb0GqTpqmgZ Sr8GPfwKfMmdFWBqIM3BaUQCgQe6DHEhZj+bn1/Fw+tP7TOg1xB+QOJAfV5SgGXORkr2jE boBOPG+kUm084vndl/kn3lOC2Z2uZ0yEamQOR7ELEIYRhQIszRoHcYdosKQ8wwt+tp8Xxe dWTROPgtpPkTESVoS7WkRSFEeM4j8dwqosit1SlnIEd6u+rY3a5rPTBN6IkWbA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706735693; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2U/lCZCwL+2FAHIhxbeD9lfDkGem1U769P92nVw7ehY=; b=FwUc9RxxuyuKUB+DwCuxwZz9Cr/ousI7z/BLdNf2BreUqsh7BdEnkk7TntuNUzGP8N/DPf kr04TqT1Ek6qYRCQ== From: "tip-bot2 for Xin Li" <tip-bot2@linutronix.de> Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/fred] x86/ptrace: Cleanup the definition of the pt_regs structure Cc: Thomas Gleixner <tglx@linutronix.de>, "H. Peter Anvin (Intel)" <hpa@zytor.com>, Xin Li <xin3.li@intel.com>, "Borislav Petkov (AMD)" <bp@alien8.de>, Shan Kang <shan.kang@intel.com>, x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231205105030.8698-14-xin3.li@intel.com> References: <20231205105030.8698-14-xin3.li@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Message-ID: <170673569232.398.15041548048531772130.tip-bot2@tip-bot2> Robot-ID: <tip-bot2@linutronix.de> Robot-Unsubscribe: Contact <mailto:tglx@linutronix.de> to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784440799157210400 X-GMAIL-MSGID: 1789642508517346836 |
Series |
[tip:,x86/fred] x86/ptrace: Cleanup the definition of the pt_regs structure
|
|
Commit Message
tip-bot2 for Thomas Gleixner
Jan. 31, 2024, 9:14 p.m. UTC
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@intel.com> AuthorDate: Tue, 05 Dec 2023 02:50:02 -08:00 Committer: Borislav Petkov (AMD) <bp@alien8.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@linutronix.de> Originally-by: H. Peter Anvin (Intel) <hpa@zytor.com> Signed-off-by: Xin Li <xin3.li@intel.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Tested-by: Shan Kang <shan.kang@intel.com> Link: https://lore.kernel.org/r/20231205105030.8698-14-xin3.li@intel.com --- arch/x86/entry/vsyscall/vsyscall_64.c | 2 +- arch/x86/include/asm/ptrace.h | 48 ++++++++++++++++++-------- arch/x86/kernel/process_64.c | 2 +- 3 files changed, 37 insertions(+), 15 deletions(-)
Comments
On January 31, 2024 1:14:52 PM PST, tip-bot2 for Xin Li <tip-bot2@linutronix.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@intel.com> >AuthorDate: Tue, 05 Dec 2023 02:50:02 -08:00 >Committer: Borislav Petkov (AMD) <bp@alien8.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@linutronix.de> >Originally-by: H. Peter Anvin (Intel) <hpa@zytor.com> >Signed-off-by: Xin Li <xin3.li@intel.com> >Signed-off-by: Thomas Gleixner <tglx@linutronix.de> >Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> >Tested-by: Shan Kang <shan.kang@intel.com> >Link: https://lore.kernel.org/r/20231205105030.8698-14-xin3.li@intel.com >--- > arch/x86/entry/vsyscall/vsyscall_64.c | 2 +- > arch/x86/include/asm/ptrace.h | 48 ++++++++++++++++++-------- > arch/x86/kernel/process_64.c | 2 +- > 3 files changed, 37 insertions(+), 15 deletions(-) > >diff --git a/arch/x86/entry/vsyscall/vsyscall_64.c b/arch/x86/entry/vsyscall/vsyscall_64.c >index e0ca812..a3c0df1 100644 >--- a/arch/x86/entry/vsyscall/vsyscall_64.c >+++ b/arch/x86/entry/vsyscall/vsyscall_64.c >@@ -76,7 +76,7 @@ static void warn_bad_vsyscall(const char *level, struct pt_regs *regs, > if (!show_unhandled_signals) > return; > >- printk_ratelimited("%s%s[%d] %s ip:%lx cs:%lx sp:%lx ax:%lx si:%lx di:%lx\n", >+ printk_ratelimited("%s%s[%d] %s ip:%lx cs:%x sp:%lx ax:%lx si:%lx di:%lx\n", > level, current->comm, task_pid_nr(current), > message, regs->ip, regs->cs, > regs->sp, regs->ax, regs->si, regs->di); >diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h >index f4db78b..b268cd2 100644 >--- a/arch/x86/include/asm/ptrace.h >+++ b/arch/x86/include/asm/ptrace.h >@@ -57,17 +57,19 @@ struct pt_regs { > #else /* __i386__ */ > > struct pt_regs { >-/* >- * C ABI says these regs are callee-preserved. They aren't saved on kernel entry >- * unless syscall needs a complete, fully filled "struct pt_regs". >- */ >+ /* >+ * C ABI says these regs are callee-preserved. They aren't saved on >+ * kernel entry unless syscall needs a complete, fully filled >+ * "struct pt_regs". >+ */ > unsigned long r15; > unsigned long r14; > unsigned long r13; > unsigned long r12; > unsigned long bp; > unsigned long bx; >-/* These regs are callee-clobbered. Always saved on kernel entry. */ >+ >+ /* These regs are callee-clobbered. Always saved on kernel entry. */ > unsigned long r11; > unsigned long r10; > unsigned long r9; >@@ -77,18 +79,38 @@ struct pt_regs { > unsigned long dx; > unsigned long si; > unsigned long di; >-/* >- * On syscall entry, this is syscall#. On CPU exception, this is error code. >- * On hw interrupt, it's IRQ number: >- */ >+ >+ /* >+ * orig_ax is used on entry for: >+ * - the syscall number (syscall, sysenter, int80) >+ * - error_code stored by the CPU on traps and exceptions >+ * - the interrupt number for device interrupts >+ */ > unsigned long orig_ax; >-/* Return frame for iretq */ >+ >+ /* The IRETQ return frame starts here */ > unsigned long ip; >- unsigned long cs; >+ >+ union { >+ /* The full 64-bit data slot containing CS */ >+ u64 csx; >+ /* CS selector */ >+ u16 cs; >+ }; >+ > unsigned long flags; > unsigned long sp; >- unsigned long ss; >-/* top of stack page */ >+ >+ union { >+ /* The full 64-bit data slot containing SS */ >+ u64 ssx; >+ /* SS selector */ >+ u16 ss; >+ }; >+ >+ /* >+ * Top of stack on IDT systems. >+ */ > }; > > #endif /* !__i386__ */ >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.
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@linutronix.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@intel.com> >> AuthorDate: Tue, 05 Dec 2023 02:50:02 -08:00 >> Committer: Borislav Petkov (AMD) <bp@alien8.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@linutronix.de> >> Originally-by: H. Peter Anvin (Intel) <hpa@zytor.com> >> Signed-off-by: Xin Li <xin3.li@intel.com> >> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> >> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> >> Tested-by: Shan Kang <shan.kang@intel.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. > Forgive my ignorance, do we have an official definition for "top-level C functions"? Thanks! Xin
On February 6, 2024 11:04:13 AM PST, Xin Li <xin@zytor.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@linutronix.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@intel.com> >>> AuthorDate: Tue, 05 Dec 2023 02:50:02 -08:00 >>> Committer: Borislav Petkov (AMD) <bp@alien8.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@linutronix.de> >>> Originally-by: H. Peter Anvin (Intel) <hpa@zytor.com> >>> Signed-off-by: Xin Li <xin3.li@intel.com> >>> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> >>> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> >>> Tested-by: Shan Kang <shan.kang@intel.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. >> > >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.)
On Tue, Feb 6, 2024 at 12:45 PM H. Peter Anvin <hpa@zytor.com> wrote: > > On February 6, 2024 11:04:13 AM PST, Xin Li <xin@zytor.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@linutronix.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@intel.com> > >>> AuthorDate: Tue, 05 Dec 2023 02:50:02 -08:00 > >>> Committer: Borislav Petkov (AMD) <bp@alien8.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@linutronix.de> > >>> Originally-by: H. Peter Anvin (Intel) <hpa@zytor.com> > >>> Signed-off-by: Xin Li <xin3.li@intel.com> > >>> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> > >>> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> > >>> Tested-by: Shan Kang <shan.kang@intel.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.
diff --git a/arch/x86/entry/vsyscall/vsyscall_64.c b/arch/x86/entry/vsyscall/vsyscall_64.c index e0ca812..a3c0df1 100644 --- a/arch/x86/entry/vsyscall/vsyscall_64.c +++ b/arch/x86/entry/vsyscall/vsyscall_64.c @@ -76,7 +76,7 @@ static void warn_bad_vsyscall(const char *level, struct pt_regs *regs, if (!show_unhandled_signals) return; - printk_ratelimited("%s%s[%d] %s ip:%lx cs:%lx sp:%lx ax:%lx si:%lx di:%lx\n", + printk_ratelimited("%s%s[%d] %s ip:%lx cs:%x sp:%lx ax:%lx si:%lx di:%lx\n", level, current->comm, task_pid_nr(current), message, regs->ip, regs->cs, regs->sp, regs->ax, regs->si, regs->di); diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h index f4db78b..b268cd2 100644 --- a/arch/x86/include/asm/ptrace.h +++ b/arch/x86/include/asm/ptrace.h @@ -57,17 +57,19 @@ struct pt_regs { #else /* __i386__ */ struct pt_regs { -/* - * C ABI says these regs are callee-preserved. They aren't saved on kernel entry - * unless syscall needs a complete, fully filled "struct pt_regs". - */ + /* + * C ABI says these regs are callee-preserved. They aren't saved on + * kernel entry unless syscall needs a complete, fully filled + * "struct pt_regs". + */ unsigned long r15; unsigned long r14; unsigned long r13; unsigned long r12; unsigned long bp; unsigned long bx; -/* These regs are callee-clobbered. Always saved on kernel entry. */ + + /* These regs are callee-clobbered. Always saved on kernel entry. */ unsigned long r11; unsigned long r10; unsigned long r9; @@ -77,18 +79,38 @@ struct pt_regs { unsigned long dx; unsigned long si; unsigned long di; -/* - * On syscall entry, this is syscall#. On CPU exception, this is error code. - * On hw interrupt, it's IRQ number: - */ + + /* + * orig_ax is used on entry for: + * - the syscall number (syscall, sysenter, int80) + * - error_code stored by the CPU on traps and exceptions + * - the interrupt number for device interrupts + */ unsigned long orig_ax; -/* Return frame for iretq */ + + /* The IRETQ return frame starts here */ unsigned long ip; - unsigned long cs; + + union { + /* The full 64-bit data slot containing CS */ + u64 csx; + /* CS selector */ + u16 cs; + }; + unsigned long flags; unsigned long sp; - unsigned long ss; -/* top of stack page */ + + union { + /* The full 64-bit data slot containing SS */ + u64 ssx; + /* SS selector */ + u16 ss; + }; + + /* + * Top of stack on IDT systems. + */ }; #endif /* !__i386__ */ 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);