Received: by 10.192.165.156 with SMTP id m28csp3011463imm; Sun, 15 Apr 2018 14:58:55 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+OOyQTuup246XYMuj2QV8hXKPSxn9KbvWQj2NO8k/FUta7Te0/Q+I1BJ3KoB9vI7K9t4os X-Received: by 2002:a17:902:1e3:: with SMTP id b90-v6mr13127147plb.155.1523829535425; Sun, 15 Apr 2018 14:58:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523829535; cv=none; d=google.com; s=arc-20160816; b=qow3VMET2IIPUCAT98esbxeyYOBr7d2QB1ASERxqQ3cXjQX3IPRLIuWGTclg1BXdTv S9beZ7E3KIiRHxQ9hP1cmML/r8X0nFEDZ2qPZh26AZ/2rAKHV4e1KzJDStzzdvDNrc88 VVRRDFY5VkUYKjivDRkwI96Da9YbJID9jZ+UlV1+JP6Y4oH5wrzPe6Cs0/T+ozOQ0xgj QnTpgFMIkLPrFFp0tN6Yd8D0LYlHKFyv2lSerA+m2ns4kntht/OVgNC6fcY/a4tYgoX+ whvFHMXDhS55fbFyfZzFbDkpoX05qn08DzwLlPgWTLpxsR4OnzTX/vRhgmCuRuZYGyiI ycwg== 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:arc-authentication-results; bh=tL5nmf7YPkLOUzh5KJasUvPxEnnXtCPD/HlAOUa9RUw=; b=IuTgb3/LGS6bMmIzx0lerUY7HcU9BPA78tVBpcM+LIUru9BcMzvSTBzFIWRaJGyzc3 h09dK9nTbQaaZONspSw0fa9GyKj/+LWvLbCZw/t/DLLUfG0HrPZIJ+3tzMFO9KKuygjZ sMCDSveTqSPj1b4IQ/KfLS029EAX7qAqkgTCl/GiwChaBbpMFEOLs2Dff9I4125nnxlN MJKRT6LyiPf9I8UmoLNoNFKmeAw0GCia1ZbTEmNyd4BmoMSoupN/EKAI8IAIMLNbs/3X ckXMhq45ff7ykPDtCYzP+DvO30dr058jBNUI8P8e+fu9j9+xdF9WgS0LVWMvCJnNXpRg G/fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=GMRIsryi; 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 bd9-v6si10538436plb.461.2018.04.15.14.58.41; Sun, 15 Apr 2018 14:58:55 -0700 (PDT) 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=GMRIsryi; 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 S1753193AbeDOV4e (ORCPT + 99 others); Sun, 15 Apr 2018 17:56:34 -0400 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]:40933 "EHLO smtp-fw-33001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752775AbeDOVzB (ORCPT ); Sun, 15 Apr 2018 17:55:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1523829300; x=1555365300; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=tL5nmf7YPkLOUzh5KJasUvPxEnnXtCPD/HlAOUa9RUw=; b=GMRIsryiSdK/7I/Jj4mu5rO4gC35mHTF5EB2QLMgJqbSv0YEefdjjaGH 5VXL7KujFJfYi++Xpy8PCHUpLX9XSESQYGnpncoCVAFSTczKuTSVfvmDP yU8cdvBvQ5Jy/JxgeHLwHtyRCmDNAAKac4kPuw6YqZ+rXwtcIrbH5kuBy 4=; X-IronPort-AV: E=Sophos;i="5.48,456,1517875200"; d="scan'208";a="726275415" Received: from sea3-co-svc-lb6-vlan2.sea.amazon.com (HELO email-inbound-relay-2c-2225282c.us-west-2.amazon.com) ([10.47.22.34]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 15 Apr 2018 21:54:57 +0000 Received: from u54e1ad5160425a4b64ea.ant.amazon.com (pdx2-ws-svc-lb17-vlan2.amazon.com [10.247.140.66]) by email-inbound-relay-2c-2225282c.us-west-2.amazon.com (8.14.7/8.14.7) with ESMTP id w3FLsrCn091557 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 15 Apr 2018 21:54:54 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 w3FLsqW4013450; Sun, 15 Apr 2018 23:54:52 +0200 Received: (from karahmed@localhost) by u54e1ad5160425a4b64ea.ant.amazon.com (8.15.2/8.15.2/Submit) id w3FLsqwI013449; Sun, 15 Apr 2018 23:54:52 +0200 From: KarimAllah Ahmed To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, pbonzini@redhat.com, rkrcmar@redhat.com Cc: KarimAllah Ahmed Subject: [PATCH v2 08/12] KVM/nVMX: Use kvm_vcpu_map when mapping the posted interrupt descriptor table Date: Sun, 15 Apr 2018 23:53:14 +0200 Message-Id: <1523829198-13236-9-git-send-email-karahmed@amazon.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523829198-13236-1-git-send-email-karahmed@amazon.de> References: <1523829198-13236-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 when mapping the posted interrupt descriptor table since using kvm_vcpu_gpa_to_page() and kmap() will only work for guest memory that has a "struct page". One additional semantic change is that the virtual host mapping lifecycle has changed a bit. It now has the same lifetime of the pinning of the interrupt descriptor table page on the host side. Signed-off-by: KarimAllah Ahmed --- v1 -> v2: - Do not change the lifecycle of the mapping (pbonzini) --- arch/x86/kvm/vmx.c | 45 +++++++++++++++------------------------------ 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index b55053a..3dd8bb2 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -493,7 +493,7 @@ struct nested_vmx { */ struct page *apic_access_page; struct kvm_host_map virtual_apic_map; - struct page *pi_desc_page; + struct kvm_host_map pi_desc_map; struct kvm_host_map msr_bitmap_map; struct pi_desc *pi_desc; @@ -7807,12 +7807,8 @@ static void free_nested(struct vcpu_vmx *vmx) vmx->nested.apic_access_page = NULL; } kvm_vcpu_unmap(&vmx->nested.virtual_apic_map); - if (vmx->nested.pi_desc_page) { - kunmap(vmx->nested.pi_desc_page); - kvm_release_page_dirty(vmx->nested.pi_desc_page); - vmx->nested.pi_desc_page = NULL; - vmx->nested.pi_desc = NULL; - } + kvm_vcpu_unmap(&vmx->nested.pi_desc_map); + vmx->nested.pi_desc = NULL; free_loaded_vmcs(&vmx->nested.vmcs02); } @@ -10413,24 +10409,16 @@ static void nested_get_vmcs12_pages(struct kvm_vcpu *vcpu) } if (nested_cpu_has_posted_intr(vmcs12)) { - if (vmx->nested.pi_desc_page) { /* shouldn't happen */ - kunmap(vmx->nested.pi_desc_page); - kvm_release_page_dirty(vmx->nested.pi_desc_page); - vmx->nested.pi_desc_page = NULL; + map = &vmx->nested.pi_desc_map; + + if (!kvm_vcpu_map(vcpu, gpa_to_gfn(vmcs12->posted_intr_desc_addr), map)) { + vmx->nested.pi_desc = + (struct pi_desc *)(((void *)map->hva) + + offset_in_page(vmcs12->posted_intr_desc_addr)); + vmcs_write64(POSTED_INTR_DESC_ADDR, pfn_to_hpa(map->pfn) + + offset_in_page(vmcs12->posted_intr_desc_addr)); } - page = kvm_vcpu_gpa_to_page(vcpu, vmcs12->posted_intr_desc_addr); - if (is_error_page(page)) - return; - vmx->nested.pi_desc_page = page; - vmx->nested.pi_desc = kmap(vmx->nested.pi_desc_page); - vmx->nested.pi_desc = - (struct pi_desc *)((void *)vmx->nested.pi_desc + - (unsigned long)(vmcs12->posted_intr_desc_addr & - (PAGE_SIZE - 1))); - vmcs_write64(POSTED_INTR_DESC_ADDR, - page_to_phys(vmx->nested.pi_desc_page) + - (unsigned long)(vmcs12->posted_intr_desc_addr & - (PAGE_SIZE - 1))); + } if (nested_vmx_prepare_msr_bitmap(vcpu, vmcs12)) vmcs_set_bits(CPU_BASED_VM_EXEC_CONTROL, @@ -12067,13 +12055,10 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason, kvm_release_page_dirty(vmx->nested.apic_access_page); vmx->nested.apic_access_page = NULL; } + kvm_vcpu_unmap(&vmx->nested.virtual_apic_map); - if (vmx->nested.pi_desc_page) { - kunmap(vmx->nested.pi_desc_page); - kvm_release_page_dirty(vmx->nested.pi_desc_page); - vmx->nested.pi_desc_page = NULL; - vmx->nested.pi_desc = NULL; - } + kvm_vcpu_unmap(&vmx->nested.pi_desc_map); + vmx->nested.pi_desc = NULL; /* * We are now running in L2, mmu_notifier will force to reload the -- 2.7.4