Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1731905lqe; Mon, 8 Apr 2024 20:14:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUIXpQHukYSg87VCg1kqWg0ImqtKKKSLAgUyOI9BnWKy+mEwLA+uj5Uy+/6bQm1xz2fyqBNMC0RiFg/+WtsI/5C9lg8Ry+vWT6XhnW74A== X-Google-Smtp-Source: AGHT+IE/SsWwJ85KWJlr+ddYmjpx9s+6HUm1yjwkVN8Z6Uj0vigc7VWQqQ0hII4Eqy6XI8BnnbW5 X-Received: by 2002:ae9:f809:0:b0:78a:3986:e7a4 with SMTP id x9-20020ae9f809000000b0078a3986e7a4mr2424063qkh.29.1712632465954; Mon, 08 Apr 2024 20:14:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712632465; cv=pass; d=google.com; s=arc-20160816; b=J+e5HiK1emQMwC9a/1uK9KYUY/U72NGeYUfrgKSLjIq+VhsmPB4Zh55d+KoA8szf84 ATNSkAFIKR0DZo68m+dQk5Hm/5mYP0z/6e1+/tU9dTzz8CdG/VO8vD3HeN1E/cD+o/ot dUmVzpNeel7BuQ08ZCwkMwYkL8eKNsfAWxYs37HAssBxcrEndwJajtZwmeE9FMcC06Hh d4XJJcSGAzdoMBOS4YG1+u8Seq97i0Qplkis0LRQmlSImvAKDUrC3lZrH9sO146pH4Cb SDpDva7aRfdb5Xsg1UK8r5TPdAR8fvfM9uJntCEs0MzXNUKJr565Eq7jc5X7PjZOdaRK JPhg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=u/w6jt9gT3BKa04bz0+7QHX98tgP06v5Gtwmcj913TY=; fh=X2jdMTah70B55lKRRyjn58PeW6BGyVgYzp7ZeHGo230=; b=gnxpGWY/1ucrjAUGVW18VmjxSwAWrz3/sUBA69uGMEFlkvs0Yd19ZYdZualMOGERsa oPT4M37fi9OqhsrswYB9S6Su9CMPkBnxE02exECc9Krex4rSl+GGi/aTSceU8k62Ani3 h4Nr+0QUZ1MlCO7C4M9ZxXSAGy7i2JrccX74RGIXPH2+SzZ0MG8FuMkD7//NxnyvlOuJ SDSCL93mG8w8Q5zv+zr2UbFm32zKrGTz8bfL+h6WdpFFOlZjZpj2ZCI6KEFGODFuDWhM KFsvs4upLjKOn47XwozZNikrXvc3ICs7FONnmxYM+IkvU6MWHKEg2rfYl9XRvR1C9uop S+Qw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Zljs23FD; 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-136177-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136177-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id bk20-20020a05620a1a1400b00789f1f0bc18si10073422qkb.477.2024.04.08.20.14.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 20:14:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-136177-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Zljs23FD; 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-136177-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136177-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id A03751C23D31 for ; Tue, 9 Apr 2024 03:14:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1635F54913; Tue, 9 Apr 2024 03:14:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Zljs23FD" Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 697C5657D4; Tue, 9 Apr 2024 03:14:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712632455; cv=none; b=PLi5uFZEIWa8ykM1sPDBr+h5bvN5r0mr/jVwgJ9f9MSB2vD5fewk135bsnzeNuIUUt3p7nMLXlMsYpkaX7W/3uqxaueR+I2F/oau4W5bJAOjmXIcJ3xqMoipNoBjOv4TTwAuSyJc3LrRgfR5dBCByyiMBgrc/ZuZJkg+p5Fp0fk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712632455; c=relaxed/simple; bh=CM4PqyEMR6sAaGtsGj1JayRPHeuY2qAqrJ0+o0qcKR0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=oWzCRsQMCK+OMbbyl+148MDo7jeRWxyHQZrfATDGxwU1uwdVLehyO8hjn6d2Keman9M/ro/4RTUR4wMpsk7OoP6T2f7orVfuhVYBpNC8h+G6NGJvb8/MK3malW+KSJb2fawvdwiuP4trKoe365q+E+QsUix/WRKVZFwEtFxVRKg= 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=Zljs23FD; arc=none smtp.client-ip=209.85.221.41 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-wr1-f41.google.com with SMTP id ffacd0b85a97d-345b857d7adso1113801f8f.1; Mon, 08 Apr 2024 20:14:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712632452; x=1713237252; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=u/w6jt9gT3BKa04bz0+7QHX98tgP06v5Gtwmcj913TY=; b=Zljs23FDROh83Bit3EfPHWhHE8HiA1l6oomi/RvXM74Qwae+sLWYWyU41sUTMy3W8U 1TnLGyGKhN5dtmbzN7kiKDCZa2UcolMjlXxNUdmzsMSHztsQJzLNawewkvKbEq82V06W VsAb7J1EVs1VU+eFDX34TNWydCyZgxAy3wFCDXulnZTRPnSFRcuNAX2J/R9n4IdtZtOP v00YNv1n8JbqDiT8T9ipUWVPnvdKM5tvsY4wP622Ek0nvO1wD1HOFoNgYXv+5bLFYpe+ qyRnL4sopLmrin6IGAKVII5p3jzDt4iP02a7/b3Y2kSwlPMvDcwmq5qWRNGtv1HsVPQ8 5O4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712632452; x=1713237252; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u/w6jt9gT3BKa04bz0+7QHX98tgP06v5Gtwmcj913TY=; b=vgBfsYc8IH8NMdLc1kSuvIlj5JjDkLXHy5z0DUd6wOUYXnensM++BJYDpWbFBah26+ E+8JNmM1kix5i9f7FpmNCZolBu3FaFhVC0P/sALU543hDnoLduBn7eU5sjtdSeDe0Wwf z6PoGASn/RrhyN11E19/aTYnhHsW2/mIFMqT0FmhN30YM0nllQY7cI2Epwg5guPrlDfR Z2578svuMONRe7Un0UU83hvYzaF0RY6sL2SiaioQ7gVPfUQMVwjTqgt7zilR0tiNrnNS RIqpP6Y0giuPWa+otfazaEpyjrm5/5bkzVdwf94HAJm1dfYCORB8So8IJcRwGUVke5P1 Tlsg== X-Forwarded-Encrypted: i=1; AJvYcCUEunxA88efBcuehSEKVUZw9SveYdnoMI/wWdshASL6fUb5LSscv/1Ozp8yBwU3hPbOc0j5IvieZjHdtlnsygevE6HllIhOT63O9Ozyi6PHEbWQ7eG41qQ1T1kso/SNTmPm747iQaXJbVwxC9AlNPvnrFx0Nt/pe0Xn420BJKX+izg7 X-Gm-Message-State: AOJu0YzGm0gAVcANyhLmt2KJzui0L0bdh7xyC15KqqkqT2BBp7qu58BW Ch0/FNKz47WNbzE1OJP70r1DGCSJZDaWNNyTDlv5s+yZlaayDij7zdqRiblbqETLiaGm05JTKRt Yd47dJNFOnWPV6eoqo+DqByx7cyk= X-Received: by 2002:adf:edc8:0:b0:341:e368:a50d with SMTP id v8-20020adfedc8000000b00341e368a50dmr7693182wro.18.1712632451619; Mon, 08 Apr 2024 20:14:11 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240408-hid-bpf-sleepable-v6-0-0499ddd91b94@kernel.org> <20240408-hid-bpf-sleepable-v6-4-0499ddd91b94@kernel.org> In-Reply-To: From: Alexei Starovoitov Date: Mon, 8 Apr 2024 20:14:00 -0700 Message-ID: Subject: Re: [PATCH RFC bpf-next v6 4/6] bpf/helpers: mark the callback of bpf_timer_set_sleepable_cb() as sleepable To: Eduard Zingerman Cc: 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 , bpf , LKML , "open list:KERNEL SELFTEST FRAMEWORK" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Apr 8, 2024 at 3:36=E2=80=AFPM Eduard Zingerman = wrote: > > 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. > > > > Signed-off-by: Benjamin Tissoires > > > > --- > > 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_verifie= r_env *env, > > > > 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_fun= c_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. At this point all subprograms are still part of the main program. jit_subprogs() hasn't been called yet. So there is only one 'prog' object. So cannot really set prog->sleepable for callback subprog. But you've raised a good point. We can remove "!in_sleepable(env)" part in do_misc_fixups() with: - if (in_sleepable(env) && is_storage_get_function(func_id)) - env->insn_aux_data[insn_idx].storage_get_func_atomic =3D true; + if (is_storage_get_function(func_id)) + env->insn_aux_data[insn_idx].storage_get_func_atomic =3D !in_sleepable(= env);