Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp331679rdb; Sat, 19 Aug 2023 03:48:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFF/B4CJKzlvlissfbvBkTT5wz4ncFKt8hyV5IGUuccpYXVX9BgaoXJgDXObG+AKljG94Mt X-Received: by 2002:a05:6a20:6a05:b0:136:f3ef:4d2 with SMTP id p5-20020a056a206a0500b00136f3ef04d2mr2355389pzk.3.1692442107628; Sat, 19 Aug 2023 03:48:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692442107; cv=none; d=google.com; s=arc-20160816; b=RmBHyXyN/K/D3MJpE0u6leuAIR3LG9YHMRuIcGy3HMrOy1Q2yAZPn2BNciwH1iDVhy hWoLE3XLNdqgEQ0gHiJ3F2DzxBcTmkE5d3D7uQtwKWvfN+D1t2XhZCSc91Khf3aEj91C O0J/Tqh9LM9wEghjaZFLn0ZPbV2/psJ/9jGCZ3OP1DPIyq4HIy5f2vNt6oSvy9lEHz82 1DmMhmu+hPnZQqAeoXFI1SYhyGeRjCTt1YnSYjPDmDAkUiGpxeMxSMQo6kRKwv9dpG+a iO25ZGNq6SQIwIo1DixsO1iDMwuvOSTAQ0ZUy1V0HyUiNXNBy45EKEpcO9WlbCpWAiHp jZkQ== 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 :message-id:date:subject:cc:to:from; bh=3SQ2mdlJ/zc4OpHFZ3If0GuAfTpQpt1yP+BpEHXI8MY=; fh=9AWIeT3iRePFFiWaUks3e8UIAu0DVI8evaQ1LtP9zWM=; b=DQ9JfIRvayVCCFgJ5h5Gomu0/wXSimxabaVUSD9g9t7+9ntY1YQ7v1vibiHShWr5+m MOul/mLruPJe1MoXtE5YDy0k4djD+AFx5/Y9Px3fDAWjNsX3Acl+rH4StTwcV5XWwMRO B86je9LAxTZj/PNKYyvwoM7MWE8FrU19NDSDqgyDKLbmdFxlLVnF6hBTvHh5K2vHzXu5 Q+il6gCGnQlzSz2XGibRA20bGrHRYfUuW9/S50GlSiD5YLdcjPjgM/nq+QiiGCuCmJaY THGSUmFGlyl8srhNTc3zCdFdJR9pM1C7iYiKToZB5I64RP0EedXFYt6mSKzMXK/PrEbX Y/0w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id a18-20020a631a52000000b0056711d044e5si3277903pgm.492.2023.08.19.03.48.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 03:48:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B170453B53; Sat, 19 Aug 2023 01:32:12 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352397AbjHQO42 (ORCPT + 99 others); Thu, 17 Aug 2023 10:56:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352491AbjHQO4Y (ORCPT ); Thu, 17 Aug 2023 10:56:24 -0400 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F193D3592; Thu, 17 Aug 2023 07:56:08 -0700 (PDT) Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-99bf8e5ab39so1048319566b.2; Thu, 17 Aug 2023 07:56:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692284167; x=1692888967; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3SQ2mdlJ/zc4OpHFZ3If0GuAfTpQpt1yP+BpEHXI8MY=; b=AQq0iF2VMg5/I+Ak/DZq/HpMby7RwpupgIzDtnSz2UmJi+wON31Wa5fgSUUuTRjeMQ JQY4qHUdHsqNJxzohrDDqsMV31y7esVT200mpYTZ/JN/QiMnKfDKlGyDHkmQBTFleGwD FG8ZlpEKhm/mxupcoEGhjQNRKdX2A8PPnsErGkAGyDld526cZk+Ns/tALVu6Mw4ReiMm q1rJQpCYhi5t8YSQ035lL3/FrOUWwUkByjkGk2y/E3nXgbFIcF09k/ChwIeT7JetuXv3 Uq85XfcMNUlzhDAKNbZoDC/AcQSNoXr+oNBgSB6Mp2ZMQuoPDjI2Sx6AZMQiZSo1gPfT Ny/g== X-Gm-Message-State: AOJu0Yy1wT4KiD9gbsrh0cJzMUsj4qlCJcg+up+Dfuv0p6tHUfSiR/Wj a0crVO9ikcnDqHes7IFInmI= X-Received: by 2002:a17:907:784b:b0:988:9b29:5653 with SMTP id lb11-20020a170907784b00b009889b295653mr3565597ejc.77.1692284167180; Thu, 17 Aug 2023 07:56:07 -0700 (PDT) Received: from localhost (fwdproxy-cln-020.fbsv.net. [2a03:2880:31ff:14::face:b00c]) by smtp.gmail.com with ESMTPSA id b21-20020a170906195500b0099df2ddfc37sm2433123eje.165.2023.08.17.07.56.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Aug 2023 07:56:06 -0700 (PDT) From: Breno Leitao To: sdf@google.com, axboe@kernel.dk, asml.silence@gmail.com, willemdebruijn.kernel@gmail.com, martin.lau@linux.dev Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, io-uring@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com, krisman@suse.de Subject: [PATCH v3 0/9] io_uring: Initial support for {s,g}etsockopt commands Date: Thu, 17 Aug 2023 07:55:45 -0700 Message-Id: <20230817145554.892543-1-leitao@debian.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no 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 This patchset adds support for getsockopt (SOCKET_URING_OP_GETSOCKOPT) and setsockopt (SOCKET_URING_OP_SETSOCKOPT) in io_uring commands. SOCKET_URING_OP_SETSOCKOPT implements generic case, covering all levels and optnames. SOCKET_URING_OP_GETSOCKOPT is limited, for now, to SOL_SOCKET level, which seems to be the most common level parameter for get/setsockopt(2). In order to keep the implementation (and tests) simple, some refactors were done prior to the changes, as follows: Patches 1-2: Modify the BPF hooks to support sockptr_t, so, these functions become flexible enough to accept user or kernel pointers for optval/optlen. Patch 3: Extract the core setsockopt() core function from __sys_setsockopt, so, the code code could be reused by other callers, such as io_uring. Patch 4: Pass compat mode to the file/socket callbacks. Patch 5: Move io_uring helpers from io_uring_zerocopy_tx to a generic io_uring headers. This simplify the testcase (last patch) PS1: For getsockopt command, the optlen field is not a userspace pointers, but an absolute value, so this is slightly different from getsockopt(2) behaviour. The new optlen value is returned in cqe->res. PS2: The userspace pointers need to be alive until the operation is completed. These changes were tested with a new test[1] in liburing, as also with bpf/progs/sockopt test case, which is now adapted to run using both system calls and io_uring commands. [1] Link: https://github.com/leitao/liburing/blob/getsock/test/socket-getsetsock-cmd.c RFC -> V1: * Copy user memory at io_uring subsystem, and call proto_ops callbacks using kernel memory * Implement all the cases for SOCKET_URING_OP_SETSOCKOPT V1 -> V2 * Implemented the BPF part * Using user pointers from optval to avoid kmalloc in io_uring part. V2 -> V3: * Break down __sys_setsockopt and reuse the core code, avoiding duplicated code. This removed the requirement to export sock_use_custom_sol_socket() as done in v2. * Added io_uring test to selftests/bpf/sockopt. * Fixed "compat" argument, by passing it to the issue_flags. Breno Leitao (9): bpf: Leverage sockptr_t in BPF getsockopt hook bpf: Leverage sockptr_t in BPF setsockopt hook net/socket: Break down __sys_setsockopt io_uring/cmd: Pass compat mode in issue_flags selftests/net: Extract uring helpers to be reusable io_uring/cmd: Introduce SOCKET_URING_OP_GETSOCKOPT io_uring/cmd: Introduce SOCKET_URING_OP_SETSOCKOPT io_uring/cmd: BPF hook for getsockopt cmd selftests/bpf/sockopt: Add io_uring support