Received: by 10.223.185.116 with SMTP id b49csp1056447wrg; Fri, 23 Feb 2018 11:06:45 -0800 (PST) X-Google-Smtp-Source: AH8x225Q8cj4ZZYiBw3ayvenmKaoTr/aTDcg7U9i7ljGUHS4cKfgxUe+BqM4LQti2cvEJPqlqqwp X-Received: by 10.101.73.197 with SMTP id t5mr2220491pgs.426.1519412805204; Fri, 23 Feb 2018 11:06:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519412805; cv=none; d=google.com; s=arc-20160816; b=iM8DrYFpt8dXkO3drK6mpNZybgv+xFE6XjvhM79RkntvYPfdZcom5+Hzf9kgYYheS6 Du6SmQbW7lnZymdjSL7G4AP2DhuTbJv2aGv8tdzsyX5MKQViDA+PSr6L8b1BlfdM1V78 Iirr3s6eqf1rFsXekm3brsDTMO5ZFNjF2i4ShJ1xatJM1bxdTS15HgQjcsIzRQeJDbLz NGaRgmvnfbZUW8MOJu26Hz19PuVLPIoPQTBi2m0B2eQkQQqJ+JvuYMT/sC3y3ZVJy+xq 7CbtpgROkJ3bagyVDZyV1ZF0Q71n7wni+0MFQNtDL0PvXbypyChS/8qQCbQznuDlCiPg ogHQ== 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 :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=toCXj+rF+X0RZdW5hDXRNiCqiMJssosKh+NIrdzUtwM=; b=Ep/HhKfZD8qmbMzHHbWg1x8I+jfjQINqjqs5slw4yL8GuJXExxiUSjkbQvlpumQRVW d8PHAC/r3WTc+zRtwn7X4TIiIrq9BZo9zDNOn03j4kuYGvJhW0947QStkfy7y/FZEzYK acjsJ1JIImxgU5z+qoqOGauVfMNz9VKRHo7h8nb0Q/LOikU6HeV53bL8e93lsicSSKjR rR80+e1XHvQD01KnFTorpb1NcOM+ZNmpOM/hRDqtZdxejBEGxU2Y6oxYDOPtpqeI3Kgg YhreqfguRpX5zaE2x+hdFiLj33y95LxWRdof/5s5eVDWNSCSvjBOfcc2MjqPBoR5LfLj y0uQ== 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 11-v6si2159985plc.376.2018.02.23.11.06.30; Fri, 23 Feb 2018 11:06:45 -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 S965501AbeBWS5y (ORCPT + 99 others); Fri, 23 Feb 2018 13:57:54 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:50336 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965490AbeBWS5w (ORCPT ); Fri, 23 Feb 2018 13:57:52 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id B209F107C; Fri, 23 Feb 2018 18:57:51 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+e4d4f9ddd4295539735d@syzkaller.appspotmail.com, Jason Wang , "Michael S. Tsirkin" , "David S. Miller" Subject: [PATCH 4.15 03/45] ptr_ring: try vmalloc() when kmalloc() fails Date: Fri, 23 Feb 2018 19:28:42 +0100 Message-Id: <20180223170715.783010673@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170715.197760019@linuxfoundation.org> References: <20180223170715.197760019@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jason Wang commit 0bf7800f1799b5b1fd7d4f024e9ece53ac489011 upstream. This patch switch to use kvmalloc_array() for using a vmalloc() fallback to help in case kmalloc() fails. Reported-by: syzbot+e4d4f9ddd4295539735d@syzkaller.appspotmail.com Fixes: 2e0ab8ca83c12 ("ptr_ring: array based FIFO for pointers") Signed-off-by: Jason Wang Acked-by: Michael S. Tsirkin Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/linux/ptr_ring.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) --- a/include/linux/ptr_ring.h +++ b/include/linux/ptr_ring.h @@ -451,11 +451,14 @@ static inline int ptr_ring_consume_batch __PTR_RING_PEEK_CALL_v; \ }) +/* Not all gfp_t flags (besides GFP_KERNEL) are allowed. See + * documentation for vmalloc for which of them are legal. + */ static inline void **__ptr_ring_init_queue_alloc(unsigned int size, gfp_t gfp) { if (size * sizeof(void *) > KMALLOC_MAX_SIZE) return NULL; - return kcalloc(size, sizeof(void *), gfp); + return kvmalloc_array(size, sizeof(void *), gfp | __GFP_ZERO); } static inline void __ptr_ring_set_size(struct ptr_ring *r, int size) @@ -588,7 +591,7 @@ static inline int ptr_ring_resize(struct spin_unlock(&(r)->producer_lock); spin_unlock_irqrestore(&(r)->consumer_lock, flags); - kfree(old); + kvfree(old); return 0; } @@ -628,7 +631,7 @@ static inline int ptr_ring_resize_multip } for (i = 0; i < nrings; ++i) - kfree(queues[i]); + kvfree(queues[i]); kfree(queues); @@ -636,7 +639,7 @@ static inline int ptr_ring_resize_multip nomem: while (--i >= 0) - kfree(queues[i]); + kvfree(queues[i]); kfree(queues); @@ -651,7 +654,7 @@ static inline void ptr_ring_cleanup(stru if (destroy) while ((ptr = ptr_ring_consume(r))) destroy(ptr); - kfree(r->queue); + kvfree(r->queue); } #endif /* _LINUX_PTR_RING_H */