From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6A07C169C4 for ; Tue, 29 Jan 2019 07:01:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 69FA5217F5 for ; Tue, 29 Jan 2019 07:01:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="DzfiahhW"; dkim=pass (1024-bit key) header.d=fb.onmicrosoft.com header.i=@fb.onmicrosoft.com header.b="NzJqAgrr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725808AbfA2HB1 (ORCPT ); Tue, 29 Jan 2019 02:01:27 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:57252 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725536AbfA2HB0 (ORCPT ); Tue, 29 Jan 2019 02:01:26 -0500 Received: from pps.filterd (m0044008.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x0T6sBGk024566; Mon, 28 Jan 2019 23:00:43 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=facebook; bh=oSZNV5bNqpblPl096ARYjVcs7hJFrA4FG0mc4pUQthE=; b=DzfiahhWQQppNzHIwNgXM695XfTbiBDnLZ9al9rAnCfJmRqFqqeyLaZIy3jCxpNrs/5/ wKmubbtK41/UzuYJ7ipAdMPPusICiFwy8tTMwdTDSXoGsy7KdF8tjIOxDLo5Y9MkbsVn kdQKyXPgpJQqyARtSPCFESslrA9z2rdbsQw= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2qaghxg7p9-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 28 Jan 2019 23:00:43 -0800 Received: from prn-mbx02.TheFacebook.com (2620:10d:c081:6::16) by prn-hub01.TheFacebook.com (2620:10d:c081:35::125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.1.1531.3; Mon, 28 Jan 2019 23:00:42 -0800 Received: from prn-hub05.TheFacebook.com (2620:10d:c081:35::129) by prn-mbx02.TheFacebook.com (2620:10d:c081:6::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.1.1531.3; Mon, 28 Jan 2019 23:00:42 -0800 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (192.168.54.28) by o365-in.thefacebook.com (192.168.16.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.1.1531.3 via Frontend Transport; Mon, 28 Jan 2019 23:00:42 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oSZNV5bNqpblPl096ARYjVcs7hJFrA4FG0mc4pUQthE=; b=NzJqAgrrSrb+a5k8lyLFrdk1PZ0rSsqgF3bxQSMMeQYtg9fWtjwmub+t0DooQg+q0dAbfYTjRNL73jYESPt5tXWsVKAaoIgs2GFWcUZeYf9qmeBbW/fT+XFtSVvlwahI3ibtQj3ep9RtUQ/uA5QliWX31nkV987/wFSRx3fc0No= Received: from MWHPR15MB1165.namprd15.prod.outlook.com (10.175.2.19) by MWHPR15MB1599.namprd15.prod.outlook.com (10.173.235.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1558.17; Tue, 29 Jan 2019 07:00:40 +0000 Received: from MWHPR15MB1165.namprd15.prod.outlook.com ([fe80::ec0e:4a05:81f8:7df9]) by MWHPR15MB1165.namprd15.prod.outlook.com ([fe80::ec0e:4a05:81f8:7df9%4]) with mapi id 15.20.1558.021; Tue, 29 Jan 2019 07:00:40 +0000 From: Song Liu To: Alexei Starovoitov CC: David Miller , Daniel Borkmann , "peterz@infradead.org" , "jannh@google.com" , "paulmck@linux.ibm.com" , "will.deacon@arm.com" , "mingo@redhat.com" , "netdev@vger.kernel.org" , Kernel Team Subject: Re: [PATCH bpf-next] bpf: check that BPF programs run with preemption disabled Thread-Topic: [PATCH bpf-next] bpf: check that BPF programs run with preemption disabled Thread-Index: AQHUt3EaLTPNzqQSIE26Fgo/pg41sqXF0csA Date: Tue, 29 Jan 2019 07:00:40 +0000 Message-ID: <6A67533E-51B3-428A-9236-B98321119446@fb.com> References: <20190129012152.251061-1-ast@kernel.org> In-Reply-To: <20190129012152.251061-1-ast@kernel.org> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Apple Mail (2.3445.102.3) x-originating-ip: [2620:10d:c090:180::1:ec49] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;MWHPR15MB1599;20:usgejPtQmHIn99yA8r+3aw0P215BXMAl5Ljx8XvIkUI86aSQESa/F5iyvPdqpLIKCkuJqIwcJSuWzDope+3xTBizBpkbS+5Vw+y794xOu6hrfPfjb9dnoVnOqEYUQbEJ8gfVgK+f6eM8Ll+/EeCK9JvDN0EnqRH15maXefsDVk0= x-ms-office365-filtering-correlation-id: cda65901-1db3-4a63-47a3-08d685b77af9 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600110)(711020)(4605077)(2017052603328)(7153060)(7193020);SRVR:MWHPR15MB1599; x-ms-traffictypediagnostic: MWHPR15MB1599: x-microsoft-antispam-prvs: x-forefront-prvs: 093290AD39 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(366004)(39860400002)(346002)(376002)(136003)(199004)(189003)(6246003)(99286004)(8936002)(6486002)(11346002)(6916009)(486006)(476003)(14454004)(68736007)(50226002)(2906002)(36756003)(186003)(446003)(81166006)(33656002)(81156014)(53936002)(25786009)(46003)(2616005)(7736002)(76176011)(305945005)(86362001)(4326008)(57306001)(106356001)(6512007)(53546011)(256004)(97736004)(83716004)(14444005)(8676002)(316002)(105586002)(82746002)(102836004)(6436002)(6116002)(6506007)(71200400001)(71190400001)(54906003)(229853002)(478600001);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR15MB1599;H:MWHPR15MB1165.namprd15.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: fb.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: MvIQ9JdbOuSQsr308NL2Dg2kXbJird3A6aHRbY0ynIegxsQG6Sl6/eRY+C38/6zPEMTVePQjF/qlAfZlWnut/FW7BLykZEgjoULNDmrP75ehi7l4XgycpbEfAyMjtCrpTIYTY0zW4X87wslnuHpr+wTiBr/p4hz4Hk5VBFW/fvEiuk49sSLIZQhZYJBVKcpgKsBPZhMF145uzvrPrsWaI/KcoX+X8WKz2RRieGNGD1oh8Ol8n+XzuyD1Td/Gw4aHJ0Xxdkl6PT+K/kKz5iKpWtz+OWw+QcpRMBzveGRBK6P8ygHZtEkUS2huJvpxhsNTNZ+/8yEcnwgJi8jivBfywQmjVh5fgxVNVJcK+d0QGTFksBja6G1h2ImMsKblM9BF8QBntprPRYoDantsg3XM1RIyMNp7sUfwFtElaR6qeXY= Content-Type: text/plain; charset="us-ascii" Content-ID: <59E22B36EB7FFB49B07B9B98A56951A7@namprd15.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: cda65901-1db3-4a63-47a3-08d685b77af9 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Jan 2019 07:00:40.6769 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR15MB1599 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-01-29_05:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org > On Jan 28, 2019, at 5:21 PM, Alexei Starovoitov wrote: >=20 > From: Peter Zijlstra >=20 > Introduce cant_sleep() macro for annotation of functions that cannot slee= p. >=20 > Use it in BPF_PROG_RUN to catch execution of BPF programs > in preemptable context. >=20 > Suggested-by: Jann Horn > Signed-off-by: Peter Zijlstra (Intel) > Signed-off-by: Alexei Starovoitov Acked-by: Song Liu > --- > include/linux/filter.h | 2 +- > include/linux/kernel.h | 14 ++++++++++++-- > kernel/sched/core.c | 28 ++++++++++++++++++++++++++++ > 3 files changed, 41 insertions(+), 3 deletions(-) >=20 > diff --git a/include/linux/filter.h b/include/linux/filter.h > index e4b473f85b46..7e87863617b3 100644 > --- a/include/linux/filter.h > +++ b/include/linux/filter.h > @@ -533,7 +533,7 @@ struct sk_filter { > struct bpf_prog *prog; > }; >=20 > -#define BPF_PROG_RUN(filter, ctx) (*(filter)->bpf_func)(ctx, (filter)->= insnsi) > +#define BPF_PROG_RUN(filter, ctx) ({ cant_sleep(); (*(filter)->bpf_func= )(ctx, (filter)->insnsi); }) >=20 > #define BPF_SKB_CB_LEN QDISC_CB_PRIV_LEN >=20 > diff --git a/include/linux/kernel.h b/include/linux/kernel.h > index 8f0e68e250a7..a8868a32098c 100644 > --- a/include/linux/kernel.h > +++ b/include/linux/kernel.h > @@ -245,8 +245,10 @@ extern int _cond_resched(void); > #endif >=20 > #ifdef CONFIG_DEBUG_ATOMIC_SLEEP > - void ___might_sleep(const char *file, int line, int preempt_offset); > - void __might_sleep(const char *file, int line, int preempt_offset); > +extern void ___might_sleep(const char *file, int line, int preempt_offse= t); > +extern void __might_sleep(const char *file, int line, int preempt_offset= ); > +extern void __cant_sleep(const char *file, int line, int preempt_offset)= ; > + > /** > * might_sleep - annotation for functions that can sleep > * > @@ -259,6 +261,13 @@ extern int _cond_resched(void); > */ > # define might_sleep() \ > do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0) > +/** > + * cant_sleep - annotation for functions that cannot sleep > + * > + * this macro will print a stack trace if it is executed with preemption= enabled > + */ > +# define cant_sleep() \ > + do { __cant_sleep(__FILE__, __LINE__, 0); } while (0) > # define sched_annotate_sleep() (current->task_state_change =3D 0) > #else > static inline void ___might_sleep(const char *file, int line, > @@ -266,6 +275,7 @@ extern int _cond_resched(void); > static inline void __might_sleep(const char *file, int line, > int preempt_offset) { } > # define might_sleep() do { might_resched(); } while (0) > +# define cant_sleep() do { } while (0) > # define sched_annotate_sleep() do { } while (0) > #endif >=20 > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index a674c7db2f29..1dcbff62f973 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -6149,6 +6149,34 @@ void ___might_sleep(const char *file, int line, in= t preempt_offset) > add_taint(TAINT_WARN, LOCKDEP_STILL_OK); > } > EXPORT_SYMBOL(___might_sleep); > + > +void __cant_sleep(const char *file, int line, int preempt_offset) > +{ > + static unsigned long prev_jiffy; > + > + if (irqs_disabled()) > + return; > + > + if (!IS_ENABLED(CONFIG_PREEMPT_COUNT)) > + return; > + > + if (preempt_count() > preempt_offset) > + return; > + > + if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy) > + return; > + prev_jiffy =3D jiffies; > + > + printk(KERN_ERR "BUG: assuming atomic context at %s:%d\n", file, line); > + printk(KERN_ERR "in_atomic(): %d, irqs_disabled(): %d, pid: %d, name: %= s\n", > + in_atomic(), irqs_disabled(), > + current->pid, current->comm); > + > + debug_show_held_locks(current); > + dump_stack(); > + add_taint(TAINT_WARN, LOCKDEP_STILL_OK); > +} > +EXPORT_SYMBOL_GPL(__cant_sleep); > #endif >=20 > #ifdef CONFIG_MAGIC_SYSRQ > --=20 > 2.20.0 >=20