Skip to content

Commit c6460da

Browse files
committed
Merge tag 'for-linus-5.15b-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip
Pull xen fixes from Juergen Gross: - The first hunk of a Xen swiotlb fixup series fixing multiple minor issues and doing some small cleanups - Some further Xen related fixes avoiding WARN() splats when running as Xen guests or dom0 - A Kconfig fix allowing the pvcalls frontend to be built as a module * tag 'for-linus-5.15b-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip: swiotlb-xen: drop DEFAULT_NSLABS swiotlb-xen: arrange to have buffer info logged swiotlb-xen: drop leftover __ref swiotlb-xen: limit init retries swiotlb-xen: suppress certain init retries swiotlb-xen: maintain slab count properly swiotlb-xen: fix late init retry swiotlb-xen: avoid double free xen/pvcalls: backend can be a module xen: fix usage of pmd_populate in mremap for pv guests xen: reset legacy rtc flag for PV domU PM: base: power: don't try to use non-existing RTC for storing data xen/balloon: use a kernel thread instead a workqueue
2 parents bdb575f + d859ed2 commit c6460da

File tree

6 files changed

+85
-40
lines changed

6 files changed

+85
-40
lines changed

arch/x86/xen/enlighten_pv.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,11 @@ static void __init xen_dom0_set_legacy_features(void)
12141214
x86_platform.legacy.rtc = 1;
12151215
}
12161216

1217+
static void __init xen_domu_set_legacy_features(void)
1218+
{
1219+
x86_platform.legacy.rtc = 0;
1220+
}
1221+
12171222
/* First C function to be called on Xen boot */
12181223
asmlinkage __visible void __init xen_start_kernel(void)
12191224
{
@@ -1359,6 +1364,8 @@ asmlinkage __visible void __init xen_start_kernel(void)
13591364
add_preferred_console("xenboot", 0, NULL);
13601365
if (pci_xen)
13611366
x86_init.pci.arch_init = pci_xen_init;
1367+
x86_platform.set_legacy_features =
1368+
xen_domu_set_legacy_features;
13621369
} else {
13631370
const struct dom0_vga_console_info *info =
13641371
(void *)((char *)xen_start_info +

arch/x86/xen/mmu_pv.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,14 +1518,17 @@ static inline void xen_alloc_ptpage(struct mm_struct *mm, unsigned long pfn,
15181518
if (pinned) {
15191519
struct page *page = pfn_to_page(pfn);
15201520

1521-
if (static_branch_likely(&xen_struct_pages_ready))
1521+
pinned = false;
1522+
if (static_branch_likely(&xen_struct_pages_ready)) {
1523+
pinned = PagePinned(page);
15221524
SetPagePinned(page);
1525+
}
15231526

15241527
xen_mc_batch();
15251528

15261529
__set_pfn_prot(pfn, PAGE_KERNEL_RO);
15271530

1528-
if (level == PT_PTE && USE_SPLIT_PTE_PTLOCKS)
1531+
if (level == PT_PTE && USE_SPLIT_PTE_PTLOCKS && !pinned)
15291532
__pin_pagetable_pfn(MMUEXT_PIN_L1_TABLE, pfn);
15301533

15311534
xen_mc_issue(PARAVIRT_LAZY_MMU);

drivers/base/power/trace.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/export.h>
1414
#include <linux/rtc.h>
1515
#include <linux/suspend.h>
16+
#include <linux/init.h>
1617

1718
#include <linux/mc146818rtc.h>
1819

@@ -165,6 +166,9 @@ void generate_pm_trace(const void *tracedata, unsigned int user)
165166
const char *file = *(const char **)(tracedata + 2);
166167
unsigned int user_hash_value, file_hash_value;
167168

169+
if (!x86_platform.legacy.rtc)
170+
return;
171+
168172
user_hash_value = user % USERHASH;
169173
file_hash_value = hash_string(lineno, file, FILEHASH);
170174
set_magic_time(user_hash_value, file_hash_value, dev_hash_value);
@@ -267,6 +271,9 @@ static struct notifier_block pm_trace_nb = {
267271

268272
static int __init early_resume_init(void)
269273
{
274+
if (!x86_platform.legacy.rtc)
275+
return 0;
276+
270277
hash_value_early_read = read_magic_time();
271278
register_pm_notifier(&pm_trace_nb);
272279
return 0;
@@ -277,6 +284,9 @@ static int __init late_resume_init(void)
277284
unsigned int val = hash_value_early_read;
278285
unsigned int user, file, dev;
279286

287+
if (!x86_platform.legacy.rtc)
288+
return 0;
289+
280290
user = val % USERHASH;
281291
val = val / USERHASH;
282292
file = val % FILEHASH;

drivers/xen/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ config XEN_PVCALLS_FRONTEND
214214
implements them.
215215

216216
config XEN_PVCALLS_BACKEND
217-
bool "XEN PV Calls backend driver"
217+
tristate "XEN PV Calls backend driver"
218218
depends on INET && XEN && XEN_BACKEND
219219
help
220220
Experimental backend for the Xen PV Calls protocol

drivers/xen/balloon.c

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
#include <linux/sched.h>
4444
#include <linux/cred.h>
4545
#include <linux/errno.h>
46+
#include <linux/freezer.h>
47+
#include <linux/kthread.h>
4648
#include <linux/mm.h>
4749
#include <linux/memblock.h>
4850
#include <linux/pagemap.h>
@@ -115,7 +117,7 @@ static struct ctl_table xen_root[] = {
115117
#define EXTENT_ORDER (fls(XEN_PFN_PER_PAGE) - 1)
116118

117119
/*
118-
* balloon_process() state:
120+
* balloon_thread() state:
119121
*
120122
* BP_DONE: done or nothing to do,
121123
* BP_WAIT: wait to be rescheduled,
@@ -130,6 +132,8 @@ enum bp_state {
130132
BP_ECANCELED
131133
};
132134

135+
/* Main waiting point for xen-balloon thread. */
136+
static DECLARE_WAIT_QUEUE_HEAD(balloon_thread_wq);
133137

134138
static DEFINE_MUTEX(balloon_mutex);
135139

@@ -144,10 +148,6 @@ static xen_pfn_t frame_list[PAGE_SIZE / sizeof(xen_pfn_t)];
144148
static LIST_HEAD(ballooned_pages);
145149
static DECLARE_WAIT_QUEUE_HEAD(balloon_wq);
146150

147-
/* Main work function, always executed in process context. */
148-
static void balloon_process(struct work_struct *work);
149-
static DECLARE_DELAYED_WORK(balloon_worker, balloon_process);
150-
151151
/* When ballooning out (allocating memory to return to Xen) we don't really
152152
want the kernel to try too hard since that can trigger the oom killer. */
153153
#define GFP_BALLOON \
@@ -366,7 +366,7 @@ static void xen_online_page(struct page *page, unsigned int order)
366366
static int xen_memory_notifier(struct notifier_block *nb, unsigned long val, void *v)
367367
{
368368
if (val == MEM_ONLINE)
369-
schedule_delayed_work(&balloon_worker, 0);
369+
wake_up(&balloon_thread_wq);
370370

371371
return NOTIFY_OK;
372372
}
@@ -491,18 +491,43 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
491491
}
492492

493493
/*
494-
* As this is a work item it is guaranteed to run as a single instance only.
494+
* Stop waiting if either state is not BP_EAGAIN and ballooning action is
495+
* needed, or if the credit has changed while state is BP_EAGAIN.
496+
*/
497+
static bool balloon_thread_cond(enum bp_state state, long credit)
498+
{
499+
if (state != BP_EAGAIN)
500+
credit = 0;
501+
502+
return current_credit() != credit || kthread_should_stop();
503+
}
504+
505+
/*
506+
* As this is a kthread it is guaranteed to run as a single instance only.
495507
* We may of course race updates of the target counts (which are protected
496508
* by the balloon lock), or with changes to the Xen hard limit, but we will
497509
* recover from these in time.
498510
*/
499-
static void balloon_process(struct work_struct *work)
511+
static int balloon_thread(void *unused)
500512
{
501513
enum bp_state state = BP_DONE;
502514
long credit;
515+
unsigned long timeout;
516+
517+
set_freezable();
518+
for (;;) {
519+
if (state == BP_EAGAIN)
520+
timeout = balloon_stats.schedule_delay * HZ;
521+
else
522+
timeout = 3600 * HZ;
523+
credit = current_credit();
503524

525+
wait_event_interruptible_timeout(balloon_thread_wq,
526+
balloon_thread_cond(state, credit), timeout);
527+
528+
if (kthread_should_stop())
529+
return 0;
504530

505-
do {
506531
mutex_lock(&balloon_mutex);
507532

508533
credit = current_credit();
@@ -529,20 +554,15 @@ static void balloon_process(struct work_struct *work)
529554
mutex_unlock(&balloon_mutex);
530555

531556
cond_resched();
532-
533-
} while (credit && state == BP_DONE);
534-
535-
/* Schedule more work if there is some still to be done. */
536-
if (state == BP_EAGAIN)
537-
schedule_delayed_work(&balloon_worker, balloon_stats.schedule_delay * HZ);
557+
}
538558
}
539559

540560
/* Resets the Xen limit, sets new target, and kicks off processing. */
541561
void balloon_set_new_target(unsigned long target)
542562
{
543563
/* No need for lock. Not read-modify-write updates. */
544564
balloon_stats.target_pages = target;
545-
schedule_delayed_work(&balloon_worker, 0);
565+
wake_up(&balloon_thread_wq);
546566
}
547567
EXPORT_SYMBOL_GPL(balloon_set_new_target);
548568

@@ -647,7 +667,7 @@ void free_xenballooned_pages(int nr_pages, struct page **pages)
647667

648668
/* The balloon may be too large now. Shrink it if needed. */
649669
if (current_credit())
650-
schedule_delayed_work(&balloon_worker, 0);
670+
wake_up(&balloon_thread_wq);
651671

652672
mutex_unlock(&balloon_mutex);
653673
}
@@ -679,6 +699,8 @@ static void __init balloon_add_region(unsigned long start_pfn,
679699

680700
static int __init balloon_init(void)
681701
{
702+
struct task_struct *task;
703+
682704
if (!xen_domain())
683705
return -ENODEV;
684706

@@ -722,6 +744,12 @@ static int __init balloon_init(void)
722744
}
723745
#endif
724746

747+
task = kthread_run(balloon_thread, NULL, "xen-balloon");
748+
if (IS_ERR(task)) {
749+
pr_err("xen-balloon thread could not be started, ballooning will not work!\n");
750+
return PTR_ERR(task);
751+
}
752+
725753
/* Init the xen-balloon driver. */
726754
xen_balloon_init();
727755

drivers/xen/swiotlb-xen.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -106,27 +106,26 @@ static int is_xen_swiotlb_buffer(struct device *dev, dma_addr_t dma_addr)
106106

107107
static int xen_swiotlb_fixup(void *buf, unsigned long nslabs)
108108
{
109-
int i, rc;
110-
int dma_bits;
109+
int rc;
110+
unsigned int order = get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT);
111+
unsigned int i, dma_bits = order + PAGE_SHIFT;
111112
dma_addr_t dma_handle;
112113
phys_addr_t p = virt_to_phys(buf);
113114

114-
dma_bits = get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT) + PAGE_SHIFT;
115+
BUILD_BUG_ON(IO_TLB_SEGSIZE & (IO_TLB_SEGSIZE - 1));
116+
BUG_ON(nslabs % IO_TLB_SEGSIZE);
115117

116118
i = 0;
117119
do {
118-
int slabs = min(nslabs - i, (unsigned long)IO_TLB_SEGSIZE);
119-
120120
do {
121121
rc = xen_create_contiguous_region(
122-
p + (i << IO_TLB_SHIFT),
123-
get_order(slabs << IO_TLB_SHIFT),
122+
p + (i << IO_TLB_SHIFT), order,
124123
dma_bits, &dma_handle);
125124
} while (rc && dma_bits++ < MAX_DMA_BITS);
126125
if (rc)
127126
return rc;
128127

129-
i += slabs;
128+
i += IO_TLB_SEGSIZE;
130129
} while (i < nslabs);
131130
return 0;
132131
}
@@ -153,9 +152,7 @@ static const char *xen_swiotlb_error(enum xen_swiotlb_err err)
153152
return "";
154153
}
155154

156-
#define DEFAULT_NSLABS ALIGN(SZ_64M >> IO_TLB_SHIFT, IO_TLB_SEGSIZE)
157-
158-
int __ref xen_swiotlb_init(void)
155+
int xen_swiotlb_init(void)
159156
{
160157
enum xen_swiotlb_err m_ret = XEN_SWIOTLB_UNKNOWN;
161158
unsigned long bytes = swiotlb_size_or_default();
@@ -185,7 +182,7 @@ int __ref xen_swiotlb_init(void)
185182
order--;
186183
}
187184
if (!start)
188-
goto error;
185+
goto exit;
189186
if (order != get_order(bytes)) {
190187
pr_warn("Warning: only able to allocate %ld MB for software IO TLB\n",
191188
(PAGE_SIZE << order) >> 20);
@@ -208,15 +205,15 @@ int __ref xen_swiotlb_init(void)
208205
swiotlb_set_max_segment(PAGE_SIZE);
209206
return 0;
210207
error:
211-
if (repeat--) {
208+
if (nslabs > 1024 && repeat--) {
212209
/* Min is 2MB */
213-
nslabs = max(1024UL, (nslabs >> 1));
214-
pr_info("Lowering to %luMB\n",
215-
(nslabs << IO_TLB_SHIFT) >> 20);
210+
nslabs = max(1024UL, ALIGN(nslabs >> 1, IO_TLB_SEGSIZE));
211+
bytes = nslabs << IO_TLB_SHIFT;
212+
pr_info("Lowering to %luMB\n", bytes >> 20);
216213
goto retry;
217214
}
215+
exit:
218216
pr_err("%s (rc:%d)\n", xen_swiotlb_error(m_ret), rc);
219-
free_pages((unsigned long)start, order);
220217
return rc;
221218
}
222219

@@ -244,17 +241,17 @@ void __init xen_swiotlb_init_early(void)
244241
rc = xen_swiotlb_fixup(start, nslabs);
245242
if (rc) {
246243
memblock_free(__pa(start), PAGE_ALIGN(bytes));
247-
if (repeat--) {
244+
if (nslabs > 1024 && repeat--) {
248245
/* Min is 2MB */
249-
nslabs = max(1024UL, (nslabs >> 1));
246+
nslabs = max(1024UL, ALIGN(nslabs >> 1, IO_TLB_SEGSIZE));
250247
bytes = nslabs << IO_TLB_SHIFT;
251248
pr_info("Lowering to %luMB\n", bytes >> 20);
252249
goto retry;
253250
}
254251
panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
255252
}
256253

257-
if (swiotlb_init_with_tbl(start, nslabs, false))
254+
if (swiotlb_init_with_tbl(start, nslabs, true))
258255
panic("Cannot allocate SWIOTLB buffer");
259256
swiotlb_set_max_segment(PAGE_SIZE);
260257
}

0 commit comments

Comments
 (0)