From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tom Roeder Subject: Re: [RFC PATCH] kvm: x86/vmx: Use kzalloc for cached_vmcs12 Date: Wed, 23 Jan 2019 10:25:40 -0800 Message-ID: <20190123182540.GA160275@google.com> References: <6f79d9be-fa76-3a06-2612-f44f3a18ece7@redhat.com> <20190114234728.49239-1-tmroeder@google.com> <20190115024304.GD5141@linux.intel.com> <2177074d-f610-0d86-7399-e63ba851346c@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Sean Christopherson , Radim =?utf-8?B?S3LEjW3DocWZ?= , Liran Alon , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+ded1696f6b50b615b630@syzkaller.appspotmail.com To: Paolo Bonzini Return-path: Content-Disposition: inline In-Reply-To: <2177074d-f610-0d86-7399-e63ba851346c@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On Tue, Jan 15, 2019 at 11:15:51AM +0100, Paolo Bonzini wrote: > On 15/01/19 03:43, Sean Christopherson wrote: > >> - vmx->nested.cached_vmcs12 = kmalloc(VMCS12_SIZE, GFP_KERNEL); > >> + vmx->nested.cached_vmcs12 = kzalloc(VMCS12_SIZE, GFP_KERNEL); > >> if (!vmx->nested.cached_vmcs12) > >> goto out_cached_vmcs12; > > Obviously not your code, but why do we allocate VMCS12_SIZE instead of > > sizeof(struct vmcs12)? I get why we require userspace to reserve the > > full 4k, but I don't understand why KVM needs to allocate the reserved > > bytes internally. > > It's just cleaner and shorter code to copy everything in and out, > instead of having to explicitly zero the slack. Could you please clarify? I don't see code that copies everything in and out, but it depends on what you mean by "everything". In the context of this email exchange, I assumed that "everything" was "all 4k (VMCS12_SIZE)". But it looks to me like the code doesn't copy 4k in and out, but rather only ever copies sizeof(struct vmcs12) in and out. The copy_from_user and copy_to_user cases in nested.c use sizeof(*vmcs12), which is sizeof(struct vmcs12). So maybe can switch to allocating sizeof(struct vmcs12). Is this correct, or is there some other reason to allocate the larger size?