Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2519468rwl; Thu, 6 Apr 2023 11:20:30 -0700 (PDT) X-Google-Smtp-Source: AKy350axIQ5QUkX8hyH48r5v01Pes73DNyD1Bd9Px/YJvwFQqhKRqFaxq1N1f+iKhzi0ptZfHj02 X-Received: by 2002:a05:6a20:6690:b0:d9:e45d:95da with SMTP id o16-20020a056a20669000b000d9e45d95damr354736pzh.20.1680805230260; Thu, 06 Apr 2023 11:20:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680805230; cv=none; d=google.com; s=arc-20160816; b=KYkfnB5SntHxb8GR/fzNaKkl+BO0NrG2sUn0FMfNbxEMKKKCc6U/fC8WVE1GQ/VcJ/ tIaCNYNn7T5vBfiLr8vnvaGv4d+nShj4qYshfqkieVzVXrgJ8tWmg61RDHvoDSZKI8yM hOaW8YRKwPdZh5vlmT/wgaBPulCIotRg3M+GJ7nEDKSGfyxrgaz3TYl06/vU3eYzSAiO JCjwllQlu3AbLjRHNCYc32jdthOR+lFpK79lVGe37rVeED0uwwGlaEqDCsoQyJbYia2G d99AEc4otMadNe4bLl9co8nncr4zaw0aJvYzGdOlatF9RBIbChZXNCeYQH4hmQC22iMa pDdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=h70PraPH5+GMWozAhM7JaPVH30CeiE+sjPLouQsdB7g=; b=kR11kCQ1ArLUJyIwlhpeLsHXyaV7HnfWFPZO33Teh7VQ/2/MpD6pVPiwOdQYjOkQeE AtlGtqtSP38GJW+lxxNBwhl8E994PfvIgZjUzg16pCoUJiz3tUACSoolA81K7PWAf0lo LlCj5Eai0ZE3x9rZq8Z1DxBYHHmZzKNPWyOPcomh1/a8tJ3vGSEbrE9l2rG3yGAd3E52 TmSjVY0DTYcLSurkfUHVFIZN8KaC5iBZYaFhX2ew4vzmJwPVTEND9oky28q+iO/gY79J ztOQOOz7SBfYS7cFyv2+vIcqEcAXlRhNTmtvHmWh+6+W0GME2YVjmdC+8/W8L8dBtNwj ulEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=sV0bNyy9; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 185-20020a6206c2000000b00627f017391csi1788447pfg.273.2023.04.06.11.20.17; Thu, 06 Apr 2023 11:20:30 -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=@google.com header.s=20210112 header.b=sV0bNyy9; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240059AbjDFSRI (ORCPT + 99 others); Thu, 6 Apr 2023 14:17:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229764AbjDFSRG (ORCPT ); Thu, 6 Apr 2023 14:17:06 -0400 Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FABFB0 for ; Thu, 6 Apr 2023 11:17:05 -0700 (PDT) Received: by mail-il1-x130.google.com with SMTP id e9e14a558f8ab-322fc56a20eso397515ab.0 for ; Thu, 06 Apr 2023 11:17:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680805024; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=h70PraPH5+GMWozAhM7JaPVH30CeiE+sjPLouQsdB7g=; b=sV0bNyy9DUoGVmnnZYp++9XpnHtdFFdBIfUu98tiebaRLFSkMDjqsbZX5u2udu69+Y NWdL2QKNoj40V0Xpai63YRAE2NFq4G0ApvL0Seq8uOnnpjOIY98m5/FJ+jA7YQUsLw2T bzb6HqEUDO1i0XQgWyH2SFNkZT6MQ2EpnWsommuVxAol7APb1dh3X74x5lR/fgRFt4ME 79KCT3E0JCzB+cinRi4Qww3f1lTq1vV9bb4Z30q6vx0LkuvbZ0QHlv+I7rGhWyShLhya OsM+H88PXCY3o5lUcgSuRGNaDR3mIesOqI117sq4d0NwSFNMRoApUNatSKDXEi4dqi11 OyCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680805024; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=h70PraPH5+GMWozAhM7JaPVH30CeiE+sjPLouQsdB7g=; b=ShHjdwZuHKMh6r8iq+/eOpthG/Nn5msfuT1lU4+eUGLJUlBDWrou+mJVOr1kR2T+va azqL3Y53mSi6qZImOi/btdG4QVHNAtPcR3QdoqzsGlWDwhcTGcx4J97QLt7+Is0KFFpc x65mRHuByK5mPXNPApU++BGXEN6zvR9EKjY0wbgDWKNMz3dqG9lZyobVaxepcRGsx6jM zExd3kpxA6Fa1cxeWqJMXOImU4DOVkFWue9P9gCTa7pQhmiWt0CA/pxje7vIsDvVndo3 HTGcu1Mp0xorrwskIKFCOn3fGlA+7eo/Vv78Q5msWIuIIt4y0GzD3sAItd3XwDg72D+9 K1Ew== X-Gm-Message-State: AAQBX9dIMDYxVNRQ1KCwVahmG6mnnzGO02XPa+p+fgfCPTVhfJ3esTse w2bE/uZdobhicVx3wbRMA8TqiEAC6gVTAn5OftH5pg== X-Received: by 2002:a05:6e02:1e0a:b0:326:55d0:efad with SMTP id g10-20020a056e021e0a00b0032655d0efadmr20905ila.12.1680805024290; Thu, 06 Apr 2023 11:17:04 -0700 (PDT) MIME-Version: 1.0 References: <20230406144330.1932798-1-leitao@debian.org> In-Reply-To: From: Willem de Bruijn Date: Thu, 6 Apr 2023 14:16:24 -0400 Message-ID: Subject: Re: [PATCH 0/5] add initial io_uring_cmd support for sockets To: Breno Leitao Cc: io-uring@vger.kernel.org, netdev@vger.kernel.org, kuba@kernel.org, asml.silence@gmail.com, axboe@kernel.dk, leit@fb.com, edumazet@google.com, pabeni@redhat.com, davem@davemloft.net, dccp@vger.kernel.org, mptcp@lists.linux.dev, linux-kernel@vger.kernel.org, dsahern@kernel.org, willemdebruijn.kernel@gmail.com, matthieu.baerts@tessares.net, marcelo.leitner@gmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-15.7 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,ENV_AND_HDR_SPF_MATCH, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=unavailable 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 Thu, Apr 6, 2023 at 11:59=E2=80=AFAM Breno Leitao wr= ote: > > On Thu, Apr 06, 2023 at 11:34:28AM -0400, Willem de Bruijn wrote: > > On Thu, Apr 6, 2023 at 10:45=E2=80=AFAM Breno Leitao wrote: > > > > > > From: Breno Leitao > > > > > > This patchset creates the initial plumbing for a io_uring command for > > > sockets. > > > > > > For now, create two uring commands for sockets, SOCKET_URING_OP_SIOCO= UTQ > > > and SOCKET_URING_OP_SIOCINQ. They are similar to ioctl operations > > > SIOCOUTQ and SIOCINQ. In fact, the code on the protocol side itself i= s > > > heavily based on the ioctl operations. > > > > This duplicates all the existing ioctl logic of each protocol. > > > > Can this just call the existing proto_ops.ioctl internally and translat= e from/to > > io_uring format as needed? > > This is doable, and we have two options in this case: > > 1) Create a ioctl core function that does not call `put_user()`, and > call it from both the `udp_ioctl` and `udp_uring_cmd`, doing the proper > translations. Something as: > > int udp_ioctl_core(struct sock *sk, int cmd, unsigned long arg) > { > int amount; > switch (cmd) { > case SIOCOUTQ: { > amount =3D sk_wmem_alloc_get(sk); > break; > } > case SIOCINQ: { > amount =3D max_t(int, 0, first_packet_length(sk))= ; > break; > } > default: > return -ENOIOCTLCMD; > } > return amount; > } > > int udp_ioctl(struct sock *sk, int cmd, unsigned long arg) > { > int amount =3D udp_ioctl_core(sk, cmd, arg); > > return put_user(amount, (int __user *)arg); > } > EXPORT_SYMBOL(udp_ioctl); > > > 2) Create a function for each "case entry". This seems a bit silly for > UDP, but it makes more sense for other protocols. The code will look > something like: > > int udp_ioctl(struct sock *sk, int cmd, unsigned long arg) > { > switch (cmd) { > case SIOCOUTQ: > { > int amount =3D udp_ioctl_siocoutq(); > return put_user(amount, (int __user *)arg); > } > ... > } > > What is the best approach? A, the issue is that sock->ops->ioctl directly call put_user. I was thinking just having sock_uring_cmd call sock->ops->ioctl, like sock_do_ioctl. But that would require those callbacks to return a negative error or positive integer, rather than calling put_user. And then move the put_user to sock_do_ioctl. Such a change is at least as much code change as your series. Though without the ending up with code duplication. It also works only if all ioctls only put_user of integer size. That's true for TCP, UDP and RAW, but not sure if true more broadly. Another approach may be to pass another argument to the ioctl callbacks, whether to call put_user or return the integer and let the caller take care of the output to user. This could possibly be embedded in the a high-order bit of the cmd, so that it fails on ioctl callbacks that do not support this mode. Of the two approaches you suggest, I find the first preferable.