Skip to content

Commit f8e4fae

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/cmetcalf/linux-tile
Pull arch/tile updates from Chris Metcalf: "The only substantive pieces in this batch are some more vDSO support, and removing the reference to &platform_bus in tile-srom.c. The rest are minor issues reported to me" * git://git.kernel.org/pub/scm/linux/kernel/git/cmetcalf/linux-tile: tile: add clock_gettime support to vDSO tile: switch to using seqlocks for the vDSO time code tile gxio: use better string copy primitive char: tile-srom: Add real platform bus parent Removed repeated word in comments tilegx: Enable ARCH_SUPPORTS_ATOMIC_RMW tile: Remove tile-specific _sinitdata and _einitdata tile: use ARRAY_SIZE
2 parents 6325e94 + 78410af commit f8e4fae

12 files changed

Lines changed: 245 additions & 94 deletions

File tree

‎arch/tile/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ config TILEGX
134134
select HAVE_KPROBES
135135
select HAVE_KRETPROBES
136136
select HAVE_ARCH_KGDB
137+
select ARCH_SUPPORTS_ATOMIC_RMW
137138

138139
config TILEPRO
139140
def_bool !TILEGX

‎arch/tile/gxio/mpipe.c‎

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,32 @@
2929
/* HACK: Avoid pointless "shadow" warnings. */
3030
#define link link_shadow
3131

32+
/**
33+
* strscpy - Copy a C-string into a sized buffer, but only if it fits
34+
* @dest: Where to copy the string to
35+
* @src: Where to copy the string from
36+
* @size: size of destination buffer
37+
*
38+
* Use this routine to avoid copying too-long strings.
39+
* The routine returns the total number of bytes copied
40+
* (including the trailing NUL) or zero if the buffer wasn't
41+
* big enough. To ensure that programmers pay attention
42+
* to the return code, the destination has a single NUL
43+
* written at the front (if size is non-zero) when the
44+
* buffer is not big enough.
45+
*/
46+
static size_t strscpy(char *dest, const char *src, size_t size)
47+
{
48+
size_t len = strnlen(src, size) + 1;
49+
if (len > size) {
50+
if (size)
51+
dest[0] = '\0';
52+
return 0;
53+
}
54+
memcpy(dest, src, len);
55+
return len;
56+
}
57+
3258
int gxio_mpipe_init(gxio_mpipe_context_t *context, unsigned int mpipe_index)
3359
{
3460
char file[32];
@@ -511,8 +537,8 @@ int gxio_mpipe_link_instance(const char *link_name)
511537
if (!context)
512538
return GXIO_ERR_NO_DEVICE;
513539

514-
strncpy(name.name, link_name, sizeof(name.name));
515-
name.name[GXIO_MPIPE_LINK_NAME_LEN - 1] = '\0';
540+
if (strscpy(name.name, link_name, sizeof(name.name)) == 0)
541+
return GXIO_ERR_NO_DEVICE;
516542

517543
return gxio_mpipe_info_instance_aux(context, name);
518544
}
@@ -529,7 +555,8 @@ int gxio_mpipe_link_enumerate_mac(int idx, char *link_name, uint8_t *link_mac)
529555

530556
rv = gxio_mpipe_info_enumerate_aux(context, idx, &name, &mac);
531557
if (rv >= 0) {
532-
strncpy(link_name, name.name, sizeof(name.name));
558+
if (strscpy(link_name, name.name, sizeof(name.name)) == 0)
559+
return GXIO_ERR_INVAL_MEMORY_SIZE;
533560
memcpy(link_mac, mac.mac, sizeof(mac.mac));
534561
}
535562

@@ -545,8 +572,8 @@ int gxio_mpipe_link_open(gxio_mpipe_link_t *link,
545572
_gxio_mpipe_link_name_t name;
546573
int rv;
547574

548-
strncpy(name.name, link_name, sizeof(name.name));
549-
name.name[GXIO_MPIPE_LINK_NAME_LEN - 1] = '\0';
575+
if (strscpy(name.name, link_name, sizeof(name.name)) == 0)
576+
return GXIO_ERR_NO_DEVICE;
550577

551578
rv = gxio_mpipe_link_open_aux(context, name, flags);
552579
if (rv < 0)

‎arch/tile/include/asm/sections.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
#include <asm-generic/sections.h>
2121

22-
/* Text and data are at different areas in the kernel VA space. */
23-
extern char _sinitdata[], _einitdata[];
24-
2522
/* Write-once data is writable only till the end of initialization. */
2623
extern char __w1data_begin[], __w1data_end[];
2724

‎arch/tile/include/asm/vdso.h‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef __TILE_VDSO_H__
1616
#define __TILE_VDSO_H__
1717

18+
#include <linux/seqlock.h>
1819
#include <linux/types.h>
1920

2021
/*
@@ -26,15 +27,20 @@
2627
*/
2728

2829
struct vdso_data {
29-
__u64 tz_update_count; /* Timezone atomicity ctr */
30-
__u64 tb_update_count; /* Timebase atomicity ctr */
31-
__u64 xtime_tod_stamp; /* TOD clock for xtime */
32-
__u64 xtime_clock_sec; /* Kernel time second */
33-
__u64 xtime_clock_nsec; /* Kernel time nanosecond */
34-
__u64 wtom_clock_sec; /* Wall to monotonic clock second */
35-
__u64 wtom_clock_nsec; /* Wall to monotonic clock nanosecond */
30+
seqcount_t tz_seq; /* Timezone seqlock */
31+
seqcount_t tb_seq; /* Timebase seqlock */
32+
__u64 cycle_last; /* TOD clock for xtime */
33+
__u64 mask; /* Cycle mask */
3634
__u32 mult; /* Cycle to nanosecond multiplier */
3735
__u32 shift; /* Cycle to nanosecond divisor (power of two) */
36+
__u64 wall_time_sec;
37+
__u64 wall_time_snsec;
38+
__u64 monotonic_time_sec;
39+
__u64 monotonic_time_snsec;
40+
__u64 wall_time_coarse_sec;
41+
__u64 wall_time_coarse_nsec;
42+
__u64 monotonic_time_coarse_sec;
43+
__u64 monotonic_time_coarse_nsec;
3844
__u32 tz_minuteswest; /* Minutes west of Greenwich */
3945
__u32 tz_dsttime; /* Type of dst correction */
4046
};

‎arch/tile/include/uapi/arch/sim_def.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,19 +360,19 @@
360360
* @{
361361
*/
362362

363-
/** Use with with SIM_PROFILER_CHIP_xxx to control the memory controllers. */
363+
/** Use with SIM_PROFILER_CHIP_xxx to control the memory controllers. */
364364
#define SIM_CHIP_MEMCTL 0x001
365365

366-
/** Use with with SIM_PROFILER_CHIP_xxx to control the XAUI interface. */
366+
/** Use with SIM_PROFILER_CHIP_xxx to control the XAUI interface. */
367367
#define SIM_CHIP_XAUI 0x002
368368

369-
/** Use with with SIM_PROFILER_CHIP_xxx to control the PCIe interface. */
369+
/** Use with SIM_PROFILER_CHIP_xxx to control the PCIe interface. */
370370
#define SIM_CHIP_PCIE 0x004
371371

372-
/** Use with with SIM_PROFILER_CHIP_xxx to control the MPIPE interface. */
372+
/** Use with SIM_PROFILER_CHIP_xxx to control the MPIPE interface. */
373373
#define SIM_CHIP_MPIPE 0x008
374374

375-
/** Use with with SIM_PROFILER_CHIP_xxx to control the TRIO interface. */
375+
/** Use with SIM_PROFILER_CHIP_xxx to control the TRIO interface. */
376376
#define SIM_CHIP_TRIO 0x010
377377

378378
/** Reference all chip devices. */

‎arch/tile/kernel/time.c‎

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -249,33 +249,52 @@ cycles_t ns2cycles(unsigned long nsecs)
249249

250250
void update_vsyscall_tz(void)
251251
{
252-
/* Userspace gettimeofday will spin while this value is odd. */
253-
++vdso_data->tz_update_count;
254-
smp_wmb();
252+
write_seqcount_begin(&vdso_data->tz_seq);
255253
vdso_data->tz_minuteswest = sys_tz.tz_minuteswest;
256254
vdso_data->tz_dsttime = sys_tz.tz_dsttime;
257-
smp_wmb();
258-
++vdso_data->tz_update_count;
255+
write_seqcount_end(&vdso_data->tz_seq);
259256
}
260257

261258
void update_vsyscall(struct timekeeper *tk)
262259
{
263-
struct timespec *wtm = &tk->wall_to_monotonic;
264-
struct clocksource *clock = tk->tkr.clock;
265-
266-
if (clock != &cycle_counter_cs)
260+
if (tk->tkr.clock != &cycle_counter_cs)
267261
return;
268262

269-
/* Userspace gettimeofday will spin while this value is odd. */
270-
++vdso_data->tb_update_count;
271-
smp_wmb();
272-
vdso_data->xtime_tod_stamp = tk->tkr.cycle_last;
273-
vdso_data->xtime_clock_sec = tk->xtime_sec;
274-
vdso_data->xtime_clock_nsec = tk->tkr.xtime_nsec;
275-
vdso_data->wtom_clock_sec = wtm->tv_sec;
276-
vdso_data->wtom_clock_nsec = wtm->tv_nsec;
277-
vdso_data->mult = tk->tkr.mult;
278-
vdso_data->shift = tk->tkr.shift;
279-
smp_wmb();
280-
++vdso_data->tb_update_count;
263+
write_seqcount_begin(&vdso_data->tb_seq);
264+
265+
vdso_data->cycle_last = tk->tkr.cycle_last;
266+
vdso_data->mask = tk->tkr.mask;
267+
vdso_data->mult = tk->tkr.mult;
268+
vdso_data->shift = tk->tkr.shift;
269+
270+
vdso_data->wall_time_sec = tk->xtime_sec;
271+
vdso_data->wall_time_snsec = tk->tkr.xtime_nsec;
272+
273+
vdso_data->monotonic_time_sec = tk->xtime_sec
274+
+ tk->wall_to_monotonic.tv_sec;
275+
vdso_data->monotonic_time_snsec = tk->tkr.xtime_nsec
276+
+ ((u64)tk->wall_to_monotonic.tv_nsec
277+
<< tk->tkr.shift);
278+
while (vdso_data->monotonic_time_snsec >=
279+
(((u64)NSEC_PER_SEC) << tk->tkr.shift)) {
280+
vdso_data->monotonic_time_snsec -=
281+
((u64)NSEC_PER_SEC) << tk->tkr.shift;
282+
vdso_data->monotonic_time_sec++;
283+
}
284+
285+
vdso_data->wall_time_coarse_sec = tk->xtime_sec;
286+
vdso_data->wall_time_coarse_nsec = (long)(tk->tkr.xtime_nsec >>
287+
tk->tkr.shift);
288+
289+
vdso_data->monotonic_time_coarse_sec =
290+
vdso_data->wall_time_coarse_sec + tk->wall_to_monotonic.tv_sec;
291+
vdso_data->monotonic_time_coarse_nsec =
292+
vdso_data->wall_time_coarse_nsec + tk->wall_to_monotonic.tv_nsec;
293+
294+
while (vdso_data->monotonic_time_coarse_nsec >= NSEC_PER_SEC) {
295+
vdso_data->monotonic_time_coarse_nsec -= NSEC_PER_SEC;
296+
vdso_data->monotonic_time_coarse_sec++;
297+
}
298+
299+
write_seqcount_end(&vdso_data->tb_seq);
281300
}

‎arch/tile/kernel/traps.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ void __kprobes do_trap(struct pt_regs *regs, int fault_num,
277277
if (fixup_exception(regs)) /* ILL_TRANS or UNALIGN_DATA */
278278
return;
279279
if (fault_num >= 0 &&
280-
fault_num < sizeof(int_name)/sizeof(int_name[0]) &&
280+
fault_num < ARRAY_SIZE(int_name) &&
281281
int_name[fault_num] != NULL)
282282
name = int_name[fault_num];
283283
else

‎arch/tile/kernel/vdso/vdso.lds.S‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ VERSION
8282
__vdso_rt_sigreturn;
8383
__vdso_gettimeofday;
8484
gettimeofday;
85+
__vdso_clock_gettime;
86+
clock_gettime;
8587
local:*;
8688
};
8789
}

0 commit comments

Comments
 (0)