From: George Dunlap <george.dunlap@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: george.dunlap@eu.citrix.com
Subject: [PATCH 4 of 4 v2] xl: Add pci_assignable_add and remove commands
Date: Fri, 11 May 2012 14:31:33 +0100 [thread overview]
Message-ID: <ba3d30d721eef8c31b33.1336743093@kodo2> (raw)
In-Reply-To: <patchbomb.1336743089@kodo2>
pci-assignable-add will always store the driver rebind path, but
pci-assignable-remove will only actually rebind if asked to do so.
v2:
- Use libxl_device_pci_init() instead of memset()
- Call xlu_cfg_destroy() properly
Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
diff -r 5e21532dab5b -r ba3d30d721ee docs/man/xl.pod.1
--- a/docs/man/xl.pod.1 Fri May 11 13:55:04 2012 +0100
+++ b/docs/man/xl.pod.1 Fri May 11 14:19:50 2012 +0100
@@ -1026,6 +1026,26 @@ These are devices in the system which ar
available for passthrough and are bound to a suitable PCI
backend driver in domain 0 rather than a real driver.
+=item B<pci-assignable-add> I<BDF>
+
+Make the device at PCI Bus/Device/Function BDF assignable to guests. This
+will bind the device to the pciback driver. If it is already bound to a
+driver, it will first be unbound, and the original driver stored so that it
+can be re-bound to the same driver later if desired.
+
+CAUTION: This will make the device unusable by Domain 0 until it is
+returned with pci-assignable-remove. Care should therefore be taken
+not to do this on a device critical to domain 0's operation, such as
+storage controllers, network interfaces, or GPUs that are currently
+being used.
+
+=item B<pci-assignable-remove> [I<-r>] I<BDF>
+
+Make the device at PCI Bus/Device/Function BDF assignable to guests. This
+will at least unbind the device from pciback. If the -r option is specified,
+it will also attempt to re-bind the device to its original driver, making it
+usable by Domain 0 again.
+
=item B<pci-attach> I<domain-id> I<BDF>
Hot-plug a new pass-through pci device to the specified domain.
diff -r 5e21532dab5b -r ba3d30d721ee tools/libxl/xl.h
--- a/tools/libxl/xl.h Fri May 11 13:55:04 2012 +0100
+++ b/tools/libxl/xl.h Fri May 11 14:19:50 2012 +0100
@@ -36,6 +36,8 @@ int main_vncviewer(int argc, char **argv
int main_pcilist(int argc, char **argv);
int main_pcidetach(int argc, char **argv);
int main_pciattach(int argc, char **argv);
+int main_pciassignable_add(int argc, char **argv);
+int main_pciassignable_remove(int argc, char **argv);
int main_pciassignable_list(int argc, char **argv);
int main_restore(int argc, char **argv);
int main_migrate_receive(int argc, char **argv);
diff -r 5e21532dab5b -r ba3d30d721ee tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Fri May 11 13:55:04 2012 +0100
+++ b/tools/libxl/xl_cmdimpl.c Fri May 11 14:19:50 2012 +0100
@@ -2368,6 +2368,86 @@ int main_pciassignable_list(int argc, ch
return 0;
}
+static void pciassignable_add(const char *bdf, int rebind)
+{
+ libxl_device_pci pcidev;
+ XLU_Config *config;
+
+ libxl_device_pci_init(&pcidev);
+
+ config = xlu_cfg_init(stderr, "command line");
+ if (!config) { perror("xlu_cfg_inig"); exit(-1); }
+
+ if (xlu_pci_parse_bdf(config, &pcidev, bdf)) {
+ fprintf(stderr, "pci-assignable-add: malformed BDF specification \"%s\"\n", bdf);
+ exit(2);
+ }
+ libxl_device_pci_assignable_add(ctx, &pcidev, rebind);
+
+ libxl_device_pci_dispose(&pcidev);
+ xlu_cfg_destroy(config);
+}
+
+int main_pciassignable_add(int argc, char **argv)
+{
+ int opt;
+ const char *bdf = NULL;
+
+ while ((opt = def_getopt(argc, argv, "", "pci-assignable-add", 1)) != -1) {
+ switch (opt) {
+ case 0: case 2:
+ return opt;
+ }
+ }
+
+ bdf = argv[optind];
+
+ pciassignable_add(bdf, 1);
+ return 0;
+}
+
+static void pciassignable_remove(const char *bdf, int rebind)
+{
+ libxl_device_pci pcidev;
+ XLU_Config *config;
+
+ libxl_device_pci_init(&pcidev);
+
+ config = xlu_cfg_init(stderr, "command line");
+ if (!config) { perror("xlu_cfg_inig"); exit(-1); }
+
+ if (xlu_pci_parse_bdf(config, &pcidev, bdf)) {
+ fprintf(stderr, "pci-assignable-remove: malformed BDF specification \"%s\"\n", bdf);
+ exit(2);
+ }
+ libxl_device_pci_assignable_remove(ctx, &pcidev, rebind);
+
+ libxl_device_pci_dispose(&pcidev);
+ xlu_cfg_destroy(config);
+}
+
+int main_pciassignable_remove(int argc, char **argv)
+{
+ int opt;
+ const char *bdf = NULL;
+ int rebind = 0;
+
+ while ((opt = def_getopt(argc, argv, "r", "pci-assignable-remove", 1)) != -1) {
+ switch (opt) {
+ case 0: case 2:
+ return opt;
+ case 'r':
+ rebind=1;
+ break;
+ }
+ }
+
+ bdf = argv[optind];
+
+ pciassignable_remove(bdf, rebind);
+ return 0;
+}
+
static void pause_domain(const char *p)
{
find_domain(p);
diff -r 5e21532dab5b -r ba3d30d721ee tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c Fri May 11 13:55:04 2012 +0100
+++ b/tools/libxl/xl_cmdtable.c Fri May 11 14:19:50 2012 +0100
@@ -86,6 +86,20 @@ struct cmd_spec cmd_table[] = {
"List pass-through pci devices for a domain",
"<Domain>",
},
+ { "pci-assignable-add",
+ &main_pciassignable_add, 0,
+ "Make a device assignable for pci-passthru",
+ "<BDF>",
+ "-h Print this help.\n"
+ },
+ { "pci-assignable-remove",
+ &main_pciassignable_remove, 0,
+ "Remove a device from being assignable",
+ "[options] <BDF>",
+ "-h Print this help.\n"
+ "-r Attempt to re-assign the device to the\n"
+ " original driver"
+ },
{ "pci-assignable-list",
&main_pciassignable_list, 0,
"List all the assignable pci devices",
next prev parent reply other threads:[~2012-05-11 13:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-11 13:31 [PATCH 0 of 4 v2] Add commands to automatically prep devices for pass-through George Dunlap
2012-05-11 13:31 ` [PATCH 1 of 4 v2] libxl: Make a helper function write a BDF to a sysfs path George Dunlap
2012-05-11 13:31 ` [PATCH 2 of 4 v2] libxl: Rename pci_list_assignable to pci_assignable_list George Dunlap
2012-05-11 13:31 ` [PATCH 3 of 4 v2] libxl: Introduce pci_assignable_add and pci_assignable_remove George Dunlap
2012-05-14 9:21 ` Ian Campbell
2012-05-14 10:06 ` George Dunlap
2012-05-21 14:13 ` Konrad Rzeszutek Wilk
2012-05-22 8:15 ` Ian Campbell
2012-05-11 13:31 ` George Dunlap [this message]
2012-05-14 9:24 ` [PATCH 4 of 4 v2] xl: Add pci_assignable_add and remove commands Ian Campbell
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=ba3d30d721eef8c31b33.1336743093@kodo2 \
--to=george.dunlap@eu.citrix.com \
--cc=xen-devel@lists.xensource.com \
/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).