Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp507558pxb; Tue, 14 Sep 2021 02:37:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHHLmCt+qwqRuz72iXZ7X2Mag+vl19gRJSZcLO2p5hofvSpfMyOASB6riES5RI3fYrWDu/ X-Received: by 2002:a17:906:4758:: with SMTP id j24mr18014795ejs.46.1631612224298; Tue, 14 Sep 2021 02:37:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631612224; cv=none; d=google.com; s=arc-20160816; b=ZI+ddifrZhhDEgC6u4KBLAnrO4mDGyBfGQnLBBSPcBpp5aAiGv6p7hfaiu1gDAhIl9 JMgP2RBVTSkjFIFLhvZTv9xt0IZBK2sf4PkOf0N4X3AXyzkkesVUnEV5j9/bRMcPiGLY 3Du8vcOJzRIAorLoGhwqi3klZU5zk5RjlCHDvzD2llSV82IabSE0afZbTWXJ1DQXAi92 4on7JbrHk3LTLz1+bgMw9MB6Mkv9lneatPrC7KOe+DYKl/yGHYyoQWF1rCh/gQDnn1Ft rMkhjb6Fi24v8HMZDzP+c+WbOWO9heUz1qQHfGm4CW0Mp/Dt9pFtQeJ+F/1JdH3eDY9Y M+fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=51BjhGNRsIASk6oWqLFKhAN0ok8SXVqby17Dax7DoqY=; b=oSw7auxKPPJdS4uh5AqZTrm9UGtQjJb5E5zDAZ2bqK5w49q70jcL1vyVXZgV3XH74o Cuihpjp24+uoUiVRHX8C78jw1pnQmF+MqtCFGqm2HNQ+dICM+vtBiBD3kE0HzTENjzxi /b4D327Q2RpyJh2m11fRYnzowzfdyeBTeYxLKaI71p4B47BPACDpemgFRQPdEkePqCCY yjSO6XHG2z5tfnaakA1LIkKZ8e3deWsogsB3KoIDImeHcoQF72SPkMeklE2fhX/wda+k OxtQgBcXNO3fir0oiiDHy6uVLMyMZWyfU0VYzjbYj7k3uDFQZgbfclKD4cSx6/TciT8q gCAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YGo3Mv3k; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i18si12228971edc.541.2021.09.14.02.36.40; Tue, 14 Sep 2021 02:37:04 -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=@redhat.com header.s=mimecast20190719 header.b=YGo3Mv3k; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231156AbhINJgU (ORCPT + 99 others); Tue, 14 Sep 2021 05:36:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:41078 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230330AbhINJgN (ORCPT ); Tue, 14 Sep 2021 05:36:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631612096; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=51BjhGNRsIASk6oWqLFKhAN0ok8SXVqby17Dax7DoqY=; b=YGo3Mv3krXeCpah8PGXYjXW8q+kacR9IPqm4sZbjE0AsnttXfD2XR6do4S9xC/vymbC5EH FeYcYKOpoemuwIkQh10cGyXVnlwD+ug7QlggZfRKfSRW7QjRzqcMUfKP1x97TFuFkUkP+3 vetl+8zw4aRUgmIo7NDV3BtPMQnJbCE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-520-WOQz7cXmMwm8XUlpCfwUrA-1; Tue, 14 Sep 2021 05:34:54 -0400 X-MC-Unique: WOQz7cXmMwm8XUlpCfwUrA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6E4E5802923; Tue, 14 Sep 2021 09:34:52 +0000 (UTC) Received: from starship (unknown [10.35.206.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5CE877F3C; Tue, 14 Sep 2021 09:34:48 +0000 (UTC) Message-ID: Subject: Re: [RFC PATCH 3/3] nSVM: use svm->nested.save to load vmcb12 registers and avoid TOC/TOU races From: Maxim Levitsky To: Emanuele Giuseppe Esposito , kvm@vger.kernel.org Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org Date: Tue, 14 Sep 2021 12:34:47 +0300 In-Reply-To: References: <20210903102039.55422-1-eesposit@redhat.com> <20210903102039.55422-4-eesposit@redhat.com> <21d2bf8c4e3eb3fc5d297fd13300557ec686b625.camel@redhat.com> <73b5a5bb-48f2-3a08-c76b-a82b5b69c406@redhat.com> <9585f1387b2581d30b74cd163a9aac2adbd37a93.camel@redhat.com> <2b1e17416cef1e37f42e9bc8b2283b03d2651cb2.camel@redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2021-09-14 at 11:24 +0200, Emanuele Giuseppe Esposito wrote: > > On 14/09/2021 11:12, Maxim Levitsky wrote: > > On Tue, 2021-09-14 at 12:02 +0300, Maxim Levitsky wrote: > > > On Tue, 2021-09-14 at 10:20 +0200, Emanuele Giuseppe Esposito wrote: > > > > On 12/09/2021 12:42, Maxim Levitsky wrote: > > > > > > > > > > > > - if (!nested_vmcb_valid_sregs(vcpu, &vmcb12->save) || > > > > > > + if (!nested_vmcb_valid_sregs(vcpu, &svm->nested.save) || > > > > > > !nested_vmcb_check_controls(vcpu, &svm->nested.ctl)) { > > > > > If you use a different struct for the copied fields, then it makes > > > > > sense IMHO to drop the 'control' parameter from nested_vmcb_check_controls, > > > > > and just use the svm->nested.save there directly. > > > > > > > > > > > > > Ok, what you say in patch 2 makes sense to me. I can create a new struct > > > > vmcb_save_area_cached, but I need to keep nested.ctl because 1) it is > > > > used also elsewhere, and different fields from the one checked here are > > > > read/set and 2) using another structure (or the same > > > > > > Yes, keep nested.ctl, since vast majority of the fields are copied I think. > > > > But actually that you mention it, I'll say why not to create vmcb_control_area_cached > > as well indeed and change the type of svm->nested.save to it. (in a separate patch) > > > > I see what you mean that we modify it a bit (but we shoudn't to be honest) and such, but > > all of this can be fixed. > > So basically you are proposing: > > struct svm_nested_state { > ... > struct vmcb_control_area ctl; // we need this because it is used > everywhere, I think > struct vmcb_control_area_cached ctl_cached; > struct vmcb_save_area_cached save_cached; > ... > } > > and then > > if (!nested_vmcb_valid_sregs(vcpu, &svm->nested.save_cached) || > !nested_vmcb_check_controls(vcpu, &svm->nested.ctl_cached)) { > > like that? > > Or do you want to delete nested.ctl completely and just keep the fields > actually used in ctl_cached? I would do it this way: struct svm_nested_state { ... /* cached fields from the vmcb12 */ struct vmcb_control_area_cached ctl; struct vmcb_save_area_cached save; ... }; Best regards, Maxim Levitsky > > > Also, note that as I am trying to use vmcb_save_area_cached, it is worth > noticing that nested_vmcb_valid_sregs() is also used in > svm_set_nested_state(), so it requires some additional little changes. > > Thank you, > Emanuele > > > The advantage of having vmcb_control_area_cached is that it becomes impossible to use > > by mistake a non copied field from the guest. > > > > It would also emphasize that this stuff came from the guest and should be treated as > > a toxic waste. > > > > Note again that this should be done if we agree as a separate patch. > > > > > Best regards, > > > Maxim Levitsky > > > > > > > > > > vmcb_save_area_cached) in its place would just duplicate the same fields > > > > of nested.ctl, creating even more confusion and possible inconsistency. > > > > > > > > Let me know if you disagree. > > > > > > > > Thank you, > > > > Emanuele > > > >