From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E6B8C4332F for ; Thu, 8 Dec 2022 08:20:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229601AbiLHIUK (ORCPT ); Thu, 8 Dec 2022 03:20:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229544AbiLHIUJ (ORCPT ); Thu, 8 Dec 2022 03:20:09 -0500 Received: from out30-45.freemail.mail.aliyun.com (out30-45.freemail.mail.aliyun.com [115.124.30.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3185B12A88; Thu, 8 Dec 2022 00:20:07 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=hengqi@linux.alibaba.com;NM=0;PH=DS;RN=11;SR=0;TI=SMTPD_---0VWpUU8Q_1670487603; Received: from 30.221.147.145(mailfrom:hengqi@linux.alibaba.com fp:SMTPD_---0VWpUU8Q_1670487603) by smtp.aliyun-inc.com; Thu, 08 Dec 2022 16:20:04 +0800 Message-ID: <39346e63-81ea-4257-5274-8b6b2ce4f3d3@linux.alibaba.com> Date: Thu, 8 Dec 2022 16:20:00 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:108.0) Gecko/20100101 Thunderbird/108.0 Subject: Re: [RFC PATCH 1/9] virtio_net: disable the hole mechanism for xdp To: Jason Wang Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, "Michael S. Tsirkin" , Paolo Abeni , Jakub Kicinski , John Fastabend , "David S. Miller" , Daniel Borkmann , Alexei Starovoitov , Eric Dumazet References: <20221122074348.88601-1-hengqi@linux.alibaba.com> <20221122074348.88601-2-hengqi@linux.alibaba.com> From: Heng Qi In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org 在 2022/12/6 下午1:20, Jason Wang 写道: > On Tue, Nov 22, 2022 at 3:44 PM Heng Qi wrote: >> XDP core assumes that the frame_size of xdp_buff and the length of >> the frag are PAGE_SIZE. But before xdp is set, the length of the prefilled >> buffer may exceed PAGE_SIZE, which may cause the processing of xdp to fail, >> so we disable the hole mechanism when xdp is loaded. >> >> Signed-off-by: Heng Qi >> Reviewed-by: Xuan Zhuo >> --- >> drivers/net/virtio_net.c | 5 ++++- >> 1 file changed, 4 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c >> index 9cce7dec7366..c5046d21b281 100644 >> --- a/drivers/net/virtio_net.c >> +++ b/drivers/net/virtio_net.c >> @@ -1419,8 +1419,11 @@ static int add_recvbuf_mergeable(struct virtnet_info *vi, >> /* To avoid internal fragmentation, if there is very likely not >> * enough space for another buffer, add the remaining space to >> * the current buffer. >> + * XDP core assumes that frame_size of xdp_buff and the length >> + * of the frag are PAGE_SIZE, so we disable the hole mechanism. >> */ >> - len += hole; >> + if (!vi->xdp_enabled) > How is this synchronized with virtnet_xdp_set()? > > I think we need to use headroom here since it did: > > static unsigned int virtnet_get_headroom(struct virtnet_info *vi) > { > return vi->xdp_enabled ? VIRTIO_XDP_HEADROOM : 0; > } > > Otherwise xdp_enabled could be re-read which may lead bugs. Yes, we should use headroom instead of using vi->xdp_enabled twice in the same position to avoid re-reading. Thanks for reminding. > > Thanks > >> + len += hole; >> alloc_frag->offset += hole; >> } >> >> -- >> 2.19.1.6.gb485710b >>