Received: by 10.223.185.116 with SMTP id b49csp1140554wrg; Wed, 14 Feb 2018 12:14:56 -0800 (PST) X-Google-Smtp-Source: AH8x226fi5ukd3NTD4SsMtcoqcbol7vUWbmINW2oSYCRdsxYUVdhU/dIYiSAyLlJQFNCerDtNJhq X-Received: by 10.101.72.4 with SMTP id h4mr174703pgs.386.1518639295967; Wed, 14 Feb 2018 12:14:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518639295; cv=none; d=google.com; s=arc-20160816; b=L9zb3Vj9eEuWSHyyVCE98M09jGoHnhA12Ock/K1wHXOiwVZT4+eCgCM6rJAKQqUFm3 asKc0f9HBXjdVBnTbqHoKkkvgonousULYFeLNB5VMb+qcLG9TKBUUTu8mkT+QAPil5XH pN4GfjCNcNF2YoylP9Lgd/OdAvT+YzNkjtmQ5kbvDh8TO+zIB3JZy5GZ8CgnlOY6mp1Z mpxqYFOSt/oHpVtPmTWHeMtZjMn9f2EWUjxY2w9KyxKPOlDbpkDkdn1EV0tfEo0eQjIA lIMtz9llz8BBcgR7LHX2k5wNR5uoQNtXpEyMurlpm4sm9wMLD7pRMyF9HfY2LYuB1iCj Vzlw== 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:arc-authentication-results; bh=HMbY14q2gYyQ3xZ9ZFfxFBGqZ3oA2aGG88VGoas1jWQ=; b=c+b71ZFm7et7gpE4aw62guZyQ3YS5TR246ZKpF6+7WhkGzdaUSJDb98Wzpn/8R+vJc 8JtkDrJs1qiiqTNYH/tJWC9Ste5XoFHT3w1JXi1I45lwrhWAvHd17OE7z1i8bUbf6msD WNmQEQ7hEqThXdfOctnR13+eiszf9qBfrmTPCfN496qNN7ZWU26L7lDWJ8pzRzo9vN1/ XRAUffGtQdp6cjXGyzAKUJ4YkbI6fOXLHAm1zSfv+SX/A/8WnD6nB0RayjfsS5XJSzlq 1wS/D2e+QKSqXC3fFiEWHx09ynHcBRwXO+tm70MDK9JdpeHQeH04qd4jaIHiK0ZVlNnL wTzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=n9UrC9FQ; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 13si242043pfk.28.2018.02.14.12.14.41; Wed, 14 Feb 2018 12:14:55 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=n9UrC9FQ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031868AbeBNUOF (ORCPT + 99 others); Wed, 14 Feb 2018 15:14:05 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:47612 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030369AbeBNUOD (ORCPT ); Wed, 14 Feb 2018 15:14:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=HMbY14q2gYyQ3xZ9ZFfxFBGqZ3oA2aGG88VGoas1jWQ=; b=n9UrC9FQxUPcZ8IqY7dLKSh0n IXCzeSctuxokjSurb7o6xZeHyJegvAGFSqZJd0gKYyBu68lw1Now8OG8PPVpe1krR2y7X0VAzpEXo UxSmFRBxoweJHaalgCRPrMhJdqMhodaV+J+KdfGTQIwO5//n8AtqWhJ+Fb3P1qhubyi86PXLWZ1C3 3O/SViVqckJRuO8YmwQFbr2qFnL6LlurRSRc9tMBuIQWbJNq1hYaguhBPQe5VdRI8PgylqSbAkjtc lH6MEuZldgBk0PTFpvGt5a3cySkFEoDtXpwudIo7B7yyERWZkF3f8BjLrmdUycvmSs9+JwlagDlqe zRiJNpXvQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.89 #1 (Red Hat Linux)) id 1em3RJ-00040q-13; Wed, 14 Feb 2018 20:14:01 +0000 Date: Wed, 14 Feb 2018 12:14:00 -0800 From: Matthew Wilcox To: Christopher Lameter Cc: Andrew Morton , Matthew Wilcox , linux-mm@kvack.org, Kees Cook , linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com Subject: Re: [PATCH 2/2] mm: Add kvmalloc_ab_c and kvzalloc_struct Message-ID: <20180214201400.GD20627@bombadil.infradead.org> References: <20180214182618.14627-1-willy@infradead.org> <20180214182618.14627-3-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 14, 2018 at 01:55:59PM -0600, Christopher Lameter wrote: > On Wed, 14 Feb 2018, Matthew Wilcox wrote: > > > +#define kvzalloc_struct(p, member, n, gfp) \ > > + (typeof(p))kvzalloc_ab_c(n, \ > > + sizeof(*(p)->member) + __must_be_array((p)->member), \ > > + offsetof(typeof(*(p)), member), gfp) > > + > > Uppercase like the similar KMEM_CACHE related macros in > include/linux/slab.h?> Do you think that would look better in the users? Compare: @@ -1284,7 +1284,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m) return -EOPNOTSUPP; if (mem.nregions > max_mem_regions) return -E2BIG; - newmem = kvzalloc(size + mem.nregions * sizeof(*m->regions), GFP_KERNEL); + newmem = kvzalloc_struct(newmem, regions, mem.nregions, GFP_KERNEL); if (!newmem) return -ENOMEM; @@ -1284,7 +1284,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m) return -EOPNOTSUPP; if (mem.nregions > max_mem_regions) return -E2BIG; - newmem = kvzalloc(size + mem.nregions * sizeof(*m->regions), GFP_KERNEL); + newmem = KVZALLOC_STRUCT(newmem, regions, mem.nregions, GFP_KERNEL); if (!newmem) return -ENOMEM; Making it look like a function is more pleasing to my eye, but I'll change it if that's the only thing keeping it from being merged.