Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1321380rwb; Tue, 27 Sep 2022 11:17:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6BraJIlLPnl5TiK33hQelxqaOcmlBh9t0rauCRGRc7bAhdgAGlBkoDa0tYe2lWrC6dNGqp X-Received: by 2002:a63:5c07:0:b0:43f:6af:7590 with SMTP id q7-20020a635c07000000b0043f06af7590mr3266307pgb.272.1664302656772; Tue, 27 Sep 2022 11:17:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664302656; cv=none; d=google.com; s=arc-20160816; b=gw+Cd/Ja+oCOc9ovmnBegsxe8Bce/W0UDoNLN51Q64qto72nRwl5p/SAVRR1Xgn1kp iV0pW79Ewyl7iPsN9tJHJpmbP8i9QJuQjMHXY/Qy5uwJqcxL21++Fulm9fJksrSSrgWj ceqeRQ9YZMO5zgcgJNNiKPWesveEUQh8QNpfWD8MsrwO44S+QoVzYcy6PDqdET0R9Dns H/otBeEU5dMZcQBB0gboKIILhJ/Kfa3/ORaIzjcOZgVGovq4BHt8/SwS0HuKpXat/ql0 FYodv2n6RGaYThweUTyFPx586PIz95YJmSR/kPK+wuDyjV8dm4cnDjj8DpOPMiVrx6NF 1fuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=ylam0E0Yl8o7oIuCiSoTBfRDDfyFUS+FtVqqi8D5J/k=; b=NoAySSH1WLgCwOlpQVZJI2IlatWQEk3jItbyWuD2gKIrNpY0o2FA6qPLCysAQ12Kca IzzicTGzukpjOqYb7uDq4WsIeyhsCPkb5Xr7FQegtMQrxFycSQEJluBV767XGT0GZMBJ 7zGyQ//L5VKt6d3esyaEy5PqR16PNlCuZbWgY4dOK1slzT7E5Ysc9g3fWRaDiyQL1EoR IjEIX2GisvoENfmbS9TPaNF9DKYC0EiTn8Fdo7FR2o0fdhVZZf/4wmhgfyIxIA1D5uyw K/xzhgMIYLNtbQVMHjGMigU2B7hHxO1wesP6lxy3JHO30+9JmPbJYoPWstO/TfEWOxaq lX3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=C0MOHD62; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nu9-20020a17090b1b0900b00202acc2169csi4448905pjb.118.2022.09.27.11.17.23; Tue, 27 Sep 2022 11:17:36 -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=@redhat.com header.s=mimecast20190719 header.b=C0MOHD62; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232428AbiI0R4a (ORCPT + 99 others); Tue, 27 Sep 2022 13:56:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233083AbiI0R4P (ORCPT ); Tue, 27 Sep 2022 13:56:15 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BBD6ABD62 for ; Tue, 27 Sep 2022 10:56:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664301368; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ylam0E0Yl8o7oIuCiSoTBfRDDfyFUS+FtVqqi8D5J/k=; b=C0MOHD62umI44M+FuCUIUujaCYv+tZZpHZTmPvmBD0Kh5RNnX5DeCg6YILNOC6+Xr/mxtv O7ZFFafdS3mgkuPm7JDj6DXv1vrrb2zLHSeEUAYFaNyv9A4gI1Qfog7sp3VGyHcpCVE+0l Uq16NKKe3ypuL1fYQtoWuN3H5pdc27U= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-29-qyrbkl68NSiylmTGCJWKwg-1; Tue, 27 Sep 2022 13:56:07 -0400 X-MC-Unique: qyrbkl68NSiylmTGCJWKwg-1 Received: by mail-wm1-f72.google.com with SMTP id f25-20020a7bc8d9000000b003b4768dcd9cso3022631wml.9 for ; Tue, 27 Sep 2022 10:56:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date; bh=ylam0E0Yl8o7oIuCiSoTBfRDDfyFUS+FtVqqi8D5J/k=; b=nevtLgOk6MA/12qFysmgSzERGCXHXoop9M1Ae5fjsVjvk4Kw7BsT1ZApnlazTBTCJL 10koLXDY2S6unbc6Sojl24UGtv37QHqrm0Lowx+MD2DsVvqZoa2umYA4PhC2nc41Epu3 4SC9k9bHF+/Eph7lGXQNY66QTRb9SGgvTQ8/bLT7UDJcLW2almJ7PiXHvnIu4nw6aWkq 8q0v/RNhtBhzCTI7XcpMC8sQ+O71gNOroaSYPf/vFTSoQi66/7A2t6sLHXUn8GNqErHO zGqq5pKdBpImS3kgO4Ryx35GWHsj9ozx+LJt7kOyrX0ANWZq0lQ+i03PwXZkL2i/corY rtdg== X-Gm-Message-State: ACrzQf1sMBJIJurXqFDLsnuQXFnNWle65tOj3LEZ9CWxduupFFq7amCl n2ccZ8G1iBfhNKUnyF0B9AIVGCkzy/mWJyT3sQY8x29mdQ3FyhrR7IT5nhH9/TtRZAiWDRgQrL0 vTA2RYRpoQ+SJOM9PVqJJgMX+ X-Received: by 2002:a05:600c:1906:b0:3b4:c979:e639 with SMTP id j6-20020a05600c190600b003b4c979e639mr3579333wmq.10.1664301366030; Tue, 27 Sep 2022 10:56:06 -0700 (PDT) X-Received: by 2002:a05:600c:1906:b0:3b4:c979:e639 with SMTP id j6-20020a05600c190600b003b4c979e639mr3579316wmq.10.1664301365775; Tue, 27 Sep 2022 10:56:05 -0700 (PDT) Received: from gerbillo.redhat.com (146-241-104-40.dyn.eolo.it. [146.241.104.40]) by smtp.gmail.com with ESMTPSA id i24-20020a1c5418000000b003a601a1c2f7sm15224452wmb.19.2022.09.27.10.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 10:56:05 -0700 (PDT) Message-ID: <85cccb780608e830024fc82a8e4f703031646f4e.camel@redhat.com> Subject: Re: [PATCH net-next 0/4] shrink struct ubuf_info From: Paolo Abeni To: Pavel Begunkov , netdev@vger.kernel.org Cc: "David S . Miller" , Jakub Kicinski , linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, Wei Liu , Paul Durrant , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, "Michael S . Tsirkin" , Jason Wang Date: Tue, 27 Sep 2022 19:56:04 +0200 In-Reply-To: References: <7fef56880d40b9d83cc99317df9060c4e7cdf919.camel@redhat.com> <021d8ea4-891c-237d-686e-64cecc2cc842@gmail.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE 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 Tue, 2022-09-27 at 18:16 +0100, Pavel Begunkov wrote: > On 9/27/22 15:28, Pavel Begunkov wrote: > > Hello Paolo, > > > > On 9/27/22 14:49, Paolo Abeni wrote: > > > Hello, > > > > > > On Fri, 2022-09-23 at 17:39 +0100, Pavel Begunkov wrote: > > > > struct ubuf_info is large but not all fields are needed for all > > > > cases. We have limited space in io_uring for it and large ubuf_info > > > > prevents some struct embedding, even though we use only a subset > > > > of the fields. It's also not very clean trying to use this typeless > > > > extra space. > > > > > > > > Shrink struct ubuf_info to only necessary fields used in generic paths, > > > > namely ->callback, ->refcnt and ->flags, which take only 16 bytes. And > > > > make MSG_ZEROCOPY and some other users to embed it into a larger struct > > > > ubuf_info_msgzc mimicking the former ubuf_info. > > > > > > > > Note, xen/vhost may also have some cleaning on top by creating > > > > new structs containing ubuf_info but with proper types. > > > > > > That sounds a bit scaring to me. If I read correctly, every uarg user > > > should check 'uarg->callback == msg_zerocopy_callback' before accessing > > > any 'extend' fields. > > > > Providers of ubuf_info access those fields via callbacks and so already > > know the actual structure used. The net core, on the opposite, should > > keep it encapsulated and not touch them at all. > > > > The series lists all places where we use extended fields just on the > > merit of stripping the structure of those fields and successfully > > building it. The only user in net/ipv{4,6}/* is MSG_ZEROCOPY, which > > again uses callbacks. > > > > Sounds like the right direction for me. There is a couple of > > places where it might get type safer, i.e. adding types instead > > of void* in for struct tun_msg_ctl and getting rid of one macro > > hiding types in xen. But seems more like TODO for later. > > > > > AFAICS the current code sometimes don't do the > > > explicit test because the condition is somewhat implied, which in turn > > > is quite hard to track. > > > > > > clearing uarg->zerocopy for the 'wrong' uarg was armless and undetected > > > before this series, and after will trigger an oops.. > > > > And now we don't have this field at all to access, considering that > > nobody blindly casts it. > > > > > There is some noise due to uarg -> uarg_zc renaming which make the > > > series harder to review. Have you considered instead keeping the old > > > name and introducing a smaller 'struct ubuf_info_common'? the overall > > > code should be mostly the same, but it will avoid the above mentioned > > > noise. > > > > I don't think there will be less noise this way, but let me try > > and see if I can get rid of some churn. > > It doesn't look any better for me > > TL;DR; This series converts only 3 users: tap, xen and MSG_ZEROCOPY > and doesn't touch core code. If we do ubuf_info_common though I'd need > to convert lots of places in skbuff.c and multiple places across > tcp/udp, which is much worse.  Uhmm... I underlook the fact we must preserve the current accessors for the common fields. I guess something like the following could do (completely untested, hopefully should illustrate the idea): struct ubuf_info { struct_group_tagged(ubuf_info_common, common, void (*callback)(struct sk_buff *, struct ubuf_info *, bool zerocopy_success); refcount_t refcnt; u8 flags; ); union { struct { unsigned long desc; void *ctx; }; struct { u32 id; u16 len; u16 zerocopy:1; u32 bytelen; }; }; struct mmpin { struct user_struct *user; unsigned int num_pg; } mmp; }; Then you should be able to: - access ubuf_info->callback,  - access the same field via ubuf_info->common.callback - declare variables as 'struct ubuf_info_commom' with appropriate contents. WDYT? Thanks, Paolo