Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3982576yba; Tue, 23 Apr 2019 12:57:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqyIHS7GAB4YYd+Nc+1qHtkwWMi34fXYlZ6a2setJlivzyPr/MtV3t9FAQpc1+4US5ew24We X-Received: by 2002:a17:902:b715:: with SMTP id d21mr28220700pls.103.1556049452086; Tue, 23 Apr 2019 12:57:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556049452; cv=none; d=google.com; s=arc-20160816; b=lhX84TFNSXT6kSPuRbmWGBDxV0C9nWjzkSp0N9DahMgzo4QeYFO0KzHp7JMhpqIUSK ToWU4DsO67JQBS3Z3jty27jXgzsswjvN8nSeFkfGWsVvrl6jXHx4f1nFoh46UStEi+UP Djf7HtKGyrdFG6zs4HgmoUF9y2fU1XLn2ju8BDxhFr1yHEQpk+IB0Mk/3yvsN9Cocwm7 B0Av5uqpAQw+Bh7g+KIEpnccf8fDoFr8V6HRj78HbYrKHJOoazbK8mK7DM/BSc0CAXkB RFyfDxtu4lmUhy7EQjT/IwATw4w86vyttoTDcbGOOHvx0NGNbj+3+7Bujr0xXScFB/hj s6fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=uBJlpdTHp6Z4y9fxNWwd3vt4kb8Y+n8p3Is+SZyxL1M=; b=XN0QjSRFiHO5YFPWO8JqDMoelhLjG5V8cPsLT/MSTjLaBRr15ktW9/4yrsaf16o4+Z CKoz/moAxM++Sj9km/VC4yQXQBYUY3qILcj6NRDUgoIo2UxG2JlKndCAFT5eJ9TH6Gdv QUJUb2nBMgtVu2Ih+ja6XmBoZFPwv3MSKOZG2mSdcRTvbNkc1slBda8BI0aDTrBeSuxI 3WHf8oXR8yKoJWleP/4qafoLxR2FSO78IpwpoBK1hGv28WzzTmMp5U2qgORomN9vHzF2 uQ54aUwumCXcSDLoRX6igKNB4WXt5THzYGcv/G7mfwqh2UVGt+kktrZdRHO3UMKSdJ5c V0vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=I8KW9sB4; 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 j23si2904213pff.108.2019.04.23.12.57.15; Tue, 23 Apr 2019 12:57:32 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=I8KW9sB4; 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 S1726157AbfDWT4V (ORCPT + 99 others); Tue, 23 Apr 2019 15:56:21 -0400 Received: from merlin.infradead.org ([205.233.59.134]:54160 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725945AbfDWT4U (ORCPT ); Tue, 23 Apr 2019 15:56:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=uBJlpdTHp6Z4y9fxNWwd3vt4kb8Y+n8p3Is+SZyxL1M=; b=I8KW9sB4KOwxZRtkHQ1cntwdC 90k82dAwZZt3KWtXa69CvKctECv1xKXqRuz4JCk4zntMv5q0iYkZ9dfEvNwlg2diyuNV+1Vtrib/f um6HAr5kWPy04/WSK6GOirByatKHryStedDxe8Ze/0jXapufmq/ew96BUTiAzZUdOrRkNMh5ne+vu 6NHlGVODDpCn6Vu3QgZ4O1bLgb/YDwqJEi3l2y+az4MME7wG6+VTTOzBsLTtgEiKyFAiUM4k97Muf MGLXPGdPJfrdJLYznNgJ28UkMmD58e/CIuen7tYpNKZJGwTDjkq1EsmHzDOd+i2Ad71eSUA8Injtn JR/AzUFVw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hJ1WK-0000xY-NS; Tue, 23 Apr 2019 19:56:00 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 53BAE29C30E0A; Tue, 23 Apr 2019 21:55:59 +0200 (CEST) Date: Tue, 23 Apr 2019 21:55:59 +0200 From: Peter Zijlstra To: Waiman Long Cc: Linus Torvalds , Ingo Molnar , Will Deacon , Thomas Gleixner , Linux List Kernel Mailing , the arch/x86 maintainers , Davidlohr Bueso , Tim Chen , huang ying , Roman Gushchin , Alexei Starovoitov , Daniel Borkmann Subject: [PATCH] bpf: Fix preempt_enable_no_resched() abuse Message-ID: <20190423195559.GY4038@hirez.programming.kicks-ass.net> References: <20190419120207.GO4038@hirez.programming.kicks-ass.net> <20190419130304.GV14281@hirez.programming.kicks-ass.net> <20190419131522.GW14281@hirez.programming.kicks-ass.net> <57620139-92a3-4a21-56bd-5d6fff23214f@redhat.com> <7b1bfc26-6e90-bd65-ab46-08413acd80e9@redhat.com> <20190423141714.GO11158@hirez.programming.kicks-ass.net> <4f62d7f2-e5f6-500e-3e70-b1d1978f7140@redhat.com> <20190423193435.GX4038@hirez.programming.kicks-ass.net> <88ba7be0-9ec5-941e-1b3f-80fbe05fe3a0@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <88ba7be0-9ec5-941e-1b3f-80fbe05fe3a0@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 23, 2019 at 03:41:32PM -0400, Waiman Long wrote: > On 4/23/19 3:34 PM, Peter Zijlstra wrote: > > On Tue, Apr 23, 2019 at 03:12:16PM -0400, Waiman Long wrote: > >> You are right on that. However, there is a variant called > >> preempt_enable_no_resched() that doesn't have this side effect. So I am > >> going to use that one instead. > > Only if the very next line is schedule(). Otherwise you're very much not > > going to use that function. > > May I know the reason why. Because it can 'consume' a need_resched and introduces arbitrary delays before the schedule() eventually happens, breaking the very notion of PREEMPT=y (and the fundamentals RT relies on). > I saw a number of instances of > preempt_enable_no_resched() without right next a schedule(). Look more closely.. and let me know, if true, those are bugs that need fixing. Argghhh.. BPF... Also, with the recent RCU rework, we can probably drop that rcu_read_lock()/rcu_read_unlock() from there if we're disabling preemption anyway. --- Subject: bpf: Fix preempt_enable_no_resched() abuse Unless the very next line is schedule(), or implies it, one must not use preempt_enable_no_resched(). It can cause a preemption to go missing and thereby cause arbitrary delays, breaking the PREEMPT=y invariant. Cc: Roman Gushchin Cc: Alexei Starovoitov Cc: Daniel Borkmann Signed-off-by: Peter Zijlstra (Intel) --- diff --git a/include/linux/bpf.h b/include/linux/bpf.h index f02367faa58d..944ccc310201 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -510,7 +510,7 @@ int bpf_prog_array_copy(struct bpf_prog_array __rcu *old_array, } \ _out: \ rcu_read_unlock(); \ - preempt_enable_no_resched(); \ + preempt_enable(); \ _ret; \ })