Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3785324pxj; Tue, 11 May 2021 11:48:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYDBEiUD25M2NQhYX71tuDA2pFd7KCUXaiu4+SqwxmsZzS9b7J6CuL0dE/mNHF73czX2dn X-Received: by 2002:aca:c413:: with SMTP id u19mr4636082oif.41.1620758904746; Tue, 11 May 2021 11:48:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620758904; cv=none; d=google.com; s=arc-20160816; b=WZKnXPy1GBknIc97fmCR2Xb7G0CJCWK3aPmSLMW9YrB/XCQP+YZOROF+OnYm80Umqi VgcidOMqYRKGca62fnr4/WwF3PWUhQwSZtG5XXowVAKmbO9WcINwf9OeU0ZWa7WZg2FO swH3a4qYM8aWPMsfTaDCUyeCjwfWF0+vAwWDg1H8cj/mCoNG2iLS6md0v036vwXJTyB4 U4Q66JNmD0Tm0qriFMuvmjDA6PH0w7+cYhzOCv/e9SXPi3N43qqvlKmQ0MySX/OeH2nn xjDAP1O+oHypM9mr5I8lm6hH8YARpk56kxmwqdMwaB+2xW/kxY2cIz1PNQqaADh5Jj1e NzqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=PUfD2hUn3KDMj/HYtm6y3Z3XD5hUc0CS8SfLuKj/HzM=; b=nvn+mI0akbp/eeGeJdJlrqAnzRrTOjveciT3mdcD5xNOV4lof/pZvGJqU/NTpgSpVV CgLKh+XJ5BtSxFUNIOolRd+hvFm0qK0ze0PGA9CrXt7DKl2/ag4FnzmUnvAzJJ64Sb8q Uv70eMQyZViyVqVtGL8HgxA2HF/J/iela3g8gJ/J1LG5wtOLBg1qVwcHnqHgDa9rE3hG TrUC8SV4A+hE/lCTfdodETVYmEYHAQyVgEB6KUdY11aEkM/qmFhTfItE3Y0Ol/fYb11S 4HJE9RTEZ+VLlFczas52pNIqmUI0UOI2Ss8PfjUKs8pTb4V9f5drRSnEQQ6x3tBLKd2Z 0HnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=hH8iZ5uG; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y8si3566663oto.201.2021.05.11.11.48.11; Tue, 11 May 2021 11:48:24 -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=@google.com header.s=20161025 header.b=hH8iZ5uG; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231868AbhEKSse (ORCPT + 99 others); Tue, 11 May 2021 14:48:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231693AbhEKSsc (ORCPT ); Tue, 11 May 2021 14:48:32 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A3B5C06174A for ; Tue, 11 May 2021 11:47:24 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id n16so11267407plf.7 for ; Tue, 11 May 2021 11:47:24 -0700 (PDT) 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; bh=PUfD2hUn3KDMj/HYtm6y3Z3XD5hUc0CS8SfLuKj/HzM=; b=hH8iZ5uGg4DljK1HEHhLdreVMW5K51visxVgKumGRH38RbTsi3BTytZLhStmDbQ4uF h53yWZqjuULTlImML+ZiT0MVhbrfviY0KnVR1MipAvU43rvHh4Y/1CpvF9jVlxa8d2hN 6KtOwEmXbdzHxwnpQ0Z5c49tNpWvzrZ2Fpj89ALnnKjQIqQcUzC6JktdGHwnSo1n7AA3 UHVT8j6ckH6x3ZPtj0xzBxA1kTk4wd7ASvHx8CgzuqGj9M8CjfT+cQJKfKg08r22Zs84 wqowq7p7x6pBqe4YACHao4OBFlFrFjh/1qycJKCDQzomPgmoKBhMyjhhCTaH9q/UHq85 Nxow== 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; bh=PUfD2hUn3KDMj/HYtm6y3Z3XD5hUc0CS8SfLuKj/HzM=; b=g43Yta0VRMOPK1ERk6uNFWB2fo8Z2pbaiKSzO80uAIe75rojdRJTcfIqb/7Pyd+iBM vaDkVcMg5nhapFG0hu8uTmq4+iDcaHtQCpQb2mLGHYf4H6cHz1+0vjTMBOxp89A7soTt UC3IGUVA29ZGEyG2M40BbvyrQGX7mtb9fQj3dEgerL0Qv/zIO4VPxwt4lK+ILsnUon+k YN2CQcPu4ya/vxhfEZ9h31irvpYsxXb0n2nH6tMXlY1nV6ek18Ij61E5dULbpTq40M/k O7eWYQ5z1zhwJDZ6IQlW8eqiwtJ8Z/APozuYR8mY5CJFC1fOkWjmd5IVGAWoArnNh2y+ cHsw== X-Gm-Message-State: AOAM5331WWFoiRTkSPJFBgJIurGgPcatwCdoVqSkB4HbFnNhMAAJNgg8 +nUl69o+G+F3T7nzRrxdZE+Gtg== X-Received: by 2002:a17:90a:390d:: with SMTP id y13mr9283273pjb.52.1620758843332; Tue, 11 May 2021 11:47:23 -0700 (PDT) Received: from google.com (240.111.247.35.bc.googleusercontent.com. [35.247.111.240]) by smtp.gmail.com with ESMTPSA id i8sm7089806pgt.58.2021.05.11.11.47.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 11:47:22 -0700 (PDT) Date: Tue, 11 May 2021 18:47:19 +0000 From: Sean Christopherson To: Ben Gardon Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Peter Xu , Peter Shier , Yulei Zhang , Wanpeng Li , Xiao Guangrong , Kai Huang , Keqian Zhu , David Hildenbrand Subject: Re: [PATCH v4 3/7] KVM: mmu: Refactor memslot copy Message-ID: References: <20210511171610.170160-1-bgardon@google.com> <20210511171610.170160-4-bgardon@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210511171610.170160-4-bgardon@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 11, 2021, Ben Gardon wrote: > Factor out copying kvm_memslots from allocating the memory for new ones > in preparation for adding a new lock to protect the arch-specific fields > of the memslots. > > No functional change intended. > > Reviewed-by: David Hildenbrand > Signed-off-by: Ben Gardon > --- > virt/kvm/kvm_main.c | 23 ++++++++++++++++------- > 1 file changed, 16 insertions(+), 7 deletions(-) > > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 6b4feb92dc79..9e106742b388 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -1306,6 +1306,18 @@ static struct kvm_memslots *install_new_memslots(struct kvm *kvm, > return old_memslots; > } > > +static size_t kvm_memslots_size(int slots) Can we call this kvm_calc_memslots_size()? This doesn't actually return the true size of a given memslots instance since the allocated size may be greater than the size computed by looking at used_slots. > +{ > + return sizeof(struct kvm_memslots) + > + (sizeof(struct kvm_memory_slot) * slots); > +} > + > +static void kvm_copy_memslots(struct kvm_memslots *from, > + struct kvm_memslots *to) > +{ > + memcpy(to, from, kvm_memslots_size(from->used_slots)); > +} > + > /* > * Note, at a minimum, the current number of used slots must be allocated, even > * when deleting a memslot, as we need a complete duplicate of the memslots for > @@ -1315,19 +1327,16 @@ static struct kvm_memslots *kvm_dup_memslots(struct kvm_memslots *old, > enum kvm_mr_change change) > { > struct kvm_memslots *slots; > - size_t old_size, new_size; > - > - old_size = sizeof(struct kvm_memslots) + > - (sizeof(struct kvm_memory_slot) * old->used_slots); > + size_t new_size; > > if (change == KVM_MR_CREATE) > - new_size = old_size + sizeof(struct kvm_memory_slot); > + new_size = kvm_memslots_size(old->used_slots + 1); > else > - new_size = old_size; > + new_size = kvm_memslots_size(old->used_slots); > > slots = kvzalloc(new_size, GFP_KERNEL_ACCOUNT); > if (likely(slots)) > - memcpy(slots, old, old_size); > + kvm_copy_memslots(old, slots); > > return slots; > } > -- > 2.31.1.607.g51e8a6a459-goog >