From patchwork Thu Jun 29 15:25:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hawkins Jiawei X-Patchwork-Id: 1801558 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=bGEZCXPz; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QsMjQ0nRFz1yhT for ; Fri, 30 Jun 2023 01:26:02 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEtWr-0001fj-RG; Thu, 29 Jun 2023 11:25:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qEtWp-0001Yr-FN for qemu-devel@nongnu.org; Thu, 29 Jun 2023 11:25:51 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qEtWn-0007QA-Ol for qemu-devel@nongnu.org; Thu, 29 Jun 2023 11:25:51 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1b80f2ed810so4739825ad.0 for ; Thu, 29 Jun 2023 08:25:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688052348; x=1690644348; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i11pe/SEBYjDzJQtCf8AUd0eYtADDXrqqVh5YnGpr5E=; b=bGEZCXPzCBb4Vz7e6f5EInUm1qfXhdlKS/k5gaUCq9o2DHM4MOOZxYv2qB6loq646X nX8iYCp1gdS8o1+rFil/oeJ68X8D2xmJfsvqqPJbn+ONhmM6JmVX/FFUUwrYPubHQHME jv2B3eez3q87MRxflXZbaahvx35lYh8qfyKtCsy3nnqSrklcYo3pXTlzsi73XQmiBvVr 9Igt3kxVsTX3Jh6M9V1aJi7g80zVmLVMOZrrjZMDUSrvVCaLUwU2+oJymH/4J5xeGUtZ PhRdfzlfDgVAa3EMDHiUGOyS0u7aBqDfDDTk11TSsGTp8dreQRRlIYFF4wlgxdKfkj/g l2dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688052348; x=1690644348; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i11pe/SEBYjDzJQtCf8AUd0eYtADDXrqqVh5YnGpr5E=; b=ayfbpLNpAd+lWoSeaKg1Ufm3gvVz/eYBKUZuDrJqoxbGcyCyvlgHGOmG0Vm5qEMDIA 2/fzg9Z4NYVTnIKfmstVR/bxRXyriTnNtCvDeyE+Dpk75A/ANty51KmCBAQGbfpe9aeS Ad6gtqqn0IuLfQNY3goVNBvka0N9xwgW66Fp2RxdPyNEWsofO20kGnQzVZD2e+k4jP/b cK4ggUNbB9YS0xKM7EfF6yOmFJGhpvOovWY/bRcZPgOgfB9QtPO7S6+d3C8ozjqtk7// fWQaxH6x/mJLdqPlh0BORWlNRHKj7GRgMqEMDOVmhXBszgBvO6jsQOA6v3FZhha7XFFP 9rmg== X-Gm-Message-State: AC+VfDwvQu6envlDwDfrnvCipMsTu6ERLvSh+rYBIagfrABUwyyrmTGc EcrHDYan/foXcb62gDsb/QE= X-Google-Smtp-Source: ACHHUZ58o17eCz2U5/0iwRxhApEFIjZAmAgyCFq5sqfzJIBfSbUw60F5mA+FD/u5M8rF6fXyTtIMsQ== X-Received: by 2002:a17:902:7289:b0:1b6:80f0:d969 with SMTP id d9-20020a170902728900b001b680f0d969mr10150355pll.11.1688052347623; Thu, 29 Jun 2023 08:25:47 -0700 (PDT) Received: from localhost ([159.226.94.115]) by smtp.gmail.com with ESMTPSA id jd22-20020a170903261600b001b3c66f806bsm6892537plb.217.2023.06.29.08.25.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 08:25:47 -0700 (PDT) From: Hawkins Jiawei To: jasowang@redhat.com, mst@redhat.com, eperezma@redhat.com Cc: qemu-devel@nongnu.org, yin31149@gmail.com, 18801353760@163.com Subject: [PATCH RFC v2 1/4] vdpa: Use iovec for vhost_vdpa_net_load_cmd() Date: Thu, 29 Jun 2023 23:25:32 +0800 Message-Id: <6d3dc0fc076564a03501e222ef1102a6a7a643af.1688051252.git.yin31149@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=yin31149@gmail.com; helo=mail-pl1-x62a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org According to VirtIO standard, "The driver MUST follow the VIRTIO_NET_CTRL_MAC_TABLE_SET command by a le32 number, followed by that number of non-multicast MAC addresses, followed by another le32 number, followed by that number of multicast addresses." Considering that these data is not stored in contiguous memory, this patch refactors vhost_vdpa_net_load_cmd() to accept scattered data, eliminating the need for an addtional data copy or packing the data into s->cvq_cmd_out_buffer outside of vhost_vdpa_net_load_cmd(). Signed-off-by: Hawkins Jiawei --- v2: - refactor vhost_vdpa_load_cmd() to accept iovec suggested by Eugenio net/vhost-vdpa.c | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 6f6a5c6df6..0bd1c7817c 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -620,29 +620,43 @@ static ssize_t vhost_vdpa_net_cvq_add(VhostVDPAState *s, size_t out_len, } static ssize_t vhost_vdpa_net_load_cmd(VhostVDPAState *s, uint8_t class, - uint8_t cmd, const void *data, - size_t data_size) + uint8_t cmd, const struct iovec *data, + size_t data_len) { const struct virtio_net_ctrl_hdr ctrl = { .class = class, .cmd = cmd, }; + void *cursor = s->cvq_cmd_out_buffer; - assert(data_size < vhost_vdpa_net_cvq_cmd_page_len() - sizeof(ctrl)); + /* pack the CVQ command header */ + assert(sizeof(ctrl) < vhost_vdpa_net_cvq_cmd_page_len() - + (cursor - s->cvq_cmd_out_buffer)); + memcpy(cursor, &ctrl, sizeof(ctrl)); + cursor += sizeof(ctrl); - memcpy(s->cvq_cmd_out_buffer, &ctrl, sizeof(ctrl)); - memcpy(s->cvq_cmd_out_buffer + sizeof(ctrl), data, data_size); + /* pack the CVQ command command-specific-data */ + for (int i = 0; i < data_len; ++i) { + assert(data[i].iov_len < vhost_vdpa_net_cvq_cmd_page_len() - + (cursor - s->cvq_cmd_out_buffer)); + memcpy(cursor, data[i].iov_base, data[i].iov_len); + cursor += data[i].iov_len; + } - return vhost_vdpa_net_cvq_add(s, sizeof(ctrl) + data_size, + return vhost_vdpa_net_cvq_add(s, cursor - s->cvq_cmd_out_buffer, sizeof(virtio_net_ctrl_ack)); } static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n) { if (virtio_vdev_has_feature(&n->parent_obj, VIRTIO_NET_F_CTRL_MAC_ADDR)) { + const struct iovec data = { + .iov_base = (void *)n->mac, + .iov_len = sizeof(n->mac), + }; ssize_t dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_MAC, VIRTIO_NET_CTRL_MAC_ADDR_SET, - n->mac, sizeof(n->mac)); + &data, 1); if (unlikely(dev_written < 0)) { return dev_written; } @@ -665,9 +679,13 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s, } mq.virtqueue_pairs = cpu_to_le16(n->curr_queue_pairs); + const struct iovec data = { + .iov_base = &mq, + .iov_len = sizeof(mq), + }; dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_MQ, - VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET, &mq, - sizeof(mq)); + VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET, + &data, 1); if (unlikely(dev_written < 0)) { return dev_written; } @@ -706,9 +724,13 @@ static int vhost_vdpa_net_load_offloads(VhostVDPAState *s, } offloads = cpu_to_le64(n->curr_guest_offloads); + const struct iovec data = { + .iov_base = &offloads, + .iov_len = sizeof(offloads), + }; dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_GUEST_OFFLOADS, VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET, - &offloads, sizeof(offloads)); + &data, 1); if (unlikely(dev_written < 0)) { return dev_written; } From patchwork Thu Jun 29 15:25:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hawkins Jiawei X-Patchwork-Id: 1801560 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=svTvaLqs; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QsMjy0cpyz1yhT for ; Fri, 30 Jun 2023 01:26:29 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEtXD-0001sZ-Iz; Thu, 29 Jun 2023 11:26:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qEtWs-0001ju-Q0 for qemu-devel@nongnu.org; Thu, 29 Jun 2023 11:25:58 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qEtWq-0007Qz-PW for qemu-devel@nongnu.org; Thu, 29 Jun 2023 11:25:54 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1b7db2e162cso4587515ad.1 for ; Thu, 29 Jun 2023 08:25:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688052351; x=1690644351; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yOB12PIn0FZFsRHdFv6Q5mXPK3RoN/QgEsk0BguCeX0=; b=svTvaLqshpChqmdsQxnlQ0+lX+Atox15FGzElMOzlAUoYSAu+imhyZme1GNelhRxDh mRrFlC6+5Yq4JQvd6dkU/18tNXySV/bJtHDnRgOXDuHunyCESsjyEXF3rHtKAakP8DJD ftIoaHl15bpzN8rlK04iYwTBKmh6aUvBpQn8tB4ZeizrkMYxehc90KoW5oilcbcew3wz f/pDgNg1Vpsl3oqQ18a3KR8sltiGjzRQbDWa+ydsvjE/XMCTIiQC2LjWobAmH8aay26g iJZ8Mf9qCd2/7WiYB0OqRxc6vbZqiTdjGVJyKPmp3PtUjMoryMKL3aS86HZYcIX+vSYE 0BZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688052351; x=1690644351; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yOB12PIn0FZFsRHdFv6Q5mXPK3RoN/QgEsk0BguCeX0=; b=Vurc0swSuNkA7vX3TQVTebAQHB3/uP6k5Q9kq8dXKZ4e7SA0PWO81xUfFxC5x1B9IW jWVuzrxgjPgNU3Wlx97liYIrTo4hCTYJ6a29QpMCBy1392+EqIj0B0HGuxkfLrJ2qnd+ L4bhVLbYxDl3BUmW+qH5o40S/3CYr/ESsk177MuyZWZlgOQmAENPO5HRHCDC5B5J/VDh isczUCly2j1l8HwopVS5lCSVJ38OsjMa2vq5yahaWeAGWXSLrqcvhw1x6eFHpGLugMd3 oBojKKyNKbjJud+DBZQIog5YW1KmNZWDVsFtr0FamLKAFDZ2oADqBP+QZZ4IMoun9/+1 MLBw== X-Gm-Message-State: AC+VfDyf1qTH6OPQGzucuwSA699xVLf+di2vYE64ns0RPvX9GMpT/OP2 3JEK/YVVbrAKtTCgE3CPx0M= X-Google-Smtp-Source: ACHHUZ6zXEpuMEUZ5GHxkapxRqmA6+J/kxgxDfXjXEFvyOosQ0e7ayCZE3VMnA8PMUWDt1L2AoFg4Q== X-Received: by 2002:a17:90a:590e:b0:262:a6f7:1946 with SMTP id k14-20020a17090a590e00b00262a6f71946mr12996398pji.9.1688052350922; Thu, 29 Jun 2023 08:25:50 -0700 (PDT) Received: from localhost ([159.226.94.115]) by smtp.gmail.com with ESMTPSA id s18-20020a17090a881200b0024e05b7ba8bsm9417000pjn.25.2023.06.29.08.25.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 08:25:50 -0700 (PDT) From: Hawkins Jiawei To: jasowang@redhat.com, mst@redhat.com, eperezma@redhat.com Cc: qemu-devel@nongnu.org, yin31149@gmail.com, 18801353760@163.com Subject: [PATCH RFC v2 2/4] vdpa: Restore MAC address filtering state Date: Thu, 29 Jun 2023 23:25:33 +0800 Message-Id: <2f2560f749186c0eb1055f9926f464587e419eeb.1688051252.git.yin31149@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=yin31149@gmail.com; helo=mail-pl1-x62f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch refactors vhost_vdpa_net_load_mac() to restore the MAC address filtering state at device's startup. Signed-off-by: Hawkins Jiawei --- v2: - use iovec suggested by Eugenio - avoid sending CVQ command in default state v1: https://lore.kernel.org/all/00f72fe154a882fd6dc15bc39e3a1ac63f9dadce.1687402580.git.yin31149@gmail.com/ net/vhost-vdpa.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 0bd1c7817c..cb45c84c88 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -665,6 +665,57 @@ static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n) } } + if (virtio_vdev_has_feature(&n->parent_obj, VIRTIO_NET_F_CTRL_RX)) { + if (n->mac_table.in_use != 0) { + /* + * According to virtio_net_reset(), device uses an empty MAC filter + * table as its default state. + * + * Therefore, there is no need to send this CVQ command if the + * driver also sets an empty MAC filter table, which aligns with + * the device's defaults. + * + * Note that the device's defaults can mismatch the driver's + * configuration only at live migration. + */ + uint32_t uni_entries = n->mac_table.first_multi, + uni_macs_size = uni_entries * ETH_ALEN, + mul_entries = n->mac_table.in_use - uni_entries, + mul_macs_size = mul_entries * ETH_ALEN; + struct virtio_net_ctrl_mac uni = { + .entries = cpu_to_le32(uni_entries), + }; + struct virtio_net_ctrl_mac mul = { + .entries = cpu_to_le32(mul_entries), + }; + const struct iovec data[] = { + { + .iov_base = &uni, + .iov_len = sizeof(uni), + }, { + .iov_base = n->mac_table.macs, + .iov_len = uni_macs_size, + }, { + .iov_base = &mul, + .iov_len = sizeof(mul), + }, { + .iov_base = &n->mac_table.macs[uni_macs_size], + .iov_len = mul_macs_size, + }, + }; + ssize_t dev_written = vhost_vdpa_net_load_cmd(s, + VIRTIO_NET_CTRL_MAC, + VIRTIO_NET_CTRL_MAC_TABLE_SET, + data, ARRAY_SIZE(data)); + if (unlikely(dev_written < 0)) { + return dev_written; + } + if (*s->status != VIRTIO_NET_OK) { + return -EINVAL; + } + } + } + return 0; } From patchwork Thu Jun 29 15:25:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hawkins Jiawei X-Patchwork-Id: 1801561 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=CmgNvUrV; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QsMk23RKzz1yhT for ; Fri, 30 Jun 2023 01:26:34 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEtXK-00024Z-Gi; Thu, 29 Jun 2023 11:26:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qEtWz-0001m5-60 for qemu-devel@nongnu.org; Thu, 29 Jun 2023 11:26:06 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qEtWt-0007Ru-5W for qemu-devel@nongnu.org; Thu, 29 Jun 2023 11:25:56 -0400 Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-55b1238a024so652662a12.0 for ; Thu, 29 Jun 2023 08:25:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688052353; x=1690644353; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YMQffePhn6GAVPNczkmSxl17glAAwF+BiBZrL06id/o=; b=CmgNvUrVOGq3FlWfVLkVX2NnW/9fr/DzPSe2P+cBRTa17uc2FHWwRx02HbLsyuAZGf 2JgP1GkrJPbkTiRXS8LUpS4HJ52Rdwuz+vrQqJ0ANRHq9pn94JF1q/sptXsXiCdrUc8H TK3X1omdj0ezvhkNiVvp0Z65/TQCsKrecdysZfzxNpDjpgu5rdFSd4QK6pkov+RQH3SM 8MVwjPad4sB2EEKXrs9SW7zXjHLmxSxWgBweVyFGNpoKKNH5PPjsc3ZI3s84vXw8OZi6 AkKDAhZb+tODq+M1oXoJpe1w64fUbvkXa01uKm6TzLamRMzGlDPvyieOJCbswckhwp6L nyVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688052353; x=1690644353; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YMQffePhn6GAVPNczkmSxl17glAAwF+BiBZrL06id/o=; b=QgC9ViKN9l3zalChXJ7YqrNZJcSsJHcAauCeShPP2ebnbBCheXL9ItugyW/DS/RN6i gniBmIXB0brJxpeTGesubbNf+V2re747oXAi9FzIN/F9s7//+gVHEtKz4Zip+4Mt8g1+ pRQYK4iYqEPG3tcGVame3ixctimyt0nCLL/fJQPykvycEafwhkl6d6wfWC9oPxep0Ud0 93pNgy8aMnEE88JfWnfB6mM7VM5Ry2JM4Oywn7AGUKAm2LYyxSiURU8NP0dPspco/InX PqMsJOGfluQR/NC2PwQZ59zlBCGzJcPhcDB+KQ6tvT+S+PwWNRjdj4qgIztOJKRcK2ae lueg== X-Gm-Message-State: AC+VfDybeUpJydoSy3E6sts2SzUdGGeHvmy38AYDAf4FGCSmL74IJIIX eOabJRRxyVuZIZp1e+0SPqQ= X-Google-Smtp-Source: ACHHUZ5KKq8cltJIsOYGZdLixdPdAHTZwjxMECcxlHAsodE4OOO+T8vX7qJR60Uzlttd6z3FLyNTeg== X-Received: by 2002:a05:6a20:659:b0:12c:8871:26df with SMTP id 25-20020a056a20065900b0012c887126dfmr23060pzm.18.1688052353447; Thu, 29 Jun 2023 08:25:53 -0700 (PDT) Received: from localhost ([159.226.94.115]) by smtp.gmail.com with ESMTPSA id x8-20020a62fb08000000b0064d6f4c8b05sm8807335pfm.93.2023.06.29.08.25.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 08:25:53 -0700 (PDT) From: Hawkins Jiawei To: jasowang@redhat.com, mst@redhat.com, eperezma@redhat.com Cc: qemu-devel@nongnu.org, yin31149@gmail.com, 18801353760@163.com Subject: [PATCH RFC v2 3/4] vdpa: Restore packet receive filtering state relative with _F_CTRL_RX feature Date: Thu, 29 Jun 2023 23:25:34 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52b; envelope-from=yin31149@gmail.com; helo=mail-pg1-x52b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch introduces vhost_vdpa_net_load_rx_mode() and vhost_vdpa_net_load_rx() to restore the packet receive filtering state in relation to VIRTIO_NET_F_CTRL_RX feature at device's startup. Signed-off-by: Hawkins Jiawei --- v2: - avoid sending CVQ command in default state suggested by Eugenio v1: https://lore.kernel.org/all/86eeddcd6f6b04e5c1e44e901ddea3b1b8b6c183.1687402580.git.yin31149@gmail.com/ net/vhost-vdpa.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index cb45c84c88..9d5d88756c 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -792,6 +792,106 @@ static int vhost_vdpa_net_load_offloads(VhostVDPAState *s, return 0; } +static int vhost_vdpa_net_load_rx_mode(VhostVDPAState *s, + uint8_t cmd, + uint8_t on) +{ + ssize_t dev_written; + const struct iovec data = { + .iov_base = &on, + .iov_len = sizeof(on), + }; + dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_RX, + cmd, &data, 1); + if (unlikely(dev_written < 0)) { + return dev_written; + } + if (*s->status != VIRTIO_NET_OK) { + return -EINVAL; + } + + return 0; +} + +static int vhost_vdpa_net_load_rx(VhostVDPAState *s, + const VirtIONet *n) +{ + uint8_t on; + int r; + + if (virtio_vdev_has_feature(&n->parent_obj, VIRTIO_NET_F_CTRL_RX)) { + /* Load the promiscous mode */ + if (n->mac_table.uni_overflow) { + /* + * According to VirtIO standard, "Since there are no guarantees, + * it can use a hash filter or silently switch to + * allmulti or promiscuous mode if it is given too many addresses." + * + * QEMU ignores non-multicast(unicast) MAC addresses and + * marks `uni_overflow` for the device internal state + * if guest sets too many non-multicast(unicast) MAC addresses. + * Therefore, we should turn promiscous mode on in this case. + */ + on = 1; + } else { + on = n->promisc; + } + if (on != 1) { + /* + * According to virtio_net_reset(), device turns promiscuous mode on + * by default. + * + * Therefore, there is no need to send this CVQ command if the + * driver also sets promiscuous mode on, which aligns with + * the device's defaults. + * + * Note that the device's defaults can mismatch the driver's + * configuration only at live migration. + */ + r = vhost_vdpa_net_load_rx_mode(s, VIRTIO_NET_CTRL_RX_PROMISC, on); + if (r < 0) { + return r; + } + } + + /* Load the all-multicast mode */ + if (n->mac_table.multi_overflow) { + /* + * According to VirtIO standard, "Since there are no guarantees, + * it can use a hash filter or silently switch to + * allmulti or promiscuous mode if it is given too many addresses." + * + * QEMU ignores multicast MAC addresses and + * marks `multi_overflow` for the device internal state + * if guest sets too many multicast MAC addresses. + * Therefore, we should turn all-multicast mode on in this case. + */ + on = 1; + } else { + on = n->allmulti; + } + if (on != 0) { + /* + * According to virtio_net_reset(), device turns all-multicast mode + * off by default. + * + * Therefore, there is no need to send this CVQ command if the + * driver also sets all-multicast mode off, which aligns with + * the device's defaults. + * + * Note that the device's defaults can mismatch the driver's + * configuration only at live migration. + */ + r = vhost_vdpa_net_load_rx_mode(s, VIRTIO_NET_CTRL_RX_ALLMULTI, on); + if (r < 0) { + return r; + } + } + } + + return 0; +} + static int vhost_vdpa_net_load(NetClientState *nc) { VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc); @@ -818,6 +918,10 @@ static int vhost_vdpa_net_load(NetClientState *nc) if (unlikely(r)) { return r; } + r = vhost_vdpa_net_load_rx(s, n); + if (unlikely(r)) { + return r; + } return 0; } From patchwork Thu Jun 29 15:25:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hawkins Jiawei X-Patchwork-Id: 1801562 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=LtSuNK0p; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QsMkD4YCtz1yhT for ; Fri, 30 Jun 2023 01:26:44 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEtXb-0002go-89; Thu, 29 Jun 2023 11:26:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qEtX2-0001mU-Rl for qemu-devel@nongnu.org; Thu, 29 Jun 2023 11:26:08 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qEtWy-0007SL-6k for qemu-devel@nongnu.org; Thu, 29 Jun 2023 11:26:02 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1b7f68f1c9eso6514035ad.2 for ; Thu, 29 Jun 2023 08:25:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688052356; x=1690644356; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XAagmwjvDf3XIktW/IyV1BnI4YKWPfBWXYBtjDR8Bhk=; b=LtSuNK0pO3V7jfhpE9VGa4POgeY/ma0P5bZz0+Rbp+jW5hVb9JYB0Cek7bnGw8Ta00 axW+FDc9BvxI+56tVSOcd20pbFOXEfL+RzHxmvIQ0R1sPyQU5oyzviQ5BQq+2yo5qVVA JOXHcZC5yFwV4ac3+2B7KWUuVOLm835Elu9gcVq50V6OkXMIjYR45kdPDkTfkOGIOmPk YuaE77qWY3xwhGrX5HlbDFUJgdUvy0yGoCFXnBwuhNZGH1hWaAF7H0ZlLOY6MdduXqz2 m/xQqmO1nnn5VPptheoAD+N1pqHqRrLAaRZm+cVCMyI/0tF/C5clS45eY/7gnS/QTi7c 6w4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688052356; x=1690644356; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XAagmwjvDf3XIktW/IyV1BnI4YKWPfBWXYBtjDR8Bhk=; b=Jc7qhzqjrv/Reo9yUKk9TlmjsvuRaOan4inVaFjq/V7vv7VohjViL92B2S8fOFqyXd x7pIviQOlhw9KzrPezoozzsD8wRAvobkhZnqhK9qZNHOMROtlz6szvJH6J5m0VHPPAHt OWkGVzXKHzloLZDMCpAaWbTsnm8mqaIJrQq/LarVSzVojs38PPWjInJ4CpvfnvGtMahk S9Zy/SiFMgI9hOK5hlG7CoR7IS3EW2d8nA1KCyqjcmB+hBwm/RiQxyTU1Je6tATwPanK DuBdpolVIo1GBC00h3Mjn0LdpZp/W4Iv0oTnazwdPEK8chrORGSMLb0DSrg2m925o0UV 0ZoQ== X-Gm-Message-State: AC+VfDxzNzavJ6gM+wODgoF/ZllVpKjOhym4wURw1D/BTvgDZFvej5H6 ZqReBKemCuqd+bCaxZ4Le+E= X-Google-Smtp-Source: ACHHUZ6GvJljDZ7aQXkNsNO2Okbr86EC0OzfZWwTzJJUNtWDOJFTEVIpheBeq6SLWFo8XvHCs9CMtw== X-Received: by 2002:a17:903:1105:b0:1b6:cafa:4d6a with SMTP id n5-20020a170903110500b001b6cafa4d6amr20020216plh.14.1688052356084; Thu, 29 Jun 2023 08:25:56 -0700 (PDT) Received: from localhost ([159.226.94.115]) by smtp.gmail.com with ESMTPSA id j24-20020a170902759800b001ac591b0500sm9202467pll.134.2023.06.29.08.25.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 08:25:55 -0700 (PDT) From: Hawkins Jiawei To: jasowang@redhat.com, mst@redhat.com, eperezma@redhat.com Cc: qemu-devel@nongnu.org, yin31149@gmail.com, 18801353760@163.com Subject: [PATCH RFC v2 4/4] vdpa: Allow VIRTIO_NET_F_CTRL_RX in SVQ Date: Thu, 29 Jun 2023 23:25:35 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=yin31149@gmail.com; helo=mail-pl1-x630.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Enable SVQ with VIRTIO_NET_F_CTRL_RX feature. Signed-off-by: Hawkins Jiawei Acked-by: Eugenio PĂ©rez --- net/vhost-vdpa.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 9d5d88756c..0410a52043 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -104,6 +104,7 @@ static const uint64_t vdpa_svq_device_features = BIT_ULL(VIRTIO_NET_F_MRG_RXBUF) | BIT_ULL(VIRTIO_NET_F_STATUS) | BIT_ULL(VIRTIO_NET_F_CTRL_VQ) | + BIT_ULL(VIRTIO_NET_F_CTRL_RX) | BIT_ULL(VIRTIO_NET_F_MQ) | BIT_ULL(VIRTIO_F_ANY_LAYOUT) | BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR) |