Message ID | 20230410081438.1750-29-xin3.li@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1760756vqo; Mon, 10 Apr 2023 01:52:54 -0700 (PDT) X-Google-Smtp-Source: AKy350aZiZ8WkWV3yInfxZWY6l5FbG75lCxyLFlc4OZ+E/UtW1oslU2oQ2jqSo1K1yw08z2WDzNk X-Received: by 2002:a17:903:280c:b0:1a6:37a6:f429 with SMTP id kp12-20020a170903280c00b001a637a6f429mr3446288plb.42.1681116774408; Mon, 10 Apr 2023 01:52:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681116774; cv=none; d=google.com; s=arc-20160816; b=nD4t2fWd7U8oFClKxFKgkqGQ7LhdXBvMigYE/FlMofy9Mfihht29yF7mbvtIEjjfAA b80hT+NTqicgmWOxMEcqy0lTZFP2JQuPFHeHnn549UDHJblLJ4UOshpa1H+CkJ/bK6VG vzRm7F5YKY4WQDlOsCZ/wkrgBMJKar4yHLbsbbtyZY94VJN7JTJ/R0Vg3DYxXl0TYPLi Se9hTTdkm3DgWUHhxUevwMj9xDa8gHSRR7C+RMDLaX/mFqTpV1LqgK0PHJu+0l4H7K8J aVzGS7PNr1hLkiJdqnIypWPAiwPjw1Ey0AWCpOc3CgR959xSHJuR0S3DUSV6d1B614fI MxNQ== 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=6ryoaO52SQacc1V2FLptfa9uuyFKNPljQyyaT3VTYMw=; b=lFxXM20+Zei+baUYTFAXO0zfBOmMJGrvVGWHD4PCuOSkFYwPEPZwjrbcDTA6sieDR8 DgNDGA/a+A918EhU6whbEztS4QkNS++dX+lVl7vDTWwH69No4p2LX9O0z7jlUHVwyPy/ 9XWFM+q/512N22C6lA8wV+7mN5SN/44vistSiCMIoyqSNolzXFIdoK3qu+mC2g8B+A3f aPPXQX6VV2dU5iOXKYIVeOL1RT1OrtLsfIh6CKiKAGUZFQT0ki4rHLcpV8MfVTgi8Cai m2ltAXR4WnpIHI5X9SGakL37PuQbKrDV9hWLKAvW8OZ0nNeOlvMrY6gTFo/kLXOUQiLk YRKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SMVRPD79; 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 j3-20020a170903028300b001a4faff9bc9si1963158plr.467.2023.04.10.01.52.42; Mon, 10 Apr 2023 01:52:54 -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=SMVRPD79; 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 S230046AbjDJIml (ORCPT <rfc822;a1648639935@gmail.com> + 99 others); Mon, 10 Apr 2023 04:42:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229792AbjDJIlu (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 10 Apr 2023 04:41:50 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F409155A8; Mon, 10 Apr 2023 01:41:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681116074; x=1712652074; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5IBl0XY5xGj0Ul5jZJTZVlHtGnpVju3gJ8HZ07Stwk0=; b=SMVRPD79X+TVAEMdTjFw4cVxt46rr5izl935DEZ7hCd/Pw/E+yj2gp16 hHzG9l2iNCUHFkTZgOMfbPzCDdcrqosiUNCZf2qofd+zT6o4vCJ4Hh/FE StJ3Mnh/HcaIlhUWeH58vYpgLwHL1CiA3CsS+wsJoLWLRQJVzxWfeUztz xFQNZhhPOSxKx3pOMNzFgwuisc/7SqJ80KrmK3dnP6I1P51rU8eym84Ya Rj5PqjsRFpHg4TNPJoiNx8q6qmd7acZWALurr9h6T1al9BMxWN4kidN4B cGmkh/kGTgJ6vP1pplZN5jp6GFem7hadnQkZ7qxxnPyfkMRlB2pKYX0AW Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10675"; a="342078172" X-IronPort-AV: E=Sophos;i="5.98,333,1673942400"; d="scan'208";a="342078172" 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:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10675"; a="799436353" X-IronPort-AV: E=Sophos;i="5.98,333,1673942400"; d="scan'208";a="799436353" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga002.fm.intel.com with ESMTP; 10 Apr 2023 01:41:07 -0700 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, jiangshanlai@gmail.com, shan.kang@intel.com Subject: [PATCH v8 28/33] x86/ia32: do not modify the DPL bits for a null selector Date: Mon, 10 Apr 2023 01:14:33 -0700 Message-Id: <20230410081438.1750-29-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 Content-Transfer-Encoding: 8bit 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: <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?1762778702803754440?= X-GMAIL-MSGID: =?utf-8?q?1762778702803754440?= |
Series |
x86: enable FRED for x86-64
|
|
Commit Message
Li, Xin3
April 10, 2023, 8:14 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. Tested-by: Shan Kang <shan.kang@intel.com> Signed-off-by: Xin Li <xin3.li@intel.com> --- arch/x86/kernel/signal_32.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/arch/x86/kernel/signal_32.c b/arch/x86/kernel/signal_32.c index 9027fc088f97..7796cf84fca2 100644 --- a/arch/x86/kernel/signal_32.c +++ b/arch/x86/kernel/signal_32.c @@ -36,22 +36,27 @@ #ifdef CONFIG_IA32_EMULATION #include <asm/ia32_unistd.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)); } #define sigset32_t compat_sigset_t