Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1416752pxb; Fri, 21 Jan 2022 18:12:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJxGCSt8YSZRGgP2g/FKi7tk10ZJ57a4KBxOyNo9ZFlz5EYmPKiuu2mj2igd9qWbAqI60KrW X-Received: by 2002:a17:902:b414:b0:142:431f:3d1c with SMTP id x20-20020a170902b41400b00142431f3d1cmr6200612plr.32.1642817534630; Fri, 21 Jan 2022 18:12:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1642817534; cv=pass; d=google.com; s=arc-20160816; b=O/DhH4qV4kRU3bYQ4S195fwSHPzzS6Xxpo6E0DdkEFIqBrbY4OQQYUdB9IWWkNne08 flvMWrK0+wU96YMnvZ/sPFSaM/Vp7a8utrmu029EWXhyzJES2k37WXhAa2cACl1EQNwI ytnvr5jQXWochkSMrdPaokTz6N2rDohXZVz2HIjhJVY+Htpsv11a79efTWzlC9FIbWVx eRHqrCIhQFoKBdipx4d+tAIJ7Q87iCyvjTQh/ASSdAWzlbZlYpfI00E+EF5Mkb8r768H w5r36jFeBdrGUT7xI7TO4IB8EiGy8pc+DPVrHDSsS5YsgskcI1MwSZy+kEJHAzFsYIPR dmGg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-id:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature; bh=b+7euje8ULiVl8STSV3Kq+UghuVegja/xePtS0HJlxY=; b=gabLsukHyJG9/crkgxzIyHl4+TuCGYhbom+Rz6uDLDFmUH5u60mhqRj+EBXH8bLouI 9orBqG/RrRp13b4P5tSMGCeZHX9wjtNFTAZwydfLClxySnSHfSHptZN9FkebPSsodU15 UkuRpJxyfUVL3DURYQOPy/HPnREraudLoFCzkEqfM6tGDUzcYwpgeyRu0RnV6ubTig19 vAgE/e81z29yHq6n++i2ewHexd6g5Y3x90aUbSXE164aFcb3pSajup9aKPJdlcct86JE 4vaRO/XwOduejM19FW86obKvMfIkx9NJPuVK2CBTwC7yJTnGPDGWwktpl8XeymincsFQ tisg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=E86DZRcE; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k14si8753692pfu.224.2022.01.21.18.12.02; Fri, 21 Jan 2022 18:12:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=E86DZRcE; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230205AbiAUS4p (ORCPT + 99 others); Fri, 21 Jan 2022 13:56:45 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:22422 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229453AbiAUS4n (ORCPT ); Fri, 21 Jan 2022 13:56:43 -0500 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.1.2/8.16.1.2) with ESMTP id 20LFtDrJ005971; Fri, 21 Jan 2022 10:56:43 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : mime-version; s=facebook; bh=b+7euje8ULiVl8STSV3Kq+UghuVegja/xePtS0HJlxY=; b=E86DZRcEEnvM8QDnfF2Hjhj8ft7Z+i/suyXh4mOsmUvbmQyF25S9lg9mbAIXVN3wTCXk Atrljbqb2SK/R+ekftnkuL1Kz0HkG6I9M2vW1QvLNG2HtJBFzaxu2rU5FXLY+2e6n8hQ DGFACluigHrj/94A1BWCpy5IWaNT9NpI8UI= Received: from mail.thefacebook.com ([163.114.132.120]) by m0001303.ppops.net (PPS) with ESMTPS id 3dqhy4n771-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Fri, 21 Jan 2022 10:56:42 -0800 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (100.104.98.9) by o365-in.thefacebook.com (100.104.94.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 21 Jan 2022 10:56:40 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EeFmRE4K6Q+pRkI2/27cuq2eImZ7NW5UHmNuvR4EKhy1dl+Vyn3hHWlqXf1U1rYUEWmAUFrxipMxILxRXKOWv6hDUuPPozve1PkB4jOX7p970k32Z4M+jQyK+qb3kVE1SZWPidHLY/e6sbh7pV+MaG9rSVofHy+kfhWNfx06F2nP6o3NVP6T+YqwJqQ10Hhl/xlnQdbnt/u5w46JqOAcOejn8c+htVdAAqoRokjFXqT4B18j2ro8U9ay+XTyWu7OMBBAkxYBC8hw0KC6oFfl03Vg17ZMEStEyQJHt1KmjYV51LrK7gVHXadTkJiYhLImXnxAwcpXSjjJts/ZonHVfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=b+7euje8ULiVl8STSV3Kq+UghuVegja/xePtS0HJlxY=; b=PicxMXGg0txFJYc5a6oD5TOOlcW5W62z0vsXCuCLmypBcg8w6Nyx7OrRjs1yugqKK0OV5H/2QXv3mYg5OpOVrWhyMiqP2IQhTGzy2NkK2KXbyj5Uf6lVy3qfC72pmrk/6CRLiM0fO0jF1nf5d8L1S+pQeUGwGdGS/osXLYlr06Mb7CaSFY1Z+qtymWdfR2Fb4eOTFineBTxMgYMht2vPYrFh0mRIDLP7Wr+KB3WvXL1oSF8dLRayQHaj6yQk5iiYEO7puhDW6znjvWK5p5CgT2xRA1SAVgWs67kH12eGR4LYS2t60MoFP3mmMliAzpyZxE9hcloppQVBnf/oNZkj3A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from SA1PR15MB5109.namprd15.prod.outlook.com (2603:10b6:806:1dc::10) by BN8PR15MB3329.namprd15.prod.outlook.com (2603:10b6:408:a5::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.12; Fri, 21 Jan 2022 18:56:39 +0000 Received: from SA1PR15MB5109.namprd15.prod.outlook.com ([fe80::1d7e:c02b:ebe1:bf5e]) by SA1PR15MB5109.namprd15.prod.outlook.com ([fe80::1d7e:c02b:ebe1:bf5e%7]) with mapi id 15.20.4909.012; Fri, 21 Jan 2022 18:56:39 +0000 From: Song Liu To: Alexei Starovoitov CC: Song Liu , bpf , Network Development , LKML , "Alexei Starovoitov" , Daniel Borkmann , "Andrii Nakryiko" , Kernel Team , "Peter Zijlstra" , X86 ML Subject: Re: [PATCH v5 bpf-next 7/7] bpf, x86_64: use bpf_prog_pack allocator Thread-Topic: [PATCH v5 bpf-next 7/7] bpf, x86_64: use bpf_prog_pack allocator Thread-Index: AQHYDjH7IlFLQbwkPUWXKcNPE2HSyKxs6t2AgADYTACAAAo4gIAAB3cA Date: Fri, 21 Jan 2022 18:56:39 +0000 Message-ID: References: <20220120191306.1801459-1-song@kernel.org> <20220120191306.1801459-8-song@kernel.org> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Apple Mail (2.3693.40.0.1.81) x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 7ed65530-8ee7-46cb-a0af-08d9dd0fc1b3 x-ms-traffictypediagnostic: BN8PR15MB3329:EE_ x-microsoft-antispam-prvs: x-fb-source: Internal x-ms-oob-tlc-oobclassifiers: OLM:8882; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: dMG6rc6fE0lcKVTmj2DJs9Yl3RozemyRiG3jsl3lrWbgE2YljvXIEGG+HnLuFd2jf2FFrIBBAv7AiYPke31TEFcK9v9zQphzdF4GDYmVb7S6CcMzRU2xdd4nUXrXjcWt8oAWTZEHVvfbExFcVzi2FP7m9u3M34p0nh6PKO2deOm3FShBcqNfCRCjH1RykLOMfhhPyXJDVoSMf9MBz0384EEZ/B7qemkkWhceTyBQk/LtOsZXEyNj2EBjCI6sUKIOjEOtTvzeenuL5B9WdcMoCFI/vjfIlvpvh4rA7lQaP3tD3F2FUXWP6IvQ+OPYd56j/YqnATDqM6Su0G4GtLIT3vX+nOZ5yDFX4n5nipQ19qDiYjR19Tt440pCklKyJ3R8ZD1zT+GjgvrnZOr7mc92KN9i0DuPXdnToP9YJkJ7OIfX87S3cxJxi2SVw98ZgyqwH4xCFeeRpLaaUIH/mYZugXFdVdEqr/93tjgfMkhTgSCXf5UAUQYSN/u7qKd2euXOGwHanwtLf3F3fgi0g6n5geoZ29wXeWdnKn+aJIsIsrqcpiIZpcl2YDQOVQ+cz4P2tCl2avVwzxfr0fu8UC2Xa42IociVRSLak2VLLSbJ151bT7a/TK90Po5BE5/QUu2neH9QB1vsfpFNrgKE91bhiuw+VksgY/ZPU2SRMODENsIPef5uAMKO1Wir768XG39tSImjhNg5M+4x4bJDSN2ilB3Ry9ldQxgtMrAu9prM/UuyHErCP6KheSCUrI85Om8P x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA1PR15MB5109.namprd15.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(316002)(33656002)(122000001)(76116006)(38100700002)(6512007)(186003)(7416002)(36756003)(71200400001)(86362001)(54906003)(53546011)(83380400001)(4326008)(5660300002)(38070700005)(2616005)(8936002)(66946007)(64756008)(8676002)(66446008)(66556008)(66476007)(2906002)(6506007)(508600001)(6486002)(6916009)(91956017)(45980500001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?Tmtd5pRAXuqe38YzRzHa4Uv44MeH858ZMl0NfxutxiUIKOlASTBLmj+shXkS?= =?us-ascii?Q?lwe/P+vUNu6O/5CnbIKY5ASLGrTmYc77jVKox5pk75ehlvKQHBm46mcIsQfU?= =?us-ascii?Q?Gw8844gHCyYOwUVHlPVapRlavo3zcB0iFZZsKGX+rJsHMYI7wVEi/denQ84y?= =?us-ascii?Q?ujkcs0vuhlE7dzNxpurUHuU88frNlqZa/bNiPtxvbjcfjTiaiBpQgferxtUY?= =?us-ascii?Q?M4mI2SP5rV/+AfWvNQoqQeTaPuWaBEPhqrN/9QYwtbbg6wJz5+FVatxqjw5L?= =?us-ascii?Q?7iYlqLygak3tSFtre15yHvqmJVjPwQY67IKgkZWp4TUWI+eZqLoSVxmxsxjc?= =?us-ascii?Q?rxAbjhyHQjgw/2GkH3Yg6tgCzDwVtVlBt5P/HGbE5M2T/pw+7Ul89dyxzqDT?= =?us-ascii?Q?E4f2sxUV5W/5YDQErGXC24GU03ArIgnkkdRWgdLCmgUVZQ8ncKBDdQ0BqFfe?= =?us-ascii?Q?Prma4qDm9qYR8kYESWO9CWQhHgACbZZQVWXBusJ0sTh531xnHlGnzOJJEL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ll65ubCP8IWufrWQxBNzNq4KfHNtyKSaQYNfw?= =?us-ascii?Q?H5wwWV58mbKb654fn9sYjXz1/1ZogPKmvssRMrjKDJYKMLjWapyWS10P9O31?= =?us-ascii?Q?ogWTC+fRWzf04t/hsBN2uRMs7TtTTa39mzWuqD+XYpaVAk6LcxrCNiDT6Zf2?= =?us-ascii?Q?mqI++pJxEY0NHBOAJJnFVun/bqgAof0byVvHPF1oMiTmflwIiX/OcPS7J/NN?= =?us-ascii?Q?Qu7+dcmwL9xHoCdUqQA14KVF/Em/7YZm/qe0YgF6HGA2LffhNRXe4blI17Bz?= =?us-ascii?Q?OAU7aw=3D=3D?= Content-Type: text/plain; charset="us-ascii" Content-ID: MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SA1PR15MB5109.namprd15.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7ed65530-8ee7-46cb-a0af-08d9dd0fc1b3 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Jan 2022 18:56:39.2408 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 6pxyMJuCnwvGqU1aA9Vzwfr8g699fDFv9yNomczWKpfsjj9iey6qdis4tC2ks8wKtwoyhuRGUPnLQ3k04FS91Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR15MB3329 X-OriginatorOrg: fb.com X-Proofpoint-ORIG-GUID: 2Zmm6rUg6QsdE6NDjrZ5Ys-77BZm3ugT X-Proofpoint-GUID: 2Zmm6rUg6QsdE6NDjrZ5Ys-77BZm3ugT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-21_09,2022-01-21_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=fb_outbound_notspam policy=fb_outbound score=0 impostorscore=0 spamscore=0 malwarescore=0 adultscore=0 clxscore=1015 mlxlogscore=751 bulkscore=0 phishscore=0 suspectscore=0 lowpriorityscore=0 mlxscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2201210123 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Jan 21, 2022, at 10:29 AM, Alexei Starovoitov wrote: > > On Fri, Jan 21, 2022 at 9:53 AM Song Liu wrote: >>> >>> the header->size could be just below 2MB. >>> I don't think kzalloc() can handle that. >> >> Technically, kzalloc can handle 2MB allocation via: >> kzalloc() => kmalloc() => kmalloc_large() => kmalloc_order() >> >> But this would fail when the memory is fragmented. I guess we should use >> kvmalloc() instead? > > Contiguous 2MB allocation? Yeah, I tried that both kzalloc() and kvmalloc() could get 2MB memory. I think kzalloc will fail when the memory is fragmented, but I haven't confirmed it yet. > >>> >>>> + if (!tmp_header) { >>>> + bpf_jit_binary_free_pack(header); >>>> + header = NULL; >>>> + prog = orig_prog; >>>> + goto out_addrs; >>>> + } >>>> + tmp_header->size = header->size; >>>> + tmp_image = (void *)tmp_header + ((void *)image - (void *)header); >>> >>> Why is 'tmp_image' needed at all? >>> The above math can be done where necessary. >> >> We pass both image and tmp_image to do_jit(), as it needs both of them. >> I think maintaining a tmp_image variable makes the logic cleaner. We can >> remove it from x64_jit_data, I guess. > > I'd remove from x64_jit_data. The recompute is cheap. Will do. > > Speaking of tmp_header name... would be great to come up > with something more descriptive. > Here both tmp_header/tmp_image and header/image are used at the same time. > My initial confusion with the patch was due to the name 'tmp'. > The "tmp" prefix implies that the tmp_image will be used first > and then it will become an image. > But it's not the case. > Maybe call it 'rw_header' and add a comment that 'header/image' > are not writeable directly ? > Or call it 'poke_header' ? > Other ideas? I think rw_header/rw_image is good. poke_header is confusing, as we will text_poke "header". Thanks, Song