Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp846668lqp; Thu, 23 May 2024 01:30:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVV9eCdIjCvBwdLvgDJFUUkIvY9kPQpnA/NpScuVokPahtDn7X2bzXxjcNiZrU3dVSS3kNaLtJsxND9JqQDpjTeapQCUo0lSH7do6r4rA== X-Google-Smtp-Source: AGHT+IGxOxrxTI3vhK8C19kp7fy6hb1DWoWxA4x9+62ktSxLiI576j/Rfx2hyszrW5wUn0QMXJfX X-Received: by 2002:a17:902:e741:b0:1f3:35e8:d2fc with SMTP id d9443c01a7336-1f335e8d4cemr25702095ad.19.1716453042705; Thu, 23 May 2024 01:30:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716453042; cv=pass; d=google.com; s=arc-20160816; b=g70NydCS6spJ2ec9vBUZZuHz4Lsck0xfbVMDFsR9vVzFlMFspnEkHhisTADtDu6/Jn mQ4BZhhgpW4okKMm8NPq6XLfkFqBxuAcsSkjgNINbezH/FdOoGleHJicSp/43zf9/5OY dbudGB4qg8q51iEBpPSR6QwaiLUSYTDqbfP3oRmiVp96h7ytiZGLu6SkMDoaieHsch8W bDiWk7A2ePBumNkme+ZbauE05A/0gJc8CkyPn+jYEaAIdT5sTCYTMLTM3eoEuuL3KfSO A+7WbAHNXcgylfaOn+d0797H0dxH1CCsG0yd7uNry7AYpoCuDdu+5/1lYVvJcdZ0MDak aMZg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=txOSv1K2CA1USg0Ze10vD1qMyJxbEs9Mfk9GiCoI090=; fh=LntsfhaS2muwfsclUwd7J6RPGqO/GuXVSbFXn/F4l5w=; b=y66KMmjIlEreGUl1oJHrYsj3eUf33HZIpB9WRThack2h/OagMiRueuvw7wtaGNiM8E k9NfUr+rPTsQ9REPVDl7vH1nWjSBfq6jHebMLNpTNHYM6956XzfSHiuVx4Nu3wmmRlaO w/zcBpmohP5ywkFbWLv0oT2afFS7odQYtHzPYusaRshtkq7LJaON5npJjq/AoNlxRXVr yLPBeSSYdpHsFShyhmicppI0BCZ3bvDB2iPAayru9JAxDgzeOjvT+sEJQ42+6VLSJYvc 8Sks+0fAHtkHrZ2hf/1vwIEKdlVWSSMYEB7e9fH246QaaAsx8/ejxG68xrwThBbM/5ij dOSA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@davidwei-uk.20230601.gappssmtp.com header.s=20230601 header.b=Uz2AHfik; arc=pass (i=1 dkim=pass dkdomain=davidwei-uk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-187026-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187026-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0bad7930si11325885ad.190.2024.05.23.01.30.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 01:30:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-187026-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@davidwei-uk.20230601.gappssmtp.com header.s=20230601 header.b=Uz2AHfik; arc=pass (i=1 dkim=pass dkdomain=davidwei-uk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-187026-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187026-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E0832284948 for ; Thu, 23 May 2024 06:03:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0B55C13B59C; Thu, 23 May 2024 06:03:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b="Uz2AHfik" Received: from mail-io1-f43.google.com (mail-io1-f43.google.com [209.85.166.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8364713B584 for ; Thu, 23 May 2024 06:02:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716444179; cv=none; b=sPA2ZlJZtSnHK4VGQJ8taMQwrVFEQ/GMLBiQqckbxPZCrhHWFm/vektR7OGvFh2wnVGKMKW5h7Fvym7q6LWv1lhKl5RT7YhEE5iQUriBxqC2AzKJPJYNlnf8A3HRjVamcg1Mwo5ZRxaX+mgMlwa8q1WX7Nnqqv7WFRWCmtpkXss= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716444179; c=relaxed/simple; bh=B9lGrOwbzZ9cwWP1ohGSBcMGMvcXioUh06F1RRqtc5A=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=jM0HTGJFuHxLDILqG6vxnYpLrWKxizAHXINGJr06vMZAONVcUOV8F75egbUz1212nCG9tzBMvf+K+lLsCRmL4JvCHAvaJ58nATnjdTKXMNbiGSi/92Voht2KcqyZH0O0WuzEJflwsKVC1m2nb70QaE9njkm04FQ9DgJZ4vV0g7k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk; spf=none smtp.mailfrom=davidwei.uk; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b=Uz2AHfik; arc=none smtp.client-ip=209.85.166.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=davidwei.uk Received: by mail-io1-f43.google.com with SMTP id ca18e2360f4ac-7e238fa7b10so211807839f.0 for ; Wed, 22 May 2024 23:02:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1716444176; x=1717048976; darn=vger.kernel.org; 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:message-id:reply-to; bh=txOSv1K2CA1USg0Ze10vD1qMyJxbEs9Mfk9GiCoI090=; b=Uz2AHfikahhuUowwWHZ/rUV3mnPgvxCUBUVLy75Ni4QVr3Zm8DMJc7X+YPT/ZlueFf fM09t2fSBt5pPpQRo2M2zZC0pkRmdXI9FCcScF4/EKN/cySBOR/qDzA5ekE4ILkpPwpy 5mKNJ6bHDg+TEheZbQ3IkCrHP/NZCEn3hQOxoKAsaSNFqq1PjKOo0dSQD72z4WdrL11T SDuOkvOaGOZFmfxRTdXg/vfbkBY5oBXpiOFGPI2dN03MwRCRVp7zTktF7l5JeFQL9kbh gj4aNjvikrd9qQBAiO+5XOkySFNkgVh2QVR/GkOax5g1Q2KM/PsKBO5u3BVjXDevfa5r Zpcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716444176; x=1717048976; 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:message-id:reply-to; bh=txOSv1K2CA1USg0Ze10vD1qMyJxbEs9Mfk9GiCoI090=; b=ccqJ5l18T89jk1xnP3gMCnRwKSwCUCF153iOumsyVX613WUjrr8JMikMmSqd8ZhEBh PT/M2as9WpiAviSKCNxw6k02pQI9oyXkfU11KELfD6NEgWU/Weqr4S0fUxXvD+ly8BsD 858hy4+PX0lkTUaqDPkRK0zAqRu1sId1uymf2DR8p6TLlTOphCRGfqTb/gCxAf/MpnhL cx+2Ie9FWSIa2V37TvrhFZrDO5rMqkfMWNn0VQpG1UTZmqzsBpwNflK1RlgExDkV0PRJ AyOJUv3KA0ZGfMvg77izfieGuoZAn9BEvF5ydjPIZ5OGZwTfqpkB+e1/Z9WULdsy/Kaj k1QQ== X-Forwarded-Encrypted: i=1; AJvYcCWllCG32P1Q/aYC7LWIqhxfhElSBirZTVyDgBz3HxrguywHup16wiz/xJAry8uCBrYMb2KO55aNUz9l6l/oRaUid8Cbldre1g3p+GSP X-Gm-Message-State: AOJu0Yz9BwfHZ3V8H4HC4XTcQwVChSeDzVMUnnw63B0E/XAe4I8BDhRE YgTUOYe3gajM5s4VMoGO7mXkFWiFeZxJkDHgfZbYmqsq6IyQ3Nwj+fH/N1D/7SwanmCMpkQNNp9 t5Os= X-Received: by 2002:a05:6e02:1447:b0:36c:7f3d:59a with SMTP id e9e14a558f8ab-371f7c80fe6mr48056835ab.4.1716444176327; Wed, 22 May 2024 23:02:56 -0700 (PDT) Received: from [192.168.1.16] (174-21-188-197.tukw.qwest.net. [174.21.188.197]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-634117190absm23448503a12.87.2024.05.22.23.02.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 May 2024 23:02:55 -0700 (PDT) Message-ID: <9097e78d-0e7d-43bd-bafd-e53a4872a4d1@davidwei.uk> Date: Wed, 22 May 2024 23:02:54 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net-next v9 11/14] tcp: RX path for devmem TCP Content-Language: en-GB To: Mina Almasry , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-alpha@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, sparclinux@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-arch@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Cc: Donald Hunter , Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Jonathan Corbet , Richard Henderson , Ivan Kokshaysky , Matt Turner , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Andreas Larsson , Jesper Dangaard Brouer , Ilias Apalodimas , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Arnd Bergmann , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Steffen Klassert , Herbert Xu , David Ahern , Willem de Bruijn , Shuah Khan , Sumit Semwal , =?UTF-8?Q?Christian_K=C3=B6nig?= , Pavel Begunkov , Jason Gunthorpe , Yunsheng Lin , Shailend Chand , Harshitha Ramamurthy , Shakeel Butt , Jeroen de Borst , Praveen Kaligineedi , Willem de Bruijn , Kaiyuan Zhang References: <20240510232128.1105145-1-almasrymina@google.com> <20240510232128.1105145-12-almasrymina@google.com> From: David Wei In-Reply-To: <20240510232128.1105145-12-almasrymina@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2024-05-10 16:21, Mina Almasry wrote: > +/* On error, returns the -errno. On success, returns number of bytes sent to the > + * user. May not consume all of @remaining_len. > + */ > +static int tcp_recvmsg_dmabuf(struct sock *sk, const struct sk_buff *skb, > + unsigned int offset, struct msghdr *msg, > + int remaining_len) > +{ > + struct dmabuf_cmsg dmabuf_cmsg = { 0 }; > + struct tcp_xa_pool tcp_xa_pool; > + unsigned int start; > + int i, copy, n; > + int sent = 0; > + int err = 0; > + > + tcp_xa_pool.max = 0; > + tcp_xa_pool.idx = 0; > + do { > + start = skb_headlen(skb); > + > + if (skb_frags_readable(skb)) { > + err = -ENODEV; > + goto out; > + } > + > + /* Copy header. */ > + copy = start - offset; > + if (copy > 0) { > + copy = min(copy, remaining_len); > + > + n = copy_to_iter(skb->data + offset, copy, > + &msg->msg_iter); > + if (n != copy) { > + err = -EFAULT; > + goto out; > + } > + > + offset += copy; > + remaining_len -= copy; > + > + /* First a dmabuf_cmsg for # bytes copied to user > + * buffer. > + */ > + memset(&dmabuf_cmsg, 0, sizeof(dmabuf_cmsg)); > + dmabuf_cmsg.frag_size = copy; > + err = put_cmsg(msg, SOL_SOCKET, SO_DEVMEM_LINEAR, > + sizeof(dmabuf_cmsg), &dmabuf_cmsg); > + if (err || msg->msg_flags & MSG_CTRUNC) { > + msg->msg_flags &= ~MSG_CTRUNC; > + if (!err) > + err = -ETOOSMALL; > + goto out; > + } > + > + sent += copy; > + > + if (remaining_len == 0) > + goto out; > + } > + > + /* after that, send information of dmabuf pages through a > + * sequence of cmsg > + */ > + for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { > + skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; > + struct net_iov *niov; > + u64 frag_offset; > + int end; > + > + /* !skb_frags_readable() should indicate that ALL the > + * frags in this skb are dmabuf net_iovs. We're checking > + * for that flag above, but also check individual frags > + * here. If the tcp stack is not setting > + * skb_frags_readable() correctly, we still don't want > + * to crash here. > + */ > + if (!skb_frag_net_iov(frag)) { > + net_err_ratelimited("Found non-dmabuf skb with net_iov"); > + err = -ENODEV; > + goto out; > + } > + > + niov = skb_frag_net_iov(frag); Sorry if we've already discussed this. We have this additional hunk: + if (niov->pp->mp_ops != &dmabuf_devmem_ops) { + err = -ENODEV; + goto out; + } In case one of our skbs end up here, skb_frag_is_net_iov() and !skb_frags_readable(). Does this even matter? And if so then is there a better way to distinguish between our two types of net_iovs?