From patchwork Thu Mar 2 05:24:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 63221 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp4063444wrd; Wed, 1 Mar 2023 21:53:07 -0800 (PST) X-Google-Smtp-Source: AK7set9Y3UcZHLza8fiLAKpVbxGZTleS9QJ7aid+MzGLUm2jX8DJh2vi/XhRJmF+xOQGwWGMcw84 X-Received: by 2002:aa7:d712:0:b0:4bd:d822:71 with SMTP id t18-20020aa7d712000000b004bdd8220071mr2743821edq.9.1677736387300; Wed, 01 Mar 2023 21:53:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677736387; cv=none; d=google.com; s=arc-20160816; b=NT2hgBsqn1jGQctYb2I752aZiUD+HlvwXLy61zCBS9/RcTzXGROY6YHpk5ejcXn2v5 ssCu4a77f9HRPbcKBn8o98BPT37MSc8FMUmME8HGiNHH7GQ0OJWjb4Teqecq6RdPjqYW RYGbX2LPUA2V96eeXrrqkxC0ZD2MibN8teB/1qh7MhZHjJGYs2dRYzgB044kD4nP1uNS sGhy5MsatctwhZjx1M7KXvMBCaK+b+v1EPgD9Ld2a7TNSdZD6DQQGzUIrP85V7w2Mumb w+1pMdSgv3AmYi1CWEgb1DpV1kljpA3mtFFFFFwL3KlIgWebIMNUbXYQzZRcFPRgdL1k 49ZQ== 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=FmLWc74cBQAtyaKd+oPKv8/i1ka1LREJLyMbbja5omw=; b=QwQUt0O1IvThYZMBRzIvf2I6Zqm1aRxx7+0jpAilX4Vpc4zY2cEmM8diOZ7ud5FevZ x66Eb1VNvw267SM+JQ78b44Gwa0iU/XBRG7EB3pmPkHtCBg/j7P1jEgrC+JrB7gLZhlt pPqJIfD/19GRT6e4UOp67qPCdjXhWaqF2Rth/jgaPsdGBwVBmtM8J8nIdWgUCGIw+IuL V0V18TPOTE0FmlcjGFIoap09uM6N4FWmWSl2jM2VRUZgBzMjiyIBNvUHBYESKwFWoCDV Aw0Y/eyovUuVKn6EXYBSzt3fA17EtMu34v75Kel3h/RURN2Lldme21gwnjDDanK6+Iry 65sQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bbo9k+K4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s14-20020a170906168e00b008b1814ec83fsi7548743ejd.176.2023.03.01.21.52.44; Wed, 01 Mar 2023 21:53:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bbo9k+K4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229937AbjCBFvV (ORCPT + 99 others); Thu, 2 Mar 2023 00:51:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229799AbjCBFu4 (ORCPT ); Thu, 2 Mar 2023 00:50:56 -0500 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 476194C6E1; Wed, 1 Mar 2023 21:50:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677736254; x=1709272254; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bMX4XCzIvBalTCdycaBebYL7w+KbpVnH8+oaUrz4fJQ=; b=bbo9k+K4SsranXdcP4Nwn0PsiTVv4AWuFiQwiUdeXS9vtWpK7OEYi9a3 JbRJ8cx2l/hK6ENT9ccbQe+s2dtyIKqxl3jzua9iWpPNBNfaEUjsSbj0+ +LP+f7aWJDFiZDxBPYBZYGJ37D+ngYlge2kIRx0icmWgPd0HDkeEuqSJw WrSw+Ruj6WyY8OwD9tFgGLzeMxMNeosM0gmCzOhfR9yy2MCPUTGWTrIFd 1vvCYepC8JtUqa70oBo44jDRX5LKZmYo1nY/z/GIat6g1hvg55tN3oE8r FdPq8zld1p/tIBcBdRNXKUvEKYJYX1Nk5x4sVgURyruKsjSVRHohExczg A==; X-IronPort-AV: E=McAfee;i="6500,9779,10636"; a="420887114" X-IronPort-AV: E=Sophos;i="5.98,226,1673942400"; d="scan'208";a="420887114" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2023 21:50:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10636"; a="920530918" X-IronPort-AV: E=Sophos;i="5.98,226,1673942400"; d="scan'208";a="920530918" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga006.fm.intel.com with ESMTP; 01 Mar 2023 21:50:48 -0800 From: Xin Li To: linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, peterz@infradead.org, andrew.cooper3@citrix.com, seanjc@google.com, pbonzini@redhat.com, ravi.v.shankar@intel.com Subject: [PATCH v4 15/34] x86/fred: make unions for the cs and ss fields in struct pt_regs Date: Wed, 1 Mar 2023 21:24:52 -0800 Message-Id: <20230302052511.1918-16-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230302052511.1918-1-xin3.li@intel.com> References: <20230302052511.1918-1-xin3.li@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759234110147128302?= X-GMAIL-MSGID: =?utf-8?q?1759234110147128302?= From: "H. Peter Anvin (Intel)" Make the cs and ss fields in struct pt_regs unions between the actual selector and the unsigned long stack slot. FRED uses this space to store additional flags. The printk changes are simply due to the cs and ss fields changed to unsigned short from unsigned long. Signed-off-by: H. Peter Anvin (Intel) Tested-by: Shan Kang Signed-off-by: Xin Li --- Changes since v3: * Rename csl/ssl of the pt_regs structure to csx/ssx (x for extended) (Andrew Cooper). --- arch/x86/entry/vsyscall/vsyscall_64.c | 2 +- arch/x86/include/asm/ptrace.h | 36 ++++++++++++++++++++++++--- arch/x86/kernel/process_64.c | 2 +- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/arch/x86/entry/vsyscall/vsyscall_64.c b/arch/x86/entry/vsyscall/vsyscall_64.c index d234ca797e4a..2429ad0df068 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..a61d860dc33c 100644 --- a/arch/x86/include/asm/ptrace.h +++ b/arch/x86/include/asm/ptrace.h @@ -82,13 +82,41 @@ struct pt_regs { * On hw interrupt, it's IRQ number: */ unsigned long orig_ax; -/* Return frame for iretq */ + + /* Return frame for iretq/eretu/erets */ unsigned long ip; - unsigned long cs; + union { + unsigned long csx; /* cs extended: CS + any fields above it */ + struct __attribute__((__packed__)) { + unsigned short cs; /* CS selector proper */ + unsigned int current_stack_level: 2; + unsigned int __csx_resv1 : 6; + unsigned int interrupt_shadowed : 1; + unsigned int software_initiated : 1; + unsigned int __csx_resv2 : 2; + unsigned int nmi : 1; + unsigned int __csx_resv3 : 3; + unsigned int __csx_resv4 : 32; + }; + }; unsigned long flags; unsigned long sp; - unsigned long ss; -/* top of stack page */ + union { + unsigned long ssx; /* ss extended: SS + any fields above it */ + struct __attribute__((__packed__)) { + unsigned short ss; /* SS selector proper */ + unsigned int __ssx_resv1 : 16; + unsigned int vector : 8; + unsigned int __ssx_resv2 : 8; + unsigned int type : 4; + unsigned int __ssx_resv3 : 4; + unsigned int enclv : 1; + unsigned int long_mode : 1; + unsigned int nested : 1; + unsigned int __ssx_resv4 : 1; + unsigned int instr_len : 4; + }; + }; }; #endif /* !__i386__ */ diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 4e34b3b68ebd..57de166dc61c 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -116,7 +116,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);