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 X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB2C6C10F11 for ; Thu, 25 Apr 2019 02:56:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B2C1D214AE for ; Thu, 25 Apr 2019 02:56:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388693AbfDYC4M (ORCPT ); Wed, 24 Apr 2019 22:56:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53164 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388683AbfDYC4M (ORCPT ); Wed, 24 Apr 2019 22:56:12 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C1CDC3082E6A; Thu, 25 Apr 2019 02:56:11 +0000 (UTC) Received: from [10.72.12.167] (ovpn-12-167.pek2.redhat.com [10.72.12.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C1121B42D; Thu, 25 Apr 2019 02:56:05 +0000 (UTC) Subject: Re: virtio_net: suspicious RCU usage with xdp To: David Ahern , "Michael S. Tsirkin" Cc: makita.toshiaki@lab.ntt.co.jp, Jesper Dangaard Brouer , =?UTF-8?Q?Toke_H=c3=b8iland-J=c3=b8rgensen?= , "netdev@vger.kernel.org" References: <20190424132533-mutt-send-email-mst@kernel.org> <8dcadb7a-b1d3-1739-9a8d-2bb09b38969c@gmail.com> From: Jason Wang Message-ID: <6ee32058-30eb-4d42-ddb9-27afce23445d@redhat.com> Date: Thu, 25 Apr 2019 10:56:03 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <8dcadb7a-b1d3-1739-9a8d-2bb09b38969c@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 25 Apr 2019 02:56:11 +0000 (UTC) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 2019/4/25 上午1:40, David Ahern wrote: > On 4/24/19 11:37 AM, Michael S. Tsirkin wrote: >> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c >> index 9010938e2d71..ccc1bdd1bb1f 100644 >> --- a/drivers/net/virtio_net.c >> +++ b/drivers/net/virtio_net.c >> @@ -495,8 +495,8 @@ static struct send_queue *virtnet_xdp_sq(struct virtnet_info *vi) >> return &vi->sq[qp]; >> } >> >> -static int virtnet_xdp_xmit(struct net_device *dev, >> - int n, struct xdp_frame **frames, u32 flags) >> +static int __virtnet_xdp_xmit(struct net_device *dev, >> + int n, struct xdp_frame **frames, u32 flags) >> { >> struct virtnet_info *vi = netdev_priv(dev); >> struct receive_queue *rq = vi->rq; >> @@ -569,6 +569,17 @@ static int virtnet_xdp_xmit(struct net_device *dev, >> return ret; >> } >> >> +static int virtnet_xdp_xmit(struct net_device *dev, >> + int n, struct xdp_frame **frames, u32 flags) >> +{ >> + int r; >> + >> + rcu_read_lock_bh(); >> + r = __virtnet_xdp_xmit(dev, n, frames, flags); >> + rcu_read_unlock_bh(); >> + return r; >> +} >> + >> static unsigned int virtnet_get_headroom(struct virtnet_info *vi) >> { >> return vi->xdp_queue_pairs ? VIRTIO_XDP_HEADROOM : 0; >> @@ -714,7 +725,7 @@ static struct sk_buff *receive_small(struct net_device *dev, > receive_small takes the rcu lock at the beginning. Yes, so the code call __virtnet_xdp_xmit() that won't try to take rcu lock. Thanks > > >> xdpf = convert_to_xdp_frame(&xdp); >> if (unlikely(!xdpf)) >> goto err_xdp; >> - err = virtnet_xdp_xmit(dev, 1, &xdpf, 0); >> + err = __virtnet_xdp_xmit(dev, 1, &xdpf, 0); >> if (unlikely(err < 0)) { >> trace_xdp_exception(vi->dev, xdp_prog, act); >> goto err_xdp; >> @@ -887,7 +898,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, > same here. >> xdpf = convert_to_xdp_frame(&xdp); >> if (unlikely(!xdpf)) >> goto err_xdp; >> - err = virtnet_xdp_xmit(dev, 1, &xdpf, 0); >> + err = __virtnet_xdp_xmit(dev, 1, &xdpf, 0); >> if (unlikely(err < 0)) { >> trace_xdp_exception(vi->dev, xdp_prog, act); >> if (unlikely(xdp_page != page)) >> >> > bq_xmit_all is invoking the xdp_xmit callback without taking the rcu > lock, but from the git history does not appear to have any recent changes.