From patchwork Sat Nov 5 10:36:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 15946 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp918822wru; Sat, 5 Nov 2022 03:36:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6EsDLvnNMC/CjgUhY4QOFSfNodWWYGweBaT15i9UxR5PMgyx2OCBEkrdwJJ1tYnLZtgwhK X-Received: by 2002:a17:90b:33ce:b0:213:e25b:9448 with SMTP id lk14-20020a17090b33ce00b00213e25b9448mr33080365pjb.44.1667644610674; Sat, 05 Nov 2022 03:36:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667644610; cv=none; d=google.com; s=arc-20160816; b=fZjWkSxopxdAACuMRH9VinrK0RIA6OO2FNTqOPYIV++ehTqqAmKF9muYmgK0zJnchr c30WXR5VCKomHV9d96bOUPf7/4PU44/Gc2cTU0gRINZ5wigMH/d3D4P13Jr00XgLbqtT 3s3X87oWt5gLPFixdDeBbT08g2/zXd9OKk5X5OHhcMdxwjSNRzGNARtzxA3mBi4KMqIV +MZgsXKtaijn49uPNX6LdZTubHWhsRrARtUDb4SNonuxQGaNfNAaN8Hl1XnAIzy9gK/8 stIUzKLno1uUe9yfukveIedu2D3aOJiejRPBPcafh5I1G4p4cgZa5EPLaz9J3FmbKgER xCYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=J2oLfthfo/dLH2t7ocF1ovI/aIMzujArDGnbhIkLGtI=; b=NiYoBv7qyDcbMlgAmY2dbyUu3n5lbAOJkQ84s0w+amqhqd0mkp9RAEb2ESQNOLrsf9 Ue+nqJHaIVquWWnprGoKV1iCXOeuOthq9UfY5/aqgqPonwKBJ34N9V0X1Sh1P6EGX+98 d4kE9uLgH5t/NKbeUKFFa/8L+g3qSDJtOug4WcMB+RUoE37Iu1j9B+0tSQrIJJStN7Cy tZDOGQaM/L4y4DBjYZFm3nYI1JREKpDxCvDDzzztAEM0n0i4ZiPxTwS/79IUvqiza1Pj 4D8tzoZVdHLgRM8JtO4ilwA3re2BK/d5hz/9V1ugRNdqkYTVoaH9npPj+sdYjPulcz4R jszg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=peJSQ+NC; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 11-20020a63164b000000b0046afcba3088si2475211pgw.735.2022.11.05.03.36.37; Sat, 05 Nov 2022 03:36:50 -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=@linutronix.de header.s=2020 header.b=peJSQ+NC; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229536AbiKEKgb (ORCPT + 99 others); Sat, 5 Nov 2022 06:36:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbiKEKg3 (ORCPT ); Sat, 5 Nov 2022 06:36:29 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D7442AE38; Sat, 5 Nov 2022 03:36:28 -0700 (PDT) Date: Sat, 05 Nov 2022 10:36:25 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667644587; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=J2oLfthfo/dLH2t7ocF1ovI/aIMzujArDGnbhIkLGtI=; b=peJSQ+NC2CDrgndPuGnoUk1s65BsCDKrP2jzXt3/ugasfpE8i+2uvdv4eSXKBqs0qvVY0q wVMsBBZuHkxmZU0fcuD6vCcdPBSU+KRU1ozBFKZZL7OVCQ+olKp0Yke/7mIEXEtTheH9ek kieiok7JzRmnnZknuXL55/E3WFWs8wcEdcNiFdUhkz/Yt6MmtKtH1dp0ESJyS5Jc/pw5Q1 GMfPTQ50aBKPe8HOg4KPftmIV8SgDfrx143tlqDGFE+fqrVfdVxkbN8HqeB8Wzo8BKtnmp +tvZ630gbStUPyjIZuZNCS/2RyiUKB+fqoGHNHf1xSuUZ4mkZ9ykEnXo6GLqFQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667644587; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=J2oLfthfo/dLH2t7ocF1ovI/aIMzujArDGnbhIkLGtI=; b=0fIKfg18i8yDzU4XQT5gppgjGkCcA5+BlvEA52O4L1QCiV9Fh7FBgsTZwj1ef6UVaQjhmu nDWtOoNbubQpwXBw== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/core] x86,pm: Force out-of-line memcpy() Cc: "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <166764458578.4906.12379655891294297691.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748652115350711192?= X-GMAIL-MSGID: =?utf-8?q?1748652115350711192?= The following commit has been merged into the x86/core branch of tip: Commit-ID: b32fd8a60f5d855758208c2b5b49cba8087f03c4 Gitweb: https://git.kernel.org/tip/b32fd8a60f5d855758208c2b5b49cba8087f03c4 Author: Peter Zijlstra AuthorDate: Thu, 03 Nov 2022 21:17:03 +01:00 Committer: Peter Zijlstra CommitterDate: Sat, 05 Nov 2022 11:28:02 +01:00 x86,pm: Force out-of-line memcpy() GCC fancies inlining memcpy(), and because it cannot prove the destination is page-aligned (it is) it ends up generating atrocious code like: 19e: 48 8b 15 00 00 00 00 mov 0x0(%rip),%rdx # 1a5 1a1: R_X86_64_PC32 core_restore_code-0x4 1a5: 48 8d 78 08 lea 0x8(%rax),%rdi 1a9: 48 89 c1 mov %rax,%rcx 1ac: 48 c7 c6 00 00 00 00 mov $0x0,%rsi 1af: R_X86_64_32S core_restore_code 1b3: 48 83 e7 f8 and $0xfffffffffffffff8,%rdi 1b7: 48 29 f9 sub %rdi,%rcx 1ba: 48 89 10 mov %rdx,(%rax) 1bd: 48 8b 15 00 00 00 00 mov 0x0(%rip),%rdx # 1c4 1c0: R_X86_64_PC32 core_restore_code+0xff4 1c4: 48 29 ce sub %rcx,%rsi 1c7: 81 c1 00 10 00 00 add $0x1000,%ecx 1cd: 48 89 90 f8 0f 00 00 mov %rdx,0xff8(%rax) 1d4: c1 e9 03 shr $0x3,%ecx 1d7: f3 48 a5 rep movsq %ds:(%rsi),%es:(%rdi) Notably the alignment code generates a text reference to code_restore_code+0xff8, for which objtool raises the objection: vmlinux.o: warning: objtool: relocate_restore_code+0x3d: relocation to !ENDBR: next_arg+0x18 Applying some __assume_aligned(PAGE_SIZE) improve code-gen to: 19e: 48 89 c7 mov %rax,%rdi 1a1: 48 c7 c6 00 00 00 00 mov $0x0,%rsi 1a4: R_X86_64_32S core_restore_code 1a8: b9 00 02 00 00 mov $0x200,%ecx 1ad: f3 48 a5 rep movsq %ds:(%rsi),%es:(%rdi) And resolve the problem, however, none of this is important code and a much simpler solution still is to force a memcpy() call: 1a1: ba 00 10 00 00 mov $0x1000,%edx 1a6: 48 c7 c6 00 00 00 00 mov $0x0,%rsi 1a9: R_X86_64_32S core_restore_code 1ad: e8 00 00 00 00 call 1b2 1ae: R_X86_64_PLT32 __memcpy-0x4 Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/power/hibernate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/power/hibernate.c b/arch/x86/power/hibernate.c index e94e005..6f955eb 100644 --- a/arch/x86/power/hibernate.c +++ b/arch/x86/power/hibernate.c @@ -159,7 +159,7 @@ int relocate_restore_code(void) if (!relocated_restore_code) return -ENOMEM; - memcpy((void *)relocated_restore_code, core_restore_code, PAGE_SIZE); + __memcpy((void *)relocated_restore_code, core_restore_code, PAGE_SIZE); /* Make the page containing the relocated code executable */ pgd = (pgd_t *)__va(read_cr3_pa()) +