From patchwork Fri Oct 30 22:16:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 55862 Delivered-To: patch@linaro.org Received: by 10.112.61.134 with SMTP id p6csp115194lbr; Fri, 30 Oct 2015 15:34:50 -0700 (PDT) X-Received: by 10.66.188.49 with SMTP id fx17mr11298603pac.95.1446244490645; Fri, 30 Oct 2015 15:34:50 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id uo9si14082272pac.37.2015.10.30.15.34.49; Fri, 30 Oct 2015 15:34:50 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031433AbbJ3Wep (ORCPT + 28 others); Fri, 30 Oct 2015 18:34:45 -0400 Received: from mail-pa0-f41.google.com ([209.85.220.41]:34383 "EHLO mail-pa0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759810AbbJ3Wel (ORCPT ); Fri, 30 Oct 2015 18:34:41 -0400 Received: by padhk11 with SMTP id hk11so86168601pad.1 for ; Fri, 30 Oct 2015 15:34:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=l05mIfhcR8mWSARgo7ea8wDqU+GN8ITLHI+P9S7NJzI=; b=mnMr8W3i1f3XAEwN6zwv2iEhaBftKMNqXpe7MPpXEJc+YrGj8v9pUE/hLVGUBsfCQA z4aVTEn3LHGjHU4dlTW1AU9D4Llm+eITzncbt3E4763d9IjDLijCowIPnEH/NxhME2ND nCRPNOoHSZw8pqN5R/0Z86OL0sH2d59u+iEfennc0gC0iiqeAauUpJphXJcvZrCxrgn+ mr5n4ofBZP16XDKU9NgKNdiu+QdxYqoYWIhnacBVXjpgy3koKL9q6MF7WozNLTIVc2pg W3VAGj/vFoU/bc6TGSiyTlvxCuHJEX5j8WXztHWPA2o1n8ZGjFFLsPm+7COBHzI7TDdU J4Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=l05mIfhcR8mWSARgo7ea8wDqU+GN8ITLHI+P9S7NJzI=; b=AezqCj1elipI3zvF1dq6R6+KaK9W2/iI0C5OwyPntjxPmyciK75zjBRNy62wteTEy8 bw6jgGZ0YvsaTCIdbKKi09Y6p5ry++1O8f4Mm9qX2VrwomecSPAH7du/NKyj3FCsPw1n b9K+jXsgqPfeZcW8DxktaO0WLnk79GHvozeQD2I8QFh9o20WoxbS2NSIoMu2RNgMM2I6 mNwkWWE7Sy8io6KoWkLjDcJoNFJm1ILuV80rL4f9kn8SpFmZ4iGMacEjZ+9l9qeqrTFE iGFzlbOjfIv9Q/bOq4LaDPDBL0Re86eqEjZ+s8lVw1z9QgK0pbWKVmJwQVuZZVCpJF2Q 5aBA== X-Gm-Message-State: ALoCoQlP3o90t5Vz5B8b5OJIxV+3eOIDR28MuLCtx3JyYDR8OtovIMiyTBIyM7mhikenCEr0mqIw X-Received: by 10.66.123.9 with SMTP id lw9mr11338387pab.119.1446244480179; Fri, 30 Oct 2015 15:34:40 -0700 (PDT) Received: from yshi-Precision-T5600.corp.ad.wrs.com (unknown-216-82.windriver.com. [147.11.216.82]) by smtp.gmail.com with ESMTPSA id ey2sm10056072pbd.77.2015.10.30.15.34.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Oct 2015 15:34:39 -0700 (PDT) From: Yang Shi To: ast@kernel.org, rostedt@goodmis.org Cc: linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org, netdev@vger.kernel.org, linaro-kernel@lists.linaro.org, yang.shi@linaro.org Subject: [PATCH] bpf: convert hashtab lock to raw lock Date: Fri, 30 Oct 2015 15:16:26 -0700 Message-Id: <1446243386-26582-1-git-send-email-yang.shi@linaro.org> X-Mailer: git-send-email 2.0.2 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When running bpf samples on rt kernel, it reports the below warning: BUG: sleeping function called from invalid context at kernel/locking/rtmutex.c:917 in_atomic(): 1, irqs_disabled(): 128, pid: 477, name: ping Preemption disabled at:[] kprobe_perf_func+0x30/0x228 CPU: 3 PID: 477 Comm: ping Not tainted 4.1.10-rt8 #4 Hardware name: Freescale Layerscape 2085a RDB Board (DT) Call trace: [] dump_backtrace+0x0/0x128 [] show_stack+0x20/0x30 [] dump_stack+0x7c/0xa0 [] ___might_sleep+0x188/0x1a0 [] rt_spin_lock+0x28/0x40 [] htab_map_update_elem+0x124/0x320 [] bpf_map_update_elem+0x40/0x58 [] __bpf_prog_run+0xd48/0x1640 [] trace_call_bpf+0x8c/0x100 [] kprobe_perf_func+0x30/0x228 [] kprobe_dispatcher+0x34/0x58 [] kprobe_handler+0x114/0x250 [] kprobe_breakpoint_handler+0x1c/0x30 [] brk_handler+0x88/0x98 [] do_debug_exception+0x50/0xb8 Exception stack(0xffff808349687460 to 0xffff808349687580) 7460: 4ca2b600 ffff8083 4a3a7000 ffff8083 49687620 ffff8083 0069c5f8 ffff8000 7480: 00000001 00000000 007e0628 ffff8000 496874b0 ffff8083 007e1de8 ffff8000 74a0: 496874d0 ffff8083 0008e04c ffff8000 00000001 00000000 4ca2b600 ffff8083 74c0: 00ba2e80 ffff8000 49687528 ffff8083 49687510 ffff8083 000e5c70 ffff8000 74e0: 00c22348 ffff8000 00000000 ffff8083 49687510 ffff8083 000e5c74 ffff8000 7500: 4ca2b600 ffff8083 49401800 ffff8083 00000001 00000000 00000000 00000000 7520: 496874d0 ffff8083 00000000 00000000 00000000 00000000 00000000 00000000 7540: 2f2e2d2c 33323130 00000000 00000000 4c944500 ffff8083 00000000 00000000 7560: 00000000 00000000 008751e0 ffff8000 00000001 00000000 124e2d1d 00107b77 Convert hashtab lock to raw lock to avoid such warning. Signed-off-by: Yang Shi --- This patch is applicable to mainline kernel too. kernel/bpf/hashtab.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) -- 2.0.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c index 83c209d..972b76b 100644 --- a/kernel/bpf/hashtab.c +++ b/kernel/bpf/hashtab.c @@ -17,7 +17,7 @@ struct bpf_htab { struct bpf_map map; struct hlist_head *buckets; - spinlock_t lock; + raw_spinlock_t lock; u32 count; /* number of elements in this hashtable */ u32 n_buckets; /* number of hash buckets */ u32 elem_size; /* size of each element in bytes */ @@ -82,7 +82,7 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr) for (i = 0; i < htab->n_buckets; i++) INIT_HLIST_HEAD(&htab->buckets[i]); - spin_lock_init(&htab->lock); + raw_spin_lock_init(&htab->lock); htab->count = 0; htab->elem_size = sizeof(struct htab_elem) + @@ -230,7 +230,7 @@ static int htab_map_update_elem(struct bpf_map *map, void *key, void *value, l_new->hash = htab_map_hash(l_new->key, key_size); /* bpf_map_update_elem() can be called in_irq() */ - spin_lock_irqsave(&htab->lock, flags); + raw_spin_lock_irqsave(&htab->lock, flags); head = select_bucket(htab, l_new->hash); @@ -266,11 +266,11 @@ static int htab_map_update_elem(struct bpf_map *map, void *key, void *value, } else { htab->count++; } - spin_unlock_irqrestore(&htab->lock, flags); + raw_spin_unlock_irqrestore(&htab->lock, flags); return 0; err: - spin_unlock_irqrestore(&htab->lock, flags); + raw_spin_unlock_irqrestore(&htab->lock, flags); kfree(l_new); return ret; } @@ -291,7 +291,7 @@ static int htab_map_delete_elem(struct bpf_map *map, void *key) hash = htab_map_hash(key, key_size); - spin_lock_irqsave(&htab->lock, flags); + raw_spin_lock_irqsave(&htab->lock, flags); head = select_bucket(htab, hash); @@ -304,7 +304,7 @@ static int htab_map_delete_elem(struct bpf_map *map, void *key) ret = 0; } - spin_unlock_irqrestore(&htab->lock, flags); + raw_spin_unlock_irqrestore(&htab->lock, flags); return ret; }