[PATCH] perf record: Set PERF_RECORD_SAMPLE if attr->freq is set.

2020-07-26 Thread Ian Rogers
From: David Sharp 

evsel__config() would only set PERF_RECORD_SAMPLE if it set attr->freq
from perf record options. When it is set by libpfm events, it would not
get set. This changes evsel__config to see if attr->freq is set outside of
whether or not it changes attr->freq itself.

Signed-off-by: David Sharp 
Signed-off-by: Ian Rogers 
---
 tools/perf/util/evsel.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index ef802f6d40c1..811f538f7d77 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -979,13 +979,18 @@ void evsel__config(struct evsel *evsel, struct 
record_opts *opts,
if (!attr->sample_period || (opts->user_freq != UINT_MAX ||
 opts->user_interval != ULLONG_MAX)) {
if (opts->freq) {
-   evsel__set_sample_bit(evsel, PERIOD);
attr->freq  = 1;
attr->sample_freq   = opts->freq;
} else {
attr->sample_period = opts->default_interval;
}
}
+   /*
+* If attr->freq was set (here or earlier), ask for period
+* to be sampled.
+*/
+   if (attr->freq)
+   evsel__set_sample_bit(evsel, PERIOD);
 
if (opts->no_samples)
attr->sample_freq = 0;
-- 
2.28.0.rc0.142.g3c755180ce-goog



Re: [PATCH v9 02/12] ata: ahci_brcm: Fix use of BCM7216 reset controller

2020-07-26 Thread Philipp Zabel
Hi Jim,

On Fri, 2020-07-24 at 16:33 -0400, Jim Quinlan wrote:
> From: Jim Quinlan 
> 
> A reset controller "rescal" is shared between the AHCI driver and the PCIe
> driver for the BrcmSTB 7216 chip.  Use
> devm_reset_control_get_optional_shared() to handle this sharing.
> 
> Signed-off-by: Jim Quinlan 
> 
> Fixes: 272ecd60a636 ("ata: ahci_brcm: BCM7216 reset is self de-asserting")
> Fixes: c345ec6a50e9 ("ata: ahci_brcm: Support BCM7216 reset controller name")
> ---
>  drivers/ata/ahci_brcm.c | 11 +++
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/ata/ahci_brcm.c b/drivers/ata/ahci_brcm.c
> index 6853dbb4131d..d6115bc04b09 100644
> --- a/drivers/ata/ahci_brcm.c
> +++ b/drivers/ata/ahci_brcm.c
> @@ -428,7 +428,6 @@ static int brcm_ahci_probe(struct platform_device *pdev)
>  {
>   const struct of_device_id *of_id;
>   struct device *dev = &pdev->dev;
> - const char *reset_name = NULL;
>   struct brcm_ahci_priv *priv;
>   struct ahci_host_priv *hpriv;
>   struct resource *res;
> @@ -452,11 +451,10 @@ static int brcm_ahci_probe(struct platform_device *pdev)
>  
>   /* Reset is optional depending on platform and named differently */
>   if (priv->version == BRCM_SATA_BCM7216)
> - reset_name = "rescal";
> + priv->rcdev = 
> devm_reset_control_get_optional_shared(&pdev->dev, "rescal");
>   else
> - reset_name = "ahci";
> + priv->rcdev = devm_reset_control_get_optional(&pdev->dev, 
> "ahci");

Please use devm_reset_control_get_optional_exclusive() here.

>  
> - priv->rcdev = devm_reset_control_get_optional(&pdev->dev, reset_name);
>   if (IS_ERR(priv->rcdev))
>   return PTR_ERR(priv->rcdev);
>  
> @@ -479,10 +477,7 @@ static int brcm_ahci_probe(struct platform_device *pdev)
>   break;
>   }
>  
> - if (priv->version == BRCM_SATA_BCM7216)
> - ret = reset_control_reset(priv->rcdev);
> - else
> - ret = reset_control_deassert(priv->rcdev);
> + ret = reset_control_deassert(priv->rcdev);
>   if (ret)
>   return ret;
>  

Since you switch from _reset to _deassert/_assert here, I suspect you
should also change the out_reset error path, and the suspend/resume
functions accordingly.

regards
Philipp


linux-next: build failure after merge of the driver-core tree

2020-07-26 Thread Stephen Rothwell
Hi all,

After merging the driver-core tree, today's linux-next build (x86_64
allmodconfig) failed like this:

In file included from include/linux/dmi.h:5,
 from drivers/firmware/efi/embedded-firmware.c:8:
drivers/firmware/efi/embedded-firmware.c:25:38: error: static declaration of 
'efi_embedded_fw_list' follows non-static declaration
   25 | EFI_EMBEDDED_FW_VISIBILITY LIST_HEAD(efi_embedded_fw_list);
  |  ^~~~
include/linux/list.h:24:19: note: in definition of macro 'LIST_HEAD'
   24 |  struct list_head name = LIST_HEAD_INIT(name)
  |   ^~~~
In file included from drivers/firmware/efi/embedded-firmware.c:17:
drivers/firmware/efi/embedded-firmware.h:16:25: note: previous declaration of 
'efi_embedded_fw_list' was here
   16 | extern struct list_head efi_embedded_fw_list;
  | ^~~~
drivers/firmware/efi/embedded-firmware.c:26:33: error: static declaration of 
'efi_embedded_fw_checked' follows non-static declaration
   26 | EFI_EMBEDDED_FW_VISIBILITY bool efi_embedded_fw_checked;
  | ^~~
In file included from drivers/firmware/efi/embedded-firmware.c:17:
drivers/firmware/efi/embedded-firmware.h:17:13: note: previous declaration of 
'efi_embedded_fw_checked' was here
   17 | extern bool efi_embedded_fw_checked;
  | ^~~

Caused by commit

  2d38dbf89a06 ("test_firmware: Test platform fw loading on non-EFI systems")

CONFIG_TEST_FIRMWARE=m for this build.

I have used the driver-core tree from next-20200724 for today.

-- 
Cheers,
Stephen Rothwell


pgp0QhfjJtpCh.pgp
Description: OpenPGP digital signature


Re: checkpatch: support deprecated terms checking

2020-07-26 Thread SeongJae Park
On Sun, 26 Jul 2020 22:33:28 +0200 "Michał Mirosław"  
wrote:

> On Sun, Jul 26, 2020 at 08:07:48PM +0200, SeongJae Park wrote:
> > On Sun, 26 Jul 2020 09:42:06 -0700 Joe Perches  wrote:
> > 
> > > On Sun, 2020-07-26 at 17:36 +0200, SeongJae Park wrote:
> > > > On Sun, 26 Jul 2020 07:50:54 -0700 Joe Perches  wrote:
> > > []
> > > > > I do not want to encourage relatively inexperienced people
> > > > > to run checkpatch and submit inappropriate patches.
> > > > 
> > > > Me, neither.  But, I think providing more warnings and references is 
> > > > better for
> > > > that.
> > > 
> > > Unfortunately, the inexperienced _do_ in fact run
> > > checkpatch on files and submit inappropriate patches.
> > > 
> > > It's generally a time sink for the experienced
> > > maintainers to reply.
> > > 
> > > > Simply limiting checks could allow people submitting inappropriate 
> > > > patches
> > > > intorducing new uses of deprecated terms.
> > > 
> > > Tradeoffs...
> > > 
> > > I expect that patches being reviewed by maintainers
> > > are preferred over files being inappropriately changed
> > > by the inexperienced.
> > > 
> > > Those inappropriate changes should not be encouraged
> > > by tools placed in the hands of the inexperienced.
> > 
> > Right, many things are tradeoff.  Seems we arrived in the point, though we
> > still have different opinions.  To summarize the pros and cons of my patch 
> > from
> > my perspective:
> > 
> > Pros 1: Handle future terms deprecated with different reasons and coverages.
> > Pros 2: Inappropriate patches are avoided if the submitters carefully read 
> > the
> > warning messages.
> > Cons: Careless people could still bother maintainers by not carefully 
> > reading
> > the message and sending inappropriate patches.
> > 
> > To me, the pros still seems larger than the cons.  I would like to also 
> > again
> > mention that the maintainer who first reported the problem, Michal, told 
> > it's
> > ok with the explicit messaging.  Nonethelss, this is just my opinion.
> > 
> > Attaching the patch addressing your comments for the previous version.  The
> > changes from the previous version are:
> > 
> >  - Make the name of reported terms not too verbose
> >  - Avoid unnecessary initialization of the reported terms hash
> >  - Warn multiple deprecated terms in same line
> 
> Hi,
> 
> Maybe you could split the meaning of --subjective and --strict, and
> enable those checks only for --subjective? The test is really hard to do
> right: you would have to consider the context and not only mere occurrence
> of a word (heh, I even wrote 'blacklisted' here, since it really is about
> a night/danger analogy and not political/ethical one).

I'm concerning if applying the switch and making this patch non-default could
reduce the check coverage.  Moreover, IMHO, the deprecation rule of the terms
that described in the 'coding-style.rst' is not so subjective but clear.  Also,
the checkpatch's warning/check message for those seems explicit enough to me.

And, the deprecated terms feature is not for this specific terms
(master/slave/blacklist/whitelist) only but general deprecated terms.  Maybe we
could add one more rule in the 'deprecated_terms.txt' by adding a comment, say,
"Please add only terms that deprecated with clear rules", for avoiding
introduce of subjective deprecated terms in future, though.


Thanks,
SeongJae Park

> 
> Best Regards,
> Michał Mirosław


Re: [PATCH v2] lib: Verify array index is correct before using it

2020-07-26 Thread Herbert Xu
On Mon, Jul 27, 2020 at 02:59:10AM -0400, Huang Guobin wrote:
> This code reads from the array before verifying that "c" is a valid
> index. Move test array offset code before use to fix it.
> 
> Fixes: 2da572c959dd ("lib: add software 842 compression/decompression")
> Signed-off-by: Huang Guobin 
> ---
>  lib/842/842_compress.c | 9 +++--
>  1 file changed, 7 insertions(+), 2 deletions(-)

Please post this to linux-cry...@vger.kernel.org.

Thanks,
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


Re: [PATCH 0/9] powerpc: delete duplicated words

2020-07-26 Thread Joe Perches
On Sun, 2020-07-26 at 12:08 -0700, Randy Dunlap wrote:

> v0.1 of this script also found lots of repeated numbers and strings of
> special characters (ASCII art etc.), so now it ignores duplicated numbers
> or special characters -- since it is really looking for duplicate words.
> 
> Anyway, I might as well attach it. It's no big deal.
> And if someone else wants to tackle using it, go for it.

This might be a reasonable thing to add to checkpatch.

And here's another possible similar perl word deduplicator attached:

Assuming you have git, this could be used like:

$ git ls-files --  | xargs perl deduplicate_words.pl

And it would overwrite all files with duplicated words.

No guarantees any changes it makes are right of course.
It still needs a human to verify any change.

For instance:

$ git ls-files kernel/trace/*.[ch] | xargs perl deduplicate_words.pl
$ git diff kernel/trace
 kernel/trace/ftrace.c | 2 +-
 kernel/trace/trace.c  | 2 +-
 kernel/trace/trace_dynevent.c | 2 +-
 kernel/trace/trace_events_synth.c | 2 +-
 kernel/trace/tracing_map.c| 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index a3093a84bae3..b7f085a4f71a 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -2405,7 +2405,7 @@ struct ftrace_ops direct_ops = {
  *
  * If the record has the FTRACE_FL_REGS set, that means that it
  * wants to convert to a callback that saves all regs. If FTRACE_FL_REGS
- * is not not set, then it wants to convert to the normal callback.
+ * is not set, then it wants to convert to the normal callback.
  *
  * Returns the address of the trampoline to set to
  */
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 5aa5c01e2fed..4d3dcfb06d6d 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -9253,7 +9253,7 @@ void ftrace_dump(enum ftrace_dump_mode oops_dump_mode)
 
/*
 * We need to stop all tracing on all CPUS to read the
-* the next buffer. This is a bit expensive, but is
+* next buffer. This is a bit expensive, but is
 * not done often. We fill all what we can read,
 * and then release the locks again.
 */
diff --git a/kernel/trace/trace_dynevent.c b/kernel/trace/trace_dynevent.c
index 2c435fdef565..8c1e7e168505 100644
--- a/kernel/trace/trace_dynevent.c
+++ b/kernel/trace/trace_dynevent.c
@@ -402,7 +402,7 @@ void dynevent_arg_init(struct dynevent_arg *arg,
  * whitespace, all followed by a separator, if applicable.  After the
  * first arg string is successfully appended to the command string,
  * the optional @operator is appended, followed by the second arg and
- * and optional @separator.  If no separator was specified when
+ * optional @separator.  If no separator was specified when
  * initializing the arg, a space will be appended.
  */
 void dynevent_arg_pair_init(struct dynevent_arg_pair *arg_pair,
diff --git a/kernel/trace/trace_events_synth.c 
b/kernel/trace/trace_events_synth.c
index e2a623f2136c..3801d3088744 100644
--- a/kernel/trace/trace_events_synth.c
+++ b/kernel/trace/trace_events_synth.c
@@ -1211,7 +1211,7 @@ __synth_event_trace_start(struct trace_event_file *file,
 * ENABLED bit is set (which attaches the probe thus allowing
 * this code to be called, etc).  Because this is called
 * directly by the user, we don't have that but we still need
-* to honor not logging when disabled.  For the the iterated
+* to honor not logging when disabled.  For the iterated
 * trace case, we save the enabed state upon start and just
 * ignore the following data calls.
 */
diff --git a/kernel/trace/tracing_map.c b/kernel/trace/tracing_map.c
index 74738c9856f1..4b50fc0cb12c 100644
--- a/kernel/trace/tracing_map.c
+++ b/kernel/trace/tracing_map.c
@@ -260,7 +260,7 @@ int tracing_map_add_var(struct tracing_map *map)
  * to use cmp_fn.
  *
  * A key can be a subset of a compound key; for that purpose, the
- * offset param is used to describe where within the the compound key
+ * offset param is used to describe where within the compound key
  * the key referenced by this key field resides.
  *
  * Return: The index identifying the field in the map and associated



deduplicate_words.pl
Description: Perl program


RE: [PATCH 03/10] remoteproc: imx: use devm_ioremap

2020-07-26 Thread Peng Fan
> Subject: Re: [PATCH 03/10] remoteproc: imx: use devm_ioremap
> 
> On Mon, Jul 27, 2020 at 06:28:20AM +, Peng Fan wrote:
> > Hi Oleksij,
> >
> > > Subject: Re: [PATCH 03/10] remoteproc: imx: use devm_ioremap
> > >
> > > On Fri, Jul 24, 2020 at 04:08:06PM +0800, Peng Fan wrote:
> > > > We might need to map an region multiple times, becaue the region
> > > > might be shared between remote processors, such i.MX8QM with dual
> M4 cores.
> > > > So use devm_ioremap, not devm_ioremap_resource.
> > >
> > > Can you please give an example of this kind of shared resources and
> > > how they should be handled by two separate devices?
> >
> > This is to share vdevbuffer space, there is a vdevbuffer in device
> > tree, it will be shared between M4_0 and M4_1.
> >
> > For the buffer, it is Linux DMA API will handle the space.
> 
> Why remoteproc need to care about it? If I see it correctly, from the linux
> perspective, it is one buffer and one driver is responsible for it. Or do I 
> missing
> some thing?

We not have the vdev buffer in resource table, so I added in device tree, see 
below:

imx8qm_cm40: imx8qm_cm4@0 {
compatible = "fsl,imx8qm-cm4";
rsc-da = <0x9000>;
mbox-names = "tx", "rx", "rxdb";
mboxes = <&lsio_mu5 0 1
  &lsio_mu5 1 1
  &lsio_mu5 3 1>;
mub-partition = <3>;
memory-region = <&vdev0vring0>, <&vdev0vring1>, <&vdevbuffer>,
<&vdev1vring0>, <&vdev1vring1>;
core-index = <0>;
core-id = ;
status = "okay";
power-domains = <&pd IMX_SC_R_M4_0_PID0>,
<&pd IMX_SC_R_M4_0_MU_1A>;
};

imx8qm_cm41: imx8x_cm4@1 {
compatible = "fsl,imx8qm-cm4";
rsc-da = <0x9010>;
mbox-names = "tx", "rx", "rxdb";
mboxes = <&lsio_mu6 0 1
  &lsio_mu6 1 1
  &lsio_mu6 3 1>;
mub-partition = <4>;
memory-region = <&vdev2vring0>, <&vdev2vring1>, <&vdevbuffer>,
<&vdev3vring0>, <&vdev3vring1>;
core-index = <1>;
core-id = ;
status = "okay";
power-domains = <&pd IMX_SC_R_M4_1_PID0>,
<&pd IMX_SC_R_M4_1_MU_1A>;
};

vdevbuffer: vdevbuffer {
compatible = "shared-dma-pool";
reg = <0 0x9040 0 0x10>;
no-map;
};

I have the upper vdevbuffer node shared between M40 and M41 node.
The vdevbuffer will be used as virtio data buffer.

And I have the following in rproc_add_virtio_dev to share vdevbuffer:
/* Try to find dedicated vdev buffer carveout */
mem = rproc_find_carveout_by_name(rproc, "vdev%dbuffer", rvdev->index);
if (!mem)
mem = rproc_find_carveout_by_name(rproc, "vdevbuffer");


Hope this is clear.


Thanks,
Peng.

> 
> > Thanks,
> > Peng.
> >
> > >
> > > > Reviewed-by: Richard Zhu 
> > > > Signed-off-by: Peng Fan 
> > > > ---
> > > >  drivers/remoteproc/imx_rproc.c | 5 +++--
> > > >  1 file changed, 3 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/drivers/remoteproc/imx_rproc.c
> > > > b/drivers/remoteproc/imx_rproc.c index 3b3904ebac75..82594a800a1b
> > > > 100644
> > > > --- a/drivers/remoteproc/imx_rproc.c
> > > > +++ b/drivers/remoteproc/imx_rproc.c
> > > > @@ -296,9 +296,10 @@ static int imx_rproc_addr_init(struct
> > > > imx_rproc
> > > *priv,
> > > > if (b >= IMX7D_RPROC_MEM_MAX)
> > > > break;
> > > >
> > > > -   priv->mem[b].cpu_addr =
> devm_ioremap_resource(&pdev->dev,
> > > &res);
> > > > +   /* Not use resource version, because we might share 
> > > > region*/
> > > > +   priv->mem[b].cpu_addr = devm_ioremap(&pdev->dev,
> res.start,
> > > > +resource_size(&res));
> > > > if (IS_ERR(priv->mem[b].cpu_addr)) {
> > > > -   dev_err(dev, "devm_ioremap_resource failed\n");
> > > > +   dev_err(dev, "devm_ioremap %pR failed\n", &res);
> > > > err = PTR_ERR(priv->mem[b].cpu_addr);
> > > > return err;
> > > > }
> > > > --
> > > > 2.16.4
> > > >
> > > >
> > >
> > > --
> > > Pengutronix e.K.   |
> > > |
> > > Steuerwalder Str. 21   |
> > > http://www.pengutronix.de/  |
> > > 31137 Hildesheim, Germany  | Phone:
> > > +49-5121-206917-0|
> > > Amtsgericht Hildesheim, HRA 2686   | Fax:
> > > +49-5121-206917- |
> 
> --
> Pengutronix e.K.   |
> |
> Steuerwalder Str. 21   |
> http://www.pengutronix.de/  |
> 3

Re: [PATCH V2] arm64: dts: qcom: sc7180: Add bandwidth votes for eMMC and SDcard

2020-07-26 Thread sbhanu

On 2020-07-24 22:40, Matthias Kaehlcke wrote:

Hi Shaik,

On Tue, Jul 21, 2020 at 04:16:21PM +0530, Shaik Sajida Bhanu wrote:

From: Pradeep P V K 

Add the bandwidth domain supporting performance state and
the corresponding OPP tables for the sdhc device on sc7180.

Signed-off-by: Pradeep P V K 
Signed-off-by: Shaik Sajida Bhanu 
---

Changes since V1:
- Incorporated review comments by Bjorn Andersson.
---
 arch/arm64/boot/dts/qcom/sc7180.dtsi | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/sc7180.dtsi 
b/arch/arm64/boot/dts/qcom/sc7180.dtsi

index 68f9894..d78a066 100644
--- a/arch/arm64/boot/dts/qcom/sc7180.dtsi
+++ b/arch/arm64/boot/dts/qcom/sc7180.dtsi
@@ -684,6 +684,9 @@
clocks = <&gcc GCC_SDCC1_APPS_CLK>,
<&gcc GCC_SDCC1_AHB_CLK>;
clock-names = "core", "iface";
+   interconnects = <&aggre1_noc MASTER_EMMC &mc_virt 
SLAVE_EBI1>,
+   <&gem_noc MASTER_APPSS_PROC &config_noc 
SLAVE_EMMC_CFG>;
+   interconnect-names = "sdhc-ddr","cpu-sdhc";
power-domains = <&rpmhpd SC7180_CX>;
operating-points-v2 = <&sdhc1_opp_table>;

@@ -704,11 +707,15 @@
opp-1 {
opp-hz = /bits/ 64 <1>;
required-opps = <&rpmhpd_opp_low_svs>;
+   opp-peak-kBps = <10 10>;
+   opp-avg-kBps = <10 5>;
};

opp-38400 {
opp-hz = /bits/ 64 <38400>;
required-opps = <&rpmhpd_opp_svs_l1>;
+   opp-peak-kBps = <60 90>;
+   opp-avg-kBps = <261438 30>;
};
};
};
@@ -2476,6 +2483,10 @@
clocks = <&gcc GCC_SDCC2_APPS_CLK>,
<&gcc GCC_SDCC2_AHB_CLK>;
clock-names = "core", "iface";
+
+   interconnects = <&aggre1_noc MASTER_SDCC_2 &mc_virt 
SLAVE_EBI1>,
+   <&gem_noc MASTER_APPSS_PROC &config_noc  
SLAVE_SDCC_2>;
+   interconnect-names = "sdhc-ddr","cpu-sdhc";
power-domains = <&rpmhpd SC7180_CX>;
operating-points-v2 = <&sdhc2_opp_table>;

@@ -2489,11 +2500,15 @@
opp-1 {
opp-hz = /bits/ 64 <1>;
required-opps = <&rpmhpd_opp_low_svs>;
+   opp-peak-kBps = <16 10>;
+   opp-avg-kBps = <8 5>;
};

opp-20200 {
opp-hz = /bits/ 64 <20200>;
required-opps = <&rpmhpd_opp_svs_l1>;
+   opp-peak-kBps = <20  12>;
+   opp-avg-kBps = <10 6>;
};
};
};


Does the sdhci-msm driver actually have BW scaling support at this 
point?




yes


There is commit 4ece9795be56 ("mmc: sdhci-msm: Add interconnect
bandwidth scaling support"), whose commit message says "make sure
interconnect driver is ready before handling interconnect scaling.".

I haven't seen any patch adding the scaling support (supposedly by
adding dev_pm_opp_set_bw() calls?). Did I miss it? If not it seems
it would make sense to post it in a series together with this patch,
as far as I can tell this patch alone does nothing in practical terms.

grep sdhc /sys/kernel/debug/interconnect/interconnect_summary
  8804000.sdhci  000
  7c4000.sdhci   000
  7c4000.sdhci   000
  8804000.sdhci  000
  ...


"mmc: sdhci-msm: Use OPP API to set clk/perf 
state"(https://lkml.org/lkml/2020/4/8/425) and "mmc: sdhci-msm: Add 
interconnect bandwidth scaling 
support"(https://lkml.org/lkml/2020/3/12/60) with these two patches 
scaling will be supported for sdhci-msm driver.


the values  in  grep sdhc 
/sys/kernel/debug/interconnect/interconnect_summary will be zero during 
device is in suspend state... and the values in  grep sdhc 
/sys/kernel/debug/interconnect/interconnect_summary during device in 
resume state will be like the following::


cicalhost / # c

[PATCH v2] lib: Verify array index is correct before using it

2020-07-26 Thread Huang Guobin
This code reads from the array before verifying that "c" is a valid
index. Move test array offset code before use to fix it.

Fixes: 2da572c959dd ("lib: add software 842 compression/decompression")
Signed-off-by: Huang Guobin 
---
 lib/842/842_compress.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/842/842_compress.c b/lib/842/842_compress.c
index c02baa4168e1..c37bfe0b9346 100644
--- a/lib/842/842_compress.c
+++ b/lib/842/842_compress.c
@@ -11,6 +11,7 @@
 #define MODULE_NAME "842_compress"
 
 #include 
+#include 
 
 #include "842.h"
 #include "842_debugfs.h"
@@ -222,12 +223,14 @@ static int add_bits(struct sw842_param *p, u64 d, u8 n)
 static int add_template(struct sw842_param *p, u8 c)
 {
int ret, i, b = 0;
-   u8 *t = comp_ops[c];
+   u8 *t = NULL;
bool inv = false;
 
if (c >= OPS_MAX)
return -EINVAL;
+   c = array_index_nospec(c, OPS_MAX);
 
+   t = comp_ops[c];
pr_debug("template %x\n", t[4]);
 
ret = add_bits(p, t[4], OP_BITS);
@@ -379,12 +382,14 @@ static int add_end_template(struct sw842_param *p)
 
 static bool check_template(struct sw842_param *p, u8 c)
 {
-   u8 *t = comp_ops[c];
+   u8 *t = NULL;
int i, match, b = 0;
 
if (c >= OPS_MAX)
return false;
+   c = array_index_nospec(c, OPS_MAX);
 
+   t = comp_ops[c];
for (i = 0; i < 4; i++) {
if (t[i] & OP_ACTION_INDEX) {
if (t[i] & OP_AMOUNT_2)
-- 
2.17.1



Re: [PATCH 18/23] init: open code setting up stdin/stdout/stderr

2020-07-26 Thread Christoph Hellwig
On Sun, Jul 26, 2020 at 11:36:15PM -0700, h...@zytor.com wrote:
> >Err, why?  The changes have been pretty simple, and I'd rather not come
> >up with new crazy ways just to make things complicated.
> 
> Why? To avoid this neverending avalanche of special interfaces and layering 
> violations. Neatly deals with non-contiguous contents and initramfs in device 
> memory, etc. etc. etc.

I don't think it will be all that simple.  But given that linux-next
is just missing one series Al was already ok with to kill off set_fs
entirely for about half of our architectures I'd rather go ahead with
this series.  If you can send a series mapping user memory that actually
cleans things up on top of it I'm not going to complain, but I'm not
sure it really is going to be all that much cleaner.


Re: [PATCH 18/23] init: open code setting up stdin/stdout/stderr

2020-07-26 Thread Christoph Hellwig
On Mon, Jul 27, 2020 at 07:03:22AM +0100, Al Viro wrote:
> On Mon, Jul 27, 2020 at 07:46:25AM +0200, Christoph Hellwig wrote:
> > On Mon, Jul 27, 2020 at 04:05:34AM +0100, Al Viro wrote:
> > > On Tue, Jul 14, 2020 at 09:04:22PM +0200, Christoph Hellwig wrote:
> > > > Don't rely on the implicit set_fs(KERNEL_DS) for ksys_open to work, but
> > > > instead open a struct file for /dev/console and then install it as FD
> > > > 0/1/2 manually.
> > > 
> > > I really hate that one.  Every time we exposed the internal details to
> > > the fucking early init code, we paid for that afterwards.  And this
> > > goes over the top wrt the level of details being exposed.
> > > 
> > > _IF_ you want to keep that thing, move it to fs/file.c, with dire comment
> > > re that being very special shite for init and likely cause of subsequent
> > > trouble whenever anything gets changed, a gnat farts somewhere, etc.
> > 
> > Err, while I'm all for keeping internals internal, fd_install and
> > get_unused_fd_flags are exported routines with tons of users of this
> > pattern all over.
> 
> get_file_rcu_many()?  All over the place?  Besides, that's _not_ the normal
> pattern for get_unused_fd() - there's a very special reason we don't expect
> an error from it here.

Oh well.  I can add an init_dup2, but that should probably go after
the series adding fs/for-init.c or fs/init.c.  I'll skip it for the
current set of fixups and will send it once we have a stable branch for
that.


Re: [PATCH] i2c: xiic: Fix reference count leaks.

2020-07-26 Thread Michal Simek
Hi,

On 27. 07. 20 8:16, Qiushi Wu wrote:
> Hi Michal,
> 
> Thanks for your reply!
> I checked the mailing list for the related emails against this API, but
> I didn't find any specific timeline they mentioned.
> Maybe we can patch this bug to prevent potential issues at this time
> point if you are willing to.

ok. I am fine with this but please send v2 and add there some comments
about it and extend commit message with more information you provided.
I just want to make sure that in several months timeframe when someone
look at this it will be clear that it was workaround.

Thanks,
Michal


Re: [PATCH 1/6] arm64/vdso: use the fault callback to map vvar pages

2020-07-26 Thread Andrei Vagin
On Fri, Jul 24, 2020 at 06:26:23PM +0100, Catalin Marinas wrote:
> On Wed, 24 Jun 2020 01:33:16 -0700, Andrei Vagin wrote:
> > Currently the vdso has no awareness of time namespaces, which may
> > apply distinct offsets to processes in different namespaces. To handle
> > this within the vdso, we'll need to expose a per-namespace data page.
> > 
> > As a preparatory step, this patch separates the vdso data page from
> > the code pages, and has it faulted in via its own fault callback.
> > Subsquent patches will extend this to support distinct pages per time
> > namespace.
> > 
> > [...]
> 
> Applied to arm64 (for-next/timens), provisionally.
> 
> One potential issue I did not check is the compat vDSO. The arm32 port
> does not support timens currently. IIUC, with these patches and
> COMPAT_VDSO enabled, it will allow timens for compat processes. Normally
> I'd like the arm32 support first before updating compat but I don't
> think there would be any interface incompatibility here.
> 
> However, does this still work for arm32 processes if COMPAT_VDSO is
> disabled in the arm64 kernel?

Yes, it does. I checked that the timens test passes with and without
COMPAT_VDSO:

[avagin@laptop linux]$ git describe HEAD
v5.8-rc3-6-g9614cc576d76

alpine:/tip/tools/testing/selftests/timens# readelf  -h ./timens
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class: ELF32
  Data:  2's complement, little endian
  Version:   1 (current)
  OS/ABI:UNIX - System V
  ABI Version:   0
  Type:  DYN (Shared object file)
  Machine:   ARM
  Version:   0x1
  Entry point address:   0x711
  Start of program headers:  52 (bytes into file)
  Start of section headers:  15444 (bytes into file)
  Flags: 0x5000400, Version5 EABI,
hard-float ABI
  Size of this header:   52 (bytes)
  Size of program headers:   32 (bytes)
  Number of program headers: 7
  Size of section headers:   40 (bytes)
  Number of section headers: 32
  Section header string table index: 31

alpine:/tip/tools/testing/selftests/timens# uname -a
Linux arm64-alpine 5.8.0-rc3+ #100 SMP Sun Jul 26 23:21:07 PDT 2020
aarch64 Linux


[avagin@laptop linux]$ cat  .config | grep VDSO
CONFIG_COMPAT_VDSO=y
CONFIG_THUMB2_COMPAT_VDSO=y
CONFIG_HAVE_GENERIC_VDSO=y
CONFIG_GENERIC_COMPAT_VDSO=y
CONFIG_GENERIC_VDSO_TIME_NS=y


alpine:/tip/tools/testing/selftests/timens# ./timens
1..10
ok 1 Passed for CLOCK_BOOTTIME (syscall)
ok 2 Passed for CLOCK_BOOTTIME (vdso)
not ok 3 # SKIP CLOCK_BOOTTIME_ALARM isn't supported
not ok 4 # SKIP CLOCK_BOOTTIME_ALARM isn't supported
ok 5 Passed for CLOCK_MONOTONIC (syscall)
ok 6 Passed for CLOCK_MONOTONIC (vdso)
ok 7 Passed for CLOCK_MONOTONIC_COARSE (syscall)
ok 8 Passed for CLOCK_MONOTONIC_COARSE (vdso)
ok 9 Passed for CLOCK_MONOTONIC_RAW (syscall)
ok 10 Passed for CLOCK_MONOTONIC_RAW (vdso)
# Pass 8 Fail 0 Xfail 0 Xpass 0 Skip 2 Error 0


[avagin@laptop linux]$ cat  .config | grep VDSO
# CONFIG_COMPAT_VDSO is not set
CONFIG_HAVE_GENERIC_VDSO=y
CONFIG_GENERIC_VDSO_TIME_NS=y

alpine:/tip/tools/testing/selftests/timens# ./timens
1..10
ok 1 Passed for CLOCK_BOOTTIME (syscall)
ok 2 Passed for CLOCK_BOOTTIME (vdso)
not ok 3 # SKIP CLOCK_BOOTTIME_ALARM isn't supported
not ok 4 # SKIP CLOCK_BOOTTIME_ALARM isn't supported
ok 5 Passed for CLOCK_MONOTONIC (syscall)
ok 6 Passed for CLOCK_MONOTONIC (vdso)
ok 7 Passed for CLOCK_MONOTONIC_COARSE (syscall)
ok 8 Passed for CLOCK_MONOTONIC_COARSE (vdso)
ok 9 Passed for CLOCK_MONOTONIC_RAW (syscall)
ok 10 Passed for CLOCK_MONOTONIC_RAW (vdso)
# Pass 8 Fail 0 Xfail 0 Xpass 0 Skip 2 Error 0

Thanks,
Andrei


RE: [PATCH 00/10] remoteproc: imx_rproc: support iMX8M and early boot

2020-07-26 Thread Peng Fan
Hi Oleksij,

> Subject: Re: [PATCH 00/10] remoteproc: imx_rproc: support iMX8M and early
> boot
> 
> Hi,
> 
> On Fri, Jul 24, 2020 at 04:08:03PM +0800, Peng Fan wrote:
> > This patchset is to support i.MX8MQ/M coproc booted before linux.
> > Since i.MX8MQ/M was not supported, several patches are needed to first
> > support the platform, then support early boot case.
> >
> > I intended to included i.MX8QM/QXP, but that would introduce a large
> > patchset, so not included. But the clk/syscon optional patch for
> > i.MX8QM/QXP was still kept here to avoid rebase error.
> 
> Thank you for your work.
> 
> Can you please provide more information about big picture of this work.
> 
> If I see it correctly, we have here support for i.MX8MM, which seems to be
> able to fully control Cortex M4 (enable CPU core, etc...).

Yes.

> 
> And other case, where remoteproc is running on application processor and
> can't or should not touch M4 (i.MX7ULP, i.MX8QM/QXP..). Since M4 provides
> some functionality, you are trying to reuse remoteproc framework to get
> resource table present in ELF header and to dynamically load things. For some
> reasons this header provides more information then needed, so you are
> changing the ELF parser in the kernel to workaround it.

Not exactly.

For i.MX8MM, we support two cases. M4 kicked by U-Boot, M4 kicked by Linux 
remoteproc.
For i.MX8QM/QXP, the typical usecase is M4 kicked by SCFW, but we will also add 
M4 kicked
by Linux remoteproc.
For i.MX7ULP, I would only support M4 dual boot case, M4 control everything.

The reason the change the elf parser is that when M4 elf is loaded by Linux 
remoteproc,
It use memset to clear area. However we use ioremap, memset on ARM64 will report
crash to device nGnRE memory. And we could not use ioremap_wc to TCM area, since
it could have data correctly written into TCM.

Maintainer not wanna to drop memset in common code, and TI guys suggest
add i.MX specific elf stuff. So I add elf handler in i.MX code.

Thanks,
Peng.

> 
> Correct?
> 
> > Peng Fan (10):
> >   dt-bindings: remoteproc: imx_rproc: add i.MX8MQ/M
> >   remoteproc: imx_rproc: correct err message
> >   remoteproc: imx: use devm_ioremap
> >   remoteproc: imx_rproc: make syscon optional
> >   remoteproc: imx_rproc: make clk optional
> >   remoteproc: imx_rproc: add load hook
> >   remoteproc: imx_rproc: add i.MX specific parse fw hook
> >   remoteproc: imx_rproc: support i.MX8MQ/M
> >   remoteproc: imx_proc: enable virtio/mailbox
> >   remoteproc: imx_rproc: support coproc booting before Linux
> >
> >  .../devicetree/bindings/remoteproc/imx-rproc.txt   |   3 +
> >  drivers/remoteproc/imx_rproc.c | 409
> -
> >  2 files changed, 401 insertions(+), 11 deletions(-)
> >
> > --
> > 2.16.4
> >
> >
> > ___
> > linux-arm-kernel mailing list
> > linux-arm-ker...@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> >
> 
> --
> Pengutronix e.K.   |
> |
> Steuerwalder Str. 21   |
> http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany  | Phone:
> +49-5121-206917-0|
> Amtsgericht Hildesheim, HRA 2686   | Fax:
> +49-5121-206917- |


Re: [PATCH 18/21] iommu/mediatek: Add support for multi domain

2020-07-26 Thread Yong Wu
On Thu, 2020-07-23 at 14:47 -0600, Rob Herring wrote:
> On Sat, Jul 11, 2020 at 02:48:43PM +0800, Yong Wu wrote:
> > Some HW IP(ex: CCU) require the special iova range. That means the
> > iova got from dma_alloc_attrs for that devices must locate in his
> > special range. In this patch, we allocate a special iova_range for
> > each a special requirement and create each a iommu domain for each
> > a iova_range.
> > 
> > meanwhile we still use one pagetable which support 16GB iova.
> > 
> > After this patch, If the iova range of a master is over 4G, the master
> > should:
> > a) Declare its special dma_ranges in its dtsi node. For example, If we
> > preassign the iova 4G-8G for vcodec, then the vcodec dtsi node should:
> > dma-ranges = <0x1 0x0 0x1 0x0 0x1 0x0>;  /* 4G ~ 8G */
> 
> BTW, dma-ranges should be in the parent node of the vcodec.

But the vcodec doesn't have its special parent node. Currently the
vcodec/display dtsi like this:

soc {

ovl:{  /* display */
/*No dma-ranges property. defaultly it is 0-4G iova range. */
}

vcodec_dec: { /* decode */
dma-ranges = <0x1 0x0 0x1 0x0 0x1 0x0>; /* 4G ~ 8G*/
};

vcodec_enc: {  /* encode */
dma-ranges = <0x1 0x0 0x1 0x0 0x1 0x0>; /* 4G ~ 8G*/
};

camera: {
dma-ranges = <0x2 0x0 0x2 0x0 0x1 0x0>; /* 8G ~ 12G */
};

}

If we add the parent node for vcodec, the vcodec driver flow will be
changed, and it may be incompatible with the previous dtb.

Here we don't have the actual bus concept. currently we support 16GB
dma_addr(iova) ranges. we only preassign 4-8G for vcodec, 8G-12G for
camera.

If the usage of dma-ranges here is different from the common one. then
how should I do here?

Thanks.
> 
> > b) Update the dma_mask:
> >  dma_set_mask_and_coherent(dev, DMA_BIT_MASK(33));
> 
> This should happen for you automatically. The DMA PFN offset 
> should also be 4GB here.

I may not follow here.

If the iova start at 0x1__, phys address start at 0x4000_.
Do you means the dma-ranges should be <0x1 0 0x0 0x4000 0x1 0x0>?
then dma_pfn_offset = PFN_DOWN(paddr - dma_addr) = 0x4. this
is also ok for us. we don't call the macro regarding this
"dev->dma_pfn_offset"

The purpose that I call it here is for updating the
dev->coherent_dma_mask[1], then we could get the iova over 4GB.

[1]
https://elixir.bootlin.com/linux/v5.8-rc1/source/drivers/iommu/dma-iommu.c#L619

> 
> > 
> > Signed-off-by: Yong Wu 
> > ---
> >  drivers/iommu/mtk_iommu.c | 49 ---
> >  drivers/iommu/mtk_iommu.h |  3 ++-
> >  2 files changed, 42 insertions(+), 10 deletions(-)



Re: [PATCH 03/10] remoteproc: imx: use devm_ioremap

2020-07-26 Thread Oleksij Rempel
On Mon, Jul 27, 2020 at 06:28:20AM +, Peng Fan wrote:
> Hi Oleksij,
> 
> > Subject: Re: [PATCH 03/10] remoteproc: imx: use devm_ioremap
> > 
> > On Fri, Jul 24, 2020 at 04:08:06PM +0800, Peng Fan wrote:
> > > We might need to map an region multiple times, becaue the region might
> > > be shared between remote processors, such i.MX8QM with dual M4 cores.
> > > So use devm_ioremap, not devm_ioremap_resource.
> > 
> > Can you please give an example of this kind of shared resources and how they
> > should be handled by two separate devices?
> 
> This is to share vdevbuffer space, there is a vdevbuffer in device tree, it 
> will be
> shared between M4_0 and M4_1.
>
> For the buffer, it is Linux DMA API will handle the space.

Why remoteproc need to care about it? If I see it correctly, from the
linux perspective, it is one buffer and one driver is responsible for
it. Or do I missing some thing?

> Thanks,
> Peng.
> 
> > 
> > > Reviewed-by: Richard Zhu 
> > > Signed-off-by: Peng Fan 
> > > ---
> > >  drivers/remoteproc/imx_rproc.c | 5 +++--
> > >  1 file changed, 3 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/remoteproc/imx_rproc.c
> > > b/drivers/remoteproc/imx_rproc.c index 3b3904ebac75..82594a800a1b
> > > 100644
> > > --- a/drivers/remoteproc/imx_rproc.c
> > > +++ b/drivers/remoteproc/imx_rproc.c
> > > @@ -296,9 +296,10 @@ static int imx_rproc_addr_init(struct imx_rproc
> > *priv,
> > >   if (b >= IMX7D_RPROC_MEM_MAX)
> > >   break;
> > >
> > > - priv->mem[b].cpu_addr = devm_ioremap_resource(&pdev->dev,
> > &res);
> > > + /* Not use resource version, because we might share region*/
> > > + priv->mem[b].cpu_addr = devm_ioremap(&pdev->dev, res.start,
> > > +resource_size(&res));
> > >   if (IS_ERR(priv->mem[b].cpu_addr)) {
> > > - dev_err(dev, "devm_ioremap_resource failed\n");
> > > + dev_err(dev, "devm_ioremap %pR failed\n", &res);
> > >   err = PTR_ERR(priv->mem[b].cpu_addr);
> > >   return err;
> > >   }
> > > --
> > > 2.16.4
> > >
> > >
> > 
> > --
> > Pengutronix e.K.   |
> > |
> > Steuerwalder Str. 21   |
> > http://www.pengutronix.de/  |
> > 31137 Hildesheim, Germany  | Phone:
> > +49-5121-206917-0|
> > Amtsgericht Hildesheim, HRA 2686   | Fax:
> > +49-5121-206917- |

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |


signature.asc
Description: PGP signature


Re: [PATCH 00/10] remoteproc: imx_rproc: support iMX8M and early boot

2020-07-26 Thread Oleksij Rempel
Hi,

On Fri, Jul 24, 2020 at 04:08:03PM +0800, Peng Fan wrote:
> This patchset is to support i.MX8MQ/M coproc booted before linux.
> Since i.MX8MQ/M was not supported, several patches are needed
> to first support the platform, then support early boot case.
> 
> I intended to included i.MX8QM/QXP, but that would introduce a large
> patchset, so not included. But the clk/syscon optional patch for
> i.MX8QM/QXP was still kept here to avoid rebase error.

Thank you for your work.

Can you please provide more information about big picture of this work.

If I see it correctly, we have here support for i.MX8MM, which seems to
be able to fully control Cortex M4 (enable CPU core, etc...).

And other case, where remoteproc is running on application processor and
can't or should not touch M4 (i.MX7ULP, i.MX8QM/QXP..). Since M4
provides some functionality, you are trying to reuse remoteproc
framework to get resource table present in ELF header and to dynamically
load things. For some reasons this header provides more information then
needed, so you are changing the ELF parser in the kernel to workaround
it.

Correct?

> Peng Fan (10):
>   dt-bindings: remoteproc: imx_rproc: add i.MX8MQ/M
>   remoteproc: imx_rproc: correct err message
>   remoteproc: imx: use devm_ioremap
>   remoteproc: imx_rproc: make syscon optional
>   remoteproc: imx_rproc: make clk optional
>   remoteproc: imx_rproc: add load hook
>   remoteproc: imx_rproc: add i.MX specific parse fw hook
>   remoteproc: imx_rproc: support i.MX8MQ/M
>   remoteproc: imx_proc: enable virtio/mailbox
>   remoteproc: imx_rproc: support coproc booting before Linux
> 
>  .../devicetree/bindings/remoteproc/imx-rproc.txt   |   3 +
>  drivers/remoteproc/imx_rproc.c | 409 
> -
>  2 files changed, 401 insertions(+), 11 deletions(-)
> 
> -- 
> 2.16.4
> 
> 
> ___
> linux-arm-kernel mailing list
> linux-arm-ker...@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> 

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |


signature.asc
Description: PGP signature


Re: [PATCH 18/23] init: open code setting up stdin/stdout/stderr

2020-07-26 Thread hpa
On July 26, 2020 11:24:25 PM PDT, Christoph Hellwig  wrote:
>On Sun, Jul 26, 2020 at 11:20:41PM -0700, h...@zytor.com wrote:
>> On July 26, 2020 8:05:34 PM PDT, Al Viro 
>wrote:
>> >On Tue, Jul 14, 2020 at 09:04:22PM +0200, Christoph Hellwig wrote:
>> >> Don't rely on the implicit set_fs(KERNEL_DS) for ksys_open to
>work,
>> >but
>> >> instead open a struct file for /dev/console and then install it as
>FD
>> >> 0/1/2 manually.
>> >
>> >I really hate that one.  Every time we exposed the internal details
>to
>> >the fucking early init code, we paid for that afterwards.  And this
>> >goes over the top wrt the level of details being exposed.
>> >
>> >_IF_ you want to keep that thing, move it to fs/file.c, with dire
>> >comment
>> >re that being very special shite for init and likely cause of
>> >subsequent
>> >trouble whenever anything gets changed, a gnat farts somewhere, etc.
>> >
>> >Do not leave that kind of crap sitting around init/*.c; KERNEL_DS
>> >may be a source of occasional PITA, but here you are trading it for
>a
>> >lot
>> >worse one in the future.
>> 
>> Okay... here is a perhaps idiotic idea... even if we don't want to
>run stuff in actual user space, could we map initramfs into user space
>memory before running init (execing init will tear down those mappings
>anyway) so that we don't need KERNEL_DS at least?
>
>Err, why?  The changes have been pretty simple, and I'd rather not come
>up with new crazy ways just to make things complicated.

Why? To avoid this neverending avalanche of special interfaces and layering 
violations. Neatly deals with non-contiguous contents and initramfs in device 
memory, etc. etc. etc.


-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


Re: WARNING in xfrm_policy_insert

2020-07-26 Thread Xin Long
On Mon, Jul 27, 2020 at 4:11 AM syzbot
 wrote:
>
> syzbot suspects this issue was fixed by commit:
>
> commit ed17b8d377eaf6b4a01d46942b4c647378a79bdd
> Author: Xin Long 
> Date:   Mon May 25 05:53:37 2020 +
>
> xfrm: fix a warning in xfrm_policy_insert_list
>
> bisection log:  https://syzkaller.appspot.com/x/bisect.txt?x=1774b9df10
> start commit:   6c677750 mlxsw: spectrum: Use NL_SET_ERR_MSG_MOD
> git tree:   net-next
> kernel config:  https://syzkaller.appspot.com/x/.config?x=82a189bf69e089b5
> dashboard link: https://syzkaller.appspot.com/bug?extid=5cfc132a76d844973259
> syz repro:  https://syzkaller.appspot.com/x/repro.syz?x=12f8821d80
> C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=13ec3c6380
>
> If the result looks correct, please mark the issue as fixed by replying with:
>
> #syz fix: xfrm: fix a warning in xfrm_policy_insert_list
>
> For information about bisection process see: https://goo.gl/tpsmEJ#bisection
#syz fix: xfrm: fix a warning in xfrm_policy_insert_list


Re: [PATCH v4 00/10] Coregroup support on Powerpc

2020-07-26 Thread Srikar Dronamraju
* Srikar Dronamraju  [2020-07-27 10:47:55]:


> Changelog v3 ->v4:
> v3: 
> https://lore.kernel.org/lkml/20200723085116.4731-1-sri...@linux.vnet.ibm.com/t/#u
> 
> powerpc/smp: Create coregroup domain
>   if coregroup_support doesn't exist, update MC mask to the next
>   smaller domain mask.
> 

Sorry for the double post of v4.
Please follow the other thread.

http://lore.kernel.org/lkml/20200727053230.19753-1-sri...@linux.vnet.ibm.com/t/#u

> 

-- 
Thanks and Regards
Srikar Dronamraju


[PATCH] spi: imx: enable runtime pm support

2020-07-26 Thread Clark Wang
Enable runtime pm support for spi-imx driver.

Signed-off-by: Clark Wang 
---
 drivers/spi/spi-imx.c | 121 ++
 1 file changed, 88 insertions(+), 33 deletions(-)

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index fdc25f549378..38a5f1304cec 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -13,7 +13,9 @@
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -30,6 +32,8 @@ static bool use_dma = true;
 module_param(use_dma, bool, 0644);
 MODULE_PARM_DESC(use_dma, "Enable usage of DMA when available (default)");
 
+#define MXC_RPM_TIMEOUT2000 /* 2000ms */
+
 #define MXC_CSPIRXDATA 0x00
 #define MXC_CSPITXDATA 0x04
 #define MXC_CSPICTRL   0x08
@@ -1530,20 +1534,16 @@ spi_imx_prepare_message(struct spi_master *master, 
struct spi_message *msg)
struct spi_imx_data *spi_imx = spi_master_get_devdata(master);
int ret;
 
-   ret = clk_enable(spi_imx->clk_per);
-   if (ret)
-   return ret;
-
-   ret = clk_enable(spi_imx->clk_ipg);
-   if (ret) {
-   clk_disable(spi_imx->clk_per);
+   ret = pm_runtime_get_sync(spi_imx->dev);
+   if (ret < 0) {
+   dev_err(spi_imx->dev, "failed to enable clock\n");
return ret;
}
 
ret = spi_imx->devtype_data->prepare_message(spi_imx, msg);
if (ret) {
-   clk_disable(spi_imx->clk_ipg);
-   clk_disable(spi_imx->clk_per);
+   pm_runtime_mark_last_busy(spi_imx->dev);
+   pm_runtime_put_autosuspend(spi_imx->dev);
}
 
return ret;
@@ -1554,8 +1554,8 @@ spi_imx_unprepare_message(struct spi_master *master, 
struct spi_message *msg)
 {
struct spi_imx_data *spi_imx = spi_master_get_devdata(master);
 
-   clk_disable(spi_imx->clk_ipg);
-   clk_disable(spi_imx->clk_per);
+   pm_runtime_mark_last_busy(spi_imx->dev);
+   pm_runtime_put_autosuspend(spi_imx->dev);
return 0;
 }
 
@@ -1674,13 +1674,15 @@ static int spi_imx_probe(struct platform_device *pdev)
goto out_master_put;
}
 
-   ret = clk_prepare_enable(spi_imx->clk_per);
-   if (ret)
-   goto out_master_put;
+   pm_runtime_enable(spi_imx->dev);
+   pm_runtime_set_autosuspend_delay(spi_imx->dev, MXC_RPM_TIMEOUT);
+   pm_runtime_use_autosuspend(spi_imx->dev);
 
-   ret = clk_prepare_enable(spi_imx->clk_ipg);
-   if (ret)
-   goto out_put_per;
+   ret = pm_runtime_get_sync(spi_imx->dev);
+   if (ret < 0) {
+   dev_err(spi_imx->dev, "failed to enable clock\n");
+   goto out_runtime_pm_put;
+   }
 
spi_imx->spi_clk = clk_get_rate(spi_imx->clk_per);
/*
@@ -1690,7 +1692,7 @@ static int spi_imx_probe(struct platform_device *pdev)
if (spi_imx->devtype_data->has_dmamode) {
ret = spi_imx_sdma_init(&pdev->dev, spi_imx, master);
if (ret == -EPROBE_DEFER)
-   goto out_clk_put;
+   goto out_runtime_pm_put;
 
if (ret < 0)
dev_err(&pdev->dev, "dma setup error %d, use pio\n",
@@ -1705,19 +1707,20 @@ static int spi_imx_probe(struct platform_device *pdev)
ret = spi_bitbang_start(&spi_imx->bitbang);
if (ret) {
dev_err(&pdev->dev, "bitbang start failed with %d\n", ret);
-   goto out_clk_put;
+   goto out_runtime_pm_put;
}
 
dev_info(&pdev->dev, "probed\n");
 
-   clk_disable(spi_imx->clk_ipg);
-   clk_disable(spi_imx->clk_per);
+   pm_runtime_mark_last_busy(spi_imx->dev);
+   pm_runtime_put_autosuspend(spi_imx->dev);
+
return ret;
 
-out_clk_put:
-   clk_disable_unprepare(spi_imx->clk_ipg);
-out_put_per:
-   clk_disable_unprepare(spi_imx->clk_per);
+out_runtime_pm_put:
+   pm_runtime_dont_use_autosuspend(spi_imx->dev);
+   pm_runtime_put_sync(spi_imx->dev);
+   pm_runtime_disable(spi_imx->dev);
 out_master_put:
spi_master_put(master);
 
@@ -1732,30 +1735,82 @@ static int spi_imx_remove(struct platform_device *pdev)
 
spi_bitbang_stop(&spi_imx->bitbang);
 
-   ret = clk_enable(spi_imx->clk_per);
+   ret = pm_runtime_get_sync(spi_imx->dev);
+   if (ret < 0) {
+   dev_err(spi_imx->dev, "failed to enable clock\n");
+   return ret;
+   }
+
+   writel(0, spi_imx->base + MXC_CSPICTRL);
+
+   pm_runtime_dont_use_autosuspend(spi_imx->dev);
+   pm_runtime_put_sync(spi_imx->dev);
+   pm_runtime_disable(spi_imx->dev);
+
+   spi_imx_sdma_exit(spi_imx);
+   spi_master_put(master);
+
+   return 0;
+}
+
+static int __maybe_unused spi_imx_runtime_resume(struct device *dev)
+{
+   struct spi_master *master = dev_get_drvdata(dev);
+   struct spi_imx_data *spi_imx;
+   int 

Re: [PATCH] ASoC: fsl-asoc-card: Remove fsl_asoc_card_set_bias_level function

2020-07-26 Thread Shengjiu Wang
On Mon, Jul 27, 2020 at 8:58 AM Nicolin Chen  wrote:
>
> On Sun, Jul 26, 2020 at 07:20:17PM +0800, Shengjiu Wang wrote:
> > With this case:
> > aplay -Dhw:x 16khz.wav 24khz.wav
> > There is sound distortion for 24khz.wav. The reason is that setting
> > PLL of WM8962 with set_bias_level function, the bias level is not
> > changed when 24khz.wav is played, then the PLL won't be reset, the
> > clock is not correct, so distortion happens.
> >
> > The resolution of this issue is to remove fsl_asoc_card_set_bias_level.
> > Move PLL configuration to hw_params and hw_free.
>
> Hmm...using set_bias_level() instead of hw_params/hw_free() was
> strongly suggested by Mark when I got imx-wm8962 machine driver
> upstream. So we will need his input here, although I personally
> don't have a problem with it...
>
> > After removing fsl_asoc_card_set_bias_level, also test WM8960 case,
> > it can work.
> >
> > Fixes: 708b4351f08c ("ASoC: fsl: Add Freescale Generic ASoC Sound Card with 
> > ASRC support")
> > Signed-off-by: Shengjiu Wang 
> > ---
> >  sound/soc/fsl/fsl-asoc-card.c | 149 +++---
> >  1 file changed, 66 insertions(+), 83 deletions(-)
> >
> > diff --git a/sound/soc/fsl/fsl-asoc-card.c b/sound/soc/fsl/fsl-asoc-card.c
> > index 4848ba61d083..0517dbb3e908 100644
> > --- a/sound/soc/fsl/fsl-asoc-card.c
> > +++ b/sound/soc/fsl/fsl-asoc-card.c
> > @@ -73,6 +73,7 @@ struct cpu_priv {
> >   * @codec_priv: CODEC private data
> >   * @cpu_priv: CPU private data
> >   * @card: ASoC card structure
> > + * @is_stream_in_use: flags for release resource in hw_free
>
> Would love to see something shorter... Could we reuse similar
> one below, borrowing from fsl_ssi driver?
>
>  * @streams: Mask of current active streams: BIT(TX) and BIT(RX)
>
> >  static int fsl_asoc_card_audmux_init(struct device_node *np,
> >struct fsl_asoc_card_priv *priv)
> >  {
> > @@ -611,7 +600,6 @@ static int fsl_asoc_card_probe(struct platform_device 
> > *pdev)
> >   /* Diversify the card configurations */
> >   if (of_device_is_compatible(np, "fsl,imx-audio-cs42888")) {
> >   codec_dai_name = "cs42888";
> > - priv->card.set_bias_level = NULL;
>
> Can check if set_bias_level is still being used with this change.

Do you mean to keep this line:
priv->card.set_bias_level = NULL; ?

best regards
wang shengjiu


RE: [PATCH 03/10] remoteproc: imx: use devm_ioremap

2020-07-26 Thread Peng Fan
Hi Oleksij,

> Subject: Re: [PATCH 03/10] remoteproc: imx: use devm_ioremap
> 
> On Fri, Jul 24, 2020 at 04:08:06PM +0800, Peng Fan wrote:
> > We might need to map an region multiple times, becaue the region might
> > be shared between remote processors, such i.MX8QM with dual M4 cores.
> > So use devm_ioremap, not devm_ioremap_resource.
> 
> Can you please give an example of this kind of shared resources and how they
> should be handled by two separate devices?

This is to share vdevbuffer space, there is a vdevbuffer in device tree, it 
will be
shared between M4_0 and M4_1.

For the buffer, it is Linux DMA API will handle the space.

Thanks,
Peng.

> 
> > Reviewed-by: Richard Zhu 
> > Signed-off-by: Peng Fan 
> > ---
> >  drivers/remoteproc/imx_rproc.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/remoteproc/imx_rproc.c
> > b/drivers/remoteproc/imx_rproc.c index 3b3904ebac75..82594a800a1b
> > 100644
> > --- a/drivers/remoteproc/imx_rproc.c
> > +++ b/drivers/remoteproc/imx_rproc.c
> > @@ -296,9 +296,10 @@ static int imx_rproc_addr_init(struct imx_rproc
> *priv,
> > if (b >= IMX7D_RPROC_MEM_MAX)
> > break;
> >
> > -   priv->mem[b].cpu_addr = devm_ioremap_resource(&pdev->dev,
> &res);
> > +   /* Not use resource version, because we might share region*/
> > +   priv->mem[b].cpu_addr = devm_ioremap(&pdev->dev, res.start,
> > +resource_size(&res));
> > if (IS_ERR(priv->mem[b].cpu_addr)) {
> > -   dev_err(dev, "devm_ioremap_resource failed\n");
> > +   dev_err(dev, "devm_ioremap %pR failed\n", &res);
> > err = PTR_ERR(priv->mem[b].cpu_addr);
> > return err;
> > }
> > --
> > 2.16.4
> >
> >
> 
> --
> Pengutronix e.K.   |
> |
> Steuerwalder Str. 21   |
> http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany  | Phone:
> +49-5121-206917-0|
> Amtsgericht Hildesheim, HRA 2686   | Fax:
> +49-5121-206917- |


Re: [PATCH v10 04/13] iommu/arm-smmu-qcom: Add implementation for the adreno GPU SMMU

2020-07-26 Thread Bjorn Andersson
On Mon 20 Jul 08:40 PDT 2020, Jordan Crouse wrote:
> diff --git a/drivers/iommu/arm-smmu-qcom.c b/drivers/iommu/arm-smmu-qcom.c
[..]
> +static int qcom_adreno_smmu_alloc_context_bank(struct arm_smmu_domain 
> *smmu_domain,
> + struct device *dev, int start, int count)
> +{
> + struct arm_smmu_device *smmu = smmu_domain->smmu;
> +
> + /*
> +  * Assign context bank 0 to the GPU device so the GPU hardware can
> +  * switch pagetables
> +  */
> + if (qcom_adreno_smmu_is_gpu_device(dev)) {
> + if (start > 0 || test_bit(0, smmu->context_map))
> + return -ENOSPC;
> +
> + set_bit(0, smmu->context_map);
> + return 0;
> + }
> +
> + return __arm_smmu_alloc_bitmap(smmu->context_map, start, count);

If we end up here before the GPU device shows up this is going to
steal the first context bank, causing the subsequent allocation for the
GPU to always fail.

As such I think it would be appropriate for you to adjust "start" to
never be 0 here. And I think it would be appropriate to write this
function as:

if (gpu) {
start = 0;
count = 1;
} else {
if (start == 0)
start = 1;
}

return __arm_smmu_alloc_bitmap(smmu->context_map, start, count);

Regards,
Bjorn


Re: [PATCH 18/23] init: open code setting up stdin/stdout/stderr

2020-07-26 Thread Christoph Hellwig
On Sun, Jul 26, 2020 at 11:20:41PM -0700, h...@zytor.com wrote:
> On July 26, 2020 8:05:34 PM PDT, Al Viro  wrote:
> >On Tue, Jul 14, 2020 at 09:04:22PM +0200, Christoph Hellwig wrote:
> >> Don't rely on the implicit set_fs(KERNEL_DS) for ksys_open to work,
> >but
> >> instead open a struct file for /dev/console and then install it as FD
> >> 0/1/2 manually.
> >
> >I really hate that one.  Every time we exposed the internal details to
> >the fucking early init code, we paid for that afterwards.  And this
> >goes over the top wrt the level of details being exposed.
> >
> >_IF_ you want to keep that thing, move it to fs/file.c, with dire
> >comment
> >re that being very special shite for init and likely cause of
> >subsequent
> >trouble whenever anything gets changed, a gnat farts somewhere, etc.
> >
> > Do not leave that kind of crap sitting around init/*.c; KERNEL_DS
> >may be a source of occasional PITA, but here you are trading it for a
> >lot
> >worse one in the future.
> 
> Okay... here is a perhaps idiotic idea... even if we don't want to run stuff 
> in actual user space, could we map initramfs into user space memory before 
> running init (execing init will tear down those mappings anyway) so that we 
> don't need KERNEL_DS at least?

Err, why?  The changes have been pretty simple, and I'd rather not come
up with new crazy ways just to make things complicated.


Re: [PATCH 03/10] remoteproc: imx: use devm_ioremap

2020-07-26 Thread Oleksij Rempel
On Fri, Jul 24, 2020 at 04:08:06PM +0800, Peng Fan wrote:
> We might need to map an region multiple times, becaue the region might
> be shared between remote processors, such i.MX8QM with dual M4 cores.
> So use devm_ioremap, not devm_ioremap_resource.

Can you please give an example of this kind of shared resources and
how they should be handled by two separate devices?

> Reviewed-by: Richard Zhu 
> Signed-off-by: Peng Fan 
> ---
>  drivers/remoteproc/imx_rproc.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
> index 3b3904ebac75..82594a800a1b 100644
> --- a/drivers/remoteproc/imx_rproc.c
> +++ b/drivers/remoteproc/imx_rproc.c
> @@ -296,9 +296,10 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
>   if (b >= IMX7D_RPROC_MEM_MAX)
>   break;
>  
> - priv->mem[b].cpu_addr = devm_ioremap_resource(&pdev->dev, &res);
> + /* Not use resource version, because we might share region*/
> + priv->mem[b].cpu_addr = devm_ioremap(&pdev->dev, res.start, 
> resource_size(&res));
>   if (IS_ERR(priv->mem[b].cpu_addr)) {
> - dev_err(dev, "devm_ioremap_resource failed\n");
> + dev_err(dev, "devm_ioremap %pR failed\n", &res);
>   err = PTR_ERR(priv->mem[b].cpu_addr);
>   return err;
>   }
> -- 
> 2.16.4
> 
> 

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |


signature.asc
Description: PGP signature


Re: [PATCH v6 2/5] scsi: ufs: Add UFS-feature layer

2020-07-26 Thread Daejun Park
> > I am also not sold on the whole "bus" thing.
> 
> How about implementing HPB as a kernel module that calls the functions
> in the UFS core directly, or in other words, get rid completely of the
> new ufsf_bus introduced by this patch?

OK, I will remove the ufsf_bus and indirect calling functions.

Thanks,
Daejun


Re: [RFC PATCH] iwlwifi: yoyo: don't print failure if debug firmware is missing

2020-07-26 Thread Luciano Coelho
On Sun, 2020-07-26 at 21:11 +0300, Kalle Valo wrote:
> Wolfram Sang  writes:
> 
> > On Thu, Jun 25, 2020 at 06:52:10PM +0200, Wolfram Sang wrote:
> > > Missing this firmware is not fatal, my wifi card still works. Even more,
> > > I couldn't find any documentation what it is or where to get it. So, I
> > > don't think the users should be notified if it is missing. If you browse
> > > the net, you see the message is present is in quite some logs. Better
> > > remove it.
> > > 
> > > Signed-off-by: Wolfram Sang 
> > > ---
> > 
> > Any input on this? Or people I should add to CC?
> 
> This was discussed on another thread:
> 
> https://lkml.kernel.org/r/87mu3magfp@tynnyri.adurom.net
> 
> Unless Intel folks object I'm planning to take this to
> wireless-drivers-next.

Yes, please, just go ahead and take it.  I have the same change in our
internal tree, but I didn't have the time to send it out due to my
vacations (from which I'm now back).

--
Cheers,
Luca.



Re: [PATCH 18/23] init: open code setting up stdin/stdout/stderr

2020-07-26 Thread hpa
On July 26, 2020 8:05:34 PM PDT, Al Viro  wrote:
>On Tue, Jul 14, 2020 at 09:04:22PM +0200, Christoph Hellwig wrote:
>> Don't rely on the implicit set_fs(KERNEL_DS) for ksys_open to work,
>but
>> instead open a struct file for /dev/console and then install it as FD
>> 0/1/2 manually.
>
>I really hate that one.  Every time we exposed the internal details to
>the fucking early init code, we paid for that afterwards.  And this
>goes over the top wrt the level of details being exposed.
>
>_IF_ you want to keep that thing, move it to fs/file.c, with dire
>comment
>re that being very special shite for init and likely cause of
>subsequent
>trouble whenever anything gets changed, a gnat farts somewhere, etc.
>
>   Do not leave that kind of crap sitting around init/*.c; KERNEL_DS
>may be a source of occasional PITA, but here you are trading it for a
>lot
>worse one in the future.

Okay... here is a perhaps idiotic idea... even if we don't want to run stuff in 
actual user space, could we map initramfs into user space memory before running 
init (execing init will tear down those mappings anyway) so that we don't need 
KERNEL_DS at least?
-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


Re: [PATCH 1/2] KVM: LAPIC: Prevent setting the tscdeadline timer if the lapic is hw disabled

2020-07-26 Thread Wanpeng Li
On Tue, 21 Jul 2020 at 23:25, Sean Christopherson
 wrote:
>
> On Tue, Jul 21, 2020 at 12:35:01PM +0200, Vitaly Kuznetsov wrote:
> > Wanpeng Li  writes:
> >
> > > From: Wanpeng Li 
> > >
> > > Prevent setting the tscdeadline timer if the lapic is hw disabled.
> > >
> > > Signed-off-by: Wanpeng Li 
>
> A Fixes and/or Cc stable is probably needed for this.
>
> > > ---
> > >  arch/x86/kvm/lapic.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> > > index 5bf72fc..4ce2ddd 100644
> > > --- a/arch/x86/kvm/lapic.c
> > > +++ b/arch/x86/kvm/lapic.c
> > > @@ -2195,7 +2195,7 @@ void kvm_set_lapic_tscdeadline_msr(struct kvm_vcpu 
> > > *vcpu, u64 data)
> > >  {
> > > struct kvm_lapic *apic = vcpu->arch.apic;
> > >
> > > -   if (!lapic_in_kernel(vcpu) || apic_lvtt_oneshot(apic) ||
> > > +   if (!kvm_apic_present(vcpu) || apic_lvtt_oneshot(apic) ||
> > > apic_lvtt_period(apic))
> > > return;
> >
> > Out of pure curiosity, what is the architectural behavior if I disable
> > LAPIC, write to IA32_TSC_DEADLINE and then re-enable LAPIC before the
> > timer was supposed to fire?
>
> Intel's SDM reserves the right for the CPU to do whatever it wants :-)
>
>When IA32_APIC_BASE[11] is set to 0, prior initialization to the APIC
>may be lost and the APIC may return to the state described in Section
>10.4.7.1, “Local APIC State After Power-Up or Reset.”
>
> Practically speaking, resetting APIC state seems like the sane approach,
> i.e. KVM should probably call kvm_lapic_reset() when the APIC transitions
> from HW enabled -> disabled.  Maybe in a follow-up patch to this one?

kvm_lapic_reset() will call the set base logic, a little recursive in
the codes, it can be done after this recursion is solved.

Wanpeng


[PATCH V3 0/1] irqchip: intmux: implement intmux PM

2020-07-26 Thread Joakim Zhang
This patch intends to implement intmux PM.

ChangeLogs:
V2->V3:
1. allocate u32 saved_reg for a per channel.

V1->V2:
1. add more detailed commit message.
2. use u32 for 32bit HW registers.
3. fix kbuild failures.
4. move trivial functions into their respective callers.
5. squash two patches together.

Joakim Zhang (1):
  irqchip: imx-intmux: implement intmux PM

 drivers/irqchip/irq-imx-intmux.c | 67 +++-
 1 file changed, 65 insertions(+), 2 deletions(-)

-- 
2.17.1



[PATCH V3 1/1] irqchip: imx-intmux: implement intmux PM

2020-07-26 Thread Joakim Zhang
When system suspended, we could explicitly disable clock to save power.
And we need save registers' state since it could be lost after power
off.

Implement PM which will:
1) Without CONFIG_PM, clock is always on after probe stage.
2) With CONFIG_PM, clock is off after probe stage.
3) Disable clock and save registers' state when do system suspend and
enable clock and restore registers' state while system resume.
4) Make Power Domain framework be able to shutdown the corresponding
power domain of this device.

Signed-off-by: Joakim Zhang 
---
 drivers/irqchip/irq-imx-intmux.c | 67 +++-
 1 file changed, 65 insertions(+), 2 deletions(-)

diff --git a/drivers/irqchip/irq-imx-intmux.c b/drivers/irqchip/irq-imx-intmux.c
index c27577c81126..4524c931c368 100644
--- a/drivers/irqchip/irq-imx-intmux.c
+++ b/drivers/irqchip/irq-imx-intmux.c
@@ -53,6 +53,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define CHANIER(n) (0x10 + (0x40 * n))
 #define CHANIPR(n) (0x20 + (0x40 * n))
@@ -60,6 +61,8 @@
 #define CHAN_MAX_NUM   0x8
 
 struct intmux_irqchip_data {
+   struct irq_chip chip;
+   u32 saved_reg;
int chanidx;
int irq;
struct irq_domain   *domain;
@@ -120,8 +123,10 @@ static struct irq_chip imx_intmux_irq_chip = {
 static int imx_intmux_irq_map(struct irq_domain *h, unsigned int irq,
  irq_hw_number_t hwirq)
 {
-   irq_set_chip_data(irq, h->host_data);
-   irq_set_chip_and_handler(irq, &imx_intmux_irq_chip, handle_level_irq);
+   struct intmux_irqchip_data *data = h->host_data;
+
+   irq_set_chip_data(irq, data);
+   irq_set_chip_and_handler(irq, &data->chip, handle_level_irq);
 
return 0;
 }
@@ -232,6 +237,10 @@ static int imx_intmux_probe(struct platform_device *pdev)
data->channum = channum;
raw_spin_lock_init(&data->lock);
 
+   pm_runtime_get_noresume(&pdev->dev);
+   pm_runtime_set_active(&pdev->dev);
+   pm_runtime_enable(&pdev->dev);
+
ret = clk_prepare_enable(data->ipg_clk);
if (ret) {
dev_err(&pdev->dev, "failed to enable ipg clk: %d\n", ret);
@@ -239,6 +248,8 @@ static int imx_intmux_probe(struct platform_device *pdev)
}
 
for (i = 0; i < channum; i++) {
+   data->irqchip_data[i].chip = imx_intmux_irq_chip;
+   data->irqchip_data[i].chip.parent_device = &pdev->dev;
data->irqchip_data[i].chanidx = i;
 
data->irqchip_data[i].irq = irq_of_parse_and_map(np, i);
@@ -267,6 +278,12 @@ static int imx_intmux_probe(struct platform_device *pdev)
 
platform_set_drvdata(pdev, data);
 
+   /*
+* Let pm_runtime_put() disable clock.
+* If CONFIG_PM is not enabled, the clock will stay powered.
+*/
+   pm_runtime_put(&pdev->dev);
+
return 0;
 out:
clk_disable_unprepare(data->ipg_clk);
@@ -288,11 +305,56 @@ static int imx_intmux_remove(struct platform_device *pdev)
irq_domain_remove(data->irqchip_data[i].domain);
}
 
+   pm_runtime_disable(&pdev->dev);
+
+   return 0;
+}
+
+#ifdef CONFIG_PM
+static int imx_intmux_runtime_suspend(struct device *dev)
+{
+   struct intmux_data *data = dev_get_drvdata(dev);
+   struct intmux_irqchip_data irqchip_data;
+   int i;
+
+   for (i = 0; i < data->channum; i++) {
+   irqchip_data = data->irqchip_data[i];
+   irqchip_data.saved_reg = readl_relaxed(data->regs + CHANIER(i));
+   }
+
clk_disable_unprepare(data->ipg_clk);
 
return 0;
 }
 
+static int imx_intmux_runtime_resume(struct device *dev)
+{
+   struct intmux_data *data = dev_get_drvdata(dev);
+   struct intmux_irqchip_data irqchip_data;
+   int ret, i;
+
+   ret = clk_prepare_enable(data->ipg_clk);
+   if (ret) {
+   dev_err(dev, "failed to enable ipg clk: %d\n", ret);
+   return ret;
+   }
+
+   for (i = 0; i < data->channum; i++) {
+   irqchip_data = data->irqchip_data[i];
+   writel_relaxed(irqchip_data.saved_reg, data->regs + CHANIER(i));
+   }
+
+   return 0;
+}
+#endif
+
+static const struct dev_pm_ops imx_intmux_pm_ops = {
+   SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
+ pm_runtime_force_resume)
+   SET_RUNTIME_PM_OPS(imx_intmux_runtime_suspend,
+  imx_intmux_runtime_resume, NULL)
+};
+
 static const struct of_device_id imx_intmux_id[] = {
{ .compatible = "fsl,imx-intmux", },
{ /* sentinel */ },
@@ -302,6 +364,7 @@ static struct platform_driver imx_intmux_driver = {
.driver = {
.name = "imx-intmux",
.of_match_table = imx_intmux_id,
+   .pm = &imx_intmux_pm_ops,
},
.probe = imx_intmux_probe,
.rem

Re: [PATCH] checkpatch: disable commit log length check warning for signature tag

2020-07-26 Thread Joe Perches
On Mon, 2020-07-27 at 11:24 +0530, Nachiket Naganure wrote:
> Disable commit log length check in case of signature tag. If the commit
> log line has valid signature tags such as "Reported-and-tested-by" with
> more than 75 characters, suppress the long length warning.
> 
> For instance in commit ac854131d984 ("USB: core: Fix misleading driver bug
> report"), the corresponding patch contains a "Reported by" tag line which
> exceeds 75 chars. And there is no valid way to shorten the length.
> 
> Signed-off-by: Nachiket Naganure 
> ---
>  scripts/checkpatch.pl | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 197436b20288..46237e9e0550 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -2806,6 +2806,8 @@ sub process {
>   # filename then :
> $line =~ /^\s*(?:Fixes:|Link:)/i ||
>   # A Fixes: or Link: line
> +   $line =~ /$signature_tags/ ||
> + # Check for signature_tags
> $commit_log_possible_stack_dump)) {
>   WARN("COMMIT_LOG_LONG_LINE",
>"Possible unwrapped commit description (prefer a 
> maximum 75 chars per line)\n" . $herecurr);

OK, but the test should be:

  $line =~ /^\s*$signature_tags/ ||

so the line has to start with a signature and
it won't match on signature tags in the middle
of other content on the same line.




[PATCH] coresight: etm4x: Fix etm4_count race using atomic variable

2020-07-26 Thread Sai Prakash Ranjan
etm4_count keeps track of number of ETMv4 registered and on some
systems, a race is observed on etm4_count variable which can
lead to multiple calls to cpuhp_setup_state_nocalls_cpuslocked().
This function internally calls cpuhp_store_callbacks() which
prevents multiple registrations of callbacks for a given state
and due to this race, it returns -EBUSY leading to ETM probe
failures like below.

 coresight-etm4x: probe of 704.etm failed with error -16

This race can easily be triggered with async probe by setting
probe type as PROBE_PREFER_ASYNCHRONOUS and with ETM power
management property "arm,coresight-loses-context-with-cpu".

Prevent this race by converting etm4_count variable to atomic.

Fixes: 9b6a3f3633a5 ("coresight: etmv4: Fix CPU power management setup in 
probe() function")
Fixes: 58eb457be028 ("hwtracing/coresight-etm4x: Convert to hotplug state 
machine")
Suggested-by: Mike Leach 
(Mike: Rootcause and context for commit message)
Signed-off-by: Sai Prakash Ranjan 
---
 drivers/hwtracing/coresight/coresight-etm4x.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c 
b/drivers/hwtracing/coresight/coresight-etm4x.c
index 6d7d2169bfb2..f256ea744c51 100644
--- a/drivers/hwtracing/coresight/coresight-etm4x.c
+++ b/drivers/hwtracing/coresight/coresight-etm4x.c
@@ -49,7 +49,7 @@ MODULE_PARM_DESC(pm_save_enable,
"Save/restore state on power down: 1 = never, 2 = self-hosted");
 
 /* The number of ETMv4 currently registered */
-static int etm4_count;
+static atomic_t etm4_count;
 static struct etmv4_drvdata *etmdrvdata[NR_CPUS];
 static void etm4_set_default_config(struct etmv4_config *config);
 static int etm4_set_event_filters(struct etmv4_drvdata *drvdata,
@@ -1403,7 +1403,7 @@ static int etm4_pm_setup_cpuslocked(void)
 {
int ret;
 
-   if (etm4_count++)
+   if (atomic_inc_return(&etm4_count))
return 0;
 
ret = cpu_pm_register_notifier(&etm4_cpu_pm_nb);
@@ -1434,13 +1434,13 @@ static int etm4_pm_setup_cpuslocked(void)
cpu_pm_unregister_notifier(&etm4_cpu_pm_nb);
 
 reduce_count:
-   --etm4_count;
+   atomic_dec(&etm4_count);
return ret;
 }
 
 static void etm4_pm_clear(void)
 {
-   if (--etm4_count != 0)
+   if (atomic_dec_return(&etm4_count) != 0)
return;
 
cpu_pm_unregister_notifier(&etm4_cpu_pm_nb);
-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation



Re: [PATCH 2/6] rtlwifi: Remove unnecessary parenthese in rtl_dbg uses

2020-07-26 Thread Pkshih
On Sat, 2020-07-25 at 12:55 -0700, Joe Perches wrote:
> Make these statements a little simpler.
> 
> Signed-off-by: Joe Perches 
> ---
>  drivers/net/wireless/realtek/rtlwifi/base.c   | 14 +--
>  .../rtlwifi/btcoexist/halbtc8192e2ant.c   | 23 ++-
>  .../rtlwifi/btcoexist/halbtc8821a2ant.c   | 12 +-
>  .../realtek/rtlwifi/btcoexist/halbtcoutsrc.c  |  9 
>  drivers/net/wireless/realtek/rtlwifi/pci.c|  2 +-
>  5 files changed, 30 insertions(+), 30 deletions(-)
> 
> 

[...]

> diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c
> b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c
> index 8d28c68f083e..f9a2d8a6730c 100644
> --- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c
> +++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c
> @@ -874,11 +874,10 @@ static void halbtc_display_wifi_status(struct
> btc_coexist *btcoexist,
>   seq_printf(m, "\n %-35s = %s / %s/ %s/ AP=%d ",
>      "Wifi freq/ bw/ traffic",
>      gl_btc_wifi_freq_string[wifi_freq],
> -    ((wifi_under_b_mode) ? "11b" :
> - gl_btc_wifi_bw_string[wifi_bw]),
> -    ((!wifi_busy) ? "idle" : ((BTC_WIFI_TRAFFIC_TX ==
> -   wifi_traffic_dir) ? "uplink" :
> -  "downlink")),
> +    wifi_under_b_mode ? "11b" : gl_btc_wifi_bw_string[wifi_bw],
> +    (!wifi_busy ? "idle" :
> + wifi_traffic_dir == BTC_WIFI_TRAFFIC_TX ? "uplink" :
> + "downlink"),

I think this would be better

+      !wifi_busy ? "idle" :
+      (wifi_traffic_dir == BTC_WIFI_TRAFFIC_TX ? "uplink" :
+   "downlink"),



>      ap_num);
>  
>   /* power status  */
> diff --git a/drivers/net/wireless/realtek/rtlwifi/pci.c
> b/drivers/net/wireless/realtek/rtlwifi/pci.c
> index 1d0af72ee780..3189d1c50d52 100644
> --- a/drivers/net/wireless/realtek/rtlwifi/pci.c
> +++ b/drivers/net/wireless/realtek/rtlwifi/pci.c
> @@ -557,7 +557,7 @@ static void _rtl_pci_tx_isr(struct ieee80211_hw *hw, int
> prio)
>   if (rtlpriv->rtlhal.earlymode_enable)
>   skb_pull(skb, EM_HDR_LEN);
>  
> - rtl_dbg(rtlpriv, (COMP_INTR | COMP_SEND), DBG_TRACE,
> + rtl_dbg(rtlpriv, COMP_INTR | COMP_SEND, DBG_TRACE,
>   "new ring->idx:%d, free: skb_queue_len:%d, free:
> seq:%x\n",
>   ring->idx,
>   skb_queue_len(&ring->queue),


Re: [PATCH v5 2/2] Add PWM fan controller driver for LGM SoC

2020-07-26 Thread Tanwar, Rahul


Hi Uwe,

On 24/7/2020 12:15 am, Uwe Kleine-König wrote:
> Hello,
>
> On Thu, Jul 23, 2020 at 03:44:18PM +0800, Rahul Tanwar wrote:
>> +static int lgm_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
>> + const struct pwm_state *state)
>> +{
>> +struct lgm_pwm_chip *pc = to_lgm_pwm_chip(chip);
>> +u32 duty_cycle, val;
>> +int ret;
>> +
>> +if (!state->enabled) {
>> +ret = lgm_pwm_enable(chip, 0);
>> +return ret;
>> +}
>> +
>> +/*
>> + * HW only supports NORMAL polarity
>> + * HW supports fixed period which can not be changed/configured by user
>> + */
>> +if (state->polarity != PWM_POLARITY_NORMAL ||
>> +state->period != pc->period)
>> +return -EINVAL;
> At least for state->polarity you have to check before state->enabled, as
> the expectation on
>
> .enabled = false
> .polarity = PWM_POLARITY_INVERSED
>
> is that the output becomes constant high. Also as confirmed at the end
> of v4, state->period < pc->period was the right check to do.

For below case:

.enabled = false
.polarity = PWM_POLARITY_INVERSED

Since our HW does not support inversed polarity, the output for above case
is expected to be constant low. And if we disable PWM before checking for
polarity, the output becomes constant low. The code just does that. Sorry,
i could not understand what is wrong with the code. It looks correct to me.

Given the fact that we support fixed period, if we allow
state->period < pc->period case then the duty cycle will be evaluated as
higher than the requested one because the state->period is lesser than
the actual fixed period supported by the HW. Can you please elaborate
on why you think we should allow state->period < pc->period case?

Thanks,

Regards,
Rahul



Re: [PATCH 18/23] init: open code setting up stdin/stdout/stderr

2020-07-26 Thread Al Viro
On Mon, Jul 27, 2020 at 07:46:25AM +0200, Christoph Hellwig wrote:
> On Mon, Jul 27, 2020 at 04:05:34AM +0100, Al Viro wrote:
> > On Tue, Jul 14, 2020 at 09:04:22PM +0200, Christoph Hellwig wrote:
> > > Don't rely on the implicit set_fs(KERNEL_DS) for ksys_open to work, but
> > > instead open a struct file for /dev/console and then install it as FD
> > > 0/1/2 manually.
> > 
> > I really hate that one.  Every time we exposed the internal details to
> > the fucking early init code, we paid for that afterwards.  And this
> > goes over the top wrt the level of details being exposed.
> > 
> > _IF_ you want to keep that thing, move it to fs/file.c, with dire comment
> > re that being very special shite for init and likely cause of subsequent
> > trouble whenever anything gets changed, a gnat farts somewhere, etc.
> 
> Err, while I'm all for keeping internals internal, fd_install and
> get_unused_fd_flags are exported routines with tons of users of this
> pattern all over.

get_file_rcu_many()?  All over the place?  Besides, that's _not_ the normal
pattern for get_unused_fd() - there's a very special reason we don't expect
an error from it here.


[PATCH] drm/dp_mst: Support remote i2c writes

2020-07-26 Thread Sam McNally
For DP MST outputs, the i2c device currently only supports transfers
that can be implemented using remote i2c reads. Such transfers must
consist of zero or more write transactions followed by one read
transaction. DDC/CI commands require standalone write transactions and
hence aren't supported.

Since each remote i2c write is handled as a separate transfer, remote
i2c writes can support transfers consisting of write transactions, where
all but the last have I2C_M_STOP set. According to the DDC/CI 1.1
standard, DDC/CI commands only require a single write or read
transaction in a transfer, so this is sufficient.

For i2c transfers meeting the above criteria, generate and send a remote
i2c write message for each transaction. Add the trivial remote i2c write
reply parsing support so remote i2c write acks bubble up correctly.

Signed-off-by: Sam McNally 
---

 drivers/gpu/drm/drm_dp_mst_topology.c | 106 ++
 1 file changed, 90 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c 
b/drivers/gpu/drm/drm_dp_mst_topology.c
index 09b32289497e..1ac874e4e7a1 100644
--- a/drivers/gpu/drm/drm_dp_mst_topology.c
+++ b/drivers/gpu/drm/drm_dp_mst_topology.c
@@ -961,6 +961,8 @@ static bool drm_dp_sideband_parse_reply(struct 
drm_dp_sideband_msg_rx *raw,
return drm_dp_sideband_parse_remote_dpcd_write(raw, msg);
case DP_REMOTE_I2C_READ:
return drm_dp_sideband_parse_remote_i2c_read_ack(raw, msg);
+   case DP_REMOTE_I2C_WRITE:
+   return true; /* since there's nothing to parse */
case DP_ENUM_PATH_RESOURCES:
return drm_dp_sideband_parse_enum_path_resources_ack(raw, msg);
case DP_ALLOCATE_PAYLOAD:
@@ -5326,29 +5328,29 @@ static bool remote_i2c_read_ok(const struct i2c_msg 
msgs[], int num)
msgs[num - 1].len <= 0xff;
 }
 
-/* I2C device */
-static int drm_dp_mst_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg 
*msgs,
-  int num)
+static bool remote_i2c_write_ok(const struct i2c_msg msgs[], int num)
+{
+   int i;
+
+   for (i = 0; i < num - 1; i++) {
+   if (msgs[i].flags & I2C_M_RD || !(msgs[i].flags & I2C_M_STOP) ||
+   msgs[i].len > 0xff)
+   return false;
+   }
+
+   return !(msgs[num - 1].flags & I2C_M_RD) && msgs[num - 1].len <= 0xff;
+}
+
+static int drm_dp_mst_i2c_read(struct drm_dp_mst_branch *mstb,
+  struct drm_dp_mst_port *port,
+  struct i2c_msg *msgs, int num)
 {
-   struct drm_dp_aux *aux = adapter->algo_data;
-   struct drm_dp_mst_port *port = container_of(aux, struct 
drm_dp_mst_port, aux);
-   struct drm_dp_mst_branch *mstb;
struct drm_dp_mst_topology_mgr *mgr = port->mgr;
unsigned int i;
struct drm_dp_sideband_msg_req_body msg;
struct drm_dp_sideband_msg_tx *txmsg = NULL;
int ret;
 
-   mstb = drm_dp_mst_topology_get_mstb_validated(mgr, port->parent);
-   if (!mstb)
-   return -EREMOTEIO;
-
-   if (!remote_i2c_read_ok(msgs, num)) {
-   DRM_DEBUG_KMS("Unsupported I2C transaction for MST device\n");
-   ret = -EIO;
-   goto out;
-   }
-
memset(&msg, 0, sizeof(msg));
msg.req_type = DP_REMOTE_I2C_READ;
msg.u.i2c_read.num_transactions = num - 1;
@@ -5389,6 +5391,78 @@ static int drm_dp_mst_i2c_xfer(struct i2c_adapter 
*adapter, struct i2c_msg *msgs
}
 out:
kfree(txmsg);
+   return ret;
+}
+
+static int drm_dp_mst_i2c_write(struct drm_dp_mst_branch *mstb,
+   struct drm_dp_mst_port *port,
+   struct i2c_msg *msgs, int num)
+{
+   struct drm_dp_mst_topology_mgr *mgr = port->mgr;
+   unsigned int i;
+   struct drm_dp_sideband_msg_req_body msg;
+   struct drm_dp_sideband_msg_tx *txmsg = NULL;
+   int ret;
+
+   txmsg = kzalloc(sizeof(*txmsg), GFP_KERNEL);
+   if (!txmsg) {
+   ret = -ENOMEM;
+   goto out;
+   }
+   for (i = 0; i < num; i++) {
+   memset(&msg, 0, sizeof(msg));
+   msg.req_type = DP_REMOTE_I2C_WRITE;
+   msg.u.i2c_write.port_number = port->port_num;
+   msg.u.i2c_write.write_i2c_device_id = msgs[i].addr;
+   msg.u.i2c_write.num_bytes = msgs[i].len;
+   msg.u.i2c_write.bytes = msgs[i].buf;
+
+   memset(txmsg, 0, sizeof(*txmsg));
+   txmsg->dst = mstb;
+
+   drm_dp_encode_sideband_req(&msg, txmsg);
+   drm_dp_queue_down_tx(mgr, txmsg);
+
+   ret = drm_dp_mst_wait_tx_reply(mstb, txmsg);
+   if (ret > 0) {
+   if (txmsg->reply.reply_type == DP_SIDEBAND_REPLY_NAK) {
+   ret = -EREMOTEIO;
+   goto out;
+   

Re: [PATCH 4/4] x86/cpu: Use SERIALIZE in sync_core() when available

2020-07-26 Thread hpa
On July 26, 2020 10:55:15 PM PDT, h...@zytor.com wrote:
>On July 26, 2020 9:31:32 PM PDT, Ricardo Neri
> wrote:
>>The SERIALIZE instruction gives software a way to force the processor
>>to
>>complete all modifications to flags, registers and memory from
>previous
>>instructions and drain all buffered writes to memory before the next
>>instruction is fetched and executed. Thus, it serves the purpose of
>>sync_core(). Use it when available.
>>
>>Use boot_cpu_has() and not static_cpu_has(); the most critical paths
>>(returning to user mode and from interrupt and NMI) will not reach
>>sync_core().
>>
>>Cc: Andy Lutomirski 
>>Cc: Cathy Zhang 
>>Cc: Dave Hansen 
>>Cc: Fenghua Yu 
>>Cc: "H. Peter Anvin" 
>>Cc: Kyung Min Park 
>>Cc: Peter Zijlstra 
>>Cc: "Ravi V. Shankar" 
>>Cc: Sean Christopherson 
>>Cc: linux-e...@vger.kernel.org
>>Cc: linux-kernel@vger.kernel.org
>>Reviwed-by: Tony Luck 
>>Suggested-by: Andy Lutomirski 
>>Signed-off-by: Ricardo Neri 
>>---
>>---
>> arch/x86/include/asm/special_insns.h |  5 +
>> arch/x86/include/asm/sync_core.h | 10 +-
>> 2 files changed, 14 insertions(+), 1 deletion(-)
>>
>>diff --git a/arch/x86/include/asm/special_insns.h
>>b/arch/x86/include/asm/special_insns.h
>>index 59a3e13204c3..0a2a60bba282 100644
>>--- a/arch/x86/include/asm/special_insns.h
>>+++ b/arch/x86/include/asm/special_insns.h
>>@@ -234,6 +234,11 @@ static inline void clwb(volatile void *__p)
>> 
>> #define nop() asm volatile ("nop")
>> 
>>+static inline void serialize(void)
>>+{
>>+ asm volatile(".byte 0xf, 0x1, 0xe8");
>>+}
>>+
>> #endif /* __KERNEL__ */
>> 
>> #endif /* _ASM_X86_SPECIAL_INSNS_H */
>>diff --git a/arch/x86/include/asm/sync_core.h
>>b/arch/x86/include/asm/sync_core.h
>>index fdb5b356e59b..bf132c09d61b 100644
>>--- a/arch/x86/include/asm/sync_core.h
>>+++ b/arch/x86/include/asm/sync_core.h
>>@@ -5,6 +5,7 @@
>> #include 
>> #include 
>> #include 
>>+#include 
>> 
>> #ifdef CONFIG_X86_32
>> static inline void iret_to_self(void)
>>@@ -54,7 +55,8 @@ static inline void iret_to_self(void)
>> static inline void sync_core(void)
>> {
>>  /*
>>-  * There are quite a few ways to do this.  IRET-to-self is nice
>>+  * Hardware can do this for us if SERIALIZE is available. Otherwise,
>>+  * there are quite a few ways to do this.  IRET-to-self is nice
>>   * because it works on every CPU, at any CPL (so it's compatible
>>   * with paravirtualization), and it never exits to a hypervisor.
>>   * The only down sides are that it's a bit slow (it seems to be
>>@@ -75,6 +77,12 @@ static inline void sync_core(void)
>>   * Like all of Linux's memory ordering operations, this is a
>>   * compiler barrier as well.
>>   */
>>+
>>+ if (boot_cpu_has(X86_FEATURE_SERIALIZE)) {
>>+ serialize();
>>+ return;
>>+ }
>>+
>>  iret_to_self();
>> }
>> 
>
>Any reason to not make sync_core() an inline with alternatives?
>
>For a really overenginered solution, but which might perform
>unnecessary poorly on existing hardware:
>
>asm volatile("1: .byte 0xf, 0x1, 0xe8; 2:"
>_ASM_EXTABLE(1b,2b));

(and : : : "memory" of course.)
-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


Re: [PATCH] drm/amd/display: Clear dm_state for fast updates

2020-07-26 Thread Mazin Rezk
On Monday, July 27, 2020 1:40 AM, Mazin Rezk  wrote:
> This patch fixes a race condition that causes a use-after-free during
> amdgpu_dm_atomic_commit_tail. This can occur when 2 non-blocking commits
> are requested and the second one finishes before the first. Essentially,
> this bug occurs when the following sequence of events happens:
>
> 1. Non-blocking commit #1 is requested w/ a new dm_state #1 and is
> deferred to the workqueue.
>
> 2. Non-blocking commit #2 is requested w/ a new dm_state #2 and is
> deferred to the workqueue.
>
> 3. Commit #2 starts before commit #1, dm_state #1 is used in the
> commit_tail and commit #2 completes, freeing dm_state #1.
>
> 4. Commit #1 starts after commit #2 completes, uses the freed dm_state
> 1 and dereferences a freelist pointer while setting the context.
>
> Since this bug has only been spotted with fast commits, this patch fixes
> the bug by clearing the dm_state instead of using the old dc_state for
> fast updates. In addition, since dm_state is only used for its dc_state
> and amdgpu_dm_atomic_commit_tail will retain the dc_state if none is found,
> removing the dm_state should not have any consequences in fast updates.
>
> This use-after-free bug has existed for a while now, but only caused a
> noticeable issue starting from 5.7-rc1 due to 3202fa62f ("slub: relocate
> freelist pointer to middle of object") moving the freelist pointer from
> dm_state->base (which was unused) to dm_state->context (which is
> dereferenced).
>
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=207383
> Fixes: bd200d190f45 ("drm/amd/display: Don't replace the dc_state for fast 
> updates")
> Reported-by: Duncan <1i5t5.dun...@cox.net>
> Signed-off-by: Mazin Rezk 
> ---
>  .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 36 ++-
>  1 file changed, 27 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
> b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> index 86ffa0c2880f..710edc70e37e 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> @@ -8717,20 +8717,38 @@ static int amdgpu_dm_atomic_check(struct drm_device 
> *dev,
>* the same resource. If we have a new DC context as part of
>* the DM atomic state from validation we need to free it and
>* retain the existing one instead.
> +  *
> +  * Furthermore, since the DM atomic state only contains the DC
> +  * context and can safely be annulled, we can free the state
> +  * and clear the associated private object now to free
> +  * some memory and avoid a possible use-after-free later.
>*/
> - struct dm_atomic_state *new_dm_state, *old_dm_state;
>
> - new_dm_state = dm_atomic_get_new_state(state);
> - old_dm_state = dm_atomic_get_old_state(state);
> + for (i = 0; i < state->num_private_objs; i++) {
> + struct drm_private_obj *obj = 
> state->private_objs[i].ptr;
>
> - if (new_dm_state && old_dm_state) {
> - if (new_dm_state->context)
> - dc_release_state(new_dm_state->context);
> + if (obj->funcs == adev->dm.atomic_obj.funcs) {
> + int j = state->num_private_objs-1;
>
> - new_dm_state->context = old_dm_state->context;
> + dm_atomic_destroy_state(obj,
> + state->private_objs[i].state);
> +
> + /* If i is not at the end of the array then the
> +  * last element needs to be moved to where i was
> +  * before the array can safely be truncated.
> +  */
> + if (i != j)
> + state->private_objs[i] =
> + state->private_objs[j];
>
> - if (old_dm_state->context)
> - dc_retain_state(old_dm_state->context);
> + state->private_objs[j].ptr = NULL;
> + state->private_objs[j].state = NULL;
> + state->private_objs[j].old_state = NULL;
> + state->private_objs[j].new_state = NULL;
> +
> + state->num_private_objs = j;
> + break;
> + }
>   }
>   }
>
> --
> 2.27.0
>

I have tested this on 5.8.0-rc6 w/ an RX 480 for 8 hours and I have not had
the crash described in the Bugzilla thread. I will also be running this
patch on my kernel for the next couple of days to further confirm that this
is working. In addition, I will ask the users in the Bugzilla thread to
test this patch

Re: [PATCH v2 03/18] gpiolib: make cdev a build option

2020-07-26 Thread Kent Gibson
On Mon, Jul 27, 2020 at 09:46:01AM +0800, Kent Gibson wrote:
> On Mon, Jul 27, 2020 at 12:25:53AM +0200, Linus Walleij wrote:
> > On Sat, Jul 25, 2020 at 6:21 AM Kent Gibson  wrote:
> > 
> > > +config GPIO_CDEV
> > > +   bool "/dev/gpiochipN (character device interface)"
> > > +   default y
> > 
> > I don't want to make it too easy to do this, as I see it as a standard
> > kernel feature.
> > 
> > Can we add:
> > 
> > depends on EXPERT
> > 
> > as with other standard kernel features?
> > 
> 
> Fair enough.
> 
> But what of the GPIO_CDEV_V1 option to disable uAPI V1 added in patch 04,
> and that depends on GPIO_CDEV?
> That is equivalent to GPIO_SYSFS, which is not dependent on EXPERT,
> so I'll need to restructure the dependencies so it doesn't
> inherit the EXPERT dependency.
> Unless you also want it to be dependent on EXPERT.
> 

I've gone with this:

+config GPIO_CDEV
+   bool
+   prompt "Character device (/dev/gpiochipN) support" if EXPERT
+   default y

so the entry is always present in menuconfig, and GPIO_CDEV_V1 can still
depend on it, but GPIO_CDEV can only be disabled if EXPERT is set.

> Hmmm, and maybe patch 04 should be later in the series - after V2 is
> fully implemented and V1 is deprecated - around patch 11.
> 

Just ignore me - the earlier code patches need the define else the V1
will be compiled out.

Cheers,
Kent.


Re: [PATCH 4/4] x86/cpu: Use SERIALIZE in sync_core() when available

2020-07-26 Thread hpa
On July 26, 2020 9:31:32 PM PDT, Ricardo Neri 
 wrote:
>The SERIALIZE instruction gives software a way to force the processor
>to
>complete all modifications to flags, registers and memory from previous
>instructions and drain all buffered writes to memory before the next
>instruction is fetched and executed. Thus, it serves the purpose of
>sync_core(). Use it when available.
>
>Use boot_cpu_has() and not static_cpu_has(); the most critical paths
>(returning to user mode and from interrupt and NMI) will not reach
>sync_core().
>
>Cc: Andy Lutomirski 
>Cc: Cathy Zhang 
>Cc: Dave Hansen 
>Cc: Fenghua Yu 
>Cc: "H. Peter Anvin" 
>Cc: Kyung Min Park 
>Cc: Peter Zijlstra 
>Cc: "Ravi V. Shankar" 
>Cc: Sean Christopherson 
>Cc: linux-e...@vger.kernel.org
>Cc: linux-kernel@vger.kernel.org
>Reviwed-by: Tony Luck 
>Suggested-by: Andy Lutomirski 
>Signed-off-by: Ricardo Neri 
>---
>---
> arch/x86/include/asm/special_insns.h |  5 +
> arch/x86/include/asm/sync_core.h | 10 +-
> 2 files changed, 14 insertions(+), 1 deletion(-)
>
>diff --git a/arch/x86/include/asm/special_insns.h
>b/arch/x86/include/asm/special_insns.h
>index 59a3e13204c3..0a2a60bba282 100644
>--- a/arch/x86/include/asm/special_insns.h
>+++ b/arch/x86/include/asm/special_insns.h
>@@ -234,6 +234,11 @@ static inline void clwb(volatile void *__p)
> 
> #define nop() asm volatile ("nop")
> 
>+static inline void serialize(void)
>+{
>+  asm volatile(".byte 0xf, 0x1, 0xe8");
>+}
>+
> #endif /* __KERNEL__ */
> 
> #endif /* _ASM_X86_SPECIAL_INSNS_H */
>diff --git a/arch/x86/include/asm/sync_core.h
>b/arch/x86/include/asm/sync_core.h
>index fdb5b356e59b..bf132c09d61b 100644
>--- a/arch/x86/include/asm/sync_core.h
>+++ b/arch/x86/include/asm/sync_core.h
>@@ -5,6 +5,7 @@
> #include 
> #include 
> #include 
>+#include 
> 
> #ifdef CONFIG_X86_32
> static inline void iret_to_self(void)
>@@ -54,7 +55,8 @@ static inline void iret_to_self(void)
> static inline void sync_core(void)
> {
>   /*
>-   * There are quite a few ways to do this.  IRET-to-self is nice
>+   * Hardware can do this for us if SERIALIZE is available. Otherwise,
>+   * there are quite a few ways to do this.  IRET-to-self is nice
>* because it works on every CPU, at any CPL (so it's compatible
>* with paravirtualization), and it never exits to a hypervisor.
>* The only down sides are that it's a bit slow (it seems to be
>@@ -75,6 +77,12 @@ static inline void sync_core(void)
>* Like all of Linux's memory ordering operations, this is a
>* compiler barrier as well.
>*/
>+
>+  if (boot_cpu_has(X86_FEATURE_SERIALIZE)) {
>+  serialize();
>+  return;
>+  }
>+
>   iret_to_self();
> }
> 

Any reason to not make sync_core() an inline with alternatives?

For a really overenginered solution, but which might perform unnecessary poorly 
on existing hardware:

asm volatile("1: .byte 0xf, 0x1, 0xe8; 2:"
_ASM_EXTABLE(1b,2b));

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


[PATCH] checkpatch: disable commit log length check warning for signature tag

2020-07-26 Thread Nachiket Naganure
Disable commit log length check in case of signature tag. If the commit
log line has valid signature tags such as "Reported-and-tested-by" with
more than 75 characters, suppress the long length warning.

For instance in commit ac854131d984 ("USB: core: Fix misleading driver bug
report"), the corresponding patch contains a "Reported by" tag line which
exceeds 75 chars. And there is no valid way to shorten the length.

Signed-off-by: Nachiket Naganure 
---
 scripts/checkpatch.pl | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 197436b20288..46237e9e0550 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2806,6 +2806,8 @@ sub process {
# filename then :
  $line =~ /^\s*(?:Fixes:|Link:)/i ||
# A Fixes: or Link: line
+ $line =~ /$signature_tags/ ||
+   # Check for signature_tags
  $commit_log_possible_stack_dump)) {
WARN("COMMIT_LOG_LONG_LINE",
 "Possible unwrapped commit description (prefer a 
maximum 75 chars per line)\n" . $herecurr);
-- 
2.25.1



Re: [PATCH v4 4/5] arm64: dts: sdm845: Add OPP tables and power-domains for venus

2020-07-26 Thread Rajendra Nayak




On 7/24/2020 7:39 PM, Stanimir Varbanov wrote:

Hi,

On 7/23/20 9:06 PM, Stanimir Varbanov wrote:

Hi Rajendra,

After applying 2,3 and 4/5 patches on linaro-integration v5.8-rc2 I see
below messages on db845:

qcom-venus aa0.video-codec: dev_pm_opp_set_rate: failed to find
current OPP for freq 53397 (-34)

^^^ This one is new.

qcom_rpmh TCS Busy, retrying RPMH message send: addr=0x3

^^^ and this message is annoying, can we make it pr_debug in rpmh?

On 7/23/20 2:26 PM, Rajendra Nayak wrote:

Add the OPP tables in order to be able to vote on the performance state of
a power-domain.

Signed-off-by: Rajendra Nayak 
---
  arch/arm64/boot/dts/qcom/sdm845.dtsi | 40 ++--
  1 file changed, 38 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/boot/dts/qcom/sdm845.dtsi 
b/arch/arm64/boot/dts/qcom/sdm845.dtsi
index e506793..5ca2265 100644
--- a/arch/arm64/boot/dts/qcom/sdm845.dtsi
+++ b/arch/arm64/boot/dts/qcom/sdm845.dtsi
@@ -3631,8 +3631,10 @@
interrupts = ;
power-domains = <&videocc VENUS_GDSC>,
<&videocc VCODEC0_GDSC>,
-   <&videocc VCODEC1_GDSC>;
-   power-domain-names = "venus", "vcodec0", "vcodec1";
+   <&videocc VCODEC1_GDSC>,
+   <&rpmhpd SDM845_CX>;
+   power-domain-names = "venus", "vcodec0", "vcodec1", 
"cx";
+   operating-points-v2 = <&venus_opp_table>;
clocks = <&videocc VIDEO_CC_VENUS_CTL_CORE_CLK>,
 <&videocc VIDEO_CC_VENUS_AHB_CLK>,
 <&videocc VIDEO_CC_VENUS_CTL_AXI_CLK>,
@@ -3654,6 +3656,40 @@
video-core1 {
compatible = "venus-encoder";
};
+
+   venus_opp_table: venus-opp-table {
+   compatible = "operating-points-v2";
+
+   opp-1 {
+   opp-hz = /bits/ 64 <1>;
+   required-opps = <&rpmhpd_opp_min_svs>;
+   };
+
+   opp-2 {
+   opp-hz = /bits/ 64 <2>;
+   required-opps = <&rpmhpd_opp_low_svs>;
+   };
+
+   opp-32000 {
+   opp-hz = /bits/ 64 <32000>;
+   required-opps = <&rpmhpd_opp_svs>;
+   };
+
+   opp-38000 {
+   opp-hz = /bits/ 64 <38000>;
+   required-opps = <&rpmhpd_opp_svs_l1>;
+   };
+
+   opp-44400 {
+   opp-hz = /bits/ 64 <44400>;
+   required-opps = <&rpmhpd_opp_nom>;
+   };
+
+   opp-53300 {
+   opp-hz = /bits/ 64 <53300>;


Actually it comes from videocc, where ftbl_video_cc_venus_clk_src
defines 53300 but the real calculated freq is 53397.


I still don't quite understand why the videocc driver returns this
frequency despite this not being in the freq table.
I would expect a clk_round_rate() when called with 53397 to return
a 53300.

Taniya, Do you know why?



If I change to opp-hz = /bits/ 64 <53397> the error disappear.

I guess we have to revisit m/n and/or pre-divider for this freq when the
source pll is P_VIDEO_PLL0_OUT_MAIN PLL?


+   required-opps = <&rpmhpd_opp_turbo>;
+   };
+   };
};
  
  		videocc: clock-controller@ab0 {








--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation


Re: linux-next: Fixes tag needs some work in the devfreq tree

2020-07-26 Thread Chanwoo Choi
Hi,

On 7/27/20 1:17 PM, Stephen Rothwell wrote:
> Hi,
> 
> On Mon, 27 Jul 2020 13:24:28 +1000 Stephen Rothwell  
> wrote:
>>
>> Hi all,
>>
>> In commit
>>
>>   332c5b522b7c ("PM / devfrq: Fix indentaion of devfreq_summary debugfs 
>> node")
> 
> This is now commit 470fa173646f
> 
>> Fixes tag
>>
>>   Fixes: commit 66d0e797bf09 ("Revert "PM / devfreq: Modify the device name 
>> as devfreq(X) for sysfs"")
>>
>> has these problem(s):
>>
>>   - leading word 'commit' unexpected
> 

Thanks for pointing out. I fixed it. Thanks.


-- 
Best Regards,
Chanwoo Choi
Samsung Electronics


Re: [PATCH] rtlwifi: core: use eth_broadcast_addr() to assign broadcast

2020-07-26 Thread Pkshih
On Mon, 2020-07-27 at 02:16 +, Xu Wang wrote:
> This patch is to use eth_broadcast_addr() to assign broadcast address
> insetad of memcpy().
> 
> Signed-off-by: Xu Wang 
> ---
>  drivers/net/wireless/realtek/rtlwifi/core.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/net/wireless/realtek/rtlwifi/core.c
> b/drivers/net/wireless/realtek/rtlwifi/core.c
> index 4dd82c6052f0..8bb49b77b5c8 100644
> --- a/drivers/net/wireless/realtek/rtlwifi/core.c
> +++ b/drivers/net/wireless/realtek/rtlwifi/core.c
> @@ -1512,7 +1512,6 @@ static int rtl_op_set_key(struct ieee80211_hw *hw, enum
> set_key_cmd cmd,
>   bool wep_only = false;
>   int err = 0;
>   u8 mac_addr[ETH_ALEN];
> - u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
>  
>   rtlpriv->btcoexist.btc_info.in_4way = false;
>  


'bcast_addr' is also used by debug:

        RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,  
 "%s hardware based encryption for keyidx: %d, mac: %pM\n", 
  cmd == SET_KEY ? "Using" : "Disabling", key->keyidx,  
  sta ? sta->addr : bcast_addr); 

If you turn on CONFIG_RTLWIFI_DEBUG, compiler must warn an error.
So, NACK.

> @@ -1634,7 +1633,7 @@ static int rtl_op_set_key(struct ieee80211_hw *hw, enum
> set_key_cmd cmd,
>   memcpy(rtlpriv->sec.key_buf[key_idx],
>      key->key, key->keylen);
>   rtlpriv->sec.key_len[key_idx] = key->keylen;
> - memcpy(mac_addr, bcast_addr, ETH_ALEN);
> + eth_broadcast_addr(mac_addr);
>   } else {/* pairwise key */
>   RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
>    "set pairwise key\n");


Re: [PATCH 1/2] fsi/sbefifo: Clean up correct FIFO when receiving reset request from SBE

2020-07-26 Thread Benjamin Herrenschmidt
On Fri, 2020-07-24 at 16:45 +0930, Joel Stanley wrote:
> From: Joachim Fenkes 
> 
> When the SBE requests a reset via the down FIFO, that is also the
> FIFO we should go and reset ;)

Is it ?

I no longer work for IBM and dont have access to any of the
documentation here but I had vague memories that we would get a reset
request in the down fifo in order to reset the up one since we control
the up one and the host controls the down one, no ?

Cheers,
Ben.

> Fixes: 9f4a8a2d7f9d ("fsi/sbefifo: Add driver for the SBE FIFO")
> Signed-off-by: Joachim Fenkes 
> Signed-off-by: Joel Stanley 
> ---
>  drivers/fsi/fsi-sbefifo.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/fsi/fsi-sbefifo.c b/drivers/fsi/fsi-sbefifo.c
> index f54df9ebc8b3..655b45c1f6ba 100644
> --- a/drivers/fsi/fsi-sbefifo.c
> +++ b/drivers/fsi/fsi-sbefifo.c
> @@ -400,7 +400,7 @@ static int sbefifo_cleanup_hw(struct sbefifo
> *sbefifo)
>   /* The FIFO already contains a reset request from the SBE ? */
>   if (down_status & SBEFIFO_STS_RESET_REQ) {
>   dev_info(dev, "Cleanup: FIFO reset request set,
> resetting\n");
> - rc = sbefifo_regw(sbefifo, SBEFIFO_UP,
> SBEFIFO_PERFORM_RESET);
> + rc = sbefifo_regw(sbefifo, SBEFIFO_DOWN,
> SBEFIFO_PERFORM_RESET);
>   if (rc) {
>   sbefifo->broken = true;
>   dev_err(dev, "Cleanup: Reset reg write failed,
> rc=%d\n", rc);



Re: [PATCH v2] soc: qcom: rpmh-rsc: Sleep waiting for tcs slots to be free

2020-07-26 Thread Maulik Shah

Hi,

Change looks good to me.

Reviewed-by: Maulik Shah 

Thanks,
Maulik

On 7/25/2020 2:47 AM, Stephen Boyd wrote:

From: Stephen Boyd 

The busy loop in rpmh_rsc_send_data() is written with the assumption
that the udelay will be preempted by the tcs_tx_done() irq handler when
the TCS slots are all full. This doesn't hold true when the calling
thread is an irqthread and the tcs_tx_done() irq is also an irqthread.
That's because kernel irqthreads are SCHED_FIFO and thus need to
voluntarily give up priority by calling into the scheduler so that other
threads can run.

I see RCU stalls when I boot with irqthreads on the kernel commandline
because the modem remoteproc driver is trying to send an rpmh async
message from an irqthread that needs to give up the CPU for the rpmh
irqthread to run and clear out tcs slots.

  rcu: INFO: rcu_preempt self-detected stall on CPU
  rcu: 0-: (1 GPs behind) idle=402/1/0x4002 
softirq=2108/2109 fqs=4920
   (t=21016 jiffies g=2933 q=590)
  Task dump for CPU 0:
  irq/11-smp2pR  running task0   148  2 0x0028
  Call trace:
   dump_backtrace+0x0/0x154
   show_stack+0x20/0x2c
   sched_show_task+0xfc/0x108
   dump_cpu_task+0x44/0x50
   rcu_dump_cpu_stacks+0xa4/0xf8
   rcu_sched_clock_irq+0x7dc/0xaa8
   update_process_times+0x30/0x54
   tick_sched_handle+0x50/0x64
   tick_sched_timer+0x4c/0x8c
   __hrtimer_run_queues+0x21c/0x36c
   hrtimer_interrupt+0xf0/0x22c
   arch_timer_handler_phys+0x40/0x50
   handle_percpu_devid_irq+0x114/0x25c
   __handle_domain_irq+0x84/0xc4
   gic_handle_irq+0xd0/0x178
   el1_irq+0xbc/0x180
   save_return_addr+0x18/0x28
   return_address+0x54/0x88
   preempt_count_sub+0x40/0x88
   _raw_spin_unlock_irqrestore+0x4c/0x6c
   ___ratelimit+0xd0/0x128
   rpmh_rsc_send_data+0x24c/0x378
   __rpmh_write+0x1b0/0x208
   rpmh_write_async+0x90/0xbc
   rpmhpd_send_corner+0x60/0x8c
   rpmhpd_aggregate_corner+0x8c/0x124
   rpmhpd_set_performance_state+0x8c/0xbc
   _genpd_set_performance_state+0xdc/0x1b8
   dev_pm_genpd_set_performance_state+0xb8/0xf8
   q6v5_pds_disable+0x34/0x60 [qcom_q6v5_mss]
   qcom_msa_handover+0x38/0x44 [qcom_q6v5_mss]
   q6v5_handover_interrupt+0x24/0x3c [qcom_q6v5]
   handle_nested_irq+0xd0/0x138
   qcom_smp2p_intr+0x188/0x200
   irq_thread_fn+0x2c/0x70
   irq_thread+0xfc/0x14c
   kthread+0x11c/0x12c
   ret_from_fork+0x10/0x18

This busy loop naturally lends itself to using a wait queue so that each
thread that tries to send a message will sleep waiting on the waitqueue
and only be woken up when a free slot is available. This should make
things more predictable too because the scheduler will be able to sleep
tasks that are waiting on a free tcs instead of the busy loop we
currently have today.

Cc: Douglas Anderson 
Cc: Maulik Shah 
Cc: Lina Iyer 
Signed-off-by: Stephen Boyd 
---

Changes in v2:
  * Document tcs_wait
  * Move wake_up() outside of the spinlock
  * Document claim_tcs_for_req()

  drivers/soc/qcom/rpmh-internal.h |   4 ++
  drivers/soc/qcom/rpmh-rsc.c  | 115 +++
  2 files changed, 58 insertions(+), 61 deletions(-)

diff --git a/drivers/soc/qcom/rpmh-internal.h b/drivers/soc/qcom/rpmh-internal.h
index ef60e790a750..344ba687c13b 100644
--- a/drivers/soc/qcom/rpmh-internal.h
+++ b/drivers/soc/qcom/rpmh-internal.h
@@ -8,6 +8,7 @@
  #define __RPM_INTERNAL_H__
  
  #include 

+#include 
  #include 
  
  #define TCS_TYPE_NR			4

@@ -106,6 +107,8 @@ struct rpmh_ctrlr {
   * @lock:   Synchronize state of the controller.  If RPMH's cache
   *  lock will also be held, the order is: drv->lock then
   *  cache_lock.
+ * @tcs_wait:   Wait queue used to wait for @tcs_in_use to free up a
+ *  slot
   * @client: Handle to the DRV's client.
   */
  struct rsc_drv {
@@ -118,6 +121,7 @@ struct rsc_drv {
struct tcs_group tcs[TCS_TYPE_NR];
DECLARE_BITMAP(tcs_in_use, MAX_TCS_NR);
spinlock_t lock;
+   wait_queue_head_t tcs_wait;
struct rpmh_ctrlr client;
  };
  
diff --git a/drivers/soc/qcom/rpmh-rsc.c b/drivers/soc/qcom/rpmh-rsc.c

index 076fd27f3081..84a27b884af0 100644
--- a/drivers/soc/qcom/rpmh-rsc.c
+++ b/drivers/soc/qcom/rpmh-rsc.c
@@ -19,6 +19,7 @@
  #include 
  #include 
  #include 
+#include 
  
  #include 

  #include 
@@ -445,6 +446,7 @@ static irqreturn_t tcs_tx_done(int irq, void *p)
if (!drv->tcs[ACTIVE_TCS].num_tcs)
enable_tcs_irq(drv, i, false);
spin_unlock(&drv->lock);
+   wake_up(&drv->tcs_wait);
if (req)
rpmh_tx_done(req, err);
}
@@ -563,73 +565,34 @@ static int find_free_tcs(struct tcs_group *tcs)
  }
  
  /**

- * tcs_write() - Store messages into a TCS right now, or return -EBUSY.
+ * claim_tcs_for_req() - Claim a tcs in the given tcs_group; only for active.
   * @drv: The controller.
+ * @tcs: The tcs_group used for ACTIVE_

Re: [PATCH 18/23] init: open code setting up stdin/stdout/stderr

2020-07-26 Thread Christoph Hellwig
On Mon, Jul 27, 2020 at 04:05:34AM +0100, Al Viro wrote:
> On Tue, Jul 14, 2020 at 09:04:22PM +0200, Christoph Hellwig wrote:
> > Don't rely on the implicit set_fs(KERNEL_DS) for ksys_open to work, but
> > instead open a struct file for /dev/console and then install it as FD
> > 0/1/2 manually.
> 
> I really hate that one.  Every time we exposed the internal details to
> the fucking early init code, we paid for that afterwards.  And this
> goes over the top wrt the level of details being exposed.
> 
> _IF_ you want to keep that thing, move it to fs/file.c, with dire comment
> re that being very special shite for init and likely cause of subsequent
> trouble whenever anything gets changed, a gnat farts somewhere, etc.

Err, while I'm all for keeping internals internal, fd_install and
get_unused_fd_flags are exported routines with tons of users of this
pattern all over.


Re: [RESEND PATCH] usb: common: usb-conn-gpio: Register optional charger

2020-07-26 Thread Chunfeng Yun
On Sun, 2020-07-26 at 12:27 +0200, Paul Cercueil wrote:
> 
> Le dim. 26 juil. 2020 à 13:14, Andy Shevchenko 
>  a écrit :
> > On Mon, Jun 22, 2020 at 1:51 AM Paul Cercueil  
> > wrote:
> >> 
> >>  Register a power supply charger, if the Kconfig option
> >>  USB_CONN_GPIO_CHARGER is set, whose online state depends on whether
> >>  the USB role is set to device or not.
> >> 
> >>  This is useful when the USB role is the only way to know if the 
> >> device
> >>  is charging from USB. The API is the standard power supply charger 
> >> API,
> >>  you get a /sys/class/power_supply/xxx/online node which tells you 
> >> the
> >>  state of the charger.
> >> 
> >>  The sole purpose of this is to give userspace applications a way to
> >>  know whether or not the charger is plugged.
> > 
> > I'm not sure I understand the purpose of this (third?) way to detect
> > USB charger and notify user space about.
> > Why is extcon not good enough?
> 
> We can't have extcon and USB role detection at the same time.
> 
> -Paul
> 
> >>  Signed-off-by: Paul Cercueil 
> >>  ---
> >>   drivers/usb/common/Kconfig | 11 +++
> >>   drivers/usb/common/usb-conn-gpio.c | 47 
> >> ++
> >>   2 files changed, 58 insertions(+)
> >> 
> >>  diff --git a/drivers/usb/common/Kconfig b/drivers/usb/common/Kconfig
> >>  index d611477aae41..5405ae96c68f 100644
> >>  --- a/drivers/usb/common/Kconfig
> >>  +++ b/drivers/usb/common/Kconfig
> >>  @@ -49,3 +49,14 @@ config USB_CONN_GPIO
> >> 
> >>To compile the driver as a module, choose M here: the 
> >> module will
> >>be called usb-conn-gpio.ko
> >>  +
> >>  +if USB_CONN_GPIO
> >>  +
> >>  +config USB_CONN_GPIO_CHARGER
> >>  +   bool "USB charger support"
> >>  +   select POWER_SUPPLY
> >>  +   help
> >>  + Register a charger with the power supply subsystem. This 
> >> will allow
> >>  + userspace to know whether or not the device is charging 
> >> from USB.
> >>  +
> >>  +endif
> >>  diff --git a/drivers/usb/common/usb-conn-gpio.c 
> >> b/drivers/usb/common/usb-conn-gpio.c
> >>  index ed204cbb63ea..129d48db280b 100644
> >>  --- a/drivers/usb/common/usb-conn-gpio.c
> >>  +++ b/drivers/usb/common/usb-conn-gpio.c
> >>  @@ -17,6 +17,7 @@
> >>   #include 
> >>   #include 
> >>   #include 
> >>  +#include 
> >>   #include 
> >>   #include 
> >> 
> >>  @@ -38,6 +39,9 @@ struct usb_conn_info {
> >>  struct gpio_desc *vbus_gpiod;
> >>  int id_irq;
> >>  int vbus_irq;
> >>  +
> >>  +   struct power_supply_desc desc;
> >>  +   struct power_supply *charger;
> >>   };
> >> 
> >>   /**
> >>  @@ -98,6 +102,8 @@ static void usb_conn_detect_cable(struct 
> >> work_struct *work)
> >>  ret = regulator_enable(info->vbus);
> >>  if (ret)
> >>  dev_err(info->dev, "enable vbus regulator 
> >> failed\n");
> >>  +   } else if (IS_ENABLED(CONFIG_USB_CONN_GPIO_CHARGER)) {
> >>  +   power_supply_changed(info->charger);
> >>  }
> >> 
> >>  info->last_role = role;
> >>  @@ -121,10 +127,35 @@ static irqreturn_t usb_conn_isr(int irq, void 
> >> *dev_id)
> >>  return IRQ_HANDLED;
> >>   }
> >> 
> >>  +static enum power_supply_property usb_charger_properties[] = {
> >>  +   POWER_SUPPLY_PROP_ONLINE,
> >>  +};
> >>  +
> >>  +static int usb_charger_get_property(struct power_supply *psy,
> >>  +   enum power_supply_property psp,
> >>  +   union power_supply_propval *val)
> >>  +{
> >>  +   struct usb_conn_info *info = power_supply_get_drvdata(psy);
> >>  +
> >>  +   switch (psp) {
> >>  +   case POWER_SUPPLY_PROP_ONLINE:
> >>  +   val->intval = info->last_role == USB_ROLE_DEVICE;
What will happen if you not change info->last_role here?
I prefer it's only changed by usb_conn_isr(), if it's changed by other
drivers, for example, through power_supply_get_property(), may skip role
switch.

> >>  +   break;
> >>  +   default:
> >>  +   return -EINVAL;
> >>  +   }
> >>  +
> >>  +   return 0;
> >>  +}
> >>  +
> >>   static int usb_conn_probe(struct platform_device *pdev)
> >>   {
> >>  struct device *dev = &pdev->dev;
> >>  +   struct power_supply_desc *desc;
> >>  struct usb_conn_info *info;
> >>  +   struct power_supply_config cfg = {
> >>  +   .of_node = dev->of_node,
> >>  +   };
> >>  int ret = 0;
> >> 
> >>  info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
> >>  @@ -203,6 +234,22 @@ static int usb_conn_probe(struct 
> >> platform_device *pdev)
> >>  }
> >>  }
> >> 
> >>  +   if (IS_ENABLED(CONFIG_USB_CONN_GPIO_CHARGER)) {
> >>  +   desc = &info->desc;
> >>  +   desc->name = "usb-charger";
> >>  +   desc->properties = usb_charger_properties;
> >>  +   desc->num_proper

drivers/net/ppp/pppox.c:84:21: sparse: sparse: incorrect type in initializer (different address spaces)

2020-07-26 Thread kernel test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   92ed301919932f13b9172e525674157e983d
commit: 670d0a4b10704667765f7d18f7592993d02783aa sparse: use identifiers to 
define address spaces
date:   6 weeks ago
config: openrisc-randconfig-s032-20200727 (attached as .config)
compiler: or1k-linux-gcc (GCC) 9.3.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.2-94-geb6779f6-dirty
git checkout 670d0a4b10704667765f7d18f7592993d02783aa
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 
CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=openrisc 

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


sparse warnings: (new ones prefixed by >>)

>> drivers/net/ppp/pppox.c:84:21: sparse: sparse: incorrect type in initializer 
>> (different address spaces) @@ expected int *__pu_addr @@ got int 
>> [noderef] __user * @@
   drivers/net/ppp/pppox.c:84:21: sparse: expected int *__pu_addr
>> drivers/net/ppp/pppox.c:84:21: sparse: got int [noderef] __user *
--
>> drivers/net/ppp/pppoe.c:751:21: sparse: sparse: incorrect type in 
>> initializer (different address spaces) @@ expected int *__pu_addr @@ 
>> got int [noderef] __user * @@
   drivers/net/ppp/pppoe.c:751:21: sparse: expected int *__pu_addr
>> drivers/net/ppp/pppoe.c:751:21: sparse: got int [noderef] __user *
>> drivers/net/ppp/pppoe.c:765:21: sparse: sparse: incorrect type in 
>> initializer (different address spaces) @@ expected int const *__gu_addr 
>> @@ got int [noderef] __user * @@
   drivers/net/ppp/pppoe.c:765:21: sparse: expected int const *__gu_addr
   drivers/net/ppp/pppoe.c:765:21: sparse: got int [noderef] __user *
   drivers/net/ppp/pppoe.c:778:21: sparse: sparse: incorrect type in 
initializer (different address spaces) @@ expected int const *__gu_addr @@  
   got int [noderef] __user * @@
   drivers/net/ppp/pppoe.c:778:21: sparse: expected int const *__gu_addr
   drivers/net/ppp/pppoe.c:778:21: sparse: got int [noderef] __user *
--
>> drivers/staging/rtl8712/rtl871x_ioctl_linux.c:1828:9: sparse: sparse: 
>> incorrect type in initializer (different address spaces) @@ expected 
>> unsigned int const *__gu_addr @@ got unsigned int [noderef] [usertype] 
>> __user * @@
   drivers/staging/rtl8712/rtl871x_ioctl_linux.c:1828:9: sparse: expected 
unsigned int const *__gu_addr
>> drivers/staging/rtl8712/rtl871x_ioctl_linux.c:1828:9: sparse: got 
>> unsigned int [noderef] [usertype] __user *
>> drivers/staging/rtl8712/rtl871x_ioctl_linux.c:1830:9: sparse: sparse: 
>> incorrect type in initializer (different address spaces) @@ expected 
>> unsigned int *__pu_addr @@ got unsigned int [noderef] [usertype] __user 
>> * @@
   drivers/staging/rtl8712/rtl871x_ioctl_linux.c:1830:9: sparse: expected 
unsigned int *__pu_addr
   drivers/staging/rtl8712/rtl871x_ioctl_linux.c:1830:9: sparse: got 
unsigned int [noderef] [usertype] __user *
   drivers/staging/rtl8712/rtl871x_ioctl_linux.c:1833:9: sparse: sparse: 
incorrect type in initializer (different address spaces) @@ expected 
unsigned int const *__gu_addr @@ got unsigned int [noderef] [usertype] 
__user * @@
   drivers/staging/rtl8712/rtl871x_ioctl_linux.c:1833:9: sparse: expected 
unsigned int const *__gu_addr
   drivers/staging/rtl8712/rtl871x_ioctl_linux.c:1833:9: sparse: got 
unsigned int [noderef] [usertype] __user *
   drivers/staging/rtl8712/rtl871x_ioctl_linux.c:1845:9: sparse: sparse: 
incorrect type in initializer (different address spaces) @@ expected 
unsigned int const *__gu_addr @@ got unsigned int [noderef] [usertype] 
__user * @@
   drivers/staging/rtl8712/rtl871x_ioctl_linux.c:1845:9: sparse: expected 
unsigned int const *__gu_addr
   drivers/staging/rtl8712/rtl871x_ioctl_linux.c:1845:9: sparse: got 
unsigned int [noderef] [usertype] __user *
   drivers/staging/rtl8712/rtl871x_ioctl_linux.c: note: in included file 
(through include/linux/sched/task.h, include/linux/sched/signal.h, 
drivers/staging/rtl8712/osdep_service.h):
   include/linux/uaccess.h:131:38: sparse: sparse: incorrect type in argument 1 
(different address spaces) @@ expected void *to @@ got void [noderef] 
__user *to @@
   include/linux/uaccess.h:131:38: sparse: expected void *to
   include/linux/uaccess.h:131:38: sparse: got void [noderef] __user *to
   include/linux/uaccess.h:131:42: sparse: sparse: incorrect type in argument 2 
(different address spaces) @@ expected void const [noderef] __user *from @@ 
got void const *from @@
   include/linux/uaccess.h:131:42: sparse: expected void const [noderef] 
__user *from
   include/linux/uaccess.h:131:42: spars

Re: [PATCH v17 00/21] per memcg lru lock

2020-07-26 Thread Alex Shi







A standard for new page isolation steps like the following:
1, get_page(); #pin the page avoid be free
2, TestClearPageLRU(); #serialize other isolation, also memcg change
3, spin_lock on lru_lock; #serialize lru list access
The step 2 could be optimzed/replaced in scenarios which page is unlikely
be accessed by others.



在 2020/7/25 下午8:59, Alex Shi 写道:
> The new version which bases on v5.8-rc6. It includes Hugh Dickins fix in 
> mm/swap.c and mm/mlock.c fix which Alexander Duyck pointed out, then
> removes 'mm/mlock: reorder isolation sequence during munlock' 
> 
> Hi Johanness & Hugh & Alexander & Willy,
> 
> Could you like to give a reviewed by since you address much of issue and
> give lots of suggestions! Many thanks!
> 
> Current lru_lock is one for each of node, pgdat->lru_lock, that guard for
> lru lists, but now we had moved the lru lists into memcg for long time. Still
> using per node lru_lock is clearly unscalable, pages on each of memcgs have
> to compete each others for a whole lru_lock. This patchset try to use per
> lruvec/memcg lru_lock to repleace per node lru lock to guard lru lists, make
> it scalable for memcgs and get performance gain.
> 
> Currently lru_lock still guards both lru list and page's lru bit, that's ok.
> but if we want to use specific lruvec lock on the page, we need to pin down
> the page's lruvec/memcg during locking. Just taking lruvec lock first may be
> undermined by the page's memcg charge/migration. To fix this problem, we could
> take out the page's lru bit clear and use it as pin down action to block the
> memcg changes. That's the reason for new atomic func TestClearPageLRU.
> So now isolating a page need both actions: TestClearPageLRU and hold the
> lru_lock.
> 
> The typical usage of this is isolate_migratepages_block() in compaction.c
> we have to take lru bit before lru lock, that serialized the page isolation
> in memcg page charge/migration which will change page's lruvec and new 
> lru_lock in it.
> 
> The above solution suggested by Johannes Weiner, and based on his new memcg 
> charge path, then have this patchset. (Hugh Dickins tested and contributed 
> much
> code from compaction fix to general code polish, thanks a lot!).
> 
> The patchset includes 3 parts:
> 1, some code cleanup and minimum optimization as a preparation.
> 2, use TestCleanPageLRU as page isolation's precondition
> 3, replace per node lru_lock with per memcg per node lru_lock
> 
> Following Daniel Jordan's suggestion, I have run 208 'dd' with on 104
> containers on a 2s * 26cores * HT box with a modefied case:
> https://git.kernel.org/pub/scm/linux/kernel/git/wfg/vm-scalability.git/tree/case-lru-file-readtwice
> With this patchset, the readtwice performance increased about 80%
> in concurrent containers.
> 
> Thanks Hugh Dickins and Konstantin Khlebnikov, they both brought this
> idea 8 years ago, and others who give comments as well: Daniel Jordan, 
> Mel Gorman, Shakeel Butt, Matthew Wilcox etc.
> 
> Thanks for Testing support from Intel 0day and Rong Chen, Fengguang Wu,
> and Yun Wang. Hugh Dickins also shared his kbuild-swap case. Thanks!
> 
> 
> Alex Shi (19):
>   mm/vmscan: remove unnecessary lruvec adding
>   mm/page_idle: no unlikely double check for idle page counting
>   mm/compaction: correct the comments of compact_defer_shift
>   mm/compaction: rename compact_deferred as compact_should_defer
>   mm/thp: move lru_add_page_tail func to huge_memory.c
>   mm/thp: clean up lru_add_page_tail
>   mm/thp: remove code path which never got into
>   mm/thp: narrow lru locking
>   mm/memcg: add debug checking in lock_page_memcg
>   mm/swap: fold vm event PGROTATED into pagevec_move_tail_fn
>   mm/lru: move lru_lock holding in func lru_note_cost_page
>   mm/lru: move lock into lru_note_cost
>   mm/lru: introduce TestClearPageLRU
>   mm/compaction: do page isolation first in compaction
>   mm/thp: add tail pages into lru anyway in split_huge_page()
>   mm/swap: serialize memcg changes in pagevec_lru_move_fn
>   mm/lru: replace pgdat lru_lock with lruvec lock
>   mm/lru: introduce the relock_page_lruvec function
>   mm/pgdat: remove pgdat lru_lock
> 
> Hugh Dickins (2):
>   mm/vmscan: use relock for move_pages_to_lru
>   mm/lru: revise the comments of lru_lock
> 
>  Documentation/admin-guide/cgroup-v1/memcg_test.rst |  15 +-
>  Documentation/admin-guide/cgroup-v1/memory.rst |  21 +--
>  Documentation/trace/events-kmem.rst|   2 +-
>  Documentation/vm/unevictable-lru.rst   |  22 +--
>  include/linux/compaction.h |   4 +-
>  include/linux/memcontrol.h |  98 ++
>  include/linux/mm_types.h   |   2 +-
>  include/linux/mmzone.h |   6 +-
>  include/linux/page-flags.h |   1 +
>  include/linux/swap.h   |   4 +-
>  include/trace/events/compaction.h  |   2 +-
>  mm/compaction.c  

linux-next: manual merge of the tip tree with the drm-msm tree

2020-07-26 Thread Stephen Rothwell
Hi all,

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

  drivers/gpu/drm/msm/msm_drv.c

between commit:

  00be2abf1413 ("drm/msm: use kthread_create_worker instead of kthread_run")

from the drm-msm tree and commits:

  64419ca67622 ("sched,msm: Convert to sched_set_fifo*()")
  8b700983de82 ("sched: Remove sched_set_*() return value")

from the tip tree.

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

-- 
Cheers,
Stephen Rothwell

diff --cc drivers/gpu/drm/msm/msm_drv.c
index 36d98d4116ca,556cca38487c..
--- a/drivers/gpu/drm/msm/msm_drv.c
+++ b/drivers/gpu/drm/msm/msm_drv.c
@@@ -524,11 -508,8 +517,7 @@@ static int msm_drm_init(struct device *
goto err_msm_uninit;
}
  
-   ret = sched_setscheduler(priv->event_thread[i].worker->task,
-SCHED_FIFO, ¶m);
-   if (ret)
-   dev_warn(dev, "event_thread set priority failed:%d\n",
-ret);
 -  sched_set_fifo(priv->event_thread[i].thread);
++  sched_set_fifo(priv->event_thread[i].worker->task);
}
  
ret = drm_vblank_init(ddev, priv->num_crtcs);


pgpxFCLustfMg.pgp
Description: OpenPGP digital signature


[PATCH] drm/amd/display: Clear dm_state for fast updates

2020-07-26 Thread Mazin Rezk
This patch fixes a race condition that causes a use-after-free during
amdgpu_dm_atomic_commit_tail. This can occur when 2 non-blocking commits
are requested and the second one finishes before the first. Essentially,
this bug occurs when the following sequence of events happens:

1. Non-blocking commit #1 is requested w/ a new dm_state #1 and is
deferred to the workqueue.

2. Non-blocking commit #2 is requested w/ a new dm_state #2 and is
deferred to the workqueue.

3. Commit #2 starts before commit #1, dm_state #1 is used in the
commit_tail and commit #2 completes, freeing dm_state #1.

4. Commit #1 starts after commit #2 completes, uses the freed dm_state
1 and dereferences a freelist pointer while setting the context.

Since this bug has only been spotted with fast commits, this patch fixes
the bug by clearing the dm_state instead of using the old dc_state for
fast updates. In addition, since dm_state is only used for its dc_state
and amdgpu_dm_atomic_commit_tail will retain the dc_state if none is found,
removing the dm_state should not have any consequences in fast updates.

This use-after-free bug has existed for a while now, but only caused a
noticeable issue starting from 5.7-rc1 due to 3202fa62f ("slub: relocate
freelist pointer to middle of object") moving the freelist pointer from
dm_state->base (which was unused) to dm_state->context (which is
dereferenced).

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=207383
Fixes: bd200d190f45 ("drm/amd/display: Don't replace the dc_state for fast 
updates")
Reported-by: Duncan <1i5t5.dun...@cox.net>
Signed-off-by: Mazin Rezk 
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 36 ++-
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 86ffa0c2880f..710edc70e37e 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -8717,20 +8717,38 @@ static int amdgpu_dm_atomic_check(struct drm_device 
*dev,
 * the same resource. If we have a new DC context as part of
 * the DM atomic state from validation we need to free it and
 * retain the existing one instead.
+*
+* Furthermore, since the DM atomic state only contains the DC
+* context and can safely be annulled, we can free the state
+* and clear the associated private object now to free
+* some memory and avoid a possible use-after-free later.
 */
-   struct dm_atomic_state *new_dm_state, *old_dm_state;

-   new_dm_state = dm_atomic_get_new_state(state);
-   old_dm_state = dm_atomic_get_old_state(state);
+   for (i = 0; i < state->num_private_objs; i++) {
+   struct drm_private_obj *obj = 
state->private_objs[i].ptr;

-   if (new_dm_state && old_dm_state) {
-   if (new_dm_state->context)
-   dc_release_state(new_dm_state->context);
+   if (obj->funcs == adev->dm.atomic_obj.funcs) {
+   int j = state->num_private_objs-1;

-   new_dm_state->context = old_dm_state->context;
+   dm_atomic_destroy_state(obj,
+   state->private_objs[i].state);
+
+   /* If i is not at the end of the array then the
+* last element needs to be moved to where i was
+* before the array can safely be truncated.
+*/
+   if (i != j)
+   state->private_objs[i] =
+   state->private_objs[j];

-   if (old_dm_state->context)
-   dc_retain_state(old_dm_state->context);
+   state->private_objs[j].ptr = NULL;
+   state->private_objs[j].state = NULL;
+   state->private_objs[j].old_state = NULL;
+   state->private_objs[j].new_state = NULL;
+
+   state->num_private_objs = j;
+   break;
+   }
}
}

--
2.27.0



[PATCH v4 10/10] powerpc/smp: Implement cpu_to_coregroup_id

2020-07-26 Thread Srikar Dronamraju
Lookup the coregroup id from the associativity array.

If unable to detect the coregroup id, fallback on the core id.
This way, ensure sched_domain degenerates and an extra sched domain is
not created.

Ideally this function should have been implemented in
arch/powerpc/kernel/smp.c. However if its implemented in mm/numa.c, we
don't need to find the primary domain again.

If the device-tree mentions more than one coregroup, then kernel
implements only the last or the smallest coregroup, which currently
corresponds to the penultimate domain in the device-tree.

Cc: linuxppc-dev 
Cc: LKML 
Cc: Michael Ellerman 
Cc: Nicholas Piggin 
Cc: Anton Blanchard 
Cc: Oliver O'Halloran 
Cc: Nathan Lynch 
Cc: Michael Neuling 
Cc: Gautham R Shenoy 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Valentin Schneider 
Cc: Jordan Niethe 
Reviewed-by : Gautham R. Shenoy 
Signed-off-by: Srikar Dronamraju 
---
Changelog v1 -> v2:
Move coregroup_enabled before getting associativity (Gautham)

 arch/powerpc/mm/numa.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 0d57779e7942..8b3b3ec7fcc4 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -1218,6 +1218,26 @@ int find_and_online_cpu_nid(int cpu)
 
 int cpu_to_coregroup_id(int cpu)
 {
+   __be32 associativity[VPHN_ASSOC_BUFSIZE] = {0};
+   int index;
+
+   if (cpu < 0 || cpu > nr_cpu_ids)
+   return -1;
+
+   if (!coregroup_enabled)
+   goto out;
+
+   if (!firmware_has_feature(FW_FEATURE_VPHN))
+   goto out;
+
+   if (vphn_get_associativity(cpu, associativity))
+   goto out;
+
+   index = of_read_number(associativity, 1);
+   if (index > min_common_depth + 1)
+   return of_read_number(&associativity[index - 1], 1);
+
+out:
return cpu_to_core_id(cpu);
 }
 
-- 
2.17.1



linux-next: manual merge of the tip tree with the vfs tree

2020-07-26 Thread Stephen Rothwell
Hi all,

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

  arch/x86/include/asm/fpu/xstate.h

between commit:

  c196049cc732 ("x86: switch to ->regset_get()")

from the vfs tree and commit:

  ce711ea3cab9 ("perf/x86/intel/lbr: Support XSAVES/XRSTORS for LBR context 
switch")

from the tip 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 arch/x86/include/asm/fpu/xstate.h
index f691ea1bc086,1559554af931..
--- a/arch/x86/include/asm/fpu/xstate.h
+++ b/arch/x86/include/asm/fpu/xstate.h
@@@ -71,8 -103,9 +103,9 @@@ extern void __init update_regset_xstate
  void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr);
  const void *get_xsave_field_ptr(int xfeature_nr);
  int using_compacted_format(void);
+ int xfeature_size(int xfeature_nr);
 -int copy_xstate_to_kernel(void *kbuf, struct xregs_state *xsave, unsigned int 
offset, unsigned int size);
 -int copy_xstate_to_user(void __user *ubuf, struct xregs_state *xsave, 
unsigned int offset, unsigned int size);
 +struct membuf;
 +void copy_xstate_to_kernel(struct membuf to, struct xregs_state *xsave);
  int copy_kernel_to_xstate(struct xregs_state *xsave, const void *kbuf);
  int copy_user_to_xstate(struct xregs_state *xsave, const void __user *ubuf);
  void copy_supervisor_to_kernel(struct xregs_state *xsave);


pgpd4jWSQlBvh.pgp
Description: OpenPGP digital signature


INVESTMENT

2020-07-26 Thread ROBERT DANKWORTH



Good day,

You were recommended by a mutual associate. I write you regarding an investment 
of bearer bonds I made on behalf of a client. 

   The investment was made in 2009 and has been under my management. The 
said investor is deceased. The window is now available to assign these bonds to 
any name or company of my choice. I have all the necessary information to 
achieve this within 10 banking days.
  
   The total value of the bond is 100million pounds sterling, in a million 
pound denominations.
  
If you can handle this, do contact me at your earliest convenience via 
my email robertdankwo...@aol.com
So we can discuss the final details Thank you.
 
Mr ROBERT DANKWORTH


[PATCH v4 07/10] Powerpc/numa: Detect support for coregroup

2020-07-26 Thread Srikar Dronamraju
Add support for grouping cores based on the device-tree classification.
- The last domain in the associativity domains always refers to the
core.
- If primary reference domain happens to be the penultimate domain in
the associativity domains device-tree property, then there are no
coregroups. However if its not a penultimate domain, then there are
coregroups. There can be more than one coregroup. For now we would be
interested in the last or the smallest coregroups.

Cc: linuxppc-dev 
Cc: LKML 
Cc: Michael Ellerman 
Cc: Nicholas Piggin 
Cc: Anton Blanchard 
Cc: Oliver O'Halloran 
Cc: Nathan Lynch 
Cc: Michael Neuling 
Cc: Gautham R Shenoy 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Valentin Schneider 
Cc: Jordan Niethe 
Reviewed-by: Gautham R. Shenoy 
Signed-off-by: Srikar Dronamraju 
---
Changelog v1 -> v2:
Explained Coregroup in commit msg (Michael Ellerman)

 arch/powerpc/include/asm/smp.h |  1 +
 arch/powerpc/kernel/smp.c  |  1 +
 arch/powerpc/mm/numa.c | 34 +-
 3 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
index 49a25e2400f2..5bdc17a7049f 100644
--- a/arch/powerpc/include/asm/smp.h
+++ b/arch/powerpc/include/asm/smp.h
@@ -28,6 +28,7 @@
 extern int boot_cpuid;
 extern int spinning_secondaries;
 extern u32 *cpu_to_phys_id;
+extern bool coregroup_enabled;
 
 extern void cpu_die(void);
 extern int cpu_to_chip_id(int cpu);
diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index 3c5ccf6d2b1c..698000c7f76f 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -74,6 +74,7 @@ static DEFINE_PER_CPU(int, cpu_state) = { 0 };
 
 struct task_struct *secondary_current;
 bool has_big_cores;
+bool coregroup_enabled;
 
 DEFINE_PER_CPU(cpumask_var_t, cpu_sibling_map);
 DEFINE_PER_CPU(cpumask_var_t, cpu_smallcore_map);
diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 2298899a0f0a..51cb672f113b 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -886,7 +886,9 @@ static void __init setup_node_data(int nid, u64 start_pfn, 
u64 end_pfn)
 static void __init find_possible_nodes(void)
 {
struct device_node *rtas;
-   u32 numnodes, i;
+   const __be32 *domains;
+   int prop_length, max_nodes;
+   u32 i;
 
if (!numa_enabled)
return;
@@ -895,25 +897,31 @@ static void __init find_possible_nodes(void)
if (!rtas)
return;
 
-   if (of_property_read_u32_index(rtas, 
"ibm,current-associativity-domains",
-   min_common_depth, &numnodes)) {
-   /*
-* ibm,current-associativity-domains is a fairly recent
-* property. If it doesn't exist, then fallback on
-* ibm,max-associativity-domains. Current denotes what the
-* platform can support compared to max which denotes what the
-* Hypervisor can support.
-*/
-   if (of_property_read_u32_index(rtas, 
"ibm,max-associativity-domains",
-   min_common_depth, &numnodes))
+   /*
+* ibm,current-associativity-domains is a fairly recent property. If
+* it doesn't exist, then fallback on ibm,max-associativity-domains.
+* Current denotes what the platform can support compared to max
+* which denotes what the Hypervisor can support.
+*/
+   domains = of_get_property(rtas, "ibm,current-associativity-domains",
+   &prop_length);
+   if (!domains) {
+   domains = of_get_property(rtas, "ibm,max-associativity-domains",
+   &prop_length);
+   if (!domains)
goto out;
}
 
-   for (i = 0; i < numnodes; i++) {
+   max_nodes = of_read_number(&domains[min_common_depth], 1);
+   for (i = 0; i < max_nodes; i++) {
if (!node_possible(i))
node_set(i, node_possible_map);
}
 
+   prop_length /= sizeof(int);
+   if (prop_length > min_common_depth + 2)
+   coregroup_enabled = 1;
+
 out:
of_node_put(rtas);
 }
-- 
2.17.1



[PATCH v4 08/10] powerpc/smp: Allocate cpumask only after searching thread group

2020-07-26 Thread Srikar Dronamraju
If allocated earlier and the search fails, then cpumask need to be
freed. However cpu_l1_cache_map can be allocated after we search thread
group.

Cc: linuxppc-dev 
Cc: LKML 
Cc: Michael Ellerman 
Cc: Nicholas Piggin 
Cc: Anton Blanchard 
Cc: Oliver O'Halloran 
Cc: Nathan Lynch 
Cc: Michael Neuling 
Cc: Gautham R Shenoy 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Valentin Schneider 
Cc: Jordan Niethe 
Reviewed-by: Gautham R. Shenoy 
Signed-off-by: Srikar Dronamraju 
---
 arch/powerpc/kernel/smp.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index 698000c7f76f..dab96a1203ec 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -797,10 +797,6 @@ static int init_cpu_l1_cache_map(int cpu)
if (err)
goto out;
 
-   zalloc_cpumask_var_node(&per_cpu(cpu_l1_cache_map, cpu),
-   GFP_KERNEL,
-   cpu_to_node(cpu));
-
cpu_group_start = get_cpu_thread_group_start(cpu, &tg);
 
if (unlikely(cpu_group_start == -1)) {
@@ -809,6 +805,9 @@ static int init_cpu_l1_cache_map(int cpu)
goto out;
}
 
+   zalloc_cpumask_var_node(&per_cpu(cpu_l1_cache_map, cpu),
+   GFP_KERNEL, cpu_to_node(cpu));
+
for (i = first_thread; i < first_thread + threads_per_core; i++) {
int i_group_start = get_cpu_thread_group_start(i, &tg);
 
-- 
2.17.1



[PATCH v4 09/10] Powerpc/smp: Create coregroup domain

2020-07-26 Thread Srikar Dronamraju
Add percpu coregroup maps and masks to create coregroup domain.
If a coregroup doesn't exist, the coregroup domain will be degenerated
in favour of SMT/CACHE domain.

Cc: linuxppc-dev 
Cc: LKML 
Cc: Michael Ellerman 
Cc: Nicholas Piggin 
Cc: Anton Blanchard 
Cc: Oliver O'Halloran 
Cc: Nathan Lynch 
Cc: Michael Neuling 
Cc: Gautham R Shenoy 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Valentin Schneider 
Cc: Jordan Niethe 
Signed-off-by: Srikar Dronamraju 
---
Changelog v3 ->v4:
if coregroup_support doesn't exist, update MC mask to the next
smaller domain mask.

Changelog v2 -> v3:
Add optimization for mask updation under coregroup_support

Changelog v1 -> v2:
Moved coregroup topology fixup to fixup_topology (Gautham)

 arch/powerpc/include/asm/topology.h | 10 +++
 arch/powerpc/kernel/smp.c   | 44 +
 arch/powerpc/mm/numa.c  |  5 
 3 files changed, 59 insertions(+)

diff --git a/arch/powerpc/include/asm/topology.h 
b/arch/powerpc/include/asm/topology.h
index f0b6300e7dd3..6609174918ab 100644
--- a/arch/powerpc/include/asm/topology.h
+++ b/arch/powerpc/include/asm/topology.h
@@ -88,12 +88,22 @@ static inline int cpu_distance(__be32 *cpu1_assoc, __be32 
*cpu2_assoc)
 
 #if defined(CONFIG_NUMA) && defined(CONFIG_PPC_SPLPAR)
 extern int find_and_online_cpu_nid(int cpu);
+extern int cpu_to_coregroup_id(int cpu);
 #else
 static inline int find_and_online_cpu_nid(int cpu)
 {
return 0;
 }
 
+static inline int cpu_to_coregroup_id(int cpu)
+{
+#ifdef CONFIG_SMP
+   return cpu_to_core_id(cpu);
+#else
+   return 0;
+#endif
+}
+
 #endif /* CONFIG_NUMA && CONFIG_PPC_SPLPAR */
 
 #include 
diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index dab96a1203ec..95f0bf72e283 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -80,6 +80,7 @@ DEFINE_PER_CPU(cpumask_var_t, cpu_sibling_map);
 DEFINE_PER_CPU(cpumask_var_t, cpu_smallcore_map);
 DEFINE_PER_CPU(cpumask_var_t, cpu_l2_cache_map);
 DEFINE_PER_CPU(cpumask_var_t, cpu_core_map);
+DEFINE_PER_CPU(cpumask_var_t, cpu_coregroup_map);
 
 EXPORT_PER_CPU_SYMBOL(cpu_sibling_map);
 EXPORT_PER_CPU_SYMBOL(cpu_l2_cache_map);
@@ -91,6 +92,7 @@ enum {
smt_idx,
 #endif
bigcore_idx,
+   mc_idx,
die_idx,
 };
 
@@ -869,6 +871,21 @@ static const struct cpumask *smallcore_smt_mask(int cpu)
 }
 #endif
 
+static struct cpumask *cpu_coregroup_mask(int cpu)
+{
+   return per_cpu(cpu_coregroup_map, cpu);
+}
+
+static bool has_coregroup_support(void)
+{
+   return coregroup_enabled;
+}
+
+static const struct cpumask *cpu_mc_mask(int cpu)
+{
+   return cpu_coregroup_mask(cpu);
+}
+
 static const struct cpumask *cpu_bigcore_mask(int cpu)
 {
return per_cpu(cpu_sibling_map, cpu);
@@ -879,6 +896,7 @@ static struct sched_domain_topology_level 
powerpc_topology[] = {
{ cpu_smt_mask, powerpc_smt_flags, SD_INIT_NAME(SMT) },
 #endif
{ cpu_bigcore_mask, SD_INIT_NAME(BIGCORE) },
+   { cpu_mc_mask, SD_INIT_NAME(MC) },
{ cpu_cpu_mask, SD_INIT_NAME(DIE) },
{ NULL, },
 };
@@ -925,6 +943,10 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
GFP_KERNEL, cpu_to_node(cpu));
zalloc_cpumask_var_node(&per_cpu(cpu_core_map, cpu),
GFP_KERNEL, cpu_to_node(cpu));
+   if (has_coregroup_support())
+   zalloc_cpumask_var_node(&per_cpu(cpu_coregroup_map, 
cpu),
+   GFP_KERNEL, cpu_to_node(cpu));
+
 #ifdef CONFIG_NEED_MULTIPLE_NODES
/*
 * numa_node_id() works after this.
@@ -942,6 +964,9 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
cpumask_set_cpu(boot_cpuid, cpu_l2_cache_mask(boot_cpuid));
cpumask_set_cpu(boot_cpuid, cpu_core_mask(boot_cpuid));
 
+   if (has_coregroup_support())
+   cpumask_set_cpu(boot_cpuid, cpu_coregroup_mask(boot_cpuid));
+
init_big_cores();
if (has_big_cores) {
cpumask_set_cpu(boot_cpuid,
@@ -1233,6 +1258,8 @@ static void remove_cpu_from_masks(int cpu)
set_cpus_unrelated(cpu, i, cpu_sibling_mask);
if (has_big_cores)
set_cpus_unrelated(cpu, i, cpu_smallcore_mask);
+   if (has_coregroup_support())
+   set_cpus_unrelated(cpu, i, cpu_coregroup_mask);
}
 }
 #endif
@@ -1293,6 +1320,20 @@ static void add_cpu_to_masks(int cpu)
add_cpu_to_smallcore_masks(cpu);
update_mask_by_l2(cpu, cpu_l2_cache_mask);
 
+   if (has_coregroup_support()) {
+   int coregroup_id = cpu_to_coregroup_id(cpu);
+
+   cpumask_set_cpu(cpu, cpu_coregroup_mask(cpu));
+   for_each_cpu_and(i, cpu_online_mask, cpu_cpu_mask(cpu)) {
+   int fcpu = cpu_first_thread_sibling(i);
+
+   

[PATCH v4 06/10] powerpc/smp: Generalize 2nd sched domain

2020-07-26 Thread Srikar Dronamraju
Currently "CACHE" domain happens to be the 2nd sched domain as per
powerpc_topology. This domain will collapse if cpumask of l2-cache is
same as SMT domain. However we could generalize this domain such that it
could mean either be a "CACHE" domain or a "BIGCORE" domain.

While setting up the "CACHE" domain, check if shared_cache is already
set.

Cc: linuxppc-dev 
Cc: LKML 
Cc: Michael Ellerman 
Cc: Nicholas Piggin 
Cc: Anton Blanchard 
Cc: Oliver O'Halloran 
Cc: Nathan Lynch 
Cc: Michael Neuling 
Cc: Gautham R Shenoy 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Valentin Schneider 
Cc: Jordan Niethe 
Signed-off-by: Srikar Dronamraju 
---
Changelog v1 -> v2:
Moved shared_cache topology fixup to fixup_topology (Gautham)

 arch/powerpc/kernel/smp.c | 48 +++
 1 file changed, 34 insertions(+), 14 deletions(-)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index d997c7411664..3c5ccf6d2b1c 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -85,6 +85,14 @@ EXPORT_PER_CPU_SYMBOL(cpu_l2_cache_map);
 EXPORT_PER_CPU_SYMBOL(cpu_core_map);
 EXPORT_SYMBOL_GPL(has_big_cores);
 
+enum {
+#ifdef CONFIG_SCHED_SMT
+   smt_idx,
+#endif
+   bigcore_idx,
+   die_idx,
+};
+
 #define MAX_THREAD_LIST_SIZE   8
 #define THREAD_GROUP_SHARE_L1   1
 struct thread_groups {
@@ -851,13 +859,7 @@ static int powerpc_shared_cache_flags(void)
  */
 static const struct cpumask *shared_cache_mask(int cpu)
 {
-   if (shared_caches)
-   return cpu_l2_cache_mask(cpu);
-
-   if (has_big_cores)
-   return cpu_smallcore_mask(cpu);
-
-   return per_cpu(cpu_sibling_map, cpu);
+   return per_cpu(cpu_l2_cache_map, cpu);
 }
 
 #ifdef CONFIG_SCHED_SMT
@@ -867,11 +869,16 @@ static const struct cpumask *smallcore_smt_mask(int cpu)
 }
 #endif
 
+static const struct cpumask *cpu_bigcore_mask(int cpu)
+{
+   return per_cpu(cpu_sibling_map, cpu);
+}
+
 static struct sched_domain_topology_level powerpc_topology[] = {
 #ifdef CONFIG_SCHED_SMT
{ cpu_smt_mask, powerpc_smt_flags, SD_INIT_NAME(SMT) },
 #endif
-   { shared_cache_mask, powerpc_shared_cache_flags, SD_INIT_NAME(CACHE) },
+   { cpu_bigcore_mask, SD_INIT_NAME(BIGCORE) },
{ cpu_cpu_mask, SD_INIT_NAME(DIE) },
{ NULL, },
 };
@@ -1311,7 +1318,6 @@ static void add_cpu_to_masks(int cpu)
 void start_secondary(void *unused)
 {
unsigned int cpu = smp_processor_id();
-   struct cpumask *(*sibling_mask)(int) = cpu_sibling_mask;
 
mmgrab(&init_mm);
current->active_mm = &init_mm;
@@ -1337,14 +1343,20 @@ void start_secondary(void *unused)
/* Update topology CPU masks */
add_cpu_to_masks(cpu);
 
-   if (has_big_cores)
-   sibling_mask = cpu_smallcore_mask;
/*
 * Check for any shared caches. Note that this must be done on a
 * per-core basis because one core in the pair might be disabled.
 */
-   if (!cpumask_equal(cpu_l2_cache_mask(cpu), sibling_mask(cpu)))
-   shared_caches = true;
+   if (!shared_caches) {
+   struct cpumask *(*sibling_mask)(int) = cpu_sibling_mask;
+   struct cpumask *mask = cpu_l2_cache_mask(cpu);
+
+   if (has_big_cores)
+   sibling_mask = cpu_smallcore_mask;
+
+   if (cpumask_weight(mask) > cpumask_weight(sibling_mask(cpu)))
+   shared_caches = true;
+   }
 
set_numa_node(numa_cpu_lookup_table[cpu]);
set_numa_mem(local_memory_node(numa_cpu_lookup_table[cpu]));
@@ -1375,9 +1387,17 @@ static void fixup_topology(void)
 #ifdef CONFIG_SCHED_SMT
if (has_big_cores) {
pr_info("Big cores detected but using small core scheduling\n");
-   powerpc_topology[0].mask = smallcore_smt_mask;
+   powerpc_topology[smt_idx].mask = smallcore_smt_mask;
}
 #endif
+   if (shared_caches) {
+   pr_info("Using shared cache scheduler topology\n");
+   powerpc_topology[bigcore_idx].mask = shared_cache_mask;
+   powerpc_topology[bigcore_idx].sd_flags = 
powerpc_shared_cache_flags;
+#ifdef CONFIG_SCHED_DEBUG
+   powerpc_topology[bigcore_idx].name = "CACHE";
+#endif
+   }
 }
 
 void __init smp_cpus_done(unsigned int max_cpus)
-- 
2.17.1



[PATCH v4 00/10] Coregroup support on Powerpc

2020-07-26 Thread Srikar Dronamraju
Changelog v3 ->v4:
v3: 
https://lore.kernel.org/lkml/20200723085116.4731-1-sri...@linux.vnet.ibm.com/t/#u

powerpc/smp: Create coregroup domain
if coregroup_support doesn't exist, update MC mask to the next
smaller domain mask.

Changelog v2 -> v3:
v2: 
https://lore.kernel.org/linuxppc-dev/20200721113814.32284-1-sri...@linux.vnet.ibm.com/t/#u

powerpc/smp: Cache node for reuse
Removed node caching part. Rewrote the Commit msg (Michael Ellerman)
Renamed to powerpc/smp: Fix a warning under !NEED_MULTIPLE_NODES

powerpc/smp: Enable small core scheduling sooner
Rewrote changelog (Gautham)
Renamed to powerpc/smp: Move topology fixups into  a new function

powerpc/smp: Create coregroup domain
Add optimization for mask updation under coregroup_support

Changelog v1 -> v2:
v1: 
https://lore.kernel.org/linuxppc-dev/20200714043624.5648-1-sri...@linux.vnet.ibm.com/t/#u

powerpc/smp: Merge Power9 topology with Power topology
Replaced a reference to cpu_smt_mask with per_cpu(cpu_sibling_map, cpu)
since cpu_smt_mask is only defined under CONFIG_SCHED_SMT

powerpc/smp: Enable small core scheduling sooner
Restored the previous info msg (Jordan)
Moved big core topology fixup to fixup_topology (Gautham)

powerpc/smp: Dont assume l2-cache to be superset of sibling
Set cpumask after verifying l2-cache. (Gautham)

powerpc/smp: Generalize 2nd sched domain
Moved shared_cache topology fixup to fixup_topology (Gautham)

Powerpc/numa: Detect support for coregroup
Explained Coregroup in commit msg (Michael Ellerman)

Powerpc/smp: Create coregroup domain
Moved coregroup topology fixup to fixup_topology (Gautham)

powerpc/smp: Implement cpu_to_coregroup_id
Move coregroup_enabled before getting associativity (Gautham)

powerpc/smp: Provide an ability to disable coregroup
Patch dropped (Michael Ellerman)

Cleanup of existing powerpc topologies and add coregroup support on
Powerpc. Coregroup is a group of (subset of) cores of a DIE that share
a resource.

Patch 7 of this patch series: "Powerpc/numa: Detect support for coregroup"
depends on
https://lore.kernel.org/linuxppc-dev/20200707140644.7241-1-sri...@linux.vnet.ibm.com/t/#u
However it should be easy to rebase the patch without the above patch.

This patch series is based on top of current powerpc/next tree + the
above patch.

On Power 8 Systems
--
$ tail /proc/cpuinfo
processor   : 255
cpu : POWER8 (architected), altivec supported
clock   : 3724.00MHz
revision: 2.1 (pvr 004b 0201)

timebase: 51200
platform: pSeries
model   : IBM,8408-E8E
machine : CHRP IBM,8408-E8E
MMU : Hash

Before the patchset
---
$ cat /proc/sys/kernel/sched_domain/cpu0/domain*/name
SMT
DIE
NUMA
NUMA
$ head /proc/schedstat
version 15
timestamp 4295534931
cpu0 0 0 0 0 0 0 41389823338 17682779896 14117
domain0 ,,,,,,,00ff 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
domain1 ,,,,,,, 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
domain2 ,,,,,,, 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
domain3 ,,,,,,, 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
cpu1 0 0 0 0 0 0 27087859050 152273672 10396
domain0 ,,,,,,,00ff 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
domain1 ,,,,,,, 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

After the patchset
--
$ cat /proc/sys/kernel/sched_domain/cpu0/domain*/name
SMT
DIE
NUMA
NUMA
$ head /proc/schedstat
version 15
timestamp 4295534931
cpu0 0 0 0 0 0 0 41389823338 17682779896 14117
domain0 ,,,,,,,00ff 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
domain1 ,,,,,,, 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
domain2 ,,,,,,, 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
domain3 ,,,,,,, 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
cpu1 0 0 0 0 0 0 27087859050 152273672 10396
domain0 ,,,,,,,00ff 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
domain1 ,0

[PATCH v4 05/10] powerpc/smp: Dont assume l2-cache to be superset of sibling

2020-07-26 Thread Srikar Dronamraju
Current code assumes that cpumask of cpus sharing a l2-cache mask will
always be a superset of cpu_sibling_mask.

Lets stop that assumption. cpu_l2_cache_mask is a superset of
cpu_sibling_mask if and only if shared_caches is set.

Cc: linuxppc-dev 
Cc: LKML 
Cc: Michael Ellerman 
Cc: Nicholas Piggin 
Cc: Anton Blanchard 
Cc: Oliver O'Halloran 
Cc: Nathan Lynch 
Cc: Michael Neuling 
Cc: Gautham R Shenoy 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Valentin Schneider 
Cc: Jordan Niethe 
Reviewed-by: Gautham R. Shenoy 
Signed-off-by: Srikar Dronamraju 
---
Changelog v1 -> v2:
Set cpumask after verifying l2-cache. (Gautham)

 arch/powerpc/kernel/smp.c | 28 +++-
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index da27f6909be1..d997c7411664 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -1194,6 +1194,7 @@ static bool update_mask_by_l2(int cpu, struct cpumask 
*(*mask_fn)(int))
if (!l2_cache)
return false;
 
+   cpumask_set_cpu(cpu, mask_fn(cpu));
for_each_cpu(i, cpu_online_mask) {
/*
 * when updating the marks the current CPU has not been marked
@@ -1276,29 +1277,30 @@ static void add_cpu_to_masks(int cpu)
 * add it to it's own thread sibling mask.
 */
cpumask_set_cpu(cpu, cpu_sibling_mask(cpu));
+   cpumask_set_cpu(cpu, cpu_core_mask(cpu));
 
for (i = first_thread; i < first_thread + threads_per_core; i++)
if (cpu_online(i))
set_cpus_related(i, cpu, cpu_sibling_mask);
 
add_cpu_to_smallcore_masks(cpu);
-   /*
-* Copy the thread sibling mask into the cache sibling mask
-* and mark any CPUs that share an L2 with this CPU.
-*/
-   for_each_cpu(i, cpu_sibling_mask(cpu))
-   set_cpus_related(cpu, i, cpu_l2_cache_mask);
update_mask_by_l2(cpu, cpu_l2_cache_mask);
 
-   /*
-* Copy the cache sibling mask into core sibling mask and mark
-* any CPUs on the same chip as this CPU.
-*/
-   for_each_cpu(i, cpu_l2_cache_mask(cpu))
-   set_cpus_related(cpu, i, cpu_core_mask);
+   if (pkg_id == -1) {
+   struct cpumask *(*mask)(int) = cpu_sibling_mask;
+
+   /*
+* Copy the sibling mask into core sibling mask and
+* mark any CPUs on the same chip as this CPU.
+*/
+   if (shared_caches)
+   mask = cpu_l2_cache_mask;
+
+   for_each_cpu(i, mask(cpu))
+   set_cpus_related(cpu, i, cpu_core_mask);
 
-   if (pkg_id == -1)
return;
+   }
 
for_each_cpu(i, cpu_online_mask)
if (get_physical_package_id(i) == pkg_id)
-- 
2.17.1



[PATCH v4 02/10] powerpc/smp: Merge Power9 topology with Power topology

2020-07-26 Thread Srikar Dronamraju
A new sched_domain_topology_level was added just for Power9. However the
same can be achieved by merging powerpc_topology with power9_topology
and makes the code more simpler especially when adding a new sched
domain.

Cc: linuxppc-dev 
Cc: LKML 
Cc: Michael Ellerman 
Cc: Nicholas Piggin 
Cc: Anton Blanchard 
Cc: Oliver O'Halloran 
Cc: Nathan Lynch 
Cc: Michael Neuling 
Cc: Gautham R Shenoy 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Valentin Schneider 
Cc: Jordan Niethe 
Reviewed-by: Gautham R. Shenoy 
Signed-off-by: Srikar Dronamraju 
---
Changelog v1 -> v2:
Replaced a reference to cpu_smt_mask with per_cpu(cpu_sibling_map, cpu)
since cpu_smt_mask is only defined under CONFIG_SCHED_SMT

 arch/powerpc/kernel/smp.c | 33 ++---
 1 file changed, 10 insertions(+), 23 deletions(-)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index edf94ca64eea..283a04e54f52 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -1313,7 +1313,7 @@ int setup_profiling_timer(unsigned int multiplier)
 }
 
 #ifdef CONFIG_SCHED_SMT
-/* cpumask of CPUs with asymetric SMT dependancy */
+/* cpumask of CPUs with asymmetric SMT dependency */
 static int powerpc_smt_flags(void)
 {
int flags = SD_SHARE_CPUCAPACITY | SD_SHARE_PKG_RESOURCES;
@@ -1326,14 +1326,6 @@ static int powerpc_smt_flags(void)
 }
 #endif
 
-static struct sched_domain_topology_level powerpc_topology[] = {
-#ifdef CONFIG_SCHED_SMT
-   { cpu_smt_mask, powerpc_smt_flags, SD_INIT_NAME(SMT) },
-#endif
-   { cpu_cpu_mask, SD_INIT_NAME(DIE) },
-   { NULL, },
-};
-
 /*
  * P9 has a slightly odd architecture where pairs of cores share an L2 cache.
  * This topology makes it *much* cheaper to migrate tasks between adjacent 
cores
@@ -1351,7 +1343,13 @@ static int powerpc_shared_cache_flags(void)
  */
 static const struct cpumask *shared_cache_mask(int cpu)
 {
-   return cpu_l2_cache_mask(cpu);
+   if (shared_caches)
+   return cpu_l2_cache_mask(cpu);
+
+   if (has_big_cores)
+   return cpu_smallcore_mask(cpu);
+
+   return per_cpu(cpu_sibling_map, cpu);
 }
 
 #ifdef CONFIG_SCHED_SMT
@@ -1361,7 +1359,7 @@ static const struct cpumask *smallcore_smt_mask(int cpu)
 }
 #endif
 
-static struct sched_domain_topology_level power9_topology[] = {
+static struct sched_domain_topology_level powerpc_topology[] = {
 #ifdef CONFIG_SCHED_SMT
{ cpu_smt_mask, powerpc_smt_flags, SD_INIT_NAME(SMT) },
 #endif
@@ -1386,21 +1384,10 @@ void __init smp_cpus_done(unsigned int max_cpus)
 #ifdef CONFIG_SCHED_SMT
if (has_big_cores) {
pr_info("Big cores detected but using small core scheduling\n");
-   power9_topology[0].mask = smallcore_smt_mask;
powerpc_topology[0].mask = smallcore_smt_mask;
}
 #endif
-   /*
-* If any CPU detects that it's sharing a cache with another CPU then
-* use the deeper topology that is aware of this sharing.
-*/
-   if (shared_caches) {
-   pr_info("Using shared cache scheduler topology\n");
-   set_sched_topology(power9_topology);
-   } else {
-   pr_info("Using standard scheduler topology\n");
-   set_sched_topology(powerpc_topology);
-   }
+   set_sched_topology(powerpc_topology);
 }
 
 #ifdef CONFIG_HOTPLUG_CPU
-- 
2.17.1



[PATCH v4 03/10] powerpc/smp: Move powerpc_topology above

2020-07-26 Thread Srikar Dronamraju
Just moving the powerpc_topology description above.
This will help in using functions in this file and avoid declarations.

No other functional changes

Cc: linuxppc-dev 
Cc: LKML 
Cc: Michael Ellerman 
Cc: Nicholas Piggin 
Cc: Anton Blanchard 
Cc: Oliver O'Halloran 
Cc: Nathan Lynch 
Cc: Michael Neuling 
Cc: Gautham R Shenoy 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Valentin Schneider 
Cc: Jordan Niethe 
Reviewed-by: Gautham R. Shenoy 
Signed-off-by: Srikar Dronamraju 
---
 arch/powerpc/kernel/smp.c | 116 +++---
 1 file changed, 58 insertions(+), 58 deletions(-)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index 283a04e54f52..a685915e5941 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -818,6 +818,64 @@ static int init_cpu_l1_cache_map(int cpu)
return err;
 }
 
+static bool shared_caches;
+
+#ifdef CONFIG_SCHED_SMT
+/* cpumask of CPUs with asymmetric SMT dependency */
+static int powerpc_smt_flags(void)
+{
+   int flags = SD_SHARE_CPUCAPACITY | SD_SHARE_PKG_RESOURCES;
+
+   if (cpu_has_feature(CPU_FTR_ASYM_SMT)) {
+   printk_once(KERN_INFO "Enabling Asymmetric SMT scheduling\n");
+   flags |= SD_ASYM_PACKING;
+   }
+   return flags;
+}
+#endif
+
+/*
+ * P9 has a slightly odd architecture where pairs of cores share an L2 cache.
+ * This topology makes it *much* cheaper to migrate tasks between adjacent 
cores
+ * since the migrated task remains cache hot. We want to take advantage of this
+ * at the scheduler level so an extra topology level is required.
+ */
+static int powerpc_shared_cache_flags(void)
+{
+   return SD_SHARE_PKG_RESOURCES;
+}
+
+/*
+ * We can't just pass cpu_l2_cache_mask() directly because
+ * returns a non-const pointer and the compiler barfs on that.
+ */
+static const struct cpumask *shared_cache_mask(int cpu)
+{
+   if (shared_caches)
+   return cpu_l2_cache_mask(cpu);
+
+   if (has_big_cores)
+   return cpu_smallcore_mask(cpu);
+
+   return per_cpu(cpu_sibling_map, cpu);
+}
+
+#ifdef CONFIG_SCHED_SMT
+static const struct cpumask *smallcore_smt_mask(int cpu)
+{
+   return cpu_smallcore_mask(cpu);
+}
+#endif
+
+static struct sched_domain_topology_level powerpc_topology[] = {
+#ifdef CONFIG_SCHED_SMT
+   { cpu_smt_mask, powerpc_smt_flags, SD_INIT_NAME(SMT) },
+#endif
+   { shared_cache_mask, powerpc_shared_cache_flags, SD_INIT_NAME(CACHE) },
+   { cpu_cpu_mask, SD_INIT_NAME(DIE) },
+   { NULL, },
+};
+
 static int init_big_cores(void)
 {
int cpu;
@@ -1247,8 +1305,6 @@ static void add_cpu_to_masks(int cpu)
set_cpus_related(cpu, i, cpu_core_mask);
 }
 
-static bool shared_caches;
-
 /* Activate a secondary processor. */
 void start_secondary(void *unused)
 {
@@ -1312,62 +1368,6 @@ int setup_profiling_timer(unsigned int multiplier)
return 0;
 }
 
-#ifdef CONFIG_SCHED_SMT
-/* cpumask of CPUs with asymmetric SMT dependency */
-static int powerpc_smt_flags(void)
-{
-   int flags = SD_SHARE_CPUCAPACITY | SD_SHARE_PKG_RESOURCES;
-
-   if (cpu_has_feature(CPU_FTR_ASYM_SMT)) {
-   printk_once(KERN_INFO "Enabling Asymmetric SMT scheduling\n");
-   flags |= SD_ASYM_PACKING;
-   }
-   return flags;
-}
-#endif
-
-/*
- * P9 has a slightly odd architecture where pairs of cores share an L2 cache.
- * This topology makes it *much* cheaper to migrate tasks between adjacent 
cores
- * since the migrated task remains cache hot. We want to take advantage of this
- * at the scheduler level so an extra topology level is required.
- */
-static int powerpc_shared_cache_flags(void)
-{
-   return SD_SHARE_PKG_RESOURCES;
-}
-
-/*
- * We can't just pass cpu_l2_cache_mask() directly because
- * returns a non-const pointer and the compiler barfs on that.
- */
-static const struct cpumask *shared_cache_mask(int cpu)
-{
-   if (shared_caches)
-   return cpu_l2_cache_mask(cpu);
-
-   if (has_big_cores)
-   return cpu_smallcore_mask(cpu);
-
-   return per_cpu(cpu_sibling_map, cpu);
-}
-
-#ifdef CONFIG_SCHED_SMT
-static const struct cpumask *smallcore_smt_mask(int cpu)
-{
-   return cpu_smallcore_mask(cpu);
-}
-#endif
-
-static struct sched_domain_topology_level powerpc_topology[] = {
-#ifdef CONFIG_SCHED_SMT
-   { cpu_smt_mask, powerpc_smt_flags, SD_INIT_NAME(SMT) },
-#endif
-   { shared_cache_mask, powerpc_shared_cache_flags, SD_INIT_NAME(CACHE) },
-   { cpu_cpu_mask, SD_INIT_NAME(DIE) },
-   { NULL, },
-};
-
 void __init smp_cpus_done(unsigned int max_cpus)
 {
/*
-- 
2.17.1



[PATCH v4 04/10] powerpc/smp: Move topology fixups into a new function

2020-07-26 Thread Srikar Dronamraju
Move topology fixup based on the platform attributes into its own
function which is called just before set_sched_topology.

Cc: linuxppc-dev 
Cc: LKML 
Cc: Michael Ellerman 
Cc: Nicholas Piggin 
Cc: Anton Blanchard 
Cc: Oliver O'Halloran 
Cc: Nathan Lynch 
Cc: Michael Neuling 
Cc: Gautham R Shenoy 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Valentin Schneider 
Cc: Jordan Niethe 
Reviewed-by: Gautham R. Shenoy 
Signed-off-by: Srikar Dronamraju 
---
Changelog v2 -> v3:
Rewrote changelog (Gautham)
Renamed to powerpc/smp: Move topology fixups into  a new function

 arch/powerpc/kernel/smp.c | 17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index a685915e5941..da27f6909be1 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -1368,6 +1368,16 @@ int setup_profiling_timer(unsigned int multiplier)
return 0;
 }
 
+static void fixup_topology(void)
+{
+#ifdef CONFIG_SCHED_SMT
+   if (has_big_cores) {
+   pr_info("Big cores detected but using small core scheduling\n");
+   powerpc_topology[0].mask = smallcore_smt_mask;
+   }
+#endif
+}
+
 void __init smp_cpus_done(unsigned int max_cpus)
 {
/*
@@ -1381,12 +1391,7 @@ void __init smp_cpus_done(unsigned int max_cpus)
 
dump_numa_cpu_topology();
 
-#ifdef CONFIG_SCHED_SMT
-   if (has_big_cores) {
-   pr_info("Big cores detected but using small core scheduling\n");
-   powerpc_topology[0].mask = smallcore_smt_mask;
-   }
-#endif
+   fixup_topology();
set_sched_topology(powerpc_topology);
 }
 
-- 
2.17.1



[PATCH v4 01/10] powerpc/smp: Fix a warning under !NEED_MULTIPLE_NODES

2020-07-26 Thread Srikar Dronamraju
Fix a build warning in a non CONFIG_NEED_MULTIPLE_NODES
"error: _numa_cpu_lookup_table_ undeclared"

Cc: linuxppc-dev 
Cc: LKML 
Cc: Michael Ellerman 
Cc: Nicholas Piggin 
Cc: Anton Blanchard 
Cc: Oliver O'Halloran 
Cc: Nathan Lynch 
Cc: Michael Neuling 
Cc: Gautham R Shenoy 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Valentin Schneider 
Cc: Jordan Niethe 
Reviewed-by: Gautham R. Shenoy 
Signed-off-by: Srikar Dronamraju 
---
Changelog v2 -> v3:
Removed node caching part. Rewrote the Commit msg (Michael Ellerman)
Renamed to powerpc/smp: Fix a warning under !NEED_MULTIPLE_NODES

 arch/powerpc/kernel/smp.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index 73199470c265..edf94ca64eea 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -860,6 +860,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
GFP_KERNEL, cpu_to_node(cpu));
zalloc_cpumask_var_node(&per_cpu(cpu_core_map, cpu),
GFP_KERNEL, cpu_to_node(cpu));
+#ifdef CONFIG_NEED_MULTIPLE_NODES
/*
 * numa_node_id() works after this.
 */
@@ -868,6 +869,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
set_cpu_numa_mem(cpu,
local_memory_node(numa_cpu_lookup_table[cpu]));
}
+#endif
}
 
/* Init the cpumasks so the boot CPU is related to itself */
-- 
2.17.1



[PATCH v6 2/9] hwmon: pmbus: adm1266: Add Block process call

2020-07-26 Thread alexandru.tachici
From: Alexandru Tachici 

PmBus devices support Block Write-Block Read Process
Call described in SMBus specification v 2.0 with the
exception that Block writes and reads are permitted to
have up 255 data bytes instead of max 32 bytes (SMBus).

This patch adds Block WR process call support for ADM1266.

Signed-off-by: Alexandru Tachici 
---
 drivers/hwmon/pmbus/Kconfig   |  1 +
 drivers/hwmon/pmbus/adm1266.c | 73 +++
 2 files changed, 74 insertions(+)

diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
index da34083e1ffd..c04068b665e6 100644
--- a/drivers/hwmon/pmbus/Kconfig
+++ b/drivers/hwmon/pmbus/Kconfig
@@ -28,6 +28,7 @@ config SENSORS_PMBUS
 
 config SENSORS_ADM1266
tristate "Analog Devices ADM1266 Sequencer"
+   select CRC8
help
  If you say yes here you get hardware monitoring support for Analog
  Devices ADM1266 Cascadable Super Sequencer.
diff --git a/drivers/hwmon/pmbus/adm1266.c b/drivers/hwmon/pmbus/adm1266.c
index 79e8d90886b8..63975eba34ad 100644
--- a/drivers/hwmon/pmbus/adm1266.c
+++ b/drivers/hwmon/pmbus/adm1266.c
@@ -6,6 +6,7 @@
  * Copyright 2020 Analog Devices Inc.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -13,11 +14,80 @@
 #include "pmbus.h"
 #include 
 
+#define ADM1266_PMBUS_BLOCK_MAX255
+
 struct adm1266_data {
struct pmbus_driver_info info;
struct i2c_client *client;
+   struct mutex buf_mutex;
+   u8 write_buf[ADM1266_PMBUS_BLOCK_MAX + 1] cacheline_aligned;
+   u8 read_buf[ADM1266_PMBUS_BLOCK_MAX + 1] cacheline_aligned;
 };
 
+DECLARE_CRC8_TABLE(pmbus_crc_table);
+
+/*
+ * Different from Block Read as it sends data and waits for the slave to
+ * return a value dependent on that data. The protocol is simply a Write Block
+ * followed by a Read Block without the Read-Block command field and the
+ * Write-Block STOP bit.
+ */
+static int adm1266_pmbus_block_xfer(struct adm1266_data *data, u8 cmd, u8 
w_len, u8 *data_w,
+   u8 *data_r)
+{
+   struct i2c_client *client = data->client;
+   struct i2c_msg msgs[2] = {
+   {
+   .addr = client->addr,
+   .flags = I2C_M_DMA_SAFE,
+   .buf = data->write_buf,
+   .len = w_len + 2,
+   },
+   {
+   .addr = client->addr,
+   .flags = I2C_M_RD | I2C_M_DMA_SAFE,
+   .buf = data->read_buf,
+   .len = ADM1266_PMBUS_BLOCK_MAX + 2,
+   }
+   };
+   u8 addr;
+   u8 crc;
+   int ret;
+
+   mutex_lock(&data->buf_mutex);
+
+   msgs[0].buf[0] = cmd;
+   msgs[0].buf[1] = w_len;
+   memcpy(&msgs[0].buf[2], data_w, w_len);
+
+   ret = i2c_transfer(client->adapter, msgs, 2);
+   if (ret != 2) {
+   if (ret >= 0)
+   ret = -EPROTO;
+   return ret;
+   }
+
+   if (client->flags & I2C_CLIENT_PEC) {
+   addr = i2c_8bit_addr_from_msg(&msgs[0]);
+   crc = crc8(pmbus_crc_table, &addr, 1, 0);
+   crc = crc8(pmbus_crc_table, msgs[0].buf,  msgs[0].len, crc);
+
+   addr = i2c_8bit_addr_from_msg(&msgs[1]);
+   crc = crc8(pmbus_crc_table, &addr, 1, crc);
+   crc = crc8(pmbus_crc_table, msgs[1].buf,  msgs[1].buf[0] + 1, 
crc);
+
+   if (crc != msgs[1].buf[msgs[1].buf[0] + 1])
+   return -EBADMSG;
+   }
+
+   memcpy(data_r, &msgs[1].buf[1], msgs[1].buf[0]);
+
+   ret = msgs[1].buf[0];
+   mutex_unlock(&data->buf_mutex);
+
+   return ret;
+}
+
 static int adm1266_probe(struct i2c_client *client, const struct i2c_device_id 
*id)
 {
struct adm1266_data *data;
@@ -33,6 +103,9 @@ static int adm1266_probe(struct i2c_client *client, const 
struct i2c_device_id *
for (i = 0; i < data->info.pages; i++)
data->info.func[i] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT;
 
+   crc8_populate_msb(pmbus_crc_table, 0x7);
+   mutex_init(&data->buf_mutex);
+
return pmbus_do_probe(client, id, &data->info);
 }
 
-- 
2.20.1



[PATCH v6 8/9] hwmon: pmbus: adm1266: program configuration

2020-07-26 Thread alexandru.tachici
From: Alexandru Tachici 

Writing the configuration Intel hex file to the nvmem,
of an adm1266, with offset 0x3, will now
trigger the configuration programming.

During this process the adm1266 sequencer will be
stopped and at the end will be issued a seq reset
(see AN-1453 Programming the configuration).

Signed-off-by: Alexandru Tachici 
---
 drivers/hwmon/pmbus/adm1266.c | 179 +-
 1 file changed, 178 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/pmbus/adm1266.c b/drivers/hwmon/pmbus/adm1266.c
index 376fc56abe04..2b07e38041da 100644
--- a/drivers/hwmon/pmbus/adm1266.c
+++ b/drivers/hwmon/pmbus/adm1266.c
@@ -40,7 +40,10 @@
 #define ADM1266_BLACKBOX_INFO  0xE6
 #define ADM1266_PDIO_STATUS0xE9
 #define ADM1266_GPIO_STATUS0xEA
+#define ADM1266_STATUS_MFR_2   0xED
+#define ADM1266_REFRESH_FLASH  0xF5
 #define ADM1266_MEMORY_CONFIG  0xF8
+#define ADM1266_MEMORY_CRC 0xF9
 #define ADM1266_SWITCH_MEMORY  0xFA
 #define ADM1266_UPDATE_FW  0xFC
 #define ADM1266_FW_PASSWORD0xFD
@@ -66,6 +69,11 @@
 
 /* ADM1266 STATUS_MFR defines */
 #define ADM1266_STATUS_PART_LOCKED(x)  FIELD_GET(BIT(2), x)
+#define ADM1266_RUNNING_REFRESH(x) FIELD_GET(BIT(3), x)
+#define ADM1266_ALL_CRC_FAULT(x)   FIELD_GET(BIT(5), x)
+
+/* ADM1266 STATUS_MFR_2 defines */
+#define ADM1266_MAIN_CONFIG_FAULT(x)   FIELD_GET(GENMASK(9, 8), x)
 
 /* ADM1266 GO_COMMAND defines */
 #define ADM1266_GO_COMMAND_STOPBIT(0)
@@ -74,6 +82,8 @@
 
 #define ADM1266_FIRMWARE_OFFSET0x0
 #define ADM1266_FIRMWARE_SIZE  131072
+#define ADM1266_CONFIG_OFFSET  0x3
+#define ADM1266_CONFIG_SIZE131072
 #define ADM1266_BLACKBOX_OFFSET0x7F700
 #define ADM1266_BLACKBOX_SIZE  64
 
@@ -117,6 +127,11 @@ static const struct nvmem_cell_info adm1266_nvmem_cells[] 
= {
.offset = ADM1266_FIRMWARE_OFFSET,
.bytes  = ADM1266_FIRMWARE_SIZE,
},
+   {
+   .name   = "configuration",
+   .offset = ADM1266_CONFIG_OFFSET,
+   .bytes  = ADM1266_CONFIG_SIZE,
+   },
 };
 
 DECLARE_CRC8_TABLE(pmbus_crc_table);
@@ -521,6 +536,9 @@ static int adm1266_read_mem_cell(struct adm1266_data *data, 
const struct nvmem_c
case ADM1266_FIRMWARE_OFFSET:
/* firmware is write-only */
return 0;
+   case ADM1266_CONFIG_OFFSET:
+   /* configuration is write-only */
+   return 0;
default:
return -EINVAL;
}
@@ -677,6 +695,7 @@ static int adm1266_write_hex(struct adm1266_data *data,
u8 first_writes[7];
u8 byte_count;
u8 reg_address;
+   bool to_slaves = false;
int ret;
int i;
 
@@ -707,7 +726,10 @@ static int adm1266_write_hex(struct adm1266_data *data,
if (ret < 0)
return ret;
 
-   ret = adm1266_group_cmd(data, reg_address, write_buf, 
byte_count, true);
+   if (offset == ADM1266_FIRMWARE_OFFSET)
+   to_slaves = true;
+
+   ret = adm1266_group_cmd(data, reg_address, write_buf, 
byte_count, to_slaves);
if (ret < 0) {
dev_err(&data->client->dev, "Firmware write error: 
%d.", ret);
return ret;
@@ -732,6 +754,87 @@ static int adm1266_write_hex(struct adm1266_data *data,
return 0;
 }
 
+static int adm1266_verify_memory(struct adm1266_data *data)
+{
+   char cmd[2];
+   int ret;
+   int reg;
+
+   cmd[0] = 0x1;
+   cmd[1] = 0x0;
+   ret = adm1266_group_cmd(data, ADM1266_MEMORY_CRC, cmd,
+   sizeof(cmd), true);
+   if (ret < 0)
+   return ret;
+
+   /* after issuing a memory recalculate crc command, wait 1000 ms */
+   msleep(1000);
+
+   reg = pmbus_read_word_data(data->client, 0, 0xFF, ADM1266_STATUS_MFR_2);
+   if (reg < 0)
+   return reg;
+
+   if (ADM1266_MAIN_CONFIG_FAULT(reg)) {
+   dev_err(&data->client->dev, "Main memory corrupted.");
+   return -EFAULT;
+   }
+
+   return 0;
+}
+
+static int adm1266_refresh_memory(struct adm1266_data *data)
+{
+   unsigned int timeout = 9000;
+   int ret;
+   u8 cmd[2];
+
+   cmd[0] = 0x2;
+   ret = adm1266_group_cmd(data, ADM1266_REFRESH_FLASH, cmd, 1, true);
+   if (ret < 0) {
+   dev_err(&data->client->dev, "Could not refresh flash.");
+   return ret;
+   }
+
+   /* after issuing a refresh flash command, wait 9000 ms */
+   msleep(9000);
+
+   do {
+   msleep(1000);
+   timeout -= 1000;
+
+   ret = pmbus_read_byte_data(data->client, 0, ADM1266_STATUS_MFR);
+   if (ret < 0) {
+   dev_err(&data->client->dev, "Could not read status.

[PATCH v6 7/9] hwmon: pmbus: adm1266: program firmware

2020-07-26 Thread alexandru.tachici
From: Alexandru Tachici 

Writing the firmware Intel hex file to the nvmem,
of the master adm1266,  with offset 0, will now
trigger the firmware programming of all cascaded
devices simultaneously through pmbus.

During this process all adm1266 sequencers will be
stopped and at the end will be issued a hard reset
(see AN-1453 Programming the firmware).

Signed-off-by: Alexandru Tachici 
---
 drivers/hwmon/pmbus/adm1266.c | 501 +-
 1 file changed, 500 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/pmbus/adm1266.c b/drivers/hwmon/pmbus/adm1266.c
index 34bd4e652729..376fc56abe04 100644
--- a/drivers/hwmon/pmbus/adm1266.c
+++ b/drivers/hwmon/pmbus/adm1266.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -18,18 +19,31 @@
 #include 
 #include 
 #include "pmbus.h"
+#include 
 #include 
 #include 
 
+#define ADM1266_STORE_USER_ALL 0x15
+#define ADM1266_STATUS_MFR 0x80
+#define ADM1266_IC_DEVICE_REV  0xAE
 #define ADM1266_BLACKBOX_CONFIG0xD3
 #define ADM1266_PDIO_CONFIG0xD4
+#define ADM1266_SEQUENCE_CONFIG0xD6
+#define ADM1266_SYSTEM_CONFIG  0xD7
+#define ADM1266_GO_COMMAND 0xD8
 #define ADM1266_READ_STATE 0xD9
 #define ADM1266_READ_BLACKBOX  0xDE
 #define ADM1266_SET_RTC0xDF
+#define ADM1266_LOGIC_CONFIG   0xE0
 #define ADM1266_GPIO_CONFIG0xE1
+#define ADM1266_USER_DATA  0xE3
 #define ADM1266_BLACKBOX_INFO  0xE6
 #define ADM1266_PDIO_STATUS0xE9
 #define ADM1266_GPIO_STATUS0xEA
+#define ADM1266_MEMORY_CONFIG  0xF8
+#define ADM1266_SWITCH_MEMORY  0xFA
+#define ADM1266_UPDATE_FW  0xFC
+#define ADM1266_FW_PASSWORD0xFD
 
 /* ADM1266 GPIO defines */
 #define ADM1266_GPIO_NR9
@@ -44,10 +58,35 @@
 #define ADM1266_PDIO_GLITCH_FILT(x)FIELD_GET(GENMASK(12, 9), x)
 #define ADM1266_PDIO_OUT_CFG(x)FIELD_GET(GENMASK(2, 0), x)
 
+/* ADM1266 FW_PASSWORD defines*/
+#define ADM1266_PASSWD_CMD_LEN 17
+#define ADM1266_CHANGE_PASSWORD1
+#define ADM1266_UNLOCK_DEV 2
+#define ADM1266_LOCK_DEV   3
+
+/* ADM1266 STATUS_MFR defines */
+#define ADM1266_STATUS_PART_LOCKED(x)  FIELD_GET(BIT(2), x)
+
+/* ADM1266 GO_COMMAND defines */
+#define ADM1266_GO_COMMAND_STOPBIT(0)
+#define ADM1266_GO_COMMAND_SEQ_RES BIT(1)
+#define ADM1266_GO_COMMAND_HARD_RESBIT(2)
+
+#define ADM1266_FIRMWARE_OFFSET0x0
+#define ADM1266_FIRMWARE_SIZE  131072
 #define ADM1266_BLACKBOX_OFFSET0x7F700
 #define ADM1266_BLACKBOX_SIZE  64
 
 #define ADM1266_PMBUS_BLOCK_MAX255
+#define ADM1266_MAX_DEVICES16
+
+static LIST_HEAD(registered_masters);
+static DEFINE_MUTEX(registered_masters_lock);
+
+struct adm1266_data_ref {
+   struct adm1266_data *data;
+   struct list_head list;
+};
 
 struct adm1266_data {
struct pmbus_driver_info info;
@@ -57,6 +96,10 @@ struct adm1266_data {
struct dentry *debugfs_dir;
struct nvmem_config nvmem_config;
struct nvmem_device *nvmem;
+   bool master_dev;
+   struct list_head cascaded_devices_list;
+   struct mutex cascaded_devices_mutex; /* lock cascaded_devices_list */
+   u8 nr_devices;
u8 *dev_mem;
struct mutex buf_mutex;
u8 write_buf[ADM1266_PMBUS_BLOCK_MAX + 1] cacheline_aligned;
@@ -69,6 +112,11 @@ static const struct nvmem_cell_info adm1266_nvmem_cells[] = 
{
.offset = ADM1266_BLACKBOX_OFFSET,
.bytes  = 2048,
},
+   {
+   .name   = "firmware",
+   .offset = ADM1266_FIRMWARE_OFFSET,
+   .bytes  = ADM1266_FIRMWARE_SIZE,
+   },
 };
 
 DECLARE_CRC8_TABLE(pmbus_crc_table);
@@ -123,6 +171,27 @@ static int adm1266_pmbus_group_command(struct adm1266_data 
*data, struct i2c_cli
return ret;
 }
 
+static int adm1266_group_cmd(struct adm1266_data *data, u8 cmd, u8 
*write_data, u8 w_len,
+bool to_slaves)
+{
+   struct i2c_client *clients[ADM1266_MAX_DEVICES];
+   struct adm1266_data_ref *slave_ref;
+   int i = 0;
+
+   clients[i] = data->client;
+   i++;
+
+   if (!to_slaves)
+   return adm1266_pmbus_group_command(data, clients, 1, cmd, 
w_len, write_data);
+
+   list_for_each_entry(slave_ref, &data->cascaded_devices_list, list) {
+   clients[i] = slave_ref->data->client;
+   i++;
+   }
+
+   return adm1266_pmbus_group_command(data, clients, i, cmd, w_len, 
write_data);
+}
+
 /*
  * Different from Block Read as it sends data and waits for the slave to
  * return a value dependent on that data. The protocol is simply a Write Block
@@ -449,6 +518,9 @@ static int adm1266_read_mem_cell(struct adm1266_data *data, 
const struct nvmem_c
if (ret)
dev_err(&data->client->dev, "Could not read 

[PATCH v6 4/9] hwmon: pmbus: adm1266: add debugfs for states

2020-07-26 Thread alexandru.tachici
From: Alexandru Tachici 

Add a debugfs entry which prints the current state
of the adm1266 sequencer.

Signed-off-by: Alexandru Tachici 
---
 drivers/hwmon/pmbus/adm1266.c | 42 ++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/pmbus/adm1266.c b/drivers/hwmon/pmbus/adm1266.c
index be911de02cf6..dbffc6d12e87 100644
--- a/drivers/hwmon/pmbus/adm1266.c
+++ b/drivers/hwmon/pmbus/adm1266.c
@@ -19,6 +19,7 @@
 #include 
 
 #define ADM1266_PDIO_CONFIG0xD4
+#define ADM1266_READ_STATE 0xD9
 #define ADM1266_GPIO_CONFIG0xE1
 #define ADM1266_PDIO_STATUS0xE9
 #define ADM1266_GPIO_STATUS0xEA
@@ -43,6 +44,7 @@ struct adm1266_data {
struct gpio_chip gc;
const char *gpio_names[ADM1266_GPIO_NR + ADM1266_PDIO_NR];
struct i2c_client *client;
+   struct dentry *debugfs_dir;
struct mutex buf_mutex;
u8 write_buf[ADM1266_PMBUS_BLOCK_MAX + 1] cacheline_aligned;
u8 read_buf[ADM1266_PMBUS_BLOCK_MAX + 1] cacheline_aligned;
@@ -287,6 +289,38 @@ static int adm1266_config_gpio(struct adm1266_data *data)
return ret;
 }
 
+static int adm1266_state_read(struct seq_file *s, void *pdata)
+{
+   struct device *dev = s->private;
+   struct i2c_client *client = to_i2c_client(dev);
+   int ret;
+
+   ret = i2c_smbus_read_word_data(client, ADM1266_READ_STATE);
+   if (ret < 0)
+   return ret;
+
+   seq_printf(s, "%d\n", ret);
+
+   return 0;
+}
+
+static void adm1266_init_debugfs(struct adm1266_data *data)
+{
+   struct dentry *entry;
+   struct dentry *root;
+
+   root = pmbus_get_debugfs_dir(data->client);
+   if (!root)
+   return;
+
+   data->debugfs_dir = debugfs_create_dir(data->client->name, root);
+   if (!data->debugfs_dir)
+   return;
+
+   entry = debugfs_create_devm_seqfile(&data->client->dev, 
"sequencer_state",
+   data->debugfs_dir, 
adm1266_state_read);
+}
+
 static int adm1266_probe(struct i2c_client *client, const struct i2c_device_id 
*id)
 {
struct adm1266_data *data;
@@ -310,7 +344,13 @@ static int adm1266_probe(struct i2c_client *client, const 
struct i2c_device_id *
if (ret < 0)
return ret;
 
-   return pmbus_do_probe(client, id, &data->info);
+   ret = pmbus_do_probe(client, id, &data->info);
+   if (ret)
+   return ret;
+
+   adm1266_init_debugfs(data);
+
+   return 0;
 }
 
 static const struct of_device_id adm1266_of_match[] = {
-- 
2.20.1



[PATCH v6 0/9] hwmon: pmbus: adm1266: add support

2020-07-26 Thread alexandru.tachici
From: Alexandru Tachici 

Add PMBus probing driver for the adm1266 Cascadable
Super Sequencer with Margin Control and Fault Recording.
Driver is using the pmbus_core, creating sysfs files
under hwmon for inputs: vh1->vh4 and vp1->vp13.

1. Add PMBus probing driver for inputs vh1->vh4
and vp1->vp13.

2. Add Block Write-Read Process Call command.
A PMBus specific implementation was required because
block write with I2C_SMBUS_PROC_CALL flag allows a
maximum of 32 bytes to be received.

3. This makes adm1266 driver expose GPIOs
to user-space. Currently are read only. Future
developments on the firmware will allow
them to be writable.

4. Allow the current sate of the seqeuncer to be read
through debugfs.

5. Blackboxes are 64 bytes of chip state related data
that is generated on faults. Use the nvmem kernel api
to expose the blackbox chip functionality to userspace.

6. Add group command support. This will allow the driver
to stop/program all cascaded adm1266 devices at once.

7. Writing the firmware hex file with offset 0
to the nvmem of the master adm1266 will trigger
the firmware programming of all cascaded devices.
The master adm1266 of each device is specified in
the devicetree.

8. Writing the configuration hex file to 0x3
byte address of the nvmem file will trigger the
programing of that device in particular.

9. dt bindings for ADM1266.

Alexandru Tachici (9):
  hwmon: pmbus: adm1266: add support
  hwmon: pmbus: adm1266: Add Block process call
  hwmon: pmbus: adm1266: Add support for GPIOs
  hwmon: pmbus: adm1266: add debugfs for states
  hwmon: pmbus: adm1266: read blackbox
  hwmon: pmbus: adm1266: Add group command support
  hwmon: pmbus: adm1266: program firmware
  hwmon: pmbus: adm1266: program configuration
  dt-bindings: hwmon: Add bindings for ADM1266

 .../bindings/hwmon/adi,adm1266.yaml   |   56 +
 Documentation/hwmon/adm1266.rst   |   37 +
 Documentation/hwmon/index.rst |1 +
 drivers/hwmon/pmbus/Kconfig   |   10 +
 drivers/hwmon/pmbus/Makefile  |1 +
 drivers/hwmon/pmbus/adm1266.c | 1273 +
 6 files changed, 1378 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/adi,adm1266.yaml
 create mode 100644 Documentation/hwmon/adm1266.rst
 create mode 100644 drivers/hwmon/pmbus/adm1266.c

-- 
2.20.1



[PATCH v6 1/9] hwmon: pmbus: adm1266: add support

2020-07-26 Thread alexandru.tachici
From: Alexandru Tachici 

Add pmbus probing driver for the adm1266 Cascadable
Super Sequencer with Margin Control and Fault Recording.
Driver is using the pmbus_core, creating sysfs files
under hwmon for inputs: vh1->vh4 and vp1->vp13.

Signed-off-by: Alexandru Tachici 
---
 Documentation/hwmon/adm1266.rst | 37 +++
 Documentation/hwmon/index.rst   |  1 +
 drivers/hwmon/pmbus/Kconfig |  9 +
 drivers/hwmon/pmbus/Makefile|  1 +
 drivers/hwmon/pmbus/adm1266.c   | 65 +
 5 files changed, 113 insertions(+)
 create mode 100644 Documentation/hwmon/adm1266.rst
 create mode 100644 drivers/hwmon/pmbus/adm1266.c

diff --git a/Documentation/hwmon/adm1266.rst b/Documentation/hwmon/adm1266.rst
new file mode 100644
index ..9257f8a48650
--- /dev/null
+++ b/Documentation/hwmon/adm1266.rst
@@ -0,0 +1,37 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Kernel driver adm1266
+=
+
+Supported chips:
+  * Analog Devices ADM1266
+Prefix: 'adm1266'
+Datasheet: 
https://www.analog.com/media/en/technical-documentation/data-sheets/ADM1266.pdf
+
+Author: Alexandru Tachici 
+
+
+Description
+---
+
+This driver supports hardware monitoring for Analog Devices ADM1266 sequencer.
+
+ADM1266 is a sequencer that features voltage readback from 17 channels via an
+integrated 12 bit SAR ADC, accessed using a PMBus interface.
+
+The driver is a client driver to the core PMBus driver. Please see
+Documentation/hwmon/pmbus for details on PMBus client drivers.
+
+
+Sysfs entries
+-
+
+The following attributes are supported. Limits are read-write, history reset
+attributes are write-only, all other attributes are read-only.
+
+inX_label  "voutx"
+inX_input  Measured voltage.
+inX_minMinimum Voltage.
+inX_maxMaximum voltage.
+inX_min_alarm  Voltage low alarm.
+inX_max_alarm  Voltage high alarm.
diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
index 55ff4b7c5349..056f7107d7b8 100644
--- a/Documentation/hwmon/index.rst
+++ b/Documentation/hwmon/index.rst
@@ -30,6 +30,7 @@ Hardware Monitoring Kernel Drivers
adm1026
adm1031
adm1177
+   adm1266
adm1275
adm9240
ads7828
diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
index a337195b1c39..da34083e1ffd 100644
--- a/drivers/hwmon/pmbus/Kconfig
+++ b/drivers/hwmon/pmbus/Kconfig
@@ -26,6 +26,15 @@ config SENSORS_PMBUS
  This driver can also be built as a module. If so, the module will
  be called pmbus.
 
+config SENSORS_ADM1266
+   tristate "Analog Devices ADM1266 Sequencer"
+   help
+ If you say yes here you get hardware monitoring support for Analog
+ Devices ADM1266 Cascadable Super Sequencer.
+
+ This driver can also be built as a module. If so, the module will
+ be called adm1266.
+
 config SENSORS_ADM1275
tristate "Analog Devices ADM1275 and compatibles"
help
diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile
index c4b15db996ad..da41d22be1c9 100644
--- a/drivers/hwmon/pmbus/Makefile
+++ b/drivers/hwmon/pmbus/Makefile
@@ -5,6 +5,7 @@
 
 obj-$(CONFIG_PMBUS)+= pmbus_core.o
 obj-$(CONFIG_SENSORS_PMBUS)+= pmbus.o
+obj-$(CONFIG_SENSORS_ADM1266)  += adm1266.o
 obj-$(CONFIG_SENSORS_ADM1275)  += adm1275.o
 obj-$(CONFIG_SENSORS_BEL_PFE)  += bel-pfe.o
 obj-$(CONFIG_SENSORS_IBM_CFFPS)+= ibm-cffps.o
diff --git a/drivers/hwmon/pmbus/adm1266.c b/drivers/hwmon/pmbus/adm1266.c
new file mode 100644
index ..79e8d90886b8
--- /dev/null
+++ b/drivers/hwmon/pmbus/adm1266.c
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * ADM1266 - Cascadable Super Sequencer with Margin
+ * Control and Fault Recording
+ *
+ * Copyright 2020 Analog Devices Inc.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "pmbus.h"
+#include 
+
+struct adm1266_data {
+   struct pmbus_driver_info info;
+   struct i2c_client *client;
+};
+
+static int adm1266_probe(struct i2c_client *client, const struct i2c_device_id 
*id)
+{
+   struct adm1266_data *data;
+   int i;
+
+   data = devm_kzalloc(&client->dev, sizeof(struct adm1266_data), 
GFP_KERNEL);
+   if (!data)
+   return -ENOMEM;
+
+   data->client = client;
+   data->info.pages = 17;
+   data->info.format[PSC_VOLTAGE_OUT] = linear;
+   for (i = 0; i < data->info.pages; i++)
+   data->info.func[i] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT;
+
+   return pmbus_do_probe(client, id, &data->info);
+}
+
+static const struct of_device_id adm1266_of_match[] = {
+   { .compatible = "adi,adm1266" },
+   { }
+};
+MODULE_DEVICE_TABLE(of, adm1266_of_match);
+
+static const struct i2c_device_id adm1266_id[] = {
+   { "adm1266", 0 },
+   { }
+};
+MODULE_DEVICE_TABLE(i2c, adm1266_id);
+
+static struct i2c_driver adm1266_

[PATCH v6 5/9] hwmon: pmbus: adm1266: read blackbox

2020-07-26 Thread alexandru.tachici
From: Alexandru Tachici 

Use the nvmem kernel api to expose the black box
chip functionality to userspace.

Using this feature, the device is capable of recording
to nonvolatile flash memory the vital data about the
system status that caused the system to perform a
black box write.

A blackbox is 64 bytes of data containing all the
status registers, last two states of the sequencer,
timestamp and counters. The mapping of this data is
described in the adm1266 datasheet.

On power-up the driver sets the unix time to
the adm1266 using the SET_RTC command. This value
is incremented by an internal clock and it is used
as timestamp for the black box feature.

Signed-off-by: Alexandru Tachici 
---
 drivers/hwmon/pmbus/adm1266.c | 165 ++
 1 file changed, 165 insertions(+)

diff --git a/drivers/hwmon/pmbus/adm1266.c b/drivers/hwmon/pmbus/adm1266.c
index dbffc6d12e87..c06465100320 100644
--- a/drivers/hwmon/pmbus/adm1266.c
+++ b/drivers/hwmon/pmbus/adm1266.c
@@ -15,12 +15,19 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include "pmbus.h"
 #include 
+#include 
 
+#define ADM1266_BLACKBOX_CONFIG0xD3
 #define ADM1266_PDIO_CONFIG0xD4
 #define ADM1266_READ_STATE 0xD9
+#define ADM1266_READ_BLACKBOX  0xDE
+#define ADM1266_SET_RTC0xDF
 #define ADM1266_GPIO_CONFIG0xE1
+#define ADM1266_BLACKBOX_INFO  0xE6
 #define ADM1266_PDIO_STATUS0xE9
 #define ADM1266_GPIO_STATUS0xEA
 
@@ -37,6 +44,9 @@
 #define ADM1266_PDIO_GLITCH_FILT(x)FIELD_GET(GENMASK(12, 9), x)
 #define ADM1266_PDIO_OUT_CFG(x)FIELD_GET(GENMASK(2, 0), x)
 
+#define ADM1266_BLACKBOX_OFFSET0x7F700
+#define ADM1266_BLACKBOX_SIZE  64
+
 #define ADM1266_PMBUS_BLOCK_MAX255
 
 struct adm1266_data {
@@ -45,11 +55,22 @@ struct adm1266_data {
const char *gpio_names[ADM1266_GPIO_NR + ADM1266_PDIO_NR];
struct i2c_client *client;
struct dentry *debugfs_dir;
+   struct nvmem_config nvmem_config;
+   struct nvmem_device *nvmem;
+   u8 *dev_mem;
struct mutex buf_mutex;
u8 write_buf[ADM1266_PMBUS_BLOCK_MAX + 1] cacheline_aligned;
u8 read_buf[ADM1266_PMBUS_BLOCK_MAX + 1] cacheline_aligned;
 };
 
+static const struct nvmem_cell_info adm1266_nvmem_cells[] = {
+   {
+   .name   = "blackbox",
+   .offset = ADM1266_BLACKBOX_OFFSET,
+   .bytes  = 2048,
+   },
+};
+
 DECLARE_CRC8_TABLE(pmbus_crc_table);
 
 /*
@@ -321,6 +342,142 @@ static void adm1266_init_debugfs(struct adm1266_data 
*data)
data->debugfs_dir, 
adm1266_state_read);
 }
 
+#if IS_ENABLED(CONFIG_NVMEM)
+static int adm1266_nvmem_read_blackbox(struct adm1266_data *data, u8 
*read_buff)
+{
+   int record_count;
+   char index;
+   u8 buf[5];
+   int ret;
+
+   ret = i2c_smbus_read_block_data(data->client, ADM1266_BLACKBOX_INFO, 
buf);
+   if (ret < 0)
+   return ret;
+
+   if (ret != 4)
+   return -EIO;
+
+   record_count = buf[3];
+
+   for (index = 0; index < record_count; index++) {
+   ret = adm1266_pmbus_block_xfer(data, ADM1266_READ_BLACKBOX, 1, 
&index, read_buff);
+   if (ret < 0)
+   return ret;
+
+   if (ret != ADM1266_BLACKBOX_SIZE)
+   return -EIO;
+
+   read_buff += ADM1266_BLACKBOX_SIZE;
+   }
+
+   return 0;
+}
+
+static bool adm1266_cell_is_accessed(const struct nvmem_cell_info *mem_cell, 
unsigned int offset,
+size_t bytes)
+{
+   unsigned int start_addr = offset;
+   unsigned int end_addr = offset + bytes;
+   unsigned int cell_start = mem_cell->offset;
+   unsigned int cell_end = mem_cell->offset + mem_cell->bytes;
+
+   return start_addr <= cell_end && cell_start <= end_addr;
+}
+
+static int adm1266_read_mem_cell(struct adm1266_data *data, const struct 
nvmem_cell_info *mem_cell)
+{
+   u8 *mem_offset;
+   int ret;
+
+   switch (mem_cell->offset) {
+   case ADM1266_BLACKBOX_OFFSET:
+   mem_offset = data->dev_mem + mem_cell->offset;
+
+   memset(mem_offset, 0, ADM1266_BLACKBOX_SIZE);
+
+   ret = adm1266_nvmem_read_blackbox(data, mem_offset);
+   if (ret)
+   dev_err(&data->client->dev, "Could not read blackbox!");
+   return ret;
+   default:
+   return -EINVAL;
+   }
+}
+
+static int adm1266_nvmem_read(void *priv, unsigned int offset, void *val,
+ size_t bytes)
+{
+   const struct nvmem_cell_info *mem_cell;
+   struct adm1266_data *data = priv;
+   int ret;
+   int i;
+
+   for (i = 0; i < data->nvmem_config.ncells; i++) {
+   mem_cell = &adm1266_nvmem_cells[i];
+   if (!adm1266_cell_is_accessed

[PATCH v6 3/9] hwmon: pmbus: adm1266: Add support for GPIOs

2020-07-26 Thread alexandru.tachici
From: Alexandru Tachici 

Adm1266 exposes 9 GPIOs and 16 PDIOs which are currently read-only. They
are controlled by the internal sequencing engine.

This patch makes adm1266 driver expose GPIOs and PDIOs to user-space
using GPIO provider kernel api.

Signed-off-by: Alexandru Tachici 
---
 drivers/hwmon/pmbus/adm1266.c | 204 ++
 1 file changed, 204 insertions(+)

diff --git a/drivers/hwmon/pmbus/adm1266.c b/drivers/hwmon/pmbus/adm1266.c
index 63975eba34ad..be911de02cf6 100644
--- a/drivers/hwmon/pmbus/adm1266.c
+++ b/drivers/hwmon/pmbus/adm1266.c
@@ -6,18 +6,42 @@
  * Copyright 2020 Analog Devices Inc.
  */
 
+#include 
 #include 
+#include 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include "pmbus.h"
 #include 
 
+#define ADM1266_PDIO_CONFIG0xD4
+#define ADM1266_GPIO_CONFIG0xE1
+#define ADM1266_PDIO_STATUS0xE9
+#define ADM1266_GPIO_STATUS0xEA
+
+/* ADM1266 GPIO defines */
+#define ADM1266_GPIO_NR9
+#define ADM1266_GPIO_FUNCTIONS(x)  FIELD_GET(BIT(0), x)
+#define ADM1266_GPIO_INPUT_EN(x)   FIELD_GET(BIT(2), x)
+#define ADM1266_GPIO_OUTPUT_EN(x)  FIELD_GET(BIT(3), x)
+#define ADM1266_GPIO_OPEN_DRAIN(x) FIELD_GET(BIT(4), x)
+
+/* ADM1266 PDIO defines */
+#define ADM1266_PDIO_NR16
+#define ADM1266_PDIO_PIN_CFG(x)FIELD_GET(GENMASK(15, 13), x)
+#define ADM1266_PDIO_GLITCH_FILT(x)FIELD_GET(GENMASK(12, 9), x)
+#define ADM1266_PDIO_OUT_CFG(x)FIELD_GET(GENMASK(2, 0), x)
+
 #define ADM1266_PMBUS_BLOCK_MAX255
 
 struct adm1266_data {
struct pmbus_driver_info info;
+   struct gpio_chip gc;
+   const char *gpio_names[ADM1266_GPIO_NR + ADM1266_PDIO_NR];
struct i2c_client *client;
struct mutex buf_mutex;
u8 write_buf[ADM1266_PMBUS_BLOCK_MAX + 1] cacheline_aligned;
@@ -88,9 +112,185 @@ static int adm1266_pmbus_block_xfer(struct adm1266_data 
*data, u8 cmd, u8 w_len,
return ret;
 }
 
+static const unsigned int adm1266_gpio_mapping[ADM1266_GPIO_NR][2] = {
+   {1, 0},
+   {2, 1},
+   {3, 2},
+   {4, 8},
+   {5, 9},
+   {6, 10},
+   {7, 11},
+   {8, 6},
+   {9, 7},
+};
+
+static const char *adm1266_names[ADM1266_GPIO_NR + ADM1266_PDIO_NR] = {
+   "GPIO1", "GPIO2", "GPIO3", "GPIO4", "GPIO5", "GPIO6", "GPIO7", "GPIO8",
+   "GPIO9", "PDIO1", "PDIO2", "PDIO3", "PDIO4", "PDIO5", "PDIO6",
+   "PDIO7", "PDIO8", "PDIO9", "PDIO10", "PDIO11", "PDIO12", "PDIO13",
+   "PDIO14", "PDIO15", "PDIO16",
+};
+
+static int adm1266_gpio_get(struct gpio_chip *chip, unsigned int offset)
+{
+   struct adm1266_data *data = gpiochip_get_data(chip);
+   u8 read_buf[I2C_SMBUS_BLOCK_MAX + 1];
+   unsigned long pins_status;
+   unsigned int pmbus_cmd;
+   int ret;
+
+   if (offset < ADM1266_GPIO_NR)
+   pmbus_cmd = ADM1266_GPIO_STATUS;
+   else
+   pmbus_cmd = ADM1266_PDIO_STATUS;
+
+   ret = i2c_smbus_read_block_data(data->client, pmbus_cmd, read_buf);
+   if (ret < 0)
+   return ret;
+
+   pins_status = read_buf[0] + (read_buf[1] << 8);
+   if (offset < ADM1266_GPIO_NR)
+   return test_bit(adm1266_gpio_mapping[offset][1], &pins_status);
+
+   return test_bit(offset - ADM1266_GPIO_NR, &pins_status);
+}
+
+static int adm1266_gpio_get_multiple(struct gpio_chip *chip, unsigned long 
*mask,
+unsigned long *bits)
+{
+   struct adm1266_data *data = gpiochip_get_data(chip);
+   u8 read_buf[ADM1266_PMBUS_BLOCK_MAX + 1];
+   unsigned long status;
+   unsigned int gpio_nr;
+   int ret;
+
+   ret = i2c_smbus_read_block_data(data->client, ADM1266_GPIO_STATUS, 
read_buf);
+   if (ret < 0)
+   return ret;
+
+   status = read_buf[0] + (read_buf[1] << 8);
+
+   *bits = 0;
+   for_each_set_bit(gpio_nr, mask, ADM1266_GPIO_NR) {
+   if (test_bit(adm1266_gpio_mapping[gpio_nr][1], &status))
+   set_bit(gpio_nr, bits);
+   }
+
+   ret = i2c_smbus_read_block_data(data->client, ADM1266_PDIO_STATUS, 
read_buf);
+   if (ret < 0)
+   return ret;
+
+   status = read_buf[0] + (read_buf[1] << 8);
+
+   *bits = 0;
+   for_each_set_bit_from(gpio_nr, mask, ADM1266_GPIO_NR + 
ADM1266_PDIO_STATUS) {
+   if (test_bit(gpio_nr - ADM1266_GPIO_NR, &status))
+   set_bit(gpio_nr, bits);
+   }
+
+   return 0;
+}
+
+static void adm1266_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
+{
+   struct adm1266_data *data = gpiochip_get_data(chip);
+   u8 read_buf[ADM1266_PMBUS_BLOCK_MAX + 1];
+   unsigned long gpio_config;
+   unsigned long pdio_config;
+   unsigned long pin_cfg;
+   u8 write_cmd;
+   int ret;
+   int i;
+
+   for (i = 0; i < ADM1266_GPIO_NR; i++) {
+   wr

[PATCH v6 9/9] dt-bindings: hwmon: Add bindings for ADM1266

2020-07-26 Thread alexandru.tachici
From: Alexandru Tachici 

Add bindings for the Analog Devices ADM1266 sequencer.

Signed-off-by: Alexandru Tachici 
---
 .../bindings/hwmon/adi,adm1266.yaml   | 56 +++
 1 file changed, 56 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/adi,adm1266.yaml

diff --git a/Documentation/devicetree/bindings/hwmon/adi,adm1266.yaml 
b/Documentation/devicetree/bindings/hwmon/adi,adm1266.yaml
new file mode 100644
index ..ad92686e2ee6
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/adi,adm1266.yaml
@@ -0,0 +1,56 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/adi,adm1266.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices ADM1266 Cascadable Super Sequencer with Margin
+  Control and Fault Recording
+
+maintainers:
+  - Alexandru Tachici 
+
+description: |
+  Analog Devices ADM1266 Cascadable Super Sequencer with Margin
+  Control and Fault Recording.
+  
https://www.analog.com/media/en/technical-documentation/data-sheets/ADM1266.pdf
+
+properties:
+  compatible:
+enum:
+  - adi,adm1266
+
+  reg:
+description: |
+  I2C address of slave device.
+items:
+  minimum: 0x40
+  maximum: 0x4F
+
+  avcc-supply:
+description: |
+  Phandle to the Avcc power supply.
+
+  adi,master-adm1266:
+description: |
+  Represents phandle of a master ADM1266 device cascaded through the IDB.
+$ref: "/schemas/types.yaml#/definitions/phandle"
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+i2c0 {
+#address-cells = <1>;
+#size-cells = <0>;
+
+adm1266@40 {
+compatible = "adi,adm1266";
+reg = <0x40>;
+};
+};
+...
-- 
2.20.1



[PATCH v6 6/9] hwmon: pmbus: adm1266: Add group command support

2020-07-26 Thread alexandru.tachici
From: Alexandru Tachici 

The Group Command Protocol is used to send commands
to more than one PMBus device. Some devices working
together require that they must execute some commands
all at once.

The commands are sent in one continuous transmission.
When the devices detect the STOP condition that ends
the sending of commands, they all begin executing
the command they received.

This patch adds support for the group command protocol.

Signed-off-by: Alexandru Tachici 
---
 drivers/hwmon/pmbus/adm1266.c | 50 +++
 1 file changed, 50 insertions(+)

diff --git a/drivers/hwmon/pmbus/adm1266.c b/drivers/hwmon/pmbus/adm1266.c
index c06465100320..34bd4e652729 100644
--- a/drivers/hwmon/pmbus/adm1266.c
+++ b/drivers/hwmon/pmbus/adm1266.c
@@ -73,6 +73,56 @@ static const struct nvmem_cell_info adm1266_nvmem_cells[] = {
 
 DECLARE_CRC8_TABLE(pmbus_crc_table);
 
+/* PMBus Group command. */
+static int adm1266_pmbus_group_command(struct adm1266_data *data, struct 
i2c_client **clients,
+  u8 nr_clients, u8 cmd, u8 w_len, u8 
*data_w)
+{
+   struct i2c_msg *msgs;
+   u8 addr;
+   int ret;
+   int i;
+
+   msgs = kcalloc(nr_clients, sizeof(struct i2c_msg), GFP_KERNEL);
+   if (!msgs)
+   return -ENOMEM;
+
+   for (i = 0; i < nr_clients; i++) {
+   msgs[i].addr = clients[i]->addr;
+   msgs[i].len = w_len + 1;
+
+   msgs[i].buf = kcalloc(ADM1266_PMBUS_BLOCK_MAX + 2, sizeof(u8), 
GFP_KERNEL);
+   if (!msgs[i].buf) {
+   ret = -ENOMEM;
+   goto cleanup;
+   }
+
+   msgs[i].buf[0] = cmd;
+   memcpy(&msgs[i].buf[1], data_w, w_len);
+
+   if (clients[i]->flags & I2C_CLIENT_PEC) {
+   u8 crc = 0;
+
+   addr = i2c_8bit_addr_from_msg(&msgs[i]);
+   crc = crc8(pmbus_crc_table, &addr, 1, crc);
+   crc = crc8(pmbus_crc_table, msgs[i].buf, msgs[i].len,
+  crc);
+
+   msgs[i].buf[msgs[i].len] = crc;
+   msgs[i].len++;
+   }
+   };
+
+   ret = i2c_transfer(data->client->adapter, msgs, nr_clients);
+
+cleanup:
+   for (i = i - 1; i >= 0; i--)
+   kfree(msgs[i].buf);
+
+   kfree(msgs);
+
+   return ret;
+}
+
 /*
  * Different from Block Read as it sends data and waits for the slave to
  * return a value dependent on that data. The protocol is simply a Write Block
-- 
2.20.1



Re: [PATCH v7 4/7] fs: Introduce O_MAYEXEC flag for openat2(2)

2020-07-26 Thread Florian Weimer
* Al Viro:

> On Thu, Jul 23, 2020 at 07:12:24PM +0200, Mickaël Salaün wrote:
>> When the O_MAYEXEC flag is passed, openat2(2) may be subject to
>> additional restrictions depending on a security policy managed by the
>> kernel through a sysctl or implemented by an LSM thanks to the
>> inode_permission hook.  This new flag is ignored by open(2) and
>> openat(2) because of their unspecified flags handling.  When used with
>> openat2(2), the default behavior is only to forbid to open a directory.
>
> Correct me if I'm wrong, but it looks like you are introducing a magical
> flag that would mean "let the Linux S&M take an extra special whip
> for this open()".
>
> Why is it done during open?  If the caller is passing it deliberately,
> why not have an explicit request to apply given torture device to an
> already opened file?  Why not sys_masochism(int fd, char *hurt_flavour),
> for that matter?

While I do not think this is appropriate language for a workplace, Al
has a point: If the auditing event can be generated on an already-open
descriptor, it would also cover scenarios like this one:

  perl < /path/to/script

Where the process that opens the file does not (and cannot) know that it
will be used for execution purposes.

Thanks,
Florian



[PATCH v4 03/10] powerpc/smp: Move powerpc_topology above

2020-07-26 Thread Srikar Dronamraju
Just moving the powerpc_topology description above.
This will help in using functions in this file and avoid declarations.

No other functional changes

Cc: linuxppc-dev 
Cc: LKML 
Cc: Michael Ellerman 
Cc: Nicholas Piggin 
Cc: Anton Blanchard 
Cc: Oliver O'Halloran 
Cc: Nathan Lynch 
Cc: Michael Neuling 
Cc: Gautham R Shenoy 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Valentin Schneider 
Cc: Jordan Niethe 
Reviewed-by: Gautham R. Shenoy 
Signed-off-by: Srikar Dronamraju 
---
 arch/powerpc/kernel/smp.c | 116 +++---
 1 file changed, 58 insertions(+), 58 deletions(-)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index 283a04e54f52..a685915e5941 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -818,6 +818,64 @@ static int init_cpu_l1_cache_map(int cpu)
return err;
 }
 
+static bool shared_caches;
+
+#ifdef CONFIG_SCHED_SMT
+/* cpumask of CPUs with asymmetric SMT dependency */
+static int powerpc_smt_flags(void)
+{
+   int flags = SD_SHARE_CPUCAPACITY | SD_SHARE_PKG_RESOURCES;
+
+   if (cpu_has_feature(CPU_FTR_ASYM_SMT)) {
+   printk_once(KERN_INFO "Enabling Asymmetric SMT scheduling\n");
+   flags |= SD_ASYM_PACKING;
+   }
+   return flags;
+}
+#endif
+
+/*
+ * P9 has a slightly odd architecture where pairs of cores share an L2 cache.
+ * This topology makes it *much* cheaper to migrate tasks between adjacent 
cores
+ * since the migrated task remains cache hot. We want to take advantage of this
+ * at the scheduler level so an extra topology level is required.
+ */
+static int powerpc_shared_cache_flags(void)
+{
+   return SD_SHARE_PKG_RESOURCES;
+}
+
+/*
+ * We can't just pass cpu_l2_cache_mask() directly because
+ * returns a non-const pointer and the compiler barfs on that.
+ */
+static const struct cpumask *shared_cache_mask(int cpu)
+{
+   if (shared_caches)
+   return cpu_l2_cache_mask(cpu);
+
+   if (has_big_cores)
+   return cpu_smallcore_mask(cpu);
+
+   return per_cpu(cpu_sibling_map, cpu);
+}
+
+#ifdef CONFIG_SCHED_SMT
+static const struct cpumask *smallcore_smt_mask(int cpu)
+{
+   return cpu_smallcore_mask(cpu);
+}
+#endif
+
+static struct sched_domain_topology_level powerpc_topology[] = {
+#ifdef CONFIG_SCHED_SMT
+   { cpu_smt_mask, powerpc_smt_flags, SD_INIT_NAME(SMT) },
+#endif
+   { shared_cache_mask, powerpc_shared_cache_flags, SD_INIT_NAME(CACHE) },
+   { cpu_cpu_mask, SD_INIT_NAME(DIE) },
+   { NULL, },
+};
+
 static int init_big_cores(void)
 {
int cpu;
@@ -1247,8 +1305,6 @@ static void add_cpu_to_masks(int cpu)
set_cpus_related(cpu, i, cpu_core_mask);
 }
 
-static bool shared_caches;
-
 /* Activate a secondary processor. */
 void start_secondary(void *unused)
 {
@@ -1312,62 +1368,6 @@ int setup_profiling_timer(unsigned int multiplier)
return 0;
 }
 
-#ifdef CONFIG_SCHED_SMT
-/* cpumask of CPUs with asymmetric SMT dependency */
-static int powerpc_smt_flags(void)
-{
-   int flags = SD_SHARE_CPUCAPACITY | SD_SHARE_PKG_RESOURCES;
-
-   if (cpu_has_feature(CPU_FTR_ASYM_SMT)) {
-   printk_once(KERN_INFO "Enabling Asymmetric SMT scheduling\n");
-   flags |= SD_ASYM_PACKING;
-   }
-   return flags;
-}
-#endif
-
-/*
- * P9 has a slightly odd architecture where pairs of cores share an L2 cache.
- * This topology makes it *much* cheaper to migrate tasks between adjacent 
cores
- * since the migrated task remains cache hot. We want to take advantage of this
- * at the scheduler level so an extra topology level is required.
- */
-static int powerpc_shared_cache_flags(void)
-{
-   return SD_SHARE_PKG_RESOURCES;
-}
-
-/*
- * We can't just pass cpu_l2_cache_mask() directly because
- * returns a non-const pointer and the compiler barfs on that.
- */
-static const struct cpumask *shared_cache_mask(int cpu)
-{
-   if (shared_caches)
-   return cpu_l2_cache_mask(cpu);
-
-   if (has_big_cores)
-   return cpu_smallcore_mask(cpu);
-
-   return per_cpu(cpu_sibling_map, cpu);
-}
-
-#ifdef CONFIG_SCHED_SMT
-static const struct cpumask *smallcore_smt_mask(int cpu)
-{
-   return cpu_smallcore_mask(cpu);
-}
-#endif
-
-static struct sched_domain_topology_level powerpc_topology[] = {
-#ifdef CONFIG_SCHED_SMT
-   { cpu_smt_mask, powerpc_smt_flags, SD_INIT_NAME(SMT) },
-#endif
-   { shared_cache_mask, powerpc_shared_cache_flags, SD_INIT_NAME(CACHE) },
-   { cpu_cpu_mask, SD_INIT_NAME(DIE) },
-   { NULL, },
-};
-
 void __init smp_cpus_done(unsigned int max_cpus)
 {
/*
-- 
2.17.1



Re: [PATCH] kernel.h: Remove duplicate include of asm/div64.h

2020-07-26 Thread Christoph Hellwig
On Sun, Jul 26, 2020 at 11:48:52PM -0400, Arvind Sankar wrote:
> This seems to have been added inadvertently in commit
>   72deb455b5ec ("block: remove CONFIG_LBDAF")
> 
> Fixes: 72deb455b5ec ("block: remove CONFIG_LBDAF")
> Signed-off-by: Arvind Sankar 
> Cc: Christoph Hellwig 

Looks good:

Reviewed-by: Christoph Hellwig 


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

2020-07-26 Thread Christoph Hellwig
The fixup looks good to me, thanks.


Re: [PATCH] [net/ipv6] ip6_output: Add ipv6_pinfo null check

2020-07-26 Thread kernel test robot
Hi Gaurav,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on sparc-next/master]
[also build test WARNING on ipvs/master linus/master v5.8-rc7 next-20200724]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:
https://github.com/0day-ci/linux/commits/Gaurav-Singh/ip6_output-Add-ipv6_pinfo-null-check/20200727-113949
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-next.git 
master
config: csky-defconfig (attached as .config)
compiler: csky-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
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
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross 
ARCH=csky 

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

All warnings (new ones prefixed by >>):

   net/ipv6/ip6_output.c: In function 'ip6_autoflowlabel':
>> net/ipv6/ip6_output.c:188:1: warning: control reaches end of non-void 
>> function [-Wreturn-type]
 188 | }
 | ^

vim +188 net/ipv6/ip6_output.c

^1da177e4c3f41 Linus Torvalds 2005-04-16  181  
e9191ffb65d8e1 Ben Hutchings  2018-01-22  182  bool ip6_autoflowlabel(struct 
net *net, const struct ipv6_pinfo *np)
513674b5a2c9c7 Shaohua Li 2017-12-20  183  {
5bdc1ea8a7d229 Gaurav Singh   2020-07-26  184   if (np && np->autoflowlabel_set)
513674b5a2c9c7 Shaohua Li 2017-12-20  185   return 
np->autoflowlabel;
5bdc1ea8a7d229 Gaurav Singh   2020-07-26  186   else
5bdc1ea8a7d229 Gaurav Singh   2020-07-26  187   
ip6_default_np_autolabel(net);
513674b5a2c9c7 Shaohua Li 2017-12-20 @188  }
513674b5a2c9c7 Shaohua Li 2017-12-20  189  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


.config.gz
Description: application/gzip


[PATCH v4 01/10] powerpc/smp: Fix a warning under !NEED_MULTIPLE_NODES

2020-07-26 Thread Srikar Dronamraju
Fix a build warning in a non CONFIG_NEED_MULTIPLE_NODES
"error: _numa_cpu_lookup_table_ undeclared"

Cc: linuxppc-dev 
Cc: LKML 
Cc: Michael Ellerman 
Cc: Nicholas Piggin 
Cc: Anton Blanchard 
Cc: Oliver O'Halloran 
Cc: Nathan Lynch 
Cc: Michael Neuling 
Cc: Gautham R Shenoy 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Valentin Schneider 
Cc: Jordan Niethe 
Reviewed-by: Gautham R. Shenoy 
Signed-off-by: Srikar Dronamraju 
---
Changelog v2 -> v3:
Removed node caching part. Rewrote the Commit msg (Michael Ellerman)
Renamed to powerpc/smp: Fix a warning under !NEED_MULTIPLE_NODES

 arch/powerpc/kernel/smp.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index 73199470c265..edf94ca64eea 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -860,6 +860,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
GFP_KERNEL, cpu_to_node(cpu));
zalloc_cpumask_var_node(&per_cpu(cpu_core_map, cpu),
GFP_KERNEL, cpu_to_node(cpu));
+#ifdef CONFIG_NEED_MULTIPLE_NODES
/*
 * numa_node_id() works after this.
 */
@@ -868,6 +869,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
set_cpu_numa_mem(cpu,
local_memory_node(numa_cpu_lookup_table[cpu]));
}
+#endif
}
 
/* Init the cpumasks so the boot CPU is related to itself */
-- 
2.17.1



Re: [PATCH 06/10] remoteproc: imx_rproc: add load hook

2020-07-26 Thread Oleksij Rempel
On Fri, Jul 24, 2020 at 04:08:09PM +0800, Peng Fan wrote:
> To i.MX8, we not able to see the correct data written into TCM when
> using ioremap_wc, so use ioremap.
> 
> However common elf loader using memset.
> 
> To arm64, "dc  zva, dst" is used in memset.
> Per ARM DDI 0487A.j, chapter C5.3.8 DC ZVA, Data Cache Zero by VA,
> 
> "If the memory region being zeroed is any type of Device memory,
> this instruction can give an alignment fault which is prioritized
> in the same way as other alignment faults that are determined
> by the memory type."
> 
> On i.MX platforms, when elf is loaded to onchip TCM area, the region
> is ioremapped, so "dc zva, dst" will trigger abort.
>
> So add i.MX specific loader to address the TCM write issue.

First I wonted to ask, if it is AMR64 related issues, why do we handle
it in iMX specific driver?

But after searching and finding this thread:
https://lkml.org/lkml/2020/4/18/93
it looks to me like most of related maintainer questions, was not
answered.

> The change not impact i.MX6/7 function.

Hm... it is impossible assumption,e except you was able to test all
firmware variants it the wild.
You changed behavior of ELF parser in the first place. It means,
not iMX6/7 is affected, but firmware used on this platforms.

> Signed-off-by: Peng Fan 
> ---
>  drivers/remoteproc/imx_rproc.c | 76 
> ++
>  1 file changed, 76 insertions(+)
> 
> diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
> index aee790efbf7b..c23726091228 100644
> --- a/drivers/remoteproc/imx_rproc.c
> +++ b/drivers/remoteproc/imx_rproc.c
> @@ -4,6 +4,7 @@
>   */
>  
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -15,6 +16,9 @@
>  #include 
>  #include 
>  
> +#include "remoteproc_internal.h"
> +#include "remoteproc_elf_helpers.h"
> +
>  #define IMX7D_SRC_SCR0x0C
>  #define IMX7D_ENABLE_M4  BIT(3)
>  #define IMX7D_SW_M4P_RST BIT(2)
> @@ -247,10 +251,82 @@ static void *imx_rproc_da_to_va(struct rproc *rproc, 
> u64 da, size_t len)
>   return va;
>  }
>  
> +static int imx_rproc_elf_load_segments(struct rproc *rproc, const struct 
> firmware *fw)
> +{
> + struct device *dev = &rproc->dev;
> + const void *ehdr, *phdr;
> + int i, ret = 0;
> + u16 phnum;
> + const u8 *elf_data = fw->data;
> + u8 class = fw_elf_get_class(fw);
> + u32 elf_phdr_get_size = elf_size_of_phdr(class);
> +
> + ehdr = elf_data;
> + phnum = elf_hdr_get_e_phnum(class, ehdr);
> + phdr = elf_data + elf_hdr_get_e_phoff(class, ehdr);
> +
> + /* go through the available ELF segments */
> + for (i = 0; i < phnum; i++, phdr += elf_phdr_get_size) {
> + u64 da = elf_phdr_get_p_paddr(class, phdr);
> + u64 memsz = elf_phdr_get_p_memsz(class, phdr);
> + u64 filesz = elf_phdr_get_p_filesz(class, phdr);
> + u64 offset = elf_phdr_get_p_offset(class, phdr);
> + u32 type = elf_phdr_get_p_type(class, phdr);
> + void *ptr;
> +
> + if (type != PT_LOAD)
> + continue;
> +
> + dev_dbg(dev, "phdr: type %d da 0x%llx memsz 0x%llx filesz 
> 0x%llx\n",
> + type, da, memsz, filesz);
> +
> + if (filesz > memsz) {
> + dev_err(dev, "bad phdr filesz 0x%llx memsz 0x%llx\n",
> + filesz, memsz);
> + ret = -EINVAL;
> + break;
> + }
> +
> + if (offset + filesz > fw->size) {
> + dev_err(dev, "truncated fw: need 0x%llx avail 0x%zx\n",
> + offset + filesz, fw->size);
> + ret = -EINVAL;
> + break;
> + }
> +
> + if (!rproc_u64_fit_in_size_t(memsz)) {
> + dev_err(dev, "size (%llx) does not fit in size_t 
> type\n",
> + memsz);
> + ret = -EOVERFLOW;
> + break;
> + }
> +
> + /* grab the kernel address for this device address */
> + ptr = rproc_da_to_va(rproc, da, memsz);
> + if (!ptr) {
> + dev_err(dev, "bad phdr da 0x%llx mem 0x%llx\n", da,
> + memsz);
> + ret = -EINVAL;
> + break;
> + }
> +
> + /* put the segment where the remote processor expects it */
> + if (filesz)
> + memcpy_toio(ptr, elf_data + offset, filesz);
> + }
> +
> + return ret;
> +}
> +
>  static const struct rproc_ops imx_rproc_ops = {
>   .start  = imx_rproc_start,
>   .stop   = imx_rproc_stop,
>   .da_to_va   = imx_rproc_da_to_va,
> + .load   = imx_rproc_elf_load_segments,
> + .parse_fw   = rproc_elf_load_rsc_table,
> + 

Re: [PATCH v2] net: ipv6: fix use-after-free Read in __xfrm6_tunnel_spi_lookup

2020-07-26 Thread B K Karthik
On Mon, Jul 27, 2020 at 1:37 AM Cong Wang  wrote:
>
> On Sat, Jul 25, 2020 at 11:12 PM B K Karthik  wrote:
> >
> > On Sun, Jul 26, 2020 at 11:05 AM Cong Wang  wrote:
> > >
> > > On Sat, Jul 25, 2020 at 8:09 PM B K Karthik  
> > > wrote:
> > > > @@ -103,10 +103,10 @@ static int __xfrm6_tunnel_spi_check(struct net 
> > > > *net, u32 spi)
> > > >  {
> > > > struct xfrm6_tunnel_net *xfrm6_tn = xfrm6_tunnel_pernet(net);
> > > > struct xfrm6_tunnel_spi *x6spi;
> > > > -   int index = xfrm6_tunnel_spi_hash_byspi(spi);
> > > > +   int index = xfrm6_tunnel_spi_hash_byaddr((const xfrm_address_t 
> > > > *)spi);
> > > >
> > > > hlist_for_each_entry(x6spi,
> > > > -&xfrm6_tn->spi_byspi[index],
> > > > +&xfrm6_tn->spi_byaddr[index],
> > > >  list_byspi) {
> > > > if (x6spi->spi == spi)
> > >
> > > How did you convince yourself this is correct? This lookup is still
> > > using spi. :)
> >
> > I'm sorry, but my intention behind writing this patch was not to fix
> > the UAF, but to fix a slab-out-of-bound.
>
> Odd, your $subject is clearly UAF, so is the stack trace in your changelog.
> :)
>
>
> > If required, I can definitely change the subject line and resend the
> > patch, but I figured this was correct for
> > https://syzkaller.appspot.com/bug?id=058d05f470583ab2843b1d6785fa8d0658ef66ae
> > . since that particular report did not have a reproducer,
> > Dmitry Vyukov  suggested that I test this patch on
> > other reports for xfrm/spi .
>
> You have to change it to avoid misleading.

I will do that once somebody tells me this patch is reasonable to
avoid wasting people's time.
>
> >
> > Forgive me if this was the wrong way to send a patch for that
> > particular report, but I guessed since the reproducer did not trigger
> > the crash
> > for UAF, I would leave the subject line as 'fix UAF' :)
> >
> > xfrm6_spi_hash_by_hash seemed more convincing because I had to prevent
> > a slab-out-of-bounds because it uses ipv6_addr_hash.
> > It would be of great help if you could help me understand how this was
> > able to fix a UAF.
>
> Sure, you just avoid a pointer deref, which of course can fix the UAF,
> but I still don't think it is correct in any aspect.

I saw a function call being made to tomoyo_check_acl(). the next thing
happening is a kfree().
Also, spi_hash_byspi just returns spi % XFRM6_TUNNEL_SPI_BYSPI_HSIZE .

I'm a mentee, hence I would say my knowledge is very limited, please
let me know if I am making a horrible mistake somewhere,
but return (__force u32)(a->s6_addr32[0] ^ a->s6_addr32[1] ^
a->s6_addr32[2] ^ a->s6_addr32[3]); seems like a better because
as David S. Miller  said "It is doing a XOR on
all bits of an IPv6 address, it is doing more bit shifting which the
existing hash was ignoring" .

Please help me understand this better if I am going wrong.

>
> Even if it is a OOB, you still have to explain why it happened. Once
> again, I can't see how it could happen either.
>
> >
> > >
> > > More importantly, can you explain how UAF happens? Apparently
> > > the syzbot stack traces you quote make no sense at all. I also
> > > looked at other similar reports, none of them makes sense to me.
> >
> > Forgive me, but I do not understand what you mean by the stack traces
> > (this or other similar reports) "make no sense".
>
> Because the stack trace in your changelog clearly shows it is allocated
> in tomoyo_init_log(), which is a buffer in struct tomoyo_query, but
> none of xfrm paths uses it. Or do you see anything otherwise?

Aren't there indirect inet calls and netfilter hooks? I'm sorry I do
not see anything otherwise.
Please help me understand.

thanks,

karthik


[PATCH v4 10/10] powerpc/smp: Implement cpu_to_coregroup_id

2020-07-26 Thread Srikar Dronamraju
Lookup the coregroup id from the associativity array.

If unable to detect the coregroup id, fallback on the core id.
This way, ensure sched_domain degenerates and an extra sched domain is
not created.

Ideally this function should have been implemented in
arch/powerpc/kernel/smp.c. However if its implemented in mm/numa.c, we
don't need to find the primary domain again.

If the device-tree mentions more than one coregroup, then kernel
implements only the last or the smallest coregroup, which currently
corresponds to the penultimate domain in the device-tree.

Cc: linuxppc-dev 
Cc: LKML 
Cc: Michael Ellerman 
Cc: Nicholas Piggin 
Cc: Anton Blanchard 
Cc: Oliver O'Halloran 
Cc: Nathan Lynch 
Cc: Michael Neuling 
Cc: Gautham R Shenoy 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Valentin Schneider 
Cc: Jordan Niethe 
Reviewed-by : Gautham R. Shenoy 
Signed-off-by: Srikar Dronamraju 
---
Changelog v1 -> v2:
Move coregroup_enabled before getting associativity (Gautham)

 arch/powerpc/mm/numa.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 0d57779e7942..8b3b3ec7fcc4 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -1218,6 +1218,26 @@ int find_and_online_cpu_nid(int cpu)
 
 int cpu_to_coregroup_id(int cpu)
 {
+   __be32 associativity[VPHN_ASSOC_BUFSIZE] = {0};
+   int index;
+
+   if (cpu < 0 || cpu > nr_cpu_ids)
+   return -1;
+
+   if (!coregroup_enabled)
+   goto out;
+
+   if (!firmware_has_feature(FW_FEATURE_VPHN))
+   goto out;
+
+   if (vphn_get_associativity(cpu, associativity))
+   goto out;
+
+   index = of_read_number(associativity, 1);
+   if (index > min_common_depth + 1)
+   return of_read_number(&associativity[index - 1], 1);
+
+out:
return cpu_to_core_id(cpu);
 }
 
-- 
2.17.1



[PATCH v4 02/10] powerpc/smp: Merge Power9 topology with Power topology

2020-07-26 Thread Srikar Dronamraju
A new sched_domain_topology_level was added just for Power9. However the
same can be achieved by merging powerpc_topology with power9_topology
and makes the code more simpler especially when adding a new sched
domain.

Cc: linuxppc-dev 
Cc: LKML 
Cc: Michael Ellerman 
Cc: Nicholas Piggin 
Cc: Anton Blanchard 
Cc: Oliver O'Halloran 
Cc: Nathan Lynch 
Cc: Michael Neuling 
Cc: Gautham R Shenoy 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Valentin Schneider 
Cc: Jordan Niethe 
Reviewed-by: Gautham R. Shenoy 
Signed-off-by: Srikar Dronamraju 
---
Changelog v1 -> v2:
Replaced a reference to cpu_smt_mask with per_cpu(cpu_sibling_map, cpu)
since cpu_smt_mask is only defined under CONFIG_SCHED_SMT

 arch/powerpc/kernel/smp.c | 33 ++---
 1 file changed, 10 insertions(+), 23 deletions(-)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index edf94ca64eea..283a04e54f52 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -1313,7 +1313,7 @@ int setup_profiling_timer(unsigned int multiplier)
 }
 
 #ifdef CONFIG_SCHED_SMT
-/* cpumask of CPUs with asymetric SMT dependancy */
+/* cpumask of CPUs with asymmetric SMT dependency */
 static int powerpc_smt_flags(void)
 {
int flags = SD_SHARE_CPUCAPACITY | SD_SHARE_PKG_RESOURCES;
@@ -1326,14 +1326,6 @@ static int powerpc_smt_flags(void)
 }
 #endif
 
-static struct sched_domain_topology_level powerpc_topology[] = {
-#ifdef CONFIG_SCHED_SMT
-   { cpu_smt_mask, powerpc_smt_flags, SD_INIT_NAME(SMT) },
-#endif
-   { cpu_cpu_mask, SD_INIT_NAME(DIE) },
-   { NULL, },
-};
-
 /*
  * P9 has a slightly odd architecture where pairs of cores share an L2 cache.
  * This topology makes it *much* cheaper to migrate tasks between adjacent 
cores
@@ -1351,7 +1343,13 @@ static int powerpc_shared_cache_flags(void)
  */
 static const struct cpumask *shared_cache_mask(int cpu)
 {
-   return cpu_l2_cache_mask(cpu);
+   if (shared_caches)
+   return cpu_l2_cache_mask(cpu);
+
+   if (has_big_cores)
+   return cpu_smallcore_mask(cpu);
+
+   return per_cpu(cpu_sibling_map, cpu);
 }
 
 #ifdef CONFIG_SCHED_SMT
@@ -1361,7 +1359,7 @@ static const struct cpumask *smallcore_smt_mask(int cpu)
 }
 #endif
 
-static struct sched_domain_topology_level power9_topology[] = {
+static struct sched_domain_topology_level powerpc_topology[] = {
 #ifdef CONFIG_SCHED_SMT
{ cpu_smt_mask, powerpc_smt_flags, SD_INIT_NAME(SMT) },
 #endif
@@ -1386,21 +1384,10 @@ void __init smp_cpus_done(unsigned int max_cpus)
 #ifdef CONFIG_SCHED_SMT
if (has_big_cores) {
pr_info("Big cores detected but using small core scheduling\n");
-   power9_topology[0].mask = smallcore_smt_mask;
powerpc_topology[0].mask = smallcore_smt_mask;
}
 #endif
-   /*
-* If any CPU detects that it's sharing a cache with another CPU then
-* use the deeper topology that is aware of this sharing.
-*/
-   if (shared_caches) {
-   pr_info("Using shared cache scheduler topology\n");
-   set_sched_topology(power9_topology);
-   } else {
-   pr_info("Using standard scheduler topology\n");
-   set_sched_topology(powerpc_topology);
-   }
+   set_sched_topology(powerpc_topology);
 }
 
 #ifdef CONFIG_HOTPLUG_CPU
-- 
2.17.1



[PATCH v4 08/10] powerpc/smp: Allocate cpumask only after searching thread group

2020-07-26 Thread Srikar Dronamraju
If allocated earlier and the search fails, then cpumask need to be
freed. However cpu_l1_cache_map can be allocated after we search thread
group.

Cc: linuxppc-dev 
Cc: LKML 
Cc: Michael Ellerman 
Cc: Nicholas Piggin 
Cc: Anton Blanchard 
Cc: Oliver O'Halloran 
Cc: Nathan Lynch 
Cc: Michael Neuling 
Cc: Gautham R Shenoy 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Valentin Schneider 
Cc: Jordan Niethe 
Reviewed-by: Gautham R. Shenoy 
Signed-off-by: Srikar Dronamraju 
---
 arch/powerpc/kernel/smp.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index 698000c7f76f..dab96a1203ec 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -797,10 +797,6 @@ static int init_cpu_l1_cache_map(int cpu)
if (err)
goto out;
 
-   zalloc_cpumask_var_node(&per_cpu(cpu_l1_cache_map, cpu),
-   GFP_KERNEL,
-   cpu_to_node(cpu));
-
cpu_group_start = get_cpu_thread_group_start(cpu, &tg);
 
if (unlikely(cpu_group_start == -1)) {
@@ -809,6 +805,9 @@ static int init_cpu_l1_cache_map(int cpu)
goto out;
}
 
+   zalloc_cpumask_var_node(&per_cpu(cpu_l1_cache_map, cpu),
+   GFP_KERNEL, cpu_to_node(cpu));
+
for (i = first_thread; i < first_thread + threads_per_core; i++) {
int i_group_start = get_cpu_thread_group_start(i, &tg);
 
-- 
2.17.1



[PATCH v4 06/10] powerpc/smp: Generalize 2nd sched domain

2020-07-26 Thread Srikar Dronamraju
Currently "CACHE" domain happens to be the 2nd sched domain as per
powerpc_topology. This domain will collapse if cpumask of l2-cache is
same as SMT domain. However we could generalize this domain such that it
could mean either be a "CACHE" domain or a "BIGCORE" domain.

While setting up the "CACHE" domain, check if shared_cache is already
set.

Cc: linuxppc-dev 
Cc: LKML 
Cc: Michael Ellerman 
Cc: Nicholas Piggin 
Cc: Anton Blanchard 
Cc: Oliver O'Halloran 
Cc: Nathan Lynch 
Cc: Michael Neuling 
Cc: Gautham R Shenoy 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Valentin Schneider 
Cc: Jordan Niethe 
Signed-off-by: Srikar Dronamraju 
---
Changelog v1 -> v2:
Moved shared_cache topology fixup to fixup_topology (Gautham)

 arch/powerpc/kernel/smp.c | 49 ---
 1 file changed, 35 insertions(+), 14 deletions(-)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index d997c7411664..3c5ccf6d2b1c 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -85,6 +85,14 @@ EXPORT_PER_CPU_SYMBOL(cpu_l2_cache_map);
 EXPORT_PER_CPU_SYMBOL(cpu_core_map);
 EXPORT_SYMBOL_GPL(has_big_cores);
 
+enum {
+#ifdef CONFIG_SCHED_SMT
+   smt_idx,
+#endif
+   bigcore_idx,
+   die_idx,
+};
+
 #define MAX_THREAD_LIST_SIZE   8
 #define THREAD_GROUP_SHARE_L1   1
 struct thread_groups {
@@ -851,13 +859,7 @@ static int powerpc_shared_cache_flags(void)
  */
 static const struct cpumask *shared_cache_mask(int cpu)
 {
-   if (shared_caches)
-   return cpu_l2_cache_mask(cpu);
-
-   if (has_big_cores)
-   return cpu_smallcore_mask(cpu);
-
-   return per_cpu(cpu_sibling_map, cpu);
+   return per_cpu(cpu_l2_cache_map, cpu);
 }
 
 #ifdef CONFIG_SCHED_SMT
@@ -867,11 +869,16 @@ static const struct cpumask *smallcore_smt_mask(int cpu)
 }
 #endif
 
+static const struct cpumask *cpu_bigcore_mask(int cpu)
+{
+   return per_cpu(cpu_sibling_map, cpu);
+}
+
 static struct sched_domain_topology_level powerpc_topology[] = {
 #ifdef CONFIG_SCHED_SMT
{ cpu_smt_mask, powerpc_smt_flags, SD_INIT_NAME(SMT) },
 #endif
-   { shared_cache_mask, powerpc_shared_cache_flags, SD_INIT_NAME(CACHE) },
+   { cpu_bigcore_mask, SD_INIT_NAME(BIGCORE) },
{ cpu_cpu_mask, SD_INIT_NAME(DIE) },
{ NULL, },
 };
@@ -1311,7 +1318,6 @@ static void add_cpu_to_masks(int cpu)
 void start_secondary(void *unused)
 {
unsigned int cpu = smp_processor_id();
-   struct cpumask *(*sibling_mask)(int) = cpu_sibling_mask;
 
mmgrab(&init_mm);
current->active_mm = &init_mm;
@@ -1337,14 +1343,20 @@ void start_secondary(void *unused)
/* Update topology CPU masks */
add_cpu_to_masks(cpu);
 
-   if (has_big_cores)
-   sibling_mask = cpu_smallcore_mask;
/*
 * Check for any shared caches. Note that this must be done on a
 * per-core basis because one core in the pair might be disabled.
 */
-   if (!cpumask_equal(cpu_l2_cache_mask(cpu), sibling_mask(cpu)))
-   shared_caches = true;
+   if (!shared_caches) {
+   struct cpumask *(*sibling_mask)(int) = cpu_sibling_mask;
+   struct cpumask *mask = cpu_l2_cache_mask(cpu);
+
+   if (has_big_cores)
+   sibling_mask = cpu_smallcore_mask;
+
+   if (cpumask_weight(mask) > cpumask_weight(sibling_mask(cpu)))
+   shared_caches = true;
+   }
 
set_numa_node(numa_cpu_lookup_table[cpu]);
set_numa_mem(local_memory_node(numa_cpu_lookup_table[cpu]));
@@ -1375,9 +1387,17 @@ static void fixup_topology(void)
 #ifdef CONFIG_SCHED_SMT
if (has_big_cores) {
pr_info("Big cores detected but using small core scheduling\n");
-   powerpc_topology[0].mask = smallcore_smt_mask;
+   powerpc_topology[smt_idx].mask = smallcore_smt_mask;
}
 #endif
+   if (shared_caches) {
+   pr_info("Using shared cache scheduler topology\n");
+   powerpc_topology[bigcore_idx].mask = shared_cache_mask;
+   powerpc_topology[bigcore_idx].sd_flags = 
powerpc_shared_cache_flags;
+#ifdef CONFIG_SCHED_DEBUG
+   powerpc_topology[bigcore_idx].name = "CACHE";
+#endif
+   }
 }
 
 void __init smp_cpus_done(unsigned int max_cpus)
-- 
2.17.1



[PATCH v4 09/10] Powerpc/smp: Create coregroup domain

2020-07-26 Thread Srikar Dronamraju
Add percpu coregroup maps and masks to create coregroup domain.
If a coregroup doesn't exist, the coregroup domain will be degenerated
in favour of SMT/CACHE domain.

Cc: linuxppc-dev 
Cc: LKML 
Cc: Michael Ellerman 
Cc: Nicholas Piggin 
Cc: Anton Blanchard 
Cc: Oliver O'Halloran 
Cc: Nathan Lynch 
Cc: Michael Neuling 
Cc: Gautham R Shenoy 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Valentin Schneider 
Cc: Jordan Niethe 
Signed-off-by: Srikar Dronamraju 
---
Changelog v3 ->v4:
if coregroup_support doesn't exist, update MC mask to the next
smaller domain mask.

Changelog v2 -> v3:
Add optimization for mask updation under coregroup_support

Changelog v1 -> v2:
Moved coregroup topology fixup to fixup_topology (Gautham)

 arch/powerpc/include/asm/topology.h | 10 ++
 arch/powerpc/kernel/smp.c   | 48 +
 arch/powerpc/mm/numa.c  |  5 +++
 3 files changed, 63 insertions(+)

diff --git a/arch/powerpc/include/asm/topology.h 
b/arch/powerpc/include/asm/topology.h
index f0b6300e7dd3..6609174918ab 100644
--- a/arch/powerpc/include/asm/topology.h
+++ b/arch/powerpc/include/asm/topology.h
@@ -88,12 +88,22 @@ static inline int cpu_distance(__be32 *cpu1_assoc, __be32 
*cpu2_assoc)
 
 #if defined(CONFIG_NUMA) && defined(CONFIG_PPC_SPLPAR)
 extern int find_and_online_cpu_nid(int cpu);
+extern int cpu_to_coregroup_id(int cpu);
 #else
 static inline int find_and_online_cpu_nid(int cpu)
 {
return 0;
 }
 
+static inline int cpu_to_coregroup_id(int cpu)
+{
+#ifdef CONFIG_SMP
+   return cpu_to_core_id(cpu);
+#else
+   return 0;
+#endif
+}
+
 #endif /* CONFIG_NUMA && CONFIG_PPC_SPLPAR */
 
 #include 
diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index dab96a1203ec..95f0bf72e283 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -80,6 +80,7 @@ DEFINE_PER_CPU(cpumask_var_t, cpu_sibling_map);
 DEFINE_PER_CPU(cpumask_var_t, cpu_smallcore_map);
 DEFINE_PER_CPU(cpumask_var_t, cpu_l2_cache_map);
 DEFINE_PER_CPU(cpumask_var_t, cpu_core_map);
+DEFINE_PER_CPU(cpumask_var_t, cpu_coregroup_map);
 
 EXPORT_PER_CPU_SYMBOL(cpu_sibling_map);
 EXPORT_PER_CPU_SYMBOL(cpu_l2_cache_map);
@@ -91,6 +92,7 @@ enum {
smt_idx,
 #endif
bigcore_idx,
+   mc_idx,
die_idx,
 };
 
@@ -869,6 +871,21 @@ static const struct cpumask *smallcore_smt_mask(int cpu)
 }
 #endif
 
+static struct cpumask *cpu_coregroup_mask(int cpu)
+{
+   return per_cpu(cpu_coregroup_map, cpu);
+}
+
+static bool has_coregroup_support(void)
+{
+   return coregroup_enabled;
+}
+
+static const struct cpumask *cpu_mc_mask(int cpu)
+{
+   return cpu_coregroup_mask(cpu);
+}
+
 static const struct cpumask *cpu_bigcore_mask(int cpu)
 {
return per_cpu(cpu_sibling_map, cpu);
@@ -879,6 +896,7 @@ static struct sched_domain_topology_level 
powerpc_topology[] = {
{ cpu_smt_mask, powerpc_smt_flags, SD_INIT_NAME(SMT) },
 #endif
{ cpu_bigcore_mask, SD_INIT_NAME(BIGCORE) },
+   { cpu_mc_mask, SD_INIT_NAME(MC) },
{ cpu_cpu_mask, SD_INIT_NAME(DIE) },
{ NULL, },
 };
@@ -925,6 +943,10 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
GFP_KERNEL, cpu_to_node(cpu));
zalloc_cpumask_var_node(&per_cpu(cpu_core_map, cpu),
GFP_KERNEL, cpu_to_node(cpu));
+   if (has_coregroup_support())
+   zalloc_cpumask_var_node(&per_cpu(cpu_coregroup_map, 
cpu),
+   GFP_KERNEL, cpu_to_node(cpu));
+
 #ifdef CONFIG_NEED_MULTIPLE_NODES
/*
 * numa_node_id() works after this.
@@ -942,6 +964,9 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
cpumask_set_cpu(boot_cpuid, cpu_l2_cache_mask(boot_cpuid));
cpumask_set_cpu(boot_cpuid, cpu_core_mask(boot_cpuid));
 
+   if (has_coregroup_support())
+   cpumask_set_cpu(boot_cpuid, cpu_coregroup_mask(boot_cpuid));
+
init_big_cores();
if (has_big_cores) {
cpumask_set_cpu(boot_cpuid,
@@ -1233,6 +1258,8 @@ static void remove_cpu_from_masks(int cpu)
set_cpus_unrelated(cpu, i, cpu_sibling_mask);
if (has_big_cores)
set_cpus_unrelated(cpu, i, cpu_smallcore_mask);
+   if (has_coregroup_support())
+   set_cpus_unrelated(cpu, i, cpu_coregroup_mask);
}
 }
 #endif
@@ -1293,6 +1320,20 @@ static void add_cpu_to_masks(int cpu)
add_cpu_to_smallcore_masks(cpu);
update_mask_by_l2(cpu, cpu_l2_cache_mask);
 
+   if (has_coregroup_support()) {
+   int coregroup_id = cpu_to_coregroup_id(cpu);
+
+   cpumask_set_cpu(cpu, cpu_coregroup_mask(cpu));
+   for_each_cpu_and(i, cpu_online_mask, cpu_cpu_mask(cpu)) {
+   int fcpu = cpu_first_thread_sibling(i);
+
+ 

[PATCH v4 04/10] powerpc/smp: Move topology fixups into a new function

2020-07-26 Thread Srikar Dronamraju
Move topology fixup based on the platform attributes into its own
function which is called just before set_sched_topology.

Cc: linuxppc-dev 
Cc: LKML 
Cc: Michael Ellerman 
Cc: Nicholas Piggin 
Cc: Anton Blanchard 
Cc: Oliver O'Halloran 
Cc: Nathan Lynch 
Cc: Michael Neuling 
Cc: Gautham R Shenoy 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Valentin Schneider 
Cc: Jordan Niethe 
Reviewed-by: Gautham R. Shenoy 
Signed-off-by: Srikar Dronamraju 
---
Changelog v2 -> v3:
Rewrote changelog (Gautham)
Renamed to powerpc/smp: Move topology fixups into  a new function

 arch/powerpc/kernel/smp.c | 17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index a685915e5941..da27f6909be1 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -1368,6 +1368,16 @@ int setup_profiling_timer(unsigned int multiplier)
return 0;
 }
 
+static void fixup_topology(void)
+{
+#ifdef CONFIG_SCHED_SMT
+   if (has_big_cores) {
+   pr_info("Big cores detected but using small core scheduling\n");
+   powerpc_topology[0].mask = smallcore_smt_mask;
+   }
+#endif
+}
+
 void __init smp_cpus_done(unsigned int max_cpus)
 {
/*
@@ -1381,12 +1391,7 @@ void __init smp_cpus_done(unsigned int max_cpus)
 
dump_numa_cpu_topology();
 
-#ifdef CONFIG_SCHED_SMT
-   if (has_big_cores) {
-   pr_info("Big cores detected but using small core scheduling\n");
-   powerpc_topology[0].mask = smallcore_smt_mask;
-   }
-#endif
+   fixup_topology();
set_sched_topology(powerpc_topology);
 }
 
-- 
2.17.1



[PATCH v4 00/10] Coregroup support on Powerpc

2020-07-26 Thread Srikar Dronamraju
Changelog v3 ->v4:
v3: 
https://lore.kernel.org/lkml/20200723085116.4731-1-sri...@linux.vnet.ibm.com/t/#u

powerpc/smp: Create coregroup domain
if coregroup_support doesn't exist, update MC mask to the next
smaller domain mask.

Changelog v2 -> v3:
v2: 
https://lore.kernel.org/linuxppc-dev/20200721113814.32284-1-sri...@linux.vnet.ibm.com/t/#u

powerpc/smp: Cache node for reuse
Removed node caching part. Rewrote the Commit msg (Michael Ellerman)
Renamed to powerpc/smp: Fix a warning under !NEED_MULTIPLE_NODES

powerpc/smp: Enable small core scheduling sooner
Rewrote changelog (Gautham)
Renamed to powerpc/smp: Move topology fixups into  a new function

powerpc/smp: Create coregroup domain
Add optimization for mask updation under coregroup_support

Changelog v1 -> v2:
v1: 
https://lore.kernel.org/linuxppc-dev/20200714043624.5648-1-sri...@linux.vnet.ibm.com/t/#u

powerpc/smp: Merge Power9 topology with Power topology
Replaced a reference to cpu_smt_mask with per_cpu(cpu_sibling_map, cpu)
since cpu_smt_mask is only defined under CONFIG_SCHED_SMT

powerpc/smp: Enable small core scheduling sooner
Restored the previous info msg (Jordan)
Moved big core topology fixup to fixup_topology (Gautham)

powerpc/smp: Dont assume l2-cache to be superset of sibling
Set cpumask after verifying l2-cache. (Gautham)

powerpc/smp: Generalize 2nd sched domain
Moved shared_cache topology fixup to fixup_topology (Gautham)

Powerpc/numa: Detect support for coregroup
Explained Coregroup in commit msg (Michael Ellerman)

Powerpc/smp: Create coregroup domain
Moved coregroup topology fixup to fixup_topology (Gautham)

powerpc/smp: Implement cpu_to_coregroup_id
Move coregroup_enabled before getting associativity (Gautham)

powerpc/smp: Provide an ability to disable coregroup
Patch dropped (Michael Ellerman)

Cleanup of existing powerpc topologies and add coregroup support on
Powerpc. Coregroup is a group of (subset of) cores of a DIE that share
a resource.

Patch 7 of this patch series: "Powerpc/numa: Detect support for coregroup"
depends on
https://lore.kernel.org/linuxppc-dev/20200707140644.7241-1-sri...@linux.vnet.ibm.com/t/#u
However it should be easy to rebase the patch without the above patch.

This patch series is based on top of current powerpc/next tree + the
above patch.

On Power 8 Systems
--
$ tail /proc/cpuinfo
processor   : 255
cpu : POWER8 (architected), altivec supported
clock   : 3724.00MHz
revision: 2.1 (pvr 004b 0201)

timebase: 51200
platform: pSeries
model   : IBM,8408-E8E
machine : CHRP IBM,8408-E8E
MMU : Hash

Before the patchset
---
$ cat /proc/sys/kernel/sched_domain/cpu0/domain*/name
SMT
DIE
NUMA
NUMA
$ head /proc/schedstat
version 15
timestamp 4295534931
cpu0 0 0 0 0 0 0 41389823338 17682779896 14117
domain0 ,,,,,,,00ff 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
domain1 ,,,,,,, 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
domain2 ,,,,,,, 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
domain3 ,,,,,,, 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
cpu1 0 0 0 0 0 0 27087859050 152273672 10396
domain0 ,,,,,,,00ff 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
domain1 ,,,,,,, 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

After the patchset
--
$ cat /proc/sys/kernel/sched_domain/cpu0/domain*/name
SMT
DIE
NUMA
NUMA
$ head /proc/schedstat
version 15
timestamp 4295534931
cpu0 0 0 0 0 0 0 41389823338 17682779896 14117
domain0 ,,,,,,,00ff 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
domain1 ,,,,,,, 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
domain2 ,,,,,,, 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
domain3 ,,,,,,, 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
cpu1 0 0 0 0 0 0 27087859050 152273672 10396
domain0 ,,,,,,,00ff 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
domain1 ,0

[PATCH v4 05/10] powerpc/smp: Dont assume l2-cache to be superset of sibling

2020-07-26 Thread Srikar Dronamraju
Current code assumes that cpumask of cpus sharing a l2-cache mask will
always be a superset of cpu_sibling_mask.

Lets stop that assumption. cpu_l2_cache_mask is a superset of
cpu_sibling_mask if and only if shared_caches is set.

Cc: linuxppc-dev 
Cc: LKML 
Cc: Michael Ellerman 
Cc: Nicholas Piggin 
Cc: Anton Blanchard 
Cc: Oliver O'Halloran 
Cc: Nathan Lynch 
Cc: Michael Neuling 
Cc: Gautham R Shenoy 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Valentin Schneider 
Cc: Jordan Niethe 
Reviewed-by: Gautham R. Shenoy 
Signed-off-by: Srikar Dronamraju 
---
Changelog v1 -> v2:
Set cpumask after verifying l2-cache. (Gautham)

 arch/powerpc/kernel/smp.c | 28 +++-
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index da27f6909be1..d997c7411664 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -1194,6 +1194,7 @@ static bool update_mask_by_l2(int cpu, struct cpumask 
*(*mask_fn)(int))
if (!l2_cache)
return false;
 
+   cpumask_set_cpu(cpu, mask_fn(cpu));
for_each_cpu(i, cpu_online_mask) {
/*
 * when updating the marks the current CPU has not been marked
@@ -1276,29 +1277,30 @@ static void add_cpu_to_masks(int cpu)
 * add it to it's own thread sibling mask.
 */
cpumask_set_cpu(cpu, cpu_sibling_mask(cpu));
+   cpumask_set_cpu(cpu, cpu_core_mask(cpu));
 
for (i = first_thread; i < first_thread + threads_per_core; i++)
if (cpu_online(i))
set_cpus_related(i, cpu, cpu_sibling_mask);
 
add_cpu_to_smallcore_masks(cpu);
-   /*
-* Copy the thread sibling mask into the cache sibling mask
-* and mark any CPUs that share an L2 with this CPU.
-*/
-   for_each_cpu(i, cpu_sibling_mask(cpu))
-   set_cpus_related(cpu, i, cpu_l2_cache_mask);
update_mask_by_l2(cpu, cpu_l2_cache_mask);
 
-   /*
-* Copy the cache sibling mask into core sibling mask and mark
-* any CPUs on the same chip as this CPU.
-*/
-   for_each_cpu(i, cpu_l2_cache_mask(cpu))
-   set_cpus_related(cpu, i, cpu_core_mask);
+   if (pkg_id == -1) {
+   struct cpumask *(*mask)(int) = cpu_sibling_mask;
+
+   /*
+* Copy the sibling mask into core sibling mask and
+* mark any CPUs on the same chip as this CPU.
+*/
+   if (shared_caches)
+   mask = cpu_l2_cache_mask;
+
+   for_each_cpu(i, mask(cpu))
+   set_cpus_related(cpu, i, cpu_core_mask);
 
-   if (pkg_id == -1)
return;
+   }
 
for_each_cpu(i, cpu_online_mask)
if (get_physical_package_id(i) == pkg_id)
-- 
2.17.1



[PATCH v4 07/10] Powerpc/numa: Detect support for coregroup

2020-07-26 Thread Srikar Dronamraju
Add support for grouping cores based on the device-tree classification.
- The last domain in the associativity domains always refers to the
core.
- If primary reference domain happens to be the penultimate domain in
the associativity domains device-tree property, then there are no
coregroups. However if its not a penultimate domain, then there are
coregroups. There can be more than one coregroup. For now we would be
interested in the last or the smallest coregroups.

Cc: linuxppc-dev 
Cc: LKML 
Cc: Michael Ellerman 
Cc: Nicholas Piggin 
Cc: Anton Blanchard 
Cc: Oliver O'Halloran 
Cc: Nathan Lynch 
Cc: Michael Neuling 
Cc: Gautham R Shenoy 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Valentin Schneider 
Cc: Jordan Niethe 
Reviewed-by: Gautham R. Shenoy 
Signed-off-by: Srikar Dronamraju 
---
Changelog v1 -> v2:
Explained Coregroup in commit msg (Michael Ellerman)

 arch/powerpc/include/asm/smp.h |  1 +
 arch/powerpc/kernel/smp.c  |  1 +
 arch/powerpc/mm/numa.c | 34 +-
 3 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
index 49a25e2400f2..5bdc17a7049f 100644
--- a/arch/powerpc/include/asm/smp.h
+++ b/arch/powerpc/include/asm/smp.h
@@ -28,6 +28,7 @@
 extern int boot_cpuid;
 extern int spinning_secondaries;
 extern u32 *cpu_to_phys_id;
+extern bool coregroup_enabled;
 
 extern void cpu_die(void);
 extern int cpu_to_chip_id(int cpu);
diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index 3c5ccf6d2b1c..698000c7f76f 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -74,6 +74,7 @@ static DEFINE_PER_CPU(int, cpu_state) = { 0 };
 
 struct task_struct *secondary_current;
 bool has_big_cores;
+bool coregroup_enabled;
 
 DEFINE_PER_CPU(cpumask_var_t, cpu_sibling_map);
 DEFINE_PER_CPU(cpumask_var_t, cpu_smallcore_map);
diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 2298899a0f0a..51cb672f113b 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -886,7 +886,9 @@ static void __init setup_node_data(int nid, u64 start_pfn, 
u64 end_pfn)
 static void __init find_possible_nodes(void)
 {
struct device_node *rtas;
-   u32 numnodes, i;
+   const __be32 *domains;
+   int prop_length, max_nodes;
+   u32 i;
 
if (!numa_enabled)
return;
@@ -895,25 +897,31 @@ static void __init find_possible_nodes(void)
if (!rtas)
return;
 
-   if (of_property_read_u32_index(rtas, 
"ibm,current-associativity-domains",
-   min_common_depth, &numnodes)) {
-   /*
-* ibm,current-associativity-domains is a fairly recent
-* property. If it doesn't exist, then fallback on
-* ibm,max-associativity-domains. Current denotes what the
-* platform can support compared to max which denotes what the
-* Hypervisor can support.
-*/
-   if (of_property_read_u32_index(rtas, 
"ibm,max-associativity-domains",
-   min_common_depth, &numnodes))
+   /*
+* ibm,current-associativity-domains is a fairly recent property. If
+* it doesn't exist, then fallback on ibm,max-associativity-domains.
+* Current denotes what the platform can support compared to max
+* which denotes what the Hypervisor can support.
+*/
+   domains = of_get_property(rtas, "ibm,current-associativity-domains",
+   &prop_length);
+   if (!domains) {
+   domains = of_get_property(rtas, "ibm,max-associativity-domains",
+   &prop_length);
+   if (!domains)
goto out;
}
 
-   for (i = 0; i < numnodes; i++) {
+   max_nodes = of_read_number(&domains[min_common_depth], 1);
+   for (i = 0; i < max_nodes; i++) {
if (!node_possible(i))
node_set(i, node_possible_map);
}
 
+   prop_length /= sizeof(int);
+   if (prop_length > min_common_depth + 2)
+   coregroup_enabled = 1;
+
 out:
of_node_put(rtas);
 }
-- 
2.17.1



[PATCH] ARC: perf: don't bail setup if pct irq missing in device-tree

2020-07-26 Thread Vineet Gupta
Current code inadventely bails if hardware supports sampling/overflow
interrupts, but the irq is missing from device tree. This need not be as
we can still do simple counting based perf stat.

This unborks perf on HSDK-4xD

Signed-off-by: Vineet Gupta 
---
 arch/arc/kernel/perf_event.c | 14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/arch/arc/kernel/perf_event.c b/arch/arc/kernel/perf_event.c
index 661fd842ea97..79849f37e782 100644
--- a/arch/arc/kernel/perf_event.c
+++ b/arch/arc/kernel/perf_event.c
@@ -562,7 +562,7 @@ static int arc_pmu_device_probe(struct platform_device 
*pdev)
 {
struct arc_reg_pct_build pct_bcr;
struct arc_reg_cc_build cc_bcr;
-   int i, has_interrupts;
+   int i, has_interrupts, irq;
int counter_size;   /* in bits */
 
union cc_name {
@@ -637,13 +637,7 @@ static int arc_pmu_device_probe(struct platform_device 
*pdev)
.attr_groups= arc_pmu->attr_groups,
};
 
-   if (has_interrupts) {
-   int irq = platform_get_irq(pdev, 0);
-
-   if (irq < 0) {
-   pr_err("Cannot get IRQ number for the platform\n");
-   return -ENODEV;
-   }
+   if (has_interrupts && (irq = platform_get_irq(pdev, 0) >= 0)) {
 
arc_pmu->irq = irq;
 
@@ -652,9 +646,9 @@ static int arc_pmu_device_probe(struct platform_device 
*pdev)
   this_cpu_ptr(&arc_pmu_cpu));
 
on_each_cpu(arc_cpu_pmu_irq_init, &irq, 1);
-
-   } else
+   } else {
arc_pmu->pmu.capabilities |= PERF_PMU_CAP_NO_INTERRUPT;
+   }
 
/*
 * perf parser doesn't really like '-' symbol in events name, so let's
-- 
2.20.1



[RESEND 3/3] ASoC: max98390: update dsm param bin max size

2020-07-26 Thread Steve Lee
 MAX98390_DSM_PARAM_MAX_SIZE is changed to support extended
 register update.

Signed-off-by: Steve Lee 
---
 sound/soc/codecs/max98390.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/codecs/max98390.h b/sound/soc/codecs/max98390.h
index 5f444e7779b0..dff884f68e3e 100644
--- a/sound/soc/codecs/max98390.h
+++ b/sound/soc/codecs/max98390.h
@@ -650,7 +650,7 @@
 
 /* DSM register offset */
 #define MAX98390_DSM_PAYLOAD_OFFSET 16
-#define MAX98390_DSM_PARAM_MAX_SIZE 770
+#define MAX98390_DSM_PARAM_MAX_SIZE 1024
 #define MAX98390_DSM_PARAM_MIN_SIZE 670
 
 struct max98390_priv {
-- 
2.17.1



[RESEND 2/3] ASoC: max98390: Update dsm init sequence and condition.

2020-07-26 Thread Steve Lee
 Modify dsm_init sequence and dsm param bin check condition.
  - Move dsm_init() to after amp init setting to
make sure dsm init is last setting.
  - dsm param bin check condition changed for extended register setting.

Signed-off-by: Steve Lee 
---
 sound/soc/codecs/max98390.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/sound/soc/codecs/max98390.c b/sound/soc/codecs/max98390.c
index 44ffebac15ad..ff5cc9bbec29 100644
--- a/sound/soc/codecs/max98390.c
+++ b/sound/soc/codecs/max98390.c
@@ -790,7 +790,7 @@ static int max98390_dsm_init(struct snd_soc_component 
*component)
param_start_addr = (dsm_param[0] & 0xff) | (dsm_param[1] & 0xff) << 8;
param_size = (dsm_param[2] & 0xff) | (dsm_param[3] & 0xff) << 8;
if (param_size > MAX98390_DSM_PARAM_MAX_SIZE ||
-   param_start_addr < DSM_STBASS_HPF_B0_BYTE0 ||
+   param_start_addr < MAX98390_IRQ_CTRL ||
fw->size < param_size + MAX98390_DSM_PAYLOAD_OFFSET) {
dev_err(component->dev,
"param fw is invalid.\n");
@@ -864,11 +864,11 @@ static int max98390_probe(struct snd_soc_component 
*component)
regmap_write(max98390->regmap, MAX98390_SOFTWARE_RESET, 0x01);
/* Sleep reset settle time */
msleep(20);
-   /* Update dsm bin param */
-   max98390_dsm_init(component);
 
/* Amp init setting */
max98390_init_regs(component);
+   /* Update dsm bin param */
+   max98390_dsm_init(component);
 
/* Dsm Setting */
if (max98390->ref_rdc_value) {
-- 
2.17.1



[RESEND 1/3] ASoC: max98390: Fix dac event dapm mixer.

2020-07-26 Thread Steve Lee
 Global EN register guide to off before AMP_EN register
 when amp disable sequence.
  - remove AMP_EN control before max98390_dac_event call

Signed-off-by: Steve Lee 
---
 sound/soc/codecs/max98390.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/codecs/max98390.c b/sound/soc/codecs/max98390.c
index 3e8094241645..44ffebac15ad 100644
--- a/sound/soc/codecs/max98390.c
+++ b/sound/soc/codecs/max98390.c
@@ -678,7 +678,7 @@ static const struct snd_kcontrol_new max98390_dai_controls =
 
 static const struct snd_soc_dapm_widget max98390_dapm_widgets[] = {
SND_SOC_DAPM_DAC_E("Amp Enable", "HiFi Playback",
-   MAX98390_R203A_AMP_EN, 0, 0, max98390_dac_event,
+   SND_SOC_NOPM, 0, 0, max98390_dac_event,
SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
SND_SOC_DAPM_MUX("DAI Sel Mux", SND_SOC_NOPM, 0, 0,
&max98390_dai_controls),
-- 
2.17.1



Re: [PATCH] Makefile.extrawarn: Move sign-compare from W=2 to W=3

2020-07-26 Thread Masahiro Yamada
On Wed, Jul 22, 2020 at 1:57 PM Joe Perches  wrote:
>
> This -Wsign-compare compiler warning can be very noisy
> and most of the suggested conversions are unnecessary.
>
> Make the warning W=3 so it's described under the
> "can most likely be ignored" block.
>
> Signed-off-by: Joe Perches 
> ---

Applied to linux-kbuild. Thanks.



> On Tue, 2020-07-21 at 14:32 -0700, Joe Perches wrote:
> > On Tue, 2020-07-21 at 19:06 +, Corentin Labbe wrote:
> > > This patch fixes the warning:
> > > warning: comparison of integer expressions of different signedness: 'int' 
> > > and 'long unsigned int' [-Wsign-compare]
> >
> > I think these do not really need conversion.
> > Are these useful compiler warnings ?
>
> Perhaps move the warning from W=2 to W=3 so
> it's described as "can most likely be ignored"
>
>  scripts/Makefile.extrawarn | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
> index 62c275685b75..95e4cdb94fe9 100644
> --- a/scripts/Makefile.extrawarn
> +++ b/scripts/Makefile.extrawarn
> @@ -66,7 +66,6 @@ KBUILD_CFLAGS += -Wnested-externs
>  KBUILD_CFLAGS += -Wshadow
>  KBUILD_CFLAGS += $(call cc-option, -Wlogical-op)
>  KBUILD_CFLAGS += -Wmissing-field-initializers
> -KBUILD_CFLAGS += -Wsign-compare
>  KBUILD_CFLAGS += -Wtype-limits
>  KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized)
>  KBUILD_CFLAGS += $(call cc-option, -Wunused-macros)
> @@ -87,6 +86,7 @@ KBUILD_CFLAGS += -Wpacked
>  KBUILD_CFLAGS += -Wpadded
>  KBUILD_CFLAGS += -Wpointer-arith
>  KBUILD_CFLAGS += -Wredundant-decls
> +KBUILD_CFLAGS += -Wsign-compare
>  KBUILD_CFLAGS += -Wswitch-default
>  KBUILD_CFLAGS += $(call cc-option, -Wpacked-bitfield-compat)
>
>
>


--
Best Regards
Masahiro Yamada


undefined reference to `start_isolate_page_range'

2020-07-26 Thread kernel test robot
Hi Michal,

FYI, the error/warning still remains.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   92ed301919932f13b9172e525674157e983d
commit: 2602276d3d3811b1a48c48113042cd75fcbfc27d microblaze: Wire CMA allocator
date:   6 months ago
config: microblaze-randconfig-c022-20200727 (attached as .config)
compiler: microblaze-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
git checkout 2602276d3d3811b1a48c48113042cd75fcbfc27d
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross 
ARCH=microblaze 

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

All errors (new ones prefixed by >>):

   microblaze-linux-ld: mm/page_alloc.o: in function `alloc_contig_range':
>> (.text+0xd274): undefined reference to `start_isolate_page_range'
>> microblaze-linux-ld: (.text+0xd48c): undefined reference to 
>> `test_pages_isolated'
>> microblaze-linux-ld: (.text+0xd548): undefined reference to 
>> `undo_isolate_page_range'

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


.config.gz
Description: application/gzip


  1   2   3   4   5   6   7   >