Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp592366pxb; Tue, 14 Sep 2021 04:42:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEVbmAyUDPChbHbISSJbyDA3zzb2BHtrQwUflvEQXdbF4ylOFw1FOtsqxG65yk1RXl73P8 X-Received: by 2002:a17:906:718e:: with SMTP id h14mr7928087ejk.365.1631619734516; Tue, 14 Sep 2021 04:42:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631619734; cv=none; d=google.com; s=arc-20160816; b=dle5ONpI88o4ybyCP7zdBRhGsj/lec5q8ry4imToaYgjKR23EE8Zp2rINWJzaHyABV nQv3OokeEPeV5WBJXDOS23E/2GvdrlFdsrEhEPUzcM0YtxeF4DRsn5DrkbQkOpuMFxUb RUPIyHuMNViDZFuIdGaAF0hsa/tQcTQr4w0f/IAh9u85IEgkO/h0qpUzI0Zy64Ips8At S0DOkX5TyfkQ3gkj+uYLdlBVNdHvNopqUnJze5t9ult4JZH4Bhe4urNE5vv5xlfxZ5Lu 2Prh7m6L5un1q1qy3oYlZ1KOsgMOIBGYhdM1g4FGKOrBARH8CG54vZXUdmo4CVH+1PyI I3Jw== 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=VXsGLVph1NbqQ2nkvDoWH9B2JiDcc6lqU3jEfo1REJk=; b=BQqX4ANPfJHeQdwWSxR2BL5I1MH7LREocVt2+sXOoH1gyAvMpm2icfF+v5pEMF/X0d /4DMrDJQi8GSNwlHFKcdO6RkiMIe34IxF/D/NHjgXIN+DmHqLE1b+0GEmq25Wl1aHrBe ihs8GL7bkZkOc8joFhgFBLK3o6X1gft5OrzrZtZfjU7n7KDDkt6qhxz18+f5is7vxYe8 NIxSRFc4en4cRmPo3LhkrJs2K0SECu+DtW6X/CX8VWhchmgoHOI3WssYNYGXqK1YRfEG XHSUbmvw4muooXcE3bFYrkUNCZWNy3anB9WtP64d7f0Cj4pTgd21OU/oSljNAOxbkQsC f3Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="SWLmyt/k"; 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 l20si10098287ejn.131.2021.09.14.04.41.50; Tue, 14 Sep 2021 04:42:14 -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="SWLmyt/k"; 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 S232388AbhINLk5 (ORCPT + 99 others); Tue, 14 Sep 2021 07:40:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:57605 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232418AbhINLkx (ORCPT ); Tue, 14 Sep 2021 07:40:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631619575; 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=VXsGLVph1NbqQ2nkvDoWH9B2JiDcc6lqU3jEfo1REJk=; b=SWLmyt/kaSxpj4MLSWPnV9hKO8tEBoiocDkndHhrqdufWdoI+3xW0YmSR242T8d3e0O9Rh 2Xbr/h2kBNAuWN6dABimbyur9/WxHRyblAu2Q6s2tS47K7v3OeUxwtVKGrw3GLZrmJyH9h B2aVJ+HLAbhTIJ6imDM18qouvZRQWU0= 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-456-WrrSKas9MgCaVgh6GAv1lQ-1; Tue, 14 Sep 2021 07:39:32 -0400 X-MC-Unique: WrrSKas9MgCaVgh6GAv1lQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 498B71811EC1; Tue, 14 Sep 2021 11:39:30 +0000 (UTC) Received: from starship (unknown [10.35.206.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16CA81002388; Tue, 14 Sep 2021 11:39:24 +0000 (UTC) Message-ID: <5fec07dfcfd53421293c3814796f1aa4add4a126.camel@redhat.com> 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 14:39:23 +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.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2021-09-14 at 12:52 +0200, Emanuele Giuseppe Esposito wrote: > > 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; > > ... > > }; > > > > > > The only thing that requires a little bit of additional work when > applying this is svm_get_nested_state() (and theoretically > svm_set_nested_state(), in option 2). In this function, nested.ctl is > copied in user_vmcb->control. But now nested.ctl is not anymore a > vmcb_control_area, so the sizes differ. > > There are 2 options here: > 1) copy nested.ctl into a full vmcb_control_area, and copy it to user > space without modifying the API. The advantage is that the API is left > intact, but an additional copy is required. Thankfully there KVM_GET_NESTED_STATE is not performance critical at all, so a copy isn't that big problem, other that it is a bit ugly. Ugh.. > > 2) modify KVM_GET_NESTED_STATE and KVM_SET_NESTED_STATE to handle > vmcb_control_area_cached. Advantage is that there is a lightweight copy > + the benefits explained by you in the previous email (no unset field). That would break the KVM_GET_NESTED_STATE ABI without a very good reason, especially since some of the currently unused fields in the ctl (there are I think very few of them), might became used later on, needing to break the ABI again. Best regards, Maxim Levitsky > > I am not sure which one is the preferred way here. > > Thank you, > Emanuele >