Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3979229pxb; Fri, 11 Feb 2022 12:05:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJwttMjtGZrA6VGQX+pzagAM4w1pCiE/x55Ah/7CeYLJXsPavlaoUnk+M3LvEzLkmED1G1qL X-Received: by 2002:a17:902:bd08:: with SMTP id p8mr3071724pls.127.1644609948669; Fri, 11 Feb 2022 12:05:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644609948; cv=none; d=google.com; s=arc-20160816; b=GJFtEILhpcX9FhGuDVhE97LXuc7nN1Qc2k5v49vgs5O/o5mk3kwJcJy+QivRO9Zej9 UwkKgLLbbvnUwTWAvOjg0DOdFv1m+PpJZhzb4LMFTgkoR3DudWCkRamEQFxEQLXJSlQ9 qv/L9UI+ItL+cUaQHgVdAvh3rhMcF7yoH/Ui93oHNN/ZSIK+pX5qMBD30GV+UNUydZ+n 3uq6ErOLO2wbeFVGPCWvN+zYGcirloRERojLehsIitBcwIul6A7jbaBki9Uz/3eVagp2 WwmBiJTPTT4e2UMms7ESYdm0pg++584neXKtFr91ZWppr4Gq7vxcLx0aCIozFwZtAD4K VVgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=mHRsq6Kn87GMOD21+jYbugw/48vB/ViEdc86yH1U1RM=; b=kGDl5uUAg+k7YShg4WKyenViFD/gLGV6ciDPRHjk7TDw784J+Whmo82EOaaUbQ97If +fIV4RBN7qx6OFjRRf7N3yJ8PG2Uq7q9/YXGgT49z9UODVdMRi+JS+HmVF+qK2xcgswE 9K78PcPEwkjc6QTyO7C8d3GZQqfDd6RIfXPJqv9A/8kOpnWcyWobJdcTX9HBBTGKe543 GxWl5b5PQisBPxPaj5R4NYdjjLhbjt0qLNF1LdVRDVnkDc044Nt+n3kWOniyQcKB1I4g /cJ323q9zugUHGjrmlsgAzNVo9jiW2ZPa55KdvS37TiXZTuOYBzvegSSXuac/BDEXJKv FaDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="cE/HfRBc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s201si22447970pgs.328.2022.02.11.12.05.34; Fri, 11 Feb 2022 12:05:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="cE/HfRBc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345869AbiBJXrL (ORCPT + 99 others); Thu, 10 Feb 2022 18:47:11 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:51138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345864AbiBJXrK (ORCPT ); Thu, 10 Feb 2022 18:47:10 -0500 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61A6B5F75 for ; Thu, 10 Feb 2022 15:47:10 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id x15so10715801pfr.5 for ; Thu, 10 Feb 2022 15:47:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=mHRsq6Kn87GMOD21+jYbugw/48vB/ViEdc86yH1U1RM=; b=cE/HfRBcMAiI7aHiAvjjmt/SqsHa2f/rPVtV36FfX+RNibf+yKHCwYxGDTUtUIoQTN n+ZC03sN7lJOgFIjtcfdqZc2niTOFjCQnJAiJcOp6p/xKpuK41BgjFbGKDbl7AUWmPk0 ur5mEAX2mLkDvRd+aBSDYM0PrWWRnuHFIpzh0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=mHRsq6Kn87GMOD21+jYbugw/48vB/ViEdc86yH1U1RM=; b=4IRoFo8jkrM8zAJFAqzUtcYwH8hhLk8vVvyCrN2OCBg7muYZUZ7aR91r+FCAvqLCT4 /3z9i7jPxBrbQ4QQfU73jktZxdqlv3CB3YTlz6baYfBxHWcHY4zerNsLPPbAmYwIPLYM 09O0FowbLIEbEKzvSaFIWBjEn6RIo/oMGXAWjf/54bTZ7nfdEz269GD7Yp4Bp90glZAH MuqPiPcVa1NhAs4jsKBjJIA611PahDcdXUP8OM3Gknl5ujQfp2mzVrfKixn3kd8Uhk47 DTiL0/7qpZvoeoek3X0nu4gbrnJdwYNtCemDQY+czDcfQvpmsm09oySU8ZuMMWcSuqAy QmYw== X-Gm-Message-State: AOAM533QCzagRIhqtRGmOYcl5ZRVT/1TSqVNSG6RidOYUzQV5kWquEw1 NgP2iRvMBLEJWOZi+7Ou1ToLAw== X-Received: by 2002:a63:7019:: with SMTP id l25mr1843865pgc.251.1644536829788; Thu, 10 Feb 2022 15:47:09 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 69sm17784092pgc.61.2022.02.10.15.47.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:47:09 -0800 (PST) Date: Thu, 10 Feb 2022 15:47:08 -0800 From: Kees Cook To: Ard Biesheuvel Cc: Victor Erminpour , Robin Murphy , Lorenzo Pieralisi , Hanjun Guo , Sudeep Holla , "Rafael J. Wysocki" , Len Brown , ACPI Devel Maling List , Linux ARM , Linux Kernel Mailing List , trivial@kernel.org Subject: Re: [PATCH v2] ACPI/IORT: Fix GCC 12 warning Message-ID: <202202101415.43750CEE@keescook> References: <1644518851-16847-1-git-send-email-victor.erminpour@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 10, 2022 at 08:41:51PM +0100, Ard Biesheuvel wrote: > On Thu, 10 Feb 2022 at 19:48, Victor Erminpour > wrote: > > > > When building with automatic stack variable initialization, GCC 12 > > complains about variables defined outside of switch case statements. > > Move the variable into the case that uses it, which silences the warning: > > > > ./drivers/acpi/arm64/iort.c:1670:59: error: statement will never be executed [-Werror=switch-unreachable] > > 1670 | struct acpi_iort_named_component *ncomp; > > | ^~~~~ > > > > Signed-off-by: Victor Erminpour > > Please cc people that commented on your v1 when you send a v2. > > Still NAK, for the same reasons. Let me see if I can talk you out of this. ;) So, on the face of it, I agree with you: this is a compiler bug. However, it's still worth fixing. Just because it's valid C isn't a good enough reason to leave it as-is: we continue to minimize the subset of the C language the kernel uses if it helps us get the most out of existing compiler features. We've eliminated all kinds of other "valid C" from the kernel because it improves robustness, security, etc. This is certainly nothing like removing VLAs or implicit fallthrough, but given that this is, I think, the only remaining case of it (I removed all the others a while ago when I had the same issues with the GCC plugins), I'd like to get it fixed. And I should point out that Clang suffers[1] from the same problem (the variables will be missed for auto-initialization), but actually has a worse behavior: it does not even warn about it. And note that the problem isn't limited to -ftrivial-auto-var-init. This code pattern seems to also hide the variables from similar instrumentation like KASan, etc. (Which is similarly silent like above.) In both compilers, it seems fixing this is not "easy", and given its corner-case nature and ease of being worked around in the kernel source, it isn't being highly prioritized. But since I both don't want these blinds spots with Clang (and GCC) var-init, and I don't want these warnings to suddenly appear once GCC 12 _does_ get released, so I'd like to get this case fixed as well. All that said, I think this patch could be improved. I'd recommend, instead, just simply: diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index f2f8f05662de..9e765d30da82 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -1671,13 +1671,14 @@ phys_addr_t __init acpi_iort_dma_get_max_cpu_address(void) end = ACPI_ADD_PTR(struct acpi_iort_node, iort, iort->header.length); for (i = 0; i < iort->node_count; i++) { + struct acpi_iort_named_component *ncomp; + struct acpi_iort_root_complex *rc; + phys_addr_t local_limit; + if (node >= end) break; switch (node->type) { - struct acpi_iort_named_component *ncomp; - struct acpi_iort_root_complex *rc; - phys_addr_t local_limit; case ACPI_IORT_NODE_NAMED_COMPONENT: ncomp = (struct acpi_iort_named_component *)node->node_data; This results in no change in binary instruction output (when there is no auto-init). -Kees [1] https://github.com/llvm/llvm-project/issues/44261 > > > > --- > > drivers/acpi/arm64/iort.c | 12 ++++++------ > > 1 file changed, 6 insertions(+), 6 deletions(-) > > > > diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c > > index 3b23fb775ac4..65395f0decf9 100644 > > --- a/drivers/acpi/arm64/iort.c > > +++ b/drivers/acpi/arm64/iort.c > > @@ -1645,7 +1645,7 @@ void __init acpi_iort_init(void) > > */ > > phys_addr_t __init acpi_iort_dma_get_max_cpu_address(void) > > { > > - phys_addr_t limit = PHYS_ADDR_MAX; > > + phys_addr_t local_limit, limit = PHYS_ADDR_MAX; > > struct acpi_iort_node *node, *end; > > struct acpi_table_iort *iort; > > acpi_status status; > > @@ -1667,17 +1667,16 @@ phys_addr_t __init acpi_iort_dma_get_max_cpu_address(void) > > break; > > > > switch (node->type) { > > + case ACPI_IORT_NODE_NAMED_COMPONENT: { > > struct acpi_iort_named_component *ncomp; > > - struct acpi_iort_root_complex *rc; > > - phys_addr_t local_limit; > > - > > - case ACPI_IORT_NODE_NAMED_COMPONENT: > > ncomp = (struct acpi_iort_named_component *)node->node_data; > > local_limit = DMA_BIT_MASK(ncomp->memory_address_limit); > > limit = min_not_zero(limit, local_limit); > > break; > > > > - case ACPI_IORT_NODE_PCI_ROOT_COMPLEX: > > + } > > + case ACPI_IORT_NODE_PCI_ROOT_COMPLEX: { > > + struct acpi_iort_root_complex *rc; > > if (node->revision < 1) > > break; > > > > @@ -1686,6 +1685,7 @@ phys_addr_t __init acpi_iort_dma_get_max_cpu_address(void) > > limit = min_not_zero(limit, local_limit); > > break; > > } > > + } > > node = ACPI_ADD_PTR(struct acpi_iort_node, node, node->length); > > } > > acpi_put_table(&iort->header); > > > > _______________________________________________ > > linux-arm-kernel mailing list > > linux-arm-kernel@lists.infradead.org > > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel -- Kees Cook