Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp570297rdb; Tue, 16 Jan 2024 08:58:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IE6+JkqY4vmRlpcyckXwdUFwVmMAoU2KPJVjO9JAB/jlAkksJQtSLbWfDbbShSSMgHaCZqg X-Received: by 2002:a05:6214:29cb:b0:680:3fa5:4b39 with SMTP id gh11-20020a05621429cb00b006803fa54b39mr6993685qvb.114.1705424298059; Tue, 16 Jan 2024 08:58:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705424298; cv=none; d=google.com; s=arc-20160816; b=fPlWb4uLfOHhU6oD/K3hrahGax6kPG2u9ehCZPagawTqWpZbN3Iy1oFoLQgxhS371b gHXj76nK66P5mIf9qsQ4vH/rpwjWGp6PwrnCm5+lDfVA9jC4OpsNxjrfxsvzwodpbGLQ ZEzcqOA8YiSG6E8fOnjGvr5FF80CGXTnxYDcpyD5zltlFEGXp07HcTGhmQQiKGqaSuCe 8it+qEPrptp/+lR3M+orT2QmIsq3JbZIoE0KR4XY+3b0KY63Irb5aTWT8RhU96lpELNu FtFzBDZxGK3IaYaAKEsR8so2/EC1WVk1fY4cMx325XwDnHpePEkr+2KtJZs58jWFFdb8 oU2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:date:from:dkim-signature; bh=hWIMOxwPuwlyypi9mGRlB1wNl0jlfrKw1ScuZdtPpAE=; fh=r4WES5lm3VjRGpJk1LUrovzhOBQe+GBPcR6TbvCqpcw=; b=rodQS65X7CUoVK6DIAGNulVjCjsEUqFbaulwCWsJ4FXuxexlLS5vrJiHp5MV6V+pXi fNd3O/IRfHtPF7PC3m1NResLHx9a6Xqk0qBDSHyklr673I2MDfscNQjHwLfxWR1vOMWb +Ack1gSF9dcYnkMThqeSuNaLi8GQ0yuxkNl/5t9sSQcWVKtzKjuZAoEVf4fGU8rUk9iS VOhICU7jN6Udr697RuRnZdhLnOo3/KXmmFVRLP4T1r34SqZQRPEzl108Hb4CcY6XOdxJ BcrEuCsczxk99rxvZeA2JaQGgtAt0FBMsKHeiTpDwmebld59vxtgLGwbYQ6lvJthT3dQ OmPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=iJ4pRd6x; spf=pass (google.com: domain of linux-kernel+bounces-27598-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27598-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 k2-20020ae9f102000000b007835c11b0b9si4508839qkg.418.2024.01.16.08.58.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 08:58:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-27598-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=iJ4pRd6x; spf=pass (google.com: domain of linux-kernel+bounces-27598-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27598-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 CC9841C237BB for ; Tue, 16 Jan 2024 16:58:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2BFBD1CA9B; Tue, 16 Jan 2024 16:58:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iJ4pRd6x" Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 CCA381C6A1; Tue, 16 Jan 2024 16:58:04 +0000 (UTC) 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-f52.google.com with SMTP id ffacd0b85a97d-3366ddd1eddso8211063f8f.0; Tue, 16 Jan 2024 08:58:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705424283; x=1706029083; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=hWIMOxwPuwlyypi9mGRlB1wNl0jlfrKw1ScuZdtPpAE=; b=iJ4pRd6xT/iZA0xUDuiNyKnNuxPjyrb+y0dg1DUodjolwttlJibv05ZLkLL6+3gKD3 0zpkPkM+3JvxcVNrqIvpY5V5eOYK/2nrKPxQf83UIBkxMRebE89lvbcKsSn6TwyCzhXh NiuPFXkVTIZ9APRuDOrJOVWWQnwdrC5z/1yFImsAxNpYCcbtt16zBxjIhsLCFx5XMF0W lKP4f7WHj50jjsr4r92UHwYgOsOYCrqdJDY1paSfS6p3YCrx8HDA3nFkxrMS6aLqv/p7 PVQ7tR6g5VQZXfoIOazul/LAqAFhDl+tNk2QOgvyJSXrxLsD/ctQpEmOF0mTFCmSnHkN 2YTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705424283; x=1706029083; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=hWIMOxwPuwlyypi9mGRlB1wNl0jlfrKw1ScuZdtPpAE=; b=Pn0GM/BnPhjvmGoo7LTZFwfqkPNI2QZ7NJylHmOEYw5BE8kDvwDPbDtJ265lkrIY63 rDcnM+CzNFLRqhSwEyLCcn4OwBLCzgVjoVnaMoUCaxH3VwFNRwqrlkGu7y362xKKxaiK /RJzC/SYu8qb79nKqR7l4Q5b77xYsXmhT9Yaih6CDdumIvWqkLw1zR4b8WhFJXJG+52a fyZk/WhexuWFdhettmt6OZo7rl503/vwd35zXcWzzcjREvr+sndkM7a4mRWsjzrGcEd5 W8eHzKhyF6xKXTVDbXqe7EJq04h0WULoRI2v/8LoEd4BF3U2nT6PV06TpxAlqULBgK4F oNoA== X-Gm-Message-State: AOJu0Yy/oNVHxiswgEBPJIrqc2WWX+xWzsGvBg9BTyG4x/d6Kf9QLGSn LJVAz7S0MH1AYNI6dxFMH6U= X-Received: by 2002:a5d:5943:0:b0:336:608f:91eb with SMTP id e3-20020a5d5943000000b00336608f91ebmr2017052wri.95.1705424282738; Tue, 16 Jan 2024 08:58:02 -0800 (PST) Received: from krava ([83.240.60.213]) by smtp.gmail.com with ESMTPSA id co8-20020a0560000a0800b00336755f15b0sm15100243wrb.68.2024.01.16.08.58.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 08:58:02 -0800 (PST) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Tue, 16 Jan 2024 17:58:01 +0100 To: Artem Savkov Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yonghong Song Subject: Re: [PATCH bpf-next v2] selftests/bpf: fix potential premature unload in bpf_testmod Message-ID: References: <82f55c0e-0ec8-4fe1-8d8c-b1de07558ad9@linux.dev> <20240110085737.8895-1-asavkov@redhat.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <20240110085737.8895-1-asavkov@redhat.com> On Wed, Jan 10, 2024 at 09:57:37AM +0100, Artem Savkov wrote: > It is possible for bpf_kfunc_call_test_release() to be called from > bpf_map_free_deferred() when bpf_testmod is already unloaded and > perf_test_stuct.cnt which it tries to decrease is no longer in memory. > This patch tries to fix the issue by waiting for all references to be > dropped in bpf_testmod_exit(). > > The issue can be triggered by running 'test_progs -t map_kptr' in 6.5, > but is obscured in 6.6 by d119357d07435 ("rcu-tasks: Treat only > synchronous grace periods urgently"). > > Fixes: 65eb006d85a2a ("bpf: Move kernel test kfuncs to bpf_testmod") > Signed-off-by: Artem Savkov > Acked-by: Yonghong Song Acked-by: Jiri Olsa jirka > --- > tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c > index 91907b321f913..e7c9e1c7fde04 100644 > --- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c > +++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c > @@ -2,6 +2,7 @@ > /* Copyright (c) 2020 Facebook */ > #include > #include > +#include > #include > #include > #include > @@ -544,6 +545,14 @@ static int bpf_testmod_init(void) > > static void bpf_testmod_exit(void) > { > + /* Need to wait for all references to be dropped because > + * bpf_kfunc_call_test_release() which currently resides in kernel can > + * be called after bpf_testmod is unloaded. Once release function is > + * moved into the module this wait can be removed. > + */ > + while (refcount_read(&prog_test_struct.cnt) > 1) > + msleep(20); > + > return sysfs_remove_bin_file(kernel_kobj, &bin_attr_bpf_testmod_file); > } > > -- > 2.43.0 >