From patchwork Wed May 1 23:52:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamas K Lengyel X-Patchwork-Id: 10925923 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1EA16933 for ; Wed, 1 May 2019 23:54:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 101C72624B for ; Wed, 1 May 2019 23:54:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03C6C28F3E; Wed, 1 May 2019 23:54:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6B6752624B for ; Wed, 1 May 2019 23:54:30 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hLz1M-00022G-Lj; Wed, 01 May 2019 23:52:16 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hLz1K-00022A-Le for xen-devel@lists.xenproject.org; Wed, 01 May 2019 23:52:14 +0000 X-Inumbo-ID: 23f5124b-6c6c-11e9-843c-bc764e045a96 Received: from mail-io1-f65.google.com (unknown [209.85.166.65]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 23f5124b-6c6c-11e9-843c-bc764e045a96; Wed, 01 May 2019 23:52:12 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id v9so465132iol.10 for ; Wed, 01 May 2019 16:52:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Cf6vKFNwGM0PHmy+EJAYnp49+CosnrTWDO07bloEDYc=; b=rDGocOHoMdaJim0F8AEvP0zel11S5xHPUWPIiyhxiGZV0b1slN+Sen7G4qjEgMmqBM /zvTC5mDjWJzkEMHp+5MiHlorHrdIA886m4VTXMIpC429VK5HfC4F58SiBqzLRd/jhj5 IRjxC1p/WGG5m0vY8oTQiLG+zurtRlrhUQVoRmxudsTw4Fi19CmE996Rdt2IKIxAZGaw QN2VE1Wo0CBJFtw7Yn+AboW9USZHR5Z25fo25Makc/2bMz5XHpQL/CsfRAoWbSPMFzmJ jTc7kHiVYLQJWfkpMp0ABoxAP3DiQK31mCR369VtAT68Lt/pdPDcFzfsOWfJ2vHV1Cq4 7LhQ== X-Gm-Message-State: APjAAAU2RQBP8dDpRNtpS/iVzxVBpxxVjlkYV4xQ91V40A0/Vjg5uE5F kzuZEQo8BbGVrv3BRNUNi5hqDD6p X-Google-Smtp-Source: APXvYqx9VbgalZWpr7I0fe7Z4g4J8FG6dnni8Tg5ov5NBWVn7OXLMZwnvbAnxqdjcv5+XZlAfMcg9g== X-Received: by 2002:a6b:b7c2:: with SMTP id h185mr390145iof.263.1556754732111; Wed, 01 May 2019 16:52:12 -0700 (PDT) Received: from localhost.localdomain (c-71-205-12-124.hsd1.co.comcast.net. [71.205.12.124]) by smtp.gmail.com with ESMTPSA id l20sm8384034ioh.83.2019.05.01.16.52.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 May 2019 16:52:10 -0700 (PDT) From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 1 May 2019 17:52:03 -0600 Message-Id: <20190501235203.1179-1-tamas@tklengyel.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2] x86/vmx: correctly gather gs_shadow value for current vCPU X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Tian , Tamas K Lengyel , Wei Liu , Jun Nakajima , Razvan Cojocaru , Andrew Cooper , Jan Beulich , Roger Pau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Currently the gs_shadow value is only cached when the vCPU is being scheduled out by Xen. Reporting this (usually) stale value through vm_event is incorrect, since it doesn't represent the actual state of the vCPU at the time the event was recorded. This prevents vm_event subscribers from correctly finding kernel structures in the guest when it is trapped while in ring3. Refresh shadow_gs value when the context being saved is for the current vCPU. Signed-off-by: Tamas K Lengyel Cc: Razvan Cojocaru Cc: Jun Nakajima Cc: Kevin Tian Cc: Jan Beulich Cc: Andrew Cooper Cc: Wei Liu Cc: Roger Pau Monne Acked-by: Razvan Cojocaru Acked-by: Kevin Tian --- v2: move fix to hvm so vm_event doesn't have to know specifics --- xen/arch/x86/hvm/vmx/vmx.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 283eb7b34d..5154ecc2a8 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -779,12 +779,17 @@ static void vmx_load_cpu_state(struct vcpu *v, struct hvm_hw_cpu *data) static void vmx_save_vmcs_ctxt(struct vcpu *v, struct hvm_hw_cpu *ctxt) { + if ( v == current ) + vmx_save_guest_msrs(v); + vmx_save_cpu_state(v, ctxt); vmx_vmcs_save(v, ctxt); } static int vmx_load_vmcs_ctxt(struct vcpu *v, struct hvm_hw_cpu *ctxt) { + ASSERT(v != current); + vmx_load_cpu_state(v, ctxt); if ( vmx_vmcs_restore(v, ctxt) )