Skip to content

Commit d271ab2

Browse files
committed
Merge tag 'for-linus-5.6-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip
Pull xen updates from Juergen Gross: - fix a bug introduced in 5.5 in the Xen gntdev driver - fix the Xen balloon driver when running on ancient Xen versions - allow Xen stubdoms to control interrupt enable flags of passed-through PCI cards - release resources in Xen backends under memory pressure * tag 'for-linus-5.6-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip: xen/blkback: Consistently insert one empty line between functions xen/blkback: Remove unnecessary static variable name prefixes xen/blkback: Squeeze page pools if a memory pressure is detected xenbus/backend: Protect xenbus callback with lock xenbus/backend: Add memory pressure handler callback xen/gntdev: Do not use mm notifiers with autotranslating guests xen/balloon: Support xend-based toolstack take two xen-pciback: optionally allow interrupt enable flag writes
2 parents 2634744 + 8557bbe commit d271ab2

File tree

16 files changed

+346
-39
lines changed

16 files changed

+346
-39
lines changed

Documentation/ABI/testing/sysfs-driver-pciback

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,16 @@ Description:
1111
#echo 00:19.0-E0:2:FF > /sys/bus/pci/drivers/pciback/quirks
1212
will allow the guest to read and write to the configuration
1313
register 0x0E.
14+
15+
What: /sys/bus/pci/drivers/pciback/allow_interrupt_control
16+
Date: Jan 2020
17+
KernelVersion: 5.6
18+
19+
Description:
20+
List of devices which can have interrupt control flag (INTx,
21+
MSI, MSI-X) set by a connected guest. It is meant to be set
22+
only when the guest is a stubdomain hosting device model (qemu)
23+
and the actual device is assigned to a HVM. It is not safe
24+
(similar to permissive attribute) to set for a devices assigned
25+
to a PV guest. The device is automatically removed from this
26+
list when the connected pcifront terminates.

Documentation/ABI/testing/sysfs-driver-xen-blkback

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,13 @@ Description:
2525
allocated without being in use. The time is in
2626
seconds, 0 means indefinitely long.
2727
The default is 60 seconds.
28+
29+
What: /sys/module/xen_blkback/parameters/buffer_squeeze_duration_ms
30+
Date: December 2019
31+
KernelVersion: 5.6
32+
Contact: SeongJae Park <[email protected]>
33+
Description:
34+
When memory pressure is reported to blkback this option
35+
controls the duration in milliseconds that blkback will not
36+
cache any page not backed by a grant mapping.
37+
The default is 10ms.

drivers/block/xen-blkback/blkback.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
* IO workloads.
6363
*/
6464

65-
static int xen_blkif_max_buffer_pages = 1024;
66-
module_param_named(max_buffer_pages, xen_blkif_max_buffer_pages, int, 0644);
65+
static int max_buffer_pages = 1024;
66+
module_param_named(max_buffer_pages, max_buffer_pages, int, 0644);
6767
MODULE_PARM_DESC(max_buffer_pages,
6868
"Maximum number of free pages to keep in each block backend buffer");
6969

@@ -78,8 +78,8 @@ MODULE_PARM_DESC(max_buffer_pages,
7878
* algorithm.
7979
*/
8080

81-
static int xen_blkif_max_pgrants = 1056;
82-
module_param_named(max_persistent_grants, xen_blkif_max_pgrants, int, 0644);
81+
static int max_pgrants = 1056;
82+
module_param_named(max_persistent_grants, max_pgrants, int, 0644);
8383
MODULE_PARM_DESC(max_persistent_grants,
8484
"Maximum number of grants to map persistently");
8585

@@ -88,8 +88,8 @@ MODULE_PARM_DESC(max_persistent_grants,
8888
* use. The time is in seconds, 0 means indefinitely long.
8989
*/
9090

91-
static unsigned int xen_blkif_pgrant_timeout = 60;
92-
module_param_named(persistent_grant_unused_seconds, xen_blkif_pgrant_timeout,
91+
static unsigned int pgrant_timeout = 60;
92+
module_param_named(persistent_grant_unused_seconds, pgrant_timeout,
9393
uint, 0644);
9494
MODULE_PARM_DESC(persistent_grant_unused_seconds,
9595
"Time in seconds an unused persistent grant is allowed to "
@@ -137,9 +137,8 @@ module_param(log_stats, int, 0644);
137137

138138
static inline bool persistent_gnt_timeout(struct persistent_gnt *persistent_gnt)
139139
{
140-
return xen_blkif_pgrant_timeout &&
141-
(jiffies - persistent_gnt->last_used >=
142-
HZ * xen_blkif_pgrant_timeout);
140+
return pgrant_timeout && (jiffies - persistent_gnt->last_used >=
141+
HZ * pgrant_timeout);
143142
}
144143

145144
static inline int get_free_page(struct xen_blkif_ring *ring, struct page **page)
@@ -234,7 +233,7 @@ static int add_persistent_gnt(struct xen_blkif_ring *ring,
234233
struct persistent_gnt *this;
235234
struct xen_blkif *blkif = ring->blkif;
236235

237-
if (ring->persistent_gnt_c >= xen_blkif_max_pgrants) {
236+
if (ring->persistent_gnt_c >= max_pgrants) {
238237
if (!blkif->vbd.overflow_max_grants)
239238
blkif->vbd.overflow_max_grants = 1;
240239
return -EBUSY;
@@ -397,14 +396,13 @@ static void purge_persistent_gnt(struct xen_blkif_ring *ring)
397396
goto out;
398397
}
399398

400-
if (ring->persistent_gnt_c < xen_blkif_max_pgrants ||
401-
(ring->persistent_gnt_c == xen_blkif_max_pgrants &&
399+
if (ring->persistent_gnt_c < max_pgrants ||
400+
(ring->persistent_gnt_c == max_pgrants &&
402401
!ring->blkif->vbd.overflow_max_grants)) {
403402
num_clean = 0;
404403
} else {
405-
num_clean = (xen_blkif_max_pgrants / 100) * LRU_PERCENT_CLEAN;
406-
num_clean = ring->persistent_gnt_c - xen_blkif_max_pgrants +
407-
num_clean;
404+
num_clean = (max_pgrants / 100) * LRU_PERCENT_CLEAN;
405+
num_clean = ring->persistent_gnt_c - max_pgrants + num_clean;
408406
num_clean = min(ring->persistent_gnt_c, num_clean);
409407
pr_debug("Going to purge at least %u persistent grants\n",
410408
num_clean);
@@ -599,8 +597,7 @@ static void print_stats(struct xen_blkif_ring *ring)
599597
current->comm, ring->st_oo_req,
600598
ring->st_rd_req, ring->st_wr_req,
601599
ring->st_f_req, ring->st_ds_req,
602-
ring->persistent_gnt_c,
603-
xen_blkif_max_pgrants);
600+
ring->persistent_gnt_c, max_pgrants);
604601
ring->st_print = jiffies + msecs_to_jiffies(10 * 1000);
605602
ring->st_rd_req = 0;
606603
ring->st_wr_req = 0;
@@ -656,8 +653,11 @@ int xen_blkif_schedule(void *arg)
656653
ring->next_lru = jiffies + msecs_to_jiffies(LRU_INTERVAL);
657654
}
658655

659-
/* Shrink if we have more than xen_blkif_max_buffer_pages */
660-
shrink_free_pagepool(ring, xen_blkif_max_buffer_pages);
656+
/* Shrink the free pages pool if it is too large. */
657+
if (time_before(jiffies, blkif->buffer_squeeze_end))
658+
shrink_free_pagepool(ring, 0);
659+
else
660+
shrink_free_pagepool(ring, max_buffer_pages);
661661

662662
if (log_stats && time_after(jiffies, ring->st_print))
663663
print_stats(ring);
@@ -884,7 +884,7 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring,
884884
continue;
885885
}
886886
if (use_persistent_gnts &&
887-
ring->persistent_gnt_c < xen_blkif_max_pgrants) {
887+
ring->persistent_gnt_c < max_pgrants) {
888888
/*
889889
* We are using persistent grants, the grant is
890890
* not mapped but we might have room for it.
@@ -911,7 +911,7 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring,
911911
pages[seg_idx]->persistent_gnt = persistent_gnt;
912912
pr_debug("grant %u added to the tree of persistent grants, using %u/%u\n",
913913
persistent_gnt->gnt, ring->persistent_gnt_c,
914-
xen_blkif_max_pgrants);
914+
max_pgrants);
915915
goto next;
916916
}
917917
if (use_persistent_gnts && !blkif->vbd.overflow_max_grants) {

drivers/block/xen-blkback/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ struct xen_blkif {
319319
/* All rings for this device. */
320320
struct xen_blkif_ring *rings;
321321
unsigned int nr_rings;
322+
unsigned long buffer_squeeze_end;
322323
};
323324

324325
struct seg_buf {

drivers/block/xen-blkback/xenbus.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ static void xenvbd_sysfs_delif(struct xenbus_device *dev)
467467
device_remove_file(&dev->dev, &dev_attr_physical_device);
468468
}
469469

470-
471470
static void xen_vbd_free(struct xen_vbd *vbd)
472471
{
473472
if (vbd->bdev)
@@ -524,6 +523,7 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle,
524523
handle, blkif->domid);
525524
return 0;
526525
}
526+
527527
static int xen_blkbk_remove(struct xenbus_device *dev)
528528
{
529529
struct backend_info *be = dev_get_drvdata(&dev->dev);
@@ -607,6 +607,7 @@ static void xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info
607607
if (err)
608608
dev_warn(&dev->dev, "writing feature-discard (%d)", err);
609609
}
610+
610611
int xen_blkbk_barrier(struct xenbus_transaction xbt,
611612
struct backend_info *be, int state)
612613
{
@@ -691,7 +692,6 @@ static int xen_blkbk_probe(struct xenbus_device *dev,
691692
return err;
692693
}
693694

694-
695695
/*
696696
* Callback received when the hotplug scripts have placed the physical-device
697697
* node. Read it and the mode node, and create a vbd. If the frontend is
@@ -783,7 +783,6 @@ static void backend_changed(struct xenbus_watch *watch,
783783
}
784784
}
785785

786-
787786
/*
788787
* Callback received when the frontend's state changes.
789788
*/
@@ -858,9 +857,27 @@ static void frontend_changed(struct xenbus_device *dev,
858857
}
859858
}
860859

860+
/* Once a memory pressure is detected, squeeze free page pools for a while. */
861+
static unsigned int buffer_squeeze_duration_ms = 10;
862+
module_param_named(buffer_squeeze_duration_ms,
863+
buffer_squeeze_duration_ms, int, 0644);
864+
MODULE_PARM_DESC(buffer_squeeze_duration_ms,
865+
"Duration in ms to squeeze pages buffer when a memory pressure is detected");
861866

862-
/* ** Connection ** */
867+
/*
868+
* Callback received when the memory pressure is detected.
869+
*/
870+
static void reclaim_memory(struct xenbus_device *dev)
871+
{
872+
struct backend_info *be = dev_get_drvdata(&dev->dev);
863873

874+
if (!be)
875+
return;
876+
be->blkif->buffer_squeeze_end = jiffies +
877+
msecs_to_jiffies(buffer_squeeze_duration_ms);
878+
}
879+
880+
/* ** Connection ** */
864881

865882
/*
866883
* Write the physical details regarding the block device to the store, and
@@ -1152,6 +1169,7 @@ static struct xenbus_driver xen_blkbk_driver = {
11521169
.remove = xen_blkbk_remove,
11531170
.otherend_changed = frontend_changed,
11541171
.allow_rebind = true,
1172+
.reclaim_memory = reclaim_memory,
11551173
};
11561174

11571175
int xen_blkif_xenbus_init(void)

drivers/xen/gntdev.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,19 +1006,19 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma)
10061006
}
10071007
mutex_unlock(&priv->lock);
10081008

1009-
/*
1010-
* gntdev takes the address of the PTE in find_grant_ptes() and passes
1011-
* it to the hypervisor in gntdev_map_grant_pages(). The purpose of
1012-
* the notifier is to prevent the hypervisor pointer to the PTE from
1013-
* going stale.
1014-
*
1015-
* Since this vma's mappings can't be touched without the mmap_sem,
1016-
* and we are holding it now, there is no need for the notifier_range
1017-
* locking pattern.
1018-
*/
1019-
mmu_interval_read_begin(&map->notifier);
1020-
10211009
if (use_ptemod) {
1010+
/*
1011+
* gntdev takes the address of the PTE in find_grant_ptes() and
1012+
* passes it to the hypervisor in gntdev_map_grant_pages(). The
1013+
* purpose of the notifier is to prevent the hypervisor pointer
1014+
* to the PTE from going stale.
1015+
*
1016+
* Since this vma's mappings can't be touched without the
1017+
* mmap_sem, and we are holding it now, there is no need for
1018+
* the notifier_range locking pattern.
1019+
*/
1020+
mmu_interval_read_begin(&map->notifier);
1021+
10221022
map->pages_vm_start = vma->vm_start;
10231023
err = apply_to_page_range(vma->vm_mm, vma->vm_start,
10241024
vma->vm_end - vma->vm_start,

drivers/xen/xen-balloon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static void watch_target(struct xenbus_watch *watch,
9494
"%llu", &static_max) == 1))
9595
static_max >>= PAGE_SHIFT - 10;
9696
else
97-
static_max = new_target;
97+
static_max = balloon_stats.current_pages;
9898

9999
target_diff = (xen_pv_domain() || xen_initial_domain()) ? 0
100100
: static_max - balloon_stats.target_pages;

drivers/xen/xen-pciback/conf_space.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,43 @@ int xen_pcibk_config_write(struct pci_dev *dev, int offset, int size, u32 value)
286286
return xen_pcibios_err_to_errno(err);
287287
}
288288

289+
int xen_pcibk_get_interrupt_type(struct pci_dev *dev)
290+
{
291+
int err;
292+
u16 val;
293+
int ret = 0;
294+
295+
err = pci_read_config_word(dev, PCI_COMMAND, &val);
296+
if (err)
297+
return err;
298+
if (!(val & PCI_COMMAND_INTX_DISABLE))
299+
ret |= INTERRUPT_TYPE_INTX;
300+
301+
/*
302+
* Do not trust dev->msi(x)_enabled here, as enabling could be done
303+
* bypassing the pci_*msi* functions, by the qemu.
304+
*/
305+
if (dev->msi_cap) {
306+
err = pci_read_config_word(dev,
307+
dev->msi_cap + PCI_MSI_FLAGS,
308+
&val);
309+
if (err)
310+
return err;
311+
if (val & PCI_MSI_FLAGS_ENABLE)
312+
ret |= INTERRUPT_TYPE_MSI;
313+
}
314+
if (dev->msix_cap) {
315+
err = pci_read_config_word(dev,
316+
dev->msix_cap + PCI_MSIX_FLAGS,
317+
&val);
318+
if (err)
319+
return err;
320+
if (val & PCI_MSIX_FLAGS_ENABLE)
321+
ret |= INTERRUPT_TYPE_MSIX;
322+
}
323+
return ret;
324+
}
325+
289326
void xen_pcibk_config_free_dyn_fields(struct pci_dev *dev)
290327
{
291328
struct xen_pcibk_dev_data *dev_data = pci_get_drvdata(dev);

drivers/xen/xen-pciback/conf_space.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ struct config_field_entry {
6565
void *data;
6666
};
6767

68+
#define INTERRUPT_TYPE_NONE (1<<0)
69+
#define INTERRUPT_TYPE_INTX (1<<1)
70+
#define INTERRUPT_TYPE_MSI (1<<2)
71+
#define INTERRUPT_TYPE_MSIX (1<<3)
72+
6873
extern bool xen_pcibk_permissive;
6974

7075
#define OFFSET(cfg_entry) ((cfg_entry)->base_offset+(cfg_entry)->field->offset)
@@ -126,4 +131,6 @@ int xen_pcibk_config_capability_init(void);
126131
int xen_pcibk_config_header_add_fields(struct pci_dev *dev);
127132
int xen_pcibk_config_capability_add_fields(struct pci_dev *dev);
128133

134+
int xen_pcibk_get_interrupt_type(struct pci_dev *dev);
135+
129136
#endif /* __XEN_PCIBACK_CONF_SPACE_H__ */

0 commit comments

Comments
 (0)