Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp158414lqs; Thu, 13 Jun 2024 06:50:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX6YieE7du/MXddzzzKknaOUwXj9eZ6l93day+1arPOZyOGRyC7n1tiS6voQx7cSZgKPxWe7laKr6axlZOedJAx1OyD49TWlHbMegxeow== X-Google-Smtp-Source: AGHT+IEsUZYonN0bGPnMss4L2Rm+8RmqtUVRJD5S0YfSqvY2FRfcoMaVdwCrl6rwZNj0+4luaXfS X-Received: by 2002:a05:6870:a691:b0:254:a168:cd61 with SMTP id 586e51a60fabf-25514f2b5c9mr5088603fac.58.1718286649815; Thu, 13 Jun 2024 06:50:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718286649; cv=pass; d=google.com; s=arc-20160816; b=OuzecP64qtMxI45jPoNr8WJQ3P/Oz7cN3r0svCzf86nJcbRlmBybA6wniKHob6UZ9X U9D6KFhwhsp/M6SkrIl9TsMIfTegNInTxDPhIOl1drCghiRLfnsnm21Dj/5n6NPDVyJT J0jP5TOrZnF0my6k0TXFziiXrmqdGYOVRIykLR1R5pjj52YTZ6UwQAYttM/ff2m1p4vn mhEKSxONnQJBuvKyxLCFuX2pyYZ62+l8eF2H0wAQtlpvC20VteKicWSX+RRnRmp0Zaxs i/k2QW1cXN+a/npImNxiNu3qMwbxnPD8DRaN7NE4hgwK8T/GjG4IxdFy5mpO39kkfASc FI5g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=y9evobZ56tePgOcIz6BoUUANwCX8e2L9RTd9imGKDRo=; fh=SfD8COGSBxU82cnxQ7z7xsS74xNVHuLnU2XCUsn9HjU=; b=digQpVmQw/2vUPOnACT59Irw1QpZlJjQNsDw2h5w3sGXXJvKUbFBPA0HdLORx0G8BG Z7cuVP/YDjPZo4zPAMlPNVu45nsBtKI/3IAmgaTHsdqZUAS2eYDQvJzxUzy5yF8izyUA inqsRq1Q9OCoPuE2xIUci6MuNit3Ksqua+NMC3lxbWJwVz/McVAes9JBpIxOSyV4yz6R qTTQLgnVXtLoiDLz/3YSdpP8OyMTJu04x2TcLW3JxkO58Pv9M2O5Jqg4D9fkRsob0xsk 2QsQYRimlSNX/PSmYS1OczjaKFtWZ6CzOGmdZppwQXWzbSMQ0lxYH7Uikj4s/4EAABql dkVQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gn58lC0F; 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-213322-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213322-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6fee310cb69si1374385a12.389.2024.06.13.06.50.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 06:50:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213322-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gn58lC0F; 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-213322-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213322-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 03CEF28C31E for ; Thu, 13 Jun 2024 13:30:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B8CA0144D1F; Thu, 13 Jun 2024 13:29:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gn58lC0F" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 EEA461448FF for ; Thu, 13 Jun 2024 13:29:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718285387; cv=none; b=poUEgwoyGiuxNlmqXdIijzEMbKhpZiDr+lY0PQu8dkNQYqwI/320BWBU7YDR1X1lYb43JWepbG0wwerU4hq3cQGV/I9HIkqTzfmhw5n6PR99ef8KYnY9LIsAvxXm+Edku2i0GGqucSD7v64PnbW2DJgYkXMeuYfbi1+DZVq0cSI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718285387; c=relaxed/simple; bh=EwDYV86apdp1y3FgvqhXoUdcP6ZAutdGUFD8nB4Rupc=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=c/bwsozwXH5I7oWSZDAJnLwUiM+5sukSrQrtJiJT2Zhdx795MqEPBRLKV+LYCYfJoqdvfV2X9aLVADTxSPjN7ZC/3zfMuIN102XS23mPeFu3d5/h8dXd2nl8TeVEnoroEDZMHu0AcRkXJNiRZTiyhj9LTGFF2GQk8Xea+H/AF9g= 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=gn58lC0F; arc=none smtp.client-ip=170.10.133.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=1718285385; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y9evobZ56tePgOcIz6BoUUANwCX8e2L9RTd9imGKDRo=; b=gn58lC0F7YRH1Ed+QnaEAiKC4OtiMuUVk+4wo2SmvW5BETV+97QmQnD89nVSDLcDgnlTDL W6in+YzPTT17GVDZn/Zi8lWp7OyMyK6A/TwNYOCVTbpZOUhzCtKVeWZNCULac1+pB46fr6 TURmVhP8g8/kB78o/Y2ezjd/uOIzcHA= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-86-sR_Cn4GDOR28Cu_fv7HBog-1; Thu, 13 Jun 2024 09:29:43 -0400 X-MC-Unique: sR_Cn4GDOR28Cu_fv7HBog-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a6f0f7d6eaaso231264066b.1 for ; Thu, 13 Jun 2024 06:29:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718285382; x=1718890182; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y9evobZ56tePgOcIz6BoUUANwCX8e2L9RTd9imGKDRo=; b=skglsPBHtOMTtJuO2UqOviZQULR+uVhkawoFAdOVVbtHT5i5PoARoRHaNasgWTzt+g 4A0pSCbtFR6Tu4LvQ/vAdpYuzABOmCKEpt+1QghyZv8Oi9IO4GIRNKcUVTu/JZ1kO6Qw /G4dUbqKLNs5CeYGur6OhACzhZjtWLcSt2hVZeGDl9o7o3Fshh2TispI+564GyjY6N1j RfJwbE/uhArpEhAGFrLBMS0h+oe4rnNdgwiYtGocWoz3SZDv6JuxUohthyXLepL1GQfv eHfhpMm157JkzgP6ZERLI0BINLrAVMFAQrp1aQwSJZFJyg+GFwQCSxR1LD24J/GicADh mynw== X-Forwarded-Encrypted: i=1; AJvYcCXUzDhuye6sNJEtcPhQsZ8/P6uKVZxGiw5kmS3itRBkiIhWe9FHFOr+2LOdvDtntiYWuNqecyK8Rk58P6tGCvdS+FQjXzxRB+EWPlU1 X-Gm-Message-State: AOJu0YxYxdCAvBMBIyrsRrBYDA4s1QSBkCHfcQKqeCHB9D41YVAE8+a/ 56kAiDcCyQ3yaRv5jHCIoBrnSFYf0/gPboyk9Fm3ZJXUJW865XkTmPb7sW9CMpprWpfoyiqPRtd 0xwwC5okFOETXYSvjHdsvCQQCWahXTvP/lK/AdMeTlhjHtbco79WMMtC5xHf5eeoaE/C6deYiaD xBbUzRXJpLLGXg/OXPYyJP6ubTJbQyxaH+Vmhr X-Received: by 2002:a17:906:f2cf:b0:a6f:1c0e:6776 with SMTP id a640c23a62f3a-a6f5240f021mr181403366b.16.1718285382606; Thu, 13 Jun 2024 06:29:42 -0700 (PDT) X-Received: by 2002:a17:906:f2cf:b0:a6f:1c0e:6776 with SMTP id a640c23a62f3a-a6f5240f021mr181401766b.16.1718285382121; Thu, 13 Jun 2024 06:29:42 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240611053239.516996-1-lulu@redhat.com> <20240613025548-mutt-send-email-mst@kernel.org> In-Reply-To: <20240613025548-mutt-send-email-mst@kernel.org> From: Cindy Lu Date: Thu, 13 Jun 2024 21:29:04 +0800 Message-ID: Subject: Re: [PATCH 1/2] vdpa: support set mac address from vdpa tool To: "Michael S. Tsirkin" 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jun 13, 2024 at 2:59=E2=80=AFPM Michael S. Tsirkin = wrote: > > 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? > Got it. Thanks, Michael. I will change this. Thanks Cindy > > > --- > > 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(struc= t 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 =3D {}; > > + struct nlattr **nl_attrs =3D info->attrs; > > + struct vdpa_mgmt_dev *mdev; > > + const u8 *macaddr; > > + const char *name; > > + int err =3D 0; > > + struct device *dev; > > + struct vdpa_device *vdev; > > + > > + if (!info->attrs[VDPA_ATTR_DEV_NAME]) > > + return -EINVAL; > > + > > + name =3D nla_data(info->attrs[VDPA_ATTR_DEV_NAME]); > > + > > + down_write(&vdpa_dev_lock); > > + dev =3D bus_find_device(&vdpa_bus, NULL, name, vdpa_name_match); > > + if (!dev) { > > + NL_SET_ERR_MSG_MOD(info->extack, "device not found"); > > + err =3D -ENODEV; > > + goto dev_err; > > + } > > + vdev =3D 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 =3D -EINVAL; > > + goto mdev_err; > > + } > > + mdev =3D 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 att= ributes", > > + BIT_ULL(VIRTIO_NET_F_MAC)); > > + err =3D -EINVAL; > > + goto mdev_err; > > + } > > + macaddr =3D nla_data(nl_attrs[VDPA_ATTR_DEV_NET_CFG_MACAD= DR]); > > + memcpy(set_config.net.mac, macaddr, ETH_ALEN); > > + set_config.mask |=3D BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MACADD= R); > > + if (mdev->ops->set_mac) { > > + err =3D mdev->ops->set_mac(mdev, vdev, &set_confi= g); > > + } 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 =3D container_of(dev, struct vdpa_device= , dev); > > @@ -1285,6 +1351,11 @@ static const struct genl_ops vdpa_nl_ops[] =3D { > > .doit =3D vdpa_nl_cmd_dev_stats_get_doit, > > .flags =3D GENL_ADMIN_PERM, > > }, > > + { > > + .cmd =3D VDPA_CMD_DEV_CONFIG_SET, > > + .doit =3D vdpa_nl_cmd_dev_config_set_doit, > > + .flags =3D GENL_ADMIN_PERM, > > + }, > > }; > > > > static struct genl_family vdpa_nl_family __ro_after_init =3D { > > 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 *d= ev); > > + int (*set_mac)(struct vdpa_mgmt_dev *mdev, struct vdpa_device *de= v, > > + 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 >