Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp209925rdb; Tue, 5 Dec 2023 03:23:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IHCm5op/PlSvG5l3yLw1sw3yXZvbESy9k6ElEs0tBE+d87wgP7q360ZXJGpBDKaTDWE1Wp+ X-Received: by 2002:a17:903:48b:b0:1d0:748d:eaa4 with SMTP id jj11-20020a170903048b00b001d0748deaa4mr2632039plb.91.1701775380633; Tue, 05 Dec 2023 03:23:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701775380; cv=none; d=google.com; s=arc-20160816; b=BDltTe5ZInwk8OVTXJKWT8N5jyNzQE9TghyrmFW3iW94i4LOI+sXD4v5A+UkT+4jdr v/mxFGuvMYkC3JL5pFXSGnXG3CR4EAKgAxPBjtlhvnrusvKQk8x9+GNs5LkP+wRMnFkp Z/Gc9tDu0GKVV8G9aZ3xXUBtwcX9Jc8B2Tr8dq+2CAXdptSllBeweCgOb8Wq4nkk7kyZ wdHoFGir1wT09LpLs0y4F+ZxLn1Oypo2toN/IxUIJC5j0ieRA3OEmpPZ/Iw9zPfHr44J g8CqlszpgvKzWlTkbMeW1oW661vA631d6CzhBY23WLPOLB1ULUWXaNE7RWQG/1Pv1J3j A6wQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OqW0NRTdKv7Lav9cu8hKi4TlEMrmZbuXcKXHxk0Oz94=; fh=uCCWEUVpLc/xDP/D3WvGY/BxHU9d0NQYu/T71GEsNmA=; b=KeYQcyOoWcWS0rXlCwZJaQE7KfYyJCTIymZvZDopDubOOYLlRfDVd2yxYAkmh3f9fl dQVgOJwIRJqVtAPvKD4RERx/eF9Oal0AsFojYxUGs2zW+NHH1PS9Pm7b4CxwUqsQEoKJ CaE6X6BKcCBE4TvB5zmTKjsxElb47dYlHinIcUKec/XI4nn/CViq6pWCFh7UvzIO5rTv FSixNb+p0Cudqa3rRcPDGMErbb/Lp7QFvV4KuYaQ0PXqzMDsBhqx0eHv5fhL0q60t9Zv bjyi3mEhz0SBdhTFrT81xQ64XgizRD32tqBc0rd8erQoWi1NPFfuYAk+Acva/z7xBanK 4WcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cIGefHGm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id u18-20020a170902e81200b001d0b0334bd3si2930675plg.375.2023.12.05.03.23.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 03:23:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cIGefHGm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 0C8EA822779E; Tue, 5 Dec 2023 03:22:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442237AbjLELWD (ORCPT + 99 others); Tue, 5 Dec 2023 06:22:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442081AbjLELVU (ORCPT ); Tue, 5 Dec 2023 06:21:20 -0500 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A43C29A; Tue, 5 Dec 2023 03:21:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701775286; x=1733311286; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3V1Fp4B8bT1xxvwEaEZ/zEmVdVDD76mAnFdI8sJmtEA=; b=cIGefHGmhoAmD+ixKo4+XJgZmvbt3po03DfLJdd7za53JotoOFnIrfpD B/lUlcp6kvNPpHVOn6OQ+YzMZCP3hAez0EpNtmfoO//Jnr8nyh5v3VCRb TI7BU5qRUoTe73U95qdad2fH6q+tJ4QIgqrcBZTauhufuDU8c92r6yaD1 VeOl2mEB6Y9uImIv7hWilBW3wsu51B8gL8HSgjBJUQ/NHauHFM2aXbMul QNX1xApcajMBQx8ZtW4tYBuZ77+ukWRqV1+8CMxVPcAk+LhNH2TXIP+H0 AyzNLa9ARZ+tbiBsZ999AMuzYpmq3eZ/xz868WEvQzdyxQCQ/pkGWt20t g==; X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="942482" X-IronPort-AV: E=Sophos;i="6.04,252,1695711600"; d="scan'208";a="942482" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Dec 2023 03:21:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="1018192942" X-IronPort-AV: E=Sophos;i="6.04,252,1695711600"; d="scan'208";a="1018192942" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga006.fm.intel.com with ESMTP; 05 Dec 2023 03:21:19 -0800 From: Xin Li To: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-edac@vger.kernel.org, linux-hyperv@vger.kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, luto@kernel.org, pbonzini@redhat.com, seanjc@google.com, peterz@infradead.org, jgross@suse.com, ravi.v.shankar@intel.com, mhiramat@kernel.org, andrew.cooper3@citrix.com, jiangshanlai@gmail.com, nik.borisov@suse.com, shan.kang@intel.com Subject: [PATCH v13 13/35] x86/ptrace: Cleanup the definition of the pt_regs structure Date: Tue, 5 Dec 2023 02:50:02 -0800 Message-ID: <20231205105030.8698-14-xin3.li@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231205105030.8698-1-xin3.li@intel.com> References: <20231205105030.8698-1-xin3.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 05 Dec 2023 03:22:48 -0800 (PST) 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 Originally-by: H. Peter Anvin (Intel) Suggested-by: Thomas Gleixner Tested-by: Shan Kang Signed-off-by: Xin Li --- Change since v12: * Put comments ontop, not on the side (Borislav Petkov). --- 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 e0ca8120aea8..a3c0df11d0e6 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 f4db78b09c8f..b268cd2a2d01 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 1553e19904e0..b924477c5ba8 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); -- 2.43.0