From patchwork Fri Nov 5 16:50:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Maguire X-Patchwork-Id: 12605129 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07DEFC433F5 for ; Fri, 5 Nov 2021 16:51:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CD65461037 for ; Fri, 5 Nov 2021 16:51:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233440AbhKEQyb (ORCPT ); Fri, 5 Nov 2021 12:54:31 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:30704 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231288AbhKEQy3 (ORCPT ); Fri, 5 Nov 2021 12:54:29 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1A5Ft67X003132; Fri, 5 Nov 2021 16:51:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=f4+r/oMKCTcZ9dHu4ictO+LSuAIJVI1YzP5kz9TYqvo=; b=fusvqjIEqP3h7TeYqhNOniO4g4L+DYQxyhJFSgg/HHNZKGj8N8F0LgoiHkBUAMmsDJiT QYdXkqIkf2btzGIbUuouKTNU8Fqm0a/fHeBf09cj52+xiJrU6QsNoetQdd4mZnwqoWOg hgMjt7/VF45HVcFsAxz53hWg+V76Lpa+zbuMk9izUJBLtmn9f3kUxrzGcexQZ1HRHAqn WRqHFEwPksS/yUGDK72WN1q6w4pAu9WZ2GMk7sR8hBcb02TcU1x8okaIhgi22lQsuphH qP4l5ZZS2wteYeYz8JCcLdQJp+HVsNQnLdYFVQrDryuOI2Hl77j8B91Ayb908gqo19if bw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3c4t7bug0p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 05 Nov 2021 16:51:06 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 1A5Ge5aF116448; Fri, 5 Nov 2021 16:51:01 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2171.outbound.protection.outlook.com [104.47.57.171]) by aserp3020.oracle.com with ESMTP id 3c4t5smde6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 05 Nov 2021 16:51:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gi7KqRLgr/yUxpBv8h19ZClz+W1NFiNe03PZmRp6tnqnYf+B2suzWg2Emfj78tdioEXDPgRVkeYMlm7r2bX5tvlwZeVsbtIwiPUpnceMLPBbYoB1PaqwKW78QQHogIvQZfSh2L3eRc4wAoBfx+yhOOtGPuIpsDdb2sGE4XbHLxWHuhEt8mG3bR/JuQk1awxOEpXvrwcrZ0KHoRosQkeGt+x/Ua+9DK5k1hHWz5ETt6BPEGHvrjTZe8RKh3x+mhFsOUkHnfPf7hdSEfJx9Nl6Cob1b8tqJg1vFbjZGGiq1BhVTLo+M11OQtfNMCgjvBUOnAgbObfvBDEguX/uJpwuHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=f4+r/oMKCTcZ9dHu4ictO+LSuAIJVI1YzP5kz9TYqvo=; b=BYuYACWM+zZdGBeEZQzgo7BWoaxVoov6xwIivevhfAbEPgq/UW96E3CpQlf5JTqSlh0jUPUkYtD1VYGkyeSJ82/1KM58g/3izL4orZRIl0yn60iXJuj0NUx5bDFHjsOuzaDAYKW62uEm+9WTAmJ+IE1d7x5sNtT8fLoqNTM5tLstSO2bNNde/rHYNkl9N1+xyza7mGzuWxwhnyRKHRPC0TwtYvg88LBuwxvM+efGN1TO6G3WW81a5fUnmWTuH+tQ+794oc4Vp/mcPcOnax+Fa2/QRoRjZ7XiDpPUnbtesc47iXRea7Ok4XXR3cCeY1axNIRTAnHd5S836wTT5KbNhw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=f4+r/oMKCTcZ9dHu4ictO+LSuAIJVI1YzP5kz9TYqvo=; b=urr0aYJm59yNe25JUHQCko57HotvypTyuMpig7DhQ6WM/fkDT9cGPUMkNHtO5FoKR4q6OsBFZXpNjUExqnR4G8ss8TJJ/YUmYNLPKHElCKd8QMGKdHTq3tSCQm3um+whQkqFvdAzD3bzmIHGoOfkg8MEhPLQms+EljQR/6FOiB0= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BLAPR10MB5267.namprd10.prod.outlook.com (2603:10b6:208:30e::22) by MN2PR10MB3213.namprd10.prod.outlook.com (2603:10b6:208:131::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.13; Fri, 5 Nov 2021 16:50:59 +0000 Received: from BLAPR10MB5267.namprd10.prod.outlook.com ([fe80::998f:e9eb:ec26:1334]) by BLAPR10MB5267.namprd10.prod.outlook.com ([fe80::998f:e9eb:ec26:1334%7]) with mapi id 15.20.4669.013; Fri, 5 Nov 2021 16:50:59 +0000 From: Alan Maguire To: ardb@kernel.org, catalin.marinas@arm.com, will@kernel.org, daniel@iogearbox.net, ast@kernel.org Cc: zlim.lnx@gmail.com, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, andreyknvl@gmail.com, vincenzo.frascino@arm.com, mark.rutland@arm.com, samitolvanen@google.com, joey.gouly@arm.com, maz@kernel.org, daizhiyuan@phytium.com.cn, jthierry@redhat.com, tiantao6@hisilicon.com, pcc@google.com, akpm@linux-foundation.org, rppt@kernel.org, Jisheng.Zhang@synaptics.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Russell King Subject: [PATCH v2 bpf-next 1/2] arm64/bpf: remove 128MB limit for BPF JIT programs Date: Fri, 5 Nov 2021 16:50:45 +0000 Message-Id: <1636131046-5982-2-git-send-email-alan.maguire@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1636131046-5982-1-git-send-email-alan.maguire@oracle.com> References: <1636131046-5982-1-git-send-email-alan.maguire@oracle.com> X-ClientProxiedBy: AM9P192CA0024.EURP192.PROD.OUTLOOK.COM (2603:10a6:20b:21d::29) To BLAPR10MB5267.namprd10.prod.outlook.com (2603:10b6:208:30e::22) MIME-Version: 1.0 Received: from localhost.uk.oracle.com (138.3.204.60) by AM9P192CA0024.EURP192.PROD.OUTLOOK.COM (2603:10a6:20b:21d::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.17 via Frontend Transport; Fri, 5 Nov 2021 16:50:55 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b20b62be-0f9e-4770-d658-08d9a07c7170 X-MS-TrafficTypeDiagnostic: MN2PR10MB3213: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2887; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: etxdappmNFPZDR9ayu9mxEi1glogcWankCHmfmrsnEvbzOYj33c+umtyab3K2wbXVn4ZPNRU7L/g5MfgE6HUOARfxxSHqVr8jVzmto6lQ7vxeAIfly6W9qKQLxbWH2EK/iIIzKtSUz4BQsMdLiOAmZxHJhPavJBmOPpAvoWJBWmu0aVBQLSckqhAX/eHDjiseaZPqMXfYrz44YtIUjRysNZBc3BSxyfxAp6cll+rjoMI4G+/+MdTrUsUaXIzABL4uv+0WUySxqBeL4A9yxRfYIGzIjkzinn2Lnavjjumh/qFlxfemBTXl7Y3z+A3wrwCJRq45Yo/kKxYWqA9Co7FOVkdUX82nFUd2ELGhUewBNppJ59HmYuhuMFDzEOYuOAyR6rIEE2rJQGvt9cnVlLmCZJY4bzclpcPCShtPQ4EeyPFhMEQtz8aKPnXXSLFYcv3j8PPEW+6kniIzJYn+9FlwhuccXCJrtJ//jhnvoxyhKbmXydoO9YYpioMQ+U48BRZWh+7GGQAc+quRURb3pYpGreu6qN4dZUN6pzhGi423cICvoel8a42lDs64e0Z1pWi7BZpj2CC5lnum3lIembJRX1B54e647ZzjeCLZ8/L6yrgxaAR4Sl20pkXpfvLwWbEw/8gFoTxuTx/hT/He8cVQXP7vt7QJYob6FhRro+A2EEz0GNR1v21hC3gqphtg1qLv3KVs3NhuYe13iEBBVJrEg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BLAPR10MB5267.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(186003)(8676002)(44832011)(36756003)(107886003)(2906002)(956004)(2616005)(66946007)(508600001)(66556008)(66476007)(316002)(4326008)(8936002)(38350700002)(83380400001)(52116002)(7696005)(6666004)(38100700002)(5660300002)(86362001)(7416002)(26005)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: i9pnrORL1u8t2uLQSFT+esrdpHrA3VOs4UUSNtUXta2fCN8tdM80vSXkIkWNKqjjw/646rw81xlGCJUMcplcqXzHcumHRHReTDpAFNTN+HJdyOmNSiiDEOvq8pcjVPsBjeIgY7pdqO0+2dy6bOKy9gh/x8D/xbwEyb7mmkvxqpZgNcYQUU1r2hJdOYiBoJ7gbw+WuoaPOJIkcgkg0/4RfLh9zkXTFIUZmiIMZhm/SzRrG3LlXFS6brvibigvQ/wsexJgYZM2J6s1rH78TZjsYPJIg/3YoNAhxI2arqeil2xgOZqFRbV5/C9Ynws38x+djYd9qUcJkt2mnRBRq7Uvzt+oeuo2w3+/VQ4FWFBWuyDcGVuYEkJ0ds7TpTaaEQbEwEyKmIuw86Sah+Pb/ficeyFyOL9Hahsv/C49fnLWFrcyP69iL7/CTzRP8Z7R7OSlzfO2enFRG4t4dbWYpE//aZZfD3vjSNMVW2fnS3I23/8KZwIlE2mFpKTuf/qT1GhHCkfUNA/PnO69EcQDlzmnA4Xr7Z6hmGaI4Ky+f1a3dAJpOwREka7T3JZL6tTRnjAPHMUS3fdWmrYzcjNnYAUX9fF+3N/4AW4AqR/DDdt22Econ+g8Nfawi8GR2SoDiPFTzrYEUj51uENYQnyvJR5cBLgE36XTY8cjUiFGw9V5eHxh+DkBBOW0l8dFunrCLIUyjq8s/DILIpCe2VStQYQZtVgFaspEhWABYc7hNAFF51GOrlI2ZWgs1+GYYhoaXYyuSZd4aazqlU9O6yEAe4pCykqcSfS5YF4zW4r9udLu483xm1H3Q8gz/cC7rYvm4bgKai/j8hucAW403Km76y0kdeVITINY2oWTAXADSot42ggs6qqAfIZRRwDn0DgTDEnDcP9RJcGits+nxzSlLw60bNT5nmQhEbOJsQ0EogN/4p8LNXmb1xVA3OlhdbwSVtRTU6j+LYgERn2ztDCxGFNnJb/M7KpVuKWKPiFXFit6TpUQyl+GSeM6zMPwoqm2MlpX0a0hHyGFARozNBjOvbmDCzZaXa80oi1vTkWxLe25rfBBUY/ZEaqcYHHmh2YKIRQY/k11UrRieAXEGFEi4OSfbI0XK1UMEXDQNbhH96uaNjLRSPW6IPT2LW0j0bAPRikttKmPe7ubfNtB3448Dj3u+BV/ONQmQ2FW/q4aOCIB27OqThiplXHbtDjnPxbAisXGxoESoe9pilWUzJqKDM7bQjEU9W4+b6qFRenTuVQPRjp+TJplqVYfXdWW6NvpbhYL5tYLO1QKoLQ+tJdHxig824o8pjwSMunRo6Arn6l7KAMmhn+xP6301J3Al/MsXP7FPWVx7EY6sObR81QzBIZ26WCAkdRbUanbubIwFunR93CaOxLSBFDa4GSjFs33AHu14BOgXB+rfqeNdFaLtH9C7ocNwd7AnZo6QMdAWqBGgfkQtFZTVZhMKdjWmwp0I6f7ddIv1xcLYVfJj8V8FAA6zfs0IGGa1nX/BdqybozSPuYR/LsNkdmdthvB9zOzxSLMxALC0nVRn0kL3N968ZJ6CsCA7RqkiuhvdDJUgkYhjnIaOQSeBd7SeVRG+u2qmV2lEPoZcrafIKJpVkz8gKWozm+JwZD68JgBGZCuQ7qhmhA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b20b62be-0f9e-4770-d658-08d9a07c7170 X-MS-Exchange-CrossTenant-AuthSource: BLAPR10MB5267.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Nov 2021 16:50:59.2132 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dlPmLhvkCaQkrlef9BuDOk7hufNr3qoF8Owyp5GoQ8eLF+kE4DrSXihVD7Eq2WNkWpXddFrTXXh8zFxc/HPjzg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3213 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10159 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=0 bulkscore=0 adultscore=0 mlxscore=0 spamscore=0 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111050094 X-Proofpoint-GUID: K7nSrEz0rhJ66NzgQRPlW0ixfhG_BYAA X-Proofpoint-ORIG-GUID: K7nSrEz0rhJ66NzgQRPlW0ixfhG_BYAA Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Russell King commit 91fc957c9b1d ("arm64/bpf: don't allocate BPF JIT programs in module memory") ...restricts BPF JIT program allocation to a 128MB region to ensure BPF programs are still in branching range of each other. However this restriction should not apply to the aarch64 JIT, since BPF_JMP | BPF_CALL are implemented as a 64-bit move into a register and then a BLR instruction - which has the effect of being able to call anything without proximity limitation. The practical reason to relax this restriction on JIT memory is that 128MB of JIT memory can be quickly exhausted, especially where PAGE_SIZE is 64KB - one page is needed per program. In cases where seccomp filters are applied to multiple VMs on VM launch - such filters are classic BPF but converted to BPF - this can severely limit the number of VMs that can be launched. In a world where we support BPF JIT always on, turning off the JIT isn't always an option either. Fixes: 91fc957c9b1d ("arm64/bpf: don't allocate BPF JIT programs in module memory") Suggested-by: Ard Biesheuvel Signed-off-by: Russell King Tested-by: Alan Maguire --- arch/arm64/include/asm/extable.h | 9 --------- arch/arm64/include/asm/memory.h | 5 +---- arch/arm64/kernel/traps.c | 2 +- arch/arm64/mm/ptdump.c | 2 -- arch/arm64/net/bpf_jit_comp.c | 7 ++----- 5 files changed, 4 insertions(+), 21 deletions(-) diff --git a/arch/arm64/include/asm/extable.h b/arch/arm64/include/asm/extable.h index 8b300dd..72b0e71 100644 --- a/arch/arm64/include/asm/extable.h +++ b/arch/arm64/include/asm/extable.h @@ -33,15 +33,6 @@ struct exception_table_entry (b)->data = (tmp).data; \ } while (0) -static inline bool in_bpf_jit(struct pt_regs *regs) -{ - if (!IS_ENABLED(CONFIG_BPF_JIT)) - return false; - - return regs->pc >= BPF_JIT_REGION_START && - regs->pc < BPF_JIT_REGION_END; -} - #ifdef CONFIG_BPF_JIT bool ex_handler_bpf(const struct exception_table_entry *ex, struct pt_regs *regs); diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index 1b9a1e2..0af70d9 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -44,11 +44,8 @@ #define _PAGE_OFFSET(va) (-(UL(1) << (va))) #define PAGE_OFFSET (_PAGE_OFFSET(VA_BITS)) #define KIMAGE_VADDR (MODULES_END) -#define BPF_JIT_REGION_START (_PAGE_END(VA_BITS_MIN)) -#define BPF_JIT_REGION_SIZE (SZ_128M) -#define BPF_JIT_REGION_END (BPF_JIT_REGION_START + BPF_JIT_REGION_SIZE) #define MODULES_END (MODULES_VADDR + MODULES_VSIZE) -#define MODULES_VADDR (BPF_JIT_REGION_END) +#define MODULES_VADDR (_PAGE_END(VA_BITS_MIN)) #define MODULES_VSIZE (SZ_128M) #define VMEMMAP_START (-(UL(1) << (VA_BITS - VMEMMAP_SHIFT))) #define VMEMMAP_END (VMEMMAP_START + VMEMMAP_SIZE) diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index 7b21213..e8986e6 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -994,7 +994,7 @@ static int bug_handler(struct pt_regs *regs, unsigned int esr) static int reserved_fault_handler(struct pt_regs *regs, unsigned int esr) { pr_err("%s generated an invalid instruction at %pS!\n", - in_bpf_jit(regs) ? "BPF JIT" : "Kernel text patching", + "Kernel text patching", (void *)instruction_pointer(regs)); /* We cannot handle this */ diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 1c40353..9bc4066 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -41,8 +41,6 @@ enum address_markers_idx { { 0 /* KASAN_SHADOW_START */, "Kasan shadow start" }, { KASAN_SHADOW_END, "Kasan shadow end" }, #endif - { BPF_JIT_REGION_START, "BPF start" }, - { BPF_JIT_REGION_END, "BPF end" }, { MODULES_VADDR, "Modules start" }, { MODULES_END, "Modules end" }, { VMALLOC_START, "vmalloc() area" }, diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index 3a8a714..86c9dc0 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -1141,15 +1141,12 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) u64 bpf_jit_alloc_exec_limit(void) { - return BPF_JIT_REGION_SIZE; + return VMALLOC_END - VMALLOC_START; } void *bpf_jit_alloc_exec(unsigned long size) { - return __vmalloc_node_range(size, PAGE_SIZE, BPF_JIT_REGION_START, - BPF_JIT_REGION_END, GFP_KERNEL, - PAGE_KERNEL, 0, NUMA_NO_NODE, - __builtin_return_address(0)); + return vmalloc(size); } void bpf_jit_free_exec(void *addr) From patchwork Fri Nov 5 16:50:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Maguire X-Patchwork-Id: 12605147 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2AEEC433EF for ; Fri, 5 Nov 2021 17:11:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C593261108 for ; Fri, 5 Nov 2021 17:11:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232818AbhKEROA (ORCPT ); Fri, 5 Nov 2021 13:14:00 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:7610 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229569AbhKERN7 (ORCPT ); Fri, 5 Nov 2021 13:13:59 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1A5Ft6Ol003132; Fri, 5 Nov 2021 17:10:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=WduBE2B0N+x/bZpKLXyB/mVPPHOQDlzqH2vvnlr6tlM=; b=d4IAbAdW3IBShSyd8xovVFJV9R70EL+pVhy7svWPC0EyCCtp9B5n3fuvFLfxih+nPw7k wVNsoeYMKRqbGbXm7LbIF9xK4dBtVW9u9KgY7XG+49Jp9AoWQ9o6j1zcXBHg2VPmzjjg t3ZHY84zU6Fa8drQNjSf2FIIUzJL9jzO8qyHTk418X781b8HOAupbwlU5GhPXJeI/b6V gX0i0NWdzQQt0nCAx621paKOppIHg1y6XhiRTA7j9f9qkWnmLbqg0i/jQj/uS7f65A3e vGMzbjbIJbzKvRKIPDNAxBulak6UNVRkGg6gOJW1n/VH+2sZniZH0tP2SWq55J9JY+nW Ng== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3c4t7bum6s-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 05 Nov 2021 17:10:41 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 1A5GeRN3074882; Fri, 5 Nov 2021 16:51:06 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2102.outbound.protection.outlook.com [104.47.55.102]) by userp3020.oracle.com with ESMTP id 3c4t61fvpk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 05 Nov 2021 16:51:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cqCs6ZLbQAj97I3d4mGyW/VlNET6MVT7bqNK4aBZvPRChJPBjFF5tbQxmh6SpN7nduURoPV9dQhW7Dx1KWYwIFf41OBHDFbx/elxDoNB9Y7QbQjpMMLAL7adhx8LSd69M439g6/OExNifit/i4kzSUqUFSGu6JYCzqswzTQMKA/R1Ycmp/o3MD/pbVISIXVBwmlajQF7SwLNcSRC/J67v4f8CvbtHPLxBFq4x8iEjWPpdInTvMr+cjk7MXxLDPE7ik8qXRgOqwbSNjbZJ4q7qm5+b5QS2WDn+UqBqNtaho0gyTptlNS0O+vdl4VZ6ttivfoCbnKGU6gk5th1bPItwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=WduBE2B0N+x/bZpKLXyB/mVPPHOQDlzqH2vvnlr6tlM=; b=fMO9g9a17K663hk83lxie0VoH6qNpH7z+Yehj5QLAdWchcmJluvcAWMHO0idXwoGczzDThcEHC6mA4V5Xk06wInLGDQMqn+ruqoQjn81wO/+1gnT28YidX174Ugn+1I46E3dCb9EwB86nK5BVtarrgG5R8YHisHwKKXmrADdlUP6gbLGnbSXZC9R9g5/b/df4q+5FwOYeWDK+TtHJUdvuV+DnaCkVu9ci8f11pbKb7VNBIeNlAdGvsl4s9PtotmyKpRuQcVjzrXZHdp68IKDoRVsE8b9p97Rhb3dUB2ayUMbAukWoHSm8VjSvvHlOE5m8xhVxyxOUB4JPkxU5VdIYA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WduBE2B0N+x/bZpKLXyB/mVPPHOQDlzqH2vvnlr6tlM=; b=QGSUNB9RWCP0L7aVipaMvDRtOu3PiKRpu9h9kGLQRrO+CN+xBTSDWRXV9vjAOGROPvIX9z4ry8pbsqM+udtESaUAbHdswxTybOcSjYHJ4dYyBKdOvYnmtzHfc6OO0BJux4XAQTobGZyU+2/r5b3ShA1fcf2iwddN2O76ofnu9D4= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BLAPR10MB5267.namprd10.prod.outlook.com (2603:10b6:208:30e::22) by MN2PR10MB3213.namprd10.prod.outlook.com (2603:10b6:208:131::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.13; Fri, 5 Nov 2021 16:51:03 +0000 Received: from BLAPR10MB5267.namprd10.prod.outlook.com ([fe80::998f:e9eb:ec26:1334]) by BLAPR10MB5267.namprd10.prod.outlook.com ([fe80::998f:e9eb:ec26:1334%7]) with mapi id 15.20.4669.013; Fri, 5 Nov 2021 16:51:03 +0000 From: Alan Maguire To: ardb@kernel.org, catalin.marinas@arm.com, will@kernel.org, daniel@iogearbox.net, ast@kernel.org Cc: zlim.lnx@gmail.com, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, andreyknvl@gmail.com, vincenzo.frascino@arm.com, mark.rutland@arm.com, samitolvanen@google.com, joey.gouly@arm.com, maz@kernel.org, daizhiyuan@phytium.com.cn, jthierry@redhat.com, tiantao6@hisilicon.com, pcc@google.com, akpm@linux-foundation.org, rppt@kernel.org, Jisheng.Zhang@synaptics.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Alan Maguire Subject: [PATCH v2 bpf-next 2/2] selftests/bpf: add exception handling selftests for tp_bpf program Date: Fri, 5 Nov 2021 16:50:46 +0000 Message-Id: <1636131046-5982-3-git-send-email-alan.maguire@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1636131046-5982-1-git-send-email-alan.maguire@oracle.com> References: <1636131046-5982-1-git-send-email-alan.maguire@oracle.com> X-ClientProxiedBy: AM9P192CA0024.EURP192.PROD.OUTLOOK.COM (2603:10a6:20b:21d::29) To BLAPR10MB5267.namprd10.prod.outlook.com (2603:10b6:208:30e::22) MIME-Version: 1.0 Received: from localhost.uk.oracle.com (138.3.204.60) by AM9P192CA0024.EURP192.PROD.OUTLOOK.COM (2603:10a6:20b:21d::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.17 via Frontend Transport; Fri, 5 Nov 2021 16:50:59 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9748385b-fe20-4f99-f403-08d9a07c73d2 X-MS-TrafficTypeDiagnostic: MN2PR10MB3213: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3173; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OSt5EXZEoHAAC6WWxNsw88EqeXBfSx12EWVhR7QS8E5KumUhtES3Cb8SL0ha0N5zhkszS/0XmUmRl5D1u6z1SqbOJ+kBKu8s4Aa14NNk5NanzXQCgnOgsr1jMaPhayIsVMQrg6cT82HDGc7FOA7dqW3whDE0uYt5MAwK1Bk61UAeB3VmsXKsEEs1ABSA3S6HovfxYKwll2NITQQqVLc9d3FElv0WrLvfWIhCd490ko8uKnPyC7FdqMO01Y60giO6Y4lSTyN1EJncKYzD+GxK9jphNH6gwE0L4lVU+OHrIbXML3zWvr2ihzjLn8n/q3c+p96EZUU0smVjbU+uJoiQCNMZ3r1Nen1/9gY+OYpfaz2Rrrl1nTKSWs+h0cwOxP3ZEioB8AIamMJTbep+B5OIvEUQVSZzVZJrc37KeaULqPgSQnKRbVHAg75+wIfESmPWT+2V4f+qARhfXdVfI2QzdLWGtj8xyGbrUzL+fTn1WftaAdfXqrjyEUVflF8vUKFknH+faXEuT/Ev5eRen4Hk3P0Chq1ZyM/4LCBX5CKSQtMItDwPChpJUr/WEZUm6gKl/6MBlPZTfGmRZ8ejarVlu7dDWdcqW4uyEyjq2ZZUUiaZh0QB/jeze0HYfHAEyrvSEvkLyxw/i1N/UZaHylWuxtz0I08g8O+6Z6PIIPnU6gbS+GrcZ0z86adpoy/dH3YDXUvIdNmqzh+iKa3iLNqTwg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BLAPR10MB5267.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(186003)(8676002)(44832011)(36756003)(107886003)(2906002)(956004)(2616005)(66946007)(508600001)(66556008)(66476007)(316002)(4326008)(8936002)(38350700002)(83380400001)(52116002)(7696005)(6666004)(38100700002)(5660300002)(86362001)(7416002)(26005)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mSgiylU6gwdSkQ+FV1eZWk+Dcpgxr6wx39dSacTattWr1AQUtXQfH1e9DOe6VSelrm6ywZfO/EjsJhNIK+3SL7MYb3fSIL5xGg5XBSmP9Tlnsw/ZgTGzxhC0PFSQ2ijkGDKIycasLa4sWoENefFU8cVDL36rmQDviUQDtmMFLilEDyIxzAIXgUvtSC7E1ckOd18KyqlaRCuxlj20AlGnViiEySR/HEqbEtSavqoyDcogF4bC9JSfkSzIidCBHsm4ZsyvH1atN4+78YS2oFHUj5YQAacfhYviUwbRx9kvW/h2BUVu79jgBSWB/OqVkvub37Z+7U28wVAvptOOQ81jJkbppi2ySR/kCPO1w7eEBdKWtM1mFdiSkaUsu1l+VDsLYXBdZ4Knmi4vD7Q7mwgAwyuvvTkO9acVYfFN3A//HbtDqGPVVPByhanRKp9bH0GPh6HDLAQ5cn+bPdr48Ebgkhvs3ZDkmegn5mEO+cRIfXwsY8fQLt+tE7oMrgtkmtlNL8sJyLp+jOmoq2M3dfIyCh6mT8qkcAo9hox+3qdUPPrHW9qyRLU1jNdupctVZSkbYclmFJbUwtakitxObBrcowByWK5YpePZuS8Esbn8j1m437MUPz3MCSS61Bg+b8vvihUL32S48WaFHnsPSg7LFb+kcF6eG2Up2db+xcbnDidCEFbzPpw9xmDG+v1xrbKdjOnEFy/b2lyIrPWWFj0vC00tQp2cBL7GFxlqOUGI76CMFNOh5KL9vUHwJREhzHqzvo5aT7B74Y6yDslwY6AEoejMR65O7X3Acj21yrNJRM49WgPfHUx5moILgTFHnXxcHMHklcLCGDj2i228Gun0pwI4wkSy+36YeyJRhGspn67T8bEqaBTG7uSNGOlC+KL6y9A+F88q3D58NX7V+rDWEo44+URAHmaLESqwYx6Tb17pILNV3mFoGdD0kfsJX6J7IdSoaeltvVo1POZBC3OvGPYmpwKBRYLhCbAx4EBKg9DTdVD4th83d8dk4nZyxRKq9gg048dgBghFdOByqfj9db39M6BxuDg+ZlB+HDbbm/E3wz4BrGEZ57OvWuGLOLnngxceO8xt9DQ/HYAm5MrbXn8ni9hcR2aCZrkSkG9J0eG828a2VBAThWY3fPzUp8RysE4ybjf9L0uGsD6U7Je08HmShmsuP3GF3o439PGLSPihURKWJZjzppPuzGMYgUGSEhf6XgyMsZVQjlanGQ2wMi+xUB2ApgtCX8U6mzsS5UpGoXrfGXih6K1lWQy0jyumRz75BmpJZJP1xKjABWw60eX3bQoDW6JvQJVVCPtDgdIPcljI4h80R/66HRxqzsoyujA94V1eWGJ/9kQ5QVr6rxUpCamnBPPCoHhZ+LqeeV5emkT4hy3H69taMTGMTgljQ+3U42IiGXcACLY4PvyBOiVLY41q3QwXWM9DsjFH/kNDfnvK6gq9dNs0VOOc1xsJLWIEersgQVHNC7xQtHpTiL3gXLpchbs1YN/0AjNMCuokdYLj5IS9yzkxPIIesmzdkFDuezg0N8JpPGnNArakuU3MMwf8sKvtUbK7Ej5N3VfuZQDgEy/lyVUynXNryFDI/+yeqhmppArivfuajxwWbVFIhmRDA9r5NqHM6EIIPG0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9748385b-fe20-4f99-f403-08d9a07c73d2 X-MS-Exchange-CrossTenant-AuthSource: BLAPR10MB5267.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Nov 2021 16:51:03.2266 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DWIuoyGOG/56aAE+m1LUSSO4nor+uajthszMCfd9Gql/HHy6vYU9H9NQQJl7l633heDs+MAoaUtjROQu52KcYg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3213 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10159 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 adultscore=0 mlxscore=0 spamscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111050094 X-Proofpoint-GUID: -UnUb5oHowJ45UQWeRycCt1MBUNiyBKd X-Proofpoint-ORIG-GUID: -UnUb5oHowJ45UQWeRycCt1MBUNiyBKd Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Exception handling is triggered in BPF tracing programs when a NULL pointer is dereferenced; the exception handler zeroes the target register and execution of the BPF program progresses. To test exception handling then, we need to trigger a NULL pointer dereference for a field which should never be zero; if it is, the only explanation is the exception handler ran. task->task_works is the NULL pointer chosen (for a new task from fork() no work is associated), and the task_works->func field should not be zero if task_works is non-NULL. Test verifies task_works and task_works->func are 0. Signed-off-by: Alan Maguire Acked-by: Andrii Nakryiko --- tools/testing/selftests/bpf/prog_tests/exhandler.c | 43 ++++++++++++++++++++++ tools/testing/selftests/bpf/progs/exhandler_kern.c | 43 ++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/exhandler.c create mode 100644 tools/testing/selftests/bpf/progs/exhandler_kern.c diff --git a/tools/testing/selftests/bpf/prog_tests/exhandler.c b/tools/testing/selftests/bpf/prog_tests/exhandler.c new file mode 100644 index 0000000..118bb18 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/exhandler.c @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2021, Oracle and/or its affiliates. */ + +#include + +/* Test that verifies exception handling is working. fork() + * triggers task_newtask tracepoint; that new task will have a + * NULL pointer task_works, and the associated task->task_works->func + * should not be NULL if task_works itself is non-NULL. + * + * So to verify exception handling we want to see a NULL task_works + * and task_works->func; if we see this we can conclude that the + * exception handler ran when we attempted to dereference task->task_works + * and zeroed the destination register. + */ +#include "exhandler_kern.skel.h" + +void test_exhandler(void) +{ + int err = 0, duration = 0, status; + struct exhandler_kern *skel; + pid_t cpid; + + skel = exhandler_kern__open_and_load(); + if (CHECK(!skel, "skel_load", "skeleton failed: %d\n", err)) + goto cleanup; + + skel->bss->test_pid = getpid(); + + err = exhandler_kern__attach(skel); + if (!ASSERT_OK(err, "attach")) + goto cleanup; + cpid = fork(); + if (!ASSERT_GT(cpid, -1, "fork failed")) + goto cleanup; + if (cpid == 0) + _exit(0); + waitpid(cpid, &status, 0); + + ASSERT_NEQ(skel->bss->exception_triggered, 0, "verify exceptions occurred"); +cleanup: + exhandler_kern__destroy(skel); +} diff --git a/tools/testing/selftests/bpf/progs/exhandler_kern.c b/tools/testing/selftests/bpf/progs/exhandler_kern.c new file mode 100644 index 0000000..f5ca142 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/exhandler_kern.c @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2021, Oracle and/or its affiliates. */ + +#include "vmlinux.h" + +#include +#include +#include + +char _license[] SEC("license") = "GPL"; + +unsigned int exception_triggered; +int test_pid; + +/* TRACE_EVENT(task_newtask, + * TP_PROTO(struct task_struct *p, u64 clone_flags) + */ +SEC("tp_btf/task_newtask") +int BPF_PROG(trace_task_newtask, struct task_struct *task, u64 clone_flags) +{ + int pid = bpf_get_current_pid_tgid() >> 32; + struct callback_head *work; + void *func; + + if (test_pid != pid) + return 0; + + /* To verify we hit an exception we dereference task->task_works->func. + * If task work has been added, + * - task->task_works is non-NULL; and + * - task->task_works->func is non-NULL also (the callback function + * must be specified for the task work. + * + * However, for a newly-created task, task->task_works is NULLed, + * so we know the exception handler triggered if task_works is + * NULL and func is NULL. + */ + work = task->task_works; + func = work->func; + if (!work && !func) + exception_triggered++; + return 0; +}