Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1309779rwi; Thu, 13 Oct 2022 11:50:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7X6sQ2d6RPy/USmpu1XLNVdL13azW+cg2c3pWa2oM+NlvrdAR1PUOiyerqWIXgJEkaZGld X-Received: by 2002:a17:902:bcc3:b0:178:639a:1a10 with SMTP id o3-20020a170902bcc300b00178639a1a10mr1082458pls.159.1665687037994; Thu, 13 Oct 2022 11:50:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665687037; cv=none; d=google.com; s=arc-20160816; b=YcOWuNqSieE5ChVLs0pnkSiaxdCykM6USYtIN0rEredWmcrhCW0CK7RpIomcXJKIE4 tjb+X1cOa7Unze68bcaYbpGzIyRE1haVrjj9vx8BToGGb/stu1xxmssblUWtJCzfcTu5 Fvf8XTnjsFZLpgbtiOoU1T+knca7Y10gOnHXKGm3MNaw+FM+vK8nU7k86QsPaMQEOa7S wFsROQonWabW0gyciaZsrCIQfOmXn58IBBEWWOcGMVmcbDX9ekWYEICCpsIW4rJ++dpL RPgCh6Zm+/NKcIOtY48rI4kF7Nm+ta1Jk+zG1C1ZM58OYHiAX2XKVcKsTMCHteODOfPe DcWg== 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=pGJ0JmD8WJA14ZbpJGAWkegUF3RuH5CeLhV7YEXL4VY=; b=TbzhMKb3PRq5KlajYOvf/KboLjauQ0ZmqZOOel8ogwZEga/2eCphYFRaumKaVGYur1 PcfUWB2/a0cLTND1G52LGCuzzG5qW6WROxyVVmkcssMoSWZfhZZ4T0Nv9eR2W8e3dF8G UfvhYgm6/thDCTCUkhFu6/UrRYe1nyTc1i12gxQqk4uAllM5kjpvQce0u0gHN0eQwcFv 6CDtHiZNmpYsRxRA28XbyMrM2z3RUcJaShnX3TkUdvBpzoOio4URnYYIniB5Fw8WQfs7 kxH2TjXfVq7tqA8UWFX2V1klpODOPJ+JNefqcwShohvF6Y1Z+33j2rtot6xTOMOD9xCa w3CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qh8KP1Lp; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 70-20020a630249000000b0045f74df51e4si75876pgc.803.2022.10.13.11.50.23; Thu, 13 Oct 2022 11:50:37 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qh8KP1Lp; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231156AbiJMSHE (ORCPT + 99 others); Thu, 13 Oct 2022 14:07:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230470AbiJMSEp (ORCPT ); Thu, 13 Oct 2022 14:04:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 393A816D8A8; Thu, 13 Oct 2022 11:04:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6FD7261931; Thu, 13 Oct 2022 17:57:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8CF41C433D6; Thu, 13 Oct 2022 17:57:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665683859; bh=EyyroCt/Oi7NB05fM0Tdh01bogd28QcQYT/jhBM2tZc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qh8KP1LpxDd9TUgJSMPcjhYu2RX2yN/EuWuwwhWNEpTQxVyYH2G29uKONQhNvZueu drL/zWdgT7Ah4yoolSji5CKEn/5dCf8tDuCOrtcUs93Me6bY260SjF0LSKSK8CaFgp hSjRv+YKhmTSLfqvrLYpmmDy3NYLKO4g/BoB0GncLTaLllRG/hzM6TXkNzHlzR8DyP 2XV+rLUZM1CTE40Gsbn8hsFfz9dk/V2/3Q5yAAc4UrUymOi9RleMkTQLVRpywHz8RX 0dVEt1ltUrK/okgw58W4AV5IyaQXLtpd1aXmTCRg1E1nha9No+URmzXCf0VpL5DZkN hntD4GirhZiZg== Date: Thu, 13 Oct 2022 13:57:38 -0400 From: Sasha Levin To: Catalin Marinas Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Mark Rutland , Will Deacon , peterz@infradead.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH AUTOSEL 5.19 17/40] arm64: atomics: remove LL/SC trampolines Message-ID: References: <20221011145129.1623487-1-sashal@kernel.org> <20221011145129.1623487-17-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,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 Wed, Oct 12, 2022 at 09:53:53AM +0100, Catalin Marinas wrote: >Hi Sasha, > >On Tue, Oct 11, 2022 at 10:51:06AM -0400, Sasha Levin wrote: >> From: Mark Rutland >> >> [ Upstream commit b2c3ccbd0011bb3b51d0fec24cb3a5812b1ec8ea ] >> >> When CONFIG_ARM64_LSE_ATOMICS=y, each use of an LL/SC atomic results in >> a fragment of code being generated in a subsection without a clear >> association with its caller. A trampoline in the caller branches to the >> LL/SC atomic with with a direct branch, and the atomic directly branches >> back into its trampoline. >> >> This breaks backtracing, as any PC within the out-of-line fragment will >> be symbolized as an offset from the nearest prior symbol (which may not >> be the function using the atomic), and since the atomic returns with a >> direct branch, the caller's PC may be missing from the backtrace. >> >> For example, with secondary_start_kernel() hacked to contain >> atomic_inc(NULL), the resulting exception can be reported as being taken >> from cpus_are_stuck_in_kernel(): >> >> | Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 >> | Mem abort info: >> | ESR = 0x0000000096000004 >> | EC = 0x25: DABT (current EL), IL = 32 bits >> | SET = 0, FnV = 0 >> | EA = 0, S1PTW = 0 >> | FSC = 0x04: level 0 translation fault >> | Data abort info: >> | ISV = 0, ISS = 0x00000004 >> | CM = 0, WnR = 0 >> | [0000000000000000] user address but active_mm is swapper >> | Internal error: Oops: 96000004 [#1] PREEMPT SMP >> | Modules linked in: >> | CPU: 1 PID: 0 Comm: swapper/1 Not tainted 5.19.0-11219-geb555cb5b794-dirty #3 >> | Hardware name: linux,dummy-virt (DT) >> | pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) >> | pc : cpus_are_stuck_in_kernel+0xa4/0x120 >> | lr : secondary_start_kernel+0x164/0x170 >> | sp : ffff80000a4cbe90 >> | x29: ffff80000a4cbe90 x28: 0000000000000000 x27: 0000000000000000 >> | x26: 0000000000000000 x25: 0000000000000000 x24: 0000000000000000 >> | x23: 0000000000000000 x22: 0000000000000000 x21: 0000000000000000 >> | x20: 0000000000000001 x19: 0000000000000001 x18: 0000000000000008 >> | x17: 3030383832343030 x16: 3030303030307830 x15: ffff80000a4cbab0 >> | x14: 0000000000000001 x13: 5d31666130663133 x12: 3478305b20313030 >> | x11: 3030303030303078 x10: 3020726f73736563 x9 : 726f737365636f72 >> | x8 : ffff800009ff2ef0 x7 : 0000000000000003 x6 : 0000000000000000 >> | x5 : 0000000000000000 x4 : 0000000000000000 x3 : 0000000000000100 >> | x2 : 0000000000000000 x1 : ffff0000029bd880 x0 : 0000000000000000 >> | Call trace: >> | cpus_are_stuck_in_kernel+0xa4/0x120 >> | __secondary_switched+0xb0/0xb4 >> | Code: 35ffffa3 17fffc6c d53cd040 f9800011 (885f7c01) >> | ---[ end trace 0000000000000000 ]--- >> >> This is confusing and hinders debugging, and will be problematic for >> CONFIG_LIVEPATCH as these cases cannot be unwound reliably. >> >> This is very similar to recent issues with out-of-line exception fixups, >> which were removed in commits: >> >> 35d67794b8828333 ("arm64: lib: __arch_clear_user(): fold fixups into body") >> 4012e0e22739eef9 ("arm64: lib: __arch_copy_from_user(): fold fixups into body") >> 139f9ab73d60cf76 ("arm64: lib: __arch_copy_to_user(): fold fixups into body") >> >> When the trampolines were introduced in commit: >> >> addfc38672c73efd ("arm64: atomics: avoid out-of-line ll/sc atomics") >> >> The rationale was to improve icache performance by grouping the LL/SC >> atomics together. This has never been measured, and this theoretical >> benefit is outweighed by other factors: >> >> * As the subsections are collapsed into sections at object file >> granularity, these are spread out throughout the kernel and can share >> cachelines with unrelated code regardless. >> >> * GCC 12.1.0 has been observed to place the trampoline out-of-line in >> specialised __ll_sc_*() functions, introducing more branching than was >> intended. >> >> * Removing the trampolines has been observed to shrink a defconfig >> kernel Image by 64KiB when building with GCC 12.1.0. >> >> This patch removes the LL/SC trampolines, meaning that the LL/SC atomics >> will be inlined into their callers (or placed in out-of line functions >> using regular BL/RET pairs). When CONFIG_ARM64_LSE_ATOMICS=y, the LL/SC >> atomics are always called in an unlikely branch, and will be placed in a >> cold portion of the function, so this should have minimal impact to the >> hot paths. >> >> Other than the improved backtracing, there should be no functional >> change as a result of this patch. >> >> Signed-off-by: Mark Rutland >> Cc: Will Deacon >> Link: https://lore.kernel.org/r/20220817155914.3975112-2-mark.rutland@arm.com >> Signed-off-by: Catalin Marinas >> Signed-off-by: Sasha Levin > >I don't think we should back-port this. There is no functional change, >more of a clean-up in preparation for RELIABLE_STACKTRACE. The oops >message in the log is to show how reporting works rather than a real >bug. I went by the "This breaks backtracing" line when backporting :) I'll drop it, thanks! -- Thanks, Sasha