Re: [PATCH 08/11] pragma once: convert scripts/atomic/

2021-02-28 Thread Peter Zijlstra
On Sun, Feb 28, 2021 at 08:03:18PM +0300, Alexey Dobriyan wrote:
> From f10fe79897fa9600f144c76bc5df52dba28b7a66 Mon Sep 17 00:00:00 2001
> From: Alexey Dobriyan 
> Date: Tue, 9 Feb 2021 01:37:55 +0300
> Subject: [PATCH 08/11] pragma once: convert scripts/atomic/
> 
> Generate atomic headers without include guards.

-ENOCONTEXT, why ?


Re: [PATCH] mm: Generalize HUGETLB_PAGE_SIZE_VARIABLE

2021-02-28 Thread Christoph Hellwig
On Mon, Mar 01, 2021 at 01:13:41PM +0530, Anshuman Khandual wrote:
> > doesn't this need a 'if HUGETLB_PAGE'
> 
> While making HUGETLB_PAGE_SIZE_VARIABLE a generic option, also made it
> dependent on HUGETLB_PAGE. Should not that gate HUGETLB_PAGE_SIZE_VARIABLE
> when HUGETLB_PAGE is not available irrespective of the select statement on
> the platforms ?

depends doesn't properly work for variables that are selected.


Re: [PATCH] vdpa/mlx5: Fix wrong use of bit numbers

2021-02-28 Thread Jason Wang



On 2021/3/1 2:28 下午, Eli Cohen wrote:

VIRTIO_F_VERSION_1 is a bit number. Use BIT_ULL() with mask
conditionals.

Also, in mlx5_vdpa_is_little_endian() use BIT_ULL for consistency with
the rest of the code.

Fixes: 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")
Signed-off-by: Eli Cohen 



Acked-by: Jason Wang 



---
  drivers/vdpa/mlx5/net/mlx5_vnet.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c 
b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index dc7031132fff..7d21b857a94a 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -821,7 +821,7 @@ static int create_virtqueue(struct mlx5_vdpa_net *ndev, 
struct mlx5_vdpa_virtque
MLX5_SET(virtio_q, vq_ctx, event_qpn_or_msix, mvq->fwqp.mqp.qpn);
MLX5_SET(virtio_q, vq_ctx, queue_size, mvq->num_ent);
MLX5_SET(virtio_q, vq_ctx, virtio_version_1_0,
-!!(ndev->mvdev.actual_features & VIRTIO_F_VERSION_1));
+!!(ndev->mvdev.actual_features & BIT_ULL(VIRTIO_F_VERSION_1)));
MLX5_SET64(virtio_q, vq_ctx, desc_addr, mvq->desc_addr);
MLX5_SET64(virtio_q, vq_ctx, used_addr, mvq->device_addr);
MLX5_SET64(virtio_q, vq_ctx, available_addr, mvq->driver_addr);
@@ -1578,7 +1578,7 @@ static void teardown_virtqueues(struct mlx5_vdpa_net 
*ndev)
  static inline bool mlx5_vdpa_is_little_endian(struct mlx5_vdpa_dev *mvdev)
  {
return virtio_legacy_is_little_endian() ||
-   (mvdev->actual_features & (1ULL << VIRTIO_F_VERSION_1));
+   (mvdev->actual_features & BIT_ULL(VIRTIO_F_VERSION_1));
  }
  
  static __virtio16 cpu_to_mlx5vdpa16(struct mlx5_vdpa_dev *mvdev, u16 val)




Re: [PATCH] dts: remove c6x dts hard link file

2021-02-28 Thread Geert Uytterhoeven
Hi Wolfram,

On Mon, Mar 1, 2021 at 7:28 AM Wolfram Sang
 wrote:
> The architecture has gone and indexing software like 'mkid' complains
> about the broken link.
>
> Signed-off-by: Wolfram Sang 

Thanks for your patch!

With s/hard/symbolic/ in the oneline-summary:
Reviewed-by: Geert Uytterhoeven 

Gr{oetje,eeting}s,

Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


Re: [PATCH] perf trace: Ensure read cmdlines are null terminated.

2021-02-28 Thread Namhyung Kim
Hi Ian,

On Sat, Feb 27, 2021 at 7:14 AM Ian Rogers  wrote:
>
> Issue detected by address sanitizer.
>
> Fixes: cd4ceb63438e (perf util: Save pid-cmdline mapping into tracing header)
> Signed-off-by: Ian Rogers 

Acked-by: Namhyung Kim 

Thanks,
Namhyung

> ---
>  tools/perf/util/trace-event-read.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/tools/perf/util/trace-event-read.c 
> b/tools/perf/util/trace-event-read.c
> index f507dff713c9..8a01af783310 100644
> --- a/tools/perf/util/trace-event-read.c
> +++ b/tools/perf/util/trace-event-read.c
> @@ -361,6 +361,7 @@ static int read_saved_cmdline(struct tep_handle *pevent)
> pr_debug("error reading saved cmdlines\n");
> goto out;
> }
> +   buf[ret] = '\0';
>
> parse_saved_cmdline(pevent, buf, size);
> ret = 0;
> --
> 2.30.1.766.gb4fecdf3b7-goog
>


Re: [PATCH] mm: Generalize HUGETLB_PAGE_SIZE_VARIABLE

2021-02-28 Thread Anshuman Khandual



On 3/1/21 11:53 AM, Christoph Hellwig wrote:
> On Mon, Mar 01, 2021 at 11:20:53AM +0530, Anshuman Khandual wrote:
>> HUGETLB_PAGE_SIZE_VARIABLE need not be defined for each individual
>> platform subscribing it. Instead just make it generic.
>>
>> Cc: Michael Ellerman 
>> Cc: Benjamin Herrenschmidt 
>> Cc: Paul Mackerras 
>> Cc: Andrew Morton 
>> Cc: Christoph Hellwig 
>> Cc: linux-i...@vger.kernel.org
>> Cc: linuxppc-...@lists.ozlabs.org
>> Cc: linux...@kvack.org
>> Cc: linux-kernel@vger.kernel.org
>> Suggested-by: Christoph Hellwig 
>> Signed-off-by: Anshuman Khandual 
>> ---
>> This change was originally suggested in an earilier discussion. This
>> applies on v5.12-rc1 and has been build tested on all applicable
>> platforms i.e ia64 and powerpc.
>>
>> https://patchwork.kernel.org/project/linux-mm/patch/1613024531-19040-3-git-send-email-anshuman.khand...@arm.com/
>>
>>  arch/ia64/Kconfig| 6 +-
>>  arch/powerpc/Kconfig | 6 +-
>>  mm/Kconfig   | 8 
>>  3 files changed, 10 insertions(+), 10 deletions(-)
>>
>> diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
>> index 2ad7a8d29fcc..6b3e3f6c29ae 100644
>> --- a/arch/ia64/Kconfig
>> +++ b/arch/ia64/Kconfig
>> @@ -32,6 +32,7 @@ config IA64
>>  select TTY
>>  select HAVE_ARCH_TRACEHOOK
>>  select HAVE_VIRT_CPU_ACCOUNTING
>> +select HUGETLB_PAGE_SIZE_VARIABLE
> 
> doesn't this need a 'if HUGETLB_PAGE'

While making HUGETLB_PAGE_SIZE_VARIABLE a generic option, also made it
dependent on HUGETLB_PAGE. Should not that gate HUGETLB_PAGE_SIZE_VARIABLE
when HUGETLB_PAGE is not available irrespective of the select statement on
the platforms ?

> 
> or did you verify that HUGETLB_PAGE_SIZE_VARIABLE checks are always
> nested inside of HUGETLB_PAGE ones?
>


Re: [GIT PULL] Driver core / debugfs changes for 5.12-rc1

2021-02-28 Thread Saravana Kannan
On Sat, Feb 27, 2021 at 6:27 AM Greg KH  wrote:
>
> On Wed, Feb 24, 2021 at 10:20:44AM -0800, Linus Torvalds wrote:
> > On Wed, Feb 24, 2021 at 6:27 AM Greg KH  wrote:
> > >
> > >  [..] I've reverted that change at
> > > the very end so we don't have to worry about regressions in 5.12.
> >
> > Side note: it would have been really nice to see links to the actual
> > problem reports in the revert commit.
>
> Odd, this showed up in my gmail spam folder, just saw this now :(

Yup, went to spam for me too!

> > Yes, there's a "Link:" line there, but that points to the
> > less-than-useful patch submission for the revert, not to the actual
> > _reasons_ for the revert.
> >
> > Now I'm looking at that revert, and I have absolutely no idea why it
> > happened. Only a very vague "there are still reported regressions
> > happening".
> >
> > I've pulled it, but wanted to just point out that when there's some
> > fairly fundamental revert like this, it really would be good to link
> > to the problems, so that when people try to re-enable it, they have
> > the history for why it didn't work the first time.
> >
> > Now all that history is basically lost (well, hopefully Saravana and
> > you actually remember, but you get my point).
>
> Sorry, the history is on the original commit Link that was reverted, and
> in lots of other emails on lkml over the past few weeks.  Next time I'll
> include links to those threads as well.

These are links of interest. All the fixes are at least linked to from
these two threads. And if they are not, they all mention "Fixes" and
list the commit that was reverted. So it's all trackable if we really
find the need to do so in the future.

The original series that set fw_devlink=on where most of the issues
were reported.
[1] - 
https://lore.kernel.org/lkml/20201218031703.3053753-1-sarava...@google.com/

This is the series that made fw_devlink=on more forgiving. And a few
issues were reported there.
[2] - 
https://lore.kernel.org/lkml/20210205222644.2357303-1-sarava...@google.com/

To summarize, the issues fell into one of these types:
* Drivers would initialize the hardware without actually probing a
struct device that existed AND didn't use the existing mechanisms (Eg:
IRQCHIP_DECLARE) meant to allow this. So fw_devlink makes their
consumers wait forever. Bunch of driver fixes for this, but [2] also
workaround most of these by making fw_devlink/fwnode code a bit
smarter.
* Drivers would initialize the hardware without creating a struct
device at all despite the DT node having a compatible property. [2]
handles this by making fw_devlink a bit smarter.
* Some device link status not getting updated correctly when a driver
is force bound with a device (I know the fix, haven't gotten around to
submitting it).
* fw_devlink causing some probe reordering that should technically be
harmless (all suppliers probed before the consumer), but drivers still
don't like it. Bunch of fixes + reducing/removing unnecessary
reordering of probes by fw_devlink (latter is under review).
* Spinlock/corruption errors that fw_devlink exposed by reordering
some probes, but the actual issue was unrelated to fw_devlink.

So it was a mix of making fw_devlink smarter to deal with existing
code and fixing some drivers.

Thanks,
Saravana


Re: Re: [PATCH] iwlegacy: Add missing check in il4965_commit_rxon

2021-02-28 Thread dinghao . liu
> On Sun, Feb 28, 2021 at 08:25:22PM +0800, Dinghao Liu wrote:
> > There is one il_set_tx_power() call in this function without
> > return value check. Print error message and return error code
> > on failure just like the other il_set_tx_power() call.
> 
> We have few calls for il_set_tx_power(), on some cases we
> check return on some not. That correct as setting tx power
> can be deferred internally if not possible at the moment.
> 
> > Signed-off-by: Dinghao Liu 
> > ---
> >  drivers/net/wireless/intel/iwlegacy/4965.c | 6 +-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/wireless/intel/iwlegacy/4965.c 
> > b/drivers/net/wireless/intel/iwlegacy/4965.c
> > index 9fa556486511..3235b8be1894 100644
> > --- a/drivers/net/wireless/intel/iwlegacy/4965.c
> > +++ b/drivers/net/wireless/intel/iwlegacy/4965.c
> > @@ -1361,7 +1361,11 @@ il4965_commit_rxon(struct il_priv *il)
> >  * We do not commit tx power settings while channel changing,
> >  * do it now if tx power changed.
> >  */
> > -   il_set_tx_power(il, il->tx_power_next, false);
> > +   ret = il_set_tx_power(il, il->tx_power_next, false);
> > +   if (ret) {
> > +   IL_ERR("Error sending TX power (%d)\n", ret);
> > +   return ret;
> > +   
> 
> This is not good change. We do not check return value of
> il_commit_rxon(), except when creating interface. So this change might
> broke creating interface, what worked otherwise when il_set_tx_power()
> returned error.
> 

It's clear to me, Thanks for your explanation!

Regards,
Dinghao


[PATCH] sata_dwc_460ex: Fix missing check in sata_dwc_isr

2021-02-28 Thread Dinghao Liu
ata_qc_from_tag() may return a null pointer and further lead to
null-pointer-dereference. Add a return value check to avoid such case.

Signed-off-by: Dinghao Liu 
---
 drivers/ata/sata_dwc_460ex.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/ata/sata_dwc_460ex.c b/drivers/ata/sata_dwc_460ex.c
index 9dcef6ac643b..0068247ffc06 100644
--- a/drivers/ata/sata_dwc_460ex.c
+++ b/drivers/ata/sata_dwc_460ex.c
@@ -548,8 +548,10 @@ static irqreturn_t sata_dwc_isr(int irq, void 
*dev_instance)
 * active tag.  It is the tag that matches the command about to
 * be completed.
 */
-   qc->ap->link.active_tag = tag;
-   sata_dwc_bmdma_start_by_tag(qc, tag);
+   if (qc) {
+   qc->ap->link.active_tag = tag;
+   sata_dwc_bmdma_start_by_tag(qc, tag);
+   }
 
handled = 1;
goto DONE;
-- 
2.17.1



Re: [PATCH v2 2/3] mm: Force update of mem cgroup soft limit tree on usage excess

2021-02-28 Thread Michal Hocko
On Fri 26-02-21 16:56:28, Tim Chen wrote:
> 
> 
> On 2/26/21 12:52 AM, Michal Hocko wrote:
> 
> >>
> >> Michal,
> >>
> >> Let's take an extreme case where memcg 1 always generate the
> >> first event and memcg 2 generates the rest of 128*8-1 events
> >> and the pattern repeat.
> > 
> > I do not follow. Events are per-memcg, aren't they?
> > __this_cpu_read(memcg->vmstats_percpu->targets[target]);
> > [...]
> > __this_cpu_write(memcg->vmstats_percpu->targets[target], next);
> > 
> 
> You are right. My previous reasoning is incorrect as the sampling is done per 
> memcg.
> I'll do some additional debugging on why memcg is not on the tree.

OK, thanks for the confirmation. I think we want to do 2 things. Remove
the soft limit specific threshold and stay with a single one and
recognize THPs.
-- 
Michal Hocko
SUSE Labs


Re: Question about the "EXPERIMENTAL" tag for dax in XFS

2021-02-28 Thread Yasunori Goto

Hello, Dan-san,

On 2021/02/27 4:24, Dan Williams wrote:

On Fri, Feb 26, 2021 at 11:05 AM Darrick J. Wong  wrote:


On Fri, Feb 26, 2021 at 09:45:45AM +, ruansy.f...@fujitsu.com wrote:

Hi, guys

Beside this patchset, I'd like to confirm something about the
"EXPERIMENTAL" tag for dax in XFS.

In XFS, the "EXPERIMENTAL" tag, which is reported in waring message
when we mount a pmem device with dax option, has been existed for a
while.  It's a bit annoying when using fsdax feature.  So, my initial
intention was to remove this tag.  And I started to find out and solve
the problems which prevent it from being removed.

As is talked before, there are 3 main problems.  The first one is "dax
semantics", which has been resolved.  The rest two are "RMAP for
fsdax" and "support dax reflink for filesystem", which I have been
working on.





So, what I want to confirm is: does it means that we can remove the
"EXPERIMENTAL" tag when the rest two problem are solved?


Yes.  I'd keep the experimental tag for a cycle or two to make sure that
nothing new pops up, but otherwise the two patchsets you've sent close
those two big remaining gaps.  Thank you for working on this!


Or maybe there are other important problems need to be fixed before
removing it?  If there are, could you please show me that?


That remains to be seen through QA/validation, but I think that's it.

Granted, I still have to read through the two patchsets...


I've been meaning to circle back here as well.

My immediate concern is the issue Jason recently highlighted [1] with
respect to invalidating all dax mappings when / if the device is
ripped out from underneath the fs. I don't think that will collide
with Ruan's implementation, but it does need new communication from
driver to fs about removal events.

[1]: 
http://lore.kernel.org/r/capcyv4i+pzhyziepf2pah0dt5jdfkmkdx-3usqy1fahf6lp...@mail.gmail.com



I'm not sure why there is a race condition between unbinding operation 
and accessing mmaped file on filesystem dax yet.


May be silly question, but could you tell me why the "unbinding" 
operation of the namespace which is mounted by filesystem dax must be

allowed?
If "unbinding" is rejected when the filesystem is mounted with dax 
enabled, what is inconvenience?


I can imagine if a device like usb memory stick is removed surprisingly, 
kernel/filesystem need to reject writeback at the time, and discard page 
cache. Then, I can understand that unbinding operation is essential for 
such case.
But I don't know why PMEM device/namespace allows unbinding operation 
like surprising removal event.


Thanks,

--
Yasunori Goto


[PATCH] Squashfs: fix xattr id and id lookup sanity checks

2021-02-28 Thread Phillip Lougher
The checks for maximum metadata block size is
missing SQUASHFS_BLOCK_OFFSET (the two byte length
count).

Cc: sta...@vger.kernel.org
Signed-off-by: Phillip Lougher 
---
 fs/squashfs/id.c   | 6 --
 fs/squashfs/xattr_id.c | 6 --
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/fs/squashfs/id.c b/fs/squashfs/id.c
index 11581bf31af4..ea5387679723 100644
--- a/fs/squashfs/id.c
+++ b/fs/squashfs/id.c
@@ -97,14 +97,16 @@ __le64 *squashfs_read_id_index_table(struct super_block *sb,
start = le64_to_cpu(table[n]);
end = le64_to_cpu(table[n + 1]);
 
-   if (start >= end || (end - start) > SQUASHFS_METADATA_SIZE) {
+   if (start >= end || (end - start) >
+   (SQUASHFS_METADATA_SIZE + 
SQUASHFS_BLOCK_OFFSET)) {
kfree(table);
return ERR_PTR(-EINVAL);
}
}
 
start = le64_to_cpu(table[indexes - 1]);
-   if (start >= id_table_start || (id_table_start - start) > 
SQUASHFS_METADATA_SIZE) {
+   if (start >= id_table_start || (id_table_start - start) >
+   (SQUASHFS_METADATA_SIZE + 
SQUASHFS_BLOCK_OFFSET)) {
kfree(table);
return ERR_PTR(-EINVAL);
}
diff --git a/fs/squashfs/xattr_id.c b/fs/squashfs/xattr_id.c
index ead66670b41a..087cab8c78f4 100644
--- a/fs/squashfs/xattr_id.c
+++ b/fs/squashfs/xattr_id.c
@@ -109,14 +109,16 @@ __le64 *squashfs_read_xattr_id_table(struct super_block 
*sb, u64 table_start,
start = le64_to_cpu(table[n]);
end = le64_to_cpu(table[n + 1]);
 
-   if (start >= end || (end - start) > SQUASHFS_METADATA_SIZE) {
+   if (start >= end || (end - start) >
+   (SQUASHFS_METADATA_SIZE + 
SQUASHFS_BLOCK_OFFSET)) {
kfree(table);
return ERR_PTR(-EINVAL);
}
}
 
start = le64_to_cpu(table[indexes - 1]);
-   if (start >= table_start || (table_start - start) > 
SQUASHFS_METADATA_SIZE) {
+   if (start >= table_start || (table_start - start) >
+   (SQUASHFS_METADATA_SIZE + 
SQUASHFS_BLOCK_OFFSET)) {
kfree(table);
return ERR_PTR(-EINVAL);
}
-- 
2.29.2


Re: [PATCH] iwlegacy: Add missing check in il4965_commit_rxon

2021-02-28 Thread Stanislaw Gruszka
On Sun, Feb 28, 2021 at 08:25:22PM +0800, Dinghao Liu wrote:
> There is one il_set_tx_power() call in this function without
> return value check. Print error message and return error code
> on failure just like the other il_set_tx_power() call.

We have few calls for il_set_tx_power(), on some cases we
check return on some not. That correct as setting tx power
can be deferred internally if not possible at the moment.

> Signed-off-by: Dinghao Liu 
> ---
>  drivers/net/wireless/intel/iwlegacy/4965.c | 6 +-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/wireless/intel/iwlegacy/4965.c 
> b/drivers/net/wireless/intel/iwlegacy/4965.c
> index 9fa556486511..3235b8be1894 100644
> --- a/drivers/net/wireless/intel/iwlegacy/4965.c
> +++ b/drivers/net/wireless/intel/iwlegacy/4965.c
> @@ -1361,7 +1361,11 @@ il4965_commit_rxon(struct il_priv *il)
>* We do not commit tx power settings while channel changing,
>* do it now if tx power changed.
>*/
> - il_set_tx_power(il, il->tx_power_next, false);
> + ret = il_set_tx_power(il, il->tx_power_next, false);
> + if (ret) {
> + IL_ERR("Error sending TX power (%d)\n", ret);
> + return ret;
> + 

This is not good change. We do not check return value of
il_commit_rxon(), except when creating interface. So this change might
broke creating interface, what worked otherwise when il_set_tx_power()
returned error.

Stanislaw


Re: linux kernel bug???

2021-02-28 Thread Dmitry Vyukov
On Mon, Mar 1, 2021 at 8:10 AM Lukas Bulwahn  wrote:
>
> Hi,
>
> On Mon, Mar 1, 2021 at 7:58 AM  wrote:
> >
> > This is the first time for me to report something, so maybe the format is 
> > not right. Please  correct me if I'm wrong. Thank you ~
> > When using Syzkaller to fuzz Linux kernel 5.11.0, it reported one 
> > null-ptr-def bug in file.c. The information is as follows:
> >
> > The kernel's commit:   c03c21ba6
> > The syzkaller commit: 52e3731913ab2677be27c29ed8142b04e8f28521
> >
>
> This looks like a valid kernel issue found with syzkaller.
>
> Given that it is reproducible, I suggest you continue with the following 
> steps:
>
> 1. Check if it reproduces on v5.12-rc1. If not, there is already a fix
> in v5.12-rc1. Try to identify the specific fix by bisection.
>
> 2. Check since when this issue occurs, e.g., does it appear on v5.10, v5.9 
> etc.
>
> 3. Bisect it to a specific commit.
>
> 4. Report back the results of your bisections.

Hi,

For syzkaller bugs it's also a good idea to check if it was already
reported by syzbot or not.
This one seems to be already reported:
https://syzkaller.appspot.com/bug?id=e9579dc4fc313abec952e5811bf48a26fb8d74b4
https://lore.kernel.org/lkml/ff83de05bc628...@google.com/


> > The report:
> > Syzkaller hit 'KASAN: null-ptr-deref Read in __fget_light' bug.
> >
> > ==
> > audit: type=1400 audit(1614571961.594:8): avc:  denied  { execmem } for  
> > pid=294 comm="syz-executor894" scontext=system_u:system_r:kernel_t:s0 
> > tcontext=system_u:system_r:kernel_t:s0 tclass=process permissive=1
> > BUG: KASAN: null-ptr-deref in instrument_atomic_read 
> > include/linux/instrumented.h:71 [inline]
> > BUG: KASAN: null-ptr-deref in atomic_read 
> > include/asm-generic/atomic-instrumented.h:27 [inline]
> > BUG: KASAN: null-ptr-deref in __fget_light+0x4f/0x250 fs/file.c:930
> > Read of size 4 at addr  by task io_wqe_worker-0/296
> >
> > CPU: 1 PID: 296 Comm: io_wqe_worker-0 Not tainted 5.11.0+ #5
> > Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
> > 1.13.0-1ubuntu1.1 04/01/2014
> > Call Trace:
> >  __dump_stack lib/dump_stack.c:79 [inline]
> >  dump_stack+0xaf/0xf2 lib/dump_stack.c:120
> >  __kasan_report mm/kasan/report.c:400 [inline]
> >  kasan_report.cold.9+0x10c/0x10e mm/kasan/report.c:413
> >  check_memory_region_inline mm/kasan/generic.c:179 [inline]
> >  check_memory_region+0x198/0x200 mm/kasan/generic.c:185
> >  instrument_atomic_read include/linux/instrumented.h:71 [inline]
> >  atomic_read include/asm-generic/atomic-instrumented.h:27 [inline]
> >  __fget_light+0x4f/0x250 fs/file.c:930
> >  fdget_raw include/linux/file.h:70 [inline]
> >  path_init+0x940/0x1290 fs/namei.c:2354
> >  path_lookupat.isra.65+0x2c/0x4e0 fs/namei.c:2410
> >  filename_lookup.part.80+0x17a/0x370 fs/namei.c:2453
> >  filename_lookup fs/namei.c:2446 [inline]
> >  user_path_at_empty+0x4b/0x80 fs/namei.c:2733
> >  user_path_at include/linux/namei.h:60 [inline]
> >  vfs_statx+0x108/0x310 fs/stat.c:195
> >  do_statx+0xa9/0x120 fs/stat.c:590
> >  io_statx fs/io_uring.c:4525 [inline]
> >  io_issue_sqe+0x1c31/0x4a50 fs/io_uring.c:6343
> >  io_wq_submit_work+0x2f7/0x8e0 fs/io_uring.c:6418
> >  io_worker_handle_work+0xcdd/0x1900 fs/io-wq.c:561
> >  io_wqe_worker+0xa15/0xeb0 fs/io-wq.c:603
> >  kthread+0x32a/0x3f0 kernel/kthread.c:292
> >  ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:294
> > ==
> >
> >
> > Syzkaller reproducer:
> > # {Threaded:false Collide:false Repeat:false RepeatTimes:0 Procs:1 
> > Slowdown:1 Sandbox: Fault:false FaultCall:-1 FaultNth:0 Leak:false 
> > NetInjection:false NetDevices:false NetReset:false Cgroups:false 
> > BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false 
> > VhciInjection:false Wifi:false Sysctl:false UseTmpDir:false 
> > HandleSegv:false Repro:false Trace:false}
> > r0 = syz_io_uring_setup(0x1, &(0x7f80)={0x0, 0x0, 0x0, 0x0, 0x0, 
> > 0x0, 0x0}, &(0x7f0a)=nil, &(0x7f0b)=nil, 
> > &(0x7f000100)=0x0, &(0x7f000140)=0x0)
> > syz_io_uring_submit(r1, r2, &(0x7f0008c0)=@IORING_OP_STATX={0x15, 0x0, 
> > 0x0, 0x, 0x0, &(0x7f0003c0)='./file1\x00', 0x20, 
> > 0x1000}, 0x3)
> > io_uring_enter(r0, 0x1, 0x1, 0x1, 0x0, 0x0)
> >
> >
> > C reproducer:
> > // autogenerated by syzkaller (https://github.com/google/syzkaller)
> >
> > #define _GNU_SOURCE
> >
> > #include 
> > #include 
> > #include 
> > #include 
> > #include 
> > #include 
> > #include 
> > #include 
> > #include 
> >
> > #define SIZEOF_IO_URING_SQE 64
> > #define SIZEOF_IO_URING_CQE 16
> > #define SQ_HEAD_OFFSET 0
> > #define SQ_TAIL_OFFSET 64
> > #define SQ_RING_MASK_OFFSET 256
> > #define SQ_RING_ENTRIES_OFFSET 264
> > #define SQ_FLAGS_OFFSET 276
> > #define SQ_DROPPED_OFFSET 272
> > #define CQ_HEAD_OFFSET 128
> > #define CQ_TAIL_OFFSET 192
> > #define 

[PATCH] PCI: acpiphp: Fixed coding style

2021-02-28 Thread chakravarthikulkarni
In this commit fixed coding style for braces and comments.

Signed-off-by: chakravarthikulkarni 
---
 drivers/pci/hotplug/acpiphp.h | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/hotplug/acpiphp.h b/drivers/pci/hotplug/acpiphp.h
index a74b274a8c45..e0964600a78f 100644
--- a/drivers/pci/hotplug/acpiphp.h
+++ b/drivers/pci/hotplug/acpiphp.h
@@ -80,8 +80,8 @@ struct acpiphp_bridge {
 struct acpiphp_slot {
struct list_head node;
struct pci_bus *bus;
-   struct list_head funcs; /* one slot may have different
-  objects (i.e. for each function) */
+   struct list_head funcs; /* one slot may have different */
+   /* objects (i.e. for each function) */
struct slot *slot;
 
u8  device; /* pci device# */
@@ -148,8 +148,7 @@ static inline struct acpiphp_root_context 
*to_acpiphp_root_context(struct acpi_h
  * ACPI has no generic method of setting/getting attention status
  * this allows for device specific driver registration
  */
-struct acpiphp_attention_info
-{
+struct acpiphp_attention_info {
int (*set_attn)(struct hotplug_slot *slot, u8 status);
int (*get_attn)(struct hotplug_slot *slot, u8 *status);
struct module *owner;
-- 
2.17.1



Re: [PATCH 6/7] dma-iommu: implement ->alloc_noncontiguous

2021-02-28 Thread Christoph Hellwig
On Mon, Mar 01, 2021 at 04:17:42PM +0900, Sergey Senozhatsky wrote:
> > > Do you think we could add the attrs parameter to the
> > > dma_alloc_noncontiguous() API?
> > 
> > Yes, we could probably do that.
> 
> I can cook a patch, unless somebody is already looking into it.

I plan to resend the whole series with the comments very soon.


Re: [PATCH 6/7] dma-iommu: implement ->alloc_noncontiguous

2021-02-28 Thread Sergey Senozhatsky
On (21/02/16 09:49), Christoph Hellwig wrote:
> > When working on the videobuf2 integration with Sergey I noticed that
> > we always pass 0 as DMA attrs here, which removes the ability for
> > drivers to use DMA_ATTR_ALLOC_SINGLE_PAGES.
> > 
> > It's quite important from a system stability point of view, because by
> > default the iommu_dma allocator would prefer big order allocations for
> > TLB locality reasons. For many devices, though, it doesn't really
> > affect the performance, because of random access patterns, so single
> > pages are good enough and reduce the risk of allocation failures or
> > latency due to fragmentation.
> > 
> > Do you think we could add the attrs parameter to the
> > dma_alloc_noncontiguous() API?
> 
> Yes, we could probably do that.

I can cook a patch, unless somebody is already looking into it.

-ss


drivers/gpu/drm/msm/dp/dp_debug.c:218 dp_debug_init() warn: passing zero to 'PTR_ERR'

2021-02-28 Thread Dan Carpenter
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   fe07bfda2fb9cdef8a4d4008a409bb02f35f1bd8
commit: d11a93690df7e9a7e07c0784ecad019a627b1449 drm/msm/dp: add debugfs 
support to DP driver
config: arm64-randconfig-m031-20210301 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 9.3.0

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

New smatch warnings:
drivers/gpu/drm/msm/dp/dp_debug.c:218 dp_debug_init() warn: passing zero to 
'PTR_ERR'

Old smatch warnings:
drivers/gpu/drm/msm/dp/dp_debug.c:227 dp_debug_init() warn: passing zero to 
'PTR_ERR'

vim +/PTR_ERR +218 drivers/gpu/drm/msm/dp/dp_debug.c

d11a93690df7e9 Abhinav Kumar 2020-09-12  209  static int dp_debug_init(struct 
dp_debug *dp_debug)
d11a93690df7e9 Abhinav Kumar 2020-09-12  210  {
d11a93690df7e9 Abhinav Kumar 2020-09-12  211int rc = 0;
d11a93690df7e9 Abhinav Kumar 2020-09-12  212struct dp_debug_private *debug 
= container_of(dp_debug,
d11a93690df7e9 Abhinav Kumar 2020-09-12  213struct 
dp_debug_private, dp_debug);
d11a93690df7e9 Abhinav Kumar 2020-09-12  214struct dentry *dir, *file;
d11a93690df7e9 Abhinav Kumar 2020-09-12  215  
d11a93690df7e9 Abhinav Kumar 2020-09-12  216dir = 
debugfs_create_dir(DEBUG_NAME, NULL);
d11a93690df7e9 Abhinav Kumar 2020-09-12  217if (IS_ERR_OR_NULL(dir)) {
d11a93690df7e9 Abhinav Kumar 2020-09-12 @218rc = PTR_ERR(dir);
d11a93690df7e9 Abhinav Kumar 2020-09-12  219DRM_ERROR("[%s] debugfs 
create dir failed, rc = %d\n",
d11a93690df7e9 Abhinav Kumar 2020-09-12  220  
DEBUG_NAME, rc);
d11a93690df7e9 Abhinav Kumar 2020-09-12  221goto error;

Debugfs function never return NULL, but actually debugfs functions
aren't supposed to be checked in the normal case (the abnormal case is
where you are trying to dereference "dir" and "file" within the driver
itself, so it doesn't apply here).

So then the function becomes a lot simpler, if it's written in the
canonical way.  This should probably be documented better in the
Documentation/filesystems/debugfs.rst file...  :/

static void dp_debug_init(struct dp_debug *dp_debug)
{
struct dp_debug_private *debug = container_of(dp_debug,
  struct dp_debug_private, 
dp_debug);

debug->root = debugfs_create_dir(DEBUG_NAME, NULL);
debugfs_create_file("dp_debug", 0444, dir, debug, _debug_fops);
}

d11a93690df7e9 Abhinav Kumar 2020-09-12  222}
d11a93690df7e9 Abhinav Kumar 2020-09-12  223  
d11a93690df7e9 Abhinav Kumar 2020-09-12  224file = 
debugfs_create_file("dp_debug", 0444, dir,
d11a93690df7e9 Abhinav Kumar 2020-09-12  225debug, 
_debug_fops);
d11a93690df7e9 Abhinav Kumar 2020-09-12  226if (IS_ERR_OR_NULL(file)) {
d11a93690df7e9 Abhinav Kumar 2020-09-12  227rc = PTR_ERR(file);
d11a93690df7e9 Abhinav Kumar 2020-09-12  228DRM_ERROR("[%s] debugfs 
create file failed, rc=%d\n",
d11a93690df7e9 Abhinav Kumar 2020-09-12  229  
DEBUG_NAME, rc);
d11a93690df7e9 Abhinav Kumar 2020-09-12  230goto error_remove_dir;
d11a93690df7e9 Abhinav Kumar 2020-09-12  231}
d11a93690df7e9 Abhinav Kumar 2020-09-12  232  
d11a93690df7e9 Abhinav Kumar 2020-09-12  233debug->root = dir;
d11a93690df7e9 Abhinav Kumar 2020-09-12  234return rc;
d11a93690df7e9 Abhinav Kumar 2020-09-12  235   error_remove_dir:
d11a93690df7e9 Abhinav Kumar 2020-09-12  236debugfs_remove(dir);
d11a93690df7e9 Abhinav Kumar 2020-09-12  237   error:
d11a93690df7e9 Abhinav Kumar 2020-09-12  238return rc;
d11a93690df7e9 Abhinav Kumar 2020-09-12  239  }

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


.config.gz
Description: application/gzip


Re: [PATCH] media: i2c: adp1653: fix error handling from a call to adp1653_get_fault

2021-02-28 Thread Sakari Ailus
Hi Dan, Colin,

On Sat, Feb 27, 2021 at 01:17:20PM +0300, Dan Carpenter wrote:
> On Fri, Feb 26, 2021 at 11:22:29PM +, Colin King wrote:
> > From: Colin Ian King 
> > 
> > The error check on rval from the call to adp1653_get_fault currently
> > returns if rval is non-zero. This appears to be incorrect as the
> > following if statement checks for various bit settings in rval so
> > clearly rval is expected to be non-zero at that point. Coverity
> > flagged the if statement up as deadcode.  Fix this so the error
> > return path only occurs when rval is negative.
> > 
> > Addresses-Coverity: ("Logically dead code")
> > Fixes: 287980e49ffc ("remove lots of IS_ERR_VALUE abuses")
> > Signed-off-by: Colin Ian King 
> > ---
> >  drivers/media/i2c/adp1653.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/media/i2c/adp1653.c b/drivers/media/i2c/adp1653.c
> > index 522a0b10e415..1a4878385394 100644
> > --- a/drivers/media/i2c/adp1653.c
> > +++ b/drivers/media/i2c/adp1653.c
> > @@ -170,7 +170,7 @@ static int adp1653_set_ctrl(struct v4l2_ctrl *ctrl)
> > int rval;
> >  
> > rval = adp1653_get_fault(flash);
> > -   if (rval)
> > +   if (rval < 0)
> > return rval;
> 
> This is good, but all the other callers need to fixed as well:
> 
> 
>140  static int adp1653_get_ctrl(struct v4l2_ctrl *ctrl)
>141  {
>142  struct adp1653_flash *flash =
>143  container_of(ctrl->handler, struct adp1653_flash, 
> ctrls);
>144  int rval;
>145  
>146  rval = adp1653_get_fault(flash);
>147  if (rval)
>148  return rval;
>149  
>150  ctrl->cur.val = 0;
>151  
>152  if (flash->fault & ADP1653_REG_FAULT_FLT_SCP)
> 
> flash->fault is the equivalent of "rval" for non-negative returns so
> this condition can never be true.  We should never be returning these
> weird firmware ADP1653_REG_FAULT_FLT_SCP fault codes to the v4l2 layers.

I think this could be fixed and cleaned up by always retuning zero on
success, and checking for flash->faults while holding the mutex in
adp1653_init_device. I could fix that, too, just let me know...

-- 
Regards,

Sakari Ailus


Re: linux kernel bug???

2021-02-28 Thread Lukas Bulwahn
Hi,

On Mon, Mar 1, 2021 at 7:58 AM  wrote:
>
> This is the first time for me to report something, so maybe the format is not 
> right. Please  correct me if I'm wrong. Thank you ~
> When using Syzkaller to fuzz Linux kernel 5.11.0, it reported one 
> null-ptr-def bug in file.c. The information is as follows:
>
> The kernel's commit:   c03c21ba6
> The syzkaller commit: 52e3731913ab2677be27c29ed8142b04e8f28521
>

This looks like a valid kernel issue found with syzkaller.

Given that it is reproducible, I suggest you continue with the following steps:

1. Check if it reproduces on v5.12-rc1. If not, there is already a fix
in v5.12-rc1. Try to identify the specific fix by bisection.

2. Check since when this issue occurs, e.g., does it appear on v5.10, v5.9 etc.

3. Bisect it to a specific commit.

4. Report back the results of your bisections.

Lukas

>
>
> The report:
> Syzkaller hit 'KASAN: null-ptr-deref Read in __fget_light' bug.
>
> ==
> audit: type=1400 audit(1614571961.594:8): avc:  denied  { execmem } for  
> pid=294 comm="syz-executor894" scontext=system_u:system_r:kernel_t:s0 
> tcontext=system_u:system_r:kernel_t:s0 tclass=process permissive=1
> BUG: KASAN: null-ptr-deref in instrument_atomic_read 
> include/linux/instrumented.h:71 [inline]
> BUG: KASAN: null-ptr-deref in atomic_read 
> include/asm-generic/atomic-instrumented.h:27 [inline]
> BUG: KASAN: null-ptr-deref in __fget_light+0x4f/0x250 fs/file.c:930
> Read of size 4 at addr  by task io_wqe_worker-0/296
>
> CPU: 1 PID: 296 Comm: io_wqe_worker-0 Not tainted 5.11.0+ #5
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 
> 04/01/2014
> Call Trace:
>  __dump_stack lib/dump_stack.c:79 [inline]
>  dump_stack+0xaf/0xf2 lib/dump_stack.c:120
>  __kasan_report mm/kasan/report.c:400 [inline]
>  kasan_report.cold.9+0x10c/0x10e mm/kasan/report.c:413
>  check_memory_region_inline mm/kasan/generic.c:179 [inline]
>  check_memory_region+0x198/0x200 mm/kasan/generic.c:185
>  instrument_atomic_read include/linux/instrumented.h:71 [inline]
>  atomic_read include/asm-generic/atomic-instrumented.h:27 [inline]
>  __fget_light+0x4f/0x250 fs/file.c:930
>  fdget_raw include/linux/file.h:70 [inline]
>  path_init+0x940/0x1290 fs/namei.c:2354
>  path_lookupat.isra.65+0x2c/0x4e0 fs/namei.c:2410
>  filename_lookup.part.80+0x17a/0x370 fs/namei.c:2453
>  filename_lookup fs/namei.c:2446 [inline]
>  user_path_at_empty+0x4b/0x80 fs/namei.c:2733
>  user_path_at include/linux/namei.h:60 [inline]
>  vfs_statx+0x108/0x310 fs/stat.c:195
>  do_statx+0xa9/0x120 fs/stat.c:590
>  io_statx fs/io_uring.c:4525 [inline]
>  io_issue_sqe+0x1c31/0x4a50 fs/io_uring.c:6343
>  io_wq_submit_work+0x2f7/0x8e0 fs/io_uring.c:6418
>  io_worker_handle_work+0xcdd/0x1900 fs/io-wq.c:561
>  io_wqe_worker+0xa15/0xeb0 fs/io-wq.c:603
>  kthread+0x32a/0x3f0 kernel/kthread.c:292
>  ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:294
> ==
>
>
> Syzkaller reproducer:
> # {Threaded:false Collide:false Repeat:false RepeatTimes:0 Procs:1 Slowdown:1 
> Sandbox: Fault:false FaultCall:-1 FaultNth:0 Leak:false NetInjection:false 
> NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false 
> KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false 
> Sysctl:false UseTmpDir:false HandleSegv:false Repro:false Trace:false}
> r0 = syz_io_uring_setup(0x1, &(0x7f80)={0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
> 0x0}, &(0x7f0a)=nil, &(0x7f0b)=nil, 
> &(0x7f000100)=0x0, &(0x7f000140)=0x0)
> syz_io_uring_submit(r1, r2, &(0x7f0008c0)=@IORING_OP_STATX={0x15, 0x0, 
> 0x0, 0x, 0x0, &(0x7f0003c0)='./file1\x00', 0x20, 0x1000}, 
> 0x3)
> io_uring_enter(r0, 0x1, 0x1, 0x1, 0x0, 0x0)
>
>
> C reproducer:
> // autogenerated by syzkaller (https://github.com/google/syzkaller)
>
> #define _GNU_SOURCE
>
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
>
> #define SIZEOF_IO_URING_SQE 64
> #define SIZEOF_IO_URING_CQE 16
> #define SQ_HEAD_OFFSET 0
> #define SQ_TAIL_OFFSET 64
> #define SQ_RING_MASK_OFFSET 256
> #define SQ_RING_ENTRIES_OFFSET 264
> #define SQ_FLAGS_OFFSET 276
> #define SQ_DROPPED_OFFSET 272
> #define CQ_HEAD_OFFSET 128
> #define CQ_TAIL_OFFSET 192
> #define CQ_RING_MASK_OFFSET 260
> #define CQ_RING_ENTRIES_OFFSET 268
> #define CQ_RING_OVERFLOW_OFFSET 284
> #define CQ_FLAGS_OFFSET 280
> #define CQ_CQES_OFFSET 320
>
> struct io_sqring_offsets {
> uint32_t head;
> uint32_t tail;
> uint32_t ring_mask;
> uint32_t ring_entries;
> uint32_t flags;
> uint32_t dropped;
> uint32_t array;
> uint32_t resv1;
> uint64_t resv2;
> };
>
> struct io_cqring_offsets {
> uint32_t head;
> uint32_t tail;
> uint32_t ring_mask;
> uint32_t ring_entries;
> uint32_t overflow;
> uint32_t cqes;
> uint64_t resv[2];
> };
>
> struct io_uring_params {
> 

Re: [PATCH v3 1/3] firmware: xilinx: Add pinctrl support

2021-02-28 Thread Michal Simek
Hi Noburiho,

On 2/28/21 1:17 AM, Nobuhiro Iwamatsu wrote:
> Hi,
> 
> 2021年2月12日(金) 21:10 Sai Krishna Potthuri
> :
>>
>> Adding pinctrl support to query platform specific information (pins)
>> from firmware.
>>
>> Signed-off-by: Sai Krishna Potthuri 
>> Acked-by: Michal Simek 
>> ---
>>  drivers/firmware/xilinx/zynqmp.c | 114 +++
>>  include/linux/firmware/xlnx-zynqmp.h |  90 +
>>  2 files changed, 204 insertions(+)
>>
>> diff --git a/drivers/firmware/xilinx/zynqmp.c 
>> b/drivers/firmware/xilinx/zynqmp.c
>> index efb8a66efc68..299c3d5a9ebd 100644
>> --- a/drivers/firmware/xilinx/zynqmp.c
>> +++ b/drivers/firmware/xilinx/zynqmp.c
>> @@ -784,6 +784,120 @@ int zynqmp_pm_fpga_get_status(u32 *value)
>>  }
>>  EXPORT_SYMBOL_GPL(zynqmp_pm_fpga_get_status);
>>
> 
> 
> 
>> @@ -125,6 +131,12 @@ enum pm_query_id {
>> PM_QID_CLOCK_GET_FIXEDFACTOR_PARAMS,
>> PM_QID_CLOCK_GET_PARENTS,
>> PM_QID_CLOCK_GET_ATTRIBUTES,
>> +   PM_QID_PINCTRL_GET_NUM_PINS = 6,
>> +   PM_QID_PINCTRL_GET_NUM_FUNCTIONS = 7,
>> +   PM_QID_PINCTRL_GET_NUM_FUNCTION_GROUPS = 8,
>> +   PM_QID_PINCTRL_GET_FUNCTION_NAME = 9,
>> +   PM_QID_PINCTRL_GET_FUNCTION_GROUPS = 10,
>> +   PM_QID_PINCTRL_GET_PIN_GROUPS = 11,
> 
> These do not have to have values, Because PM_QID_INVALID is 0.
> 
>> PM_QID_CLOCK_GET_NUM_CLOCKS = 12,
> 
> And you can drop value from this.

Please take a look at
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/firmware/xlnx-zynqmp.h?h=v5.12-rc1=1077d4367ab3b97f6db2f66c87289af863652215

We are using explicit values as was recommended by Greg.

Thanks,
Michal


-- 
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs



drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c:106 dpu_rm_init() warn: passing zero to 'PTR_ERR'

2021-02-28 Thread Dan Carpenter
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   fe07bfda2fb9cdef8a4d4008a409bb02f35f1bd8
commit: bb00a452d6f77391441ef7df48f7115dd459cd2f drm/msm/dpu: Refactor resource 
manager
config: arm64-randconfig-m031-20210301 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 9.3.0

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

New smatch warnings:
drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c:106 dpu_rm_init() warn: passing zero to 
'PTR_ERR'

Old smatch warnings:
drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c:135 dpu_rm_init() warn: passing zero to 
'PTR_ERR'
drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c:157 dpu_rm_init() warn: passing zero to 
'PTR_ERR'
drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c:174 dpu_rm_init() warn: passing zero to 
'PTR_ERR'

vim +/PTR_ERR +106 drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c

25fdd5933e4c0f Jeykumar Sankaran 2018-06-27   74  int dpu_rm_init(struct dpu_rm 
*rm,
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27   75struct 
dpu_mdss_cfg *cat,
3763f1a5511005 Jeykumar Sankaran 2018-12-07   76void __iomem 
*mmio)
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27   77  {
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27   78int rc, i;
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27   79  
3763f1a5511005 Jeykumar Sankaran 2018-12-07   80if (!rm || !cat || 
!mmio) {
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27   81
DPU_ERROR("invalid kms\n");
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27   82return -EINVAL;
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27   83}
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27   84  
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27   85/* Clear, setup lists */
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27   86memset(rm, 0, 
sizeof(*rm));
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27   87  
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27   88
mutex_init(>rm_lock);
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27   89  
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27   90/* Interrogate HW 
catalog and create tracking items for hw blocks */
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27   91for (i = 0; i < 
cat->mixer_count; i++) {
bb00a452d6f773 Drew Davenport2020-02-19   92struct 
dpu_hw_mixer *hw;
abda0d925f9c06 Stephen Boyd  2019-11-19   93const struct 
dpu_lm_cfg *lm = >mixer[i];
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27   94  
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27   95if 
(lm->pingpong == PINGPONG_MAX) {
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27   96
DPU_DEBUG("skip mixer %d without pingpong\n", lm->id);
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27   97
continue;
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27   98}
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27   99  
bb00a452d6f773 Drew Davenport2020-02-19  100if (lm->id < 
LM_0 || lm->id >= LM_MAX) {
bb00a452d6f773 Drew Davenport2020-02-19  101
DPU_ERROR("skip mixer %d with invalid id\n", lm->id);
bb00a452d6f773 Drew Davenport2020-02-19  102
continue;
bb00a452d6f773 Drew Davenport2020-02-19  103}
bb00a452d6f773 Drew Davenport2020-02-19  104hw = 
dpu_hw_lm_init(lm->id, mmio, cat);
bb00a452d6f773 Drew Davenport2020-02-19  105if 
(IS_ERR_OR_NULL(hw)) {
bb00a452d6f773 Drew Davenport2020-02-19 @106rc = 
PTR_ERR(hw);

The dpu_hw_lm_init() never returns NULL...

bb00a452d6f773 Drew Davenport2020-02-19  107
DPU_ERROR("failed lm object creation: err %d\n", rc);

If it did, then the NULL returns are a special kind of success and they
should not result in an error message.

25fdd5933e4c0f Jeykumar Sankaran 2018-06-27  108goto 
fail;
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27  109}
bb00a452d6f773 Drew Davenport2020-02-19  110
rm->mixer_blks[lm->id - LM_0] = >base;
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27  111  
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27  112if 
(!rm->lm_max_width) {
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27  113
rm->lm_max_width = lm->sblk->maxwidth;
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27  114} else if 
(rm->lm_max_width != lm->sblk->maxwidth) {
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27  115/*
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27  116 * 
Don't expect to have hw where lm max widths differ.
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27  117 * If 
found, take the min.
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27  118 */
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27  119

drivers/gpu/drm/msm/dp/dp_hpd.c:37 dp_hpd_connect() error: we previously assumed 'hpd_priv->dp_cb' could be null (see line 37)

2021-02-28 Thread Dan Carpenter
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   fe07bfda2fb9cdef8a4d4008a409bb02f35f1bd8
commit: c943b4948b5848fc0e07f875edbd35a973879e22 drm/msm/dp: add displayPort 
driver support
config: arm64-randconfig-m031-20210301 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 9.3.0

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

smatch warnings:
drivers/gpu/drm/msm/dp/dp_hpd.c:37 dp_hpd_connect() error: we previously 
assumed 'hpd_priv->dp_cb' could be null (see line 37)
drivers/gpu/drm/msm/dp/dp_power.c:203 dp_power_clk_enable() warn: inconsistent 
indenting

vim +37 drivers/gpu/drm/msm/dp/dp_hpd.c

c943b4948b5848 Chandan Uddaraju 2020-08-27  27  static int 
dp_hpd_connect(struct dp_usbpd *dp_usbpd, bool hpd)
c943b4948b5848 Chandan Uddaraju 2020-08-27  28  {
c943b4948b5848 Chandan Uddaraju 2020-08-27  29  int rc = 0;
c943b4948b5848 Chandan Uddaraju 2020-08-27  30  struct dp_hpd_private 
*hpd_priv;
c943b4948b5848 Chandan Uddaraju 2020-08-27  31  
c943b4948b5848 Chandan Uddaraju 2020-08-27  32  hpd_priv = 
container_of(dp_usbpd, struct dp_hpd_private,
c943b4948b5848 Chandan Uddaraju 2020-08-27  33  
dp_usbpd);
c943b4948b5848 Chandan Uddaraju 2020-08-27  34  
c943b4948b5848 Chandan Uddaraju 2020-08-27  35  dp_usbpd->hpd_high = 
hpd;
c943b4948b5848 Chandan Uddaraju 2020-08-27  36  
c943b4948b5848 Chandan Uddaraju 2020-08-27 @37  if (!hpd_priv->dp_cb && 
!hpd_priv->dp_cb->configure

^^^
Probably || was intended instead of &&.  If "hpd_priv->dp_cb" is NULL
this will Oops.

c943b4948b5848 Chandan Uddaraju 2020-08-27  38  
&& !hpd_priv->dp_cb->disconnect) {
c943b4948b5848 Chandan Uddaraju 2020-08-27  39  pr_err("hpd 
dp_cb not initialized\n");
c943b4948b5848 Chandan Uddaraju 2020-08-27  40  return -EINVAL;
c943b4948b5848 Chandan Uddaraju 2020-08-27  41  }
c943b4948b5848 Chandan Uddaraju 2020-08-27  42  if (hpd)
c943b4948b5848 Chandan Uddaraju 2020-08-27  43  
hpd_priv->dp_cb->configure(hpd_priv->dev);
c943b4948b5848 Chandan Uddaraju 2020-08-27  44  else
c943b4948b5848 Chandan Uddaraju 2020-08-27  45  
hpd_priv->dp_cb->disconnect(hpd_priv->dev);
c943b4948b5848 Chandan Uddaraju 2020-08-27  46  
c943b4948b5848 Chandan Uddaraju 2020-08-27  47  return rc;
c943b4948b5848 Chandan Uddaraju 2020-08-27  48  }

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


.config.gz
Description: application/gzip


[RFC PATCH v3 4/8] KVM: selftests: Make a generic helper to get vm guest mode strings

2021-02-28 Thread Yanan Wang
For generality and conciseness, make an API which can be used in all
kvm libs and selftests to get vm guest mode strings. And the index i
is checked in the API in case of possiable faults.

Reviewed-by: Andrew Jones 
Suggested-by: Sean Christopherson 
Signed-off-by: Yanan Wang 
---
 .../testing/selftests/kvm/include/kvm_util.h  |  4 +--
 tools/testing/selftests/kvm/lib/kvm_util.c| 29 ---
 2 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/tools/testing/selftests/kvm/include/kvm_util.h 
b/tools/testing/selftests/kvm/include/kvm_util.h
index 2d7eb6989e83..f52a7492f47f 100644
--- a/tools/testing/selftests/kvm/include/kvm_util.h
+++ b/tools/testing/selftests/kvm/include/kvm_util.h
@@ -68,9 +68,6 @@ enum vm_guest_mode {
 #define MIN_PAGE_SIZE  (1U << MIN_PAGE_SHIFT)
 #define PTES_PER_MIN_PAGE  ptes_per_page(MIN_PAGE_SIZE)
 
-#define vm_guest_mode_string(m) vm_guest_mode_string[m]
-extern const char * const vm_guest_mode_string[];
-
 struct vm_guest_mode_params {
unsigned int pa_bits;
unsigned int va_bits;
@@ -84,6 +81,7 @@ int vm_enable_cap(struct kvm_vm *vm, struct kvm_enable_cap 
*cap);
 int vcpu_enable_cap(struct kvm_vm *vm, uint32_t vcpu_id,
struct kvm_enable_cap *cap);
 void vm_enable_dirty_ring(struct kvm_vm *vm, uint32_t ring_size);
+const char *vm_guest_mode_string(uint32_t i);
 
 struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int 
perm);
 void kvm_vm_free(struct kvm_vm *vmp);
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c 
b/tools/testing/selftests/kvm/lib/kvm_util.c
index d787cb802b4a..cc22c4ab7d67 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -141,17 +141,24 @@ static void vm_open(struct kvm_vm *vm, int perm)
"rc: %i errno: %i", vm->fd, errno);
 }
 
-const char * const vm_guest_mode_string[] = {
-   "PA-bits:52,  VA-bits:48,  4K pages",
-   "PA-bits:52,  VA-bits:48, 64K pages",
-   "PA-bits:48,  VA-bits:48,  4K pages",
-   "PA-bits:48,  VA-bits:48, 64K pages",
-   "PA-bits:40,  VA-bits:48,  4K pages",
-   "PA-bits:40,  VA-bits:48, 64K pages",
-   "PA-bits:ANY, VA-bits:48,  4K pages",
-};
-_Static_assert(sizeof(vm_guest_mode_string)/sizeof(char *) == NUM_VM_MODES,
-  "Missing new mode strings?");
+const char *vm_guest_mode_string(uint32_t i)
+{
+   static const char * const strings[] = {
+   [VM_MODE_P52V48_4K] = "PA-bits:52,  VA-bits:48,  4K pages",
+   [VM_MODE_P52V48_64K]= "PA-bits:52,  VA-bits:48, 64K pages",
+   [VM_MODE_P48V48_4K] = "PA-bits:48,  VA-bits:48,  4K pages",
+   [VM_MODE_P48V48_64K]= "PA-bits:48,  VA-bits:48, 64K pages",
+   [VM_MODE_P40V48_4K] = "PA-bits:40,  VA-bits:48,  4K pages",
+   [VM_MODE_P40V48_64K]= "PA-bits:40,  VA-bits:48, 64K pages",
+   [VM_MODE_PXXV48_4K] = "PA-bits:ANY, VA-bits:48,  4K pages",
+   };
+   _Static_assert(sizeof(strings)/sizeof(char *) == NUM_VM_MODES,
+  "Missing new mode strings?");
+
+   TEST_ASSERT(i < NUM_VM_MODES, "Guest mode ID %d too big", i);
+
+   return strings[i];
+}
 
 const struct vm_guest_mode_params vm_guest_mode_params[] = {
{ 52, 48,  0x1000, 12 },
-- 
2.23.0



[RFC PATCH v3 1/8] tools headers: sync headers of asm-generic/hugetlb_encode.h

2021-02-28 Thread Yanan Wang
This patch syncs contents of tools/include/asm-generic/hugetlb_encode.h
and include/uapi/asm-generic/hugetlb_encode.h. Arch powerpc supports 16KB
hugepages and ARM64 supports 32MB/512MB hugepages. The corresponding mmap
flags have already been added in include/uapi/asm-generic/hugetlb_encode.h,
but not tools/include/asm-generic/hugetlb_encode.h.

Cc: Ingo Molnar 
Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Arnaldo Carvalho de Melo 
Signed-off-by: Yanan Wang 
---
 tools/include/asm-generic/hugetlb_encode.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/include/asm-generic/hugetlb_encode.h 
b/tools/include/asm-generic/hugetlb_encode.h
index e4732d3c2998..4f3d5aaa11f5 100644
--- a/tools/include/asm-generic/hugetlb_encode.h
+++ b/tools/include/asm-generic/hugetlb_encode.h
@@ -20,13 +20,16 @@
 #define HUGETLB_FLAG_ENCODE_SHIFT  26
 #define HUGETLB_FLAG_ENCODE_MASK   0x3f
 
+#define HUGETLB_FLAG_ENCODE_16KB   (14 << HUGETLB_FLAG_ENCODE_SHIFT)
 #define HUGETLB_FLAG_ENCODE_64KB   (16 << HUGETLB_FLAG_ENCODE_SHIFT)
 #define HUGETLB_FLAG_ENCODE_512KB  (19 << HUGETLB_FLAG_ENCODE_SHIFT)
 #define HUGETLB_FLAG_ENCODE_1MB(20 << 
HUGETLB_FLAG_ENCODE_SHIFT)
 #define HUGETLB_FLAG_ENCODE_2MB(21 << 
HUGETLB_FLAG_ENCODE_SHIFT)
 #define HUGETLB_FLAG_ENCODE_8MB(23 << 
HUGETLB_FLAG_ENCODE_SHIFT)
 #define HUGETLB_FLAG_ENCODE_16MB   (24 << HUGETLB_FLAG_ENCODE_SHIFT)
+#define HUGETLB_FLAG_ENCODE_32MB   (25 << HUGETLB_FLAG_ENCODE_SHIFT)
 #define HUGETLB_FLAG_ENCODE_256MB  (28 << HUGETLB_FLAG_ENCODE_SHIFT)
+#define HUGETLB_FLAG_ENCODE_512MB  (29 << HUGETLB_FLAG_ENCODE_SHIFT)
 #define HUGETLB_FLAG_ENCODE_1GB(30 << 
HUGETLB_FLAG_ENCODE_SHIFT)
 #define HUGETLB_FLAG_ENCODE_2GB(31 << 
HUGETLB_FLAG_ENCODE_SHIFT)
 #define HUGETLB_FLAG_ENCODE_16GB   (34 << HUGETLB_FLAG_ENCODE_SHIFT)
-- 
2.23.0



[RFC PATCH v3 6/8] KVM: selftests: List all hugetlb src types specified with page sizes

2021-02-28 Thread Yanan Wang
With VM_MEM_SRC_ANONYMOUS_HUGETLB, we currently can only use system
default hugetlb pages to back the testing guest memory. In order to
add flexibility, now list all the known hugetlb backing src types with
different page sizes, so that we can specify use of hugetlb pages of the
exact granularity that we want. And as all the known hugetlb page sizes
are listed, it's appropriate for all architectures.

Besides, the helper get_backing_src_pagesz() is added to get the
granularity of different backing src types(anonumous, thp, hugetlb).

Suggested-by: Ben Gardon 
Signed-off-by: Yanan Wang 
---
 .../testing/selftests/kvm/include/test_util.h | 19 ++-
 tools/testing/selftests/kvm/lib/kvm_util.c|  2 +-
 tools/testing/selftests/kvm/lib/test_util.c   | 56 +++
 3 files changed, 63 insertions(+), 14 deletions(-)

diff --git a/tools/testing/selftests/kvm/include/test_util.h 
b/tools/testing/selftests/kvm/include/test_util.h
index ef24c76ba89a..be5d08bcdca7 100644
--- a/tools/testing/selftests/kvm/include/test_util.h
+++ b/tools/testing/selftests/kvm/include/test_util.h
@@ -70,16 +70,31 @@ struct timespec timespec_div(struct timespec ts, int 
divisor);
 enum vm_mem_backing_src_type {
VM_MEM_SRC_ANONYMOUS,
VM_MEM_SRC_ANONYMOUS_THP,
-   VM_MEM_SRC_ANONYMOUS_HUGETLB,
+   VM_MEM_SRC_ANONYMOUS_HUGETLB_16KB,
+   VM_MEM_SRC_ANONYMOUS_HUGETLB_64KB,
+   VM_MEM_SRC_ANONYMOUS_HUGETLB_512KB,
+   VM_MEM_SRC_ANONYMOUS_HUGETLB_1MB,
+   VM_MEM_SRC_ANONYMOUS_HUGETLB_2MB,
+   VM_MEM_SRC_ANONYMOUS_HUGETLB_8MB,
+   VM_MEM_SRC_ANONYMOUS_HUGETLB_16MB,
+   VM_MEM_SRC_ANONYMOUS_HUGETLB_32MB,
+   VM_MEM_SRC_ANONYMOUS_HUGETLB_256MB,
+   VM_MEM_SRC_ANONYMOUS_HUGETLB_512MB,
+   VM_MEM_SRC_ANONYMOUS_HUGETLB_1GB,
+   VM_MEM_SRC_ANONYMOUS_HUGETLB_2GB,
+   VM_MEM_SRC_ANONYMOUS_HUGETLB_16GB,
+   NUM_SRC_TYPES,
 };
 
 struct vm_mem_backing_src_alias {
const char *name;
-   enum vm_mem_backing_src_type type;
+   uint32_t flag;
 };
 
 bool thp_configured(void);
 size_t get_trans_hugepagesz(void);
+const struct vm_mem_backing_src_alias *vm_mem_backing_src_alias(uint32_t i);
+size_t get_backing_src_pagesz(uint32_t i);
 void backing_src_help(void);
 enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name);
 
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c 
b/tools/testing/selftests/kvm/lib/kvm_util.c
index cc22c4ab7d67..b91c8e3a7ee1 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -757,7 +757,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
region->mmap_start = mmap(NULL, region->mmap_size,
  PROT_READ | PROT_WRITE,
  MAP_PRIVATE | MAP_ANONYMOUS
- | (src_type == VM_MEM_SRC_ANONYMOUS_HUGETLB ? 
MAP_HUGETLB : 0),
+ | vm_mem_backing_src_alias(src_type)->flag,
  -1, 0);
TEST_ASSERT(region->mmap_start != MAP_FAILED,
"test_malloc failed, mmap_start: %p errno: %i",
diff --git a/tools/testing/selftests/kvm/lib/test_util.c 
b/tools/testing/selftests/kvm/lib/test_util.c
index f2d133f76c67..1f5e7241c80e 100644
--- a/tools/testing/selftests/kvm/lib/test_util.c
+++ b/tools/testing/selftests/kvm/lib/test_util.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "linux/kernel.h"
 
 #include "test_util.h"
@@ -112,12 +113,6 @@ void print_skip(const char *fmt, ...)
puts(", skipping test");
 }
 
-const struct vm_mem_backing_src_alias backing_src_aliases[] = {
-   {"anonymous", VM_MEM_SRC_ANONYMOUS,},
-   {"anonymous_thp", VM_MEM_SRC_ANONYMOUS_THP,},
-   {"anonymous_hugetlb", VM_MEM_SRC_ANONYMOUS_HUGETLB,},
-};
-
 bool thp_configured(void)
 {
int ret;
@@ -153,22 +148,61 @@ size_t get_trans_hugepagesz(void)
return size;
 }
 
+const struct vm_mem_backing_src_alias *vm_mem_backing_src_alias(uint32_t i)
+{
+   static const struct vm_mem_backing_src_alias aliases[] = {
+   { "anonymous",   0},
+   { "anonymous_thp",   0},
+   { "anonymous_hugetlb_16kb",  MAP_HUGETLB | MAP_HUGE_16KB  },
+   { "anonymous_hugetlb_64kb",  MAP_HUGETLB | MAP_HUGE_64KB  },
+   { "anonymous_hugetlb_512kb", MAP_HUGETLB | MAP_HUGE_512KB },
+   { "anonymous_hugetlb_1mb",   MAP_HUGETLB | MAP_HUGE_1MB   },
+   { "anonymous_hugetlb_2mb",   MAP_HUGETLB | MAP_HUGE_2MB   },
+   { "anonymous_hugetlb_8mb",   MAP_HUGETLB | MAP_HUGE_8MB   },
+   { "anonymous_hugetlb_16mb",  MAP_HUGETLB | MAP_HUGE_16MB  },
+   { "anonymous_hugetlb_32mb",  MAP_HUGETLB | MAP_HUGE_32MB  },
+   { "anonymous_hugetlb_256mb", MAP_HUGETLB | MAP_HUGE_256MB },
+   { 

[RFC PATCH v3 8/8] KVM: selftests: Add a test for kvm page table code

2021-02-28 Thread Yanan Wang
This test serves as a performance tester and a bug reproducer for
kvm page table code (GPA->HPA mappings), so it gives guidance for
people trying to make some improvement for kvm.

The function guest_code() can cover the conditions where a single vcpu or
multiple vcpus access guest pages within the same memory region, in three
VM stages(before dirty logging, during dirty logging, after dirty logging).
Besides, the backing src memory type(ANONYMOUS/THP/HUGETLB) of the tested
memory region can be specified by users, which means normal page mappings
or block mappings can be chosen by users to be created in the test.

If ANONYMOUS memory is specified, kvm will create normal page mappings
for the tested memory region before dirty logging, and update attributes
of the page mappings from RO to RW during dirty logging. If THP/HUGETLB
memory is specified, kvm will create block mappings for the tested memory
region before dirty logging, and split the blcok mappings into normal page
mappings during dirty logging, and coalesce the page mappings back into
block mappings after dirty logging is stopped.

So in summary, as a performance tester, this test can present the
performance of kvm creating/updating normal page mappings, or the
performance of kvm creating/splitting/recovering block mappings,
through execution time.

When we need to coalesce the page mappings back to block mappings after
dirty logging is stopped, we have to firstly invalidate *all* the TLB
entries for the page mappings right before installation of the block entry,
because a TLB conflict abort error could occur if we can't invalidate the
TLB entries fully. We have hit this TLB conflict twice on aarch64 software
implementation and fixed it. As this test can imulate process from dirty
logging enabled to dirty logging stopped of a VM with block mappings,
so it can also reproduce this TLB conflict abort due to inadequate TLB
invalidation when coalescing tables.

Signed-off-by: Yanan Wang 
---
 tools/testing/selftests/kvm/Makefile  |   3 +
 .../selftests/kvm/kvm_page_table_test.c   | 476 ++
 2 files changed, 479 insertions(+)
 create mode 100644 tools/testing/selftests/kvm/kvm_page_table_test.c

diff --git a/tools/testing/selftests/kvm/Makefile 
b/tools/testing/selftests/kvm/Makefile
index a6d61f451f88..bac81924166d 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -67,6 +67,7 @@ TEST_GEN_PROGS_x86_64 += x86_64/xen_vmcall_test
 TEST_GEN_PROGS_x86_64 += demand_paging_test
 TEST_GEN_PROGS_x86_64 += dirty_log_test
 TEST_GEN_PROGS_x86_64 += dirty_log_perf_test
+TEST_GEN_PROGS_x86_64 += kvm_page_table_test
 TEST_GEN_PROGS_x86_64 += hardware_disable_test
 TEST_GEN_PROGS_x86_64 += kvm_create_max_vcpus
 TEST_GEN_PROGS_x86_64 += memslot_modification_stress_test
@@ -78,6 +79,7 @@ TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list-sve
 TEST_GEN_PROGS_aarch64 += demand_paging_test
 TEST_GEN_PROGS_aarch64 += dirty_log_test
 TEST_GEN_PROGS_aarch64 += dirty_log_perf_test
+TEST_GEN_PROGS_aarch64 += kvm_page_table_test
 TEST_GEN_PROGS_aarch64 += kvm_create_max_vcpus
 TEST_GEN_PROGS_aarch64 += set_memory_region_test
 TEST_GEN_PROGS_aarch64 += steal_time
@@ -87,6 +89,7 @@ TEST_GEN_PROGS_s390x += s390x/resets
 TEST_GEN_PROGS_s390x += s390x/sync_regs_test
 TEST_GEN_PROGS_s390x += demand_paging_test
 TEST_GEN_PROGS_s390x += dirty_log_test
+TEST_GEN_PROGS_s390x += kvm_page_table_test
 TEST_GEN_PROGS_s390x += kvm_create_max_vcpus
 TEST_GEN_PROGS_s390x += set_memory_region_test
 
diff --git a/tools/testing/selftests/kvm/kvm_page_table_test.c 
b/tools/testing/selftests/kvm/kvm_page_table_test.c
new file mode 100644
index ..032b49d1483b
--- /dev/null
+++ b/tools/testing/selftests/kvm/kvm_page_table_test.c
@@ -0,0 +1,476 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * KVM page table test
+ *
+ * Copyright (C) 2021, Huawei, Inc.
+ *
+ * Make sure that THP has been enabled or enough HUGETLB pages with specific
+ * page size have been pre-allocated on your system, if you are planning to
+ * use hugepages to back the guest memory for testing.
+ */
+
+#define _GNU_SOURCE /* for program_invocation_name */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "test_util.h"
+#include "kvm_util.h"
+#include "processor.h"
+#include "guest_modes.h"
+
+#define TEST_MEM_SLOT_INDEX 1
+
+/* Default size(1GB) of the memory for testing */
+#define DEFAULT_TEST_MEM_SIZE  (1 << 30)
+
+/* Default guest test virtual memory offset */
+#define DEFAULT_GUEST_TEST_MEM 0xc000
+
+/* Number of guest memory accessing types(read/write) */
+#define NUM_ACCESS_TYPES   2
+
+/* Different guest memory accessing stages */
+enum test_stage {
+   KVM_BEFORE_MAPPINGS,
+   KVM_CREATE_MAPPINGS,
+   KVM_UPDATE_MAPPINGS,
+   KVM_ADJUST_MAPPINGS,
+   NUM_TEST_STAGES,
+};
+
+static const char * const test_stage_string[] = {
+   "KVM_BEFORE_MAPPINGS",
+   

[RFC PATCH v3 0/7] KVM: selftests: some improvement and a new test for kvm page table

2021-02-28 Thread Yanan Wang
Hi,
This v3 series can mainly include two parts.
Based on kvm queue branch: 
https://git.kernel.org/pub/scm/virt/kvm/kvm.git/log/?h=queue
Links of v1: 
https://lore.kernel.org/lkml/20210208090841.333724-1-wangyana...@huawei.com/
Links of v2: 
https://lore.kernel.org/lkml/20210225055940.18748-1-wangyana...@huawei.com/

In the first part, all the known hugetlb backing src types specified
with different hugepage sizes are listed, so that we can specify use
of hugetlb source of the exact granularity that we want, instead of
the system default ones. And as all the known hugetlb page sizes are
listed, it's appropriate for all architectures. Besides, a helper that
can get granularity of different backing src types(anonumous/thp/hugetlb)
is added, so that we can use the accurate backing src granularity for
kinds of alignment or guest memory accessing of vcpus.

In the second part, a new test is added:
This test is added to serve as a performance tester and a bug reproducer
for kvm page table code (GPA->HPA mappings), it gives guidance for the
people trying to make some improvement for kvm. And the following explains
what we can exactly do through this test.

The function guest_code() can cover the conditions where a single vcpu or
multiple vcpus access guest pages within the same memory region, in three
VM stages(before dirty logging, during dirty logging, after dirty logging).
Besides, the backing src memory type(ANONYMOUS/THP/HUGETLB) of the tested
memory region can be specified by users, which means normal page mappings
or block mappings can be chosen by users to be created in the test.

If ANONYMOUS memory is specified, kvm will create normal page mappings
for the tested memory region before dirty logging, and update attributes
of the page mappings from RO to RW during dirty logging. If THP/HUGETLB
memory is specified, kvm will create block mappings for the tested memory
region before dirty logging, and split the blcok mappings into normal page
mappings during dirty logging, and coalesce the page mappings back into
block mappings after dirty logging is stopped.

So in summary, as a performance tester, this test can present the
performance of kvm creating/updating normal page mappings, or the
performance of kvm creating/splitting/recovering block mappings,
through execution time.

When we need to coalesce the page mappings back to block mappings after
dirty logging is stopped, we have to firstly invalidate *all* the TLB
entries for the page mappings right before installation of the block entry,
because a TLB conflict abort error could occur if we can't invalidate the
TLB entries fully. We have hit this TLB conflict twice on aarch64 software
implementation and fixed it. As this test can imulate process from dirty
logging enabled to dirty logging stopped of a VM with block mappings,
so it can also reproduce this TLB conflict abort due to inadequate TLB
invalidation when coalescing tables.

Links about the TLB conflict abort:
https://lore.kernel.org/lkml/20201201201034.116760-3-wangyana...@huawei.com/

---

Change logs:

v2->v3:
- Add tags of Suggested-by, Reviewed-by in the patches
- Add a generic micro to get hugetlb page sizes
- Some changes for suggestions about v2 series

v1->v2:
- Add a patch to sync header files
- Add helpers to get granularity of different backing src types
- Some changes for suggestions about v1 series

---

Yanan Wang (7):
  tools headers: sync headers of asm-generic/hugetlb_encode.h
  tools headers: Add a macro to get HUGETLB page sizes for mmap
  KVM: selftests: Use flag CLOCK_MONOTONIC_RAW for timing
  KVM: selftests: Make a generic helper to get vm guest mode strings
  KVM: selftests: Add a helper to get system configured THP page size
  KVM: selftests: List all hugetlb src types specified with page sizes
  KVM: selftests: Adapt vm_userspace_mem_region_add to new helpers
  KVM: selftests: Add a test for kvm page table code

 include/uapi/linux/mman.h |   2 +
 tools/include/asm-generic/hugetlb_encode.h|   3 +
 tools/include/uapi/linux/mman.h   |   2 +
 tools/testing/selftests/kvm/Makefile  |   3 +
 .../selftests/kvm/demand_paging_test.c|   8 +-
 .../selftests/kvm/dirty_log_perf_test.c   |  14 +-
 .../testing/selftests/kvm/include/kvm_util.h  |   4 +-
 .../testing/selftests/kvm/include/test_util.h |  21 +-
 .../selftests/kvm/kvm_page_table_test.c   | 476 ++
 tools/testing/selftests/kvm/lib/kvm_util.c|  59 ++-
 tools/testing/selftests/kvm/lib/test_util.c   |  92 +++-
 tools/testing/selftests/kvm/steal_time.c  |   4 +-
 12 files changed, 628 insertions(+), 60 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/kvm_page_table_test.c 

-- 
2.19.1



[RFC PATCH v3 3/8] KVM: selftests: Use flag CLOCK_MONOTONIC_RAW for timing

2021-02-28 Thread Yanan Wang
In addition to function of CLOCK_MONOTONIC, flag CLOCK_MONOTONIC_RAW can
also shield possiable impact of NTP, which can provide more robustness.

Suggested-by: Vitaly Kuznetsov 
Signed-off-by: Yanan Wang 
---
 tools/testing/selftests/kvm/demand_paging_test.c  |  8 
 tools/testing/selftests/kvm/dirty_log_perf_test.c | 14 +++---
 tools/testing/selftests/kvm/lib/test_util.c   |  2 +-
 tools/testing/selftests/kvm/steal_time.c  |  4 ++--
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/tools/testing/selftests/kvm/demand_paging_test.c 
b/tools/testing/selftests/kvm/demand_paging_test.c
index 5f7a229c3af1..efbf0c1e9130 100644
--- a/tools/testing/selftests/kvm/demand_paging_test.c
+++ b/tools/testing/selftests/kvm/demand_paging_test.c
@@ -53,7 +53,7 @@ static void *vcpu_worker(void *data)
vcpu_args_set(vm, vcpu_id, 1, vcpu_id);
run = vcpu_state(vm, vcpu_id);
 
-   clock_gettime(CLOCK_MONOTONIC, );
+   clock_gettime(CLOCK_MONOTONIC_RAW, );
 
/* Let the guest access its memory */
ret = _vcpu_run(vm, vcpu_id);
@@ -86,7 +86,7 @@ static int handle_uffd_page_request(int uffd, uint64_t addr)
copy.len = perf_test_args.host_page_size;
copy.mode = 0;
 
-   clock_gettime(CLOCK_MONOTONIC, );
+   clock_gettime(CLOCK_MONOTONIC_RAW, );
 
r = ioctl(uffd, UFFDIO_COPY, );
if (r == -1) {
@@ -123,7 +123,7 @@ static void *uffd_handler_thread_fn(void *arg)
struct timespec start;
struct timespec ts_diff;
 
-   clock_gettime(CLOCK_MONOTONIC, );
+   clock_gettime(CLOCK_MONOTONIC_RAW, );
while (!quit_uffd_thread) {
struct uffd_msg msg;
struct pollfd pollfd[2];
@@ -336,7 +336,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 
pr_info("Finished creating vCPUs and starting uffd threads\n");
 
-   clock_gettime(CLOCK_MONOTONIC, );
+   clock_gettime(CLOCK_MONOTONIC_RAW, );
 
for (vcpu_id = 0; vcpu_id < nr_vcpus; vcpu_id++) {
pthread_create(_threads[vcpu_id], NULL, vcpu_worker,
diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c 
b/tools/testing/selftests/kvm/dirty_log_perf_test.c
index 04a2641261be..6cff4ccf9525 100644
--- a/tools/testing/selftests/kvm/dirty_log_perf_test.c
+++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c
@@ -50,7 +50,7 @@ static void *vcpu_worker(void *data)
while (!READ_ONCE(host_quit)) {
int current_iteration = READ_ONCE(iteration);
 
-   clock_gettime(CLOCK_MONOTONIC, );
+   clock_gettime(CLOCK_MONOTONIC_RAW, );
ret = _vcpu_run(vm, vcpu_id);
ts_diff = timespec_elapsed(start);
 
@@ -141,7 +141,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
iteration = 0;
host_quit = false;
 
-   clock_gettime(CLOCK_MONOTONIC, );
+   clock_gettime(CLOCK_MONOTONIC_RAW, );
for (vcpu_id = 0; vcpu_id < nr_vcpus; vcpu_id++) {
vcpu_last_completed_iteration[vcpu_id] = -1;
 
@@ -162,7 +162,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
ts_diff.tv_sec, ts_diff.tv_nsec);
 
/* Enable dirty logging */
-   clock_gettime(CLOCK_MONOTONIC, );
+   clock_gettime(CLOCK_MONOTONIC_RAW, );
vm_mem_region_set_flags(vm, PERF_TEST_MEM_SLOT_INDEX,
KVM_MEM_LOG_DIRTY_PAGES);
ts_diff = timespec_elapsed(start);
@@ -174,7 +174,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 * Incrementing the iteration number will start the vCPUs
 * dirtying memory again.
 */
-   clock_gettime(CLOCK_MONOTONIC, );
+   clock_gettime(CLOCK_MONOTONIC_RAW, );
iteration++;
 
pr_debug("Starting iteration %d\n", iteration);
@@ -189,7 +189,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
pr_info("Iteration %d dirty memory time: %ld.%.9lds\n",
iteration, ts_diff.tv_sec, ts_diff.tv_nsec);
 
-   clock_gettime(CLOCK_MONOTONIC, );
+   clock_gettime(CLOCK_MONOTONIC_RAW, );
kvm_vm_get_dirty_log(vm, PERF_TEST_MEM_SLOT_INDEX, bmap);
 
ts_diff = timespec_elapsed(start);
@@ -199,7 +199,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
iteration, ts_diff.tv_sec, ts_diff.tv_nsec);
 
if (dirty_log_manual_caps) {
-   clock_gettime(CLOCK_MONOTONIC, );
+   clock_gettime(CLOCK_MONOTONIC_RAW, );
kvm_vm_clear_dirty_log(vm, PERF_TEST_MEM_SLOT_INDEX, 
bmap, 0,
   host_num_pages);
 
@@ -212,7 +212,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
}
 
/* Disable dirty logging */
-   clock_gettime(CLOCK_MONOTONIC, );
+ 

[RFC PATCH v3 7/8] KVM: selftests: Adapt vm_userspace_mem_region_add to new helpers

2021-02-28 Thread Yanan Wang
With VM_MEM_SRC_ANONYMOUS_THP specified in vm_userspace_mem_region_add(),
we have to get the transparent hugepage size for HVA alignment. With the
new helpers, we can use get_backing_src_pagesz() to check whether THP is
configured and then get the exact configured hugepage size.

As different architectures may have different THP page sizes configured,
this can get the accurate THP page sizes on any platform.

Signed-off-by: Yanan Wang 
---
 tools/testing/selftests/kvm/lib/kvm_util.c | 28 +++---
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c 
b/tools/testing/selftests/kvm/lib/kvm_util.c
index b91c8e3a7ee1..b29402f9f00c 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -18,7 +18,6 @@
 #include 
 #include 
 
-#define KVM_UTIL_PGS_PER_HUGEPG 512
 #define KVM_UTIL_MIN_PFN   2
 
 /* Aligns x up to the next multiple of size. Size must be a power of 2. */
@@ -686,7 +685,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
 {
int ret;
struct userspace_mem_region *region;
-   size_t huge_page_size = KVM_UTIL_PGS_PER_HUGEPG * vm->page_size;
+   size_t backing_src_pagesz = get_backing_src_pagesz(src_type);
size_t alignment;
 
TEST_ASSERT(vm_adjust_num_guest_pages(vm->mode, npages) == npages,
@@ -748,7 +747,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
 #endif
 
if (src_type == VM_MEM_SRC_ANONYMOUS_THP)
-   alignment = max(huge_page_size, alignment);
+   alignment = max(backing_src_pagesz, alignment);
 
/* Add enough memory to align up if necessary */
if (alignment > 1)
@@ -767,22 +766,13 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
region->host_mem = align(region->mmap_start, alignment);
 
/* As needed perform madvise */
-   if (src_type == VM_MEM_SRC_ANONYMOUS || src_type == 
VM_MEM_SRC_ANONYMOUS_THP) {
-   struct stat statbuf;
-
-   ret = stat("/sys/kernel/mm/transparent_hugepage", );
-   TEST_ASSERT(ret == 0 || (ret == -1 && errno == ENOENT),
-   "stat /sys/kernel/mm/transparent_hugepage");
-
-   TEST_ASSERT(ret == 0 || src_type != VM_MEM_SRC_ANONYMOUS_THP,
-   "VM_MEM_SRC_ANONYMOUS_THP requires THP to be 
configured in the host kernel");
-
-   if (ret == 0) {
-   ret = madvise(region->host_mem, npages * vm->page_size,
- src_type == VM_MEM_SRC_ANONYMOUS ? 
MADV_NOHUGEPAGE : MADV_HUGEPAGE);
-   TEST_ASSERT(ret == 0, "madvise failed, addr: %p length: 
0x%lx src_type: %x",
-   region->host_mem, npages * vm->page_size, 
src_type);
-   }
+   if ((src_type == VM_MEM_SRC_ANONYMOUS ||
+src_type == VM_MEM_SRC_ANONYMOUS_THP) && thp_configured()) {
+   ret = madvise(region->host_mem, npages * vm->page_size,
+ src_type == VM_MEM_SRC_ANONYMOUS ? 
MADV_NOHUGEPAGE : MADV_HUGEPAGE);
+   TEST_ASSERT(ret == 0, "madvise failed, addr: %p length: 0x%lx 
src_type: %s",
+   region->host_mem, npages * vm->page_size,
+   vm_mem_backing_src_alias(src_type)->name);
}
 
region->unused_phy_pages = sparsebit_alloc();
-- 
2.23.0



[RFC PATCH v3 5/8] KVM: selftests: Add a helper to get system configured THP page size

2021-02-28 Thread Yanan Wang
If we want to have some tests about transparent hugepages, the system
configured THP hugepage size should better be known by the tests, which
can be used for kinds of alignment or guest memory accessing of vcpus...
So it makes sense to add a helper to get the transparent hugepage size.

With VM_MEM_SRC_ANONYMOUS_THP specified in vm_userspace_mem_region_add(),
we now stat /sys/kernel/mm/transparent_hugepage to check whether THP is
configured in the host kernel before madvise(). Based on this, we can also
read file /sys/kernel/mm/transparent_hugepage/hpage_pmd_size to get THP
hugepage size.

Reviewed-by: Ben Gardon 
Signed-off-by: Yanan Wang 
---
 .../testing/selftests/kvm/include/test_util.h |  2 ++
 tools/testing/selftests/kvm/lib/test_util.c   | 36 +++
 2 files changed, 38 insertions(+)

diff --git a/tools/testing/selftests/kvm/include/test_util.h 
b/tools/testing/selftests/kvm/include/test_util.h
index b7f41399f22c..ef24c76ba89a 100644
--- a/tools/testing/selftests/kvm/include/test_util.h
+++ b/tools/testing/selftests/kvm/include/test_util.h
@@ -78,6 +78,8 @@ struct vm_mem_backing_src_alias {
enum vm_mem_backing_src_type type;
 };
 
+bool thp_configured(void);
+size_t get_trans_hugepagesz(void);
 void backing_src_help(void);
 enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name);
 
diff --git a/tools/testing/selftests/kvm/lib/test_util.c 
b/tools/testing/selftests/kvm/lib/test_util.c
index c7c0627c6842..f2d133f76c67 100644
--- a/tools/testing/selftests/kvm/lib/test_util.c
+++ b/tools/testing/selftests/kvm/lib/test_util.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "linux/kernel.h"
 
 #include "test_util.h"
@@ -117,6 +118,41 @@ const struct vm_mem_backing_src_alias 
backing_src_aliases[] = {
{"anonymous_hugetlb", VM_MEM_SRC_ANONYMOUS_HUGETLB,},
 };
 
+bool thp_configured(void)
+{
+   int ret;
+   struct stat statbuf;
+
+   ret = stat("/sys/kernel/mm/transparent_hugepage", );
+   TEST_ASSERT(ret == 0 || (ret == -1 && errno == ENOENT),
+   "Error in stating /sys/kernel/mm/transparent_hugepage: %d",
+   errno);
+
+   return ret == 0;
+}
+
+size_t get_trans_hugepagesz(void)
+{
+   size_t size;
+   char buf[16];
+   FILE *f;
+
+   TEST_ASSERT(thp_configured(), "THP is not configured in host kernel");
+
+   f = fopen("/sys/kernel/mm/transparent_hugepage/hpage_pmd_size", "r");
+   TEST_ASSERT(f != NULL,
+   "Error in opening transparent_hugepage/hpage_pmd_size: %d",
+   errno);
+
+   if (fread(buf, sizeof(char), sizeof(buf), f) == 0) {
+   fclose(f);
+   TEST_FAIL("Unable to read transparent_hugepage/hpage_pmd_size");
+   }
+
+   size = strtoull(buf, NULL, 10);
+   return size;
+}
+
 void backing_src_help(void)
 {
int i;
-- 
2.23.0



[RFC PATCH v3 2/8] tools headers: Add a macro to get HUGETLB page sizes for mmap

2021-02-28 Thread Yanan Wang
We know that if a system supports multiple hugetlb page sizes,
the desired hugetlb page size can be specified in bits [26:31]
of the flag arguments. The value in these 6 bits will be the
shift of each hugetlb page size.

So add a macro to get the page size shift and then calculate the
corresponding hugetlb page size, using flag x.

Cc: Ben Gardon 
Cc: Ingo Molnar 
Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Arnaldo Carvalho de Melo 
Cc: Arnd Bergmann 
Cc: Michael Kerrisk 
Cc: Thomas Gleixner 
Suggested-by: Ben Gardon 
Signed-off-by: Yanan Wang 
---
 include/uapi/linux/mman.h   | 2 ++
 tools/include/uapi/linux/mman.h | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/include/uapi/linux/mman.h b/include/uapi/linux/mman.h
index f55bc680b5b0..8bd41128a0ee 100644
--- a/include/uapi/linux/mman.h
+++ b/include/uapi/linux/mman.h
@@ -41,4 +41,6 @@
 #define MAP_HUGE_2GB   HUGETLB_FLAG_ENCODE_2GB
 #define MAP_HUGE_16GB  HUGETLB_FLAG_ENCODE_16GB
 
+#define MAP_HUGE_PAGE_SIZE(x) (1 << ((x >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK))
+
 #endif /* _UAPI_LINUX_MMAN_H */
diff --git a/tools/include/uapi/linux/mman.h b/tools/include/uapi/linux/mman.h
index f55bc680b5b0..8bd41128a0ee 100644
--- a/tools/include/uapi/linux/mman.h
+++ b/tools/include/uapi/linux/mman.h
@@ -41,4 +41,6 @@
 #define MAP_HUGE_2GB   HUGETLB_FLAG_ENCODE_2GB
 #define MAP_HUGE_16GB  HUGETLB_FLAG_ENCODE_16GB
 
+#define MAP_HUGE_PAGE_SIZE(x) (1 << ((x >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK))
+
 #endif /* _UAPI_LINUX_MMAN_H */
-- 
2.23.0



drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dspp.c:31 dpu_setup_dspp_pcc() warn: variable dereferenced before check 'ctx' (see line 29)

2021-02-28 Thread Dan Carpenter
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   fe07bfda2fb9cdef8a4d4008a409bb02f35f1bd8
commit: 4259ff7ae509ed880b3a7bb685972c3a3bf4b74b drm/msm/dpu: add support for 
pcc color block in dpu driver
config: arm64-randconfig-m031-20210301 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 9.3.0

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

smatch warnings:
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dspp.c:31 dpu_setup_dspp_pcc() warn: 
variable dereferenced before check 'ctx' (see line 29)

vim +/ctx +31 drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dspp.c

4259ff7ae509ed Kalyan Thota 2020-03-24  28  
4259ff7ae509ed Kalyan Thota 2020-03-24 @29  u32 base = 
ctx->cap->sblk->pcc.base;
   ^
Dereference

4259ff7ae509ed Kalyan Thota 2020-03-24  30  
4259ff7ae509ed Kalyan Thota 2020-03-24 @31  if (!ctx || !base) {

Checked too late

4259ff7ae509ed Kalyan Thota 2020-03-24  32  DRM_ERROR("invalid ctx 
%pK pcc base 0x%x\n", ctx, base);
4259ff7ae509ed Kalyan Thota 2020-03-24  33  return;
4259ff7ae509ed Kalyan Thota 2020-03-24  34  }

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


.config.gz
Description: application/gzip


Re: [PATCH net-next RFC v4] net: hdlc_x25: Queue outgoing LAPB frames

2021-02-28 Thread Martin Schiller

On 2021-02-27 00:03, Xie He wrote:

On Fri, Feb 26, 2021 at 6:21 AM Martin Schiller  wrote:


I have now had a look at it. It works as expected.
I just wonder if it would not be more appropriate to call
the lapb_register() already in x25_hdlc_open(), so that the layer2
(lapb) can already "work" before the hdlc_x25 interface is up.


I think it's better not to keep LAPB running unless hdlc_x25 is up.
If I am the user, I would expect that when I change the X.25 interface
to the DOWN state, the LAPB protocol would be completely stopped and
the LAPB layer would not generate any new frames anymore (even if the
other side wants to connect), and when I change the X.25 interface
back to the UP state, it would be a fresh new start for the LAPB
protocol.

Also, I have a hard time assessing if such a wrap is really 
enforceable.


Sorry. I don't understand what you mean. What "wrap" are you referring 
to?


I mean the change from only one hdlc interface to both hdlc and
hdlc_x25.

I can't estimate how many users are out there and how their setup looks
like.




Unfortunately I have no idea how many users there actually are.


Re: [RFC PATCH 12/12] HV/Storvsc: Add bounce buffer support for Storvsc

2021-02-28 Thread Christoph Hellwig
This should be handled by the DMA mapping layer, just like for native
SEV support.


Re: [PATCH V8 0/4] dt: Add fdtoverlay rule and statically build unittest

2021-02-28 Thread Viresh Kumar
On 12-02-21, 16:48, Viresh Kumar wrote:
> Hi,
> 
> This patchset adds a generic rule for applying overlays using fdtoverlay
> tool and then updates unittests to get built statically using the same.
> 
> V7->V8:
> - Patch 1 is new.
> - Platforms need to use dtb-y += foo.dtb instead of overlay-y +=
>   foo.dtb.
> - Use multi_depend instead of .SECONDEXPANSION.
> - Use dtb-y for unittest instead of overlay-y.
> - Rename the commented dtb filess in unittest Makefile as .dtbo.
> - Improved Makefile code (I am learning a lot every day :)

Ping!

-- 
viresh


[PATCH V5 1/2] topology: Allow multiple entities to provide sched_freq_tick() callback

2021-02-28 Thread Viresh Kumar
This patch attempts to make it generic enough so other parts of the
kernel can also provide their own implementation of scale_freq_tick()
callback, which is called by the scheduler periodically to update the
per-cpu freq_scale variable.

The implementations now need to provide 'struct scale_freq_data' for the
CPUs for which they have hardware counters available, and a callback
gets registered for each possible CPU in a per-cpu variable.

The arch specific (or ARM AMU) counters are updated to adapt to this and
they take the highest priority if they are available, i.e. they will be
used instead of CPPC based counters for example.

The special code to rebuild the sched domains, in case invariance status
change for the system, is moved out of arm64 specific code and is added
to arch_topology.c.

Note that this also defines SCALE_FREQ_SOURCE_CPUFREQ but doesn't use it
and it is added to show that cpufreq is also acts as source of
information for FIE and will be used by default if no other counters are
supported for a platform.

Reviewed-by: Ionela Voinescu 
Tested-by: Ionela Voinescu 
Signed-off-by: Viresh Kumar 
---
 arch/arm64/include/asm/topology.h |  10 +--
 arch/arm64/kernel/topology.c  | 105 +++---
 drivers/base/arch_topology.c  |  85 ++--
 include/linux/arch_topology.h |  14 +++-
 4 files changed, 134 insertions(+), 80 deletions(-)

diff --git a/arch/arm64/include/asm/topology.h 
b/arch/arm64/include/asm/topology.h
index 3b8dca4eb08d..ec2db3419c41 100644
--- a/arch/arm64/include/asm/topology.h
+++ b/arch/arm64/include/asm/topology.h
@@ -17,17 +17,9 @@ int pcibus_to_node(struct pci_bus *bus);
 #include 
 
 void update_freq_counters_refs(void);
-void topology_scale_freq_tick(void);
-
-#ifdef CONFIG_ARM64_AMU_EXTN
-/*
- * Replace task scheduler's default counter-based
- * frequency-invariance scale factor setting.
- */
-#define arch_scale_freq_tick topology_scale_freq_tick
-#endif /* CONFIG_ARM64_AMU_EXTN */
 
 /* Replace task scheduler's default frequency-invariant accounting */
+#define arch_scale_freq_tick topology_scale_freq_tick
 #define arch_set_freq_scale topology_set_freq_scale
 #define arch_scale_freq_capacity topology_get_freq_scale
 #define arch_scale_freq_invariant topology_scale_freq_invariant
diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
index e08a4126453a..47fca7376c93 100644
--- a/arch/arm64/kernel/topology.c
+++ b/arch/arm64/kernel/topology.c
@@ -199,12 +199,47 @@ static int freq_inv_set_max_ratio(int cpu, u64 max_rate, 
u64 ref_rate)
return 0;
 }
 
-static DEFINE_STATIC_KEY_FALSE(amu_fie_key);
-#define amu_freq_invariant() static_branch_unlikely(_fie_key)
+static void amu_scale_freq_tick(void)
+{
+   u64 prev_core_cnt, prev_const_cnt;
+   u64 core_cnt, const_cnt, scale;
+
+   prev_const_cnt = this_cpu_read(arch_const_cycles_prev);
+   prev_core_cnt = this_cpu_read(arch_core_cycles_prev);
+
+   update_freq_counters_refs();
+
+   const_cnt = this_cpu_read(arch_const_cycles_prev);
+   core_cnt = this_cpu_read(arch_core_cycles_prev);
+
+   if (unlikely(core_cnt <= prev_core_cnt ||
+const_cnt <= prev_const_cnt))
+   return;
+
+   /*
+*  /\corearch_max_freq_scale
+* scale =  --- * 
+*  /\const   SCHED_CAPACITY_SCALE
+*
+* See validate_cpu_freq_invariance_counters() for details on
+* arch_max_freq_scale and the use of SCHED_CAPACITY_SHIFT.
+*/
+   scale = core_cnt - prev_core_cnt;
+   scale *= this_cpu_read(arch_max_freq_scale);
+   scale = div64_u64(scale >> SCHED_CAPACITY_SHIFT,
+ const_cnt - prev_const_cnt);
+
+   scale = min_t(unsigned long, scale, SCHED_CAPACITY_SCALE);
+   this_cpu_write(freq_scale, (unsigned long)scale);
+}
+
+static struct scale_freq_data amu_sfd = {
+   .source = SCALE_FREQ_SOURCE_ARCH,
+   .set_freq_scale = amu_scale_freq_tick,
+};
 
 static void amu_fie_setup(const struct cpumask *cpus)
 {
-   bool invariant;
int cpu;
 
/* We are already set since the last insmod of cpufreq driver */
@@ -221,25 +256,10 @@ static void amu_fie_setup(const struct cpumask *cpus)
 
cpumask_or(amu_fie_cpus, amu_fie_cpus, cpus);
 
-   invariant = topology_scale_freq_invariant();
-
-   /* We aren't fully invariant yet */
-   if (!invariant && !cpumask_equal(amu_fie_cpus, cpu_present_mask))
-   return;
-
-   static_branch_enable(_fie_key);
+   topology_set_scale_freq_source(_sfd, amu_fie_cpus);
 
pr_debug("CPUs[%*pbl]: counters will be used for FIE.",
 cpumask_pr_args(cpus));
-
-   /*
-* Task scheduler behavior depends on frequency invariance support,
-* either cpufreq or counter driven. If the support status changes as
-* a result of counter initialisation and use, retrigger 

[PATCH V5 2/2] cpufreq: CPPC: Add support for frequency invariance

2021-02-28 Thread Viresh Kumar
The Frequency Invariance Engine (FIE) is providing a frequency scaling
correction factor that helps achieve more accurate load-tracking.

Normally, this scaling factor can be obtained directly with the help of
the cpufreq drivers as they know the exact frequency the hardware is
running at. But that isn't the case for CPPC cpufreq driver.

Another way of obtaining that is using the arch specific counter
support, which is already present in kernel, but that hardware is
optional for platforms.

This patch updates the CPPC driver to register itself with the topology
core to provide its own implementation (cppc_scale_freq_tick()) of
topology_scale_freq_tick() which gets called by the scheduler on every
tick. Note that the arch specific counters have higher priority than
CPPC counters, if available, though the CPPC driver doesn't need to have
any special handling for that.

On an invocation of cppc_scale_freq_tick(), we schedule an irq work
(since we reach here from hard-irq context), which then schedules a
normal work item and cppc_scale_freq_workfn() updates the per_cpu
freq_scale variable based on the counter updates since the last tick.

To allow platforms to disable frequency invariance support if they want,
this is all done under CONFIG_ACPI_CPPC_CPUFREQ_FIE, which is enabled by
default.

This also exports sched_setattr_nocheck() as the CPPC driver can be
built as a module.

Cc: Ionela Voinescu 
Cc: linux-a...@vger.kernel.org
Signed-off-by: Viresh Kumar 
---
 drivers/cpufreq/Kconfig.arm|   9 ++
 drivers/cpufreq/cppc_cpufreq.c | 244 +++--
 include/linux/arch_topology.h  |   1 +
 kernel/sched/core.c|   1 +
 4 files changed, 243 insertions(+), 12 deletions(-)

diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
index e65e0a43be64..a3e2d6dfea70 100644
--- a/drivers/cpufreq/Kconfig.arm
+++ b/drivers/cpufreq/Kconfig.arm
@@ -19,6 +19,15 @@ config ACPI_CPPC_CPUFREQ
 
  If in doubt, say N.
 
+config ACPI_CPPC_CPUFREQ_FIE
+   bool "Frequency Invariance support for CPPC cpufreq driver"
+   depends on ACPI_CPPC_CPUFREQ
+   default y
+   help
+ This enables frequency invariance support for CPPC cpufreq driver.
+
+ If in doubt, say N.
+
 config ARM_ALLWINNER_SUN50I_CPUFREQ_NVMEM
tristate "Allwinner nvmem based SUN50I CPUFreq driver"
depends on ARCH_SUNXI
diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
index 8a482c434ea6..c4580a37a1b1 100644
--- a/drivers/cpufreq/cppc_cpufreq.c
+++ b/drivers/cpufreq/cppc_cpufreq.c
@@ -10,14 +10,18 @@
 
 #define pr_fmt(fmt)"CPPC Cpufreq:" fmt
 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -57,6 +61,203 @@ static struct cppc_workaround_oem_info wa_info[] = {
}
 };
 
+#ifdef CONFIG_ACPI_CPPC_CPUFREQ_FIE
+
+/* Frequency invariance support */
+struct cppc_freq_invariance {
+   int cpu;
+   struct irq_work irq_work;
+   struct kthread_work work;
+   struct cppc_perf_fb_ctrs prev_perf_fb_ctrs;
+   struct cppc_cpudata *cpu_data;
+};
+
+static DEFINE_PER_CPU(struct cppc_freq_invariance, cppc_freq_inv);
+static struct kthread_worker *kworker_fie;
+
+static struct cpufreq_driver cppc_cpufreq_driver;
+static unsigned int hisi_cppc_cpufreq_get_rate(unsigned int cpu);
+static int cppc_perf_from_fbctrs(struct cppc_cpudata *cpu_data,
+struct cppc_perf_fb_ctrs fb_ctrs_t0,
+struct cppc_perf_fb_ctrs fb_ctrs_t1);
+
+/**
+ * cppc_scale_freq_workfn - CPPC freq_scale updater for frequency invariance
+ * @work: The work item.
+ *
+ * The CPPC driver register itself with the topology core to provide its own
+ * implementation (cppc_scale_freq_tick()) of topology_scale_freq_tick() which
+ * gets called by the scheduler on every tick.
+ *
+ * Note that the arch specific counters have higher priority than CPPC 
counters,
+ * if available, though the CPPC driver doesn't need to have any special
+ * handling for that.
+ *
+ * On an invocation of cppc_scale_freq_tick(), we schedule an irq work (since 
we
+ * reach here from hard-irq context), which then schedules a normal work item
+ * and cppc_scale_freq_workfn() updates the per_cpu freq_scale variable based 
on
+ * the counter updates since the last tick.
+ */
+static void cppc_scale_freq_workfn(struct kthread_work *work)
+{
+   struct cppc_freq_invariance *cppc_fi;
+   struct cppc_perf_fb_ctrs fb_ctrs = {0};
+   struct cppc_cpudata *cpu_data;
+   unsigned long local_freq_scale;
+   u64 perf;
+
+   cppc_fi = container_of(work, struct cppc_freq_invariance, work);
+   cpu_data = cppc_fi->cpu_data;
+
+   if (cppc_get_perf_ctrs(cppc_fi->cpu, _ctrs)) {
+   pr_warn("%s: failed to read perf counters\n", __func__);
+   return;
+   }
+
+   cppc_fi->prev_perf_fb_ctrs = 

[PATCH V5 0/2] cpufreq: cppc: Add support for frequency invariance

2021-02-28 Thread Viresh Kumar
Hello,

CPPC cpufreq driver is used for ARM servers and this patch series tries
to provide counter-based frequency invariance support for them in the
absence for architecture specific counters (like AMUs).

This is tested by:
- /me with some hacks on Hikey, as I didn't have access to the right
  hardware.

- Vincent Guittot on ThunderX2, only initial testing done.

- Ionela Voinescu on Juno R2, though she tested a previous version of
  this.


This is based of 5.12-rc1.

Changes since V4:
- Move some code to policy specific initialization for cppc driver.
- Initialize kthread specific stuff only once in cppc driver.
- Added a kerneldoc comment in cppc driver and improved changelog as
  well.

Changes since V3:
- rebuild_sched_domains_energy() stuff moved from arm64 to drivers/base.
- Added Reviewed/Tested-by Ionela for the first patch.
- Remove unused max_freq field from structure in cppc driver.
- s/cppc_f_i/cppc_freq_inv.
- Fix an per-cpu access, there was a bug in earlier version.
- Create a single kthread which can run on any CPU and takes care of
  work from all the CPUs.
- Do the whole FIE thing under a new CONFIG option for cppc driver.
- Few minor improvements.

Changes since V2:
- Not sending as an RFC anymore.
- Several renames, reordering of code in 1/2 based on Ionela's comments.
- Several rebase changes for 2/2.
- The freq_scale calculations are optimized a bit.
- Better overall commenting and commit logs.

Changes since V1:
- The interface for setting the callbacks is improved, so different
  parts looking to provide their callbacks don't need to think about
  each other.

- Moved to per-cpu storage for storing the callback related data, AMU
  counters have higher priority with this.

--
viresh

Viresh Kumar (2):
  topology: Allow multiple entities to provide sched_freq_tick()
callback
  cpufreq: CPPC: Add support for frequency invariance

 arch/arm64/include/asm/topology.h |  10 +-
 arch/arm64/kernel/topology.c  | 105 +
 drivers/base/arch_topology.c  |  85 ++-
 drivers/cpufreq/Kconfig.arm   |   9 ++
 drivers/cpufreq/cppc_cpufreq.c| 244 --
 include/linux/arch_topology.h |  15 +-
 kernel/sched/core.c   |   1 +
 7 files changed, 377 insertions(+), 92 deletions(-)


base-commit: fe07bfda2fb9cdef8a4d4008a409bb02f35f1bd8
-- 
2.25.0.rc1.19.g042ed3e048af



[PATCH] drm/amd/display: Remove unnecessary conversion to bool

2021-02-28 Thread Jiapeng Chong
Fix the following coccicheck warnings:

./drivers/gpu/drm/amd/display/dc/dcn30/dcn30_dpp_cm.c:298:33-38:
WARNING: conversion to bool not needed here.

Reported-by: Abaci Robot 
Signed-off-by: Jiapeng Chong 
---
 drivers/gpu/drm/amd/display/dc/dcn30/dcn30_dpp_cm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_dpp_cm.c 
b/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_dpp_cm.c
index 3398540..fbefbba 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_dpp_cm.c
+++ b/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_dpp_cm.c
@@ -295,7 +295,7 @@ bool dpp3_program_gamcor_lut(
cm_helper_program_gamcor_xfer_func(dpp_base->ctx, params, _regs);
 
dpp3_program_gammcor_lut(dpp_base, params->rgb_resulted, 
params->hw_points_num,
-   next_mode == LUT_RAM_A ? true:false);
+next_mode == LUT_RAM_A);
 
//select Gamma LUT to use for next frame
REG_UPDATE(CM_GAMCOR_CONTROL, CM_GAMCOR_SELECT, next_mode == LUT_RAM_A 
? 0:1);
-- 
1.8.3.1



[PATCH v3 4/4] clk: rockchip: add clock controller for rk3568

2021-02-28 Thread Elaine Zhang
Add the clock tree definition for the new rk3568 SoC.

Signed-off-by: Elaine Zhang 
---
 drivers/clk/rockchip/Kconfig  |7 +
 drivers/clk/rockchip/Makefile |1 +
 drivers/clk/rockchip/clk-rk3568.c | 1726 +
 drivers/clk/rockchip/clk.h|   30 +-
 4 files changed, 1763 insertions(+), 1 deletion(-)
 create mode 100644 drivers/clk/rockchip/clk-rk3568.c

diff --git a/drivers/clk/rockchip/Kconfig b/drivers/clk/rockchip/Kconfig
index effd05032e85..2e31901f4213 100644
--- a/drivers/clk/rockchip/Kconfig
+++ b/drivers/clk/rockchip/Kconfig
@@ -85,4 +85,11 @@ config CLK_RK3399
default y
help
  Build the driver for RK3399 Clock Driver.
+
+config CLK_RK3568
+   tristate "Rockchip RK3568 clock controller support"
+   depends on (ARM64 || COMPILE_TEST)
+   default y
+   help
+ Build the driver for RK3568 Clock Driver.
 endif
diff --git a/drivers/clk/rockchip/Makefile b/drivers/clk/rockchip/Makefile
index a99e4d9bbae1..2b78f1247372 100644
--- a/drivers/clk/rockchip/Makefile
+++ b/drivers/clk/rockchip/Makefile
@@ -26,3 +26,4 @@ obj-$(CONFIG_CLK_RK3308)+= clk-rk3308.o
 obj-$(CONFIG_CLK_RK3328)+= clk-rk3328.o
 obj-$(CONFIG_CLK_RK3368)+= clk-rk3368.o
 obj-$(CONFIG_CLK_RK3399)+= clk-rk3399.o
+obj-$(CONFIG_CLK_RK3568)   += clk-rk3568.o
diff --git a/drivers/clk/rockchip/clk-rk3568.c 
b/drivers/clk/rockchip/clk-rk3568.c
new file mode 100644
index ..60913aa91897
--- /dev/null
+++ b/drivers/clk/rockchip/clk-rk3568.c
@@ -0,0 +1,1726 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2021 Rockchip Electronics Co. Ltd.
+ * Author: Elaine Zhang 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "clk.h"
+
+#define RK3568_GRF_SOC_STATUS0 0x580
+
+enum rk3568_pmu_plls {
+   ppll, hpll,
+};
+
+enum rk3568_plls {
+   apll, dpll, gpll, cpll, npll, vpll,
+};
+
+static struct rockchip_pll_rate_table rk3568_pll_rates[] = {
+   /* _mhz, _refdiv, _fbdiv, _postdiv1, _postdiv2, _dsmpd, _frac */
+   RK3036_PLL_RATE(220800, 1, 92, 1, 1, 1, 0),
+   RK3036_PLL_RATE(218400, 1, 91, 1, 1, 1, 0),
+   RK3036_PLL_RATE(216000, 1, 90, 1, 1, 1, 0),
+   RK3036_PLL_RATE(208800, 1, 87, 1, 1, 1, 0),
+   RK3036_PLL_RATE(206400, 1, 86, 1, 1, 1, 0),
+   RK3036_PLL_RATE(204000, 1, 85, 1, 1, 1, 0),
+   RK3036_PLL_RATE(201600, 1, 84, 1, 1, 1, 0),
+   RK3036_PLL_RATE(199200, 1, 83, 1, 1, 1, 0),
+   RK3036_PLL_RATE(192000, 1, 80, 1, 1, 1, 0),
+   RK3036_PLL_RATE(189600, 1, 79, 1, 1, 1, 0),
+   RK3036_PLL_RATE(18, 1, 75, 1, 1, 1, 0),
+   RK3036_PLL_RATE(170400, 1, 71, 1, 1, 1, 0),
+   RK3036_PLL_RATE(160800, 1, 67, 1, 1, 1, 0),
+   RK3036_PLL_RATE(16, 3, 200, 1, 1, 1, 0),
+   RK3036_PLL_RATE(158400, 1, 132, 2, 1, 1, 0),
+   RK3036_PLL_RATE(156000, 1, 130, 2, 1, 1, 0),
+   RK3036_PLL_RATE(153600, 1, 128, 2, 1, 1, 0),
+   RK3036_PLL_RATE(151200, 1, 126, 2, 1, 1, 0),
+   RK3036_PLL_RATE(148800, 1, 124, 2, 1, 1, 0),
+   RK3036_PLL_RATE(146400, 1, 122, 2, 1, 1, 0),
+   RK3036_PLL_RATE(144000, 1, 120, 2, 1, 1, 0),
+   RK3036_PLL_RATE(141600, 1, 118, 2, 1, 1, 0),
+   RK3036_PLL_RATE(14, 3, 350, 2, 1, 1, 0),
+   RK3036_PLL_RATE(139200, 1, 116, 2, 1, 1, 0),
+   RK3036_PLL_RATE(136800, 1, 114, 2, 1, 1, 0),
+   RK3036_PLL_RATE(134400, 1, 112, 2, 1, 1, 0),
+   RK3036_PLL_RATE(132000, 1, 110, 2, 1, 1, 0),
+   RK3036_PLL_RATE(129600, 1, 108, 2, 1, 1, 0),
+   RK3036_PLL_RATE(127200, 1, 106, 2, 1, 1, 0),
+   RK3036_PLL_RATE(124800, 1, 104, 2, 1, 1, 0),
+   RK3036_PLL_RATE(12, 1, 100, 2, 1, 1, 0),
+   RK3036_PLL_RATE(118800, 1, 99, 2, 1, 1, 0),
+   RK3036_PLL_RATE(110400, 1, 92, 2, 1, 1, 0),
+   RK3036_PLL_RATE(11, 3, 275, 2, 1, 1, 0),
+   RK3036_PLL_RATE(100800, 1, 84, 2, 1, 1, 0),
+   RK3036_PLL_RATE(10, 3, 250, 2, 1, 1, 0),
+   RK3036_PLL_RATE(91200, 1, 76, 2, 1, 1, 0),
+   RK3036_PLL_RATE(81600, 1, 68, 2, 1, 1, 0),
+   RK3036_PLL_RATE(8, 3, 200, 2, 1, 1, 0),
+   RK3036_PLL_RATE(7, 3, 350, 4, 1, 1, 0),
+   RK3036_PLL_RATE(69600, 1, 116, 4, 1, 1, 0),
+   RK3036_PLL_RATE(6, 1, 100, 4, 1, 1, 0),
+   RK3036_PLL_RATE(59400, 1, 99, 4, 1, 1, 0),
+   RK3036_PLL_RATE(5, 1, 125, 6, 1, 1, 0),
+   RK3036_PLL_RATE(40800, 1, 68, 2, 2, 1, 0),
+   RK3036_PLL_RATE(31200, 1, 78, 6, 1, 1, 0),
+   RK3036_PLL_RATE(21600, 1, 72, 4, 2, 1, 0),
+   RK3036_PLL_RATE(2, 1, 100, 3, 4, 1, 0),
+   RK3036_PLL_RATE(14850, 1, 99, 4, 4, 1, 0),
+   RK3036_PLL_RATE(1, 1, 150, 6, 6, 1, 0),
+   RK3036_PLL_RATE(9600, 1, 96, 6, 4, 1, 0),
+   RK3036_PLL_RATE(7425, 2, 

[PATCH v3 2/4] clk: rockchip: add dt-binding header for rk3568

2021-02-28 Thread Elaine Zhang
Add the dt-bindings header for the rk3568, that gets shared between
the clock controller and the clock references in the dts.
Add softreset ID for rk3568.

Signed-off-by: Elaine Zhang 
---
 include/dt-bindings/clock/rk3568-cru.h | 926 +
 1 file changed, 926 insertions(+)
 create mode 100644 include/dt-bindings/clock/rk3568-cru.h

diff --git a/include/dt-bindings/clock/rk3568-cru.h 
b/include/dt-bindings/clock/rk3568-cru.h
new file mode 100644
index ..d29890865150
--- /dev/null
+++ b/include/dt-bindings/clock/rk3568-cru.h
@@ -0,0 +1,926 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2021 Rockchip Electronics Co. Ltd.
+ * Author: Elaine Zhang 
+ */
+
+#ifndef _DT_BINDINGS_CLK_ROCKCHIP_RK3568_H
+#define _DT_BINDINGS_CLK_ROCKCHIP_RK3568_H
+
+/* pmucru-clocks indices */
+
+/* pmucru plls */
+#define PLL_PPLL   1
+#define PLL_HPLL   2
+
+/* pmucru clocks */
+#define XIN_OSC0_DIV   4
+#define CLK_RTC_32K5
+#define CLK_PMU6
+#define CLK_I2C0   7
+#define CLK_RTC32K_FRAC8
+#define CLK_UART0_DIV  9
+#define CLK_UART0_FRAC 10
+#define SCLK_UART0 11
+#define DBCLK_GPIO012
+#define CLK_PWM0   13
+#define CLK_CAPTURE_PWM0_NDFT  14
+#define CLK_PMUPVTM15
+#define CLK_CORE_PMUPVTM   16
+#define CLK_REF24M 17
+#define XIN_OSC0_USBPHY0_G 18
+#define CLK_USBPHY0_REF19
+#define XIN_OSC0_USBPHY1_G 20
+#define CLK_USBPHY1_REF21
+#define XIN_OSC0_MIPIDSIPHY0_G 22
+#define CLK_MIPIDSIPHY0_REF23
+#define XIN_OSC0_MIPIDSIPHY1_G 24
+#define CLK_MIPIDSIPHY1_REF25
+#define CLK_WIFI_DIV   26
+#define CLK_WIFI_OSC0  27
+#define CLK_WIFI   28
+#define CLK_PCIEPHY0_DIV   29
+#define CLK_PCIEPHY0_OSC0  30
+#define CLK_PCIEPHY0_REF   31
+#define CLK_PCIEPHY1_DIV   32
+#define CLK_PCIEPHY1_OSC0  33
+#define CLK_PCIEPHY1_REF   34
+#define CLK_PCIEPHY2_DIV   35
+#define CLK_PCIEPHY2_OSC0  36
+#define CLK_PCIEPHY2_REF   37
+#define CLK_PCIE30PHY_REF_M38
+#define CLK_PCIE30PHY_REF_N39
+#define CLK_HDMI_REF   40
+#define XIN_OSC0_EDPPHY_G  41
+#define PCLK_PDPMU 42
+#define PCLK_PMU   43
+#define PCLK_UART0 44
+#define PCLK_I2C0  45
+#define PCLK_GPIO0 46
+#define PCLK_PMUPVTM   47
+#define PCLK_PWM0  48
+#define CLK_PDPMU  49
+#define SCLK_32K_IOE   50
+
+#define CLKPMU_NR_CLKS (SCLK_32K_IOE + 1)
+
+/* cru-clocks indices */
+
+/* cru plls */
+#define PLL_APLL   1
+#define PLL_DPLL   2
+#define PLL_CPLL   3
+#define PLL_GPLL   4
+#define PLL_VPLL   5
+#define PLL_NPLL   6
+
+/* cru clocks */
+#define CPLL_333M  9
+#define ARMCLK 10
+#define USB480M11
+#define ACLK_CORE_NIU2BUS  18
+#define CLK_CORE_PVTM  19
+#define CLK_CORE_PVTM_CORE 20
+#define CLK_CORE_PVTPLL21
+#define CLK_GPU_SRC22
+#define CLK_GPU_PRE_NDFT   23
+#define CLK_GPU_PRE_MUX24
+#define ACLK_GPU_PRE   25
+#define PCLK_GPU_PRE   26
+#define CLK_GPU27
+#define CLK_GPU_NP528
+#define PCLK_GPU_PVTM  29
+#define CLK_GPU_PVTM   30
+#define CLK_GPU_PVTM_CORE  31
+#define CLK_GPU_PVTPLL 32
+#define CLK_NPU_SRC33
+#define CLK_NPU_PRE_NDFT   34
+#define CLK_NPU35
+#define CLK_NPU_NP536
+#define HCLK_NPU_PRE   37
+#define PCLK_NPU_PRE   38
+#define ACLK_NPU_PRE   39
+#define ACLK_NPU   40
+#define HCLK_NPU   41
+#define PCLK_NPU_PVTM  42
+#define CLK_NPU_PVTM   43
+#define CLK_NPU_PVTM_CORE  44
+#define CLK_NPU_PVTPLL 45
+#define CLK_DDRPHY1X_SRC   46
+#define CLK_DDRPHY1X_HWFFC_SRC 47
+#define CLK_DDR1X  48
+#define CLK_MSCH   49
+#define CLK24_DDRMON   50
+#define ACLK_GIC_AUDIO 51
+#define HCLK_GIC_AUDIO 52
+#define HCLK_SDMMC_BUFFER  53
+#define DCLK_SDMMC_BUFFER  54
+#define ACLK_GIC60055
+#define ACLK_SPINLOCK  56
+#define HCLK_I2S0_8CH  57
+#define HCLK_I2S1_8CH  58
+#define HCLK_I2S2_2CH  59
+#define HCLK_I2S3_2CH  60
+#define CLK_I2S0_8CH_TX_SRC61
+#define CLK_I2S0_8CH_TX_FRAC   62
+#define MCLK_I2S0_8CH_TX   63
+#define I2S0_MCLKOUT_TX64
+#define CLK_I2S0_8CH_RX_SRC65
+#define CLK_I2S0_8CH_RX_FRAC   66
+#define MCLK_I2S0_8CH_RX   67
+#define I2S0_MCLKOUT_RX68
+#define CLK_I2S1_8CH_TX_SRC69
+#define CLK_I2S1_8CH_TX_FRAC   70
+#define MCLK_I2S1_8CH_TX   71
+#define 

[PATCH v3 3/4] clk: rockchip: support more core div setting

2021-02-28 Thread Elaine Zhang
Use arrays to support more core independent div settings.
A55 supports each core to work at different frequencies, and each core
has an independent divider control.

Signed-off-by: Elaine Zhang 
---
 drivers/clk/rockchip/clk-cpu.c| 53 +--
 drivers/clk/rockchip/clk-px30.c   |  7 ++--
 drivers/clk/rockchip/clk-rk3036.c |  7 ++--
 drivers/clk/rockchip/clk-rk3128.c |  7 ++--
 drivers/clk/rockchip/clk-rk3188.c |  7 ++--
 drivers/clk/rockchip/clk-rk3228.c |  7 ++--
 drivers/clk/rockchip/clk-rk3288.c |  7 ++--
 drivers/clk/rockchip/clk-rk3308.c |  7 ++--
 drivers/clk/rockchip/clk-rk3328.c |  7 ++--
 drivers/clk/rockchip/clk-rk3368.c | 14 
 drivers/clk/rockchip/clk-rk3399.c | 14 
 drivers/clk/rockchip/clk-rv1108.c |  7 ++--
 drivers/clk/rockchip/clk.h| 24 +++---
 13 files changed, 94 insertions(+), 74 deletions(-)

diff --git a/drivers/clk/rockchip/clk-cpu.c b/drivers/clk/rockchip/clk-cpu.c
index fa9027fb1920..47288197c9d7 100644
--- a/drivers/clk/rockchip/clk-cpu.c
+++ b/drivers/clk/rockchip/clk-cpu.c
@@ -84,10 +84,10 @@ static unsigned long rockchip_cpuclk_recalc_rate(struct 
clk_hw *hw,
 {
struct rockchip_cpuclk *cpuclk = to_rockchip_cpuclk_hw(hw);
const struct rockchip_cpuclk_reg_data *reg_data = cpuclk->reg_data;
-   u32 clksel0 = readl_relaxed(cpuclk->reg_base + reg_data->core_reg);
+   u32 clksel0 = readl_relaxed(cpuclk->reg_base + reg_data->core_reg[0]);
 
-   clksel0 >>= reg_data->div_core_shift;
-   clksel0 &= reg_data->div_core_mask;
+   clksel0 >>= reg_data->div_core_shift[0];
+   clksel0 &= reg_data->div_core_mask[0];
return parent_rate / (clksel0 + 1);
 }
 
@@ -120,6 +120,7 @@ static int rockchip_cpuclk_pre_rate_change(struct 
rockchip_cpuclk *cpuclk,
const struct rockchip_cpuclk_rate_table *rate;
unsigned long alt_prate, alt_div;
unsigned long flags;
+   int i = 0;
 
/* check validity of the new rate */
rate = rockchip_get_cpuclk_settings(cpuclk, ndata->new_rate);
@@ -142,10 +143,10 @@ static int rockchip_cpuclk_pre_rate_change(struct 
rockchip_cpuclk *cpuclk,
if (alt_prate > ndata->old_rate) {
/* calculate dividers */
alt_div =  DIV_ROUND_UP(alt_prate, ndata->old_rate) - 1;
-   if (alt_div > reg_data->div_core_mask) {
+   if (alt_div > reg_data->div_core_mask[0]) {
pr_warn("%s: limiting alt-divider %lu to %d\n",
-   __func__, alt_div, reg_data->div_core_mask);
-   alt_div = reg_data->div_core_mask;
+   __func__, alt_div, reg_data->div_core_mask[0]);
+   alt_div = reg_data->div_core_mask[0];
}
 
/*
@@ -158,19 +159,17 @@ static int rockchip_cpuclk_pre_rate_change(struct 
rockchip_cpuclk *cpuclk,
pr_debug("%s: setting div %lu as alt-rate %lu > old-rate %lu\n",
 __func__, alt_div, alt_prate, ndata->old_rate);
 
-   writel(HIWORD_UPDATE(alt_div, reg_data->div_core_mask,
- reg_data->div_core_shift) |
-  HIWORD_UPDATE(reg_data->mux_core_alt,
-reg_data->mux_core_mask,
-reg_data->mux_core_shift),
-  cpuclk->reg_base + reg_data->core_reg);
-   } else {
-   /* select alternate parent */
-   writel(HIWORD_UPDATE(reg_data->mux_core_alt,
-reg_data->mux_core_mask,
-reg_data->mux_core_shift),
-  cpuclk->reg_base + reg_data->core_reg);
+   for (i = 0; i < reg_data->num_cores; i++) {
+   writel(HIWORD_UPDATE(alt_div, 
reg_data->div_core_mask[i],
+reg_data->div_core_shift[i]),
+  cpuclk->reg_base + reg_data->core_reg[i]);
+   }
}
+   /* select alternate parent */
+   writel(HIWORD_UPDATE(reg_data->mux_core_alt,
+reg_data->mux_core_mask,
+reg_data->mux_core_shift),
+  cpuclk->reg_base + reg_data->core_reg[0]);
 
spin_unlock_irqrestore(cpuclk->lock, flags);
return 0;
@@ -182,6 +181,7 @@ static int rockchip_cpuclk_post_rate_change(struct 
rockchip_cpuclk *cpuclk,
const struct rockchip_cpuclk_reg_data *reg_data = cpuclk->reg_data;
const struct rockchip_cpuclk_rate_table *rate;
unsigned long flags;
+   int i = 0;
 
rate = rockchip_get_cpuclk_settings(cpuclk, ndata->new_rate);
if (!rate) {
@@ -202,12 +202,17 @@ static int rockchip_cpuclk_post_rate_change(struct 
rockchip_cpuclk *cpuclk,
 * primary parent by the extra dividers that were needed for the alt.
 */
 
-   

[PATCH v3 1/4] dt-binding: clock: Document rockchip,rk3568-cru bindings

2021-02-28 Thread Elaine Zhang
Document the device tree bindings of the rockchip Rk3568 SoC
clock driver in 
Documentation/devicetree/bindings/clock/rockchip,rk3568-cru.yaml.

Signed-off-by: Elaine Zhang 
---
 .../bindings/clock/rockchip,rk3568-cru.yaml   | 60 +++
 1 file changed, 60 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/clock/rockchip,rk3568-cru.yaml

diff --git a/Documentation/devicetree/bindings/clock/rockchip,rk3568-cru.yaml 
b/Documentation/devicetree/bindings/clock/rockchip,rk3568-cru.yaml
new file mode 100644
index ..b2c26097827f
--- /dev/null
+++ b/Documentation/devicetree/bindings/clock/rockchip,rk3568-cru.yaml
@@ -0,0 +1,60 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/clock/rockchip,rk3568-cru.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ROCKCHIP rk3568 Family Clock Control Module Binding
+
+maintainers:
+  - Elaine Zhang 
+  - Heiko Stuebner 
+
+description: |
+  The RK3568 clock controller generates the clock and also implements a
+  reset controller for SoC peripherals.
+  (examples: provide SCLK_UART1\PCLK_UART1 and SRST_P_UART1\SRST_S_UART1 for 
UART module)
+  Each clock is assigned an identifier and client nodes can use this identifier
+  to specify the clock which they consume. All available clocks are defined as
+  preprocessor macros in the dt-bindings/clock/rk3568-cru.h headers and can be
+  used in device tree sources.
+
+properties:
+  compatible:
+enum:
+  - rockchip,rk3568-cru
+  - rockchip,rk3568-pmucru
+
+  reg:
+maxItems: 1
+
+  "#clock-cells":
+const: 1
+
+  "#reset-cells":
+const: 1
+
+required:
+  - compatible
+  - reg
+  - "#clock-cells"
+  - "#reset-cells"
+
+additionalProperties: false
+
+examples:
+  # Clock Control Module node:
+  - |
+pmucru: clock-controller@fdd0 {
+  compatible = "rockchip,rk3568-pmucru";
+  reg = <0xfdd0 0x1000>;
+  #clock-cells = <1>;
+  #reset-cells = <1>;
+};
+  - |
+cru: clock-controller@fdd2 {
+  compatible = "rockchip,rk3568-cru";
+  reg = <0xfdd2 0x1000>;
+  #clock-cells = <1>;
+  #reset-cells = <1>;
+};
-- 
2.17.1





[PATCH v3 0/4] clk: rockchip: add clock controller for rk3568

2021-02-28 Thread Elaine Zhang
Add the clock tree definition for the new rk3568 SoC.

Change in V3:
[PATCH v3 1/4]: Fix some code styles.
[PATCH v3 2/4]: No change.
[PATCH v3 3/4]: No change.
[PATCH v3 4/4]: No change.

Change in V2:
[PATCH v2 1/4]: Convert rockchip,rk3568-cru.txt to YAML,
And update commit message.
[PATCH v2 2/4]: No change.
[PATCH v2 3/4]: Use arrays to support more core independent div
settings.
[PATCH v2 4/4]: Adapter [PATCH v2 3/4] changes.

Elaine Zhang (4):
  dt-binding: clock: Document rockchip,rk3568-cru bindings
  clk: rockchip: add dt-binding header for rk3568
  clk: rockchip: support more core div setting
  clk: rockchip: add clock controller for rk3568

 .../bindings/clock/rockchip,rk3568-cru.yaml   |   60 +
 drivers/clk/rockchip/Kconfig  |7 +
 drivers/clk/rockchip/Makefile |1 +
 drivers/clk/rockchip/clk-cpu.c|   53 +-
 drivers/clk/rockchip/clk-px30.c   |7 +-
 drivers/clk/rockchip/clk-rk3036.c |7 +-
 drivers/clk/rockchip/clk-rk3128.c |7 +-
 drivers/clk/rockchip/clk-rk3188.c |7 +-
 drivers/clk/rockchip/clk-rk3228.c |7 +-
 drivers/clk/rockchip/clk-rk3288.c |7 +-
 drivers/clk/rockchip/clk-rk3308.c |7 +-
 drivers/clk/rockchip/clk-rk3328.c |7 +-
 drivers/clk/rockchip/clk-rk3368.c |   14 +-
 drivers/clk/rockchip/clk-rk3399.c |   14 +-
 drivers/clk/rockchip/clk-rk3568.c | 1726 +
 drivers/clk/rockchip/clk-rv1108.c |7 +-
 drivers/clk/rockchip/clk.h|   54 +-
 include/dt-bindings/clock/rk3568-cru.h|  926 +
 18 files changed, 2843 insertions(+), 75 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/clock/rockchip,rk3568-cru.yaml
 create mode 100644 drivers/clk/rockchip/clk-rk3568.c
 create mode 100644 include/dt-bindings/clock/rk3568-cru.h

-- 
2.17.1





RE: [PATCH V3 XRT Alveo 01/18] Documentation: fpga: Add a document describing XRT Alveo drivers

2021-02-28 Thread Sonal Santan
Hello Tom,

> -Original Message-
> From: Tom Rix 
> Sent: Friday, February 19, 2021 2:26 PM
> To: Lizhi Hou ; linux-kernel@vger.kernel.org
> Cc: Lizhi Hou ; linux-f...@vger.kernel.org; Max Zhen
> ; Sonal Santan ; Michal Simek
> ; Stefano Stabellini ;
> devicet...@vger.kernel.org; m...@kernel.org; r...@kernel.org; Max Zhen
> 
> Subject: Re: [PATCH V3 XRT Alveo 01/18] Documentation: fpga: Add a
> document describing XRT Alveo drivers
> 
> From the documentation, there are a couple of big questions and a bunch of
> word smithing.
> 
> pseudo-bus : do we need a bus ?
We are looking for guidance here. 
> 
> xrt-lib real platform devices that aren't fpga, do they need to move to 
> another
> subsystem ?
> 

Drivers for the IPs that show up in the Alveo shell are not generic enough. 
They 
fit into the framework that XRT uses. Is the idea that that they can be used in 
a 
different context?

> Overall looks good, love the ascii art!
> 
> On 2/17/21 10:40 PM, Lizhi Hou wrote:
> > Describe XRT driver architecture and provide basic overview of Xilinx
> > Alveo platform.
> >
> > Signed-off-by: Sonal Santan 
> > Signed-off-by: Max Zhen 
> > Signed-off-by: Lizhi Hou 
> > ---
> >  Documentation/fpga/index.rst |   1 +
> >  Documentation/fpga/xrt.rst   | 842
> +++
> >  2 files changed, 843 insertions(+)
> >  create mode 100644 Documentation/fpga/xrt.rst
> >
> > diff --git a/Documentation/fpga/index.rst
> > b/Documentation/fpga/index.rst index f80f95667ca2..30134357b70d 100644
> > --- a/Documentation/fpga/index.rst
> > +++ b/Documentation/fpga/index.rst
> > @@ -8,6 +8,7 @@ fpga
> >  :maxdepth: 1
> >
> >  dfl
> > +xrt
> >
> >  .. only::  subproject and html
> >
> > diff --git a/Documentation/fpga/xrt.rst b/Documentation/fpga/xrt.rst
> > new file mode 100644 index ..9bc2d2785cb9
> > --- /dev/null
> > +++ b/Documentation/fpga/xrt.rst
> > @@ -0,0 +1,842 @@
> > +.. SPDX-License-Identifier: GPL-2.0
> > +
> > +==
> > +XRTV2 Linux Kernel Driver Overview
> > +==
> > +
> > +Authors:
> > +
> > +* Sonal Santan 
> > +* Max Zhen 
> > +* Lizhi Hou 
> > +
> > +XRTV2 drivers are second generation `XRT
> > +`_ drivers which support `Alveo
> > +`_
> > +PCIe platforms from Xilinx.
> > +
> > +XRTV2 drivers support *subsystem* style data driven platforms where
> > +driver's
> where the driver's
> > +configuration and behavior is determined by meta data provided by the
> > +platform (in *device tree* format). Primary management physical
> > +function (MPF) driver is called **xmgmt**. Primary user physical
> > +function (UPF) driver is called
> > +**xuser** and is under development. xrt driver framework and HW
> > +subsystem drivers are packaged into a library module called
> > +**xrt-lib**, which is shared by **xmgmt** and **xuser** (under
> > +development). The xrt driver framework
> xuser still under development ?
> > +implements a pseudo-bus which is used to discover HW subsystems and
> > +facilitate
> 
> A pseudo-bus.
> 
> It would be good if this was close to what was done for dfl here
> 
> https://lore.kernel.org/linux-fpga/1605159759-3439-1-git-send-email-
> yilun...@intel.com/
> 

I am wondering if we can phase in the migration to formal bus architecture 
based on struct bus_type as a follow on set of patches?

> > +inter HW subsystem interaction.
> > +
> > +Driver Modules
> > +==
> > +
> > +xrt-lib.ko
> > +--
> > +
> > +Repository of all subsystem drivers and pure software modules that
> > +can potentially
> 
> subsystem drivers
> 
> drivers in fpga/ should be for managing just the fpganess of the fpga.
> 
> soft devices ex/ a soft tty should go to their respective subsystem location
> 
> Are there any in this patchset you think might move ?

We have already shrunk the patch to only include FPGA centric pieces 
necessary to get the bitstream download implemented. Should we explore
the question of subsystem drivers when we add support for more features of 
the Alveo shell?

> 
> Maybe we can defer reviewing those now.
> 
> > +be shared between xmgmt and xuser. All these drivers are structured
> > +as Linux *platform driver* and are instantiated by xmgmt (or xuser
> > +under development) based on meta data associated with hardware. The
> > +metadata is in the form of device tree
> 
> with the hardware
> 
> form of a device tree
> 

Will change

> > +as mentioned before. Each platform driver statically defines a
> > +subsystem node array by using node name or a string in its
> > +``compatible`` property. And this array is eventually translated to IOMEM
> resources of the platform device.
> > +
> > +The xrt-lib core infrastructure provides hooks to platform drivers
> > +for device node management, user file operations and ioctl callbacks.
> > +The core also provides pseudo-bus functionality for platform 

Re: [PATCH 1/5] dt-bindings: media: mtk-vcodec: Add dma-ranges property

2021-02-28 Thread Irui Wang
On Wed, 2021-02-10 at 16:53 -0600, Rob Herring wrote:
> On Wed, Feb 03, 2021 at 04:37:48PM +0800, Irui Wang wrote:
> > Adds dma-ranges property for DMA addresses translation.
> > 
> > Signed-off-by: Irui Wang 
> > ---
> >  Documentation/devicetree/bindings/media/mediatek-vcodec.txt | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/Documentation/devicetree/bindings/media/mediatek-vcodec.txt 
> > b/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
> > index f85276e629bf..e4644f8caee9 100644
> > --- a/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
> > +++ b/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
> > @@ -23,6 +23,8 @@ Required properties:
> >  - iommus : should point to the respective IOMMU block with master port as
> >argument, see Documentation/devicetree/bindings/iommu/mediatek,iommu.txt
> >for details.
> > +- dma-ranges : describes how the physical address space of the IOMMU maps
> > +  to memory.
> 
> dma-ranges is supposed to be in a bus/parent node.
Dear Rob,

The mt8192 iommu support 0~16GB iova. We separate it to four banks:
0~4G; 4G~8G; 8G~12G; 12G~16G.

The "dma-ranges" could be used to adjust the bank we locate.
If we don't set this property. The default range always is 0~4G.

Here we don't have actual bus/parent concept here.  And the iova
requirement is for our HW. Thus put the property in our node.

Is this OK? If this is ok for you, I will put this message in the commit
message and binding in next version.

Regards
> 
> >  One of the two following nodes:
> >  - mediatek,vpu : the node of the video processor unit, if using VPU.
> >  - mediatek,scp : the node of the SCP unit, if using SCP.
> > -- 
> > 2.25.1
> > 



[PATCH v5] i2c: virtio: add a virtio i2c frontend driver

2021-02-28 Thread Jie Deng
Add an I2C bus driver for virtio para-virtualization.

The controller can be emulated by the backend driver in
any device model software by following the virtio protocol.

The device specification can be found on
https://lists.oasis-open.org/archives/virtio-comment/202101/msg8.html.

By following the specification, people may implement different
backend drivers to emulate different controllers according to
their needs.

Co-developed-by: Conghui Chen 
Signed-off-by: Conghui Chen 
Signed-off-by: Jie Deng 
---
 drivers/i2c/busses/Kconfig  |  11 ++
 drivers/i2c/busses/Makefile |   3 +
 drivers/i2c/busses/i2c-virtio.c | 281 
 include/uapi/linux/virtio_i2c.h |  56 
 include/uapi/linux/virtio_ids.h |   1 +
 5 files changed, 352 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-virtio.c
 create mode 100644 include/uapi/linux/virtio_i2c.h

diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 05ebf75..0860395 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -21,6 +21,17 @@ config I2C_ALI1535
  This driver can also be built as a module.  If so, the module
  will be called i2c-ali1535.
 
+config I2C_VIRTIO
+   tristate "Virtio I2C Adapter"
+   depends on VIRTIO
+   help
+ If you say yes to this option, support will be included for the virtio
+ I2C adapter driver. The hardware can be emulated by any device model
+ software according to the virtio protocol.
+
+ This driver can also be built as a module. If so, the module
+ will be called i2c-virtio.
+
 config I2C_ALI1563
tristate "ALI 1563"
depends on PCI
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 615f35e..b88da08 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -6,6 +6,9 @@
 # ACPI drivers
 obj-$(CONFIG_I2C_SCMI) += i2c-scmi.o
 
+# VIRTIO I2C host controller driver
+obj-$(CONFIG_I2C_VIRTIO)   += i2c-virtio.o
+
 # PC SMBus host controller drivers
 obj-$(CONFIG_I2C_ALI1535)  += i2c-ali1535.o
 obj-$(CONFIG_I2C_ALI1563)  += i2c-ali1563.o
diff --git a/drivers/i2c/busses/i2c-virtio.c b/drivers/i2c/busses/i2c-virtio.c
new file mode 100644
index 000..8c8bc95
--- /dev/null
+++ b/drivers/i2c/busses/i2c-virtio.c
@@ -0,0 +1,281 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Virtio I2C Bus Driver
+ *
+ * Copyright (c) 2021 Intel Corporation. All rights reserved.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+/**
+ * struct virtio_i2c - virtio I2C data
+ * @vdev: virtio device for this controller
+ * @completion: completion of virtio I2C message
+ * @adap: I2C adapter for this controller
+ * @i2c_lock: lock for virtqueue processing
+ * @vq: the virtio virtqueue for communication
+ */
+struct virtio_i2c {
+   struct virtio_device *vdev;
+   struct completion completion;
+   struct i2c_adapter adap;
+   struct mutex i2c_lock;
+   struct virtqueue *vq;
+};
+
+static void virtio_i2c_msg_done(struct virtqueue *vq)
+{
+   struct virtio_i2c *vi = vq->vdev->priv;
+
+   complete(>completion);
+}
+
+static int virtio_i2c_send_reqs(struct virtqueue *vq,
+   struct virtio_i2c_req *reqs,
+   struct i2c_msg *msgs, int nr)
+{
+   struct scatterlist *sgs[3], out_hdr, msg_buf, in_hdr;
+   int i, outcnt, incnt, err = 0;
+   u8 *buf;
+
+   for (i = 0; i < nr; i++) {
+   if (!msgs[i].len)
+   break;
+
+   reqs[i].out_hdr.addr = cpu_to_le16(msgs[i].addr << 1);
+
+   if (i != nr - 1)
+   reqs[i].out_hdr.flags |= VIRTIO_I2C_FLAGS_FAIL_NEXT;
+
+   outcnt = incnt = 0;
+   sg_init_one(_hdr, [i].out_hdr, 
sizeof(reqs[i].out_hdr));
+   sgs[outcnt++] = _hdr;
+
+   buf = kzalloc(msgs[i].len, GFP_KERNEL);
+   if (!buf)
+   break;
+
+   if (msgs[i].flags & I2C_M_RD) {
+   reqs[i].read_buf = buf;
+   sg_init_one(_buf, reqs[i].read_buf, msgs[i].len);
+   sgs[outcnt + incnt++] = _buf;
+   } else {
+   reqs[i].write_buf = buf;
+   memcpy(reqs[i].write_buf, msgs[i].buf, msgs[i].len);
+   sg_init_one(_buf, reqs[i].write_buf, msgs[i].len);
+   sgs[outcnt++] = _buf;
+   }
+
+   sg_init_one(_hdr, [i].in_hdr, sizeof(reqs[i].in_hdr));
+   sgs[outcnt + incnt++] = _hdr;
+
+   err = virtqueue_add_sgs(vq, sgs, outcnt, incnt, [i], 
GFP_KERNEL);
+   if (err < 0) {
+   pr_err("failed to add msg[%d] to virtqueue.\n", i);
+   if 

Re: [PATCH 1/3] crypto: sa2ul - Hide pointer and fix -Wpointer-to-int-cast in dev_dbg()

2021-02-28 Thread Krzysztof Kozlowski
On Mon, 1 Mar 2021 at 07:36, Herbert Xu  wrote:
>
> On Sat, Feb 27, 2021 at 05:37:49PM +0100, Krzysztof Kozlowski wrote:
> >
> > I think this patch was lost, although you replied that the entire set
> > is applied.
> >
> > Can you pick it up?
>
> I think it was not applicable because the following had already
> been applied:
>
> commit ea066b7a3ddf1e4e5ae749495f0adf12766188b4
> Author: YueHaibing 
> Date:   Tue Aug 18 22:00:01 2020 +0800
>
> crypto: sa2ul - Fix pointer-to-int-cast warning

Yes, you're right. Sorry for the noise.

Best regards,
Krzysztof


Re: [PATCH 1/3] crypto: sa2ul - Hide pointer and fix -Wpointer-to-int-cast in dev_dbg()

2021-02-28 Thread Herbert Xu
On Sat, Feb 27, 2021 at 05:37:49PM +0100, Krzysztof Kozlowski wrote:
>
> I think this patch was lost, although you replied that the entire set
> is applied.
> 
> Can you pick it up?

I think it was not applicable because the following had already
been applied:

commit ea066b7a3ddf1e4e5ae749495f0adf12766188b4
Author: YueHaibing 
Date:   Tue Aug 18 22:00:01 2020 +0800

crypto: sa2ul - Fix pointer-to-int-cast warning

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


[PATCH] arch: mips: sibyte: Return -EFAULT if copy_to_user() fails

2021-02-28 Thread Wang Qing
The copy_to_user() function returns the number of bytes remaining to be
copied, but we want to return -EFAULT if the copy doesn't complete.

Signed-off-by: Wang Qing 
---
 arch/mips/sibyte/common/sb_tbprof.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/sibyte/common/sb_tbprof.c 
b/arch/mips/sibyte/common/sb_tbprof.c
index f80d7a7..eac125f
--- a/arch/mips/sibyte/common/sb_tbprof.c
+++ b/arch/mips/sibyte/common/sb_tbprof.c
@@ -465,7 +465,7 @@ static ssize_t sbprof_tb_read(struct file *filp, char *buf,
if (err) {
*offp = cur_off + cur_count - err;
mutex_unlock();
-   return err;
+   return -EFAULT;
}
pr_debug(DEVNAME ": read from sample %d, %d bytes\n",
 cur_sample, cur_count);
-- 
2.7.4



Re: [PATCH] staging: rtl8192u avoid flex array of flex array

2021-02-28 Thread Dan Carpenter
On Sat, Feb 27, 2021 at 07:06:14PM -0600, Darryl T. Agostinelli wrote:
> Undo the flex array in struct ieee80211_info_element.  It is used as the flex
> array type in other structs (creating a flex array of flex arrays) making
> sparse unhappy.  This change maintains the intent of the code and satisfies
> sparse.
> 
> Signed-off-by: Darryl T. Agostinelli 
> ---
>  drivers/staging/rtl8192u/ieee80211/ieee80211.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211.h 
> b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
> index 39f4ddd86796..43bb7aeb35e3 100644
> --- a/drivers/staging/rtl8192u/ieee80211/ieee80211.h
> +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
> @@ -951,7 +951,7 @@ struct rtl_80211_hdr_4addrqos {
>  struct ieee80211_info_element {
>   u8 id;
>   u8 len;
> - u8 data[];
> + u8 data[0];

Nah...  Just ignore Sparse on this.

regards,
dan carpenter



[PATCH] vdpa/mlx5: Fix wrong use of bit numbers

2021-02-28 Thread Eli Cohen
VIRTIO_F_VERSION_1 is a bit number. Use BIT_ULL() with mask
conditionals.

Also, in mlx5_vdpa_is_little_endian() use BIT_ULL for consistency with
the rest of the code.

Fixes: 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")
Signed-off-by: Eli Cohen 
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c 
b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index dc7031132fff..7d21b857a94a 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -821,7 +821,7 @@ static int create_virtqueue(struct mlx5_vdpa_net *ndev, 
struct mlx5_vdpa_virtque
MLX5_SET(virtio_q, vq_ctx, event_qpn_or_msix, mvq->fwqp.mqp.qpn);
MLX5_SET(virtio_q, vq_ctx, queue_size, mvq->num_ent);
MLX5_SET(virtio_q, vq_ctx, virtio_version_1_0,
-!!(ndev->mvdev.actual_features & VIRTIO_F_VERSION_1));
+!!(ndev->mvdev.actual_features & BIT_ULL(VIRTIO_F_VERSION_1)));
MLX5_SET64(virtio_q, vq_ctx, desc_addr, mvq->desc_addr);
MLX5_SET64(virtio_q, vq_ctx, used_addr, mvq->device_addr);
MLX5_SET64(virtio_q, vq_ctx, available_addr, mvq->driver_addr);
@@ -1578,7 +1578,7 @@ static void teardown_virtqueues(struct mlx5_vdpa_net 
*ndev)
 static inline bool mlx5_vdpa_is_little_endian(struct mlx5_vdpa_dev *mvdev)
 {
return virtio_legacy_is_little_endian() ||
-   (mvdev->actual_features & (1ULL << VIRTIO_F_VERSION_1));
+   (mvdev->actual_features & BIT_ULL(VIRTIO_F_VERSION_1));
 }
 
 static __virtio16 cpu_to_mlx5vdpa16(struct mlx5_vdpa_dev *mvdev, u16 val)
-- 
2.30.1



[PATCH 5/5] mm: memcontrol: use object cgroup for remote memory cgroup charging

2021-02-28 Thread Muchun Song
We spent a lot of energy to make slab accounting do not hold a refcount
to memory cgroup, so the dying cgroup can be freed as soon as possible
on cgroup offlined.

But some users of remote memory cgroup charging (e.g. bpf and fsnotify)
hold a refcount to memory cgroup for charging to it later. Actually,
the slab core use obj_cgroup APIs for memory cgroup charing, so we can
hold a refcount to obj_cgroup instead of memory cgroup. In this case,
the infrastructure of remote meory charging also do not hold a refcount
to memory cgroup.

Signed-off-by: Muchun Song 
---
 fs/buffer.c  | 10 --
 fs/notify/fanotify/fanotify.c|  6 ++--
 fs/notify/fanotify/fanotify_user.c   |  2 +-
 fs/notify/group.c|  3 +-
 fs/notify/inotify/inotify_fsnotify.c |  8 ++---
 fs/notify/inotify/inotify_user.c |  2 +-
 include/linux/bpf.h  |  2 +-
 include/linux/fsnotify_backend.h |  2 +-
 include/linux/memcontrol.h   | 15 
 include/linux/sched.h|  4 +--
 include/linux/sched/mm.h | 28 +++
 kernel/bpf/syscall.c | 35 +--
 kernel/fork.c|  2 +-
 mm/memcontrol.c  | 66 
 14 files changed, 121 insertions(+), 64 deletions(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index 591547779dbd..cc99fcf66368 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -842,14 +842,16 @@ struct buffer_head *alloc_page_buffers(struct page *page, 
unsigned long size,
struct buffer_head *bh, *head;
gfp_t gfp = GFP_NOFS | __GFP_ACCOUNT;
long offset;
-   struct mem_cgroup *memcg, *old_memcg;
+   struct mem_cgroup *memcg;
+   struct obj_cgroup *objcg, *old_objcg;
 
if (retry)
gfp |= __GFP_NOFAIL;
 
/* The page lock pins the memcg */
memcg = page_memcg(page);
-   old_memcg = set_active_memcg(memcg);
+   objcg = get_obj_cgroup_from_mem_cgroup(memcg);
+   old_objcg = set_active_obj_cgroup(objcg);
 
head = NULL;
offset = PAGE_SIZE;
@@ -868,7 +870,9 @@ struct buffer_head *alloc_page_buffers(struct page *page, 
unsigned long size,
set_bh_page(bh, page, offset);
}
 out:
-   set_active_memcg(old_memcg);
+   set_active_obj_cgroup(old_objcg);
+   if (objcg)
+   obj_cgroup_put(objcg);
return head;
 /*
  * In case anything failed, we just free everything we got.
diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
index 1192c9953620..04d24acfffc7 100644
--- a/fs/notify/fanotify/fanotify.c
+++ b/fs/notify/fanotify/fanotify.c
@@ -530,7 +530,7 @@ static struct fanotify_event *fanotify_alloc_event(struct 
fsnotify_group *group,
struct inode *dirid = fanotify_dfid_inode(mask, data, data_type, dir);
const struct path *path = fsnotify_data_path(data, data_type);
unsigned int fid_mode = FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS);
-   struct mem_cgroup *old_memcg;
+   struct obj_cgroup *old_objcg;
struct inode *child = NULL;
bool name_event = false;
 
@@ -580,7 +580,7 @@ static struct fanotify_event *fanotify_alloc_event(struct 
fsnotify_group *group,
gfp |= __GFP_RETRY_MAYFAIL;
 
/* Whoever is interested in the event, pays for the allocation. */
-   old_memcg = set_active_memcg(group->memcg);
+   old_objcg = set_active_obj_cgroup(group->objcg);
 
if (fanotify_is_perm_event(mask)) {
event = fanotify_alloc_perm_event(path, gfp);
@@ -608,7 +608,7 @@ static struct fanotify_event *fanotify_alloc_event(struct 
fsnotify_group *group,
event->pid = get_pid(task_tgid(current));
 
 out:
-   set_active_memcg(old_memcg);
+   set_active_obj_cgroup(old_objcg);
return event;
 }
 
diff --git a/fs/notify/fanotify/fanotify_user.c 
b/fs/notify/fanotify/fanotify_user.c
index 9e0c1afac8bd..055ca36d4e0e 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -985,7 +985,7 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, 
unsigned int, event_f_flags)
group->fanotify_data.user = user;
group->fanotify_data.flags = flags;
atomic_inc(>fanotify_listeners);
-   group->memcg = get_mem_cgroup_from_mm(current->mm);
+   group->objcg = get_obj_cgroup_from_current();
 
group->overflow_event = fanotify_alloc_overflow_event();
if (unlikely(!group->overflow_event)) {
diff --git a/fs/notify/group.c b/fs/notify/group.c
index ffd723ffe46d..fac46b92c16f 100644
--- a/fs/notify/group.c
+++ b/fs/notify/group.c
@@ -24,7 +24,8 @@ static void fsnotify_final_destroy_group(struct 
fsnotify_group *group)
if (group->ops->free_group_priv)
group->ops->free_group_priv(group);
 
-   mem_cgroup_put(group->memcg);
+   if (group->objcg)
+   obj_cgroup_put(group->objcg);
  

[PATCH 3/5] mm: memcontrol: reparent the kmem pages on cgroup removal

2021-02-28 Thread Muchun Song
Currently the slab objects already reparent to it's parent memcg on
cgroup removal. But there are still some corner objects which are
not reparent (e.g. allocations larger than order-1 page on SLUB).
Actually those objects are allocated directly from the buddy allocator.
And they are chared as kmem to memcg via __memcg_kmem_charge_page().
Such objects are not reparent on cgroup removal.

So this patch aims to reparent kmem pages on cgroup removal. Doing
this is simple with help of the infrastructures of obj_cgroup.
Finally, the page->memcg_data points to an object cgroup for the
kmem page.

Signed-off-by: Muchun Song 
---
 include/linux/memcontrol.h |  66 +++
 mm/memcontrol.c| 155 -
 2 files changed, 124 insertions(+), 97 deletions(-)

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 1d2c82464c8c..27043478220f 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -370,23 +370,15 @@ static inline bool page_memcg_charged(struct page *page)
 }
 
 /*
- * page_memcg_kmem - get the memory cgroup associated with a kmem page.
- * @page: a pointer to the page struct
+ * After the initialization objcg->memcg is always pointing at
+ * a valid memcg, but can be atomically swapped to the parent memcg.
  *
- * Returns a pointer to the memory cgroup associated with the kmem page,
- * or NULL. This function assumes that the page is known to have a proper
- * memory cgroup pointer. It is only suitable for kmem pages which means
- * PageMemcgKmem() returns true for this page.
+ * The caller must ensure that the returned memcg won't be released:
+ * e.g. acquire the rcu_read_lock or css_set_lock.
  */
-static inline struct mem_cgroup *page_memcg_kmem(struct page *page)
+static inline struct mem_cgroup *obj_cgroup_memcg(struct obj_cgroup *objcg)
 {
-   unsigned long memcg_data = page->memcg_data;
-
-   VM_BUG_ON_PAGE(PageSlab(page), page);
-   VM_BUG_ON_PAGE(memcg_data & MEMCG_DATA_OBJCGS, page);
-   VM_BUG_ON_PAGE(!(memcg_data & MEMCG_DATA_KMEM), page);
-
-   return (struct mem_cgroup *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK);
+   return READ_ONCE(objcg->memcg);
 }
 
 /*
@@ -462,6 +454,17 @@ static inline struct mem_cgroup *page_memcg_check(struct 
page *page)
if (memcg_data & MEMCG_DATA_OBJCGS)
return NULL;
 
+   if (memcg_data & MEMCG_DATA_KMEM) {
+   struct obj_cgroup *objcg;
+
+   /*
+* The caller must ensure that the returned memcg won't be
+* released: e.g. acquire the rcu_read_lock or css_set_lock.
+*/
+   objcg = (void *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK);
+   return obj_cgroup_memcg(objcg);
+   }
+
return (struct mem_cgroup *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK);
 }
 
@@ -520,6 +523,24 @@ static inline struct obj_cgroup **page_objcgs_check(struct 
page *page)
return (struct obj_cgroup **)(memcg_data & ~MEMCG_DATA_FLAGS_MASK);
 }
 
+/*
+ * page_objcg - get the object cgroup associated with a kmem page
+ * @page: a pointer to the page struct
+ *
+ * Returns a pointer to the object cgroup associated with the kmem page,
+ * or NULL. This function assumes that the page is known to have an
+ * associated object cgroup. It's only safe to call this function
+ * against kmem pages (PageMemcgKmem() returns true).
+ */
+static inline struct obj_cgroup *page_objcg(struct page *page)
+{
+   unsigned long memcg_data = page->memcg_data;
+
+   VM_BUG_ON_PAGE(memcg_data & MEMCG_DATA_OBJCGS, page);
+   VM_BUG_ON_PAGE(!(memcg_data & MEMCG_DATA_KMEM), page);
+
+   return (struct obj_cgroup *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK);
+}
 #else
 static inline struct obj_cgroup **page_objcgs(struct page *page)
 {
@@ -530,6 +551,11 @@ static inline struct obj_cgroup **page_objcgs_check(struct 
page *page)
 {
return NULL;
 }
+
+static inline struct obj_cgroup *page_objcg(struct page *page)
+{
+   return NULL;
+}
 #endif
 
 static __always_inline bool memcg_stat_item_in_bytes(int idx)
@@ -748,18 +774,6 @@ static inline void obj_cgroup_put(struct obj_cgroup *objcg)
percpu_ref_put(>refcnt);
 }
 
-/*
- * After the initialization objcg->memcg is always pointing at
- * a valid memcg, but can be atomically swapped to the parent memcg.
- *
- * The caller must ensure that the returned memcg won't be released:
- * e.g. acquire the rcu_read_lock or css_set_lock.
- */
-static inline struct mem_cgroup *obj_cgroup_memcg(struct obj_cgroup *objcg)
-{
-   return READ_ONCE(objcg->memcg);
-}
-
 static inline void mem_cgroup_put(struct mem_cgroup *memcg)
 {
if (memcg)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index bfd6efe1e196..39cb8c5bf8b2 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -856,10 +856,16 @@ void __mod_lruvec_page_state(struct page *page, enum 
node_stat_item idx,
 {
struct page *head = 

[PATCH 4/5] mm: memcontrol: move remote memcg charging APIs to CONFIG_MEMCG_KMEM

2021-02-28 Thread Muchun Song
The remote memcg charing APIs is a mechanism to charge kernel memory
to a given memcg. So we can move the infrastructure to the scope of
the CONFIG_MEMCG_KMEM.

As a bonus, on !CONFIG_MEMCG_KMEM build some functions and variables
can be compiled out.

Signed-off-by: Muchun Song 
---
 include/linux/sched.h| 2 ++
 include/linux/sched/mm.h | 2 +-
 kernel/fork.c| 2 +-
 mm/memcontrol.c  | 4 
 4 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index ee46f5cab95b..c2d488eddf85 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1314,7 +1314,9 @@ struct task_struct {
 
/* Number of pages to reclaim on returning to userland: */
unsigned intmemcg_nr_pages_over_high;
+#endif
 
+#ifdef CONFIG_MEMCG_KMEM
/* Used by memcontrol for targeted memcg charge: */
struct mem_cgroup   *active_memcg;
 #endif
diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h
index 1ae08b8462a4..64a72975270e 100644
--- a/include/linux/sched/mm.h
+++ b/include/linux/sched/mm.h
@@ -294,7 +294,7 @@ static inline void memalloc_nocma_restore(unsigned int 
flags)
 }
 #endif
 
-#ifdef CONFIG_MEMCG
+#ifdef CONFIG_MEMCG_KMEM
 DECLARE_PER_CPU(struct mem_cgroup *, int_active_memcg);
 /**
  * set_active_memcg - Starts the remote memcg charging scope.
diff --git a/kernel/fork.c b/kernel/fork.c
index d66cd1014211..d66718bc82d5 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -942,7 +942,7 @@ static struct task_struct *dup_task_struct(struct 
task_struct *orig, int node)
tsk->use_memdelay = 0;
 #endif
 
-#ifdef CONFIG_MEMCG
+#ifdef CONFIG_MEMCG_KMEM
tsk->active_memcg = NULL;
 #endif
return tsk;
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 39cb8c5bf8b2..092dc4588b43 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -76,8 +76,10 @@ EXPORT_SYMBOL(memory_cgrp_subsys);
 
 struct mem_cgroup *root_mem_cgroup __read_mostly;
 
+#ifdef CONFIG_MEMCG_KMEM
 /* Active memory cgroup to use from an interrupt context */
 DEFINE_PER_CPU(struct mem_cgroup *, int_active_memcg);
+#endif
 
 /* Socket memory accounting disabled? */
 static bool cgroup_memory_nosocket;
@@ -1054,6 +1056,7 @@ struct mem_cgroup *get_mem_cgroup_from_mm(struct 
mm_struct *mm)
 }
 EXPORT_SYMBOL(get_mem_cgroup_from_mm);
 
+#ifdef CONFIG_MEMCG_KMEM
 static __always_inline struct mem_cgroup *active_memcg(void)
 {
if (in_interrupt())
@@ -1074,6 +1077,7 @@ static __always_inline bool memcg_kmem_bypass(void)
 
return false;
 }
+#endif
 
 /**
  * mem_cgroup_iter - iterate over memory cgroup hierarchy
-- 
2.11.0



[PATCH 2/5] mm: memcontrol: make page_memcg{_rcu} only applicable for non-kmem page

2021-02-28 Thread Muchun Song
We want to reuse the obj_cgroup APIs to reparent the kmem pages when
the memcg offlined. If we do this, we should store an object cgroup
pointer to page->memcg_data for the kmem pages.

Finally, page->memcg_data can have 3 different meanings.

  1) For the slab pages, page->memcg_data points to an object cgroups
 vector.

  2) For the kmem pages (exclude the slab pages), page->memcg_data
 points to an object cgroup.

  3) For the user pages (e.g. the LRU pages), page->memcg_data points
 to a memory cgroup.

Currently we always get the memcg associated with a page via page_memcg
or page_memcg_rcu. page_memcg_check is special, it has to be used in
cases when it's not known if a page has an associated memory cgroup
pointer or an object cgroups vector. Because the page->memcg_data of
the kmem page is not pointing to a memory cgroup in the later patch,
the page_memcg and page_memcg_rcu cannot be applicable for the kmem
pages. In this patch, we introduce page_memcg_kmem to get the memcg
associated with the kmem pages. And make page_memcg and page_memcg_rcu
no longer apply to the kmem pages.

In the end, there are 4 helpers to get the memcg associated with a
page. The usage is as follows.

  1) Get the memory cgroup associated with a non-kmem page (e.g. the LRU
 pages).

 - page_memcg()
 - page_memcg_rcu()

  2) Get the memory cgroup associated with a kmem page (exclude the slab
 pages).

 - page_memcg_kmem()

  3) Get the memory cgroup associated with a page. It has to be used in
 cases when it's not known if a page has an associated memory cgroup
 pointer or an object cgroups vector. Returns NULL for slab pages or
 uncharged pages, otherwise, returns memory cgroup for charged pages
 (e.g. kmem pages, LRU pages).

 - page_memcg_check()

In some place, we use page_memcg to check whether the page is charged.
Now we introduce page_memcg_charged helper to do this.

This is a preparation for reparenting the kmem pages. To support reparent
kmem pages, we just need to adjust page_memcg_kmem and page_memcg_check in
the later patch.

Signed-off-by: Muchun Song 
---
 include/linux/memcontrol.h | 56 +++---
 mm/memcontrol.c| 23 ++-
 mm/page_alloc.c|  4 ++--
 3 files changed, 63 insertions(+), 20 deletions(-)

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index e6dc793d587d..1d2c82464c8c 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -358,14 +358,46 @@ enum page_memcg_data_flags {
 
 #define MEMCG_DATA_FLAGS_MASK (__NR_MEMCG_DATA_FLAGS - 1)
 
+/* Return true for charged page, otherwise false. */
+static inline bool page_memcg_charged(struct page *page)
+{
+   unsigned long memcg_data = page->memcg_data;
+
+   VM_BUG_ON_PAGE(PageSlab(page), page);
+   VM_BUG_ON_PAGE(memcg_data & MEMCG_DATA_OBJCGS, page);
+
+   return !!memcg_data;
+}
+
 /*
- * page_memcg - get the memory cgroup associated with a page
+ * page_memcg_kmem - get the memory cgroup associated with a kmem page.
+ * @page: a pointer to the page struct
+ *
+ * Returns a pointer to the memory cgroup associated with the kmem page,
+ * or NULL. This function assumes that the page is known to have a proper
+ * memory cgroup pointer. It is only suitable for kmem pages which means
+ * PageMemcgKmem() returns true for this page.
+ */
+static inline struct mem_cgroup *page_memcg_kmem(struct page *page)
+{
+   unsigned long memcg_data = page->memcg_data;
+
+   VM_BUG_ON_PAGE(PageSlab(page), page);
+   VM_BUG_ON_PAGE(memcg_data & MEMCG_DATA_OBJCGS, page);
+   VM_BUG_ON_PAGE(!(memcg_data & MEMCG_DATA_KMEM), page);
+
+   return (struct mem_cgroup *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK);
+}
+
+/*
+ * page_memcg - get the memory cgroup associated with a non-kmem page
  * @page: a pointer to the page struct
  *
  * Returns a pointer to the memory cgroup associated with the page,
  * or NULL. This function assumes that the page is known to have a
  * proper memory cgroup pointer. It's not safe to call this function
- * against some type of pages, e.g. slab pages or ex-slab pages.
+ * against some type of pages, e.g. slab pages, kmem pages or ex-slab
+ * pages.
  *
  * Any of the following ensures page and memcg binding stability:
  * - the page lock
@@ -378,27 +410,30 @@ static inline struct mem_cgroup *page_memcg(struct page 
*page)
unsigned long memcg_data = page->memcg_data;
 
VM_BUG_ON_PAGE(PageSlab(page), page);
-   VM_BUG_ON_PAGE(memcg_data & MEMCG_DATA_OBJCGS, page);
+   VM_BUG_ON_PAGE(memcg_data & MEMCG_DATA_FLAGS_MASK, page);
 
-   return (struct mem_cgroup *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK);
+   return (struct mem_cgroup *)memcg_data;
 }
 
 /*
- * page_memcg_rcu - locklessly get the memory cgroup associated with a page
+ * page_memcg_rcu - locklessly get the memory cgroup associated with a 
non-kmem page
  * @page: a 

[PATCH 1/5] mm: memcontrol: introduce obj_cgroup_{un}charge_page

2021-02-28 Thread Muchun Song
We know that the unit of charging slab object is bytes, the unit of
charging kmem page is PAGE_SIZE. So If we want to reuse obj_cgroup
APIs to charge the kmem pages, we should pass PAGE_SIZE (as third
parameter) to obj_cgroup_charge(). Because the charing size is page
size, we always need to refill objcg stock. This is pointless. As we
already know the charing size. So we can directly skip touch the
objcg stock and introduce obj_cgroup_{un}charge_page() to charge or
uncharge a kmem page.

In the later patch, we can reuse those helpers to charge/uncharge
the kmem pages. This is just code movement without any functional
change.

Signed-off-by: Muchun Song 
---
 mm/memcontrol.c | 46 +++---
 1 file changed, 31 insertions(+), 15 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 2db2aeac8a9e..2eafbae504ac 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3060,6 +3060,34 @@ static void memcg_free_cache_id(int id)
ida_simple_remove(_cache_ida, id);
 }
 
+static inline void obj_cgroup_uncharge_page(struct obj_cgroup *objcg,
+   unsigned int nr_pages)
+{
+   rcu_read_lock();
+   __memcg_kmem_uncharge(obj_cgroup_memcg(objcg), nr_pages);
+   rcu_read_unlock();
+}
+
+static int obj_cgroup_charge_page(struct obj_cgroup *objcg, gfp_t gfp,
+ unsigned int nr_pages)
+{
+   struct mem_cgroup *memcg;
+   int ret;
+
+   rcu_read_lock();
+retry:
+   memcg = obj_cgroup_memcg(objcg);
+   if (unlikely(!css_tryget(>css)))
+   goto retry;
+   rcu_read_unlock();
+
+   ret = __memcg_kmem_charge(memcg, gfp, nr_pages);
+
+   css_put(>css);
+
+   return ret;
+}
+
 /**
  * __memcg_kmem_charge: charge a number of kernel pages to a memcg
  * @memcg: memory cgroup to charge
@@ -3184,11 +3212,8 @@ static void drain_obj_stock(struct memcg_stock_pcp 
*stock)
unsigned int nr_pages = stock->nr_bytes >> PAGE_SHIFT;
unsigned int nr_bytes = stock->nr_bytes & (PAGE_SIZE - 1);
 
-   if (nr_pages) {
-   rcu_read_lock();
-   __memcg_kmem_uncharge(obj_cgroup_memcg(old), nr_pages);
-   rcu_read_unlock();
-   }
+   if (nr_pages)
+   obj_cgroup_uncharge_page(old, nr_pages);
 
/*
 * The leftover is flushed to the centralized per-memcg value.
@@ -3246,7 +3271,6 @@ static void refill_obj_stock(struct obj_cgroup *objcg, 
unsigned int nr_bytes)
 
 int obj_cgroup_charge(struct obj_cgroup *objcg, gfp_t gfp, size_t size)
 {
-   struct mem_cgroup *memcg;
unsigned int nr_pages, nr_bytes;
int ret;
 
@@ -3263,24 +3287,16 @@ int obj_cgroup_charge(struct obj_cgroup *objcg, gfp_t 
gfp, size_t size)
 * refill_obj_stock(), called from this function or
 * independently later.
 */
-   rcu_read_lock();
-retry:
-   memcg = obj_cgroup_memcg(objcg);
-   if (unlikely(!css_tryget(>css)))
-   goto retry;
-   rcu_read_unlock();
-
nr_pages = size >> PAGE_SHIFT;
nr_bytes = size & (PAGE_SIZE - 1);
 
if (nr_bytes)
nr_pages += 1;
 
-   ret = __memcg_kmem_charge(memcg, gfp, nr_pages);
+   ret = obj_cgroup_charge_page(objcg, gfp, nr_pages);
if (!ret && nr_bytes)
refill_obj_stock(objcg, PAGE_SIZE - nr_bytes);
 
-   css_put(>css);
return ret;
 }
 
-- 
2.11.0



[PATCH 0/5] Use obj_cgroup APIs to change kmem pages

2021-02-28 Thread Muchun Song
Since Roman series "The new cgroup slab memory controller" applied. All
slab objects are changed via the new APIs of obj_cgroup. This new APIs
introduce a struct obj_cgroup instead of using struct mem_cgroup directly
to charge slab objects. It prevents long-living objects from pinning the
original memory cgroup in the memory. But there are still some corner
objects (e.g. allocations larger than order-1 page on SLUB) which are
not charged via the API of obj_cgroup. Those objects (include the pages
which are allocated from buddy allocator directly) are charged as kmem
pages which still hold a reference to the memory cgroup.

E.g. We know that the kernel stack is charged as kmem pages because the
size of the kernel stack can be greater than 2 pages (e.g. 16KB on x86_64
or arm64). If we create a thread (suppose the thread stack is charged to
memory cgroup A) and then move it from memory cgroup A to memory cgroup
B. Because the kernel stack of the thread hold a reference to the memory
cgroup A. The thread can pin the memory cgroup A in the memory even if
we remove the cgroup A. If we want to see this scenario by using the
following script. We can see that the system has added 500 dying cgroups.

#!/bin/bash

cat /proc/cgroups | grep memory

cd /sys/fs/cgroup/memory
echo 1 > memory.move_charge_at_immigrate

for i in range{1..500}
do
mkdir kmem_test
echo $$ > kmem_test/cgroup.procs
sleep 3600 &
echo $$ > cgroup.procs
echo `cat kmem_test/cgroup.procs` > cgroup.procs
rmdir kmem_test
done

cat /proc/cgroups | grep memory

This patchset aims to make those kmem pages drop the reference to memory
cgroup by using the APIs of obj_cgroup. Finally, we can see that the number
of the dying cgroups will not increase if we run the above test script.

Patch 1-3 are using obj_cgroup APIs to charge kmem pages. The remote
memory cgroup charing APIs is a mechanism to charge kernel memory to a
given memory cgroup. So I also make it use the APIs of obj_cgroup.
Patch 4-5 are doing this.

Muchun Song (5):
  mm: memcontrol: introduce obj_cgroup_{un}charge_page
  mm: memcontrol: make page_memcg{_rcu} only applicable for non-kmem
page
  mm: memcontrol: reparent the kmem pages on cgroup removal
  mm: memcontrol: move remote memcg charging APIs to CONFIG_MEMCG_KMEM
  mm: memcontrol: use object cgroup for remote memory cgroup charging

 fs/buffer.c  |  10 +-
 fs/notify/fanotify/fanotify.c|   6 +-
 fs/notify/fanotify/fanotify_user.c   |   2 +-
 fs/notify/group.c|   3 +-
 fs/notify/inotify/inotify_fsnotify.c |   8 +-
 fs/notify/inotify/inotify_user.c |   2 +-
 include/linux/bpf.h  |   2 +-
 include/linux/fsnotify_backend.h |   2 +-
 include/linux/memcontrol.h   | 109 +++---
 include/linux/sched.h|   6 +-
 include/linux/sched/mm.h |  30 ++--
 kernel/bpf/syscall.c |  35 ++---
 kernel/fork.c|   4 +-
 mm/memcontrol.c  | 276 ++-
 mm/page_alloc.c  |   4 +-
 15 files changed, 324 insertions(+), 175 deletions(-)

-- 
2.11.0



Re: [PATCH] mm: Generalize HUGETLB_PAGE_SIZE_VARIABLE

2021-02-28 Thread Christoph Hellwig
On Mon, Mar 01, 2021 at 11:20:53AM +0530, Anshuman Khandual wrote:
> HUGETLB_PAGE_SIZE_VARIABLE need not be defined for each individual
> platform subscribing it. Instead just make it generic.
> 
> Cc: Michael Ellerman 
> Cc: Benjamin Herrenschmidt 
> Cc: Paul Mackerras 
> Cc: Andrew Morton 
> Cc: Christoph Hellwig 
> Cc: linux-i...@vger.kernel.org
> Cc: linuxppc-...@lists.ozlabs.org
> Cc: linux...@kvack.org
> Cc: linux-kernel@vger.kernel.org
> Suggested-by: Christoph Hellwig 
> Signed-off-by: Anshuman Khandual 
> ---
> This change was originally suggested in an earilier discussion. This
> applies on v5.12-rc1 and has been build tested on all applicable
> platforms i.e ia64 and powerpc.
> 
> https://patchwork.kernel.org/project/linux-mm/patch/1613024531-19040-3-git-send-email-anshuman.khand...@arm.com/
> 
>  arch/ia64/Kconfig| 6 +-
>  arch/powerpc/Kconfig | 6 +-
>  mm/Kconfig   | 8 
>  3 files changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
> index 2ad7a8d29fcc..6b3e3f6c29ae 100644
> --- a/arch/ia64/Kconfig
> +++ b/arch/ia64/Kconfig
> @@ -32,6 +32,7 @@ config IA64
>   select TTY
>   select HAVE_ARCH_TRACEHOOK
>   select HAVE_VIRT_CPU_ACCOUNTING
> + select HUGETLB_PAGE_SIZE_VARIABLE

doesn't this need a 'if HUGETLB_PAGE'

or did you verify that HUGETLB_PAGE_SIZE_VARIABLE checks are always
nested inside of HUGETLB_PAGE ones?


Re: [PATCH] staging: rtl8723bs: Fixed indentation and coding style

2021-02-28 Thread Dan Carpenter
On Sun, Feb 28, 2021 at 03:32:30AM +0530, chakravarthikulkarni wrote:
> @@ -795,14 +795,14 @@ struct RunInThread_param {
>  
>  
>  /*
> -
> -Result:
> -0x00: success
> -0x01: sucess, and check Response.
> -0x02: cmd ignored due to duplicated sequcne number
> -0x03: cmd dropped due to invalid cmd code
> -0x04: reserved.
> -
> +*
> +*Result:
> +*0x00: success
> +*0x01: sucess, and check Response.
> +*0x02: cmd ignored due to duplicated sequcne number
> +*0x03: cmd dropped due to invalid cmd code
> +*0x04: reserved.
> +*
>  */

This indenting style is wrong.  There should be a spaces around the '*'
character:

/*
 * Result:
 * 0x00: success
 * 0x01: sucess, and check Response.
 * 0x02: cmd ignored due to duplicated sequcne number
 * 0x03: cmd dropped due to invalid cmd code
 * 0x04: reserved.
 */

regards,
dan carpenter



[PATCH] dts: remove c6x dts hard link file

2021-02-28 Thread Wolfram Sang
The architecture has gone and indexing software like 'mkid' complains
about the broken link.

Signed-off-by: Wolfram Sang 
---
 scripts/dtc/include-prefixes/c6x | 1 -
 1 file changed, 1 deletion(-)
 delete mode 12 scripts/dtc/include-prefixes/c6x

diff --git a/scripts/dtc/include-prefixes/c6x b/scripts/dtc/include-prefixes/c6x
deleted file mode 12
index 49ded4cae2be..
--- a/scripts/dtc/include-prefixes/c6x
+++ /dev/null
@@ -1 +0,0 @@
-../../../arch/c6x/boot/dts
\ No newline at end of file
-- 
2.30.0



[PATCH] arm64: dts: ti: k3-am64-main: Add GPIO DT nodes

2021-02-28 Thread Aswath Govindraju
Add device tree nodes for GPIO modules and interrupt controller in main
domain.

Signed-off-by: Aswath Govindraju 
---

This patch depends on,
https://patchwork.kernel.org/project/linux-arm-kernel/list/?series=439039


 arch/arm64/boot/dts/ti/k3-am64-main.dtsi | 45 
 1 file changed, 45 insertions(+)

diff --git a/arch/arm64/boot/dts/ti/k3-am64-main.dtsi 
b/arch/arm64/boot/dts/ti/k3-am64-main.dtsi
index a36ebddf3a4c..8b4d76d83342 100644
--- a/arch/arm64/boot/dts/ti/k3-am64-main.dtsi
+++ b/arch/arm64/boot/dts/ti/k3-am64-main.dtsi
@@ -367,6 +367,51 @@
clocks = <_clks 145 0>;
};
 
+   main_gpio_intr: interrupt-controller0 {
+   compatible = "ti,sci-intr";
+   ti,intr-trigger-type = <1>;
+   interrupt-controller;
+   interrupt-parent = <>;
+   #interrupt-cells = <1>;
+   ti,sci = <>;
+   ti,sci-dev-id = <3>;
+   ti,interrupt-ranges = <0 32 16>;
+   };
+
+   main_gpio0: gpio@60 {
+   compatible = "ti,am64-gpio", "ti,keystone-gpio";
+   reg = <0x0 0x0060 0x0 0x100>;
+   gpio-controller;
+   #gpio-cells = <2>;
+   interrupt-parent = <_gpio_intr>;
+   interrupts = <190>, <191>, <192>,
+<193>, <194>, <195>;
+   interrupt-controller;
+   #interrupt-cells = <2>;
+   ti,ngpio = <87>;
+   ti,davinci-gpio-unbanked = <0>;
+   power-domains = <_pds 77 TI_SCI_PD_EXCLUSIVE>;
+   clocks = <_clks 77 0>;
+   clock-names = "gpio";
+   };
+
+   main_gpio1: gpio@601000 {
+   compatible = "ti,am64-gpio", "ti,keystone-gpio";
+   reg = <0x0 0x00601000 0x0 0x100>;
+   gpio-controller;
+   #gpio-cells = <2>;
+   interrupt-parent = <_gpio_intr>;
+   interrupts = <180>, <181>, <182>,
+<183>, <184>, <185>;
+   interrupt-controller;
+   #interrupt-cells = <2>;
+   ti,ngpio = <88>;
+   ti,davinci-gpio-unbanked = <0>;
+   power-domains = <_pds 78 TI_SCI_PD_EXCLUSIVE>;
+   clocks = <_clks 78 0>;
+   clock-names = "gpio";
+   };
+
sdhci0: mmc@fa1 {
compatible = "ti,am64-sdhci-8bit";
reg = <0x00 0xfa1 0x00 0x260>, <0x00 0xfa18000 0x00 0x134>;
-- 
2.17.1



Re: [PATCH] copy_file_range.2: Kernel v5.12 updates

2021-02-28 Thread Amir Goldstein
On Mon, Mar 1, 2021 at 12:25 AM Steve French  wrote:
>
> On Sun, Feb 28, 2021 at 1:36 AM Amir Goldstein  wrote:
> >
> > On Sun, Feb 28, 2021 at 1:08 AM Steve French  wrote:
> > >
> > > On Fri, Feb 26, 2021 at 11:43 PM Amir Goldstein  
> > > wrote:
> > > >
> > > > On Sat, Feb 27, 2021 at 12:19 AM Alejandro Colomar (man-pages)
> > > >  wrote:
> > > > >
> > > > > Hello Amir, Luis,
> > > > >
> > > > > On 2/24/21 5:10 PM, Amir Goldstein wrote:
> > > > > > On Wed, Feb 24, 2021 at 4:22 PM Luis Henriques  
> > > > > > wrote:
> > > > > >>
> > > > > >> Update man-page with recent changes to this syscall.
> > > > > >>
> > > > > >> Signed-off-by: Luis Henriques 
> > > > > >> ---
> > > > > >> Hi!
> > > > > >>
> > > > > >> Here's a suggestion for fixing the manpage for copy_file_range().  
> > > > > >> Note that
> > > > > >> I've assumed the fix will hit 5.12.
> > > > > >>
> > > > > >>   man2/copy_file_range.2 | 10 +-
> > > > > >>   1 file changed, 9 insertions(+), 1 deletion(-)
> > > > > >>
> > > > > >> diff --git a/man2/copy_file_range.2 b/man2/copy_file_range.2
> > > > > >> index 611a39b8026b..b0fd85e2631e 100644
> > > > > >> --- a/man2/copy_file_range.2
> > > > > >> +++ b/man2/copy_file_range.2
> > > > > >> @@ -169,6 +169,9 @@ Out of memory.
> > > > > >>   .B ENOSPC
> > > > > >>   There is not enough space on the target filesystem to complete 
> > > > > >> the copy.
> > > > > >>   .TP
> > > > > >> +.B EOPNOTSUPP
> > > > >
> > > > > I'll add the kernel version here:
> > > > >
> > > > > .BR EOPNOTSUPP " (since Linux 5.12)"
> > > >
> > > > Error could be returned prior to 5.3 and would be probably returned
> > > > by future stable kernels 5.3..5.12 too
> > > >
> > > > >
> > > > > >> +The filesystem does not support this operation >> +.TP
> > > > > >>   .B EOVERFLOW
> > > > > >>   The requested source or destination range is too large to 
> > > > > >> represent in the
> > > > > >>   specified data types.
> > > > > >> @@ -187,7 +190,7 @@ refers to an active swap file.
> > > > > >>   .B EXDEV
> > > > > >>   The files referred to by
> > > > > >>   .IR fd_in " and " fd_out
> > > > > >> -are not on the same mounted filesystem (pre Linux 5.3).
> > > > > >> +are not on the same mounted filesystem (pre Linux 5.3 and post 
> > > > > >> Linux 5.12).
> > > > >
> > > > > I'm not sure that 'mounted' adds any value here.  Would you remove the
> > > > > word here?
> > > >
> > > > See rename(2). 'mounted' in this context is explained there.
> > > > HOWEVER, it does not fit here.
> > > > copy_file_range() IS allowed between two mounts of the same filesystem 
> > > > instance.
> > > >
> > > > To make things more complicated, it appears that cross mount clone is 
> > > > not
> > > > allowed via FICLONE/FICLONERANGE ioctl, so ioctl_ficlonerange(2) man 
> > > > page
> > > > also uses the 'mounted filesystem' terminology for EXDEV
> > > >
> > > > As things stand now, because of the fallback to clone logic,
> > > > copy_file_range() provides a way for users to clone across different 
> > > > mounts
> > > > of the same filesystem instance, which they cannot do with the FICLONE 
> > > > ioctl.
> > > >
> > > > Fun :)
> > > >
> > > > BTW, I don't know if preventing cross mount clone was done 
> > > > intentionally,
> > > > but as I wrote in a comment in the code once:
> > > >
> > > > /*
> > > >  * FICLONE/FICLONERANGE ioctls enforce that src and dest files 
> > > > are on
> > > >  * the same mount. Practically, they only need to be on the 
> > > > same file
> > > >  * system.
> > > >  */
> > > >
> > > > >
> > > > > It reads as if two separate devices with the same filesystem type 
> > > > > would
> > > > > still give this error.
> > > > >
> > > > > Per the LWN.net article Amir shared, this is permitted ("When called
> > > > > from user space, copy_file_range() will only try to copy a file across
> > > > > filesystems if the two are of the same type").
> > > > >
> > > > > This behavior was slightly different before 5.3 AFAICR (was it?) 
> > > > > ("until
> > > > > then, copy_file_range() refused to copy between files that were not
> > > > > located on the same filesystem.").  If that's the case, I'd specify 
> > > > > the
> > > > > difference, or more probably split the error into two, one before 5.3,
> > > > > and one since 5.12.
> > > > >
> > > >
> > > > True.
> > > >
> > > > > >
> > > > > > I think you need to drop the (Linux range) altogether.
> > > > >
> > > > > I'll keep the range.  Users of 5.3..5.11 might be surprised if the
> > > > > filesystems are different and they don't get an error, I think.
> > > > >
> > > > > I reworded it to follow other pages conventions:
> > > > >
> > > > > .BR EXDEV " (before Linux 5.3; or since Linux 5.12)"
> > > > >
> > > > > which renders as:
> > > > >
> > > > > EXDEV (before Linux 5.3; or since Linux 5.12)
> > > > >The files referred to by fd_in and fd_out are not on
> > > > >the same mounted filesystem.
> > > > >
> > > 

[PATCH] configfs: Fix use-after-free issue in __configfs_open_file

2021-02-28 Thread Chao Yu
From: Daiyue Zhang 

Commit b0841eefd969 ("configfs: provide exclusion between IO and removals")
uses ->frag_dead to mark the fragment state, thus no bothering with extra
refcount on config_item when opening a file. The configfs_get_config_item
was removed in __configfs_open_file, but not with config_item_put. So the
refcount on config_item will lost its balance, causing use-after-free
issues in some occasions like this:

Test:
1. Mount configfs on /config with read-only items:
drwxrwx--- 289 root   root0 2021-04-01 11:55 /config
drwxr-xr-x   2 root   root0 2021-04-01 11:54 /config/a
--w--w--w-   1 root   root 4096 2021-04-01 11:53 /config/a/1.txt
..

2. Then run:
for file in /config
do
echo $file
grep -R 'key' $file
done

3. __configfs_open_file will be called in parallel, the first one
got called will do:
if (file->f_mode & FMODE_READ) {
if (!(inode->i_mode & S_IRUGO))
goto out_put_module;
config_item_put(buffer->item);
kref_put()
package_details_release()
kfree()

the other one will run into use-after-free issues like this:
BUG: KASAN: use-after-free in __configfs_open_file+0x1bc/0x3b0
Read of size 8 at addr fff155f02480 by task grep/13096
CPU: 0 PID: 13096 Comm: grep VIP: 00 Tainted: GW   4.14.116-kasan #1
TGID: 13096 Comm: grep
Call trace:
dump_stack+0x118/0x160
kasan_report+0x22c/0x294
__asan_load8+0x80/0x88
__configfs_open_file+0x1bc/0x3b0
configfs_open_file+0x28/0x34
do_dentry_open+0x2cc/0x5c0
vfs_open+0x80/0xe0
path_openat+0xd8c/0x2988
do_filp_open+0x1c4/0x2fc
do_sys_open+0x23c/0x404
SyS_openat+0x38/0x48

Allocated by task 2138:
kasan_kmalloc+0xe0/0x1ac
kmem_cache_alloc_trace+0x334/0x394
packages_make_item+0x4c/0x180
configfs_mkdir+0x358/0x740
vfs_mkdir2+0x1bc/0x2e8
SyS_mkdirat+0x154/0x23c
el0_svc_naked+0x34/0x38

Freed by task 13096:
kasan_slab_free+0xb8/0x194
kfree+0x13c/0x910
package_details_release+0x524/0x56c
kref_put+0xc4/0x104
config_item_put+0x24/0x34
__configfs_open_file+0x35c/0x3b0
configfs_open_file+0x28/0x34
do_dentry_open+0x2cc/0x5c0
vfs_open+0x80/0xe0
path_openat+0xd8c/0x2988
do_filp_open+0x1c4/0x2fc
do_sys_open+0x23c/0x404
SyS_openat+0x38/0x48
el0_svc_naked+0x34/0x38

To fix this issue, remove the config_item_put in
__configfs_open_file to balance the refcount of config_item.

Fixes: b0841eefd969 ("configfs: provide exclusion between IO and removals")
Cc: Al Viro 
Cc: Joel Becker 
Cc: Christoph Hellwig 
Signed-off-by: Daiyue Zhang 
Signed-off-by: Yi Chen 
Signed-off-by: Ge Qiu 
Reviewed-by: Chao Yu 
---
 fs/configfs/file.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/configfs/file.c b/fs/configfs/file.c
index 1f0270229d7b..da8351d1e455 100644
--- a/fs/configfs/file.c
+++ b/fs/configfs/file.c
@@ -378,7 +378,7 @@ static int __configfs_open_file(struct inode *inode, struct 
file *file, int type
 
attr = to_attr(dentry);
if (!attr)
-   goto out_put_item;
+   goto out_free_buffer;
 
if (type & CONFIGFS_ITEM_BIN_ATTR) {
buffer->bin_attr = to_bin_attr(dentry);
@@ -391,7 +391,7 @@ static int __configfs_open_file(struct inode *inode, struct 
file *file, int type
/* Grab the module reference for this attribute if we have one */
error = -ENODEV;
if (!try_module_get(buffer->owner))
-   goto out_put_item;
+   goto out_free_buffer;
 
error = -EACCES;
if (!buffer->item->ci_type)
@@ -435,8 +435,6 @@ static int __configfs_open_file(struct inode *inode, struct 
file *file, int type
 
 out_put_module:
module_put(buffer->owner);
-out_put_item:
-   config_item_put(buffer->item);
 out_free_buffer:
up_read(>frag_sem);
kfree(buffer);
-- 
2.29.2



drivers/accessibility/speakup/speakup_dtlk.c:334:14: warning: performing pointer arithmetic on a null pointer has undefined behavior

2021-02-28 Thread kernel test robot
Hi Samuel,

First bad commit (maybe != root cause):

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   fe07bfda2fb9cdef8a4d4008a409bb02f35f1bd8
commit: 2067fd92d75b6d9085a43caf050bca5d88c491b8 staging/speakup: Move out of 
staging
date:   7 months ago
config: riscv-randconfig-r002-20210301 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 
5de09ef02e24d234d9fc0cd1c6dfe18a1bb784b0)
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
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=2067fd92d75b6d9085a43caf050bca5d88c491b8
git remote add linus 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout 2067fd92d75b6d9085a43caf050bca5d88c491b8
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=riscv 

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

All warnings (new ones prefixed by >>):

   In file included from drivers/accessibility/speakup/speakup_dtlk.c:18:
   In file included from drivers/accessibility/speakup/spk_priv.h:16:
   In file included from drivers/accessibility/speakup/spk_types.h:17:
   In file included from include/linux/io.h:13:
   In file included from arch/riscv/include/asm/io.h:148:
   include/asm-generic/io.h:556:9: warning: performing pointer arithmetic on a 
null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   return inb(addr);
  ^
   arch/riscv/include/asm/io.h:54:76: note: expanded from macro 'inb'
   #define inb(c)  ({ u8  __v; __io_pbr(); __v = 
readb_cpu((void*)(PCI_IOBASE + (c))); __io_par(__v); __v; })
   
~~ ^
   arch/riscv/include/asm/mmio.h:93:48: note: expanded from macro 'readb_cpu'
   #define readb_cpu(c)({ u8  __r = __raw_readb(c); __r; })
^
   In file included from drivers/accessibility/speakup/speakup_dtlk.c:18:
   In file included from drivers/accessibility/speakup/spk_priv.h:16:
   In file included from drivers/accessibility/speakup/spk_types.h:17:
   In file included from include/linux/io.h:13:
   In file included from arch/riscv/include/asm/io.h:148:
   include/asm-generic/io.h:564:9: warning: performing pointer arithmetic on a 
null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   return inw(addr);
  ^
   arch/riscv/include/asm/io.h:55:76: note: expanded from macro 'inw'
   #define inw(c)  ({ u16 __v; __io_pbr(); __v = 
readw_cpu((void*)(PCI_IOBASE + (c))); __io_par(__v); __v; })
   
~~ ^
   arch/riscv/include/asm/mmio.h:94:76: note: expanded from macro 'readw_cpu'
   #define readw_cpu(c)({ u16 __r = le16_to_cpu((__force 
__le16)__raw_readw(c)); __r; })

^
   include/uapi/linux/byteorder/little_endian.h:36:51: note: expanded from 
macro '__le16_to_cpu'
   #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
 ^
   In file included from drivers/accessibility/speakup/speakup_dtlk.c:18:
   In file included from drivers/accessibility/speakup/spk_priv.h:16:
   In file included from drivers/accessibility/speakup/spk_types.h:17:
   In file included from include/linux/io.h:13:
   In file included from arch/riscv/include/asm/io.h:148:
   include/asm-generic/io.h:572:9: warning: performing pointer arithmetic on a 
null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   return inl(addr);
  ^
   arch/riscv/include/asm/io.h:56:76: note: expanded from macro 'inl'
   #define inl(c)  ({ u32 __v; __io_pbr(); __v = 
readl_cpu((void*)(PCI_IOBASE + (c))); __io_par(__v); __v; })
   
~~ ^
   arch/riscv/include/asm/mmio.h:95:76: note: expanded from macro 'readl_cpu'
   #define readl_cpu(c)({ u32 __r = le32_to_cpu((__force 
__le32)__raw_readl(c)); __r; })

^
   include/uapi/linux/byteorder/little_endian.h:34:51: note: expanded from 
macro '__le32_to_cpu'
   #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
 ^
   In file included from 

Re: [linux-next:master 5983/6048] h8300-linux-ld: section .data VMA overlaps section __kcrctab VMA

2021-02-28 Thread Feng Tang
Hi Paul,

On Wed, Feb 10, 2021 at 02:21:41AM +0800, Paul Moore wrote:
> On Tue, Feb 9, 2021 at 1:09 PM kernel test robot  wrote:
> > tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git 
> > master
> > head:   59fa6a163ffabc1bf25c5e0e33899e268a96d3cc
> > commit: 77d8143a5290b38e3331f61f55c0b682699884bc [5983/6048] Merge 
> > remote-tracking branch 'selinux/next'
> > config: h8300-randconfig-r005-20210209 (attached as .config)
> > compiler: h8300-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
> > # 
> > https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=77d8143a5290b38e3331f61f55c0b682699884bc
> > git remote add linux-next 
> > https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
> > git fetch --no-tags linux-next master
> > git checkout 77d8143a5290b38e3331f61f55c0b682699884bc
> > # save the attached .config to linux build tree
> > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross 
> > ARCH=h8300
> >
> > If you fix the issue, kindly add following tag as appropriate
> > Reported-by: kernel test robot 
> >
> > All errors (new ones prefixed by >>):
> >
> >h8300-linux-ld: section .init.text LMA 
> > [00430360,004479a1] overlaps section .data LMA 
> > [0041868c,004489eb]
> > >> h8300-linux-ld: section .data VMA [0040,0043035f] 
> > >> overlaps section __kcrctab VMA [003fdd74,0040007b]
> > >> h8300-linux-ld: section __kcrctab_gpl VMA 
> > >> [0040007c,004025a7] overlaps section .data VMA 
> > >> [0040,0043035f]
> >h8300-linux-ld: arch/h8300/kernel/entry.o: in function `resume_kernel':
> >(.text+0x29a): undefined reference to `TI_PRE_COUNT'
> 
> This really doesn't look like something caused by SELinux ...

No, this is not related with SELinux, sorry for the false alarm.

Further check shows it is related with the kernel config and the
built-out kernel size. With the kernel config, the ROM size is 4MB
large, and when the config selects many components, its .text and
.rodata may exceeds the 4MB size limit, causes the "overlaps section"
errors.

If we trim the kernel config and enable the "CONFIG_TRIM_UNUSED_KSYMS",
then the compilation can succeed.

For testing kbuild on platforms which has special size limits, one
thought is the kernel config may need to be chosen specifically.

Thanks,
Feng

> --
> paul moore
> www.paul-moore.com
> 


[PATCH] arm64: dts: ti: k3-am642-evm: Add support for SPI EEPROM

2021-02-28 Thread Aswath Govindraju
Add pinmux details and device tree node for the EEPROM attached to SPI0
module in main domain.

Signed-off-by: Aswath Govindraju 
---

This patch depends on,
https://patchwork.kernel.org/project/linux-arm-kernel/patch/20210301055109.17626-3-a-govindr...@ti.com/

 arch/arm64/boot/dts/ti/k3-am642-evm.dts | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/arch/arm64/boot/dts/ti/k3-am642-evm.dts 
b/arch/arm64/boot/dts/ti/k3-am642-evm.dts
index bfd849a29655..bc5bd7f896ab 100644
--- a/arch/arm64/boot/dts/ti/k3-am642-evm.dts
+++ b/arch/arm64/boot/dts/ti/k3-am642-evm.dts
@@ -139,6 +139,15 @@
AM64X_IOPAD(0x02a8, PIN_OUTPUT, 0) /* (E19) 
USB0_DRVVBUS */
>;
};
+
+   main_spi0_pins_default: main-spi0-pins-default {
+   pinctrl-single,pins = <
+   AM64X_IOPAD(0x0210, PIN_INPUT, 0) /* (D13) SPI0_CLK */
+   AM64X_IOPAD(0x0208, PIN_OUTPUT, 0) /* (D12) SPI0_CS0 */
+   AM64X_IOPAD(0x0214, PIN_OUTPUT, 0) /* (A13) SPI0_D0 */
+   AM64X_IOPAD(0x0218, PIN_INPUT, 0) /* (A14) SPI0_D1 */
+   >;
+   };
 };
 
 _uart0 {
@@ -245,6 +254,19 @@
pinctrl-0 = <_usb0_pins_default>;
 };
 
+_spi0 {
+   pinctrl-names = "default";
+   pinctrl-0 = <_spi0_pins_default>;
+   ti,pindir-d0-out-d1-in = <1>;
+   eeprom@0 {
+   compatible = "microchip,93lc46b";
+   reg = <0>;
+   spi-max-frequency = <100>;
+   spi-cs-high;
+   data-size = <16>;
+   };
+};
+
  {
/* emmc */
bus-width = <8>;
-- 
2.17.1



[PATCH] inetpeer: use div64_ul() and clamp_val() calculate inet_peer_threshold

2021-02-28 Thread Yejune Deng
In inet_initpeers(), struct inet_peer on IA32 uses 128 bytes in nowdays.
Get rid of the cascade and use div64_ul() and clamp_val() calculate that
will not need to be adjusted in the future as suggested by Eric Dumazet.

Suggested-by: Eric Dumazet 
Signed-off-by: Yejune Deng 
---
 net/ipv4/inetpeer.c | 21 +++--
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
index ff327a62c9ce..da21dfce24d7 100644
--- a/net/ipv4/inetpeer.c
+++ b/net/ipv4/inetpeer.c
@@ -65,7 +65,7 @@ EXPORT_SYMBOL_GPL(inet_peer_base_init);
 #define PEER_MAX_GC 32
 
 /* Exported for sysctl_net_ipv4.  */
-int inet_peer_threshold __read_mostly = 65536 + 128;   /* start to throw 
entries more
+int inet_peer_threshold __read_mostly; /* start to throw entries more
 * aggressively at this stage */
 int inet_peer_minttl __read_mostly = 120 * HZ; /* TTL under high load: 120 sec 
*/
 int inet_peer_maxttl __read_mostly = 10 * 60 * HZ; /* usual time to live: 
10 min */
@@ -73,20 +73,13 @@ int inet_peer_maxttl __read_mostly = 10 * 60 * HZ;  /* 
usual time to live: 10 min
 /* Called from ip_output.c:ip_init  */
 void __init inet_initpeers(void)
 {
-   struct sysinfo si;
+   u64 nr_entries;
 
-   /* Use the straight interface to information about memory. */
-   si_meminfo();
-   /* The values below were suggested by Alexey Kuznetsov
-* .  I don't have any opinion about the values
-* myself.  --SAW
-*/
-   if (si.totalram <= (32768*1024)/PAGE_SIZE)
-   inet_peer_threshold >>= 1; /* max pool size about 1MB on IA32 */
-   if (si.totalram <= (16384*1024)/PAGE_SIZE)
-   inet_peer_threshold >>= 1; /* about 512KB */
-   if (si.totalram <= (8192*1024)/PAGE_SIZE)
-   inet_peer_threshold >>= 2; /* about 128KB */
+/* 1% of physical memory */
+   nr_entries = div64_ul((u64)totalram_pages() << PAGE_SHIFT,
+ 100 * L1_CACHE_ALIGN(sizeof(struct inet_peer)));
+
+   inet_peer_threshold = clamp_val(nr_entries, 4096, 65536 + 128);
 
peer_cachep = kmem_cache_create("inet_peer_cache",
sizeof(struct inet_peer),
-- 
2.29.0



[PATCH v3 4/4] MAINTAINERS: Add entry for Intel MAX 10 mfd driver

2021-02-28 Thread Xu Yilun
This patch adds maintainer info for Intel MAX 10 mfd driver.

Signed-off-by: Xu Yilun 
Reviewed-by: Tom Rix 
---
v3: Add Tom Rix as the reviewer.
---
 MAINTAINERS | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index b58a469..ab31c01 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -9116,6 +9116,16 @@ F:   include/linux/mei_cl_bus.h
 F: include/uapi/linux/mei.h
 F: samples/mei/*
 
+INTEL MAX 10 BMC MFD DRIVER
+M: Xu Yilun 
+R: Tom Rix 
+S: Maintained
+F: Documentation/ABI/testing/sysfs-driver-intel-m10-bmc
+F: Documentation/hwmon/intel-m10-bmc-hwmon.rst
+F: drivers/hwmon/intel-m10-bmc-hwmon.c
+F: drivers/mfd/intel-m10-bmc.c
+F: include/linux/mfd/intel-m10-bmc.h
+
 INTEL MENLOW THERMAL DRIVER
 M: Sujith Thomas 
 L: platform-driver-...@vger.kernel.org
-- 
2.7.4



[PATCH v3 3/4] mfd: intel-m10-bmc: Add access table configuration to the regmap

2021-02-28 Thread Xu Yilun
From: Matthew Gerlach 

This patch adds access tables to the MAX 10 BMC regmap. This prevents
the host from accessing the unwanted I/O space. It also filters out the
invalid outputs when reading the regmap debugfs interface.

Signed-off-by: Matthew Gerlach 
Signed-off-by: Xu Yilun 
Reviewed-by: Tom Rix 
---
v2: Use the new macro M10BMC_LEGACY_BUILD_VER
v3: No change, rebased to 5.12-rc1
---
 drivers/mfd/intel-m10-bmc.c   | 13 +
 include/linux/mfd/intel-m10-bmc.h |  5 -
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/intel-m10-bmc.c b/drivers/mfd/intel-m10-bmc.c
index 0d2c03f..1932101 100644
--- a/drivers/mfd/intel-m10-bmc.c
+++ b/drivers/mfd/intel-m10-bmc.c
@@ -23,10 +23,23 @@ static struct mfd_cell m10bmc_pacn3000_subdevs[] = {
{ .name = "n3000bmc-secure" },
 };
 
+static const struct regmap_range m10bmc_regmap_range[] = {
+   regmap_reg_range(M10BMC_LEGACY_BUILD_VER, M10BMC_LEGACY_BUILD_VER),
+   regmap_reg_range(M10BMC_SYS_BASE, M10BMC_SYS_END),
+   regmap_reg_range(M10BMC_FLASH_BASE, M10BMC_FLASH_END),
+};
+
+static const struct regmap_access_table m10bmc_access_table = {
+   .yes_ranges = m10bmc_regmap_range,
+   .n_yes_ranges   = ARRAY_SIZE(m10bmc_regmap_range),
+};
+
 static struct regmap_config intel_m10bmc_regmap_config = {
.reg_bits = 32,
.val_bits = 32,
.reg_stride = 4,
+   .wr_table = _access_table,
+   .rd_table = _access_table,
.max_register = M10BMC_MEM_END,
 };
 
diff --git a/include/linux/mfd/intel-m10-bmc.h 
b/include/linux/mfd/intel-m10-bmc.h
index 4f1071f..c4eb38c 100644
--- a/include/linux/mfd/intel-m10-bmc.h
+++ b/include/linux/mfd/intel-m10-bmc.h
@@ -11,7 +11,10 @@
 
 #define M10BMC_LEGACY_BUILD_VER0x300468
 #define M10BMC_SYS_BASE0x300800
-#define M10BMC_MEM_END 0x1fff
+#define M10BMC_SYS_END 0x300fff
+#define M10BMC_FLASH_BASE  0x1000
+#define M10BMC_FLASH_END   0x1fff
+#define M10BMC_MEM_END M10BMC_FLASH_END
 
 /* Register offset of system registers */
 #define NIOS2_FW_VERSION   0x0
-- 
2.7.4



[PATCH v3 1/4] mfd: intel-m10-bmc: Fix the register access range

2021-02-28 Thread Xu Yilun
This patch fixes the max register address of MAX 10 BMC. The range
0x2000 ~ 0x20fc are for control registers of the QSPI flash
controller, which are not accessible to host.

Signed-off-by: Xu Yilun 
Reviewed-by: Tom Rix 
---
v2: no change.
v3: no change, rebased to 5.12-rc1
---
 include/linux/mfd/intel-m10-bmc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/mfd/intel-m10-bmc.h 
b/include/linux/mfd/intel-m10-bmc.h
index 74d4e19..9b54ca1 100644
--- a/include/linux/mfd/intel-m10-bmc.h
+++ b/include/linux/mfd/intel-m10-bmc.h
@@ -11,7 +11,7 @@
 
 #define M10BMC_LEGACY_SYS_BASE 0x300400
 #define M10BMC_SYS_BASE0x300800
-#define M10BMC_MEM_END 0x20fc
+#define M10BMC_MEM_END 0x1fff
 
 /* Register offset of system registers */
 #define NIOS2_FW_VERSION   0x0
-- 
2.7.4



[PATCH v3 0/4] Some improvement for Intel MAX 10 MFD drivers

2021-02-28 Thread Xu Yilun
This patchset is some improvements for intel-m10-bmc and its subdevs.

Main changes from v1:
- Add a patch (#2) to simplify the definition of the legacy version reg.
- Add a patch (#4), add entry in MAINTAINERS for intel-m10-bmc mfd driver
  and the subdev drivers.

Main changes from v2:
- Add Tom Rix as the reviewer for intel-m10-bmc mfd driver and the subdev
  drivers.
- Rebased to 5.12-rc1


Matthew Gerlach (1):
  mfd: intel-m10-bmc: Add access table configuration to the regmap

Xu Yilun (3):
  mfd: intel-m10-bmc: Fix the register access range
  mfd: intel-m10-bmc: Simplify the legacy version reg definition
  MAINTAINERS: Add entry for Intel MAX 10 mfd driver

 MAINTAINERS   | 10 ++
 drivers/mfd/intel-m10-bmc.c   | 25 ++---
 include/linux/mfd/intel-m10-bmc.h |  7 +--
 3 files changed, 33 insertions(+), 9 deletions(-)

-- 
2.7.4



[PATCH v3 2/4] mfd: intel-m10-bmc: Simplify the legacy version reg definition

2021-02-28 Thread Xu Yilun
The version register is the only one in the legacy I/O space to be
accessed, so it is not necessary to define the legacy base & version
register offset. A direct definition of the legacy version register
address would be fine.

Signed-off-by: Xu Yilun 
Reviewed-by: Tom Rix 
---
v3: no change, rebased to 5.12-rc1
---
 drivers/mfd/intel-m10-bmc.c   | 12 +---
 include/linux/mfd/intel-m10-bmc.h |  2 +-
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/mfd/intel-m10-bmc.c b/drivers/mfd/intel-m10-bmc.c
index 06c9775..0d2c03f 100644
--- a/drivers/mfd/intel-m10-bmc.c
+++ b/drivers/mfd/intel-m10-bmc.c
@@ -117,16 +117,14 @@ static int check_m10bmc_version(struct intel_m10bmc 
*ddata)
 
/*
 * This check is to filter out the very old legacy BMC versions,
-* M10BMC_LEGACY_SYS_BASE is the offset to this old block of mmio
-* registers. In the old BMC chips, the BMC version info is stored
-* in this old version register (M10BMC_LEGACY_SYS_BASE +
-* M10BMC_BUILD_VER), so its read out value would have not been
-* LEGACY_INVALID (0x). But in new BMC chips that the
+* 0x300400 is the offset to this old block of mmio registers. In the
+* old BMC chips, the BMC version info is stored in this old version
+* register (0x300400 + 0x68), so its read out value would have not
+* been LEGACY_INVALID (0x). But in new BMC chips that the
 * driver supports, the value of this register should be
 * LEGACY_INVALID.
 */
-   ret = m10bmc_raw_read(ddata,
- M10BMC_LEGACY_SYS_BASE + M10BMC_BUILD_VER, );
+   ret = m10bmc_raw_read(ddata, M10BMC_LEGACY_BUILD_VER, );
if (ret)
return -ENODEV;
 
diff --git a/include/linux/mfd/intel-m10-bmc.h 
b/include/linux/mfd/intel-m10-bmc.h
index 9b54ca1..4f1071f 100644
--- a/include/linux/mfd/intel-m10-bmc.h
+++ b/include/linux/mfd/intel-m10-bmc.h
@@ -9,7 +9,7 @@
 
 #include 
 
-#define M10BMC_LEGACY_SYS_BASE 0x300400
+#define M10BMC_LEGACY_BUILD_VER0x300468
 #define M10BMC_SYS_BASE0x300800
 #define M10BMC_MEM_END 0x1fff
 
-- 
2.7.4



Re: [PATCH v2] kdb: Get rid of custom debug heap allocator

2021-02-28 Thread Sumit Garg
On Fri, 26 Feb 2021 at 23:07, Daniel Thompson
 wrote:
>
> On Fri, Feb 26, 2021 at 06:12:13PM +0530, Sumit Garg wrote:
> > On Fri, 26 Feb 2021 at 16:29, Daniel Thompson
> >  wrote:
> > >
> > > On Fri, Feb 26, 2021 at 03:23:06PM +0530, Sumit Garg wrote:
> > > > Currently the only user for debug heap is kdbnearsym() which can be
> > > > modified to rather ask the caller to supply a buffer for symbol name.
> > > > So do that and modify kdbnearsym() callers to pass a symbol name buffer
> > > > allocated statically and hence remove custom debug heap allocator.
> > >
> > > Why make the callers do this?
> > >
> > > The LRU buffers were managed inside kdbnearsym() why does switching to
> > > an approach with a single buffer require us to push that buffer out to
> > > the callers?
> > >
> >
> > Earlier the LRU buffers managed namebuf uniqueness per caller (upto
> > 100 callers)
>
> The uniqueness is per symbol, not per caller.
>

Agree.

> > but if we switch to single entry in kdbnearsym() then all
> > callers need to share common buffer which will lead to incorrect
> > results from following simple sequence:
> >
> > kdbnearsym(word, );
> > kdbnearsym(word, );
> > kdb_symbol_print(word, , 0);
> > kdb_symbol_print(word, , 0);
> >
> > But if we change to a unique static namebuf per caller then the
> > following sequence will work:
> >
> > kdbnearsym(word, , namebuf1);
> > kdbnearsym(word, , namebuf2);
> > kdb_symbol_print(word, , 0);
> > kdb_symbol_print(word, , 0);
>
> This is true but do any of the callers of kdbnearsym ever do this?

No, but any of prospective callers may need this.

> The
> main reaason that heap stuck out as redundant was that I've only ever
> seen the output of kdbnearsym() consumed almost immediately by a print.
>

Yeah but I think the alternative proposed in this patch isn't as
burdensome as the heap and tries to somewhat match existing
functionality.

> I wrote an early version of a patch like this that just shrunk the LRU
> cache down to 2 and avoided any heap usage... but I threw it away
> when I realized we never carry cached values outside the function
> that obtained them.
>

Okay, so if you still think that having a single static buffer inside
kdbnearsym() is an appropriate approach for time being then I will
switch to use that instead.

-Sumit

>
> > > > @@ -526,6 +526,7 @@ int kdbgetaddrarg(int argc, const char **argv, int 
> > > > *nextarg,
> >
> > >
> > > > diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
> > > > index 9d69169582c6..6efe9ec53906 100644
> > > > --- a/kernel/debug/kdb/kdb_main.c
> > > > +++ b/kernel/debug/kdb/kdb_main.c
> > > > @@ -526,6 +526,7 @@ int kdbgetaddrarg(int argc, const char **argv, int 
> > > > *nextarg,
> > >
> > > The documentation comment for this function has not been updated to
> > > describe the new contract on callers of this function (e.g. if they
> > > consume the symbol name they must do so before calling kdbgetaddrarg()
> > > (and maybe kdbnearsym() again).
> > >
> >
> > I am not sure if I follow you here. If we have a unique static buffer
> > per caller then why do we need this new contract?
>
> I traced the code wrong. I thought it shared symtab->sym_name with its
> own caller... but it doesn't it shares synname with its caller and
> that's totally different...
>
>
> Daniel.
>
> >
> > >
> > > >   char symbol = '\0';
> > > >   char *cp;
> > > >   kdb_symtab_t symtab;
> > > > + static char namebuf[KSYM_NAME_LEN];
> > > >
> > > >   /*
> > > >* If the enable flags prohibit both arbitrary memory access
> > > > diff --git a/kernel/debug/kdb/kdb_support.c 
> > > > b/kernel/debug/kdb/kdb_support.c
> > > > index b59aad1f0b55..9b907a84f2db 100644
> > > > --- a/kernel/debug/kdb/kdb_support.c
> > > > +++ b/kernel/debug/kdb/kdb_support.c
> > > > @@ -57,8 +57,6 @@ int kdbgetsymval(const char *symname, kdb_symtab_t 
> > > > *symtab)
> > > >  }
> > > >  EXPORT_SYMBOL(kdbgetsymval);
> > > >
> > > > -static char *kdb_name_table[100];/* arbitrary size */
> > > > -
> > > >  /*
> > > >   * kdbnearsym -  Return the name of the symbol with the nearest 
> > > > address
> > > >   *   less than 'addr'.
> > >
> > > Again the documentation comment has not been updated and, in this case,
> > > is now misleading.
> >
> > Okay, I will fix it.
> >
> > >
> > > If we move the static buffer here then the remarks section on this
> > > function is a really good place to describe what the callers must do to
> > > manage the static buffer safely as well as a convenient place to mention
> > > that we tolerate the reuse of the static buffer if kdb is re-entered
> > > becase a) kdb is broken if that happens and b) we are crash resilient
> > > if if does.
> > >
> > >
> > > > @@ -79,13 +77,11 @@ static char *kdb_name_table[100]; /* arbitrary size 
> > > > */
> > > >   *   hold active strings, no kdb caller of kdbnearsym makes more
> > > >   *   than ~20 later calls before using a saved value.
> > > >   */
> > > > -int 

Re: [PATCH] drivers: gnu: drm: i915: gvt: Fixed couple of spellings in the file gtt.c

2021-02-28 Thread Zhenyu Wang
On 2021.02.22 06:22:37 -0800, Randy Dunlap wrote:
> On 2/22/21 6:21 AM, Randy Dunlap wrote:
> > On 2/22/21 12:18 AM, Bhaskar Chowdhury wrote:
> >>
> >> s/negtive/negative/
> >> s/possilbe/possible/
> >>
> >> Signed-off-by: Bhaskar Chowdhury 
> > 
> > Acked-by: Randy Dunlap 
> 
> except the Subject has a typo in it.
> s/gnu/gpu/
>

And pls follow gvt subsys's subject line as drm/i915/gvt: xxx in future.
I'll fix the title and queue this.

Thanks!

> >> ---
> >>  drivers/gpu/drm/i915/gvt/gtt.c | 4 ++--
> >>  1 file changed, 2 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/gpu/drm/i915/gvt/gtt.c 
> >> b/drivers/gpu/drm/i915/gvt/gtt.c
> >> index 897c007ea96a..dc5834bf4de2 100644
> >> --- a/drivers/gpu/drm/i915/gvt/gtt.c
> >> +++ b/drivers/gpu/drm/i915/gvt/gtt.c
> >> @@ -1159,8 +1159,8 @@ static inline void 
> >> ppgtt_generate_shadow_entry(struct intel_gvt_gtt_entry *se,
> >>   * @vgpu: target vgpu
> >>   * @entry: target pfn's gtt entry
> >>   *
> >> - * Return 1 if 2MB huge gtt shadowing is possilbe, 0 if miscondition,
> >> - * negtive if found err.
> >> + * Return 1 if 2MB huge gtt shadowing is possible, 0 if miscondition,
> >> + * negative if found err.
> >>   */
> >>  static int is_2MB_gtt_possible(struct intel_vgpu *vgpu,
> >>struct intel_gvt_gtt_entry *entry)
> >> --
> > 
> > 
> 
> 
> -- 
> ~Randy
> Reported-by: Randy Dunlap 
> ___
> intel-gvt-dev mailing list
> intel-gvt-...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gvt-dev


signature.asc
Description: PGP signature


Re: [PATCH] usb: dwc2: Add STM32 related debugfs entries

2021-02-28 Thread Minas Harutyunyan
On 2/28/2021 1:55 AM, Martin Devera wrote:
> These are entries related to STM32MP1 PHY control.
> 
> Signed-off-by: Martin Devera 

Acked-by: Minas Harutyunyan 

> ---
>   drivers/usb/dwc2/debugfs.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/usb/dwc2/debugfs.c b/drivers/usb/dwc2/debugfs.c
> index aaafd463d72a..f13eed4231e1 100644
> --- a/drivers/usb/dwc2/debugfs.c
> +++ b/drivers/usb/dwc2/debugfs.c
> @@ -691,6 +691,8 @@ static int params_show(struct seq_file *seq, void *v)
>   print_param(seq, p, ulpi_fs_ls);
>   print_param(seq, p, host_support_fs_ls_low_power);
>   print_param(seq, p, host_ls_low_power_phy_clk);
> + print_param(seq, p, activate_stm_fs_transceiver);
> + print_param(seq, p, activate_stm_id_vb_detection);
>   print_param(seq, p, ts_dline);
>   print_param(seq, p, reload_ctl);
>   print_param_hex(seq, p, ahbcfg);
> 



arch/mips/loongson64/cop2-ex.c:97:30: error: no member named 'fpu' in 'struct thread_struct'

2021-02-28 Thread kernel test robot
Hi Huacai,

FYI, the error/warning still remains.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   fe07bfda2fb9cdef8a4d4008a409bb02f35f1bd8
commit: f83e4f9896eff614d0f2547a561fa5f39f9cddde MIPS: Loongson-3: Add some 
unaligned instructions emulation
date:   10 months ago
config: mips-randconfig-r011-20210301 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 
b077d82b00d81934c7c27ac89dd8b0e7f448bded)
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
# install mips cross compiling tool for clang build
# apt-get install binutils-mips-linux-gnu
# 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f83e4f9896eff614d0f2547a561fa5f39f9cddde
git remote add linus 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout f83e4f9896eff614d0f2547a561fa5f39f9cddde
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=mips 

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

All errors (new ones prefixed by >>):

   arch/mips/include/asm/cmpxchg.h:102:7: note: expanded from macro 'xchg'
   if (!__SYNC_loongson3_war)  \
^
   arch/mips/include/asm/sync.h:147:34: note: expanded from macro 
'__SYNC_loongson3_war'
   # define __SYNC_loongson3_war   (1 << 31)
  ^
   In file included from arch/mips/loongson64/cop2-ex.c:14:
   In file included from include/linux/sched.h:15:
   In file included from include/linux/sem.h:5:
   In file included from include/uapi/linux/sem.h:5:
   In file included from include/linux/ipc.h:7:
   In file included from include/linux/rhashtable-types.h:15:
   In file included from include/linux/workqueue.h:9:
   In file included from include/linux/timer.h:6:
   In file included from include/linux/ktime.h:24:
   In file included from include/linux/time.h:74:
   In file included from include/linux/time32.h:13:
   In file included from include/linux/timex.h:65:
   In file included from arch/mips/include/asm/timex.h:19:
   In file included from arch/mips/include/asm/cpu-type.h:12:
   In file included from include/linux/smp.h:15:
   include/linux/llist.h:222:9: warning: converting the result of '<<' to a 
boolean always evaluates to true [-Wtautological-constant-compare]
   return xchg(>first, NULL);
  ^
   arch/mips/include/asm/cmpxchg.h:102:7: note: expanded from macro 'xchg'
   if (!__SYNC_loongson3_war)  \
^
   arch/mips/include/asm/sync.h:147:34: note: expanded from macro 
'__SYNC_loongson3_war'
   # define __SYNC_loongson3_war   (1 << 31)
  ^
   In file included from arch/mips/loongson64/cop2-ex.c:16:
   In file included from include/linux/ptrace.h:10:
   In file included from include/linux/pid_namespace.h:7:
   In file included from include/linux/mm.h:10:
   In file included from include/linux/gfp.h:9:
   include/linux/topology.h:119:9: error: implicit declaration of function 
'cpu_logical_map' [-Werror,-Wimplicit-function-declaration]
   return cpu_to_node(raw_smp_processor_id());
  ^
   arch/mips/include/asm/mach-loongson64/topology.h:7:27: note: expanded from 
macro 'cpu_to_node'
   #define cpu_to_node(cpu)(cpu_logical_map(cpu) >> 2)
^
   In file included from arch/mips/loongson64/cop2-ex.c:16:
   In file included from include/linux/ptrace.h:10:
   In file included from include/linux/pid_namespace.h:7:
   In file included from include/linux/mm.h:10:
   In file included from include/linux/gfp.h:9:
   include/linux/topology.h:176:9: error: implicit declaration of function 
'cpu_logical_map' [-Werror,-Wimplicit-function-declaration]
   return cpu_to_node(cpu);
  ^
   arch/mips/include/asm/mach-loongson64/topology.h:7:27: note: expanded from 
macro 'cpu_to_node'
   #define cpu_to_node(cpu)(cpu_logical_map(cpu) >> 2)
^
   In file included from arch/mips/loongson64/cop2-ex.c:16:
   In file included from include/linux/ptrace.h:10:
   In file included from include/linux/pid_namespace.h:7:
   In file included from include/linux/mm.h:10:
   In file included from include/linux/gfp.h:9:
   include/linux/topology.h:210:25: error: implicit declaration of function 
'cpu_logical_map' [-Werror,-Wimplicit-function-declaration]
   return cpumask_of_node(cpu_to_node(cpu));
  ^
   arch/mips/include/asm/mach-loongson64/topology.h:7:27: note: expanded from 
macro 'cpu_to_node'
   

Not yet merged patches

2021-02-28 Thread Eli Cohen
Hi Michael,

I see that you did not include these in your latest pull request.

https://lkml.org/lkml/2021/2/10/1386
https://lkml.org/lkml/2021/2/10/1383
https://lkml.org/lkml/2021/2/18/124

Are you going to merge them?



[PATCH 2/2] arm64: dts: ti: k3-am642-evm: Add USB support

2021-02-28 Thread Aswath Govindraju
AM64 EVM board has a micro USB 2.0 AB connector and the USB0_VBUS is
connected with a resistor divider in between. USB0_DRVVBUS pin is muxed
between USB0_DRVVBUS and GPIO1_79 signals.

Add the corresponding properties and set the pinmux mode for USB subsystem
in the evm dts file.

Signed-off-by: Aswath Govindraju 
Acked-by: Roger Quadros 
---
 arch/arm64/boot/dts/ti/k3-am642-evm.dts | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/arch/arm64/boot/dts/ti/k3-am642-evm.dts 
b/arch/arm64/boot/dts/ti/k3-am642-evm.dts
index 1f1787750fef..bfd849a29655 100644
--- a/arch/arm64/boot/dts/ti/k3-am642-evm.dts
+++ b/arch/arm64/boot/dts/ti/k3-am642-evm.dts
@@ -133,6 +133,12 @@
AM64X_IOPAD(0x026c, PIN_INPUT_PULLUP, 0) /* (B19) 
I2C1_SDA */
>;
};
+
+   main_usb0_pins_default: main-usb0-pins-default {
+   pinctrl-single,pins = <
+   AM64X_IOPAD(0x02a8, PIN_OUTPUT, 0) /* (E19) 
USB0_DRVVBUS */
+   >;
+   };
 };
 
 _uart0 {
@@ -227,6 +233,18 @@
status = "disabled";
 };
 
+ {
+   ti,vbus-divider;
+   ti,usb2-only;
+};
+
+ {
+   dr_mode = "otg";
+   maximum-speed = "high-speed";
+   pinctrl-names = "default";
+   pinctrl-0 = <_usb0_pins_default>;
+};
+
  {
/* emmc */
bus-width = <8>;
-- 
2.17.1



[PATCH 0/2] AM64: Add USB support

2021-02-28 Thread Aswath Govindraju
The following series of patches, add USB support for AM64.

This series of patches depends on,
https://patchwork.kernel.org/project/linux-arm-kernel/list/?series=439039

Aswath Govindraju (2):
  arm64: dts: ti: k3-am64-main: Add DT node for USB subsystem
  arm64: dts: ti: k3-am642-evm: Add USB support

 arch/arm64/boot/dts/ti/k3-am64-main.dtsi | 30 
 arch/arm64/boot/dts/ti/k3-am642-evm.dts  | 18 ++
 2 files changed, 48 insertions(+)

-- 
2.17.1



[PATCH 1/2] arm64: dts: ti: k3-am64-main: Add DT node for USB subsystem

2021-02-28 Thread Aswath Govindraju
Add DT node for the single USB subsystem in main dtsi file.

Signed-off-by: Aswath Govindraju 
Acked-by: Roger Quadros 
---
 arch/arm64/boot/dts/ti/k3-am64-main.dtsi | 30 
 1 file changed, 30 insertions(+)

diff --git a/arch/arm64/boot/dts/ti/k3-am64-main.dtsi 
b/arch/arm64/boot/dts/ti/k3-am64-main.dtsi
index 5f85950daef7..a36ebddf3a4c 100644
--- a/arch/arm64/boot/dts/ti/k3-am64-main.dtsi
+++ b/arch/arm64/boot/dts/ti/k3-am64-main.dtsi
@@ -402,4 +402,34 @@
ti,otap-del-sel-ddr50 = <0x9>;
ti,clkbuf-sel = <0x7>;
};
+
+   usbss0: cdns-usb@f90{
+   compatible = "ti,am64-usb", "ti,j721e-usb";
+   reg = <0x00 0xf90 0x00 0x100>;
+   power-domains = <_pds 161 TI_SCI_PD_EXCLUSIVE>;
+   clocks = <_clks 161 9>, <_clks 161 1>;
+   clock-names = "ref", "lpm";
+   assigned-clocks = <_clks 161 9>; /* USB2_REFCLK */
+   assigned-clock-parents = <_clks 161 10>; /* HF0SC0 */
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+   usb0: usb@f40{
+   compatible = "cdns,usb3";
+   reg = <0x00 0xf40 0x00 0x1>,
+ <0x00 0xf41 0x00 0x1>,
+ <0x00 0xf42 0x00 0x1>;
+   reg-names = "otg",
+   "xhci",
+   "dev";
+   interrupts = , /* 
irq.0 */
+, /* 
irq.6 */
+; /* 
otgirq */
+   interrupt-names = "host",
+ "peripheral",
+ "otg";
+   maximum-speed = "super-speed";
+   dr_mode = "otg";
+   };
+   };
 };
-- 
2.17.1



[PATCH] mm: Generalize HUGETLB_PAGE_SIZE_VARIABLE

2021-02-28 Thread Anshuman Khandual
HUGETLB_PAGE_SIZE_VARIABLE need not be defined for each individual
platform subscribing it. Instead just make it generic.

Cc: Michael Ellerman 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Andrew Morton 
Cc: Christoph Hellwig 
Cc: linux-i...@vger.kernel.org
Cc: linuxppc-...@lists.ozlabs.org
Cc: linux...@kvack.org
Cc: linux-kernel@vger.kernel.org
Suggested-by: Christoph Hellwig 
Signed-off-by: Anshuman Khandual 
---
This change was originally suggested in an earilier discussion. This
applies on v5.12-rc1 and has been build tested on all applicable
platforms i.e ia64 and powerpc.

https://patchwork.kernel.org/project/linux-mm/patch/1613024531-19040-3-git-send-email-anshuman.khand...@arm.com/

 arch/ia64/Kconfig| 6 +-
 arch/powerpc/Kconfig | 6 +-
 mm/Kconfig   | 8 
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
index 2ad7a8d29fcc..6b3e3f6c29ae 100644
--- a/arch/ia64/Kconfig
+++ b/arch/ia64/Kconfig
@@ -32,6 +32,7 @@ config IA64
select TTY
select HAVE_ARCH_TRACEHOOK
select HAVE_VIRT_CPU_ACCOUNTING
+   select HUGETLB_PAGE_SIZE_VARIABLE
select VIRT_TO_BUS
select GENERIC_IRQ_PROBE
select GENERIC_PENDING_IRQ if SMP
@@ -82,11 +83,6 @@ config STACKTRACE_SUPPORT
 config GENERIC_LOCKBREAK
def_bool n
 
-config HUGETLB_PAGE_SIZE_VARIABLE
-   bool
-   depends on HUGETLB_PAGE
-   default y
-
 config GENERIC_CALIBRATE_DELAY
bool
default y
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 3778ad17f56a..b8565bed284f 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -232,6 +232,7 @@ config PPC
select HAVE_HARDLOCKUP_DETECTOR_PERFif PERF_EVENTS && 
HAVE_PERF_EVENTS_NMI && !HAVE_HARDLOCKUP_DETECTOR_ARCH
select HAVE_PERF_REGS
select HAVE_PERF_USER_STACK_DUMP
+   select HUGETLB_PAGE_SIZE_VARIABLE   if PPC_BOOK3S_64
select MMU_GATHER_RCU_TABLE_FREE
select MMU_GATHER_PAGE_SIZE
select HAVE_REGS_AND_STACK_ACCESS_API
@@ -416,11 +417,6 @@ config HIGHMEM
 
 source "kernel/Kconfig.hz"
 
-config HUGETLB_PAGE_SIZE_VARIABLE
-   bool
-   depends on HUGETLB_PAGE && PPC_BOOK3S_64
-   default y
-
 config MATH_EMULATION
bool "Math emulation"
depends on 4xx || PPC_8xx || PPC_MPC832x || BOOKE
diff --git a/mm/Kconfig b/mm/Kconfig
index 24c045b24b95..e604a87862a4 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -274,6 +274,14 @@ config ARCH_ENABLE_HUGEPAGE_MIGRATION
 config ARCH_ENABLE_THP_MIGRATION
bool
 
+config HUGETLB_PAGE_SIZE_VARIABLE
+   def_bool n
+   depends on HUGETLB_PAGE
+   help
+ When there are multiple HugeTLB sizes available on a platform
+ and pageblock_order could then be a dynamic value instead of
+ standard HUGETLB_PAGE_ORDER.
+
 config CONTIG_ALLOC
def_bool (MEMORY_ISOLATION && COMPACTION) || CMA
 
-- 
2.20.1



Re: [PATCH] arm64: dts: ti: k3-j721e-main: Update the speed modes supported and their itap delay values for MMCSD subsystems

2021-02-28 Thread Kishon Vijay Abraham I
On 25/02/21 6:57 pm, Aswath Govindraju wrote:
> According to latest errata of J721e [1], HS400 mode is not supported
> in MMCSD0 subsystem (i2024) and SDR104 mode is not supported in MMCSD1/2
> subsystems (i2090). Therefore, replace mmc-hs400-1_8v with mmc-hs200-1_8v
> in MMCSD0 subsystem and add a sdhci mask to disable SDR104 speed mode.
> 
> Also, update the itap delay values for all the MMCSD subsystems according
> the latest J721e data sheet[2]
> 
> [1] - https://www.ti.com/lit/er/sprz455/sprz455.pdf
> [2] - https://www.ti.com/lit/ds/symlink/tda4vm.pdf
> 
> Fixes: e6dc10f200da ("arm64: dts: ti: j721e-main: Add SDHCI nodes")
> Signed-off-by: Aswath Govindraju 

Reviewed-by: Kishon Vijay Abraham I 

Thanks
Kishon

> ---
>  arch/arm64/boot/dts/ti/k3-j721e-main.dtsi | 17 -
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/boot/dts/ti/k3-j721e-main.dtsi 
> b/arch/arm64/boot/dts/ti/k3-j721e-main.dtsi
> index 8c84dafb7125..f1e7da3dfa27 100644
> --- a/arch/arm64/boot/dts/ti/k3-j721e-main.dtsi
> +++ b/arch/arm64/boot/dts/ti/k3-j721e-main.dtsi
> @@ -1042,13 +1042,16 @@
>   assigned-clocks = <_clks 91 1>;
>   assigned-clock-parents = <_clks 91 2>;
>   bus-width = <8>;
> - mmc-hs400-1_8v;
> + mmc-hs200-1_8v;
>   mmc-ddr-1_8v;
>   ti,otap-del-sel-legacy = <0xf>;
>   ti,otap-del-sel-mmc-hs = <0xf>;
>   ti,otap-del-sel-ddr52 = <0x5>;
>   ti,otap-del-sel-hs200 = <0x6>;
>   ti,otap-del-sel-hs400 = <0x0>;
> + ti,itap-del-sel-legacy = <0x10>;
> + ti,itap-del-sel-mmc-hs = <0xa>;
> + ti,itap-del-sel-ddr52 = <0x3>;
>   ti,trm-icp = <0x8>;
>   ti,strobe-sel = <0x77>;
>   dma-coherent;
> @@ -1069,9 +1072,15 @@
>   ti,otap-del-sel-sdr25 = <0xf>;
>   ti,otap-del-sel-sdr50 = <0xc>;
>   ti,otap-del-sel-ddr50 = <0xc>;
> + ti,itap-del-sel-legacy = <0x0>;
> + ti,itap-del-sel-sd-hs = <0x0>;
> + ti,itap-del-sel-sdr12 = <0x0>;
> + ti,itap-del-sel-sdr25 = <0x0>;
> + ti,itap-del-sel-ddr50 = <0x2>;
>   ti,trm-icp = <0x8>;
>   ti,clkbuf-sel = <0x7>;
>   dma-coherent;
> + sdhci-caps-mask = <0x2 0x0>;
>   };
>  
>   main_sdhci2: mmc@4f98000 {
> @@ -1089,9 +1098,15 @@
>   ti,otap-del-sel-sdr25 = <0xf>;
>   ti,otap-del-sel-sdr50 = <0xc>;
>   ti,otap-del-sel-ddr50 = <0xc>;
> + ti,itap-del-sel-legacy = <0x0>;
> + ti,itap-del-sel-sd-hs = <0x0>;
> + ti,itap-del-sel-sdr12 = <0x0>;
> + ti,itap-del-sel-sdr25 = <0x0>;
> + ti,itap-del-sel-ddr50 = <0x2>;
>   ti,trm-icp = <0x8>;
>   ti,clkbuf-sel = <0x7>;
>   dma-coherent;
> + sdhci-caps-mask = <0x2 0x0>;
>   };
>  
>   usbss0: cdns-usb@4104000 {
> 


Re: [PATCH] Input: elan_i2c - Reduce the resume time for new devices

2021-02-28 Thread Dmitry Torokhov
Hi Jingle,

On Fri, Feb 26, 2021 at 03:35:37PM +0800, jingle.wu wrote:
> @@ -273,10 +318,12 @@ static int __elan_initialize(struct elan_tp_data *data)
>   bool woken_up = false;
>   int error;
>  
> - error = data->ops->initialize(client);
> - if (error) {
> - dev_err(>dev, "device initialize failed: %d\n", error);
> - return error;
> + if (!(data->quirks & ETP_QUIRK_SET_QUICK_WAKEUP_DEV)) {
> + error = data->ops->initialize(client);
> + if (error) {
> + dev_err(>dev, "device initialize failed: %d\n", 
> error);
> + return error;
> + }

So data->ops->initialize(client) essentially performs reset of the
controller (we may want to rename it even) and as far as I understand
you would want to avoid resetting the controller on newer devices,
right?

My question is how behavior of older devices differ from the new ones
(are they stay in "undefined" state at power up) and whether it is
possible to determine if controller is in operating mode. For example,
what would happen on older devices if we call elan_query_product() below
without resetting the controller?

I also think that while I can see us skipping reset in resume paths we
probably want to keep it in probe as we really do not know the state of
the device (was it powered up properly earlier, etc).

>   }
>  
>   error = elan_query_product(data);
> @@ -366,6 +413,8 @@ static int elan_query_device_info(struct elan_tp_data 
> *data)
>   if (error)
>   return error;
>  
> + data->quirks = elan_i2c_lookup_quirk(data->ic_type, data->product_id);
> +
>   error = elan_get_fwinfo(data->ic_type, data->iap_version,
>   >fw_validpage_count,
>   >fw_signature_address,
> -- 
> 2.17.1
> 

Thanks.

-- 
Dmitry


Re: [PATCH v17 4/9] mm: hugetlb: alloc the vmemmap pages associated with each HugeTLB page

2021-02-28 Thread Muchun Song
On Thu, Feb 25, 2021 at 9:24 PM Muchun Song  wrote:
>
> When we free a HugeTLB page to the buddy allocator, we should allocate
> the vmemmap pages associated with it. But we may cannot allocate vmemmap
> pages when the system is under memory pressure, in this case, we just
> refuse to free the HugeTLB page instead of looping forever trying to
> allocate the pages. This changes some behavior (list below) on some
> corner cases.
>
>  1) Failing to free a huge page triggered by the user (decrease nr_pages).
>
> Need try again later by the user.
>
>  2) Failing to free a surplus huge page when freed by the application.
>
> Try again later when freeing a huge page next time.
>
>  3) Failing to dissolve a free huge page on ZONE_MOVABLE via
> offline_pages().
>
> This is a bit unfortunate if we have plenty of ZONE_MOVABLE memory
> but are low on kernel memory. For example, migration of huge pages
> would still work, however, dissolving the free page does not work.
> This is a corner cases. When the system is that much under memory
> pressure, offlining/unplug can be expected to fail. This is
> unfortunate because it prevents from the memory offlining which
> shouldn't happen for movable zones. People depending on the memory
> hotplug and movable zone should carefuly consider whether savings
> on unmovable memory are worth losing their hotplug functionality
> in some situations.
>
>  4) Failing to dissolve a huge page on CMA/ZONE_MOVABLE via
> alloc_contig_range() - once we have that handling in place. Mainly
> affects CMA and virtio-mem.
>
> Similar to 3). virito-mem will handle migration errors gracefully.
> CMA might be able to fallback on other free areas within the CMA
> region.
>
> Vmemmap pages are allocated from the page freeing context. In order for
> those allocations to be not disruptive (e.g. trigger oom killer)
> __GFP_NORETRY is used. hugetlb_lock is dropped for the allocation
> because a non sleeping allocation would be too fragile and it could fail
> too easily under memory pressure. GFP_ATOMIC or other modes to access
> memory reserves is not used because we want to prevent consuming
> reserves under heavy hugetlb freeing.

Hi,

Since this patch is the only patch that has no reviewed-by tag.
I hope someone (e.g. Mike, Oscar, David or Michal) could review
this. Thanks a lot.

>
> Signed-off-by: Muchun Song 
> ---
>  Documentation/admin-guide/mm/hugetlbpage.rst |  8 +++
>  include/linux/mm.h   |  2 +
>  mm/hugetlb.c | 92 
> +---
>  mm/hugetlb_vmemmap.c | 32 ++
>  mm/hugetlb_vmemmap.h | 23 +++
>  mm/sparse-vmemmap.c  | 75 ++-
>  6 files changed, 197 insertions(+), 35 deletions(-)
>
> diff --git a/Documentation/admin-guide/mm/hugetlbpage.rst 
> b/Documentation/admin-guide/mm/hugetlbpage.rst
> index f7b1c7462991..6988895d09a8 100644
> --- a/Documentation/admin-guide/mm/hugetlbpage.rst
> +++ b/Documentation/admin-guide/mm/hugetlbpage.rst
> @@ -60,6 +60,10 @@ HugePages_Surp
>  the pool above the value in ``/proc/sys/vm/nr_hugepages``. The
>  maximum number of surplus huge pages is controlled by
>  ``/proc/sys/vm/nr_overcommit_hugepages``.
> +   Note: When the feature of freeing unused vmemmap pages associated
> +   with each hugetlb page is enabled, the number of surplus huge pages
> +   may be temporarily larger than the maximum number of surplus huge
> +   pages when the system is under memory pressure.
>  Hugepagesize
> is the default hugepage size (in Kb).
>  Hugetlb
> @@ -80,6 +84,10 @@ returned to the huge page pool when freed by a task.  A 
> user with root
>  privileges can dynamically allocate more or free some persistent huge pages
>  by increasing or decreasing the value of ``nr_hugepages``.
>
> +Note: When the feature of freeing unused vmemmap pages associated with each
> +hugetlb page is enabled, we can fail to free the huge pages triggered by
> +the user when ths system is under memory pressure.  Please try again later.
> +
>  Pages that are used as huge pages are reserved inside the kernel and cannot
>  be used for other purposes.  Huge pages cannot be swapped out under
>  memory pressure.
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 4ddfc31f21c6..77693c944a36 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -2973,6 +2973,8 @@ static inline void print_vma_addr(char *prefix, 
> unsigned long rip)
>
>  void vmemmap_remap_free(unsigned long start, unsigned long end,
> unsigned long reuse);
> +int vmemmap_remap_alloc(unsigned long start, unsigned long end,
> +   unsigned long reuse, gfp_t gfp_mask);
>
>  void *sparse_buffer_alloc(unsigned long size);
>  struct page * __populate_section_memmap(unsigned long pfn,
> 

RE: [PATCH 0/2] tracing: Detect unsafe dereferencing of pointers from trace events

2021-02-28 Thread Pawel Laszczak


+ Peter Chen - Maintainer of CDNS3 driver

>
>[ Resending with an address that should work for Felipe ]
>
>On Sat, 27 Feb 2021 14:18:02 -0500
>Steven Rostedt  wrote:
>
>> On Fri, 26 Feb 2021 14:21:00 -0800
>> Linus Torvalds  wrote:
>>
>> > On Fri, Feb 26, 2021 at 11:07 AM Steven Rostedt  
>> > wrote:
>> > >
>> > > The first patch scans the print fmts of the trace events looking for
>> > > dereferencing pointers from %p*, and making sure that they refer back
>> > > to the trace event itself.
>> > >
>> > > The second patch handles strings "%s" [..]
>> >
>> > Doing this at runtime really feels like the wrong thing to do.
>> >
>> > It won't even protect us from what happened - people like me and
>> > Andrew won't even run those tracepoints in the first place, so we
>> > won't notice.
>> >
>> > It really would be much better in every respect to have this done by
>> > checkpatch, I think.
>>
>> And after fixing the parsing to not trigger false positives, an
>> allyesconfig boot found this:
>>
>> event cdns3_gadget_giveback has unsafe dereference of argument 11
>> print_fmt: "%s: req: %p, req buff %p, length: %u/%u %s%s%s, status: %d, trb: 
>> [start:%d, end:%d: virt addr %pa], flags:%x SID: %u",
>__get_str(name), REC->req, REC->buf,
>>  REC->actual, REC->length, REC->zero ? "Z" : "z", REC->short_not_ok ? "S" : 
>> "s", REC->no_interrupt ? "I" : "i", REC->status, REC-
>>start_trb, REC->end_trb, REC->start_trb_addr, REC->flags, RE
>> C->stream_id
>>
>> (as the above is from a trace event class, it triggered for every event
>> in that class).
>>
>> As it looks like it uses %pa which IIUC from the printk code, it
>> dereferences the pointer to find it's virtual address. The event has
>> this as the field:
>>
>> __field(struct cdns3_trb *, start_trb_addr)
>>
>> Assigns it with:
>>
>> __entry->start_trb_addr = req->trb;
>>
>> And prints that with %pa, which will dereference pointer at the time of
>> reading, where the address in question may no longer be around. That
>> looks to me as a potential bug.
>>
>> [ Cc'd the people responsible for that code. ]
>>
>> -- Steve



[PATCH] selftests/sgx: fix EINIT failure dueto SGX_INVALID_SIGNATURE

2021-02-28 Thread Tianjia Zhang
q2 is not always 384-byte length. Sometimes it only has 383-byte.
In this case, the valid portion of q2 is reordered reversely for
little endian order, and the remaining portion is filled with zero.

Signed-off-by: Tianjia Zhang 
---
 tools/testing/selftests/sgx/sigstruct.c | 41 +
 1 file changed, 21 insertions(+), 20 deletions(-)

diff --git a/tools/testing/selftests/sgx/sigstruct.c 
b/tools/testing/selftests/sgx/sigstruct.c
index dee7a3d6c5a5..92bbc5a15c39 100644
--- a/tools/testing/selftests/sgx/sigstruct.c
+++ b/tools/testing/selftests/sgx/sigstruct.c
@@ -55,10 +55,27 @@ static bool alloc_q1q2_ctx(const uint8_t *s, const uint8_t 
*m,
return true;
 }
 
+static void reverse_bytes(void *data, int length)
+{
+   int i = 0;
+   int j = length - 1;
+   uint8_t temp;
+   uint8_t *ptr = data;
+
+   while (i < j) {
+   temp = ptr[i];
+   ptr[i] = ptr[j];
+   ptr[j] = temp;
+   i++;
+   j--;
+   }
+}
+
 static bool calc_q1q2(const uint8_t *s, const uint8_t *m, uint8_t *q1,
  uint8_t *q2)
 {
struct q1q2_ctx ctx;
+   int len;
 
if (!alloc_q1q2_ctx(s, m, )) {
fprintf(stderr, "Not enough memory for Q1Q2 calculation\n");
@@ -89,8 +106,10 @@ static bool calc_q1q2(const uint8_t *s, const uint8_t *m, 
uint8_t *q1,
goto out;
}
 
-   BN_bn2bin(ctx.q1, q1);
-   BN_bn2bin(ctx.q2, q2);
+   len = BN_bn2bin(ctx.q1, q1);
+   reverse_bytes(q1, len);
+   len = BN_bn2bin(ctx.q2, q2);
+   reverse_bytes(q2, len);
 
free_q1q2_ctx();
return true;
@@ -152,22 +171,6 @@ static RSA *gen_sign_key(void)
return key;
 }
 
-static void reverse_bytes(void *data, int length)
-{
-   int i = 0;
-   int j = length - 1;
-   uint8_t temp;
-   uint8_t *ptr = data;
-
-   while (i < j) {
-   temp = ptr[i];
-   ptr[i] = ptr[j];
-   ptr[j] = temp;
-   i++;
-   j--;
-   }
-}
-
 enum mrtags {
MRECREATE = 0x0045544145524345,
MREADD = 0x4145,
@@ -367,8 +370,6 @@ bool encl_measure(struct encl *encl)
/* BE -> LE */
reverse_bytes(sigstruct->signature, SGX_MODULUS_SIZE);
reverse_bytes(sigstruct->modulus, SGX_MODULUS_SIZE);
-   reverse_bytes(sigstruct->q1, SGX_MODULUS_SIZE);
-   reverse_bytes(sigstruct->q2, SGX_MODULUS_SIZE);
 
EVP_MD_CTX_destroy(ctx);
RSA_free(key);
-- 
2.19.1.3.ge56e4f7



[PATCH] arm64/mm: Drop redundant ARCH_WANT_HUGE_PMD_SHARE

2021-02-28 Thread Anshuman Khandual
There is already an ARCH_WANT_HUGE_PMD_SHARE which is being selected for
applicable configurations. Hence just drop the other redundant entry.

Cc: Catalin Marinas 
Cc: Will Deacon 
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual 
---
This applies on v5.12-rc1

 arch/arm64/Kconfig | 2 --
 1 file changed, 2 deletions(-)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index d4fe5118e9c8..9cd33c7be429 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -1056,8 +1056,6 @@ config HW_PERF_EVENTS
 config SYS_SUPPORTS_HUGETLBFS
def_bool y
 
-config ARCH_WANT_HUGE_PMD_SHARE
-
 config ARCH_HAS_CACHE_LINE_SIZE
def_bool y
 
-- 
2.20.1



[PATCH v2 3/3] f2fs: check if swapfile is section-alligned

2021-02-28 Thread Huang Jianan
If the swapfile isn't created by pin and fallocate, it can't be
guaranteed section-aligned, so it may be selected by f2fs gc. When
gc_pin_file_threshold is reached, the address of swapfile may change,
but won't be synchronized to swap_extent, so swap will write to wrong
address, which will cause data corruption.

Signed-off-by: Huang Jianan 
Signed-off-by: Guo Weichao 
---
 fs/f2fs/data.c | 109 +++--
 1 file changed, 88 insertions(+), 21 deletions(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 4dbc1cafc55d..d33085daa3dc 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -3781,11 +3781,64 @@ int f2fs_migrate_page(struct address_space *mapping,
 #endif
 
 #ifdef CONFIG_SWAP
+static int f2fs_is_file_aligned(struct inode *inode)
+{
+   struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
+   block_t main_blkaddr = SM_I(sbi)->main_blkaddr;
+   block_t cur_lblock;
+   block_t last_lblock;
+   block_t pblock;
+   unsigned long nr_pblocks;
+   unsigned int blocks_per_sec = BLKS_PER_SEC(sbi);
+   int ret = 0;
+
+   cur_lblock = 0;
+   last_lblock = bytes_to_blks(inode, i_size_read(inode));
+
+   while (cur_lblock < last_lblock) {
+   struct f2fs_map_blocks map;
+
+   memset(, 0, sizeof(map));
+   map.m_lblk = cur_lblock;
+   map.m_len = last_lblock - cur_lblock;
+   map.m_next_pgofs = NULL;
+   map.m_next_extent = NULL;
+   map.m_seg_type = NO_CHECK_TYPE;
+   map.m_may_create = false;
+
+   ret = f2fs_map_blocks(inode, , 0, F2FS_GET_BLOCK_FIEMAP);
+   if (ret)
+   goto out;
+
+   /* hole */
+   if (!(map.m_flags & F2FS_MAP_FLAGS)) {
+   f2fs_err(sbi, "Swapfile has holes\n");
+   ret = -ENOENT;
+   goto out;
+   }
+
+   pblock = map.m_pblk;
+   nr_pblocks = map.m_len;
+
+   if ((pblock - main_blkaddr) & (blocks_per_sec - 1) ||
+   nr_pblocks & (blocks_per_sec - 1)) {
+   f2fs_err(sbi, "Swapfile does not align to section");
+   ret = -EINVAL;
+   goto out;
+   }
+
+   cur_lblock += nr_pblocks;
+   }
+out:
+   return ret;
+}
+
 static int check_swap_activate_fast(struct swap_info_struct *sis,
struct file *swap_file, sector_t *span)
 {
struct address_space *mapping = swap_file->f_mapping;
struct inode *inode = mapping->host;
+   struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
sector_t cur_lblock;
sector_t last_lblock;
sector_t pblock;
@@ -3793,8 +3846,8 @@ static int check_swap_activate_fast(struct 
swap_info_struct *sis,
sector_t highest_pblock = 0;
int nr_extents = 0;
unsigned long nr_pblocks;
-   u64 len;
-   int ret;
+   unsigned int blocks_per_sec = BLKS_PER_SEC(sbi);
+   int ret = 0;
 
/*
 * Map all the blocks into the extent list.  This code doesn't try
@@ -3802,31 +3855,41 @@ static int check_swap_activate_fast(struct 
swap_info_struct *sis,
 */
cur_lblock = 0;
last_lblock = bytes_to_blks(inode, i_size_read(inode));
-   len = i_size_read(inode);
 
while (cur_lblock + 1 <= last_lblock && cur_lblock < sis->max) {
struct f2fs_map_blocks map;
-   pgoff_t next_pgofs;
 
cond_resched();
 
memset(, 0, sizeof(map));
map.m_lblk = cur_lblock;
-   map.m_len = bytes_to_blks(inode, len) - cur_lblock;
-   map.m_next_pgofs = _pgofs;
+   map.m_len = last_lblock - cur_lblock;
+   map.m_next_pgofs = NULL;
+   map.m_next_extent = NULL;
map.m_seg_type = NO_CHECK_TYPE;
+   map.m_may_create = false;
 
ret = f2fs_map_blocks(inode, , 0, F2FS_GET_BLOCK_FIEMAP);
if (ret)
-   goto err_out;
+   goto out;
 
/* hole */
-   if (!(map.m_flags & F2FS_MAP_FLAGS))
-   goto err_out;
+   if (!(map.m_flags & F2FS_MAP_FLAGS)) {
+   f2fs_err(sbi, "Swapfile has holes\n");
+   ret = -ENOENT;
+   goto out;
+   }
 
pblock = map.m_pblk;
nr_pblocks = map.m_len;
 
+   if ((pblock - SM_I(sbi)->main_blkaddr) & (blocks_per_sec - 1) ||
+   nr_pblocks & (blocks_per_sec - 1)) {
+   f2fs_err(sbi, "Swapfile does not align to section");
+   ret = -EINVAL;
+   goto out;
+   }
+
if (cur_lblock + nr_pblocks >= sis->max)
  

[PATCH V2] mm/memtest: Add ARCH_USE_MEMTEST

2021-02-28 Thread Anshuman Khandual
early_memtest() does not get called from all architectures. Hence enabling
CONFIG_MEMTEST and providing a valid memtest=[1..N] kernel command line
option might not trigger the memory pattern tests as would be expected in
normal circumstances. This situation is misleading.

The change here prevents the above mentioned problem after introducing a
new config option ARCH_USE_MEMTEST that should be subscribed on platforms
that call early_memtest(), in order to enable the config CONFIG_MEMTEST.
Conversely CONFIG_MEMTEST cannot be enabled on platforms where it would
not be tested anyway.

Cc: Russell King 
Cc: Catalin Marinas 
Cc: Will Deacon 
Cc: Thomas Bogendoerfer 
Cc: Michael Ellerman 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: Chris Zankel 
Cc: Max Filippov 
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-m...@vger.kernel.org
Cc: linuxppc-...@lists.ozlabs.org
Cc: linux-xte...@linux-xtensa.org
Cc: linux...@kvack.org
Cc: linux-kernel@vger.kernel.org
Reviewed-by: Max Filippov 
Signed-off-by: Anshuman Khandual 
---
This patch applies on v5.12-rc1 and has been tested on arm64 platform.
But it has been just build tested on all other platforms.

Changes in V2:

- Added ARCH_USE_MEMTEST in the sorted alphabetical order on platforms

Changes in V1:

https://patchwork.kernel.org/project/linux-mm/patch/1612498242-31579-1-git-send-email-anshuman.khand...@arm.com/

 arch/arm/Kconfig | 1 +
 arch/arm64/Kconfig   | 1 +
 arch/mips/Kconfig| 1 +
 arch/powerpc/Kconfig | 1 +
 arch/x86/Kconfig | 1 +
 arch/xtensa/Kconfig  | 1 +
 lib/Kconfig.debug| 9 -
 7 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 853aab5ab327..9ab047d4cd0a 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -33,6 +33,7 @@ config ARM
select ARCH_SUPPORTS_ATOMIC_RMW
select ARCH_USE_BUILTIN_BSWAP
select ARCH_USE_CMPXCHG_LOCKREF
+   select ARCH_USE_MEMTEST
select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU
select ARCH_WANT_IPC_PARSE_VERSION
select ARCH_WANT_LD_ORPHAN_WARN
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 1f212b47a48a..d4fe5118e9c8 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -67,6 +67,7 @@ config ARM64
select ARCH_KEEP_MEMBLOCK
select ARCH_USE_CMPXCHG_LOCKREF
select ARCH_USE_GNU_PROPERTY
+   select ARCH_USE_MEMTEST
select ARCH_USE_QUEUED_RWLOCKS
select ARCH_USE_QUEUED_SPINLOCKS
select ARCH_USE_SYM_ANNOTATIONS
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index d89efba3d8a4..93a4f502f962 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -14,6 +14,7 @@ config MIPS
select ARCH_SUPPORTS_UPROBES
select ARCH_USE_BUILTIN_BSWAP
select ARCH_USE_CMPXCHG_LOCKREF if 64BIT
+   select ARCH_USE_MEMTEST
select ARCH_USE_QUEUED_RWLOCKS
select ARCH_USE_QUEUED_SPINLOCKS
select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 386ae12d8523..3778ad17f56a 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -149,6 +149,7 @@ config PPC
select ARCH_SUPPORTS_DEBUG_PAGEALLOCif PPC32 || PPC_BOOK3S_64
select ARCH_USE_BUILTIN_BSWAP
select ARCH_USE_CMPXCHG_LOCKREF if PPC64
+   select ARCH_USE_MEMTEST
select ARCH_USE_QUEUED_RWLOCKS  if PPC_QUEUED_SPINLOCKS
select ARCH_USE_QUEUED_SPINLOCKSif PPC_QUEUED_SPINLOCKS
select ARCH_WANT_IPC_PARSE_VERSION
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 2792879d398e..2cb76fd5258e 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -100,6 +100,7 @@ config X86
select ARCH_SUPPORTS_LTO_CLANG  if X86_64
select ARCH_SUPPORTS_LTO_CLANG_THIN if X86_64
select ARCH_USE_BUILTIN_BSWAP
+   select ARCH_USE_MEMTEST
select ARCH_USE_QUEUED_RWLOCKS
select ARCH_USE_QUEUED_SPINLOCKS
select ARCH_USE_SYM_ANNOTATIONS
diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig
index a99dc39f6964..ca51896c53df 100644
--- a/arch/xtensa/Kconfig
+++ b/arch/xtensa/Kconfig
@@ -7,6 +7,7 @@ config XTENSA
select ARCH_HAS_SYNC_DMA_FOR_CPU if MMU
select ARCH_HAS_SYNC_DMA_FOR_DEVICE if MMU
select ARCH_HAS_DMA_SET_UNCACHED if MMU
+   select ARCH_USE_MEMTEST
select ARCH_USE_QUEUED_RWLOCKS
select ARCH_USE_QUEUED_SPINLOCKS
select ARCH_WANT_FRAME_POINTERS
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index a2d04c00cda2..2c296535a4b3 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -2521,11 +2521,18 @@ config TEST_FPU
 
 endif # RUNTIME_TESTING_MENU
 
+config ARCH_USE_MEMTEST
+   bool
+   help
+ An architecture should select this when it uses early_memtest()
+ during boot process.
+
 config MEMTEST
bool "Memtest"
+   depends on 

Re: [PATCH] cpufreq: qcom-hw: fix dereferencing freed memory 'data'

2021-02-28 Thread Viresh Kumar
On 28-02-21, 09:33, Shawn Guo wrote:
> Commit 67fc209b527d ("cpufreq: qcom-hw: drop devm_xxx() calls from
> init/exit hooks") introduces an issue of dereferencing freed memory
> 'data'.  Fix it.
> 
> Fixes: 67fc209b527d ("cpufreq: qcom-hw: drop devm_xxx() calls from init/exit 
> hooks")
> Reported-by: kernel test robot 
> Reported-by: Dan Carpenter 
> Signed-off-by: Shawn Guo 
> ---
> Viresh,
> 
> The issue was introduced by v2 of "cpufreq: qcom-hw: drop devm_xxx()
> calls from init/exit hooks", which misses the conversion of 'data->base'
> in error path.  Sorry!
> 
> Shawn
> 
>  drivers/cpufreq/qcom-cpufreq-hw.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/cpufreq/qcom-cpufreq-hw.c 
> b/drivers/cpufreq/qcom-cpufreq-hw.c
> index d3c23447b892..bee5d67a8227 100644
> --- a/drivers/cpufreq/qcom-cpufreq-hw.c
> +++ b/drivers/cpufreq/qcom-cpufreq-hw.c
> @@ -374,7 +374,7 @@ static int qcom_cpufreq_hw_cpu_init(struct cpufreq_policy 
> *policy)
>  error:
>   kfree(data);
>  unmap_base:
> - iounmap(data->base);
> + iounmap(base);
>  release_region:
>   release_mem_region(res->start, resource_size(res));
>   return ret;

Applied. Thanks.
-- 
viresh


Re: drivers/opp/of.c:959:12: warning: stack frame size of 2064 bytes in function '_of_add_table_indexed'

2021-02-28 Thread Viresh Kumar
On 28-02-21, 02:11, kernel test robot wrote:
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
> master
> head:   3fb6d0e00efc958d01c2f109c8453033a2d96796
> commit: 406e47652161d4f0d9bc4cd6237b36c51497ec75 opp: Create 
> _of_add_table_indexed() to reduce code duplication
> date:   4 weeks ago
> config: powerpc64-randconfig-r002-20210227 (attached as .config)
> compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 
> 83bc7815c4235786111aa2abf7193292e4a602f5)
> 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
> # install powerpc64 cross compiling tool for clang build
> # apt-get install binutils-powerpc64-linux-gnu
> # 
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=406e47652161d4f0d9bc4cd6237b36c51497ec75
> git remote add linus 
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
> git fetch --no-tags linus master
> git checkout 406e47652161d4f0d9bc4cd6237b36c51497ec75
> # save the attached .config to linux build tree
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross 
> ARCH=powerpc64 
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot 
> 
> All warnings (new ones prefixed by >>):
> 
> >> drivers/opp/of.c:959:12: warning: stack frame size of 2064 bytes in 
> >> function '_of_add_table_indexed' [-Wframe-larger-than=]
>static int _of_add_table_indexed(struct device *dev, int index)
>   ^
>1 warning generated.
> 
> 
> vim +/_of_add_table_indexed +959 drivers/opp/of.c
> 
>958
>  > 959static int _of_add_table_indexed(struct device *dev, int index)
>960{
>961struct opp_table *opp_table;
>962int ret, count;

Is this a false positive ?

-- 
viresh


RE: [PATCH 04/13] PCI: hyperv: Drop msi_controller structure

2021-02-28 Thread Michael Kelley
From: Marc Zyngier  Sent: Thursday, February 25, 2021 7:10 AM
> 
> The Hyper-V PCI driver still makes use of a msi_controller structure,
> but it looks more like a distant leftover than anything actually
> useful, since it is initialised to 0 and never used for anything.
> 
> Just remove it.
> 
> Signed-off-by: Marc Zyngier 
> ---
>  drivers/pci/controller/pci-hyperv.c | 4 
>  1 file changed, 4 deletions(-)
> 
> diff --git a/drivers/pci/controller/pci-hyperv.c 
> b/drivers/pci/controller/pci-hyperv.c
> index 6db8d96a78eb..93dc0fd004a3 100644
> --- a/drivers/pci/controller/pci-hyperv.c
> +++ b/drivers/pci/controller/pci-hyperv.c
> @@ -473,7 +473,6 @@ struct hv_pcibus_device {
>   struct list_head dr_list;
> 
>   struct msi_domain_info msi_info;
> - struct msi_controller msi_chip;
>   struct irq_domain *irq_domain;
> 
>   spinlock_t retarget_msi_interrupt_lock;
> @@ -1866,9 +1865,6 @@ static int create_root_hv_pci_bus(struct 
> hv_pcibus_device *hbus)
>   if (!hbus->pci_bus)
>   return -ENODEV;
> 
> - hbus->pci_bus->msi = >msi_chip;
> - hbus->pci_bus->msi->dev = >hdev->device;
> -
>   pci_lock_rescan_remove();
>   pci_scan_child_bus(hbus->pci_bus);
>   hv_pci_assign_numa_node(hbus);
> --
> 2.29.2

Reviewed-by: Michael Kelley 

I also tested in an Azure VM on Hyper-V, with a Mellanox ConnectX-4
virtual function as the PCI device.  Started with a 5.11 kernel and
applied all 13 patches in the series.  The VM booted up correctly with
nothing anomalous in the 'dmesg' output. The Mellanox VF was
detected and configured properly.  'ethtool -S' output showed that
the Mellanox VF was handling network traffic as expected.  I also
hot-removed the Mellanox VF, and then hot-added it back again.
All worked as expected.  So,

Tested-by: Michael Kelley 


Re: [PATCH 3/9] arm64: dts: qcom: sc7280: Add device tree node for LLCC

2021-02-28 Thread Stephen Boyd
Quoting Sai Prakash Ranjan (2021-02-27 05:58:25)
> On 2021-02-27 00:15, Stephen Boyd wrote:
> > Quoting Sai Prakash Ranjan (2021-02-26 00:04:27)
> >> On 2021-02-26 01:07, Stephen Boyd wrote:
> >> > Quoting Sai Prakash Ranjan (2021-02-25 01:30:19)
> >> >> Add a DT node for Last level cache (aka. system cache)
> >> >> controller which provides control over the last level
> >> >> cache present on SC7280 SoC.
> >> >>
> >> >> Signed-off-by: Sai Prakash Ranjan 
> >> >> ---
> >> >
> >> > Reviewed-by: Stephen Boyd 
> >> >
> >> > Should add system-cache-controller to the devicetree spec. Or just use
> >> > cache-controller for the node name.
> >> 
> >> This was as per discussion in [1][2] where dt-schema throws an error
> >> since it expects cache-level to be associated with cache-controller.
> >> 
> > 
> > Ah right. Can you add system-cache-controller to the dt spec?
> 
> Sure, I'll add it. Hopefully that won't have to block this change?
> Because I might need some time to get permissions to add it there.
> 

Doesn't block it for me.


Re: possible deadlock in io_poll_double_wake (2)

2021-02-28 Thread syzbot
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an 
issue:
possible deadlock in io_poll_double_wake


WARNING: possible recursive locking detected
5.11.0-syzkaller #0 Not tainted

syz-executor.0/10241 is trying to acquire lock:
888012e09130 (>sleep){..-.}-{2:2}, at: spin_lock 
include/linux/spinlock.h:354 [inline]
888012e09130 (>sleep){..-.}-{2:2}, at: 
io_poll_double_wake+0x25f/0x6a0 fs/io_uring.c:4921

but task is already holding lock:
888013b00130 (>sleep){..-.}-{2:2}, at: 
__wake_up_common_lock+0xb4/0x130 kernel/sched/wait.c:137

other info that might help us debug this:
 Possible unsafe locking scenario:

   CPU0
   
  lock(>sleep);
  lock(>sleep);

 *** DEADLOCK ***

 May be due to missing lock nesting notation

4 locks held by syz-executor.0/10241:
 #0: 88801b1ce128 (>uring_lock){+.+.}-{3:3}, at: 
__do_sys_io_uring_enter+0x1155/0x22b0 fs/io_uring.c:9139
 #1: 8b574460 (rcu_read_lock){}-{1:2}, at: file_ctx 
security/apparmor/include/file.h:33 [inline]
 #1: 8b574460 (rcu_read_lock){}-{1:2}, at: 
aa_file_perm+0x119/0x1100 security/apparmor/file.c:607
 #2: 888020842108 (>lock){..-.}-{2:2}, at: 
_snd_pcm_stream_lock_irqsave+0x9f/0xd0 sound/core/pcm_native.c:170
 #3: 888013b00130 (>sleep){..-.}-{2:2}, at: 
__wake_up_common_lock+0xb4/0x130 kernel/sched/wait.c:137

stack backtrace:
CPU: 1 PID: 10241 Comm: syz-executor.0 Not tainted 5.11.0-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 
01/01/2011
Call Trace:
 
 __dump_stack lib/dump_stack.c:79 [inline]
 dump_stack+0xfa/0x151 lib/dump_stack.c:120
 print_deadlock_bug kernel/locking/lockdep.c:2829 [inline]
 check_deadlock kernel/locking/lockdep.c:2872 [inline]
 validate_chain kernel/locking/lockdep.c:3661 [inline]
 __lock_acquire.cold+0x14c/0x3b4 kernel/locking/lockdep.c:4900
 lock_acquire kernel/locking/lockdep.c:5510 [inline]
 lock_acquire+0x1ab/0x730 kernel/locking/lockdep.c:5475
 __raw_spin_lock include/linux/spinlock_api_smp.h:142 [inline]
 _raw_spin_lock+0x2a/0x40 kernel/locking/spinlock.c:151
 spin_lock include/linux/spinlock.h:354 [inline]
 io_poll_double_wake+0x25f/0x6a0 fs/io_uring.c:4921
 __wake_up_common+0x147/0x650 kernel/sched/wait.c:108
 __wake_up_common_lock+0xd0/0x130 kernel/sched/wait.c:138
 snd_pcm_update_state+0x46a/0x540 sound/core/pcm_lib.c:203
 snd_pcm_update_hw_ptr0+0xa75/0x1a50 sound/core/pcm_lib.c:464
 snd_pcm_period_elapsed+0x160/0x250 sound/core/pcm_lib.c:1805
 dummy_hrtimer_callback+0x94/0x1b0 sound/drivers/dummy.c:378
 __run_hrtimer kernel/time/hrtimer.c:1519 [inline]
 __hrtimer_run_queues+0x609/0xe40 kernel/time/hrtimer.c:1583
 hrtimer_run_softirq+0x17b/0x360 kernel/time/hrtimer.c:1600
 __do_softirq+0x29b/0x9f6 kernel/softirq.c:343
 asm_call_irq_on_stack+0xf/0x20
 
 __run_on_irqstack arch/x86/include/asm/irq_stack.h:26 [inline]
 run_on_irqstack_cond arch/x86/include/asm/irq_stack.h:77 [inline]
 do_softirq_own_stack+0xaa/0xd0 arch/x86/kernel/irq_64.c:77
 invoke_softirq kernel/softirq.c:226 [inline]
 __irq_exit_rcu kernel/softirq.c:420 [inline]
 irq_exit_rcu+0x134/0x200 kernel/softirq.c:432
 sysvec_apic_timer_interrupt+0x4d/0x100 arch/x86/kernel/apic/apic.c:1100
 asm_sysvec_apic_timer_interrupt+0x12/0x20 arch/x86/include/asm/idtentry.h:635
RIP: 0010:lock_acquire+0x1e4/0x730 kernel/locking/lockdep.c:5478
Code: 07 b8 ff ff ff ff 65 0f c1 05 e8 b3 a8 7e 83 f8 01 0f 85 d9 03 00 00 48 
83 7c 24 08 00 74 01 fb 48 b8 00 00 00 00 00 fc ff df <48> 01 c3 48 c7 03 00 00 
00 00 48 c7 43 08 00 00 00 00 48 8b 84 24
RSP: 0018:c9000b0e7468 EFLAGS: 0206
RAX: dc00 RBX: 19200161ce8f RCX: 013c4b5b
RDX: 1110030b54a9 RSI:  RDI: 
RBP:  R08:  R09: 8f0a77a7
R10: fbfff1e14ef4 R11:  R12: 0002
R13: 8b574460 R14:  R15: 
 rcu_lock_acquire include/linux/rcupdate.h:267 [inline]
 rcu_read_lock include/linux/rcupdate.h:656 [inline]
 aa_file_perm+0x14d/0x1100 security/apparmor/file.c:609
 common_file_perm security/apparmor/lsm.c:466 [inline]
 apparmor_file_permission+0x163/0x4e0 security/apparmor/lsm.c:480
 security_file_permission+0x56/0x560 security/security.c:1456
 rw_verify_area+0x115/0x350 fs/read_write.c:400
 io_read+0x267/0xaf0 fs/io_uring.c:3235
 io_issue_sqe+0x2e1/0x59d0 fs/io_uring.c:5937
 __io_queue_sqe+0x18c/0xc40 fs/io_uring.c:6204
 io_queue_sqe+0x60d/0xf60 fs/io_uring.c:6257
 io_submit_sqe fs/io_uring.c:6421 [inline]
 io_submit_sqes+0x519a/0x6320 fs/io_uring.c:6535
 __do_sys_io_uring_enter+0x1161/0x22b0 fs/io_uring.c:9140
 do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xae
RIP: 0033:0x465ef9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 
89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 

[PATCH] can: c_can: move runtime PM enable/disable to c_can_platform

2021-02-28 Thread Tong Zhang
Currently doing modprobe c_can_pci will make kernel complain
"Unbalanced pm_runtime_enable!", this is caused by pm_runtime_enable()
called before pm is initialized in register_candev() and doing so will
also cause it to enable twice.
This fix is similar to 227619c3ff7c, move those pm_enable/disable code to
c_can_platform.

Signed-off-by: Tong Zhang 
---
 drivers/net/can/c_can/c_can.c  | 26 ++
 drivers/net/can/c_can/c_can_platform.c |  6 +-
 2 files changed, 7 insertions(+), 25 deletions(-)

diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
index ef474bae47a1..04f783b3d9d3 100644
--- a/drivers/net/can/c_can/c_can.c
+++ b/drivers/net/can/c_can/c_can.c
@@ -212,18 +212,6 @@ static const struct can_bittiming_const 
c_can_bittiming_const = {
.brp_inc = 1,
 };
 
-static inline void c_can_pm_runtime_enable(const struct c_can_priv *priv)
-{
-   if (priv->device)
-   pm_runtime_enable(priv->device);
-}
-
-static inline void c_can_pm_runtime_disable(const struct c_can_priv *priv)
-{
-   if (priv->device)
-   pm_runtime_disable(priv->device);
-}
-
 static inline void c_can_pm_runtime_get_sync(const struct c_can_priv *priv)
 {
if (priv->device)
@@ -1335,7 +1323,6 @@ static const struct net_device_ops c_can_netdev_ops = {
 
 int register_c_can_dev(struct net_device *dev)
 {
-   struct c_can_priv *priv = netdev_priv(dev);
int err;
 
/* Deactivate pins to prevent DRA7 DCAN IP from being
@@ -1345,28 +1332,19 @@ int register_c_can_dev(struct net_device *dev)
 */
pinctrl_pm_select_sleep_state(dev->dev.parent);
 
-   c_can_pm_runtime_enable(priv);
-
dev->flags |= IFF_ECHO; /* we support local echo */
dev->netdev_ops = _can_netdev_ops;
 
err = register_candev(dev);
-   if (err)
-   c_can_pm_runtime_disable(priv);
-   else
-   devm_can_led_init(dev);
-
+   if (!err)
+ devm_can_led_init(dev);
return err;
 }
 EXPORT_SYMBOL_GPL(register_c_can_dev);
 
 void unregister_c_can_dev(struct net_device *dev)
 {
-   struct c_can_priv *priv = netdev_priv(dev);
-
unregister_candev(dev);
-
-   c_can_pm_runtime_disable(priv);
 }
 EXPORT_SYMBOL_GPL(unregister_c_can_dev);
 
diff --git a/drivers/net/can/c_can/c_can_platform.c 
b/drivers/net/can/c_can/c_can_platform.c
index 05f425ceb53a..47b251b1607c 100644
--- a/drivers/net/can/c_can/c_can_platform.c
+++ b/drivers/net/can/c_can/c_can_platform.c
@@ -29,6 +29,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -386,6 +387,7 @@ static int c_can_plat_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, dev);
SET_NETDEV_DEV(dev, >dev);
 
+   pm_runtime_enable(priv->device);
ret = register_c_can_dev(dev);
if (ret) {
dev_err(>dev, "registering %s failed (err=%d)\n",
@@ -398,6 +400,7 @@ static int c_can_plat_probe(struct platform_device *pdev)
return 0;
 
 exit_free_device:
+   pm_runtime_disable(priv->device);
free_c_can_dev(dev);
 exit:
dev_err(>dev, "probe failed\n");
@@ -408,9 +411,10 @@ static int c_can_plat_probe(struct platform_device *pdev)
 static int c_can_plat_remove(struct platform_device *pdev)
 {
struct net_device *dev = platform_get_drvdata(pdev);
+   struct c_can_priv *priv = netdev_priv(dev);
 
unregister_c_can_dev(dev);
-
+   pm_runtime_disable(priv->device);
free_c_can_dev(dev);
 
return 0;
-- 
2.25.1



[PATCH] video: fbdev: fix use of 'dma_map_single'

2021-02-28 Thread Hui Tang
DMA_TO_DEVICE synchronisation must be done after the last modification
of the memory region by the software and before it is handed off to
the device.

Signed-off-by: Hui Tang 
---
 drivers/video/fbdev/grvga.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/grvga.c b/drivers/video/fbdev/grvga.c
index 24818b2..25ae9ef 100644
--- a/drivers/video/fbdev/grvga.c
+++ b/drivers/video/fbdev/grvga.c
@@ -435,6 +435,8 @@ static int grvga_probe(struct platform_device *dev)
retval = -ENOMEM;
goto dealloc_cmap;
}
+
+   memset((unsigned long *) virtual_start, 0, grvga_mem_size);
} else {/* Allocate frambuffer memory */
 
unsigned long page;
@@ -449,6 +451,7 @@ static int grvga_probe(struct platform_device *dev)
goto dealloc_cmap;
}
 
+   memset((unsigned long *) virtual_start, 0, grvga_mem_size);
physical_start = dma_map_single(>dev, (void 
*)virtual_start, grvga_mem_size, DMA_TO_DEVICE);
 
/* Set page reserved so that mmap will work. This is necessary
@@ -463,8 +466,6 @@ static int grvga_probe(struct platform_device *dev)
par->fb_alloced = 1;
}
 
-   memset((unsigned long *) virtual_start, 0, grvga_mem_size);
-
info->screen_base = (char __iomem *) virtual_start;
info->fix.smem_start = physical_start;
info->fix.smem_len   = grvga_mem_size;
-- 
2.8.1



[PATCH] xfrm: Use actual socket sk instead of skb socket for xfrm_output_resume

2021-02-28 Thread Evan Nimmo
A situation can occur where the interface bound to the sk is different
to the interface bound to the sk attached to the skb. The interface
bound to the sk is the correct one however this information is lost inside
xfrm_output2 and instead the sk on the skb is used in xfrm_output_resume
instead. This assumes that the sk bound interface and the bound interface
attached to the sk within the skb are the same which can lead to lookup
failures inside ip_route_me_harder resulting in the packet being dropped.

We have an l2tp v3 tunnel with ipsec protection. The tunnel is in the
global VRF however we have an encapsulated dot1q tunnel interface that
is within a different VRF. We also have a mangle rule that marks the 
packets causing them to be processed inside ip_route_me_harder.

Prior to commit 31c70d5956fc ("l2tp: keep original skb ownership") this
worked fine as the sk attached to the skb was changed from the dot1q
encapsulated interface to the sk for the tunnel which meant the interface
bound to the sk and the interface bound to the skb were identical.
Commit 46d6c5ae953c ("netfilter: use actual socket sk rather than skb sk
when routing harder") fixed some of these issues however a similar
problem existed in the xfrm code.

Signed-off-by: Evan Nimmo 
---
 include/net/xfrm.h |  2 +-
 net/ipv4/ah4.c |  2 +-
 net/ipv4/esp4.c|  2 +-
 net/ipv6/ah6.c |  2 +-
 net/ipv6/esp6.c|  2 +-
 net/xfrm/xfrm_output.c | 10 +-
 6 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index b2a06f10b62c..bfbc7810df94 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -1557,7 +1557,7 @@ int xfrm_trans_queue_net(struct net *net, struct sk_buff 
*skb,
 int xfrm_trans_queue(struct sk_buff *skb,
 int (*finish)(struct net *, struct sock *,
   struct sk_buff *));
-int xfrm_output_resume(struct sk_buff *skb, int err);
+int xfrm_output_resume(struct sock *sk, struct sk_buff *skb, int err);
 int xfrm_output(struct sock *sk, struct sk_buff *skb);
 
 #if IS_ENABLED(CONFIG_NET_PKTGEN)
diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
index d99e1be94019..36ed85bf2ad5 100644
--- a/net/ipv4/ah4.c
+++ b/net/ipv4/ah4.c
@@ -141,7 +141,7 @@ static void ah_output_done(struct crypto_async_request 
*base, int err)
}
 
kfree(AH_SKB_CB(skb)->tmp);
-   xfrm_output_resume(skb, err);
+   xfrm_output_resume(skb->sk, skb, err);
 }
 
 static int ah_output(struct xfrm_state *x, struct sk_buff *skb)
diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
index a3271ec3e162..4b834bbf95e0 100644
--- a/net/ipv4/esp4.c
+++ b/net/ipv4/esp4.c
@@ -279,7 +279,7 @@ static void esp_output_done(struct crypto_async_request 
*base, int err)
x->encap && x->encap->encap_type == TCP_ENCAP_ESPINTCP)
esp_output_tail_tcp(x, skb);
else
-   xfrm_output_resume(skb, err);
+   xfrm_output_resume(skb->sk, skb, err);
}
 }
 
diff --git a/net/ipv6/ah6.c b/net/ipv6/ah6.c
index 440080da805b..080ee7f44c64 100644
--- a/net/ipv6/ah6.c
+++ b/net/ipv6/ah6.c
@@ -316,7 +316,7 @@ static void ah6_output_done(struct crypto_async_request 
*base, int err)
}
 
kfree(AH_SKB_CB(skb)->tmp);
-   xfrm_output_resume(skb, err);
+   xfrm_output_resume(skb->sk, skb, err);
 }
 
 static int ah6_output(struct xfrm_state *x, struct sk_buff *skb)
diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
index 153ad103ba74..727d791ed5e6 100644
--- a/net/ipv6/esp6.c
+++ b/net/ipv6/esp6.c
@@ -314,7 +314,7 @@ static void esp_output_done(struct crypto_async_request 
*base, int err)
x->encap && x->encap->encap_type == TCP_ENCAP_ESPINTCP)
esp_output_tail_tcp(x, skb);
else
-   xfrm_output_resume(skb, err);
+   xfrm_output_resume(skb->sk, skb, err);
}
 }
 
diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c
index a7ab19353313..b81ca117dac7 100644
--- a/net/xfrm/xfrm_output.c
+++ b/net/xfrm/xfrm_output.c
@@ -503,22 +503,22 @@ static int xfrm_output_one(struct sk_buff *skb, int err)
return err;
 }
 
-int xfrm_output_resume(struct sk_buff *skb, int err)
+int xfrm_output_resume(struct sock *sk, struct sk_buff *skb, int err)
 {
struct net *net = xs_net(skb_dst(skb)->xfrm);
 
while (likely((err = xfrm_output_one(skb, err)) == 0)) {
nf_reset_ct(skb);
 
-   err = skb_dst(skb)->ops->local_out(net, skb->sk, skb);
+   err = skb_dst(skb)->ops->local_out(net, sk, skb);
if (unlikely(err != 1))
goto out;
 
if (!skb_dst(skb)->xfrm)
-   return dst_output(net, skb->sk, skb);
+   return dst_output(net, sk, skb);
 
err = nf_hook(skb_dst(skb)->ops->family,
-

[PATCH v2 2/2] hwmon: (pmbus): Add driver for Infineon IR36021

2021-02-28 Thread Chris Packham
The IR36021 is a dual‐loop digital multi‐phase buck controller.

Signed-off-by: Chris Packham 
---
Changes in v2:
- update against latest kernel for pmbus API changes
- avoid double negation

 Documentation/hwmon/index.rst   |  1 +
 Documentation/hwmon/ir36021.rst | 62 ++
 drivers/hwmon/pmbus/Kconfig |  9 
 drivers/hwmon/pmbus/Makefile|  1 +
 drivers/hwmon/pmbus/ir36021.c   | 79 +
 5 files changed, 152 insertions(+)
 create mode 100644 Documentation/hwmon/ir36021.rst
 create mode 100644 drivers/hwmon/pmbus/ir36021.c

diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
index 8d5a2df1ecb6..b34894403c2b 100644
--- a/Documentation/hwmon/index.rst
+++ b/Documentation/hwmon/index.rst
@@ -77,6 +77,7 @@ Hardware Monitoring Kernel Drivers
intel-m10-bmc-hwmon
ir35221
ir38064
+   ir36021
isl68137
it87
jc42
diff --git a/Documentation/hwmon/ir36021.rst b/Documentation/hwmon/ir36021.rst
new file mode 100644
index ..36ef8d518b81
--- /dev/null
+++ b/Documentation/hwmon/ir36021.rst
@@ -0,0 +1,62 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Kernel driver ir36021
+=
+
+Supported chips:
+
+  * Infineon IR36021
+
+Prefix: ir36021
+Addresses scanned: -
+
+Datasheet: Publicly available at the Infineon website
+  
https://www.infineon.com/dgdl/ir36021.pdf?fileId=5546d462533600a4015355d0aa2d1775
+
+Authors:
+  - Chris Packham 
+
+Description
+---
+
+The IR36021 is a dual‐loop digital multi‐phase buck controller designed for
+point of load applications.
+
+Usage Notes
+---
+
+This driver does not probe for PMBus devices. You will have to instantiate
+devices explicitly.
+
+Sysfs attributes
+
+
+=== ===
+curr1_label "iin"
+curr1_input Measured input current
+curr1_alarm Input fault alarm
+
+curr2_label "iout1"
+curr2_input Measured output current
+curr2_alarm Output over-current alarm
+
+in1_label   "vin"
+in1_input   Measured input voltage
+in1_alarm   Input under-voltage alarm
+
+in2_label   "vout1"
+in2_input   Measured output voltage
+in2_alarm   Output over-voltage alarm
+
+power1_label"pin"
+power1_inputMeasured input power
+power1_alarmInput under-voltage alarm
+
+power2_label"pout1"
+power2_inputMeasured output power
+
+temp1_input Measured temperature
+temp1_alarm Temperature alarm
+
+temp2_input Measured other loop temperature
+temp2_alarm Temperature alarm
diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
index 32d2fc850621..ee8c27b3b83d 100644
--- a/drivers/hwmon/pmbus/Kconfig
+++ b/drivers/hwmon/pmbus/Kconfig
@@ -84,6 +84,15 @@ config SENSORS_IR35221
  This driver can also be built as a module. If so, the module will
  be called ir35221.
 
+config SENSORS_IR36021
+   tristate "Infineon IR36021"
+   help
+ If you say yes here you get hardware monitoring support for Infineon
+ IR36021.
+
+ This driver can also be built as a module. If so, the module will
+ be called ir36021.
+
 config SENSORS_IR38064
tristate "Infineon IR38064"
help
diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile
index 6a4ba0fdc1db..685a6bc2b15f 100644
--- a/drivers/hwmon/pmbus/Makefile
+++ b/drivers/hwmon/pmbus/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_SENSORS_BEL_PFE) += bel-pfe.o
 obj-$(CONFIG_SENSORS_IBM_CFFPS)+= ibm-cffps.o
 obj-$(CONFIG_SENSORS_INSPUR_IPSPS) += inspur-ipsps.o
 obj-$(CONFIG_SENSORS_IR35221)  += ir35221.o
+obj-$(CONFIG_SENSORS_IR36021)  += ir36021.o
 obj-$(CONFIG_SENSORS_IR38064)  += ir38064.o
 obj-$(CONFIG_SENSORS_IRPS5401) += irps5401.o
 obj-$(CONFIG_SENSORS_ISL68137) += isl68137.o
diff --git a/drivers/hwmon/pmbus/ir36021.c b/drivers/hwmon/pmbus/ir36021.c
new file mode 100644
index ..4767e39cc965
--- /dev/null
+++ b/drivers/hwmon/pmbus/ir36021.c
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Hardware monitoring driver for Infineon IR36021
+ *
+ * Copyright (c) 2021 Allied Telesis
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "pmbus.h"
+
+static struct pmbus_driver_info ir36021_info = {
+   .pages = 1,
+   .format[PSC_VOLTAGE_IN] = linear,
+   .format[PSC_VOLTAGE_OUT] = linear,
+   .format[PSC_CURRENT_IN] = linear,
+   .format[PSC_CURRENT_OUT] = linear,
+   .format[PSC_POWER] = linear,
+   .format[PSC_TEMPERATURE] = linear,
+   .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT
+   | PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT
+   | PMBUS_HAVE_PIN | PMBUS_HAVE_POUT
+   | PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2
+   | 

  1   2   3   4   >