Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp764316ybm; Fri, 29 May 2020 11:32:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwL7k19qD9pWXaiPQsNKUbf05NyOLpO7kcEvDdPQcbLyO24nxpj9pK0recJROnKqJMsWmce X-Received: by 2002:a17:906:4d13:: with SMTP id r19mr8434291eju.45.1590777131665; Fri, 29 May 2020 11:32:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590777131; cv=none; d=google.com; s=arc-20160816; b=LkDEAiQePkfg8dub2meMlJoL0hZK5rdNTYll5W3QqcVib4R0DA3WymT4urUWn3+A2C cz+BOQQSAmczDE1pnPq8ETT4Y1QQf1S/R5KmQqYfj4n+exuUEJxV11Ncr/7GlKnFdhol wQ4c0fLuFT/+4k49jPpwjZDEyx22D8RDzPBVIkNGsruZHUa+5ILjHls93t3y8PwsxDsq H2VIX1siBTrg2GWoV2ozQHVdDsStemNOHx1LCJkjptyOMJqyP5gI4/FfZ5140/ETHybr K8Xclf15X1DMjbtTtTk5azqXZUh76uVeFfCjOjHJH8/RO6pCLvdByB7SsNa1QSt7atA9 1M1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:dkim-signature; bh=NnBhVkik+DPjxPNgherj6ybw5/R0wr5vT5i5/UWWsqY=; b=EkyvVnvHmQTPQlFtMermqh1vqJTHvDtmSak3jYCK+Raa6yEEyplWYHspk0vGkLKr+M XPhVckmySGGYD7aKYuUbxtuSuJtcfULILqPAHToSH+EtRQSgyEW7usKDyCxKJc5HyGU0 nf8hKW1tqP/DA/CrpjS7ChHNDxr8daS3L+nVrdnKNdbNQhpPBFPjpXFz40wJ1fCIrtWv hlp1hibc4S1NbHtRni/c3+eEcf+Ph8X4u++PAXVhN9h7w+QJJFU7R0HIv5Hj1YpkzAt1 2tmb94eSoo1dIoLDCQkpeT9jJ3+qbvb/rDG3cJGOQ/TMqUti3MOBAmJiroDHqyMMZuHM V7kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=z4CGYlD6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cx19si3085357edb.395.2020.05.29.11.31.48; Fri, 29 May 2020 11:32:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=z4CGYlD6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727062AbgE2S2B (ORCPT + 99 others); Fri, 29 May 2020 14:28:01 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:34894 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725839AbgE2S2A (ORCPT ); Fri, 29 May 2020 14:28:00 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 04TIIxgN027628; Fri, 29 May 2020 18:27:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=NnBhVkik+DPjxPNgherj6ybw5/R0wr5vT5i5/UWWsqY=; b=z4CGYlD6baoYOD1TzwdUW77pHp7Nua3J5PPrMFyyouDKpELHZ43Mxeiy2KT6Rbse0SmM HIHArTEPOibKStlmc2eONgPzXNbO9nLlIofScJo8Uk7MbUjZHRanWeRpZJdwmh/KDLYB wR/MaZP/j/P5dtwbOjbFDtbBLg67WNK16FHyVcq/CdY6iZBpG06yysdIIo2Y4rikPs7D qu7EJHrQYk0cJTyaDU+F4MShkjQXbljg49Ay1WavdKod35GQx9ez7GxYJDFcMmTgdSA7 x+Wk2dg/3pGai+OtCtekINr4/g1xUs+KzHEBJyMIw4d5c8rqPhUoEoobJ/e5ofdTdfUT uA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 318xe1uugn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 29 May 2020 18:27:58 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 04TIJBtZ113228; Fri, 29 May 2020 18:27:57 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 317ddus6tg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 May 2020 18:27:57 +0000 Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 04TIRuhG016282; Fri, 29 May 2020 18:27:56 GMT Received: from localhost.localdomain (/10.159.246.35) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 29 May 2020 11:27:56 -0700 Subject: Re: [PATCH 10/30] KVM: nSVM: extract preparation of VMCB for nested run To: Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org References: <20200529153934.11694-1-pbonzini@redhat.com> <20200529153934.11694-11-pbonzini@redhat.com> From: Krish Sadhukhan Message-ID: Date: Fri, 29 May 2020 11:27:55 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20200529153934.11694-11-pbonzini@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9636 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 mlxscore=0 phishscore=0 adultscore=0 suspectscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005290138 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9636 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 adultscore=0 cotscore=-2147483648 mlxscore=0 bulkscore=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1015 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005290138 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/29/20 8:39 AM, Paolo Bonzini wrote: > Split out filling svm->vmcb.save and svm->vmcb.control before VMRUN. > Only the latter will be useful when restoring nested SVM state. > > This patch introduces no semantic change, so the MMU setup is still > done in nested_prepare_vmcb_save. The next patch will clean up things. > > Signed-off-by: Paolo Bonzini > --- > arch/x86/kvm/svm/nested.c | 40 +++++++++++++++++++++++---------------- > 1 file changed, 24 insertions(+), 16 deletions(-) > > diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c > index fc0c6d1678eb..73be7af79453 100644 > --- a/arch/x86/kvm/svm/nested.c > +++ b/arch/x86/kvm/svm/nested.c > @@ -245,21 +245,8 @@ static void load_nested_vmcb_control(struct vcpu_svm *svm, > svm->vcpu.arch.tsc_offset += control->tsc_offset; > } > > -void enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa, > - struct vmcb *nested_vmcb) > +static void nested_prepare_vmcb_save(struct vcpu_svm *svm, struct vmcb *nested_vmcb) Not a big deal, but I feel that it helps a lot in readability if we keep the names symmetric. This one could be named prepare_nested_vmcb_save to match load_nested_vmcb_control that you created in the previous patch. Or load_nested_vmcb_control could be renamed to nested_load_vmcb_control to match the name here. > { > - bool evaluate_pending_interrupts = > - is_intercept(svm, INTERCEPT_VINTR) || > - is_intercept(svm, INTERCEPT_IRET); > - > - svm->nested.vmcb = vmcb_gpa; > - if (kvm_get_rflags(&svm->vcpu) & X86_EFLAGS_IF) > - svm->vcpu.arch.hflags |= HF_HIF_MASK; > - else > - svm->vcpu.arch.hflags &= ~HF_HIF_MASK; > - > - load_nested_vmcb_control(svm, &nested_vmcb->control); > - > if (nested_vmcb->control.nested_ctl & SVM_NESTED_CTL_NP_ENABLE) > nested_svm_init_mmu_context(&svm->vcpu); > > @@ -291,7 +278,10 @@ void enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa, > svm->vmcb->save.dr7 = nested_vmcb->save.dr7; > svm->vcpu.arch.dr6 = nested_vmcb->save.dr6; > svm->vmcb->save.cpl = nested_vmcb->save.cpl; > +} > > +static void nested_prepare_vmcb_control(struct vcpu_svm *svm, struct vmcb *nested_vmcb) > +{ > svm_flush_tlb(&svm->vcpu); > if (nested_vmcb->control.int_ctl & V_INTR_MASKING_MASK) > svm->vcpu.arch.hflags |= HF_VINTR_MASK; > @@ -321,6 +311,26 @@ void enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa, > */ > recalc_intercepts(svm); > > + mark_all_dirty(svm->vmcb); > +} > + > +void enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa, > + struct vmcb *nested_vmcb) > +{ > + bool evaluate_pending_interrupts = > + is_intercept(svm, INTERCEPT_VINTR) || > + is_intercept(svm, INTERCEPT_IRET); > + > + svm->nested.vmcb = vmcb_gpa; > + if (kvm_get_rflags(&svm->vcpu) & X86_EFLAGS_IF) > + svm->vcpu.arch.hflags |= HF_HIF_MASK; > + else > + svm->vcpu.arch.hflags &= ~HF_HIF_MASK; > + > + load_nested_vmcb_control(svm, &nested_vmcb->control); > + nested_prepare_vmcb_save(svm, nested_vmcb); > + nested_prepare_vmcb_control(svm, nested_vmcb); > + > /* > * If L1 had a pending IRQ/NMI before executing VMRUN, > * which wasn't delivered because it was disallowed (e.g. > @@ -336,8 +346,6 @@ void enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa, > enable_gif(svm); > if (unlikely(evaluate_pending_interrupts)) > kvm_make_request(KVM_REQ_EVENT, &svm->vcpu); > - > - mark_all_dirty(svm->vmcb); > } > > int nested_svm_vmrun(struct vcpu_svm *svm)