Received: by 2002:ab2:6f44:0:b0:1fd:c486:4f03 with SMTP id l4csp209307lqq; Thu, 13 Jun 2024 00:05:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW9+X9HtPFyaYLbnMtawmH+zSusfMjb1CwzjSCIJWoST8/3TD702VE1MiAtcgfdIQWG6t/ePO2bIRNav9B/YHofroKHJLPbk9jAeFK7Lg== X-Google-Smtp-Source: AGHT+IF5kLZ1oDYmCwd+Q2yO9LDYxgWqxbEDziBU4HPttPXf77FeFJAJYmdeVcw4vhe7MetvedZQ X-Received: by 2002:a05:6358:491a:b0:19f:174c:7fa0 with SMTP id e5c5f4694b2df-19f69d8b87dmr443349255d.24.1718262348011; Thu, 13 Jun 2024 00:05:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718262347; cv=pass; d=google.com; s=arc-20160816; b=urp6DwcQLVH5inUNtWDKWd/OG8gefZyExO30QZB5rahATKLqMKnPSit5LKuWofUa0m mqbT8FaYW9cHt/cVcxI8VI++euEOeW3SIvbDefD9XZQ45Z3Cx6ofJWXxyctrqZ7smKhV qoaaW1RW7nokQ+Jc+vYG0jdzsiXrvNzpzHFNfaDcnJbP+aNYIVXWt/30xZoY3mSzKePC L6CdI56GZZbsLcvTRvCHnwhBIZmshscjTuZqmGiWv2+jHFX77AA8cBzXwtrFwfw6gc3q ewLXBtCZ1F7NR0A+AcWVuBHOQmWS3i/LGHcsdlzCBWlnZzhq3TwMhsml/FmIQrrQZsBr CbZg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=drA76IDECayT317ZaKBjGX9PcBu+0gorkvMz8yjsoxU=; fh=YxBYJdZoc733cuPjrFlyIozvfhwcjybgrMoh7q+aYqo=; b=XoiJGgCGzzE0f0kd1W3yjtyWXAsqxRBi1/GCDMfbm5vvAWX/gJw6k6i62vs1121kSv xQiW+whyfxCdiP85zY7A80+0G5yyt4zMfcwPaqZRUbWC9taT2NY3BwQwqHeNIWSq/16n sL32v3s03qxUY1eiNQxTmSuDVKI6muMnat4V0LPnM4w55mshhSMDa/eBqsZe7FxPMmiP sdNarSwV0Qbp2Dr06kCZfQaTh7I/dXoUSUl2RDyJvvnbjgebC/4qWP33azKB5vS80yjM P2AfQXxgNWhNgEhI+JklRQNhPR45l7WaA2IRKUaWbG3EUcb5EzKu+omw4t7deKxRDZZW qdZQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=P7jNLZKM; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-212665-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212665-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-6fee67b7637si752062a12.785.2024.06.13.00.05.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 00:05:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212665-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=P7jNLZKM; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-212665-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212665-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 24E07B21C61 for ; Thu, 13 Jun 2024 06:59:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FAA3137C31; Thu, 13 Jun 2024 06:59:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="P7jNLZKM" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DEDA13791E for ; Thu, 13 Jun 2024 06:59:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718261980; cv=none; b=POjN80uRs6mmUG/tpHerk+I6vS6RAHnINQvBG8OsyND6LuxYumzgte2+u3pq6qzJ0DN9YXTjGzOZom/MExZ4L/GmnikPk4FJLZpRewc42K4rZrfdyD3j8ulEuBeDtvGn/DRBqoxhTKbCa6eCGWZvvMlOdUfk6QO5hHJfyMk9pEg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718261980; c=relaxed/simple; bh=pJwjntH5QMkuPUwNOFSmpR3KkB6NULCVjIIWybM6pWU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Hf3OXJFjF6oUTS6h4GkNj6Fp+mPUsbhm6qbCwKDSCCQSyfRY32ckSKbiqq4e44UbKW37VzC2FOfAWmBGSqhqFtr6Z2eUuL7WwMLMBwCf5NTUV53HK7L5WGa6AYRE3V9IZPPsXnjNbaja/YtwjPm/sWWcGe4RpvjmypzYTRvtDq8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=P7jNLZKM; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718261977; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=drA76IDECayT317ZaKBjGX9PcBu+0gorkvMz8yjsoxU=; b=P7jNLZKMTCuGmu/EM5gKsLH7vtT5doD+3OeZmJdp7DhRu0cNVtjSlkYmYXBUVRjnYB3XYS 6lO/Vl0UBwqbOCTXNj0HTWuUoRODMuS23/XVOU/LKDnTuxwGSeJqOLCrhehO/SEyKFqg7U 2Rta/EY8AH6oQECIDjBSfALva11Q8GA= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-167-5QA2bsrNNmyw0T9g7Nt4nQ-1; Thu, 13 Jun 2024 02:59:35 -0400 X-MC-Unique: 5QA2bsrNNmyw0T9g7Nt4nQ-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-35f1f958b7dso415644f8f.3 for ; Wed, 12 Jun 2024 23:59:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718261974; x=1718866774; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=drA76IDECayT317ZaKBjGX9PcBu+0gorkvMz8yjsoxU=; b=k2L0UctIiqRaVSLEr3ofv3S20U44NE9azrvNhbgaD9Nn44EZ0MotZy+LXKh9wd9Uyt 7BEryQLO0nUnUVcNZTcc8TJlMwX7BEeXNFxQk4FUnHxokF6e1/oYe5Dhd6syDqKotQZr cvIM1TRrOs55IWHd103r6D2WG6ntT0gC0eG8ILex+apY4HhmYSMJ2FDDWBGF20itEsI1 3kSJAgW61n8Kexu4OjsEzJvPAsR7bOW30w2YaPa/VsV/JMmuIgmWANAyjxxxmTIC4kbT kN+P7a/txLlRV19MeAphtCL6+axc/5AytL8WHsZONsAkU1HgYtf0ztQc5C7QUPnq8EUx f8MQ== X-Forwarded-Encrypted: i=1; AJvYcCVaIUf/XcQdfsZF3P62+FcWQxCqWOTPs/Y5zWt6/Vs2GiaoB6y4sXNNIRPJo4AxUvJG52JkTxtKtyk6YyTPelbisYGlDx7eSwCKFXmn X-Gm-Message-State: AOJu0Yz9KVe7G/siDd4htl6onp9bWD9+tajYKNpAMdPO0Ojp6lQ+Kr+p 4o8eYUzUuuWmqx30v88tvsHPMUP1h9fjvmXe/qptIdnLcfpXzZu5CWAmN8QooWXFo26lXwi11BD dfX4Mo0unqrwr3Mj9SMbsEx+sof/1/OubP6htKcytKBj3fqJnELiuDql/eq4DPQ== X-Received: by 2002:adf:fc4a:0:b0:35f:1c26:b68d with SMTP id ffacd0b85a97d-35fe89433c6mr2681769f8f.60.1718261973685; Wed, 12 Jun 2024 23:59:33 -0700 (PDT) X-Received: by 2002:adf:fc4a:0:b0:35f:1c26:b68d with SMTP id ffacd0b85a97d-35fe89433c6mr2681752f8f.60.1718261973066; Wed, 12 Jun 2024 23:59:33 -0700 (PDT) Received: from redhat.com ([2a0d:6fc7:341:5539:9b1a:2e49:4aac:204e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-360750f22e8sm779696f8f.80.2024.06.12.23.59.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 23:59:32 -0700 (PDT) Date: Thu, 13 Jun 2024 02:59:29 -0400 From: "Michael S. Tsirkin" To: Cindy Lu Cc: dtatulea@nvidia.com, jasowang@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org Subject: Re: [PATCH 1/2] vdpa: support set mac address from vdpa tool Message-ID: <20240613025548-mutt-send-email-mst@kernel.org> References: <20240611053239.516996-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240611053239.516996-1-lulu@redhat.com> On Tue, Jun 11, 2024 at 01:32:32PM +0800, Cindy Lu wrote: > Add new UAPI to support the mac address from vdpa tool > Function vdpa_nl_cmd_dev_config_set_doit() will get the > MAC address from the vdpa tool and then set it to the device. > > The usage is: vdpa dev set name vdpa_name mac **:**:**:**:**:** > > Here is sample: > root@L1# vdpa -jp dev config show vdpa0 > { > "config": { > "vdpa0": { > "mac": "82:4d:e9:5d:d7:e6", > "link ": "up", > "link_announce ": false, > "mtu": 1500 > } > } > } > > root@L1# vdpa dev set name vdpa0 mac 00:11:22:33:44:55 > > root@L1# vdpa -jp dev config show vdpa0 > { > "config": { > "vdpa0": { > "mac": "00:11:22:33:44:55", > "link ": "up", > "link_announce ": false, > "mtu": 1500 > } > } > } > > Signed-off-by: Cindy Lu I think actually the idea of allowing provisioning by specifying config of the device is actually valid. However - the name SET_CONFIG makes people think this allows writing even when e.g. device is assigned to guest - having the internal api be mac specific is weird Shouldn't config be an attribute maybe, not a new command? > --- > drivers/vdpa/vdpa.c | 71 +++++++++++++++++++++++++++++++++++++++ > include/linux/vdpa.h | 2 ++ > include/uapi/linux/vdpa.h | 1 + > 3 files changed, 74 insertions(+) > > diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c > index a7612e0783b3..347ae6e7749d 100644 > --- a/drivers/vdpa/vdpa.c > +++ b/drivers/vdpa/vdpa.c > @@ -1149,6 +1149,72 @@ static int vdpa_nl_cmd_dev_config_get_doit(struct sk_buff *skb, struct genl_info > return err; > } > > +static int vdpa_nl_cmd_dev_config_set_doit(struct sk_buff *skb, > + struct genl_info *info) > +{ > + struct vdpa_dev_set_config set_config = {}; > + struct nlattr **nl_attrs = info->attrs; > + struct vdpa_mgmt_dev *mdev; > + const u8 *macaddr; > + const char *name; > + int err = 0; > + struct device *dev; > + struct vdpa_device *vdev; > + > + if (!info->attrs[VDPA_ATTR_DEV_NAME]) > + return -EINVAL; > + > + name = nla_data(info->attrs[VDPA_ATTR_DEV_NAME]); > + > + down_write(&vdpa_dev_lock); > + dev = bus_find_device(&vdpa_bus, NULL, name, vdpa_name_match); > + if (!dev) { > + NL_SET_ERR_MSG_MOD(info->extack, "device not found"); > + err = -ENODEV; > + goto dev_err; > + } > + vdev = container_of(dev, struct vdpa_device, dev); > + if (!vdev->mdev) { > + NL_SET_ERR_MSG_MOD( > + info->extack, > + "Fail to find the specified management device"); > + err = -EINVAL; > + goto mdev_err; > + } > + mdev = vdev->mdev; > + if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MACADDR]) { > + if (!(mdev->supported_features & BIT_ULL(VIRTIO_NET_F_MAC))) { > + NL_SET_ERR_MSG_FMT_MOD( > + info->extack, > + "Missing features 0x%llx for provided attributes", > + BIT_ULL(VIRTIO_NET_F_MAC)); > + err = -EINVAL; > + goto mdev_err; > + } > + macaddr = nla_data(nl_attrs[VDPA_ATTR_DEV_NET_CFG_MACADDR]); > + memcpy(set_config.net.mac, macaddr, ETH_ALEN); > + set_config.mask |= BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MACADDR); > + if (mdev->ops->set_mac) { > + err = mdev->ops->set_mac(mdev, vdev, &set_config); > + } else { > + NL_SET_ERR_MSG_FMT_MOD( > + info->extack, > + "%s device not support set mac address ", name); > + } > + > + } else { > + NL_SET_ERR_MSG_FMT_MOD(info->extack, > + "%s device not support this config ", > + name); > + } > + > +mdev_err: > + put_device(dev); > +dev_err: > + up_write(&vdpa_dev_lock); > + return err; > +} > + > static int vdpa_dev_config_dump(struct device *dev, void *data) > { > struct vdpa_device *vdev = container_of(dev, struct vdpa_device, dev); > @@ -1285,6 +1351,11 @@ static const struct genl_ops vdpa_nl_ops[] = { > .doit = vdpa_nl_cmd_dev_stats_get_doit, > .flags = GENL_ADMIN_PERM, > }, > + { > + .cmd = VDPA_CMD_DEV_CONFIG_SET, > + .doit = vdpa_nl_cmd_dev_config_set_doit, > + .flags = GENL_ADMIN_PERM, > + }, > }; > > static struct genl_family vdpa_nl_family __ro_after_init = { > diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h > index db15ac07f8a6..c97f4f1da753 100644 > --- a/include/linux/vdpa.h > +++ b/include/linux/vdpa.h > @@ -581,6 +581,8 @@ struct vdpa_mgmtdev_ops { > int (*dev_add)(struct vdpa_mgmt_dev *mdev, const char *name, > const struct vdpa_dev_set_config *config); > void (*dev_del)(struct vdpa_mgmt_dev *mdev, struct vdpa_device *dev); > + int (*set_mac)(struct vdpa_mgmt_dev *mdev, struct vdpa_device *dev, > + const struct vdpa_dev_set_config *config); > }; > > /** > diff --git a/include/uapi/linux/vdpa.h b/include/uapi/linux/vdpa.h > index 54b649ab0f22..53f249fb26bc 100644 > --- a/include/uapi/linux/vdpa.h > +++ b/include/uapi/linux/vdpa.h > @@ -19,6 +19,7 @@ enum vdpa_command { > VDPA_CMD_DEV_GET, /* can dump */ > VDPA_CMD_DEV_CONFIG_GET, /* can dump */ > VDPA_CMD_DEV_VSTATS_GET, > + VDPA_CMD_DEV_CONFIG_SET, > }; > > enum vdpa_attr { > -- > 2.45.0