From patchwork Tue Sep 5 18:46:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 810251 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="OFIrVIh/"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xmwfh6h6Sz9s8J for ; Wed, 6 Sep 2017 04:46:36 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752867AbdIESqf (ORCPT ); Tue, 5 Sep 2017 14:46:35 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:37171 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751863AbdIESqb (ORCPT ); Tue, 5 Sep 2017 14:46:31 -0400 Received: by mail-pg0-f65.google.com with SMTP id 63so484045pgc.4; Tue, 05 Sep 2017 11:46:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:cc:date:in-reply-to:references :mime-version:content-transfer-encoding; bh=rFftfXG7bapwkcjxuMBmFEI8clZtQD854pyEwtHHg7o=; b=OFIrVIh/Cb53Zoeu+imx+7rCOVOWaWRibXK9K2Fju6Y5fyW9paltIR5AVV+Pb7QRbV M5bqmJk6N8AHDExLATukyBncX9fT7rCt3SWsDHBivzI3SC4I/HIGRfUXVrTVxh44UGvS SAzex2Ifo0d7RgG4x42e4zkKpLWNHnIw9cge8IqD5oGiW7+KnbeOG3ZWbJG0KHmUzTQK MOevCh9z3kLRcFXQlbLjcX9Ft/gB7XUZKLGTaysYkpqTkcyk9TU26o7A1uDTuK/N/hnM 09nlR4bsQMPiYM3s6LburW78M2GOhR6j9d2bRy60H38v4my34bum+i5cRIDO9EoHEQJo BVxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:mime-version:content-transfer-encoding; bh=rFftfXG7bapwkcjxuMBmFEI8clZtQD854pyEwtHHg7o=; b=CtLDzPImwIjeklxf6h2Qc/bdw6JvlnXpWLajHsNY7U5IAE1nsdRmxpmFA2uwf8sOA9 nBKNLFNUebRcaYjmvfj/Dm6yMpaRgc+hps1vqo3dDDxFSDl8h2uJuZdBP8P9/0zpz3uQ l13tiDrjiKqm53VplRVSLd7J6+1Hyl+L+oyse2RPiZcOKw224G4HmidfZhT5VxVZ4kfz ywFOE9EPzSrHUzpeN1QIKhkGq4My90xvXwyYYrPUKCH0C3Zk2Y0FTOHAn11xtvjpRumS R3R+5wVW59dVZkTs0HACPZwEAhwgkOHDa/JbYM6by8v57QzXfSGTOONdEA5Ut+M5KyA7 73dg== X-Gm-Message-State: AHPjjUi+lIaFpSIpgKVgdA5or351y3qPbnkQfyBxRbYwDZUDmaKvD9fQ CYO/2EXP7/sJ4Q== X-Google-Smtp-Source: ADKCNb7LySfDHIRfMyPzUFuKs2/oir0OeXW95zGk/6UuC4aAfOdJnukiCyrc4pj8W0OAamgUSDpJqA== X-Received: by 10.84.210.107 with SMTP id z98mr5328848plh.77.1504637191512; Tue, 05 Sep 2017 11:46:31 -0700 (PDT) Received: from ?IPv6:2620:15c:2c1:100:71d2:2db4:a10e:204e? ([2620:15c:2c1:100:71d2:2db4:a10e:204e]) by smtp.googlemail.com with ESMTPSA id s1sm2455718pfk.27.2017.09.05.11.46.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Sep 2017 11:46:30 -0700 (PDT) Message-ID: <1504637190.15310.62.camel@edumazet-glaptop3.roam.corp.google.com> Subject: [PATCH v2] radix-tree: must check __radix_tree_preload() return value From: Eric Dumazet To: Matthew Wilcox Cc: Matthew Wilcox , "Kirill A. Shutemov" , Andrew Morton , netdev , Linus Torvalds , linux-kernel Date: Tue, 05 Sep 2017 11:46:30 -0700 In-Reply-To: <1504634367.15310.59.camel@edumazet-glaptop3.roam.corp.google.com> References: <1504634367.15310.59.camel@edumazet-glaptop3.roam.corp.google.com> X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eric Dumazet __radix_tree_preload() only disables preemption if no error is returned. So we really need to make sure callers always check the return value. idr_preload() contract is to always disable preemption, so we need to add a missing preempt_disable() if an error happened. Similarly, ida_pre_get() only needs to call preempt_enable() in the case no error happened. Fixes: 0a835c4f090a ("Reimplement IDR and IDA using the radix tree") Fixes: 7ad3d4d85c7a ("ida: Move ida_bitmap to a percpu variable") Signed-off-by: Eric Dumazet Cc: [4.11+] --- v2: addressed Linus feedback, not adding useless/confusing 'ret' variables. lib/radix-tree.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/radix-tree.c b/lib/radix-tree.c index 3527eb364964..afb3cb4d44b6 100644 --- a/lib/radix-tree.c +++ b/lib/radix-tree.c @@ -463,7 +463,7 @@ radix_tree_node_free(struct radix_tree_node *node) * To make use of this facility, the radix tree must be initialised without * __GFP_DIRECT_RECLAIM being passed to INIT_RADIX_TREE(). */ -static int __radix_tree_preload(gfp_t gfp_mask, unsigned nr) +static __must_check int __radix_tree_preload(gfp_t gfp_mask, unsigned nr) { struct radix_tree_preload *rtp; struct radix_tree_node *node; @@ -2104,7 +2104,8 @@ EXPORT_SYMBOL(radix_tree_tagged); */ void idr_preload(gfp_t gfp_mask) { - __radix_tree_preload(gfp_mask, IDR_PRELOAD_SIZE); + if (__radix_tree_preload(gfp_mask, IDR_PRELOAD_SIZE)) + preempt_disable(); } EXPORT_SYMBOL(idr_preload); @@ -2118,13 +2119,13 @@ EXPORT_SYMBOL(idr_preload); */ int ida_pre_get(struct ida *ida, gfp_t gfp) { - __radix_tree_preload(gfp, IDA_PRELOAD_SIZE); /* * The IDA API has no preload_end() equivalent. Instead, * ida_get_new() can return -EAGAIN, prompting the caller * to return to the ida_pre_get() step. */ - preempt_enable(); + if (!__radix_tree_preload(gfp, IDA_PRELOAD_SIZE)) + preempt_enable(); if (!this_cpu_read(ida_bitmap)) { struct ida_bitmap *bitmap = kmalloc(sizeof(*bitmap), gfp);