From patchwork Fri Sep 6 09:52:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13793825 X-Patchwork-Delegate: kuba@kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A2471C8FB0 for ; Fri, 6 Sep 2024 09:52:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725616351; cv=none; b=qXKa17lA0PoNvpqUBxoVYu1S9D5ChpLRf4aUYjDgqW28MlRvk8jeBUTAfWAgPz6td3YwsU9UER+OtOumR6B94Gx0/JV1ExaRe43P1TlZ99IaoVUvbCPOjjXNEkbzUSMuRJs4nQHzP2s/nZwglcMhQjDql6ziumH9/T0bqlZSNE0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725616351; c=relaxed/simple; bh=DWPyC70aofNTN8NzN76YlcX1EqMQAr3p3SCqYoehNM4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fwJ1V5bVjrHYu9oP4I1Y8CTH6JOMeJGUsRg3RXzROKR95d71oQNsOCg7xHJoUyjCtLw88MzH3gQ8OWFAZ8QDU78h6oUfmv501DVmGrDxZgN87BF7EvDJNSgEMTiF32EDTRRcF789ARgMcSDp3eVVEdxiDUkcvuGNg8La4ruY+58= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=LKnyHv6v; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LKnyHv6v" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725616349; h=from:from:reply-to:subject:subject: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=qOfH+ccoyBiuGopATmlM0rbjaC0DlQkgKBk3NY2p3mM=; b=LKnyHv6vVQ0BXzHtfZtjc8wcmIR7uO30BtQtaKXvEAUT8IZ5qTJOi54n7J5GgG2InwQsMF K3ghbcNflgkelmcFRfABIZhZjVsU+VocbqaBIvgqUK87ZbdmnTg0XFbbwQ9mIkjd6NgRyM jdZBzuyqx8OuU2xoWHTwqlL785DJnQQ= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-454-nmQbWcFPMZyRejq820IUlw-1; Fri, 06 Sep 2024 05:52:28 -0400 X-MC-Unique: nmQbWcFPMZyRejq820IUlw-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-374cd315c68so1190304f8f.0 for ; Fri, 06 Sep 2024 02:52:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725616342; x=1726221142; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=qOfH+ccoyBiuGopATmlM0rbjaC0DlQkgKBk3NY2p3mM=; b=mYgxbt+CXmqDFI4S2J7QPYlR6B68tyTb7xCAqYvEWgklwfcD2e8P/KtWIXXFJQO0a6 1jD8SWdvFU0PNkbkw3m1fuY4I2lDcr0MdRNUgvqcRCyXWYazaCw3FWq2tjqsC6O+14Vg ydJHSHV/2Ne0M26FCSoAq0ySZIe+cWpytPblYl/RiIlwHQHm6Qch32yDUGS6XNyNtgls yrngEKrWdyRdgwyUNlHGh8zStGSIq+AGOmfOPT0PnFpvi2vPhgyibwwu4lR8UbWA06Sd abhbBxfvO0jDGKFlFPSHx7I7c2TzkubDXBrn7n8ZAolUkhtcUuZU5Ke59evKQLh4/obq AbKA== X-Forwarded-Encrypted: i=1; AJvYcCXsxf6BGKwyIW8pUdtI01DILWHGp1I2mcieyumz/bBJ+vPCBy0w2ZVadIhyGXVEC8gMi9k=@vger.kernel.org X-Gm-Message-State: AOJu0YyFb5VPWLsGlvsG6ojmJmLuQRXoiOMouYo7Ioy3kN7FtT5GCkEt tCW3He7jFV9t03vXumaY5XZg5ERd2XG87eDji8Uxdj4EkS9OTD+JSM7t0v3IFUefD43JTIIt7nx 20WamfUVVTvslnG+7wtAx8P5+xBCmW0HpKriDLkdsm1U+VqJNkk0MheepwwDZ X-Received: by 2002:adf:fb11:0:b0:371:8845:a3af with SMTP id ffacd0b85a97d-3749b57f2f1mr16703545f8f.39.1725616341752; Fri, 06 Sep 2024 02:52:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFTt73JKwPHK16Z3/RYkW5dDFMWDG3+e0lk0yoShyoCu8E1G8MPLSTYcu8GmLc/SunC8mGUWg== X-Received: by 2002:adf:fb11:0:b0:371:8845:a3af with SMTP id ffacd0b85a97d-3749b57f2f1mr16703518f8f.39.1725616340741; Fri, 06 Sep 2024 02:52:20 -0700 (PDT) Received: from redhat.com ([155.133.17.165]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-374c958c471sm13302350f8f.25.2024.09.06.02.52.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 02:52:20 -0700 (PDT) Date: Fri, 6 Sep 2024 05:52:16 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Xuan Zhuo , Jason Wang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , virtualization@lists.linux.dev, Si-Wei Liu , Darren Kenny , Boris Ostrovsky , Eugenio =?utf-8?b?UMOpcmV6?= , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , bpf@vger.kernel.org Subject: [RFC PATCH v2 1/7] Revert "virtio_net: xsk: rx: support recv merge mode" Message-ID: <51e961cfb4f0a4db7fb4a7dc97cc966af05bf895.1725616135.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This reverts commit 99c861b44eb1fb9dfe8776854116a6a9064c19bb. leads to crashes with no ACCESS_PLATFORM when sysctl net.core.high_order_alloc_disable=1 Cc: Xuan Zhuo Reported-by: Si-Wei Liu Signed-off-by: Michael S. Tsirkin --- drivers/net/virtio_net.c | 144 --------------------------------------- 1 file changed, 144 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index c6af18948092..15e202dd6964 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -504,10 +504,6 @@ static int virtnet_xdp_handler(struct bpf_prog *xdp_prog, struct xdp_buff *xdp, struct virtnet_rq_stats *stats); static void virtnet_receive_done(struct virtnet_info *vi, struct receive_queue *rq, struct sk_buff *skb, u8 flags); -static struct sk_buff *virtnet_skb_append_frag(struct sk_buff *head_skb, - struct sk_buff *curr_skb, - struct page *page, void *buf, - int len, int truesize); static bool is_xdp_frame(void *ptr) { @@ -988,11 +984,6 @@ static void virtnet_rq_unmap_free_buf(struct virtqueue *vq, void *buf) rq = &vi->rq[i]; - if (rq->xsk_pool) { - xsk_buff_free((struct xdp_buff *)buf); - return; - } - if (!vi->big_packets || vi->mergeable_rx_bufs) virtnet_rq_unmap(rq, buf, 0); @@ -1161,139 +1152,6 @@ static struct sk_buff *virtnet_receive_xsk_small(struct net_device *dev, struct } } -static void xsk_drop_follow_bufs(struct net_device *dev, - struct receive_queue *rq, - u32 num_buf, - struct virtnet_rq_stats *stats) -{ - struct xdp_buff *xdp; - u32 len; - - while (num_buf-- > 1) { - xdp = virtqueue_get_buf(rq->vq, &len); - if (unlikely(!xdp)) { - pr_debug("%s: rx error: %d buffers missing\n", - dev->name, num_buf); - DEV_STATS_INC(dev, rx_length_errors); - break; - } - u64_stats_add(&stats->bytes, len); - xsk_buff_free(xdp); - } -} - -static int xsk_append_merge_buffer(struct virtnet_info *vi, - struct receive_queue *rq, - struct sk_buff *head_skb, - u32 num_buf, - struct virtio_net_hdr_mrg_rxbuf *hdr, - struct virtnet_rq_stats *stats) -{ - struct sk_buff *curr_skb; - struct xdp_buff *xdp; - u32 len, truesize; - struct page *page; - void *buf; - - curr_skb = head_skb; - - while (--num_buf) { - buf = virtqueue_get_buf(rq->vq, &len); - if (unlikely(!buf)) { - pr_debug("%s: rx error: %d buffers out of %d missing\n", - vi->dev->name, num_buf, - virtio16_to_cpu(vi->vdev, - hdr->num_buffers)); - DEV_STATS_INC(vi->dev, rx_length_errors); - return -EINVAL; - } - - u64_stats_add(&stats->bytes, len); - - xdp = buf_to_xdp(vi, rq, buf, len); - if (!xdp) - goto err; - - buf = napi_alloc_frag(len); - if (!buf) { - xsk_buff_free(xdp); - goto err; - } - - memcpy(buf, xdp->data - vi->hdr_len, len); - - xsk_buff_free(xdp); - - page = virt_to_page(buf); - - truesize = len; - - curr_skb = virtnet_skb_append_frag(head_skb, curr_skb, page, - buf, len, truesize); - if (!curr_skb) { - put_page(page); - goto err; - } - } - - return 0; - -err: - xsk_drop_follow_bufs(vi->dev, rq, num_buf, stats); - return -EINVAL; -} - -static struct sk_buff *virtnet_receive_xsk_merge(struct net_device *dev, struct virtnet_info *vi, - struct receive_queue *rq, struct xdp_buff *xdp, - unsigned int *xdp_xmit, - struct virtnet_rq_stats *stats) -{ - struct virtio_net_hdr_mrg_rxbuf *hdr; - struct bpf_prog *prog; - struct sk_buff *skb; - u32 ret, num_buf; - - hdr = xdp->data - vi->hdr_len; - num_buf = virtio16_to_cpu(vi->vdev, hdr->num_buffers); - - ret = XDP_PASS; - rcu_read_lock(); - prog = rcu_dereference(rq->xdp_prog); - /* TODO: support multi buffer. */ - if (prog && num_buf == 1) - ret = virtnet_xdp_handler(prog, xdp, dev, xdp_xmit, stats); - rcu_read_unlock(); - - switch (ret) { - case XDP_PASS: - skb = xsk_construct_skb(rq, xdp); - if (!skb) - goto drop_bufs; - - if (xsk_append_merge_buffer(vi, rq, skb, num_buf, hdr, stats)) { - dev_kfree_skb(skb); - goto drop; - } - - return skb; - - case XDP_TX: - case XDP_REDIRECT: - return NULL; - - default: - /* drop packet */ - xsk_buff_free(xdp); - } - -drop_bufs: - xsk_drop_follow_bufs(dev, rq, num_buf, stats); - -drop: - u64_stats_inc(&stats->drops); - return NULL; -} - static void virtnet_receive_xsk_buf(struct virtnet_info *vi, struct receive_queue *rq, void *buf, u32 len, unsigned int *xdp_xmit, @@ -1323,8 +1181,6 @@ static void virtnet_receive_xsk_buf(struct virtnet_info *vi, struct receive_queu if (!vi->mergeable_rx_bufs) skb = virtnet_receive_xsk_small(dev, vi, rq, xdp, xdp_xmit, stats); - else - skb = virtnet_receive_xsk_merge(dev, vi, rq, xdp, xdp_xmit, stats); if (skb) virtnet_receive_done(vi, rq, skb, flags); From patchwork Fri Sep 6 09:52:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13793826 X-Patchwork-Delegate: kuba@kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A00321C7B8C for ; Fri, 6 Sep 2024 09:52:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725616352; cv=none; b=LDhAc2yCkWgxBqHv4skvM/FnAM+wMRF71LS5k9SMUOk2cz3uEnlarjO/XjiZmlyGTgLOWRE5gUxiNO1aCv3NsleENB3v+FeqY7oYkdBP30ElFnATxiUa7Yv356a+kOKFNi926YnursrHCwqiYYYRyEgs9aNKmkgNNFrMuTRUtys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725616352; c=relaxed/simple; bh=KyPP1o9S1U5UC6LtE50yMluFJTn7axsCXpK4LciRg5k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=f1bb8f1DfH+br/eJAOtRfmqKIsRaMTDGsC2fJIsWnLWRjJYeJSFwx0dRG/yqgZwxq/qy+bf+tNL/lOIzhpTB5f42StX1yQeglIPryN0cQ2DhePYLIzLmgGg8MJTsBGd85pgKazL7aVRu8eXaBD0Fgim92CoAayhEdkxXjokjO9w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=iRgan3Lf; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iRgan3Lf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725616349; h=from:from:reply-to:subject:subject: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=vyImZpVyScr+sYVvHBd0P2jX1+a+RifktquzyDOii9A=; b=iRgan3LfKuWqUAfjeATMpjIbKTJ9pmDWVm3WM9XDhE41dH5VRg+xvpq+Jr7UQ3FtV80/AQ YkStOCSF70YOC4mcJRKNsyEDKdrKxQnRcYg5bozGMTx/q/2lYy0MoLEFDj85xTiTEMybNu 4vRohIUv3O2AGDJoLjNSgBiDNGQUqbE= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-456-wrPTUhL5N86skLnMxPx2fA-1; Fri, 06 Sep 2024 05:52:28 -0400 X-MC-Unique: wrPTUhL5N86skLnMxPx2fA-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-374bb1e931cso1480706f8f.0 for ; Fri, 06 Sep 2024 02:52:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725616347; x=1726221147; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=vyImZpVyScr+sYVvHBd0P2jX1+a+RifktquzyDOii9A=; b=GqwHAEEjzzNDHiLyN07pAD16geqgdoXIWXbY+M6iOuj3nNfIJUv7/B4qM9kt2/dROS CX2ngA76oW/BAvmtoiVmj+Kfz8nuWVrgwPCFK2QOEHDDOfAe8ezCr8Gvcu3Nc4FgYP5/ aUxH9ZxbbURSpFKcuwd2F4tNBMyXdTB7dg/nQj5t59TZFwmsrAKG4/PKd7PVGJ4PTEhZ 6ILm+LsnH/X6F7RRealvxZugRyC3rSjLGIYWWsqa1zTinZOTCcaM0CI4g++sVy29QmI3 gJ/MAEXBF9KGAcUIYIDti8vIcBwR2gEDTw7MRRzxxxb+dpHT7H44ZuB1EOwBXEsQI7en bjyA== X-Forwarded-Encrypted: i=1; AJvYcCUMo/OiQQPWFvbBYEtTRwACXeNXnHy9Tk/IkYD//XHEkgUOkNzkdTkGh/QUz2KKrRBE0Ic=@vger.kernel.org X-Gm-Message-State: AOJu0YydqSzq56Mer5jXPh8vToed+5ywdgb8ZGfGvLd3kvAjwimkWtLq 6gtLdGjl/pFtZQncyZUtPnLavrPt1g5OXs4D11Gyyz88pkHTJOVWwewX0zlIuZJMVbx/EXxvRdw /PK1EdMhDN2EdXOW3t0Xxew2F0lAJaHZuSfC7Ddhq8Hvypu27ug== X-Received: by 2002:a05:600c:468a:b0:428:b4a:7001 with SMTP id 5b1f17b1804b1-42c95be865emr55954425e9.15.1725616347147; Fri, 06 Sep 2024 02:52:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEAzjIbOhY0yl5ABAsozjpxMGlePH4FD0Zgd3LEMcGMp/X5jhGJ5bKacT+G2O0mgJRKlVceNA== X-Received: by 2002:a05:600c:468a:b0:428:b4a:7001 with SMTP id 5b1f17b1804b1-42c95be865emr55954205e9.15.1725616346621; Fri, 06 Sep 2024 02:52:26 -0700 (PDT) Received: from redhat.com ([155.133.17.165]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42ca05d925dsm14786045e9.39.2024.09.06.02.52.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 02:52:24 -0700 (PDT) Date: Fri, 6 Sep 2024 05:52:21 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Xuan Zhuo , Jason Wang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , virtualization@lists.linux.dev, Si-Wei Liu , Darren Kenny , Boris Ostrovsky , Eugenio =?utf-8?b?UMOpcmV6?= , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , bpf@vger.kernel.org Subject: [RFC PATCH v2 2/7] Revert "virtio_net: xsk: rx: support recv small mode" Message-ID: <6838211b8b864c757204a2bfd1ad3ffc7aa42e52.1725616135.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This reverts commit a4e7ba7027012f009f22a68bcfde670f9298d3a4. leads to crashes with no ACCESS_PLATFORM when sysctl net.core.high_order_alloc_disable=1 Cc: Xuan Zhuo Reported-by: Si-Wei Liu Signed-off-by: Michael S. Tsirkin --- drivers/net/virtio_net.c | 198 ++++----------------------------------- 1 file changed, 19 insertions(+), 179 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 15e202dd6964..041c483a06c5 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -498,12 +498,6 @@ struct virtio_net_common_hdr { }; static void virtnet_sq_free_unused_buf(struct virtqueue *vq, void *buf); -static int virtnet_xdp_handler(struct bpf_prog *xdp_prog, struct xdp_buff *xdp, - struct net_device *dev, - unsigned int *xdp_xmit, - struct virtnet_rq_stats *stats); -static void virtnet_receive_done(struct virtnet_info *vi, struct receive_queue *rq, - struct sk_buff *skb, u8 flags); static bool is_xdp_frame(void *ptr) { @@ -1068,124 +1062,6 @@ static void sg_fill_dma(struct scatterlist *sg, dma_addr_t addr, u32 len) sg->length = len; } -static struct xdp_buff *buf_to_xdp(struct virtnet_info *vi, - struct receive_queue *rq, void *buf, u32 len) -{ - struct xdp_buff *xdp; - u32 bufsize; - - xdp = (struct xdp_buff *)buf; - - bufsize = xsk_pool_get_rx_frame_size(rq->xsk_pool) + vi->hdr_len; - - if (unlikely(len > bufsize)) { - pr_debug("%s: rx error: len %u exceeds truesize %u\n", - vi->dev->name, len, bufsize); - DEV_STATS_INC(vi->dev, rx_length_errors); - xsk_buff_free(xdp); - return NULL; - } - - xsk_buff_set_size(xdp, len); - xsk_buff_dma_sync_for_cpu(xdp); - - return xdp; -} - -static struct sk_buff *xsk_construct_skb(struct receive_queue *rq, - struct xdp_buff *xdp) -{ - unsigned int metasize = xdp->data - xdp->data_meta; - struct sk_buff *skb; - unsigned int size; - - size = xdp->data_end - xdp->data_hard_start; - skb = napi_alloc_skb(&rq->napi, size); - if (unlikely(!skb)) { - xsk_buff_free(xdp); - return NULL; - } - - skb_reserve(skb, xdp->data_meta - xdp->data_hard_start); - - size = xdp->data_end - xdp->data_meta; - memcpy(__skb_put(skb, size), xdp->data_meta, size); - - if (metasize) { - __skb_pull(skb, metasize); - skb_metadata_set(skb, metasize); - } - - xsk_buff_free(xdp); - - return skb; -} - -static struct sk_buff *virtnet_receive_xsk_small(struct net_device *dev, struct virtnet_info *vi, - struct receive_queue *rq, struct xdp_buff *xdp, - unsigned int *xdp_xmit, - struct virtnet_rq_stats *stats) -{ - struct bpf_prog *prog; - u32 ret; - - ret = XDP_PASS; - rcu_read_lock(); - prog = rcu_dereference(rq->xdp_prog); - if (prog) - ret = virtnet_xdp_handler(prog, xdp, dev, xdp_xmit, stats); - rcu_read_unlock(); - - switch (ret) { - case XDP_PASS: - return xsk_construct_skb(rq, xdp); - - case XDP_TX: - case XDP_REDIRECT: - return NULL; - - default: - /* drop packet */ - xsk_buff_free(xdp); - u64_stats_inc(&stats->drops); - return NULL; - } -} - -static void virtnet_receive_xsk_buf(struct virtnet_info *vi, struct receive_queue *rq, - void *buf, u32 len, - unsigned int *xdp_xmit, - struct virtnet_rq_stats *stats) -{ - struct net_device *dev = vi->dev; - struct sk_buff *skb = NULL; - struct xdp_buff *xdp; - u8 flags; - - len -= vi->hdr_len; - - u64_stats_add(&stats->bytes, len); - - xdp = buf_to_xdp(vi, rq, buf, len); - if (!xdp) - return; - - if (unlikely(len < ETH_HLEN)) { - pr_debug("%s: short packet %i\n", dev->name, len); - DEV_STATS_INC(dev, rx_length_errors); - xsk_buff_free(xdp); - return; - } - - flags = ((struct virtio_net_common_hdr *)(xdp->data - vi->hdr_len))->hdr.flags; - - if (!vi->mergeable_rx_bufs) - skb = virtnet_receive_xsk_small(dev, vi, rq, xdp, xdp_xmit, stats); - - if (skb) - virtnet_receive_done(vi, rq, skb, flags); -} - static int virtnet_add_recvbuf_xsk(struct virtnet_info *vi, struct receive_queue *rq, struct xsk_buff_pool *pool, gfp_t gfp) { @@ -2516,67 +2392,31 @@ static void refill_work(struct work_struct *work) } } -static int virtnet_receive_xsk_bufs(struct virtnet_info *vi, - struct receive_queue *rq, - int budget, - unsigned int *xdp_xmit, - struct virtnet_rq_stats *stats) -{ - unsigned int len; - int packets = 0; - void *buf; - - while (packets < budget) { - buf = virtqueue_get_buf(rq->vq, &len); - if (!buf) - break; - - virtnet_receive_xsk_buf(vi, rq, buf, len, xdp_xmit, stats); - packets++; - } - - return packets; -} - -static int virtnet_receive_packets(struct virtnet_info *vi, - struct receive_queue *rq, - int budget, - unsigned int *xdp_xmit, - struct virtnet_rq_stats *stats) -{ - unsigned int len; - int packets = 0; - void *buf; - - if (!vi->big_packets || vi->mergeable_rx_bufs) { - void *ctx; - while (packets < budget && - (buf = virtnet_rq_get_buf(rq, &len, &ctx))) { - receive_buf(vi, rq, buf, len, ctx, xdp_xmit, stats); - packets++; - } - } else { - while (packets < budget && - (buf = virtqueue_get_buf(rq->vq, &len)) != NULL) { - receive_buf(vi, rq, buf, len, NULL, xdp_xmit, stats); - packets++; - } - } - - return packets; -} - static int virtnet_receive(struct receive_queue *rq, int budget, unsigned int *xdp_xmit) { struct virtnet_info *vi = rq->vq->vdev->priv; struct virtnet_rq_stats stats = {}; - int i, packets; + unsigned int len; + int packets = 0; + void *buf; + int i; - if (rq->xsk_pool) - packets = virtnet_receive_xsk_bufs(vi, rq, budget, xdp_xmit, &stats); - else - packets = virtnet_receive_packets(vi, rq, budget, xdp_xmit, &stats); + if (!vi->big_packets || vi->mergeable_rx_bufs) { + void *ctx; + + while (packets < budget && + (buf = virtnet_rq_get_buf(rq, &len, &ctx))) { + receive_buf(vi, rq, buf, len, ctx, xdp_xmit, &stats); + packets++; + } + } else { + while (packets < budget && + (buf = virtqueue_get_buf(rq->vq, &len)) != NULL) { + receive_buf(vi, rq, buf, len, NULL, xdp_xmit, &stats); + packets++; + } + } if (rq->vq->num_free > min((unsigned int)budget, virtqueue_get_vring_size(rq->vq)) / 2) { if (!try_fill_recv(vi, rq, GFP_ATOMIC)) { From patchwork Fri Sep 6 09:52:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13793827 X-Patchwork-Delegate: kuba@kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 779741C9DFE for ; Fri, 6 Sep 2024 09:52:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725616357; cv=none; b=Q8z/gSIoSNtXVvJ/rvsUhkUKAw2lI81hU34tVQ8qHppXJ8HA+zawybjacbZsCgC9YWMvM8kjVM4xRYmV8PA6ABDWWVeUXP1getAXLXMALiEZCLiF7YzDB6BYYLVAKHY/+Jata5pWA7Ub919ezKiiRzoo0O40OIETLyS3jtNqQbo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725616357; c=relaxed/simple; bh=dCHcn/1FgMWhuuHVvEWKLUbibFBqHz7uA0Xt+uzcciM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FE3p9Ti5TTgSE/hrZSq8c8WEFxMhV2mU7Sitkpwg1RRbAe+HcvUAPx+pLOmEXeS3X1eZEPVqAW/gwgh2BmhhyDtYd0zGQC76im/wSS9maTDhJE3bhkfKyib7XFwrHJIPgzqLwTyl1hxKXknE4ez1GvVTJTN/fRIIf7mXaDms4H4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=iZ58DOvE; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iZ58DOvE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725616354; h=from:from:reply-to:subject:subject: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=8H99B9KUPJW7l1/czX9Tp6t+iue87wNuoi4+eOXBhL0=; b=iZ58DOvEYptrYhELD1PIhma+iZOsioKenGRMRNinI6ugMvp1/pZdNnpljCQTLbhB5JVTG7 5WFlvtKqINQMUXq3Xs9Ub0B+71pjMVBV28IVKXetA4fsWrzMaX0obBJ+lyjD5qnXo+kzWD suTeJt5jJf7tHZx0nvbjqiW3UhHtch8= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-680-8WKdBfzFOM-1UqXk46aqfg-1; Fri, 06 Sep 2024 05:52:33 -0400 X-MC-Unique: 8WKdBfzFOM-1UqXk46aqfg-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3771b6da3ceso1088711f8f.3 for ; Fri, 06 Sep 2024 02:52:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725616352; x=1726221152; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8H99B9KUPJW7l1/czX9Tp6t+iue87wNuoi4+eOXBhL0=; b=tfjzngmK+rdzaUQDx/ORJxY/XIzyytOa3s0cXml/V2PpQCW+yIHofq9HCrUVp5F5wZ HfGHqw0DKLyNndo5ThcOvfEeFspMzzCD2B+DKrPpknStOCYHmNPWgp176PQ8hSL4bnAY 4RgobG+XKGAJf9UieqW2Cu0qIRHRlEzG+07AhW2NneQPwZeFDOl2ZUOpU+UnwxWl809A XBZk9KtEzuXQ5yDeiAyktVxCfD5whCHeIzIjMopQJxVbcGQaiFVpioABwXm+k4DEIRIN Y+JwMoJ/hq/RdPZp330TS1vqvBIPif3skGYYIazn+7Dg+OLOSw31vAswTB2st29nz7Op wymA== X-Forwarded-Encrypted: i=1; AJvYcCXnRYyF2yaOHB1nPspWlvrLqu1gtgL4zb8Qgf2UBSRuXPKPpXH8+19R7Upk4d0TjaHOv6o=@vger.kernel.org X-Gm-Message-State: AOJu0YytQAKEFOxh7c0M1tMUa19MQBMOmBeBa6psB8OG0NdeLTv4krzK TVQCxpaQ/IDdrJwpSifpX/A5bv503cIggZijA9DAMVIMRUsLSk5S4wTSGJzPOZrb7aAX40bIJcl CytIvyfV76S7YhPXo83sXRMgSdIGH85QMjvINWusmzf3FAUxVrw== X-Received: by 2002:a05:6000:18a7:b0:376:7a68:bc42 with SMTP id ffacd0b85a97d-3767a68c23dmr9293275f8f.27.1725616352183; Fri, 06 Sep 2024 02:52:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEFIF65gKfiZPFBH5iQEaBnXgeO1FhuaZdZ4FK0I9pUsn3NYiq1dGZhLD2zESCViTEQMrN15g== X-Received: by 2002:a05:6000:18a7:b0:376:7a68:bc42 with SMTP id ffacd0b85a97d-3767a68c23dmr9293241f8f.27.1725616351706; Fri, 06 Sep 2024 02:52:31 -0700 (PDT) Received: from redhat.com ([155.133.17.165]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42ca0606984sm14793275e9.40.2024.09.06.02.52.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 02:52:31 -0700 (PDT) Date: Fri, 6 Sep 2024 05:52:26 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Xuan Zhuo , Jason Wang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , virtualization@lists.linux.dev, Si-Wei Liu , Darren Kenny , Boris Ostrovsky , Eugenio =?utf-8?b?UMOpcmV6?= , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , bpf@vger.kernel.org Subject: [RFC PATCH v2 3/7] Revert "virtio_net: xsk: rx: support fill with xsk buffer" Message-ID: <9559b3ff39bbe94bb81caf2e6c1e464eea0e9de9.1725616135.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This reverts commit e9f3962441c0a4d6f16c656e6c8aa02a3ccdd568. leads to crashes with no ACCESS_PLATFORM when sysctl net.core.high_order_alloc_disable=1 Cc: Xuan Zhuo Reported-by: Si-Wei Liu Signed-off-by: Michael S. Tsirkin --- drivers/net/virtio_net.c | 70 +++------------------------------------- 1 file changed, 4 insertions(+), 66 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 041c483a06c5..3cb0f8adf2e6 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -354,8 +354,6 @@ struct receive_queue { /* xdp rxq used by xsk */ struct xdp_rxq_info xsk_rxq_info; - - struct xdp_buff **xsk_buffs; }; /* This structure can contain rss message with maximum settings for indirection table and keysize @@ -1056,53 +1054,6 @@ static void check_sq_full_and_disable(struct virtnet_info *vi, } } -static void sg_fill_dma(struct scatterlist *sg, dma_addr_t addr, u32 len) -{ - sg->dma_address = addr; - sg->length = len; -} - -static int virtnet_add_recvbuf_xsk(struct virtnet_info *vi, struct receive_queue *rq, - struct xsk_buff_pool *pool, gfp_t gfp) -{ - struct xdp_buff **xsk_buffs; - dma_addr_t addr; - int err = 0; - u32 len, i; - int num; - - xsk_buffs = rq->xsk_buffs; - - num = xsk_buff_alloc_batch(pool, xsk_buffs, rq->vq->num_free); - if (!num) - return -ENOMEM; - - len = xsk_pool_get_rx_frame_size(pool) + vi->hdr_len; - - for (i = 0; i < num; ++i) { - /* Use the part of XDP_PACKET_HEADROOM as the virtnet hdr space. - * We assume XDP_PACKET_HEADROOM is larger than hdr->len. - * (see function virtnet_xsk_pool_enable) - */ - addr = xsk_buff_xdp_get_dma(xsk_buffs[i]) - vi->hdr_len; - - sg_init_table(rq->sg, 1); - sg_fill_dma(rq->sg, addr, len); - - err = virtqueue_add_inbuf(rq->vq, rq->sg, 1, xsk_buffs[i], gfp); - if (err) - goto err; - } - - return num; - -err: - for (; i < num; ++i) - xsk_buff_free(xsk_buffs[i]); - - return err; -} - static int virtnet_xsk_wakeup(struct net_device *dev, u32 qid, u32 flag) { struct virtnet_info *vi = netdev_priv(dev); @@ -2294,11 +2245,7 @@ static bool try_fill_recv(struct virtnet_info *vi, struct receive_queue *rq, gfp_t gfp) { int err; - - if (rq->xsk_pool) { - err = virtnet_add_recvbuf_xsk(vi, rq, rq->xsk_pool, gfp); - goto kick; - } + bool oom; do { if (vi->mergeable_rx_bufs) @@ -2308,11 +2255,10 @@ static bool try_fill_recv(struct virtnet_info *vi, struct receive_queue *rq, else err = add_recvbuf_small(vi, rq, gfp); + oom = err == -ENOMEM; if (err) break; } while (rq->vq->num_free); - -kick: if (virtqueue_kick_prepare(rq->vq) && virtqueue_notify(rq->vq)) { unsigned long flags; @@ -2321,7 +2267,7 @@ static bool try_fill_recv(struct virtnet_info *vi, struct receive_queue *rq, u64_stats_update_end_irqrestore(&rq->stats.syncp, flags); } - return err != -ENOMEM; + return !oom; } static void skb_recv_done(struct virtqueue *rvq) @@ -5168,7 +5114,7 @@ static int virtnet_xsk_pool_enable(struct net_device *dev, struct receive_queue *rq; struct device *dma_dev; struct send_queue *sq; - int err, size; + int err; if (vi->hdr_len > xsk_pool_get_headroom(pool)) return -EINVAL; @@ -5199,12 +5145,6 @@ static int virtnet_xsk_pool_enable(struct net_device *dev, if (!dma_dev) return -EINVAL; - size = virtqueue_get_vring_size(rq->vq); - - rq->xsk_buffs = kvcalloc(size, sizeof(*rq->xsk_buffs), GFP_KERNEL); - if (!rq->xsk_buffs) - return -ENOMEM; - err = xsk_pool_dma_map(pool, dma_dev, 0); if (err) goto err_xsk_map; @@ -5239,8 +5179,6 @@ static int virtnet_xsk_pool_disable(struct net_device *dev, u16 qid) xsk_pool_dma_unmap(pool, 0); - kvfree(rq->xsk_buffs); - return err; } From patchwork Fri Sep 6 09:52:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13793828 X-Patchwork-Delegate: kuba@kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3F325C603 for ; Fri, 6 Sep 2024 09:52:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725616361; cv=none; b=TPahbGETgsqyMKA2X2q8Il/S4hyPRHwtDqJojzlldsq42SSwhoo9bNV/oOToTXvKoD1cYES8BsNF94oT/sAbyTVYZVS+iIpHy3HmCRxx9wO6PE1RG/OjAX0YQ84KAB3CH0YHf9nNcydEjK6vtGopOLAruPDTw0LyXyRx+WXpw64= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725616361; c=relaxed/simple; bh=nWO4hB6PBG1t9aSNmguYJznkt6bwH8E+U9bsso6Id7c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QZBPLu52z9sKvKVVfi6Uk3+n3L3rcy0fvv2EhWxNy9zAUdmg/Lr+YzsDIWsJGdqn/N0KX3ziUXiWKBx7YMNAb7puEiiHG3jLg6wfuR99WuyOkvWoXYVzJug8cL+Q+ydeGdn1owmEVf6+azIrY6ypROcjyi1XkI4f7ttr/bBDKhM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=CDsz+Cmo; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CDsz+Cmo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725616358; h=from:from:reply-to:subject:subject: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=mrSfru2lWTmJ7ntOOD4Zd3IGqv+cr43dsZNB2qiF4RM=; b=CDsz+CmopsZEktXtrjIxf0/jL6UnxeEEgDn9Dc7ArNt3/ceeOIk4SP0d3jRrPgNlNnkoDe ch6Kn5dy4JMboWVi2ghp6P4KyGN5n49Ckrpi+JIiCyniJbFlMTGuyAwYAUVSK6JT/OOqOj V2g4n7k7M+LKC0RhCMGSzAf8vhIRtpQ= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-630-k-7dWos7NNOxW5467pt7fQ-1; Fri, 06 Sep 2024 05:52:37 -0400 X-MC-Unique: k-7dWos7NNOxW5467pt7fQ-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-374b9617ab0so1107684f8f.3 for ; Fri, 06 Sep 2024 02:52:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725616357; x=1726221157; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=mrSfru2lWTmJ7ntOOD4Zd3IGqv+cr43dsZNB2qiF4RM=; b=LZwLQmDXRqFoZpgOELL1tG8fU73PUjEXyplokRL1Wh7Kkrego/tBYP+pY4a+ElQzQi dLBNryEzsb/oFDEszgvLc3mJBN1y0QW78s9qBkz3LA/sZJo36Wba3bCPxqMhB9x22/sk u7iPdrN5kO6to/AFG4E0UKHI4wvI4rtxCIhLR5Id+1IYaNc+vrGvxDpV/UESNreZCfzT C/rWXZvk8fLlbrKKanyGubNJsRtx9EWd0jXWRlgh0zoznOnhrzlD5iuOiy8xEOfyMvT8 N+bACsPbZCL8F9to9NQf1cMXOXDU+u4Mn8CzGLdEpnOGtQpEVO3srJF9+yNK19q1n8iI oI0g== X-Forwarded-Encrypted: i=1; AJvYcCVW87jirixsVsCHuD9HScauEHQLAoQIZL5mvJ2GNlElL28HKj5LL2CYDhxAoJoPMPx+KaU=@vger.kernel.org X-Gm-Message-State: AOJu0YxQxvN1O6+GV0e/qdpGPLTfQGrDlP9S/11TYlQ2iy151Zob3FC5 ghYU81aRMZMb2xdtK+GTCAi8hwNHHpUUj0F44C+Tyr+Dt68pm9qWD6VxEjeKzxLMQ9RJgAkUjKt SNBIB/yTiG2eZMnVgDSJ7YSieNVwSZytLt8PpI9KyScRCJR+Nsg== X-Received: by 2002:a5d:5e12:0:b0:374:b685:672 with SMTP id ffacd0b85a97d-374b6850721mr12179530f8f.26.1725616356559; Fri, 06 Sep 2024 02:52:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEy9H2fY+IdgasPGdCkAErAN464kou0VTksRkihXRxCSa5S0om1fP+DF92pWZQwo6psBMtuqw== X-Received: by 2002:a5d:5e12:0:b0:374:b685:672 with SMTP id ffacd0b85a97d-374b6850721mr12179503f8f.26.1725616355994; Fri, 06 Sep 2024 02:52:35 -0700 (PDT) Received: from redhat.com ([155.133.17.165]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3749ee9c48csm21348537f8f.51.2024.09.06.02.52.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 02:52:35 -0700 (PDT) Date: Fri, 6 Sep 2024 05:52:31 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Xuan Zhuo , Jason Wang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , virtualization@lists.linux.dev, Si-Wei Liu , Darren Kenny , Boris Ostrovsky , Eugenio =?utf-8?b?UMOpcmV6?= , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , bpf@vger.kernel.org Subject: [RFC PATCH v2 4/7] Revert "virtio_net: xsk: bind/unbind xsk for rx" Message-ID: <3f9f2c4be3d84f38ab5878494bfd91be01d18432.1725616135.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This reverts commit 09d2b3182c8e3a215a9b2a1834f81dd07305989f. leads to crashes with no ACCESS_PLATFORM when sysctl net.core.high_order_alloc_disable=1 Cc: Xuan Zhuo Reported-by: Si-Wei Liu Signed-off-by: Michael S. Tsirkin --- drivers/net/virtio_net.c | 134 --------------------------------------- 1 file changed, 134 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 3cb0f8adf2e6..0944430dfb1f 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -25,7 +25,6 @@ #include #include #include -#include static int napi_weight = NAPI_POLL_WEIGHT; module_param(napi_weight, int, 0444); @@ -349,11 +348,6 @@ struct receive_queue { /* Record the last dma info to free after new pages is allocated. */ struct virtnet_rq_dma *last_dma; - - struct xsk_buff_pool *xsk_pool; - - /* xdp rxq used by xsk */ - struct xdp_rxq_info xsk_rxq_info; }; /* This structure can contain rss message with maximum settings for indirection table and keysize @@ -5065,132 +5059,6 @@ static int virtnet_restore_guest_offloads(struct virtnet_info *vi) return virtnet_set_guest_offloads(vi, offloads); } -static int virtnet_rq_bind_xsk_pool(struct virtnet_info *vi, struct receive_queue *rq, - struct xsk_buff_pool *pool) -{ - int err, qindex; - - qindex = rq - vi->rq; - - if (pool) { - err = xdp_rxq_info_reg(&rq->xsk_rxq_info, vi->dev, qindex, rq->napi.napi_id); - if (err < 0) - return err; - - err = xdp_rxq_info_reg_mem_model(&rq->xsk_rxq_info, - MEM_TYPE_XSK_BUFF_POOL, NULL); - if (err < 0) - goto unreg; - - xsk_pool_set_rxq_info(pool, &rq->xsk_rxq_info); - } - - virtnet_rx_pause(vi, rq); - - err = virtqueue_reset(rq->vq, virtnet_rq_unmap_free_buf); - if (err) { - netdev_err(vi->dev, "reset rx fail: rx queue index: %d err: %d\n", qindex, err); - - pool = NULL; - } - - rq->xsk_pool = pool; - - virtnet_rx_resume(vi, rq); - - if (pool) - return 0; - -unreg: - xdp_rxq_info_unreg(&rq->xsk_rxq_info); - return err; -} - -static int virtnet_xsk_pool_enable(struct net_device *dev, - struct xsk_buff_pool *pool, - u16 qid) -{ - struct virtnet_info *vi = netdev_priv(dev); - struct receive_queue *rq; - struct device *dma_dev; - struct send_queue *sq; - int err; - - if (vi->hdr_len > xsk_pool_get_headroom(pool)) - return -EINVAL; - - /* In big_packets mode, xdp cannot work, so there is no need to - * initialize xsk of rq. - */ - if (vi->big_packets && !vi->mergeable_rx_bufs) - return -ENOENT; - - if (qid >= vi->curr_queue_pairs) - return -EINVAL; - - sq = &vi->sq[qid]; - rq = &vi->rq[qid]; - - /* xsk assumes that tx and rx must have the same dma device. The af-xdp - * may use one buffer to receive from the rx and reuse this buffer to - * send by the tx. So the dma dev of sq and rq must be the same one. - * - * But vq->dma_dev allows every vq has the respective dma dev. So I - * check the dma dev of vq and sq is the same dev. - */ - if (virtqueue_dma_dev(rq->vq) != virtqueue_dma_dev(sq->vq)) - return -EINVAL; - - dma_dev = virtqueue_dma_dev(rq->vq); - if (!dma_dev) - return -EINVAL; - - err = xsk_pool_dma_map(pool, dma_dev, 0); - if (err) - goto err_xsk_map; - - err = virtnet_rq_bind_xsk_pool(vi, rq, pool); - if (err) - goto err_rq; - - return 0; - -err_rq: - xsk_pool_dma_unmap(pool, 0); -err_xsk_map: - return err; -} - -static int virtnet_xsk_pool_disable(struct net_device *dev, u16 qid) -{ - struct virtnet_info *vi = netdev_priv(dev); - struct xsk_buff_pool *pool; - struct receive_queue *rq; - int err; - - if (qid >= vi->curr_queue_pairs) - return -EINVAL; - - rq = &vi->rq[qid]; - - pool = rq->xsk_pool; - - err = virtnet_rq_bind_xsk_pool(vi, rq, NULL); - - xsk_pool_dma_unmap(pool, 0); - - return err; -} - -static int virtnet_xsk_pool_setup(struct net_device *dev, struct netdev_bpf *xdp) -{ - if (xdp->xsk.pool) - return virtnet_xsk_pool_enable(dev, xdp->xsk.pool, - xdp->xsk.queue_id); - else - return virtnet_xsk_pool_disable(dev, xdp->xsk.queue_id); -} - static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog, struct netlink_ext_ack *extack) { @@ -5316,8 +5184,6 @@ static int virtnet_xdp(struct net_device *dev, struct netdev_bpf *xdp) switch (xdp->command) { case XDP_SETUP_PROG: return virtnet_xdp_set(dev, xdp->prog, xdp->extack); - case XDP_SETUP_XSK_POOL: - return virtnet_xsk_pool_setup(dev, xdp); default: return -EINVAL; } From patchwork Fri Sep 6 09:52:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13793835 X-Patchwork-Delegate: kuba@kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E76D1CB147 for ; Fri, 6 Sep 2024 09:52:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725616365; cv=none; b=lbnTIfsp/SDqtSKPDEECP/eb+kbT74N206NqEJvVwjhAIIBwYDnXq9nJixHwcTW5EVnh1iVc8oh9sr0DOIn9aeLSUha22c0byXS8kdvyZ3RaSFdjl41oICCqo9j25rALmJ2gZgjFGicYuXExyUOI5Bv2CCkUZrBY/zQxB3/MP8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725616365; c=relaxed/simple; bh=fnNO00Sl3L0ct2dB2f93woTB2J1hByHs/OImvIYoPQo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kvTyi+udxGFab5+oD9/czNBnTrSzo2pbxqP2yJr91ce+i3tlNnRlTLmSqse6jijtlQDy4c5fmRiMBYjM7zEwYsHWDfWQibRIqfM1Sqtsyq0qma4QofQqxBj2l+hAHt6wN2+Tyw+mzHwbu98zJUWoOrY2wyLuxTXr1eM/qiQ/nLg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=THxcTmHK; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="THxcTmHK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725616363; h=from:from:reply-to:subject:subject: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=SiA0MhlHaW5Sr2cHC/L9B039T74TheX16DO6mIEzrLM=; b=THxcTmHKbr9oGQ3HkSbhP+dUZnp9BgQjaHTNrwWs6JJsBy3w1tAyiHypEo3ow+EKrNTyj2 QTALXRRpA+rMxaCdSdCNT4v9cHxkvpzgApR26++zBnz4knkXz6RpsdsWfot1nRORYfSMaf UufLOrKfI9qn/6B3nQhf0JymfH0Rbqs= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-83-wT6qDiX2OGuvDWuCKbE4_A-1; Fri, 06 Sep 2024 05:52:42 -0400 X-MC-Unique: wT6qDiX2OGuvDWuCKbE4_A-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-42bac946976so14618925e9.2 for ; Fri, 06 Sep 2024 02:52:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725616360; x=1726221160; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=SiA0MhlHaW5Sr2cHC/L9B039T74TheX16DO6mIEzrLM=; b=g3navbU6zNCediKIqJqmG07JOTW95sI6JOzfrlUE2UoTWEvP+mIXXwre06ZVNYCRRq 1+rQBX/4O/3a1HI/TzVwJI9p0IGKkSc22H1tXDPoAGJUNf/ou00Ji1YvLfOMzKtLtaKv Ax5VLG3uCi9hEnySZ7yOUXTu/v4i/V5kg6feIbsnXCWbW+gXVbvOScjP616fpGcW/Nzh gban4kD+8PgSh8wUgsYcAW0JUR09eQoOaU0kUFux/xZZowh7vFwcuW5wCcJgnz0wNETc lR27QmHoXW8FtQP325R2xSe3mPyLdUFHXoM/gO0h/GvyM6WGVS93KMrYHPHZ5nTzJx8P vEzQ== X-Forwarded-Encrypted: i=1; AJvYcCVwRV7kjkx6BI9UhGxUvCF8ygnDqUy4YhKG/29Fnb1+nxjxzNFhemC5HV+tZQ7F5C5RDOBhVTw=@vger.kernel.org X-Gm-Message-State: AOJu0YyK49FiGyGbi1ckVxa2QSFvGCyLjXyrn/QXdu3s6JlPhomwlcF9 mhevAcvlDMepWee976+A5YrumO4QaxqT8QSkc9iYPgrlalXcfCr7wQ+fnp2FVYTdEkW1VNVWcTG 09JRNx6Xg3Fh4EB4OjOpkia27LMOoVKA6GmdF53KIYdTQTr4B4PdDTDGFki8G/k6n X-Received: by 2002:a05:6000:785:b0:378:80c8:57a with SMTP id ffacd0b85a97d-37880c807bdmr4669431f8f.9.1725616360522; Fri, 06 Sep 2024 02:52:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEDAqymEkxUqG9asen2sDEFG8aZbMqUOUYx8yF9vb6IyZR1cQeui5rUo3L6/Clt8B1jcSujSA== X-Received: by 2002:a05:6000:785:b0:378:80c8:57a with SMTP id ffacd0b85a97d-37880c807bdmr4669393f8f.9.1725616359931; Fri, 06 Sep 2024 02:52:39 -0700 (PDT) Received: from redhat.com ([155.133.17.165]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42ca2cfc296sm9182305e9.36.2024.09.06.02.52.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 02:52:39 -0700 (PDT) Date: Fri, 6 Sep 2024 05:52:36 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Xuan Zhuo , Jason Wang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , virtualization@lists.linux.dev, Si-Wei Liu , Darren Kenny , Boris Ostrovsky , Eugenio =?utf-8?b?UMOpcmV6?= Subject: [RFC PATCH v2 5/7] Revert "virtio_net: rx remove premapped failover code" Message-ID: <69d3032b6560323844d6d9fb0ac4f832ed87f13d.1725616135.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This reverts commit defd28aa5acb0fd7c15adc6bc40a8ac277d04dea. leads to crashes with no ACCESS_PLATFORM when sysctl net.core.high_order_alloc_disable=1 Cc: Xuan Zhuo Reported-by: Si-Wei Liu Signed-off-by: Michael S. Tsirkin --- drivers/net/virtio_net.c | 89 +++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 37 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 0944430dfb1f..0a2ec9570521 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -348,6 +348,9 @@ struct receive_queue { /* Record the last dma info to free after new pages is allocated. */ struct virtnet_rq_dma *last_dma; + + /* Do dma by self */ + bool do_dma; }; /* This structure can contain rss message with maximum settings for indirection table and keysize @@ -867,7 +870,7 @@ static void *virtnet_rq_get_buf(struct receive_queue *rq, u32 *len, void **ctx) void *buf; buf = virtqueue_get_buf_ctx(rq->vq, len, ctx); - if (buf) + if (buf && rq->do_dma) virtnet_rq_unmap(rq, buf, *len); return buf; @@ -880,6 +883,11 @@ static void virtnet_rq_init_one_sg(struct receive_queue *rq, void *buf, u32 len) u32 offset; void *head; + if (!rq->do_dma) { + sg_init_one(rq->sg, buf, len); + return; + } + head = page_address(rq->alloc_frag.page); offset = buf - head; @@ -905,42 +913,44 @@ static void *virtnet_rq_alloc(struct receive_queue *rq, u32 size, gfp_t gfp) head = page_address(alloc_frag->page); - dma = head; + if (rq->do_dma) { + dma = head; - /* new pages */ - if (!alloc_frag->offset) { - if (rq->last_dma) { - /* Now, the new page is allocated, the last dma - * will not be used. So the dma can be unmapped - * if the ref is 0. + /* new pages */ + if (!alloc_frag->offset) { + if (rq->last_dma) { + /* Now, the new page is allocated, the last dma + * will not be used. So the dma can be unmapped + * if the ref is 0. + */ + virtnet_rq_unmap(rq, rq->last_dma, 0); + rq->last_dma = NULL; + } + + dma->len = alloc_frag->size - sizeof(*dma); + + addr = virtqueue_dma_map_single_attrs(rq->vq, dma + 1, + dma->len, DMA_FROM_DEVICE, 0); + if (virtqueue_dma_mapping_error(rq->vq, addr)) + return NULL; + + dma->addr = addr; + dma->need_sync = virtqueue_dma_need_sync(rq->vq, addr); + + /* Add a reference to dma to prevent the entire dma from + * being released during error handling. This reference + * will be freed after the pages are no longer used. */ - virtnet_rq_unmap(rq, rq->last_dma, 0); - rq->last_dma = NULL; + get_page(alloc_frag->page); + dma->ref = 1; + alloc_frag->offset = sizeof(*dma); + + rq->last_dma = dma; } - dma->len = alloc_frag->size - sizeof(*dma); - - addr = virtqueue_dma_map_single_attrs(rq->vq, dma + 1, - dma->len, DMA_FROM_DEVICE, 0); - if (virtqueue_dma_mapping_error(rq->vq, addr)) - return NULL; - - dma->addr = addr; - dma->need_sync = virtqueue_dma_need_sync(rq->vq, addr); - - /* Add a reference to dma to prevent the entire dma from - * being released during error handling. This reference - * will be freed after the pages are no longer used. - */ - get_page(alloc_frag->page); - dma->ref = 1; - alloc_frag->offset = sizeof(*dma); - - rq->last_dma = dma; + ++dma->ref; } - ++dma->ref; - buf = head + alloc_frag->offset; get_page(alloc_frag->page); @@ -957,9 +967,12 @@ static void virtnet_rq_set_premapped(struct virtnet_info *vi) if (!vi->mergeable_rx_bufs && vi->big_packets) return; - for (i = 0; i < vi->max_queue_pairs; i++) - /* error should never happen */ - BUG_ON(virtqueue_set_dma_premapped(vi->rq[i].vq)); + for (i = 0; i < vi->max_queue_pairs; i++) { + if (virtqueue_set_dma_premapped(vi->rq[i].vq)) + continue; + + vi->rq[i].do_dma = true; + } } static void virtnet_rq_unmap_free_buf(struct virtqueue *vq, void *buf) @@ -2107,7 +2120,8 @@ static int add_recvbuf_small(struct virtnet_info *vi, struct receive_queue *rq, err = virtqueue_add_inbuf_ctx(rq->vq, rq->sg, 1, buf, ctx, gfp); if (err < 0) { - virtnet_rq_unmap(rq, buf, 0); + if (rq->do_dma) + virtnet_rq_unmap(rq, buf, 0); put_page(virt_to_head_page(buf)); } @@ -2221,7 +2235,8 @@ static int add_recvbuf_mergeable(struct virtnet_info *vi, ctx = mergeable_len_to_ctx(len + room, headroom); err = virtqueue_add_inbuf_ctx(rq->vq, rq->sg, 1, buf, ctx, gfp); if (err < 0) { - virtnet_rq_unmap(rq, buf, 0); + if (rq->do_dma) + virtnet_rq_unmap(rq, buf, 0); put_page(virt_to_head_page(buf)); } @@ -5392,7 +5407,7 @@ static void free_receive_page_frags(struct virtnet_info *vi) int i; for (i = 0; i < vi->max_queue_pairs; i++) if (vi->rq[i].alloc_frag.page) { - if (vi->rq[i].last_dma) + if (vi->rq[i].do_dma && vi->rq[i].last_dma) virtnet_rq_unmap(&vi->rq[i], vi->rq[i].last_dma, 0); put_page(vi->rq[i].alloc_frag.page); } From patchwork Fri Sep 6 09:52:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13793837 X-Patchwork-Delegate: kuba@kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CF411C8FBB for ; Fri, 6 Sep 2024 09:52:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725616379; cv=none; b=kFY1ATtDfU2eA160U4rQeckIk8SoAD8sqjEi9okIQdx+0zD0tCV8d1yFUFTUlYuRQVxTGZto9IQC+nv7mgaWgJlgREvkA5ivleUzBqGK1odOrV6xtcIq6YSc/khjy/uQKTWMoafM+82B67mf8v0TXbwtunikBU+eqxmrugn0EN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725616379; c=relaxed/simple; bh=y/2q/oU3B2T/Sj3xYbJ3TRbapgrDhvFRSSna1J7JF/0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=J5BDepHPoFOa2xxgpEq/G2un67GVFa2RqCoYlcpvSH9MdPU9+WnGIQJcw7RwGr7hZfrM/n1eJEHXepU9f4ILaLbNaKDpgzGQY6iXTDT4VRVjxieDT//uUx54c1jdlEeVxGeCHg9Bwe+GefUaTy/TwOO7Tq1DsQu1hGAaQNS93bg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=CjOE/3GJ; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CjOE/3GJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725616367; h=from:from:reply-to:subject:subject: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=Pft5+JeYXYrsom9XC/wwmdmDEnhGm2vJUjZuwg+BsyM=; b=CjOE/3GJ4IyJBnXsBf/ykYzDPdCAsYwIpxktf0H7ALGACJzD7fxEuKLww18iVhY7To9dyr 12kmyIrQ1Ac8qGBeLi0OUqINRpFNrZgqMHnmkFTyRBxr5S2AG7prW7Hp9M/1hEk0V14Ioy sNO/0gxeDm1sZSnrnqAu+JDmYyZfylI= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-25-lFUZIY2MPTytrb0LIqkhtQ-1; Fri, 06 Sep 2024 05:52:46 -0400 X-MC-Unique: lFUZIY2MPTytrb0LIqkhtQ-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-42c883c8cf7so15070485e9.1 for ; Fri, 06 Sep 2024 02:52:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725616365; x=1726221165; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Pft5+JeYXYrsom9XC/wwmdmDEnhGm2vJUjZuwg+BsyM=; b=A57QFkXz3ze4wUWkjaPqVpWeapH1i6C4uO2xjSjOVXeuGTRRQDIKHl1PIx0pNVHpsN SQ6wthZzb6yqex2u3Tu+889Nvgy+t90Hzi2njlTtyuQBJtBern9fq8nWCl46UHHyc1zD 4OsAHEupFA+hfYbtvezxPlE5ikYp0lGZ0GJTKpE/mSaXLArVAJtIoZds+35j3N+whsmZ Y6XdvHvaJVsFlrXBUUCGcvSIu8a1d4gukYUwixNPzMvOmZJeCnN62r6mtPGb1LrcXzvm mhTwGFmATC48EafyNmYgHjW658r3PnI3WV7JJIyaxOPmO6eZCUiUrCxWHcezDikgRvj7 OxnA== X-Forwarded-Encrypted: i=1; AJvYcCXpcSqtnh6bYfZBBDc1FjM0GuZDkWr7ZATieWMe4LOhMKod3Lb4Pe3LYeyNoqAmky6keduY56o=@vger.kernel.org X-Gm-Message-State: AOJu0YyozflQiffZgyURtQRVXrbhlUjGehKHsIgotvCgtFQAgwr7i4lY 1imcqrB8MVOGr2fiYRsH2XbHnR8x+BPEeLKFYF2BHuzeJeMOCfbV9Yy/teJ1HV/K6UpfYIZkctk lN1IWYJh2ofEHxkSjhFGERpLzxHlNaLUaeeJcsuj/Ch96dOAAgmDRkw== X-Received: by 2002:a05:600c:1913:b0:426:5d0d:a2c9 with SMTP id 5b1f17b1804b1-42c9f97dbfamr13581685e9.10.1725616365016; Fri, 06 Sep 2024 02:52:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF21JiRX7kMArBtpqaDQnryw6ZUluOTmbApXNoVkHLpPhwvwYOfjmZQYcgbTEuY9mkhpcPeag== X-Received: by 2002:a05:600c:1913:b0:426:5d0d:a2c9 with SMTP id 5b1f17b1804b1-42c9f97dbfamr13581415e9.10.1725616364521; Fri, 06 Sep 2024 02:52:44 -0700 (PDT) Received: from redhat.com ([155.133.17.165]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42ca05d3171sm14716285e9.28.2024.09.06.02.52.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 02:52:43 -0700 (PDT) Date: Fri, 6 Sep 2024 05:52:40 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Xuan Zhuo , Jason Wang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , virtualization@lists.linux.dev, Si-Wei Liu , Darren Kenny , Boris Ostrovsky , Eugenio =?utf-8?b?UMOpcmV6?= Subject: [RFC PATCH v2 6/7] Revert "virtio_net: big mode skip the unmap check" Message-ID: <3db7fcc631c2f1dd6a62e5d90fecf3e5c32ca4e2.1725616135.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This reverts commit a377ae542d8d0a20a3173da3bbba72e045bea7a9. leads to crashes with no ACCESS_PLATFORM when sysctl net.core.high_order_alloc_disable=1 Cc: Xuan Zhuo Reported-by: Si-Wei Liu Signed-off-by: Michael S. Tsirkin --- drivers/net/virtio_net.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 0a2ec9570521..6f3c39dc6f76 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -983,7 +983,7 @@ static void virtnet_rq_unmap_free_buf(struct virtqueue *vq, void *buf) rq = &vi->rq[i]; - if (!vi->big_packets || vi->mergeable_rx_bufs) + if (rq->do_dma) virtnet_rq_unmap(rq, buf, 0); virtnet_rq_free_buf(vi, rq, buf); @@ -2367,7 +2367,7 @@ static int virtnet_receive(struct receive_queue *rq, int budget, } } else { while (packets < budget && - (buf = virtqueue_get_buf(rq->vq, &len)) != NULL) { + (buf = virtnet_rq_get_buf(rq, &len, NULL)) != NULL) { receive_buf(vi, rq, buf, len, NULL, xdp_xmit, &stats); packets++; } From patchwork Fri Sep 6 09:52:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 13793836 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0F9F1CB329 for ; Fri, 6 Sep 2024 09:52:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725616374; cv=none; b=o/ZSuDs7HB/zNqIyjL0H9C8xqvIVQnvl5+dlIVCFRcNb9slFGIq3oDzCpwF2XgbvJoVN/dgkEy0yCI06Wpbk8E6lTutNj+3HFHn6yfeKAOVOuC0hDsntLSckw7L5pI/L1n02aoGvaUV8aipK6NqFFNQfqm0hR5Y5XIGi7LzR1Qc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725616374; c=relaxed/simple; bh=G0vuRwIZULx1awulz3TZccpUD9HBmx1Km+yJqugvR6M=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=neLi/AO/O/Be5SUNUZEVeRTpskeY3ZK4RZucS67ZHZ3/3YYszkyaSS0eAOop9yvW6G3kWreSpxgMVWpkTHyvBxvicuRjuVSMmwg7T8c6fEZBxONHKdlMiUEroPofDXm963fny9xJeywP4FKos9KUzd6Ad2ECpjZeI9QO91r9yNA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=c4AMZsBg; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="c4AMZsBg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725616372; h=from:from:reply-to:subject:subject: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=0BVAAiLX2YDT2AdtI4QtNJTs70zsl324iWlMmUL5ZGE=; b=c4AMZsBgBTcYlVtCsXNOIBoM43gGwqkNDY5Mg00r/ujfL1/TyId7lgjUeU7S2NAvPnlAi0 Xl7luMWUej5FB9A+bL4YImFXTpBEScZa1pZzi15S7TwHIgmb+YsydizQ3bLTOTNp3p6cHo FDmbi90xP1cDNJfE2F+7XMC6E7F9+dE= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-113-NBrs5pg5NoWYMWjUpWuNuA-1; Fri, 06 Sep 2024 05:52:50 -0400 X-MC-Unique: NBrs5pg5NoWYMWjUpWuNuA-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-42bbd062ac1so14755185e9.0 for ; Fri, 06 Sep 2024 02:52:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725616369; x=1726221169; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=0BVAAiLX2YDT2AdtI4QtNJTs70zsl324iWlMmUL5ZGE=; b=f7mMik3W+eRmSvXU5GFa6zKyCRf3fAckakUrTsAMQIrqvP9wGsp2QORol69x/w++q8 t8ASOjfg8lZlJ/XcEZChZ/zTazS0yww9txQFZpRaG75xF8BbulYdQZ1KZrJAj2dQR6nH Ya1iAgtmnhLeBFVdO6an0aOQ5efy/jCy2ZWv7OkrodbFCD9cTCNLnKpINExzpzvmFq1k Lrzib0Zv4L0fg99j9S9wyCY+3GAjvWD4hHCOWvdj77aEQfl9ojH2X5vDUXS6RDEqhFrR Xk4Ibv0KYzlDgAVz1PkYc7xW720s71A+VyoKCVDqOm4jK8v+gbq6D7nEY4aHeCev7j7i qFeA== X-Forwarded-Encrypted: i=1; AJvYcCVlGsrr5vZGTRb2mpE7kilsLtbDRTxBC0Xi9eZg29oLpuDz7bDqJVeVw93HGqaSP2Ta7YCxAY8=@vger.kernel.org X-Gm-Message-State: AOJu0Ywp4Fr8pvJuQ5b4ZpPdNGbTufTUz46hwsaU+P1MjmSal/+5GiB4 Cs9EcbGhcyv/WTwk7nTBEke0II2WGxTpnaYPqZPO7P1zze/axvLgcMlEyrZZY/OiHCUoMhciElp wyjKauULGuTY3ZLZtvV0vSWE7s+SZ672xV/5zyIR8wT7jqLCI2cm2Cg== X-Received: by 2002:a5d:5225:0:b0:36b:3384:40e5 with SMTP id ffacd0b85a97d-378895de480mr1326176f8f.24.1725616369305; Fri, 06 Sep 2024 02:52:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEpPl6uh0wHWO+9rukppTUDX20dNZLFoJnMDp58PodNRcJ5IH3PPSXhUNF+FyNXmBHbr/zcog== X-Received: by 2002:a5d:5225:0:b0:36b:3384:40e5 with SMTP id ffacd0b85a97d-378895de480mr1326157f8f.24.1725616368848; Fri, 06 Sep 2024 02:52:48 -0700 (PDT) Received: from redhat.com ([155.133.17.165]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-374c5ba7027sm14447997f8f.19.2024.09.06.02.52.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 02:52:48 -0700 (PDT) Date: Fri, 6 Sep 2024 05:52:44 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Xuan Zhuo , Jason Wang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , virtualization@lists.linux.dev, Si-Wei Liu , Darren Kenny , Boris Ostrovsky , Eugenio =?utf-8?b?UMOpcmV6?= Subject: [RFC PATCH v2 7/7] Revert "virtio_ring: enable premapped mode whatever use_dma_api" Message-ID: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent X-Patchwork-State: RFC This reverts commit f9dac92ba9081062a6477ee015bd3b8c5914efc4. leads to crashes with no ACCESS_PLATFORM when sysctl net.core.high_order_alloc_disable=1 Cc: Xuan Zhuo Reported-by: Si-Wei Liu Signed-off-by: Michael S. Tsirkin --- drivers/virtio/virtio_ring.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index be7309b1e860..06b5bdf0920e 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -2782,7 +2782,7 @@ EXPORT_SYMBOL_GPL(virtqueue_resize); * * Returns zero or a negative error. * 0: success. - * -EINVAL: too late to enable premapped mode, the vq already contains buffers. + * -EINVAL: vring does not use the dma api, so we can not enable premapped mode. */ int virtqueue_set_dma_premapped(struct virtqueue *_vq) { @@ -2798,6 +2798,11 @@ int virtqueue_set_dma_premapped(struct virtqueue *_vq) return -EINVAL; } + if (!vq->use_dma_api) { + END_USE(vq); + return -EINVAL; + } + vq->premapped = true; vq->do_unmap = false;