From patchwork Fri Jan 6 08:56:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 40029 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp728768wrt; Fri, 6 Jan 2023 01:24:01 -0800 (PST) X-Google-Smtp-Source: AMrXdXvWONhiNgGmZhvelX8BgTLkqhZJwFASAF6CH1oZEDruEH6M71aRtdxJBcLfNCWl21Fcd9N5 X-Received: by 2002:a17:907:2587:b0:7c0:e7ad:fb0f with SMTP id ad7-20020a170907258700b007c0e7adfb0fmr38237276ejc.20.1672997041503; Fri, 06 Jan 2023 01:24:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672997041; cv=none; d=google.com; s=arc-20160816; b=uznqXyD/ynoQPZsLi31XjK9KeJGeMUw7mcx+oq5Piz5e6UsO/QsCLv5MriWtonDM6G NBHUeQrTgHRtWsmXeWQ1wrj9tIkBE+yt+S31zlh9SpOZ6yRf42sJA1fJF1jrJaVyXKQU u4yTvGWroJoxtynhF6XsLE2e/39qjPMVczWLtVHUxNFxdA0SHd9aNBlB2gfvRwAUtP5s r9MIH2zpiRV9U+HoCJcIrLdRYH+n2ZVxzX8SvQ3l/iXbFi/hTA9O5nGC4b+5BdPohl2z Vo3QRhcdCAetKSWnOfwq0IDP+Puo7Aa/PpPBlKduyaUD7GRe32yQh0COqcjaWlZmq1Bk rlVg== 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=vh86c52AI4jixrEGzY6NHO0WH1hit48wl3rot9rxk8Y=; b=yMeW2g0MnhSiOslS/1H/y1vp1KjjW2VuBA/AK/kUK7Ed8zo4Ysxk+rf1uCDITFYsbO lzLoEPjjNkYCqSMukLP5fFnmzRjAF+gK2f1N5a+rSAXPj4AyR2dm7g3VChSyvAEriIPF EtEsibXDABoC571fXGQu6psJIEIvP1jkRv8OwgzmOx8gFoyCDi9huohAWQ1D2H68b8Mb 8RkIYmH67eE5GRQZ5WwXhYQJxDBwQvnuubeaYXf3/U8Q8xIPLhDt31SciB1nmtYEmOFA +N9iL27vSkC8ik8x9aZC9a0bI/zMQs50FTLhK5Es8XB2wSVrRxZh+qNWN1l9BVoxI62A 8wew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=L3do6vfq; 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 du3-20020a17090772c300b0084d1ed9b688si896780ejc.405.2023.01.06.01.23.37; Fri, 06 Jan 2023 01:24:01 -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=L3do6vfq; 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 S234092AbjAFJWV (ORCPT + 99 others); Fri, 6 Jan 2023 04:22:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233027AbjAFJUV (ORCPT ); Fri, 6 Jan 2023 04:20:21 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3E6B63188; Fri, 6 Jan 2023 01:20:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672996820; x=1704532820; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WILQEUcGGh0f3+f/4EusBZPXm98ZhSdCi01R/9hMgCA=; b=L3do6vfqfzBhNE4O4OLghWTM/oLLTUDOCdk97qcXNAWycwOK7q6h0qG5 HWcDLOKxpiD42SJNPPNfEt8G0XvbYm/qqCUEYOYtVxh1IUzprUkBeb2ja itVgi++or6HtvkUqMXa3oLAZmr9JvdStHW73n1I4mV038/0wlI2r5+63H qr8EBSrgv+JGP0LJuP4yoXYOSAeQwWYQkl/5PDcpyqb5DbYeuOm/wFPrU xU43OZrqgAraXNmjb1FsifHDs8UecLRrD3J3HFCAbJuQjB2J4OKJkF02A VoFXYZJsvBgzoXjxDh6xpGViA0l0O3UEBTNY6kKr6qNtPSdXDDKgTxx+S A==; X-IronPort-AV: E=McAfee;i="6500,9779,10581"; a="322511505" X-IronPort-AV: E=Sophos;i="5.96,304,1665471600"; d="scan'208";a="322511505" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jan 2023 01:20:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10581"; a="719139392" X-IronPort-AV: E=Sophos;i="5.96,304,1665471600"; d="scan'208";a="719139392" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga008.fm.intel.com with ESMTP; 06 Jan 2023 01:20:14 -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: [RFC PATCH v2 15/32] x86/fred: make unions for the cs and ss fields in struct pt_regs Date: Fri, 6 Jan 2023 00:56:00 -0800 Message-Id: <20230106085617.17248-16-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230106085617.17248-1-xin3.li@intel.com> References: <20230106085617.17248-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?1754264545583387880?= X-GMAIL-MSGID: =?utf-8?q?1754264545583387880?= 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) Signed-off-by: Xin Li --- 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 4af81df133ee..6349c818d20a 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..341e44847cc1 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 csl; /* CS + any fields above it */ + struct __attribute__((__packed__)) { + unsigned short cs; /* CS selector proper */ + unsigned int current_stack_level: 2; + unsigned int __csl_resv1 : 6; + unsigned int interrupt_shadowed : 1; + unsigned int software_initiated : 1; + unsigned int __csl_resv2 : 2; + unsigned int nmi : 1; + unsigned int __csl_resv3 : 3; + unsigned int __csl_resv4 : 32; + }; + }; unsigned long flags; unsigned long sp; - unsigned long ss; -/* top of stack page */ + union { + unsigned long ssl; /* SS + any fields above it */ + struct __attribute__((__packed__)) { + unsigned short ss; /* SS selector proper */ + unsigned int __ssl_resv1: 16; + unsigned int vector : 8; + unsigned int __ssl_resv2: 8; + unsigned int type : 4; + unsigned int __ssl_resv3: 4; + unsigned int enclv : 1; + unsigned int long_mode : 1; + unsigned int nested : 1; + unsigned int __ssl_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 6b3418bff326..bfe6179b7a17 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);