Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2092268pxb; Fri, 25 Mar 2022 10:57:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIQtVnheZdRfCHbWVDOvcvuMy8KQl+5YSJA34Uq5OCJBjD3rjH85clN1CZcUFPQENiL2ND X-Received: by 2002:a17:903:230a:b0:154:6770:ea6d with SMTP id d10-20020a170903230a00b001546770ea6dmr13033987plh.139.1648231051276; Fri, 25 Mar 2022 10:57:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648231051; cv=none; d=google.com; s=arc-20160816; b=WsTPHzS5XpwJqjdM1oh+8sHBJKe87h8blFIL2A/0XqFvV6WZNNjxE4PwecgOcDKPtP 9SGOuccJ2nT7U6d+eqoq2xPmcPS+Qb3Ujduohzd3XbQjcTNJfflJq7EtjGx0cBZso6hN M1SZJ6wZ8BlaUGKQPmQhjL9Wn0riqKx0AHLaUDK/LJgH3kWvuQC/Pjf3Tbjz2QZm48a2 z/nuT7n7uTvbs/BCmQuFps+s+8DwTuycBRxMBmTq2vPiM8ZmpErFbvh6ZlxOdjWv+bz6 R0Itnxgp3HFKDEy8PZ890efmIBs0/ODxAe8BS0VJiyUDDnWAjzlJv1rjfwqnld5YyoRk hxCg== 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; bh=3JV7I98gTGI5aKRnT6mTZiQK+SUA0c+OIAPRIpf91ic=; b=iszscCshKOBF9xf16MkBxx7mdxvp+e+eKryJ+ke84tDhJUrf0TIVQ0KKmHkdF5wGb7 YupmJj0kq37lWLrJhvgIIU4RvIk1eYjl+EtukuChvZzaQFlDdH2bGL5ffFmk+3HSGA4Y q3mraHMzaw9CZxkl7St67qcOesEWb4yKRMX2jH3rIHuBj2Cffb7fekRaPYZ7hbW5tW4Y 8CRqnEZINzzN5fs2CjTlfQ13/c3ekpxIfiB9wFlpdJRQ6T6L8AEqhN2KQaxGlYb4P2E8 jvsysHZGNX2J4jo4rmSX7RMGCpJIuR7L9ydDcBv1sCTdbwN3oX1mTpPLnknhGvnICzyu nVjQ== 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:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c20-20020a631c14000000b0038251571eacsi3057921pgc.180.2022.03.25.10.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 10:57:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 069C1111775; Fri, 25 Mar 2022 10:37:01 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351281AbiCXPbi (ORCPT + 99 others); Thu, 24 Mar 2022 11:31:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239897AbiCXPbg (ORCPT ); Thu, 24 Mar 2022 11:31:36 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 341C45AA75 for ; Thu, 24 Mar 2022 08:30:04 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A64301515; Thu, 24 Mar 2022 08:30:03 -0700 (PDT) Received: from lakrids (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AD4A03F73B; Thu, 24 Mar 2022 08:30:02 -0700 (PDT) Date: Thu, 24 Mar 2022 15:29:56 +0000 From: Mark Rutland To: Borislav Petkov Cc: Nick Desaulniers , Nathan Chancellor , x86-ml , lkml , Peter Zijlstra , Josh Poimboeuf Subject: Re: clang memcpy calls Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Thu, Mar 24, 2022 at 12:19:19PM +0100, Borislav Petkov wrote: > Hi folks, Hi Boris, > 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". I think there's a more general soundness problem with noinstr here, because with the options we pass today it's entirely legitimate for the compiler to generate out-of-line calls to a number of support functions (e.g. memcpy, but also memset and others), and we either need to inhibit out-of-line calls to *any* of those, or ensure the out-of-line copies used are never instrumented. I'm not entirely sure how to prevent this on arm64 short of some whole-compilation-unit shennanigans -- we don't have short sequence like "rep movsq" that can be easily inlined, and we explicitly instrument mem*() when certain KASAN options are selected. I think we need more compiler help to make noinstr sound generally, and/or may need to rethink the way we use noinstr. Thanks, Mark. > 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