Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp10916295rwd; Thu, 22 Jun 2023 06:35:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ58O7CmTLl/dwWz9+U7JcZD6r++2ADq4GqiuTWy31SUEgR2Jh581qVp9S0MUVF+pKIEYBXA X-Received: by 2002:a17:902:9f97:b0:1b0:637e:e25a with SMTP id g23-20020a1709029f9700b001b0637ee25amr17535623plq.67.1687440925521; Thu, 22 Jun 2023 06:35:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687440925; cv=none; d=google.com; s=arc-20160816; b=SDF8QvCoIo7hDO9SD/ZBObuqbhevz/9eGjyhaxCuswLMVlK24eMc7O4UNKc2qyOCZh +NxINpQXJT/PUbCAOx2QBPnbGNNRpZcvNCOkTxMUV24R49UjUYI2mN7/XRsNzc+zCHZ0 LY8hxFGTwnQGVUl4fz2nbicsG+cmmzJZAzWNQjwuH9jpMNqON/qs5PZFfo6gsKVgtivE NkNH6WA1GDjKhx6xf6ZEhA6+S8RhcYt5WZ9EuLwLrGQ+3gjvB3BOHd+a3EXK+3QQfea3 naeI+y210UoeaY9kfaidvVJwPHGKCT1U3EDSe491AoROgBia8vwIcELfBp/AFIodroLa YGHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ZGsYjRdIk+qTEW9g8j9uHVQZ+FPzEP6/mOPSgQ8KtbM=; b=Wji3cjD70ZE8aUf+XIlXFwvg4jNdu7r4puAiOoOegAGJ4Ws0+fsIhqpCaFhQ6Ai2ld MRC+EcF0OsAe3YgAcxL5mBOqmd7qFH4AJgOopp6WCJilm7LTCZIuoiDYCYc8lrjyS+3Q W86xHqmb+7ujhxp8I1+P0I2fWo/B8U2p52X7J2xaKVrpqIosmk8ovSckyQePy+aJXf5q e2NEh7FjxdSIolCMdBxBjsonLVoleu+TJ09zYV3GiVr2vfFTn9Y7JI8JeMhdawpPbzuN duf2XvpSdca9hjo2dx6bf8dkWCZ4KI/Wo3rfqYTs856Pq9cD/S3jq2l60ZxOsiLaFJUT 6n6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=nf9I1PNF; 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=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e11-20020a17090301cb00b001b672af6244si7450742plh.266.2023.06.22.06.35.12; Thu, 22 Jun 2023 06:35:25 -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=@gmail.com header.s=20221208 header.b=nf9I1PNF; 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=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231520AbjFVNGl (ORCPT + 99 others); Thu, 22 Jun 2023 09:06:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231340AbjFVNGj (ORCPT ); Thu, 22 Jun 2023 09:06:39 -0400 Received: from mail-yb1-xb44.google.com (mail-yb1-xb44.google.com [IPv6:2607:f8b0:4864:20::b44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E2972111; Thu, 22 Jun 2023 06:06:11 -0700 (PDT) Received: by mail-yb1-xb44.google.com with SMTP id 3f1490d57ef6-bff0beb2d82so1614864276.2; Thu, 22 Jun 2023 06:06:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687439166; x=1690031166; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ZGsYjRdIk+qTEW9g8j9uHVQZ+FPzEP6/mOPSgQ8KtbM=; b=nf9I1PNF0yDYNhtU8M4SAhuCDuln7HMvgdjLpIGLbxc1or0A8Fyo4q4MoIMsYDRV6M TzKi2rnw4268I0d3S8sOv6bfY/ZgbuTaZkhuhdvzhxwpZep7KnbFOXrSudVP+7nMveKi bbW0u02XKYK1gnoygyCClchPRqtEDIf7pLRfeAAUZMFQ3eovxq1fxyFx95fJi/pZRPO3 RPq41Nc1X8GGuTOmgeUUyGnl7XEvZi5hkGzkIE6cQw3jcaRLIgKFOPWBM68QghgQuSST J583sL7duIAihSBfzYcWLBjCJAHPli0nLE+CJFFkpDgIoQ4g8LLY5PU/CpnGIFqr8xhq LHkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687439166; x=1690031166; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZGsYjRdIk+qTEW9g8j9uHVQZ+FPzEP6/mOPSgQ8KtbM=; b=aEcQhnpOdwo4OAzcAHCjsJj8HtlTD23dO3/OHmQYqjX10kva+bXeyBlAQY1IoEnA79 l3RncX1YR2gOIMtngJl01pdy0ydKYDzgPynJg6pIM8twuor+pwgRgXQ3mJ8tZ7ML0n8k hx/5zmuLWxatgzh8ElXmKUQCEs1uSG9FlKNMzfYiaGh1kQw/Cq0cimfl6zhwTOzN6dge F0G+KUl8PSqXbq8X/uXjUt7BSzV56/TxttVJo5cDi6awPf9TUiG/MziSUcET5rWiLcdy MQfNkOajiy8ruxkxKw8FWph951fL7dfVjzUYIdhzVSU5OuaDp8vn7pns8SREyNPfEf8D +w2w== X-Gm-Message-State: AC+VfDxMjyZzpZm4ljLsZn7f255yMdbpV23WMa4jMcDzoevAQyk07yH1 +OmYeD/evmSZ2ecifKooa449emtLPuyhpraA7aI= X-Received: by 2002:a25:800c:0:b0:bc5:edbe:8b43 with SMTP id m12-20020a25800c000000b00bc5edbe8b43mr13980225ybk.25.1687439166522; Thu, 22 Jun 2023 06:06:06 -0700 (PDT) MIME-Version: 1.0 References: <20230613025226.3167956-1-imagedong@tencent.com> <20230613025226.3167956-3-imagedong@tencent.com> <7a82744f454944778f55c36e8445762f@AcuMS.aculab.com> In-Reply-To: <7a82744f454944778f55c36e8445762f@AcuMS.aculab.com> From: Menglong Dong Date: Thu, 22 Jun 2023 21:05:55 +0800 Message-ID: Subject: Re: [PATCH bpf-next v5 2/3] bpf, x86: allow function arguments up to 12 for TRACING To: David Laight Cc: Yonghong Song , "alexei.starovoitov@gmail.com" , "ast@kernel.org" , "daniel@iogearbox.net" , "andrii@kernel.org" , "martin.lau@linux.dev" , "song@kernel.org" , "yhs@fb.com" , "john.fastabend@gmail.com" , "kpsingh@kernel.org" , "sdf@google.com" , "haoluo@google.com" , "jolsa@kernel.org" , "benbjiang@tencent.com" , "bpf@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Menglong Dong Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 On Thu, Jun 22, 2023 at 5:06=E2=80=AFPM David Laight wrote: > > ... > > > + /* Generally speaking, the compiler will pass the arguments > > > + * on-stack with "push" instruction, which will take 8-byte > > > + * on the stack. On this case, there won't be garbage values > > > > On this case -> In this case. The same for below another case. > > > > > + * while we copy the arguments from origin stack frame to current > > > + * in BPF_DW. > > > + * > > > + * However, sometimes the compiler will only allocate 4-byte on > > > + * the stack for the arguments. For now, this case will only > > > + * happen if there is only one argument on-stack and its size > > > + * not more than 4 byte. On this case, there will be garbage > > > + * values on the upper 4-byte where we store the argument on > > > + * current stack frame. > > Is that right for 86-64? > > IIRC arguments always take (at least) 64bits. > For any 32bit argument (register or stack) the high bits are undefined. > (Maybe in kernel they are always zero? > From 32bit userspace they are definitely random.) > Hello, According to my testing, the compiler will always pass the arguments on 8-byte size with "push" insn if the count of the arguments that need to be passed on stack more than 1 and the size of the argument doesn't exceed 8-byte. In this case, there won't be garbage. For example, the high 4-byte will be made 0 if the size of the argument is 4-byte, as the "push" insn will copy the argument from regs or imm into stack in 8-byte. If the count of the arguments on-stack is 1 and its size doesn't exceed 4-byte, some compiler, like clang, may not use the "push" insn. Instead, it allocates 4 bytes in the stack, and copies the arguments from regs or imm into stack in 4-byte. This is the case we deal with here. I'm not sure if I understand you correctly. Do you mean that there will be garbage values for 32bit args? > I think the called code is also responsible form masking 8 and 16bit > values (in reality char/short args and return values just add code > bloat). > > A 128bit value is either passed in two registers or two stack > slots. If the last register is skipped it will be used for the > next argument. > Yeah, this point is considered in save_args(). Once this happen, the count of stack slots should more then 1, and the arguments on-stack will be stored with "push" insn in 8-byte. Therefore, there shouldn't be garbage values in this case? Do I miss something? Thanks! Menglong Dong > David > > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1= 1PT, UK > Registration No: 1397386 (Wales)