Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1249402lqo; Fri, 17 May 2024 16:26:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXVssNG1Rrppos3f+7DWaiAaeS18QvIbns5GeaErJwOGQp5ULvY7rLh8psJcDluPNdVuVn4kK7wvvpxCUECrMVqcNOgTPY2bP2w5i6SHQ== X-Google-Smtp-Source: AGHT+IG9jHPbrJf2wdYY3kR7dEVRsGaHwUT0xsCpcW1Nedet2rMB32SxAMF7XwO2BmSp5+8WZIN0 X-Received: by 2002:a17:90a:c691:b0:2bd:5fdf:fdb1 with SMTP id 98e67ed59e1d1-2bd5fdffe23mr610111a91.48.1715988417773; Fri, 17 May 2024 16:26:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715988417; cv=pass; d=google.com; s=arc-20160816; b=p6q2fNAgqAWmmWRJuqlXmCnJOGRTpsNjrSeHqTAPaISTo+i0YOpAX7STYBIS6PSpds u+7pUpVJLuyPz2fk3SgocXz7KggnA0SXmQDUidN9+2Z7v+jrbENN0AOqbhe6c4U6VIoC SJeXTHbrBvisvDaNTM69QQbqYZHIrd0JPpLVJakVQlRKSu1vDoUDPIehZiXSe4U5Yu6k i3Mq+Td3+tKeISjqzJRKhDDfnFrnbzTsRoP6Xy1CqBM4mGtQalRUQX3a3qWeoz6b1RGr 0qDX7JgUtMlhM3k6jqmgbju4AX9u0VPAhmx/Ekvakg0IQ6j6nXBbQq6a4NaG1htWch6M Q+Fw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=8IZ5BJXL4a/Gxno+DYgdII2wwGlh7k3xDXbAXofV+S8=; fh=BaQgrKYlBhj4jInhNmiJABPjWwf8DVscOxlVr/xJDSM=; b=Z3j5P1Pywg3PT7/62NfZMEkpfPpQwVd+cV67CHxR/BsPAC4eV7hO65KlJlJt8KrFz0 NdJRzsTtc4JRQ/XtXiIGU+EtlndAeFrK9c3lpgO9WyqThkKXSC4Lhs9Dh8A8fr7cnuWc ZlEW6uIudmITh28D58BE02fDI/vvw4VxhGxCLyJ0niiMVDCFXlVKj3t13m93Y7T4/eDU aWsPLgEB/wUm9iRY9I/Q0z2A2QvrAAAMwb2Iatglc6uNFWEcD4foDch2PNomXdWmg9+B R/wxlGkzgD82Lyd+0hZko3WHGG7wXu4eOWJC+1GHk6diJs0RnYUZB7O099zn7ERfUvNP 2eoA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ElvmhEaO; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-182686-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182686-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2b670f592b4si18420011a91.71.2024.05.17.16.26.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 16:26:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182686-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ElvmhEaO; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-182686-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182686-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 11F3B283CA5 for ; Fri, 17 May 2024 23:26:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 94C1B141995; Fri, 17 May 2024 23:26:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ElvmhEaO" Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.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 122341411C1 for ; Fri, 17 May 2024 23:26:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715988405; cv=none; b=WrVjx+vBVogPV+i7T9wF881/WfC0dsLEugkoafR1E4XESQytzMW3J3SBAaz732VCBeA7HL6YIEx/fNRJLHGZM3AJNSRZuvIN/UKJ8qY7hqRhDKbwO2XBqK5KAT75HWPyU22UbdTyvHHdrSwU8kRTbQl0ze7cz2QXj8rLQQMiKUo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715988405; c=relaxed/simple; bh=FY2QEdFM0cTzmcZAB9CNLgD+w9UuXW+H7VPr0lLxhQo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rGq0TJpjyv77wSWKSvx82+PeS6l0Fv+5mFwIyf+ofPTzr6KYXEK7GXu/nZqahUvNoPL6hqRngMs051gLWqvGXVkYkT436hmHYMd/2KJu7RM0Pzs+0bCiOZdQl/sCClLJuVvRwuoJ3hk7RFPpqp+g4nnMA7lX+FzxlHd7lLnHMXE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=ElvmhEaO; arc=none smtp.client-ip=209.85.215.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-5ce07cf1e5dso923009a12.2 for ; Fri, 17 May 2024 16:26:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1715988403; x=1716593203; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=8IZ5BJXL4a/Gxno+DYgdII2wwGlh7k3xDXbAXofV+S8=; b=ElvmhEaOXbPoJt4xNKunmU+6kuhOeFynKjUp/QhX2C+eGn15pLBdIildFoOOZNwB5v AKJeq7SmX+q+yXzGYb6E/07Xyq+liiiTIzBEuNLZJ+iOsIdAzDQ/H618Gb7RCbFG/Ve2 PyWpSPYekbM8M5h+2PLVTXXNv/f9l6iD8pmKY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715988403; x=1716593203; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8IZ5BJXL4a/Gxno+DYgdII2wwGlh7k3xDXbAXofV+S8=; b=N5KyVlAxmth7TzxVcfVQ721JhRRCBaboBz1M7uvNFSD8Paa3tPD+en2pgWA36BA10/ h3Rxb0eYeZ7WvHUTmV1Mk4EyL/hqeN8um85XSBlOq8e4lLEp7+JpCC2WvhqIvfb9ZVeO 5Bp5X5rdndmIjWFwcunq7DTHHsKL0+xTRpYuxD2/7aObASZ6ZjuTW7K8X9d9v5ocAAFS /C9kK/Tnwv8juwC7PK83JxCguSXyV+U2e35QolKnP1NYI500Dv2SdkSph0T9PsO5JFZN N8h3/h97aZGrM+n3ouJiVRkKrbzDXUwym0zv0XhuQUQWjcGJZTDCTzQrDEwS/dFgQHpN C7Pg== X-Forwarded-Encrypted: i=1; AJvYcCWD49K7MBHaRqP6dghH0te/BVBL56/hN5ZRZpui/+6g3c/gYnMRV94EKD/S20nAl1jpXH6tRqp2AmtqTRrbkrXH1beKb408YtBo5Tnk X-Gm-Message-State: AOJu0YxA4sFHHR2IKcxOkYlcom7NMR2hjo0dXIeVAadH3z5SRuDk0jxm TsZQVEkzaDfj0FzBGMpvPkF1EzsCcfQUfjhx9eTB8iqMB8+0ZobTvdKz3QZKtA== X-Received: by 2002:a05:6a00:1819:b0:6f4:8e8c:67f6 with SMTP id d2e1a72fcca58-6f4e03bf3c8mr28122111b3a.33.1715988403203; Fri, 17 May 2024 16:26:43 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f4d2a6667bsm15222293b3a.36.2024.05.17.16.26.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 16:26:42 -0700 (PDT) Date: Fri, 17 May 2024 16:26:41 -0700 From: Kees Cook To: Masahiro Yamada Cc: Andy Lutomirski , Will Drewry , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Belloni , Benjamin Tissoires , Christian Borntraeger , Claudio Imbrenda , David Hildenbrand , Janosch Frank , Jiri Kosina , Shuah Khan , bpf@vger.kernel.org, kvm@vger.kernel.org, linux-input@vger.kernel.org, linux-rtc@vger.kernel.org Subject: Re: [PATCH 1/2] selftests: harness: remove unneeded __constructor_order_last() Message-ID: <202405171621.A178606D8@keescook> References: <20240517114506.1259203-1-masahiroy@kernel.org> <20240517114506.1259203-2-masahiroy@kernel.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=us-ascii Content-Disposition: inline In-Reply-To: <20240517114506.1259203-2-masahiroy@kernel.org> On Fri, May 17, 2024 at 08:45:05PM +0900, Masahiro Yamada wrote: > __constructor_order_last() is unneeded. > > If __constructor_order_last() is not called on reverse-order systems, > __constructor_order will remain 0 instead of being set to > _CONSTRUCTOR_ORDER_BACKWARD (= -1). > > __LIST_APPEND() will still take the 'else' branch, so there is no > difference in the behavior. > > Signed-off-by: Masahiro Yamada > --- > > .../selftests/drivers/s390x/uvdevice/test_uvdevice.c | 6 ------ > tools/testing/selftests/hid/hid_bpf.c | 6 ------ > tools/testing/selftests/kselftest_harness.h | 10 +--------- > tools/testing/selftests/rtc/rtctest.c | 7 ------- > 4 files changed, 1 insertion(+), 28 deletions(-) > > diff --git a/tools/testing/selftests/drivers/s390x/uvdevice/test_uvdevice.c b/tools/testing/selftests/drivers/s390x/uvdevice/test_uvdevice.c > index ea0cdc37b44f..7ee7492138c6 100644 > --- a/tools/testing/selftests/drivers/s390x/uvdevice/test_uvdevice.c > +++ b/tools/testing/selftests/drivers/s390x/uvdevice/test_uvdevice.c > @@ -257,12 +257,6 @@ TEST_F(attest_fixture, att_inval_addr) > att_inval_addr_test(&self->uvio_attest.meas_addr, _metadata, self); > } > > -static void __attribute__((constructor)) __constructor_order_last(void) > -{ > - if (!__constructor_order) > - __constructor_order = _CONSTRUCTOR_ORDER_BACKWARD; > -} > - > int main(int argc, char **argv) > { > int fd = open(UV_PATH, O_ACCMODE); > diff --git a/tools/testing/selftests/hid/hid_bpf.c b/tools/testing/selftests/hid/hid_bpf.c > index 2cf96f818f25..f47feef2aced 100644 > --- a/tools/testing/selftests/hid/hid_bpf.c > +++ b/tools/testing/selftests/hid/hid_bpf.c > @@ -853,12 +853,6 @@ static int libbpf_print_fn(enum libbpf_print_level level, > return 0; > } > > -static void __attribute__((constructor)) __constructor_order_last(void) > -{ > - if (!__constructor_order) > - __constructor_order = _CONSTRUCTOR_ORDER_BACKWARD; > -} > - > int main(int argc, char **argv) > { > /* Use libbpf 1.0 API mode */ > diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h > index ba3ddeda24bf..60c1cf5b0f0d 100644 > --- a/tools/testing/selftests/kselftest_harness.h > +++ b/tools/testing/selftests/kselftest_harness.h > @@ -444,12 +444,6 @@ > * Use once to append a main() to the test file. > */ > #define TEST_HARNESS_MAIN \ > - static void __attribute__((constructor)) \ > - __constructor_order_last(void) \ > - { \ > - if (!__constructor_order) \ > - __constructor_order = _CONSTRUCTOR_ORDER_BACKWARD; \ > - } \ > int main(int argc, char **argv) { \ > return test_harness_run(argc, argv); \ > } This won't work. All constructors are executed, so we have to figure out which is run _first_. Switching this to a boolean means we gain no information about ordering: it'll always be set to "true". We need to detect which constructor sets it first so that we can walk the lists (that are built via all the constructors in between) in the correct order. > @@ -846,7 +840,6 @@ static struct __fixture_metadata *__fixture_list = &_fixture_global; > static int __constructor_order; > > #define _CONSTRUCTOR_ORDER_FORWARD 1 > -#define _CONSTRUCTOR_ORDER_BACKWARD -1 > > static inline void __register_fixture(struct __fixture_metadata *f) > { > @@ -1272,8 +1265,7 @@ static int test_harness_run(int argc, char **argv) > > static void __attribute__((constructor)) __constructor_order_first(void) > { > - if (!__constructor_order) > - __constructor_order = _CONSTRUCTOR_ORDER_FORWARD; > + __constructor_order = _CONSTRUCTOR_ORDER_FORWARD; > } > > #endif /* __KSELFTEST_HARNESS_H */ > diff --git a/tools/testing/selftests/rtc/rtctest.c b/tools/testing/selftests/rtc/rtctest.c > index 63ce02d1d5cc..9647b14b47c5 100644 > --- a/tools/testing/selftests/rtc/rtctest.c > +++ b/tools/testing/selftests/rtc/rtctest.c > @@ -410,13 +410,6 @@ TEST_F_TIMEOUT(rtc, alarm_wkalm_set_minute, 65) { > ASSERT_EQ(new, secs); > } > > -static void __attribute__((constructor)) > -__constructor_order_last(void) > -{ > - if (!__constructor_order) > - __constructor_order = _CONSTRUCTOR_ORDER_BACKWARD; > -} > - > int main(int argc, char **argv) > { > switch (argc) { A better question is why these tests are open-coding the execution of "main"... -- Kees Cook