From patchwork Tue Dec 5 10:50:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 173982 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3359042vqy; Tue, 5 Dec 2023 03:22:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IGpMdIudR9BzUqHcuWsdnFVSkkq3y6KB9r2TvBTV315vQuIMB050dM7eI3r+RcNEqAu7cLP X-Received: by 2002:a17:90b:1110:b0:286:6cc1:2cad with SMTP id gi16-20020a17090b111000b002866cc12cadmr853597pjb.55.1701775349815; Tue, 05 Dec 2023 03:22:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701775349; cv=none; d=google.com; s=arc-20160816; b=r3BXURdHFs63ZsulU4NmmySjtWmGCmX5cOs3YYnoJcuoHbNwXksq4vRWeMYCY4zzos lx0n/zfeuCsznMkBAULBz1aPw1B5iRNYNTSVFMBnz6cIqs+4wKCyySA3QHurOZDhWPV6 lHITZ3Y34CnRZECWcOBSgpkhiusdGlqF4dkw4HpRTSm3No5IyHbgjb04P2NSvutxVuJx gkLppD48NGSXOgYoDHLWYcbd9EQ1g84+KXVerlFg8myWcd5l2k7ewAwoXQWcvbEh9aq8 g/CrU1aOrIn5vXtrcnhcsQdOKNdxt0BWhbFFLC/NCWqDBO8kY4PSBJOwOdHmEX43IoCI P+pw== 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=e66ttYKVI/gnDQpkF7rSEjP0z9fVEapOMc83NlqIjI8=; fh=uCCWEUVpLc/xDP/D3WvGY/BxHU9d0NQYu/T71GEsNmA=; b=ucklOhoX3O6En4vhLpBqrSnKvMscFnB7/Jv/9TA2YvSmC98mslLVSu4SGW/J1NMshS Fu9dY34bz6AZQH7m9a+81euiqEcucgMRBc/cVhN/qUEihVb3klCXqtH+50jiTxNjs1eT 83AXbv8uAAhE7VALPZnbN5oq5LuJix20y6z6Jp6+kT7jngSXUY8jkcqpGqsUJigqPupX ZOeeBZjnz+YjTBkXA4n2HjqxtxiPRak+I4cmtGuiYkL8KyqML32cv4fVBkfpHoCBLon/ wI2vX4cjQMWUc4ivMdzKZHmhtZx+v4zN4WtraTtCB5W2+W3WeTtoLaJ+SSLekH9YMDRJ KZIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OY93Qapa; 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id h3-20020a17090acf0300b002867ec14e6fsi4706366pju.153.2023.12.05.03.22.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 03:22:29 -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=OY93Qapa; 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 05C6F8225CBA; Tue, 5 Dec 2023 03:22:18 -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 S1442230AbjLELWA (ORCPT + 99 others); Tue, 5 Dec 2023 06:22:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442079AbjLELVU (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 DFCA9116; 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=1701775287; x=1733311287; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FnZS/yD0JeHn5+eEO+y+LbIbxiSvYr0DpCCKe3lA/lE=; b=OY93Qapal3E1ms9fz+snRlSE9hMMokgzLjpIrZ3eQsZTJHh9TrQjhxR2 Swbzc9/69KQueXIbzwAY1ZDE1jRhHVeR1EK2++MopKR6931SA0w0Hg7V3 aai+76yk5HEX/mCf4FIgKKJ2m5Cv+sJXcuxvNEi6/ErKvGmhLSRDxZP4k Tylu7RHRX9kzZc5YLmER+rS17gVMjVZh8bovlaSqQJDNOfuLl6hRiRSsd RkPMbbaf3aAy3s/x4qfCsoqrrk/vxg/Ecd+p3/zglfaLIEjdSXGkCZmUZ trUT5rwuECKUKQV8ilJKabpXIMqEDdge6q79vuBJ97TPxll03JMVfygu1 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="942495" X-IronPort-AV: E=Sophos;i="6.04,252,1695711600"; d="scan'208";a="942495" 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:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="1018192946" X-IronPort-AV: E=Sophos;i="6.04,252,1695711600"; d="scan'208";a="1018192946" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga006.fm.intel.com with ESMTP; 05 Dec 2023 03:21:20 -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 14/35] x86/ptrace: Add FRED additional information to the pt_regs structure Date: Tue, 5 Dec 2023 02:50:03 -0800 Message-ID: <20231205105030.8698-15-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 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:18 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784440789313219978 X-GMAIL-MSGID: 1784440789313219978 FRED defines additional information in the upper 48 bits of cs/ss fields. Therefore add the information definitions into the pt_regs structure. Specially introduce a new structure fred_ss to denote the FRED flags above SS selector, which avoids FRED_SSX_ macros and makes the code simpler and easier to read. Originally-by: H. Peter Anvin (Intel) Suggested-by: Thomas Gleixner Tested-by: Shan Kang Signed-off-by: Xin Li --- Change since v11: * Add a new structure fred_cs to denote the FRED flags above CS selector as what is done for SS (H. Peter Anvin). Changes since v9: * Introduce a new structure fred_ss to denote the FRED flags above SS selector, which avoids FRED_SSX_ macros and makes the code simpler and easier to read (Thomas Gleixner). * Use type u64 to define FRED bit fields instead of type unsigned int (Thomas Gleixner). 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/include/asm/ptrace.h | 66 ++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h index b268cd2a2d01..5a83fbd9bc0b 100644 --- a/arch/x86/include/asm/ptrace.h +++ b/arch/x86/include/asm/ptrace.h @@ -56,6 +56,50 @@ struct pt_regs { #else /* __i386__ */ +struct fred_cs { + /* CS selector */ + u64 cs : 16, + /* Stack level at event time */ + sl : 2, + /* IBT in WAIT_FOR_ENDBRANCH state */ + wfe : 1, + : 45; +}; + +struct fred_ss { + /* SS selector */ + u64 ss : 16, + /* STI state */ + sti : 1, + /* Set if syscall, sysenter or INT n */ + swevent : 1, + /* Event is NMI type */ + nmi : 1, + : 13, + /* Event vector */ + vector : 8, + : 8, + /* Event type */ + type : 4, + : 4, + /* Event was incident to enclave execution */ + enclave : 1, + /* CPU was in long mode */ + lm : 1, + /* + * Nested exception during FRED delivery, not set + * for #DF. + */ + nested : 1, + : 1, + /* + * The length of the instruction causing the event. + * Only set for INTO, INT1, INT3, INT n, SYSCALL + * and SYSENTER. 0 otherwise. + */ + insnlen : 4; +}; + struct pt_regs { /* * C ABI says these regs are callee-preserved. They aren't saved on @@ -85,6 +129,12 @@ struct pt_regs { * - the syscall number (syscall, sysenter, int80) * - error_code stored by the CPU on traps and exceptions * - the interrupt number for device interrupts + * + * A FRED stack frame starts here: + * 1) It _always_ includes an error code; + * + * 2) The return frame for ERET[US] starts here, but + * the content of orig_ax is ignored. */ unsigned long orig_ax; @@ -92,24 +142,30 @@ struct pt_regs { unsigned long ip; union { - /* The full 64-bit data slot containing CS */ - u64 csx; /* CS selector */ u16 cs; + /* The extended 64-bit data slot containing CS */ + u64 csx; + /* The FRED CS extension */ + struct fred_cs fred_cs; }; unsigned long flags; unsigned long sp; union { - /* The full 64-bit data slot containing SS */ - u64 ssx; /* SS selector */ u16 ss; + /* The extended 64-bit data slot containing SS */ + u64 ssx; + /* The FRED SS extension */ + struct fred_ss fred_ss; }; /* - * Top of stack on IDT systems. + * Top of stack on IDT systems, while FRED systems have extra fields + * defined above for storing exception related information, e.g. CR2 or + * DR6. */ };