From patchwork Wed Oct 19 08:25:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5558 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp349914wrs; Wed, 19 Oct 2022 07:12:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6FAOFFno99/SHak+9WcOtnqGvlDDHJ3ttbNmy0jH+ijYwDA6FE1zO0bH7b+w4m2kh/dawI X-Received: by 2002:a17:902:f78c:b0:17a:ef1:e902 with SMTP id q12-20020a170902f78c00b0017a0ef1e902mr8568110pln.5.1666188762860; Wed, 19 Oct 2022 07:12:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666188762; cv=none; d=google.com; s=arc-20160816; b=CNxq4e/kQfWpE57OMBTuPvKJujRPxugIrBwUy0VOTdp4DJCif/htnF/458eYgbsu81 ybBhxPNG9bExZcCUiCrTH1NNCuQmQzOo9m7Q0gW2RLysWtdCFzakUWem6AJYSsv3nUOo DtfB0ce5ofHntYE+wnkPiJBPj8hXcTK+hNdUhzwGakfw6lPIjaMTwQugkMzV58O2jHDL iRwEnYYJmkqupg2wwXJ8kGxpK4PmMwWMUsYPnuH4pIaUm5DA9ywDNkuYvS3hcVnX8QBS j5F0bU9BOzbQxL/pZriIlEGFOapeVM4WI/3a9A54xm935xo4ZKK1JKB5Jm67QT0Z3SXZ DMeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=t8U78CrPaII5mcDpQrc7pVPzmGmws8mbFikncnOMiDs=; b=mkLUjC4rZiKi9E4bIRfrzbrj4uAiR72ynUW9Ecm1a/dGDcf76z1Vb8rM8y7wvPkXuD rZW/AW4hHdsGiauS3H291Ud5PQ8IlphrlT7aU6lnvUZAk4U522c1PdQUsoxOOO5OxQRb pcBO1EskTIUCctsI/KpU4DjXw2V2OiYIHavPbDUNrAna0CeA5QZUuT47BiAtQrMMY6Qf O6tmzqSUWnVCYWGa3pQM0cr0fifbolc1M89EVQZsn2hGYvZVbnTChxyLjyo3hzGHDn/q EofFBtmll6DlVNWyhiPCJA8xNz/DwQfg3YWKdBbfta58oWQHwWWu2u8++RggFzwYp0np Hlzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vZJOy68s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e11-20020a17090301cb00b001787f1922a7si23457334plh.19.2022.10.19.07.12.22; Wed, 19 Oct 2022 07:12:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vZJOy68s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230063AbiJSN6a (ORCPT + 99 others); Wed, 19 Oct 2022 09:58:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234010AbiJSNyf (ORCPT ); Wed, 19 Oct 2022 09:54:35 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A41AC1DDC1D; Wed, 19 Oct 2022 06:37:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 081FAB82337; Wed, 19 Oct 2022 08:49:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BF7FC433D7; Wed, 19 Oct 2022 08:49:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169386; bh=wQ4vvWEZ6w/RYnBZK7uYJgLompeNljXKcXo+SrdSuZc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vZJOy68sTzVZ5fdyI9kWgap0R8lusm9AulZ5eG6Y2yMIX+dzLJqA6FYkmXMG0d6pJ LZxURLjj4n8MSCe68VqLpWzKbJ+wnGbZv1maBD191kSWxowKyAEV3KqDciBP5C0Jga BrE+xmClkyuA+DI3dpwgB5R/B/+IXXzlqr3Ev7u4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hou Tao , Alexei Starovoitov , Martin KaFai Lau , Sasha Levin Subject: [PATCH 6.0 257/862] bpf: Use this_cpu_{inc_return|dec} for prog->active Date: Wed, 19 Oct 2022 10:25:44 +0200 Message-Id: <20221019083301.406438627@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747125548230738787?= X-GMAIL-MSGID: =?utf-8?q?1747125548230738787?= From: Hou Tao [ Upstream commit c89e843a11f1075d27684f6b42256213e4592383 ] Both __this_cpu_inc_return() and __this_cpu_dec() are not preemption safe and now migrate_disable() doesn't disable preemption, so the update of prog-active is not atomic and in theory under fully preemptible kernel recurisve prevention may do not work. Fixing by using the preemption-safe and IRQ-safe variants. Fixes: ca06f55b9002 ("bpf: Add per-program recursion prevention mechanism") Signed-off-by: Hou Tao Acked-by: Alexei Starovoitov Link: https://lore.kernel.org/r/20220901061938.3789460-3-houtao@huaweicloud.com Signed-off-by: Martin KaFai Lau Signed-off-by: Sasha Levin --- kernel/bpf/trampoline.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c index ff87e38af8a7..ad76940b02cc 100644 --- a/kernel/bpf/trampoline.c +++ b/kernel/bpf/trampoline.c @@ -895,7 +895,7 @@ u64 notrace __bpf_prog_enter(struct bpf_prog *prog, struct bpf_tramp_run_ctx *ru run_ctx->saved_run_ctx = bpf_set_run_ctx(&run_ctx->run_ctx); - if (unlikely(__this_cpu_inc_return(*(prog->active)) != 1)) { + if (unlikely(this_cpu_inc_return(*(prog->active)) != 1)) { inc_misses_counter(prog); return 0; } @@ -930,7 +930,7 @@ void notrace __bpf_prog_exit(struct bpf_prog *prog, u64 start, struct bpf_tramp_ bpf_reset_run_ctx(run_ctx->saved_run_ctx); update_prog_stats(prog, start); - __this_cpu_dec(*(prog->active)); + this_cpu_dec(*(prog->active)); migrate_enable(); rcu_read_unlock(); } @@ -966,7 +966,7 @@ u64 notrace __bpf_prog_enter_sleepable(struct bpf_prog *prog, struct bpf_tramp_r migrate_disable(); might_fault(); - if (unlikely(__this_cpu_inc_return(*(prog->active)) != 1)) { + if (unlikely(this_cpu_inc_return(*(prog->active)) != 1)) { inc_misses_counter(prog); return 0; } @@ -982,7 +982,7 @@ void notrace __bpf_prog_exit_sleepable(struct bpf_prog *prog, u64 start, bpf_reset_run_ctx(run_ctx->saved_run_ctx); update_prog_stats(prog, start); - __this_cpu_dec(*(prog->active)); + this_cpu_dec(*(prog->active)); migrate_enable(); rcu_read_unlock_trace(); }