Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp898823pxb; Thu, 24 Mar 2022 08:56:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwClF1f1S7/rqp9L5KileVRtZpmKXvasNXQ+z2ivNH0l66pS759h8+AUpiaMTD3Szsmjwf/ X-Received: by 2002:a63:1758:0:b0:381:effc:b48f with SMTP id 24-20020a631758000000b00381effcb48fmr4591670pgx.124.1648137379431; Thu, 24 Mar 2022 08:56:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648137379; cv=none; d=google.com; s=arc-20160816; b=ddfN6UExPkAqJr4aJADpkTVl0by2WQc9sz1w9IlAWAlHzNjPzRx4pO9s2d2xrEo1KC WiJY2FSOfnKqzEvu3Xb7dCJ8NnB1I9jRErHWeqobQZN6Hd8c6u2GhF8Qn94zaosRO0oN Mgn+3VqczIlp8v0Rzk7UlXE0E/y6n2BeKk/Z5K/im+bZEjzcXYhUPsCvPV6RpyCyAXba KFQUeW67ZxSKZJV6I2BARpbI1kt/R15F/2q+x3a7XJqd8ZU7iFoT8cJbXa0iVPNs/Zxw ymgWxPJe4jaRe6S0WCjrZ9iFc3luROdLfk9abQ7X2UVShqWSFCgj0Ks2dO9AxB2Fovsx ETkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=zQ487WGGxoU+PaAQiF6Z96QlXNCWPl8aoNSJ7IshVJ8=; b=tqYMkYMkYuBvMskKWts8ROp81pnehlBfzjberuNuuGvA8OKidttcCAK1Loyt4pcUMW iVaJUBP7WB0nHfQEbrUEYYIxKJjjwhsBSHXbFGFRGwnd9Yo3koO+8i1rbSCK8H5IkR5C CyAya+Rzw30iGJ+A5QyzSbYLkWGpoEcnDaLoKXZsteujfeidMdNggDhDoEdGRsCpQaf1 gZMKBZMrqRYKIolZD03ryUFdLYZt56F/79bicGpE/7hIRBVt0RKTHuZ6tDLVfFiF4jJ8 KKNxFOpsQRY8Rge15erBR3YGfI6fi8aCeIucgsPQBz5NuALNso2JRDETTQjlWWIinYo4 NWhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=fQB156Fo; 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=alien8.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m18-20020a656a12000000b003860088b975si9254610pgu.93.2022.03.24.08.56.05; Thu, 24 Mar 2022 08:56: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; dkim=pass header.i=@alien8.de header.s=dkim header.b=fQB156Fo; 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=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243101AbiCXLVC (ORCPT + 99 others); Thu, 24 Mar 2022 07:21:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236369AbiCXLVB (ORCPT ); Thu, 24 Mar 2022 07:21:01 -0400 Received: from mail.skyhub.de (mail.skyhub.de [5.9.137.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B563C558B for ; Thu, 24 Mar 2022 04:19:29 -0700 (PDT) Received: from zn.tnic (p2e55dff8.dip0.t-ipconnect.de [46.85.223.248]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 4C0191EC04F9; Thu, 24 Mar 2022 12:19:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1648120764; h=from:from: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:in-reply-to:references; bh=zQ487WGGxoU+PaAQiF6Z96QlXNCWPl8aoNSJ7IshVJ8=; b=fQB156FoQMS/bM1ss8dkbyOOZIvEx+opgWLoP6Jb/LSVXWv40/w5Df61jEVhjjMICBLozD 0o1VC9MdAlaJYx7Ba///m/C10EweJbQvDInMTpKR6ps8imKToZxgXwh1A46FKRBcVtawCr uA6hE8op4Cllx/rOHdDTsqOXT/1cR7I= Date: Thu, 24 Mar 2022 12:19:19 +0100 From: Borislav Petkov To: Nick Desaulniers , Nathan Chancellor Cc: x86-ml , lkml Subject: clang memcpy calls Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Hi folks, so I've been looking at a recent objtool noinstr warning from clang builds: vmlinux.o: warning: objtool: sync_regs()+0x20: call to memcpy() leaves .noinstr.text section The issue is that clang generates a memcpy() call when a struct copy happens: if (regs != eregs) *regs = *eregs; see below for asm output. While gcc does simply generate an actual "rep; movsq". So, how hard would it be to make clang do that too pls? Oh, and another thing while we're comparing asm: I'd love for clang's -fverbose-asm to issue interleaved C source lines too, like gcc does. That's it - no pink pony - just "normal" wishes. :-) GCC: ==== sync_regs: .LASANPC4246: # arch/x86/kernel/traps.c:770: { movq %rdi, %rsi # tmp91, eregs # arch/x86/kernel/traps.c:771: struct pt_regs *regs = (struct pt_regs *)this_cpu_read(cpu_current_top_of_stack) - 1; #APP # 771 "arch/x86/kernel/traps.c" 1 movq %gs:cpu_current_top_of_stack(%rip), %rax # cpu_current_top_of_stack, pfo_val__ # 0 "" 2 # arch/x86/kernel/traps.c:771: struct pt_regs *regs = (struct pt_regs *)this_cpu_read(cpu_current_top_of_stack) - 1; #NO_APP subq $168, %rax #, # arch/x86/kernel/traps.c:772: if (regs != eregs) cmpq %rdi, %rax # eregs, je .L387 #, # arch/x86/kernel/traps.c:773: *regs = *eregs; movl $21, %ecx #, tmp89 movq %rax, %rdi # , rep movsq .L387: # arch/x86/kernel/traps.c:775: } ret CLANG: ====== .section .noinstr.text,"ax",@progbits .globl sync_regs # -- Begin function sync_regs .p2align 6, 0x90 .type sync_regs,@function sync_regs: # @sync_regs # %bb.0: # %entry pushq %rbx #APP movq %gs:cpu_current_top_of_stack(%rip), %rbx #NO_APP addq $-168, %rbx cmpq %rdi, %rbx je .LBB19_2 # %bb.1: # %if.then movq %rdi, %rsi movl $168, %edx movq %rbx, %rdi callq memcpy@PLT .LBB19_2: # %if.end movq %rbx, %rax popq %rbx retq -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette