Skip to content

Commit 9ab9bc5

Browse files
committed
Merge tag 'hyperv-next-signed' of git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux
Pull hyperv updates from Wei Liu: - A patch series from Andrea to improve vmbus code - Two clean-up patches from Alexander and Randy * tag 'hyperv-next-signed' of git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux: hyperv: hyperv.h: drop a duplicated word tools: hv: change http to https in hv_kvp_daemon.c Drivers: hv: vmbus: Remove the lock field from the vmbus_channel struct scsi: storvsc: Introduce the per-storvsc_device spinlock Drivers: hv: vmbus: Remove unnecessary channel->lock critical sections (sc_list updaters) Drivers: hv: vmbus: Use channel_mutex in channel_vp_mapping_show() Drivers: hv: vmbus: Remove unnecessary channel->lock critical sections (sc_list readers) Drivers: hv: vmbus: Replace cpumask_test_cpu(, cpu_online_mask) with cpu_online() Drivers: hv: vmbus: Remove the numa_node field from the vmbus_channel struct Drivers: hv: vmbus: Remove the target_vp field from the vmbus_channel struct
2 parents 47ec530 + 7deff7b commit 9ab9bc5

File tree

8 files changed

+34
-68
lines changed

8 files changed

+34
-68
lines changed

drivers/hv/channel.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/uio.h>
1919
#include <linux/interrupt.h>
2020
#include <asm/page.h>
21+
#include <asm/mshyperv.h>
2122

2223
#include "hyperv_vmbus.h"
2324

@@ -128,12 +129,8 @@ static int __vmbus_open(struct vmbus_channel *newchannel,
128129
send_pages = newchannel->ringbuffer_send_offset;
129130
recv_pages = newchannel->ringbuffer_pagecount - send_pages;
130131

131-
spin_lock_irqsave(&newchannel->lock, flags);
132-
if (newchannel->state != CHANNEL_OPEN_STATE) {
133-
spin_unlock_irqrestore(&newchannel->lock, flags);
132+
if (newchannel->state != CHANNEL_OPEN_STATE)
134133
return -EINVAL;
135-
}
136-
spin_unlock_irqrestore(&newchannel->lock, flags);
137134

138135
newchannel->state = CHANNEL_OPENING_STATE;
139136
newchannel->onchannel_callback = onchannelcallback;
@@ -176,7 +173,7 @@ static int __vmbus_open(struct vmbus_channel *newchannel,
176173
open_msg->child_relid = newchannel->offermsg.child_relid;
177174
open_msg->ringbuffer_gpadlhandle = newchannel->ringbuffer_gpadlhandle;
178175
open_msg->downstream_ringbuffer_pageoffset = newchannel->ringbuffer_send_offset;
179-
open_msg->target_vp = newchannel->target_vp;
176+
open_msg->target_vp = hv_cpu_number_to_vp_number(newchannel->target_cpu);
180177

181178
if (userdatalen)
182179
memcpy(open_msg->userdata, userdata, userdatalen);

drivers/hv/channel_mgmt.c

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ static struct vmbus_channel *alloc_channel(void)
317317
return NULL;
318318

319319
spin_lock_init(&channel->sched_lock);
320-
spin_lock_init(&channel->lock);
321320
init_completion(&channel->rescind_event);
322321

323322
INIT_LIST_HEAD(&channel->sc_list);
@@ -400,8 +399,6 @@ static void vmbus_release_relid(u32 relid)
400399

401400
void hv_process_channel_removal(struct vmbus_channel *channel)
402401
{
403-
unsigned long flags;
404-
405402
lockdep_assert_held(&vmbus_connection.channel_mutex);
406403
BUG_ON(!channel->rescind);
407404

@@ -422,14 +419,10 @@ void hv_process_channel_removal(struct vmbus_channel *channel)
422419
if (channel->offermsg.child_relid != INVALID_RELID)
423420
vmbus_channel_unmap_relid(channel);
424421

425-
if (channel->primary_channel == NULL) {
422+
if (channel->primary_channel == NULL)
426423
list_del(&channel->listentry);
427-
} else {
428-
struct vmbus_channel *primary_channel = channel->primary_channel;
429-
spin_lock_irqsave(&primary_channel->lock, flags);
424+
else
430425
list_del(&channel->sc_list);
431-
spin_unlock_irqrestore(&primary_channel->lock, flags);
432-
}
433426

434427
/*
435428
* If this is a "perf" channel, updates the hv_numa_map[] masks so that
@@ -470,7 +463,6 @@ static void vmbus_add_channel_work(struct work_struct *work)
470463
struct vmbus_channel *newchannel =
471464
container_of(work, struct vmbus_channel, add_channel_work);
472465
struct vmbus_channel *primary_channel = newchannel->primary_channel;
473-
unsigned long flags;
474466
int ret;
475467

476468
/*
@@ -531,13 +523,10 @@ static void vmbus_add_channel_work(struct work_struct *work)
531523
*/
532524
newchannel->probe_done = true;
533525

534-
if (primary_channel == NULL) {
526+
if (primary_channel == NULL)
535527
list_del(&newchannel->listentry);
536-
} else {
537-
spin_lock_irqsave(&primary_channel->lock, flags);
528+
else
538529
list_del(&newchannel->sc_list);
539-
spin_unlock_irqrestore(&primary_channel->lock, flags);
540-
}
541530

542531
/* vmbus_process_offer() has mapped the channel. */
543532
vmbus_channel_unmap_relid(newchannel);
@@ -557,7 +546,6 @@ static void vmbus_process_offer(struct vmbus_channel *newchannel)
557546
{
558547
struct vmbus_channel *channel;
559548
struct workqueue_struct *wq;
560-
unsigned long flags;
561549
bool fnew = true;
562550

563551
/*
@@ -609,10 +597,10 @@ static void vmbus_process_offer(struct vmbus_channel *newchannel)
609597
}
610598
}
611599

612-
if (fnew)
600+
if (fnew) {
613601
list_add_tail(&newchannel->listentry,
614602
&vmbus_connection.chn_list);
615-
else {
603+
} else {
616604
/*
617605
* Check to see if this is a valid sub-channel.
618606
*/
@@ -630,9 +618,7 @@ static void vmbus_process_offer(struct vmbus_channel *newchannel)
630618
* Process the sub-channel.
631619
*/
632620
newchannel->primary_channel = channel;
633-
spin_lock_irqsave(&channel->lock, flags);
634621
list_add_tail(&newchannel->sc_list, &channel->sc_list);
635-
spin_unlock_irqrestore(&channel->lock, flags);
636622
}
637623

638624
vmbus_channel_map_relid(newchannel);
@@ -702,10 +688,7 @@ static void init_vp_index(struct vmbus_channel *channel)
702688
* In case alloc_cpumask_var() fails, bind it to
703689
* VMBUS_CONNECT_CPU.
704690
*/
705-
channel->numa_node = cpu_to_node(VMBUS_CONNECT_CPU);
706691
channel->target_cpu = VMBUS_CONNECT_CPU;
707-
channel->target_vp =
708-
hv_cpu_number_to_vp_number(VMBUS_CONNECT_CPU);
709692
if (perf_chn)
710693
hv_set_alloced_cpu(VMBUS_CONNECT_CPU);
711694
return;
@@ -721,7 +704,6 @@ static void init_vp_index(struct vmbus_channel *channel)
721704
continue;
722705
break;
723706
}
724-
channel->numa_node = numa_node;
725707
alloced_mask = &hv_context.hv_numa_map[numa_node];
726708

727709
if (cpumask_weight(alloced_mask) ==
@@ -739,7 +721,6 @@ static void init_vp_index(struct vmbus_channel *channel)
739721
cpumask_set_cpu(target_cpu, alloced_mask);
740722

741723
channel->target_cpu = target_cpu;
742-
channel->target_vp = hv_cpu_number_to_vp_number(target_cpu);
743724

744725
free_cpumask_var(available_mask);
745726
}

drivers/hv/hv.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ int hv_synic_cleanup(unsigned int cpu)
241241
{
242242
struct vmbus_channel *channel, *sc;
243243
bool channel_found = false;
244-
unsigned long flags;
245244

246245
/*
247246
* Hyper-V does not provide a way to change the connect CPU once
@@ -263,14 +262,12 @@ int hv_synic_cleanup(unsigned int cpu)
263262
channel_found = true;
264263
break;
265264
}
266-
spin_lock_irqsave(&channel->lock, flags);
267265
list_for_each_entry(sc, &channel->sc_list, sc_list) {
268266
if (sc->target_cpu == cpu) {
269267
channel_found = true;
270268
break;
271269
}
272270
}
273-
spin_unlock_irqrestore(&channel->lock, flags);
274271
if (channel_found)
275272
break;
276273
}

drivers/hv/vmbus_drv.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <linux/cpu.h>
2424
#include <linux/sched/task_stack.h>
2525

26-
#include <asm/mshyperv.h>
2726
#include <linux/delay.h>
2827
#include <linux/notifier.h>
2928
#include <linux/ptrace.h>
@@ -227,7 +226,7 @@ static ssize_t numa_node_show(struct device *dev,
227226
if (!hv_dev->channel)
228227
return -ENODEV;
229228

230-
return sprintf(buf, "%d\n", hv_dev->channel->numa_node);
229+
return sprintf(buf, "%d\n", cpu_to_node(hv_dev->channel->target_cpu));
231230
}
232231
static DEVICE_ATTR_RO(numa_node);
233232
#endif
@@ -508,18 +507,17 @@ static ssize_t channel_vp_mapping_show(struct device *dev,
508507
{
509508
struct hv_device *hv_dev = device_to_hv_device(dev);
510509
struct vmbus_channel *channel = hv_dev->channel, *cur_sc;
511-
unsigned long flags;
512510
int buf_size = PAGE_SIZE, n_written, tot_written;
513511
struct list_head *cur;
514512

515513
if (!channel)
516514
return -ENODEV;
517515

516+
mutex_lock(&vmbus_connection.channel_mutex);
517+
518518
tot_written = snprintf(buf, buf_size, "%u:%u\n",
519519
channel->offermsg.child_relid, channel->target_cpu);
520520

521-
spin_lock_irqsave(&channel->lock, flags);
522-
523521
list_for_each(cur, &channel->sc_list) {
524522
if (tot_written >= buf_size - 1)
525523
break;
@@ -533,7 +531,7 @@ static ssize_t channel_vp_mapping_show(struct device *dev,
533531
tot_written += n_written;
534532
}
535533

536-
spin_unlock_irqrestore(&channel->lock, flags);
534+
mutex_unlock(&vmbus_connection.channel_mutex);
537535

538536
return tot_written;
539537
}
@@ -1717,7 +1715,7 @@ static ssize_t target_cpu_store(struct vmbus_channel *channel,
17171715
/* No CPUs should come up or down during this. */
17181716
cpus_read_lock();
17191717

1720-
if (!cpumask_test_cpu(target_cpu, cpu_online_mask)) {
1718+
if (!cpu_online(target_cpu)) {
17211719
cpus_read_unlock();
17221720
return -EINVAL;
17231721
}
@@ -1779,8 +1777,6 @@ static ssize_t target_cpu_store(struct vmbus_channel *channel,
17791777
*/
17801778

17811779
channel->target_cpu = target_cpu;
1782-
channel->target_vp = hv_cpu_number_to_vp_number(target_cpu);
1783-
channel->numa_node = cpu_to_node(target_cpu);
17841780

17851781
/* See init_vp_index(). */
17861782
if (hv_is_perf_channel(channel))
@@ -2347,7 +2343,6 @@ static int vmbus_acpi_add(struct acpi_device *device)
23472343
static int vmbus_bus_suspend(struct device *dev)
23482344
{
23492345
struct vmbus_channel *channel, *sc;
2350-
unsigned long flags;
23512346

23522347
while (atomic_read(&vmbus_connection.offer_in_progress) != 0) {
23532348
/*
@@ -2405,12 +2400,10 @@ static int vmbus_bus_suspend(struct device *dev)
24052400
continue;
24062401
}
24072402

2408-
spin_lock_irqsave(&channel->lock, flags);
24092403
list_for_each_entry(sc, &channel->sc_list, sc_list) {
24102404
pr_err("Sub-channel not deleted!\n");
24112405
WARN_ON_ONCE(1);
24122406
}
2413-
spin_unlock_irqrestore(&channel->lock, flags);
24142407

24152408
atomic_inc(&vmbus_connection.nr_chan_fixup_on_resume);
24162409
}

drivers/scsi/storvsc_drv.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,11 @@ struct storvsc_device {
462462
* Mask of CPUs bound to subchannels.
463463
*/
464464
struct cpumask alloced_cpus;
465+
/*
466+
* Serializes modifications of stor_chns[] from storvsc_do_io()
467+
* and storvsc_change_target_cpu().
468+
*/
469+
spinlock_t lock;
465470
/* Used for vsc/vsp channel reset process */
466471
struct storvsc_cmd_request init_request;
467472
struct storvsc_cmd_request reset_request;
@@ -639,7 +644,7 @@ static void storvsc_change_target_cpu(struct vmbus_channel *channel, u32 old,
639644
return;
640645

641646
/* See storvsc_do_io() -> get_og_chn(). */
642-
spin_lock_irqsave(&device->channel->lock, flags);
647+
spin_lock_irqsave(&stor_device->lock, flags);
643648

644649
/*
645650
* Determines if the storvsc device has other channels assigned to
@@ -676,7 +681,7 @@ static void storvsc_change_target_cpu(struct vmbus_channel *channel, u32 old,
676681
WRITE_ONCE(stor_device->stor_chns[new], channel);
677682
cpumask_set_cpu(new, &stor_device->alloced_cpus);
678683

679-
spin_unlock_irqrestore(&device->channel->lock, flags);
684+
spin_unlock_irqrestore(&stor_device->lock, flags);
680685
}
681686

682687
static void handle_sc_creation(struct vmbus_channel *new_sc)
@@ -1433,14 +1438,14 @@ static int storvsc_do_io(struct hv_device *device,
14331438
}
14341439
}
14351440
} else {
1436-
spin_lock_irqsave(&device->channel->lock, flags);
1441+
spin_lock_irqsave(&stor_device->lock, flags);
14371442
outgoing_channel = stor_device->stor_chns[q_num];
14381443
if (outgoing_channel != NULL) {
1439-
spin_unlock_irqrestore(&device->channel->lock, flags);
1444+
spin_unlock_irqrestore(&stor_device->lock, flags);
14401445
goto found_channel;
14411446
}
14421447
outgoing_channel = get_og_chn(stor_device, q_num);
1443-
spin_unlock_irqrestore(&device->channel->lock, flags);
1448+
spin_unlock_irqrestore(&stor_device->lock, flags);
14441449
}
14451450

14461451
found_channel:
@@ -1881,6 +1886,7 @@ static int storvsc_probe(struct hv_device *device,
18811886
init_waitqueue_head(&stor_device->waiting_to_drain);
18821887
stor_device->device = device;
18831888
stor_device->host = host;
1889+
spin_lock_init(&stor_device->lock);
18841890
hv_set_drvdata(device, stor_device);
18851891

18861892
stor_device->port_number = host->host_no;

include/linux/hyperv.h

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -803,17 +803,15 @@ struct vmbus_channel {
803803
u64 sig_event;
804804

805805
/*
806-
* Starting with win8, this field will be used to specify
807-
* the target virtual processor on which to deliver the interrupt for
808-
* the host to guest communication.
809-
* Prior to win8, incoming channel interrupts would only
810-
* be delivered on cpu 0. Setting this value to 0 would
811-
* preserve the earlier behavior.
806+
* Starting with win8, this field will be used to specify the
807+
* target CPU on which to deliver the interrupt for the host
808+
* to guest communication.
809+
*
810+
* Prior to win8, incoming channel interrupts would only be
811+
* delivered on CPU 0. Setting this value to 0 would preserve
812+
* the earlier behavior.
812813
*/
813-
u32 target_vp;
814-
/* The corresponding CPUID in the guest */
815814
u32 target_cpu;
816-
int numa_node;
817815
/*
818816
* Support for sub-channels. For high performance devices,
819817
* it will be useful to have multiple sub-channels to support
@@ -842,12 +840,6 @@ struct vmbus_channel {
842840
*/
843841
void (*chn_rescind_callback)(struct vmbus_channel *channel);
844842

845-
/*
846-
* The spinlock to protect the structure. It is being used to protect
847-
* test-and-set access to various attributes of the structure as well
848-
* as all sc_list operations.
849-
*/
850-
spinlock_t lock;
851843
/*
852844
* All Sub-channels of a primary channel are linked here.
853845
*/

include/uapi/linux/hyperv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ struct hv_do_fcopy {
219219
* kernel and user-level daemon communicate using a connector channel.
220220
*
221221
* The user mode component first registers with the
222-
* the kernel component. Subsequently, the kernel component requests, data
222+
* kernel component. Subsequently, the kernel component requests, data
223223
* for the specified keys. In response to this message the user mode component
224224
* fills in the value corresponding to the specified key. We overload the
225225
* sequence field in the cn_msg header to define our KVP message types.

tools/hv/hv_kvp_daemon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ void kvp_get_os_info(void)
437437

438438
/*
439439
* Parse the /etc/os-release file if present:
440-
* http://www.freedesktop.org/software/systemd/man/os-release.html
440+
* https://www.freedesktop.org/software/systemd/man/os-release.html
441441
*/
442442
file = fopen("/etc/os-release", "r");
443443
if (file != NULL) {

0 commit comments

Comments
 (0)