Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp646077lqs; Tue, 5 Mar 2024 12:00:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWMbM6kzODgdRj82LWLsd/KepKg3E8jdt/4GQocf2s4zBF8gYnGFCncrdfZdnaSiP6dw6ybTd5EuNd1N97BT6JMAWYvobpLiC8i6HTp8A== X-Google-Smtp-Source: AGHT+IFEUh1MlwycxC4b7VCCUcDQjyqP7QzlUavNYF9sdjmPR5zXiEP9twlNBdv9HdSVozXtcNQ/ X-Received: by 2002:aa7:d9da:0:b0:567:de59:e93e with SMTP id v26-20020aa7d9da000000b00567de59e93emr225283eds.25.1709668845025; Tue, 05 Mar 2024 12:00:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709668845; cv=pass; d=google.com; s=arc-20160816; b=TJYu73ALfX6P1t3dNR+57IDn44fUml+7jX3E9W9AADjy8XKWk/jTJS3uGPWboNs6Xr 3FDlFkp3n4bVz9N8E+bLEMUxFlMvaBo24zUrsW6wvCUzmRcUGKGrZ4V7ptimcYLrHQiQ JtCGKRuKpotPM9h16lf4Np3AUlpxAtlsqjXdIaz+4geyw6k6UPEJJeRvRUzprnnBQ7pY 6VgFgPBzWqxJn9/zOIBJXd5Jm+Y3gOeFqQUGk26AOiT3aayduDTaCYhIF9yYw9LBekCA TQnxox4LeDcam+iqpyb9Iz+8jWl9v8y8eVYrutqbipzE3AgT5OywQavdOK/JDtPmBHjI nCJQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=Um7HQJN8N4J1bd3DjjlCtIBtcKYJjLGAY5O7WX29jhs=; fh=0/PrOuuGIxQRwjT+AiIxVxBQWaY+iVW/sriY5jK0Lq0=; b=UFsoZMmHkBDKfKDeeYY9uqFdhYcLvLxj8lx1wi7CWzc5D/lLs3wcKEVNLC2+Tp3Soq i1urEeF0kAMQ//i1Ss3LWqHul6nzhywyhzqa4g1ysKuwgR+UAZYiR+hcz3v81MYVUlKg euYAZqygJX/9kSNTTV9e3zVTRnSBfBLQcKU3mkPEHLR8gjUC6avtn+zqQutp1JxPOOT6 UJqyicHSS77tapzHgBf2ENYUrgPWrbM0FaIsze211YmMpK6Fi/KhOngcXYq9jyx2aZ9b MMG9niue8w8rxV5PddEfpDAyCUyT/Fv305uN60fXFarAc1MG7S992hppdj3GhVybrOrH HGAA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=GQCcdh2M; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-92920-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-92920-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id r22-20020a50d696000000b005640f00f50bsi5293786edi.415.2024.03.05.12.00.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 12:00:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-92920-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=GQCcdh2M; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-92920-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-92920-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 9376E1F27F54 for ; Tue, 5 Mar 2024 20:00:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CA16760EF8; Tue, 5 Mar 2024 20:00:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="GQCcdh2M" Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (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 A05708563F for ; Tue, 5 Mar 2024 20:00:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709668824; cv=none; b=arPFUN2OoLgCAqYGUJZ/s6OoePLmrS5URP/QEVM/wFPYhLTMc59YImZudWWn22EvKLGUX4l4uc+PizJ5kvzud0HCs05hoCqSRXV2cgXI9swGInb8DKX0Ua48oWPrzT7L4CqT4eJnb0WRCM7DBirq0lUBU6zSoU/XL76RgttyRqk= 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.41 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 Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a45b25f6f84so40309366b.0 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=Kr2VX+5dBlg9fJiajdkP4pLHr1XmVrECGhEh41vlJn/UGZrUIimt1BEetovTHhyJ39 6Hj6IcVXXQOjMSIHGSpQvi6lSLf1RkCDsAlysQ1nO9XrvWD86OC+0w0Q0j3rj0dTr37O 2Ort+mLwWAlnAegKqJrr02X0hEQJ8l5FwZ4Yxc+UT143y3FHsTjc2N6CpR3ngl+IX/em iZSSf+uZMY6Jr3WetVj3BJLr/Y2GuynYlOjRbuoxkKXeOdXdOS+YP61HPAAhhIey0Bqh lIQuvMpd0XpdyWjmDQFHeQx3ZpqvAc0AM0RO3hkadtcfwkQsqBKtNys73F++kQ9c68Qw rXqQ== X-Forwarded-Encrypted: i=1; AJvYcCW5cN5A4Kdiab5jQIBDGoKbgJuITOikAlLpi6lepaKhXl9h1mNLG+lD5M+4K4ZuPaUPlCfdO3r5rXKYkH9040PEeWyV0zIzqUAS4sFp X-Gm-Message-State: AOJu0Yyx97BNaaDVHi9ccN6auyt911FjntsxRmwnOoERdeJ5AgLlgE/C UwWeFdlol4H8jyZHVW9OsCHBQ0Zf+Xe5/pO9CGyVsnOHDQQep80X0WY03apCIU4JDKj3qX2BxUi aFSMpLhiXP3dI29j+oF6+OfMiX7R0aKP0CpBO 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: linux-kernel@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