Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1477113rwb; Tue, 27 Sep 2022 13:47:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4VdtTBNzsZ9OHlHGf1CPv4jjmvCozskLOXoECkz7sUQSynmSq30bykyt3Ts84SlwIfJEhR X-Received: by 2002:a17:906:8a4a:b0:781:70ab:e7cb with SMTP id gx10-20020a1709068a4a00b0078170abe7cbmr23660250ejc.492.1664311646438; Tue, 27 Sep 2022 13:47:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664311646; cv=none; d=google.com; s=arc-20160816; b=E65xyZs58WUqnNq4ftcjwCUinFzf0j7/mLO8VPFTmGCnBk0anrrz+6PYkU36ux915C MHwm8Bwo9OQQ+lS+BtoSi09i4VzL2H2DwbpDldTwMnjJ3hVdpbDhX7arj0Ku3vvz276A LOBlJZUacCodMZp8UNp920I1kQQvefz4gHOKL668lwa/mfSyANCoUEu81k3lgENbO4EP SJtF7UgAedPDT+ApoMvlAmeU4UNUoVmr6QbuzZeNJGpNdRF+TG2MUR1dcSoqJ5+7Q5t8 0yILLPaf2KrH6Y1lIROL0KJXmOkjQQHrO23aIxaupzDYv+3umRdPAO0elQ91eRrlixPa UjCw== 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=Dx5HDOePnyxgHzqa6DOD5MnqegsYWwrLtgMoZQ1P8dI=; b=ThUJtUYEQQ7WJhsBTnYsWAGKlWtdGFg+r9PXBCq9jOxAI0MdhFrtCzJW4nYC9Q9G0p wVqVGfGWcR02PKK3unXXOiiQh/d9imDSbuOQGVkCrzqPalQqlc7elIX1iiPHBV0VEk8W QA1VeRuVoF/tfdD+XFK8+YxDQBIMhte4IjZ93YfXIqFoLWstf+U8rN9Tq08EQYcvDwK+ FR8rOhicsnQmwWK86Yjl8n1PJ/hOG6VMZEom1Dn3zF9OYjDChkiF8/o9EN37D40bQr77 RR9iGfBor9PJ0o95CZxmbXXcHroLEcfYIdtEppZBM4UW01Yo6MQr/Hltk9rJtZRgFnmk m9Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=foQAH5na; 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 b18-20020a056402279200b0044e848a603bsi3035756ede.79.2022.09.27.13.47.01; Tue, 27 Sep 2022 13:47:26 -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=foQAH5na; 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 S232467AbiI0T72 (ORCPT + 99 others); Tue, 27 Sep 2022 15:59:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232200AbiI0T7N (ORCPT ); Tue, 27 Sep 2022 15:59:13 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B34A1C4829 for ; Tue, 27 Sep 2022 12:59:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664308750; 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=Dx5HDOePnyxgHzqa6DOD5MnqegsYWwrLtgMoZQ1P8dI=; b=foQAH5nakY7QGTs1zy17OITp0hzS+NleBEm/R7EPaMexNqiNMfVAyMl3oSnslTRyeZLDzR Mq9C+MILsXcbi53GcHgDGXVSJxA2jAHWDul+Bcc2h3m/wLlOBnpLsI0DYDX0Se3CEXMCPn i24kp/BImMOWZhc+6S2LhKA4BrxGuNU= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-348-4F8IJ_ixOq6nPyQm-EMgsQ-1; Tue, 27 Sep 2022 15:59:09 -0400 X-MC-Unique: 4F8IJ_ixOq6nPyQm-EMgsQ-1 Received: by mail-wm1-f71.google.com with SMTP id c2-20020a1c3502000000b003b535aacc0bso4266019wma.2 for ; Tue, 27 Sep 2022 12:59:09 -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=Dx5HDOePnyxgHzqa6DOD5MnqegsYWwrLtgMoZQ1P8dI=; b=vfjqLgL5b6M+jKuUsU7IaDS5buyf97lLAILgevwCEF+0HXZ2IuOlPZChdpVP/0XN2E pllqYMf286CqtQcvyQh20pbWGNcodFho1YdcZ7jTTpxDs4NR9YRRlL0fK8HOX3n6PJYp wm9g1iT0APnvv4MgAZRPvvv9IkKjTp+gfmB/jyzTE9DXtHjNYQfiUNhTA576BBlyWzVM 71UxpJbX12PgW8z753cWJkxDuHYeWgwXY3yTZ6J0pL0+av8zVs7f49GViRPHL9F+h7hR /BKkE5FzW1yDsCreKTqHh1i68jxioY10fTTDdehKLRUoU1yXJqpbI84eGPD2KUE8IcvT KWsA== X-Gm-Message-State: ACrzQf1TI+5o1KlWFXlj8RkBrMsckUa6nIbKywbWd5fB2WZEw6Pg9xYp I/RDotFhnIvsDpQIG8D1h2UVuJmLUzlYsF5J+jQ/uZKtDDSZ7NZrBAHP1TCnURuvCExgGB7vgVR qzonXwOe+gaCK2o/PxllXqkyH X-Received: by 2002:a05:6000:1a8a:b0:22a:33aa:a907 with SMTP id f10-20020a0560001a8a00b0022a33aaa907mr17893670wry.322.1664308748213; Tue, 27 Sep 2022 12:59:08 -0700 (PDT) X-Received: by 2002:a05:6000:1a8a:b0:22a:33aa:a907 with SMTP id f10-20020a0560001a8a00b0022a33aaa907mr17893654wry.322.1664308747882; Tue, 27 Sep 2022 12:59:07 -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 f12-20020a05600c4e8c00b003b33943ce5esm17310012wmq.32.2022.09.27.12.59.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 12:59:07 -0700 (PDT) Message-ID: <6502e1a45526f97a1e6d7d27bbe07e3bb3623de3.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 21:59:06 +0200 In-Reply-To: References: <7fef56880d40b9d83cc99317df9060c4e7cdf919.camel@redhat.com> <021d8ea4-891c-237d-686e-64cecc2cc842@gmail.com> <85cccb780608e830024fc82a8e4f703031646f4e.camel@redhat.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: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 19:48 +0100, Pavel Begunkov wrote: > On 9/27/22 18:56, Paolo Abeni wrote: > > 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? > > Interesting, I didn't think about struct_group, this would > let to split patches better and would limit non-core changes. > But if the plan is to convert the core helpers to > ubuf_info_common, than I think it's still messier than changing > ubuf providers only. > > I can do the exercise, but I don't really see what is the goal. > Let me ask this, if we forget for a second how diffs look, > do you care about which pair is going to be in the end? Uhm... I proposed this initially with the goal of remove non fuctional changes from a patch that was hard to digest for me (4/4). So it's about diffstat to me ;) On the flip side the change suggested would probably not be as straighforward as I would hope for. > ubuf_info_common/ubuf_info vs ubuf_info/ubuf_info_msgzc? The specific names used are not much relevant. > Are there you concerned about naming or is there more to it? I feel like this series is potentially dangerous, but I could not spot bugs into the code. I would have felt more relaxed eariler in the devel cycle. Cheers, Paolo