Received: by 2002:ac8:734e:0:b0:40f:fb00:664b with SMTP id q14csp1722876qtp; Wed, 9 Aug 2023 09:59:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHF3mE966xoRPhdNA/oZmM049g3QgLVlJQKH3f819Tnf2sbnsmbq4654n5sECrI6tnNkECb X-Received: by 2002:aa7:c655:0:b0:523:102f:3ce1 with SMTP id z21-20020aa7c655000000b00523102f3ce1mr2996116edr.10.1691600387029; Wed, 09 Aug 2023 09:59:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691600387; cv=none; d=google.com; s=arc-20160816; b=COvhdgiJCZ3avNlaRKsjHrlgdr+1ecoJPTHHhggsUoZeWnu5vjHGJFnoqoyMYMyXK5 cUItt1QOrPeyfgfTJ+eJoBzpE4TYV6W4Qw9hceuXRZUtcdzJsYw0oitPhgAyRM3ycEmY Jt03QjAzZdZ2/8Ed+ydCfQMd3l4Yo9EqtOTAq9veopgUJBJOryRGIYbQoM6c7H/kMvJK Nhw18Ahqo5kg7v5ePQVUaIJ18MmfQrcXPaEwFCdgUY6/wEIONY4LJQc5voxbpBWgy8um 02rcMGRACKXrejC4Wbzi9nJ50T/Q3zB0Wq9CXcdvTWkL0aH0/2gRKAlnswcvVv1HBqRT gjRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:dkim-signature :dkim-signature; bh=6rO3bUwCxHrhMQ/KnyWVceX9aLTMN6xCVxviePeeskU=; fh=+V/QRs68yeDRu3Uxk4J70FAGv6km6I5r6wzqah/E9iw=; b=kYQ4yPR96841OvglP+EETCvO3HeIq0cDCUmC52dJsoPzyJHKC4l1A8VK0AirUJcXkl NPcUaCGFfNlTHmRtePn87+/9nPKdqe4QjAmrta17a0xLlWBiamczVpophBIhY14IVmGs j1u0MI1eqWFL70LZ4emiwSGybDM39wJ+s4y+asgzpiR3AesJMenDLNjl4cSrHMJPP7/Q nBgrz4Bw4hVy4xy5Qx1kILx5yCcUzkOYFYfeAhwYmMnQF7gilMNUEt2iIAI5hX/+IV63 IobZ/EAVQX0n1RsLKZxlOIJlVwWjVu1vkSmGsacxHD0hCXF24IdpsSYbbq4k29VIM2eQ Ypcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=txUbbjWI; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=D6SVisja; 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=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d13-20020aa7d68d000000b005234da35264si1846915edr.125.2023.08.09.09.59.23; Wed, 09 Aug 2023 09:59:47 -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=@suse.de header.s=susede2_rsa header.b=txUbbjWI; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=D6SVisja; 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=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230283AbjHIQqc (ORCPT + 99 others); Wed, 9 Aug 2023 12:46:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229710AbjHIQqb (ORCPT ); Wed, 9 Aug 2023 12:46:31 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2FD81BF7; Wed, 9 Aug 2023 09:46:30 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5673021866; Wed, 9 Aug 2023 16:46:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1691599589; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6rO3bUwCxHrhMQ/KnyWVceX9aLTMN6xCVxviePeeskU=; b=txUbbjWI5xw5IUefZ5+yIFbM4fAhuTkdbK68tmd9ICSYbBAuJ++hpQQg6rxjeL0n2VXzel zj2aZuTBkvwIOmCjEr7Y6at53HwZkrlpX/bcUlaDc/gM1tsNuSrUwU9J3XXEPKaw0XSmPn 3biEZDSHLsaLDk4yVAXY3G/xW3CIDBY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1691599589; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6rO3bUwCxHrhMQ/KnyWVceX9aLTMN6xCVxviePeeskU=; b=D6SVisjaDadmt9fliy1dxxoVcIW1VNppOcFZSit1E54dGhJ4h7QqGkljwSTY9FmUIB0Oy3 6rqA/qJDBVQvv/BQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1562F133B5; Wed, 9 Aug 2023 16:46:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id UXouO+TC02SQbAAAMHmgww (envelope-from ); Wed, 09 Aug 2023 16:46:28 +0000 From: Gabriel Krisman Bertazi To: Breno Leitao Cc: sdf@google.com, axboe@kernel.dk, asml.silence@gmail.com, willemdebruijn.kernel@gmail.com, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, io-uring@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com Subject: Re: [PATCH v2 7/8] io_uring/cmd: BPF hook for getsockopt cmd In-Reply-To: <20230808134049.1407498-8-leitao@debian.org> (Breno Leitao's message of "Tue, 8 Aug 2023 06:40:47 -0700") References: <20230808134049.1407498-1-leitao@debian.org> <20230808134049.1407498-8-leitao@debian.org> Date: Wed, 09 Aug 2023 12:46:27 -0400 Message-ID: <87wmy46u58.fsf@suse.de> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 Breno Leitao writes: > Add BPF hooks support for getsockopts io_uring command. So, bpf cgroups > programs can run when SOCKET_URING_OP_GETSOCKOPT command is called. > > This implementation follows a similar approach to what > __sys_getsockopt() does, but, using USER_SOCKPTR() for optval instead of > kernel pointer. > > Signed-off-by: Breno Leitao > --- > io_uring/uring_cmd.c | 18 +++++++++++++----- > 1 file changed, 13 insertions(+), 5 deletions(-) > > diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c > index dbba005a7290..3693e5779229 100644 > --- a/io_uring/uring_cmd.c > +++ b/io_uring/uring_cmd.c > @@ -5,6 +5,8 @@ > #include > #include > #include > +#include > +#include > > #include > #include > @@ -179,17 +181,23 @@ static inline int io_uring_cmd_getsockopt(struct socket *sock, > if (err) > return err; > > - if (level == SOL_SOCKET) { > + err = -EOPNOTSUPP; > + if (level == SOL_SOCKET) > err = sk_getsockopt(sock->sk, level, optname, > USER_SOCKPTR(optval), > KERNEL_SOCKPTR(&optlen)); > - if (err) > - return err; > > + if (!in_compat_syscall()) > + err = BPF_CGROUP_RUN_PROG_GETSOCKOPT(sock->sk, level, > + optname, > + USER_SOCKPTR(optval), > + KERNEL_SOCKPTR(&optlen), > + optlen, err); I'm not sure if it makes sense to use in_compat_syscall() here. Can't this be invoked in a ring with ctx->compat set, but from outside a compat syscall context (i.e. from sqpoll or even a !compat io_uring_enter syscall)? I suspect you might need to check ctx->compact instead, but I'm not sure. Did you consider that? > + > + if (!err) > return optlen; > - } > > - return -EOPNOTSUPP; > + return err; > } > > static inline int io_uring_cmd_setsockopt(struct socket *sock, -- Gabriel Krisman Bertazi