From patchwork Thu Aug 29 12:25:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lin Yikai X-Patchwork-Id: 13783088 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2067.outbound.protection.outlook.com [40.107.255.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6144C191484; Thu, 29 Aug 2024 12:26:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.255.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724934377; cv=fail; b=VugqxbwE2Hqf0bf9Ts1Wbv+A4E7IKIZ+FROAyr2bkmYU79JtqET7DCbUQk29NmEhSsSWd1jAo+gd7gNtbi3tIl4fuEE6KfiyMoGKPFQ5wvs+i4zsMeFAEMLulYetOY+sxCuQyTLW8nS4oNCvvvQWXQ4ZX7a4qJZMqXAlClT3+iw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724934377; c=relaxed/simple; bh=fJmljRKixWFxV7kzmKolJUJrLHC1Zl8QjF8upD0sc00=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=GPXmROuzD79RfNovJ3VNHYhZIBe0+f+qkgT0XejMeMgHQGUpFgzXgFe8dt8NX7GhKtUuEoREjM0E8SyOXwL635Hw9aXnG/Omt9V3uJaTIjBX28W0SzxVYzjACjbvSzRfcHVErRknKGeJdAGPL5iFiGYKA+014UyEX8hFaT7Gy/M= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com; spf=pass smtp.mailfrom=vivo.com; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b=kK8gqYuF; arc=fail smtp.client-ip=40.107.255.67 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=vivo.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b="kK8gqYuF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=h5c5/oJiliCVcitwA8+Cvd7yV7hrVjh7LnG2PlwQ9b3uBz4xZOjPlNq2FRyqkPu1JWtJVETMi6FwEm0DkKge45pG8oRnN5H24OhhWAJgcPkYCqCJWrOnthj1q2/a1JY5ZCeL8sYZKW3GKCV45foo+rRIpr0X8N3zdjrnG+iYAySt3xh6QSJAo5+Q5WPEbPHtSHAcKx5LGlwpdd5ToSgimie4z+egiGFdItuzALqQYw8yUzFK08FyXo3FnmnrDUrzhY8DlPIt5ImR4UCzd+T7iCtcqBzb11xs3ZH51ey2gUFiraJT4uceH3UjtlcvqE3mdknLnr1ECkSJBFne+2APkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=MuG4Pu0GMPeBgFjEzUhrvDK1Gc2PlbYPSkEB4Xwg2FY=; b=r3rTw52Viumi7Z8MoHANeoWzbECIgLJbnRJfXpIuXNc3qQD7UmuabERB3uOqd7z/H461UaStEFgmUHErZceGAr7FeFT8YEIrnqFsBVdarzpcxcEhkrASUxU3HtR5em2i2IdbFnGM1pSotHw6AqYAnSYEq1PNo4U3dSzFPatKSIOMXDd/Fz8/YsG07XjtNCBmDbBiLNk1wE+zBzq+hDzwz9wEeR/uL2BQSCITfx+grFNQADfkEpfxRk/vYnXIz+yw40op9b3tZGwHQ9tZgaLWLA7iyGmNw52dSwV4Hx7SvULfazXud+i86cugBeRRj/1NRApvZI1TGEswGMrfGLtYcw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MuG4Pu0GMPeBgFjEzUhrvDK1Gc2PlbYPSkEB4Xwg2FY=; b=kK8gqYuFE1Nx/EcOA8BccTddZdRhsG7r3lutzTY77mV8vNf8BjZORinYr843uLuvt722IACgb8KiZ27xjbBwyIa2aqeY2iXaVNdOYFUYILa5N2eBxfb9+cCq2hHAAp3M1GX2/k0Z6YysKQDpETAf4BFRYVjCxAgd+s7AmDkpeLEXt+uSQMIGfhIPGnUXOqCk0lLHqgAd7namJryzZ7LLXwpkQ/0w/JjnjgFLj6uBzQo3WGnoadIUg+NJKjpsFP+Gx6LZaQtgFquaJNHQSRB9hTQnkomEV7x1PuhWkXjgW+j8N17ajE8DHRkGaOUAGExEgbuJlWzniECW7w8TvaBbjg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SEYPR06MB5913.apcprd06.prod.outlook.com (2603:1096:101:da::16) by SEZPR06MB7078.apcprd06.prod.outlook.com (2603:1096:101:1f0::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.25; Thu, 29 Aug 2024 12:26:12 +0000 Received: from SEYPR06MB5913.apcprd06.prod.outlook.com ([fe80::f049:a716:8200:c4a1]) by SEYPR06MB5913.apcprd06.prod.outlook.com ([fe80::f049:a716:8200:c4a1%4]) with mapi id 15.20.7897.021; Thu, 29 Aug 2024 12:26:12 +0000 From: Lin Yikai To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: opensource.kernel@vivo.com, yikai.lin@vivo.com Subject: [PATCH bpf-next V1] enable virtFS(9p virtio) for sharing directory on VM to optimize debugging Date: Thu, 29 Aug 2024 20:25:40 +0800 Message-Id: <20240829122540.2206118-1-yikai.lin@vivo.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SG2PR02CA0102.apcprd02.prod.outlook.com (2603:1096:4:92::18) To SEYPR06MB5913.apcprd06.prod.outlook.com (2603:1096:101:da::16) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR06MB5913:EE_|SEZPR06MB7078:EE_ X-MS-Office365-Filtering-Correlation-Id: 05daab0b-8f90-409e-c063-08dcc825c4e8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016|52116014|7416014|921020|38350700014; X-Microsoft-Antispam-Message-Info: /FiuX06OyErSBAI6b3E+vEmnyBrvS+MIgcWPWWXh5MrIqtDK+2AmeIdICzI8j2IhDPOg6i17hw2RA8qRJdbb4EEeHqu6lKfQb4KWT+GOGB+LTwcqTodMvakEu7eBLEfhviy43Yv/xbSrf6M9Yqx+7Rsfq0pPWy9lVFiqDpgKi1dzZAtEOjp1ER/RVLtlYbJwNWbLWnXGmnTLp8bJ6Y7L7Eg67ANQ9V4TzIj1fEOtq1pKJF0clfxx21GA9MILqPJ/rMEKSmsOcwESOILav2Tfh7++C7POlz3iDXuliojD+VI0+lXr48koC8NUJP4Uv/Hl0zVL/XAt/Ix7OjA4H5PFX1YJ/uoxMQcATF3cW6W9eFv5nm6RK/DjwaNYknvsb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jOHr+sc8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SEYPR06MB5913.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(1800799024)(366016)(52116014)(7416014)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fdk+EmuQG7w6ODnUrEIQGS4LoHj+OUSgceQFeQxABfDDDcvGcOWDA8OpyFf593Ak9YvzRs72wlBnXWtcEXEusY1Zru/1VTMFt8wQYuE0MI+v36Gqqdihx0BumPGiyboo8sAm1ZjxTd2mgXFLd2MhBAiehy17aC6wdJzhh4AUeiDPXhrQIDYRVZj19GhjchUlPvp2oHDxX0lSuk7pn/Dwz6g6Iwu9K0nhvvb0IhDz+SFKSNTjoS1UXlOXc+NDlv8UERcxYGKT9PerKSFaFt9a9YtW0dCzvzsHI+/hxd7FL7u/F5G27MIc9MBTnqrgOA7By/IVcXa+xNkP+YoVHjwzRkuBMwYdicxbxyzN/iq6ZPUi3PtSBiRjwb9y1VjNlwTC+U8dkn1h8d+ZQilJwEx7ROfOGku3dOUiErJBajRrFxWQgOK4uDGcs4xs7p32++tGyQTxoh+epCso9Bj5w7i1WqWxzC0H7diOfjjjMsGHpk9T2ltmc2CNJ/9tbIgnZecKPcVYSvFjdQTqvGWHRRnO6HogLDPwLDXiLILKnBBfKIILobT2FDHhKSMnLVrDWzVUGUze1iUK761npFhamKvXPUjIbZweLe1A5asoeZjQyIXVWYD3quArH5/zQP0jTKnsJlEOgub3uWbBHAKqk2Qo7+PXj4vxbDxXd6KMO1YWreuqneQoimxoGmEfLdQ3GWf5EC9cQ2Vd4XG7+5Zno3j86AXRkW1Tz3mFxAGN2iCYV202aUMHs79cNpXjPG+BEI4KkqhasCpqYmbeeB48NAEaogJNItzrk8GHk8wXgt13hmxoR+M7mW7NoIEIDU2YlFHMMyCP57YMHG0EnOoxwBPem3c37A94VfuWQWN3ddSIP5KxCMpt94H0tND8ga/cU8yvH46o6eroFuyKryKhe/TUnBsD+vAYG84OP3S2tTYR3yXC3WBDRncL2VoBipuxqMjUtUBlal21aE7nTkeVAHnHvDCUkwXs8rfl7xIFdWf3W6hupkIolS5seutGZP8d1FwbyLdQdmvv+BxtZ4eL3Svo4MFFdjXo7uCnJEL3kgtK5Qz6SmkmZyqE4iufwlFqAxYKSpIIANnAu7LYH7PP3Fivb60JoVUUZguFBV+/r/HX8Oe2C5MLy4C8B+6IP8nqPWzZlx/QOpna7koannn292N4TekEkCsi0YXtibmNBbC52VX9liAP9XR43XvnKMpAKaZ8QXqLGOfZJdmXghxAN7zOqdoJ+bIpT+F7vJh402lUfK741EyZrf4mNxCpDA8Uy/nEycntxwJPt+1WXzbTuqosv+3/dp5lUWAQEaAzzEIWuhBNp/lqcfXNYKU3ohu+R51C+VLjuDq0bwbq3Pb6tskJIWqtd8wPEJp1faWnk5u7FqsCUmMxJMFI4UtxFguYqowP799m7ou4QQk61DWZwtSiu6lR5iGV/Kl/1BjTlgktS7xKta8S2UJ9dcIuGb9FXmgU0mZWc3RTQoaDhl2YpwnthjAnY6vwucZwfJj6Z8r1V0cxSHcqipNCZXhQzpBjtcjbsBR9u4Xq1Xt/Zu6b9gQ5e9LGAGrC2/g0gmHvPkWLefqfWV+bfdPt46dDjcDdPBVz X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 05daab0b-8f90-409e-c063-08dcc825c4e8 X-MS-Exchange-CrossTenant-AuthSource: SEYPR06MB5913.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2024 12:26:12.4520 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: refxJAK+bl7DIrPmc3oa3Qa12CxaZIryYQze1DoGsyvI+Kz1tDRuyujV0fYPVP2s0xvpimH5iEJaJGjSFt7O7A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR06MB7078 [Problem] Sometimes, we have only x86_64 server for compiling BPF with target ARCH of arm64. Therefore, the only way to debug bpf is using cross-compile and qemu. Unfortunately, debugging online on VM is very inconvenient, when test_progs fails. Such as: 1. We are unable to directly replace old test object and still need to quit VM and restart, which consumes valuable time. 2. We also want to share other tools or binaries online for execution on the VM, which is not supported by VM. [Optimization] I noitce that CONFIG_9P_FS is enabled in "config.vm", so virtFS (9p virtio) is available on VM. To achieve it, I add a new init file on qemu, which only exists when '-v' option is appended. root@(none):/# cat /etc/rcS.d/S20-testDebug #!/bin/sh set -x rm -rf /mnt/shared mkdir -p /mnt/shared /bin/mount -t 9p -o trans=virtio,version=9p2000.L host0 /mnt/shared [Usage] Append the option '-v' to enable it. For instance: LDLIBS=-static ./vmtest.sh -v -s -- ./test_progs -t d_path This will share the directory between VM's "/mnt/shared" with host's *${OUTPUT_DIR}/${MOUNT_DIR}/shared*. On host: $ mv ./test_progs ~/workplace/bpf/arm64/.bpf_selftests/mnt/shared/ On VM(you can directly move it into /root/bpf): root@(none):/# ls /mnt/shared/ test_progs Signed-off-by: Lin Yikai --- tools/testing/selftests/bpf/vmtest.sh | 75 ++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/vmtest.sh b/tools/testing/selftests/bpf/vmtest.sh index c7461ed496ab..82afadde50da 100755 --- a/tools/testing/selftests/bpf/vmtest.sh +++ b/tools/testing/selftests/bpf/vmtest.sh @@ -70,10 +70,15 @@ LOG_FILE_BASE="$(date +"bpf_selftests.%Y-%m-%d_%H-%M-%S")" LOG_FILE="${LOG_FILE_BASE}.log" EXIT_STATUS_FILE="${LOG_FILE_BASE}.exit_status" +DEBUG_CMD_INIT="" +DEBUG_FILE_INIT="S20-testDebug" +QEMU_FLAG_VIRTFS="" + + usage() { cat <] -- [] +Usage: $0 [-i] [-s] [-v] [-d ] -- [] is the command you would normally run when you are in tools/testing/selftests/bpf. e.g: @@ -101,6 +106,8 @@ Options: -s) Instead of powering off the VM, start an interactive shell. If is specified, the shell runs after the command finishes executing + -v) enable virtFS (9p virtio) for sharing directory + of "/mnt/shared" on the VM EOF } @@ -275,6 +282,7 @@ EOF -serial mon:stdio \ "${QEMU_FLAGS[@]}" \ -enable-kvm \ + ${QEMU_FLAG_VIRTFS} \ -m 4G \ -drive file="${rootfs_img}",format=raw,index=1,media=disk,if=virtio,cache=none \ -kernel "${kernel_bzimage}" \ @@ -354,6 +362,60 @@ catch() exit ${exit_code} } +update_debug_init() +{ + #You can do something else just for debuging on qemu. + #The init script will be reset every time before vm running on host, + #and be executed on qemu before test_progs. + local init_script_dir="${OUTPUT_DIR}/${MOUNT_DIR}/etc/rcS.d" + local init_script_file="${init_script_dir}/${DEBUG_FILE_INIT}" + + mount_image + if [[ "${DEBUG_CMD_INIT}" == "" ]]; then + sudo rm -rf ${init_script_file} + unmount_image + return + fi + + if [[ ! -d "${init_script_dir}" ]]; then + cat < ${init_script_file}" <