Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1477648rwb; Tue, 27 Sep 2022 13:48:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7ESM2eem/l/Ym2SjTPr/kGbij474kWyskZr1omDie2tEDf1WCj7QbFUxQOlABQtq92URWM X-Received: by 2002:a17:907:2e02:b0:77b:bdab:674b with SMTP id ig2-20020a1709072e0200b0077bbdab674bmr24623506ejc.159.1664311685470; Tue, 27 Sep 2022 13:48:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664311685; cv=none; d=google.com; s=arc-20160816; b=C71XutEa/1KT2fnLBFTEQ3598FFTGs604BZsv7K3wv+S4pkrgSemFaysXSYK5LzukO 7BBjykV1L2+NVq6s3UGBOLTBI5W7EcrLqCvhVrHI8iP0RZ42cmF9v91pyM3SJjTSpTaG Qak4R1AdBQR0y8OUsxVhryUQuDXZoPTUMTNPoNLvZrlANjDcujToPHn5EardX9JwT4/g iefWV/RAxERRpb6eudSFET4RLz1AbRNuS8EZDqzhPAbMYecprY/ejhV5H3xJAteC/fzY SBSdeN+tKh3cgvSTPV6qSpaw539MEE29akW2dmcSSZZgbuD8xdiMzCwe5okekwkAVy0g y/aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=VYiQC0+hw/YN0HXUIX2ZHIj06ZGTMESETEb91ek6mio=; b=hhoCOl9kauxJXc0f2DJ+IG45Pw24uPuwvubR69OKpk8ewBppawTWJlFR3z0gaZibaR w4DrI32ejbXvq4P6KMCi3dVHsmjqcVYxF473NWDRAYsGkNRtNaPC2lRwHSGyCIFNZ58g cJS2uVwmCdiXuoyk5qtG7sgbhzvwP2SOz0DjVnikj73+U7HdurGijpnKegvElrf92g84 +b4wsDcwlCiWPysbHqcwNn0zeodcxtiON0jfb2NCA4o/iBvezveisx0U+5yBChwkEsQO 6+q/tx43d9UBbs4NUkY1PorLUEZJV6T3EYlOL0pQ5BRB6XjK/+xE8gUFFiWBO7EZaRgA Bhdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=b+d1TFFX; 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 d11-20020a50c88b000000b004575571fbc6si2406382edh.321.2022.09.27.13.47.38; Tue, 27 Sep 2022 13:48:05 -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=20210112 header.b=b+d1TFFX; 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 S233083AbiI0UT1 (ORCPT + 99 others); Tue, 27 Sep 2022 16:19:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233226AbiI0USz (ORCPT ); Tue, 27 Sep 2022 16:18:55 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F919F7B; Tue, 27 Sep 2022 13:18:54 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id cc5so16680255wrb.6; Tue, 27 Sep 2022 13:18:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date; bh=VYiQC0+hw/YN0HXUIX2ZHIj06ZGTMESETEb91ek6mio=; b=b+d1TFFX1HXrnCaj7FfV0JH6lWEvDi7u3jNGbto0NjhdTpD6ERgE7IZlMeUVVKagS3 tAsXx4Z6ZmRtpNFpwpxDVJPUF7h5h/m+dvjMfh69N0kHhjdsGOlPbcdGFjPe3dIamT8v q7TwybO/csHrDvvde2hc5jWTaSOMBDxPgCFs4rJEcVW2Wza3nWPY1r7D8Q6xQaRVfGVO x6hQERoCR+sQon+7K602PQLtOTJI4fdHVnOIBlQyCQKkl8kKxYNVRzBpgHiZR8VozqwO dhDUyaw7//V8D4F1HfY5TRpbllYVg9mn6ql2NwHov4/vATDDt8Oa8QIsfUomFfI1owfC 8IZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=VYiQC0+hw/YN0HXUIX2ZHIj06ZGTMESETEb91ek6mio=; b=vA5/uerW8DcNZj2140wQdU7YkI1DiN8+lAktK2KMIzxHAObcUVm4129GxoKNR+zc+m StbsmDuLrGkS9thd39vt6V/XgBZxBo5CjVdcQm0OVCKkjC2Q/JMRv6mXON3+M/9QEUhT dHQaLxQUWlf7VXSt2ezvDZw1K8EPqVNmtqVVhIJL9tFKEtuFFMV9es1eqbL4+1+vEd5A FOVO1fQqENDuzcnWj8yB0nNrF7kC8fxMlFHoHXO94WcxvsMSqLgutJ1TY7y4Y+qVqOaJ 2sjkjrYPnocPXjEAeJgQl+sws+KlD76OezKxR6x2vl3lsF5kYxiSCI04lK0IWbT1X++h XQGw== X-Gm-Message-State: ACrzQf3R8XB2BauifgRn+gKmHI79HABv9+qWwTohsA5sYlFBo50Cg0wX Xk8lyl3ITH04BqNNG43nyeI= X-Received: by 2002:a05:6000:186e:b0:22a:e3b1:9c7d with SMTP id d14-20020a056000186e00b0022ae3b19c7dmr19019256wri.113.1664309932648; Tue, 27 Sep 2022 13:18:52 -0700 (PDT) Received: from [192.168.8.100] (94.196.228.157.threembb.co.uk. [94.196.228.157]) by smtp.gmail.com with ESMTPSA id h6-20020a05600c2ca600b003b4c40378casm15913221wmc.39.2022.09.27.13.18.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 27 Sep 2022 13:18:52 -0700 (PDT) Message-ID: Date: Tue, 27 Sep 2022 21:17:26 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH net-next 0/4] shrink struct ubuf_info Content-Language: en-US To: Paolo Abeni , 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 References: <7fef56880d40b9d83cc99317df9060c4e7cdf919.camel@redhat.com> <021d8ea4-891c-237d-686e-64cecc2cc842@gmail.com> <85cccb780608e830024fc82a8e4f703031646f4e.camel@redhat.com> <6502e1a45526f97a1e6d7d27bbe07e3bb3623de3.camel@redhat.com> From: Pavel Begunkov In-Reply-To: <6502e1a45526f97a1e6d7d27bbe07e3bb3623de3.camel@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 9/27/22 20:59, Paolo Abeni wrote: > 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 ;) Ah, got it > 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. union { struct { unsigned long desc; void *ctx; }; struct { u32 id; u16 len; u16 zerocopy:1; u32 bytelen; }; }; btw, nobody would frivolously change ->zerocopy anyway as it's in a union. Even without the series we're absolutely screwed if someone does that. If anything it adds a way to get rid of it: 1) Make vhost and xen use their own structures with right types. 2) kill unused struct {ctx, desc} for MSG_ZEROCOPY -- Pavel Begunkov