From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 0FC851DE3C4 for ; Thu, 16 Jan 2025 11:35:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737027345; cv=none; b=acGRaIQhgE78rtuk16cmPf+qeV2if7G10QKTLOc6W0ZkcQOhNJTc57VPBQrq8OPFG4CaPaYMr30WkX/qGrrmc5IY/vH2+va3x3p/qct7Ky5YPcefh6QuPva+X6ZBaS9CoP+jlDmC0fT9kdKXrSqBwRYed2dw1d4Wtz3jF0dqOSw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737027345; c=relaxed/simple; bh=4rScqGobGnb4mpIlFYLwvBzWFz/YxIvFcWlI5EGHYXE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=OutQWfW+h1bn9FI7bMMLB/SbapdQvvR29DG9CFZ7hBF3hZRBS0j+fbjtriuv8Jo290RMvTVTqrxd+WVsB+QLNJ23hnwlRu5QBTbIXG9OcuD9LQchDyMfnRAjPKnOlq60dGFrOMLOtMngZosRT7Ww8X9WtLk07iV/7TRrE1iJ41c= 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=ZmI+zVYM; arc=none smtp.client-ip=209.85.128.49 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ZmI+zVYM" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-436345cc17bso4803965e9.0 for ; Thu, 16 Jan 2025 03:35:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1737027341; x=1737632141; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=F+IL0+GOfzEC4aeJWJbSxSpruqaLU6cR4sD7yZTPtTI=; b=ZmI+zVYM2cDreQMpPos69d4v7gpYC+D0SXHp0k2o/i9y/0cOU1pN7IazeIhxhw988C tfeD6FaH7GanmGMAmcorD7SJaoFy1fg3D06ZL1HScpfTDbTa3917UusxbjVvG8axVoqz 7TZc+H4WtunoUGhCVRhamX4UM8BWlUOElzhx8BEVS+ergM/Q1/OaWNdDlunyDUQtNvL6 fhaMopIxof1U7aCZeOH/UnF7RT7RO1FURbc9LRYQqVDU+7KE9rl7NEV8CpdbB1DwIHEQ IdNn+6XJZTvOpwPHQ331SFecW/FxJuVWhEiTVQnSEHce/sAMXvVdPo68hZefoVa7Qe+N yniQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737027341; x=1737632141; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=F+IL0+GOfzEC4aeJWJbSxSpruqaLU6cR4sD7yZTPtTI=; b=IusHxSdyG4U/RC7cJKoQrhHpG6jHrhkgkkkJZGAoa02Nh5jjUwtFFTMbjeH2uL2jxm SQ9+XwwXSS3jJgUPkzubtroSz9lUd2crM2odoSuX/iWoGALES90Tn82+gccpb2XMZ5Mu 6DuQZZaAjknN9TGxFXQOrbsN8wT9uyDxye69sFijqbKukkhnf1ZtUud+7wYY1IsUSDZN Od4ng4PpUOBXOjfudnyFLIdHT/+125DZtvIEdn1rO54Ym8FtgJBT1MK9r7+ZVV565aCc Qfx6U+aZ9G3sFm4yd5PrP9fyRJiqpK37YXhBL7ZyhfTAvd6n5eG2hFG3U+guVN9Mwbzp f93w== X-Forwarded-Encrypted: i=1; AJvYcCXmtoeXHO9RG9xhsi9Sjccybhpolggge2y8umIgARo00VWRID6qIUCRkPMLEjZqpsFKSpIxgtOM6s3MvF4=@vger.kernel.org X-Gm-Message-State: AOJu0Yw6bpJQ/8aPRB/boBN2FRbnp8qvytdS4NpcFpcAS1CEITc+Evas 844+Dl4nDTNp5q93C5sEYK/dUbCcrHPHFrCtuZ8YB5OD9gSa4h52fMsi0oWS8jA= X-Gm-Gg: ASbGnct1Y9PqLnM0eU1RI3apLcl8RUQlALSgdGdVRn0O4xEMyMzQFKAzd0pEOCGTLWr xmJl6tYQwDbjDhlPe4CbYXChg918y/7j24+XIIf/i7yiHdf+MZQBA1oJbcjPTk0dA2hgZQgyEl1 sgw4lyAvhLiPBi11U2JcE79/OMoUcobeGTJixyGI4we3t3tx1yS/0KmzL8WCdTYg1T3D4YWdzDg a3H1Cobuk0VwcaFdHVI6j8LowTgnkC7zVJylIpP+ETl0ikHKPZa1GXoTXFqPy19/g== X-Google-Smtp-Source: AGHT+IGBydE7n4ukQMxeJC/IohCUHz/oBS4d62nahhto5e93jzlvZ4RUwir6qAgTxFQnHx/YuIXhKA== X-Received: by 2002:a05:600c:3c85:b0:434:a1d3:a30f with SMTP id 5b1f17b1804b1-436e267736cmr270167985e9.6.1737027341348; Thu, 16 Jan 2025 03:35:41 -0800 (PST) Received: from [192.168.68.163] ([145.224.65.18]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a8e37d0fasm20597123f8f.19.2025.01.16.03.35.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Jan 2025 03:35:41 -0800 (PST) Message-ID: <6d3dd8f5-db23-402d-b7c0-d8264bb5a045@linaro.org> Date: Thu, 16 Jan 2025 11:35:39 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] perf bench: Fix undefined behavior in cmpworker() To: Kuan-Wei Chiu Cc: mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, Ching-Chun Huang , Chun-Ying Huang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org References: <20250116110842.4087530-1-visitorckw@gmail.com> Content-Language: en-US From: James Clark In-Reply-To: <20250116110842.4087530-1-visitorckw@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 16/01/2025 11:08 am, Kuan-Wei Chiu wrote: > The comparison function cmpworker() violates the C standard's > requirements for qsort() comparison functions, which mandate symmetry > and transitivity: > > Symmetry: If x < y, then y > x. > Transitivity: If x < y and y < z, then x < z. > > In its current implementation, cmpworker() incorrectly returns 0 when > w1->tid < w2->tid, which breaks both symmetry and transitivity. This > violation causes undefined behavior, potentially leading to issues such > as memory corruption in glibc [1]. > > Fix the issue by returning -1 when w1->tid < w2->tid, ensuring > compliance with the C standard and preventing undefined behavior. > > Link: https://www.qualys.com/2024/01/30/qsort.txt [1] > Fixes: 121dd9ea0116 ("perf bench: Add epoll parallel epoll_wait benchmark") > Cc: stable@vger.kernel.org > Signed-off-by: Kuan-Wei Chiu > --- > Changes in v3: > - Perform a full comparison for clarity, as suggested by James. > Reviewed-by: James Clark