Re: [PATCH] fs: iomap: Change return type to vm_fault_t

2018-07-19 Thread Souptick Joarder
On Fri, Jul 20, 2018 at 11:39 AM, Darrick J. Wong
 wrote:
> On Fri, Jul 20, 2018 at 10:31:30AM +0530, Souptick Joarder wrote:
>> On Wed, Jul 4, 2018 at 3:22 AM, Andreas Gruenbacher  
>> wrote:
>> > On 3 July 2018 at 23:39, Darrick J. Wong  wrote:
>> >> On Mon, Jul 02, 2018 at 07:52:41PM +0200, Andreas Gruenbacher wrote:
>> >>> On 2 July 2018 at 17:43, Souptick Joarder  wrote:
>> >>> > Return type has been changed to vm_fault_t type for
>> >>> > iomap_page_mkwrite().
>> >>> >
>> >>> > see commit 1c8f422059ae ("mm: change return type to
>> >>> > vm_fault_t") for reference.
>> >>> >
>> >>> > Signed-off-by: Souptick Joarder 
>> >>> > Reviewed-by: Matthew Wilcox 
>> >>
>> >> I don't recall Christoph [now cc'd] rescinding his NAK of the previous
>> >> version of this patch[1].  Has he changed his mind since May?
>> >  /|\
>> > Oops, a reply gone wrong -- I was me  |   to reply to Souptick
>> > Joarder's gfs2 change which I've add  |   the gfs2 for-next branch.
>> > Not the iomap change. Sorry for the   |  sion.
>> >   |
>> >> [1] https://spinics.net/lists/linux  |  vel/msg126032.html
>> >>  |
>> >> Now granted I didn't have a problem  |   the code (and applied the xfs
>> >> version to 4.18 after monitoring to  |  sfy myself that nothing
>> >> particularly weird happened during   |   but seeing as most of the iomap
>> >> changes have gone through hch's rev  |  nd landed via the xfs tree...
>   |
> --D   |
>   |
> I wasn't planning on it, due to aforementioned NAK still being in place
> to the best of my knowledge, at least for the iomap patch.
>
>> Darrick, is this patch going to 4.19 through xfs tree ?

Well,  the original patch was NAK by Christoph because he wanted
to see the complete vm_fault_t migration picture in a patch series
where Matthew mentioned to send one patch per driver through
different maintainers tree to upstream the changes. This discussion
went on into two separate mail threads.

At this point we are almost done with vm_fault_t migration in all drivers/fs
except 3 patches and all the changes will be available in 4.19-rc1. We followed
one patch per driver mechanism and I believe we not are going to adopt other
mechanism (patch series) to upstream these vm_fault_t patches.

This particular patch is struggling for more than 3 months now.

Christoph, would you still like to maintain NAK on this patch ? :-)


Re: [PATCHv2 2/2] arm64: Clear the stack

2018-07-19 Thread Mark Rutland
On Thu, Jul 19, 2018 at 04:28:06PM -0700, Laura Abbott wrote:
> 
> Implementation of stackleak based heavily on the x86 version
> 
> Signed-off-by: Laura Abbott 

Reviewed-by: Mark Rutlamd 

Thanks for working on this!

Mark.

> ---
> v2: Convert to adjusted on_acessible_stack APIs. Fixed alloca check to
> just panic. Dropped the extra include per Kees. I also didn't add the
> Reviewed-by since the APIs did change and I wanted another pass.
> ---
>  arch/arm64/Kconfig|  1 +
>  arch/arm64/include/asm/processor.h| 15 +++
>  arch/arm64/kernel/entry.S |  7 +++
>  arch/arm64/kernel/process.c   | 17 +
>  arch/arm64/kvm/hyp/Makefile   |  3 ++-
>  drivers/firmware/efi/libstub/Makefile |  3 ++-
>  6 files changed, 44 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index 42c090cf0292..216d36a49ab5 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -96,6 +96,7 @@ config ARM64
>   select HAVE_ARCH_MMAP_RND_BITS
>   select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT
>   select HAVE_ARCH_SECCOMP_FILTER
> + select HAVE_ARCH_STACKLEAK
>   select HAVE_ARCH_THREAD_STRUCT_WHITELIST
>   select HAVE_ARCH_TRACEHOOK
>   select HAVE_ARCH_TRANSPARENT_HUGEPAGE
> diff --git a/arch/arm64/include/asm/processor.h 
> b/arch/arm64/include/asm/processor.h
> index a73ae1e49200..0061450a793b 100644
> --- a/arch/arm64/include/asm/processor.h
> +++ b/arch/arm64/include/asm/processor.h
> @@ -266,5 +266,20 @@ extern void __init minsigstksz_setup(void);
>  #define SVE_SET_VL(arg)  sve_set_current_vl(arg)
>  #define SVE_GET_VL() sve_get_current_vl()
>  
> +/*
> + * For CONFIG_GCC_PLUGIN_STACKLEAK
> + *
> + * These need to be macros because otherwise we get stuck in a nightmare
> + * of header definitions for the use of task_stack_page.
> + */
> +
> +#define current_top_of_stack()   
> \
> +({   
> \
> + struct stack_info _info;
> \
> + BUG_ON(!on_accessible_stack(current, current_stack_pointer, &_info));   
> \
> + _info.high; 
> \
> +})
> +#define on_thread_stack()(on_task_stack(current, current_stack_pointer, 
> NULL))
> +
>  #endif /* __ASSEMBLY__ */
>  #endif /* __ASM_PROCESSOR_H */
> diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
> index 28ad8799406f..67d12016063d 100644
> --- a/arch/arm64/kernel/entry.S
> +++ b/arch/arm64/kernel/entry.S
> @@ -431,6 +431,11 @@ tsk  .reqx28 // current thread_info
>  
>   .text
>  
> + .macro  stackleak_erase
> +#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
> + bl  stackleak_erase
> +#endif
> + .endm
>  /*
>   * Exception vectors.
>   */
> @@ -910,6 +915,7 @@ ret_fast_syscall:
>   and x2, x1, #_TIF_WORK_MASK
>   cbnzx2, work_pending
>   enable_step_tsk x1, x2
> + stackleak_erase
>   kernel_exit 0
>  ret_fast_syscall_trace:
>   enable_daif
> @@ -936,6 +942,7 @@ ret_to_user:
>   cbnzx2, work_pending
>  finish_ret_to_user:
>   enable_step_tsk x1, x2
> + stackleak_erase
>   kernel_exit 0
>  ENDPROC(ret_to_user)
>  
> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
> index e10bc363f533..2724e4d31b16 100644
> --- a/arch/arm64/kernel/process.c
> +++ b/arch/arm64/kernel/process.c
> @@ -493,3 +493,20 @@ void arch_setup_new_exec(void)
>  {
>   current->mm->context.flags = is_compat_task() ? MMCF_AARCH32 : 0;
>  }
> +
> +#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
> +void __used stackleak_check_alloca(unsigned long size)
> +{
> + unsigned long stack_left;
> + unsigned long current_sp = current_stack_pointer;
> + struct stack_info info;
> +
> + BUG_ON(!on_accessible_stack(current, current_sp, &info));
> +
> + stack_left = current_sp - info.low;
> +
> + if (size >= stack_left)
> + panic("alloca() over the kernel stack boundary\n");
> +}
> +EXPORT_SYMBOL(stackleak_check_alloca);
> +#endif
> diff --git a/arch/arm64/kvm/hyp/Makefile b/arch/arm64/kvm/hyp/Makefile
> index 4313f7475333..2fabc2dc1966 100644
> --- a/arch/arm64/kvm/hyp/Makefile
> +++ b/arch/arm64/kvm/hyp/Makefile
> @@ -3,7 +3,8 @@
>  # Makefile for Kernel-based Virtual Machine module, HYP part
>  #
>  
> -ccflags-y += -fno-stack-protector -DDISABLE_BRANCH_PROFILING
> +ccflags-y += -fno-stack-protector -DDISABLE_BRANCH_PROFILING \
> + $(DISABLE_STACKLEAK_PLUGIN)
>  
>  KVM=../../../../virt/kvm
>  
> diff --git a/drivers/firmware/efi/libstub/Makefile 
> b/drivers/firmware/efi/libstub/Makefile
> index a34e9290a699..25dd2a14560d 100644
> --- a/drivers/firmware/efi/libstub/Makefile
> +++ b/drivers/firmware/efi/libstub/Makefile
> @@ -20,7 +20,8 @@ cflags-$(CONFIG_EFI_ARMSTUB)+= 
> -I$(srct

[PATCH] ASoC: AMD: Add a fix voltage regulator for DA7219 and ADAU7002

2018-07-19 Thread Akshu Agrawal
DA7219 for our platform need to be configured for 1.8V.
Hence, we add a fixed volatge regulator with supplies
of 1.8V in the machine driver.

Signed-off-by: Akshu Agrawal 
---
 sound/soc/amd/Kconfig|  2 ++
 sound/soc/amd/acp-da7219-max98357a.c | 45 
 2 files changed, 47 insertions(+)

diff --git a/sound/soc/amd/Kconfig b/sound/soc/amd/Kconfig
index 6cbf9cf..c447a51 100644
--- a/sound/soc/amd/Kconfig
+++ b/sound/soc/amd/Kconfig
@@ -8,6 +8,8 @@ config SND_SOC_AMD_CZ_DA7219MX98357_MACH
select SND_SOC_DA7219
select SND_SOC_MAX98357A
select SND_SOC_ADAU7002
+   select REGULATOR
+   select REGULATOR_FIXED_VOLTAGE
depends on SND_SOC_AMD_ACP && I2C
help
 This option enables machine driver for DA7219 and MAX9835.
diff --git a/sound/soc/amd/acp-da7219-max98357a.c 
b/sound/soc/amd/acp-da7219-max98357a.c
index f42606e..fdf8972 100644
--- a/sound/soc/amd/acp-da7219-max98357a.c
+++ b/sound/soc/amd/acp-da7219-max98357a.c
@@ -31,7 +31,10 @@
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -320,11 +323,53 @@ static void cz_dmic_shutdown(struct snd_pcm_substream 
*substream)
.num_controls = ARRAY_SIZE(cz_mc_controls),
 };
 
+static struct regulator_consumer_supply acp_da7219_supplies[] = {
+   REGULATOR_SUPPLY("VDD", "i2c-DLGS7219:00"),
+   REGULATOR_SUPPLY("VDDMIC", "i2c-DLGS7219:00"),
+   REGULATOR_SUPPLY("VDDIO", "i2c-DLGS7219:00"),
+   REGULATOR_SUPPLY("IOVDD", "ADAU7002:00"),
+};
+
+static struct regulator_init_data acp_da7219_data = {
+   .constraints = {
+   .always_on = 1,
+   },
+   .num_consumer_supplies = ARRAY_SIZE(acp_da7219_supplies),
+   .consumer_supplies = acp_da7219_supplies,
+};
+
+static struct fixed_voltage_config acp_da7219 = {
+   .supply_name = "reg-fixed-1.8V",
+   .microvolts = 180, /* 1.8V */
+   .gpio = -EINVAL,
+   .enabled_at_boot = 1,
+   .init_data = &acp_da7219_data,
+};
+
+static struct platform_device acp_da7219_regulator = {
+   .name = "reg-fixed-voltage",
+   .id = PLATFORM_DEVID_AUTO,
+   .dev = {
+   .platform_data = &acp_da7219,
+   },
+};
+
 static int cz_probe(struct platform_device *pdev)
 {
int ret;
struct snd_soc_card *card;
struct acp_platform_info *machine;
+   static bool regulators_registered;
+
+   if (!regulators_registered) {
+   ret = platform_device_register(&acp_da7219_regulator);
+   if (ret) {
+   dev_err(&pdev->dev, "Failed to register regulator: 
%d\n",
+   ret);
+   return ret;
+   }
+   regulators_registered = true;
+   }
 
machine = devm_kzalloc(&pdev->dev, sizeof(struct acp_platform_info),
   GFP_KERNEL);
-- 
1.9.1



Re: [PATCH v3] Optimize C3 entry on Centaur CPUs

2018-07-19 Thread Thomas Gleixner
On Tue, 29 May 2018, David Wang wrote:

> For new Centaur CPUs the ucode will take care of the preservation of cache 
> coherence
> between CPU cores in C-states regardless of how deep the C-states are. So, it 
> is not
> necessary to flush the caches in software befor entering C3.
> 
> Signed-off-by: David Wang 

Reviewed-by: Thomas Gleixner 



Re: [PATCHv2 1/2] arm64: Add stack information to on_accessible_stack

2018-07-19 Thread Mark Rutland
On Thu, Jul 19, 2018 at 04:28:05PM -0700, Laura Abbott wrote:
> 
> In preparation for enabling the stackleak plugin on arm64,
> we need a way to get the bounds of the current stack. Extend
> on_accessible_stack to get this information.
> 
> Signed-off-by: Laura Abbott 
> ---
> v2: Switched to using struct stack_info for argument passing.
> on_accessible_stack is now the primary API. Split STACK_TYPE_SDEI
> into STACK_TYPE_SDEI_NORMAL and STACK_TYPE_SDEI_CRITICAL.

[...]

> -static inline bool on_irq_stack(unsigned long sp)
> +static inline bool on_irq_stack(unsigned long sp,
> + struct stack_info *info)
>  {
>   unsigned long low = (unsigned long)raw_cpu_read(irq_stack_ptr);
>   unsigned long high = low + IRQ_STACK_SIZE;
> @@ -47,46 +63,79 @@ static inline bool on_irq_stack(unsigned long sp)
>   if (!low)
>   return false;
>  
> - return (low <= sp && sp < high);
> + if (sp < low || sp >= high)
> + return false;
> +
> + if (info) {
> + info->low = low;
> + info->high = high;
> + info->type = STACK_TYPE_IRQ;
> + }
> +
> + return true;
>  }

[...]

> -bool _on_sdei_stack(unsigned long sp)
> +bool on_sdei_normal_stack(unsigned long sp,
> + struct stack_info *info)
> +{
> + unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_normal_ptr);
> + unsigned long high = low + SDEI_STACK_SIZE;
> +
> + if (low <= sp && sp < high) {
> + if (info) {
> + info->low = low;
> + info->high = high;
> + info->type = STACK_TYPE_SDEI_NORMAL;
> + }
> + return true;
> + }
> +
> + return false;
> +}
> +
> +bool on_sdei_critical_stack(unsigned long sp,
> + struct stack_info *info)
> +{
> + unsigned long low = (unsigned 
> long)raw_cpu_read(sdei_stack_critical_ptr);
> + unsigned long high = low + SDEI_STACK_SIZE;
> +
> + if (low <= sp && sp < high) {
> + if (info) {
> + info->low = low;
> + info->high = high;
> + info->type = STACK_TYPE_SDEI_CRITICAL;
> + }
> + return true;
> + }
> +
> + return false;
> +}

Minor nit, but it would be good to avoid the nested conditionals for these two
by bailing out early when the SP is out of bounds, as with the other
on__stack() functions, e.g.

bool on_sdei_normal_stack(unsigned long sp,
struct stack_info *info)
{
unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_normal_ptr);
unsigned long high = low + SDEI_STACK_SIZE;

if (sp < low || sp >= high)
return false;

if (info) {
info->low = low;
info->high = high;
info->type = STACK_TYPE_SDEI_NORMAL;
}

return true;
}

Otherwise, this all looks good to me. With that:

Reviewed-by: Mark Rutland 

Thanks for working on this!

Mark.


Re: [PATCH 0/4] Rework NVMe abort handling

2018-07-19 Thread Johannes Thumshirn
On Thu, Jul 19, 2018 at 08:04:09AM -0700, James Smart wrote:
> Which I'm going to say no on. I originally did the abort before the reset
> and it brought out some confusion in the reset code. Thus the existing flow
> which just resets the controller which has to be done after the abort
> anyway.

OK copied that.

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850


Re: [GIT PULL] nds32 fixes for 4.18

2018-07-19 Thread Greentime Hu
Greentime Hu  於 2018年7月17日 週二 下午2:34寫道:
>
> Hi Linus,
> Greentime Hu  於 2018年7月9日 週一 下午4:19寫道:
> >
> > The following changes since commit ce397d215ccd07b8ae3f71db689aedb85d56ab40:
> >
> >   Linux 4.18-rc1 (2018-06-17 08:04:49 +0900)
> >
> > are available in the Git repository at:
> >
> >   
> > ssh://g...@gitolite.kernel.org/pub/scm/linux/kernel/git/greentime/linux.git 
> > tags/nds32-for-linus-4.18
> >
> > for you to fetch changes up to 987553894f0ce8c1d83578136603a89009f42d35:
> >
> >   nds32: fix build error "relocation truncated to fit: 
> > R_NDS32_25_PCREL_RELA" when make allyesconfig (2018-07-05 16:13:47 +0800)
> >
> > 
> > nds32 patches for 4.18
> >
> > Here is the nds32 patch set based on 4.18-rc1.
> > Contained in here are the bug fixes and building error fixes for nds32.
> >
> > These are the LTP20170427 testing results.
> >
> > Total Tests: 1902
> > Total Skipped Tests: 593
> > Total Failures: 418
> > Kernel Version: 4.18.0-rc1-6-g987553894f0c-dirty
> > Machine Architecture: nds32
> >
> > Signed-off-by: Greentime Hu 
> >
> > 
> >
> > Greentime Hu (4):
> >   nds32: To implement these icache invalidation APIs since nds32 cores
> > don't snoop data cache. This issue is found by Guo Ren. Based on the
> > Documentation/core-api/cachetlb.rst and it says:
> >   nds32: Fix the dts pointer is not passed correctly issue.
> >   nds32: To simplify the implementation of update_mmu_cache()
> >   nds32: fix build error "relocation truncated to fit:
> > R_NDS32_25_PCREL_RELA" when make allyesconfig
> >
> > Guenter Roeck (1):
> >   nds32: Fix build error caused by configuration flag rename
> >
> > Luc Van Oostenryck (1):
> >   nds32: define __NDS32_E[BL]__ for sparse
> >
> >  arch/nds32/Kconfig  |  12 ++---
> >  arch/nds32/Makefile |   2 +
> >  arch/nds32/include/asm/cacheflush.h |   9 +++-
> >  arch/nds32/include/asm/futex.h  |   2 +-
> >  arch/nds32/kernel/setup.c   |   3 +-
> >  arch/nds32/mm/cacheflush.c  | 100 
> > +++-
> >  6 files changed, 58 insertions(+), 70 deletions(-)
> >
>
> Ping.
>
> Did this please-pull get lost or is there another reason that prevents
> the upstream integration?
>
> Thank you. :)

Sorry for that I forgot to add your email.
Ping again. :)


Re: [PATCH] ARM64: smp: BUG() if smp_send_reschedule() is called for an offline cpu

2018-07-19 Thread Mark Rutland
On Thu, Jul 19, 2018 at 03:12:49PM -0700, Venkata Narendra Kumar Gutta wrote:
> Based on the 'commit <8b775be35e41b9f> ("ARM: smp:
> BUG() if smp_send_reschedule() is called for an offline cpu")'

This commit does not appear to exist in mainline. Which tree is it in?

> Sending an IPI_RESCHEDULE to an offline CPU is incorrect and potentially
> bad for both power and stability. On some sub-architectures such as MSM,
> if a power-collapsed CPU is unexpectedly woken up by an IPI, it will be
> begin executing without the preparations that would normally happen as
> part of CPU_UP_PREPARE. If clocks, voltage regulators, or other hardware
> configuration are not performed, the booting CPU may cause general
> instability or (at best) poor power performance since the CPU would be
> powered up but not utilized.
> 
> One common cause for such issues is misuse of add_timer_on() or APIs
> such as queue_work_on() which call it. If proper precautions are not
> taken to block hotplug while these APIs are called then a race may
> result in IPIs being sent to CPUs that are already offline.
> 
> This same argument could be applied to other IPIs (with the exception
> of IPI_WAKEUP), but the others are already restricted to only online
> CPUs by existing mechanisms, so an explicit assertion is not useful.
> 
> Signed-off-by: Matt Wagantall 
> Signed-off-by: Trilok Soni 
> Signed-off-by: Venkata Narendra Kumar Gutta 
> ---
>  arch/arm64/kernel/smp.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c
> index 2faa986..5e39030 100644
> --- a/arch/arm64/kernel/smp.c
> +++ b/arch/arm64/kernel/smp.c
> @@ -898,6 +898,7 @@ void handle_IPI(int ipinr, struct pt_regs *regs)
>  
>  void smp_send_reschedule(int cpu)
>  {
> + BUG_ON(cpu_is_offline(cpu));
>   smp_cross_call(cpumask_of(cpu), IPI_RESCHEDULE);
>  }

Is BUG_ON() appropriate?

Why not WARN_ON() and return?

AFAICT, arm doesn't have this logic today either.

Thanks,
Mark.


Re: [PATCH] ARM64: smp: Fix cpu_up() racing with sys_reboot

2018-07-19 Thread Mark Rutland
On Thu, Jul 19, 2018 at 03:18:46PM -0700, Venkata Narendra Kumar Gutta wrote:
> Nothing stops a process from hotplugging in a CPU concurrently
> with a sys_reboot() call. In such a situation we could have
> ipi_cpu_stop() mark a cpu as 'offline' and _cpu_up() ignore the
> fact that the CPU is not really offline and call the
> CPU_UP_PREPARE notifier. When this happens stop_machine code will
> complain that the cpu thread already exists and BUG_ON().
> 
> CPU0  CPU1
> 
>  sys_reboot()
>  kernel_restart()
>  machine_restart()
>  machine_shutdown()
>  smp_send_stop()

>From a quick look arm64's machine_restart() disables IRQs, calls
smp_send_stop(), then calls one of:

* efi_reboot()
* arm_pm_restart()
* do_kernel_restart()

... and I can't see any of these calling machine_shutdown() directly.

How does machine_shutdown() get called? Is that somewhere in the restart_list
associated with do_kernel_restart?

>  ...   ipi_cpu_stop()
>  set_cpu_online(1, false)
>local_irq_disable()
>while(1)
> 

Given IRQs are disabled in machine_restart(), I don't understand how this
preemption can occur. Where do they get re-enabled?

>  cpu_up()
>  _cpu_up()
>  if (!cpu_online(1))
>  __cpu_notify(CPU_UP_PREPARE...)
> 
>  cpu_stop_cpu_callback()
>  BUG_ON(stopper->thread)
> 
> This is easily reproducible by hotplugging in and out in a tight
> loop while also rebooting.

Is this reproducible with mainline? e.g. v4.18-rc5?

I've packed away my HW in preparation for an office move, but I might be able
to give this a go in a VM.

> Since the CPU is not really offline and hasn't gone through the
> proper steps to be marked as such, let's mark the CPU as inactive.
> This is just as easily testable as online and avoids any possibility
> of _cpu_up() trying to bring the CPU back online when it never was
> offline to begin with. Based on the similar patchset by for arm
> targets 040c163( "ARM: smp: Fix cpu_up() racing with sys_reboot)"

Is this in mainline?

Looking at v4.18-rc5 I don't see arm's ipi_cpu_stop touching the active mask.

Thanks,
Mark.

> 
> Signed-off-by: Abhimanyu Kapur 
> Signed-off-by: Venkata Narendra Kumar Gutta 
> ---
>  arch/arm64/kernel/smp.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c
> index 2faa986..adee4d3 100644
> --- a/arch/arm64/kernel/smp.c
> +++ b/arch/arm64/kernel/smp.c
> @@ -790,7 +790,7 @@ void arch_irq_work_raise(void)
>   */
>  static void ipi_cpu_stop(unsigned int cpu)
>  {
> - set_cpu_online(cpu, false);
> + set_cpu_active(cpu, false);
>  
>   local_daif_mask();
>   sdei_mask_local_cpu();
> @@ -925,10 +925,10 @@ void smp_send_stop(void)
>  
>   /* Wait up to one second for other CPUs to stop */
>   timeout = USEC_PER_SEC;
> - while (num_online_cpus() > 1 && timeout--)
> + while (num_active_cpus() > 1 && timeout--)
>   udelay(1);
>  
> - if (num_online_cpus() > 1)
> + if (num_active_cpus() > 1)
>   pr_warning("SMP: failed to stop secondary CPUs %*pbl\n",
>  cpumask_pr_args(cpu_online_mask));
>  
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 


RE: [RFC PATCH 3/3] sdhci: arasan: Add support to read Tap Delay values from DT

2018-07-19 Thread Manish Narani
Hi Uffe,

> -Original Message-
> From: Ulf Hansson [mailto:ulf.hans...@linaro.org]
> Sent: Tuesday, July 10, 2018 2:02 PM
> To: Manish Narani 
> Cc: Rob Herring ; Mark Rutland
> ; Catalin Marinas ; Will
> Deacon ; Moritz Fischer ;
> stefan.krsmano...@aggios.com; Linux ARM  ker...@lists.infradead.org>; Linux Kernel Mailing List  ker...@vger.kernel.org>; linux-...@vger.kernel.org;
> devicet...@vger.kernel.org; Adrian Hunter ;
> Michal Simek 
> Subject: Re: [RFC PATCH 3/3] sdhci: arasan: Add support to read Tap Delay
> values from DT
> 
> On 7 June 2018 at 14:11, Manish Narani  wrote:
> > This patch adds support for reading Tap Delay values from Device Tree
> > and write them via eemi calls. The macros containing these tap delay
> > values are removed from the driver.
> >
> > Signed-off-by: Manish Narani 
> > ---
> >  drivers/mmc/host/sdhci-of-arasan.c | 131
> > +
> >  1 file changed, 131 insertions(+)
> >
> > diff --git a/drivers/mmc/host/sdhci-of-arasan.c
> > b/drivers/mmc/host/sdhci-of-arasan.c
> > index e3332a5..fc0fd01 100644
> > --- a/drivers/mmc/host/sdhci-of-arasan.c
> > +++ b/drivers/mmc/host/sdhci-of-arasan.c
> > @@ -36,6 +36,8 @@
> >
> >  #define PHY_CLK_TOO_SLOW_HZ40
> >
> > +#define MMC_BANK2  0x2
> > +
> >  /*
> >   * On some SoCs the syscon area has a feature where the upper 16-bits of
> >   * each 32-bit register act as a write mask for the lower 16-bits.
> > This allows @@ -90,6 +92,10 @@ struct sdhci_arasan_data {
> > struct sdhci_host *host;
> > struct clk  *clk_ahb;
> > struct phy  *phy;
> > +   u32 mio_bank;
> > +   u32 device_id;
> > +   u32 itapdly[MMC_TIMING_MMC_HS400 + 1];
> > +   u32 otapdly[MMC_TIMING_MMC_HS400 + 1];
> > boolis_phy_on;
> >
> > boolhas_cqe;
> > @@ -160,11 +166,36 @@ static int sdhci_arasan_syscon_write(struct
> sdhci_host *host,
> > return ret;
> >  }
> >
> > +/**
> > + * arasan_zynqmp_set_tap_delay - Program the tap delays.
> > + * @deviceid:  Unique Id of device
> > + * @itap_delay:Input Tap Delay
> > + * @oitap_delay:   Output Tap Delay
> > + */
> > +static void arasan_zynqmp_set_tap_delay(u8 deviceid, u8 itap_delay,
> > +u8 otap_delay) {
> > +   const struct zynqmp_eemi_ops *eemi_ops =
> > +zynqmp_pm_get_eemi_ops();
> 
> No thanks!
> 
> Isn't there a more generic framework we can use to change the tap values,
> rather than calling SoC specific functions from the driver?
Yes, Thanks for your suggestion. I will work on the generic framework which 
will be used to change tap values
Via SoC drivers.
> 
> BTW, what is a tap value, more exactly?
> What does changing a tap value mean and where does the property belong,
> really?
Tap Value is the delay of clock phase which is used to adjust phase to the 
working value. The auto tuning
process generally sets tap values internally in controller in SD UHS modes. But 
for other modes where
auto tuning is applicable, we are determining tap values via trial & error 
method for specific SoC.
> > 
> Of course this doesn't even compile, as you have a dependency to another
> series. Next time, please clarify that in a cover-letter (maybe you did, but I
> can't find it).
> 
> > +   u32 node_id = (deviceid == 0) ? NODE_SD_0 : NODE_SD_1;
> > +
> > +   if (!eemi_ops || !eemi_ops->ioctl)
> > +   return;
> > +
> > +   if (itap_delay)
> > +   eemi_ops->ioctl(node_id, IOCTL_SET_SD_TAPDELAY,
> > +   PM_TAPDELAY_INPUT, itap_delay, NULL);
> > +
> > +   if (otap_delay)
> > +   eemi_ops->ioctl(node_id, IOCTL_SET_SD_TAPDELAY,
> > +   PM_TAPDELAY_OUTPUT, otap_delay, NULL);
> > +}
> 
> Another overall comment for the series.
> 
> I would recommend to change the order of the patches in the series.
> Let the DT doc change come first, next the driver change and finally the 
> change
> to the DTS file(s). This makes it easier to follow and review.
Sure, I will do that.

Thanks & Regards,
Manish

> 
> [...]
> 
> Kind regards
> Uffe


Re: [PATCH 17/32] staging: gasket: annotate ioctl arg with __user

2018-07-19 Thread Greg Kroah-Hartman
On Thu, Jul 19, 2018 at 07:44:53PM -0700, Todd Poynor wrote:
> >>  /* Type of the ioctl permissions check callback. See below. */
> >>  typedef int (*gasket_ioctl_permissions_cb_t)(
> >> - struct file *filp, uint cmd, ulong arg);
> >> + struct file *filp, uint cmd, void __user *arg);
> >>
> >>  /*
> >>   * Device type descriptor.
> >> @@ -549,7 +549,7 @@ struct gasket_driver_desc {
> >>* return -EINVAL. Should return an error status (either -EINVAL or
> >>* the error result of the ioctl being handled).
> >>*/
> >> - long (*ioctl_handler_cb)(struct file *filp, uint cmd, ulong arg);
> >> + long (*ioctl_handler_cb)(struct file *filp, uint cmd, void __user 
> >> *arg);
> >
> > Why are you not using the typedef above?
> 
> There's a typedef for the permissions check callback, but not for the
> handler callback.  It's a bit confusing, so I tried adding a typedef
> for the handler, but now checkpatch is spanking me for adding new
> typedefs -- maybe I should drop the existing typedef?

No, typedefs for function pointers is just fine, checkpatch should not
be complaining about that.  And even if it is, it's just a guideline,
not a hard rule that you have to abide by everything it says :)

thanks,

greg k-h


Re: [PATCH] fs: iomap: Change return type to vm_fault_t

2018-07-19 Thread Darrick J. Wong
On Fri, Jul 20, 2018 at 10:31:30AM +0530, Souptick Joarder wrote:
> On Wed, Jul 4, 2018 at 3:22 AM, Andreas Gruenbacher  
> wrote:
> > On 3 July 2018 at 23:39, Darrick J. Wong  wrote:
> >> On Mon, Jul 02, 2018 at 07:52:41PM +0200, Andreas Gruenbacher wrote:
> >>> On 2 July 2018 at 17:43, Souptick Joarder  wrote:
> >>> > Return type has been changed to vm_fault_t type for
> >>> > iomap_page_mkwrite().
> >>> >
> >>> > see commit 1c8f422059ae ("mm: change return type to
> >>> > vm_fault_t") for reference.
> >>> >
> >>> > Signed-off-by: Souptick Joarder 
> >>> > Reviewed-by: Matthew Wilcox 
> >>
> >> I don't recall Christoph [now cc'd] rescinding his NAK of the previous
> >> version of this patch[1].  Has he changed his mind since May?
> >  /|\
> > Oops, a reply gone wrong -- I was me  |   to reply to Souptick
> > Joarder's gfs2 change which I've add  |   the gfs2 for-next branch.
> > Not the iomap change. Sorry for the   |  sion.
> >   |
> >> [1] https://spinics.net/lists/linux  |  vel/msg126032.html
> >>  |
> >> Now granted I didn't have a problem  |   the code (and applied the xfs
> >> version to 4.18 after monitoring to  |  sfy myself that nothing
> >> particularly weird happened during   |   but seeing as most of the iomap
> >> changes have gone through hch's rev  |  nd landed via the xfs tree...
  |
--D   |
  |
I wasn't planning on it, due to aforementioned NAK still being in place
to the best of my knowledge, at least for the iomap patch.

> Darrick, is this patch going to 4.19 through xfs tree ?


[PATCH 1/2] security/keys/secure_key: Adds the secure key support based on CAAM.

2018-07-19 Thread Udit Agarwal
Secure keys are derieved using CAAM crypto block.

Secure keys derieved are the random number symmetric keys from CAAM.
Blobs corresponding to the key are formed using CAAM. User space
will only be able to view the blob of the key.

Signed-off-by: Udit Agarwal 
Reviewed-by: Sahil Malhotra 
---
 Documentation/security/keys/secure-key.rst |  67 +++
 MAINTAINERS|  11 +
 include/keys/secure-type.h |  33 ++
 security/keys/Kconfig  |  11 +
 security/keys/Makefile |   3 +
 security/keys/secure_key.c | 339 
 security/keys/securekey_desc.c | 606 +
 security/keys/securekey_desc.h | 141 +
 8 files changed, 1211 insertions(+)
 create mode 100644 Documentation/security/keys/secure-key.rst
 create mode 100644 include/keys/secure-type.h
 create mode 100644 security/keys/secure_key.c
 create mode 100644 security/keys/securekey_desc.c
 create mode 100644 security/keys/securekey_desc.h

diff --git a/Documentation/security/keys/secure-key.rst 
b/Documentation/security/keys/secure-key.rst
new file mode 100644
index ..0fc3367b00f8
--- /dev/null
+++ b/Documentation/security/keys/secure-key.rst
@@ -0,0 +1,67 @@
+==
+Secure Key
+==
+
+Secure key is the new type added to kernel key ring service.
+Secure key is a symmetric type key of minimum length 32 bytes
+and with maximum possible length to be 128 bytes. It is produced
+in kernel using the CAAM crypto engine. Userspace can only see
+the blob for the corresponding key. All the blobs are displayed
+or loaded in hex ascii.
+
+Secure key can only be created on platforms which supports CAAM
+hardware block. Secure key can also be used as a master key to
+create the encrypted keys along with the existing key types in
+kernel.
+
+Secure key uses CAAM hardware to generate the key and blobify its
+content for userspace. Generated blobs are tied up with the hardware
+secret key stored in CAAM, hence the same blob will not be able to
+de-blobify with the different secret key on another machine.
+
+Usage::
+
+   keyctl add secure  "new " 
+   keyctl load secure  "load " 
+   keyctl print 
+
+"keyctl add secure" option will create the random data of the
+specified key len using CAAM and store it as a key in kernel.
+Key contents will be displayed as blobs to the user in hex ascii.
+User can input key len from 32 bytes to 128 bytes.
+
+"keyctl load secure" option will load the blob contents. In kernel,
+key will be deirved using input blob and CAAM, along with the secret
+key stored in CAAM.
+
+"keyctl print" will return the hex string of the blob corresponding to
+key_id. Returned blob will be of key_len + 48 bytes. Extra 48 bytes are
+the header bytes added by the CAAM.
+
+Example of secure key usage::
+
+1. Create the secure key with name kmk-master of length 32 bytes::
+
+   $ keyctl add secure kmk-master "new 32" @u
+   46001928
+
+   $keyctl show
+   Session Keyring
+   1030783626 --alswrv  0 65534  keyring: _uid_ses.0
+695927745 --alswrv  0 65534   \_ keyring: _uid.0
+ 46001928 --als-rv  0 0   \_ secure: kmk-master
+
+2. Print the blob contents for the kmk-master key::
+
+   $ keyctl print 46001928
+   d9743445b640f3d59c1670dddc0bc9c2
+   34fc9aab7dd05c965e6120025012f029b
+   07faa4776c4f6ed02899e35a135531e9a
+   6e5c2b51132f9d5aef28f68738e658296
+   3fe583177cfe50d2542b659a13039
+
+   $ keyctl pipe 46001928 > secure_key.blob
+
+3. Load the blob in the user key ring::
+
+   $ keyctl load secure kmk-master "load 'cat secure_key.blob'" @u
diff --git a/MAINTAINERS b/MAINTAINERS
index 9fd5e8808208..654be2ee4b0a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7939,6 +7939,17 @@ F:   include/keys/trusted-type.h
 F: security/keys/trusted.c
 F: security/keys/trusted.h
 
+KEYS-SECURE
+M: Udit Agarwal 
+R: Sahil Malhotra 
+L: linux-security-mod...@vger.kernel.org
+L: keyri...@vger.kernel.org
+S: Supported
+F: include/keys/secure-type.h
+F: security/keys/secure_key.c
+F: security/keys/securekey_desc.c
+F: security/keys/securekey_desc.h
+
 KEYS/KEYRINGS:
 M: David Howells 
 L: keyri...@vger.kernel.org
diff --git a/include/keys/secure-type.h b/include/keys/secure-type.h
new file mode 100644
index ..5b7a5f144e41
--- /dev/null
+++ b/include/keys/secure-type.h
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2018 NXP.
+ *
+ */
+
+#ifndef _KEYS_SECURE_TYPE_H
+#define _KEYS_SECURE_TYPE_H
+
+#include 
+#include 
+
+/* Minimum key size to be used is 32 bytes and maximum key size fixed
+ * is 128 bytes.
+ * Blob size to be kept is Maximum key size + blob header added by CAAM.
+ */
+
+#define MIN_KEY_SIZE32
+#define MAX_KEY_SIZE128
+#define BLOB_HEADER_SIZE   48
+
+#define 

[PATCH 2/2] encrypted_keys: Adds support for secure key-type as master key.

2018-07-19 Thread Udit Agarwal
Encrypted keys can use secure key-type as master key along with
trusted/user keys.

Secure key as master key uses, secure key type payload derieved
using CAAM hardware.

Signed-off-by: Udit Agarwal 
Reviewed-by: Sahil Malhotra 
---
 MAINTAINERS   |  1 +
 security/keys/encrypted-keys/Makefile |  2 +
 security/keys/encrypted-keys/encrypted.c  | 13 ++-
 security/keys/encrypted-keys/encrypted.h  | 13 +++
 .../keys/encrypted-keys/masterkey_secure.c| 37 +++
 5 files changed, 64 insertions(+), 2 deletions(-)
 create mode 100644 security/keys/encrypted-keys/masterkey_secure.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 654be2ee4b0a..847254eec22a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7949,6 +7949,7 @@ F:include/keys/secure-type.h
 F: security/keys/secure_key.c
 F: security/keys/securekey_desc.c
 F: security/keys/securekey_desc.h
+F: security/keys/encrypted-keys/masterkey_secure.c
 
 KEYS/KEYRINGS:
 M: David Howells 
diff --git a/security/keys/encrypted-keys/Makefile 
b/security/keys/encrypted-keys/Makefile
index 7a44dce6f69d..df2b906b7d24 100644
--- a/security/keys/encrypted-keys/Makefile
+++ b/security/keys/encrypted-keys/Makefile
@@ -7,5 +7,7 @@ obj-$(CONFIG_ENCRYPTED_KEYS) += encrypted-keys.o
 
 encrypted-keys-y := encrypted.o ecryptfs_format.o
 masterkey-$(CONFIG_TRUSTED_KEYS) := masterkey_trusted.o
+masterkey-$(CONFIG_SECURE_KEYS) := masterkey_secure.o
 masterkey-$(CONFIG_TRUSTED_KEYS)-$(CONFIG_ENCRYPTED_KEYS) := 
masterkey_trusted.o
+masterkey-$(CONFIG_SECURE_KEYS)-$(CONFIG_ENCRYPTED_KEYS) := masterkey_secure.o
 encrypted-keys-y += $(masterkey-y) $(masterkey-m-m)
diff --git a/security/keys/encrypted-keys/encrypted.c 
b/security/keys/encrypted-keys/encrypted.c
index d92cbf9687c3..258b38094705 100644
--- a/security/keys/encrypted-keys/encrypted.c
+++ b/security/keys/encrypted-keys/encrypted.c
@@ -39,6 +39,7 @@
 #include "ecryptfs_format.h"
 
 static const char KEY_TRUSTED_PREFIX[] = "trusted:";
+static const char KEY_SECURE_PREFIX[] = "secure:";
 static const char KEY_USER_PREFIX[] = "user:";
 static const char hash_alg[] = "sha256";
 static const char hmac_alg[] = "hmac(sha256)";
@@ -49,6 +50,7 @@ static unsigned int ivsize;
 static int blksize;
 
 #define KEY_TRUSTED_PREFIX_LEN (sizeof (KEY_TRUSTED_PREFIX) - 1)
+#define KEY_SECURE_PREFIX_LEN (sizeof(KEY_SECURE_PREFIX) - 1)
 #define KEY_USER_PREFIX_LEN (sizeof (KEY_USER_PREFIX) - 1)
 #define KEY_ECRYPTFS_DESC_LEN 16
 #define HASH_SIZE SHA256_DIGEST_SIZE
@@ -125,7 +127,7 @@ static int valid_ecryptfs_desc(const char *ecryptfs_desc)
 /*
  * valid_master_desc - verify the 'key-type:desc' of a new/updated master-key
  *
- * key-type:= "trusted:" | "user:"
+ * key-type:= "trusted:" | "user:" | "secure:"
  * desc:= master-key description
  *
  * Verify that 'key-type' is valid and that 'desc' exists. On key update,
@@ -140,6 +142,8 @@ static int valid_master_desc(const char *new_desc, const 
char *orig_desc)
 
if (!strncmp(new_desc, KEY_TRUSTED_PREFIX, KEY_TRUSTED_PREFIX_LEN))
prefix_len = KEY_TRUSTED_PREFIX_LEN;
+   else if (!strncmp(new_desc, KEY_SECURE_PREFIX, KEY_SECURE_PREFIX_LEN))
+   prefix_len = KEY_SECURE_PREFIX_LEN;
else if (!strncmp(new_desc, KEY_USER_PREFIX, KEY_USER_PREFIX_LEN))
prefix_len = KEY_USER_PREFIX_LEN;
else
@@ -358,7 +362,7 @@ static int calc_hmac(u8 *digest, const u8 *key, unsigned 
int keylen,
 
 enum derived_key_type { ENC_KEY, AUTH_KEY };
 
-/* Derive authentication/encryption key from trusted key */
+/* Derive authentication/encryption key from trusted/secure key */
 static int get_derived_key(u8 *derived_key, enum derived_key_type key_type,
   const u8 *master_key, size_t master_keylen)
 {
@@ -429,6 +433,11 @@ static struct key *request_master_key(struct 
encrypted_key_payload *epayload,
mkey = request_trusted_key(epayload->master_desc +
   KEY_TRUSTED_PREFIX_LEN,
   master_key, master_keylen);
+   } else if (!strncmp(epayload->master_desc, KEY_SECURE_PREFIX,
+   KEY_SECURE_PREFIX_LEN)) {
+   mkey = request_secure_key(epayload->master_desc +
+ KEY_SECURE_PREFIX_LEN,
+ master_key, master_keylen);
} else if (!strncmp(epayload->master_desc, KEY_USER_PREFIX,
KEY_USER_PREFIX_LEN)) {
mkey = request_user_key(epayload->master_desc +
diff --git a/security/keys/encrypted-keys/encrypted.h 
b/security/keys/encrypted-keys/encrypted.h
index 1809995db452..f1cb73611e77 100644
--- a/security/keys/encrypted-keys/encrypted.h
+++ b/security/keys/encrypted-keys/encrypted.h
@@ -16,6 +16,19 @@ static inline struct key *request_trusted_key(const char 
*trusted_desc,
 }
 #endif
 
+#if defined(

Re: [PATCH v3 2/6] KVM: X86: Implement PV IPIs in linux guest

2018-07-19 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 00:47, Paolo Bonzini  wrote:
>
> On 19/07/2018 18:28, Radim Krčmář wrote:
> >> +
> >> +kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap_low, ipi_bitmap_high, 
> >> vector);
> > and
> >
> >   kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap[0], ipi_bitmap[1], vector);
> >
> > Still, the main problem is that we can only address 128 APICs.
> >
> > A simple improvement would reuse the vector field (as we need only 8
> > bits) and put a 'offset' in the rest.  The offset would say which
> > cluster of 128 are we addressing.  24 bits of offset results in 2^31
> > total addressable CPUs (we probably should even use that many bits).
> > The downside of this is that we can only address 128 at a time.
> >
> > It's basically the same as x2apic cluster mode, only with 128 cluster
> > size instead of 16, so the code should be a straightforward port.
> > And because x2apic code doesn't seem to use any division by the cluster
> > size, we could even try to use kvm_hypercall4, add ipi_bitmap[2], and
> > make the cluster size 192. :)
>
> I did suggest an offset earlier in the discussion.
>
> The main problem is that consecutive CPU ids do not map to consecutive
> APIC ids.  But still, we could do an hypercall whenever the total range
> exceeds 64.  Something like
>
> u64 ipi_bitmap = 0;
> for_each_cpu(cpu, mask)
> if (!ipi_bitmap) {
> min = max = cpu;
> } else if (cpu < min && max - cpu < 64) {
> ipi_bitmap <<= min - cpu;
> min = cpu;
> } else if (id < min + 64) {
> max = cpu < max ? max : cpu;
> } else {
> /* ... send hypercall... */
> min = max = cpu;
> ipi_bitmap = 0;
> }
> __set_bit(ipi_bitmap, cpu - min);
> }
> if (ipi_bitmap) {
> /* ... send hypercall... */
> }
>
> We could keep the cluster size of 128, but it would be more complicated
> to do the left shift in the first "else if".  If the limit is 64, you
> can keep the two arguments in the hypercall, and just pass 0 as the
> "high" bitmap on 64-bit kernels.

As David pointed out, we need to scale to higher APIC IDs. I will add
the cpu id to apic id transfer in the for loop. How about:
kvm_hypercall2(KVM_HC_SEND_IPI, ipi_bitmap, vector); directly. In
addition, why need to pass the 0 as the "high" bitmap even if for 128
vCPUs case?

Regards,
Wanpeng Li


Re: m68k allmodconfig build errors

2018-07-19 Thread Finn Thain
On Thu, 19 Jul 2018, Randy Dunlap wrote:

> Hi Geert,
> 
> I am seeing a few errors when cross-building m68k on x86_64, using the 
> toolchain at https://mirrors.edge.kernel.org/pub/tools/crosstool/ 
> (thanks, Arnd). (so this is gcc 8.1.0)
> 
> block/partitions/ldm.o: In function `ldm_partition':
> ldm.c:(.text+0x1900): undefined reference to `strcmp'
> ldm.c:(.text+0x1964): undefined reference to `strcmp'
> drivers/rtc/rtc-proc.o: In function `is_rtc_hctosys':
> rtc-proc.c:(.text+0x290): undefined reference to `strcmp'
> drivers/watchdog/watchdog_pretimeout.o: In function 
> `watchdog_register_governor':
> (.text+0x142): undefined reference to `strcmp'
> 
> 
> Adding #include  does not help.
> 
> Is this a toolchain problem or drivers or something else?
> 

This gcc build was apparently configured like so:

/home/arnd/git/gcc/configure --target=m68k-linux --enable-targets=all 
--prefix=/home/arnd/cross/x86_64/gcc-8.1.0-nolibc/m68k-linux 
--enable-languages=c --without-headers --disable-bootstrap --disable-nls 
--disable-threads --disable-shared --disable-libmudflap --disable-libssp 
--disable-libgomp --disable-decimal-float --disable-libquadmath 
--disable-libatomic --disable-libcc1 --disable-libmpx 
--enable-checking=release

In my own cross toolchain builds strcmp comes from glibc but this 
toolchain has no libc at all.

> help?
> 

Linux will use the strcmp in lib/string.c unless __HAVE_ARCH_STRCMP is 
defined in the arch headers. Grep suggests that m68k, mips, x86, xtensa, 
arc, sh, arm64, s390 all define that macro. But maybe you could just patch 
out that definition for build testing.

-- 

> thanks,
> 


[PATCH v6 4/4] MAINTAINERS: add an entry for MediaTek Bluetooth driver

2018-07-19 Thread sean.wang
From: Sean Wang 

Add an entry for the MediaTek Bluetooth driver.

Signed-off-by: Sean Wang 
---
 MAINTAINERS | 8 
 1 file changed, 8 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 20de9a5..5d81cc1 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8780,6 +8780,14 @@ F:   include/uapi/linux/meye.h
 F: include/uapi/linux/ivtv*
 F: include/uapi/linux/uvcvideo.h
 
+MEDIATEK BLUETOOTH DRIVER
+M: Sean Wang 
+L: linux-blueto...@vger.kernel.org
+L: linux-media...@lists.infradead.org (moderated for non-subscribers)
+S: Maintained
+F: Documentation/devicetree/bindings/net/mediatek-bluetooth.txt
+F: drivers/bluetooth/btmtkuart.c
+
 MEDIATEK CIR DRIVER
 M: Sean Wang 
 S: Maintained
-- 
2.7.4



[PATCH v6 1/4] dt-bindings: net: bluetooth: Add mediatek-bluetooth

2018-07-19 Thread sean.wang
From: Sean Wang 

Add binding document for a SoC built-in device using MediaTek protocol.
Which could be found on MT7622 SoC or other similar MediaTek SoCs.

Signed-off-by: Sean Wang 
Reviewed-by: Rob Herring 
---
 .../devicetree/bindings/net/mediatek-bluetooth.txt | 35 ++
 1 file changed, 35 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/mediatek-bluetooth.txt

diff --git a/Documentation/devicetree/bindings/net/mediatek-bluetooth.txt 
b/Documentation/devicetree/bindings/net/mediatek-bluetooth.txt
new file mode 100644
index 000..14ceb2a
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/mediatek-bluetooth.txt
@@ -0,0 +1,35 @@
+MediaTek SoC built-in Bluetooth Devices
+==
+
+This device is a serial attached device to BTIF device and thus it must be a
+child node of the serial node with BTIF. The dt-bindings details for BTIF
+device can be known via Documentation/devicetree/bindings/serial/8250.txt.
+
+Required properties:
+
+- compatible:  Must be
+ "mediatek,mt7622-bluetooth": for MT7622 SoC
+- clocks:  Should be the clock specifiers corresponding to the entry in
+   clock-names property.
+- clock-names: Should contain "ref" entries.
+- power-domains: Phandle to the power domain that the device is part of
+
+Example:
+
+   btif: serial@1100c000 {
+   compatible = "mediatek,mt7622-btif",
+"mediatek,mtk-btif";
+   reg = <0 0x1100c000 0 0x1000>;
+   interrupts = ;
+   clocks = <&pericfg CLK_PERI_BTIF_PD>;
+   clock-names = "main";
+   reg-shift = <2>;
+   reg-io-width = <4>;
+
+   bluetooth {
+   compatible = "mediatek,mt7622-bluetooth";
+   power-domains = <&scpsys MT7622_POWER_DOMAIN_WB>;
+   clocks = <&clk25m>;
+   clock-names = "ref";
+   };
+   };
-- 
2.7.4



Re: potential deadlock in cpufreq-dt

2018-07-19 Thread Viresh Kumar
+ linux-pm list.

On 19-07-18, 16:44, Jiada Wang wrote:
> Hello all
> 
> After enable lockdep, by poking /sys/kernel/debug/sched_features,
> I triggered the following lockdep report:
> 
> [   34.410559] ==
> [   34.416766] WARNING: possible circular locking dependency detected
> [   34.422987] 4.14.50-03493-g65adcd3b74c9-dirty #203 Tainted: G C
> [   34.450785] --
> [   34.457001] systemd-udevd/1490 is trying to acquire lock:
> [   34.462432]  (
> [   34.464102] opp_table_lock
> [   34.466814] ){+.+.}
> [   34.468932] , at: []
> dev_pm_opp_get_opp_table+0x2c/0x140
> [   34.475819]
>but task is already holding lock:
> [   34.481689]  (
> [   34.483359] subsys mutex
> [   34.485914] #6
> [   34.487587] ){+.+.}
> [   34.489701] , at: []
> subsys_interface_register+0x68/0x118
> [   34.496677]
>which lock already depends on the new lock.
> 
> [   34.504890]
>the existing dependency chain (in reverse order) is:
> [   34.512406]
>-> #3
> [   34.515836]  (
> [   34.517505] subsys mutex
> [   34.520045] #6
> [   34.521715] ){+.+.}linux-kernel@vger.kernel.org
> [   34.523819] :
> [   34.525412]__mutex_lock+0x94/0x840
> [   34.529543]mutex_lock_nested+0x1c/0x24
> [   34.534022]subsys_interface_register+0x68/0x118
> [   34.539284]cpufreq_register_driver+0x10c/0x1d8
> [   34.544464]dt_cpufreq_probe+0xcc/0x108 [cpufreq_dt]
> [   34.550074]platform_drv_probe+0x58/0xa8
> [   34.554637]driver_probe_device+0x200/0x2b4
> [   34.559463]__driver_attach+0x7c/0xac
> [   34.563768]bus_for_each_dev+0xa0/0xb8
> [   34.568169]driver_attach+0x20/0x28
> [   34.568173]bus_add_driver+0x19c/0x1d8
> [   34.568177]driver_register+0x98/0xd0
> [   34.568187]__platform_driver_register+0x48/0x50
> [   34.568198]dt_cpufreq_platdrv_init+0x18/0x1000 [cpufreq_dt]
> [   34.568205]do_one_initcall+0x120/0x13c
> [   34.568212]do_init_module+0x5c/0x1c8
> [   34.568215]load_module+0x20f0/0x2150
> [   34.568218]SyS_finit_module+0xd4/0xe8
> [   34.568220]el0_svc_naked+0x34/0x38
> [   34.568224]
>-> #2
> [   34.568225]  (
> [   34.568228] cpu_hotplug_lock.rw_sem
> [   34.568229] ){}
> [   34.568230] :
> [   34.568236]cpus_read_lock+0x54/0xcc
> [   34.568241]static_key_enable+0x14/0x2c
> [   34.568247]sched_feat_write+0xd0/0x1c4
> [   34.568252]full_proxy_write+0x6c/0xac
> [   34.568257]__vfs_write+0x34/0x138
> [   34.568260]vfs_write+0xc0/0x17c
> [   34.568262]SyS_write+0x60/0xb8
> [   34.568265]el0_svc_naked+0x34/0x38
> [   34.568266]
>-> #1
> [   34.568267]  (
> [   34.568269] &sb->s_type->i_mutex_key
> [   34.568271] #3
> [   34.568272] ){+.+.}
> [   34.568273] :
> [   34.568279]down_write+0x48/0x84
> [   34.568282]start_creating+0x7c/0xd0
> [   34.568284]debugfs_create_dir+0x14/0xbc
> [   34.568289]opp_debug_register+0x68/0xa8
> [   34.568293]_add_opp_dev+0x78/0xb4
> [   34.568296]dev_pm_opp_get_opp_table+0x7c/0x140
> [   34.568300]dev_pm_opp_of_add_table+0x1e0/0x4a4
> [   34.568306]InitDVFS+0x7c/0x37c
> [   34.568314]PVRSRVDeviceCreate+0x324/0x610
> [   34.568317]pvr_drm_load+0x64/0x128
> [   34.568322]pvr_probe+0x70/0xa0
> [   34.568325]platform_drv_probe+0x58/0xa8
> [   34.568328]driver_probe_device+0x200/0x2b4
> [   34.568331]__driver_attach+0x7c/0xac
> [   34.568334]bus_for_each_dev+0xa0/0xb8
> [   34.568337]driver_attach+0x20/0x28
> [   34.568340]bus_add_driver+0x19c/0x1d8
> [   34.568343]driver_register+0x98/0xd0
> [   34.568346]__platform_driver_register+0x48/0x50
> [   34.568352]pvr_init+0x50/0x58
> [   34.568355]do_one_initcall+0x120/0x13c
> [   34.568360]kernel_init_freeable+0x26c/0x270
> [   34.568366]kernel_init+0x10/0xfc
> [   34.568369]ret_from_fork+0x10/0x18
> [   34.568370]
>-> #0
> [   34.568372]  (
> [   34.568373] opp_table_lock
> [   34.568375] ){+.+.}
> [   34.568376] :
> [   34.568381]lock_acquire+0x224/0x250
> [   34.568384]__mutex_lock+0x94/0x840
> [   34.568387]mutex_lock_nested+0x1c/0x24
> [   34.568391]dev_pm_opp_get_opp_table+0x2c/0x140
> [   34.568394]dev_pm_opp_set_regulators+0x30/0x190
> [   34.568400]cpufreq_init+0xe4/0x304 [cpufreq_dt]
> [   34.568405]cpufreq_online+0x174/0x5d8
> [   34.568408]cpufreq_add_dev+0x60/0x78linux-ker...@vger.kernel.org
> [   34.568411]subsys_interface_register+0x100/0x118
> [   34.568414]cpufreq_register_driver+0x10c/0x1d8
> [   34.568419]dt_cpufreq_probe+0xcc/0x108 [cpufreq_dt]
> [   34.5

[PATCH v6 3/4] Bluetooth: mediatek: Add protocol support for MediaTek serial devices

2018-07-19 Thread sean.wang
From: Sean Wang 

This adds a driver to run on the top of btuart driver for the MediaTek
serial protocol based on running H:4, which can enable the built-in
Bluetooth device inside MT7622 SoC.

Signed-off-by: Sean Wang 
---
 drivers/bluetooth/Kconfig |  11 +
 drivers/bluetooth/Makefile|   2 +
 drivers/bluetooth/btmtkuart.c | 552 ++
 drivers/bluetooth/btmtkuart.h |  83 +++
 4 files changed, 648 insertions(+)
 create mode 100644 drivers/bluetooth/btmtkuart.c
 create mode 100644 drivers/bluetooth/btmtkuart.h

diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
index a164ac4..074737c 100644
--- a/drivers/bluetooth/Kconfig
+++ b/drivers/bluetooth/Kconfig
@@ -74,6 +74,17 @@ config BT_HCIBTSDIO
  Say Y here to compile support for Bluetooth SDIO devices into the
  kernel or say M to compile it as module (btsdio).
 
+config BT_HCIBTUART_MTK
+   tristate "MediaTek HCI UART driver"
+   depends on SERIAL_DEV_BUS
+   help
+ MediaTek Bluetooth HCI UART driver.
+ This driver is required if you want to use MediaTek Bluetooth
+ with serial interface.
+
+ Say Y here to compile support for MediaTek Bluetooth UART devices
+ into the kernel or say M to compile it as module (btmtkuart).
+
 config BT_HCIUART
tristate "HCI UART driver"
depends on SERIAL_DEV_BUS || !SERIAL_DEV_BUS
diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile
index 2fb6268..2aea62e 100644
--- a/drivers/bluetooth/Makefile
+++ b/drivers/bluetooth/Makefile
@@ -25,6 +25,8 @@ obj-$(CONFIG_BT_BCM)  += btbcm.o
 obj-$(CONFIG_BT_RTL)   += btrtl.o
 obj-$(CONFIG_BT_QCA)   += btqca.o
 
+obj-$(CONFIG_BT_HCIBTUART_MTK) += btmtkuart.o
+
 obj-$(CONFIG_BT_HCIUART_NOKIA) += hci_nokia.o
 
 btmrvl-y   := btmrvl_main.o
diff --git a/drivers/bluetooth/btmtkuart.c b/drivers/bluetooth/btmtkuart.c
new file mode 100644
index 000..dd800ac
--- /dev/null
+++ b/drivers/bluetooth/btmtkuart.c
@@ -0,0 +1,552 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2018 MediaTek Inc.
+
+/*
+ * Bluetooth support for MediaTek serial devices
+ *
+ * Author: Sean Wang 
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include "btmtkuart.h"
+#include "h4_recv.h"
+
+static void mtk_stp_reset(struct mtk_stp_splitter *sp)
+{
+   sp->cursor = 2;
+   sp->dlen = 0;
+}
+
+static const unsigned char *
+mtk_stp_split(struct mtk_btuart_dev *bdev, struct mtk_stp_splitter *sp,
+ const unsigned char *data, int count, int *sz_h4)
+{
+   struct mtk_stp_hdr *shdr;
+
+   /* The cursor is reset when all the data of STP is consumed out. */
+   if (!sp->dlen && sp->cursor >= 6)
+   sp->cursor = 0;
+
+   /* Filling pad until all STP info is obtained. */
+   while (sp->cursor < 6 && count > 0) {
+   sp->pad[sp->cursor] = *data;
+   sp->cursor++;
+   data++;
+   count--;
+   }
+
+   /* Retrieve STP info and have a sanity check. */
+   if (!sp->dlen && sp->cursor >= 6) {
+   shdr = (struct mtk_stp_hdr *)&sp->pad[2];
+   sp->dlen = shdr->dlen1 << 8 | shdr->dlen2;
+
+   /* Resync STP when unexpected data is being read. */
+   if (shdr->prefix != 0x80 || sp->dlen > 2048) {
+   bt_dev_err(bdev->hdev, "stp format unexpect (%d, %d)",
+  shdr->prefix, sp->dlen);
+   mtk_stp_reset(sp);
+   }
+   }
+
+   /* Directly quit when there's no data found for H4 can process. */
+   if (count <= 0)
+   return NULL;
+
+   /* Tranlate to how much the size of data H4 can handle so far. */
+   *sz_h4 = min_t(int, count, sp->dlen);
+
+   /* Update the remaining size of STP packet. */
+   sp->dlen -= *sz_h4;
+
+   /* Data points to STP payload which can be handled by H4. */
+   return data;
+}
+
+static int mtk_stp_send(struct mtk_btuart_dev *bdev, struct sk_buff *skb)
+{
+   struct mtk_stp_hdr *shdr;
+   struct sk_buff *new_skb;
+   int dlen;
+
+   memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
+   dlen = skb->len;
+
+   /* Make sure of STP header at least has 4-bytes free space to fill. */
+   if (unlikely(skb_headroom(skb) < sizeof(*shdr))) {
+   new_skb = skb_realloc_headroom(skb, sizeof(*shdr));
+   kfree_skb(skb);
+   skb = new_skb;
+   }
+
+   /* Build for STP packet format. */
+   shdr = skb_push(skb, sizeof(*shdr));
+   mtk_make_stp_hdr(shdr, 0, dlen);
+   skb_put_zero(skb, MTK_STP_TLR_SIZE);
+
+   skb_queue_tail(&bdev->txq, skb);
+
+   return 0;
+}
+
+static int mtk_hci_wmt_sync(struct hci_dev *hdev, u8 opcode, u8 flag,
+ 

[PATCH v6 2/4] Bluetooth: Add new quirk for non-persistent setup settings

2018-07-19 Thread sean.wang
From: Sean Wang 

Add a new quirk HCI_QUIRK_NON_PERSISTENT_SETUP allowing that a quirk that
runs setup() after every open() and not just after the first open().

Signed-off-by: Sean Wang 
---
 include/net/bluetooth/hci.h | 9 +
 net/bluetooth/hci_core.c| 3 ++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 1668211..b37d973 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -183,6 +183,15 @@ enum {
 * during the hdev->setup vendor callback.
 */
HCI_QUIRK_NON_PERSISTENT_DIAG,
+
+   /* When this quirk is set, setup() would be run after every
+* open() and not just after the first open().
+*
+* This quirk can be set before hci_register_dev is called or
+* during the hdev->setup vendor callback.
+*
+*/
+   HCI_QUIRK_NON_PERSISTENT_SETUP,
 };
 
 /* HCI device flags */
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 40d260f..7de712e2 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1377,7 +1377,8 @@ static int hci_dev_do_open(struct hci_dev *hdev)
atomic_set(&hdev->cmd_cnt, 1);
set_bit(HCI_INIT, &hdev->flags);
 
-   if (hci_dev_test_flag(hdev, HCI_SETUP)) {
+   if (hci_dev_test_flag(hdev, HCI_SETUP) ||
+   test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks)) {
hci_sock_dev_event(hdev, HCI_DEV_SETUP);
 
if (hdev->setup)
-- 
2.7.4



[PATCH v6 0/4] add support for Bluetooth on MT7622 SoC

2018-07-19 Thread sean.wang
From: Sean Wang 

v6 and changes since v5:
 - make btmtkuart become a separate driver.
 - drop already applied patches and the patch for btuart driver
 - refine comments in driver allowing people know that mtk extra header
   + length doesn't indicate a full H:4 frame, things can fragment.
 - enhance dt-binding document with removing mistaken added " and improve
   English sentence.
 - remove unnecessary '\n' with bt_dev_err.
 - refine code style.
 - set hdev->manufacturer as mtk id.

v5 and changes since v4:
 - add Reviewed-by Tag from Ulf Hansson for patch 2
 - remove default y in Kconfig for btmtkuart selection to avoid overkill for
   users which would like to have less an amount on stuff in kernel.
 - list header declarations in alphabetical order and add a proper blank line
   within.
 - remove unused macro.
 - use sizeof to calculate structure size instead of an aextra macro to 
hardcode.
 - use struct hci_dev * as input paraments for mtk_hci_wmt_sync and mtk_setup_fw
   for that can be reused in mtk bluetooth with other interfaces.
 - remove unused local variabled in mtk_btuart_recv.
 - remove superfluous :8 for dlen2 in struct mtk_stp_hdr definition.
 - give a reasonable naming for these labels and add a pm_runtime_put_noidle()
   in the path undoing failing pm_runtime_get_sync().
 - Turn __u8 into u8 in struct mtk_stp_hdr.

 Really thanks for these reviews by Johan Hovold and Andy Shevchenko

v4 and changes since v3:
 - refine patch 2 based on commit 919b7308fcc4 to allow that
   dev_pm_domain_attach() will return better error codes. 

v3 and changes since v2
* all changes happen on patch 6
 - fix up SPDX license style for btmtkuart.h.
 - change firmware download from in ACL data to in HCI commands
   and then remove unused mtk_acl_wmt_sync and related code.
 - add a workaround replacing bad vendor event id 0xe4 with 0xff every
   vendor should use.
 - add a sanity check for mtk_hci_wmt_sync to verifying if
   input parameters are valid.
 - add an atomic_inc(&bdev->hdev->cmd_cnt) for __hci_cmd_sync_ev.
 - be changed to use firmware with a header called mt7622pr2h.bin.

v2 and changes since v1
 - Dropped patches already being applied
 - Rewirte the whole driver using btuart [1], and add slight extension
   of btuart to fit into btmtkuart driver. Beware that [1] is also pulled
   into one part of the series for avoiding any breakage when the patchset
   is being compiled.

[1] btuart 
https://www.spinics.net/lists/linux-bluetooth/msg74918.html

v1:

Hi,

This patchset introduces built-in Bluetooth support on MT7622 SoC.
And, it should be simple to make an extension to support other
MediaTek SoCs with adjusting a few of changes on the initialization
sequence of the device.

Before the main driver is being introduced, a few of things about
power-domain management should be re-worked for serdev core and MediaTek
SCPSYS to allow the Bluetooth to properly power up.

Patch 2: add a generic way attaching power domain to serdev
Patch 3 and 4: add cleanups with reuse APIs from Linux core
Patch 5: fix a limitation about power enablement Bluetooth depends on
Patch 1, 6 and 7: the major part of adding Bluetooth support to MT7622

Sean

Sean Wang (4):
  dt-bindings: net: bluetooth: Add mediatek-bluetooth
  Bluetooth: Add new quirk for non-persistent setup settings
  Bluetooth: mediatek: Add protocol support for MediaTek serial devices
  MAINTAINERS: add an entry for MediaTek Bluetooth driver

 .../devicetree/bindings/net/mediatek-bluetooth.txt |  35 ++
 MAINTAINERS|   8 +
 drivers/bluetooth/Kconfig  |  11 +
 drivers/bluetooth/Makefile |   2 +
 drivers/bluetooth/btmtkuart.c  | 552 +
 drivers/bluetooth/btmtkuart.h  |  83 
 include/net/bluetooth/hci.h|   9 +
 net/bluetooth/hci_core.c   |   3 +-
 8 files changed, 702 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/net/mediatek-bluetooth.txt
 create mode 100644 drivers/bluetooth/btmtkuart.c
 create mode 100644 drivers/bluetooth/btmtkuart.h

-- 
2.7.4



[tip:x86/pti] x86/pti: Check the return value of pti_user_pagetable_walk_pmd()

2018-07-19 Thread tip-bot for Jiang Biao
Commit-ID:  8c934e01a7ce685d98e970880f5941d79272c654
Gitweb: https://git.kernel.org/tip/8c934e01a7ce685d98e970880f5941d79272c654
Author: Jiang Biao 
AuthorDate: Fri, 20 Jul 2018 08:06:32 +0800
Committer:  Thomas Gleixner 
CommitDate: Fri, 20 Jul 2018 07:07:39 +0200

x86/pti: Check the return value of pti_user_pagetable_walk_pmd()

pti_user_pagetable_walk_pmd() can return NULL, so the return value should
be checked to prevent a NULL pointer dereference.

Add the check and a warning when the PMD allocation fails.

Signed-off-by: Jiang Biao 
Signed-off-by: Thomas Gleixner 
Cc: dave.han...@linux.intel.com
Cc: l...@kernel.org
Cc: h...@zytor.com
Cc: albca...@gmail.com
Cc: zhong.weid...@zte.com.cn
Link: 
https://lkml.kernel.org/r/1532045192-49622-2-git-send-email-jiang.bi...@zte.com.cn

---
 arch/x86/mm/pti.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
index 001ee6b0619e..bcf35dac1920 100644
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -205,7 +205,7 @@ static pmd_t *pti_user_pagetable_walk_pmd(unsigned long 
address)
BUILD_BUG_ON(p4d_large(*p4d) != 0);
if (p4d_none(*p4d)) {
unsigned long new_pud_page = __get_free_page(gfp);
-   if (!new_pud_page)
+   if (WARN_ON_ONCE(!new_pud_page))
return NULL;
 
set_p4d(p4d, __p4d(_KERNPG_TABLE | __pa(new_pud_page)));
@@ -219,7 +219,7 @@ static pmd_t *pti_user_pagetable_walk_pmd(unsigned long 
address)
}
if (pud_none(*pud)) {
unsigned long new_pmd_page = __get_free_page(gfp);
-   if (!new_pmd_page)
+   if (WARN_ON_ONCE(!new_pmd_page))
return NULL;
 
set_pud(pud, __pud(_KERNPG_TABLE | __pa(new_pmd_page)));
@@ -241,9 +241,13 @@ static pmd_t *pti_user_pagetable_walk_pmd(unsigned long 
address)
 static __init pte_t *pti_user_pagetable_walk_pte(unsigned long address)
 {
gfp_t gfp = (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO);
-   pmd_t *pmd = pti_user_pagetable_walk_pmd(address);
+   pmd_t *pmd;
pte_t *pte;
 
+   pmd = pti_user_pagetable_walk_pmd(address);
+   if (!pmd)
+   return NULL;
+
/* We can't do anything sensible if we hit a large mapping. */
if (pmd_large(*pmd)) {
WARN_ON(1);


[tip:x86/pti] x86/pti: Check the return value of pti_user_pagetable_walk_p4d()

2018-07-19 Thread tip-bot for Jiang Biao
Commit-ID:  b2b7d986a89b6c94b1331a909de1217214fb08c1
Gitweb: https://git.kernel.org/tip/b2b7d986a89b6c94b1331a909de1217214fb08c1
Author: Jiang Biao 
AuthorDate: Fri, 20 Jul 2018 08:06:31 +0800
Committer:  Thomas Gleixner 
CommitDate: Fri, 20 Jul 2018 07:07:39 +0200

x86/pti: Check the return value of pti_user_pagetable_walk_p4d()

pti_user_pagetable_walk_p4d() can return NULL, so the return value should
be checked to prevent a NULL pointer dereference.

Add the check and a warning when the P4D allocation fails.

Signed-off-by: Jiang Biao 
Signed-off-by: Thomas Gleixner 
Cc: dave.han...@linux.intel.com
Cc: l...@kernel.org
Cc: h...@zytor.com
Cc: albca...@gmail.com
Cc: zhong.weid...@zte.com.cn
Link: 
https://lkml.kernel.org/r/1532045192-49622-1-git-send-email-jiang.bi...@zte.com.cn

---
 arch/x86/mm/pti.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
index 7b1c85759005..001ee6b0619e 100644
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -176,7 +176,7 @@ static p4d_t *pti_user_pagetable_walk_p4d(unsigned long 
address)
 
if (pgd_none(*pgd)) {
unsigned long new_p4d_page = __get_free_page(gfp);
-   if (!new_p4d_page)
+   if (WARN_ON_ONCE(!new_p4d_page))
return NULL;
 
set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(new_p4d_page)));
@@ -195,9 +195,13 @@ static p4d_t *pti_user_pagetable_walk_p4d(unsigned long 
address)
 static pmd_t *pti_user_pagetable_walk_pmd(unsigned long address)
 {
gfp_t gfp = (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO);
-   p4d_t *p4d = pti_user_pagetable_walk_p4d(address);
+   p4d_t *p4d;
pud_t *pud;
 
+   p4d = pti_user_pagetable_walk_p4d(address);
+   if (!p4d)
+   return NULL;
+
BUILD_BUG_ON(p4d_large(*p4d) != 0);
if (p4d_none(*p4d)) {
unsigned long new_pud_page = __get_free_page(gfp);
@@ -359,6 +363,9 @@ static void __init pti_clone_p4d(unsigned long addr)
pgd_t *kernel_pgd;
 
user_p4d = pti_user_pagetable_walk_p4d(addr);
+   if (!user_p4d)
+   return;
+
kernel_pgd = pgd_offset_k(addr);
kernel_p4d = p4d_offset(kernel_pgd, addr);
*user_p4d = *kernel_p4d;


Re: linux-next: manual merge of the mfd tree with the sound tree

2018-07-19 Thread Takashi Iwai
On Fri, 20 Jul 2018 05:42:19 +0200,
Stephen Rothwell wrote:
> 
> Hi all,
> 
> Today's linux-next merge of the mfd tree got a conflict in:
> 
>   drivers/gpu/drm/i915/Kconfig
> 
> between commit:
> 
>   a57942bfdd61 ("ALSA: hda: Make audio component support more generic")
> 
> from the sound tree and commit:
> 
>   9c229127aee2 ("drm/i915: hdmi: add CEC notifier to intel_hdmi")
> 
> from the mfd tree.
> 
> I fixed it up (see below) and can carry the fix as necessary. This
> is now fixed as far as linux-next is concerned, but any non trivial
> conflicts should be mentioned to your upstream maintainer when your tree
> is submitted for merging.  You may also want to consider cooperating
> with the maintainer of the conflicting tree to minimise any particularly
> complex conflicts.
> 
> -- 
> Cheers,
> Stephen Rothwell
> 
> diff --cc drivers/gpu/drm/i915/Kconfig
> index 5c607f2c707b,2d65d567d5d1..
> --- a/drivers/gpu/drm/i915/Kconfig
> +++ b/drivers/gpu/drm/i915/Kconfig
> @@@ -23,7 -23,7 +23,8 @@@ config DRM_I91
>   select SYNC_FILE
>   select IOSF_MBI
>   select CRC32
>  +select SND_HDA_I915 if SND_HDA_CORE
> + select CEC_CORE if CEC_NOTIFIER
>   help
> Choose this option if you have a system that has "Intel Graphics
> Media Accelerator" or "HD Graphics" integrated graphics,

Looks good, thanks!


Takashi


Re: [PATCH] fs: iomap: Change return type to vm_fault_t

2018-07-19 Thread Souptick Joarder
On Wed, Jul 4, 2018 at 3:22 AM, Andreas Gruenbacher  wrote:
> On 3 July 2018 at 23:39, Darrick J. Wong  wrote:
>> On Mon, Jul 02, 2018 at 07:52:41PM +0200, Andreas Gruenbacher wrote:
>>> On 2 July 2018 at 17:43, Souptick Joarder  wrote:
>>> > Return type has been changed to vm_fault_t type for
>>> > iomap_page_mkwrite().
>>> >
>>> > see commit 1c8f422059ae ("mm: change return type to
>>> > vm_fault_t") for reference.
>>> >
>>> > Signed-off-by: Souptick Joarder 
>>> > Reviewed-by: Matthew Wilcox 
>>
>> I don't recall Christoph [now cc'd] rescinding his NAK of the previous
>> version of this patch[1].  Has he changed his mind since May?
>
> Oops, a reply gone wrong -- I was meaning to reply to Souptick
> Joarder's gfs2 change which I've added to the gfs2 for-next branch.
> Not the iomap change. Sorry for the confusion.
>
>> [1] https://spinics.net/lists/linux-fsdevel/msg126032.html
>>
>> Now granted I didn't have a problem with the code (and applied the xfs
>> version to 4.18 after monitoring to satisfy myself that nothing
>> particularly weird happened during 4.17) but seeing as most of the iomap
>> changes have gone through hch's review and landed via the xfs tree...

Darrick, is this patch going to 4.19 through xfs tree ?


[tip:x86/hyperv] x86/hyper-v: Fix wrong merge conflict resolution

2018-07-19 Thread tip-bot for K. Y. Srinivasan
Commit-ID:  be0e16ce7c3bf9855f1ef5ae46cf889e1784ddea
Gitweb: https://git.kernel.org/tip/be0e16ce7c3bf9855f1ef5ae46cf889e1784ddea
Author: K. Y. Srinivasan 
AuthorDate: Fri, 20 Jul 2018 03:50:09 +
Committer:  Thomas Gleixner 
CommitDate: Fri, 20 Jul 2018 06:56:23 +0200

x86/hyper-v: Fix wrong merge conflict resolution

When the mapping betwween the Linux notion of CPU ID to the hypervisor's
notion of CPU ID is not initialized, IPI must fall back to the
non-enlightened path.

The recent merge of upstream changes into the hyperv branch resolved a
merge conflict wronly by returning success in that case, which results in
the IPI not being sent at all. Fix it up.

Fixes: 8f63e9230dec ("Merge branch 'x86/urgent' into x86/hyperv")
Reported-by: Michael Kelley 
Signed-off-by: K. Y. Srinivasan 
Signed-off-by: Thomas Gleixner 
Cc: gre...@linuxfoundation.org
Cc: de...@linuxdriverproject.org
Cc: o...@aepfle.de
Cc: a...@canonical.com
Cc: jasow...@redhat.com
Cc: h...@zytor.com
Cc: sthem...@microsoft.com
Cc: michael.h.kel...@microsoft.com
Cc: vkuzn...@redhat.com
Link: https://lkml.kernel.org/r/20180720035009.3995-1-...@linuxonhyperv.com
---
 arch/x86/hyperv/hv_apic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c
index 0c3c9f8fee77..5b0f613428c2 100644
--- a/arch/x86/hyperv/hv_apic.c
+++ b/arch/x86/hyperv/hv_apic.c
@@ -168,7 +168,7 @@ static bool __send_ipi_mask(const struct cpumask *mask, int 
vector)
for_each_cpu(cur_cpu, mask) {
vcpu = hv_cpu_number_to_vp_number(cur_cpu);
if (vcpu == VP_INVAL)
-   return true;
+   return false;
 
/*
 * This particular version of the IPI hypercall can


Re: [RFC PATCH v2 1/4] dt-bindings: misc: Add bindings for misc. BMC control fields

2018-07-19 Thread Benjamin Herrenschmidt
On Fri, 2018-07-20 at 09:37 +0930, Andrew Jeffery wrote:
> > 
> > Andrew, can you start with a list that shows what you expect us to need
> > on our systems ?
> > 
> 
> Okay, our Witherspoon and Romulus platforms containing the ASPEED AST2500 
> currently need the following tuneables exposed:
> 
> > From the SCU:
> 
> - Debug UART enable
> - VGA DAC mux
> - VGA scratch registers 0-7
> - LPC SuperIO decode enable
> - VGA MMIO decode enable
> 
> > From the LPC controller:
> 
> - iLPC2AHB enable
> - SuperIO scratch registers 0x20-0x2f
> 
> (The LPC controller is just as much of a collection of random bits as the SCU)
> 
> Lastly, our Palmetto platform uses an AST2400 which has fewer features 
> compared to the AST2500. Its tuneable list is the same as the above with the 
> exception of "Debug UART enable".
> 
> Tuneables that we may need to expose in the future include:
> 
> > From the SCU:
> 
> - PCI VID/DID for the BMC PCIe device
> - VGA device enable (may need to be disabled if the platform contains a 
> discrete graphics processor)

Additionally there's a bunch of resigters controlling the mapping of
various MMIO regions of the BMC PCIe device to portions of the BMC
address space. I'm not sure what's the best way to handle that.

This specific set might require a dedicated device as a subnode of
the SCU in the DT that contains all the mappings as properties... 

That or we consider them static enough and just whack it in u-boot.

> > From the LPC controller:
> 
> - UART mux
> 
> Alexander, Eugene, can you chime in with your platforms' needs?
> 
> Cheers,
> 
> Andrew


Re: [PATCH] sched/fair: remove #ifdefs from scale_rt_capacity

2018-07-19 Thread Viresh Kumar
On 19-07-18, 14:00, Vincent Guittot wrote:
> Reuse cpu_util_irq() that has been defined for schedutil and set irq util
> to 0 when !CONFIG_IRQ_TIME_ACCOUNTING
> 
> But the compiler is not able to optimize the sequence (at least with
> aarch64 GCC 7.2.1)
>   free *= (max - irq);
>   free /= max;
> when irq is fixed to 0
> 
> Add a new inline function scale_irq_capacity() that will scale utilization
> when irq is accounted. Reuse this funciton in schedutil which applies
> similar formula.
> 
> Suggested-by: Ingo Molnar 
> Signed-off-by: Vincent Guittot 
> ---
>  kernel/sched/cpufreq_schedutil.c |  3 +--
>  kernel/sched/fair.c  | 13 +++--
>  kernel/sched/sched.h | 20 ++--
>  3 files changed, 22 insertions(+), 14 deletions(-)
> 
> diff --git a/kernel/sched/cpufreq_schedutil.c 
> b/kernel/sched/cpufreq_schedutil.c
> index 97dcd44..3fffad3 100644
> --- a/kernel/sched/cpufreq_schedutil.c
> +++ b/kernel/sched/cpufreq_schedutil.c
> @@ -247,8 +247,7 @@ static unsigned long sugov_get_util(struct sugov_cpu 
> *sg_cpu)
>*   U' = irq + --- * U
>*max
>*/
> - util *= (max - irq);
> - util /= max;
> + util = scale_irq_capacity(util, irq, max);
>   util += irq;
>  
>   /*
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index d5f7d52..14c3fdd 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -7551,16 +7551,12 @@ static unsigned long scale_rt_capacity(int cpu)
>   struct rq *rq = cpu_rq(cpu);
>   unsigned long max = arch_scale_cpu_capacity(NULL, cpu);
>   unsigned long used, free;
> -#if defined(CONFIG_IRQ_TIME_ACCOUNTING) || 
> defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
>   unsigned long irq;
> -#endif
>  
> -#if defined(CONFIG_IRQ_TIME_ACCOUNTING) || 
> defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
> - irq = READ_ONCE(rq->avg_irq.util_avg);
> + irq = cpu_util_irq(rq);
>  
>   if (unlikely(irq >= max))
>   return 1;
> -#endif
>  
>   used = READ_ONCE(rq->avg_rt.util_avg);
>   used += READ_ONCE(rq->avg_dl.util_avg);
> @@ -7569,11 +7565,8 @@ static unsigned long scale_rt_capacity(int cpu)
>   return 1;
>  
>   free = max - used;
> -#if defined(CONFIG_IRQ_TIME_ACCOUNTING) || 
> defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
> - free *= (max - irq);
> - free /= max;
> -#endif
> - return free;
> +
> + return scale_irq_capacity(free, irq, max);
>  }
>  
>  static void update_cpu_capacity(struct sched_domain *sd, int cpu)
> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> index ebb4b3c..b80c3fd 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h
> @@ -2210,17 +2210,33 @@ static inline unsigned long cpu_util_rt(struct rq *rq)
>  {
>   return READ_ONCE(rq->avg_rt.util_avg);
>  }
> +#endif
>  
> -#if defined(CONFIG_IRQ_TIME_ACCOUNTING) || 
> defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
> +#if defined(SMP) \
> + && (defined(CONFIG_IRQ_TIME_ACCOUNTING) || 
> defined(CONFIG_PARAVIRT_TIME_ACCOUNTING))
>  static inline unsigned long cpu_util_irq(struct rq *rq)
>  {
>   return rq->avg_irq.util_avg;
>  }
> +
> +static inline
> +unsigned long scale_irq_capacity(unsigned long util, unsigned long irq, 
> unsigned long max)
> +{
> + util *= (max - irq);

() can be dropped here. 

Other than that: 

Acked-by: Viresh Kumar 

-- 
viresh


Re: [PATCH v2] pinctrl: uniphier: add spi pin-mux settings

2018-07-19 Thread Masahiro Yamada
2018-07-19 18:05 GMT+09:00 Keiji Hayashibara :
> From: Kunihiko Hayashi 
>
> Add pin-mux settings for spi controller.
>
> Signed-off-by: Kunihiko Hayashi 
> Signed-off-by: Keiji Hayashibara 
> ---


Acked-by: Masahiro Yamada 



>  Changes since v1:
>  - Fix build error of "pinctrl-uniphier-sld8.c".
>
>  drivers/pinctrl/uniphier/pinctrl-uniphier-ld11.c | 10 ++
>  drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c | 20 
>  drivers/pinctrl/uniphier/pinctrl-uniphier-ld4.c  |  5 +
>  drivers/pinctrl/uniphier/pinctrl-uniphier-ld6b.c | 10 ++
>  drivers/pinctrl/uniphier/pinctrl-uniphier-pro4.c | 10 ++
>  drivers/pinctrl/uniphier/pinctrl-uniphier-pro5.c | 15 +++
>  drivers/pinctrl/uniphier/pinctrl-uniphier-pxs2.c | 10 ++
>  drivers/pinctrl/uniphier/pinctrl-uniphier-pxs3.c | 10 ++
>  drivers/pinctrl/uniphier/pinctrl-uniphier-sld8.c |  5 +
>  9 files changed, 95 insertions(+)
>
> diff --git a/drivers/pinctrl/uniphier/pinctrl-uniphier-ld11.c 
> b/drivers/pinctrl/uniphier/pinctrl-uniphier-ld11.c
> index 58825f6..bce533f 100644
> --- a/drivers/pinctrl/uniphier/pinctrl-uniphier-ld11.c
> +++ b/drivers/pinctrl/uniphier/pinctrl-uniphier-ld11.c
> @@ -517,6 +517,10 @@ static const int i2c4_muxvals[] = {1, 1};
>  static const unsigned nand_pins[] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
>  15, 16, 17};
>  static const int nand_muxvals[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
> 0};
> +static const unsigned spi0_pins[] = {56, 57, 58, 59};
> +static const int spi0_muxvals[] = {0, 0, 0, 0};
> +static const unsigned spi1_pins[] = {169, 170, 171, 172};
> +static const int spi1_muxvals[] = {1, 1, 1, 1};
>  static const unsigned system_bus_pins[] = {1, 2, 6, 7, 8, 9, 10, 11, 12, 13,
>14, 15, 16, 17};
>  static const int system_bus_muxvals[] = {0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
> 2,
> @@ -596,6 +600,8 @@ static const struct uniphier_pinctrl_group 
> uniphier_ld11_groups[] = {
> UNIPHIER_PINCTRL_GROUP(i2c3),
> UNIPHIER_PINCTRL_GROUP(i2c4),
> UNIPHIER_PINCTRL_GROUP(nand),
> +   UNIPHIER_PINCTRL_GROUP(spi0),
> +   UNIPHIER_PINCTRL_GROUP(spi1),
> UNIPHIER_PINCTRL_GROUP(system_bus),
> UNIPHIER_PINCTRL_GROUP(system_bus_cs1),
> UNIPHIER_PINCTRL_GROUP(uart0),
> @@ -632,6 +638,8 @@ static const char * const i2c1_groups[] = {"i2c1"};
>  static const char * const i2c3_groups[] = {"i2c3"};
>  static const char * const i2c4_groups[] = {"i2c4"};
>  static const char * const nand_groups[] = {"nand"};
> +static const char * const spi0_groups[] = {"spi0"};
> +static const char * const spi1_groups[] = {"spi1"};
>  static const char * const system_bus_groups[] = {"system_bus",
>  "system_bus_cs1"};
>  static const char * const uart0_groups[] = {"uart0"};
> @@ -657,6 +665,8 @@ static const struct uniphier_pinmux_function 
> uniphier_ld11_functions[] = {
> UNIPHIER_PINMUX_FUNCTION(i2c3),
> UNIPHIER_PINMUX_FUNCTION(i2c4),
> UNIPHIER_PINMUX_FUNCTION(nand),
> +   UNIPHIER_PINMUX_FUNCTION(spi0),
> +   UNIPHIER_PINMUX_FUNCTION(spi1),
> UNIPHIER_PINMUX_FUNCTION(system_bus),
> UNIPHIER_PINMUX_FUNCTION(uart0),
> UNIPHIER_PINMUX_FUNCTION(uart1),
> diff --git a/drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c 
> b/drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c
> index 9f449b3..99f06fe 100644
> --- a/drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c
> +++ b/drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c
> @@ -606,6 +606,14 @@ static const unsigned nand_pins[] = {3, 4, 5, 6, 7, 8, 
> 9, 10, 11, 12, 13, 14,
>  static const int nand_muxvals[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
> 0};
>  static const unsigned sd_pins[] = {10, 11, 12, 13, 14, 15, 16, 17};
>  static const int sd_muxvals[] = {3, 3, 3, 3, 3, 3, 3, 3};  /* No SDVOLC */
> +static const unsigned spi0_pins[] = {56, 57, 58, 59};
> +static const int spi0_muxvals[] = {0, 0, 0, 0};
> +static const unsigned spi1_pins[] = {169, 170, 171, 172};
> +static const int spi1_muxvals[] = {1, 1, 1, 1};
> +static const unsigned spi2_pins[] = {86, 87, 88, 89};
> +static const int spi2_muxvals[] = {1, 1, 1, 1};
> +static const unsigned spi3_pins[] = {74, 75, 76, 77};
> +static const int spi3_muxvals[] = {1, 1, 1, 1};
>  static const unsigned system_bus_pins[] = {1, 2, 6, 7, 8, 9, 10, 11, 12, 13,
>14, 15, 16, 17};
>  static const int system_bus_muxvals[] = {0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
> 2,
> @@ -685,6 +693,10 @@ static const struct uniphier_pinctrl_group 
> uniphier_ld20_groups[] = {
> UNIPHIER_PINCTRL_GROUP(i2c4),
> UNIPHIER_PINCTRL_GROUP(nand),
> UNIPHIER_PINCTRL_GROUP(sd),
> +   UNIPHIER_PINCTRL_GROUP(spi0),
> +   UNIPHIER_PINCTRL_GROUP(spi1),
> +   UNIPHIER_PINCTRL_GROUP(spi2),
> +   UNIPHIER_PINC

Re: [PATCHv2 2/2] arm64: Clear the stack

2018-07-19 Thread Kees Cook
On Thu, Jul 19, 2018 at 4:28 PM, Laura Abbott  wrote:
>
> Implementation of stackleak based heavily on the x86 version
>
> Signed-off-by: Laura Abbott 

This is the commit message I wrote when I was using an earlier
version, which I think is more descriptive:

arm64: Add support for STACKLEAK gcc plugin

This adds support for the STACKLEAK gcc plugin to arm64 by implementing
stackleak_check_alloca(), based heavily on the x86 version, and adding the
two helpers used by the stackleak common code: current_top_of_stack() and
on_thread_stack(). The stack erasure calls are made at syscall returns.
Additionally, this disables the plugin in hypervisor and EFI stub code,
which are out of scope for the protection.

Either way:

Reviewed-by: Kees Cook 

Thanks for getting this hammered out!

> ---
> v2: Convert to adjusted on_acessible_stack APIs. Fixed alloca check to
> just panic. Dropped the extra include per Kees. I also didn't add the
> Reviewed-by since the APIs did change and I wanted another pass.

Maybe the panic() should get a comment above it to describe why it's
there (i.e. summarize the thread where that change was discussed?) Or
maybe mention it in the commit log (instead of being only below the
--- line?)

-Kees

> ---
>  arch/arm64/Kconfig|  1 +
>  arch/arm64/include/asm/processor.h| 15 +++
>  arch/arm64/kernel/entry.S |  7 +++
>  arch/arm64/kernel/process.c   | 17 +
>  arch/arm64/kvm/hyp/Makefile   |  3 ++-
>  drivers/firmware/efi/libstub/Makefile |  3 ++-
>  6 files changed, 44 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index 42c090cf0292..216d36a49ab5 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -96,6 +96,7 @@ config ARM64
> select HAVE_ARCH_MMAP_RND_BITS
> select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT
> select HAVE_ARCH_SECCOMP_FILTER
> +   select HAVE_ARCH_STACKLEAK
> select HAVE_ARCH_THREAD_STRUCT_WHITELIST
> select HAVE_ARCH_TRACEHOOK
> select HAVE_ARCH_TRANSPARENT_HUGEPAGE
> diff --git a/arch/arm64/include/asm/processor.h 
> b/arch/arm64/include/asm/processor.h
> index a73ae1e49200..0061450a793b 100644
> --- a/arch/arm64/include/asm/processor.h
> +++ b/arch/arm64/include/asm/processor.h
> @@ -266,5 +266,20 @@ extern void __init minsigstksz_setup(void);
>  #define SVE_SET_VL(arg)sve_set_current_vl(arg)
>  #define SVE_GET_VL()   sve_get_current_vl()
>
> +/*
> + * For CONFIG_GCC_PLUGIN_STACKLEAK
> + *
> + * These need to be macros because otherwise we get stuck in a nightmare
> + * of header definitions for the use of task_stack_page.
> + */
> +
> +#define current_top_of_stack()   
>   \
> +({   
>   \
> +   struct stack_info _info;  
>   \
> +   BUG_ON(!on_accessible_stack(current, current_stack_pointer, &_info)); 
>   \
> +   _info.high;   
>   \
> +})
> +#define on_thread_stack()  (on_task_stack(current, 
> current_stack_pointer, NULL))
> +
>  #endif /* __ASSEMBLY__ */
>  #endif /* __ASM_PROCESSOR_H */
> diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
> index 28ad8799406f..67d12016063d 100644
> --- a/arch/arm64/kernel/entry.S
> +++ b/arch/arm64/kernel/entry.S
> @@ -431,6 +431,11 @@ tsk.reqx28 // current thread_info
>
> .text
>
> +   .macro  stackleak_erase
> +#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
> +   bl  stackleak_erase
> +#endif
> +   .endm
>  /*
>   * Exception vectors.
>   */
> @@ -910,6 +915,7 @@ ret_fast_syscall:
> and x2, x1, #_TIF_WORK_MASK
> cbnzx2, work_pending
> enable_step_tsk x1, x2
> +   stackleak_erase
> kernel_exit 0
>  ret_fast_syscall_trace:
> enable_daif
> @@ -936,6 +942,7 @@ ret_to_user:
> cbnzx2, work_pending
>  finish_ret_to_user:
> enable_step_tsk x1, x2
> +   stackleak_erase
> kernel_exit 0
>  ENDPROC(ret_to_user)
>
> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
> index e10bc363f533..2724e4d31b16 100644
> --- a/arch/arm64/kernel/process.c
> +++ b/arch/arm64/kernel/process.c
> @@ -493,3 +493,20 @@ void arch_setup_new_exec(void)
>  {
> current->mm->context.flags = is_compat_task() ? MMCF_AARCH32 : 0;
>  }
> +
> +#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
> +void __used stackleak_check_alloca(unsigned long size)
> +{
> +   unsigned long stack_left;
> +   unsigned long current_sp = current_stack_pointer;
> +   struct stack_info info;
> +
> +   BUG_ON(!on_accessible_stack(current, current_sp, &info));
> +
> +   stack_left = current_sp - info.low;
> +
> +   if (size >= stack_left)
> +   panic("alloca() ov

Re: [RFC PATCH] EDAC, ghes: Enable per-layer error reporting for ARM

2018-07-19 Thread Borislav Petkov
On Thu, Jul 19, 2018 at 02:36:21PM -0400, Tyler Baicar wrote:
> With the current ghes_edac setup, it seems the only way this could
> work would be to have the firmware always report the module value to

My experience with firmware so far is that it is a lost cause,
considering all the bugs, snafus and incompleteness it demonstrates...

> The other obvious but more messy way would be to have notifiers
> register to be called by ghes_edac and have a custom EDAC driver for
> each CPU to properly populate their layer information.

... which is what we do on x86 and whitelist only known-good platforms
in ghes_edac, which claim that their fw info is correct.

-- 
Regards/Gruss,
Boris.

ECO tip #101: Trim your mails when you reply.
--


[PATCH 1/1] x86/hyper-v: Fix a merge error

2018-07-19 Thread kys
From: "K. Y. Srinivasan" 

When the mapping betwween the Linux notion of CPU ID
to the hypervisor's notion of CPU ID is not initialized,
we should fall back on the non-enligghtened path for IPI.
A merge error introduced this bug; fix it.

Fixes: 1268ed0c474a ("Merge branch 'x86/urgent' into x86/hyperv")

Reported-by: Michael Kelley 
Signed-off-by: K. Y. Srinivasan 
---
 arch/x86/hyperv/hv_apic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c
index 0c3c9f8fee77..5b0f613428c2 100644
--- a/arch/x86/hyperv/hv_apic.c
+++ b/arch/x86/hyperv/hv_apic.c
@@ -168,7 +168,7 @@ static bool __send_ipi_mask(const struct cpumask *mask, int 
vector)
for_each_cpu(cur_cpu, mask) {
vcpu = hv_cpu_number_to_vp_number(cur_cpu);
if (vcpu == VP_INVAL)
-   return true;
+   return false;
 
/*
 * This particular version of the IPI hypercall can
-- 
2.17.1



[PATCH] Drivers: staging: rts5208: xd.c fixed a brace coding style issue

2018-07-19 Thread Ali Aminian
Fixing a coding style issue

Signed-off-by: Ali Aminian 
---
 drivers/staging/rts5208/xd.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/rts5208/xd.c b/drivers/staging/rts5208/xd.c
index 667dfe1..261d868 100644
--- a/drivers/staging/rts5208/xd.c
+++ b/drivers/staging/rts5208/xd.c
@@ -787,9 +787,8 @@ static int reset_xd(struct rtsx_chip *chip)
}
 
dev_dbg(rtsx_dev(chip), "CIS block: 0x%x\n", xd_card->cis_block);
-   if (xd_card->cis_block == 0x) {
+   if (xd_card->cis_block == 0x)
return STATUS_FAIL;
-   }
 
chip->capacity[chip->card2lun[XD_CARD]] = xd_card->capacity;
 
-- 
2.7.4



RE: [PATCH V3 0/4] KVM/x86/hyper-V: Introduce PV guest address space mapping flush support

2018-07-19 Thread KY Srinivasan



> -Original Message-
> From: Tianyu Lan
> Sent: Thursday, July 19, 2018 1:40 AM
> Cc: Tianyu Lan ; de...@linuxdriverproject.org;
> Haiyang Zhang ; h...@zytor.com;
> k...@vger.kernel.org; KY Srinivasan ; linux-
> ker...@vger.kernel.org; mi...@redhat.com; pbonz...@redhat.com;
> rkrc...@redhat.com; Stephen Hemminger ;
> t...@linutronix.de; x...@kernel.org; Michael Kelley (EOSG)
> ; vkuzn...@redhat.com
> Subject: [PATCH V3 0/4] KVM/x86/hyper-V: Introduce PV guest address
> space mapping flush support
> 
> Hyper-V provides a para-virtualization hypercall
> HvFlushGuestPhysicalAddressSpace
> to flush nested VM address space mapping in l1 hypervisor and it's to reduce
> overhead
> of flushing ept tlb among vcpus. The tradition way is to send IPIs to all
> affected
> vcpus and executes INVEPT on each vcpus. It will trigger several vmexits for
> IPI and
> INVEPT emulation. The pv hypercall can help to flush specified ept table on 
> all
> vcpus
> via one single hypercall.
> 
> Change since v2:
>- Make ept_pointers_match as tristate "check", "match" and "mismatch".
>Set "check" in vmx_set_cr3(), check all ept table pointers in
> hv_remote_flush_tlb()
>and call hypercall when all ept pointers are same.
>- Rename kvm_arch_hv_flush_remote_tlb with
> kvm_arch_flush_remote_tlb and
>Rename kvm_x86_ops->hv_tlb_remote_flush with kvm_x86_ops-
> >tlb_remote_flush
>- Fix issue that ignore updating tlbs_dirty during calling
> kvm_arch_flush_remote_tlbs()
>- Merge patch "KVM/VMX: Add identical ept table pointer check" and
>patch "KVM/x86: Add tlb_remote_flush callback support for vmx"
> 
> Change since v1:
>- Fix compilation error for non-x86 platform.
>- Use ept_pointers_match to check condition of identical ept
> table pointer and get ept pointer from struct 
> vcpu_vmx->ept_pointer.
>- Add hyperv_nested_flush_guest_mapping ftrace support
> 
> 
> 
> Lan Tianyu (4):
>   X86/Hyper-V: Add flush HvFlushGuestPhysicalAddressSpace hypercall
> support
>   X86/Hyper-V: Add hyperv_nested_flush_guest_mapping ftrace support
>   KVM: Add tlb remote flush callback in kvm_x86_ops.
>   KVM/x86: Add tlb_remote_flush callback support for vmx
> 
>  arch/x86/hyperv/Makefile|  2 +-
>  arch/x86/hyperv/nested.c| 67
> ++
>  arch/x86/include/asm/hyperv-tlfs.h  |  8 +
>  arch/x86/include/asm/kvm_host.h | 11 ++
>  arch/x86/include/asm/mshyperv.h |  2 ++
>  arch/x86/include/asm/trace/hyperv.h | 14 
>  arch/x86/kvm/vmx.c  | 72
> -
>  include/linux/kvm_host.h|  7 
>  virt/kvm/kvm_main.c |  3 +-
>  9 files changed, 183 insertions(+), 3 deletions(-)
>  create mode 100644 arch/x86/hyperv/nested.c

Acked-by: K. Y. Srinivasan 

> 
> --
> 2.14.3


Re: [PATCH v3 5/6] KVM: X86: Add NMI support to PV IPIs

2018-07-19 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 00:31, Radim Krčmář  wrote:
>
> 2018-07-03 14:21+0800, Wanpeng Li:
> > From: Wanpeng Li 
> >
> > The NMI delivery mode of ICR is used to deliver an NMI to the processor,
> > and the vector information is ignored.
> >
> > Cc: Paolo Bonzini 
> > Cc: Radim Krčmář 
> > Cc: Vitaly Kuznetsov 
> > Signed-off-by: Wanpeng Li 
> > ---
> > diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
> > @@ -479,7 +479,16 @@ static int __send_ipi_mask(const struct cpumask *mask, 
> > int vector)
> >   }
> >   }
> >
> > - ret = kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap_low, 
> > ipi_bitmap_high, vector);
> > + switch (vector) {
> > + default:
> > + icr = APIC_DM_FIXED | vector;
> > + break;
> > + case NMI_VECTOR:
> > + icr = APIC_DM_NMI;
>
> I think it would be better to say that KVM interprets NMI_VECTOR and
> sends the interrupt as APIC_DM_NMI.

Yeah, in addition, SDM 10.6.1 also mentioned that:
Delivery mode:
100 (NMI) Delivers an NMI interrupt to the target processor or
processors. The vector information is ignored.

Regards,
Wanpeng Li


[PATCH 01/20] staging: gasket: allow compile for ARM64 in Kconfig

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

The gasket and apex drivers are also to be used on ARM64 architectures.

Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/gasket/Kconfig b/drivers/staging/gasket/Kconfig
index c836389c1402d..970e299046c37 100644
--- a/drivers/staging/gasket/Kconfig
+++ b/drivers/staging/gasket/Kconfig
@@ -2,7 +2,7 @@ menu "Gasket devices"
 
 config STAGING_GASKET_FRAMEWORK
tristate "Gasket framework"
-   depends on PCI && X86_64
+   depends on PCI && (X86_64 || ARM64)
help
  This framework supports Gasket-compatible devices, such as Apex.
  It is required for any of the following module(s).
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 03/20] staging: gasket: remove code for no physical device

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

gasket_enable_dev code for enabling a gasket device with no physical PCI
device registered shouldn't be necessary.

Reported-by: Greg Kroah-Hartman 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 12 +---
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index f327c9d7f90a3..18cc8e3283b39 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -898,7 +898,6 @@ static int gasket_enable_dev(
 {
int tbl_idx;
int ret;
-   struct device *ddev;
const struct gasket_driver_desc *driver_desc =
internal_desc->driver_desc;
 
@@ -919,21 +918,12 @@ static int gasket_enable_dev(
for (tbl_idx = 0; tbl_idx < driver_desc->num_page_tables; tbl_idx++) {
gasket_log_debug(
gasket_dev, "Initializing page table %d.", tbl_idx);
-   if (gasket_dev->pci_dev) {
-   ddev = &gasket_dev->pci_dev->dev;
-   } else {
-   gasket_log_error(
-   gasket_dev,
-   "%s with no physical device!!", __func__);
-   WARN_ON(1);
-   ddev = NULL;
-   }
ret = gasket_page_table_init(
&gasket_dev->page_table[tbl_idx],
&gasket_dev->bar_data[
driver_desc->page_table_bar_index],
&driver_desc->page_table_configs[tbl_idx],
-   ddev, gasket_dev->pci_dev, true);
+   &gasket_dev->pci_dev->dev, gasket_dev->pci_dev, true);
if (ret) {
gasket_log_error(
gasket_dev,
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 09/20] staging: gasket: gasket page table functions use bool return type

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Convert from int to bool return type for gasket page table functions
that return values used as booleans.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_page_table.c | 58 +++---
 drivers/staging/gasket/gasket_page_table.h |  8 +--
 2 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/gasket/gasket_page_table.c 
b/drivers/staging/gasket/gasket_page_table.c
index 36a560c87af36..2a27db658a4e4 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -262,16 +262,16 @@ static void gasket_perform_unmapping(
 static void gasket_free_extended_subtable(
struct gasket_page_table *pg_tbl, struct gasket_page_table_entry *pte,
u64 __iomem *att_reg);
-static int gasket_release_page(struct page *page);
+static bool gasket_release_page(struct page *page);
 
 /* Other/utility declarations */
-static inline int gasket_addr_is_simple(
+static inline bool gasket_addr_is_simple(
struct gasket_page_table *pg_tbl, ulong addr);
-static int gasket_is_simple_dev_addr_bad(
+static bool gasket_is_simple_dev_addr_bad(
struct gasket_page_table *pg_tbl, ulong dev_addr, uint num_pages);
-static int gasket_is_extended_dev_addr_bad(
+static bool gasket_is_extended_dev_addr_bad(
struct gasket_page_table *pg_tbl, ulong dev_addr, uint num_pages);
-static int gasket_is_pte_range_free(
+static bool gasket_is_pte_range_free(
struct gasket_page_table_entry *pte, uint num_entries);
 static void gasket_page_table_garbage_collect_nolock(
struct gasket_page_table *pg_tbl);
@@ -558,7 +558,7 @@ int gasket_page_table_lookup_page(
 }
 
 /* See gasket_page_table.h for description. */
-int gasket_page_table_are_addrs_bad(
+bool gasket_page_table_are_addrs_bad(
struct gasket_page_table *pg_tbl, ulong host_addr, ulong dev_addr,
ulong bytes)
 {
@@ -567,7 +567,7 @@ int gasket_page_table_are_addrs_bad(
pg_tbl,
"host mapping address 0x%lx must be page aligned",
host_addr);
-   return 1;
+   return true;
}
 
return gasket_page_table_is_dev_addr_bad(pg_tbl, dev_addr, bytes);
@@ -575,7 +575,7 @@ int gasket_page_table_are_addrs_bad(
 EXPORT_SYMBOL(gasket_page_table_are_addrs_bad);
 
 /* See gasket_page_table.h for description. */
-int gasket_page_table_is_dev_addr_bad(
+bool gasket_page_table_is_dev_addr_bad(
struct gasket_page_table *pg_tbl, ulong dev_addr, ulong bytes)
 {
uint num_pages = bytes / PAGE_SIZE;
@@ -584,7 +584,7 @@ int gasket_page_table_is_dev_addr_bad(
gasket_pg_tbl_error(
pg_tbl,
"mapping size 0x%lX must be page aligned", bytes);
-   return 1;
+   return true;
}
 
if (num_pages == 0) {
@@ -592,7 +592,7 @@ int gasket_page_table_is_dev_addr_bad(
pg_tbl,
"requested mapping is less than one page: %lu / %lu",
bytes, PAGE_SIZE);
-   return 1;
+   return true;
}
 
if (gasket_addr_is_simple(pg_tbl, dev_addr))
@@ -1285,23 +1285,23 @@ static void gasket_free_extended_subtable(
 /*
  * Safely return a page to the OS.
  * @page: The page to return to the OS.
- * Returns 1 if the page was released, 0 if it was
+ * Returns true if the page was released, false if it was
  * ignored.
  */
-static int gasket_release_page(struct page *page)
+static bool gasket_release_page(struct page *page)
 {
if (!page)
-   return 0;
+   return false;
 
if (!PageReserved(page))
SetPageDirty(page);
put_page(page);
 
-   return 1;
+   return true;
 }
 
 /* Evaluates to nonzero if the specified virtual address is simple. */
-static inline int gasket_addr_is_simple(
+static inline bool gasket_addr_is_simple(
struct gasket_page_table *pg_tbl, ulong addr)
 {
return !((addr) & (pg_tbl)->extended_flag);
@@ -1317,7 +1317,7 @@ static inline int gasket_addr_is_simple(
  * address to/from page + offset) and that the requested page range starts and
  * ends within the set of currently-partitioned simple pages.
  */
-static int gasket_is_simple_dev_addr_bad(
+static bool gasket_is_simple_dev_addr_bad(
struct gasket_page_table *pg_tbl, ulong dev_addr, uint num_pages)
 {
ulong page_offset = dev_addr & (PAGE_SIZE - 1);
@@ -1328,7 +1328,7 @@ static int gasket_is_simple_dev_addr_bad(
pg_tbl, 1, page_index, page_offset) != dev_addr) {
gasket_pg_tbl_error(
pg_tbl, "address is invalid, 0x%lX", dev_addr);
-   return 1;
+   return true;
}
 
if (page_index >= pg_tbl->num_simple_entries) {
@@ -1336,7 +1336,7 @@ static int

[PATCH 08/20] staging: gasket: apex_clock_gating simplify logic, reduce indentation

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Collapse together two checks and return immediately, avoid conditional
indentation for most of function code.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/apex_driver.c | 43 +---
 1 file changed, 20 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/gasket/apex_driver.c 
b/drivers/staging/gasket/apex_driver.c
index 3a83c3d4d5561..a01b1f2b827ea 100644
--- a/drivers/staging/gasket/apex_driver.c
+++ b/drivers/staging/gasket/apex_driver.c
@@ -666,33 +666,30 @@ static long apex_clock_gating(struct gasket_dev 
*gasket_dev, ulong arg)
 {
struct apex_gate_clock_ioctl ibuf;
 
-   if (bypass_top_level)
+   if (bypass_top_level || !allow_sw_clock_gating)
return 0;
 
-   if (allow_sw_clock_gating) {
-   if (copy_from_user(&ibuf, (void __user *)arg, sizeof(ibuf)))
-   return -EFAULT;
+   if (copy_from_user(&ibuf, (void __user *)arg, sizeof(ibuf)))
+   return -EFAULT;
 
-   gasket_log_error(
-   gasket_dev, "%s %llu", __func__, ibuf.enable);
+   gasket_log_error(gasket_dev, "%s %llu", __func__, ibuf.enable);
 
-   if (ibuf.enable) {
-   /* Quiesce AXI, gate GCB clock. */
-   gasket_read_modify_write_32(
-   gasket_dev, APEX_BAR_INDEX,
-   APEX_BAR2_REG_AXI_QUIESCE, 0x1, 1, 16);
-   gasket_read_modify_write_32(
-   gasket_dev, APEX_BAR_INDEX,
-   APEX_BAR2_REG_GCB_CLOCK_GATE, 0x1, 2, 18);
-   } else {
-   /* Un-gate GCB clock, un-quiesce AXI. */
-   gasket_read_modify_write_32(
-   gasket_dev, APEX_BAR_INDEX,
-   APEX_BAR2_REG_GCB_CLOCK_GATE, 0x0, 2, 18);
-   gasket_read_modify_write_32(
-   gasket_dev, APEX_BAR_INDEX,
-   APEX_BAR2_REG_AXI_QUIESCE, 0x0, 1, 16);
-   }
+   if (ibuf.enable) {
+   /* Quiesce AXI, gate GCB clock. */
+   gasket_read_modify_write_32(
+   gasket_dev, APEX_BAR_INDEX,
+   APEX_BAR2_REG_AXI_QUIESCE, 0x1, 1, 16);
+   gasket_read_modify_write_32(
+   gasket_dev, APEX_BAR_INDEX,
+   APEX_BAR2_REG_GCB_CLOCK_GATE, 0x1, 2, 18);
+   } else {
+   /* Un-gate GCB clock, un-quiesce AXI. */
+   gasket_read_modify_write_32(
+   gasket_dev, APEX_BAR_INDEX,
+   APEX_BAR2_REG_GCB_CLOCK_GATE, 0x0, 2, 18);
+   gasket_read_modify_write_32(
+   gasket_dev, APEX_BAR_INDEX,
+   APEX_BAR2_REG_AXI_QUIESCE, 0x0, 1, 16);
}
return 0;
 }
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 06/20] staging: gasket: don't treat no device reset callback as an error

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

It is not an error for a device to not have a reset callback registered.

Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index 53236e1ba4e48..eb5ad161ccda2 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -1836,11 +1836,8 @@ int gasket_reset_nolock(struct gasket_dev *gasket_dev, 
uint reset_type)
const struct gasket_driver_desc *driver_desc;
 
driver_desc = gasket_dev->internal_desc->driver_desc;
-   if (!driver_desc->device_reset_cb) {
-   gasket_log_error(
-   gasket_dev, "No device reset callback was registered.");
-   return -EINVAL;
-   }
+   if (!driver_desc->device_reset_cb)
+   return 0;
 
/* Perform a device reset of the requested type. */
ret = driver_desc->device_reset_cb(gasket_dev, reset_type);
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 05/20] staging: gasket: remove unnecessary code in coherent allocator

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Remove extraneous statement in gasket_config_coherent_allocator()

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_ioctl.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/gasket/gasket_ioctl.c 
b/drivers/staging/gasket/gasket_ioctl.c
index 0c2f85cf54480..d0142ed048a65 100644
--- a/drivers/staging/gasket/gasket_ioctl.c
+++ b/drivers/staging/gasket/gasket_ioctl.c
@@ -420,10 +420,8 @@ static int gasket_config_coherent_allocator(
if (ibuf.page_table_index >= gasket_dev->num_page_tables)
return -EFAULT;
 
-   if (ibuf.size > PAGE_SIZE * MAX_NUM_COHERENT_PAGES) {
-   ibuf.size = PAGE_SIZE * MAX_NUM_COHERENT_PAGES;
+   if (ibuf.size > PAGE_SIZE * MAX_NUM_COHERENT_PAGES)
return -ENOMEM;
-   }
 
if (ibuf.enable == 0) {
ret = gasket_free_coherent_memory(
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 17/20] staging: gasket: top ioctl handler add __user annotations

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Add __user annotation to gasket_core top-level ioctl handling pointer
arguments, for sparse checking.

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 6 --
 drivers/staging/gasket/gasket_core.h | 7 +--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index 254fb392c05c1..40e46ca5228c8 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -14,6 +14,7 @@
 #include "gasket_page_table.h"
 #include "gasket_sysfs.h"
 
+#include 
 #include 
 #include 
 #include 
@@ -1781,6 +1782,7 @@ static long gasket_ioctl(struct file *filp, uint cmd, 
ulong arg)
 {
struct gasket_dev *gasket_dev;
const struct gasket_driver_desc *driver_desc;
+   void __user *argp = (void __user *)arg;
char path[256];
 
if (!filp)
@@ -1810,14 +1812,14 @@ static long gasket_ioctl(struct file *filp, uint cmd, 
ulong arg)
 * check_and_invoke_callback.
 */
if (driver_desc->ioctl_handler_cb)
-   return driver_desc->ioctl_handler_cb(filp, cmd, arg);
+   return driver_desc->ioctl_handler_cb(filp, cmd, argp);
 
gasket_log_error(
gasket_dev, "Received unknown ioctl 0x%x", cmd);
return -EINVAL;
}
 
-   return gasket_handle_ioctl(filp, cmd, arg);
+   return gasket_handle_ioctl(filp, cmd, argp);
 }
 
 int gasket_reset(struct gasket_dev *gasket_dev, uint reset_type)
diff --git a/drivers/staging/gasket/gasket_core.h 
b/drivers/staging/gasket/gasket_core.h
index 7ea1df123ba5d..bf4ed3769efb2 100644
--- a/drivers/staging/gasket/gasket_core.h
+++ b/drivers/staging/gasket/gasket_core.h
@@ -314,9 +314,12 @@ struct gasket_dev {
struct hlist_node legacy_hlist_node;
 };
 
+/* Type of the ioctl handler callback. */
+typedef long (*gasket_ioctl_handler_cb_t)
+   (struct file *file, uint cmd, void __user *argp);
 /* Type of the ioctl permissions check callback. See below. */
 typedef int (*gasket_ioctl_permissions_cb_t)(
-   struct file *filp, uint cmd, ulong arg);
+   struct file *filp, uint cmd, void __user *argp);
 
 /*
  * Device type descriptor.
@@ -550,7 +553,7 @@ struct gasket_driver_desc {
 * return -EINVAL. Should return an error status (either -EINVAL or
 * the error result of the ioctl being handled).
 */
-   long (*ioctl_handler_cb)(struct file *filp, uint cmd, ulong arg);
+   gasket_ioctl_handler_cb_t ioctl_handler_cb;
 
/*
 * device_status_cb: Callback to determine device health.
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 15/20] staging: gasket: fix multi-line comment syntax in gasket_core.h

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Use consistent kernel-style multi-line comment syntax.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/gasket/gasket_core.h 
b/drivers/staging/gasket/gasket_core.h
index 50ad0c8853183..7ea1df123ba5d 100644
--- a/drivers/staging/gasket/gasket_core.h
+++ b/drivers/staging/gasket/gasket_core.h
@@ -54,7 +54,8 @@ enum gasket_interrupt_type {
PLATFORM_WIRE = 2,
 };
 
-/* Used to describe a Gasket interrupt. Contains an interrupt index, a 
register,
+/*
+ * Used to describe a Gasket interrupt. Contains an interrupt index, a 
register,
  * and packing data for that interrupt. The register and packing data
  * fields are relevant only for PCI_MSIX interrupt type and can be
  * set to 0 for everything else.
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 14/20] staging: gasket: remove extra parens in gasket_write_mappable_regions

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Remove unneeded parentheses around subexpressions.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index ae5febec8844c..ba48a379b0ada 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -1889,7 +1889,7 @@ static ssize_t gasket_write_mappable_regions(
if (bar_desc.permissions == GASKET_NOMAP)
return 0;
for (i = 0;
-(i < bar_desc.num_mappable_regions) && (total_written < PAGE_SIZE);
+i < bar_desc.num_mappable_regions && total_written < PAGE_SIZE;
 i++) {
min_addr = bar_desc.mappable_regions[i].start -
   driver_desc->legacy_mmap_address_offset;
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 12/20] staging: gasket: remove unnecessary parens in page table code

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

gasket_alloc_coherent_memory() extra parentheses in statement.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_page_table.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/gasket/gasket_page_table.c 
b/drivers/staging/gasket/gasket_page_table.c
index 617d602b8b447..9f8116112e0ac 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -1639,7 +1639,7 @@ int gasket_alloc_coherent_memory(struct gasket_dev 
*gasket_dev, u64 size,
dma_addr_t handle;
void *mem;
int j;
-   unsigned int num_pages = (size + PAGE_SIZE - 1) / (PAGE_SIZE);
+   unsigned int num_pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
const struct gasket_driver_desc *driver_desc =
gasket_get_driver_desc(gasket_dev);
 
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 13/20] staging: gasket: gasket_mmap use PAGE_MASK

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

gasket_mmap use PAGE_MASK, instead of performing math on PAGE_SIZE, for
simplicity and clarity.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index 3cf918f9d2604..ae5febec8844c 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -1591,7 +1591,7 @@ static int gasket_mmap(struct file *filp, struct 
vm_area_struct *vma)
}
driver_desc = gasket_dev->internal_desc->driver_desc;
 
-   if (vma->vm_start & (PAGE_SIZE - 1)) {
+   if (vma->vm_start & ~PAGE_MASK) {
gasket_log_error(
gasket_dev, "Base address not page-aligned: 0x%p\n",
(void *)vma->vm_start);
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 16/20] staging: gasket: always allow root open for write

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Always allow root to open device for writing.

Drop special-casing of ioctl permissions for root vs. owner.

Convert to bool types as appropriate.

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/apex_driver.c  | 15 --
 drivers/staging/gasket/gasket_core.c  |  8 ---
 drivers/staging/gasket/gasket_ioctl.c | 30 +--
 3 files changed, 23 insertions(+), 30 deletions(-)

diff --git a/drivers/staging/gasket/apex_driver.c 
b/drivers/staging/gasket/apex_driver.c
index a01b1f2b827ea..4c00f3609f081 100644
--- a/drivers/staging/gasket/apex_driver.c
+++ b/drivers/staging/gasket/apex_driver.c
@@ -140,7 +140,7 @@ static int apex_reset(struct gasket_dev *gasket_dev, uint 
type);
 
 static int apex_get_status(struct gasket_dev *gasket_dev);
 
-static uint apex_ioctl_check_permissions(struct file *file, uint cmd);
+static bool apex_ioctl_check_permissions(struct file *file, uint cmd);
 
 static long apex_ioctl(struct file *file, uint cmd, ulong arg);
 
@@ -625,18 +625,11 @@ static bool is_gcb_in_reset(struct gasket_dev *gasket_dev)
  * @file: File pointer from ioctl.
  * @cmd: ioctl command.
  *
- * Returns 1 if the current user may execute this ioctl, and 0 otherwise.
+ * Returns true if the current user may execute this ioctl, and false 
otherwise.
  */
-static uint apex_ioctl_check_permissions(struct file *filp, uint cmd)
+static bool apex_ioctl_check_permissions(struct file *filp, uint cmd)
 {
-   struct gasket_dev *gasket_dev = filp->private_data;
-   int root = capable(CAP_SYS_ADMIN);
-   int is_owner = gasket_dev->dev_info.ownership.is_owned &&
-  current->tgid == gasket_dev->dev_info.ownership.owner;
-
-   if (root || is_owner)
-   return 1;
-   return 0;
+   return !!(filp->f_mode & FMODE_WRITE);
 }
 
 /*
diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index ba48a379b0ada..254fb392c05c1 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -1072,6 +1072,7 @@ static int gasket_open(struct inode *inode, struct file 
*filp)
char task_name[TASK_COMM_LEN];
struct gasket_cdev_info *dev_info =
container_of(inode->i_cdev, struct gasket_cdev_info, cdev);
+   int is_root = capable(CAP_SYS_ADMIN);
 
gasket_dev = dev_info->gasket_dev_ptr;
driver_desc = gasket_dev->internal_desc->driver_desc;
@@ -1085,7 +1086,7 @@ static int gasket_open(struct inode *inode, struct file 
*filp)
"Attempting to open with tgid %u (%s) (f_mode: 0%03o, "
"fmode_write: %d is_root: %u)",
current->tgid, task_name, filp->f_mode,
-   (filp->f_mode & FMODE_WRITE), capable(CAP_SYS_ADMIN));
+   (filp->f_mode & FMODE_WRITE), is_root);
 
/* Always allow non-writing accesses. */
if (!(filp->f_mode & FMODE_WRITE)) {
@@ -1099,8 +1100,9 @@ static int gasket_open(struct inode *inode, struct file 
*filp)
gasket_dev, "Current owner open count (owning tgid %u): %d.",
ownership->owner, ownership->write_open_count);
 
-   /* Opening a node owned by another TGID is an error (even root.) */
-   if (ownership->is_owned && ownership->owner != current->tgid) {
+   /* Opening a node owned by another TGID is an error (unless root) */
+   if (ownership->is_owned && ownership->owner != current->tgid &&
+   !is_root) {
gasket_log_error(
gasket_dev,
"Process %u is opening a node held by %u.",
diff --git a/drivers/staging/gasket/gasket_ioctl.c 
b/drivers/staging/gasket/gasket_ioctl.c
index d0142ed048a65..8fd44979fe713 100644
--- a/drivers/staging/gasket/gasket_ioctl.c
+++ b/drivers/staging/gasket/gasket_ioctl.c
@@ -22,7 +22,7 @@
 #define trace_gasket_ioctl_config_coherent_allocator(x, ...)
 #endif
 
-static uint gasket_ioctl_check_permissions(struct file *filp, uint cmd);
+static bool gasket_ioctl_check_permissions(struct file *filp, uint cmd);
 static int gasket_set_event_fd(struct gasket_dev *dev, ulong arg);
 static int gasket_read_page_table_size(
struct gasket_dev *gasket_dev, ulong arg);
@@ -167,12 +167,13 @@ long gasket_is_supported_ioctl(uint cmd)
  * @filp: File structure pointer describing this node usage session.
  * @cmd: ioctl number to handle.
  *
- * Standard permissions checker.
+ * Check permissions for Gasket ioctls.
+ * Returns true if the file opener may execute this ioctl, or false otherwise.
  */
-static uint gasket_ioctl_check_permissions(struct file *filp, uint cmd)
+static bool gasket_ioctl_check_permissions(struct file *filp, uint cmd)
 {
-   uint alive, root, device_owner;
-   fmode_t read, write;
+   bool alive;
+   bool read, write;
struct gasket_dev *gasket_dev = (struct gasket_dev *)filp->private_data;
 

[PATCH 20/20] staging: gasket: common ioctls add __user annotations

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Add __user annotation to gasket common ioctl pointer arguments for
sparse checking.

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_ioctl.c | 102 ++
 1 file changed, 55 insertions(+), 47 deletions(-)

diff --git a/drivers/staging/gasket/gasket_ioctl.c 
b/drivers/staging/gasket/gasket_ioctl.c
index 998d0e215523c..2e2c9b997093b 100644
--- a/drivers/staging/gasket/gasket_ioctl.c
+++ b/drivers/staging/gasket/gasket_ioctl.c
@@ -24,17 +24,24 @@
 #endif
 
 static bool gasket_ioctl_check_permissions(struct file *filp, uint cmd);
-static int gasket_set_event_fd(struct gasket_dev *dev, ulong arg);
+static int gasket_set_event_fd(struct gasket_dev *dev,
+  struct gasket_interrupt_eventfd __user *argp);
 static int gasket_read_page_table_size(
-   struct gasket_dev *gasket_dev, ulong arg);
+   struct gasket_dev *gasket_dev,
+   struct gasket_page_table_ioctl __user *argp);
 static int gasket_read_simple_page_table_size(
-   struct gasket_dev *gasket_dev, ulong arg);
+   struct gasket_dev *gasket_dev,
+   struct gasket_page_table_ioctl __user *argp);
 static int gasket_partition_page_table(
-   struct gasket_dev *gasket_dev, ulong arg);
-static int gasket_map_buffers(struct gasket_dev *gasket_dev, ulong arg);
-static int gasket_unmap_buffers(struct gasket_dev *gasket_dev, ulong arg);
+   struct gasket_dev *gasket_dev,
+   struct gasket_page_table_ioctl __user *argp);
+static int gasket_map_buffers(struct gasket_dev *gasket_dev,
+ struct gasket_page_table_ioctl __user *argp);
+static int gasket_unmap_buffers(struct gasket_dev *gasket_dev,
+   struct gasket_page_table_ioctl __user *argp);
 static int gasket_config_coherent_allocator(
-   struct gasket_dev *gasket_dev, ulong arg);
+   struct gasket_dev *gasket_dev,
+   struct gasket_coherent_alloc_config_ioctl __user *argp);
 
 /*
  * standard ioctl dispatch function.
@@ -80,7 +87,7 @@ long gasket_handle_ioctl(struct file *filp, uint cmd, void 
__user *argp)
retval = gasket_reset(gasket_dev, arg);
break;
case GASKET_IOCTL_SET_EVENTFD:
-   retval = gasket_set_event_fd(gasket_dev, arg);
+   retval = gasket_set_event_fd(gasket_dev, argp);
break;
case GASKET_IOCTL_CLEAR_EVENTFD:
trace_gasket_ioctl_integer_data(arg);
@@ -89,31 +96,30 @@ long gasket_handle_ioctl(struct file *filp, uint cmd, void 
__user *argp)
break;
case GASKET_IOCTL_PARTITION_PAGE_TABLE:
trace_gasket_ioctl_integer_data(arg);
-   retval = gasket_partition_page_table(gasket_dev, arg);
+   retval = gasket_partition_page_table(gasket_dev, argp);
break;
case GASKET_IOCTL_NUMBER_PAGE_TABLES:
trace_gasket_ioctl_integer_data(gasket_dev->num_page_tables);
-   if (copy_to_user((void __user *)arg,
-&gasket_dev->num_page_tables,
+   if (copy_to_user(argp, &gasket_dev->num_page_tables,
 sizeof(uint64_t)))
retval = -EFAULT;
else
retval = 0;
break;
case GASKET_IOCTL_PAGE_TABLE_SIZE:
-   retval = gasket_read_page_table_size(gasket_dev, arg);
+   retval = gasket_read_page_table_size(gasket_dev, argp);
break;
case GASKET_IOCTL_SIMPLE_PAGE_TABLE_SIZE:
-   retval = gasket_read_simple_page_table_size(gasket_dev, arg);
+   retval = gasket_read_simple_page_table_size(gasket_dev, argp);
break;
case GASKET_IOCTL_MAP_BUFFER:
-   retval = gasket_map_buffers(gasket_dev, arg);
+   retval = gasket_map_buffers(gasket_dev, argp);
break;
case GASKET_IOCTL_CONFIG_COHERENT_ALLOCATOR:
-   retval = gasket_config_coherent_allocator(gasket_dev, arg);
+   retval = gasket_config_coherent_allocator(gasket_dev, argp);
break;
case GASKET_IOCTL_UNMAP_BUFFER:
-   retval = gasket_unmap_buffers(gasket_dev, arg);
+   retval = gasket_unmap_buffers(gasket_dev, argp);
break;
case GASKET_IOCTL_CLEAR_INTERRUPT_COUNTS:
/* Clear interrupt counts doesn't take an arg, so use 0. */
@@ -218,16 +224,15 @@ static bool gasket_ioctl_check_permissions(struct file 
*filp, uint cmd)
 /*
  * Associate an eventfd with an interrupt.
  * @gasket_dev: Pointer to the current gasket_dev we're using.
- * @arg: Pointer to gasket_interrupt_eventfd struct in userspace.
+ * @argp: Pointer to gasket_interrupt_eventfd struct in userspace.
  */
-static int gasket_set_event_fd(struct gasket_dev *gasket_dev, ulong arg)

Re: [PATCH v3 4/6] KVM: X86: Implement PV IPIs send hypercall

2018-07-19 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 00:47, Paolo Bonzini  wrote:
>
> On 03/07/2018 08:21, Wanpeng Li wrote:
> > +
> > + rcu_read_lock();
> > + map = rcu_dereference(kvm->arch.apic_map);
> > +
> > + for_each_set_bit(i, &ipi_bitmap_low, BITS_PER_LONG) {
> > + vcpu = map->phys_map[i]->vcpu;
> > + if (!kvm_apic_set_irq(vcpu, &irq, NULL))
> > + return 1;
> > + }
> > +
> > + for_each_set_bit(i, &ipi_bitmap_high, BITS_PER_LONG) {
> > + vcpu = map->phys_map[i + BITS_PER_LONG]->vcpu;
> > + if (!kvm_apic_set_irq(vcpu, &irq, NULL))
> > + return 1;
> > + }
> > +
>
> This should be the guest's BITS_PER_LONG, not the host's (i.e. you need
> to pass op_64_bit from kvm_emulate_hypercall).

Will do in next version.

Regards,
Wanpeng Li


[PATCH 07/20] staging: gasket: gasket_mmap return error instead of valid BAR index

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

When offset to be mapped matches both a BAR region and a coherent mapped
region return an error as intended, not the BAR index.

Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index eb5ad161ccda2..3cf918f9d2604 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -1627,7 +1627,7 @@ static int gasket_mmap(struct file *filp, struct 
vm_area_struct *vma)
"0x%lx",
raw_offset);
trace_gasket_mmap_exit(bar_index);
-   return bar_index;
+   return -EINVAL;
}
 
vma->vm_private_data = gasket_dev;
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 19/20] staging: gasket: common ioctl dispatcher add __user annotations

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Add __user annotation to gasket core common ioctl pointer arguments for
sparse checking.

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_ioctl.c | 8 +---
 drivers/staging/gasket/gasket_ioctl.h | 4 +++-
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/gasket/gasket_ioctl.c 
b/drivers/staging/gasket/gasket_ioctl.c
index 8fd44979fe713..998d0e215523c 100644
--- a/drivers/staging/gasket/gasket_ioctl.c
+++ b/drivers/staging/gasket/gasket_ioctl.c
@@ -7,6 +7,7 @@
 #include "gasket_interrupt.h"
 #include "gasket_logging.h"
 #include "gasket_page_table.h"
+#include 
 #include 
 #include 
 
@@ -39,13 +40,14 @@ static int gasket_config_coherent_allocator(
  * standard ioctl dispatch function.
  * @filp: File structure pointer describing this node usage session.
  * @cmd: ioctl number to handle.
- * @arg: ioctl-specific data pointer.
+ * @argp: ioctl-specific data pointer.
  *
  * Standard ioctl dispatcher; forwards operations to individual handlers.
  */
-long gasket_handle_ioctl(struct file *filp, uint cmd, ulong arg)
+long gasket_handle_ioctl(struct file *filp, uint cmd, void __user *argp)
 {
struct gasket_dev *gasket_dev;
+   unsigned long arg = (unsigned long)argp;
int retval;
 
gasket_dev = (struct gasket_dev *)filp->private_data;
@@ -53,7 +55,7 @@ long gasket_handle_ioctl(struct file *filp, uint cmd, ulong 
arg)
 
if (gasket_get_ioctl_permissions_cb(gasket_dev)) {
retval = gasket_get_ioctl_permissions_cb(gasket_dev)(
-   filp, cmd, arg);
+   filp, cmd, argp);
if (retval < 0) {
trace_gasket_ioctl_exit(-EPERM);
return retval;
diff --git a/drivers/staging/gasket/gasket_ioctl.h 
b/drivers/staging/gasket/gasket_ioctl.h
index 461fab27a3e52..51f468c77f041 100644
--- a/drivers/staging/gasket/gasket_ioctl.h
+++ b/drivers/staging/gasket/gasket_ioctl.h
@@ -5,6 +5,8 @@
 
 #include "gasket_core.h"
 
+#include 
+
 /*
  * Handle Gasket common ioctls.
  * @filp: Pointer to the ioctl's file.
@@ -13,7 +15,7 @@
  *
  * Returns 0 on success and nonzero on failure.
  */
-long gasket_handle_ioctl(struct file *filp, uint cmd, ulong arg);
+long gasket_handle_ioctl(struct file *filp, uint cmd, void __user *argp);
 
 /*
  * Determines if an ioctl is part of the standard Gasket framework.
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 02/20] staging: gasket: gasket_enable_dev remove unnecessary variable

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Remove unnecessary variable, pass constant param instead.

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index 0d5ba7359af73..f327c9d7f90a3 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -898,7 +898,6 @@ static int gasket_enable_dev(
 {
int tbl_idx;
int ret;
-   bool has_dma_ops;
struct device *ddev;
const struct gasket_driver_desc *driver_desc =
internal_desc->driver_desc;
@@ -917,8 +916,6 @@ static int gasket_enable_dev(
return ret;
}
 
-   has_dma_ops = true;
-
for (tbl_idx = 0; tbl_idx < driver_desc->num_page_tables; tbl_idx++) {
gasket_log_debug(
gasket_dev, "Initializing page table %d.", tbl_idx);
@@ -936,7 +933,7 @@ static int gasket_enable_dev(
&gasket_dev->bar_data[
driver_desc->page_table_bar_index],
&driver_desc->page_table_configs[tbl_idx],
-   ddev, gasket_dev->pci_dev, has_dma_ops);
+   ddev, gasket_dev->pci_dev, true);
if (ret) {
gasket_log_error(
gasket_dev,
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 18/20] staging: gasket: apex ioctl add __user annotations

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Add __user annotation to ioctl pointer argument, for sparse checking.

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/apex_driver.c | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/gasket/apex_driver.c 
b/drivers/staging/gasket/apex_driver.c
index 4c00f3609f081..3e76c4db5db2e 100644
--- a/drivers/staging/gasket/apex_driver.c
+++ b/drivers/staging/gasket/apex_driver.c
@@ -5,6 +5,7 @@
  * Copyright (C) 2018 Google, Inc.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -142,9 +143,10 @@ static int apex_get_status(struct gasket_dev *gasket_dev);
 
 static bool apex_ioctl_check_permissions(struct file *file, uint cmd);
 
-static long apex_ioctl(struct file *file, uint cmd, ulong arg);
+static long apex_ioctl(struct file *file, uint cmd, void __user *argp);
 
-static long apex_clock_gating(struct gasket_dev *gasket_dev, ulong arg);
+static long apex_clock_gating(struct gasket_dev *gasket_dev,
+ struct apex_gate_clock_ioctl __user *argp);
 
 static int apex_enter_reset(struct gasket_dev *gasket_dev, uint type);
 
@@ -635,7 +637,7 @@ static bool apex_ioctl_check_permissions(struct file *filp, 
uint cmd)
 /*
  * Apex-specific ioctl handler.
  */
-static long apex_ioctl(struct file *filp, uint cmd, ulong arg)
+static long apex_ioctl(struct file *filp, uint cmd, void __user *argp)
 {
struct gasket_dev *gasket_dev = filp->private_data;
 
@@ -644,7 +646,7 @@ static long apex_ioctl(struct file *filp, uint cmd, ulong 
arg)
 
switch (cmd) {
case APEX_IOCTL_GATE_CLOCK:
-   return apex_clock_gating(gasket_dev, arg);
+   return apex_clock_gating(gasket_dev, argp);
default:
return -ENOTTY; /* unknown command */
}
@@ -653,16 +655,17 @@ static long apex_ioctl(struct file *filp, uint cmd, ulong 
arg)
 /*
  * Gates or un-gates Apex clock.
  * @gasket_dev: Gasket device pointer.
- * @arg: User ioctl arg, in this case to a apex_gate_clock_ioctl struct.
+ * @argp: User ioctl arg, pointer to a apex_gate_clock_ioctl struct.
  */
-static long apex_clock_gating(struct gasket_dev *gasket_dev, ulong arg)
+static long apex_clock_gating(struct gasket_dev *gasket_dev,
+ struct apex_gate_clock_ioctl __user *argp)
 {
struct apex_gate_clock_ioctl ibuf;
 
if (bypass_top_level || !allow_sw_clock_gating)
return 0;
 
-   if (copy_from_user(&ibuf, (void __user *)arg, sizeof(ibuf)))
+   if (copy_from_user(&ibuf, argp, sizeof(ibuf)))
return -EFAULT;
 
gasket_log_error(gasket_dev, "%s %llu", __func__, ibuf.enable);
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 11/20] staging: gasket: fix comment syntax in apex.h

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Use kernel-style multi-line comment syntax.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/apex.h | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/gasket/apex.h b/drivers/staging/gasket/apex.h
index 4ef264106f503..d89cc2387b7d4 100644
--- a/drivers/staging/gasket/apex.h
+++ b/drivers/staging/gasket/apex.h
@@ -22,9 +22,10 @@
 
 #define APEX_EXTENDED_SHIFT 63 /* Extended address bit position. */
 
-/* Addresses are 2^3=8 bytes each. */
-/* page in second level page table */
-/* holds APEX_PAGE_SIZE/8 addresses  */
+/*
+ * Addresses are 2^3=8 bytes each. Page in second level page table holds
+ * APEX_PAGE_SIZE/8 addresses.
+ */
 #define APEX_ADDR_SHIFT 3
 #define APEX_LEVEL_SHIFT (APEX_PAGE_SHIFT - APEX_ADDR_SHIFT)
 #define APEX_LEVEL_SIZE BIT(APEX_LEVEL_SHIFT)
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 10/20] staging: gasket: remove else clause after return in if clause

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Else after return is unnecessary and may cause static code checkers to
complain.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_page_table.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/gasket/gasket_page_table.c 
b/drivers/staging/gasket/gasket_page_table.c
index 2a27db658a4e4..617d602b8b447 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -598,9 +598,7 @@ bool gasket_page_table_is_dev_addr_bad(
if (gasket_addr_is_simple(pg_tbl, dev_addr))
return gasket_is_simple_dev_addr_bad(
pg_tbl, dev_addr, num_pages);
-   else
-   return gasket_is_extended_dev_addr_bad(
-   pg_tbl, dev_addr, num_pages);
+   return gasket_is_extended_dev_addr_bad(pg_tbl, dev_addr, num_pages);
 }
 EXPORT_SYMBOL(gasket_page_table_is_dev_addr_bad);
 
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 04/20] staging: gasket: fix class create bug handling

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

class_create() never returns NULL, and this driver should never return
PTR_ERR(NULL) anyway.

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
Reviewed-by: Dmitry Torokhov 
---
 drivers/staging/gasket/gasket_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index 18cc8e3283b39..53236e1ba4e48 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -321,7 +321,7 @@ int gasket_register_device(const struct gasket_driver_desc 
*driver_desc)
internal->class =
class_create(driver_desc->module, driver_desc->name);
 
-   if (IS_ERR_OR_NULL(internal->class)) {
+   if (IS_ERR(internal->class)) {
gasket_nodev_error("Cannot register %s class [ret=%ld]",
   driver_desc->name, PTR_ERR(internal->class));
ret = PTR_ERR(internal->class);
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 00/20 v4] staging: gasket: sundry fixes and fixups

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Various fixes mainly from the chromium review of the gasket and apex
drivers.  More to come.

Todd Poynor (20):
  staging: gasket: allow compile for ARM64 in Kconfig
  staging: gasket: gasket_enable_dev remove unnecessary variable
  staging: gasket: remove code for no physical device
  staging: gasket: fix class create bug handling
  staging: gasket: remove unnecessary code in coherent allocator
  staging: gasket: don't treat no device reset callback as an error
  staging: gasket: gasket_mmap return error instead of valid BAR index
  staging: gasket: apex_clock_gating simplify logic, reduce indentation
  staging: gasket: gasket page table functions use bool return type
  staging: gasket: remove else clause after return in if clause
  staging: gasket: fix comment syntax in apex.h
  staging: gasket: remove unnecessary parens in page table code
  staging: gasket: gasket_mmap use PAGE_MASK
  staging: gasket: remove extra parens in gasket_write_mappable_regions
  staging: gasket: fix multi-line comment syntax in gasket_core.h
  staging: gasket: always allow root open for write
  staging: gasket: top ioctl handler add __user annotations
  staging: gasket: apex ioctl add __user annotations
  staging: gasket: common ioctl dispatcher add __user annotations
  staging: gasket: common ioctls add __user annotations

Patches changed from v3 in v4:
  staging: gasket: remove X86 Kconfig restriction
 Rename: staging: gasket: allow compile for ARM64 in Kconfig
 Restore existing "depends on" for X86_64, add ARM64.  Only compile for
 64-bit architectures known to work with this driver.
  staging: gasket: always allow root open for write
 Fold in patch to convert apex_ioctl_check_permissions to return bool
 Convert gasket_ioctl_check_permissions to use bool types.
  staging: gasket: apex_ioctl_check_permissions use bool return type
 Folded into above patch.
  staging: gasket: annotate ioctl arg with __user
 Split up into new patches:
staging: gasket: top ioctl handler add __user annotations
staging: gasket: apex ioctl add __user annotations
staging: gasket: common ioctl dispatcher add __user annotations
staging: gasket: common ioctls add __user annotations
 Convert various uses of void * to actual type.
 Minor formatting and naming changes.
 Drop Reviewed-By: Dmitry Torokhov due to changes since review.

Patches unchanged from v3 in v4:
  staging: gasket: gasket_enable_dev remove unnecessary variable
  staging: gasket: remove code for no physical device
  staging: gasket: fix class create bug handling
  staging: gasket: remove unnecessary code in coherent allocator
  staging: gasket: don't treat no device reset callback as an error
  staging: gasket: gasket_mmap return error instead of valid BAR index
  staging: gasket: apex_clock_gating simplify logic, reduce indentation
  staging: gasket: gasket page table functions use bool return type
  staging: gasket: remove else clause after return in if clause
  staging: gasket: fix comment syntax in apex.h
  staging: gasket: remove unnecessary parens in page table code
  staging: gasket: gasket_mmap use PAGE_MASK
  staging: gasket: remove extra parens in gasket_write_mappable_regions
  staging: gasket: fix multi-line comment syntax in gasket_core.h

Patches removed from v3 in v4 (already merged to staging-next):
  staging: gasket: fix typo in apex_enter_reset
  staging: gasket: fix typo in gasket_core.h comments
  staging: gasket: whitespace fix in gasket_page_table_init
  staging: gasket: remove driver registration on class creation failure
  staging: gasket: hold mutex on gasket driver unregistration
  staging: gasket: Return EBUSY on mapping create when already in use
  staging: gasket: Remove stale pointers on error allocating attr array
  staging: gasket: convert gasket_mmap_has_permissions to bool return
  staging: gasket: fix gasket_wait_with_reschedule timeout return code
  staging: gasket: gasket_wait_with_reschedule use msleep
  staging: gasket: gasket_wait_with_reschedule simplify logic
  staging: gasket: gasket_wait_with_reschedule use 32 bits of retry
  staging: gasket: bail out of reset sequence on device callback error
  staging: gasket: drop gasket_cdev_get_info, use container_of

 drivers/staging/gasket/Kconfig |   2 +-
 drivers/staging/gasket/apex.h  |   7 +-
 drivers/staging/gasket/apex_driver.c   |  73 +--
 drivers/staging/gasket/gasket_core.c   |  44 +++
 drivers/staging/gasket/gasket_core.h   |  10 +-
 drivers/staging/gasket/gasket_ioctl.c  | 144 +++--
 drivers/staging/gasket/gasket_ioctl.h  |   4 +-
 drivers/staging/gasket/gasket_page_table.c |  64 +
 drivers/staging/gasket/gasket_page_table.h |   8 +-
 9 files changed, 174 insertions(+), 182 deletions(-)

-- 
2.18.0.233.g985f88cf7e-goog



Re: [PATCH v3 2/6] KVM: X86: Implement PV IPIs in linux guest

2018-07-19 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 07:05, David Matlack  wrote:
>
> On Mon, Jul 2, 2018 at 11:23 PM Wanpeng Li  wrote:
> >
> > From: Wanpeng Li 
> >
> > Implement paravirtual apic hooks to enable PV IPIs.
>
> Very cool. Thanks for working on this!

Thanks David!

>
> >
> > apic->send_IPI_mask
> > apic->send_IPI_mask_allbutself
> > apic->send_IPI_allbutself
> > apic->send_IPI_all
> >
> > The PV IPIs supports maximal 128 vCPUs VM, it is big enough for cloud
> > environment currently,
>
> From the Cloud perspective, 128 vCPUs is already obsolete. GCE's
> n1-utlramem-160 VMs have 160 vCPUs where the maximum APIC ID is 231.
> I'd definitely prefer an approach that scales to higher APIC IDs, like
> Paolo's offset idea.

Ok, I will try the offset method in next version.

>
> To Radim's point of real world performance testing, do you know what
> is the primary source of multi-target IPIs? If it's TLB shootdowns we
> might get a bigger bang for our buck with a PV TLB Shootdown.

The "Function Call interrupts", there is a lot of callers for
smp_call_function_many() except TLB Shootdowns in linux kernel which
try to run a function on a set of other CPUs. TLB Shootdown still can
get benefit from PV IPIs even if PV TLB Shootdown is enabled since
IPIs should be sent to the vCPUs which are active and will incur
vmexits. PV IPIs will benefit both vCPUs overcommit and
non-overcommit(which PV TLB Shootdown can't help) scenarios. Btw,
hyperv also implements PV IPIs even if PV TLB Shootdown is present.
https://lkml.org/lkml/2018/7/3/537

Regards,
Wanpeng Li


linux-next: manual merge of the mfd tree with the sound tree

2018-07-19 Thread Stephen Rothwell
Hi all,

Today's linux-next merge of the mfd tree got a conflict in:

  drivers/gpu/drm/i915/Kconfig

between commit:

  a57942bfdd61 ("ALSA: hda: Make audio component support more generic")

from the sound tree and commit:

  9c229127aee2 ("drm/i915: hdmi: add CEC notifier to intel_hdmi")

from the mfd tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc drivers/gpu/drm/i915/Kconfig
index 5c607f2c707b,2d65d567d5d1..
--- a/drivers/gpu/drm/i915/Kconfig
+++ b/drivers/gpu/drm/i915/Kconfig
@@@ -23,7 -23,7 +23,8 @@@ config DRM_I91
select SYNC_FILE
select IOSF_MBI
select CRC32
 +  select SND_HDA_I915 if SND_HDA_CORE
+   select CEC_CORE if CEC_NOTIFIER
help
  Choose this option if you have a system that has "Intel Graphics
  Media Accelerator" or "HD Graphics" integrated graphics,


pgpu8LR9tqAnJ.pgp
Description: OpenPGP digital signature


Re: [PATCH v3 2/6] KVM: X86: Implement PV IPIs in linux guest

2018-07-19 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 00:47, Paolo Bonzini  wrote:
>
> On 19/07/2018 18:28, Radim Krčmář wrote:
> >> +
> >> +kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap_low, ipi_bitmap_high, 
> >> vector);
> > and
> >
> >   kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap[0], ipi_bitmap[1], vector);
> >
> > Still, the main problem is that we can only address 128 APICs.
> >
> > A simple improvement would reuse the vector field (as we need only 8
> > bits) and put a 'offset' in the rest.  The offset would say which
> > cluster of 128 are we addressing.  24 bits of offset results in 2^31
> > total addressable CPUs (we probably should even use that many bits).
> > The downside of this is that we can only address 128 at a time.
> >
> > It's basically the same as x2apic cluster mode, only with 128 cluster
> > size instead of 16, so the code should be a straightforward port.
> > And because x2apic code doesn't seem to use any division by the cluster
> > size, we could even try to use kvm_hypercall4, add ipi_bitmap[2], and
> > make the cluster size 192. :)
>
> I did suggest an offset earlier in the discussion.
>
> The main problem is that consecutive CPU ids do not map to consecutive
> APIC ids.  But still, we could do an hypercall whenever the total range
> exceeds 64.  Something like
>
> u64 ipi_bitmap = 0;
> for_each_cpu(cpu, mask)
> if (!ipi_bitmap) {
> min = max = cpu;
> } else if (cpu < min && max - cpu < 64) {
> ipi_bitmap <<= min - cpu;
> min = cpu;
> } else if (id < min + 64) {
> max = cpu < max ? max : cpu;
> } else {
> /* ... send hypercall... */
> min = max = cpu;
> ipi_bitmap = 0;
> }
> __set_bit(ipi_bitmap, cpu - min);
> }
> if (ipi_bitmap) {
> /* ... send hypercall... */
> }
>
> We could keep the cluster size of 128, but it would be more complicated
> to do the left shift in the first "else if".  If the limit is 64, you
> can keep the two arguments in the hypercall, and just pass 0 as the
> "high" bitmap on 64-bit kernels.

Cool, i will try the offset method in next version. Thanks for your
review, Paolo! :)

Regards,
Wanpeng Li


Re: [PATCH v3 2/6] KVM: X86: Implement PV IPIs in linux guest

2018-07-19 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 00:28, Radim Krčmář  wrote:
>
> 2018-07-03 14:21+0800, Wanpeng Li:
> > From: Wanpeng Li 
> >
> > Implement paravirtual apic hooks to enable PV IPIs.
> >
> > apic->send_IPI_mask
> > apic->send_IPI_mask_allbutself
> > apic->send_IPI_allbutself
> > apic->send_IPI_all
> >
> > The PV IPIs supports maximal 128 vCPUs VM, it is big enough for cloud
> > environment currently, supporting more vCPUs needs to introduce more
> > complex logic, in the future this might be extended if needed.
> >
> > Cc: Paolo Bonzini 
> > Cc: Radim Krčmář 
> > Cc: Vitaly Kuznetsov 
> > Signed-off-by: Wanpeng Li 
> > ---
> > diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
> > @@ -454,6 +454,71 @@ static void __init sev_map_percpu_data(void)
> >  }
> >
> >  #ifdef CONFIG_SMP
> > +
> > +#ifdef CONFIG_X86_64
> > +static void __send_ipi_mask(const struct cpumask *mask, int vector)
> > +{
> > + unsigned long flags, ipi_bitmap_low = 0, ipi_bitmap_high = 0;
> > + int cpu, apic_id;
> > +
> > + if (cpumask_empty(mask))
> > + return;
> > +
> > + local_irq_save(flags);
> > +
> > + for_each_cpu(cpu, mask) {
> > + apic_id = per_cpu(x86_cpu_to_apicid, cpu);
> > + if (apic_id < BITS_PER_LONG)
> > + __set_bit(apic_id, &ipi_bitmap_low);
> > + else if (apic_id < 2 * BITS_PER_LONG)
> > + __set_bit(apic_id - BITS_PER_LONG, &ipi_bitmap_high);
>
> It'd be nicer with 'unsigned long ipi_bitmap[2]' and a single
>
> __set_bit(apic_id, ipi_bitmap);
>
> > + }
> > +
> > + kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap_low, ipi_bitmap_high, 
> > vector);
>
> and
>
> kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap[0], ipi_bitmap[1], vector);
>
> Still, the main problem is that we can only address 128 APICs.
>
> A simple improvement would reuse the vector field (as we need only 8
> bits) and put a 'offset' in the rest.  The offset would say which
> cluster of 128 are we addressing.  24 bits of offset results in 2^31
> total addressable CPUs (we probably should even use that many bits).
> The downside of this is that we can only address 128 at a time.
>
> It's basically the same as x2apic cluster mode, only with 128 cluster
> size instead of 16, so the code should be a straightforward port.
> And because x2apic code doesn't seem to use any division by the cluster
> size, we could even try to use kvm_hypercall4, add ipi_bitmap[2], and
> make the cluster size 192. :)
>
> But because it is very similar to x2apic, I'd really need some real
> performance data to see if this benefits a real workload.

Thanks for your review, Radim! :) I will find another real benchmark
instead of the micro one to evaluate the performance.

> Hardware could further optimize LAPIC (apicv, vapic) in the future,
> which we'd lose by using paravirt.
>
> e.g. AMD's acceleration should be superior to this when using < 8 VCPUs
> as they can use logical xAPIC and send without VM exits (when all VCPUs
> are running).
>
> > +
> > + local_irq_restore(flags);
> > +}
> > +
> > +static void kvm_send_ipi_mask(const struct cpumask *mask, int vector)
> > +{
> > + __send_ipi_mask(mask, vector);
> > +}
> > +
> > +static void kvm_send_ipi_mask_allbutself(const struct cpumask *mask, int 
> > vector)
> > +{
> > + unsigned int this_cpu = smp_processor_id();
> > + struct cpumask new_mask;
> > + const struct cpumask *local_mask;
> > +
> > + cpumask_copy(&new_mask, mask);
> > + cpumask_clear_cpu(this_cpu, &new_mask);
> > + local_mask = &new_mask;
> > + __send_ipi_mask(local_mask, vector);
> > +}
> > +
> > +static void kvm_send_ipi_allbutself(int vector)
> > +{
> > + kvm_send_ipi_mask_allbutself(cpu_online_mask, vector);
> > +}
> > +
> > +static void kvm_send_ipi_all(int vector)
> > +{
> > + __send_ipi_mask(cpu_online_mask, vector);
>
> These should be faster when using the native APIC shorthand -- is this
> the "Broadcast" in your tests?

Not true, .send_IPI_all almost no callers though linux apic drivers
implement this hook, in addition, shortcut is not used for x2apic
mode(__x2apic_send_IPI_dest()), and very limited using in other
scenarios according to linux apic drivers.

>
> > +}
> > +
> > +/*
> > + * Set the IPI entry points
> > + */
> > +static void kvm_setup_pv_ipi(void)
> > +{
> > + apic->send_IPI_mask = kvm_send_ipi_mask;
> > + apic->send_IPI_mask_allbutself = kvm_send_ipi_mask_allbutself;
> > + apic->send_IPI_allbutself = kvm_send_ipi_allbutself;
> > + apic->send_IPI_all = kvm_send_ipi_all;
> > + pr_info("KVM setup pv IPIs\n");
> > +}
> > +#endif
> > +
> >  static void __init kvm_smp_prepare_cpus(unsigned int max_cpus)
> >  {
> >   native_smp_prepare_cpus(max_cpus);
> > @@ -626,6 +691,11 @@ static uint32_t __init kvm_detect(void)
> >
> >  static void __init kvm_apic_init(void)
> >  {
> > +#if defined(CONFIG_SMP) && defined(CONFIG_X86_64)
> > + if (kvm_para_has_feature(KVM_FEATURE_PV_

Re: [PATCH] ARM: dts: imx7d: remove "operating-points" property for cpu1

2018-07-19 Thread Shawn Guo
On Thu, Jul 19, 2018 at 04:24:19PM +0800, Anson Huang wrote:
> Commit b97872d4eb22 ("ARM: dts: imx: Add missing OPP properties for CPUs")
> added "operating-points" property for all CPUs, but i.MX7D already has
> "operating-points-v2" property on both CPUs, so no need to add
> "operating-points" property again, this patch removes it.
> 
> Fixes: b97872d4eb22 ("ARM: dts: imx: Add missing OPP properties for CPUs")
> Signed-off-by: Anson Huang 

Applied, thanks.


Re: [PATCH v2] ARM: dts: vf610: Add ZII CFU1 board

2018-07-19 Thread Shawn Guo
On Thu, Jul 19, 2018 at 12:57:24PM -0700, Andrey Smirnov wrote:
> Add support for the Zodiac Inflight Innovations CFU1
> board (VF610-based).
> 
> Cc: Shawn Guo 
> Cc: Fabio Estevam 
> Cc: cphe...@gmail.com
> Cc: linux-arm-ker...@lists.infradead.org
> Cc: devicet...@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Reviewed-by: Fabio Estevam 
> Signed-off-by: Andrew Lunn 
> Signed-off-by: Andrey Smirnov 

Applied, thanks.


Re: [PATCH] ARM: dts: vf610-zii-ssmb-spu3: Fix W=1 level warnings

2018-07-19 Thread Shawn Guo
On Thu, Jul 19, 2018 at 01:00:02PM -0700, Andrey Smirnov wrote:
> Fix a couple of things that were causing warning when building DTB
> with W=1.
> 
> Cc: Shawn Guo 
> Cc: Fabio Estevam 
> Cc: cphe...@gmail.com
> Cc: linux-arm-ker...@lists.infradead.org
> Cc: devicet...@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Andrey Smirnov 

Applied, thanks.


Re: [PATCH 17/32] staging: gasket: annotate ioctl arg with __user

2018-07-19 Thread Todd Poynor
On Thu, Jul 19, 2018 at 2:37 AM, Greg Kroah-Hartman
 wrote:
> On Tue, Jul 17, 2018 at 01:56:57PM -0700, Todd Poynor wrote:
>> From: Todd Poynor 
>>
>> For sparse checking.
>
> Close, but you can do better :)
>
>>
>> Reported-by: Dmitry Torokhov 
>> Signed-off-by: Zhongze Hu 
>> Signed-off-by: Todd Poynor 
>> Reviewed-by: Dmitry Torokhov 
>> ---
>>  drivers/staging/gasket/apex_driver.c  | 11 ++--
>>  drivers/staging/gasket/gasket_core.c  |  6 ++-
>>  drivers/staging/gasket/gasket_core.h  |  4 +-
>>  drivers/staging/gasket/gasket_ioctl.c | 72 ++-
>>  drivers/staging/gasket/gasket_ioctl.h |  4 +-
>>  5 files changed, 52 insertions(+), 45 deletions(-)
>>
>> diff --git a/drivers/staging/gasket/apex_driver.c 
>> b/drivers/staging/gasket/apex_driver.c
>> index 612b3ab803196..c91c5aff5ab9c 100644
>> --- a/drivers/staging/gasket/apex_driver.c
>> +++ b/drivers/staging/gasket/apex_driver.c
>> @@ -5,6 +5,7 @@
>>   * Copyright (C) 2018 Google, Inc.
>>   */
>>
>> +#include 
>>  #include 
>>  #include 
>>  #include 
>> @@ -142,9 +143,9 @@ static int apex_get_status(struct gasket_dev 
>> *gasket_dev);
>>
>>  static uint apex_ioctl_check_permissions(struct file *file, uint cmd);
>>
>> -static long apex_ioctl(struct file *file, uint cmd, ulong arg);
>> +static long apex_ioctl(struct file *file, uint cmd, void __user *arg);
>>
>> -static long apex_clock_gating(struct gasket_dev *gasket_dev, ulong arg);
>> +static long apex_clock_gating(struct gasket_dev *gasket_dev, void __user 
>> *arg);
>
> Make this a __user pointer to the correct struct type you are handling
> here.  You know what the type is, use it.

Got it.

>
>>  static int apex_enter_reset(struct gasket_dev *gasket_dev, uint type);
>>
>> @@ -635,7 +636,7 @@ static uint apex_ioctl_check_permissions(struct file 
>> *filp, uint cmd)
>>  /*
>>   * Apex-specific ioctl handler.
>>   */
>> -static long apex_ioctl(struct file *filp, uint cmd, ulong arg)
>> +static long apex_ioctl(struct file *filp, uint cmd, void __user *arg)
>>  {
>>   struct gasket_dev *gasket_dev = filp->private_data;
>>
>> @@ -655,7 +656,7 @@ static long apex_ioctl(struct file *filp, uint cmd, 
>> ulong arg)
>>   * @gasket_dev: Gasket device pointer.
>>   * @arg: User ioctl arg, in this case to a apex_gate_clock_ioctl struct.
>>   */
>> -static long apex_clock_gating(struct gasket_dev *gasket_dev, ulong arg)
>> +static long apex_clock_gating(struct gasket_dev *gasket_dev, void __user 
>> *arg)
>
> As above, this should be a different type.
>
>>  {
>>   struct apex_gate_clock_ioctl ibuf;
>>
>> @@ -663,7 +664,7 @@ static long apex_clock_gating(struct gasket_dev 
>> *gasket_dev, ulong arg)
>>   return 0;
>>
>>   if (allow_sw_clock_gating) {
>> - if (copy_from_user(&ibuf, (void __user *)arg, sizeof(ibuf)))
>> + if (copy_from_user(&ibuf, arg, sizeof(ibuf)))
>>   return -EFAULT;
>>
>>   gasket_log_error(
>> diff --git a/drivers/staging/gasket/gasket_core.c 
>> b/drivers/staging/gasket/gasket_core.c
>> index 947b4fcc76970..ff34af42bbe7c 100644
>> --- a/drivers/staging/gasket/gasket_core.c
>> +++ b/drivers/staging/gasket/gasket_core.c
>> @@ -14,6 +14,7 @@
>>  #include "gasket_page_table.h"
>>  #include "gasket_sysfs.h"
>>
>> +#include 
>>  #include 
>>  #include 
>>  #include 
>> @@ -1823,14 +1824,15 @@ static long gasket_ioctl(struct file *filp, uint 
>> cmd, ulong arg)
>>* check_and_invoke_callback.
>>*/
>>   if (driver_desc->ioctl_handler_cb)
>> - return driver_desc->ioctl_handler_cb(filp, cmd, arg);
>> + return driver_desc->ioctl_handler_cb(
>> + filp, cmd, (void __user *)arg);
>
> You can use a temp variable and then only have to cast things once then,
> instead of twice, if you care.  Not a big deal.

But then I have to name it, and I suck at that. :P  I'm trying
switching to "arg" for ulong/int arguments and "argp" for pointer
arguments.

>
>>
>>   gasket_log_error(
>>   gasket_dev, "Received unknown ioctl 0x%x", cmd);
>
> This is a fun way to cause a DoS on your system, you should fix this up
> in later changes.

Yeah there's another patch coming soon that converts a bunch of errors
and infos to debugs.

>
>>   return -EINVAL;
>>   }
>>
>> - return gasket_handle_ioctl(filp, cmd, arg);
>> + return gasket_handle_ioctl(filp, cmd, (void __user *)arg);
>>  }
>>
>>  int gasket_reset(struct gasket_dev *gasket_dev, uint reset_type)
>> diff --git a/drivers/staging/gasket/gasket_core.h 
>> b/drivers/staging/gasket/gasket_core.h
>> index 50ad0c8853183..68b4d2ac9fd6c 100644
>> --- a/drivers/staging/gasket/gasket_core.h
>> +++ b/drivers/staging/gasket/gasket_core.h
>> @@ -315,7 +315,7 @@ struct gasket_dev {
>>
>>  /* Type of the ioctl permissions check callback. See below. */
>>  typedef int (*gasket_ioctl_permissions_cb_t)(
>> - struct file *filp, 

[PATCH] arch/h8300: eliminate kgbd.c warning

2018-07-19 Thread Randy Dunlap
From: Randy Dunlap 

Drop the "const" qualifier from arch_kgdb_ops to eliminate the gcc
warning (gcc version is 8.1.0).

arch/h8300/kernel/kgdb.c:132:24: error: conflicting type qualifiers for 
'arch_kgdb_ops'
 const struct kgdb_arch arch_kgdb_ops = {
In file included from ../arch/h8300/kernel/kgdb.c:12:
../include/linux/kgdb.h:284:26: note: previous declaration of 'arch_kgdb_ops' 
was here
 extern struct kgdb_arch  arch_kgdb_ops;

Signed-off-by: Randy Dunlap 
Cc: Yoshinori Sato 
Cc: uclinux-h8-de...@lists.sourceforge.jp
---
 arch/h8300/kernel/kgdb.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- linux-next-20180717.orig/arch/h8300/kernel/kgdb.c
+++ linux-next-20180717/arch/h8300/kernel/kgdb.c
@@ -129,7 +129,7 @@ void kgdb_arch_exit(void)
/* Nothing to do */
 }
 
-const struct kgdb_arch arch_kgdb_ops = {
+struct kgdb_arch arch_kgdb_ops = {
/* Breakpoint instruction: trapa #2 */
.gdb_bpt_instr = { 0x57, 0x20 },
 };




[PATCH] arch/h8300: eliminate ptrace.h warnings

2018-07-19 Thread Randy Dunlap
From: Randy Dunlap 

Add a "struct task_struct;" stub to arch/h8300's ptrace.h header to
eliminate gcc warnings (gcc version is 8.1.0).

../arch/h8300/include/asm/ptrace.h:32:34: warning: 'struct task_struct' 
declared inside parameter list will not be visible outside of this definition 
or declaration
 extern long h8300_get_reg(struct task_struct *task, int regno);
../arch/h8300/include/asm/ptrace.h:33:33: warning: 'struct task_struct' 
declared inside parameter list will not be visible outside of this definition 
or declaration
 extern int h8300_put_reg(struct task_struct *task, int regno,

Signed-off-by: Randy Dunlap 
Cc: Yoshinori Sato 
Cc: uclinux-h8-de...@lists.sourceforge.jp
---
 arch/h8300/include/asm/ptrace.h |2 ++
 1 file changed, 2 insertions(+)

--- linux-next-20180717.orig/arch/h8300/include/asm/ptrace.h
+++ linux-next-20180717/arch/h8300/include/asm/ptrace.h
@@ -4,6 +4,8 @@
 
 #include 
 
+struct task_struct;
+
 #ifndef __ASSEMBLY__
 #ifndef PS_S
 #define PS_S  (0x10)




RE: [PATCH 2/2] spi: add SPI controller driver for UniPhier SoC

2018-07-19 Thread Keiji Hayashibara
Hi Trent,

> -Original Message-
> From: Trent Piepho [mailto:tpie...@impinj.com]
> Sent: Friday, July 20, 2018 4:46 AM
> Subject: Re: [PATCH 2/2] spi: add SPI controller driver for UniPhier SoC
> 
> On Thu, 2018-07-19 at 15:51 +0900, Keiji Hayashibara wrote:
> >
> > +config SPI_UNIPHIER
> > +   tristate "Socionext UniPhier SPI Controller"
> > +   depends on (ARCH_UNIPHIER || COMPILE_TEST) && OF
> > +   help
> > + This driver supports the SPI controller on Socionext
> > + UniPhier SoCs.
> 
> Perhaps add the bit that this is for the SCSSI and not MCSSI here?

OK. I will add it.

> >
> > +
> > +#define BYTES_PER_WORD(x)  \
> > +({ \
> > +   int __x;\
> > +   __x = (x <= 8)  ? 1 :   \
> > + (x <= 16) ? 2 : 4;\
> > +   __x;\
> > +})
> 
> Or:
> 
> static inline bytes_per_word(unsigned int bits) {
>return bits <= 8 ? 1 : (bits <= 16 ? 2 : 4); }

I will modify.


> 
> > +
> > +static inline void uniphier_spi_irq_enable(struct spi_device *spi,
> > +u32 mask) {
> > +   struct uniphier_spi_priv *priv = spi_master_get_devdata(spi->master);
> > +   u32 val;
> > +
> > +   val = readl(priv->base + SSI_IE);
> > +   val |= mask;
> > +   writel(val, priv->base + SSI_IE);
> > +}
> > +
> > +static inline void uniphier_spi_irq_disable(struct spi_device *spi,
> > +u32 mask) {
> > +   struct uniphier_spi_priv *priv = spi_master_get_devdata(spi->master);
> > +   u32 val;
> > +
> > +   val = readl(priv->base + SSI_IE);
> > +   val &= ~mask;
> > +   writel(val, priv->base + SSI_IE);
> > +}
> > +
> > +static void uniphier_spi_set_transfer_size(struct spi_device *spi,
> > +int size) {
> > +   struct uniphier_spi_priv *priv = spi_master_get_devdata(spi->master);
> > +   u32 val;
> > +
> > +   val = readl(priv->base + SSI_TXWDS);
> > +   val &= ~(SSI_TXWDS_WDLEN_MASK | SSI_TXWDS_DTLEN_MASK);
> > +   val |= FIELD_PREP(SSI_TXWDS_WDLEN_MASK, size);
> > +   val |= FIELD_PREP(SSI_TXWDS_DTLEN_MASK, size);
> > +   writel(val, priv->base + SSI_TXWDS);
> > +
> > +   val = readl(priv->base + SSI_RXWDS);
> > +   val &= ~SSI_RXWDS_DTLEN_MASK;
> > +   val |= FIELD_PREP(SSI_RXWDS_DTLEN_MASK, size);
> > +   writel(val, priv->base + SSI_RXWDS); }
> > +
> > +static int uniphier_spi_set_baudrate(struct spi_device *spi, unsigned
> > +int speed) {
> > +   struct uniphier_spi_priv *priv = spi_master_get_devdata(spi->master);
> > +   u32 val, ckrat;
> > +
> > +   /*
> > +* the supported rates are even numbers from 4 to 254. (4,6,8...254)
> > +* round up as we look for equal or less speed
> > +*/
> > +   ckrat = DIV_ROUND_UP(clk_get_rate(priv->clk), speed);
> > +   ckrat = roundup(ckrat, 2);
> > +
> > +   /* check if requested speed is too small */
> > +   if (ckrat > SSI_MAX_CLK_DIVIDER)
> > +   return -EINVAL;
> > +
> > +   if (ckrat < SSI_MIN_CLK_DIVIDER)
> > +   ckrat = SSI_MIN_CLK_DIVIDER;
> > +
> > +   val = readl(priv->base + SSI_CKS);
> > +   val &= ~SSI_CKS_CKRAT_MASK;
> > +   val |= ckrat & SSI_CKS_CKRAT_MASK;
> > +   writel(val, priv->base + SSI_CKS);
> > +
> > +   return 0;
> > +}
> > +
> > +static int uniphier_spi_setup_transfer(struct spi_device *spi,
> > +  struct spi_transfer *t)
> > +{
> > +   struct uniphier_spi_priv *priv = spi_master_get_devdata(spi->master);
> > +   u32 val;
> > +   int ret;
> > +
> > +   priv->error = 0;
> > +   priv->tx_buf = t->tx_buf;
> > +   priv->rx_buf = t->rx_buf;
> > +   priv->tx_bytes = priv->rx_bytes = t->len;
> > +
> > +   if (priv->bits_per_word != t->bits_per_word) {
> > +   uniphier_spi_set_transfer_size(spi, t->bits_per_word);
> > +   priv->bits_per_word = t->bits_per_word;
> > +   }
> > +
> > +   if (priv->speed_hz != t->speed_hz) {
> > +   ret = uniphier_spi_set_baudrate(spi, t->speed_hz);
> > +   if (ret)
> > +   return ret;
> > +   priv->speed_hz = t->speed_hz;
> > +   }
> > +
> > +   /* reset FIFOs */
> > +   val = SSI_FC_TXFFL | SSI_FC_RXFFL;
> > +   writel(val, priv->base + SSI_FC);
> > +
> > +   return 0;
> > +}
> > +
> > +static void uniphier_spi_send(struct uniphier_spi_priv *priv) {
> > +   int i, loop;
> > +   u32 val = 0;
> > +
> > +   loop = BYTES_PER_WORD(priv->bits_per_word);
> > +   if (priv->tx_bytes < loop)
> > +   loop = priv->tx_bytes;
> > +
> > +   priv->tx_bytes -= loop;
> > +
> > +   if (priv->tx_buf)
> > +   for (i = 0; i < loop; i++) {
> > +   val |= (*(const u8 *)priv->tx_buf)
> > +   << (BITS_PER_BYTE * i);
> 
> priv->tx_buf is already a const u8*, no need to cast it.  Also in recv,
> no need to cast the pointer.  It'll just hide errors if someone changes the 
> type of the field.

I agree.

> > +   (const u8 *)priv->tx_buf++;
> > +   }
> > +
> > +   writel(val, priv->base + SSI_TXDR);
> >

Re: [V9fs-developer] KASAN: use-after-free Read in generic_perform_write

2018-07-19 Thread Matthew Wilcox
On Fri, Jul 20, 2018 at 02:27:05AM +0200, Dominique Martinet wrote:
> Andrew Morton wrote on Thu, Jul 19, 2018:
> > On Thu, 19 Jul 2018 11:01:01 -0700 syzbot 
> >  wrote:
> > > Hello,
> > > 
> > > syzbot found the following crash on:
> > > 
> > > HEAD commit:1c34981993da Add linux-next specific files for 20180719
> > > git tree:   linux-next
> > > console output: https://syzkaller.appspot.com/x/log.txt?x=16e6ac4440
> > > kernel config:  https://syzkaller.appspot.com/x/.config?x=7002497517b09aec
> > > dashboard link: 
> > > https://syzkaller.appspot.com/bug?extid=b173e77096a8ba815511
> > > compiler:   gcc (GCC) 8.0.1 20180413 (experimental)
> > > 
> > > Unfortunately, I don't have any reproducer for this crash yet.
> 
> > I'm suspecting v9fs.  Does that fs attempt to write to the fs from a
> > kmalloced buffer?
> 
> Difficult to say without any idea of what syzkaller tried doing, but it
> looks like it hook'd up a fd opened to a local ext4 file into a trans_fd
> mount; so sending a packet to the "server" would trigger a local write
> instead.
> The reason it's freed too early probably is that the reply came from a
> read before the write happened; this is going to be tricky to fix as
> that write is 100% asynchronous without any feedback right now (the
> design assumes that the write has to have finished by the time reply
> came), but if we want to protect ourselves from rogue servers we'll have
> to think about something.
> 
> I'll write it down to not forget, thanks for the cc.

I suspect this got unmasked by my changes; before it would allocate
buffers and just leave them around.  Now it'll free them, which means we
get to see this reuse (rather than having the buffer reused and getting
corrupt data written).

Not that I'm volunteering to fix this problem ;-)


Re: [PATCH 4/4] perf tools: Fix struct comm_str removal crash

2018-07-19 Thread Namhyung Kim
Hi Arnaldo,

On Thu, Jul 19, 2018 at 03:31:14PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Thu, Jul 19, 2018 at 03:28:43PM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Thu, Jul 19, 2018 at 04:33:45PM +0200, Jiri Olsa escreveu:
> > > +++ b/tools/perf/util/comm.c
> > > @@ -18,11 +18,9 @@ struct comm_str {
> > >  static struct rb_root comm_str_root;
> > >  static struct rw_semaphore comm_str_lock = {.lock = 
> > > PTHREAD_RWLOCK_INITIALIZER,};
> > >  
> > > -static struct comm_str *comm_str__get(struct comm_str *cs)
> > > +static bool comm_str__get(struct comm_str *cs)
> > >  {
> > > - if (cs)
> > > - refcount_inc(&cs->refcnt);
> > > - return cs;
> > > + return cs ? refcount_inc_not_zero(&cs->refcnt) : false;
> > >  }
> > 
> > I don't like changing the semantics of a __get() operation this way, I
> > think it should stay like all the others, i.e. return the object with
> > the desired refcount or return NULL if that is not possible.
> > 
> > Otherwise we'll have to switch gears when debugging refcounts in various
> > objects, that start having slightly different semantics for reference
> > counting.
> > 
> > We should try to find a fix that maintains the semantics of refcounting.
> 
> After looking at the code, this refcount_inc_not_zero returns bool comes
> from the kernel, trying to see how this is used with __get() operations
> there, if at all.

Something like this?

static struct comm_str *comm_str__get(struct comm_str *cs)
{
if (cs && refcount_inc_not_zero(&cs->refcnt))
return cs;
return NULL;
}


Other than that I don't have better idea, so

Acked-by: Namhyung Kim 

Thanks,
Namhyung


linux-next: manual merge of the pci tree with Linus' tree

2018-07-19 Thread Stephen Rothwell
Hi all,

Today's linux-next merge of the pci tree got a conflict in:

  drivers/pci/controller/pci-aardvark.c

between commit:

  1df3e5b3feeb ("PCI: aardvark: Fix I/O space page leak")

from Linus' tree and commit:

  6df6ba974a55 ("PCI: aardvark: Remove PCIe outbound window configuration")

from the pci tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc drivers/pci/controller/pci-aardvark.c
index 0fae816fba39,d5030cd06197..
--- a/drivers/pci/controller/pci-aardvark.c
+++ b/drivers/pci/controller/pci-aardvark.c
@@@ -843,13 -809,7 +809,7 @@@ static int advk_pcie_parse_request_of_p
  
switch (resource_type(res)) {
case IORESOURCE_IO:
-   advk_pcie_set_ob_win(pcie, 1,
-upper_32_bits(res->start),
-lower_32_bits(res->start),
-0, 0xF800, 0,
-lower_32_bits(res->start),
-OB_PCIE_IO);
 -  err = pci_remap_iospace(res, iobase);
 +  err = devm_pci_remap_iospace(dev, res, iobase);
if (err) {
dev_warn(dev, "error %d: failed to map resource 
%pR\n",
 err, res);


pgpcvH5m1eyP6.pgp
Description: OpenPGP digital signature


Re: [PATCH v3 2/4] x86/boot: Add acpitb.c to parse acpi tables

2018-07-19 Thread Chao Fan
On Thu, Jul 19, 2018 at 05:22:35PM +0200, Thomas Gleixner wrote:
>On Tue, 17 Jul 2018, Chao Fan wrote:
>> +
>> +/* Search efi table for rsdp table. */
>> +static bool efi_get_rsdp_addr(acpi_physical_address *rsdp_addr)
>> +{
>> +efi_system_table_t *systab;
>> +bool find_rsdp = false;
>> +bool acpi_20 = false;
>> +bool efi_64 = false;
>> +void *config_tables;
>> +struct efi_info *e;
>> +char *sig;
>> +int size;
>> +int i;
>> +
>> +#ifndef CONFIG_EFI
>> +return false;
>> +#endif
>
>Please no. Wrap the whole function into CONFIG_EFI annd have a stub for the
>non EFI case returning false.

Yes, you are right. Will change it in the next version.

Thanks,
Chao Fan

>
>Thanks,
>
>   tglx
>
>




Re: [PATCH] uio: fix wrong return value from uio_mmap()

2018-07-19 Thread Xiubo Li

On 2018/7/20 8:31, Hailong Liu wrote:

uio_mmap has multiple fail paths to set return value to nonzero then
goto out. However, it always returns *0* from the *out* at end, and
this will mislead callers who check the return value of this function.

Fixes: 57c5f4df0a5a0ee ("uio: fix crash after the device is unregistered")
CC: Xiubo Li 
Signed-off-by: Hailong Liu 
Signed-off-by: Jiang Biao 
---
  drivers/uio/uio.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 5d421d7..0ddfda2 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -814,7 +814,7 @@ static int uio_mmap(struct file *filep, struct 
vm_area_struct *vma)
  
  out:

mutex_unlock(&idev->info_lock);
-   return 0;
+   return ret;

Hi Hailong,

Good catch, Thanks.

BRs



  }
  
  static const struct file_operations uio_fops = {





[PATCH 4/5] time: Fix extra sleeptime injection when suspend fails

2018-07-19 Thread John Stultz
From: Mukesh Ojha 

Currently, there exists a corner case assuming when there is
only one clocksource e.g RTC, and system failed to go to
suspend mode. While resume rtc_resume() injects the sleeptime
as timekeeping_rtc_skipresume() returned 'false' (default value
of sleeptime_injected) due to which we can see mismatch in
timestamps.

This issue can also come in a system where more than one
clocksource are present and very first suspend fails.

Success case:

{sleeptime_injected=false}
rtc_suspend() => timekeeping_suspend() => timekeeping_resume() =>

(sleeptime injected)
 rtc_resume()

Failure case:

 {failure in sleep path} {sleeptime_injected=false}
rtc_suspend() =>  rtc_resume()

{sleeptime injected again which was not required as the suspend failed}

Fix this by handling the boolean logic properly.

Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: Miroslav Lichvar 
Cc: Richard Cochran 
Cc: Prarit Bhargava 
Cc: Stephen Boyd 
Originally-by: Thomas Gleixner 
Signed-off-by: Mukesh Ojha 
Signed-off-by: John Stultz 
---
 kernel/time/timekeeping.c | 32 +---
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 7033ac1..19414b1 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1519,8 +1519,20 @@ void __weak read_boot_clock64(struct timespec64 *ts)
ts->tv_nsec = 0;
 }
 
-/* Flag for if timekeeping_resume() has injected sleeptime */
-static bool sleeptime_injected;
+/*
+ * Flag reflecting whether timekeeping_resume() has injected sleeptime.
+ *
+ * The flag starts of false and is only set when a suspend reaches
+ * timekeeping_suspend(), timekeeping_resume() sets it to false when the
+ * timekeeper clocksource is not stopping across suspend and has been
+ * used to update sleep time. If the timekeeper clocksource has stopped
+ * then the flag stays true and is used by the RTC resume code to decide
+ * whether sleeptime must be injected and if so the flag gets false then.
+ *
+ * If a suspend fails before reaching timekeeping_resume() then the flag
+ * stays false and prevents erroneous sleeptime injection.
+ */
+static bool suspend_timing_needed;
 
 /* Flag for if there is a persistent clock on this platform */
 static bool persistent_clock_exists;
@@ -1619,7 +1631,7 @@ static void __timekeeping_inject_sleeptime(struct 
timekeeper *tk,
  */
 bool timekeeping_rtc_skipresume(void)
 {
-   return sleeptime_injected;
+   return !suspend_timing_needed;
 }
 
 /**
@@ -1655,6 +1667,8 @@ void timekeeping_inject_sleeptime64(const struct 
timespec64 *delta)
raw_spin_lock_irqsave(&timekeeper_lock, flags);
write_seqcount_begin(&tk_core.seq);
 
+   suspend_timing_needed = false;
+
timekeeping_forward_now(tk);
 
__timekeeping_inject_sleeptime(tk, delta);
@@ -1679,8 +1693,8 @@ void timekeeping_resume(void)
unsigned long flags;
struct timespec64 ts_new, ts_delta;
u64 cycle_now;
+   bool inject_sleeptime = false;
 
-   sleeptime_injected = false;
read_persistent_clock64(&ts_new);
 
clockevents_resume();
@@ -1710,14 +1724,16 @@ void timekeeping_resume(void)
  tk->tkr_mono.mask);
nsec = mul_u64_u32_shr(cyc_delta, clock->mult, clock->shift);
ts_delta = ns_to_timespec64(nsec);
-   sleeptime_injected = true;
+   inject_sleeptime = true;
} else if (timespec64_compare(&ts_new, &timekeeping_suspend_time) > 0) {
ts_delta = timespec64_sub(ts_new, timekeeping_suspend_time);
-   sleeptime_injected = true;
+   inject_sleeptime = true;
}
 
-   if (sleeptime_injected)
+   if (inject_sleeptime) {
+   suspend_timing_needed = false;
__timekeeping_inject_sleeptime(tk, &ts_delta);
+   }
 
/* Re-base the last cycle value */
tk->tkr_mono.cycle_last = cycle_now;
@@ -1752,6 +1768,8 @@ int timekeeping_suspend(void)
if (timekeeping_suspend_time.tv_sec || timekeeping_suspend_time.tv_nsec)
persistent_clock_exists = true;
 
+   suspend_timing_needed = true;
+
raw_spin_lock_irqsave(&timekeeper_lock, flags);
write_seqcount_begin(&tk_core.seq);
timekeeping_forward_now(tk);
-- 
2.7.4



[PATCH 5/5] time: Introduce one suspend clocksource to compensate the suspend time

2018-07-19 Thread John Stultz
From: Baolin Wang 

On some hardware with multiple clocksources, we have coarse grained
clocksources that support the CLOCK_SOURCE_SUSPEND_NONSTOP flag, but
which are less than ideal for timekeeping whereas other clocksources
can be better candidates but halt on suspend.

Currently, the timekeeping core only supports timing suspend using
CLOCK_SOURCE_SUSPEND_NONSTOP clocksources if that clocksource is the
current clocksource for timekeeping.

As a result, some architectures try to implement read_persistent_clock64()
using those non-stop clocksources, but isn't really ideal, which will
introduce more duplicate code. To fix this, provide logic to allow a
registered SUSPEND_NONSTOP clocksource, which isn't the current
clocksource, to be used to calculate the suspend time.

Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: Miroslav Lichvar 
Cc: Richard Cochran 
Cc: Prarit Bhargava 
Cc: Stephen Boyd 
Cc: Daniel Lezcano 
Reviewed-by: Thomas Gleixner 
Reviewed-by: Daniel Lezcano 
Suggested-by: Thomas Gleixner 
Signed-off-by: Baolin Wang 
[jstultz: minor tweaks to merge with previous resume changes]
Signed-off-by: John Stultz 
---
 include/linux/clocksource.h |   3 +
 kernel/time/clocksource.c   | 149 
 kernel/time/timekeeping.c   |  22 ---
 3 files changed, 166 insertions(+), 8 deletions(-)

diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index 7dff196..3089189 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -194,6 +194,9 @@ extern void clocksource_suspend(void);
 extern void clocksource_resume(void);
 extern struct clocksource * __init clocksource_default_clock(void);
 extern void clocksource_mark_unstable(struct clocksource *cs);
+extern void
+clocksource_start_suspend_timing(struct clocksource *cs, u64 start_cycles);
+extern u64 clocksource_stop_suspend_timing(struct clocksource *cs, u64 now);
 
 extern u64
 clocks_calc_max_nsecs(u32 mult, u32 shift, u32 maxadj, u64 mask, u64 
*max_cycles);
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index f89a78e..f74fb00 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -94,6 +94,8 @@ EXPORT_SYMBOL_GPL(clocks_calc_mult_shift);
 /*[Clocksource internal variables]-
  * curr_clocksource:
  * currently selected clocksource.
+ * suspend_clocksource:
+ * used to calculate the suspend time.
  * clocksource_list:
  * linked list with the registered clocksources
  * clocksource_mutex:
@@ -102,10 +104,12 @@ EXPORT_SYMBOL_GPL(clocks_calc_mult_shift);
  * Name of the user-specified clocksource.
  */
 static struct clocksource *curr_clocksource;
+static struct clocksource *suspend_clocksource;
 static LIST_HEAD(clocksource_list);
 static DEFINE_MUTEX(clocksource_mutex);
 static char override_name[CS_NAME_LEN];
 static int finished_booting;
+static u64 suspend_start;
 
 #ifdef CONFIG_CLOCKSOURCE_WATCHDOG
 static void clocksource_watchdog_work(struct work_struct *work);
@@ -447,6 +451,140 @@ static inline void clocksource_watchdog_unlock(unsigned 
long *flags) { }
 
 #endif /* CONFIG_CLOCKSOURCE_WATCHDOG */
 
+static bool clocksource_is_suspend(struct clocksource *cs)
+{
+   return cs == suspend_clocksource;
+}
+
+static void __clocksource_suspend_select(struct clocksource *cs)
+{
+   /*
+* Skip the clocksource which will be stopped in suspend state.
+*/
+   if (!(cs->flags & CLOCK_SOURCE_SUSPEND_NONSTOP))
+   return;
+
+   /*
+* The nonstop clocksource can be selected as the suspend clocksource to
+* calculate the suspend time, so it should not supply suspend/resume
+* interfaces to suspend the nonstop clocksource when system suspends.
+*/
+   if (cs->suspend || cs->resume) {
+   pr_warn("Nonstop clocksource %s should not supply 
suspend/resume interfaces\n",
+   cs->name);
+   }
+
+   /* Pick the best rating. */
+   if (!suspend_clocksource || cs->rating > suspend_clocksource->rating)
+   suspend_clocksource = cs;
+}
+
+/**
+ * clocksource_suspend_select - Select the best clocksource for suspend timing
+ * @fallback:  if select a fallback clocksource
+ */
+static void clocksource_suspend_select(bool fallback)
+{
+   struct clocksource *cs, *old_suspend;
+
+   old_suspend = suspend_clocksource;
+   if (fallback)
+   suspend_clocksource = NULL;
+
+   list_for_each_entry(cs, &clocksource_list, list) {
+   /* Skip current if we were requested for a fallback. */
+   if (fallback && cs == old_suspend)
+   continue;
+
+   __clocksource_suspend_select(cs);
+   }
+}
+
+/**
+ * clocksource_start_suspend_timing - Start measuring the suspend timing
+ * @cs:current clocksource from timekeeping
+ * @start_cycles:  current cycles from timekeeping
+ *
+ * This function will save the start cycle 

[PATCH 3/5] timekeeping/ntp: Constify some function arguments

2018-07-19 Thread John Stultz
From: Ondrej Mosnacek 

Add 'const' to some function arguments and variables to make it easier
to read the code.

Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: Miroslav Lichvar 
Cc: Richard Cochran 
Cc: Prarit Bhargava 
Cc: Stephen Boyd 
Signed-off-by: Ondrej Mosnacek 
[jstultz: Also fixup pre-existing checkpatch warnings for
 prototype arguments with no variable name]
Signed-off-by: John Stultz 
---
 include/linux/timekeeping.h|  2 +-
 kernel/time/ntp.c  |  6 +++---
 kernel/time/ntp_internal.h |  4 ++--
 kernel/time/timekeeping.c  | 29 +++--
 kernel/time/timekeeping_debug.c|  2 +-
 kernel/time/timekeeping_internal.h |  2 +-
 6 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index 86bc202..edace6b 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -177,7 +177,7 @@ static inline time64_t ktime_get_clocktai_seconds(void)
 extern bool timekeeping_rtc_skipsuspend(void);
 extern bool timekeeping_rtc_skipresume(void);
 
-extern void timekeeping_inject_sleeptime64(struct timespec64 *delta);
+extern void timekeeping_inject_sleeptime64(const struct timespec64 *delta);
 
 /*
  * struct system_time_snapshot - simultaneous raw/real time capture with
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index a627cae..c5e0cba 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -642,7 +642,7 @@ void ntp_notify_cmos_timer(void)
 /*
  * Propagate a new txc->status value into the NTP state:
  */
-static inline void process_adj_status(struct timex *txc)
+static inline void process_adj_status(const struct timex *txc)
 {
if ((time_status & STA_PLL) && !(txc->status & STA_PLL)) {
time_state = TIME_OK;
@@ -665,7 +665,7 @@ static inline void process_adj_status(struct timex *txc)
 }
 
 
-static inline void process_adjtimex_modes(struct timex *txc, s32 *time_tai)
+static inline void process_adjtimex_modes(const struct timex *txc, s32 
*time_tai)
 {
if (txc->modes & ADJ_STATUS)
process_adj_status(txc);
@@ -716,7 +716,7 @@ static inline void process_adjtimex_modes(struct timex 
*txc, s32 *time_tai)
  * adjtimex mainly allows reading (and writing, if superuser) of
  * kernel time-keeping variables. used by xntpd.
  */
-int __do_adjtimex(struct timex *txc, struct timespec64 *ts, s32 *time_tai)
+int __do_adjtimex(struct timex *txc, const struct timespec64 *ts, s32 
*time_tai)
 {
int result;
 
diff --git a/kernel/time/ntp_internal.h b/kernel/time/ntp_internal.h
index 909bd1f..c24b0e1 100644
--- a/kernel/time/ntp_internal.h
+++ b/kernel/time/ntp_internal.h
@@ -8,6 +8,6 @@ extern void ntp_clear(void);
 extern u64 ntp_tick_length(void);
 extern ktime_t ntp_get_next_leap(void);
 extern int second_overflow(time64_t secs);
-extern int __do_adjtimex(struct timex *, struct timespec64 *, s32 *);
-extern void __hardpps(const struct timespec64 *, const struct timespec64 *);
+extern int __do_adjtimex(struct timex *txc, const struct timespec64 *ts, s32 
*time_tai);
+extern void __hardpps(const struct timespec64 *phase_ts, const struct 
timespec64 *raw_ts);
 #endif /* _LINUX_NTP_INTERNAL_H */
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index ad779c2..7033ac1 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -105,7 +105,7 @@ static inline void tk_normalize_xtime(struct timekeeper *tk)
}
 }
 
-static inline struct timespec64 tk_xtime(struct timekeeper *tk)
+static inline struct timespec64 tk_xtime(const struct timekeeper *tk)
 {
struct timespec64 ts;
 
@@ -162,7 +162,7 @@ static inline void tk_update_sleep_time(struct timekeeper 
*tk, ktime_t delta)
  * a read of the fast-timekeeper tkrs (which is protected by its own locking
  * and update logic).
  */
-static inline u64 tk_clock_read(struct tk_read_base *tkr)
+static inline u64 tk_clock_read(const struct tk_read_base *tkr)
 {
struct clocksource *clock = READ_ONCE(tkr->clock);
 
@@ -211,7 +211,7 @@ static void timekeeping_check_update(struct timekeeper *tk, 
u64 offset)
}
 }
 
-static inline u64 timekeeping_get_delta(struct tk_read_base *tkr)
+static inline u64 timekeeping_get_delta(const struct tk_read_base *tkr)
 {
struct timekeeper *tk = &tk_core.timekeeper;
u64 now, last, mask, max, delta;
@@ -255,7 +255,7 @@ static inline u64 timekeeping_get_delta(struct tk_read_base 
*tkr)
 static inline void timekeeping_check_update(struct timekeeper *tk, u64 offset)
 {
 }
-static inline u64 timekeeping_get_delta(struct tk_read_base *tkr)
+static inline u64 timekeeping_get_delta(const struct tk_read_base *tkr)
 {
u64 cycle_now, delta;
 
@@ -352,7 +352,7 @@ u32 (*arch_gettimeoffset)(void) = 
default_arch_gettimeoffset;
 static inline u32 arch_gettimeoffset(void) { return 0; }
 #endif
 
-static inline u64 timekeeping_delta_to_ns(struct tk_read_base *tkr, u64 delta)
+static inline u64 timekeepi

[PATCH 2/5] ntp: Use kstrtos64 for s64 variable

2018-07-19 Thread John Stultz
From: Ondrej Mosnacek 

...instead of kstrtol with a dirty cast.

Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: Miroslav Lichvar 
Cc: Richard Cochran 
Cc: Prarit Bhargava 
Cc: Stephen Boyd 
Signed-off-by: Ondrej Mosnacek 
Signed-off-by: John Stultz 
---
 kernel/time/ntp.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 3eddac2..a627cae 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -1020,12 +1020,11 @@ void __hardpps(const struct timespec64 *phase_ts, const 
struct timespec64 *raw_t
 
 static int __init ntp_tick_adj_setup(char *str)
 {
-   int rc = kstrtol(str, 0, (long *)&ntp_tick_adj);
-
+   int rc = kstrtos64(str, 0, &ntp_tick_adj);
if (rc)
return rc;
-   ntp_tick_adj <<= NTP_SCALE_SHIFT;
 
+   ntp_tick_adj <<= NTP_SCALE_SHIFT;
return 1;
 }
 
-- 
2.7.4



[GIT PULL][PATCH 0/5] A few more timekeeping items for 4.19

2018-07-19 Thread John Stultz
The following changes since commit c6bb11147eb09bd39f316c6062455b88c905ab6e:

  Merge branch 'fortglx/4.19/time' of 
https://git.linaro.org/people/john.stultz/linux into timers/core (2018-07-12 
22:19:58 +0200)

are available in the git repository at:

  https://git.linaro.org/people/john.stultz/linux.git 
tags/fortglx/4.19/time-part2

for you to fetch changes up to 39232ed5a1793f67b11430c43ed8a9ed6e96c6eb:

  time: Introduce one suspend clocksource to compensate the suspend time 
(2018-07-19 17:08:52 -0700)


Just a second set of timekeeping things for 4.19

* NTP argument clenaups and constification from Ondrej Mosnacek
* Fix to avoid RTC injecting sleeptime when suspend fails from
  Mukesh Ojha
* Broading suspsend-timing to include non-stop clocksources that
  aren't currently used for timekeeping from Baolin Wang


Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: Miroslav Lichvar 
Cc: Richard Cochran 
Cc: Prarit Bhargava 
Cc: Stephen Boyd 
Cc: Ondrej Mosnacek 
Cc: Mukesh Ojha 
Cc: Baolin Wang 
CC: Daniel Lezcano 

Baolin Wang (1):
  time: Introduce one suspend clocksource to compensate the suspend time

Mukesh Ojha (1):
  time: Fix extra sleeptime injection when suspend fails

Ondrej Mosnacek (3):
  ntp: Remove redundant arguments
  ntp: Use kstrtos64 for s64 variable
  timekeeping/ntp: Constify some function arguments

 include/linux/clocksource.h|   3 ++
 include/linux/timekeeping.h|   2 +-
 kernel/time/clocksource.c  | 149 

 kernel/time/ntp.c  |  17 +--
 kernel/time/ntp_internal.h |   4 +--
 kernel/time/timekeeping.c  |  83 
+--
 kernel/time/timekeeping_debug.c|   2 +-
 kernel/time/timekeeping_internal.h |   2 +-
 8 files changed, 218 insertions(+), 44 deletions(-)

-- 
2.7.4



[PATCH 1/5] ntp: Remove redundant arguments

2018-07-19 Thread John Stultz
From: Ondrej Mosnacek 

The 'ts' argument of process_adj_status() and process_adjtimex_modes()
is unused and can be safely removed.

Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: Miroslav Lichvar 
Cc: Richard Cochran 
Cc: Prarit Bhargava 
Cc: Stephen Boyd 
Signed-off-by: Ondrej Mosnacek 
Signed-off-by: John Stultz 
---
 kernel/time/ntp.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 10a7905..3eddac2 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -642,7 +642,7 @@ void ntp_notify_cmos_timer(void)
 /*
  * Propagate a new txc->status value into the NTP state:
  */
-static inline void process_adj_status(struct timex *txc, struct timespec64 *ts)
+static inline void process_adj_status(struct timex *txc)
 {
if ((time_status & STA_PLL) && !(txc->status & STA_PLL)) {
time_state = TIME_OK;
@@ -665,12 +665,10 @@ static inline void process_adj_status(struct timex *txc, 
struct timespec64 *ts)
 }
 
 
-static inline void process_adjtimex_modes(struct timex *txc,
-   struct timespec64 *ts,
-   s32 *time_tai)
+static inline void process_adjtimex_modes(struct timex *txc, s32 *time_tai)
 {
if (txc->modes & ADJ_STATUS)
-   process_adj_status(txc, ts);
+   process_adj_status(txc);
 
if (txc->modes & ADJ_NANO)
time_status |= STA_NANO;
@@ -735,7 +733,7 @@ int __do_adjtimex(struct timex *txc, struct timespec64 *ts, 
s32 *time_tai)
 
/* If there are input parameters, then process them: */
if (txc->modes)
-   process_adjtimex_modes(txc, ts, time_tai);
+   process_adjtimex_modes(txc, time_tai);
 
txc->offset = shift_right(time_offset * NTP_INTERVAL_FREQ,
  NTP_SCALE_SHIFT);
-- 
2.7.4



[PATCH] uio: fix wrong return value from uio_mmap()

2018-07-19 Thread Hailong Liu
uio_mmap has multiple fail paths to set return value to nonzero then
goto out. However, it always returns *0* from the *out* at end, and
this will mislead callers who check the return value of this function.

Fixes: 57c5f4df0a5a0ee ("uio: fix crash after the device is unregistered")
CC: Xiubo Li 
Signed-off-by: Hailong Liu 
Signed-off-by: Jiang Biao 
---
 drivers/uio/uio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 5d421d7..0ddfda2 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -814,7 +814,7 @@ static int uio_mmap(struct file *filep, struct 
vm_area_struct *vma)
 
 out:
mutex_unlock(&idev->info_lock);
-   return 0;
+   return ret;
 }
 
 static const struct file_operations uio_fops = {
-- 
1.8.3.1



RE: [PATCH 2/2] spi: add SPI controller driver for UniPhier SoC

2018-07-19 Thread Keiji Hayashibara
Hi Mark,

> -Original Message-
> From: Mark Brown [mailto:broo...@kernel.org]
> Sent: Friday, July 20, 2018 1:52 AM
> Subject: Re: [PATCH 2/2] spi: add SPI controller driver for UniPhier SoC
> 
> On Thu, Jul 19, 2018 at 03:51:57PM +0900, Keiji Hayashibara wrote:
> 
> This all looks good, just a small number of fairly minor things - mostly 
> style points.
> 
> > @@ -0,0 +1,532 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * spi-uniphier.c - Socionext UniPhier SPI controller driver
> > + *
> > + * Copyright 2012  Panasonic Corporation
> > + * Copyright 2016-2018 Socionext Inc.
> > + */
> 
> Please make the entire comment a C++ one, it makes things look a bit more 
> joined up/intentional.

OK. I will modify to C++ style.


> > +#define BYTES_PER_WORD(x)  \
> > +({ \
> > +   int __x;\
> > +   __x = (x <= 8)  ? 1 :   \
> > + (x <= 16) ? 2 : 4;\
> > +   __x;\
> > +})
> 
> Could this be replaced with an inline function?  The usage seems fine but 
> it's a bit big for a macro.  The end
> result should be similar.

OK. I will replace with an inline function.

> 
> > +static irqreturn_t uniphier_spi_handler(int irq, void *dev_id) {
> > +   struct uniphier_spi_priv *priv = dev_id;
> > +   u32 val, stat;
> > +
> > +   stat = readl(priv->base + SSI_IS);
> > +   val = SSI_IC_TCIC | SSI_IC_RCIC | SSI_IC_RORIC;
> > +   writel(val, priv->base + SSI_IC);
> > +
> > +   /* rx fifo overrun */
> > +   if (stat & SSI_IS_RORID) {
> > +   priv->error = -EIO;
> > +   goto done;
> > +   }
> > +
> > +   /* rx complete */
> > +   if ((stat & SSI_IS_RCID) && (stat & SSI_IS_RXRS)) {
> 
> > +   }
> > +
> > +   return IRQ_HANDLED;
> > +
> > +done:
> > +   complete(&priv->xfer_done);
> > +   return IRQ_HANDLED;
> 
> This will unconditionally report IRQ_HANDLED even if none of the flags were 
> set by the hardware which will cause
> problems if something goes wrong - the interrupt will continually be serviced 
> and the interrupt framework won't
> be able to mitigate or provide diagnostics.  It's better to return IRQ_NONE 
> if nothing is detected from the hardware.

I agree. I will modify it.

> > +static const struct of_device_id uniphier_spi_match[] = {
> > +   { .compatible = "socionext,uniphier-scssi", },
> > +   { /* sentinel */ },
> > +};
> > +MODULE_DEVICE_TABLE(of, uniphier_spi_match);
> 
> The binding document also listed socionext,uniphier-mcssi as a compatible but 
> this driver doesn't match that.

This driver doesn't support uniphier-mcssi, and support uniphier-scssi only.
I described in the commit comment,
but I will also describe it in the binding document.

Thank you.

-
Best Regards,
Keiji Hayashibara





Re: [PATCH v3 1/8] swap: Add comments to lock_cluster_or_swap_info()

2018-07-19 Thread Huang, Ying
Christoph Hellwig  writes:

> On Thu, Jul 19, 2018 at 04:48:35PM +0800, Huang Ying wrote:
>> +/*
>> + * Determine the locking method in use for this device.  Return
>> + * swap_cluster_info if SSD-style cluster-based locking is in place.
>> + */
>>  static inline struct swap_cluster_info *lock_cluster_or_swap_info(
>>  struct swap_info_struct *si,
>>  unsigned long offset)
>>  {
>>  struct swap_cluster_info *ci;
>>  
>> +/* Try to use fine-grained SSD-style locking if available: */
>
> Once you touch this are can you also please use standard two-tab
> alignment for the spill-over function arguments:
>
> static inline struct swap_cluster_info *lock_cluster_or_swap_info(
>   struct swap_info_struct *si, unsigned long offset)

Sure.  Will change this in next version.

Best Regards,
Huang, Ying


Re: [V9fs-developer] KASAN: use-after-free Read in generic_perform_write

2018-07-19 Thread Dominique Martinet
Andrew Morton wrote on Thu, Jul 19, 2018:
> On Thu, 19 Jul 2018 11:01:01 -0700 syzbot 
>  wrote:
> > Hello,
> > 
> > syzbot found the following crash on:
> > 
> > HEAD commit:1c34981993da Add linux-next specific files for 20180719
> > git tree:   linux-next
> > console output: https://syzkaller.appspot.com/x/log.txt?x=16e6ac4440
> > kernel config:  https://syzkaller.appspot.com/x/.config?x=7002497517b09aec
> > dashboard link: https://syzkaller.appspot.com/bug?extid=b173e77096a8ba815511
> > compiler:   gcc (GCC) 8.0.1 20180413 (experimental)
> > 
> > Unfortunately, I don't have any reproducer for this crash yet.
> 
> Thanks.  I cc'ed v9fs-developer, optimistically.  That list manager is
> weird :(

I agree that list is weird, does anyone know the reason v9fs-developer
is not a vger.k.o list? Or a reason not to change? It's still not too
late...

> I'm suspecting v9fs.  Does that fs attempt to write to the fs from a
> kmalloced buffer?

Difficult to say without any idea of what syzkaller tried doing, but it
looks like it hook'd up a fd opened to a local ext4 file into a trans_fd
mount; so sending a packet to the "server" would trigger a local write
instead.
The reason it's freed too early probably is that the reply came from a
read before the write happened; this is going to be tricky to fix as
that write is 100% asynchronous without any feedback right now (the
design assumes that the write has to have finished by the time reply
came), but if we want to protect ourselves from rogue servers we'll have
to think about something.

I'll write it down to not forget, thanks for the cc.

-- 
Dominique Martinet


Re: [RESEND][PATCH] powerpc/powernv : Save/Restore SPRG3 on entry/exit from stop.

2018-07-19 Thread Michael Neuling
On Wed, 2018-07-18 at 13:42 +0530, Gautham R Shenoy wrote:
> Hello Mikey,
> 
> On Wed, Jul 18, 2018 at 09:24:19AM +1000, Michael Neuling wrote:
> > 
> > >   DEFINE(PPC_DBELL_SERVER, PPC_DBELL_SERVER);
> > > diff --git a/arch/powerpc/kernel/idle_book3s.S
> > > b/arch/powerpc/kernel/idle_book3s.S
> > > index d85d551..5069d42 100644
> > > --- a/arch/powerpc/kernel/idle_book3s.S
> > > +++ b/arch/powerpc/kernel/idle_book3s.S
> > > @@ -120,6 +120,9 @@ power9_save_additional_sprs:
> > >   mfspr   r4, SPRN_MMCR2
> > >   std r3, STOP_MMCR1(r13)
> > >   std r4, STOP_MMCR2(r13)
> > > +
> > > + mfspr   r3, SPRN_SPRG3
> > > + std r3, STOP_SPRG3(r13)
> > 
> > We don't need to save it.  Just restore it from paca->sprg_vdso which should
> > never change.
> 
> Ok. I will respin a patch to restore SPRG3 from paca->sprg_vdso.
> 
> > 
> > How can we do better at catching these missing SPRGs?
> 
> We can go through the list of SPRs from the POWER9 User Manual and
> document explicitly why we don't have to save/restore certain SPRs
> during the execution of the stop instruction. Does this sound ok ?
> 
> (Ref: Table 4-8, Section 4.7.3.4 from the POWER9 User Manual
> accessible from
> https://openpowerfoundation.org/?resource_lib=power9-processor-users-manual)

I was thinking of a boot time test case built into linux. linux has some boot
time test cases which you can enable via CONFIG options.

Firstly you could see if an SPR exists using the same trick xmon does in
dump_one_spr(). Then once you have a list of usable SPRs, you could write all
the known ones (I assume you'd have to leave out some, like the PSSCR), then set
the appropriate stop level, make sure you got into that stop level, and then see
if that register was changed. Then you'd have an automated list of registers you
need to make sure you save/restore at each stop level.

Could something like that work?

Mikey


Re: [PATCH v3 4/8] swap: Unify normal/huge code path in swap_page_trans_huge_swapped()

2018-07-19 Thread Huang, Ying
Christoph Hellwig  writes:

>>  static inline bool cluster_is_huge(struct swap_cluster_info *info)
>>  {
>> -return info->flags & CLUSTER_FLAG_HUGE;
>> +if (IS_ENABLED(CONFIG_THP_SWAP))
>> +return info->flags & CLUSTER_FLAG_HUGE;
>> +else
>> +return false;
>
> Nitpick: no need for an else after a return:
>
>   if (IS_ENABLED(CONFIG_THP_SWAP))
>   return info->flags & CLUSTER_FLAG_HUGE;
>   return false;

Sure.  Will change this in next version.

Best Regards,
Huang, Ying


Re: [PATCH] rapidio: remove redundant pointer md

2018-07-19 Thread Alexandre Bounine

Acked-by: Alexandre Bounine 


On 2018-07-11 04:23 AM, Colin King wrote:

From: Colin Ian King 

Pointer md is being assigned but is never used hence it is redundant
and can be removed.

Cleans up clang warning:
warning: variable 'md' set but not used [-Wunused-but-set-variable]

Signed-off-by: Colin Ian King 
---
  drivers/rapidio/devices/rio_mport_cdev.c | 2 --
  1 file changed, 2 deletions(-)

diff --git a/drivers/rapidio/devices/rio_mport_cdev.c 
b/drivers/rapidio/devices/rio_mport_cdev.c
index a8cb8d2f2abb..cbe467ff1aba 100644
--- a/drivers/rapidio/devices/rio_mport_cdev.c
+++ b/drivers/rapidio/devices/rio_mport_cdev.c
@@ -1006,7 +1006,6 @@ static int rio_mport_transfer_ioctl(struct file *filp, 
void __user *arg)
  static int rio_mport_wait_for_async_dma(struct file *filp, void __user *arg)
  {
struct mport_cdev_priv *priv;
-   struct mport_dev *md;
struct rio_async_tx_wait w_param;
struct mport_dma_req *req;
dma_cookie_t cookie;
@@ -1016,7 +1015,6 @@ static int rio_mport_wait_for_async_dma(struct file 
*filp, void __user *arg)
int ret;
  
  	priv = (struct mport_cdev_priv *)filp->private_data;

-   md = priv->md;
  
  	if (unlikely(copy_from_user(&w_param, arg, sizeof(w_param

return -EFAULT;



Re: [PATCH] arch/h8300: add a defconfig target

2018-07-19 Thread Yoshinori Sato
On Thu, 19 Jul 2018 15:04:29 +0900,
Randy Dunlap wrote:
> 
> From: Randy Dunlap 
> 
> Make the "defconfig" target valid for arch/h8300.  Currently
> "make ARCH=h8300 defconfig" produces:
> 
> *** Can't find default configuration "arch/h8300/defconfig"!
> ../scripts/kconfig/Makefile:87: recipe for target 'defconfig' failed
> 
> By adding a value for KBUILD_DEFCONFIG, "make ARCH=h8300 defconfig"
> successfully produces a kernel .config file:
> 
> *** Default configuration is based on 'edosk2674_defconfig'
> 
> This is useful for Kconfig editing/testing.
> 
> Signed-off-by: Randy Dunlap 
> Cc: Yoshinori Sato 
> Cc: uclinux-h8-de...@lists.sourceforge.jp (moderated for non-subscribers)
> ---
>  arch/h8300/Makefile |2 ++
>  1 file changed, 2 insertions(+)
> 
> --- linux-next-20180717.orig/arch/h8300/Makefile
> +++ linux-next-20180717/arch/h8300/Makefile
> @@ -8,6 +8,8 @@
>  # (C) Copyright 2002-2015 Yoshinori Sato 
>  #
>  
> +KBUILD_DEFCONFIG := edosk2674_defconfig
> +
>  cflags-$(CONFIG_CPU_H8300H)  := -mh
>  aflags-$(CONFIG_CPU_H8300H)  := -mh -Wa,--mach=h8300h
>  ldflags-$(CONFIG_CPU_H8300H) := -mh8300helf_linux
> 
> 

Applied for h8300-next.
Thanks.

-- 
Yosinori Sato


[PATCH net-next 8/9] vhost_net: rename VHOST_RX_BATCH to VHOST_NET_BATCH

2018-07-19 Thread Jason Wang
A more generic name which could be used for TX as well.

Signed-off-by: Jason Wang 
---
 drivers/vhost/net.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 53d305b..2fd2f0e3 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -94,7 +94,7 @@ struct vhost_net_ubuf_ref {
struct vhost_virtqueue *vq;
 };
 
-#define VHOST_RX_BATCH 64
+#define VHOST_NET_BATCH 64
 struct vhost_net_buf {
void **queue;
int tail;
@@ -168,7 +168,7 @@ static int vhost_net_buf_produce(struct vhost_net_virtqueue 
*nvq)
 
rxq->head = 0;
rxq->tail = ptr_ring_consume_batched(nvq->rx_ring, rxq->queue,
- VHOST_RX_BATCH);
+ VHOST_NET_BATCH);
return rxq->tail;
 }
 
@@ -1007,7 +1007,7 @@ static void handle_rx(struct vhost_net *net)
goto out;
}
nvq->done_idx += headcount;
-   if (nvq->done_idx > VHOST_RX_BATCH)
+   if (nvq->done_idx > VHOST_NET_BATCH)
vhost_net_signal_used(nvq);
if (unlikely(vq_log))
vhost_log_write(vq, vq_log, log, vhost_len);
@@ -1075,7 +1075,7 @@ static int vhost_net_open(struct inode *inode, struct 
file *f)
return -ENOMEM;
}
 
-   queue = kmalloc_array(VHOST_RX_BATCH, sizeof(void *),
+   queue = kmalloc_array(VHOST_NET_BATCH, sizeof(void *),
  GFP_KERNEL);
if (!queue) {
kfree(vqs);
-- 
2.7.4



[PATCH v4 1/2] x86/pti: check the return value of pti_user_pagetable_walk_p4d

2018-07-19 Thread Jiang Biao
pti_user_pagetable_walk_p4d() may return NULL, we should check the
return value to avoid NULL pointer dereference. And add warning
for fail allocation where NULL returned.

Signed-off-by: Jiang Biao 
---
 arch/x86/mm/pti.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
index 4d418e7..8679c64 100644
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -176,7 +176,7 @@ static p4d_t *pti_user_pagetable_walk_p4d(unsigned long 
address)

if (pgd_none(*pgd)) {
unsigned long new_p4d_page = __get_free_page(gfp);
-   if (!new_p4d_page)
+   if (WARN_ON_ONCE(!new_p4d_page))
return NULL;

set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(new_p4d_page)));
@@ -195,9 +195,13 @@ static p4d_t *pti_user_pagetable_walk_p4d(unsigned long 
address)
 static pmd_t *pti_user_pagetable_walk_pmd(unsigned long address)
 {
gfp_t gfp = (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO);
-   p4d_t *p4d = pti_user_pagetable_walk_p4d(address);
+   p4d_t *p4d;
pud_t *pud;

+   p4d = pti_user_pagetable_walk_p4d(address);
+   if (!p4d)
+   return NULL;
+
BUILD_BUG_ON(p4d_large(*p4d) != 0);
if (p4d_none(*p4d)) {
unsigned long new_pud_page = __get_free_page(gfp);
@@ -354,6 +358,9 @@ static void __init pti_clone_p4d(unsigned long addr)
pgd_t *kernel_pgd;

user_p4d = pti_user_pagetable_walk_p4d(addr);
+   if (!user_p4d)
+   return;
+
kernel_pgd = pgd_offset_k(addr);
kernel_p4d = p4d_offset(kernel_pgd, addr);
*user_p4d = *kernel_p4d;
--
2.7.4



[PATCH v4 2/2] x86/pti: check the return value of pti_user_pagetable_walk_pmd

2018-07-19 Thread Jiang Biao
Check the return value of pti_user_pagetable_walk_pmd() to avoid
NULL pointer dereference. And add warning for fail allocation.

Signed-off-by: Jiang Biao 
---
 arch/x86/mm/pti.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
index 8679c64..5cd7b82 100644
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -205,7 +205,7 @@ static pmd_t *pti_user_pagetable_walk_pmd(unsigned long 
address)
BUILD_BUG_ON(p4d_large(*p4d) != 0);
if (p4d_none(*p4d)) {
unsigned long new_pud_page = __get_free_page(gfp);
-   if (!new_pud_page)
+   if (WARN_ON_ONCE(!new_pud_page))
return NULL;

set_p4d(p4d, __p4d(_KERNPG_TABLE | __pa(new_pud_page)));
@@ -219,7 +219,7 @@ static pmd_t *pti_user_pagetable_walk_pmd(unsigned long 
address)
}
if (pud_none(*pud)) {
unsigned long new_pmd_page = __get_free_page(gfp);
-   if (!new_pmd_page)
+   if (WARN_ON_ONCE(!new_pmd_page))
return NULL;

set_pud(pud, __pud(_KERNPG_TABLE | __pa(new_pmd_page)));
@@ -241,9 +241,13 @@ static pmd_t *pti_user_pagetable_walk_pmd(unsigned long 
address)
 static __init pte_t *pti_user_pagetable_walk_pte(unsigned long address)
 {
gfp_t gfp = (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO);
-   pmd_t *pmd = pti_user_pagetable_walk_pmd(address);
+   pmd_t *pmd;
pte_t *pte;

+   pmd = pti_user_pagetable_walk_pmd(address);
+   if (!pmd)
+   return NULL;
+
/* We can't do anything sensible if we hit a large mapping. */
if (pmd_large(*pmd)) {
WARN_ON(1);
--
2.7.4



Re: KASAN: use-after-free Read in generic_perform_write

2018-07-19 Thread Andrew Morton
On Thu, 19 Jul 2018 11:01:01 -0700 syzbot 
 wrote:

> Hello,
> 
> syzbot found the following crash on:
> 
> HEAD commit:1c34981993da Add linux-next specific files for 20180719
> git tree:   linux-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=16e6ac4440
> kernel config:  https://syzkaller.appspot.com/x/.config?x=7002497517b09aec
> dashboard link: https://syzkaller.appspot.com/bug?extid=b173e77096a8ba815511
> compiler:   gcc (GCC) 8.0.1 20180413 (experimental)
> 
> Unfortunately, I don't have any reproducer for this crash yet.

Thanks.  I cc'ed v9fs-developer, optimistically.  That list manager is
weird :(

I'm suspecting v9fs.  Does that fs attempt to write to the fs from a
kmalloced buffer?

Full report below...

> IMPORTANT: if you fix the bug, please add the following tag to the commit:
> Reported-by: syzbot+b173e77096a8ba815...@syzkaller.appspotmail.com
> 
> IPVS: length: 141 != 24
> XFS (loop5): Invalid superblock magic number
> ==
> BUG: KASAN: use-after-free in memcpy include/linux/string.h:345 [inline]
> BUG: KASAN: use-after-free in iov_iter_copy_from_user_atomic+0xb8d/0xfa0  
> lib/iov_iter.c:916
> Read of size 21 at addr 880190103660 by task kworker/0:3/4927
> 
> CPU: 0 PID: 4927 Comm: kworker/0:3 Not tainted 4.18.0-rc5-next-20180719+ #11
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS  
> Google 01/01/2011
> Workqueue: events p9_write_work
> Call Trace:
>   __dump_stack lib/dump_stack.c:77 [inline]
>   dump_stack+0x1c9/0x2b4 lib/dump_stack.c:113
>   print_address_description+0x6c/0x20b mm/kasan/report.c:256
>   kasan_report_error mm/kasan/report.c:354 [inline]
>   kasan_report.cold.7+0x242/0x30d mm/kasan/report.c:412
>   check_memory_region_inline mm/kasan/kasan.c:260 [inline]
>   check_memory_region+0x13e/0x1b0 mm/kasan/kasan.c:267
>   memcpy+0x23/0x50 mm/kasan/kasan.c:302
>   memcpy include/linux/string.h:345 [inline]
>   iov_iter_copy_from_user_atomic+0xb8d/0xfa0 lib/iov_iter.c:916
>   generic_perform_write+0x469/0x6c0 mm/filemap.c:3058
>   __generic_file_write_iter+0x26e/0x630 mm/filemap.c:3175
>   ext4_file_write_iter+0x390/0x1450 fs/ext4/file.c:266
>   call_write_iter include/linux/fs.h:1826 [inline]
>   new_sync_write fs/read_write.c:474 [inline]
>   __vfs_write+0x6af/0x9d0 fs/read_write.c:487
>   vfs_write+0x1fc/0x560 fs/read_write.c:549
>   kernel_write+0xab/0x120 fs/read_write.c:526
>   p9_fd_write net/9p/trans_fd.c:427 [inline]
>   p9_write_work+0x6f1/0xd50 net/9p/trans_fd.c:476
>   process_one_work+0xc73/0x1ba0 kernel/workqueue.c:2153
>   worker_thread+0x189/0x13c0 kernel/workqueue.c:2296
>   kthread+0x345/0x410 kernel/kthread.c:246
>   ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:415
> 
> Allocated by task 13072:
>   save_stack+0x43/0xd0 mm/kasan/kasan.c:448
>   set_track mm/kasan/kasan.c:460 [inline]
>   kasan_kmalloc+0xc4/0xe0 mm/kasan/kasan.c:553
>   __do_kmalloc mm/slab.c:3718 [inline]
>   __kmalloc+0x14e/0x760 mm/slab.c:3727
>   kmalloc include/linux/slab.h:518 [inline]
>   p9_fcall_alloc+0x1e/0x90 net/9p/client.c:237
>   p9_tag_alloc net/9p/client.c:266 [inline]
>   p9_client_prepare_req.part.8+0x107/0xa00 net/9p/client.c:640
>   p9_client_prepare_req net/9p/client.c:675 [inline]
>   p9_client_rpc+0x242/0x1330 net/9p/client.c:675
>   p9_client_version net/9p/client.c:890 [inline]
>   p9_client_create+0xca4/0x1537 net/9p/client.c:974
>   v9fs_session_init+0x21a/0x1a80 fs/9p/v9fs.c:400
>   v9fs_mount+0x7c/0x900 fs/9p/vfs_super.c:135
>   legacy_get_tree+0x131/0x460 fs/fs_context.c:674
>   vfs_get_tree+0x1cb/0x5c0 fs/super.c:1743
>   do_new_mount fs/namespace.c:2603 [inline]
>   do_mount+0x6f2/0x1e20 fs/namespace.c:2927
>   ksys_mount+0x12d/0x140 fs/namespace.c:3143
>   __do_sys_mount fs/namespace.c:3157 [inline]
>   __se_sys_mount fs/namespace.c:3154 [inline]
>   __x64_sys_mount+0xbe/0x150 fs/namespace.c:3154
>   do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
>   entry_SYSCALL_64_after_hwframe+0x49/0xbe
> 
> Freed by task 13072:
>   save_stack+0x43/0xd0 mm/kasan/kasan.c:448
>   set_track mm/kasan/kasan.c:460 [inline]
>   __kasan_slab_free+0x11a/0x170 mm/kasan/kasan.c:521
>   kasan_slab_free+0xe/0x10 mm/kasan/kasan.c:528
>   __cache_free mm/slab.c:3498 [inline]
>   kfree+0xd9/0x260 mm/slab.c:3813
>   p9_free_req+0xb5/0x120 net/9p/client.c:338
>   p9_client_rpc+0xa8e/0x1330 net/9p/client.c:739
>   p9_client_version net/9p/client.c:890 [inline]
>   p9_client_create+0xca4/0x1537 net/9p/client.c:974
>   v9fs_session_init+0x21a/0x1a80 fs/9p/v9fs.c:400
>   v9fs_mount+0x7c/0x900 fs/9p/vfs_super.c:135
>   legacy_get_tree+0x131/0x460 fs/fs_context.c:674
&g

Re: [RFC PATCH v2 1/4] dt-bindings: misc: Add bindings for misc. BMC control fields

2018-07-19 Thread Andrew Jeffery
> 
> Andrew, can you start with a list that shows what you expect us to need
> on our systems ?
> 

Okay, our Witherspoon and Romulus platforms containing the ASPEED AST2500 
currently need the following tuneables exposed:

>From the SCU:
- Debug UART enable
- VGA DAC mux
- VGA scratch registers 0-7
- LPC SuperIO decode enable
- VGA MMIO decode enable

>From the LPC controller:
- iLPC2AHB enable
- SuperIO scratch registers 0x20-0x2f

(The LPC controller is just as much of a collection of random bits as the SCU)

Lastly, our Palmetto platform uses an AST2400 which has fewer features compared 
to the AST2500. Its tuneable list is the same as the above with the exception 
of "Debug UART enable".

Tuneables that we may need to expose in the future include:

>From the SCU:
- PCI VID/DID for the BMC PCIe device
- VGA device enable (may need to be disabled if the platform contains a 
discrete graphics processor)

>From the LPC controller:
- UART mux

Alexander, Eugene, can you chime in with your platforms' needs?

Cheers,

Andrew


Re: [PATCH 2/2] jffs2: Provide jffs2_sync files to track gc POLL progress

2018-07-19 Thread Al Viro
On Fri, Jul 20, 2018 at 11:50:12AM +1200, Theuns Verwoerd wrote:

> +ssize_t jffs2_sync_file_read(struct file *f,
> +   char __user *b, size_t len, loff_t *ofs)
> +{
> + struct jffs2_sb_info *c = file_inode(f)->i_private;
> +
> + while (c->tidemark)
> + schedule();
> +
> + return 0;
> +}

Brilliant.  So when that gets called with c->tidemark being true and
need_resched() - false, we shall...

Bonus question: what happens if that is called after that jffs2_sb_info
gets freed?

--
It Doesn't Need To Make Sense - It's For Security Purposes.


Re: [PATCH] proc: fixup PDE allocation bloat

2018-07-19 Thread Shakeel Butt
On Sun, Jun 17, 2018 at 2:57 PM Alexey Dobriyan  wrote:
>
> commit 24074a35c5c975c94cd9691ae962855333aac47f
> ("proc: Make inline name size calculation automatic")
> started to put PDE allocations into kmalloc-256 which is unnecessary as
> ~40 character names are very rare.
>
> Put allocation back into kmalloc-192 cache for 64-bit non-debug builds.
>
> Put BUILD_BUG_ON to know when PDE size is gotten out of control.
>
> Signed-off-by: Alexey Dobriyan 
> ---
>
>  fs/proc/inode.c|6 --
>  fs/proc/internal.h |   17 +++--
>  2 files changed, 11 insertions(+), 12 deletions(-)
>
> --- a/fs/proc/inode.c
> +++ b/fs/proc/inode.c
> @@ -105,8 +105,10 @@ void __init proc_init_kmemcache(void)
> kmem_cache_create("pde_opener", sizeof(struct pde_opener), 0,
>   SLAB_ACCOUNT|SLAB_PANIC, NULL);
> proc_dir_entry_cache = kmem_cache_create_usercopy(
> -   "proc_dir_entry", SIZEOF_PDE_SLOT, 0, SLAB_PANIC,
> -   OFFSETOF_PDE_NAME, SIZEOF_PDE_INLINE_NAME, NULL);
> +   "proc_dir_entry", SIZEOF_PDE, 0, SLAB_PANIC,

Hi Alexey, can you comment if proc_dir_entry_cache should or shouldn't
have SLAB_ACCOUNT flag?

Shakeel


[PATCH 1/2] ata: ahci: Support state with min power but Partial low power state

2018-07-19 Thread Srinivas Pandruvada
Currently when min_power policy is selected, the partial low power state
is not entered and link will try aggressively enter to only slumber state.
Add a new policy which still enable DEVSLP but also try to enter partial
low power state. This policy is presented as "min_power_with_partial".

For information the difference between partial and slumber
Partial – PHY logic is powered up, and in a reduced power state. The link
PM exit latency to active state maximum is 10 ns.
Slumber – PHY logic is powered up, and in a reduced power state. The link
PM exit latency to active state maximum is 10 ms.
Devslp – PHY logic is powered down. The link PM exit latency from this
state to active state maximum is 20 ms, unless otherwise specified by
DETO.

Suggested-by: Hans de Goede 
Signed-off-by: Srinivas Pandruvada 
---
 drivers/ata/libahci.c | 5 -
 drivers/ata/libata-core.c | 1 +
 drivers/ata/libata-scsi.c | 1 +
 include/linux/libata.h| 3 ++-
 4 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
index 4c49c7c2a42c..94dcec2a8a5b 100644
--- a/drivers/ata/libahci.c
+++ b/drivers/ata/libahci.c
@@ -800,6 +800,8 @@ static int ahci_set_lpm(struct ata_link *link, enum 
ata_lpm_policy policy,
cmd |= PORT_CMD_ALPE;
if (policy == ATA_LPM_MIN_POWER)
cmd |= PORT_CMD_ASP;
+   else if (policy == ATA_LPM_MIN_POWER_WITH_PARTIAL)
+   cmd &= ~PORT_CMD_ASP;
 
/* write out new cmd value */
writel(cmd, port_mmio + PORT_CMD);
@@ -810,7 +812,8 @@ static int ahci_set_lpm(struct ata_link *link, enum 
ata_lpm_policy policy,
if ((hpriv->cap2 & HOST_CAP2_SDS) &&
(hpriv->cap2 & HOST_CAP2_SADM) &&
(link->device->flags & ATA_DFLAG_DEVSLP)) {
-   if (policy == ATA_LPM_MIN_POWER)
+   if (policy == ATA_LPM_MIN_POWER ||
+   policy == ATA_LPM_MIN_POWER_WITH_PARTIAL)
ahci_set_aggressive_devslp(ap, true);
else
ahci_set_aggressive_devslp(ap, false);
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 27d15ed7fa3d..773b5f8eed1e 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -3967,6 +3967,7 @@ int sata_link_scr_lpm(struct ata_link *link, enum 
ata_lpm_policy policy,
scontrol |= (0x6 << 8);
break;
case ATA_LPM_MED_POWER_WITH_DIPM:
+   case ATA_LPM_MIN_POWER_WITH_PARTIAL:
case ATA_LPM_MIN_POWER:
if (ata_link_nr_enabled(link) > 0)
/* no restrictions on LPM transitions */
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 6a91d04351d9..4648bd5cee15 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -110,6 +110,7 @@ static const char *ata_lpm_policy_names[] = {
[ATA_LPM_MAX_POWER] = "max_performance",
[ATA_LPM_MED_POWER] = "medium_power",
[ATA_LPM_MED_POWER_WITH_DIPM]   = "med_power_with_dipm",
+   [ATA_LPM_MIN_POWER_WITH_PARTIAL] = "min_power_with_partial",
[ATA_LPM_MIN_POWER] = "min_power",
 };
 
diff --git a/include/linux/libata.h b/include/linux/libata.h
index 8b8946dd63b9..975543f8c1ff 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -522,7 +522,8 @@ enum ata_lpm_policy {
ATA_LPM_MAX_POWER,
ATA_LPM_MED_POWER,
ATA_LPM_MED_POWER_WITH_DIPM, /* Med power + DIPM as win IRST does */
-   ATA_LPM_MIN_POWER,
+   ATA_LPM_MIN_POWER_WITH_PARTIAL, /* Min Power + partial and slumber */
+   ATA_LPM_MIN_POWER, /* Min power + no partial (slumber only) */
 };
 
 enum ata_lpm_hints {
-- 
2.17.1



[PATCH 0/2] ata: ahci: Enable DEVSLP by default on SLP_S0 support

2018-07-19 Thread Srinivas Pandruvada
One of the requirement for modern x86 system to enter lowest power mode
(SLP_S0) is SATA IP block to be off. This is true even during when
platform is suspended to idle and not only in opportunistic (runtime)
suspend.
This series is to enable DEVSLP by default.

-current (non-rfc) series
Implemented suggestions from Hans
- no override of policy set via module param
- Overide lpm policy per host not global policy
- changed the new policy name to "min_power_with_partial"

rfc-v2
- As suggested by Hans, it is possible to have ASP with DEVSLP, so
add a new state.
- Removed usage of mem_sleep_current, instead just rely on low power
idle flag. Don't feel good to EXPORT from core suspend code.
- Depending host policy to decide if we enable DEVSLP by default.

Srinivas Pandruvada (2):
  ata: ahci: Support state with min power but Partial low power state
  ata: ahci: Enable DEVSLP by default on x86 with SLP_S0

 drivers/ata/ahci.c| 33 +
 drivers/ata/libahci.c |  6 +-
 drivers/ata/libata-core.c |  1 +
 drivers/ata/libata-scsi.c |  1 +
 include/linux/libata.h|  3 ++-
 5 files changed, 38 insertions(+), 6 deletions(-)

-- 
2.17.1



[PATCH 2/2] ata: ahci: Enable DEVSLP by default on x86 with SLP_S0

2018-07-19 Thread Srinivas Pandruvada
One of the requirement for modern x86 system to enter lowest power mode
(SLP_S0) is SATA IP block to be off. This is true even during when
platform is suspended to idle and not only in opportunistic (runtime)
suspend.

Several of these system don't have traditional ACPI S3, so it is
important that they enter SLP_S0 state, to avoid draining battery even
during suspend. So it is important that out of the box Linux installation
reach this state.

SATA IP block doesn't get turned off till SATA is in DEVSLP mode. Here
user has to either use scsi-host sysfs or tools like powertop to set
the sata-host link_power_management_policy to min_power.

This change sets by default link power management policy to min_power
with partial (preferred) or slumber support on idle for some platforms.

To avoid regressions, the following conditions are used:
- User didn't override the policy from module parameter
- The kernel config is already set to use med_power_with_dipm or deeper
- System is a SLP_S0 capable using ACPI low power idle flag
This combination will make sure that systems are fairly recent and
since getting shipped with SLP_S0 support, the DEVSLP function
is already validated.

Signed-off-by: Srinivas Pandruvada 
---
 drivers/ata/ahci.c | 33 +
 1 file changed, 29 insertions(+), 4 deletions(-)

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 738fb22978dd..72dc9edbc221 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -1550,6 +1550,34 @@ static int ahci_init_msi(struct pci_dev *pdev, unsigned 
int n_ports,
return pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSIX);
 }
 
+void ahci_update_initial_lpm_policy(struct ata_port *ap,
+   struct ahci_host_priv *hpriv)
+{
+   int policy = mobile_lpm_policy;
+
+   /* Ignore processing for non mobile platforms */
+   if (!(hpriv->flags & AHCI_HFLAG_IS_MOBILE))
+   return;
+
+   /* user modified policy via module param */
+   if (policy != CONFIG_SATA_MOBILE_LPM_POLICY)
+   goto update_policy;
+
+#ifdef CONFIG_ACPI
+   if (policy > ATA_LPM_MED_POWER &&
+   (acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0)) {
+   if (hpriv->cap & HOST_CAP_PART)
+   policy = ATA_LPM_MIN_POWER_WITH_PARTIAL;
+   else if (hpriv->cap & HOST_CAP_SSC)
+   policy = ATA_LPM_MIN_POWER;
+   }
+#endif
+
+update_policy:
+   if (policy >= ATA_LPM_UNKNOWN && policy <= ATA_LPM_MIN_POWER)
+   ap->target_lpm_policy = policy;
+}
+
 static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
unsigned int board_id = ent->driver_data;
@@ -1747,10 +1775,7 @@ static int ahci_init_one(struct pci_dev *pdev, const 
struct pci_device_id *ent)
if (ap->flags & ATA_FLAG_EM)
ap->em_message_type = hpriv->em_msg_type;
 
-   if ((hpriv->flags & AHCI_HFLAG_IS_MOBILE) &&
-   mobile_lpm_policy >= ATA_LPM_UNKNOWN &&
-   mobile_lpm_policy <= ATA_LPM_MIN_POWER)
-   ap->target_lpm_policy = mobile_lpm_policy;
+   ahci_update_initial_lpm_policy(ap, hpriv);
 
/* disabled/not-implemented port */
if (!(hpriv->port_map & (1 << i)))
-- 
2.17.1



Re: [PATCH] perf/x86/intel: Fix unwind errors from PEBS entries (mk-II)

2018-07-19 Thread kbuild test robot
Hi Peter,

I love your patch! Yet something to improve:

[auto build test ERROR on tip/perf/core]
[also build test ERROR on v4.18-rc5 next-20180719]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Peter-Zijlstra/perf-x86-intel-Fix-unwind-errors-from-PEBS-entries-mk-II/20180720-061741
config: powerpc-allnoconfig (attached as .config)
compiler: powerpc-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
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
GCC_VERSION=7.2.0 make.cross ARCH=powerpc 

All errors (new ones prefixed by >>):

   In file included from include/linux/perf_event.h:17:0,
from include/linux/trace_events.h:10,
from include/trace/syscall.h:7,
from arch/powerpc/kernel/ptrace.c:32:
>> include/uapi/linux/perf_event.h:147:39: error: left shift count >= width of 
>> type [-Werror=shift-count-overflow]
 __PERF_SAMPLE_CALLCHAIN_EARLY  = 1UL << 63,
  ^~
   cc1: all warnings being treated as errors

vim +147 include/uapi/linux/perf_event.h

   118  
   119  /*
   120   * Bits that can be set in attr.sample_type to request information
   121   * in the overflow packets.
   122   */
   123  enum perf_event_sample_format {
   124  PERF_SAMPLE_IP  = 1U << 0,
   125  PERF_SAMPLE_TID = 1U << 1,
   126  PERF_SAMPLE_TIME= 1U << 2,
   127  PERF_SAMPLE_ADDR= 1U << 3,
   128  PERF_SAMPLE_READ= 1U << 4,
   129  PERF_SAMPLE_CALLCHAIN   = 1U << 5,
   130  PERF_SAMPLE_ID  = 1U << 6,
   131  PERF_SAMPLE_CPU = 1U << 7,
   132  PERF_SAMPLE_PERIOD  = 1U << 8,
   133  PERF_SAMPLE_STREAM_ID   = 1U << 9,
   134  PERF_SAMPLE_RAW = 1U << 10,
   135  PERF_SAMPLE_BRANCH_STACK= 1U << 11,
   136  PERF_SAMPLE_REGS_USER   = 1U << 12,
   137  PERF_SAMPLE_STACK_USER  = 1U << 13,
   138  PERF_SAMPLE_WEIGHT  = 1U << 14,
   139  PERF_SAMPLE_DATA_SRC= 1U << 15,
   140  PERF_SAMPLE_IDENTIFIER  = 1U << 16,
   141  PERF_SAMPLE_TRANSACTION = 1U << 17,
   142  PERF_SAMPLE_REGS_INTR   = 1U << 18,
   143  PERF_SAMPLE_PHYS_ADDR   = 1U << 19,
   144  
   145  PERF_SAMPLE_MAX = 1U << 20, /* non-ABI */
   146  
 > 147  __PERF_SAMPLE_CALLCHAIN_EARLY   = 1UL << 63,
   148  };
   149  

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


Re: [PATCH v2 02/12] sched/core: uclamp: map TASK's clamp values into CPU's clamp groups

2018-07-19 Thread Suren Baghdasaryan
On Mon, Jul 16, 2018 at 1:28 AM, Patrick Bellasi
 wrote:
> Utilization clamping requires each CPU to know which clamp values are
> assigned to tasks that are currently RUNNABLE on that CPU.
> Multiple tasks can be assigned the same clamp value and tasks with
> different clamp values can be concurrently active on the same CPU.
> Thus, a proper data structure is required to support a fast and
> efficient aggregation of the clamp values required by the currently
> RUNNABLE tasks.
>
> For this purpose we use a per-CPU array of reference counters,
> where each slot is used to account how many tasks require a certain
> clamp value are currently RUNNABLE on each CPU.
> Each clamp value corresponds to a "clamp index" which identifies the
> position within the array of reference couters.
>
>  :
>(user-space changes)  :  (kernel space / scheduler)
>  :
>  SLOW PATH   : FAST PATH
>  :
> task_struct::uclamp::value   : sched/core::enqueue/dequeue
>  : cpufreq_schedutil
>  :
>   ++++ +---+
>   |  TASK  || CLAMP GROUP| |CPU CLAMPS |
>   ++++ +---+
>   |||   clamp_{min,max}  | |  clamp_{min,max}  |
>   | util_{min,max} ||  se_count  | |tasks count|
>   ++++ +---+
>  :
>+-->  :  +--->
> group_id = map(clamp_value)  :  ref_count(group_id)
>  :
>  :
>
> Let's introduce the support to map tasks to "clamp groups".
> Specifically we introduce the required functions to translate a
> "clamp value" into a clamp's "group index" (group_id).
>
> Only a limited number of (different) clamp values are supported since:
> 1. there are usually only few classes of workloads for which it makes
>sense to boost/limit to different frequencies,
>e.g. background vs foreground, interactive vs low-priority
> 2. it allows a simpler and more memory/time efficient tracking of
>the per-CPU clamp values in the fast path.
>
> The number of possible different clamp values is currently defined at
> compile time. Thus, setting a new clamp value for a task can result into
> a -ENOSPC error in case this will exceed the number of maximum different
> clamp values supported.
>
> Signed-off-by: Patrick Bellasi 
> Cc: Ingo Molnar 
> Cc: Peter Zijlstra 
> Cc: Paul Turner 
> Cc: Todd Kjos 
> Cc: Joel Fernandes 
> Cc: Juri Lelli 
> Cc: Dietmar Eggemann 
> Cc: Morten Rasmussen 
> Cc: linux-kernel@vger.kernel.org
> Cc: linux...@vger.kernel.org
> ---
>  include/linux/sched.h |  15 ++-
>  init/Kconfig  |  22 
>  kernel/sched/core.c   | 300 +-
>  3 files changed, 330 insertions(+), 7 deletions(-)
>
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index fd8495723088..0635e8073cd3 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -578,6 +578,19 @@ struct sched_dl_entity {
> struct hrtimer inactive_timer;
>  };
>
> +/**
> + * Utilization's clamp group
> + *
> + * A utilization clamp group maps a "clamp value" (value), i.e.
> + * util_{min,max}, to a "clamp group index" (group_id).
> + */
> +struct uclamp_se {
> +   /* Utilization constraint for tasks in this group */
> +   unsigned int value;
> +   /* Utilization clamp group for this constraint */
> +   unsigned int group_id;
> +};
> +
>  union rcu_special {
> struct {
> u8  blocked;
> @@ -662,7 +675,7 @@ struct task_struct {
>
>  #ifdef CONFIG_UCLAMP_TASK
> /* Utlization clamp values for this task */
> -   int uclamp[UCLAMP_CNT];
> +   struct uclamp_seuclamp[UCLAMP_CNT];
>  #endif
>
>  #ifdef CONFIG_PREEMPT_NOTIFIERS
> diff --git a/init/Kconfig b/init/Kconfig
> index 1d45a6877d6f..0a377ad7c166 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -601,7 +601,29 @@ config UCLAMP_TASK
>
>   If in doubt, say N.
>
> +config UCLAMP_GROUPS_COUNT
> +   int "Number of different utilization clamp values supported"
> +   range 0 127
> +   default 2
> +   depends on UCLAMP_TASK
> +   help
> + This defines the maximum number of different utilization clamp
> + values which can be concurrently enforced for each utilization
> + clamp index (i.e. minimum and maximum utilization).
> +
> + Only a limited number of clamp values are supported because:
> +   1. there are usually only few classes of workloads for which it
> +  

  1   2   3   4   5   6   7   8   >