Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1639284lqe; Mon, 8 Apr 2024 15:36:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVI1Wy3pRfOjw9Bt6qUj4fwi6Ui1zlmbyRn3WapNjgluwVy3Y0iAJCyriwLoCGXQ84P0906B44ctm62yBTQp7TkS9LmdmiiBSFGAS34VA== X-Google-Smtp-Source: AGHT+IFQs+vmZnhUQfCsCzPFNX5f0w03ElKzg90z8pYZZgL/nuYLy5R4eSme9dQexquvAzu2ARlD X-Received: by 2002:a50:c050:0:b0:568:1248:9f49 with SMTP id u16-20020a50c050000000b0056812489f49mr5843793edd.18.1712615774554; Mon, 08 Apr 2024 15:36:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712615774; cv=pass; d=google.com; s=arc-20160816; b=jJmOMQsZillGUckWayIaQ3a3gJotK7Kb9ZlIAaomcbjKas0n1SWtAOHAhvRy3VUExY lE9Tk1RfYwIpKVWzFnThFPqpcAS32r7y7ygxzoTmU3e4FgGOMD02e+mcP85UGT8jNw8x PP8seDghKPxiyq4RxpTLIed7AKIUcuI+KUvFrmeLtfmNRT6mZr32K/UfpASa+pOuWY+W kFrRln7BfdnxlfNbJMUxa0Pr10eX3xTjstWBZ8a6hhd6hswYNMlDAZcxGfq5rgSwEU2+ HSTxkt7t2Tlj1591OZovD0nWMWDcZBHaqhC5Xbl67ySP2mXoGGAMTQ0WV8kPhODbGEfk a2Wg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:content-transfer-encoding:references:in-reply-to:date:cc :to:from:subject:message-id:dkim-signature; bh=QzaOLKxDboX4yOy570vjmU1pifeDoG6kHY2U+WBIbU8=; fh=rizYILf/QWanJ0eEGDC7PHNhQgCSO2+SQnOcfIIaHvA=; b=ywH93GeGoy5C1Z2viPv3gdtBbIvj2FAtIEvKP0cbiam+3AKNI+58LqkhdAV0brFWYr 4eKy2szJ7Q5M6tfHl2CxFJXTkSluFISD046nul2uqXO+CHIo+JDY+Zged2vrOgX+mC3d SsmiCgbarzyOzMoyAcSz3XY0hdFR9KQzSzCWDY0qnBZPvjytPrXFOqaMbunodokekekk /8aQGbAFsXboBt5y+qEBzDSzw9ToaMW1M+ypRumdhCVyzmH3EjeK69vNdlJGiVMn3sTK aQmNmWdpmotedgZWj4swJUonCYZ7v3Nd8TYU6np+HtHZ7ErRRrFg3HzSLUxv8nLFNFx+ HtLw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=SH145i7H; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-135976-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135976-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id s21-20020a508d15000000b0056e51c19bf5si2237599eds.170.2024.04.08.15.36.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 15:36:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135976-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=SH145i7H; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-135976-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135976-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 459E51F2365F for ; Mon, 8 Apr 2024 22:36:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F285C29CEB; Mon, 8 Apr 2024 22:36:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SH145i7H" Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74FF01A5A2; Mon, 8 Apr 2024 22:35:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712615761; cv=none; b=DwFLerX3ZBn5/4xunAB+6kloDfOMjANgY8xMvFHP4Ihd0qAayPZe0fVFCwnCnysxBP5iwDiuJKQKgL0I/pJ6GvP/WNn7sGqrGcoHxyU14W+lYnGKvGnhZcik6F99OXm2eK/lKPmfcaaOQkCUrNSQxexZBIimX2k7zZcnaQVfMQU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712615761; c=relaxed/simple; bh=3cPal0PcyBF+aiN/zwbK05iiWVn1zNZFAKQzLfq3x8M=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=iPNo9onvc0HgXqsTZ2cQGZaPUsYBXPOr7O8Nw8lmohiwLfQC9ls9KEtAPeHV/yUmJnlxmoqVhymRX9a4C0L4Ul2WV4ywDSnP+fejnkDNpVB6qdhvj0aRP+xVCkZ61iQyOmFfhKmYwkgUztq4BYxZprp0zEdDSvIcIXzjarFYFt8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SH145i7H; arc=none smtp.client-ip=209.85.208.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-2d6fd3cfaa6so63890291fa.2; Mon, 08 Apr 2024 15:35:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712615758; x=1713220558; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=QzaOLKxDboX4yOy570vjmU1pifeDoG6kHY2U+WBIbU8=; b=SH145i7H7u3jMlfuRViGkC3qVhnfzU6dMU67780b0vMT/VI03e4bdhG/uasohW+lfh 5E54Y8IxlmRrRZhx+NFmZbSOZtiKgbwHnHtda9gRfVlsJv6jEWKQNlHlS3NL1AuC14RW NlXx30rm7zPjHqX6+J4hInEO7H1IVUE7EzH6A0ZT6+k8uwyJST9hMdFaeUSLykppupnv C4ZsaGbtgzfgYE4OzGrLLQGZyHUoJsAvCKVHoIac8XdPydlT6Yu7XkchJlga5j9V2kV9 3PenCoCzkknqXqGxbE90N8b8iZkMmreKbfWcnCPYHnW2gjFcugFcUA8t0BrKWZKNV6bK TQjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712615758; x=1713220558; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=QzaOLKxDboX4yOy570vjmU1pifeDoG6kHY2U+WBIbU8=; b=InNFDKxDzCYh1QAlX+cOmjb6wD7dbZRDLQhpNEj8Bd+qN+vSR7fFYgXrS5l9eOuXMO vLaOmJeDe2iADvboKujpGFaM7EXHIG7D9mDrRIv6U8tzP0O2f0vg9v/cr5L9D+wGdyGO m44CH1OUqSYijd+5tdaZOuWteb80xZ5KxuJ9aWmXADeLMRagIwoWI6RYtPKMeoyaCTUf hftcOgavHr539zDcistY4P1PjZlxwKrZDgjBkgDEut2/YWVKcm7NhQPPpbuJIZnOaOlQ hv08YDS17AE4BXR4zDTbLz19jqnXqV0yFuB+C1ODftnlMif5UvEmiokOoVhwRqWqtbVM l//Q== X-Forwarded-Encrypted: i=1; AJvYcCV6yIv7Gm3hcpCxHrfy3BG0MYv23jRiYK2ssskH5V0oq+TYBqBql4OOgvekqyhWg/m7pM1Q2B4dMTBlKRGhLyRAo9bRGtYASzXwf6wvQkwzmhodqq4A4QoEaqBxDeYSuAB4Sd9Mz9+BXv6tizdI X-Gm-Message-State: AOJu0YyF5pMpp5FhEK41HiU0mfHPuPIA40nq/M4Nxcth03rXb4gW7pZn z8sY/dYNcI3w2/WUH4evV8wQ7ZEQkBUduoxRQyQZlCiiZMcJw+t0 X-Received: by 2002:a05:651c:1422:b0:2d8:6467:1a13 with SMTP id u34-20020a05651c142200b002d864671a13mr5848323lje.30.1712615757343; Mon, 08 Apr 2024 15:35:57 -0700 (PDT) Received: from [192.168.100.206] ([89.28.99.140]) by smtp.gmail.com with ESMTPSA id y13-20020a056402358d00b0056e031bb5efsm4544308edc.47.2024.04.08.15.35.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 15:35:56 -0700 (PDT) Message-ID: Subject: Re: [PATCH RFC bpf-next v6 4/6] bpf/helpers: mark the callback of bpf_timer_set_sleepable_cb() as sleepable From: Eduard Zingerman To: Benjamin Tissoires , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Date: Tue, 09 Apr 2024 01:35:55 +0300 In-Reply-To: <20240408-hid-bpf-sleepable-v6-4-0499ddd91b94@kernel.org> References: <20240408-hid-bpf-sleepable-v6-0-0499ddd91b94@kernel.org> <20240408-hid-bpf-sleepable-v6-4-0499ddd91b94@kernel.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Mon, 2024-04-08 at 10:09 +0200, Benjamin Tissoires wrote: > Now that we have bpf_timer_set_sleepable_cb() available and working, we > can tag the attached callback as sleepable, and let the verifier check > in the correct context the calls and kfuncs. >=20 > Signed-off-by: Benjamin Tissoires >=20 > --- I think this patch is fine with one nit regarding in_sleepable(). Acked-by: Eduard Zingerman > @@ -5279,7 +5281,8 @@ static int map_kptr_match_type(struct bpf_verifier_= env *env, > =20 > static bool in_sleepable(struct bpf_verifier_env *env) > { > - return env->prog->sleepable; > + return env->prog->sleepable || > + (env->cur_state && env->cur_state->in_sleepable); > } Sorry, I already raised this before. As far as I understand the 'env->cur_state' check is needed because this function is used from do_misc_fixups(): if (is_storage_get_function(insn->imm)) { if (!in_sleepable(env) || env->insn_aux_data[i + delta].storage_get_func_atomic) insn_buf[0] =3D BPF_MOV64_IMM(BPF_REG_5, (__force __s32)GFP_ATOMIC); else insn_buf[0] =3D BPF_MOV64_IMM(BPF_REG_5, (__force __s32)GFP_KERNEL); insn_buf[1] =3D *insn; cnt =3D 2; ... } For a timer callback function 'env->prog->sleepable' would be false. Which means that inside sleepable callback function GFP_ATOMIC would be used in cases where GFP_KERNEL would be sufficient. An alternative would be to check (and set) sleepable flag not for a full program but for a subprogram. Whether or not this is something worth addressing I don't know. [...]