From patchwork Wed Mar 30 06:33:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Si-Wei Liu X-Patchwork-Id: 12795529 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 125F5C433F5 for ; Wed, 30 Mar 2022 06:51:39 +0000 (UTC) Received: from localhost ([::1]:44176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZSB7-0004NA-Q2 for qemu-devel@archiver.kernel.org; Wed, 30 Mar 2022 02:51:37 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZRtl-0007Xv-2C for qemu-devel@nongnu.org; Wed, 30 Mar 2022 02:33:41 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:39872) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZRti-0005NQ-BH for qemu-devel@nongnu.org; Wed, 30 Mar 2022 02:33:40 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22U3Mg4E001205; Wed, 30 Mar 2022 06:33:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2021-07-09; bh=g6CCMKEhY4A9XctA35s5iChBffq+Mq8CfEB26NtciaA=; b=pEGLmJdSC1sFrll3dHfVquZblNhirX5rVDfDyOMcv7W9eQxG0c6rTK1Ym8O0XYkqOx8k d0/QK2jySxoeYw2ba7udLQXp+70a7RpuhMGKNewcDYier533+2miJRTa7NahVCSXa6Cg Svg7QgormwxEI9vblH+FH97PwO1G/WLBSjxu80DLaM8Eo8tRXPBqn+1nu7dWL4LsAnvY j54Gic+KkuBUePLy2GemVXwUAoCiyFrvrejb7790oaxliqCAPUpTEIjUM9DduE5Lfoa+ tH5HSUIAlG5/fQF4DeG/9E4xxyXKeQ+tdhc2FqS69BeIM+HeaJ7c1+Q9W7KGP/3NLxkp CA== Received: from aserp3030.oracle.com ([141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3f1s8crcnj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Mar 2022 06:33:34 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22U6IT3o114576; Wed, 30 Mar 2022 06:33:33 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2171.outbound.protection.outlook.com [104.47.59.171]) by aserp3030.oracle.com with ESMTP id 3f1rv8egk8-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Mar 2022 06:33:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZQnoCVh1Y08lO62Yj5EMZAUvlmQxGhOimgG5dA8mPbXSkab1jFRgXNnNpLOhigrcWo+oHzxpLmhr6cGPRjnjJnEhoA9lqNNNRUscoJ/JAJf1ifT5INuN4l0x6yFWa9yErPYLoXwXxzOXcyUXYzKVgrq0DkfTffP/NwbvFggUDy6Td0Kog2GuD6yEMj3pDLf7BAHZ/36DbVp1Oo1AMrlv310jloT4GMkpJ/htBXMmljU5SW0YRdUiepGbEe8kNfEi3ppL2xoMjQG9/TNFiGQJqhn2c53ZjLBPYCsylGVGb/v7U8iqn+PWyBd4z/TEyQSJz5Hy4mP0LWyXcX20S8+2IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=g6CCMKEhY4A9XctA35s5iChBffq+Mq8CfEB26NtciaA=; b=CcmvJlKh79AdLzucYroobNhSRHjkcG54G3MB41d2/gVs1Jg4RaUYJh0NMI4HeHjMJuG/VaBAVwoqa9vccR2plM93PqvsYrRElVSu8nDmmo6t66/UvBVZT9A9TnzElluqyo1uZ5ppk+pKgS8E0QYHTMvm+C61Y8yQVhntQnrkSFbYJ/aW0nLUwB2dJLxsa4/Jo3YLGguLTQpJgKnANgRKmjRI09OYOT232sx38bsCArROfhw3itFjgQgcb+sbyF5AYuqf9p+OdyEHNjS58Ve0XnWV971q9LbpKTzXfUwG06ilTrtlVicOMFnoZipDJWVVnHuqhYBR21hg7YBf9rtzpg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=g6CCMKEhY4A9XctA35s5iChBffq+Mq8CfEB26NtciaA=; b=c6NgcHhU885Tg7TCV3Gdve4QwCulcm1uC5kXcL3XF4TGOeGmsaxf00wDneNOyzgtFQiwje62azUyg3/F3930hZyWyFNDVMvxiwFGV+eeOSylLblj8EAEp1bazAoxogNvaUDd2pS8vXwGDMzM+2ynjjd4GhU4H8XXk6iocACABW8= Received: from BYAPR10MB3287.namprd10.prod.outlook.com (2603:10b6:a03:15c::11) by DM6PR10MB3130.namprd10.prod.outlook.com (2603:10b6:5:1b1::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.17; Wed, 30 Mar 2022 06:33:31 +0000 Received: from BYAPR10MB3287.namprd10.prod.outlook.com ([fe80::e478:4b5e:50a8:7f96]) by BYAPR10MB3287.namprd10.prod.outlook.com ([fe80::e478:4b5e:50a8:7f96%6]) with mapi id 15.20.5102.023; Wed, 30 Mar 2022 06:33:31 +0000 From: Si-Wei Liu To: qemu-devel@nongnu.org Subject: [PATCH 3/7] virtio-net: Only enable userland vq if using tap backend Date: Tue, 29 Mar 2022 23:33:13 -0700 Message-Id: <1648621997-22416-4-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1648621997-22416-1-git-send-email-si-wei.liu@oracle.com> References: <1648621997-22416-1-git-send-email-si-wei.liu@oracle.com> X-ClientProxiedBy: DM6PR11CA0006.namprd11.prod.outlook.com (2603:10b6:5:190::19) To BYAPR10MB3287.namprd10.prod.outlook.com (2603:10b6:a03:15c::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f3ad5ada-bfba-4ffa-f966-08da1217355b X-MS-TrafficTypeDiagnostic: DM6PR10MB3130:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bysm83TLcooahr+rRaDDeujzHSXlu6ns5iKneWEoscjh8v/xdrXBdS1H3gGYaZxfnYzAF757eo3cxutMcqzYLHtUzLqhQiuq2a8ElagBYp7QASo+YQn8TTN+xMMWozqyAlt5nhQC+8tvNML/nOioRhmlYZomb5A1SYLzHK36IMIwYgkJ3wfcKhwO8AE/TQwSyQI/bOay7f+gGeeLryejYwP+KwcnulEtaQaXYMfwkOSLzaFbVREO+rFB6/6ASVNqBL9SyyX8++2sv4SBVL+/gx0iTlhvebr+QVPi/Ut88Zr3X7i3T60i7w5uinPZKqG6oXvcugbPtRG5zBJcAabyxSoXsKqbVMixlYiLGXijQbtqnRFzowhuSS7X12/UORdzqofyNZ4npD3SdChdwYByAoakHNmCgj9Nr2vgatV53iDE1KISbyFNI4C42gMFInI68g3x40mWWNbikU/ge8ReHyeuQhmEPsR3CNp4eeLYJGkU8N0bhQqIYo5oPxr51bN/5WI08aZU6FTJy6xkIZ9tuufHkv1/oAnXMdJazpzaHBdc566Q0dW8DKqgpThZ+Slm2E2w3gZNZUBcuUkBYtMx3oNWZ31WhtZVeeIgYfeYnscr3grMysyHhELyTi+ORHPgsC2c4uuP7laXKP2M2eRbL4Anb/jkXKEDQThqqCnuIecS9/aqIoTJWErfnLf3k00tKUXlNRantyrC/D7L9hR06g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB3287.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(6506007)(36756003)(2906002)(66946007)(66556008)(508600001)(8676002)(6486002)(6666004)(6512007)(4326008)(38350700002)(66476007)(52116002)(38100700002)(26005)(186003)(2616005)(316002)(6916009)(107886003)(86362001)(5660300002)(8936002)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Aukn3spzIfG28kXF+wh2e4jCanuQ?= =?utf-8?q?9llCtWDNee6iKJjPY5+NYl0ghRno6Ch4Spblz/Bkj1O2ZUx3WNNLfi8WAENoB0fav?= =?utf-8?q?fHSsTj2TyonbyPHPlu8ICJMdvLD2G54sTw6cDJVvN0e5o3SYJSSxgRDRvJWI1jS10?= =?utf-8?q?IyFhiukXc+gX7Vo8yQzRqEOo3kyFHZ1p8qztWKGbFtqOZ+XF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smDOBBeL7F9E?= =?utf-8?q?fYdnklbgaAfXxlGvTduKe7Tz3SxCSVVXP57duFWboFV+GFu3RUeTBPHVuqkzVbRM9?= =?utf-8?q?+nOCqyT4xV3up2EwY6h8rjhDob8rQ8/79/p9SXM3n7T7xb2vaa7dasnCb2QeT/H7U?= =?utf-8?q?I9levR7reyR/670/nIqmms16MKH7w9JWZSEFnqPF/mUJ7BLYAkQsPd4b+d7ioSMur?= =?utf-8?q?V4XfXoEA7sh9kA8Lskjmrhq4fc6vButR8xJbslTi1UvqYiyf14scsBXPhpMWrabwY?= =?utf-8?q?FQ8hbVJZcKePHbM0i36sVkXYnebenfyTJaL5gtVDk5VULCGFRyyyqyeJabydWygYt?= =?utf-8?q?EInCiODDRfi8za4cpD0px0denC2EgqWN83w9EaBgwU2Unpz+Ace6y1OfNAK2HnM/r?= =?utf-8?q?e2TcV9SAcQy2nPoNU8ymrg20utQqOS22J57mrIn/XFS5BXmKPfhCCX+0PTKWYHjhO?= =?utf-8?q?i/2iGtZeApicKWAs7etTOSwLbZ0n6DzRq8ZeULeCQ7/QdZnhql2fcqqvGGjb5PNk2?= =?utf-8?q?2o5hT/rtjuHlCIJ6iqymlcRS7e5gCaGjQcVaEw4kMCgZablEQPM+cHi2lL24KCQkv?= =?utf-8?q?6ZEOAGwyiMGoULJmwyCkTmp0BzVXzks31mN6nz4hqJtiDeQtEAj5A=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f3ad5ada-bfba-4ffa-f966-08da1217355b X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3287.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2022 06:33:31.7145 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 3ruuqP7xC7s+jPZzaZ8q02UrSOh6DOoPy2de9EhWAwQyzetaH1ne8GJ1fw+iVFvy73AzUDSaKC/vc4AXeCKQIA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3130 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10301 signatures=695566 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 adultscore=0 mlxscore=0 phishscore=0 bulkscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203300030 X-Proofpoint-GUID: oxqy04K2sKdrn6tNzVMKaB5thiWxiv6L X-Proofpoint-ORIG-GUID: oxqy04K2sKdrn6tNzVMKaB5thiWxiv6L Received-SPF: pass client-ip=205.220.177.32; envelope-from=si-wei.liu@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: si-wei.liu@oracle.com, eperezma@redhat.com, jasowang@redhat.com, eli@mellanox.com, mst@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Eugenio Pérez Qemu falls back on userland handlers even if vhost-user and vhost-vdpa cases. These assumes a tap device can handle the packets. If a vdpa device fail to start, it can trigger a sigsegv because of that. Do not resort on them unless actually possible. Signed-off-by: Eugenio Pérez --- hw/net/virtio-net.c | 4 ++++ hw/virtio/virtio.c | 21 +++++++++++++-------- include/hw/virtio/virtio.h | 2 ++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index ffaf481..9cdf777 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3523,6 +3523,10 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) nc = qemu_get_queue(n->nic); nc->rxfilter_notify_enabled = 1; + if (!nc->peer || nc->peer->info->type != NET_CLIENT_DRIVER_TAP) { + /* Only tap can use userspace networking */ + vdev->disable_ioeventfd_handler = true; + } if (nc->peer && nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) { struct virtio_net_config netcfg = {}; memcpy(&netcfg.mac, &n->nic_conf.macaddr, ETH_ALEN); diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 9d637e0..806603b 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3708,17 +3708,22 @@ static int virtio_device_start_ioeventfd_impl(VirtIODevice *vdev) err = r; goto assign_error; } - event_notifier_set_handler(&vq->host_notifier, - virtio_queue_host_notifier_read); + + if (!vdev->disable_ioeventfd_handler) { + event_notifier_set_handler(&vq->host_notifier, + virtio_queue_host_notifier_read); + } } - for (n = 0; n < VIRTIO_QUEUE_MAX; n++) { - /* Kick right away to begin processing requests already in vring */ - VirtQueue *vq = &vdev->vq[n]; - if (!vq->vring.num) { - continue; + if (!vdev->disable_ioeventfd_handler) { + for (n = 0; n < VIRTIO_QUEUE_MAX; n++) { + /* Kick right away to begin processing requests already in vring */ + VirtQueue *vq = &vdev->vq[n]; + if (!vq->vring.num) { + continue; + } + event_notifier_set(&vq->host_notifier); } - event_notifier_set(&vq->host_notifier); } memory_region_transaction_commit(); return 0; diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index b31c450..b6ce5f0 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -105,6 +105,8 @@ struct VirtIODevice VMChangeStateEntry *vmstate; char *bus_name; uint8_t device_endian; + /* backend does not support userspace handler */ + bool disable_ioeventfd_handler; bool use_guest_notifier_mask; AddressSpace *dma_as; QLIST_HEAD(, VirtQueue) *vector_queues;