Message ID | 20221220063658.19271-30-xin3.li@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2819014wrn; Mon, 19 Dec 2022 23:19:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf5uaIInGmydLxM02qJeG9X7kSqHXmpnVruaDSPrVQ+bR2h3sg40sZMPaSfpQjlrbaTlppHw X-Received: by 2002:a17:902:6b8b:b0:188:a4a3:7bb3 with SMTP id p11-20020a1709026b8b00b00188a4a37bb3mr45368170plk.9.1671520772983; Mon, 19 Dec 2022 23:19:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671520772; cv=none; d=google.com; s=arc-20160816; b=p1UHgYdeB7EkRRphVNPzM97TmHLLjBkF+cl/wmCtTPP/N38xc/8e0S5VVkRXzDx4Bk V6SgWLub1TgTGJ5cXf3Bj9QbdVpBzDdyATw5CUKWnMag9A9HRuEADbgiBHTCiUQyzXwZ sxMwFLr+hRMTI7sgntVyAxbFVmepMnCnCu7UcIfKgefpH3VqNTFCP+oB0oRrcOu6oOMb fBu/2kjOap4AWvo/piVwnrxxKzH7EsFXvl+61cr750RcGd/ohDzAmo3Br+I9pndhWYnF ZUkyfDR6GlNXVNQjPUtCa2p1lqpt291myYBYhfOsI/9vlW25rxuXVWDjlq+KmXp0DGP/ Nk1A== 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=K1pTP8jaKVQfZYXJaxEJ9qvzXWFgoi5IhB/Sa4OLgrQ=; b=QgFYVABxx/JmkQZq1kwoBRUT51Hqln+pOWqIdjpNM1P2hNoj2DavZ3ZbZMzSrTjN1z lDGXRqzkYP7THKKLi0ZBzj8dfw/J7EZBo/BTKM4n96X54yeuNfth+oRFntu5Q6Vi+YKT STWlMCjQJnA5APdDy++serfSYeLt5suZslNy/sB0Tt/aO1pjAdi9FDjujTA9p7K7nkqQ UmQNCHXIXDGME5NtWmyo42+lGKXBs50S5L8HndjwLQqgvM7JUQ45EzD3qvcu3pq8+52+ agNyfcyYja10k69UWkWJ0OCs17w7Mz4OeOhIr2k47XDvyIyEqZZo1xisVehIUyt/XZrb lccA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BDPoVh9A; 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 l18-20020a170903245200b00189b15ea35bsi14294742pls.208.2022.12.19.23.19.16; Mon, 19 Dec 2022 23:19:32 -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=BDPoVh9A; 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 S233695AbiLTHES (ORCPT <rfc822;abdi.embedded@gmail.com> + 99 others); Tue, 20 Dec 2022 02:04:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233300AbiLTHBo (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 20 Dec 2022 02:01:44 -0500 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DF8715FEC; Mon, 19 Dec 2022 23:01:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671519702; x=1703055702; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yvHd27MPzoRPhJLMrlSGr6kQm8k0tLId/1KA4wMkuYk=; b=BDPoVh9AaDqOWI32Qx9QseFcXRmMDZzl+jRzot659QlJF1SQmh+e5Tv4 iK0CDvJijF5bIQ1Q3D6DHcoJxWtybByVwKKgnlXgVEL+GT8Vt8GhnC2Ch ojDJUW+Y+68EKQ8R69JGxQASLspsfQfNdBDLV82O9hMs54HLcDxxOv4ki BHQq5K1Q6/t6tSQBaYKaduyjNGlfnXsUtvPpPllqCnnozU/0Lj0aAe0F+ FQMaA9ScdhOEgWQ+DMpJnPACX/39T8ifL3azyFfVO4IRqkroGqSmsqrbg 0+cmA6weMp6dtUOxJZcSe/+sEmMJ5QykUQ3zBgUcHSjdBIyT5Je2QixkF A==; X-IronPort-AV: E=McAfee;i="6500,9779,10566"; a="302972165" X-IronPort-AV: E=Sophos;i="5.96,258,1665471600"; d="scan'208";a="302972165" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Dec 2022 23:01:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10566"; a="644326551" X-IronPort-AV: E=Sophos;i="5.96,258,1665471600"; d="scan'208";a="644326551" Received: from unknown (HELO fred..) ([172.25.112.68]) by orsmga007.jf.intel.com with ESMTP; 19 Dec 2022 23:01:19 -0800 From: Xin Li <xin3.li@intel.com> 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 29/32] x86/ia32: do not modify the DPL bits for a null selector Date: Mon, 19 Dec 2022 22:36:55 -0800 Message-Id: <20221220063658.19271-30-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221220063658.19271-1-xin3.li@intel.com> References: <20221220063658.19271-1-xin3.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752716566162925095?= X-GMAIL-MSGID: =?utf-8?q?1752716566162925095?= |
Series |
x86: enable FRED for x86-64
|
|
Commit Message
Li, Xin3
Dec. 20, 2022, 6:36 a.m. UTC
When a null selector is to be loaded into a segment register,
reload_segments() sets its DPL bits to 3. Later when the IRET
instruction loads it, it zeros the segment register. The two
operations offset each other to actually effect a nop.
Unlike IRET, ERETU does not make any of DS, ES, FS, or GS null
if it is found to have DPL < 3. It is expected that a FRED-enabled
operating system will return to ring 3 (in compatibility mode)
only when those segments all have DPL = 3.
Thus when FRED is enabled, we end up with having 3 in a segment
register even when it is initially set to 0.
Fix it by not modifying the DPL bits for a null selector.
Signed-off-by: Xin Li <xin3.li@intel.com>
---
arch/x86/ia32/ia32_signal.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c index 14c739303099..31f5bbb59441 100644 --- a/arch/x86/ia32/ia32_signal.c +++ b/arch/x86/ia32/ia32_signal.c @@ -36,22 +36,27 @@ #include <asm/smap.h> #include <asm/gsseg.h> +static inline u16 usrseg(u16 sel) +{ + return sel <= 3 ? sel : sel | 3; +} + static inline void reload_segments(struct sigcontext_32 *sc) { unsigned int cur; savesegment(gs, cur); - if ((sc->gs | 0x03) != cur) - load_gs_index(sc->gs | 0x03); + if (usrseg(sc->gs) != cur) + load_gs_index(usrseg(sc->gs)); savesegment(fs, cur); - if ((sc->fs | 0x03) != cur) - loadsegment(fs, sc->fs | 0x03); + if (usrseg(sc->fs) != cur) + loadsegment(fs, usrseg(sc->fs)); savesegment(ds, cur); - if ((sc->ds | 0x03) != cur) - loadsegment(ds, sc->ds | 0x03); + if (usrseg(sc->ds) != cur) + loadsegment(ds, usrseg(sc->ds)); savesegment(es, cur); - if ((sc->es | 0x03) != cur) - loadsegment(es, sc->es | 0x03); + if (usrseg(sc->es) != cur) + loadsegment(es, usrseg(sc->es)); } /*