From patchwork Tue Aug 1 08:32:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 129143 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2567674vqg; Tue, 1 Aug 2023 03:17:23 -0700 (PDT) X-Google-Smtp-Source: APBJJlHzuURvlwaE0dzOpn4ifxA8B2cVArdNjXhXhnCq3+57CZfVgvQz88XMqgotlqod97cS+vwv X-Received: by 2002:aca:bd87:0:b0:3a3:fda0:37c7 with SMTP id n129-20020acabd87000000b003a3fda037c7mr10388116oif.46.1690885042782; Tue, 01 Aug 2023 03:17:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690885042; cv=none; d=google.com; s=arc-20160816; b=NYFIdx1Lnywx14QCmDMW+NVuqYFWbGGMs+h+SasQ1K6HQmvYCy+1KWBK7SQN+YA4z6 34Li5rWC+/lbHqu+2JcHxVWYg7/IfNI7MXspiSgQ76MIooNzbShe3rlM7sSW2XB/TT79 nugzfiuhgiEuBF5Nbeato86MUNKMFd7VvUh7imLaklQAtGYJtrQnwopN5lXSYNCvsR0/ kXT4sFeysNQO9Q22nIhga8aBPKyVH4YqTwvHPacLhNIzaAfYWFa5jHDoWdzlq4127PdV 887F4hMsT4Mdkre/Mtnt3VjSTN38wdsBkRIyqQvDJnToCOvlmhMEZU6S9dQBtU9kTz8d d/WA== 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=smtqT00X5PokEtaSjNpwUt9fY2UaLhM8q2yw2MIPd6o=; fh=nYO9ukkM7JnAAJZcChGC8UWBlCLXeJxIDT82cxoIaf0=; b=RZyG9tNt8ZerZtPj/OWnEAP+KmcqustpyABmWbxlpL60Q7ixVcWU+gx/nTp3fWRT9O 0llOV15KvhjY3eQpz68osKXg7Z7B/btgu7xEHoKFdclhBwMVjUHNd9xKsYIfijSprdpH stckmQoiXAuP/yiQWsRT91/wHhwq1t8Fh8riOA5E6KOiPfS7TZwS/GdQgFVrhlFnURS3 3ZWluAGiXUa/C7ngL4h5OMm7Z+Fjwav4wu/WyXa4Tjhb+AjSSTOZ2dfb1xDkCxlqplXF F205+TT0tpBggrcStAVGSS5MP4Usz0ZGxUblQ3V+Hoeb6vTLrVo/Fw9zqe+Jhtmf2car cPHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dLsfxeib; 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 x5-20020a654145000000b00563fe2c1163si5497778pgp.168.2023.08.01.03.17.09; Tue, 01 Aug 2023 03:17:22 -0700 (PDT) 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=dLsfxeib; 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 S232532AbjHAJEP (ORCPT + 99 others); Tue, 1 Aug 2023 05:04:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232644AbjHAJDK (ORCPT ); Tue, 1 Aug 2023 05:03:10 -0400 Received: from mgamail.intel.com (unknown [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E7C930C1; Tue, 1 Aug 2023 02:02:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690880557; x=1722416557; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=f1KjXTBSCMC/3m47AKFmo72XHXtCtx2wNvJSmQVR8WU=; b=dLsfxeibL5Kp/2FkaRznUAMD6fGxFEEWHiuwyquSAb09tA+COc1ZvwT4 6akD/2w6YG7crv2+2XCbuZ6n6Jqy5/t/0XiBIrmYB53f+11O/Bt6Ca2Oi i3o+WZqcW+0xg1m0llt1En5zewAcaGaA5JufN0ScVH0B/8KbB0rKFB9UJ F4yp6o93dGePEfBdS0aEcMw0AfnhgwH/jOLHt/beNiyeRfUfyV+DlmQQ2 fqPzJwf+iT3BpUyvpUf6ZO9z/cG9lh5N6naH4J+igYV3evNrVWtSen6QY NjIyhJMR++is65P1Ewnmk5iNQfQ6+aeWfkyYZxmtnoMVos8URHTfM8Ca2 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10788"; a="433082331" X-IronPort-AV: E=Sophos;i="6.01,246,1684825200"; d="scan'208";a="433082331" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Aug 2023 02:01:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10788"; a="975216994" X-IronPort-AV: E=Sophos;i="6.01,246,1684825200"; d="scan'208";a="975216994" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga006.fm.intel.com with ESMTP; 01 Aug 2023 02:01:58 -0700 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: Jonathan Corbet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Andy Lutomirski , Oleg Nesterov , Tony Luck , "K . Y . Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Paolo Bonzini , Wanpeng Li , Vitaly Kuznetsov , Sean Christopherson , Peter Zijlstra , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Josh Poimboeuf , "Paul E . McKenney" , Catalin Marinas , Randy Dunlap , Steven Rostedt , Kim Phillips , Xin Li , Hyeonggon Yoo <42.hyeyoo@gmail.com>, "Liam R . Howlett" , Sebastian Reichel , "Kirill A . Shutemov" , Suren Baghdasaryan , Pawan Gupta , Babu Moger , Jim Mattson , Sandipan Das , Lai Jiangshan , Hans de Goede , Reinette Chatre , Daniel Sneddon , Breno Leitao , Nikunj A Dadhania , Brian Gerst , Sami Tolvanen , Alexander Potapenko , Andrew Morton , Arnd Bergmann , "Eric W . Biederman" , Kees Cook , Masami Hiramatsu , Masahiro Yamada , Ze Gao , Fei Li , Conghui , Ashok Raj , "Jason A . Donenfeld" , Mark Rutland , Jacob Pan , Jiapeng Chong , Jane Malalane , David Woodhouse , Boris Ostrovsky , Arnaldo Carvalho de Melo , Yantengsi , Christophe Leroy , Sathvika Vasireddy Subject: [PATCH RESEND v9 09/36] x86/fred: Make unions for the cs and ss fields in struct pt_regs Date: Tue, 1 Aug 2023 01:32:51 -0700 Message-Id: <20230801083318.8363-10-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230801083318.8363-1-xin3.li@intel.com> References: <20230801083318.8363-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,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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: INBOX X-GMAIL-THRID: 1773021474593447883 X-GMAIL-MSGID: 1773021474593447883 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 v8: * Reflect stack frame definition changes from FRED spec 3.0 to 5.0. * Use __packed instead of __attribute__((__packed__)) (Borislav Petkov). * Put all comments above the members, like the rest of the file does (Borislav Petkov). 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 | 57 +++++++++++++++++++++++++-- arch/x86/kernel/process_64.c | 2 +- 3 files changed, 56 insertions(+), 5 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..f1690beffd15 100644 --- a/arch/x86/include/asm/ptrace.h +++ b/arch/x86/include/asm/ptrace.h @@ -80,15 +80,66 @@ struct pt_regs { /* * On syscall entry, this is syscall#. On CPU exception, this is error code. * On hw interrupt, it's IRQ number: + * + * A FRED stack frame starts here: + * 1) It _always_ includes an error code; + * 2) The return frame for eretu/erets starts here. */ unsigned long orig_ax; /* Return frame for iretq */ unsigned long ip; - unsigned long cs; + union { +/* CS extended: CS + any fields above it */ + unsigned long csx; + struct { +/* CS selector proper */ + unsigned short cs; +/* The stack level (SL) at the time the event occurred */ + unsigned int sl : 2; +/* Set to indicate that indirect branch tracker in WAIT_FOR_ENDBRANCH state */ + unsigned int wfe : 1; + unsigned int __csx_resv1: 13; + unsigned int __csx_resv2: 32; + } __packed; + }; unsigned long flags; unsigned long sp; - unsigned long ss; -/* top of stack page */ + union { +/* SS extended: SS + any fields above it */ + unsigned long ssx; + struct { +/* SS selector proper */ + unsigned short ss; +/* Set to indicate that interrupt blocking by STI was in effect */ + unsigned int sti : 1; +/* For SYSCALL, SYSENTER, or INT n (for any value of n) */ + unsigned int sys : 1; + unsigned int nmi : 1; + unsigned int __ssx_resv1: 13; +/* Event information fields, ignored by the FRED return instructions */ + unsigned int vector : 8; + unsigned int __ssx_resv2: 8; + unsigned int type : 4; + unsigned int __ssx_resv3: 4; +/* Set to indicate that the event was incident to enclave execution */ + unsigned int enc : 1; +/* Set to indicate that the logical processor had been in 64-bit mode */ + unsigned int l : 1; +/* + * Set to indicate the event is a nested exception encountered during FRED + * event delivery of another event. This bit is not set if the event is + * double fault (#DF). + */ + unsigned int nst : 1; + unsigned int __ssx_resv4: 1; +/* The length of the instruction causing the event */ + unsigned int instr_len : 4; + } __packed; + }; +/* + * Top of stack page on IDT systems, while FRED systems have extra fields + * defined above, see . + */ }; #endif /* !__i386__ */ diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 3d181c16a2f6..265ab8fcb146 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);