From patchwork Thu Sep 6 13:32:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liran Alon X-Patchwork-Id: 10590635 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 68DFE5A4 for ; Thu, 6 Sep 2018 13:33:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F3C52A2DF for ; Thu, 6 Sep 2018 13:33:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 514E92A3DE; Thu, 6 Sep 2018 13:33:10 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3781A2A2DF for ; Thu, 6 Sep 2018 13:33:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729619AbeIFSIl (ORCPT ); Thu, 6 Sep 2018 14:08:41 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:52990 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729565AbeIFSIl (ORCPT ); Thu, 6 Sep 2018 14:08:41 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w86DTSQG099092; Thu, 6 Sep 2018 13:33:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=OpT8MogXjPS89S20czZDevIq1d21uEJORWJXZXxMJuY=; b=zfkAcTknSdTPBfJbkTTk77ion1BUVjvz6DN2r9XG9AwFD33xlo7cXphK8DLYVTp3HgSX 85SloORlLbn3oSSyM3gsK6RJD8gy5cWDO5xSfixoLD/4Tpqa7+AZz8H+MGfR97RTgI/H 6zNlpv8P/FWxVxhkQ0EE11qBEj/VDmDtWZUio7Ay7nPX6v5nkdarASlTvfZXl9ZMpIhw aZp34XcsBitix6jJUc8tkXLhk5k9p1v6tB/BcWtaUE0WPcFY+r3VcNBqyRoTlKcBCIzF XabQdVYgaklnW77vqYjyjhEKWnTbyqE+3ExiqY/W0JmPnEFN5uaWvD/P4m0Sy8H8kxpI bw== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2m7jqpv5c6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 06 Sep 2018 13:33:00 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w86DWs8E013815 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 6 Sep 2018 13:32:54 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w86DWsmg024992; Thu, 6 Sep 2018 13:32:54 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 06 Sep 2018 06:32:53 -0700 From: Liran Alon To: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org Cc: jmattson@google.com, idan.brown@oracle.com, Liran Alon Subject: [PATCH 3/4] KVM: nVMX: Set vmcs02->vpid to vmcs12->vpid if L1 uses EPT Date: Thu, 6 Sep 2018 16:32:27 +0300 Message-Id: <20180906133228.118282-4-liran.alon@oracle.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180906133228.118282-1-liran.alon@oracle.com> References: <20180906133228.118282-1-liran.alon@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9007 signatures=668708 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=666 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1809060137 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If CPU use both VPID and EPT, TLB entries populated by CPU are tagged with both EPTP and VPID. Therefore, if L1 uses EPT, L2 TLB entries are separated from L1 TLB entries by the EPTP tags as vmcs02 use EPTP02 while vmcs01 use EPTP01. Thus, we don't need to make sure that vmcs02->vpid != vmcs01->vpid. Therefore, we can just set vmcs02->vpid to vmcs12->vpid. Reviewed-by: Mihai Carabas Reviewed-by: Darren Kenny Reviewed-by: Nikita Leshchenko Signed-off-by: Liran Alon Reviewed-by: Jim Mattson --- arch/x86/kvm/vmx.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index b97e0c5ccb46..98faba65c24a 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -12018,10 +12018,20 @@ static void prepare_vmcs02_full(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) vmcs_write64(GUEST_BNDCFGS, vmcs12->guest_bndcfgs); if (enable_vpid) { - if (nested_cpu_has_vpid(vmcs12) && vmx->nested.vpid02) - vmcs_write16(VIRTUAL_PROCESSOR_ID, vmx->nested.vpid02); - else - vmcs_write16(VIRTUAL_PROCESSOR_ID, vmx->vpid); + u16 vmcs02_vpid; + + if (nested_cpu_has_vpid(vmcs12)) { + if (nested_cpu_has_ept(vmcs12)) + vmcs02_vpid = vmcs12->virtual_processor_id; + else if (vmx->nested.vpid02) + vmcs02_vpid = vmx->nested.vpid02; + else + vmcs02_vpid = vmx->vpid; + } else { + vmcs02_vpid = vmx->vpid; + } + + vmcs_write16(VIRTUAL_PROCESSOR_ID, vmcs02_vpid); } /*