Received: by 10.223.185.82 with SMTP id b18csp163826wrg; Thu, 8 Mar 2018 22:00:51 -0800 (PST) X-Google-Smtp-Source: AG47ELswUMlPa7vwvlh7T+/b4KXNn+MB5pynuSZy3ii06NgvGdNWL/xj9KA89ZTAJFZTN9YXkzLa X-Received: by 2002:a17:902:584c:: with SMTP id f12-v6mr26412612plj.374.1520575251005; Thu, 08 Mar 2018 22:00:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520575250; cv=none; d=google.com; s=arc-20160816; b=UgmVyWpR5eEpjhPHsxeqvCvThMoe3VHPT/tYyuOpRjPOp0QbZDCqtAWzk4k5Bh49Dt Gm53w3vzZNnidiR2Z6l6lrgsIkFm4loRwuNJrVeZniN838bmZWpX1psm8eZQxajANODC HqAfAe1+9CC3eVzobAAGz5telR2veWJabnIshFQI4F5386cV9AB+XSENZwJzTJCsOr33 CSaRJ5BMPoOgynfmgSfPpJ5lgo6A5f6vHEDb28XsODY1O2BIxOAnqbB9Tmo9svx6ZCpm t3FzI649YlMvRFFxivi+qealHiNWNU909hDNnx3QziNctHhSIGRFd/LhKlOLcXfpMFUu gHXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=Z9wC4DtB3ydCxa4u/X0ZOMazTsEsAl6Jt/aRjzR4l1o=; b=tGCmRpHGjtas2Ww2ZrBKHIbqIVZ32Wir/S69glTgyFIVH6C/73HJlmb64ijS4pLgYG 5hWoEcJ4FDl53a/vLlee7J2w0NTsq0eHx1aX4wYtMc1ztFm5uDhCQ5+nQm+11Q04BrUj 6JyNM7p7WizgvSF6hU65u9WGgnehI45V2UQPEUIEshg6BvlVsEAJZwCDbdzCd5f1n36a QJ7CDPAIoeNOJHqwMXO8L3oek6m1WfUy7rcqnLYoEZ2o+sty3St5Z5eAkfXDOsque3e8 faGSOoZdxH/IP+OzuatbQZixw5S1auNr2z76GOz7q1IowqIhp3rxWjPhsjNmEiVqV0nU 7xcA== ARC-Authentication-Results: i=1; mx.google.com; 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 f1-v6si278109pld.744.2018.03.08.22.00.36; Thu, 08 Mar 2018 22:00:50 -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; 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 S1751030AbeCIF7q (ORCPT + 99 others); Fri, 9 Mar 2018 00:59:46 -0500 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:36168 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750897AbeCIF7p (ORCPT ); Fri, 9 Mar 2018 00:59:45 -0500 X-IronPort-AV: E=Sophos;i="5.47,444,1515452400"; d="scan'208";a="317141657" Received: from abo-3-110-68.mrs.modulonet.fr (HELO [192.168.0.15]) ([85.68.110.3]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Mar 2018 06:59:43 +0100 Date: Fri, 9 Mar 2018 06:59:43 +0100 (CET) From: Julia Lawall X-X-Sender: jll@hadrien To: Matthew Wilcox cc: Kees Cook , Andrew Morton , Matthew Wilcox , Linux-MM , LKML , Kernel Hardening , cocci@systeme.lip6.fr, Himanshu Jha Subject: Re: [PATCH 2/2] mm: Add kvmalloc_ab_c and kvzalloc_struct In-Reply-To: <20180308230512.GD29073@bombadil.infradead.org> Message-ID: References: <20180214182618.14627-1-willy@infradead.org> <20180214182618.14627-3-willy@infradead.org> <20180308025812.GA9082@bombadil.infradead.org> <20180308230512.GD29073@bombadil.infradead.org> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 8 Mar 2018, Matthew Wilcox wrote: > On Thu, Mar 08, 2018 at 07:24:47AM +0100, Julia Lawall wrote: > > On Wed, 7 Mar 2018, Matthew Wilcox wrote: > > > On Wed, Mar 07, 2018 at 10:18:21PM +0100, Julia Lawall wrote: > > > > > Otherwise, yes, please. We could build a coccinelle rule for > > > > > additional replacements... > > > > > > > > A potential semantic patch and the changes it generates are attached > > > > below. Himanshu Jha helped with its development. Working on this > > > > uncovered one bug, where the allocated array is too large, because the > > > > size provided for it was a structure size, but actually only pointers to > > > > that structure were to be stored in it. > > > > > > This is cool! Thanks for doing the coccinelle patch! Diffstat: > > > > > > 50 files changed, 81 insertions(+), 124 deletions(-) > > > > > > I find that pretty compelling. I'll repost the kvmalloc_struct patch > > > imminently. > > > > Thanks. So it's OK to replace kmalloc and kzalloc, even though they > > didn't previously consider vmalloc and even though kmalloc doesn't zero? > > We'll also need to replace the corresponding places where those structs > are freed with kvfree(). Can coccinelle handle that too? This would be harder to do 100% reliably. Coccinelle would have to rely on the structure name or the structure type, if the free is in a different function. But I guess that the type should be mostly reliable, since all instances of allocations of the same type should be transformed in the same way. > > > There are a few other cases that use GFP_NOFS and GFP_NOWAIT, but I didn't > > transform those because the comment says that the flags should be > > GFP_KERNEL based. Should those be transformed too? > > The problem with non-GFP_KERNEL allocations is that vmalloc may have to > allocate page tables, which is always done with an implicit GFP_KERNEL > allocation. There's an intent to get rid of GFP_NOFS, but that's not > been realised yet (and I'm not sure of our strategy to eliminate it ... > I'll send a separate email about that). I'm not sure why anything's > trying to allocate with GFP_NOWAIT; can you send a list of those places? drivers/dma/fsl-edma.c: fsl_desc = kzalloc(sizeof(*fsl_desc) + sizeof(struct fsl_edma_sw_tcd) * sg_len, GFP_NOWAIT); drivers/dma/st_fdma.c: fdesc = kzalloc(sizeof(*fdesc) + sizeof(struct st_fdma_sw_node) * sg_len, GFP_NOWAIT); drivers/dma/pxa_dma.c: sw_desc = kzalloc(sizeof(*sw_desc) + nb_hw_desc * sizeof(struct pxad_desc_hw *), GFP_NOWAIT); julia