From patchwork Sun Mar 8 03:19:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Rientjes X-Patchwork-Id: 5961021 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 87194BF440 for ; Sun, 8 Mar 2015 03:19:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 61CE32034E for ; Sun, 8 Mar 2015 03:19:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 55A7F202EB for ; Sun, 8 Mar 2015 03:19:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751188AbbCHDTP (ORCPT ); Sat, 7 Mar 2015 22:19:15 -0500 Received: from mail-ig0-f180.google.com ([209.85.213.180]:44984 "EHLO mail-ig0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751030AbbCHDTO (ORCPT ); Sat, 7 Mar 2015 22:19:14 -0500 Received: by igdh15 with SMTP id h15so13143922igd.3 for ; Sat, 07 Mar 2015 19:19:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=date:from:to:cc:subject:message-id:user-agent:mime-version :content-type; bh=t2q5Tfa2ybhTBoO08fSMghKBnXm3l45QgsEL+00sWi0=; b=BKrsuSL6HUIgDH0Z9tg8nXeik7CC9DgwYsL0CZKoLfeM1soTOlvMlxWm+xmgnld/+c 2kntoQnyt9CAqvwoV8BPP1FVYx87qIce3I3eWka7GfxfJikxKNvz4f9dr54anqGLfm/2 un3sWa8E+0kre5l3JyBJLdRqcawancPolqh2K3GMS+c+ZP9fYulrloNLi7WgeoXO6iCQ zkATt2KTlFI5AYfPYfD/Sk1assrZRv8fePqIxSFIntVXOPvtBF0z1P2pH7Gte6Dih4Qf tIC73DGF8sqyWfLhuPFpHqgShJ3hEqDelc85bGqnFB7SarTYDtzjgwCGKONk3W0lBZBs E4+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:user-agent :mime-version:content-type; bh=t2q5Tfa2ybhTBoO08fSMghKBnXm3l45QgsEL+00sWi0=; b=dmQMAypun5ut5DXy+l1KqYOF5u6X5DmjEiBnCii+AlUzOMOBTAgWDNgZcX8e39wKPD vM/W5YX+UFQ9fIxr9E37UgUCUyq+ZtRAVqX9Kt1YqC3G6S/yDdKOil0Q57rPO228hSC4 1uT2+gegF/DBdJM+vq2XktTz127nJW65Z+aYpiT6n5kTCJJemWybFc7KDpa1BlDzynYX 1aEZQsNgmRmznC9qkbdJ0UqN0Mm0fB+mLFo+U/RcBT2zw1NRCm+N7resFRGKBqRj2Zgi KFI1/jzhoAL7c8Hn3S/JM6ZeGCp1I/YH9uWc6NQlzQob6HYvjXjviDtF1EU6cHHL3KK0 zgpw== X-Gm-Message-State: ALoCoQnTJF5bkPMGIwAFL686pvRjwgrnDmpy5RTBmW/4vOSTSNfRKtAgGzG58Wb/gzsogvN4PKAa X-Received: by 10.107.167.145 with SMTP id q139mr38656521ioe.16.1425784753329; Sat, 07 Mar 2015 19:19:13 -0800 (PST) Received: from [2620:0:1008:1101:a0e7:858f:fe1d:d33] ([2620:0:1008:1101:a0e7:858f:fe1d:d33]) by mx.google.com with ESMTPSA id b6sm3805735igb.15.2015.03.07.19.19.12 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 07 Mar 2015 19:19:12 -0800 (PST) Date: Sat, 7 Mar 2015 19:19:11 -0800 (PST) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Andrew Morton cc: Steffen Maier , Martin Schwidefsky , Heiko Carstens , Steve French , linux-kernel@vger.kernel.org, linux-cifs@vger.kernel.org, linux-s390@vger.kernel.org Subject: [patch] mm, mempool: do not allow atomic resizing Message-ID: User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Allocating a large number of elements in atomic context could quickly deplete memory reserves, so just disallow atomic resizing entirely. Nothing currently uses mempool_resize() with anything other than GFP_KERNEL, so convert existing callers to drop the gfp_mask. Signed-off-by: David Rientjes Acked-by: Steffen Maier --- drivers/s390/scsi/zfcp_erp.c | 4 ++-- fs/cifs/connect.c | 6 ++---- include/linux/mempool.h | 2 +- mm/mempool.c | 9 +++++---- 4 files changed, 10 insertions(+), 11 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/s390/scsi/zfcp_erp.c b/drivers/s390/scsi/zfcp_erp.c --- a/drivers/s390/scsi/zfcp_erp.c +++ b/drivers/s390/scsi/zfcp_erp.c @@ -738,11 +738,11 @@ static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act) return ZFCP_ERP_FAILED; if (mempool_resize(act->adapter->pool.sr_data, - act->adapter->stat_read_buf_num, GFP_KERNEL)) + act->adapter->stat_read_buf_num)) return ZFCP_ERP_FAILED; if (mempool_resize(act->adapter->pool.status_read_req, - act->adapter->stat_read_buf_num, GFP_KERNEL)) + act->adapter->stat_read_buf_num)) return ZFCP_ERP_FAILED; atomic_set(&act->adapter->stat_miss, act->adapter->stat_read_buf_num); diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -773,8 +773,7 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server) length = atomic_dec_return(&tcpSesAllocCount); if (length > 0) - mempool_resize(cifs_req_poolp, length + cifs_min_rcv, - GFP_KERNEL); + mempool_resize(cifs_req_poolp, length + cifs_min_rcv); } static int @@ -848,8 +847,7 @@ cifs_demultiplex_thread(void *p) length = atomic_inc_return(&tcpSesAllocCount); if (length > 1) - mempool_resize(cifs_req_poolp, length + cifs_min_rcv, - GFP_KERNEL); + mempool_resize(cifs_req_poolp, length + cifs_min_rcv); set_freezable(); while (server->tcpStatus != CifsExiting) { diff --git a/include/linux/mempool.h b/include/linux/mempool.h --- a/include/linux/mempool.h +++ b/include/linux/mempool.h @@ -29,7 +29,7 @@ extern mempool_t *mempool_create_node(int min_nr, mempool_alloc_t *alloc_fn, mempool_free_t *free_fn, void *pool_data, gfp_t gfp_mask, int nid); -extern int mempool_resize(mempool_t *pool, int new_min_nr, gfp_t gfp_mask); +extern int mempool_resize(mempool_t *pool, int new_min_nr); extern void mempool_destroy(mempool_t *pool); extern void * mempool_alloc(mempool_t *pool, gfp_t gfp_mask); extern void mempool_free(void *element, mempool_t *pool); diff --git a/mm/mempool.c b/mm/mempool.c --- a/mm/mempool.c +++ b/mm/mempool.c @@ -113,23 +113,24 @@ EXPORT_SYMBOL(mempool_create_node); * mempool_create(). * @new_min_nr: the new minimum number of elements guaranteed to be * allocated for this pool. - * @gfp_mask: the usual allocation bitmask. * * This function shrinks/grows the pool. In the case of growing, * it cannot be guaranteed that the pool will be grown to the new * size immediately, but new mempool_free() calls will refill it. + * This function may sleep. * * Note, the caller must guarantee that no mempool_destroy is called * while this function is running. mempool_alloc() & mempool_free() * might be called (eg. from IRQ contexts) while this function executes. */ -int mempool_resize(mempool_t *pool, int new_min_nr, gfp_t gfp_mask) +int mempool_resize(mempool_t *pool, int new_min_nr) { void *element; void **new_elements; unsigned long flags; BUG_ON(new_min_nr <= 0); + might_sleep(); spin_lock_irqsave(&pool->lock, flags); if (new_min_nr <= pool->min_nr) { @@ -145,7 +146,7 @@ int mempool_resize(mempool_t *pool, int new_min_nr, gfp_t gfp_mask) spin_unlock_irqrestore(&pool->lock, flags); /* Grow the pool */ - new_elements = kmalloc(new_min_nr * sizeof(*new_elements), gfp_mask); + new_elements = kmalloc(new_min_nr * sizeof(*new_elements), GFP_KERNEL); if (!new_elements) return -ENOMEM; @@ -164,7 +165,7 @@ int mempool_resize(mempool_t *pool, int new_min_nr, gfp_t gfp_mask) while (pool->curr_nr < pool->min_nr) { spin_unlock_irqrestore(&pool->lock, flags); - element = pool->alloc(gfp_mask, pool->pool_data); + element = pool->alloc(GFP_KERNEL, pool->pool_data); if (!element) goto out; spin_lock_irqsave(&pool->lock, flags);