From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4BF7B3858D38; Mon, 30 Jan 2023 18:54:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4BF7B3858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675104860; bh=Q2h+nSL6hhRFZC+Xc1ZFrB3KNMO89/BYagfi2mHHnYI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=MtthW1TuHd8sgLCpHexyAOx37g2Xpr9g87UdfQ0GwoO5HIYJp2+KNuQ2KlBA7wAWR XbrSlyr3ITLkrkd692sfHQ+BRtbvbCDspgXVCFmO8DiOsWaB2/LVgpHG5Rogylq4A2 m0q3tyV1veUwwDpFnlPtWkTP3nZ5J/CgY3ZOXsQE= From: "torvalds@linux-foundation.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/108552] Linux i386 kernel 5.14 memory corruption for pre_compound_page() when gcov is enabled Date: Mon, 30 Jan 2023 18:54:18 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 11.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: torvalds@linux-foundation.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108552 --- Comment #47 from Linus Torvalds --- (In reply to Richard Biener from comment #45) > For user code >=20 > volatile long long x; > void foo () { x++; } >=20 > emitting inc + adc with memory operands is only "incorrect" in re-ordering > the subword reads with the subword writes, the reads and writes still hap= pen > architecturally ... But the thing is, the ordering *is* very much defined for volatile accesses. "volatile" is not a "the access happens architecturally", it's very much defined "the access is _visible_ architecturally, and ordering matters". So with the "volatile long long x" code, I think any language lawyer will s= ay that generating it as add $1,mem adc $0,mem+4 is unquestionably a compiler bug. It may be what the user *wants* (and it's obviously what the gcov code would like), but it's simply not a valid volatile access to 'x'. So the gcov code would really want something slightly weaker than 'volatile= '. Something that just does 'guaranteed access' and disallows combining stores= or doing re-loads, without the ordering constraints. Side note: we would use such a "weaker volatile" in the kernel too. We alre= ady have that concept in the form of READ_ONCE() and WRITE_ONCE(), and it uses "volatile" internally, and it works fine for us. But if we had another way = to just describe "guaranteed access", that could be useful. I suspect the memory ordering primitives would be a better model than 'volatile' for this. What are the rules for doing it as load/store with 'memory_order_relaxed'? That should at least guarantee that the load is nev= er re-done (getting two different values for anybody who does a load), but may= be the stores can be combined? And gcc should already have all that infrastructure in place. Hmm?=