Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp628922imu; Wed, 9 Jan 2019 03:49:15 -0800 (PST) X-Google-Smtp-Source: ALg8bN5+rpLmY9R/MGfUvbvioie9AmsdIhEyQhdEfbHIr0ebC6kx+o5hMFY/LNQdLnlT4XgBHxrn X-Received: by 2002:a63:5723:: with SMTP id l35mr4925530pgb.228.1547034555135; Wed, 09 Jan 2019 03:49:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547034555; cv=none; d=google.com; s=arc-20160816; b=ul9i/6XG/wxB0VinIspAChW65u+c46BtS4Zx6LGXdHvvok5LWzTYFuRibgXN5ZWGUN omtnr2JoGB2sUVrec3Qx3rc1mrWvK6aEJR2fhwkoSm6KumPFzDKxeVhisoA3zNtiXsoQ ytbDkkOX1sljILGEvg/CAE/8DxRuCw16JblNPtQgkRQlNurmSz2HREa3vu4x4Ptc1gu4 47h7HNyiaQCZVdRB30UlAkXx6LgklkWv2vxnVqH3SHLhqn4M0ZdNkxa9Ll7aRG3iFyIx XQEUfPGYF9ifxgL93TOEzXYXAb+tBIS2wV+muXeY8ESvUes9ZfVRRIbG9wQJxY0ZBPjN 2cyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=wKlFPeDrBIeJOZeTheOUbY1n64CVmAdUoP9gF7kZoZ8=; b=Wim7a7yfSa9Rux2mySL2wNxHVbyFo9cIMqqKfmOWgIGSL0LgiKGp04d8ffolSynow6 AhkamxYG3Jclv9s8haoyKjBDOaAGcZyy10L6HWkOPqBoc7Oz43DJ+TqdI2s/wFjn0oa0 /epEa3SubgME+GQWA0exTK9/l7XZCfYDzVt2MgkkHhwoLWpXQIXED6yZb+7JLetOmQth MDl+t+cwkUfzoriIoMUljt7QDtJdgI4Roh5yApUcO9r8RRoO6rZUAG5a/4Tk9M5qhqBM HDqxq77s0vj/TyCqFGm20+Y5O37Yh3HwhYoYRF5u57PrnZ2xzauUyuF7caTKtDsxi3h5 5DDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=frzAzPJG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k186si69613773pgc.576.2019.01.09.03.48.57; Wed, 09 Jan 2019 03:49:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=frzAzPJG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730649AbfAIJnK (ORCPT + 99 others); Wed, 9 Jan 2019 04:43:10 -0500 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:38448 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730479AbfAIJma (ORCPT ); Wed, 9 Jan 2019 04:42:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1547026949; x=1578562949; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=wKlFPeDrBIeJOZeTheOUbY1n64CVmAdUoP9gF7kZoZ8=; b=frzAzPJGmyOP2q7Fm4CShUQyZ/Ni1WB2gFHdlJy6ZJZuah1tcC+wMnEP EEhHgXfVH4afPg/dSYEGY9raagN0KCSOK6yCE888jLa5xBUw11Nb1+AAJ FLtxP0slpu9vCi/GX0ScLypbMZMnaakwnaJlppLLRr2qLh690zlKqNhNt M=; X-IronPort-AV: E=Sophos;i="5.56,253,1539648000"; d="scan'208";a="652219865" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2b-8cc5d68b.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 09 Jan 2019 09:42:25 +0000 Received: from u54e1ad5160425a4b64ea.ant.amazon.com (pdx2-ws-svc-lb17-vlan2.amazon.com [10.247.140.66]) by email-inbound-relay-2b-8cc5d68b.us-west-2.amazon.com (8.14.7/8.14.7) with ESMTP id x099gLUS064151 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 9 Jan 2019 09:42:22 GMT Received: from u54e1ad5160425a4b64ea.ant.amazon.com (localhost [127.0.0.1]) by u54e1ad5160425a4b64ea.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTP id x099gKaT031327; Wed, 9 Jan 2019 10:42:20 +0100 Received: (from karahmed@localhost) by u54e1ad5160425a4b64ea.ant.amazon.com (8.15.2/8.15.2/Submit) id x099gKc9031326; Wed, 9 Jan 2019 10:42:20 +0100 From: KarimAllah Ahmed To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, pbonzini@redhat.com, rkrcmar@redhat.com Cc: KarimAllah Ahmed Subject: [PATCH v5 09/13] KVM/X86: Use kvm_vcpu_map in emulator_cmpxchg_emulated Date: Wed, 9 Jan 2019 10:42:09 +0100 Message-Id: <1547026933-31226-10-git-send-email-karahmed@amazon.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1547026933-31226-1-git-send-email-karahmed@amazon.de> References: <1547026933-31226-1-git-send-email-karahmed@amazon.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use kvm_vcpu_map in emulator_cmpxchg_emulated since using kvm_vcpu_gpa_to_page() and kmap() will only work for guest memory that has a "struct page". Signed-off-by: KarimAllah Ahmed --- v4 -> v5: - unmap with dirty flag v1 -> v2: - Update to match the new API return codes --- arch/x86/kvm/x86.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 02c8e09..0c35cfc 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5492,9 +5492,9 @@ static int emulator_cmpxchg_emulated(struct x86_emulate_ctxt *ctxt, unsigned int bytes, struct x86_exception *exception) { + struct kvm_host_map map; struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt); gpa_t gpa; - struct page *page; char *kaddr; bool exchanged; @@ -5511,12 +5511,11 @@ static int emulator_cmpxchg_emulated(struct x86_emulate_ctxt *ctxt, if (((gpa + bytes - 1) & PAGE_MASK) != (gpa & PAGE_MASK)) goto emul_write; - page = kvm_vcpu_gfn_to_page(vcpu, gpa >> PAGE_SHIFT); - if (is_error_page(page)) + if (kvm_vcpu_map(vcpu, gpa_to_gfn(gpa), &map)) goto emul_write; - kaddr = kmap_atomic(page); - kaddr += offset_in_page(gpa); + kaddr = map.hva + offset_in_page(gpa); + switch (bytes) { case 1: exchanged = CMPXCHG_TYPE(u8, kaddr, old, new); @@ -5533,8 +5532,8 @@ static int emulator_cmpxchg_emulated(struct x86_emulate_ctxt *ctxt, default: BUG(); } - kunmap_atomic(kaddr); - kvm_release_page_dirty(page); + + kvm_vcpu_unmap(&map, true); if (!exchanged) return X86EMUL_CMPXCHG_FAILED; -- 2.7.4