Re: [PATCH 06/19] perf ftrace: add support for trace option sleep-time

2020-05-30 Thread Namhyung Kim
On Thu, May 21, 2020 at 6:01 AM Arnaldo Carvalho de Melo
 wrote:
>
> Em Sun, May 10, 2020 at 11:06:15PM +0800, Changbin Du escreveu:
> > This adds an option '--nosleep-time' which allow us only to measure
> > on-CPU time. This option is function_graph tracer only.
>
> This seems, for now, very specific to the function_graph tracer, so
> perhaps we should have a:
>
> --function_graph_opts nosleep-time,other,another,etc
>
> ?

Agreed.  Also I don't want to add an option in a negative form
as it's confusing.  Actually, our option parser can recognize
--no-xxx form automatically so adding a positive option (--xxx)
can handle that too.

Thanks
Namhyung


Re: [PATCH RFC] seccomp: Implement syscall isolation based on memory areas

2020-05-30 Thread Gabriel Krisman Bertazi
Kees Cook  writes:

> On Sat, May 30, 2020 at 01:59:53AM -0400, Gabriel Krisman Bertazi wrote:
>> Modern Windows applications are executing system call instructions
>> directly from the application's code without going through the WinAPI.
>> This breaks Wine emulation, because it doesn't have a chance to
>> intercept and emulate these syscalls before they are submitted to Linux.
>> 
>> In addition, we cannot simply trap every system call of the application
>> to userspace using PTRACE_SYSEMU, because performance would suffer,
>> since our main use case is to run Windows games over Linux.  Therefore,
>> we need some in-kernel filtering to decide whether the syscall was
>> issued by the wine code or by the windows application.
>
> Interesting use-case! It seems like you're in the position of needing to
> invert the assumption about syscalls: before you knew everything going
> through WinAPI needed emulation, and now you need to assume everything
> not going through a native library needs emulation. Oof.
>
> Is it possible to disassemble and instrument the Windows code to insert
> breakpoints (or emulation calls) at all the Windows syscall points?

Hi Kees,

I considered instrumenting the syscall instructions with calls to some
wrapper, but I was told that modifying the game in memory or on disk
will trigger all sorts of anti-cheating mechanisms (my main use case are
windows games).

>> [...]
>> * Why not SECCOMP_MODE_FILTER?
>> 
>> We experimented with dynamically generating BPF filters for whitelisted
>> memory regions and using SECCOMP_MODE_FILTER, but there are a few
>> reasons why it isn't enough nor a good idea for our use case:
>> 
>> 1. We cannot set the filters at program initialization time and forget
>> about it, since there is no way of knowing which modules will be loaded,
>> whether native and windows.  Filter would need a way to be updated
>> frequently during game execution.
>> 
>> 2. We cannot predict which Linux libraries will issue syscalls directly.
>> Most of the time, whitelisting libc and a few other libraries is enough,
>> but there are no guarantees other Linux libraries won't issue syscalls
>> directly and break the execution.  Adding every linux library that is
>> loaded also has a large performance cost due to the large resulting
>> filter.
>
> Just so I can understand the expected use: given the dynamic nature of
> the library loading, how would Wine be marking the VMAs?

Paul (cc'ed) is the wine expert, but my understanding is that memory
allocation and initial program load of the emulated binary will go
through wine.  It does the allocation and mark the vma accordingly
before returning the allocated range to the windows application.

>> 3. As I mentioned before, performance is critical.  In our testing with
>> just a single memory segment blacklisted/whitelisted, the minimum size
>> of a bpf filter would be 4 instructions.  In that scenario,
>> SECCOMP_MODE_FILTER added an average overhead of 10% to the execution
>> time of sysinfo(2) in comparison to seccomp disabled, while the impact
>> of SECCOMP_MODE_MEMMAP was averaged around 1.5%.
>
> Was the BPF JIT enabled? I was recently examining filter performance too:
> https://lore.kernel.org/linux-security-module/202005291043.A63D910A8@keescook/

yes:

root@dilma:~# sysctl -a | grep -i jit
net.core.bpf_jit_enable = 1
net.core.bpf_jit_harden = 0

>
>> Indeed, points 1 and 2 could be worked around with some userspace work
>> and improved SECCOMP_MODE_FILTER support, but at a high performance and
>> some stability cost, to obtain the semantics we want.  Still, the
>> performance would suffer, and SECCOMP_MODE_MEMMAP is non intrusive
>> enough that I believe it should be considered as an upstream solution.
>
> It looks like you're using SECCOMP_RET_TRAP for this? Signal handling
> can be pretty slow. Did you try SECCOMP_RET_USER_NOTIF?

I experimented with SECCOMP_RET_TRAP and SECCOMP_RET_TRACE, but I hadn't
consider USER_NOTIF.  It seems to be a quite recent feature and I wasn't
aware of it.  I will try it and let you know.

>> diff --git a/include/linux/mman.h b/include/linux/mman.h
>> index 4b08e9c9c538..a5ca42eb685a 100644
>> --- a/include/linux/mman.h
>> +++ b/include/linux/mman.h
>> @@ -94,7 +94,8 @@ static inline void vm_unacct_memory(long pages)
>>   */
>>  static inline bool arch_validate_prot(unsigned long prot, unsigned long 
>> addr)
>>  {
>> -return (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM)) == 0;
>> +return (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM
>> + | PROT_NOSYSCALL)) == 0;
>>  }
>>  #define arch_validate_prot arch_validate_prot
>>  #endif
>> @@ -119,6 +120,7 @@ calc_vm_prot_bits(unsigned long prot, unsigned long pkey)
>>  return _calc_vm_trans(prot, PROT_READ,  VM_READ ) |
>> _calc_vm_trans(prot, PROT_WRITE, VM_WRITE) |
>> _calc_vm_trans(prot, PROT_EXEC,  VM_EXEC) |
>> +   _calc_vm_trans(prot, PROT_NOSYSCALL, VM_NOSYSCALL) |

Re: [PATCH v6 4/6] clocksource/drivers/timer-riscv: Use per-CPU timer interrupt

2020-05-30 Thread Anup Patel
On Sat, May 30, 2020 at 5:11 PM Marc Zyngier  wrote:
>
> On 2020-05-30 11:07, Anup Patel wrote:
> > Instead of directly calling RISC-V timer interrupt handler from
> > RISC-V local interrupt conntroller driver, this patch implements
> > RISC-V timer interrupt as a per-CPU interrupt using per-CPU APIs
> > of Linux IRQ subsystem.
> >
> > Signed-off-by: Anup Patel 
> > Reviewed-by: Atish Patra 
> > ---
> >  arch/riscv/include/asm/irq.h  |  2 --
> >  drivers/clocksource/timer-riscv.c | 41 ---
> >  drivers/irqchip/irq-riscv-intc.c  |  8 --
> >  3 files changed, 38 insertions(+), 13 deletions(-)
> >
> > diff --git a/arch/riscv/include/asm/irq.h
> > b/arch/riscv/include/asm/irq.h
> > index a9e5f07a7e9c..9807ad164015 100644
> > --- a/arch/riscv/include/asm/irq.h
> > +++ b/arch/riscv/include/asm/irq.h
> > @@ -10,8 +10,6 @@
> >  #include 
> >  #include 
> >
> > -void riscv_timer_interrupt(void);
> > -
> >  #include 
> >
> >  #endif /* _ASM_RISCV_IRQ_H */
> > diff --git a/drivers/clocksource/timer-riscv.c
> > b/drivers/clocksource/timer-riscv.c
> > index c4f15c4068c0..1fe847983f50 100644
> > --- a/drivers/clocksource/timer-riscv.c
> > +++ b/drivers/clocksource/timer-riscv.c
> > @@ -12,8 +12,11 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> > +#include 
> > +#include 
> >  #include 
> >  #include 
> >
> > @@ -39,6 +42,7 @@ static int riscv_clock_next_event(unsigned long
> > delta,
> >   return 0;
> >  }
> >
> > +static unsigned int riscv_clock_event_irq;
> >  static DEFINE_PER_CPU(struct clock_event_device, riscv_clock_event) =
> > {
> >   .name   = "riscv_timer_clockevent",
> >   .features   = CLOCK_EVT_FEAT_ONESHOT,
> > @@ -74,30 +78,36 @@ static int riscv_timer_starting_cpu(unsigned int
> > cpu)
> >   struct clock_event_device *ce = per_cpu_ptr(_clock_event, cpu);
> >
> >   ce->cpumask = cpumask_of(cpu);
> > + ce->irq = riscv_clock_event_irq;
> >   clockevents_config_and_register(ce, riscv_timebase, 100, 0x7fff);
> >
> > - csr_set(CSR_IE, IE_TIE);
> > + enable_percpu_irq(riscv_clock_event_irq,
> > +   irq_get_trigger_type(riscv_clock_event_irq));
> >   return 0;
> >  }
> >
> >  static int riscv_timer_dying_cpu(unsigned int cpu)
> >  {
> > - csr_clear(CSR_IE, IE_TIE);
> > + disable_percpu_irq(riscv_clock_event_irq);
> >   return 0;
> >  }
> >
> >  /* called directly from the low-level interrupt handler */
> > -void riscv_timer_interrupt(void)
> > +static irqreturn_t riscv_timer_interrupt(int irq, void *dev_id)
> >  {
> >   struct clock_event_device *evdev = this_cpu_ptr(_clock_event);
> >
> >   csr_clear(CSR_IE, IE_TIE);
> >   evdev->event_handler(evdev);
> > +
> > + return IRQ_HANDLED;
> >  }
> >
> >  static int __init riscv_timer_init_dt(struct device_node *n)
> >  {
> >   int cpuid, hartid, error;
> > + struct device_node *child;
> > + struct irq_domain *domain;
> >
> >   hartid = riscv_of_processor_hartid(n);
> >   if (hartid < 0) {
> > @@ -115,6 +125,23 @@ static int __init riscv_timer_init_dt(struct
> > device_node *n)
> >   if (cpuid != smp_processor_id())
> >   return 0;
> >
> > + domain = NULL;
> > + for_each_child_of_node(n, child) {
> > + domain = irq_find_host(child);
> > + if (domain)
> > + break;
> > + }
>
> This is a bit clumsy, and probably better written as:
>
>  child = of_get_compatible(n, "riscv,cpu-intc");
>  if (!child) { error out }
>  domain = irq_find_host(child);

I thought of not hard-coding INTC compatible string here but
both RISC-V INTC and RISC-V Timer are RISC-V specific so
I guess it's simpler to use of_get_compatible() directly.

I will update.

>
> It would be even better if each CPU would have its per-CPU interrupt
> controller designated as such (with an interrupt-parent property),
> meaning that you wouldn't have to do anything at all.
>
> Too late for that anyway.

Yes, too late now.

Regards,
Anup


Re: [PATCH 03/19] perf ftrace: select function/function_graph tracer automatically

2020-05-30 Thread Namhyung Kim
Hello,

On Mon, May 11, 2020 at 12:07 AM Changbin Du  wrote:
>
> The '-g/-G' options have already implied function_graph tracer should be
> used instead of function tracer. So the extra option '--tracer' can be
> killed.
>
> This patch changes the behavior as below:
>   - By default, function tracer is used.

Why?  You also removed -t/--tracer option.

>   - If '-g' or '-G' option is on, then function_graph tracer is used.

I'm ok with this.

>   - The perf configuration item 'ftrace.tracer' is removed.

Why?

>   - The default filter for -G is to trace all functions.

There's no reason to use -G option then.  Also It might be confusing
if it sees an argument - whether it's a function or a workload.

I just don't know why you want to change this as we have a way to
change the default tracer already.

Thanks

Namhyung


Re: [PATCH v6 3/6] irqchip: RISC-V per-HART local interrupt controller driver

2020-05-30 Thread Anup Patel
On Sat, May 30, 2020 at 5:31 PM Marc Zyngier  wrote:
>
> On 2020-05-30 11:07, Anup Patel wrote:
> > The RISC-V per-HART local interrupt controller manages software
> > interrupts, timer interrupts, external interrupts (which are routed
> > via the platform level interrupt controller) and other per-HART
> > local interrupts.
> >
> > This patch adds a driver for the RISC-V local interrupt controller.
>
> Please don't use "This patch...". Say something like:
>
> "Add a driver driver for this component, which eventually replaces
>   the RISC-V architecture code, allowing for a better split between
>   arch code and drivers."

Okay, will update.

>
> > It is a major re-write over perviously submitted version.
> > (Refer, https://www.spinics.net/lists/devicetree/msg241230.html)
>
> I'm not sure that's very useful. Again, this is better placed in the
> cover letter, and can be retrived via the Link: tags.

Okay, will update.

>
> > The driver is compliant with RISC-V Hart-Level Interrupt Controller
> > DT bindings located at:
> > Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt
> >
> > Co-developed-by: Palmer Dabbelt 
> > Signed-off-by: Palmer Dabbelt 
> > Signed-off-by: Anup Patel 
> > Acked-by: Palmer Dabbelt 
> > ---
> >  arch/riscv/Kconfig|   1 +
> >  arch/riscv/include/asm/irq.h  |   2 -
> >  arch/riscv/kernel/irq.c   |  33 +--
> >  arch/riscv/kernel/traps.c |   2 -
> >  drivers/irqchip/Kconfig   |  13 +++
> >  drivers/irqchip/Makefile  |   1 +
> >  drivers/irqchip/irq-riscv-intc.c  | 148 ++
> >  drivers/irqchip/irq-sifive-plic.c |  30 --
> >  include/linux/cpuhotplug.h|   1 +
> >  9 files changed, 191 insertions(+), 40 deletions(-)
> >  create mode 100644 drivers/irqchip/irq-riscv-intc.c
> >
> > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> > index 90a008e28f7e..822cb0e1a380 100644
> > --- a/arch/riscv/Kconfig
> > +++ b/arch/riscv/Kconfig
> > @@ -40,6 +40,7 @@ config RISCV
> >   select HAVE_PERF_REGS
> >   select HAVE_PERF_USER_STACK_DUMP
> >   select HAVE_SYSCALL_TRACEPOINTS
> > + select HANDLE_DOMAIN_IRQ
> >   select IRQ_DOMAIN
> >   select SPARSE_IRQ
> >   select SYSCTL_EXCEPTION_TRACE
> > diff --git a/arch/riscv/include/asm/irq.h
> > b/arch/riscv/include/asm/irq.h
> > index 0183e15ace66..a9e5f07a7e9c 100644
> > --- a/arch/riscv/include/asm/irq.h
> > +++ b/arch/riscv/include/asm/irq.h
> > @@ -10,8 +10,6 @@
> >  #include 
> >  #include 
> >
> > -#define NR_IRQS 0
> > -
> >  void riscv_timer_interrupt(void);
> >
> >  #include 
> > diff --git a/arch/riscv/kernel/irq.c b/arch/riscv/kernel/irq.c
> > index bb0bfcd537e7..eb8777642ce6 100644
> > --- a/arch/riscv/kernel/irq.c
> > +++ b/arch/riscv/kernel/irq.c
> > @@ -7,7 +7,6 @@
> >
> >  #include 
> >  #include 
> > -#include 
> >  #include 
> >  #include 
> >
> > @@ -19,39 +18,13 @@ int arch_show_interrupts(struct seq_file *p, int
> > prec)
> >
> >  asmlinkage __visible void __irq_entry do_IRQ(struct pt_regs *regs)
> >  {
> > - struct pt_regs *old_regs;
> > -
> > - switch (regs->cause & ~CAUSE_IRQ_FLAG) {
> > - case RV_IRQ_TIMER:
> > - old_regs = set_irq_regs(regs);
> > - irq_enter();
> > - riscv_timer_interrupt();
> > - irq_exit();
> > - set_irq_regs(old_regs);
> > - break;
> > -#ifdef CONFIG_SMP
> > - case RV_IRQ_SOFT:
> > - /*
> > -  * We only use software interrupts to pass IPIs, so if a 
> > non-SMP
> > -  * system gets one, then we don't know what to do.
> > -  */
> > - handle_IPI(regs);
> > - break;
> > -#endif
> > - case RV_IRQ_EXT:
> > - old_regs = set_irq_regs(regs);
> > - irq_enter();
> > + if (handle_arch_irq)
> >   handle_arch_irq(regs);
> > - irq_exit();
> > - set_irq_regs(old_regs);
> > - break;
> > - default:
> > - pr_alert("unexpected interrupt cause 0x%lx", regs->cause);
> > - BUG();
> > - }
> >  }
> >
> >  void __init init_IRQ(void)
> >  {
> >   irqchip_init();
> > + if (!handle_arch_irq)
> > + panic("No interrupt controller found.");
> >  }
> > diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c
> > index 7f58fa53033f..f48c76aadbf3 100644
> > --- a/arch/riscv/kernel/traps.c
> > +++ b/arch/riscv/kernel/traps.c
> > @@ -178,6 +178,4 @@ void trap_init(void)
> >   csr_write(CSR_SCRATCH, 0);
> >   /* Set the exception vector address */
> >   csr_write(CSR_TVEC, _exception);
> > - /* Enable interrupts */
> > - csr_write(CSR_IE, IE_SIE);
> >  }
> > diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
> > index a85aada04a64..95d6137a8117 100644
> > --- a/drivers/irqchip/Kconfig
> > +++ b/drivers/irqchip/Kconfig
> > @@ -493,6 +493,19 @@ config 

fs/exfat/nls.c:531:22: warning: Variable 'p_uniname->name_len' is reassigned a value before the old one has been used. [redundantAssignment]

2020-05-30 Thread kbuild test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   ffeb595d84811dde16a28b33d8a7cf26d51d51b3
commit: b9d1e2e6265f5dc25e9f5dbfbde3e53d8a4958ac exfat: add Kconfig and Makefile
date:   3 months ago
compiler: gcc-9 (Debian 9.3.0-13) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot 


cppcheck warnings: (new ones prefixed by >>)

>> fs/exfat/nls.c:531:22: warning: Variable 'p_uniname->name_len' is reassigned 
>> a value before the old one has been used. [redundantAssignment]
p_uniname->name_len = unilen;
^
   fs/exfat/nls.c:519:22: note: Variable 'p_uniname->name_len' is reassigned a 
value before the old one has been used.
p_uniname->name_len = unilen & 0xFF;
^
   fs/exfat/nls.c:531:22: note: Variable 'p_uniname->name_len' is reassigned a 
value before the old one has been used.
p_uniname->name_len = unilen;
^

vim +531 fs/exfat/nls.c

370e812b3ec190 Namjae Jeon 2020-03-02  492  
370e812b3ec190 Namjae Jeon 2020-03-02  493  static int 
exfat_utf8_to_utf16(struct super_block *sb,
370e812b3ec190 Namjae Jeon 2020-03-02  494  const unsigned char 
*p_cstring, const int len,
370e812b3ec190 Namjae Jeon 2020-03-02  495  struct exfat_uni_name 
*p_uniname, int *p_lossy)
370e812b3ec190 Namjae Jeon 2020-03-02  496  {
370e812b3ec190 Namjae Jeon 2020-03-02  497  int i, unilen, lossy = 
NLS_NAME_NO_LOSSY;
370e812b3ec190 Namjae Jeon 2020-03-02  498  unsigned short 
upname[MAX_NAME_LENGTH + 1];
370e812b3ec190 Namjae Jeon 2020-03-02  499  unsigned short *uniname = 
p_uniname->name;
370e812b3ec190 Namjae Jeon 2020-03-02  500  
370e812b3ec190 Namjae Jeon 2020-03-02  501  WARN_ON(!len);
370e812b3ec190 Namjae Jeon 2020-03-02  502  
370e812b3ec190 Namjae Jeon 2020-03-02  503  unilen = 
utf8s_to_utf16s(p_cstring, len, UTF16_HOST_ENDIAN,
370e812b3ec190 Namjae Jeon 2020-03-02  504  (wchar_t 
*)uniname, MAX_NAME_LENGTH + 2);
370e812b3ec190 Namjae Jeon 2020-03-02  505  if (unilen < 0) {
370e812b3ec190 Namjae Jeon 2020-03-02  506  exfat_msg(sb, KERN_ERR,
370e812b3ec190 Namjae Jeon 2020-03-02  507  "failed to %s 
(err : %d) nls len : %d",
370e812b3ec190 Namjae Jeon 2020-03-02  508  __func__, 
unilen, len);
370e812b3ec190 Namjae Jeon 2020-03-02  509  return unilen;
370e812b3ec190 Namjae Jeon 2020-03-02  510  }
370e812b3ec190 Namjae Jeon 2020-03-02  511  
370e812b3ec190 Namjae Jeon 2020-03-02  512  if (unilen > MAX_NAME_LENGTH) {
370e812b3ec190 Namjae Jeon 2020-03-02  513  exfat_msg(sb, KERN_ERR,
370e812b3ec190 Namjae Jeon 2020-03-02  514  "failed to %s 
(estr:ENAMETOOLONG) nls len : %d, unilen : %d > %d",
370e812b3ec190 Namjae Jeon 2020-03-02  515  __func__, len, 
unilen, MAX_NAME_LENGTH);
370e812b3ec190 Namjae Jeon 2020-03-02  516  return -ENAMETOOLONG;
370e812b3ec190 Namjae Jeon 2020-03-02  517  }
370e812b3ec190 Namjae Jeon 2020-03-02  518  
370e812b3ec190 Namjae Jeon 2020-03-02  519  p_uniname->name_len = unilen & 
0xFF;
370e812b3ec190 Namjae Jeon 2020-03-02  520  
370e812b3ec190 Namjae Jeon 2020-03-02  521  for (i = 0; i < unilen; i++) {
370e812b3ec190 Namjae Jeon 2020-03-02  522  if (*uniname < 0x0020 ||
370e812b3ec190 Namjae Jeon 2020-03-02  523  
exfat_wstrchr(bad_uni_chars, *uniname))
370e812b3ec190 Namjae Jeon 2020-03-02  524  lossy |= 
NLS_NAME_LOSSY;
370e812b3ec190 Namjae Jeon 2020-03-02  525  
370e812b3ec190 Namjae Jeon 2020-03-02  526  upname[i] = 
exfat_toupper(sb, *uniname);
370e812b3ec190 Namjae Jeon 2020-03-02  527  uniname++;
370e812b3ec190 Namjae Jeon 2020-03-02  528  }
370e812b3ec190 Namjae Jeon 2020-03-02  529  
370e812b3ec190 Namjae Jeon 2020-03-02  530  *uniname = '\0';
370e812b3ec190 Namjae Jeon 2020-03-02 @531  p_uniname->name_len = unilen;
370e812b3ec190 Namjae Jeon 2020-03-02  532  p_uniname->name_hash = 
exfat_calc_chksum_2byte(upname, unilen << 1, 0,
370e812b3ec190 Namjae Jeon 2020-03-02  533  CS_DEFAULT);
370e812b3ec190 Namjae Jeon 2020-03-02  534  
370e812b3ec190 Namjae Jeon 2020-03-02  535  if (p_lossy)
370e812b3ec190 Namjae Jeon 2020-03-02  536  *p_lossy = lossy;
370e812b3ec190 Namjae Jeon 2020-03-02  537  return unilen;
370e812b3ec190 Namjae Jeon 2020-03-02  538  }
370e812b3ec190 Namjae Jeon 2020-03-02  539  

:: The code at line 531 was first introduced by commit
:: 370e812b3ec190fa492c9fd5a80c38b086d105c0 exfat: add nls operations

:: TO: Namjae Jeon 
:: CC: Al Viro 

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


[GIT] Networking

2020-05-30 Thread David Miller


Another week, another set of bug fixes:

1) Fix pskb_pull length in __xfrm_transport_prep(), from Xin Long.

2) Fix double xfrm_state put in esp{4,6}_gro_receive(), also from Xin
   Long.

3) Re-arm discovery timer properly in mac80211 mesh code, from Linus
   Lüssing.

4) Prevent buffer overflows in nf_conntrack_pptp debug code, from Pablo
   Neira Ayuso.

5) Fix race in ktls code between tls_sw_recvmsg() and
   tls_decrypt_done(), from Vinay Kumar Yadav.

6) Fix crashes on TCP fallback in MPTCP code, from Paolo Abeni.

7) More validation is necessary of untrusted GSO packets coming from
   virtualization devices, from Willem de Bruijn.

8) Fix endianness of bnxt_en firmware message length accesses, from
   Edwin Peer.

9) Fix infinite loop in sch_fq_pie, from Davide Caratti.

10) Fix lockdep splat in DSA by setting lockless TX in netdev features
for slave ports, from Vladimir Oltean.

11) Fix suspend/resume crashes in mlx5, from Mark Bloch.

12) Fix use after free in bpf fmod_ret, from Alexei Starovoitov.

13) ARP retransmit timer guard uses wrong offset, from Hongbin Liu.

14) Fix leak in inetdev_init(), from Yang Yingliang.

15) Don't try to use inet hash and unhash in l2tp code, results in
crashes.  From Eric Dumazet.

Please pull, thanks a lot!

The following changes since commit 98790bbac4db1697212ce9462ec35ca09c4a2810:

  Merge tag 'efi-urgent-2020-05-24' of 
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip (2020-05-24 10:24:10 
-0700)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git 

for you to fetch changes up to d9a81a225277686eb629938986d97629ea102633:

  l2tp: add sk_family checks to l2tp_validate_socket (2020-05-30 21:56:55 -0700)


Alexei Starovoitov (1):
  bpf: Fix use-after-free in fmod_ret check

Antony Antony (1):
  xfrm: fix error in comment

Arnd Bergmann (1):
  bridge: multicast: work around clang bug

Aya Levin (1):
  net/mlx5e: Fix arch depending casting issue in FEC

Björn Töpel (1):
  xsk: Add overflow check for u64 division, stored into u32

Chris Lew (1):
  net: qrtr: Allocate workqueue before kernel_bind

Chris Packham (1):
  net: sctp: Fix spelling in Kconfig help

Chuhong Yuan (1):
  NFC: st21nfca: add missed kfree_skb() in an error path

Daniele Palmas (1):
  net: usb: qmi_wwan: add Telit LE910C1-EUX composition

David Ahern (4):
  nexthops: Move code from remove_nexthop_from_groups to remove_nh_grp_entry
  nexthop: Expand nexthop_is_multipath in a few places
  ipv4: Refactor nhc evaluation in fib_table_lookup
  ipv4: nexthop version of fib_info_nh_uses_dev

David S. Miller (9):
  Merge tag 'mac80211-for-net-2020-05-25' of 
git://git.kernel.org/.../jberg/mac80211
  Merge git://git.kernel.org/.../pablo/nf
  Merge branch 'nexthop-group-fixes'
  Merge branch 'bnxt_en-Bug-fixes'
  Merge git://git.kernel.org/.../pablo/nf
  Merge branch 'master' of git://git.kernel.org/.../klassert/ipsec
  Merge git://git.kernel.org/.../bpf/bpf
  Merge tag 'mlx5-fixes-2020-05-28' of git://git.kernel.org/.../saeed/linux
  Merge branch 'mptcp-a-bunch-of-fixes'

Davide Caratti (1):
  net/sched: fix infinite loop in sch_fq_pie

Edwin Peer (1):
  bnxt_en: fix firmware message length endianness

Eric Dumazet (4):
  crypto: chelsio/chtls: properly set tp->lsndtime
  net: be more gentle about silly gso requests coming from user
  l2tp: do not use inet_hash()/inet_unhash()
  l2tp: add sk_family checks to l2tp_validate_socket

Fugang Duan (1):
  net: stmmac: enable timestamp snapshot for required PTP packets in dwmac 
v5.10a

Hangbin Liu (1):
  neigh: fix ARP retransmit timer guard

Heinrich Kuhn (1):
  nfp: flower: fix used time of merge flow statistics

Jia He (1):
  virtio_vsock: Fix race condition in virtio_transport_recv_pkt

Johannes Berg (1):
  cfg80211: fix debugfs rename crash

John Fastabend (3):
  bpf: Fix a verifier issue when assigning 32bit reg states to 64bit ones
  bpf, selftests: Verifier bounds tests need to be updated
  bpf, selftests: Add a verifier test for assigning 32bit reg states to 
64bit ones

Jonas Falkevik (1):
  sctp: check assoc before SCTP_ADDR_{MADE_PRIM, ADDED} event

Linus Lüssing (1):
  mac80211: mesh: fix discovery timer re-arming issue / crash

Maor Dickman (1):
  net/mlx5e: Remove warning "devices are not on same switch HW"

Mark Bloch (1):
  net/mlx5: Fix crash upon suspend/resume

Michael Braun (1):
  netfilter: nft_reject_bridge: enable reject with bridge vlan

Michael Chan (1):
  bnxt_en: Fix accumulation of bp->net_stats_prev.

Nathan Chancellor (1):
  netfilter: conntrack: Pass value of ctinfo to __nf_conntrack_update

Nicolas Dichtel (1):
  xfrm interface: fix oops when deleting a x-netns interface

Nikolay Aleksandrov (1):
  nexthops: don't modify 

Re: [PATCH RFT] ravb: Mask PHY mode to avoid inserting delays twice

2020-05-30 Thread David Miller
From: Geert Uytterhoeven 
Date: Fri, 29 May 2020 14:25:40 +0200

> Until recently, the Micrel KSZ9031 PHY driver ignored any PHY mode
> ("RGMII-*ID") settings, but used the hardware defaults, augmented by
> explicit configuration of individual skew values using the "*-skew-ps"
> DT properties.  The lack of PHY mode support was compensated by the
> EtherAVB MAC driver, which configures TX and/or RX internal delay
> itself, based on the PHY mode.
> 
> However, now the KSZ9031 driver has gained PHY mode support, delays may
> be configured twice, causing regressions.  E.g. on the Renesas
> Salvator-X board with R-Car M3-W ES1.0, TX performance dropped from ca.
> 400 Mbps to 0.1-0.3 Mbps, as measured by nuttcp.
> 
> As internal delay configuration supported by the KSZ9031 PHY is too
> limited for some use cases, the ability to configure MAC internal delay
> is deemed useful and necessary.  Hence a proper fix would involve
> splitting internal delay configuration in two parts, one for the PHY,
> and one for the MAC.  However, this would require adding new DT
> properties, thus breaking DTB backwards-compatibility.
> 
> Hence fix the regression in a backwards-compatibility way, by letting
> the EtherAVB driver mask the PHY mode when it has inserted a delay, to
> avoid the PHY driver adding a second delay.  This also fixes messages
> like:
> 
> Micrel KSZ9031 Gigabit PHY e680.ethernet-:00: *-skew-ps 
> values should be used only with phy-mode = "rgmii"
> 
> as the PHY no longer sees the original RGMII-*ID mode.
> 
> Solving the issue by splitting configuration in two parts can be handled
> in future patches, and would require retaining a backwards-compatibility
> mode anyway.
> 
> Fixes: bcf3440c6dd78bfe ("net: phy: micrel: add phy-mode support for the 
> KSZ9031 PHY")
> Signed-off-by: Geert Uytterhoeven 

Applied to net-next, thank you.


Re: [PATCH] net: qrtr: Allocate workqueue before kernel_bind

2020-05-30 Thread David Miller
From: Chris Lew 
Date: Thu, 28 May 2020 16:05:26 -0700

> A null pointer dereference in qrtr_ns_data_ready() is seen if a client
> opens a qrtr socket before qrtr_ns_init() can bind to the control port.
> When the control port is bound, the ENETRESET error will be broadcasted
> and clients will close their sockets. This results in DEL_CLIENT
> packets being sent to the ns and qrtr_ns_data_ready() being called
> without the workqueue being allocated.
> 
> Allocate the workqueue before setting sk_data_ready and binding to the
> control port. This ensures that the work and workqueue structs are
> allocated and initialized before qrtr_ns_data_ready can be called.
> 
> Fixes: 0c2204a4ad71 ("net: qrtr: Migrate nameservice to kernel from 
> userspace")
> Signed-off-by: Chris Lew 

Applied, thank you.


Stable backport request for linux-4.4.y

2020-05-30 Thread chenxb_99091
From: Xuebing Chen 

In linux-4.4.y,the  provides drm_for_each_plane_mask 
macro 
and plane_mask is defined as bitmask of plane indices, such as
1 << drm_plane_index(plane). There is an error setting of plane_mask
in pan_display_atomic() function.

Please backport the following patch to the 4.4.y kernel stable tree:
commit 7118fd9bd975a9f3093239d4c0f4e15356b57fab 
("drm/fb-helper: Use proper plane mask for fb cleanup")
The above patch fixes error setting of plane_mask in pan_display_atomic() 
function.

Cc: sta...@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Xuebing Chen 











Re: [GIT PULL] sh: remove sh5 support

2020-05-30 Thread Rob Landley
On 5/30/20 3:08 AM, John Paul Adrian Glaubitz wrote:
> On 5/29/20 7:53 PM, Rich Felker wrote:
>> Frustratingly, I _still_ don't have an official tree on kernel.org for
>> the purpose of being the canonical place for linux-next to pull from,
>> due to policies around pgp keys and nobody following up on signing
>> mine. This is all really silly since there are ridiculously many
>> independent channels I could cryptographically validate identity
>> through with vanishing probability that they're all compromised. For
>> the time being I'll reactivate my repo on git.musl-libc.org.
> 
> May I suggest to pick up these patches, for example? There might be
> more I missed, but getting these merged should already help a lot with
> the clean-up of arch/sh.

Does that include the 2 fixes to build with current binutils I made puppy eyes
about last -rc7 (in march)?

https://marc.info/?l=linux-sh=158544749818664=2

Rob


[PATCH] [v2] i2c: imx-lpi2c: Fix runtime PM imbalance on error

2020-05-30 Thread Dinghao Liu
pm_runtime_get_sync() increments the runtime PM usage counter even
the call returns an error code. Thus a pairing decrement is needed
on the error handling path to keep the counter balanced.

Signed-off-by: Dinghao Liu 
---
Changelog:

v2: - Use pm_runtime_put_noidle() instead of
  pm_runtime_put_autosuspend().
---
 drivers/i2c/busses/i2c-imx-lpi2c.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c 
b/drivers/i2c/busses/i2c-imx-lpi2c.c
index 94743ba581fe..bdee02dff284 100644
--- a/drivers/i2c/busses/i2c-imx-lpi2c.c
+++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
@@ -260,8 +260,10 @@ static int lpi2c_imx_master_enable(struct lpi2c_imx_struct 
*lpi2c_imx)
int ret;
 
ret = pm_runtime_get_sync(lpi2c_imx->adapter.dev.parent);
-   if (ret < 0)
+   if (ret < 0) {
+   pm_runtime_put_noidle(lpi2c_imx->adapter.dev.parent);
return ret;
+   }
 
temp = MCR_RST;
writel(temp, lpi2c_imx->base + LPI2C_MCR);
-- 
2.17.1



sound/soc/meson/t9015.c:315:34: warning: unused variable 't9015_ids'

2020-05-30 Thread kbuild test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   ffeb595d84811dde16a28b33d8a7cf26d51d51b3
commit: 33901f5b9b16d212ee58865e9e8e80fc813f12da ASoC: meson: add t9015 
internal DAC driver
date:   3 months ago
config: x86_64-randconfig-r033-20200531 (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 
2388a096e7865c043e83ece4e26654bd3d1a20d5)
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
git checkout 33901f5b9b16d212ee58865e9e8e80fc813f12da
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot 

All warnings (new ones prefixed by >>, old ones prefixed by <<):

>> sound/soc/meson/t9015.c:315:34: warning: unused variable 't9015_ids' 
>> [-Wunused-const-variable]
static const struct of_device_id t9015_ids[] = {
^
1 warning generated.

vim +/t9015_ids +315 sound/soc/meson/t9015.c

   314  
 > 315  static const struct of_device_id t9015_ids[] = {
   316  { .compatible = "amlogic,t9015", },
   317  { }
   318  };
   319  MODULE_DEVICE_TABLE(of, t9015_ids);
   320  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


.config.gz
Description: application/gzip


Re: [PATCH] irqchip/gic-v3-its: Don't try to move a disabled irq

2020-05-30 Thread kbuild test robot
Hi Ali,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on linux/master v5.7-rc7]
[cannot apply to tip/irq/core arm-jcooper/irqchip/for-next next-20200529]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:
https://github.com/0day-ci/linux/commits/Ali-Saidi/irqchip-gic-v3-its-Don-t-try-to-move-a-disabled-irq/20200531-043957
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
86852175b016f0c6873dcbc24b93d12b7b246612
config: arm64-allyesconfig (attached as .config)
compiler: aarch64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross 
ARCH=arm64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot 

All warnings (new ones prefixed by >>, old ones prefixed by <<):

drivers/irqchip/irq-gic-v3-its.c: In function 'its_irq_domain_activate':
>> drivers/irqchip/irq-gic-v3-its.c:3449:14: warning: passing argument 1 of 
>> 'cpumask_and' discards 'const' qualifier from pointer target type 
>> [-Wdiscarded-qualifiers]
3449 |  cpumask_and(cpu_mask, cpu_mask, cpu_online_mask);
|  ^~~~
In file included from include/linux/rcupdate.h:31,
from include/linux/radix-tree.h:15,
from include/linux/idr.h:15,
from include/linux/kernfs.h:13,
from include/linux/sysfs.h:16,
from include/linux/kobject.h:20,
from include/linux/of.h:17,
from include/linux/irqdomain.h:35,
from include/linux/acpi.h:13,
from drivers/irqchip/irq-gic-v3-its.c:7:
include/linux/cpumask.h:424:47: note: expected 'struct cpumask *' but argument 
is of type 'const struct cpumask *'
424 | static inline int cpumask_and(struct cpumask *dstp,
|   ^~~~
In file included from include/linux/bits.h:23,
from include/linux/ioport.h:15,
from include/linux/acpi.h:12,
from drivers/irqchip/irq-gic-v3-its.c:7:
drivers/irqchip/irq-gic-v3-its.c: In function 'its_init_vpe_domain':
include/linux/bits.h:26:28: warning: comparison of unsigned expression < 0 is 
always false [-Wtype-limits]
26 |   __builtin_constant_p((l) > (h)), (l) > (h), 0)))
|^
include/linux/build_bug.h:16:62: note: in definition of macro 
'BUILD_BUG_ON_ZERO'
16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
|  ^
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK'
39 |  (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
|   ^~~
drivers/irqchip/irq-gic-v3-its.c:4765:10: note: in expansion of macro 'GENMASK'
4765 |  devid = GENMASK(device_ids(its) - 1, 0);
|  ^~~
include/linux/bits.h:26:40: warning: comparison of unsigned expression < 0 is 
always false [-Wtype-limits]
26 |   __builtin_constant_p((l) > (h)), (l) > (h), 0)))
|^
include/linux/build_bug.h:16:62: note: in definition of macro 
'BUILD_BUG_ON_ZERO'
16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
|  ^
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK'
39 |  (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
|   ^~~
drivers/irqchip/irq-gic-v3-its.c:4765:10: note: in expansion of macro 'GENMASK'
4765 |  devid = GENMASK(device_ids(its) - 1, 0);
|  ^~~

vim +3449 drivers/irqchip/irq-gic-v3-its.c

  3433  
  3434  static int its_irq_domain_activate(struct irq_domain *domain,
  3435 struct irq_data *d, bool reserve)
  3436  {
  3437  struct its_device *its_dev = irq_data_get_irq_chip_data(d);
  3438  u32 event = its_get_event_id(d);
  3439  const struct cpumask *cpu_mask = cpu_online_mask;
  3440  int cpu;
  3441  
  3442  /* get the cpu_mask of local node */
  3443  if (its_dev->its->numa_node >= 0)
  3444  cpu_mask = cpumask_of_node(its_dev->its->numa_node);
  3445  
  3446  /* If the cpu set to a different CPU that is still online use 
it */
  3447  cpu = its_dev->event_map.col_map[event];
  3448  
> 3449  cpumask_and(cpu_mask, cpu_mask, cpu_online_mask);
  3450  
  3451  if (!cpumask_test_cpu(cpu, cpu_mask)) {
  3452  /* Bind the LPI to the first possible CPU */
  3453  cpu = cpumask_first(cpu_mask);
  3454  }
  3455  
  3456  if (cpu >= nr_cpu_ids) {
  3457  if 

Re: 答复: [PATCH][v5] KVM: X86: support APERF/MPERF registers

2020-05-30 Thread Xiaoyao Li

On 5/31/2020 10:08 AM, Li,Rongqing wrote:




-邮件原件-
发件人: Xiaoyao Li [mailto:xiaoyao...@intel.com]
发送时间: 2020年5月30日 18:40
收件人: Li,Rongqing ; linux-kernel@vger.kernel.org;
k...@vger.kernel.org; x...@kernel.org; h...@zytor.com; b...@alien8.de;
mi...@redhat.com; t...@linutronix.de; jmatt...@google.com;
wanpen...@tencent.com; vkuzn...@redhat.com;
sean.j.christopher...@intel.com; pbonz...@redhat.com;
wei.hua...@amd.com
主题: Re: [PATCH][v5] KVM: X86: support APERF/MPERF registers

On 5/30/2020 12:35 PM, Li RongQing wrote:

Guest kernel reports a fixed cpu frequency in /proc/cpuinfo, this is
confused to user when turbo is enable, and aperf/mperf can be used to
show current cpu frequency after 7d5905dc14a
"(x86 / CPU: Always show current CPU frequency in /proc/cpuinfo)"
so guest should support aperf/mperf capability

This patch implements aperf/mperf by three mode: none, software
emulation, and pass-through

None: default mode, guest does not support aperf/mperf

Software emulation: the period of aperf/mperf in guest mode are
accumulated as emulated value

Pass-though: it is only suitable for KVM_HINTS_REALTIME, Because that
hint guarantees we have a 1:1 vCPU:CPU binding and guaranteed no
over-commit.

And a per-VM capability is added to configure aperfmperf mode



[...]


diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index
cd708b0b460a..c960dda4251b 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -122,6 +122,14 @@ int kvm_update_cpuid(struct kvm_vcpu *vcpu)
   MSR_IA32_MISC_ENABLE_MWAIT);
}

+   best = kvm_find_cpuid_entry(vcpu, 6, 0);
+   if (best) {
+   if (guest_has_aperfmperf(vcpu->kvm) &&
+   boot_cpu_has(X86_FEATURE_APERFMPERF))
+   best->ecx |= 1;
+   else
+   best->ecx &= ~1;
+   }


In my understanding, KVM allows userspace to set a CPUID feature bit for
guest even if hardware doesn't support the feature.

So what makes X86_FEATURE_APERFMPERF different here? Is there any
concern I miss?

-Xiaoyao


Whether software emulation for aperf/mperf or pass-through depends on host cpu 
aperf/mperf feature.
  
Software emulation: the period of aperf/mperf in guest mode are accumulated as emulated value




I know it that you want to ensure the correctness of exposure of 
aperf/mperf.


But there are so many features other than aperf/mperf that KVM reports 
the supported settings of them through KVM_GET_SUPPORTED_CPUID, but 
doesn't check nor force the correctness of userspace input. i.e., KVM 
allows userspace to set bogus CPUID settings as long as it doesn't break 
KVM (host kernel).


Indeed, bogus CPUID settings more than likely breaks the guest. But it's 
not KVM's fault. KVM just do what userspace wants.


IMO, If we really want to ensure the correctness of userspace provided 
CPUID settings, we need to return ERROR to userspace instead of fixing 
it siliently.


- Xiaoyao


drivers/soundwire/intel_init.c:192:7: warning: no previous prototype for function 'sdw_intel_init'

2020-05-30 Thread kbuild test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   ffeb595d84811dde16a28b33d8a7cf26d51d51b3
commit: f98f690fb03c2a8d21dfa31aa1042480cf6f7f9b soundwire: intel: update 
interfaces between ASoC and SoundWire
date:   6 months ago
config: x86_64-randconfig-r033-20200531 (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 
2388a096e7865c043e83ece4e26654bd3d1a20d5)
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
git checkout f98f690fb03c2a8d21dfa31aa1042480cf6f7f9b
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot 

All warnings (new ones prefixed by >>, old ones prefixed by <<):

>> drivers/soundwire/intel_init.c:192:7: warning: no previous prototype for 
>> function 'sdw_intel_init' [-Wmissing-prototypes]
void *sdw_intel_init(acpi_handle *parent_handle, struct sdw_intel_res *res)
^
drivers/soundwire/intel_init.c:192:1: note: declare 'static' if the function is 
not intended to be used outside of this translation unit
void *sdw_intel_init(acpi_handle *parent_handle, struct sdw_intel_res *res)
^
static
1 warning generated.

vim +/sdw_intel_init +192 drivers/soundwire/intel_init.c

d62a7d41f38e1d Vinod Koul 2017-12-14  183  
d62a7d41f38e1d Vinod Koul 2017-12-14  184  /**
d62a7d41f38e1d Vinod Koul 2017-12-14  185   * sdw_intel_init() - SoundWire 
Intel init routine
d62a7d41f38e1d Vinod Koul 2017-12-14  186   * @parent_handle: ACPI parent handle
d62a7d41f38e1d Vinod Koul 2017-12-14  187   * @res: resource data
d62a7d41f38e1d Vinod Koul 2017-12-14  188   *
d62a7d41f38e1d Vinod Koul 2017-12-14  189   * This scans the namespace and 
creates SoundWire link controller devices
d62a7d41f38e1d Vinod Koul 2017-12-14  190   * based on the info queried.
d62a7d41f38e1d Vinod Koul 2017-12-14  191   */
d62a7d41f38e1d Vinod Koul 2017-12-14 @192  void *sdw_intel_init(acpi_handle 
*parent_handle, struct sdw_intel_res *res)
d62a7d41f38e1d Vinod Koul 2017-12-14  193  {
d62a7d41f38e1d Vinod Koul 2017-12-14  194   acpi_status status;
d62a7d41f38e1d Vinod Koul 2017-12-14  195  
d62a7d41f38e1d Vinod Koul 2017-12-14  196   status = 
acpi_walk_namespace(ACPI_TYPE_DEVICE,
d62a7d41f38e1d Vinod Koul 2017-12-14  197
parent_handle, 1,
d62a7d41f38e1d Vinod Koul 2017-12-14  198
sdw_intel_acpi_cb,
d62a7d41f38e1d Vinod Koul 2017-12-14  199
NULL, res, NULL);
d62a7d41f38e1d Vinod Koul 2017-12-14  200   if (ACPI_FAILURE(status))
d62a7d41f38e1d Vinod Koul 2017-12-14  201   return NULL;
d62a7d41f38e1d Vinod Koul 2017-12-14  202  
d62a7d41f38e1d Vinod Koul 2017-12-14  203   return 
sdw_intel_add_controller(res);
d62a7d41f38e1d Vinod Koul 2017-12-14  204  }
d62a7d41f38e1d Vinod Koul 2017-12-14  205  

:: The code at line 192 was first introduced by commit
:: d62a7d41f38e1d3f8f8a1c0db4dec7a5bb39268a soundwire: intel: Add Intel 
init module

:: TO: Vinod Koul 
:: CC: Greg Kroah-Hartman 

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


.config.gz
Description: application/gzip


答复: [PATCH][v5] KVM: X86: support APERF/MPERF registers

2020-05-30 Thread Li,Rongqing


> -邮件原件-
> 发件人: Xiaoyao Li [mailto:xiaoyao...@intel.com]
> 发送时间: 2020年5月30日 18:40
> 收件人: Li,Rongqing ; linux-kernel@vger.kernel.org;
> k...@vger.kernel.org; x...@kernel.org; h...@zytor.com; b...@alien8.de;
> mi...@redhat.com; t...@linutronix.de; jmatt...@google.com;
> wanpen...@tencent.com; vkuzn...@redhat.com;
> sean.j.christopher...@intel.com; pbonz...@redhat.com;
> wei.hua...@amd.com
> 主题: Re: [PATCH][v5] KVM: X86: support APERF/MPERF registers
> 
> On 5/30/2020 12:35 PM, Li RongQing wrote:
> > Guest kernel reports a fixed cpu frequency in /proc/cpuinfo, this is
> > confused to user when turbo is enable, and aperf/mperf can be used to
> > show current cpu frequency after 7d5905dc14a
> > "(x86 / CPU: Always show current CPU frequency in /proc/cpuinfo)"
> > so guest should support aperf/mperf capability
> >
> > This patch implements aperf/mperf by three mode: none, software
> > emulation, and pass-through
> >
> > None: default mode, guest does not support aperf/mperf
> >
> > Software emulation: the period of aperf/mperf in guest mode are
> > accumulated as emulated value
> >
> > Pass-though: it is only suitable for KVM_HINTS_REALTIME, Because that
> > hint guarantees we have a 1:1 vCPU:CPU binding and guaranteed no
> > over-commit.
> >
> > And a per-VM capability is added to configure aperfmperf mode
> >
> 
> [...]
> 
> > diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index
> > cd708b0b460a..c960dda4251b 100644
> > --- a/arch/x86/kvm/cpuid.c
> > +++ b/arch/x86/kvm/cpuid.c
> > @@ -122,6 +122,14 @@ int kvm_update_cpuid(struct kvm_vcpu *vcpu)
> >MSR_IA32_MISC_ENABLE_MWAIT);
> > }
> >
> > +   best = kvm_find_cpuid_entry(vcpu, 6, 0);
> > +   if (best) {
> > +   if (guest_has_aperfmperf(vcpu->kvm) &&
> > +   boot_cpu_has(X86_FEATURE_APERFMPERF))
> > +   best->ecx |= 1;
> > +   else
> > +   best->ecx &= ~1;
> > +   }
> 
> In my understanding, KVM allows userspace to set a CPUID feature bit for
> guest even if hardware doesn't support the feature.
> 
> So what makes X86_FEATURE_APERFMPERF different here? Is there any
> concern I miss?
> 
> -Xiaoyao

Whether software emulation for aperf/mperf or pass-through depends on host cpu 
aperf/mperf feature.
 
Software emulation: the period of aperf/mperf in guest mode are accumulated as 
emulated value

-Li


Re: [PATCHSET v5 0/12] Add support for async buffered reads

2020-05-30 Thread Jens Axboe
On 5/30/20 12:57 PM, Sedat Dilek wrote:
> Here are the numbers with your patchset:
> 
> # cat systemd-analyze-time_5.7.0-rc7-4-amd64-clang_2nd-try.txt
> Startup finished in 7.229s (kernel) + 1min 18.304s (userspace) = 1min 25.534s
> graphical.target reached after 1min 18.286s in userspace

Can you see if this makes a difference?

diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index c296463c15eb..ccb895f911b1 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -374,8 +374,7 @@ enum req_flag_bits {
 #define REQ_INTEGRITY  (1ULL << __REQ_INTEGRITY)
 #define REQ_FUA(1ULL << __REQ_FUA)
 #define REQ_PREFLUSH   (1ULL << __REQ_PREFLUSH)
-#define REQ_RAHEAD \
-   ((1ULL << __REQ_RAHEAD) | (1ULL << __REQ_NOWAIT))
+#define REQ_RAHEAD (1ULL << __REQ_RAHEAD)
 #define REQ_BACKGROUND (1ULL << __REQ_BACKGROUND)
 #define REQ_NOWAIT (1ULL << __REQ_NOWAIT)
 #define REQ_CGROUP_PUNT(1ULL << __REQ_CGROUP_PUNT)

-- 
Jens Axboe



Re: [RFC PATCH v4 05/13] riscv: Add new csr defines related to vector extension

2020-05-30 Thread Guo Ren
Hi Greentime,

Why remove vxrm and xstat ?

> Appendix B: Calling Convention
> In the RISC-V psABI, the vector registers v0-v31 are all caller-saved. The 
> vstart, vl, and vtype CSRs are also caller-saved.
> The vxrm and vxsat fields have thread storage duration.

As spec 0.9 mentioned above, vxrm and vxsat are thread storage duration.

When timer 's interrupt coming, we still need to save them in context_switch.

On Tue, May 26, 2020 at 3:03 PM Greentime Hu  wrote:
>
> From: Guo Ren 
>
> Follow the riscv vector spec to add new csr number.
>
> [greentime...@sifive.com: update the defined value based on new spec and
> remove unused ones]
> Signed-off-by: Greentime Hu 
> Signed-off-by: Guo Ren 
> ---
>  arch/riscv/include/asm/csr.h | 16 ++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h
> index 8e18d2c64399..cc13626c4bbe 100644
> --- a/arch/riscv/include/asm/csr.h
> +++ b/arch/riscv/include/asm/csr.h
> @@ -24,6 +24,12 @@
>  #define SR_FS_CLEAN_AC(0x4000, UL)
>  #define SR_FS_DIRTY_AC(0x6000, UL)
>
> +#define SR_VS   _AC(0x0600, UL) /* Vector Status */
> +#define SR_VS_OFF   _AC(0x, UL)
> +#define SR_VS_INITIAL   _AC(0x0200, UL)
> +#define SR_VS_CLEAN _AC(0x0400, UL)
> +#define SR_VS_DIRTY _AC(0x0600, UL)
> +
>  #define SR_XS  _AC(0x00018000, UL) /* Extension Status */
>  #define SR_XS_OFF  _AC(0x, UL)
>  #define SR_XS_INITIAL  _AC(0x8000, UL)
> @@ -31,9 +37,9 @@
>  #define SR_XS_DIRTY_AC(0x00018000, UL)
>
>  #ifndef CONFIG_64BIT
> -#define SR_SD  _AC(0x8000, UL) /* FS/XS dirty */
> +#define SR_SD  _AC(0x8000, UL) /* FS/VS/XS dirty */
>  #else
> -#define SR_SD  _AC(0x8000, UL) /* FS/XS dirty */
> +#define SR_SD  _AC(0x8000, UL) /* FS/VS/XS dirty */
>  #endif
>
>  /* SATP flags */
> @@ -114,6 +120,12 @@
>  #define CSR_PMPADDR0   0x3b0
>  #define CSR_MHARTID0xf14
>
> +#define CSR_VSTART 0x8
> +#define CSR_VCSR   0xf
> +#define CSR_VL 0xc20
> +#define CSR_VTYPE  0xc21
> +#define CSR_VLENB  0xc22
> +
>  #ifdef CONFIG_RISCV_M_MODE
>  # define CSR_STATUSCSR_MSTATUS
>  # define CSR_IECSR_MIE
> --
> 2.26.2
>
>


--
Best Regards
 Guo Ren

ML: https://lore.kernel.org/linux-csky/


Re: [PATCH] perf: Make perf able to build with latest libbfd

2020-05-30 Thread Marek Vasut
Hi,

since commit
0ada120c883d ("perf: Make perf able to build with latest libbfd")
is in master, can it be backported to stable as well? I keep hitting
this with too new binutils on Linux 5.4.y and I have to keep
cherry-picking this commit to fix it.

Thanks


[PATCH] drivers: usb: core: driver: fixed 80 line character length issue

2020-05-30 Thread Lokesh Chebrolu
From: lokeshch007 

Fixed a coding style issue

Signed-off-by: Lokesh Chebrolu 
---
 drivers/usb/core/driver.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index f81606c..83c3287 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -1796,7 +1796,9 @@ int usb_autopm_get_interface_async(struct usb_interface 
*intf)
 EXPORT_SYMBOL_GPL(usb_autopm_get_interface_async);
 
 /**
- * usb_autopm_get_interface_no_resume - increment a USB interface's PM-usage 
counter
+ * usb_autopm_get_interface_no_resume -
+ * increment a USB interface's PM-usage counter
+ *
  * @intf: the usb_interface whose counter should be incremented
  *
  * This routine increments @intf's usage counter but does not carry out an
-- 
2.7.4



Re: [PATCH v7 1/4] bitops: Introduce the the for_each_set_clump macro

2020-05-30 Thread Syed Nayyar Waris
On Sat, May 30, 2020 at 2:50 PM Andy Shevchenko
 wrote:
>
> On Sat, May 30, 2020 at 11:45 AM Syed Nayyar Waris  
> wrote:
> > On Sat, May 30, 2020 at 3:49 AM Andy Shevchenko
> >  wrote:
>
> ...
>
> > I am still investigating more on this. Let me know if you have any 
> > suggestions.
>
> As far as I understand the start pointers are implementations of abs()
> macro followed by min()/max().
> I think in the latter case it's actually something which might help here.
>
> Sorry, right now I have no time to dive deeper.

No Problem. Thank you for sharing your initial pointers.

By the way, as I was working on it I found a way to avoid comparison
with '0' in '__builtin_constant_p'. And because of this, no
compilation warnings are getting produced.

Change the following:

#define GENMASK_INPUT_CHECK(h, l) \
(BUILD_BUG_ON_ZERO(__builtin_choose_expr( \
__builtin_constant_p((l) > (h)), (l) > (h), 0)))


To this:

#if (l) == 0
#define GENMASK_INPUT_CHECK(h, l)  0
#elif
#define GENMASK_INPUT_CHECK(h, l) \
(BUILD_BUG_ON_ZERO(__builtin_choose_expr( \
__builtin_constant_p((l) > (h)), (l) > (h), 0)))
#endif

I have verified that this works. Basically this just avoids the sanity
check when the 'lower' bound 'l' is zero. Let me know if it looks
fine.

Regarding min, max macro that you suggested I am also looking further into it.

Regards
Syed Nayyar Waris


[git pull] a couple of sparc ptrace fixes

2020-05-30 Thread Al Viro
The following changes since commit 8f3d9f354286745c751374f5f1fcafee6b3f3136:

  Linux 5.7-rc1 (2020-04-12 12:35:55 -0700)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git for-davem

for you to fetch changes up to cf51e129b96847f969bfb8af1ee1516a01a70b39:

  sparc32: fix register window handling in genregs32_[gs]et() (2020-05-20 
13:29:37 -0400)


Al Viro (2):
  sparc64: fix misuses of access_process_vm() in genregs32_[sg]et()
  sparc32: fix register window handling in genregs32_[gs]et()

 arch/sparc/kernel/ptrace_32.c | 228 ++
 arch/sparc/kernel/ptrace_64.c |  17 +---
 2 files changed, 101 insertions(+), 144 deletions(-)


Re: [PATCH RFC] seccomp: Implement syscall isolation based on memory areas

2020-05-30 Thread Andy Lutomirski



> On May 30, 2020, at 5:26 PM, Gabriel Krisman Bertazi  
> wrote:
> 
> Andy Lutomirski  writes:
> 
 On May 29, 2020, at 11:00 PM, Gabriel Krisman Bertazi 
  wrote:
>>> 
>>> Modern Windows applications are executing system call instructions
>>> directly from the application's code without going through the WinAPI.
>>> This breaks Wine emulation, because it doesn't have a chance to
>>> intercept and emulate these syscalls before they are submitted to Linux.
>>> 
>>> In addition, we cannot simply trap every system call of the application
>>> to userspace using PTRACE_SYSEMU, because performance would suffer,
>>> since our main use case is to run Windows games over Linux.  Therefore,
>>> we need some in-kernel filtering to decide whether the syscall was
>>> issued by the wine code or by the windows application.
>> 
>> Do you really need in-kernel filtering?  What if you could have
>> efficient userspace filtering instead?  That is, set something up so
>> that all syscalls, except those from a special address, are translated
>> to CALL thunk where the thunk is configured per task.  Then the thunk
>> can do whatever emulation is needed.
> 
> Hi,
> 
> I suggested something similar to my customer, by using
> libsyscall-intercept.  The idea would be overwritting the syscall
> instruction with a call to the entry point.  I'm not a specialist on the
> specifics of Windows games, (cc'ed Paul Gofman, who can provide more
> details on that side), but as far as I understand, the reason why that
> is not feasible is that the anti-cheat protection in games will abort
> execution if the binary region was modified either on-disk or in-memory.
> 
> Is there some mechanism to do that without modiyfing the application?

I’m suggesting that the kernel learn how to help you, maybe like this:

prctl(PR_SET_SYSCALL_THUNK, target, address_of_unredirected_syscall, 0, 0, 0, 
0);

This would be inherited on clone/fork and cleared on execve.

> 
>> Getting the details and especially the interaction with any seccomp
>> filters that may be installed right could be tricky, but the performance
>> should be decent, at least on non-PTI systems.
>> 
>> (If we go this route, I suspect that the correct interaction with
>> seccomp is that this type of redirection takes precedence over seccomp
>> and seccomp filters are not invoked for redirected syscalls. After all,
>> a redirected syscall is, functionally, not a syscall at all.)
>> 
> 
> 
> -- 
> Gabriel Krisman Bertazi


Re: [RFC PATCH v4 07/13] riscv: Add has_vector/riscv_vsize to save vector features.

2020-05-30 Thread Guo Ren
Reviewed-by: Guo Ren 

On Tue, May 26, 2020 at 3:03 PM Greentime Hu  wrote:
>
> From: Guo Ren 
>
> This patch is used to detect vector support status of CPU and use
> riscv_vsize to save the size of all the vector registers. It assumes
> all harts has the same capabilities in SMP system.
>
> [greentime...@sifive.com: add support for dynamic vlen]
> Signed-off-by: Greentime Hu 
> Signed-off-by: Guo Ren 
> ---
>  arch/riscv/kernel/cpufeature.c | 11 +++
>  1 file changed, 11 insertions(+)
>
> diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c
> index c8527d770c98..5a68a926da68 100644
> --- a/arch/riscv/kernel/cpufeature.c
> +++ b/arch/riscv/kernel/cpufeature.c
> @@ -16,6 +16,10 @@ unsigned long elf_hwcap __read_mostly;
>  #ifdef CONFIG_FPU
>  bool has_fpu __read_mostly;
>  #endif
> +#ifdef CONFIG_VECTOR
> +bool has_vector __read_mostly;
> +unsigned long riscv_vsize __read_mostly;
> +#endif
>
>  void riscv_fill_hwcap(void)
>  {
> @@ -73,4 +77,11 @@ void riscv_fill_hwcap(void)
> if (elf_hwcap & (COMPAT_HWCAP_ISA_F | COMPAT_HWCAP_ISA_D))
> has_fpu = true;
>  #endif
> +
> +#ifdef CONFIG_VECTOR
> +   if (elf_hwcap & COMPAT_HWCAP_ISA_V) {
> +   has_vector = true;
> +   riscv_vsize = csr_read(CSR_VLENB) * 32;
No magic number 32.
eg:
#define VECTOR_REGS_NUM 32

-- 
Best Regards
 Guo Ren

ML: https://lore.kernel.org/linux-csky/


Re: [PATCH net-next v3] hinic: add set_channels ethtool_ops support

2020-05-30 Thread David Miller
From: Luo bin 
Date: Fri, 29 May 2020 18:11:50 +

> add support to change TX/RX queue number with ethtool -L ethx combined
> 
> Signed-off-by: Luo bin 

Luo, I am not applying any of your patches until you fix the time on
your computer.

This causes a lot of issues and slows down my workflow because it
causes your patch submissions to be placed deep in my patchwork
backlog because patchwork entries is ordered by date.

Therefore, please fix the date on your computer and resubmit your
changes.

Thank you.


Re: [PATCH v3] virtio_vsock: Fix race condition in virtio_transport_recv_pkt

2020-05-30 Thread David Miller
From: Jia He 
Date: Sat, 30 May 2020 09:38:28 +0800

> When client on the host tries to connect(SOCK_STREAM, O_NONBLOCK) to the
> server on the guest, there will be a panic on a ThunderX2 (armv8a server):
 ...
> The race condition is as follows:
> Task1Task2
> ==
> __sock_release   virtio_transport_recv_pkt
>   __vsock_release  vsock_find_bound_socket (found sk)
> lock_sock_nested
> vsock_remove_sock
> sock_orphan
>   sk_set_socket(sk, NULL)
> sk->sk_shutdown = SHUTDOWN_MASK
> ...
> release_sock
> lock_sock
>virtio_transport_recv_connecting
>  sk->sk_socket->state (panic!)
> 
> The root cause is that vsock_find_bound_socket can't hold the lock_sock,
> so there is a small race window between vsock_find_bound_socket() and
> lock_sock(). If __vsock_release() is running in another task,
> sk->sk_socket will be set to NULL inadvertently.
> 
> This fixes it by checking sk->sk_shutdown(suggested by Stefano) after
> lock_sock since sk->sk_shutdown is set to SHUTDOWN_MASK under the
> protection of lock_sock_nested.
> 
> Signed-off-by: Jia He 
> Reviewed-by: Stefano Garzarella 

Applied and queued up for -stable, thank you.


Re: [PATCH net-next 0/6] net: hns3: adds some cleanups for -next

2020-05-30 Thread David Miller
From: Huazhong Tan 
Date: Sat, 30 May 2020 09:08:26 +0800

> There are some cleanups for the HNS3 ethernet driver, fix an
> incorrect print format, an incorrect comment and some coding
> style issues, also remove some unused codes and macros.

Series applied, thanks.


Re: [PATCH RFC] seccomp: Implement syscall isolation based on memory areas

2020-05-30 Thread Gabriel Krisman Bertazi
Andy Lutomirski  writes:

>> On May 29, 2020, at 11:00 PM, Gabriel Krisman Bertazi 
>>  wrote:
>> 
>> Modern Windows applications are executing system call instructions
>> directly from the application's code without going through the WinAPI.
>> This breaks Wine emulation, because it doesn't have a chance to
>> intercept and emulate these syscalls before they are submitted to Linux.
>> 
>> In addition, we cannot simply trap every system call of the application
>> to userspace using PTRACE_SYSEMU, because performance would suffer,
>> since our main use case is to run Windows games over Linux.  Therefore,
>> we need some in-kernel filtering to decide whether the syscall was
>> issued by the wine code or by the windows application.
>
> Do you really need in-kernel filtering?  What if you could have
> efficient userspace filtering instead?  That is, set something up so
> that all syscalls, except those from a special address, are translated
> to CALL thunk where the thunk is configured per task.  Then the thunk
> can do whatever emulation is needed.

Hi,

I suggested something similar to my customer, by using
libsyscall-intercept.  The idea would be overwritting the syscall
instruction with a call to the entry point.  I'm not a specialist on the
specifics of Windows games, (cc'ed Paul Gofman, who can provide more
details on that side), but as far as I understand, the reason why that
is not feasible is that the anti-cheat protection in games will abort
execution if the binary region was modified either on-disk or in-memory.

Is there some mechanism to do that without modiyfing the application?

> Getting the details and especially the interaction with any seccomp
> filters that may be installed right could be tricky, but the performance
> should be decent, at least on non-PTI systems.
>
> (If we go this route, I suspect that the correct interaction with
> seccomp is that this type of redirection takes precedence over seccomp
> and seccomp filters are not invoked for redirected syscalls. After all,
> a redirected syscall is, functionally, not a syscall at all.)
>


-- 
Gabriel Krisman Bertazi


Re: [PATCH stable-4.19.y] net: phy: reschedule state machine if AN has not completed in PHY_AN state

2020-05-30 Thread Russell King - ARM Linux admin
On Sun, May 31, 2020 at 12:43:15AM +0300, Vladimir Oltean wrote:
> From: Vladimir Oltean 
> 
> In kernel 4.19 (and probably earlier too) there are issues surrounding
> the PHY_AN state.
> 
> For example, if a PHY is in PHY_AN state and AN has not finished, then
> what is supposed to happen is that the state machine gets rescheduled
> until it is, or until the link_timeout reaches zero which triggers an
> autoneg restart process.
> 
> But actually the rescheduling never works if the PHY uses interrupts,
> because the condition under which rescheduling occurs is just if
> phy_polling_mode() is true. So basically, this whole rescheduling
> functionality works for AN-not-yet-complete just by mistake. Let me
> explain.
> 
> Most of the time the AN process manages to finish by the time the
> interrupt has triggered. One might say "that should always be the case,
> otherwise the PHY wouldn't raise the interrupt, right?".
> Well, some PHYs implement an .aneg_done method which allows them to tell
> the state machine when the AN is really complete.
> The AR8031/AR8033 driver (at803x.c) is one such example. Even when
> copper autoneg completes, the driver still keeps the "aneg_done"
> variable unset until in-band SGMII autoneg finishes too (there is no
> interrupt for that). So we have the premises of a race condition.

Why do we care whether SGMII autoneg has completed - is that not the
domain of the MAC side of the link?

It sounds like things are a little confused.  The PHY interrupt is
signalling that the copper side has completed its autoneg.  If we're
in SGMII mode, the PHY can now start the process of informing the
MAC about the negotiation results across the SGMII link.  When the
MAC receives those results, and sends the acknowledgement back to the
PHY, is it not the responsibility of the MAC to then say "the link is
now up" ?

That's how we deal with it elsewhere with phylink integration, which
is what has to be done when you have to cope with PHYs that switch
their host interface mode between SGMII, 2500BASE-X, 5GBASE-R and
10GBASE-R - the MAC side needs to be dynamically reconfigured depending
on the new host-side operating mode of the PHY.  Only when the MAC
subsequently reports that the link has been established is the whole
link from the MAC to the media deemed to be operational.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC for 0.8m (est. 1762m) line in suburbia: sync at 13.1Mbps down 424kbps up


Re: [RFC PATCH v5 2/6] interconnect: Add generic interconnect driver for Exynos SoCs

2020-05-30 Thread Chanwoo Choi
Hi Sylwester,

On Sat, May 30, 2020 at 1:34 AM Sylwester Nawrocki
 wrote:
>
> This patch adds a generic interconnect driver for Exynos SoCs in order
> to provide interconnect functionality for each "samsung,exynos-bus"
> compatible device.
>
> The SoC topology is a graph (or more specifically, a tree) and its
> edges are specified using the 'samsung,interconnect-parent' in the
> DT. Due to unspecified relative probing order, -EPROBE_DEFER may be
> propagated to ensure that the parent is probed before its children.
>
> Each bus is now an interconnect provider and an interconnect node as
> well (cf. Documentation/interconnect/interconnect.rst), i.e. every bus
> registers itself as a node. Node IDs are not hardcoded but rather
> assigned dynamically at runtime. This approach allows for using this
> driver with various Exynos SoCs.
>
> Frequencies requested via the interconnect API for a given node are
> propagated to devfreq using dev_pm_qos_update_request(). Please note
> that it is not an error when CONFIG_INTERCONNECT is 'n', in which
> case all interconnect API functions are no-op.
>
> Signed-off-by: Artur Świgoń 
> Signed-off-by: Sylwester Nawrocki 
>
> Changes for v5:
>  - adjust to renamed exynos,interconnect-parent-node property,
>  - use automatically generated platform device id as the interconect
>node id instead of a now unavailable devfreq->id field,
>  - add icc_ prefix to some variables to make the code more self-commenting,
>  - use icc_nodes_remove() instead of icc_node_del() + icc_node_destroy(),
>  - adjust to exynos,interconnect-parent-node property rename to
>samsung,interconnect-parent,
>  - converted to a separate platform driver in drivers/interconnect.
> ---
>  drivers/interconnect/Kconfig |   1 +
>  drivers/interconnect/Makefile|   1 +
>  drivers/interconnect/exynos/Kconfig  |   6 ++
>  drivers/interconnect/exynos/Makefile |   4 +
>  drivers/interconnect/exynos/exynos.c | 185 
> +++
>  5 files changed, 197 insertions(+)
>  create mode 100644 drivers/interconnect/exynos/Kconfig
>  create mode 100644 drivers/interconnect/exynos/Makefile
>  create mode 100644 drivers/interconnect/exynos/exynos.c
>
> diff --git a/drivers/interconnect/Kconfig b/drivers/interconnect/Kconfig
> index 5b7204e..eca6eda 100644
> --- a/drivers/interconnect/Kconfig
> +++ b/drivers/interconnect/Kconfig
> @@ -11,6 +11,7 @@ menuconfig INTERCONNECT
>
>  if INTERCONNECT
>
> +source "drivers/interconnect/exynos/Kconfig"
>  source "drivers/interconnect/imx/Kconfig"
>  source "drivers/interconnect/qcom/Kconfig"
>
> diff --git a/drivers/interconnect/Makefile b/drivers/interconnect/Makefile
> index 4825c28..2ba1de6 100644
> --- a/drivers/interconnect/Makefile
> +++ b/drivers/interconnect/Makefile
> @@ -4,5 +4,6 @@ CFLAGS_core.o   := -I$(src)
>  icc-core-objs  := core.o
>
>  obj-$(CONFIG_INTERCONNECT) += icc-core.o
> +obj-$(CONFIG_INTERCONNECT_EXYNOS)  += exynos/
>  obj-$(CONFIG_INTERCONNECT_IMX) += imx/
>  obj-$(CONFIG_INTERCONNECT_QCOM)+= qcom/
> diff --git a/drivers/interconnect/exynos/Kconfig 
> b/drivers/interconnect/exynos/Kconfig
> new file mode 100644
> index 000..e51e52e
> --- /dev/null
> +++ b/drivers/interconnect/exynos/Kconfig
> @@ -0,0 +1,6 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +config INTERCONNECT_EXYNOS
> +   tristate "Exynos generic interconnect driver"
> +   depends on ARCH_EXYNOS || COMPILE_TEST
> +   help
> + Generic interconnect driver for Exynos SoCs.
> diff --git a/drivers/interconnect/exynos/Makefile 
> b/drivers/interconnect/exynos/Makefile
> new file mode 100644
> index 000..e19d1df
> --- /dev/null
> +++ b/drivers/interconnect/exynos/Makefile
> @@ -0,0 +1,4 @@
> +# SPDX-License-Identifier: GPL-2.0
> +exynos-interconnect-objs   := exynos.o
> +
> +obj-$(CONFIG_INTERCONNECT_EXYNOS)  += exynos-interconnect.o
> diff --git a/drivers/interconnect/exynos/exynos.c 
> b/drivers/interconnect/exynos/exynos.c
> new file mode 100644
> index 000..8278194
> --- /dev/null
> +++ b/drivers/interconnect/exynos/exynos.c
> @@ -0,0 +1,185 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Exynos generic interconnect provider driver
> + *
> + * Copyright (c) 2020 Samsung Electronics Co., Ltd.
> + *
> + * Authors: Artur Świgoń 
> + *  Sylwester Nawrocki 
> + */
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define kbps_to_khz(x) ((x) / 8)
> +
> +struct exynos_icc_priv {
> +   struct device *dev;
> +
> +   /* One interconnect node per provider */
> +   struct icc_provider provider;
> +   struct icc_node *node;
> +
> +   struct dev_pm_qos_request qos_req;
> +};
> +
> +static struct icc_node *exynos_icc_get_parent(struct device_node *np)
> +{
> +   struct of_phandle_args args;
> +   int num, ret;
> +
> +   num = of_count_phandle_with_args(np, 

[PATCH v3 3/4] pinctrl: bcm2835: Match BCM7211 compatible string

2020-05-30 Thread Florian Fainelli
The BCM7211 SoC uses the same pinconf_ops as the ones defined for the
BCM2711 SoC, match the compatible string and use the correct set of
options.

Signed-off-by: Florian Fainelli 
---
 drivers/pinctrl/bcm/pinctrl-bcm2835.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/pinctrl/bcm/pinctrl-bcm2835.c 
b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
index 06bd2b70af3c..1b00d93aa66e 100644
--- a/drivers/pinctrl/bcm/pinctrl-bcm2835.c
+++ b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
@@ -1137,6 +1137,10 @@ static const struct of_device_id bcm2835_pinctrl_match[] 
= {
.compatible = "brcm,bcm2711-gpio",
.data = _plat_data,
},
+   {
+   .compatible = "brcm,bcm7211-gpio",
+   .data = _plat_data,
+   },
{}
 };
 
-- 
2.17.1



[PATCH v3 0/4] pinctrl: bcm2835: Add support for wake-up interrupts

2020-05-30 Thread Florian Fainelli
Hi Linus,

This patch series updates the bcm2835 pinctrl driver to support
the BCM7211 SoC which is quite similar to 2711 (Raspberry Pi 4)
except that it also supports wake-up interrupts.

Thanks!

Changes in v3:

- added Rob's Acked-by for the binding patches (#1 and #2)
- correct check on the number of GPIOs in irq_set_irq_wake (Stefan)

Changes in v2:

- fixed patch #3 to reference the correct data structure (Stefan)
- fixed patch #4 to use conditional initialization and fetching of
  interrupt resources to limit the memory overhead for non-7211 chips

Florian Fainelli (4):
  dt-bindings: pinctrl: Document 7211 compatible for
brcm,bcm2835-gpio.txt
  dt-bindings: pinctrl: Document optional BCM7211 wake-up interrupts
  pinctrl: bcm2835: Match BCM7211 compatible string
  pinctrl: bcm2835: Add support for wake-up interrupts

 .../bindings/pinctrl/brcm,bcm2835-gpio.txt|  5 +-
 drivers/pinctrl/bcm/pinctrl-bcm2835.c | 80 ++-
 2 files changed, 83 insertions(+), 2 deletions(-)

-- 
2.17.1



[PATCH v3 4/4] pinctrl: bcm2835: Add support for wake-up interrupts

2020-05-30 Thread Florian Fainelli
Leverage the IRQCHIP_MASK_ON_SUSPEND flag in order to avoid having to
specifically treat the GPIO interrupts during suspend and resume, and
simply implement an irq_set_wake() callback that is responsible for
enabling the parent wake-up interrupt as a wake-up interrupt.

To avoid allocating unnecessary resources for other chips, the wake-up
interrupts are only initialized if we have a brcm,bcm7211-gpio
compatibility string.

Signed-off-by: Florian Fainelli 
---
 drivers/pinctrl/bcm/pinctrl-bcm2835.c | 76 ++-
 1 file changed, 75 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/bcm/pinctrl-bcm2835.c 
b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
index 1b00d93aa66e..1d21129f7751 100644
--- a/drivers/pinctrl/bcm/pinctrl-bcm2835.c
+++ b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -76,6 +77,7 @@
 struct bcm2835_pinctrl {
struct device *dev;
void __iomem *base;
+   int *wake_irq;
 
/* note: locking assumes each bank will have its own unsigned long */
unsigned long enabled_irq_map[BCM2835_NUM_BANKS];
@@ -435,6 +437,11 @@ static void bcm2835_gpio_irq_handler(struct irq_desc *desc)
chained_irq_exit(host_chip, desc);
 }
 
+static irqreturn_t bcm2835_gpio_wake_irq_handler(int irq, void *dev_id)
+{
+   return IRQ_HANDLED;
+}
+
 static inline void __bcm2835_gpio_irq_config(struct bcm2835_pinctrl *pc,
unsigned reg, unsigned offset, bool enable)
 {
@@ -634,6 +641,34 @@ static void bcm2835_gpio_irq_ack(struct irq_data *data)
bcm2835_gpio_set_bit(pc, GPEDS0, gpio);
 }
 
+static int bcm2835_gpio_irq_set_wake(struct irq_data *data, unsigned int on)
+{
+   struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
+   struct bcm2835_pinctrl *pc = gpiochip_get_data(chip);
+   unsigned gpio = irqd_to_hwirq(data);
+   unsigned int irqgroup;
+   int ret = -EINVAL;
+
+   if (!pc->wake_irq)
+   return ret;
+
+   if (gpio <= 27)
+   irqgroup = 0;
+   else if (gpio >= 28 && gpio <= 45)
+   irqgroup = 1;
+   else if (gpio >= 46 && gpio <= 57)
+   irqgroup = 2;
+   else
+   return ret;
+
+   if (on)
+   ret = enable_irq_wake(pc->wake_irq[irqgroup]);
+   else
+   ret = disable_irq_wake(pc->wake_irq[irqgroup]);
+
+   return ret;
+}
+
 static struct irq_chip bcm2835_gpio_irq_chip = {
.name = MODULE_NAME,
.irq_enable = bcm2835_gpio_irq_enable,
@@ -642,6 +677,8 @@ static struct irq_chip bcm2835_gpio_irq_chip = {
.irq_ack = bcm2835_gpio_irq_ack,
.irq_mask = bcm2835_gpio_irq_disable,
.irq_unmask = bcm2835_gpio_irq_enable,
+   .irq_set_wake = bcm2835_gpio_irq_set_wake,
+   .flags = IRQCHIP_MASK_ON_SUSPEND,
 };
 
 static int bcm2835_pctl_get_groups_count(struct pinctrl_dev *pctldev)
@@ -1154,6 +1191,7 @@ static int bcm2835_pinctrl_probe(struct platform_device 
*pdev)
struct resource iomem;
int err, i;
const struct of_device_id *match;
+   int is_7211 = 0;
 
BUILD_BUG_ON(ARRAY_SIZE(bcm2835_gpio_pins) != BCM2711_NUM_GPIOS);
BUILD_BUG_ON(ARRAY_SIZE(bcm2835_gpio_groups) != BCM2711_NUM_GPIOS);
@@ -1180,6 +1218,7 @@ static int bcm2835_pinctrl_probe(struct platform_device 
*pdev)
return -EINVAL;
 
pdata = match->data;
+   is_7211 = of_device_is_compatible(np, "brcm,bcm7211-gpio");
 
pc->gpio_chip = *pdata->gpio_chip;
pc->gpio_chip.parent = dev;
@@ -1214,6 +1253,15 @@ static int bcm2835_pinctrl_probe(struct platform_device 
*pdev)
 GFP_KERNEL);
if (!girq->parents)
return -ENOMEM;
+
+   if (is_7211) {
+   pc->wake_irq = devm_kcalloc(dev, BCM2835_NUM_IRQS,
+   sizeof(*pc->wake_irq),
+   GFP_KERNEL);
+   if (!pc->wake_irq)
+   return -ENOMEM;
+   }
+
/*
 * Use the same handler for all groups: this is necessary
 * since we use one gpiochip to cover all lines - the
@@ -1221,8 +1269,34 @@ static int bcm2835_pinctrl_probe(struct platform_device 
*pdev)
 * bank that was firing the IRQ and look up the per-group
 * and bank data.
 */
-   for (i = 0; i < BCM2835_NUM_IRQS; i++)
+   for (i = 0; i < BCM2835_NUM_IRQS; i++) {
+   int len;
+   char *name;
+
girq->parents[i] = irq_of_parse_and_map(np, i);
+   if (!is_7211)
+   continue;
+
+   /* Skip over the all banks interrupts */
+   pc->wake_irq[i] = irq_of_parse_and_map(np, i +
+  BCM2835_NUM_IRQS + 1);
+
+   len = strlen(dev_name(pc->dev)) + 16;
+   name = 

[PATCH v3 1/4] dt-bindings: pinctrl: Document 7211 compatible for brcm,bcm2835-gpio.txt

2020-05-30 Thread Florian Fainelli
Document the brcm,bcm7211-gpio compatible string in the
brcm,bcm2835-gpio.txt document.

Acked-by: Rob Herring 
Signed-off-by: Florian Fainelli 
---
 Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt 
b/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt
index 3cab7336a326..dfc67b90591c 100644
--- a/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt
+++ b/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt
@@ -9,6 +9,7 @@ Required properties:
   "brcm,bcm2835-gpio" - BCM2835 compatible pinctrl
   "brcm,bcm7211-gpio" - BCM7211 compatible pinctrl
   "brcm,bcm2711-gpio" - BCM2711 compatible pinctrl
+  "brcm,bcm7211-gpio" - BCM7211 compatible pinctrl
 - reg: Should contain the physical address of the GPIO module's registers.
 - gpio-controller: Marks the device node as a GPIO controller.
 - #gpio-cells : Should be two. The first cell is the pin number and the
-- 
2.17.1



[PATCH v3 2/4] dt-bindings: pinctrl: Document optional BCM7211 wake-up interrupts

2020-05-30 Thread Florian Fainelli
BCM7211 supports wake-up interrupts in the form of optional interrupt
lines, one per bank, plus the "all banks" interrupt line.

Acked-by: Rob Herring 
Signed-off-by: Florian Fainelli 
---
 .../devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt 
b/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt
index dfc67b90591c..5682b2010e50 100644
--- a/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt
+++ b/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt
@@ -16,7 +16,9 @@ Required properties:
   second cell is used to specify optional parameters:
   - bit 0 specifies polarity (0 for normal, 1 for inverted)
 - interrupts : The interrupt outputs from the controller. One interrupt per
-  individual bank followed by the "all banks" interrupt.
+  individual bank followed by the "all banks" interrupt. For BCM7211, an
+  additional set of per-bank interrupt line and an "all banks" wake-up
+  interrupt may be specified.
 - interrupt-controller: Marks the device node as an interrupt controller.
 - #interrupt-cells : Should be 2.
   The first cell is the GPIO number.
-- 
2.17.1



Re: [RFC PATCH v5 5/6] ARM: dts: exynos: Add interconnects to Exynos4412 mixer

2020-05-30 Thread Chanwoo Choi
Hi Sylwester,

On Sat, May 30, 2020 at 1:33 AM Sylwester Nawrocki
 wrote:
>
> From: Artur Świgoń 
>
> This patch adds an 'interconnects' property to Exynos4412 DTS in order to
> declare the interconnect path used by the mixer. Please note that the
> 'interconnect-names' property is not needed when there is only one path in
> 'interconnects', in which case calling of_icc_get() with a NULL name simply
> returns the right path.
>
> Signed-off-by: Artur Świgoń 
> Reviewed-by: Chanwoo Choi 
> ---
> Changes for v5:
>  - none.
> ---
>  arch/arm/boot/dts/exynos4412.dtsi | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/arch/arm/boot/dts/exynos4412.dtsi 
> b/arch/arm/boot/dts/exynos4412.dtsi
> index a7496d3..eee86d2 100644
> --- a/arch/arm/boot/dts/exynos4412.dtsi
> +++ b/arch/arm/boot/dts/exynos4412.dtsi
> @@ -776,6 +776,7 @@
> clock-names = "mixer", "hdmi", "sclk_hdmi", "vp";
> clocks = < CLK_MIXER>, < CLK_HDMI>,
>  < CLK_SCLK_HDMI>, < CLK_VP>;
> +   interconnects = <_display _dmc>;

I think it is really good and necessary in order to support the
minimum bandwidth.
Until now, I had to add the additional code to support for this same purpose
into product code.

Reviewed-by: Chanwoo Choi 

-- 
Best Regards,
Chanwoo Choi
Samsung Electronics


Re: [RFC PATCH v5 4/6] ARM: dts: exynos: Add interconnect properties to Exynos4412 bus nodes

2020-05-30 Thread Chanwoo Choi
Hi Sylwester,

On Sat, May 30, 2020 at 1:33 AM Sylwester Nawrocki
 wrote:
>
> This patch adds the following properties for Exynos4412 interconnect
> bus nodes:
>  - samsung,interconnect-parent: to declare connections between
>nodes in order to guarantee PM QoS requirements between nodes;
>  - #interconnect-cells: required by the interconnect framework.
>
> Note that #interconnect-cells is always zero and node IDs are not
> hardcoded anywhere.
>
> Signed-off-by: Artur Świgoń 
> Signed-off-by: Sylwester Nawrocki 
> ---
> Changes for v5:
>  - adjust to renamed exynos,interconnect-parent-node property,
>  - add properties in common exynos4412.dtsi file rather than
>in Odroid specific odroid4412-odroid-common.dtsi.
> ---
>  arch/arm/boot/dts/exynos4412.dtsi | 5 +
>  1 file changed, 5 insertions(+)
>
> diff --git a/arch/arm/boot/dts/exynos4412.dtsi 
> b/arch/arm/boot/dts/exynos4412.dtsi
> index 4886894..a7496d3 100644
> --- a/arch/arm/boot/dts/exynos4412.dtsi
> +++ b/arch/arm/boot/dts/exynos4412.dtsi
> @@ -381,6 +381,7 @@
> clocks = < CLK_DIV_DMC>;
> clock-names = "bus";
> operating-points-v2 = <_dmc_opp_table>;
> +   #interconnect-cells = <0>;
> status = "disabled";
> };
>
> @@ -450,6 +451,8 @@
> clocks = < CLK_DIV_GDL>;
> clock-names = "bus";
> operating-points-v2 = <_leftbus_opp_table>;
> +   samsung,interconnect-parent = <_dmc>;
> +   #interconnect-cells = <0>;
> status = "disabled";
> };
>
> @@ -466,6 +469,8 @@
> clocks = < CLK_ACLK160>;
> clock-names = "bus";
> operating-points-v2 = <_display_opp_table>;
> +   samsung,interconnect-parent = <_leftbus>;
> +   #interconnect-cells = <0>;
> status = "disabled";
> };
>
> --
> 2.7.4
>

Reviewed-by: Chanwoo Choi 

-- 
Best Regards,
Chanwoo Choi
Samsung Electronics


Re: [RFC PATCH v5 1/6] dt-bindings: exynos-bus: Add documentation for interconnect properties

2020-05-30 Thread Chanwoo Choi
Hi Sylwester,


On Sat, May 30, 2020 at 1:32 AM Sylwester Nawrocki
 wrote:
>
> Add documentation for new optional properties in the exynos bus nodes:
> samsung,interconnect-parent, #interconnect-cells.
> These properties allow to specify the SoC interconnect structure which
> then allows the interconnect consumer devices to request specific
> bandwidth requirements.
>
> Signed-off-by: Artur Świgoń 
> Signed-off-by: Sylwester Nawrocki 
> ---
> Changes for v5:
>  - exynos,interconnect-parent-node renamed to samsung,interconnect-parent
> ---
>  Documentation/devicetree/bindings/devfreq/exynos-bus.txt | 15 +--
>  1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/devfreq/exynos-bus.txt 
> b/Documentation/devicetree/bindings/devfreq/exynos-bus.txt
> index e71f752..e0d2daa 100644
> --- a/Documentation/devicetree/bindings/devfreq/exynos-bus.txt
> +++ b/Documentation/devicetree/bindings/devfreq/exynos-bus.txt
> @@ -51,6 +51,11 @@ Optional properties only for parent bus device:
>  - exynos,saturation-ratio: the percentage value which is used to calibrate
> the performance count against total cycle count.
>
> +Optional properties for interconnect functionality (QoS frequency 
> constraints):
> +- samsung,interconnect-parent: phandle to the parent interconnect node; for
> +  passive devices should point to same node as the exynos,parent-bus 
> property.
> +- #interconnect-cells: should be 0
> +
>  Detailed correlation between sub-blocks and power line according to Exynos 
> SoC:
>  - In case of Exynos3250, there are two power line as following:
> VDD_MIF |--- DMC
> @@ -185,8 +190,9 @@ Example1:
> --
>
>  Example2 :
> -   The bus of DMC (Dynamic Memory Controller) block in exynos3250.dtsi
> -   is listed below:
> +   The bus of DMC (Dynamic Memory Controller) block in exynos3250.dtsi is
> +   listed below. An interconnect path "bus_lcd0 -- bus_leftbus -- 
> bus_dmc"
> +   is defined for demonstration purposes.
>
> bus_dmc: bus_dmc {
> compatible = "samsung,exynos-bus";
> @@ -376,12 +382,15 @@ Example2 :
> _dmc {
> devfreq-events = <_dmc0_3>, <_dmc1_3>;
> vdd-supply = <_reg>;  /* VDD_MIF */
> +   #interconnect-cells = <0>;
> status = "okay";
> };
>
> _leftbus {
> devfreq-events = <_leftbus_3>, <_rightbus_3>;
> vdd-supply = <_reg>;
> +   samsung,interconnect-parent = <_dmc>;
> +   #interconnect-cells = <0>;
> status = "okay";
> };
>
> @@ -392,6 +401,8 @@ Example2 :
>
> _lcd0 {
> devfreq = <_leftbus>;
> +   samsung,interconnect-parent = <_leftbus>;
> +   #interconnect-cells = <0>;
> status = "okay";
> };
>
> --
> 2.7.4
>

If you add the usage example like the mixer device of patch5 to this
dt-binding document,
I think it is very beneficial and more helpful for user of
exynos-bus/exynos-generic-icc.

Acked-by: Chanwoo Choi 

--
Best Regards,
Chanwoo Choi
Samsung Electronics


Re: [RFC PATCH v5 3/6] PM / devfreq: exynos-bus: Add registration of interconnect child device

2020-05-30 Thread Chanwoo Choi
Hi Sylwester,

On Sat, May 30, 2020 at 1:33 AM Sylwester Nawrocki
 wrote:
>
> This patch adds registration of a child platform device for the exynos
> interconnect driver. It is assumed that the interconnect provider will
> only be needed when #interconnect-cells property is present in the bus
> DT node, hence the child device will be created only when such a property
> is present.
>
> Signed-off-by: Sylwester Nawrocki 
>
> Changes for v5:
>  - new patch.
> ---
>  drivers/devfreq/exynos-bus.c | 17 +
>  1 file changed, 17 insertions(+)
>
> diff --git a/drivers/devfreq/exynos-bus.c b/drivers/devfreq/exynos-bus.c
> index 8fa8eb5..856e37d 100644
> --- a/drivers/devfreq/exynos-bus.c
> +++ b/drivers/devfreq/exynos-bus.c
> @@ -24,6 +24,7 @@
>
>  struct exynos_bus {
> struct device *dev;
> +   struct platform_device *icc_pdev;
>
> struct devfreq *devfreq;
> struct devfreq_event_dev **edev;
> @@ -156,6 +157,8 @@ static void exynos_bus_exit(struct device *dev)
> if (ret < 0)
> dev_warn(dev, "failed to disable the devfreq-event 
> devices\n");
>
> +   platform_device_unregister(bus->icc_pdev);
> +
> dev_pm_opp_of_remove_table(dev);
> clk_disable_unprepare(bus->clk);
> if (bus->opp_table) {
> @@ -168,6 +171,8 @@ static void exynos_bus_passive_exit(struct device *dev)
>  {
> struct exynos_bus *bus = dev_get_drvdata(dev);
>
> +   platform_device_unregister(bus->icc_pdev);
> +
> dev_pm_opp_of_remove_table(dev);
> clk_disable_unprepare(bus->clk);
>  }
> @@ -431,6 +436,18 @@ static int exynos_bus_probe(struct platform_device *pdev)
> if (ret < 0)
> goto err;
>
> +   /* Create child platform device for the interconnect provider */
> +   if (of_get_property(dev->of_node, "#interconnect-cells", NULL)) {
> +   bus->icc_pdev = platform_device_register_data(
> +   dev, "exynos-generic-icc",
> +   PLATFORM_DEVID_AUTO, NULL, 0);
> +
> +   if (IS_ERR(bus->icc_pdev)) {
> +   ret = PTR_ERR(bus->icc_pdev);
> +   goto err;
> +   }
> +   }
> +
> max_state = bus->devfreq->profile->max_state;
> min_freq = (bus->devfreq->profile->freq_table[0] / 1000);
> max_freq = (bus->devfreq->profile->freq_table[max_state - 1] / 1000);
> --
> 2.7.4
>

It looks like very similar like the registering the interconnect
device of imx-bus.c
and I already reviewed and agreed this approach.

Acked-by: Chanwoo Choi 

nitpick: IMHO, I think that 'exynos-icc' is proper and simple without
'generic' word.
If we need to add new icc compatible int the future, we will add
'exynos-icc' new compatible.
But, I'm not forcing it. just opinion. Anyway, I agree this approach.

-- 
Best Regards,
Chanwoo Choi
Samsung Electronics


Re: [PATCH 09/12] x86/xen: save and restore steal clock

2020-05-30 Thread Boris Ostrovsky
On 5/19/20 7:28 PM, Anchal Agarwal wrote:
> From: Munehisa Kamata 
>
> Save steal clock values of all present CPUs in the system core ops
> suspend callbacks. Also, restore a boot CPU's steal clock in the system
> core resume callback. For non-boot CPUs, restore after they're brought
> up, because runstate info for non-boot CPUs are not active until then.
>
> Signed-off-by: Munehisa Kamata 
> Signed-off-by: Anchal Agarwal 
> ---
>  arch/x86/xen/suspend.c | 13 -
>  arch/x86/xen/time.c|  3 +++
>  2 files changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/xen/suspend.c b/arch/x86/xen/suspend.c
> index 784c4484100b..dae0f74f5390 100644
> --- a/arch/x86/xen/suspend.c
> +++ b/arch/x86/xen/suspend.c
> @@ -91,12 +91,20 @@ void xen_arch_suspend(void)
>  static int xen_syscore_suspend(void)
>  {
>   struct xen_remove_from_physmap xrfp;
> - int ret;
> + int cpu, ret;
>  
>   /* Xen suspend does similar stuffs in its own logic */
>   if (xen_suspend_mode_is_xen_suspend())
>   return 0;
>  
> + for_each_present_cpu(cpu) {
> + /*
> +  * Nonboot CPUs are already offline, but the last copy of
> +  * runstate info is still accessible.
> +  */
> + xen_save_steal_clock(cpu);
> + }
> +
>   xrfp.domid = DOMID_SELF;
>   xrfp.gpfn = __pa(HYPERVISOR_shared_info) >> PAGE_SHIFT;
>  
> @@ -118,6 +126,9 @@ static void xen_syscore_resume(void)
>  
>   pvclock_resume();


Doesn't make any difference but I think since this patch is where you
are dealing with clock then pvclock_resume() should be added here and
not in the earlier patch.


-boris


>  
> + /* Nonboot CPUs will be resumed when they're brought up */
> + xen_restore_steal_clock(smp_processor_id());
> +
>   gnttab_resume();
>  }
>  
> diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c
> index c8897aad13cd..33d754564b09 100644
> --- a/arch/x86/xen/time.c
> +++ b/arch/x86/xen/time.c
> @@ -545,6 +545,9 @@ static void xen_hvm_setup_cpu_clockevents(void)
>  {
>   int cpu = smp_processor_id();
>   xen_setup_runstate_info(cpu);
> + if (cpu)
> + xen_restore_steal_clock(cpu);
> +
>   /*
>* xen_setup_timer(cpu) - snprintf is bad in atomic context. Hence
>* doing it xen_hvm_cpu_notify (which gets called by smp_init during





Re: [PATCH 08/12] xen/time: introduce xen_{save,restore}_steal_clock

2020-05-30 Thread Boris Ostrovsky
On 5/19/20 7:28 PM, Anchal Agarwal wrote:
> From: Munehisa Kamata 
>
> Currently, steal time accounting code in scheduler expects steal clock
> callback to provide monotonically increasing value. If the accounting
> code receives a smaller value than previous one, it uses a negative
> value to calculate steal time and results in incorrectly updated idle
> and steal time accounting. This breaks userspace tools which read
> /proc/stat.
>
> top - 08:05:35 up  2:12,  3 users,  load average: 0.00, 0.07, 0.23
> Tasks:  80 total,   1 running,  79 sleeping,   0 stopped,   0 zombie
> Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,30100.0%id,  0.0%wa,  0.0%hi, 
> 0.0%si,-1253874204672.0%st
>
> This can actually happen when a Xen PVHVM guest gets restored from
> hibernation, because such a restored guest is just a fresh domain from
> Xen perspective and the time information in runstate info starts over
> from scratch.
>
> This patch introduces xen_save_steal_clock() which saves current values
> in runstate info into per-cpu variables. Its couterpart,
> xen_restore_steal_clock(), sets offset if it found the current values in
> runstate info are smaller than previous ones. xen_steal_clock() is also
> modified to use the offset to ensure that scheduler only sees
> monotonically increasing number.
>
> Signed-off-by: Munehisa Kamata 
> Signed-off-by: Anchal Agarwal 
> ---
>  drivers/xen/time.c| 29 -
>  include/xen/xen-ops.h |  2 ++
>  2 files changed, 30 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/xen/time.c b/drivers/xen/time.c
> index 0968859c29d0..3560222cc0dd 100644
> --- a/drivers/xen/time.c
> +++ b/drivers/xen/time.c
> @@ -23,6 +23,9 @@ static DEFINE_PER_CPU(struct vcpu_runstate_info, 
> xen_runstate);
>  
>  static DEFINE_PER_CPU(u64[4], old_runstate_time);
>  
> +static DEFINE_PER_CPU(u64, xen_prev_steal_clock);
> +static DEFINE_PER_CPU(u64, xen_steal_clock_offset);


Can you use old_runstate_time here? It is used to solve a similar
problem for pv suspend, isn't it?


-boris






Re: [PATCH v2 4/4] pinctrl: bcm2835: Add support for wake-up interrupts

2020-05-30 Thread Stefan Wahren
Hi Florian,

Am 30.05.20 um 23:19 schrieb Florian Fainelli:
>
> On 5/30/2020 12:49 AM, Stefan Wahren wrote:
>> Hi Florian,
>>
>> Am 29.05.20 um 21:15 schrieb Florian Fainelli:
>>>  }
>>>  
>>> +static int bcm2835_gpio_irq_set_wake(struct irq_data *data, unsigned int 
>>> on)
>>> +{
>>> +   struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
>>> +   struct bcm2835_pinctrl *pc = gpiochip_get_data(chip);
>>> +   unsigned gpio = irqd_to_hwirq(data);
>>> +   unsigned int irqgroup;
>>> +   int ret = -EINVAL;
>>> +
>>> +   if (!pc->wake_irq)
>>> +   return ret;
>>> +
>>> +   if (gpio <= 27)
>>> +   irqgroup = 0;
>>> +   else if (gpio >= 28 && gpio <= 45)
>>> +   irqgroup = 1;
>>> +   else if (gpio >= 46 && gpio <= 53)
>>> +   irqgroup = 2;
>> in case the BCM7211 has 58 GPIOs, but the wake up interrupts are only
>> available for the first 54 this should deserve a comment.
> irqgroup 2 covers GPIOs 46 through 57, thanks for noticing. Do you have
> more comments before I spin a v3? Thank you for reviewing.

no, i don't.

Regards
Stefan



Re: [PATCH 05/12] genirq: Shutdown irq chips in suspend/resume during hibernation

2020-05-30 Thread Boris Ostrovsky
On 5/19/20 7:26 PM, Anchal Agarwal wrote:
> Many legacy device drivers do not implement power management (PM)
> functions which means that interrupts requested by these drivers stay
> in active state when the kernel is hibernated.
>
> This does not matter on bare metal and on most hypervisors because the
> interrupt is restored on resume without any noticable side effects as
> it stays connected to the same physical or virtual interrupt line.
>
> The XEN interrupt mechanism is different as it maintains a mapping
> between the Linux interrupt number and a XEN event channel. If the
> interrupt stays active on hibernation this mapping is preserved but
> there is unfortunately no guarantee that on resume the same event
> channels are reassigned to these devices. This can result in event
> channel conflicts which prevent the affected devices from being
> restored correctly.
>
> One way to solve this would be to add the necessary power management
> functions to all affected legacy device drivers, but that's a
> questionable effort which does not provide any benefits on non-XEN
> environments.
>
> The least intrusive and most efficient solution is to provide a
> mechanism which allows the core interrupt code to tear down these
> interrupts on hibernation and bring them back up again on resume. This
> allows the XEN event channel mechanism to assign an arbitrary event
> channel on resume without affecting the functionality of these
> devices.
>
> Fortunately all these device interrupts are handled by a dedicated XEN
> interrupt chip so the chip can be marked that all interrupts connected
> to it are handled this way. This is pretty much in line with the other
> interrupt chip specific quirks, e.g. IRQCHIP_MASK_ON_SUSPEND.
>
> Add a new quirk flag IRQCHIP_SHUTDOWN_ON_SUSPEND and add support for
> it the core interrupt suspend/resume paths.
>
> Signed-off-by: Anchal Agarwal 
> Signed-off--by: Thomas Gleixner 


Since Thomas wrote this patch I think it should also have "From: " him.


-boris




[PATCH 4/8] macintosh/adb-iop: Access current_req and adb_iop_state when inside lock

2020-05-30 Thread Finn Thain
Drop the redundant local_irq_save/restore() from adb_iop_start() because
the caller has to do it anyway. This is the pattern used in via-macii.

Cc: Joshua Thompson 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/macintosh/adb-iop.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/macintosh/adb-iop.c b/drivers/macintosh/adb-iop.c
index c3089dacf2e2..7ecc41bc7358 100644
--- a/drivers/macintosh/adb-iop.c
+++ b/drivers/macintosh/adb-iop.c
@@ -137,7 +137,6 @@ static void adb_iop_listen(struct iop_msg *msg)
 
 static void adb_iop_start(void)
 {
-   unsigned long flags;
struct adb_request *req;
struct adb_iopmsg amsg;
 
@@ -146,8 +145,6 @@ static void adb_iop_start(void)
if (!req)
return;
 
-   local_irq_save(flags);
-
/* The IOP takes MacII-style packets, so strip the initial
 * ADB_PACKET byte.
 */
@@ -161,7 +158,6 @@ static void adb_iop_start(void)
 
req->sent = 1;
adb_iop_state = sending;
-   local_irq_restore(flags);
 
/* Now send it. The IOP manager will call adb_iop_complete
 * when the message has been sent.
@@ -208,13 +204,13 @@ static int adb_iop_write(struct adb_request *req)
return -EINVAL;
}
 
-   local_irq_save(flags);
-
req->next = NULL;
req->sent = 0;
req->complete = 0;
req->reply_len = 0;
 
+   local_irq_save(flags);
+
if (current_req != 0) {
last_req->next = req;
last_req = req;
@@ -223,10 +219,11 @@ static int adb_iop_write(struct adb_request *req)
last_req = req;
}
 
-   local_irq_restore(flags);
-
if (adb_iop_state == idle)
adb_iop_start();
+
+   local_irq_restore(flags);
+
return 0;
 }
 
-- 
2.26.2



[PATCH 5/8] macintosh/adb-iop: Resolve static checker warnings

2020-05-30 Thread Finn Thain
drivers/macintosh/adb-iop.c:215:28: warning: Using plain integer as NULL pointer
drivers/macintosh/adb-iop.c:170:5: warning: symbol 'adb_iop_probe' was not 
declared. Should it be static?
drivers/macintosh/adb-iop.c:177:5: warning: symbol 'adb_iop_init' was not 
declared. Should it be static?
drivers/macintosh/adb-iop.c:184:5: warning: symbol 'adb_iop_send_request' was 
not declared. Should it be static?
drivers/macintosh/adb-iop.c:230:5: warning: symbol 'adb_iop_autopoll' was not 
declared. Should it be static?
drivers/macintosh/adb-iop.c:236:6: warning: symbol 'adb_iop_poll' was not 
declared. Should it be static?
drivers/macintosh/adb-iop.c:241:5: warning: symbol 'adb_iop_reset_bus' was not 
declared. Should it be static?

Cc: Joshua Thompson 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/macintosh/adb-iop.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/macintosh/adb-iop.c b/drivers/macintosh/adb-iop.c
index 7ecc41bc7358..a2b28e09f2ce 100644
--- a/drivers/macintosh/adb-iop.c
+++ b/drivers/macintosh/adb-iop.c
@@ -166,21 +166,21 @@ static void adb_iop_start(void)
 adb_iop_complete);
 }
 
-int adb_iop_probe(void)
+static int adb_iop_probe(void)
 {
if (!iop_ism_present)
return -ENODEV;
return 0;
 }
 
-int adb_iop_init(void)
+static int adb_iop_init(void)
 {
pr_info("adb: IOP ISM driver v0.4 for Unified ADB\n");
iop_listen(ADB_IOP, ADB_CHAN, adb_iop_listen, "ADB");
return 0;
 }
 
-int adb_iop_send_request(struct adb_request *req, int sync)
+static int adb_iop_send_request(struct adb_request *req, int sync)
 {
int err;
 
@@ -211,7 +211,7 @@ static int adb_iop_write(struct adb_request *req)
 
local_irq_save(flags);
 
-   if (current_req != 0) {
+   if (current_req) {
last_req->next = req;
last_req = req;
} else {
@@ -227,18 +227,18 @@ static int adb_iop_write(struct adb_request *req)
return 0;
 }
 
-int adb_iop_autopoll(int devs)
+static int adb_iop_autopoll(int devs)
 {
/* TODO: how do we enable/disable autopoll? */
return 0;
 }
 
-void adb_iop_poll(void)
+static void adb_iop_poll(void)
 {
iop_ism_irq_poll(ADB_IOP);
 }
 
-int adb_iop_reset_bus(void)
+static int adb_iop_reset_bus(void)
 {
struct adb_request req;
 
-- 
2.26.2



[PATCH 8/8] macintosh/adb-iop: Implement SRQ autopolling

2020-05-30 Thread Finn Thain
The adb_driver.autopoll method is needed during ADB bus scan and device
address assignment. Implement this method so that the IOP's list of
device addresses can be updated. When the list is empty, disable SRQ
autopolling.

Cc: Joshua Thompson 
Cc: Geert Uytterhoeven 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 arch/m68k/include/asm/adb_iop.h |  1 +
 drivers/macintosh/adb-iop.c | 32 ++--
 2 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/arch/m68k/include/asm/adb_iop.h b/arch/m68k/include/asm/adb_iop.h
index 195d7fb1268c..6aecd020e2fc 100644
--- a/arch/m68k/include/asm/adb_iop.h
+++ b/arch/m68k/include/asm/adb_iop.h
@@ -29,6 +29,7 @@
 
 #define ADB_IOP_EXPLICIT   0x80/* nonzero if explicit command */
 #define ADB_IOP_AUTOPOLL   0x40/* auto/SRQ polling enabled*/
+#define ADB_IOP_SET_AUTOPOLL   0x20/* set autopoll device list*/
 #define ADB_IOP_SRQ0x04/* SRQ detected*/
 #define ADB_IOP_TIMEOUT0x02/* nonzero if timeout  
*/
 
diff --git a/drivers/macintosh/adb-iop.c b/drivers/macintosh/adb-iop.c
index 8594e4f9a830..f3d1a460fbce 100644
--- a/drivers/macintosh/adb-iop.c
+++ b/drivers/macintosh/adb-iop.c
@@ -7,10 +7,6 @@
  * 1999-07-01 (jmt) - First implementation for new driver architecture.
  *
  * 1999-07-31 (jmt) - First working version.
- *
- * TODO:
- *
- * o Implement SRQ handling.
  */
 
 #include 
@@ -28,6 +24,7 @@
 
 static struct adb_request *current_req;
 static struct adb_request *last_req;
+static unsigned int autopoll_devs;
 
 static enum adb_iop_state {
idle,
@@ -123,7 +120,7 @@ static void adb_iop_listen(struct iop_msg *msg)
  amsg->flags & ADB_IOP_AUTOPOLL);
}
 
-   msg->reply[0] = ADB_IOP_AUTOPOLL;
+   msg->reply[0] = autopoll_devs ? ADB_IOP_AUTOPOLL : 0;
iop_complete_message(msg);
 
if (req_done)
@@ -231,9 +228,32 @@ static int adb_iop_write(struct adb_request *req)
return 0;
 }
 
+static void adb_iop_set_ap_complete(struct iop_msg *msg)
+{
+   struct adb_iopmsg *amsg = (struct adb_iopmsg *)msg->message;
+
+   autopoll_devs = (amsg->data[1] << 8) | amsg->data[0];
+}
+
 static int adb_iop_autopoll(int devs)
 {
-   /* TODO: how do we enable/disable autopoll? */
+   struct adb_iopmsg amsg;
+   unsigned long flags;
+   unsigned int mask = (unsigned int)devs & 0xFFFE;
+
+   local_irq_save(flags);
+
+   amsg.flags = ADB_IOP_SET_AUTOPOLL | (mask ? ADB_IOP_AUTOPOLL : 0);
+   amsg.count = 2;
+   amsg.cmd = 0;
+   amsg.data[0] = mask & 0xFF;
+   amsg.data[1] = (mask >> 8) & 0xFF;
+
+   iop_send_message(ADB_IOP, ADB_CHAN, NULL, sizeof(amsg), (__u8 *),
+adb_iop_set_ap_complete);
+
+   local_irq_restore(flags);
+
return 0;
 }
 
-- 
2.26.2



[PATCH 0/8] Mac ADB IOP driver fixes

2020-05-30 Thread Finn Thain
The adb-iop driver was never finished. Some deficiencies have become
apparent over the years. For example,

 - Mouse and/or keyboard may stop working if used together

 - SRQ autopoll list cannot be changed

 - Some bugs were found by inspection

This patch series contains fixes for the known bugs in the driver, plus
a few clean-ups.


Finn Thain (8):
  macintosh/adb-iop: Remove dead and redundant code
  macintosh/adb-iop: Correct comment text
  macintosh/adb-iop: Adopt bus reset algorithm from via-macii driver
  macintosh/adb-iop: Access current_req and adb_iop_state when inside
lock
  macintosh/adb-iop: Resolve static checker warnings
  macintosh/adb-iop: Implement idle -> sending state transition
  macintosh/adb-iop: Implement sending -> idle state transition
  macintosh/adb-iop: Implement SRQ autopolling

 arch/m68k/include/asm/adb_iop.h |   1 +
 drivers/macintosh/adb-iop.c | 186 +++-
 2 files changed, 86 insertions(+), 101 deletions(-)

-- 
2.26.2



[PATCH 3/8] macintosh/adb-iop: Adopt bus reset algorithm from via-macii driver

2020-05-30 Thread Finn Thain
This algorithm is slightly shorter and avoids the surprising
adb_iop_start() call in adb_iop_poll().

Cc: Joshua Thompson 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/macintosh/adb-iop.c | 21 -
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/drivers/macintosh/adb-iop.c b/drivers/macintosh/adb-iop.c
index ca3b411b0742..c3089dacf2e2 100644
--- a/drivers/macintosh/adb-iop.c
+++ b/drivers/macintosh/adb-iop.c
@@ -238,24 +238,19 @@ int adb_iop_autopoll(int devs)
 
 void adb_iop_poll(void)
 {
-   if (adb_iop_state == idle)
-   adb_iop_start();
iop_ism_irq_poll(ADB_IOP);
 }
 
 int adb_iop_reset_bus(void)
 {
-   struct adb_request req = {
-   .reply_expected = 0,
-   .nbytes = 2,
-   .data = { ADB_PACKET, 0 },
-   };
-
-   adb_iop_write();
-   while (!req.complete) {
-   adb_iop_poll();
-   schedule();
-   }
+   struct adb_request req;
+
+   /* Command = 0, Address = ignored */
+   adb_request(, NULL, ADBREQ_NOSEND, 1, ADB_BUSRESET);
+   adb_iop_send_request(, 1);
+
+   /* Don't want any more requests during the Global Reset low time. */
+   mdelay(3);
 
return 0;
 }
-- 
2.26.2



[PATCH 1/8] macintosh/adb-iop: Remove dead and redundant code

2020-05-30 Thread Finn Thain
Cc: Joshua Thompson 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/macintosh/adb-iop.c | 29 -
 1 file changed, 29 deletions(-)

diff --git a/drivers/macintosh/adb-iop.c b/drivers/macintosh/adb-iop.c
index fca31640e3ef..ce28ff40fb9c 100644
--- a/drivers/macintosh/adb-iop.c
+++ b/drivers/macintosh/adb-iop.c
@@ -18,24 +18,16 @@
 #include 
 #include 
 #include 
-#include 
 
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #include 
 
-/*#define DEBUG_ADB_IOP*/
-
 static struct adb_request *current_req;
 static struct adb_request *last_req;
-#if 0
-static unsigned char reply_buff[16];
-static unsigned char *reply_ptr;
-#endif
 
 static enum adb_iop_state {
idle,
@@ -104,22 +96,11 @@ static void adb_iop_listen(struct iop_msg *msg)
struct adb_iopmsg *amsg = (struct adb_iopmsg *)msg->message;
struct adb_request *req;
unsigned long flags;
-#ifdef DEBUG_ADB_IOP
-   int i;
-#endif
 
local_irq_save(flags);
 
req = current_req;
 
-#ifdef DEBUG_ADB_IOP
-   printk("adb_iop_listen %p: rcvd packet, %d bytes: %02X %02X", req,
-  (uint)amsg->count + 2, (uint)amsg->flags, (uint)amsg->cmd);
-   for (i = 0; i < amsg->count; i++)
-   printk(" %02X", (uint)amsg->data[i]);
-   printk("\n");
-#endif
-
/* Handle a timeout. Timeout packets seem to occur even after */
/* we've gotten a valid reply to a TALK, so I'm assuming that */
/* a "timeout" is actually more like an "end-of-data" signal. */
@@ -163,9 +144,6 @@ static void adb_iop_start(void)
unsigned long flags;
struct adb_request *req;
struct adb_iopmsg amsg;
-#ifdef DEBUG_ADB_IOP
-   int i;
-#endif
 
/* get the packet to send */
req = current_req;
@@ -174,13 +152,6 @@ static void adb_iop_start(void)
 
local_irq_save(flags);
 
-#ifdef DEBUG_ADB_IOP
-   printk("adb_iop_start %p: sending packet, %d bytes:", req, req->nbytes);
-   for (i = 0; i < req->nbytes; i++)
-   printk(" %02X", (uint)req->data[i]);
-   printk("\n");
-#endif
-
/* The IOP takes MacII-style packets, so */
/* strip the initial ADB_PACKET byte.*/
 
-- 
2.26.2



[PATCH 6/8] macintosh/adb-iop: Implement idle -> sending state transition

2020-05-30 Thread Finn Thain
In the present algorithm, the 'idle' state transition does not take
place until there's a bus timeout. Once idle, the driver does not
automatically proceed with the next request.

Change the algorithm so that queued ADB requests will be sent as soon as
the driver becomes idle. This is to take place after the current IOP
message is completed.

Cc: Joshua Thompson 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/macintosh/adb-iop.c | 43 +
 1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/drivers/macintosh/adb-iop.c b/drivers/macintosh/adb-iop.c
index a2b28e09f2ce..f22792c95d4f 100644
--- a/drivers/macintosh/adb-iop.c
+++ b/drivers/macintosh/adb-iop.c
@@ -54,13 +54,19 @@ struct adb_driver adb_iop_driver = {
.reset_bus= adb_iop_reset_bus
 };
 
-static void adb_iop_end_req(struct adb_request *req, int state)
+static void adb_iop_done(void)
 {
+   struct adb_request *req = current_req;
+
+   adb_iop_state = idle;
+
req->complete = 1;
current_req = req->next;
if (req->done)
(*req->done)(req);
-   adb_iop_state = state;
+
+   if (adb_iop_state == idle)
+   adb_iop_start();
 }
 
 /*
@@ -94,37 +100,36 @@ static void adb_iop_complete(struct iop_msg *msg)
 static void adb_iop_listen(struct iop_msg *msg)
 {
struct adb_iopmsg *amsg = (struct adb_iopmsg *)msg->message;
-   struct adb_request *req;
unsigned long flags;
+   bool req_done = false;
 
local_irq_save(flags);
 
-   req = current_req;
-
/* Handle a timeout. Timeout packets seem to occur even after
 * we've gotten a valid reply to a TALK, presumably because of
 * autopolling.
 */
 
-   if (amsg->flags & ADB_IOP_TIMEOUT) {
-   msg->reply[0] = ADB_IOP_TIMEOUT | ADB_IOP_AUTOPOLL;
-   msg->reply[1] = 0;
-   msg->reply[2] = 0;
-   if (req && (adb_iop_state != idle)) {
-   adb_iop_end_req(req, idle);
-   }
-   } else {
-   if ((adb_iop_state == awaiting_reply) &&
-   (amsg->flags & ADB_IOP_EXPLICIT)) {
+   if (amsg->flags & ADB_IOP_EXPLICIT) {
+   if (adb_iop_state == awaiting_reply) {
+   struct adb_request *req = current_req;
+
req->reply_len = amsg->count + 1;
memcpy(req->reply, >cmd, req->reply_len);
-   } else {
-   adb_input(>cmd, amsg->count + 1,
- amsg->flags & ADB_IOP_AUTOPOLL);
+
+   req_done = true;
}
-   memcpy(msg->reply, msg->message, IOP_MSG_LEN);
+   } else if (!(amsg->flags & ADB_IOP_TIMEOUT)) {
+   adb_input(>cmd, amsg->count + 1,
+ amsg->flags & ADB_IOP_AUTOPOLL);
}
+
+   msg->reply[0] = ADB_IOP_AUTOPOLL;
iop_complete_message(msg);
+
+   if (req_done)
+   adb_iop_done();
+
local_irq_restore(flags);
 }
 
-- 
2.26.2



[PATCH 2/8] macintosh/adb-iop: Correct comment text

2020-05-30 Thread Finn Thain
This patch improves comment style and corrects some misunderstandings
in the text.

Cc: Joshua Thompson 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/macintosh/adb-iop.c | 29 +
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/drivers/macintosh/adb-iop.c b/drivers/macintosh/adb-iop.c
index ce28ff40fb9c..ca3b411b0742 100644
--- a/drivers/macintosh/adb-iop.c
+++ b/drivers/macintosh/adb-iop.c
@@ -101,11 +101,10 @@ static void adb_iop_listen(struct iop_msg *msg)
 
req = current_req;
 
-   /* Handle a timeout. Timeout packets seem to occur even after */
-   /* we've gotten a valid reply to a TALK, so I'm assuming that */
-   /* a "timeout" is actually more like an "end-of-data" signal. */
-   /* We need to send back a timeout packet to the IOP to shut   */
-   /* it up, plus complete the current request, if any.  */
+   /* Handle a timeout. Timeout packets seem to occur even after
+* we've gotten a valid reply to a TALK, presumably because of
+* autopolling.
+*/
 
if (amsg->flags & ADB_IOP_TIMEOUT) {
msg->reply[0] = ADB_IOP_TIMEOUT | ADB_IOP_AUTOPOLL;
@@ -115,9 +114,6 @@ static void adb_iop_listen(struct iop_msg *msg)
adb_iop_end_req(req, idle);
}
} else {
-   /* TODO: is it possible for more than one chunk of data  */
-   /*   to arrive before the timeout? If so we need to */
-   /*   use reply_ptr here like the other drivers do.  */
if ((adb_iop_state == awaiting_reply) &&
(amsg->flags & ADB_IOP_EXPLICIT)) {
req->reply_len = amsg->count + 1;
@@ -152,23 +148,24 @@ static void adb_iop_start(void)
 
local_irq_save(flags);
 
-   /* The IOP takes MacII-style packets, so */
-   /* strip the initial ADB_PACKET byte.*/
-
+   /* The IOP takes MacII-style packets, so strip the initial
+* ADB_PACKET byte.
+*/
amsg.flags = ADB_IOP_EXPLICIT;
amsg.count = req->nbytes - 2;
 
-   /* amsg.data immediately follows amsg.cmd, effectively making */
-   /* amsg.cmd a pointer to the beginning of a full ADB packet.  */
+   /* amsg.data immediately follows amsg.cmd, effectively making
+*  a pointer to the beginning of a full ADB packet.
+*/
memcpy(, req->data + 1, req->nbytes - 1);
 
req->sent = 1;
adb_iop_state = sending;
local_irq_restore(flags);
 
-   /* Now send it. The IOP manager will call adb_iop_complete */
-   /* when the packet has been sent.  */
-
+   /* Now send it. The IOP manager will call adb_iop_complete
+* when the message has been sent.
+*/
iop_send_message(ADB_IOP, ADB_CHAN, req, sizeof(amsg), (__u8 *),
 adb_iop_complete);
 }
-- 
2.26.2



[PATCH 7/8] macintosh/adb-iop: Implement sending -> idle state transition

2020-05-30 Thread Finn Thain
On leaving the 'sending' state, proceed to the 'idle' state if no reply is
expected. Drop redundant test for adb_iop_state == sending && current_req.

Cc: Joshua Thompson 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/macintosh/adb-iop.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/macintosh/adb-iop.c b/drivers/macintosh/adb-iop.c
index f22792c95d4f..8594e4f9a830 100644
--- a/drivers/macintosh/adb-iop.c
+++ b/drivers/macintosh/adb-iop.c
@@ -77,15 +77,14 @@ static void adb_iop_done(void)
 
 static void adb_iop_complete(struct iop_msg *msg)
 {
-   struct adb_request *req;
unsigned long flags;
 
local_irq_save(flags);
 
-   req = current_req;
-   if ((adb_iop_state == sending) && req && req->reply_expected) {
+   if (current_req->reply_expected)
adb_iop_state = awaiting_reply;
-   }
+   else
+   adb_iop_done();
 
local_irq_restore(flags);
 }
-- 
2.26.2



[PATCH 2/4] m68k/mac: Fix IOP status/control register writes

2020-05-30 Thread Finn Thain
When writing values to the IOP status/control register make sure those
values do not have any extraneous bits that will clear interrupt flags.

To place the SCC IOP into bypass mode would be desirable but this is not
achieved by writing IOP_DMAINACTIVE | IOP_RUN | IOP_AUTOINC | IOP_BYPASS
to the control register. Drop this ineffective register write.

Remove the flawed and unused iop_bypass() function. Make use of the
unused iop_stop() function.

Cc: Joshua Thompson 
Tested-by: Stan Johnson 
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Finn Thain 
---
 arch/m68k/mac/iop.c | 12 +++-
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/arch/m68k/mac/iop.c b/arch/m68k/mac/iop.c
index 22c4e2b8bdf2..5fc3b59ba811 100644
--- a/arch/m68k/mac/iop.c
+++ b/arch/m68k/mac/iop.c
@@ -183,7 +183,7 @@ static __inline__ void iop_writeb(volatile struct mac_iop 
*iop, __u16 addr, __u8
 
 static __inline__ void iop_stop(volatile struct mac_iop *iop)
 {
-   iop->status_ctrl &= ~IOP_RUN;
+   iop->status_ctrl = IOP_AUTOINC;
 }
 
 static __inline__ void iop_start(volatile struct mac_iop *iop)
@@ -191,14 +191,9 @@ static __inline__ void iop_start(volatile struct mac_iop 
*iop)
iop->status_ctrl = IOP_RUN | IOP_AUTOINC;
 }
 
-static __inline__ void iop_bypass(volatile struct mac_iop *iop)
-{
-   iop->status_ctrl |= IOP_BYPASS;
-}
-
 static __inline__ void iop_interrupt(volatile struct mac_iop *iop)
 {
-   iop->status_ctrl |= IOP_IRQ;
+   iop->status_ctrl = IOP_IRQ | IOP_RUN | IOP_AUTOINC;
 }
 
 static int iop_alive(volatile struct mac_iop *iop)
@@ -244,7 +239,6 @@ void __init iop_preinit(void)
} else {
iop_base[IOP_NUM_SCC] = (struct mac_iop *) 
SCC_IOP_BASE_QUADRA;
}
-   iop_base[IOP_NUM_SCC]->status_ctrl = 0x87;
iop_scc_present = 1;
} else {
iop_base[IOP_NUM_SCC] = NULL;
@@ -256,7 +250,7 @@ void __init iop_preinit(void)
} else {
iop_base[IOP_NUM_ISM] = (struct mac_iop *) 
ISM_IOP_BASE_QUADRA;
}
-   iop_base[IOP_NUM_ISM]->status_ctrl = 0;
+   iop_stop(iop_base[IOP_NUM_ISM]);
iop_ism_present = 1;
} else {
iop_base[IOP_NUM_ISM] = NULL;
-- 
2.26.2



[PATCH 1/4] m68k/mac: Don't send IOP message until channel is idle

2020-05-30 Thread Finn Thain
In the following sequence of calls, iop_do_send() gets called when the
"send" channel is not in the IOP_MSG_IDLE state:

iop_ism_irq()
iop_handle_send()
(msg->handler)()
iop_send_message()
iop_do_send()

Avoid this by testing the channel state before calling iop_do_send().

When sending, and iop_send_queue is empty, call iop_do_send() because
the channel is idle. If iop_send_queue is not empty, iop_do_send() will
get called later by iop_handle_send().

Cc: Joshua Thompson 
Tested-by: Stan Johnson 
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Finn Thain 
---
 arch/m68k/mac/iop.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/arch/m68k/mac/iop.c b/arch/m68k/mac/iop.c
index d99c7ea08d8c..22c4e2b8bdf2 100644
--- a/arch/m68k/mac/iop.c
+++ b/arch/m68k/mac/iop.c
@@ -415,7 +415,8 @@ static void iop_handle_send(uint iop_num, uint chan)
msg->status = IOP_MSGSTATUS_UNUSED;
msg = msg->next;
iop_send_queue[iop_num][chan] = msg;
-   if (msg) iop_do_send(msg);
+   if (msg && iop_readb(iop, IOP_ADDR_SEND_STATE + chan) == IOP_MSG_IDLE)
+   iop_do_send(msg);
 }
 
 /*
@@ -489,16 +490,12 @@ int iop_send_message(uint iop_num, uint chan, void 
*privdata,
 
if (!(q = iop_send_queue[iop_num][chan])) {
iop_send_queue[iop_num][chan] = msg;
+   iop_do_send(msg);
} else {
while (q->next) q = q->next;
q->next = msg;
}
 
-   if (iop_readb(iop_base[iop_num],
-   IOP_ADDR_SEND_STATE + chan) == IOP_MSG_IDLE) {
-   iop_do_send(msg);
-   }
-
return 0;
 }
 
-- 
2.26.2



[PATCH 4/4] m68k/mac: Improve IOP debug messages

2020-05-30 Thread Finn Thain
Always dump the full message and reply. Avoid printing partial lines
as this output gets mixed up with the output from called functions.
Don't output the state of idle channels.

Cc: Joshua Thompson 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 arch/m68k/mac/iop.c | 38 +++---
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/arch/m68k/mac/iop.c b/arch/m68k/mac/iop.c
index 8d6946edf2c8..373a74c99356 100644
--- a/arch/m68k/mac/iop.c
+++ b/arch/m68k/mac/iop.c
@@ -347,8 +347,8 @@ void iop_complete_message(struct iop_msg *msg)
int chan = msg->channel;
int i,offset;
 
-   iop_pr_debug("msg %p iop_num %d channel %d\n", msg, msg->iop_num,
-msg->channel);
+   iop_pr_debug("iop_num %d chan %d reply %*ph\n",
+msg->iop_num, msg->channel, IOP_MSG_LEN, msg->reply);
 
offset = IOP_ADDR_RECV_MSG + (msg->channel * IOP_MSG_LEN);
 
@@ -372,6 +372,9 @@ static void iop_do_send(struct iop_msg *msg)
volatile struct mac_iop *iop = iop_base[msg->iop_num];
int i,offset;
 
+   iop_pr_debug("iop_num %d chan %d message %*ph\n",
+msg->iop_num, msg->channel, IOP_MSG_LEN, msg->message);
+
offset = IOP_ADDR_SEND_MSG + (msg->channel * IOP_MSG_LEN);
 
for (i = 0 ; i < IOP_MSG_LEN ; i++, offset++) {
@@ -394,8 +397,6 @@ static void iop_handle_send(uint iop_num, uint chan)
struct iop_msg *msg;
int i,offset;
 
-   iop_pr_debug("iop_num %d chan %d\n", iop_num, chan);
-
iop_writeb(iop, IOP_ADDR_SEND_STATE + chan, IOP_MSG_IDLE);
 
if (!(msg = iop_send_queue[iop_num][chan])) return;
@@ -405,6 +406,9 @@ static void iop_handle_send(uint iop_num, uint chan)
for (i = 0 ; i < IOP_MSG_LEN ; i++, offset++) {
msg->reply[i] = iop_readb(iop, offset);
}
+   iop_pr_debug("iop_num %d chan %d reply %*ph\n",
+iop_num, chan, IOP_MSG_LEN, msg->reply);
+
if (msg->handler) (*msg->handler)(msg);
msg->status = IOP_MSGSTATUS_UNUSED;
msg = msg->next;
@@ -424,8 +428,6 @@ static void iop_handle_recv(uint iop_num, uint chan)
int i,offset;
struct iop_msg *msg;
 
-   iop_pr_debug("iop_num %d chan %d\n", iop_num, chan);
-
msg = iop_get_unused_msg();
msg->iop_num = iop_num;
msg->channel = chan;
@@ -437,6 +439,8 @@ static void iop_handle_recv(uint iop_num, uint chan)
for (i = 0 ; i < IOP_MSG_LEN ; i++, offset++) {
msg->message[i] = iop_readb(iop, offset);
}
+   iop_pr_debug("iop_num %d chan %d message %*ph\n",
+iop_num, chan, IOP_MSG_LEN, msg->message);
 
iop_writeb(iop, IOP_ADDR_RECV_STATE + chan, IOP_MSG_RCVD);
 
@@ -446,9 +450,6 @@ static void iop_handle_recv(uint iop_num, uint chan)
if (msg->handler) {
(*msg->handler)(msg);
} else {
-   iop_pr_debug("unclaimed message on iop_num %d chan %d\n",
-iop_num, chan);
-   iop_pr_debug("%*ph\n", IOP_MSG_LEN, msg->message);
memset(msg->reply, 0, IOP_MSG_LEN);
iop_complete_message(msg);
}
@@ -559,35 +560,34 @@ irqreturn_t iop_ism_irq(int irq, void *dev_id)
int i,state;
u8 events = iop->status_ctrl & (IOP_INT0 | IOP_INT1);
 
-   iop_pr_debug("status %02X\n", iop->status_ctrl);
-
do {
+   iop_pr_debug("iop_num %d status %02X\n", iop_num,
+iop->status_ctrl);
+
/* INT0 indicates state change on an outgoing message channel */
if (events & IOP_INT0) {
iop->status_ctrl = IOP_INT0 | IOP_RUN | IOP_AUTOINC;
-   iop_pr_debug("new status %02X, send states",
-iop->status_ctrl);
for (i = 0; i < NUM_IOP_CHAN; i++) {
state = iop_readb(iop, IOP_ADDR_SEND_STATE + i);
-   iop_pr_cont(" %02X", state);
if (state == IOP_MSG_COMPLETE)
iop_handle_send(iop_num, i);
+   else if (state != IOP_MSG_IDLE)
+   iop_pr_debug("chan %d send state 
%02X\n",
+i, state);
}
-   iop_pr_cont("\n");
}
 
/* INT1 for incoming messages */
if (events & IOP_INT1) {
iop->status_ctrl = IOP_INT1 | IOP_RUN | IOP_AUTOINC;
-   iop_pr_debug("new status %02X, recv states",
-iop->status_ctrl);
for (i = 0; i < NUM_IOP_CHAN; i++) {
state = iop_readb(iop, IOP_ADDR_RECV_STATE + i);
-

[PATCH 3/4] m68k/mac: Don't send uninitialized data in IOP message reply

2020-05-30 Thread Finn Thain
Clear the message reply before calling iop_complete(). This code path is
not normally executed but should that happen let's arrange for consistent
behaviour from the IOP.

Cc: Joshua Thompson 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 arch/m68k/mac/iop.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/m68k/mac/iop.c b/arch/m68k/mac/iop.c
index 5fc3b59ba811..8d6946edf2c8 100644
--- a/arch/m68k/mac/iop.c
+++ b/arch/m68k/mac/iop.c
@@ -449,6 +449,7 @@ static void iop_handle_recv(uint iop_num, uint chan)
iop_pr_debug("unclaimed message on iop_num %d chan %d\n",
 iop_num, chan);
iop_pr_debug("%*ph\n", IOP_MSG_LEN, msg->message);
+   memset(msg->reply, 0, IOP_MSG_LEN);
iop_complete_message(msg);
}
 }
-- 
2.26.2



[PATCH 0/4] Mac IOP driver fixes

2020-05-30 Thread Finn Thain
This patch series has several bug fixes for the IOP driver and some
improvements to the debug level log messages.

Geert, please consider pushing these fixes for v5.8, if not the
whole series.


Finn Thain (4):
  m68k/mac: Don't send IOP message until channel is idle
  m68k/mac: Fix IOP status/control register writes
  m68k/mac: Don't send uninitialized data in IOP message reply
  m68k/mac: Improve IOP debug messages

 arch/m68k/mac/iop.c | 60 -
 1 file changed, 26 insertions(+), 34 deletions(-)

-- 
2.26.2



Re: [PATCH] checkpatch/coding-style: Allow 100 column lines

2020-05-30 Thread Joe Perches
On Sat, 2020-05-30 at 16:14 -0600, Andreas Dilger wrote:
> On May 29, 2020, at 5:12 PM, Joe Perches  wrote:
> > Change the maximum allowed line length to 100 from 80.
> 
> What is the benefit/motivation for changing this?  The vast majority
> of files are wrapped at 80 columns, and if some files start being
> wrapped at 100 columns they will either display poorly on 80-column
> terminals, or a lot of dead space will show in 100-column terminals.

YA Linus bleat in this thread.
I don't much care one way or any other.

https://lore.kernel.org/lkml/CAHk-=wj3igqqjpvc+gf6+c29jo4coj6oqqfzdy0h5qvyktd...@mail.gmail.com/

and

https://lore.kernel.org/lkml/CAHk-=wjr0h3+2ba0uuwwoyzybh0gx9ytf5dj2mzyo0xvyzv...@mail.gmail.com/




Re: [PATCH 04/12] x86/xen: add system core suspend and resume callbacks

2020-05-30 Thread Boris Ostrovsky
On 5/19/20 7:26 PM, Anchal Agarwal wrote:
> From: Munehisa Kamata 
>
> Add Xen PVHVM specific system core callbacks for PM suspend and
> hibernation support. The callbacks suspend and resume Xen
> primitives,like shared_info, pvclock and grant table. Note that
> Xen suspend can handle them in a different manner, but system
> core callbacks are called from the context.


I don't think I understand that last sentence.


>  So if the callbacks
> are called from Xen suspend context, return immediately.
>


> +
> +static int xen_syscore_suspend(void)
> +{
> + struct xen_remove_from_physmap xrfp;
> + int ret;
> +
> + /* Xen suspend does similar stuffs in its own logic */
> + if (xen_suspend_mode_is_xen_suspend())
> + return 0;
> +
> + xrfp.domid = DOMID_SELF;
> + xrfp.gpfn = __pa(HYPERVISOR_shared_info) >> PAGE_SHIFT;
> +
> + ret = HYPERVISOR_memory_op(XENMEM_remove_from_physmap, );
> + if (!ret)
> + HYPERVISOR_shared_info = _dummy_shared_info;
> +
> + return ret;
> +}
> +
> +static void xen_syscore_resume(void)
> +{
> + /* Xen suspend does similar stuffs in its own logic */
> + if (xen_suspend_mode_is_xen_suspend())
> + return;
> +
> + /* No need to setup vcpu_info as it's already moved off */
> + xen_hvm_map_shared_info();
> +
> + pvclock_resume();
> +
> + gnttab_resume();


Do you call gnttab_suspend() in pm suspend path?


> +}
> +
> +/*
> + * These callbacks will be called with interrupts disabled and when having 
> only
> + * one CPU online.
> + */
> +static struct syscore_ops xen_hvm_syscore_ops = {
> + .suspend = xen_syscore_suspend,
> + .resume = xen_syscore_resume
> +};
> +
> +void __init xen_setup_syscore_ops(void)
> +{
> + if (xen_hvm_domain())


Have you tested this (the whole feature, not just this patch) with PVH
guest BTW? And PVH dom0 for that matter?


-boris


> + register_syscore_ops(_hvm_syscore_ops);
> +}





Re: [RFC PATCH] checkpatch: check for trivial sizeofs

2020-05-30 Thread Joe Perches
On Sun, 2020-05-31 at 00:21 +0300, Denis Efremov wrote:
> sizeof(char) and its variations in most cases doesn't make code more clear.
> It only makes code wordy.

There are about 1000 of these uses in the kernel.

Not sure I like this though as many/most of the uses
seem _less_ readable with a 1 in their place.

$ git grep -P 
'sizeof\s*\(\s*(?:(?:unsigned\s+)?char\s*|(?:__)?u8|u?int8_t|[us]?byte(?:_t)?)\s*\)'
 | wc -l
970

Try the grep without the wc and see if you agree.

And if this is actually going to be used, I'd prefer
using a separate $typeChar for the search.

Maybe something like:
---
 scripts/checkpatch.pl | 17 +
 1 file changed, 17 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index dd750241958b..de2e9242350b 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -466,6 +466,13 @@ our $typeTypedefs = qr{(?x:
$typeKernelTypedefs\b
 )};
 
+our $typeChar = qr{(?x:
+   (?:(?:un)?signed\s+)?char |
+   (?:__)?u8 |
+   (?:u_|u)?int8_t |
+   [us]?byte(?:_t)?
+)};
+
 our $zero_initializer = qr{(?:(?:0[xX])?0+$Int_type?|NULL|false)\b};
 
 our $logFunctions = qr{(?x:
@@ -6106,6 +6113,16 @@ sub process {
}
}
 
+# check for trivial sizeof(char) == 1
+   if ($line =~ /\bsizeof\s*\(\s*($typeChar)\s*\)/) {
+   my $byte = $1;
+   if (CHK("SIZEOF_CHAR",
+   "sizeof($byte) could be the constant 1 
instead\n" . $herecurr) &&
+   $fix) {
+   $fixed[$fixlinenr] =~ 
s/sizeof\s*\(\s*\Q$byte\E\s*\)/1/;
+   }
+   }
+
 # check for struct spinlock declarations
if ($line =~ /^.\s*\bstruct\s+spinlock\s+\w+\s*;/) {
WARN("USE_SPINLOCK_T",




Re: [PATCH 03/12] x86/xen: Introduce new function to map HYPERVISOR_shared_info on Resume

2020-05-30 Thread Boris Ostrovsky
On 5/19/20 7:25 PM, Anchal Agarwal wrote:
> Introduce a small function which re-uses shared page's PA allocated
> during guest initialization time in reserve_shared_info() and not
> allocate new page during resume flow.
> It also  does the mapping of shared_info_page by calling
> xen_hvm_init_shared_info() to use the function.
>
> Signed-off-by: Anchal Agarwal 
> ---
>  arch/x86/xen/enlighten_hvm.c | 7 +++
>  arch/x86/xen/xen-ops.h   | 1 +
>  2 files changed, 8 insertions(+)
>
> diff --git a/arch/x86/xen/enlighten_hvm.c b/arch/x86/xen/enlighten_hvm.c
> index e138f7de52d2..75b1ec7a0fcd 100644
> --- a/arch/x86/xen/enlighten_hvm.c
> +++ b/arch/x86/xen/enlighten_hvm.c
> @@ -27,6 +27,13 @@
>  
>  static unsigned long shared_info_pfn;
>  
> +void xen_hvm_map_shared_info(void)
> +{
> + xen_hvm_init_shared_info();
> + if (shared_info_pfn)
> + HYPERVISOR_shared_info = __va(PFN_PHYS(shared_info_pfn));
> +}
> +


AFAICT it is only called once so I don't see a need for new routine.


And is it possible for shared_info_pfn to be NULL in resume path (which
is where this is called)?


-boris




Re: [PATCH 02/12] xenbus: add freeze/thaw/restore callbacks support

2020-05-30 Thread Boris Ostrovsky
On 5/19/20 7:25 PM, Anchal Agarwal wrote:
>  
>  int xenbus_dev_resume(struct device *dev)
>  {
> - int err;
> + int err = 0;


That's not necessary.


>   struct xenbus_driver *drv;
>   struct xenbus_device *xdev
>   = container_of(dev, struct xenbus_device, dev);
> -
> + bool xen_suspend = xen_suspend_mode_is_xen_suspend();
>   DPRINTK("%s", xdev->nodename);
>  
>   if (dev->driver == NULL)
> @@ -627,24 +645,32 @@ int xenbus_dev_resume(struct device *dev)
>   drv = to_xenbus_driver(dev->driver);
>   err = talk_to_otherend(xdev);
>   if (err) {
> - pr_warn("resume (talk_to_otherend) %s failed: %i\n",
> + pr_warn("%s (talk_to_otherend) %s failed: %i\n",


Please use dev_warn() everywhere, we just had a bunch of patches that
replaced pr_warn(). In fact,  this is one of the lines that got changed.


>  
>  int xenbus_dev_cancel(struct device *dev)
>  {
> - /* Do nothing */
> - DPRINTK("cancel");
> + int err = 0;


Again, no need to initialize.


> + struct xenbus_driver *drv;
> + struct xenbus_device *xdev
> + = container_of(dev, struct xenbus_device, dev);


xendev please to be consistent with other code. And use to_xenbus_device().


-boris



Re: [PATCH stable-4.19.y] net: phy: reschedule state machine if AN has not completed in PHY_AN state

2020-05-30 Thread Vladimir Oltean
Hi Heiner,

On Sun, 31 May 2020 at 01:36, Heiner Kallweit  wrote:
>
> On 30.05.2020 23:43, Vladimir Oltean wrote:
> > From: Vladimir Oltean 
> >
> > In kernel 4.19 (and probably earlier too) there are issues surrounding
> > the PHY_AN state.
> >
> > For example, if a PHY is in PHY_AN state and AN has not finished, then
> > what is supposed to happen is that the state machine gets rescheduled
> > until it is, or until the link_timeout reaches zero which triggers an
> > autoneg restart process.
> >
> > But actually the rescheduling never works if the PHY uses interrupts,
> > because the condition under which rescheduling occurs is just if
> > phy_polling_mode() is true. So basically, this whole rescheduling
> > functionality works for AN-not-yet-complete just by mistake. Let me
> > explain.
> >
> > Most of the time the AN process manages to finish by the time the
> > interrupt has triggered. One might say "that should always be the case,
> > otherwise the PHY wouldn't raise the interrupt, right?".
> > Well, some PHYs implement an .aneg_done method which allows them to tell
> > the state machine when the AN is really complete.
> > The AR8031/AR8033 driver (at803x.c) is one such example. Even when
> > copper autoneg completes, the driver still keeps the "aneg_done"
> > variable unset until in-band SGMII autoneg finishes too (there is no
> > interrupt for that). So we have the premises of a race condition.
> >
> That's not nice from the PHY:
> It signals "link up", and if the system asks the PHY for link details,
> then it sheepishly says "well, link is *almost* up".
>

The copper-side link is 100% up. In my opinion this is actually abuse
of the .aneg_done API. Here's what the guy who added it had to say:

commit f62265b53ef34a372b657c99e23d32e95b464316
Author: Zefir Kurtisi 
Date:   Mon Oct 24 12:40:54 2016 +0200

at803x: double check SGMII side autoneg

In SGMII mode, we observed an autonegotiation issue
after power-down-up cycles where the copper side
reports successful link establishment but the
SGMII side's link is down.

This happened in a setup where the at8031 is
connected over SGMII to a eTSEC (fsl gianfar),
but so far could not be reproduced with other
Ethernet device / driver combinations.

This commit adds a wrapper function for at8031
that in case of operating in SGMII mode double
checks SGMII link state when generic aneg_done()
succeeds. It prints a warning on failure but
intentionally does not try to recover from this
state. As a result, if you ever see a warning
'803x_aneg_done: SGMII link is not ok' you will
end up having an Ethernet link up but won't get
any data through. This should not happen, if it
does, please contact the module maintainer.

Signed-off-by: Zefir Kurtisi 
Signed-off-by: David S. Miller 

> Question would be whether the same happens with other SGMII-capable
> PHY's so that we need to cater for this scenario in phylib.
> Or whether we consider it a chip quirk. In the latter case a custom
> read_status() handler might do the trick too: if link is reported
> as up then wait until aneg is signaled as done too before reading
> further link details.
>
> And it's interesting that nobody else stumbled across this problem
> before. I mean the PHY we talk about isn't really new. Or is your
> use case so special?
>

No, my use case isn't special at all. Just using it in interrupt mode :)
Today we have the pcs_poll option in phylink (checking the in-band AN
status at PCS side and not at PHY side). But not all Ethernet drivers
have phylink. Actually I think there's no good place in phylib to do
this in-band AN status checking.

But my patch is rather minimal and makes things work in the way there
were intended at that time.

> > In practice, what really happens depends on the log level of the serial
> > console. If the log level is verbose enough that kernel messages related
> > to the Ethernet link state are printed to the console, then this gives
> > in-band AN enough time to complete, which means the link will come up
> > and everyone will be happy. But if the console is not that verbose, the
> > link will sometimes come up, and sometimes will be forced down by the
> > .aneg_done of the PHY driver (forever, since we are not rescheduling).
> >
> > The conclusion is that an extra condition needs to be explicitly added,
> > so that the state machine can be rescheduled properly. Otherwise PHY
> > devices in interrupt mode will never work properly if they have an
> > .aneg_done callback.
> >
> > In more recent kernels, the whole PHY_AN state was removed by Heiner
> > Kallweit in the "[net-next,0/5] net: phy: improve and simplify phylib
> > state machine" series here:
> >
> > https://patchwork.ozlabs.org/cover/994464/
> >
> > and the problem was just masked away instead of being addressed with a
> > punctual patch.
> >
> > Fixes: 76a423a3f8f1 ("net: phy: allow driver to implement their own 
> > aneg_done")

RE: [PATCH] x86/apic/flat64: Add back the early_param("apic", parse_apic)

2020-05-30 Thread Dexuan Cui
> From: Randy Dunlap 
> Sent: Friday, May 29, 2020 6:33 AM
> Hi,
> Looks like you will also need to update
> Documentation/admin-guide/kernel-parameters.txt, where it says:
> 
>   For X86-32, this can also be used to specify an APIC
>   driver name.
> --
> ~Randy

Hi Randy, 
Thanks for you reminder! I just posted a v2 for this with you Cc'd.

Thanks,
-- Dexuan


[PATCH v2] x86/apic/flat64: Add back the early_param("apic", parse_apic)

2020-05-30 Thread Dexuan Cui
parse_apic() allows the user to try a different APIC driver than the
default one that's automatically chosen. It works for X86-32, but
doesn't work for X86-64 because it was removed in 2009 for X86-64 by
commit 7b38725318f4 ("x86: remove subarchitecture support code"),
whose changelog doesn't explicitly describe the removal for X86-64.

The patch adds back the functionality for X86-64. The intent is mainly
to work around an APIC emulation bug in Hyper-V in the case of kdump:
currently Hyper-V does not honor the disabled state of the local APICs,
so all the IOAPIC-based interrupts may not be delivered to the correct
virtual CPU, if the logical-mode APIC driver is used (the kdump
kernel usually uses the logical-mode APIC driver, since typically
only 1 CPU is active). Luckily the kdump issue can be worked around by
forcing the kdump kernel to use physical mode, before the fix to Hyper-V
becomes widely available.

The current algorithm of choosing an APIC driver is:

1. The global pointer "struct apic *apic" has a default value, i.e
"apic_default" on X86-32, and "apic_flat" on X86-64.

2. If the early_param "apic=" is specified, parse_apic() is called and
the pointer "apic" is changed if a matching APIC driver is found.

3. default_acpi_madt_oem_check() calls the acpi_madt_oem_check() method
of all APIC drivers, which may override the "apic" pointer.

4. default_setup_apic_routing() may override the "apic" pointer, e.g.
by calling the probe() method of all APIC drivers. Note: refer to the
order of the APIC drivers specified in arch/x86/kernel/apic/Makefile.

The patch is safe because if the apic= early param is not specified,
the current algorithm of choosing an APIC driver is unchanged; when the
param is specified (e.g. on X86-64, "apic=physical flat"), the kernel
still tries to find a "more suitable" APIC driver in the above step 3 and
4: e.g. if the BIOS/firmware requires that apic_x2apic_phys should be used,
the above step 4 will override the APIC driver to apic_x2apic_phys, even
if an early_param "apic=physical flat" is specified.

On Hyper-V, when a Linux VM has <= 8 virtual CPUs, if we use
"apic=physical flat", sending IPIs to multiple vCPUs is still fast because
Linux VM uses the para-virtualized IPI hypercalls: see hv_apic_init().

Fixes: 7b38725318f4 ("x86: remove subarchitecture support code")
Signed-off-by: Dexuan Cui 
---

Changes in v2:
  Updated Documentation/admin-guide/kernel-parameters.txt. [Randy Dunlap]
  Changed apic_set_verbosity().
  Enhanced the changelog.

 .../admin-guide/kernel-parameters.txt | 11 +---
 arch/x86/kernel/apic/apic.c   | 11 +++-
 arch/x86/kernel/apic/apic_flat_64.c   | 27 ++-
 3 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index 7bc83f3d9bdf..c4503fff9348 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -341,10 +341,15 @@
Format: { quiet (default) | verbose | debug }
Change the amount of debugging information output
when initialising the APIC and IO-APIC components.
-   For X86-32, this can also be used to specify an APIC
-   driver name.
+   This can also be used to specify an APIC driver name.
Format: apic=driver_name
-   Examples: apic=bigsmp
+   Examples:
+ On X86-32:  apic=bigsmp
+ On X86-64: "apic=physical flat"
+ Note: the available driver names depend on the
+ architecture and the kernel config; the setting may
+ be overridden by the acpi_madt_oem_check() and probe()
+ methods of other APIC drivers.
 
apic_extnmi=[APIC,X86] External NMI delivery setting
Format: { bsp (default) | all | none }
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 81b9c63dae1b..ee2363b3c59e 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -2854,13 +2854,10 @@ static int __init apic_set_verbosity(char *arg)
apic_verbosity = APIC_DEBUG;
else if (strcmp("verbose", arg) == 0)
apic_verbosity = APIC_VERBOSE;
-#ifdef CONFIG_X86_64
-   else {
-   pr_warn("APIC Verbosity level %s not recognised"
-   " use apic=verbose or apic=debug\n", arg);
-   return -EINVAL;
-   }
-#endif
+
+   /* Ignore unrecognized verbosity level setting. */
+
+   pr_info("APIC Verbosity level is %d\n", apic_verbosity);
 
return 0;
 }
diff --git a/arch/x86/kernel/apic/apic_flat_64.c 
b/arch/x86/kernel/apic/apic_flat_64.c
index 7862b152a052..efbec63bb01f 

Re: [PATCH stable-4.19.y] net: phy: reschedule state machine if AN has not completed in PHY_AN state

2020-05-30 Thread Heiner Kallweit
On 30.05.2020 23:43, Vladimir Oltean wrote:
> From: Vladimir Oltean 
> 
> In kernel 4.19 (and probably earlier too) there are issues surrounding
> the PHY_AN state.
> 
> For example, if a PHY is in PHY_AN state and AN has not finished, then
> what is supposed to happen is that the state machine gets rescheduled
> until it is, or until the link_timeout reaches zero which triggers an
> autoneg restart process.
> 
> But actually the rescheduling never works if the PHY uses interrupts,
> because the condition under which rescheduling occurs is just if
> phy_polling_mode() is true. So basically, this whole rescheduling
> functionality works for AN-not-yet-complete just by mistake. Let me
> explain.
> 
> Most of the time the AN process manages to finish by the time the
> interrupt has triggered. One might say "that should always be the case,
> otherwise the PHY wouldn't raise the interrupt, right?".
> Well, some PHYs implement an .aneg_done method which allows them to tell
> the state machine when the AN is really complete.
> The AR8031/AR8033 driver (at803x.c) is one such example. Even when
> copper autoneg completes, the driver still keeps the "aneg_done"
> variable unset until in-band SGMII autoneg finishes too (there is no
> interrupt for that). So we have the premises of a race condition.
> 
That's not nice from the PHY:
It signals "link up", and if the system asks the PHY for link details,
then it sheepishly says "well, link is *almost* up".

Question would be whether the same happens with other SGMII-capable
PHY's so that we need to cater for this scenario in phylib.
Or whether we consider it a chip quirk. In the latter case a custom
read_status() handler might do the trick too: if link is reported
as up then wait until aneg is signaled as done too before reading
further link details.

And it's interesting that nobody else stumbled across this problem
before. I mean the PHY we talk about isn't really new. Or is your
use case so special?

> In practice, what really happens depends on the log level of the serial
> console. If the log level is verbose enough that kernel messages related
> to the Ethernet link state are printed to the console, then this gives
> in-band AN enough time to complete, which means the link will come up
> and everyone will be happy. But if the console is not that verbose, the
> link will sometimes come up, and sometimes will be forced down by the
> .aneg_done of the PHY driver (forever, since we are not rescheduling).
> 
> The conclusion is that an extra condition needs to be explicitly added,
> so that the state machine can be rescheduled properly. Otherwise PHY
> devices in interrupt mode will never work properly if they have an
> .aneg_done callback.
> 
> In more recent kernels, the whole PHY_AN state was removed by Heiner
> Kallweit in the "[net-next,0/5] net: phy: improve and simplify phylib
> state machine" series here:
> 
> https://patchwork.ozlabs.org/cover/994464/
> 
> and the problem was just masked away instead of being addressed with a
> punctual patch.
> 
> Fixes: 76a423a3f8f1 ("net: phy: allow driver to implement their own 
> aneg_done")
> Signed-off-by: Vladimir Oltean 
> ---
> I'm not sure the procedure I'm following is correct, sending this
> directly to Greg. The patch doesn't apply on net.
> 
>  drivers/net/phy/phy.c | 6 --
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index cc454b8c032c..ca4fd74fd2c8 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c
> @@ -934,7 +934,7 @@ void phy_state_machine(struct work_struct *work)
>   struct delayed_work *dwork = to_delayed_work(work);
>   struct phy_device *phydev =
>   container_of(dwork, struct phy_device, state_queue);
> - bool needs_aneg = false, do_suspend = false;
> + bool recheck = false, needs_aneg = false, do_suspend = false;
>   enum phy_state old_state;
>   int err = 0;
>   int old_link;
> @@ -981,6 +981,8 @@ void phy_state_machine(struct work_struct *work)
>   phy_link_up(phydev);
>   } else if (0 == phydev->link_timeout--)
>   needs_aneg = true;
> + else
> + recheck = true;
>   break;
>   case PHY_NOLINK:
>   if (!phy_polling_mode(phydev))
> @@ -1123,7 +1125,7 @@ void phy_state_machine(struct work_struct *work)
>* PHY, if PHY_IGNORE_INTERRUPT is set, then we will be moving
>* between states from phy_mac_interrupt()
>*/
> - if (phy_polling_mode(phydev))
> + if (phy_polling_mode(phydev) || recheck)
>   queue_delayed_work(system_power_efficient_wq, 
> >state_queue,
>  PHY_STATE_TIME * HZ);
>  }
> 



Re: Regression with PM / wakeup: Show wakeup sources stats in sysfs"

2020-05-30 Thread Tri Vo
On Sat, May 30, 2020 at 11:52 AM Florian Fainelli  wrote:
>
>
>
> On 5/29/2020 4:14 PM, Tri Vo wrote:
> > On Fri, May 29, 2020 at 3:37 PM Florian Fainelli  
> > wrote:
> >>
> >> On 5/29/20 3:28 PM, Tri Vo wrote:
> >>> On Fri, May 29, 2020 at 9:51 AM Rafael J. Wysocki
> >>>  wrote:
> 
>  On 5/28/2020 10:46 PM, Florian Fainelli wrote:
> > Hi,
> >
> > Commit c8377adfa78103be5380200eb9dab764d7ca890e ("PM / wakeup: Show
> > wakeup sources stats in sysfs") is causing some of our tests to fail
> > because /sys/class/net/*/device/power/wakeup_count is now 0, despite
> > /sys/kernel/debug/wakeup_sources clearly indicating that the Ethernet
> > device was responsible for system wake-up.
> >
> > What's more in looking at /sys/class/wakekup/wakeup2/event_count, we
> > have the number of Wake-on-LAN wakeups recorded properly, but
> > wakeup_count is desperately 0, why is that?
> 
>  I need to look at that commit in detail to find out what is going on.
> >>>
> >>> It would be helpful to see the contents of
> >>> /sys/kernel/debug/wakeup_sources, /sys/class/net/*/device/power/*, and
> >>> /sys/class/wakekup/* corresponding to the device in question. The
> >>> values in these files are queried from the same struct wakeup_source.
> >>> So it's odd if wakeup_count diverges.
> >>
> >> Most certainly, below is the information you want, the two cat
> >> /s/k/d/wakeup_sources were done before Wake-on-LAN and after waking-up
> >> from LAN. /sys/class/wakeup/wakeup2 maps to the Ethernet device.
> >>
> >> The Ethernet device calls pm_wakeup_event() against the struct device
> >> that is embedded in the platform_device that it was probed with. I will
> >> try to debug this myself over the weekend, time permitting.
> >>
> >>
> >> # ethtool -s eth0 wol g
> >> # cat /sys/kernel/debug/wakeup_sources
> >> nameactive_countevent_count wakeup_count
> >> expire_countactive_sincetotal_time  max_time
> >> last_changep
> >> revent_suspend_time
> >> 47d58.ethernet  0   0   0
> >> 0   0   0   0   0  0
> >> alarmtimer  0   0   0   0
> >> 0   0   0   0  0
> >> 47c408400.waketimer 2   2   0
> >> 0   0   0   0   6144
> >> 1   0
> >> # pml -w20
> >> [ 3449.937142] brcm-waketimer 47c408400.waketimer: Using sysfs
> >> attributes, consider using 'rtcwake'
> >> Pass 1 out of 1, mode=none, tp_al[ 3449.952654] PM: suspend entry (shallow)
> >> l=1, cycle_tp=, sleep=, [ 3449.959004] Filesystems sync: 0.000 seconds
> >> wakeup_time=20
> >> [ 3449.965984] Freezing user space processes ... (elapsed 0.001 seconds)
> >> done.
> >> [ 3449.974087] OOM killer disabled.
> >> [ 3449.977316] Freezing remaining freezable tasks ... (elapsed 0.006
> >> seconds) done.
> >> [ 3449.991114] printk: Suspending console(s) (use no_console_suspend to
> >> debug)
> >> AMS: System is entering S2...
> >> [ 3450.022381] bcmgenet 47d58.ethernet eth0: Link is Down
> >> [ 3450.048340] Disabling non-boot CPUs ...
> >> [ 3450.049344] CPU1: shutdown
> >> [ 3450.050393] psci: CPU1 killed (polled 1 ms)
> >> [ 3450.051332] Enabling non-boot CPUs ...
> >> [ 3450.051712] Detected PIPT I-cache on CPU1
> >> [ 3450.051812] CPU1: Booted secondary processor 0x01 [0x410fd083]
> >> [ 3450.052435] CPU1 is up
> >> [ 3450.683588] bcmgenet 47d58.ethernet eth0: Link is Up - 1Gbps/Full
> >> - flow control rx/tx
> >> [ 3450.729677] OOM killer enabled.
> >> [ 3450.732908] Restarting tasks ... done.
> >> [ 3450.738539] PM: suspend exit
> >> --
> >> [ 3450.744239] brcm-waketimer 47c408400.waketimer: Using sysfs
> >> attributes, consider using 'rtcwake'
> >> # cat /sys/kernel/debug/wakeup_sources
> >> nameactive_countevent_count wakeup_count
> >> expire_countactive_sincetotal_time  max_time
> >> last_changep
> >> revent_suspend_time
> >> 47d58.ethernet  1   1   0
> >> 0   0   0   0   3450
> >> 054 0
> >> alarmtimer  0   0   0   0
> >> 0   0   0   0  0
> >> 47c408400.waketimer 2   2   0
> >> 0   0   0   0   6144
> >> 1   0
> >> # cat /sys/class/net/*/device/power/*
> >> cat: read error: Input/output error
> >> auto
> >> 0
> >> unsupported
> >> 0
> >> enabled
> >> 0
> >> 0
> >> 1
> >> 0
> >> 0
> >> 3450054
> >> 0
> >> 0
> >
> > UUIC, 47d58.ethernet is the device of interest here. It's
> > wakeup_count was 0 before wake up, and we expect it to be 1 after wake
> > up. One of the files you cat'ed here has a 1 

Re: [PATCH 01/12] xen/manage: keep track of the on-going suspend mode

2020-05-30 Thread Boris Ostrovsky
On 5/19/20 7:24 PM, Anchal Agarwal wrote:
>  
> +enum suspend_modes {
> + NO_SUSPEND = 0,
> + XEN_SUSPEND,
> + PM_SUSPEND,
> + PM_HIBERNATION,
> +};
> +
> +/* Protected by pm_mutex */
> +static enum suspend_modes suspend_mode = NO_SUSPEND;
> +
> +bool xen_suspend_mode_is_xen_suspend(void)
> +{
> + return suspend_mode == XEN_SUSPEND;
> +}
> +
> +bool xen_suspend_mode_is_pm_suspend(void)
> +{
> + return suspend_mode == PM_SUSPEND;
> +}
> +
> +bool xen_suspend_mode_is_pm_hibernation(void)
> +{
> + return suspend_mode == PM_HIBERNATION;
> +}
> +


I don't see these last two used anywhere. Are you, in fact,
distinguishing between PM suspend and hibernation?


(I would also probably shorten the name a bit, perhaps
xen_is_pv/pm_suspend()?)


-boris





Re: [PATCH] checkpatch/coding-style: Allow 100 column lines

2020-05-30 Thread Andreas Dilger
On May 29, 2020, at 5:12 PM, Joe Perches  wrote:
> 
> Change the maximum allowed line length to 100 from 80.

What is the benefit/motivation for changing this?  The vast majority
of files are wrapped at 80 columns, and if some files start being
wrapped at 100 columns they will either display poorly on 80-column
terminals, or a lot of dead space will show in 100-column terminals.

> Miscellanea:
> 
> o to avoid unnecessary whitespace changes in files,
>  checkpatch will no longer emit a warning about line length
>  when scanning files unless --strict is also used
> o Add a bit to coding-style about alignment to open parenthesis
> 
> Signed-off-by: Joe Perches 
> ---
> Documentation/process/coding-style.rst | 25 -
> scripts/checkpatch.pl  | 14 +-
> 2 files changed, 25 insertions(+), 14 deletions(-)
> 
> diff --git a/Documentation/process/coding-style.rst 
> b/Documentation/process/coding-style.rst
> index acb2f1b36350..55b148e9c6b8 100644
> --- a/Documentation/process/coding-style.rst
> +++ b/Documentation/process/coding-style.rst
> @@ -84,15 +84,22 @@ Get a decent editor and don't leave whitespace at the end 
> of lines.
> Coding style is all about readability and maintainability using commonly
> available tools.
> 
> -The limit on the length of lines is 80 columns and this is a strongly
> -preferred limit.
> -
> -Statements longer than 80 columns will be broken into sensible chunks, unless
> -exceeding 80 columns significantly increases readability and does not hide
> -information. Descendants are always substantially shorter than the parent and
> -are placed substantially to the right. The same applies to function headers
> -with a long argument list. However, never break user-visible strings such as
> -printk messages, because that breaks the ability to grep for them.
> +The preferred limit on the length of a single line is 80 columns.
> +
> +Statements longer than 80 columns should be broken into sensible chunks,
> +unless exceeding 80 columns significantly increases readability and does
> +not hide information.
> +
> +Statements may be up to 100 columns when appropriate.
> +
> +Descendants are always substantially shorter than the parent and are
> +are placed substantially to the right.  A very commonly used style
> +is to align descendants to a function open parenthesis.
> +
> +These same rules are applied to function headers with a long argument list.
> +
> +However, never break user-visible strings such as printk messages because
> +that breaks the ability to grep for them.
> 
> 
> 3) Placing Braces and Spaces
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index dd750241958b..5f00df2c3f59 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -53,7 +53,7 @@ my %ignore_type = ();
> my @ignore = ();
> my $help = 0;
> my $configuration_file = ".checkpatch.conf";
> -my $max_line_length = 80;
> +my $max_line_length = 100;
> my $ignore_perl_version = 0;
> my $minimum_perl_version = 5.10.0;
> my $min_conf_desc_length = 4;
> @@ -99,9 +99,11 @@ Options:
>   --types TYPE(,TYPE2...)show only these comma separated message types
>   --ignore TYPE(,TYPE2...)   ignore various comma separated message types
>   --show-types   show the specific message type in the output
> -  --max-line-length=nset the maximum line length, if exceeded, warn
> +  --max-line-length=nset the maximum line length, (default 
> $max_line_length)
> + if exceeded, warn on patches
> + requires --strict for use with --file
>   --min-conf-desc-length=n   set the min description length, if shorter, warn
> -  --tab-size=n   set the number of spaces for tab (default 8)
> +  --tab-size=n   set the number of spaces for tab (default 
> $tabsize)
>   --root=PATHPATH to the kernel tree root
>   --no-summary   suppress the per-file summary
>   --mailback only produce a report in case of warnings/errors
> @@ -3282,8 +3284,10 @@ sub process {
> 
>   if ($msg_type ne "" &&
>   (show_type("LONG_LINE") || show_type($msg_type))) {
> - WARN($msg_type,
> -  "line over $max_line_length characters\n" 
> . $herecurr);
> + my $msg_level = \
> + $msg_level = \ if ($file);
> + &{$msg_level}($msg_type,
> +   "line length of $length exceeds 
> $max_line_length columns\n" . $herecurr);
>   }
>   }
> 
> 


Cheers, Andreas







signature.asc
Description: Message signed with OpenPGP


[PATCH v2 02/10] x86/percpu: Clean up percpu_to_op()

2020-05-30 Thread Brian Gerst
The core percpu macros already have a switch on the data size, so the switch
in the x86 code is redundant and produces more dead code.

Also use appropriate types for the width of the instructions.  This avoids
errors when compiling with Clang.

Signed-off-by: Brian Gerst 
Reviewed-by: Nick Desaulniers 
---
 arch/x86/include/asm/percpu.h | 90 ++-
 1 file changed, 35 insertions(+), 55 deletions(-)

diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index 19838e4f7a8f..fb280fba94c5 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -117,37 +117,17 @@ extern void __bad_percpu_size(void);
 #define __pcpu_reg_imm_4(x) "ri" (x)
 #define __pcpu_reg_imm_8(x) "re" (x)
 
-#define percpu_to_op(qual, op, var, val)   \
-do {   \
-   typedef typeof(var) pto_T__;\
-   if (0) {\
-   pto_T__ pto_tmp__;  \
-   pto_tmp__ = (val);  \
-   (void)pto_tmp__;\
-   }   \
-   switch (sizeof(var)) {  \
-   case 1: \
-   asm qual (op "b %1,"__percpu_arg(0) \
-   : "+m" (var)\
-   : "qi" ((pto_T__)(val)));   \
-   break;  \
-   case 2: \
-   asm qual (op "w %1,"__percpu_arg(0) \
-   : "+m" (var)\
-   : "ri" ((pto_T__)(val)));   \
-   break;  \
-   case 4: \
-   asm qual (op "l %1,"__percpu_arg(0) \
-   : "+m" (var)\
-   : "ri" ((pto_T__)(val)));   \
-   break;  \
-   case 8: \
-   asm qual (op "q %1,"__percpu_arg(0) \
-   : "+m" (var)\
-   : "re" ((pto_T__)(val)));   \
-   break;  \
-   default: __bad_percpu_size();   \
-   }   \
+#define percpu_to_op(size, qual, op, _var, _val)   \
+do {   \
+   __pcpu_type_##size pto_val__ = __pcpu_cast_##size(_val);\
+   if (0) {\
+   typeof(_var) pto_tmp__; \
+   pto_tmp__ = (_val); \
+   (void)pto_tmp__;\
+   }   \
+   asm qual(__pcpu_op2_##size(op, "%[val]", __percpu_arg([var]))   \
+   : [var] "+m" (_var) \
+   : [val] __pcpu_reg_imm_##size(pto_val__));  \
 } while (0)
 
 /*
@@ -425,18 +405,18 @@ do {  
\
 #define raw_cpu_read_2(pcp)percpu_from_op(, "mov", pcp)
 #define raw_cpu_read_4(pcp)percpu_from_op(, "mov", pcp)
 
-#define raw_cpu_write_1(pcp, val)  percpu_to_op(, "mov", (pcp), val)
-#define raw_cpu_write_2(pcp, val)  percpu_to_op(, "mov", (pcp), val)
-#define raw_cpu_write_4(pcp, val)  percpu_to_op(, "mov", (pcp), val)
+#define raw_cpu_write_1(pcp, val)  percpu_to_op(1, , "mov", (pcp), val)
+#define raw_cpu_write_2(pcp, val)  percpu_to_op(2, , "mov", (pcp), val)
+#define raw_cpu_write_4(pcp, val)  percpu_to_op(4, , "mov", (pcp), val)
 #define raw_cpu_add_1(pcp, val)percpu_add_op(, (pcp), val)
 #define raw_cpu_add_2(pcp, val)percpu_add_op(, (pcp), val)
 #define raw_cpu_add_4(pcp, val)percpu_add_op(, (pcp), val)
-#define raw_cpu_and_1(pcp, val)percpu_to_op(, "and", (pcp), 
val)
-#define raw_cpu_and_2(pcp, val)percpu_to_op(, "and", (pcp), 
val)
-#define raw_cpu_and_4(pcp, val)percpu_to_op(, "and", (pcp), 
val)
-#define raw_cpu_or_1(pcp, val) percpu_to_op(, "or", (pcp), val)
-#define raw_cpu_or_2(pcp, val) percpu_to_op(, "or", (pcp), val)
-#define raw_cpu_or_4(pcp, val) percpu_to_op(, "or", (pcp), val)
+#define raw_cpu_and_1(pcp, val)percpu_to_op(1, , "and", (pcp), 
val)
+#define raw_cpu_and_2(pcp, val)percpu_to_op(2, , "and", (pcp), 
val)
+#define raw_cpu_and_4(pcp, val)

[PATCH v2 08/10] x86/percpu: Clean up percpu_cmpxchg_op()

2020-05-30 Thread Brian Gerst
The core percpu macros already have a switch on the data size, so the switch
in the x86 code is redundant and produces more dead code.

Also use appropriate types for the width of the instructions.  This avoids
errors when compiling with Clang.

Signed-off-by: Brian Gerst 
Reviewed-by: Nick Desaulniers 
---
 arch/x86/include/asm/percpu.h | 58 +++
 1 file changed, 18 insertions(+), 40 deletions(-)

diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index ac6d7e76c0d4..7efc0b5c4ff0 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -236,39 +236,17 @@ do {  
\
  * cmpxchg has no such implied lock semantics as a result it is much
  * more efficient for cpu local operations.
  */
-#define percpu_cmpxchg_op(qual, var, oval, nval)   \
+#define percpu_cmpxchg_op(size, qual, _var, _oval, _nval)  \
 ({ \
-   typeof(var) pco_ret__;  \
-   typeof(var) pco_old__ = (oval); \
-   typeof(var) pco_new__ = (nval); \
-   switch (sizeof(var)) {  \
-   case 1: \
-   asm qual ("cmpxchgb %2, "__percpu_arg(1)\
-   : "=a" (pco_ret__), "+m" (var)  \
-   : "q" (pco_new__), "0" (pco_old__)  \
-   : "memory");\
-   break;  \
-   case 2: \
-   asm qual ("cmpxchgw %2, "__percpu_arg(1)\
-   : "=a" (pco_ret__), "+m" (var)  \
-   : "r" (pco_new__), "0" (pco_old__)  \
-   : "memory");\
-   break;  \
-   case 4: \
-   asm qual ("cmpxchgl %2, "__percpu_arg(1)\
-   : "=a" (pco_ret__), "+m" (var)  \
-   : "r" (pco_new__), "0" (pco_old__)  \
-   : "memory");\
-   break;  \
-   case 8: \
-   asm qual ("cmpxchgq %2, "__percpu_arg(1)\
-   : "=a" (pco_ret__), "+m" (var)  \
-   : "r" (pco_new__), "0" (pco_old__)  \
-   : "memory");\
-   break;  \
-   default: __bad_percpu_size();   \
-   }   \
-   pco_ret__;  \
+   __pcpu_type_##size pco_old__ = __pcpu_cast_##size(_oval);   \
+   __pcpu_type_##size pco_new__ = __pcpu_cast_##size(_nval);   \
+   asm qual (__pcpu_op2_##size("cmpxchg", "%[nval]",   \
+   __percpu_arg([var]))\
+ : [oval] "+a" (pco_old__),\
+   [var] "+m" (_var)   \
+ : [nval] __pcpu_reg_##size(, pco_new__)   \
+ : "memory");  \
+   (typeof(_var))(unsigned long) pco_old__;\
 })
 
 /*
@@ -336,16 +314,16 @@ do {  
\
 #define raw_cpu_add_return_1(pcp, val) percpu_add_return_op(1, , pcp, 
val)
 #define raw_cpu_add_return_2(pcp, val) percpu_add_return_op(2, , pcp, 
val)
 #define raw_cpu_add_return_4(pcp, val) percpu_add_return_op(4, , pcp, 
val)
-#define raw_cpu_cmpxchg_1(pcp, oval, nval) percpu_cmpxchg_op(, pcp, oval, 
nval)
-#define raw_cpu_cmpxchg_2(pcp, oval, nval) percpu_cmpxchg_op(, pcp, oval, 
nval)
-#define raw_cpu_cmpxchg_4(pcp, oval, nval) percpu_cmpxchg_op(, pcp, oval, 
nval)
+#define raw_cpu_cmpxchg_1(pcp, oval, nval) percpu_cmpxchg_op(1, , pcp, 
oval, nval)
+#define raw_cpu_cmpxchg_2(pcp, oval, nval) percpu_cmpxchg_op(2, , pcp, 
oval, nval)
+#define raw_cpu_cmpxchg_4(pcp, oval, nval) percpu_cmpxchg_op(4, , pcp, 
oval, nval)
 
 #define this_cpu_add_return_1(pcp, val)percpu_add_return_op(1, 

[PATCH v2 10/10] x86/percpu: Remove unused PER_CPU() macro

2020-05-30 Thread Brian Gerst
Also remove now unused __percpu_mov_op.

Signed-off-by: Brian Gerst 
---
 arch/x86/include/asm/percpu.h | 18 --
 1 file changed, 18 deletions(-)

diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index cf2b9c2a241e..a3c33b79fb86 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -4,33 +4,15 @@
 
 #ifdef CONFIG_X86_64
 #define __percpu_seg   gs
-#define __percpu_mov_opmovq
 #else
 #define __percpu_seg   fs
-#define __percpu_mov_opmovl
 #endif
 
 #ifdef __ASSEMBLY__
 
-/*
- * PER_CPU finds an address of a per-cpu variable.
- *
- * Args:
- *var - variable name
- *reg - 32bit register
- *
- * The resulting address is stored in the "reg" argument.
- *
- * Example:
- *PER_CPU(cpu_gdt_descr, %ebx)
- */
 #ifdef CONFIG_SMP
-#define PER_CPU(var, reg)  \
-   __percpu_mov_op %__percpu_seg:this_cpu_off, reg;\
-   lea var(reg), reg
 #define PER_CPU_VAR(var)   %__percpu_seg:var
 #else /* ! SMP */
-#define PER_CPU(var, reg)  __percpu_mov_op $var, reg
 #define PER_CPU_VAR(var)   var
 #endif /* SMP */
 
-- 
2.25.4



[PATCH v2 07/10] x86/percpu: Clean up percpu_xchg_op()

2020-05-30 Thread Brian Gerst
The core percpu macros already have a switch on the data size, so the switch
in the x86 code is redundant and produces more dead code.

Also use appropriate types for the width of the instructions.  This avoids
errors when compiling with Clang.

Signed-off-by: Brian Gerst 
Reviewed-by: Nick Desaulniers 
---
 arch/x86/include/asm/percpu.h | 61 +++
 1 file changed, 18 insertions(+), 43 deletions(-)

diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index 0776a11e7e11..ac6d7e76c0d4 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -215,46 +215,21 @@ do {  
\
  * expensive due to the implied lock prefix.  The processor cannot prefetch
  * cachelines if xchg is used.
  */
-#define percpu_xchg_op(qual, var, nval)
\
+#define percpu_xchg_op(size, qual, _var, _nval)
\
 ({ \
-   typeof(var) pxo_ret__;  \
-   typeof(var) pxo_new__ = (nval); \
-   switch (sizeof(var)) {  \
-   case 1: \
-   asm qual ("\n\tmov "__percpu_arg(1)",%%al"  \
-   "\n1:\tcmpxchgb %2, "__percpu_arg(1)\
-   "\n\tjnz 1b"\
-   : "=" (pxo_ret__), "+m" (var) \
-   : "q" (pxo_new__)   \
-   : "memory");\
-   break;  \
-   case 2: \
-   asm qual ("\n\tmov "__percpu_arg(1)",%%ax"  \
-   "\n1:\tcmpxchgw %2, "__percpu_arg(1)\
-   "\n\tjnz 1b"\
-   : "=" (pxo_ret__), "+m" (var) \
-   : "r" (pxo_new__)   \
-   : "memory");\
-   break;  \
-   case 4: \
-   asm qual ("\n\tmov "__percpu_arg(1)",%%eax" \
-   "\n1:\tcmpxchgl %2, "__percpu_arg(1)\
-   "\n\tjnz 1b"\
-   : "=" (pxo_ret__), "+m" (var) \
-   : "r" (pxo_new__)   \
-   : "memory");\
-   break;  \
-   case 8: \
-   asm qual ("\n\tmov "__percpu_arg(1)",%%rax" \
-   "\n1:\tcmpxchgq %2, "__percpu_arg(1)\
-   "\n\tjnz 1b"\
-   : "=" (pxo_ret__), "+m" (var) \
-   : "r" (pxo_new__)   \
-   : "memory");\
-   break;  \
-   default: __bad_percpu_size();   \
-   }   \
-   pxo_ret__;  \
+   __pcpu_type_##size pxo_old__;   \
+   __pcpu_type_##size pxo_new__ = __pcpu_cast_##size(_nval);   \
+   asm qual (__pcpu_op2_##size("mov", __percpu_arg([var]), \
+   "%[oval]")  \
+ "\n1:\t"  \
+ __pcpu_op2_##size("cmpxchg", "%[nval]",   \
+   __percpu_arg([var]))\
+ "\n\tjnz 1b"  \
+ : [oval] "=" (pxo_old__),   \
+   [var] "+m" (_var)   \
+ : [nval] __pcpu_reg_##size(, pxo_new__)   \
+ : "memory");  \
+   (typeof(_var))(unsigned long) pxo_old__;\
 })
 
 /*
@@ -354,9 +329,9 @@ do {
\
 #define this_cpu_or_1(pcp, val)

[PATCH v2 09/10] x86/percpu: Clean up percpu_stable_op()

2020-05-30 Thread Brian Gerst
Use __pcpu_size_call_return() to simplify this_cpu_read_stable().
Also remove __bad_percpu_size() which is now unused.

Signed-off-by: Brian Gerst 
---
 arch/x86/include/asm/percpu.h | 41 ++-
 1 file changed, 12 insertions(+), 29 deletions(-)

diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index 7efc0b5c4ff0..cf2b9c2a241e 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -85,7 +85,6 @@
 
 /* For arch-specific code, we can use direct single-insn ops (they
  * don't give an lvalue though). */
-extern void __bad_percpu_size(void);
 
 #define __pcpu_type_1 u8
 #define __pcpu_type_2 u16
@@ -167,33 +166,13 @@ do {  
\
(typeof(_var))(unsigned long) pfo_val__;\
 })
 
-#define percpu_stable_op(op, var)  \
-({ \
-   typeof(var) pfo_ret__;  \
-   switch (sizeof(var)) {  \
-   case 1: \
-   asm(op "b "__percpu_arg(P1)",%0"\
-   : "=q" (pfo_ret__)  \
-   : "p" (&(var)));\
-   break;  \
-   case 2: \
-   asm(op "w "__percpu_arg(P1)",%0"\
-   : "=r" (pfo_ret__)  \
-   : "p" (&(var)));\
-   break;  \
-   case 4: \
-   asm(op "l "__percpu_arg(P1)",%0"\
-   : "=r" (pfo_ret__)  \
-   : "p" (&(var)));\
-   break;  \
-   case 8: \
-   asm(op "q "__percpu_arg(P1)",%0"\
-   : "=r" (pfo_ret__)  \
-   : "p" (&(var)));\
-   break;  \
-   default: __bad_percpu_size();   \
-   }   \
-   pfo_ret__;  \
+#define percpu_stable_op(size, op, _var)   \
+({ \
+   __pcpu_type_##size pfo_val__;   \
+   asm(__pcpu_op2_##size(op, __percpu_arg(P[var]), "%[val]")   \
+   : [val] __pcpu_reg_##size("=", pfo_val__)   \
+   : [var] "p" (&(_var))); \
+   (typeof(_var))(unsigned long) pfo_val__;\
 })
 
 /*
@@ -258,7 +237,11 @@ do {   
\
  * per-thread variables implemented as per-cpu variables and thus
  * stable for the duration of the respective task.
  */
-#define this_cpu_read_stable(var)  percpu_stable_op("mov", var)
+#define this_cpu_read_stable_1(pcp)percpu_stable_op(1, "mov", pcp)
+#define this_cpu_read_stable_2(pcp)percpu_stable_op(2, "mov", pcp)
+#define this_cpu_read_stable_4(pcp)percpu_stable_op(4, "mov", pcp)
+#define this_cpu_read_stable_8(pcp)percpu_stable_op(8, "mov", pcp)
+#define this_cpu_read_stable(pcp)  
__pcpu_size_call_return(this_cpu_read_stable_, pcp)
 
 #define raw_cpu_read_1(pcp)percpu_from_op(1, , "mov", pcp)
 #define raw_cpu_read_2(pcp)percpu_from_op(2, , "mov", pcp)
-- 
2.25.4



[PATCH v2 05/10] x86/percpu: Remove "e" constraint from XADD

2020-05-30 Thread Brian Gerst
The "e" constraint represents a constant, but the XADD instruction doesn't
accept immediate operands.

Signed-off-by: Brian Gerst 
---
 arch/x86/include/asm/percpu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index 2a24f3c795eb..9bb5440d98d3 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -220,7 +220,7 @@ do {
\
break;  \
case 8: \
asm qual ("xaddq %0, "__percpu_arg(1)   \
-   : "+re" (paro_ret__), "+m" (var)\
+   : "+r" (paro_ret__), "+m" (var) \
: : "memory");  \
break;  \
default: __bad_percpu_size();   \
-- 
2.25.4



[PATCH v2 03/10] x86/percpu: Clean up percpu_from_op()

2020-05-30 Thread Brian Gerst
The core percpu macros already have a switch on the data size, so the switch
in the x86 code is redundant and produces more dead code.

Also use appropriate types for the width of the instructions.  This avoids
errors when compiling with Clang.

Signed-off-by: Brian Gerst 
Reviewed-by: Nick Desaulniers 
---
 arch/x86/include/asm/percpu.h | 50 +++
 1 file changed, 15 insertions(+), 35 deletions(-)

diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index fb280fba94c5..a40d2e055f58 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -190,33 +190,13 @@ do {  
\
}   \
 } while (0)
 
-#define percpu_from_op(qual, op, var)  \
-({ \
-   typeof(var) pfo_ret__;  \
-   switch (sizeof(var)) {  \
-   case 1: \
-   asm qual (op "b "__percpu_arg(1)",%0"   \
-   : "=q" (pfo_ret__)  \
-   : "m" (var));   \
-   break;  \
-   case 2: \
-   asm qual (op "w "__percpu_arg(1)",%0"   \
-   : "=r" (pfo_ret__)  \
-   : "m" (var));   \
-   break;  \
-   case 4: \
-   asm qual (op "l "__percpu_arg(1)",%0"   \
-   : "=r" (pfo_ret__)  \
-   : "m" (var));   \
-   break;  \
-   case 8: \
-   asm qual (op "q "__percpu_arg(1)",%0"   \
-   : "=r" (pfo_ret__)  \
-   : "m" (var));   \
-   break;  \
-   default: __bad_percpu_size();   \
-   }   \
-   pfo_ret__;  \
+#define percpu_from_op(size, qual, op, _var)   \
+({ \
+   __pcpu_type_##size pfo_val__;   \
+   asm qual (__pcpu_op2_##size(op, __percpu_arg([var]), "%[val]")  \
+   : [val] __pcpu_reg_##size("=", pfo_val__)   \
+   : [var] "m" (_var));\
+   (typeof(_var))(unsigned long) pfo_val__;\
 })
 
 #define percpu_stable_op(op, var)  \
@@ -401,9 +381,9 @@ do {
\
  */
 #define this_cpu_read_stable(var)  percpu_stable_op("mov", var)
 
-#define raw_cpu_read_1(pcp)percpu_from_op(, "mov", pcp)
-#define raw_cpu_read_2(pcp)percpu_from_op(, "mov", pcp)
-#define raw_cpu_read_4(pcp)percpu_from_op(, "mov", pcp)
+#define raw_cpu_read_1(pcp)percpu_from_op(1, , "mov", pcp)
+#define raw_cpu_read_2(pcp)percpu_from_op(2, , "mov", pcp)
+#define raw_cpu_read_4(pcp)percpu_from_op(4, , "mov", pcp)
 
 #define raw_cpu_write_1(pcp, val)  percpu_to_op(1, , "mov", (pcp), val)
 #define raw_cpu_write_2(pcp, val)  percpu_to_op(2, , "mov", (pcp), val)
@@ -433,9 +413,9 @@ do {
\
 #define raw_cpu_xchg_2(pcp, val)   raw_percpu_xchg_op(pcp, val)
 #define raw_cpu_xchg_4(pcp, val)   raw_percpu_xchg_op(pcp, val)
 
-#define this_cpu_read_1(pcp)   percpu_from_op(volatile, "mov", pcp)
-#define this_cpu_read_2(pcp)   percpu_from_op(volatile, "mov", pcp)
-#define this_cpu_read_4(pcp)   percpu_from_op(volatile, "mov", pcp)
+#define this_cpu_read_1(pcp)   percpu_from_op(1, volatile, "mov", pcp)
+#define this_cpu_read_2(pcp)   percpu_from_op(2, volatile, "mov", pcp)
+#define this_cpu_read_4(pcp)   percpu_from_op(4, volatile, "mov", pcp)
 #define this_cpu_write_1(pcp, val) percpu_to_op(1, volatile, "mov", (pcp), 
val)
 #define this_cpu_write_2(pcp, val) percpu_to_op(2, volatile, "mov", (pcp), 
val)
 #define this_cpu_write_4(pcp, val) percpu_to_op(4, volatile, "mov", (pcp), 
val)
@@ -488,7 +468,7 @@ do {
\
  * 32 bit must fall back to generic operations.
  */
 #ifdef CONFIG_X86_64
-#define raw_cpu_read_8(pcp)percpu_from_op(, "mov", pcp)
+#define raw_cpu_read_8(pcp)percpu_from_op(8, , 

[PATCH v2 00/10] x86: Clean up percpu operations

2020-05-30 Thread Brian Gerst
The core percpu operations already have a switch on the width of the
data type, which resulted in an extra amount of dead code being
generated with the x86 operations having another switch.  This patch set
rewrites the x86 ops to remove the switch.  Additional cleanups are to
use named assembly operands, and to cast variables to the width used in
the assembly to make Clang happy.

Changes from v1:
- Add separate patch for XADD constraint fix
- Fixed sparse truncation warning
- Add cleanup of percpu_stable_op()
- Add patch to Remove PER_CPU()

Brian Gerst (10):
  x86/percpu: Introduce size abstraction macros
  x86/percpu: Clean up percpu_to_op()
  x86/percpu: Clean up percpu_from_op()
  x86/percpu: Clean up percpu_add_op()
  x86/percpu: Remove "e" constraint from XADD
  x86/percpu: Clean up percpu_add_return_op()
  x86/percpu: Clean up percpu_xchg_op()
  x86/percpu: Clean up percpu_cmpxchg_op()
  x86/percpu: Clean up percpu_stable_op()
  x86/percpu: Remove unused PER_CPU() macro

 arch/x86/include/asm/percpu.h | 510 --
 1 file changed, 172 insertions(+), 338 deletions(-)


base-commit: 229aaa8c059f2c908e0561453509f996f2b2d5c4
-- 
2.25.4



[PATCH v2 04/10] x86/percpu: Clean up percpu_add_op()

2020-05-30 Thread Brian Gerst
The core percpu macros already have a switch on the data size, so the switch
in the x86 code is redundant and produces more dead code.

Also use appropriate types for the width of the instructions.  This avoids
errors when compiling with Clang.

Signed-off-by: Brian Gerst 
---
 arch/x86/include/asm/percpu.h | 99 ---
 1 file changed, 22 insertions(+), 77 deletions(-)

diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index a40d2e055f58..2a24f3c795eb 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -130,64 +130,32 @@ do {  
\
: [val] __pcpu_reg_imm_##size(pto_val__));  \
 } while (0)
 
+#define percpu_unary_op(size, qual, op, _var)  \
+({ \
+   asm qual (__pcpu_op1_##size(op, __percpu_arg([var]))\
+   : [var] "+m" (_var));   \
+})
+
 /*
  * Generate a percpu add to memory instruction and optimize code
  * if one is added or subtracted.
  */
-#define percpu_add_op(qual, var, val)  \
+#define percpu_add_op(size, qual, var, val)\
 do {   \
-   typedef typeof(var) pao_T__;\
const int pao_ID__ = (__builtin_constant_p(val) &&  \
  ((val) == 1 || (val) == -1)) ?\
(int)(val) : 0; \
if (0) {\
-   pao_T__ pao_tmp__;  \
+   typeof(var) pao_tmp__;  \
pao_tmp__ = (val);  \
(void)pao_tmp__;\
}   \
-   switch (sizeof(var)) {  \
-   case 1: \
-   if (pao_ID__ == 1)  \
-   asm qual ("incb "__percpu_arg(0) : "+m" (var)); \
-   else if (pao_ID__ == -1)\
-   asm qual ("decb "__percpu_arg(0) : "+m" (var)); \
-   else\
-   asm qual ("addb %1, "__percpu_arg(0)\
-   : "+m" (var)\
-   : "qi" ((pao_T__)(val)));   \
-   break;  \
-   case 2: \
-   if (pao_ID__ == 1)  \
-   asm qual ("incw "__percpu_arg(0) : "+m" (var)); \
-   else if (pao_ID__ == -1)\
-   asm qual ("decw "__percpu_arg(0) : "+m" (var)); \
-   else\
-   asm qual ("addw %1, "__percpu_arg(0)\
-   : "+m" (var)\
-   : "ri" ((pao_T__)(val)));   \
-   break;  \
-   case 4: \
-   if (pao_ID__ == 1)  \
-   asm qual ("incl "__percpu_arg(0) : "+m" (var)); \
-   else if (pao_ID__ == -1)\
-   asm qual ("decl "__percpu_arg(0) : "+m" (var)); \
-   else\
-   asm qual ("addl %1, "__percpu_arg(0)\
-   : "+m" (var)\
-   : "ri" ((pao_T__)(val)));   \
-   break;  \
-   case 8: \
-   if (pao_ID__ == 1)  \
-   asm qual ("incq "__percpu_arg(0) : "+m" (var)); \
-   else if (pao_ID__ == -1)\
-   asm qual ("decq "__percpu_arg(0) : "+m" (var)); \
-   else\
-   asm qual ("addq %1, "__percpu_arg(0)\
-   : "+m" 

[PATCH v2 06/10] x86/percpu: Clean up percpu_add_return_op()

2020-05-30 Thread Brian Gerst
The core percpu macros already have a switch on the data size, so the switch
in the x86 code is redundant and produces more dead code.

Also use appropriate types for the width of the instructions.  This avoids
errors when compiling with Clang.

Signed-off-by: Brian Gerst 
---
 arch/x86/include/asm/percpu.h | 51 +++
 1 file changed, 16 insertions(+), 35 deletions(-)

diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index 9bb5440d98d3..0776a11e7e11 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -199,34 +199,15 @@ do {  
\
 /*
  * Add return operation
  */
-#define percpu_add_return_op(qual, var, val)   \
+#define percpu_add_return_op(size, qual, _var, _val)   \
 ({ \
-   typeof(var) paro_ret__ = val;   \
-   switch (sizeof(var)) {  \
-   case 1: \
-   asm qual ("xaddb %0, "__percpu_arg(1)   \
-   : "+q" (paro_ret__), "+m" (var) \
-   : : "memory");  \
-   break;  \
-   case 2: \
-   asm qual ("xaddw %0, "__percpu_arg(1)   \
-   : "+r" (paro_ret__), "+m" (var) \
-   : : "memory");  \
-   break;  \
-   case 4: \
-   asm qual ("xaddl %0, "__percpu_arg(1)   \
-   : "+r" (paro_ret__), "+m" (var) \
-   : : "memory");  \
-   break;  \
-   case 8: \
-   asm qual ("xaddq %0, "__percpu_arg(1)   \
-   : "+r" (paro_ret__), "+m" (var) \
-   : : "memory");  \
-   break;  \
-   default: __bad_percpu_size();   \
-   }   \
-   paro_ret__ += val;  \
-   paro_ret__; \
+   __pcpu_type_##size paro_tmp__ = __pcpu_cast_##size(_val);   \
+   asm qual (__pcpu_op2_##size("xadd", "%[tmp]",   \
+__percpu_arg([var]))   \
+ : [tmp] __pcpu_reg_##size("+", paro_tmp__),   \
+   [var] "+m" (_var)   \
+ : : "memory");\
+   (typeof(_var))(unsigned long) (paro_tmp__ + _val);  \
 })
 
 /*
@@ -377,16 +358,16 @@ do {  
\
 #define this_cpu_xchg_2(pcp, nval) percpu_xchg_op(volatile, pcp, nval)
 #define this_cpu_xchg_4(pcp, nval) percpu_xchg_op(volatile, pcp, nval)
 
-#define raw_cpu_add_return_1(pcp, val) percpu_add_return_op(, pcp, val)
-#define raw_cpu_add_return_2(pcp, val) percpu_add_return_op(, pcp, val)
-#define raw_cpu_add_return_4(pcp, val) percpu_add_return_op(, pcp, val)
+#define raw_cpu_add_return_1(pcp, val) percpu_add_return_op(1, , pcp, 
val)
+#define raw_cpu_add_return_2(pcp, val) percpu_add_return_op(2, , pcp, 
val)
+#define raw_cpu_add_return_4(pcp, val) percpu_add_return_op(4, , pcp, 
val)
 #define raw_cpu_cmpxchg_1(pcp, oval, nval) percpu_cmpxchg_op(, pcp, oval, 
nval)
 #define raw_cpu_cmpxchg_2(pcp, oval, nval) percpu_cmpxchg_op(, pcp, oval, 
nval)
 #define raw_cpu_cmpxchg_4(pcp, oval, nval) percpu_cmpxchg_op(, pcp, oval, 
nval)
 
-#define this_cpu_add_return_1(pcp, val)
percpu_add_return_op(volatile, pcp, val)
-#define this_cpu_add_return_2(pcp, val)
percpu_add_return_op(volatile, pcp, val)
-#define this_cpu_add_return_4(pcp, val)
percpu_add_return_op(volatile, pcp, val)
+#define this_cpu_add_return_1(pcp, val)percpu_add_return_op(1, 
volatile, pcp, val)
+#define this_cpu_add_return_2(pcp, val)percpu_add_return_op(2, 
volatile, pcp, val)
+#define this_cpu_add_return_4(pcp, val)percpu_add_return_op(4, 
volatile, pcp, 

[PATCH v2 01/10] x86/percpu: Introduce size abstraction macros

2020-05-30 Thread Brian Gerst
In preparation for cleaning up the percpu operations, define macros for
abstraction based on the width of the operation.

Signed-off-by: Brian Gerst 
---
 arch/x86/include/asm/percpu.h | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index 2278797c769d..19838e4f7a8f 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -87,6 +87,36 @@
  * don't give an lvalue though). */
 extern void __bad_percpu_size(void);
 
+#define __pcpu_type_1 u8
+#define __pcpu_type_2 u16
+#define __pcpu_type_4 u32
+#define __pcpu_type_8 u64
+
+#define __pcpu_cast_1(val) ((u8)(((unsigned long) val) & 0xff))
+#define __pcpu_cast_2(val) ((u16)(((unsigned long) val) & 0x))
+#define __pcpu_cast_4(val) ((u32)(((unsigned long) val) & 0x))
+#define __pcpu_cast_8(val) ((u64)(val))
+
+#define __pcpu_op1_1(op, dst) op "b " dst
+#define __pcpu_op1_2(op, dst) op "w " dst
+#define __pcpu_op1_4(op, dst) op "l " dst
+#define __pcpu_op1_8(op, dst) op "q " dst
+
+#define __pcpu_op2_1(op, src, dst) op "b " src ", " dst
+#define __pcpu_op2_2(op, src, dst) op "w " src ", " dst
+#define __pcpu_op2_4(op, src, dst) op "l " src ", " dst
+#define __pcpu_op2_8(op, src, dst) op "q " src ", " dst
+
+#define __pcpu_reg_1(mod, x) mod "q" (x)
+#define __pcpu_reg_2(mod, x) mod "r" (x)
+#define __pcpu_reg_4(mod, x) mod "r" (x)
+#define __pcpu_reg_8(mod, x) mod "r" (x)
+
+#define __pcpu_reg_imm_1(x) "qi" (x)
+#define __pcpu_reg_imm_2(x) "ri" (x)
+#define __pcpu_reg_imm_4(x) "ri" (x)
+#define __pcpu_reg_imm_8(x) "re" (x)
+
 #define percpu_to_op(qual, op, var, val)   \
 do {   \
typedef typeof(var) pto_T__;\
-- 
2.25.4



Re: [PATCH RFC] seccomp: Implement syscall isolation based on memory areas

2020-05-30 Thread Andy Lutomirski



> On May 29, 2020, at 11:00 PM, Gabriel Krisman Bertazi  
> wrote:
> 
> Modern Windows applications are executing system call instructions
> directly from the application's code without going through the WinAPI.
> This breaks Wine emulation, because it doesn't have a chance to
> intercept and emulate these syscalls before they are submitted to Linux.
> 
> In addition, we cannot simply trap every system call of the application
> to userspace using PTRACE_SYSEMU, because performance would suffer,
> since our main use case is to run Windows games over Linux.  Therefore,
> we need some in-kernel filtering to decide whether the syscall was
> issued by the wine code or by the windows application.

Do you really need in-kernel filtering?  What if you could have efficient 
userspace filtering instead?  That is, set something up so that all syscalls, 
except those from a special address, are translated to CALL thunk where the 
thunk is configured per task.  Then the thunk can do whatever emulation is 
needed.

Getting the details and especially the interaction with any seccomp filters 
that may be installed right could be tricky, but the performance should be 
decent, at least on non-PTI systems.

(If we go this route, I suspect that the correct interaction with seccomp is 
that this type of redirection takes precedence over seccomp and seccomp filters 
are not invoked for redirected syscalls. After all, a redirected syscall is, 
functionally, not a syscall at all.)

> 


Re: [PATCH] lib: make a test module with get_count_order/long

2020-05-30 Thread Andy Shevchenko
On Sun, May 31, 2020 at 12:23 AM Wei Yang  wrote:
> On Sat, May 30, 2020 at 01:25:31PM +0300, Andy Shevchenko wrote:
> >On Sat, May 30, 2020 at 12:43:28AM +, Wei Yang wrote:
> >> A test module to make sure get_count_order/long returns the correct result.
> >
> >>  lib/Kconfig.debug  | 13 ++
> >>  lib/Makefile   |  2 +
> >>  lib/test_getorder.c| 64 ++
> >
> >I didn't get why it's not a part of test_bitops?
> >
>
> I see the document of test_bitops says it does exercise on clear_bit and
> set_bit. So not sure it is proper to put them together.

It's not a problem to amend a documentation as well :-)

-- 
With Best Regards,
Andy Shevchenko


arch/mips/sgi-ip27/ip27-hubio.c:30:15: warning: no previous prototype for 'hub_pio_map'

2020-05-30 Thread kbuild test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   86852175b016f0c6873dcbc24b93d12b7b246612
commit: b78e9d63a3b6307b6b786e6ba189d3978b60ceb5 MIPS: SGI-IP27: use 
asm/sn/agent.h for including HUB related stuff
date:   5 months ago
config: mips-ip27_defconfig (attached as .config)
compiler: mips64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
git checkout b78e9d63a3b6307b6b786e6ba189d3978b60ceb5
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross 
ARCH=mips 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot 

All warnings (new ones prefixed by >>, old ones prefixed by <<):

>> arch/mips/sgi-ip27/ip27-hubio.c:30:15: warning: no previous prototype for 
>> 'hub_pio_map' [-Wmissing-prototypes]
30 | unsigned long hub_pio_map(nasid_t nasid, xwidgetnum_t widget,
|   ^~~
>> arch/mips/sgi-ip27/ip27-hubio.c:175:6: warning: no previous prototype for 
>> 'hub_pio_init' [-Wmissing-prototypes]
175 | void hub_pio_init(nasid_t nasid)
|  ^~~~

vim +/hub_pio_map +30 arch/mips/sgi-ip27/ip27-hubio.c

^1da177e4c3f41 Linus Torvalds  2005-04-16   20  
^1da177e4c3f41 Linus Torvalds  2005-04-16   21  /**
^1da177e4c3f41 Linus Torvalds  2005-04-16   22   * hub_pio_map  -  
establish a HUB PIO mapping
^1da177e4c3f41 Linus Torvalds  2005-04-16   23   *
^1da177e4c3f41 Linus Torvalds  2005-04-16   24   * @hub:hub to perform 
PIO mapping on
^1da177e4c3f41 Linus Torvalds  2005-04-16   25   * @widget: widget ID to 
perform PIO mapping for
^1da177e4c3f41 Linus Torvalds  2005-04-16   26   * @xtalk_addr: 
xtalk_address that needs to be mapped
^1da177e4c3f41 Linus Torvalds  2005-04-16   27   * @size:   size of the PIO 
mapping
^1da177e4c3f41 Linus Torvalds  2005-04-16   28   *
^1da177e4c3f41 Linus Torvalds  2005-04-16   29   **/
4bf841ebf17aaa Thomas Bogendoerfer 2019-10-03  @30  unsigned long 
hub_pio_map(nasid_t nasid, xwidgetnum_t widget,
^1da177e4c3f41 Linus Torvalds  2005-04-16   31
unsigned long xtalk_addr, size_t size)
^1da177e4c3f41 Linus Torvalds  2005-04-16   32  {
^1da177e4c3f41 Linus Torvalds  2005-04-16   33  unsigned i;
^1da177e4c3f41 Linus Torvalds  2005-04-16   34  
^1da177e4c3f41 Linus Torvalds  2005-04-16   35  /* use small-window 
mapping if possible */
^1da177e4c3f41 Linus Torvalds  2005-04-16   36  if ((xtalk_addr % 
SWIN_SIZE) + size <= SWIN_SIZE)
^1da177e4c3f41 Linus Torvalds  2005-04-16   37  return 
NODE_SWIN_BASE(nasid, widget) + (xtalk_addr % SWIN_SIZE);
^1da177e4c3f41 Linus Torvalds  2005-04-16   38  
^1da177e4c3f41 Linus Torvalds  2005-04-16   39  if ((xtalk_addr % 
BWIN_SIZE) + size > BWIN_SIZE) {
^1da177e4c3f41 Linus Torvalds  2005-04-16   40  
printk(KERN_WARNING "PIO mapping at hub %d widget %d addr 0x%lx"
^1da177e4c3f41 Linus Torvalds  2005-04-16   41  
" too big (%ld)\n",
^1da177e4c3f41 Linus Torvalds  2005-04-16   42  
nasid, widget, xtalk_addr, size);
^1da177e4c3f41 Linus Torvalds  2005-04-16   43  return 0;
^1da177e4c3f41 Linus Torvalds  2005-04-16   44  }
^1da177e4c3f41 Linus Torvalds  2005-04-16   45  
^1da177e4c3f41 Linus Torvalds  2005-04-16   46  xtalk_addr &= 
~(BWIN_SIZE-1);
^1da177e4c3f41 Linus Torvalds  2005-04-16   47  for (i = 0; i < 
HUB_NUM_BIG_WINDOW; i++) {
4bf841ebf17aaa Thomas Bogendoerfer 2019-10-03   48  if 
(test_and_set_bit(i, hub_data(nasid)->h_bigwin_used))
^1da177e4c3f41 Linus Torvalds  2005-04-16   49  
continue;
^1da177e4c3f41 Linus Torvalds  2005-04-16   50  
^1da177e4c3f41 Linus Torvalds  2005-04-16   51  /*
^1da177e4c3f41 Linus Torvalds  2005-04-16   52   * The code 
below does a PIO write to setup an ITTE entry.
^1da177e4c3f41 Linus Torvalds  2005-04-16   53   *
^1da177e4c3f41 Linus Torvalds  2005-04-16   54   * We need to 
prevent other CPUs from seeing our updated
^1da177e4c3f41 Linus Torvalds  2005-04-16   55   * memory 
shadow of the ITTE (in the piomap) until the ITTE
^1da177e4c3f41 Linus Torvalds  2005-04-16   56   * entry is 
actually set up; otherwise, another CPU might
^1da177e4c3f41 Linus Torvalds  2005-04-16   57   * attempt a 
PIO prematurely.
^1da177e4c3f41 Linus Torvalds  2005-04-16   58   *
^1da177e4c3f41 Linus Torvalds  2005-04-16   59   * Also, the 
only way we can know that an entry has been
^1da177e4c3f41 Linus Torvalds  2005-04-16   60   * received  by 
the hub 

Re: [PATCH] cifs: Standardize logging output

2020-05-30 Thread Steve French
tentatively merged into cifs-2.6.git for-next but had to clean it up
to avoid merge conflicts.

Minor followon patch (attached) to add the two remaining ones that Joe
pointed out that.

On Wed, Apr 15, 2020 at 12:46 AM Joe Perches via samba-technical
 wrote:
>
> Use pr_fmt to standardize all logging for fs/cifs.
>
> Some logging output had no CIFS: specific prefix.
>
> Now all output has one of three prefixes:
>
> o CIFS:
> o CIFS: VFS:
> o Root-CIFS:
>
> Miscellanea:
>
> o Convert printks to pr_
> o Neaten macro definitions
> o Remove embedded CIFS: prefixes from formats
> o Convert "illegal" to "invalid"
> o Coalesce formats
> o Add missing '\n' format terminations
> o Consolidate multiple cifs_dbg continuations into single calls
> o More consistent use of upper case first word output logging
> o Multiline statement argument alignment and wrapping
>
> Signed-off-by: Joe Perches 
> ---
>  fs/cifs/cifs_debug.h  | 145 ++---
>  fs/cifs/cifsencrypt.c |   8 +-
>  fs/cifs/cifsproto.h   |  26 +++
>  fs/cifs/cifsroot.c|   6 +-
>  fs/cifs/cifssmb.c |  26 +++
>  fs/cifs/connect.c |  77 
>  fs/cifs/dfs_cache.c   |  14 ++--
>  fs/cifs/file.c|  24 +++---
>  fs/cifs/inode.c   |   4 +-
>  fs/cifs/misc.c|  12 +--
>  fs/cifs/netmisc.c |   6 +-
>  fs/cifs/readdir.c |  10 +--
>  fs/cifs/sess.c|  28 +++
>  fs/cifs/smb1ops.c |   2 +-
>  fs/cifs/smb2inode.c   |   3 +-
>  fs/cifs/smb2misc.c|  20 ++---
>  fs/cifs/smb2ops.c |  31 
>  fs/cifs/smb2pdu.c |  72 +-
>  fs/cifs/smbdirect.c   | 165 +-
>  fs/cifs/transport.c   |  25 +++
>  20 files changed, 321 insertions(+), 383 deletions(-)
>
> diff --git a/fs/cifs/cifs_debug.h b/fs/cifs/cifs_debug.h
> index 100b00..5e66da 100644
> --- a/fs/cifs/cifs_debug.h
> +++ b/fs/cifs/cifs_debug.h
> @@ -8,6 +8,12 @@
>  #ifndef _H_CIFS_DEBUG
>  #define _H_CIFS_DEBUG
>
> +#ifdef pr_fmt
> +#undef pr_fmt
> +#endif
> +
> +#define pr_fmt(fmt) "CIFS: " fmt
> +
>  void cifs_dump_mem(char *label, void *data, int length);
>  void cifs_dump_detail(void *buf, struct TCP_Server_Info *ptcp_info);
>  void cifs_dump_mids(struct TCP_Server_Info *);
> @@ -46,92 +52,81 @@ extern int cifsFYI;
>   */
>
>  /* Information level messages, minor events */
> -#define cifs_info_func(ratefunc, fmt, ...) \
> -do {   \
> -   pr_info_ ## ratefunc("CIFS: " fmt, ##__VA_ARGS__);  \
> -} while (0)
> +#define cifs_info_func(ratefunc, fmt, ...) \
> +   pr_info_ ## ratefunc(fmt, ##__VA_ARGS__)
>
> -#define cifs_info(fmt, ...)\
> -do {   \
> -   cifs_info_func(ratelimited, fmt, ##__VA_ARGS__);\
> -} while (0)
> +#define cifs_info(fmt, ...)\
> +   cifs_info_func(ratelimited, fmt, ##__VA_ARGS__)
>
>  /* information message: e.g., configuration, major event */
> -#define cifs_dbg_func(ratefunc, type, fmt, ...)\
> -do {   \
> -   if ((type) & FYI && cifsFYI & CIFS_INFO) {  \
> -   pr_debug_ ## ratefunc("%s: "\
> -   fmt, __FILE__, ##__VA_ARGS__);  \
> -   } else if ((type) & VFS) {  \
> -   pr_err_ ## ratefunc("CIFS VFS: "\
> -fmt, ##__VA_ARGS__);   \
> -   } else if ((type) & NOISY && (NOISY != 0)) {\
> -   pr_debug_ ## ratefunc(fmt, ##__VA_ARGS__);  \
> -   }   \
> +#define cifs_dbg_func(ratefunc, type, fmt, ...)  
>   \
> +do {   \
> +   if ((type) & FYI && cifsFYI & CIFS_INFO) {  \
> +   pr_debug_ ## ratefunc("%s: " fmt,   \
> + __FILE__, ##__VA_ARGS__); \
> +   } else if ((type) & VFS) {  \
> +   pr_err_ ## ratefunc("VFS: " fmt, ##__VA_ARGS__);\
> +   } else if ((type) & NOISY && (NOISY != 0)) {\
> +   pr_debug_ ## ratefunc(fmt, ##__VA_ARGS__);  \
> +   }   \
>  } while (0)
>
> -#define cifs_dbg(type, fmt, ...) \
> -do {   \
> -   if ((type) & ONCE)  \
> -   cifs_dbg_func(once, \
> -type, fmt, ##__VA_ARGS__); \
> -   else   

[PATCH stable-4.19.y] net: phy: reschedule state machine if AN has not completed in PHY_AN state

2020-05-30 Thread Vladimir Oltean
From: Vladimir Oltean 

In kernel 4.19 (and probably earlier too) there are issues surrounding
the PHY_AN state.

For example, if a PHY is in PHY_AN state and AN has not finished, then
what is supposed to happen is that the state machine gets rescheduled
until it is, or until the link_timeout reaches zero which triggers an
autoneg restart process.

But actually the rescheduling never works if the PHY uses interrupts,
because the condition under which rescheduling occurs is just if
phy_polling_mode() is true. So basically, this whole rescheduling
functionality works for AN-not-yet-complete just by mistake. Let me
explain.

Most of the time the AN process manages to finish by the time the
interrupt has triggered. One might say "that should always be the case,
otherwise the PHY wouldn't raise the interrupt, right?".
Well, some PHYs implement an .aneg_done method which allows them to tell
the state machine when the AN is really complete.
The AR8031/AR8033 driver (at803x.c) is one such example. Even when
copper autoneg completes, the driver still keeps the "aneg_done"
variable unset until in-band SGMII autoneg finishes too (there is no
interrupt for that). So we have the premises of a race condition.

In practice, what really happens depends on the log level of the serial
console. If the log level is verbose enough that kernel messages related
to the Ethernet link state are printed to the console, then this gives
in-band AN enough time to complete, which means the link will come up
and everyone will be happy. But if the console is not that verbose, the
link will sometimes come up, and sometimes will be forced down by the
.aneg_done of the PHY driver (forever, since we are not rescheduling).

The conclusion is that an extra condition needs to be explicitly added,
so that the state machine can be rescheduled properly. Otherwise PHY
devices in interrupt mode will never work properly if they have an
.aneg_done callback.

In more recent kernels, the whole PHY_AN state was removed by Heiner
Kallweit in the "[net-next,0/5] net: phy: improve and simplify phylib
state machine" series here:

https://patchwork.ozlabs.org/cover/994464/

and the problem was just masked away instead of being addressed with a
punctual patch.

Fixes: 76a423a3f8f1 ("net: phy: allow driver to implement their own aneg_done")
Signed-off-by: Vladimir Oltean 
---
I'm not sure the procedure I'm following is correct, sending this
directly to Greg. The patch doesn't apply on net.

 drivers/net/phy/phy.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index cc454b8c032c..ca4fd74fd2c8 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -934,7 +934,7 @@ void phy_state_machine(struct work_struct *work)
struct delayed_work *dwork = to_delayed_work(work);
struct phy_device *phydev =
container_of(dwork, struct phy_device, state_queue);
-   bool needs_aneg = false, do_suspend = false;
+   bool recheck = false, needs_aneg = false, do_suspend = false;
enum phy_state old_state;
int err = 0;
int old_link;
@@ -981,6 +981,8 @@ void phy_state_machine(struct work_struct *work)
phy_link_up(phydev);
} else if (0 == phydev->link_timeout--)
needs_aneg = true;
+   else
+   recheck = true;
break;
case PHY_NOLINK:
if (!phy_polling_mode(phydev))
@@ -1123,7 +1125,7 @@ void phy_state_machine(struct work_struct *work)
 * PHY, if PHY_IGNORE_INTERRUPT is set, then we will be moving
 * between states from phy_mac_interrupt()
 */
-   if (phy_polling_mode(phydev))
+   if (phy_polling_mode(phydev) || recheck)
queue_delayed_work(system_power_efficient_wq, 
>state_queue,
   PHY_STATE_TIME * HZ);
 }
-- 
2.25.1



[PATCH v2 3/4] iio: chemical: scd30: add serial interface driver

2020-05-30 Thread Tomasz Duszynski
Add serial interface driver for the SCD30 sensor.

Signed-off-by: Tomasz Duszynski 
---
 MAINTAINERS |   1 +
 drivers/iio/chemical/Kconfig|  11 ++
 drivers/iio/chemical/Makefile   |   1 +
 drivers/iio/chemical/scd30_serial.c | 266 
 4 files changed, 279 insertions(+)
 create mode 100644 drivers/iio/chemical/scd30_serial.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 13aed3473b7e..5db4b446c8ba 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -15143,6 +15143,7 @@ S:  Maintained
 F: drivers/iio/chemical/scd30.h
 F: drivers/iio/chemical/scd30_core.c
 F: drivers/iio/chemical/scd30_i2c.c
+F: drivers/iio/chemical/scd30_serial.c
 
 SENSIRION SPS30 AIR POLLUTION SENSOR DRIVER
 M: Tomasz Duszynski 
diff --git a/drivers/iio/chemical/Kconfig b/drivers/iio/chemical/Kconfig
index 970d34888c2e..10bb431bc3ce 100644
--- a/drivers/iio/chemical/Kconfig
+++ b/drivers/iio/chemical/Kconfig
@@ -107,6 +107,17 @@ config SCD30_I2C
  To compile this driver as a module, choose M here: the module will
  be called scd30_i2c.
 
+config SCD30_SERIAL
+   tristate "SCD30 carbon dioxide sensor serial driver"
+   depends on SCD30_CORE && SERIAL_DEV_BUS
+   select CRC16
+   help
+ Say Y here to build support for the Sensirion SCD30 serial interface
+ driver.
+
+ To compile this driver as a module, choose M here: the module will
+ be called scd30_serial.
+
 config SENSIRION_SGP30
tristate "Sensirion SGPxx gas sensors"
depends on I2C
diff --git a/drivers/iio/chemical/Makefile b/drivers/iio/chemical/Makefile
index 0966ca34e34b..fef63dd5bf92 100644
--- a/drivers/iio/chemical/Makefile
+++ b/drivers/iio/chemical/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_IAQCORE) += ams-iaq-core.o
 obj-$(CONFIG_PMS7003) += pms7003.o
 obj-$(CONFIG_SCD30_CORE) += scd30_core.o
 obj-$(CONFIG_SCD30_I2C) += scd30_i2c.o
+obj-$(CONFIG_SCD30_SERIAL) += scd30_serial.o
 obj-$(CONFIG_SENSIRION_SGP30)  += sgp30.o
 obj-$(CONFIG_SPS30) += sps30.o
 obj-$(CONFIG_VZ89X)+= vz89x.o
diff --git a/drivers/iio/chemical/scd30_serial.c 
b/drivers/iio/chemical/scd30_serial.c
new file mode 100644
index ..07d7d3110fe0
--- /dev/null
+++ b/drivers/iio/chemical/scd30_serial.c
@@ -0,0 +1,266 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Sensirion SCD30 carbon dioxide sensor serial driver
+ *
+ * Copyright (c) 2020 Tomasz Duszynski 
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "scd30.h"
+
+#define SCD30_SERDEV_ADDR 0x61
+#define SCD30_SERDEV_WRITE 0x06
+#define SCD30_SERDEV_READ 0x03
+#define SCD30_SERDEV_MAX_BUF_SIZE 17
+#define SCD30_SERDEV_RX_HEADER_SIZE 3
+#define SCD30_SERDEV_CRC_SIZE 2
+#define SCD30_SERDEV_TIMEOUT msecs_to_jiffies(200)
+
+struct scd30_serdev_priv {
+   struct completion meas_ready;
+   char *buf;
+   int num_expected;
+   int num;
+};
+
+static u16 scd30_serdev_cmd_lookup_tbl[] = {
+   [CMD_START_MEAS] = 0x0036,
+   [CMD_STOP_MEAS] = 0x0037,
+   [CMD_MEAS_INTERVAL] = 0x0025,
+   [CMD_MEAS_READY] = 0x0027,
+   [CMD_READ_MEAS] = 0x0028,
+   [CMD_ASC] = 0x003a,
+   [CMD_FRC] = 0x0039,
+   [CMD_TEMP_OFFSET] = 0x003b,
+   [CMD_FW_VERSION] = 0x0020,
+   [CMD_RESET] = 0x0034,
+};
+
+static u16 scd30_serdev_calc_crc(const char *buf, int size)
+{
+   return crc16(0x, buf, size);
+}
+
+static int scd30_serdev_xfer(struct scd30_state *state, char *txbuf, int 
txsize,
+char *rxbuf, int rxsize)
+{
+   struct serdev_device *serdev = to_serdev_device(state->dev);
+   struct scd30_serdev_priv *priv = state->priv;
+   int ret;
+
+   priv->buf = rxbuf;
+   priv->num_expected = rxsize;
+   priv->num = 0;
+
+   ret = serdev_device_write(serdev, txbuf, txsize, SCD30_SERDEV_TIMEOUT);
+   if (ret < txsize)
+   return ret < 0 ? ret : -EIO;
+
+   ret = wait_for_completion_interruptible_timeout(>meas_ready,
+   SCD30_SERDEV_TIMEOUT);
+   if (ret > 0)
+   ret = 0;
+   else if (!ret)
+   ret = -ETIMEDOUT;
+
+   return ret;
+}
+
+static int scd30_serdev_command(struct scd30_state *state, enum scd30_cmd cmd,
+   u16 arg, void *response, int size)
+{
+   /*
+* Communication over serial line is based on modbus protocol (or rather
+* its variation called modbus over serial to be precise). Upon
+* receiving a request device should reply with response.
+*
+* Frame below represents a request message. Each field takes
+* exactly one byte.
+*
+* +--+--+-+-+---+---+-+-+
+* | dev  | op   | reg | reg | byte1 | byte0 | crc | crc |
+* | addr | code | msb | 

[PATCH v2 1/4] iio: chemical: scd30: add core driver

2020-05-30 Thread Tomasz Duszynski
Add Sensirion SCD30 carbon dioxide core driver.

Signed-off-by: Tomasz Duszynski 
---
 Documentation/ABI/testing/sysfs-bus-iio-scd30 |  20 +
 MAINTAINERS   |   6 +
 drivers/iio/chemical/Kconfig  |  11 +
 drivers/iio/chemical/Makefile |   1 +
 drivers/iio/chemical/scd30.h  |  75 ++
 drivers/iio/chemical/scd30_core.c | 764 ++
 6 files changed, 877 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-scd30
 create mode 100644 drivers/iio/chemical/scd30.h
 create mode 100644 drivers/iio/chemical/scd30_core.c

diff --git a/Documentation/ABI/testing/sysfs-bus-iio-scd30 
b/Documentation/ABI/testing/sysfs-bus-iio-scd30
new file mode 100644
index ..a05b1d28e94a
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-iio-scd30
@@ -0,0 +1,20 @@
+What:  /sys/bus/iio/devices/iio:deviceX/calibration
+Date:  June 2020
+KernelVersion: 5.8
+Contact:   linux-...@vger.kernel.org
+Description:
+   Contaminants build-up in the measurement chamber or optical
+   elements deterioration leads to sensor drift.
+
+   One can compensate for sensor drift by using either automatic
+   self calibration (asc) or forced recalibration (frc). If used
+   at once one will overwrite the other.
+
+   Writing 1 or 0 to this attribute will respectively activate or
+   deactivate asc.
+
+   Picking value from the range [400 1 2000] and writing it to the
+   sensor will set frc.
+
+   Upon reading current asc status and frc value are returned
+   respectively.
diff --git a/MAINTAINERS b/MAINTAINERS
index 60ed2963efaa..41a509cca6f1 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -15137,6 +15137,12 @@ S: Maintained
 F: drivers/misc/phantom.c
 F: include/uapi/linux/phantom.h

+SENSIRION SCD30 CARBON DIOXIDE SENSOR DRIVER
+M: Tomasz Duszynski 
+S: Maintained
+F: drivers/iio/chemical/scd30.h
+F: drivers/iio/chemical/scd30_core.c
+
 SENSIRION SPS30 AIR POLLUTION SENSOR DRIVER
 M: Tomasz Duszynski 
 S: Maintained
diff --git a/drivers/iio/chemical/Kconfig b/drivers/iio/chemical/Kconfig
index 7f21afd73b1c..99e852b67e55 100644
--- a/drivers/iio/chemical/Kconfig
+++ b/drivers/iio/chemical/Kconfig
@@ -85,6 +85,17 @@ config PMS7003
  To compile this driver as a module, choose M here: the module will
  be called pms7003.

+config SCD30_CORE
+   tristate "SCD30 carbon dioxide sensor driver"
+   select IIO_BUFFER
+   select IIO_TRIGGERED_BUFFER
+   help
+ Say Y here to build support for the Sensirion SCD30 sensor with carbon
+ dioxide, relative humidity and temperature sensing capabilities.
+
+ To compile this driver as a module, choose M here: the module will
+ be called scd30_core.
+
 config SENSIRION_SGP30
tristate "Sensirion SGPxx gas sensors"
depends on I2C
diff --git a/drivers/iio/chemical/Makefile b/drivers/iio/chemical/Makefile
index aba4167db745..c9804b041ecd 100644
--- a/drivers/iio/chemical/Makefile
+++ b/drivers/iio/chemical/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_BME680_SPI) += bme680_spi.o
 obj-$(CONFIG_CCS811)   += ccs811.o
 obj-$(CONFIG_IAQCORE)  += ams-iaq-core.o
 obj-$(CONFIG_PMS7003) += pms7003.o
+obj-$(CONFIG_SCD30_CORE) += scd30_core.o
 obj-$(CONFIG_SENSIRION_SGP30)  += sgp30.o
 obj-$(CONFIG_SPS30) += sps30.o
 obj-$(CONFIG_VZ89X)+= vz89x.o
diff --git a/drivers/iio/chemical/scd30.h b/drivers/iio/chemical/scd30.h
new file mode 100644
index ..9b25f7423142
--- /dev/null
+++ b/drivers/iio/chemical/scd30.h
@@ -0,0 +1,75 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _SCD30_H
+#define _SCD30_H
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct scd30_state;
+
+enum scd30_cmd {
+   /* start continuous measurement with pressure compensation */
+   CMD_START_MEAS,
+   /* stop continuous measurement */
+   CMD_STOP_MEAS,
+   /* set/get measurement interval */
+   CMD_MEAS_INTERVAL,
+   /* check whether new measurement is ready */
+   CMD_MEAS_READY,
+   /* get measurement */
+   CMD_READ_MEAS,
+   /* turn on/off automatic self calibration */
+   CMD_ASC,
+   /* set/get forced recalibration value */
+   CMD_FRC,
+   /* set/get temperature offset */
+   CMD_TEMP_OFFSET,
+   /* get firmware version */
+   CMD_FW_VERSION,
+   /* reset sensor */
+   CMD_RESET,
+   /*
+* Command for altitude compensation was omitted intentionally because
+* the same can be achieved by means of CMD_START_MEAS which takes
+* pressure above the sea level as an argument.
+*/
+};
+
+#define SCD30_MEAS_COUNT 3
+
+typedef int (*scd30_command_t)(struct scd30_state *state, enum scd30_cmd cmd,
+   

[PATCH v2 2/4] iio: chemical: scd30: add I2C interface driver

2020-05-30 Thread Tomasz Duszynski
Add I2C interface driver for the SCD30 sensor.

Signed-off-by: Tomasz Duszynski 
---
 MAINTAINERS  |   1 +
 drivers/iio/chemical/Kconfig |  11 +++
 drivers/iio/chemical/Makefile|   1 +
 drivers/iio/chemical/scd30_i2c.c | 134 +++
 4 files changed, 147 insertions(+)
 create mode 100644 drivers/iio/chemical/scd30_i2c.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 41a509cca6f1..13aed3473b7e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -15142,6 +15142,7 @@ M:  Tomasz Duszynski 
 S: Maintained
 F: drivers/iio/chemical/scd30.h
 F: drivers/iio/chemical/scd30_core.c
+F: drivers/iio/chemical/scd30_i2c.c
 
 SENSIRION SPS30 AIR POLLUTION SENSOR DRIVER
 M: Tomasz Duszynski 
diff --git a/drivers/iio/chemical/Kconfig b/drivers/iio/chemical/Kconfig
index 99e852b67e55..970d34888c2e 100644
--- a/drivers/iio/chemical/Kconfig
+++ b/drivers/iio/chemical/Kconfig
@@ -96,6 +96,17 @@ config SCD30_CORE
  To compile this driver as a module, choose M here: the module will
  be called scd30_core.
 
+config SCD30_I2C
+   tristate "SCD30 carbon dioxide sensor I2C driver"
+   depends on SCD30_CORE && I2C
+   select CRC8
+   help
+ Say Y here to build support for the Sensirion SCD30 I2C interface
+ driver.
+
+ To compile this driver as a module, choose M here: the module will
+ be called scd30_i2c.
+
 config SENSIRION_SGP30
tristate "Sensirion SGPxx gas sensors"
depends on I2C
diff --git a/drivers/iio/chemical/Makefile b/drivers/iio/chemical/Makefile
index c9804b041ecd..0966ca34e34b 100644
--- a/drivers/iio/chemical/Makefile
+++ b/drivers/iio/chemical/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_CCS811)  += ccs811.o
 obj-$(CONFIG_IAQCORE)  += ams-iaq-core.o
 obj-$(CONFIG_PMS7003) += pms7003.o
 obj-$(CONFIG_SCD30_CORE) += scd30_core.o
+obj-$(CONFIG_SCD30_I2C) += scd30_i2c.o
 obj-$(CONFIG_SENSIRION_SGP30)  += sgp30.o
 obj-$(CONFIG_SPS30) += sps30.o
 obj-$(CONFIG_VZ89X)+= vz89x.o
diff --git a/drivers/iio/chemical/scd30_i2c.c b/drivers/iio/chemical/scd30_i2c.c
new file mode 100644
index ..a6b532b83669
--- /dev/null
+++ b/drivers/iio/chemical/scd30_i2c.c
@@ -0,0 +1,134 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Sensirion SCD30 carbon dioxide sensor i2c driver
+ *
+ * Copyright (c) 2020 Tomasz Duszynski 
+ *
+ * I2C slave address: 0x61
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "scd30.h"
+
+#define SCD30_I2C_MAX_BUF_SIZE 18
+#define SCD30_I2C_CRC8_POLYNOMIAL 0x31
+
+static u16 scd30_i2c_cmd_lookup_tbl[] = {
+   [CMD_START_MEAS] = 0x0010,
+   [CMD_STOP_MEAS] = 0x0104,
+   [CMD_MEAS_INTERVAL] = 0x4600,
+   [CMD_MEAS_READY] = 0x0202,
+   [CMD_READ_MEAS] = 0x0300,
+   [CMD_ASC] = 0x5306,
+   [CMD_FRC] = 0x5204,
+   [CMD_TEMP_OFFSET] = 0x5403,
+   [CMD_FW_VERSION] = 0xd100,
+   [CMD_RESET] = 0xd304,
+};
+
+DECLARE_CRC8_TABLE(scd30_i2c_crc8_tbl);
+
+static int scd30_i2c_xfer(struct scd30_state *state, char *txbuf, int txsize,
+ char *rxbuf, int rxsize)
+{
+   struct i2c_client *client = to_i2c_client(state->dev);
+   int ret;
+
+   /*
+* repeated start is not supported hence instead of sending two i2c
+* messages in a row we send one by one
+*/
+   ret = i2c_master_send(client, txbuf, txsize);
+   if (ret != txsize)
+   return ret < 0 ? ret : -EIO;
+
+   if (!rxbuf)
+   return 0;
+
+   ret = i2c_master_recv(client, rxbuf, rxsize);
+   if (ret != rxsize)
+   return ret < 0 ? ret : -EIO;
+
+   return 0;
+}
+
+static int scd30_i2c_command(struct scd30_state *state, enum scd30_cmd cmd,
+u16 arg, void *response, int size)
+{
+   char crc, buf[SCD30_I2C_MAX_BUF_SIZE], *rsp = response;
+   int i, ret;
+
+   put_unaligned_be16(scd30_i2c_cmd_lookup_tbl[cmd], buf);
+   i = 2;
+
+   if (rsp) {
+   /* each two bytes are followed by a crc8 */
+   size += size / 2;
+   } else {
+   put_unaligned_be16(arg, buf + i);
+   crc = crc8(scd30_i2c_crc8_tbl, buf + i, 2, CRC8_INIT_VALUE);
+   i += 2;
+   buf[i] = crc;
+   i += 1;
+
+   /* commands below don't take an argument */
+   if ((cmd == CMD_STOP_MEAS) || (cmd == CMD_RESET))
+   i -= 3;
+   }
+
+   ret = scd30_i2c_xfer(state, buf, i, buf, size);
+   if (ret)
+   return ret;
+
+   /* validate received data and strip off crc bytes */
+   for (i = 0; i < size; i += 3) {
+   crc = crc8(scd30_i2c_crc8_tbl, buf + i, 2, CRC8_INIT_VALUE);
+   if (crc != buf[i + 2]) {
+   dev_err(state->dev, "data integrity check failed\n");
+   return 

[PATCH v2 4/4] dt-bindings: iio: scd30: add device binding file

2020-05-30 Thread Tomasz Duszynski
Add SCD30 sensor binding file.

Signed-off-by: Tomasz Duszynski 
---
 .../iio/chemical/sensirion,scd30.yaml | 68 +++
 MAINTAINERS   |  1 +
 2 files changed, 69 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/iio/chemical/sensirion,scd30.yaml

diff --git 
a/Documentation/devicetree/bindings/iio/chemical/sensirion,scd30.yaml 
b/Documentation/devicetree/bindings/iio/chemical/sensirion,scd30.yaml
new file mode 100644
index ..34cc3925d64d
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/chemical/sensirion,scd30.yaml
@@ -0,0 +1,68 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/chemical/sensirion,scd30.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sensirion SCD30 carbon dioxide sensor
+
+maintainers:
+  - Tomasz Duszynski 
+
+description: |
+  Air quality sensor capable of measuring co2 concentration, temperature
+  and relative humidity.
+
+properties:
+  compatible:
+enum:
+  - sensirion,scd30
+
+  reg:
+maxItems: 1
+
+  interrupts:
+maxItems: 1
+
+  vdd-supply: true
+
+  sensirion,sel-gpios:
+description: GPIO connected to the SEL line
+maxItems: 1
+
+  sensirion,pwm-gpios:
+description: GPIO connected to the PWM line
+maxItems: 1
+
+required:
+  - compatible
+
+additionalProperties: false
+
+examples:
+  - |
+# include 
+i2c {
+  #address-cells = <1>;
+  #size-cells = <0>;
+
+  scd30@61 {
+compatible = "sensirion,scd30";
+reg = <0x61>;
+vdd-supply = <>;
+interrupt-parent = <>;
+interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
+  };
+};
+  - |
+# include 
+serial {
+  scd30 {
+compatible = "sensirion,scd30";
+vdd-supply = <>;
+interrupt-parent = <>;
+interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
+  };
+};
+
+...
diff --git a/MAINTAINERS b/MAINTAINERS
index 5db4b446c8ba..0ab9cf39e051 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -15140,6 +15140,7 @@ F:  include/uapi/linux/phantom.h
 SENSIRION SCD30 CARBON DIOXIDE SENSOR DRIVER
 M: Tomasz Duszynski 
 S: Maintained
+F: Documentation/devicetree/bindings/iio/chemical/sensirion,scd30.yaml
 F: drivers/iio/chemical/scd30.h
 F: drivers/iio/chemical/scd30_core.c
 F: drivers/iio/chemical/scd30_i2c.c
-- 
2.26.2



[PATCH v2 0/4] Add support for SCD30 sensor

2020-05-30 Thread Tomasz Duszynski
Following series adds support for Sensirion SCD30 sensor module capable of
measuring carbon dioxide, temperature and relative humidity. CO2 measurements
base on NDIR principle while temperature and relative humidity are measured by
the on board SHT31. As for sensor communication, both I2C and serial interfaces
are supported.

v2:
* move asm/byteorder.h towards the bottom of include list
* make channel address names in enum more specific
* add postfixes to defines and extra comments
* drop unneeded i2c include from scd30 header
* break generic command sending function into specialized options
* expose automatic calibration and forced calibration via the same attr
* use SAMP_FREQ to set frequency instead of meas_interval attr
* use CALISCALE to set pressure compensation instead of pressure_comp attr
* use CALIBBIAS to set temperature offset instead of temp_offset attr
* fix order in MAINTAINERS
* drop attribute allowing one to reset sensor
* as we have dt probing drop board file based probing (i2c_device_id)
* merge patches touching related files
* use fwnode API to retrieve interrupt from dt
* fix interrupt-parent spelling
* change binding license
* drop supply from required property

Tomasz Duszynski (4):
  iio: chemical: scd30: add core driver
  iio: chemical: scd30: add I2C interface driver
  iio: chemical: scd30: add serial interface driver
  dt-bindings: iio: scd30: add device binding file

 Documentation/ABI/testing/sysfs-bus-iio-scd30 |  20 +
 .../iio/chemical/sensirion,scd30.yaml |  68 ++
 MAINTAINERS   |   9 +
 drivers/iio/chemical/Kconfig  |  33 +
 drivers/iio/chemical/Makefile |   3 +
 drivers/iio/chemical/scd30.h  |  75 ++
 drivers/iio/chemical/scd30_core.c | 764 ++
 drivers/iio/chemical/scd30_i2c.c  | 134 +++
 drivers/iio/chemical/scd30_serial.c   | 266 ++
 9 files changed, 1372 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-scd30
 create mode 100644 
Documentation/devicetree/bindings/iio/chemical/sensirion,scd30.yaml
 create mode 100644 drivers/iio/chemical/scd30.h
 create mode 100644 drivers/iio/chemical/scd30_core.c
 create mode 100644 drivers/iio/chemical/scd30_i2c.c
 create mode 100644 drivers/iio/chemical/scd30_serial.c

--
2.26.2



Re: [PATCH] bitops: use the same mechanism for get_count_order[_long]

2020-05-30 Thread Wei Yang
Andrew,

Would you mind picking up this one? The test module doesn't show any warning
after this on applied.

On Mon, May 25, 2020 at 09:59:58PM +, Wei Yang wrote:
>These two functions share the same logic.
>
>Signed-off-by: Wei Yang 
>---
> include/linux/bitops.h | 8 +++-
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
>diff --git a/include/linux/bitops.h b/include/linux/bitops.h
>index 5b5609e81a84..80703ef27aee 100644
>--- a/include/linux/bitops.h
>+++ b/include/linux/bitops.h
>@@ -188,12 +188,10 @@ static inline unsigned fls_long(unsigned long l)
> 
> static inline int get_count_order(unsigned int count)
> {
>-  int order;
>+  if (count == 0)
>+  return -1;
> 
>-  order = fls(count) - 1;
>-  if (count & (count - 1))
>-  order++;
>-  return order;
>+  return fls(--count);
> }
> 
> /**
>-- 
>2.23.0

-- 
Wei Yang
Help you, Help me


[RFC PATCH] checkpatch: check for trivial sizeofs

2020-05-30 Thread Denis Efremov
sizeof(char) and its variations in most cases doesn't make code more clear.
It only makes code wordy.

Signed-off-by: Denis Efremov 
---
 scripts/checkpatch.pl | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index eac40f0abd56..9dd338b125d2 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6045,6 +6045,13 @@ sub process {
}
}
 
+# check for trivial sizeof(char) == 1
+   if ($line =~ 
/\bsizeof\s*\(\s*((?:(?:un)?signed\s+)?char|(?:__)?u8|u?int8_t|[us]?byte(?:_t)?)\s*\)/)
 {
+   my $byte = $1;
+   CHK("SIZEOF_TRIVIAL",
+"redundant sizeof($byte) == 1 \n" . $herecurr);
+   }
+
 # check for struct spinlock declarations
if ($line =~ /^.\s*\bstruct\s+spinlock\s+\w+\s*;/) {
WARN("USE_SPINLOCK_T",
-- 
2.26.2



Re: [PATCH v2 4/4] pinctrl: bcm2835: Add support for wake-up interrupts

2020-05-30 Thread Florian Fainelli



On 5/30/2020 12:49 AM, Stefan Wahren wrote:
> Hi Florian,
> 
> Am 29.05.20 um 21:15 schrieb Florian Fainelli:
>> Leverage the IRQCHIP_MASK_ON_SUSPEND flag in order to avoid having to
>> specifically treat the GPIO interrupts during suspend and resume, and
>> simply implement an irq_set_wake() callback that is responsible for
>> enabling the parent wake-up interrupt as a wake-up interrupt.
>>
>> To avoid allocating unnecessary resources for other chips, the wake-up
>> interrupts are only initialized if we have a brcm,bcm7211-gpio
>> compatibility string.
>>
>> Signed-off-by: Florian Fainelli 
>> ---
>>  drivers/pinctrl/bcm/pinctrl-bcm2835.c | 76 ++-
>>  1 file changed, 75 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/pinctrl/bcm/pinctrl-bcm2835.c 
>> b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
>> index 1b00d93aa66e..1fbf067a3eed 100644
>> --- a/drivers/pinctrl/bcm/pinctrl-bcm2835.c
>> +++ b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
>> @@ -19,6 +19,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  #include 
>>  #include 
>>  #include 
>> @@ -76,6 +77,7 @@
>>  struct bcm2835_pinctrl {
>>  struct device *dev;
>>  void __iomem *base;
>> +int *wake_irq;
>>  
>>  /* note: locking assumes each bank will have its own unsigned long */
>>  unsigned long enabled_irq_map[BCM2835_NUM_BANKS];
>> @@ -435,6 +437,11 @@ static void bcm2835_gpio_irq_handler(struct irq_desc 
>> *desc)
>>  chained_irq_exit(host_chip, desc);
>>  }
>>  
>> +static irqreturn_t bcm2835_gpio_wake_irq_handler(int irq, void *dev_id)
>> +{
>> +return IRQ_HANDLED;
>> +}
>> +
>>  static inline void __bcm2835_gpio_irq_config(struct bcm2835_pinctrl *pc,
>>  unsigned reg, unsigned offset, bool enable)
>>  {
>> @@ -634,6 +641,34 @@ static void bcm2835_gpio_irq_ack(struct irq_data *data)
>>  bcm2835_gpio_set_bit(pc, GPEDS0, gpio);
>>  }
>>  
>> +static int bcm2835_gpio_irq_set_wake(struct irq_data *data, unsigned int on)
>> +{
>> +struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
>> +struct bcm2835_pinctrl *pc = gpiochip_get_data(chip);
>> +unsigned gpio = irqd_to_hwirq(data);
>> +unsigned int irqgroup;
>> +int ret = -EINVAL;
>> +
>> +if (!pc->wake_irq)
>> +return ret;
>> +
>> +if (gpio <= 27)
>> +irqgroup = 0;
>> +else if (gpio >= 28 && gpio <= 45)
>> +irqgroup = 1;
>> +else if (gpio >= 46 && gpio <= 53)
>> +irqgroup = 2;
> in case the BCM7211 has 58 GPIOs, but the wake up interrupts are only
> available for the first 54 this should deserve a comment.

irqgroup 2 covers GPIOs 46 through 57, thanks for noticing. Do you have
more comments before I spin a v3? Thank you for reviewing.
-- 
Florian


Re: [PATCH] lib: make a test module with get_count_order/long

2020-05-30 Thread Wei Yang
On Sat, May 30, 2020 at 01:25:31PM +0300, Andy Shevchenko wrote:
>On Sat, May 30, 2020 at 12:43:28AM +, Wei Yang wrote:
>> A test module to make sure get_count_order/long returns the correct result.
>
>>  lib/Kconfig.debug  | 13 ++
>>  lib/Makefile   |  2 +
>>  lib/test_getorder.c| 64 ++
>
>I didn't get why it's not a part of test_bitops?
>

I see the document of test_bitops says it does exercise on clear_bit and
set_bit. So not sure it is proper to put them together.

>-- 
>With Best Regards,
>Andy Shevchenko
>

-- 
Wei Yang
Help you, Help me


[PATCH v2 net-next 3/3] selftests/bpf: Add test for SO_BINDTODEVICE opt of bpf_setsockopt

2020-05-30 Thread Ferenc Fejes
This test intended to verify if SO_BINDTODEVICE option works in
bpf_setsockopt. Because we already in the SOL_SOCKET level in this
connect bpf prog its safe to verify the sanity in the beginning of
the connect_v4_prog by calling the bind_to_device test helper.

The testing environment already created by the test_sock_addr.sh
script so this test assume that two netdevices already existing in
the system: veth pair with names test_sock_addr1 and test_sock_addr2.
The test will try to bind the socket to those devices first.
Then the test assume there are no netdevice with "nonexistent_dev"
name so the bpf_setsockopt will give use ENODEV error.
At the end the test remove the device binding from the socket
by binding it to an empty name.

Signed-off-by: Ferenc Fejes 
---
 .../selftests/bpf/progs/connect4_prog.c   | 33 +++
 1 file changed, 33 insertions(+)

diff --git a/tools/testing/selftests/bpf/progs/connect4_prog.c 
b/tools/testing/selftests/bpf/progs/connect4_prog.c
index c2c85c31cffd..1ab2c5eba86c 100644
--- a/tools/testing/selftests/bpf/progs/connect4_prog.c
+++ b/tools/testing/selftests/bpf/progs/connect4_prog.c
@@ -9,6 +9,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include 
 #include 
@@ -21,6 +23,10 @@
 #define TCP_CA_NAME_MAX 16
 #endif
 
+#ifndef IFNAMSIZ
+#define IFNAMSIZ 16
+#endif
+
 int _version SEC("version") = 1;
 
 __attribute__ ((noinline))
@@ -75,6 +81,29 @@ static __inline int set_cc(struct bpf_sock_addr *ctx)
return 0;
 }
 
+static __inline int bind_to_device(struct bpf_sock_addr *ctx)
+{
+   char veth1[IFNAMSIZ] = "test_sock_addr1";
+   char veth2[IFNAMSIZ] = "test_sock_addr2";
+   char missing[IFNAMSIZ] = "nonexistent_dev";
+   char del_bind[IFNAMSIZ] = "";
+
+   if (bpf_setsockopt(ctx, SOL_SOCKET, SO_BINDTODEVICE,
+   , sizeof(veth1)))
+   return 1;
+   if (bpf_setsockopt(ctx, SOL_SOCKET, SO_BINDTODEVICE,
+   , sizeof(veth2)))
+   return 1;
+   if (bpf_setsockopt(ctx, SOL_SOCKET, SO_BINDTODEVICE,
+   , sizeof(missing)) != -ENODEV)
+   return 1;
+   if (bpf_setsockopt(ctx, SOL_SOCKET, SO_BINDTODEVICE,
+   _bind, sizeof(del_bind)))
+   return 1;
+
+   return 0;
+}
+
 SEC("cgroup/connect4")
 int connect_v4_prog(struct bpf_sock_addr *ctx)
 {
@@ -88,6 +117,10 @@ int connect_v4_prog(struct bpf_sock_addr *ctx)
tuple.ipv4.daddr = bpf_htonl(DST_REWRITE_IP4);
tuple.ipv4.dport = bpf_htons(DST_REWRITE_PORT4);
 
+   /* Bind to device and unbind it. */
+   if (bind_to_device(ctx))
+   return 0;
+
if (ctx->type != SOCK_STREAM && ctx->type != SOCK_DGRAM)
return 0;
else if (ctx->type == SOCK_STREAM)
-- 
2.17.1



[PATCH v2 net-next 1/3] net: Make locking in sock_bindtoindex optional

2020-05-30 Thread Ferenc Fejes
The sock_bindtoindex intended for kernel wide usage however
it will lock the socket regardless of the context. This modification
relax this behavior optionally: locking the socket will be optional
by calling the sock_bindtoindex with lock_sk = true.

The modification applied to all users of the sock_bindtoindex.

Signed-off-by: Ferenc Fejes 
---
 include/net/sock.h|  2 +-
 net/core/sock.c   | 10 ++
 net/ipv4/udp_tunnel.c |  2 +-
 net/ipv6/ip6_udp_tunnel.c |  2 +-
 4 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/include/net/sock.h b/include/net/sock.h
index d994daa418ec..098d97d9fe72 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2688,7 +2688,7 @@ static inline bool sk_dev_equal_l3scope(struct sock *sk, 
int dif)
 
 void sock_def_readable(struct sock *sk);
 
-int sock_bindtoindex(struct sock *sk, int ifindex);
+int sock_bindtoindex(struct sock *sk, int ifindex, bool lock_sk);
 void sock_enable_timestamps(struct sock *sk);
 void sock_no_linger(struct sock *sk);
 void sock_set_keepalive(struct sock *sk);
diff --git a/net/core/sock.c b/net/core/sock.c
index 2ca3425b519c..c7ee722cfbe9 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -594,13 +594,15 @@ static int sock_bindtoindex_locked(struct sock *sk, int 
ifindex)
return ret;
 }
 
-int sock_bindtoindex(struct sock *sk, int ifindex)
+int sock_bindtoindex(struct sock *sk, int ifindex, bool lock_sk)
 {
int ret;
 
-   lock_sock(sk);
+   if (lock_sk)
+   lock_sock(sk);
ret = sock_bindtoindex_locked(sk, ifindex);
-   release_sock(sk);
+   if (lock_sk)
+   release_sock(sk);
 
return ret;
 }
@@ -646,7 +648,7 @@ static int sock_setbindtodevice(struct sock *sk, char 
__user *optval,
goto out;
}
 
-   return sock_bindtoindex(sk, index);
+   return sock_bindtoindex(sk, index, true);
 out:
 #endif
 
diff --git a/net/ipv4/udp_tunnel.c b/net/ipv4/udp_tunnel.c
index 2158e8bddf41..3eecba0874aa 100644
--- a/net/ipv4/udp_tunnel.c
+++ b/net/ipv4/udp_tunnel.c
@@ -22,7 +22,7 @@ int udp_sock_create4(struct net *net, struct udp_port_cfg 
*cfg,
goto error;
 
if (cfg->bind_ifindex) {
-   err = sock_bindtoindex(sock->sk, cfg->bind_ifindex);
+   err = sock_bindtoindex(sock->sk, cfg->bind_ifindex, true);
if (err < 0)
goto error;
}
diff --git a/net/ipv6/ip6_udp_tunnel.c b/net/ipv6/ip6_udp_tunnel.c
index 2e0ad1bc84a8..cdc4d4ee2420 100644
--- a/net/ipv6/ip6_udp_tunnel.c
+++ b/net/ipv6/ip6_udp_tunnel.c
@@ -30,7 +30,7 @@ int udp_sock_create6(struct net *net, struct udp_port_cfg 
*cfg,
goto error;
}
if (cfg->bind_ifindex) {
-   err = sock_bindtoindex(sock->sk, cfg->bind_ifindex);
+   err = sock_bindtoindex(sock->sk, cfg->bind_ifindex, true);
if (err < 0)
goto error;
}
-- 
2.17.1



[PATCH v2 net-next 0/3] Extending bpf_setsockopt with SO_BINDTODEVICE sockopt

2020-05-30 Thread Ferenc Fejes
This option makes it possible to programatically bind sockets
to netdevices. With the help of this option sockets 
of VRF unaware applications could be distributed between 
multiple VRFs with an eBPF program. This lets the applications
benefit from multiple possible routes.

v2:
- splitting up the patch to three parts
- lock_sk parameter for optional locking in sock_bindtoindex - Stanislav 
Fomichev
- testing the SO_BINDTODEVICE option - Andrii Nakryiko

Ferenc Fejes (3):
  net: Make locking in sock_bindtoindex optional
  bpf: Allow SO_BINDTODEVICE opt in bpf_setsockopt
  selftests/bpf: Add test for SO_BINDTODEVICE opt of bpf_setsockopt

 include/net/sock.h|  2 +-
 net/core/filter.c | 27 ++-
 net/core/sock.c   | 10 +++---
 net/ipv4/udp_tunnel.c |  2 +-
 net/ipv6/ip6_udp_tunnel.c |  2 +-
 .../selftests/bpf/progs/connect4_prog.c   | 33 +++
 6 files changed, 68 insertions(+), 8 deletions(-)

-- 
2.17.1



[PATCH v2 net-next 2/3] bpf: Allow SO_BINDTODEVICE opt in bpf_setsockopt

2020-05-30 Thread Ferenc Fejes
Extending the supported sockopts in bpf_setsockopt with
SO_BINDTODEVICE. We call sock_bindtoindex with parameter
lock_sk = false in this context because we already owning
the socket.

Signed-off-by: Ferenc Fejes 
---
 net/core/filter.c | 27 ++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/net/core/filter.c b/net/core/filter.c
index bd2853d23b50..a0958c5ef127 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -4248,6 +4248,9 @@ static const struct bpf_func_proto 
bpf_get_socket_uid_proto = {
 static int _bpf_setsockopt(struct sock *sk, int level, int optname,
   char *optval, int optlen, u32 flags)
 {
+   char devname[IFNAMSIZ];
+   struct net *net;
+   int ifindex;
int ret = 0;
int val;
 
@@ -4257,7 +4260,7 @@ static int _bpf_setsockopt(struct sock *sk, int level, 
int optname,
sock_owned_by_me(sk);
 
if (level == SOL_SOCKET) {
-   if (optlen != sizeof(int))
+   if (optlen != sizeof(int) && optname != SO_BINDTODEVICE)
return -EINVAL;
val = *((int *)optval);
 
@@ -4298,6 +4301,29 @@ static int _bpf_setsockopt(struct sock *sk, int level, 
int optname,
sk_dst_reset(sk);
}
break;
+   case SO_BINDTODEVICE:
+   ret = -ENOPROTOOPT;
+#ifdef CONFIG_NETDEVICES
+   optlen = min_t(long, optlen, IFNAMSIZ - 1);
+   strncpy(devname, optval, optlen);
+   devname[optlen] = 0;
+
+   ifindex = 0;
+   if (devname[0] != '\0') {
+   struct net_device *dev;
+
+   ret = -ENODEV;
+
+   net = sock_net(sk);
+   dev = dev_get_by_name(net, devname);
+   if (!dev)
+   break;
+   ifindex = dev->ifindex;
+   dev_put(dev);
+   }
+   ret = sock_bindtoindex(sk, ifindex, false);
+#endif
+   break;
default:
ret = -EINVAL;
}
-- 
2.17.1



Re: [PATCH] cifs: remove redundant initialization of variable rc

2020-05-30 Thread Steve French
merged into cifs-2.6.git for-next


On Wed, May 27, 2020 at 7:52 AM Colin King  wrote:
>
> From: Colin Ian King 
>
> The variable rc is being initialized with a value that is never read
> and it is being updated later with a new value.  The initialization is
> redundant and can be removed.
>
> Addresses-Coverity: ("Unused value")
> Signed-off-by: Colin Ian King 
> ---
>  fs/cifs/cifssmb.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
> index 5014a82391ff..d62f9175c546 100644
> --- a/fs/cifs/cifssmb.c
> +++ b/fs/cifs/cifssmb.c
> @@ -2375,7 +2375,7 @@ int
>  CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms,
>   unsigned int *nbytes, struct kvec *iov, int n_vec)
>  {
> -   int rc = -EACCES;
> +   int rc;
> WRITE_REQ *pSMB = NULL;
> int wct;
> int smb_hdr_len;
> --
> 2.25.1
>


--
Thanks,

Steve


  1   2   3   4   5   >