Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp798508pxb; Thu, 25 Feb 2021 15:49:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJyFfQBGSpIZzYWvFYmM0sjJrxCxr11VYmmE71VR18pWPBOjIc4cCMuU/aQ0xspsesPC+KQ2 X-Received: by 2002:a17:906:f9d8:: with SMTP id lj24mr153731ejb.200.1614296943338; Thu, 25 Feb 2021 15:49:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614296943; cv=none; d=google.com; s=arc-20160816; b=DAbvyWnx8jOax0P9RqDADr6MU/5ugt17J+fMZrHkw0pQPJp1x058Nlu31e4kzcUp8V GJXJxCWGGJvsJAeCONDkWyZz7NCjl+F3CWu56Y0FspYSQNRZtS1NnbtDzvI2MPqJZQHn n+ZVJQacthtRo93aZcPu3uqcaegEhS/OSUkIQa53/O/Tzun7B9OyA7PW4rj4jcQ6lwEW ElPeA4q5N3x8fBqciEe5GzA9nZfaQBLZSp19BpU0f40e7/+ZHsD6YK7QFmjkltZDqmFR D+SahmEsUuvWASduPVRpdBoR2r3nfvhYDWM4ImzuCRH1DRPA85ULmg6KU6HCZoFEdbub WBDg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xE5jfbmD7ggvOtV/7xXWeCQmjvzq79ebUAY3GevP7YY=; b=vhIrjhuzB7NRj9cmWW9c5r99D+XhUlczs9q+mfdRwGiIuK8tf8kNPKWVs1PNA6U5KJ T+PL1fpjW9PQ1iBUuaUXX/17UqclC0+fceqxkTflmE7MVNWY3WS1IJeSc//ghzW5NI5w xUwsm3bjZRE6EKdmDcWO9hegAV2BIy7Qq1TF+ttyfXbpXu5aEGV6WqAywg7faaEjO3+Y QsXD55Yepe2nYc7OVapbOp7Qofq0QXJvujzlokZnxwgYBSSjK9nbVWKOSbhJxntaOvOf tVx0bsMHRou3il2xs+SwKBdT5RfPvMD49gkgdV3qLiLhdqFlgdAAvRe/N4vi6OCK4g5F 2sqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=TvVQrF5j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e6si4811250edz.98.2021.02.25.15.48.40; Thu, 25 Feb 2021 15:49:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=TvVQrF5j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232778AbhBYXq7 (ORCPT + 99 others); Thu, 25 Feb 2021 18:46:59 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:9068 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229491AbhBYXoj (ORCPT ); Thu, 25 Feb 2021 18:44:39 -0500 Received: from pps.filterd (m0148460.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 11PNhvqb029205 for ; Thu, 25 Feb 2021 15:43:58 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=xE5jfbmD7ggvOtV/7xXWeCQmjvzq79ebUAY3GevP7YY=; b=TvVQrF5jlR1RUpcgWlU1hQo6+ncsVcwe1zpTKKpxyqIz5v45lDcmRI+oVnIeUlxLJ4Um 0eMUus1JqkPWHipxUuY8pLvz/DiqKSwVAszyBmPnfWQgVBwk5/rjbftrB3mkQBJJhUh+ OL2JnCzhDI721AA3APhv/z8PbuEgeSdgazg= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 36x9cavfkw-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 25 Feb 2021 15:43:58 -0800 Received: from intmgw001.06.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::e) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 25 Feb 2021 15:43:51 -0800 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 38A4C62E1BF5; Thu, 25 Feb 2021 15:43:44 -0800 (PST) From: Song Liu To: , , CC: , , , , Song Liu Subject: [PATCH v6 bpf-next 4/6] selftests/bpf: test deadlock from recursive bpf_task_storage_[get|delete] Date: Thu, 25 Feb 2021 15:43:17 -0800 Message-ID: <20210225234319.336131-5-songliubraving@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20210225234319.336131-1-songliubraving@fb.com> References: <20210225234319.336131-1-songliubraving@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369,18.0.761 definitions=2021-02-25_15:2021-02-24,2021-02-25 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 mlxlogscore=942 malwarescore=0 mlxscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 adultscore=0 suspectscore=0 spamscore=0 lowpriorityscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102250180 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a test with recursive bpf_task_storage_[get|delete] from fentry programs on bpf_local_storage_lookup and bpf_local_storage_update. Withou= t proper deadlock prevent mechanism, this test would cause deadlock. Signed-off-by: Song Liu --- .../bpf/prog_tests/task_local_storage.c | 23 ++++++ .../selftests/bpf/progs/task_ls_recursion.c | 70 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/task_ls_recursion.c diff --git a/tools/testing/selftests/bpf/prog_tests/task_local_storage.c = b/tools/testing/selftests/bpf/prog_tests/task_local_storage.c index dbb7525cdd567..035c263aab1b1 100644 --- a/tools/testing/selftests/bpf/prog_tests/task_local_storage.c +++ b/tools/testing/selftests/bpf/prog_tests/task_local_storage.c @@ -8,6 +8,7 @@ #include #include "task_local_storage.skel.h" #include "task_local_storage_exit_creds.skel.h" +#include "task_ls_recursion.skel.h" =20 static void test_sys_enter_exit(void) { @@ -60,10 +61,32 @@ static void test_exit_creds(void) task_local_storage_exit_creds__destroy(skel); } =20 +static void test_recursion(void) +{ + struct task_ls_recursion *skel; + int err; + + skel =3D task_ls_recursion__open_and_load(); + if (!ASSERT_OK_PTR(skel, "skel_open_and_load")) + return; + + err =3D task_ls_recursion__attach(skel); + if (!ASSERT_OK(err, "skel_attach")) + goto out; + + /* trigger sys_enter, make sure it does not cause deadlock */ + syscall(SYS_gettid); + +out: + task_ls_recursion__destroy(skel); +} + void test_task_local_storage(void) { if (test__start_subtest("sys_enter_exit")) test_sys_enter_exit(); if (test__start_subtest("exit_creds")) test_exit_creds(); + if (test__start_subtest("recursion")) + test_recursion(); } diff --git a/tools/testing/selftests/bpf/progs/task_ls_recursion.c b/tool= s/testing/selftests/bpf/progs/task_ls_recursion.c new file mode 100644 index 0000000000000..564583dca7c85 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/task_ls_recursion.c @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2021 Facebook */ + +#include "vmlinux.h" +#include +#include + +char _license[] SEC("license") =3D "GPL"; + +struct { + __uint(type, BPF_MAP_TYPE_TASK_STORAGE); + __uint(map_flags, BPF_F_NO_PREALLOC); + __type(key, int); + __type(value, long); +} map_a SEC(".maps"); + +struct { + __uint(type, BPF_MAP_TYPE_TASK_STORAGE); + __uint(map_flags, BPF_F_NO_PREALLOC); + __type(key, int); + __type(value, long); +} map_b SEC(".maps"); + +SEC("fentry/bpf_local_storage_lookup") +int BPF_PROG(on_lookup) +{ + struct task_struct *task =3D bpf_get_current_task_btf(); + + bpf_task_storage_delete(&map_a, task); + bpf_task_storage_delete(&map_b, task); + return 0; +} + +SEC("fentry/bpf_local_storage_update") +int BPF_PROG(on_update) +{ + struct task_struct *task =3D bpf_get_current_task_btf(); + long *ptr; + + ptr =3D bpf_task_storage_get(&map_a, task, 0, + BPF_LOCAL_STORAGE_GET_F_CREATE); + if (ptr) + *ptr +=3D 1; + + ptr =3D bpf_task_storage_get(&map_b, task, 0, + BPF_LOCAL_STORAGE_GET_F_CREATE); + if (ptr) + *ptr +=3D 1; + + return 0; +} + +SEC("tp_btf/sys_enter") +int BPF_PROG(on_enter, struct pt_regs *regs, long id) +{ + struct task_struct *task; + long *ptr; + + task =3D bpf_get_current_task_btf(); + ptr =3D bpf_task_storage_get(&map_a, task, 0, + BPF_LOCAL_STORAGE_GET_F_CREATE); + if (ptr) + *ptr =3D 200; + + ptr =3D bpf_task_storage_get(&map_b, task, 0, + BPF_LOCAL_STORAGE_GET_F_CREATE); + if (ptr) + *ptr =3D 100; + return 0; +} --=20 2.24.1