From patchwork Mon Apr 10 08:14:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 81391 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1757062vqo; Mon, 10 Apr 2023 01:41:56 -0700 (PDT) X-Google-Smtp-Source: AKy350YlY5KoIsiEeYrZ5WAm3oKoF7NW+2qmAMkj9GUR/o7wlRdmXidt4yIvxOeXFdn6m2eV0GfF X-Received: by 2002:a17:902:e493:b0:1a2:1042:cac1 with SMTP id i19-20020a170902e49300b001a21042cac1mr10117498ple.49.1681116115718; Mon, 10 Apr 2023 01:41:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681116115; cv=none; d=google.com; s=arc-20160816; b=WGcMXN3oLnu4yJTE86W47Ku8nDh5nralr4+aL5VTLS4Ui8fNDJLFYEUZ4SV3pRx6re bYkJiBsu4gNl/IFmM0rfvjH6doGRlxFKkAiosw4jNVmDWE0aIbILdYmMpF8U+ChJ3nwW r6Ng81V+83RwUGQfSvFf7OGfUN2zci9zhC29vzynF0SLnyKotwSpZDv6v+UN2NeKWVTg SMZcrF8EjOQ7+wqBIwbNKSR4zO/MqB5eh5zo/ShKJW4C8mJtIkJFwBFvEUyxlVQ0YWcw H1Qf0ehILYis7QqnYZGYWb7BmoN+jg14fdgCnajTRsVG299H7/lx200woYN4RqNTPKCz OXQw== 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=69uZgB5syZguYJi9iT6gO8XISz/gXRjkiGmbEgB4SD0=; b=YIpvfwYsBeP789Nz+szouapzDOQ7C6R2oggMWZgD2P1m7KSk6arxb4tZTE0pkS4RBF Q7fRVD3dpLsbxBDHWEMl29OdCbd+gewWFKHF1mYDJhtXncFwtKR42ANRXQ2GBRfNZnRq 8BCE/Xr/184lVGnZpLvEU27rYObrwHanKEQnrXZRxl806CQbA+VPJYpm0ROqAO/Qqj5F zMDyA15QDc0SJfHVoffrmGgIohEVjz1bH8e8e9fNopD58JYT3y38uTajhI+h2K79ZFHU zevGOOG1RWeoGpHyPikoDFArWSg5DRTcMbuVbJvtBCaOv+yl/MJNbiI45PIyzkVu7OB2 DycQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lTIqv9Uq; 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 k8-20020a170902c40800b001a63d75e33esi2383989plk.6.2023.04.10.01.41.44; Mon, 10 Apr 2023 01:41:55 -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=lTIqv9Uq; 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 S229743AbjDJIlM (ORCPT + 99 others); Mon, 10 Apr 2023 04:41:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229626AbjDJIlE (ORCPT ); Mon, 10 Apr 2023 04:41:04 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D86B40D9; Mon, 10 Apr 2023 01:41:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681116063; x=1712652063; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Nl6wMwkpqmIYYyq7+MpcXBB5xF17anU3m57tPiay76c=; b=lTIqv9Uq9rS5cOrLsD8ryaVKRwpxNGI27Jah/m8tlOFIW0l4tDhfNmJg tVRGIRgftIhO4ZQAziIvvdiMfDH7llEAguwdue8AkgHO1o4+nvgd6QKgW 8Ykxe8S7FUfPqZjqypQL4KL2vT3jlNBQsQXbFWy1Oi9u/YUn60H0X3Tlx jQTehOqVdNwFuEHLU0lJPDQNyJwGo4AXIrxZqd5kgeagWWK7D4B0h2O7h H5btdyCOYxe/HF9CmyNQZ5SfjGGMXQSQoPe8TulYgf0YNKfifMdt/gjpj kUF9SiPFqhm2kX7YBfjuAzifSajY+fLoYM3L9qPj0rBim8ZpYJKxMeQzn Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10675"; a="342077881" X-IronPort-AV: E=Sophos;i="5.98,333,1673942400"; d="scan'208";a="342077881" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 01:41:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10675"; a="799436241" X-IronPort-AV: E=Sophos;i="5.98,333,1673942400"; d="scan'208";a="799436241" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga002.fm.intel.com with ESMTP; 10 Apr 2023 01:41:01 -0700 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, jiangshanlai@gmail.com, shan.kang@intel.com Subject: [PATCH v8 02/33] x86/fred: make unions for the cs and ss fields in struct pt_regs Date: Mon, 10 Apr 2023 01:14:07 -0700 Message-Id: <20230410081438.1750-3-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410081438.1750-1-xin3.li@intel.com> References: <20230410081438.1750-1-xin3.li@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=unavailable 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?1762778012188065209?= X-GMAIL-MSGID: =?utf-8?q?1762778012188065209?= 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 | 34 ++++++++++++++++++++++++--- arch/x86/kernel/process_64.c | 2 +- 3 files changed, 33 insertions(+), 5 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..2abb23e6c1e2 100644 --- a/arch/x86/include/asm/ptrace.h +++ b/arch/x86/include/asm/ptrace.h @@ -82,12 +82,40 @@ 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; + 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; + }; + }; /* top of stack page */ }; diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index bb65a68b4b49..a1aa74864c8b 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);