Received: by 10.223.148.5 with SMTP id 5csp6423020wrq; Wed, 17 Jan 2018 13:33:08 -0800 (PST) X-Google-Smtp-Source: ACJfBovSlX8ThS8kID82kVC1f9QhakS13EGrtwO0c6fzzpF0E3jnQPvFoH4FtfGapg2mMsN4aWzD X-Received: by 10.84.248.134 with SMTP id q6mr36835980pll.247.1516224788536; Wed, 17 Jan 2018 13:33:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516224788; cv=none; d=google.com; s=arc-20160816; b=QvyakfgQmgfmVUfRGDJ6VQ3Ii1vTImElIfNTV6VWwLNF/x5+lFJyzoQCRVrLq3AV9k xD+tJpv/zARhtSh1JtVD++UoaCRkbSqNkaslrh87IJsZHemFv7CvfduICNQTOEkDUD5z 2KJToPmNnKtylgavnIGNJMXvot4S3AUnDbJQLPjnY4mlKA4or9zYZ91kk5laMq4GmcqB llqzC162P1xftUYFScRDkC2PjlMwhCqj+6OokCJNpF1tYrKk1t7ylCW5V9ZznoSCX9tb YTVIJdmW4O1K8j+RpjMSKS9pLl4hcxJqVIw3XvWxhIWpTPsBNmszYg7BUwzYChVwUDSe 1h8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=3+gVLjfy9qEkLV7UUi0LogwR2bgWd+1yKGOrc4BKohY=; b=FLh6eoK2Gz/6Z5DQclXVrxNdZhiLkA8Tba3qAZPmS/nzZmxEDF5ZALc51usrl5sU54 TsHwjrUbPYqVQacwxX1v7P/FPUXaveFEguWbUcZ9N/BNTsfLaojqa1WjOOjUUlgaoy0X p2JCUkXHNZ/aisu3wdWDI4xNhQSMU+gYcKLhqDxtk54K1mhvWBVDYDTjMyD61HNSjOlt R+zKetBgYzEG32ljK7+MzbdDSxKlz+JUXMKwDqYBtkZaYGus7PZ7etKyKmX6W8airkgf rDYvUVKFtC/1hefEPXsNHMh0xFN2u3PE7RufN5K/SSX7fhe9s7uxBQVfPzXVF/VhQbGZ lXgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=LETQ00fY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r3si5257088plo.432.2018.01.17.13.32.52; Wed, 17 Jan 2018 13:33:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=LETQ00fY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753189AbeAQVc0 (ORCPT + 99 others); Wed, 17 Jan 2018 16:32:26 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:43808 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750872AbeAQVcY (ORCPT ); Wed, 17 Jan 2018 16:32:24 -0500 Received: by mail-wm0-f67.google.com with SMTP id g1so17942708wmg.2; Wed, 17 Jan 2018 13:32:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3+gVLjfy9qEkLV7UUi0LogwR2bgWd+1yKGOrc4BKohY=; b=LETQ00fY/itDCDK87b8/U5Zx7FJRHg6cb/OAOac9M1PRf+YACs1h/P2yhWxYN69vY5 EacKzFbky07W6GCE2xxDch9Ez860g88wstyJaM/uHNOn8J1Hp32ahF7aPjWjTPhqap7D Fl9B+b/IvbS0EBpUbEqFVS4U2cNfOzxPnE+Z1tGBD4Vvow3kvyp7x7HAhIl874J5zI8j SeCVEx18RK+UJKLuSWQcMN7E09RaNA8il47DoEFNRVmtnNIHkv4CYJVwDtq09px7XXbZ rW/nv0LXIzMMFbh034BOospGbLe6+wqgxQ0PE0ofO7k08H7GVTeYLGQYK+AMFky6HGVZ NRCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3+gVLjfy9qEkLV7UUi0LogwR2bgWd+1yKGOrc4BKohY=; b=I7Vei+drzIj+38g0ODmwtU6JQaPJymLfAOOVYHHOmGASMS7mAxuGua8VvhwDBXnAHY hf7wXGzhhyPF991XF++ENi7RTIQCr3fpA/stXp9pK3DPZP0HbCY0AJKOmQbpuaStzxx7 fI7/zhz9nsz2QiG8Aul/t+b7cp2Q0RHVp13quvctZlpSevPqiLO7k0IJ8+pLZXKW3Kh3 FPNmk/6kkzMw+rQFS09KZNKthBDjxEJt9l9ro6xYMgyr2MaIIXFonMRKeM1TuqfIzVT1 ScXhegbnoDIi5VDL8C7dYC+Qr5E8CvGUFyfJ+C5HPlEA8D63lWrjGN31ejbwWTZoOT6d gtqg== X-Gm-Message-State: AKwxytc7Wa7rzicbbQ3Z6Rt3CVCUhSnvUJob19CTf9QLkbs2MU4mgwud TKsbwZ3sMOd+Ri/4c6tpZYU= X-Received: by 10.28.215.15 with SMTP id o15mr3569438wmg.70.1516224742608; Wed, 17 Jan 2018 13:32:22 -0800 (PST) Received: from localhost.localdomain ([41.40.205.38]) by smtp.gmail.com with ESMTPSA id 44sm7935004wrv.0.2018.01.17.13.32.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Jan 2018 13:32:21 -0800 (PST) From: Karim Eshapa To: ast@kernel.org Cc: daniel@iogearbox.net, ecree@solarflare.com, davem@davemloft.net, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Karim Eshapa Subject: [PATCH] kernel:bpf Remove structure passing and assignment to save stack and no coping structures Date: Wed, 17 Jan 2018 23:32:03 +0200 Message-Id: <1516224723-20195-1-git-send-email-karim.eshapa@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <20180114173102.smi6jiwqz66wf7av@ast-mbpfile> References: <20180114173102.smi6jiwqz66wf7av@ast-mbpfile> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org >On Sun, Jan 14, 2018 at 01:18:35PM +0200, Karim Eshapa wrote: >> >> Use pointers to structure as arguments to function instead of coping >> >> structures and less stack size. Also transfer TNUM(_v, _m) to >> >> tnum.h file to be used in differnet files for creating anonymous structures >> >> statically. >> >> >> >> Signed-off-by: Karim Eshapa >> ... >> >> +/* Statically tnum constant */ >> >> +#define TNUM(_v, _m) (struct tnum){.value = _v, .mask = _m} >> >> /* Represent a known constant as a tnum. */ >> >> struct tnum tnum_const(u64 value); >> >> /* A completely unknown value */ >> >> @@ -26,7 +28,7 @@ struct tnum tnum_lshift(struct tnum a, u8 shift); >> >> /* Shift a tnum right (by a fixed shift) */ >> >> struct tnum tnum_rshift(struct tnum a, u8 shift); >> >> /* Add two tnums, return @a + @b */ >> >> -struct tnum tnum_add(struct tnum a, struct tnum b); >> >> +void tnum_add(struct tnum *res, struct tnum *a, struct tnum *b); >> ... >> >> - reg_off = tnum_add(reg->var_off, tnum_const(ip_align + reg->off + off)); >> >> + tnum_add(®_off, ®->var_off, &TNUM(ip_align + reg->off + off, 0)); >> >> if (!tnum_is_aligned(reg_off, size)) { >> >> char tn_buf[48]; >> >> >> >> @@ -1023,8 +1023,7 @@ static int check_generic_ptr_alignment(struct bpf_verifier_env *env, >> >> /* Byte size accesses are always allowed. */ >> >> if (!strict || size == 1) >> >> return 0; >> >> - >> >> - reg_off = tnum_add(reg->var_off, tnum_const(reg->off + off)); >> >> + tnum_add(®_off, ®->var_off, &TNUM(reg->off + off, 0)); >> ... > >> - dst_reg->var_off = tnum_add(ptr_reg->var_off, off_reg->var_off); >> >> + tnum_add(&dst_reg->var_off, &ptr_reg->var_off, >> >> + &off_reg->var_off); >> >> >Is it gnu or intel style of argumnets ? where is src or dest ? >> >Can the same pointer be used as src and as dst ? etc, etc >> >I don't think it saves stack either. >> >I'd rather leave things as-is. >> >> It's not specific style but it's recommended when passing structure specially if >> the structures have large sizes. > and (dest, src0, src1) respectively.Although tnum structure isn't large but it saves >> stack,we have 2 structure passed before calling and 1 returned to receive the return value. >1. your patch has compile time warnings >2. it doesn't reduce stack size. > For two functions that use tnum_add: > adjust_ptr_min_max_vals() before and after has exactly the same. > check_ptr_alignment() after your patch _increased_ stack size. >3. text of verifier.o shrank 133 bytes while tnum.o increased 198 >Please do your homework next time. >tnum code will stay as-is. Thanks so much for your response,if there is any recommended tools to test how your patch affect memory, performance and what's going on because all accepted patches I sumbited was so trivial I'll be so appreciated. Karim,