Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3229660imc; Wed, 13 Mar 2019 12:11:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqwHuSPWgQYU1tvqXZa4F1Ml/EVPDQcxbjpVMvphtMtvFzcbvunrg1or8b59kv7n/10VUkHH X-Received: by 2002:a63:e40b:: with SMTP id a11mr41534193pgi.259.1552504286450; Wed, 13 Mar 2019 12:11:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552504286; cv=none; d=google.com; s=arc-20160816; b=XXDTdor48+t19QiKDOBRcDzsinz7uagfwwJldXBXYLT/FQpdSqYr5I6YNWNyvweYuF pJ7IsMZxXfT7osGS6DlIWjnzzNXF2DnHhWjpPMnK9TS05t1BjMLpV/sifGCy8/D02Ul+ 97ieGOe5xWOlPeYl65MrQ2ldhhxkZjHyL446mT+AbE8Ef7tSYK2KLV4VdkOZ4r+dEkqZ zCWX7A8MLyS4yID0QJxBbxGvZDqeOkE4yUPz+0F5ZoayAIfAD7BJQONmB8PPkFCq7EPc +KzEXCXvTlH21G+jWKimsOeJ80VGFwFM1XvdQtP3Mgt9pgPtB/QimOhW0YG0IW+P/PLw DEUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=g7WIbSM0aTjWLOA+AWsYWemp0K0JAwa3gYAU4AZplZg=; b=rg3ynO50Z7KZ4t53A532ODSWF6FiZk96zEX3cSTAXfhu4GkxoNJs40wJXixD4+6gzg LfchA/2InuLkXo7g4IGeG0/CabmTSX32MGLFZeq8lMqkiFnZovpmZyKG94MkUkGiW8rP Pn9E88kmvITr/uOwrHMR8kqxoWIJ8vo926msI8um9iN6ZqEcx8eSvgVVhIigagm6bR7n H00Esv/IJIEMFJBKPy/Uqyd7Q4sb5g0gdVXiq/z8+tI8K2CqPQQVBv2VJyY9PZB2wHpF hGelSc+wzAUsVjU52uuD84BQobbEn4exStqQQpkzqC4K50s6CkjuyV49VplhggS9u1Zh YVJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BqHQM1VV; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a98si12550607pla.267.2019.03.13.12.11.08; Wed, 13 Mar 2019 12:11:26 -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; dkim=pass header.i=@kernel.org header.s=default header.b=BqHQM1VV; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727132AbfCMTKl (ORCPT + 99 others); Wed, 13 Mar 2019 15:10:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:41242 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727112AbfCMTKi (ORCPT ); Wed, 13 Mar 2019 15:10:38 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 874712184D; Wed, 13 Mar 2019 19:10:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552504237; bh=P4dMpDvhBPN5Wx05GPrpTJkk2VG1k+xFDs0XYWKE8pc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BqHQM1VVXeoFAgIFDgqirLcVwzk/22rrrrWuIscP2c7RGPlleNzW65Ya0nz+EYWfd v62MHMojF9crKpWotu6krwOBhfkF94D2gotze7Dy2ggRwNrXqO71MIcPq0qo4tshGz FMCJ+SI5qKJqR6jN/VpP87oHV7c1vQYMdweOBAt8= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , Sasha Levin Subject: [PATCH AUTOSEL 4.20 08/60] bpf: fix lockdep false positive in stackmap Date: Wed, 13 Mar 2019 15:09:29 -0400 Message-Id: <20190313191021.158171-8-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190313191021.158171-1-sashal@kernel.org> References: <20190313191021.158171-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexei Starovoitov [ Upstream commit 3defaf2f15b2bfd86c6664181ac009e91985f8ac ] Lockdep warns about false positive: [ 11.211460] ------------[ cut here ]------------ [ 11.211936] DEBUG_LOCKS_WARN_ON(depth <= 0) [ 11.211985] WARNING: CPU: 0 PID: 141 at ../kernel/locking/lockdep.c:3592 lock_release+0x1ad/0x280 [ 11.213134] Modules linked in: [ 11.214954] RIP: 0010:lock_release+0x1ad/0x280 [ 11.223508] Call Trace: [ 11.223705] [ 11.223874] ? __local_bh_enable+0x7a/0x80 [ 11.224199] up_read+0x1c/0xa0 [ 11.224446] do_up_read+0x12/0x20 [ 11.224713] irq_work_run_list+0x43/0x70 [ 11.225030] irq_work_run+0x26/0x50 [ 11.225310] smp_irq_work_interrupt+0x57/0x1f0 [ 11.225662] irq_work_interrupt+0xf/0x20 since rw_semaphore is released in a different task vs task that locked the sema. It is expected behavior. Fix the warning with up_read_non_owner() and rwsem_release() annotation. Fixes: bae77c5eb5b2 ("bpf: enable stackmap with build_id in nmi context") Signed-off-by: Alexei Starovoitov Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin --- kernel/bpf/stackmap.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c index d43b14535827..950ab2f28922 100644 --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -44,7 +44,7 @@ static void do_up_read(struct irq_work *entry) struct stack_map_irq_work *work; work = container_of(entry, struct stack_map_irq_work, irq_work); - up_read(work->sem); + up_read_non_owner(work->sem); work->sem = NULL; } @@ -338,6 +338,12 @@ static void stack_map_get_build_id_offset(struct bpf_stack_build_id *id_offs, } else { work->sem = ¤t->mm->mmap_sem; irq_work_queue(&work->irq_work); + /* + * The irq_work will release the mmap_sem with + * up_read_non_owner(). The rwsem_release() is called + * here to release the lock from lockdep's perspective. + */ + rwsem_release(¤t->mm->mmap_sem.dep_map, 1, _RET_IP_); } } -- 2.19.1