Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1479417rdb; Mon, 19 Feb 2024 18:21:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWOSwrzqBFXfPgb/lbwsWf91uIP/V4Tr6ETujI06qdn+P2YytSYa2jXTOtUygeAUrm1jHHenOUhVl47mv/C6/jFHGaZDkEZCgSWPPJF6w== X-Google-Smtp-Source: AGHT+IFdVAY4hBqnIt1ZSrVlruEwOi4OkAcnhPRHXTUmFjuwO9f3PMKS92ETvQVrL8ORKdCLwjT2 X-Received: by 2002:a17:906:b154:b0:a3e:cb72:b6fd with SMTP id bt20-20020a170906b15400b00a3ecb72b6fdmr1733246ejb.23.1708395709762; Mon, 19 Feb 2024 18:21:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708395709; cv=pass; d=google.com; s=arc-20160816; b=BbbzWVqmN79GHn68W3+Wd4P08p9b/MbEmjt8mNNHXXUtNe6JK19GVd2HEj7jBSxasx kksCg3+Vge3PyVfuhulBldXDlyyOjf2sj7dkOmm5o7RIDSDcTLNMxerhN0W3cylDpROL i7vboHGk8lDQP5+KybG1aWSoGgywRbV1rlbl2uj9Y7pRsk6qkM1sh+P4cLpTbbDKArOK FTBNwStGB+o7mTOorXV6t+RyH8AVO2QVXLSzQrLp9+5XISM1hrcJ1e4M8+iEtk5xd/Y5 lgItREueIq0Ax4olzFJoefkwByrTwW9ulLMH5t3dWqX86SrRlKfp0vupFFyXqZhfPPZ+ vKwA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:in-reply-to :subject:cc:to:from:user-agent:references:dkim-signature; bh=+OAN0Lt5ZKU5YCY2zjENEtHOA9Ppd3OvNfkI0wLPm9E=; fh=8AZGqMvbAaH/cjOjlfczxovy+YS8lrJBGS9nLOH0648=; b=VK9hHZtLjNxo/SoEc4tK6VmtpuYqy4mTkQjXbJnNTobfEYkyQWVf4WsVfCwUj1H2v/ 16Nb6PsMNZVpjNG44YtcPqz6KOkHLf679M8AynVuXRyEB16ChowDcR8VWat0baPoZ+qf SWUZh/8LQqpDekOEd/T8Q9jd7RkDscfVpRE2J4ci5Wip3pxkR1MApqT8zItR+tjZ/jEI TbjLc/sUSUgcdb9vWUcsn4mega1oJjJU359x1EQFdTDQ7K7iQ0lpKOzWF5PIJnf01jHi o6UmlXl+en6QO2pRPdtptxJn1epu2vrYURbogAu8Ngj5ARGJR59jdr9xQ1CVp0SSpxdD R4Vg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yckeErJc; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-72205-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72205-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id go42-20020a1709070daa00b00a3e6512224asi1976470ejc.247.2024.02.19.18.21.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 18:21:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72205-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yckeErJc; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-72205-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72205-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 6C47D1F246B3 for ; Tue, 20 Feb 2024 02:16:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8D8FD3D38F; Tue, 20 Feb 2024 02:16:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="yckeErJc" Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 943073F9CD for ; Tue, 20 Feb 2024 02:16:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708395365; cv=none; b=gnibZxcYoLR+dJp1IEhCoreXomYBfZ9usk7GFnbtDgbmtdJc1A6zV/b0wlO8a4sei6yX/AD6uzNHn3edvEEyWhnapo79Num5bk72DHq4FXS7/FQ8YUfOXLDo1YMQlF34mi8bsIMRSxlH2aTPmr6ekqBxoQis7HOfe4zzgu5DIp0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708395365; c=relaxed/simple; bh=+7g6xZPa4MQeBNdj24ssUkgA+nZTA9KzvinQD9Fnew4=; h=References:From:To:Cc:Subject:In-reply-to:Date:Message-ID: MIME-Version:Content-Type; b=KBluPh8dV3mvJ6UUbq9IWMCcrj75WHbjgskp/kwP4eVdWaWBbux15Qd1OZ9kRUNhIZzzCzjPgutFqb85keSfVvugZH3w/8LucnfrYXqc2u+b70JZimqOOGJiUo2iv7ObMwSsVM6DhSyKQdZt+V1UVQhw1cdZy6PZoMNSPoM3pbk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=yckeErJc; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1d918008b99so40422285ad.3 for ; Mon, 19 Feb 2024 18:16:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708395360; x=1709000160; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:in-reply-to :subject:cc:to:from:user-agent:references:from:to:cc:subject:date :message-id:reply-to; bh=+OAN0Lt5ZKU5YCY2zjENEtHOA9Ppd3OvNfkI0wLPm9E=; b=yckeErJcH5dfA3i7ebhfsFRK6lZEltNb8u7msAhQoEAxnUvBj+MZFesc7ZLC6uDPd/ Vl2FwqJs3VSvaVGfgnJfxpyXFel5VOryJCxH5lNaK+Rm4cc3IOr384sUWpXsHipEAsuU K4S4EFV0e/Jz42nMG2SUIpaUXaxYh8E4gY7sMrNGuw+zBpxNVrEHwxj/dOr1smpg06fA jlPEjzl9SixTVctot5Mx8vDo9aY0MqYqZWcuJYIEl/KPKmPLw7y6aJo6fybiiFCL+vMz 0sydS86asqL9WdrNMK/TkGd4nzpsjQu56bPgg5wxb6pcqySzxWQ87jwdMPM40vpgg9qf yrow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708395360; x=1709000160; h=content-transfer-encoding:mime-version:message-id:date:in-reply-to :subject:cc:to:from:user-agent:references:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=+OAN0Lt5ZKU5YCY2zjENEtHOA9Ppd3OvNfkI0wLPm9E=; b=wXgXL0R9Ww1IqouzOzRUQv5PcfhIImyliCfu9ClcnTSNDqe+l3+Xa7IQlZ417BC0c5 6oNpUOAjVjAkSj8PpXIBOLaDApLK2KlHD+J/65FHS2SXS1Z8NYhpG+KCjRzxacpUZtr7 lv51pEBm/6Kn78WaWL4Rope57nIqsD7K5emXX9etLLBobo3+xCRB5kgIB7e0y6CZFp5k N3wq9+oO/YSYNdAugnVjJnqUwz1Qb5fudmhwc+EVpJEathlclJIaMR5HSr8ywQAZzfbR +Iv/TYJP18LspPBOlo0j7MxsTvhyg6oTGqtSBqzPu6YiJCq8NzTbUMOfOa4dhJsr9y7v oK7g== X-Forwarded-Encrypted: i=1; AJvYcCX0/gvPFmfAux4FuIahDsyU6Q6kMntLbKSrV4z30IS2a9TB2kgY4UAjGOn3usELtU2yBTJw1d655CYIqULza/G604uqhw+Ul4N/F6H4 X-Gm-Message-State: AOJu0Yw9MvXaU8U8uURXrZk8bfOQ4Z+l5IZIK/S1Xq5JAsvsOHRNAbiN jL+6m3HDeL0mmIz4LGRlGaO+YEwy7JnikVBmPGuohoPQT9PoLTrsaYgzsEmiZJY= X-Received: by 2002:a17:902:ea0d:b0:1db:e7a4:90a8 with SMTP id s13-20020a170902ea0d00b001dbe7a490a8mr6006330plg.10.1708395359755; Mon, 19 Feb 2024 18:15:59 -0800 (PST) Received: from localhost ([2804:14d:7e39:8470:a328:9cae:8aed:4821]) by smtp.gmail.com with ESMTPSA id x15-20020a170902ec8f00b001db3efca159sm5042143plg.132.2024.02.19.18.15.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 18:15:59 -0800 (PST) References: <20240203-arm64-gcs-v8-0-c9fec77673ef@kernel.org> <20240203-arm64-gcs-v8-33-c9fec77673ef@kernel.org> User-agent: mu4e 1.10.8; emacs 29.1 From: Thiago Jung Bauermann To: Mark Brown Cc: Catalin Marinas , Will Deacon , Jonathan Corbet , Andrew Morton , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Arnd Bergmann , Oleg Nesterov , Eric Biederman , Kees Cook , Shuah Khan , "Rick P. Edgecombe" , Deepak Gupta , Ard Biesheuvel , Szabolcs Nagy , "H.J. Lu" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Florian Weimer , Christian Brauner , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, kvmarm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: Re: [PATCH v8 33/38] kselftest/arm64: Add a GCS test program built with the system libc In-reply-to: <20240203-arm64-gcs-v8-33-c9fec77673ef@kernel.org> Date: Mon, 19 Feb 2024 23:15:57 -0300 Message-ID: <87sf1n7uea.fsf@linaro.org> 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=utf-8 Content-Transfer-Encoding: quoted-printable Mark Brown writes: > There are things like threads which nolibc struggles with which we want > to add coverage for, and the ABI allows us to test most of these even if > libc itself does not understand GCS so add a test application built > using the system libc. > > Signed-off-by: Mark Brown > --- > tools/testing/selftests/arm64/gcs/.gitignore | 1 + > tools/testing/selftests/arm64/gcs/Makefile | 4 +- > tools/testing/selftests/arm64/gcs/gcs-util.h | 10 + > tools/testing/selftests/arm64/gcs/libc-gcs.c | 736 +++++++++++++++++++++= ++++++ > 4 files changed, 750 insertions(+), 1 deletion(-) In v7, several tests weren't running in my FVT VM for some reason. This time they do: $ ./run_kselftest.sh -t arm64:libc-gcs TAP version 13 1..1 # timeout set to 45 # selftests: arm64: libc-gcs # TAP version 13 # 1..118 # # Starting 118 tests from 32 test cases. # # RUN global.can_call_function ... # # can_call_function: Test terminated unexpectedly by signal 11 # # FAIL global.can_call_function # not ok 1 global.can_call_function # # RUN global.gcs_enabled_thread ... # # OK global.gcs_enabled_thread # ok 2 global.gcs_enabled_thread =E2=8B=AE # # RUN invalid_mprotect.exec_bti.do_map_read ... # # Allocated stack from 0xffffb3aa9000-0xffffb3aaa000 # # OK invalid_mprotect.exec_bti.do_map_read # ok 118 invalid_mprotect.exec_bti.do_map_read # # FAILED: 117 / 118 tests passed. # # Totals: pass:117 fail:1 xfail:0 xpass:0 skip:0 error:0 not ok 1 selftests: arm64: libc-gcs # exit=3D1 The only issue as can be seen above is that the can_call_function test is failing. The child is getting a GCS Segmentation fault when returning from fork(). I tried debugging it with GDB, but I don't see what's wrong since the address in LR matches the first entry in GCSPR. Here is the debug session: (gdb) break libc-gcs.c:58 Breakpoint 1 at 0x3894: file libc-gcs.c, line 58. (gdb) set follow-fork-mode child (gdb) r Starting program: /var/tmp/selftests/arm64/libc-gcs [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1". TAP version 13 1..118 # Starting 118 tests from 32 test cases. # RUN global.can_call_function ... [Attaching after Thread 0xfffff7ff7e80 (LWP 9164) fork to child process 916= 8] [New inferior 2 (process 9168)] [Detaching after fork from parent process 9164] [Inferior 1 (process 9164) detached] [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1". Thread 2.1 "libc-gcs" received signal SIGSEGV, Segmentation fault Guarded Control Stack error. [Switching to Thread 0xfffff7ff7e80 (LWP 9168)] 0x0000fffff7ec6fc0 [GCS error] in __GI__Fork () at ../sysdeps/nptl/_Fork.c:= 50 warning: 50 ../sysdeps/nptl/_Fork.c: No such file or directory (gdb) bt #0 0x0000fffff7ec6fc0 [GCS error] in __GI__Fork () at ../sysdeps/nptl/_For= k.c:50 #1 0x0000fffff7ec6be0 in __libc_fork () at ./posix/fork.c:73 #2 0x0000aaaaaaaa49b8 in __run_test (f=3Df@entry=3D0xaaaaaaab98c8 <_fixtur= e_global>, variant=3Dvariant@entry=3D0xffffffffefb8, t=3Dt@entry=3D0xaaaaaaab81b0 = <_can_call_function_object>) at /home/thiago.bauermann/src/linux/tools/testing/selftests/kselftest_h= arness.h:1128 #3 0x0000aaaaaaaa2ac4 in test_harness_run (argv=3D0xfffffffff158, argc=3D1) at /home/thiago.bauermann/src/linux/tools/testing/selftests/kselftest_h= arness.h:1199 #4 main (argc=3D1, argv=3D0xfffffffff158) at libc-gcs.c:735 (gdb) p $gcspr $1 =3D (void *) 0xfffff7dfffe0 (gdb) p/x $lr $3 =3D 0xfffff7ec6be0 (gdb) p/x *(unsigned long *)$gcspr $5 =3D 0xfffff7ec6be0 (gdb) disassemble Dump of assembler code for function __GI__Fork: 0x0000fffff7ec6f70 <+0>: mrs x5, tpidr_el0 0x0000fffff7ec6f74 <+4>: mov x0, #0x11 // = #17 0x0000fffff7ec6f78 <+8>: sub x6, x5, #0x7c0 0x0000fffff7ec6f7c <+12>: sub x4, x5, #0x6f0 0x0000fffff7ec6f80 <+16>: movk x0, #0x120, lsl #16 0x0000fffff7ec6f84 <+20>: mov x1, #0x0 // = #0 0x0000fffff7ec6f88 <+24>: mov x2, #0x0 // = #0 0x0000fffff7ec6f8c <+28>: mov x3, #0x0 // = #0 0x0000fffff7ec6f90 <+32>: mov x8, #0xdc // = #220 0x0000fffff7ec6f94 <+36>: svc #0x0 0x0000fffff7ec6f98 <+40>: cmn x0, #0x1, lsl #12 0x0000fffff7ec6f9c <+44>: b.hi 0xfffff7ec6fc4 <__GI__Fork+84> // = b.pmore 0x0000fffff7ec6fa0 <+48>: mov w2, w0 0x0000fffff7ec6fa4 <+52>: cbnz w0, 0xfffff7ec6fbc <__GI__Fork+76> 0x0000fffff7ec6fa8 <+56>: sub x0, x5, #0x6e0 0x0000fffff7ec6fac <+60>: mov x1, #0x18 // = #24 0x0000fffff7ec6fb0 <+64>: mov x8, #0x63 // = #99 0x0000fffff7ec6fb4 <+68>: stp x0, x0, [x6, #216] 0x0000fffff7ec6fb8 <+72>: svc #0x0 0x0000fffff7ec6fbc <+76>: mov w0, w2 =3D> 0x0000fffff7ec6fc0 <+80>: ret 0x0000fffff7ec6fc4 <+84>: adrp x1, 0xfffff7faa000 0x0000fffff7ec6fc8 <+88>: ldr x1, [x1, #3528] 0x0000fffff7ec6fcc <+92>: neg w0, w0 0x0000fffff7ec6fd0 <+96>: mov w2, #0xffffffff // = #-1 0x0000fffff7ec6fd4 <+100>: str w0, [x5, x1] 0x0000fffff7ec6fd8 <+104>: mov w0, w2 0x0000fffff7ec6fdc <+108>: ret End of assembler dump. (gdb) p $w0 $8 =3D 0 (gdb) p $_siginfo.si_signo $12 =3D 11 (gdb) p $_siginfo.si_code $13 =3D 10 (gdb) p $_siginfo._sifields._sigfault.si_addr $14 =3D (void *) 0xfffff7ec6fc0 <__GI__Fork+80> --=20 Thiago