Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2702361imw; Sun, 17 Jul 2022 15:06:19 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tfrf+MEEkjKlsXOPNyepSzPXCPg5dWYiI7poUz3yEnjRBci3gvNaQUv4IuDJNwCp5FDwkD X-Received: by 2002:a17:906:9c82:b0:6df:baa2:9f75 with SMTP id fj2-20020a1709069c8200b006dfbaa29f75mr23163627ejc.762.1658095579615; Sun, 17 Jul 2022 15:06:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658095579; cv=none; d=google.com; s=arc-20160816; b=mpQ8dQ3DquPo3zTTzidx64BpmScnO5XYzIRULpbEF3Di0G/f4tWhcGJKm4/yplksWC 6YZch1rH9rkroWALT3ImKvapv/UMV8eMNzd/jvaMO5MNNjlA+ZvS6/0H10E8PFhyKm9U 8zxRXzoe+RK9UIHsYFiwGV7BVpUlWwfJQuQBh6L6bn21113FFEPNNt7mAX2jEpX+yZTW BglQiddvHoAi6JIOHK4TLTdJ9c8xo90HT8B4haFn2Pbcl/69HoiCyHILA9dfJhtOE31P bDLy+nOJHVWwgnrkuSjR5aXKoe0AAJ5hYAD120PgmTgdk3pXiNTob1rQliAqSdro0ihQ Og3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=h2hWrmP9m2DErUpxXx3urSVD2AW8dcKvhJmlLdZrRh0=; b=n3XbhN9I1pTG2mu97gc7+STtKX9a0cidSfHMLB4fQi58z+YItts3rTLIeKaaqZIZyt cyQitWcbOnm6k4QIu6yAr6QzMaiYwqSYXx5oXLsgZ2ZFzpz3uVTWvS69gO5yFGozFwRY J6TlOLzbVQmfpPdB6YzGK8PBmxvFeqExvgjVIzw11SZiUy9EGZwgnM4hpBVwTx6Eu6aD U/xh7tofYVBHdmgrWGZ2goB2L6pMLr/InbLfI54+V6rH2e/8oUs5UiXeIo87s1kvqP/j 2pJZtR8SiijkYRjgk3rTW5bCJHUVLjOCX5sYyCEQ+qyCNZd06G5mqosPYTNCowN1SI4I BQwg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m13-20020a056402510d00b0043a54f78399si8017311edd.485.2022.07.17.15.05.54; Sun, 17 Jul 2022 15:06:19 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232300AbiGQVxd (ORCPT + 99 others); Sun, 17 Jul 2022 17:53:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229587AbiGQVxc (ORCPT ); Sun, 17 Jul 2022 17:53:32 -0400 Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AF2381263D; Sun, 17 Jul 2022 14:53:31 -0700 (PDT) Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 26HLjA69019105; Sun, 17 Jul 2022 16:45:10 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 26HLj9EJ019104; Sun, 17 Jul 2022 16:45:09 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Sun, 17 Jul 2022 16:45:08 -0500 From: Segher Boessenkool To: Linus Torvalds Cc: Sudip Mukherjee , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Kees Cook , linuxppc-dev , linux-kernel , linux-hardening@vger.kernel.org Subject: Re: mainline build failure of powerpc allmodconfig for prom_init_check Message-ID: <20220717214508.GD25951@gate.crashing.org> References: <20220717205615.GC25951@gate.crashing.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS 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 Sun, Jul 17, 2022 at 02:11:52PM -0700, Linus Torvalds wrote: > On Sun, Jul 17, 2022 at 2:00 PM Segher Boessenkool > wrote: > > Calling mem* on a volatile object (or a struct containing one) is not > > valid. I opened gcc.gnu.org/PR106335. > > Well, that very quickly got marked as a duplicate of a decade-old bug. > > So I guess we shouldn't expect this to be fixed any time soon. It shouldn't be all that hard to implement. GCC wants all ports to define their own mem* because these functions are so critical for performance, but it isn't hard to do a straightforward by-field copy for assignments if using memcpy would not be valid at all. Also, if we would have this we could make a compiler flag saying to always open-code this, getting rid of this annoyance (namely, that extetnal mem* are required) for -ffreestanding. > That said, your test-case of copying the whole structure is very > different from the one in the kernel that works on them one structure > member at a time. > > I can *kind of* see the logic that when you do a whole struct > assignment, it turns into a "memcpy" without regard for volatile > members. You're not actually accessing the volatile members in some > particular order, so the struct assignment arguably does not really > have an access ordering that needs to be preserved. The order is not defined, correct. But a "volatile int" can only be accessed as an int, and an external memcpy will typically use different size accesses, and can even access some fields more than once (or partially); all not okay for a volatile object. > But the kernel code in question very much does access the members > individually, and so I think that the compiler quite unequivocally did > something horribly horribly bad by turning them into a memset. > > So I don't think your test-case is really particularly good, and maybe > that's why that old bug has languished for over a decade - people > didn't realize just *how* incredibly broken it was. People haven't looked at my test case for all that time, it sprouted from my demented mind just minutes ago ;-) The purpose of writing it this way was to make sure that memcpy will be called for this (on any target etc.), not some shorter and/or smarter thing. I don't know what the real reason is that this bugs hasn't been fixed yet. It should be quite easy to make this more correct. In Richard suggested doing it in the frontend, which seems reasonable (but more work than the patch there). There have been no follow-up patches as far as I can see :-( Segher