From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 18B97C3600B for ; Thu, 27 Mar 2025 13:10:55 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.929264.1331879 (Exim 4.92) (envelope-from ) id 1txn0K-00071O-GQ; Thu, 27 Mar 2025 13:10:40 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 929264.1331879; Thu, 27 Mar 2025 13:10:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1txn0K-00071H-Dh; Thu, 27 Mar 2025 13:10:40 +0000 Received: by outflank-mailman (input) for mailman id 929264; Thu, 27 Mar 2025 13:10:40 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1txn0K-00071B-3w for xen-devel@lists.xenproject.org; Thu, 27 Mar 2025 13:10:40 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2062a.outbound.protection.outlook.com [2a01:111:f403:2415::62a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ddb7fbb2-0b0c-11f0-9ffa-bf95429c2676; Thu, 27 Mar 2025 14:10:34 +0100 (CET) Received: from MW4PR03CA0057.namprd03.prod.outlook.com (2603:10b6:303:8e::32) by CH3PR12MB9395.namprd12.prod.outlook.com (2603:10b6:610:1ce::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.44; Thu, 27 Mar 2025 13:10:30 +0000 Received: from SJ5PEPF000001CC.namprd05.prod.outlook.com (2603:10b6:303:8e:cafe::af) by MW4PR03CA0057.outlook.office365.com (2603:10b6:303:8e::32) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8534.43 via Frontend Transport; Thu, 27 Mar 2025 13:10:30 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by SJ5PEPF000001CC.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8534.20 via Frontend Transport; Thu, 27 Mar 2025 13:10:29 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 27 Mar 2025 08:10:28 -0500 Received: from [172.17.183.194] (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Thu, 27 Mar 2025 08:10:27 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ddb7fbb2-0b0c-11f0-9ffa-bf95429c2676 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LRGVzRpZS/qoj5uuBiQdYv8OdUPOlhzkacw+AZK+h8H5ST90VYUCeTicf+SzDDoMzINvys5NEWASRKKjE2xphBMOYHfBIUn/v7kSq+hggnbuOtjc9fDzASSeheMBsIYFVf+884HUYY/R/tvEmQeOSwdML1jNmW3YwYeUbc3LgkM9/sDI2UBsIUNh8I8eGiXrTIlkGyhPzVFaOfjy8VOLo0uSPhBDGSbRFAWk2YF0MK9z1uX70KjRyUVDIMBsydcLIs15LSUgZ31/OhPGfWjDxFmiv5JURRGCazGZg70CGJ3jqO+Aab+uaGuWLU3QYDhOCNqopWc3xGGFdJ+pjVj5Tg== 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=i5bIlOECIDuXi7tNjnzbQXAmEnw/LIcLpPOIU/e1LKI=; b=qRzxJ9sKB99ogXg0vJD03zd3ClPdi/zwstSOdA9XkaujH2zR0qbS5F3QXu4V1aCShbJRF8UUZyqw4WzGjaidmfLEjVexGI81tvvKxtp24yv5RI1vrwXmtCGKbdPmP1KCD6vyAcqlFV3OKpbc4HQOXXSqJXYlt4yqpJJ9uHxOhErv2M97j/woXkx9rcNgeqjOfMLISwmD+ybjqmDuZ7uST5zAbvE4ZImDKDDFo8EUPNBaQ+Phir67xt0fcCnK3QODI9TmBNGilc40lIxgVgQqrEkr7yGmLfvghrkwGE4Y4sOy4DjxB8omTabjMsHGfEWZrb0wrpj/JM7MiDUDiMa0NQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=bugseng.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=i5bIlOECIDuXi7tNjnzbQXAmEnw/LIcLpPOIU/e1LKI=; b=iYFzo9tnX1JAM1+kolBRQZgLFSXJOSM9QENDcnUCPXysr+EVrooVgP4kKB3Pz/KxfvZ5c/gKzQct5LuOV1HcuIuzuzmunpqtWE7GnjhQkXxeDFlPbk3KNNH6DMB7hGWJ9/ZEn6xlxeFzhOf5VqVYxgaSjaZSBeEgIsUxroTvrxI= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Message-ID: <66c8b421-fa74-4a8e-9ec6-ffdfd5082b72@amd.com> Date: Thu, 27 Mar 2025 09:10:26 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 2/3] xen: x86: irq: initialize irq desc in create_irq() To: Nicola Vetrini , Jan Beulich CC: Volodymyr Babchuk , , Andrew Cooper , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , References: <20250327004044.2014048-1-volodymyr_babchuk@epam.com> <20250327004044.2014048-3-volodymyr_babchuk@epam.com> <84903e47-038c-46f5-862a-a0c9623c8125@suse.com> <2836f7977d3a7061f481c1e83d0b2820@bugseng.com> Content-Language: en-US From: Stewart Hildebrand In-Reply-To: <2836f7977d3a7061f481c1e83d0b2820@bugseng.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Received-SPF: None (SATLEXMB03.amd.com: stewart.hildebrand@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF000001CC:EE_|CH3PR12MB9395:EE_ X-MS-Office365-Filtering-Correlation-Id: e0e9323d-54fa-4cd0-27c9-08dd6d30bf8d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|82310400026|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?VUFWb1M0cTFuaWdnd1lXZyttY2wwVkV3ZkVPUTR6czkvdlAwVk9h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3UUZGNjlWOGlwaS9mRFpYZytZ?= =?utf-8?B?d2xpUEM0VWMreVR3RnQ3cmMxODZiRUVWRll2eVc3ZFdmdTRGc0lJTFhtZnQ2?= =?utf-8?B?Z0g3akFBRFlFRDNYVDg5Z3pQajh2ZkJvZUR4NFdaenA4MVBhV2o1TXNvb0lI?= =?utf-8?Q?Sx+dSe9Q7Ai+w6RUSEFwAfYrW+YV60=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2025 13:10:29.4160 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e0e9323d-54fa-4cd0-27c9-08dd6d30bf8d X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ5PEPF000001CC.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9395 On 3/27/25 05:00, Nicola Vetrini wrote: > On 2025-03-27 09:37, Nicola Vetrini wrote: >> On 2025-03-27 09:03, Jan Beulich wrote: >>> On 27.03.2025 01:40, Volodymyr Babchuk wrote: >>>> While building xen with GCC 14.2.1 with "-fcondition-coverage" option, >>>> the compiler produces a false positive warning: >>>> >>>>   arch/x86/irq.c: In function ‘create_irq’: >>>>   arch/x86/irq.c:281:11: error: ‘desc’ may be used uninitialized [-Werror=maybe-uninitialized] >>>>     281 |     ret = init_one_irq_desc(desc); >>>>         |           ^~~~~~~~~~~~~~~~~~~~~~~ >>>>   arch/x86/irq.c:269:22: note: ‘desc’ was declared here >>>>     269 |     struct irq_desc *desc; >>>>         |                      ^~~~ >>>>   cc1: all warnings being treated as errors >>>>   make[2]: *** [Rules.mk:252: arch/x86/irq.o] Error 1 >>>> >>>> While we have signed/unsigned comparison both in "for" loop and in >>>> "if" statement, this still can't lead to use of uninitialized "desc", >>>> as either loop will be executed at least once, or the function will >>>> return early. So this is a clearly false positive warning. Anyways, >>>> initialize "desc" with NULL to make GCC happy. >>>> >>>> Signed-off-by: Volodymyr Babchuk >>> >>> Hmm, this puts us in an interesting conflict, I think. Misra, aiui, will ... >>> >>>> --- a/xen/arch/x86/irq.c >>>> +++ b/xen/arch/x86/irq.c >>>> @@ -265,7 +265,7 @@ void __init clear_irq_vector(int irq) >>>>  int create_irq(nodeid_t node, bool grant_access) >>>>  { >>>>      int irq, ret; >>>> -    struct irq_desc *desc; >>>> +    struct irq_desc *desc = NULL; >>> >>> ... consider such an assignment useless (and hence potentially confusing) >>> code. I'm curious what BugsEng folks are going to say here. >>> > > Just to mention it: having a "do { } while" loop instead of a for (just out of context) probably avoid tripping gcc's false positive and also help with MISRA Rule 9.1 without needing an explicit initializer. > >> >> It is quite odd to see this only in coverage builds, but the side effects of coverage options might trigger some of gcc's internal analyzer thresholds. Anyway, since there are no concerns about dead code (see https://gitlab.com/xen-project/xen/-/blob/staging/docs/misra/deviations.rst: R2.2, "There shall be no dead code", is globally deviated) and that this might actually be beneficial to remove some caution reports for R9.1 ("The value of an object with automatic storage duration shall not be read before it has been set") I think the overall effect is positive. I tried running an "-Og default for debug builds" change through CI, and I ran into *almost* the same error with -Og and certain version(s) of GCC: arch/x86/irq.c: In function 'create_irq': arch/x86/irq.c:298:25: error: 'desc' may be used uninitialized [-Werror=maybe-uninitialized] 298 | desc->arch.used = IRQ_UNUSED; arch/x86/irq.c:268:22: note: 'desc' was declared here 268 | struct irq_desc *desc; | ^~~~ The do { } while loop Nicola suggested indeed fixes it in the case of -Og: diff --git a/xen/arch/x86/irq.c b/xen/arch/x86/irq.c index dd8d921f18f6..812f9eb91453 100644 --- a/xen/arch/x86/irq.c +++ b/xen/arch/x86/irq.c @@ -267,12 +267,18 @@ int create_irq(nodeid_t node, bool grant_access) int irq, ret; struct irq_desc *desc; - for (irq = nr_irqs_gsi; irq < nr_irqs; irq++) + irq = nr_irqs_gsi; + + if ( irq >= nr_irqs ) + return -1; + + do { desc = irq_to_desc(irq); if (cmpxchg(&desc->arch.used, IRQ_UNUSED, IRQ_RESERVED) == IRQ_UNUSED) break; - } + irq++; + } while ( irq < nr_irqs ); if (irq >= nr_irqs) return -ENOSPC;