From nobody Sun Apr 28 03:42:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1612951083; cv=none; d=zohomail.com; s=zohoarc; b=BmXRRWki7xChEPJMHUil2ddyRb62wOeAHT2mRiqQy81+tCKW0zRjACxsWXFVpg3iECP2DSDSlmpHAMbYLwvcjQE9lPUJZBCz+ab0c9u6zxjOnGJlcqWYgGg+W7EK6e+5qUACx5z1+VjxjfVpe73oV7XZhbNS6YAE2EXD3YQmJVY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612951083; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=qquZIWRI0HVUHWPa6REcgtkd8siTn2WKZs0cNZYkmOc=; b=nBVFWf1UdwrmT1c0wW3YKOrx3iRFVv4fZ1yP3csV0/fGpMx9URMLVwUp1x4GdJVMYWh/ezK4ZJdIEcoZtyLw625f1oXGOJboeQmDUnn8mBC13O8mXub+Ra5BE33Le8wpL8inKyRg9Onh/HafnH5fQv+gUrjmmYU7dfVV/dUeC8o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1612951082760109.76805756891508; Wed, 10 Feb 2021 01:58:02 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.83513.155610 (Exim 4.92) (envelope-from ) id 1l9mFj-000090-Ek; Wed, 10 Feb 2021 09:57:43 +0000 Received: by outflank-mailman (output) from mailman id 83513.155610; Wed, 10 Feb 2021 09:57:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l9mFj-00008t-Br; Wed, 10 Feb 2021 09:57:43 +0000 Received: by outflank-mailman (input) for mailman id 83513; Wed, 10 Feb 2021 09:57:42 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l9mFi-00008o-LX for xen-devel@lists.xenproject.org; Wed, 10 Feb 2021 09:57:42 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id e29b3b47-3708-4922-a3a9-94abd4aa0967; Wed, 10 Feb 2021 09:57:40 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 76DBEB138; Wed, 10 Feb 2021 09:57:39 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e29b3b47-3708-4922-a3a9-94abd4aa0967 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1612951060; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qquZIWRI0HVUHWPa6REcgtkd8siTn2WKZs0cNZYkmOc=; b=QzD3QTcmLhvQF32yzs4uP8b+tEsPU08Q2UeZj4M5qg3L68flLVd3heQ7N2bYfg7UNSVp6x ItkKyzjrBmo3ydfZmY2ktRCor5Xg3/o/rx3iDzQq+UZwWhXokLsCejfJJMxia7j8Va80qH nzqN4TelAba99nv1lsHCW6saxTmR144= To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= From: Jan Beulich Subject: [PATCH] x86emul: fix SYSENTER/SYSCALL switching into 64-bit mode Message-ID: <7ce15e4b-8bf1-0cfd-ca9e-5f6eba12cac1@suse.com> Date: Wed, 10 Feb 2021 10:57:38 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" When invoked by compat mode, mode_64bit() will be false at the start of emulation. The logic after complete_insn, however, needs to consider the mode switched into, in particular to avoid truncating RIP. Inspired by / paralleling and extending Linux commit 943dea8af21b ("KVM: x86: Update emulator context mode if SYSENTER xfers to 64-bit mode"). While there, tighten a related assertion in x86_emulate_wrapper() - we want to be sure to not switch into an impossible mode when the code gets built for 32-bit only (as is possible for the test harness). Signed-off-by: Jan Beulich --- In principle we could drop SYSENTER's ctxt->lma dependency when setting _regs.r(ip). I wasn't certain whether leaving it as is serves as kind of documentation ... --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -6127,6 +6127,10 @@ x86_emulate( (rc =3D ops->write_segment(x86_seg_ss, &sreg, ctxt)) ) goto done; =20 + if ( ctxt->lma ) + /* In particular mode_64bit() needs to return true from here o= n. */ + ctxt->addr_size =3D ctxt->sp_size =3D 64; + /* * SYSCALL (unlike most instructions) evaluates its singlestep act= ion * based on the resulting EFLAGS.TF, not the starting EFLAGS.TF. @@ -6927,6 +6931,10 @@ x86_emulate( ctxt)) !=3D X86EMUL_OKAY ) goto done; =20 + if ( ctxt->lma ) + /* In particular mode_64bit() needs to return true from here o= n. */ + ctxt->addr_size =3D ctxt->sp_size =3D 64; + singlestep =3D _regs.eflags & X86_EFLAGS_TF; break; =20 @@ -12113,8 +12121,12 @@ int x86_emulate_wrapper( unsigned long orig_ip =3D ctxt->regs->r(ip); int rc; =20 +#ifdef __x86_64__ if ( mode_64bit() ) ASSERT(ctxt->lma); +#else + ASSERT(!ctxt->lma && !mode_64bit()); +#endif =20 rc =3D x86_emulate(ctxt, ops); =20