Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp501496pxb; Tue, 14 Sep 2021 02:26:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEOamkdFLaEJVbrspqJo6ug7+8BNaHV0bdpLB9+1MuAZwxlqA6QQ/r1cKbqG3TsdbUYATq X-Received: by 2002:a05:6638:1926:: with SMTP id p38mr13753158jal.18.1631611609709; Tue, 14 Sep 2021 02:26:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631611609; cv=none; d=google.com; s=arc-20160816; b=UywGcWET4jVaqaK7hbzISBuPzLURLiscepbi4+3icpnA8Bn2Uzm0BhXpHTPpla94sP zqHIobmbxks850bfqsGMulZ5OE0MhgHjCa0W2hPPMDzx9yj5y8l9zIq2qyjBI5KDdYdk vdWDfG8cXExURCHn9TqcqtFrTGdSilY00k0Sacd9qBAtt8q5d+PEgGpmuIRrlUHC1/eD rm8QBIA28K9DImU3GbCSCz5EYvPhSAV9jiwkXtmt29YQn6liApU1qIXkhVR0T0NIL8FR TlTkx0eH/uwvUPCzF9EPEwuDbuCnPKXD6f5QKFb/EWMvVtqfnUT3UN1ZraYJ0NRqof/U oFTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=6eUT5aaraqAWkuE8C9hQZ8wEwgwIbUTUok3BPR1VmCk=; b=nPKHLMG837XT8i+0Lkjjxtk6SM10Aq9NWXQmsGiMltYrpTlDAzxXLlupN9Qxq45CZ8 dkeMutosc2K+Mvv91/GRcANGu1SXnBjI+8rBc+2pInTW5s/l6ScCneEbLE0mkGX6FfWU NY3cwZKjK2rm2GzXsiOWovA96senRXTWhZs6GBEazqj6YsaFVyq+ns/1T5ANl0JeHIoQ mKcoilNGHJWY2GOoiQBh6naMeUUZC9KYjXmR3nbxmufaSU/c9wE0fw5cvAEnh6VX/h3O QOEWwwK0Sy9fk8m/hnZ0dwrBTZl9o0dlD5UngJK0/yL0YfVzShrMMeSG1HHlM+XDj53l ByGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ik+ETu6B; 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 k1si9121402ilo.14.2021.09.14.02.26.37; Tue, 14 Sep 2021 02:26:49 -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=Ik+ETu6B; 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 S230122AbhINJZ6 (ORCPT + 99 others); Tue, 14 Sep 2021 05:25:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:58790 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229551AbhINJZ5 (ORCPT ); Tue, 14 Sep 2021 05:25:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631611479; 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=6eUT5aaraqAWkuE8C9hQZ8wEwgwIbUTUok3BPR1VmCk=; b=Ik+ETu6B2BpHO3wOf2F7J2KABefBimfPqZ7h/kVvLV8Jy6XeWLYR0tRf6lF2mWa6+yqcLV LG2hH1uvjo7JbiJoPlO4a2fVeLEVz3PurGVbaCkN0XVqCKR6qiz/IPWb4qFLQ6jWskE+T0 s1PBqJv4M6bC/fxoiUJR43ie33UGZHM= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-212-cpkNzd4_MsK1d48mvuZeJg-1; Tue, 14 Sep 2021 05:24:38 -0400 X-MC-Unique: cpkNzd4_MsK1d48mvuZeJg-1 Received: by mail-ed1-f72.google.com with SMTP id z17-20020a05640240d100b003cac681f4f4so6417503edb.21 for ; Tue, 14 Sep 2021 02:24:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=6eUT5aaraqAWkuE8C9hQZ8wEwgwIbUTUok3BPR1VmCk=; b=u2O+bHy3f/tnGmDQvvwSAz4FWOcJUtnwSC9HnLG6QT0/WNSst/yd9RIQbKhAdoIwE+ EccDJWuNrABZrIQyuniTnV2LcskY+ub83axYA0cLuMNrR4jPRJKBsTd+XMxgPwv1RAud FPbta/pdi78VlU4bVF0r4dW5a92+bG9/ygR6ob1h+i+62Y+70elK6IntZ6QIIy5y3hvS ygYkLJuaRsNmuIY+fTGTs8Oszrz5I5HsXBaEDKvrbh+2t/Nto8dVZGtIW/0icgrvgSWy PDESjmSXtZOWed3L7X9R1VfjTlAjFgnyXfuBDINnoRj2WiPTA9CTt8mwMvLZxmX9tZY9 KGQw== X-Gm-Message-State: AOAM5326j7k30PTUBgelUxXe9ewQYQ0RSE55xXzIFc1RwlxN72KAb6a0 2gZ49BYOjY9rlz9hSS9+zO1mFDVgYS5BllvP9Ket/3Rl0fIm94Ek3wvzqFYKzhuMOmMnQgvCR0k Jc8YdK9yslqW9jjsSBRt5zT+4gE3ODcFQQiUH4Yaw6Gv2Vc9HPfXb8Njcte3+QBmZoj4cdD/8qv 5I X-Received: by 2002:a17:906:3ce2:: with SMTP id d2mr17979078ejh.410.1631611477096; Tue, 14 Sep 2021 02:24:37 -0700 (PDT) X-Received: by 2002:a17:906:3ce2:: with SMTP id d2mr17979048ejh.410.1631611476892; Tue, 14 Sep 2021 02:24:36 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:4:31cb:e591:1e1e:abde:a8f1]) by smtp.gmail.com with ESMTPSA id q19sm5263011edc.74.2021.09.14.02.24.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Sep 2021 02:24:36 -0700 (PDT) Subject: Re: [RFC PATCH 3/3] nSVM: use svm->nested.save to load vmcb12 registers and avoid TOC/TOU races To: Maxim Levitsky , 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 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> From: Emanuele Giuseppe Esposito Message-ID: Date: Tue, 14 Sep 2021 11:24:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <2b1e17416cef1e37f42e9bc8b2283b03d2651cb2.camel@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? 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 >>> > >