Re: [PATCH] acpi: watchdog: properly initialize resources

2017-09-15 Thread Mika Westerberg
On Fri, Sep 15, 2017 at 09:55:18PM +0200, Arnd Bergmann wrote:
> We copy a local resource structure into a list, but only
> initialize some of its members, as pointed out by gcc-4.4:
> 
> drivers/acpi/acpi_watchdog.c: In function 'acpi_watchdog_init':
> drivers/acpi/acpi_watchdog.c:105: error: 'res.child' may be used 
> uninitialized in this function
> drivers/acpi/acpi_watchdog.c:105: error: 'res.sibling' may be used 
> uninitialized in this function
> drivers/acpi/acpi_watchdog.c:105: error: 'res.parent' may be used 
> uninitialized in this function
> drivers/acpi/acpi_watchdog.c:105: error: 'res.desc' may be used uninitialized 
> in this function
> drivers/acpi/acpi_watchdog.c:105: error: 'res.name' may be used uninitialized 
> in this function
> 
> Newer compilers can presumably optimize the uninitialized access
> away entirely and don't warn at all, but rely on the kzalloc()
> to zero the structure first. This adds an explicit initialization
> to force consistent behavior.
> 
> Fixes: 058dfc767008 ("ACPI / watchdog: Add support for WDAT hardware 
> watchdog")
> Signed-off-by: Arnd Bergmann 

Acked-by: Mika Westerberg 


[PATCH] Staging: irda: Use !x instead of NULL comparison

2017-09-15 Thread Srishti Sharma
Test for NULL as !x where functions that return NULL on failure
are used. Done using the following semantic patch by coccinelle.

@ is_null @
expression E;
statement S;
@@

E = (\(kmalloc\|devm_kzalloc\|kmalloc_array\|devm_ioremap\|
usb_alloc_urb\|alloc_netdev\|dev_alloc_skb\)(...));

(
if(!E)
   S
|
-if(E==NULL)
+if(!E)
S
)

Signed-off-by: Srishti Sharma 
---
 drivers/staging/irda/net/discovery.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/irda/net/discovery.c 
b/drivers/staging/irda/net/discovery.c
index 364d70a..1e54954 100644
--- a/drivers/staging/irda/net/discovery.c
+++ b/drivers/staging/irda/net/discovery.c
@@ -179,7 +179,7 @@ void irlmp_expire_discoveries(hashbin_t *log, __u32 saddr, 
int force)
/* Create the client specific buffer */
n = HASHBIN_GET_SIZE(log);
buffer = kmalloc(n * sizeof(struct 
irda_device_info), GFP_ATOMIC);
-   if (buffer == NULL) {
+   if (!buffer) {

spin_unlock_irqrestore(&log->hb_spinlock, flags);
return;
}
@@ -291,7 +291,7 @@ struct irda_device_info *irlmp_copy_discoveries(hashbin_t 
*log, int *pn,
/* Create the client specific buffer */
n = HASHBIN_GET_SIZE(log);
buffer = kmalloc(n * sizeof(struct 
irda_device_info), GFP_ATOMIC);
-   if (buffer == NULL) {
+   if (!buffer) {

spin_unlock_irqrestore(&log->hb_spinlock, flags);
return NULL;
}
-- 
2.7.4



[PATCH] perf script: Fix error handling path

2017-09-15 Thread Christophe JAILLET
If the string passed in '--time' is invalid, or if failed to set
libtraceevent function resolver, we must do some cleanup before leaving.
As in the other error handling paths of this function.

Signed-off-by: Christophe JAILLET 
---
 tools/perf/builtin-script.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 378f76cdf923..78ffdb4cbdea 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -3004,7 +3004,8 @@ int cmd_script(int argc, const char **argv)
 machine__resolve_kernel_addr,
 &session->machines.host) < 0) {
pr_err("%s: failed to set libtraceevent function resolver\n", 
__func__);
-   return -1;
+   err = -1;
+   goto out_delete;
}
 
if (generate_script_lang) {
@@ -3064,7 +3065,8 @@ int cmd_script(int argc, const char **argv)
/* needs to be parsed after looking up reference time */
if (perf_time__parse_str(&script.ptime, script.time_str) != 0) {
pr_err("Invalid time string\n");
-   return -EINVAL;
+   err = -EINVAL;
+   goto out_delete;
}
 
err = __cmd_script(&script);
-- 
2.11.0



Re: [GIT PULL] Firmware files removal for 4.14-rc1

2017-09-15 Thread Markus Trippelsdorf
On 2017.09.16 at 06:51 +0200, Markus Trippelsdorf wrote:
> On 2017.09.15 at 11:56 -0700, Greg KH wrote:
> > The following changes since commit 569dbb88e80deb68974ef6fdd6a13edb9d686261:
> >
> >   Linux 4.13 (2017-09-03 13:56:17 -0700)
> >
> > are available in the git repository at:
> >
> >   git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git/ 
> > tags/firmware_removal-4.14-rc1
> >
> > for you to fetch changes up to 5620a0d1aacd554ebebcff373e31107bb1ef7769:
> >
> >   firmware: delete in-kernel firmware (2017-09-14 14:49:41 -0700)
> >
> > 
> > Firmware removal patch for 4.14-rc1
> >
> > Many many years ago (at the kernel summit in Boston), we all came to the
> > agreement that the firmware/ tree should be dropped from the kernel, and
> > everyone use the linux-firmware package instead.  For some minor reason,
> > David Woodhouse didn't send the pull request at that point in time, and
> > everyone forgot about this.
> >
> > The topic came up in the hallway track at the Plumbers conference this
> > week, so here's a single patch that drops the whole firmware tree.  The
> > last firmware update was back in 2013, and all distros have been using
> > linux-firmware instead since at least that year, if not before.  The
> > only commits to that directory since 2013 was some kbuild fixups for
> > various build tool issues.
> >
> > So lets finally drop this, we don't need to lug them around in the
> > kernel source tree anymore, especially as no one wants or uses them.
> 
> Well, it is one thing to drop the redundant binary blobs. But is another
> to break perfectly fine setups that worked for years, e.g.:
> 
> CONFIG_FW_LOADER=y
> CONFIG_FIRMWARE_IN_KERNEL=y
> CONFIG_EXTRA_FIRMWARE="amd-ucode/microcode_amd.bin radeon/R600_rlc.bin"
> CONFIG_EXTRA_FIRMWARE_DIR="/lib/firmware"
> 
> Please restore the support for built-in firmware.

The following patch seems to work for me.

 Makefile |  2 +-
 drivers/base/Kconfig |  5 +
 firmware/.gitignore  |  6 +
 firmware/Makefile| 63 
 4 files changed, 71 insertions(+), 5 deletions(-)
 create mode 100644 firmware/.gitignore
 create mode 100644 firmware/Makefile

diff --git a/Makefile b/Makefile
index 7e2ca4971a39..9f86816c41fd 100644
--- a/Makefile
+++ b/Makefile
@@ -562,7 +562,7 @@ scripts: scripts_basic include/config/auto.conf 
include/config/tristate.conf \
 
 # Objects we will link into vmlinux / subdirs we need to visit
 init-y := init/
-drivers-y  := drivers/ sound/
+drivers-y  := drivers/ sound/ firmware/
 net-y  := net/
 libs-y := lib/
 core-y := usr/
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index f046d21de57d..1a5f6a157a57 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -140,13 +140,10 @@ config EXTRA_FIRMWARE
 config EXTRA_FIRMWARE_DIR
string "Firmware blobs root directory"
depends on EXTRA_FIRMWARE != ""
-   default "firmware"
+   default "/lib/firmware"
help
  This option controls the directory in which the kernel build system
  looks for the firmware files listed in the EXTRA_FIRMWARE option.
- The default is firmware/ in the kernel source tree, but by changing
- this option you can point it elsewhere, such as /lib/firmware/ or
- some other directory containing the firmware files.
 
 config FW_LOADER_USER_HELPER
bool
diff --git a/firmware/.gitignore b/firmware/.gitignore
new file mode 100644
index ..d9c69017bc9a
--- /dev/null
+++ b/firmware/.gitignore
@@ -0,0 +1,6 @@
+*.gen.S
+*.fw
+*.bin
+*.csp
+*.dsp
+ihex2fw
diff --git a/firmware/Makefile b/firmware/Makefile
new file mode 100644
index ..fa0808853883
--- /dev/null
+++ b/firmware/Makefile
@@ -0,0 +1,63 @@
+#
+# kbuild file for firmware/
+#
+
+# Create $(fwabs) from $(CONFIG_EXTRA_FIRMWARE_DIR) -- if it doesn't have a
+# leading /, it's relative to $(srctree).
+fwdir := $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE_DIR))
+fwabs := $(addprefix $(srctree)/,$(filter-out /%,$(fwdir)))$(filter 
/%,$(fwdir))
+
+fw-external-y := $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE))
+
+quiet_cmd_fwbin = MK_FW   $@
+  cmd_fwbin = FWNAME="$(patsubst firmware/%.gen.S,%,$@)";   \
+ FWSTR="$(subst /,_,$(subst .,_,$(subst -,_,$(patsubst  \
+   firmware/%.gen.S,%,$@";  \
+ ASM_WORD=$(if $(CONFIG_64BIT),.quad,.long);\
+ ASM_ALIGN=$(if $(CONFIG_64BIT),3,2);   \
+ PROGBITS=$(if $(CONFIG_ARM),%,@)progbits;  \
+ echo "/* Generated by firmware/Makefile */"   > $@;\
+ echo ".section .rodata"   >>$@;\
+ echo ".p2align $${ASM_ALIGN}" >>$@;\
+

Re: [PATCH v8 10/18] RISC-V: Init and Halt Code

2017-09-15 Thread Dmitriy Cherkasov

On 09/13/2017 11:15 AM, Daniel Lezcano wrote:


All this code must go in the timer side and use the TIMER_OF_DECLARE
macro with the proper wrappers.


Hi, thanks for the feedback.

Agreed. I'll clean this up.



Where is the request_per_cpu_interrupt()?

What is this riscv_timer_interrupt() signature?


This arch defines a separate exception type for local timer interrupts. 
Currently the interrupt controller driver checks the trap cause register, 
determines that it's a timer, and calls the handler directly. To make this go 
through the interrupt subsystem, this driver would need to be reworked.




Where is get_cycles64() ?


This is in asm/timex.h. Should this be split into a separate asm header ala 
arm64?



The timer driver should be self-contained and not spread across
different places, it is very difficult to review it.

[ ... ]



Agreed, thanks again for reviewing it anyway :)


DMA error when sg->offset value is greater than PAGE_SIZE in Intel IOMMU

2017-09-15 Thread Harsh Jain
Hi,

While debugging DMA mapping error in chelsio crypto driver we observed that 
when scatter/gather list received by driver has some entry with page->offset > 
4096 (PAGE_SIZE). It starts giving DMA error.  Without IOMMU it works fine.

Before reaching to chelsio crypto driver(driver/crypto/chelsio) following 
entities change the sg'

1) IN esp_output() "__skb_to_sgvec()" convert skb frags to scatter gather list. 
At that moment sg->offset was 4094.
2) From esp_output control reaches to "crypto_authenc_encrypt()". Here in 
"scatterwalk_ffwd()" sg->offset become 4110.
3) Same sg list received by chelsio crypto driver(chcr). When chcr try to do 
DMA mapping it starts giving DMA errors.

Following error observed. first two prints are added for debugging in chcr. 
Kernel version used to reproduce is 4.9.28 on x86_64.

Sep 15 12:40:52 heptagon kernel: process_cipher req src 8803cb41f0a8
Sep 15 12:40:52 heptagon kernel: = issuehit offset:4110 === 
dma_addr f24b000e ==> DMA mapped address returned by dma_map_sg()

Sep 15 12:40:52 heptagon kernel: DMAR: DRHD: handling fault status reg 2
Sep 15 12:40:52 heptagon kernel: DMAR: [DMA Write] Request device [02:00.4] 
fault addr f24b [fault reason 05] PTE Write access is not set

 By applying following hack in kernel. Things start working.

diff --git a/crypto/scatterwalk.c b/crypto/scatterwalk.c
index c16c94f8..1d75a3a 100644
--- a/crypto/scatterwalk.c
+++ b/crypto/scatterwalk.c
@@ -78,6 +78,8 @@ struct scatterlist *scatterwalk_ffwd(struct scatterlist dst[2]
 struct scatterlist *src,
 unsigned int len)
 {
+   unsigned int mod_page_offset;
+
for (;;) {
if (!len)
return src;
@@ -90,7 +92,9 @@ struct scatterlist *scatterwalk_ffwd(struct scatterlist dst[2]
}

sg_init_table(dst, 2);
-   sg_set_page(dst, sg_page(src), src->length - len, src->offset + len);
+mod_page_offset = (src->offset + len) / PAGE_SIZE;
+   sg_set_page(dst, sg_page(src) + mod_page_offset, src->length - len,
+   (src->offset + len) - (mod_page_offset * PAGE_SIZE));
scatterwalk_crypto_chain(dst, sg_next(src), 0, 2);


1) We are not expecting issue in "scatterwalk_ffwd" because it is not the only 
place where kernel 
updates src->offset without checking page boundary. similar logic used in 
"__skb_to_sgvec".
 
2) It cannot be driver's responsibilty to update received sg entries to adjust 
offset and page 
because we are not the only one who directly uses received sg list.

3) Since Without IOMMU every thing works fine. We are expecting IOMMU bugs.

Regards

Harsh Jain



[PATCH] perf kmem: Perform some cleanup if '--time' is given an invalid value

2017-09-15 Thread Christophe JAILLET
If the string passed in '--time' is invalid, we must do some cleanup
before leaving. As in the other error handling paths of this function.

Fixes: 2a865bd8 ("perf kmem: Add option to specify time window of interest")
Signed-off-by: Christophe JAILLET 
---
 tools/perf/builtin-kmem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 24ee68ecdd42..d8f25ef8157b 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -1983,7 +1983,8 @@ int cmd_kmem(int argc, const char **argv)
 
if (perf_time__parse_str(&ptime, time_str) != 0) {
pr_err("Invalid time string\n");
-   return -EINVAL;
+   ret = -EINVAL;
+   goto out_delete;
}
 
if (!strcmp(argv[0], "stat")) {
-- 
2.11.0



[PATCH] ASoC: davinci-mcasp: Fix an error handling path in 'davinci_mcasp_probe()'

2017-09-15 Thread Christophe JAILLET
All error handling paths in this function 'goto err' except this one.

If one of the 2 previous memory allocations fails, we should go through
the existing error handling path. Otherwise there is an unbalanced
pm_runtime_enable()/pm_runtime_disable().

Fixes: dd55ff8346a9 ("ASoC: davinci-mcasp: Add set_tdm_slots() support")
Signed-off-by: Christophe JAILLET 
---
 sound/soc/davinci/davinci-mcasp.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/sound/soc/davinci/davinci-mcasp.c 
b/sound/soc/davinci/davinci-mcasp.c
index f395bbc7c354..23b0da7df1f2 100644
--- a/sound/soc/davinci/davinci-mcasp.c
+++ b/sound/soc/davinci/davinci-mcasp.c
@@ -1982,8 +1982,10 @@ static int davinci_mcasp_probe(struct platform_device 
*pdev)
 GFP_KERNEL);
 
if (!mcasp->chconstr[SNDRV_PCM_STREAM_PLAYBACK].list ||
-   !mcasp->chconstr[SNDRV_PCM_STREAM_CAPTURE].list)
-   return -ENOMEM;
+   !mcasp->chconstr[SNDRV_PCM_STREAM_CAPTURE].list) {
+   ret = -ENOMEM;
+   goto err;
+   }
 
ret = davinci_mcasp_set_ch_constraints(mcasp);
if (ret)
-- 
2.11.0



Re: [PATCH] clk: tegra: Use readl_relaxed_poll_timeout_atomic in tegra210_clock_init

2017-09-15 Thread Nicolin Chen
On Fri, Sep 15, 2017 at 12:31:45PM +0300, Peter De Schrijver wrote:
> Apart from the typo in the commit message (preemption rather than preemtion):

Sent a v2 to correct it. And included your Acked-by.

Thanks

> 
> Acked-By: Peter De Schrijver 
> 
> On Thu, Sep 14, 2017 at 06:36:14PM -0700, Nicolin Chen wrote:
> > Below is the call trace of tegra210_init_pllu() function:
> >   start_kernel()
> >   -> time_init()
> >   --> of_clk_init()
> >   ---> tegra210_clock_init()
> >   > tegra210_pll_init()
> >   -> tegra210_init_pllu()
> > 
> > Because the preemtion is disabled in the start_kernel before calling
> > time_init, tegra210_init_pllu is actually in an atomic context while
> > it includes a readl_relaxed_poll_timeout that might sleep.
> > 
> > So this patch just changes this readl_relaxed_poll_timeout() to its
> > atomic version.
> > 
> > Signed-off-by: Nicolin Chen 
> > ---
> >  drivers/clk/tegra/clk-tegra210.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/clk/tegra/clk-tegra210.c 
> > b/drivers/clk/tegra/clk-tegra210.c
> > index 0b9789a..ea695c4 100644
> > --- a/drivers/clk/tegra/clk-tegra210.c
> > +++ b/drivers/clk/tegra/clk-tegra210.c
> > @@ -2587,8 +2587,8 @@ static int tegra210_enable_pllu(void)
> > reg |= PLL_ENABLE;
> > writel(reg, clk_base + PLLU_BASE);
> >  
> > -   readl_relaxed_poll_timeout(clk_base + PLLU_BASE, reg,
> > -  reg & PLL_BASE_LOCK, 2, 1000);
> > +   readl_relaxed_poll_timeout_atomic(clk_base + PLLU_BASE, reg,
> > + reg & PLL_BASE_LOCK, 2, 1000);
> > if (!(reg & PLL_BASE_LOCK)) {
> > pr_err("Timed out waiting for PLL_U to lock\n");
> > return -ETIMEDOUT;
> > -- 
> > 2.1.4
> > 


[PATCH 0/2] android: binder: resolve lru, dentry and task deadlock

2017-09-15 Thread Sherry Yang
This patch set removes the unused vma argument in update_page_range
and resolves a potential deadlock between lru lock, task lock and
dentry lock reported by lockdep.

android: binder: Don't get mm from task
android: binder: Remove unused vma argument

drivers/android/binder_alloc.c | 36 ++---
drivers/android/binder_alloc.h |  1 -
2 files changed, 15 insertions(+), 22 deletions(-)



[PATCH 2/2] android: binder: Don't get mm from task

2017-09-15 Thread Sherry Yang
Use binder_alloc struct's mm_struct rather than getting
a reference to the mm struct through get_task_mm to
avoid a potential deadlock between lru lock, task lock and
dentry lock, since a thread can be holding the task lock
and the dentry lock while trying to acquire the lru lock.

Acked-by: Arve Hjønnevåg 
Signed-off-by: Sherry Yang 
---
 drivers/android/binder_alloc.c | 22 +-
 drivers/android/binder_alloc.h |  1 -
 2 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
index b87ecf77f9d1..e283670695db 100644
--- a/drivers/android/binder_alloc.c
+++ b/drivers/android/binder_alloc.c
@@ -215,17 +215,12 @@ static int binder_update_page_range(struct binder_alloc 
*alloc, int allocate,
}
}
 
-   if (need_mm)
-   mm = get_task_mm(alloc->tsk);
+   if (need_mm && mmget_not_zero(alloc->vma_vm_mm))
+   mm = alloc->vma_vm_mm;
 
if (mm) {
down_write(&mm->mmap_sem);
vma = alloc->vma;
-   if (vma && mm != alloc->vma_vm_mm) {
-   pr_err("%d: vma mm and task mm mismatch\n",
-   alloc->pid);
-   vma = NULL;
-   }
}
 
if (!vma && need_mm) {
@@ -718,6 +713,7 @@ int binder_alloc_mmap_handler(struct binder_alloc *alloc,
barrier();
alloc->vma = vma;
alloc->vma_vm_mm = vma->vm_mm;
+   mmgrab(alloc->vma_vm_mm);
 
return 0;
 
@@ -793,6 +789,8 @@ void binder_alloc_deferred_release(struct binder_alloc 
*alloc)
vfree(alloc->buffer);
}
mutex_unlock(&alloc->mutex);
+   if (alloc->vma_vm_mm)
+   mmdrop(alloc->vma_vm_mm);
 
binder_alloc_debug(BINDER_DEBUG_OPEN_CLOSE,
 "%s: %d buffers %d, pages %d\n",
@@ -887,7 +885,6 @@ int binder_alloc_get_allocated_count(struct binder_alloc 
*alloc)
 void binder_alloc_vma_close(struct binder_alloc *alloc)
 {
WRITE_ONCE(alloc->vma, NULL);
-   WRITE_ONCE(alloc->vma_vm_mm, NULL);
 }
 
 /**
@@ -924,9 +921,9 @@ enum lru_status binder_alloc_free_page(struct list_head 
*item,
page_addr = (uintptr_t)alloc->buffer + index * PAGE_SIZE;
vma = alloc->vma;
if (vma) {
-   mm = get_task_mm(alloc->tsk);
-   if (!mm)
-   goto err_get_task_mm_failed;
+   if (!mmget_not_zero(alloc->vma_vm_mm))
+   goto err_mmget;
+   mm = alloc->vma_vm_mm;
if (!down_write_trylock(&mm->mmap_sem))
goto err_down_write_mmap_sem_failed;
}
@@ -961,7 +958,7 @@ enum lru_status binder_alloc_free_page(struct list_head 
*item,
 
 err_down_write_mmap_sem_failed:
mmput_async(mm);
-err_get_task_mm_failed:
+err_mmget:
 err_page_already_freed:
mutex_unlock(&alloc->mutex);
 err_get_alloc_mutex_failed:
@@ -1000,7 +997,6 @@ struct shrinker binder_shrinker = {
  */
 void binder_alloc_init(struct binder_alloc *alloc)
 {
-   alloc->tsk = current->group_leader;
alloc->pid = current->group_leader->pid;
mutex_init(&alloc->mutex);
INIT_LIST_HEAD(&alloc->buffers);
diff --git a/drivers/android/binder_alloc.h b/drivers/android/binder_alloc.h
index a3a3602c689c..2dd33b6df104 100644
--- a/drivers/android/binder_alloc.h
+++ b/drivers/android/binder_alloc.h
@@ -100,7 +100,6 @@ struct binder_lru_page {
  */
 struct binder_alloc {
struct mutex mutex;
-   struct task_struct *tsk;
struct vm_area_struct *vma;
struct mm_struct *vma_vm_mm;
void *buffer;
-- 
2.11.0 (Apple Git-81)



[PATCH 1/2] android: binder: Remove unused vma argument

2017-09-15 Thread Sherry Yang
The vma argument in update_page_range is no longer
used after 74310e06 ("android: binder: Move buffer
out of area shared with user space"), since mmap_handler
no longer calls update_page_range with a vma.

Acked-by: Arve Hjønnevåg 
Signed-off-by: Sherry Yang 
---
 drivers/android/binder_alloc.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
index 064f5e31ec55..b87ecf77f9d1 100644
--- a/drivers/android/binder_alloc.c
+++ b/drivers/android/binder_alloc.c
@@ -186,12 +186,12 @@ struct binder_buffer *binder_alloc_prepare_to_free(struct 
binder_alloc *alloc,
 }
 
 static int binder_update_page_range(struct binder_alloc *alloc, int allocate,
-   void *start, void *end,
-   struct vm_area_struct *vma)
+   void *start, void *end)
 {
void *page_addr;
unsigned long user_page_addr;
struct binder_lru_page *page;
+   struct vm_area_struct *vma = NULL;
struct mm_struct *mm = NULL;
bool need_mm = false;
 
@@ -215,7 +215,7 @@ static int binder_update_page_range(struct binder_alloc 
*alloc, int allocate,
}
}
 
-   if (!vma && need_mm)
+   if (need_mm)
mm = get_task_mm(alloc->tsk);
 
if (mm) {
@@ -442,7 +442,7 @@ struct binder_buffer *binder_alloc_new_buf_locked(struct 
binder_alloc *alloc,
if (end_page_addr > has_page_addr)
end_page_addr = has_page_addr;
ret = binder_update_page_range(alloc, 1,
-   (void *)PAGE_ALIGN((uintptr_t)buffer->data), end_page_addr, NULL);
+   (void *)PAGE_ALIGN((uintptr_t)buffer->data), end_page_addr);
if (ret)
return ERR_PTR(ret);
 
@@ -483,7 +483,7 @@ struct binder_buffer *binder_alloc_new_buf_locked(struct 
binder_alloc *alloc,
 err_alloc_buf_struct_failed:
binder_update_page_range(alloc, 0,
 (void *)PAGE_ALIGN((uintptr_t)buffer->data),
-end_page_addr, NULL);
+end_page_addr);
return ERR_PTR(-ENOMEM);
 }
 
@@ -567,8 +567,7 @@ static void binder_delete_free_buffer(struct binder_alloc 
*alloc,
   alloc->pid, buffer->data,
   prev->data, next->data);
binder_update_page_range(alloc, 0, buffer_start_page(buffer),
-buffer_start_page(buffer) + PAGE_SIZE,
-NULL);
+buffer_start_page(buffer) + PAGE_SIZE);
}
list_del(&buffer->entry);
kfree(buffer);
@@ -605,8 +604,7 @@ static void binder_free_buf_locked(struct binder_alloc 
*alloc,
 
binder_update_page_range(alloc, 0,
(void *)PAGE_ALIGN((uintptr_t)buffer->data),
-   (void *)(((uintptr_t)buffer->data + buffer_size) & PAGE_MASK),
-   NULL);
+   (void *)(((uintptr_t)buffer->data + buffer_size) & PAGE_MASK));
 
rb_erase(&buffer->rb_node, &alloc->allocated_buffers);
buffer->free = 1;
-- 
2.11.0 (Apple Git-81)



Re: [GIT PULL] Firmware files removal for 4.14-rc1

2017-09-15 Thread Markus Trippelsdorf
On 2017.09.15 at 11:56 -0700, Greg KH wrote:
> The following changes since commit 569dbb88e80deb68974ef6fdd6a13edb9d686261:
>
>   Linux 4.13 (2017-09-03 13:56:17 -0700)
>
> are available in the git repository at:
>
>   git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git/ 
> tags/firmware_removal-4.14-rc1
>
> for you to fetch changes up to 5620a0d1aacd554ebebcff373e31107bb1ef7769:
>
>   firmware: delete in-kernel firmware (2017-09-14 14:49:41 -0700)
>
> 
> Firmware removal patch for 4.14-rc1
>
> Many many years ago (at the kernel summit in Boston), we all came to the
> agreement that the firmware/ tree should be dropped from the kernel, and
> everyone use the linux-firmware package instead.  For some minor reason,
> David Woodhouse didn't send the pull request at that point in time, and
> everyone forgot about this.
>
> The topic came up in the hallway track at the Plumbers conference this
> week, so here's a single patch that drops the whole firmware tree.  The
> last firmware update was back in 2013, and all distros have been using
> linux-firmware instead since at least that year, if not before.  The
> only commits to that directory since 2013 was some kbuild fixups for
> various build tool issues.
>
> So lets finally drop this, we don't need to lug them around in the
> kernel source tree anymore, especially as no one wants or uses them.

Well, it is one thing to drop the redundant binary blobs. But is another
to break perfectly fine setups that worked for years, e.g.:

CONFIG_FW_LOADER=y
CONFIG_FIRMWARE_IN_KERNEL=y
CONFIG_EXTRA_FIRMWARE="amd-ucode/microcode_amd.bin radeon/R600_rlc.bin"
CONFIG_EXTRA_FIRMWARE_DIR="/lib/firmware"

Please restore the support for built-in firmware.
Thanks.

-- 
Markus


Re: [PATCH] Revert "xhci: Limit USB2 port wake support for AMD Promontory hosts"

2017-09-15 Thread Kai-Heng Feng
On Mon, Aug 28, 2017 at 9:56 PM, Kai-Heng Feng
 wrote:
> On Mon, Aug 28, 2017 at 6:14 PM, Mathias Nyman
>  wrote:
>> On 28.08.2017 12:29, Greg KH wrote:
>>
>> Adding more people who were involved in the original patch.
>>
>> Users are now seeing the unresponsive USB2 ports with Promontory hosts.
>> Is there any update on a better way to solve the original issue.
>>
>> To me a "dead" USB2 port seems like a much worse issue for a user
>> than a BIOS disabled port waking up on plug/unplug (wake on
>> connect/disconnect),
>> so I'm myself in favor of doing this revert.
>
> At least I can't find "Disable USB2" on my ASUS PRIME B350M-A, so the
> new behavior is quite surprising.
>
>>
>> But there was a strong push from Promontory developers to get the original
>> fix in,
>> and I would like to get some comment from them before I do anything about
>> it.
>
> You looped them to the mail thread which I reported the regression two
> weeks ago, and there is no response since then...

Still no response from AMD and ASMedia guys.

I don't like to use out-of-tree patches for myself, but probably it's
the only way here?

>
>>
>> Thanks
>> -Mathias
>>


Re: [PATCH] firmware: add firmware to new device's devres list for second time cache

2017-09-15 Thread Kai-Heng Feng
On Tue, Aug 22, 2017 at 12:52 AM, Kai-Heng Feng
 wrote:
> Currently, firmware will only be chached if assign_firmware_buf() gets
> called.
>
> When a device loses its power or a USB device gets plugged to another
> port under suspend, request_firmware() can still find cached firmware,
> but firmware name no longer associates with the new device's devres.
> So next time the system suspend, those firmware won't be cached.
>
> Hence, we should add the firmware name to the devres when the firmware
> is found in cache, to make the firmware cacheable next time.
>
> Signed-off-by: Kai-Heng Feng 
> ---
>  drivers/base/firmware_class.c | 4 
>  1 file changed, 4 insertions(+)
>
> diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
> index bfbe1e154128..a99de34e3fdc 100644
> --- a/drivers/base/firmware_class.c
> +++ b/drivers/base/firmware_class.c
> @@ -1177,6 +1177,10 @@ _request_firmware_prepare(struct firmware 
> **firmware_p, const char *name,
>
> ret = fw_lookup_and_allocate_buf(name, &fw_cache, &buf, dbuf, size);
>
> +   /* device might be a new one, add it to devres list */
> +   if (ret == 0 || ret == 1)
> +   fw_add_devm_name(device, name);
> +
> /*
>  * bind with 'buf' now to avoid warning in failure path
>  * of requesting firmware.
> --
> 2.14.1
>

*A gentle ping here*


Re: [PATCH] usb: dwc3: Fix the USB 3.0 hub detection bug after warm boot

2017-09-15 Thread gustavo panizzo

Hello

On Fri, Sep 15, 2017 at 09:01:13AM +, gustavo panizzo wrote:

Hello

On Thu, Sep 07, 2017 at 01:51:31PM +0300, Felipe Balbi wrote:


Hi,

gustavo panizzo  writes:

---
drivers/usb/dwc3/core.c | 33 +
1 file changed, 33 insertions(+)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 326b302fc440..f92dfe213d89 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -1259,6 +1259,38 @@ static int dwc3_probe(struct platform_device
*pdev)
  return ret;
}

+static void dwc3_shutdown(struct platform_device *pdev)
+{
+   struct dwc3 *dwc = platform_get_drvdata(pdev);
+   struct resource *res = platform_get_resource(pdev,
IORESOURCE_MEM, 0);
+
+   pm_runtime_get_sync(&pdev->dev);
+   /*
+* restore res->start back to its original value so that, in case
the
+* probe is deferred, we don't end up getting error in request
the
+* memory region the next time probe is called.
+*/
+   res->start -= DWC3_GLOBALS_REGS_START;
+
+   dwc3_debugfs_exit(dwc);
+   dwc3_core_exit_mode(dwc);
+   dwc3_event_buffers_cleanup(dwc);



What about dwc3_event_buffers_cleanup? should I remove it from
dwc3_shutdown()?
It is already in dwc3_core_exit()


I think so. We should avoid duplicate code.


+   dwc3_free_event_buffers(dwc);
+
+   usb_phy_set_suspend(dwc->usb2_phy, 1);
+   usb_phy_set_suspend(dwc->usb3_phy, 1);
+
+   phy_power_off(dwc->usb2_generic_phy);
+   phy_power_off(dwc->usb3_generic_phy);



We've done these in dwc3_core_exit().


This is the patch after testing on a Odroid XU4, on top of linux-next
964bcc1b4f57028d56dace7d9bc5924f2eb43f36 which translates to 
4.13.0-rc1-next-20170717+
I tested this patch for a week without problems with heavy USB and NIC usage.
Please consider merging it


Author: Brian Kim 
Date:   Wed Jul 12 11:26:55 2017 +0800

  usb: dwc3: Fix the USB 3.0 hub detection bug after warm boot
  The dwc3 could not release resources when the module is built-in
  because this module does not have shutdown method. This causes the USB
  3.0 hub is not able to detect after warm boot.
  Original patch by Brian Kim, updated and submitted upstream by gustavo
  panizzo.
  Also see https://bugs.debian.org/843448
  Signed-off-by: Brian Kim 
  Signed-off-by: gustavo panizzo 

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 326b302fc440..09de37d47ee7 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -1259,6 +1259,32 @@ static int dwc3_probe(struct platform_device *pdev)
return ret;
}

+static void dwc3_shutdown(struct platform_device *pdev)
+{
+   struct dwc3 *dwc = platform_get_drvdata(pdev);
+   struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+
+   pm_runtime_get_sync(&pdev->dev);
+   /*
+* restore res->start back to its original value so that, in case the
+* probe is deferred, we don't end up getting error in request the
+* memory region the next time probe is called.
+*/
+   res->start -= DWC3_GLOBALS_REGS_START;
+
+   dwc3_debugfs_exit(dwc);
+   dwc3_core_exit_mode(dwc);
+   dwc3_event_buffers_cleanup(dwc);
+   dwc3_free_event_buffers(dwc);
+
+   dwc3_core_exit(dwc);
+   dwc3_ulpi_exit(dwc);
+
+   pm_runtime_put_sync(&pdev->dev);
+   pm_runtime_allow(&pdev->dev);
+   pm_runtime_disable(&pdev->dev);
+}
+
static int dwc3_remove(struct platform_device *pdev)
{
struct dwc3 *dwc = platform_get_drvdata(pdev);
@@ -1488,6 +1514,7 @@ MODULE_DEVICE_TABLE(acpi, dwc3_acpi_match);
static struct platform_driver dwc3_driver = {
   .probe  = dwc3_probe,
   .remove = dwc3_remove,
+   .shutdown   = dwc3_shutdown,
   .driver = {
   .name   = "dwc3",
   .of_match_table = of_match_ptr(of_dwc3_match),

Patch applies cleanly on top of c6be5a0e3cebc145127d46a58350e05d2bcf6323 from 
linux-next
Can you _please_ merge it?


why are you upset? You didn't do the changes I requested until now. It's


I'm not upset


too late for v4.14 merge window and you didn't even send this as a
proper patch. I also have no evidence that you've been testing mainline
kernel, the commits you pointed me to are against a v4.9 vendor kernel.


the commit i sent was tested, and is still running, on top linux-next
964bcc1b4f57028d56dace7d9bc5924f2eb43f36, which gives an uname -r
4.13.0-rc1-next-20170717+




Test this against a vanilla tree (v4.13 was tagged days ago) and give me
logs showing the problem without your commit.


the patch does not work on top of 4.13.0 :(

could you draft a patch i can test?

thanks



dmesg on top of 4.13.0

[0.00] Booting Linux on physical CPU 0x100
[0.00] random: get_random_bytes called from start_kernel+0x44/0x460 
with crng_init=0
[0.00] Linux version 4.13.0 (root@odroid) (gcc version 6.3.0 20170516 
(Deb

Re: [PATCH] once: switch to new jump label API

2017-09-15 Thread Eric Biggers
On Tue, Aug 22, 2017 at 02:44:41PM -0400, Hannes Frederic Sowa wrote:
> Eric Biggers  writes:
> 
> > From: Eric Biggers 
> >
> > Switch the DO_ONCE() macro from the deprecated jump label API to the new
> > one.  The new one is more readable, and for DO_ONCE() it also makes the
> > generated code more icache-friendly: now the one-time initialization
> > code is placed out-of-line at the jump target, rather than at the inline
> > fallthrough case.
> >
> > Signed-off-by: Eric Biggers 
> 
> Acked-by: Hannes Frederic Sowa  
> Thanks!

Great!  Who though is the maintainer for this code?  It seems it was originally
taken by David Miller through the networking tree.  David, are you taking
further patches to the "once" functions, or should I be trying to get this into
-mm, or somewhere else?

Eric


[PATCH 2/5] ia64: Add .opd based function descriptor dereference

2017-09-15 Thread Sergey Senozhatsky
We are moving towards separate kernel and module function descriptor
dereference callbacks. This patch enables it for IA64.

For pointers that belong to the kernel
-  Added __start_opd and __end_opd pointers, to track the kernel
   .opd section address range;

-  Added dereference_kernel_function_descriptor(). Now we
   will dereference only function pointers that are within
   [__start_opd, __end_opd];

For pointers that belong to a module
-  Added dereference_module_function_descriptor() to handle module
   function descriptor dereference. Now we will dereference only
   pointers that are within [module->opd.start, module->opd.end].

Signed-off-by: Sergey Senozhatsky 
---
 arch/ia64/include/asm/sections.h | 14 +-
 arch/ia64/kernel/module.c| 13 +
 arch/ia64/kernel/vmlinux.lds.S   |  2 ++
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/arch/ia64/include/asm/sections.h b/arch/ia64/include/asm/sections.h
index 2ab2003698ef..bff3f3535609 100644
--- a/arch/ia64/include/asm/sections.h
+++ b/arch/ia64/include/asm/sections.h
@@ -25,8 +25,11 @@ extern char __start_gate_fsyscall_patchlist[], 
__end_gate_fsyscall_patchlist[];
 extern char __start_gate_brl_fsys_bubble_down_patchlist[], 
__end_gate_brl_fsys_bubble_down_patchlist[];
 extern char __start_unwind[], __end_unwind[];
 extern char __start_ivt_text[], __end_ivt_text[];
+extern char __start_opd[], __end_opd[];
 
 #undef dereference_function_descriptor
+#undef dereference_kernel_function_descriptor
+
 static inline void *dereference_function_descriptor(void *ptr)
 {
struct fdesc *desc = ptr;
@@ -37,6 +40,15 @@ static inline void *dereference_function_descriptor(void 
*ptr)
return ptr;
 }
 
+static inline void *dereference_kernel_function_descriptor(void *ptr)
+{
+   /*
+* Check if the ptr is a function descriptor and thus needs to
+* be dereferenced.
+*/
+   if (ptr < (void *)__start_opd || (void *)__end_opd < ptr)
+   return ptr;
+   return dereference_function_descriptor(ptr);
+}
 
 #endif /* _ASM_IA64_SECTIONS_H */
-
diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
index d1d945c6bd05..d42f1e19d75d 100644
--- a/arch/ia64/kernel/module.c
+++ b/arch/ia64/kernel/module.c
@@ -35,6 +35,7 @@
 
 #include 
 #include 
+#include 
 
 #define ARCH_MODULE_DEBUG 0
 
@@ -917,3 +918,15 @@ module_arch_cleanup (struct module *mod)
if (mod->arch.core_unw_table)
unw_remove_unwind_table(mod->arch.core_unw_table);
 }
+
+unsigned long dereference_module_function_descriptor(struct module *mod,
+unsigned long addr)
+{
+   Elf64_Shdr *opd = mod->arch.opd;
+
+   if (addr < opd->sh_addr ||
+   (opd->sh_addr + opd->sh_size) < addr)
+   return addr;
+
+   return dereference_function_descriptor(addr);
+}
diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
index 798026dde52e..f872ba5ff82a 100644
--- a/arch/ia64/kernel/vmlinux.lds.S
+++ b/arch/ia64/kernel/vmlinux.lds.S
@@ -107,7 +107,9 @@ SECTIONS {
RODATA
 
.opd : AT(ADDR(.opd) - LOAD_OFFSET) {
+   __start_opd = .;
*(.opd)
+   __end_opd = .;
}
 
/*
-- 
2.14.1



[PATCH 5/5] symbol lookup: use new kernel and module dereference functions

2017-09-15 Thread Sergey Senozhatsky
Call appropriate function descriptor dereference ARCH callbacks:
- dereference_kernel_function_descriptor() if the pointer is a
  kernel symbol;

- dereference_module_function_descriptor() if the pointer is a
  module symbol.

This patch also removes dereference_function_descriptor() from
'%pF/%pf' vsprintf handler, because it has the same behavior with
'%pS/%ps' now.

Signed-off-by: Sergey Senozhatsky 
---
 Documentation/printk-formats.txt | 15 +--
 kernel/kallsyms.c|  1 +
 kernel/module.c  |  1 +
 lib/vsprintf.c   |  5 +
 4 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/Documentation/printk-formats.txt b/Documentation/printk-formats.txt
index 361789df51ec..b2afafc84638 100644
--- a/Documentation/printk-formats.txt
+++ b/Documentation/printk-formats.txt
@@ -50,26 +50,23 @@ Symbols/Function Pointers
 
 ::
 
+   %pS versatile_init+0x0/0x110
+   %ps versatile_init
%pF versatile_init+0x0/0x110
%pf versatile_init
-   %pS versatile_init+0x0/0x110
%pSRversatile_init+0x9/0x110
(with __builtin_extract_return_addr() translation)
-   %ps versatile_init
%pB prev_fn_of_versatile_init+0x88/0x88
 
-The ``F`` and ``f`` specifiers are for printing function pointers,
-for example, f->func, &gettimeofday. They have the same result as
-``S`` and ``s`` specifiers. But they do an extra conversion on
-ia64, ppc64 and parisc64 architectures where the function pointers
-are actually function descriptors.
-
 The ``S`` and ``s`` specifiers can be used for printing symbols
 from direct addresses, for example, __builtin_return_address(0),
 (void *)regs->ip. They result in the symbol name with (``S``) or
 without (``s``) offsets. If KALLSYMS are disabled then the symbol
 address is printed instead.
 
+Note, that the ``F`` and ``f`` specifiers are identical to ``S`` (``s``)
+and thus deprecated.
+
 The ``B`` specifier results in the symbol name with offsets and should be
 used when printing stack backtraces. The specifier takes into
 consideration the effect of compiler optimisations which may occur
@@ -77,8 +74,6 @@ when tail-call``s are used and marked with the noreturn GCC 
attribute.
 
 Examples::
 
-   printk("Going to call: %pF\n", gettimeofday);
-   printk("Going to call: %pF\n", p->func);
printk("%s: called from %pS\n", __func__, (void *)_RET_IP_);
printk("%s: called from %pS\n", __func__,
(void *)__builtin_return_address(0));
diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index 127e7cfafa55..e2fc09ea9509 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -322,6 +322,7 @@ const char *kallsyms_lookup(unsigned long addr,
if (is_ksym_addr(addr)) {
unsigned long pos;
 
+   addr = dereference_kernel_function_descriptor(addr);
pos = get_symbol_pos(addr, symbolsize, offset);
/* Grab name */
kallsyms_expand_symbol(get_symbol_offset(pos),
diff --git a/kernel/module.c b/kernel/module.c
index 87cdb46863cd..4f591f2bbf5a 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -3948,6 +3948,7 @@ const char *module_address_lookup(unsigned long addr,
preempt_disable();
mod = __module_address(addr);
if (mod) {
+   addr = dereference_module_function_descriptor(mod, addr);
if (modname)
*modname = mod->name;
ret = get_ksymbol(mod, addr, size, offset);
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 86c3385b9eb3..bf04b4f5d8e7 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -40,7 +40,6 @@
 #include "../mm/internal.h"/* For the trace_print_flags arrays */
 
 #include   /* for PAGE_SIZE */
-#include   /* for dereference_function_descriptor() */
 #include  /* cpu_to_le16 */
 
 #include 
@@ -1721,10 +1720,8 @@ char *pointer(const char *fmt, char *buf, char *end, 
void *ptr,
}
 
switch (*fmt) {
-   case 'F':
+   case 'F': /* %pF and %pf are kept for compatibility reasons only */
case 'f':
-   ptr = dereference_function_descriptor(ptr);
-   /* Fallthrough */
case 'S':
case 's':
case 'B':
-- 
2.14.1



[PATCH 3/5] powerpc64: Add .opd based function descriptor dereference

2017-09-15 Thread Sergey Senozhatsky
We are moving towards separate kernel and module function descriptor
dereference callbacks. This patch enables it for powerpc64.

For pointers that belong to the kernel
-  Added __start_opd and __end_opd pointers, to track the kernel
   .opd section address range;

-  Added dereference_kernel_function_descriptor(). Now we
   will dereference only function pointers that are within
   [__start_opd, __end_opd];

For pointers that belong to a module
-  Added dereference_module_function_descriptor() to handle module
   function descriptor dereference. Now we will dereference only
   pointers that are within [module->opd.start, module->opd.end].

Signed-off-by: Sergey Senozhatsky 
---
 arch/powerpc/include/asm/module.h   |  3 +++
 arch/powerpc/include/asm/sections.h | 13 +
 arch/powerpc/kernel/module_64.c | 16 
 arch/powerpc/kernel/vmlinux.lds.S   |  2 ++
 4 files changed, 34 insertions(+)

diff --git a/arch/powerpc/include/asm/module.h 
b/arch/powerpc/include/asm/module.h
index 6c0132c7212f..7e28442827f1 100644
--- a/arch/powerpc/include/asm/module.h
+++ b/arch/powerpc/include/asm/module.h
@@ -45,6 +45,9 @@ struct mod_arch_specific {
unsigned long tramp;
 #endif
 
+   /* For module function descriptor dereference */
+   unsigned long start_opd;
+   unsigned long end_opd;
 #else /* powerpc64 */
/* Indices of PLT sections within module. */
unsigned int core_plt_section;
diff --git a/arch/powerpc/include/asm/sections.h 
b/arch/powerpc/include/asm/sections.h
index 7902d6358854..7cc4db86952b 100644
--- a/arch/powerpc/include/asm/sections.h
+++ b/arch/powerpc/include/asm/sections.h
@@ -16,6 +16,9 @@ extern char __end_interrupts[];
 extern char __prom_init_toc_start[];
 extern char __prom_init_toc_end[];
 
+extern char __start_opd[];
+extern char __end_opd[];
+
 static inline int in_kernel_text(unsigned long addr)
 {
if (addr >= (unsigned long)_stext && addr < (unsigned long)__init_end)
@@ -66,6 +69,8 @@ static inline int overlaps_kvm_tmp(unsigned long start, 
unsigned long end)
 
 #ifdef PPC64_ELF_ABI_v1
 #undef dereference_function_descriptor
+#undef dereference_kernel_function_descriptor
+
 static inline void *dereference_function_descriptor(void *ptr)
 {
struct ppc64_opd_entry *desc = ptr;
@@ -75,6 +80,14 @@ static inline void *dereference_function_descriptor(void 
*ptr)
ptr = p;
return ptr;
 }
+
+static inline void *dereference_kernel_function_descriptor(void *ptr)
+{
+   if (ptr < (void *)__start_opd || (void *)__end_opd < ptr)
+   return ptr;
+
+   return dereference_function_descriptor(ptr);
+}
 #endif /* PPC64_ELF_ABI_v1 */
 
 #endif
diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c
index 0b0f89685b67..52aa5d668364 100644
--- a/arch/powerpc/kernel/module_64.c
+++ b/arch/powerpc/kernel/module_64.c
@@ -344,6 +344,11 @@ int module_frob_arch_sections(Elf64_Ehdr *hdr,
else if (strcmp(secstrings+sechdrs[i].sh_name,"__versions")==0)
dedotify_versions((void *)hdr + sechdrs[i].sh_offset,
  sechdrs[i].sh_size);
+   else if (strcmp(secstrings + sechdrs[i].sh_name, ".opd")==0) {
+   me->arch.start_opd = sechdrs[i].sh_offset;
+   me->arch.end_opd = me->arch.start_opd +
+   sechdrs[i].sh_size;
+   }
 
/* We don't handle .init for the moment: rename to _init */
while ((p = strstr(secstrings + sechdrs[i].sh_name, ".init")))
@@ -712,6 +717,17 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
return 0;
 }
 
+#ifdef PPC64_ELF_ABI_v1
+unsigned long dereference_module_function_descriptor(struct module *mod,
+unsigned long addr)
+{
+   if (addr < mod->arch.start_opd || mod->arch.end_opd < addr)
+   return addr;
+
+   return dereference_function_descriptor(addr);
+}
+#endif /* PPC64_ELF_ABI_v1 */
+
 #ifdef CONFIG_DYNAMIC_FTRACE
 
 #ifdef CC_USING_MPROFILE_KERNEL
diff --git a/arch/powerpc/kernel/vmlinux.lds.S 
b/arch/powerpc/kernel/vmlinux.lds.S
index 882628fa6987..70e10251e083 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -277,7 +277,9 @@ SECTIONS
}
 
.opd : AT(ADDR(.opd) - LOAD_OFFSET) {
+   __start_opd = .;
*(.opd)
+   __end_opd = .;
}
 
. = ALIGN(256);
-- 
2.14.1



[PATCH 4/5] parisc64: Add .opd based function descriptor dereference

2017-09-15 Thread Sergey Senozhatsky
We are moving towards separate kernel and module function descriptor
dereference callbacks. This patch enables it for parisc64.

For pointers that belong to the kernel
-  Added __start_opd and __end_opd pointers, to track the kernel
   .opd section address range;

-  Added dereference_kernel_function_descriptor(). Now we
   will dereference only function pointers that are within
   [__start_opd, __end_opd];

For pointers that belong to a module
-  Added dereference_module_function_descriptor() to handle module
   function descriptor dereference. Now we will dereference only
   pointers that are within [module->opd.start, module->opd.end].

Signed-off-by: Sergey Senozhatsky 
---
 arch/parisc/boot/compressed/vmlinux.lds.S |  2 ++
 arch/parisc/include/asm/sections.h|  3 +++
 arch/parisc/kernel/module.c   | 14 ++
 arch/parisc/kernel/process.c  | 10 ++
 arch/parisc/kernel/vmlinux.lds.S  |  2 ++
 5 files changed, 31 insertions(+)

diff --git a/arch/parisc/boot/compressed/vmlinux.lds.S 
b/arch/parisc/boot/compressed/vmlinux.lds.S
index a4ce3314e78e..4ebd4e65524c 100644
--- a/arch/parisc/boot/compressed/vmlinux.lds.S
+++ b/arch/parisc/boot/compressed/vmlinux.lds.S
@@ -29,7 +29,9 @@ SECTIONS
. = ALIGN(16);
/* Linkage tables */
.opd : {
+   __start_opd = .;
*(.opd)
+   __end_opd = .;
} PROVIDE (__gp = .);
.plt : {
*(.plt)
diff --git a/arch/parisc/include/asm/sections.h 
b/arch/parisc/include/asm/sections.h
index 9d13c3507ad6..e3cde650b2f9 100644
--- a/arch/parisc/include/asm/sections.h
+++ b/arch/parisc/include/asm/sections.h
@@ -6,7 +6,10 @@
 
 #ifdef CONFIG_64BIT
 #undef dereference_function_descriptor
+#undef dereference_kernel_function_descriptor
+
 void *dereference_function_descriptor(void *);
+void *dereference_kernel_function_descriptor(void *);
 #endif
 
 #endif
diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
index f1a76935a314..bc2eae8634fd 100644
--- a/arch/parisc/kernel/module.c
+++ b/arch/parisc/kernel/module.c
@@ -954,3 +954,17 @@ void module_arch_cleanup(struct module *mod)
 {
deregister_unwind_table(mod);
 }
+
+#ifdef CONFIG_64BIT
+unsigned long dereference_module_function_descriptor(struct module *mod,
+unsigned long addr)
+{
+   void *opd_sz = mod->arch.fdesc_offset +
+  mod->arch.fdesc_max * sizeof(Elf64_Fdesc);
+
+   if (addr < mod->arch.fdesc_offset || opd_sz < addr)
+   return addr;
+
+   return dereference_function_descriptor(addr);
+}
+#endif
diff --git a/arch/parisc/kernel/process.c b/arch/parisc/kernel/process.c
index 30f92391a93e..f30776bdaa79 100644
--- a/arch/parisc/kernel/process.c
+++ b/arch/parisc/kernel/process.c
@@ -267,6 +267,8 @@ get_wchan(struct task_struct *p)
 }
 
 #ifdef CONFIG_64BIT
+extern char __start_opd[], __end_opd[];
+
 void *dereference_function_descriptor(void *ptr)
 {
Elf64_Fdesc *desc = ptr;
@@ -276,6 +278,14 @@ void *dereference_function_descriptor(void *ptr)
ptr = p;
return ptr;
 }
+
+void *dereference_kernel_function_descriptor(void *ptr)
+{
+   if (ptr < (void *)__start_opd || (void *)__end_opd < ptr)
+   return ptr;
+
+   return dereference_function_descriptor(ptr);
+}
 #endif
 
 static inline unsigned long brk_rnd(void)
diff --git a/arch/parisc/kernel/vmlinux.lds.S b/arch/parisc/kernel/vmlinux.lds.S
index ffe2cbf52d1a..ab030895dd1e 100644
--- a/arch/parisc/kernel/vmlinux.lds.S
+++ b/arch/parisc/kernel/vmlinux.lds.S
@@ -99,7 +99,9 @@ SECTIONS
. = ALIGN(16);
/* Linkage tables */
.opd : {
+   __start_opd = .;
*(.opd)
+   __end_opd = .;
} PROVIDE (__gp = .);
.plt : {
*(.plt)
-- 
2.14.1



[PATCH 1/5] sections: split dereference_function_descriptor()

2017-09-15 Thread Sergey Senozhatsky
There are two format specifiers to print out a pointer in symbolic
format: '%pS/%ps' and '%pF/%pf'. On most architectures, the two
mean exactly the same thing, but some architectures (ia64, ppc64,
parisc64) use an indirect pointer for C function pointers, where
the function pointer points to a function descriptor (which in
turn contains the actual pointer to the code). The '%pF/%pf, when
used appropriately, automatically does the appropriate function
descriptor dereference on such architectures.

The "when used appropriately" part is tricky. Basically this is
a subtle ABI detail, specific to some platforms, that made it to
the API level and people can be unaware of it and miss the whole
"we need to dereference the function" business out. [1] proves
that point (note that it fixes only '%pF' and '%pS', there might
be '%pf' and '%ps' cases as well).

It appears that we can handle everything within the affected
arches and make '%pS/%ps' smart enough to retire '%pF/%pf'.
Function descriptors live in .opd elf section and all affected
arches (ia64, ppc64, parisc64) handle it properly for kernel
and modules. So we, technically, can decide if the dereference
is needed by simply looking at the pointer: if it belongs to
.opd section then we need to dereference it.

The kernel and modules have their own .opd sections, obviously,
that's why we need to split dereference_function_descriptor()
and use separate kernel and module dereference arch callbacks.

This patch does the first step, it
a) adds dereference_kernel_function_descriptor() function.
b) adds a weak alias to dereference_module_function_descriptor()
   function.

So, for the time being, we will have:
1) dereference_function_descriptor()
   A generic function, that simply dereferences the pointer. There is
   bunch of places that call it: kgdbts, init/main.c, extable, etc.

2) dereference_kernel_function_descriptor()
   A function to call on kernel symbols that does kernel .opd section
   address range test.

3) dereference_module_function_descriptor()
   A function to call on modules' symbols that does modules' .opd
   section address range test.

[1] https://marc.info/?l=linux-kernel&m=150472969730573

Signed-off-by: Sergey Senozhatsky 
---
 include/asm-generic/sections.h | 4 ++--
 include/linux/moduleloader.h   | 4 
 kernel/module.c| 6 ++
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index e5da44eddd2f..21d2165e531a 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -49,10 +49,10 @@ extern char __ctors_start[], __ctors_end[];
 
 extern __visible const void __nosave_begin, __nosave_end;
 
-/* function descriptor handling (if any).  Override
- * in asm/sections.h */
+/* Function descriptor handling (if any).  Override in asm/sections.h */
 #ifndef dereference_function_descriptor
 #define dereference_function_descriptor(p) (p)
+#define dereference_kernel_function_descriptor(p) (p)
 #endif
 
 /* random extra sections (if any).  Override
diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
index 4d0cb9bba93e..172904e9cded 100644
--- a/include/linux/moduleloader.h
+++ b/include/linux/moduleloader.h
@@ -85,6 +85,10 @@ void module_arch_cleanup(struct module *mod);
 /* Any cleanup before freeing mod->module_init */
 void module_arch_freeing_init(struct module *mod);
 
+/* Dereference module function descriptor */
+unsigned long dereference_module_function_descriptor(struct module *mod,
+unsigned long addr);
+
 #ifdef CONFIG_KASAN
 #include 
 #define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT)
diff --git a/kernel/module.c b/kernel/module.c
index de66ec825992..87cdb46863cd 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2121,6 +2121,12 @@ void __weak module_arch_freeing_init(struct module *mod)
 {
 }
 
+unsigned long __weak dereference_module_function_descriptor(struct module *mod,
+   unsigned long addr)
+{
+   return addr;
+}
+
 /* Free a module, remove from lists, etc. */
 static void free_module(struct module *mod)
 {
-- 
2.14.1



[PATCH 0/5] [RFC] printk/ia64/ppc64/parisc64: let's deprecate %pF/%pf printk specifiers

2017-09-15 Thread Sergey Senozhatsky
Hello

RFC

On some arches C function pointers are indirect and point to
a function descriptor, which contains the actual pointer to the code.
This mostly doesn't matter, except for cases when people want to print
out function pointers in symbolic format, because the usual '%pS/%ps'
does not work on those arches as expected. That's the reason why we
have '%pF/%pf', but since it's here because of a subtle ABI detail
specific to some arches (ppc64/ia64/parisc64) it's easy to misuse
'%pF/%pf' and '%pS/%ps' (see [1], for example).

This patch set attempts to move ia64/ppc64/parisc64 C function
pointer ABI details out of printk() to arch code. Function dereference
code now checks if a pointer belongs to a .opd ELF section and dereferences
that pointer only if it does. The kernel and modules have their own .opd
sections that's why I use two different ARCH functions: for kernel and
for module pointer dereference.

I planned to remove dereference_function_descriptor() entirely,
but then I discovered a bunch other uses cases (kgdbts, init/main.c,
extable, etc.), so I decided to keep dereference_function_descriptor()
around because the main point of this patch set is to deprecate %pF/%pf.
But at the same time, I think I can go further and handle both kernel
and module descriptor dereference in dereference_function_descriptor().
We need a module pointer for module .opd check, so that will come at an
extra cost of module lookup (may be there will some other issues along
the way, haven't checked it).

Right now we've got:

- dereference_function_descriptor(addr)
a generic (old) function. it simply attempts to dereference
whatever pointer we give it.

- dereference_kernel_function_descriptor(addr)
dereferences a kernel pointer if it's within the kernel's .opd
section.

- dereference_module_function_descriptor(module, addr)
dereference a module pointer if it's within the module's .opd
section.


*** A BIG NOTE ***
I don't own ia64/ppc64/parisc64 hardware, so the patches are not
tested. Sorry about that!


Another note:
I need to check what is BPF symbol lookup and do we need to
do any dereference there.


[1] https://marc.info/?l=linux-kernel&m=150472969730573

Sergey Senozhatsky (5):
  sections: split dereference_function_descriptor()
  ia64: Add .opd based function descriptor dereference
  powerpc64: Add .opd based function descriptor dereference
  parisc64: Add .opd based function descriptor dereference
  symbol lookup: use new kernel and module dereference functions

 Documentation/printk-formats.txt  | 15 +--
 arch/ia64/include/asm/sections.h  | 14 +-
 arch/ia64/kernel/module.c | 13 +
 arch/ia64/kernel/vmlinux.lds.S|  2 ++
 arch/parisc/boot/compressed/vmlinux.lds.S |  2 ++
 arch/parisc/include/asm/sections.h|  3 +++
 arch/parisc/kernel/module.c   | 14 ++
 arch/parisc/kernel/process.c  | 10 ++
 arch/parisc/kernel/vmlinux.lds.S  |  2 ++
 arch/powerpc/include/asm/module.h |  3 +++
 arch/powerpc/include/asm/sections.h   | 13 +
 arch/powerpc/kernel/module_64.c   | 16 
 arch/powerpc/kernel/vmlinux.lds.S |  2 ++
 include/asm-generic/sections.h|  4 ++--
 include/linux/moduleloader.h  |  4 
 kernel/kallsyms.c |  1 +
 kernel/module.c   |  7 +++
 lib/vsprintf.c|  5 +
 18 files changed, 113 insertions(+), 17 deletions(-)

-- 
2.14.1



Re: [PATCH] mbcache: initialize entry->e_referenced in mb_cache_entry_create()

2017-09-15 Thread Eric Biggers
On Thu, Jul 06, 2017 at 08:27:25PM +0200, Alexander Potapenko wrote:
> KMSAN reported use of uninitialized |entry->e_referenced| in a condition
> in mb_cache_shrink():
> 

This still hasn't been fixed yet.  I think mbcache patches usually go in through
the ext4 tree --- Ted, can you take this patch through the ext4 tree sometime?

Eric


[GIT PULL] PCI fixes for v4.14

2017-09-15 Thread Bjorn Helgaas
PCI fix:

  - revert an attempt to fix a race while enabling upstream bridges because
it broke iwlwifi firmware loading


The following changes since commit 711aab1dbb324d321e3d84368a435a78908c7bce:

  vfs: constify path argument to kernel_read_file_from_path (2017-09-14 
20:18:45 -0700)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git 
tags/pci-v4.14-fixes-1

for you to fetch changes up to 0f50a49e3008597abed0fff052d487f77db89093:

  Revert "PCI: Avoid race while enabling upstream bridges" (2017-09-15 01:33:51 
-0500)


pci-v4.14-fixes-1


Bjorn Helgaas (1):
  Revert "PCI: Avoid race while enabling upstream bridges"

 drivers/pci/pci.c | 13 ++---
 1 file changed, 2 insertions(+), 11 deletions(-)


[PATCH 2/2] mm/memory_hotplug: define find_{smallest|biggest}_section_pfn as unsigned long

2017-09-15 Thread YASUAKI ISHIMATSU
find_{smallest|biggest}_section_pfn()s find the smallest/biggest section
and return the pfn of the section. But the functions are defined as int.
So the functions always return 0x - 0x. It means
if memory address is over 16TB, the functions does not work correctly.

To handle 64 bit value, the patch defines find_{smallest|biggest}_section_pfn()
as unsigned long.

Signed-off-by: Yasuaki Ishimatsu 
---
 mm/memory_hotplug.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 38c3c37..120e45b 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -582,7 +582,7 @@ int __ref __add_pages(int nid, struct zone *zone, unsigned 
long phys_start_pfn,

 #ifdef CONFIG_MEMORY_HOTREMOVE
 /* find the smallest valid pfn in the range [start_pfn, end_pfn) */
-static int find_smallest_section_pfn(int nid, struct zone *zone,
+static unsigned long find_smallest_section_pfn(int nid, struct zone *zone,
 unsigned long start_pfn,
 unsigned long end_pfn)
 {
@@ -607,7 +607,7 @@ static int find_smallest_section_pfn(int nid, struct zone 
*zone,
 }

 /* find the biggest valid pfn in the range [start_pfn, end_pfn). */
-static int find_biggest_section_pfn(int nid, struct zone *zone,
+static unsigned long find_biggest_section_pfn(int nid, struct zone *zone,
unsigned long start_pfn,
unsigned long end_pfn)
 {
-- 
1.8.3.1


[PATCH 1/2] mm/memory_hotplug: Change pfn_to_section_nr/section_nr_to_pfn macro to inline function

2017-09-15 Thread YASUAKI ISHIMATSU
pfn_to_section_nr() and section_nr_to_pfn() are defined as macro.
pfn_to_section_nr() has no issue even if it is defined as macro.
But section_nr_to_pfn() has overflow issue if sec is defined as int.

section_nr_to_pfn() just shifts sec by PFN_SECTION_SHIFT. If sec
is defined as unsigned long, section_nr_to_pfn() returns pfn as 64
bit value. But if sec is defined as int, section_nr_to_pfn() returns
pfn as 32 bit value.

__remove_section() calculates start_pfn using section_nr_to_pfn() and
scn_nr defined as int. So if hot-removed memory address is over 16TB,
overflow issue occurs and section_nr_to_pfn() does not calculate
correct pfn.

To make callers use proper arg, the patch changes the macros to
inline functions.

Signed-off-by: Yasuaki Ishimatsu 
---
 include/linux/mmzone.h | 10 --
 mm/memory_hotplug.c|  2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index ef6a13b..6ae12b2 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -1073,8 +1073,14 @@ static inline unsigned long early_pfn_to_nid(unsigned 
long pfn)
 #error Allocator MAX_ORDER exceeds SECTION_SIZE
 #endif

-#define pfn_to_section_nr(pfn) ((pfn) >> PFN_SECTION_SHIFT)
-#define section_nr_to_pfn(sec) ((sec) << PFN_SECTION_SHIFT)
+static inline unsigned long pfn_to_section_nr(unsigned long pfn)
+{
+   return pfn >> PFN_SECTION_SHIFT;
+}
+static inline unsigned long section_nr_to_pfn(unsigned long sec)
+{
+   return sec << PFN_SECTION_SHIFT;
+}

 #define SECTION_ALIGN_UP(pfn)  (((pfn) + PAGES_PER_SECTION - 1) & 
PAGE_SECTION_MASK)
 #define SECTION_ALIGN_DOWN(pfn)((pfn) & PAGE_SECTION_MASK)
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index b63d7d1..38c3c37 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -798,7 +798,7 @@ static int __remove_section(struct zone *zone, struct 
mem_section *ms,
return ret;

scn_nr = __section_nr(ms);
-   start_pfn = section_nr_to_pfn(scn_nr);
+   start_pfn = section_nr_to_pfn((unsigned long)scn_nr);
__remove_zone(zone, start_pfn);

sparse_remove_one_section(zone, ms, map_offset);
-- 
1.8.3.1


Re: UBSAN: Undefined behaviour in ./arch/x86/include/asm/futex.h:53:13

2017-09-15 Thread Randy Dunlap
On 09/06/17 10:23, Toralf Förster wrote:
> I catched the following UBSAN spew at a stable Gentoo Linux server with 
> hardened tool chain (.config attached) :
> 
> FWIW - The lines before the UBSAN might be completely unrelated - I'm unsure.
> They do come from the build bot [1] I do run at that machine for Gentoo.
> 
> Sep  6 02:18:43 mr-fox kernel: [182842.823403] readonly.exe[3354]: segfault 
> at 400518 ip 0040048f sp 7ffc527356f0 error 7 in 
> readonly.exe[40+1000]
> Sep  6 02:19:07 mr-fox kernel: [182867.599599] readonly.exe[20803]: segfault 
> at 400518 ip 0040048f sp 7ffd2f10ab60 error 7 in 
> readonly.exe[40+1000]
> Sep  6 02:29:21 mr-fox kernel: [183481.309291] readonly.exe[5057]: segfault 
> at 400518 ip 0040048f sp 7ffccf238df0 error 7 in 
> readonly.exe[40+1000]
> Sep  6 05:00:43 mr-fox kernel: [192563.296629] ThreadTest[31675]: segfault at 
> 0 ip 00407967 sp 7fbdb22d5ea0 error 4 in ThreadTest[40+d000]
> Sep  6 05:00:44 mr-fox kernel: [192564.438163] ThreadTest[32629]: segfault at 
> 0 ip 00407967 sp 7f3426479ea0 error 4 in ThreadTest[40+d000]
> Sep  6 05:00:45 mr-fox kernel: [192565.289479] ThreadTest[790]: segfault at 0 
> ip 00407967 sp 7fafb495cea0 error 4 in ThreadTest[40+d000]
> Sep  6 05:00:46 mr-fox kernel: [192566.645458] ThreadTest[1725]: segfault at 
> 0 ip 00407967 sp 7f6007ffeea0 error 4 in ThreadTest[40+d000]
> Sep  6 05:00:47 mr-fox kernel: [192567.340325] ThreadTest[2056]: segfault at 
> 0 ip 7f9d4eea33cc sp 7f9d4ca4ad00 error 4 in 
> libxerces-c-3.1.so[7f9d4ed4f000+33a000]
> Sep  6 05:00:49 mr-fox kernel: [192568.879404] ThreadTest[3237]: segfault at 
> 0 ip 00407967 sp 7f35d9378ea0 error 4 in ThreadTest[40+d000]
> Sep  6 05:00:49 mr-fox kernel: [192568.921071] ThreadTest[3295]: segfault at 
> 0 ip 7fd21fe2a3cc sp 7fd21b9cdd00 error 4 in 
> libxerces-c-3.1.so[7fd21fcd6000+33a000]
> Sep  6 06:00:27 mr-fox kernel: [196147.270993] TCP: request_sock_TCPv6: 
> Possible SYN flooding on port 45651. Sending cookies.  Check SNMP counters.
> Sep  6 06:53:13 mr-fox kernel: [199312.923377] tiff_read_bw[3757]: segfault 
> at 1c50 ip 00400f5d sp 7fffa9abc950 error 4 in 
> tiff_read_bw[40+3000]
> Sep  6 08:02:32 mr-fox kernel: [203471.959326] lt-IlmCtlTest[21137]: segfault 
> at 8 ip 7f9490d0fcd0 sp 7fff4adf6fc0 error 4 in 
> libIlmCtlSimd.so.2.0.0[7f9490cd3000+168000]
> Sep  6 08:36:01 mr-fox kernel: [205480.927067] kworker/dying (9366) used 
> greatest stack depth: 9384 bytes left
> Sep  6 11:24:41 mr-fox kernel: [215601.542468] ling_example[13697]: segfault 
> at 0 ip 7f8616e077b6 sp 7ffdf64bda00 error 4 in 
> libestbase.so.2.1.1[7f8616d09000+253000]
> Sep  6 11:24:41 mr-fox kernel: [215601.561549] ling_regression[13709]: 
> segfault at 0 ip 7faff2d267b6 sp 7fff35129530 error 4 in 
> libestbase.so.2.1.1[7faff2c28000+253000]
> Sep  6 11:24:44 mr-fox kernel: [215604.598147] ch_wave[15951]: segfault at 0 
> ip 7f59faae77b6 sp 7ffd8e4be770 error 4 in 
> libestbase.so.2.1.1[7f59fa9e9000+253000]
> Sep  6 11:24:44 mr-fox kernel: [215604.621802] ch_wave[15960]: segfault at 0 
> ip 7fa70eb957b6 sp 7ffd533c8fc0 error 4 in 
> libestbase.so.2.1.1[7fa70ea97000+253000]
> Sep  6 11:24:45 mr-fox kernel: [215604.922110] viterbi[16171]: segfault at 0 
> ip 7f4503df27b6 sp 7fffcde7d030 error 4 in 
> libestbase.so.2.1.1[7f4503cf4000+253000]
> Sep  6 13:22:47 mr-fox kernel: [222687.240207] capability: warning: `caps' 
> uses deprecated v2 capabilities in a way that may be insecure
> Sep  6 13:22:47 mr-fox kernel: [222687.240213] capability: warning: `caps' 
> uses 32-bit capabilities (legacy support in use)
> Sep  6 13:22:48 mr-fox kernel: [222687.825742] execve[16964]: segfault at 
> fff0 ip 7f706beec1bb sp 7ffc8ec20068 error 5 in 
> libc-2.25.so[7f706bdb6000+1a8000]
> Sep  6 13:23:20 mr-fox kernel: [222720.041895] execve[26054]: segfault at 
> fff0 ip 7fcdf24011bb sp 7ffc9a2624f8 error 5 in 
> libc-2.25.so[7fcdf22cb000+1a8000]
> Sep  6 13:23:20 mr-fox kernel: [222720.100918] mmap: remap_file_page (26074) 
> uses deprecated remap_file_pages() syscall. See 
> Documentation/vm/remap_file_pages.txt.
> Sep  6 13:23:22 mr-fox kernel: [222722.772032] execve[27083]: segfault at 
> fff0 ip 7f2742f041bb sp 7fff5d8d3408 error 5 in 
> libc-2.25.so[7f2742dce000+1a8000]
> Sep  6 13:23:30 mr-fox kernel: [222730.428190] execve[29792]: segfault at 
> fff0 ip 7fc3f8f361bb sp 7fffc9c90238 error 5 in 
> libc-2.25.so[7fc3f8e0+1a8000]
> Sep  6 13:23:32 mr-fox kernel: [222732.084648] execve[30195]: segfault at 
> fff0 ip 7f763af981bb sp 7ffe5672bb08 error 5 in 
> libc-2.25.so[7f763ae62000+1a8000]
> Sep  6 13:23:34 mr-fox kernel: [222734.012531] execve[30632]: segfault at 
> fff0 ip 7f30fdfad1bb sp 7ffc8

RE: [PATCH 1/3] mm, sysctl: make VM stats configurable

2017-09-15 Thread Wang, Kemi
-Original Message-
From: Michal Hocko [mailto:mho...@kernel.org] 
Sent: Friday, September 15, 2017 7:50 PM
To: Wang, Kemi 
Cc: Luis R . Rodriguez ; Kees Cook ; 
Andrew Morton ; Jonathan Corbet ; 
Mel Gorman ; Johannes Weiner ; 
Christopher Lameter ; Sebastian Andrzej Siewior 
; Vlastimil Babka ; Hillf Danton 
; Dave ; Chen, Tim C 
; Kleen, Andi ; Jesper Dangaard 
Brouer ; Huang, Ying ; Lu, Aaron 
; Proc sysctl ; Linux MM 
; Linux Kernel 
Subject: Re: [PATCH 1/3] mm, sysctl: make VM stats configurable

On Fri 15-09-17 17:23:24, Kemi Wang wrote:
> This patch adds a tunable interface that allows VM stats configurable, as
> suggested by Dave Hansen and Ying Huang.
> 
> When performance becomes a bottleneck and you can tolerate some possible
> tool breakage and some decreased counter precision (e.g. numa counter), you
> can do:
>   echo [C|c]oarse > /proc/sys/vm/vmstat_mode
> 
> When performance is not a bottleneck and you want all tooling to work, you
> can do:
>   echo [S|s]trict > /proc/sys/vm/vmstat_mode
> 
> We recommend automatic detection of virtual memory statistics by system,
> this is also system default configuration, you can do:
>   echo [A|a]uto > /proc/sys/vm/vmstat_mode
> 
> The next patch handles numa statistics distinctively based-on different VM
> stats mode.

I would just merge this with the second patch so that it is clear how
those modes are implemented. I am also wondering why cannot we have a
much simpler interface and implementation to enable/disable numa stats
(btw. sysctl_vm_numa_stats would be more descriptive IMHO).

The motivation is that we propose a general tunable  interface for VM stats.
This would be more scalable, since we don't have to add an individual
Interface for each type of counter that can be configurable.
In the second patch, NUMA stats, as an example, can benefit for that.

If you still hold your idea, I don't mind to merge them together.
-- 
Michal Hocko
SUSE Labs


Re: [PATCH] scsi: aacraid: error: testing array offset 'bus' after use

2017-09-15 Thread Martin K. Petersen

Nikola,

> Fix possible indexing array of bound for &aac->hba_map[bus][cid],
> where bus and cid boundary check happens later.

Applied to 4.14/scsi-fixes. Thanks!

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH] csi: libcxgbi: remove redundant check and close on csk

2017-09-15 Thread Martin K. Petersen

Colin,

> csk is always null on the error return path and so the non-null check
> and call to cxgbi_sock_closed on csk is redundant and can be removed.

Applied to 4.15/scsi-queue.

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH v4 00/11] Enhance libsas hotplug feature

2017-09-15 Thread Martin K. Petersen

Jason,

> Yijing Wang handed over this topic to me. We are working on it the
> last two months. We have tested the patchset for a long time. Here is
> the new version.

Applied patches 1-4 and 11 to 4.15/scsi-queue. I suggest you resubmit
the rest to get them back on people's radar.

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [BACKPORT] swiotlb-xen: implement xen_swiotlb_dma_mmap callback

2017-09-15 Thread Greg KH
On Thu, Sep 14, 2017 at 04:23:05PM -0700, Stefano Stabellini wrote:
> Hi all,
> 
> We are getting reports from Xen on ARM users about DMA issues. The
> problem is that the commit below
> (7e91c7df29b5e196de3dc6f086c8937973bd0b88) is necessary to support mmap
> on Xen on ARM. It is self-contained and doesn't affect anything outside
> of Xen on ARM, so I think is a good candidate for backporting. It went
> upstream in 4.11.

But it's a new feature, right?  How does that fit the stable kernel
rules?

> 
> 
> Could you please backport the following commit:
> 
>   commit 7e91c7df29b5e196de3dc6f086c8937973bd0b88
>   Author: Stefano Stabellini 
>   Date:   Tue Feb 7 19:58:02 2017 +0200
>   
>   swiotlb-xen: implement xen_swiotlb_dma_mmap callback
>   
>   This function creates userspace mapping for the DMA-coherent memory.
> 
> to the stable trees up until 3.14?
> 
> 
> Because of 00085f1efa387a8ce100e3734920f7639c80caa3 "dma-mapping: use
> unsigned long for dma_attrs", the appended patch (to be applied on top)
> is required for trees older than 4.8. 

What does the kvm maintainers think about this?

thanks,

greg k-h


[PATCH 2/6] mm, x86 : introduce arch_pkeys_enabled()

2017-09-15 Thread Ram Pai
Arch neutral code needs to know if the architecture supports
protection  keys  to  display protection key in smaps. Hence
introducing arch_pkeys_enabled().

This patch also provides x86 implementation for
arch_pkeys_enabled().

Signed-off-by: Ram Pai 
---
 arch/x86/include/asm/pkeys.h |1 +
 arch/x86/kernel/fpu/xstate.c |5 +
 include/linux/pkeys.h|5 +
 3 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/arch/x86/include/asm/pkeys.h b/arch/x86/include/asm/pkeys.h
index b3b09b9..fa82799 100644
--- a/arch/x86/include/asm/pkeys.h
+++ b/arch/x86/include/asm/pkeys.h
@@ -5,6 +5,7 @@
 
 extern int arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
unsigned long init_val);
+extern bool arch_pkeys_enabled(void);
 
 /*
  * Try to dedicate one of the protection keys to be used as an
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index c24ac1e..df594b8 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -918,6 +918,11 @@ int arch_set_user_pkey_access(struct task_struct *tsk, int 
pkey,
 
return 0;
 }
+
+bool arch_pkeys_enabled(void)
+{
+   return boot_cpu_has(X86_FEATURE_OSPKE);
+}
 #endif /* ! CONFIG_ARCH_HAS_PKEYS */
 
 /*
diff --git a/include/linux/pkeys.h b/include/linux/pkeys.h
index a1bacf1..d120810 100644
--- a/include/linux/pkeys.h
+++ b/include/linux/pkeys.h
@@ -34,6 +34,11 @@ static inline int arch_set_user_pkey_access(struct 
task_struct *tsk, int pkey,
return 0;
 }
 
+static inline bool arch_pkeys_enabled(void)
+{
+   return false;
+}
+
 static inline void copy_init_pkru_to_fpregs(void)
 {
 }
-- 
1.7.1



[PATCH 4/6] mm/mprotect, powerpc/mm/pkeys, x86/mm/pkeys: Add sysfs interface

2017-09-15 Thread Ram Pai
From: Thiago Jung Bauermann 

Expose useful information for programs using memory protection keys.
Provide implementation for powerpc and x86.

On a powerpc system with pkeys support, here is what is shown:

$ head /sys/kernel/mm/protection_keys/*
==> /sys/kernel/mm/protection_keys/disable_access_supported <==
true

==> /sys/kernel/mm/protection_keys/disable_execute_supported <==
true

==> /sys/kernel/mm/protection_keys/disable_write_supported <==
true

==> /sys/kernel/mm/protection_keys/total_keys <==
32

==> /sys/kernel/mm/protection_keys/usable_keys <==
29

And on an x86 without pkeys support:

$ head /sys/kernel/mm/protection_keys/*
==> /sys/kernel/mm/protection_keys/disable_access_supported <==
false

==> /sys/kernel/mm/protection_keys/disable_execute_supported <==
false

==> /sys/kernel/mm/protection_keys/disable_write_supported <==
false

==> /sys/kernel/mm/protection_keys/total_keys <==
1

==> /sys/kernel/mm/protection_keys/usable_keys <==
0

Signed-off-by: Ram Pai 
Signed-off-by: Thiago Jung Bauermann 
---
 arch/powerpc/include/asm/pkeys.h   |2 +
 arch/powerpc/mm/pkeys.c|   20 
 arch/x86/include/asm/mmu_context.h |4 +-
 arch/x86/include/asm/pkeys.h   |1 +
 arch/x86/mm/pkeys.c|8 +++
 include/linux/pkeys.h  |4 ++
 mm/mprotect.c  |   88 
 7 files changed, 126 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/include/asm/pkeys.h b/arch/powerpc/include/asm/pkeys.h
index baac435..5924325 100644
--- a/arch/powerpc/include/asm/pkeys.h
+++ b/arch/powerpc/include/asm/pkeys.h
@@ -244,6 +244,8 @@ static inline bool pkey_mmu_enabled(void)
return cpu_has_feature(CPU_FTR_PKEY);
 }
 
+extern bool arch_supports_pkeys(int cap);
+extern unsigned int arch_usable_pkeys(void);
 extern void thread_pkey_regs_save(struct thread_struct *thread);
 extern void thread_pkey_regs_restore(struct thread_struct *new_thread,
struct thread_struct *old_thread);
diff --git a/arch/powerpc/mm/pkeys.c b/arch/powerpc/mm/pkeys.c
index 07e76dc..33c9207 100644
--- a/arch/powerpc/mm/pkeys.c
+++ b/arch/powerpc/mm/pkeys.c
@@ -373,3 +373,23 @@ bool arch_vma_access_permitted(struct vm_area_struct *vma,
 
return pkey_access_permitted(pkey, write, execute);
 }
+
+unsigned int arch_usable_pkeys(void)
+{
+   unsigned int reserved;
+
+   if (!pkey_inited)
+   return 0;
+
+   /* Reserve one more to account for the execute-only pkey. */
+   reserved = hweight32(initial_allocation_mask) + 1;
+
+   return pkeys_total > reserved ? pkeys_total - reserved : 0;
+}
+
+bool arch_supports_pkeys(int cap)
+{
+   if (cap & PKEY_DISABLE_EXECUTE)
+   return pkey_execute_disable_support;
+   return (cap & (PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE));
+}
diff --git a/arch/x86/include/asm/mmu_context.h 
b/arch/x86/include/asm/mmu_context.h
index 265c907..e960ab2 100644
--- a/arch/x86/include/asm/mmu_context.h
+++ b/arch/x86/include/asm/mmu_context.h
@@ -129,13 +129,15 @@ static inline void enter_lazy_tlb(struct mm_struct *mm, 
struct task_struct *tsk)
this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
 }
 
+#define PKEY_INITIAL_ALLOCATION_MAP1
+
 static inline int init_new_context(struct task_struct *tsk,
   struct mm_struct *mm)
 {
#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
if (cpu_feature_enabled(X86_FEATURE_OSPKE)) {
/* pkey 0 is the default and always allocated */
-   mm->context.pkey_allocation_map = 0x1;
+   mm->context.pkey_allocation_map = PKEY_INITIAL_ALLOCATION_MAP;
/* -1 means unallocated or invalid */
mm->context.execute_only_pkey = -1;
}
diff --git a/arch/x86/include/asm/pkeys.h b/arch/x86/include/asm/pkeys.h
index fa82799..e1b25aa 100644
--- a/arch/x86/include/asm/pkeys.h
+++ b/arch/x86/include/asm/pkeys.h
@@ -105,5 +105,6 @@ extern int arch_set_user_pkey_access(struct task_struct 
*tsk, int pkey,
 extern int __arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
unsigned long init_val);
 extern void copy_init_pkru_to_fpregs(void);
+extern unsigned int arch_usable_pkeys(void);
 
 #endif /*_ASM_X86_PKEYS_H */
diff --git a/arch/x86/mm/pkeys.c b/arch/x86/mm/pkeys.c
index 2dab69a..6b7f4e1 100644
--- a/arch/x86/mm/pkeys.c
+++ b/arch/x86/mm/pkeys.c
@@ -123,6 +123,14 @@ int __arch_override_mprotect_pkey(struct vm_area_struct 
*vma, int prot, int pkey
return vma_pkey(vma);
 }
 
+unsigned int arch_usable_pkeys(void)
+{
+   /* Reserve one more to account for the execute-only pkey. */
+   unsigned int reserved = hweight32(PKEY_INITIAL_ALLOCATION_MAP) + 1;
+
+   return arch_max_pkey() > reserved ? arch_max_pkey() - reserved : 0;
+}
+
 #define PKRU_AD_KEY(pkey)  (PKRU_AD_BIT << ((pkey) * PKRU_BITS_PER_PKEY))
 
 /*
diff --git a/include/linux/pk

[PATCH 3/6] mm: display pkey in smaps if arch_pkeys_enabled() is true

2017-09-15 Thread Ram Pai
Currently the  architecture  specific code is expected to
display  the  protection  keys  in  smap  for a given vma.
This can lead to redundant code and possibly to divergent
formats in which the key gets displayed.

This  patch  changes  the implementation. It displays the
pkey only if the architecture support pkeys.

x86 arch_show_smap() function is not needed anymore.
Delete it.

Signed-off-by: Ram Pai 
---
 arch/x86/kernel/setup.c |8 
 fs/proc/task_mmu.c  |   11 ++-
 2 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 3486d04..1953bce 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1340,11 +1340,3 @@ static int __init register_kernel_offset_dumper(void)
return 0;
 }
 __initcall(register_kernel_offset_dumper);
-
-void arch_show_smap(struct seq_file *m, struct vm_area_struct *vma)
-{
-   if (!boot_cpu_has(X86_FEATURE_OSPKE))
-   return;
-
-   seq_printf(m, "ProtectionKey:  %8u\n", vma_pkey(vma));
-}
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index cf25306..667d44a 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -16,6 +16,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -714,10 +715,6 @@ static int smaps_hugetlb_range(pte_t *pte, unsigned long 
hmask,
 }
 #endif /* HUGETLB_PAGE */
 
-void __weak arch_show_smap(struct seq_file *m, struct vm_area_struct *vma)
-{
-}
-
 static int show_smap(struct seq_file *m, void *v, int is_pid)
 {
struct vm_area_struct *vma = v;
@@ -803,7 +800,11 @@ static int show_smap(struct seq_file *m, void *v, int 
is_pid)
   (vma->vm_flags & VM_LOCKED) ?
(unsigned long)(mss.pss >> (10 + PSS_SHIFT)) : 0);
 
-   arch_show_smap(m, vma);
+#ifdef CONFIG_ARCH_HAS_PKEYS
+   if (arch_pkeys_enabled())
+   seq_printf(m, "ProtectionKey:  %8u\n", vma_pkey(vma));
+#endif
+
show_smap_vma_flags(m, vma);
m_cache_vma(m, vma);
return 0;
-- 
1.7.1



[PATCH 1/6] mm: introduce an additional vma bit for powerpc pkey

2017-09-15 Thread Ram Pai
Currently only 4bits are allocated in the vma flags to hold 16
keys. This is sufficient for x86. PowerPC  supports  32  keys,
which needs 5bits. This patch allocates an  additional bit.

Signed-off-by: Ram Pai 
---
 fs/proc/task_mmu.c |6 --
 include/linux/mm.h |   16 ++--
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index b836fd6..cf25306 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -661,13 +661,15 @@ static void show_smap_vma_flags(struct seq_file *m, 
struct vm_area_struct *vma)
[ilog2(VM_MERGEABLE)]   = "mg",
[ilog2(VM_UFFD_MISSING)]= "um",
[ilog2(VM_UFFD_WP)] = "uw",
-#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
+#ifdef CONFIG_ARCH_HAS_PKEYS
/* These come out via ProtectionKey: */
[ilog2(VM_PKEY_BIT0)]   = "",
[ilog2(VM_PKEY_BIT1)]   = "",
[ilog2(VM_PKEY_BIT2)]   = "",
[ilog2(VM_PKEY_BIT3)]   = "",
-#endif
+   /* Additional bit used by ppc64 */
+   [ilog2(VM_PKEY_BIT4)]   = "",
+#endif /* CONFIG_ARCH_HAS_PKEYS */
};
size_t i;
 
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 46b9ac5..6d72ec0 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -208,21 +208,25 @@ extern int overcommit_kbytes_handler(struct ctl_table *, 
int, void __user *,
 #define VM_HIGH_ARCH_BIT_1 33  /* bit only usable on 64-bit 
architectures */
 #define VM_HIGH_ARCH_BIT_2 34  /* bit only usable on 64-bit 
architectures */
 #define VM_HIGH_ARCH_BIT_3 35  /* bit only usable on 64-bit 
architectures */
+#define VM_HIGH_ARCH_BIT_4 36  /* bit only usable on 64-bit 
architectures */
 #define VM_HIGH_ARCH_0 BIT(VM_HIGH_ARCH_BIT_0)
 #define VM_HIGH_ARCH_1 BIT(VM_HIGH_ARCH_BIT_1)
 #define VM_HIGH_ARCH_2 BIT(VM_HIGH_ARCH_BIT_2)
 #define VM_HIGH_ARCH_3 BIT(VM_HIGH_ARCH_BIT_3)
+#define VM_HIGH_ARCH_4 BIT(VM_HIGH_ARCH_BIT_4)
 #endif /* CONFIG_ARCH_USES_HIGH_VMA_FLAGS */
 
-#if defined(CONFIG_X86)
-# define VM_PATVM_ARCH_1   /* PAT reserves whole VMA at 
once (x86) */
-#if defined (CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS)
+#ifdef CONFIG_ARCH_HAS_PKEYS
 # define VM_PKEY_SHIFT VM_HIGH_ARCH_BIT_0
-# define VM_PKEY_BIT0  VM_HIGH_ARCH_0  /* A protection key is a 4-bit value */
-# define VM_PKEY_BIT1  VM_HIGH_ARCH_1
+# define VM_PKEY_BIT0  VM_HIGH_ARCH_0 /* A protection key is a 4-bit value */
+# define VM_PKEY_BIT1  VM_HIGH_ARCH_1 /* on x86 and 5-bit value on ppc64   */
 # define VM_PKEY_BIT2  VM_HIGH_ARCH_2
 # define VM_PKEY_BIT3  VM_HIGH_ARCH_3
-#endif
+# define VM_PKEY_BIT4  VM_HIGH_ARCH_4
+#endif /* CONFIG_ARCH_HAS_PKEYS */
+
+#if defined(CONFIG_X86)
+# define VM_PATVM_ARCH_1   /* PAT reserves whole VMA at 
once (x86) */
 #elif defined(CONFIG_PPC)
 # define VM_SAOVM_ARCH_1   /* Strong Access Ordering 
(powerpc) */
 #elif defined(CONFIG_PARISC)
-- 
1.7.1



[PATCH 6/6] Documentation/vm: PowerPC specific updates to memory protection keys

2017-09-15 Thread Ram Pai
Add documentation updates that capture PowerPC specific changes.

Signed-off-by: Thiago Jung Bauermann 
Signed-off-by: Ram Pai 
---
 Documentation/vm/protection-keys.txt |  125 +++---
 1 files changed, 100 insertions(+), 25 deletions(-)

diff --git a/Documentation/vm/protection-keys.txt 
b/Documentation/vm/protection-keys.txt
index b643045..ef5f73b 100644
--- a/Documentation/vm/protection-keys.txt
+++ b/Documentation/vm/protection-keys.txt
@@ -1,22 +1,45 @@
-Memory Protection Keys for Userspace (PKU aka PKEYs) is a CPU feature
-which will be found on future Intel CPUs.
-
-Memory Protection Keys provides a mechanism for enforcing page-based
-protections, but without requiring modification of the page tables
-when an application changes protection domains.  It works by
-dedicating 4 previously ignored bits in each page table entry to a
-"protection key", giving 16 possible keys.
-
-There is also a new user-accessible register (PKRU) with two separate
-bits (Access Disable and Write Disable) for each key.  Being a CPU
-register, PKRU is inherently thread-local, potentially giving each
-thread a different set of protections from every other thread.
-
-There are two new instructions (RDPKRU/WRPKRU) for reading and writing
-to the new register.  The feature is only available in 64-bit mode,
-even though there is theoretically space in the PAE PTEs.  These
-permissions are enforced on data access only and have no effect on
-instruction fetches.
+Memory Protection Keys for Userspace (PKU aka PKEYs) is a CPU feature found on
+future Intel CPUs and on PowerPC 5 and higher CPUs.
+
+Memory Protection Keys provide a mechanism for enforcing page-based
+protections, but without requiring modification of the page tables when an
+application changes protection domains.
+
+It works by dedicating bits in each page table entry to a "protection key".
+There is also a user-accessible register with two separate bits for each
+key.  Being a CPU register, the user-accessible register is inherently
+thread-local, potentially giving each thread a different set of protections
+from every other thread.
+
+On Intel:
+
+   Four previously bits are used the page table entry giving 16 possible 
keys.
+
+   The user accessible register(PKRU) has a bit each per key to disable
+   access and to disable write.
+
+   The feature is only available in 64-bit mode, even though there is
+   theoretically space in the PAE PTEs.  These permissions are enforced on
+   data access only and have no effect on instruction fetches.
+
+On PowerPC:
+
+   Five bits in the page table entry are used giving 32 possible keys.
+   This support is currently for Hash Page Table mode only.
+
+   The user accessible register(AMR) has a bit each per key to disable
+   read and write. Access disable can be achieved by disabling
+   read and write.
+
+   'mtspr 0xd, mem' reads the AMR register
+   'mfspr mem, 0xd' writes into the AMR register.
+
+   Execution can  be  disabled by allocating a key with execute-disabled
+   permission. The execute-permissions on the key; however, cannot be
+   changed through a user accessible register. The CPU will not allow
+   execution of instruction in pages that are associated with
+   execute-disabled key.
+
 
 === Syscalls ===
 
@@ -28,9 +51,9 @@ There are 3 system calls which directly interact with pkeys:
  unsigned long prot, int pkey);
 
 Before a pkey can be used, it must first be allocated with
-pkey_alloc().  An application calls the WRPKRU instruction
+pkey_alloc().  An application calls the WRPKRU/AMR instruction
 directly in order to change access permissions to memory covered
-with a key.  In this example WRPKRU is wrapped by a C function
+with a key.  In this example WRPKRU/AMR is wrapped by a C function
 called pkey_set().
 
int real_prot = PROT_READ|PROT_WRITE;
@@ -52,11 +75,11 @@ is no longer in use:
munmap(ptr, PAGE_SIZE);
pkey_free(pkey);
 
-(Note: pkey_set() is a wrapper for the RDPKRU and WRPKRU instructions.
+(Note: pkey_set() is a wrapper for the RDPKRU,WRPKRU or AMR instructions.
  An example implementation can be found in
- tools/testing/selftests/x86/protection_keys.c)
+ tools/testing/selftests/vm/protection_keys.c)
 
-=== Behavior ===
+=== Behavior =
 
 The kernel attempts to make protection keys consistent with the
 behavior of a plain mprotect().  For instance if you do this:
@@ -66,7 +89,7 @@ behavior of a plain mprotect().  For instance if you do this:
 
 you can expect the same effects with protection keys when doing this:
 
-   pkey = pkey_alloc(0, PKEY_DISABLE_WRITE | PKEY_DISABLE_READ);
+   pkey = pkey_alloc(0, PKEY_DISABLE_ACCESS);
pkey_mprotect(ptr, size, PROT_READ|PROT_WRITE, pkey);
   

[PATCH 0/6] mm, x86, powerpc: Memory Protection Keys enhancement

2017-09-15 Thread Ram Pai
The patch-series enhances memory protection keys feature.

The patch(1)  introduces  an  additional  vma bit to support 32
pkeys.  PowerPC supports 32 pkeys.

The patch(2,3)  introduces a new interface arch_pkeys_enabled(),
this  interface  can   be used by arch-neutral code to display
protection key value in smap.

The patch(4) introduces a syfs interface, to display the static
attributes  of the protection key. Eg: max number of keys.

The last two patches, (5,6) update documentation.

A separate patch series that enhances selftest will follow. The
entire  patch  series  that  enables  pkeys  on  powerpc  is at 
https://github.com/rampai/memorykeys.git memkey.v9-rc1

Testing:
---
This  patches are tested on powerpc platform using a
enhaced set of selftests.
Could not test on x86 since I do not have access to
one with pkey support.

History:
---
version v3:
(1) sysfs interface - thanks Thiago.
(2) Documentation update.

version v2:
(1) Documentation   is   updated   to  better 
capture the semantics.
(2) introduced   arch_pkeys_enabled() to find
if an arch enables pkeys.  Correspond-
ing change in logic that displays key
value in smaps.
(3) code  rearranged  in many places based on
comments from   Dave Hansen,   Balbir,
Anshuman.   
version v1: Initial version

Ram Pai (5):
  mm: introduce an additional vma bit for powerpc pkey
  mm, x86 : introduce arch_pkeys_enabled()
  mm: display pkey in smaps if arch_pkeys_enabled() is true
  Documentation/x86: Move protecton key documentation to arch neutral
directory
  Documentation/vm: PowerPC specific updates to memory protection keys

Thiago Jung Bauermann (1):
  mm/mprotect, powerpc/mm/pkeys, x86/mm/pkeys: Add sysfs interface

 Documentation/vm/protection-keys.txt  |  160 +
 Documentation/x86/protection-keys.txt |   85 -
 arch/powerpc/include/asm/pkeys.h  |2 +
 arch/powerpc/mm/pkeys.c   |   20 
 arch/x86/include/asm/mmu_context.h|4 +-
 arch/x86/include/asm/pkeys.h  |2 +
 arch/x86/kernel/fpu/xstate.c  |5 +
 arch/x86/kernel/setup.c   |8 --
 arch/x86/mm/pkeys.c   |8 ++
 fs/proc/task_mmu.c|   17 ++--
 include/linux/mm.h|   16 ++--
 include/linux/pkeys.h |9 ++
 mm/mprotect.c |   88 ++
 13 files changed, 317 insertions(+), 107 deletions(-)
 create mode 100644 Documentation/vm/protection-keys.txt
 delete mode 100644 Documentation/x86/protection-keys.txt



[PATCH 5/6] Documentation/x86: Move protecton key documentation to arch neutral directory

2017-09-15 Thread Ram Pai
Since PowerPC and Intel both support memory protection keys, moving
the documenation to arch-neutral directory.

Signed-off-by: Ram Pai 
---
 Documentation/vm/protection-keys.txt  |   85 +
 Documentation/x86/protection-keys.txt |   85 -
 2 files changed, 85 insertions(+), 85 deletions(-)
 create mode 100644 Documentation/vm/protection-keys.txt
 delete mode 100644 Documentation/x86/protection-keys.txt

diff --git a/Documentation/vm/protection-keys.txt 
b/Documentation/vm/protection-keys.txt
new file mode 100644
index 000..b643045
--- /dev/null
+++ b/Documentation/vm/protection-keys.txt
@@ -0,0 +1,85 @@
+Memory Protection Keys for Userspace (PKU aka PKEYs) is a CPU feature
+which will be found on future Intel CPUs.
+
+Memory Protection Keys provides a mechanism for enforcing page-based
+protections, but without requiring modification of the page tables
+when an application changes protection domains.  It works by
+dedicating 4 previously ignored bits in each page table entry to a
+"protection key", giving 16 possible keys.
+
+There is also a new user-accessible register (PKRU) with two separate
+bits (Access Disable and Write Disable) for each key.  Being a CPU
+register, PKRU is inherently thread-local, potentially giving each
+thread a different set of protections from every other thread.
+
+There are two new instructions (RDPKRU/WRPKRU) for reading and writing
+to the new register.  The feature is only available in 64-bit mode,
+even though there is theoretically space in the PAE PTEs.  These
+permissions are enforced on data access only and have no effect on
+instruction fetches.
+
+=== Syscalls ===
+
+There are 3 system calls which directly interact with pkeys:
+
+   int pkey_alloc(unsigned long flags, unsigned long init_access_rights)
+   int pkey_free(int pkey);
+   int pkey_mprotect(unsigned long start, size_t len,
+ unsigned long prot, int pkey);
+
+Before a pkey can be used, it must first be allocated with
+pkey_alloc().  An application calls the WRPKRU instruction
+directly in order to change access permissions to memory covered
+with a key.  In this example WRPKRU is wrapped by a C function
+called pkey_set().
+
+   int real_prot = PROT_READ|PROT_WRITE;
+   pkey = pkey_alloc(0, PKEY_DENY_WRITE);
+   ptr = mmap(NULL, PAGE_SIZE, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 
0);
+   ret = pkey_mprotect(ptr, PAGE_SIZE, real_prot, pkey);
+   ... application runs here
+
+Now, if the application needs to update the data at 'ptr', it can
+gain access, do the update, then remove its write access:
+
+   pkey_set(pkey, 0); // clear PKEY_DENY_WRITE
+   *ptr = foo; // assign something
+   pkey_set(pkey, PKEY_DENY_WRITE); // set PKEY_DENY_WRITE again
+
+Now when it frees the memory, it will also free the pkey since it
+is no longer in use:
+
+   munmap(ptr, PAGE_SIZE);
+   pkey_free(pkey);
+
+(Note: pkey_set() is a wrapper for the RDPKRU and WRPKRU instructions.
+ An example implementation can be found in
+ tools/testing/selftests/x86/protection_keys.c)
+
+=== Behavior ===
+
+The kernel attempts to make protection keys consistent with the
+behavior of a plain mprotect().  For instance if you do this:
+
+   mprotect(ptr, size, PROT_NONE);
+   something(ptr);
+
+you can expect the same effects with protection keys when doing this:
+
+   pkey = pkey_alloc(0, PKEY_DISABLE_WRITE | PKEY_DISABLE_READ);
+   pkey_mprotect(ptr, size, PROT_READ|PROT_WRITE, pkey);
+   something(ptr);
+
+That should be true whether something() is a direct access to 'ptr'
+like:
+
+   *ptr = foo;
+
+or when the kernel does the access on the application's behalf like
+with a read():
+
+   read(fd, ptr, 1);
+
+The kernel will send a SIGSEGV in both cases, but si_code will be set
+to SEGV_PKERR when violating protection keys versus SEGV_ACCERR when
+the plain mprotect() permissions are violated.
diff --git a/Documentation/x86/protection-keys.txt 
b/Documentation/x86/protection-keys.txt
deleted file mode 100644
index b643045..000
--- a/Documentation/x86/protection-keys.txt
+++ /dev/null
@@ -1,85 +0,0 @@
-Memory Protection Keys for Userspace (PKU aka PKEYs) is a CPU feature
-which will be found on future Intel CPUs.
-
-Memory Protection Keys provides a mechanism for enforcing page-based
-protections, but without requiring modification of the page tables
-when an application changes protection domains.  It works by
-dedicating 4 previously ignored bits in each page table entry to a
-"protection key", giving 16 possible keys.
-
-There is also a new user-accessible register (PKRU) with two separate
-bits (Access Disable and Write Disable) for each key.  Being a CPU
-register, PKRU is inherently thread-local, potentially giving each
-thread a different set of protections from every oth

Re: [PATCH v2] HID: asus: Add support for Fn keys on Asus ROG G752

2017-09-15 Thread Jiri Kosina
On Thu, 7 Sep 2017, Maxime Bellengé wrote:

> This patch adds support for Fn keys on Asus ROG G752 laptop.
> The report descriptor is broken so I fixed it.
> 
> Tested on an Asus G752VT.
> Resent fix white space fixes

Those whitespace fixes were almost right :) Except for the quirk/blacklist 
additions, which still added with spaces instead of tabs. I've fixed that 
up manually while applying, but please look into it for any further 
submissions.

Applied to for-4.15/asus.

Thanks, 

-- 
Jiri Kosina
SUSE Labs



Re: [PATCH] Asoc: rockchip: Init dapm routes dynamically

2017-09-15 Thread Matthias Kaehlcke
El Tue, Sep 05, 2017 at 12:14:01PM +0800 Jeffy Chen ha dit:

> Currently we are using a fixed list of dapm routes.
> 
> Init dapm routes dynamically when parsing dailinks, since we are
> supporting optional codecs.
> 
> Signed-off-by: Jeffy Chen 
> ---
> 
>  sound/soc/rockchip/rk3399_gru_sound.c | 88 
> +--
>  1 file changed, 74 insertions(+), 14 deletions(-)
> 
> diff --git a/sound/soc/rockchip/rk3399_gru_sound.c 
> b/sound/soc/rockchip/rk3399_gru_sound.c
> index 0513fe480353..c537781f8054 100644
> --- a/sound/soc/rockchip/rk3399_gru_sound.c
> +++ b/sound/soc/rockchip/rk3399_gru_sound.c
> @@ -47,18 +47,7 @@ static const struct snd_soc_dapm_widget 
> rockchip_dapm_widgets[] = {
>   SND_SOC_DAPM_SPK("Speakers", NULL),
>   SND_SOC_DAPM_MIC("Headset Mic", NULL),
>   SND_SOC_DAPM_MIC("Int Mic", NULL),
> -};
> -
> -static const struct snd_soc_dapm_route rockchip_dapm_routes[] = {
> - /* Input Lines */
> - {"MIC", NULL, "Headset Mic"},
> - {"DMIC1L", NULL, "Int Mic"},
> - {"DMIC1R", NULL, "Int Mic"},
> -
> - /* Output Lines */
> - {"Headphones", NULL, "HPL"},
> - {"Headphones", NULL, "HPR"},
> - {"Speakers", NULL, "Speaker"},
> + SND_SOC_DAPM_LINE("HDMI", NULL),

The HDMI items are newly added, I think a separate patch would be
preferable.

>  };
>  
>  static const struct snd_kcontrol_new rockchip_controls[] = {
> @@ -66,6 +55,7 @@ static const struct snd_kcontrol_new rockchip_controls[] = {
>   SOC_DAPM_PIN_SWITCH("Speakers"),
>   SOC_DAPM_PIN_SWITCH("Headset Mic"),
>   SOC_DAPM_PIN_SWITCH("Int Mic"),
> + SOC_DAPM_PIN_SWITCH("HDMI"),
>  };
>  
>  static int rockchip_sound_max98357a_hw_params(struct snd_pcm_substream 
> *substream,
> @@ -314,8 +304,6 @@ static struct snd_soc_card rockchip_sound_card = {
>   .owner = THIS_MODULE,
>   .dapm_widgets = rockchip_dapm_widgets,
>   .num_dapm_widgets = ARRAY_SIZE(rockchip_dapm_widgets),
> - .dapm_routes = rockchip_dapm_routes,
> - .num_dapm_routes = ARRAY_SIZE(rockchip_dapm_routes),
>   .controls = rockchip_controls,
>   .num_controls = ARRAY_SIZE(rockchip_controls),
>  };
> @@ -391,6 +379,65 @@ static const struct snd_soc_dai_link rockchip_dais[] = {
>   },
>  };
>  
> +static const struct snd_soc_dapm_route rockchip_sound_cdndp_routes[] = {
> + /* Output */
> + {"HDMI", NULL, "TX"},
> +};
> +
> +static const struct snd_soc_dapm_route rockchip_sound_da7219_routes[] = {
> + /* Output */
> + {"Headphones", NULL, "HPL"},
> + {"Headphones", NULL, "HPR"},
> +
> + /* Input */
> + {"MIC", NULL, "Headset Mic"},
> +};
> +
> +static const struct snd_soc_dapm_route rockchip_sound_dmic_routes[] = {
> + /* Input */
> + {"Dmic", NULL, "Int Mic"},

Should be "DMic" as in dmic_dapm_widgets of the dmic codec driver.

This route is also new and would probably be better added in a
separate patch.

> +};
> +
> +static const struct snd_soc_dapm_route rockchip_sound_max98357a_routes[] = {
> + /* Output */
> + {"Speakers", NULL, "Speaker"},
> +};
> +
> +static const struct snd_soc_dapm_route rockchip_sound_rt5514_routes[] = {
> + /* Input */
> + {"DMIC1L", NULL, "Int Mic"},
> + {"DMIC1R", NULL, "Int Mic"},
> +};
> +
> +struct rockchip_sound_route {
> + const struct snd_soc_dapm_route *routes;
> + int num_routes;
> +};
> +
> +static const struct rockchip_sound_route rockchip_routes[] = {
> + [DAILINK_CDNDP] = {
> + .routes = rockchip_sound_cdndp_routes,
> + .num_routes = ARRAY_SIZE(rockchip_sound_cdndp_routes),
> + },
> + [DAILINK_DA7219] = {
> + .routes = rockchip_sound_da7219_routes,
> + .num_routes = ARRAY_SIZE(rockchip_sound_da7219_routes),
> + },
> + [DAILINK_DMIC] = {
> + .routes = rockchip_sound_dmic_routes,
> + .num_routes = ARRAY_SIZE(rockchip_sound_dmic_routes),
> + },
> + [DAILINK_MAX98357A] = {
> + .routes = rockchip_sound_max98357a_routes,
> + .num_routes = ARRAY_SIZE(rockchip_sound_max98357a_routes),
> + },
> + [DAILINK_RT5514] = {
> + .routes = rockchip_sound_rt5514_routes,
> + .num_routes = ARRAY_SIZE(rockchip_sound_rt5514_routes),
> + },
> + [DAILINK_RT5514_DSP] = {},
> +};
> +
>  static int rockchip_sound_codec_node_match(struct device_node *np_codec)
>  {
>   int i;
> @@ -408,6 +455,7 @@ static int rockchip_sound_of_parse_dais(struct device 
> *dev,
>   struct device_node *np_cpu, *np_cpu0, *np_cpu1;
>   struct device_node *np_codec;
>   struct snd_soc_dai_link *dai;
> + struct snd_soc_dapm_route *routes;
>   int i, index;
>  
>   card->dai_link = devm_kzalloc(dev, sizeof(rockchip_dais),
> @@ -415,9 +463,16 @@ static int rockchip_sound_of_parse_dais(struct device 
> *dev,
>   if (!card->dai_link)
>   return -ENOMEM;
>  
> + routes = devm_kzalloc(dev, sizeof(rockchip_routes),
>

[PATCH] staging: lustre: lnet: Replace list_for_each with list_for_each_entry

2017-09-15 Thread Haneen Mohammed
Replace use of the combination of list_for_each and list_entry
with list_for_each_entry to simplify the code and remove variables
that are used only in list_for_each.
Issue found and corrected using Coccinelle script:

@r@
expression head, member, e;
type T1, T2, T3;
iterator name list_for_each, list_for_each_entry;
identifier pos, var;
@@

-T1 *pos;
...when!=pos=e;

-list_for_each(pos, head)
+list_for_each_entry(var, head, member)
{
...when!=pos=e;
   when!=T3 *var;
-var = list_entry(pos, T2, member);
...when!=pos=e;
}
...when!=pos=e;

Signed-off-by: Haneen Mohammed 
---
 drivers/staging/lustre/lnet/lnet/router.c | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/lustre/lnet/lnet/router.c 
b/drivers/staging/lustre/lnet/lnet/router.c
index 3df101b..b8eba33 100644
--- a/drivers/staging/lustre/lnet/lnet/router.c
+++ b/drivers/staging/lustre/lnet/lnet/router.c
@@ -222,15 +222,12 @@ struct lnet_remotenet *
 lnet_find_net_locked(__u32 net)
 {
struct lnet_remotenet *rnet;
-   struct list_head *tmp;
struct list_head *rn_list;
 
LASSERT(!the_lnet.ln_shutdown);
 
rn_list = lnet_net2rnethash(net);
-   list_for_each(tmp, rn_list) {
-   rnet = list_entry(tmp, struct lnet_remotenet, lrn_list);
-
+   list_for_each_entry(rnet, rn_list, lrn_list) {
if (rnet->lrn_net == net)
return rnet;
}
@@ -243,7 +240,6 @@ static void lnet_shuffle_seed(void)
__u32 lnd_type, seed[2];
struct timespec64 ts;
struct lnet_ni *ni;
-   struct list_head *tmp;
 
if (seeded)
return;
@@ -254,8 +250,7 @@ static void lnet_shuffle_seed(void)
 * Nodes with small feet have little entropy
 * the NID for this node gives the most entropy in the low bits
 */
-   list_for_each(tmp, &the_lnet.ln_nis) {
-   ni = list_entry(tmp, struct lnet_ni, ni_list);
+   list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
lnd_type = LNET_NETTYP(LNET_NIDNET(ni->ni_nid));
 
if (lnd_type != LOLND)
-- 
2.7.4



[PATCH 0/1] acpi: unbreak ACPI_HANDLE(), encapsulate fwnode_operations

2017-09-15 Thread john . hubbard
From: John Hubbard 

Hi everyone,

I really don't know for sure which fix is going to be preferred--the
following patch, or just an obvious one-line fix that changes
DECLARE_ACPI_FWNODE_OPS() so that it invokes EXPORT_SYMBOL, instead of
EXPORT_SYMBOL_GPL. I explained the reasoning in PATCH 1/1, anyway, so
please see what you think.

John Hubbard (1):
  acpi: unbreak ACPI_HANDLE(), encapsulate fwnode_operations

 drivers/acpi/property.c | 13 +
 include/acpi/acpi_bus.h | 18 --
 2 files changed, 17 insertions(+), 14 deletions(-)

-- 
2.14.1



[PATCH 1/1] acpi: unbreak ACPI_HANDLE(), encapsulate fwnode_operations

2017-09-15 Thread john . hubbard
From: John Hubbard 

Due to commit db3e50f3234b ("device property: Get rid of struct
fwnode_handle type field"), ACPI_HANDLE() inadvertently became
a GPL-only call. The call path that led to that was:

ACPI_HANDLE()
ACPI_COMPANION()
to_acpi_device_node()
is_acpi_device_node()
acpi_device_fwnode_ops
DECLARE_ACPI_FWNODE_OPS(acpi_device_fwnode_ops);

...and the new DECLARE_ACPI_FWNODE_OPS() includes
EXPORT_SYMBOL_GPL, whereas previously it was a static struct.

In order to avoid changing any of that, let's instead provide ever
so slightly better encapsulation of those struct fwnode_operations
instances. Those do not really need to be directly used in
inline function calls in header files. Simply moving two small
functions (is_acpi_device_node and is_acpi_data_node) out of
acpi_bus.h, and into a .c file, does that.

That leaves the internals of struct fwnode_operations as GPL-only
(which I think was the intent all along), but un-breaks any driver
code out there that relies on the ACPI subsystem's being (historically)
an EXPORT_SYMBOL-usable system. By that, I mean, ACPI_HANDLE() and
other basic ACPI calls were non-GPL-protected.

Also, while I'm there, remove a tiny bit of redundancy that was missed
in the earlier commit, by having is_acpi_node() use the other two
routines, instead of checking fwnode directly.

Signed-off-by: John Hubbard 
---
 drivers/acpi/property.c | 13 +
 include/acpi/acpi_bus.h | 18 --
 2 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index c1c216163de3..1e3c2517a1ac 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -1293,3 +1293,16 @@ static int acpi_fwnode_graph_parse_endpoint(const struct 
fwnode_handle *fwnode,
 DECLARE_ACPI_FWNODE_OPS(acpi_device_fwnode_ops);
 DECLARE_ACPI_FWNODE_OPS(acpi_data_fwnode_ops);
 const struct fwnode_operations acpi_static_fwnode_ops;
+
+bool is_acpi_device_node(const struct fwnode_handle *fwnode)
+{
+   return !IS_ERR_OR_NULL(fwnode) &&
+   fwnode->ops == &acpi_device_fwnode_ops;
+}
+EXPORT_SYMBOL(is_acpi_device_node);
+
+bool is_acpi_data_node(const struct fwnode_handle *fwnode)
+{
+   return !IS_ERR_OR_NULL(fwnode) && fwnode->ops == &acpi_data_fwnode_ops;
+}
+EXPORT_SYMBOL(is_acpi_data_node);
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index dedf9d789166..fa1505292f6c 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -399,17 +399,12 @@ extern const struct fwnode_operations 
acpi_device_fwnode_ops;
 extern const struct fwnode_operations acpi_data_fwnode_ops;
 extern const struct fwnode_operations acpi_static_fwnode_ops;
 
+bool is_acpi_device_node(const struct fwnode_handle *fwnode);
+bool is_acpi_data_node(const struct fwnode_handle *fwnode);
+
 static inline bool is_acpi_node(const struct fwnode_handle *fwnode)
 {
-   return !IS_ERR_OR_NULL(fwnode) &&
-   (fwnode->ops == &acpi_device_fwnode_ops
-|| fwnode->ops == &acpi_data_fwnode_ops);
-}
-
-static inline bool is_acpi_device_node(const struct fwnode_handle *fwnode)
-{
-   return !IS_ERR_OR_NULL(fwnode) &&
-   fwnode->ops == &acpi_device_fwnode_ops;
+   return (is_acpi_device_node(fwnode) || is_acpi_data_node(fwnode));
 }
 
 #define to_acpi_device_node(__fwnode)  \
@@ -422,11 +417,6 @@ static inline bool is_acpi_device_node(const struct 
fwnode_handle *fwnode)
NULL;   \
})
 
-static inline bool is_acpi_data_node(const struct fwnode_handle *fwnode)
-{
-   return !IS_ERR_OR_NULL(fwnode) && fwnode->ops == &acpi_data_fwnode_ops;
-}
-
 #define to_acpi_data_node(__fwnode)\
({  \
typeof(__fwnode) __to_acpi_data_node_fwnode = __fwnode; \
-- 
2.14.1



Re: [PATCH 5/7] Support new Alps device that name is T4

2017-09-15 Thread Jiri Kosina
On Tue, 12 Sep 2017, Masaki Ota wrote:

> From: Masaki Ota 
> -Add T4 device code and Product ID
> -This device is used on HP EliteBook 1000 series and Zbook Stduio
[ ... snip ... ]
> Signed-off-by: Masaki Ota 
> +static int t4_read_write_register(struct hid_device *hdev, u32 address,
> + u8 *read_val, u8 write_val, bool read_flag)
> +{
> + int ret;
> + u16 check_sum;
> + u8 *input;
> + u8 *readbuf;
> +
> + input = kzalloc(T4_FEATURE_REPORT_LEN, GFP_KERNEL);
> + if (!input)
> + return -ENOMEM;
> +
> + input[0] = T4_FEATURE_REPORT_ID;
> + if (read_flag) {
> + input[1] = T4_CMD_REGISTER_READ;
> + input[8] = 0x00;
> + } else {
> + input[1] = T4_CMD_REGISTER_WRITE;
> + input[8] = write_val;
> + }
> + put_unaligned_le32(address, input + 2);
> + input[6] = 1;
> + input[7] = 0;
> +
> + /* Calculate the checksum */
> + check_sum = t4_calc_check_sum(input, 1, 8);
> + input[9] = (u8)check_sum;
> + input[10] = (u8)(check_sum >> 8);
> + input[11] = 0;
> +
> + ret = hid_hw_raw_request(hdev, T4_FEATURE_REPORT_ID, input,
> + T4_FEATURE_REPORT_LEN,
> + HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
> +
> + if (ret < 0) {
> + dev_err(&hdev->dev, "failed to read command (%d)\n", ret);
> + goto exit;
> + }
> +
> + if (read_flag) {
> + readbuf = kzalloc(T4_FEATURE_REPORT_LEN, GFP_KERNEL);
> + if (!readbuf) {
> + ret = -ENOMEM;
> + goto exit;
> + }
> +
> + ret = hid_hw_raw_request(hdev, T4_FEATURE_REPORT_ID, readbuf,
> + T4_FEATURE_REPORT_LEN,
> + HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
> + if (ret < 0) {
> + dev_err(&hdev->dev, "failed read register (%d)\n", ret);
> + kfree(readbuf);
> + goto exit;
> + }
> +
> + if (*(u32 *)&readbuf[6] != address) {
> + dev_err(&hdev->dev, "read register address error 
> (%x,%x)\n",
> + *(u32 *)&readbuf[6], address);
> + kfree(readbuf);
> + goto exit;
> + }
> +
> + if (*(u16 *)&readbuf[10] != 1) {
> + dev_err(&hdev->dev, "read register size error (%x)\n",
> + *(u16 *)&readbuf[10]);
> + kfree(readbuf);
> + goto exit;
> + }
> +
> + check_sum = t4_calc_check_sum(readbuf, 6, 7);
> + if (*(u16 *)&readbuf[13] != check_sum) {
> + dev_err(&hdev->dev, "read register checksum error 
> (%x,%x)\n",
> + *(u16 *)&readbuf[13], check_sum);
> + kfree(readbuf);
> + goto exit;
> + }
> +
> + *read_val = readbuf[12];
> +
> + kfree(readbuf);

You have a lot of

kfree(readbuf);
goto exit;

duplicates here, and you're freeing the buffer before returning anyway in 
all cases, so it'd make sense to introduce another label (say 
exit_readbuf) before the exit one, and free it there in a common exit 
path.

[ ... snip ... ]
> +static int t4_raw_event(struct alps_dev *hdata, u8 *data, int size)
> +{
> + unsigned int x, y, z;
> + int i;
> + struct t4_input_report *p_report = (struct t4_input_report *)data;
> +
> + if (!data)
> + return 0;
> + for (i = 0; i < hdata->max_fingers; i++) {
> + x = p_report->contact[i].x_hi << 8 | p_report->contact[i].x_lo;
> + y = p_report->contact[i].y_hi << 8 | p_report->contact[i].y_lo;
> + y = hdata->y_max - y + hdata->y_min;
> + z = (p_report->contact[i].palm < 0x80 &&
> + p_report->contact[i].palm > 0) * 62;
> + if (x == 0x) {
> + x = 0;
> + y = 0;
> + z = 0;
> + }
> + input_mt_slot(hdata->input, i);
> +
> + input_mt_report_slot_state(hdata->input,
> + MT_TOOL_FINGER, z != 0);
> +
> + if (!z)
> + continue;
> +
> + input_report_abs(hdata->input, ABS_MT_POSITION_X, x);
> + input_report_abs(hdata->input, ABS_MT_POSITION_Y, y);
> + input_report_abs(hdata->input, ABS_MT_PRESSURE, z);
> + }
> + input_mt_sync_frame(hdata->input);
> +
> + input_report_key(hdata->input, BTN_LEFT,p_report->button);

Extra tab here?

> -static int alps_post_resume(struct hid_device *hdev)
> +static int __maybe_unused alps_post_reset(struct hid_device *hdev)

Do we really need the __maybe_unused annotation here? Why not just hide 
the whole  post-reset callback handling into a #ifdef CONFIG_PM block?

Thanks,

-- 
J

Re: [PATCH] Support new Alps HID Touchpad device

2017-09-15 Thread Jiri Kosina
On Tue, 12 Sep 2017, Masaki Ota wrote:

> This is the patch for support new Alps HID Touchpad device.
> I submitted these patch before, but it was not completed.
> So I separate the patch to some parts and release it again. 

Hi,

I have a few minor comments -- as in the past, I'd like to ask for 
improved changelogs, so that they are up to our kernel standards. As you 
are a regular contributor, it's time to start getting things right :)

Namely:

- please be generally more verbose / detailed in your changelogs
- explain not only what changes are being done, but also why they are 
  being done (what is the motivation). As an example, patch #1 has this:

-To support Alps T4 device, clean up the source code
-Delete unnecessary structure

  Please briefly document the cleanups, and also document which structure 
  is being removed and why it is redundant
- you can drop the repeating "Minor changes in hid-alps.c for support new 
  Alps device" prefix for the patche subjects, as it doesn't really 
  provide any extra information
- pathces #4 and #5 do quite a substantial changes to the code, it'd be 
  nice to describe in a few sentnces what are the changes (what are the 
  specifics of the new protocol, etc)

Thanks a lot!

-- 
Jiri Kosina
SUSE Labs



Re: [PATCH v2 2/3] livepatch: add atomic replace

2017-09-15 Thread Greg KH
On Fri, Sep 15, 2017 at 05:46:58PM +0200, Petr Mladek wrote:
> On Thu 2017-09-14 08:31:24, Jason Baron wrote:
> > 
> > 
> > On 09/14/2017 06:32 AM, Petr Mladek wrote:
> > > On Tue 2017-09-12 23:47:32, Jason Baron wrote:
> > >>
> > >>
> > >> On 09/12/2017 01:35 AM, Petr Mladek wrote:
> > >>> On Mon 2017-09-11 23:46:28, Jason Baron wrote:
> >  On 09/11/2017 09:53 AM, Petr Mladek wrote:
> > > On Wed 2017-08-30 17:38:44, Jason Baron wrote:
> > >> diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
> > >> index 6004be3..21cecc5 100644
> > >> --- a/kernel/livepatch/core.c
> > >> +++ b/kernel/livepatch/core.c
> > >> @@ -600,13 +603,38 @@ static void klp_free_patch(struct klp_patch 
> > >> *patch)
> > >>  list_del(&patch->list);
> > >>  }
> > >>  
> > >> -static int klp_init_func(struct klp_object *obj, struct klp_func 
> > >> *func)
> > >> +void klp_patch_free_no_ops(struct klp_patch *patch)
> > >> +{
> > >> +struct klp_object *obj, *tmp_obj;
> > >> +struct klp_func *func, *tmp_func;
> > >> +
> > >> +klp_for_each_object(patch, obj) {
> > >> +list_for_each_entry_safe(func, tmp_func, 
> > >> &obj->func_list,
> > >> + func_entry) {
> > >> +list_del_init(&func->func_entry);
> > >> +kobject_put(&func->kobj);
> > >> +kfree(func->old_name);
> > >> +kfree(func);
> > >
> > > kobject_put() is asynchronous. The structure should be freed using
> > > the kobject release method.
> > >
> > > The question is how secure this should be. We might want to block
> > > other operations with the patch until all the release methods
> > > are called. But this might be tricky as there is not a single
> > > root kobject that would get destroyed at the end.
> > >
> > > A crazy solution would be to define a global atomic counter.
> > > It might get increased with each kobject_put() call and
> > > descreased in each release method. Then we could wait
> > > until it gets zero.
> > >
> > > It should be safe to wait with klp_mutex taken. Note that this
> > > is not possible with patch->kobj() where the "the enable"
> > > attribute takes the mutex as well, see
> > > enabled_store() in kernel/livepatch/core.c.
> > 
> >  Thanks for pointing this out - it looks like the livepatch code uses
> >  wait_for_completion() with special kobj callbacks. Perhaps, there could
> >  be a nop callback, but I'd have to look at this more closely...
> > >>>
> > >>> The completion is usable for the root kobject but you do not free
> > >>> it here. It might be pretty complicated if you need separate
> > >>> completion for all the freed kobjects.
> > >>>
> > >>> A solution might be a global atomic counter and a waitqueue.
> > >>> Feel free to ask for more details.
> > >>>
> > >>
> > >> So the issue is that the user might access some of the klp_* data
> > >> structures via /sysfs after we have already freed them?
> > > 
> > > yes
> > > 
> > >> if so, this seems to be a common kernel pattern:
> > >>
> > >> kobject_del(kobj);
> > >> kobject_put(kobj);
> > > 
> > > IMHO, this is used for other reason.
> > > 
> > > kobject_del() removes the object from the hierachy. Therefore
> > > it prevents new operations. But it does not wait for the exiting
> > > operations to finish. Therefore there still might be users that
> > > access the data even after this function finishes.
> > 
> > I looked into this further - and it does appear to wait until all
> > operations finish. In kernfs_drain() the code does:
> > 
> > wait_event(root->deactivate_waitq, atomic_read(&kn->active) ==
> > KN_DEACTIVATED_BIAS);
> > 
> > The call stack is:
> > 
> > kobject_del()
> >  sysfs_remove_dir()
> >   kernfs_remove()
> >__kernfs_remove()
> > kernfs_drain()
> > 
> > And __kernfs_remove() has already done a 'deactivate' prior:
> > 
> > /* prevent any new usage under @kn by deactivating all nodes */
> > 
> > pos = NULL;
> > 
> > while ((pos = kernfs_next_descendant_post(pos, kn)))
> > 
> >if (kernfs_active(pos))
> > 
> >atomic_add(KN_DEACTIVATED_BIAS, &pos->active);
> > 
> > 
> > So I *think* doing the kobject_del() first is sufficient. It may be
> > worth some better documented if that is the case...
> 
> Sigh, I am confused. Your arguments look convincing. But I still
> feel a fear. As I said, we had had a long discussion about this long
> time ago. Unfortunately, I do not remember all the details.
> 
> In each case, there is the following mentioned in
> Documentation/kobject.txt:
> 
> === cut ===
> Once you registered your kobject via kobject_add(), you must never use
> kfree() to free it directly. The only safe way is to use kobject_put(). It
> is good practice to always use kobject_put() after kobject_init() to avoid
> 

Re: [PATCH 5/5] usb: usb251xb: Add copyrights

2017-09-15 Thread Serge Semin
On Fri, Sep 15, 2017 at 04:53:13PM -0700, Greg KH  
wrote:
> On Sat, Sep 16, 2017 at 02:45:17AM +0300, Serge Semin wrote:
> > On Fri, Sep 15, 2017 at 04:40:28PM -0700, Greg KH 
> >  wrote:
> > > On Sat, Sep 16, 2017 at 02:31:13AM +0300, Serge Semin wrote:
> > > > Signed-off-by: Serge Semin 
> > > > ---
> > > >  drivers/usb/misc/usb251xb.c | 1 +
> > > >  1 file changed, 1 insertions(+), 0 deletion(-)
> > > 
> > > I can't take patches without any changelog text, sorry.
> > > 
> > 
> > I'll merge it into the previous patch then. There is nothing to 
> > changeloging here. 
> > 
> > > > 
> > > > diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c
> > > > index 1d47acd09..43afa04ad 100644
> > > > --- a/drivers/usb/misc/usb251xb.c
> > > > +++ b/drivers/usb/misc/usb251xb.c
> > > > @@ -3,6 +3,7 @@
> > > >   * Configuration via SMBus.
> > > >   *
> > > >   * Copyright (c) 2017 SKIDATA AG
> > > > + * Copyright (c) 2017 T-platforms
> > > 
> > > I don't see the connection between a random company, and a random
> > > gmail.com email address.  Please explain :)
> > 
> > Why do you see gmail.com only? I cc-ed this patchset to my work email:
> > sergey.se...@t-platforms.ru
> > Do I really need to send it from my work e-mail? I have met such rule 
> > before.
> 
> The authorship of these patches are coming from a gmail.com address, how
> do I know what that relates to some random email you cc: on the patch :)
> 
> thanks,
> 
> greg k-h

Does it really matter? I could create any domain and add some random company
as copyright. How would you know the copyrighted company is real then? The
only way would be just google it. That's it. But still the site can be faked
if it is really necessary.
I thought these things are a matter of trust. I submitted a patchset from my
personal e-mail, but created it while working for the company. It's highly
possible, that my personal email is going to be mine for much longer time, then
I'll be working in the company. In this case, the better way to declare it as
primary email, instead of the company one, so to have a longer support. Isn't 
it?
Why would I need to fake a copyrighted company anyway?

-Sergey



Re: [PATCH 1/5] usb: usb251xb: Add USB2517/i hub support

2017-09-15 Thread Serge Semin
On Fri, Sep 15, 2017 at 04:45:14PM -0700, Greg KH  
wrote:
> On Sat, Sep 16, 2017 at 02:31:09AM +0300, Serge Semin wrote:
> > USB2517i hubs are very like USB251xb devices series. They have almost
> > the same configuration registers space except number of ports, led
> > configurations and lack of battery settings. All these peculiarities
> > are reflected in this patch.
> 
> Please add one type of feature at a time per patch.  That makes it
> easier to review and ensure you got it right.
> 
> thanks,
> 
> greg k-h

Ok. The patch isn't that big though.

Regards,
-Sergey



Re: [PATCH 5/5] usb: usb251xb: Add copyrights

2017-09-15 Thread Greg KH
On Sat, Sep 16, 2017 at 02:45:17AM +0300, Serge Semin wrote:
> On Fri, Sep 15, 2017 at 04:40:28PM -0700, Greg KH 
>  wrote:
> > On Sat, Sep 16, 2017 at 02:31:13AM +0300, Serge Semin wrote:
> > > Signed-off-by: Serge Semin 
> > > ---
> > >  drivers/usb/misc/usb251xb.c | 1 +
> > >  1 file changed, 1 insertions(+), 0 deletion(-)
> > 
> > I can't take patches without any changelog text, sorry.
> > 
> 
> I'll merge it into the previous patch then. There is nothing to changeloging 
> here. 
> 
> > > 
> > > diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c
> > > index 1d47acd09..43afa04ad 100644
> > > --- a/drivers/usb/misc/usb251xb.c
> > > +++ b/drivers/usb/misc/usb251xb.c
> > > @@ -3,6 +3,7 @@
> > >   * Configuration via SMBus.
> > >   *
> > >   * Copyright (c) 2017 SKIDATA AG
> > > + * Copyright (c) 2017 T-platforms
> > 
> > I don't see the connection between a random company, and a random
> > gmail.com email address.  Please explain :)
> 
> Why do you see gmail.com only? I cc-ed this patchset to my work email:
> sergey.se...@t-platforms.ru
> Do I really need to send it from my work e-mail? I have met such rule before.

The authorship of these patches are coming from a gmail.com address, how
do I know what that relates to some random email you cc: on the patch :)

thanks,

greg k-h


Re: [PATCH V5 0/4] Add Broadcom STB USB phy driver

2017-09-15 Thread Florian Fainelli
On September 4, 2017 11:11:47 PM PDT, Kishon Vijay Abraham I  
wrote:
>Florian,
>
>On Saturday 02 September 2017 07:46 AM, Florian Fainelli wrote:
>> 
>> 
>> On 08/25/2017 10:51 AM, Al Cooper wrote:
>>> Add a new USB Phy driver for Broadcom STB SoCs. This driver
>>> supports Broadcom STB ARM SoCs. This driver in
>>> combination with the Broadcom STB ohci, ehci and xhci
>>> drivers will enable USB1.1, USB2.0 and USB3.0 support.
>>> This Phy driver also supports the Broadcom BDC gadget
>>> driver.
>> 
>> Thanks Al! Kishon, feel free to merge everything through your tree
>there
>> should not be any conflicts with drivers/soc/bcm/brcmstb/common.c and
>> include/linux/soc/brcmstb/brcmstb.h.
>
>I'll start merging once 4.14 -rc1 is tagged.

OK, does not that mean we will be missing this driver in 4.14? I suppose that's 
fine. Thanks!
Hi Kishon,
-- 
Florian


[git pull] drm amd fixes for 4.14-rc1

2017-09-15 Thread Dave Airlie
Hi Linus,

Just had a single AMD fixes pull for Alex for rc1.

Dave.

The following changes since commit 7846b12fe0b5feab5446d892f41b5140c1419109:

  Merge branch 'drm-vmwgfx-next' of
git://people.freedesktop.org/~syeh/repos_linux into drm-next
(2017-08-29 10:38:14 +1000)

are available in the git repository at:

  git://people.freedesktop.org/~airlied/linux tags/drm-fixes-for-v4.14-rc1

for you to fetch changes up to 47e0cd6b1dbbbff7591fe7eecc20bac5ca674351:

  Merge branch 'drm-next-4.14' of
git://people.freedesktop.org/~agd5f/linux into drm-next (2017-09-13
14:34:11 +1000)


amd fixes pull


Alex Deucher (5):
  drm/amdgpu/gfx8: fix spelling typo in mqd allocation
  drm/amdgpu: add automatic per asic settings for gart_size
  drm/amdgpu: refine default gart size
  drm/amdgpu: move default gart size setting into gmc modules
  drm/amdgpu: set sched_hw_submission higher for KIQ (v3)

Christian König (6):
  drm/amdgpu: fix and cleanup shadow handling
  drm/amdgpu: discard commands of killed processes
  drm/amdgpu: remove the GART copy hack
  drm/amdgpu: fix amdgpu_ttm_bind
  drm/amdgpu: inline amdgpu_ttm_do_bind again
  drm/amdgpu: revert "fix deadlock of reservation between cs and
gpu reset v2"

Christophe JAILLET (1):
  drm/amdgpu: check memory allocation failure

Colin Ian King (1):
  drm/amdgpu: remove duplicate return statement

Dave Airlie (1):
  Merge branch 'drm-next-4.14' of
git://people.freedesktop.org/~agd5f/linux into drm-next

Emily Deng (1):
  drm/amdgpu/virtual_dce: Virtual display doesn't support disable
vblank immediately

Evan Quan (2):
  drm/amd/powerplay: unhalt mec after loading
  drm/amd/powerplay: ACG frequency added in PPTable

Felix Kuehling (1):
  drm/amdgpu: Fix huge page updates with CPU

Monk Liu (2):
  drm/ttm: fix missing inc bo_count
  drm/ttm:fix wrong decoding of bo_count

Roger He (1):
  drm/amd/amdgpu: fix BANK_SELECT on Vega10 (v2)

 drivers/gpu/drm/amd/amdgpu/amdgpu.h|  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c  |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c |  7 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 10 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c|  4 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c   | 12 
 drivers/gpu/drm/amd/amdgpu/amdgpu_gart.h   |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c| 14 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c|  5 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 46 ++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c   | 16 +++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c| 76 --
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h|  4 --
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 46 ++---
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c  | 12 ++--
 drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c   |  5 +-
 drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c  | 19 +-
 drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c  | 22 ++-
 drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c  | 21 +-
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c  | 16 -
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c|  5 +-
 drivers/gpu/drm/amd/include/vi_structs.h   |  4 +-
 drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c | 11 +++-
 drivers/gpu/drm/amd/powerplay/inc/smu9_driver_if.h |  6 +-
 drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c |  3 +-
 drivers/gpu/drm/amd/scheduler/gpu_scheduler.c  | 23 +--
 drivers/gpu/drm/ttm/ttm_bo.c   |  4 +-
 drivers/gpu/drm/ttm/ttm_bo_util.c  |  1 +
 28 files changed, 236 insertions(+), 160 deletions(-)


Re: [PATCH 1/5] usb: usb251xb: Add USB2517/i hub support

2017-09-15 Thread Greg KH
On Sat, Sep 16, 2017 at 02:31:09AM +0300, Serge Semin wrote:
> USB2517i hubs are very like USB251xb devices series. They have almost
> the same configuration registers space except number of ports, led
> configurations and lack of battery settings. All these peculiarities
> are reflected in this patch.

Please add one type of feature at a time per patch.  That makes it
easier to review and ensure you got it right.

thanks,

greg k-h


Re: [PATCH 5/5] usb: usb251xb: Add copyrights

2017-09-15 Thread Serge Semin
On Fri, Sep 15, 2017 at 04:40:28PM -0700, Greg KH  
wrote:
> On Sat, Sep 16, 2017 at 02:31:13AM +0300, Serge Semin wrote:
> > Signed-off-by: Serge Semin 
> > ---
> >  drivers/usb/misc/usb251xb.c | 1 +
> >  1 file changed, 1 insertions(+), 0 deletion(-)
> 
> I can't take patches without any changelog text, sorry.
> 

I'll merge it into the previous patch then. There is nothing to changeloging 
here. 

> > 
> > diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c
> > index 1d47acd09..43afa04ad 100644
> > --- a/drivers/usb/misc/usb251xb.c
> > +++ b/drivers/usb/misc/usb251xb.c
> > @@ -3,6 +3,7 @@
> >   * Configuration via SMBus.
> >   *
> >   * Copyright (c) 2017 SKIDATA AG
> > + * Copyright (c) 2017 T-platforms
> 
> I don't see the connection between a random company, and a random
> gmail.com email address.  Please explain :)

Why do you see gmail.com only? I cc-ed this patchset to my work email:
sergey.se...@t-platforms.ru
Do I really need to send it from my work e-mail? I have met such rule before.

> 
> thanks,
> 
> greg k-h


Re: [PATCH] vfs: introduce UMOUNT_WAIT which waits for umount completion

2017-09-15 Thread Al Viro
On Fri, Sep 15, 2017 at 04:29:11PM -0700, Jaegeuk Kim wrote:

> The mntput() in delayed_fput() is the last function call. So before that 
> moment,
> sys_umount() may see mnt_get_count() as 2, so it avoids EBUSY condition. I'm 
> not
> sure why it check over 2 tho.

Because it has just grabbed a reference itself, in addition to the one that 
keeps
the damn thing alive (due to being mounted).  So it bloody well should have
triggered -EBUSY, if they refer to the same vfsmount.


Re: [PATCH 5/5] usb: usb251xb: Add copyrights

2017-09-15 Thread Greg KH
On Fri, Sep 15, 2017 at 04:40:28PM -0700, Greg KH wrote:
> On Sat, Sep 16, 2017 at 02:31:13AM +0300, Serge Semin wrote:
> > Signed-off-by: Serge Semin 
> > ---
> >  drivers/usb/misc/usb251xb.c | 1 +
> >  1 file changed, 1 insertions(+), 0 deletion(-)
> 
> I can't take patches without any changelog text, sorry.
> 
> > 
> > diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c
> > index 1d47acd09..43afa04ad 100644
> > --- a/drivers/usb/misc/usb251xb.c
> > +++ b/drivers/usb/misc/usb251xb.c
> > @@ -3,6 +3,7 @@
> >   * Configuration via SMBus.
> >   *
> >   * Copyright (c) 2017 SKIDATA AG
> > + * Copyright (c) 2017 T-platforms
> 
> I don't see the connection between a random company, and a random
> gmail.com email address.  Please explain :)

Also, based on the changes in this series, I fail to see how you could
even claim copyright on the entire file.  Please explain that as well
when you resend this patch.

Note, I'm not a lawyer, and this isn't legal advice, please contact your
company's lawyers, they know this type of thing, and now the normal
rules for claiming copyright of a whole file.  They also know that
copyright notices in files don't mean anything, but lawyers love to
cargo-cult things more than any other profession :)

thanks,

greg k-h


Re: Detecting page cache trashing state

2017-09-15 Thread Taras Kondratiuk
Quoting vcap...@pengaru.com (2017-09-15 14:20:28)
> On Fri, Sep 15, 2017 at 04:36:19PM +0200, Michal Hocko wrote:
> > On Thu 14-09-17 17:16:27, Taras Kondratiuk wrote:
> > > Hi
> > > 
> > > In our devices under low memory conditions we often get into a trashing
> > > state when system spends most of the time re-reading pages of .text
> > > sections from a file system (squashfs in our case). Working set doesn't
> > > fit into available page cache, so it is expected. The issue is that
> > > OOM killer doesn't get triggered because there is still memory for
> > > reclaiming. System may stuck in this state for a quite some time and
> > > usually dies because of watchdogs.
> > > 
> > > We are trying to detect such trashing state early to take some
> > > preventive actions. It should be a pretty common issue, but for now we
> > > haven't find any existing VM/IO statistics that can reliably detect such
> > > state.
> > > 
> > > Most of metrics provide absolute values: number/rate of page faults,
> > > rate of IO operations, number of stolen pages, etc. For a specific
> > > device configuration we can determine threshold values for those
> > > parameters that will detect trashing state, but it is not feasible for
> > > hundreds of device configurations.
> > > 
> > > We are looking for some relative metric like "percent of CPU time spent
> > > handling major page faults". With such relative metric we could use a
> > > common threshold across all devices. For now we have added such metric
> > > to /proc/stat in our kernel, but we would like to find some mechanism
> > > available in upstream kernel.
> > > 
> > > Has somebody faced similar issue? How are you solving it?
> > 
> > Yes this is a pain point for a _long_ time. And we still do not have a
> > good answer upstream. Johannes has been playing in this area [1].
> > The main problem is that our OOM detection logic is based on the ability
> > to reclaim memory to allocate new memory. And that is pretty much true
> > for the pagecache when you are trashing. So we do not know that
> > basically whole time is spent refaulting the memory back and forth.
> > We do have some refault stats for the page cache but that is not
> > integrated to the oom detection logic because this is really a
> > non-trivial problem to solve without triggering early oom killer
> > invocations.
> > 
> > [1] http://lkml.kernel.org/r/20170727153010.23347-1-han...@cmpxchg.org
> 
> For desktop users running without swap, couldn't we just provide a kernel
> setting which marks all executable pages as unevictable when first faulted
> in?  Then at least thrashing within the space occupied by executables and
> shared libraries before eventual OOM would be avoided, and only the
> remaining file-backed non-executable pages would be thrashable.
> 
> On my swapless laptops I'd much rather have OOM killer kick in immediately
> rather than wait for a few minutes of thrashing to pass while the bogged
> down system crawls through depleting what's left of technically reclaimable
> memory.  It's much improved on modern SSDs, but still annoying.

Usually a significant part of executable is used rarely or only once
during initialization. Pinning all executable pages forever will waste
a lot of memory.


Re: [PATCH 5/5] usb: usb251xb: Add copyrights

2017-09-15 Thread Greg KH
On Sat, Sep 16, 2017 at 02:31:13AM +0300, Serge Semin wrote:
> Signed-off-by: Serge Semin 
> ---
>  drivers/usb/misc/usb251xb.c | 1 +
>  1 file changed, 1 insertions(+), 0 deletion(-)

I can't take patches without any changelog text, sorry.

> 
> diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c
> index 1d47acd09..43afa04ad 100644
> --- a/drivers/usb/misc/usb251xb.c
> +++ b/drivers/usb/misc/usb251xb.c
> @@ -3,6 +3,7 @@
>   * Configuration via SMBus.
>   *
>   * Copyright (c) 2017 SKIDATA AG
> + * Copyright (c) 2017 T-platforms

I don't see the connection between a random company, and a random
gmail.com email address.  Please explain :)

thanks,

greg k-h


kernel crash using fbtft / SPI on Orange Pi zero board, armbian

2017-09-15 Thread jon
I am trying to use an LCD connected via SPI on an Orange Pi zero board.
It works, for a while, then crashes.

armbian forum thread here:
https://forum.armbian.com/index.php?/topic/5067-orange-pi-zero-fbtft-unreliable/


root@orangepizero:~# uname -a
Linux orangepizero 3.4.113-sun8i #12 SMP PREEMPT Fri Sep 15 00:26:14 CEST 2017 
armv7l armv7l armv7l GNU/Linux


The LCD initially works, but fbtft stops updating the LCD framebuffer
after a few mins use. The more frequent the framebuffer updates the
faster it is to lockup. 

In this case advmame is running pacman, works for <2mins.  advmame is
built from source on the ARM board itself.  This source and the LCD
module itself work without issues on Raspberry Pi boards.

dmesg shows the following:

[  113.076235] warning: process `advmame' used the deprecated sysctl system 
call with 8.1.2.
[  361.030206] INFO: task kworker/u:0:5 blocked for more than 120 seconds.
[  361.030258] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this 
message.
[  361.030303] kworker/u:0 D c061c3a4 0 5  2 0x
[  361.030452] [] (__schedule+0x574/0x7fc) from [] 
(schedule+0x90/0x94)
[  361.030540] [] (schedule+0x90/0x94) from [] 
(schedule_timeout+0x2c/0x2bc)
[  361.030629] [] (schedule_timeout+0x2c/0x2bc) from [] 
(wait_for_common+0x120/0x168)
[  361.030719] [] (wait_for_common+0x120/0x168) from [] 
(wait_for_completion+0x20/0x24)
[  361.030817] [] (wait_for_completion+0x20/0x24) from [] 
(sunxi_spi_work+0x748/0x88c)
[  361.030918] [] (sunxi_spi_work+0x748/0x88c) from [] 
(process_one_work+0x248/0x404)
[  361.031011] [] (process_one_work+0x248/0x404) from [] 
(worker_thread+0x1b4/0x2d0)
[  361.031105] [] (worker_thread+0x1b4/0x2d0) from [] 
(kthread+0x94/0xa0)
[  361.031201] [] (kthread+0x94/0xa0) from [] 
(kernel_thread_exit+0x0/0x8)
[  361.031273] INFO: task kworker/1:1:25 blocked for more than 120 seconds.
[  361.031313] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this 
message.
[  361.031355] kworker/1:1 D c061c3a4 025  2 0x
[  361.031466] [] (__schedule+0x574/0x7fc) from [] 
(schedule+0x90/0x94)
[  361.031551] [] (schedule+0x90/0x94) from [] 
(schedule_timeout+0x2c/0x2bc)
[  361.031637] [] (schedule_timeout+0x2c/0x2bc) from [] 
(wait_for_common+0x120/0x168)
[  361.031726] [] (wait_for_common+0x120/0x168) from [] 
(wait_for_completion+0x20/0x24)
[  361.031816] [] (wait_for_completion+0x20/0x24) from [] 
(spi_sync+0x84/0xa0)
[  361.031958] [] (spi_sync+0x84/0xa0) from [] 
(fbtft_write_spi+0xf0/0x104 [fbtft])
[  361.032136] [] (fbtft_write_spi+0xf0/0x104 [fbtft]) from 
[] (fbtft_write_vmem16_bus8+0x11c/0x138 [fbtft])
[  361.032295] [] (fbtft_write_vmem16_bus8+0x11c/0x138 [fbtft]) from 
[] (fbtft_update_display+0x150/0x2fc [fbtft])
[  361.032445] [] (fbtft_update_display+0x150/0x2fc [fbtft]) from 
[] (fbtft_deferred_io+0x110/0x11c [fbtft])
[  361.032573] [] (fbtft_deferred_io+0x110/0x11c [fbtft]) from 
[] (fb_deferred_io_work+0x84/0xcc)
[  361.032670] [] (fb_deferred_io_work+0x84/0xcc) from [] 
(process_one_work+0x248/0x404)
[  361.032760] [] (process_one_work+0x248/0x404) from [] 
(worker_thread+0x1b4/0x2d0)
[  361.032850] [] (worker_thread+0x1b4/0x2d0) from [] 
(kthread+0x94/0xa0)
[  361.032940] [] (kthread+0x94/0xa0) from [] 
(kernel_thread_exit+0x0/0x8)
[  361.033053] INFO: task advmame:1561 blocked for more than 120 seconds.
[  361.033093] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this 
message.
[  361.033135] advmame D c061c3a4 0  1561   1517 0x
[  361.033246] [] (__schedule+0x574/0x7fc) from [] 
(schedule+0x90/0x94)
[  361.03] [] (schedule+0x90/0x94) from [] 
(schedule_preempt_disabled+0x30/0x40)
[  361.033425] [] (schedule_preempt_disabled+0x30/0x40) from 
[] (__mutex_lock_slowpath+0x160/0x1a8)
[  361.033518] [] (__mutex_lock_slowpath+0x160/0x1a8) from 
[] (mutex_lock+0x64/0x7c)
[  361.033607] [] (mutex_lock+0x64/0x7c) from [] 
(fb_deferred_io_mkwrite+0x2c/0xbc)
[  361.033699] [] (fb_deferred_io_mkwrite+0x2c/0xbc) from 
[] (do_wp_page+0x224/0x7a4)
[  361.033789] [] (do_wp_page+0x224/0x7a4) from [] 
(handle_pte_fault+0x7b0/0x838)
[  361.033874] [] (handle_pte_fault+0x7b0/0x838) from [] 
(handle_mm_fault+0xf8/0x134)
[  361.033961] [] (handle_mm_fault+0xf8/0x134) from [] 
(do_page_fault+0x11c/0x344)
[  361.034047] [] (do_page_fault+0x11c/0x344) from [] 
(do_DataAbort+0x44/0xa8)
[  361.034132] [] (do_DataAbort+0x44/0xa8) from [] 
(__dabt_usr+0x38/0x40)
[  361.034184] Exception stack(0xd719ffb0 to 0xd719fff8)
[  361.034237] ffa0:   
b5aa3000 0445f912
[  361.034307] ffc0:   b5aa3000  0001 000b 
f800 001f
[  361.034374] ffe0: 0120 bef33fc8 fe00 0003d094 6830 

I am not a linux kernel hacker, just posting here to draw attention to
it :-) 

Thanks,
Jon





[PATCH v2 1/2] mmc: sdhci-msm: Utilize bulk clock API

2017-09-15 Thread Bjorn Andersson
By stuffing the runtime controlled clocks into a clk_bulk_data array we
can utilize the newly introduced bulk clock operations and clean up the
error paths. This allow us to handle additional clocks in subsequent
patch, without the added complexity.

Cc: Ritesh Harjani 
Signed-off-by: Bjorn Andersson 
---

Changes since v1:
- Dropped "clk" and "pclk" from sdhci_msm_host

 drivers/mmc/host/sdhci-msm.c | 80 +++-
 1 file changed, 34 insertions(+), 46 deletions(-)

diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
index 9d601dc0d646..b9ca1b1ef9a8 100644
--- a/drivers/mmc/host/sdhci-msm.c
+++ b/drivers/mmc/host/sdhci-msm.c
@@ -127,10 +127,9 @@ struct sdhci_msm_host {
struct platform_device *pdev;
void __iomem *core_mem; /* MSM SDCC mapped address */
int pwr_irq;/* power irq */
-   struct clk *clk;/* main SD/MMC bus clock */
-   struct clk *pclk;   /* SDHC peripheral bus clock */
struct clk *bus_clk;/* SDHC bus voter clock */
struct clk *xo_clk; /* TCXO clk needed for FLL feature of cm_dll*/
+   struct clk_bulk_data bulk_clks[2]; /* core, iface clocks */
unsigned long clk_rate;
struct mmc_host *mmc;
bool use_14lpp_dll_reset;
@@ -164,10 +163,11 @@ static void msm_set_clock_rate_for_bus_mode(struct 
sdhci_host *host,
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
struct mmc_ios curr_ios = host->mmc->ios;
+   struct clk *core_clk = msm_host->bulk_clks[0].clk;
int rc;
 
clock = msm_get_clock_rate_for_bus_mode(host, clock);
-   rc = clk_set_rate(msm_host->clk, clock);
+   rc = clk_set_rate(core_clk, clock);
if (rc) {
pr_err("%s: Failed to set clock at rate %u at timing %d\n",
   mmc_hostname(host->mmc), clock,
@@ -176,7 +176,7 @@ static void msm_set_clock_rate_for_bus_mode(struct 
sdhci_host *host,
}
msm_host->clk_rate = clock;
pr_debug("%s: Setting clock at rate %lu at timing %d\n",
-mmc_hostname(host->mmc), clk_get_rate(msm_host->clk),
+mmc_hostname(host->mmc), clk_get_rate(core_clk),
 curr_ios.timing);
 }
 
@@ -1032,8 +1032,9 @@ static unsigned int sdhci_msm_get_max_clock(struct 
sdhci_host *host)
 {
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
+   struct clk *core_clk = msm_host->bulk_clks[0].clk;
 
-   return clk_round_rate(msm_host->clk, ULONG_MAX);
+   return clk_round_rate(core_clk, ULONG_MAX);
 }
 
 static unsigned int sdhci_msm_get_min_clock(struct sdhci_host *host)
@@ -1124,6 +1125,7 @@ static int sdhci_msm_probe(struct platform_device *pdev)
struct sdhci_pltfm_host *pltfm_host;
struct sdhci_msm_host *msm_host;
struct resource *core_memres;
+   struct clk *clk;
int ret;
u16 host_version, core_minor;
u32 core_version, config;
@@ -1159,24 +1161,32 @@ static int sdhci_msm_probe(struct platform_device *pdev)
}
 
/* Setup main peripheral bus clock */
-   msm_host->pclk = devm_clk_get(&pdev->dev, "iface");
-   if (IS_ERR(msm_host->pclk)) {
-   ret = PTR_ERR(msm_host->pclk);
+   clk = devm_clk_get(&pdev->dev, "iface");
+   if (IS_ERR(clk)) {
+   ret = PTR_ERR(clk);
dev_err(&pdev->dev, "Peripheral clk setup failed (%d)\n", ret);
goto bus_clk_disable;
}
-
-   ret = clk_prepare_enable(msm_host->pclk);
-   if (ret)
-   goto bus_clk_disable;
+   msm_host->bulk_clks[1].clk = clk;
 
/* Setup SDC MMC clock */
-   msm_host->clk = devm_clk_get(&pdev->dev, "core");
-   if (IS_ERR(msm_host->clk)) {
-   ret = PTR_ERR(msm_host->clk);
+   clk = devm_clk_get(&pdev->dev, "core");
+   if (IS_ERR(clk)) {
+   ret = PTR_ERR(clk);
dev_err(&pdev->dev, "SDC MMC clk setup failed (%d)\n", ret);
-   goto pclk_disable;
+   goto bus_clk_disable;
}
+   msm_host->bulk_clks[0].clk = clk;
+
+   /* Vote for maximum clock rate for maximum performance */
+   ret = clk_set_rate(clk, INT_MAX);
+   if (ret)
+   dev_warn(&pdev->dev, "core clock boost failed\n");
+
+   ret = clk_bulk_prepare_enable(ARRAY_SIZE(msm_host->bulk_clks),
+ msm_host->bulk_clks);
+   if (ret)
+   goto bus_clk_disable;
 
/*
 * xo clock is needed for FLL feature of cm_dll.
@@ -1188,15 +1198,6 @@ static int sdhci_msm_probe(struct platform_device *pdev)
dev_warn(&pdev->dev, "TCXO clk not present (%d)\n", ret);
}
 
-   /* Vote for maximum clock rate for maximum performance */
-   ret = 

Re: [PATCH] [media] solo6x10: hide unused variable

2017-09-15 Thread Ismael Luceno
On 15/Sep/2017 21:52, Arnd Bergmann wrote:
> When building without CONFIG_GPIOLIB, we get a harmless
> warning about an unused variable:
> 
> drivers/media/pci/solo6x10/solo6x10-gpio.c: In function 'solo_gpio_init':
> drivers/media/pci/solo6x10/solo6x10-gpio.c:165:6: error: unused variable 
> 'ret' [-Werror=unused-variable]
> 
> This adds another #ifdef around the declaration.
> 
> Fixes: d3202d1981dc ("media: solo6x10: export hardware GPIO pins 8:31 to 
> gpiolib interface")
> Signed-off-by: Arnd Bergmann 
> ---
>  drivers/media/pci/solo6x10/solo6x10-gpio.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/media/pci/solo6x10/solo6x10-gpio.c 
> b/drivers/media/pci/solo6x10/solo6x10-gpio.c
> index 3d0d1aa2f6a8..7b4641a2cb84 100644
> --- a/drivers/media/pci/solo6x10/solo6x10-gpio.c
> +++ b/drivers/media/pci/solo6x10/solo6x10-gpio.c
> @@ -162,7 +162,9 @@ static void solo_gpiochip_set(struct gpio_chip *chip,
>  
>  int solo_gpio_init(struct solo_dev *solo_dev)
>  {
> +#ifdef CONFIG_GPIOLIB
>   int ret;
> +#endif
>  
>   solo_gpio_config(solo_dev);
>  #ifdef CONFIG_GPIOLIB
> -- 
> 2.9.0
> 

Signed-off-by: Ismael Luceno 


[PATCH v2 0/2] Support SDHCI on 8974pro devices

2017-09-15 Thread Bjorn Andersson
The calibration clocks for the delay circut should be enabled, as done in the
downstream kernel, in order for reset of the SDHCI not to fail on some Qualcomm
platforms (e.g. 8974pro). These patches makes it possible to reference these
clocks.

Bjorn Andersson (2):
  mmc: sdhci-msm: Utilize bulk clock API
  mmc: sdhci-msm: Enable delay circuit calibration clocks

 .../devicetree/bindings/mmc/sdhci-msm.txt  |  2 +
 drivers/mmc/host/sdhci-msm.c   | 90 +++---
 2 files changed, 46 insertions(+), 46 deletions(-)

-- 
2.12.0



[PATCH v2 2/2] mmc: sdhci-msm: Enable delay circuit calibration clocks

2017-09-15 Thread Bjorn Andersson
The delay circuit used to support HS400 is calibrated based on two
additional clocks. When these clocks are not available and
FF_CLK_SW_RST_DIS is not set in CORE_HC_MODE, reset might fail. But on
some platforms this doesn't work properly and below dump can be seen in
the kernel log.

  mmc0: Reset 0x1 never completed.
  mmc0: sdhci:  SDHCI REGISTER DUMP ===
  mmc0: sdhci: Sys addr:  0x | Version:  0x1102
  mmc0: sdhci: Blk size:  0x4000 | Blk cnt:  0x
  mmc0: sdhci: Argument:  0x | Trn mode: 0x
  mmc0: sdhci: Present:   0x01f8 | Host ctl: 0x
  mmc0: sdhci: Power: 0x | Blk gap:  0x
  mmc0: sdhci: Wake-up:   0x | Clock:0x0002
  mmc0: sdhci: Timeout:   0x | Int stat: 0x
  mmc0: sdhci: Int enab:  0x | Sig enab: 0x
  mmc0: sdhci: AC12 err:  0x | Slot int: 0x
  mmc0: sdhci: Caps:  0x742dc8b2 | Caps_1:   0x8007
  mmc0: sdhci: Cmd:   0x | Max curr: 0x
  mmc0: sdhci: Resp[0]:   0x | Resp[1]:  0x
  mmc0: sdhci: Resp[2]:   0x | Resp[3]:  0x
  mmc0: sdhci: Host ctl2: 0x
  mmc0: sdhci: 

Add support for the additional calibration clocks to allow these
platforms to be configured appropriately.

Cc: Venkat Gopalakrishnan 
Cc: Ritesh Harjani 
Signed-off-by: Bjorn Andersson 
---

Changes since v1:
- Add new clocks to DT binding

 Documentation/devicetree/bindings/mmc/sdhci-msm.txt |  2 ++
 drivers/mmc/host/sdhci-msm.c| 12 +++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/mmc/sdhci-msm.txt 
b/Documentation/devicetree/bindings/mmc/sdhci-msm.txt
index 0576264eab5e..5d9c3cd1bdaa 100644
--- a/Documentation/devicetree/bindings/mmc/sdhci-msm.txt
+++ b/Documentation/devicetree/bindings/mmc/sdhci-msm.txt
@@ -18,6 +18,8 @@ Required properties:
"core"  - SDC MMC clock (MCLK) (required)
"bus"   - SDCC bus voter clock (optional)
"xo"- TCXO clock (optional)
+   "cal"   - reference clock for RCLK delay calibration (optional)
+   "sleep" - sleep clock for RCLK delay calibration (optional)
 
 Example:
 
diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
index b9ca1b1ef9a8..ea330e8169dc 100644
--- a/drivers/mmc/host/sdhci-msm.c
+++ b/drivers/mmc/host/sdhci-msm.c
@@ -129,7 +129,7 @@ struct sdhci_msm_host {
int pwr_irq;/* power irq */
struct clk *bus_clk;/* SDHC bus voter clock */
struct clk *xo_clk; /* TCXO clk needed for FLL feature of cm_dll*/
-   struct clk_bulk_data bulk_clks[2]; /* core, iface clocks */
+   struct clk_bulk_data bulk_clks[4]; /* core, iface, cal, sleep clocks */
unsigned long clk_rate;
struct mmc_host *mmc;
bool use_14lpp_dll_reset;
@@ -1183,6 +1183,16 @@ static int sdhci_msm_probe(struct platform_device *pdev)
if (ret)
dev_warn(&pdev->dev, "core clock boost failed\n");
 
+   clk = devm_clk_get(&pdev->dev, "cal");
+   if (IS_ERR(clk))
+   clk = NULL;
+   msm_host->bulk_clks[2].clk = clk;
+
+   clk = devm_clk_get(&pdev->dev, "sleep");
+   if (IS_ERR(clk))
+   clk = NULL;
+   msm_host->bulk_clks[3].clk = clk;
+
ret = clk_bulk_prepare_enable(ARRAY_SIZE(msm_host->bulk_clks),
  msm_host->bulk_clks);
if (ret)
-- 
2.12.0



kernel crash using fbtft / SPI on Orange Pi zero board, armbian

2017-09-15 Thread jon
I am trying to use an LCD connected via SPI on an Orange Pi zero board.
It works, for a while, then crashes.

armbian forum thread here:
https://forum.armbian.com/index.php?/topic/5067-orange-pi-zero-fbtft-unreliable/


root@orangepizero:~# uname -a
Linux orangepizero 3.4.113-sun8i #12 SMP PREEMPT Fri Sep 15 00:26:14 CEST 2017 
armv7l armv7l armv7l GNU/Linux


The LCD initially works, but fbtft stops updating the LCD framebuffer
after a few mins use. The more frequent the framebuffer updates the
faster it is to lockup. 

In this case advmame is running pacman, works for <2mins.  advmame is
built from source on the ARM board itself.  This source and the LCD
module itself work without issues on Raspberry Pi boards.

dmesg shows the following:

[  113.076235] warning: process `advmame' used the deprecated sysctl system 
call with 8.1.2.
[  361.030206] INFO: task kworker/u:0:5 blocked for more than 120 seconds.
[  361.030258] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this 
message.
[  361.030303] kworker/u:0 D c061c3a4 0 5  2 0x
[  361.030452] [] (__schedule+0x574/0x7fc) from [] 
(schedule+0x90/0x94)
[  361.030540] [] (schedule+0x90/0x94) from [] 
(schedule_timeout+0x2c/0x2bc)
[  361.030629] [] (schedule_timeout+0x2c/0x2bc) from [] 
(wait_for_common+0x120/0x168)
[  361.030719] [] (wait_for_common+0x120/0x168) from [] 
(wait_for_completion+0x20/0x24)
[  361.030817] [] (wait_for_completion+0x20/0x24) from [] 
(sunxi_spi_work+0x748/0x88c)
[  361.030918] [] (sunxi_spi_work+0x748/0x88c) from [] 
(process_one_work+0x248/0x404)
[  361.031011] [] (process_one_work+0x248/0x404) from [] 
(worker_thread+0x1b4/0x2d0)
[  361.031105] [] (worker_thread+0x1b4/0x2d0) from [] 
(kthread+0x94/0xa0)
[  361.031201] [] (kthread+0x94/0xa0) from [] 
(kernel_thread_exit+0x0/0x8)
[  361.031273] INFO: task kworker/1:1:25 blocked for more than 120 seconds.
[  361.031313] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this 
message.
[  361.031355] kworker/1:1 D c061c3a4 025  2 0x
[  361.031466] [] (__schedule+0x574/0x7fc) from [] 
(schedule+0x90/0x94)
[  361.031551] [] (schedule+0x90/0x94) from [] 
(schedule_timeout+0x2c/0x2bc)
[  361.031637] [] (schedule_timeout+0x2c/0x2bc) from [] 
(wait_for_common+0x120/0x168)
[  361.031726] [] (wait_for_common+0x120/0x168) from [] 
(wait_for_completion+0x20/0x24)
[  361.031816] [] (wait_for_completion+0x20/0x24) from [] 
(spi_sync+0x84/0xa0)
[  361.031958] [] (spi_sync+0x84/0xa0) from [] 
(fbtft_write_spi+0xf0/0x104 [fbtft])
[  361.032136] [] (fbtft_write_spi+0xf0/0x104 [fbtft]) from 
[] (fbtft_write_vmem16_bus8+0x11c/0x138 [fbtft])
[  361.032295] [] (fbtft_write_vmem16_bus8+0x11c/0x138 [fbtft]) from 
[] (fbtft_update_display+0x150/0x2fc [fbtft])
[  361.032445] [] (fbtft_update_display+0x150/0x2fc [fbtft]) from 
[] (fbtft_deferred_io+0x110/0x11c [fbtft])
[  361.032573] [] (fbtft_deferred_io+0x110/0x11c [fbtft]) from 
[] (fb_deferred_io_work+0x84/0xcc)
[  361.032670] [] (fb_deferred_io_work+0x84/0xcc) from [] 
(process_one_work+0x248/0x404)
[  361.032760] [] (process_one_work+0x248/0x404) from [] 
(worker_thread+0x1b4/0x2d0)
[  361.032850] [] (worker_thread+0x1b4/0x2d0) from [] 
(kthread+0x94/0xa0)
[  361.032940] [] (kthread+0x94/0xa0) from [] 
(kernel_thread_exit+0x0/0x8)
[  361.033053] INFO: task advmame:1561 blocked for more than 120 seconds.
[  361.033093] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this 
message.
[  361.033135] advmame D c061c3a4 0  1561   1517 0x
[  361.033246] [] (__schedule+0x574/0x7fc) from [] 
(schedule+0x90/0x94)
[  361.03] [] (schedule+0x90/0x94) from [] 
(schedule_preempt_disabled+0x30/0x40)
[  361.033425] [] (schedule_preempt_disabled+0x30/0x40) from 
[] (__mutex_lock_slowpath+0x160/0x1a8)
[  361.033518] [] (__mutex_lock_slowpath+0x160/0x1a8) from 
[] (mutex_lock+0x64/0x7c)
[  361.033607] [] (mutex_lock+0x64/0x7c) from [] 
(fb_deferred_io_mkwrite+0x2c/0xbc)
[  361.033699] [] (fb_deferred_io_mkwrite+0x2c/0xbc) from 
[] (do_wp_page+0x224/0x7a4)
[  361.033789] [] (do_wp_page+0x224/0x7a4) from [] 
(handle_pte_fault+0x7b0/0x838)
[  361.033874] [] (handle_pte_fault+0x7b0/0x838) from [] 
(handle_mm_fault+0xf8/0x134)
[  361.033961] [] (handle_mm_fault+0xf8/0x134) from [] 
(do_page_fault+0x11c/0x344)
[  361.034047] [] (do_page_fault+0x11c/0x344) from [] 
(do_DataAbort+0x44/0xa8)
[  361.034132] [] (do_DataAbort+0x44/0xa8) from [] 
(__dabt_usr+0x38/0x40)
[  361.034184] Exception stack(0xd719ffb0 to 0xd719fff8)
[  361.034237] ffa0:   
b5aa3000 0445f912
[  361.034307] ffc0:   b5aa3000  0001 000b 
f800 001f
[  361.034374] ffe0: 0120 bef33fc8 fe00 0003d094 6830 

I am not a linux kernel hacker, just posting here to draw attention to
it :-) 

Thanks,
Jon




[PATCH 2/5] usb: usb251xb: Fix property_u32 NULL pointer dereference

2017-09-15 Thread Serge Semin
The methods like of_property_read_u32 utilizing the specified
pointer permit only the pointer to a preallocated u32 storage as the
third argument. As a result the driver crashes on NULL pointer
dereference in case if "oc-delay-us" or "power-on-time-ms" declared
in dts file.

Signed-off-by: Serge Semin 
---
 drivers/usb/misc/usb251xb.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c
index 2ef22758c..8101c6212 100644
--- a/drivers/usb/misc/usb251xb.c
+++ b/drivers/usb/misc/usb251xb.c
@@ -348,7 +348,7 @@ static int usb251xb_get_ofdata(struct usb251xb *hub,
struct device *dev = hub->dev;
struct device_node *np = dev->of_node;
int len, err, i;
-   u32 *property_u32 = NULL;
+   u32 property_u32 = 0;
const u32 *cproperty_u32;
const char *cproperty_char;
char str[USB251XB_STRING_BUFSIZE / 2];
@@ -425,16 +425,16 @@ static int usb251xb_get_ofdata(struct usb251xb *hub,
if (of_get_property(np, "dynamic-power-switching", NULL))
hub->conf_data2 |= BIT(7);
 
-   if (!of_property_read_u32(np, "oc-delay-us", property_u32)) {
-   if (*property_u32 == 100) {
+   if (!of_property_read_u32(np, "oc-delay-us", &property_u32)) {
+   if (property_u32 == 100) {
/* 100 us*/
hub->conf_data2 &= ~BIT(5);
hub->conf_data2 &= ~BIT(4);
-   } else if (*property_u32 == 4000) {
+   } else if (property_u32 == 4000) {
/* 4 ms */
hub->conf_data2 &= ~BIT(5);
hub->conf_data2 |= BIT(4);
-   } else if (*property_u32 == 16000) {
+   } else if (property_u32 == 16000) {
/* 16 ms */
hub->conf_data2 |= BIT(5);
hub->conf_data2 |= BIT(4);
@@ -494,8 +494,8 @@ static int usb251xb_get_ofdata(struct usb251xb *hub,
}
 
hub->power_on_time = USB251XB_DEF_POWER_ON_TIME;
-   if (!of_property_read_u32(np, "power-on-time-ms", property_u32))
-   hub->power_on_time = min_t(u8, *property_u32 / 2, 255);
+   if (!of_property_read_u32(np, "power-on-time-ms", &property_u32))
+   hub->power_on_time = min_t(u8, property_u32 / 2, 255);
 
if (of_property_read_u16_array(np, "language-id", &hub->lang_id, 1))
hub->lang_id = USB251XB_DEF_LANGUAGE_ID;
-- 
2.12.0



[PATCH 5/5] usb: usb251xb: Add copyrights

2017-09-15 Thread Serge Semin
Signed-off-by: Serge Semin 
---
 drivers/usb/misc/usb251xb.c | 1 +
 1 file changed, 1 insertions(+), 0 deletion(-)

diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c
index 1d47acd09..43afa04ad 100644
--- a/drivers/usb/misc/usb251xb.c
+++ b/drivers/usb/misc/usb251xb.c
@@ -3,6 +3,7 @@
  * Configuration via SMBus.
  *
  * Copyright (c) 2017 SKIDATA AG
+ * Copyright (c) 2017 T-platforms
  *
  * This work is based on the USB3503 driver by Dongjin Kim and
  * a not-accepted patch by Fabien Lahoudere, see:
-- 
2.12.0



[PATCH 4/5] usb: usb251xb: Use GPIO descriptor consumer interface

2017-09-15 Thread Serge Semin
The driver used to be developed with legacy GPIO API support. It's
better to use descriptor-based interface for several reasons. First
of all the legacy API doesn't support the ACTIVE_LOW/HIGH flag of dts
nodes, which is essential since different hardware may have different
GPIOs connectivity including the logical value inversion. Secondly,
by requesting the reset GPIO descriptor the driver prevent the other
applications from changing its value. And last but not least the
legacy GPIO interface should be avoided in the new code due to it
obsolescence.

Signed-off-by: Serge Semin 
---
 Documentation/devicetree/bindings/usb/usb251xb.txt |  2 +-
 drivers/usb/misc/usb251xb.c| 33 +-
 2 files changed, 14 insertions(+), 21 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/usb251xb.txt 
b/Documentation/devicetree/bindings/usb/usb251xb.txt
index dd59a32e7..7c981d556 100644
--- a/Documentation/devicetree/bindings/usb/usb251xb.txt
+++ b/Documentation/devicetree/bindings/usb/usb251xb.txt
@@ -8,10 +8,10 @@ Required properties :
"microchip,usb2512b", "microchip,usb2512bi", "microchip,usb2513b",
"microchip,usb2513bi", "microchip,usb2514b", "microchip,usb2514bi",
"microchip,usb2517", "microchip,usb2517i"
- - reset-gpios : Should specify the gpio for hub reset
  - reg : I2C address on the selected bus (default is <0x2C>)
 
 Optional properties :
+ - reset-gpios : Should specify the gpio for hub reset
  - skip-config : Skip Hub configuration, but only send the USB-Attach command
  - vendor-id : Set USB Vendor ID of the hub (16 bit, default is 0x0424)
  - product-id : Set USB Product ID of the hub (16 bit, default depends on type)
diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c
index d6a0ff4ec..1d47acd09 100644
--- a/drivers/usb/misc/usb251xb.c
+++ b/drivers/usb/misc/usb251xb.c
@@ -20,12 +20,11 @@
  */
 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
 #include 
-#include 
 #include 
 
 /* Internal Register Set Addresses & Default Values acc. to DS1692C */
@@ -127,7 +126,7 @@ struct usb251xb {
struct device *dev;
struct i2c_client *i2c;
u8 skip_config;
-   int gpio_reset;
+   struct gpio_desc *gpio_reset;
u16 vendor_id;
u16 product_id;
u16 device_id;
@@ -235,13 +234,13 @@ static const struct usb251xb_data usb2517i_data = {
 
 static void usb251xb_reset(struct usb251xb *hub, int state)
 {
-   if (!gpio_is_valid(hub->gpio_reset))
+   if (!hub->gpio_reset)
return;
 
-   gpio_set_value_cansleep(hub->gpio_reset, state);
+   gpiod_set_value_cansleep(hub->gpio_reset, state);
 
/* wait for hub recovery/stabilization */
-   if (state)
+   if (!state)
usleep_range(500, 750); /* >=500us at power on */
else
usleep_range(1, 10);/* >=1us at power down */
@@ -260,7 +259,7 @@ static int usb251xb_connect(struct usb251xb *hub)
i2c_wb[0] = 0x01;
i2c_wb[1] = USB251XB_STATUS_COMMAND_ATTACH;
 
-   usb251xb_reset(hub, 1);
+   usb251xb_reset(hub, 0);
 
err = i2c_smbus_write_i2c_block_data(hub->i2c,
USB251XB_ADDR_STATUS_COMMAND, 2, i2c_wb);
@@ -310,7 +309,7 @@ static int usb251xb_connect(struct usb251xb *hub)
i2c_wb[USB251XB_ADDR_PORT_MAP_7]= hub->port_map7;
i2c_wb[USB251XB_ADDR_STATUS_COMMAND] = USB251XB_STATUS_COMMAND_ATTACH;
 
-   usb251xb_reset(hub, 1);
+   usb251xb_reset(hub, 0);
 
/* write registers */
for (i = 0; i < (USB251XB_I2C_REG_SZ / USB251XB_I2C_WRITE_SZ); i++) {
@@ -363,19 +362,13 @@ static int usb251xb_get_ofdata(struct usb251xb *hub,
else
hub->skip_config = 0;
 
-   hub->gpio_reset = of_get_named_gpio(np, "reset-gpios", 0);
-   if (hub->gpio_reset == -EPROBE_DEFER)
+   hub->gpio_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
+   if (PTR_ERR(hub->gpio_reset) == -EPROBE_DEFER) {
return -EPROBE_DEFER;
-   if (gpio_is_valid(hub->gpio_reset)) {
-   err = devm_gpio_request_one(dev, hub->gpio_reset,
-   GPIOF_OUT_INIT_LOW,
-   "usb251xb reset");
-   if (err) {
-   dev_err(dev,
-   "unable to request GPIO %d as reset pin (%d)\n",
-   hub->gpio_reset, err);
-   return err;
-   }
+   } else if (IS_ERR(hub->gpio_reset)) {
+   err = PTR_ERR(hub->gpio_reset);
+   dev_err(dev, "unable to request GPIO reset pin (%d)\n", err);
+   return err;
}
 
if (of_property_read_u16_array(np, "vendor-id", &hub->vendor_id, 1))
-- 
2.12.0



[PATCH 0/5] usb: usb251xb: Add USB2517i hub support and fix some bugs

2017-09-15 Thread Serge Semin
Primarily it was intended to just add USB2517 hub support to the driver.
But after tests a bug and inconistency were discovered. So it was decided
to perform following changes:

Changelog v1:
- Add USB2517/i hub specifics support to the driver
- Fix property_u32 NULL-pointer dereference
- Add new {bus,self}-max-{power,curret} dts properties
- Replace legacy GPIO API usage with descriptor-based one

Serge Semin (5):
  usb: usb251xb: Add USB2517/i hub support
  usb: usb251xb: Fix property_u32 NULL pointer dereference
  usb: usb251xb: Add max power/current dts nodes
  usb: usb251xb: Use GPIO descriptor consumer interface
  usb: usb251xb: Add copyrights

 Documentation/devicetree/bindings/usb/usb251xb.txt |  12 +-
 drivers/usb/misc/usb251xb.c| 154 +++--
 2 files changed, 123 insertions(+), 43 deletions(-)

-- 
2.12.0



[PATCH 3/5] usb: usb251xb: Add max power/current dts nodes

2017-09-15 Thread Serge Semin
This parameters may be varied in accordance with hardware specifics.
So lets add the corresponding settings to the usb251x driver dts
specification.

Signed-off-by: Serge Semin 
---
 Documentation/devicetree/bindings/usb/usb251xb.txt |  6 ++
 drivers/usb/misc/usb251xb.c| 20 
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/usb251xb.txt 
b/Documentation/devicetree/bindings/usb/usb251xb.txt
index 3d84626d3..dd59a32e7 100644
--- a/Documentation/devicetree/bindings/usb/usb251xb.txt
+++ b/Documentation/devicetree/bindings/usb/usb251xb.txt
@@ -44,6 +44,12 @@ Optional properties :
device connected.
  - sp-disabled-ports : Specifies the ports which will be self-power disabled
  - bp-disabled-ports : Specifies the ports which will be bus-power disabled
+ - sp-max-{power,current} : Indicates the power/current consumed by hub from
+   an upstream port (VBUS) when operation as a self-powered hub. The value
+   is given in mA in a 0 - 100 range (default is 1mA).
+ - bp-max-{power,current} : Indicates the power/current consumed by hub from
+   an upstream port (VBUS) when operation as a bus-powered hub. The value
+   is given in mA in a 0 - 510 range (default is 100mA).
  - power-on-time-ms : Specifies the time it takes from the time the host
initiates the power-on sequence to a port until the port has adequate
power. The value is given in ms in a 0 - 510 range (default is 100ms).
diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c
index 8101c6212..d6a0ff4ec 100644
--- a/drivers/usb/misc/usb251xb.c
+++ b/drivers/usb/misc/usb251xb.c
@@ -493,6 +493,22 @@ static int usb251xb_get_ofdata(struct usb251xb *hub,
}
}
 
+   hub->max_power_sp = USB251XB_DEF_MAX_POWER_SELF;
+   if (!of_property_read_u32(np, "sp-max-power", &property_u32))
+   hub->max_power_sp = min_t(u8, property_u32 / 2, 50);
+
+   hub->max_power_bp = USB251XB_DEF_MAX_POWER_BUS;
+   if (!of_property_read_u32(np, "bp-max-power", &property_u32))
+   hub->max_power_bp = min_t(u8, property_u32 / 2, 255);
+
+   hub->max_current_sp = USB251XB_DEF_MAX_CURRENT_SELF;
+   if (!of_property_read_u32(np, "sp-max-current", &property_u32))
+   hub->max_current_sp = min_t(u8, property_u32 / 2, 50);
+
+   hub->max_current_bp = USB251XB_DEF_MAX_CURRENT_BUS;
+   if (!of_property_read_u32(np, "bp-max-current", &property_u32))
+   hub->max_current_bp = min_t(u8, property_u32 / 2, 255);
+
hub->power_on_time = USB251XB_DEF_POWER_ON_TIME;
if (!of_property_read_u32(np, "power-on-time-ms", &property_u32))
hub->power_on_time = min_t(u8, property_u32 / 2, 255);
@@ -532,10 +548,6 @@ static int usb251xb_get_ofdata(struct usb251xb *hub,
/* The following parameters are currently not exposed to devicetree, but
 * may be as soon as needed.
 */
-   hub->max_power_sp = USB251XB_DEF_MAX_POWER_SELF;
-   hub->max_power_bp = USB251XB_DEF_MAX_POWER_BUS;
-   hub->max_current_sp = USB251XB_DEF_MAX_CURRENT_SELF;
-   hub->max_current_bp = USB251XB_DEF_MAX_CURRENT_BUS;
hub->bat_charge_en = USB251XB_DEF_BATTERY_CHARGING_ENABLE;
hub->boost_up = USB251XB_DEF_BOOST_UP;
hub->boost_57 = USB251XB_DEF_BOOST_57;
-- 
2.12.0



[PATCH 1/5] usb: usb251xb: Add USB2517/i hub support

2017-09-15 Thread Serge Semin
USB2517i hubs are very like USB251xb devices series. They have almost
the same configuration registers space except number of ports, led
configurations and lack of battery settings. All these peculiarities
are reflected in this patch.

Signed-off-by: Serge Semin 
---
 Documentation/devicetree/bindings/usb/usb251xb.txt |  4 +-
 drivers/usb/misc/usb251xb.c| 84 +++---
 2 files changed, 78 insertions(+), 10 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/usb251xb.txt 
b/Documentation/devicetree/bindings/usb/usb251xb.txt
index 3957d4eda..3d84626d3 100644
--- a/Documentation/devicetree/bindings/usb/usb251xb.txt
+++ b/Documentation/devicetree/bindings/usb/usb251xb.txt
@@ -6,7 +6,8 @@ Hi-Speed Controller.
 Required properties :
  - compatible : Should be "microchip,usb251xb" or one of the specific types:
"microchip,usb2512b", "microchip,usb2512bi", "microchip,usb2513b",
-   "microchip,usb2513bi", "microchip,usb2514b", "microchip,usb2514bi"
+   "microchip,usb2513bi", "microchip,usb2514b", "microchip,usb2514bi",
+   "microchip,usb2517", "microchip,usb2517i"
  - reset-gpios : Should specify the gpio for hub reset
  - reg : I2C address on the selected bus (default is <0x2C>)
 
@@ -36,6 +37,7 @@ Optional properties :
an invalid value is given, the default is used instead.
  - compound-device : indicate the hub is part of a compound device
  - port-mapping-mode : enable port mapping mode
+ - speed-led-mode : led speed indiation mode selection (usb2517 only)
  - string-support : enable string descriptor support (required for 
manufacturer,
product and serial string configuration)
  - non-removable-ports : Should specify the ports which have a non-removable
diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c
index 91f66d68b..2ef22758c 100644
--- a/drivers/usb/misc/usb251xb.c
+++ b/drivers/usb/misc/usb251xb.c
@@ -38,6 +38,7 @@
 #define USB251XB_DEF_PRODUCT_ID_12 0x2512 /* USB2512B/12Bi */
 #define USB251XB_DEF_PRODUCT_ID_13 0x2513 /* USB2513B/13Bi */
 #define USB251XB_DEF_PRODUCT_ID_14 0x2514 /* USB2514B/14Bi */
+#define USB251XB_DEF_PRODUCT_ID_17 0x2517 /* USB2517i */
 
 #define USB251XB_ADDR_DEVICE_ID_LSB0x04
 #define USB251XB_ADDR_DEVICE_ID_MSB0x05
@@ -48,7 +49,7 @@
 #define USB251XB_ADDR_CONFIG_DATA_20x07
 #define USB251XB_DEF_CONFIG_DATA_2 0x20
 #define USB251XB_ADDR_CONFIG_DATA_30x08
-#define USB251XB_DEF_CONFIG_DATA_3 0x02
+#define USB251XB_DEF_CONFIG_DATA_3 0x00
 
 #define USB251XB_ADDR_NON_REMOVABLE_DEVICES0x09
 #define USB251XB_DEF_NON_REMOVABLE_DEVICES 0x00
@@ -82,7 +83,7 @@
 
 #define USB251XB_ADDR_PRODUCT_STRING_LEN   0x14
 #define USB251XB_ADDR_PRODUCT_STRING   0x54
-#define USB251XB_DEF_PRODUCT_STRING"USB251xB/xBi"
+#define USB251XB_DEF_PRODUCT_STRING"USB251xB/xBi/7i"
 
 #define USB251XB_ADDR_SERIAL_STRING_LEN0x15
 #define USB251XB_ADDR_SERIAL_STRING0x92
@@ -93,8 +94,10 @@
 
 #define USB251XB_ADDR_BOOST_UP 0xF6
 #define USB251XB_DEF_BOOST_UP  0x00
-#define USB251XB_ADDR_BOOST_X  0xF8
-#define USB251XB_DEF_BOOST_X   0x00
+#define USB251XB_ADDR_BOOST_57 0xF8
+#define USB251XB_DEF_BOOST_57  0x00
+#define USB251XB_ADDR_BOOST_14 0xF8
+#define USB251XB_DEF_BOOST_14  0x00
 
 #define USB251XB_ADDR_PORT_SWAP0xFA
 #define USB251XB_DEF_PORT_SWAP 0x00
@@ -102,7 +105,11 @@
 #define USB251XB_ADDR_PORT_MAP_12  0xFB
 #define USB251XB_DEF_PORT_MAP_12   0x00
 #define USB251XB_ADDR_PORT_MAP_34  0xFC
-#define USB251XB_DEF_PORT_MAP_34   0x00 /* USB2513B/i & USB2514B/i only */
+#define USB251XB_DEF_PORT_MAP_34   0x00 /* USB251{3B/i,4B/i,7/i} only */
+#define USB251XB_ADDR_PORT_MAP_56  0xFD
+#define USB251XB_DEF_PORT_MAP_56   0x00 /* USB2517/i only */
+#define USB251XB_ADDR_PORT_MAP_7   0xFE
+#define USB251XB_DEF_PORT_MAP_70x00 /* USB2517/i only */
 
 #define USB251XB_ADDR_STATUS_COMMAND   0xFF
 #define USB251XB_STATUS_COMMAND_SMBUS_DOWN 0x04
@@ -144,48 +151,88 @@ struct usb251xb {
char serial[USB251XB_STRING_BUFSIZE];
u8  bat_charge_en;
u8  boost_up;
-   u8  boost_x;
+   u8  boost_57;
+   u8  boost_14;
u8  port_swap;
u8  port_map12;
u8  port_map34;
+   u8  port_map56;
+   u8  port_map7;
u8  status;
 };
 
 struct usb251xb_data {
u16 product_id;
+   u8 port_cnt;
+   bool led_support;
+   bool bat_support;
char product_str[USB251XB_STRING_BUFSIZE / 2]; /* ASCII string */
 };
 
 static const struct usb251xb_data usb2512b_data = {
.product_id = 0x2512,
+   .port_cnt = 2,
+   .led_support = false,
+   .bat_support = true,
.product_str = "USB2512B",
 };
 
 static const struct usb251xb_data usb2512bi_data = {
.product_id = 0x2512,
+   .port_cnt = 2,
+   .led_support = false,
+   .bat_support = true

Re: [PATCH] vfs: introduce UMOUNT_WAIT which waits for umount completion

2017-09-15 Thread Jaegeuk Kim
On 09/15, Theodore Ts'o wrote:
> On Fri, Sep 15, 2017 at 11:44:33AM -0700, Jaegeuk Kim wrote:
> > 
> > So, I digged it in more detail, and found, in drivers/android/binder.c [1],
> > - binder_ioctl()
> >  - create a kernel thread
> >  - zombie_cleanup_check()
> >   - binder_defer_work()
> > - queue_work(..., &binder_deferred_work);
> > 
> > - binder_deferred_func()
> >  - binder_clear_zombies()
> >   - binder_proc_clear_zombies()
> >- put_files_struct()
> > - close_files()
> >  - filp_close()
> >   - fput()
> > 
> > It seems binder holds some proc files.
> 
> If binder was holding some files open, then umount should have failed
> with EBUSY, no?

Based on what I've got some traces so far,

- binder_ioctl
 - create a kernel thread
 - zombie_cleanup_check
  - binder_defer_work
   - queue_work(..., &binder_deferred_work);

- binder_deferred_func
 - binder_clear_zombies
  - binder_proc_clear_zombies
   - put_files_struct
 - close_files
  - filp_close
   - fput

- delayed_fput
 ...
 - file_free
 - dput
init
- umount
 - mntput
  - mntput_no_expire
- do_umount
 - mnt_get_count() > 2
- mntput_no_expire
 - mnt_add_count(-1);
   - mnt_add_count(-1);
 - mnt_get_count() return;
 - return 0;
   - delayed_mntput_work
- device_shutdown
- ext4_put_super()
 - EIO, and panic if error=panic


The mntput() in delayed_fput() is the last function call. So before that moment,
sys_umount() may see mnt_get_count() as 2, so it avoids EBUSY condition. I'm not
sure why it check over 2 tho.

> 
> Does Android use mount namespaces at all?
> 
>   - Ted


Re: [RFC PATCH 3/4] x86/asm: Make alternative macro interfaces more clear and consistent

2017-09-15 Thread Josh Poimboeuf
On Fri, Sep 15, 2017 at 11:01:19AM -0700, Linus Torvalds wrote:
> On Fri, Sep 15, 2017 at 9:53 AM, Andrey Ryabinin
>  wrote:
> >
> > I'm not so sure that this is disabled optimization. I assume that global 
> > rsp makes
> > changes something in gcc's register allocation logic, or something like 
> > that leading
> > to subtle changes in generated code.
> >
> > But what I recently find out, is that this "regression" sometimes is 
> > actually improvement in .text size.
> > It all depends on .config, e.g:
> 
> Oh, that would be lovely and solve all the issues.
> 
> And looking at the code generation differences for one file
> (kernel/futex.c) and one single config (my default config), the thing
> that the global stack register seems to change is that it moves some
> code - particularly completely unrelated inline asm code - inside the
> region protected by frame pointers.
> 
> There are a few register allocation changes too, but they didn't seem
> to make code worse, and I think they were just "incidental" from code
> movement. And most code movement really seemed to be around inline
> asms, I  wonder if the gcc logic simply is something like "if the
> stack pointer is visible as a register, don't move any inline asm
> across a frame setup".
> 
> In fact, on that one file and one configuration, the resulting
> assembler file had three fewer lines of code with that global stack
> register declaration than with the local one.
> 
> So at least from just that one case, I can back up Andrey's
> observation: it's not that the code gets worse, it just is slightly
> different. Sometimes it's better.
> 
> So maybe that simple patch to just make the stack pointer be a global
> register declaration really is the fix for this issue.
> 
> It's not *pretty*, and I'd much rather just see some explicit way for
> us to say "this asm wants the frame to be set up", but of the
> alternatives we've seen, maybe it's the right thing to do?

Ok, here's the (compile tested) patch in case anybody wants to try it
out.


diff --git a/arch/x86/include/asm/alternative.h 
b/arch/x86/include/asm/alternative.h
index 1b020381ab38..c096624137ae 100644
--- a/arch/x86/include/asm/alternative.h
+++ b/arch/x86/include/asm/alternative.h
@@ -218,10 +218,9 @@ static inline int alternatives_text_reserved(void *start, 
void *end)
 #define alternative_call_2(oldfunc, newfunc1, feature1, newfunc2, feature2,   \
   output, input...)  \
 {\
-   register void *__sp asm(_ASM_SP); \
asm volatile (ALTERNATIVE_2("call %P[old]", "call %P[new1]", feature1,\
"call %P[new2]", feature2)\
-   : output, "+r" (__sp) \
+   : output, ASM_CALL_CONSTRAINT \
: [old] "i" (oldfunc), [new1] "i" (newfunc1), \
  [new2] "i" (newfunc2), ## input);   \
 }
diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h
index 676ee5807d86..3914cdf0e488 100644
--- a/arch/x86/include/asm/asm.h
+++ b/arch/x86/include/asm/asm.h
@@ -132,4 +132,9 @@
 /* For C file, we already have NOKPROBE_SYMBOL macro */
 #endif
 
+#ifndef __ASSEMBLY__
+register void *__asm_call_sp asm(_ASM_SP);
+#define ASM_CALL_CONSTRAINT "+r" (__asm_call_sp)
+#endif
+
 #endif /* _ASM_X86_ASM_H */
diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index 63cc96f064dc..647e2f1d4cb6 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -179,7 +179,6 @@ static inline u64 hv_do_hypercall(u64 control, void *input, 
void *output)
u64 input_address = input ? virt_to_phys(input) : 0;
u64 output_address = output ? virt_to_phys(output) : 0;
u64 hv_status;
-   register void *__sp asm(_ASM_SP);
 
 #ifdef CONFIG_X86_64
if (!hv_hypercall_pg)
@@ -187,7 +186,7 @@ static inline u64 hv_do_hypercall(u64 control, void *input, 
void *output)
 
__asm__ __volatile__("mov %4, %%r8\n"
 "call *%5"
-: "=a" (hv_status), "+r" (__sp),
+: "=a" (hv_status), ASM_CALL_CONSTRAINT,
   "+c" (control), "+d" (input_address)
 :  "r" (output_address), "m" (hv_hypercall_pg)
 : "cc", "memory", "r8", "r9", "r10", "r11");
@@ -202,7 +201,7 @@ static inline u64 hv_do_hypercall(u64 control, void *input, 
void *output)
 
__asm__ __volatile__("call *%7"
 : "=A" (hv_status),
-  "+c" (input_address_lo), "+r" (__sp)
+  "+c" (input_address_lo), ASM_CALL_CONSTRAINT,
 : "A" (control),
   

Re: [PATCH v3 2/5] KVM: MMU: check guest CR3 reserved bits based on its physical address width.

2017-09-15 Thread Jim Mattson
On Thu, Aug 24, 2017 at 5:27 AM, Yu Zhang  wrote:
> Currently, KVM uses CR3_L_MODE_RESERVED_BITS to check the
> reserved bits in CR3. Yet the length of reserved bits in
> guest CR3 should be based on the physical address width
> exposed to the VM. This patch changes CR3 check logic to
> calculate the reserved bits at runtime.
>
> Signed-off-by: Yu Zhang 
> ---
>  arch/x86/include/asm/kvm_host.h |  1 -
>  arch/x86/kvm/emulate.c  | 14 --
>  arch/x86/kvm/mmu.h  |  3 +++
>  arch/x86/kvm/x86.c  |  8 
>  4 files changed, 19 insertions(+), 7 deletions(-)
>
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 6db0ed9..e716228 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -79,7 +79,6 @@
>   | X86_CR0_ET | X86_CR0_NE | X86_CR0_WP | X86_CR0_AM 
> \
>   | X86_CR0_NW | X86_CR0_CD | X86_CR0_PG))
>
> -#define CR3_L_MODE_RESERVED_BITS 0xFF00ULL
>  #define CR3_PCID_INVD   BIT_64(63)
>  #define CR4_RESERVED_BITS   \
> (~(unsigned long)(X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD | 
> X86_CR4_DE\
> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
> index 319d91f..a89b595 100644
> --- a/arch/x86/kvm/emulate.c
> +++ b/arch/x86/kvm/emulate.c
> @@ -28,6 +28,7 @@
>
>  #include "x86.h"
>  #include "tss.h"
> +#include "mmu.h"
>
>  /*
>   * Operand types
> @@ -4097,8 +4098,17 @@ static int check_cr_write(struct x86_emulate_ctxt 
> *ctxt)
> u64 rsvd = 0;
>
> ctxt->ops->get_msr(ctxt, MSR_EFER, &efer);
> -   if (efer & EFER_LMA)
> -   rsvd = CR3_L_MODE_RESERVED_BITS & ~CR3_PCID_INVD;
> +   if (efer & EFER_LMA) {
> +   u64 maxphyaddr;
> +   u32 eax = 0x8008;
> +
> +   if (ctxt->ops->get_cpuid(ctxt, &eax, NULL, NULL,
> +NULL, false))

Passing NULL for the address of ecx looks problematic to me.

We have:

static bool emulator_get_cpuid(struct x86_emulate_ctxt *ctxt,
u32 *eax, u32 *ebx, u32 *ecx, u32 *edx, bool
check_limit)
{
return kvm_cpuid(emul_to_vcpu(ctxt), eax, ebx, ecx, edx, check_limit);
}

And:

bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx,
   u32 *ecx, u32 *edx, bool check_limit)
{
u32 function = *eax, index = *ecx;
struct kvm_cpuid_entry2 *best;
bool entry_found = true;
...

Doesn't this immediately try to dereference a NULL pointer?  How much
testing have you done of this code?

> +   maxphyaddr = eax & 0xff;
> +   else
> +   maxphyaddr = 36;
> +   rsvd = rsvd_bits(maxphyaddr, 62);
> +   }
>
> if (new_val & rsvd)
> return emulate_gp(ctxt, 0);
> diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
> index 3ed6192..67e7ec2 100644
> --- a/arch/x86/kvm/mmu.h
> +++ b/arch/x86/kvm/mmu.h
> @@ -48,6 +48,9 @@
>
>  static inline u64 rsvd_bits(int s, int e)
>  {
> +   if (e < s)
> +   return 0;
> +
> return ((1ULL << (e - s + 1)) - 1) << s;
>  }
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index cc2c7e4..79f5889 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -813,10 +813,10 @@ int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long 
> cr3)
> return 0;
> }
>
> -   if (is_long_mode(vcpu)) {
> -   if (cr3 & CR3_L_MODE_RESERVED_BITS)
> -   return 1;
> -   } else if (is_pae(vcpu) && is_paging(vcpu) &&
> +   if (is_long_mode(vcpu) &&
> +   (cr3 & rsvd_bits(cpuid_maxphyaddr(vcpu), 62)))
> +   return 1;
> +   else if (is_pae(vcpu) && is_paging(vcpu) &&
>!load_pdptrs(vcpu, vcpu->arch.walk_mmu, cr3))
> return 1;
>
> --
> 2.5.0
>


[PATCH v4 03/13] xen/pvcalls: connect to the backend

2017-09-15 Thread Stefano Stabellini
Implement the probe function for the pvcalls frontend. Read the
supported versions, max-page-order and function-calls nodes from
xenstore.

Only one frontend<->backend connection is supported at any given time
for a guest. Store the active frontend device to a static pointer.

Introduce a stub functions for the event handler.

Signed-off-by: Stefano Stabellini 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 133 
 1 file changed, 133 insertions(+)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 67c8337..ffbbcd1 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -96,12 +96,145 @@ static int pvcalls_front_remove(struct xenbus_device *dev)
 static int pvcalls_front_probe(struct xenbus_device *dev,
  const struct xenbus_device_id *id)
 {
+   int ret = -ENOMEM, evtchn, i;
+   unsigned int max_page_order, function_calls, len;
+   char *versions;
+   grant_ref_t gref_head = 0;
+   struct xenbus_transaction xbt;
+   struct pvcalls_bedata *bedata = NULL;
+   struct xen_pvcalls_sring *sring;
+
+   if (pvcalls_front_dev != NULL) {
+   dev_err(&dev->dev, "only one PV Calls connection supported\n");
+   return -EINVAL;
+   }
+
+   versions = xenbus_read(XBT_NIL, dev->otherend, "versions", &len);
+   if (!len)
+   return -EINVAL;
+   if (strcmp(versions, "1")) {
+   kfree(versions);
+   return -EINVAL;
+   }
+   kfree(versions);
+   max_page_order = xenbus_read_unsigned(dev->otherend,
+ "max-page-order", 0);
+   if (max_page_order < PVCALLS_RING_ORDER)
+   return -ENODEV;
+   function_calls = xenbus_read_unsigned(dev->otherend,
+ "function-calls", 0);
+   /* See XENBUS_FUNCTIONS_CALLS in pvcalls.h */
+   if (function_calls != 1)
+   return -ENODEV;
+   pr_info("%s max-page-order is %u\n", __func__, max_page_order);
+
+   bedata = kzalloc(sizeof(struct pvcalls_bedata), GFP_KERNEL);
+   if (!bedata)
+   return -ENOMEM;
+
+   dev_set_drvdata(&dev->dev, bedata);
+   pvcalls_front_dev = dev;
+   init_waitqueue_head(&bedata->inflight_req);
+   INIT_LIST_HEAD(&bedata->socket_mappings);
+   INIT_LIST_HEAD(&bedata->socketpass_mappings);
+   spin_lock_init(&bedata->socket_lock);
+   bedata->irq = -1;
+   bedata->ref = -1;
+
+   for (i = 0; i < PVCALLS_NR_REQ_PER_RING; i++)
+   bedata->rsp[i].req_id = PVCALLS_INVALID_ID;
+
+   sring = (struct xen_pvcalls_sring *) __get_free_page(GFP_KERNEL |
+__GFP_ZERO);
+   if (!sring)
+   goto error;
+   SHARED_RING_INIT(sring);
+   FRONT_RING_INIT(&bedata->ring, sring, XEN_PAGE_SIZE);
+
+   ret = xenbus_alloc_evtchn(dev, &evtchn);
+   if (ret)
+   goto error;
+
+   bedata->irq = bind_evtchn_to_irqhandler(evtchn,
+   pvcalls_front_event_handler,
+   0, "pvcalls-frontend", dev);
+   if (bedata->irq < 0) {
+   ret = bedata->irq;
+   goto error;
+   }
+
+   ret = gnttab_alloc_grant_references(1, &gref_head);
+   if (ret < 0)
+   goto error;
+   bedata->ref = gnttab_claim_grant_reference(&gref_head);
+   if (bedata->ref < 0) {
+   ret = bedata->ref;
+   goto error;
+   }
+   gnttab_grant_foreign_access_ref(bedata->ref, dev->otherend_id,
+   virt_to_gfn((void *)sring), 0);
+
+ again:
+   ret = xenbus_transaction_start(&xbt);
+   if (ret) {
+   xenbus_dev_fatal(dev, ret, "starting transaction");
+   goto error;
+   }
+   ret = xenbus_printf(xbt, dev->nodename, "version", "%u", 1);
+   if (ret)
+   goto error_xenbus;
+   ret = xenbus_printf(xbt, dev->nodename, "ring-ref", "%d", bedata->ref);
+   if (ret)
+   goto error_xenbus;
+   ret = xenbus_printf(xbt, dev->nodename, "port", "%u",
+   evtchn);
+   if (ret)
+   goto error_xenbus;
+   ret = xenbus_transaction_end(xbt, 0);
+   if (ret) {
+   if (ret == -EAGAIN)
+   goto again;
+   xenbus_dev_fatal(dev, ret, "completing transaction");
+   goto error;
+   }
+   xenbus_switch_state(dev, XenbusStateInitialised);
+
return 0;
+
+ error_xenbus:
+   xenbus_transaction_end(xbt, 1);
+   xenbus_dev_fatal(dev, ret, "writing xenstore");
+ error:
+   pvcalls_front_remove(dev);
+   return ret;
 }
 
 static void pvcalls_front_changed(struct xenbus_device *dev,

[PATCH v4 04/13] xen/pvcalls: implement socket command and handle events

2017-09-15 Thread Stefano Stabellini
Send a PVCALLS_SOCKET command to the backend, use the masked
req_prod_pvt as req_id. This way, req_id is guaranteed to be between 0
and PVCALLS_NR_REQ_PER_RING. We already have a slot in the rsp array
ready for the response, and there cannot be two outstanding responses
with the same req_id.

Wait for the response by waiting on the inflight_req waitqueue and
check for the req_id field in rsp[req_id]. Use atomic accesses and
barriers to read the field. Note that the barriers are simple smp
barriers (as opposed to virt barriers) because they are for internal
frontend synchronization, not frontend<->backend communication.

Once a response is received, clear the corresponding rsp slot by setting
req_id to PVCALLS_INVALID_ID. Note that PVCALLS_INVALID_ID is invalid
only from the frontend point of view. It is not part of the PVCalls
protocol.

pvcalls_front_event_handler is in charge of copying responses from the
ring to the appropriate rsp slot. It is done by copying the body of the
response first, then by copying req_id atomically. After the copies,
wake up anybody waiting on waitqueue.

socket_lock protects accesses to the ring.

Create a new struct sock_mapping and convert the pointer into an
uint64_t and use it as id for the new socket to pass to the backend. The
struct will be fully initialized later on connect or bind. In this patch
the struct sock_mapping is empty, the fields will be added by the next
patch.

sock->sk->sk_send_head is not used for ip sockets: reuse the field to
store a pointer to the struct sock_mapping corresponding to the socket.
This way, we can easily get the struct sock_mapping from the struct
socket.

Signed-off-by: Stefano Stabellini 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 135 
 drivers/xen/pvcalls-front.h |   8 +++
 2 files changed, 143 insertions(+)
 create mode 100644 drivers/xen/pvcalls-front.h

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index ffbbcd1..1bad1b1 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -20,6 +20,8 @@
 #include 
 #include 
 
+#include "pvcalls-front.h"
+
 #define PVCALLS_INVALID_ID UINT_MAX
 #define PVCALLS_RING_ORDER XENBUS_MAX_RING_GRANT_ORDER
 #define PVCALLS_NR_REQ_PER_RING __CONST_RING_SIZE(xen_pvcalls, XEN_PAGE_SIZE)
@@ -51,11 +53,144 @@ struct pvcalls_bedata {
atomic_dec(&pvcalls_refcount);  \
 }
 
+struct sock_mapping {
+   bool active_socket;
+   struct list_head list;
+   struct socket *sock;
+};
+
+static inline int get_request(struct pvcalls_bedata *bedata, int *req_id)
+{
+   *req_id = bedata->ring.req_prod_pvt & (RING_SIZE(&bedata->ring) - 1);
+   if (RING_FULL(&bedata->ring) ||
+   READ_ONCE(bedata->rsp[*req_id].req_id) != PVCALLS_INVALID_ID)
+   return -EAGAIN;
+   return 0;
+}
+
 static irqreturn_t pvcalls_front_event_handler(int irq, void *dev_id)
 {
+   struct xenbus_device *dev = dev_id;
+   struct pvcalls_bedata *bedata;
+   struct xen_pvcalls_response *rsp;
+   uint8_t *src, *dst;
+   int req_id = 0, more = 0, done = 0;
+
+   if (dev == NULL)
+   return IRQ_HANDLED;
+
+   pvcalls_enter;
+   bedata = dev_get_drvdata(&dev->dev);
+   if (bedata == NULL) {
+   pvcalls_exit;
+   return IRQ_HANDLED;
+   }
+
+again:
+   while (RING_HAS_UNCONSUMED_RESPONSES(&bedata->ring)) {
+   rsp = RING_GET_RESPONSE(&bedata->ring, bedata->ring.rsp_cons);
+
+   req_id = rsp->req_id;
+   dst = (uint8_t *)&bedata->rsp[req_id] + sizeof(rsp->req_id);
+   src = (uint8_t *)rsp + sizeof(rsp->req_id);
+   memcpy(dst, src, sizeof(*rsp) - sizeof(rsp->req_id));
+   /*
+* First copy the rest of the data, then req_id. It is
+* paired with the barrier when accessing bedata->rsp.
+*/
+   smp_wmb();
+   WRITE_ONCE(bedata->rsp[req_id].req_id, rsp->req_id);
+
+   done = 1;
+   bedata->ring.rsp_cons++;
+   }
+
+   RING_FINAL_CHECK_FOR_RESPONSES(&bedata->ring, more);
+   if (more)
+   goto again;
+   if (done)
+   wake_up(&bedata->inflight_req);
+   pvcalls_exit;
return IRQ_HANDLED;
 }
 
+int pvcalls_front_socket(struct socket *sock)
+{
+   struct pvcalls_bedata *bedata;
+   struct sock_mapping *map = NULL;
+   struct xen_pvcalls_request *req;
+   int notify, req_id, ret;
+
+   pvcalls_enter;
+   if (!pvcalls_front_dev) {
+   pvcalls_exit;
+   return -EACCES;
+   }
+   /*
+* PVCalls only supports domain AF_INET,
+* type SOCK_STREAM and protocol 0 sockets for now.
+*
+* Check socket type here, AF_INET and protocol checks are done
+* by the caller.
+*/
+   if (sock->type != SOC

[PATCH v4 01/13] xen/pvcalls: introduce the pvcalls xenbus frontend

2017-09-15 Thread Stefano Stabellini
Introduce a xenbus frontend for the pvcalls protocol, as defined by
https://xenbits.xen.org/docs/unstable/misc/pvcalls.html.

This patch only adds the stubs, the code will be added by the following
patches.

Signed-off-by: Stefano Stabellini 
Reviewed-by: Boris Ostrovsky 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 61 +
 1 file changed, 61 insertions(+)
 create mode 100644 drivers/xen/pvcalls-front.c

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
new file mode 100644
index 000..a8d38c2
--- /dev/null
+++ b/drivers/xen/pvcalls-front.c
@@ -0,0 +1,61 @@
+/*
+ * (c) 2017 Stefano Stabellini 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static const struct xenbus_device_id pvcalls_front_ids[] = {
+   { "pvcalls" },
+   { "" }
+};
+
+static int pvcalls_front_remove(struct xenbus_device *dev)
+{
+   return 0;
+}
+
+static int pvcalls_front_probe(struct xenbus_device *dev,
+ const struct xenbus_device_id *id)
+{
+   return 0;
+}
+
+static void pvcalls_front_changed(struct xenbus_device *dev,
+   enum xenbus_state backend_state)
+{
+}
+
+static struct xenbus_driver pvcalls_front_driver = {
+   .ids = pvcalls_front_ids,
+   .probe = pvcalls_front_probe,
+   .remove = pvcalls_front_remove,
+   .otherend_changed = pvcalls_front_changed,
+};
+
+static int __init pvcalls_frontend_init(void)
+{
+   if (!xen_domain())
+   return -ENODEV;
+
+   pr_info("Initialising Xen pvcalls frontend driver\n");
+
+   return xenbus_register_frontend(&pvcalls_front_driver);
+}
+
+module_init(pvcalls_frontend_init);
-- 
1.9.1



[PATCH v4 05/13] xen/pvcalls: implement connect command

2017-09-15 Thread Stefano Stabellini
Send PVCALLS_CONNECT to the backend. Allocate a new ring and evtchn for
the active socket.

Introduce fields in struct sock_mapping to keep track of active sockets.
Introduce a waitqueue to allow the frontend to wait on data coming from
the backend on the active socket (recvmsg command).

Two mutexes (one of reads and one for writes) will be used to protect
the active socket in and out rings from concurrent accesses.

Signed-off-by: Stefano Stabellini 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 163 
 drivers/xen/pvcalls-front.h |   2 +
 2 files changed, 165 insertions(+)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 1bad1b1..ef511b6 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -13,6 +13,10 @@
  */
 
 #include 
+#include 
+#include 
+
+#include 
 
 #include 
 #include 
@@ -57,6 +61,18 @@ struct sock_mapping {
bool active_socket;
struct list_head list;
struct socket *sock;
+   union {
+   struct {
+   int irq;
+   grant_ref_t ref;
+   struct pvcalls_data_intf *ring;
+   struct pvcalls_data data;
+   struct mutex in_mutex;
+   struct mutex out_mutex;
+
+   wait_queue_head_t inflight_conn_req;
+   } active;
+   };
 };
 
 static inline int get_request(struct pvcalls_bedata *bedata, int *req_id)
@@ -114,6 +130,18 @@ static irqreturn_t pvcalls_front_event_handler(int irq, 
void *dev_id)
return IRQ_HANDLED;
 }
 
+static irqreturn_t pvcalls_front_conn_handler(int irq, void *sock_map)
+{
+   struct sock_mapping *map = sock_map;
+
+   if (map == NULL)
+   return IRQ_HANDLED;
+
+   wake_up_interruptible(&map->active.inflight_conn_req);
+
+   return IRQ_HANDLED;
+}
+
 int pvcalls_front_socket(struct socket *sock)
 {
struct pvcalls_bedata *bedata;
@@ -191,6 +219,133 @@ int pvcalls_front_socket(struct socket *sock)
return ret;
 }
 
+static int create_active(struct sock_mapping *map, int *evtchn)
+{
+   void *bytes;
+   int ret = -ENOMEM, irq = -1, i;
+
+   *evtchn = -1;
+   init_waitqueue_head(&map->active.inflight_conn_req);
+
+   map->active.ring = (struct pvcalls_data_intf *)
+   __get_free_page(GFP_KERNEL | __GFP_ZERO);
+   if (map->active.ring == NULL)
+   goto out_error;
+   map->active.ring->ring_order = PVCALLS_RING_ORDER;
+   bytes = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
+   PVCALLS_RING_ORDER);
+   if (bytes == NULL)
+   goto out_error;
+   for (i = 0; i < (1 << PVCALLS_RING_ORDER); i++)
+   map->active.ring->ref[i] = gnttab_grant_foreign_access(
+   pvcalls_front_dev->otherend_id,
+   pfn_to_gfn(virt_to_pfn(bytes) + i), 0);
+
+   map->active.ref = gnttab_grant_foreign_access(
+   pvcalls_front_dev->otherend_id,
+   pfn_to_gfn(virt_to_pfn((void *)map->active.ring)), 0);
+
+   map->active.data.in = bytes;
+   map->active.data.out = bytes +
+   XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER);
+
+   ret = xenbus_alloc_evtchn(pvcalls_front_dev, evtchn);
+   if (ret)
+   goto out_error;
+   irq = bind_evtchn_to_irqhandler(*evtchn, pvcalls_front_conn_handler,
+   0, "pvcalls-frontend", map);
+   if (irq < 0) {
+   ret = irq;
+   goto out_error;
+   }
+
+   map->active.irq = irq;
+   map->active_socket = true;
+   mutex_init(&map->active.in_mutex);
+   mutex_init(&map->active.out_mutex);
+
+   return 0;
+
+out_error:
+   if (irq >= 0)
+   unbind_from_irqhandler(irq, map);
+   else if (*evtchn >= 0)
+   xenbus_free_evtchn(pvcalls_front_dev, *evtchn);
+   kfree(map->active.data.in);
+   kfree(map->active.ring);
+   return ret;
+}
+
+int pvcalls_front_connect(struct socket *sock, struct sockaddr *addr,
+   int addr_len, int flags)
+{
+   struct pvcalls_bedata *bedata;
+   struct sock_mapping *map = NULL;
+   struct xen_pvcalls_request *req;
+   int notify, req_id, ret, evtchn;
+
+   pvcalls_enter;
+   if (!pvcalls_front_dev) {
+   pvcalls_exit;
+   return -ENETUNREACH;
+   }
+   if (addr->sa_family != AF_INET || sock->type != SOCK_STREAM) {
+   pvcalls_exit;
+   return -ENOTSUPP;
+   }
+
+   bedata = dev_get_drvdata(&pvcalls_front_dev->dev);
+
+   map = (struct sock_mapping *) sock->sk->sk_send_head;
+   if (!map) {
+   pvcalls_exit;
+   return -ENOTSOCK;
+   }
+
+   spin_lock(&bedata->socket_lock);
+   ret 

[PATCH v4 06/13] xen/pvcalls: implement bind command

2017-09-15 Thread Stefano Stabellini
Send PVCALLS_BIND to the backend. Introduce a new structure, part of
struct sock_mapping, to store information specific to passive sockets.

Introduce a status field to keep track of the status of the passive
socket.

Signed-off-by: Stefano Stabellini 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 68 +
 drivers/xen/pvcalls-front.h |  3 ++
 2 files changed, 71 insertions(+)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index ef511b6..50b6588 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -72,6 +72,13 @@ struct sock_mapping {
 
wait_queue_head_t inflight_conn_req;
} active;
+   struct {
+   /* Socket status */
+#define PVCALLS_STATUS_UNINITALIZED  0
+#define PVCALLS_STATUS_BIND  1
+#define PVCALLS_STATUS_LISTEN2
+   uint8_t status;
+   } passive;
};
 };
 
@@ -346,6 +353,67 @@ int pvcalls_front_connect(struct socket *sock, struct 
sockaddr *addr,
return ret;
 }
 
+int pvcalls_front_bind(struct socket *sock, struct sockaddr *addr, int 
addr_len)
+{
+   struct pvcalls_bedata *bedata;
+   struct sock_mapping *map = NULL;
+   struct xen_pvcalls_request *req;
+   int notify, req_id, ret;
+
+   pvcalls_enter;
+   if (!pvcalls_front_dev) {
+   pvcalls_exit;
+   return -ENOTCONN;
+   }
+   if (addr->sa_family != AF_INET || sock->type != SOCK_STREAM) {
+   pvcalls_exit;
+   return -ENOTSUPP;
+   }
+   bedata = dev_get_drvdata(&pvcalls_front_dev->dev);
+
+   map = (struct sock_mapping *) sock->sk->sk_send_head;
+   if (map == NULL) {
+   pvcalls_exit;
+   return -ENOTSOCK;
+   }
+
+   spin_lock(&bedata->socket_lock);
+   ret = get_request(bedata, &req_id);
+   if (ret < 0) {
+   spin_unlock(&bedata->socket_lock);
+   pvcalls_exit;
+   return ret;
+   }
+   req = RING_GET_REQUEST(&bedata->ring, req_id);
+   req->req_id = req_id;
+   map->sock = sock;
+   req->cmd = PVCALLS_BIND;
+   req->u.bind.id = (uint64_t) map;
+   memcpy(req->u.bind.addr, addr, sizeof(*addr));
+   req->u.bind.len = addr_len;
+
+   init_waitqueue_head(&map->passive.inflight_accept_req);
+
+   map->active_socket = false;
+
+   bedata->ring.req_prod_pvt++;
+   RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify);
+   spin_unlock(&bedata->socket_lock);
+   if (notify)
+   notify_remote_via_irq(bedata->irq);
+
+   wait_event(bedata->inflight_req,
+  READ_ONCE(bedata->rsp[req_id].req_id) == req_id);
+
+   map->passive.status = PVCALLS_STATUS_BIND;
+   ret = bedata->rsp[req_id].ret;
+   /* read ret, then set this rsp slot to be reused */
+   smp_mb();
+   WRITE_ONCE(bedata->rsp[req_id].req_id, PVCALLS_INVALID_ID);
+   pvcalls_exit;
+   return 0;
+}
+
 static const struct xenbus_device_id pvcalls_front_ids[] = {
{ "pvcalls" },
{ "" }
diff --git a/drivers/xen/pvcalls-front.h b/drivers/xen/pvcalls-front.h
index 63b0417..8b0a274 100644
--- a/drivers/xen/pvcalls-front.h
+++ b/drivers/xen/pvcalls-front.h
@@ -6,5 +6,8 @@
 int pvcalls_front_socket(struct socket *sock);
 int pvcalls_front_connect(struct socket *sock, struct sockaddr *addr,
  int addr_len, int flags);
+int pvcalls_front_bind(struct socket *sock,
+  struct sockaddr *addr,
+  int addr_len);
 
 #endif
-- 
1.9.1



[PATCH v4 07/13] xen/pvcalls: implement listen command

2017-09-15 Thread Stefano Stabellini
Send PVCALLS_LISTEN to the backend.

Signed-off-by: Stefano Stabellini 
Reviewed-by: Boris Ostrovsky 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 56 +
 drivers/xen/pvcalls-front.h |  1 +
 2 files changed, 57 insertions(+)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 50b6588..4ecc1e5 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -414,6 +414,62 @@ int pvcalls_front_bind(struct socket *sock, struct 
sockaddr *addr, int addr_len)
return 0;
 }
 
+int pvcalls_front_listen(struct socket *sock, int backlog)
+{
+   struct pvcalls_bedata *bedata;
+   struct sock_mapping *map;
+   struct xen_pvcalls_request *req;
+   int notify, req_id, ret;
+
+   pvcalls_enter;
+   if (!pvcalls_front_dev) {
+   pvcalls_exit;
+   return -ENOTCONN;
+   }
+   bedata = dev_get_drvdata(&pvcalls_front_dev->dev);
+
+   map = (struct sock_mapping *) sock->sk->sk_send_head;
+   if (!map) {
+   pvcalls_exit;
+   return -ENOTSOCK;
+   }
+
+   if (map->passive.status != PVCALLS_STATUS_BIND) {
+   pvcalls_exit;
+   return -EOPNOTSUPP;
+   }
+
+   spin_lock(&bedata->socket_lock);
+   ret = get_request(bedata, &req_id);
+   if (ret < 0) {
+   spin_unlock(&bedata->socket_lock);
+   pvcalls_exit;
+   return ret;
+   }
+   req = RING_GET_REQUEST(&bedata->ring, req_id);
+   req->req_id = req_id;
+   req->cmd = PVCALLS_LISTEN;
+   req->u.listen.id = (uint64_t) map;
+   req->u.listen.backlog = backlog;
+
+   bedata->ring.req_prod_pvt++;
+   RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify);
+   spin_unlock(&bedata->socket_lock);
+   if (notify)
+   notify_remote_via_irq(bedata->irq);
+
+   wait_event(bedata->inflight_req,
+  READ_ONCE(bedata->rsp[req_id].req_id) == req_id);
+
+   map->passive.status = PVCALLS_STATUS_LISTEN;
+   ret = bedata->rsp[req_id].ret;
+   /* read ret, then set this rsp slot to be reused */
+   smp_mb();
+   WRITE_ONCE(bedata->rsp[req_id].req_id, PVCALLS_INVALID_ID);
+   pvcalls_exit;
+   return ret;
+}
+
 static const struct xenbus_device_id pvcalls_front_ids[] = {
{ "pvcalls" },
{ "" }
diff --git a/drivers/xen/pvcalls-front.h b/drivers/xen/pvcalls-front.h
index 8b0a274..aa8fe10 100644
--- a/drivers/xen/pvcalls-front.h
+++ b/drivers/xen/pvcalls-front.h
@@ -9,5 +9,6 @@ int pvcalls_front_connect(struct socket *sock, struct sockaddr 
*addr,
 int pvcalls_front_bind(struct socket *sock,
   struct sockaddr *addr,
   int addr_len);
+int pvcalls_front_listen(struct socket *sock, int backlog);
 
 #endif
-- 
1.9.1



[PATCH v4 08/13] xen/pvcalls: implement accept command

2017-09-15 Thread Stefano Stabellini
Introduce a waitqueue to allow only one outstanding accept command at
any given time and to implement polling on the passive socket. Introduce
a flags field to keep track of in-flight accept and poll commands.

Send PVCALLS_ACCEPT to the backend. Allocate a new active socket. Make
sure that only one accept command is executed at any given time by
setting PVCALLS_FLAG_ACCEPT_INFLIGHT and waiting on the
inflight_accept_req waitqueue.

Convert the new struct sock_mapping pointer into an uint64_t and use it
as id for the new socket to pass to the backend.

Check if the accept call is non-blocking: in that case after sending the
ACCEPT command to the backend store the sock_mapping pointer of the new
struct and the inflight req_id then return -EAGAIN (which will respond
only when there is something to accept). Next time accept is called,
we'll check if the ACCEPT command has been answered, if so we'll pick up
where we left off, otherwise we return -EAGAIN again.

Note that, differently from the other commands, we can use
wait_event_interruptible (instead of wait_event) in the case of accept
as we are able to track the req_id of the ACCEPT response that we are
waiting.

Signed-off-by: Stefano Stabellini 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 135 
 drivers/xen/pvcalls-front.h |   3 +
 2 files changed, 138 insertions(+)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 4ecc1e5..414eafd 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -78,6 +78,16 @@ struct sock_mapping {
 #define PVCALLS_STATUS_BIND  1
 #define PVCALLS_STATUS_LISTEN2
uint8_t status;
+   /*
+* Internal state-machine flags.
+* Only one accept operation can be inflight for a socket.
+* Only one poll operation can be inflight for a given socket.
+*/
+#define PVCALLS_FLAG_ACCEPT_INFLIGHT 0
+   uint8_t flags;
+   uint32_t inflight_req_id;
+   struct sock_mapping *accept_map;
+   wait_queue_head_t inflight_accept_req;
} passive;
};
 };
@@ -470,6 +480,131 @@ int pvcalls_front_listen(struct socket *sock, int backlog)
return ret;
 }
 
+int pvcalls_front_accept(struct socket *sock, struct socket *newsock, int 
flags)
+{
+   struct pvcalls_bedata *bedata;
+   struct sock_mapping *map;
+   struct sock_mapping *map2 = NULL;
+   struct xen_pvcalls_request *req;
+   int notify, req_id, ret, evtchn, nonblock;
+
+   pvcalls_enter;
+   if (!pvcalls_front_dev) {
+   pvcalls_exit;
+   return -ENOTCONN;
+   }
+   bedata = dev_get_drvdata(&pvcalls_front_dev->dev);
+
+   map = (struct sock_mapping *) sock->sk->sk_send_head;
+   if (!map) {
+   pvcalls_exit;
+   return -ENOTSOCK;
+   }
+
+   if (map->passive.status != PVCALLS_STATUS_LISTEN) {
+   pvcalls_exit;
+   return -EINVAL;
+   }
+
+   nonblock = flags & SOCK_NONBLOCK;
+   /*
+* Backend only supports 1 inflight accept request, will return
+* errors for the others
+*/
+   if (test_and_set_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT,
+(void *)&map->passive.flags)) {
+   req_id = READ_ONCE(map->passive.inflight_req_id);
+   if (req_id != PVCALLS_INVALID_ID &&
+   READ_ONCE(bedata->rsp[req_id].req_id) == req_id) {
+   map2 = map->passive.accept_map;
+   goto received;
+   }
+   if (nonblock) {
+   pvcalls_exit;
+   return -EAGAIN;
+   }
+   if (wait_event_interruptible(map->passive.inflight_accept_req,
+   !test_and_set_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT,
+ (void *)&map->passive.flags))) {
+   pvcalls_exit;
+   return -EINTR;
+   }
+   }
+
+   spin_lock(&bedata->socket_lock);
+   ret = get_request(bedata, &req_id);
+   if (ret < 0) {
+   spin_unlock(&bedata->socket_lock);
+   pvcalls_exit;
+   return ret;
+   }
+   map2 = kzalloc(sizeof(*map2), GFP_KERNEL);
+   if (map2 == NULL) {
+   spin_unlock(&bedata->socket_lock);
+   pvcalls_exit;
+   return -ENOMEM;
+   }
+   ret =  create_active(map2, &evtchn);
+   if (ret < 0) {
+   kfree(map2);
+   spin_unlock(&bedata->socket_lock);
+   pvcalls_exit;
+   return -ENOMEM;
+   }
+   list_add_tail(&map2->list, &bedata->socket_mappings);
+
+   req = RING_GET_REQUEST(&bedata->ring, req_id);
+   

[PATCH v4 10/13] xen/pvcalls: implement recvmsg

2017-09-15 Thread Stefano Stabellini
Implement recvmsg by copying data from the "in" ring. If not enough data
is available and the recvmsg call is blocking, then wait on the
inflight_conn_req waitqueue. Take the active socket in_mutex so that
only one function can access the ring at any given time.

Signed-off-by: Stefano Stabellini 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 110 
 drivers/xen/pvcalls-front.h |   4 ++
 2 files changed, 114 insertions(+)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 2907e85..01a5a69 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -118,6 +118,20 @@ static bool pvcalls_front_write_todo(struct sock_mapping 
*map)
return !!(size - pvcalls_queued(prod, cons, size));
 }
 
+static bool pvcalls_front_read_todo(struct sock_mapping *map)
+{
+   struct pvcalls_data_intf *intf = map->active.ring;
+   RING_IDX cons, prod;
+   int32_t error;
+
+   cons = intf->in_cons;
+   prod = intf->in_prod;
+   error = intf->in_error;
+   return (error != 0 ||
+   pvcalls_queued(prod, cons,
+  XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER)) != 0);
+}
+
 static irqreturn_t pvcalls_front_event_handler(int irq, void *dev_id)
 {
struct xenbus_device *dev = dev_id;
@@ -482,6 +496,102 @@ int pvcalls_front_sendmsg(struct socket *sock, struct 
msghdr *msg,
return tot_sent;
 }
 
+static int __read_ring(struct pvcalls_data_intf *intf,
+  struct pvcalls_data *data,
+  struct iov_iter *msg_iter,
+  size_t len, int flags)
+{
+   RING_IDX cons, prod, size, masked_prod, masked_cons;
+   RING_IDX array_size = XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER);
+   int32_t error;
+
+   cons = intf->in_cons;
+   prod = intf->in_prod;
+   error = intf->in_error;
+   /* get pointers before reading from the ring */
+   virt_rmb();
+   if (error < 0)
+   return error;
+
+   size = pvcalls_queued(prod, cons, array_size);
+   masked_prod = pvcalls_mask(prod, array_size);
+   masked_cons = pvcalls_mask(cons, array_size);
+
+   if (size == 0)
+   return 0;
+
+   if (len > size)
+   len = size;
+
+   if (masked_prod > masked_cons) {
+   copy_to_iter(data->in + masked_cons, len, msg_iter);
+   } else {
+   if (len > (array_size - masked_cons)) {
+   copy_to_iter(data->in + masked_cons,
+array_size - masked_cons, msg_iter);
+   copy_to_iter(data->in,
+len - (array_size - masked_cons),
+msg_iter);
+   } else {
+   copy_to_iter(data->in + masked_cons, len, msg_iter);
+   }
+   }
+   /* read data from the ring before increasing the index */
+   virt_mb();
+   if (!(flags & MSG_PEEK))
+   intf->in_cons += len;
+
+   return len;
+}
+
+int pvcalls_front_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
+int flags)
+{
+   struct pvcalls_bedata *bedata;
+   int ret;
+   struct sock_mapping *map;
+
+   pvcalls_enter;
+   if (!pvcalls_front_dev) {
+   pvcalls_exit;
+   return -ENOTCONN;
+   }
+   bedata = dev_get_drvdata(&pvcalls_front_dev->dev);
+
+   map = (struct sock_mapping *) sock->sk->sk_send_head;
+   if (!map) {
+   pvcalls_exit;
+   return -ENOTSOCK;
+   }
+
+   if (flags & (MSG_CMSG_CLOEXEC|MSG_ERRQUEUE|MSG_OOB|MSG_TRUNC)) {
+   pvcalls_exit;
+   return -EOPNOTSUPP;
+   }
+
+   mutex_lock(&map->active.in_mutex);
+   if (len > XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER))
+   len = XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER);
+
+   while (!(flags & MSG_DONTWAIT) && !pvcalls_front_read_todo(map)) {
+   wait_event_interruptible(map->active.inflight_conn_req,
+pvcalls_front_read_todo(map));
+   }
+   ret = __read_ring(map->active.ring, &map->active.data,
+ &msg->msg_iter, len, flags);
+
+   if (ret > 0)
+   notify_remote_via_irq(map->active.irq);
+   if (ret == 0)
+   ret = -EAGAIN;
+   if (ret == -ENOTCONN)
+   ret = 0;
+
+   mutex_unlock(&map->active.in_mutex);
+   pvcalls_exit;
+   return ret;
+}
+
 int pvcalls_front_bind(struct socket *sock, struct sockaddr *addr, int 
addr_len)
 {
struct pvcalls_bedata *bedata;
diff --git a/drivers/xen/pvcalls-front.h b/drivers/xen/pvcalls-front.h
index d937c24..de24041 100644
--- a/drivers/xen/pvcalls-front.h
+++ b/drivers/xen/pvcalls-front.h
@@ -16,5 +16,9 @@ int pvcalls_front_accept(struct socket *so

[PATCH v4 11/13] xen/pvcalls: implement poll command

2017-09-15 Thread Stefano Stabellini
For active sockets, check the indexes and use the inflight_conn_req
waitqueue to wait.

For passive sockets if an accept is outstanding
(PVCALLS_FLAG_ACCEPT_INFLIGHT), check if it has been answered by looking
at bedata->rsp[req_id]. If so, return POLLIN.  Otherwise use the
inflight_accept_req waitqueue.

If no accepts are inflight, send PVCALLS_POLL to the backend. If we have
outstanding POLL requests awaiting for a response use the inflight_req
waitqueue: inflight_req is awaken when a new response is received; on
wakeup we check whether the POLL response is arrived by looking at the
PVCALLS_FLAG_POLL_RET flag. We set the flag from
pvcalls_front_event_handler, if the response was for a POLL command.

In pvcalls_front_event_handler, get the struct sock_mapping from the
poll id (we previously converted struct sock_mapping* to uint64_t and
used it as id).

Signed-off-by: Stefano Stabellini 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 144 +---
 drivers/xen/pvcalls-front.h |   3 +
 2 files changed, 138 insertions(+), 9 deletions(-)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 01a5a69..8a90213 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -85,6 +85,8 @@ struct sock_mapping {
 * Only one poll operation can be inflight for a given socket.
 */
 #define PVCALLS_FLAG_ACCEPT_INFLIGHT 0
+#define PVCALLS_FLAG_POLL_INFLIGHT   1
+#define PVCALLS_FLAG_POLL_RET2
uint8_t flags;
uint32_t inflight_req_id;
struct sock_mapping *accept_map;
@@ -155,15 +157,32 @@ static irqreturn_t pvcalls_front_event_handler(int irq, 
void *dev_id)
rsp = RING_GET_RESPONSE(&bedata->ring, bedata->ring.rsp_cons);
 
req_id = rsp->req_id;
-   dst = (uint8_t *)&bedata->rsp[req_id] + sizeof(rsp->req_id);
-   src = (uint8_t *)rsp + sizeof(rsp->req_id);
-   memcpy(dst, src, sizeof(*rsp) - sizeof(rsp->req_id));
-   /*
-* First copy the rest of the data, then req_id. It is
-* paired with the barrier when accessing bedata->rsp.
-*/
-   smp_wmb();
-   WRITE_ONCE(bedata->rsp[req_id].req_id, rsp->req_id);
+   if (rsp->cmd == PVCALLS_POLL) {
+   struct sock_mapping *map = (struct sock_mapping *)
+  rsp->u.poll.id;
+
+   set_bit(PVCALLS_FLAG_POLL_RET,
+   (void *)&map->passive.flags);
+   /*
+* Set RET, then clear INFLIGHT. It pairs with
+* the checks at the beginning of
+* pvcalls_front_poll_passive.
+*/
+   smp_wmb();
+   clear_bit(PVCALLS_FLAG_POLL_INFLIGHT,
+ (void *)&map->passive.flags);
+   } else {
+   dst = (uint8_t *)&bedata->rsp[req_id] +
+ sizeof(rsp->req_id);
+   src = (uint8_t *)rsp + sizeof(rsp->req_id);
+   memcpy(dst, src, sizeof(*rsp) - sizeof(rsp->req_id));
+   /*
+* First copy the rest of the data, then req_id. It is
+* paired with the barrier when accessing bedata->rsp.
+*/
+   smp_wmb();
+   WRITE_ONCE(bedata->rsp[req_id].req_id, rsp->req_id);
+   }
 
done = 1;
bedata->ring.rsp_cons++;
@@ -834,6 +853,113 @@ int pvcalls_front_accept(struct socket *sock, struct 
socket *newsock, int flags)
return ret;
 }
 
+static unsigned int pvcalls_front_poll_passive(struct file *file,
+  struct pvcalls_bedata *bedata,
+  struct sock_mapping *map,
+  poll_table *wait)
+{
+   int notify, req_id, ret;
+   struct xen_pvcalls_request *req;
+
+   if (test_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT,
+(void *)&map->passive.flags)) {
+   uint32_t req_id = READ_ONCE(map->passive.inflight_req_id);
+
+   if (req_id != PVCALLS_INVALID_ID &&
+   READ_ONCE(bedata->rsp[req_id].req_id) == req_id)
+   return POLLIN | POLLRDNORM;
+
+   poll_wait(file, &map->passive.inflight_accept_req, wait);
+   return 0;
+   }
+
+   if (test_and_clear_bit(PVCALLS_FLAG_POLL_RET,
+  (void *)&map->passive.flags))
+   return POLLIN | POLLRDNORM;
+
+   /*
+* First check RET, then INFLIGHT. No barriers necessary 

[PATCH v4 09/13] xen/pvcalls: implement sendmsg

2017-09-15 Thread Stefano Stabellini
Send data to an active socket by copying data to the "out" ring. Take
the active socket out_mutex so that only one function can access the
ring at any given time.

If not enough room is available on the ring, rather than returning
immediately or sleep-waiting, spin for up to 5000 cycles. This small
optimization turns out to improve performance significantly.

Signed-off-by: Stefano Stabellini 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 119 
 drivers/xen/pvcalls-front.h |   3 ++
 2 files changed, 122 insertions(+)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 414eafd..2907e85 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -29,6 +29,7 @@
 #define PVCALLS_INVALID_ID UINT_MAX
 #define PVCALLS_RING_ORDER XENBUS_MAX_RING_GRANT_ORDER
 #define PVCALLS_NR_REQ_PER_RING __CONST_RING_SIZE(xen_pvcalls, XEN_PAGE_SIZE)
+#define PVCALLS_FRONT_MAX_SPIN 5000
 
 struct pvcalls_bedata {
struct xen_pvcalls_front_ring ring;
@@ -101,6 +102,22 @@ static inline int get_request(struct pvcalls_bedata 
*bedata, int *req_id)
return 0;
 }
 
+static bool pvcalls_front_write_todo(struct sock_mapping *map)
+{
+   struct pvcalls_data_intf *intf = map->active.ring;
+   RING_IDX cons, prod, size = XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER);
+   int32_t error;
+
+   cons = intf->out_cons;
+   prod = intf->out_prod;
+   error = intf->out_error;
+   if (error == -ENOTCONN)
+   return false;
+   if (error != 0)
+   return true;
+   return !!(size - pvcalls_queued(prod, cons, size));
+}
+
 static irqreturn_t pvcalls_front_event_handler(int irq, void *dev_id)
 {
struct xenbus_device *dev = dev_id;
@@ -363,6 +380,108 @@ int pvcalls_front_connect(struct socket *sock, struct 
sockaddr *addr,
return ret;
 }
 
+static int __write_ring(struct pvcalls_data_intf *intf,
+   struct pvcalls_data *data,
+   struct iov_iter *msg_iter,
+   int len)
+{
+   RING_IDX cons, prod, size, masked_prod, masked_cons;
+   RING_IDX array_size = XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER);
+   int32_t error;
+
+   error = intf->out_error;
+   if (error < 0)
+   return error;
+   cons = intf->out_cons;
+   prod = intf->out_prod;
+   /* read indexes before continuing */
+   virt_mb();
+
+   size = pvcalls_queued(prod, cons, array_size);
+   if (size >= array_size)
+   return 0;
+   if (len > array_size - size)
+   len = array_size - size;
+
+   masked_prod = pvcalls_mask(prod, array_size);
+   masked_cons = pvcalls_mask(cons, array_size);
+
+   if (masked_prod < masked_cons) {
+   copy_from_iter(data->out + masked_prod, len, msg_iter);
+   } else {
+   if (len > array_size - masked_prod) {
+   copy_from_iter(data->out + masked_prod,
+  array_size - masked_prod, msg_iter);
+   copy_from_iter(data->out,
+  len - (array_size - masked_prod),
+  msg_iter);
+   } else {
+   copy_from_iter(data->out + masked_prod, len, msg_iter);
+   }
+   }
+   /* write to ring before updating pointer */
+   virt_wmb();
+   intf->out_prod += len;
+
+   return len;
+}
+
+int pvcalls_front_sendmsg(struct socket *sock, struct msghdr *msg,
+ size_t len)
+{
+   struct pvcalls_bedata *bedata;
+   struct sock_mapping *map;
+   int sent, tot_sent = 0;
+   int count = 0, flags;
+
+   pvcalls_enter;
+   if (!pvcalls_front_dev) {
+   pvcalls_exit;
+   return -ENOTCONN;
+   }
+   bedata = dev_get_drvdata(&pvcalls_front_dev->dev);
+
+   map = (struct sock_mapping *) sock->sk->sk_send_head;
+   if (!map) {
+   pvcalls_exit;
+   return -ENOTSOCK;
+   }
+
+   flags = msg->msg_flags;
+   if (flags & (MSG_CONFIRM|MSG_DONTROUTE|MSG_EOR|MSG_OOB)) {
+   pvcalls_exit;
+   return -EOPNOTSUPP;
+   }
+
+   mutex_lock(&map->active.out_mutex);
+   if ((flags & MSG_DONTWAIT) && !pvcalls_front_write_todo(map)) {
+   mutex_unlock(&map->active.out_mutex);
+   pvcalls_exit;
+   return -EAGAIN;
+   }
+   if (len > INT_MAX)
+   len = INT_MAX;
+
+again:
+   count++;
+   sent = __write_ring(map->active.ring,
+   &map->active.data, &msg->msg_iter,
+   len);
+   if (sent > 0) {
+   len -= sent;
+   tot_sent += sent;
+   notify_remote_via_irq(map->active.irq);
+   }
+   if (sent >= 0 && len > 0 && count < 

[PATCH v4 02/13] xen/pvcalls: implement frontend disconnect

2017-09-15 Thread Stefano Stabellini
Introduce a data structure named pvcalls_bedata. It contains pointers to
the command ring, the event channel, a list of active sockets and a list
of passive sockets. Lists accesses are protected by a spin_lock.

Introduce a waitqueue to allow waiting for a response on commands sent
to the backend.

Introduce an array of struct xen_pvcalls_response to store commands
responses.

pvcalls_refcount is used to keep count of the outstanding pvcalls users.
Only remove connections once the refcount is zero.

Implement pvcalls frontend removal function. Go through the list of
active and passive sockets and free them all, one at a time.

Signed-off-by: Stefano Stabellini 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 63 +
 1 file changed, 63 insertions(+)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index a8d38c2..67c8337 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -20,6 +20,42 @@
 #include 
 #include 
 
+#define PVCALLS_INVALID_ID UINT_MAX
+#define PVCALLS_RING_ORDER XENBUS_MAX_RING_GRANT_ORDER
+#define PVCALLS_NR_REQ_PER_RING __CONST_RING_SIZE(xen_pvcalls, XEN_PAGE_SIZE)
+
+struct pvcalls_bedata {
+   struct xen_pvcalls_front_ring ring;
+   grant_ref_t ref;
+   int irq;
+
+   struct list_head socket_mappings;
+   struct list_head socketpass_mappings;
+   spinlock_t socket_lock;
+
+   wait_queue_head_t inflight_req;
+   struct xen_pvcalls_response rsp[PVCALLS_NR_REQ_PER_RING];
+};
+static struct xenbus_device *pvcalls_front_dev;
+static atomic_t pvcalls_refcount;
+
+/* first increment refcount, then proceed */
+#define pvcalls_enter { \
+   atomic_inc(&pvcalls_refcount);  \
+   smp_mb();   \
+}
+
+/* first complete other operations, then decrement refcount */
+#define pvcalls_exit {  \
+   smp_mb();   \
+   atomic_dec(&pvcalls_refcount);  \
+}
+
+static irqreturn_t pvcalls_front_event_handler(int irq, void *dev_id)
+{
+   return IRQ_HANDLED;
+}
+
 static const struct xenbus_device_id pvcalls_front_ids[] = {
{ "pvcalls" },
{ "" }
@@ -27,6 +63,33 @@
 
 static int pvcalls_front_remove(struct xenbus_device *dev)
 {
+   struct pvcalls_bedata *bedata;
+   struct sock_mapping *map = NULL, *n;
+
+   bedata = dev_get_drvdata(&pvcalls_front_dev->dev);
+   dev_set_drvdata(&dev->dev, NULL);
+   pvcalls_front_dev = NULL;
+   if (bedata->irq >= 0)
+   unbind_from_irqhandler(bedata->irq, dev);
+
+   smp_mb();
+   while (atomic_read(&pvcalls_refcount) > 0)
+   cpu_relax();
+   list_for_each_entry_safe(map, n, &bedata->socket_mappings, list) {
+   pvcalls_front_free_map(bedata, map);
+   kfree(map);
+   }
+   list_for_each_entry_safe(map, n, &bedata->socketpass_mappings, list) {
+   spin_lock(&bedata->socket_lock);
+   list_del_init(&map->list);
+   spin_unlock(&bedata->socket_lock);
+   kfree(map);
+   }
+   if (bedata->ref >= 0)
+   gnttab_end_foreign_access(bedata->ref, 0, 0);
+   kfree(bedata->ring.sring);
+   kfree(bedata);
+   xenbus_switch_state(dev, XenbusStateClosed);
return 0;
 }
 
-- 
1.9.1



[PATCH v4 13/13] xen: introduce a Kconfig option to enable the pvcalls frontend

2017-09-15 Thread Stefano Stabellini
Also add pvcalls-front to the Makefile.

Signed-off-by: Stefano Stabellini 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/Kconfig  | 9 +
 drivers/xen/Makefile | 1 +
 2 files changed, 10 insertions(+)

diff --git a/drivers/xen/Kconfig b/drivers/xen/Kconfig
index 4545561..0b2c828 100644
--- a/drivers/xen/Kconfig
+++ b/drivers/xen/Kconfig
@@ -196,6 +196,15 @@ config XEN_PCIDEV_BACKEND
 
  If in doubt, say m.
 
+config XEN_PVCALLS_FRONTEND
+   tristate "XEN PV Calls frontend driver"
+   depends on INET && XEN
+   help
+ Experimental frontend for the Xen PV Calls protocol
+ (https://xenbits.xen.org/docs/unstable/misc/pvcalls.html). It
+ sends a small set of POSIX calls to the backend, which
+ implements them.
+
 config XEN_PVCALLS_BACKEND
bool "XEN PV Calls backend driver"
depends on INET && XEN && XEN_BACKEND
diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile
index 480b928..afb9e03 100644
--- a/drivers/xen/Makefile
+++ b/drivers/xen/Makefile
@@ -39,6 +39,7 @@ obj-$(CONFIG_XEN_EFI) += efi.o
 obj-$(CONFIG_XEN_SCSI_BACKEND) += xen-scsiback.o
 obj-$(CONFIG_XEN_AUTO_XLATE)   += xlate_mmu.o
 obj-$(CONFIG_XEN_PVCALLS_BACKEND)  += pvcalls-back.o
+obj-$(CONFIG_XEN_PVCALLS_FRONTEND) += pvcalls-front.o
 xen-evtchn-y   := evtchn.o
 xen-gntdev-y   := gntdev.o
 xen-gntalloc-y := gntalloc.o
-- 
1.9.1



[PATCH v4 12/13] xen/pvcalls: implement release command

2017-09-15 Thread Stefano Stabellini
Send PVCALLS_RELEASE to the backend and wait for a reply. Take both
in_mutex and out_mutex to avoid concurrent accesses. Then, free the
socket.

For passive sockets, check whether we have already pre-allocated an
active socket for the purpose of being accepted. If so, free that as
well.

Signed-off-by: Stefano Stabellini 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 104 
 drivers/xen/pvcalls-front.h |   1 +
 2 files changed, 105 insertions(+)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 8a90213..5f8e94a 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -209,6 +209,24 @@ static irqreturn_t pvcalls_front_conn_handler(int irq, 
void *sock_map)
return IRQ_HANDLED;
 }
 
+static void pvcalls_front_free_map(struct pvcalls_bedata *bedata,
+  struct sock_mapping *map)
+{
+   int i;
+
+   unbind_from_irqhandler(map->active.irq, map);
+
+   spin_lock(&bedata->socket_lock);
+   if (!list_empty(&map->list))
+   list_del_init(&map->list);
+   spin_unlock(&bedata->socket_lock);
+
+   for (i = 0; i < (1 << PVCALLS_RING_ORDER); i++)
+   gnttab_end_foreign_access(map->active.ring->ref[i], 0, 0);
+   gnttab_end_foreign_access(map->active.ref, 0, 0);
+   free_page((unsigned long)map->active.ring);
+}
+
 int pvcalls_front_socket(struct socket *sock)
 {
struct pvcalls_bedata *bedata;
@@ -960,6 +978,92 @@ unsigned int pvcalls_front_poll(struct file *file, struct 
socket *sock,
return ret;
 }
 
+int pvcalls_front_release(struct socket *sock)
+{
+   struct pvcalls_bedata *bedata;
+   struct sock_mapping *map;
+   int req_id, notify, ret;
+   struct xen_pvcalls_request *req;
+
+   pvcalls_enter;
+   if (!pvcalls_front_dev) {
+   pvcalls_exit;
+   return -EIO;
+   }
+   if (sock->sk == NULL) {
+   pvcalls_exit;
+   return 0;
+   }
+
+   bedata = dev_get_drvdata(&pvcalls_front_dev->dev);
+
+   map = (struct sock_mapping *) sock->sk->sk_send_head;
+   if (map == NULL) {
+   pvcalls_exit;
+   return 0;
+   }
+
+   spin_lock(&bedata->socket_lock);
+   ret = get_request(bedata, &req_id);
+   if (ret < 0) {
+   spin_unlock(&bedata->socket_lock);
+   pvcalls_exit;
+   return ret;
+   }
+   sock->sk->sk_send_head = NULL;
+
+   req = RING_GET_REQUEST(&bedata->ring, req_id);
+   req->req_id = req_id;
+   req->cmd = PVCALLS_RELEASE;
+   req->u.release.id = (uint64_t)map;
+
+   bedata->ring.req_prod_pvt++;
+   RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify);
+   spin_unlock(&bedata->socket_lock);
+   if (notify)
+   notify_remote_via_irq(bedata->irq);
+
+   wait_event(bedata->inflight_req,
+  READ_ONCE(bedata->rsp[req_id].req_id) == req_id);
+
+   if (map->active_socket) {
+   /*
+* Set in_error and wake up inflight_conn_req to force
+* recvmsg waiters to exit.
+*/
+   map->active.ring->in_error = -EBADF;
+   wake_up_interruptible(&map->active.inflight_conn_req);
+
+   /*
+* Wait until there are no more waiters on the mutexes.
+* We know that no new waiters can be added because sk_send_head
+* is set to NULL -- we only need to wait for the existing
+* waiters to return.
+*/
+   while (!mutex_trylock(&map->active.in_mutex) ||
+  !mutex_trylock(&map->active.out_mutex))
+   cpu_relax();
+
+   pvcalls_front_free_map(bedata, map);
+   kfree(map);
+   } else {
+   spin_lock(&bedata->socket_lock);
+   if (READ_ONCE(map->passive.inflight_req_id) !=
+   PVCALLS_INVALID_ID) {
+   pvcalls_front_free_map(bedata,
+  map->passive.accept_map);
+   kfree(map->passive.accept_map);
+   }
+   list_del_init(&map->list);
+   kfree(map);
+   spin_unlock(&bedata->socket_lock);
+   }
+   WRITE_ONCE(bedata->rsp[req_id].req_id, PVCALLS_INVALID_ID);
+
+   pvcalls_exit;
+   return 0;
+}
+
 static const struct xenbus_device_id pvcalls_front_ids[] = {
{ "pvcalls" },
{ "" }
diff --git a/drivers/xen/pvcalls-front.h b/drivers/xen/pvcalls-front.h
index 25e05b8..3332978 100644
--- a/drivers/xen/pvcalls-front.h
+++ b/drivers/xen/pvcalls-front.h
@@ -23,5 +23,6 @@ int pvcalls_front_recvmsg(struct socket *sock,
 unsigned int pvcalls_front_poll(struct file *file,
struct socket *sock,
  

[PATCH v4 00/13] introduce the Xen PV Calls frontend

2017-09-15 Thread Stefano Stabellini
Hi all,

this series introduces the frontend for the newly introduced PV Calls
procotol.

PV Calls is a paravirtualized protocol that allows the implementation of
a set of POSIX functions in a different domain. The PV Calls frontend
sends POSIX function calls to the backend, which implements them and
returns a value to the frontend and acts on the function call.

For more information about PV Calls, please read:

https://xenbits.xen.org/docs/unstable/misc/pvcalls.html

This patch series only implements the frontend driver. It doesn't
attempt to redirect POSIX calls to it. The functions exported in
pvcalls-front.h are meant to be used for that. A separate patch series
will be sent to use them and hook them into the system.



Changes in v4:

In this version of the series I introduced a global refcount to keep
track of outstanding users of the pvcalls functions. refcount is
increased on entering a pvcalls frontend function and is decreased on
returning from it. This is necessary to figure out the right time to
deallocate pvcalls frontend resources in pvcalls_front_remove.

A similar, more limited, issue affects pvcalls_front_release: it needs
to find out the right time to free a single active socket mapping. The
outstanding users are sendmsg and recvmsg. Instead of adding another
refcount, I am reusing the existing in_mutex and out_mutex to find out
if there are outstanding users of the socket mapping. It is safe because
we know that there cannot be any new sendmsg and recvmsg callers not
already waiting for one of the two mutexes.

- introduce pvcalls_refcount to avoid removing data structs that are
  still in-use
- set pvcalls_front_dev to NULL first in pvcalls_front_remove
- use mutex_trylock to check the state of in_mutex and out_mutex before
  freeing a map in pvcalls_front_release
- rename pvcallss_lock to socket_lock
- add a comment on XENBUS_FUNCTIONS_CALLS
- fix the irq check to >= 0
- initialize socket_mappings in pvcalls_front_probe so that
  pvcalls_front_remove can deal with it properly
- use IPPROTO_IP
- free new mapping in pvcalls_front_socket in case of errors
- no need to zero map->active.ring twice
- use PVCALLS_RING_ORDER instead of map->active.ring->ring_order
- set *evtchn to -1 at the beginning of create_active
- don't free map in create_active in case of errors, it should be freed
  by a release command
- add reviewed-bys
- free map2 in case of errors in pvcalls_front_accept
- properly unlock in error paths in pvcalls_front_accept
- make pvcalls_front_write_todo return bool
- move the error check before the barrier in __write_ring
- add a check "len >= INT_MAX" in pvcalls_front_sendmsg
- make the len parameter of __write_ring an int
- don't initialize sent in pvcalls_front_sendmsg
- make the error value for sk_send_head being zero consistent
- don't initialize ret in pvcalls_front_recvmsg
- unbind_from_irqhandler before doing anything else in
  pvcalls_front_free_map
- move the "sock->sk == NULL" check before bedata access in
  pvcalls_front_release
- no need to use READ/WRITE_ONCE to access sk_send_head


Stefano Stabellini (13):
  xen/pvcalls: introduce the pvcalls xenbus frontend
  xen/pvcalls: implement frontend disconnect
  xen/pvcalls: connect to the backend
  xen/pvcalls: implement socket command and handle events
  xen/pvcalls: implement connect command
  xen/pvcalls: implement bind command
  xen/pvcalls: implement listen command
  xen/pvcalls: implement accept command
  xen/pvcalls: implement sendmsg
  xen/pvcalls: implement recvmsg
  xen/pvcalls: implement poll command
  xen/pvcalls: implement release command
  xen: introduce a Kconfig option to enable the pvcalls frontend

 drivers/xen/Kconfig |9 +
 drivers/xen/Makefile|1 +
 drivers/xen/pvcalls-front.c | 1273 +++
 drivers/xen/pvcalls-front.h |   28 +
 4 files changed, 1311 insertions(+)
 create mode 100644 drivers/xen/pvcalls-front.c
 create mode 100644 drivers/xen/pvcalls-front.h


Linux 3.2.93

2017-09-15 Thread Ben Hutchings
I'm announcing the release of the 3.2.93 kernel.

All users of the 3.2 kernel series should upgrade.

The updated 3.2.y git tree can be found at:
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git 
linux-3.2.y
and can be browsed at the normal kernel.org git web browser:
https://git.kernel.org/?p=linux/kernel/git/stable/linux-stable.git

The diff from 3.2.92 is attached to this message.

Ben.



 Makefile   |  2 +-
 arch/alpha/kernel/osf_sys.c|  6 +-
 arch/mips/include/asm/kprobes.h|  3 +-
 arch/mips/kernel/entry.S   |  3 +
 arch/powerpc/include/asm/page.h| 12 +++
 arch/powerpc/kernel/kprobes.c  | 12 +++
 arch/powerpc/kernel/setup_64.c | 25 ++
 arch/x86/kvm/mmu.c |  7 +-
 arch/x86/kvm/mmu.h |  1 +
 arch/x86/kvm/x86.c | 53 -
 crypto/gcm.c   |  6 +-
 drivers/ata/ahci.c | 38 +
 drivers/char/mem.c |  5 ++
 drivers/dma/ep93xx_dma.c   |  2 +
 drivers/gpu/drm/radeon/radeon_combios.c|  7 ++
 drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c   |  2 +
 drivers/i2c/busses/i2c-tiny-usb.c  | 25 +-
 drivers/input/serio/i8042-x86ia64io.h  |  7 ++
 drivers/media/rc/ir-raw.c  | 13 ++--
 drivers/media/video/videobuf2-core.c   |  4 +-
 drivers/net/ethernet/8390/ax88796.c|  7 +-
 drivers/net/ethernet/ethoc.c   |  3 +-
 drivers/net/irda/irda-usb.c|  2 +-
 drivers/net/phy/marvell.c  | 68 
 drivers/of/fdt.c   |  2 +
 drivers/scsi/qla2xxx/qla_os.c  |  8 +-
 drivers/staging/gma500/psb_intel_lvds.c| 18 +++--
 drivers/staging/usbip/vhci_hcd.c   | 11 ++-
 drivers/usb/core/devio.c   |  4 +-
 drivers/usb/core/hcd.c |  4 +-
 drivers/usb/core/hub.c | 28 +--
 drivers/usb/gadget/dummy_hcd.c |  6 +-
 drivers/usb/gadget/f_mass_storage.c| 13 +++-
 drivers/usb/host/r8a66597-hcd.c|  6 +-
 drivers/usb/host/xhci-hub.c| 37 +
 drivers/usb/host/xhci-mem.c|  2 +-
 drivers/usb/host/xhci-pci.c| 16 +++-
 drivers/usb/host/xhci-ring.c   | 37 +
 drivers/usb/host/xhci.h|  3 +
 drivers/usb/misc/iowarrior.c   |  2 +-
 drivers/usb/musb/tusb6010_omap.c   | 13 +++-
 drivers/usb/serial/ftdi_sio.c  |  2 +-
 drivers/usb/serial/io_ti.c |  5 +-
 drivers/usb/serial/ir-usb.c| 21 ++---
 drivers/usb/serial/mct_u232.c  |  2 +-
 drivers/usb/storage/ene_ub6250.c   | 90 +-
 drivers/uwb/i1480/dfu/usb.c|  5 +-
 drivers/watchdog/pcwd_usb.c|  3 +
 drivers/xen/biomerge.c |  3 +-
 fs/autofs4/dev-ioctl.c |  2 +-
 fs/configfs/symlink.c  |  3 +-
 fs/ext4/extents.c  |  2 +
 fs/ext4/inode.c| 31 ++--
 fs/partitions/check.c  |  4 +-
 fs/proc/array.c|  2 +-
 fs/proc/base.c | 12 +--
 fs/proc/namespaces.c   |  4 +-
 fs/ufs/inode.c |  5 +-
 fs/ufs/super.c | 18 +
 fs/ufs/truncate.c  |  6 --
 fs/ufs/util.h  | 10 ++-
 include/linux/kprobes.h|  4 +-
 include/linux/ptrace.h | 24 +-
 include/linux/skbuff.h |  1 +
 include/linux/usb/ch11.h   |  3 +
 include/net/xfrm.h | 10 ---
 kernel/events/core.c   |  2 +-
 kernel/futex.c |  2 +-
 kernel/futex_compat.c  |  2 +-
 kernel/kprobes.c   |  2 +-
 kernel/ptrace.c| 39 --
 kernel/signal.c| 20 +++--
 kernel/time/alarmtimer.c   | 12 ++-
 kernel/trace/trace_kprobe.c| 18 +

Re: [PATCH] scripts/dtc: update dtx_diff cpp and dts include paths to match build

2017-09-15 Thread Rob Herring
On Fri, Sep 15, 2017 at 5:16 PM,   wrote:
> From: Frank Rowand 

I feel like we just had the same subject. Can you make it more specific.

> Update dtx_diff include paths in the same manner as:
> commit b12869a8d519 ("of: remove drivers/of/testcase-data from
> include search path for CPP"), commit 5ffa2aed389c ("of: remove
> arch/$(SRCARCH)/boot/dts from include search path for CPP"), and
> commit 50f9ddaf64e1 ("of: search scripts/dtc/include-prefixes path
> for both CPP and DTC").

We need a better way for this to stop happening besides me remembering
in reviews...

Perhaps a separate file of include paths that all tools can use?

>
> Remove proposed include path kernel/dts/, which was never implemented
> for the dtb build.
>
> For the diff case, each source file is compiled separately.  For
> each of those compiles, provide the location of the source file
> as an include path, not the location of both source files.
>
> ---
>
> The referenced commits b12869a8d519, 5ffa2aed389c, 50f9ddaf64e1
> are in v4.14-rc1.  No stable kernels need this patch.
>
>  scripts/dtc/dtx_diff |   22 +-
>  1 file changed, 9 insertions(+), 13 deletions(-)
>
> Signed-off-by: Frank Rowand 

This is going to get dropped.

Rob


Re: [PATCH v2 4/5] watchdog: jz4740: Add support for the watchdog in jz4780 SoC

2017-09-15 Thread Guenter Roeck
On Fri, Sep 15, 2017 at 09:20:19PM +0200, Mathieu Malaterre wrote:
> The watchdog unit present in the JZ4780 works the same as the one in the
> JZ4740.
> 
> Signed-off-by: Mathieu Malaterre 
> ---
> Changes in v2:
> * do not re-use the compatible string for different SoC (Paul Cercueil)

I thought that was one of the specific features of compatible statements,
to avoid having to change the driver each time a new chip comes along.
Did that change recently ?

Guenter

> 
>  drivers/watchdog/jz4740_wdt.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/watchdog/jz4740_wdt.c b/drivers/watchdog/jz4740_wdt.c
> index 20627f22baf6..aafbeb96561b 100644
> --- a/drivers/watchdog/jz4740_wdt.c
> +++ b/drivers/watchdog/jz4740_wdt.c
> @@ -146,6 +146,7 @@ static const struct watchdog_ops jz4740_wdt_ops = {
>  #ifdef CONFIG_OF
>  static const struct of_device_id jz4740_wdt_of_matches[] = {
>   { .compatible = "ingenic,jz4740-watchdog", },
> + { .compatible = "ingenic,jz4780-watchdog", },
>   { /* sentinel */ }
>  };
>  MODULE_DEVICE_TABLE(of, jz4740_wdt_of_matches);
> -- 
> 2.11.0
> 


Re: selftests/bpf doesn't compile

2017-09-15 Thread Shuah Khan
On 09/15/2017 12:48 PM, Daniel Borkmann wrote:
> On 09/15/2017 08:23 PM, Daniel Borkmann wrote:
>> On 09/15/2017 08:07 PM, Alexei Starovoitov wrote:
>>> On Fri, Sep 15, 2017 at 05:58:40PM +0100, Edward Cree wrote:
 On 15/09/17 17:02, Alexei Starovoitov wrote:
> On Thu, Sep 14, 2017 at 09:33:48AM -0600, Shuah Khan wrote:
>> Is bpf test intended to be run in kselftest run? The clang dependency 
>> might
>> not be met on majority of the systems. Is this a hard dependency??
> It is a hard dependency and clang should be present on majority of the 
> systems.
 I think this is the wrong approach.  Making kselftest hard-require clang 
 doesn't
   mean that the bpf tests will be run more often, it means that the rest 
 of the
   kselftests will be run less often.  clang is quite big (when I tried to 
 install
   it on one of my test servers, I didn't have enough disk space & had to 
 go on a
   clear-out of unused packages), and most people aren't interested in the 
 bpf
   subsystem specifically; they would rather be able to skip those tests.
 I feel that as long as they know they are skipping some tests (so e.g. they
   won't consider it a sufficient test of a kselftest refactor), that's 
 fine.
 It's not even as though all of the bpf tests require clang; the (smaller) 
 tests
   written directly in raw eBPF instructions could still be run on such a 
 system.
   So I think we should attempt to run as much as possible but accept that 
 clang
   may not be available and have an option to skip some tests in that case.
>>>
>>> imo the value of selftests/bpf is twofold:
>>> 1. it helps bpf developers avoid regressions
>>> 2. as part of continuous integration it helps to catch bpf regressions
>>> that were somehow caused by changes in other parts of the kernel
>>>
>>> If a developer didn't bother to satisfy all bpf tests dependencies
>>> (which includes clang) and ran all tests before sending a patch,
>>> I don't want to see such patches. It just wastes maintainers time
>>> to review code and spot bugs that could have been caught by tests.
>>> Collectively we invested years of work into these tests and
>>> developers better take advantage of it by running all.
>>
>> +1
>>
>>> If a CI server didn't satisfy all bpf test dependencies,
>>> I don't want such CI setup to be running and reporting results,
>>> since it will give false sense of test coverage.
>>> Test failures due to missing dependencies are hard failures.
>>> We cannot skip them.
>>
>> +1
> 
> Btw, on that note, the folks from zero-day bot run the BPF kselftests
> for a while now just fine and they do run them together with clang,
> so they have the full, proper coverage how it should be. It's not
> how it used to be in the early days, you can just go and install
> llvm/clang package on all the major distros today and you get the
> bpf target by default enabled already.
> 
>>> I'd like generic XDP tests to be added to selftests/bpf which
>>> would mean that the latest iproute2 will become a hard dependency
>>> and bpf developers and CI host owners would need to upgrade
>>> their iproute2.
>>> The tests either pass or fail. Skipping them due to missing
>>> dependencies is the same as fail and in that sense I don't want
>>> to change selftests/bpf/Makefile to make it skip clang.
>>
>> I fully agree that for the BPF selftests it is very desirable
>> to not only test the verifier with couple of BPF insn snippets,
>> but to actually load and run programs that more closely resemble
>> real world programs. For more complex interactions these snippets
>> are just limited, think of tail calls, testing perf event output
>> helper, etc, which would all require to write these tests with
>> restricted C when we add them (unless we want to make writing
>> these tests a real pain ;) in which case no-one will bother to
>> write tests at all for them). Mid to long term I would definitely
>> like to see more programs in BPF selftests (e.g. moved over from
>> samples/bpf/) to increase the test coverage.
> 

As I said in my earlier email:

Unless users choose to install clang, bpf will always fail run without
clang. So clang dependency is an issue for bpf test coverage in general.
That is your choice as to whether you want to increase the scope of
regression test coverage for bpf or not.

I fully understand you have weigh that against ease of writing tests.

We can leave things the way they are since:

- You can't force users to install clang and run bpf test. Users might
  opt for letting bpf test fail due to unmet dependency.

- You have reasons to continue use clang and you have been using it for
  a longtime.

I will try to see why make ksefltest fails on bpf even with my patch
series that addresses the source directory issue. All other tests build
and run. It is not an issue with bpf specifically, it is something that
has never been tested in this use-case.

thanks

Re: [PATCH] acpi: watchdog: properly initialize resources

2017-09-15 Thread Guenter Roeck
On Fri, Sep 15, 2017 at 09:55:18PM +0200, Arnd Bergmann wrote:
> We copy a local resource structure into a list, but only
> initialize some of its members, as pointed out by gcc-4.4:
> 
> drivers/acpi/acpi_watchdog.c: In function 'acpi_watchdog_init':
> drivers/acpi/acpi_watchdog.c:105: error: 'res.child' may be used 
> uninitialized in this function
> drivers/acpi/acpi_watchdog.c:105: error: 'res.sibling' may be used 
> uninitialized in this function
> drivers/acpi/acpi_watchdog.c:105: error: 'res.parent' may be used 
> uninitialized in this function
> drivers/acpi/acpi_watchdog.c:105: error: 'res.desc' may be used uninitialized 
> in this function
> drivers/acpi/acpi_watchdog.c:105: error: 'res.name' may be used uninitialized 
> in this function
> 
> Newer compilers can presumably optimize the uninitialized access
> away entirely and don't warn at all, but rely on the kzalloc()
> to zero the structure first. This adds an explicit initialization
> to force consistent behavior.
> 
> Fixes: 058dfc767008 ("ACPI / watchdog: Add support for WDAT hardware 
> watchdog")
> Signed-off-by: Arnd Bergmann 

Acked-by: Guenter Roeck 

> ---
>  drivers/acpi/acpi_watchdog.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/acpi/acpi_watchdog.c b/drivers/acpi/acpi_watchdog.c
> index bf22c29d2517..11b113f8e367 100644
> --- a/drivers/acpi/acpi_watchdog.c
> +++ b/drivers/acpi/acpi_watchdog.c
> @@ -66,7 +66,7 @@ void __init acpi_watchdog_init(void)
>   for (i = 0; i < wdat->entries; i++) {
>   const struct acpi_generic_address *gas;
>   struct resource_entry *rentry;
> - struct resource res;
> + struct resource res = {};
>   bool found;
>  
>   gas = &entries[i].register_region;
> -- 
> 2.9.0
> 


[PATCH] MAINTAINERS: update TPM driver infrastructure changes

2017-09-15 Thread Jarkko Sakkinen
Signed-off-by: Jarkko Sakkinen 
---
 CREDITS |  7 +++
 MAINTAINERS | 13 ++---
 2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/CREDITS b/CREDITS
index 5d09c26d69cd..dcd761885ea8 100644
--- a/CREDITS
+++ b/CREDITS
@@ -4130,6 +4130,13 @@ D: MD driver
 D: EISA/sysfs subsystem
 S: France
 
+N: Marcel Selhorst
+E: tp...@selhorst.net
+D: TPM driver
+
+N: Ashley Lai
+E: ashleyd...@gmail.com
+D: IBM VTPM driver
 
 # Don't add your name here, unless you really _are_ after Marc
 # alphabetically. Leonard used to be very proud of being the 
diff --git a/MAINTAINERS b/MAINTAINERS
index dfca9a4f1112..00f0610c3ec9 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13291,23 +13291,14 @@ F:drivers/platform/x86/toshiba-wmi.c
 
 TPM DEVICE DRIVER
 M: Peter Huewe 
-M: Marcel Selhorst 
 M: Jarkko Sakkinen 
 R: Jason Gunthorpe 
-W: http://tpmdd.sourceforge.net
-L: tpmdd-de...@lists.sourceforge.net (moderated for non-subscribers)
-Q: https://patchwork.kernel.org/project/tpmdd-devel/list/
+L: linux-integr...@vger.kernel.org
+Q: https://patchwork.kernel.org/project/linux-integrity/list/
 T: git git://git.infradead.org/users/jjs/linux-tpmdd.git
 S: Maintained
 F: drivers/char/tpm/
 
-TPM IBM_VTPM DEVICE DRIVER
-M: Ashley Lai 
-W: http://tpmdd.sourceforge.net
-L: tpmdd-de...@lists.sourceforge.net (moderated for non-subscribers)
-S: Maintained
-F: drivers/char/tpm/tpm_ibmvtpm*
-
 TRACING
 M: Steven Rostedt 
 M: Ingo Molnar 
-- 
2.14.1



Re: [PATCH v2 1/2] soc: qcom: smem: Rename "uncached" accessors

2017-09-15 Thread Bjorn Andersson
On Fri 15 Sep 12:19 PDT 2017, Stephen Boyd wrote:

> On 08/14, Bjorn Andersson wrote:
> > In preparation for adding accessors for "cached" entries rename the
> > "uncached" accessors to. Also rename "first" cached entry to "last", as
> 
> s/to/too? or to "uncached"?
> 

Doesn't it make more sense if we ju just make it: rename the "uncached"
accessors? I.e just drop the "to".

> > the cached list grows backwards.
> > 
> > Signed-off-by: Bjorn Andersson 
> 
> 
> Otherwise,
> 
> Reviewed-by: Stephen Boyd 
> 

Thanks,
Bjorn


Re: selftests/bpf doesn't compile

2017-09-15 Thread Shuah Khan
On 09/15/2017 12:14 PM, Alexei Starovoitov wrote:
> On Fri, Sep 15, 2017 at 11:00:31AM -0600, Shuah Khan wrote:
 I could add a special target for bpf TARGET_BPF perhaps and exclude it from
 the run_test> 
>>> I'm not sure what was the motivation to exclude hotplug from default 
>>> testing,
>>
>> These are considered a bit more disruptive and were excluded a while
>> back. These take cpus and memory on and off-line. Also require
>> root access. So even if they are included in the regular run, these
>> won't run.
> 
> most of bpf tests require root access as well.
> 
>> The first failure due to clang dependency is not a problem. The second one
>> in the case of "make kselftest" is the one that requires some work when bpf
>> make is run from the main Makefile. A lots of users run tests using the
>> kselftest target from the mail Makefile. hence I would like to get this
>> working, so it would be easier to run this test on test servers.
> 
> 'make kselftest' doesn't work for me at all, since I suspect it
> assumes in-source build. I always use KBUILD_OUTPUT,
> since I build multiple archs with different configs out of the same
> source tree, so there is a bigger problem here.

Right. I think you probably use

make KBUILD_OUTPUT=dir -C tools/testing/selftests/bpf

> 
> $ make kselftest
> make[1]: Entering directory `/data/users/ast/net-next/bld_x64'
> make: Entering an unknown directory
> make: *** tools/testing/selftests: No such file or directory.  Stop.
> make: Leaving an unknown directory
> make[1]: *** [kselftest] Error 2
> make[1]: Leaving directory `/data/users/ast/net-next/bld_x64'
> make: *** [sub-make] Error 2
> 

Right. There is patch set out to fix this problem which I sent out couple
of days ago. It is probably the case that bpf Makefile might need changes
to build when it is built from the sleftests/Makefile or the main Makefile.

thanks,
-- Shuah


Re: [RFC] KVM: arm/arm64: Introduce KVM_DEV_ARM_ITS_CTRL_RESET

2017-09-15 Thread Marc Zyngier
On Fri, Sep 15 2017 at 10:56:06 am BST, Christoffer Dall  
wrote:
> On Fri, Sep 15, 2017 at 5:26 AM, Auger Eric  wrote:
>> Hi,
>>
>> On 14/09/2017 19:06, Marc Zyngier wrote:
>>> On Thu, Sep 14 2017 at 10:57:28 am BST, Eric Auger  
>>> wrote:
 At the moment, the in-kernel emulated ITS is not properly reset.
 On guest restart/reset some registers keep their old values and
 internal structures like device, ITE, collection lists are not emptied.

 This may lead to various bugs. Among them, we can have incorrect state
 backup or failure when saving the ITS state at early guest boot stage.

 This patch introduces a new attribute, KVM_DEV_ARM_ITS_CTRL_RESET in
 the KVM_DEV_ARM_VGIC_GRP_CTRL group.

 Upon this action, we can invalidate the various memory structures
 pointed by GITS_BASERn and GITS_CBASER, free the ITS internal caches
 and reset the relevant registers.

 Signed-off-by: Eric Auger 

 ---

 An alternative would consist in having the userspace writing
 individual registers with default values: GITS_BASERn, GITS_CBASER
 and GITS_CTLR. On kernel side we would reset related lists when
 detecting the valid bit is set to false.
>>>
>>> I'm not sure this is necessarily a "either/or" situation. It looks to me
>>> that we're not completely doing the right thing when writing to the
>>> GITS_BASER registers, and that writing a new value (with the valid bit
>>> set or not) should have an action of some sort on the fate of the
>>> existing mappings.
>>
>> I agree. I think whenever the GITS_BASERn or GITS_CBASER validity bit is
>> reset, we should empty the internal lists and assure the code does not
>> attempt to read the data structures in caches/RAM anymore.
>>
>
> I don't think that is likely to match the behavior suggested in the
> GIC/ITS spec.  I doubt that hardware implementations will support
> software changing the BASERs without turning off the GIC, and
> therefore I don't think we'll see drivers doing this any time soon,
> and I don't think we need to support that.

I've managed to check this, and at least one implementation does clear
its caches on write to the corresponding BASERn registers, which makes
some sense. It is slightly annoying that the spec doesn't outline this,
but I'll enquire to see if that can be clarified.

> What I do think we should support is the ITS power management sequence
> pointed out in Section 6.6 in the spec.  But I don't think this is
> urgent, as we don't seem to have any guests that power down and power
> up the ITS yet.

+1 on both point.

M.
-- 
Jazz is not dead. It just smells funny.


[PATCH] clk: si5351: implement remove handler

2017-09-15 Thread Alexey Khoroshilov
The driver has no remove function, so it does not cleanup
resources that are not under devm management.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov 
---
 drivers/clk/clk-si5351.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/drivers/clk/clk-si5351.c b/drivers/clk/clk-si5351.c
index 20d90769cced..36a15f161dfd 100644
--- a/drivers/clk/clk-si5351.c
+++ b/drivers/clk/clk-si5351.c
@@ -1619,6 +1619,18 @@ static int si5351_i2c_probe(struct i2c_client *client,
return ret;
 }
 
+static int si5351_i2c_remove(struct i2c_client *client)
+{
+   struct si5351_driver_data *drvdata = i2c_get_clientdata(client);
+
+   of_clk_del_provider(client->dev.of_node);
+   if (!IS_ERR(drvdata->pxtal))
+   clk_disable_unprepare(drvdata->pxtal);
+   if (!IS_ERR(drvdata->pclkin))
+   clk_disable_unprepare(drvdata->pclkin);
+   return 0;
+}
+
 static const struct i2c_device_id si5351_i2c_ids[] = {
{ "si5351a", SI5351_VARIANT_A },
{ "si5351a-msop", SI5351_VARIANT_A3 },
@@ -1634,6 +1646,7 @@ static struct i2c_driver si5351_driver = {
.of_match_table = of_match_ptr(si5351_dt_ids),
},
.probe = si5351_i2c_probe,
+   .remove = si5351_i2c_remove,
.id_table = si5351_i2c_ids,
 };
 module_i2c_driver(si5351_driver);
-- 
2.7.4



Re: Vibrations in input vs. LED was Re: [PATCH v2 0/3] led: ledtrig-transient: add support for hrtimer

2017-09-15 Thread Dmitry Torokhov
On Fri, Sep 15, 2017 at 2:55 PM, Jacek Anaszewski
 wrote:
> On 09/15/2017 08:34 PM, Dmitry Torokhov wrote:
>> On Thu, Sep 14, 2017 at 1:58 PM, Pavel Machek  wrote:
>>> On Thu 2017-09-14 21:31:31, Jacek Anaszewski wrote:
 Hi David and Pavel,

 On 09/13/2017 10:20 PM, Pavel Machek wrote:
> Hi!
>
>> These patch series add the LED_BRIGHTNESS_FAST flag support for
>> ledtrig-transient to use hrtimer so that platforms with high-resolution 
>> timer
>> support can have better accuracy in the trigger duration timing. The 
>> need for
>> this support is driven by the fact that Android has removed the 
>> timed_ouput [1]
>> and is now using led-trigger for handling vibrator control which 
>> requires the
>> timer to be accurate up to a millisecond. However, this flag support 
>> would also
>> allow hrtimer to co-exist with the ktimer without causing warning to the
>> existing drivers [2].
>
> NAK.
>
> LEDs do not need extra overhead, and vibrator control should not go
> through LED subsystem.
>
> Input subsystem includes support for vibrations and force
> feedback. Please use that instead.

 I think that most vital criterion here is the usability of the
 interface. If it can be harnessed for doing the work seemingly
 unrelated to the primary subsystem's purpose, that's fine.
 Moreover, it is extremely easy to use in comparison to the force
 feedback one.
>>>
>>> Well, no.
>>>
>>> Kernel is supposed to provide hardware abstraction, that means it
>>> should hide differences between different devices.
>>>
>>> And we already have devices using input as designed. We don't want to
>>> have situation where "on phones A, D and E, vibrations are handled via
>>> input, while on B, C and F, they are handled via /sys/class/leds".
>>>
>>> If we want to have discussion "how to make vibrations in input
>>> easier to use", well that's fair. But I don't think it is particulary hard.
>>>
>>
>> I would like to know more about why you find the FF interface hard,
>
> led-transient trigger can be activated using only following bash
> commands:
>
> # echo 1 > state
> # echo 1000 > duration
> # while [ 1 ]; do echo 1 > activate; sleep 3; done
>
> Could you share sample sequence of commands to use ff driver?

Cut what you need from this:
https://github.com/flosse/linuxconsole/blob/master/utils/fftest.c

If your objection is that FF is not easily engaged from the shell -
yes, but I do not think that actual users who want to do vibration do
that via shell either. On the other hand, can you drop privileges and
still allow a certain process control your vibrator via LED interface?
With FF you can pass an FD to whoever you deem worthy and later revoke
access.

IOW sysfs interfaces are nice for quick hacks, but when you want to
use them in real frameworks, where you need to think about proper
namespaces, isolation, etc, etc, other kinds of interfaces might suit
better.

>
>> given that for rumble you need calls - one ioctl to set up rumble
>> parameters, and a write to start the playback. The FF core should take
>> care of handling duration of the effect, ramping it up and decaying,
>> if desired, and we make sure to automatically stop effects when
>> userspace closes the fd (because of ordinary exit or crash or FD being
>> revoked).
>>
>>> If we want to say "lets move all vibrations from input to LED
>>> subsystem"... I don't think that is good idea, but its a valid
>>> discussion. Some good reasons would be needed.
>>>
>>> But having half devices use one interface and half use different one
>>> is just bad...
>>
>> Completely agree here. I just merged PWM vibra driver from Sebastian
>> Reichel, we already had regulator-haptic driver, do we need gpio-based
>> one? Or make regulator-based one working with fixed regulators?
>
> Just to clarify: the background of this discussion is the question
> whether we should remove the following lines from
> Documentation/leds/ledtrig-transient.txt:
>
> -As a specific example of this use-case, let's look at vibrate feature on
> -phones. Vibrate function on phones is implemented using PWM pins on SoC or
> -PMIC. There is a need to activate one shot timer to control the vibrate
> -feature, to prevent user space crashes leaving the phone in vibrate mode
> -permanently causing the battery to drain.
> whether we should remove the following use case example from
>
> In effect Pavel has objections to increasing ledtrig-transient
> interval accuracy by adding hr_timer support to it, because vibrate
> devices, as one of the use cases, can benefit from it.
>
> So there are two issues:
> 1. Addition of hr_timer support to LED trigger.
> 2. Removal of vibrate devices use case from ledtrig-transient doc.
>
> I am in favour of 1. and against 2. since we're not gaining anything
> by hiding information about some kernel functionality when it will
> still be there. It also doesn't define the location

Re: [PATCH 00/16] gpio: Tight IRQ chip integration and banked infrastructure

2017-09-15 Thread Grygorii Strashko


On 09/15/2017 11:57 AM, Tony Lindgren wrote:
> * Thierry Reding  [170915 08:10]:
>> On Thu, Sep 14, 2017 at 03:54:56PM +0200, Linus Walleij wrote:
>>> Sorry about that. Let's move ahead with this now, it is neat and
>>> clean.
>>>
>>> What I want (as maintainer) is a bit of fingerpointing at the drivers
>>> that need to be converted to use the new banking infrastructure
>>> so they don't stay with their old crappy design pattern. OMAP is
>>> a clear candidate right? (Added Tony to CC...)
>>
>> OMAP should be able to use this infrastructure, but it may not want to
>> because the semantics would change slightly. Currently OMAP registers a
>> GPIO chip for each bank, whereas this infrastructure exposes multiple
>> banks via a single chip.
> 
> Oh so you don't have separate interrupts for the instances?
> Thanks for clarifying that.
> 
>> There might be some userspace that relies on the existence of multiple
>> chips, but Tony can probably knows that better than I.
> 
> On omaps, each bank is a separate driver instance with it's own
> interrupt. Maybe really all we need to do is get rid of the "bank"
> naming, I think that's left over from 15 years ago when we did not
> have separate driver instances. It seems we should s/bank/ddata/
> on the driver to avoid confusion.
> 
> Grygorii, any comments?

Sry, for delayed reply - I've saw this series, but, honestly, it's very big 
change for review :(

So, can it be split? I think, patches which reorganize gpio irqchip specific 
fields placement 
and move them in gpio_irq_chip can be considered separately if they will not 
introduce
functional changes. Also, omap changes can be considered separately.
(Pay attention that new fields introduced in patch 1).  

Regarding OMAP GPIO - right now I do not see how it can be applied for OMAP :(
Each OMAP GPIO bank is standalone device which can be enabled/disabled, 
powered on/off in Linux. There are no contiguous MMIO space and each GPIO
bank have separate MMIO space.

I really, need more time to review this idea and I think that it can be done
more easily if series size will be reduced.

Few more notes:
- pay attention on commit dc749a0 "gpiolib: allow gpio irqchip to map irqs 
dynamically"
- good to see binding and DT examples
- not sure if I've got idea of encoding bank&pin in spec[0] :(

+   bank = (spec[0] >> gc->of_gpio_bank_mask) & gc->of_gpio_bank_shift;
+   pin = (spec[0] >> gc->of_gpio_pin_mask) & gc->of_gpio_pin_shift;

- irq "mapping" inside gpio_irq_chip is not clear :( does it static?
does it require one array item/per pin - sry, this is waste of memory?

irq->map[offset + j] = irq->parents[parent];

Potentially, this feature can be applied to Davinci GPIO driver, which
is GPIO controller divided in multiple logical banks and which also have
set of common registers for all logical banks. But, again, not sure how
effective this implementation is - need more time. As of now, we perfectly 
handle this in Davinci GPIO driver by creating only ONE gpio_chip which hides
HW details in driver and still uses standard irq DT mappings:
 <&gpio0 140 GPIO_ACTIVE_LOW>;

By the way Patch 14 adds 300 lines, while patch changes 200 lines, so
in terms of code lines this feature seems is not very efficient.
(same for Patch 15, 16)

-- 
regards,
-grygorii


  1   2   3   4   5   6   >