Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'for-linus-5.0-rc3-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip

Pull xen fixes from Juergen Gross:

- Several fixes for the Xen pvcalls drivers (1 fix for the backend and
8 for the frontend).

- A fix for a rather longstanding bug in the Xen sched_clock()
interface which led to weird time jumps when migrating the system.

- A fix for avoiding accesses to x2apic MSRs in Xen PV guests.

* tag 'for-linus-5.0-rc3-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip:
xen: Fix x86 sched_clock() interface for xen
pvcalls-front: fix potential null dereference
always clear the X2APIC_ENABLE bit for PV guest
pvcalls-front: Avoid get_free_pages(GFP_KERNEL) under spinlock
xen/pvcalls: remove set but not used variable 'intf'
pvcalls-back: set -ENOTCONN in pvcalls_conn_back_read
pvcalls-front: don't return error when the ring is full
pvcalls-front: properly allocate sk
pvcalls-front: don't try to free unallocated rings
pvcalls-front: read all data before closing the connection

+91 -43
+1 -4
arch/x86/xen/enlighten_pv.c
··· 898 898 val = native_read_msr_safe(msr, err); 899 899 switch (msr) { 900 900 case MSR_IA32_APICBASE: 901 - #ifdef CONFIG_X86_X2APIC 902 - if (!(cpuid_ecx(1) & (1 << (X86_FEATURE_X2APIC & 31)))) 903 - #endif 904 - val &= ~X2APIC_ENABLE; 901 + val &= ~X2APIC_ENABLE; 905 902 break; 906 903 } 907 904 return val;
+9 -3
arch/x86/xen/time.c
··· 361 361 { 362 362 int cpu; 363 363 364 - pvclock_resume(); 365 - 366 364 if (xen_clockevent != &xen_vcpuop_clockevent) 367 365 return; 368 366 ··· 377 379 }; 378 380 379 381 static struct pvclock_vsyscall_time_info *xen_clock __read_mostly; 382 + static u64 xen_clock_value_saved; 380 383 381 384 void xen_save_time_memory_area(void) 382 385 { 383 386 struct vcpu_register_time_memory_area t; 384 387 int ret; 388 + 389 + xen_clock_value_saved = xen_clocksource_read() - xen_sched_clock_offset; 385 390 386 391 if (!xen_clock) 387 392 return; ··· 405 404 int ret; 406 405 407 406 if (!xen_clock) 408 - return; 407 + goto out; 409 408 410 409 t.addr.v = &xen_clock->pvti; 411 410 ··· 422 421 if (ret != 0) 423 422 pr_notice("Cannot restore secondary vcpu_time_info (err %d)", 424 423 ret); 424 + 425 + out: 426 + /* Need pvclock_resume() before using xen_clocksource_read(). */ 427 + pvclock_resume(); 428 + xen_sched_clock_offset = xen_clocksource_read() - xen_clock_value_saved; 425 429 } 426 430 427 431 static void xen_setup_vsyscall_time_info(void)
+1 -1
drivers/xen/events/events_base.c
··· 1650 1650 xen_have_vector_callback = 0; 1651 1651 return; 1652 1652 } 1653 - pr_info("Xen HVM callback vector for event delivery is enabled\n"); 1653 + pr_info_once("Xen HVM callback vector for event delivery is enabled\n"); 1654 1654 alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR, 1655 1655 xen_hvm_callback_vector); 1656 1656 }
+4 -5
drivers/xen/pvcalls-back.c
··· 160 160 161 161 /* write the data, then modify the indexes */ 162 162 virt_wmb(); 163 - if (ret < 0) 163 + if (ret < 0) { 164 + atomic_set(&map->read, 0); 164 165 intf->in_error = ret; 165 - else 166 + } else 166 167 intf->in_prod = prod + ret; 167 168 /* update the indexes, then notify the other end */ 168 169 virt_wmb(); ··· 283 282 static void pvcalls_sk_state_change(struct sock *sock) 284 283 { 285 284 struct sock_mapping *map = sock->sk_user_data; 286 - struct pvcalls_data_intf *intf; 287 285 288 286 if (map == NULL) 289 287 return; 290 288 291 - intf = map->ring; 292 - intf->in_error = -ENOTCONN; 289 + atomic_inc(&map->read); 293 290 notify_remote_via_irq(map->irq); 294 291 } 295 292
+76 -30
drivers/xen/pvcalls-front.c
··· 31 31 #define PVCALLS_NR_RSP_PER_RING __CONST_RING_SIZE(xen_pvcalls, XEN_PAGE_SIZE) 32 32 #define PVCALLS_FRONT_MAX_SPIN 5000 33 33 34 + static struct proto pvcalls_proto = { 35 + .name = "PVCalls", 36 + .owner = THIS_MODULE, 37 + .obj_size = sizeof(struct sock), 38 + }; 39 + 34 40 struct pvcalls_bedata { 35 41 struct xen_pvcalls_front_ring ring; 36 42 grant_ref_t ref; ··· 341 335 return ret; 342 336 } 343 337 338 + static void free_active_ring(struct sock_mapping *map) 339 + { 340 + if (!map->active.ring) 341 + return; 342 + 343 + free_pages((unsigned long)map->active.data.in, 344 + map->active.ring->ring_order); 345 + free_page((unsigned long)map->active.ring); 346 + } 347 + 348 + static int alloc_active_ring(struct sock_mapping *map) 349 + { 350 + void *bytes; 351 + 352 + map->active.ring = (struct pvcalls_data_intf *) 353 + get_zeroed_page(GFP_KERNEL); 354 + if (!map->active.ring) 355 + goto out; 356 + 357 + map->active.ring->ring_order = PVCALLS_RING_ORDER; 358 + bytes = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 359 + PVCALLS_RING_ORDER); 360 + if (!bytes) 361 + goto out; 362 + 363 + map->active.data.in = bytes; 364 + map->active.data.out = bytes + 365 + XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER); 366 + 367 + return 0; 368 + 369 + out: 370 + free_active_ring(map); 371 + return -ENOMEM; 372 + } 373 + 344 374 static int create_active(struct sock_mapping *map, int *evtchn) 345 375 { 346 376 void *bytes; ··· 385 343 *evtchn = -1; 386 344 init_waitqueue_head(&map->active.inflight_conn_req); 387 345 388 - map->active.ring = (struct pvcalls_data_intf *) 389 - __get_free_page(GFP_KERNEL | __GFP_ZERO); 390 - if (map->active.ring == NULL) 391 - goto out_error; 392 - map->active.ring->ring_order = PVCALLS_RING_ORDER; 393 - bytes = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 394 - PVCALLS_RING_ORDER); 395 - if (bytes == NULL) 396 - goto out_error; 346 + bytes = map->active.data.in; 397 347 for (i = 0; i < (1 << PVCALLS_RING_ORDER); i++) 398 348 map->active.ring->ref[i] = gnttab_grant_foreign_access( 399 349 pvcalls_front_dev->otherend_id, ··· 394 360 map->active.ref = gnttab_grant_foreign_access( 395 361 pvcalls_front_dev->otherend_id, 396 362 pfn_to_gfn(virt_to_pfn((void *)map->active.ring)), 0); 397 - 398 - map->active.data.in = bytes; 399 - map->active.data.out = bytes + 400 - XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER); 401 363 402 364 ret = xenbus_alloc_evtchn(pvcalls_front_dev, evtchn); 403 365 if (ret) ··· 415 385 out_error: 416 386 if (*evtchn >= 0) 417 387 xenbus_free_evtchn(pvcalls_front_dev, *evtchn); 418 - free_pages((unsigned long)map->active.data.in, PVCALLS_RING_ORDER); 419 - free_page((unsigned long)map->active.ring); 420 388 return ret; 421 389 } 422 390 ··· 434 406 return PTR_ERR(map); 435 407 436 408 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); 409 + ret = alloc_active_ring(map); 410 + if (ret < 0) { 411 + pvcalls_exit_sock(sock); 412 + return ret; 413 + } 437 414 438 415 spin_lock(&bedata->socket_lock); 439 416 ret = get_request(bedata, &req_id); 440 417 if (ret < 0) { 441 418 spin_unlock(&bedata->socket_lock); 419 + free_active_ring(map); 442 420 pvcalls_exit_sock(sock); 443 421 return ret; 444 422 } 445 423 ret = create_active(map, &evtchn); 446 424 if (ret < 0) { 447 425 spin_unlock(&bedata->socket_lock); 426 + free_active_ring(map); 448 427 pvcalls_exit_sock(sock); 449 428 return ret; 450 429 } ··· 504 469 virt_mb(); 505 470 506 471 size = pvcalls_queued(prod, cons, array_size); 507 - if (size >= array_size) 472 + if (size > array_size) 508 473 return -EINVAL; 474 + if (size == array_size) 475 + return 0; 509 476 if (len > array_size - size) 510 477 len = array_size - size; 511 478 ··· 597 560 error = intf->in_error; 598 561 /* get pointers before reading from the ring */ 599 562 virt_rmb(); 600 - if (error < 0) 601 - return error; 602 563 603 564 size = pvcalls_queued(prod, cons, array_size); 604 565 masked_prod = pvcalls_mask(prod, array_size); 605 566 masked_cons = pvcalls_mask(cons, array_size); 606 567 607 568 if (size == 0) 608 - return 0; 569 + return error ?: size; 609 570 610 571 if (len > size) 611 572 len = size; ··· 815 780 } 816 781 } 817 782 783 + map2 = kzalloc(sizeof(*map2), GFP_KERNEL); 784 + if (map2 == NULL) { 785 + clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT, 786 + (void *)&map->passive.flags); 787 + pvcalls_exit_sock(sock); 788 + return -ENOMEM; 789 + } 790 + ret = alloc_active_ring(map2); 791 + if (ret < 0) { 792 + clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT, 793 + (void *)&map->passive.flags); 794 + kfree(map2); 795 + pvcalls_exit_sock(sock); 796 + return ret; 797 + } 818 798 spin_lock(&bedata->socket_lock); 819 799 ret = get_request(bedata, &req_id); 820 800 if (ret < 0) { 821 801 clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT, 822 802 (void *)&map->passive.flags); 823 803 spin_unlock(&bedata->socket_lock); 804 + free_active_ring(map2); 805 + kfree(map2); 824 806 pvcalls_exit_sock(sock); 825 807 return ret; 826 808 } 827 - map2 = kzalloc(sizeof(*map2), GFP_ATOMIC); 828 - if (map2 == NULL) { 829 - clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT, 830 - (void *)&map->passive.flags); 831 - spin_unlock(&bedata->socket_lock); 832 - pvcalls_exit_sock(sock); 833 - return -ENOMEM; 834 - } 809 + 835 810 ret = create_active(map2, &evtchn); 836 811 if (ret < 0) { 812 + free_active_ring(map2); 837 813 kfree(map2); 838 814 clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT, 839 815 (void *)&map->passive.flags); ··· 885 839 886 840 received: 887 841 map2->sock = newsock; 888 - newsock->sk = kzalloc(sizeof(*newsock->sk), GFP_KERNEL); 842 + newsock->sk = sk_alloc(sock_net(sock->sk), PF_INET, GFP_KERNEL, &pvcalls_proto, false); 889 843 if (!newsock->sk) { 890 844 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID; 891 845 map->passive.inflight_req_id = PVCALLS_INVALID_ID; ··· 1078 1032 spin_lock(&bedata->socket_lock); 1079 1033 list_del(&map->list); 1080 1034 spin_unlock(&bedata->socket_lock); 1081 - if (READ_ONCE(map->passive.inflight_req_id) != 1082 - PVCALLS_INVALID_ID) { 1035 + if (READ_ONCE(map->passive.inflight_req_id) != PVCALLS_INVALID_ID && 1036 + READ_ONCE(map->passive.inflight_req_id) != 0) { 1083 1037 pvcalls_front_free_map(bedata, 1084 1038 map->passive.accept_map); 1085 1039 }