Re: [PATCH v2] misc: aspeed-lpc-ctrl: make parameter optional

2019-04-30 Thread Joel Stanley
On Fri, 18 Jan 2019 at 20:12, Vijay Khemka  wrote:
>
> Hi Andrew,
> Thanks for this review, I will have a follow up patch for this return values.

Did you send a follow up patch to fix the return values?

Greg, is there any reason why you did not merge this one? 5.2 will
have device trees that depend on this patch's behavior.

Cheers,

Joel

> On 1/17/19, 8:58 PM, "Andrew Jeffery"  wrote:
>
> Hi Vijay,
>
> Thanks for doing the work to fix the driver. Some minor queries/points
> below.
>
> On Thu, 17 Jan 2019, at 08:31, Vijay Khemka wrote:
> > Makiing memory-region and flash as optional parameter in device
> > tree if user needs to use these parameter through ioctl then
> > need to define in devicetree.
> >
> > Signed-off-by: Vijay Khemka 
> > ---
> >  drivers/misc/aspeed-lpc-ctrl.c | 58 +-
> >  1 file changed, 36 insertions(+), 22 deletions(-)
> >
> > diff --git a/drivers/misc/aspeed-lpc-ctrl.c b/drivers/misc/aspeed-lpc-
> > ctrl.c
> > index a024f8042259..332210e06e98 100644
> > --- a/drivers/misc/aspeed-lpc-ctrl.c
> > +++ b/drivers/misc/aspeed-lpc-ctrl.c
> > @@ -68,6 +68,7 @@ static long aspeed_lpc_ctrl_ioctl(struct file *file,
> > unsigned int cmd,
> >   unsigned long param)
> >  {
> >   struct aspeed_lpc_ctrl *lpc_ctrl = file_aspeed_lpc_ctrl(file);
> > + struct device *dev = file->private_data;
> >   void __user *p = (void __user *)param;
> >   struct aspeed_lpc_ctrl_mapping map;
> >   u32 addr;
> > @@ -90,6 +91,12 @@ static long aspeed_lpc_ctrl_ioctl(struct file *file,
> > unsigned int cmd,
> >   if (map.window_id != 0)
> >   return -EINVAL;
> >
> > + /* If memory-region is not described in device tree */
> > + if (!lpc_ctrl->mem_size) {
> > + dev_err(dev, "Didn't find reserved memory\n");
> > + return -EINVAL;
>
> I feel like EINVAL isn't quite right - it's pretty generic, and the 
> parameter
> value changes its validity with the devicetree context. My gut instinct
> would be to use EINVAL for parameter values that violate assumptions
> of the driver rather than violate configuration of the driver. Maybe ENXIO
> ("No such device or address") is an improvement: "I can't map that device
> because there's no such device or address"?
>
> > + }
> > +
> >   map.size = lpc_ctrl->mem_size;
> >
> >   return copy_to_user(p, , sizeof(map)) ? -EFAULT : 0;
> > @@ -126,9 +133,18 @@ static long aspeed_lpc_ctrl_ioctl(struct file
> > *file, unsigned int cmd,
> >   return -EINVAL;
> >
> >   if (map.window_type == ASPEED_LPC_CTRL_WINDOW_FLASH) {
> > + if (!lpc_ctrl->pnor_size) {
> > + dev_err(dev, "Didn't find host pnor flash\n");
> > + return -EINVAL;
>
> See the error code discussion above. Also, this is userspace's error not
> the kernel's, so I think dev_err() is a bit harsh. Probably best to just 
> let
> userspace log the error if it thinks the it is concerning.
>
> > + }
> >   addr = lpc_ctrl->pnor_base;
> >   size = lpc_ctrl->pnor_size;
> >   } else if (map.window_type == ASPEED_LPC_CTRL_WINDOW_MEMORY) {
> > + /* If memory-region is not described in device tree */
> > + if (!lpc_ctrl->mem_size) {
> > + dev_err(dev, "Didn't find reserved memory\n");
> > + return -EINVAL;
>
> as above.
>
> > + }
> >   addr = lpc_ctrl->mem_base;
> >   size = lpc_ctrl->mem_size;
> >   } else {
> > @@ -196,17 +212,17 @@ static int aspeed_lpc_ctrl_probe(struct
> > platform_device *pdev)
> >   if (!lpc_ctrl)
> >   return -ENOMEM;
> >
> > + /* If flash is described in device tree then store */
> >   node = of_parse_phandle(dev->of_node, "flash", 0);
> >   if (!node) {
> > - dev_err(dev, "Didn't find host pnor flash node\n");
> > - return -ENODEV;
> > - }
> > -
> > - rc = of_address_to_resource(node, 1, );
> > - of_node_put(node);
> > - if (rc) {
> > - dev_err(dev, "Couldn't address to resource for flash\n");
> > - return rc;
> > + dev_dbg(dev, "Didn't find host pnor flash node\n");
> > + } else {
> > + rc = of_address_to_resource(node, 1, );
> > + of_node_put(node);
> > + if (rc) {
> > + dev_err(dev, "Couldn't address to resource for 
> flash\n");
> > + return rc;
> > + }
> >   }
> >
> >   lpc_ctrl->pnor_size = resource_size();

[PATCH v2] staging: vc04_services: bcm2835-camera: Compress two lines into one line

2019-04-30 Thread Vatsala Narang
Return value directly without saving it in a variable and remove that
variable.

Issue suggested by Coccinelle.

Signed-off-by: Vatsala Narang 
---
Changes in v2:
-Change subject line and log message
-Remove respective unused variable

 drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c 
b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
index c9b6346111a5..68f08dc18da9 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
+++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
@@ -1491,7 +1491,6 @@ static int set_camera_parameters(struct 
vchiq_mmal_instance *instance,
 struct vchiq_mmal_component *camera,
 struct bm2835_mmal_dev *dev)
 {
-   int ret;
struct mmal_parameter_camera_config cam_config = {
.max_stills_w = dev->max_width,
.max_stills_h = dev->max_height,
@@ -1507,10 +1506,9 @@ static int set_camera_parameters(struct 
vchiq_mmal_instance *instance,
.use_stc_timestamp = MMAL_PARAM_TIMESTAMP_MODE_RAW_STC
};
 
-   ret = vchiq_mmal_port_parameter_set(instance, >control,
+   return vchiq_mmal_port_parameter_set(instance, >control,
MMAL_PARAMETER_CAMERA_CONFIG,
_config, sizeof(cam_config));
-   return ret;
 }
 
 #define MAX_SUPPORTED_ENCODINGS 20
-- 
2.17.1



Re: [PATCH] dt-bindings: Add silabs,si5341

2019-04-30 Thread Mike Looijmans
On 30-04-19 02:17, Stephen Boyd wrote:
> Quoting Mike Looijmans (2019-04-27 02:42:56)
>> On 27-04-19 02:44, Stephen Boyd wrote:
>>> Quoting Mike Looijmans (2019-04-25 23:51:15)
 On 26-04-19 01:04, Stephen Boyd wrote:
>> +
>> +Optional properties:
>> +- silabs,pll-m-num, silabs,pll-m-den: Numerator and denominator for PLL
>> +  feedback divider. Must be such that the PLL output is in the valid 
>> range. For
>> +  example, to create 14GHz from a 48MHz xtal, use m-num=14000 and 
>> m-den=48. Only
>> +  the fraction matters, using 3500 and 12 will deliver the exact same 
>> result.
>> +  If these are not specified, and the PLL is not yet programmed when 
>> the driver
>> +  probes, the PLL will be set to 14GHz.
>
> Can this be done via assigned-clock-rates? Possibly with a table in the
> clk driver to tell us how to generate those rates.

 The PLL frequency choice determines who'll get jitter and who won't. It's
 ridiculously accurate too.

 For example, if you need a 26 MHz and a 100 MHz output, there's no solution
 for the PLL that makes both clocks an integer divider (SI is vague about 
 it,
 but apparently integer dividers have less jitter on output). Only the 
 enduser
 can say which clock will get the better quality.
> 
> Right. So maybe we make tables of rates and put it in the driver and
> keep adding code in there? I'm worried about having these properties in
> DT and then having to work around them later on by "fixing" the DT. If
> it's only in the driver then we're able to tweak the values to get
> better jitter numbers, etc.

Programming the main PLL is easy, no tables required.

It's all user choice, that's the issue here. Drivers themselves cannot make 
this decision.

(user = the person doing board support, writing the devicetree and kernel 
config for example)

In my example, the chip has no issue synthesizing both 26 and 100 MHz. 
Depending on the main PLL setting, one may have more jitter than the other. If 
the PLL is set to 14.0 GHz, the 100 MHz clock will be of better quality, while 
if the PLL is set to 13.624 GHz (an even multiple of 26), the 26 MHz will have 
better quality.


>> +- silabs,reprogram: When present, the driver will always assume the 
>> device must
>> +  be initialized, and always performs the soft-reset routine. Since 
>> this will
>> +  temporarily stop all output clocks, don't do this if the chip is 
>> generating
>> +  the CPU clock for example.
>
> Could this be done with the reset framework? It almost sounds like if
> the clk is a CLK_IS_CRITICAL then we shouldn't do the reset, otherwise
> we probably should reset the chip when the driver probes. If we don't
> have a case where it's going to be supplying a critical clk for a long
> time then perhaps we shouldn't even consider this topic until later.

 The driver can sort of see that the chips is already configured. This tells
 the driver whether that's expected or just coincidence.

 Maybe it'd be clearer if I reversed the logic and name this
 "silabs,preprogrammed", which will skip the driver's initialization 
 routine?

>>>
>>> Maybe? Is there any way to look at some register to figure out for sure
>>> if it's been pre-programmed or not? Could TOOL_VERSION be used or
>>> ACTIVE_NVM_BANK or DESIGN_ID0-7?
>>
>> I've experimentally determined that TOOL_VERSION and DESIGN_IDx
>> apparently get filled with zeroes by the clockbuilder anyway.
>>
>> ACTIVE_NVM_BANK works reliably for self-programmed chips.
>>
>> The flag is about "is this chip under full kernel control, or is it
>> generating clocks the kernel doesn't know about (e.g. for realtime cores
>> or FPGA logic)".
>>
> 
> Alright.
> 
>>
>>
>> +==Child nodes==
>> +
>> +Each of the clock outputs can be overwritten individually by
>> +using a child node to the I2C device node. If a child node for a clock
>> +output is not set, the configuration remains unchanged.
>> +
>> +Required child node properties:
>> +- reg: number of clock output.
>> +
>> +Optional child node properties:
>> +- silabs,format: Output format, see [1], 1=differential, 2=low-power, 
>> 4=LVCMOS
>> +- silabs,common-mode: Output common mode, depends on standard.
>> +- silabs,amplitude: Output amplitude, depends on standard.
>> +- silabs,synth-source: Select which multisynth to use for this output
>> +- silabs,synth-frequency: Sets the frequency for the multisynth 
>> connected to
>> +  this output. This will affect other outputs connected to this 
>> multisynth. The
>> +  setting is applied before silabs,synth-master and clock-frequency.
>> +- silabs,synth-master: If present, this output is allowed to change the
>> +  multisynth frequency dynamically.
>
> These above properties look like highly detailed configuration 

Re: [RFC PATCH 5/7] x86/mm/fault: hook up SCI verification

2019-04-30 Thread Mike Rapoport
On Tue, Apr 30, 2019 at 09:44:09AM -0700, Andy Lutomirski wrote:
> On Sat, Apr 27, 2019 at 10:47 PM Mike Rapoport  wrote:
> >
> > On Fri, Apr 26, 2019 at 09:42:23AM +0200, Peter Zijlstra wrote:
> > > On Fri, Apr 26, 2019 at 12:45:52AM +0300, Mike Rapoport wrote:
> > > > If a system call runs in isolated context, it's accesses to kernel code 
> > > > and
> > > > data will be verified by SCI susbsytem.
> > > >
> > > > Signed-off-by: Mike Rapoport 
> > > > ---
> > > >  arch/x86/mm/fault.c | 28 
> > > >  1 file changed, 28 insertions(+)
> > >
> > > There's a distinct lack of touching do_double_fault(). It appears to me
> > > that you'll instantly trigger #DF when you #PF, because the #PF handler
> > > itself will not be able to run.
> >
> > The #PF handler is able to run. On interrupt/error entry the cr3 is
> > switched to the full kernel page tables, pretty much like PTI does for
> > user <-> kernel transitions. It's in the patch 3.
> >
> >
> 
> PeterZ meant page_fault, not do_page_fault.  In your patch, page_fault
> and some of error_entry run before that magic switchover happens.  If
> they're not in the page tables, you double-fault.

The entry code is in sci page tables, just like in user-space page tables
with PTI.
 
> And don't even try to do SCI magic in the double-fault handler.  As I
> understand it, the SDM and APM aren't kidding when they say that #DF
> is an abort, not a fault.  There is a single case in the kernel where
> we recover from #DF, and it was vetted by microcode people.
> 

-- 
Sincerely yours,
Mike.



read and get back to me

2019-04-30 Thread Mr Anbrose Fred




-- 
Greetings

I wonder why you continue neglecting my emails. Please, acknowledge the
receipt of this message in reference to the subject above as I intend
to send to you the details of the project.

Sometimes, try to check your spam box because most of these
correspondences
fall out sometimes in SPAM folder.

Best regards.
Mr. Ambrose Fred


[PATCH] mm/slub: avoid double string traverse in kmem_cache_flags()

2019-04-30 Thread Yury Norov
If ',' is not found, kmem_cache_flags() calls strlen() to find the end
of line. We can do it in a single pass using strchrnul().

Signed-off-by: Yury Norov 
---
 mm/slub.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index 4922a0394757..85f90370a293 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1317,9 +1317,7 @@ slab_flags_t kmem_cache_flags(unsigned int object_size,
char *end, *glob;
size_t cmplen;
 
-   end = strchr(iter, ',');
-   if (!end)
-   end = iter + strlen(iter);
+   end = strchrnul(iter, ',');
 
glob = strnchr(iter, end - iter, '*');
if (glob)
-- 
2.17.1



Re: [v2 RFC PATCH 0/9] Another Approach to Use PMEM as NUMA Node

2019-04-30 Thread Fengguang Wu

On Thu, Apr 18, 2019 at 11:02:27AM +0200, Michal Hocko wrote:

On Wed 17-04-19 13:43:44, Yang Shi wrote:
[...]

And, I'm wondering whether this optimization is also suitable to general
NUMA balancing or not.


If there are convincing numbers then this should be a preferable way to
deal with it. Please note that the number of promotions is not the only
metric to watch. The overal performance/access latency would be another one.


Good question. Shi and me aligned today. Also talked with Mel (but
sorry I must missed some points due to poor English listening). It
becomes clear that

1) PMEM/DRAM page promotion/demotion is a hard problem to attack.
There will and should be multiple approaches for open discussion
before settling down. The criteria might be balanced complexity,
overheads, performance, etc.

2) We need a lot more data to lay solid foundation for effective
discussions. Testing will be a rather time consuming part for
contributor. We'll need to work together to create a number of
benchmarks that can well exercise the kernel promotion/demotion paths
and gather the necessary numbers. By collaborating on a common set of
tests, we can not only amortize efforts, but also compare different
approaches or compare v1/v2/... of the same approach conveniently.

Ying has already created several LKP test cases for that purpose.
Shi and me plan to join the efforts, too.

Thanks,
Fengguang


Re: [PATCH v8] Bluetooth: btqca: inject command complete event during fw download

2019-04-30 Thread Balakrishna Godavarthi

Hi Harish,

On 2019-04-30 21:08, Matthias Kaehlcke wrote:

On Tue, Apr 30, 2019 at 02:27:33PM +0800, kbuild test robot wrote:

Hi Matthias,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on bluetooth-next/master]
[also build test ERROR on next-20190429]
[cannot apply to v5.1-rc7]
[if your patch is applied to the wrong git tree, please drop us a note 
to help improve the system]


url:
https://github.com/0day-ci/linux/commits/Matthias-Kaehlcke/Bluetooth-btqca-inject-command-complete-event-during-fw-download/20190430-125407
base:   
https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git 
master

config: xtensa-allyesconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 8.1.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross 
-O ~/bin/make.cross

chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=8.1.0 make.cross ARCH=xtensa

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

All errors (new ones prefixed by >>):

   drivers/bluetooth/btqca.c: In function 
'qca_inject_cmd_complete_event':

>> drivers/bluetooth/btqca.c:286:18: error: 'QCA_HCI_CC_SUCCESS' undeclared 
(first use in this function); did you mean 'QCA_HCI_CC_OPCODE'?
 skb_put_u8(skb, QCA_HCI_CC_SUCCESS);
 ^~
 QCA_HCI_CC_OPCODE
   drivers/bluetooth/btqca.c:286:18: note: each undeclared identifier 
is reported only once for each function it appears in


vim +286 drivers/bluetooth/btqca.c

   267
   268  static int qca_inject_cmd_complete_event(struct hci_dev *hdev)
   269  {
   270  struct hci_event_hdr *hdr;
   271  struct hci_ev_cmd_complete *evt;
   272  struct sk_buff *skb;
   273
   274		skb = bt_skb_alloc(sizeof(*hdr) + sizeof(*evt) + 1, 
GFP_KERNEL);

   275  if (!skb)
   276  return -ENOMEM;
   277
   278  hdr = skb_put(skb, sizeof(*hdr));
   279  hdr->evt = HCI_EV_CMD_COMPLETE;
   280  hdr->plen = sizeof(*evt) + 1;
   281
   282  evt = skb_put(skb, sizeof(*evt));
   283  evt->ncmd = 1;
   284  evt->opcode = HCI_OP_NOP;
   285
 > 286   skb_put_u8(skb, QCA_HCI_CC_SUCCESS);


Oh, I changed it in my tree, but somehow missed to include this file
in the commit ...

I'll fix it in the next version. Since I expect the change to remain
controversial I'll wait a bit for other comments before sending out
v9.

Thanks

Matthias


[Bala]: can you check whether this change  is applicable for wcn3998 as 
well.


@Matthias, Thanks Matthias for taking Up :)

--
Regards
Balakrishna.


Re: arm64: Fix size of __early_cpu_boot_status

2019-04-30 Thread Arun KS
On Tue, Apr 30, 2019 at 4:39 PM Will Deacon  wrote:
>
> On Tue, Apr 30, 2019 at 04:05:04PM +0530, Arun KS wrote:
> > __early_cpu_boot_status is of type long. Use quad
> > assembler directive to allocate proper size.
> >
> > Signed-off-by: Arun KS 
> > ---
> >  arch/arm64/kernel/head.S | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
> > index eecf792..115f332 100644
> > --- a/arch/arm64/kernel/head.S
> > +++ b/arch/arm64/kernel/head.S
> > @@ -684,7 +684,7 @@ ENTRY(__boot_cpu_mode)
> >   * with MMU turned off.
> >   */
> >  ENTRY(__early_cpu_boot_status)
> > - .long   0
> > + .quad   0
>
> Yikes. How did you spot this? Did we end up corrupting an adjacent variable,
> or does the alignment in the linker script save us in practice?

Rite now there is no adjacent variable. But I was adding one and it
was getting corrupted.

Regards,
Arun
>
> Will


[PATCH v7 2/4] soc: qcom: Add AOSS QMP driver

2019-04-30 Thread Bjorn Andersson
The Always On Subsystem (AOSS) Qualcomm Messaging Protocol (QMP) driver
is used to communicate with the AOSS for certain side-channel requests,
that are not available through the RPMh interface.

The communication is a very simple synchronous mechanism of messages
being written in message RAM and a doorbell in the AOSS is rung. As the
AOSS has processed the message length is cleared and an interrupt is
fired by the AOSS as acknowledgment.

The driver exposes the QDSS clock as a clock and the low-power state
associated with the remoteprocs in the system as a set of power-domains.

Signed-off-by: Bjorn Andersson 
---

Changes since v6:
- Squash the pd into the same driver as the communication, to simplify
  the interaction.
- Representing the QDSS clocks as a clock/power domain turns out to
  cascade into a request to make all Coresight drivers have a secondary
  compatible to replace the required bus clock with a required power
  domain. So in v7 this is exposed as a clock instead.
- Some error checking updates, as reported by Doug.

 drivers/soc/qcom/Kconfig |  11 +
 drivers/soc/qcom/Makefile|   1 +
 drivers/soc/qcom/qcom_aoss.c | 473 +++
 3 files changed, 485 insertions(+)
 create mode 100644 drivers/soc/qcom/qcom_aoss.c

diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig
index 1ee298f6bf17..3e460b334b47 100644
--- a/drivers/soc/qcom/Kconfig
+++ b/drivers/soc/qcom/Kconfig
@@ -3,6 +3,17 @@
 #
 menu "Qualcomm SoC drivers"
 
+config QCOM_AOSS_QMP
+   tristate "Qualcomm AOSS Driver"
+   depends on ARCH_QCOM || COMPILE_TEST
+   depends on MAILBOX
+   select PM_GENERIC_DOMAINS
+   help
+ This driver provides the means of communicating with and controlling
+ the low-power state for resources related to the remoteproc
+ subsystems as well as controlling the debug clocks exposed by the 
Always On
+ Subsystem (AOSS) using Qualcomm Messaging Protocol (QMP).
+
 config QCOM_COMMAND_DB
bool "Qualcomm Command DB"
depends on ARCH_QCOM || COMPILE_TEST
diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile
index ffe519b0cb66..eeb088beb15f 100644
--- a/drivers/soc/qcom/Makefile
+++ b/drivers/soc/qcom/Makefile
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 CFLAGS_rpmh-rsc.o := -I$(src)
+obj-$(CONFIG_QCOM_AOSS_QMP) += qcom_aoss.o
 obj-$(CONFIG_QCOM_GENI_SE) +=  qcom-geni-se.o
 obj-$(CONFIG_QCOM_COMMAND_DB) += cmd-db.o
 obj-$(CONFIG_QCOM_GLINK_SSR) +=glink_ssr.o
diff --git a/drivers/soc/qcom/qcom_aoss.c b/drivers/soc/qcom/qcom_aoss.c
new file mode 100644
index ..f1fc26ab2e36
--- /dev/null
+++ b/drivers/soc/qcom/qcom_aoss.c
@@ -0,0 +1,473 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2019, Linaro Ltd
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define QMP_DESC_MAGIC 0x0
+#define QMP_DESC_VERSION   0x4
+#define QMP_DESC_FEATURES  0x8
+
+/* AOP-side offsets */
+#define QMP_DESC_UCORE_LINK_STATE  0xc
+#define QMP_DESC_UCORE_LINK_STATE_ACK  0x10
+#define QMP_DESC_UCORE_CH_STATE0x14
+#define QMP_DESC_UCORE_CH_STATE_ACK0x18
+#define QMP_DESC_UCORE_MBOX_SIZE   0x1c
+#define QMP_DESC_UCORE_MBOX_OFFSET 0x20
+
+/* Linux-side offsets */
+#define QMP_DESC_MCORE_LINK_STATE  0x24
+#define QMP_DESC_MCORE_LINK_STATE_ACK  0x28
+#define QMP_DESC_MCORE_CH_STATE0x2c
+#define QMP_DESC_MCORE_CH_STATE_ACK0x30
+#define QMP_DESC_MCORE_MBOX_SIZE   0x34
+#define QMP_DESC_MCORE_MBOX_OFFSET 0x38
+
+#define QMP_STATE_UP   0x
+#define QMP_STATE_DOWN 0x
+
+#define QMP_MAGIC  0x4d41494c
+#define QMP_VERSION1
+
+/* Requests are expected to be 96 bytes long */
+#define QMP_MSG_LEN96
+
+/**
+ * struct qmp - driver state for QMP implementation
+ * @msgram: iomem referencing the message RAM used for communication
+ * @dev: reference to QMP device
+ * @mbox_client: mailbox client used to ring the doorbell on transmit
+ * @mbox_chan: mailbox channel used to ring the doorbell on transmit
+ * @offset: offset within @msgram where messages should be written
+ * @size: maximum size of the messages to be transmitted
+ * @event: wait_queue for synchronization with the IRQ
+ * @tx_lock: provides syncrhonization between multiple callers of qmp_send()
+ * @qdss_clk: QDSS clock hw struct
+ * @pd_data: genpd data
+ */
+struct qmp {
+   void __iomem *msgram;
+   struct device *dev;
+
+   struct mbox_client mbox_client;
+   struct mbox_chan *mbox_chan;
+
+   size_t offset;
+   size_t size;
+
+   wait_queue_head_t event;
+
+   struct mutex tx_lock;
+
+   struct clk_hw qdss_clk;
+   struct genpd_onecell_data pd_data;
+};
+
+struct qmp_pd {
+   struct qmp *qmp;
+   struct generic_pm_domain pd;
+};
+
+#define to_qmp_pd_resource(res) container_of(res, struct qmp_pd, pd)
+
+static void 

[PATCH v7 0/4] Qualcomm AOSS QMP driver

2019-04-30 Thread Bjorn Andersson
Introduce a driver implementing Qualcomm Messaging Protocol (QMP) to
communicate with the Always On Subsystem (AOSS) and expose the low-power
states for the remoteprocs as a set of power-domains and the QDSS clock
as a clock.

Changes since v6:
- First couple of patches merged for v5.2
- Squashed the qmp and qmp-pd driver into one and by that moved it all
  to one file
- Expose QDSS clock as a clock instead of a power domain

Bjorn Andersson (3):
  dt-bindings: soc: qcom: Add AOSS QMP binding
  soc: qcom: Add AOSS QMP driver
  arm64: dts: qcom: Add AOSS QMP node

Sibi Sankar (1):
  arm64: dts: qcom: sdm845: Add Q6V5 MSS node

 .../bindings/soc/qcom/qcom,aoss-qmp.txt   |  81 +++
 arch/arm64/boot/dts/qcom/sdm845.dtsi  |  68 +++
 drivers/soc/qcom/Kconfig  |  11 +
 drivers/soc/qcom/Makefile |   1 +
 drivers/soc/qcom/qcom_aoss.c  | 473 ++
 include/dt-bindings/power/qcom-aoss-qmp.h |  14 +
 6 files changed, 648 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,aoss-qmp.txt
 create mode 100644 drivers/soc/qcom/qcom_aoss.c
 create mode 100644 include/dt-bindings/power/qcom-aoss-qmp.h

-- 
2.18.0



[PATCH v7 4/4] arm64: dts: qcom: sdm845: Add Q6V5 MSS node

2019-04-30 Thread Bjorn Andersson
From: Sibi Sankar 

This patch adds Q6V5 MSS remoteproc node for SDM845 SoCs.

Reviewed-by: Douglas Anderson 
Signed-off-by: Sibi Sankar 
Signed-off-by: Bjorn Andersson 
---

Changes since v6:
- None

 arch/arm64/boot/dts/qcom/sdm845.dtsi | 58 
 1 file changed, 58 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/sdm845.dtsi 
b/arch/arm64/boot/dts/qcom/sdm845.dtsi
index 666bc88d3e81..2f3ab6acda3d 100644
--- a/arch/arm64/boot/dts/qcom/sdm845.dtsi
+++ b/arch/arm64/boot/dts/qcom/sdm845.dtsi
@@ -1672,6 +1672,64 @@
};
};
 
+   mss_pil: remoteproc@408 {
+   compatible = "qcom,sdm845-mss-pil";
+   reg = <0 0x0408 0 0x408>, <0 0x0418 0 0x48>;
+   reg-names = "qdsp6", "rmb";
+
+   interrupts-extended =
+   < GIC_SPI 266 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 0 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 1 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 2 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 3 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 7 IRQ_TYPE_EDGE_RISING>;
+   interrupt-names = "wdog", "fatal", "ready",
+ "handover", "stop-ack",
+ "shutdown-ack";
+
+   clocks = < GCC_MSS_CFG_AHB_CLK>,
+< GCC_MSS_Q6_MEMNOC_AXI_CLK>,
+< GCC_BOOT_ROM_AHB_CLK>,
+< GCC_MSS_GPLL0_DIV_CLK_SRC>,
+< GCC_MSS_SNOC_AXI_CLK>,
+< GCC_MSS_MFAB_AXIS_CLK>,
+< GCC_PRNG_AHB_CLK>,
+< RPMH_CXO_CLK>;
+   clock-names = "iface", "bus", "mem", "gpll0_mss",
+ "snoc_axi", "mnoc_axi", "prng", "xo";
+
+   qcom,smem-states = <_smp2p_out 0>;
+   qcom,smem-state-names = "stop";
+
+   resets = <_reset AOSS_CC_MSS_RESTART>,
+<_reset PDC_MODEM_SYNC_RESET>;
+   reset-names = "mss_restart", "pdc_reset";
+
+   qcom,halt-regs = <_mutex_regs 0x23000 0x25000 
0x24000>;
+
+   power-domains = <_qmp AOSS_QMP_LS_MODEM>,
+   < SDM845_CX>,
+   < SDM845_MX>,
+   < SDM845_MSS>;
+   power-domain-names = "load_state", "cx", "mx", "mss";
+
+   mba {
+   memory-region = <_region>;
+   };
+
+   mpss {
+   memory-region = <_region>;
+   };
+
+   glink-edge {
+   interrupts = ;
+   label = "modem";
+   qcom,remote-pid = <1>;
+   mboxes = <_shared 12>;
+   };
+   };
+
gpucc: clock-controller@509 {
compatible = "qcom,sdm845-gpucc";
reg = <0 0x0509 0 0x9000>;
-- 
2.18.0



[PATCH v7 3/4] arm64: dts: qcom: Add AOSS QMP node

2019-04-30 Thread Bjorn Andersson
The AOSS QMP provides a number of power domains, used for QDSS and
PIL, add the node for this.

Tested-by: Sibi Sankar 
Reviewed-by: Sibi Sankar 
Signed-off-by: Bjorn Andersson 
---

Changes since v6:
- Added #clock-cells

 arch/arm64/boot/dts/qcom/sdm845.dtsi | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/sdm845.dtsi 
b/arch/arm64/boot/dts/qcom/sdm845.dtsi
index fcb93300ca62..666bc88d3e81 100644
--- a/arch/arm64/boot/dts/qcom/sdm845.dtsi
+++ b/arch/arm64/boot/dts/qcom/sdm845.dtsi
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -2142,6 +2143,15 @@
#reset-cells = <1>;
};
 
+   aoss_qmp: qmp@c30 {
+   compatible = "qcom,sdm845-aoss-qmp";
+   reg = <0 0x0c30 0 0x10>;
+   interrupts = ;
+   mboxes = <_shared 0>;
+
+   #clock-cells = <0>;
+   #power-domain-cells = <1>;
+   };
+
spmi_bus: spmi@c44 {
compatible = "qcom,spmi-pmic-arb";
reg = <0 0x0c44 0 0x1100>,
-- 
2.18.0



[PATCH v7 1/4] dt-bindings: soc: qcom: Add AOSS QMP binding

2019-04-30 Thread Bjorn Andersson
Add binding for the QMP based side-channel communication mechanism to
the AOSS, which is used to control resources not exposed through the
RPMh interface.

Signed-off-by: Bjorn Andersson 
---

Changes since v6:
- Added #clock-cells

 .../bindings/soc/qcom/qcom,aoss-qmp.txt   | 81 +++
 include/dt-bindings/power/qcom-aoss-qmp.h | 14 
 2 files changed, 95 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,aoss-qmp.txt
 create mode 100644 include/dt-bindings/power/qcom-aoss-qmp.h

diff --git a/Documentation/devicetree/bindings/soc/qcom/qcom,aoss-qmp.txt 
b/Documentation/devicetree/bindings/soc/qcom/qcom,aoss-qmp.txt
new file mode 100644
index ..14a45b3dc059
--- /dev/null
+++ b/Documentation/devicetree/bindings/soc/qcom/qcom,aoss-qmp.txt
@@ -0,0 +1,81 @@
+Qualcomm Always-On Subsystem side channel binding
+
+This binding describes the hardware component responsible for side channel
+requests to the always-on subsystem (AOSS), used for certain power management
+requests that is not handled by the standard RPMh interface. Each client in the
+SoC has it's own block of message RAM and IRQ for communication with the AOSS.
+The protocol used to communicate in the message RAM is known as Qualcomm
+Messagin Protocol (QMP)
+
+The AOSS side channel exposes control over a set of resources, used to control
+a set of debug related clocks and to affect the low power state of resources
+related to the secondary subsystems. These resources are exposed as a set of
+power-domains.
+
+- compatible:
+   Usage: required
+   Value type: 
+   Definition: must be "qcom,sdm845-aoss-qmp"
+
+- reg:
+   Usage: required
+   Value type: 
+   Definition: the base address and size of the message RAM for this
+   client's communication with the AOSS
+
+- interrupts:
+   Usage: required
+   Value type: 
+   Definition: should specify the AOSS message IRQ for this client
+
+- mboxes:
+   Usage: required
+   Value type: 
+   Definition: reference to the mailbox representing the outgoing doorbell
+   in APCS for this client, as described in mailbox/mailbox.txt
+
+- #clock-cells:
+   Usage: optional
+   Value type: 
+   Definition: must be 0
+   The single clock represents the QDSS clock.
+
+- #power-domain-cells:
+   Usage: optional
+   Value type: 
+   Definition: must be 1
+   The provided power-domains are:
+   CDSP state (0), LPASS state (1), modem state (2), SLPI
+   state (3), SPSS state (4) and Venus state (5).
+
+= SUBNODES
+The AOSS side channel also provides the controls for three cooling devices,
+these are expressed as subnodes of the QMP node. The name of the node is used
+to identify the resource and must therefor be "cx", "mx" or "ebi".
+
+- #cooling-cells:
+   Usage: optional
+   Value type: 
+   Definition: must be 2
+
+= EXAMPLE
+
+The following example represents the AOSS side-channel message RAM and the
+mechanism exposing the power-domains, as found in SDM845.
+
+  aoss_qmp: qmp@c30 {
+ compatible = "qcom,sdm845-aoss-qmp";
+ reg = <0x0c30 0x10>;
+ interrupts = ;
+ mboxes = <_shared 0>;
+
+ #power-domain-cells = <1>;
+
+ cx_cdev: cx {
+   #cooling-cells = <2>;
+ };
+
+ mx_cdev: mx {
+   #cooling-cells = <2>;
+ };
+  };
diff --git a/include/dt-bindings/power/qcom-aoss-qmp.h 
b/include/dt-bindings/power/qcom-aoss-qmp.h
new file mode 100644
index ..ec336d31dee4
--- /dev/null
+++ b/include/dt-bindings/power/qcom-aoss-qmp.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2018, Linaro Ltd. */
+
+#ifndef __DT_BINDINGS_POWER_QCOM_AOSS_QMP_H
+#define __DT_BINDINGS_POWER_QCOM_AOSS_QMP_H
+
+#define AOSS_QMP_LS_CDSP   0
+#define AOSS_QMP_LS_LPASS  1
+#define AOSS_QMP_LS_MODEM  2
+#define AOSS_QMP_LS_SLPI   3
+#define AOSS_QMP_LS_SPSS   4
+#define AOSS_QMP_LS_VENUS  5
+
+#endif
-- 
2.18.0



[PATCH v7 0/4] Qualcomm AOSS QMP driver

2019-04-30 Thread Bjorn Andersson
Introduce a driver implementing Qualcomm Messaging Protocol (QMP) to
communicate with the Always On Subsystem (AOSS) and expose the low-power states
for the remoteprocs as a set of power-domains and the QDSS clock as a clock.

Bjorn Andersson (3):
  dt-bindings: soc: qcom: Add AOSS QMP binding
  soc: qcom: Add AOSS QMP driver
  arm64: dts: qcom: Add AOSS QMP node

Sibi Sankar (1):
  arm64: dts: qcom: sdm845: Add Q6V5 MSS node

 .../bindings/soc/qcom/qcom,aoss-qmp.txt   |  81 +++
 arch/arm64/boot/dts/qcom/sdm845.dtsi  |  68 +++
 drivers/soc/qcom/Kconfig  |  11 +
 drivers/soc/qcom/Makefile |   1 +
 drivers/soc/qcom/qcom_aoss.c  | 473 ++
 include/dt-bindings/power/qcom-aoss-qmp.h |  14 +
 6 files changed, 648 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,aoss-qmp.txt
 create mode 100644 drivers/soc/qcom/qcom_aoss.c
 create mode 100644 include/dt-bindings/power/qcom-aoss-qmp.h

-- 
2.18.0



[PATCH 03/18] x86 smpboot: Rename match_die() to match_pkg()

2019-04-30 Thread Len Brown
From: Len Brown 

Syntax only, no functional or semantic change.

This routine matches packages, not die, so name it thus.

Signed-off-by: Len Brown 
---
 arch/x86/kernel/smpboot.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index ce1a67b70168..3f8bbfb26c18 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -455,7 +455,7 @@ static bool match_llc(struct cpuinfo_x86 *c, struct 
cpuinfo_x86 *o)
  * multicore group inside a NUMA node.  If this happens, we will
  * discard the MC level of the topology later.
  */
-static bool match_die(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)
+static bool match_pkg(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)
 {
if (c->phys_proc_id == o->phys_proc_id)
return true;
@@ -546,7 +546,7 @@ void set_cpu_sibling_map(int cpu)
for_each_cpu(i, cpu_sibling_setup_mask) {
o = _data(i);
 
-   if ((i == cpu) || (has_mp && match_die(c, o))) {
+   if ((i == cpu) || (has_mp && match_pkg(c, o))) {
link_mask(topology_core_cpumask, cpu, i);
 
/*
@@ -570,7 +570,7 @@ void set_cpu_sibling_map(int cpu)
} else if (i != cpu && !c->booted_cores)
c->booted_cores = cpu_data(i).booted_cores;
}
-   if (match_die(c, o) && !topology_same_node(c, o))
+   if (match_pkg(c, o) && !topology_same_node(c, o))
x86_has_numa_in_package = true;
}
 
-- 
2.18.0-rc0



[PATCH 09/18] powercap/intel_rapl: Simplify rapl_find_package()

2019-04-30 Thread Len Brown
From: Zhang Rui 

Syntax only, no functional or semantic change.

Simplify how the code to discover a package is called.
Rename find_package_by_id() to rapl_find_package_domain()

Signed-off-by: Zhang Rui 
Signed-off-by: Len Brown 
Acked-by: Rafael J. Wysocki 
Cc: linux...@vger.kernel.org
---
 drivers/powercap/intel_rapl.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c
index 4347f15165f8..3c3c0c23180b 100644
--- a/drivers/powercap/intel_rapl.c
+++ b/drivers/powercap/intel_rapl.c
@@ -264,8 +264,9 @@ static struct powercap_control_type *control_type; /* 
PowerCap Controller */
 static struct rapl_domain *platform_rapl_domain; /* Platform (PSys) domain */
 
 /* caller to ensure CPU hotplug lock is held */
-static struct rapl_package *find_package_by_id(int id)
+static struct rapl_package *rapl_find_package_domain(int cpu)
 {
+   int id = topology_physical_package_id(cpu);
struct rapl_package *rp;
 
list_for_each_entry(rp, _packages, plist) {
@@ -1300,7 +1301,7 @@ static int __init rapl_register_psys(void)
rd->rpl[0].name = pl1_name;
rd->rpl[1].prim_id = PL2_ENABLE;
rd->rpl[1].name = pl2_name;
-   rd->rp = find_package_by_id(0);
+   rd->rp = rapl_find_package_domain(0);
 
power_zone = powercap_register_zone(>power_zone, control_type,
"psys", NULL,
@@ -1456,8 +1457,9 @@ static void rapl_remove_package(struct rapl_package *rp)
 }
 
 /* called from CPU hotplug notifier, hotplug lock held */
-static struct rapl_package *rapl_add_package(int cpu, int pkgid)
+static struct rapl_package *rapl_add_package(int cpu)
 {
+   int id = topology_physical_package_id(cpu);
struct rapl_package *rp;
int ret;
 
@@ -1466,7 +1468,7 @@ static struct rapl_package *rapl_add_package(int cpu, int 
pkgid)
return ERR_PTR(-ENOMEM);
 
/* add the new package to the list */
-   rp->id = pkgid;
+   rp->id = id;
rp->lead_cpu = cpu;
 
/* check if the package contains valid domains */
@@ -1497,12 +1499,11 @@ static struct rapl_package *rapl_add_package(int cpu, 
int pkgid)
  */
 static int rapl_cpu_online(unsigned int cpu)
 {
-   int pkgid = topology_physical_package_id(cpu);
struct rapl_package *rp;
 
-   rp = find_package_by_id(pkgid);
+   rp = rapl_find_package_domain(cpu);
if (!rp) {
-   rp = rapl_add_package(cpu, pkgid);
+   rp = rapl_add_package(cpu);
if (IS_ERR(rp))
return PTR_ERR(rp);
}
@@ -1512,11 +1513,10 @@ static int rapl_cpu_online(unsigned int cpu)
 
 static int rapl_cpu_down_prep(unsigned int cpu)
 {
-   int pkgid = topology_physical_package_id(cpu);
struct rapl_package *rp;
int lead_cpu;
 
-   rp = find_package_by_id(pkgid);
+   rp = rapl_find_package_domain(cpu);
if (!rp)
return 0;
 
-- 
2.18.0-rc0



[PATCH 07/18] x86 topology: Define topology_die_id()

2019-04-30 Thread Len Brown
From: Len Brown 

topology_die_id(cpu) is a simple macro for use inside the kernel
to get the die_id associated with the given cpu.

Signed-off-by: Len Brown 
---
 arch/x86/include/asm/topology.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h
index e0232f7042c3..3777dbe9c0ff 100644
--- a/arch/x86/include/asm/topology.h
+++ b/arch/x86/include/asm/topology.h
@@ -106,6 +106,7 @@ extern const struct cpumask *cpu_coregroup_mask(int cpu);
 
 #define topology_logical_package_id(cpu)   (cpu_data(cpu).logical_proc_id)
 #define topology_physical_package_id(cpu)  (cpu_data(cpu).phys_proc_id)
+#define topology_die_id(cpu)   (cpu_data(cpu).cpu_die_id)
 #define topology_core_id(cpu)  (cpu_data(cpu).cpu_core_id)
 
 #ifdef CONFIG_SMP
-- 
2.18.0-rc0



[PATCH 05/18] x86 topology: Create topology_max_die_per_package()

2019-04-30 Thread Len Brown
From: Len Brown 

topology_max_packages() is available to size resources to
cover all packages in the system.

But now we have multi-die/package systems, and some
resources are per-die.

Create topology_max_die_per_package(), for detecting
multi-die/package systems, and sizing any per-die resources.

Signed-off-by: Len Brown 
---
 arch/x86/include/asm/processor.h |  1 -
 arch/x86/include/asm/topology.h  | 10 ++
 arch/x86/kernel/cpu/topology.c   |  5 -
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 2507edc30cc2..5f45488b1a9d 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -106,7 +106,6 @@ struct cpuinfo_x86 {
unsigned long   loops_per_jiffy;
/* cpuid returned max cores value: */
u16 x86_max_cores;
-   u16 x86_max_dies;
u16 apicid;
u16 initial_apicid;
u16 x86_clflush_size;
diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h
index 453cf38a1c33..e0232f7042c3 100644
--- a/arch/x86/include/asm/topology.h
+++ b/arch/x86/include/asm/topology.h
@@ -115,6 +115,13 @@ extern const struct cpumask *cpu_coregroup_mask(int cpu);
 extern unsigned int __max_logical_packages;
 #define topology_max_packages()(__max_logical_packages)
 
+extern unsigned int __max_die_per_package;
+
+static inline int topology_max_die_per_package(void)
+{
+   return __max_die_per_package;
+}
+
 extern int __max_smt_threads;
 
 static inline int topology_max_smt_threads(void)
@@ -131,6 +138,9 @@ bool topology_smt_supported(void);
 static inline int
 topology_update_package_map(unsigned int apicid, unsigned int cpu) { return 0; 
}
 static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return 0; }
+static inline int topology_phys_to_logical_die(unsigned int die,
+   unsigned int cpu) { return 0; }
+static inline int topology_max_die_per_package(void) { return 1; }
 static inline int topology_max_smt_threads(void) { return 1; }
 static inline bool topology_is_primary_thread(unsigned int cpu) { return true; 
}
 static inline bool topology_smt_supported(void) { return false; }
diff --git a/arch/x86/kernel/cpu/topology.c b/arch/x86/kernel/cpu/topology.c
index 4d17e699657d..ee48c3fc8a65 100644
--- a/arch/x86/kernel/cpu/topology.c
+++ b/arch/x86/kernel/cpu/topology.c
@@ -26,6 +26,9 @@
 #define LEVEL_MAX_SIBLINGS(ebx)((ebx) & 0x)
 
 #ifdef CONFIG_SMP
+unsigned int __max_die_per_package __read_mostly = 1;
+EXPORT_SYMBOL(__max_die_per_package);
+
 /*
  * Check if given CPUID extended toplogy "leaf" is implemented
  */
@@ -146,7 +149,7 @@ int detect_extended_topology(struct cpuinfo_x86 *c)
c->apicid = apic->phys_pkg_id(c->initial_apicid, 0);
 
c->x86_max_cores = (core_level_siblings / smp_num_siblings);
-   c->x86_max_dies = (die_level_siblings / core_level_siblings);
+   __max_die_per_package = (die_level_siblings / core_level_siblings);
 #endif
return 0;
 }
-- 
2.18.0-rc0



[PATCH 12/18] powercap/intel_rapl: update rapl domain name and debug messages

2019-04-30 Thread Len Brown
From: Zhang Rui 

The RAPL domain "name" attribute contains "Package-N",
which is ambiguous on multi-die per-package systems.

Update the name to "package-X-die-Y" on those systems.

No change on systems without multi-die/package.

Update driver debug messages.

Signed-off-by: Zhang Rui 
Signed-off-by: Len Brown 
Acked-by: Rafael J. Wysocki 
Cc: linux...@vger.kernel.org
---
 drivers/powercap/intel_rapl.c | 57 ---
 1 file changed, 32 insertions(+), 25 deletions(-)

diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c
index 9202dbcef96d..ad78c1d08260 100644
--- a/drivers/powercap/intel_rapl.c
+++ b/drivers/powercap/intel_rapl.c
@@ -178,12 +178,15 @@ struct rapl_domain {
 #define power_zone_to_rapl_domain(_zone) \
container_of(_zone, struct rapl_domain, power_zone)
 
+/* maximum rapl package domain name: package-%d-die-%d */
+#define PACKAGE_DOMAIN_NAME_LENGTH 30
 
-/* Each physical package contains multiple domains, these are the common
+
+/* Each rapl package contains multiple domains, these are the common
  * data across RAPL domains within a package.
  */
 struct rapl_package {
-   unsigned int id; /* physical package/socket id */
+   unsigned int id; /* logical die id, equals physical 1-die systems */
unsigned int nr_domains;
unsigned long domain_map; /* bit map of active domains */
unsigned int power_unit;
@@ -198,6 +201,7 @@ struct rapl_package {
int lead_cpu; /* one active cpu per package for access */
/* Track active cpus */
struct cpumask cpumask;
+   char name[PACKAGE_DOMAIN_NAME_LENGTH];
 };
 
 struct rapl_defaults {
@@ -926,8 +930,8 @@ static int rapl_check_unit_core(struct rapl_package *rp, 
int cpu)
value = (msr_val & TIME_UNIT_MASK) >> TIME_UNIT_OFFSET;
rp->time_unit = 100 / (1 << value);
 
-   pr_debug("Core CPU package %d energy=%dpJ, time=%dus, power=%duW\n",
-   rp->id, rp->energy_unit, rp->time_unit, rp->power_unit);
+   pr_debug("Core CPU %s energy=%dpJ, time=%dus, power=%duW\n",
+   rp->name, rp->energy_unit, rp->time_unit, rp->power_unit);
 
return 0;
 }
@@ -951,8 +955,8 @@ static int rapl_check_unit_atom(struct rapl_package *rp, 
int cpu)
value = (msr_val & TIME_UNIT_MASK) >> TIME_UNIT_OFFSET;
rp->time_unit = 100 / (1 << value);
 
-   pr_debug("Atom package %d energy=%dpJ, time=%dus, power=%duW\n",
-   rp->id, rp->energy_unit, rp->time_unit, rp->power_unit);
+   pr_debug("Atom %s energy=%dpJ, time=%dus, power=%duW\n",
+   rp->name, rp->energy_unit, rp->time_unit, rp->power_unit);
 
return 0;
 }
@@ -1181,7 +1185,7 @@ static void rapl_update_domain_data(struct rapl_package 
*rp)
u64 val;
 
for (dmn = 0; dmn < rp->nr_domains; dmn++) {
-   pr_debug("update package %d domain %s data\n", rp->id,
+   pr_debug("update %s domain %s data\n", rp->name,
 rp->domains[dmn].name);
/* exclude non-raw primitives */
for (prim = 0; prim < NR_RAW_PRIMITIVES; prim++) {
@@ -1206,7 +1210,6 @@ static void rapl_unregister_powercap(void)
 static int rapl_package_register_powercap(struct rapl_package *rp)
 {
struct rapl_domain *rd;
-   char dev_name[17]; /* max domain name = 7 + 1 + 8 for int + 1 for null*/
struct powercap_zone *power_zone = NULL;
int nr_pl, ret;
 
@@ -1217,20 +1220,16 @@ static int rapl_package_register_powercap(struct 
rapl_package *rp)
for (rd = rp->domains; rd < rp->domains + rp->nr_domains; rd++) {
if (rd->id == RAPL_DOMAIN_PACKAGE) {
nr_pl = find_nr_power_limit(rd);
-   pr_debug("register socket %d package domain %s\n",
-   rp->id, rd->name);
-   memset(dev_name, 0, sizeof(dev_name));
-   snprintf(dev_name, sizeof(dev_name), "%s-%d",
-   rd->name, rp->id);
+   pr_debug("register package domain %s\n", rp->name);
power_zone = powercap_register_zone(>power_zone,
control_type,
-   dev_name, NULL,
+   rp->name, NULL,
_ops[rd->id],
nr_pl,
_ops);
if (IS_ERR(power_zone)) {
-   pr_debug("failed to register package, %d\n",
-   rp->id);
+   pr_debug("failed to register power zone %s\n",
+   rp->name);
return PTR_ERR(power_zone);
 

[PATCH 17/18] perf/x86/intel/rapl: Support multi-die/package

2019-04-30 Thread Len Brown
From: Kan Liang 

RAPL becomes die-scope on Xeon Cascade Lake-AP. Perf RAPL driver needs
to support die-scope RAPL domain.

Use topology_logical_die_id() to replace topology_logical_package_id().
For previous platforms which doesn't have multi-die,
topology_logical_die_id() is identical as topology_logical_package_id().

Use topology_die_cpumask() to replace topology_core_cpumask().
For previous platforms which doesn't have multi-die,
topology_die_cpumask() is identical as topology_core_cpumask().

There is no functional change for previous platforms.

Signed-off-by: Kan Liang 
Cc: Peter Zijlstra 
Signed-off-by: Len Brown 
---
 arch/x86/events/intel/rapl.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/x86/events/intel/rapl.c b/arch/x86/events/intel/rapl.c
index 94dc564146ca..e49f69c51b10 100644
--- a/arch/x86/events/intel/rapl.c
+++ b/arch/x86/events/intel/rapl.c
@@ -161,7 +161,7 @@ static u64 rapl_timer_ms;
 
 static inline struct rapl_pmu *cpu_to_rapl_pmu(unsigned int cpu)
 {
-   unsigned int pkgid = topology_logical_package_id(cpu);
+   unsigned int pkgid = topology_logical_die_id(cpu);
 
/*
 * The unsigned check also catches the '-1' return value for non
@@ -571,7 +571,7 @@ static int rapl_cpu_offline(unsigned int cpu)
 
pmu->cpu = -1;
/* Find a new cpu to collect rapl events */
-   target = cpumask_any_but(topology_core_cpumask(cpu), cpu);
+   target = cpumask_any_but(topology_die_cpumask(cpu), cpu);
 
/* Migrate rapl events to the new target */
if (target < nr_cpu_ids) {
@@ -598,14 +598,14 @@ static int rapl_cpu_online(unsigned int cpu)
pmu->timer_interval = ms_to_ktime(rapl_timer_ms);
rapl_hrtimer_init(pmu);
 
-   rapl_pmus->pmus[topology_logical_package_id(cpu)] = pmu;
+   rapl_pmus->pmus[topology_logical_die_id(cpu)] = pmu;
}
 
/*
 * Check if there is an online cpu in the package which collects rapl
 * events already.
 */
-   target = cpumask_any_and(_cpu_mask, topology_core_cpumask(cpu));
+   target = cpumask_any_and(_cpu_mask, topology_die_cpumask(cpu));
if (target < nr_cpu_ids)
return 0;
 
@@ -675,7 +675,7 @@ static void cleanup_rapl_pmus(void)
 
 static int __init init_rapl_pmus(void)
 {
-   int maxpkg = topology_max_packages();
+   int maxpkg = topology_max_packages() * topology_max_die_per_package();
size_t size;
 
size = sizeof(*rapl_pmus) + maxpkg * sizeof(struct rapl_pmu *);
-- 
2.18.0-rc0



[PATCH 13/18] hwmon/coretemp: Support multi-die/package

2019-04-30 Thread Len Brown
From: Zhang Rui 

Package temperature sensors are actually implemented in hardware per-die.

Update coretemp to be "die-aware", so it can expose mulitple sensors
per package, instead of just one.  No change to single-die/package
systems.

Signed-off-by: Zhang Rui 
Signed-off-by: Len Brown 
Acked-by: Guenter Roeck 
Cc: linux...@vger.kernel.org
Cc: linux-hw...@vger.kernel.org
---
 drivers/hwmon/coretemp.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
index 5d34f7271e67..23a2d90534c7 100644
--- a/drivers/hwmon/coretemp.c
+++ b/drivers/hwmon/coretemp.c
@@ -435,7 +435,7 @@ static int chk_ucode_version(unsigned int cpu)
 
 static struct platform_device *coretemp_get_pdev(unsigned int cpu)
 {
-   int pkgid = topology_logical_package_id(cpu);
+   int pkgid = topology_logical_die_id(cpu);
 
if (pkgid >= 0 && pkgid < max_packages)
return pkg_devices[pkgid];
@@ -579,7 +579,7 @@ static struct platform_driver coretemp_driver = {
 
 static struct platform_device *coretemp_device_add(unsigned int cpu)
 {
-   int err, pkgid = topology_logical_package_id(cpu);
+   int err, pkgid = topology_logical_die_id(cpu);
struct platform_device *pdev;
 
if (pkgid < 0)
@@ -703,7 +703,7 @@ static int coretemp_cpu_offline(unsigned int cpu)
 * the rest.
 */
if (cpumask_empty(>cpumask)) {
-   pkg_devices[topology_logical_package_id(cpu)] = NULL;
+   pkg_devices[topology_logical_die_id(cpu)] = NULL;
platform_device_unregister(pdev);
return 0;
}
@@ -732,6 +732,7 @@ static enum cpuhp_state coretemp_hp_online;
 static int __init coretemp_init(void)
 {
int err;
+   struct cpuinfo_x86 *c = _data(0);
 
/*
 * CPUID.06H.EAX[0] indicates whether the CPU has thermal
@@ -741,7 +742,7 @@ static int __init coretemp_init(void)
if (!x86_match_cpu(coretemp_ids))
return -ENODEV;
 
-   max_packages = topology_max_packages();
+   max_packages = topology_max_packages() * topology_max_die_per_package();
pkg_devices = kcalloc(max_packages, sizeof(struct platform_device *),
  GFP_KERNEL);
if (!pkg_devices)
-- 
2.18.0-rc0



[PATCH 15/18] topology: Create core_cpus and die_cpus sysfs attributes

2019-04-30 Thread Len Brown
From: Len Brown 

Create CPU topology sysfs attributes: "core_cpus" and "core_cpus_list"

These attributes represent all of the logical CPUs that share the
same core.

These attriutes is synonymous with the existing "thread_siblings" and
"thread_siblings_list" attribute, which will be deprecated.

Create CPU topology sysfs attributes: "die_cpus" and "die_cpus_list".
These attributes represent all of the logical CPUs that share the
same die.

Signed-off-by: Len Brown 
Suggested-by: Brice Goglin 
---
 Documentation/cputopology.txt   | 21 +++--
 arch/x86/include/asm/smp.h  |  1 +
 arch/x86/include/asm/topology.h |  1 +
 arch/x86/kernel/smpboot.c   | 22 ++
 arch/x86/xen/smp_pv.c   |  1 +
 drivers/base/topology.c | 12 
 include/linux/topology.h|  3 +++
 7 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/Documentation/cputopology.txt b/Documentation/cputopology.txt
index 48af5c290e20..b90dafcc8237 100644
--- a/Documentation/cputopology.txt
+++ b/Documentation/cputopology.txt
@@ -36,15 +36,15 @@ drawer_id:
identifier (rather than the kernel's).  The actual value is
architecture and platform dependent.
 
-thread_siblings:
+core_cpus:
 
-   internal kernel map of cpuX's hardware threads within the same
-   core as cpuX.
+   internal kernel map of CPUs within the same core.
+   (deprecated name: "thread_siblings")
 
-thread_siblings_list:
+core_cpus_list:
 
-   human-readable list of cpuX's hardware threads within the same
-   core as cpuX.
+   human-readable list of CPUs within the same core.
+   (deprecated name: "thread_siblings_list");
 
 package_cpus:
 
@@ -56,6 +56,14 @@ package_cpus_list:
human-readable list of CPUs sharing the same physical_package_id.
(deprecated name: "core_siblings_list")
 
+die_cpus:
+
+   internal kernel map of CPUs within the same die.
+
+die_cpus_list:
+
+   human-readable list of CPUs within the same die.
+
 book_siblings:
 
internal kernel map of cpuX's hardware threads within the same
@@ -93,6 +101,7 @@ these macros in include/asm-XXX/topology.h::
#define topology_drawer_id(cpu)
#define topology_sibling_cpumask(cpu)
#define topology_core_cpumask(cpu)
+   #define topology_die_cpumask(cpu)
#define topology_book_cpumask(cpu)
#define topology_drawer_cpumask(cpu)
 
diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
index 2e95b6c1bca3..39266d193597 100644
--- a/arch/x86/include/asm/smp.h
+++ b/arch/x86/include/asm/smp.h
@@ -23,6 +23,7 @@ extern unsigned int num_processors;
 
 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map);
 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
+DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_die_map);
 /* cpus sharing the last level cache: */
 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h
index 9de16b4f6023..4b14d2318251 100644
--- a/arch/x86/include/asm/topology.h
+++ b/arch/x86/include/asm/topology.h
@@ -111,6 +111,7 @@ extern const struct cpumask *cpu_coregroup_mask(int cpu);
 #define topology_core_id(cpu)  (cpu_data(cpu).cpu_core_id)
 
 #ifdef CONFIG_SMP
+#define topology_die_cpumask(cpu)  (per_cpu(cpu_die_map, cpu))
 #define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu))
 #define topology_sibling_cpumask(cpu)  (per_cpu(cpu_sibling_map, cpu))
 
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index a114375e14f7..48a671443266 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -91,6 +91,10 @@ EXPORT_PER_CPU_SYMBOL(cpu_sibling_map);
 DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
 EXPORT_PER_CPU_SYMBOL(cpu_core_map);
 
+/* representing HT, core, and die siblings of each logical CPU */
+DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_die_map);
+EXPORT_PER_CPU_SYMBOL(cpu_die_map);
+
 DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
 
 /* Per CPU bogomips and other parameters */
@@ -509,6 +513,15 @@ static bool match_pkg(struct cpuinfo_x86 *c, struct 
cpuinfo_x86 *o)
return false;
 }
 
+static bool match_die(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)
+{
+   if ((c->phys_proc_id == o->phys_proc_id) &&
+   (c->cpu_die_id == o->cpu_die_id))
+   return true;
+   return false;
+}
+
+
 #if defined(CONFIG_SCHED_SMT) || defined(CONFIG_SCHED_MC)
 static inline int x86_sched_itmt_flags(void)
 {
@@ -571,6 +584,7 @@ void set_cpu_sibling_map(int cpu)
cpumask_set_cpu(cpu, topology_sibling_cpumask(cpu));
cpumask_set_cpu(cpu, cpu_llc_shared_mask(cpu));
cpumask_set_cpu(cpu, topology_core_cpumask(cpu));
+   cpumask_set_cpu(cpu, topology_die_cpumask(cpu));

[PATCH 08/18] x86 topology: Define topology_logical_die_id()

2019-04-30 Thread Len Brown
From: Len Brown 

Define topology_logical_die_id() ala
existing topology_logical_package_id()

Tested-by: Zhang Rui 
Signed-off-by: Len Brown 
---
 arch/x86/include/asm/processor.h |  1 +
 arch/x86/include/asm/topology.h  |  5 
 arch/x86/kernel/cpu/common.c |  1 +
 arch/x86/kernel/smpboot.c| 45 
 4 files changed, 52 insertions(+)

diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 5f45488b1a9d..def963d0b805 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -118,6 +118,7 @@ struct cpuinfo_x86 {
/* Core id: */
u16 cpu_core_id;
u16 cpu_die_id;
+   u16 logical_die_id;
/* Index into per_cpu list: */
u16 cpu_index;
u32 microcode;
diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h
index 3777dbe9c0ff..9de16b4f6023 100644
--- a/arch/x86/include/asm/topology.h
+++ b/arch/x86/include/asm/topology.h
@@ -106,6 +106,7 @@ extern const struct cpumask *cpu_coregroup_mask(int cpu);
 
 #define topology_logical_package_id(cpu)   (cpu_data(cpu).logical_proc_id)
 #define topology_physical_package_id(cpu)  (cpu_data(cpu).phys_proc_id)
+#define topology_logical_die_id(cpu)   (cpu_data(cpu).logical_die_id)
 #define topology_die_id(cpu)   (cpu_data(cpu).cpu_die_id)
 #define topology_core_id(cpu)  (cpu_data(cpu).cpu_core_id)
 
@@ -131,13 +132,17 @@ static inline int topology_max_smt_threads(void)
 }
 
 int topology_update_package_map(unsigned int apicid, unsigned int cpu);
+int topology_update_die_map(unsigned int dieid, unsigned int cpu);
 int topology_phys_to_logical_pkg(unsigned int pkg);
+int topology_phys_to_logical_die(unsigned int die, unsigned int cpu);
 bool topology_is_primary_thread(unsigned int cpu);
 bool topology_smt_supported(void);
 #else
 #define topology_max_packages()(1)
 static inline int
 topology_update_package_map(unsigned int apicid, unsigned int cpu) { return 0; 
}
+static inline int
+topology_update_die_map(unsigned int dieid, unsigned int cpu) { return 0; }
 static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return 0; }
 static inline int topology_phys_to_logical_die(unsigned int die,
unsigned int cpu) { return 0; }
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index cb28e98a0659..24f96c9771af 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1285,6 +1285,7 @@ static void validate_apic_and_package_id(struct 
cpuinfo_x86 *c)
   cpu, apicid, c->initial_apicid);
}
BUG_ON(topology_update_package_map(c->phys_proc_id, cpu));
+   BUG_ON(topology_update_die_map(c->cpu_die_id, cpu));
 #else
c->logical_proc_id = 0;
 #endif
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 05f9cfdddffd..a114375e14f7 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -101,6 +101,7 @@ EXPORT_PER_CPU_SYMBOL(cpu_info);
 unsigned int __max_logical_packages __read_mostly;
 EXPORT_SYMBOL(__max_logical_packages);
 static unsigned int logical_packages __read_mostly;
+static unsigned int logical_die __read_mostly;
 
 /* Maximum number of SMT threads on any online core */
 int __read_mostly __max_smt_threads = 1;
@@ -302,6 +303,26 @@ int topology_phys_to_logical_pkg(unsigned int phys_pkg)
return -1;
 }
 EXPORT_SYMBOL(topology_phys_to_logical_pkg);
+/**
+ * topology_phys_to_logical_die - Map a physical die id to logical
+ *
+ * Returns logical die id or -1 if not found
+ */
+int topology_phys_to_logical_die(unsigned int die_id, unsigned int cur_cpu)
+{
+   int cpu;
+   int proc_id = cpu_data(cur_cpu).phys_proc_id;
+
+   for_each_possible_cpu(cpu) {
+   struct cpuinfo_x86 *c = _data(cpu);
+
+   if (c->initialized && c->cpu_die_id == die_id &&
+   c->phys_proc_id == proc_id)
+   return c->logical_die_id;
+   }
+   return -1;
+}
+EXPORT_SYMBOL(topology_phys_to_logical_die);
 
 /**
  * topology_update_package_map - Update the physical to logical package map
@@ -326,6 +347,29 @@ int topology_update_package_map(unsigned int pkg, unsigned 
int cpu)
cpu_data(cpu).logical_proc_id = new;
return 0;
 }
+/**
+ * topology_update_die_map - Update the physical to logical die map
+ * @die:   The die id as retrieved via CPUID
+ * @cpu:   The cpu for which this is updated
+ */
+int topology_update_die_map(unsigned int die, unsigned int cpu)
+{
+   int new;
+
+   /* Already available somewhere? */
+   new = topology_phys_to_logical_die(die, cpu);
+   if (new >= 0)
+   goto found;
+
+   new = logical_die++;
+   if (new != die) {
+   pr_info("CPU %u Converting 

[PATCH 16/18] perf/x86/intel/uncore: Support multi-die/package

2019-04-30 Thread Len Brown
From: Kan Liang 

Uncore becomes die-scope on Xeon Cascade Lake-AP. Uncore driver needs to
support die-scope uncore units.

Use topology_logical_die_id() to replace topology_logical_package_id().
For previous platforms which doesn't have multi-die,
topology_logical_die_id() is identical as topology_logical_package_id().

In pci_probe/remove, the group id reads from PCI BUS is logical die id
for multi-die systems.

Use topology_die_cpumask() to replace topology_core_cpumask().
For previous platforms which doesn't have multi-die,
topology_die_cpumask() is identical as topology_core_cpumask().

There is no functional change for previous platforms.

Signed-off-by: Kan Liang 
Cc: Peter Zijlstra 
Signed-off-by: Len Brown 
---
 arch/x86/events/intel/uncore.c | 20 +++-
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c
index 9fe64c01a2e5..a6461ff85a32 100644
--- a/arch/x86/events/intel/uncore.c
+++ b/arch/x86/events/intel/uncore.c
@@ -100,7 +100,7 @@ ssize_t uncore_event_show(struct kobject *kobj,
 
 struct intel_uncore_box *uncore_pmu_to_box(struct intel_uncore_pmu *pmu, int 
cpu)
 {
-   unsigned int pkgid = topology_logical_package_id(cpu);
+   unsigned int pkgid = topology_logical_die_id(cpu);
 
/*
 * The unsigned check also catches the '-1' return value for non
@@ -942,7 +942,8 @@ static int uncore_pci_probe(struct pci_dev *pdev, const 
struct pci_device_id *id
if (phys_id < 0)
return -ENODEV;
 
-   pkg = topology_phys_to_logical_pkg(phys_id);
+   pkg = (topology_max_die_per_package() > 1) ? phys_id :
+   topology_phys_to_logical_pkg(phys_id);
if (pkg < 0)
return -EINVAL;
 
@@ -1033,7 +1034,8 @@ static void uncore_pci_remove(struct pci_dev *pdev)
 
box = pci_get_drvdata(pdev);
if (!box) {
-   pkg = topology_phys_to_logical_pkg(phys_id);
+   pkg = (topology_max_die_per_package() > 1) ? phys_id :
+   topology_phys_to_logical_pkg(phys_id);
for (i = 0; i < UNCORE_EXTRA_PCI_DEV_MAX; i++) {
if (uncore_extra_pci_dev[pkg].dev[i] == pdev) {
uncore_extra_pci_dev[pkg].dev[i] = NULL;
@@ -1110,7 +1112,7 @@ static void uncore_change_type_ctx(struct 
intel_uncore_type *type, int old_cpu,
struct intel_uncore_box *box;
int i, pkg;
 
-   pkg = topology_logical_package_id(old_cpu < 0 ? new_cpu : old_cpu);
+   pkg = topology_logical_die_id(old_cpu < 0 ? new_cpu : old_cpu);
for (i = 0; i < type->num_boxes; i++, pmu++) {
box = pmu->boxes[pkg];
if (!box)
@@ -1151,7 +1153,7 @@ static int uncore_event_cpu_offline(unsigned int cpu)
if (!cpumask_test_and_clear_cpu(cpu, _cpu_mask))
goto unref;
/* Find a new cpu to collect uncore events */
-   target = cpumask_any_but(topology_core_cpumask(cpu), cpu);
+   target = cpumask_any_but(topology_die_cpumask(cpu), cpu);
 
/* Migrate uncore events to the new target */
if (target < nr_cpu_ids)
@@ -1164,7 +1166,7 @@ static int uncore_event_cpu_offline(unsigned int cpu)
 
 unref:
/* Clear the references */
-   pkg = topology_logical_package_id(cpu);
+   pkg = topology_logical_die_id(cpu);
for (; *types; types++) {
type = *types;
pmu = type->pmus;
@@ -1223,7 +1225,7 @@ static int uncore_event_cpu_online(unsigned int cpu)
struct intel_uncore_box *box;
int i, ret, pkg, target;
 
-   pkg = topology_logical_package_id(cpu);
+   pkg = topology_logical_die_id(cpu);
ret = allocate_boxes(types, pkg, cpu);
if (ret)
return ret;
@@ -1242,7 +1244,7 @@ static int uncore_event_cpu_online(unsigned int cpu)
 * Check if there is an online cpu in the package
 * which collects uncore events already.
 */
-   target = cpumask_any_and(_cpu_mask, topology_core_cpumask(cpu));
+   target = cpumask_any_and(_cpu_mask, topology_die_cpumask(cpu));
if (target < nr_cpu_ids)
return 0;
 
@@ -1411,7 +1413,7 @@ static int __init intel_uncore_init(void)
if (boot_cpu_has(X86_FEATURE_HYPERVISOR))
return -ENODEV;
 
-   max_packages = topology_max_packages();
+   max_packages = topology_max_packages() * topology_max_die_per_package();
 
uncore_init = (struct intel_uncore_init_fun *)id->driver_data;
if (uncore_init->pci_init) {
-- 
2.18.0-rc0



[PATCH 10/18] powercap/intel_rapl: Support multi-die/package

2019-04-30 Thread Len Brown
From: Zhang Rui 

RAPL "package" domains are actually implemented in hardware per-die.
Thus, the new multi-die/package systems have mulitple domains
within each physical package.

Update the intel_rapl driver to be "die aware" -- exporting multiple
domains within a single package, when present.
No change on single die/package systems.

Signed-off-by: Zhang Rui 
Signed-off-by: Len Brown 
Acked-by: Rafael J. Wysocki 
Cc: linux...@vger.kernel.org
---
 drivers/powercap/intel_rapl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c
index 3c3c0c23180b..9202dbcef96d 100644
--- a/drivers/powercap/intel_rapl.c
+++ b/drivers/powercap/intel_rapl.c
@@ -266,7 +266,7 @@ static struct rapl_domain *platform_rapl_domain; /* 
Platform (PSys) domain */
 /* caller to ensure CPU hotplug lock is held */
 static struct rapl_package *rapl_find_package_domain(int cpu)
 {
-   int id = topology_physical_package_id(cpu);
+   int id = topology_logical_die_id(cpu);
struct rapl_package *rp;
 
list_for_each_entry(rp, _packages, plist) {
@@ -1459,7 +1459,7 @@ static void rapl_remove_package(struct rapl_package *rp)
 /* called from CPU hotplug notifier, hotplug lock held */
 static struct rapl_package *rapl_add_package(int cpu)
 {
-   int id = topology_physical_package_id(cpu);
+   int id = topology_logical_die_id(cpu);
struct rapl_package *rp;
int ret;
 
-- 
2.18.0-rc0



[PATCH 11/18] thermal/x86_pkg_temp_thermal: Support multi-die/package

2019-04-30 Thread Len Brown
From: Zhang Rui 

Package temperature sensors are actually implemented in hardware per-die.
Thus, the new multi-die/package systems sport mulitple package thermal
zones for each package.

Update the x86_pkg_temp_thermal to be "multi-die-aware", so it can
expose multiple zones per package, instead of just one.

Signed-off-by: Zhang Rui 
Signed-off-by: Len Brown 
---
 drivers/thermal/intel/x86_pkg_temp_thermal.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/thermal/intel/x86_pkg_temp_thermal.c 
b/drivers/thermal/intel/x86_pkg_temp_thermal.c
index 1ef937d799e4..405b3858900a 100644
--- a/drivers/thermal/intel/x86_pkg_temp_thermal.c
+++ b/drivers/thermal/intel/x86_pkg_temp_thermal.c
@@ -122,7 +122,7 @@ static int pkg_temp_debugfs_init(void)
  */
 static struct pkg_device *pkg_temp_thermal_get_dev(unsigned int cpu)
 {
-   int pkgid = topology_logical_package_id(cpu);
+   int pkgid = topology_logical_die_id(cpu);
 
if (pkgid >= 0 && pkgid < max_packages)
return packages[pkgid];
@@ -353,7 +353,7 @@ static int pkg_thermal_notify(u64 msr_val)
 
 static int pkg_temp_thermal_device_add(unsigned int cpu)
 {
-   int pkgid = topology_logical_package_id(cpu);
+   int pkgid = topology_logical_die_id(cpu);
u32 tj_max, eax, ebx, ecx, edx;
struct pkg_device *pkgdev;
int thres_count, err;
@@ -449,7 +449,7 @@ static int pkg_thermal_cpu_offline(unsigned int cpu)
 * worker will see the package anymore.
 */
if (lastcpu) {
-   packages[topology_logical_package_id(cpu)] = NULL;
+   packages[topology_logical_die_id(cpu)] = NULL;
/* After this point nothing touches the MSR anymore. */
wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT,
  pkgdev->msr_pkg_therm_low, pkgdev->msr_pkg_therm_high);
@@ -515,7 +515,7 @@ static int __init pkg_temp_thermal_init(void)
if (!x86_match_cpu(pkg_temp_thermal_ids))
return -ENODEV;
 
-   max_packages = topology_max_packages();
+   max_packages = topology_max_packages() * topology_max_die_per_package();
packages = kcalloc(max_packages, sizeof(struct pkg_device *),
   GFP_KERNEL);
if (!packages)
-- 
2.18.0-rc0



[PATCH 18/18] perf/x86/intel/cstate: Support multi-die/package

2019-04-30 Thread Len Brown
From: Kan Liang 

Some cstate counters becomes die-scope on Xeon Cascade Lake-AP. Perf
cstate driver needs to support die-scope cstate counters.

Use topology_die_cpumask() to replace topology_core_cpumask().
For previous platforms which doesn't have multi-die,
topology_die_cpumask() is identical as topology_core_cpumask().
There is no functional change for previous platforms.

Name the die-scope PMU "cstate_die".

Signed-off-by: Kan Liang 
Cc: Peter Zijlstra 
Signed-off-by: Len Brown 
---
 arch/x86/events/intel/cstate.c | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/arch/x86/events/intel/cstate.c b/arch/x86/events/intel/cstate.c
index 94a4b7fc75d0..52c5fea29457 100644
--- a/arch/x86/events/intel/cstate.c
+++ b/arch/x86/events/intel/cstate.c
@@ -302,7 +302,7 @@ static int cstate_pmu_event_init(struct perf_event *event)
return -EINVAL;
event->hw.event_base = pkg_msr[cfg].msr;
cpu = cpumask_any_and(_pkg_cpu_mask,
- topology_core_cpumask(event->cpu));
+ topology_die_cpumask(event->cpu));
} else {
return -ENOENT;
}
@@ -385,7 +385,7 @@ static int cstate_cpu_exit(unsigned int cpu)
if (has_cstate_pkg &&
cpumask_test_and_clear_cpu(cpu, _pkg_cpu_mask)) {
 
-   target = cpumask_any_but(topology_core_cpumask(cpu), cpu);
+   target = cpumask_any_but(topology_die_cpumask(cpu), cpu);
/* Migrate events if there is a valid target */
if (target < nr_cpu_ids) {
cpumask_set_cpu(target, _pkg_cpu_mask);
@@ -414,7 +414,7 @@ static int cstate_cpu_init(unsigned int cpu)
 * in the package cpu mask as the designated reader.
 */
target = cpumask_any_and(_pkg_cpu_mask,
-topology_core_cpumask(cpu));
+topology_die_cpumask(cpu));
if (has_cstate_pkg && target >= nr_cpu_ids)
cpumask_set_cpu(cpu, _pkg_cpu_mask);
 
@@ -661,7 +661,13 @@ static int __init cstate_init(void)
}
 
if (has_cstate_pkg) {
-   err = perf_pmu_register(_pkg_pmu, cstate_pkg_pmu.name, 
-1);
+   if (topology_max_die_per_package() > 1) {
+   err = perf_pmu_register(_pkg_pmu,
+   "cstate_die", -1);
+   } else {
+   err = perf_pmu_register(_pkg_pmu,
+   cstate_pkg_pmu.name, -1);
+   }
if (err) {
has_cstate_pkg = false;
pr_info("Failed to register cstate pkg pmu\n");
-- 
2.18.0-rc0



[PATCH 0/18] v4 multi-die/package topology support

2019-04-30 Thread Len Brown


This patch series does 4 things.

1. Parse the new CPUID.1F leaf to discover multi-die/package topology

2. Export multi-die topology inside the kernel

3. Update 4 places (coretemp, pkgtemp, rapl, perf) that that need to know
   the difference between die and package-scope MSR.

4. Export multi-die topology to user-space via sysfs

These changes should have 0 impact on cache topology,
NUMA topology, Linux scheduler, or system performance.

These topology changes primarily impact parts of the kernel
and some applications that care about package MSR scope.
Also, some software is licensed per package, and other tools,
such as benchmark reporting software sometimes cares about packages.

---
Updates since v3:

None!

Earlier today I sent the correct v3 e-mail header, pointing to the
correct git branch, but ran git-send-email from the wrong directory
and it happily spammed you with a copy of the old 14-patch v1 series.
Sorry about that!

---
Updates since v2:

All review feedback has been addressed.

In response to brice, peterz and Morten Rasmussen,
used the word "cpu" rather than "thread" for the new sysfs attributes.

In response to tglx, replaced access to cpuinfo_x86.x86_max_dies,
with macro topology_max_die_per_package().  In doing so,
deleted this new per-cpu field entirely, as a global is sufficient.

Also, appended 3 patches from Kan Liang, updating the perf code
to be multi-die aware.  These patches are similar to the preceding
power and temperature patches.  I believe that with these patches,
this series now includes all needed multi-die kernel support.

---
The following changes since commit 085b7755808aa11f78ab9377257e1dad2e6fa4bb:

  Linux 5.1-rc6 (2019-04-21 10:45:57 -0700)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux.git x86

for you to fetch changes up to 6c4891c7f2f1eacfcab00bf5d84b5ac119f654b9:

  perf/x86/intel/cstate: Support multi-die/package (2019-04-30 16:49:26 -0400)


Kan Liang (3):
  perf/x86/intel/uncore: Support multi-die/package
  perf/x86/intel/rapl: Support multi-die/package
  perf/x86/intel/cstate: Support multi-die/package

Len Brown (10):
  x86 topology: Fix doc typo
  topology: Simplify cputopology.txt formatting and wording
  x86 smpboot: Rename match_die() to match_pkg()
  x86 topology: Add CPUID.1F multi-die/package support
  x86 topology: Create topology_max_die_per_package()
  cpu topology: Export die_id
  x86 topology: Define topology_die_id()
  x86 topology: Define topology_logical_die_id()
  topology: Create package_cpus sysfs attribute
  topology: Create core_cpus and die_cpus sysfs attributes

Zhang Rui (5):
  powercap/intel_rapl: Simplify rapl_find_package()
  powercap/intel_rapl: Support multi-die/package
  thermal/x86_pkg_temp_thermal: Support multi-die/package
  powercap/intel_rapl: update rapl domain name and debug messages
  hwmon/coretemp: Support multi-die/package

 Documentation/cputopology.txt| 80 +++--
 Documentation/x86/topology.txt   |  6 +-
 arch/x86/events/intel/cstate.c   | 14 +++--
 arch/x86/events/intel/rapl.c | 10 ++--
 arch/x86/events/intel/uncore.c   | 20 ---
 arch/x86/include/asm/processor.h |  4 +-
 arch/x86/include/asm/smp.h   |  1 +
 arch/x86/include/asm/topology.h  | 17 ++
 arch/x86/kernel/cpu/common.c |  1 +
 arch/x86/kernel/cpu/topology.c   | 88 ++--
 arch/x86/kernel/smpboot.c| 75 +++-
 arch/x86/xen/smp_pv.c|  1 +
 drivers/base/topology.c  | 22 +++
 drivers/hwmon/coretemp.c |  9 +--
 drivers/powercap/intel_rapl.c| 75 +---
 drivers/thermal/intel/x86_pkg_temp_thermal.c |  8 +--
 include/linux/topology.h |  6 ++
 17 files changed, 322 insertions(+), 115 deletions(-)



[PATCH 01/18] x86 topology: Fix doc typo

2019-04-30 Thread Len Brown
From: Len Brown 

Syntax only, no functional or semantic change.

reflect actual cpuinfo_x86 field name:

s/logical_id/logical_proc_id/

Signed-off-by: Len Brown 
Cc: linux-...@vger.kernel.org
---
 Documentation/x86/topology.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/x86/topology.txt b/Documentation/x86/topology.txt
index 2953e3ec9a02..06b3cdbc4048 100644
--- a/Documentation/x86/topology.txt
+++ b/Documentation/x86/topology.txt
@@ -51,7 +51,7 @@ The topology of a system is described in the units of:
 The physical ID of the package. This information is retrieved via CPUID
 and deduced from the APIC IDs of the cores in the package.
 
-  - cpuinfo_x86.logical_id:
+  - cpuinfo_x86.logical_proc_id:
 
 The logical ID of the package. As we do not trust BIOSes to enumerate the
 packages in a consistent way, we introduced the concept of logical package
-- 
2.18.0-rc0



[PATCH 04/18] x86 topology: Add CPUID.1F multi-die/package support

2019-04-30 Thread Len Brown
From: Len Brown 

Some new systems have multiple software-visible die within each package.

Update Linux parsing of the Intel CPUID "Extended Topology Leaf"
to handle either CPUID.B, or the new CPUID.1F.

Add cpuinfo_x86.die_id and cpuinfo_x86.max_dies to store the result.

die_id will be non-zero only for multi-die/package systems.

Signed-off-by: Len Brown 
Cc: linux-...@vger.kernel.org
---
 Documentation/x86/topology.txt   |  4 ++
 arch/x86/include/asm/processor.h |  4 +-
 arch/x86/kernel/cpu/topology.c   | 85 +---
 arch/x86/kernel/smpboot.c|  2 +
 4 files changed, 75 insertions(+), 20 deletions(-)

diff --git a/Documentation/x86/topology.txt b/Documentation/x86/topology.txt
index 06b3cdbc4048..8107b6cfc9ea 100644
--- a/Documentation/x86/topology.txt
+++ b/Documentation/x86/topology.txt
@@ -46,6 +46,10 @@ The topology of a system is described in the units of:
 
 The number of cores in a package. This information is retrieved via CPUID.
 
+  - cpuinfo_x86.x86_max_dies:
+
+The number of dies in a package. This information is retrieved via CPUID.
+
   - cpuinfo_x86.phys_proc_id:
 
 The physical ID of the package. This information is retrieved via CPUID
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 2bb3a648fc12..2507edc30cc2 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -105,7 +105,8 @@ struct cpuinfo_x86 {
int x86_power;
unsigned long   loops_per_jiffy;
/* cpuid returned max cores value: */
-   u16  x86_max_cores;
+   u16 x86_max_cores;
+   u16 x86_max_dies;
u16 apicid;
u16 initial_apicid;
u16 x86_clflush_size;
@@ -117,6 +118,7 @@ struct cpuinfo_x86 {
u16 logical_proc_id;
/* Core id: */
u16 cpu_core_id;
+   u16 cpu_die_id;
/* Index into per_cpu list: */
u16 cpu_index;
u32 microcode;
diff --git a/arch/x86/kernel/cpu/topology.c b/arch/x86/kernel/cpu/topology.c
index 8f6c784141d1..4d17e699657d 100644
--- a/arch/x86/kernel/cpu/topology.c
+++ b/arch/x86/kernel/cpu/topology.c
@@ -15,33 +15,63 @@
 /* leaf 0xb SMT level */
 #define SMT_LEVEL  0
 
-/* leaf 0xb sub-leaf types */
+/* extended topology sub-leaf types */
 #define INVALID_TYPE   0
 #define SMT_TYPE   1
 #define CORE_TYPE  2
+#define DIE_TYPE   5
 
 #define LEAFB_SUBTYPE(ecx) (((ecx) >> 8) & 0xff)
 #define BITS_SHIFT_NEXT_LEVEL(eax) ((eax) & 0x1f)
 #define LEVEL_MAX_SIBLINGS(ebx)((ebx) & 0x)
 
-int detect_extended_topology_early(struct cpuinfo_x86 *c)
-{
 #ifdef CONFIG_SMP
+/*
+ * Check if given CPUID extended toplogy "leaf" is implemented
+ */
+static int check_extended_topology_leaf(int leaf)
+{
unsigned int eax, ebx, ecx, edx;
 
-   if (c->cpuid_level < 0xb)
+   cpuid_count(leaf, SMT_LEVEL, , , , );
+
+   if (ebx == 0 || (LEAFB_SUBTYPE(ecx) != SMT_TYPE))
return -1;
 
-   cpuid_count(0xb, SMT_LEVEL, , , , );
+   return 0;
+}
+/*
+ * Return best CPUID Extended Toplogy Leaf supported
+ */
+static int detect_extended_topology_leaf(struct cpuinfo_x86 *c)
+{
+   if (c->cpuid_level >= 0x1f) {
+   if (check_extended_topology_leaf(0x1f) == 0)
+   return 0x1f;
+   }
 
-   /*
-* check if the cpuid leaf 0xb is actually implemented.
-*/
-   if (ebx == 0 || (LEAFB_SUBTYPE(ecx) != SMT_TYPE))
+   if (c->cpuid_level >= 0xb) {
+   if (check_extended_topology_leaf(0xb) == 0)
+   return 0xb;
+   }
+
+   return -1;
+}
+#endif
+
+int detect_extended_topology_early(struct cpuinfo_x86 *c)
+{
+#ifdef CONFIG_SMP
+   unsigned int eax, ebx, ecx, edx;
+   int leaf;
+
+   leaf = detect_extended_topology_leaf(c);
+   if (leaf < 0)
return -1;
 
set_cpu_cap(c, X86_FEATURE_XTOPOLOGY);
 
+   cpuid_count(leaf, SMT_LEVEL, , , , );
/*
 * initial apic id, which also represents 32-bit extended x2apic id.
 */
@@ -52,7 +82,7 @@ int detect_extended_topology_early(struct cpuinfo_x86 *c)
 }
 
 /*
- * Check for extended topology enumeration cpuid leaf 0xb and if it
+ * Check for extended topology enumeration cpuid leaf, and if it
  * exists, use it for populating initial_apicid and cpu topology
  * detection.
  */
@@ -60,22 +90,28 @@ int detect_extended_topology(struct cpuinfo_x86 *c)
 {
 #ifdef CONFIG_SMP
unsigned int eax, ebx, ecx, edx, sub_index;
-   unsigned int ht_mask_width, core_plus_mask_width;
+   unsigned int ht_mask_width, core_plus_mask_width, die_plus_mask_width;
unsigned int core_select_mask, 

[PATCH 14/18] topology: Create package_cpus sysfs attribute

2019-04-30 Thread Len Brown
From: Len Brown 

The existing sysfs cpu/topology/core_siblings (and core_siblings_list)
attributes are documented, implemented, and used by programs to
represent set of logical CPUs sharing the same package.

This makes sense if the next topology level above a core
is always a package.  But on systems where there is a die
topology level between a core and a package, the name
and its definition become inconsistent.

So without changing its function, add a name for this map
that describes what it actually is -- package CPUs --
the set of CPUs that share the same package.

This new name will be immune to changes in topology, since
it describes threads at the current level, not siblings
at a contained level.

Signed-off-by: Len Brown 
Suggested-by: Brice Goglin 
---
 Documentation/cputopology.txt | 12 ++--
 drivers/base/topology.c   |  6 ++
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/Documentation/cputopology.txt b/Documentation/cputopology.txt
index 2ff8a1e9a2db..48af5c290e20 100644
--- a/Documentation/cputopology.txt
+++ b/Documentation/cputopology.txt
@@ -46,15 +46,15 @@ thread_siblings_list:
human-readable list of cpuX's hardware threads within the same
core as cpuX.
 
-core_siblings:
+package_cpus:
 
-   internal kernel map of cpuX's hardware threads within the same
-   physical_package_id.
+   internal kernel map of the CPUs sharing the same physical_package_id.
+   (deprecated name: "core_siblings")
 
-core_siblings_list:
+package_cpus_list:
 
-   human-readable list of cpuX's hardware threads within the same
-   physical_package_id.
+   human-readable list of CPUs sharing the same physical_package_id.
+   (deprecated name: "core_siblings_list")
 
 book_siblings:
 
diff --git a/drivers/base/topology.c b/drivers/base/topology.c
index 50352cf96f85..dc3c19b482f3 100644
--- a/drivers/base/topology.c
+++ b/drivers/base/topology.c
@@ -57,6 +57,10 @@ define_siblings_show_func(core_siblings, core_cpumask);
 static DEVICE_ATTR_RO(core_siblings);
 static DEVICE_ATTR_RO(core_siblings_list);
 
+define_siblings_show_func(package_cpus, core_cpumask);
+static DEVICE_ATTR_RO(package_cpus);
+static DEVICE_ATTR_RO(package_cpus_list);
+
 #ifdef CONFIG_SCHED_BOOK
 define_id_show_func(book_id);
 static DEVICE_ATTR_RO(book_id);
@@ -81,6 +85,8 @@ static struct attribute *default_attrs[] = {
_attr_thread_siblings_list.attr,
_attr_core_siblings.attr,
_attr_core_siblings_list.attr,
+   _attr_package_cpus.attr,
+   _attr_package_cpus_list.attr,
 #ifdef CONFIG_SCHED_BOOK
_attr_book_id.attr,
_attr_book_siblings.attr,
-- 
2.18.0-rc0



[PATCH V2] drivers: core: Remove glue dirs early only when refcount is 1

2019-04-30 Thread Prateek Sood
While loading firmware blobs parallely in different threads, it is possible
to free sysfs node of glue_dirs in device_del() from a thread while another
thread is trying to add subdir from device_add() in glue_dirs sysfs node.

CPU1   CPU2
fw_load_sysfs_fallback()
  device_add()
get_device_parent()
  class_dir_create_and_add()
kobject_add_internal()
  create_dir() // glue_dir

   fw_load_sysfs_fallback()
 device_add()
   get_device_parent()
 kobject_get() //glue_dir

  device_del()
cleanup_glue_dir()
  kobject_del()

   kobject_add()
 kobject_add_internal()
   create_dir() // in glue_dir
 kernfs_create_dir_ns()

   sysfs_remove_dir() //glue_dir->sd=NULL
   sysfs_put() // free glue_dir->sd

   kernfs_new_node()
 kernfs_get(glue_dir)

Fix this race by making sure that kernfs_node for glue_dir is released only
when refcount for glue_dir kobj is 1.

Signed-off-by: Prateek Sood 
---
 drivers/base/core.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 4aeaa0c..3955d07 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -1820,12 +1820,15 @@ static inline struct kobject *get_glue_dir(struct 
device *dev)
  */
 static void cleanup_glue_dir(struct device *dev, struct kobject *glue_dir)
 {
+   unsigned int refcount;
+
/* see if we live in a "glue" directory */
if (!live_in_glue_dir(glue_dir, dev))
return;
 
mutex_lock(_mutex);
-   if (!kobject_has_children(glue_dir))
+   refcount = kref_read(_dir->kref);
+   if (!kobject_has_children(glue_dir) && !--refcount)
kobject_del(glue_dir);
kobject_put(glue_dir);
mutex_unlock(_mutex);
-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc., 
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



Re: [PATCH v5 2/3] power: supply: Add driver for Microchip UCS1002

2019-04-30 Thread Andrey Smirnov
On Tue, Apr 30, 2019 at 8:43 PM Randy Dunlap  wrote:
>
> Hi,
>
> On 4/30/19 8:34 PM, Andrey Smirnov wrote:
> > diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
> > index e901b9879e7e..c614c8a196f3 100644
> > --- a/drivers/power/supply/Kconfig
> > +++ b/drivers/power/supply/Kconfig
> > @@ -660,4 +660,13 @@ config FUEL_GAUGE_SC27XX
> >Say Y here to enable support for fuel gauge with SC27XX
> >PMIC chips.
> >
> > +config CHARGER_UCS1002
> > +tristate "Microchip UCS1002 USB Port Power Controller"
>
> Please indent the tristate line with a tab instead of spaces.
>

OK, will do.

Thanks,
Andrey Smirnov


Re: [tip:x86/mm 14/35] kernel/trace/bpf_trace.c:179:16: error: implicit declaration of function 'nmi_uaccess_okay'; did you mean '__access_ok'?

2019-04-30 Thread Nadav Amit
> On Apr 30, 2019, at 5:13 PM, kbuild test robot  wrote:
> 
> tree:   
> https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftip%2Ftip.gitdata=02%7C01%7Cnamit%40vmware.com%7C8a380b9453f249fd924a08d6cdc9e8cd%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636922664483201432sdata=NWhVtiLZ4l7LvLKsNNDrR4A8PlpXIeH1tErfFz6EmcM%3Dreserved=0
>  x86/mm
> head:   3950746d9d8ef981c1cb842384e0e86e8d1aad76
> commit: c7b6f29b6257532792fc722b68fcc0e00b5a856c [14/35] bpf: Fail 
> bpf_probe_write_user() while mm is switched
> config: s390-defconfig (attached as .config)
> compiler: s390x-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
> reproduce:
>wget 
> https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fraw.githubusercontent.com%2Fintel%2Flkp-tests%2Fmaster%2Fsbin%2Fmake.crossdata=02%7C01%7Cnamit%40vmware.com%7C8a380b9453f249fd924a08d6cdc9e8cd%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636922664483201432sdata=Sm%2FfjL7UqETv7HEEr32M2v3XmGwdAD10Wyr8ZmoQX50%3Dreserved=0
>  -O ~/bin/make.cross
>chmod +x ~/bin/make.cross
>git checkout c7b6f29b6257532792fc722b68fcc0e00b5a856c
># save the attached .config to linux build tree
>GCC_VERSION=7.2.0 make.cross ARCH=s390 
> 
> If you fix the issue, kindly add following tag
> Reported-by: kbuild test robot 
> 
> All errors (new ones prefixed by >>):
> 
>   In file included from include/linux/kernel.h:11:0,
>from kernel/trace/bpf_trace.c:5:
>   kernel/trace/bpf_trace.c: In function 'bpf_probe_write_user':
>>> kernel/trace/bpf_trace.c:179:16: error: implicit declaration of function 
>>> 'nmi_uaccess_okay'; did you mean '__access_ok'? 
>>> [-Werror=implicit-function-declaration]
> if (unlikely(!nmi_uaccess_okay()))

So s390 does not use the generic TLB gather architecture, which triggered
the problem.

Unfortunately, reproducing the failed build caused (other) errors. But
worse, fixing this issue “cleanly” is hard due to the dependencies between
the header files.

The best I managed to do without over-complicating the solution is the
following, which might not be super clean. Let me know whether to submit a
separate patch (on top or instead of the current one).

-- >8 --

From bc60dfc415f9ecc01771b388dacd41adc976929c Mon Sep 17 00:00:00 2001
From: Nadav Amit 
Date: Tue, 30 Apr 2019 13:48:48 -0700
Subject: [PATCH] mm/tlb: Fix "Provide default nmi_uaccess_okay()"

Signed-off-by: Nadav Amit 
---
 arch/x86/include/asm/tlbflush.h |  4 +---
 arch/x86/include/asm/uaccess.h  |  2 ++
 include/asm-generic/tlb.h   |  9 -
 include/linux/uaccess.h | 12 
 4 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
index dee375831962..765e6b01eefd 100644
--- a/arch/x86/include/asm/tlbflush.h
+++ b/arch/x86/include/asm/tlbflush.h
@@ -249,7 +249,7 @@ DECLARE_PER_CPU_SHARED_ALIGNED(struct tlb_state, 
cpu_tlbstate);
  * interrupted some kernel code that was temporarily using a
  * different mm.
  */
-static inline bool nmi_uaccess_okay(void)
+static inline bool arch_nmi_uaccess_okay(void)
 {
struct mm_struct *loaded_mm = this_cpu_read(cpu_tlbstate.loaded_mm);
struct mm_struct *current_mm = current->mm;
@@ -274,8 +274,6 @@ static inline bool nmi_uaccess_okay(void)
return true;
 }
 
-#define nmi_uaccess_okay nmi_uaccess_okay
-
 /* Initialize cr4 shadow for this CPU. */
 static inline void cr4_init_shadow(void)
 {
diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index 22ba683afdc2..d4b487d2441c 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -698,6 +698,8 @@ extern struct movsl_mask {
  */
 #define __copy_from_user_nmi __copy_from_user_inatomic
 
+#define nmi_uaccess_okay() arch_nmi_uaccess_okay()
+
 /*
  * The "unsafe" user accesses aren't really "unsafe", but the naming
  * is a big fat warning: you have to not only do the access_ok()
diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h
index 480e5b2a5748..b9edc7608d90 100644
--- a/include/asm-generic/tlb.h
+++ b/include/asm-generic/tlb.h
@@ -21,15 +21,6 @@
 #include 
 #include 
 
-/*
- * Blindly accessing user memory from NMI context can be dangerous
- * if we're in the middle of switching the current user task or switching
- * the loaded mm.
- */
-#ifndef nmi_uaccess_okay
-# define nmi_uaccess_okay() true
-#endif
-
 #ifdef CONFIG_MMU
 
 /*
diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
index 2b70130af585..e2e12945deab 100644
--- a/include/linux/uaccess.h
+++ b/include/linux/uaccess.h
@@ -280,4 +280,16 @@ void __noreturn usercopy_abort(const char *name, const 
char *detail,
   unsigned long len);
 #endif
 
+/*
+ * Blindly accessing user memory from NMI context can be dangerous if we're in
+ * the middle of switching the current user task or switching the loaded mm.
+ * 

Re: [PATCH v3 2/2] dt-bindings: cpufreq: Document allwinner,cpu-operating-points-v2

2019-04-30 Thread Frank Lee
On Tue, Apr 30, 2019 at 12:42 PM Viresh Kumar  wrote:
>
> On 29-04-19, 11:18, Rob Herring wrote:
> > On Sun, Apr 28, 2019 at 4:53 AM Frank Lee  wrote:
> > >
> > > On Sat, Apr 27, 2019 at 5:15 AM Rob Herring  wrote:
> > > >
> > > > On Wed, Apr 10, 2019 at 01:41:39PM -0400, Yangtao Li wrote:
> > > > > Allwinner Process Voltage Scaling Tables defines the voltage and
> > > > > frequency value based on the speedbin blown in the efuse combination.
> > > > > The sunxi-cpufreq-nvmem driver reads the efuse value from the SoC to
> > > > > provide the OPP framework with required information.
> > > > > This is used to determine the voltage and frequency value for each
> > > > > OPP of operating-points-v2 table when it is parsed by the OPP 
> > > > > framework.
> > > > >
> > > > > The "allwinner,cpu-operating-points-v2" DT extends the 
> > > > > "operating-points-v2"
> > > > > with following parameters:
> > > > > - nvmem-cells (NVMEM area containig the speedbin information)
> > > > > - opp-microvolt-: voltage in micro Volts.
> > > > >   At runtime, the platform can pick a  and matching
> > > > >   opp-microvolt- property.
> > > > >   HW: :
> > > > >   sun50iw-h6  speed0 speed1 speed2
> > > >
> > > > We already have at least one way to support speed bins with QC kryo
> > > > binding. Why do we need a different way?
> > >
> > > For some SOCs, for some reason (making the CPU have approximate 
> > > performance),
> > > they use the same frequency but different voltage. In the case where
> > > this speed bin
> > > is not a lot and opp uses the same frequency, too many repeated opp
> > > nodes are a bit
> > > redundant and not intuitive enough.
> > >
> > > So, I think it's worth the new method.
> >
> > Well, I don't.
> >
> > We can't have every SoC vendor doing their own thing just because they
> > want to. If there are technical reasons why existing bindings don't
> > work, then maybe we need to do something different. But I haven't
> > heard any reasons.
>
> Well there is a good reason for attempting the new bindings and I wasn't sure 
> if
> updating the earlier bindings or adding another one for platform is correct. 
> As
> we aren't really adding new bindings, but just documentation around it.
We didn't really add anything else, it still revolves around the
features that opp already supports.
>
> So there are two ways OPP core support this thing:
>
> - opp-supported-hw: This is a better fit if we have a smaller group of
>   frequencies to select from a bigger group, so we disable non-required OPPs
>   completely. This is what Qcom did as they wanted to select different
>   frequencies all together.
>
> - opp-microvolt-: This is a better fit if the frequencies remain same 
> and
>   only few of the properties like voltage/current have a different value. So 
> we
>   don't disable any OPPs but just select the right voltage/current for those
>   frequencies. This avoids unnecessary duplication of the OPPs in DT and 
> that's
>   what allwinner guys want.
>
> The kryo nvmem bindings currently supports opp-supported-hw, maybe we can add
> mention support for second one in the same file and rename it well.
So which way is correct?

Thx,
Yangtao
>
> --
> viresh


Re: [PATCH v3 6/6] arm64: dts: qcom: msm8998: Add mmcc node

2019-04-30 Thread Bjorn Andersson
On Tue 30 Apr 19:27 PDT 2019, Jeffrey Hugo wrote:

> Add MSM8998 Multimedia Clock Controller DT node.
> 
> Signed-off-by: Jeffrey Hugo 

Reviewed-by: Bjorn Andersson 

(But same comment as earlier wrt clocks vs clock-names ordering)

Regards,
Bjorn

> ---
>  arch/arm64/boot/dts/qcom/msm8998.dtsi | 14 ++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/arch/arm64/boot/dts/qcom/msm8998.dtsi 
> b/arch/arm64/boot/dts/qcom/msm8998.dtsi
> index 9c88801..5b63fa2 100644
> --- a/arch/arm64/boot/dts/qcom/msm8998.dtsi
> +++ b/arch/arm64/boot/dts/qcom/msm8998.dtsi
> @@ -3,6 +3,7 @@
>  
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  
> @@ -1066,6 +1067,19 @@
>   status = "disabled";
>   };
>  
> + mmcc: clock-controller@c8c {
> + compatible = "qcom,mmcc-msm8998";
> + #clock-cells = <1>;
> + #reset-cells = <1>;
> + #power-domain-cells = <1>;
> + reg = <0x0c8c 0x4>;
> +
> + clock-names = "xo",
> +   "gpll0";
> + clocks = < RPM_SMD_XO_CLK_SRC>,
> +  < GPLL0_OUT_MAIN>;
> + };
> +
>   timer@1792 {
>   #address-cells = <1>;
>   #size-cells = <1>;
> -- 
> Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, 
> Inc.
> Qualcomm Technologies, Inc. is a member of the
> Code Aurora Forum, a Linux Foundation Collaborative Project.
> 


Re: [PATCH v5 2/3] power: supply: Add driver for Microchip UCS1002

2019-04-30 Thread Randy Dunlap
Hi,

On 4/30/19 8:34 PM, Andrey Smirnov wrote:
> diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
> index e901b9879e7e..c614c8a196f3 100644
> --- a/drivers/power/supply/Kconfig
> +++ b/drivers/power/supply/Kconfig
> @@ -660,4 +660,13 @@ config FUEL_GAUGE_SC27XX
>Say Y here to enable support for fuel gauge with SC27XX
>PMIC chips.
>  
> +config CHARGER_UCS1002
> +tristate "Microchip UCS1002 USB Port Power Controller"

Please indent the tristate line with a tab instead of spaces.

> + depends on I2C
> + depends on OF
> + select REGMAP_I2C
> + help
> +   Say Y to enable support for Microchip UCS1002 Programmable
> +   USB Port Power Controller with Charger Emulation.
> +
>  endif # POWER_SUPPLY


thnx.
-- 
~Randy


Re: [PATCH v3 5/6] clk: qcom: Add MSM8998 Multimedia Clock Controller (MMCC) driver

2019-04-30 Thread Bjorn Andersson
On Tue 30 Apr 19:27 PDT 2019, Jeffrey Hugo wrote:
> +static const struct of_device_id mmcc_msm8998_match_table[] = {
> + { .compatible = "qcom,mmcc-msm8998" },
> + { }
> +};
> +MODULE_DEVICE_TABLE(of, mmcc_msm8998_match_table);
> +
> +static int mmcc_msm8998_probe(struct platform_device *pdev)
> +{
> + struct regmap *regmap;
> +

Don't you want to wait for "xo" here as well?

> + regmap = qcom_cc_map(pdev, _msm8998_desc);
> + if (IS_ERR(regmap))
> + return PTR_ERR(regmap);
> +
> + return qcom_cc_really_probe(pdev, _msm8998_desc, regmap);
> +}
[..]
> +MODULE_DESCRIPTION("QCOM MMCC MSM8998 Driver");
> +MODULE_LICENSE("GPL v2");
> +MODULE_ALIAS("platform:mmcc-msm8998");

MODULE_DEVICE_TABLE() will provide the alias for module auto loading, so
drop this.

Regards,
Bjorn


linux-next: manual merge of the input tree with the arm-soc tree

2019-04-30 Thread Stephen Rothwell
Hi Dmitry,

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

  Documentation/devicetree/bindings/vendor-prefixes.txt

between commit:

  2c98d9e47533 ("dt-bindings: vendor-prefixes: add AZW")

from the arm-soc tree and commit:

  7b5bb55d0dad ("Input: add support for Azoteq IQS550/572/525")

from the input tree.

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

-- 
Cheers,
Stephen Rothwell

diff --cc Documentation/devicetree/bindings/vendor-prefixes.txt
index 5f2b185a04e6,51f99549161e..
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@@ -54,7 -53,7 +54,8 @@@ avic  Shanghai AVIC Optoelectronics Co.
  avnet Avnet, Inc.
  axentia   Axentia Technologies AB
  axis  Axis Communications AB
+ azoteqAzoteq (Pty) Ltd
 +azw Shenzhen AZW Technology Co., Ltd.
  bananapi BIPAI KEJI LIMITED
  bhf   Beckhoff Automation GmbH & Co. KG
  bitmain   Bitmain Technologies


pgpO1X0guE_cw.pgp
Description: OpenPGP digital signature


Re: perf build broken in 5.1-rc7

2019-04-30 Thread Song Liu
On Tue, Apr 30, 2019 at 6:31 AM Thomas Backlund  wrote:
>
>
> Den 30-04-2019 kl. 16:06, skrev Song Liu:
> > On Tue, Apr 30, 2019 at 12:55 AM Thomas Backlund  wrote:
> >> Den 30-04-2019 kl. 10:26, skrev Thomas Backlund:
> >>> Building perf in 5.1-rc5/6/7 fails:
> >>>
> >>>
> >>> Build start:
> >>>
> >>>
> >>>make -s -C tools/perf NO_PERF_READ_VDSO32=1 NO_PERF_READ_VDSOX32=1
> >>> WERROR=0 NO_LIBUNWIND=1 HAVE_CPLUS_DEMANGLE=1 NO_GTK2=1 NO_STRLCPY=1
> >>> NO_BIONIC=1 NO_JVMTI=1 prefix=/usr lib=lib64 all
> >>> BUILD:   Doing 'make -j32' parallel build
> >>> HOSTCC   fixdep.o
> >>> HOSTLD   fixdep-in.o
> >>> LINK fixdep
> >>> Warning: Kernel ABI header at 'tools/arch/x86/include/uapi/asm/vmx.h'
> >>> differs from latest version at 'arch/x86/include/uapi/asm/vmx.h'
> >>> diff -u tools/arch/x86/include/uapi/asm/vmx.h
> >>> arch/x86/include/uapi/asm/vmx.h
> >>>
> >>> Auto-detecting system features:
> >>> ... dwarf: [ on  ]
> >>> ...dwarf_getlocations: [ on  ]
> >>> ... glibc: [ on  ]
> >>> ...  gtk2: [ on  ]
> >>> ...  libaudit: [ on  ]
> >>> ...libbfd: [ on  ]
> >>> ...libelf: [ on  ]
> >>> ...   libnuma: [ on  ]
> >>> ...numa_num_possible_cpus: [ on  ]
> >>> ...   libperl: [ on  ]
> >>> ... libpython: [ on  ]
> >>> ...  libslang: [ on  ]
> >>> ... libcrypto: [ on  ]
> >>> ... libunwind: [ on  ]
> >>> ...libdw-dwarf-unwind: [ on  ]
> >>> ...  zlib: [ on  ]
> >>> ...  lzma: [ on  ]
> >>> ... get_cpuid: [ on  ]
> >>> ...   bpf: [ on  ]
> >>> ...libaio: [ on  ]
> >>> ...disassembler-four-args: [ OFF ]
> >>>
> >>> Makefile.config:473: No sys/sdt.h found, no SDT events are defined,
> >>> please install systemtap-sdt-devel or systemtap-sdt-dev
> >>> Makefile.config:853: No libbabeltrace found, disables 'perf data' CTF
> >>> format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev
> >>>
> >>>
> >>> And breaks with:
> >>>
> >>>
> >>> CC   ui/setup.o
> >>> util/annotate.c: In function 'symbol__disassemble_bpf':
> >>> util/annotate.c:1767:29: error: incompatible type for argument 1 of
> >>> 'disassembler'
> >>> disassemble = disassembler(bfdf);
> >>>^~~~
> >>> In file included from util/annotate.c:1689:
> >>> /usr/include/dis-asm.h:325:63: note: expected 'enum bfd_architecture'
> >>> but argument is of type 'bfd *' {aka 'struct bfd *'}
> >>>extern disassembler_ftype disassembler (enum bfd_architecture arc,
> >>>~~^~~
> >>> util/annotate.c:1767:16: error: too few arguments to function
> >>> 'disassembler'
> >>> disassemble = disassembler(bfdf);
> >>>   ^~~~
> >>> In file included from util/annotate.c:1689:
> >>> /usr/include/dis-asm.h:325:27: note: declared here
> >>>extern disassembler_ftype disassembler (enum bfd_architecture arc,
> >>>  ^~~~
> >>> CC   arch/x86/util/header.o
> >>> CC   arch/x86/util/tsc.o
> >>> CC   arch/x86/util/pmu.o
> >>> mv: cannot stat 'util/.annotate.o.tmp': No such file or directory
> >>> CC   bench/futex-requeue.o
> >>> CC   arch/x86/util/kvm-stat.o
> >>> make[4]: ***
> >>> [/work/rpmbuild/BUILD/kernel-x86_64/linux-5.0/tools/build/Makefile.build:97:
> >>> util/annotate.o] Error 1
> >>> make[4]: *** Waiting for unfinished jobs
> >>> CC   util/build-id.o
> >>>
> >>>
> >>>
> >>
> >> And I forgot...
> >>
> >> Reverting:
> >>   From 6987561c9e86eace45f2dbb0c564964a63f4150a Mon Sep 17 00:00:00 2001
> >> From: Song Liu 
> >> Date: Mon, 11 Mar 2019 22:30:48 -0700
> >> Subject: perf annotate: Enable annotation of BPF programs
> >>
> >> Makes it build again.
> >>
> >> --
> >> Thomas
> >>
> > Hi Thomas,
> >
> > Which system are you running this test on? I would like to repro it in a VM.
> >
> > Thanks,
> > Song
>
>
> Mageia Cauldron currently stabilizing to become Mageia 7 in ~1 month.
>
>
> Basesystem is:
>
> binutils-2.32-5.mga7
> (includes all fixes from upstream binutils-2_32-branch)
>
> gcc-8.3.1-0.20190419.2.mga7
>
> glibc-2.29-7.mga7
> (includes all fixes from upstream glibc release/2.29/master branch up to
> 2019-04-15 for now)
>
>
> kernel-desktop-5.1.0-0.rc7.1.mga7
> kernel-userspace-headers-5.1.0-0.rc7.1.mga7
>
>
> --
>
> Thomas
>
>

I am trying to install Mageia 7 beta 3, but hit some issue. While I try fix it,
could you please try clean everything under tools/ and retry:

  make -C tools/ clean
  make -C tools/perf -j

If it still fails, how about building bpftool?

  make -C tools/bpf -j

Thanks,
Song


Re: [PATCH v3 4/6] dt-bindings: clock: Add support for the MSM8998 mmcc

2019-04-30 Thread Bjorn Andersson
On Tue 30 Apr 19:26 PDT 2019, Jeffrey Hugo wrote:

> Document the multimedia clock controller found on MSM8998.
> 
> Signed-off-by: Jeffrey Hugo 
> Reviewed-by: Rob Herring 

Reviewed-by: Bjorn Andersson 

> ---
>  .../devicetree/bindings/clock/qcom,mmcc.txt|  21 +++
>  include/dt-bindings/clock/qcom,mmcc-msm8998.h  | 210 
> +
>  2 files changed, 231 insertions(+)
>  create mode 100644 include/dt-bindings/clock/qcom,mmcc-msm8998.h
> 
> diff --git a/Documentation/devicetree/bindings/clock/qcom,mmcc.txt 
> b/Documentation/devicetree/bindings/clock/qcom,mmcc.txt
> index 8b0f784..a92f3cb 100644
> --- a/Documentation/devicetree/bindings/clock/qcom,mmcc.txt
> +++ b/Documentation/devicetree/bindings/clock/qcom,mmcc.txt
> @@ -10,11 +10,32 @@ Required properties :
>   "qcom,mmcc-msm8960"
>   "qcom,mmcc-msm8974"
>   "qcom,mmcc-msm8996"
> + "qcom,mmcc-msm8998"
>  
>  - reg : shall contain base register location and length
>  - #clock-cells : shall contain 1
>  - #reset-cells : shall contain 1
>  
> +For MSM8998 only:
> + - clocks: a list of phandles and clock-specifier pairs,
> +   one for each entry in clock-names.
> + - clock-names: "xo" for the xo clock.
> +"gpll0" for the global pll 0 clock.
> +"dsi0dsi" for the dsi0 pll dsi clock (required if dsi is
> + enabled, optional otherwise).
> +"dsi0byte" for the dsi0 pll byte clock (required if dsi
> + is enabled, optional otherwise).
> +"dsi1dsi" for the dsi1 pll dsi clock (required if dsi is
> + enabled, optional otherwise).
> +"dsi1byte" for the dsi1 pll byte clock (required if dsi
> + is enabled, optional otherwise).
> +"hdmipll" for the hdmi pll clock (required if hdmi is
> + enabled, optional otherwise).
> +"dpvco" for the displayport pll vco clock (required if
> + dp is enabled, optional otherwise).
> +"dplink" for the displayport pll link clock (required if
> + dp is enabled, optional otherwise).
> +
>  Optional properties :
>  - #power-domain-cells : shall contain 1
>  
> diff --git a/include/dt-bindings/clock/qcom,mmcc-msm8998.h 
> b/include/dt-bindings/clock/qcom,mmcc-msm8998.h
> new file mode 100644
> index 000..ecbafdb
> --- /dev/null
> +++ b/include/dt-bindings/clock/qcom,mmcc-msm8998.h
> @@ -0,0 +1,210 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright (c) 2019, The Linux Foundation. All rights reserved.
> + */
> +
> +#ifndef _DT_BINDINGS_CLK_MSM_MMCC_8998_H
> +#define _DT_BINDINGS_CLK_MSM_MMCC_8998_H
> +
> +#define MMPLL0   0
> +#define MMPLL0_OUT_EVEN  1
> +#define MMPLL1   2
> +#define MMPLL1_OUT_EVEN  3
> +#define MMPLL3   4
> +#define MMPLL3_OUT_EVEN  5
> +#define MMPLL4   6
> +#define MMPLL4_OUT_EVEN  7
> +#define MMPLL5   8
> +#define MMPLL5_OUT_EVEN  9
> +#define MMPLL6   10
> +#define MMPLL6_OUT_EVEN  11
> +#define MMPLL7   12
> +#define MMPLL7_OUT_EVEN  13
> +#define MMPLL10  14
> +#define MMPLL10_OUT_EVEN 15
> +#define BYTE0_CLK_SRC16
> +#define BYTE1_CLK_SRC17
> +#define CCI_CLK_SRC  18
> +#define CPP_CLK_SRC  19
> +#define CSI0_CLK_SRC 20
> +#define CSI1_CLK_SRC 21
> +#define CSI2_CLK_SRC 22
> +#define CSI3_CLK_SRC 23
> +#define CSIPHY_CLK_SRC   24
> +#define CSI0PHYTIMER_CLK_SRC 25
> +#define CSI1PHYTIMER_CLK_SRC 26
> +#define CSI2PHYTIMER_CLK_SRC 27
> +#define DP_AUX_CLK_SRC   28
> +#define DP_CRYPTO_CLK_SRC29
> +#define DP_LINK_CLK_SRC  30
> +#define DP_PIXEL_CLK_SRC 31
> +#define ESC0_CLK_SRC   

Re: [PATCH v3 2/6] arm64: dts: msm8998: Add xo clock to gcc node

2019-04-30 Thread Bjorn Andersson
On Tue 30 Apr 19:25 PDT 2019, Jeffrey Hugo wrote:

> GCC is a consumer of the xo clock.  Add a reference to the clock supplier
> to the gcc node.
> 
> Signed-off-by: Jeffrey Hugo 

Reviewed-by: Bjorn Andersson 

(Although I prefer clock-names following clocks)

Regards,
Bjorn

> ---
>  arch/arm64/boot/dts/qcom/msm8998.dtsi | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/arm64/boot/dts/qcom/msm8998.dtsi 
> b/arch/arm64/boot/dts/qcom/msm8998.dtsi
> index 574be78..9c88801 100644
> --- a/arch/arm64/boot/dts/qcom/msm8998.dtsi
> +++ b/arch/arm64/boot/dts/qcom/msm8998.dtsi
> @@ -709,6 +709,8 @@
>   #reset-cells = <1>;
>   #power-domain-cells = <1>;
>   reg = <0x10 0xb>;
> + clock-names = "xo";
> + clocks = < RPM_SMD_XO_CLK_SRC>;
>   };
>  
>   tlmm: pinctrl@340 {
> -- 
> Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, 
> Inc.
> Qualcomm Technologies, Inc. is a member of the
> Code Aurora Forum, a Linux Foundation Collaborative Project.
> 


[PATCH v5 3/3] dt-bindings: power: supply: Add bindings for Microchip UCS1002

2019-04-30 Thread Andrey Smirnov
Add bindings for Microchip UCS1002 Programmable USB Port Power
Controller with Charger Emulation.

Signed-off-by: Andrey Smirnov 
Reviewed-by: Rob Herring 
Cc: Enric Balletbo Serra 
Cc: Chris Healy 
Cc: Lucas Stach 
Cc: Fabio Estevam 
Cc: Guenter Roeck 
Cc: Sebastian Reichel 
Cc: linux-kernel@vger.kernel.org
Cc: linux...@vger.kernel.org
---
 .../power/supply/microchip,ucs1002.txt| 27 +++
 1 file changed, 27 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/power/supply/microchip,ucs1002.txt

diff --git 
a/Documentation/devicetree/bindings/power/supply/microchip,ucs1002.txt 
b/Documentation/devicetree/bindings/power/supply/microchip,ucs1002.txt
new file mode 100644
index ..1d284ad816bf
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/supply/microchip,ucs1002.txt
@@ -0,0 +1,27 @@
+Microchip UCS1002 USB Port Power Controller
+
+Required properties:
+- compatible   : Should be "microchip,ucs1002";
+- reg  : I2C slave address
+
+Optional properties:
+- interrupts   : A list of interrupts lines present (could be either
+ corresponding to A_DET# pin, ALERT# pin, or both)
+- interrupt-names  : A list of interrupt names. Should contain (if
+ present):
+ - "a_det" for line connected to A_DET# pin
+ - "alert" for line connected to ALERT# pin
+ Both are expected to be IRQ_TYPE_EDGE_BOTH
+Example:
+
+ {
+   charger@32 {
+   compatible = "microchip,ucs1002";
+   pinctrl-names = "default";
+   pinctrl-0 = <_ucs1002_pins>;
+   reg = <0x32>;
+   interrupts-extended = < 2 IRQ_TYPE_EDGE_BOTH>,
+ < 21 IRQ_TYPE_EDGE_BOTH>;
+   interrupt-names = "a_det", "alert";
+   };
+};
-- 
2.20.1



[PATCH v5 2/3] power: supply: Add driver for Microchip UCS1002

2019-04-30 Thread Andrey Smirnov
Add driver for Microchip UCS1002 Programmable USB Port Power
Controller with Charger Emulation. The driver exposed a power supply
device to control/monitor various parameter of the device as well as a
regulator to allow controlling VBUS line.

Signed-off-by: Enric Balletbo Serra 
Signed-off-by: Andrey Smirnov 
Cc: Chris Healy 
Cc: Lucas Stach 
Cc: Fabio Estevam 
Cc: Guenter Roeck 
Cc: Sebastian Reichel 
Cc: linux-kernel@vger.kernel.org
Cc: linux...@vger.kernel.org
---
 drivers/power/supply/Kconfig |   9 +
 drivers/power/supply/Makefile|   1 +
 drivers/power/supply/ucs1002_power.c | 646 +++
 3 files changed, 656 insertions(+)
 create mode 100644 drivers/power/supply/ucs1002_power.c

diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
index e901b9879e7e..c614c8a196f3 100644
--- a/drivers/power/supply/Kconfig
+++ b/drivers/power/supply/Kconfig
@@ -660,4 +660,13 @@ config FUEL_GAUGE_SC27XX
 Say Y here to enable support for fuel gauge with SC27XX
 PMIC chips.
 
+config CHARGER_UCS1002
+tristate "Microchip UCS1002 USB Port Power Controller"
+   depends on I2C
+   depends on OF
+   select REGMAP_I2C
+   help
+ Say Y to enable support for Microchip UCS1002 Programmable
+ USB Port Power Controller with Charger Emulation.
+
 endif # POWER_SUPPLY
diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile
index b731c2a9b695..c56803a9e4fe 100644
--- a/drivers/power/supply/Makefile
+++ b/drivers/power/supply/Makefile
@@ -87,3 +87,4 @@ obj-$(CONFIG_AXP288_CHARGER)  += axp288_charger.o
 obj-$(CONFIG_CHARGER_CROS_USBPD)   += cros_usbpd-charger.o
 obj-$(CONFIG_CHARGER_SC2731)   += sc2731_charger.o
 obj-$(CONFIG_FUEL_GAUGE_SC27XX)+= sc27xx_fuel_gauge.o
+obj-$(CONFIG_CHARGER_UCS1002)  += ucs1002_power.o
diff --git a/drivers/power/supply/ucs1002_power.c 
b/drivers/power/supply/ucs1002_power.c
new file mode 100644
index ..d66b4eff9b7a
--- /dev/null
+++ b/drivers/power/supply/ucs1002_power.c
@@ -0,0 +1,646 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Driver for UCS1002 Programmable USB Port Power Controller
+ *
+ * Copyright (C) 2019 Zodiac Inflight Innovations
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* UCS1002 Registers */
+#define UCS1002_REG_CURRENT_MEASUREMENT0x00
+
+/*
+ * The Total Accumulated Charge registers store the total accumulated
+ * charge delivered from the VS source to a portable device. The total
+ * value is calculated using four registers, from 01h to 04h. The bit
+ * weighting of the registers is given in mA/hrs.
+ */
+#define UCS1002_REG_TOTAL_ACC_CHARGE   0x01
+
+/* Other Status Register */
+#define UCS1002_REG_OTHER_STATUS   0x0f
+#  define F_ADET_PIN   BIT(4)
+#  define F_CHG_ACTBIT(3)
+
+/* Interrupt Status */
+#define UCS1002_REG_INTERRUPT_STATUS   0x10
+#  define F_DISCHARGE_ERR  BIT(6)
+#  define F_RESET  BIT(5)
+#  define F_MIN_KEEP_OUT   BIT(4)
+#  define F_TSDBIT(3)
+#  define F_OVER_VOLT  BIT(2)
+#  define F_BACK_VOLT  BIT(1)
+#  define F_OVER_ILIM  BIT(0)
+
+/* Pin Status Register */
+#define UCS1002_REG_PIN_STATUS 0x14
+#  define UCS1002_PWR_STATE_MASK   0x03
+#  define F_PWR_EN_PIN BIT(6)
+#  define F_M2_PIN BIT(5)
+#  define F_M1_PIN BIT(4)
+#  define F_EM_EN_PIN  BIT(3)
+#  define F_SEL_PINBIT(2)
+#  define F_ACTIVE_MODE_MASK   GENMASK(5, 3)
+#  define F_ACTIVE_MODE_PASSTHROUGHF_M2_PIN
+#  define F_ACTIVE_MODE_DEDICATED  F_EM_EN_PIN
+#  define F_ACTIVE_MODE_BC12_DCP   (F_M2_PIN | F_EM_EN_PIN)
+#  define F_ACTIVE_MODE_BC12_SDP   F_M1_PIN
+#  define F_ACTIVE_MODE_BC12_CDP   (F_M1_PIN | F_M2_PIN | F_EM_EN_PIN)
+
+/* General Configuration Register */
+#define UCS1002_REG_GENERAL_CFG0x15
+#  define F_RATION_EN  BIT(3)
+
+/* Emulation Configuration Register */
+#define UCS1002_REG_EMU_CFG0x16
+
+/* Switch Configuration Register */
+#define UCS1002_REG_SWITCH_CFG 0x17
+#  define F_PIN_IGNORE BIT(7)
+#  define F_EM_EN_SET  BIT(5)
+#  define F_M2_SET BIT(4)
+#  define F_M1_SET BIT(3)
+#  define F_S0_SET BIT(2)
+#  define F_PWR_EN_SET BIT(1)
+#  define F_LATCH_SET  BIT(0)
+#  define V_SET_ACTIVE_MODE_MASK   GENMASK(5, 3)
+#  define V_SET_ACTIVE_MODE_PASSTHROUGHF_M2_SET
+#  define V_SET_ACTIVE_MODE_DEDICATED  F_EM_EN_SET
+#  define V_SET_ACTIVE_MODE_BC12_DCP   (F_M2_SET | F_EM_EN_SET)
+#  define V_SET_ACTIVE_MODE_BC12_SDP   

Re: [PATCH v3 1/6] dt-bindings: clock: Document external clocks for MSM8998 gcc

2019-04-30 Thread Bjorn Andersson
On Tue 30 Apr 19:24 PDT 2019, Jeffrey Hugo wrote:

> The global clock controller on MSM8998 can consume a number of external
> clocks.  Document them.
> 
> Signed-off-by: Jeffrey Hugo 
> ---
>  Documentation/devicetree/bindings/clock/qcom,gcc.txt | 10 ++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/clock/qcom,gcc.txt 
> b/Documentation/devicetree/bindings/clock/qcom,gcc.txt
> index 8661c3c..7d45323 100644
> --- a/Documentation/devicetree/bindings/clock/qcom,gcc.txt
> +++ b/Documentation/devicetree/bindings/clock/qcom,gcc.txt
> @@ -28,6 +28,16 @@ Required properties :
>  - #clock-cells : shall contain 1
>  - #reset-cells : shall contain 1
>  
> +For MSM8998 only:
> + - clocks: a list of phandles and clock-specifier pairs,
> +   one for each entry in clock-names.
> + - clock-names: "xo" (required)
> +"usb3_pipe" (optional)
> +"ufs_rx_symbol0" (optional)
> +"ufs_rx_symbol1" (optional)
> +"ufs_tx_symbol0" (optional)
> +"pcie0_pipe" (optional)

The optional clocks here comes from hardware blocks that in turn depends
on the gcc, so we would need to resolve them lazily (in contrast to xo).

We typically don't list these in DT, but if this is close to the
complete list of incoming clocks then I like the explicitness of it.

Reviewed-by: Bjorn Andersson 

Regards,
Bjorn

> +
>  Optional properties :
>  - #power-domain-cells : shall contain 1
>  - Qualcomm TSENS (thermal sensor device) on some devices can
> -- 
> Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, 
> Inc.
> Qualcomm Technologies, Inc. is a member of the
> Code Aurora Forum, a Linux Foundation Collaborative Project.
> 


[PATCH v5 0/3] Driver for UCS1002

2019-04-30 Thread Andrey Smirnov
Everyone:

This small series adds a driver for UCS1002 Programmable USB Port
Power Controller with Charger Emulation. See [page] for product page
and [datasheet] for device dataseet. Hopefully each individual patch
is self explanatory.

Note that this series is a revival of the upstreaming effort by Enric
Balletbo Serra last version of which can be found at [original-effort]

Feedback is welcome!

Thanks,
Andrey Smirnov

Changes since [v4]:

- Chagned "interrupts-extended" -> "interrupts" in DT bindings description

- Collected Reviewed-by from Rob

Changes since [v3]:

- Added a check for negative values to ucs1002_set_usb_type()

Changes since [v2]:

- Fixed a bug pointed out by Lucas

Changes since [v1]:

- Moved IRQ trigger specification to DT

- Fixed silent error paths in probe()

- Dropped error message in ucs1002_set_max_current()

- Fixed license mismatch

- Changed the driver to configure the chip to BC1.2 CDP by default

- Made other small fixes as per feedback for v1

[v4] 
https://lore.kernel.org/lkml/20190430064557.28469-1-andrew.smir...@gmail.com
[v3] 
https://lore.kernel.org/lkml/20190429195349.20335-1-andrew.smir...@gmail.com
[v2] https://lore.kernel.org/lkml/20190429054741.7286-1-andrew.smir...@gmail.com
[v1] 
https://lore.kernel.org/lkml/20190417084457.28747-1-andrew.smir...@gmail.com/
[page] https://www.microchip.com/wwwproducts/en/UCS1002-2
[datasheet] 
https://ww1.microchip.com/downloads/en/DeviceDoc/UCS1002-2%20Data%20Sheet.pdf
[original-effort] 
https://lore.kernel.org/lkml/1460705181-10493-1-git-send-email-enric.balle...@collabora.com/

Andrey Smirnov (3):
  power: supply: core: Add POWER_SUPPLY_HEALTH_OVERCURRENT constant
  power: supply: Add driver for Microchip UCS1002
  dt-bindings: power: supply: Add bindings for Microchip UCS1002

 .../power/supply/microchip,ucs1002.txt|  27 +
 drivers/power/supply/Kconfig  |   9 +
 drivers/power/supply/Makefile |   1 +
 drivers/power/supply/power_supply_sysfs.c |   2 +-
 drivers/power/supply/ucs1002_power.c  | 646 ++
 include/linux/power_supply.h  |   1 +
 6 files changed, 685 insertions(+), 1 deletion(-)
 create mode 100644 
Documentation/devicetree/bindings/power/supply/microchip,ucs1002.txt
 create mode 100644 drivers/power/supply/ucs1002_power.c

-- 
2.20.1



[PATCH v5 1/3] power: supply: core: Add POWER_SUPPLY_HEALTH_OVERCURRENT constant

2019-04-30 Thread Andrey Smirnov
Add POWER_SUPPLY_HEALTH_OVERCURRENT constant in order to allow
singalling overcurrent condition via power supply health information.

Signed-off-by: Andrey Smirnov 
Reviewed-by: Guenter Roeck 
Cc: Enric Balletbo Serra 
Cc: Chris Healy 
Cc: Lucas Stach 
Cc: Fabio Estevam 
Cc: Guenter Roeck 
Cc: Sebastian Reichel 
Cc: linux-kernel@vger.kernel.org
Cc: linux...@vger.kernel.org
---
 drivers/power/supply/power_supply_sysfs.c | 2 +-
 include/linux/power_supply.h  | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/power_supply_sysfs.c 
b/drivers/power/supply/power_supply_sysfs.c
index 5358a80d854f..153f4a6ca57c 100644
--- a/drivers/power/supply/power_supply_sysfs.c
+++ b/drivers/power/supply/power_supply_sysfs.c
@@ -62,7 +62,7 @@ static const char * const power_supply_charge_type_text[] = {
 static const char * const power_supply_health_text[] = {
"Unknown", "Good", "Overheat", "Dead", "Over voltage",
"Unspecified failure", "Cold", "Watchdog timer expire",
-   "Safety timer expire"
+   "Safety timer expire", "Over current"
 };
 
 static const char * const power_supply_technology_text[] = {
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 2f9c201a54d1..bdab14c7ca4d 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -57,6 +57,7 @@ enum {
POWER_SUPPLY_HEALTH_COLD,
POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE,
POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE,
+   POWER_SUPPLY_HEALTH_OVERCURRENT,
 };
 
 enum {
-- 
2.20.1



Re: [PATCH v3 3/6] clk: qcom: smd: Add XO clock for MSM8998

2019-04-30 Thread Bjorn Andersson
On Tue 30 Apr 19:26 PDT 2019, Jeffrey Hugo wrote:

> The XO clock generally feeds into other clock controllers as the parent
> for a lot of clock generators.
> 
> Drop the "fake" XO clock in GCC now that it is redundant can will cause a
> namespace conflict.
> 
> Signed-off-by: Jeffrey Hugo 
> ---
>  drivers/clk/qcom/clk-smd-rpm.c | 24 
>  drivers/clk/qcom/gcc-msm8998.c | 29 -
>  2 files changed, 32 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/clk/qcom/clk-smd-rpm.c b/drivers/clk/qcom/clk-smd-rpm.c
> index 22dd42a..55a622df 100644
> --- a/drivers/clk/qcom/clk-smd-rpm.c
> +++ b/drivers/clk/qcom/clk-smd-rpm.c
> @@ -68,7 +68,7 @@
>   }
>  
>  #define __DEFINE_CLK_SMD_RPM_BRANCH(_platform, _name, _active, type, r_id,   
>  \
> - stat_id, r, key)  \
> + stat_id, r, key, ignore_unused) 
>   \

I expect that we can revert the ignore_unused part once we have a proper
way to deal with resource handover.


Reviewed-by: Bjorn Andersson 

Regards,
Bjorn

>   static struct clk_smd_rpm _platform##_##_active;  \
>   static struct clk_smd_rpm _platform##_##_name = { \
>   .rpm_res_type = (type),   \
> @@ -83,6 +83,7 @@
>   .name = #_name,   \
>   .parent_names = (const char *[]){ "xo_board" },   \
>   .num_parents = 1, \
> + .flags = (ignore_unused) ? CLK_IGNORE_UNUSED : 0, \
>   },\
>   };\
>   static struct clk_smd_rpm _platform##_##_active = {   \
> @@ -99,6 +100,7 @@
>   .name = #_active, \
>   .parent_names = (const char *[]){ "xo_board" },   \
>   .num_parents = 1, \
> + .flags = (ignore_unused) ? CLK_IGNORE_UNUSED : 0, \
>   },\
>   }
>  
> @@ -108,7 +110,17 @@
>  
>  #define DEFINE_CLK_SMD_RPM_BRANCH(_platform, _name, _active, type, r_id, r)  
>  \
>   __DEFINE_CLK_SMD_RPM_BRANCH(_platform, _name, _active, type,  \
> - r_id, 0, r, QCOM_RPM_SMD_KEY_ENABLE)
> + r_id, 0, r, QCOM_RPM_SMD_KEY_ENABLE, false)
> +
> +/*
> + * Intended for XO clock where we don't want it turned off during late init
> + * if we don't have a consumer by then, but can turn it off later for deep
> + * sleep
> + */
> +#define DEFINE_CLK_SMD_RPM_BRANCH_SKIP_UNUSED(_platform, _name, _active, 
> type,\
> +   r_id, r)\
> + __DEFINE_CLK_SMD_RPM_BRANCH(_platform, _name, _active, type,  \
> + r_id, 0, r, QCOM_RPM_SMD_KEY_ENABLE, true)
>  
>  #define DEFINE_CLK_SMD_RPM_QDSS(_platform, _name, _active, type, r_id)   
>   \
>   __DEFINE_CLK_SMD_RPM(_platform, _name, _active, type, r_id,   \
> @@ -117,12 +129,12 @@
>  #define DEFINE_CLK_SMD_RPM_XO_BUFFER(_platform, _name, _active, r_id)
>   \
>   __DEFINE_CLK_SMD_RPM_BRANCH(_platform, _name, _active,\
>   QCOM_SMD_RPM_CLK_BUF_A, r_id, 0, 1000,\
> - QCOM_RPM_KEY_SOFTWARE_ENABLE)
> + QCOM_RPM_KEY_SOFTWARE_ENABLE, false)
>  
>  #define DEFINE_CLK_SMD_RPM_XO_BUFFER_PINCTRL(_platform, _name, _active, 
> r_id) \
>   __DEFINE_CLK_SMD_RPM_BRANCH(_platform, _name, _active,\
>   QCOM_SMD_RPM_CLK_BUF_A, r_id, 0, 1000,\
> - QCOM_RPM_KEY_PIN_CTRL_CLK_BUFFER_ENABLE_KEY)
> + QCOM_RPM_KEY_PIN_CTRL_CLK_BUFFER_ENABLE_KEY, false)
>  
>  #define to_clk_smd_rpm(_hw) container_of(_hw, struct clk_smd_rpm, hw)
>  
> @@ -656,6 +668,8 @@ static int clk_smd_rpm_enable_scaling(struct qcom_smd_rpm 
> *rpm)
>  };
>  
>  /* msm8998 */
> +DEFINE_CLK_SMD_RPM_BRANCH_SKIP_UNUSED(msm8998, xo, xo_a, 
> QCOM_SMD_RPM_MISC_CLK,
> +   0, 1920);
>  DEFINE_CLK_SMD_RPM(msm8998, snoc_clk, snoc_a_clk, QCOM_SMD_RPM_BUS_CLK, 1);
>  DEFINE_CLK_SMD_RPM(msm8998, cnoc_clk, cnoc_a_clk, QCOM_SMD_RPM_BUS_CLK, 2);
>  DEFINE_CLK_SMD_RPM(msm8998, ce1_clk, ce1_a_clk, QCOM_SMD_RPM_CE_CLK, 0);
> @@ -678,6 +692,8 @@ static int clk_smd_rpm_enable_scaling(struct qcom_smd_rpm 
> *rpm)
>  DEFINE_CLK_SMD_RPM_XO_BUFFER(msm8998, rf_clk3, rf_clk3_a, 6);
>  DEFINE_CLK_SMD_RPM_XO_BUFFER_PINCTRL(msm8998, rf_clk3_pin, rf_clk3_a_pin, 6);
>  static struct clk_smd_rpm *msm8998_clks[] = {
> + [RPM_SMD_XO_CLK_SRC] 

Re: [PATCH v2] ext4: bad mount opts in no journal mode

2019-04-30 Thread Theodore Ts'o
On Mon, Apr 29, 2019 at 01:31:58PM -0400, Debabrata Banerjee wrote:
> Fixes:
> commit 1e381f60dad9 ("ext4: do not allow journal_opts for fs w/o journal")
> 
> Instead of removing EXT4_MOUNT_JOURNAL_CHECKSUM from s_def_mount_opt as
> I assume was intended, all other options were blown away leading to
> _ext4_show_options() output being incorrect.
> 
> Signed-off-by: Debabrata Banerjee 

Thanks, applied.  Note that the Fixes line should like this:

Fixes: 1e381f60dad9 ("ext4: do not allow journal_opts for fs w/o journal")

... and be placed along with the Signed-off-by: headers.

- Ted


[PATCH v3 6/6] arm64: dts: qcom: msm8998: Add mmcc node

2019-04-30 Thread Jeffrey Hugo
Add MSM8998 Multimedia Clock Controller DT node.

Signed-off-by: Jeffrey Hugo 
---
 arch/arm64/boot/dts/qcom/msm8998.dtsi | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/msm8998.dtsi 
b/arch/arm64/boot/dts/qcom/msm8998.dtsi
index 9c88801..5b63fa2 100644
--- a/arch/arm64/boot/dts/qcom/msm8998.dtsi
+++ b/arch/arm64/boot/dts/qcom/msm8998.dtsi
@@ -3,6 +3,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -1066,6 +1067,19 @@
status = "disabled";
};
 
+   mmcc: clock-controller@c8c {
+   compatible = "qcom,mmcc-msm8998";
+   #clock-cells = <1>;
+   #reset-cells = <1>;
+   #power-domain-cells = <1>;
+   reg = <0x0c8c 0x4>;
+
+   clock-names = "xo",
+ "gpll0";
+   clocks = < RPM_SMD_XO_CLK_SRC>,
+< GPLL0_OUT_MAIN>;
+   };
+
timer@1792 {
#address-cells = <1>;
#size-cells = <1>;
-- 
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH v3 5/6] clk: qcom: Add MSM8998 Multimedia Clock Controller (MMCC) driver

2019-04-30 Thread Jeffrey Hugo
Add a driver for the multimedia clock controller found on MSM8998
based devices. This should allow most multimedia device drivers
to probe and control their clocks.

Signed-off-by: Jeffrey Hugo 
---
 drivers/clk/qcom/Kconfig|9 +
 drivers/clk/qcom/Makefile   |1 +
 drivers/clk/qcom/mmcc-msm8998.c | 2915 +++
 3 files changed, 2925 insertions(+)
 create mode 100644 drivers/clk/qcom/mmcc-msm8998.c

diff --git a/drivers/clk/qcom/Kconfig b/drivers/clk/qcom/Kconfig
index 18bdf34..8f06cd9 100644
--- a/drivers/clk/qcom/Kconfig
+++ b/drivers/clk/qcom/Kconfig
@@ -221,6 +221,15 @@ config MSM_GCC_8998
  Say Y if you want to use peripheral devices such as UART, SPI,
  i2c, USB, UFS, SD/eMMC, PCIe, etc.
 
+config MSM_MMCC_8998
+   tristate "MSM8998 Multimedia Clock Controller"
+   select MSM_GCC_8998
+   select QCOM_GDSC
+   help
+ Support for the multimedia clock controller on msm8998 devices.
+ Say Y if you want to support multimedia devices such as display,
+ graphics, video encode/decode, camera, etc.
+
 config QCS_GCC_404
tristate "QCS404 Global Clock Controller"
help
diff --git a/drivers/clk/qcom/Makefile b/drivers/clk/qcom/Makefile
index f0768fb..0e7db8d 100644
--- a/drivers/clk/qcom/Makefile
+++ b/drivers/clk/qcom/Makefile
@@ -36,6 +36,7 @@ obj-$(CONFIG_MSM_GCC_8998) += gcc-msm8998.o
 obj-$(CONFIG_MSM_MMCC_8960) += mmcc-msm8960.o
 obj-$(CONFIG_MSM_MMCC_8974) += mmcc-msm8974.o
 obj-$(CONFIG_MSM_MMCC_8996) += mmcc-msm8996.o
+obj-$(CONFIG_MSM_MMCC_8996) += mmcc-msm8998.o
 obj-$(CONFIG_QCOM_A53PLL) += a53-pll.o
 obj-$(CONFIG_QCOM_CLK_APCS_MSM8916) += apcs-msm8916.o
 obj-$(CONFIG_QCOM_CLK_RPM) += clk-rpm.o
diff --git a/drivers/clk/qcom/mmcc-msm8998.c b/drivers/clk/qcom/mmcc-msm8998.c
new file mode 100644
index 000..30fd5e17
--- /dev/null
+++ b/drivers/clk/qcom/mmcc-msm8998.c
@@ -0,0 +1,2915 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2019, The Linux Foundation. All rights reserved.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "common.h"
+#include "clk-regmap.h"
+#include "clk-regmap-divider.h"
+#include "clk-alpha-pll.h"
+#include "clk-rcg.h"
+#include "clk-branch.h"
+#include "reset.h"
+#include "gdsc.h"
+
+enum {
+   P_XO,
+   P_GPLL0,
+   P_GPLL0_DIV,
+   P_MMPLL0_OUT_EVEN,
+   P_MMPLL1_OUT_EVEN,
+   P_MMPLL3_OUT_EVEN,
+   P_MMPLL4_OUT_EVEN,
+   P_MMPLL5_OUT_EVEN,
+   P_MMPLL6_OUT_EVEN,
+   P_MMPLL7_OUT_EVEN,
+   P_MMPLL10_OUT_EVEN,
+   P_DSI0PLL,
+   P_DSI1PLL,
+   P_DSI0PLL_BYTE,
+   P_DSI1PLL_BYTE,
+   P_HDMIPLL,
+   P_DPVCO,
+   P_DPLINK,
+   P_CORE_BI_PLL_TEST_SE,
+};
+
+static struct clk_fixed_factor gpll0_div = {
+   .mult = 1,
+   .div = 2,
+   .hw.init = &(struct clk_init_data){
+   .name = "mmss_gpll0_div",
+   .parent_data = &(const struct clk_parent_data){
+   .fw_name = "gpll0",
+   .name = "gpll0"
+   },
+   .num_parents = 1,
+   .ops = _fixed_factor_ops,
+   },
+};
+
+static const struct clk_div_table post_div_table_fabia_even[] = {
+   { 0x0, 1 },
+   { 0x1, 2 },
+   { 0x3, 4 },
+   { 0x7, 8 },
+   { }
+};
+
+static struct clk_alpha_pll mmpll0 = {
+   .offset = 0xc000,
+   .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_FABIA],
+   .clkr = {
+   .enable_reg = 0x1e0,
+   .enable_mask = BIT(0),
+   .hw.init = &(struct clk_init_data){
+   .name = "mmpll0",
+   .parent_data = &(const struct clk_parent_data){
+   .fw_name = "xo",
+   .name = "xo"
+   },
+   .num_parents = 1,
+   .ops = _alpha_pll_fixed_fabia_ops,
+   },
+   },
+};
+
+static struct clk_alpha_pll_postdiv mmpll0_out_even = {
+   .offset = 0xc000,
+   .post_div_shift = 8,
+   .post_div_table = post_div_table_fabia_even,
+   .num_post_div = ARRAY_SIZE(post_div_table_fabia_even),
+   .width = 4,
+   .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_FABIA],
+   .clkr.hw.init = &(struct clk_init_data){
+   .name = "mmpll0_out_even",
+   .parent_hws = (const struct clk_hw *[]){  },
+   .num_parents = 1,
+   .ops = _alpha_pll_postdiv_fabia_ops,
+   },
+};
+
+static struct clk_alpha_pll mmpll1 = {
+   .offset = 0xc050,
+   .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_FABIA],
+   .clkr = {
+   .enable_reg = 0x1e0,
+   .enable_mask = BIT(1),
+   .hw.init = &(struct clk_init_data){
+   .name = "mmpll1",
+   

[PATCH v3 4/6] dt-bindings: clock: Add support for the MSM8998 mmcc

2019-04-30 Thread Jeffrey Hugo
Document the multimedia clock controller found on MSM8998.

Signed-off-by: Jeffrey Hugo 
Reviewed-by: Rob Herring 
---
 .../devicetree/bindings/clock/qcom,mmcc.txt|  21 +++
 include/dt-bindings/clock/qcom,mmcc-msm8998.h  | 210 +
 2 files changed, 231 insertions(+)
 create mode 100644 include/dt-bindings/clock/qcom,mmcc-msm8998.h

diff --git a/Documentation/devicetree/bindings/clock/qcom,mmcc.txt 
b/Documentation/devicetree/bindings/clock/qcom,mmcc.txt
index 8b0f784..a92f3cb 100644
--- a/Documentation/devicetree/bindings/clock/qcom,mmcc.txt
+++ b/Documentation/devicetree/bindings/clock/qcom,mmcc.txt
@@ -10,11 +10,32 @@ Required properties :
"qcom,mmcc-msm8960"
"qcom,mmcc-msm8974"
"qcom,mmcc-msm8996"
+   "qcom,mmcc-msm8998"
 
 - reg : shall contain base register location and length
 - #clock-cells : shall contain 1
 - #reset-cells : shall contain 1
 
+For MSM8998 only:
+   - clocks: a list of phandles and clock-specifier pairs,
+ one for each entry in clock-names.
+   - clock-names: "xo" for the xo clock.
+  "gpll0" for the global pll 0 clock.
+  "dsi0dsi" for the dsi0 pll dsi clock (required if dsi is
+   enabled, optional otherwise).
+  "dsi0byte" for the dsi0 pll byte clock (required if dsi
+   is enabled, optional otherwise).
+  "dsi1dsi" for the dsi1 pll dsi clock (required if dsi is
+   enabled, optional otherwise).
+  "dsi1byte" for the dsi1 pll byte clock (required if dsi
+   is enabled, optional otherwise).
+  "hdmipll" for the hdmi pll clock (required if hdmi is
+   enabled, optional otherwise).
+  "dpvco" for the displayport pll vco clock (required if
+   dp is enabled, optional otherwise).
+  "dplink" for the displayport pll link clock (required if
+   dp is enabled, optional otherwise).
+
 Optional properties :
 - #power-domain-cells : shall contain 1
 
diff --git a/include/dt-bindings/clock/qcom,mmcc-msm8998.h 
b/include/dt-bindings/clock/qcom,mmcc-msm8998.h
new file mode 100644
index 000..ecbafdb
--- /dev/null
+++ b/include/dt-bindings/clock/qcom,mmcc-msm8998.h
@@ -0,0 +1,210 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2019, The Linux Foundation. All rights reserved.
+ */
+
+#ifndef _DT_BINDINGS_CLK_MSM_MMCC_8998_H
+#define _DT_BINDINGS_CLK_MSM_MMCC_8998_H
+
+#define MMPLL0 0
+#define MMPLL0_OUT_EVEN1
+#define MMPLL1 2
+#define MMPLL1_OUT_EVEN3
+#define MMPLL3 4
+#define MMPLL3_OUT_EVEN5
+#define MMPLL4 6
+#define MMPLL4_OUT_EVEN7
+#define MMPLL5 8
+#define MMPLL5_OUT_EVEN9
+#define MMPLL6 10
+#define MMPLL6_OUT_EVEN11
+#define MMPLL7 12
+#define MMPLL7_OUT_EVEN13
+#define MMPLL1014
+#define MMPLL10_OUT_EVEN   15
+#define BYTE0_CLK_SRC  16
+#define BYTE1_CLK_SRC  17
+#define CCI_CLK_SRC18
+#define CPP_CLK_SRC19
+#define CSI0_CLK_SRC   20
+#define CSI1_CLK_SRC   21
+#define CSI2_CLK_SRC   22
+#define CSI3_CLK_SRC   23
+#define CSIPHY_CLK_SRC 24
+#define CSI0PHYTIMER_CLK_SRC   25
+#define CSI1PHYTIMER_CLK_SRC   26
+#define CSI2PHYTIMER_CLK_SRC   27
+#define DP_AUX_CLK_SRC 28
+#define DP_CRYPTO_CLK_SRC  29
+#define DP_LINK_CLK_SRC30
+#define DP_PIXEL_CLK_SRC   31
+#define ESC0_CLK_SRC   32
+#define ESC1_CLK_SRC   33
+#define EXTPCLK_CLK_SRC34
+#define FD_CORE_CLK_SRC35
+#define HDMI_CLK_SRC   

Re: Strange issues with epoll since 5.0

2019-04-30 Thread Eric Wong
Eric Wong  wrote:
> Deepa Dinamani  wrote:
> > I'm not sure what the hang in the userspace is about. Is it because
> > the syscall did not return an error or the particular signal was
> > blocked etc.
> 
> Uh, ok; that's less comforting.

Nevermind, I think I understand everything, now.  epoll_pwait
never set errno without our patch.

cmogstored does this in notify.c:

/* wait_intr calls epoll_pwait: */
mfd = mog_idleq_wait_intr(mog_notify_queue, timeout);
if (mfd)
notify_queue_step(mfd);
else if (errno == EINTR) /* EINTR fails to be noticed */
note_run();


[PATCH v3 2/6] arm64: dts: msm8998: Add xo clock to gcc node

2019-04-30 Thread Jeffrey Hugo
GCC is a consumer of the xo clock.  Add a reference to the clock supplier
to the gcc node.

Signed-off-by: Jeffrey Hugo 
---
 arch/arm64/boot/dts/qcom/msm8998.dtsi | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/msm8998.dtsi 
b/arch/arm64/boot/dts/qcom/msm8998.dtsi
index 574be78..9c88801 100644
--- a/arch/arm64/boot/dts/qcom/msm8998.dtsi
+++ b/arch/arm64/boot/dts/qcom/msm8998.dtsi
@@ -709,6 +709,8 @@
#reset-cells = <1>;
#power-domain-cells = <1>;
reg = <0x10 0xb>;
+   clock-names = "xo";
+   clocks = < RPM_SMD_XO_CLK_SRC>;
};
 
tlmm: pinctrl@340 {
-- 
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH v3 3/6] clk: qcom: smd: Add XO clock for MSM8998

2019-04-30 Thread Jeffrey Hugo
The XO clock generally feeds into other clock controllers as the parent
for a lot of clock generators.

Drop the "fake" XO clock in GCC now that it is redundant can will cause a
namespace conflict.

Signed-off-by: Jeffrey Hugo 
---
 drivers/clk/qcom/clk-smd-rpm.c | 24 
 drivers/clk/qcom/gcc-msm8998.c | 29 -
 2 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/drivers/clk/qcom/clk-smd-rpm.c b/drivers/clk/qcom/clk-smd-rpm.c
index 22dd42a..55a622df 100644
--- a/drivers/clk/qcom/clk-smd-rpm.c
+++ b/drivers/clk/qcom/clk-smd-rpm.c
@@ -68,7 +68,7 @@
}
 
 #define __DEFINE_CLK_SMD_RPM_BRANCH(_platform, _name, _active, type, r_id,\
-   stat_id, r, key)  \
+   stat_id, r, key, ignore_unused) 
  \
static struct clk_smd_rpm _platform##_##_active;  \
static struct clk_smd_rpm _platform##_##_name = { \
.rpm_res_type = (type),   \
@@ -83,6 +83,7 @@
.name = #_name,   \
.parent_names = (const char *[]){ "xo_board" },   \
.num_parents = 1, \
+   .flags = (ignore_unused) ? CLK_IGNORE_UNUSED : 0, \
},\
};\
static struct clk_smd_rpm _platform##_##_active = {   \
@@ -99,6 +100,7 @@
.name = #_active, \
.parent_names = (const char *[]){ "xo_board" },   \
.num_parents = 1, \
+   .flags = (ignore_unused) ? CLK_IGNORE_UNUSED : 0, \
},\
}
 
@@ -108,7 +110,17 @@
 
 #define DEFINE_CLK_SMD_RPM_BRANCH(_platform, _name, _active, type, r_id, r)   \
__DEFINE_CLK_SMD_RPM_BRANCH(_platform, _name, _active, type,  \
-   r_id, 0, r, QCOM_RPM_SMD_KEY_ENABLE)
+   r_id, 0, r, QCOM_RPM_SMD_KEY_ENABLE, false)
+
+/*
+ * Intended for XO clock where we don't want it turned off during late init
+ * if we don't have a consumer by then, but can turn it off later for deep
+ * sleep
+ */
+#define DEFINE_CLK_SMD_RPM_BRANCH_SKIP_UNUSED(_platform, _name, _active, type,\
+ r_id, r)\
+   __DEFINE_CLK_SMD_RPM_BRANCH(_platform, _name, _active, type,  \
+   r_id, 0, r, QCOM_RPM_SMD_KEY_ENABLE, true)
 
 #define DEFINE_CLK_SMD_RPM_QDSS(_platform, _name, _active, type, r_id)   \
__DEFINE_CLK_SMD_RPM(_platform, _name, _active, type, r_id,   \
@@ -117,12 +129,12 @@
 #define DEFINE_CLK_SMD_RPM_XO_BUFFER(_platform, _name, _active, r_id)\
__DEFINE_CLK_SMD_RPM_BRANCH(_platform, _name, _active,\
QCOM_SMD_RPM_CLK_BUF_A, r_id, 0, 1000,\
-   QCOM_RPM_KEY_SOFTWARE_ENABLE)
+   QCOM_RPM_KEY_SOFTWARE_ENABLE, false)
 
 #define DEFINE_CLK_SMD_RPM_XO_BUFFER_PINCTRL(_platform, _name, _active, r_id) \
__DEFINE_CLK_SMD_RPM_BRANCH(_platform, _name, _active,\
QCOM_SMD_RPM_CLK_BUF_A, r_id, 0, 1000,\
-   QCOM_RPM_KEY_PIN_CTRL_CLK_BUFFER_ENABLE_KEY)
+   QCOM_RPM_KEY_PIN_CTRL_CLK_BUFFER_ENABLE_KEY, false)
 
 #define to_clk_smd_rpm(_hw) container_of(_hw, struct clk_smd_rpm, hw)
 
@@ -656,6 +668,8 @@ static int clk_smd_rpm_enable_scaling(struct qcom_smd_rpm 
*rpm)
 };
 
 /* msm8998 */
+DEFINE_CLK_SMD_RPM_BRANCH_SKIP_UNUSED(msm8998, xo, xo_a, QCOM_SMD_RPM_MISC_CLK,
+ 0, 1920);
 DEFINE_CLK_SMD_RPM(msm8998, snoc_clk, snoc_a_clk, QCOM_SMD_RPM_BUS_CLK, 1);
 DEFINE_CLK_SMD_RPM(msm8998, cnoc_clk, cnoc_a_clk, QCOM_SMD_RPM_BUS_CLK, 2);
 DEFINE_CLK_SMD_RPM(msm8998, ce1_clk, ce1_a_clk, QCOM_SMD_RPM_CE_CLK, 0);
@@ -678,6 +692,8 @@ static int clk_smd_rpm_enable_scaling(struct qcom_smd_rpm 
*rpm)
 DEFINE_CLK_SMD_RPM_XO_BUFFER(msm8998, rf_clk3, rf_clk3_a, 6);
 DEFINE_CLK_SMD_RPM_XO_BUFFER_PINCTRL(msm8998, rf_clk3_pin, rf_clk3_a_pin, 6);
 static struct clk_smd_rpm *msm8998_clks[] = {
+   [RPM_SMD_XO_CLK_SRC] = _xo,
+   [RPM_SMD_XO_A_CLK_SRC] = _xo_a,
[RPM_SMD_SNOC_CLK] = _snoc_clk,
[RPM_SMD_SNOC_A_CLK] = _snoc_a_clk,
[RPM_SMD_CNOC_CLK] = _cnoc_clk,
diff --git a/drivers/clk/qcom/gcc-msm8998.c b/drivers/clk/qcom/gcc-msm8998.c
index 0336882..47c3163 100644
--- a/drivers/clk/qcom/gcc-msm8998.c
+++ b/drivers/clk/qcom/gcc-msm8998.c
@@ 

[PATCH v3 1/6] dt-bindings: clock: Document external clocks for MSM8998 gcc

2019-04-30 Thread Jeffrey Hugo
The global clock controller on MSM8998 can consume a number of external
clocks.  Document them.

Signed-off-by: Jeffrey Hugo 
---
 Documentation/devicetree/bindings/clock/qcom,gcc.txt | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/Documentation/devicetree/bindings/clock/qcom,gcc.txt 
b/Documentation/devicetree/bindings/clock/qcom,gcc.txt
index 8661c3c..7d45323 100644
--- a/Documentation/devicetree/bindings/clock/qcom,gcc.txt
+++ b/Documentation/devicetree/bindings/clock/qcom,gcc.txt
@@ -28,6 +28,16 @@ Required properties :
 - #clock-cells : shall contain 1
 - #reset-cells : shall contain 1
 
+For MSM8998 only:
+   - clocks: a list of phandles and clock-specifier pairs,
+ one for each entry in clock-names.
+   - clock-names: "xo" (required)
+  "usb3_pipe" (optional)
+  "ufs_rx_symbol0" (optional)
+  "ufs_rx_symbol1" (optional)
+  "ufs_tx_symbol0" (optional)
+  "pcie0_pipe" (optional)
+
 Optional properties :
 - #power-domain-cells : shall contain 1
 - Qualcomm TSENS (thermal sensor device) on some devices can
-- 
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH v3 0/6] MSM8998 Multimedia Clock Controller

2019-04-30 Thread Jeffrey Hugo
The multimedia clock controller (mmcc) is the main clock controller for
the multimedia subsystem and is required to enable things like display and
camera.

v3:
-Rebase onto linux-next to get the final version of the clk parent rewrite
series
-Moved the bindings header to the bindings patch per Rob
-Made xo manditory for GCC to work around the lack of clk orphan probe defer
to avoid the uart console glitch

v2:
-Rebased on the "Rewrite clk parent handling" series and updated to the clk init
mechanisms introduced there.
-Marked XO clk as CLK_IGNORE_UNUSED to avoid the concern about the XO going away
"incorrectly" during late init
-Corrected the name of the XO clock to "xo"
-Dropped the fake XO clock in GCC to prevent a namespace conflict
-Fully enumerated the external clocks (DSI PLLs, etc) in the DT binding
-Cleaned up the weird newlines in the added DT node
-Added DT header file to msm8998 DT for future clients

Jeffrey Hugo (6):
  dt-bindings: clock: Document external clocks for MSM8998 gcc
  arm64: dts: msm8998: Add xo clock to gcc node
  clk: qcom: smd: Add XO clock for MSM8998
  dt-bindings: clock: Add support for the MSM8998 mmcc
  clk: qcom: Add MSM8998 Multimedia Clock Controller (MMCC) driver
  arm64: dts: qcom: msm8998: Add mmcc node

 .../devicetree/bindings/clock/qcom,gcc.txt|   10 +
 .../devicetree/bindings/clock/qcom,mmcc.txt   |   21 +
 arch/arm64/boot/dts/qcom/msm8998.dtsi |   16 +
 drivers/clk/qcom/Kconfig  |9 +
 drivers/clk/qcom/Makefile |1 +
 drivers/clk/qcom/clk-smd-rpm.c|   24 +-
 drivers/clk/qcom/gcc-msm8998.c|   29 +-
 drivers/clk/qcom/mmcc-msm8998.c   | 2915 +
 include/dt-bindings/clock/qcom,mmcc-msm8998.h |  210 ++
 9 files changed, 3214 insertions(+), 21 deletions(-)
 create mode 100644 drivers/clk/qcom/mmcc-msm8998.c
 create mode 100644 include/dt-bindings/clock/qcom,mmcc-msm8998.h

-- 
2.17.1



Re: Strange issues with epoll since 5.0

2019-04-30 Thread Eric Wong
Deepa Dinamani  wrote:
> I was also not able to reproduce this.
> Arnd and I were talking about this today morning. Here is something
> Arnd noticed:
> 
> If there was a signal after do_epoll_wait(), we never were not
> entering the if (err = -EINTR) at all before.

I'm not sure which `if' statement you're talking about, but ok...

> But, now we do.
> We could try with the below patch:

Wasn't close to applying or being buildable, but I put a
working version together (below).

epoll_pwait wakes up as expected, now :>

> If this works that means we know what is busted.

OK, good to know...

> I'm not sure what the hang in the userspace is about. Is it because
> the syscall did not return an error or the particular signal was
> blocked etc.

Uh, ok; that's less comforting.

> There are also a few timing differences also. But, can we try this first?

Anyways, the following patch works and builds cleanly for me
(didn't test AIO, but everything else seems good)

Thanks!

-8<---
Subject: [PATCH] test fix from Deepa

TBD
---
 fs/aio.c   |  8 
 fs/eventpoll.c |  4 ++--
 fs/select.c| 12 ++--
 include/linux/signal.h |  2 +-
 kernel/signal.c|  6 --
 5 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/fs/aio.c b/fs/aio.c
index 3d9669d011b9..d54513ca11b6 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -2146,7 +2146,7 @@ SYSCALL_DEFINE6(io_pgetevents,
return ret;
 
ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ?  : NULL);
-   restore_user_sigmask(ksig.sigmask, );
+   restore_user_sigmask(ksig.sigmask, , -1);
if (signal_pending(current) && !ret)
ret = -ERESTARTNOHAND;
 
@@ -2180,7 +2180,7 @@ SYSCALL_DEFINE6(io_pgetevents_time32,
return ret;
 
ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ?  : NULL);
-   restore_user_sigmask(ksig.sigmask, );
+   restore_user_sigmask(ksig.sigmask, , -1);
if (signal_pending(current) && !ret)
ret = -ERESTARTNOHAND;
 
@@ -2244,7 +2244,7 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents,
return ret;
 
ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ?  : NULL);
-   restore_user_sigmask(ksig.sigmask, );
+   restore_user_sigmask(ksig.sigmask, , -1);
if (signal_pending(current) && !ret)
ret = -ERESTARTNOHAND;
 
@@ -2277,7 +2277,7 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents_time64,
return ret;
 
ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ?  : NULL);
-   restore_user_sigmask(ksig.sigmask, );
+   restore_user_sigmask(ksig.sigmask, , -1);
if (signal_pending(current) && !ret)
ret = -ERESTARTNOHAND;
 
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index a5d219d920e7..bd84ec54a8fb 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -2247,7 +2247,7 @@ SYSCALL_DEFINE6(epoll_pwait, int, epfd, struct 
epoll_event __user *, events,
 
error = do_epoll_wait(epfd, events, maxevents, timeout);
 
-   restore_user_sigmask(sigmask, );
+   restore_user_sigmask(sigmask, , error == -EINTR);
 
return error;
 }
@@ -2272,7 +2272,7 @@ COMPAT_SYSCALL_DEFINE6(epoll_pwait, int, epfd,
 
err = do_epoll_wait(epfd, events, maxevents, timeout);
 
-   restore_user_sigmask(sigmask, );
+   restore_user_sigmask(sigmask, , err == -EINTR);
 
return err;
 }
diff --git a/fs/select.c b/fs/select.c
index d0f35dbc0e8f..04720e5856ed 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -760,7 +760,7 @@ static long do_pselect(int n, fd_set __user *inp, fd_set 
__user *outp,
ret = core_sys_select(n, inp, outp, exp, to);
ret = poll_select_copy_remaining(_time, tsp, type, ret);
 
-   restore_user_sigmask(sigmask, );
+   restore_user_sigmask(sigmask, , -1);
 
return ret;
 }
@@ -1106,7 +1106,7 @@ SYSCALL_DEFINE5(ppoll, struct pollfd __user *, ufds, 
unsigned int, nfds,
 
ret = do_sys_poll(ufds, nfds, to);
 
-   restore_user_sigmask(sigmask, );
+   restore_user_sigmask(sigmask, , -1);
 
/* We can restart this syscall, usually */
if (ret == -EINTR)
@@ -1142,7 +1142,7 @@ SYSCALL_DEFINE5(ppoll_time32, struct pollfd __user *, 
ufds, unsigned int, nfds,
 
ret = do_sys_poll(ufds, nfds, to);
 
-   restore_user_sigmask(sigmask, );
+   restore_user_sigmask(sigmask, , -1);
 
/* We can restart this syscall, usually */
if (ret == -EINTR)
@@ -1352,7 +1352,7 @@ static long do_compat_pselect(int n, compat_ulong_t 
__user *inp,
ret = compat_core_sys_select(n, inp, outp, exp, to);
ret = poll_select_copy_remaining(_time, tsp, type, ret);
 
-   restore_user_sigmask(sigmask, );
+   restore_user_sigmask(sigmask, , -1);
 
return ret;
 }
@@ -1425,7 +1425,7 @@ COMPAT_SYSCALL_DEFINE5(ppoll, struct pollfd __user *, 
ufds,
 
ret = do_sys_poll(ufds, nfds, to);
 
-   

Re: [PATCH] Revert "PCI/LINK: Report degraded links via link bandwidth notification"

2019-04-30 Thread Bjorn Helgaas
On Tue, Apr 30, 2019 at 12:18:13PM -0600, Keith Busch wrote:
> On Tue, Apr 30, 2019 at 12:05:09PM -0600, Keith Busch wrote:
> > On Tue, Apr 30, 2019 at 11:11:51AM -0500, Bjorn Helgaas wrote:
> > > > I'm not convinced a revert is the best call.
> > > 
> > > I have very limited options at this stage of the release, but I'd be
> > > glad to hear suggestions.  My concern is that if we release v5.1
> > > as-is, we'll spend a lot of energy on those false positives.
> > 
> > May be too late now if the revert is queued up, but I think this feature
> > should have been a default 'false' Kconfig bool rather than always on.

Since this feature currently just adds a message in dmesg, which we
don't really consider a stable API, I think a Kconfig switch is a
reasonable option.

If you send me a signed-off-by for the following patch, I can apply it:

commit 302b77157e66
Author: Keith Busch 
Date:   Tue Apr 30 12:18:13 2019 -0600

PCI/LINK: Add Kconfig option (default off)

e8303bb7a75c ("PCI/LINK: Report degraded links via link bandwidth
notification") added dmesg logging whenever a link changes speed or width
to a state that is considered degraded.  Unfortunately, it cannot
differentiate signal integrity-related link changes from those
intentionally initiated by an endpoint driver, including drivers that may
live in userspace or VMs when making use of vfio-pci.  Some GPU drivers
actively manage the link state to save power, which generates a stream of
messages like this:

  vfio-pci :07:00.0: 32.000 Gb/s available PCIe bandwidth, limited by 
2.5 GT/s x16 link at :00:02.0 (capable of 64.000 Gb/s with 5 GT/s x16 link)

Since we can't distinguish the intentional changes from the signal
integrity issues, leave the reporting turned off by default.  Add a Kconfig
option to turn it on if desired.

Fixes: e8303bb7a75c ("PCI/LINK: Report degraded links via link bandwidth
notification")

diff --git a/drivers/pci/pcie/Kconfig b/drivers/pci/pcie/Kconfig
index 5cbdbca904ac..4a094f0d2856 100644
--- a/drivers/pci/pcie/Kconfig
+++ b/drivers/pci/pcie/Kconfig
@@ -142,3 +142,12 @@ config PCIE_PTM
 
  This is only useful if you have devices that support PTM, but it
  is safe to enable even if you don't.
+
+config PCIE_BW
+   bool "PCI Express Bandwidth Change Notification"
+   default n
+   depends on PCIEPORTBUS
+   help
+ This enables PCI Express Bandwidth Change Notification.  If
+ you know link width or rate changes occur only to correct
+ unreliable links, you may answer Y.
diff --git a/drivers/pci/pcie/Makefile b/drivers/pci/pcie/Makefile
index f1d7bc1e5efa..d356a5bdb158 100644
--- a/drivers/pci/pcie/Makefile
+++ b/drivers/pci/pcie/Makefile
@@ -3,7 +3,6 @@
 # Makefile for PCI Express features and port driver
 
 pcieportdrv-y  := portdrv_core.o portdrv_pci.o err.o
-pcieportdrv-y  += bw_notification.o
 
 obj-$(CONFIG_PCIEPORTBUS)  += pcieportdrv.o
 
@@ -13,3 +12,4 @@ obj-$(CONFIG_PCIEAER_INJECT)  += aer_inject.o
 obj-$(CONFIG_PCIE_PME) += pme.o
 obj-$(CONFIG_PCIE_DPC) += dpc.o
 obj-$(CONFIG_PCIE_PTM) += ptm.o
+obj-$(CONFIG_PCIE_BW)  := bw_notification.o


Re: [RFC][PATCH v2] ftrace/x86: Emulate call function while updating in breakpoint handler

2019-04-30 Thread Linus Torvalds
On Tue, Apr 30, 2019 at 6:35 PM Steven Rostedt  wrote:
>
>
> Probably easier to move it from inline asm to ftrace_X.S and use the
> lockdep TRACE_ON/OFF macros.

Yeah, that should clean up the percpu stuff too since we have helper
macros for it for *.S files anyway.

I only did the asm() in C because it made the "look, something like
this" patch simpler to test (and it made it easy to check the
generated asm file). Not because it was a good idea ;)

 Linus


Re: linux-next: Signed-off-by missing for commit in the ext4 tree

2019-04-30 Thread Theodore Ts'o
On Wed, May 01, 2019 at 08:06:07AM +1000, Stephen Rothwell wrote:
> Hi all,
> 
> Commit
> 
>   60ae11086c04 ("unicode: update unicode database unicode version 12.1.0")
> 
> is missing a Signed-off-by from its committer.

Oops, thanks for pointing this out.  Will fix.

- Ted


Re: [RFC][PATCHSET] sorting out RCU-delayed stuff in ->destroy_inode()

2019-04-30 Thread Al Viro
On Tue, Apr 30, 2019 at 05:00:43AM +0100, Al Viro wrote:

> Where would you put that synchronize_rcu()?  Doing that before ->put_super()
> is too early - inode references might be dropped in there.  OTOH, doing
> that after that point means that while struct super_block itself will be
> there, any number of data structures hanging from it might be not.
> 
> So we are still very limited in what we can do inside ->free_inode()
> instance *and* we get bunch of synchronize_rcu() for no good reason.
> 
> Note that for normal lockless accesses (lockless ->d_revalidate(), ->d_hash(),
> etc.) we are just fine with having struct super_block freeing RCU-delayed
> (along with any data structures we might need) - the superblock had
> been seen at some point after we'd taken rcu_read_lock(), so its
> freeing won't happen until we drop it.  So we don't need synchronize_rcu()
> for that.
> 
> Here the problem is that we are dealing with another RCU callback;
> synchronize_rcu() would be needed for it, but it will only protect that
> intermediate dereference of ->i_sb; any rcu-delayed stuff scheduled
> from inside ->put_super() would not be ordered wrt ->free_inode().
> And if we are doing that just for the sake of that one dereference,
> we might as well do it before scheduling i_callback().
> 
> PS: we *are* guaranteed that module will still be there 
> (unregister_filesystem()
> does synchronize_rcu() and rcu_barrier() is done before kmem_cache_destroy()
> in assorted exit_foo_fs()).

After playing with that for a while, I think that adding barriers on
superblock freeing (or shutdown) should wait, assuming we do them at
all.

Right now no ->free_inode() instances look at superblock or anything
associated with it; moreover, there's no good candidate code that
could be moved there and would benefit from such access.  So we
don't have any material to see what could be useful to protect.

Access to ->i_sb->s_op->free_inode itself is the only exception and
moving that to before the rcu delay is both less invasive and a _lot_
more robust than playing with synchronize_rcu().  We can do that
without growing struct inode or storing it for long periods -
->i_fop is only accessed for struct inode with positive refcount,
so we can put that into anon union with the ->free_inode value,
setting it just before we schedule execution of i_callback()
(and before the direct call of the same in alloc_inode() failure
exit).

IMO the following is the sane incremental for the coming window purposes;
if we get a convincing case for ->free_inode() doing something that could
benefit from being ordered wrt parts of fs shutdown, we can always deal
with synchronize_rcu() later.  Existing instances will be fine, and IMO
separating RCU-delayed parts of inode destruction from the rest is
worthwhile on its own.

Objections?

diff --git a/Documentation/filesystems/porting 
b/Documentation/filesystems/porting
index 9d80f9e0855e..b8d3ddd8b8db 100644
--- a/Documentation/filesystems/porting
+++ b/Documentation/filesystems/porting
@@ -655,3 +655,11 @@ in your dentry operations instead.
* if ->free_inode() is non-NULL, it gets scheduled by call_rcu()
* combination of NULL ->destroy_inode and NULL ->free_inode is
  treated as NULL/free_inode_nonrcu, to preserve the 
compatibility.
+
+   Note that the callback (be it via ->free_inode() or explicit call_rcu()
+   in ->destroy_inode()) is *NOT* ordered wrt superblock destruction;
+   as the matter of fact, the superblock and all associated structures
+   might be already gone.  The filesystem driver is guaranteed to be still
+   there, but that's it.  Freeing memory in the callback is fine; doing
+   more than that is possible, but requires a lot of care and is best
+   avoided.
diff --git a/fs/inode.c b/fs/inode.c
index fb45590d284e..627e1766503a 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -211,8 +211,8 @@ EXPORT_SYMBOL(free_inode_nonrcu);
 static void i_callback(struct rcu_head *head)
 {
struct inode *inode = container_of(head, struct inode, i_rcu);
-   if (inode->i_sb->s_op->free_inode)
-   inode->i_sb->s_op->free_inode(inode);
+   if (inode->free_inode)
+   inode->free_inode(inode);
else
free_inode_nonrcu(inode);
 }
@@ -236,6 +236,7 @@ static struct inode *alloc_inode(struct super_block *sb)
if (!ops->free_inode)
return NULL;
}
+   inode->free_inode = ops->free_inode;
i_callback(>i_rcu);
return NULL;
}
@@ -276,6 +277,7 @@ static void destroy_inode(struct inode *inode)
if (!ops->free_inode)
return;
}
+   inode->free_inode = ops->free_inode;
call_rcu(>i_rcu, i_callback);
 }
 
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 2e9b9f87caca..92732286b748 100644
--- a/include/linux/fs.h

Re: [RFC][PATCH v2] ftrace/x86: Emulate call function while updating in breakpoint handler

2019-04-30 Thread Steven Rostedt
On Tue, 30 Apr 2019 17:53:34 -0400
Steven Rostedt  wrote:

> + if (ftrace_location(ip)) {
> + /* A breakpoint at the beginning of the function was hit */
> + if (in_nmi()) {
> + /* NMIs have their own trampoline */
> + this_cpu_write(ftrace_bp_call_nmi_return, (void *)ip + 
> MCOUNT_INSN_SIZE);
> + regs->ip = (unsigned long) ftrace_emulate_call_nmi;
> + return 1;
> + }
> + this_cpu_write(ftrace_bp_call_return, (void *)ip + 
> MCOUNT_INSN_SIZE);
> + if (regs->flags & X86_EFLAGS_IF) {
> + regs->flags &= ~X86_EFLAGS_IF;
> + regs->ip = (unsigned long) ftrace_emulate_call_irqoff;
> + /* Tell lockdep here we are enabling interrupts */
> + trace_hardirqs_on();

This isn't good enough. The return from interrupt does call lockdep
saying interrupts are disabled. Need to add the lockdep tracking in the
asm as well.

Probably easier to move it from inline asm to ftrace_X.S and use the
lockdep TRACE_ON/OFF macros.

-- Steve




> + } else {
> + regs->ip = (unsigned long) ftrace_emulate_call_irqon;
> + }
> + return 1;
> + } else if (is_ftrace_caller(ip)) {
> + /* An ftrace trampoline is being updated */
> + if (!ftrace_update_func_call) {
> + /* If it's a jump, just need to skip it */
> + regs->ip += MCOUNT_INSN_SIZE -1;
> + return 1;
> + }
> + if (in_nmi()) {
> + /* NMIs have their own trampoline */
> + this_cpu_write(ftrace_bp_call_nmi_return, (void *)ip + 
> MCOUNT_INSN_SIZE);
> + regs->ip = (unsigned long) 
> ftrace_emulate_call_update_nmi;
> + return 1;
> + }
> + this_cpu_write(ftrace_bp_call_return, (void *)ip + 
> MCOUNT_INSN_SIZE);
> + if (regs->flags & X86_EFLAGS_IF) {
> + regs->flags &= ~X86_EFLAGS_IF;
> + regs->ip = (unsigned long) 
> ftrace_emulate_call_update_irqoff;
> + trace_hardirqs_on();
> + } else {
> + regs->ip = (unsigned long) 
> ftrace_emulate_call_update_irqon;
> + }
> + return 1;
> + }
>  
> - return 1;
> + return 0;
>  }


[PATCH] regulator: hi6xxx: Switch to SPDX identifier

2019-04-30 Thread Axel Lin
Convert HiSilicon hi6xxx PMIC drivers to SPDX identifier.

Signed-off-by: Axel Lin 
---
 drivers/regulator/hi6421-regulator.c | 24 +-
 drivers/regulator/hi6421v530-regulator.c | 26 ++--
 drivers/regulator/hi655x-regulator.c | 22 
 3 files changed, 30 insertions(+), 42 deletions(-)

diff --git a/drivers/regulator/hi6421-regulator.c 
b/drivers/regulator/hi6421-regulator.c
index 6c7ea4eb4bb0..5ac3d7c29725 100644
--- a/drivers/regulator/hi6421-regulator.c
+++ b/drivers/regulator/hi6421-regulator.c
@@ -1,17 +1,13 @@
-/*
- * Device driver for regulators in Hi6421 IC
- *
- * Copyright (c) <2011-2014> HiSilicon Technologies Co., Ltd.
- *  http://www.hisilicon.com
- * Copyright (c) <2013-2014> Linaro Ltd.
- *  http://www.linaro.org
- *
- * Author: Guodong Xu 
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
+// SPDX-License-Identifier: GPL-2.0
+//
+// Device driver for regulators in Hi6421 IC
+//
+// Copyright (c) <2011-2014> HiSilicon Technologies Co., Ltd.
+//  http://www.hisilicon.com
+// Copyright (c) <2013-2014> Linaro Ltd.
+//  http://www.linaro.org
+//
+// Author: Guodong Xu 
 
 #include 
 #include 
diff --git a/drivers/regulator/hi6421v530-regulator.c 
b/drivers/regulator/hi6421v530-regulator.c
index c09bc71538a5..06ae65199afd 100644
--- a/drivers/regulator/hi6421v530-regulator.c
+++ b/drivers/regulator/hi6421v530-regulator.c
@@ -1,18 +1,14 @@
-/*
- * Device driver for regulators in Hi6421V530 IC
- *
- * Copyright (c) <2017> HiSilicon Technologies Co., Ltd.
- *  http://www.hisilicon.com
- * Copyright (c) <2017> Linaro Ltd.
- *  http://www.linaro.org
- *
- * Author: Wang Xiaoyin 
- * Guodong Xu 
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
+// SPDX-License-Identifier: GPL-2.0
+//
+// Device driver for regulators in Hi6421V530 IC
+//
+// Copyright (c) <2017> HiSilicon Technologies Co., Ltd.
+//  http://www.hisilicon.com
+// Copyright (c) <2017> Linaro Ltd.
+//  http://www.linaro.org
+//
+// Author: Wang Xiaoyin 
+// Guodong Xu 
 
 #include 
 #include 
diff --git a/drivers/regulator/hi655x-regulator.c 
b/drivers/regulator/hi655x-regulator.c
index 6f6635daa026..ac2ee2030211 100644
--- a/drivers/regulator/hi655x-regulator.c
+++ b/drivers/regulator/hi655x-regulator.c
@@ -1,16 +1,12 @@
-/*
- * Device driver for regulators in Hi655x IC
- *
- * Copyright (c) 2016 Hisilicon.
- *
- * Authors:
- * Chen Feng 
- * Fei  Wang 
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
+// SPDX-License-Identifier: GPL-2.0
+//
+// Device driver for regulators in Hi655x IC
+//
+// Copyright (c) 2016 Hisilicon.
+//
+// Authors:
+// Chen Feng 
+// Fei  Wang 
 
 #include 
 #include 
-- 
2.17.1



[PATCH 4/7] lib: make bitmap_parse_user a wrapper on bitmap_parse

2019-04-30 Thread Yury Norov
Currently we parse user data byte after byte which leads to
overcomplicating of parsing algorithm. There are no performance
critical users of bitmap_parse_user(), and so we can duplicate
user data to kernel buffer and simply call bitmap_parselist().
This rework lets us unify and simplify bitmap_parse() and
bitmap_parse_user(), which is done in the following patch.

Signed-off-by: Yury Norov 
---
 lib/bitmap.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/lib/bitmap.c b/lib/bitmap.c
index f235434df87b..300732031fad 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -434,22 +434,22 @@ EXPORT_SYMBOL(__bitmap_parse);
  *then it must be terminated with a \0.
  * @maskp: pointer to bitmap array that will contain result.
  * @nmaskbits: size of bitmap, in bits.
- *
- * Wrapper for __bitmap_parse(), providing it with user buffer.
- *
- * We cannot have this as an inline function in bitmap.h because it needs
- * linux/uaccess.h to get the access_ok() declaration and this causes
- * cyclic dependencies.
  */
 int bitmap_parse_user(const char __user *ubuf,
unsigned int ulen, unsigned long *maskp,
int nmaskbits)
 {
-   if (!access_ok(ubuf, ulen))
-   return -EFAULT;
-   return __bitmap_parse((const char __force *)ubuf,
-   ulen, 1, maskp, nmaskbits);
+   char *buf;
+   int ret;
 
+   buf = memdup_user_nul(ubuf, ulen);
+   if (IS_ERR(buf))
+   return PTR_ERR(buf);
+
+   ret = bitmap_parse(buf, ulen, maskp, nmaskbits);
+
+   kfree(buf);
+   return ret;
 }
 EXPORT_SYMBOL(bitmap_parse_user);
 
-- 
2.17.1



[PATCH 7/7] cpumask: don't calculate length of the input string

2019-04-30 Thread Yury Norov
New design of inner bitmap_parse() allows to avoid
calculating the size of a null-terminated string.

Signed-off-by: Yury Norov 
---
 include/linux/cpumask.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 21755471b1c3..d55d015edc58 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -633,9 +633,7 @@ static inline int cpumask_parselist_user(const char __user 
*buf, int len,
  */
 static inline int cpumask_parse(const char *buf, struct cpumask *dstp)
 {
-   unsigned int len = strchrnul(buf, '\n') - buf;
-
-   return bitmap_parse(buf, len, cpumask_bits(dstp), nr_cpumask_bits);
+   return bitmap_parse(buf, UINT_MAX, cpumask_bits(dstp), nr_cpumask_bits);
 }
 
 /**
-- 
2.17.1



[PATCH 6/7] lib: new testcases for bitmap_parse{_user}

2019-04-30 Thread Yury Norov
New version of bitmap_parse() is unified with bitmap_parse_list(),
and therefore:
 - weakens rules on whitespaces and commas between hex chunks;
 - in addition to \0 allows using \n as the line ending symbol;
 - allows passing UINT_MAX or any other big number as the length
   of input string instead of actual string length.

The patch covers the cases.

Signed-off-by: Yury Norov 
---
 lib/test_bitmap.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index 731e107d811a..9e6b87895108 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -343,14 +343,22 @@ static const unsigned long parse_test2[] __initconst = {
 };
 
 static const struct test_bitmap_parselist parse_tests[] __initconst = {
+   {0, "", _test[0 * step], 32, 0},
+   {0, " ",_test[0 * step], 32, 0},
{0, "0",_test[0 * step], 32, 0},
+   {0, "0\n",  _test[0 * step], 32, 0},
{0, "1",_test[1 * step], 32, 0},
{0, "deadbeef", _test[2 * step], 32, 0},
{0, "1,0",  _test[3 * step], 33, 0},
+   {0, "deadbeef,\n,0,1",  _test[2 * step], 96, 0},
 
{0, "deadbeef,1,0", _test2[0 * 2 * step], 96, 0},
{0, "baadf00d,deadbeef,1,0",_test2[1 * 2 * step], 128, 0},
{0, "badf00d,deadbeef,1,0", _test2[2 * 2 * step], 124, 0},
+   {0, "badf00d,deadbeef,1,0", _test2[2 * 2 * step], 124, 
NO_LEN},
+   {0, "  badf00d,deadbeef,1,0  ", _test2[2 * 2 * step], 124, 0},
+   {0, " , badf00d,deadbeef,1,0 , ",   _test2[2 * 2 * step], 
124, 0},
+   {0, " , badf00d, ,, ,,deadbeef,1,0 , ", _test2[2 * 2 * step], 
124, 0},
 
{-EINVAL,"goodfood,deadbeef,1,0",   NULL, 128, 0},
{-EOVERFLOW, "3,0", NULL, 33, 0},
-- 
2.17.1



[PATCH 5/7] lib: rework bitmap_parse()

2019-04-30 Thread Yury Norov
bitmap_parse() is ineffective and full of opaque variables and opencoded
parts. It leads to hard understanding and usage of it. This rework
includes:
 - remove bitmap_shift_left() call from the cycle. Now it makes the
   complexity of the algorithm as O(nbits^2). In the suggested approach
   the input string is parsed in reverse direction, so no shifts needed;
 - relax requirement on a single comma and no white spaces between chunks.
   It is considered useful in scripting, and it aligns with
   bitmap_parselist();
 - split bitmap_parse() to small readable helpers;
 - make an explicit calculation of the end of input line at the
   beginning, so users of the bitmap_parse() won't bother doing this.

Signed-off-by: Yury Norov 
---
 include/linux/bitmap.h |   8 +-
 lib/bitmap.c   | 179 -
 2 files changed, 88 insertions(+), 99 deletions(-)

diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index f58e97446abc..c3e84864cc33 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -172,7 +172,7 @@ bitmap_find_next_zero_area(unsigned long *map,
  align_mask, 0);
 }
 
-extern int __bitmap_parse(const char *buf, unsigned int buflen, int is_user,
+extern int bitmap_parse(const char *buf, unsigned int buflen,
unsigned long *dst, int nbits);
 extern int bitmap_parse_user(const char __user *ubuf, unsigned int ulen,
unsigned long *dst, int nbits);
@@ -408,12 +408,6 @@ static inline void bitmap_shift_left(unsigned long *dst, 
const unsigned long *sr
__bitmap_shift_left(dst, src, shift, nbits);
 }
 
-static inline int bitmap_parse(const char *buf, unsigned int buflen,
-   unsigned long *maskp, int nmaskbits)
-{
-   return __bitmap_parse(buf, buflen, 0, maskp, nmaskbits);
-}
-
 /**
  * BITMAP_FROM_U64() - Represent u64 value in the format suitable for bitmap.
  * @n: u64 value
diff --git a/lib/bitmap.c b/lib/bitmap.c
index 300732031fad..ebcf4700ebed 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -335,97 +335,6 @@ EXPORT_SYMBOL(bitmap_find_next_zero_area_off);
  * second version by Paul Jackson, third by Joe Korty.
  */
 
-#define CHUNKSZ32
-#define nbits_to_hold_value(val)   fls(val)
-#define BASEDEC 10 /* fancier cpuset lists input in decimal */
-
-/**
- * __bitmap_parse - convert an ASCII hex string into a bitmap.
- * @buf: pointer to buffer containing string.
- * @buflen: buffer size in bytes.  If string is smaller than this
- *then it must be terminated with a \0.
- * @is_user: location of buffer, 0 indicates kernel space
- * @maskp: pointer to bitmap array that will contain result.
- * @nmaskbits: size of bitmap, in bits.
- *
- * Commas group hex digits into chunks.  Each chunk defines exactly 32
- * bits of the resultant bitmask.  No chunk may specify a value larger
- * than 32 bits (%-EOVERFLOW), and if a chunk specifies a smaller value
- * then leading 0-bits are prepended.  %-EINVAL is returned for illegal
- * characters and for grouping errors such as "1,,5", ",44", "," and "".
- * Leading and trailing whitespace accepted, but not embedded whitespace.
- */
-int __bitmap_parse(const char *buf, unsigned int buflen,
-   int is_user, unsigned long *maskp,
-   int nmaskbits)
-{
-   int c, old_c, totaldigits, ndigits, nchunks, nbits;
-   u32 chunk;
-   const char __user __force *ubuf = (const char __user __force *)buf;
-
-   bitmap_zero(maskp, nmaskbits);
-
-   nchunks = nbits = totaldigits = c = 0;
-   do {
-   chunk = 0;
-   ndigits = totaldigits;
-
-   /* Get the next chunk of the bitmap */
-   while (buflen) {
-   old_c = c;
-   if (is_user) {
-   if (__get_user(c, ubuf++))
-   return -EFAULT;
-   }
-   else
-   c = *buf++;
-   buflen--;
-   if (isspace(c))
-   continue;
-
-   /*
-* If the last character was a space and the current
-* character isn't '\0', we've got embedded whitespace.
-* This is a no-no, so throw an error.
-*/
-   if (totaldigits && c && isspace(old_c))
-   return -EINVAL;
-
-   /* A '\0' or a ',' signal the end of the chunk */
-   if (c == '\0' || c == ',')
-   break;
-
-   if (!isxdigit(c))
-   return -EINVAL;
-
-   /*
-* Make sure there are at least 4 free bits in 'chunk'.
-

[PATCH 0/7] lib: rework bitmap_parse

2019-04-30 Thread Yury Norov
On top of next-20190418.

Similarly to recently revisited bitmap_parselist() [1],
bitmap_parse() is ineffective and overcomplicated.  This
series reworks it, aligns its interface with bitmap_parselist()
and makes usage simpler.

The series also adds a test for the function and fixes usage of it
in cpumask_parse() according to new design - drops the calculating
of length of an input string.

The following users would also consider to drop the length argument,
if possible:
drivers/block/drbd/drbd_main.c:2608
kernel/padata.c:924
net/core/net-sysfs.c:726
net/core/net-sysfs.c:1309
net/core/net-sysfs.c:1391

bitmap_parse() takes the array of numbers to be put into the map in
the BE order which is reversed to the natural LE order for bitmaps.
For example, to construct bitmap containing a bit on the position 42,
we have to put a line '400,0'. Current implementation reads chunk
one by one from the beginning ('400' before '0') and makes bitmap
shift after each successful parse. It makes the complexity of the
whole process as O(n^2). We can do it in reverse direction ('0'
before '400') and avoid shifting, but it requires reverse parsing
helpers.

Tested on arm64 and BE mips.

v1: https://lkml.org/lkml/2019/4/27/597
v2:
 - strnchrnul() signature and description changed, ifdeffery and
   exporting removed;
 - test split for better demonstration of before/after changes;
 - minor naming and formatting issues fixed.

[1] https://lkml.org/lkml/2019/4/16/66

Yury Norov (7):
  lib/string: add strnchrnul()
  bitops: more BITS_TO_* macros
  lib: add test for bitmap_parse()
  lib: make bitmap_parse_user a wrapper on bitmap_parse
  lib: rework bitmap_parse()
  lib: new testcases for bitmap_parse{_user}
  cpumask: don't calculate length of the input string

 include/linux/bitmap.h   |   8 +-
 include/linux/bitops.h   |   5 +-
 include/linux/cpumask.h  |   4 +-
 include/linux/string.h   |   1 +
 lib/bitmap.c | 197 +--
 lib/string.c |  17 +++
 lib/test_bitmap.c| 102 +-
 tools/include/linux/bitops.h |   9 +-
 8 files changed, 226 insertions(+), 117 deletions(-)

-- 
2.17.1



[PATCH 2/7] bitops: more BITS_TO_* macros

2019-04-30 Thread Yury Norov
Introduce BITS_TO_U64, BITS_TO_U32 and BITS_TO_BYTES as they are handy
in the following patches (BITS_TO_U32 specifically). Reimplement tools/
version of the macros according to the kernel implementation.

Also fix indentation for BITS_PER_TYPE definition.

Signed-off-by: Yury Norov 
---
 include/linux/bitops.h   | 5 -
 tools/include/linux/bitops.h | 9 +
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index cf074bce3eb3..e61c4e614264 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -4,8 +4,11 @@
 #include 
 #include 
 
-#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
+#define BITS_PER_TYPE(type)(sizeof(type) * BITS_PER_BYTE)
 #define BITS_TO_LONGS(nr)  DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
+#define BITS_TO_U64(nr)DIV_ROUND_UP(nr, BITS_PER_TYPE(u64))
+#define BITS_TO_U32(nr)DIV_ROUND_UP(nr, BITS_PER_TYPE(u32))
+#define BITS_TO_BYTES(nr)  DIV_ROUND_UP(nr, BITS_PER_TYPE(char))
 
 extern unsigned int __sw_hweight8(unsigned int w);
 extern unsigned int __sw_hweight16(unsigned int w);
diff --git a/tools/include/linux/bitops.h b/tools/include/linux/bitops.h
index 0b0ef3abc966..a8ba37a50d08 100644
--- a/tools/include/linux/bitops.h
+++ b/tools/include/linux/bitops.h
@@ -13,10 +13,11 @@
 #include 
 #include 
 
-#define BITS_TO_LONGS(nr)  DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
-#define BITS_TO_U64(nr)DIV_ROUND_UP(nr, BITS_PER_BYTE * 
sizeof(u64))
-#define BITS_TO_U32(nr)DIV_ROUND_UP(nr, BITS_PER_BYTE * 
sizeof(u32))
-#define BITS_TO_BYTES(nr)  DIV_ROUND_UP(nr, BITS_PER_BYTE)
+#define BITS_PER_TYPE(type)(sizeof(type) * BITS_PER_BYTE)
+#define BITS_TO_LONGS(nr)  DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
+#define BITS_TO_U64(nr)DIV_ROUND_UP(nr, BITS_PER_TYPE(u64))
+#define BITS_TO_U32(nr)DIV_ROUND_UP(nr, BITS_PER_TYPE(u32))
+#define BITS_TO_BYTES(nr)  DIV_ROUND_UP(nr, BITS_PER_TYPE(char))
 
 extern unsigned int __sw_hweight8(unsigned int w);
 extern unsigned int __sw_hweight16(unsigned int w);
-- 
2.17.1



[PATCH 1/7] lib/string: add strnchrnul()

2019-04-30 Thread Yury Norov
New function works like strchrnul() with a length limited strings.

Signed-off-by: Yury Norov 
---
 include/linux/string.h |  1 +
 lib/string.c   | 17 +
 2 files changed, 18 insertions(+)

diff --git a/include/linux/string.h b/include/linux/string.h
index 4deb11f7976b..ae934d6c50bf 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -62,6 +62,7 @@ extern char * strchr(const char *,int);
 #ifndef __HAVE_ARCH_STRCHRNUL
 extern char * strchrnul(const char *,int);
 #endif
+extern char * strnchrnul(const char *, size_t, int);
 #ifndef __HAVE_ARCH_STRNCHR
 extern char * strnchr(const char *, size_t, int);
 #endif
diff --git a/lib/string.c b/lib/string.c
index 6016eb3ac73d..eee521ad1f40 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -429,6 +429,23 @@ char *strchrnul(const char *s, int c)
 EXPORT_SYMBOL(strchrnul);
 #endif
 
+/**
+ * strnchrnul - Find and return a character in a length limited string,
+ * or end of string
+ * @s: The string to be searched
+ * @count: The number of characters to be searched
+ * @c: The character to search for
+ *
+ * Returns pointer to the first occurrence of 'c' in s. If c is not found,
+ * then return a pointer to the last character of the string.
+ */
+char *strnchrnul(const char *s, size_t count, int c)
+{
+   while (count-- && *s && *s != (char)c)
+   s++;
+   return (char *)s;
+}
+
 #ifndef __HAVE_ARCH_STRRCHR
 /**
  * strrchr - Find the last occurrence of a character in a string
-- 
2.17.1



[PATCH 3/7] lib: add test for bitmap_parse()

2019-04-30 Thread Yury Norov
The test is derived from bitmap_parselist()
NO_LEN is reserved for use in following patches.

Signed-off-by: Yury Norov 
---
 lib/test_bitmap.c | 94 ++-
 1 file changed, 93 insertions(+), 1 deletion(-)

diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index d3a501f2a81a..731e107d811a 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -205,7 +205,8 @@ static void __init test_copy(void)
expect_eq_pbl("0-108,128-1023", bmap2, 1024);
 }
 
-#define PARSE_TIME 0x1
+#define PARSE_TIME 0x1
+#define NO_LEN 0x2
 
 struct test_bitmap_parselist{
const int errno;
@@ -328,6 +329,85 @@ static void __init __test_bitmap_parselist(int is_user)
}
 }
 
+static const unsigned long parse_test[] __initconst = {
+   BITMAP_FROM_U64(0),
+   BITMAP_FROM_U64(1),
+   BITMAP_FROM_U64(0xdeadbeef),
+   BITMAP_FROM_U64(0x1ULL),
+};
+
+static const unsigned long parse_test2[] __initconst = {
+   BITMAP_FROM_U64(0x1ULL), BITMAP_FROM_U64(0xdeadbeef),
+   BITMAP_FROM_U64(0x1ULL), BITMAP_FROM_U64(0xbaadf00ddeadbeef),
+   BITMAP_FROM_U64(0x1ULL), BITMAP_FROM_U64(0x0badf00ddeadbeef),
+};
+
+static const struct test_bitmap_parselist parse_tests[] __initconst = {
+   {0, "0",_test[0 * step], 32, 0},
+   {0, "1",_test[1 * step], 32, 0},
+   {0, "deadbeef", _test[2 * step], 32, 0},
+   {0, "1,0",  _test[3 * step], 33, 0},
+
+   {0, "deadbeef,1,0", _test2[0 * 2 * step], 96, 0},
+   {0, "baadf00d,deadbeef,1,0",_test2[1 * 2 * step], 128, 0},
+   {0, "badf00d,deadbeef,1,0", _test2[2 * 2 * step], 124, 0},
+
+   {-EINVAL,"goodfood,deadbeef,1,0",   NULL, 128, 0},
+   {-EOVERFLOW, "3,0", NULL, 33, 0},
+   {-EOVERFLOW, "123badf00d,deadbeef,1,0", NULL, 128, 0},
+   {-EOVERFLOW, "badf00d,deadbeef,1,0",NULL, 90, 0},
+   {-EOVERFLOW, "fbadf00d,deadbeef,1,0",   NULL, 95, 0},
+   {-EOVERFLOW, "badf00d,deadbeef,1,0",NULL, 100, 0},
+};
+
+static void __init __test_bitmap_parse(int is_user)
+{
+   int i;
+   int err;
+   ktime_t time;
+   DECLARE_BITMAP(bmap, 2048);
+   char *mode = is_user ? "_user"  : "";
+
+   for (i = 0; i < ARRAY_SIZE(parse_tests); i++) {
+   struct test_bitmap_parselist test = parse_tests[i];
+
+   if (is_user) {
+   size_t len = strlen(test.in);
+   mm_segment_t orig_fs = get_fs();
+
+   set_fs(KERNEL_DS);
+   time = ktime_get();
+   err = bitmap_parse_user(test.in, len, bmap, test.nbits);
+   time = ktime_get() - time;
+   set_fs(orig_fs);
+   } else {
+   size_t len = test.flags & NO_LEN ?
+   UINT_MAX : strlen(test.in);
+   time = ktime_get();
+   err = bitmap_parse(test.in, len, bmap, test.nbits);
+   time = ktime_get() - time;
+   }
+
+   if (err != test.errno) {
+   pr_err("parse%s: %d: input is %s, errno is %d, expected 
%d\n",
+   mode, i, test.in, err, test.errno);
+   continue;
+   }
+
+   if (!err && test.expected
+&& !__bitmap_equal(bmap, test.expected, test.nbits)) {
+   pr_err("parse%s: %d: input is %s, result is 0x%lx, 
expected 0x%lx\n",
+   mode, i, test.in, bmap[0],
+   *test.expected);
+   continue;
+   }
+
+   if (test.flags & PARSE_TIME)
+   pr_err("parse%s: %d: input is '%s' OK, Time: %llu\n",
+   mode, i, test.in, time);
+   }
+}
+
 static void __init test_bitmap_parselist(void)
 {
__test_bitmap_parselist(0);
@@ -338,6 +418,16 @@ static void __init test_bitmap_parselist_user(void)
__test_bitmap_parselist(1);
 }
 
+static void __init test_bitmap_parse(void)
+{
+   __test_bitmap_parse(0);
+}
+
+static void __init test_bitmap_parse_user(void)
+{
+   __test_bitmap_parse(1);
+}
+
 #define EXP_BYTES  (sizeof(exp) * 8)
 
 static void __init test_bitmap_arr32(void)
@@ -409,6 +499,8 @@ static void __init selftest(void)
test_fill_set();
test_copy();
test_bitmap_arr32();
+   test_bitmap_parse();
+   test_bitmap_parse_user();
test_bitmap_parselist();
test_bitmap_parselist_user();
test_mem_optimisations();
-- 
2.17.1



Re: [PATCH v4 0/1] Add support for IPMB driver

2019-04-30 Thread Corey Minyard
On Tue, Apr 30, 2019 at 09:24:29PM +, Vadim Pasternak wrote:
> 
> 
> > -Original Message-
> > From: Asmaa Mnebhi 
> > Sent: Tuesday, April 30, 2019 8:59 PM
> > To: miny...@acm.org; w...@the-dreams.de; Vadim Pasternak
> > ; Michael Shych 
> > Cc: Asmaa Mnebhi ; linux-kernel@vger.kernel.org;
> > linux-...@vger.kernel.org
> > Subject: [PATCH v4 0/1] Add support for IPMB driver
> > 
> > Thank you for your feedback Vadim. I have addressed your comments.
> 
> Hi Asmaa,
> 
> Thank you for your comments and added doc.
> 
> > 
> > 1) You are correct. This driver is not specific to Mellanox so I have 
> > removed the
> > Mellanox attribute.
> > 
> > 2) I have added a documentation file called IPMB.txt which explains how this
> > module works and how it should be instantiated. It is very similar to the 
> > existing
> > linux i2c-slave-eeprom module.
> > 
> > The HW for my testing works as follows:
> > A BMC is connected to a Satellite MC via I2C (I2C is equivalent to IPMB). 
> > The
> > BMC initiates the IPMB requests and sends them via I2C.
> > Obviously the BMC needs its own driver to do this which I haven't included 
> > in this
> > code. We have no intent of upstreaming that at the moment.
> 
> I believe you are going to do it at some point, right?

This is a little confusing to me.  Why wouldn't you use the same driver on the
BMC?  IIRC, the IPMB protocol is symmetric at this level.

-corey

> 
> > This ipmb-dev-int driver is to be loaded and instantiated on the Satellite 
> > MC to
> > be able to receive IPMB requests. These IPMB request messages will be picked
> > up by a user space program such (in my case it is OpenIPMI) to handle the
> > request and generate a response.
> > The response will be then passed from the user program back to kernel space.
> > Then this driver would send that response back to the BMC.
> > 
> > 3) You asked the following:
> > 
> > "Is it expected to be zero in vaid case?"
> > The 8 least significant bits of the sum is always expected to be 0 in the 
> > case
> > where the checksum is valid. I have added a comment for clarifications.
> 
> 
> > 
> > "why do you need this cast?"
> > buf[++ipmb_dev_p->msg_idx]=(u8)(client->addr<<1)
> > This is because client->addr is of type unsigned short which is
> > 2 bytes so it is safer to typecast it to u8 (u8* buf)
> 
> Better, if you can avoid cast.
> Would compiler warn if you use for example
> rol16(client->addr, 1) & GENMASK(7, 0);
> or something like it?
> 
> 
> > 
> > "It could be only single ipmb-dev within the system? Couldn't it be few, 
> > like
> > master/slave for example?"
> > My understanding of your question is that: what if we have multiple 
> > instances of
> > ipmb-dev-int, that we register it under different addresses?
> > This driver only works as a slave so it will only be instantiated once on 
> > the
> > Satellite MC under one slave address.
> 
> I mentioned some config like:
> BMC1 (master)  -- busA --|
>   Satellite
> BMC2 (standby)-- busB --| 
> 
> Since this is not Mellanox specific driver, maybe it would be good to support
> multiple instances of it.

I second this.  Especially if it's on a BMC, you can expect to have multiple
IPMBs.

-corey

> 
> > 
> > Asmaa Mnebhi (1):
> >   Add support for IPMB driver
> > 
> >  Documentation/IPMB.txt   |  53 ++
> >  drivers/char/ipmi/Kconfig|   8 +
> >  drivers/char/ipmi/Makefile   |   1 +
> >  drivers/char/ipmi/ipmb_dev_int.c | 381
> > +++
> >  4 files changed, 443 insertions(+)
> >  create mode 100644 Documentation/IPMB.txt  create mode 100644
> > drivers/char/ipmi/ipmb_dev_int.c
> > 
> > --
> > 2.1.2
> 


[RESEND PATCH 6/6] perf/x86/intel/uncore: Add IMC uncore support for Snow Ridge

2019-04-30 Thread kan . liang
From: Kan Liang 

IMC uncore unit can only be accessed via MMIO on Snow Ridge.
The MMIO space of IMC uncore is at the specified offsets from the
MEM0_BAR. Add snr_uncore_get_mc_dev() to locate the PCI device with
MMIO_BASE and MEM0_BAR register.

Add new ops to access the IMC registers via MMIO.

Add 3 new free running counters for clocks, read and write bandwidth.

Signed-off-by: Kan Liang 
---
 arch/x86/events/intel/uncore.c   |   3 +-
 arch/x86/events/intel/uncore.h   |   2 +
 arch/x86/events/intel/uncore_snbep.c | 197 +++
 3 files changed, 201 insertions(+), 1 deletion(-)

diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c
index 39b0f96..f5db8dd 100644
--- a/arch/x86/events/intel/uncore.c
+++ b/arch/x86/events/intel/uncore.c
@@ -28,7 +28,7 @@ struct event_constraint uncore_constraint_empty =
 
 MODULE_LICENSE("GPL");
 
-static int uncore_pcibus_to_physid(struct pci_bus *bus)
+int uncore_pcibus_to_physid(struct pci_bus *bus)
 {
struct pci2phy_map *map;
int phys_id = -1;
@@ -1437,6 +1437,7 @@ static const struct intel_uncore_init_fun icl_uncore_init 
__initconst = {
 static const struct intel_uncore_init_fun snr_uncore_init __initconst = {
.cpu_init = snr_uncore_cpu_init,
.pci_init = snr_uncore_pci_init,
+   .mmio_init = snr_uncore_mmio_init,
 };
 
 static const struct x86_cpu_id intel_uncore_match[] __initconst = {
diff --git a/arch/x86/events/intel/uncore.h b/arch/x86/events/intel/uncore.h
index 738bed3..57641bf 100644
--- a/arch/x86/events/intel/uncore.h
+++ b/arch/x86/events/intel/uncore.h
@@ -163,6 +163,7 @@ struct pci2phy_map {
 };
 
 struct pci2phy_map *__find_pci2phy_map(int segment);
+int uncore_pcibus_to_physid(struct pci_bus *bus);
 
 ssize_t uncore_event_show(struct kobject *kobj,
  struct kobj_attribute *attr, char *buf);
@@ -555,6 +556,7 @@ int skx_uncore_pci_init(void);
 void skx_uncore_cpu_init(void);
 int snr_uncore_pci_init(void);
 void snr_uncore_cpu_init(void);
+void snr_uncore_mmio_init(void);
 
 /* uncore_nhmex.c */
 void nhmex_uncore_cpu_init(void);
diff --git a/arch/x86/events/intel/uncore_snbep.c 
b/arch/x86/events/intel/uncore_snbep.c
index 851f76f..7420e8b6 100644
--- a/arch/x86/events/intel/uncore_snbep.c
+++ b/arch/x86/events/intel/uncore_snbep.c
@@ -374,6 +374,19 @@
 #define SNR_PCIE3_PCI_PMON_CTR00x4e8
 #define SNR_PCIE3_PCI_PMON_BOX_CTL 0x4e4
 
+/* SNR IMC */
+#define SNR_IMC_MMIO_PMON_FIXED_CTL0x54
+#define SNR_IMC_MMIO_PMON_FIXED_CTR0x38
+#define SNR_IMC_MMIO_PMON_CTL0 0x40
+#define SNR_IMC_MMIO_PMON_CTR0 0x8
+#define SNR_IMC_MMIO_PMON_BOX_CTL  0x22800
+#define SNR_IMC_MMIO_OFFSET0x4000
+#define SNR_IMC_MMIO_SIZE  0x4000
+#define SNR_IMC_MMIO_BASE_OFFSET   0xd0
+#define SNR_IMC_MMIO_BASE_MASK 0x1FFF
+#define SNR_IMC_MMIO_MEM0_OFFSET   0xd8
+#define SNR_IMC_MMIO_MEM0_MASK 0x7FF
+
 DEFINE_UNCORE_FORMAT_ATTR(event, event, "config:0-7");
 DEFINE_UNCORE_FORMAT_ATTR(event2, event, "config:0-6");
 DEFINE_UNCORE_FORMAT_ATTR(event_ext, event, "config:0-7,21");
@@ -4370,4 +4383,188 @@ int snr_uncore_pci_init(void)
return 0;
 }
 
+static struct pci_dev *snr_uncore_get_mc_dev(int id)
+{
+   struct pci_dev *mc_dev = NULL;
+   int phys_id, pkg;
+
+   while (1) {
+   mc_dev = pci_get_device(PCI_VENDOR_ID_INTEL, 0x3451, mc_dev);
+   if (!mc_dev)
+   break;
+   phys_id = uncore_pcibus_to_physid(mc_dev->bus);
+   if (phys_id < 0)
+   continue;
+   pkg = topology_phys_to_logical_pkg(phys_id);
+   if (pkg < 0)
+   continue;
+   else if (pkg == id)
+   break;
+   }
+   return mc_dev;
+}
+
+static void snr_uncore_mmio_init_box(struct intel_uncore_box *box)
+{
+   struct pci_dev *pdev = snr_uncore_get_mc_dev(box->pkgid);
+   unsigned int box_ctl = uncore_mmio_box_ctl(box);
+   resource_size_t addr;
+   u32 pci_dword;
+
+   if (!pdev)
+   return;
+
+   pci_read_config_dword(pdev, SNR_IMC_MMIO_BASE_OFFSET, _dword);
+   addr = (pci_dword & SNR_IMC_MMIO_BASE_MASK) << 23;
+
+   pci_read_config_dword(pdev, SNR_IMC_MMIO_MEM0_OFFSET, _dword);
+   addr |= (pci_dword & SNR_IMC_MMIO_MEM0_MASK) << 12;
+
+   addr += box_ctl;
+
+   box->io_addr = ioremap(addr, SNR_IMC_MMIO_SIZE);
+   if (!box->io_addr)
+   return;
+
+   writel(IVBEP_PMON_BOX_CTL_INT, box->io_addr);
+}
+
+static void snr_uncore_mmio_disable_box(struct intel_uncore_box *box)
+{
+   u32 config;
+
+   if (!box->io_addr)
+   return;
+
+   config = readl(box->io_addr);
+   config |= SNBEP_PMON_BOX_CTL_FRZ;
+   writel(config, 

[RESEND PATCH 0/6] Perf uncore support for Snow Ridge server

2019-04-30 Thread kan . liang
From: Kan Liang 

The patch series intends to enable perf uncore support for Snow Ridge
server.

Here is the link for the uncore document.
https://cdrdv2.intel.com/v1/dl/getContent/611319

Patch 1: Fixes a generic issue for uncore free-running counter, which
also impacts the Snow Ridge server.

Patch 2-6: Perf uncore support for Snow Ridge server.

Kan Liang (6):
  perf/x86/intel/uncore: Handle invalid event coding for free-running
counter
  perf/x86/intel/uncore: Add uncore support for Snow Ridge server
  perf/x86/intel/uncore: Extract codes of box ref/unref
  perf/x86/intel/uncore: Support MMIO type uncore blocks
  perf/x86/intel/uncore: Clean up client IMC
  perf/x86/intel/uncore: Add IMC uncore support for Snow Ridge

 arch/x86/events/intel/uncore.c   | 122 +--
 arch/x86/events/intel/uncore.h   |  41 ++-
 arch/x86/events/intel/uncore_snb.c   |  16 +-
 arch/x86/events/intel/uncore_snbep.c | 601 +++
 4 files changed, 737 insertions(+), 43 deletions(-)

-- 
2.7.4



[RESEND PATCH 4/6] perf/x86/intel/uncore: Support MMIO type uncore blocks

2019-04-30 Thread kan . liang
From: Kan Liang 

A new MMIO type uncore box is introduced on Snow Ridge server. The
counters of MMIO type uncore box can only be accessed by MMIO.

Add a new uncore type, uncore_mmio_uncores, for MMIO type uncore blocks.

Support MMIO type uncore blocks in CPU hot plug. The MMIO space has to
be map/unmap for the first/last CPU. The context also need to be
migrated if the bind CPU changes.

Add mmio_init() to init and register PMUs for MMIO type uncore blocks.

Add a helper to calculate the box_ctl address.

The helpers which calculate ctl/ctr can be shared with PCI type uncore
blocks.

Signed-off-by: Kan Liang 
---
 arch/x86/events/intel/uncore.c | 51 --
 arch/x86/events/intel/uncore.h | 21 -
 2 files changed, 60 insertions(+), 12 deletions(-)

diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c
index 0b72ca5..3c00635 100644
--- a/arch/x86/events/intel/uncore.c
+++ b/arch/x86/events/intel/uncore.c
@@ -7,6 +7,7 @@
 static struct intel_uncore_type *empty_uncore[] = { NULL, };
 struct intel_uncore_type **uncore_msr_uncores = empty_uncore;
 struct intel_uncore_type **uncore_pci_uncores = empty_uncore;
+struct intel_uncore_type **uncore_mmio_uncores = empty_uncore;
 
 static bool pcidrv_registered;
 struct pci_driver *uncore_pci_driver;
@@ -1175,12 +1176,14 @@ static int uncore_event_cpu_offline(unsigned int cpu)
target = -1;
 
uncore_change_context(uncore_msr_uncores, cpu, target);
+   uncore_change_context(uncore_mmio_uncores, cpu, target);
uncore_change_context(uncore_pci_uncores, cpu, target);
 
 unref:
/* Clear the references */
pkg = topology_logical_package_id(cpu);
uncore_box_unref(uncore_msr_uncores, pkg);
+   uncore_box_unref(uncore_mmio_uncores, pkg);
return 0;
 }
 
@@ -1248,12 +1251,13 @@ static int uncore_box_ref(struct intel_uncore_type 
**types,
 
 static int uncore_event_cpu_online(unsigned int cpu)
 {
-   int ret, pkg, target;
+   int pkg, target, msr_ret, mmio_ret;
 
pkg = topology_logical_package_id(cpu);
-   ret = uncore_box_ref(uncore_msr_uncores, pkg, cpu);
-   if (ret)
-   return ret;
+   msr_ret = uncore_box_ref(uncore_msr_uncores, pkg, cpu);
+   mmio_ret = uncore_box_ref(uncore_mmio_uncores, pkg, cpu);
+   if (msr_ret && mmio_ret)
+   return -ENOMEM;
 
/*
 * Check if there is an online cpu in the package
@@ -1265,7 +1269,10 @@ static int uncore_event_cpu_online(unsigned int cpu)
 
cpumask_set_cpu(cpu, _cpu_mask);
 
-   uncore_change_context(uncore_msr_uncores, -1, cpu);
+   if (!msr_ret)
+   uncore_change_context(uncore_msr_uncores, -1, cpu);
+   if (!mmio_ret)
+   uncore_change_context(uncore_mmio_uncores, -1, cpu);
uncore_change_context(uncore_pci_uncores, -1, cpu);
return 0;
 }
@@ -1313,12 +1320,35 @@ static int __init uncore_cpu_init(void)
return ret;
 }
 
+static int __init uncore_mmio_init(void)
+{
+   struct intel_uncore_type **types = uncore_mmio_uncores;
+   int ret;
+
+   ret = uncore_types_init(types, true);
+   if (ret)
+   goto err;
+
+   for (; *types; types++) {
+   ret = type_pmu_register(*types);
+   if (ret)
+   goto err;
+   }
+   return 0;
+err:
+   uncore_types_exit(uncore_mmio_uncores);
+   uncore_mmio_uncores = empty_uncore;
+   return ret;
+}
+
+
 #define X86_UNCORE_MODEL_MATCH(model, init)\
{ X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (unsigned long) }
 
 struct intel_uncore_init_fun {
void(*cpu_init)(void);
int (*pci_init)(void);
+   void(*mmio_init)(void);
 };
 
 static const struct intel_uncore_init_fun nhm_uncore_init __initconst = {
@@ -1431,7 +1461,7 @@ static int __init intel_uncore_init(void)
 {
const struct x86_cpu_id *id;
struct intel_uncore_init_fun *uncore_init;
-   int pret = 0, cret = 0, ret;
+   int pret = 0, cret = 0, mret = 0, ret;
 
id = x86_match_cpu(intel_uncore_match);
if (!id)
@@ -1454,7 +1484,12 @@ static int __init intel_uncore_init(void)
cret = uncore_cpu_init();
}
 
-   if (cret && pret)
+   if (uncore_init->mmio_init) {
+   uncore_init->mmio_init();
+   mret = uncore_mmio_init();
+   }
+
+   if (cret && pret && mret)
return -ENODEV;
 
/* Install hotplug callbacks to setup the targets for each package */
@@ -1468,6 +1503,7 @@ static int __init intel_uncore_init(void)
 
 err:
uncore_types_exit(uncore_msr_uncores);
+   uncore_types_exit(uncore_mmio_uncores);
uncore_pci_exit();
return ret;
 }
@@ -1477,6 +1513,7 @@ static void __exit intel_uncore_exit(void)
 {
cpuhp_remove_state(CPUHP_AP_PERF_X86_UNCORE_ONLINE);

[RESEND PATCH 5/6] perf/x86/intel/uncore: Clean up client IMC

2019-04-30 Thread kan . liang
From: Kan Liang 

The client IMC block is accessed by MMIO. Current code uses an informal
way to access the block, which is not recommended.

Cleaning up the code by using __iomem annotation and the accessor
functions (read[lq]()).
Move exit_box() and read_counter() to generic code, which can be shared
with server later.

Signed-off-by: Kan Liang 
---
 arch/x86/events/intel/uncore.c | 15 +++
 arch/x86/events/intel/uncore.h |  6 +-
 arch/x86/events/intel/uncore_snb.c | 16 ++--
 3 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c
index 3c00635..39b0f96 100644
--- a/arch/x86/events/intel/uncore.c
+++ b/arch/x86/events/intel/uncore.c
@@ -119,6 +119,21 @@ u64 uncore_msr_read_counter(struct intel_uncore_box *box, 
struct perf_event *eve
return count;
 }
 
+void uncore_mmio_exit_box(struct intel_uncore_box *box)
+{
+   if (box->io_addr)
+   iounmap(box->io_addr);
+}
+
+u64 uncore_mmio_read_counter(struct intel_uncore_box *box,
+struct perf_event *event)
+{
+   if (!box->io_addr)
+   return 0;
+
+   return readq(box->io_addr + event->hw.event_base);
+}
+
 /*
  * generic get constraint function for shared match/mask registers.
  */
diff --git a/arch/x86/events/intel/uncore.h b/arch/x86/events/intel/uncore.h
index 426a490..738bed3 100644
--- a/arch/x86/events/intel/uncore.h
+++ b/arch/x86/events/intel/uncore.h
@@ -2,6 +2,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include "../perf_event.h"
@@ -128,7 +129,7 @@ struct intel_uncore_box {
struct hrtimer hrtimer;
struct list_head list;
struct list_head active_list;
-   void *io_addr;
+   void __iomem *io_addr;
struct intel_uncore_extra_reg shared_regs[0];
 };
 
@@ -502,6 +503,9 @@ static inline struct intel_uncore_box 
*uncore_event_to_box(struct perf_event *ev
 
 struct intel_uncore_box *uncore_pmu_to_box(struct intel_uncore_pmu *pmu, int 
cpu);
 u64 uncore_msr_read_counter(struct intel_uncore_box *box, struct perf_event 
*event);
+void uncore_mmio_exit_box(struct intel_uncore_box *box);
+u64 uncore_mmio_read_counter(struct intel_uncore_box *box,
+struct perf_event *event);
 void uncore_pmu_start_hrtimer(struct intel_uncore_box *box);
 void uncore_pmu_cancel_hrtimer(struct intel_uncore_box *box);
 void uncore_pmu_event_start(struct perf_event *event, int flags);
diff --git a/arch/x86/events/intel/uncore_snb.c 
b/arch/x86/events/intel/uncore_snb.c
index f843181..5d0ce4347 100644
--- a/arch/x86/events/intel/uncore_snb.c
+++ b/arch/x86/events/intel/uncore_snb.c
@@ -420,11 +420,6 @@ static void snb_uncore_imc_init_box(struct 
intel_uncore_box *box)
box->hrtimer_duration = UNCORE_SNB_IMC_HRTIMER_INTERVAL;
 }
 
-static void snb_uncore_imc_exit_box(struct intel_uncore_box *box)
-{
-   iounmap(box->io_addr);
-}
-
 static void snb_uncore_imc_enable_box(struct intel_uncore_box *box)
 {}
 
@@ -437,13 +432,6 @@ static void snb_uncore_imc_enable_event(struct 
intel_uncore_box *box, struct per
 static void snb_uncore_imc_disable_event(struct intel_uncore_box *box, struct 
perf_event *event)
 {}
 
-static u64 snb_uncore_imc_read_counter(struct intel_uncore_box *box, struct 
perf_event *event)
-{
-   struct hw_perf_event *hwc = >hw;
-
-   return (u64)*(unsigned int *)(box->io_addr + hwc->event_base);
-}
-
 /*
  * Keep the custom event_init() function compatible with old event
  * encoding for free running counters.
@@ -570,13 +558,13 @@ static struct pmu snb_uncore_imc_pmu = {
 
 static struct intel_uncore_ops snb_uncore_imc_ops = {
.init_box   = snb_uncore_imc_init_box,
-   .exit_box   = snb_uncore_imc_exit_box,
+   .exit_box   = uncore_mmio_exit_box,
.enable_box = snb_uncore_imc_enable_box,
.disable_box= snb_uncore_imc_disable_box,
.disable_event  = snb_uncore_imc_disable_event,
.enable_event   = snb_uncore_imc_enable_event,
.hw_config  = snb_uncore_imc_hw_config,
-   .read_counter   = snb_uncore_imc_read_counter,
+   .read_counter   = uncore_mmio_read_counter,
 };
 
 static struct intel_uncore_type snb_uncore_imc = {
-- 
2.7.4



[RESEND PATCH 1/6] perf/x86/intel/uncore: Handle invalid event coding for free-running counter

2019-04-30 Thread kan . liang
From: Kan Liang 

Counting with invalid event coding for free-running counter may cause
OOPs, e.g. uncore_iio_free_running_0/event=1/.

Current code only validate the event with free-running event format,
event=0xff,umask=0xXY. Non-free-running event format never be checked
for the PMU with free-running counters.

Add generic hw_config() to check and reject the invalid event coding
for free-running PMU.

Fixes: 0f519f0352e3 ("perf/x86/intel/uncore: Support IIO free-running counters 
on SKX")
Signed-off-by: Kan Liang 
Cc: sta...@vger.kernel.org
---
 arch/x86/events/intel/uncore.h   | 10 ++
 arch/x86/events/intel/uncore_snbep.c |  1 +
 2 files changed, 11 insertions(+)

diff --git a/arch/x86/events/intel/uncore.h b/arch/x86/events/intel/uncore.h
index 79eb2e2..28499e3 100644
--- a/arch/x86/events/intel/uncore.h
+++ b/arch/x86/events/intel/uncore.h
@@ -419,6 +419,16 @@ static inline bool is_freerunning_event(struct perf_event 
*event)
   (((cfg >> 8) & 0xff) >= UNCORE_FREERUNNING_UMASK_START);
 }
 
+/* Check and reject invalid config */
+static inline int uncore_freerunning_hw_config(struct intel_uncore_box *box,
+  struct perf_event *event)
+{
+   if (is_freerunning_event(event))
+   return 0;
+
+   return -EINVAL;
+}
+
 static inline void uncore_disable_box(struct intel_uncore_box *box)
 {
if (box->pmu->type->ops->disable_box)
diff --git a/arch/x86/events/intel/uncore_snbep.c 
b/arch/x86/events/intel/uncore_snbep.c
index b10e043..8e4e8e4 100644
--- a/arch/x86/events/intel/uncore_snbep.c
+++ b/arch/x86/events/intel/uncore_snbep.c
@@ -3585,6 +3585,7 @@ static struct uncore_event_desc 
skx_uncore_iio_freerunning_events[] = {
 
 static struct intel_uncore_ops skx_uncore_iio_freerunning_ops = {
.read_counter   = uncore_msr_read_counter,
+   .hw_config  = uncore_freerunning_hw_config,
 };
 
 static struct attribute *skx_uncore_iio_freerunning_formats_attr[] = {
-- 
2.7.4



[RESEND PATCH 3/6] perf/x86/intel/uncore: Extract codes of box ref/unref

2019-04-30 Thread kan . liang
From: Kan Liang 

For uncore box which can only be accessed by MSR, its reference
box->refcnt is updated in CPU hot plug. The uncore boxes needs to be
init/exit accordingly for the first/last CPU of a socket.
Starts from Snow Ridge server, a new type of uncore box is introduced,
which can only be accessed by MMIO. The driver needs to map/unmap
MMIO space for the first/last CPU of a socket.

Extract the codes of box ref/unref and init/exit for reuse later.

There is no functional change.

Signed-off-by: Kan Liang 
---
 arch/x86/events/intel/uncore.c | 55 +++---
 1 file changed, 36 insertions(+), 19 deletions(-)

diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c
index ee23b50..0b72ca5 100644
--- a/arch/x86/events/intel/uncore.c
+++ b/arch/x86/events/intel/uncore.c
@@ -1140,12 +1140,27 @@ static void uncore_change_context(struct 
intel_uncore_type **uncores,
uncore_change_type_ctx(*uncores, old_cpu, new_cpu);
 }
 
-static int uncore_event_cpu_offline(unsigned int cpu)
+static void uncore_box_unref(struct intel_uncore_type **types, int id)
 {
-   struct intel_uncore_type *type, **types = uncore_msr_uncores;
+   struct intel_uncore_type *type;
struct intel_uncore_pmu *pmu;
struct intel_uncore_box *box;
-   int i, pkg, target;
+   int i;
+
+   for (; *types; types++) {
+   type = *types;
+   pmu = type->pmus;
+   for (i = 0; i < type->num_boxes; i++, pmu++) {
+   box = pmu->boxes[id];
+   if (box && atomic_dec_return(>refcnt) == 0)
+   uncore_box_exit(box);
+   }
+   }
+}
+
+static int uncore_event_cpu_offline(unsigned int cpu)
+{
+   int pkg, target;
 
/* Check if exiting cpu is used for collecting uncore events */
if (!cpumask_test_and_clear_cpu(cpu, _cpu_mask))
@@ -1165,15 +1180,7 @@ static int uncore_event_cpu_offline(unsigned int cpu)
 unref:
/* Clear the references */
pkg = topology_logical_package_id(cpu);
-   for (; *types; types++) {
-   type = *types;
-   pmu = type->pmus;
-   for (i = 0; i < type->num_boxes; i++, pmu++) {
-   box = pmu->boxes[pkg];
-   if (box && atomic_dec_return(>refcnt) == 0)
-   uncore_box_exit(box);
-   }
-   }
+   uncore_box_unref(uncore_msr_uncores, pkg);
return 0;
 }
 
@@ -1215,16 +1222,15 @@ static int allocate_boxes(struct intel_uncore_type 
**types,
}
return -ENOMEM;
 }
-
-static int uncore_event_cpu_online(unsigned int cpu)
+static int uncore_box_ref(struct intel_uncore_type **types,
+ int id, unsigned int cpu)
 {
-   struct intel_uncore_type *type, **types = uncore_msr_uncores;
+   struct intel_uncore_type *type;
struct intel_uncore_pmu *pmu;
struct intel_uncore_box *box;
-   int i, ret, pkg, target;
+   int i, ret;
 
-   pkg = topology_logical_package_id(cpu);
-   ret = allocate_boxes(types, pkg, cpu);
+   ret = allocate_boxes(types, id, cpu);
if (ret)
return ret;
 
@@ -1232,11 +1238,22 @@ static int uncore_event_cpu_online(unsigned int cpu)
type = *types;
pmu = type->pmus;
for (i = 0; i < type->num_boxes; i++, pmu++) {
-   box = pmu->boxes[pkg];
+   box = pmu->boxes[id];
if (box && atomic_inc_return(>refcnt) == 1)
uncore_box_init(box);
}
}
+   return 0;
+}
+
+static int uncore_event_cpu_online(unsigned int cpu)
+{
+   int ret, pkg, target;
+
+   pkg = topology_logical_package_id(cpu);
+   ret = uncore_box_ref(uncore_msr_uncores, pkg, cpu);
+   if (ret)
+   return ret;
 
/*
 * Check if there is an online cpu in the package
-- 
2.7.4



[RESEND PATCH 2/6] perf/x86/intel/uncore: Add uncore support for Snow Ridge server

2019-04-30 Thread kan . liang
From: Kan Liang 

The uncore subsystem on Snow Ridge is similar as previous SKX server.
The uncore units on Snow Ridge include Ubox, Chabox, IIO, IRP, M2PCIE,
PCU, M2M, PCIE3 and IMC.
- The config register encoding and pci device IDs are changed.
- For CHA, the umask_ext and filter_tid fields are changed.
- For IIO, the ch_mask and fc_mask fields are changed.
- For M2M, the mask_ext field is changed.
- Add new PCIe3 unit for PCIe3 root port which provides the interface
  between PCIe devices, plugged into the PCIe port, and the components
  (in M2IOSF).
- IMC can only be accessed via MMIO on Snow Ridge now. Current common
  code doesn't support it yet. IMC will be supported in following
  patches.
- There are 9 free running counters for IIO CLOCKS and bandwidth In.
- Full uncore event list is not published yet. Event constrain is not
  included in this patch. It will be added later separately.

Signed-off-by: Kan Liang 
---
 arch/x86/events/intel/uncore.c   |   6 +
 arch/x86/events/intel/uncore.h   |   2 +
 arch/x86/events/intel/uncore_snbep.c | 403 +++
 3 files changed, 411 insertions(+)

diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c
index fc40a14..ee23b50 100644
--- a/arch/x86/events/intel/uncore.c
+++ b/arch/x86/events/intel/uncore.c
@@ -1372,6 +1372,11 @@ static const struct intel_uncore_init_fun 
icl_uncore_init __initconst = {
.pci_init = skl_uncore_pci_init,
 };
 
+static const struct intel_uncore_init_fun snr_uncore_init __initconst = {
+   .cpu_init = snr_uncore_cpu_init,
+   .pci_init = snr_uncore_pci_init,
+};
+
 static const struct x86_cpu_id intel_uncore_match[] __initconst = {
X86_UNCORE_MODEL_MATCH(INTEL_FAM6_NEHALEM_EP, nhm_uncore_init),
X86_UNCORE_MODEL_MATCH(INTEL_FAM6_NEHALEM,nhm_uncore_init),
@@ -1399,6 +1404,7 @@ static const struct x86_cpu_id intel_uncore_match[] 
__initconst = {
X86_UNCORE_MODEL_MATCH(INTEL_FAM6_KABYLAKE_MOBILE, skl_uncore_init),
X86_UNCORE_MODEL_MATCH(INTEL_FAM6_KABYLAKE_DESKTOP, skl_uncore_init),
X86_UNCORE_MODEL_MATCH(INTEL_FAM6_ICELAKE_MOBILE, icl_uncore_init),
+   X86_UNCORE_MODEL_MATCH(INTEL_FAM6_ATOM_TREMONT_X, snr_uncore_init),
{},
 };
 
diff --git a/arch/x86/events/intel/uncore.h b/arch/x86/events/intel/uncore.h
index 28499e3..5e97e5e 100644
--- a/arch/x86/events/intel/uncore.h
+++ b/arch/x86/events/intel/uncore.h
@@ -538,6 +538,8 @@ int knl_uncore_pci_init(void);
 void knl_uncore_cpu_init(void);
 int skx_uncore_pci_init(void);
 void skx_uncore_cpu_init(void);
+int snr_uncore_pci_init(void);
+void snr_uncore_cpu_init(void);
 
 /* uncore_nhmex.c */
 void nhmex_uncore_cpu_init(void);
diff --git a/arch/x86/events/intel/uncore_snbep.c 
b/arch/x86/events/intel/uncore_snbep.c
index 8e4e8e4..851f76f 100644
--- a/arch/x86/events/intel/uncore_snbep.c
+++ b/arch/x86/events/intel/uncore_snbep.c
@@ -324,12 +324,64 @@
 #define SKX_M2M_PCI_PMON_CTR0  0x200
 #define SKX_M2M_PCI_PMON_BOX_CTL   0x258
 
+/* SNR Ubox */
+#define SNR_U_MSR_PMON_CTR00x1f98
+#define SNR_U_MSR_PMON_CTL00x1f91
+#define SNR_U_MSR_PMON_UCLK_FIXED_CTL  0x1f93
+#define SNR_U_MSR_PMON_UCLK_FIXED_CTR  0x1f94
+
+/* SNR CHA */
+#define SNR_CHA_RAW_EVENT_MASK_EXT 0x3ff
+#define SNR_CHA_MSR_PMON_CTL0  0x1c01
+#define SNR_CHA_MSR_PMON_CTR0  0x1c08
+#define SNR_CHA_MSR_PMON_BOX_CTL   0x1c00
+#define SNR_C0_MSR_PMON_BOX_FILTER00x1c05
+
+
+/* SNR IIO */
+#define SNR_IIO_MSR_PMON_CTL0  0x1e08
+#define SNR_IIO_MSR_PMON_CTR0  0x1e01
+#define SNR_IIO_MSR_PMON_BOX_CTL   0x1e00
+#define SNR_IIO_MSR_OFFSET 0x10
+#define SNR_IIO_PMON_RAW_EVENT_MASK_EXT0x7
+
+/* SNR IRP */
+#define SNR_IRP0_MSR_PMON_CTL0 0x1ea8
+#define SNR_IRP0_MSR_PMON_CTR0 0x1ea1
+#define SNR_IRP0_MSR_PMON_BOX_CTL  0x1ea0
+#define SNR_IRP_MSR_OFFSET 0x10
+
+/* SNR M2PCIE */
+#define SNR_M2PCIE_MSR_PMON_CTL0   0x1e58
+#define SNR_M2PCIE_MSR_PMON_CTR0   0x1e51
+#define SNR_M2PCIE_MSR_PMON_BOX_CTL0x1e50
+#define SNR_M2PCIE_MSR_OFFSET  0x10
+
+/* SNR PCU */
+#define SNR_PCU_MSR_PMON_CTL0  0x1ef1
+#define SNR_PCU_MSR_PMON_CTR0  0x1ef8
+#define SNR_PCU_MSR_PMON_BOX_CTL   0x1ef0
+#define SNR_PCU_MSR_PMON_BOX_FILTER0x1efc
+
+/* SNR M2M */
+#define SNR_M2M_PCI_PMON_CTL0  0x468
+#define SNR_M2M_PCI_PMON_CTR0  0x440
+#define SNR_M2M_PCI_PMON_BOX_CTL   0x438
+#define SNR_M2M_PCI_PMON_UMASK_EXT 0xff
+
+/* SNR PCIE3 */
+#define SNR_PCIE3_PCI_PMON_CTL00x508
+#define SNR_PCIE3_PCI_PMON_CTR00x4e8
+#define 

Re: [PATCH 4/6] lib: rework bitmap_parse()

2019-04-30 Thread Yury Norov
On Sun, Apr 28, 2019 at 07:57:45PM +0300, Andy Shevchenko wrote:
> On Sat, Apr 27, 2019 at 08:29:34PM -0700, Yury Norov wrote:
> > bitmap_parse() is ineffective and full of opaque variables and opencoded
> > parts. It leads to hard understanding of it. This rework includes:
> >  - remove bitmap_shift_left() call from the cycle. Now it makes the
> >complexity of the algorithm as O(nbits^2). In the suggested approach
> >the input string is parsed in reverse direction, so no shifts needed;
> >  - relax requirement on a single comma and no white spaces between chunks.
> >It is considered useful in scripting, and it aligns with
> >bitmap_parselist();
> >  - split bitmap_parse() to small readable helpers;
> >  - make an explicit calculation of the end of input line at the
> >beginning, so users of the bitmap_parse() won't bother doing this.
> 
> > +static inline bool in_str(const char *start, const char *ptr)
> > +{
> > +   return start <= ptr;
> > +}
> > +
> 
> I don't see how it's better than explicit use. Moreover, explicit use shows 
> the
> exact condition in-line. Even by used characters it's longer.

I did 2 mistakes with a condition ('<' instead of '<=') during the
development, after that I decided to introduce it. I would prefer
keep it.
 
> > +static const char *bitmap_get_hex32_rev(const char *start,
> > +   const char *end, u32 *num)
> 
> In kernel few functions to work with hex u32 named foo_x32(). I would rather
> use that. Besides, we spell "reverse" in full.

OK

> > +{
> > +   u32 ret = 0;
> > +   int c, i;
> > +
> > +   if (hex_to_bin(*end) < 0)
> > +   return ERR_PTR(-EINVAL);
> > +
> > +   for (i = 0; i < 32; i += 4) {
> > +   c = hex_to_bin(*end--);
> > +   if (c < 0)
> 
> Perhaps we may need similar patch for hex_to_bin() as in the commit
> 9888a588ea96 ("lib/hexdump.c: return -EINVAL in case of error in hex2bin()")
> 
> > +   return ERR_PTR(-EINVAL);
> 
> > +
> > +   ret |= c << i;
> > +
> > +   if (!in_str(start, end) || __end_of_region(*end))
> > +   goto out;
> > +   }
> > +
> > +   if (hex_to_bin(*end) >= 0)
> > +   return ERR_PTR(-EOVERFLOW);
> > +out:
> > +   *num = ret;
> > +   return end;
> > +}
> 
> -- 
> With Best Regards,
> Andy Shevchenko
> 


Re: [PATCH] tty: Don't force RISCV SBI console as preferred console

2019-04-30 Thread Palmer Dabbelt

On Thu, 25 Apr 2019 06:35:06 PDT (-0700), Anup Patel wrote:

The Linux kernel will auto-disables all boot consoles whenever it
gets a preferred real console.

Currently on RISC-V systems, if we have a real console which is not
RISCV SBI console then boot consoles (such as earlycon=sbi) are not
auto-disabled when a real console (ttyS0 or ttySIF0) is available.
This results in duplicate prints at boot-time after kernel starts
using real console (i.e. ttyS0 or ttySIF0) if "earlycon=" kernel
parameter was passed by bootloader.

The reason for above issue is that RISCV SBI console always adds
itself as preferred console which is causing other real consoles
to be not used as preferred console.

Ideally "console=" kernel parameter passed by bootloaders should
be the one selecting a preferred real console.

This patch fixes above issue by not forcing RISCV SBI console as
preferred console.

Fixes: afa6b1ccfad5 ("tty: New RISC-V SBI console driver")
Cc: sta...@vger.kernel.org
Signed-off-by: Anup Patel 
---
 drivers/tty/hvc/hvc_riscv_sbi.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/tty/hvc/hvc_riscv_sbi.c b/drivers/tty/hvc/hvc_riscv_sbi.c
index 75155bde2b88..31f53fa77e4a 100644
--- a/drivers/tty/hvc/hvc_riscv_sbi.c
+++ b/drivers/tty/hvc/hvc_riscv_sbi.c
@@ -53,7 +53,6 @@ device_initcall(hvc_sbi_init);
 static int __init hvc_sbi_console_init(void)
 {
hvc_instantiate(0, 0, _sbi_ops);
-   add_preferred_console("hvc", 0, NULL);
 
 	return 0;

 }
--
2.17.1



I merged this.  Also, it looks like Exchange is doing something to your patches
that makes them a bit difficult to merge.  If you don't have a way of fixing
that, can you include a pointer to a git tree with a signed commit/tag?


[tip:x86/mm 14/35] kernel/trace/bpf_trace.c:179:16: error: implicit declaration of function 'nmi_uaccess_okay'; did you mean '__access_ok'?

2019-04-30 Thread kbuild test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/mm
head:   3950746d9d8ef981c1cb842384e0e86e8d1aad76
commit: c7b6f29b6257532792fc722b68fcc0e00b5a856c [14/35] bpf: Fail 
bpf_probe_write_user() while mm is switched
config: s390-defconfig (attached as .config)
compiler: s390x-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
git checkout c7b6f29b6257532792fc722b68fcc0e00b5a856c
# save the attached .config to linux build tree
GCC_VERSION=7.2.0 make.cross ARCH=s390 

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

All errors (new ones prefixed by >>):

   In file included from include/linux/kernel.h:11:0,
from kernel/trace/bpf_trace.c:5:
   kernel/trace/bpf_trace.c: In function 'bpf_probe_write_user':
>> kernel/trace/bpf_trace.c:179:16: error: implicit declaration of function 
>> 'nmi_uaccess_okay'; did you mean '__access_ok'? 
>> [-Werror=implicit-function-declaration]
 if (unlikely(!nmi_uaccess_okay()))
   ^
   include/linux/compiler.h:77:42: note: in definition of macro 'unlikely'
# define unlikely(x) __builtin_expect(!!(x), 0)
 ^
   cc1: some warnings being treated as errors

vim +179 kernel/trace/bpf_trace.c

   > 5  #include 
 6  #include 
 7  #include 
 8  #include 
 9  #include 
10  #include 
11  #include 
12  #include 
13  #include 
14  #include 
15  #include 
16  
17  #include 
18  
19  #include "trace_probe.h"
20  #include "trace.h"
21  
22  #ifdef CONFIG_MODULES
23  struct bpf_trace_module {
24  struct module *module;
25  struct list_head list;
26  };
27  
28  static LIST_HEAD(bpf_trace_modules);
29  static DEFINE_MUTEX(bpf_module_mutex);
30  
31  static struct bpf_raw_event_map *bpf_get_raw_tracepoint_module(const 
char *name)
32  {
33  struct bpf_raw_event_map *btp, *ret = NULL;
34  struct bpf_trace_module *btm;
35  unsigned int i;
36  
37  mutex_lock(_module_mutex);
38  list_for_each_entry(btm, _trace_modules, list) {
39  for (i = 0; i < btm->module->num_bpf_raw_events; ++i) {
40  btp = >module->bpf_raw_events[i];
41  if (!strcmp(btp->tp->name, name)) {
42  if (try_module_get(btm->module))
43  ret = btp;
44  goto out;
45  }
46  }
47  }
48  out:
49  mutex_unlock(_module_mutex);
50  return ret;
51  }
52  #else
53  static struct bpf_raw_event_map *bpf_get_raw_tracepoint_module(const 
char *name)
54  {
55  return NULL;
56  }
57  #endif /* CONFIG_MODULES */
58  
59  u64 bpf_get_stackid(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
60  u64 bpf_get_stack(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
61  
62  /**
63   * trace_call_bpf - invoke BPF program
64   * @call: tracepoint event
65   * @ctx: opaque context pointer
66   *
67   * kprobe handlers execute BPF programs via this helper.
68   * Can be used from static tracepoints in the future.
69   *
70   * Return: BPF programs always return an integer which is interpreted by
71   * kprobe handler as:
72   * 0 - return from kprobe (event is filtered out)
73   * 1 - store kprobe event into ring buffer
74   * Other values are reserved and currently alias to 1
75   */
76  unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx)
77  {
78  unsigned int ret;
79  
80  if (in_nmi()) /* not supported yet */
81  return 1;
82  
83  preempt_disable();
84  
85  if (unlikely(__this_cpu_inc_return(bpf_prog_active) != 1)) {
86  /*
87   * since some bpf program is already running on this 
cpu,
88   * don't call into another bpf program (same or 
different)
89   * and don't send kprobe event into ring-buffer,
90   * so return zero here
91   */
92  ret = 0;
93  goto out;
94  }
95  
96  /*
97   * Instead of moving 
rcu_read_lock/rcu_dereference/rcu_read_unlock
98   * to all call sites, we did a bpf_prog_array_valid() there to 
check
99   * whether call->prog_array is empty or not, which is
   100   * a heurisitc to speed up execution.
   101   *
   102   * If 

Re: [PATCH v6 0/3] Allow accessing CSR using CSR number

2019-04-30 Thread Palmer Dabbelt

On Thu, 25 Apr 2019 01:38:24 PDT (-0700), Anup Patel wrote:

This patch series adds support to access CSR using both CSR name and
CSR numbers.

Also, we should prefer accessing CSRs using their CSR numbers because:
1. It compiles fine with older toolchains.
2. We can use latest CSR names in #define macro names of CSR numbers
   as-per RISC-V spec. (e.g. sptbr => CSR_SATP, sbadaddr => CSR_STVAL, etc.)
3. We can access newly added CSRs even if toolchain does not recognize
   newly addes CSRs by name. (e.g. BSSTATUS, BSIE, SSIP, etc.)

The patchset can be found in riscv_csr_number_v6 branch of
https//github.com/avpatel/linux.git

Changes since v5:
 - Drop redundant INTERRUPT_CAUSE_FLAG from kernel/irq.c

Changes since v4:
 - Express SCAUSE_IRQ_FLAG in-terms of __riscv_xlen

Changes since v3:
 - Keep old INTERRUPT_xyz defines in kernel/irq.c for PATCH2

Changes since v2:
 - Dropped PATCH1 which added asm/encoding.h
 - Added new PATCH1 which beautifies asm/csr.h by using tabs to
   align macro values

Changes since v1:
 - Squash PATCH2 into cpatch3
 - Added new PATCH2 to add interrupt related SCAUSE defines
   in asm/encoding.h

Anup Patel (3):
  RISC-V: Use tabs to align macro values in asm/csr.h
  RISC-V: Add interrupt related SCAUSE defines in asm/csr.h
  RISC-V: Access CSRs using CSR numbers

 arch/riscv/include/asm/csr.h | 123 +--
 arch/riscv/include/asm/irqflags.h|  10 +--
 arch/riscv/include/asm/mmu_context.h |   7 +-
 arch/riscv/kernel/entry.S|  22 ++---
 arch/riscv/kernel/head.S |  12 +--
 arch/riscv/kernel/irq.c  |  16 +---
 arch/riscv/kernel/perf_event.c   |   4 +-
 arch/riscv/kernel/smp.c  |   2 +-
 arch/riscv/kernel/traps.c|   6 +-
 arch/riscv/mm/fault.c|   6 +-
 10 files changed, 111 insertions(+), 97 deletions(-)

--
2.17.1


Thanks.  I've added these to for-next with a minor merge conflict, but I think
I managed to avoid screwing it up!


Re: PSCI version 1.1 and SYSTEM_RESET2

2019-04-30 Thread Sodagudi Prasad

On 2019-04-30 14:44, Sodagudi Prasad wrote:
+Sudeep


Hi Mark/Will,

I would like to understand whether ARM linux community have plans to
support PSCI version 1.1 or not.
PSCI_1_1 specification introduced support for SYSTEM_RESET2 command
and this new command helps mobile devices to SYSTEM_WARM_RESET
support. Rebooting devices with warm reboot helps to capture the
snapshot of the ram contents for post-mortem analysis.


I think, there is a recent discussion from Sudeep for the SYSTEM_RESET2 
support.

https://patchwork.kernel.org/patch/10884345/


Hi Sudeep,

I was going through your discussion in the below list -
https://lore.kernel.org/lkml/d73d3580-4ec1-a281-4585-5c776fc08...@xilinx.com/

There is no provision to set up reboot mode dynamically instead kernel 
command line parameter.
Looking for options to reboot device with warm reboot option when kernel 
crashed.


panic() --> emergency_restart() --> machine_emergency_restart() --> 
machine_restart(NULL);


It would nice if there is a config option to reboot the device either in 
warm or cold in the case of kernel panic.
Calling machine_restart with a NULL parameter for kernel crash is 
leading to devices cold reboot.


-Thanks, Prasad



-Thanks, Prasad


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

Linux Foundation Collaborative Project


kobject_init_and_add() confusion

2019-04-30 Thread Tobin C. Harding
Hi,

Looks like I've created a bit of confusion trying to fix memleaks in
calls to kobject_init_and_add().  Its spread over various patches and
mailing lists so I'm starting a new thread and CC'ing anyone that
commented on one of those patches.

If there is a better way to go about this discussion please do tell me.

The problem
---

Calls to kobject_init_and_add() are leaking memory throughout the kernel
because of how the error paths are handled.

The solution


Write the error path code correctly.

Example
---

We have samples/kobject/kobject-example.c but it uses
kobject_create_and_add().  I thought of adding another example file here
but could not think of how to do it off the top of my head without being
super contrived.  Can add this to the TODO list if it will help.

Here is an attempted canonical usage of kobject_init_and_add() typical
of the code that currently is getting it wrong.  This is the second time
I've written this and the first time it was wrong even after review (you
know who you are, you are definitely buying the next round of drinks :)


Assumes we have an object in memory already that has the kobject
embedded in it. Variable 'kobj' below would typically be >kobj


void fn(void)
{
int ret;

ret = kobject_init_and_add(kobj, ktype, NULL, "foo");
if (ret) {
/*
 * This means kobject_init() has succeeded
 * but kobject_add() failed.
 */
goto err_put;
}

ret = some_init_fn();
if (ret) {
/*
 * We need to wind back kobject_add() AND kobject_put().
 * kobject_add() incremented the refcount in
 * kobj->parent, that needs to be decremented THEN we 
need
 * the call to kobject_put() to decrement the refcount 
of kobj.
 */
goto err_del;
}

ret = some_other_init_fn();
if (ret)
goto other_err;

kobject_uevent(kobj, KOBJ_ADD);
return 0;

other_err:
other_clean_up_fn();
err_del:
kobject_del(kobj);
err_put:
kobject_put(kobj);

return ret;
}


Have I got this correct?

TODO


- Fix all the callsites to kobject_init_and_add()
- Further clarify the function docstring for kobject_init_and_add() [perhaps]
- Add a section to Documentation/kobject.txt [optional]
- Add a sample usage file under samples/kobject [optional]


Thanks,
Tobin.


Re: [PATCH v4 3/3] dt-bindings: power: supply: Add bindings for Microchip UCS1002

2019-04-30 Thread Guenter Roeck

On 4/30/19 3:32 PM, Rob Herring wrote:

On Tue, Apr 30, 2019 at 09:15:42AM -0700, Guenter Roeck wrote:

On Mon, Apr 29, 2019 at 11:45:57PM -0700, Andrey Smirnov wrote:

Add bindings for Microchip UCS1002 Programmable USB Port Power
Controller with Charger Emulation.

Signed-off-by: Andrey Smirnov 
Cc: Enric Balletbo Serra 
Cc: Chris Healy 
Cc: Lucas Stach 
Cc: Fabio Estevam 
Cc: Guenter Roeck 
Cc: Rob Herring 
Cc: devicet...@vger.kernel.org
Cc: Sebastian Reichel 
Cc: linux-kernel@vger.kernel.org
Cc: linux...@vger.kernel.org
---
  .../power/supply/microchip,ucs1002.txt| 27 +++
  1 file changed, 27 insertions(+)
  create mode 100644 
Documentation/devicetree/bindings/power/supply/microchip,ucs1002.txt

diff --git 
a/Documentation/devicetree/bindings/power/supply/microchip,ucs1002.txt 
b/Documentation/devicetree/bindings/power/supply/microchip,ucs1002.txt
new file mode 100644
index ..021fd7aba75e
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/supply/microchip,ucs1002.txt
@@ -0,0 +1,27 @@
+Microchip UCS1002 USB Port Power Controller
+
+Required properties:
+- compatible   : Should be "microchip,ucs1002";
+- reg  : I2C slave address
+
+Optional properties:
+- interrupts-extended  : A list of interrupts lines present (could be either
+ corresponding to A_DET# pin, ALERT# pin, or both)


Just make this 'interrupts'. Support for 'interrupts-extended' is
implied.

With that,

Reviewed-by: Rob Herring 


+- interrupt-names  : A list of interrupt names. Should contain (if
+ present):
+ - "a_det" for line connected to A_DET# pin
+ - "alert" for line connected to ALERT# pin
+ Both are expected to be IRQ_TYPE_EDGE_BOTH
+Example:
+
+ {
+   charger@32 {
+   compatible = "microchip,ucs1002";
+   pinctrl-names = "default";
+   pinctrl-0 = <_ucs1002_pins>;


Document the above ? Or is that optional ?


I would have said to document this, but recently we had some discussion
about allowing this to be implied when there's only a 'default' entry.
We'll add it automatically for schemas.



Good to know. Thanks for the information!

Guenter


Re: [PATCH v1] mmc: dt: add DT bindings for ls1028a eSDHC host controller

2019-04-30 Thread Li Yang
On Tue, Apr 30, 2019 at 12:16 AM Yinbo Zhu  wrote:
>
> From: Yinbo Zhu 

The patch title better to be "dt-bindings: mmc: ..."
>
> Add "fsl,ls1028a-esdhc" bindings for ls1028a eSDHC host controller
>
> Signed-off-by: Yinbo Zhu 
> ---
>  .../devicetree/bindings/mmc/fsl-esdhc.txt  |1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/mmc/fsl-esdhc.txt 
> b/Documentation/devicetree/bindings/mmc/fsl-esdhc.txt
> index 99c5cf8..a7250b9 100644
> --- a/Documentation/devicetree/bindings/mmc/fsl-esdhc.txt
> +++ b/Documentation/devicetree/bindings/mmc/fsl-esdhc.txt
> @@ -21,6 +21,7 @@ Required properties:
> "fsl,ls1043a-esdhc"
> "fsl,ls1046a-esdhc"
> "fsl,ls2080a-esdhc"
> +   "fsl,ls1028a-esdhc"

Better to be alphabetical order.

>- clock-frequency : specifies eSDHC base clock frequency.
>
>  Optional properties:
> --
> 1.7.1
>


Re: [PATCH] Revert "PCI/LINK: Report degraded links via link bandwidth notification"

2019-04-30 Thread Lukas Wunner
On Tue, Apr 30, 2019 at 12:05:09PM -0600, Keith Busch wrote:
> On Tue, Apr 30, 2019 at 11:11:51AM -0500, Bjorn Helgaas wrote:
> > > I'm not convinced a revert is the best call.
> > 
> > I have very limited options at this stage of the release, but I'd be
> > glad to hear suggestions.  My concern is that if we release v5.1
> > as-is, we'll spend a lot of energy on those false positives.
> 
> May be too late now if the revert is queued up, but I think this feature
> should have been a default 'false' Kconfig bool rather than always on.

Good idea, this would seem to be a less harsh solution than a revert.

Enabling the feature by default for everyone was probably overly confident.
I recall I did bring up in a review comment that all other port services
have a Kconfig option.  Alex replied that he's not using one because
on device enumeration, downtraining is checked unconditionally as well.

Bandwidth notification might be a feature that's not used by many operating
systems.  Such features don't get much real world exposure or aren't even
validated by manufacturers.  Inevitably, unpleasant side effects occur
once Linux supports them.

However if we keep the code and default to "N" in Kconfig, at least people
get a chance to test and validate the functionality and hopefully this
will lead to either better hardware or better driver support in the future.

Thanks,

Lukas


Re: [PATCH 04/12] mips: Reserve memory for the kernel image resources

2019-04-30 Thread Paul Burton
Hi Serge,

On Fri, Apr 26, 2019 at 03:00:36AM +0300, Serge Semin wrote:
> >  1) Older systems generally had something like an ISA bus which used
> > addresses below the kernel, and bootloaders like YAMON left behind
> > functions that could be called right at the start of RAM. This sort
> > of thing should be accounted for by /memreserve/ in DT or similar
> > platform-specific reservations though rather than generically, and
> > at least Malta & SEAD-3 DTs already have /memreserve/ entries for
> > it. So this part I think is OK. Some other older platforms might
> > need updating, but that's fine.
> > 
> 
> Regarding ISA. As far as I remember devices on that bus can DMA only to the
> lowest 16MB. So in case if kernel is too big or placed pretty much high,
> they may be left even without reachable memory at all in current
> implementation.

Sure - I'm not too worried about these old buses, platforms can continue
to reserve the memory through DT or otherwise if they need to.

> >  2) trap_init() only allocates memory for the exception vector if using
> > a vectored interrupt mode. In other cases it just uses CAC_BASE
> > which currently gets reserved as part of this region between
> > PHYS_OFFSET & _text.
> > 
> > I think this behavior is bogus, and we should instead:
> > 
> > - Allocate the exception vector memory using memblock_alloc() for
> >   CPUs implementing MIPSr2 or higher (ie. CPUs with a programmable
> >   EBase register). If we're not using vectored interrupts then
> >   allocating one page will do, and we already have the size
> >   calculation for if we are.
> > 
> > - Otherwise use CAC_BASE but call memblock_reserve() on the first
> >   page.
> > 
> > I think we should make that change before this one goes in. I can
> > try to get to it tomorrow, but feel free to beat me to it.
> > 
> 
> As far as I understood you and the code this should be enough to fix
> the problem:
> diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
> index 98ca55d62201..f680253e2617 100644
> --- a/arch/mips/kernel/traps.c
> +++ b/arch/mips/kernel/traps.c
> @@ -2326,6 +2326,8 @@ void __init trap_init(void)
>   ebase += (read_c0_ebase() & 0x3000);
>   }
>   }
> +
> + memblock_reserve(ebase, PAGE_SIZE);
>   }
>  
>   if (cpu_has_mmips) {
> ---
> 
> Allocation has already been implemented in the if-branch under the
> (cpu_has_veic || cpu_has_vint) condition. So we don't need to change
> there anything.
> In case if vectored interrupts aren't supported the else-clause is
> taken and we need to reserve whatever is set in the exception base
> address variable.
> 
> I'll add this patch between 3d and 4th ones if you are ok with it.

I think that would work, but I have other motivations to allocate the
memory in non-vectored cases anyway. I just sent a series that does that
& cleans up a little [1]. If you could take a look that would be great.
With that change made I think this patch will be good to apply.

Thanks,
Paul

[1] 
https://lore.kernel.org/linux-mips/20190430225216.7164-1-paul.bur...@mips.com/T/#t


Re: [PATCH v3 5/6] dt-bindings: mfd: max77620: Add maxim,system-power-controller property

2019-04-30 Thread Rob Herring
On Thu, Apr 25, 2019 at 01:48:59AM +0300, Dmitry Osipenko wrote:
> Add new property that designates the PMIC as the system's power
> controller.
> 
> Signed-off-by: Dmitry Osipenko 
> ---
>  Documentation/devicetree/bindings/mfd/max77620.txt | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/mfd/max77620.txt 
> b/Documentation/devicetree/bindings/mfd/max77620.txt
> index 9058499051e0..dda6d158b170 100644
> --- a/Documentation/devicetree/bindings/mfd/max77620.txt
> +++ b/Documentation/devicetree/bindings/mfd/max77620.txt
> @@ -18,6 +18,9 @@ Optional properties:
>   IRQ numbers for different interrupt source of MAX77620
>   are defined at dt-bindings/mfd/max77620.h.
>  
> +- maxim,system-power-controller: Indicates that this PMIC is controlling the
> +  system power.

Drop the 'maxim'. We have a standard property for this.

> +
>  Optional subnodes and their properties:
>  ===
>  
> -- 
> 2.21.0
> 


Re: [PATCH] mm: Fix kobject memleak in SLUB

2019-04-30 Thread Tobin C. Harding
On Sun, Apr 28, 2019 at 09:40:00AM +1000, Tobin C. Harding wrote:
> Currently error return from kobject_init_and_add() is not followed by a
> call to kobject_put().  This means there is a memory leak.
> 
> Add call to kobject_put() in error path of kobject_init_and_add().
> 
> Signed-off-by: Tobin C. Harding 
> ---
>  mm/slub.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/slub.c b/mm/slub.c
> index d30ede89f4a6..84a9d6c06c27 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -5756,8 +5756,10 @@ static int sysfs_slab_add(struct kmem_cache *s)
>  
>   s->kobj.kset = kset;
>   err = kobject_init_and_add(>kobj, _ktype, NULL, "%s", name);
> - if (err)
> + if (err) {
> + kobject_put(>kobj);
>   goto out;
> + }
>  
>   err = sysfs_create_group(>kobj, _attr_group);
>   if (err)
> -- 
> 2.21.0
> 

This patch is not _completely_ correct.  Please do not consider for
merge.  There are a bunch of these on various LKML lists, once the
confusion has cleared I'll re-spin v2.

thanks,
Tobin.


Re: [PATCH v3 4/6] dt-bindings: mfd: max77620: Add compatible for Maxim 77663

2019-04-30 Thread Rob Herring
On Thu, Apr 25, 2019 at 01:48:58AM +0300, Dmitry Osipenko wrote:
> Maxim 77663 has a few minor differences in regards to hardware interface
> and available capabilities by comparing it with 77620 and 20024 models,
> hence re-use 77620 device-tree binding for the 77663.
> 
> Signed-off-by: Dmitry Osipenko 
> ---
>  Documentation/devicetree/bindings/mfd/max77620.txt | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/devicetree/bindings/mfd/max77620.txt 
> b/Documentation/devicetree/bindings/mfd/max77620.txt
> index 9c16d51cc15b..9058499051e0 100644
> --- a/Documentation/devicetree/bindings/mfd/max77620.txt
> +++ b/Documentation/devicetree/bindings/mfd/max77620.txt
> @@ -4,7 +4,8 @@ Required properties:
>  ---
>  - compatible: Must be one of
>   "maxim,max77620"
> - "maxim,max20024".
> + "maxim,max20024"
> + "maxim,max77663".

Drop the period so we don't have to remove it on the next addition.

With that,

Reviewed-by: Rob Herring 

>  - reg: I2C device address.
>  
>  Optional properties:
> @@ -105,6 +106,7 @@ Optional properties:
>  Here supported time periods by device in microseconds are as follows:
>  MAX77620 supports 40, 80, 160, 320, 640, 1280, 2560 and 5120 microseconds.
>  MAX20024 supports 20, 40, 80, 160, 320, 640, 1280 and 2540 microseconds.
> +MAX77663 supports 20, 40, 80, 160, 320, 640, 1280 and 2540 microseconds.
>  
>  -maxim,power-ok-control: configure map power ok bit
>   1: Enables POK(Power OK) to control nRST_IO and GPIO1
> -- 
> 2.21.0
> 


[PATCHv2 01/10] vfio/mdev: Avoid release parent reference during error path

2019-04-30 Thread Parav Pandit
During mdev parent registration in mdev_register_device(),
if parent device is duplicate, it releases the reference of existing
parent device.
This is incorrect. Existing parent device should not be touched.

Fixes: 7b96953bc640 ("vfio: Mediated device Core driver")
Reviewed-by: Cornelia Huck 
Reviewed By: Kirti Wankhede 
Reviewed-by: Maxim Levitsky 
Signed-off-by: Parav Pandit 
---
 drivers/vfio/mdev/mdev_core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
index b96fedc77ee5..1299d2e72ce2 100644
--- a/drivers/vfio/mdev/mdev_core.c
+++ b/drivers/vfio/mdev/mdev_core.c
@@ -181,6 +181,7 @@ int mdev_register_device(struct device *dev, const struct 
mdev_parent_ops *ops)
/* Check for duplicate */
parent = __find_parent_device(dev);
if (parent) {
+   parent = NULL;
ret = -EEXIST;
goto add_dev_err;
}
-- 
2.19.2



[PATCHv2 04/10] vfio/mdev: Avoid masking error code to EBUSY

2019-04-30 Thread Parav Pandit
Instead of masking return error to -EBUSY, return actual error
returned by the driver.

Reviewed-by: Cornelia Huck 
Reviewed-by: Maxim Levitsky 
Signed-off-by: Parav Pandit 
---
 drivers/vfio/mdev/mdev_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
index 00ca61392de9..836d31985f14 100644
--- a/drivers/vfio/mdev/mdev_core.c
+++ b/drivers/vfio/mdev/mdev_core.c
@@ -141,7 +141,7 @@ static int mdev_device_remove_ops(struct mdev_device *mdev, 
bool force_remove)
 */
ret = parent->ops->remove(mdev);
if (ret && !force_remove)
-   return -EBUSY;
+   return ret;
 
sysfs_remove_groups(>dev.kobj, parent->ops->mdev_attr_groups);
return 0;
-- 
2.19.2



[PATCHv2 02/10] vfio/mdev: Removed unused kref

2019-04-30 Thread Parav Pandit
Remove unused kref from the mdev_device structure.

Fixes: 7b96953bc640 ("vfio: Mediated device Core driver")
Reviewed-by: Cornelia Huck 
Reviewed By: Kirti Wankhede 
Reviewed-by: Maxim Levitsky 
Signed-off-by: Parav Pandit 
---
 drivers/vfio/mdev/mdev_core.c| 1 -
 drivers/vfio/mdev/mdev_private.h | 1 -
 2 files changed, 2 deletions(-)

diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
index 1299d2e72ce2..00ca61392de9 100644
--- a/drivers/vfio/mdev/mdev_core.c
+++ b/drivers/vfio/mdev/mdev_core.c
@@ -311,7 +311,6 @@ int mdev_device_create(struct kobject *kobj,
mutex_unlock(_list_lock);
 
mdev->parent = parent;
-   kref_init(>ref);
 
mdev->dev.parent  = dev;
mdev->dev.bus = _bus_type;
diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h
index 379758c52b1b..ddcf9c72bd8a 100644
--- a/drivers/vfio/mdev/mdev_private.h
+++ b/drivers/vfio/mdev/mdev_private.h
@@ -30,7 +30,6 @@ struct mdev_device {
struct mdev_parent *parent;
guid_t uuid;
void *driver_data;
-   struct kref ref;
struct list_head next;
struct kobject *type_kobj;
bool active;
-- 
2.19.2



[PATCHv2 06/10] vfio/mdev: Fix aborting mdev child device removal if one fails

2019-04-30 Thread Parav Pandit
device_for_each_child() stops executing callback function for remaining
child devices, if callback hits an error.
Each child mdev device is independent of each other.
While unregistering parent device, mdev core must remove all child mdev
devices.
Therefore, mdev_device_remove_cb() always returns success so that
device_for_each_child doesn't abort if one child removal hits error.

While at it, improve remove and unregister functions for below simplicity.

There isn't need to pass forced flag pointer during mdev parent
removal which invokes mdev_device_remove(). So simplify the flow.

mdev_device_remove() is called from two paths.
1. mdev_unregister_driver()
 mdev_device_remove_cb()
   mdev_device_remove()
2. remove_store()
 mdev_device_remove()

Fixes: 7b96953bc640 ("vfio: Mediated device Core driver")
Reviewed-by: Maxim Levitsky 
Signed-off-by: Parav Pandit 
---
 drivers/vfio/mdev/mdev_core.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
index 836d31985f14..1a317e409355 100644
--- a/drivers/vfio/mdev/mdev_core.c
+++ b/drivers/vfio/mdev/mdev_core.c
@@ -149,10 +149,10 @@ static int mdev_device_remove_ops(struct mdev_device 
*mdev, bool force_remove)
 
 static int mdev_device_remove_cb(struct device *dev, void *data)
 {
-   if (!dev_is_mdev(dev))
-   return 0;
+   if (dev_is_mdev(dev))
+   mdev_device_remove(dev, true);
 
-   return mdev_device_remove(dev, data ? *(bool *)data : true);
+   return 0;
 }
 
 /*
@@ -240,7 +240,6 @@ EXPORT_SYMBOL(mdev_register_device);
 void mdev_unregister_device(struct device *dev)
 {
struct mdev_parent *parent;
-   bool force_remove = true;
 
mutex_lock(_list_lock);
parent = __find_parent_device(dev);
@@ -254,8 +253,7 @@ void mdev_unregister_device(struct device *dev)
list_del(>next);
class_compat_remove_link(mdev_bus_compat_class, dev, NULL);
 
-   device_for_each_child(dev, (void *)_remove,
- mdev_device_remove_cb);
+   device_for_each_child(dev, NULL, mdev_device_remove_cb);
 
parent_remove_sysfs_files(parent);
 
-- 
2.19.2



Re: [PATCH v3 1/3] dt-bindings: net: add qca,ar71xx.txt documentation

2019-04-30 Thread Rob Herring
On Mon, Apr 22, 2019 at 08:40:44AM +0200, Oleksij Rempel wrote:
> Add binding documentation for Atheros/QCA networking IP core used
> in many routers.
> 
> Signed-off-by: Oleksij Rempel 
> ---
>  .../devicetree/bindings/net/qca,ar71xx.txt| 44 +++
>  1 file changed, 44 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/net/qca,ar71xx.txt
> 
> diff --git a/Documentation/devicetree/bindings/net/qca,ar71xx.txt 
> b/Documentation/devicetree/bindings/net/qca,ar71xx.txt
> new file mode 100644
> index ..56abf224de2c
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/net/qca,ar71xx.txt
> @@ -0,0 +1,44 @@

Needs some title and info about what this h/w is.

> +Required properties:
> +- compatible:Should be "qca,-eth". Currently support 
> compatibles are:
> + qca,ar7100-eth - Atheros AR7100
> + qca,ar7240-eth - Atheros AR7240
> + qca,ar7241-eth - Atheros AR7241
> + qca,ar7242-eth - Atheros AR7242
> + qca,ar9130-eth - Atheros AR9130
> + qca,ar9330-eth - Atheros AR9330
> + qca,ar9340-eth - Atheros AR9340
> + qca,qca9530-eth - Qualcomm Atheros QCA9530
> + qca,qca9550-eth - Qualcomm Atheros QCA9550
> + qca,qca9560-eth - Qualcomm Atheros QCA9560
> +
> +- reg : Address and length of the register set for the device
> +- interrupts : Should contain eth interrupt
> +- phy-mode : See ethernet.txt file in the same directory

Is there a subset of valid modes?

> +- clocks: the clock used by the core
> +- clock-names: the names of the clock listed in the clocks property. These 
> are
> + "mdio".

Seems strange that's the only clock.

> +- resets: Should contain phandles to the reset signals
> +- reset-names: Should contain the names of reset signal listed in the resets
> + property. These are "mac" and "mdio"
> +
> +Optional properties:
> +- phy-handle : phandle to the PHY device connected to this device.
> +- fixed-link : Assume a fixed link. See fixed-link.txt in the same directory.
> +  Use instead of phy-handle.
> +
> +Optional subnodes:
> +- mdio : specifies the mdio bus, used as a container for phy nodes
> +  according to phy.txt in the same directory
> +
> +Example:
> +
> +ethernet@1a00 {
> + compatible = "qca,ar9330-eth";
> + reg = <0x1a00 0x200>;
> + interrupts = <5>;
> + resets = < 13>, < 23>;
> + reset-names = "mac", "mdio";
> + clocks = < ATH79_CLK_MDIO>;
> + clock-names = "mdio";
> + phy-mode = "gmii";
> +};
> -- 
> 2.20.1
> 


[PATCHv2 07/10] vfio/mdev: Avoid inline get and put parent helpers

2019-04-30 Thread Parav Pandit
As section 15 of Documentation/process/coding-style.rst clearly
describes that compiler will be able to optimize code.

Hence drop inline for get and put helpers for parent.

Signed-off-by: Parav Pandit 
---
 drivers/vfio/mdev/mdev_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
index 1a317e409355..1040a4a2dcbc 100644
--- a/drivers/vfio/mdev/mdev_core.c
+++ b/drivers/vfio/mdev/mdev_core.c
@@ -88,7 +88,7 @@ static void mdev_release_parent(struct kref *kref)
put_device(dev);
 }
 
-static inline struct mdev_parent *mdev_get_parent(struct mdev_parent *parent)
+static struct mdev_parent *mdev_get_parent(struct mdev_parent *parent)
 {
if (parent)
kref_get(>ref);
@@ -96,7 +96,7 @@ static inline struct mdev_parent *mdev_get_parent(struct 
mdev_parent *parent)
return parent;
 }
 
-static inline void mdev_put_parent(struct mdev_parent *parent)
+static void mdev_put_parent(struct mdev_parent *parent)
 {
if (parent)
kref_put(>ref, mdev_release_parent);
-- 
2.19.2



  1   2   3   4   5   6   7   8   9   10   >