[PATCH v3 3/6] usb: dwc3: ep0: preparation for handling non maxpacket aligned transfers > 512

2015-07-26 Thread Kishon Vijay Abraham I
No functional change. This is in preparation for handling non maxpacket
aligned transfers greater than bounce buffer size. This is basically to
avoid code duplication when using chained TRB transfers to handle
non maxpacket aligned transfers greater than bounce buffer size.

Signed-off-by: Kishon Vijay Abraham I 
---
 drivers/usb/dwc3/ep0.c |   25 +
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 713e46a..4998074 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -779,7 +779,11 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
struct usb_request  *ur;
struct dwc3_trb *trb;
struct dwc3_ep  *ep0;
-   u32 transferred;
+   unsignedtransfer_size = 0;
+   unsignedmaxp;
+   unsignedremaining_ur_length;
+   void*buf;
+   u32 transferred = 0;
u32 status;
u32 length;
u8  epnum;
@@ -808,20 +812,24 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
}
 
ur = &r->request;
+   buf = ur->buf;
+   remaining_ur_length = ur->length;
 
length = trb->size & DWC3_TRB_SIZE_MASK;
 
+   maxp = ep0->endpoint.maxpacket;
+
if (dwc->ep0_bounced) {
-   unsigned maxp = ep0->endpoint.maxpacket;
-   unsigned transfer_size = roundup(ur->length, maxp);
+   transfer_size = roundup((ur->length - transfer_size),
+   maxp);
 
/* Maximum of DWC3_EP0_BOUNCE_SIZE can only be received */
if (transfer_size > DWC3_EP0_BOUNCE_SIZE)
transfer_size = DWC3_EP0_BOUNCE_SIZE;
 
-   transferred = min_t(u32, ur->length,
-   transfer_size - length);
-   memcpy(ur->buf, dwc->ep0_bounce, transferred);
+   transferred = min_t(u32, remaining_ur_length,
+   transfer_size - length);
+   memcpy(buf, dwc->ep0_bounce, transferred);
} else {
transferred = ur->length - length;
}
@@ -930,7 +938,7 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
DWC3_TRBCTL_CONTROL_DATA);
} else if (!IS_ALIGNED(req->request.length, dep->endpoint.maxpacket)
&& (dep->number == 0)) {
-   u32 transfer_size;
+   u32 transfer_size = 0;
u32 maxpacket;
 
ret = usb_gadget_map_request(&dwc->gadget, &req->request,
@@ -941,7 +949,8 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
}
 
maxpacket = dep->endpoint.maxpacket;
-   transfer_size = roundup(req->request.length, maxpacket);
+   transfer_size = roundup((req->request.length - transfer_size),
+   maxpacket);
 
if (transfer_size > DWC3_EP0_BOUNCE_SIZE) {
dev_WARN(dwc->dev, "bounce buf can't handle req len\n");
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 1/6] usb: dwc3: ep0: Fix mem corruption on OUT transfers of more than 512 bytes

2015-07-26 Thread Kishon Vijay Abraham I
DWC3 uses bounce buffer to handle non max packet aligned OUT transfers and
the size of bounce buffer is 512 bytes. However if the host initiates OUT
transfers of size more than 512 bytes (and non max packet aligned), the
driver throws a WARN dump but still programs the TRB to receive more than
512 bytes. This will cause bounce buffer to overflow and corrupt the
adjacent memory locations which can be fatal.

Fix it by programming the TRB to receive a maximum of DWC3_EP0_BOUNCE_SIZE
(512) bytes.

Cc:  # 3.4+
Signed-off-by: Kishon Vijay Abraham I 
---
 drivers/usb/dwc3/ep0.c |   12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 2ef3c8d..8858c60 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -816,6 +816,11 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
unsigned maxp = ep0->endpoint.maxpacket;
 
transfer_size += (maxp - (transfer_size % maxp));
+
+   /* Maximum of DWC3_EP0_BOUNCE_SIZE can only be received */
+   if (transfer_size > DWC3_EP0_BOUNCE_SIZE)
+   transfer_size = DWC3_EP0_BOUNCE_SIZE;
+
transferred = min_t(u32, ur->length,
transfer_size - length);
memcpy(ur->buf, dwc->ep0_bounce, transferred);
@@ -937,11 +942,14 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
return;
}
 
-   WARN_ON(req->request.length > DWC3_EP0_BOUNCE_SIZE);
-
maxpacket = dep->endpoint.maxpacket;
transfer_size = roundup(req->request.length, maxpacket);
 
+   if (transfer_size > DWC3_EP0_BOUNCE_SIZE) {
+   dev_WARN(dwc->dev, "bounce buf can't handle req len\n");
+   transfer_size = DWC3_EP0_BOUNCE_SIZE;
+   }
+
dwc->ep0_bounced = true;
 
/*
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH 2/3] drivers: usb: dwc3: Add adjust_frame_length_quirk

2015-07-26 Thread Badola Nikhil
> -Original Message-
> From: Felipe Balbi [mailto:ba...@ti.com]
> Sent: Thursday, July 23, 2015 8:39 PM
> To: Felipe Balbi
> Cc: Badola Nikhil-B46172; linux-kernel@vger.kernel.org; linux-
> u...@vger.kernel.org; linux-o...@vger.kernel.org;
> gre...@linuxfoundation.org
> Subject: Re: [PATCH 2/3] drivers: usb: dwc3: Add adjust_frame_length_quirk
> 
> Hi again,
> 
> On Thu, Jul 23, 2015 at 09:55:32AM -0500, Felipe Balbi wrote:
> > > diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index
> > > 0447788..b7a5119 100644
> > > --- a/drivers/usb/dwc3/core.h
> > > +++ b/drivers/usb/dwc3/core.h
> > > @@ -124,6 +124,7 @@
> > >  #define DWC3_GEVNTCOUNT(n)   (0xc40c + (n * 0x10))
> > >
> > >  #define DWC3_GHWPARAMS8  0xc600
> > > +#define DWC3_GFLADJ  0xc630
> > >
> > >  /* Device Registers */
> > >  #define DWC3_DCFG0xc700
> > > @@ -234,6 +235,10 @@
> > >  /* Global HWPARAMS6 Register */
> > >  #define DWC3_GHWPARAMS6_EN_FPGA  (1 << 7)
> > >
> > > +/* Global Frame Length Adjustment Register */
> > > +#define GFLADJ_30MHZ_REG_SEL (1 << 7)
> >
> > always prepend with DWC3_ like *all* other macros in this file.
> >
> > Also, match docs to ease grepping. This should be called
> > DWC3_GFLADJ_30MHZ_SDBND_SEL

GFLADJ_30MHZ_REG_SEL is the field's name in LS1021A Reference Manual as well 
as dwc3 databook. Though DWC3_GFLADJ_30MHZ_SDBND_SEL seems more
relevant. 

> 
> yet another problem is that this register doesn't exist in *all* versions of
> DWC3. It was introduced in version 2.50a so the branch I typed above needs
> one extra check, and since it's getting so large, it deserves be factored out
> into its own function.
> 
> static int dwc3_frame_length_adjustment(struct dwc3 *dwc, u32 fladj) {
>   u32 reg;
>   u32 dft;
> 
>   if (dwc->revision <= DWC3_REVISION_250A)
>   return 0;
> 
>   if (fladj == 0)
>   return 0;
> 
>   reg = dwc3_readl(dwc->regs, DWC3_GFLADJ);
>   dft = reg & 0x3f; /* needs a mask macro */
> 
>   if (!dev_WARN_ONCE(dwc->dev, dft == fladj,
>   "requested value same as default, ignoring\n")) {
>   reg &= ~0x3f; /* needs a mask macro */
>   reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL |
>   DWC3_GFLADJ_30MHZ(fladj_value);
> 
>   dwc3_writel(dwc->regs, DWC3_GFLADJ, reg);
>   }
> }
> 
> you really *MUST* check this sort of this out when writing patches. It's not
> only about *your* SoC. You gotta remember we have a ton of different
> users and those a prone to major grumpyness should a completely unrelated
> patch break their use case.
> 
> You have access to the IP's documentation, and that contains the entire
> history of the IP itself, so it's easy to figure all of this out with a 
> simple search
> in the documentation.
> 
> One extra detail is that you were very careless when writing to the GFLADJ
> register too. You simply wrote your 30MHz sideband value, potentially
> clearing other bits which shouldn't be touched. That alone can add
> regressions.
> 
> When resending, make sure all 3 patches reach linux-usb. I still can't find
> patch 3/3.
>

Will take care of above scenarios and resend patches cc'ing linux-usb in each 
of them.

Regarding acceptance of the patch only when it's used in glue layer, there is 
no freescale's
glue layer present for dwc3 as of now. Furthermore, there is not any platform 
specific 
code required in glue layer apart from the ones present in dwc3/core.c. 

Please suggest.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 4/6] usb: dwc3; ep0: Modify _dwc3_ep0_start_trans_ API to take 'chain' parameter

2015-07-26 Thread Kishon Vijay Abraham I
No functional change. Added a new parameter in _dwc3_ep0_start_trans_ to
indicate whether the TRB is a chained TRB or last TRB. This is in
preparation for adding chained TRB support for ep0.

Signed-off-by: Kishon Vijay Abraham I 
---
 drivers/usb/dwc3/ep0.c |   15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 4998074..01411a8 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -56,7 +56,7 @@ static const char *dwc3_ep0_state_string(enum dwc3_ep0_state 
state)
 }
 
 static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma,
-   u32 len, u32 type)
+   u32 len, u32 type, bool chain)
 {
struct dwc3_gadget_ep_cmd_params params;
struct dwc3_trb *trb;
@@ -302,7 +302,7 @@ void dwc3_ep0_out_start(struct dwc3 *dwc)
int ret;
 
ret = dwc3_ep0_start_trans(dwc, 0, dwc->ctrl_req_addr, 8,
-   DWC3_TRBCTL_CONTROL_SETUP);
+   DWC3_TRBCTL_CONTROL_SETUP, false);
WARN_ON(ret < 0);
 }
 
@@ -851,7 +851,7 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
 
ret = dwc3_ep0_start_trans(dwc, epnum,
dwc->ctrl_req_addr, 0,
-   DWC3_TRBCTL_CONTROL_DATA);
+   DWC3_TRBCTL_CONTROL_DATA, false);
WARN_ON(ret < 0);
}
}
@@ -935,7 +935,7 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
if (req->request.length == 0) {
ret = dwc3_ep0_start_trans(dwc, dep->number,
dwc->ctrl_req_addr, 0,
-   DWC3_TRBCTL_CONTROL_DATA);
+   DWC3_TRBCTL_CONTROL_DATA, false);
} else if (!IS_ALIGNED(req->request.length, dep->endpoint.maxpacket)
&& (dep->number == 0)) {
u32 transfer_size = 0;
@@ -966,7 +966,7 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
 */
ret = dwc3_ep0_start_trans(dwc, dep->number,
dwc->ep0_bounce_addr, transfer_size,
-   DWC3_TRBCTL_CONTROL_DATA);
+   DWC3_TRBCTL_CONTROL_DATA, false);
} else {
ret = usb_gadget_map_request(&dwc->gadget, &req->request,
dep->number);
@@ -976,7 +976,8 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
}
 
ret = dwc3_ep0_start_trans(dwc, dep->number, req->request.dma,
-   req->request.length, DWC3_TRBCTL_CONTROL_DATA);
+   req->request.length, DWC3_TRBCTL_CONTROL_DATA,
+   false);
}
 
WARN_ON(ret < 0);
@@ -991,7 +992,7 @@ static int dwc3_ep0_start_control_status(struct dwc3_ep 
*dep)
: DWC3_TRBCTL_CONTROL_STATUS2;
 
return dwc3_ep0_start_trans(dwc, dep->number,
-   dwc->ctrl_req_addr, 0, type);
+   dwc->ctrl_req_addr, 0, type, false);
 }
 
 static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep)
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFCv2 2/3] dts: zynq: Add devicetree entry for Xilinx Zynq reset controller.

2015-07-26 Thread Michal Simek
Hi Moritz,

On 07/25/2015 02:21 AM, Moritz Fischer wrote:
> Signed-off-by: Moritz Fischer 
> ---
>  arch/arm/boot/dts/zynq-7000.dtsi| 43 -

This patch is nice in general but every change in binding should be
discussed separately. There is also necessary to wire them up in the
driver to do action. That's why I think that will be the best just to
add the code to slcr and keep others untouched.

For example MACB/GEM is one example. Adding names to this node and
extending driver to work properly with reset means that all others MACB
users will be affected. Definitely this patch should be ACKed by Nicolas.

Thanks,
Michal

-- 
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/
Maintainer of Linux kernel - Xilinx Zynq ARM architecture
Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform




signature.asc
Description: OpenPGP digital signature


[PATCH v3 2/6] usb: dwc3: ep0: use _roundup_ to calculate the transfer size

2015-07-26 Thread Kishon Vijay Abraham I
No functional change. Used _roundup_ macro to calculate the transfer
size aligned to maxpacket in  dwc3_ep0_complete_data. It also makes it
similar to how transfer size is calculated in __dwc3_ep0_do_control_data.

Signed-off-by: Kishon Vijay Abraham I 
---
 drivers/usb/dwc3/ep0.c |4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 8858c60..713e46a 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -812,10 +812,8 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
length = trb->size & DWC3_TRB_SIZE_MASK;
 
if (dwc->ep0_bounced) {
-   unsigned transfer_size = ur->length;
unsigned maxp = ep0->endpoint.maxpacket;
-
-   transfer_size += (maxp - (transfer_size % maxp));
+   unsigned transfer_size = roundup(ur->length, maxp);
 
/* Maximum of DWC3_EP0_BOUNCE_SIZE can only be received */
if (transfer_size > DWC3_EP0_BOUNCE_SIZE)
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 6/6] usb: dwc3: ep0: handle non maxpacket aligned transfers > 512

2015-07-26 Thread Kishon Vijay Abraham I
Use chained TRB mechanism to handle non maxpacket aligned transfers
greater than bounce buffer size. With this the first TRB will be programmed
to receive 'ALIGN(ur->length - maxp, maxp)' data and the second TRB
will be programmed to receive the remaining data using bounce buffer.

Signed-off-by: Kishon Vijay Abraham I 
---
 drivers/usb/dwc3/ep0.c |   42 --
 1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 73500d3..f6c3c73 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -830,13 +830,26 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
maxp = ep0->endpoint.maxpacket;
 
if (dwc->ep0_bounced) {
+   /*
+* Handle the first TRB before handling the bounce buffer if
+* the request length is greater than the bounce buffer size
+*/
+   if (ur->length > DWC3_EP0_BOUNCE_SIZE) {
+   transfer_size = ALIGN(ur->length - maxp, maxp);
+   transferred = transfer_size - length;
+   buf = (u8 *)buf + transferred;
+   ur->actual += transferred;
+   remaining_ur_length -= transferred;
+
+   trb++;
+   length = trb->size & DWC3_TRB_SIZE_MASK;
+
+   ep0->free_slot = 0;
+   }
+
transfer_size = roundup((ur->length - transfer_size),
maxp);
 
-   /* Maximum of DWC3_EP0_BOUNCE_SIZE can only be received */
-   if (transfer_size > DWC3_EP0_BOUNCE_SIZE)
-   transfer_size = DWC3_EP0_BOUNCE_SIZE;
-
transferred = min_t(u32, remaining_ur_length,
transfer_size - length);
memcpy(buf, dwc->ep0_bounce, transferred);
@@ -959,21 +972,22 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
}
 
maxpacket = dep->endpoint.maxpacket;
-   transfer_size = roundup((req->request.length - transfer_size),
-   maxpacket);
 
-   if (transfer_size > DWC3_EP0_BOUNCE_SIZE) {
-   dev_WARN(dwc->dev, "bounce buf can't handle req len\n");
-   transfer_size = DWC3_EP0_BOUNCE_SIZE;
+   if (req->request.length > DWC3_EP0_BOUNCE_SIZE) {
+   transfer_size = ALIGN(req->request.length - maxpacket,
+ maxpacket);
+   ret = dwc3_ep0_start_trans(dwc, dep->number,
+  req->request.dma,
+  transfer_size,
+  DWC3_TRBCTL_CONTROL_DATA,
+  true);
}
 
+   transfer_size = roundup((req->request.length - transfer_size),
+   maxpacket);
+
dwc->ep0_bounced = true;
 
-   /*
-* REVISIT in case request length is bigger than
-* DWC3_EP0_BOUNCE_SIZE we will need two chained
-* TRBs to handle the transfer.
-*/
ret = dwc3_ep0_start_trans(dwc, dep->number,
dwc->ep0_bounce_addr, transfer_size,
DWC3_TRBCTL_CONTROL_DATA, false);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 0/6] usb: dwc3: handle non maxpacket aligned transfers > 512

2015-07-26 Thread Kishon Vijay Abraham I
Patch series first fixes memory corruption and then adds support to
handle non maxpacket aligned transfers.

Patch series adds support to handle non maxpacket aligned transfers
greater than bounce buffer size (512). It first adds chained TRB
support and then uses it to handle non maxpacket aligned transfers
greater than bounce buffer size.

Also included a cleanup patch to use 'roundup' macro.

Changes from v2:
*) fixed the "stable" mail address
*) Used "bool" for the argument instead of unsigned.

Changes from v1:
*) Included the patch to fix memory corruption in this series. (Also
   marked it for stable release).

Non maxpacket aligned transfers can be initiated by
"./testusb -t 14 -c 1 -s 520 -v 1"

Before this series: (Causes memory corruption)
unknown speed   /dev/bus/usb/010/0090
/dev/bus/usb/010/009 test 14,0.219638 secs

After the 1st patch of this series:
unknown speed   /dev/bus/usb/001/0180
/dev/bus/usb/001/018 test 14 --> 110 (Connection timed out)

After this series: (No memory corruption)
unknown speed   /dev/bus/usb/001/0230
/dev/bus/usb/001/023 test 14,0.000486 secs

Tested this patch using USB3 Gen X CV (ch9 tests: usb2 and usb3,
link layer testing and MSC tests) and using USB2 X CV (ch9 tests,
MSC tests) and verified this doesn't cause additional failures.

Lecroy compliance tests fail even without this patch series so
deferred testing it. 

Kishon Vijay Abraham I (6):
  usb: dwc3: ep0: Fix mem corruption on OUT transfers of more than 512
bytes
  usb: dwc3: ep0: use _roundup_ to calculate the transfer size
  usb: dwc3: ep0: preparation for handling non maxpacket aligned
transfers > 512
  usb: dwc3; ep0: Modify _dwc3_ep0_start_trans_ API to take 'chain'
parameter
  usb: dwc3: ep0: Add chained TRB support
  usb: dwc3: ep0: handle non maxpacket aligned transfers > 512

 drivers/usb/dwc3/ep0.c|   92 -
 drivers/usb/dwc3/gadget.c |2 +-
 2 files changed, 67 insertions(+), 27 deletions(-)

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 5/6] usb: dwc3: ep0: Add chained TRB support

2015-07-26 Thread Kishon Vijay Abraham I
Add chained TRB support to ep0. Now TRB's can be chained just by
invoking _dwc3_ep0_start_trans_ with 'chain' parameter set to true.

Signed-off-by: Kishon Vijay Abraham I 
---
 drivers/usb/dwc3/ep0.c|   16 +---
 drivers/usb/dwc3/gadget.c |2 +-
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 01411a8..73500d3 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -70,7 +70,10 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, 
dma_addr_t buf_dma,
return 0;
}
 
-   trb = dwc->ep0_trb;
+   trb = &dwc->ep0_trb[dep->free_slot];
+
+   if (chain)
+   dep->free_slot++;
 
trb->bpl = lower_32_bits(buf_dma);
trb->bph = upper_32_bits(buf_dma);
@@ -78,10 +81,17 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, 
dma_addr_t buf_dma,
trb->ctrl = type;
 
trb->ctrl |= (DWC3_TRB_CTRL_HWO
-   | DWC3_TRB_CTRL_LST
-   | DWC3_TRB_CTRL_IOC
| DWC3_TRB_CTRL_ISP_IMI);
 
+   if (chain)
+   trb->ctrl |= DWC3_TRB_CTRL_CHN;
+   else
+   trb->ctrl |= (DWC3_TRB_CTRL_IOC
+   | DWC3_TRB_CTRL_LST);
+
+   if (chain)
+   return 0;
+
memset(¶ms, 0, sizeof(params));
params.param0 = upper_32_bits(dwc->ep0_trb_addr);
params.param1 = lower_32_bits(dwc->ep0_trb_addr);
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index d97fcfa..2feed9e 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2687,7 +2687,7 @@ int dwc3_gadget_init(struct dwc3 *dwc)
goto err0;
}
 
-   dwc->ep0_trb = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ep0_trb),
+   dwc->ep0_trb = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ep0_trb) * 2,
&dwc->ep0_trb_addr, GFP_KERNEL);
if (!dwc->ep0_trb) {
dev_err(dwc->dev, "failed to allocate ep0 trb\n");
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/4] cp210x: Store part number

2015-07-26 Thread Petr Tesarik
On Sun, 26 Jul 2015 15:32:54 +0200
Oliver Neukum  wrote:

> On Fri, 2015-07-24 at 08:48 +0200, Petr Tesarik wrote:
> > @@ -872,6 +886,12 @@ static int cp210x_startup(struct usb_serial
> > *serial)
> >  
> > usb_set_serial_data(serial, spriv);
> >  
> > +   /* Get the 1-byte part number of the cp210x device */
> > +   cp210x_control_msg(serial->port[0], CP210X_VENDOR_SPECIFIC,
> > +  REQTYPE_DEVICE_TO_HOST, CP210X_GET_PARTNUM,
> > +  &partnum, 1, USB_CTRL_GET_TIMEOUT);
> > +   spriv->bPartNumber = partnum & 0xFF;
> 
> DMA on the stack. That breaks the cache coherency rules.
> You must kmalloc the buffer.

I don't understand. While you're right that I copied this part from
Sillicon Labs' driver without much thinking, and &spriv->bPartNumber
can be used directly, I can't see any DMA on stack. FWIW
cp210x_control_msg always allocates a buffer using kcalloc:

buf = kcalloc(length, sizeof(__le32), GFP_KERNEL);
/* ... */
result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
 request, requesttype, value,
 spriv->bInterfaceNumber, buf, size, timeout);

Is that what you mean?

TIA,
Petr T
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 1/2] dmaengine: Add an enum for the dmaengine alignment constraints

2015-07-26 Thread Maxime Ripard
On Mon, Jul 20, 2015 at 11:03:25AM +0200, Thomas Petazzoni wrote:
> Maxime,
> 
> On Mon, 20 Jul 2015 10:41:32 +0200, Maxime Ripard wrote:
> 
> >  /**
> > + * enum dmaengine_alignment - defines alignment of the DMA async tx
> > + * buffers
> > + */
> > +enum dmaengine_alignment {
> > +   DMAENGINE_ALIGN_1_BYTE = 0,
> > +   DMAENGINE_ALIGN_2_BYTES = 1,
> > +   DMAENGINE_ALIGN_4_BYTES = 2,
> > +   DMAENGINE_ALIGN_8_BYTES = 3,
> > +   DMAENGINE_ALIGN_16_BYTES = 4,
> > +   DMAENGINE_ALIGN_32_BYTES = 5,
> > +   DMAENGINE_ALIGN_64_BYTES = 6,
> > +};
> 
> Sorry I didn't think about this during the first iteration, but this
> define is just the log2 of the values, no? So maybe you could simply do
> something like:
> 
> static inline unsigned int dmaengine_alignment(size_t bytes)
> {
>   return ilog2(bytes);
> }

I could, but all the rest of the other similar case so far in
dmaengine are made through enum, so I guess it's still better for
consistency. And we also provide a comprehensive list of the valid
values this way, something a function would not provide (or at least
not at compilation time)

Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com


signature.asc
Description: Digital signature


Re: [PATCH V5 2/7] mm: mlock: Add new mlock system call

2015-07-26 Thread Kirill A. Shutemov
On Fri, Jul 24, 2015 at 05:28:40PM -0400, Eric B Munson wrote:
> With the refactored mlock code, introduce a new system call for mlock.
> The new call will allow the user to specify what lock states are being
> added.  mlock2 is trivial at the moment, but a follow on patch will add
> a new mlock state making it useful.
> 
> Signed-off-by: Eric B Munson 
> Cc: Michal Hocko 
> Cc: Vlastimil Babka 
> Cc: Heiko Carstens 
> Cc: Geert Uytterhoeven 
> Cc: Catalin Marinas 
> Cc: Stephen Rothwell 
> Cc: Guenter Roeck 
> Cc: linux-al...@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Cc: linux-arm-ker...@lists.infradead.org
> Cc: adi-buildroot-de...@lists.sourceforge.net
> Cc: linux-cris-ker...@axis.com
> Cc: linux-i...@vger.kernel.org
> Cc: linux-m...@lists.linux-m68k.org
> Cc: linux-am33-l...@redhat.com
> Cc: linux-par...@vger.kernel.org
> Cc: linuxppc-...@lists.ozlabs.org
> Cc: linux-s...@vger.kernel.org
> Cc: linux...@vger.kernel.org
> Cc: sparcli...@vger.kernel.org
> Cc: linux-xte...@linux-xtensa.org
> Cc: linux-...@vger.kernel.org
> Cc: linux-a...@vger.kernel.org
> Cc: linux...@kvack.org
> ---
> Changes from V4:
> * Drop all architectures except x86[_64] from this patch, MIPS is added
>   later in the series.  All others will be left to their maintainers.
> 
> Changes from V3:
> * Do a (hopefully) complete job of adding the new system calls
>  arch/alpha/include/uapi/asm/mman.h | 2 ++
>  arch/mips/include/uapi/asm/mman.h  | 5 +
>  arch/parisc/include/uapi/asm/mman.h| 2 ++
>  arch/powerpc/include/uapi/asm/mman.h   | 2 ++
>  arch/sparc/include/uapi/asm/mman.h | 2 ++
>  arch/tile/include/uapi/asm/mman.h  | 5 +
>  arch/x86/entry/syscalls/syscall_32.tbl | 1 +
>  arch/x86/entry/syscalls/syscall_64.tbl | 1 +
>  arch/xtensa/include/uapi/asm/mman.h| 5 +

Define MLOCK_LOCKED in include/uapi/asm-generic/mman-common.h.
This way you can drop changes in powerpc, sparc and tile.

Otherwise looks good.

-- 
 Kirill A. Shutemov
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[no subject]

2015-07-26 Thread lihua
auth 37b0e0af subscribe linux-kernel \ 
lihua@gmail.com 


N�r��yb�X��ǧv�^�)޺{.n�+{zX����ܨ}���Ơz�&j:+v���zZ+��+zf���h���~i���z��w���?�&�)ߢf��^jǫy�m��@A�a���
0��h���i

RE: [char-misc-next 0/9 RESEND] mei: support for async event notifications

2015-07-26 Thread Winkler, Tomas

> 
> On Sun, Jul 26, 2015 at 09:54:14AM +0300, Tomas Winkler wrote:
> > FW has gained new capability where a FW client can asynchronously
> > notify the host that an event has occurred in its process.
> > The notification doesn't provide any data and host may need to query
> > further the FW client in order to get details of the event.
> > New IOCTLs are introduced for the user space to enable/disable
> > and consume the event notifications.
> > The asynchronous nature is provided via poll and fasync.
> 
> What changed to require a RESEND?

You've asked for it.
Tomas

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V5 1/7] mm: mlock: Refactor mlock, munlock, and munlockall code

2015-07-26 Thread Kirill A. Shutemov
On Fri, Jul 24, 2015 at 05:28:39PM -0400, Eric B Munson wrote:
> Extending the mlock system call is very difficult because it currently
> does not take a flags argument.  A later patch in this set will extend
> mlock to support a middle ground between pages that are locked and
> faulted in immediately and unlocked pages.  To pave the way for the new
> system call, the code needs some reorganization so that all the actual
> entry point handles is checking input and translating to VMA flags.
> 
> Signed-off-by: Eric B Munson 
> Cc: Michal Hocko 
> Cc: Vlastimil Babka 
> Cc: "Kirill A. Shutemov" 
> Cc: linux...@kvack.org
> Cc: linux-kernel@vger.kernel.org

Acked-by: Kirill A. Shutemov 

-- 
 Kirill A. Shutemov
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 0/3] dra7xx: Add PM support to PCIe

2015-07-26 Thread Kishon Vijay Abraham I
This series adds PM support to pci-dra7xx so that PCI clocks can be disabled
during suspend and enabled back during resume without affecting
PCI functionality.

Changes from v2:
*) Used SET_SYSTEM_SLEEP_PM_OPS and SET_NOIRQ_SYSTEM_SLEEP_PM_OPS for
   populating PM ops.

Changes from v1:
*) Moved resetting and setting of MSE bit to pci-dra7xx.

The comment to reset and set ISE is not done now since I don't have a card
with IO space. Once I get to test that, I'll post a separate patch for
handling that.

Kishon Vijay Abraham I (3):
  PCI: host: pci-dra7xx: Disable pm_runtime on get_sync failure
  PCI: host: pci-dra7xx: add pm support to pci dra7xx
  PCI: host: pci-dra7xx: Idle the module by disabling MSE bit

 drivers/pci/host/pci-dra7xx.c |   95 -
 1 file changed, 94 insertions(+), 1 deletion(-)

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [alsa-devel] [PATCH v3] ASoC: Add support for NAU8825 codec to ASoC

2015-07-26 Thread Chih-Chiang Chang
Hi Anatol,

Thanks for your suggestion. We are working on different architectures to
support NAU8825 ALSA driver, and I also think it is better we can have a
cooperation for driver development and upstream. We have checked your
code, and we think your implement version should more follow the ALSA
upstream coding standards.

We have another version of ALSA driver, which also supports most
features as you listed. And I think you already got it from our HW
engineers. The major difference between our architectures should be the
flow and sequence in sleep mode, and some other architecture dependence
codes.

For the upstream, we think it is better to have only one version source
and could support different architectures. Do you agree to use your
version to go on the upstream in future? If yes, we can port your driver
to our test platform, and then give the feedback to you.

On 2015/7/23 上午 01:57, Anatol Pomozov wrote:
> Hi Chih-Chiang
> 
> On Mon, Jul 13, 2015 at 12:33 AM, Chih-Chiang Chang
>  wrote:
>> The NAU88L25 is an ultra-low power high performance audio codec designed
>> for smartphone, tablet PC, and other portable devices by Nuvoton, now
>> add linux driver support for it.
> 
> At ChromeOS we work with Nuvoton hw engineers on driver for this nice
> chip as well.
> 
> Here is current driver code
> https://github.com/anatol/linux/blob/nau8825/sound/soc/codecs/nau8825.c
> 
> The functionality is mostly ready. Our driver handles playback,
> capture, mic jack detection, an button presses (4 buttons according
> Android specification). We need to resolve a few remaining issues,
> such as
>  - chip needs better way to recognize high-impedance input (e.g. Bose
> Quiet Comfort 15 headset)
>  - implement headset cross talk automatic configuration
>  - general code cleanup
> 
> But otherwise driver is functional and used for testing in our next
> generation device.
> 
> 
> What do you think about joining efforts on this software development
> to make great driver for this chip?
> 
>> Signed-off-by: Chih-Chiang Chang 
>> ---
>> v3->v2:
>>- fix the wrong definition of reg_default
>>- fix the flow of set_sys_clk() and nau8825_set_bias_level()
>>- remove unnecessary code in nau8825_volatile_register() and
>> nau8825_i2c_probe()
>>- add trigger function for ADC/DAC control
>>- add some register definitions
>>- fix some coding style issues
>> v2->v1:
>>- fixes according to Lars-Peter Clausen's review comments
>>- removes unused platform data file
>>- corrects the naming of DAPM input widget
>>- fixes some wrong coding of SOC widgets and other codes
>>- adds definition and remark for config FLL clock
>>- moves the code of reset hardware registers from codec_probe() to
>> i2c_probe()
>>- removes unused codes
>>
>>  sound/soc/codecs/Kconfig   |   5 +
>>  sound/soc/codecs/Makefile  |   2 +
>>  sound/soc/codecs/nau8825.c | 724
>> +
>>  sound/soc/codecs/nau8825.h | 399 +
>>  4 files changed, 1130 insertions(+)
>>  create mode 100644 sound/soc/codecs/nau8825.c
>>  create mode 100644 sound/soc/codecs/nau8825.h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 2/3] PCI: host: pci-dra7xx: add pm support to pci dra7xx

2015-07-26 Thread Kishon Vijay Abraham I
Add PM support to pci-dra7xx so that PCI clocks can be disabled
during suspend and enabled back during resume without affecting
PCI functionality.

Signed-off-by: Kishon Vijay Abraham I 
---
 drivers/pci/host/pci-dra7xx.c |   72 +
 1 file changed, 72 insertions(+)

diff --git a/drivers/pci/host/pci-dra7xx.c b/drivers/pci/host/pci-dra7xx.c
index d8b6d66..7599201 100644
--- a/drivers/pci/host/pci-dra7xx.c
+++ b/drivers/pci/host/pci-dra7xx.c
@@ -433,6 +433,77 @@ static int __exit dra7xx_pcie_remove(struct 
platform_device *pdev)
return 0;
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int dra7xx_pcie_suspend(struct device *dev)
+{
+   struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
+   struct pcie_port *pp = &dra7xx->pp;
+
+   dw_pcie_suspend_rc(pp);
+
+   return 0;
+}
+
+static int dra7xx_pcie_resume(struct device *dev)
+{
+   struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
+   struct pcie_port *pp = &dra7xx->pp;
+
+   dw_pcie_resume_rc(pp);
+
+   return 0;
+}
+
+static int dra7xx_pcie_suspend_noirq(struct device *dev)
+{
+   struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
+   int count = dra7xx->phy_count;
+
+   while (count--) {
+   phy_power_off(dra7xx->phy[count]);
+   phy_exit(dra7xx->phy[count]);
+   }
+
+   return 0;
+}
+
+static int dra7xx_pcie_resume_noirq(struct device *dev)
+{
+   struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
+   int phy_count = dra7xx->phy_count;
+   int ret;
+   int i;
+
+   for (i = 0; i < phy_count; i++) {
+   ret = phy_init(dra7xx->phy[i]);
+   if (ret < 0)
+   goto err_phy;
+
+   ret = phy_power_on(dra7xx->phy[i]);
+   if (ret < 0) {
+   phy_exit(dra7xx->phy[i]);
+   goto err_phy;
+   }
+   }
+
+   return 0;
+
+err_phy:
+   while (--i >= 0) {
+   phy_power_off(dra7xx->phy[i]);
+   phy_exit(dra7xx->phy[i]);
+   }
+
+   return ret;
+}
+#endif
+
+static const struct dev_pm_ops dra7xx_pcie_pm_ops = {
+   SET_SYSTEM_SLEEP_PM_OPS(dra7xx_pcie_suspend, dra7xx_pcie_resume)
+   SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(dra7xx_pcie_suspend_noirq,
+ dra7xx_pcie_resume_noirq)
+};
+
 static const struct of_device_id of_dra7xx_pcie_match[] = {
{ .compatible = "ti,dra7-pcie", },
{},
@@ -444,6 +515,7 @@ static struct platform_driver dra7xx_pcie_driver = {
.driver = {
.name   = "dra7-pcie",
.of_match_table = of_dra7xx_pcie_match,
+   .pm = &dra7xx_pcie_pm_ops,
},
 };
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 1/3] PCI: host: pci-dra7xx: Disable pm_runtime on get_sync failure

2015-07-26 Thread Kishon Vijay Abraham I
Fix the error handling code in case pm_runtime_get_sync fails. Now
when pm_runtime_get_sync fails pm_runtime_disable is invoked so that
there is no unbalanced pm_runtime_enable calls.

Signed-off-by: Kishon Vijay Abraham I 
---
 drivers/pci/host/pci-dra7xx.c |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/host/pci-dra7xx.c b/drivers/pci/host/pci-dra7xx.c
index 80db09e..d8b6d66 100644
--- a/drivers/pci/host/pci-dra7xx.c
+++ b/drivers/pci/host/pci-dra7xx.c
@@ -384,7 +384,7 @@ static int __init dra7xx_pcie_probe(struct platform_device 
*pdev)
ret = pm_runtime_get_sync(dev);
if (IS_ERR_VALUE(ret)) {
dev_err(dev, "pm_runtime_get_sync failed\n");
-   goto err_phy;
+   goto err_get_sync;
}
 
reg = dra7xx_pcie_readl(dra7xx, PCIECTRL_DRA7XX_CONF_DEVICE_CMD);
@@ -401,6 +401,8 @@ static int __init dra7xx_pcie_probe(struct platform_device 
*pdev)
 
 err_add_port:
pm_runtime_put(dev);
+
+err_get_sync:
pm_runtime_disable(dev);
 
 err_phy:
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 3/3] PCI: host: pci-dra7xx: Idle the module by disabling MSE bit

2015-07-26 Thread Kishon Vijay Abraham I
DRA7xx require MSE bit to be cleared to set the master in
standby mode. (In DRA7xx TRM_vE, section 24.9.4.5.2.2.1 PCIe
Controller Master Standby Behavior advises to use the clearing
of the local MSE bit to set the master in standby. Without this
some of the clocks do not idle).

Cleared the MSE bit on suspend and enabled it back on resume.
Clearing MSE bit is required to get clocks to be idled after
suspend.

Signed-off-by: Kishon Vijay Abraham I 
Signed-off-by: Sekhar Nori 
---
 drivers/pci/host/pci-dra7xx.c |   23 +--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/host/pci-dra7xx.c b/drivers/pci/host/pci-dra7xx.c
index 7599201..7acc833 100644
--- a/drivers/pci/host/pci-dra7xx.c
+++ b/drivers/pci/host/pci-dra7xx.c
@@ -83,6 +83,17 @@ static inline void dra7xx_pcie_writel(struct dra7xx_pcie 
*pcie, u32 offset,
writel(value, pcie->base + offset);
 }
 
+static inline u32 dra7xx_pcie_readl_rc(struct pcie_port *pp, u32 offset)
+{
+   return readl(pp->dbi_base + offset);
+}
+
+static inline void dra7xx_pcie_writel_rc(struct pcie_port *pp, u32 offset,
+u32 value)
+{
+   writel(value, pp->dbi_base + offset);
+}
+
 static int dra7xx_pcie_link_up(struct pcie_port *pp)
 {
struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp);
@@ -438,8 +449,12 @@ static int dra7xx_pcie_suspend(struct device *dev)
 {
struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
struct pcie_port *pp = &dra7xx->pp;
+   u32 val;
 
-   dw_pcie_suspend_rc(pp);
+   /* clear MSE */
+   val = dra7xx_pcie_readl_rc(pp, PCI_COMMAND);
+   val &= ~PCI_COMMAND_MEMORY;
+   dra7xx_pcie_writel_rc(pp, PCI_COMMAND, val);
 
return 0;
 }
@@ -448,8 +463,12 @@ static int dra7xx_pcie_resume(struct device *dev)
 {
struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
struct pcie_port *pp = &dra7xx->pp;
+   u32 val;
 
-   dw_pcie_resume_rc(pp);
+   /* clear MSE */
+   val = dra7xx_pcie_readl_rc(pp, PCI_COMMAND);
+   val |= PCI_COMMAND_MEMORY;
+   dra7xx_pcie_writel_rc(pp, PCI_COMMAND, val);
 
return 0;
 }
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:irq/core] avr32/at32ap: Consolidate chained IRQ handler install/remove

2015-07-26 Thread tip-bot for Thomas Gleixner
Commit-ID:  4365160def95ef2f5da9b5cc5660e5747e5e1956
Gitweb: http://git.kernel.org/tip/4365160def95ef2f5da9b5cc5660e5747e5e1956
Author: Thomas Gleixner 
AuthorDate: Mon, 13 Jul 2015 20:31:09 +
Committer:  Thomas Gleixner 
CommitDate: Sun, 26 Jul 2015 11:47:25 +0200

avr32/at32ap: Consolidate chained IRQ handler install/remove

Chained irq handlers usually set up handler data as well. We now have
a function to set both under irq_desc->lock. Replace the two calls
with one.

Search and conversion was done with coccinelle.

Reported-by: Russell King 
Signed-off-by: Thomas Gleixner 
Acked-by: Hans-Christian Egtvedt 
Cc: Haavard Skinnemoen 
Cc: Jiang Liu 
Cc: Julia Lawall 
Link: http://lkml.kernel.org/r/20150713100606.351640...@linutronix.de
Signed-off-by: Thomas Gleixner 
---
 arch/avr32/mach-at32ap/pio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/avr32/mach-at32ap/pio.c b/arch/avr32/mach-at32ap/pio.c
index 903c7d8..6c7035a 100644
--- a/arch/avr32/mach-at32ap/pio.c
+++ b/arch/avr32/mach-at32ap/pio.c
@@ -312,7 +312,6 @@ gpio_irq_setup(struct pio_device *pio, int irq, int 
gpio_irq)
unsignedi;
 
irq_set_chip_data(irq, pio);
-   irq_set_handler_data(irq, (void *)gpio_irq);
 
for (i = 0; i < 32; i++, gpio_irq++) {
irq_set_chip_data(gpio_irq, pio);
@@ -320,7 +319,8 @@ gpio_irq_setup(struct pio_device *pio, int irq, int 
gpio_irq)
 handle_simple_irq);
}
 
-   irq_set_chained_handler(irq, gpio_irq_handler);
+   irq_set_chained_handler_and_data(irq, gpio_irq_handler,
+(void *)gpio_irq);
 }
 
 /*--*/
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:irq/core] irqchip/bcm7120-l2: Fix interrupt status for multiple parent IRQs

2015-07-26 Thread tip-bot for Florian Fainelli
Commit-ID:  0aef3997e12a10d4dfb6e01133e2fe478b9aa5eb
Gitweb: http://git.kernel.org/tip/0aef3997e12a10d4dfb6e01133e2fe478b9aa5eb
Author: Florian Fainelli 
AuthorDate: Thu, 23 Jul 2015 15:52:21 -0700
Committer:  Thomas Gleixner 
CommitDate: Mon, 27 Jul 2015 08:09:38 +0200

irqchip/bcm7120-l2: Fix interrupt status for multiple parent IRQs

Our irq-bcm7120-l2 interrupt controller driver utilizes the same handler
function for the different parent interrupts it services: UPG_MAIN, UPG_BSC for
instance.

The problem is that function reads the IRQSTAT register which can combine
interrupt causes for different parent interrupts, such that we can end-up in
the following situation:

- CPU takes an interrupt
- bcm7120_l2_intc_irq_handle() reads IRQSTAT
- generic_handle_irq() is invoked
- there are still pending interrupts flagged in IRQSTAT from a different parent
- handle_bad_irq() is invoked for these since they come from a different 
irq_desc/irq

In order to fix this, make sure that we always mask IRQSTAT with the
appropriate bits that correspond go the parent interrupt source this is coming
from. To simplify things, associate an unique structure per parent interrupt
handler to avoid multiplying the number of lookups.

Fixes: a5042de2688d ("irqchip: bcm7120-l2: Add Broadcom BCM7120-style Level 2 
interrupt controller")
Signed-off-by: Florian Fainelli 
Cc: linux-m...@linux-mips.org
Cc: cerne...@gmail.com
Cc: ja...@lakedaemon.net
Cc: bcm-kernel-feedback-l...@broadcom.com
Cc: gregory.0...@gmail.com
Cc: computersforpe...@gmail.com
Link: 
http://lkml.kernel.org/r/1437691941-3100-1-git-send-email-f.faine...@gmail.com
Signed-off-by: Thomas Gleixner 
---
 drivers/irqchip/irq-bcm7120-l2.c | 52 ++--
 1 file changed, 39 insertions(+), 13 deletions(-)

diff --git a/drivers/irqchip/irq-bcm7120-l2.c b/drivers/irqchip/irq-bcm7120-l2.c
index c885a5c..d3f9769 100644
--- a/drivers/irqchip/irq-bcm7120-l2.c
+++ b/drivers/irqchip/irq-bcm7120-l2.c
@@ -37,6 +37,11 @@
 #define MAX_MAPPINGS   (MAX_WORDS * 2)
 #define IRQS_PER_WORD  32
 
+struct bcm7120_l1_intc_data {
+   struct bcm7120_l2_intc_data *b;
+   u32 irq_map_mask[MAX_WORDS];
+};
+
 struct bcm7120_l2_intc_data {
unsigned int n_words;
void __iomem *map_base[MAX_MAPPINGS];
@@ -46,14 +51,15 @@ struct bcm7120_l2_intc_data {
struct irq_domain *domain;
bool can_wake;
u32 irq_fwd_mask[MAX_WORDS];
-   u32 irq_map_mask[MAX_WORDS];
+   struct bcm7120_l1_intc_data *l1_data;
int num_parent_irqs;
const __be32 *map_mask_prop;
 };
 
 static void bcm7120_l2_intc_irq_handle(unsigned int irq, struct irq_desc *desc)
 {
-   struct bcm7120_l2_intc_data *b = irq_desc_get_handler_data(desc);
+   struct bcm7120_l1_intc_data *data = irq_desc_get_handler_data(desc);
+   struct bcm7120_l2_intc_data *b = data->b;
struct irq_chip *chip = irq_desc_get_chip(desc);
unsigned int idx;
 
@@ -68,7 +74,8 @@ static void bcm7120_l2_intc_irq_handle(unsigned int irq, 
struct irq_desc *desc)
 
irq_gc_lock(gc);
pending = irq_reg_readl(gc, b->stat_offset[idx]) &
-   gc->mask_cache;
+   gc->mask_cache &
+   data->irq_map_mask[idx];
irq_gc_unlock(gc);
 
for_each_set_bit(hwirq, &pending, IRQS_PER_WORD) {
@@ -104,8 +111,9 @@ static void bcm7120_l2_intc_resume(struct irq_chip_generic 
*gc)
 
 static int bcm7120_l2_intc_init_one(struct device_node *dn,
struct bcm7120_l2_intc_data *data,
-   int irq)
+   int irq, u32 *valid_mask)
 {
+   struct bcm7120_l1_intc_data *l1_data = &data->l1_data[irq];
int parent_irq;
unsigned int idx;
 
@@ -117,20 +125,28 @@ static int bcm7120_l2_intc_init_one(struct device_node 
*dn,
 
/* For multiple parent IRQs with multiple words, this looks like:
 * 
+*
+* We need to associate a given parent interrupt with its corresponding
+* map_mask in order to mask the status register with it because we
+* have the same handler being called for multiple parent interrupts.
+*
+* This is typically something needed on BCM7xxx (STB chips).
 */
for (idx = 0; idx < data->n_words; idx++) {
if (data->map_mask_prop) {
-   data->irq_map_mask[idx] |=
+   l1_data->irq_map_mask[idx] |=
be32_to_cpup(data->map_mask_prop +
 irq * data->n_words + idx);
} else {
-   data->irq_map_mask[idx] = 0x;
+   l1_data->irq_map_mask[idx] = 0x;
}
+   valid_mask[idx] |= l1_data->irq_ma

[tip:irq/core] irqchip/bcm7120-l2: Perform suspend/ resume even without installed child IRQs

2015-07-26 Thread tip-bot for Brian Norris
Commit-ID:  fd537766715e9b6bf7ff07abb22f4817201433db
Gitweb: http://git.kernel.org/tip/fd537766715e9b6bf7ff07abb22f4817201433db
Author: Brian Norris 
AuthorDate: Wed, 22 Jul 2015 16:21:40 -0700
Committer:  Thomas Gleixner 
CommitDate: Mon, 27 Jul 2015 08:09:38 +0200

irqchip/bcm7120-l2: Perform suspend/resume even without installed child IRQs

Make use of the new irq_chip_generic suspend/resume callbacks.

This is required because if there are no installed child IRQs for this
chip, the irq_chip::irq_{suspend,resume} functions will not be called.
However, we still need to save/restore the forwarding mask, to enable
the top-level GIC interrupt; otherwise, we lose UART output after S3
resume.

In addition to refactoring the callbacks, we have to self-initialize the
mask cache, since the genirq core also doesn't initialize this until the
first child IRQ is installed.

The original problem report is described in extra detail here:
http://lkml.kernel.org/g/20150619224123.GL4917@ld-irv-0074

Signed-off-by: Brian Norris 
Tested-by: Florian Fainelli 
Cc: Gregory Fong 
Cc: bcm-kernel-feedback-l...@broadcom.com
Cc: linux-m...@linux-mips.org
Cc: Kevin Cernekee 
Cc: Jason Cooper 
Link: 
http://lkml.kernel.org/r/1437607300-40858-2-git-send-email-computersforpe...@gmail.com
Signed-off-by: Thomas Gleixner 
---
 drivers/irqchip/irq-bcm7120-l2.c | 21 +
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/irqchip/irq-bcm7120-l2.c b/drivers/irqchip/irq-bcm7120-l2.c
index 88c9719..c885a5c 100644
--- a/drivers/irqchip/irq-bcm7120-l2.c
+++ b/drivers/irqchip/irq-bcm7120-l2.c
@@ -80,11 +80,10 @@ static void bcm7120_l2_intc_irq_handle(unsigned int irq, 
struct irq_desc *desc)
chained_irq_exit(chip, desc);
 }
 
-static void bcm7120_l2_intc_suspend(struct irq_data *d)
+static void bcm7120_l2_intc_suspend(struct irq_chip_generic *gc)
 {
-   struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
-   struct irq_chip_type *ct = irq_data_get_chip_type(d);
struct bcm7120_l2_intc_data *b = gc->private;
+   struct irq_chip_type *ct = gc->chip_types;
 
irq_gc_lock(gc);
if (b->can_wake)
@@ -93,10 +92,9 @@ static void bcm7120_l2_intc_suspend(struct irq_data *d)
irq_gc_unlock(gc);
 }
 
-static void bcm7120_l2_intc_resume(struct irq_data *d)
+static void bcm7120_l2_intc_resume(struct irq_chip_generic *gc)
 {
-   struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
-   struct irq_chip_type *ct = irq_data_get_chip_type(d);
+   struct irq_chip_type *ct = gc->chip_types;
 
/* Restore the saved mask */
irq_gc_lock(gc);
@@ -279,8 +277,15 @@ int __init bcm7120_l2_intc_probe(struct device_node *dn,
ct->chip.irq_mask = irq_gc_mask_clr_bit;
ct->chip.irq_unmask = irq_gc_mask_set_bit;
ct->chip.irq_ack = irq_gc_noop;
-   ct->chip.irq_suspend = bcm7120_l2_intc_suspend;
-   ct->chip.irq_resume = bcm7120_l2_intc_resume;
+   gc->suspend = bcm7120_l2_intc_suspend;
+   gc->resume = bcm7120_l2_intc_resume;
+
+   /*
+* Initialize mask-cache, in case we need it for
+* saving/restoring fwd mask even w/o any child interrupts
+* installed
+*/
+   gc->mask_cache = irq_reg_readl(gc, ct->regs.mask);
 
if (data->can_wake) {
/* This IRQ chip can wake the system, set all
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:irq/core] genirq: Add chip_[suspend|resume] PM support to irq_chip

2015-07-26 Thread tip-bot for Brian Norris
Commit-ID:  be9b22b6a7e6725162c64155a08b71f0654b675c
Gitweb: http://git.kernel.org/tip/be9b22b6a7e6725162c64155a08b71f0654b675c
Author: Brian Norris 
AuthorDate: Wed, 22 Jul 2015 16:21:39 -0700
Committer:  Thomas Gleixner 
CommitDate: Mon, 27 Jul 2015 08:09:38 +0200

genirq: Add chip_[suspend|resume] PM support to irq_chip

Some (admittedly odd) irqchips perform functions that are not directly
related to any of their child IRQ lines, and therefore need to perform
some tasks during suspend/resume regardless of whether there are
any "installed" interrupts for the irqchip. However, the current
generic-chip framework does not call the chip's irq_{suspend,resume}
when there are no interrupts installed (this makes sense, because there
are no irq_data objects for such a call to be made).

More specifically, irq-bcm7120-l2 configures both a forwarding mask
(which affects other top-level GIC IRQs) and a second-level interrupt
mask (for managing its own child interrupts). The former must be
saved/restored on suspend/resume, even when there's nothing to do for
the latter.

This patch adds a new set of suspend/resume hooks to irq_chip_generic,
to help represent *chip* suspend/resume, rather than IRQ suspend/resume.
These callbacks will always be called for an IRQ chip (regardless of the
installed interrupts) and are based on the per-chip irq_chip_generic
struct, rather than the per-IRQ irq_data struct.

The original problem report is described in extra detail here:
http://lkml.kernel.org/g/20150619224123.GL4917@ld-irv-0074

Signed-off-by: Brian Norris 
Tested-by: Florian Fainelli 
Cc: Gregory Fong 
Cc: bcm-kernel-feedback-l...@broadcom.com
Cc: linux-m...@linux-mips.org
Cc: Kevin Cernekee 
Cc: Jason Cooper 
Link: 
http://lkml.kernel.org/r/1437607300-40858-1-git-send-email-computersforpe...@gmail.com
Signed-off-by: Thomas Gleixner 
---
 include/linux/irq.h   | 14 --
 kernel/irq/generic-chip.c |  6 ++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/include/linux/irq.h b/include/linux/irq.h
index 5284cb1..2c8730a 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -324,8 +324,10 @@ static inline irq_hw_number_t irqd_to_hwirq(struct 
irq_data *d)
  * @irq_bus_sync_unlock:function to sync and unlock slow bus (i2c) chips
  * @irq_cpu_online:configure an interrupt source for a secondary CPU
  * @irq_cpu_offline:   un-configure an interrupt source for a secondary CPU
- * @irq_suspend:   function called from core code on suspend once per chip
- * @irq_resume:function called from core code on resume once 
per chip
+ * @irq_suspend:   function called from core code on suspend once per
+ * chip, when one or more interrupts are installed
+ * @irq_resume:function called from core code on resume once 
per chip,
+ * when one ore more interrupts are installed
  * @irq_pm_shutdown:   function called from core code on shutdown once per chip
  * @irq_calc_mask: Optional function to set irq_data.mask for special cases
  * @irq_print_chip:optional to print special chip info in show_interrupts
@@ -760,6 +762,12 @@ struct irq_chip_type {
  * @reg_base:  Register base address (virtual)
  * @reg_readl: Alternate I/O accessor (defaults to readl if NULL)
  * @reg_writel:Alternate I/O accessor (defaults to writel if 
NULL)
+ * @suspend:   Function called from core code on suspend once per
+ * chip; can be useful instead of irq_chip::suspend to
+ * handle chip details even when no interrupts are in use
+ * @resume:Function called from core code on resume once per chip;
+ * can be useful instead of irq_chip::suspend to handle
+ * chip details even when no interrupts are in use
  * @irq_base:  Interrupt base nr for this chip
  * @irq_cnt:   Number of interrupts handled by this chip
  * @mask_cache:Cached mask register shared between all chip 
types
@@ -786,6 +794,8 @@ struct irq_chip_generic {
void __iomem*reg_base;
u32 (*reg_readl)(void __iomem *addr);
void(*reg_writel)(u32 val, void __iomem *addr);
+   void(*suspend)(struct irq_chip_generic *gc);
+   void(*resume)(struct irq_chip_generic *gc);
unsigned intirq_base;
unsigned intirq_cnt;
u32 mask_cache;
diff --git a/kernel/irq/generic-chip.c b/kernel/irq/generic-chip.c
index 15b370d..abd286a 100644
--- a/kernel/irq/generic-chip.c
+++ b/kernel/irq/generic-chip.c
@@ -553,6 +553,9 @@ static int irq_gc_suspend(void)
if (data)
ct->chip.irq_suspend(data);
}
+
+   if (gc->suspend)
+   gc->suspend(gc);
}

[tip:irq/core] irqchip/gic: Remove redundant gic_set_irqchip_flags

2015-07-26 Thread tip-bot for Sudeep Holla
Commit-ID:  0d3f2c92e004c67404fabea19728c1962b777bd6
Gitweb: http://git.kernel.org/tip/0d3f2c92e004c67404fabea19728c1962b777bd6
Author: Sudeep Holla 
AuthorDate: Wed, 15 Jul 2015 15:38:29 +0100
Committer:  Thomas Gleixner 
CommitDate: Mon, 27 Jul 2015 08:09:38 +0200

irqchip/gic: Remove redundant gic_set_irqchip_flags

Now that the GIC chip implementation enables IRQCHIP_SKIP_SET_WAKE and
IRQCHIP_MASK_ON_SUSPEND by default, the platforms requiring them need
not override the irqchip flags as before.

This patch removes all the users of gic_set_irqchip_flags and the
function itself.

Signed-off-by: Sudeep Holla 
Acked-by: Linus Walleij 
Cc: Marc Zyngier 
Cc: Simon Horman 
Cc: Jason Cooper 
Cc: Michal Simek 
Cc: Magnus Damm 
Cc: Gregory CLEMENT 
Cc: Geert Uytterhoeven 
Cc: Lorenzo Pieralisi 
Cc: linux-arm-ker...@lists.infradead.org
Link: 
http://lkml.kernel.org/r/1436971109-20189-2-git-send-email-sudeep.ho...@arm.com
Signed-off-by: Thomas Gleixner 
---
 arch/arm/mach-shmobile/intc-sh73a0.c   | 1 -
 arch/arm/mach-shmobile/setup-r8a7779.c | 1 -
 arch/arm/mach-ux500/cpu.c  | 1 -
 arch/arm/mach-zynq/common.c| 1 -
 drivers/irqchip/irq-gic.c  | 5 -
 include/linux/irqchip/arm-gic.h| 1 -
 6 files changed, 10 deletions(-)

diff --git a/arch/arm/mach-shmobile/intc-sh73a0.c 
b/arch/arm/mach-shmobile/intc-sh73a0.c
index fd63ae6..151a71a 100644
--- a/arch/arm/mach-shmobile/intc-sh73a0.c
+++ b/arch/arm/mach-shmobile/intc-sh73a0.c
@@ -313,7 +313,6 @@ void __init sh73a0_init_irq(void)
void __iomem *gic_cpu_base = IOMEM(0xf100);
void __iomem *intevtsa = ioremap_nocache(0xffd20100, PAGE_SIZE);
 
-   gic_set_irqchip_flags(IRQCHIP_SKIP_SET_WAKE);
gic_init(0, 29, gic_dist_base, gic_cpu_base);
 
register_intc_controller(&intcs_desc);
diff --git a/arch/arm/mach-shmobile/setup-r8a7779.c 
b/arch/arm/mach-shmobile/setup-r8a7779.c
index c03e562..aea5cff 100644
--- a/arch/arm/mach-shmobile/setup-r8a7779.c
+++ b/arch/arm/mach-shmobile/setup-r8a7779.c
@@ -719,7 +719,6 @@ void __init r8a7779_init_irq_dt(void)
void __iomem *gic_dist_base = ioremap_nocache(0xf0001000, 0x1000);
void __iomem *gic_cpu_base = ioremap_nocache(0xf100, 0x1000);
 #endif
-   gic_set_irqchip_flags(IRQCHIP_SKIP_SET_WAKE);
 
 #ifdef CONFIG_ARCH_SHMOBILE_LEGACY
gic_init(0, 29, gic_dist_base, gic_cpu_base);
diff --git a/arch/arm/mach-ux500/cpu.c b/arch/arm/mach-ux500/cpu.c
index e31d3d6..6cb10c7 100644
--- a/arch/arm/mach-ux500/cpu.c
+++ b/arch/arm/mach-ux500/cpu.c
@@ -56,7 +56,6 @@ void __init ux500_init_irq(void)
struct device_node *np;
struct resource r;
 
-   gic_set_irqchip_flags(IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MASK_ON_SUSPEND);
irqchip_init();
np = of_find_compatible_node(NULL, NULL, "stericsson,db8500-prcmu");
of_address_to_resource(np, 0, &r);
diff --git a/arch/arm/mach-zynq/common.c b/arch/arm/mach-zynq/common.c
index 616d584..2ad1acc 100644
--- a/arch/arm/mach-zynq/common.c
+++ b/arch/arm/mach-zynq/common.c
@@ -186,7 +186,6 @@ static void __init zynq_map_io(void)
 
 static void __init zynq_irq_init(void)
 {
-   gic_set_irqchip_flags(IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MASK_ON_SUSPEND);
irqchip_init();
 }
 
diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
index 39ff8df..80fde37 100644
--- a/drivers/irqchip/irq-gic.c
+++ b/drivers/irqchip/irq-gic.c
@@ -881,11 +881,6 @@ static const struct irq_domain_ops gic_irq_domain_ops = {
.xlate = gic_irq_domain_xlate,
 };
 
-void gic_set_irqchip_flags(unsigned long flags)
-{
-   gic_chip.flags |= flags;
-}
-
 void __init gic_init_bases(unsigned int gic_nr, int irq_start,
   void __iomem *dist_base, void __iomem *cpu_base,
   u32 percpu_offset, struct device_node *node)
diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
index 9de976b..61a2007 100644
--- a/include/linux/irqchip/arm-gic.h
+++ b/include/linux/irqchip/arm-gic.h
@@ -95,7 +95,6 @@
 
 struct device_node;
 
-void gic_set_irqchip_flags(unsigned long flags);
 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
u32 offset, struct device_node *);
 void gic_cascade_irq(unsigned int gic_nr, unsigned int irq);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:irq/core] irqchip: Appropriate __init annotation for const data

2015-07-26 Thread tip-bot for Nicolas Pitre
Commit-ID:  c376023b7096e76ac4d5526105cf9be8743bead9
Gitweb: http://git.kernel.org/tip/c376023b7096e76ac4d5526105cf9be8743bead9
Author: Nicolas Pitre 
AuthorDate: Fri, 24 Jul 2015 15:24:45 -0400
Committer:  Thomas Gleixner 
CommitDate: Mon, 27 Jul 2015 08:09:38 +0200

irqchip: Appropriate __init annotation for const data

Init data marked const should be annotated with __initconst for
correctness and not __initdata.  And for those already __initconst,
they should be qualified as const at the compiler level too.
This also fixes LTO builds that otherwise fail with section mismatch
errors.

Signed-off-by: Nicolas Pitre 
Cc: Jason Cooper 
Link: http://lkml.kernel.org/r/alpine.lfd.2.20.1507241511551.1...@knanqh.ubzr
Signed-off-by: Thomas Gleixner 

---
 drivers/irqchip/irq-atmel-aic.c  | 2 +-
 drivers/irqchip/irq-atmel-aic5.c | 2 +-
 drivers/irqchip/irq-bcm2835.c| 8 
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/irqchip/irq-atmel-aic.c b/drivers/irqchip/irq-atmel-aic.c
index dbbf30a..8a0c7f2 100644
--- a/drivers/irqchip/irq-atmel-aic.c
+++ b/drivers/irqchip/irq-atmel-aic.c
@@ -225,7 +225,7 @@ static void __init at91sam9g45_aic_irq_fixup(struct 
device_node *root)
aic_common_rtt_irq_fixup(root);
 }
 
-static const struct of_device_id __initdata aic_irq_fixups[] = {
+static const struct of_device_id aic_irq_fixups[] __initconst = {
{ .compatible = "atmel,at91rm9200", .data = at91rm9200_aic_irq_fixup },
{ .compatible = "atmel,at91sam9g45", .data = at91sam9g45_aic_irq_fixup 
},
{ .compatible = "atmel,at91sam9n12", .data = at91rm9200_aic_irq_fixup },
diff --git a/drivers/irqchip/irq-atmel-aic5.c b/drivers/irqchip/irq-atmel-aic5.c
index ff2e832..9da9942 100644
--- a/drivers/irqchip/irq-atmel-aic5.c
+++ b/drivers/irqchip/irq-atmel-aic5.c
@@ -290,7 +290,7 @@ static void __init sama5d3_aic_irq_fixup(struct device_node 
*root)
aic_common_rtc_irq_fixup(root);
 }
 
-static const struct of_device_id __initdata aic5_irq_fixups[] = {
+static const struct of_device_id aic5_irq_fixups[] __initconst = {
{ .compatible = "atmel,sama5d3", .data = sama5d3_aic_irq_fixup },
{ .compatible = "atmel,sama5d4", .data = sama5d3_aic_irq_fixup },
{ /* sentinel */ },
diff --git a/drivers/irqchip/irq-bcm2835.c b/drivers/irqchip/irq-bcm2835.c
index a36ba96..ca35171 100644
--- a/drivers/irqchip/irq-bcm2835.c
+++ b/drivers/irqchip/irq-bcm2835.c
@@ -75,10 +75,10 @@
 #define NR_BANKS   3
 #define IRQS_PER_BANK  32
 
-static int reg_pending[] __initconst = { 0x00, 0x04, 0x08 };
-static int reg_enable[] __initconst = { 0x18, 0x10, 0x14 };
-static int reg_disable[] __initconst = { 0x24, 0x1c, 0x20 };
-static int bank_irqs[] __initconst = { 8, 32, 32 };
+static const int reg_pending[] __initconst = { 0x00, 0x04, 0x08 };
+static const int reg_enable[] __initconst = { 0x18, 0x10, 0x14 };
+static const int reg_disable[] __initconst = { 0x24, 0x1c, 0x20 };
+static const int bank_irqs[] __initconst = { 8, 32, 32 };
 
 static const int shortcuts[] = {
7, 9, 10, 18, 19,   /* Bank 1 */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:irq/core] genirq: Export irq_[get|set]_irqchip_state()

2015-07-26 Thread tip-bot for Bjorn Andersson
Commit-ID:  1ee4fb3ee1e47f2b3c294ded383a3cd9cc2decd4
Gitweb: http://git.kernel.org/tip/1ee4fb3ee1e47f2b3c294ded383a3cd9cc2decd4
Author: Bjorn Andersson 
AuthorDate: Wed, 22 Jul 2015 12:43:04 -0700
Committer:  Thomas Gleixner 
CommitDate: Mon, 27 Jul 2015 08:09:38 +0200

genirq: Export irq_[get|set]_irqchip_state()

Export these functions to be able to build the Qualcomm family A PMIC
gpio and mpp drivers as modules.

[ tglx: Made them GPL exports ]

Signed-off-by: Bjorn Andersson 
Reviewed-by: Mark Brown 
Cc: Marc Zyngier 
Cc: 
Cc: 
Cc: Srinivas Kandagatla 
Cc: Linus Walleij 
Link: 
http://lkml.kernel.org/r/1437594184-22966-1-git-send-email-bjorn.anders...@sonymobile.com
Signed-off-by: Thomas Gleixner 
---
 kernel/irq/manage.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 886f115..ad1b064 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -1877,6 +1877,7 @@ int irq_get_irqchip_state(unsigned int irq, enum 
irqchip_irq_state which,
irq_put_desc_busunlock(desc, flags);
return err;
 }
+EXPORT_SYMBOL_GPL(irq_get_irqchip_state);
 
 /**
  * irq_set_irqchip_state - set the state of a forwarded interrupt.
@@ -1922,3 +1923,4 @@ int irq_set_irqchip_state(unsigned int irq, enum 
irqchip_irq_state which,
irq_put_desc_busunlock(desc, flags);
return err;
 }
+EXPORT_SYMBOL_GPL(irq_set_irqchip_state);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] usb: gadget: Convert use of __constant_cpu_to_le16 to cpu_to_le16

2015-07-26 Thread Vaishali Thakkar
On Sat, Jun 6, 2015 at 7:02 AM, Vaishali Thakkar  wrote:
> In big endian cases, macro cpu_to_le16 unfolds to __swab16 which
> provides special case for constants. In little endian cases,
> __constant_cpu_to_le16 and cpu_to_le16 expand directly to the
> same expression. So, replace __constant_cpu_to_le16 with
> cpu_to_le16 with the goal of getting rid of the definition of
> __constant_cpu_to_le16 completely.
>
> The semantic patch that performs this transformation is as follows:
>
> @@expression x;@@
>
> - __constant_cpu_to_le16(x)
> + cpu_to_le16(x)

Hello

This is just a friendly reminder. As this patch was sent before almost 50 days
with the aim of removing constant_ definitions completely
and not yet applied, is it missed?? Do I need to resend this patch?

Thank You.

> Signed-off-by: Vaishali Thakkar 
> ---
>  drivers/usb/gadget/legacy/audio.c |  6 +++---
>  drivers/usb/gadget/legacy/dbgp.c  | 10 +-
>  drivers/usb/gadget/legacy/gmidi.c |  6 +++---
>  drivers/usb/gadget/legacy/nokia.c |  6 +++---
>  4 files changed, 14 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/usb/gadget/legacy/audio.c 
> b/drivers/usb/gadget/legacy/audio.c
> index f289caf..b8095bf 100644
> --- a/drivers/usb/gadget/legacy/audio.c
> +++ b/drivers/usb/gadget/legacy/audio.c
> @@ -124,7 +124,7 @@ static struct usb_device_descriptor device_desc = {
> .bLength =  sizeof device_desc,
> .bDescriptorType =  USB_DT_DEVICE,
>
> -   .bcdUSB =   __constant_cpu_to_le16(0x200),
> +   .bcdUSB =   cpu_to_le16(0x200),
>
>  #ifdef CONFIG_GADGET_UAC1
> .bDeviceClass = USB_CLASS_PER_INTERFACE,
> @@ -141,8 +141,8 @@ static struct usb_device_descriptor device_desc = {
>  * we support.  (As does bNumConfigurations.)  These values can
>  * also be overridden by module parameters.
>  */
> -   .idVendor = __constant_cpu_to_le16(AUDIO_VENDOR_NUM),
> -   .idProduct =__constant_cpu_to_le16(AUDIO_PRODUCT_NUM),
> +   .idVendor = cpu_to_le16(AUDIO_VENDOR_NUM),
> +   .idProduct =cpu_to_le16(AUDIO_PRODUCT_NUM),
> /* .bcdDevice = f(hardware) */
> /* .iManufacturer = DYNAMIC */
> /* .iProduct = DYNAMIC */
> diff --git a/drivers/usb/gadget/legacy/dbgp.c 
> b/drivers/usb/gadget/legacy/dbgp.c
> index 204b10b..5231a32 100644
> --- a/drivers/usb/gadget/legacy/dbgp.c
> +++ b/drivers/usb/gadget/legacy/dbgp.c
> @@ -35,10 +35,10 @@ static struct dbgp {
>  static struct usb_device_descriptor device_desc = {
> .bLength = sizeof device_desc,
> .bDescriptorType = USB_DT_DEVICE,
> -   .bcdUSB = __constant_cpu_to_le16(0x0200),
> +   .bcdUSB = cpu_to_le16(0x0200),
> .bDeviceClass = USB_CLASS_VENDOR_SPEC,
> -   .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_ID),
> -   .idProduct = __constant_cpu_to_le16(DRIVER_PRODUCT_ID),
> +   .idVendor = cpu_to_le16(DRIVER_VENDOR_ID),
> +   .idProduct = cpu_to_le16(DRIVER_PRODUCT_ID),
> .bNumConfigurations = 1,
>  };
>
> @@ -251,7 +251,7 @@ static int dbgp_configure_endpoints(struct usb_gadget 
> *gadget)
>
> dbgp.i_ep->driver_data = gadget;
> i_desc.wMaxPacketSize =
> -   __constant_cpu_to_le16(USB_DEBUG_MAX_PACKET_SIZE);
> +   cpu_to_le16(USB_DEBUG_MAX_PACKET_SIZE);
>
> dbgp.o_ep = usb_ep_autoconfig(gadget, &o_desc);
> if (!dbgp.o_ep) {
> @@ -262,7 +262,7 @@ static int dbgp_configure_endpoints(struct usb_gadget 
> *gadget)
>
> dbgp.o_ep->driver_data = gadget;
> o_desc.wMaxPacketSize =
> -   __constant_cpu_to_le16(USB_DEBUG_MAX_PACKET_SIZE);
> +   cpu_to_le16(USB_DEBUG_MAX_PACKET_SIZE);
>
> dbg_desc.bDebugInEndpoint = i_desc.bEndpointAddress;
> dbg_desc.bDebugOutEndpoint = o_desc.bEndpointAddress;
> diff --git a/drivers/usb/gadget/legacy/gmidi.c 
> b/drivers/usb/gadget/legacy/gmidi.c
> index da19c48..650568d 100644
> --- a/drivers/usb/gadget/legacy/gmidi.c
> +++ b/drivers/usb/gadget/legacy/gmidi.c
> @@ -88,10 +88,10 @@ MODULE_PARM_DESC(out_ports, "Number of MIDI output 
> ports");
>  static struct usb_device_descriptor device_desc = {
> .bLength =  USB_DT_DEVICE_SIZE,
> .bDescriptorType =  USB_DT_DEVICE,
> -   .bcdUSB =   __constant_cpu_to_le16(0x0200),
> +   .bcdUSB =   cpu_to_le16(0x0200),
> .bDeviceClass = USB_CLASS_PER_INTERFACE,
> -   .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_NUM),
> -   .idProduct =__constant_cpu_to_le16(DRIVER_PRODUCT_NUM),
> +   .idVendor = cpu_to_le16(DRIVER_VENDOR_NUM),
> +   .idProduct =cpu_to_le16(DRIVER_PRODUCT_NUM),
> /* .iManufacturer = DYNAMIC */
> /* .iProduct =  DYNAMIC */
> .bNumConfigurations =   1,
> diff --git a/drivers/usb/gadget/legacy/nokia.c 
> b/dri

[tip:irq/core] irqchip/gic: Enable SKIP_SET_WAKE and MASK_ON_SUSPEND

2015-07-26 Thread tip-bot for Sudeep Holla
Commit-ID:  aec89ef72ba6c94420f599dcb684ed66937cdacf
Gitweb: http://git.kernel.org/tip/aec89ef72ba6c94420f599dcb684ed66937cdacf
Author: Sudeep Holla 
AuthorDate: Wed, 15 Jul 2015 15:38:28 +0100
Committer:  Thomas Gleixner 
CommitDate: Mon, 27 Jul 2015 08:09:37 +0200

irqchip/gic: Enable SKIP_SET_WAKE and MASK_ON_SUSPEND

The GIC controller doesn't provides any facility to configure the wakeup
sources. For the same reason, GIC chip implementation can't provide
irq_set_wake functionality, but that results in the irqchip core
preventing the systems from entering sleep states like "suspend to RAM".

The GICv1/v2 controllers support wakeup events. They signal these wakeup
events even when CPU interface is disabled which means the wakeup
outputs are always enabled with the required logic in always-on domain.
An implementation can powerdown the GIC completely, but then the wake-up
must be relayed to some control logic within the power controller that
acts as wake-up interrupt controller.

Setting the IRQCHIP_SKIP_SET_WAKE flags will ensure that the interrupts
from GIC can work as wakeup interrupts and resume from suspend-to-{idle,
ram}. The wakeup interrupt sources need to use enable_irq_wake() and the
irqchip core will then set the IRQD_WAKEUP_STATE flag.

Also it's always safer to mask all the non wakeup interrupts are masked
at the chip level when suspending. The irqchip infrastructure can handle
masking of those interrupts at the chip level. The chip implementation
just have to indicate that with IRQCHIP_MASK_ON_SUSPEND.

This patch enables IRQCHIP_SKIP_SET_WAKE and IRQCHIP_MASK_ON_SUSPEND so
that the irqchip core allows and handles the power managemant wake up
modes.

Signed-off-by: Sudeep Holla 
Cc: Marc Zyngier 
Cc: Simon Horman 
Cc: Jason Cooper 
Cc: Michal Simek 
Cc: Linus Walleij 
Cc: Magnus Damm 
Cc: Gregory CLEMENT 
Cc: Geert Uytterhoeven 
Cc: Lorenzo Pieralisi 
Cc: linux-arm-ker...@lists.infradead.org
Link: 
http://lkml.kernel.org/r/1436971109-20189-1-git-send-email-sudeep.ho...@arm.com
Signed-off-by: Thomas Gleixner 
---
 drivers/irqchip/irq-gic.c   | 4 +++-
 drivers/irqchip/irq-hip04.c | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
index cadd862..39ff8df 100644
--- a/drivers/irqchip/irq-gic.c
+++ b/drivers/irqchip/irq-gic.c
@@ -324,7 +324,9 @@ static struct irq_chip gic_chip = {
 #endif
.irq_get_irqchip_state  = gic_irq_get_irqchip_state,
.irq_set_irqchip_state  = gic_irq_set_irqchip_state,
-   .flags  = IRQCHIP_SET_TYPE_MASKED,
+   .flags  = IRQCHIP_SET_TYPE_MASKED |
+ IRQCHIP_SKIP_SET_WAKE |
+ IRQCHIP_MASK_ON_SUSPEND,
 };
 
 void __init gic_cascade_irq(unsigned int gic_nr, unsigned int irq)
diff --git a/drivers/irqchip/irq-hip04.c b/drivers/irqchip/irq-hip04.c
index 55c2c10..a0128c7 100644
--- a/drivers/irqchip/irq-hip04.c
+++ b/drivers/irqchip/irq-hip04.c
@@ -202,7 +202,9 @@ static struct irq_chip hip04_irq_chip = {
 #ifdef CONFIG_SMP
.irq_set_affinity   = hip04_irq_set_affinity,
 #endif
-   .flags  = IRQCHIP_SET_TYPE_MASKED,
+   .flags  = IRQCHIP_SET_TYPE_MASKED |
+ IRQCHIP_SKIP_SET_WAKE |
+ IRQCHIP_MASK_ON_SUSPEND,
 };
 
 static u16 hip04_get_cpumask(struct hip04_irq_data *intc)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:irq/core] avr32/at32ap: Use irq_set_handler_locked()

2015-07-26 Thread tip-bot for Thomas Gleixner
Commit-ID:  4f31dd63e050b777d3f3139197c4b3860aa89301
Gitweb: http://git.kernel.org/tip/4f31dd63e050b777d3f3139197c4b3860aa89301
Author: Thomas Gleixner 
AuthorDate: Mon, 13 Jul 2015 20:31:10 +
Committer:  Thomas Gleixner 
CommitDate: Sun, 26 Jul 2015 11:47:25 +0200

avr32/at32ap: Use irq_set_handler_locked()

Use irq_set_handler_locked() as it avoids a redundant lookup of the
irq descriptor.

Search and replacement was done with coccinelle.

Signed-off-by: Thomas Gleixner 
Acked-by: Hans-Christian Egtvedt 
Cc: Haavard Skinnemoen 
Cc: Jiang Liu 
Cc: Julia Lawall 
Link: http://lkml.kernel.org/r/20150713100606.448031...@linutronix.de
Signed-off-by: Thomas Gleixner 
---
 arch/avr32/mach-at32ap/extint.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/avr32/mach-at32ap/extint.c b/arch/avr32/mach-at32ap/extint.c
index 2d48b6a..d51ff8f 100644
--- a/arch/avr32/mach-at32ap/extint.c
+++ b/arch/avr32/mach-at32ap/extint.c
@@ -128,9 +128,9 @@ static int eic_set_irq_type(struct irq_data *d, unsigned 
int flow_type)
 
irqd_set_trigger_type(d, flow_type);
if (flow_type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
-   __irq_set_handler_locked(irq, handle_level_irq);
+   irq_set_handler_locked(d, handle_level_irq);
else
-   __irq_set_handler_locked(irq, handle_edge_irq);
+   irq_set_handler_locked(d, handle_edge_irq);
 
return IRQ_SET_MASK_OK_NOCOPY;
 }
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:irq/core] avr32/irq: Use irq_desc_get_xxx() to avoid redundant lookup of irq_desc

2015-07-26 Thread tip-bot for Jiang Liu
Commit-ID:  df6e23ae62d46a524ba3db95a201904a01419bdc
Gitweb: http://git.kernel.org/tip/df6e23ae62d46a524ba3db95a201904a01419bdc
Author: Jiang Liu 
AuthorDate: Mon, 13 Jul 2015 20:31:12 +
Committer:  Thomas Gleixner 
CommitDate: Sun, 26 Jul 2015 11:47:25 +0200

avr32/irq: Use irq_desc_get_xxx() to avoid redundant lookup of irq_desc

Use irq_desc_get_xxx() to avoid redundant lookup of irq_desc while we
already have a pointer to corresponding irq_desc.

Signed-off-by: Jiang Liu 
Acked-by: Hans-Christian Egtvedt 
Cc: Haavard Skinnemoen 
Link: http://lkml.kernel.org/r/20150713100606.527106...@linutronix.de
Signed-off-by: Thomas Gleixner 
---
 arch/avr32/mach-at32ap/pio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/avr32/mach-at32ap/pio.c b/arch/avr32/mach-at32ap/pio.c
index 6c7035a..157a5e0 100644
--- a/arch/avr32/mach-at32ap/pio.c
+++ b/arch/avr32/mach-at32ap/pio.c
@@ -286,7 +286,7 @@ static void gpio_irq_handler(unsigned irq, struct irq_desc 
*desc)
struct pio_device   *pio = irq_desc_get_chip_data(desc);
unsignedgpio_irq;
 
-   gpio_irq = (unsigned) irq_get_handler_data(irq);
+   gpio_irq = (unsigned) irq_desc_get_handler_data(desc);
for (;;) {
u32 isr;
 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/5] pwm: add the Berlin pwm controller driver

2015-07-26 Thread Antoine Tenart
Hi,

On Sun, Jul 26, 2015 at 07:56:55PM -0300, Ezequiel Garcia wrote:
> El jul. 25, 2015 6:40 PM, "Antoine Tenart" 
> escribió:
> > +
> > +static const struct of_device_id berlin_pwm_match[] = {
> > +       { .compatible = "marvell,berlin-pwm" },
> 
> Don't we need a sentinel here?

Oops. I'll fix that.

Antoine

-- 
Antoine Ténart, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/7] ipmi: Factor out message flushing procedure

2015-07-26 Thread Hidehiro Kawai
Factor out message flushing procedure which is used in run-to-completion
mode.  This patch doesn't change the logic.

Signed-off-by: Hidehiro Kawai 
---
 drivers/char/ipmi/ipmi_si_intf.c |   39 ++
 1 file changed, 18 insertions(+), 21 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index 8a45e92..660e53b 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -928,11 +928,25 @@ static void check_start_timer_thread(struct smi_info 
*smi_info)
}
 }
 
+static void flush_messages(struct smi_info *smi_info)
+{
+   enum si_sm_result result;
+
+   /*
+* Currently, this function is called only in run-to-completion
+* mode.  This means we are single-threaded, no need for locks.
+*/
+   result = smi_event_handler(smi_info, 0);
+   while (result != SI_SM_IDLE) {
+   udelay(SI_SHORT_TIMEOUT_USEC);
+   result = smi_event_handler(smi_info, SI_SHORT_TIMEOUT_USEC);
+   }
+}
+
 static void sender(void*send_info,
   struct ipmi_smi_msg *msg)
 {
struct smi_info   *smi_info = send_info;
-   enum si_sm_result result;
unsigned long flags;
 
debug_timestamp("Enqueue");
@@ -944,17 +958,7 @@ static void sender(void*send_info,
 */
smi_info->waiting_msg = msg;
 
-   /*
-* Run to completion means we are single-threaded, no
-* need for locks.
-*/
-
-   result = smi_event_handler(smi_info, 0);
-   while (result != SI_SM_IDLE) {
-   udelay(SI_SHORT_TIMEOUT_USEC);
-   result = smi_event_handler(smi_info,
-  SI_SHORT_TIMEOUT_USEC);
-   }
+   flush_messages(smi_info);
return;
}
 
@@ -975,17 +979,10 @@ static void sender(void*send_info,
 static void set_run_to_completion(void *send_info, bool i_run_to_completion)
 {
struct smi_info   *smi_info = send_info;
-   enum si_sm_result result;
 
smi_info->run_to_completion = i_run_to_completion;
-   if (i_run_to_completion) {
-   result = smi_event_handler(smi_info, 0);
-   while (result != SI_SM_IDLE) {
-   udelay(SI_SHORT_TIMEOUT_USEC);
-   result = smi_event_handler(smi_info,
-  SI_SHORT_TIMEOUT_USEC);
-   }
-   }
+   if (i_run_to_completion)
+   flush_messages(smi_info);
 }
 
 /*


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/7] ipmi: Remove unneeded set_run_to_completion call

2015-07-26 Thread Hidehiro Kawai
send_panic_events() calls intf->handlers->set_run_to_completion(),
but it has already been done in the caller function panic_event().
Remove it from send_panic_events().

Signed-off-by: Hidehiro Kawai 
---
 drivers/char/ipmi/ipmi_msghandler.c |2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_msghandler.c 
b/drivers/char/ipmi/ipmi_msghandler.c
index bf75f63..a6e6ec0 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -4364,9 +4364,7 @@ static void send_panic_events(char *str)
/* Interface is not ready. */
continue;
 
-   intf->run_to_completion = 1;
/* Send the event announcing the panic. */
-   intf->handlers->set_run_to_completion(intf->send_info, 1);
ipmi_panic_request_and_wait(intf, &addr, &msg);
}
 


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 5/7] ipmi: Don't call receive handler in the panic context

2015-07-26 Thread Hidehiro Kawai
Received handlers defined as ipmi_recv_hndl member of struct
ipmi_user_hndl can take a spinlock.  This means that if the kernel
panics while holding the lock, a deadlock may happen on the lock
while flushing queued messages in the panic context.

Calling the receive handler doesn't make much meanings in the panic
context, simply skip it to avoid possible deadlocks.

Signed-off-by: Hidehiro Kawai 
---
 drivers/char/ipmi/ipmi_msghandler.c |8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/char/ipmi/ipmi_msghandler.c 
b/drivers/char/ipmi/ipmi_msghandler.c
index e7d84482..5a2d9fe 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -744,7 +744,13 @@ static void deliver_response(struct ipmi_recv_msg *msg)
ipmi_inc_stat(intf, unhandled_local_responses);
}
ipmi_free_recv_msg(msg);
-   } else {
+   } else if (!oops_in_progress) {
+   /*
+* If we are running in the panic context, calling the
+* receive handler doesn't much meaning and has a deadlock
+* risk.  At this moment, simply skip it in that case.
+*/
+
ipmi_user_t user = msg->user;
user->handler->ipmi_recv_hndl(msg, user->handler_data);
}


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 7/7] ipmi/kcs: Don't run the KCS state machine when it is KCS_IDLE

2015-07-26 Thread Hidehiro Kawai
If a BMC is unresponsive for some reason, it ends up completing
the requested message as an error, then kcs_event() is called once
to advance the state machine.  However, since the BMC is
unresponsive now, the status of the KCS interface may not be
idle.  As the result, the state machine can continue to run and
comsume CPU time indefinitely even if there is no more request
message.  Moreover, if this happens in run-to-completion mode
(i.e. context of panic_event()), the kernel hangs up.

To fix this problem, this patch ignores kcs_event() call if there
is no request message to be processed.

Signed-off-by: Hidehiro Kawai 
---
 drivers/char/ipmi/ipmi_kcs_sm.c |4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/char/ipmi/ipmi_kcs_sm.c b/drivers/char/ipmi/ipmi_kcs_sm.c
index 8c25f59..0e187fb 100644
--- a/drivers/char/ipmi/ipmi_kcs_sm.c
+++ b/drivers/char/ipmi/ipmi_kcs_sm.c
@@ -353,6 +353,10 @@ static enum si_sm_result kcs_event(struct si_sm_data *kcs, 
long time)
if (kcs_debug & KCS_DEBUG_STATES)
printk(KERN_DEBUG "KCS: State = %d, %x\n", kcs->state, status);
 
+   /* We don't want to run the state machine when the state is IDLE */
+   if (kcs->state == KCS_IDLE)
+   return SI_SM_IDLE;
+
/* All states wait for ibf, so just do it here. */
if (!check_ibf(kcs, status, time))
return SI_SM_CALL_WITH_DELAY;


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 6/7] ipmi: Handle queued messages more certainly on panic

2015-07-26 Thread Hidehiro Kawai
panic_event() called as a panic notifier tries to flush queued
messages, but it can't handle them if the kernel panic happens
while processing a message.  What happens depends on when the
kernel panics.

Here is the summary of message sending process.

smi_send()
 smi_add_send_msg()
(1)   intf->curr_msg = msg
 sender()
(2)   smi_info->waiting_msg = msg


check_start_timer_thread()
 start_next_msg()
  smi_info->curr_msg = smi_info->waiting_msg
(3)   smi_info->waiting_msg = NULL
(4)   smi_info->handlers->start_transaction()


smi_event_handler()
(5)  handle_transaction_done()
  smi_info->curr_msg = NULL
  deliver_recv_msg()
   ipmi_smi_msg_received()
intf->curr_msg = NULL

If the kernel panics before (1), the requested message will be
lost.  But it can't be helped.

If the kernel panics before (2), new message sent by
send_panic_events() is queued to intf->xmit_msgs because
intf->curr_msg is non-NULL.  But the new message will be never
sent because no one sends intf->curr_msg.  As the result, the
kernel hangs up.

If the kernel panics before (3), intf->curr_msg will be sent by
set_run_to_completion().  It's no problem.

If the kernel panics before (4), intf->curr_msg will be lost.
However, messages on intf->xmit_msgs will be handled.

If the kernel panics before (5), we try to continue running the
state machine.  It may successfully complete.

If the kernel panics after (5), we will miss the response message
handling, but it's not much problem in the panic context.

This patch tries to handle messages in intf->curr_msg and
intf->xmit_msgs only once without losing them.  To achieve this,
this patch does that:
  - if a message is in intf->curr_msg or intf->xmit_msgs and
start_transaction() for the message hasn't been done yet,
resend it
  - if start_transaction() for a message has been called,
just continue to run the state machine
  - if the transaction has been completed, do nothing

>From the perspective of implementation, these are done by keeping
smi_info->waiting_msg until start_transaction() is completed and
by keeping new flag IPMI_MSG_RESEND_ON_PANIC just before starting
the state machine.

Signed-off-by: Hidehiro Kawai 
---
 drivers/char/ipmi/ipmi_msghandler.c |   36 +++
 drivers/char/ipmi/ipmi_si_intf.c|5 -
 include/linux/ipmi_smi.h|5 +
 3 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/drivers/char/ipmi/ipmi_msghandler.c 
b/drivers/char/ipmi/ipmi_msghandler.c
index 5a2d9fe..3dcd814 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -1493,6 +1493,8 @@ static struct ipmi_smi_msg *smi_add_send_msg(ipmi_smi_t 
intf,
 struct ipmi_smi_msg *smi_msg,
 int priority)
 {
+   smi_msg->flags |= IPMI_MSG_RESEND_ON_PANIC;
+
if (intf->curr_msg) {
if (priority > 0)
list_add_tail(&smi_msg->link, &intf->hp_xmit_msgs);
@@ -4223,6 +4225,7 @@ struct ipmi_smi_msg *ipmi_alloc_smi_msg(void)
rv->done = free_smi_msg;
rv->user_data = NULL;
atomic_inc(&smi_msg_inuse_count);
+   rv->flags = 0;
}
return rv;
 }
@@ -4531,7 +4534,40 @@ static int panic_event(struct notifier_block *this,
spin_unlock(&intf->waiting_rcv_msgs_lock);
 
intf->run_to_completion = 1;
+restart:
intf->handlers->set_run_to_completion(intf->send_info, 1);
+
+   if (intf->curr_msg) {
+   /*
+* This can happen if the kernel panics before
+* setting msg to smi_info->waiting_msg or while
+* processing a response.  For the former case, we
+* resend the message by re-queueing it.  For the
+* latter case, we simply ignore it because handling
+* response is not much meaningful in the panic
+* context.
+*/
+
+   /*
+* Since we want to send the current message first,
+* re-queue it into the high-prioritized queue.
+*/
+   if (intf->curr_msg->flags & IPMI_MSG_RESEND_ON_PANIC)
+   list_add(&intf->curr_msg->link,
+&intf->hp_xmit_msgs);
+
+   intf->curr_msg = NULL;
+   }
+
+   if (!list_empty(&intf->hp_xmit_msgs) ||
+   !list_empty(&intf->xmit_msgs)) {
+   /*
+* This can happen if the kernel panics while
+* processing a response.  Kick the queue and restart.
+*/
+  

[PATCH 3/7] ipmi: Don't flush messages in sneder() in run-to-completion mode

2015-07-26 Thread Hidehiro Kawai
When flushing queued messages in run-to-completion mode,
smi_event_handler() is recursively called.

flush_messages()
 smi_event_handler()
  handle_transaction_done()
   deliver_recv_msg()
ipmi_smi_msg_received()
 smi_recv_tasklet()
  sender()
   flush_messages()
smi_event_handler()
 ...

The depth of the recursive call depends on the number of queued
messages, so it can cause a stack overflow if many messages have
been queued.

To solve this problem, this patch removes flush_messages()
from sender()@ipmi_si_intf.c.  Instead, add flush_messages() to
caller side of sender() if needed.  Additionally, to implement this,
add new handler flush_messages to struct ipmi_smi_handlers.

Signed-off-by: Hidehiro Kawai 
---
 drivers/char/ipmi/ipmi_msghandler.c |3 +++
 drivers/char/ipmi/ipmi_si_intf.c|5 +++--
 include/linux/ipmi_smi.h|5 +
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_msghandler.c 
b/drivers/char/ipmi/ipmi_msghandler.c
index a6e6ec0..f1ecd25 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -4291,6 +4291,9 @@ static void ipmi_panic_request_and_wait(ipmi_smi_t
   intf,
0, 1); /* Don't retry, and don't wait. */
if (rv)
atomic_sub(2, &panic_done_count);
+   else if (intf->handlers->flush_messages)
+   intf->handlers->flush_messages(intf->send_info);
+
while (atomic_read(&panic_done_count) != 0)
ipmi_poll(intf);
 }
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index 660e53b..814b7b7 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -928,8 +928,9 @@ static void check_start_timer_thread(struct smi_info 
*smi_info)
}
 }
 
-static void flush_messages(struct smi_info *smi_info)
+static void flush_messages(void *send_info)
 {
+   struct smi_info *smi_info = send_info;
enum si_sm_result result;
 
/*
@@ -958,7 +959,6 @@ static void sender(void*send_info,
 */
smi_info->waiting_msg = msg;
 
-   flush_messages(smi_info);
return;
}
 
@@ -1264,6 +1264,7 @@ static void set_maintenance_mode(void *send_info, bool 
enable)
.set_need_watch = set_need_watch,
.set_maintenance_mode   = set_maintenance_mode,
.set_run_to_completion  = set_run_to_completion,
+   .flush_messages = flush_messages,
.poll   = poll,
 };
 
diff --git a/include/linux/ipmi_smi.h b/include/linux/ipmi_smi.h
index 0b1e569..ba57fb1 100644
--- a/include/linux/ipmi_smi.h
+++ b/include/linux/ipmi_smi.h
@@ -115,6 +115,11 @@ struct ipmi_smi_handlers {
   implement it. */
void (*set_need_watch)(void *send_info, bool enable);
 
+   /*
+* Called when flushing all pending messages.
+*/
+   void (*flush_messages)(void *send_info);
+
/* Called when the interface should go into "run to
   completion" mode.  If this call sets the value to true, the
   interface should make sure that all messages are flushed


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 0/7] ipmi: various fixes for panic notifier robustness

2015-07-26 Thread Hidehiro Kawai
This patche set fixes multiple bugs in IPMI driver especially for
the panic notifier callback panic_event() and related functions.
This callback is called before kdump if crash_kexec_post_notifiers
boot option is specified, so its robustness is very important.

panic_event() first tries to flush queued messages before panic,
and this can cause multiple trouble such as hang-up.  PATCH 3 to 6 
addresses this kind of problems.

PATCH 7 addresses a problem caused by malfunctioning BMC.

NOTE: I'm planning to post another patch set which includes a patch
to drop all queued messages at the beginning of panic_event() if
crash_kexec_post_notifiers boot option is specified.  This will
improve the robustness of the panic notifier callback.

---

Hidehiro Kawai (7):
  ipmi: Remove unneeded set_run_to_completion call
  ipmi: Factor out message flushing procedure
  ipmi: Don't flush messages in sneder() in run-to-completion mode
  ipmi: Avoid touching possible corrupted lists in the panic context
  ipmi: Don't call receive handler in the panic context
  ipmi: Handle queued messages more certainly on panic
  ipmi/kcs: Don't run the KCS state machine when it is KCS_IDLE


 drivers/char/ipmi/ipmi_kcs_sm.c |4 ++
 drivers/char/ipmi/ipmi_msghandler.c |   66 +--
 drivers/char/ipmi/ipmi_si_intf.c|   45 
 include/linux/ipmi_smi.h|   10 +
 4 files changed, 100 insertions(+), 25 deletions(-)


-- 
Hidehiro Kawai
Hitachi, Ltd. Research & Development Group


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 4/7] ipmi: Avoid touching possible corrupted lists in the panic context

2015-07-26 Thread Hidehiro Kawai
When processing queued messages in the panic context, IPMI driver
tries to do it without any locking to avoid deadlocks.  However,
this means we can touch a corrupted list if the kernel panicked
while manipulating the list.  Fortunately, current `add-tail and
del-from-head' style implementation won't touch the corrupted part,
but it is inherently risky.

To get rid of the risk, this patch re-initializes the message lists
on panic if the related spinlock has already been acquired.  As the
result, we may lose queued messages, but it's not so painful.
Droping messages on the received message list is also less
problematic because no one can respond the received messages.

Signed-off-by: Hidehiro Kawai 
---
 drivers/char/ipmi/ipmi_msghandler.c |   17 +
 1 file changed, 17 insertions(+)

diff --git a/drivers/char/ipmi/ipmi_msghandler.c 
b/drivers/char/ipmi/ipmi_msghandler.c
index f1ecd25..e7d84482 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -4507,6 +4507,23 @@ static int panic_event(struct notifier_block *this,
/* Interface is not ready. */
continue;
 
+   /*
+* If we were interrupted while locking xmit_msgs_lock or
+* waiting_rcv_msgs_lock, the corresponding list may be
+* corrupted.  In this case, drop itmes on the list for
+* the safety.
+*/
+   if (!spin_trylock(&intf->xmit_msgs_lock)) {
+   INIT_LIST_HEAD(&intf->xmit_msgs);
+   INIT_LIST_HEAD(&intf->hp_xmit_msgs);
+   } else
+   spin_unlock(&intf->xmit_msgs_lock);
+
+   if (!spin_trylock(&intf->waiting_rcv_msgs_lock))
+   INIT_LIST_HEAD(&intf->waiting_rcv_msgs);
+   else
+   spin_unlock(&intf->waiting_rcv_msgs_lock);
+
intf->run_to_completion = 1;
intf->handlers->set_run_to_completion(intf->send_info, 1);
}


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: linux-next: build failure after merge of the wireless-drivers-next tree

2015-07-26 Thread Stephen Rothwell
Hi Kalle,

On Mon, 27 Jul 2015 08:41:49 +0300 Kalle Valo  wrote:
>
> Stephen Rothwell  writes:
> 
> > After merging the wireless-drivers-next tree, today's linux-next build
> > (x86_64 allmodconfig) failed like this:
> >
> > ERROR: "of_default_bus_match_table" [drivers/bcma/bcma.ko] undefined!
> >
> > Caused by commit
> >
> >   cae761b5a6bd ("bcma: populate bus DT subnodes as platform_device-s")
> >
> > I have used the wireless-drivers-next tree from next-20150721 for today.
> 
> Yesterday I pushed the commit below which should fix this issue. Please
> let me know if you still have any problems.
> 
> commit 92ff7a698badec3938edd3ba6b3e3ae03365
> Author: Hauke Mehrtens 
> Date:   Sat Jul 25 21:10:27 2015 +0200
> 
> bcma: fix build error when build as module

It is fixed today, thanks.
-- 
Cheers,
Stephen Rothwells...@canb.auug.org.au
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


linux-next: Tree for Jul 27

2015-07-26 Thread Stephen Rothwell
Hi all,

Changes since 20150724:

New tree: orangefs

The ext4 tree lost its build failure.

The wireless-drivers-next tree lost its build failure.

The drm tree gained a conflict against Linus' tree.

The input tree lost its build failure.

The battery tree gained a build failure so I used the version from
next-20150724.

The clk tree gained a conflict against the omap tree and a build failure
for which I applied a merge fix patch.

The akpm-current tree still had its build failures for which I reverted
2 commits.

The akpm tree gained a conflict against Linus' tree.

Non-merge commits (relative to Linus' tree): 3983
 3956 files changed, 190637 insertions(+), 101842 deletions(-)



I have created today's linux-next tree at
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
(patches at http://www.kernel.org/pub/linux/kernel/next/ ).  If you
are tracking the linux-next tree using git, you should not use "git pull"
to do so as that will try to merge the new linux-next release with the
old one.  You should use "git fetch" and checkout or reset to the new
master.

You can see which trees have been included by looking in the Next/Trees
file in the source.  There are also quilt-import.log and merge.log
files in the Next directory.  Between each merge, the tree was built
with a ppc64_defconfig for powerpc and an allmodconfig for x86_64,
a multi_v7_defconfig for arm and a native build of tools/perf. After
the final fixups (if any), it is also built with powerpc allnoconfig
(32 and 64 bit), ppc44x_defconfig and allyesconfig (this fails its final
link) and i386, sparc, sparc64 and arm defconfig.

Below is a summary of the state of the merge.

I am currently merging 225 trees (counting Linus' and 33 trees of patches
pending for Linus' tree).

Stats about the size of the tree over time can be seen at
http://neuling.org/linux-next-size.html .

Status of my local build tests will be at
http://kisskb.ellerman.id.au/linux-next .  If maintainers want to give
advice about cross compilers/configs that work, we are always open to add
more builds.

Thanks to Randy Dunlap for doing many randconfig builds.  And to Paul
Gortmaker for triage and bug fixes.

-- 
Cheers,
Stephen Rothwells...@canb.auug.org.au

$ git checkout master
$ git reset --hard stable
Merging origin/master (cbfe8fa6cd67 Linux 4.2-rc4)
Merging fixes/master (c7e9ad7da219 Merge branch 'perf-urgent-for-linus' of 
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip)
Merging kbuild-current/rc-fixes (3d1450d54a4f Makefile: Force gzip and xz on 
module install)
Merging arc-current/for-curr (e4140819dadc ARC: signal handling robustify)
Merging arm-current/fixes (0871b7248113 ARM: fix __virt_to_idmap build error on 
!MMU)
Merging m68k-current/for-linus (1214c525484c m68k: Use for_each_sg())
Merging metag-fixes/fixes (0164a711c97b metag: Fix ioremap_wc/ioremap_cached 
build errors)
Merging mips-fixes/mips-fixes (1795cd9b3a91 Linux 3.16-rc5)
Merging powerpc-fixes/fixes (120d200a8627 macintosh/ans-lcd: fix build failure 
after module_init/exit relocation)
Merging powerpc-merge-mpe/fixes (bc0195aad0da Linux 4.2-rc2)
Merging powerpc-merge-benh/merge (c517d838eb7d Linux 4.0-rc1)
Merging sparc/master (4a10a91756ef Merge branch 'upstream' of 
git://git.infradead.org/users/pcmoore/audit)
Merging net/master (485164381c1d Merge 
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf)
Merging ipsec/master (31a418986a58 xen: netback: read hotplug script once at 
start of day.)
Merging sound-current/for-linus (e9c28e16a0b7 ALSA: hda - Fix the headset mic 
that will not work on Dell desktop machine)
Merging pci-current/for-linus (c9ddbac9c891 PCI: Restore PCI_MSIX_FLAGS_BIRMASK 
definition)
Merging wireless-drivers/master (df2cd4586f17 Merge tag 
'iwlwifi-for-kalle-2015-06-12' of 
https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/iwlwifi-fixes)
Merging driver-core.current/driver-core-linus (52721d9d3334 Linux 4.2-rc3)
Merging tty.current/tty-linus (61e86cc90af4 tty: vt: Fix !TASK_RUNNING 
diagnostic warning from paste_selection())
Merging usb.current/usb-linus (1209544d8a2a USB: OHCI: fix bad #define in 
ohci-tmio.c)
Merging usb-gadget-fixes/fixes (aebda6187181 usb: dwc3: Reset the transfer 
resource index on SET_INTERFACE)
Merging usb-serial-fixes/usb-linus (6da3700c98cd USB: qcserial: Add support for 
Dell Wireless 5809e 4G Modem)
Merging staging.current/staging-linus (00243b1d180b Merge tag 
'iio-fixes-for-4.2c' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio 
into staging-linus)
Merging char-misc.current/char-misc-linus (4e5a74f1db8d parport: Revert 
"parport: fix memory leak")
Merging input-current/for-linus (8b5a359c5b3e Input: goodix - fix touch 
coordinates on WinBook TW100 and TW700)
Merging crypto-current/master (f898c522f0e9 crypto: ixp4xx - Remove bogus 
BUG_ON on scattered dst buffer)
Merging ide/master (d681f1166919 ide: remove deprecated use o

Re: [PATCH 1/4] loop: Enable correct physical blocksize

2015-07-26 Thread Hannes Reinecke
On 07/27/2015 07:15 AM, Christoph Hellwig wrote:
> On Fri, Jul 17, 2015 at 09:27:04AM +0200, Hannes Reinecke wrote:
>> When running on files the physical blocksize is actually 4k,
>> so we should be announcing it as such. This is enabled with
>> a new LO_FLAGS_BLOCKSIZE flag value to the existing ioctl.
> 
> The flag is only used in this patch, but not actually defined anywhere.
> 
Ah, Merge error.
I'll fix it up.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke   zSeries & Storage
h...@suse.de  +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 5/8] perf: Split perf_event_read_value()

2015-07-26 Thread Sukadev Bhattiprolu
Peter Zijlstra [pet...@infradead.org] wrote:
| On Tue, Jul 14, 2015 at 08:01:52PM -0700, Sukadev Bhattiprolu wrote:
| > Move the part of perf_event_read_value() that computes the event
| > counts and event times into a new function, perf_event_compute().
| > 
| > This would allow us to call perf_event_compute() independently.
| > 
| > Signed-off-by: Sukadev Bhattiprolu 
| > 
| > Changelog[v3]
| > Rather than move perf_event_read() into callers and then
| > rename, just move the computations into a separate function
| > (redesign to address comment from Peter Zijlstra).
| > ---
| >  kernel/events/core.c |   37 -
| >  1 file changed, 24 insertions(+), 13 deletions(-)
| > 
| > diff --git a/kernel/events/core.c b/kernel/events/core.c
| > index 44fb89d..b1e9a42 100644
| > --- a/kernel/events/core.c
| > +++ b/kernel/events/core.c
| > @@ -3704,6 +3704,29 @@ static int perf_release(struct inode *inode, struct 
file *file)
| > return 0;
| >  }
| >  
| > +static u64 perf_event_compute(struct perf_event *event, u64 *enabled,
| > + u64 *running)
| > +{
| > +   struct perf_event *child;
| > +   u64 total;
| > +
| > +   total = perf_event_count(event);
| > +
| > +   *enabled += event->total_time_enabled +
| > +   atomic64_read(&event->child_total_time_enabled);
| > +   *running += event->total_time_running +
| > +   atomic64_read(&event->child_total_time_running);
| > +
| > +   list_for_each_entry(child, &event->child_list, child_list) {
| > +   perf_event_read(child);
| 
| Sure we don't want that..

So if say x86 calls perf_event_read_value() the current upstream code
makes the perf_event_read(child).

If we remove this, then it would be a change in behavior?

I have commented it out and have TODO in the latest patchset. Pls
review and let me know if we should drop this read (and the TODO)
of the child event.

Sukadev

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v4 2/7] clk: mediatek: Fix rate and dependency of MT8173 clocks

2015-07-26 Thread Sascha Hauer
On Fri, Jul 24, 2015 at 07:10:14PM +0800, Daniel Kurtz wrote:
> On Fri, Jul 24, 2015 at 11:02 AM, James Liao  
> wrote:
> > Remove the dependency from clk_null, and give all root clocks a
> > typical rate, include clkph_mck_o, usb_syspll_125m and hdmitx_dig_cts.
> >
> > dpi_ck was removed due to no clock reference to it.
> >
> > Replace parent clock of infra_cpum with cpum_ck, which is an external
> > clock and can be defined in the deivce tree.
> >
> > Signed-off-by: James Liao 
> > ---
> >  drivers/clk/mediatek/clk-mt8173.c  | 13 ++---
> >  include/dt-bindings/clock/mt8173-clk.h |  1 -
> >  2 files changed, 6 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/clk/mediatek/clk-mt8173.c 
> > b/drivers/clk/mediatek/clk-mt8173.c
> > index 4b9e04c..50b3266 100644
> > --- a/drivers/clk/mediatek/clk-mt8173.c
> > +++ b/drivers/clk/mediatek/clk-mt8173.c
> > @@ -24,11 +24,9 @@
> >
> >  static DEFINE_SPINLOCK(mt8173_clk_lock);
> >
> > -static const struct mtk_fixed_factor root_clk_alias[] __initconst = {
> > -   FACTOR(CLK_TOP_CLKPH_MCK_O, "clkph_mck_o", "clk_null", 1, 1),
> > -   FACTOR(CLK_TOP_DPI, "dpi_ck", "clk_null", 1, 1),
> > -   FACTOR(CLK_TOP_USB_SYSPLL_125M, "usb_syspll_125m", "clk_null", 1, 
> > 1),
> > -   FACTOR(CLK_TOP_HDMITX_DIG_CTS, "hdmitx_dig_cts", "clk_null", 1, 1),
> > +static const struct mtk_fixed_clk fixed_clks[] __initconst = {
> > +   FIXED_CLK(CLK_TOP_CLKPH_MCK_O, "clkph_mck_o", "clk26m", 400 * MHZ),
> > +   FIXED_CLK(CLK_TOP_USB_SYSPLL_125M, "usb_syspll_125m", "clk26m", 125 
> > * MHZ),
> >  };
> >
> >  static const struct mtk_fixed_factor top_divs[] __initconst = {
> > @@ -53,6 +51,7 @@ static const struct mtk_fixed_factor top_divs[] 
> > __initconst = {
> > FACTOR(CLK_TOP_CLKRTC_INT, "clkrtc_int", "clk26m", 1, 793),
> > FACTOR(CLK_TOP_FPC, "fpc_ck", "clk26m", 1, 1),
> >
> > +   FACTOR(CLK_TOP_HDMITX_DIG_CTS, "hdmitx_dig_cts", "tvdpll_445p5m", 
> > 1, 3),
> > FACTOR(CLK_TOP_HDMITXPLL_D2, "hdmitxpll_d2", "hdmitx_dig_cts", 1, 
> > 2),
> > FACTOR(CLK_TOP_HDMITXPLL_D3, "hdmitxpll_d3", "hdmitx_dig_cts", 1, 
> > 3),
> >
> > @@ -611,7 +610,7 @@ static const struct mtk_gate infra_clks[] __initconst = 
> > {
> > GATE_ICG(CLK_INFRA_GCE, "infra_gce", "axi_sel", 6),
> > GATE_ICG(CLK_INFRA_L2C_SRAM, "infra_l2c_sram", "axi_sel", 7),
> > GATE_ICG(CLK_INFRA_M4U, "infra_m4u", "mem_sel", 8),
> > -   GATE_ICG(CLK_INFRA_CPUM, "infra_cpum", "clk_null", 15),
> > +   GATE_ICG(CLK_INFRA_CPUM, "infra_cpum", "cpum_ck", 15),
> > GATE_ICG(CLK_INFRA_KP, "infra_kp", "axi_sel", 16),
> > GATE_ICG(CLK_INFRA_CEC, "infra_cec", "clk26m", 18),
> > GATE_ICG(CLK_INFRA_PMICSPI, "infra_pmicspi", "pmicspi_sel", 22),
> > @@ -714,7 +713,7 @@ static void __init mtk_topckgen_init(struct device_node 
> > *node)
> >
> > clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
> >
> > -   mtk_clk_register_factors(root_clk_alias, 
> > ARRAY_SIZE(root_clk_alias), clk_data);
> > +   mtk_clk_register_fixed_clks(fixed_clks, ARRAY_SIZE(fixed_clks), 
> > clk_data);
> > mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs), clk_data);
> > mtk_clk_register_composites(top_muxes, ARRAY_SIZE(top_muxes), base,
> > &mt8173_clk_lock, clk_data);
> > diff --git a/include/dt-bindings/clock/mt8173-clk.h 
> > b/include/dt-bindings/clock/mt8173-clk.h
> > index 4ad76ed..7230c38 100644
> > --- a/include/dt-bindings/clock/mt8173-clk.h
> > +++ b/include/dt-bindings/clock/mt8173-clk.h
> > @@ -18,7 +18,6 @@
> >  /* TOPCKGEN */
> >
> >  #define CLK_TOP_CLKPH_MCK_O1
> > -#define CLK_TOP_DPI2
> >  #define CLK_TOP_USB_SYSPLL_125M3
> 
> I think we should renumber the rest of the CLK_TOP_*

They shouldn't be renumbered at all as this makes all binary device
trees out there useless. That may not be a big issue with the MT8173
at the moment as there are hardly any binary device trees with the
mainline device trees shipped, but still we should get used to not
break existing device trees without need.

Sascha


-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC v4 03/25] m68k/atari: Move Atari-specific code out of drivers/char/nvram.c

2015-07-26 Thread Finn Thain

On Mon, 27 Jul 2015, Michael Schmitz wrote:

> Finn,
> 
> my bad - there is indeed a change in the /proc/driver/nvram output:
> 
> --- nvram-4.out2015-07-24 12:32:44.0 +1200
> +++ nvram-4p2.out2015-07-27 13:56:06.0 +1200
> @@ -7,7 +7,7 @@
>  Keyboard language: English (US)
>  Date format  : DD.MM.YY, 24h clock
>  Boot delay   : 32s
> -Video mode   : 4 colors, 40 columns, TV NTSC monitor
> +Video mode   : 256 colors, 80 columns, VGA PAL monitor
> no overscan, compat. mode off
>    00 00 00 00 00 00 00 00  11 2e 20 01 ff 00 00 3b  |.. 
> ;|
>  0010  84 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  
> ||
> 
> 
> That video mode is indeed the one set in the NVRAM (by ARAnyM config,
> if running emulated)

All's well then.

Thanks.

Finn

> 
> Cheers,
> 
>   Michael
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 04/10] perf: Rename perf_event_read_{one,group}, perf_read_hw

2015-07-26 Thread Sukadev Bhattiprolu
From: "Peter Zijlstra (Intel)" 

In order to free up the perf_event_read_group() name:

 s/perf_event_read_\(one\|group\)/perf_read_\1/g
 s/perf_read_hw/__perf_read/g

Signed-off-by: Peter Zijlstra (Intel) 
---
 kernel/events/core.c |   14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 97619ed..a6bd09d 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3675,7 +3675,7 @@ static void put_event(struct perf_event *event)
 * see the comment there.
 *
 *  2) there is a lock-inversion with mmap_sem through
-* perf_event_read_group(), which takes faults while
+* perf_read_group(), which takes faults while
 * holding ctx->mutex, however this is called after
 * the last filedesc died, so there is no possibility
 * to trigger the AB-BA case.
@@ -3783,7 +3783,7 @@ u64 perf_event_read_value(struct perf_event *event, u64 
*enabled, u64 *running)
 }
 EXPORT_SYMBOL_GPL(perf_event_read_value);
 
-static int perf_event_read_group(struct perf_event *event,
+static int perf_read_group(struct perf_event *event,
   u64 read_format, char __user *buf)
 {
struct perf_event *leader = event->group_leader, *sub;
@@ -3831,7 +3831,7 @@ static int perf_event_read_group(struct perf_event *event,
return ret;
 }
 
-static int perf_event_read_one(struct perf_event *event,
+static int perf_read_one(struct perf_event *event,
 u64 read_format, char __user *buf)
 {
u64 enabled, running;
@@ -3869,7 +3869,7 @@ static bool is_event_hup(struct perf_event *event)
  * Read the performance event - simple non blocking version for now
  */
 static ssize_t
-perf_read_hw(struct perf_event *event, char __user *buf, size_t count)
+__perf_read(struct perf_event *event, char __user *buf, size_t count)
 {
u64 read_format = event->attr.read_format;
int ret;
@@ -3887,9 +3887,9 @@ perf_read_hw(struct perf_event *event, char __user *buf, 
size_t count)
 
WARN_ON_ONCE(event->ctx->parent_ctx);
if (read_format & PERF_FORMAT_GROUP)
-   ret = perf_event_read_group(event, read_format, buf);
+   ret = perf_read_group(event, read_format, buf);
else
-   ret = perf_event_read_one(event, read_format, buf);
+   ret = perf_read_one(event, read_format, buf);
 
return ret;
 }
@@ -3902,7 +3902,7 @@ perf_read(struct file *file, char __user *buf, size_t 
count, loff_t *ppos)
int ret;
 
ctx = perf_event_ctx_lock(event);
-   ret = perf_read_hw(event, buf, count);
+   ret = __perf_read(event, buf, count);
perf_event_ctx_unlock(event, ctx);
 
return ret;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 03/10] perf: Define perf_event_aggregate()

2015-07-26 Thread Sukadev Bhattiprolu
Move the part of perf_event_read_value() that aggregates the event
counts and event times into a new function, perf_event_aggregate().

This would allow us to call perf_event_aggregate() independently.

Signed-off-by: Sukadev Bhattiprolu 
---
Changelog[v4]
[Peter Zijlstra] Add missing lockdep_assert(). Rename
perf_event_compute() (to perf_event_aggregate()).

Changelog[v3]
Rather than move perf_event_read() into callers and then
rename, just move the computations into a separate function
(redesign to address comment from Peter Zijlstra).

---
 kernel/events/core.c |   39 ++-
 1 file changed, 26 insertions(+), 13 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index f9ca8cb..97619ed 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3704,6 +3704,31 @@ static int perf_release(struct inode *inode, struct file 
*file)
return 0;
 }
 
+static u64 perf_event_aggregate(struct perf_event *event, u64 *enabled,
+ u64 *running)
+{
+   struct perf_event *child;
+   u64 total;
+
+   total = perf_event_count(event);
+
+   *enabled += event->total_time_enabled +
+   atomic64_read(&event->child_total_time_enabled);
+   *running += event->total_time_running +
+   atomic64_read(&event->child_total_time_running);
+
+   lockdep_assert_held(&event->child_mutex);
+
+   list_for_each_entry(child, &event->child_list, child_list) {
+   perf_event_read(child);
+   total += perf_event_count(child);
+   *enabled += child->total_time_enabled;
+   *running += child->total_time_running;
+   }
+
+   return total;
+}
+
 /*
  * Remove all orphanes events from the context.
  */
@@ -3742,7 +3767,6 @@ static void orphans_remove_work(struct work_struct *work)
 
 u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
 {
-   struct perf_event *child;
u64 total = 0;
 
*enabled = 0;
@@ -3751,19 +3775,8 @@ u64 perf_event_read_value(struct perf_event *event, u64 
*enabled, u64 *running)
mutex_lock(&event->child_mutex);
 
perf_event_read(event);
-   total += perf_event_count(event);
-
-   *enabled += event->total_time_enabled +
-   atomic64_read(&event->child_total_time_enabled);
-   *running += event->total_time_running +
-   atomic64_read(&event->child_total_time_running);
+   total = perf_event_aggregate(event, enabled, running);
 
-   list_for_each_entry(child, &event->child_list, child_list) {
-   perf_event_read(child);
-   total += perf_event_count(child);
-   *enabled += child->total_time_enabled;
-   *running += child->total_time_running;
-   }
mutex_unlock(&event->child_mutex);
 
return total;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 06/10] perf: Add return value for perf_event_read().

2015-07-26 Thread Sukadev Bhattiprolu
Add a return value to perf_event_read(). The return value will be
needed later in perf_read_group() implements ability to read several
counters in a PERF_PMU_TXN_READ transaction.

Signed-off-by: Sukadev Bhattiprolu 
---
 kernel/events/core.c |   19 +--
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 0ce3012..21a55d1 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3212,7 +3212,7 @@ static inline u64 perf_event_count(struct perf_event 
*event)
return __perf_event_count(event);
 }
 
-static void perf_event_read(struct perf_event *event)
+static int perf_event_read(struct perf_event *event)
 {
/*
 * If event is enabled and currently active on a CPU, update the
@@ -3238,6 +3238,8 @@ static void perf_event_read(struct perf_event *event)
update_event_times(event);
raw_spin_unlock_irqrestore(&ctx->lock, flags);
}
+
+   return 0;
 }
 
 /*
@@ -3720,7 +3722,7 @@ static u64 perf_event_aggregate(struct perf_event *event, 
u64 *enabled,
lockdep_assert_held(&event->child_mutex);
 
list_for_each_entry(child, &event->child_list, child_list) {
-   perf_event_read(child);
+   (void)perf_event_read(child);
total += perf_event_count(child);
*enabled += child->total_time_enabled;
*running += child->total_time_running;
@@ -3774,7 +3776,7 @@ u64 perf_event_read_value(struct perf_event *event, u64 
*enabled, u64 *running)
 
mutex_lock(&event->child_mutex);
 
-   perf_event_read(event);
+   (void)perf_event_read(event);
total = perf_event_aggregate(event, enabled, running);
 
mutex_unlock(&event->child_mutex);
@@ -3798,7 +3800,12 @@ static int perf_read_group(struct perf_event *event,
 
mutex_lock(&leader->child_mutex);
 
-   perf_event_read(leader);
+   ret = perf_event_read(leader);
+   if (ret) {
+   mutex_unlock(&leader->child_mutex);
+   return ret;
+   }
+
count = perf_event_aggregate(leader, &enabled, &running);
 
mutex_unlock(&leader->child_mutex);
@@ -3824,7 +3831,7 @@ static int perf_read_group(struct perf_event *event,
 
mutex_lock(&leader->child_mutex);
 
-   perf_event_read(sub);
+   (void)perf_event_read(sub);
values[n++] = perf_event_aggregate(sub, &enabled, &running);
 
mutex_unlock(&leader->child_mutex);
@@ -3946,7 +3953,7 @@ static unsigned int perf_poll(struct file *file, 
poll_table *wait)
 
 static void _perf_event_reset(struct perf_event *event)
 {
-   perf_event_read(event);
+   (void)perf_event_read(event);
local64_set(&event->count, 0);
perf_event_update_userpage(event);
 }
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: linux-next: build failure after merge of the wireless-drivers-next tree

2015-07-26 Thread Kalle Valo
Hi Stephen,

Stephen Rothwell  writes:

> After merging the wireless-drivers-next tree, today's linux-next build
> (x86_64 allmodconfig) failed like this:
>
> ERROR: "of_default_bus_match_table" [drivers/bcma/bcma.ko] undefined!
>
> Caused by commit
>
>   cae761b5a6bd ("bcma: populate bus DT subnodes as platform_device-s")
>
> I have used the wireless-drivers-next tree from next-20150721 for today.

Yesterday I pushed the commit below which should fix this issue. Please
let me know if you still have any problems.

commit 92ff7a698badec3938edd3ba6b3e3ae03365
Author: Hauke Mehrtens 
Date:   Sat Jul 25 21:10:27 2015 +0200

bcma: fix build error when build as module

Currently of_default_bus_match_table is not exported so we can only use
this feature when bcma is build into the kernel. This patch removes
support for child buses when bcma is build as a module as a temporary
fix for a build problem introduces in this commit:

commit cae761b5a6bdc597ba476a040fdcd5b4bc559b85
Author: Rafal Milecki 
Date:   Sun Jun 28 17:17:13 2015 +0200

bcma: populate bus DT subnodes as platform_device-s

Reported-by: Stephen Rothwell 
Fixes: cae761b5a6bd ("bcma: populate bus DT subnodes as platform_device-s")
Signed-off-by: Hauke Mehrtens 
Signed-off-by: Kalle Valo 


-- 
Kalle Valo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] rsi: Fix failure to load firmware after memory leak fix and fix the leak

2015-07-26 Thread Mike Looijmans
Fixes commit eae79b4f3e82ca63a53478a161b190a0d38fe526 ("rsi: fix memory leak
in rsi_load_ta_instructions()") which stopped the driver from functioning.

Firmware data has been allocated using vmalloc(), resulting in memory
that cannot be used for DMA. Hence the firmware was first copied to a
buffer allocated with kmalloc() in the original code. This patch reverts
the commit and only calls "kfree()" to release the buffer after sending
the data. This fixes the memory leak without breaking the driver.

Add a comment to the kmemdup() calls to explain why this is done.

Tested on a Topic Miami-Florida board which contains the rsi SDIO chip.

Also added the same kfree() call to the USB glue driver. This was not
tested on actual hardware though, as I only have the SDIO version.

Signed-off-by: Mike Looijmans 
Cc: sta...@vger.kernel.org
---
 drivers/net/wireless/rsi/rsi_91x_sdio_ops.c | 6 +-
 drivers/net/wireless/rsi/rsi_91x_usb_ops.c  | 2 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/rsi/rsi_91x_sdio_ops.c 
b/drivers/net/wireless/rsi/rsi_91x_sdio_ops.c
index b6cc9ff..5c37a71 100644
--- a/drivers/net/wireless/rsi/rsi_91x_sdio_ops.c
+++ b/drivers/net/wireless/rsi/rsi_91x_sdio_ops.c
@@ -172,6 +172,7 @@ static int rsi_load_ta_instructions(struct rsi_common 
*common)
(struct rsi_91x_sdiodev *)adapter->rsi_dev;
u32 len;
u32 num_blocks;
+   const u8 *fw;
const struct firmware *fw_entry = NULL;
u32 block_size = dev->tx_blk_size;
int status = 0;
@@ -200,6 +201,8 @@ static int rsi_load_ta_instructions(struct rsi_common 
*common)
return status;
}
 
+   /* Copy firmware into DMA-accessible memory */
+   fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
len = fw_entry->size;
 
if (len % 4)
@@ -210,7 +213,8 @@ static int rsi_load_ta_instructions(struct rsi_common 
*common)
rsi_dbg(INIT_ZONE, "%s: Instruction size:%d\n", __func__, len);
rsi_dbg(INIT_ZONE, "%s: num blocks: %d\n", __func__, num_blocks);
 
-   status = rsi_copy_to_card(common, fw_entry->data, len, num_blocks);
+   status = rsi_copy_to_card(common, fw, len, num_blocks);
+   kfree(fw);
release_firmware(fw_entry);
return status;
 }
diff --git a/drivers/net/wireless/rsi/rsi_91x_usb_ops.c 
b/drivers/net/wireless/rsi/rsi_91x_usb_ops.c
index 1106ce7..088e28e 100644
--- a/drivers/net/wireless/rsi/rsi_91x_usb_ops.c
+++ b/drivers/net/wireless/rsi/rsi_91x_usb_ops.c
@@ -146,6 +146,7 @@ static int rsi_load_ta_instructions(struct rsi_common 
*common)
return status;
}
 
+   /* Copy firmware into DMA-accessible memory */
fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
len = fw_entry->size;
 
@@ -158,6 +159,7 @@ static int rsi_load_ta_instructions(struct rsi_common 
*common)
rsi_dbg(INIT_ZONE, "%s: num blocks: %d\n", __func__, num_blocks);
 
status = rsi_copy_to_card(common, fw, len, num_blocks);
+   kfree(fw);
release_firmware(fw_entry);
return status;
 }
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 07/10] perf: Add group parameter to perf_event_read()

2015-07-26 Thread Sukadev Bhattiprolu
Add a 'group' parameter to perf_event_read(). It will be used (set
to true) in a follow-on patch to update event times of the group.

Signed-off-by: Sukadev Bhattiprolu 
---
 kernel/events/core.c |   17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 21a55d1..f38fe0b 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3212,7 +3212,7 @@ static inline u64 perf_event_count(struct perf_event 
*event)
return __perf_event_count(event);
 }
 
-static int perf_event_read(struct perf_event *event)
+static int perf_event_read(struct perf_event *event, bool group)
 {
/*
 * If event is enabled and currently active on a CPU, update the
@@ -3235,7 +3235,12 @@ static int perf_event_read(struct perf_event *event)
update_context_time(ctx);
update_cgrp_time_from_event(event);
}
-   update_event_times(event);
+
+   if (group)
+   update_group_times(event);
+   else
+   update_event_times(event);
+
raw_spin_unlock_irqrestore(&ctx->lock, flags);
}
 
@@ -3722,7 +3727,7 @@ static u64 perf_event_aggregate(struct perf_event *event, 
u64 *enabled,
lockdep_assert_held(&event->child_mutex);
 
list_for_each_entry(child, &event->child_list, child_list) {
-   (void)perf_event_read(child);
+   (void)perf_event_read(child, false);
total += perf_event_count(child);
*enabled += child->total_time_enabled;
*running += child->total_time_running;
@@ -3776,7 +3781,7 @@ u64 perf_event_read_value(struct perf_event *event, u64 
*enabled, u64 *running)
 
mutex_lock(&event->child_mutex);
 
-   (void)perf_event_read(event);
+   (void)perf_event_read(event, false);
total = perf_event_aggregate(event, enabled, running);
 
mutex_unlock(&event->child_mutex);
@@ -3831,7 +3836,7 @@ static int perf_read_group(struct perf_event *event,
 
mutex_lock(&leader->child_mutex);
 
-   (void)perf_event_read(sub);
+   (void)perf_event_read(sub, false);
values[n++] = perf_event_aggregate(sub, &enabled, &running);
 
mutex_unlock(&leader->child_mutex);
@@ -3953,7 +3958,7 @@ static unsigned int perf_poll(struct file *file, 
poll_table *wait)
 
 static void _perf_event_reset(struct perf_event *event)
 {
-   (void)perf_event_read(event);
+   (void)perf_event_read(event, false);
local64_set(&event->count, 0);
perf_event_update_userpage(event);
 }
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 02/10] perf: Split perf_event_read() and perf_event_count()

2015-07-26 Thread Sukadev Bhattiprolu
perf_event_read() does two things:

- call the PMU to read/update the counter value, and
- compute the total count of the event and its children

Not all callers need both. perf_event_reset() for instance needs the
first piece but doesn't need the second.  Similarly, when we implement
the ability to read a group of events using the transaction interface,
we would need the two pieces done independently.

Break up perf_event_read() and have it just read/update the counter
and have the callers compute the total count if necessary.

Signed-off-by: Sukadev Bhattiprolu 
---
 kernel/events/core.c |   14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4435bf5..f9ca8cb 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3212,7 +3212,7 @@ static inline u64 perf_event_count(struct perf_event 
*event)
return __perf_event_count(event);
 }
 
-static u64 perf_event_read(struct perf_event *event)
+static void perf_event_read(struct perf_event *event)
 {
/*
 * If event is enabled and currently active on a CPU, update the
@@ -3238,8 +3238,6 @@ static u64 perf_event_read(struct perf_event *event)
update_event_times(event);
raw_spin_unlock_irqrestore(&ctx->lock, flags);
}
-
-   return perf_event_count(event);
 }
 
 /*
@@ -3751,14 +3749,18 @@ u64 perf_event_read_value(struct perf_event *event, u64 
*enabled, u64 *running)
*running = 0;
 
mutex_lock(&event->child_mutex);
-   total += perf_event_read(event);
+
+   perf_event_read(event);
+   total += perf_event_count(event);
+
*enabled += event->total_time_enabled +
atomic64_read(&event->child_total_time_enabled);
*running += event->total_time_running +
atomic64_read(&event->child_total_time_running);
 
list_for_each_entry(child, &event->child_list, child_list) {
-   total += perf_event_read(child);
+   perf_event_read(child);
+   total += perf_event_count(child);
*enabled += child->total_time_enabled;
*running += child->total_time_running;
}
@@ -3918,7 +3920,7 @@ static unsigned int perf_poll(struct file *file, 
poll_table *wait)
 
 static void _perf_event_reset(struct perf_event *event)
 {
-   (void)perf_event_read(event);
+   perf_event_read(event);
local64_set(&event->count, 0);
perf_event_update_userpage(event);
 }
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 08/10] perf: Add return value to __perf_event_read()

2015-07-26 Thread Sukadev Bhattiprolu
Add a return value to __perf_event_read(). The return value will be
needed later in perf_read_group() implements ability to read several
counters in a PERF_PMU_TXN_READ transaction.

Signed-off-by: Sukadev Bhattiprolu 
---
 kernel/events/core.c |   22 +++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index f38fe0b..951d835 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3174,12 +3174,18 @@ void perf_event_exec(void)
rcu_read_unlock();
 }
 
+struct perf_read_data {
+   struct perf_event *event;
+   int ret;
+};
+
 /*
  * Cross CPU call to read the hardware event
  */
 static void __perf_event_read(void *info)
 {
-   struct perf_event *event = info;
+   struct perf_read_data *data = info;
+   struct perf_event *event = data->event;
struct perf_event_context *ctx = event->ctx;
struct perf_cpu_context *cpuctx = __get_cpu_context(ctx);
 
@@ -3201,6 +3207,8 @@ static void __perf_event_read(void *info)
update_event_times(event);
if (event->state == PERF_EVENT_STATE_ACTIVE)
event->pmu->read(event);
+
+   data->ret = 0;
raw_spin_unlock(&ctx->lock);
 }
 
@@ -3214,13 +3222,21 @@ static inline u64 perf_event_count(struct perf_event 
*event)
 
 static int perf_event_read(struct perf_event *event, bool group)
 {
+   int ret = 0;
+
/*
 * If event is enabled and currently active on a CPU, update the
 * value in the event structure:
 */
if (event->state == PERF_EVENT_STATE_ACTIVE) {
+   struct perf_read_data data = {
+   .event = event,
+   .ret = 0,
+   };
+
smp_call_function_single(event->oncpu,
-__perf_event_read, event, 1);
+__perf_event_read, &data, 1);
+   ret = data.ret;
} else if (event->state == PERF_EVENT_STATE_INACTIVE) {
struct perf_event_context *ctx = event->ctx;
unsigned long flags;
@@ -3244,7 +3260,7 @@ static int perf_event_read(struct perf_event *event, bool 
group)
raw_spin_unlock_irqrestore(&ctx->lock, flags);
}
 
-   return 0;
+   return ret;
 }
 
 /*
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 10/10] powerpc/perf/hv-24x7: Use PMU_TXN_READ interface

2015-07-26 Thread Sukadev Bhattiprolu
The 24x7 counters in Powerpc allow monitoring a large number of counters
simultaneously. They also allow reading several counters in a single
HCALL so we can get a more consistent snapshot of the system.

Use the PMU's transaction interface to monitor and read several event
counters at once. The idea is that users can group several 24x7 events
into a single group of events. We use the following logic to submit
the group of events to the PMU and read the values:

pmu->start_txn()// Initialize before first event

for each event in group
pmu->read(event);   // Queue each event to be read

pmu->commit_txn()   // Read/update all queuedcounters

The ->commit_txn() also updates the event counts in the respective
perf_event objects.  The perf subsystem can then directly get the
event counts from the perf_event and can avoid submitting a new
->read() request to the PMU.

Thanks to input from Peter Zijlstra.

Signed-off-by: Sukadev Bhattiprolu 

---
Changelog[v3]
[Peter Zijlstra] Save the transaction state in ->start_txn() and
remove the flags parameter from ->commit_txn() and ->cancel_txn().

---
 arch/powerpc/perf/hv-24x7.c |  166 ++-
 1 file changed, 164 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/perf/hv-24x7.c b/arch/powerpc/perf/hv-24x7.c
index 4d1a8d1..b86121c 100644
--- a/arch/powerpc/perf/hv-24x7.c
+++ b/arch/powerpc/perf/hv-24x7.c
@@ -142,6 +142,15 @@ static struct attribute_group event_long_desc_group = {
 
 static struct kmem_cache *hv_page_cache;
 
+DEFINE_PER_CPU(int, hv_24x7_txn_flags);
+DEFINE_PER_CPU(int, hv_24x7_txn_err);
+
+struct hv_24x7_hw {
+   struct perf_event *events[255];
+};
+
+DEFINE_PER_CPU(struct hv_24x7_hw, hv_24x7_hw);
+
 /*
  * request_buffer and result_buffer are not required to be 4k aligned,
  * but are not allowed to cross any 4k boundary. Aligning them to 4k is
@@ -1233,9 +1242,48 @@ static void update_event_count(struct perf_event *event, 
u64 now)
 static void h_24x7_event_read(struct perf_event *event)
 {
u64 now;
+   struct hv_24x7_request_buffer *request_buffer;
+   struct hv_24x7_hw *h24x7hw;
+   int txn_flags;
+
+   txn_flags = __this_cpu_read(hv_24x7_txn_flags);
+
+   /*
+* If in a READ transaction, add this counter to the list of
+* counters to read during the next HCALL (i.e commit_txn()).
+* If not in a READ transaction, go ahead and make the HCALL
+* to read this counter by itself.
+*/
+
+   if (txn_flags & PERF_PMU_TXN_READ) {
+   int i;
+   int ret;
 
-   now = h_24x7_get_value(event);
-   update_event_count(event, now);
+   if (__this_cpu_read(hv_24x7_txn_err))
+   return;
+
+   request_buffer = (void *)get_cpu_var(hv_24x7_reqb);
+
+   ret = add_event_to_24x7_request(event, request_buffer);
+   if (ret) {
+   __this_cpu_write(hv_24x7_txn_err, ret);
+   } else {
+   /*
+* Assoicate the event with the HCALL request index,
+* so ->commit_txn() can quickly find/update count.
+*/
+   i = request_buffer->num_requests - 1;
+
+   h24x7hw = &get_cpu_var(hv_24x7_hw);
+   h24x7hw->events[i] = event;
+   put_cpu_var(h24x7hw);
+   }
+
+   put_cpu_var(hv_24x7_reqb);
+   } else {
+   now = h_24x7_get_value(event);
+   update_event_count(event, now);
+   }
 }
 
 static void h_24x7_event_start(struct perf_event *event, int flags)
@@ -1257,6 +1305,117 @@ static int h_24x7_event_add(struct perf_event *event, 
int flags)
return 0;
 }
 
+/*
+ * 24x7 counters only support READ transactions. They are
+ * always counting and dont need/support ADD transactions.
+ * Cache the flags, but otherwise ignore transactions that
+ * are not PERF_PMU_TXN_READ.
+ */
+static void h_24x7_event_start_txn(struct pmu *pmu, int flags)
+{
+   struct hv_24x7_request_buffer *request_buffer;
+   struct hv_24x7_data_result_buffer *result_buffer;
+
+   /* We should not be called if we are already in a txn */
+   WARN_ON_ONCE(__this_cpu_read(hv_24x7_txn_flags));
+
+   __this_cpu_write(hv_24x7_txn_flags, flags);
+   if (flags & ~PERF_PMU_TXN_READ)
+   return;
+
+   request_buffer = (void *)get_cpu_var(hv_24x7_reqb);
+   result_buffer = (void *)get_cpu_var(hv_24x7_resb);
+
+   init_24x7_request(request_buffer, result_buffer);
+
+   put_cpu_var(hv_24x7_resb);
+   put_cpu_var(hv_24x7_reqb);
+}
+
+/*
+ * Clean up transaction state.
+ *
+ * NOTE: Ignore state of request and result buffers for now.
+ *  We will initialize them during the next read/txn.
+ */
+static void reset_txn(void)

[PATCH 09/10] Define PERF_PMU_TXN_READ interface

2015-07-26 Thread Sukadev Bhattiprolu
Define a new PERF_PMU_TXN_READ interface to read a group of counters
at once.

pmu->start_txn()// Initialize before first event

for each event in group
pmu->read(event);   // Queue each event to be read

pmu->commit_txn()   // Read/update all queued counters

Note that we use this interface with all PMUs.  PMUs that implement this
interface use the ->read() operation to _queue_ the counters to be read
and use ->commit_txn() to actually read all the queued counters at once.

PMUs that don't implement PERF_PMU_TXN_READ ignore ->start_txn() and
->commit_txn() and continue to read counters one at a time.

Thanks to input from Peter Zijlstra.

Signed-off-by: Sukadev Bhattiprolu 
---
Changelog[v4]
[Peter Zijlstra] Add lockdep_assert_held() in perf_event_read_group().
Make sure the entire transaction happens on the same CPU.

---
 include/linux/perf_event.h |1 +
 kernel/events/core.c   |   38 +++---
 2 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 44bf05f..da307ad 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -169,6 +169,7 @@ struct perf_event;
 #define PERF_EVENT_TXN 0x1
 
 #define PERF_PMU_TXN_ADD  0x1  /* txn to add/schedule event on PMU */
+#define PERF_PMU_TXN_READ 0x2  /* txn to read event group from PMU */
 
 /**
  * pmu::capabilities flags
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 951d835..b5aa92c 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3176,6 +3176,7 @@ void perf_event_exec(void)
 
 struct perf_read_data {
struct perf_event *event;
+   bool group;
int ret;
 };
 
@@ -3186,8 +3187,10 @@ static void __perf_event_read(void *info)
 {
struct perf_read_data *data = info;
struct perf_event *event = data->event;
+   struct perf_event *sub;
struct perf_event_context *ctx = event->ctx;
struct perf_cpu_context *cpuctx = __get_cpu_context(ctx);
+   struct pmu *pmu = event->pmu;
 
/*
 * If this is a task context, we need to check whether it is
@@ -3205,10 +3208,25 @@ static void __perf_event_read(void *info)
update_cgrp_time_from_event(event);
}
update_event_times(event);
-   if (event->state == PERF_EVENT_STATE_ACTIVE)
-   event->pmu->read(event);
+   if (event->state != PERF_EVENT_STATE_ACTIVE)
+   goto unlock;
+
+   if (!data->group) {
+   pmu->read(event);
+   goto unlock;
+   }
+
+   pmu->start_txn(pmu, PERF_PMU_TXN_READ);
 
-   data->ret = 0;
+   pmu->read(event);
+   list_for_each_entry(sub, &event->sibling_list, group_entry) {
+   if (sub->state == PERF_EVENT_STATE_ACTIVE)
+   pmu->read(sub);
+   }
+
+   data->ret = pmu->commit_txn(pmu);
+
+unlock:
raw_spin_unlock(&ctx->lock);
 }
 
@@ -3231,6 +3249,7 @@ static int perf_event_read(struct perf_event *event, bool 
group)
if (event->state == PERF_EVENT_STATE_ACTIVE) {
struct perf_read_data data = {
.event = event,
+   .group = group,
.ret = 0,
};
 
@@ -3743,7 +3762,13 @@ static u64 perf_event_aggregate(struct perf_event 
*event, u64 *enabled,
lockdep_assert_held(&event->child_mutex);
 
list_for_each_entry(child, &event->child_list, child_list) {
+#if 0
+   /*
+* TODO: Do we need this read() for group events on PMUs that
+*   don't implement PERF_PMU_TXN_READ transactions?
+*/
(void)perf_event_read(child, false);
+#endif
total += perf_event_count(child);
*enabled += child->total_time_enabled;
*running += child->total_time_running;
@@ -3821,7 +3846,7 @@ static int perf_read_group(struct perf_event *event,
 
mutex_lock(&leader->child_mutex);
 
-   ret = perf_event_read(leader);
+   ret = perf_event_read(leader, true);
if (ret) {
mutex_unlock(&leader->child_mutex);
return ret;
@@ -3850,12 +3875,11 @@ static int perf_read_group(struct perf_event *event,
list_for_each_entry(sub, &leader->sibling_list, group_entry) {
n = 0;
 
-   mutex_lock(&leader->child_mutex);
+   mutex_lock(&sub->child_mutex);
 
-   (void)perf_event_read(sub, false);
values[n++] = perf_event_aggregate(sub, &enabled, &running);
 
-   mutex_unlock(&leader->child_mutex);
+   mutex_unlock(&sub->child_mutex);
 
if (read_format & PERF_FORMAT_ID)
values[n++] = primary_event_id(sub);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line 

[PATCH v4 0/10] Implement group-read of events using txn interface

2015-07-26 Thread Sukadev Bhattiprolu
Unlike normal hardware PMCs, the 24x7 counters in Power8 are stored in
memory and accessed via a hypervisor call (HCALL).  A major aspect of the
HCALL is that it allows retireving _several_ counters at once (unlike
regular PMCs, which are read one at a time). By reading several counters
at once, we can get a more consistent snapshot of the system.

This patchset extends the transaction interface to accomplish submitting
several events to the PMU and have the PMU read them all at once. User is
expected to submit the set of events they want to read as an "event group".

In the kernel, we submit each event to the PMU using the following logic
(from Peter Zijlstra).

pmu->start_txn(pmu, PMU_TXN_READ);

leader->read();
for_each_sibling()
sibling->read();
pmu->commit_txn();

where:
- the ->read()s queue events to be submitted to the hypervisor, and,
- the ->commit_txn() issues the HCALL, retrieves the result and
  updates the event count.

Architectures/PMUs that don't need/implement PMU_TXN_READ type of transactions,
simply ignore the ->start_txn() and ->commit_txn() and continue to read the
counters one at a time in the ->read() call.

Compile/touch tested on x86. Need help testing on s390 and Sparc.

Thanks to Peter Zijlstra for his input/code.

Changelog[v4]
- Ensure all the transactions operations happen on the same CPU so PMUs
  can use per-CPU buffers for the transaction.
- Add lockdep assert and fix a locking issue in perf_read_group().

Changelog [v3]
- Simple changes/reorg of patchset to split/rename functions
- [Peter Zijlstra] Save the transaction flags in ->start_txn() and
  drop the flags parameter from ->commit_txn() and ->cancel_txn().
- [Peter Zijlstra] The nop txn interfaces don't need to disable/enable
  PMU for PERF_PMU_TXN_READ transactions.

Changelog [v2]
- Use the transaction interface unconditionally to avoid special-case
  code. Architectures/PMUs that don't need the READ transaction types
  simply ignore the ->start_txn() and ->commit_txn() calls.

Peter Zijlstra (Intel) (1):
  perf: Rename perf_event_read_{one,group}, perf_read_hw

Sukadev Bhattiprolu (9):
  perf: Add a flags parameter to pmu txn interfaces
  perf: Split perf_event_read() and perf_event_count()
  perf: Define perf_event_aggregate()
  perf: Unroll perf_event_read_value() in perf_read_group()
  perf: Add return value for perf_event_read().
  perf: Add group parameter to perf_event_read()
  perf: Add return value to __perf_event_read()
  Define PERF_PMU_TXN_READ interface
  powerpc/perf/hv-24x7: Use PMU_TXN_READ interface

 arch/powerpc/perf/core-book3s.c  |   25 +-
 arch/powerpc/perf/hv-24x7.c  |  166 -
 arch/s390/kernel/perf_cpum_cf.c  |   24 +-
 arch/sparc/kernel/perf_event.c   |   19 -
 arch/x86/kernel/cpu/perf_event.c |   27 +-
 arch/x86/kernel/cpu/perf_event.h |1 +
 include/linux/perf_event.h   |   15 +++-
 kernel/events/core.c |  167 +++---
 8 files changed, 403 insertions(+), 41 deletions(-)

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 05/10] perf: Unroll perf_event_read_value() in perf_read_group()

2015-07-26 Thread Sukadev Bhattiprolu
Unroll the calls to perf_event_read_value() in perf_read_group()
so we can later optimize out parts we don't need for group events.

Signed-off-by: Sukadev Bhattiprolu 
---
 kernel/events/core.c |   17 +++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index a6bd09d..0ce3012 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3794,7 +3794,14 @@ static int perf_read_group(struct perf_event *event,
 
lockdep_assert_held(&ctx->mutex);
 
-   count = perf_event_read_value(leader, &enabled, &running);
+   enabled = running = 0;
+
+   mutex_lock(&leader->child_mutex);
+
+   perf_event_read(leader);
+   count = perf_event_aggregate(leader, &enabled, &running);
+
+   mutex_unlock(&leader->child_mutex);
 
values[n++] = 1 + leader->nr_siblings;
if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
@@ -3815,7 +3822,13 @@ static int perf_read_group(struct perf_event *event,
list_for_each_entry(sub, &leader->sibling_list, group_entry) {
n = 0;
 
-   values[n++] = perf_event_read_value(sub, &enabled, &running);
+   mutex_lock(&leader->child_mutex);
+
+   perf_event_read(sub);
+   values[n++] = perf_event_aggregate(sub, &enabled, &running);
+
+   mutex_unlock(&leader->child_mutex);
+
if (read_format & PERF_FORMAT_ID)
values[n++] = primary_event_id(sub);
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 01/10] perf: Add a flags parameter to pmu txn interfaces

2015-07-26 Thread Sukadev Bhattiprolu
Currently, the PMU interface allows reading only one counter at a time.
But some PMUs like the 24x7 counters in Power, support reading several
counters at once. To leveage this functionality, extend the transaction
interface to support a "transaction type".

The first type, PERF_PMU_TXN_ADD, refers to the existing transactions,
i.e. used to _schedule_ all the events on the PMU as a group. A second
transaction type, PERF_PMU_TXN_READ, will be used in a follow-on patch,
by the 24x7 counters to read several counters at once.

Extend the transaction interfaces to the PMU to accept a 'txn_flags'
parameter and use this parameter to ignore any transactions that are
not of type PERF_PMU_TXN_ADD.

Thanks to Peter Zijlstra for his input.

Signed-off-by: Sukadev Bhattiprolu 
---
Changelog[v4]
- [Peter Zijlstra] Fix an copy-paste error in power_pmu_cancel_txn().
- [Peter Zijlstra] Use __this_cpu_read() and __this_cpu_write().

Changelog[v3]
- [Peter Zijlstra] Ensure the nop_txn interfaces disable/enable
  PMU only for TXN_ADD transactions.
- [Peter Zijlstra] Cache the flags parameter in ->start_txn() and
  drop the flags parameter from ->commit_txn() and ->cancel_txn().

---
 arch/powerpc/perf/core-book3s.c  |   25 -
 arch/s390/kernel/perf_cpum_cf.c  |   24 +++-
 arch/sparc/kernel/perf_event.c   |   19 ++-
 arch/x86/kernel/cpu/perf_event.c |   27 +--
 arch/x86/kernel/cpu/perf_event.h |1 +
 include/linux/perf_event.h   |   14 +++---
 kernel/events/core.c |   31 ---
 7 files changed, 130 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
index d90893b..b18efe4 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -50,6 +50,7 @@ struct cpu_hw_events {
 
unsigned int group_flag;
int n_txn_start;
+   int txn_flags;
 
/* BHRB bits */
u64 bhrb_filter;/* BHRB HW branch 
filter */
@@ -1586,11 +1587,19 @@ static void power_pmu_stop(struct perf_event *event, 
int ef_flags)
  * Start group events scheduling transaction
  * Set the flag to make pmu::enable() not perform the
  * schedulability test, it will be performed at commit time
+ *
+ * We only support PERF_PMU_TXN_ADD transactions. Save the
+ * transaction flags but otherwise ignore non-PERF_PMU_TXN_ADD
+ * transactions.
  */
-static void power_pmu_start_txn(struct pmu *pmu)
+static void power_pmu_start_txn(struct pmu *pmu, int txn_flags)
 {
struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);
 
+   cpuhw->txn_flags = txn_flags;
+   if (txn_flags & ~PERF_PMU_TXN_ADD)
+   return;
+
perf_pmu_disable(pmu);
cpuhw->group_flag |= PERF_EVENT_TXN;
cpuhw->n_txn_start = cpuhw->n_events;
@@ -1604,6 +1613,12 @@ static void power_pmu_start_txn(struct pmu *pmu)
 static void power_pmu_cancel_txn(struct pmu *pmu)
 {
struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);
+   int txn_flags;
+
+   txn_flags = cpuhw->txn_flags;
+   cpuhw->txn_flags = 0;
+   if (txn_flags & ~PERF_PMU_TXN_ADD)
+   return;
 
cpuhw->group_flag &= ~PERF_EVENT_TXN;
perf_pmu_enable(pmu);
@@ -1618,10 +1633,18 @@ static int power_pmu_commit_txn(struct pmu *pmu)
 {
struct cpu_hw_events *cpuhw;
long i, n;
+   int txn_flags;
 
if (!ppmu)
return -EAGAIN;
+
cpuhw = this_cpu_ptr(&cpu_hw_events);
+
+   txn_flags = cpuhw->txn_flags;
+   cpuhw->txn_flags = 0;
+   if (cpuhw->txn_flags & ~PERF_PMU_TXN_ADD)
+   return 0;
+
n = cpuhw->n_events;
if (check_excludes(cpuhw->event, cpuhw->flags, 0, n))
return -EAGAIN;
diff --git a/arch/s390/kernel/perf_cpum_cf.c b/arch/s390/kernel/perf_cpum_cf.c
index 56fdad4..a6f9e7b 100644
--- a/arch/s390/kernel/perf_cpum_cf.c
+++ b/arch/s390/kernel/perf_cpum_cf.c
@@ -72,6 +72,7 @@ struct cpu_hw_events {
atomic_tctr_set[CPUMF_CTR_SET_MAX];
u64 state, tx_state;
unsigned intflags;
+   int txn_flags;
 };
 static DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = {
.ctr_set = {
@@ -82,6 +83,7 @@ static DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = {
},
.state = 0,
.flags = 0,
+   .txn_flags = 0,
 };
 
 static int get_counter_set(u64 event)
@@ -572,11 +574,19 @@ static void cpumf_pmu_del(struct perf_event *event, int 
flags)
 /*
  * Start group events scheduling transaction.
  * Set flags to perform a single test at commit time.
+ *
+ * We only support PERF_PMU_TXN_ADD transactions. Save the
+ * transaction flags but otherwise ignore non-PERF_PMU_TXN_ADD
+ * transactions.
  */
-static void cpumf_pmu_start_

Re: [PATCH 1/4] spmi: pmic-arb: add irq_get_irqchip_state implementation

2015-07-26 Thread Andy Gross
On Thu, Jun 18, 2015 at 02:13:42PM -0700, Bjorn Andersson wrote:
> Signed-off-by: Courtney Cavin 
> Signed-off-by: Bjorn Andersson 
> ---

Looks good.

Greg, can you pick this up?

Reviewed-by: Andy Gross 

-- 
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 1/2] PM / devfreq: exynos-ppmu: Add the support of PPMUv2 for Exynos5433

2015-07-26 Thread MyungJoo Ham
>   
>  This patch adds the support for PPMU (Platform Performance Monitoring Unit)
> version 2.0 for Exynos5433 SoC. Exynos5433 SoC must need PPMUv2 which is
> quite different from PPMUv1.1. The exynos-ppmu.c driver supports both PPMUv1.1
> and PPMUv2.
> 
> Cc: MyungJoo Ham 
> Cc: Kyungmin Park 
> Signed-off-by: Chanwoo Choi 

Acked-by: MyungJoo Ham 

> ---
>  drivers/devfreq/event/exynos-ppmu.c | 170 
> ++--
>  drivers/devfreq/event/exynos-ppmu.h |  70 +++
>  2 files changed, 233 insertions(+), 7 deletions(-)
> 


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

2015-07-26 Thread Stephen Rothwell
Hi Andrew,

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

  arch/x86/mm/mpx.c

between commit:

  a89652769470 ("x86/mpx: Do not set ->vm_ops on MPX VMAs")

from Linus' tree and patch:

  "mm, mpx: add "vm_flags_t vm_flags" arg to do_mmap_pgoff()"

from the akpm tree.

I fixed it up (I used the akpm tree version of mpx_map()) and can carry
the fix as necessary (no action is required).

-- 
Cheers,
Stephen Rothwells...@canb.auug.org.au
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 2/2] PM / devfreq: exynos-ppmu: Update documentation to support PPMUv2

2015-07-26 Thread MyungJoo Ham
>   
>  This patch updates the documentation to include the information of PPMUv2.
> The PPMUv2 is used for Exynos5433 and Exynos7420 to monitor the performance
> of each IP in Exynos SoC.
> 
> Cc: MyungJoo Ham 
> Cc: Kyungmin Park 
> Signed-off-by: Chanwoo Choi 

Acked-by: MyungJoo Ham 

> ---
>  .../bindings/devfreq/event/exynos-ppmu.txt | 42 
> --
>  1 file changed, 40 insertions(+), 2 deletions(-)
> 


Re: [PATCH] sm750fb: coding style fixes lines over 80 chars

2015-07-26 Thread Sudip Mukherjee
On Tue, Jul 21, 2015 at 03:17:06PM +0530, Vinay Simha wrote:
> Joe,
> 
> Just want to confirm, shall i delete this code in sm750_help.h, even the
> FIELD_START and FIELD_END is not required.
If they are not used anywhere feel free to send a patch to delete them.

regards
sudip
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/4] loop: Remove unused 'bdev' argument from loop_set_capacity

2015-07-26 Thread Christoph Hellwig
On Fri, Jul 17, 2015 at 09:27:05AM +0200, Hannes Reinecke wrote:
> Signed-off-by: Hannes Reinecke 

Looks good,

Reviewed-by: Christoph Hellwig 

(and should be moved first in the series)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v10 6/7] sched: Provide runnable_load_avg back to cfs_rq

2015-07-26 Thread Boqun Feng
Hi Yuyang,

On Mon, Jul 27, 2015 at 04:34:09AM +0800, Yuyang Du wrote:
> On Mon, Jul 27, 2015 at 12:04:20PM +0800, Boqun Feng wrote:
> > > ~~~
> > > > > 1) blocked load is more "difficult" to track, hint, migrate.
> > > ~~~ 
> > 
> > I may not get your point here? Are you saying my patch fails to handle
> > the migration or are you just telling me that blocked load tracking need
> > to take migration into consideration?
> 
> Both, is it so difficult to get?
>  

Hmm.. I will appreciate more if you comment on my patch to point out
where is wrong ;-)

> > If it's the latter one, I want to say that, with blocked load or not, we
> > have to handle load_avg in migrations, so *adding* some code to handle
> > blocked load is not a big deal.
> > 
> > Please consider this piece of code in update_cfs_rq_load_avg(), which
> > decays and updates blocked_load_avg.
>  
> At this point of time, you tell me why exactly you want to track the blocked?

I want to track the blocked load because you want to track runnable load
in your patch, and as you've already tracked load_avg, which is the sum
of blocked load and runnable load, so I wonder whether tracking blocked
load is *another* way to track runnable load. Because if tracking
blocked load costs less than tracking runnable load, it's of course
better to track blocked load and calculate runnable load on demand
rather than track runnable load directly.

Yes, I do need to decay and update blocked_load_avg in
update_cfs_rq_load_avg() if there is a *non-zero* value of
remove_load_avg, but:

1.  if no entity is migrated and no entity is dequeued(blocked), I
need to do nothing but tracking runnable load directly still
needs to update runnable load, for example, in entity_tick().
2.  if no entity is migrated and a entity is dequeued(blocked), what
I need to do is similar as tracking runnable load directly does.

and of course:

3.  if a entity is migrated, I do need to do more than tracking
runnable load directly.

So,
For #1 situations, tracking blocked load wins
For #2 situations, tie
For #3 situations, tracking runnable load wins

And which are more rare in the system, #1 or #3?


I write that patch to see how much we need to track blocked load
*instead* of runnable load, and I don't see that costs a lot. So I
basically want to know, is my patch of tracking blocked wrong? If not,
does that cost more than or nearly equal to tracking runnable load
directly?  If not, why not track blocked load instead of tracking
runnable load?

However, I admit all the questions should be answered by real
benchmarks. I just want to see whether you have thought the same
questions as I and could give me a quick answer.

But I think an simple and directly answer is that "because we need
runnable load so we track it", code simplicity wins! if your current
answer is that, I'm OK with it, and will do some benchmark myself to see
whether it's worth to track blocked load rather than runnable load
directly. Again, I still hope a quick and convinced answer from you.
Thank you ;-)

Regards,
Boqun


signature.asc
Description: PGP signature


Re: [PATCH 1/4] loop: Enable correct physical blocksize

2015-07-26 Thread Christoph Hellwig
On Fri, Jul 17, 2015 at 09:27:04AM +0200, Hannes Reinecke wrote:
> When running on files the physical blocksize is actually 4k,
> so we should be announcing it as such. This is enabled with
> a new LO_FLAGS_BLOCKSIZE flag value to the existing ioctl.

The flag is only used in this patch, but not actually defined anywhere.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFCv2 3/3] reset: reset-zynq: Adding support for Xilinx Zynq reset controller.

2015-07-26 Thread Michal Simek
On 07/25/2015 02:21 AM, Moritz Fischer wrote:
> This adds a reset controller driver to control the Xilinx Zynq
> SoC's various resets.
> 
> Signed-off-by: Moritz Fischer 
> ---
>  drivers/reset/Makefile |   1 +
>  drivers/reset/reset-zynq.c | 142 
> +
>  2 files changed, 143 insertions(+)
>  create mode 100644 drivers/reset/reset-zynq.c
> 
> diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile
> index 157d421..3fe50e7 100644
> --- a/drivers/reset/Makefile
> +++ b/drivers/reset/Makefile
> @@ -3,3 +3,4 @@ obj-$(CONFIG_ARCH_SOCFPGA) += reset-socfpga.o
>  obj-$(CONFIG_ARCH_BERLIN) += reset-berlin.o
>  obj-$(CONFIG_ARCH_SUNXI) += reset-sunxi.o
>  obj-$(CONFIG_ARCH_STI) += sti/
> +obj-$(CONFIG_ARCH_ZYNQ) += reset-zynq.o
> diff --git a/drivers/reset/reset-zynq.c b/drivers/reset/reset-zynq.c
> new file mode 100644
> index 000..05e37f8
> --- /dev/null
> +++ b/drivers/reset/reset-zynq.c
> @@ -0,0 +1,142 @@
> +/*
> + * Copyright (c) 2015, National Instruments Corp.
> + *
> + * Xilinx Zynq Reset controller driver
> + *
> + * 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 
> +
> +/* Offsets into SLCR regmap */
> +#define SLCR_RST_CTRL_OFFSET 0x200 /* FPGA Software Reset Control */

incorrect comment.

> +
> +#define NBANKS   18
> +
> +struct zynq_reset_data {
> + struct regmap *slcr;
> + struct reset_controller_dev rcdev;
> +};
> +
> +#define to_zynq_reset_data(p)\
> + container_of((p), struct zynq_reset_data, rcdev)
> +
> +static int zynq_reset_assert(struct reset_controller_dev *rcdev,
> +  unsigned long id)
> +{
> + struct zynq_reset_data *priv = to_zynq_reset_data(rcdev);
> +
> + int bank = id / BITS_PER_LONG;
> + int offset = id % BITS_PER_LONG;
> +
> + regmap_update_bits(priv->slcr,
> +SLCR_RST_CTRL_OFFSET + (bank * 4),
> +BIT(offset),
> +BIT(offset));
> +
> + return 0;
> +}
> +
> +static int zynq_reset_deassert(struct reset_controller_dev *rcdev,
> +unsigned long id)
> +{
> + struct zynq_reset_data *priv = to_zynq_reset_data(rcdev);
> +
> + int bank = id / BITS_PER_LONG;
> + int offset = id % BITS_PER_LONG;
> +
> + regmap_update_bits(priv->slcr,
> +SLCR_RST_CTRL_OFFSET + (bank * 4),
> +BIT(offset),
> +~BIT(offset));
> +
> + return 0;
> +}
> +
> +static int zynq_reset_status(struct reset_controller_dev *rcdev,
> +  unsigned long id)
> +{
> + struct zynq_reset_data *priv = to_zynq_reset_data(rcdev);
> +
> + int bank = id / BITS_PER_LONG;
> + int offset = id % BITS_PER_LONG;
> + u32 reg;
> +
> + regmap_read(priv->slcr, SLCR_RST_CTRL_OFFSET + (bank * 4), ®);
> +
> + return !(reg & BIT(offset));
> +}
> +
> +static const struct reset_control_ops zynq_reset_ops = {
> + .assert = zynq_reset_assert,
> + .deassert   = zynq_reset_deassert,
> + .status = zynq_reset_status,
> +};
> +
> +static int zynq_reset_probe(struct platform_device *pdev)
> +{
> + struct zynq_reset_data *priv;
> +
> + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
> + if (!priv)
> + return -ENOMEM;
> + platform_set_drvdata(pdev, priv);
> +
> + priv->slcr = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
> + "syscon");

NIT - incorrect indentation.

> + if (IS_ERR(priv->slcr)) {
> + dev_err(&pdev->dev, "unable to get zynq-slcr regmap");
> + return PTR_ERR(priv->slcr);
> + }
> +
> + priv->rcdev.owner = THIS_MODULE;
> + priv->rcdev.nr_resets = NBANKS * BITS_PER_LONG;
> + priv->rcdev.ops = &zynq_reset_ops;
> + priv->rcdev.of_node = pdev->dev.of_node;
> + reset_controller_register(&priv->rcdev);
> +
> + return 0;
> +}
> +
> +static int zynq_reset_remove(struct platform_device *pdev)
> +{
> + struct zynq_reset_data *priv = platform_get_drvdata(pdev);
> +
> + reset_controller_unregister(&priv->rcdev);
> +
> + return 0;
> +}
> +
> +static const struct of_device_id zynq_reset_dt_ids[] = {
> + { .compatible = "xlnx,zynq-reset", },
> + { /* sentinel */ },
> +};
> +
> +static struct platform_driver zynq_reset_driver = {
> + .probe  = zynq_reset_probe,
> + .remove = zynq_reset_remove,
>

Re: [PATCH v2 25/25] pmem: convert to generic memremap

2015-07-26 Thread Christoph Hellwig
On Sun, Jul 26, 2015 at 11:11:44AM -0700, Dan Williams wrote:
> I don't follow.  We have __iomem for the cpu mapping of a resource and
> dma_map() for a PCI device.  __pmem works the same and is there to
> make sure someone doesn't simply de-reference a pointer to pmem and
> hope that the write is persistent.

But no deference of a kernel pointer is magily persistent, so I'm
not really worried about that.  It just means whenever we want to
pass it to anything we'll need to cast.  And anything that does
I/O falls into that category.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 08/25] arch: introduce memremap()

2015-07-26 Thread Christoph Hellwig
On Sun, Jul 26, 2015 at 10:49:39AM -0700, Dan Williams wrote:
> On Sun, Jul 26, 2015 at 10:25 AM, Christoph Hellwig  wrote:
> > On Fri, Jul 24, 2015 at 10:38:42PM -0400, Dan Williams wrote:
> >> The behavior change to return NULL on an unsupported request is reserved
> >> for a later patch.
> >
> > Why?
> 
> This is for drivers like pmem that care about the mapping type.  For
> example, if pmem can't get a cache-enabled mapping it is potentially
> putting the write durability of the persistent media at risk.

I understand that part, but the question is why the old behavior
is retained for now and only changed later.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 08/25] arch: introduce memremap()

2015-07-26 Thread Christoph Hellwig
On Sun, Jul 26, 2015 at 10:49:39AM -0700, Dan Williams wrote:
> > What's the point of having this MEMREMAP_CACHE alias?
> 
> For developers that are used to seeing ioremap_cache()...

Meh.  We've got git logs that show clearly what replaced a previous API.
Duplicate names for the same API are highly confusing.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[V2 PATCH 2/3] kexec: Fix race between panic() and crash_kexec() called directly

2015-07-26 Thread Hidehiro Kawai
Currently, panic() and crash_kexec() can be called at the same time.
For example (x86 case):

CPU 0:
  oops_end()
crash_kexec()
  mutex_trylock() // acquired
nmi_shootdown_cpus() // stop other cpus

CPU 1:
  panic()
crash_kexec()
  mutex_trylock() // failed to acquire
smp_send_stop() // stop other cpus
infinite loop

If CPU 1 calls smp_send_stop() before nmi_shootdown_cpus(), kdump
fails.

In another case:

CPU 0:
  oops_end()
crash_kexec()
  mutex_trylock() // acquired

io_check_error()
  panic()
crash_kexec()
  mutex_trylock() // failed to acquire
infinite loop

Clearly, this is an undesirable result.

To fix this problem, this patch changes crash_kexec() to exclude
others by using atomic_t panicking_cpu.

V2:
- Use atomic_cmpxchg() instead of spin_trylock() on panic_lock
  to exclude concurrent accesses
- Don't introduce no-lock version of crash_kexec()

Signed-off-by: Hidehiro Kawai 
Cc: Eric Biederman 
Cc: Vivek Goyal 
Cc: Andrew Morton 
---
 kernel/kexec.c |   20 
 1 file changed, 20 insertions(+)

diff --git a/kernel/kexec.c b/kernel/kexec.c
index a785c10..ca40a19 100644
--- a/kernel/kexec.c
+++ b/kernel/kexec.c
@@ -1472,6 +1472,18 @@ void __weak crash_unmap_reserved_pages(void)
 
 void crash_kexec(struct pt_regs *regs)
 {
+   int old_cpu, this_cpu;
+
+   /*
+* `old_cpu == -1' means we are the first comer and crash_kexec()
+* was called without entering panic().
+* `old_cpu == this_cpu' means crash_kexec() was called from panic().
+*/
+   this_cpu = raw_smp_processor_id();
+   old_cpu = atomic_cmpxchg(&panicking_cpu, -1, this_cpu);
+   if (old_cpu != -1 && old_cpu != this_cpu)
+   return;
+
/* Take the kexec_mutex here to prevent sys_kexec_load
 * running on one cpu from replacing the crash kernel
 * we are using after a panic on a different cpu.
@@ -1491,6 +1503,14 @@ void crash_kexec(struct pt_regs *regs)
}
mutex_unlock(&kexec_mutex);
}
+
+   /*
+* If we came here from panic(), we have to keep panicking_cpu
+* to prevent other cpus from entering panic().  Otherwise,
+* resetting it so that other cpus can enter panic()/crash_kexec().
+*/
+   if (old_cpu == this_cpu)
+   atomic_set(&panicking_cpu, -1);
 }
 
 size_t crash_get_memory_size(void)


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[V2 PATCH 1/3] x86/panic: Fix re-entrance problem due to panic on NMI

2015-07-26 Thread Hidehiro Kawai
If panic on NMI happens just after panic() on the same CPU, panic()
is recursively called.  As the result, it stalls after failing to
acquire panic_lock.

To avoid this problem, don't call panic() in NMI context if
we've already entered panic().

V2:
- Use atomic_cmpxchg() instead of current spin_trylock() to
  exclude concurrent accesses to the panic routines
- Don't introduce no-lock version of panic()

Signed-off-by: Hidehiro Kawai 
Cc: Andrew Morton 
Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: "H. Peter Anvin" 
Cc: Peter Zijlstra 
---
 arch/x86/kernel/nmi.c  |   15 +++
 include/linux/kernel.h |1 +
 kernel/panic.c |   13 ++---
 3 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
index d05bd2e..5b32d81 100644
--- a/arch/x86/kernel/nmi.c
+++ b/arch/x86/kernel/nmi.c
@@ -230,7 +230,8 @@ void unregister_nmi_handler(unsigned int type, const char 
*name)
}
 #endif
 
-   if (panic_on_unrecovered_nmi)
+   if (panic_on_unrecovered_nmi &&
+   atomic_cmpxchg(&panicking_cpu, -1, raw_smp_processor_id()) == -1)
panic("NMI: Not continuing");
 
pr_emerg("Dazed and confused, but trying to continue\n");
@@ -255,8 +256,13 @@ void unregister_nmi_handler(unsigned int type, const char 
*name)
 reason, smp_processor_id());
show_regs(regs);
 
-   if (panic_on_io_nmi)
-   panic("NMI IOCK error: Not continuing");
+   if (panic_on_io_nmi) {
+   if (atomic_cmpxchg(&panicking_cpu, -1, raw_smp_processor_id())
+   == -1)
+   panic("NMI IOCK error: Not continuing");
+   else
+   return; /* We don't want to wait and re-enable NMI */
+   }
 
/* Re-enable the IOCK line, wait for a few seconds */
reason = (reason & NMI_REASON_CLEAR_MASK) | NMI_REASON_CLEAR_IOCHK;
@@ -296,7 +302,8 @@ void unregister_nmi_handler(unsigned int type, const char 
*name)
 reason, smp_processor_id());
 
pr_emerg("Do you have a strange power saving mode enabled?\n");
-   if (unknown_nmi_panic || panic_on_unrecovered_nmi)
+   if ((unknown_nmi_panic || panic_on_unrecovered_nmi) &&
+   atomic_cmpxchg(&panicking_cpu, -1, raw_smp_processor_id()) == -1)
panic("NMI: Not continuing");
 
pr_emerg("Dazed and confused, but trying to continue\n");
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 5582410..8ca199b 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -442,6 +442,7 @@ extern __scanf(2, 0)
 extern int sysctl_panic_on_stackoverflow;
 
 extern bool crash_kexec_post_notifiers;
+extern atomic_t panicking_cpu;
 
 /*
  * Only to be used by arch init code. If the user over-wrote the default
diff --git a/kernel/panic.c b/kernel/panic.c
index 04e91ff..7e6b568 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -60,6 +60,8 @@ void __weak panic_smp_self_stop(void)
cpu_relax();
 }
 
+atomic_t panicking_cpu = ATOMIC_INIT(-1);
+
 /**
  * panic - halt the system
  * @fmt: The text string to print
@@ -70,17 +72,17 @@ void __weak panic_smp_self_stop(void)
  */
 void panic(const char *fmt, ...)
 {
-   static DEFINE_SPINLOCK(panic_lock);
static char buf[1024];
va_list args;
long i, i_next = 0;
int state = 0;
+   int old_cpu, this_cpu;
 
/*
 * Disable local interrupts. This will prevent panic_smp_self_stop
 * from deadlocking the first cpu that invokes the panic, since
 * there is nothing to prevent an interrupt handler (that runs
-* after the panic_lock is acquired) from invoking panic again.
+* after setting panicking_cpu) from invoking panic again.
 */
local_irq_disable();
 
@@ -93,8 +95,13 @@ void panic(const char *fmt, ...)
 * multiple parallel invocations of panic, all other CPUs either
 * stop themself or will wait until they are stopped by the 1st CPU
 * with smp_send_stop().
+*
+* `old_cpu == -1' means we are the first comer.
+* `old_cpu == this_cpu' means we came here due to panic on NMI.
 */
-   if (!spin_trylock(&panic_lock))
+   this_cpu = raw_smp_processor_id();
+   old_cpu = atomic_cmpxchg(&panicking_cpu, -1, this_cpu);
+   if (old_cpu != -1 && old_cpu != this_cpu)
panic_smp_self_stop();
 
console_verbose();


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[V2 PATCH 3/3] x86/apic: Introduce noextnmi boot option

2015-07-26 Thread Hidehiro Kawai
This patch introduces new boot option "noextnmi" which disables
external NMI.  This option is useful for the dump capture kernel
so that an HA application or administrator wouldn't mistakenly
shoot down the kernel by NMI.

Currently, only x86 supports this option.

Signed-off-by: Hidehiro Kawai 
Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: "H. Peter Anvin" 
Cc: Jonathan Corbet 
---
 Documentation/kernel-parameters.txt |4 
 arch/x86/kernel/apic/apic.c |   17 -
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/Documentation/kernel-parameters.txt 
b/Documentation/kernel-parameters.txt
index 1d6f045..2cbd40b 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -2364,6 +2364,10 @@ bytes respectively. Such letter suffixes can also be 
entirely omitted.
noexec=on: enable non-executable mappings (default)
noexec=off: disable non-executable mappings
 
+   noextnmi[X86]
+   Mask external NMI.  This option is useful for a
+   dump capture kernel to be shot down by NMI.
+
nosmap  [X86]
Disable SMAP (Supervisor Mode Access Prevention)
even if it is supported by processor.
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index dcb5285..a140410 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -82,6 +82,12 @@
 static unsigned int disabled_cpu_apicid __read_mostly = BAD_APICID;
 
 /*
+ * Don't enable external NMI via LINT1 on BSP.  This is useful for
+ * the dump capture kernel.
+ */
+static bool apic_noextnmi;
+
+/*
  * Map cpu index to physical APIC ID
  */
 DEFINE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_cpu_to_apicid, BAD_APICID);
@@ -1150,6 +1156,8 @@ void __init init_bsp_APIC(void)
value = APIC_DM_NMI;
if (!lapic_is_integrated()) /* 82489DX */
value |= APIC_LVT_LEVEL_TRIGGER;
+   if (apic_noextnmi)
+   value |= APIC_LVT_MASKED;
apic_write(APIC_LVT1, value);
 }
 
@@ -1369,7 +1377,7 @@ void setup_local_APIC(void)
/*
 * only the BP should see the LINT1 NMI signal, obviously.
 */
-   if (!cpu)
+   if (!cpu && !apic_noextnmi)
value = APIC_DM_NMI;
else
value = APIC_DM_NMI | APIC_LVT_MASKED;
@@ -2537,3 +2545,10 @@ static int __init apic_set_disabled_cpu_apicid(char *arg)
return 0;
 }
 early_param("disable_cpu_apicid", apic_set_disabled_cpu_apicid);
+
+static int __init apic_set_noextnmi(char *arg)
+{
+   apic_noextnmi = true;
+   return 0;
+}
+early_param("noextnmi", apic_set_noextnmi);


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[V2 PATCH 0/3] x86: Fix panic vs. NMI issues

2015-07-26 Thread Hidehiro Kawai
When an HA cluster software or administrator detects non-response
of a host, they issue an NMI to the host to completely stop current
works and take a crash dump.  If the kernel has already panicked
or is capturing a crash dump at that time, further NMI can cause
a crash dump failure.

To solve this issue, this patch set does two things:

- Don't panic on NMI if the kernel has already panicked
- Introduce "noextnmi" boot option which masks external NMI at the
  boot time (supported only for x86)

V2:
- Use atomic_cmpxchg() instead of current spin_trylock() to exclude
  concurrent accesses to panic() and crash_kexec()
- Don't introduce no-lock version of panic() and crash_kexec()

---

Hidehiro Kawai (3):
  x86/panic: Fix re-entrance problem due to panic on NMI
  kexec: Fix race between panic() and crash_kexec() called directly
  x86/apic: Introduce noextnmi boot option


 Documentation/kernel-parameters.txt |4 
 arch/x86/kernel/apic/apic.c |   17 -
 arch/x86/kernel/nmi.c   |   15 +++
 include/linux/kernel.h  |1 +
 kernel/kexec.c  |   20 
 kernel/panic.c  |   13 ++---
 6 files changed, 62 insertions(+), 8 deletions(-)


-- 
Hidehiro Kawai
Hitachi, Ltd. Research & Development Group


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFCv2 1/3] docs: dts: Added documentation for Xilinx Zynq Reset Controller bindings.

2015-07-26 Thread Michal Simek
On 07/25/2015 02:21 AM, Moritz Fischer wrote:
> Signed-off-by: Moritz Fischer 
> ---
>  Documentation/devicetree/bindings/reset/zynq-reset-pl.txt | 13 +
>  1 file changed, 13 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/reset/zynq-reset-pl.txt
> 
> diff --git a/Documentation/devicetree/bindings/reset/zynq-reset-pl.txt 
> b/Documentation/devicetree/bindings/reset/zynq-reset-pl.txt
> new file mode 100644
> index 000..ac4499e
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/reset/zynq-reset-pl.txt
> @@ -0,0 +1,13 @@
> +Xilinx Zynq PL Reset Manager

here

> +
> +Required properties:
> +- compatible: "xlnx,zynq-reset-pl"

Currently it is not just PL reset controller.

> +- syscon <&slcr>;


missing : and please be more descriptive here.

> +- #reset-cells: 1
> +
> +Example:
> + rstc: rstc@240 {
> + #reset-cells = <1>;
> + compatible = "xlnx,zynq-reset-pl";

Compatible property should go first.

I am missing that reg property

> + syscon = <&slcr>;
> + };
> 

Thanks,
Michal


-- 
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/
Maintainer of Linux kernel - Xilinx Zynq ARM architecture
Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform




signature.asc
Description: OpenPGP digital signature


Re: [parport] BUG kmalloc-16 (Not tainted): Object already free

2015-07-26 Thread Sudip Mukherjee
On Mon, Jul 27, 2015 at 07:46:59AM +0800, Fengguang Wu wrote:
> Sorry for the duplicate report! It'll be auto avoided in future.
No problem. And thanks again for the script to reproduce the error. I am
still wondering why it did not came up in my tests before sending the
patch.

regards
sudip
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH V2 07/11] OPP: Add clock-latency-ns support

2015-07-26 Thread Viresh Kumar
With "operating-points-v2" bindings, clock-latency is defined per OPP.
Users of this value expect a single value which defines the latency to
switch to any clock rate. Find maximum clock-latency-ns from the OPP
table to service requests from such users.

Reviewed-by: Stephen Boyd 
Signed-off-by: Viresh Kumar 
---
 drivers/base/power/opp.c | 41 +++--
 include/linux/pm_opp.h   |  6 ++
 2 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c
index d9ebbd739b23..96d7d1b6730a 100644
--- a/drivers/base/power/opp.c
+++ b/drivers/base/power/opp.c
@@ -57,6 +57,8 @@
  * @u_volt_min:Minimum voltage in microvolts corresponding to this OPP
  * @u_volt_max:Maximum voltage in microvolts corresponding to this OPP
  * @u_amp: Maximum current drawn by the device in microamperes
+ * @clock_latency_ns: Latency (in nanoseconds) of switching to this OPP's
+ * frequency from any other OPP's frequency.
  * @dev_opp:   points back to the device_opp struct this opp belongs to
  * @rcu_head:  RCU callback head used for deferred freeing
  * @np:OPP's device node.
@@ -75,6 +77,7 @@ struct dev_pm_opp {
unsigned long u_volt_min;
unsigned long u_volt_max;
unsigned long u_amp;
+   unsigned long clock_latency_ns;
 
struct device_opp *dev_opp;
struct rcu_head rcu_head;
@@ -109,6 +112,8 @@ struct device_opp {
struct srcu_notifier_head srcu_head;
struct rcu_head rcu_head;
struct list_head opp_list;
+
+   unsigned long clock_latency_ns_max;
 };
 
 /*
@@ -226,6 +231,32 @@ unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
 EXPORT_SYMBOL_GPL(dev_pm_opp_get_freq);
 
 /**
+ * dev_pm_opp_get_max_clock_latency() - Get max clock latency in nanoseconds
+ * @dev:   device for which we do this operation
+ *
+ * Return: This function returns the max clock latency in nanoseconds.
+ *
+ * Locking: This function takes rcu_read_lock().
+ */
+unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
+{
+   struct device_opp *dev_opp;
+   unsigned long clock_latency_ns;
+
+   rcu_read_lock();
+
+   dev_opp = _find_device_opp(dev);
+   if (IS_ERR(dev_opp))
+   clock_latency_ns = 0;
+   else
+   clock_latency_ns = dev_opp->clock_latency_ns_max;
+
+   rcu_read_unlock();
+   return clock_latency_ns;
+}
+EXPORT_SYMBOL_GPL(dev_pm_opp_get_max_clock_latency);
+
+/**
  * dev_pm_opp_get_opp_count() - Get number of opps available in the opp list
  * @dev:   device for which we do this operation
  *
@@ -765,6 +796,8 @@ static int _opp_add_static_v2(struct device *dev, struct 
device_node *np)
new_opp->np = np;
new_opp->dynamic = false;
new_opp->available = true;
+   of_property_read_u32(np, "clock-latency-ns",
+(u32 *)&new_opp->clock_latency_ns);
 
ret = opp_get_microvolt(new_opp, dev);
if (ret)
@@ -776,11 +809,15 @@ static int _opp_add_static_v2(struct device *dev, struct 
device_node *np)
if (ret)
goto free_opp;
 
+   if (new_opp->clock_latency_ns > dev_opp->clock_latency_ns_max)
+   dev_opp->clock_latency_ns_max = new_opp->clock_latency_ns;
+
mutex_unlock(&dev_opp_list_lock);
 
-   pr_debug("%s: turbo:%d rate:%lu uv:%lu uvmin:%lu uvmax:%lu\n",
+   pr_debug("%s: turbo:%d rate:%lu uv:%lu uvmin:%lu uvmax:%lu 
latency:%lu\n",
 __func__, new_opp->turbo, new_opp->rate, new_opp->u_volt,
-new_opp->u_volt_min, new_opp->u_volt_max);
+new_opp->u_volt_min, new_opp->u_volt_max,
+new_opp->clock_latency_ns);
 
/*
 * Notify the changes in the availability of the operable
diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index cec2d4540914..20324b579adc 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -31,6 +31,7 @@ unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
 unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
 
 int dev_pm_opp_get_opp_count(struct device *dev);
+unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev);
 
 struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
  unsigned long freq,
@@ -67,6 +68,11 @@ static inline int dev_pm_opp_get_opp_count(struct device 
*dev)
return 0;
 }
 
+static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device 
*dev)
+{
+   return 0;
+}
+
 static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
unsigned long freq, bool available)
 {
-- 
2.4.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[PATCH V2 04/11] OPP: Allocate dev_opp from _add_device_opp()

2015-07-26 Thread Viresh Kumar
There is no need to complicate _opp_add_dynamic() with allocation of
dev_opp as well. Allocate it from _add_device_opp() instead.

Reviewed-by: Stephen Boyd 
Reviewed-by: Bartlomiej Zolnierkiewicz 
Signed-off-by: Viresh Kumar 
---
 drivers/base/power/opp.c | 41 ++---
 1 file changed, 18 insertions(+), 23 deletions(-)

diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c
index 7895fdd64192..901b6c77a791 100644
--- a/drivers/base/power/opp.c
+++ b/drivers/base/power/opp.c
@@ -408,11 +408,11 @@ struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct 
device *dev,
 EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor);
 
 /**
- * _add_device_opp() - Allocate a new device OPP table
+ * _add_device_opp() - Find device OPP table or allocate a new one
  * @dev:   device for which we do this operation
  *
- * New device node which uses OPPs - used when multiple devices with OPP tables
- * are maintained.
+ * It tries to find an existing table first, if it couldn't find one, it
+ * allocates a new OPP table and returns that.
  *
  * Return: valid device_opp pointer if success, else NULL.
  */
@@ -420,6 +420,11 @@ static struct device_opp *_add_device_opp(struct device 
*dev)
 {
struct device_opp *dev_opp;
 
+   /* Check for existing list for 'dev' first */
+   dev_opp = _find_device_opp(dev);
+   if (!IS_ERR(dev_opp))
+   return dev_opp;
+
/*
 * Allocate a new device OPP table. In the infrequent case where a new
 * device is needed to be added, we pay this penalty.
@@ -575,7 +580,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_remove);
 static int _opp_add_dynamic(struct device *dev, unsigned long freq,
long u_volt, bool dynamic)
 {
-   struct device_opp *dev_opp = NULL;
+   struct device_opp *dev_opp;
struct dev_pm_opp *opp, *new_opp;
struct list_head *head;
int ret;
@@ -592,19 +597,11 @@ static int _opp_add_dynamic(struct device *dev, unsigned 
long freq,
new_opp->rate = freq;
new_opp->u_volt = u_volt;
new_opp->available = true;
-   new_opp->dynamic = dynamic;
-
-   /* Check for existing list for 'dev' */
-   dev_opp = _find_device_opp(dev);
-   if (IS_ERR(dev_opp)) {
-   dev_opp = _add_device_opp(dev);
-   if (!dev_opp) {
-   ret = -ENOMEM;
-   goto free_opp;
-   }
 
-   head = &dev_opp->opp_list;
-   goto list_add;
+   dev_opp = _add_device_opp(dev);
+   if (!dev_opp) {
+   ret = -ENOMEM;
+   goto free_opp;
}
 
/*
@@ -613,14 +610,12 @@ static int _opp_add_dynamic(struct device *dev, unsigned 
long freq,
 */
head = &dev_opp->opp_list;
list_for_each_entry_rcu(opp, &dev_opp->opp_list, node) {
-   if (new_opp->rate <= opp->rate)
-   break;
-   else
+   if (new_opp->rate > opp->rate)
head = &opp->node;
-   }
+   else if (new_opp->rate < opp->rate)
+   break;
 
-   /* Duplicate OPPs ? */
-   if (new_opp->rate == opp->rate) {
+   /* Duplicate OPPs */
ret = opp->available && new_opp->u_volt == opp->u_volt ?
0 : -EEXIST;
 
@@ -630,7 +625,7 @@ static int _opp_add_dynamic(struct device *dev, unsigned 
long freq,
goto free_opp;
}
 
-list_add:
+   new_opp->dynamic = dynamic;
new_opp->dev_opp = dev_opp;
list_add_rcu(&new_opp->node, head);
mutex_unlock(&dev_opp_list_lock);
-- 
2.4.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH V2 05/11] OPP: Break _opp_add_dynamic() into smaller functions

2015-07-26 Thread Viresh Kumar
Later commits would add support for new OPP bindings and this would be
required then. So, lets do it in a separate patch to make it easily
reviewable.

Another change worth noticing is INIT_LIST_HEAD(&opp->node). We weren't
doing it earlier as we never tried to delete a list node before it is
added to list. But this wouldn't be the case anymore. We might try to
delete a node (just to reuse the same code paths), without it being
getting added to the list.

Reviewed-by: Bartlomiej Zolnierkiewicz 
Signed-off-by: Viresh Kumar 
---
 drivers/base/power/opp.c | 109 ++-
 1 file changed, 69 insertions(+), 40 deletions(-)

diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c
index 901b6c77a791..962d62316b80 100644
--- a/drivers/base/power/opp.c
+++ b/drivers/base/power/opp.c
@@ -484,6 +484,7 @@ static void _kfree_opp_rcu(struct rcu_head *head)
  * _opp_remove()  - Remove an OPP from a table definition
  * @dev_opp:   points back to the device_opp struct this opp belongs to
  * @opp:   pointer to the OPP to remove
+ * @notify:OPP_EVENT_REMOVE notification should be sent or not
  *
  * This function removes an opp definition from the opp list.
  *
@@ -492,13 +493,14 @@ static void _kfree_opp_rcu(struct rcu_head *head)
  * strategy.
  */
 static void _opp_remove(struct device_opp *dev_opp,
-   struct dev_pm_opp *opp)
+   struct dev_pm_opp *opp, bool notify)
 {
/*
 * Notify the changes in the availability of the operable
 * frequency/voltage list.
 */
-   srcu_notifier_call_chain(&dev_opp->srcu_head, OPP_EVENT_REMOVE, opp);
+   if (notify)
+   srcu_notifier_call_chain(&dev_opp->srcu_head, OPP_EVENT_REMOVE, 
opp);
list_del_rcu(&opp->node);
call_srcu(&dev_opp->srcu_head.srcu, &opp->rcu_head, _kfree_opp_rcu);
 
@@ -544,12 +546,63 @@ void dev_pm_opp_remove(struct device *dev, unsigned long 
freq)
goto unlock;
}
 
-   _opp_remove(dev_opp, opp);
+   _opp_remove(dev_opp, opp, true);
 unlock:
mutex_unlock(&dev_opp_list_lock);
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_remove);
 
+static struct dev_pm_opp *_allocate_opp(struct device *dev,
+   struct device_opp **dev_opp)
+{
+   struct dev_pm_opp *opp;
+
+   /* allocate new OPP node */
+   opp = kzalloc(sizeof(*opp), GFP_KERNEL);
+   if (!opp)
+   return NULL;
+
+   INIT_LIST_HEAD(&opp->node);
+
+   *dev_opp = _add_device_opp(dev);
+   if (!*dev_opp) {
+   kfree(opp);
+   return NULL;
+   }
+
+   return opp;
+}
+
+static int _opp_add(struct dev_pm_opp *new_opp, struct device_opp *dev_opp)
+{
+   struct dev_pm_opp *opp;
+   struct list_head *head = &dev_opp->opp_list;
+
+   /*
+* Insert new OPP in order of increasing frequency
+* and discard if already present.
+*/
+   list_for_each_entry_rcu(opp, head, node) {
+   if (new_opp->rate > opp->rate)
+   head = &opp->node;
+   else if (new_opp->rate < opp->rate)
+   break;
+
+   /* Duplicate OPPs */
+   dev_warn(dev_opp->dev, "%s: duplicate OPPs detected. Existing: 
freq: %lu, volt: %lu, enabled: %d. New: freq: %lu, volt: %lu, enabled: %d\n",
+__func__, opp->rate, opp->u_volt, opp->available,
+new_opp->rate, new_opp->u_volt, new_opp->available);
+
+   return opp->available && new_opp->u_volt == opp->u_volt ?
+   0 : -EEXIST;
+   }
+
+   new_opp->dev_opp = dev_opp;
+   list_add_rcu(&new_opp->node, head);
+
+   return 0;
+}
+
 /**
  * _opp_add_dynamic() - Allocate a dynamic OPP.
  * @dev:   device for which we do this operation
@@ -581,53 +634,28 @@ static int _opp_add_dynamic(struct device *dev, unsigned 
long freq,
long u_volt, bool dynamic)
 {
struct device_opp *dev_opp;
-   struct dev_pm_opp *opp, *new_opp;
-   struct list_head *head;
+   struct dev_pm_opp *new_opp;
int ret;
 
-   /* allocate new OPP node */
-   new_opp = kzalloc(sizeof(*new_opp), GFP_KERNEL);
-   if (!new_opp)
-   return -ENOMEM;
-
/* Hold our list modification lock here */
mutex_lock(&dev_opp_list_lock);
 
+   new_opp = _allocate_opp(dev, &dev_opp);
+   if (!new_opp) {
+   ret = -ENOMEM;
+   goto unlock;
+   }
+
/* populate the opp table */
new_opp->rate = freq;
new_opp->u_volt = u_volt;
new_opp->available = true;
+   new_opp->dynamic = dynamic;
 
-   dev_opp = _add_device_opp(dev);
-   if (!dev_opp) {
-   ret = -ENOMEM;
-   goto free_opp;
-   }
-
-   /*
-* Insert new OPP in order of increasing frequency
-* and disca

[PATCH V2 10/11] opp: Add helpers for initializing CPU OPPs

2015-07-26 Thread Viresh Kumar
With "operating-points-v2" its possible to tell which devices share
OPPs. We already have infrastructure to decode that information.

This patch adds following APIs:
- of_get_cpus_sharing_opps: Returns cpumask of CPUs sharing OPPs (only
  valid with v2 bindings).
- of_cpumask_init_opp_table: Initializes OPPs for all CPUs present in
  cpumask.
- of_cpumask_free_opp_table: Frees OPPs for all CPUs present in cpumask.

- set_cpus_sharing_opps: Sets which CPUs share OPPs (only valid with old
  OPP bindings, as this information isn't present in DT).

Signed-off-by: Viresh Kumar 
---
 drivers/base/power/opp.c | 175 +++
 include/linux/pm_opp.h   |  23 +++
 2 files changed, 198 insertions(+)

diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c
index 22b1e6ae7a94..976c839cb238 100644
--- a/drivers/base/power/opp.c
+++ b/drivers/base/power/opp.c
@@ -11,6 +11,7 @@
  * published by the Free Software Foundation.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -1181,6 +1182,26 @@ void of_free_opp_table(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(of_free_opp_table);
 
+void of_cpumask_free_opp_table(cpumask_var_t cpumask)
+{
+   struct device *cpu_dev;
+   int cpu;
+
+   WARN_ON(cpumask_empty(cpumask));
+
+   for_each_cpu(cpu, cpumask) {
+   cpu_dev = get_cpu_device(cpu);
+   if (!cpu_dev) {
+   pr_err("%s: failed to get cpu%d device\n", __func__,
+  cpu);
+   continue;
+   }
+
+   of_free_opp_table(cpu_dev);
+   }
+}
+EXPORT_SYMBOL_GPL(of_cpumask_free_opp_table);
+
 /* Returns opp descriptor node from its phandle. Caller must do of_node_put() 
*/
 static struct device_node *
 _of_get_opp_desc_node_from_prop(struct device *dev, const struct property 
*prop)
@@ -1197,6 +1218,31 @@ _of_get_opp_desc_node_from_prop(struct device *dev, 
const struct property *prop)
return opp_np;
 }
 
+/* Returns opp descriptor node for a device. Caller must do of_node_put() */
+static struct device_node *_of_get_opp_desc_node(struct device *dev)
+{
+   const struct property *prop;
+
+   prop = of_find_property(dev->of_node, "operating-points-v2", NULL);
+   if (!prop)
+   return ERR_PTR(-ENODEV);
+   if (!prop->value)
+   return ERR_PTR(-ENODATA);
+
+   /*
+* TODO: Support for multiple OPP tables.
+*
+* There should be only ONE phandle present in "operating-points-v2"
+* property.
+*/
+   if (prop->length != sizeof(__be32)) {
+   dev_err(dev, "%s: Invalid opp desc phandle\n", __func__);
+   return ERR_PTR(-EINVAL);
+   }
+
+   return _of_get_opp_desc_node_from_prop(dev, prop);
+}
+
 /* Initializes OPP tables based on new bindings */
 static int _of_init_opp_table_v2(struct device *dev,
 const struct property *prop)
@@ -1337,4 +1383,133 @@ int of_init_opp_table(struct device *dev)
return _of_init_opp_table_v2(dev, prop);
 }
 EXPORT_SYMBOL_GPL(of_init_opp_table);
+
+int of_cpumask_init_opp_table(cpumask_var_t cpumask)
+{
+   struct device *cpu_dev;
+   int cpu, ret = 0;
+
+   WARN_ON(cpumask_empty(cpumask));
+
+   for_each_cpu(cpu, cpumask) {
+   cpu_dev = get_cpu_device(cpu);
+   if (!cpu_dev) {
+   pr_err("%s: failed to get cpu%d device\n", __func__,
+  cpu);
+   continue;
+   }
+
+   ret = of_init_opp_table(cpu_dev);
+   if (ret) {
+   pr_err("%s: couldn't find opp table for cpu:%d, %d\n",
+  __func__, cpu, ret);
+
+   /* Free all other OPPs */
+   of_cpumask_free_opp_table(cpumask);
+   break;
+   }
+   }
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(of_cpumask_init_opp_table);
+
+/* Required only for V1 bindings, as v2 can manage it from DT itself */
+int set_cpus_sharing_opps(struct device *cpu_dev, cpumask_var_t cpumask)
+{
+   struct device_list_opp *list_dev;
+   struct device_opp *dev_opp;
+   struct device *dev;
+   int cpu, ret = 0;
+
+   rcu_read_lock();
+
+   dev_opp = _find_device_opp(cpu_dev);
+   if (IS_ERR(dev_opp)) {
+   ret = -EINVAL;
+   goto out_rcu_read_unlock;
+   }
+
+   for_each_cpu(cpu, cpumask) {
+   if (cpu == cpu_dev->id)
+   continue;
+
+   dev = get_cpu_device(cpu);
+   if (!dev) {
+   dev_err(cpu_dev, "%s: failed to get cpu%d device\n",
+   __func__, cpu);
+   continue;
+   }
+
+   list_dev = _add_list_dev(dev, dev_opp);
+   if (!list_dev) {
+   dev_err(

[PATCH V2 06/11] opp: Add support to parse "operating-points-v2" bindings

2015-07-26 Thread Viresh Kumar
This adds support in OPP library to parse and create list of OPPs from
operating-points-v2 bindings. It takes care of most of the properties of
new bindings (except shared-opp, which will be handled separately).

For backward compatibility, we keep supporting earlier bindings. We try
to search for the new bindings first, in case they aren't present we
look for the old deprecated ones.

There are few things marked as TODO:
- Support for multiple OPP tables
- Support for multiple regulators

They should be fixed separately.

Signed-off-by: Viresh Kumar 
---
 drivers/base/power/opp.c | 250 ++-
 1 file changed, 226 insertions(+), 24 deletions(-)

diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c
index 962d62316b80..d9ebbd739b23 100644
--- a/drivers/base/power/opp.c
+++ b/drivers/base/power/opp.c
@@ -51,10 +51,15 @@
  * order.
  * @dynamic:   not-created from static DT entries.
  * @available: true/false - marks if this OPP as available or not
+ * @turbo: true if turbo (boost) OPP
  * @rate:  Frequency in hertz
- * @u_volt:Nominal voltage in microvolts corresponding to this OPP
+ * @u_volt:Target voltage in microvolts corresponding to this OPP
+ * @u_volt_min:Minimum voltage in microvolts corresponding to this OPP
+ * @u_volt_max:Maximum voltage in microvolts corresponding to this OPP
+ * @u_amp: Maximum current drawn by the device in microamperes
  * @dev_opp:   points back to the device_opp struct this opp belongs to
  * @rcu_head:  RCU callback head used for deferred freeing
+ * @np:OPP's device node.
  *
  * This structure stores the OPP information for a given device.
  */
@@ -63,11 +68,18 @@ struct dev_pm_opp {
 
bool available;
bool dynamic;
+   bool turbo;
unsigned long rate;
+
unsigned long u_volt;
+   unsigned long u_volt_min;
+   unsigned long u_volt_max;
+   unsigned long u_amp;
 
struct device_opp *dev_opp;
struct rcu_head rcu_head;
+
+   struct device_node *np;
 };
 
 /**
@@ -672,6 +684,118 @@ static int _opp_add_dynamic(struct device *dev, unsigned 
long freq,
return ret;
 }
 
+/* TODO: Support multiple regulators */
+static int opp_get_microvolt(struct dev_pm_opp *opp, struct device *dev)
+{
+   u32 microvolt[3] = {0};
+   int count, ret;
+
+   count = of_property_count_u32_elems(opp->np, "opp-microvolt");
+   if (!count)
+   return 0;
+
+   /* There can be one or three elements here */
+   if (count != 1 && count != 3) {
+   dev_err(dev, "%s: Invalid number of elements in opp-microvolt 
property (%d)\n",
+   __func__, count);
+   return -EINVAL;
+   }
+
+   ret = of_property_read_u32_array(opp->np, "opp-microvolt", microvolt,
+count);
+   if (ret) {
+   dev_err(dev, "%s: error parsing opp-microvolt: %d\n", __func__,
+   ret);
+   return -EINVAL;
+   }
+
+   opp->u_volt = microvolt[0];
+   opp->u_volt_min = microvolt[1];
+   opp->u_volt_max = microvolt[2];
+
+   return 0;
+}
+
+/**
+ * _opp_add_static_v2() - Allocate static OPPs (As per 'v2' DT bindings)
+ * @dev:   device for which we do this operation
+ * @np:device node
+ *
+ * This function adds an opp definition to the opp list and returns status. The
+ * opp can be controlled using dev_pm_opp_enable/disable functions and may be
+ * removed by dev_pm_opp_remove.
+ *
+ * Locking: The internal device_opp and opp structures are RCU protected.
+ * Hence this function internally uses RCU updater strategy with mutex locks
+ * to keep the integrity of the internal data structures. Callers should ensure
+ * that this function is *NOT* called under RCU protection or in contexts where
+ * mutex cannot be locked.
+ *
+ * Return:
+ * 0   On success OR
+ * Duplicate OPPs (both freq and volt are same) and opp->available
+ * -EEXIST Freq are same and volt are different OR
+ * Duplicate OPPs (both freq and volt are same) and !opp->available
+ * -ENOMEM Memory allocation failure
+ * -EINVAL Failed parsing the OPP node
+ */
+static int _opp_add_static_v2(struct device *dev, struct device_node *np)
+{
+   struct device_opp *dev_opp;
+   struct dev_pm_opp *new_opp;
+   int ret;
+
+   /* Hold our list modification lock here */
+   mutex_lock(&dev_opp_list_lock);
+
+   new_opp = _allocate_opp(dev, &dev_opp);
+   if (!new_opp) {
+   ret = -ENOMEM;
+   goto unlock;
+   }
+
+   ret = of_property_read_u32(np, "opp-hz", (u32 *)&new_opp->rate);
+   if (ret < 0) {
+   dev_err(dev, "%s: opp-hz not found\n", __func__);
+   goto free_opp;
+   }
+
+   new_opp->turbo = of_property_read_bool(np, "turbo-mode");
+
+   new_opp->n

[PATCH V2 09/11] OPP: Add support for opp-suspend

2015-07-26 Thread Viresh Kumar
With "operating-points-v2" bindings, its possible to specify the OPP to
which the device must be switched, before suspending.

This patch adds support for getting that information.

Signed-off-by: Viresh Kumar 
---
 drivers/base/power/opp.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c
index d6ab6af7e847..22b1e6ae7a94 100644
--- a/drivers/base/power/opp.c
+++ b/drivers/base/power/opp.c
@@ -133,6 +133,7 @@ struct device_opp {
struct device_node *np;
unsigned long clock_latency_ns_max;
bool shared_opp;
+   struct dev_pm_opp *suspend_opp;
 };
 
 /*
@@ -909,6 +910,16 @@ static int _opp_add_static_v2(struct device *dev, struct 
device_node *np)
if (ret)
goto free_opp;
 
+   /* OPP to select on device suspend */
+   if (of_property_read_bool(np, "opp-suspend")) {
+   if (dev_opp->suspend_opp)
+   dev_warn(dev, "%s: Multiple suspend OPPs found (%lu 
%lu)\n",
+__func__, dev_opp->suspend_opp->rate,
+new_opp->rate);
+   else
+   dev_opp->suspend_opp = new_opp;
+   }
+
if (new_opp->clock_latency_ns > dev_opp->clock_latency_ns_max)
dev_opp->clock_latency_ns_max = new_opp->clock_latency_ns;
 
-- 
2.4.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH V2 08/11] opp: Add OPP sharing information to OPP library

2015-07-26 Thread Viresh Kumar
An opp can be shared by multiple devices, for example its very common
for CPUs to share the OPPs, i.e. when they share clock/voltage rails.

This patch adds support of shared OPPs to the OPP library.

Instead of a single device, dev_opp will not contain a list of devices
that use it. It also senses if the device (we are trying to initialize
OPPs for) shares OPPs with a device added earlier and in that case we
update the list of devices managed by OPPs instead of duplicating OPPs
again.

The same infrastructure will be used for the old OPP bindings, with
later patches.

Reviewed-by: Stephen Boyd 
Signed-off-by: Viresh Kumar 
---
 drivers/base/power/opp.c | 174 ---
 1 file changed, 150 insertions(+), 24 deletions(-)

diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c
index 96d7d1b6730a..d6ab6af7e847 100644
--- a/drivers/base/power/opp.c
+++ b/drivers/base/power/opp.c
@@ -86,16 +86,33 @@ struct dev_pm_opp {
 };
 
 /**
+ * struct device_list_opp - devices managed by 'struct device_opp'
+ * @node:  list node
+ * @dev:   device to which the struct object belongs
+ * @rcu_head:  RCU callback head used for deferred freeing
+ *
+ * This is an internal data structure maintaining the list of devices that are
+ * managed by 'struct device_opp'.
+ */
+struct device_list_opp {
+   struct list_head node;
+   const struct device *dev;
+   struct rcu_head rcu_head;
+};
+
+/**
  * struct device_opp - Device opp structure
  * @node:  list node - contains the devices with OPPs that
  * have been registered. Nodes once added are not modified in this
  * list.
  * RCU usage: nodes are not modified in the list of device_opp,
  * however addition is possible and is secured by dev_opp_list_lock
- * @dev:   device pointer
  * @srcu_head: notifier head to notify the OPP availability changes.
  * @rcu_head:  RCU callback head used for deferred freeing
+ * @dev_list:  list of devices that share these OPPs
  * @opp_list:  list of opps
+ * @np:struct device_node pointer for opp's DT node.
+ * @shared_opp: OPP is shared between multiple devices.
  *
  * This is an internal data structure maintaining the link to opps attached to
  * a device. This structure is not meant to be shared to users as it is
@@ -108,12 +125,14 @@ struct dev_pm_opp {
 struct device_opp {
struct list_head node;
 
-   struct device *dev;
struct srcu_notifier_head srcu_head;
struct rcu_head rcu_head;
+   struct list_head dev_list;
struct list_head opp_list;
 
+   struct device_node *np;
unsigned long clock_latency_ns_max;
+   bool shared_opp;
 };
 
 /*
@@ -133,6 +152,38 @@ do {   
\
   "dev_opp_list_lock protection"); \
 } while (0)
 
+static struct device_list_opp *_find_list_dev(const struct device *dev,
+ struct device_opp *dev_opp)
+{
+   struct device_list_opp *list_dev;
+
+   list_for_each_entry(list_dev, &dev_opp->dev_list, node)
+   if (list_dev->dev == dev)
+   return list_dev;
+
+   return NULL;
+}
+
+static struct device_opp *_managed_opp(const struct device_node *np)
+{
+   struct device_opp *dev_opp;
+
+   list_for_each_entry_rcu(dev_opp, &dev_opp_list, node) {
+   if (dev_opp->np == np) {
+   /*
+* Multiple devices can point to the same OPP table and
+* so will have same node-pointer, np.
+*
+* But the OPPs will be considered as shared only if the
+* OPP table contains a "opp-shared" property.
+*/
+   return dev_opp->shared_opp ? dev_opp : NULL;
+   }
+   }
+
+   return NULL;
+}
+
 /**
  * _find_device_opp() - find device_opp struct using device pointer
  * @dev:   device pointer used to lookup device OPPs
@@ -149,21 +200,18 @@ do {  
\
  */
 static struct device_opp *_find_device_opp(struct device *dev)
 {
-   struct device_opp *tmp_dev_opp, *dev_opp = ERR_PTR(-ENODEV);
+   struct device_opp *dev_opp;
 
if (unlikely(IS_ERR_OR_NULL(dev))) {
pr_err("%s: Invalid parameters\n", __func__);
return ERR_PTR(-EINVAL);
}
 
-   list_for_each_entry_rcu(tmp_dev_opp, &dev_opp_list, node) {
-   if (tmp_dev_opp->dev == dev) {
-   dev_opp = tmp_dev_opp;
-   break;
-   }
-   }
+   list_for_each_entry_rcu(dev_opp, &dev_opp_list, node)
+   if (_find_list_dev(dev, dev_opp))
+   return dev_opp;
 
-   return dev_opp;
+   retu

[PATCH V2 11/11] cpufreq-dt: Add support for operating-points-v2 bindings

2015-07-26 Thread Viresh Kumar
Support for parsing operating-points-v2 bindings is in place now, lets
modify cpufreq-dt driver to use them.

For backward compatibility we will continue to support earlier bindings.
Special handling for that is required, to make sure OPPs are initialized
for all the CPUs.

Signed-off-by: Viresh Kumar 
---
 drivers/cpufreq/cpufreq-dt.c | 56 
 1 file changed, 46 insertions(+), 10 deletions(-)

diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
index 528a82bf5038..c6e7033076de 100644
--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -184,7 +184,6 @@ static int allocate_resources(int cpu, struct device **cdev,
 
 static int cpufreq_init(struct cpufreq_policy *policy)
 {
-   struct cpufreq_dt_platform_data *pd;
struct cpufreq_frequency_table *freq_table;
struct device_node *np;
struct private_data *priv;
@@ -193,6 +192,7 @@ static int cpufreq_init(struct cpufreq_policy *policy)
struct clk *cpu_clk;
unsigned long min_uV = ~0, max_uV = 0;
unsigned int transition_latency;
+   bool need_update = false;
int ret;
 
ret = allocate_resources(policy->cpu, &cpu_dev, &cpu_reg, &cpu_clk);
@@ -208,8 +208,47 @@ static int cpufreq_init(struct cpufreq_policy *policy)
goto out_put_reg_clk;
}
 
-   /* OPPs might be populated at runtime, don't check for error here */
-   of_init_opp_table(cpu_dev);
+   /* Get OPP-sharing information from "operating-points-v2" bindings */
+   ret = of_get_cpus_sharing_opps(cpu_dev, policy->cpus);
+   if (ret) {
+   /*
+* operating-points-v2 not supported, fallback to old method of
+* finding shared-OPPs for backward compatibility.
+*/
+   if (ret == -ENOENT)
+   need_update = true;
+   else
+   goto out_node_put;
+   }
+
+   /*
+* Initialize OPP tables for all policy->cpus. They will be shared by
+* all CPUs which have marked their CPUs shared with OPP bindings.
+*
+* For platforms not using operating-points-v2 bindings, we do this
+* before updating policy->cpus. Otherwise, we will end up creating
+* duplicate OPPs for policy->cpus.
+*
+* OPPs might be populated at runtime, don't check for error here
+*/
+   of_cpumask_init_opp_table(policy->cpus);
+
+   if (need_update) {
+   struct cpufreq_dt_platform_data *pd = cpufreq_get_driver_data();
+
+   if (!pd || !pd->independent_clocks)
+   cpumask_setall(policy->cpus);
+
+   /*
+* OPP tables are initialized only for policy->cpu, do it for
+* others as well.
+*/
+   set_cpus_sharing_opps(cpu_dev, policy->cpus);
+
+   of_property_read_u32(np, "clock-latency", &transition_latency);
+   } else {
+   transition_latency = dev_pm_opp_get_max_clock_latency(cpu_dev);
+   }
 
/*
 * But we need OPP table to function so if it is not there let's
@@ -230,7 +269,7 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 
of_property_read_u32(np, "voltage-tolerance", &priv->voltage_tolerance);
 
-   if (of_property_read_u32(np, "clock-latency", &transition_latency))
+   if (!transition_latency)
transition_latency = CPUFREQ_ETERNAL;
 
if (!IS_ERR(cpu_reg)) {
@@ -293,10 +332,6 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 
policy->cpuinfo.transition_latency = transition_latency;
 
-   pd = cpufreq_get_driver_data();
-   if (!pd || !pd->independent_clocks)
-   cpumask_setall(policy->cpus);
-
of_node_put(np);
 
return 0;
@@ -306,7 +341,8 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 out_free_priv:
kfree(priv);
 out_free_opp:
-   of_free_opp_table(cpu_dev);
+   of_cpumask_free_opp_table(policy->cpus);
+out_node_put:
of_node_put(np);
 out_put_reg_clk:
clk_put(cpu_clk);
@@ -322,7 +358,7 @@ static int cpufreq_exit(struct cpufreq_policy *policy)
 
cpufreq_cooling_unregister(priv->cdev);
dev_pm_opp_free_cpufreq_table(priv->cpu_dev, &policy->freq_table);
-   of_free_opp_table(priv->cpu_dev);
+   of_cpumask_free_opp_table(policy->related_cpus);
clk_put(policy->clk);
if (!IS_ERR(priv->cpu_reg))
regulator_put(priv->cpu_reg);
-- 
2.4.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH V2 03/11] OPP: Create _remove_device_opp() for freeing dev_opp

2015-07-26 Thread Viresh Kumar
This will be used from multiple places later. Lets create a separate
routine for that.

Reviewed-by: Stephen Boyd 
Reviewed-by: Bartlomiej Zolnierkiewicz 
Signed-off-by: Viresh Kumar 
---
 drivers/base/power/opp.c | 22 +-
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c
index 8c3fd57975fb..7895fdd64192 100644
--- a/drivers/base/power/opp.c
+++ b/drivers/base/power/opp.c
@@ -449,6 +449,22 @@ static void _kfree_device_rcu(struct rcu_head *head)
 }
 
 /**
+ * _remove_device_opp() - Removes a device OPP table
+ * @dev_opp: device OPP table to be removed.
+ *
+ * Removes/frees device OPP table it it doesn't contain any OPPs.
+ */
+static void _remove_device_opp(struct device_opp *dev_opp)
+{
+   if (!list_empty(&dev_opp->opp_list))
+   return;
+
+   list_del_rcu(&dev_opp->node);
+   call_srcu(&dev_opp->srcu_head.srcu, &dev_opp->rcu_head,
+ _kfree_device_rcu);
+}
+
+/**
  * _kfree_opp_rcu() - Free OPP RCU handler
  * @head:  RCU head
  */
@@ -481,11 +497,7 @@ static void _opp_remove(struct device_opp *dev_opp,
list_del_rcu(&opp->node);
call_srcu(&dev_opp->srcu_head.srcu, &opp->rcu_head, _kfree_opp_rcu);
 
-   if (list_empty(&dev_opp->opp_list)) {
-   list_del_rcu(&dev_opp->node);
-   call_srcu(&dev_opp->srcu_head.srcu, &dev_opp->rcu_head,
- _kfree_device_rcu);
-   }
+   _remove_device_opp(dev_opp);
 }
 
 /**
-- 
2.4.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH V2 02/11] opp: Relocate few routines

2015-07-26 Thread Viresh Kumar
In order to prepare for the later commits, this relocates few routines
towards the top as they will be used earlier in the code.

Reviewed-by: Stephen Boyd 
Reviewed-by: Bartlomiej Zolnierkiewicz 
Signed-off-by: Viresh Kumar 
---
 drivers/base/power/opp.c | 277 ---
 1 file changed, 139 insertions(+), 138 deletions(-)

diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c
index 677fb2843553..8c3fd57975fb 100644
--- a/drivers/base/power/opp.c
+++ b/drivers/base/power/opp.c
@@ -438,6 +438,102 @@ static struct device_opp *_add_device_opp(struct device 
*dev)
 }
 
 /**
+ * _kfree_device_rcu() - Free device_opp RCU handler
+ * @head:  RCU head
+ */
+static void _kfree_device_rcu(struct rcu_head *head)
+{
+   struct device_opp *device_opp = container_of(head, struct device_opp, 
rcu_head);
+
+   kfree_rcu(device_opp, rcu_head);
+}
+
+/**
+ * _kfree_opp_rcu() - Free OPP RCU handler
+ * @head:  RCU head
+ */
+static void _kfree_opp_rcu(struct rcu_head *head)
+{
+   struct dev_pm_opp *opp = container_of(head, struct dev_pm_opp, 
rcu_head);
+
+   kfree_rcu(opp, rcu_head);
+}
+
+/**
+ * _opp_remove()  - Remove an OPP from a table definition
+ * @dev_opp:   points back to the device_opp struct this opp belongs to
+ * @opp:   pointer to the OPP to remove
+ *
+ * This function removes an opp definition from the opp list.
+ *
+ * Locking: The internal device_opp and opp structures are RCU protected.
+ * It is assumed that the caller holds required mutex for an RCU updater
+ * strategy.
+ */
+static void _opp_remove(struct device_opp *dev_opp,
+   struct dev_pm_opp *opp)
+{
+   /*
+* Notify the changes in the availability of the operable
+* frequency/voltage list.
+*/
+   srcu_notifier_call_chain(&dev_opp->srcu_head, OPP_EVENT_REMOVE, opp);
+   list_del_rcu(&opp->node);
+   call_srcu(&dev_opp->srcu_head.srcu, &opp->rcu_head, _kfree_opp_rcu);
+
+   if (list_empty(&dev_opp->opp_list)) {
+   list_del_rcu(&dev_opp->node);
+   call_srcu(&dev_opp->srcu_head.srcu, &dev_opp->rcu_head,
+ _kfree_device_rcu);
+   }
+}
+
+/**
+ * dev_pm_opp_remove()  - Remove an OPP from OPP list
+ * @dev:   device for which we do this operation
+ * @freq:  OPP to remove with matching 'freq'
+ *
+ * This function removes an opp from the opp list.
+ *
+ * Locking: The internal device_opp and opp structures are RCU protected.
+ * Hence this function internally uses RCU updater strategy with mutex locks
+ * to keep the integrity of the internal data structures. Callers should ensure
+ * that this function is *NOT* called under RCU protection or in contexts where
+ * mutex cannot be locked.
+ */
+void dev_pm_opp_remove(struct device *dev, unsigned long freq)
+{
+   struct dev_pm_opp *opp;
+   struct device_opp *dev_opp;
+   bool found = false;
+
+   /* Hold our list modification lock here */
+   mutex_lock(&dev_opp_list_lock);
+
+   dev_opp = _find_device_opp(dev);
+   if (IS_ERR(dev_opp))
+   goto unlock;
+
+   list_for_each_entry(opp, &dev_opp->opp_list, node) {
+   if (opp->rate == freq) {
+   found = true;
+   break;
+   }
+   }
+
+   if (!found) {
+   dev_warn(dev, "%s: Couldn't find OPP with freq: %lu\n",
+__func__, freq);
+   goto unlock;
+   }
+
+   _opp_remove(dev_opp, opp);
+unlock:
+   mutex_unlock(&dev_opp_list_lock);
+}
+EXPORT_SYMBOL_GPL(dev_pm_opp_remove);
+
+/**
  * _opp_add_dynamic() - Allocate a dynamic OPP.
  * @dev:   device for which we do this operation
  * @freq:  Frequency in Hz for this OPP
@@ -570,102 +666,6 @@ int dev_pm_opp_add(struct device *dev, unsigned long 
freq, unsigned long u_volt)
 EXPORT_SYMBOL_GPL(dev_pm_opp_add);
 
 /**
- * _kfree_opp_rcu() - Free OPP RCU handler
- * @head:  RCU head
- */
-static void _kfree_opp_rcu(struct rcu_head *head)
-{
-   struct dev_pm_opp *opp = container_of(head, struct dev_pm_opp, 
rcu_head);
-
-   kfree_rcu(opp, rcu_head);
-}
-
-/**
- * _kfree_device_rcu() - Free device_opp RCU handler
- * @head:  RCU head
- */
-static void _kfree_device_rcu(struct rcu_head *head)
-{
-   struct device_opp *device_opp = container_of(head, struct device_opp, 
rcu_head);
-
-   kfree_rcu(device_opp, rcu_head);
-}
-
-/**
- * _opp_remove()  - Remove an OPP from a table definition
- * @dev_opp:   points back to the device_opp struct this opp belongs to
- * @opp:   pointer to the OPP to remove
- *
- * This function removes an opp definition from the opp list.
- *
- * Locking: The internal device_opp and opp structures are RCU protected.
- * It is assumed that the caller holds required mutex for an RCU updater
- * strategy.
- */
-static void _opp_remove(struct device_opp *dev_opp,
- 

Re: [PATCH v2 1/3] staging: sm7xxfb: move sm712fb out of staging

2015-07-26 Thread Sudip Mukherjee
On Sat, Jul 18, 2015 at 09:38:57AM +0530, Sudip Mukherjee wrote:
> Now since all cleanups are done and the code is ready to be merged lets
> move it out of staging into fbdev location.
Hi Tomi,

A gentle ping

regards
sudip
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/5] staging: lustre: Add one space after ', ' in parameters list.

2015-07-26 Thread Sudip Mukherjee
On Sat, Jul 25, 2015 at 09:49:19AM +0800, Incarnation P. Lee wrote:
> From: "Pan Li" 
> 
> Add one space after ',' in function call parameters list.
> Signed-off-by: Pan Li 
> 
> ---
This has already been done by 574150f0d275 ("staging:lustre: fix "space
required after that ', '" error in cl_page.c").

I think you need to refresh your tree.

regards
sudip
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 1/2] Move the pt_regs_offset struct definition from arch to common include file

2015-07-26 Thread David Long
From: "David A. Long" 

The pt_regs_offset structure is used for the HAVE_REGS_AND_STACK_ACCESS_API
feature and has identical definitions in four different arch ptrace.h
include files. It seems unlikely that definition would ever need to be
changed regardless of architecture so lets move it into
include/linux/ptrace.h, along with macros commonly used to access it.

Signed-off-by: David A. Long 
---
 arch/arm/kernel/ptrace.c |   7 +-
 arch/powerpc/kernel/ptrace.c |  31 -
 arch/sh/include/asm/ptrace.h |   9 +--
 arch/sh/kernel/ptrace_32.c   |  48 +++---
 arch/sh/kernel/ptrace_64.c   | 152 +--
 arch/x86/kernel/ptrace.c |  59 -
 include/linux/ptrace.h   |  12 
 7 files changed, 152 insertions(+), 166 deletions(-)

diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
index ef9119f..3b5a2ba 100644
--- a/arch/arm/kernel/ptrace.c
+++ b/arch/arm/kernel/ptrace.c
@@ -59,14 +59,9 @@
 #define BREAKINST_THUMB0xde01
 #endif
 
-struct pt_regs_offset {
-   const char *name;
-   int offset;
-};
 
 #define REG_OFFSET_NAME(r) \
{.name = #r, .offset = offsetof(struct pt_regs, ARM_##r)}
-#define REG_OFFSET_END {.name = NULL, .offset = 0}
 
 static const struct pt_regs_offset regoffset_table[] = {
REG_OFFSET_NAME(r0),
@@ -87,7 +82,7 @@ static const struct pt_regs_offset regoffset_table[] = {
REG_OFFSET_NAME(pc),
REG_OFFSET_NAME(cpsr),
REG_OFFSET_NAME(ORIG_r0),
-   REG_OFFSET_END,
+   REGS_OFFSET_END,
 };
 
 /**
diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index f21897b..b8f054c 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -52,16 +52,9 @@
 #define PARAMETER_SAVE_AREA_OFFSET 48  /* bytes */
 #endif
 
-struct pt_regs_offset {
-   const char *name;
-   int offset;
-};
-
 #define STR(s) #s  /* convert to string */
-#define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
 #define GPR_OFFSET_NAME(num)   \
{.name = STR(gpr##num), .offset = offsetof(struct pt_regs, gpr[num])}
-#define REG_OFFSET_END {.name = NULL, .offset = 0}
 
 static const struct pt_regs_offset regoffset_table[] = {
GPR_OFFSET_NAME(0),
@@ -96,21 +89,21 @@ static const struct pt_regs_offset regoffset_table[] = {
GPR_OFFSET_NAME(29),
GPR_OFFSET_NAME(30),
GPR_OFFSET_NAME(31),
-   REG_OFFSET_NAME(nip),
-   REG_OFFSET_NAME(msr),
-   REG_OFFSET_NAME(ctr),
-   REG_OFFSET_NAME(link),
-   REG_OFFSET_NAME(xer),
-   REG_OFFSET_NAME(ccr),
+   REGS_OFFSET_NAME(nip),
+   REGS_OFFSET_NAME(msr),
+   REGS_OFFSET_NAME(ctr),
+   REGS_OFFSET_NAME(link),
+   REGS_OFFSET_NAME(xer),
+   REGS_OFFSET_NAME(ccr),
 #ifdef CONFIG_PPC64
-   REG_OFFSET_NAME(softe),
+   REGS_OFFSET_NAME(softe),
 #else
-   REG_OFFSET_NAME(mq),
+   REGS_OFFSET_NAME(mq),
 #endif
-   REG_OFFSET_NAME(trap),
-   REG_OFFSET_NAME(dar),
-   REG_OFFSET_NAME(dsisr),
-   REG_OFFSET_END,
+   REGS_OFFSET_NAME(trap),
+   REGS_OFFSET_NAME(dar),
+   REGS_OFFSET_NAME(dsisr),
+   REGS_OFFSET_END,
 };
 
 /**
diff --git a/arch/sh/include/asm/ptrace.h b/arch/sh/include/asm/ptrace.h
index 2506c7d..523955f 100644
--- a/arch/sh/include/asm/ptrace.h
+++ b/arch/sh/include/asm/ptrace.h
@@ -23,17 +23,10 @@
 /*
  * kprobe-based event tracer support
  */
-struct pt_regs_offset {
-   const char *name;
-   int offset;
-};
-
-#define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
-#define REGS_OFFSET_NAME(num)  \
+#define REG_OFFSET_NAME(num)   \
{.name = __stringify(r##num), .offset = offsetof(struct pt_regs, 
regs[num])}
 #define TREGS_OFFSET_NAME(num) \
{.name = __stringify(tr##num), .offset = offsetof(struct pt_regs, 
tregs[num])}
-#define REG_OFFSET_END {.name = NULL, .offset = 0}
 
 /* Query offset/name of register from its name/offset */
 extern int regs_query_register_offset(const char *name);
diff --git a/arch/sh/kernel/ptrace_32.c b/arch/sh/kernel/ptrace_32.c
index c1a6b89..e6fe4f4 100644
--- a/arch/sh/kernel/ptrace_32.c
+++ b/arch/sh/kernel/ptrace_32.c
@@ -277,30 +277,30 @@ static int dspregs_active(struct task_struct *target,
 #endif
 
 const struct pt_regs_offset regoffset_table[] = {
-   REGS_OFFSET_NAME(0),
-   REGS_OFFSET_NAME(1),
-   REGS_OFFSET_NAME(2),
-   REGS_OFFSET_NAME(3),
-   REGS_OFFSET_NAME(4),
-   REGS_OFFSET_NAME(5),
-   REGS_OFFSET_NAME(6),
-   REGS_OFFSET_NAME(7),
-   REGS_OFFSET_NAME(8),
-   REGS_OFFSET_NAME(9),
-   REGS_OFFSET_NAME(10),
-   REGS_OFFSET_NAME(11),
-   REGS_OFFSET_NAME(12),
-   REGS_OFFSET_NAME(13),
-   REGS_OFFSET_NAME(14),
-   REGS_OFFSET_NAME(15),
-   REG_OFFSET_NAME(pc),
-   REG_OFFSET_NAME(pr),
-   REG_OFFSET_NAME(sr),
-   REG_OFFSET_NAME(gbr),
-   REG_OFFSET_

[PATCH v2 0/2] Consolidate redundant register/stack access code

2015-07-26 Thread David Long
From: "David A. Long" 

Move duplicate and functionally equivalent code for accessing registers
and stack (CONFIG_HAVE_REGS_AND_STACK_ACCESS_API) from arch subdirs into
common kernel files.

Changes since v1:
Move the REG_OFFSET_NAME and REG_OFFSET_END macros to architecture-
independent include file. Change their name from REG_* to REGS_* for
consistency.

Note: Help regression testing s390, hexagon, and sh would be appreciated.
  Powerpc builds but I have not verified the functionality.

David A. Long (2):
  Move the pt_regs_offset struct definition from arch to common include
file
  Consolidate redundant register/stack access code

 arch/arm/include/asm/ptrace.h  |   6 --
 arch/arm/kernel/ptrace.c   |  74 +---
 arch/hexagon/include/uapi/asm/ptrace.h |   3 -
 arch/powerpc/include/asm/ptrace.h  |  38 
 arch/powerpc/kernel/ptrace.c   |  65 +++---
 arch/s390/include/asm/ptrace.h |   3 -
 arch/s390/kernel/ptrace.c  |  69 +--
 arch/sh/include/asm/ptrace.h   |  48 +-
 arch/sh/kernel/Makefile|   2 +-
 arch/sh/kernel/ptrace.c|  33 ---
 arch/sh/kernel/ptrace_32.c |  50 +--
 arch/sh/kernel/ptrace_64.c | 154 -
 arch/x86/include/asm/ptrace.h  |  37 
 arch/x86/kernel/ptrace.c   |  93 ++--
 include/linux/ptrace.h |  54 
 kernel/ptrace.c|  38 
 16 files changed, 258 insertions(+), 509 deletions(-)
 delete mode 100644 arch/sh/kernel/ptrace.c

-- 
1.8.1.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 2/2] Consolidate redundant register/stack access code

2015-07-26 Thread David Long
From: "David A. Long" 

Several architectures have identical or functionally equivalent code
implementing parts of the HAVE_REGS_AND_STACK_ACCESS_API feature.  Move
that code out of the architecture directories.

Signed-off-by: David A. Long 
---
 arch/arm/include/asm/ptrace.h  |  6 ---
 arch/arm/kernel/ptrace.c   | 67 +
 arch/hexagon/include/uapi/asm/ptrace.h |  3 --
 arch/powerpc/include/asm/ptrace.h  | 38 ---
 arch/powerpc/kernel/ptrace.c   | 34 +
 arch/s390/include/asm/ptrace.h |  3 --
 arch/s390/kernel/ptrace.c  | 69 ++
 arch/sh/include/asm/ptrace.h   | 39 ---
 arch/sh/kernel/Makefile|  2 +-
 arch/sh/kernel/ptrace.c| 33 
 arch/sh/kernel/ptrace_32.c |  2 +-
 arch/sh/kernel/ptrace_64.c |  2 +-
 arch/x86/include/asm/ptrace.h  | 37 --
 arch/x86/kernel/ptrace.c   | 34 +
 include/linux/ptrace.h | 42 +
 kernel/ptrace.c| 38 +++
 16 files changed, 106 insertions(+), 343 deletions(-)
 delete mode 100644 arch/sh/kernel/ptrace.c

diff --git a/arch/arm/include/asm/ptrace.h b/arch/arm/include/asm/ptrace.h
index 51622ba..84a0ea4 100644
--- a/arch/arm/include/asm/ptrace.h
+++ b/arch/arm/include/asm/ptrace.h
@@ -120,12 +120,6 @@ extern unsigned long profile_pc(struct pt_regs *regs);
 #include 
 #define MAX_REG_OFFSET (offsetof(struct pt_regs, ARM_ORIG_r0))
 
-extern int regs_query_register_offset(const char *name);
-extern const char *regs_query_register_name(unsigned int offset);
-extern bool regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr);
-extern unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
-  unsigned int n);
-
 /**
  * regs_get_register() - get register value from its offset
  * @regs: pt_regs from which register value is gotten
diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
index 3b5a2ba..f26e23b 100644
--- a/arch/arm/kernel/ptrace.c
+++ b/arch/arm/kernel/ptrace.c
@@ -63,7 +63,7 @@
 #define REG_OFFSET_NAME(r) \
{.name = #r, .offset = offsetof(struct pt_regs, ARM_##r)}
 
-static const struct pt_regs_offset regoffset_table[] = {
+const struct pt_regs_offset regs_offset_table[] = {
REG_OFFSET_NAME(r0),
REG_OFFSET_NAME(r1),
REG_OFFSET_NAME(r2),
@@ -85,71 +85,6 @@ static const struct pt_regs_offset regoffset_table[] = {
REGS_OFFSET_END,
 };
 
-/**
- * regs_query_register_offset() - query register offset from its name
- * @name:  the name of a register
- *
- * regs_query_register_offset() returns the offset of a register in struct
- * pt_regs from its name. If the name is invalid, this returns -EINVAL;
- */
-int regs_query_register_offset(const char *name)
-{
-   const struct pt_regs_offset *roff;
-   for (roff = regoffset_table; roff->name != NULL; roff++)
-   if (!strcmp(roff->name, name))
-   return roff->offset;
-   return -EINVAL;
-}
-
-/**
- * regs_query_register_name() - query register name from its offset
- * @offset:the offset of a register in struct pt_regs.
- *
- * regs_query_register_name() returns the name of a register from its
- * offset in struct pt_regs. If the @offset is invalid, this returns NULL;
- */
-const char *regs_query_register_name(unsigned int offset)
-{
-   const struct pt_regs_offset *roff;
-   for (roff = regoffset_table; roff->name != NULL; roff++)
-   if (roff->offset == offset)
-   return roff->name;
-   return NULL;
-}
-
-/**
- * regs_within_kernel_stack() - check the address in the stack
- * @regs:  pt_regs which contains kernel stack pointer.
- * @addr:  address which is checked.
- *
- * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
- * If @addr is within the kernel stack, it returns true. If not, returns false.
- */
-bool regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr)
-{
-   return ((addr & ~(THREAD_SIZE - 1))  ==
-   (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
-}
-
-/**
- * regs_get_kernel_stack_nth() - get Nth entry of the stack
- * @regs:  pt_regs which contains kernel stack pointer.
- * @n: stack entry number.
- *
- * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
- * is specified by @regs. If the @n th entry is NOT in the kernel stack,
- * this returns 0.
- */
-unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
-{
-   unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
-   addr += n;
-   if (regs_within_kernel_stack(regs, (unsigned long)addr))
-   return *addr;
-   else
-   

Re: [PATCH] userns: simplify map_id_range_* functions

2015-07-26 Thread Eric W. Biederman
Nicolas Iooss  writes:

> Functions map_id_range_down, map_id_down and map_id_up all used the
> construction:
>
> if (...)
> id = ...
> else
> id = ...
> return id;
>
> which can be simplified by directly returning the result of the
> computations in each branch.
>
> Moreover as the condition tested whether the "break;" in the previous
> for loop was hit, it is simpler to directly compute the result and
> return it.

It is not a simplification, it is just code motion.

Further at least to my eyes adding multiple exit points and setting the
same value in two different places actually obscures what the functions
are doing.

If we could talk about speeding up the performance of the stat system
call I think there would be a point in mucking with these functions.

As it is I think it is I think merging your patch will just make it more
difficult to understand what the code is doing in the future, with no 
benefit except a reduction in line count.

Eric
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] regmap: regcache-rbtree: Clean new present bits on present bitmap resize

2015-07-26 Thread Guenter Roeck
When inserting a new register into a block, the present bit map size is
increased using krealloc. krealloc does not clear the additionally
allocated memory, leaving it filled with random values. Result is that
some registers are considered cached even though this is not the case.

Fix the problem by clearing the additionally allocated memory. Also, if
the bitmap size does not increase, do not reallocate the bitmap at all
to reduce overhead.

Fixes: 3f4ff561bc88 ("regmap: rbtree: Make cache_present bitmap per node")
Cc: Lars-Peter Clausen 
Signed-off-by: Guenter Roeck 
---
 drivers/base/regmap/regcache-rbtree.c | 19 ++-
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/drivers/base/regmap/regcache-rbtree.c 
b/drivers/base/regmap/regcache-rbtree.c
index 81751a49d8bf..56486d92c4e7 100644
--- a/drivers/base/regmap/regcache-rbtree.c
+++ b/drivers/base/regmap/regcache-rbtree.c
@@ -296,11 +296,20 @@ static int regcache_rbtree_insert_to_block(struct regmap 
*map,
if (!blk)
return -ENOMEM;
 
-   present = krealloc(rbnode->cache_present,
-   BITS_TO_LONGS(blklen) * sizeof(*present), GFP_KERNEL);
-   if (!present) {
-   kfree(blk);
-   return -ENOMEM;
+   if (BITS_TO_LONGS(blklen) > BITS_TO_LONGS(rbnode->blklen)) {
+   present = krealloc(rbnode->cache_present,
+  BITS_TO_LONGS(blklen) * sizeof(*present),
+  GFP_KERNEL);
+   if (!present) {
+   kfree(blk);
+   return -ENOMEM;
+   }
+
+   memset(present + BITS_TO_LONGS(rbnode->blklen), 0,
+  (BITS_TO_LONGS(blklen) - BITS_TO_LONGS(rbnode->blklen))
+  * sizeof(*present));
+   } else {
+   present = rbnode->cache_present;
}
 
/* insert the register value in the correct place in the rbnode block */
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Staging:dgap :Compression of lines for immediate return

2015-07-26 Thread Sudip Mukherjee
On Sun, Jul 26, 2015 at 11:04:13PM +0530, Shraddha Barke wrote:
> This patch compresses two lines into a single line if immediate return 
> statement
> is found. Also,remove variable rc as it is no longer needed.
> It is done using tool Coccinelle. And semantic patch used for this is as 
> follows:
> 
> @@
> expression ret;
> identifier f;
> @@
> 
> -ret =
> +return
>  f(...);
> -return ret;
> ---
Missed the Signed-off-by: here also, and always add the maintainers in
your To: list.

regards
sudip
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] LSM: LoadPin for module and firmware loading restrictions

2015-07-26 Thread James Morris
On Thu, 23 Jul 2015, Kees Cook wrote:

> +
> +/*
> + * Return an allocated string that has been escaped of special characters
> + * and double quotes, making it safe to log in quotes.
> + */
> +static char *kstrdup_quotable(char *src)
> +{

Do you think these should go into a library?



-- 
James Morris


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v10 6/7] sched: Provide runnable_load_avg back to cfs_rq

2015-07-26 Thread Yuyang Du
On Mon, Jul 27, 2015 at 12:04:20PM +0800, Boqun Feng wrote:
> > ~~~
> > > > 1) blocked load is more "difficult" to track, hint, migrate.
> > ~~~ 
> 
> I may not get your point here? Are you saying my patch fails to handle
> the migration or are you just telling me that blocked load tracking need
> to take migration into consideration?

Both, is it so difficult to get?
 
> If it's the latter one, I want to say that, with blocked load or not, we
> have to handle load_avg in migrations, so *adding* some code to handle
> blocked load is not a big deal.
> 
> Please consider this piece of code in update_cfs_rq_load_avg(), which
> decays and updates blocked_load_avg.
 
At this point of time, you tell me why exactly you want to track the blocked?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 5/6] iommu/mediatek: Add mt8173 IOMMU driver

2015-07-26 Thread Yong Wu
On Fri, 2015-07-24 at 17:55 +0100, Will Deacon wrote:
> On Fri, Jul 24, 2015 at 06:43:13AM +0100, Yong Wu wrote:
> > On Tue, 2015-07-21 at 15:59 +0100, Will Deacon wrote:
> > > On Thu, Jul 16, 2015 at 10:04:34AM +0100, Yong Wu wrote:
> > > > +static void mtk_iommu_tlb_flush_all(void *cookie)
> > > > +{
> > > > +   struct mtk_iommu_domain *domain = cookie;
> > > > +   void __iomem *base;
> > > > +
> > > > +   base = domain->data->base;
> > > > +   writel(F_INVLD_EN1 | F_INVLD_EN0, base + REG_MMU_INV_SEL);
> > > > +   writel(F_ALL_INVLD, base + REG_MMU_INVALIDATE);
> > > 
> > > This needs to be synchronous, so you probably want to call
> > > mtk_iommu_tlb_sync at the end.
> > 
> > From our spec, we have to wait until HW done after tlb flush range.
> > But it don't need wait after tlb flush all.
> > so It isn't necessary to add mtk_iommu_tlb_sync in tlb_flush_all here.
> 
> Okey doke, but I'm surprised you don't need a subsequent DSB or read-back.
> What if the writel is buffered on the way to the IOMMU?

Then I change to this:
 //==
writel_relaxed(F_INVLD_EN1 | F_INVLD_EN0, base + REG_MMU_INV_SEL);
writel_relaxed(F_ALL_INVLD, base + REG_MMU_INVALIDATE);
dsb(ishst);
//===
dsb or mb(). which one is better here?

> 
> Will


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v10 7/7] sched: Clean up load average references

2015-07-26 Thread Yuyang Du
Hi Dietmar,

On Fri, Jul 24, 2015 at 05:41:45PM +0100, Dietmar Eggemann wrote:
> On 15/07/15 01:04, Yuyang Du wrote:
> > For cfs_rq, we have load.weight, runnable_load_avg, and load_avg. We
> > now start to clean up how they are used.
> > 
> > First, as group sched_entity already largely uses load_avg, we now expand
> > to use load_avg in all cases.
> 
> You're talking about group se's or cfs_rq owned by the group se's
> (se->my_q) here or both?
 
Definitely, group SE, and if the cfs_rq owned by group SE is also concerned
with group SE, then both. I don't think this is very well calculated to be 
optimal, but probably this is the right move I can think of now.

We need to revisit all of the codes before we can at least make a final call.

> Just asking because both data structures (cfs_rq and se) have a 'struct
> load_weight load' as well as 'struct sched_avg avg' member.
> 
>  Second, for CPU-wide load balancing, we
> > choose to use runnable_load_avg in all cases, which is the same as before
> > this series.
> 
> With your patch-set there will be still the difference of
> 'cfs_rq->utilization_load_avg' and your 'cfs_rq->avg.util_avg' in the
> sense that the former one does not contain the contribution of blocked se's.
> 
> The EAS patch-set adds blocked utilization contribution:
> https://lkml.org/lkml/2015/7/7/915
> 
> The cfs_rq utilization is also used by the load-balancer code via
> get_cpu_usage() so the blocked utilization contribution to
> 'cfs_rq->avg.util_avg' can change load-balancing as well.
> 
> Since it is not as heavily used as the cfs_rq->runnable_load_avg we
> might not need to reintroduce cfs_rq->utilization_load_avg but at least
> mention this here.
> 

Yes, thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 3/6] iommu: add ARM short descriptor page table allocator.

2015-07-26 Thread Yong Wu
On Fri, 2015-07-24 at 17:53 +0100, Will Deacon wrote:
> On Fri, Jul 24, 2015 at 06:24:26AM +0100, Yong Wu wrote:
> > On Tue, 2015-07-21 at 18:11 +0100, Will Deacon wrote:
> > > On Thu, Jul 16, 2015 at 10:04:32AM +0100, Yong Wu wrote:
> > > > +/* level 2 pagetable */
> > > > +#define ARM_SHORT_PTE_TYPE_LARGE   BIT(0)
> > > > +#define ARM_SHORT_PTE_SMALL_XN BIT(0)
> > > > +#define ARM_SHORT_PTE_TYPE_SMALL   BIT(1)
> > > > +#define ARM_SHORT_PTE_BBIT(2)
> > > > +#define ARM_SHORT_PTE_CBIT(3)
> > > > +#define ARM_SHORT_PTE_SMALL_TEX0   BIT(6)
> > > > +#define ARM_SHORT_PTE_IMPLEBIT(9)
> > >
> > > This is AP[2] for small pages.
> > 
> > Sorry, In our pagetable bit9 in PGD and PTE is PA[32] that is for  the
> > dram size over 4G. I didn't care it is different in PTE of the standard
> > spec.
> > And I don't use the AP[2] currently, so I only delete this line in next
> > time.
> 
> Is this related to the "special bit". What would be good is a comment
> next to the #define for the quirk describing *exactly* that differs in
> your implementation. Without that, it's very difficult to know what is
> intentional and what is actually broken.

I will add the comment alongside the #define.

> 
> > > > +static arm_short_iopte
> > > > +__arm_short_pte_prot(struct arm_short_io_pgtable *data, int prot, bool 
> > > > large)
> > > > +{
> > > > +   arm_short_iopte pteprot;
> > > > +
> > > > +   pteprot = ARM_SHORT_PTE_S | ARM_SHORT_PTE_nG;
> > > > +   pteprot |= large ? ARM_SHORT_PTE_TYPE_LARGE :
> > > > +   ARM_SHORT_PTE_TYPE_SMALL;
> > > > +   if (prot & IOMMU_CACHE)
> > > > +   pteprot |=  ARM_SHORT_PTE_B | ARM_SHORT_PTE_C;
> > > > +   if (prot & IOMMU_WRITE)
> > > > +   pteprot |= large ? ARM_SHORT_PTE_LARGE_TEX0 :
> > > > +   ARM_SHORT_PTE_SMALL_TEX0;
> > >
> > > This doesn't make any sense. TEX[2:0] is all about memory attributes, not
> > > permissions, so you're making the mapping write-back, write-allocate but
> > > that's not what the IOMMU_* values are about.
> > 
> >  I will delete it.
> 
> Well, can you not control mapping permissions with the AP bits? The idea
> of the IOMMU flags are:
> 
>   IOMMU_CACHE : Install a normal, cacheable mapping (you've got this right)
>   IOMMU_READ : Allow read access for the device
>   IOMMU_WRITE : Allow write access for the device
>   IOMMU_NOEXEC : Disallow execute access for the device
> 
> so the caller to iommu_map passes in a bitmap of these, which you need to
> encode in the page-table entry.

>From the spec, AP[2] differentiate the read/write and readonly.
How about this?: 
//===
  #define ARM_SHORT_PGD_FULL_ACCESS  (3 << 10) 
  #define ARM_SHORT_PGD_RDONLY   BIT(15)

  pgdprot |= ARM_SHORT_PGD_FULL_ACCESS;/* or other names? */
  if(!(prot & IOMMU_WRITE) && (prot & IOMMU_READ))
 pgdprot |= ARM_SHORT_PGD_RDONLY;
//===
pte is the same. 

Sorry, Our HW don't meet the standard spec fully. it don't implement the
AP bits.

> 
> > > > +static int
> > > > +_arm_short_map(struct arm_short_io_pgtable *data,
> > > > +  unsigned int iova, phys_addr_t paddr,
> > > > +  arm_short_iopte pgdprot, arm_short_iopte pteprot,
> > > > +  bool large)
> > > > +{
> > > > +   const struct iommu_gather_ops *tlb = data->iop.cfg.tlb;
> > > > +   arm_short_iopte *pgd = data->pgd, *pte;
> > > > +   void *cookie = data->iop.cookie, *pte_va;
> > > > +   unsigned int ptenr = large ? 16 : 1;
> > > > +   int i, quirk = data->iop.cfg.quirks;
> > > > +   bool ptenew = false;
> > > > +
> > > > +   pgd += ARM_SHORT_PGD_IDX(iova);
> > > > +
> > > > +   if (!pteprot) { /* section or supersection */
> > > > +   if (quirk & IO_PGTABLE_QUIRK_SHORT_MTK)
> > > > +   pgdprot &= ~ARM_SHORT_PGD_SECTION_XN;
> > > > +   pte = pgd;
> > > > +   pteprot = pgdprot;
> > > > +   } else {/* page or largepage */
> > > > +   if (quirk & IO_PGTABLE_QUIRK_SHORT_MTK) {
> > > > +   if (large) { /* special Bit */
> > >
> > > This definitely needs a better comment! What exactly are you doing here
> > > and what is that quirk all about?
> > 
> > I use this quirk is for MTK Special Bit as we don't have the XN bit in
> > pagetable.
> 
> I'm still not really clear about what this is.

There is some difference between the standard spec and MTK HW,
Our hw don't implement some bits, like XN and AP.
So I add a quirk for MTK special.

> 
> > > > +   if (!(*pgd)) {
> > > > +   pte_va = kmem_cache_zalloc(data->ptekmem, 
> > > > GFP_ATOMIC);
> > > > +   if (unlikely(!pte_va))
> > > > +   return -ENOMEM;
> > > > +   ptenew

  1   2   3   >