From patchwork Fri Aug 23 08:06:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard Zingerman X-Patchwork-Id: 13774747 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 B30074A08 for ; Fri, 23 Aug 2024 08:07:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724400423; cv=none; b=cDWm5vJz2iyi1XniOnAPcMsb+vOAM7X6zxL8wueajWwWF9CC2YKkJmX5g3dNGAVJUFaQ5kTIZK6p+V9+PTA1dkXlGPYDx+8pLD2cKz1splmsFd1E5djlsQ79mCKEHIvk/38Ano9Xx1/Wj8Okg1hGKzNQzoewg7znvajl3eyPy2o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724400423; c=relaxed/simple; bh=VeLM5HyI97tLEkBQ+UHzTWaxBChts7r+AVjeRb/3Abs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lpNz3hcn+1cDWJe2qweS0SmMin2seRdT6SInm/69qC5wqNTtEJGpq3tEo5vIdJIZ9b707MYe0WSqywm0kYREMvVIf/pMOR0oQI/jqJF2Pbo1Rvw/scGyrman+GyEe2pI19HyAojkDH1iiPlCDFuBU8vJNhcz69HuODYlL/PJoao= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=asABzpEs; arc=none smtp.client-ip=209.85.214.170 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="asABzpEs" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-201fba05363so13881655ad.3 for ; Fri, 23 Aug 2024 01:07:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724400421; x=1725005221; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LFjfH3Q7I2fkEbcO1C3+5RtO/EIwRd/dal+BkGGs7Pk=; b=asABzpEsxXyNMY3ObHMyjpjp9sWMkwjKvap7gcDAmfeDbxi6nCZHA25bT/AeBS4I3c euOrB9CGqSzOLq1stfapgavu2UVQA/9aLhbK9cBHr2JdG7DH+DVZBmP4tQad89G390Lz dPdP1qtdy1tZRvHl4euS/soDWGY9HBhAv3mHiABALnq91wVqIFXBF3bU7JtyYiWCg+qr 3FnmaoM3TscJ1KGt2LtEPqGf73xWOA7svQyU/yAE0l0F5LmKr/VKJvlfG8siZIXB8+eb AMCS7Wb6YFsplL9ej+KFzoF3CpTt0ULyCWO67C3WXlpe51bORZ0aGtBtF10azq63ggQn cpmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724400421; x=1725005221; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LFjfH3Q7I2fkEbcO1C3+5RtO/EIwRd/dal+BkGGs7Pk=; b=AV14L6y1q0Me2r9f68XYyC0xlIHKy0BzxYKFJGHjF3ekQifCEPAO4c7se4/ObfdfwH XbKe6xovmo3Mod7P1Lxl4mJaQGvJeDQdIZhznZg9b/7KR/lB0eDBmDjfKEhd9RE5jWok OZs+5lpkP7d8FVcr6igJAJzDQPqbYBnOZ/K/dkH1Q6Y2AcwxWnfmGYLQI5piwu9ykYyu S/bhgXawQdYFno7/mdznt2d/3Ni8wKg8CEKVT3VSu/mH7GjaSaHOCXZGCTjBKC46/jNU eB1zBREX0s21dC6QgSYLp4qq7TtfgQp76DgHvIhYRgGs30efNiBGaSV6yOGVHWbXZ2NN 1exg== X-Gm-Message-State: AOJu0YzgW4M35zSzQ3ormgxngejKMGG6lWkLveOggjhHgSoXUTZnbbg7 7MG7d+ZBmKuO3/+SvM9xCrIYVImjYn4J7xX3v8Hw5/Llp1CmBol9qk4PhA== X-Google-Smtp-Source: AGHT+IHAfpHhUCe5V0u+yuFEozmMeKYV5G1mchnB0aSZG43BmcTKxNztGbQkEo0Xte7n7sGi629mUw== X-Received: by 2002:a17:902:e88b:b0:202:54b8:72e5 with SMTP id d9443c01a7336-2039e4def47mr15799435ad.22.1724400420666; Fri, 23 Aug 2024 01:07:00 -0700 (PDT) Received: from honey-badger.. ([38.34.87.7]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20385567f74sm23463925ad.60.2024.08.23.01.06.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 01:07:00 -0700 (PDT) From: Eduard Zingerman To: bpf@vger.kernel.org, ast@kernel.org Cc: andrii@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, kernel-team@fb.com, yonghong.song@linux.dev, Eduard Zingerman Subject: [PATCH bpf-next 1/3] selftests/bpf: test_loader.c:get_current_arch() should not return 0 Date: Fri, 23 Aug 2024 01:06:42 -0700 Message-ID: <20240823080644.263943-2-eddyz87@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240823080644.263943-1-eddyz87@gmail.com> References: <20240823080644.263943-1-eddyz87@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net At the moment, when test_loader.c:get_current_arch() can't determine the arch, it returns 0. The arch check in run_subtest() looks as follows: if ((get_current_arch() & spec->arch_mask) == 0) { test__skip(); return; } Which means that all test_loader based tests would be skipped if arch could not be determined. get_current_arch() recognizes x86_64, arm64 and riscv64. Which means that CI skips test_loader tests for s390. Fix this by making sure that get_current_arch() always returns non-zero value. In combination with default spec->arch_mask == -1 this should cover all possibilities. Fixes: f406026fefa7 ("selftests/bpf: by default use arch mask allowing all archs") Fixes: 7d743e4c759c ("selftests/bpf: __jited test tag to check disassembly after jit") Signed-off-by: Eduard Zingerman --- tools/testing/selftests/bpf/test_loader.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/bpf/test_loader.c b/tools/testing/selftests/bpf/test_loader.c index 2ca9b73e5a6b..4223cffc090e 100644 --- a/tools/testing/selftests/bpf/test_loader.c +++ b/tools/testing/selftests/bpf/test_loader.c @@ -336,9 +336,10 @@ static const char *skip_dynamic_pfx(const char *s, const char *pfx) } enum arch { - ARCH_X86_64 = 0x1, - ARCH_ARM64 = 0x2, - ARCH_RISCV64 = 0x4, + ARCH_UNKNOWN = 0x1, + ARCH_X86_64 = 0x2, + ARCH_ARM64 = 0x4, + ARCH_RISCV64 = 0x8, }; static int get_current_arch(void) @@ -350,7 +351,7 @@ static int get_current_arch(void) #elif defined(__riscv) && __riscv_xlen == 64 return ARCH_RISCV64; #endif - return 0; + return ARCH_UNKNOWN; } /* Uses btf_decl_tag attributes to describe the expected test From patchwork Fri Aug 23 08:06:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard Zingerman X-Patchwork-Id: 13774748 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 F35A613F42A for ; Fri, 23 Aug 2024 08:07:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724400424; cv=none; b=shZ3C9a/2iWVA+dK9G2GVh9Uk9bzH1ZgkR0yv5qeoGchx6y8SMiLAAQyj7h+yoGW4MXYum/4eK2qWIXoxP40iMU93kkeeVivVp+kzvKXVsEYxP0umI6spz0OLDhUMkoTxEFZtPdWlts0EeCOC+tYq79kOse8HQWl6YpkEWiZtBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724400424; c=relaxed/simple; bh=MBXXs1mprhRKqJuL6VFup41CFPrKOCxduNc1b5WKbaA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J5H+nR7JsWAoqNQE8CMQWFCierjvkWEajrdIeXetprl7CY7kK1dTG+vV94mSfR9Zn0M6GClDyXMTp1OPnuiUi0Hxj8uD19p8sUN3Acrm9UY5mnv2kOS+NVNMvSO6QieBP6o7TjO32EDqfIjIz70VR2xahZO78tpfl15jxvlY4Uk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LqGSTkR8; arc=none smtp.client-ip=209.85.214.182 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LqGSTkR8" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-201fba05363so13881795ad.3 for ; Fri, 23 Aug 2024 01:07:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724400422; x=1725005222; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=c8G7SJ1gB25PYRCSCjuMt+UHkI/3Gt0/ihw3FtV7kTI=; b=LqGSTkR8qMQ8VsMBKQdCKEY8koxpIG8TvFlXyQPtt+maLSzz+Ka2N0zbs/9vMs+XdN O1d3uSSyV+h0iC01ZAx2Rl7uz9dc10PO/Dh2znNUzUZZUpsd5jx83kbIqxsg4BWOLq4U rqMD9otwRD+Nep4bdNTiDuDTtDVOXSzmEnaP/9bw1Ybmvn+spP0kLb2fnW3ho8Dda3NG E4MX44x0qxhTIEqJ+OiHtu3jc1vDfMh+A/s5gVcNpbaUY/SYVOy/zc1qYhw+9Qa9+Qr9 oOnI+qm3uAPfRbqowS4FKEdXivW9IpcVidENhTf8GJEDyyTlsbenh8QSfU3qeUnB9Zm1 s2BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724400422; x=1725005222; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c8G7SJ1gB25PYRCSCjuMt+UHkI/3Gt0/ihw3FtV7kTI=; b=dGBsBG0Gaw8M1/08z6YO7bN+5P0LWuTxiFjs/uyPO8kKC4aLTzYSrDu9vptL+io9nJ Dmbi/g6vUWCI8DeCWUnOWgOupgHevzNw+CXm2Yg1tmqkITJWq83jYWDR7SDIwOOLLVUH j67rfoyRW+I2RaRxZ8te4sndzaLYvi+Zw3OfL9sM6SEBgEThvBhV0QbMtparBkurIqlC D+8eJ20mnjRv71T5ZnItIqYZxNL2ZLBVJ43sg7G9RYgPJyUuQePaxpqBXTQeiriMz4TE 2bmBuxshHX81pbMi23JfOrnSKYueIAZ1TwXKM08K3izJa5wzW0uE81QS/dTWBn+IXyAw xzJQ== X-Gm-Message-State: AOJu0YxRTfTCMrhAcd3boHAyGdnJs4isGMfPnMjTUUrTMFG7HEB8POZL OnwZaQjx4BN/DHj2wVKtYtrJyRyZlVLlP5Rx/46hb4iEzKN2DsDcBuuWug== X-Google-Smtp-Source: AGHT+IFZfPxhpFiCL/8rgzzh+UHSCpDM/0HhM2VJdsHCFspb0edeJol62sgHGuABBdtQg7CdWThuZw== X-Received: by 2002:a17:903:32c7:b0:202:2b3c:9ac7 with SMTP id d9443c01a7336-2039e6be6d3mr14599035ad.65.1724400421659; Fri, 23 Aug 2024 01:07:01 -0700 (PDT) Received: from honey-badger.. ([38.34.87.7]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20385567f74sm23463925ad.60.2024.08.23.01.07.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 01:07:01 -0700 (PDT) From: Eduard Zingerman To: bpf@vger.kernel.org, ast@kernel.org Cc: andrii@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, kernel-team@fb.com, yonghong.song@linux.dev, Eduard Zingerman Subject: [PATCH bpf-next 2/3] selftests/bpf: match both retq/rethunk in verifier_tailcall_jit Date: Fri, 23 Aug 2024 01:06:43 -0700 Message-ID: <20240823080644.263943-3-eddyz87@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240823080644.263943-1-eddyz87@gmail.com> References: <20240823080644.263943-1-eddyz87@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Depending on kernel parameters, x86 jit generates either retq or jump to rethunk for 'exit' instruction. The difference could be seen when kernel is booted with and without mitigations=off parameter. Relax the verifier_tailcall_jit test case to match both variants. Fixes: e5bdd6a8be78 ("selftests/bpf: validate jit behaviour for tail calls") Signed-off-by: Eduard Zingerman --- tools/testing/selftests/bpf/progs/verifier_tailcall_jit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/verifier_tailcall_jit.c b/tools/testing/selftests/bpf/progs/verifier_tailcall_jit.c index 06d327cf1e1f..8d60c634a114 100644 --- a/tools/testing/selftests/bpf/progs/verifier_tailcall_jit.c +++ b/tools/testing/selftests/bpf/progs/verifier_tailcall_jit.c @@ -59,7 +59,7 @@ __jited(" movq -0x10(%rbp), %rax") __jited(" callq 0x{{.*}}") /* call to sub() */ __jited(" xorl %eax, %eax") __jited(" leave") -__jited(" retq") +__jited(" {{(retq|jmp 0x)}}") /* return or jump to rethunk */ __jited("...") /* subprogram entry for sub(), regular function prologue */ __jited(" endbr64") @@ -89,7 +89,7 @@ __jited(" popq %rax") __jited(" popq %rax") __jited(" jmp {{.*}}") /* jump to tail call tgt */ __jited("L0: leave") -__jited(" retq") +__jited(" {{(retq|jmp 0x)}}") /* return or jump to rethunk */ SEC("tc") __naked int main(void) { From patchwork Fri Aug 23 08:06:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard Zingerman X-Patchwork-Id: 13774749 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 9F6AD140E23 for ; Fri, 23 Aug 2024 08:07:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724400425; cv=none; b=qY8NpUQNhzqLzuvu4oymghhqH3kQfLxc/QN1q+IvPj4EER6eiUNVoFkhD5AQuJeJFXIkjyX2/iVSp/unD7SASu+ff2x4+t3r0mwyOWN/myiSzDSMRACGkgOBbweI5f5I0ilnPZjwpikjlGm0fS/e9ymFWoQy7eP5MnqUWmo079U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724400425; c=relaxed/simple; bh=kVDT7KuyrVApObgO6Oyh1m4xSCeQcbIL0Y0yzfjKntc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BTnQL7Ac5+Nro/z8qL1hzSoYigX5zQtjQ9iHbILf91Aqqb04eoIKxyU0sZzl835TgMrBh1zHsKheZgq3iuiERQhTJIv9R5FJRNxRLMXMK+UZZPW6nGfIL6MQtVgzygtzhEMrkBoTsKph1fAiH78JxcESG8yuDcTK6uK0nsAHhws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dBn0LEu4; arc=none smtp.client-ip=209.85.214.171 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dBn0LEu4" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2021c08b95cso21764825ad.0 for ; Fri, 23 Aug 2024 01:07:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724400422; x=1725005222; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6z2LLbIpDy50MRImJ98Lp+Br9vG4OoOapBprDnt+jCE=; b=dBn0LEu4dyIZcHdgoQNGChcEIwe4bXV0NwRKdX34XZh5f4ghakdPBFZrTdt+LqsvU5 cjSnRFzYAD04leFmM+PhW1fkxLQ9IAZdrx2q2TlZ57+PZQ2Glojouz74B80jl05ykqoO neplYUWUhjjrkHLGX4kAZbnnWkYMYnDjqOGA9bW9o+H+YQ65FiW6+5PrVWN429kGODb4 n+/TI9CQthXn7npIt6py/cOaApIDIG+MZamJgsk5ZusRQyEr18knOvW+4ugub/r3K1JY 3P1APuGOo7ngKkFZXa12EMmAnAE/eCJVJZw5pwNEEDIj/CA17Vg+X7AnDh1BiioklQDJ hf5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724400422; x=1725005222; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6z2LLbIpDy50MRImJ98Lp+Br9vG4OoOapBprDnt+jCE=; b=dI5Oi+8CuKpO649OBIb7zLxRbZwykazxQBVRBUvqOWvJyd8i8QYdwuSUnEQcKHxVD5 QTXHJGLJch5EELGCV4EFqG6hg0JpnrzY9Sf5uS84JjsyEsartsHGvpQdp4HDe2yiPNH7 XjdflEyhvJIg2gV105x6TeNsKbp6dNd5jTaeDkYm0ZPXM+U6VaURSKfIq68dyWRpwZfi PV38d2Ntl0g8zVZrTN99KxL2VHY3u1z0/0keuO4mxngf21YA2xFg0JPUoMKz+PAwwaZg FyfkfJULnZdLtDkiogUvoHjf7MO+s6ZgD3jtnagry6ibe/xbIr8pFU1AUsI5K60/mXbi SfVw== X-Gm-Message-State: AOJu0Yy0U4HrSI7gxO9npqo20qZHvaNtbVJpACQIZU3C1tlQWHj0uIit BcFPTIaVijHYZyNqjp4nAqDNE6MKl97FcrKcM6K8TWoUlVUnCjzWn+CBZg== X-Google-Smtp-Source: AGHT+IEKFM7Gb5VoWUyGPdRxBNDc+26SjZCCUlwvvgMdNxLkjdRNnFXkQjX0LS6Eqs8LbmGTa2tbBQ== X-Received: by 2002:a17:902:dacd:b0:1fc:41c0:7a82 with SMTP id d9443c01a7336-2039bb3f532mr33728965ad.0.1724400422477; Fri, 23 Aug 2024 01:07:02 -0700 (PDT) Received: from honey-badger.. ([38.34.87.7]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20385567f74sm23463925ad.60.2024.08.23.01.07.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 01:07:02 -0700 (PDT) From: Eduard Zingerman To: bpf@vger.kernel.org, ast@kernel.org Cc: andrii@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, kernel-team@fb.com, yonghong.song@linux.dev, Eduard Zingerman Subject: [PATCH bpf-next 3/3] selftests/bpf: #define LOCAL_LABEL_LEN for jit_disasm_helpers.c Date: Fri, 23 Aug 2024 01:06:44 -0700 Message-ID: <20240823080644.263943-4-eddyz87@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240823080644.263943-1-eddyz87@gmail.com> References: <20240823080644.263943-1-eddyz87@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Extract local label length as a #define directive and elaborate why 'i % MAX_LOCAL_LABELS' expression is needed for local labels array initialization. Signed-off-by: Eduard Zingerman --- .../testing/selftests/bpf/jit_disasm_helpers.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/bpf/jit_disasm_helpers.c b/tools/testing/selftests/bpf/jit_disasm_helpers.c index 1b0f1fd267c0..febd6b12e372 100644 --- a/tools/testing/selftests/bpf/jit_disasm_helpers.c +++ b/tools/testing/selftests/bpf/jit_disasm_helpers.c @@ -16,6 +16,11 @@ */ #define MAX_LOCAL_LABELS 32 +/* Local labels are encoded as 'L42', this requires 4 bytes of storage: + * 3 characters + zero byte + */ +#define LOCAL_LABEL_LEN 4 + static bool llvm_initialized; struct local_labels { @@ -23,7 +28,7 @@ struct local_labels { __u32 prog_len; __u32 cnt; __u32 pcs[MAX_LOCAL_LABELS]; - char names[MAX_LOCAL_LABELS][4]; + char names[MAX_LOCAL_LABELS][LOCAL_LABEL_LEN]; }; static const char *lookup_symbol(void *data, uint64_t ref_value, uint64_t *ref_type, @@ -118,8 +123,14 @@ static int disasm_one_func(FILE *text_out, uint8_t *image, __u32 len) } qsort(labels.pcs, labels.cnt, sizeof(*labels.pcs), cmp_u32); for (i = 0; i < labels.cnt; ++i) - /* use (i % 100) to avoid format truncation warning */ - snprintf(labels.names[i], sizeof(labels.names[i]), "L%d", i % 100); + /* gcc is unable to infer upper bound for labels.cnt and assumes + * it to be U32_MAX. U32_MAX takes 10 decimal digits. + * snprintf below prints into labels.names[*], + * which has space only for two digits and a letter. + * To avoid truncation warning use (i % MAX_LOCAL_LABELS), + * which informs gcc about printed value upper bound. + */ + snprintf(labels.names[i], sizeof(labels.names[i]), "L%d", i % MAX_LOCAL_LABELS); /* now print with labels */ labels.print_phase = true;