Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp693583lqt; Fri, 19 Apr 2024 07:49:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVhJgBha4HduXPOG2KGw1Kf0+V0ShkdMA6S3OXOaslIXTorUvvNhvGv+tH72lboS5uznlTD3ABgBPW/nWyHXtkBbwmWJs3iXgzExECMXg== X-Google-Smtp-Source: AGHT+IH47dWpmqcD2hXQ+agHZ/jJXvzIc/Jrx93w5x17L9qt1IQhTJMJeYFymnFPZLQU9eGm1Wcm X-Received: by 2002:a05:6a00:1910:b0:6e7:4abe:85a0 with SMTP id y16-20020a056a00191000b006e74abe85a0mr2856927pfi.14.1713538163195; Fri, 19 Apr 2024 07:49:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713538163; cv=pass; d=google.com; s=arc-20160816; b=yN2XnolaSGKy1HcbXfIiZixd5kWitEjs+LBzu0K07OrYc7t5L74yXUxF4OAjyc0/5R +cj59VrrBHe6BsvG+boIZrtqF8lrNpgyaWFjP5/amXiQNBec7bQwB0kvvR08bBeAXLuS 8csq6jcfSZJ88qw+R4NuhXEop8FXI9EKTL+m1DElj9TDbTKPgQ4GAHnwslFCxh8+H+fE H2aUFk+f1+TN9kPxEdD8IF1fQnz8lQxj9bUD9ohrwax7T9AuiCerIXW+eXSzeyx9MfzS MSKzRYMHb/UURzMb8Fu4DYnz8V3XKbOFARDDxclXRHlXzqN62zRn5ddObLVVttHem1T6 MFBQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=RT01wqBAI9CrX0bmnf/ZeGNbnB/v72Eil0q0wM+kigI=; fh=ECceH2dayNfnvmqOepwt3462Sc1jlGs79NtdtkTNamk=; b=WUntNhXJULpjU9ZELvM6q51HoA+n0VW6RAreSLUVh3/B3DfKooegVuuiwaRVlN+OpT scjxLeEUBBEg/ZcPWU7ttARh3eDQavB1SeR9OjaeYDgSd1I3jkZ+BZU5tmdGCunklbkW UoFNRygz9XIwhJpr8AQRTYaszB0YSiQLzOqutx9EkwbxeMZ9W/QStWLvc8ngFdH8ujRz PuccFWBbEG/otNUoirNwkRG+/3konaG2iHQqVFNCzbV1osXVk3Va7nvzDdRPWbUrSZcJ Lo8bXxawsufE5usEfPWqupUfbUyCq8gpJ5WQlIDezZkDDrHY0Zp1QbIFgk9ukD78gyKX 6Seg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BuRCUrVG; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-151604-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151604-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q16-20020a638c50000000b005f80483dba6si700716pgn.112.2024.04.19.07.49.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 07:49:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151604-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BuRCUrVG; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-151604-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151604-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 49771286180 for ; Fri, 19 Apr 2024 14:48:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3836212FF7B; Fri, 19 Apr 2024 14:48:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BuRCUrVG" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5AA1112FB3B; Fri, 19 Apr 2024 14:48:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713538084; cv=none; b=UYrACQVR60ftJgqeWR8tFDAx51qzzdAmaquY3XJqoM5yrll3uiBxfgWqiok5AFPaxJIQd0vZSlmIsZq9cvP6Q3Sxi09oY2wE5+OGS8Q2I91Q7nsexEMNwzkJcEas6/sfEOszosWVKEfyg2S26OMMdE6RlDIkPiSgtR4CbWnyvVI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713538084; c=relaxed/simple; bh=/LAcqzfMdnZvAZXucskSQU6PgrY6Yvip45QZyOx1xEw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UN9nNF2+BuBA39f5jfk2NoOKr3YrNqsF2uHaddiezgxOl34T4RPrKfo03VQ4YPOJc4nB02VF3kab0i9jWVm9c3gNjfFKKpj4K/ZhQqs//lvrwnYA+oz0bOUF0m8WyS+jJnX+6xWubdwPQlRdt+uE7o1deq3WFGF4OaEf+UGrip4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BuRCUrVG; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BD80C32781; Fri, 19 Apr 2024 14:48:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713538083; bh=/LAcqzfMdnZvAZXucskSQU6PgrY6Yvip45QZyOx1xEw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BuRCUrVGAEZpoS7MUCJYTtXvL7w0JOBGu4+4DTrXALwT9tPj80MKg/M3EvvWAnYIH C+GDP29BK06kDF/XsfpueUAWVUJtOc/0QeD7a8bhRTjKBt0QycpKGYGFLg4+ULaNR+ FVC5mU+g89mesb/KowzjOoPoQmnhlOUG/sR8jR4XvCtxLGZCXixz97tsBxqP6rSwJ1 rMTIwaVLjTmRNLIu1R5YmSmIjyx6Gd443PuIsCrIA0aBChDmD0E7pFH+mPNiKfj5Yh SdLC6eRZAOL6AHqLneNiV4+ZuViPU+Xyu45rVAfnJaOB98UsmrJc3wzQZCD7Z05mep TLvc9BFWJEGSA== From: Benjamin Tissoires Date: Fri, 19 Apr 2024 16:47:53 +0200 Subject: [PATCH 3/3] HID: bpf: lazy load the hid_tail_call entrypoint Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240419-hid_bpf_lazy_skel-v1-3-9210bcd4b61c@kernel.org> References: <20240419-hid_bpf_lazy_skel-v1-0-9210bcd4b61c@kernel.org> In-Reply-To: <20240419-hid_bpf_lazy_skel-v1-0-9210bcd4b61c@kernel.org> To: Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires , stable@vger.kernel.org X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1713538077; l=1849; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=/LAcqzfMdnZvAZXucskSQU6PgrY6Yvip45QZyOx1xEw=; b=lu1EPuWLunmFB5BNa2UVk8h2iuEuTCLoaDtaCSaoBiBBjalZ7wijs3fNFa7n0hhBxBbUGPHYf OY6tl7r6sNmDz1auSPrxNwagDSn5LNOpnYP/iXkwqf6hAFRP908s1ck X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= Turns out that on some professional distributions, with things partly backported (not sure exactly), loading this kernel bpf program might enter a RCU task deadlock. Given that it actually does not make sense to preload this in every environment, we can lazy load it the first time we need it, i.e. the first time the kfunc hid_bpf_attach_prog() is called. Cc: stable@vger.kernel.org Signed-off-by: Benjamin Tissoires --- drivers/hid/bpf/hid_bpf_dispatch.c | 6 ------ drivers/hid/bpf/hid_bpf_jmp_table.c | 7 +++++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/hid/bpf/hid_bpf_dispatch.c b/drivers/hid/bpf/hid_bpf_dispatch.c index 10289f44d0cc..1946ad962d03 100644 --- a/drivers/hid/bpf/hid_bpf_dispatch.c +++ b/drivers/hid/bpf/hid_bpf_dispatch.c @@ -642,12 +642,6 @@ static int __init hid_bpf_init(void) return 0; } - err = hid_bpf_preload_skel(); - if (err) { - pr_warn("error while preloading HID BPF dispatcher: %d", err); - return 0; - } - /* register tracing kfuncs after we are sure we can load our preloaded bpf program */ err = register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, &hid_bpf_kfunc_set); if (err) { diff --git a/drivers/hid/bpf/hid_bpf_jmp_table.c b/drivers/hid/bpf/hid_bpf_jmp_table.c index 301ac79db241..75ce215f0ada 100644 --- a/drivers/hid/bpf/hid_bpf_jmp_table.c +++ b/drivers/hid/bpf/hid_bpf_jmp_table.c @@ -404,6 +404,13 @@ __hid_bpf_attach_prog(struct hid_device *hdev, enum hid_bpf_prog_type prog_type, mutex_lock(&hid_bpf_attach_lock); + if (!jmp_table.map) { + err = hid_bpf_preload_skel(); + WARN_ONCE(err, "error while preloading HID BPF dispatcher: %d", err); + if (err) + goto err_unlock; + } + link = kzalloc(sizeof(*link), GFP_USER); if (!link) { err = -ENOMEM; -- 2.44.0