From: "Michael S. Tsirkin" <mst@redhat.com>
To: Si-Wei Liu <si-wei.liu@oracle.com>
Cc: alexander.h.duyck@intel.com, virtio-dev@lists.oasis-open.org,
jiri@resnulli.us, kubakici@wp.pl, sridhar.samudrala@intel.com,
virtualization@lists.linux-foundation.org,
netdev@vger.kernel.org, davem@davemloft.net
Subject: Re: [RFC PATCH 1/3] qemu: virtio-bypass should explicitly bind to a passthrough device
Date: Tue, 3 Apr 2018 15:25:21 +0300 [thread overview]
Message-ID: <20180403152308-mutt-send-email-mst__26973.7346134663$1522758226$gmane$org@kernel.org> (raw)
In-Reply-To: <1522573990-5242-2-git-send-email-si-wei.liu@oracle.com>
On Sun, Apr 01, 2018 at 05:13:08AM -0400, Si-Wei Liu wrote:
> @@ -896,6 +898,68 @@ void qmp_device_del(const char *id, Error **errp)
> }
> }
>
> +int pci_get_busdevfn_by_id(const char *id, uint16_t *busnr,
> + uint16_t *devfn, Error **errp)
> +{
> + uint16_t busnum = 0, slot = 0, func = 0;
> + const char *pc, *pd, *pe;
> + Error *local_err = NULL;
> + ObjectClass *class;
> + char value[1024];
> + BusState *bus;
> + uint64_t u64;
> +
> + if (!(pc = strchr(id, ':'))) {
> + error_setg(errp, "Invalid id: backup=%s, "
> + "correct format should be backup="
> + "'<bus-id>:<slot>[.<function>]'", id);
> + return -1;
> + }
> + get_opt_name(value, sizeof(value), id, ':');
> + if (pc != id + 1) {
> + bus = qbus_find(value, errp);
> + if (!bus)
> + return -1;
> +
> + class = object_get_class(OBJECT(bus));
> + if (class != object_class_by_name(TYPE_PCI_BUS) &&
> + class != object_class_by_name(TYPE_PCIE_BUS)) {
> + error_setg(errp, "%s is not a device on pci bus", id);
> + return -1;
> + }
> + busnum = (uint16_t)pci_bus_num(PCI_BUS(bus));
> + }
pci_bus_num is almost always a bug if not done within
a context of a PCI host, bridge, etc.
In particular this will not DTRT if run before guest assigns bus
numbers.
> +
> + if (!devfn)
> + goto out;
> +
> + pd = strchr(pc, '.');
> + pe = get_opt_name(value, sizeof(value), pc + 1, '.');
> + if (pe != pc + 1) {
> + parse_option_number("slot", value, &u64, &local_err);
> + if (local_err) {
> + error_propagate(errp, local_err);
> + return -1;
> + }
> + slot = (uint16_t)u64;
> + }
> + if (pd && *(pd + 1) != '\0') {
> + parse_option_number("function", pd, &u64, &local_err);
> + if (local_err) {
> + error_propagate(errp, local_err);
> + return -1;
> + }
> + func = (uint16_t)u64;
> + }
> +
> +out:
> + if (busnr)
> + *busnr = busnum;
> + if (devfn)
> + *devfn = ((slot & 0x1F) << 3) | (func & 0x7);
> + return 0;
> +}
> +
> BlockBackend *blk_by_qdev_id(const char *id, Error **errp)
> {
> DeviceState *dev;
> --
> 1.8.3.1
next prev parent reply other threads:[~2018-04-03 12:25 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1522573990-5242-1-git-send-email-si-wei.liu@oracle.com>
[not found] ` <1522573990-5242-4-git-send-email-si-wei.liu@oracle.com>
2018-04-03 12:20 ` [RFC PATCH 3/3] virtio_net: make lower netdevs for virtio_bypass hidden Michael S. Tsirkin
[not found] ` <20180403151915-mutt-send-email-mst@kernel.org>
2018-04-04 8:03 ` [virtio-dev] " Siwei Liu
[not found] ` <1522573990-5242-2-git-send-email-si-wei.liu@oracle.com>
2018-04-03 12:25 ` Michael S. Tsirkin [this message]
[not found] ` <20180403152308-mutt-send-email-mst@kernel.org>
2018-04-04 8:02 ` [virtio-dev] Re: [RFC PATCH 1/3] qemu: virtio-bypass should explicitly bind to a passthrough device Siwei Liu
[not found] ` <CADGSJ23jr7xrq8h9rFHLtXkbpsB+AK8wcUzOQnpeftbhiYdOvA@mail.gmail.com>
[not found] ` <d666b8a9-9ff8-4a56-0faa-ef3d0bf81d25@redhat.com>
2018-04-07 2:54 ` Siwei Liu
[not found] ` <1522573990-5242-3-git-send-email-si-wei.liu@oracle.com>
[not found] ` <8b589cd2-1abc-59c2-99f1-96df8174bb6b@gmail.com>
2018-04-03 7:40 ` [RFC PATCH 2/3] netdev: kernel-only IFF_HIDDEN netdevice Siwei Liu
2018-04-03 15:42 ` Jiri Pirko
[not found] ` <20180403154210.GK3313@nanopsycho>
2018-04-03 19:23 ` Siwei Liu
[not found] ` <3bdfc39f-4935-2433-7982-9ce28c3aa166@gmail.com>
2018-04-04 6:19 ` Jiri Pirko
2018-04-04 7:36 ` Siwei Liu
[not found] ` <20180404061945.GN3313@nanopsycho>
2018-04-04 8:01 ` Siwei Liu
2018-04-04 8:28 ` Siwei Liu
[not found] ` <CADGSJ23Zr7_CLMr1W9qhcWux59+aCvFdTg_nQ7Mmp5B-FWL8=Q@mail.gmail.com>
[not found] ` <54accf73-e6cc-e03f-6a1c-34e1bbd78047@gmail.com>
2018-04-04 17:37 ` David Miller
2018-04-04 18:02 ` Siwei Liu
[not found] ` <20180404.133749.1802514210170809419.davem@davemloft.net>
2018-04-04 18:20 ` Jiri Pirko
2018-04-07 2:32 ` Siwei Liu
2018-04-07 3:19 ` Andrew Lunn
2018-04-09 22:07 ` Siwei Liu
[not found] ` <CADGSJ211kA5ktADbwv2f4ma_ooBmYW4r7YwzGD2G_Gw5+wv5rw@mail.gmail.com>
2018-04-09 22:15 ` Andrew Lunn
[not found] ` <20180409221523.GH562@lunn.ch>
2018-04-09 22:30 ` Siwei Liu
2018-04-09 23:03 ` Stephen Hemminger
[not found] ` <20180409160348.12f8a6d9@xeon-e3>
2018-04-09 23:31 ` Siwei Liu
2018-04-08 16:32 ` David Miller
[not found] ` <20180408.123207.2294740686493951200.davem@davemloft.net>
2018-04-10 6:48 ` Siwei Liu
[not found] ` <CADGSJ233AmbBrTP-A_u3-5fkr=HUJka_xcSNWxO1HWGua1J92Q@mail.gmail.com>
2018-04-18 0:26 ` Siwei Liu
[not found] ` <CADGSJ21nQ1BQctfZcThpmOcOUrpqLfG71jsh2trb1utVjNQH=Q@mail.gmail.com>
2018-04-18 23:33 ` [virtio-dev] " Samudrala, Sridhar
[not found] ` <1f3af59f-fd64-cc0d-f9eb-668636c52db4@intel.com>
2018-04-19 4:41 ` Michael S. Tsirkin
[not found] ` <20180419072003-mutt-send-email-mst@kernel.org>
2018-04-19 5:00 ` Samudrala, Sridhar
[not found] ` <4e029524-d542-0f12-bfdb-7c8a2f198e28@intel.com>
2018-04-19 5:07 ` Michael S. Tsirkin
[not found] ` <20180419080215-mutt-send-email-mst@kernel.org>
2018-04-19 6:10 ` Samudrala, Sridhar
[not found] ` <5d5f1e52-bddf-5551-bdea-8e7b408b39b9@intel.com>
2018-04-19 6:43 ` Siwei Liu
2018-04-19 6:31 ` Siwei Liu
[not found] ` <CADGSJ22qmdzY8AiOfQdFdmR7T6rehTp-hHHj1U10XGad0bTb8A@mail.gmail.com>
[not found] ` <b0f5e27b-0be1-311e-f3f3-f79af5cd4521@gmail.com>
2018-04-04 17:42 ` David Miller
2018-04-04 17:44 ` Stephen Hemminger
2018-04-04 20:08 ` Andrew Lunn
2018-04-03 17:35 ` Stephen Hemminger
[not found] ` <20180403103536.6ec1450c@xeon-e3>
[not found] ` <CADGSJ23vZdtQzWdc_6M_Hr4MUej--wgvJ785DwRF3VaPWS1rpA@mail.gmail.com>
[not found] ` <20180403160834.51594373@xeon-e3>
2018-04-06 21:29 ` Siwei Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='20180403152308-mutt-send-email-mst__26973.7346134663$1522758226$gmane$org@kernel.org' \
--to=mst@redhat.com \
--cc=alexander.h.duyck@intel.com \
--cc=davem@davemloft.net \
--cc=jiri@resnulli.us \
--cc=kubakici@wp.pl \
--cc=netdev@vger.kernel.org \
--cc=si-wei.liu@oracle.com \
--cc=sridhar.samudrala@intel.com \
--cc=virtio-dev@lists.oasis-open.org \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).