Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.5 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD6A5C433DB for ; Wed, 10 Feb 2021 13:54:43 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6586B64E16 for ; Wed, 10 Feb 2021 13:54:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6586B64E16 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.83608.155994 (Exim 4.92) (envelope-from ) id 1l9pww-00085D-RA; Wed, 10 Feb 2021 13:54:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 83608.155994; Wed, 10 Feb 2021 13:54:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l9pww-000856-Nm; Wed, 10 Feb 2021 13:54:34 +0000 Received: by outflank-mailman (input) for mailman id 83608; Wed, 10 Feb 2021 13:54:33 +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 1l9pwv-00084y-Gq for xen-devel@lists.xenproject.org; Wed, 10 Feb 2021 13:54:33 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d961a3b7-a242-4333-8dcf-34e00102ec04; Wed, 10 Feb 2021 13:54:32 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 482CCACBF; Wed, 10 Feb 2021 13:54:31 +0000 (UTC) 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: d961a3b7-a242-4333-8dcf-34e00102ec04 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=1612965271; 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: in-reply-to:in-reply-to:references:references; bh=7oRBAvtl+Q8sPQoGsn5VbLvJ8fGKg4gthf78AOEzXqc=; b=nmQYRLnydaDmCXpsHAu8TWA4ondGQKrLbg3m48BMZ9hiFT1pj1ajQPj8twoW9z5/BvaW+K YYetU0ke3RZl5i7g8IQXQV8HyQcNwF+x0xUVvRq/NbJQTNPJIiR0IBOIJyPEoPAagDkAEb V8bVSHNnTzfWltlZizJpDtq4YbuBDUQ= Subject: Re: [PATCH] x86emul: fix SYSENTER/SYSCALL switching into 64-bit mode To: Andrew Cooper Cc: Wei Liu , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= , "xen-devel@lists.xenproject.org" References: <7ce15e4b-8bf1-0cfd-ca9e-5f6eba12cac1@suse.com> From: Jan Beulich Message-ID: <2eed5630-3e23-3005-245e-989893fc8476@suse.com> Date: Wed, 10 Feb 2021 14:54:30 +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 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 10.02.2021 13:28, Andrew Cooper wrote: > On 10/02/2021 09:57, Jan Beulich wrote: >> 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 = ops->write_segment(x86_seg_ss, &sreg, ctxt)) ) >> goto done; >> >> + if ( ctxt->lma ) >> + /* In particular mode_64bit() needs to return true from here on. */ >> + ctxt->addr_size = ctxt->sp_size = 64; > > I think this is fine as presented, but don't we want the logical > opposite for SYSRET/SYSEXIT ? > > We truncate rip suitably already, This is why I left them alone, i.e. ... > but don't know what other checks may appear in the future. ... I thought we would deal with this if and when such checks would appear. Just like considered in the post-description remark, we could drop the conditional part from sysexit's setting of _regs.r(ip), and _then_ we would indeed need a respective change there, for the truncation to happen at complete_insn:. Jan