[PATCH 2/2] KVM: nVMX: Validate the IA32_BNDCFGS on nested VM-entry

2017-10-26 Thread Wanpeng Li
From: Wanpeng Li 

According to the SDM, if the "load IA32_BNDCFGS" VM-entry controls is 1, the
following checks are performed on the field for the IA32_BNDCFGS MSR:
 - Bits reserved in the IA32_BNDCFGS MSR must be 0.
 - The linear address in bits 63:12 must be canonical.

Cc: Paolo Bonzini 
Cc: Radim Krčmář 
Cc: Jim Mattson 
Signed-off-by: Wanpeng Li 
---
 arch/x86/kvm/vmx.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index e6c8ffa..f29f57d 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -10805,6 +10805,13 @@ static int check_vmentry_postreqs(struct kvm_vcpu 
*vcpu, struct vmcs12 *vmcs12,
return 1;
}
 
+   if (kvm_mpx_supported() &&
+   (vmcs12->vm_entry_controls & VM_ENTRY_LOAD_BNDCFGS)) {
+   if (is_noncanonical_address(vmcs12->guest_bndcfgs & PAGE_MASK, 
vcpu) ||
+   (vmcs12->guest_bndcfgs & MSR_IA32_BNDCFGS_RSVD))
+   return 1;
+   }
+
return 0;
 }
 
-- 
2.7.4



[PATCH 1/2] KVM: X86: Fix operand size during instruction decoding

2017-10-26 Thread Wanpeng Li
From: Wanpeng Li 

Pedro reported:
  During tests that we conducted on KVM, we noticed that executing a "PUSH %ES"
  instruction under KVM produces different results on both memory and the SP
  register depending on whether EPT support is enabled. With EPT the SP is
  reduced by 4 bytes (and the written value is 0-padded) but without EPT support
  it is only reduced by 2 bytes. The difference can be observed when the CS.DB
  field is 1 (32-bit) but not when it's 0 (16-bit).

The internal segment descriptor cache exist even in real/vm8096 mode. The CS.D
also should be respected instead of just default operand-size/66H prefix during
instruction decoding. This patch fixes it by also adjusting operand-size 
according
to CS.D.

Reported-by: Pedro Fonseca 
Cc: Paolo Bonzini 
Cc: Radim Krčmář 
Cc: Nadav Amit 
Cc: Pedro Fonseca 
Signed-off-by: Wanpeng Li 
---
 arch/x86/kvm/emulate.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 8079d14..7cada51 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -5000,6 +5000,8 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void 
*insn, int insn_len)
bool op_prefix = false;
bool has_seg_override = false;
struct opcode opcode;
+   u16 dummy;
+   struct desc_struct desc;
 
ctxt->memop.type = OP_NONE;
ctxt->memopp = NULL;
@@ -5020,9 +5022,15 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void 
*insn, int insn_len)
case X86EMUL_MODE_VM86:
case X86EMUL_MODE_PROT16:
def_op_bytes = def_ad_bytes = 2;
+   ctxt->ops->get_segment(ctxt, &dummy, &desc, NULL, VCPU_SREG_CS);
+   if (desc.d)
+   def_op_bytes = 4;
break;
case X86EMUL_MODE_PROT32:
def_op_bytes = def_ad_bytes = 4;
+   ctxt->ops->get_segment(ctxt, &dummy, &desc, NULL, VCPU_SREG_CS);
+   if (!desc.d)
+   def_op_bytes = 2;
break;
 #ifdef CONFIG_X86_64
case X86EMUL_MODE_PROT64:
-- 
2.7.4



Re: [PATCHv2 2/2] Add /proc/PID/{smaps, numa_maps} support for DAX

2017-10-26 Thread kbuild test robot
Hi Fan,

Thank you for the patch! Yet we hit a small issue.
[auto build test WARNING on linus/master]
[also build test WARNING on v4.14-rc6 next-20171018]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Fan-Du/proc-mm-export-PTE-sizes-directly-in-smaps/20171027-141157
config: x86_64-randconfig-x011-201743 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings

All warnings (new ones prefixed by >>):

   fs/proc/task_mmu.c: In function 'gather_pte_stats':
>> fs/proc/task_mmu.c:1805:6: warning: 'page' may be used uninitialized in this 
>> function [-Wmaybe-uninitialized]
  if (!page)
 ^

vim +/page +1805 fs/proc/task_mmu.c

28093f9f3 Gerald Schaefer2016-04-28  1771  
f69ff943d Stephen Wilson 2011-05-24  1772  static int 
gather_pte_stats(pmd_t *pmd, unsigned long addr,
f69ff943d Stephen Wilson 2011-05-24  1773   unsigned long end, 
struct mm_walk *walk)
f69ff943d Stephen Wilson 2011-05-24  1774  {
d85f4d6d3 Naoya Horiguchi2015-02-11  1775   struct numa_maps *md = 
walk->private;
d85f4d6d3 Naoya Horiguchi2015-02-11  1776   struct vm_area_struct *vma = 
walk->vma;
f69ff943d Stephen Wilson 2011-05-24  1777   spinlock_t *ptl;
f69ff943d Stephen Wilson 2011-05-24  1778   pte_t *orig_pte;
f69ff943d Stephen Wilson 2011-05-24  1779   pte_t *pte;
3bf801467 Fan Du 2017-10-24  1780   struct page *page;
f69ff943d Stephen Wilson 2011-05-24  1781  
28093f9f3 Gerald Schaefer2016-04-28  1782  #ifdef 
CONFIG_TRANSPARENT_HUGEPAGE
b6ec57f4b Kirill A. Shutemov 2016-01-21  1783   ptl = pmd_trans_huge_lock(pmd, 
vma);
b6ec57f4b Kirill A. Shutemov 2016-01-21  1784   if (ptl) {
3bf801467 Fan Du 2017-10-24  1785   if (!vma_is_dax(vma))
28093f9f3 Gerald Schaefer2016-04-28  1786   page = 
can_gather_numa_stats_pmd(*pmd, vma, addr);
3bf801467 Fan Du 2017-10-24  1787   else if 
(pmd_devmap(*pmd))
3bf801467 Fan Du 2017-10-24  1788   page = 
pmd_page(*pmd);
32ef43848 Dave Hansen2011-09-20  1789   if (page)
28093f9f3 Gerald Schaefer2016-04-28  1790   
gather_stats(page, md, pmd_dirty(*pmd),
32ef43848 Dave Hansen2011-09-20  1791
HPAGE_PMD_SIZE/PAGE_SIZE);
bf929152e Kirill A. Shutemov 2013-11-14  1792   spin_unlock(ptl);
32ef43848 Dave Hansen2011-09-20  1793   return 0;
32ef43848 Dave Hansen2011-09-20  1794   }
32ef43848 Dave Hansen2011-09-20  1795  
1a5a9906d Andrea Arcangeli   2012-03-21  1796   if (pmd_trans_unstable(pmd))
1a5a9906d Andrea Arcangeli   2012-03-21  1797   return 0;
28093f9f3 Gerald Schaefer2016-04-28  1798  #endif
f69ff943d Stephen Wilson 2011-05-24  1799   orig_pte = pte = 
pte_offset_map_lock(walk->mm, pmd, addr, &ptl);
f69ff943d Stephen Wilson 2011-05-24  1800   do {
3bf801467 Fan Du 2017-10-24  1801   if (!vma_is_dax(vma))
3bf801467 Fan Du 2017-10-24  1802   page = 
can_gather_numa_stats(*pte, vma, addr);
3bf801467 Fan Du 2017-10-24  1803   else if 
(pte_devmap(*pte))
3bf801467 Fan Du 2017-10-24  1804   page = 
pte_page(*pte);
f69ff943d Stephen Wilson 2011-05-24 @1805   if (!page)
f69ff943d Stephen Wilson 2011-05-24  1806   continue;
eb4866d00 Dave Hansen2011-09-20  1807   gather_stats(page, md, 
pte_dirty(*pte), 1);
f69ff943d Stephen Wilson 2011-05-24  1808  
f69ff943d Stephen Wilson 2011-05-24  1809   } while (pte++, addr += 
PAGE_SIZE, addr != end);
f69ff943d Stephen Wilson 2011-05-24  1810   pte_unmap_unlock(orig_pte, ptl);
a66c0410b Hugh Dickins   2016-12-12  1811   cond_resched();
f69ff943d Stephen Wilson 2011-05-24  1812   return 0;
f69ff943d Stephen Wilson 2011-05-24  1813  }
f69ff943d Stephen Wilson 2011-05-24  1814  #ifdef CONFIG_HUGETLB_PAGE
632fd60fe Naoya Horiguchi2015-02-11  1815  static int 
gather_hugetlb_stats(pte_t *pte, unsigned long hmask,
f69ff943d Stephen Wilson 2011-05-24  1816   unsigned long addr, 
unsigned long end, struct mm_walk *walk)
f69ff943d Stephen Wilson 2011-05-24  1817  {
5c2ff95e4 Michael Holzheu2016-02-02  1818   pte_t huge_pte = 
huge_ptep_get(pte);
f69ff943d Stephen Wilson 2011-05-24  1819   struct numa_maps *md;
f69ff943d Stephen Wilson 2011-05-24  1820   struct page *page;
f69ff943d Stephen Wilson 2011-05-24  1821  
5c2ff95e4 Michael Holzheu2016-02-02  1822   if (!pte_present(huge_pte))
f69ff943d Stephen Wilson 2011-05-24  1823  

RE: [PATCH] refcount: provide same memory ordering guarantees as in atomic_t

2017-10-26 Thread Reshetova, Elena
> On Mon, Oct 23, 2017 at 02:09:44PM +0300, Elena Reshetova wrote:
> > Currently arch. independent implementation of refcount_t in
> > lib/refcount.c provides weak memory ordering guarantees
> > compare to its analog atomic_t implementations.
> > While it should not be a problem for most of the actual
> > cases of refcounters, it is more understandable for everyone
> > (and more error-prone for future users) to provide exactly
> > same memory ordering guarantees as atomics.
> >
> > If speed is of a concern, then either more efficient arch.
> > dependent refcount_t implementation should be used or if there
> > are enough users in the future we might need to provide both
> > strict and relaxed refcount_t APIs.
> >
> > Suggested-by: Kees Cook 
> 
> NAK

Could we possibly have a bit more elaborate discussion on this? 

Or alternatively, what then should be the correct way for a certain variable 
(that behaves like
a standard refcounter) to check if the relaxed memory ordering is ok?
This is what Thomas was asking me to do for core kernel conversions and this
is what I don't know how to do correctly. Also, I got exactly the same question
from xfs maintainer, so if we provide an API that we hope will be used 
correctly in
the future, we should have a way for people to verify it. 

Maybe it is just me, but I would think that having a way to verify that your 
code
is ok with this refcounter-specific relaxed memory ordering applies to any 
memory ordering
requirements, refcounters are just a subset with certain properties, so is then
the full answer is to figure out how to verify any memory ordering requirement 
of your code? 

We can also document this logic in more docs or even maybe try to create a 
better
documentation for current memory ordering bits since it is not the most easiest 
read
at the moment. Otherwise this might be just bad enough reason for many people to
avoid refcount_t type if it is just easier to tell "let's take just old atomic, 
we knew it 
somehow worked before"

Best Regards,
Elena.


Re: [PATCH v3 00/13] dax: fix dma vs truncate and remove 'page-less' support

2017-10-26 Thread Dave Chinner
On Thu, Oct 26, 2017 at 11:51:04PM +, Williams, Dan J wrote:
> On Thu, 2017-10-26 at 12:58 +0200, Jan Kara wrote:
> > On Fri 20-10-17 11:31:48, Christoph Hellwig wrote:
> > > On Fri, Oct 20, 2017 at 09:47:50AM +0200, Christoph Hellwig wrote:
> > > > I'd like to brainstorm how we can do something better.
> > > > 
> > > > How about:
> > > > 
> > > > If we hit a page with an elevated refcount in truncate / hole puch
> > > > etc for a DAX file system we do not free the blocks in the file system,
> > > > but add it to the extent busy list.  We mark the page as delayed
> > > > free (e.g. page flag?) so that when it finally hits refcount zero we
> > > > call back into the file system to remove it from the busy list.
> > > 
> > > Brainstorming some more:
> > > 
> > > Given that on a DAX file there shouldn't be any long-term page
> > > references after we unmap it from the page table and don't allow
> > > get_user_pages calls why not wait for the references for all
> > > DAX pages to go away first?  E.g. if we find a DAX page in
> > > truncate_inode_pages_range that has an elevated refcount we set
> > > a new flag to prevent new references from showing up, and then
> > > simply wait for it to go away.  Instead of a busy way we can
> > > do this through a few hashed waitqueued in dev_pagemap.  And in
> > > fact put_zone_device_page already gets called when putting the
> > > last page so we can handle the wakeup from there.
> > > 
> > > In fact if we can't find a page flag for the stop new callers
> > > things we could probably come up with a way to do that through
> > > dev_pagemap somehow, but I'm not sure how efficient that would
> > > be.
> > 
> > We were talking about this yesterday with Dan so some more brainstorming
> > from us. We can implement the solution with extent busy list in ext4
> > relatively easily - we already have such list currently similarly to XFS.
> > There would be some modifications needed but nothing too complex. The
> > biggest downside of this solution I see is that it requires per-filesystem
> > solution for busy extents - ext4 and XFS are reasonably fine, however btrfs
> > may have problems and ext2 definitely will need some modifications.
> > Invisible used blocks may be surprising to users at times although given
> > page refs should be relatively short term, that should not be a big issue.
> > But are we guaranteed page refs are short term? E.g. if someone creates
> > v4l2 videobuf in MAP_SHARED mapping of a file on DAX filesystem, page refs
> > can be rather long-term similarly as in RDMA case. Also freeing of blocks
> > on page reference drop is another async entry point into the filesystem
> > which could unpleasantly surprise us but I guess workqueues would solve
> > that reasonably fine.
> > 
> > WRT waiting for page refs to be dropped before proceeding with truncate (or
> > punch hole for that matter - that case is even nastier since we don't have
> > i_size to guard us). What I like about this solution is that it is very
> > visible there's something unusual going on with the file being truncated /
> > punched and so problems are easier to diagnose / fix from the admin side.
> > So far we have guarded hole punching from concurrent faults (and
> > get_user_pages() does fault once you do unmap_mapping_range()) with
> > I_MMAP_LOCK (or its equivalent in ext4). We cannot easily wait for page
> > refs to be dropped under I_MMAP_LOCK as that could deadlock - the most
> > obvious case Dan came up with is when GUP obtains ref to page A, then hole
> > punch comes grabbing I_MMAP_LOCK and waiting for page ref on A to be
> > dropped, and then GUP blocks on trying to fault in another page.
> > 
> > I think we cannot easily prevent new page references to be grabbed as you
> > write above since nobody expects stuff like get_page() to fail. But I 
> > think that unmapping relevant pages and then preventing them to be faulted
> > in again is workable and stops GUP as well. The problem with that is though
> > what to do with page faults to such pages - you cannot just fail them for
> > hole punch, and you cannot easily allocate new blocks either. So we are
> > back at a situation where we need to detach blocks from the inode and then
> > wait for page refs to be dropped - so some form of busy extents. Am I
> > missing something?
> > 
> 
> No, that's a good summary of what we talked about. However, I did go
> back and give the new lock approach a try and was able to get my test
> to pass. The new locking is not pretty especially since you need to
> drop and reacquire the lock so that get_user_pages() can finish
> grabbing all the pages it needs. Here are the two primary patches in
> the series, do you think the extent-busy approach would be cleaner?

The XFS_DAXDMA 

$DEITY that patch is so ugly I can't even bring myself to type it.

-Dave.
-- 
Dave Chinner
da...@fromorbit.com


Re: [PATCH v3 00/13] dax: fix dma vs truncate and remove 'page-less' support

2017-10-26 Thread Christoph Hellwig
On Thu, Oct 26, 2017 at 12:58:50PM +0200, Jan Kara wrote:
> But are we guaranteed page refs are short term? E.g. if someone creates
> v4l2 videobuf in MAP_SHARED mapping of a file on DAX filesystem, page refs
> can be rather long-term similarly as in RDMA case. Also freeing of blocks
> on page reference drop is another async entry point into the filesystem
> which could unpleasantly surprise us but I guess workqueues would solve
> that reasonably fine.

The point is that we need to prohibit long term elevated page counts
with DAX anyway - we can't just let people grab allocated blocks forever
while ignoring file system operations.  For stage 1 we'll just need to
fail those, and in the long run they will have to use a mechanism
similar to FL_LAYOUT locks to deal with file system allocation changes.


Re: [PATCH] drm/bridge/synopsys: dsi: add optional pixel clock

2017-10-26 Thread Andrzej Hajda
On 26.10.2017 18:09, Philippe Cornu wrote:
> The pixel clock is optional. When available, it offers a better
> preciseness for timing computations.
>
> Signed-off-by: Philippe Cornu 
> ---
>  drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c | 24 ++--
>  1 file changed, 18 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c 
> b/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c
> index d9cca4f..8b3787d 100644
> --- a/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c
> +++ b/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c
> @@ -225,6 +225,7 @@ struct dw_mipi_dsi {
>   void __iomem *base;
>  
>   struct clk *pclk;
> + struct clk *px_clk;
>  
>   unsigned int lane_mbps; /* per lane */
>   u32 channel;
> @@ -753,24 +754,28 @@ void dw_mipi_dsi_bridge_mode_set(struct drm_bridge 
> *bridge,
>   struct dw_mipi_dsi *dsi = bridge_to_dsi(bridge);
>   const struct dw_mipi_dsi_phy_ops *phy_ops = dsi->plat_data->phy_ops;
>   void *priv_data = dsi->plat_data->priv_data;
> + struct drm_display_mode px_clk_mode = *mode;
>   int ret;
>  
>   clk_prepare_enable(dsi->pclk);
>  
> - ret = phy_ops->get_lane_mbps(priv_data, mode, dsi->mode_flags,
> + if (dsi->px_clk)
> + px_clk_mode.clock = clk_get_rate(dsi->px_clk) / 1000;
> +
> + ret = phy_ops->get_lane_mbps(priv_data, &px_clk_mode, dsi->mode_flags,
>dsi->lanes, dsi->format, &dsi->lane_mbps);

Just small suggestion: if pixel clock rate matters, maybe better is to
fix it in adjusted_mode in mode_fixup callback.

>   if (ret)
>   DRM_DEBUG_DRIVER("Phy get_lane_mbps() failed\n");
>  
>   pm_runtime_get_sync(dsi->dev);
>   dw_mipi_dsi_init(dsi);
> - dw_mipi_dsi_dpi_config(dsi, mode);
> + dw_mipi_dsi_dpi_config(dsi, &px_clk_mode);
>   dw_mipi_dsi_packet_handler_config(dsi);
>   dw_mipi_dsi_video_mode_config(dsi);
> - dw_mipi_dsi_video_packet_config(dsi, mode);
> + dw_mipi_dsi_video_packet_config(dsi, &px_clk_mode);
>   dw_mipi_dsi_command_mode_config(dsi);
> - dw_mipi_dsi_line_timer_config(dsi, mode);
> - dw_mipi_dsi_vertical_timing_config(dsi, mode);
> + dw_mipi_dsi_line_timer_config(dsi, &px_clk_mode);
> + dw_mipi_dsi_vertical_timing_config(dsi, &px_clk_mode);
>  
>   dw_mipi_dsi_dphy_init(dsi);
>   dw_mipi_dsi_dphy_timing_config(dsi);
> @@ -784,7 +789,7 @@ void dw_mipi_dsi_bridge_mode_set(struct drm_bridge 
> *bridge,
>  
>   dw_mipi_dsi_dphy_enable(dsi);
>  
> - dw_mipi_dsi_wait_for_two_frames(mode);
> + dw_mipi_dsi_wait_for_two_frames(&px_clk_mode);
>  
>   /* Switch to cmd mode for panel-bridge pre_enable & panel prepare */
>   dw_mipi_dsi_set_mode(dsi, 0);
> @@ -878,6 +883,13 @@ static int dw_mipi_dsi_bridge_attach(struct drm_bridge 
> *bridge)
>   return ERR_PTR(ret);
>   }
>  
> + dsi->px_clk = devm_clk_get(dev, "px_clk");
> + if (IS_ERR(dsi->px_clk)) {
> + ret = PTR_ERR(dsi->px_clk);
> + dev_dbg(dev, "Unable to get optional px_clk: %d\n", ret);
> + dsi->px_clk = NULL;
> + }
> +

devm_clk_get is called from bridge::attach callback, do we have
guarantee that in ::detach callback the clock will be removed?
And what if the clock is defined in dts, but it cannot be get due to
other reasons? I guess the code should fail then, ie you should have
different paths for -ENOENT and for other errors.

 --
Regards
Andrzej

>   /*
>* Note that the reset was not defined in the initial device tree, so
>* we have to be prepared for it not being found.




[PATCH net-next] qed: Set error code for allocation failures

2017-10-26 Thread Dan Carpenter
There are several places where we accidentally return success when
kcalloc() fails.

Fixes: fcb39f6c10b2 ("qed: Add mpa buffer descriptors for storing and 
processing mpa fpdus")
Signed-off-by: Dan Carpenter 

diff --git a/drivers/net/ethernet/qlogic/qed/qed_iwarp.c 
b/drivers/net/ethernet/qlogic/qed/qed_iwarp.c
index 409041eab189..6366f2ef82b7 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_iwarp.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_iwarp.c
@@ -2585,7 +2585,7 @@ qed_iwarp_ll2_start(struct qed_hwfn *p_hwfn,
struct qed_ll2_cbs cbs;
u32 mpa_buff_size;
u16 n_ooo_bufs;
-   int rc = 0;
+   int rc;
int i;
 
iwarp_info = &p_hwfn->p_rdma_info->iwarp;
@@ -2696,6 +2696,7 @@ qed_iwarp_ll2_start(struct qed_hwfn *p_hwfn,
if (rc)
goto err;
 
+   rc = -ENOMEM;
iwarp_info->partial_fpdus = kcalloc((u16)p_hwfn->p_rdma_info->num_qps,
sizeof(*iwarp_info->partial_fpdus),
GFP_KERNEL);
@@ -2724,7 +2725,7 @@ qed_iwarp_ll2_start(struct qed_hwfn *p_hwfn,
for (i = 0; i < data.input.rx_num_desc; i++)
list_add_tail(&iwarp_info->mpa_bufs[i].list_entry,
  &iwarp_info->mpa_buf_list);
-   return rc;
+   return 0;
 err:
qed_iwarp_ll2_stop(p_hwfn, p_ptt);
 


Re: [PATCH] f2fs: fix out-of-free problem caused by atomic write

2017-10-26 Thread Christoph Hellwig
On Thu, Oct 26, 2017 at 04:30:19PM +0200, Jaegeuk Kim wrote:
> On 10/26, Yunlong Song wrote:
> > f2fs_balance_fs only actives once in the commit_inmem_pages, but there
> > are more than one page to commit, so all the other pages will miss the
> > check. This will lead to out-of-free problem when commit a very large
> > file. To fix it, we should do f2fs_balance_fs for each inmem page.
> 
> NAK, this breaks atomicity.

Can someone please explain (and write down in e.g. manpages) these
atomicy rules?


Re: [PATCH] pci: Add a acs_disable option for pci kernel parameter

2017-10-26 Thread Christoph Hellwig
On Thu, Oct 26, 2017 at 08:37:49PM -0600, sba...@raithlin.com wrote:
> From: Stephen Bates 
> 
> On some servers the BIOS sets up ACS on any valid pci_dev in the
> system. The kernel has no way of backing this out since the kernel
> only turns ACS capabilities on.
> 
> This patch adds a new boot option to the pci kernel parameter called
> "acs_disable" that will disable ACS. This is useful for PCI peer to
> peer communication but can cause problems when IOVA isolation is
> required and an IOMMU is enabled. Use with care.

Eww.  Can we please add smbios quirks for the systems where you've
observed this? (we probably also want to keep the option just in case).


RE: [PATCH 1/3] [S390] vmur: convert urdev.ref_count from atomic_t to refcount_t

2017-10-26 Thread Reshetova, Elena

> On Fri, 20 Oct 2017 10:47:48 +0300
> Elena Reshetova  wrote:
> 
> > atomic_t variables are currently used to implement reference
> > counters with the following properties:
> >  - counter is initialized to 1 using atomic_set()
> >  - a resource is freed upon counter reaching zero
> >  - once counter reaches zero, its further
> >increments aren't allowed
> >  - counter schema uses basic atomic operations
> >(set, inc, inc_not_zero, dec_and_test, etc.)
> >
> > Such atomic variables should be converted to a newly provided
> > refcount_t type and API that prevents accidental counter overflows
> > and underflows. This is important since overflows and underflows
> > can lead to use-after-free situation and be exploitable.
> >
> > The variable urdev.ref_count is used as pure reference counter.
> > Convert it to refcount_t and fix up the operations.
> >
> > Suggested-by: Kees Cook 
> > Reviewed-by: David Windsor 
> > Reviewed-by: Hans Liljestrand 
> > Signed-off-by: Elena Reshetova 
> 
> Added to s390/linux:features for the next merge window. Thanks.

Thank you very much!

Best Regards,
Elena.
> 
> --
> blue skies,
>Martin.
> 
> "Reality continues to ruin my life." - Calvin.



[PATCH v2 0/3] mailbox: Add support for Hi3660 mailbox

2017-10-26 Thread Kaihua Zhong
From: Leo Yan 

Hi3660 mailbox controller is used to send message within multiple
processors, MCU, HIFI, etc. This patch series is to implement an
initial version for Hi3660 mailbox driver with "automatic
acknowledge" mode.

The patch set have been verified with Hi3660 stub clock driver, so
we can send message to MCU to execute CPU frequency scaling. This is
tested on 96boards Hikey960.

Changes from v1:
* Refactored structure definition according to Jassi's suggestion;
* Refactored and simplized mailbox driver with "automatic ack" mode;
* Refined commit logs to give background info for driver;
* Added document for DT binding;
* Added cover letter to track the changelog.


Kaihua Zhong (2):
  mailbox: Add support for Hi3660 mailbox
  dts: arm64: Add mailbox binding for hi3660

Leo Yan (1):
  dt-bindings: mailbox: Introduce Hi3660 controller binding

 .../bindings/mailbox/hisilicon,hi3660-mailbox.txt  |  52 
 arch/arm64/boot/dts/hisilicon/hi3660.dtsi  |   8 +
 drivers/mailbox/Kconfig|   8 +
 drivers/mailbox/Makefile   |   2 +
 drivers/mailbox/hi3660-mailbox.c   | 331 +
 5 files changed, 401 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/mailbox/hisilicon,hi3660-mailbox.txt
 create mode 100644 drivers/mailbox/hi3660-mailbox.c

-- 
1.9.1



[PATCH v2 1/3] dt-bindings: mailbox: Introduce Hi3660 controller binding

2017-10-26 Thread Kaihua Zhong
From: Leo Yan 

Introduce a binding for the Hi3660 mailbox controller, the mailbox is
used within application processor (AP), communication processor (CP),
HIFI and MCU, etc.

Cc: John Stultz 
Cc: Guodong Xu 
Cc: Haojian Zhuang 
Cc: Niranjan Yadla 
Cc: Raj Pawate 
Signed-off-by: Leo Yan 
---
 .../bindings/mailbox/hisilicon,hi3660-mailbox.txt  | 52 ++
 1 file changed, 52 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/mailbox/hisilicon,hi3660-mailbox.txt

diff --git 
a/Documentation/devicetree/bindings/mailbox/hisilicon,hi3660-mailbox.txt 
b/Documentation/devicetree/bindings/mailbox/hisilicon,hi3660-mailbox.txt
new file mode 100644
index 000..8a8d7e1
--- /dev/null
+++ b/Documentation/devicetree/bindings/mailbox/hisilicon,hi3660-mailbox.txt
@@ -0,0 +1,52 @@
+Hisilicon Hi3660 Mailbox Driver
+
+Hisilicon Hi3660 mailbox controller supports up to 32 channels.  Messages
+are passed between processors, including application & communication
+processors, MCU, HIFI, etc.  Each channel is unidirectional and accessed
+by using MMIO registers; it supports maximum to 8 words message.
+
+Controller
+--
+
+Required properties:
+- compatible:  : Shall be "hisilicon,hi3660-mbox"
+- reg: : Offset and length of the device's register set
+- #mbox-cells: : Must be 3
+ <&phandle channel dst_irq ack_irq>
+   phandle : Label name of controller
+   channel : Channel number
+   dst_irq : Remote interrupt vector
+   ack_irq : Local interrupt vector
+
+- interrupts:  : Contains the two IRQ lines for mailbox.
+
+Example:
+
+mailbox: mailbox@e896b000 {
+   compatible = "hisilicon,hi3660-mbox";
+   reg = <0x0 0xe896b000 0x0 0x1000>;
+   interrupts = <0x0 0xc0 0x4>,
+<0x0 0xc1 0x4>;
+   #mbox-cells = <3>;
+};
+
+Client
+--
+
+Required properties:
+- compatible   : See the client docs
+- mboxes   : Standard property to specify a Mailbox (See 
./mailbox.txt)
+ Cells must match 'mbox-cells' (See Controller docs 
above)
+
+Optional properties
+- mbox-names   : Name given to channels seen in the 'mboxes' property.
+
+Example:
+
+stub_clock: stub_clock {
+   compatible = "hisilicon,hi3660-stub-clk";
+   reg = <0x0 0xe896b500 0x0 0x0100>;
+   #clock-cells = <1>;
+   mbox-names = "mbox-tx";
+   mboxes = <&mailbox 13 3 0>;
+};
-- 
1.9.1



[PATCH v2 3/3] dts: arm64: Add mailbox binding for hi3660

2017-10-26 Thread Kaihua Zhong
Add DT binding for mailbox driver.

Cc: John Stultz 
Cc: Guodong Xu 
Cc: Haojian Zhuang 
Cc: Niranjan Yadla 
Cc: Raj Pawate 
Signed-off-by: Leo Yan 
Signed-off-by: Ruyi Wang 
Signed-off-by: Kaihua Zhong 
---
 arch/arm64/boot/dts/hisilicon/hi3660.dtsi | 8 
 1 file changed, 8 insertions(+)

diff --git a/arch/arm64/boot/dts/hisilicon/hi3660.dtsi 
b/arch/arm64/boot/dts/hisilicon/hi3660.dtsi
index 610990f..451b6bf 100644
--- a/arch/arm64/boot/dts/hisilicon/hi3660.dtsi
+++ b/arch/arm64/boot/dts/hisilicon/hi3660.dtsi
@@ -285,6 +285,14 @@
#reset-cells = <2>;
};
 
+   mailbox: mailbox@e896b000 {
+   compatible = "hisilicon,hi3660-mbox";
+   reg = <0x0 0xe896b000 0x0 0x1000>;
+   interrupts = ,
+;
+   #mbox-cells = <3>;
+   };
+
dual_timer0: timer@fff14000 {
compatible = "arm,sp804", "arm,primecell";
reg = <0x0 0xfff14000 0x0 0x1000>;
-- 
1.9.1



Re: [PATCH v2] kprobes: avoid the kprobe being re-registered

2017-10-26 Thread zhouchengming

On 2017/10/27 13:57, Masami Hiramatsu wrote:

On Fri, 27 Oct 2017 09:56:40 +0800
Zhou Chengming  wrote:


Changes from v1:
- We should put the modifies of the kprobe after the re-reg check.
- And then the address_safe check.
- When check_kprobe_address_safe() return fail, the *probed_mod
   should be set to NULL, and no module refcount held.

Could you split this item from this patch (with initializing probe_mod = NULL),
since it is another bug?

Thank you,


Ok, it seems more reasonable. I will split this patch into two patches later.

Thank you.


Old code use check_kprobe_rereg() to check if the kprobe has been
registered already, but check_kprobe_rereg() will release the
kprobe_mutex then, so maybe two paths will pass the check and
register the same kprobe. This patch put the check inside the mutex.

Signed-off-by: Zhou Chengming
---
  kernel/kprobes.c | 28 +---
  1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index a1606a4..f622639 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1443,19 +1443,6 @@ static struct kprobe *__get_valid_kprobe(struct kprobe 
*p)
return ap;
  }

-/* Return error if the kprobe is being re-registered */
-static inline int check_kprobe_rereg(struct kprobe *p)
-{
-   int ret = 0;
-
-   mutex_lock(&kprobe_mutex);
-   if (__get_valid_kprobe(p))
-   ret = -EINVAL;
-   mutex_unlock(&kprobe_mutex);
-
-   return ret;
-}
-
  int __weak arch_check_ftrace_location(struct kprobe *p)
  {
unsigned long ftrace_addr;
@@ -1501,6 +1488,7 @@ static int check_kprobe_address_safe(struct kprobe *p,
 * its code to prohibit unexpected unloading.
 */
if (unlikely(!try_module_get(*probed_mod))) {
+   *probed_mod = NULL;
ret = -ENOENT;
goto out;
}
@@ -1536,9 +1524,13 @@ int register_kprobe(struct kprobe *p)
return PTR_ERR(addr);
p->addr = addr;

-   ret = check_kprobe_rereg(p);
-   if (ret)
-   return ret;
+   mutex_lock(&kprobe_mutex);
+
+   /* Return error if the kprobe is being re-registered */
+   if (__get_valid_kprobe(p)) {
+   ret = -EINVAL;
+   goto out;
+   }

/* User can pass only KPROBE_FLAG_DISABLED to register_kprobe */
p->flags&= KPROBE_FLAG_DISABLED;
@@ -1547,9 +1539,7 @@ int register_kprobe(struct kprobe *p)

ret = check_kprobe_address_safe(p,&probed_mod);
if (ret)
-   return ret;
-
-   mutex_lock(&kprobe_mutex);
+   goto out;

old_p = get_kprobe(p->addr);
if (old_p) {
--
1.8.3.1








[PATCH v2 2/3] mailbox: Add support for Hi3660 mailbox

2017-10-26 Thread Kaihua Zhong
Hi3660 mailbox controller is used to send message within multiple
processors, MCU, HIFI, etc.  It supports 32 mailbox channels and every
channel can only be used for single transferring direction.  Once the
channel is enabled, it needs to specify the destination interrupt and
acknowledge interrupt, these two interrupt vectors are used to create
the connection between the mailbox and interrupt controllers.

The application processor (or from point of view of kernel) is not the
only one master which can launch the data transferring, other
processors or MCU/DSP also can kick off the data transferring.  So this
driver implements a locking mechanism to support exclusive accessing.

The data transferring supports two modes, one is named as "automatic
acknowledge" mode so after send message the kernel doesn't need to wait
for acknowledge from remote and directly return; there have another mode
is to rely on handling interrupt for acknowledge.

This commit is for initial version driver, which only supports
"automatic acknowledge" mode to support CPU clock, which is the only
one consumer to use mailbox and has been verified.  Later may enhance
this driver for interrupt mode (e.g. for supporting HIFI).

Cc: John Stultz 
Cc: Guodong Xu 
Cc: Haojian Zhuang 
Cc: Niranjan Yadla 
Cc: Raj Pawate 
Signed-off-by: Leo Yan 
Signed-off-by: Ruyi Wang 
Signed-off-by: Kaihua Zhong 
Signed-off-by: Kevin Wang 
---
 drivers/mailbox/Kconfig  |   8 +
 drivers/mailbox/Makefile |   2 +
 drivers/mailbox/hi3660-mailbox.c | 331 +++
 3 files changed, 341 insertions(+)
 create mode 100644 drivers/mailbox/hi3660-mailbox.c

diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig
index c5731e5..4b5d6e9 100644
--- a/drivers/mailbox/Kconfig
+++ b/drivers/mailbox/Kconfig
@@ -108,6 +108,14 @@ config TI_MESSAGE_MANAGER
  multiple processors within the SoC. Select this driver if your
  platform has support for the hardware block.
 
+config HI3660_MBOX
+   tristate "Hi3660 Mailbox"
+   depends on ARCH_HISI && OF
+   help
+ An implementation of the hi3660 mailbox. It is used to send message
+ between application processors and other processors/MCU/DSP. Select
+ Y here if you want to use Hi3660 mailbox controller.
+
 config HI6220_MBOX
tristate "Hi6220 Mailbox"
depends on ARCH_HISI
diff --git a/drivers/mailbox/Makefile b/drivers/mailbox/Makefile
index d54e412..7d1bd51 100644
--- a/drivers/mailbox/Makefile
+++ b/drivers/mailbox/Makefile
@@ -26,6 +26,8 @@ obj-$(CONFIG_TI_MESSAGE_MANAGER) += ti-msgmgr.o
 
 obj-$(CONFIG_XGENE_SLIMPRO_MBOX) += mailbox-xgene-slimpro.o
 
+obj-$(CONFIG_HI3660_MBOX)  += hi3660-mailbox.o
+
 obj-$(CONFIG_HI6220_MBOX)  += hi6220-mailbox.o
 
 obj-$(CONFIG_BCM_PDC_MBOX) += bcm-pdc-mailbox.o
diff --git a/drivers/mailbox/hi3660-mailbox.c b/drivers/mailbox/hi3660-mailbox.c
new file mode 100644
index 000..67df8f8
--- /dev/null
+++ b/drivers/mailbox/hi3660-mailbox.c
@@ -0,0 +1,331 @@
+/*
+ * Hisilicon's Hi3660 mailbox controller driver
+ *
+ * Copyright (c) 2017 Hisilicon Limited.
+ * Copyright (c) 2017 Linaro Limited.
+ *
+ * Author: Leo Yan 
+ *
+ * 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, version 2 of the License.
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mailbox.h"
+
+#define MBOX_CHAN_MAX  32
+
+#define MBOX_RX(0x0)
+#define MBOX_TX(0x1)
+
+#define MBOX_BASE(mbox, ch)((mbox)->base + ((ch) * 0x40))
+#define MBOX_SRC_REG   (0x00)
+#define MBOX_DST_REG   (0x04)
+#define MBOX_DCLR_REG  (0x08)
+#define MBOX_DSTAT_REG (0x0c)
+#define MBOX_MODE_REG  (0x10)
+#define MBOX_IMASK_REG (0x14)
+#define MBOX_ICLR_REG  (0x18)
+#define MBOX_SEND_REG  (0x1c)
+#define MBOX_DATA_REG  (0x20)
+
+#define MBOX_IPC_LOCK_REG  (0xa00)
+#define MBOX_IPC_UNLOCK(0x1acce551)
+
+#define MBOX_AUTOMATIC_ACK (1)
+
+#define MBOX_STATE_IDLEBIT(4)
+#define MBOX_STATE_ACK BIT(7)
+
+#define MBOX_MSG_LEN   8
+
+/**
+ * Hi3660 mailbox channel device data
+ *
+ * A channel can be used for TX or RX, it can trigger remote
+ * processor interrupt to notify remote processor and can receive
+ * interrupt if has incoming mess

[PATCH] selftests/ftrace: Do not use arch dependent do_IRQ as a target function

2017-10-26 Thread Masami Hiramatsu
Instead using arch-dependent do_IRQ, use do_softirq as a
target function.

Applying do_IRQ to set_ftrace_filter always fail on arm/arm64 and any
other architectures which don't define do_IRQ. So, instead of using
that, use do_softirq which is defined in kernel/softirq.c.

Signed-off-by: Masami Hiramatsu 
---
 .../ftrace/test.d/ftrace/func_set_ftrace_file.tc   |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/tools/testing/selftests/ftrace/test.d/ftrace/func_set_ftrace_file.tc 
b/tools/testing/selftests/ftrace/test.d/ftrace/func_set_ftrace_file.tc
index 113b4d9bc733..20f15c858af6 100644
--- a/tools/testing/selftests/ftrace/test.d/ftrace/func_set_ftrace_file.tc
+++ b/tools/testing/selftests/ftrace/test.d/ftrace/func_set_ftrace_file.tc
@@ -32,7 +32,7 @@ do_reset
 
 FILTER=set_ftrace_filter
 FUNC1="schedule"
-FUNC2="do_IRQ"
+FUNC2="do_softirq"
 
 ALL_FUNCS=" all functions enabled "
 



Re: [PATCH 01/12] Input: ad7897 - use managed devm_device_add_group

2017-10-26 Thread Andi Shyti
Hi Dmitry,

> > Commit 57b8ff070f98 ("driver core: add devm_device_add_group()
> > and friends") has added the the managed version for creating
> > sysfs group files.
> > 
> > Use devm_device_add_group instead of sysfs_create_group and
> > remove the relative sysfs_remove_group and goto label.
> > 
> > CC: Michael Hennerich 
> > Signed-off-by: Andi Shyti 
> > ---
> >  drivers/input/touchscreen/ad7877.c | 8 ++--
> >  1 file changed, 2 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/input/touchscreen/ad7877.c 
> > b/drivers/input/touchscreen/ad7877.c
> > index 9c250ae780d9..677ba38b4d1c 100644
> > --- a/drivers/input/touchscreen/ad7877.c
> > +++ b/drivers/input/touchscreen/ad7877.c
> > @@ -783,18 +783,16 @@ static int ad7877_probe(struct spi_device *spi)
> > goto err_free_mem;
> > }
> >  
> > -   err = sysfs_create_group(&spi->dev.kobj, &ad7877_attr_group);
> > +   err = devm_device_add_group(&spi->dev, &ad7877_attr_group);
> 
> This changes order of operations and ultimately may cause use-after-free
> as memory for ad7877 structure will be freed before we remove
> attributes.

yes, right... sorry... was too fast at making these patches :)
I'll send a second version over the weekend.

Andi


Re: WARNING in refcount_sub_and_test

2017-10-26 Thread Dmitry Vyukov
On Thu, Oct 26, 2017 at 6:56 PM, Xin Long  wrote:
> Hi all,
>
> I am failed to reproduce it on target kernel with the reproducer file
> or replaying the target syzkaller description log file, do I made
> something wrong or there exists more subjects then the line in
> repro.txt:
>
> #{Threaded:true Collide:true Repeat:false Procs:1 Sandbox:namespace
> Fault:false FaultCall:-1 FaultNth:0 EnableTun:false UseTmpDir:true
> HandleSegv:false WaitRepeat:false Debug:false Repro:false}


 Hi ChunYu,

 I've just re-tested the C repro and was able to trigger the bug in a 
 second.
 I've checked out 49ca1943a7adb429b11b8e05d81bc821694b76c7, copied the
 provided config, run make olddefconfig, built with gcc-7 (you can get
 the exact one here
 https://storage.googleapis.com/syzkaller/gcc-7.tar.gz). Then run in
 qemu (most of the flags are probably irrelevant):

 qemu-system-x86_64 -hda wheezy.img -net
 user,host=10.0.2.10,hostfwd=tcp::10022-:22 -net nic -nographic -kernel
 arch/x86/boot/bzImage -append "kvm-intel.nested=1
 kvm-intel.unrestricted_guest=1 kvm-intel.ept=1
 kvm-intel.flexpriority=1 kvm-intel.vpid=1
 kvm-intel.emulate_invalid_guest_state=1 kvm-intel.eptad=1
 kvm-intel.enable_shadow_vmcs=1 kvm-intel.pml=1
 kvm-intel.enable_apicv=1 console=ttyS0 root=/dev/sda
 earlyprintk=serial slub_debug=UZ vsyscall=native rodata=n oops=panic
 panic_on_warn=1 panic=86400" -enable-kvm -pidfile vm_pid -m 2G -smp 4
 -cpu host -usb -usbdevice mouse -usbdevice tablet -soundhw all
>>> Just wondering where we can get wheezy.img, if I can't download
>>> somewhere, can you provide one if possible ?
>>>
>>> I made some imgs before, with kernel built with the .config mail-list
>>> usually gave, the guest always failed to boot.
>>
>> Makes sense. Added image/key links here:
>> https://github.com/google/syzkaller/blob/master/docs/syzbot.md#crash-does-not-reproduce
>>
>> Here are commands to start qemu, ssh into the VM. This just worked for
>> me to reproduce the crash.
>>
>> qemu-system-x86_64 -hda wheezy.img -net
>> user,host=10.0.2.10,hostfwd=tcp::10022-:22 -net nic -nographic -kernel
>> arch/x86/boot/bzImage -append "kvm-intel.nested=1
>> kvm-intel.unrestricted_guest=1 kvm-intel.ept=1
>> kvm-intel.flexpriority=1 kvm-intel.vpid=1
>> kvm-intel.emulate_invalid_guest_state=1 kvm-intel.eptad=1
>> kvm-intel.enable_shadow_vmcs=1 kvm-intel.pml=1
>> kvm-intel.enable_apicv=1 console=ttyS0 root=/dev/sda
>> earlyprintk=serial vsyscall=native rodata=n oops=panic panic_on_warn=1
>> panic=86400" -enable-kvm -m 2G -smp 4 -cpu host -usb -usbdevice mouse
>> -usbdevice tablet -soundhw all
>>
>> ssh -i wheezy.img.key -p 10022 -o UserKnownHostsFile=/dev/null -o
>> StrictHostKeyChecking=no -o IdentitiesOnly=yes root@localhost
> Works, and be able to reproduce the issue. Thanks Dmitry.

Great!

> Another thing is (you might also notice):
> https://paste.fedoraproject.org/paste/N~htmOMPUSiIXGUeLH7yIw
> This call trace always comes up after kernel has started.

Yes, I've noticed this one. It seems to happen on a first incoming
network connection (ssh/scp). I have not seen it before.


Re: WARNING in refcount_sub_and_test

2017-10-26 Thread Dmitry Vyukov
On Fri, Oct 27, 2017 at 4:30 AM, ChunYu Wang  wrote:
> Maybe I have just made some mistakes on understanding the reproduction
> methods, will try it again.


This is reproducible with the C program. If bot posts it, it was able
to reproduce the bug with the compiled C program. If it was not able
to reproduce with a C program, then it will post just syzkaller
program.

To answer your question re running these programs. To reproduce one
needs to save this to a file:

#{Threaded:true Collide:true Repeat:false Procs:1 Sandbox:namespace
Fault:false FaultCall:-1 FaultNth:0 EnableTun:false UseTmpDir:true
HandleSegv:false WaitRepeat:false Debug:false Repro:false}
mmap(&(0x7f00/0xb5)=nil, 0xb5, 0x3, 0x32,
0x, 0x0)
r0 = socket$inet_sctp(0x2, 0x1, 0x84)
listen(r0, 0x11c8)
accept4(r0, &(0x7fb54000-0x10)=@ethernet={0x0, @local={[0x0, 0x0,
0x0, 0x0, 0x0], 0x0}, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]},
&(0x7f138000-0x4)=0x10, 0x8)
listen(r0, 0x0)
sendto$inet(r0,
&(0x7f002000-0x68)="3755cecb8ecfa33eced658b46a028cba4565dff33dff05002377",
0x1a, 0x4, &(0x7f944000)={0x2, 0x3, @loopback=0x7f01, [0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}, 0x10)

and then run:

./syz-execprog -sandbox=namespace saved.prog.file

If syz-executor is not in the current dir, then also add -executor
/path/to/syz-executor.
-threaded and -collide flags are true by default, so it's not
necessary to add them in this case.

If it does not reproduce, it may be useful to run:

./syz-execprog -sandbox=namespace -procs=8 -repeat=0 saved.prog.file
i.e. repeat executing it in infinite loop with 8 parallel processes,
as lots of bugs are caused by races.



> On Thu, Oct 26, 2017 at 10:49 PM, Dmitry Vyukov  wrote:
>> On Thu, Oct 26, 2017 at 10:53 AM, ChunYu Wang  wrote:
>>> Hi all,
>>>
>>> I am failed to reproduce it on target kernel with the reproducer file
>>> or replaying the target syzkaller description log file, do I made
>>> something wrong or there exists more subjects then the line in
>>> repro.txt:
>>>
>>> #{Threaded:true Collide:true Repeat:false Procs:1 Sandbox:namespace
>>> Fault:false FaultCall:-1 FaultNth:0 EnableTun:false UseTmpDir:true
>>> HandleSegv:false WaitRepeat:false Debug:false Repro:false}
>>
>>
>> Hi ChunYu,
>>
>> I've just re-tested the C repro and was able to trigger the bug in a second.
>> I've checked out 49ca1943a7adb429b11b8e05d81bc821694b76c7, copied the
>> provided config, run make olddefconfig, built with gcc-7 (you can get
>> the exact one here
>> https://storage.googleapis.com/syzkaller/gcc-7.tar.gz). Then run in
>> qemu (most of the flags are probably irrelevant):
>>
>> qemu-system-x86_64 -hda wheezy.img -net
>> user,host=10.0.2.10,hostfwd=tcp::10022-:22 -net nic -nographic -kernel
>> arch/x86/boot/bzImage -append "kvm-intel.nested=1
>> kvm-intel.unrestricted_guest=1 kvm-intel.ept=1
>> kvm-intel.flexpriority=1 kvm-intel.vpid=1
>> kvm-intel.emulate_invalid_guest_state=1 kvm-intel.eptad=1
>> kvm-intel.enable_shadow_vmcs=1 kvm-intel.pml=1
>> kvm-intel.enable_apicv=1 console=ttyS0 root=/dev/sda
>> earlyprintk=serial slub_debug=UZ vsyscall=native rodata=n oops=panic
>> panic_on_warn=1 panic=86400" -enable-kvm -pidfile vm_pid -m 2G -smp 4
>> -cpu host -usb -usbdevice mouse -usbdevice tablet -soundhw all
>>
>> And running the provided C program instantly spewed the following.
>>
>> Is there anything you did differently? I would like to understand
>> common reasons why syzbot reproducers don't work and outline them
>> here:
>> https://github.com/google/syzkaller/blob/master/docs/syzbot.md
>>
>> Thanks
>>
>>
>> [  588.444300] refcount_t: underflow; use-after-free.
>> [  588.445812] [ cut here ]
>> [  588.447026] WARNING: CPU: 1 PID: 3086 at lib/refcount.c:186
>> refcount_sub_and_test+0x167/0x1b0
>> [  588.449082] Kernel panic - not syncing: panic_on_warn set ...
>> [  588.449082]
>> [  588.450737] CPU: 1 PID: 3086 Comm: a.out Not tainted 4.14.0-rc5+ #9
>> [  588.452160] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996),
>> BIOS Bochs 01/01/2011
>> [  588.454059] Call Trace:
>> [  588.454658]  dump_stack+0x194/0x257
>> [  588.455538]  ? arch_local_irq_restore+0x53/0x53
>> [  588.456630]  panic+0x1e4/0x417
>> [  588.457367]  ? __warn+0x1d9/0x1d9
>> [  588.458171]  ? show_regs_print_info+0x65/0x65
>> [  588.459234]  ? refcount_sub_and_test+0x167/0x1b0
>> [  588.460262]  __warn+0x1c4/0x1d9
>> [  588.460958]  ? refcount_sub_and_test+0x167/0x1b0
>> [  588.461965]  report_bug+0x211/0x2d0
>> [  588.462756]  fixup_bug+0x40/0x90
>> [  588.463597]  do_trap+0x260/0x390
>> [  588.464304]  do_error_trap+0x120/0x390
>> [  588.465105]  ? vprintk_emit+0x49b/0x590
>> [  588.465929]  ? do_trap+0x390/0x390
>> [  588.41]  ? refcount_sub_and_test+0x167/0x1b0
>> [  588.467646]  ? vprintk_emit+0x3ea/0x590
>> [  588.468475]  ? trace_hardirqs_off_thunk+0x1a/0x1c
>> [  588.469482]  do_invalid_op+0x1b/0x20
>> [  588.470262]  invalid_op+0x18/0x20
>> [  588.470988] R

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

2017-10-26 Thread Dmitry Vyukov
On Thu, Oct 26, 2017 at 7:58 PM, Tejun Heo  wrote:
> Hello,
>
> On Thu, Oct 26, 2017 at 09:35:44AM -0700, syzbot wrote:
>> BUG: KASAN: use-after-free in __read_once_size
>> include/linux/compiler.h:276 [inline]
>> BUG: KASAN: use-after-free in atomic64_read
>> arch/x86/include/asm/atomic64_64.h:21 [inline]
>> BUG: KASAN: use-after-free in atomic_long_read
>> include/asm-generic/atomic-long.h:44 [inline]
>> BUG: KASAN: use-after-free in get_work_pool+0x1c2/0x1e0
>> kernel/workqueue.c:709
>> Read of size 8 at addr 8801cc58c378 by task syz-executor5/21326
>>
>> CPU: 1 PID: 21326 Comm: syz-executor5 Not tainted 4.13.0+ #43
>> Hardware name: Google Google Compute Engine/Google Compute Engine,
>> BIOS Google 01/01/2011
>> Call Trace:
>>  __dump_stack lib/dump_stack.c:16 [inline]
>>  dump_stack+0x194/0x257 lib/dump_stack.c:52
>>  print_address_description+0x73/0x250 mm/kasan/report.c:252
>>  kasan_report_error mm/kasan/report.c:351 [inline]
>>  kasan_report+0x24e/0x340 mm/kasan/report.c:409
>>  __asan_report_load8_noabort+0x14/0x20 mm/kasan/report.c:430
>>  __read_once_size include/linux/compiler.h:276 [inline]
>>  atomic64_read arch/x86/include/asm/atomic64_64.h:21 [inline]
>>  atomic_long_read include/asm-generic/atomic-long.h:44 [inline]
>>  get_work_pool+0x1c2/0x1e0 kernel/workqueue.c:709
>>  __queue_work+0x235/0x1150 kernel/workqueue.c:1401
>>  queue_work_on+0x16a/0x1c0 kernel/workqueue.c:1486
>>  queue_work include/linux/workqueue.h:489 [inline]
>>  strp_check_rcv+0x25/0x30 net/strparser/strparser.c:553
>>  kcm_attach net/kcm/kcmsock.c:1439 [inline]
>>  kcm_attach_ioctl net/kcm/kcmsock.c:1460 [inline]
>>  kcm_ioctl+0x826/0x1610 net/kcm/kcmsock.c:1695
>>  sock_do_ioctl+0x65/0xb0 net/socket.c:961
>>  sock_ioctl+0x2c2/0x440 net/socket.c:1058
>>  vfs_ioctl fs/ioctl.c:45 [inline]
>>  do_vfs_ioctl+0x1b1/0x1530 fs/ioctl.c:685
>>  SYSC_ioctl fs/ioctl.c:700 [inline]
>>  SyS_ioctl+0x8f/0xc0 fs/ioctl.c:691
>>  entry_SYSCALL_64_fastpath+0x1f/0xbe
>
> Looks like kcm is trying to reuse a work item whose last workqueue has
> been destroyed without re-initing it.  A work item needs to be
> reinit'd.

+kcm maintainers

> ---
> This bug is generated by a dumb bot. It may contain errors.
> See https://goo.gl/tpsmEJ for details.
> Direct all questions to syzkal...@googlegroups.com.
>
> syzbot will keep track of this bug report.
> Once a fix for this bug is committed, please reply to this email with:
> #syz fix: exact-commit-title
> To mark this as a duplicate of another syzbot report, please reply with:
> #syz dup: exact-subject-of-another-report
> If it's a one-off invalid bug report, please reply with:
> #syz invalid
> Note: if the crash happens again, it will cause creation of a new bug
> report.


[PATCH] drivers/net: dlink: Convert timers to use timer_setup()

2017-10-26 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Denis Kirjanov 
Cc: net...@vger.kernel.org
Signed-off-by: Kees Cook 
---
 drivers/net/ethernet/dlink/sundance.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/dlink/sundance.c 
b/drivers/net/ethernet/dlink/sundance.c
index 6ca9e981ad57..1a27176381fb 100644
--- a/drivers/net/ethernet/dlink/sundance.c
+++ b/drivers/net/ethernet/dlink/sundance.c
@@ -431,7 +431,7 @@ static void mdio_write(struct net_device *dev, int phy_id, 
int location, int val
 static int  mdio_wait_link(struct net_device *dev, int wait);
 static int  netdev_open(struct net_device *dev);
 static void check_duplex(struct net_device *dev);
-static void netdev_timer(unsigned long data);
+static void netdev_timer(struct timer_list *t);
 static void tx_timeout(struct net_device *dev);
 static void init_ring(struct net_device *dev);
 static netdev_tx_t start_tx(struct sk_buff *skb, struct net_device *dev);
@@ -913,7 +913,7 @@ static int netdev_open(struct net_device *dev)
   ioread16(ioaddr + MACCtrl1), ioread16(ioaddr + 
MACCtrl0));
 
/* Set the timer to check for link beat. */
-   setup_timer(&np->timer, netdev_timer, (unsigned long)dev);
+   timer_setup(&np->timer, netdev_timer, 0);
np->timer.expires = jiffies + 3*HZ;
add_timer(&np->timer);
 
@@ -951,10 +951,10 @@ static void check_duplex(struct net_device *dev)
}
 }
 
-static void netdev_timer(unsigned long data)
+static void netdev_timer(struct timer_list *t)
 {
-   struct net_device *dev = (struct net_device *)data;
-   struct netdev_private *np = netdev_priv(dev);
+   struct netdev_private *np = from_timer(np, t, timer);
+   struct net_device *dev = np->mii_if.dev;
void __iomem *ioaddr = np->base;
int next_tick = 10*HZ;
 
-- 
2.7.4


-- 
Kees Cook
Pixel Security


Re: [RFC PATCH v8 1/7] dt-bindings: PCI: Add definition of PCIe WAKE# irq and PCI irq

2017-10-26 Thread jeffy

Hi Brian,

On 10/27/2017 01:40 PM, Brian Norris wrote:

Another odd thing about this series is that the interrupt doesn't
actually show up in /proc/interrupts, /sys/kernel/debug/gpio, or
similar, seemingly because the wakeirq is requested/released every time
we suspend/resume. So it's really not that obvious that the interrupt is
being configured properly. That's not really a functional problem,
necessarily, but it doesn't quite seem ideal.

right, so maybe we can call dev_pm_set_dedicated_wake_irq() in the 
setup(), and use device_set_wakeup_enable() to enable/disable it in the 
set_wakeup()?



Brian





[PATCH] drivers/net: korina: Convert timers to use timer_setup()

2017-10-26 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: "David S. Miller" 
Cc: Roman Yeryomin 
Cc: Florian Fainelli 
Cc: net...@vger.kernel.org
Signed-off-by: Kees Cook 
---
 drivers/net/ethernet/korina.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/korina.c b/drivers/net/ethernet/korina.c
index 7cecd9dbc111..ae195f8adff5 100644
--- a/drivers/net/ethernet/korina.c
+++ b/drivers/net/ethernet/korina.c
@@ -653,10 +653,10 @@ static void korina_check_media(struct net_device *dev, 
unsigned int init_media)
&lp->eth_regs->ethmac2);
 }
 
-static void korina_poll_media(unsigned long data)
+static void korina_poll_media(struct timer_list *t)
 {
-   struct net_device *dev = (struct net_device *) data;
-   struct korina_private *lp = netdev_priv(dev);
+   struct korina_private *lp = from_timer(lp, t, media_check_timer);
+   struct net_device *dev = lp->dev;
 
korina_check_media(dev, 0);
mod_timer(&lp->media_check_timer, jiffies + HZ);
@@ -1103,7 +1103,7 @@ static int korina_probe(struct platform_device *pdev)
": cannot register net device: %d\n", rc);
goto probe_err_register;
}
-   setup_timer(&lp->media_check_timer, korina_poll_media, (unsigned long) 
dev);
+   timer_setup(&lp->media_check_timer, korina_poll_media, 0);
 
INIT_WORK(&lp->restart_task, korina_restart_task);
 
-- 
2.7.4


-- 
Kees Cook
Pixel Security


Re: [PATCH v2] kprobes: avoid the kprobe being re-registered

2017-10-26 Thread Masami Hiramatsu
On Fri, 27 Oct 2017 09:56:40 +0800
Zhou Chengming  wrote:

> Changes from v1:
> - We should put the modifies of the kprobe after the re-reg check.
> - And then the address_safe check.
> - When check_kprobe_address_safe() return fail, the *probed_mod
>   should be set to NULL, and no module refcount held.

Could you split this item from this patch (with initializing probe_mod = NULL),
since it is another bug?

Thank you,

> 
> Old code use check_kprobe_rereg() to check if the kprobe has been
> registered already, but check_kprobe_rereg() will release the
> kprobe_mutex then, so maybe two paths will pass the check and
> register the same kprobe. This patch put the check inside the mutex.
> 
> Signed-off-by: Zhou Chengming 
> ---
>  kernel/kprobes.c | 28 +---
>  1 file changed, 9 insertions(+), 19 deletions(-)
> 
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index a1606a4..f622639 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -1443,19 +1443,6 @@ static struct kprobe *__get_valid_kprobe(struct kprobe 
> *p)
>   return ap;
>  }
>  
> -/* Return error if the kprobe is being re-registered */
> -static inline int check_kprobe_rereg(struct kprobe *p)
> -{
> - int ret = 0;
> -
> - mutex_lock(&kprobe_mutex);
> - if (__get_valid_kprobe(p))
> - ret = -EINVAL;
> - mutex_unlock(&kprobe_mutex);
> -
> - return ret;
> -}
> -
>  int __weak arch_check_ftrace_location(struct kprobe *p)
>  {
>   unsigned long ftrace_addr;
> @@ -1501,6 +1488,7 @@ static int check_kprobe_address_safe(struct kprobe *p,
>* its code to prohibit unexpected unloading.
>*/
>   if (unlikely(!try_module_get(*probed_mod))) {
> + *probed_mod = NULL;
>   ret = -ENOENT;
>   goto out;
>   }
> @@ -1536,9 +1524,13 @@ int register_kprobe(struct kprobe *p)
>   return PTR_ERR(addr);
>   p->addr = addr;
>  
> - ret = check_kprobe_rereg(p);
> - if (ret)
> - return ret;
> + mutex_lock(&kprobe_mutex);
> +
> + /* Return error if the kprobe is being re-registered */
> + if (__get_valid_kprobe(p)) {
> + ret = -EINVAL;
> + goto out;
> + }
>  
>   /* User can pass only KPROBE_FLAG_DISABLED to register_kprobe */
>   p->flags &= KPROBE_FLAG_DISABLED;
> @@ -1547,9 +1539,7 @@ int register_kprobe(struct kprobe *p)
>  
>   ret = check_kprobe_address_safe(p, &probed_mod);
>   if (ret)
> - return ret;
> -
> - mutex_lock(&kprobe_mutex);
> + goto out;
>  
>   old_p = get_kprobe(p->addr);
>   if (old_p) {
> -- 
> 1.8.3.1
> 


-- 
Masami Hiramatsu 


[PATCH] drivers/net: natsemi: Convert timers to use timer_setup()

2017-10-26 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: "David S. Miller" 
Cc: Allen Pais 
Cc: Eric Dumazet 
Cc: Philippe Reynes 
Cc: Wei Yongjun 
Cc: net...@vger.kernel.org
Signed-off-by: Kees Cook 
---
 drivers/net/ethernet/natsemi/natsemi.c | 10 +-
 drivers/net/ethernet/natsemi/ns83820.c |  8 
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/natsemi/natsemi.c 
b/drivers/net/ethernet/natsemi/natsemi.c
index dedeacd0bbca..b9a1a9f999ea 100644
--- a/drivers/net/ethernet/natsemi/natsemi.c
+++ b/drivers/net/ethernet/natsemi/natsemi.c
@@ -610,7 +610,7 @@ static int netdev_open(struct net_device *dev);
 static void do_cable_magic(struct net_device *dev);
 static void undo_cable_magic(struct net_device *dev);
 static void check_link(struct net_device *dev);
-static void netdev_timer(unsigned long data);
+static void netdev_timer(struct timer_list *t);
 static void dump_ring(struct net_device *dev);
 static void ns_tx_timeout(struct net_device *dev);
 static int alloc_ring(struct net_device *dev);
@@ -1571,7 +1571,7 @@ static int netdev_open(struct net_device *dev)
dev->name, (int)readl(ioaddr + ChipCmd));
 
/* Set the timer to check for link beat. */
-   setup_timer(&np->timer, netdev_timer, (unsigned long)dev);
+   timer_setup(&np->timer, netdev_timer, 0);
np->timer.expires = round_jiffies(jiffies + NATSEMI_TIMER_FREQ);
add_timer(&np->timer);
 
@@ -1787,10 +1787,10 @@ static void init_registers(struct net_device *dev)
  *this check via dspcfg_workaround sysfs option.
  * 3) check of death of the RX path due to OOM
  */
-static void netdev_timer(unsigned long data)
+static void netdev_timer(struct timer_list *t)
 {
-   struct net_device *dev = (struct net_device *)data;
-   struct netdev_private *np = netdev_priv(dev);
+   struct netdev_private *np = from_timer(np, t, timer);
+   struct net_device *dev = np->dev;
void __iomem * ioaddr = ns_ioaddr(dev);
int next_tick = NATSEMI_TIMER_FREQ;
const int irq = np->pci_dev->irq;
diff --git a/drivers/net/ethernet/natsemi/ns83820.c 
b/drivers/net/ethernet/natsemi/ns83820.c
index 99d3c7884a4a..958fced4dacf 100644
--- a/drivers/net/ethernet/natsemi/ns83820.c
+++ b/drivers/net/ethernet/natsemi/ns83820.c
@@ -1600,10 +1600,10 @@ static void ns83820_tx_timeout(struct net_device *ndev)
spin_unlock_irqrestore(&dev->tx_lock, flags);
 }
 
-static void ns83820_tx_watch(unsigned long data)
+static void ns83820_tx_watch(struct timer_list *t)
 {
-   struct net_device *ndev = (void *)data;
-   struct ns83820 *dev = PRIV(ndev);
+   struct ns83820 *dev = from_timer(dev, t, tx_watchdog);
+   struct net_device *ndev = dev->ndev;
 
 #if defined(DEBUG)
printk("ns83820_tx_watch: %u %u %d\n",
@@ -1652,7 +1652,7 @@ static int ns83820_open(struct net_device *ndev)
writel(0, dev->base + TXDP_HI);
writel(desc, dev->base + TXDP);
 
-   setup_timer(&dev->tx_watchdog, ns83820_tx_watch, (unsigned long)ndev);
+   timer_setup(&dev->tx_watchdog, ns83820_tx_watch, 0);
mod_timer(&dev->tx_watchdog, jiffies + 2*HZ);
 
netif_start_queue(ndev);/* FIXME: wait for phy to come up */
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] drivers/net: packetengines: Convert timers to use timer_setup()

2017-10-26 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: "David S. Miller" 
Cc: Allen Pais 
Cc: yuan linyu 
Cc: Philippe Reynes 
Cc: net...@vger.kernel.org
Signed-off-by: Kees Cook 
---
 drivers/net/ethernet/packetengines/hamachi.c   | 14 +++---
 drivers/net/ethernet/packetengines/yellowfin.c | 10 +-
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/packetengines/hamachi.c 
b/drivers/net/ethernet/packetengines/hamachi.c
index 77bc7cca8980..c9529c29a0a7 100644
--- a/drivers/net/ethernet/packetengines/hamachi.c
+++ b/drivers/net/ethernet/packetengines/hamachi.c
@@ -413,13 +413,13 @@ that case.
 
 /* The rest of these values should never change. */
 
-static void hamachi_timer(unsigned long data);
+static void hamachi_timer(struct timer_list *t);
 
 enum capability_flags {CanHaveMII=1, };
 static const struct chip_info {
u16 vendor_id, device_id, device_id_mask, pad;
const char *name;
-   void (*media_timer)(unsigned long data);
+   void (*media_timer)(struct timer_list *t);
int flags;
 } chip_tbl[] = {
{0x1318, 0x0911, 0x, 0, "Hamachi GNIC-II", hamachi_timer, 0},
@@ -547,7 +547,7 @@ static int mdio_read(struct net_device *dev, int phy_id, 
int location);
 static void mdio_write(struct net_device *dev, int phy_id, int location, int 
value);
 static int hamachi_open(struct net_device *dev);
 static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
-static void hamachi_timer(unsigned long data);
+static void hamachi_timer(struct timer_list *t);
 static void hamachi_tx_timeout(struct net_device *dev);
 static void hamachi_init_ring(struct net_device *dev);
 static netdev_tx_t hamachi_start_xmit(struct sk_buff *skb,
@@ -979,7 +979,7 @@ static int hamachi_open(struct net_device *dev)
   dev->name, readw(ioaddr + RxStatus), readw(ioaddr + 
TxStatus));
}
/* Set the timer to check for link beat. */
-   setup_timer(&hmp->timer, hamachi_timer, (unsigned long)dev);
+   timer_setup(&hmp->timer, hamachi_timer, 0);
hmp->timer.expires = RUN_AT((24*HZ)/10);/* 2.4 
sec. */
add_timer(&hmp->timer);
 
@@ -1017,10 +1017,10 @@ static inline int hamachi_tx(struct net_device *dev)
return 0;
 }
 
-static void hamachi_timer(unsigned long data)
+static void hamachi_timer(struct timer_list *t)
 {
-   struct net_device *dev = (struct net_device *)data;
-   struct hamachi_private *hmp = netdev_priv(dev);
+   struct hamachi_private *hmp = from_timer(hmp, t, timer);
+   struct net_device *dev = hmp->mii_if.dev;
void __iomem *ioaddr = hmp->base;
int next_tick = 10*HZ;
 
diff --git a/drivers/net/ethernet/packetengines/yellowfin.c 
b/drivers/net/ethernet/packetengines/yellowfin.c
index 33c241f52a71..54224d1822e3 100644
--- a/drivers/net/ethernet/packetengines/yellowfin.c
+++ b/drivers/net/ethernet/packetengines/yellowfin.c
@@ -343,7 +343,7 @@ static int mdio_read(void __iomem *ioaddr, int phy_id, int 
location);
 static void mdio_write(void __iomem *ioaddr, int phy_id, int location, int 
value);
 static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
 static int yellowfin_open(struct net_device *dev);
-static void yellowfin_timer(unsigned long data);
+static void yellowfin_timer(struct timer_list *t);
 static void yellowfin_tx_timeout(struct net_device *dev);
 static int yellowfin_init_ring(struct net_device *dev);
 static netdev_tx_t yellowfin_start_xmit(struct sk_buff *skb,
@@ -632,7 +632,7 @@ static int yellowfin_open(struct net_device *dev)
}
 
/* Set the timer to check for link beat. */
-   setup_timer(&yp->timer, yellowfin_timer, (unsigned long)dev);
+   timer_setup(&yp->timer, yellowfin_timer, 0);
yp->timer.expires = jiffies + 3*HZ;
add_timer(&yp->timer);
 out:
@@ -643,10 +643,10 @@ static int yellowfin_open(struct net_device *dev)
goto out;
 }
 
-static void yellowfin_timer(unsigned long data)
+static void yellowfin_timer(struct timer_list *t)
 {
-   struct net_device *dev = (struct net_device *)data;
-   struct yellowfin_private *yp = netdev_priv(dev);
+   struct yellowfin_private *yp = from_timer(yp, t, timer);
+   struct net_device *dev = pci_get_drvdata(yp->pci_dev);
void __iomem *ioaddr = yp->base;
int next_tick = 60*HZ;
 
-- 
2.7.4


-- 
Kees Cook
Pixel Security


Re: [RFC PATCH v8 7/7] PCI / PM: Add support for the PCIe WAKE# signal for OF

2017-10-26 Thread Brian Norris
Hi Jeffy,

On Thu, Oct 26, 2017 at 09:28:40PM +0800, Jeffy Chen wrote:
> Add pci-of.c to handle the PCIe WAKE# interrupt.
> 
> Also use the dedicated wakeirq infrastructure to simplify it.
> 
> Signed-off-by: Jeffy Chen 
> ---
> 
> Changes in v8:
> Add pci-of.c and use platform_pm_ops to handle the PCIe WAKE# signal.
> 
> Changes in v7:
> Move PCIE_WAKE handling into pci core.
> 
> Changes in v6:
> Fix device_init_wake error handling, and add some comments.
> 
> Changes in v5:
> Rebase.
> 
> Changes in v3:
> Fix error handling.
> 
> Changes in v2:
> Use dev_pm_set_dedicated_wake_irq.
> 
>  drivers/pci/Makefile |   2 +-
>  drivers/pci/pci-of.c | 136 
> +++
>  2 files changed, 137 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/pci/pci-of.c
> 
> diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
> index 66a21acad952..4f76dbdb024c 100644
> --- a/drivers/pci/Makefile
> +++ b/drivers/pci/Makefile
> @@ -49,7 +49,7 @@ obj-$(CONFIG_PCI_ECAM) += ecam.o
>  
>  obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o
>  
> -obj-$(CONFIG_OF) += of.o
> +obj-$(CONFIG_OF) += of.o pci-of.o
>  
>  ccflags-$(CONFIG_PCI_DEBUG) := -DDEBUG
>  
> diff --git a/drivers/pci/pci-of.c b/drivers/pci/pci-of.c
> new file mode 100644
> index ..55a33206fc84
> --- /dev/null
> +++ b/drivers/pci/pci-of.c
> @@ -0,0 +1,136 @@
> +/*
> + * OF PCI PM support
> + *
> + * Copyright (c) 2017 Rockchip, Inc.
> + *
> + * Author: Jeffy Chen 
> + *
> + * 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.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "pci.h"
> +
> +struct of_pci_pm_data {
> + struct device   *dev;
> + unsigned intwakeup_irq;
> + atomic_twakeup_cnt;
> +};
> +
> +static void *of_pci_setup(struct device *dev)
> +{
> + struct of_pci_pm_data *data;
> + int irq;
> +
> + if (!dev->of_node)
> + return NULL;
> +
> + data = devm_kzalloc(dev, sizeof(struct of_pci_pm_data), GFP_KERNEL);
> + if (!data)
> + return ERR_PTR(-ENOMEM);
> +
> + irq = of_irq_get_byname(dev->of_node, "wakeup");
> + if (irq < 0) {
> + if (irq == -EPROBE_DEFER)
> + return ERR_PTR(irq);
> +
> + return NULL;
> + }
> +
> + data->wakeup_irq = irq;
> + data->dev = dev;
> +
> + device_init_wakeup(dev, false);
> +
> + dev_info(dev, "Wakeup IRQ %d\n", irq);
> + return data;
> +}
> +
> +static void *of_pci_setup_dev(struct pci_dev *pci_dev)
> +{
> + return of_pci_setup(&pci_dev->dev);
> +}
> +
> +static void *of_pci_setup_host_bridge(struct pci_host_bridge *bridge)
> +{
> + return of_pci_setup(bridge->dev.parent);
> +}
> +
> +static void of_pci_cleanup(void *pmdata)
> +{
> + struct of_pci_pm_data *data = pmdata;
> +
> + if (IS_ERR_OR_NULL(data)) {
> + device_init_wakeup(data->dev, false);
> + dev_pm_clear_wake_irq(data->dev);
> + }
> +}
> +
> +static bool of_pci_can_wakeup(void *pmdata)
> +{
> + struct of_pci_pm_data *data = pmdata;
> +
> + if (IS_ERR_OR_NULL(data))
> + return false;
> +
> + return data->wakeup_irq > 0;
> +}
> +
> +static int of_pci_dev_wakeup(void *pmdata, bool enable)
> +{
> + struct of_pci_pm_data *data = pmdata;
> + struct device *dev = data->dev;
> + int ret;
> +
> + if (!enable) {
> + dev_pm_clear_wake_irq(dev);
> + return device_set_wakeup_enable(dev, false);
> + }
> +
> + ret = device_set_wakeup_enable(dev, true);
> + if (ret < 0)
> + return ret;

One reason this series is failing for me: the above is failing with
-EINVAL -- it seems like no one set the 'can_wakeup' flag for the
Marvell Wifi card I'm using. It seems like we probably *should* be
calling device_set_wakeup_capable() from your new setup method, to say
that we're capable of wakeup. The PCI PME code does this already, which
seems to make sense. There are also some network drivers that do it too
(e.g., ath10k), but not all.

Brian

> +
> + ret = dev_pm_set_dedicated_wake_irq(dev, data->wakeup_irq);
> + if (ret < 0) {
> + device_set_wakeup_enable(dev, false);
> + return ret;
> + }
> +
> + return 0;
> +}
> +
> +static int of_pci_bridge_wakeup(void *pmdata, bool enable)
> +{
> + struct of_pci_pm_data *data = pmdata;
> +
> + if (enable && atomic_inc_return(&data->wakeup_cnt) != 1)
> + return 0;
> +
> + if (!enable && atomic_dec_return(&data->wakeup_cnt) != 0)
> + return 0;
> +
> + return of_pci_dev_wakeup(pmdata, enable);
> +}
> +
> +static const struct pci_platform_pm_ops of_pci_platform_pm = {
> + .setup_dev  = of_pci_setup_dev,
> +

[PATCH] netfilter: ipvs: Convert timers to use timer_setup()

2017-10-26 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Wensong Zhang 
Cc: Simon Horman 
Cc: Julian Anastasov 
Cc: Pablo Neira Ayuso 
Cc: Jozsef Kadlecsik 
Cc: Florian Westphal 
Cc: "David S. Miller" 
Cc: net...@vger.kernel.org
Cc: lvs-de...@vger.kernel.org
Cc: netfilter-de...@vger.kernel.org
Cc: coret...@netfilter.org
Signed-off-by: Kees Cook 
---
 net/netfilter/ipvs/ip_vs_conn.c  | 10 +-
 net/netfilter/ipvs/ip_vs_ctl.c   |  7 +++
 net/netfilter/ipvs/ip_vs_est.c   |  6 +++---
 net/netfilter/ipvs/ip_vs_lblc.c  | 11 ++-
 net/netfilter/ipvs/ip_vs_lblcr.c | 11 ++-
 5 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
index 3d2ac71a83ec..3a43b3470331 100644
--- a/net/netfilter/ipvs/ip_vs_conn.c
+++ b/net/netfilter/ipvs/ip_vs_conn.c
@@ -104,7 +104,7 @@ static inline void ct_write_unlock_bh(unsigned int key)
spin_unlock_bh(&__ip_vs_conntbl_lock_array[key&CT_LOCKARRAY_MASK].l);
 }
 
-static void ip_vs_conn_expire(unsigned long data);
+static void ip_vs_conn_expire(struct timer_list *t);
 
 /*
  * Returns hash value for IPVS connection entry
@@ -457,7 +457,7 @@ EXPORT_SYMBOL_GPL(ip_vs_conn_out_get_proto);
 static void __ip_vs_conn_put_notimer(struct ip_vs_conn *cp)
 {
__ip_vs_conn_put(cp);
-   ip_vs_conn_expire((unsigned long)cp);
+   ip_vs_conn_expire(&cp->timer);
 }
 
 /*
@@ -817,9 +817,9 @@ static void ip_vs_conn_rcu_free(struct rcu_head *head)
kmem_cache_free(ip_vs_conn_cachep, cp);
 }
 
-static void ip_vs_conn_expire(unsigned long data)
+static void ip_vs_conn_expire(struct timer_list *t)
 {
-   struct ip_vs_conn *cp = (struct ip_vs_conn *)data;
+   struct ip_vs_conn *cp = from_timer(cp, t, timer);
struct netns_ipvs *ipvs = cp->ipvs;
 
/*
@@ -909,7 +909,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p, int 
dest_af,
}
 
INIT_HLIST_NODE(&cp->c_list);
-   setup_timer(&cp->timer, ip_vs_conn_expire, (unsigned long)cp);
+   timer_setup(&cp->timer, ip_vs_conn_expire, 0);
cp->ipvs   = ipvs;
cp->af = p->af;
cp->daf= dest_af;
diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
index 4f940d7eb2f7..b47e266c6eca 100644
--- a/net/netfilter/ipvs/ip_vs_ctl.c
+++ b/net/netfilter/ipvs/ip_vs_ctl.c
@@ -1146,9 +1146,9 @@ ip_vs_del_dest(struct ip_vs_service *svc, struct 
ip_vs_dest_user_kern *udest)
return 0;
 }
 
-static void ip_vs_dest_trash_expire(unsigned long data)
+static void ip_vs_dest_trash_expire(struct timer_list *t)
 {
-   struct netns_ipvs *ipvs = (struct netns_ipvs *)data;
+   struct netns_ipvs *ipvs = from_timer(ipvs, t, dest_trash_timer);
struct ip_vs_dest *dest, *next;
unsigned long now = jiffies;
 
@@ -4019,8 +4019,7 @@ int __net_init ip_vs_control_net_init(struct netns_ipvs 
*ipvs)
 
INIT_LIST_HEAD(&ipvs->dest_trash);
spin_lock_init(&ipvs->dest_trash_lock);
-   setup_timer(&ipvs->dest_trash_timer, ip_vs_dest_trash_expire,
-   (unsigned long) ipvs);
+   timer_setup(&ipvs->dest_trash_timer, ip_vs_dest_trash_expire, 0);
atomic_set(&ipvs->ftpsvc_counter, 0);
atomic_set(&ipvs->nullsvc_counter, 0);
atomic_set(&ipvs->conn_out_counter, 0);
diff --git a/net/netfilter/ipvs/ip_vs_est.c b/net/netfilter/ipvs/ip_vs_est.c
index 457c6c193e13..489055091a9b 100644
--- a/net/netfilter/ipvs/ip_vs_est.c
+++ b/net/netfilter/ipvs/ip_vs_est.c
@@ -97,12 +97,12 @@ static void ip_vs_read_cpu_stats(struct ip_vs_kstats *sum,
 }
 
 
-static void estimation_timer(unsigned long arg)
+static void estimation_timer(struct timer_list *t)
 {
struct ip_vs_estimator *e;
struct ip_vs_stats *s;
u64 rate;
-   struct netns_ipvs *ipvs = (struct netns_ipvs *)arg;
+   struct netns_ipvs *ipvs = from_timer(ipvs, t, est_timer);
 
spin_lock(&ipvs->est_lock);
list_for_each_entry(e, &ipvs->est_list, list) {
@@ -192,7 +192,7 @@ int __net_init ip_vs_estimator_net_init(struct netns_ipvs 
*ipvs)
 {
INIT_LIST_HEAD(&ipvs->est_list);
spin_lock_init(&ipvs->est_lock);
-   setup_timer(&ipvs->est_timer, estimation_timer, (unsigned long)ipvs);
+   timer_setup(&ipvs->est_timer, estimation_timer, 0);
mod_timer(&ipvs->est_timer, jiffies + 2 * HZ);
return 0;
 }
diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
index b6aa4a970c6e..d625179de485 100644
--- a/net/netfilter/ipvs/ip_vs_lblc.c
+++ b/net/netfilter/ipvs/ip_vs_lblc.c
@@ -106,6 +106,7 @@ struct ip_vs_lblc_table {
struct rcu_head rcu_head;
struct hlist_head   bucket[IP_VS_LBLC_TAB_SIZE];  /* hash bucket */
struct timer_list   periodic_timer; /* collect stale entries */

[PATCH] drivers/net: mellanox: Convert timers to use timer_setup()

2017-10-26 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Saeed Mahameed 
Cc: Matan Barak 
Cc: Leon Romanovsky 
Cc: net...@vger.kernel.org
Cc: linux-r...@vger.kernel.org
Signed-off-by: Kees Cook 
---
 drivers/net/ethernet/mellanox/mlx5/core/health.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/health.c 
b/drivers/net/ethernet/mellanox/mlx5/core/health.c
index a89a68ce53ad..185dcac0abe7 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/health.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/health.c
@@ -285,9 +285,9 @@ void mlx5_trigger_health_work(struct mlx5_core_dev *dev)
spin_unlock_irqrestore(&health->wq_lock, flags);
 }
 
-static void poll_health(unsigned long data)
+static void poll_health(struct timer_list *t)
 {
-   struct mlx5_core_dev *dev = (struct mlx5_core_dev *)data;
+   struct mlx5_core_dev *dev = from_timer(dev, t, priv.health.timer);
struct mlx5_core_health *health = &dev->priv.health;
u32 count;
 
@@ -320,7 +320,7 @@ void mlx5_start_health_poll(struct mlx5_core_dev *dev)
 {
struct mlx5_core_health *health = &dev->priv.health;
 
-   setup_timer(&health->timer, poll_health, (unsigned long)dev);
+   timer_setup(&health->timer, poll_health, 0);
health->sick = 0;
clear_bit(MLX5_DROP_NEW_HEALTH_WORK, &health->flags);
clear_bit(MLX5_DROP_NEW_RECOVERY_WORK, &health->flags);
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] drivers/net: smsc: Convert timers to use timer_setup()

2017-10-26 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: "David S. Miller" 
Cc: "yuval.sh...@oracle.com" 
Cc: Eric Dumazet 
Cc: Philippe Reynes 
Cc: Allen Pais 
Cc: Tobias Klauser 
Cc: net...@vger.kernel.org
Signed-off-by: Kees Cook 
---
 drivers/net/ethernet/smsc/epic100.c | 10 +-
 drivers/net/ethernet/smsc/smc91c92_cs.c | 10 +-
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/smsc/epic100.c 
b/drivers/net/ethernet/smsc/epic100.c
index 2a9724898fcf..949aaef390b6 100644
--- a/drivers/net/ethernet/smsc/epic100.c
+++ b/drivers/net/ethernet/smsc/epic100.c
@@ -290,7 +290,7 @@ static int read_eeprom(struct epic_private *, int);
 static int mdio_read(struct net_device *dev, int phy_id, int location);
 static void mdio_write(struct net_device *dev, int phy_id, int loc, int val);
 static void epic_restart(struct net_device *dev);
-static void epic_timer(unsigned long data);
+static void epic_timer(struct timer_list *t);
 static void epic_tx_timeout(struct net_device *dev);
 static void epic_init_ring(struct net_device *dev);
 static netdev_tx_t epic_start_xmit(struct sk_buff *skb,
@@ -739,7 +739,7 @@ static int epic_open(struct net_device *dev)
 
/* Set the timer to switch to check for link beat and perhaps switch
   to an alternate media type. */
-   setup_timer(&ep->timer, epic_timer, (unsigned long)dev);
+   timer_setup(&ep->timer, epic_timer, 0);
ep->timer.expires = jiffies + 3*HZ;
add_timer(&ep->timer);
 
@@ -843,10 +843,10 @@ static void check_media(struct net_device *dev)
}
 }
 
-static void epic_timer(unsigned long data)
+static void epic_timer(struct timer_list *t)
 {
-   struct net_device *dev = (struct net_device *)data;
-   struct epic_private *ep = netdev_priv(dev);
+   struct epic_private *ep = from_timer(ep, t, timer);
+   struct net_device *dev = ep->mii.dev;
void __iomem *ioaddr = ep->ioaddr;
int next_tick = 5*HZ;
 
diff --git a/drivers/net/ethernet/smsc/smc91c92_cs.c 
b/drivers/net/ethernet/smsc/smc91c92_cs.c
index 92c927aec66d..a55f430f6a7b 100644
--- a/drivers/net/ethernet/smsc/smc91c92_cs.c
+++ b/drivers/net/ethernet/smsc/smc91c92_cs.c
@@ -280,7 +280,7 @@ static void set_rx_mode(struct net_device *dev);
 static int s9k_config(struct net_device *dev, struct ifmap *map);
 static void smc_set_xcvr(struct net_device *dev, int if_port);
 static void smc_reset(struct net_device *dev);
-static void media_check(u_long arg);
+static void media_check(struct timer_list *t);
 static void mdio_sync(unsigned int addr);
 static int mdio_read(struct net_device *dev, int phy_id, int loc);
 static void mdio_write(struct net_device *dev, int phy_id, int loc, int value);
@@ -1070,7 +1070,7 @@ static int smc_open(struct net_device *dev)
 smc->packets_waiting = 0;
 
 smc_reset(dev);
-setup_timer(&smc->media, media_check, (u_long)dev);
+timer_setup(&smc->media, media_check, 0);
 mod_timer(&smc->media, jiffies + HZ);
 
 return 0;
@@ -1708,10 +1708,10 @@ static void smc_reset(struct net_device *dev)
 
 ==*/
 
-static void media_check(u_long arg)
+static void media_check(struct timer_list *t)
 {
-struct net_device *dev = (struct net_device *) arg;
-struct smc_private *smc = netdev_priv(dev);
+struct smc_private *smc = from_timer(smc, t, media);
+struct net_device *dev = smc->mii_if.dev;
 unsigned int ioaddr = dev->base_addr;
 u_short i, media, saved_bank;
 u_short link;
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] drivers/net: fealnx: Convert timers to use timer_setup()

2017-10-26 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: "David S. Miller" 
Cc: "yuval.sh...@oracle.com" 
Cc: Allen Pais 
Cc: Stephen Hemminger 
Cc: Philippe Reynes 
Cc: Johannes Berg 
Cc: net...@vger.kernel.org
Signed-off-by: Kees Cook 
---
 drivers/net/ethernet/fealnx.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
index c8982313d850..23053919ebf5 100644
--- a/drivers/net/ethernet/fealnx.c
+++ b/drivers/net/ethernet/fealnx.c
@@ -426,8 +426,8 @@ static void mdio_write(struct net_device *dev, int phy_id, 
int location, int val
 static int netdev_open(struct net_device *dev);
 static void getlinktype(struct net_device *dev);
 static void getlinkstatus(struct net_device *dev);
-static void netdev_timer(unsigned long data);
-static void reset_timer(unsigned long data);
+static void netdev_timer(struct timer_list *t);
+static void reset_timer(struct timer_list *t);
 static void fealnx_tx_timeout(struct net_device *dev);
 static void init_ring(struct net_device *dev);
 static netdev_tx_t start_tx(struct sk_buff *skb, struct net_device *dev);
@@ -909,13 +909,13 @@ static int netdev_open(struct net_device *dev)
printk(KERN_DEBUG "%s: Done netdev_open().\n", dev->name);
 
/* Set the timer to check for link beat. */
-   setup_timer(&np->timer, netdev_timer, (unsigned long)dev);
+   timer_setup(&np->timer, netdev_timer, 0);
np->timer.expires = RUN_AT(3 * HZ);
 
/* timer handler */
add_timer(&np->timer);
 
-   setup_timer(&np->reset_timer, reset_timer, (unsigned long)dev);
+   timer_setup(&np->reset_timer, reset_timer, 0);
np->reset_timer_armed = 0;
return rc;
 }
@@ -1078,10 +1078,10 @@ static void allocate_rx_buffers(struct net_device *dev)
 }
 
 
-static void netdev_timer(unsigned long data)
+static void netdev_timer(struct timer_list *t)
 {
-   struct net_device *dev = (struct net_device *) data;
-   struct netdev_private *np = netdev_priv(dev);
+   struct netdev_private *np = from_timer(np, t, timer);
+   struct net_device *dev = np->mii.dev;
void __iomem *ioaddr = np->mem;
int old_crvalue = np->crvalue;
unsigned int old_linkok = np->linkok;
@@ -1167,10 +1167,10 @@ static void enable_rxtx(struct net_device *dev)
 }
 
 
-static void reset_timer(unsigned long data)
+static void reset_timer(struct timer_list *t)
 {
-   struct net_device *dev = (struct net_device *) data;
-   struct netdev_private *np = netdev_priv(dev);
+   struct netdev_private *np = from_timer(np, t, reset_timer);
+   struct net_device *dev = np->mii.dev;
unsigned long flags;
 
printk(KERN_WARNING "%s: resetting tx and rx machinery\n", dev->name);
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] drivers/net: chelsio/cxgb*: Convert timers to use timer_setup()

2017-10-26 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Santosh Raspatur 
Cc: Ganesh Goudar 
Cc: Casey Leedom 
Cc: net...@vger.kernel.org
Signed-off-by: Kees Cook 
---
 drivers/net/ethernet/chelsio/cxgb3/sge.c | 12 ++--
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c |  7 +++
 drivers/net/ethernet/chelsio/cxgb4/sge.c | 12 ++--
 drivers/net/ethernet/chelsio/cxgb4vf/sge.c   | 12 ++--
 4 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb3/sge.c 
b/drivers/net/ethernet/chelsio/cxgb3/sge.c
index e2d342647b19..e3d28ae75360 100644
--- a/drivers/net/ethernet/chelsio/cxgb3/sge.c
+++ b/drivers/net/ethernet/chelsio/cxgb3/sge.c
@@ -2853,9 +2853,9 @@ void t3_sge_err_intr_handler(struct adapter *adapter)
  * bother cleaning them up here.
  *
  */
-static void sge_timer_tx(unsigned long data)
+static void sge_timer_tx(struct timer_list *t)
 {
-   struct sge_qset *qs = (struct sge_qset *)data;
+   struct sge_qset *qs = from_timer(qs, t, tx_reclaim_timer);
struct port_info *pi = netdev_priv(qs->netdev);
struct adapter *adap = pi->adapter;
unsigned int tbd[SGE_TXQ_PER_SET] = {0, 0};
@@ -2893,10 +2893,10 @@ static void sge_timer_tx(unsigned long data)
  * starved.
  *
  */
-static void sge_timer_rx(unsigned long data)
+static void sge_timer_rx(struct timer_list *t)
 {
spinlock_t *lock;
-   struct sge_qset *qs = (struct sge_qset *)data;
+   struct sge_qset *qs = from_timer(qs, t, rx_reclaim_timer);
struct port_info *pi = netdev_priv(qs->netdev);
struct adapter *adap = pi->adapter;
u32 status;
@@ -2976,8 +2976,8 @@ int t3_sge_alloc_qset(struct adapter *adapter, unsigned 
int id, int nports,
struct sge_qset *q = &adapter->sge.qs[id];
 
init_qset_cntxt(q, id);
-   setup_timer(&q->tx_reclaim_timer, sge_timer_tx, (unsigned long)q);
-   setup_timer(&q->rx_reclaim_timer, sge_timer_rx, (unsigned long)q);
+   timer_setup(&q->tx_reclaim_timer, sge_timer_tx, 0);
+   timer_setup(&q->rx_reclaim_timer, sge_timer_rx, 0);
 
q->fl[0].desc = alloc_ring(adapter->pdev, p->fl_size,
   sizeof(struct rx_desc),
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c 
b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c
index 92a311767381..0c154c663748 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c
@@ -366,9 +366,9 @@ int cxgb4_tc_flower_destroy(struct net_device *dev,
return ret;
 }
 
-static void ch_flower_stats_cb(unsigned long data)
+static void ch_flower_stats_cb(struct timer_list *t)
 {
-   struct adapter *adap = (struct adapter *)data;
+   struct adapter *adap = from_timer(adap, t, flower_stats_timer);
struct ch_tc_flower_entry *flower_entry;
struct ch_tc_flower_stats *ofld_stats;
unsigned int i;
@@ -440,8 +440,7 @@ int cxgb4_tc_flower_stats(struct net_device *dev,
 void cxgb4_init_tc_flower(struct adapter *adap)
 {
hash_init(adap->flower_anymatch_tbl);
-   setup_timer(&adap->flower_stats_timer, ch_flower_stats_cb,
-   (unsigned long)adap);
+   timer_setup(&adap->flower_stats_timer, ch_flower_stats_cb, 0);
mod_timer(&adap->flower_stats_timer, jiffies + STATS_CHECK_PERIOD);
 }
 
diff --git a/drivers/net/ethernet/chelsio/cxgb4/sge.c 
b/drivers/net/ethernet/chelsio/cxgb4/sge.c
index 4ef68f69b58c..486b01fe23bd 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/sge.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/sge.c
@@ -2583,11 +2583,11 @@ irq_handler_t t4_intr_handler(struct adapter *adap)
return t4_intr_intx;
 }
 
-static void sge_rx_timer_cb(unsigned long data)
+static void sge_rx_timer_cb(struct timer_list *t)
 {
unsigned long m;
unsigned int i;
-   struct adapter *adap = (struct adapter *)data;
+   struct adapter *adap = from_timer(adap, t, sge.rx_timer);
struct sge *s = &adap->sge;
 
for (i = 0; i < BITS_TO_LONGS(s->egr_sz); i++)
@@ -2620,11 +2620,11 @@ static void sge_rx_timer_cb(unsigned long data)
mod_timer(&s->rx_timer, jiffies + RX_QCHECK_PERIOD);
 }
 
-static void sge_tx_timer_cb(unsigned long data)
+static void sge_tx_timer_cb(struct timer_list *t)
 {
unsigned long m;
unsigned int i, budget;
-   struct adapter *adap = (struct adapter *)data;
+   struct adapter *adap = from_timer(adap, t, sge.tx_timer);
struct sge *s = &adap->sge;
 
for (i = 0; i < BITS_TO_LONGS(s->egr_sz); i++)
@@ -3458,8 +3458,8 @@ int t4_sge_init(struct adapter *adap)
/* Set up timers used for recuring callbacks to process RX and TX
 * administrative tasks.
 */
-   setup_timer(&s->rx_timer

[PATCH] drivers/net: amd: Convert timers to use timer_setup()

2017-10-26 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Tom Lendacky 
Cc: "David S. Miller" 
Cc: Allen Pais 
Cc: net...@vger.kernel.org
Signed-off-by: Kees Cook 
---
 drivers/net/ethernet/amd/a2065.c | 13 ++---
 drivers/net/ethernet/amd/am79c961a.c |  9 +
 drivers/net/ethernet/amd/am79c961a.h |  1 +
 drivers/net/ethernet/amd/declance.c  | 10 ++
 drivers/net/ethernet/amd/pcnet32.c   | 10 +-
 drivers/net/ethernet/amd/sunlance.c  |  8 
 drivers/net/ethernet/amd/xgbe/xgbe-drv.c | 14 ++
 7 files changed, 37 insertions(+), 28 deletions(-)

diff --git a/drivers/net/ethernet/amd/a2065.c b/drivers/net/ethernet/amd/a2065.c
index 998d30e050a6..212fe72a190b 100644
--- a/drivers/net/ethernet/amd/a2065.c
+++ b/drivers/net/ethernet/amd/a2065.c
@@ -123,6 +123,7 @@ struct lance_private {
int burst_sizes;  /* ledma SBus burst sizes */
 #endif
struct timer_list multicast_timer;
+   struct net_device *dev;
 };
 
 #define LANCE_ADDR(x) ((int)(x) & ~0xff00)
@@ -638,6 +639,13 @@ static void lance_set_multicast(struct net_device *dev)
netif_wake_queue(dev);
 }
 
+static void lance_set_multicast_retry(struct timer_list *t)
+{
+   struct lance_private *lp = from_timer(lp, t, multicast_timer);
+
+   lance_set_multicast(lp->dev);
+}
+
 static int a2065_init_one(struct zorro_dev *z,
  const struct zorro_device_id *ent);
 static void a2065_remove_one(struct zorro_dev *z);
@@ -728,14 +736,13 @@ static int a2065_init_one(struct zorro_dev *z,
priv->lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
priv->rx_ring_mod_mask = RX_RING_MOD_MASK;
priv->tx_ring_mod_mask = TX_RING_MOD_MASK;
+   priv->dev = dev;
 
dev->netdev_ops = &lance_netdev_ops;
dev->watchdog_timeo = 5*HZ;
dev->dma = 0;
 
-   setup_timer(&priv->multicast_timer,
-   (void(*)(unsigned long))lance_set_multicast,
-   (unsigned long)dev);
+   timer_setup(&priv->multicast_timer, lance_set_multicast_retry, 0);
 
err = register_netdev(dev);
if (err) {
diff --git a/drivers/net/ethernet/amd/am79c961a.c 
b/drivers/net/ethernet/amd/am79c961a.c
index 0612dbee00d2..01d132c02ff9 100644
--- a/drivers/net/ethernet/amd/am79c961a.c
+++ b/drivers/net/ethernet/amd/am79c961a.c
@@ -302,10 +302,10 @@ am79c961_init_for_open(struct net_device *dev)
write_rreg (dev->base_addr, CSR0, CSR0_IENA|CSR0_STRT);
 }
 
-static void am79c961_timer(unsigned long data)
+static void am79c961_timer(struct timer_list *t)
 {
-   struct net_device *dev = (struct net_device *)data;
-   struct dev_priv *priv = netdev_priv(dev);
+   struct dev_priv *priv = from_timer(priv, t, timer);
+   struct net_device *dev = priv->dev;
unsigned int lnkstat, carrier;
unsigned long flags;
 
@@ -728,7 +728,8 @@ static int am79c961_probe(struct platform_device *pdev)
am79c961_banner();
 
spin_lock_init(&priv->chip_lock);
-   setup_timer(&priv->timer, am79c961_timer, (unsigned long)dev);
+   priv->dev = dev;
+   timer_setup(&priv->timer, am79c961_timer, 0);
 
if (am79c961_hw_init(dev))
goto release;
diff --git a/drivers/net/ethernet/amd/am79c961a.h 
b/drivers/net/ethernet/amd/am79c961a.h
index 9f384b79507b..fc5088c70731 100644
--- a/drivers/net/ethernet/amd/am79c961a.h
+++ b/drivers/net/ethernet/amd/am79c961a.h
@@ -140,6 +140,7 @@ struct dev_priv {
 unsigned long  txhdr;
 spinlock_t chip_lock;
 struct timer_list  timer;
+struct net_device   *dev;
 };
 
 #endif
diff --git a/drivers/net/ethernet/amd/declance.c 
b/drivers/net/ethernet/amd/declance.c
index 9bdf81c2cd00..116997a8b593 100644
--- a/drivers/net/ethernet/amd/declance.c
+++ b/drivers/net/ethernet/amd/declance.c
@@ -260,6 +260,7 @@ struct lance_private {
unsigned short busmaster_regval;
 
struct timer_list   multicast_timer;
+   struct net_device   *dev;
 
/* Pointers to the ring buffers as seen from the CPU */
char *rx_buf_ptr_cpu[RX_RING_SIZE];
@@ -1000,9 +1001,10 @@ static void lance_set_multicast(struct net_device *dev)
netif_wake_queue(dev);
 }
 
-static void lance_set_multicast_retry(unsigned long _opaque)
+static void lance_set_multicast_retry(struct timer_list *t)
 {
-   struct net_device *dev = (struct net_device *) _opaque;
+   struct lance_private *lp = from_timer(lp, t, multicast_timer);
+   struct net_device *dev = lp->dev;
 
lance_set_multicast(dev);
 }
@@ -1246,8 +1248,8 @@ static int dec_lance_probe(struct device *bdev, const int 
type)
 * can occur from interrupts (ex. IPv6).  So we
 * use a timer to try again later when necessary. -DaveM
 */
-   set

[PATCH] drivers/net: appletalk/cops: Convert timers to use timer_setup()

2017-10-26 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Allen Pais 
Cc: "David S. Miller" 
Cc: David Howells 
Cc: net...@vger.kernel.org
Signed-off-by: Kees Cook 
---
 drivers/net/appletalk/cops.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/net/appletalk/cops.c b/drivers/net/appletalk/cops.c
index caf04284711a..bb49f6e40a19 100644
--- a/drivers/net/appletalk/cops.c
+++ b/drivers/net/appletalk/cops.c
@@ -155,6 +155,7 @@ static int cops_irqlist[] = {
 };
 
 static struct timer_list cops_timer;
+static struct net_device *cops_timer_dev;
 
 /* use 0 for production, 1 for verification, 2 for debug, 3 for verbose debug 
*/
 #ifndef COPS_DEBUG
@@ -187,7 +188,7 @@ static void cops_load (struct net_device *dev);
 static int  cops_nodeid (struct net_device *dev, int nodeid);
 
 static irqreturn_t cops_interrupt (int irq, void *dev_id);
-static void cops_poll (unsigned long ltdev);
+static void cops_poll(struct timer_list *t);
 static void cops_timeout(struct net_device *dev);
 static void cops_rx (struct net_device *dev);
 static netdev_tx_t  cops_send_packet (struct sk_buff *skb,
@@ -424,7 +425,8 @@ static int cops_open(struct net_device *dev)
 */
if(lp->board==TANGENT)  /* Poll 20 times per second */
{
-   setup_timer(&cops_timer, cops_poll, (unsigned long)dev);
+   cops_timer_dev = dev;
+   timer_setup(&cops_timer, cops_poll, 0);
cops_timer.expires  = jiffies + HZ/20;
add_timer(&cops_timer);
} 
@@ -671,12 +673,11 @@ static int cops_nodeid (struct net_device *dev, int 
nodeid)
  * Poll the Tangent type cards to see if we have work.
  */
  
-static void cops_poll(unsigned long ltdev)
+static void cops_poll(struct timer_list *unused)
 {
int ioaddr, status;
int boguscount = 0;
-
-   struct net_device *dev = (struct net_device *)ltdev;
+   struct net_device *dev = cops_timer_dev;
 
del_timer(&cops_timer);
 
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] drivers/net: 8390: Convert timers to use timer_setup()

2017-10-26 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: net...@vger.kernel.org
Signed-off-by: Kees Cook 
---
 drivers/net/ethernet/8390/axnet_cs.c | 10 +-
 drivers/net/ethernet/8390/pcnet_cs.c | 10 +-
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/8390/axnet_cs.c 
b/drivers/net/ethernet/8390/axnet_cs.c
index 3da1fc539ef9..7bddb8efb6d5 100644
--- a/drivers/net/ethernet/8390/axnet_cs.c
+++ b/drivers/net/ethernet/8390/axnet_cs.c
@@ -85,7 +85,7 @@ static struct net_device_stats *get_stats(struct net_device 
*dev);
 static void set_multicast_list(struct net_device *dev);
 static void axnet_tx_timeout(struct net_device *dev);
 static irqreturn_t ei_irq_wrapper(int irq, void *dev_id);
-static void ei_watchdog(u_long arg);
+static void ei_watchdog(struct timer_list *t);
 static void axnet_reset_8390(struct net_device *dev);
 
 static int mdio_read(unsigned int addr, int phy_id, int loc);
@@ -483,7 +483,7 @@ static int axnet_open(struct net_device *dev)
 link->open++;
 
 info->link_status = 0x00;
-setup_timer(&info->watchdog, ei_watchdog, (u_long)dev);
+timer_setup(&info->watchdog, ei_watchdog, 0);
 mod_timer(&info->watchdog, jiffies + HZ);
 
 return ax_open(dev);
@@ -547,10 +547,10 @@ static irqreturn_t ei_irq_wrapper(int irq, void *dev_id)
 return ax_interrupt(irq, dev_id);
 }
 
-static void ei_watchdog(u_long arg)
+static void ei_watchdog(struct timer_list *t)
 {
-struct net_device *dev = (struct net_device *)(arg);
-struct axnet_dev *info = PRIV(dev);
+struct axnet_dev *info = from_timer(info, t, watchdog);
+struct net_device *dev = info->p_dev->priv;
 unsigned int nic_base = dev->base_addr;
 unsigned int mii_addr = nic_base + AXNET_MII_EEP;
 u_short link;
diff --git a/drivers/net/ethernet/8390/pcnet_cs.c 
b/drivers/net/ethernet/8390/pcnet_cs.c
index bd0a2a14b649..eae9827035dc 100644
--- a/drivers/net/ethernet/8390/pcnet_cs.c
+++ b/drivers/net/ethernet/8390/pcnet_cs.c
@@ -99,7 +99,7 @@ static int pcnet_open(struct net_device *dev);
 static int pcnet_close(struct net_device *dev);
 static int ei_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
 static irqreturn_t ei_irq_wrapper(int irq, void *dev_id);
-static void ei_watchdog(u_long arg);
+static void ei_watchdog(struct timer_list *t);
 static void pcnet_reset_8390(struct net_device *dev);
 static int set_config(struct net_device *dev, struct ifmap *map);
 static int setup_shmem_window(struct pcmcia_device *link, int start_pg,
@@ -917,7 +917,7 @@ static int pcnet_open(struct net_device *dev)
 
 info->phy_id = info->eth_phy;
 info->link_status = 0x00;
-setup_timer(&info->watchdog, ei_watchdog, (u_long)dev);
+timer_setup(&info->watchdog, ei_watchdog, 0);
 mod_timer(&info->watchdog, jiffies + HZ);
 
 return ei_open(dev);
@@ -1006,10 +1006,10 @@ static irqreturn_t ei_irq_wrapper(int irq, void *dev_id)
 return ret;
 }
 
-static void ei_watchdog(u_long arg)
+static void ei_watchdog(struct timer_list *t)
 {
-struct net_device *dev = (struct net_device *)arg;
-struct pcnet_dev *info = PRIV(dev);
+struct pcnet_dev *info = from_timer(info, t, watchdog);
+struct net_device *dev = info->p_dev->priv;
 unsigned int nic_base = dev->base_addr;
 unsigned int mii_addr = nic_base + DLINK_GPIO;
 u_short link;
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH -mm -V2] mm, swap: Fix false error message in __swp_swapcount()

2017-10-26 Thread Huang, Ying
From: Huang Ying 

When a page fault occurs for a swap entry, the physical swap readahead
(not the VMA base swap readahead) may readahead several swap entries
after the fault swap entry.  The readahead algorithm calculates some
of the swap entries to readahead via increasing the offset of the
fault swap entry without checking whether they are beyond the end of
the swap device and it relys on the __swp_swapcount() and
swapcache_prepare() to check it.  Although __swp_swapcount() checks
for the swap entry passed in, it will complain with the error message
as follow for the expected invalid swap entry.  This may make the end
users confused.

  swap_info_get: Bad swap offset entry 0200f8a7

To fix the false error message, the swap entry checking is added in
swap readahead to avoid to pass the out-bound swap entries and the
swap entry reserved for the swap header to __swp_swapcount() and
swapcache_prepare().

Cc: Tim Chen 
Cc: Minchan Kim 
Cc: Michal Hocko 
Cc:  # 4.11-4.13
Reported-by: Christian Kujau 
Fixes: e8c26ab60598 ("mm/swap: skip readahead for unreferenced swap slots")
Signed-off-by: "Huang, Ying" 
---
 include/linux/swap.h |  1 +
 mm/swap_state.c  |  6 --
 mm/swapfile.c| 21 +
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/include/linux/swap.h b/include/linux/swap.h
index 84255b3da7c1..43b4b821c805 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -476,6 +476,7 @@ extern int page_swapcount(struct page *);
 extern int __swap_count(struct swap_info_struct *si, swp_entry_t entry);
 extern int __swp_swapcount(swp_entry_t entry);
 extern int swp_swapcount(swp_entry_t entry);
+extern bool swap_entry_check(swp_entry_t entry);
 extern struct swap_info_struct *page_swap_info(struct page *);
 extern struct swap_info_struct *swp_swap_info(swp_entry_t entry);
 extern bool reuse_swap_page(struct page *, int *);
diff --git a/mm/swap_state.c b/mm/swap_state.c
index 6c017ced11e6..7dd70e77058d 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -569,11 +569,13 @@ struct page *swapin_readahead(swp_entry_t entry, gfp_t 
gfp_mask,
/* Read a page_cluster sized and aligned cluster around offset. */
start_offset = offset & ~mask;
end_offset = offset | mask;
-   if (!start_offset)  /* First page is swap header. */
-   start_offset++;
 
blk_start_plug(&plug);
for (offset = start_offset; offset <= end_offset ; offset++) {
+   swp_entry_t ent = swp_entry(swp_type(entry), offset);
+
+   if (!swap_entry_check(ent))
+   continue;
/* Ok, do the async read-ahead now */
page = __read_swap_cache_async(
swp_entry(swp_type(entry), offset),
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 3074b02eaa09..b04cec29c234 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1107,6 +1107,27 @@ static struct swap_info_struct 
*swap_info_get_cont(swp_entry_t entry,
return p;
 }
 
+bool swap_entry_check(swp_entry_t entry)
+{
+   struct swap_info_struct *p;
+   unsigned long offset, type;
+
+   type = swp_type(entry);
+   if (type >= nr_swapfiles)
+   goto bad_file;
+   p = swap_info[type];
+   offset = swp_offset(entry);
+   if (unlikely(!offset || offset >= p->max))
+   goto out;
+
+   return true;
+
+bad_file:
+   pr_err("%s: %s%08lx\n", __func__, Bad_file, entry.val);
+out:
+   return false;
+}
+
 static unsigned char __swap_entry_free(struct swap_info_struct *p,
   swp_entry_t entry, unsigned char usage)
 {
-- 
2.14.2



[PATCH v3 2/2] net: netrom: nr_route: mark expected switch fall-throughs

2017-10-26 Thread Gustavo A. R. Silva
In preparation to enabling -Wimplicit-fallthrough, mark switch cases
where we are expecting to fall through.

Signed-off-by: Gustavo A. R. Silva 
---
Changes in v2:
 None.

Changes in v3:
 Update subject.

 net/netrom/nr_route.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/netrom/nr_route.c b/net/netrom/nr_route.c
index fba4b4c..75e6ba9 100644
--- a/net/netrom/nr_route.c
+++ b/net/netrom/nr_route.c
@@ -265,6 +265,7 @@ static int __must_check nr_add_node(ax25_address *nr, const 
char *mnemonic,
case 3:
re_sort_routes(nr_node, 0, 1);
re_sort_routes(nr_node, 1, 2);
+   /* fall through */
case 2:
re_sort_routes(nr_node, 0, 1);
case 1:
@@ -357,6 +358,7 @@ static int nr_del_node(ax25_address *callsign, ax25_address 
*neighbour, struct n
switch (i) {
case 0:
nr_node->routes[0] = nr_node->routes[1];
+   /* fall through */
case 1:
nr_node->routes[1] = nr_node->routes[2];
case 2:
@@ -526,6 +528,7 @@ void nr_rt_device_down(struct net_device *dev)
switch (i) {
case 0:
t->routes[0] = 
t->routes[1];
+   /* fall through */
case 1:
t->routes[1] = 
t->routes[2];
case 2:
-- 
2.7.4



[PATCH v3 1/2] net: netrom: nr_route: refactor code in nr_add_node

2017-10-26 Thread Gustavo A. R. Silva
Code refactoring in order to make the code easier to read and maintain.

Signed-off-by: Gustavo A. R. Silva 
---
Changes in v2:
 Make use of the swap macro and remove inline keyword.

Changes in v3:
 Update subject.

 net/netrom/nr_route.c | 59 ++-
 1 file changed, 16 insertions(+), 43 deletions(-)

diff --git a/net/netrom/nr_route.c b/net/netrom/nr_route.c
index 0c59354..fba4b4c 100644
--- a/net/netrom/nr_route.c
+++ b/net/netrom/nr_route.c
@@ -80,6 +80,19 @@ static struct nr_neigh *nr_neigh_get_dev(ax25_address 
*callsign,
 
 static void nr_remove_neigh(struct nr_neigh *);
 
+/*  re-sort the routes in quality order.*/
+static void re_sort_routes(struct nr_node *nr_node, int x, int y)
+{
+   if (nr_node->routes[y].quality > nr_node->routes[x].quality) {
+   if (nr_node->which == x)
+   nr_node->which = y;
+   else if (nr_node->which == y)
+   nr_node->which = x;
+
+   swap(nr_node->routes[x], nr_node->routes[y]);
+   }
+}
+
 /*
  * Add a new route to a node, and in the process add the node and the
  * neighbour if it is new.
@@ -90,7 +103,6 @@ static int __must_check nr_add_node(ax25_address *nr, const 
char *mnemonic,
 {
struct nr_node  *nr_node;
struct nr_neigh *nr_neigh;
-   struct nr_route nr_route;
int i, found;
struct net_device *odev;
 
@@ -251,49 +263,10 @@ static int __must_check nr_add_node(ax25_address *nr, 
const char *mnemonic,
/* Now re-sort the routes in quality order */
switch (nr_node->count) {
case 3:
-   if (nr_node->routes[1].quality > nr_node->routes[0].quality) {
-   switch (nr_node->which) {
-   case 0:
-   nr_node->which = 1;
-   break;
-   case 1:
-   nr_node->which = 0;
-   break;
-   }
-   nr_route   = nr_node->routes[0];
-   nr_node->routes[0] = nr_node->routes[1];
-   nr_node->routes[1] = nr_route;
-   }
-   if (nr_node->routes[2].quality > nr_node->routes[1].quality) {
-   switch (nr_node->which) {
-   case 1:  nr_node->which = 2;
-   break;
-
-   case 2:  nr_node->which = 1;
-   break;
-
-   default:
-   break;
-   }
-   nr_route   = nr_node->routes[1];
-   nr_node->routes[1] = nr_node->routes[2];
-   nr_node->routes[2] = nr_route;
-   }
+   re_sort_routes(nr_node, 0, 1);
+   re_sort_routes(nr_node, 1, 2);
case 2:
-   if (nr_node->routes[1].quality > nr_node->routes[0].quality) {
-   switch (nr_node->which) {
-   case 0:  nr_node->which = 1;
-   break;
-
-   case 1:  nr_node->which = 0;
-   break;
-
-   default: break;
-   }
-   nr_route   = nr_node->routes[0];
-   nr_node->routes[0] = nr_node->routes[1];
-   nr_node->routes[1] = nr_route;
-   }
+   re_sort_routes(nr_node, 0, 1);
case 1:
break;
}
-- 
2.7.4



[PATCH v3 0/2] refactor code and mark expected switch fall-throughs

2017-10-26 Thread Gustavo A. R. Silva
The aim of this patchset is firstly to refactor code in nr_route.c in order to 
make it
easier to read and maintain and, secondly, to mark some expected switch 
fall-throughs
in preparation to enabling -Wimplicit-fallthrough.

I have to mention that I did not implement any unit test.
If someone has any suggestions on how I could test this piece of code
it'd be greatly appreciated.

Thanks

Changes in v2:
 - Make use of the swap macro and remove inline keyword as suggested by
   Walter Harms and Kevin Dawson.

Changes in v3:
 - Update subject for both patches.
 - Add this cover letter as suggested by David Miller.

Gustavo A. R. Silva (2):
  net: netrom: nr_route: refactor code in nr_add_node
  net: netrom: nr_route: mark expected switch fall-throughs

 net/netrom/nr_route.c | 62 ---
 1 file changed, 19 insertions(+), 43 deletions(-)

-- 
2.7.4



Re: [PATCH] x86: Remove unnecessary return from void function

2017-10-26 Thread Juergen Gross
On 23/06/17 18:23, Anton Vasilyev wrote:
> The patch removes unnecessary return from void function.
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Anton Vasilyev 

Reviewed-by: Juergen Gross 


Juergen


Re: [RFC PATCH v8 1/7] dt-bindings: PCI: Add definition of PCIe WAKE# irq and PCI irq

2017-10-26 Thread Brian Norris
Hi Jeffy,

On Fri, Oct 27, 2017 at 11:06:34AM +0800, Jeffy Chen wrote:
> On 10/27/2017 10:33 AM, Brian Norris wrote:
> >In fact, I'm pretty sure this series fails to actually look in the host
> >bridge for the "wakeup" interrupt at all! Did you actually test this?
> actually it could...
> 
> static void *of_pci_setup(struct device *dev)
> {
> ...
> device_init_wakeup(dev, false);
> 
> dev_info(dev, "Wakeup IRQ %d\n", irq);
> return data;
> }
> 
> [1.546561] OF: PCI:   MEM 0xfa00..0xfbdf -> 0xfa00
> [1.553154] OF: PCI:IO 0xfbe0..0xfbef -> 0xfbe0
> [1.560859] rockchip-pcie f800.pcie: Wakeup IRQ 64
> [1.566555] rockchip-pcie f800.pcie: PCI host bridge to bus

Hmm, I think I missed the .setup_host_bridge() stuff. So you do handle
both. I'll have to take a little closer look tomorrow. But you
definitely at least need to improve the documentation as mentioned.

Another odd thing about this series is that the interrupt doesn't
actually show up in /proc/interrupts, /sys/kernel/debug/gpio, or
similar, seemingly because the wakeirq is requested/released every time
we suspend/resume. So it's really not that obvious that the interrupt is
being configured properly. That's not really a functional problem,
necessarily, but it doesn't quite seem ideal.

Brian


Re: [PATCHv4 1/1] [tools/selftests]: android/ion: userspace test utility for ion buffer sharing

2017-10-26 Thread Pintu Kumar
Dear Laura, Shuah,

Request you to please review the PATCHv4.
If you have more comments please let me know.

Thanks,
Pintu

On Tue, Oct 24, 2017 at 4:56 AM, Pintu Agarwal  wrote:
> This is a test utility to verify ION buffer sharing in user space
> between 2 independent processes.
> It uses unix domain socket (with SCM_RIGHTS) as IPC to transfer an FD to
> another process to share the same buffer.
> This utility demonstrates how ION buffer sharing can be implemented between
> two user space processes, using various heap types.
>
> This utility is made to be run as part of kselftest framework in kernel.
> The utility is verified on Ubuntu-32 bit system with Linux Kernel 4.14,
> using ION system heap and CMA heap.
>
> For more information about the utility please check the README file.
>
> Signed-off-by: Pintu Agarwal 
> ---
>  tools/testing/selftests/Makefile   |   3 +-
>  tools/testing/selftests/android/Makefile   |  46 
>  tools/testing/selftests/android/ion/.gitignore |   2 +
>  tools/testing/selftests/android/ion/Makefile   |  16 ++
>  tools/testing/selftests/android/ion/README | 101 
>  tools/testing/selftests/android/ion/config |   4 +
>  tools/testing/selftests/android/ion/ion_test.sh|  61 +
>  .../testing/selftests/android/ion/ionapp_export.c  | 144 
>  .../testing/selftests/android/ion/ionapp_import.c  |  88 +++
>  tools/testing/selftests/android/ion/ionutils.c | 259 
> +
>  tools/testing/selftests/android/ion/ionutils.h |  55 +
>  tools/testing/selftests/android/ion/ipcsocket.c| 227 ++
>  tools/testing/selftests/android/ion/ipcsocket.h|  35 +++
>  tools/testing/selftests/android/run.sh |   3 +
>  14 files changed, 1043 insertions(+), 1 deletion(-)
>  create mode 100644 tools/testing/selftests/android/Makefile
>  create mode 100644 tools/testing/selftests/android/ion/.gitignore
>  create mode 100644 tools/testing/selftests/android/ion/Makefile
>  create mode 100644 tools/testing/selftests/android/ion/README
>  create mode 100644 tools/testing/selftests/android/ion/config
>  create mode 100755 tools/testing/selftests/android/ion/ion_test.sh
>  create mode 100644 tools/testing/selftests/android/ion/ionapp_export.c
>  create mode 100644 tools/testing/selftests/android/ion/ionapp_import.c
>  create mode 100644 tools/testing/selftests/android/ion/ionutils.c
>  create mode 100644 tools/testing/selftests/android/ion/ionutils.h
>  create mode 100644 tools/testing/selftests/android/ion/ipcsocket.c
>  create mode 100644 tools/testing/selftests/android/ion/ipcsocket.h
>  create mode 100755 tools/testing/selftests/android/run.sh
>
> diff --git a/tools/testing/selftests/Makefile 
> b/tools/testing/selftests/Makefile
> index ff80564..61bc77b 100644
> --- a/tools/testing/selftests/Makefile
> +++ b/tools/testing/selftests/Makefile
> @@ -1,4 +1,5 @@
> -TARGETS =  bpf
> +TARGETS = android
> +TARGETS += bpf
>  TARGETS += breakpoints
>  TARGETS += capabilities
>  TARGETS += cpufreq
> diff --git a/tools/testing/selftests/android/Makefile 
> b/tools/testing/selftests/android/Makefile
> new file mode 100644
> index 000..1a74922
> --- /dev/null
> +++ b/tools/testing/selftests/android/Makefile
> @@ -0,0 +1,46 @@
> +SUBDIRS := ion
> +
> +TEST_PROGS := run.sh
> +
> +.PHONY: all clean
> +
> +include ../lib.mk
> +
> +all:
> +   @for DIR in $(SUBDIRS); do  \
> +   BUILD_TARGET=$(OUTPUT)/$$DIR;   \
> +   mkdir $$BUILD_TARGET  -p;   \
> +   make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
> +   #SUBDIR test prog name should be in the form: SUBDIR_test.sh
> +   TEST=$$DIR"_test.sh"; \
> +   if [ -e $$DIR/$$TEST ]; then
> +   rsync -a $$DIR/$$TEST $$BUILD_TARGET/;
> +   fi
> +   done
> +
> +override define RUN_TESTS
> +   @cd $(OUTPUT); ./run.sh
> +endef
> +
> +override define INSTALL_RULE
> +   mkdir -p $(INSTALL_PATH)
> +   install -t $(INSTALL_PATH) $(TEST_PROGS) $(TEST_PROGS_EXTENDED) 
> $(TEST_FILES)
> +
> +   @for SUBDIR in $(SUBDIRS); do \
> +   BUILD_TARGET=$(OUTPUT)/$$SUBDIR;\
> +   mkdir $$BUILD_TARGET  -p;   \
> +   $(MAKE) OUTPUT=$$BUILD_TARGET -C $$SUBDIR 
> INSTALL_PATH=$(INSTALL_PATH)/$$SUBDIR install; \
> +   done;
> +endef
> +
> +override define EMIT_TESTS
> +   echo "./run.sh"
> +endef
> +
> +override define CLEAN
> +   @for DIR in $(SUBDIRS); do  \
> +   BUILD_TARGET=$(OUTPUT)/$$DIR;   \
> +   mkdir $$BUILD_TARGET  -p;   \
> +   make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
> +   done
> +endef
> diff --git a/tools/testing/selftests/android/ion/.gitignore 
> b/tools/testing/selftests/android/ion/.gitignore
> new file mode 100644
> index 000..67e6f39
> --- /dev/null
> +++ b/tools/testing/selftests/android/ion/.gitig

Re: [PATCH v2 0/2] KVM: fixes for the kernel-hardening tree

2017-10-26 Thread Paul Mackerras
On Thu, Oct 26, 2017 at 03:45:45PM +0200, Paolo Bonzini wrote:
> Four KVM ioctls (KVM_GET/SET_CPUID2 on x86, KVM_GET/SET_ONE_REG on
> ARM and s390) directly access the kvm_vcpu_arch struct.  Therefore, the
> new usercopy hardening work in linux-next, which forbids copies from and
> to slab objects unless they are from kmalloc or explicitly whitelisted,
> breaks KVM on those architectures.
> 
> The kvm_vcpu_arch struct is embedded in the kvm_vcpu struct and the
> corresponding slab cache is allocated by architecture-independent code.
> It is enough, for simplicity, to whitelist the whole sub-struct and
> only touch one place of the KVM code.  Later, any further restrictions
> can be applied in the KVM tree.

I checked arch/powerpc/kvm, and all the copy_to/from_user calls are
accessing the stack or memory allocated with kzalloc or kvzalloc, so
if I understand correctly, we should be OK there.

Paul.


Re: [PATCH] workqueue: Fix NULL pointer dereference

2017-10-26 Thread Li Bin

Hi, Jiangshan

on 2017/10/26 23:55, Lai Jiangshan wrote:
> On Tue, Oct 24, 2017 at 9:18 AM, Li Bin  wrote:

> 
> I remember that softirq can be invoked when irq_eixt(),
> and in this case the current->current_pwq is also NULL
> if __queue_work() is called in the soft irq.
> 
> So in_task() might be better than !in_irq() for the fix?
> 

Good catch, I will fix it and resend the patch.

Thanks,
Li Bin

>> |-schedule()
>> 
>>
>> Avoid it by checking for irq context in current_wq_worker(), and
>> if in irq context, we shouldn't use the 'current' to check the
>> condition.
>>
>> Reported-by: Xiaofei Tan 
>> Signed-off-by: Li Bin 
>> ---
>>  kernel/workqueue_internal.h | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/kernel/workqueue_internal.h b/kernel/workqueue_internal.h
>> index 8635417..d81cb9b 100644
>> --- a/kernel/workqueue_internal.h
>> +++ b/kernel/workqueue_internal.h
>> @@ -9,6 +9,7 @@
>>
>>  #include 
>>  #include 
>> +#include 
>>
>>  struct worker_pool;
>>
>> @@ -59,7 +60,7 @@ struct worker {
>>   */
>>  static inline struct worker *current_wq_worker(void)
>>  {
>> -   if (current->flags & PF_WQ_WORKER)
>> +   if (!in_irq() && (current->flags & PF_WQ_WORKER))
>> return kthread_data(current);
>> return NULL;
>>  }
>> --
>> 1.7.12.4
>>
> 
> .
> 



Re: [PATCH v3 2/2] watchdog: Add Spreadtrum watchdog driver

2017-10-26 Thread Guenter Roeck

On 10/26/2017 07:28 PM, Eric Long wrote:

This patch adds the watchdog driver for Spreadtrum SC9860 platform.

Signed-off-by: Eric Long 
---
Change since v2:
  - Rename all the macors, add SPRD tag at the head of the macro names.
  - Rename SPRD_WDT_CLK as SPRD_WTC_CNT_STEP.
  - Remove the code which check timeout value at the wrong place.
  - Add min/max timeout value limit.
  - Remove set WDOG_HW_RUNNING status at sprd_wdt_enable().
  - Add timeout/pretimeout judgment when set them.
  - Support WATCHDOG_NOWAYOUT status.

Changes since v1:
  - Use pretimeout instead of own implementation.
  - Fix timeout loop when loading timeout values.
  - use the infrastructure to read and set "timeout-sec" property.
  - Add conditions when start or stop watchdog.
  - Change the position of enabling watchdog.
  - Other optimization.
---
  drivers/watchdog/Kconfig|   8 +
  drivers/watchdog/Makefile   |   1 +
  drivers/watchdog/sprd_wdt.c | 415 
  3 files changed, 424 insertions(+)
  create mode 100644 drivers/watchdog/sprd_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index c722cbf..4a77e17 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -787,6 +787,14 @@ config UNIPHIER_WATCHDOG
  To compile this driver as a module, choose M here: the
  module will be called uniphier_wdt.
  
+config SPRD_WATCHDOG

+   tristate "Spreadtrum watchdog support"
+   depends on ARCH_SPRD || COMPILE_TEST
+   select WATCHDOG_CORE
+   help
+ Say Y here to include support watchdog timer embedded
+ into the Spreadtrum system.


Maybe better "supported by" instead of "embedded into". Or at least
"embedded in".


+
  # AVR32 Architecture
  
  config AT32AP700X_WDT

diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 56adf9f..187cca2 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -87,6 +87,7 @@ obj-$(CONFIG_ASPEED_WATCHDOG) += aspeed_wdt.o
  obj-$(CONFIG_ZX2967_WATCHDOG) += zx2967_wdt.o
  obj-$(CONFIG_STM32_WATCHDOG) += stm32_iwdg.o
  obj-$(CONFIG_UNIPHIER_WATCHDOG) += uniphier_wdt.o
+obj-$(CONFIG_SPRD_WATCHDOG) += sprd_wdt.o
  
  # AVR32 Architecture

  obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o
diff --git a/drivers/watchdog/sprd_wdt.c b/drivers/watchdog/sprd_wdt.c
new file mode 100644
index 000..5fc3dde
--- /dev/null
+++ b/drivers/watchdog/sprd_wdt.c
@@ -0,0 +1,415 @@
+/*
+ * Spreadtrum watchdog driver
+ * Copyright (C) 2017 Spreadtrum - http://www.spreadtrum.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define SPRD_WDT_LOAD_LOW  0x0
+#define SPRD_WDT_LOAD_HIGH 0x4
+#define SPRD_WDT_CTRL  0x8
+#define SPRD_WDT_INT_CLR   0xc
+#define SPRD_WDT_INT_RAW   0x10
+#define SPRD_WDT_INT_MSK   0x14
+#define SPRD_WDT_CNT_LOW   0x18
+#define SPRD_WDT_CNT_HIGH  0x1c
+#define SPRD_WDT_LOCK  0x20
+#define SPRD_WDT_IRQ_LOAD_LOW  0x2c
+#define SPRD_WDT_IRQ_LOAD_HIGH 0x30
+
+/* WDT_CTRL */
+#define SPRD_WDT_INT_EN_BITBIT(0)
+#define SPRD_WDT_CNT_EN_BITBIT(1)
+#define SPRD_WDT_NEW_VER_ENBIT(2)
+#define SPRD_WDT_RST_EN_BITBIT(3)
+
+/* WDT_INT_CLR */
+#define SPRD_WDT_INT_CLEAR_BIT BIT(0)
+#define SPRD_WDT_RST_CLEAR_BIT BIT(3)
+
+/* WDT_INT_RAW */
+#define SPRD_WDT_INT_RAW_BIT   BIT(0)
+#define SPRD_WDT_RST_RAW_BIT   BIT(3)
+#define SPRD_WDT_LD_BUSY_BIT   BIT(4)
+
+/* 1s equale to 32768 counter steps */


equal ?


+#define SPRD_WDT_CNT_STEP  32768
+
+#define SPRD_WDT_UNLOCK_KEY0xe551
+#define SPRD_WDT_MIN_TIMROUT   3


TIMROUT ot TIMEOUT ?


+#define SPRD_WDT_MAX_TIMEOUT   60


Is that really the maximum supported timeout ? Seems a bit low.
Shouldn't it be something like (U32_MAX / SPRD_WDT_CNT_STEP) ?


+
+#define SPRD_WDT_CNT_HIGH_VALUE16


Maybe name it "SPRD_WDT_CNT_HIGH_SHIFT". It is not really a value,
it is a shift.


+#define SPRD_WDT_LOW_VALUE_MASKGENMASK(15, 0)
+#define SPRD_WDT_CNT_VALUE_MAX GENMASK(31, 0)


Does this mask serve a useful purpose ?


+#define SPRD_WDT_LOAD_TIMEOUT  1000
+
+struct sprd_wdt {
+   void __iomem *base;
+   struct watchdog_device wdd;
+   struct clk *enable;
+   struct clk *rtc_enable

Re: [PATCH v3 1/7] ACPI/PPTT: Add Processor Properties Topology Table parsing

2017-10-26 Thread Tomasz Nowicki

Hi John,

On 19.10.2017 12:25, John Garry wrote:

On 19/10/2017 06:18, Tomasz Nowicki wrote:


Summary:

I'm not at all happy with this specification's attempt to leave out
pieces of information which make parsing things more deterministic. In
this case I'm happy to demote the message level, but not remove it
entirely but I do think the obvious case you list shouldn't be the
default one.

Lastly:

I'm assuming the final result is that the table is actually being
parsed correctly despite the ugly message?


Indeed, the ThunderX2 PPTT table is being parsed so that topology shown
in lstopo and lscpu is correct.


Hi Tomasz,

Can you share the lscpu output? Does it have cluster info? I did not 
think that lscpu has a concept of clustering.


I would say that the per-cpu cluster index sysfs entry needs be added to 
drivers/base/arch_topology.c (and other appropiate code under 
GENERIC_ARCH_TOPOLOGY) to support this.


Here is what I get:

tn@val2-11 [~]$ lscpu -ap
# The following is the parsable format, which can be fed to other
# programs. Each different item in every column has an unique ID
# starting from zero.
# CPU,Core,Socket,Node,,L1d,L1i,L2,L3
[...]
1,0,0,0,,0,0,0,0
[...]

so yes, no cluster info.

Thanks,
Tomasz


Re: [PATCH 0/5] Few more FlexRM driver improvements

2017-10-26 Thread Anup Patel
On Tue, Oct 3, 2017 at 10:51 AM, Anup Patel  wrote:
> This patchset does few more improvements to Broadcom FlexRM mailbox
> driver.
>
> The patches are based on Linux-4.14-rc3 and can also be found at
> flexrm-imp2-v1 branch of:
> https://github.com/Broadcom/arm64-linux.git
>
> Anup Patel (4):
>   mailbox: bcm-flexrm-mailbox: Fix FlexRM ring flush sequence
>   mailbox: bcm-flexrm-mailbox: Print ring number in errors and warnings
>   mailbox: bcm-flexrm-mailbox: Use common GPL comment header
>   mailbox: Build Broadcom FlexRM driver as loadable module for iProc
> SOCs
>
> Scott Branden (1):
>   mailbox: bcm-flexrm-mailbox: add depends on ARCH_BCM_IPROC
>
>  drivers/mailbox/Kconfig  |  3 +-
>  drivers/mailbox/bcm-flexrm-mailbox.c | 66 
> ++--
>  2 files changed, 51 insertions(+), 18 deletions(-)
>
> --
> 2.7.4
>

Ping ??

Regards,
Anup


Re: [PATCH 1/3] Documentation: DT: Add Cygnus usb phy binding

2017-10-26 Thread Raveendra Padasalagi
Hi Rob,

On Fri, Oct 27, 2017 at 9:09 AM, Rob Herring  wrote:
> On Tue, Oct 24, 2017 at 10:07:00AM +0530, Raveendra Padasalagi wrote:
>> Add devicetree binding document for broadcom's
>> Cygnus SoC specific usb phy controller driver.
>
> "dt-bindings: phy: ..." for the subject please.

Ok. I will update it in the next patch set version.

>>
>> Signed-off-by: Raveendra Padasalagi 
>> ---
>>  .../bindings/phy/brcm,cygnus-usb-phy.txt   | 101 
>> +
>>  1 file changed, 101 insertions(+)
>>  create mode 100644 
>> Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt
>>
>> diff --git a/Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt 
>> b/Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt
>> new file mode 100644
>> index 000..2d99fea
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt
>> @@ -0,0 +1,101 @@
>> +BROADCOM CYGNUS USB PHY
>> +
>> +Required Properties:
>> +- compatible:  brcm,cygnus-usb-phy
>> +- reg : the register start address and length for crmu_usbphy_aon_ctrl,
>> +  cdru usb phy control and reset registers, usb host idm registers,
>> +  usb device idm registers.
>
> Make this list 1 per line.
Ok
>> +- reg-names: a list of the names corresponding to the previous register
>> +  ranges. Should contain "crmu-usbphy-aon-ctrl", "cdru-usbphy",
>> +  "usb2h-idm", "usb2d-idm".
>> +- address-cells: should be 1
>> +- size-cells: should be 0
>> +
>> +Sub-nodes:
>> +  Each port's PHY should be represented as a sub-node.
>> +
>> +Sub-nodes required properties:
>> +- reg: the PHY number
>> +- #phy-cells must be 1
>> +  The node that uses the phy must provide 1 integer argument specifying
>> +  port number.
>
> Either you need to move #phy-cells up a level or #phy-cells should be 0.
Ok
>> +
>> +Optional Properties:
>> +- vbus-p#-supply : The regulator for vbus out control for the host
>> +  functionality enabled ports.
>> +- vbus-gpios: vbus gpio binding
>
> Are you using these or extcon?
Yes, using extcon in phy driver to receive USB Device/Host connect/disconnect
notifications.

> Don't use extcon. It needs to be redesigned and I don't want to see new
> users.

Without extcon I need to duplicate the code in phy driver to implement
extcon functionality,
which is again bad. Once the extcon redesign is done may be we can
adopt the changes in
this driver at that time.

>> +  This is mandatory for port 2, as port 2 is used as dual role phy.
>> +  Based on the vbus and id values device or host role is determined
>> +  for phy 2.
>> +
>> +- extcon: extcon phandle
>> +  This is mandatory for port 2,  as port 2 is used as dual role phy.
>> +  extcon should be phandle to external usb gpio module which provide
>> +  device or host role notifications based on the ID and VBUS gpio's state.
>> +
>> +
>> +Refer to phy/phy-bindings.txt for the generic PHY binding properties
>> +
>> +NOTE: port 0 and port 1 are host only and port 2 is dual role port.
>> +
>> +Example of phy :
>> + usbphy: phy@0301c028 {
>
> usb-phy@301c028
>
>> + compatible = "brcm,cygnus-usb-phy";
>> + reg = <0x0301c028 0x4>,
>> +   <0x0301d1b4 0x5c>,
>> +   <0x18115000 0xa00>,
>> +   <0x18111000 0xa00>;
>> + reg-names = "crmu-usbphy-aon-ctrl", "cdru-usbphy",
>> + "usb2h-idm", "usb2d-idm";
>> + #address-cells = <1>;
>> + #size-cells = <0>;
>> +
>> + usbphy0: usb-phy@0 {
>> + reg = <0>;
>> + #phy-cells = <1>;
>> + };
>> +
>> + usbphy1: usb-phy@1 {
>> + reg = <1>;
>> + #phy-cells = <1>;
>> + };
>> +
>> + usbphy2: usb-phy@2 {
>> + reg = <2>;
>> + #phy-cells = <1>;
>> + extcon = <&extcon_usb>;
>> + };
>> + };
>> +
>> + extcon_usb: extcon_usb {
>> + compatible = "linux,extcon-usb-gpio";
>> + vbus-gpio = <&gpio_asiu 121 0>;
>> + id-gpio = <&gpio_asiu 122 0>;
>> + status = "okay";
>> + };
>> +
>> +
>> +Example of node using the phy:
>> +
>> + /* This nodes declares all three ports, port 0
>> + and port 1 are host and port 2 is device */
>> +
>> + ehci0: usb@18048000 {
>> + compatible = "generic-ehci";
>> + reg = <0x18048000 0x100>;
>> + interrupts = ;
>> + phys = <&usbphy0 0 &usbphy1 1 &usbphy2 2>;
>> + phy-names = "usbp0","usbp1","usbp2";
>> + status = "okay";
>> + };
>> +
>> + /* This node declares port 2 phy
>> + and configures it for device */
>> +
>> + usbd_udc_dwc1: usbd_udc_dwc@1804c000 {
>
> usb@...
Ok.
>> + compatible = "iproc-udc";
>> + reg = <0x1804c000 0x2000>;
>> + interrupts = ;
>> + phys = <&usbphy2 2>;
>> +

Re: [PATCH] net: tipc: Convert timers to use timer_setup()

2017-10-26 Thread Kees Cook
On Tue, Oct 24, 2017 at 11:44 AM, Jon Maloy  wrote:
> NAK. It doesn't sound like a good idea to send this to net. Especially since 
> one of these timers has already been refactored in net-next.

Hi! I'm not sure what you mean about the one timer issue. I don't see
any use of timer_setup() in net/tipc (and no recent conversions to the
older setup_timer() API). What's the preferred path for landing this
API conversion in net/tipc/?

And, just to note, these changes are almost entirely mechanical. The
only "special" case is in tipc_sk_timeout() where the argument needs
to be slightly adjusted to fetch the tsk from the sk again.

Thanks!

-Kees

-- 
Kees Cook
Pixel Security


Re: [PATCH 1/1] l2tp: cleanup l2tp_tunnel_delete calls

2017-10-26 Thread David Miller
From: Jiri Slaby 
Date: Wed, 25 Oct 2017 15:57:55 +0200

> l2tp_tunnel_delete does not return anything since commit 62b982eeb458
> ("l2tp: fix race condition in l2tp_tunnel_delete").  But call sites of
> l2tp_tunnel_delete still do casts to void to avoid unused return value
> warnings.
> 
> Kill these now useless casts.
> 
> Signed-off-by: Jiri Slaby 

Appied to net-next, thanks.


Re: [PATCH] maintainers: drop Chris Wright from pvops

2017-10-26 Thread Chris Wright
(resend w/out html damage that triggers lkml reject)

On Thu, Oct 26, 2017 at 3:17 PM, Rusty Russell  wrote:
> Chris CC'd: He wasn't that hard to find.
>
> (linkedin says he's CTO of RedHat now.  I feel like an underachiever!)
>
> Cheers,
> Rusty.
>
> Juergen Gross  writes:
>
>> Mails to chr...@sous-sol.org are not deliverable since several months.
>> Drop him as PARAVIRT_OPS maintainer.
>>
>> Signed-off-by: Juergen Gross 

Acked-by: Chris Wright 

;)

thanks,
-chris

>> ---
>>  MAINTAINERS | 1 -
>>  1 file changed, 1 deletion(-)
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index d85c08956875..af0cb69f6a3e 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -10179,7 +10179,6 @@ F:Documentation/parport*.txt
>>
>>  PARAVIRT_OPS INTERFACE
>>  M:   Juergen Gross 
>> -M:   Chris Wright 
>>  M:   Alok Kataria 
>>  M:   Rusty Russell 
>>  L:   virtualizat...@lists.linux-foundation.org
>> --
>> 2.12.3


[PATCH] x86/build: beautify build log of syscall headers

2017-10-26 Thread Masahiro Yamada
This makes the build log look nicer.

Before:
  SYSTBL  arch/x86/entry/syscalls/../../include/generated/asm/syscalls_32.h
  SYSHDR  arch/x86/entry/syscalls/../../include/generated/asm/unistd_32_ia32.h
  SYSHDR  arch/x86/entry/syscalls/../../include/generated/asm/unistd_64_x32.h
  SYSTBL  arch/x86/entry/syscalls/../../include/generated/asm/syscalls_64.h
  SYSHDR  arch/x86/entry/syscalls/../../include/generated/uapi/asm/unistd_32.h
  SYSHDR  arch/x86/entry/syscalls/../../include/generated/uapi/asm/unistd_64.h
  SYSHDR  arch/x86/entry/syscalls/../../include/generated/uapi/asm/unistd_x32.h

After:
  SYSTBL  arch/x86/include/generated/asm/syscalls_32.h
  SYSHDR  arch/x86/include/generated/asm/unistd_32_ia32.h
  SYSHDR  arch/x86/include/generated/asm/unistd_64_x32.h
  SYSTBL  arch/x86/include/generated/asm/syscalls_64.h
  SYSHDR  arch/x86/include/generated/uapi/asm/unistd_32.h
  SYSHDR  arch/x86/include/generated/uapi/asm/unistd_64.h
  SYSHDR  arch/x86/include/generated/uapi/asm/unistd_x32.h

Signed-off-by: Masahiro Yamada 
---

 arch/x86/entry/syscalls/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/entry/syscalls/Makefile b/arch/x86/entry/syscalls/Makefile
index 57aa59f..e34c7a9 100644
--- a/arch/x86/entry/syscalls/Makefile
+++ b/arch/x86/entry/syscalls/Makefile
@@ -1,5 +1,5 @@
-out := $(obj)/../../include/generated/asm
-uapi := $(obj)/../../include/generated/uapi/asm
+out := arch/$(SRCARCH)/include/generated/asm
+uapi := arch/$(SRCARCH)/include/generated/uapi/asm
 
 # Create output directory if not already present
 _dummy := $(shell [ -d '$(out)' ] || mkdir -p '$(out)') \
-- 
2.7.4



Re: [PATCH v2] ipv6: esp6: use BUG_ON instead of if condition followed by BUG

2017-10-26 Thread Gustavo A. R. Silva


Quoting Herbert Xu :


On Thu, Oct 26, 2017 at 07:51:06AM -0500, Gustavo A. R. Silva wrote:

Use BUG_ON instead of if condition followed by BUG in esp_remove_trailer.

This issue was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva 


Acked-by: Herbert Xu 


Thanks!

--
Gustavo A. R. Silva








[PATCH] ipv6: exthdrs: use swap macro in ipv6_dest_hao

2017-10-26 Thread Gustavo A. R. Silva
make use of the swap macro and remove unnecessary variable tmp_addr.
This makes the code easier to read and maintain.

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva 
---
 net/ipv6/exthdrs.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c
index 7835dea..9f918a7 100644
--- a/net/ipv6/exthdrs.c
+++ b/net/ipv6/exthdrs.c
@@ -187,7 +187,6 @@ static bool ipv6_dest_hao(struct sk_buff *skb, int optoff)
struct ipv6_destopt_hao *hao;
struct inet6_skb_parm *opt = IP6CB(skb);
struct ipv6hdr *ipv6h = ipv6_hdr(skb);
-   struct in6_addr tmp_addr;
int ret;
 
if (opt->dsthao) {
@@ -229,9 +228,7 @@ static bool ipv6_dest_hao(struct sk_buff *skb, int optoff)
if (skb->ip_summed == CHECKSUM_COMPLETE)
skb->ip_summed = CHECKSUM_NONE;
 
-   tmp_addr = ipv6h->saddr;
-   ipv6h->saddr = hao->addr;
-   hao->addr = tmp_addr;
+   swap(ipv6h->saddr, hao->addr);
 
if (skb->tstamp == 0)
__net_timestamp(skb);
-- 
2.7.4



Re: [PATCH 0/4] Add SimpleFB support for Allwinner H3 SoC

2017-10-26 Thread icenowy

在 2017-09-11 23:55,Icenowy Zheng 写道:

This patchset adds devicetree-side support of SimpleFB on Allwinner H3
SoC.

The DE2 CCU is initialized and used by the SimpleFB node, in order to
furtherly coexist with the DRM code.

The first patch adds pipelines for DE2 displays in simplefb-sunxi
device tree binding.

The second patch adds DE2 CCU device node for H3 SoC, and the skeleton
of the node enters the H3/H5 common DTSI; the H5 support is splited
into the third patch, as they will enter different tree.

The fourth patch finally adds simplefb nodes, using the
pipeline strings introduced in the first patch.

Icenowy Zheng (4):
  dt-bindings: simplefb-sunxi: add pipelines for DE2
  ARM: sun8i: h3/h5: add DE2 CCU device node for H3
  arm64: allwinner: h5: add compatible string for DE2 CCU
  ARM: sunxi: h3/h5: add simplefb nodes


Maxime,
as the U-Boot side is applied to u-boot-video, could you take a look at 
this

patchset?

Thanks!
Icenowy



 .../bindings/display/simple-framebuffer-sunxi.txt  |  4 ++
 arch/arm/boot/dts/sun8i-h3.dtsi|  4 ++
 arch/arm/boot/dts/sunxi-h3-h5.dtsi | 43 
++

 arch/arm64/boot/dts/allwinner/sun50i-h5.dtsi   |  4 ++
 4 files changed, 55 insertions(+)


Re: [PATCH] mm/swap: Use page flags to determine LRU list in __activate_page()

2017-10-26 Thread Anshuman Khandual
On 10/23/2017 08:52 AM, Anshuman Khandual wrote:
> On 10/19/2017 09:03 PM, Michal Hocko wrote:
>> On Thu 19-10-17 20:26:57, Anshuman Khandual wrote:
>>> Its already assumed that the PageActive flag is clear on the input
>>> page, hence page_lru(page) will pick the base LRU for the page. In
>>> the same way page_lru(page) will pick active base LRU, once the
>>> flag PageActive is set on the page. This change of LRU list should
>>> happen implicitly through the page flags instead of being hard
>>> coded.
>>
>> The patch description tells what but it doesn't explain _why_? Does the
>> resulting code is better, more optimized or is this a pure readability
>> thing?
> 
> Not really. Not only it removes couple of lines of code but it also
> makes it look more logical from function flow point of view as well.
> 
>>
>> All I can see is that page_lru is more complex and a large part of it
>> can be optimized away which has been done manually here. I suspect the
>> compiler can deduce the same thing.
> 
> Why not ? I mean, that is the essence of the function page_lru() which
> should get us the exact LRU list the page should be on and hence we
> should not hand craft these manually.

Hi Michal,

Did not hear from you on this. So wondering what is the verdict
about this patch ?

- Anshuman



RE: [PATCH 2/2] Add /proc/PID/{smaps, numa_maps} support for DAX

2017-10-26 Thread Du, Fan


>-Original Message-
>From: linux-kernel-ow...@vger.kernel.org
>[mailto:linux-kernel-ow...@vger.kernel.org] On Behalf Of Dave Hansen
>Sent: Thursday, October 26, 2017 10:51 PM
>To: Michal Hocko 
>Cc: Du, Fan ; a...@linux-foundation.org; h...@lst.de;
>Williams, Dan J ; linux-kernel@vger.kernel.org;
>linux-...@vger.kernel.org
>Subject: Re: [PATCH 2/2] Add /proc/PID/{smaps, numa_maps} support for DAX
>
>On 10/26/2017 07:31 AM, Michal Hocko wrote:
>> On Thu 26-10-17 07:24:14, Dave Hansen wrote:
>>> Actually, I don't remember whether it was tooling or just confused
>>> humans.  I *think* Dan was trying to write test cases for huge page DAX
>>> support and couldn't figure out whether or not it was using large pages.
>>
>> That sounds like a very weak justification to adding new stuff to smaps
>> to be honest.
>
>Yep, agreed.  It can't go in _just_ for DAX, and Fan and the other DAX
>folks need to elaborate on their needs here.

If user creates device DAX /dev/dax with some capacity like 512G, mmap it and
Use it will, or touched 128G. To my best knowledge at this part, there is no
statistics reported how much memory behind DAX actually used.

This is the problem our customer is facing right now.

I agree with smaps should make no special for DAX, whether or not we update
smaps for DAX, cat /proc/PID/smaps always report its part for /dev/dax.
The problem is should we report DAX usage by RSS, or introduce new fields
Like Pte@{4K,2M} for a another different purpose.

The v4 version tried to merged device DAX usage with RSS,
https://lkml.org/lkml/2017/10/26/24



>Do you have any better ideas?  If we did this, we could probably make an
>argument that the AnonHuge fields could go away some day.  They haven't
>always been there.
>
>The only other alternative I can think of are truly DAX-specific
>interfaces, which also seem like a really bad idea.
>
>> Not only that. There have been reports that reading smaps is too
>> expensive. Curiously enough the overhead doesn't come up from
>> the data collection but rather copying to the userspace. So we should be
>> careful to not print data that is not of general use.
>
>Yikes!  I just did a quick:
>
>   while true; do cat /proc/*/smaps | wc ; done
>
>and the copying out to userspace is ~1/15th the overhead of
>smaps_account().  Something sounds screwy if you're seeing the overhead
>at copying to userspace.
>
>What else can we do than continue to bloat smaps?  Could we do a file
>per VMA?
>
>   /proc/$pid/smap/0x123000-0x456000



[PATCH] panic: add support to update panic_timeout via DT

2017-10-26 Thread Jeetesh Burman
Add support to set 'panic_timeout' value via dtb to have
control from device tree. This makes sense when you have
multiple platforms support from same defconfig and
differentiated only through device tree blob.
The patch will check for panic time out value coming
from dtb if it exists, otherwise continues with
defconfig provided option.

Signed-off-by: Jeetesh Burman 
---
 kernel/panic.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/kernel/panic.c b/kernel/panic.c
index bdd18af..2541b96 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define PANIC_TIMER_STEP 100
 #define PANIC_BLINK_SPD 18
@@ -482,6 +483,12 @@ static u64 oops_id;
 
 static int init_oops_id(void)
 {
+   struct device_node *np;
+
+   np = of_find_node_by_name(NULL, "panic_timeout");
+   if (np)
+   of_property_read_u32(np, "panic-timeout-value", &panic_timeout);
+
if (!oops_id)
get_random_bytes(&oops_id, sizeof(oops_id));
else
-- 
2.1.4



Re: [RFC 1/3] USB: Add document for usb of Hikey960

2017-10-26 Thread Rob Herring
On Tue, Oct 24, 2017 at 02:06:08PM +0800, Yu Chen wrote:
> DT bindings for usb of Hikey960.
> 
> Signed-off-by: Yu Chen 
> Signed-off-by: Ning Fan 
> Signed-off-by: Di Yang 
> Signed-off-by: Rui Li 
> 
> ---
>  .../devicetree/bindings/usb/hisilicon-usb.txt  | 38 
> ++
>  1 file changed, 38 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/usb/hisilicon-usb.txt
> 
> diff --git a/Documentation/devicetree/bindings/usb/hisilicon-usb.txt 
> b/Documentation/devicetree/bindings/usb/hisilicon-usb.txt
> new file mode 100644
> index ..dc4c460885d6
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/usb/hisilicon-usb.txt

Should be 3660 specific?

> @@ -0,0 +1,38 @@
> +* HISILICON USB HUB

Looks like a controller, not a hub?

> +
> +Required properties:
> +- compatible: One of the specific types :"hisilicon,hi3660-dwc3",

> + "hisilicon,gpio_hubv1","hisilicon,gpio_hubv2"

What are these?

> +
> +Optional properties of devices using ISP1301:
> +- transceiver: phandle of isp1301 - this helps the ISP1301 driver to find the
> +   ISP1301 instance associated with the respective USB driver

Really? A full-speed transceiver?

> +
> +Example:
> +
> + hisi_usb@ff20 {

usb@...

> + #address-cells = <2>;
> + #size-cells = <2>;
> + compatible = "hisilicon,hi3660-dwc3";
> + reg = <0x0 0xff20 0x0 0x1000
> +  0x0 0xff10 0x0 0x10>;
> + ranges;
> + bc_again_flag = <0>;

Not documented. Don't use '_' in property names.

> +
> + clocks = <&crg_ctrl HI3660_CLK_ABB_USB>,
> +  <&crg_ctrl HI3660_ACLK_GATE_USB3OTG>;
> + clock-names = "clk_usb3phy_ref", "aclk_usb3otg";
> + eye_diagram_param = <0x1c466e3>;
> + eye_diagram_host_param = <0x1c466e3>;
> + usb3_phy_cr_param = <0xb80>;
> + usb3_phy_host_cr_param = <0x980>;
> + usb3_phy_tx_vboost_lvl = <0x5>;

All of these have to be documented.

> +
> + dwc3@ff10 {

Ah, it's a DWC3 controller. No references to the common binding?

> + compatible = "snps,dwc3";
> + reg = <0x0 0xff10 0x0 0x10>;
> + interrupts = <0 159 4>, <0 161 4>;
> + dr_mode = "otg";
> + maximum-speed = "super-speed";
> + };
> + };
> \ No newline at end of file

Fix what it says here.

Rob


Re: [PATCH] MAINTAINERS: thermal: Remove Eduardo's git tree

2017-10-26 Thread Eduardo Valentin
Hello Florian,

On Fri, Oct 27, 2017 at 10:22:31AM +0800, Zhang Rui wrote:
> CC Eduardo.
> 
> On Thu, 2017-10-26 at 19:06 +0200, Daniel Lezcano wrote:
> > On 26/10/2017 18:59, Florian Fainelli wrote:
> > > 
> > > On 09/24/2017 02:18 PM, Florian Fainelli wrote:
> > > > 
> > > > Eduardo's git tree at:
> > > > git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-
> > > > thermal.git
> > > > 
> > > > has not been updated in months, remove it to avoid any confusing
> > > > and
> > > > patch submissions to stall.
> > > > 
> > > > Signed-off-by: Florian Fainelli 
> > > > ---
> > > > This is agains Rui's next branch
> > > The very fact that this patch has not received any response is a
> > > clear
> > > indication that there is something seriously wrong with the SoC
> > > thermal
> > > drivers maintenance.

> > > 
> > > Eduardo, if you can't even be bothered to respond to emails and
> > > Ack/Nack, then remove yourself so you can set clear expectations
> > > with
> > > people attempting to get their drivers upstreamed.
> > Eduardo reviewed and took my patches recently.
> > 
> > I don't know the status about merging them in Linus's tree.
> > 
> > 
> Eduardo was busy on some personal stuff during last release cycle, and
> now he is back and is taking thermal soc patches for next merge window.

Yes, past merge windows I was not able to help on the thermal subsystem
maintenance, which I do, btw, in my free time.
If you want to sponsor that, feel free to contact me in private.

*Also, not that there are TWO maintainers in the thermal subsystem, and Rui
was notified of my absence. And I am pretty sure he would take care of
patches in case you properly called his attention.*

> 
> I think he didn't response because he was not CCed.

Yup, if you do not copy me in e-mails that you want my attention, it's
hard to respond. I suppose if you want to remove a tree of a volunteer,
it would be fair if you at least copy him/her :-)

Not sure if you noticed, but the BRCM driver you pinged me in linux-pm
is also already merge in my tree and will be sent in the next merge
window as notified over email:
https://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal.git/log/?h=linus

Hope that helps and also clarifies.

> 
> thanks,
> rui


Re: [PATCH 1/3] Documentation: DT: Add Cygnus usb phy binding

2017-10-26 Thread Rob Herring
On Tue, Oct 24, 2017 at 10:07:00AM +0530, Raveendra Padasalagi wrote:
> Add devicetree binding document for broadcom's
> Cygnus SoC specific usb phy controller driver.

"dt-bindings: phy: ..." for the subject please.

> 
> Signed-off-by: Raveendra Padasalagi 
> ---
>  .../bindings/phy/brcm,cygnus-usb-phy.txt   | 101 
> +
>  1 file changed, 101 insertions(+)
>  create mode 100644 
> Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt
> 
> diff --git a/Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt 
> b/Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt
> new file mode 100644
> index 000..2d99fea
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt
> @@ -0,0 +1,101 @@
> +BROADCOM CYGNUS USB PHY
> +
> +Required Properties:
> +- compatible:  brcm,cygnus-usb-phy
> +- reg : the register start address and length for crmu_usbphy_aon_ctrl,
> +  cdru usb phy control and reset registers, usb host idm registers,
> +  usb device idm registers.

Make this list 1 per line.

> +- reg-names: a list of the names corresponding to the previous register
> +  ranges. Should contain "crmu-usbphy-aon-ctrl", "cdru-usbphy",
> +  "usb2h-idm", "usb2d-idm".
> +- address-cells: should be 1
> +- size-cells: should be 0
> +
> +Sub-nodes:
> +  Each port's PHY should be represented as a sub-node.
> +
> +Sub-nodes required properties:
> +- reg: the PHY number
> +- #phy-cells must be 1
> +  The node that uses the phy must provide 1 integer argument specifying
> +  port number.

Either you need to move #phy-cells up a level or #phy-cells should be 0.

> +
> +Optional Properties:
> +- vbus-p#-supply : The regulator for vbus out control for the host
> +  functionality enabled ports.
> +- vbus-gpios: vbus gpio binding

Are you using these or extcon?

Don't use extcon. It needs to be redesigned and I don't want to see new 
users.

> +  This is mandatory for port 2, as port 2 is used as dual role phy.
> +  Based on the vbus and id values device or host role is determined
> +  for phy 2.
> +
> +- extcon: extcon phandle
> +  This is mandatory for port 2,  as port 2 is used as dual role phy.
> +  extcon should be phandle to external usb gpio module which provide
> +  device or host role notifications based on the ID and VBUS gpio's state.
> +
> +
> +Refer to phy/phy-bindings.txt for the generic PHY binding properties
> +
> +NOTE: port 0 and port 1 are host only and port 2 is dual role port.
> +
> +Example of phy :
> + usbphy: phy@0301c028 {

usb-phy@301c028

> + compatible = "brcm,cygnus-usb-phy";
> + reg = <0x0301c028 0x4>,
> +   <0x0301d1b4 0x5c>,
> +   <0x18115000 0xa00>,
> +   <0x18111000 0xa00>;
> + reg-names = "crmu-usbphy-aon-ctrl", "cdru-usbphy",
> + "usb2h-idm", "usb2d-idm";
> + #address-cells = <1>;
> + #size-cells = <0>;
> +
> + usbphy0: usb-phy@0 {
> + reg = <0>;
> + #phy-cells = <1>;
> + };
> +
> + usbphy1: usb-phy@1 {
> + reg = <1>;
> + #phy-cells = <1>;
> + };
> +
> + usbphy2: usb-phy@2 {
> + reg = <2>;
> + #phy-cells = <1>;
> + extcon = <&extcon_usb>;
> + };
> + };
> +
> + extcon_usb: extcon_usb {
> + compatible = "linux,extcon-usb-gpio";
> + vbus-gpio = <&gpio_asiu 121 0>;
> + id-gpio = <&gpio_asiu 122 0>;
> + status = "okay";
> + };
> +
> +
> +Example of node using the phy:
> +
> + /* This nodes declares all three ports, port 0
> + and port 1 are host and port 2 is device */
> +
> + ehci0: usb@18048000 {
> + compatible = "generic-ehci";
> + reg = <0x18048000 0x100>;
> + interrupts = ;
> + phys = <&usbphy0 0 &usbphy1 1 &usbphy2 2>;
> + phy-names = "usbp0","usbp1","usbp2";
> + status = "okay";
> + };
> +
> + /* This node declares port 2 phy
> + and configures it for device */
> +
> + usbd_udc_dwc1: usbd_udc_dwc@1804c000 {

usb@...

> + compatible = "iproc-udc";
> + reg = <0x1804c000 0x2000>;
> + interrupts = ;
> + phys = <&usbphy2 2>;
> + phy-names = "usbdrd";
> + };
> -- 
> 1.9.1
> 


[PATCH] media: i2c: Add the ov7740 image sensor driver

2017-10-26 Thread Wenyou Yang
From: Songjun Wu 

The ov7740 (color) image sensor is a high performance VGA CMOS
image snesor, which supports for output formats: RAW RGB and YUV
and image sizes: VGA, and QVGA, CIF and any size smaller.

Signed-off-by: Songjun Wu 
Signed-off-by: Wenyou Yang 
---

 .../devicetree/bindings/media/i2c/ov7740.txt   |   43 +
 drivers/media/i2c/Kconfig  |8 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/ov7740.c | 1220 
 4 files changed, 1272 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov7740.txt
 create mode 100644 drivers/media/i2c/ov7740.c

diff --git a/Documentation/devicetree/bindings/media/i2c/ov7740.txt 
b/Documentation/devicetree/bindings/media/i2c/ov7740.txt
new file mode 100644
index ..b306e5aa97bf
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/ov7740.txt
@@ -0,0 +1,43 @@
+* Omnivision OV7740 CMOS image sensor
+
+The Omnivision OV7740 image sensor supports multiple output image
+size, such as VGA, and QVGA, CIF and any size smaller. It also
+supports the RAW RGB and YUV output formats.
+
+Required Properties:
+- compatible: should be "ovti,ov7740"
+- clocks: reference to the xvclk input clock.
+- clock-names: should be "xvclk".
+
+Optional Properties:
+- reset-gpios: reference to the GPIO connected to the reset_b pin,
+  if any. Active low with pull-ip resistor.
+- powerdown-gpios: reference to the GPIO connected to the pwdn pin,
+  if any. Active high with pull-down resistor.
+
+The device node must contain one 'port' child node for its digital
+output video port, in accordance with the video interface bindings
+defined in Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+
+   i2c1: i2c@fc028000 {
+   ov7740: camera@21 {
+   compatible = "ovti,ov7740";
+   reg = <0x21>;
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_sensor_power 
&pinctrl_sensor_reset>;
+   clocks = <&isc>;
+   clock-names = "xvclk";
+   assigned-clocks = <&isc>;
+   assigned-clock-rates = <2400>;
+   reset-gpios = <&pioA 43 GPIO_ACTIVE_LOW>;
+   powerdown-gpios = <&pioA 44 GPIO_ACTIVE_HIGH>;
+
+   port {
+   ov7740_0: endpoint {
+   remote-endpoint = <&isc_0>;
+   };
+   };
+   };
+   };
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 47113774a297..402ad0e4024c 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -657,6 +657,14 @@ config VIDEO_OV7670
  OV7670 VGA camera.  It currently only works with the M88ALP01
  controller.
 
+config VIDEO_OV7740
+   tristate "OmniVision OV7740 sensor support"
+   depends on I2C && VIDEO_V4L2
+   depends on MEDIA_CAMERA_SUPPORT
+   ---help---
+ This is a Video4Linux2 sensor-level driver for the OmniVision
+ OV7740 VGA camera sensor.
+
 config VIDEO_OV9650
tristate "OmniVision OV9650/OV9652 sensor support"
depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index c843c181dfb9..f94cb2a8ed91 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -67,6 +67,7 @@ obj-$(CONFIG_VIDEO_OV5670) += ov5670.o
 obj-$(CONFIG_VIDEO_OV6650) += ov6650.o
 obj-$(CONFIG_VIDEO_OV7640) += ov7640.o
 obj-$(CONFIG_VIDEO_OV7670) += ov7670.o
+obj-$(CONFIG_VIDEO_OV7740) += ov7740.o
 obj-$(CONFIG_VIDEO_OV9650) += ov9650.o
 obj-$(CONFIG_VIDEO_OV13858) += ov13858.o
 obj-$(CONFIG_VIDEO_MT9M032) += mt9m032.o
diff --git a/drivers/media/i2c/ov7740.c b/drivers/media/i2c/ov7740.c
new file mode 100644
index ..d68add05b46e
--- /dev/null
+++ b/drivers/media/i2c/ov7740.c
@@ -0,0 +1,1220 @@
+/*
+ * Copyright (c) 2017 Microchip Corporation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define REG_OUTSIZE_LSB 0x34
+
+/* OV7740 register tables */
+#define REG_GAIN   0x00/* Gain lower 8 bits (rest in vref) */
+#define REG_BGAIN  0x01/* blue gain */
+#define REG_RGAIN  0x02/* red gain */
+#define REG_GGAIN 

[PATCH v5 1/5] media: atmel-isc: Add spin lock for clock enable ops

2017-10-26 Thread Wenyou Yang
Add the spin lock for the clock enable and disable operations.

Signed-off-by: Wenyou Yang 
---

Changes in v5: None
Changes in v4: None
Changes in v3:
 - Fix the wrong used spinlock.
 - s/_/- on the subject.

Changes in v2: None

 drivers/media/platform/atmel/atmel-isc.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/atmel/atmel-isc.c 
b/drivers/media/platform/atmel/atmel-isc.c
index 2f8e345d297e..991f962b7023 100644
--- a/drivers/media/platform/atmel/atmel-isc.c
+++ b/drivers/media/platform/atmel/atmel-isc.c
@@ -65,6 +65,7 @@ struct isc_clk {
struct clk_hw   hw;
struct clk  *clk;
struct regmap   *regmap;
+   spinlock_t  lock;
u8  id;
u8  parent_id;
u32 div;
@@ -312,26 +313,37 @@ static int isc_clk_enable(struct clk_hw *hw)
struct isc_clk *isc_clk = to_isc_clk(hw);
u32 id = isc_clk->id;
struct regmap *regmap = isc_clk->regmap;
+   unsigned long flags;
+   unsigned int status;
 
dev_dbg(isc_clk->dev, "ISC CLK: %s, div = %d, parent id = %d\n",
__func__, isc_clk->div, isc_clk->parent_id);
 
+   spin_lock_irqsave(&isc_clk->lock, flags);
regmap_update_bits(regmap, ISC_CLKCFG,
   ISC_CLKCFG_DIV_MASK(id) | ISC_CLKCFG_SEL_MASK(id),
   (isc_clk->div << ISC_CLKCFG_DIV_SHIFT(id)) |
   (isc_clk->parent_id << ISC_CLKCFG_SEL_SHIFT(id)));
 
regmap_write(regmap, ISC_CLKEN, ISC_CLK(id));
+   spin_unlock_irqrestore(&isc_clk->lock, flags);
 
-   return 0;
+   regmap_read(regmap, ISC_CLKSR, &status);
+   if (status & ISC_CLK(id))
+   return 0;
+   else
+   return -EINVAL;
 }
 
 static void isc_clk_disable(struct clk_hw *hw)
 {
struct isc_clk *isc_clk = to_isc_clk(hw);
u32 id = isc_clk->id;
+   unsigned long flags;
 
+   spin_lock_irqsave(&isc_clk->lock, flags);
regmap_write(isc_clk->regmap, ISC_CLKDIS, ISC_CLK(id));
+   spin_unlock_irqrestore(&isc_clk->lock, flags);
 }
 
 static int isc_clk_is_enabled(struct clk_hw *hw)
@@ -492,6 +504,7 @@ static int isc_clk_register(struct isc_device *isc, 
unsigned int id)
isc_clk->regmap = regmap;
isc_clk->id = id;
isc_clk->dev= isc->dev;
+   spin_lock_init(&isc_clk->lock);
 
isc_clk->clk = clk_register(isc->dev, &isc_clk->hw);
if (IS_ERR(isc_clk->clk)) {
-- 
2.13.0



[PATCH v5 5/5] media: atmel-isc: Rework the format list

2017-10-26 Thread Wenyou Yang
To improve the readability of code, split the format array into two,
one for the format description, other for the register configuration.
Meanwhile, add the flag member to indicate the format can be achieved
from the sensor or be produced by the controller, and rename members
related to the register configuration.

Also add more formats support: GREY, ARGB444, ARGB555 and ARGB32.

Signed-off-by: Wenyou Yang 
---

Changes in v5: None
Changes in v4: None
Changes in v3:
 - Add a new flag for Raw Bayer format to remove MAX_RAW_FMT_INDEX define.
 - Add the comments for define of the format flag.
 - Rebase media_tree/master.

Changes in v2:
 - Add the new patch to remove the unnecessary member from
   isc_subdev_entity struct.
 - Rebase on the patch set,
[PATCH 0/6] [media] Atmel: Adjustments for seven function 
implementations
https://www.mail-archive.com/linux-media@vger.kernel.org/msg118342.html

 drivers/media/platform/atmel/atmel-isc.c | 530 ---
 1 file changed, 411 insertions(+), 119 deletions(-)

diff --git a/drivers/media/platform/atmel/atmel-isc.c 
b/drivers/media/platform/atmel/atmel-isc.c
index a99796f7eb03..9294ff0c7b83 100644
--- a/drivers/media/platform/atmel/atmel-isc.c
+++ b/drivers/media/platform/atmel/atmel-isc.c
@@ -89,34 +89,63 @@ struct isc_subdev_entity {
struct list_head list;
 };
 
+/* Indicate the format is generated by the sensor */
+#define FMT_FLAG_FROM_SENSOR   BIT(0)
+/* Indicate the format is produced by ISC itself */
+#define FMT_FLAG_FROM_CONTROLLER   BIT(1)
+/* Indicate a Raw Bayer format */
+#define FMT_FLAG_RAW_FORMATBIT(2)
+
+#define FMT_FLAG_RAW_FROM_SENSOR   (FMT_FLAG_FROM_SENSOR | \
+FMT_FLAG_RAW_FORMAT)
+
 /*
  * struct isc_format - ISC media bus format information
  * @fourcc:Fourcc code for this format
  * @mbus_code: V4L2 media bus format code.
+ * flags:  Indicate format from sensor or converted by controller
  * @bpp:   Bits per pixel (when stored in memory)
- * @reg_bps:   reg value for bits per sample
  * (when transferred over a bus)
- * @pipeline:  pipeline switch
  * @sd_support:Subdev supports this format
  * @isc_support:   ISC can convert raw format to this format
  */
+
 struct isc_format {
u32 fourcc;
u32 mbus_code;
+   u32 flags;
u8  bpp;
 
-   u32 reg_bps;
-   u32 reg_bay_cfg;
-   u32 reg_rlp_mode;
-   u32 reg_dcfg_imode;
-   u32 reg_dctrl_dview;
-
-   u32 pipeline;
-
boolsd_support;
boolisc_support;
 };
 
+/* Pipeline bitmap */
+#define WB_ENABLE  BIT(0)
+#define CFA_ENABLE BIT(1)
+#define CC_ENABLE  BIT(2)
+#define GAM_ENABLE BIT(3)
+#define GAM_BENABLEBIT(4)
+#define GAM_GENABLEBIT(5)
+#define GAM_RENABLEBIT(6)
+#define CSC_ENABLE BIT(7)
+#define CBC_ENABLE BIT(8)
+#define SUB422_ENABLE  BIT(9)
+#define SUB420_ENABLE  BIT(10)
+
+#define GAM_ENABLES(GAM_RENABLE | GAM_GENABLE | GAM_BENABLE | GAM_ENABLE)
+
+struct fmt_config {
+   u32 fourcc;
+
+   u32 pfe_cfg0_bps;
+   u32 cfa_baycfg;
+   u32 rlp_cfg_mode;
+   u32 dcfg_imode;
+   u32 dctrl_dview;
+
+   u32 bits_pipeline;
+};
 
 #define HIST_ENTRIES   512
 #define HIST_BAYER (ISC_HIS_CFG_MODE_B + 1)
@@ -181,80 +210,320 @@ struct isc_device {
struct list_headsubdev_entities;
 };
 
-#define RAW_FMT_IND_START0
-#define RAW_FMT_IND_END  11
-#define ISC_FMT_IND_START12
-#define ISC_FMT_IND_END  14
-
-static struct isc_format isc_formats[] = {
-   { V4L2_PIX_FMT_SBGGR8, MEDIA_BUS_FMT_SBGGR8_1X8, 8,
- ISC_PFE_CFG0_BPS_EIGHT, ISC_BAY_CFG_BGBG, ISC_RLP_CFG_MODE_DAT8,
- ISC_DCFG_IMODE_PACKED8, ISC_DCTRL_DVIEW_PACKED, 0x0,
- false, false },
-   { V4L2_PIX_FMT_SGBRG8, MEDIA_BUS_FMT_SGBRG8_1X8, 8,
- ISC_PFE_CFG0_BPS_EIGHT, ISC_BAY_CFG_GBGB, ISC_RLP_CFG_MODE_DAT8,
- ISC_DCFG_IMODE_PACKED8, ISC_DCTRL_DVIEW_PACKED, 0x0,
- false, false },
-   { V4L2_PIX_FMT_SGRBG8, MEDIA_BUS_FMT_SGRBG8_1X8, 8,
- ISC_PFE_CFG0_BPS_EIGHT, ISC_BAY_CFG_GRGR, ISC_RLP_CFG_MODE_DAT8,
- ISC_DCFG_IMODE_PACKED8, ISC_DCTRL_DVIEW_PACKED, 0x0,
- false, false },
-   { V4L2_PIX_FMT_SRGGB8, MEDIA_BUS_FMT_SRGGB8_1X8, 8,
- ISC_PFE_CFG0_BPS_EIGHT, ISC_BAY_CFG_RGRG, ISC_RLP_CFG_MODE_DAT8,
- ISC_DCFG_IMODE_PACKED8, ISC_DCTRL_DVIEW_PACKED, 0x0,
- false, false },
-
-   { V4L2_PIX_FMT_SBGGR10, MEDIA_BUS_FMT_SBGGR10_1X10, 16,
- ISC_PFG_CFG0_BPS_TEN, ISC_BAY_CFG_BGBG, ISC_RLP_CFG_MODE_DAT10,
- ISC_DCFG_IMODE_PACKED16, ISC_DCTRL_DVIEW_PACKED, 0x0,
- false, false },
-   { V4L2_PIX_FMT_SGBRG10, MEDIA_BUS_FMT_SGBRG10_1X10, 16,
- ISC_PFG

[PATCH v5 0/5] media: atmel-isc: Rework the format list and clock provider

2017-10-26 Thread Wenyou Yang
To improve the readability of code, rework the format list table,
split the format array into two. Meanwhile, fix the issue of the
clock provider operation and the pm runtime support.

Changes in v5:
 - Fix the clock ID which enters the runtime suspend should be
   ISC_ISPCK, instead of ISC_MCK for clk_prepare/clk_unprepare().
 - Fix the clock ID to ISC_ISPCK, instead of ISC_MCK for
   isc_clk_is_enabled().

Changes in v4:
 - Call pm_runtime_get_sync() and pm_runtime_put_sync() in ->prepare
   and ->unprepare callback.
 - Move pm_runtime_enable() call from the complete callback to the
   end of probe.
 - Call pm_runtime_get_sync() and pm_runtime_put_sync() in
   ->is_enabled() callbacks.
 - Call clk_disable_unprepare() in ->remove callback.

Changes in v3:
 - Fix the wrong used spinlock.
 - s/_/- on the subject.
 - Add a new flag for Raw Bayer format to remove MAX_RAW_FMT_INDEX define.
 - Add the comments for define of the format flag.
 - Rebase media_tree/master.

Changes in v2:
 - Add the new patch to remove the unnecessary member from
   isc_subdev_entity struct.
 - Rebase on the patch set,
[PATCH 0/6] [media] Atmel: Adjustments for seven function 
implementations
https://www.mail-archive.com/linux-media@vger.kernel.org/msg118342.html

Wenyou Yang (5):
  media: atmel-isc: Add spin lock for clock enable ops
  media: atmel-isc: Add prepare and unprepare ops
  media: atmel-isc: Enable the clocks during probe
  media: atmel-isc: Remove unnecessary member
  media: atmel-isc: Rework the format list

 drivers/media/platform/atmel/atmel-isc-regs.h |   1 +
 drivers/media/platform/atmel/atmel-isc.c  | 629 --
 2 files changed, 498 insertions(+), 132 deletions(-)

-- 
2.13.0



[PATCH v5 4/5] media: atmel-isc: Remove unnecessary member

2017-10-26 Thread Wenyou Yang
Remove the memeber *config from the isc_subdev_entity struct,
the member is useless afterward.

Signed-off-by: Wenyou Yang 
---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/media/platform/atmel/atmel-isc.c | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/media/platform/atmel/atmel-isc.c 
b/drivers/media/platform/atmel/atmel-isc.c
index 4431c27dfb09..a99796f7eb03 100644
--- a/drivers/media/platform/atmel/atmel-isc.c
+++ b/drivers/media/platform/atmel/atmel-isc.c
@@ -83,7 +83,6 @@ struct isc_subdev_entity {
struct v4l2_subdev  *sd;
struct v4l2_async_subdev*asd;
struct v4l2_async_notifier  notifier;
-   struct v4l2_subdev_pad_config   *config;
 
u32 pfe_cfg0;
 
@@ -1000,6 +999,7 @@ static int isc_try_fmt(struct isc_device *isc, struct 
v4l2_format *f,
 {
struct isc_format *isc_fmt;
struct v4l2_pix_format *pixfmt = &f->fmt.pix;
+   struct v4l2_subdev_pad_config pad_cfg;
struct v4l2_subdev_format format = {
.which = V4L2_SUBDEV_FORMAT_TRY,
};
@@ -1030,7 +1030,7 @@ static int isc_try_fmt(struct isc_device *isc, struct 
v4l2_format *f,
 
v4l2_fill_mbus_format(&format.format, pixfmt, mbus_code);
ret = v4l2_subdev_call(isc->current_subdev->sd, pad, set_fmt,
-  isc->current_subdev->config, &format);
+  &pad_cfg, &format);
if (ret < 0)
return ret;
 
@@ -1495,8 +1495,6 @@ static void isc_async_unbind(struct v4l2_async_notifier 
*notifier,
  struct isc_device, v4l2_dev);
cancel_work_sync(&isc->awb_work);
video_unregister_device(&isc->video_dev);
-   if (isc->current_subdev->config)
-   v4l2_subdev_free_pad_config(isc->current_subdev->config);
v4l2_ctrl_handler_free(&isc->ctrls.handler);
 }
 
@@ -1648,10 +1646,6 @@ static int isc_async_complete(struct v4l2_async_notifier 
*notifier)
INIT_LIST_HEAD(&isc->dma_queue);
spin_lock_init(&isc->dma_queue_lock);
 
-   sd_entity->config = v4l2_subdev_alloc_pad_config(sd_entity->sd);
-   if (!sd_entity->config)
-   return -ENOMEM;
-
ret = isc_formats_init(isc);
if (ret < 0) {
v4l2_err(&isc->v4l2_dev,
-- 
2.13.0



Re: [PATCH v4] f2fs: support soft block reservation

2017-10-26 Thread Chao Yu
On 2017/10/27 11:11, Yunlong Song wrote:
> It renames reserved_blocks sysfs interface to target_reserved_blocks,
> and supports to extend it to be soft threshold, which allows user
> configure it exceeding current available user space. So this patch
> also introduces a new sysfs interface called current_reserved_blocks to
> show the current blocks which have already been reserved.
> 
> Signed-off-by: Yunlong Song 
> Signed-off-by: Chao Yu 
> ---
>  Documentation/ABI/testing/sysfs-fs-f2fs | 15 +--
>  fs/f2fs/f2fs.h  | 15 ---
>  fs/f2fs/super.c |  5 +++--
>  fs/f2fs/sysfs.c | 20 +++-
>  4 files changed, 43 insertions(+), 12 deletions(-)
> 
> diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs 
> b/Documentation/ABI/testing/sysfs-fs-f2fs
> index 11b7f4e..482d78b 100644
> --- a/Documentation/ABI/testing/sysfs-fs-f2fs
> +++ b/Documentation/ABI/testing/sysfs-fs-f2fs
> @@ -134,11 +134,22 @@ Contact:"Sheng Yong" 
>  Description:
>Controls the injection type.
>  
> -What:/sys/fs/f2fs//reserved_blocks
> +What:/sys/fs/f2fs//target_reserved_blocks

For backward compatibility, how about keep this interface name, instead
just update its description?

Thanks,

>  Date:June 2017
>  Contact: "Chao Yu" 
>  Description:
> -  Controls current reserved blocks in system.
> +  Controls target reserved blocks in system, the threshold
> +  is soft, it could exceed current available user space.
> +
> +What:/sys/fs/f2fs//current_reserved_blocks
> +Date:October 2017
> +Contact: "Yunlong Song" 
> +Contact: "Chao Yu" 
> +Description:
> +  Shows current reserved blocks in system, it may be temporarily
> +  smaller than target_reserved_blocks, but will gradually
> +  increase to target_reserved_blocks when more free blocks are
> +  freed by user later.
>  
>  What:/sys/fs/f2fs//gc_urgent
>  Date:August 2017
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 13a96b8..c26fccb 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -1081,7 +1081,8 @@ struct f2fs_sb_info {
>   block_t total_valid_block_count;/* # of valid blocks */
>   block_t discard_blks;   /* discard command candidats */
>   block_t last_valid_block_count; /* for recovery */
> - block_t reserved_blocks;/* configurable reserved blocks 
> */
> + block_t target_reserved_blocks; /* configurable reserved blocks 
> */
> + block_t current_reserved_blocks;/* current reserved blocks */
>  
>   u32 s_next_generation;  /* for NFS support */
>  
> @@ -1557,7 +1558,8 @@ static inline int inc_valid_block_count(struct 
> f2fs_sb_info *sbi,
>  
>   spin_lock(&sbi->stat_lock);
>   sbi->total_valid_block_count += (block_t)(*count);
> - avail_user_block_count = sbi->user_block_count - sbi->reserved_blocks;
> + avail_user_block_count = sbi->user_block_count -
> + sbi->current_reserved_blocks;
>   if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) {
>   diff = sbi->total_valid_block_count - avail_user_block_count;
>   *count -= diff;
> @@ -1591,6 +1593,10 @@ static inline void dec_valid_block_count(struct 
> f2fs_sb_info *sbi,
>   f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count);
>   f2fs_bug_on(sbi, inode->i_blocks < sectors);
>   sbi->total_valid_block_count -= (block_t)count;
> + if (sbi->target_reserved_blocks &&
> + sbi->current_reserved_blocks < sbi->target_reserved_blocks)
> + sbi->current_reserved_blocks = min(sbi->target_reserved_blocks,
> + sbi->current_reserved_blocks + count);
>   spin_unlock(&sbi->stat_lock);
>   f2fs_i_blocks_write(inode, count, false, true);
>  }
> @@ -1737,7 +1743,7 @@ static inline int inc_valid_node_count(struct 
> f2fs_sb_info *sbi,
>   spin_lock(&sbi->stat_lock);
>  
>   valid_block_count = sbi->total_valid_block_count + 1;
> - if (unlikely(valid_block_count + sbi->reserved_blocks >
> + if (unlikely(valid_block_count + sbi->current_reserved_blocks >
>   sbi->user_block_count)) {
>   spin_unlock(&sbi->stat_lock);
>   goto enospc;
> @@ -1780,6 +1786,9 @@ static inline void dec_valid_node_count(struct 
> f2fs_sb_info *sbi,
>  
>   sbi->total_valid_node_count--;
>   sbi->total_valid_block_count--;
> + if (sbi->target_reserved_blocks &&
> + sbi->current_reserved_blocks < sbi->target_reserved_blocks)
> + sbi->current_reserved_blocks++;
>  
>   spin_unlock(&sbi->stat_lock);
>  
> diff --git a/fs/f

[PATCH v5 2/5] media: atmel-isc: Add prepare and unprepare ops

2017-10-26 Thread Wenyou Yang
A software write operation to the ISC_CLKEN or ISC_CLKDIS register
requires double clock domain synchronization and is not permitted
when the ISC_SR.SIP is asserted. So add the .prepare and .unprepare
ops to make sure the ISC_CLKSR.SIP is unasserted before the write
operation to the ISC_CLKEN or ISC_CLKDIS register.

Signed-off-by: Wenyou Yang 
---

Changes in v5:
 - Fix the clock ID which enters the runtime suspend should be
   ISC_ISPCK, instead of ISC_MCK for clk_prepare/clk_unprepare().

Changes in v4:
 - Call pm_runtime_get_sync() and pm_runtime_put_sync() in ->prepare
   and ->unprepare callback.

Changes in v3: None
Changes in v2: None

 drivers/media/platform/atmel/atmel-isc-regs.h |  1 +
 drivers/media/platform/atmel/atmel-isc.c  | 40 +++
 2 files changed, 41 insertions(+)

diff --git a/drivers/media/platform/atmel/atmel-isc-regs.h 
b/drivers/media/platform/atmel/atmel-isc-regs.h
index 6936ac467609..93e58fcf1d5f 100644
--- a/drivers/media/platform/atmel/atmel-isc-regs.h
+++ b/drivers/media/platform/atmel/atmel-isc-regs.h
@@ -42,6 +42,7 @@
 
 /* ISC Clock Status Register */
 #define ISC_CLKSR   0x0020
+#define ISC_CLKSR_SIP  BIT(31)
 
 #define ISC_CLK(n) BIT(n)
 
diff --git a/drivers/media/platform/atmel/atmel-isc.c 
b/drivers/media/platform/atmel/atmel-isc.c
index 991f962b7023..329ee8f256bb 100644
--- a/drivers/media/platform/atmel/atmel-isc.c
+++ b/drivers/media/platform/atmel/atmel-isc.c
@@ -308,6 +308,44 @@ module_param(sensor_preferred, uint, 0644);
 MODULE_PARM_DESC(sensor_preferred,
 "Sensor is preferred to output the specified format (1-on 
0-off), default 1");
 
+static int isc_wait_clk_stable(struct clk_hw *hw)
+{
+   struct isc_clk *isc_clk = to_isc_clk(hw);
+   struct regmap *regmap = isc_clk->regmap;
+   unsigned long timeout = jiffies + usecs_to_jiffies(1000);
+   unsigned int status;
+
+   while (time_before(jiffies, timeout)) {
+   regmap_read(regmap, ISC_CLKSR, &status);
+   if (!(status & ISC_CLKSR_SIP))
+   return 0;
+
+   usleep_range(10, 250);
+   }
+
+   return -ETIMEDOUT;
+}
+
+static int isc_clk_prepare(struct clk_hw *hw)
+{
+   struct isc_clk *isc_clk = to_isc_clk(hw);
+
+   if (isc_clk->id == ISC_ISPCK)
+   pm_runtime_get_sync(isc_clk->dev);
+
+   return isc_wait_clk_stable(hw);
+}
+
+static void isc_clk_unprepare(struct clk_hw *hw)
+{
+   struct isc_clk *isc_clk = to_isc_clk(hw);
+
+   isc_wait_clk_stable(hw);
+
+   if (isc_clk->id == ISC_ISPCK)
+   pm_runtime_put_sync(isc_clk->dev);
+}
+
 static int isc_clk_enable(struct clk_hw *hw)
 {
struct isc_clk *isc_clk = to_isc_clk(hw);
@@ -459,6 +497,8 @@ static int isc_clk_set_rate(struct clk_hw *hw,
 }
 
 static const struct clk_ops isc_clk_ops = {
+   .prepare= isc_clk_prepare,
+   .unprepare  = isc_clk_unprepare,
.enable = isc_clk_enable,
.disable= isc_clk_disable,
.is_enabled = isc_clk_is_enabled,
-- 
2.13.0



[PATCH v5 3/5] media: atmel-isc: Enable the clocks during probe

2017-10-26 Thread Wenyou Yang
To meet the relationship, enable the HCLOCK and ispck during the
device probe, "isc_pck frequency is less than or equal to isc_ispck,
and isc_ispck is greater than or equal to HCLOCK."
Meanwhile, call the pm_runtime_enable() in the right place.

Signed-off-by: Wenyou Yang 
---

Changes in v5:
 - Fix the clock ID to ISC_ISPCK, instead of ISC_MCK for
   isc_clk_is_enabled().

Changes in v4:
 - Move pm_runtime_enable() call from the complete callback to the
   end of probe.
 - Call pm_runtime_get_sync() and pm_runtime_put_sync() in
   ->is_enabled() callbacks.
 - Call clk_disable_unprepare() in ->remove callback.

Changes in v3: None
Changes in v2: None

 drivers/media/platform/atmel/atmel-isc.c | 34 
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/atmel/atmel-isc.c 
b/drivers/media/platform/atmel/atmel-isc.c
index 329ee8f256bb..4431c27dfb09 100644
--- a/drivers/media/platform/atmel/atmel-isc.c
+++ b/drivers/media/platform/atmel/atmel-isc.c
@@ -389,8 +389,14 @@ static int isc_clk_is_enabled(struct clk_hw *hw)
struct isc_clk *isc_clk = to_isc_clk(hw);
u32 status;
 
+   if (isc_clk->id == ISC_ISPCK)
+   pm_runtime_get_sync(isc_clk->dev);
+
regmap_read(isc_clk->regmap, ISC_CLKSR, &status);
 
+   if (isc_clk->id == ISC_ISPCK)
+   pm_runtime_put_sync(isc_clk->dev);
+
return status & ISC_CLK(isc_clk->id) ? 1 : 0;
 }
 
@@ -1866,25 +1872,37 @@ static int atmel_isc_probe(struct platform_device *pdev)
return ret;
}
 
+   ret = clk_prepare_enable(isc->hclock);
+   if (ret) {
+   dev_err(dev, "failed to enable hclock: %d\n", ret);
+   return ret;
+   }
+
ret = isc_clk_init(isc);
if (ret) {
dev_err(dev, "failed to init isc clock: %d\n", ret);
-   goto clean_isc_clk;
+   goto unprepare_hclk;
}
 
isc->ispck = isc->isc_clks[ISC_ISPCK].clk;
 
+   ret = clk_prepare_enable(isc->ispck);
+   if (ret) {
+   dev_err(dev, "failed to enable ispck: %d\n", ret);
+   goto unprepare_hclk;
+   }
+
/* ispck should be greater or equal to hclock */
ret = clk_set_rate(isc->ispck, clk_get_rate(isc->hclock));
if (ret) {
dev_err(dev, "failed to set ispck rate: %d\n", ret);
-   goto clean_isc_clk;
+   goto unprepare_clk;
}
 
ret = v4l2_device_register(dev, &isc->v4l2_dev);
if (ret) {
dev_err(dev, "unable to register v4l2 device.\n");
-   goto clean_isc_clk;
+   goto unprepare_clk;
}
 
ret = isc_parse_dt(dev, isc);
@@ -1917,7 +1935,9 @@ static int atmel_isc_probe(struct platform_device *pdev)
break;
}
 
+   pm_runtime_set_active(dev);
pm_runtime_enable(dev);
+   pm_request_idle(dev);
 
return 0;
 
@@ -1927,7 +1947,11 @@ static int atmel_isc_probe(struct platform_device *pdev)
 unregister_v4l2_device:
v4l2_device_unregister(&isc->v4l2_dev);
 
-clean_isc_clk:
+unprepare_clk:
+   clk_disable_unprepare(isc->ispck);
+unprepare_hclk:
+   clk_disable_unprepare(isc->hclock);
+
isc_clk_cleanup(isc);
 
return ret;
@@ -1938,6 +1962,8 @@ static int atmel_isc_remove(struct platform_device *pdev)
struct isc_device *isc = platform_get_drvdata(pdev);
 
pm_runtime_disable(&pdev->dev);
+   clk_disable_unprepare(isc->ispck);
+   clk_disable_unprepare(isc->hclock);
 
isc_subdev_cleanup(isc);
 
-- 
2.13.0



Re: [PATCH v6 2/9] clk: mediatek: Add dt-bindings for MT2712 clocks

2017-10-26 Thread Rob Herring
On Mon, Oct 23, 2017 at 12:10:33PM +0800, Weiyi Lu wrote:
> Add MT2712 clock dt-bindings, include topckgen, apmixedsys,
> infracfg, pericfg, mcucfg and subsystem clocks.
> 
> Signed-off-by: Weiyi Lu 
> ---
>  include/dt-bindings/clock/mt2712-clk.h | 427 
> +
>  1 file changed, 427 insertions(+)
>  create mode 100644 include/dt-bindings/clock/mt2712-clk.h

Acked-by: Rob Herring 


Re: [PATCH 01/10 v3] usb: usb251xb: Update usb251xb bindings

2017-10-26 Thread Rob Herring
On Sun, Oct 22, 2017 at 11:38:03PM +0300, Serge Semin wrote:
> Since hub usb2517 is going to be supported by the usb251xb driver,
> the bindings need to be properly updated. Particularly:
> - add "microchip,usb2517" and "microchip,usb2517i" compatible strings.
> - add "boolean" description to all the properties, which really accept
> a boolean value including a new one "led-{usb,speed}-mode".
> - move reset-gpios property to the optional section. It isn't
> defined as required in the code and shouldn't be required at all, since
> hardware may handle reset pins by itself.
> - add new led-{usb,speed}-mode mode property. USB2517 device supports
> two LED modes: USB mode and speed (default) indication mode. The last one
> can be switched on by this property.
> - add {bp,sp}-max-{total,removable}-current-microamp property measured in
> microamp. It hasn't been defined as property before. Since the limitation
> specified by these parameters is hardware specific it needs to be defined
> in dts.
> 
> Signed-off-by: Serge Semin 
> ---
>  .../devicetree/bindings/usb/usb251xb.txt   | 46 
> +++---
>  1 file changed, 32 insertions(+), 14 deletions(-)

Acked-by: Rob Herring 



Re: [PATCH v3 05/13] irqchip: add initial support for ompic

2017-10-26 Thread Rob Herring
On Sun, Oct 22, 2017 at 12:15:52PM +0900, Stafford Horne wrote:
> From: Stefan Kristiansson 
> 
> IPI driver for the Open Multi-Processor Interrupt Controller (ompic) as
> described in the Multi-core support section of the OpenRISC 1.2
> proposed architecture specification:
> 
>   
> https://github.com/stffrdhrn/doc/raw/arch-1.2-proposal/openrisc-arch-1.2-rev0.pdf
> 
> Each OpenRISC core contains a full interrupt controller which is used in
> the SMP architecture for interrupt balancing.  This IPI device, the
> ompic, is the only external device required for enabling SMP on
> OpenRISC.
> 
> Pending ops are stored in a memory bit mask which can allow multiple
> pending operations to be set and serviced at a time. This is mostly
> borrowed from the alpha IPI implementation.
> 
> Cc: Marc Zyngier 
> Cc: Rob Herring 
> Signed-off-by: Stefan Kristiansson 
> [sho...@gmail.com: converted ops to bitmask, wrote commit message]
> Signed-off-by: Stafford Horne 
> ---
> 
> Changes since v2
>  - Fixed some issues with missing static
>  - Fixed spelling issue with multi-core
>  - Added back #interrupt-cells
> 
> Changes since v1
>  - Added openrisc, prefix
>  - Clarified 8 bytes per cpu
>  - Removed #interrupt-cells as this will not be an irq parent
>  - Changed ops to be percpu
>  - Added DTS and intialization failure validations
> 
> 
>  .../interrupt-controller/openrisc,ompic.txt|  22 +++

Acked-by: Rob Herring 

>  MAINTAINERS|   1 +
>  arch/openrisc/Kconfig  |   1 +
>  drivers/irqchip/Kconfig|   3 +
>  drivers/irqchip/Makefile   |   1 +
>  drivers/irqchip/irq-ompic.c| 205 
> +
>  6 files changed, 233 insertions(+)
>  create mode 100644 
> Documentation/devicetree/bindings/interrupt-controller/openrisc,ompic.txt
>  create mode 100644 drivers/irqchip/irq-ompic.c


Re: [PATCH 3/3] openrisc: dts: Add OpenRISC platform SoC

2017-10-26 Thread Rob Herring
On Sun, Oct 22, 2017 at 11:46:41AM +0900, Stafford Horne wrote:
> Add devicetree binding documentation for the OpenRISC platform
> opencores,or1ksim.  This is the main OpenRISC reference platform
> supporting multiple FPGA SoC's.
> 
> This format is based on some of the mips binding docs as we have
> similar requirements.
> 
> Also, update maintainers so openrisc related binding changes are visible
> to the openrisc team.

Your subject is wrong because this is not a dts patch. Use 
"dt-bindings: openrisc: ..."

> 
> Suggested-by: Pavel Machek 
> Signed-off-by: Stafford Horne 
> ---
>  .../bindings/openrisc/opencores/or1ksim.txt| 39 
> ++
>  MAINTAINERS|  1 +
>  2 files changed, 40 insertions(+)
>  create mode 100644 
> Documentation/devicetree/bindings/openrisc/opencores/or1ksim.txt

Otherwise,

Acked-by: Rob Herring 



Re: [PATCH] display: panel: Add Tianma tm070rvhg71 display support (800x480)

2017-10-26 Thread Rob Herring
On Sat, Oct 21, 2017 at 12:10:03AM +0200, Lukasz Majewski wrote:
> Signed-off-by: Lukasz Majewski 
> ---
>  .../bindings/display/panel/tianma,tm070rvhg71.txt  |  7 ++
>  drivers/gpu/drm/panel/panel-simple.c   | 27 
> ++
>  2 files changed, 34 insertions(+)
>  create mode 100644 
> Documentation/devicetree/bindings/display/panel/tianma,tm070rvhg71.txt
> 
> diff --git 
> a/Documentation/devicetree/bindings/display/panel/tianma,tm070rvhg71.txt 
> b/Documentation/devicetree/bindings/display/panel/tianma,tm070rvhg71.txt
> new file mode 100644
> index 000..b84217f
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/display/panel/tianma,tm070rvhg71.txt
> @@ -0,0 +1,7 @@
> +Tianma Micro-electronics TM070RVHG71 7.0" WXGA TFT LCD panel
> +
> +Required properties:
> +- compatible: should be "tianma,tm070rvhg71
> +
> +This binding is compatible with the simple-panel binding, which is specified
> +in simple-panel.txt in this directory.

No supplies? Still need to list power-supply here if so, so it is clear 
that this display has a single supply (or you need to list multiple ones 
if not).

Rob


[PATCH v4] f2fs: support soft block reservation

2017-10-26 Thread Yunlong Song
It renames reserved_blocks sysfs interface to target_reserved_blocks,
and supports to extend it to be soft threshold, which allows user
configure it exceeding current available user space. So this patch
also introduces a new sysfs interface called current_reserved_blocks to
show the current blocks which have already been reserved.

Signed-off-by: Yunlong Song 
Signed-off-by: Chao Yu 
---
 Documentation/ABI/testing/sysfs-fs-f2fs | 15 +--
 fs/f2fs/f2fs.h  | 15 ---
 fs/f2fs/super.c |  5 +++--
 fs/f2fs/sysfs.c | 20 +++-
 4 files changed, 43 insertions(+), 12 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs 
b/Documentation/ABI/testing/sysfs-fs-f2fs
index 11b7f4e..482d78b 100644
--- a/Documentation/ABI/testing/sysfs-fs-f2fs
+++ b/Documentation/ABI/testing/sysfs-fs-f2fs
@@ -134,11 +134,22 @@ Contact:  "Sheng Yong" 
 Description:
 Controls the injection type.
 
-What:  /sys/fs/f2fs//reserved_blocks
+What:  /sys/fs/f2fs//target_reserved_blocks
 Date:  June 2017
 Contact:   "Chao Yu" 
 Description:
-Controls current reserved blocks in system.
+Controls target reserved blocks in system, the threshold
+is soft, it could exceed current available user space.
+
+What:  /sys/fs/f2fs//current_reserved_blocks
+Date:  October 2017
+Contact:   "Yunlong Song" 
+Contact:   "Chao Yu" 
+Description:
+Shows current reserved blocks in system, it may be temporarily
+smaller than target_reserved_blocks, but will gradually
+increase to target_reserved_blocks when more free blocks are
+freed by user later.
 
 What:  /sys/fs/f2fs//gc_urgent
 Date:  August 2017
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 13a96b8..c26fccb 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1081,7 +1081,8 @@ struct f2fs_sb_info {
block_t total_valid_block_count;/* # of valid blocks */
block_t discard_blks;   /* discard command candidats */
block_t last_valid_block_count; /* for recovery */
-   block_t reserved_blocks;/* configurable reserved blocks 
*/
+   block_t target_reserved_blocks; /* configurable reserved blocks 
*/
+   block_t current_reserved_blocks;/* current reserved blocks */
 
u32 s_next_generation;  /* for NFS support */
 
@@ -1557,7 +1558,8 @@ static inline int inc_valid_block_count(struct 
f2fs_sb_info *sbi,
 
spin_lock(&sbi->stat_lock);
sbi->total_valid_block_count += (block_t)(*count);
-   avail_user_block_count = sbi->user_block_count - sbi->reserved_blocks;
+   avail_user_block_count = sbi->user_block_count -
+   sbi->current_reserved_blocks;
if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) {
diff = sbi->total_valid_block_count - avail_user_block_count;
*count -= diff;
@@ -1591,6 +1593,10 @@ static inline void dec_valid_block_count(struct 
f2fs_sb_info *sbi,
f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count);
f2fs_bug_on(sbi, inode->i_blocks < sectors);
sbi->total_valid_block_count -= (block_t)count;
+   if (sbi->target_reserved_blocks &&
+   sbi->current_reserved_blocks < sbi->target_reserved_blocks)
+   sbi->current_reserved_blocks = min(sbi->target_reserved_blocks,
+   sbi->current_reserved_blocks + count);
spin_unlock(&sbi->stat_lock);
f2fs_i_blocks_write(inode, count, false, true);
 }
@@ -1737,7 +1743,7 @@ static inline int inc_valid_node_count(struct 
f2fs_sb_info *sbi,
spin_lock(&sbi->stat_lock);
 
valid_block_count = sbi->total_valid_block_count + 1;
-   if (unlikely(valid_block_count + sbi->reserved_blocks >
+   if (unlikely(valid_block_count + sbi->current_reserved_blocks >
sbi->user_block_count)) {
spin_unlock(&sbi->stat_lock);
goto enospc;
@@ -1780,6 +1786,9 @@ static inline void dec_valid_node_count(struct 
f2fs_sb_info *sbi,
 
sbi->total_valid_node_count--;
sbi->total_valid_block_count--;
+   if (sbi->target_reserved_blocks &&
+   sbi->current_reserved_blocks < sbi->target_reserved_blocks)
+   sbi->current_reserved_blocks++;
 
spin_unlock(&sbi->stat_lock);
 
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 213d2c1..c682978 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -987,7 +987,7 @@ static int f2fs_statfs(struct dentry *dentry, struct 
kstatfs *buf)
buf->f_blocks = total_count - start_count;
buf->f_bfree = user_block_count - valid_user_blocks(sbi) + ovp_cou

Re: [PATCH] drivers/net: wan/dscc4: Remove unused timer

2017-10-26 Thread David Miller
From: Kees Cook 
Date: Wed, 25 Oct 2017 03:53:42 -0700

> This removes an entirely unused timer, which avoids needing to convert it
> to timer_setup().
> 
> Cc: Francois Romieu 
> Cc: net...@vger.kernel.org
> Signed-off-by: Kees Cook 

Applied.


Re: [PATCH] drivers/net: arcnet: Convert timers to use timer_setup()

2017-10-26 Thread David Miller
From: Kees Cook 
Date: Wed, 25 Oct 2017 03:54:06 -0700

> In preparation for unconditionally passing the struct timer_list pointer to
> all timer callbacks, switch to using the new timer_setup() and from_timer()
> to pass the timer pointer explicitly.
> 
> Cc: Michael Grzeschik 
> Cc: net...@vger.kernel.org
> Signed-off-by: Kees Cook 

Applied.


Re: [PATCH] drivers/net: wan/sdla: Convert timers to use timer_setup()

2017-10-26 Thread David Miller
From: Kees Cook 
Date: Wed, 25 Oct 2017 03:53:59 -0700

> In preparation for unconditionally passing the struct timer_list pointer to
> all timer callbacks, switch to using the new timer_setup() and from_timer()
> to pass the timer pointer explicitly.
> 
> Cc: Allen Pais 
> Cc: "David S. Miller" 
> Cc: Tobias Klauser 
> Cc: net...@vger.kernel.org
> Signed-off-by: Kees Cook 

Applied.


Re: [PATCH] drivers/net: wan/lmc: Convert timers to use timer_setup()

2017-10-26 Thread David Miller
From: Kees Cook 
Date: Wed, 25 Oct 2017 03:53:53 -0700

> In preparation for unconditionally passing the struct timer_list pointer to
> all timer callbacks, switch to using the new timer_setup() and from_timer()
> to pass the timer pointer explicitly.
> 
> Cc: Allen Pais 
> Cc: "David S. Miller" 
> Cc: net...@vger.kernel.org
> Signed-off-by: Kees Cook 

Applied.


Re: [PATCH v5 3/5] Documentation: Add device tree binding for Goldfish FB driver

2017-10-26 Thread Rob Herring
On Fri, Oct 20, 2017 at 04:33:36PM +0200, Aleksandar Markovic wrote:
> From: Aleksandar Markovic 
> 
> Add documentation for DT binding of Goldfish FB driver. The compatible
> string used by OS for binding the driver is "google,goldfish-fb".
> 
> Signed-off-by: Miodrag Dinic 
> Signed-off-by: Goran Ferenc 
> Signed-off-by: Aleksandar Markovic 
> ---
>  .../devicetree/bindings/display/google,goldfish-fb.txt | 18 
> ++
>  1 file changed, 18 insertions(+)
>  create mode 100644 
> Documentation/devicetree/bindings/display/google,goldfish-fb.txt
> 
> diff --git a/Documentation/devicetree/bindings/display/google,goldfish-fb.txt 
> b/Documentation/devicetree/bindings/display/google,goldfish-fb.txt
> new file mode 100644
> index 000..9ce0615
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/display/google,goldfish-fb.txt
> @@ -0,0 +1,18 @@
> +Android Goldfish framebuffer
> +
> +Android Goldfish framebuffer device used by Android emulator.
> +
> +Required properties:
> +
> +- compatible : should contain "google,goldfish-fb"
> +- reg: 
> +- interrupts : 
> +
> +Example:
> +
> + goldfish_fb@1f008000 {

Use generic node names:

display-controller@...

With that,

Acked-by: Rob Herring 


> + compatible = "google,goldfish-fb";
> + interrupts = <0x10>;
> + reg = <0x1f008000 0x0 0x100>;

An address of one cell and size of 2 cells is strange...

> + compatible = "google,goldfish-fb";
> + };
> -- 
> 2.7.4
> 


Re: [PATCH] drivers/net: nuvoton: Convert timers to use timer_setup()

2017-10-26 Thread David Miller
From: Kees Cook 
Date: Wed, 25 Oct 2017 03:51:58 -0700

> In preparation for unconditionally passing the struct timer_list pointer to
> all timer callbacks, switch to using the new timer_setup() and from_timer()
> to pass the timer pointer explicitly.
> 
> Cc: Wan ZongShun 
> Cc: linux-arm-ker...@lists.infradead.org
> Cc: net...@vger.kernel.org
> Signed-off-by: Kees Cook 

Applied.


Re: [PATCH] drivers/net: realtek: Convert timers to use timer_setup()

2017-10-26 Thread David Miller
From: Kees Cook 
Date: Wed, 25 Oct 2017 03:53:12 -0700

> In preparation for unconditionally passing the struct timer_list pointer to
> all timer callbacks, switch to using the new timer_setup() and from_timer()
> to pass the timer pointer explicitly.
> 
> Cc: Realtek linux nic maintainers 
> Cc: "David S. Miller" 
> Cc: David Howells 
> Cc: Jay Vosburgh 
> Cc: Allen Pais 
> Cc: Eric Dumazet 
> Cc: Tobias Klauser 
> Cc: net...@vger.kernel.org
> Signed-off-by: Kees Cook 

Applied.


Re: [PATCH] drivers/net: hamradio/yam: Convert timers to use timer_setup()

2017-10-26 Thread David Miller
From: Kees Cook 
Date: Wed, 25 Oct 2017 03:51:20 -0700

> In preparation for unconditionally passing the struct timer_list pointer to
> all timer callbacks, switch to using the new timer_setup() and from_timer()
> to pass the timer pointer explicitly. Initialization was entirely missing.
> 
> Cc: Jean-Paul Roubelat 
> Cc: linux-h...@vger.kernel.org
> Cc: net...@vger.kernel.org
> Signed-off-by: Kees Cook 

Applied.


Re: [PATCH] drivers/net: 3com/3c515: Convert timers to use timer_setup()

2017-10-26 Thread David Miller
From: Kees Cook 
Date: Wed, 25 Oct 2017 03:51:03 -0700

> In preparation for unconditionally passing the struct timer_list pointer to
> all timer callbacks, switch to using the new timer_setup() and from_timer()
> to pass the timer pointer explicitly.
> 
> Cc: "David S. Miller" 
> Cc: Thomas Gleixner 
> Cc: Stephen Hemminger 
> Cc: Johannes Berg 
> Cc: net...@vger.kernel.org
> Signed-off-by: Kees Cook 

Applied.


Re: [PATCH] drivers/net: sxgbe: Convert timers to use timer_setup()

2017-10-26 Thread David Miller
From: Kees Cook 
Date: Wed, 25 Oct 2017 03:53:20 -0700

> In preparation for unconditionally passing the struct timer_list pointer to
> all timer callbacks, switch to using the new timer_setup() and from_timer()
> to pass the timer pointer explicitly.
> 
> Cc: Byungho An 
> Cc: Girish K S 
> Cc: Vipul Pandya 
> Cc: net...@vger.kernel.org
> Signed-off-by: Kees Cook 

Applied.


Re: [PATCH] drivers/net: can: Convert timers to use timer_setup()

2017-10-26 Thread David Miller
From: Kees Cook 
Date: Wed, 25 Oct 2017 03:51:14 -0700

> In preparation for unconditionally passing the struct timer_list pointer to
> all timer callbacks, switch to using the new timer_setup() and from_timer()
> to pass the timer pointer explicitly.
> 
> Cc: Wolfgang Grandegger 
> Cc: Marc Kleine-Budde 
> Cc: "David S. Miller" 
> Cc: Allen Pais 
> Cc: linux-...@vger.kernel.org
> Cc: net...@vger.kernel.org
> Signed-off-by: Kees Cook 

Applied.


Re: [PATCH] drivers/net: netronome: Convert timers to use timer_setup()

2017-10-26 Thread David Miller
From: Kees Cook 
Date: Wed, 25 Oct 2017 03:51:38 -0700

> In preparation for unconditionally passing the struct timer_list pointer to
> all timer callbacks, switch to using the new timer_setup() and from_timer()
> to pass the timer pointer explicitly.
> 
> Cc: Jakub Kicinski 
> Cc: "David S. Miller" 
> Cc: Jiri Pirko 
> Cc: Jamal Hadi Salim 
> Cc: Simon Horman 
> Cc: oss-driv...@netronome.com
> Cc: net...@vger.kernel.org
> Signed-off-by: Kees Cook 

Applied.


Re: [PATCH] drivers/net: hippi: Convert timers to use timer_setup()

2017-10-26 Thread David Miller
From: Kees Cook 
Date: Wed, 25 Oct 2017 03:51:29 -0700

> In preparation for unconditionally passing the struct timer_list pointer to
> all timer callbacks, switch to using the new timer_setup() and from_timer()
> to pass the timer pointer explicitly.
> 
> Cc: Jes Sorensen 
> Cc: linux-hi...@sunsite.dk
> Cc: net...@vger.kernel.org
> Signed-off-by: Kees Cook 

Applied.


Re: [PATCH v5 1/5] Documentation: Add device tree binding for Goldfish PIC driver

2017-10-26 Thread Rob Herring
On Fri, Oct 20, 2017 at 04:33:34PM +0200, Aleksandar Markovic wrote:
> From: Miodrag Dinic 
> 
> Add documentation for DT binding of Goldfish PIC driver. The compatible
> string used by OS for binding the driver is "google,goldfish-pic".
> 
> Signed-off-by: Miodrag Dinic 
> Signed-off-by: Goran Ferenc 
> Signed-off-by: Aleksandar Markovic 
> ---
>  .../interrupt-controller/google,goldfish-pic.txt   | 30 
> ++
>  MAINTAINERS|  5 
>  2 files changed, 35 insertions(+)
>  create mode 100644 
> Documentation/devicetree/bindings/interrupt-controller/google,goldfish-pic.txt
> 
> diff --git 
> a/Documentation/devicetree/bindings/interrupt-controller/google,goldfish-pic.txt
>  
> b/Documentation/devicetree/bindings/interrupt-controller/google,goldfish-pic.txt
> new file mode 100644
> index 000..295bf97
> --- /dev/null
> +++ 
> b/Documentation/devicetree/bindings/interrupt-controller/google,goldfish-pic.txt
> @@ -0,0 +1,30 @@
> +Android Goldfish PIC
> +
> +Android Goldfish programmable interrupt device used by Android
> +emulator.
> +
> +Required properties:
> +
> +- compatible : should contain "google,goldfish-pic"
> +- reg: 
> +- interrupts : 
> +
> +Example for mips when used in cascade mode:
> +
> +cpuintc {
> +#interrupt-cells = <0x1>;
> +#address-cells = <0>;
> +interrupt-controller;
> +compatible = "mti,cpu-interrupt-controller";
> +};
> +
> +goldfish_pic@1f00 {

interrupt-controller@...

With that,

Acked-by: Rob Herring 

> +compatible = "google,goldfish-pic";
> +reg = <0x1f00 0x0 0x1000>;
> +
> +interrupt-controller;
> +#interrupt-cells = <0x1>;
> +
> +interrupt-parent = <&cpuintc>;
> +interrupts = <0x2>;
> +};
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 4a3de82..4d5108f 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -872,6 +872,11 @@ S:   Supported
>  F:   drivers/android/
>  F:   drivers/staging/android/
>  
> +ANDROID GOLDFISH PIC DRIVER
> +M:   Miodrag Dinic 
> +S:   Supported
> +F:   
> Documentation/devicetree/bindings/interrupt-controller/google,goldfish-pic.txt
> +
>  ANDROID GOLDFISH RTC DRIVER
>  M:   Miodrag Dinic 
>  S:   Supported
> -- 
> 2.7.4
> 


Re: [RFC PATCH v8 1/7] dt-bindings: PCI: Add definition of PCIe WAKE# irq and PCI irq

2017-10-26 Thread jeffy

Hi Brian,

On 10/27/2017 10:33 AM, Brian Norris wrote:

On Thu, Oct 26, 2017 at 09:28:34PM +0800, Jeffy Chen wrote:

Add optional interrupts for PCIe WAKE# pin and PCI interrupt pin.

Signed-off-by: Jeffy Chen 
---

Changes in v8:
Add optional "pci", and rewrite commit message.

Changes in v7: None
Changes in v6: None
Changes in v5:
Move to pci.txt

Changes in v3: None
Changes in v2: None

  Documentation/devicetree/bindings/pci/pci.txt | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/Documentation/devicetree/bindings/pci/pci.txt 
b/Documentation/devicetree/bindings/pci/pci.txt
index c77981c5dd18..faed405811cd 100644
--- a/Documentation/devicetree/bindings/pci/pci.txt
+++ b/Documentation/devicetree/bindings/pci/pci.txt
@@ -24,3 +24,6 @@ driver implementation may support the following properties:
 unsupported link speed, for instance, trying to do training for
 unsupported link speed, etc.  Must be '4' for gen4, '3' for gen3, '2'
 for gen2, and '1' for gen1. Any other values are invalid.
+- interrupts: Interrupt specifier for each name in interrupt-names.
+- interrupt-names: May contains "wakeup" for PCIe WAKE# interrupt and "pci"
+  for PCI interrupt.


Similar criticism to what Rob made on patch 4: this file already says "a
host bridge driver implementation may support the following properties",
so this property is clearly not for child devices. And so having the
"PCI interrupt" here doesn't make much sense.

Similarly, you're documenting "wakeup" here as a host bridge property,
but then patch 7 is adding per-device support it seems? That seems
wrong.
oops...so there's no section for PCI device here, maybe i should add a 
section about "PCI device have standardized Device Tree bindings:" to 
place it? will do in next version.





In fact, I'm pretty sure this series fails to actually look in the host
bridge for the "wakeup" interrupt at all! Did you actually test this?

actually it could...

static void *of_pci_setup(struct device *dev)
{
...
device_init_wakeup(dev, false);

dev_info(dev, "Wakeup IRQ %d\n", irq);
return data;
}

[1.546561] OF: PCI:   MEM 0xfa00..0xfbdf -> 0xfa00
[1.553154] OF: PCI:IO 0xfbe0..0xfbef -> 0xfbe0
[1.560859] rockchip-pcie f800.pcie: Wakeup IRQ 64
[1.566555] rockchip-pcie f800.pcie: PCI host bridge to bus



And again, describing your intentions a little better in the commit
message would make this clearer. Then we could tell which way you
intended this to work...

ok, will do in next version...


Brian








[PATCH V2 net] tuntap: properly align skb->head before building skb

2017-10-26 Thread Jason Wang
An unaligned alloc_frag->offset caused by previous allocation will
result an unaligned skb->head. This will lead unaligned
skb_shared_info and then unaligned dataref which requires to be
aligned for accessing on some architecture. Fix this by aligning
alloc_frag->offset before the frag refilling.

Fixes: 0bbd7dad34f8 ("tun: make tun_build_skb() thread safe")
Cc: Eric Dumazet 
Cc: Willem de Bruijn 
Cc: Wei Wei 
Cc: Dmitry Vyukov 
Cc: Mark Rutland 
Reported-by: Wei Wei 
Signed-off-by: Jason Wang 
---
- The patch is needed for -stable.
- Wei, can you try this patch to see if it solves your issue?
---
 drivers/net/tun.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index b9973fb..5550f56 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1286,6 +1286,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct 
*tun,
buflen += SKB_DATA_ALIGN(len + pad);
rcu_read_unlock();
 
+   alloc_frag->offset = ALIGN((u64)alloc_frag->offset, SMP_CACHE_BYTES);
if (unlikely(!skb_page_frag_refill(buflen, alloc_frag, GFP_KERNEL)))
return ERR_PTR(-ENOMEM);
 
-- 
2.7.4



Re:Re: [PATCH] power: supply: 88pm860x_battery array_soc first number is in mV

2017-10-26 Thread 刘稳










At 2017-10-26 12:41:18, "Joe Perches"  wrote:
>On Thu, 2017-10-26 at 13:21 +0800, winton.liu wrote:
>> Fix wrong comments of array_soc description.
>> First number is mV not mAh.
>[]
>> diff --git a/drivers/power/supply/88pm860x_battery.c 
>> b/drivers/power/supply/88pm860x_battery.c
>[]
>> @@ -123,7 +123,7 @@ struct ccnt {
>>  
>>  /*
>>   * State of Charge.
>> - * The first number is mAh(=3.6C), and the second number is percent point.
>> + * The first number is mV, and the second number is percent point.
>>   */
>>  static int array_soc[][2] = {
>>  {4170, 100}, {4154, 99}, {4136, 98}, {4122, 97}, {4107, 96},
>
>OK, but why not change the declaration to a struct
>and make it obvious?
>
>Also, the array or struct should be const.
>
Yes, using a struct makes it more readable.

>Perhaps:
>---
> drivers/power/supply/88pm860x_battery.c | 13 -
> 1 file changed, 8 insertions(+), 5 deletions(-)
>
>diff --git a/drivers/power/supply/88pm860x_battery.c 
>b/drivers/power/supply/88pm860x_battery.c
>index 63c57dc82ac1..973c5f7b07ba 100644
>--- a/drivers/power/supply/88pm860x_battery.c
>+++ b/drivers/power/supply/88pm860x_battery.c
>@@ -123,9 +123,12 @@ struct ccnt {
> 
> /*
>  * State of Charge.
>- * The first number is mAh(=3.6C), and the second number is percent point.
>+ * The first number is mV(=3.6C), and the second number is percent point3..
   '(=3.6C)' is not needed. 1mAh = 1mA *3600s = 3.6C. As first number is 
mV, 3.6C is not needed.
>  */
>-static int array_soc[][2] = {
>+static const struct {
>+  u16 mv;
>+  u8 percent;
>+} array_soc[] = {
>   {4170, 100}, {4154, 99}, {4136, 98}, {4122, 97}, {4107, 96},
>   {4102, 95}, {4088, 94}, {4081, 93}, {4070, 92}, {4060, 91},
>   {4053, 90}, {4044, 89}, {4035, 88}, {4028, 87}, {4019, 86},
>@@ -388,14 +391,14 @@ static int calc_soc(struct pm860x_battery_info *info, 
>int state, int *soc)
>   return ret;
> 
>   count = ARRAY_SIZE(array_soc);
>-  if (ocv < array_soc[count - 1][0]) {
>+  if (ocv < array_soc[count - 1].mv) {
>   *soc = 0;
>   return 0;
>   }
> 
>   for (i = 0; i < count; i++) {
>-  if (ocv >= array_soc[i][0]) {
>-  *soc = array_soc[i][1];
>+  if (ocv >= array_soc[i].mv) {
>+  *soc = array_soc[i].percent;
>   break;
>   }
>   }
>


Re: [PATCH net] tuntap: properly align skb->head before building skb

2017-10-26 Thread Jason Wang



On 2017年10月26日 22:11, Eric Dumazet wrote:

On Thu, Oct 26, 2017 at 5:15 AM, Jason Wang  wrote:

An unaligned alloc_frag->offset caused by previous allocation will
result an unaligned skb->head. This will lead unaligned
skb_shared_info and then unaligned dataref which requires to be
aligned for accessing on some architecture. Fix this by aligning
alloc_frag->offset before the frag refilling.

Fixes: 0bbd7dad34f8 ("tun: make tun_build_skb() thread safe")
Cc: Eric Dumazet 
Cc: Willem de Bruijn 
Cc: Wei Wei 
Cc: Dmitry Vyukov 
Cc: Mark Rutland 
Reported-by: Wei Wei 
Signed-off-by: Jason Wang 
---
- The patch is needed for -stable.
- Wei, can you try this patch to see if it solves your issue?
---
  drivers/net/tun.c | 1 +
  1 file changed, 1 insertion(+)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index b9973fb..60e44f2 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1286,6 +1286,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct 
*tun,
 buflen += SKB_DATA_ALIGN(len + pad);
 rcu_read_unlock();

+   alloc_frag->offset = ALIGN((u64)alloc_frag->offset, TUN_RX_PAD);

You have to align to one cache line (SMP_CACHE_BYTES), or SKB_DATA_ALIGN(1)


Oh right.


Then eventually use skb_reserve() for NET_IP_ALIGN, but I guess it is
already done.


Yes.

Thanks


Re: [PATCH] thunderbolt: Drop sequence number check from tb_xdomain_match()

2017-10-26 Thread David Miller
From: Mika Westerberg 
Date: Wed, 25 Oct 2017 12:27:34 +0300

> Commit 9a03c3d398c1 ("thunderbolt: Fix a couple right shifting to zero
> bugs") revealed an issue that was previously hidden because we never
> actually compared received XDomain message sequence numbers properly.
> The idea with these sequence numbers is that the responding host uses
> the same sequence number that was in the request packet which we can
> then check at the requesting host.
> 
> However, testing against macOS it looks like it does not follow this but
> instead uses some other logic. Windows driver on the other hand handles
> it the same way than Linux.
> 
> In order to be able to talk to macOS again, fix this so that we drop the
> whole sequence number check. This effectively works exactly the same
> than it worked before the aforementioned commit. This also follows the
> logic the original P2P networking code used.
> 
> Signed-off-by: Mika Westerberg 
> ---
> This applies on top of net-next.git/master.

Applied, thank you.


Re: [PATCH v9 00/10] net: stmmac: dwmac-sun8i: Handle integrated PHY

2017-10-26 Thread David Miller
From: Corentin Labbe 
Date: Tue, 24 Oct 2017 19:57:04 +0200

> The first 7 patch should go via the sunxi tree, the last three via
> the net tree.

I've applied the last 3 patches to net-next.


[PATCH net-next] stmmac: copy unicast mac address to MAC registers

2017-10-26 Thread Bhadram Varka
Currently stmmac driver not copying the valid ethernet
MAC address to MAC registers. This patch takes care
of updating the MAC register with MAC address.

Signed-off-by: Bhadram Varka 
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 0e1b0a3..e0e6348 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -3748,6 +3748,20 @@ static int stmmac_ioctl(struct net_device *dev, struct 
ifreq *rq, int cmd)
return ret;
 }
 
+static int stmmac_set_mac_address(struct net_device *ndev, void *addr)
+{
+   struct stmmac_priv *priv = netdev_priv(ndev);
+   int ret = 0;
+
+   ret = eth_mac_addr(ndev, addr);
+   if (ret)
+   return ret;
+
+   priv->hw->mac->set_umac_addr(priv->hw, ndev->dev_addr, 0);
+
+   return ret;
+}
+
 #ifdef CONFIG_DEBUG_FS
 static struct dentry *stmmac_fs_dir;
 
@@ -3975,7 +3989,7 @@ static const struct net_device_ops stmmac_netdev_ops = {
 #ifdef CONFIG_NET_POLL_CONTROLLER
.ndo_poll_controller = stmmac_poll_controller,
 #endif
-   .ndo_set_mac_address = eth_mac_addr,
+   .ndo_set_mac_address = stmmac_set_mac_address,
 };
 
 /**
-- 
2.7.4



RE: [PATCH v4] Add /proc/PID/smaps support for DAX

2017-10-26 Thread Du, Fan


>-Original Message-
>From: linux-kernel-ow...@vger.kernel.org
>[mailto:linux-kernel-ow...@vger.kernel.org] On Behalf Of Dan Williams
>Sent: Thursday, October 26, 2017 5:17 PM
>To: Du, Fan 
>Cc: Andrew Morton ; Christoph Hellwig
>; Hansen, Dave ; Michal Hocko
>; linux-kernel@vger.kernel.org
>Subject: Re: [PATCH v4] Add /proc/PID/smaps support for DAX
>
>On Wed, Oct 25, 2017 at 10:13 PM, Fan Du  wrote:
>>
>> Memory behind device DAX is not attached into normal memory
>> management system, when user mmap /dev/dax, smaps part is
>> currently missing, so no idea for user to check how much
>> device DAX memory are actually used in practice.
>>
>> Whether vma is backed up by normal page,huge page, or both
>> at the same time, this makes no difference for device DAX
>> user so far.
>>
>> Using existing smaps structure is enough to do the job, so
>> this patch tries to use existing RSS/PSS stuff for statistics.
>> An example reading is like this:
>> 
>> 7f30fe20-7f310220 rw-s  00:06 19567
>/dev/dax12.0
>> Size:  65536 kB
>> KernelPageSize:4 kB
>> MMUPageSize:   4 kB
>> Rss:   65536 kB
>> Pss:   65536 kB
>> Shared_Clean:  0 kB
>> Shared_Dirty:  0 kB
>> Private_Clean: 0 kB
>> Private_Dirty: 65536 kB
>> Referenced:65536 kB
>> Anonymous: 0 kB
>> LazyFree:  0 kB
>> AnonHugePages: 0 kB
>> ShmemPmdMapped:0 kB
>> Shared_Hugetlb:0 kB
>> Private_Hugetlb:   0 kB
>> Swap:  0 kB
>> SwapPss:   0 kB
>> Locked:65536 kB
>> ProtectionKey: 0
>> VmFlags: rd wr sh mr mw me ms mm hg
>>
>> Signed-off-by: Fan Du 
>> ---
>> v4:
>> * Merge device DAX readings into existing smap counters
>>   for simplicity.
>>
>> v3:
>> * Elaborate more about the usage suggested by Michal Hocko
>>
>> v2:
>> * Using pte_devmap to check valid pfn page structure,
>>   Pointed out by Dan. thx!
>>  fs/proc/task_mmu.c | 74
>--
>>  1 file changed, 72 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
>> index 5589b4b..9b2d3e6 100644
>> --- a/fs/proc/task_mmu.c
>> +++ b/fs/proc/task_mmu.c
>> @@ -507,6 +507,55 @@ static void smaps_account(struct mem_size_stats
>*mss, struct page *page,
>> }
>>  }
>>
>> +/* page structure behind DAX mappings is NOT compound page
>> + * when it's a huge page mappings, so introduce new API to
>> + * account for both PMD and PUD mapping.
>> + */
>> +static void smaps_account_dax_huge(struct mem_size_stats *mss,
>> +   struct page *page, unsigned long size, bool
>young, bool dirty)
>> +{
>> +   int mapcount = page_mapcount(page);
>> +
>> +   if (PageAnon(page)) {
>> +   mss->anonymous += size;
>> +   if (!PageSwapBacked(page) && !dirty
>&& !PageDirty(page))
>> +   mss->lazyfree += size;
>> +   }
>> +
>> +   mss->resident += size;
>> +   /* Accumulate the size in pages that have been accessed. */
>> +   if (young || page_is_young(page) || PageReferenced(page))
>> +   mss->referenced += size;
>> +
>> +   /*
>> +* page_count(page) == 1 guarantees the page is mapped exactly
>once.
>> +* If any subpage of the compound page mapped with PTE it
>would elevate
>> +* page_count().
>> +*/
>> +   if (page_count(page) == 1) {
>> +   if (dirty || PageDirty(page))
>> +   mss->private_dirty += size;
>> +   else
>> +   mss->private_clean += size;
>> +   mss->pss += (u64)size << PSS_SHIFT;
>> +   return;
>> +   }
>> +
>> +   if (mapcount >= 2) {
>> +   if (dirty || PageDirty(page))
>> +   mss->shared_dirty += size;
>> +   else
>> +   mss->shared_clean += size;
>> +   mss->pss += (size << PSS_SHIFT) / mapcount;
>> +   } else {
>> +   if (dirty || PageDirty(page))
>> +   mss->private_dirty += size;
>> +   else
>> +   mss->private_clean += size;
>> +   mss->pss += size << PSS_SHIFT;
>> +   }
>> +}
>> +
>>  #ifdef CONFIG_SHMEM
>>  static int smaps_pte_hole(unsigned long addr, unsigned long end,
>> struct mm_walk *walk)
>> @@ -528,7 +577,16 @@ static void smaps_pte_entry(pte_t *pte, unsigned
>long addr,
>> struct page *page = NULL;
>>
>> if (pte_present(*pte)) {
>> -   page = vm_normal_page(vma, addr, *pte);
>> +   if (!vma_is_dax(vma))
>> +   page = vm_normal_page(vma, addr, *pte);
>> +   else if (pte_devmap(*pte)) {
>> +   struct dev_pagemap *pgmap;
>> +
>> +   pgmap = get_dev_pagemap(pt

RE: [PATCH v4] Add /proc/PID/smaps support for DAX

2017-10-26 Thread Du, Fan


>-Original Message-
>From: Hansen, Dave
>Sent: Thursday, October 26, 2017 10:03 PM
>To: Du, Fan ; a...@linux-foundation.org; h...@lst.de;
>Williams, Dan J ; mho...@kernel.org
>Cc: linux-kernel@vger.kernel.org
>Subject: Re: [PATCH v4] Add /proc/PID/smaps support for DAX
>
>I'm honestly not understanding what problem this solves.  Could you,
>perhaps, do a before and after of smaps with and without this patch?

The motivation here is described in the commit message.
--
Memory behind device DAX is not attached into normal memory
management system, when user mmap /dev/dax, smaps part is
currently missing, so no idea for user to check how much
device DAX memory are actually used in practice.
--


>> +/* page structure behind DAX mappings is NOT compound page
>> + * when it's a huge page mappings, so introduce new API to
>> + * account for both PMD and PUD mapping.
>> + */
>
>Why do they need to be compound?  Why don't we just make them
>compound
>instead of adding all this code which is *just* for DAX?
>
>> +static void smaps_account_dax_huge(struct mem_size_stats *mss,
>> +struct page *page, unsigned long size, bool young, bool 
>> dirty)
>> +{
>> +int mapcount = page_mapcount(page);
>> +
>> +if (PageAnon(page)) {
>> +mss->anonymous += size;
>> +if (!PageSwapBacked(page) && !dirty && !PageDirty(page))
>> +mss->lazyfree += size;
>> +}
>
>How can you have DAX anonymous huge pages?
>
>> +mss->resident += size;
>> +/* Accumulate the size in pages that have been accessed. */
>> +if (young || page_is_young(page) || PageReferenced(page))
>> +mss->referenced += size;
>
>Isn't this just a copy'n'paste of smaps_account() code?
>
>> +/*
>> + * page_count(page) == 1 guarantees the page is mapped exactly once.
>> + * If any subpage of the compound page mapped with PTE it would
>elevate
>> + * page_count().
>> + */
>> +if (page_count(page) == 1) {
>> +if (dirty || PageDirty(page))
>> +mss->private_dirty += size;
>> +else
>> +mss->private_clean += size;
>> +mss->pss += (u64)size << PSS_SHIFT;
>> +return;
>> +}
>
>PSS makes *zero* sense for DAX.  The "memory" is used whether the
>mapping exists or not.
>
>Also, the idea of "private" doesn't really make sense here.
>
>> +if (mapcount >= 2) {
>> +if (dirty || PageDirty(page))
>> +mss->shared_dirty += size;
>> +else
>> +mss->shared_clean += size;
>> +mss->pss += (size << PSS_SHIFT) / mapcount;
>> +} else {
>> +if (dirty || PageDirty(page))
>> +mss->private_dirty += size;
>> +else
>> +mss->private_clean += size;
>> +mss->pss += size << PSS_SHIFT;
>> +}
>> +}
>> +
>>  #ifdef CONFIG_SHMEM
>>  static int smaps_pte_hole(unsigned long addr, unsigned long end,
>>  struct mm_walk *walk)
>> @@ -528,7 +577,16 @@ static void smaps_pte_entry(pte_t *pte, unsigned
>long addr,
>>  struct page *page = NULL;
>>
>>  if (pte_present(*pte)) {
>> -page = vm_normal_page(vma, addr, *pte);
>> +if (!vma_is_dax(vma))
>> +page = vm_normal_page(vma, addr, *pte);
>> +else if (pte_devmap(*pte)) {
>> +struct dev_pagemap *pgmap;
>> +
>> +pgmap = get_dev_pagemap(pte_pfn(*pte), NULL);
>> +if (!pgmap)
>> +return;
>> +page = pte_page(*pte);
>> +}
>>  } else if (is_swap_pte(*pte)) {
>>  swp_entry_t swpent = pte_to_swp_entry(*pte);
>>
>> @@ -579,7 +637,19 @@ static void smaps_pmd_entry(pmd_t *pmd,
>unsigned long addr,
>>  struct page *page;
>>
>>  /* FOLL_DUMP will return -EFAULT on huge zero page */
>> -page = follow_trans_huge_pmd(vma, addr, pmd, FOLL_DUMP);
>> +if (!vma_is_dax(vma))
>> +page = follow_trans_huge_pmd(vma, addr, pmd, FOLL_DUMP);
>> +else if (pmd_devmap(*pmd)) {
>> +struct dev_pagemap *pgmap;
>> +
>> +pgmap = get_dev_pagemap(pmd_pfn(*pmd), NULL);
>> +if (!pgmap)
>> +return;
>> +page = pmd_page(*pmd);
>> +smaps_account_dax_huge(mss, page, PMD_SIZE, pmd_young(*pmd),
>> +pmd_dirty(*pmd));
>> +return;
>> +}
>>  if (IS_ERR_OR_NULL(page))
>>  return;
>>  if (PageAnon(page))
>>
>
>There's a fair amount of copying and pasting going on here.  There is,
>again, a bunch of specialized DAX code.  Isn't there a way to do this
>more generically?


[PATCH 01/12] housekeeping: Move housekeeping related code to its own file

2017-10-26 Thread Frederic Weisbecker
The housekeeping code is currently tied to the nohz code. As we are
planning to make housekeeping independant from it, start with moving
the relevant code to its own file.

Acked-by: Paul E. McKenney 
Signed-off-by: Frederic Weisbecker 
Cc: Chris Metcalf 
Cc: Christoph Lameter 
Cc: Linus Torvalds 
Cc: Luiz Capitulino 
Cc: Mike Galbraith 
Cc: Paul E. McKenney 
Cc: Peter Zijlstra 
Cc: Rik van Riel 
Cc: Thomas Gleixner 
Cc: Wanpeng Li 
---
 drivers/net/ethernet/tile/tilegx.c |  2 +-
 include/linux/sched/isolation.h| 56 ++
 include/linux/tick.h   | 37 -
 init/main.c|  2 ++
 kernel/rcu/tree_plugin.h   |  1 +
 kernel/rcu/update.c|  1 +
 kernel/sched/Makefile  |  1 +
 kernel/sched/core.c|  1 +
 kernel/sched/fair.c|  1 +
 kernel/sched/isolation.c   | 33 ++
 kernel/time/tick-sched.c   | 18 
 kernel/watchdog.c  |  1 +
 12 files changed, 98 insertions(+), 56 deletions(-)
 create mode 100644 include/linux/sched/isolation.h
 create mode 100644 kernel/sched/isolation.c

diff --git a/drivers/net/ethernet/tile/tilegx.c 
b/drivers/net/ethernet/tile/tilegx.c
index c00102b..27a3272 100644
--- a/drivers/net/ethernet/tile/tilegx.c
+++ b/drivers/net/ethernet/tile/tilegx.c
@@ -40,7 +40,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 
 #include 
 #include 
diff --git a/include/linux/sched/isolation.h b/include/linux/sched/isolation.h
new file mode 100644
index 000..b7cfbc4
--- /dev/null
+++ b/include/linux/sched/isolation.h
@@ -0,0 +1,56 @@
+#ifndef _LINUX_SCHED_ISOLATION_H
+#define _LINUX_SCHED_ISOLATION_H
+
+#include 
+#include 
+#include 
+
+#ifdef CONFIG_NO_HZ_FULL
+extern cpumask_var_t housekeeping_mask;
+
+static inline int housekeeping_any_cpu(void)
+{
+   return cpumask_any_and(housekeeping_mask, cpu_online_mask);
+}
+
+extern void __init housekeeping_init(void);
+
+#else
+
+static inline int housekeeping_any_cpu(void)
+{
+   return smp_processor_id();
+}
+
+static inline void housekeeping_init(void) { }
+#endif /* CONFIG_NO_HZ_FULL */
+
+
+static inline const struct cpumask *housekeeping_cpumask(void)
+{
+#ifdef CONFIG_NO_HZ_FULL
+   if (tick_nohz_full_enabled())
+   return housekeeping_mask;
+#endif
+   return cpu_possible_mask;
+}
+
+static inline bool is_housekeeping_cpu(int cpu)
+{
+#ifdef CONFIG_NO_HZ_FULL
+   if (tick_nohz_full_enabled())
+   return cpumask_test_cpu(cpu, housekeeping_mask);
+#endif
+   return true;
+}
+
+static inline void housekeeping_affine(struct task_struct *t)
+{
+#ifdef CONFIG_NO_HZ_FULL
+   if (tick_nohz_full_enabled())
+   set_cpus_allowed_ptr(t, housekeeping_mask);
+
+#endif
+}
+
+#endif /* _LINUX_SCHED_ISOLATION_H */
diff --git a/include/linux/tick.h b/include/linux/tick.h
index fe01e68..68afc09 100644
--- a/include/linux/tick.h
+++ b/include/linux/tick.h
@@ -137,7 +137,6 @@ static inline u64 get_cpu_iowait_time_us(int cpu, u64 
*unused) { return -1; }
 #ifdef CONFIG_NO_HZ_FULL
 extern bool tick_nohz_full_running;
 extern cpumask_var_t tick_nohz_full_mask;
-extern cpumask_var_t housekeeping_mask;
 
 static inline bool tick_nohz_full_enabled(void)
 {
@@ -161,11 +160,6 @@ static inline void tick_nohz_full_add_cpus_to(struct 
cpumask *mask)
cpumask_or(mask, mask, tick_nohz_full_mask);
 }
 
-static inline int housekeeping_any_cpu(void)
-{
-   return cpumask_any_and(housekeeping_mask, cpu_online_mask);
-}
-
 extern void tick_nohz_dep_set(enum tick_dep_bits bit);
 extern void tick_nohz_dep_clear(enum tick_dep_bits bit);
 extern void tick_nohz_dep_set_cpu(int cpu, enum tick_dep_bits bit);
@@ -235,10 +229,6 @@ static inline void tick_dep_clear_signal(struct 
signal_struct *signal,
 extern void tick_nohz_full_kick_cpu(int cpu);
 extern void __tick_nohz_task_switch(void);
 #else
-static inline int housekeeping_any_cpu(void)
-{
-   return smp_processor_id();
-}
 static inline bool tick_nohz_full_enabled(void) { return false; }
 static inline bool tick_nohz_full_cpu(int cpu) { return false; }
 static inline void tick_nohz_full_add_cpus_to(struct cpumask *mask) { }
@@ -260,33 +250,6 @@ static inline void tick_nohz_full_kick_cpu(int cpu) { }
 static inline void __tick_nohz_task_switch(void) { }
 #endif
 
-static inline const struct cpumask *housekeeping_cpumask(void)
-{
-#ifdef CONFIG_NO_HZ_FULL
-   if (tick_nohz_full_enabled())
-   return housekeeping_mask;
-#endif
-   return cpu_possible_mask;
-}
-
-static inline bool is_housekeeping_cpu(int cpu)
-{
-#ifdef CONFIG_NO_HZ_FULL
-   if (tick_nohz_full_enabled())
-   return cpumask_test_cpu(cpu, housekeeping_mask);
-#endif
-   return true;
-}
-
-static inline void housekeeping_affine(struct task_struct *t)
-{
-#ifdef CONFIG_NO_HZ_FULL
-   if (tick_nohz_full_enabled())
-

  1   2   3   4   5   6   7   8   >