Skip to content

Commit 5d6a0f4

Browse files
committed
Merge tag 'for-linus-6.0-rc1b-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip
Pull more xen updates from Juergen Gross: - fix the handling of the "persistent grants" feature negotiation between Xen blkfront and Xen blkback drivers - a cleanup of xen.config and adding xen.config to Xen section in MAINTAINERS - support HVMOP_set_evtchn_upcall_vector, which is more compliant to "normal" interrupt handling than the global callback used up to now - further small cleanups * tag 'for-linus-6.0-rc1b-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip: MAINTAINERS: add xen config fragments to XEN HYPERVISOR sections xen: remove XEN_SCRUB_PAGES in xen.config xen/pciback: Fix comment typo xen/xenbus: fix return type in xenbus_file_read() xen-blkfront: Apply 'feature_persistent' parameter when connect xen-blkback: Apply 'feature_persistent' parameter when connect xen-blkback: fix persistent grants negotiation x86/xen: Add support for HVMOP_set_evtchn_upcall_vector
2 parents 96f86ff + 5ad3134 commit 5d6a0f4

File tree

16 files changed

+116
-36
lines changed

16 files changed

+116
-36
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ KernelVersion: 5.10
4242
Contact: Maximilian Heyne <[email protected]>
4343
Description:
4444
Whether to enable the persistent grants feature or not. Note
45-
that this option only takes effect on newly created backends.
45+
that this option only takes effect on newly connected backends.
4646
The default is Y (enable).

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ KernelVersion: 5.10
1515
Contact: Maximilian Heyne <[email protected]>
1616
Description:
1717
Whether to enable the persistent grants feature or not. Note
18-
that this option only takes effect on newly created frontends.
18+
that this option only takes effect on newly connected frontends.
1919
The default is Y (enable).

MAINTAINERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22200,12 +22200,14 @@ F: drivers/*/xen-*front.c
2220022200
F: drivers/xen/
2220122201
F: include/uapi/xen/
2220222202
F: include/xen/
22203+
F: kernel/configs/xen.config
2220322204

2220422205
XEN HYPERVISOR X86
2220522206
M: Juergen Gross <[email protected]>
2220622207
R: Boris Ostrovsky <[email protected]>
2220722208
L: [email protected] (moderated for non-subscribers)
2220822209
S: Supported
22210+
F: arch/x86/configs/xen.config
2220922211
F: arch/x86/include/asm/pvclock-abi.h
2221022212
F: arch/x86/include/asm/xen/
2221122213
F: arch/x86/platform/pvh/

arch/x86/include/asm/xen/cpuid.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@
107107
* ID field from 8 to 15 bits, allowing to target APIC IDs up 32768.
108108
*/
109109
#define XEN_HVM_CPUID_EXT_DEST_ID (1u << 5)
110+
/* Per-vCPU event channel upcalls */
111+
#define XEN_HVM_CPUID_UPCALL_VECTOR (1u << 6)
110112

111113
/*
112114
* Leaf 6 (0x40000x05)

arch/x86/include/asm/xen/events.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static inline int xen_irqs_disabled(struct pt_regs *regs)
2323
/* No need for a barrier -- XCHG is a barrier on x86. */
2424
#define xchg_xen_ulong(ptr, val) xchg((ptr), (val))
2525

26-
extern int xen_have_vector_callback;
26+
extern bool xen_have_vector_callback;
2727

2828
/*
2929
* Events delivered via platform PCI interrupts are always
@@ -34,4 +34,5 @@ static inline bool xen_support_evtchn_rebind(void)
3434
return (!xen_hvm_domain() || xen_have_vector_callback);
3535
}
3636

37+
extern bool xen_percpu_upcall;
3738
#endif /* _ASM_X86_XEN_EVENTS_H */

arch/x86/xen/enlighten.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ EXPORT_SYMBOL_GPL(xen_start_info);
5151

5252
struct shared_info xen_dummy_shared_info;
5353

54-
__read_mostly int xen_have_vector_callback;
54+
__read_mostly bool xen_have_vector_callback = true;
5555
EXPORT_SYMBOL_GPL(xen_have_vector_callback);
5656

5757
/*

arch/x86/xen/enlighten_hvm.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <xen/features.h>
1010
#include <xen/events.h>
11+
#include <xen/hvm.h>
12+
#include <xen/interface/hvm/hvm_op.h>
1113
#include <xen/interface/memory.h>
1214

1315
#include <asm/apic.h>
@@ -31,6 +33,9 @@
3133

3234
static unsigned long shared_info_pfn;
3335

36+
__ro_after_init bool xen_percpu_upcall;
37+
EXPORT_SYMBOL_GPL(xen_percpu_upcall);
38+
3439
void xen_hvm_init_shared_info(void)
3540
{
3641
struct xen_add_to_physmap xatp;
@@ -126,6 +131,9 @@ DEFINE_IDTENTRY_SYSVEC(sysvec_xen_hvm_callback)
126131
{
127132
struct pt_regs *old_regs = set_irq_regs(regs);
128133

134+
if (xen_percpu_upcall)
135+
ack_APIC_irq();
136+
129137
inc_irq_stat(irq_hv_callback_count);
130138

131139
xen_hvm_evtchn_do_upcall();
@@ -169,6 +177,15 @@ static int xen_cpu_up_prepare_hvm(unsigned int cpu)
169177
if (!xen_have_vector_callback)
170178
return 0;
171179

180+
if (xen_percpu_upcall) {
181+
rc = xen_set_upcall_vector(cpu);
182+
if (rc) {
183+
WARN(1, "HVMOP_set_evtchn_upcall_vector"
184+
" for CPU %d failed: %d\n", cpu, rc);
185+
return rc;
186+
}
187+
}
188+
172189
if (xen_feature(XENFEAT_hvm_safe_pvclock))
173190
xen_setup_timer(cpu);
174191

@@ -189,8 +206,6 @@ static int xen_cpu_dead_hvm(unsigned int cpu)
189206
return 0;
190207
}
191208

192-
static bool no_vector_callback __initdata;
193-
194209
static void __init xen_hvm_guest_init(void)
195210
{
196211
if (xen_pv_domain())
@@ -213,9 +228,6 @@ static void __init xen_hvm_guest_init(void)
213228

214229
xen_panic_handler_init();
215230

216-
if (!no_vector_callback && xen_feature(XENFEAT_hvm_callback_vector))
217-
xen_have_vector_callback = 1;
218-
219231
xen_hvm_smp_init();
220232
WARN_ON(xen_cpuhp_setup(xen_cpu_up_prepare_hvm, xen_cpu_dead_hvm));
221233
xen_unplug_emulated_devices();
@@ -241,7 +253,7 @@ early_param("xen_nopv", xen_parse_nopv);
241253

242254
static __init int xen_parse_no_vector_callback(char *arg)
243255
{
244-
no_vector_callback = true;
256+
xen_have_vector_callback = false;
245257
return 0;
246258
}
247259
early_param("xen_no_vector_callback", xen_parse_no_vector_callback);

arch/x86/xen/suspend_hvm.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <xen/hvm.h>
66
#include <xen/features.h>
77
#include <xen/interface/features.h>
8+
#include <xen/events.h>
89

910
#include "xen-ops.h"
1011

@@ -14,6 +15,13 @@ void xen_hvm_post_suspend(int suspend_cancelled)
1415
xen_hvm_init_shared_info();
1516
xen_vcpu_restore();
1617
}
17-
xen_setup_callback_vector();
18+
if (xen_percpu_upcall) {
19+
unsigned int cpu;
20+
21+
for_each_online_cpu(cpu)
22+
BUG_ON(xen_set_upcall_vector(cpu));
23+
} else {
24+
xen_setup_callback_vector();
25+
}
1826
xen_unplug_emulated_devices();
1927
}

drivers/block/xen-blkback/xenbus.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ static int xen_blkif_alloc_rings(struct xen_blkif *blkif)
157157
return 0;
158158
}
159159

160+
/* Enable the persistent grants feature. */
161+
static bool feature_persistent = true;
162+
module_param(feature_persistent, bool, 0644);
163+
MODULE_PARM_DESC(feature_persistent, "Enables the persistent grants feature");
164+
160165
static struct xen_blkif *xen_blkif_alloc(domid_t domid)
161166
{
162167
struct xen_blkif *blkif;
@@ -472,12 +477,6 @@ static void xen_vbd_free(struct xen_vbd *vbd)
472477
vbd->bdev = NULL;
473478
}
474479

475-
/* Enable the persistent grants feature. */
476-
static bool feature_persistent = true;
477-
module_param(feature_persistent, bool, 0644);
478-
MODULE_PARM_DESC(feature_persistent,
479-
"Enables the persistent grants feature");
480-
481480
static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle,
482481
unsigned major, unsigned minor, int readonly,
483482
int cdrom)
@@ -520,8 +519,6 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle,
520519
if (bdev_max_secure_erase_sectors(bdev))
521520
vbd->discard_secure = true;
522521

523-
vbd->feature_gnt_persistent = feature_persistent;
524-
525522
pr_debug("Successful creation of handle=%04x (dom=%u)\n",
526523
handle, blkif->domid);
527524
return 0;
@@ -1087,10 +1084,9 @@ static int connect_ring(struct backend_info *be)
10871084
xenbus_dev_fatal(dev, err, "unknown fe protocol %s", protocol);
10881085
return -ENOSYS;
10891086
}
1090-
if (blkif->vbd.feature_gnt_persistent)
1091-
blkif->vbd.feature_gnt_persistent =
1092-
xenbus_read_unsigned(dev->otherend,
1093-
"feature-persistent", 0);
1087+
1088+
blkif->vbd.feature_gnt_persistent = feature_persistent &&
1089+
xenbus_read_unsigned(dev->otherend, "feature-persistent", 0);
10941090

10951091
blkif->vbd.overflow_max_grants = 0;
10961092

drivers/block/xen-blkfront.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,8 +1988,6 @@ static int blkfront_probe(struct xenbus_device *dev,
19881988
info->vdevice = vdevice;
19891989
info->connected = BLKIF_STATE_DISCONNECTED;
19901990

1991-
info->feature_persistent = feature_persistent;
1992-
19931991
/* Front end dir is a number, which is used as the id. */
19941992
info->handle = simple_strtoul(strrchr(dev->nodename, '/')+1, NULL, 0);
19951993
dev_set_drvdata(&dev->dev, info);
@@ -2283,7 +2281,7 @@ static void blkfront_gather_backend_features(struct blkfront_info *info)
22832281
if (xenbus_read_unsigned(info->xbdev->otherend, "feature-discard", 0))
22842282
blkfront_setup_discard(info);
22852283

2286-
if (info->feature_persistent)
2284+
if (feature_persistent)
22872285
info->feature_persistent =
22882286
!!xenbus_read_unsigned(info->xbdev->otherend,
22892287
"feature-persistent", 0);

drivers/xen/events/events_base.c

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include <asm/irq.h>
4646
#include <asm/io_apic.h>
4747
#include <asm/i8259.h>
48+
#include <asm/xen/cpuid.h>
4849
#include <asm/xen/pci.h>
4950
#endif
5051
#include <asm/sync_bitops.h>
@@ -2184,6 +2185,7 @@ static struct irq_chip xen_percpu_chip __read_mostly = {
21842185
.irq_ack = ack_dynirq,
21852186
};
21862187

2188+
#ifdef CONFIG_X86
21872189
#ifdef CONFIG_XEN_PVHVM
21882190
/* Vector callbacks are better than PCI interrupts to receive event
21892191
* channel notifications because we can receive vector callbacks on any
@@ -2196,11 +2198,48 @@ void xen_setup_callback_vector(void)
21962198
callback_via = HVM_CALLBACK_VECTOR(HYPERVISOR_CALLBACK_VECTOR);
21972199
if (xen_set_callback_via(callback_via)) {
21982200
pr_err("Request for Xen HVM callback vector failed\n");
2199-
xen_have_vector_callback = 0;
2201+
xen_have_vector_callback = false;
22002202
}
22012203
}
22022204
}
22032205

2206+
/*
2207+
* Setup per-vCPU vector-type callbacks. If this setup is unavailable,
2208+
* fallback to the global vector-type callback.
2209+
*/
2210+
static __init void xen_init_setup_upcall_vector(void)
2211+
{
2212+
if (!xen_have_vector_callback)
2213+
return;
2214+
2215+
if ((cpuid_eax(xen_cpuid_base() + 4) & XEN_HVM_CPUID_UPCALL_VECTOR) &&
2216+
!xen_set_upcall_vector(0))
2217+
xen_percpu_upcall = true;
2218+
else if (xen_feature(XENFEAT_hvm_callback_vector))
2219+
xen_setup_callback_vector();
2220+
else
2221+
xen_have_vector_callback = false;
2222+
}
2223+
2224+
int xen_set_upcall_vector(unsigned int cpu)
2225+
{
2226+
int rc;
2227+
xen_hvm_evtchn_upcall_vector_t op = {
2228+
.vector = HYPERVISOR_CALLBACK_VECTOR,
2229+
.vcpu = per_cpu(xen_vcpu_id, cpu),
2230+
};
2231+
2232+
rc = HYPERVISOR_hvm_op(HVMOP_set_evtchn_upcall_vector, &op);
2233+
if (rc)
2234+
return rc;
2235+
2236+
/* Trick toolstack to think we are enlightened. */
2237+
if (!cpu)
2238+
rc = xen_set_callback_via(1);
2239+
2240+
return rc;
2241+
}
2242+
22042243
static __init void xen_alloc_callback_vector(void)
22052244
{
22062245
if (!xen_have_vector_callback)
@@ -2211,8 +2250,11 @@ static __init void xen_alloc_callback_vector(void)
22112250
}
22122251
#else
22132252
void xen_setup_callback_vector(void) {}
2253+
static inline void xen_init_setup_upcall_vector(void) {}
2254+
int xen_set_upcall_vector(unsigned int cpu) {}
22142255
static inline void xen_alloc_callback_vector(void) {}
2215-
#endif
2256+
#endif /* CONFIG_XEN_PVHVM */
2257+
#endif /* CONFIG_X86 */
22162258

22172259
bool xen_fifo_events = true;
22182260
module_param_named(fifo_events, xen_fifo_events, bool, 0);
@@ -2272,10 +2314,9 @@ void __init xen_init_IRQ(void)
22722314
if (xen_initial_domain())
22732315
pci_xen_initial_domain();
22742316
}
2275-
if (xen_feature(XENFEAT_hvm_callback_vector)) {
2276-
xen_setup_callback_vector();
2277-
xen_alloc_callback_vector();
2278-
}
2317+
xen_init_setup_upcall_vector();
2318+
xen_alloc_callback_vector();
2319+
22792320

22802321
if (xen_hvm_domain()) {
22812322
native_init_IRQ();

drivers/xen/xen-pciback/pciback_ops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ int xen_pcibk_enable_msi(struct xen_pcibk_device *pdev,
159159
return XEN_PCI_ERR_op_failed;
160160
}
161161

162-
/* The value the guest needs is actually the IDT vector, not the
162+
/* The value the guest needs is actually the IDT vector, not
163163
* the local domain's IRQ number. */
164164

165165
op->value = dev->irq ? xen_pirq_from_irq(dev->irq) : 0;

drivers/xen/xenbus/xenbus_dev_frontend.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static ssize_t xenbus_file_read(struct file *filp,
128128
{
129129
struct xenbus_file_priv *u = filp->private_data;
130130
struct read_buffer *rb;
131-
unsigned i;
131+
ssize_t i;
132132
int ret;
133133

134134
mutex_lock(&u->reply_mutex);
@@ -148,7 +148,7 @@ static ssize_t xenbus_file_read(struct file *filp,
148148
rb = list_entry(u->read_buffers.next, struct read_buffer, list);
149149
i = 0;
150150
while (i < len) {
151-
unsigned sz = min((unsigned)len - i, rb->len - rb->cons);
151+
size_t sz = min_t(size_t, len - i, rb->len - rb->cons);
152152

153153
ret = copy_to_user(ubuf + i, &rb->msg[rb->cons], sz);
154154

include/xen/hvm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,6 @@ static inline int hvm_get_parameter(int idx, uint64_t *value)
6060

6161
void xen_setup_callback_vector(void);
6262

63+
int xen_set_upcall_vector(unsigned int cpu);
64+
6365
#endif /* XEN_HVM_H__ */

include/xen/interface/hvm/hvm_op.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,23 @@ struct xen_hvm_get_mem_type {
4646
};
4747
DEFINE_GUEST_HANDLE_STRUCT(xen_hvm_get_mem_type);
4848

49+
#if defined(__i386__) || defined(__x86_64__)
50+
51+
/*
52+
* HVMOP_set_evtchn_upcall_vector: Set a <vector> that should be used for event
53+
* channel upcalls on the specified <vcpu>. If set,
54+
* this vector will be used in preference to the
55+
* domain global callback via (see
56+
* HVM_PARAM_CALLBACK_IRQ).
57+
*/
58+
#define HVMOP_set_evtchn_upcall_vector 23
59+
struct xen_hvm_evtchn_upcall_vector {
60+
uint32_t vcpu;
61+
uint8_t vector;
62+
};
63+
typedef struct xen_hvm_evtchn_upcall_vector xen_hvm_evtchn_upcall_vector_t;
64+
DEFINE_GUEST_HANDLE_STRUCT(xen_hvm_evtchn_upcall_vector_t);
65+
66+
#endif /* defined(__i386__) || defined(__x86_64__) */
67+
4968
#endif /* __XEN_PUBLIC_HVM_HVM_OP_H__ */

kernel/configs/xen.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ CONFIG_INPUT_XEN_KBDDEV_FRONTEND=m
3434
CONFIG_XEN_SCSI_FRONTEND=m
3535
# others
3636
CONFIG_XEN_BALLOON=y
37-
CONFIG_XEN_SCRUB_PAGES=y
3837
CONFIG_XEN_DEV_EVTCHN=m
3938
CONFIG_XEN_BLKDEV_FRONTEND=m
4039
CONFIG_XEN_NETDEV_FRONTEND=m

0 commit comments

Comments
 (0)