From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (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 8B7D91B59F for ; Tue, 5 Mar 2024 20:00:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709668824; cv=none; b=HtUTp7bAU6Z78XAiwpXSPBiHKq2ifLsrj3tphVr07h3Fd9hgBMTBbZoi67sv9o1bUCYK7A5TyvDN4nZdZ+jCPRnVkHLLDN0YZm/7TnpTz1EojjvzNPDegrj1NYEWjGiaf+ldOs+HuRm/6n3qLRv5ENCPQdJZ+EGKvoIUZL83fJ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709668824; c=relaxed/simple; bh=zvCIxr8VBjsKzdRKj72ITiWaaPuXwUFhasVmFGiaDtk=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=dCi446Hfl4c0ialN6X1Uof8avHOv9Lm3JaoWec1BI3xh75ARvzTIZYJEZD1Q14it/uXeQCdkub8znUye+VG/aVPtIB12wmQeXm5CQbginnJh2QPDtxF1Q21uEsQb2j7xx5Gpq1Ha18JFXvOq9V1R3UKSo3W+nofRKtg2toZ7UkU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=GQCcdh2M; arc=none smtp.client-ip=209.85.218.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="GQCcdh2M" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a450bedffdfso346915066b.3 for ; Tue, 05 Mar 2024 12:00:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709668821; x=1710273621; darn=vger.kernel.org; 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=Um7HQJN8N4J1bd3DjjlCtIBtcKYJjLGAY5O7WX29jhs=; b=GQCcdh2MldH/YcpNngEOhJ93Lez+BG92jbvj3xTQKZfXfuaZNCzmOOZbV2gDMd4//R RUDIXcB0aVfS9WSwFs7IJJQ/y1Qy/nicYVfdFQluHtxSMfgcamUEChzZrV6bE5RVAg+d 8x7sUhgoYrXyQAD3Q6LRJGRQxNsdjrhT6qN4tKbeqfoxWmkzMvDIL7erP/n5qj18xKHf R8fBtNcxgwib9+mtc8yx+839STKOJlbtiDxY5Rzdvlj2/s7kRdLuo4E2+Lxyc/t5v71o hE27KoRkiuOaRQejDkoDPRhF+QXyaz5wGJRSvG72AT2vKBH6JSBdgt/ZHxE3VsBBvnf8 rw+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709668821; x=1710273621; 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=Um7HQJN8N4J1bd3DjjlCtIBtcKYJjLGAY5O7WX29jhs=; b=tWHjpAipee6T6gCqkHnlqf7c1hl8Zr9zJviVjOYm7CHB2FTOvQ0n9vlSv7Po0Zau4e KfA8s8HTx8hyOAwsKMsUYTgfk1yKV7HBM0rvw9OdBdQZ5qf0KnwfdfiQ4ot5+0tDabF0 9fKTJIXB/ypei6VtM83SliJHKD1lZOpSuH0IrfHt1BqcsA++Cvujk6k1OY+HfjmLdMfX optaKFFOXNcsDXMggbIz50UfdJ0DZADXcGUkGcXlEADMezM8ScyX0WyLnDOfq7tZiIPj W/1WvlqbgR9p1nhHyqelk7rjecDAvZFSRv8a/G3eZNnwFjA8aoFja6mtoTo7qQrznUWG GVPA== X-Forwarded-Encrypted: i=1; AJvYcCVaokXLfwl9acMkfFk7cv/2lAurmBE41P+pcSf3Lh1+CD3sR2+mLL1/NnbguAF2k3bA4P1aYmswXXfaBusWa2DXnkGrgydQpvx1nA== X-Gm-Message-State: AOJu0Yxij0jERExy+X0wTVeyC6pNNe69zJ+tnBrS4OSpl3iamLEAWE1i /sPyujYygGnB+VtrTMkXEFxaYT+9wS/ktZ5SEtaAgt29qeJk6hVUIuUEXBNOMa3Z7gw28YW7hIz UyK8m0HeWZRHFlTohTtq2NzS5ClDjAokAyMMY X-Google-Smtp-Source: AGHT+IHytdC7v7Vx7sLFDUTdLyz9HH4/B980RlTrZABliOPKZSD4E6pDWhlNI6pqEZujcxK31LaEVTdzhieo1tJYP+0= X-Received: by 2002:a17:906:394b:b0:a43:6146:a4df with SMTP id g11-20020a170906394b00b00a436146a4dfmr7667230eje.21.1709668820535; Tue, 05 Mar 2024 12:00:20 -0800 (PST) Precedence: bulk X-Mailing-List: sparclinux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240305020153.2787423-1-almasrymina@google.com> <20240305020153.2787423-6-almasrymina@google.com> <5e2f9342-4ee9-4b30-9dcf-393e57e0f7c6@app.fastmail.com> In-Reply-To: <5e2f9342-4ee9-4b30-9dcf-393e57e0f7c6@app.fastmail.com> From: Mina Almasry Date: Tue, 5 Mar 2024 12:00:08 -0800 Message-ID: Subject: Re: [RFC PATCH net-next v6 05/15] netdev: support binding dma-buf to netdevice To: Arnd Bergmann Cc: Netdev , 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 , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , 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 , 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 , David Ahern , Willem de Bruijn , shuah , Sumit Semwal , =?UTF-8?Q?Christian_K=C3=B6nig?= , Pavel Begunkov , David Wei , Jason Gunthorpe , Yunsheng Lin , Shailend Chand , Harshitha Ramamurthy , Shakeel Butt , Jeroen de Borst , Praveen Kaligineedi , Willem de Bruijn , Kaiyuan Zhang Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Mar 5, 2024 at 1:05=E2=80=AFAM Arnd Bergmann wrote: > > On Tue, Mar 5, 2024, at 03:01, Mina Almasry wrote: > > > +int netdev_bind_dmabuf(struct net_device *dev, unsigned int dmabuf_fd, > > + struct netdev_dmabuf_binding **out) > > +{ > > + struct netdev_dmabuf_binding *binding; > > + static u32 id_alloc_next; > > + struct scatterlist *sg; > > + struct dma_buf *dmabuf; > > + unsigned int sg_idx, i; > > + unsigned long virtual; > > + int err; > > + > > + if (!capable(CAP_NET_ADMIN)) > > + return -EPERM; > > + > > + dmabuf =3D dma_buf_get(dmabuf_fd); > > + if (IS_ERR_OR_NULL(dmabuf)) > > + return -EBADFD; > > You should never need to use IS_ERR_OR_NULL() for a properly > defined kernel interface. This one should always return an > error or a valid pointer, so don't check for NULL. > Thanks for clarifying. I will convert to IS_ERR(). > > + binding->attachment =3D dma_buf_attach(binding->dmabuf, dev->dev.= parent); > > + if (IS_ERR(binding->attachment)) { > > + err =3D PTR_ERR(binding->attachment); > > + goto err_free_id; > > + } > > + > > + binding->sgt =3D > > + dma_buf_map_attachment(binding->attachment, DMA_BIDIRECTI= ONAL); > > + if (IS_ERR(binding->sgt)) { > > + err =3D PTR_ERR(binding->sgt); > > + goto err_detach; > > + } > > Should there be a check to verify that this buffer > is suitable for network data? > > In general, dmabuf allows buffers that are uncached or reside > in MMIO space of another device, but I think this would break > when you get an skb with those buffers and try to parse the > data inside of the kernel on architectures where MMIO space > is not a normal pointer or unaligned access is disallowed on > uncached data. > > Arnd A key goal of this patch series is that the kernel does not try to parse the skb frags that reside in the dma-buf for that precise reason. This is achieved using patch "net: add support for skbs with unreadable frags" which disables the kernel touching the payload in these skbs, and "tcp: RX path for devmem TCP" which implements a uapi where the kernel hands the data in the dmabuf to the userspace via a cmsg that gives the user a pointer to the data in the dmabuf (offset + size). So really AFACT the only restriction here is that the NIC should be able to DMA into the dmabuf that we're attaching, and dma_buf_attach() fails in this scenario so we're covered there. --=20 Thanks, Mina