Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1582826rdb; Thu, 7 Dec 2023 03:28:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IFc5xXJrqdETDUMUBB7i8/Dz6amaeELaTzeGWDT5At/8ohZ+cfVAAIHf3/ul3cwagMmqZlu X-Received: by 2002:a05:6a00:194c:b0:6c0:4006:4195 with SMTP id s12-20020a056a00194c00b006c040064195mr2901108pfk.0.1701948513974; Thu, 07 Dec 2023 03:28:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701948513; cv=none; d=google.com; s=arc-20160816; b=mdNQmuGLp+qrm3tUtlhvrdcSy1Xlamt7aEVPBTviJRd95Fndv/JoESmtduoz809cD5 xoileJNIHHeECDQpMulo70x6hBn6vfeygVEyL1ZmHIc00Tg+XLF9DQvjAV92ItCAaoYv Av7ccigCdqgmi+GLkIt+MFwLQV7SSVDdVO7dHwsCQZLYsJdvulxKwT/7WVXxT6/NM1zO 8r94dnLJZvrbHz0UraPzNW0AS4KtcAQ09ETQCBRmNOJKqStvP41kS6ULyrXcBaf62zlE XRK08gNkBy2gm8s7J/aELMNmWUF0OZXrc83OfRroPYE/QPOtyFnOFBon4x8QWQrH56dN 95RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=dZ8TeQ65k+SeGAp45GrrLMIMgJLQZonFrPxkzb/IGnA=; fh=Uk8g7gJ4FUMp5jCxq3NbM9wADjawiPgypmO2SkxfNRY=; b=Dnr2Fpn1XHHOTQV+HXrezqjYx5DHNAv4nQsGqeU9zrdIoXSE235EXqzPZSR35Z6JCq ZVgA6UGFmr1fLbCAuKLsLX0oWuUKVgN+MKcz5G1AJnOJB8D0z+0R4lCyl/PsNgrN/yl1 Zvr7+Z1pL2smSZbcYBGvQ7IzOjLz0CuG0IYB7CIqoZicJMvdhU2qILam+fttiWRLUMY+ RvRqJBd1oNv2BmlV84RWxTfn3kco4ZQ/ezx9xDepC/J/6/3EkS/v/s+XoQOK2cvS43Yc NWAIe+/aVSYh2YkgJUVVMwxtBhOuOxR4bi/JfC+PX69EwpOATiiFmeWVf4syGd1QBFCh NzDQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id z25-20020a056a001d9900b006be55174f3fsi1104974pfw.28.2023.12.07.03.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 03:28:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 06C888051BBE; Thu, 7 Dec 2023 03:28:33 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232424AbjLGL2S (ORCPT + 99 others); Thu, 7 Dec 2023 06:28:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232398AbjLGL2P (ORCPT ); Thu, 7 Dec 2023 06:28:15 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61E1310C2; Thu, 7 Dec 2023 03:28:19 -0800 (PST) Received: from dggpemm500005.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SmBp05SJ9zYsnN; Thu, 7 Dec 2023 19:27:36 +0800 (CST) Received: from [10.69.30.204] (10.69.30.204) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 7 Dec 2023 19:28:17 +0800 Subject: Re: [PATCH net-next 6/6] tools: virtio: introduce vhost_net_test To: Jason Wang CC: , , , , , "Michael S. Tsirkin" , Xuan Zhuo , References: <20231205113444.63015-1-linyunsheng@huawei.com> <20231205113444.63015-7-linyunsheng@huawei.com> From: Yunsheng Lin Message-ID: <424670ab-23d8-663b-10cb-d88906767956@huawei.com> Date: Thu, 7 Dec 2023 19:28:16 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.69.30.204] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 07 Dec 2023 03:28:33 -0800 (PST) On 2023/12/7 14:00, Jason Wang wrote: > On Tue, Dec 5, 2023 at 7:35 PM Yunsheng Lin wrote: ... >> + >> +static int tun_alloc(void) >> +{ >> + struct ifreq ifr; >> + int fd, e; >> + >> + fd = open("/dev/net/tun", O_RDWR); >> + if (fd < 0) { >> + perror("Cannot open /dev/net/tun"); >> + return fd; >> + } >> + >> + memset(&ifr, 0, sizeof(ifr)); >> + >> + ifr.ifr_flags = IFF_TUN | IFF_NO_PI; > > Why did you use IFF_TUN but not IFF_TAP here? To be honest, no particular reason, I just picked IFF_TUN and it happened to work for me to test changing in vhost_net_build_xdp(). Is there a particular reason you perfer the IFF_TAP over IFF_TUN? > >> + strncpy(ifr.ifr_name, "tun0", IFNAMSIZ); > > tun0 is pretty common if there's a VPN. Do we need some randomized name here? How about something like below? snprintf(ifr.ifr_name, IFNAMSIZ, "tun_%d", getpid()); > > >> + >> + e = ioctl(fd, TUNSETIFF, (void *) &ifr); >> + if (e < 0) { >> + perror("ioctl[TUNSETIFF]"); >> + close(fd); >> + return e; >> + } >> + >> + return fd; >> +} >> + >> +/* Unused */ >> +void *__kmalloc_fake, *__kfree_ignore_start, *__kfree_ignore_end; > > Why do we need trick like these here? That is because of the below error: tools/virtio/./linux/kernel.h:58: undefined reference to `__kmalloc_fake' when virtio_ring.c is compiled in the userspace, the kmalloc raleted function is implemented in tools/virtio/./linux/kernel.h, which requires those varibles to be defined. > >> + >> +struct vq_info { >> + int kick; >> + int call; >> + int num; >> + int idx; >> + void *ring; >> + /* copy used for control */ >> + struct vring vring; >> + struct virtqueue *vq; >> +}; >> + >> +struct vdev_info { >> + struct virtio_device vdev; >> + int control; >> + struct pollfd fds[1]; >> + struct vq_info vqs[1]; >> + int nvqs; >> + void *buf; >> + size_t buf_size; >> + struct vhost_memory *mem; >> +}; >> + >> +static struct vhost_vring_file no_backend = { .index = 1, .fd = -1 }, >> + backend = { .index = 1, .fd = 1 }; > > A magic number like fd = 1 is pretty confusing. > > And I don't see why we need global variables here. I was using the virtio_test.c as reference, will try to remove it if it is possible. > >> +static const struct vhost_vring_state null_state = {}; >> + .. >> + >> +done: >> + backend.fd = tun_alloc(); >> + assert(backend.fd >= 0); >> + vdev_info_init(&dev, features); >> + vq_info_add(&dev, 256); >> + run_test(&dev, &dev.vqs[0], delayed, batch, reset, nbufs); > > I'd expect we are testing some basic traffic here. E.g can we use a > packet socket then we can test both tx and rx? Yes, only rx for tun is tested. Do you have an idea how to test the tx too? As I am not familar enough with vhost_net and tun yet. > > Thanks