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 branches 'locking-urgent-for-linus' and 'timers-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull futex and timer fixes from Thomas Gleixner:
"A oneliner bugfix for the jinxed futex code:

- Drop hash bucket lock in the error exit path. I really could slap
myself for intruducing that bug while fixing all the other horror
in that code three month ago ...

and the timer department is not too proud about the following fixes:

- Deal with a long standing rounding bug in the timeval to jiffies
conversion. It's a real issue and this fix fell through the cracks
for quite some time.

- Another round of alarmtimer fixes. Finally this code gets used
more widely and the subtle issues hidden for quite some time are
noticed and fixed. Nothing really exciting, just the itty bitty
details which bite the serious users here and there"

* 'locking-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
futex: Unlock hb->lock in futex_wait_requeue_pi() error path

* 'timers-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
alarmtimer: Lock k_itimer during timer callback
alarmtimer: Do not signal SIGEV_NONE timers
alarmtimer: Return relative times in timer_gettime
jiffies: Fix timeval conversion to jiffies

+54 -47
-12
include/linux/jiffies.h
··· 258 258 #define SEC_JIFFIE_SC (32 - SHIFT_HZ) 259 259 #endif 260 260 #define NSEC_JIFFIE_SC (SEC_JIFFIE_SC + 29) 261 - #define USEC_JIFFIE_SC (SEC_JIFFIE_SC + 19) 262 261 #define SEC_CONVERSION ((unsigned long)((((u64)NSEC_PER_SEC << SEC_JIFFIE_SC) +\ 263 262 TICK_NSEC -1) / (u64)TICK_NSEC)) 264 263 265 264 #define NSEC_CONVERSION ((unsigned long)((((u64)1 << NSEC_JIFFIE_SC) +\ 266 265 TICK_NSEC -1) / (u64)TICK_NSEC)) 267 - #define USEC_CONVERSION \ 268 - ((unsigned long)((((u64)NSEC_PER_USEC << USEC_JIFFIE_SC) +\ 269 - TICK_NSEC -1) / (u64)TICK_NSEC)) 270 - /* 271 - * USEC_ROUND is used in the timeval to jiffie conversion. See there 272 - * for more details. It is the scaled resolution rounding value. Note 273 - * that it is a 64-bit value. Since, when it is applied, we are already 274 - * in jiffies (albit scaled), it is nothing but the bits we will shift 275 - * off. 276 - */ 277 - #define USEC_ROUND (u64)(((u64)1 << USEC_JIFFIE_SC) - 1) 278 266 /* 279 267 * The maximum jiffie value is (MAX_INT >> 1). Here we translate that 280 268 * into seconds. The 64-bit case will overflow if we are not careful,
+1
kernel/futex.c
··· 2592 2592 * shared futexes. We need to compare the keys: 2593 2593 */ 2594 2594 if (match_futex(&q.key, &key2)) { 2595 + queue_unlock(hb); 2595 2596 ret = -EINVAL; 2596 2597 goto out_put_keys; 2597 2598 }
+23 -11
kernel/time/alarmtimer.c
··· 464 464 static enum alarmtimer_restart alarm_handle_timer(struct alarm *alarm, 465 465 ktime_t now) 466 466 { 467 + unsigned long flags; 467 468 struct k_itimer *ptr = container_of(alarm, struct k_itimer, 468 469 it.alarm.alarmtimer); 469 - if (posix_timer_event(ptr, 0) != 0) 470 - ptr->it_overrun++; 470 + enum alarmtimer_restart result = ALARMTIMER_NORESTART; 471 + 472 + spin_lock_irqsave(&ptr->it_lock, flags); 473 + if ((ptr->it_sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE) { 474 + if (posix_timer_event(ptr, 0) != 0) 475 + ptr->it_overrun++; 476 + } 471 477 472 478 /* Re-add periodic timers */ 473 479 if (ptr->it.alarm.interval.tv64) { 474 480 ptr->it_overrun += alarm_forward(alarm, now, 475 481 ptr->it.alarm.interval); 476 - return ALARMTIMER_RESTART; 482 + result = ALARMTIMER_RESTART; 477 483 } 478 - return ALARMTIMER_NORESTART; 484 + spin_unlock_irqrestore(&ptr->it_lock, flags); 485 + 486 + return result; 479 487 } 480 488 481 489 /** ··· 549 541 * @new_timer: k_itimer pointer 550 542 * @cur_setting: itimerspec data to fill 551 543 * 552 - * Copies the itimerspec data out from the k_itimer 544 + * Copies out the current itimerspec data 553 545 */ 554 546 static void alarm_timer_get(struct k_itimer *timr, 555 547 struct itimerspec *cur_setting) 556 548 { 557 - memset(cur_setting, 0, sizeof(struct itimerspec)); 549 + ktime_t relative_expiry_time = 550 + alarm_expires_remaining(&(timr->it.alarm.alarmtimer)); 558 551 559 - cur_setting->it_interval = 560 - ktime_to_timespec(timr->it.alarm.interval); 561 - cur_setting->it_value = 562 - ktime_to_timespec(timr->it.alarm.alarmtimer.node.expires); 563 - return; 552 + if (ktime_to_ns(relative_expiry_time) > 0) { 553 + cur_setting->it_value = ktime_to_timespec(relative_expiry_time); 554 + } else { 555 + cur_setting->it_value.tv_sec = 0; 556 + cur_setting->it_value.tv_nsec = 0; 557 + } 558 + 559 + cur_setting->it_interval = ktime_to_timespec(timr->it.alarm.interval); 564 560 } 565 561 566 562 /**
+30 -24
kernel/time/time.c
··· 559 559 * that a remainder subtract here would not do the right thing as the 560 560 * resolution values don't fall on second boundries. I.e. the line: 561 561 * nsec -= nsec % TICK_NSEC; is NOT a correct resolution rounding. 562 + * Note that due to the small error in the multiplier here, this 563 + * rounding is incorrect for sufficiently large values of tv_nsec, but 564 + * well formed timespecs should have tv_nsec < NSEC_PER_SEC, so we're 565 + * OK. 562 566 * 563 567 * Rather, we just shift the bits off the right. 564 568 * 565 569 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec 566 570 * value to a scaled second value. 567 571 */ 568 - unsigned long 569 - timespec_to_jiffies(const struct timespec *value) 572 + static unsigned long 573 + __timespec_to_jiffies(unsigned long sec, long nsec) 570 574 { 571 - unsigned long sec = value->tv_sec; 572 - long nsec = value->tv_nsec + TICK_NSEC - 1; 575 + nsec = nsec + TICK_NSEC - 1; 573 576 574 577 if (sec >= MAX_SEC_IN_JIFFIES){ 575 578 sec = MAX_SEC_IN_JIFFIES; ··· 583 580 (NSEC_JIFFIE_SC - SEC_JIFFIE_SC))) >> SEC_JIFFIE_SC; 584 581 585 582 } 583 + 584 + unsigned long 585 + timespec_to_jiffies(const struct timespec *value) 586 + { 587 + return __timespec_to_jiffies(value->tv_sec, value->tv_nsec); 588 + } 589 + 586 590 EXPORT_SYMBOL(timespec_to_jiffies); 587 591 588 592 void ··· 606 596 } 607 597 EXPORT_SYMBOL(jiffies_to_timespec); 608 598 609 - /* Same for "timeval" 599 + /* 600 + * We could use a similar algorithm to timespec_to_jiffies (with a 601 + * different multiplier for usec instead of nsec). But this has a 602 + * problem with rounding: we can't exactly add TICK_NSEC - 1 to the 603 + * usec value, since it's not necessarily integral. 610 604 * 611 - * Well, almost. The problem here is that the real system resolution is 612 - * in nanoseconds and the value being converted is in micro seconds. 613 - * Also for some machines (those that use HZ = 1024, in-particular), 614 - * there is a LARGE error in the tick size in microseconds. 615 - 616 - * The solution we use is to do the rounding AFTER we convert the 617 - * microsecond part. Thus the USEC_ROUND, the bits to be shifted off. 618 - * Instruction wise, this should cost only an additional add with carry 619 - * instruction above the way it was done above. 605 + * We could instead round in the intermediate scaled representation 606 + * (i.e. in units of 1/2^(large scale) jiffies) but that's also 607 + * perilous: the scaling introduces a small positive error, which 608 + * combined with a division-rounding-upward (i.e. adding 2^(scale) - 1 609 + * units to the intermediate before shifting) leads to accidental 610 + * overflow and overestimates. 611 + * 612 + * At the cost of one additional multiplication by a constant, just 613 + * use the timespec implementation. 620 614 */ 621 615 unsigned long 622 616 timeval_to_jiffies(const struct timeval *value) 623 617 { 624 - unsigned long sec = value->tv_sec; 625 - long usec = value->tv_usec; 626 - 627 - if (sec >= MAX_SEC_IN_JIFFIES){ 628 - sec = MAX_SEC_IN_JIFFIES; 629 - usec = 0; 630 - } 631 - return (((u64)sec * SEC_CONVERSION) + 632 - (((u64)usec * USEC_CONVERSION + USEC_ROUND) >> 633 - (USEC_JIFFIE_SC - SEC_JIFFIE_SC))) >> SEC_JIFFIE_SC; 618 + return __timespec_to_jiffies(value->tv_sec, 619 + value->tv_usec * NSEC_PER_USEC); 634 620 } 635 621 EXPORT_SYMBOL(timeval_to_jiffies); 636 622