Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1083959imu; Wed, 23 Jan 2019 10:27:46 -0800 (PST) X-Google-Smtp-Source: ALg8bN5U1jypn4AddORWGJjncL6pUljc30QLItrmfikUfQOpuvdQ02ybEwg4BKy5S7jhOBNZUHMP X-Received: by 2002:a62:1212:: with SMTP id a18mr3122559pfj.217.1548268066813; Wed, 23 Jan 2019 10:27:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548268066; cv=none; d=google.com; s=arc-20160816; b=nScoGsaK31qH+OSdD72mux3y8eATYuHal1vjvSmkQJ6m+sIEQsBMJc9lUr4+jIL4/5 Rm47B9NfpyFmZy1dkz+1+ptZiVCoaLmnCx09CqIJ2paStDqjxj+PMV+UoWK4286saYYp ya1pMzsSCB23QbcSXWW4KUuBalZV74vwJl3V4LaqH/VzYCE+ia9ZrowMQQbAgcBfdkFt BW63IHLOIfvBFzjAi8MCWfsyGbjTi2tst2rz+CNEgPye0iMKB1rpb+24HD4seO3eFsCW HNMdMKvh3lNGJCbdrZEgdTQuiwTW7PD0kYDRtkbgxH8iH7FLzOQuMv/lcwKQF3O2PmT2 yF8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Bb8meiKX5UXwfPsIYWEkYs0yO3FDiFHyANgVbs990ww=; b=V/7PBIxojlv5uvutbJ3tQbNkA2Ip3UvPBw2X72ALl4xl01IIaE46Pj71tDv4tAP2qk sFt5cAqmMnfiyor5QfvhnpyoiWeDh1uu6wvIk4Q1EA3KKfDJJNklpWNzACChnl2C7OEW qXj1hEtEUqUPUn/s2dODZ1Y4YlR/Bcz/YvAAxtXAa273t8IMNAWyVwzwloJdDyBdp3cn jGTIPBqyy+R87b/T1F3uO0xidylZHoLHdTvVTRbpg8v1+owtwjiyelfuOOV1Nd0hrdjc VVi3ak2i0O9b1ftR6PTGqgGUh6CIh2MNonQtt+8iZRKBBLAHq6nhk7NNGCk6L+RyoIhE Y1bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=QY1mE+9+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w15si16915947plk.357.2019.01.23.10.27.23; Wed, 23 Jan 2019 10:27:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=QY1mE+9+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726225AbfAWSZv (ORCPT + 99 others); Wed, 23 Jan 2019 13:25:51 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:41305 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725987AbfAWSZu (ORCPT ); Wed, 23 Jan 2019 13:25:50 -0500 Received: by mail-pg1-f194.google.com with SMTP id m1so1430300pgq.8 for ; Wed, 23 Jan 2019 10:25:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Bb8meiKX5UXwfPsIYWEkYs0yO3FDiFHyANgVbs990ww=; b=QY1mE+9+b1mCNCD9b+247xj3qBpAhD43W1bw+JIabtY9bUOgnwZI+Tg5wY/m85XpPR 3KmKAbmhm2In9V9WnozM8mxvFWD+9mslGK5ejcA2lWA+cF92FURB8PqIoUPUIf2SpJN4 n5cV0myv1V4MUsM113hLBkYO3LICHsC0t16rVTi4vzVexFRp100UUN3jyoGa/0atHrOM ZpbVjr23pWx/pb2txXfcn44nde/fDfJFYqNRYcNwpTxPaK0MwE0HJ9ziizEBu92bNWrc G7QHfzOrOv+YsW3p3T8Q3j+kxn1Cm4paDDdxJk+qEb66RSKDvA/juYvh4XNgPb8wWKVQ oU5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Bb8meiKX5UXwfPsIYWEkYs0yO3FDiFHyANgVbs990ww=; b=On/0Qb+1Jaa7RbhDSShHrsmP27hZTOtVgzMTK4rpVzgQDPhMM9Wi785RagQGEYRrdL okIrWiGkZqlkFCHpCYkPe2x337jAy1Jf/4juokGlcdWliEq0IFNRWKEf5Wah/UbyidNX pFd36MUXt/R3idcCKXtwYDiWQAv1aCfLA7UYL2baI6kaukzecUXn9mMUcMmKi7R3QD9y br8C5R2B78mGa2XPuWDUdQdNfCsYKcdcJ7GkLXcRsNlzLXaXF81krkwkEQ36rO3wH0fc GfqhI4LeWDmS80r31dTCE5He5iJoqmqJpjkvFQqdnutJsxsnhQ1wiQ86+65UnU9w5QN1 Rf8Q== X-Gm-Message-State: AJcUukeYkfe0L1It5ncd9nR6eJjDYZCrOJMis6JaEl6Y//C/y7rR/Xuz RCY4+Hd9o+TjsdFhIJuqcdwLgQ== X-Received: by 2002:a63:fc05:: with SMTP id j5mr3014517pgi.434.1548267949323; Wed, 23 Jan 2019 10:25:49 -0800 (PST) Received: from google.com ([2620:15c:17:4:f0b1:8ff5:16a0:5f15]) by smtp.gmail.com with ESMTPSA id h185sm28003115pfg.143.2019.01.23.10.25.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Jan 2019 10:25:48 -0800 (PST) Date: Wed, 23 Jan 2019 10:25:40 -0800 From: Tom Roeder To: Paolo Bonzini 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 Subject: Re: [RFC PATCH] kvm: x86/vmx: Use kzalloc for cached_vmcs12 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 Content-Disposition: inline In-Reply-To: <2177074d-f610-0d86-7399-e63ba851346c@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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?