[PATCH v2 2/2] f2fs: compress: delay temp page allocation

2020-07-24 Thread Chao Yu
Currently, we allocate temp pages which is used to pad hole in
cluster during read IO submission, it may take long time before
releasing them in f2fs_decompress_pages(), since they are only
used as temp output buffer in decompression context, so let's
just do the allocation in that context to reduce time of memory
pool resource occupation.

Signed-off-by: Chao Yu 
---
v2:
- fix to assign return value in error path
 fs/f2fs/compress.c | 37 +
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
index a20c9f3272af..6e7db450006c 100644
--- a/fs/f2fs/compress.c
+++ b/fs/f2fs/compress.c
@@ -670,6 +670,7 @@ void f2fs_decompress_pages(struct bio *bio, struct page 
*page, bool verity)
const struct f2fs_compress_ops *cops =
f2fs_cops[fi->i_compress_algorithm];
int ret;
+   int i;
 
dec_page_count(sbi, F2FS_RD_DATA);
 
@@ -688,6 +689,26 @@ void f2fs_decompress_pages(struct bio *bio, struct page 
*page, bool verity)
goto out_free_dic;
}
 
+   dic->tpages = f2fs_kzalloc(sbi, sizeof(struct page *) *
+   dic->cluster_size, GFP_NOFS);
+   if (!dic->tpages) {
+   ret = -ENOMEM;
+   goto out_free_dic;
+   }
+
+   for (i = 0; i < dic->cluster_size; i++) {
+   if (dic->rpages[i]) {
+   dic->tpages[i] = dic->rpages[i];
+   continue;
+   }
+
+   dic->tpages[i] = f2fs_compress_alloc_page();
+   if (!dic->tpages[i]) {
+   ret = -ENOMEM;
+   goto out_free_dic;
+   }
+   }
+
if (cops->init_decompress_ctx) {
ret = cops->init_decompress_ctx(dic);
if (ret)
@@ -1449,22 +1470,6 @@ struct decompress_io_ctx *f2fs_alloc_dic(struct 
compress_ctx *cc)
dic->cpages[i] = page;
}
 
-   dic->tpages = f2fs_kzalloc(sbi, sizeof(struct page *) *
-   dic->cluster_size, GFP_NOFS);
-   if (!dic->tpages)
-   goto out_free;
-
-   for (i = 0; i < dic->cluster_size; i++) {
-   if (cc->rpages[i]) {
-   dic->tpages[i] = cc->rpages[i];
-   continue;
-   }
-
-   dic->tpages[i] = f2fs_compress_alloc_page();
-   if (!dic->tpages[i])
-   goto out_free;
-   }
-
return dic;
 
 out_free:
-- 
2.26.2



Re: [PATCH net-next v3 1/2] hinic: add support to handle hw abnormal event

2020-07-24 Thread luobin (L)
On 2020/7/24 17:57, Edward Cree wrote:
> On 23/07/2020 20:08, David Miller wrote:
>> From: Luo bin 
>> Date: Thu, 23 Jul 2020 22:40:37 +0800
>>
>>> +static int hinic_fw_reporter_dump(struct devlink_health_reporter *reporter,
>>> + struct devlink_fmsg *fmsg, void *priv_ctx,
>>> + struct netlink_ext_ack *extack)
>>> +{
>>> +   struct hinic_mgmt_watchdog_info *watchdog_info;
>>> +   int err;
>>> +
>>> +   if (priv_ctx) {
>>> +   watchdog_info = priv_ctx;
>>> +   err = mgmt_watchdog_report_show(fmsg, watchdog_info);
>>> +   if (err)
>>> +   return err;
>>> +   }
>>> +
>>> +   return 0;
>>> +}
>> This 'watchdog_info' variable is completely unnecessary, just pass
>> 'priv_ctx' as-is into mgmt_watchdog_report_show().
> Looks like the 'err' variable is unnecessary too...
> 
> -ed
> .
> 
Will fix. Thanks for your review.


Re: [PATCH net-next v4 1/2] hinic: add support to handle hw abnormal event

2020-07-24 Thread luobin (L)
On 2020/7/25 8:04, David Miller wrote:
> From: Luo bin 
> Date: Fri, 24 Jul 2020 17:17:31 +0800
> 
>> +static int hinic_fw_reporter_dump(struct devlink_health_reporter *reporter,
>> +  struct devlink_fmsg *fmsg, void *priv_ctx,
>> +  struct netlink_ext_ack *extack)
>> +{
>> +int err;
>> +
>> +if (priv_ctx) {
>> +err = mgmt_watchdog_report_show(fmsg, priv_ctx);
>> +if (err)
>> +return err;
>> +}
>> +
>> +return 0;
>> +}
> 
> As Edward Cree pointed out for v3 of this patch series, this 'err' is not
> necessary at all.
> .
> 
Will fix. Thanks.


[PATCH] lockdep: Introduce CONFIG_LOCKDEP_LARGE

2020-07-24 Thread Tetsuo Handa
Since syzkaller continues various test cases until the kernel crashes,
syzkaller tends to examine more locking dependencies than normal systems.
As a result, syzbot is reporting that the fuzz testing was terminated
due to hitting upper limits lockdep can track [1] [2] [3].

Like CONFIG_LOCKDEP_SMALL which halves the upper limits, let's introduce
CONFIG_LOCKDEP_LARGE which doubles the upper limits.

[1] 
https://syzkaller.appspot.com/bug?id=3d97ba93fb3566000c1c59691ea427370d33ea1b
[2] 
https://syzkaller.appspot.com/bug?id=381cb436fe60dc03d7fd2a092b46d7f09542a72a
[3] 
https://syzkaller.appspot.com/bug?id=a588183ac34c1437fc0785e8f220e88282e5a29f

Reported-by: syzbot 
Reported-by: syzbot 
Reported-by: syzbot 
Signed-off-by: Tetsuo Handa 
---
 kernel/locking/lockdep.c   | 4 
 kernel/locking/lockdep_internals.h | 5 +
 lib/Kconfig.debug  | 8 
 3 files changed, 17 insertions(+)

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 29a8de4..85ba7eb 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -1349,7 +1349,11 @@ static int add_lock_to_list(struct lock_class *this,
 /*
  * For good efficiency of modular, we use power of 2
  */
+#ifdef CONFIG_LOCKDEP_LARGE
+#define MAX_CIRCULAR_QUEUE_SIZE8192UL
+#else
 #define MAX_CIRCULAR_QUEUE_SIZE4096UL
+#endif
 #define CQ_MASK(MAX_CIRCULAR_QUEUE_SIZE-1)
 
 /*
diff --git a/kernel/locking/lockdep_internals.h 
b/kernel/locking/lockdep_internals.h
index baca699..00a3ec3 100644
--- a/kernel/locking/lockdep_internals.h
+++ b/kernel/locking/lockdep_internals.h
@@ -93,6 +93,11 @@ enum {
 #define MAX_LOCKDEP_CHAINS_BITS15
 #define MAX_STACK_TRACE_ENTRIES262144UL
 #define STACK_TRACE_HASH_SIZE  8192
+#elif defined(CONFIG_LOCKDEP_LARGE)
+#define MAX_LOCKDEP_ENTRIES65536UL
+#define MAX_LOCKDEP_CHAINS_BITS17
+#define MAX_STACK_TRACE_ENTRIES1048576UL
+#define STACK_TRACE_HASH_SIZE  32768
 #else
 #define MAX_LOCKDEP_ENTRIES32768UL
 
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 9ad9210..69ba624 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1266,6 +1266,14 @@ config LOCKDEP
 config LOCKDEP_SMALL
bool
 
+config LOCKDEP_LARGE
+   bool "Use larger buffer for tracking more locking dependencies"
+   depends on LOCKDEP && !LOCKDEP_SMALL
+   help
+ If you say Y here, the upper limits the lock dependency engine uses 
will
+ be doubled. Useful for fuzz testing which tends to test many 
complecated
+ dependencies than normal systems.
+
 config DEBUG_LOCKDEP
bool "Lock dependency engine debugging"
depends on DEBUG_KERNEL && LOCKDEP
-- 
1.8.3.1



[RFC PATCH bpf-next] bpf: POC on local_storage charge and uncharge map_ops

2020-07-24 Thread Martin KaFai Lau
It is a direct replacement of the patch 3 in discussion [1]
and to test out the idea on adding
map_local_storage_charge, map_local_storage_uncharge,
and map_owner_storage_ptr.

It is only compiler tested to demo the idea.

[1]: 
https://patchwork.ozlabs.org/project/netdev/patch/20200723115032.460770-4-kpsi...@chromium.org/

Signed-off-by: Martin KaFai Lau 
---
 include/linux/bpf.h|  10 ++
 include/net/bpf_sk_storage.h   |  51 +++
 include/uapi/linux/bpf.h   |   8 +-
 net/core/bpf_sk_storage.c  | 250 +
 tools/include/uapi/linux/bpf.h |   8 +-
 5 files changed, 236 insertions(+), 91 deletions(-)

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 72221aea1c60..d4eab7ccbb51 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -33,6 +33,9 @@ struct btf;
 struct btf_type;
 struct exception_table_entry;
 struct seq_operations;
+struct bpf_local_storage;
+struct bpf_local_storage_map;
+struct bpf_local_storage_elem;
 
 extern struct idr btf_idr;
 extern spinlock_t btf_idr_lock;
@@ -93,6 +96,13 @@ struct bpf_map_ops {
__poll_t (*map_poll)(struct bpf_map *map, struct file *filp,
 struct poll_table_struct *pts);
 
+   /* Functions called by bpf_local_storage maps */
+   int (*map_local_storage_charge)(struct bpf_local_storage_map *smap,
+   void *owner, u32 size);
+   void (*map_local_storage_uncharge)(struct bpf_local_storage_map *smap,
+  void *owner, u32 size);
+   struct bpf_local_storage __rcu ** (*map_owner_storage_ptr)(struct 
bpf_local_storage_map *smap,
+  void *owner);
/* BTF name and id of struct allocated by map_alloc */
const char * const map_btf_name;
int *map_btf_id;
diff --git a/include/net/bpf_sk_storage.h b/include/net/bpf_sk_storage.h
index 950c5aaba15e..05b777950eb3 100644
--- a/include/net/bpf_sk_storage.h
+++ b/include/net/bpf_sk_storage.h
@@ -3,8 +3,15 @@
 #ifndef _BPF_SK_STORAGE_H
 #define _BPF_SK_STORAGE_H
 
+#include 
+#include 
+#include 
 #include 
 #include 
+#include 
+#include 
+#include 
+#include 
 
 struct sock;
 
@@ -34,6 +41,50 @@ u16 bpf_local_storage_cache_idx_get(struct 
bpf_local_storage_cache *cache);
 void bpf_local_storage_cache_idx_free(struct bpf_local_storage_cache *cache,
  u16 idx);
 
+/* Helper functions for bpf_local_storage */
+int bpf_local_storage_map_alloc_check(union bpf_attr *attr);
+
+struct bpf_local_storage_map *bpf_local_storage_map_alloc(union bpf_attr 
*attr);
+
+struct bpf_local_storage_data *
+bpf_local_storage_lookup(struct bpf_local_storage *local_storage,
+struct bpf_local_storage_map *smap,
+bool cacheit_lockit);
+
+void bpf_local_storage_map_free(struct bpf_local_storage_map *smap);
+
+int bpf_local_storage_map_check_btf(const struct bpf_map *map,
+   const struct btf *btf,
+   const struct btf_type *key_type,
+   const struct btf_type *value_type);
+
+void bpf_selem_link_storage(struct bpf_local_storage *local_storage,
+   struct bpf_local_storage_elem *selem);
+
+bool bpf_selem_unlink_storage(struct bpf_local_storage *local_storage,
+ struct bpf_local_storage_elem *selem,
+ bool uncharge_omem);
+
+void bpf_selem_unlink(struct bpf_local_storage_elem *selem);
+
+void bpf_selem_link_map(struct bpf_local_storage_map *smap,
+   struct bpf_local_storage_elem *selem);
+
+void bpf_selem_unlink_map(struct bpf_local_storage_elem *selem);
+
+struct bpf_local_storage_elem *
+bpf_selem_alloc(struct bpf_local_storage_map *smap, void *owner, void *value,
+   bool charge_mem);
+
+int
+bpf_local_storage_alloc(void *owner,
+   struct bpf_local_storage_map *smap,
+   struct bpf_local_storage_elem *first_selem);
+
+struct bpf_local_storage_data *
+bpf_local_storage_update(void *owner, struct bpf_map *map, void *value,
+u64 map_flags);
+
 #ifdef CONFIG_BPF_SYSCALL
 int bpf_sk_storage_clone(const struct sock *sk, struct sock *newsk);
 struct bpf_sk_storage_diag *
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 54d0c886e3ba..b9d2e4792d08 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -3630,9 +3630,13 @@ enum {
BPF_F_SYSCTL_BASE_NAME  = (1ULL << 0),
 };
 
-/* BPF_FUNC_sk_storage_get flags */
+/* BPF_FUNC__storage_get flags */
 enum {
-   BPF_SK_STORAGE_GET_F_CREATE = (1ULL << 0),
+   BPF_LOCAL_STORAGE_GET_F_CREATE  = (1ULL << 0),
+   /* BPF_SK_STORAGE_GET_F_CREATE is only kept for backward compatibility
+* and BPF_LOCAL_STORAGE_GET_F_CREATE must be 

Re: [GIT PULL] PCI fixes for v5.8

2020-07-24 Thread pr-tracker-bot
The pull request you sent on Fri, 24 Jul 2020 19:17:53 -0500:

> git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git 
> tags/pci-v5.8-fixes-2

has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/23ee3e4e5bd27bdbc0f1785eef7209ce872794c7

Thank you!

-- 
Deet-doot-dot, I am a bot.
https://korg.wiki.kernel.org/userdoc/prtracker


Re: [GIT PULL] nfsd bugfix for 5.8

2020-07-24 Thread pr-tracker-bot
The pull request you sent on Fri, 24 Jul 2020 18:02:25 -0400:

> git://linux-nfs.org/~bfields/linux.git tags/nfsd-5.8-2

has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/5876aa073f52541f4787b6111c8494ea9cfcde15

Thank you!

-- 
Deet-doot-dot, I am a bot.
https://korg.wiki.kernel.org/userdoc/prtracker


[PATCH] regulator: pca9450: Convert to use module_i2c_driver

2020-07-24 Thread Axel Lin
Use module_i2c_driver to simplify driver init boilerplate.

Signed-off-by: Axel Lin 
---
 drivers/regulator/pca9450-regulator.c | 12 +---
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/drivers/regulator/pca9450-regulator.c 
b/drivers/regulator/pca9450-regulator.c
index 02250459aa90..eb5822bf53e0 100644
--- a/drivers/regulator/pca9450-regulator.c
+++ b/drivers/regulator/pca9450-regulator.c
@@ -826,17 +826,7 @@ static struct i2c_driver pca9450_i2c_driver = {
.probe = pca9450_i2c_probe,
 };
 
-static int __init pca9450_i2c_init(void)
-{
-   return i2c_add_driver(&pca9450_i2c_driver);
-}
-module_init(pca9450_i2c_init);
-
-static void __exit pca9450_i2c_exit(void)
-{
-   i2c_del_driver(&pca9450_i2c_driver);
-}
-module_exit(pca9450_i2c_exit);
+module_i2c_driver(pca9450_i2c_driver);
 
 MODULE_AUTHOR("Robin Gong ");
 MODULE_DESCRIPTION("NXP PCA9450 Power Management IC driver");
-- 
2.25.1



[PATCH v3 2/5] MIPS: Loongson64: Process ISA Node in DeviceTree

2020-07-24 Thread Jiaxun Yang
Previously, we're hardcoding resserved ISA I/O Space in code, now
we're processing reverved I/O via DeviceTree directly. Using the ranges
property to determine the size and address of reserved I/O space.

Signed-off-by: Jiaxun Yang 
--
v2: Use range_parser instead of pci_range_parser
---
 arch/mips/loongson64/init.c | 87 ++---
 1 file changed, 62 insertions(+), 25 deletions(-)

diff --git a/arch/mips/loongson64/init.c b/arch/mips/loongson64/init.c
index 59ddadace83f..8ba22c30f312 100644
--- a/arch/mips/loongson64/init.c
+++ b/arch/mips/loongson64/init.c
@@ -7,6 +7,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -63,41 +65,76 @@ void __init prom_free_prom_memory(void)
 {
 }
 
-static __init void reserve_pio_range(void)
+static int __init add_legacy_isa_io(struct fwnode_handle *fwnode, 
resource_size_t hw_start,
+   resource_size_t size)
 {
+   int ret = 0;
struct logic_pio_hwaddr *range;
+   unsigned long vaddr;
 
range = kzalloc(sizeof(*range), GFP_ATOMIC);
if (!range)
-   return;
+   return -ENOMEM;
 
-   range->fwnode = &of_root->fwnode;
-   range->size = MMIO_LOWER_RESERVED;
-   range->hw_start = LOONGSON_PCIIO_BASE;
+   range->fwnode = fwnode;
+   range->size = size;
+   range->hw_start = hw_start;
range->flags = LOGIC_PIO_CPU_MMIO;
 
-   if (logic_pio_register_range(range)) {
-   pr_err("Failed to reserve PIO range for legacy ISA\n");
-   goto free_range;
+   ret = logic_pio_register_range(range);
+   if (ret) {
+   kfree(range);
+   return ret;
+   }
+
+   /* Legacy ISA must placed at the start of PCI_IOBASE */
+   if (range->io_start != 0) {
+   logic_pio_unregister_range(range);
+   kfree(range);
+   return -EINVAL;
}
 
-   if (WARN(range->io_start != 0,
-   "Reserved PIO range does not start from 0\n"))
-   goto unregister;
-
-   /*
-* i8259 would access I/O space, so mapping must be done here.
-* Please remove it when all drivers can be managed by logic_pio.
-*/
-   ioremap_page_range(PCI_IOBASE, PCI_IOBASE + MMIO_LOWER_RESERVED,
-   LOONGSON_PCIIO_BASE,
-   pgprot_device(PAGE_KERNEL));
-
-   return;
-unregister:
-   logic_pio_unregister_range(range);
-free_range:
-   kfree(range);
+   vaddr = PCI_IOBASE + range->io_start;
+
+   ioremap_page_range(vaddr, vaddr + size, hw_start, 
pgprot_device(PAGE_KERNEL));
+
+   return 0;
+}
+
+static __init void reserve_pio_range(void)
+{
+   struct device_node *np;
+
+   for_each_node_by_name(np, "isa") {
+   struct of_range range;
+   struct of_range_parser parser;
+
+   pr_info("ISA Bridge: %pOF\n", np);
+
+   if (of_range_parser_init(&parser, np)) {
+   pr_info("Failed to parse resources.\n");
+   break;
+   }
+
+   for_each_of_range(&parser, &range) {
+   switch (range.flags & IORESOURCE_TYPE_BITS) {
+   case IORESOURCE_IO:
+   pr_info(" IO 0x%016llx..0x%016llx  ->  
0x%016llx\n",
+   range.cpu_addr,
+   range.cpu_addr + range.size - 1,
+   range.bus_addr);
+   if (add_legacy_isa_io(&np->fwnode, 
range.cpu_addr, range.size))
+   pr_warn("Failed to reserve legacy IO in 
Logic PIO\n");
+   break;
+   case IORESOURCE_MEM:
+   pr_info(" MEM 0x%016llx..0x%016llx  ->  
0x%016llx\n",
+   range.cpu_addr,
+   range.cpu_addr + range.size - 1,
+   range.bus_addr);
+   break;
+   }
+   }
+   }
 }
 
 void __init arch_init_irq(void)
-- 
2.28.0.rc1



[PATCH v3 0/5] MIPS: Loongson64: Process ISA Node in DeviceTree

2020-07-24 Thread Jiaxun Yang
Hi,

This series convert reservation of Loongson64 Logic PIO into DeviceTree based
method.

It can be used to replace Huacai's
"MIPS: Loongson64: Reserve legacy MMIO space according to bridge type".

Thanks.

v2:
  - Address Rob and Huacai's review comments.
v3:
  - Address Rob, Thomas's review comments.

Jiaxun Yang (5):
  of_address: Add bus type match for pci ranges parser
  MIPS: Loongson64: Process ISA Node in DeviceTree
  MIPS: Loongson64: Enlarge IO_SPACE_LIMIT
  MIPS: Loongson64: DTS: Fix ISA range for RS780E PCH
  MIPS: Loongson64: Add ISA node for LS7A PCH

 arch/mips/boot/dts/loongson/ls7a-pch.dtsi |  7 ++
 arch/mips/boot/dts/loongson/rs780e-pch.dtsi   |  2 +-
 arch/mips/include/asm/io.h|  2 -
 arch/mips/include/asm/mach-generic/spaces.h   |  4 +
 .../mips/include/asm/mach-loongson64/spaces.h |  3 +-
 arch/mips/loongson64/init.c   | 87 +--
 drivers/of/address.c  | 29 ---
 include/linux/of_address.h|  4 +
 8 files changed, 96 insertions(+), 42 deletions(-)

-- 
2.28.0.rc1



[PATCH v3 1/5] of_address: Add bus type match for pci ranges parser

2020-07-24 Thread Jiaxun Yang
So the parser can be used to parse range property of ISA bus.

As they're all using PCI-like method of range property, there is no need
start a new parser.

Signed-off-by: Jiaxun Yang 

--
v2: Drop useless check, fix some na for bus_addr
add define of of_range_parser_init according to
Rob's suggestion.
v3: Abstract out has_flags. simplify define.
---
 drivers/of/address.c   | 29 +
 include/linux/of_address.h |  4 
 2 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/drivers/of/address.c b/drivers/of/address.c
index 8eea3f6e29a4..813936d419ad 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -49,6 +49,7 @@ struct of_bus {
u64 (*map)(__be32 *addr, const __be32 *range,
int na, int ns, int pna);
int (*translate)(__be32 *addr, u64 offset, int na);
+   boolhas_flags;
unsigned int(*get_flags)(const __be32 *addr);
 };
 
@@ -364,6 +365,7 @@ static struct of_bus of_busses[] = {
.count_cells = of_bus_pci_count_cells,
.map = of_bus_pci_map,
.translate = of_bus_pci_translate,
+   .has_flags = true,
.get_flags = of_bus_pci_get_flags,
},
 #endif /* CONFIG_PCI */
@@ -375,6 +377,7 @@ static struct of_bus of_busses[] = {
.count_cells = of_bus_isa_count_cells,
.map = of_bus_isa_map,
.translate = of_bus_isa_translate,
+   .has_flags = true,
.get_flags = of_bus_isa_get_flags,
},
/* Default */
@@ -698,9 +701,10 @@ static int parser_init(struct of_pci_range_parser *parser,
 
parser->node = node;
parser->pna = of_n_addr_cells(node);
-   parser->na = of_bus_n_addr_cells(node);
-   parser->ns = of_bus_n_size_cells(node);
parser->dma = !strcmp(name, "dma-ranges");
+   parser->bus = of_match_bus(node);
+
+   parser->bus->count_cells(parser->node, &parser->na, &parser->ns);
 
parser->range = of_get_property(node, name, &rlen);
if (parser->range == NULL)
@@ -732,6 +736,7 @@ struct of_pci_range *of_pci_range_parser_one(struct 
of_pci_range_parser *parser,
int na = parser->na;
int ns = parser->ns;
int np = parser->pna + na + ns;
+   int busflag_na = 0;
 
if (!range)
return NULL;
@@ -739,12 +744,13 @@ struct of_pci_range *of_pci_range_parser_one(struct 
of_pci_range_parser *parser,
if (!parser->range || parser->range + np > parser->end)
return NULL;
 
-   if (parser->na == 3)
-   range->flags = of_bus_pci_get_flags(parser->range);
-   else
-   range->flags = 0;
+   range->flags = parser->bus->get_flags(parser->range);
+
+   /* A extra cell for resource flags */
+   if (parser->bus->has_flags)
+   busflag_na = 1;
 
-   range->pci_addr = of_read_number(parser->range, na);
+   range->bus_addr = of_read_number(parser->range + busflag_na, na - 
busflag_na);
 
if (parser->dma)
range->cpu_addr = of_translate_dma_address(parser->node,
@@ -759,11 +765,10 @@ struct of_pci_range *of_pci_range_parser_one(struct 
of_pci_range_parser *parser,
/* Now consume following elements while they are contiguous */
while (parser->range + np <= parser->end) {
u32 flags = 0;
-   u64 pci_addr, cpu_addr, size;
+   u64 bus_addr, cpu_addr, size;
 
-   if (parser->na == 3)
-   flags = of_bus_pci_get_flags(parser->range);
-   pci_addr = of_read_number(parser->range, na);
+   flags = parser->bus->get_flags(parser->range);
+   bus_addr = of_read_number(parser->range + busflag_na, na - 
busflag_na);
if (parser->dma)
cpu_addr = of_translate_dma_address(parser->node,
parser->range + na);
@@ -774,7 +779,7 @@ struct of_pci_range *of_pci_range_parser_one(struct 
of_pci_range_parser *parser,
 
if (flags != range->flags)
break;
-   if (pci_addr != range->pci_addr + range->size ||
+   if (bus_addr != range->bus_addr + range->size ||
cpu_addr != range->cpu_addr + range->size)
break;
 
diff --git a/include/linux/of_address.h b/include/linux/of_address.h
index 763022ed3456..88bc943405cd 100644
--- a/include/linux/of_address.h
+++ b/include/linux/of_address.h
@@ -6,8 +6,11 @@
 #include 
 #include 
 
+struct of_bus;
+
 struct of_pci_range_parser {
struct device_node *node;
+   struct of_bus *bus;
const __be32 *range;
const __be32 *end;
int na;
@@ -119,6 +122,7 @@ static inline void __iomem *of_iomap(struct device_node 
*device, int index)
return NULL;
 }
 #endif
+#define of_range_p

[PATCH v3 3/5] MIPS: Loongson64: Enlarge IO_SPACE_LIMIT

2020-07-24 Thread Jiaxun Yang
It can be very big on LS7A PCH systems.

Signed-off-by: Jiaxun Yang 
--
v3: Move IO_SPACE_LIMIT to spaces.h
---
 arch/mips/include/asm/io.h | 2 --
 arch/mips/include/asm/mach-generic/spaces.h| 4 
 arch/mips/include/asm/mach-loongson64/spaces.h | 3 +--
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/mips/include/asm/io.h b/arch/mips/include/asm/io.h
index 346fffd9e972..8ca53f17c7c2 100644
--- a/arch/mips/include/asm/io.h
+++ b/arch/mips/include/asm/io.h
@@ -51,8 +51,6 @@
 
 /* ioswab[bwlq], __mem_ioswab[bwlq] are defined in mangle-port.h */
 
-#define IO_SPACE_LIMIT 0x
-
 /*
  * On MIPS I/O ports are memory mapped, so we access them using normal
  * load/store instructions. mips_io_port_base is the virtual address to
diff --git a/arch/mips/include/asm/mach-generic/spaces.h 
b/arch/mips/include/asm/mach-generic/spaces.h
index ee5ebe98f6cf..c3ac06a6acd2 100644
--- a/arch/mips/include/asm/mach-generic/spaces.h
+++ b/arch/mips/include/asm/mach-generic/spaces.h
@@ -14,6 +14,10 @@
 
 #include 
 
+#ifndef IO_SPACE_LIMIT
+#define IO_SPACE_LIMIT 0x
+#endif
+
 /*
  * This gives the physical RAM offset.
  */
diff --git a/arch/mips/include/asm/mach-loongson64/spaces.h 
b/arch/mips/include/asm/mach-loongson64/spaces.h
index 3de0ac9d8829..ce04e998a37b 100644
--- a/arch/mips/include/asm/mach-loongson64/spaces.h
+++ b/arch/mips/include/asm/mach-loongson64/spaces.h
@@ -11,8 +11,7 @@
 #define PCI_IOSIZE SZ_16M
 #define MAP_BASE   (PCI_IOBASE + PCI_IOSIZE)
 
-/* Reserved at the start of PCI_IOBASE for legacy drivers */
-#define MMIO_LOWER_RESERVED0x1
+#define IO_SPACE_LIMIT  (PCI_IOSIZE - 1)
 
 #include 
 #endif
-- 
2.28.0.rc1



[PATCH v3 5/5] MIPS: Loongson64: Add ISA node for LS7A PCH

2020-07-24 Thread Jiaxun Yang
Although currently we're not enabling any ISA device in devicetree,
but this node is required to express the ranges of address reserved
for ISA.

Signed-off-by: Jiaxun Yang 
---
 arch/mips/boot/dts/loongson/ls7a-pch.dtsi | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/mips/boot/dts/loongson/ls7a-pch.dtsi 
b/arch/mips/boot/dts/loongson/ls7a-pch.dtsi
index 1c286bb8c703..e574a062dfae 100644
--- a/arch/mips/boot/dts/loongson/ls7a-pch.dtsi
+++ b/arch/mips/boot/dts/loongson/ls7a-pch.dtsi
@@ -367,5 +367,12 @@ pci_bridge@14,0 {
interrupt-map = <0 0 0 0 &pic 39 
IRQ_TYPE_LEVEL_HIGH>;
};
};
+
+   isa {
+   compatible = "isa";
+   #address-cells = <2>;
+   #size-cells = <1>;
+   ranges = <1 0 0 0x1800 0x2>;
+   };
};
 };
-- 
2.28.0.rc1



[PATCH v3 4/5] MIPS: Loongson64: DTS: Fix ISA range for RS780E PCH

2020-07-24 Thread Jiaxun Yang
Ranges should express the actual physical address on bus.

Signed-off-by: Jiaxun Yang 
---
 arch/mips/boot/dts/loongson/rs780e-pch.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/boot/dts/loongson/rs780e-pch.dtsi 
b/arch/mips/boot/dts/loongson/rs780e-pch.dtsi
index d4c803d74036..99174b52dfb8 100644
--- a/arch/mips/boot/dts/loongson/rs780e-pch.dtsi
+++ b/arch/mips/boot/dts/loongson/rs780e-pch.dtsi
@@ -25,7 +25,7 @@ isa {
compatible = "isa";
#address-cells = <2>;
#size-cells = <1>;
-   ranges = <1 0 0 0 0x4000>;
+   ranges = <1 0 0 0x1800 0x4000>;
 
rtc0: rtc@70 {
compatible = "motorola,mc146818";
-- 
2.28.0.rc1



[PATCH net-next] fib: use indirect call wrappers in the most common fib_rules_ops

2020-07-24 Thread Brian Vazquez
This avoids another inderect call per RX packet which save us around
20-40 ns.

Signed-off-by: Brian Vazquez 
---
 net/core/fib_rules.c  | 32 
 net/ipv4/fib_rules.c  | 12 
 net/ipv6/fib6_rules.c | 12 
 3 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index bd7eba9066f8d..ceef012dd0e65 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static const struct fib_kuid_range fib_kuid_range_unset = {
KUIDT_INIT(0),
@@ -242,6 +243,10 @@ static int nla_put_port_range(struct sk_buff *skb, int 
attrtype,
return nla_put(skb, attrtype, sizeof(*range), range);
 }
 
+INDIRECT_CALLABLE_DECLARE(int fib6_rule_match(struct fib_rule *rule,
+   struct flowi *fl, int flags));
+INDIRECT_CALLABLE_DECLARE(int fib4_rule_match(struct fib_rule *rule,
+   struct flowi *fl, int flags));
 static int fib_rule_match(struct fib_rule *rule, struct fib_rules_ops *ops,
  struct flowi *fl, int flags,
  struct fib_lookup_arg *arg)
@@ -267,11 +272,24 @@ static int fib_rule_match(struct fib_rule *rule, struct 
fib_rules_ops *ops,
uid_gt(fl->flowi_uid, rule->uid_range.end))
goto out;
 
-   ret = ops->match(rule, fl, flags);
+   ret = INDIRECT_CALL_INET(ops->match,
+fib6_rule_match,
+fib4_rule_match,
+rule, fl, flags);
 out:
return (rule->flags & FIB_RULE_INVERT) ? !ret : ret;
 }
 
+INDIRECT_CALLABLE_DECLARE(int fib6_rule_action(struct fib_rule *rule,
+   struct flowi *flp, int flags,
+   struct fib_lookup_arg *arg));
+INDIRECT_CALLABLE_DECLARE(int fib4_rule_action(struct fib_rule *rule,
+   struct flowi *flp, int flags,
+   struct fib_lookup_arg *arg));
+INDIRECT_CALLABLE_DECLARE(bool fib6_rule_suppress(struct fib_rule *rule,
+   struct fib_lookup_arg *arg));
+INDIRECT_CALLABLE_DECLARE(bool fib4_rule_suppress(struct fib_rule *rule,
+   struct fib_lookup_arg *arg));
 int fib_rules_lookup(struct fib_rules_ops *ops, struct flowi *fl,
 int flags, struct fib_lookup_arg *arg)
 {
@@ -298,9 +316,15 @@ int fib_rules_lookup(struct fib_rules_ops *ops, struct 
flowi *fl,
} else if (rule->action == FR_ACT_NOP)
continue;
else
-   err = ops->action(rule, fl, flags, arg);
-
-   if (!err && ops->suppress && ops->suppress(rule, arg))
+   err = INDIRECT_CALL_INET(ops->action,
+  fib6_rule_action,
+  fib4_rule_action,
+  rule, fl, flags, arg);
+
+   if (!err && ops->suppress && INDIRECT_CALL_INET(ops->suppress,
+   
fib6_rule_suppress,
+   
fib4_rule_suppress,
+   rule, arg))
continue;
 
if (err != -EAGAIN) {
diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c
index f99e3bac5cab2..fd3def3ffa6df 100644
--- a/net/ipv4/fib_rules.c
+++ b/net/ipv4/fib_rules.c
@@ -29,6 +29,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct fib4_rule {
struct fib_rule common;
@@ -103,8 +104,9 @@ int __fib_lookup(struct net *net, struct flowi4 *flp,
 }
 EXPORT_SYMBOL_GPL(__fib_lookup);
 
-static int fib4_rule_action(struct fib_rule *rule, struct flowi *flp,
-   int flags, struct fib_lookup_arg *arg)
+INDIRECT_CALLABLE_SCOPE int fib4_rule_action(struct fib_rule *rule,
+   struct flowi *flp, int flags,
+   struct fib_lookup_arg *arg)
 {
int err = -EAGAIN;
struct fib_table *tbl;
@@ -138,7 +140,8 @@ static int fib4_rule_action(struct fib_rule *rule, struct 
flowi *flp,
return err;
 }
 
-static bool fib4_rule_suppress(struct fib_rule *rule, struct fib_lookup_arg 
*arg)
+INDIRECT_CALLABLE_SCOPE bool fib4_rule_suppress(struct fib_rule *rule,
+   struct fib_lookup_arg *arg)
 {
struct fib_result *result = (struct fib_result *) arg->result;
struct net_device *dev = NULL;
@@ -169,7 +172,8 @@ static bool fib4_rule_suppress(struct fib_rule *rule, 
struct fib_lookup_arg *arg
return true;
 }
 
-static int fib4_rule_match(struct fib_rule *rule, struct flowi *fl, int flags)
+INDIRECT_CALLAB

[tip:WIP.x86/build] BUILD SUCCESS 3dcdcc6f042d35afc7ec32da39cf8fc8b69ce15a

2020-07-24 Thread kernel test robot
tree/branch: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git  
WIP.x86/build
branch HEAD: 3dcdcc6f042d35afc7ec32da39cf8fc8b69ce15a  x86/defconfigs: Refresh 
defconfig files

elapsed time: 725m

configs tested: 103
configs skipped: 70

The following configs have been built successfully.
More configs may be tested in the coming days.

arm defconfig
arm  allyesconfig
arm  allmodconfig
arm   allnoconfig
arm64allyesconfig
arm64   defconfig
arm64allmodconfig
arm64 allnoconfig
i386  allnoconfig
i386 allyesconfig
i386defconfig
i386  debian-10.3
ia64 allmodconfig
ia64defconfig
ia64  allnoconfig
ia64 allyesconfig
m68k allmodconfig
m68k  allnoconfig
m68k   sun3_defconfig
m68kdefconfig
m68k allyesconfig
nds32   defconfig
nds32 allnoconfig
csky allyesconfig
cskydefconfig
alpha   defconfig
alphaallyesconfig
xtensa   allyesconfig
h8300allyesconfig
h8300allmodconfig
xtensa  defconfig
arc defconfig
arc  allyesconfig
sh   allmodconfig
shallnoconfig
microblazeallnoconfig
nios2   defconfig
nios2allyesconfig
openriscdefconfig
c6x  allyesconfig
c6x   allnoconfig
openrisc allyesconfig
mips allyesconfig
mips  allnoconfig
mips allmodconfig
pariscallnoconfig
parisc  defconfig
parisc   allyesconfig
parisc   allmodconfig
powerpc  allyesconfig
powerpc  rhel-kconfig
powerpc  allmodconfig
powerpc   allnoconfig
i386 randconfig-a003-20200724
i386 randconfig-a005-20200724
i386 randconfig-a004-20200724
i386 randconfig-a006-20200724
i386 randconfig-a002-20200724
i386 randconfig-a001-20200724
i386 randconfig-a003-20200725
i386 randconfig-a005-20200725
i386 randconfig-a004-20200725
i386 randconfig-a006-20200725
i386 randconfig-a002-20200725
i386 randconfig-a001-20200725
x86_64   randconfig-a014-20200724
x86_64   randconfig-a016-20200724
x86_64   randconfig-a015-20200724
x86_64   randconfig-a012-20200724
x86_64   randconfig-a013-20200724
x86_64   randconfig-a011-20200724
i386 randconfig-a016-20200725
i386 randconfig-a013-20200725
i386 randconfig-a012-20200725
i386 randconfig-a015-20200725
i386 randconfig-a014-20200725
i386 randconfig-a011-20200725
i386 randconfig-a016-20200724
i386 randconfig-a013-20200724
i386 randconfig-a012-20200724
i386 randconfig-a015-20200724
i386 randconfig-a014-20200724
i386 randconfig-a011-20200724
riscvallyesconfig
riscv allnoconfig
riscv   defconfig
riscvallmodconfig
s390 allyesconfig
s390  allnoconfig
s390 allmodconfig
s390defconfig
sparcallyesconfig
sparc   defconfig
sparc64 defconfig
sparc64   allnoconfig
sparc64  allyesconfig
sparc64  allmodconfig
x86_64rhel-7.6-kselftests
x86_64   rhel-8.3
x86_64  kexec
x86_64   rhel

Re: [PATCH -next] arm64: Export __cpu_logical_map

2020-07-24 Thread Kefeng Wang



On 2020/7/24 21:10, Sudeep Holla wrote:

On Fri, Jul 24, 2020 at 11:08:03AM +0800, Kefeng Wang wrote:

+maillist

On 2020/7/24 11:04, Kefeng Wang wrote:

ERROR: modpost: "__cpu_logical_map" [drivers/cpufreq/tegra194-cpufreq.ko] 
undefined!

ARM64 tegra194-cpufreq driver use cpu_logical_map, export
__cpu_logical_map to fix build issue.


I wonder why like other instances in the drivers, the mpidr is not get
directly from the cpu. The cpufreq_driver->init call happens when the cpu
is being brought online and is executed on the required cpu IIUC.

read_cpuid_mpidr() is inline and avoids having to export the logical_cpu_map.
Though we may not add physical hotplug anytime soon, less dependency
on this cpu_logical_map is better given that we can resolve this without
the need to access the map.


Hi all,  thanks for all comments.

As Sudeep said, I will using read_cpuid_mpidr() directly in 
tegra194-cpufreq to


fix the build issue,  and later we also would turn cpu_logical_map() 
into a C wrapper.


If that's ok, I will send a new build-fix patch firstly, thanks.








Re: [PATCH v5 3/6] arch/x86: Implement text_alloc() and text_free()

2020-07-24 Thread Jarkko Sakkinen
On Fri, Jul 24, 2020 at 11:22:58AM +0200, Ingo Molnar wrote:
> 
> * Jarkko Sakkinen  wrote:
> 
> > +void text_free(void *region)
> > +{
> > +   /*
> > +* This memory may be RO, and freeing RO memory in an interrupt is not
> > +* supported by vmalloc.
> > +*/
> > +   lockdep_assert_irqs_enabled();
> > +
> > +   vfree(region);
> 
> Had to dig around a bit to find the source of this restriction. Might 
> make sense to clarify this comment to:
> 
>   /*
>* This memory may be read-only, and freeing VM_FLUSH_RESET_PERMS memory
>* in an interrupt is not supported by vmalloc.
>*/

This definitely clarifies and is a better explanation. I updated the
commit accordingly. Thank you.

> 
> Thanks,
> 
>   Ingo

/Jarkko


Re: [RFC PATCH] mm: silence soft lockups from unlock_page

2020-07-24 Thread Hugh Dickins
On Fri, 24 Jul 2020, Linus Torvalds wrote:

> On Fri, Jul 24, 2020 at 10:32 AM Linus Torvalds
>  wrote:
> > Ok, that makes sense. Except you did it on top of the original patch
> > without the fix to set WQ_FLAG_WOKEN for the non-wakeup case.
> 
> Hmm.
> 
> I just realized that one thing we could do is to not even test the
> page bit for the shared case in the wakeup path.
> 
> Because anybody who uses the non-exclusive "wait_on_page_locked()" or
> "wait_on_page_writeback()" isn't actually interested in the bit state
> any more at that point. All they care about is that somebody cleared
> it - not whether it was then re-taken again.
> 
> So instead of keeping them on the list - or stopping the waitqueue
> walk because somebody else got the bit - we could just mark them
> successfully done, wake them up, and remove those entries from the
> list.
> 
> That would be better for everybody - less pointless waiting for a new
> lock or writeback event, but also fewer entries on the wait queues as
> we get rid of them more quickly instead of walking them over and over
> just because somebody else re-took the page lock.
> 
> Generally "wait_on_page_locked()" is used for two things
> 
>  - either wait for the IO to then check if it's now uptodate
> 
>  - throttle things that can't afford to lock the page (eg page faults
> that dropped the mm lock, and as such need to go through the whole
> restart logic, but that don't want to lock the page because it's now
> too late, but also the page migration things)
> 
> In the first case, waiting to actually seeing the locked bit clear is
> pointless - the code only cared about the "wait for IO in progress"
> not about the lock bit itself.
> 
> And that second case generally might want to retry, but doesn't want
> to busy-loop.
> 
> And "wait_on_page_writeback()" is basically used for similar reasons
> (ie check if there were IO errors, but also possibly to throttle
> writeback traffic).
> 
> Saying "stop walking, keep it on the list" seems wrong. It makes IO
> error handling and retries much worse, for example.
> 
> So it turns out that the wakeup logic and the initial wait logic don't
> have so much in common after all, and there is a fundamental
> conceptual difference between that "check bit one last time" case, and
> the "we got woken up, now what" case..
> 
> End result: one final (yes, hopefully - I think I'm done) version of
> this patch-series.
> 
> This not only makes the code cleaner (the generated code for
> wake_up_page() is really quite nice now), but getting rid of extra
> waiting might help the load that Michal reported.
> 
> Because a lot of page waiting might be that non-exclusive
> "wait_on_page_locked()" kind, particularly in the thundering herd kind
> of situation where one process starts IO, and then other processes
> wait for it to finish.
> 
> Those users don't even care if somebody else then did a "lock_page()"
> for some other reason (maybe for writeback). They are generally
> perfectly happy with a locked page, as long as it's now up-to-date.
> 
> So this not only simplifies the code, it really might avoid some problems too.

That set of tests I started yesterday has now completed: no crashes
due to your changes (though, one machine crashed with an entirely
unrelated list_del corruption: over in driverland, just a coincidence).

I do see more of these stresstests reporting failure than I remember
from the last time I ran them, and I wasn't quickly able to work out
why (usually I just care about not crashing or hanging, rarely delve
deeper into what they actually call success).  The most likely cause
would be some internal infrastructural oddity, and nothing for you
to worry about; but there is a possibility that it's meaningful.

But whatever, what happens on the next run, with these latest patches,
will be more important; and I'll follow this next run with a run on
the baseline without them, to compare results.

Hugh


Re: [v7, PATCH 2/7] mtk-mmsys: add mmsys private data

2020-07-24 Thread Chun-Kuang Hu
Hi, Yongqiang:

Yongqiang Niu  於 2020年7月23日 週四 上午10:05寫道:
>
> add mmsys private data
>
> Feature: drm/mediatek
> Signed-off-by: Yongqiang Niu 
> ---
>  drivers/soc/mediatek/Makefile |   1 +
>  drivers/soc/mediatek/mmsys/Makefile   |   2 +
>  drivers/soc/mediatek/mmsys/mt2701-mmsys.c | 250 +++
>  drivers/soc/mediatek/mtk-mmsys.c  | 271 
> +-
>  include/linux/soc/mediatek/mtk-mmsys.h|  15 ++
>  5 files changed, 314 insertions(+), 225 deletions(-)
>  create mode 100644 drivers/soc/mediatek/mmsys/Makefile
>  create mode 100644 drivers/soc/mediatek/mmsys/mt2701-mmsys.c
>
> diff --git a/drivers/soc/mediatek/Makefile b/drivers/soc/mediatek/Makefile
> index 2afa7b9..b37ac2c 100644
> --- a/drivers/soc/mediatek/Makefile
> +++ b/drivers/soc/mediatek/Makefile
> @@ -3,3 +3,4 @@ obj-$(CONFIG_MTK_CMDQ) += mtk-cmdq-helper.o
>  obj-$(CONFIG_MTK_PMIC_WRAP) += mtk-pmic-wrap.o
>  obj-$(CONFIG_MTK_SCPSYS) += mtk-scpsys.o
>  obj-$(CONFIG_MTK_MMSYS) += mtk-mmsys.o
> +obj-$(CONFIG_MTK_MMSYS) += mmsys/
> diff --git a/drivers/soc/mediatek/mmsys/Makefile 
> b/drivers/soc/mediatek/mmsys/Makefile
> new file mode 100644
> index 000..33b0dab
> --- /dev/null
> +++ b/drivers/soc/mediatek/mmsys/Makefile
> @@ -0,0 +1,2 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +obj-y += mt2701-mmsys.o
> diff --git a/drivers/soc/mediatek/mmsys/mt2701-mmsys.c 
> b/drivers/soc/mediatek/mmsys/mt2701-mmsys.c
> new file mode 100644
> index 000..b8e53b0
> --- /dev/null
> +++ b/drivers/soc/mediatek/mmsys/mt2701-mmsys.c
> @@ -0,0 +1,250 @@
> +// SPDX-License-Identifier: GPL-2.0
> +//
> +// Copyright (c) 2020 MediaTek Inc.
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define DISP_REG_CONFIG_DISP_OVL0_MOUT_EN  0x040
> +#define DISP_REG_CONFIG_DISP_OVL1_MOUT_EN  0x044
> +#define DISP_REG_CONFIG_DISP_OD_MOUT_EN0x048
> +#define DISP_REG_CONFIG_DISP_GAMMA_MOUT_EN 0x04c
> +#define DISP_REG_CONFIG_DISP_UFOE_MOUT_EN  0x050
> +#define DISP_REG_CONFIG_DISP_COLOR0_SEL_IN 0x084
> +#define DISP_REG_CONFIG_DISP_COLOR1_SEL_IN 0x088
> +#define DISP_REG_CONFIG_DSIE_SEL_IN0x0a4
> +#define DISP_REG_CONFIG_DSIO_SEL_IN0x0a8
> +#define DISP_REG_CONFIG_DPI_SEL_IN 0x0ac
> +#define DISP_REG_CONFIG_DISP_RDMA2_SOUT0x0b8
> +#define DISP_REG_CONFIG_DISP_RDMA0_SOUT_EN 0x0c4
> +#define DISP_REG_CONFIG_DISP_RDMA1_SOUT_EN 0x0c8
> +#define DISP_REG_CONFIG_MMSYS_CG_CON0  0x100
> +
> +#define DISP_REG_CONFIG_DISP_OVL_MOUT_EN   0x030
> +#define DISP_REG_CONFIG_OUT_SEL0x04c
> +#define DISP_REG_CONFIG_DSI_SEL0x050
> +#define DISP_REG_CONFIG_DPI_SEL0x064
> +
> +#define OVL0_MOUT_EN_COLOR00x1
> +#define OD_MOUT_EN_RDMA0   0x1
> +#define OD1_MOUT_EN_RDMA1  BIT(16)
> +#define UFOE_MOUT_EN_DSI0  0x1
> +#define COLOR0_SEL_IN_OVL0 0x1
> +#define OVL1_MOUT_EN_COLOR10x1
> +#define GAMMA_MOUT_EN_RDMA10x1
> +#define RDMA0_SOUT_DPI00x2
> +#define RDMA0_SOUT_DPI10x3
> +#define RDMA0_SOUT_DSI10x1
> +#define RDMA0_SOUT_DSI20x4
> +#define RDMA0_SOUT_DSI30x5
> +#define RDMA1_SOUT_DPI00x2
> +#define RDMA1_SOUT_DPI10x3
> +#define RDMA1_SOUT_DSI10x1
> +#define RDMA1_SOUT_DSI20x4
> +#define RDMA1_SOUT_DSI30x5
> +#define RDMA2_SOUT_DPI00x2
> +#define RDMA2_SOUT_DPI10x3
> +#define RDMA2_SOUT_DSI10x1
> +#define RDMA2_SOUT_DSI20x4
> +#define RDMA2_SOUT_DSI30x5
> +#define DPI0_SEL_IN_RDMA1  0x1
> +#define DPI0_SEL_IN_RDMA2  0x3
> +#define DPI1_SEL_IN_RDMA1  (0x1 << 8)
> +#define DPI1_SEL_IN_RDMA2  (0x3 << 8)
> +#define DSI0_SEL_IN_RDMA1  0x1
> +#define DSI0_SEL_IN_RDMA2  0x4
> +#define DSI1_SEL_IN_RDMA1  0x1
> +#define DSI1_SEL_IN_RDMA2  0x4
> +#define DSI2_SEL_IN_RDMA1  (0x1 << 16)
> +#define DSI2_SEL_IN_RDMA2  (0x4 << 16)
> +#define DSI3_SEL_IN_RDMA1  (0x1 << 16)
> +#define DSI3_SEL_IN_RDMA2  (0x4 << 16)
> +#define COLOR1_SEL_IN_OVL1 0x1
> +
> +#define OVL_MOUT_EN_RDMA   0x1
> +#define BLS_TO_DSI_RDMA1_TO_DPI1   0x8
> +#define BLS_

Re: [PATCH v5 2/6] vmalloc: Add text_alloc() and text_free()

2020-07-24 Thread Jarkko Sakkinen
On Fri, Jul 24, 2020 at 01:22:43PM +0300, Mike Rapoport wrote:
> On Fri, Jul 24, 2020 at 08:05:49AM +0300, Jarkko Sakkinen wrote:
> > Introduce functions for allocating memory for dynamic trampolines, such
> > as kprobes. An arch can promote the availability of these functions with
> > CONFIG_ARCH_HAS_TEXT_ALLOC.
> 
> As it was pointed out at the discussion on the previous version [1],
> text_alloc() alone won't necessarily suit other architectures.
>  
> I don't see a point in defining a "generic" interface that apriory could
> not be imeplemented by several architectures.
> 
> [1] 
> https://lore.kernel.org/lkml/20200714094625.1443261-1-jarkko.sakki...@linux.intel.com/

These changes do actually acknowledge the feedback [1][2][3]. They do not
interfere with module_alloc() and are fully optional.

[1] https://lore.kernel.org/linux-riscv/20200714102826.GB4756@willie-the-truck/
[2] 
https://lore.kernel.org/linux-riscv/20200714164245.ge1...@shell.armlinux.org.uk/
[3] https://lore.kernel.org/linux-riscv/20200714135651.GA27819@linux-8ccs/

/Jarkko


[PATCH] nbd: add missed destroy_workqueue when nbd_start_device fails

2020-07-24 Thread Li Heng
destroy_workqueue() should be called to destroy ndev->tx_wq
when nbd_start_device init resources fails.

Reported-by: Hulk Robot 
Signed-off-by: Li Heng 
---
 drivers/block/nbd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index ce7e9f22..45e0a9f4 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -4,7 +4,7 @@
  *
  * Note that you can not swap over this thing, yet. Seems to work but
  * deadlocks sometimes - you can not swap over TCP in general.
- * 
+ *
  * Copyright 1997-2000, 2008 Pavel Machek 
  * Parts copyright 2001 Steven Whitehouse 
  *
@@ -1270,6 +1270,7 @@ static int nbd_start_device(struct nbd_device *nbd)
error = device_create_file(disk_to_dev(nbd->disk), &pid_attr);
if (error) {
dev_err(disk_to_dev(nbd->disk), "device_create_file failed!\n");
+   destroy_workqueue(nbd->recv_workq);
return error;
}
set_bit(NBD_RT_HAS_PID_FILE, &config->runtime_flags);
@@ -1291,6 +1292,7 @@ static int nbd_start_device(struct nbd_device *nbd)
 */
if (i)
flush_workqueue(nbd->recv_workq);
+   destroy_workqueue(nbd->recv_workq);
return -ENOMEM;
}
sk_set_memalloc(config->socks[i]->sock->sk);
-- 
2.7.4



Re: [PATCH v5 1/6] kprobes: Remove dependency to the module_mutex

2020-07-24 Thread Jarkko Sakkinen
On Fri, Jul 24, 2020 at 11:13:19AM +0200, Ingo Molnar wrote:
> 
> * Jarkko Sakkinen  wrote:
> 
> > Add lock_modules() and unlock_modules() wrappers for acquiring module_mutex
> > in order to remove the compile time dependency to it.
> > 
> > Cc: linux...@kvack.org
> > Cc: Andi Kleen 
> > Cc: Peter Zijlstra 
> > Suggested-by: Masami Hiramatsu 
> > Signed-off-by: Jarkko Sakkinen 
> > ---
> >  include/linux/module.h  | 18 ++
> >  kernel/kprobes.c|  4 ++--
> >  kernel/trace/trace_kprobe.c |  4 ++--
> >  3 files changed, 22 insertions(+), 4 deletions(-)
> > 
> > diff --git a/include/linux/module.h b/include/linux/module.h
> > index 2e6670860d27..8850b9692b8f 100644
> > --- a/include/linux/module.h
> > +++ b/include/linux/module.h
> > @@ -705,6 +705,16 @@ static inline bool is_livepatch_module(struct module 
> > *mod)
> >  bool is_module_sig_enforced(void);
> >  void set_module_sig_enforced(void);
> >  
> > +static inline void lock_modules(void)
> > +{
> > +   mutex_lock(&module_mutex);
> > +}
> > +
> > +static inline void unlock_modules(void)
> > +{
> > +   mutex_unlock(&module_mutex);
> > +}
> > +
> >  #else /* !CONFIG_MODULES... */
> >  
> >  static inline struct module *__module_address(unsigned long addr)
> > @@ -852,6 +862,14 @@ void *dereference_module_function_descriptor(struct 
> > module *mod, void *ptr)
> > return ptr;
> >  }
> >  
> > +static inline void lock_modules(void)
> > +{
> > +}
> > +
> > +static inline void unlock_modules(void)
> > +{
> > +}
> 
> Minor namespace nit: when introducing new locking wrappers please 
> standardize on the XYZ_lock()/XYZ_unlock() nomenclature, i.e.:
> 
>   modules_lock()
>   ...
>   modules_unlock()
> 
> Similarly to the mutex_lock/unlock(&module_mutex) API that it is 
> wrapping.
> 
> Also, JFYI, the overwhelming majority of the modules related APIs use 
> module_*(), i.e. singular - not plural, so 
> module_lock()/module_unlock() would be the more canonical choice. 
> (But both sound fine to me)

Thanks, I renamed them as module_lock() and module_unlock().

> Thanks,
> 
>   Ingo

/Jarkko


Re: [PATCH v5 1/6] kprobes: Remove dependency to the module_mutex

2020-07-24 Thread Jarkko Sakkinen
On Fri, Jul 24, 2020 at 01:22:58PM +0300, Mike Rapoport wrote:
> On Fri, Jul 24, 2020 at 08:05:48AM +0300, Jarkko Sakkinen wrote:
> > Add lock_modules() and unlock_modules() wrappers for acquiring module_mutex
> > in order to remove the compile time dependency to it.
> > 
> > Cc: linux...@kvack.org
> > Cc: Andi Kleen 
> > Cc: Peter Zijlstra 
> > Suggested-by: Masami Hiramatsu 
> > Signed-off-by: Jarkko Sakkinen 
> > ---
> >  include/linux/module.h  | 18 ++
> >  kernel/kprobes.c|  4 ++--
> >  kernel/trace/trace_kprobe.c |  4 ++--
> >  3 files changed, 22 insertions(+), 4 deletions(-)
> 
> Any reason to convert only kprobes to the new API and leave others with
> opencoded implementation?

Not anything particular.

Lets see:

$ git --no-pager grep "mutex_lock(&module_mutex)"
arch/powerpc/platforms/powernv/pci-cxl.c:   mutex_lock(&module_mutex);
drivers/gpu/drm/drm_fb_helper.c:mutex_lock(&module_mutex);
include/linux/module.h: mutex_lock(&module_mutex);
kernel/livepatch/core.c:mutex_lock(&module_mutex);
kernel/livepatch/core.c:mutex_lock(&module_mutex);
kernel/module.c:mutex_lock(&module_mutex);
kernel/module.c:mutex_lock(&module_mutex);
kernel/module.c:mutex_lock(&module_mutex);
kernel/module.c:mutex_lock(&module_mutex);
kernel/module.c:mutex_lock(&module_mutex);
kernel/module.c:mutex_lock(&module_mutex);
kernel/module.c:mutex_lock(&module_mutex);
kernel/module.c:mutex_lock(&module_mutex);
kernel/module.c:mutex_lock(&module_mutex);
kernel/module.c:mutex_lock(&module_mutex);
kernel/module.c:mutex_lock(&module_mutex);
kernel/module.c:mutex_lock(&module_mutex);
kernel/module.c:mutex_lock(&module_mutex);

I could refine this commit to patch these sites. Or should I split it
into multiple?

/Jarkko


Re: [RFC PATCH] mm: silence soft lockups from unlock_page

2020-07-24 Thread Linus Torvalds
On Fri, Jul 24, 2020 at 7:08 PM Hugh Dickins  wrote:
>
> But whatever, what happens on the next run, with these latest patches,
> will be more important; and I'll follow this next run with a run on
> the baseline without them, to compare results.

So the loads you are running are known to have sensitivity to this
particular area, and are why you've done your patches to the page wait
bit code?

Because yes, I think that last version in particular might make a big
difference with the "let people continue even if they only saw the
wakeup event, and never actually tested and saw the bit clear".

Of course, there's a possibility that "big difference" ends up being a
negative one. I think it will make the page wait queues shorter (which
is good for that latency and lockup thing), but waking things up more
aggressively _may_ also end up adding more CPU load, if they then all
decide to retry the operation for whatever reason.

And hey, it's also possible that it makes no difference at all,
because your load mainly tests the exclusive "lock_page()" case, which
won't have changed.

And that's all assuming they don't show some instability, of course.
But the code actually seems fairly simple now, and the basic
synchronization hasn't changed, just a behavioral optimization.

Famous last words.

   Linus


Re: [PATCH v5 1/6] kprobes: Remove dependency to the module_mutex

2020-07-24 Thread Jarkko Sakkinen
On Fri, Jul 24, 2020 at 11:46:31PM +0900, Masami Hiramatsu wrote:
> On Fri, 24 Jul 2020 08:05:48 +0300
> Jarkko Sakkinen  wrote:
> 
> > Add lock_modules() and unlock_modules() wrappers for acquiring module_mutex
> > in order to remove the compile time dependency to it.
> 
> This subject is a bit confusing. This is just wrapping modules_mutex in
> kpprobes. We still have compile time dependency, e.g. module_state, right?

Yes. This more like a preliminary change to make that happen. The
actual flagging is in 6/6 ("Remove CONFIG_MODULE dependency").

Maybe a better angle would be to make this update all sites that
deal with module_mutex [*] and base the whole rationale on that?

[*] https://lore.kernel.org/lkml/20200725024227.gd17...@linux.intel.com/

/Jarkko


Re: [PATCH] scsi: imm: Remove superfluous breaks

2020-07-24 Thread Martin K. Petersen
On Tue, 14 Jul 2020 18:59:27 +0800, Yi Wang wrote:

> Remove superfluous breaks, as there is a "return" before them.

Applied to 5.9/scsi-queue, thanks!

[1/1] scsi: imm: Remove superfluous breaks
  https://git.kernel.org/mkp/scsi/c/b54dc46cbe71

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH] scsi: libsas: remove redundant assignment to variable res

2020-07-24 Thread Martin K. Petersen
On Wed, 22 Jul 2020 16:44:04 +0100, Colin King wrote:

> The variable res is being initialized with a value that is
> never read and it is being updated later with a new value. The
> initialization is redundant and can be removed.

Applied to 5.9/scsi-queue, thanks!

[1/1] scsi: libsas: Remove redundant assignment to variable res
  https://git.kernel.org/mkp/scsi/c/55eb809f5e1c

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH] scsi/mesh: Fix panic after host or bus reset

2020-07-24 Thread Martin K. Petersen
On Thu, 23 Jul 2020 09:25:51 +1000, Finn Thain wrote:

> Booting Linux with a Conner CP3200 drive attached to the MESH SCSI bus
> results in EH measures and a panic:
> 
> [   25.499838] mesh: configured for synchronous 5 MB/s
> [   25.787154] mesh: performing initial bus reset...
> [   29.867115] scsi host0: MESH
> [   29.929527] mesh: target 0 synchronous at 3.6 MB/s
> [   29.998763] scsi 0:0:0:0: Direct-Access CONNER   CP3200-200mb-3.5 4040 
> PQ: 0 ANSI: 1 CCS
> [   31.989975] sd 0:0:0:0: [sda] 415872 512-byte logical blocks: (213 MB/203 
> MiB)
> [   32.070975] sd 0:0:0:0: [sda] Write Protect is off
> [   32.137197] sd 0:0:0:0: [sda] Mode Sense: 5b 00 00 08
> [   32.209661] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, 
> doesn't support DPO or FUA
> [   32.332708]  sda: [mac] sda1 sda2 sda3
> [   32.417733] sd 0:0:0:0: [sda] Attached SCSI disk
> ... snip ...
> [   76.687067] mesh_abort((ptrval))
> [   76.743606] mesh: state at (ptrval), regs at (ptrval), dma at (ptrval)
> [   76.810798] ct=6000 seq=86 bs=4017 fc= 0 exc= 0 err= 0 im= 7 int= 0 
> sp=85
> [   76.880720] dma stat=84e0 cmdptr=1f73d000
> [   76.941387] phase=4 msgphase=0 conn_tgt=0 data_ptr=24576
> [   77.005567] dma_st=1 dma_ct=0 n_msgout=0
> [   77.065456] target 0: req=(ptrval) goes_out=0 saved_ptr=0
> [   77.130512] mesh_abort((ptrval))
> [   77.187670] mesh: state at (ptrval), regs at (ptrval), dma at (ptrval)
> [   77.255594] ct=6000 seq=86 bs=4017 fc= 0 exc= 0 err= 0 im= 7 int= 0 
> sp=85
> [   77.325778] dma stat=84e0 cmdptr=1f73d000
> [   77.387239] phase=4 msgphase=0 conn_tgt=0 data_ptr=24576
> [   77.453665] dma_st=1 dma_ct=0 n_msgout=0
> [   77.515900] target 0: req=(ptrval) goes_out=0 saved_ptr=0
> [   77.582902] mesh_host_reset
> [   88.187083] Kernel panic - not syncing: mesh: double DMA start !
> [   88.254510] CPU: 0 PID: 358 Comm: scsi_eh_0 Not tainted 5.6.13-pmac #1
> [   88.323302] Call Trace:
> [   88.378854] [e16ddc58] [c0027080] panic+0x13c/0x308 (unreliable)
> [   88.446221] [e16ddcb8] [c02b2478] mesh_start.part.12+0x130/0x414
> [   88.513298] [e16ddcf8] [c02b2fc8] mesh_queue+0x54/0x70
> [   88.577097] [e16ddd18] [c02a1848] scsi_send_eh_cmnd+0x374/0x384
> [   88.643476] [e16dddc8] [c02a1938] scsi_eh_tur+0x5c/0xb8
> [   88.707878] [e16dddf8] [c02a1ab8] scsi_eh_test_devices+0x124/0x178
> [   88.775663] [e16dde28] [c02a2094] scsi_eh_ready_devs+0x588/0x8a8
> [   88.843124] [e16dde98] [c02a31d8] scsi_error_handler+0x344/0x520
> [   88.910697] [e16ddf08] [c00409c8] kthread+0xe4/0xe8
> [   88.975166] [e16ddf38] [c000f234] ret_from_kernel_thread+0x14/0x1c
> [   89.044112] Rebooting in 180 seconds..
> 
> [...]

Applied to 5.9/scsi-queue, thanks!

[1/1] scsi: mesh: Fix panic after host or bus reset
  https://git.kernel.org/mkp/scsi/c/edd7dd2292ab

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH] scsi: isci: remove redundant initialization of variable status

2020-07-24 Thread Martin K. Petersen
On Thu, 23 Jul 2020 15:26:14 +0100, Colin King wrote:

> The variable status is being initialized with a value that is never read
> and it is being updated later with a new value.  The initialization is
> redundant and can be removed.

Applied to 5.9/scsi-queue, thanks!

[1/1] scsi: isci: Remove redundant initialization of variable 'status'
  https://git.kernel.org/mkp/scsi/c/584d902eb10e

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH] scsi: fcoe: use eth_zero_addr() to clear mac address

2020-07-24 Thread Martin K. Petersen
On Mon, 20 Jul 2020 16:39:04 +0800, linmiaohe wrote:

> Use eth_zero_addr() to clear mac address insetad of memset().

Applied to 5.9/scsi-queue, thanks!

[1/1] scsi: fcoe: Use eth_zero_addr() to clear mac address
  https://git.kernel.org/mkp/scsi/c/e2289db1ccc6

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH -next] scsi: dpt_i2o: remove some not needed memset

2020-07-24 Thread Martin K. Petersen
On Sat, 18 Jul 2020 20:32:24 +0800, Wang Hai wrote:

> Fixes coccicheck warning:
> 
> ./drivers/scsi/dpt_i2o.c:3070:11-29: WARNING:
>  dma_alloc_coherent use in sys_tbl already zeroes out memory, so memset is 
> not needed
> ./drivers/scsi/dpt_i2o.c:2780:10-28: WARNING:
>  dma_alloc_coherent use in status already zeroes out memory, so memset is not 
> needed
> ./drivers/scsi/dpt_i2o.c:2834:20-38: WARNING:
>  dma_alloc_coherent use in pHba -> reply_pool already zeroes out memory, so 
> memset is not needed
> ./drivers/scsi/dpt_i2o.c:1328:10-28: WARNING:
>  dma_alloc_coherent use in status already zeroes out memory, so memset is not 
> needed

Applied to 5.9/scsi-queue, thanks!

[1/1] scsi: dpt_i2o: Remove superfluous memset()
  https://git.kernel.org/mkp/scsi/c/003015b890e1

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH] scsi: fnic: use eth_broadcast_addr() to assign broadcast address

2020-07-24 Thread Martin K. Petersen
On Mon, 20 Jul 2020 16:24:58 +0800, linmiaohe wrote:

> Use eth_broadcast_addr() to assign broadcast address insetad of memset().

Applied to 5.9/scsi-queue, thanks!

[1/1] scsi: fnic: Use eth_broadcast_addr() to assign broadcast address
  https://git.kernel.org/mkp/scsi/c/51d263cbdd76

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH v2 4/4] xen: add helpers to allocate unpopulated memory

2020-07-24 Thread kernel test robot
Hi Roger,

Thank you for the patch! Yet something to improve:

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

url:
https://github.com/0day-ci/linux/commits/Roger-Pau-Monne/xen-balloon-fixes-for-memory-hotplug/20200724-204452
base:   https://git.kernel.org/pub/scm/linux/kernel/git/xen/tip.git linux-next
config: x86_64-allyesconfig (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 
1d09ecf36175f7910ffedd6d497c07b5c74c22fb)
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 x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

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

All errors (new ones prefixed by >>):

>> drivers/gpu/drm/xen/xen_drm_front_gem.c:102:9: error: implicit declaration 
>> of function 'xen_alloc_unpopulated_pages' 
>> [-Werror,-Wimplicit-function-declaration]
   ret = xen_alloc_unpopulated_pages(xen_obj->num_pages,
 ^
>> drivers/gpu/drm/xen/xen_drm_front_gem.c:155:5: error: implicit declaration 
>> of function 'xen_free_unpopulated_pages' 
>> [-Werror,-Wimplicit-function-declaration]
   
xen_free_unpopulated_pages(xen_obj->num_pages,
   ^
   2 errors generated.

vim +/xen_alloc_unpopulated_pages +102 drivers/gpu/drm/xen/xen_drm_front_gem.c

77  
78  static struct xen_gem_object *gem_create(struct drm_device *dev, size_t 
size)
79  {
80  struct xen_drm_front_drm_info *drm_info = dev->dev_private;
81  struct xen_gem_object *xen_obj;
82  int ret;
83  
84  size = round_up(size, PAGE_SIZE);
85  xen_obj = gem_create_obj(dev, size);
86  if (IS_ERR_OR_NULL(xen_obj))
87  return xen_obj;
88  
89  if (drm_info->front_info->cfg.be_alloc) {
90  /*
91   * backend will allocate space for this buffer, so
92   * only allocate array of pointers to pages
93   */
94  ret = gem_alloc_pages_array(xen_obj, size);
95  if (ret < 0)
96  goto fail;
97  
98  /*
99   * allocate ballooned pages which will be used to map
   100   * grant references provided by the backend
   101   */
 > 102  ret = xen_alloc_unpopulated_pages(xen_obj->num_pages,
   103xen_obj->pages);
   104  if (ret < 0) {
   105  DRM_ERROR("Cannot allocate %zu ballooned pages: 
%d\n",
   106xen_obj->num_pages, ret);
   107  gem_free_pages_array(xen_obj);
   108  goto fail;
   109  }
   110  
   111  xen_obj->be_alloc = true;
   112  return xen_obj;
   113  }
   114  /*
   115   * need to allocate backing pages now, so we can share those
   116   * with the backend
   117   */
   118  xen_obj->num_pages = DIV_ROUND_UP(size, PAGE_SIZE);
   119  xen_obj->pages = drm_gem_get_pages(&xen_obj->base);
   120  if (IS_ERR_OR_NULL(xen_obj->pages)) {
   121  ret = PTR_ERR(xen_obj->pages);
   122  xen_obj->pages = NULL;
   123  goto fail;
   124  }
   125  
   126  return xen_obj;
   127  
   128  fail:
   129  DRM_ERROR("Failed to allocate buffer with size %zu\n", size);
   130  return ERR_PTR(ret);
   131  }
   132  
   133  struct drm_gem_object *xen_drm_front_gem_create(struct drm_device *dev,
   134  size_t size)
   135  {
   136  struct xen_gem_object *xen_obj;
   137  
   138  xen_obj = gem_create(dev, size);
   139  if (IS_ERR_OR_NULL(xen_obj))
   140  return ERR_CAST(xen_obj);
   141  
   142  return &xen_obj->base;
   143  }
   144  
   145  void xen_drm_front_gem_free_object_unlocked(struct drm_gem_o

Re: [PATCH v1 0/2] scsi: libsas: An improvement on error handle and tidy-up

2020-07-24 Thread Martin K. Petersen
On Wed, 22 Jul 2020 17:04:01 +0800, Luo Jiaxing wrote:

> This patch introduces an improvement to reduce error handle time and a
> tidy-up, including:
> - postreset() is deleted from sas_sata_ops.
> - Do not perform hard reset and delayed retry on a removed SATA disk. This
> can effectively reduce the error handle duration of hot unplug a SATA disk
> with traffic(reduce about 30s depending on the delay setting of libata).
> 
> [...]

Applied to 5.9/scsi-queue, thanks!

[1/2] scsi: libsas: Remove postreset from sas_sata_ops
  https://git.kernel.org/mkp/scsi/c/3a243c2c3500
[2/2] scsi: libsas: Check link status in ATA prereset()
  https://git.kernel.org/mkp/scsi/c/386533796574

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH] scsi: ppa: Remove superfluous breaks

2020-07-24 Thread Martin K. Petersen
On Tue, 14 Jul 2020 18:59:31 +0800, Yi Wang wrote:

> Remove superfluous breaks, as there is a "return" before them.

Applied to 5.9/scsi-queue, thanks!

[1/1] scsi: ppa: Remove superfluous breaks
  https://git.kernel.org/mkp/scsi/c/6671eebd672c

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH -next] scsi: lpfc: Add dependency on CPU_FREQ

2020-07-24 Thread Martin K. Petersen
On Tue, 21 Jul 2020 19:30:27 -0700, Guenter Roeck wrote:

> Since commit 317aeb83c92b ("scsi: lpfc: Add blk_io_poll support for
> latency improvment"), the lpfc driver depends on CPUFREQ. Without it,
> builds fail with
> 
> drivers/scsi/lpfc/lpfc_sli.c: In function 'lpfc_init_idle_stat_hb':
> drivers/scsi/lpfc/lpfc_sli.c:7329:26: error:
>   implicit declaration of function 'get_cpu_idle_time'
> 
> [...]

Applied to 5.9/scsi-queue, thanks!

[1/1] scsi: lpfc: Add dependency on CPU_FREQ
  https://git.kernel.org/mkp/scsi/c/e3d2bf6505dd

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH] net: cdc_ncm: USB_NET_CDC_NCM selects USB_NET_CDCETHER

2020-07-24 Thread David Miller
From: t...@redhat.com
Date: Thu, 23 Jul 2020 07:22:10 -0700

> From: Tom Rix 
> 
> A link error
> 
> ld: drivers/net/usb/cdc_ncm.o:
>   undefined reference to `usbnet_cdc_update_filter'
> 
> usbnet_cdc_update_filter is defined in cdc_ether.c
> Building of cdc_ether.o is controlled by USB_NET_CDCETHER
> 
> Building of cdc_ncm.o is controlled by USB_NET_CDC_NCM
> 
> So add a select USB_NET_CDCETHER to USB_NET_CDC_NCM
> 
> Signed-off-by: Tom Rix 

Please indicate the appropriate target tree ('net' or 'net-next') in
your Subject line f.e. "[PATCH net-next] ..."

Please provide an appropriate and properly formatted Fixes: tag.

Thank you.


[PATCH] RDMA/core: fix return error value to negative

2020-07-24 Thread Li Heng
Fixes: 8d9ec9addd6c (IB/core: Add a sgid_attr pointer to struct rdma_ah_attr)
Reported-by: Hulk Robot 
Signed-off-by: Li Heng 
---
 drivers/infiniband/core/verbs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
index 53d6505c..f369f0a 100644
--- a/drivers/infiniband/core/verbs.c
+++ b/drivers/infiniband/core/verbs.c
@@ -1712,7 +1712,7 @@ static int _ib_modify_qp(struct ib_qp *qp, struct 
ib_qp_attr *attr,
if (!(rdma_protocol_ib(qp->device,
   attr->alt_ah_attr.port_num) &&
  rdma_protocol_ib(qp->device, port))) {
-   ret = EINVAL;
+   ret = -EINVAL;
goto out;
}
}
-- 
2.7.4



Re: [PATCH 00/40] Set 4: Next set of SCSI related W=1 warnings

2020-07-24 Thread Martin K. Petersen
On Tue, 21 Jul 2020 17:41:08 +0100, Lee Jones wrote:

> This set is part of a larger effort attempting to clean-up W=1
> kernel builds, which are currently overwhelmingly riddled with
> niggly little warnings.
> 
> This brings the total of W=1 SCSI wanings from 1690 in v5.8-rc1 to 817.
> 
> Lee Jones (40):
>   scsi: arcmsr: arcmsr_hba: Remove statement with no effect
>   scsi: aic7xxx: aic79xx_core: Remove a bunch of unused variables
>   scsi: aacraid: sa: Add descriptions for missing parameters
>   scsi: aacraid: rkt: Add missing description for 'dev'
>   scsi: aacraid: nark: Add missing description for 'dev'
>   scsi: aic94xx: aic94xx_dev: Fix a couple of kerneldoc formatting
> issues
>   scsi: aacraid: src: Add descriptions for missing parameters
>   scsi: aic94xx: aic94xx_tmf: Fix kerneldoc formatting issue with 'task'
>   scsi: pm8001: pm8001_sas: Fix strncpy() warning
>   scsi: pm8001: pm8001_sas: Mover function header and supply some
> missing parameter descriptions
>   scsi: pm8001: pm8001_ctl: Add descriptions for unused 'attr' function
> parameters
>   scsi: qla4xxx: ql4_init: Remove set but unused variable 'func_number'
>   scsi: qla4xxx: ql4_init: Check return value of pci_set_mwi()
>   scsi: qla4xxx: ql4_83xx: Move 'qla4_83xx_reg_tbl' from shared header
>   scsi: aic7xxx: aic79xx_core: Remove set but unused variables
> 'targ_info' and 'value'
>   scsi: pm8001: pm8001_hwi: Fix a bunch of kerneldoc issues
>   scsi: pm8001: pm80xx_hwi: Fix some function documentation issues
>   scsi: pm8001: pm8001_hwi: Remove a bunch of set but unused variables
>   scsi: qla4xxx: ql4_nx: Move 'qla4_82xx_reg_tbl' to the only place its
> used
>   scsi: lpfc: lpfc_sli: Remove unused variable 'pg_addr'
>   scsi: qla4xxx: ql4_mbx: Fix-up incorrectly documented parameter
>   scsi: qla4xxx: ql4_iocb: Fix incorrectly named function parameter
>   scsi: lpfc: lpfc_sli: Fix-up around 120 documentation issues
>   scsi: pm8001: pm8001_hwi: Remove unused variable 'value'
>   scsi: pm8001: pm80xx_hwi: Staticify 'pm80xx_pci_mem_copy' and
> 'mpi_set_phy_profile_req'
>   scsi: qla4xxx: ql4_os: Fix some kerneldoc parameter documentation
> issues
>   scsi: qla4xxx: ql4_isr: Repair function documentation headers
>   scsi: lpfc: lpfc_mem: Provide description for lpfc_mem_alloc()'s
> 'align' param
>   scsi: qla4xxx: ql4_init: Document qla4xxx_process_ddb()'s 'conn_err'
>   scsi: lpfc: lpfc_ct: Fix-up formatting/docrot where appropriate
>   scsi: csiostor: csio_init: Fix misnamed function parameter
>   scsi: qla4xxx: ql4_nx: Remove three set but unused variables
>   scsi: qla4xxx: ql4_nx: Supply description for 'code'
>   scsi: csiostor: csio_lnode: Demote kerneldoc that fails to meet the
> criteria
>   scsi: bfa: bfad_bsg: Staticify all local functions
>   scsi: lpfc: lpfc_sli: Ensure variable has the same stipulations as
> code using it
>   scsi: sym53c8xx_2: sym_glue: Add missing description for 'pdev'
>   scsi: sym53c8xx_2: sym_hipd: Ensure variable has the same stipulations
> as code using it
>   scsi: mvsas: mv_init: Move 'core_nr' inside #ifdef and remove unused
> variable 'res_flag'
>   scsi: cxgbi: cxgb3i: cxgb3i: Remove bad documentation and demote
> kerneldoc header
> 
> [...]

Applied to 5.9/scsi-next, thanks!

[01/40] scsi: arcmsr: arcmsr_hba: Remove statement with no effect
https://git.kernel.org/mkp/scsi/c/7c7ef829ad08
[02/40] scsi: aic7xxx: aic79xx_core: Remove a bunch of unused variables
https://git.kernel.org/mkp/scsi/c/84dc1a1d5459
[03/40] scsi: aacraid: Add descriptions for missing parameters
https://git.kernel.org/mkp/scsi/c/baef36891460
[04/40] scsi: aacraid: Add missing description for 'dev'
https://git.kernel.org/mkp/scsi/c/3c4538f80b09
[05/40] scsi: aacraid: Add missing description for 'dev'
https://git.kernel.org/mkp/scsi/c/5d9d46b93d0a
[06/40] scsi: aic94xx: Fix a couple of kerneldoc formatting issues
https://git.kernel.org/mkp/scsi/c/ee37a6e6d2a1
[07/40] scsi: aacraid: Add descriptions for missing parameters
https://git.kernel.org/mkp/scsi/c/a13689118f63
[08/40] scsi: aic94xx: Fix kerneldoc formatting issue with 'task'
https://git.kernel.org/mkp/scsi/c/45c21cec3867
[10/40] scsi: pm8001: Move function header and supply some missing parameter 
descriptions
https://git.kernel.org/mkp/scsi/c/a0cf5ce40d12
[11/40] scsi: pm8001: Add descriptions for unused 'attr' function parameters
https://git.kernel.org/mkp/scsi/c/cd2eebfd4028
[12/40] scsi: qla4xxx: Remove set but unused variable 'func_number'
https://git.kernel.org/mkp/scsi/c/4c2de9c54112
[13/40] scsi: qla4xxx: Check return value of pci_set_mwi()
https://git.kernel.org/mkp/scsi/c/b854460053ec
[14/40] scsi: qla4xxx: Move 'qla4_83xx_reg_tbl' from shared header
https://git.kernel.org/mkp/scsi/c/3ca2c203ed99
[15/40] scsi: aic7xxx: Remove set but unused variables 'targ_info' and 'value'
https://git.kernel.

Re: [PATCH 00/40] Set 5: Penultimate set of SCSI related W=1 warnings

2020-07-24 Thread Martin K. Petersen
On Thu, 23 Jul 2020 13:24:06 +0100, Lee Jones wrote:

> This set is part of a larger effort attempting to clean-up W=1
> kernel builds, which are currently overwhelmingly riddled with
> niggly little warnings.
> 
> Hopefully this is the penultimate set.
> 
> Lee Jones (40):
>   scsi: lpfc: lpfc_els: Fix some function parameter descriptions
>   scsi: lpfc: lpfc_hbadisc: Fix kerneldoc parameter
> formatting/misnaming/missing issues
>   scsi: ufs: ufs-qcom: Demote nonconformant kerneldoc headers
>   scsi: bnx2i: bnx2i_init: Fix parameter misnaming in function header
>   scsi: ufs: ufs-exynos: Make stubs 'static inline'
>   scsi: ufs: ufs-exynos: Demote seemingly unintentional kerneldoc header
>   scsi: bfa: bfa_port: Staticify local functions
>   scsi: bnx2i: bnx2i_sysfs: Add missing descriptions for 'attr'
> parameter
>   scsi: bfa: bfa_fcpim: Remove set but unused variable 'rp'
>   scsi: bfa: bfa_fcpim: Demote seemingly unintentional kerneldoc header
>   scsi: qedi: qedi_main: Remove 2 set but unused variables
>   scsi: ips: Remove some set but unused variables
>   scsi: ips: Convert strnlen() to memcpy() since result should not be
> NUL terminated
>   scsi: qla4xxx: ql4_83xx: Remove set but unused variable 'status'
>   scsi: lpfc: lpfc_init: Use __printf() format notation
>   scsi: lpfc: lpfc_init: Add and rename a whole bunch of function
> parameter descriptions
>   scsi: qla4xxx: ql4_bsg: Rename function parameter descriptions
>   scsi: lpfc: lpfc_mbox: Fix a bunch of kerneldoc misdemeanours
>   scsi: lpfc: lpfc_nportdisc: Add description for lpfc_release_rpi()'s
> 'ndlpl param
>   scsi: bfa: bfa_ioc: Remove a few unused variables 'pgoff' and 't'
>   scsi: csiostor: csio_hw: Mark known unused variable as __always_unused
>   scsi: csiostor: csio_hw_t5: Remove 2 unused variables
> {mc,edc}_bist_status_rdata_reg
>   scsi: bfa: bfa_ioc: Staticify non-external functions
>   scsi: csiostor: csio_rnode: Add missing description for
> csio_rnode_fwevt_handler()'s 'fwevt' param
>   scsi: bfa: bfa_ioc_ct: Demote non-compliant kerneldoc headers to
> standard comments
>   scsi: mvsas: mv_init: Place 'core_nr' inside correct clause
>   scsi: bfa: bfa_fcs_rport: Remove unused variable 'adisc'
>   scsi: bnx2i: bnx2i_hwi: Fix a whole host of kerneldoc issues
>   scsi: bnx2i: bnx2i_iscsi: Add, remove and edit some function parameter
> descriptions
>   scsi: be2iscsi: be_iscsi: Correct misdocumentation of function param
> 'ep'
>   scsi: qedi: qedi_fw: Remove set but unused variable 'tmp'
>   scsi: esas2r: esas2r: Add braces around the one-line if()
>   scsi: bfa: bfa_ioc: Demote non-kerneldoc headers down to standard
> comment blocks
>   scsi: bfa: bfa_core: Demote seemingly unintentional kerneldoc header
>   scsi: bfa: bfa_svc: Demote seemingly unintentional kerneldoc header
>   scsi: qedi: qedi_main: Demote seemingly unintentional kerneldoc header
>   scsi: qedi: qedi_iscsi: Staticify non-external function
> 'qedi_get_iscsi_error'
>   scsi: bfa: bfa_ioc: Ensure a blank line precedes next function/header
>   scsi: bnx2i: bnx2i_iscsi: Add parameter description and rename another
>   scsi: esas2r: esas2r_log: Demote a few non-conformant kerneldoc
> headers
> 
> [...]

Applied to 5.9/scsi-next, thanks!

[01/40] scsi: lpfc: Fix some function parameter descriptions
https://git.kernel.org/mkp/scsi/c/a0e4a64f8650
[02/40] scsi: lpfc: Fix kerneldoc parameter formatting/misnaming/missing issues
https://git.kernel.org/mkp/scsi/c/e415f2a2acd9
[03/40] scsi: ufs: ufs-qcom: Demote nonconformant kerneldoc headers
https://git.kernel.org/mkp/scsi/c/bc5b681614cc
[04/40] scsi: bnx2i: Fix parameter misnaming in function header
https://git.kernel.org/mkp/scsi/c/b4688a7e01e5
[06/40] scsi: ufs: ufs-exynos: Demote seemingly unintentional kerneldoc header
https://git.kernel.org/mkp/scsi/c/b44cc4a40bd6
[07/40] scsi: bfa: Staticify local functions
https://git.kernel.org/mkp/scsi/c/004a7a79
[08/40] scsi: bnx2i: Add missing descriptions for 'attr' parameter
https://git.kernel.org/mkp/scsi/c/2ad6e0c339d2
[09/40] scsi: bfa: Remove set but unused variable 'rp'
https://git.kernel.org/mkp/scsi/c/70b4de0bb928
[10/40] scsi: bfa: Demote seemingly unintentional kerneldoc header
https://git.kernel.org/mkp/scsi/c/7106de1d8a75
[11/40] scsi: qedi: Remove 2 set but unused variables
https://git.kernel.org/mkp/scsi/c/e4020e0835ed
[12/40] scsi: ips: Remove some set but unused variables
https://git.kernel.org/mkp/scsi/c/ffe1757e45aa
[13/40] scsi: ips: Convert strnlen() to memcpy() since result should not be NUL 
terminated
https://git.kernel.org/mkp/scsi/c/00e245655e75
[14/40] scsi: qla4xxx: Remove set but unused variable 'status'
https://git.kernel.org/mkp/scsi/c/6e3f4f68821b
[15/40] scsi: lpfc: Use __printf() format notation
https://git.kernel.org/mkp/scsi/c/7fa03c77cd54
[16/40] scsi: lpfc: Add and ren

Re: [PATCH v5 1/6] kprobes: Remove dependency to the module_mutex

2020-07-24 Thread Jarkko Sakkinen
On Fri, Jul 24, 2020 at 11:17:11AM +0200, Ingo Molnar wrote:
> 
> * Jarkko Sakkinen  wrote:
> 
> > --- a/kernel/kprobes.c
> > +++ b/kernel/kprobes.c
> > @@ -564,7 +564,7 @@ static void kprobe_optimizer(struct work_struct *work)
> > cpus_read_lock();
> > mutex_lock(&text_mutex);
> > /* Lock modules while optimizing kprobes */
> > -   mutex_lock(&module_mutex);
> > +   lock_modules();
> >  
> > /*
> >  * Step 1: Unoptimize kprobes and collect cleaned (unused and disarmed)
> > @@ -589,7 +589,7 @@ static void kprobe_optimizer(struct work_struct *work)
> > /* Step 4: Free cleaned kprobes after quiesence period */
> > do_free_cleaned_kprobes();
> >  
> > -   mutex_unlock(&module_mutex);
> > +   unlock_modules();
> > mutex_unlock(&text_mutex);
> > cpus_read_unlock();
> 
> BTW., it would be nice to expand on the comments above - exactly which 
> parts of the modules code is being serialized against and why?
> 
> We already hold the text_mutex here, which should protect against most 
> kprobes related activities interfering - and it's unclear (to me) 
> which part of the modules code is being serialized with here, and the 
> 'lock modules while optimizing kprobes' comments is unhelpful. :-)
> 
> Thanks,
> 
>   Ingo

AFAIK, only if you need to call find_module(), you ever need to acquire
this mutex. 99% of time it is internally taken care by kernel/module.c.

I cannot make up any obvious reason to acquire it here.

/Jarkko


Re: [PATCH v3 5/6] powerpc/pseries: implement paravirt qspinlocks for SPLPAR

2020-07-24 Thread Waiman Long

On 7/24/20 3:10 PM, Waiman Long wrote:

On 7/24/20 4:16 AM, Will Deacon wrote:

On Thu, Jul 23, 2020 at 08:47:59PM +0200, pet...@infradead.org wrote:

On Thu, Jul 23, 2020 at 02:32:36PM -0400, Waiman Long wrote:
BTW, do you have any comment on my v2 lock holder cpu info 
qspinlock patch?
I will have to update the patch to fix the reported 0-day test 
problem, but

I want to collect other feedback before sending out v3.

I want to say I hate it all, it adds instructions to a path we spend an
aweful lot of time optimizing without really getting anything back for
it.

Will, how do you feel about it?

I can see it potentially being useful for debugging, but I hate the
limitation to 256 CPUs. Even arm64 is hitting that now.


After thinking more about that, I think we can use all the remaining 
bits in the 16-bit locked_pending. Reserving 1 bit for locked and 1 
bit for pending, there are 14 bits left. So as long as NR_CPUS < 16k 
(requirement for 16-bit locked_pending), we can put all possible cpu 
numbers into the lock. We can also just use smp_processor_id() without 
additional percpu data. 


Sorry, that doesn't work. The extra bits in the pending byte won't get 
cleared on unlock. That will have noticeable performance impact. 
Clearing the pending byte on unlock will cause other performance 
problem. So I guess we will have to limit the cpu number in the locked byte.


Regards,
Longman



Re: [PATCH v2 0/3] net: dsa: mv88e6xxx: port mtu support

2020-07-24 Thread David Miller
From: Chris Packham 
Date: Fri, 24 Jul 2020 11:21:19 +1200

> This series connects up the mv88e6xxx switches to the dsa infrastructure for
> configuring the port MTU. The first patch is also a bug fix which might be a
> candiatate for stable.
> 
> I've rebased this series on top of net-next/master to pick up Andrew's change
> for the gigabit switches. Patch 1 and 2 are unchanged (aside from adding
> Andrew's Reviewed-by). Patch 3 is reworked to make use of the existing mtu
> support.

Series applied, thanks Chris.


Re: [PATCH] amdgpu_dm: fix nonblocking atomic commit use-after-free

2020-07-24 Thread Mazin Rezk
On Friday, July 24, 2020 5:19 PM, Paul Menzel  wrote:

> Dear Kees,
>
> Am 24.07.20 um 19:33 schrieb Kees Cook:
>
> > On Fri, Jul 24, 2020 at 09:45:18AM +0200, Paul Menzel wrote:
> >
> > > Am 24.07.20 um 00:32 schrieb Kees Cook:
> > >
> > > > On Thu, Jul 23, 2020 at 09:10:15PM +, Mazin Rezk wrote:
> > > > As Linux 5.8-rc7 is going to be released this Sunday, I wonder, if 
> > > > commit
> > > > 3202fa62f ("slub: relocate freelist pointer to middle of object") 
> > > > should be
> > > > reverted for now to fix the regression for the users according to 
> > > > Linux’ no
> > > > regression policy. Once the AMDGPU/DRM driver issue is fixed, it can be
> > > > reapplied. I know it’s not optimal, but as some testing is going to be
> > > > involved for the fix, I’d argue it’s the best option for the users.
> >
> > Well, the SLUB defense was already released in v5.7, so I'm not sure it
> > really helps for amdgpu_dm users seeing it there too.
>
> In my opinion, it would help, as the stable release could pick up the
> revert, ones it’s in Linus’ master branch.
>
> > There was a fix to disable the async path for this driver that worked
> > around the bug too, yes? That seems like a safer and more focused
> > change that doesn't revert the SLUB defense for all users, and would
> > actually provide a complete, I think, workaround whereas reverting
> > the SLUB change means the race still exists. For example, it would be
> > hit with slab poisoning, etc.
>
> I do not know. If there is such a fix, that would be great. But if you
> do not know, how should a normal user? ;-)
>
> Kind regards,
>
> Paul
>
> Kind regards,
>
> Paul

If we're talking about workarounds now, I suggest simply swapping the base
and context variables in struct dm_atomic_state. By that way, we won't need
to change non-amdgpu parts of the code (e.g. by reverting the SLUB patch).

Prior to 3202fa62f, the freelist pointer was stored in dm_state->base which
was never dereferenced and therefore caused no noticeable issue. After
3202fa62f, the freelist pointer is stored in the middle of the struct (i.e.
dm_state->context).

Swapping the position of the base and context variables in dm_atomic_state
should, in theory, revert this code back to it's pre-5.7 state since the
code would be back to overwriting base instead.

If we decide to use this workaround, I can write the patch and do more
extended tests to confirm it works around the issues.

That said, I haven't seen the async disabling patch. If you could link to
it, I'd be glad to test it out and perhaps we can use that instead.

Thanks,
Mazin Rezk



[PATCH] svc: add missed destroy_workqueue when gb_svc_create fails

2020-07-24 Thread Li Heng
destroy_workqueue() should be called to destroy svc->wq
when gb_svc_create() init resources fails.

Fixes: 8465def499c7 ("staging: greybus: move the greybus core to 
drivers/greybus")
Reported-by: Hulk Robot 
Signed-off-by: Li Heng 
---
 drivers/greybus/svc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/greybus/svc.c b/drivers/greybus/svc.c
index ce7740e..38f858f 100644
--- a/drivers/greybus/svc.c
+++ b/drivers/greybus/svc.c
@@ -1340,6 +1340,7 @@ struct gb_svc *gb_svc_create(struct gb_host_device *hd)
 
 err_put_device:
put_device(&svc->dev);
+   destroy_workqueue(svc->wq);
return NULL;
 }
 
-- 
2.7.4



Re: [QUESTION] Sharing a `struct page` across multiple `struct address_space` instances

2020-07-24 Thread Matthew Wilcox
On Fri, Jul 24, 2020 at 05:22:21PM -0700, Vito Caputo wrote:
> Prior to looking at the code, conceptually I was envisioning the pages
> in the reflink source inode's address_space would simply get their
> refcounts bumped as they were added to the dest inode's address_space,
> with some CoW flag set to prevent writes.
> 
> But there seems to be a fundamental assumption that a `struct page`
> would only belong to a single `struct address_space` at a time, as it
> has single `mapping` and `index` members for reverse mapping the page
> to its address_space.
> 
> Am I completely lost here or does it really look like a rather
> invasive modification to support this feature?
> 
> I have vague memories of Dave Chinner mentioning work towards sharing
> pages across address spaces in the interests of getting reflink copies
> more competitive with overlayfs in terms of page cache utilization.

It's invasive.  Dave and I have chatted about this in the past.  I've done
no work towards it (... a little busy right now with THPs in the page
cache ...) but I have a design in mind.

The fundamental idea is to use the DAX support to refer to pages which
actually belong to a separate address space.  DAX entries are effectively
PFN entries.  So there would be a clear distinction between "I looked
up a page which actually belongs to this address space" and "I looked
up a page which is shared with a different address space".  My thinking
has been that if files A and B are reflinked, both A and B would see
DAX entries in their respective page caches.  The page would belong to
a third address space which might be the block device's address space,
or maybe there would be an address space per shared fragment (since
files can share fragments that are at different offsets from each other).

There are a lot of details to get right around this approach.
Importantly, there _shouldn't_ be a refcount from each of file A and
B on the page.  Instead the refcount from files A and B should be on
the fragment.  When the fragment's refcount goes to zero, we know there
are no more references to the fragment and all its pages can be freed.

That means that if we reflink B to C, we don't have to walk every page
in the file and increase its refcount again.

So, are you prepared to do a lot of work, or were you thinking this
would be a quick hack?  Because I'm willing to advise on a big project,
but if you're thinking this will be quick, and don't have time for a
big project, it's probably time to stop here.

---

Something that did occur to me while writing this is that if you just want
read-only duplicates of files to work, you could make inode->i_mapping
point to a different address_space instead of &inode->i_data.  There's
probabyl a quick hack solution there.


Re: [PATCH v5 0/4] Add USB PHY support for new Ingenic SoCs.

2020-07-24 Thread Zhou Yanjie

Hello Felipe,

在 2020/7/23 下午5:19, Felipe Balbi 写道:

周琰杰 (Zhou Yanjie)  writes:


1.separate the adjustments to the code style into
   a separate patch.
2.Modify the help message, make it more future-proof.
3.Drop the unnecessary comment about hardware reset.
4.Create 'soc_info' structures instead having ID_* as platform data.

For v5.10, make sure to move your phy driver to drivers/phy.


Sure, I will move it to drivers/phy in next version.

Thanks and best regards!



Re: [PATCH] drm/vkms: add missing drm_crtc_vblank_put to the get/put pair on flush

2020-07-24 Thread Sidong Yang
On Wed, Jul 22, 2020 at 05:17:05PM +0200, Daniel Vetter wrote:
> On Wed, Jul 22, 2020 at 4:06 PM Melissa Wen  wrote:
> >
> > On 07/22, dan...@ffwll.ch wrote:
> > > On Wed, Jul 22, 2020 at 08:04:11AM -0300, Melissa Wen wrote:
> > > > This patch adds a missing drm_crtc_vblank_put op to the pair
> > > > drm_crtc_vblank_get/put (inc/decrement counter to guarantee vblanks).
> > > >
> > > > It clears the execution of the following kms_cursor_crc subtests:
> > > > 1. pipe-A-cursor-[size,alpha-opaque, NxN-(on-screen, off-screen, 
> > > > sliding,
> > > >random, fast-moving])] - successful when running individually.
> > > > 2. pipe-A-cursor-dpms passes again
> > > > 3. pipe-A-cursor-suspend also passes
> > > >
> > > > The issue was initially tracked in the sequential execution of IGT
> > > > kms_cursor_crc subtest: when running the test sequence or one of its
> > > > subtests twice, the odd execs complete and the pairs get stuck in an
> > > > endless wait. In the IGT code, calling a wait_for_vblank before the 
> > > > start
> > > > of CRC capture prevented the busy-wait. But the problem persisted in the
> > > > pipe-A-cursor-dpms and -suspend subtests.
> > > >
> > > > Checking the history, the pipe-A-cursor-dpms subtest was successful 
> > > > when,
> > > > in vkms_atomic_commit_tail, instead of using the flip_done op, it used
> > > > wait_for_vblanks. Another way to prevent blocking was wait_one_vblank 
> > > > when
> > > > enabling crtc. However, in both cases, pipe-A-cursor-suspend persisted
> > > > blocking in the 2nd start of CRC capture, which may indicate that
> > > > something got stuck in the step of CRC setup. Indeed, wait_one_vblank in
> > > > the crc setup was able to sync things and free all kms_cursor_crc
> > > > subtests.
> > > >
> > > > Tracing and comparing a clean run with a blocked one:
> > > > - in a clean one, vkms_crtc_atomic_flush enables vblanks;
> > > > - when blocked, only in next op, vkms_crtc_atomic_enable, the vblanks
> > > > started. Moreover, a series of vkms_vblank_simulate flow out until
> > > > disabling vblanks.
> > > > Also watching the steps of vkms_crtc_atomic_flush, when the very first
> > > > drm_crtc_vblank_get returned an error, the subtest crashed. On the other
> > > > hand, when vblank_get succeeded, the subtest completed. Finally, 
> > > > checking
> > > > the flush steps: it increases counter to hold a vblank reference (get),
> > > > but there isn't a op to decreased it and release vblanks (put).
> > > >
> > > > Cc: Daniel Vetter 
> > > > Cc: Rodrigo Siqueira 
> > > > Cc: Haneen Mohammed 
> > > > Signed-off-by: Melissa Wen 
> > > > ---
> > > >  drivers/gpu/drm/vkms/vkms_crtc.c | 1 +
> > > >  1 file changed, 1 insertion(+)
> > > >
> > > > diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c 
> > > > b/drivers/gpu/drm/vkms/vkms_crtc.c
> > > > index ac85e17428f8..a99d6b4a92dd 100644
> > > > --- a/drivers/gpu/drm/vkms/vkms_crtc.c
> > > > +++ b/drivers/gpu/drm/vkms/vkms_crtc.c
> > > > @@ -246,6 +246,7 @@ static void vkms_crtc_atomic_flush(struct drm_crtc 
> > > > *crtc,
> > > >
> > > > spin_unlock(&crtc->dev->event_lock);
> > > >
> > > > +   drm_crtc_vblank_put(crtc);
> > >
> > > Uh so I reviewed this a bit more carefully now, and I dont think this is
> > > the correct bugfix. From the kerneldoc of drm_crtc_arm_vblank_event():
> > >
> > >  * Caller must hold a vblank reference for the event @e acquired by a
> > >  * drm_crtc_vblank_get(), which will be dropped when the next vblank 
> > > arrives.
> > >
> > > So when we call drm_crtc_arm_vblank_event then the vblank_put gets called
> > > for us. And that's the only case where we successfully acquired a vblank
> > > interrupt reference since on failure of drm_crtc_vblank_get (0 indicates
> > > success for that function, failure negative error number) we directly send
> > > out the event.
> > >
> > > So something else fishy is going on, and now I'm totally confused why this
> > > even happens.
> > >
> > > We also have a pile of WARN_ON checks in drm_crtc_vblank_put to make sure
> > > we don't underflow the refcount, so it's also not that I think (except if
> > > this patch creates more WARNING backtraces).
> > >
> > > But clearly it changes behaviour somehow ... can you try to figure out
> > > what changes? Maybe print out the vblank->refcount at various points in
> > > the driver, and maybe also trace when exactly the fake vkms vblank hrtimer
> > > is enabled/disabled ...
> >
> > :(
> >
> > I can check these, but I also have other suspicions. When I place the
> > drm_crct_vblank_put out of the if (at the end of flush), it not only solve
> > the issue of blocking on kms_cursor_crc, but also the WARN_ON on kms_flip
> > doesn't appear anymore (a total cleanup). Just after:
> >
> > vkms_output->composer_state = to_vkms_crtc_state(crtc->state);
> >
> > looks like there is something stuck around here.
> 
> Hm do you have the full WARNING for this? Maybe this gives me an idea
> what's going wrong.
> 
> > Besides, the

Re: [v7, PATCH 2/7] mtk-mmsys: add mmsys private data

2020-07-24 Thread Yongqiang Niu
On Sat, 2020-07-25 at 10:11 +0800, Chun-Kuang Hu wrote:
> Hi, Yongqiang:
> 
> Yongqiang Niu  於 2020年7月23日 週四 上午10:05寫道:
> >
> > add mmsys private data
> >
> > Feature: drm/mediatek
> > Signed-off-by: Yongqiang Niu 
> > ---
> >  drivers/soc/mediatek/Makefile |   1 +
> >  drivers/soc/mediatek/mmsys/Makefile   |   2 +
> >  drivers/soc/mediatek/mmsys/mt2701-mmsys.c | 250 +++
> >  drivers/soc/mediatek/mtk-mmsys.c  | 271 
> > +-
> >  include/linux/soc/mediatek/mtk-mmsys.h|  15 ++
> >  5 files changed, 314 insertions(+), 225 deletions(-)
> >  create mode 100644 drivers/soc/mediatek/mmsys/Makefile
> >  create mode 100644 drivers/soc/mediatek/mmsys/mt2701-mmsys.c
> >
> > diff --git a/drivers/soc/mediatek/Makefile b/drivers/soc/mediatek/Makefile
> > index 2afa7b9..b37ac2c 100644
> > --- a/drivers/soc/mediatek/Makefile
> > +++ b/drivers/soc/mediatek/Makefile
> > @@ -3,3 +3,4 @@ obj-$(CONFIG_MTK_CMDQ) += mtk-cmdq-helper.o
> >  obj-$(CONFIG_MTK_PMIC_WRAP) += mtk-pmic-wrap.o
> >  obj-$(CONFIG_MTK_SCPSYS) += mtk-scpsys.o
> >  obj-$(CONFIG_MTK_MMSYS) += mtk-mmsys.o
> > +obj-$(CONFIG_MTK_MMSYS) += mmsys/
> > diff --git a/drivers/soc/mediatek/mmsys/Makefile 
> > b/drivers/soc/mediatek/mmsys/Makefile
> > new file mode 100644
> > index 000..33b0dab
> > --- /dev/null
> > +++ b/drivers/soc/mediatek/mmsys/Makefile
> > @@ -0,0 +1,2 @@
> > +# SPDX-License-Identifier: GPL-2.0-only
> > +obj-y += mt2701-mmsys.o
> > diff --git a/drivers/soc/mediatek/mmsys/mt2701-mmsys.c 
> > b/drivers/soc/mediatek/mmsys/mt2701-mmsys.c
> > new file mode 100644
> > index 000..b8e53b0
> > --- /dev/null
> > +++ b/drivers/soc/mediatek/mmsys/mt2701-mmsys.c
> > @@ -0,0 +1,250 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +//
> > +// Copyright (c) 2020 MediaTek Inc.
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#define DISP_REG_CONFIG_DISP_OVL0_MOUT_EN  0x040
> > +#define DISP_REG_CONFIG_DISP_OVL1_MOUT_EN  0x044
> > +#define DISP_REG_CONFIG_DISP_OD_MOUT_EN0x048
> > +#define DISP_REG_CONFIG_DISP_GAMMA_MOUT_EN 0x04c
> > +#define DISP_REG_CONFIG_DISP_UFOE_MOUT_EN  0x050
> > +#define DISP_REG_CONFIG_DISP_COLOR0_SEL_IN 0x084
> > +#define DISP_REG_CONFIG_DISP_COLOR1_SEL_IN 0x088
> > +#define DISP_REG_CONFIG_DSIE_SEL_IN0x0a4
> > +#define DISP_REG_CONFIG_DSIO_SEL_IN0x0a8
> > +#define DISP_REG_CONFIG_DPI_SEL_IN 0x0ac
> > +#define DISP_REG_CONFIG_DISP_RDMA2_SOUT0x0b8
> > +#define DISP_REG_CONFIG_DISP_RDMA0_SOUT_EN 0x0c4
> > +#define DISP_REG_CONFIG_DISP_RDMA1_SOUT_EN 0x0c8
> > +#define DISP_REG_CONFIG_MMSYS_CG_CON0  0x100
> > +
> > +#define DISP_REG_CONFIG_DISP_OVL_MOUT_EN   0x030
> > +#define DISP_REG_CONFIG_OUT_SEL0x04c
> > +#define DISP_REG_CONFIG_DSI_SEL0x050
> > +#define DISP_REG_CONFIG_DPI_SEL0x064
> > +
> > +#define OVL0_MOUT_EN_COLOR00x1
> > +#define OD_MOUT_EN_RDMA0   0x1
> > +#define OD1_MOUT_EN_RDMA1  BIT(16)
> > +#define UFOE_MOUT_EN_DSI0  0x1
> > +#define COLOR0_SEL_IN_OVL0 0x1
> > +#define OVL1_MOUT_EN_COLOR10x1
> > +#define GAMMA_MOUT_EN_RDMA10x1
> > +#define RDMA0_SOUT_DPI00x2
> > +#define RDMA0_SOUT_DPI10x3
> > +#define RDMA0_SOUT_DSI10x1
> > +#define RDMA0_SOUT_DSI20x4
> > +#define RDMA0_SOUT_DSI30x5
> > +#define RDMA1_SOUT_DPI00x2
> > +#define RDMA1_SOUT_DPI10x3
> > +#define RDMA1_SOUT_DSI10x1
> > +#define RDMA1_SOUT_DSI20x4
> > +#define RDMA1_SOUT_DSI30x5
> > +#define RDMA2_SOUT_DPI00x2
> > +#define RDMA2_SOUT_DPI10x3
> > +#define RDMA2_SOUT_DSI10x1
> > +#define RDMA2_SOUT_DSI20x4
> > +#define RDMA2_SOUT_DSI30x5
> > +#define DPI0_SEL_IN_RDMA1  0x1
> > +#define DPI0_SEL_IN_RDMA2  0x3
> > +#define DPI1_SEL_IN_RDMA1  (0x1 << 8)
> > +#define DPI1_SEL_IN_RDMA2  (0x3 << 8)
> > +#define DSI0_SEL_IN_RDMA1  0x1
> > +#define DSI0_SEL_IN_RDMA2  0x4
> > +#define DSI1_SEL_IN_RDMA1  0x1
> > +#define DSI1_SEL_IN_RDMA2  0x4
> > +#define DSI2_SEL_IN_RDMA1  (0x1 << 16)
> > +#define DSI2_SEL_IN_RDMA2  (0x4 << 16)
> > +#define DSI3_SEL_IN_RDMA1   

Re: [PATCH v5 5/6] kprobes: Use text_alloc() and text_free()

2020-07-24 Thread Jarkko Sakkinen
On Fri, Jul 24, 2020 at 11:27:46AM +0200, Ingo Molnar wrote:
> 
> * Jarkko Sakkinen  wrote:
> 
> > Use text_alloc() and text_free() instead of module_alloc() and
> > module_memfree() when an arch provides them.
> > 
> > Cc: linux...@kvack.org
> > Cc: Andi Kleen 
> > Cc: Masami Hiramatsu 
> > Cc: Peter Zijlstra 
> > Signed-off-by: Jarkko Sakkinen 
> > ---
> >  kernel/kprobes.c | 9 +
> >  1 file changed, 9 insertions(+)
> > 
> > diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> > index 4e46d96d4e16..611fcda9f6bf 100644
> > --- a/kernel/kprobes.c
> > +++ b/kernel/kprobes.c
> > @@ -40,6 +40,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  
> >  #define KPROBE_HASH_BITS 6
> >  #define KPROBE_TABLE_SIZE (1 << KPROBE_HASH_BITS)
> > @@ -111,12 +112,20 @@ enum kprobe_slot_state {
> >  
> >  void __weak *alloc_insn_page(void)
> >  {
> > +#ifdef CONFIG_ARCH_HAS_TEXT_ALLOC
> > +   return text_alloc(PAGE_SIZE);
> > +#else
> > return module_alloc(PAGE_SIZE);
> > +#endif
> >  }
> >  
> >  void __weak free_insn_page(void *page)
> >  {
> > +#ifdef CONFIG_ARCH_HAS_TEXT_ALLOC
> > +   text_free(page);
> > +#else
> > module_memfree(page);
> > +#endif
> >  }
> 
> I've read the observations in the other threads, but this #ifdef 
> jungle is silly, it's a de-facto open coded text_alloc() with a 
> module_alloc() fallback...

In the previous version I had:

  
https://lore.kernel.org/lkml/20200717030422.679972-4-jarkko.sakki...@linux.intel.com/

and I had just calls to text_alloc() and text_free() in corresponding
snippet to the above.

I got this feedback from Mike:

  https://lore.kernel.org/lkml/20200718162359.ga2919...@kernel.org/

I'm not still sure that I fully understand this feedback as I don't see
any inherent and obvious difference to the v4. In that version fallbacks
are to module_alloc() and module_memfree() and text_alloc() and
text_memfree() can be overridden by arch.

> Thanks,
> 
>   Ingo

/Jarkko


Re: [PATCH] drivers/net/wan: lapb: Corrected the usage of skb_cow

2020-07-24 Thread David Miller
From: Xie He 
Date: Fri, 24 Jul 2020 09:33:47 -0700

> This patch fixed 2 issues with the usage of skb_cow in LAPB drivers
> "lapbether" and "hdlc_x25":
> 
> 1) After skb_cow fails, kfree_skb should be called to drop a reference
> to the skb. But in both drivers, kfree_skb is not called.
> 
> 2) skb_cow should be called before skb_push so that is can ensure the
> safety of skb_push. But in "lapbether", it is incorrectly called after
> skb_push.
> 
> More details about these 2 issues:
> 
> 1) The behavior of calling kfree_skb on failure is also the behavior of
> netif_rx, which is called by this function with "return netif_rx(skb);".
> So this function should follow this behavior, too.
> 
> 2) In "lapbether", skb_cow is called after skb_push. This results in 2
> logical issues:
>a) skb_push is not protected by skb_cow;
>b) An extra headroom of 1 byte is ensured after skb_push. This extra
>   headroom has no use in this function. It also has no use in the
>   upper-layer function that this function passes the skb to
>   (x25_lapb_receive_frame in net/x25/x25_dev.c).
> So logically skb_cow should instead be called before skb_push.
> 
> Cc: Eric Dumazet 
> Cc: Martin Schiller 
> Signed-off-by: Xie He 

Applied, thank you.


Re: [PATCH v5 5/6] kprobes: Use text_alloc() and text_free()]

2020-07-24 Thread Jarkko Sakkinen
On Fri, Jul 24, 2020 at 03:16:08PM +0300, Ard Biesheuvel wrote:
> On Fri, 24 Jul 2020 at 12:27, Ingo Molnar  wrote:
> >
> >
> > * Jarkko Sakkinen  wrote:
> >
> > > Use text_alloc() and text_free() instead of module_alloc() and
> > > module_memfree() when an arch provides them.
> > >
> > > Cc: linux...@kvack.org
> > > Cc: Andi Kleen 
> > > Cc: Masami Hiramatsu 
> > > Cc: Peter Zijlstra 
> > > Signed-off-by: Jarkko Sakkinen 
> > > ---
> > >  kernel/kprobes.c | 9 +
> > >  1 file changed, 9 insertions(+)
> > >
> > > diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> > > index 4e46d96d4e16..611fcda9f6bf 100644
> > > --- a/kernel/kprobes.c
> > > +++ b/kernel/kprobes.c
> > > @@ -40,6 +40,7 @@
> > >  #include 
> > >  #include 
> > >  #include 
> > > +#include 
> > >
> > >  #define KPROBE_HASH_BITS 6
> > >  #define KPROBE_TABLE_SIZE (1 << KPROBE_HASH_BITS)
> > > @@ -111,12 +112,20 @@ enum kprobe_slot_state {
> > >
> > >  void __weak *alloc_insn_page(void)
> > >  {
> > > +#ifdef CONFIG_ARCH_HAS_TEXT_ALLOC
> > > + return text_alloc(PAGE_SIZE);
> > > +#else
> > >   return module_alloc(PAGE_SIZE);
> > > +#endif
> > >  }
> > >
> > >  void __weak free_insn_page(void *page)
> > >  {
> > > +#ifdef CONFIG_ARCH_HAS_TEXT_ALLOC
> > > + text_free(page);
> > > +#else
> > >   module_memfree(page);
> > > +#endif
> > >  }
> >
> > I've read the observations in the other threads, but this #ifdef
> > jungle is silly, it's a de-facto open coded text_alloc() with a
> > module_alloc() fallback...
> >
> 
> Also, as I attempted to explain before, there is no reason to allocate
> kasan shadow for any of these use cases, so cloning module_alloc() to
> implement text_alloc() is not the correct approach even on x86.
> 
> I suppose module_alloc() could be reimplemented in terms of
> text_alloc() in this case, but simply relabelling it like this seems
> inappropriate on all architectures.

I agree with this. Even if there was chance to do a merge of some
kind, it should probably happen over time and accept some redundancy
first.

/Jarkko


Re: [PATCH] watch_queue: Limit the number of watches a user can hold

2020-07-24 Thread Jarkko Sakkinen
On Fri, Jul 24, 2020 at 11:17:26PM +0100, David Howells wrote:
> Impose a limit on the number of watches that a user can hold so that they
> can't use this mechanism to fill up all the available memory.
> 
> This is done by putting a counter in user_struct that's incremented when a
> watch is allocated and decreased when it is released.  If the number
> exceeds the RLIMIT_NOFILE limit, the watch is rejected with EAGAIN.
> 
> This can be tested by the following means:
> 
>  (1) Create a watch queue and attach it to fd 5 in the program given - in
>  this case, bash:
> 
>   keyctl watch_session /tmp/nlog /tmp/gclog 5 bash
> 
>  (2) In the shell, set the maximum number of files to, say, 99:
> 
>   ulimit -n 99
> 
>  (3) Add 200 keyrings:
> 
>   for ((i=0; i<200; i++)); do keyctl newring a$i @s || break; done
> 
>  (4) Try to watch all of the keyrings:
> 
>   for ((i=0; i<200; i++)); do echo $i; keyctl watch_add 5 %:a$i || break; 
> done
> 
>  This should fail when the number of watches belonging to the user hits
>  99.
> 
>  (5) Remove all the keyrings and all of those watches should go away:
> 
>   for ((i=0; i<200; i++)); do keyctl unlink %:a$i; done
> 
>  (6) Kill off the watch queue by exiting the shell spawned by
>  watch_session.
> 
> Fixes: c73be61cede5 ("pipe: Add general notification queue support")
> Reported-by: Linus Torvalds 
> Signed-off-by: David Howells 
> ---
> 
>  include/linux/sched/user.h |3 +++
>  kernel/watch_queue.c   |8 
>  2 files changed, 11 insertions(+)
> 
> diff --git a/include/linux/sched/user.h b/include/linux/sched/user.h
> index 917d88edb7b9..a8ec3b6093fc 100644
> --- a/include/linux/sched/user.h
> +++ b/include/linux/sched/user.h
> @@ -36,6 +36,9 @@ struct user_struct {
>  defined(CONFIG_NET) || defined(CONFIG_IO_URING)
>   atomic_long_t locked_vm;
>  #endif
> +#ifdef CONFIG_WATCH_QUEUE
> + atomic_t nr_watches;/* The number of watches this user currently 
> has */
> +#endif
>  
>   /* Miscellaneous per-user rate limit */
>   struct ratelimit_state ratelimit;
> diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c
> index f74020f6bd9d..0ef8f65bd2d7 100644
> --- a/kernel/watch_queue.c
> +++ b/kernel/watch_queue.c
> @@ -393,6 +393,7 @@ static void free_watch(struct rcu_head *rcu)
>   struct watch *watch = container_of(rcu, struct watch, rcu);
>  
>   put_watch_queue(rcu_access_pointer(watch->queue));
> + atomic_dec(&watch->cred->user->nr_watches);
>   put_cred(watch->cred);
>  }
>  
> @@ -452,6 +453,13 @@ int add_watch_to_object(struct watch *watch, struct 
> watch_list *wlist)
>   watch->cred = get_current_cred();
>   rcu_assign_pointer(watch->watch_list, wlist);
>  
> + if (atomic_inc_return(&watch->cred->user->nr_watches) >
> + task_rlimit(current, RLIMIT_NOFILE)) {
> + atomic_dec(&watch->cred->user->nr_watches);
> + put_cred(watch->cred);
> + return -EAGAIN;
> + }
> +
>   spin_lock_bh(&wqueue->lock);
>   kref_get(&wqueue->usage);
>   kref_get(&watch->usage);
> 
> 

Reviewed-by: Jarkko Sakkinen 

David, BTW, would it be possible to push keyrings to lore.kernel.org?

I don't have an archive for keyrings, which means that I cannot push
this forward.

/Jarkko


[RFC][PATCH] dma-heap: Add proper kref handling on dma-buf heaps

2020-07-24 Thread John Stultz
Add proper refcounting on the dma_heap structure.
While existing heaps are built-in, we may eventually
have heaps loaded from modules, and we'll need to be
able to properly handle the references to the heaps

Cc: Sumit Semwal 
Cc: Andrew F. Davis 
Cc: Benjamin Gaignard 
Cc: Liam Mark 
Cc: Laura Abbott 
Cc: Brian Starkey 
Cc: linux-me...@vger.kernel.org
Cc: dri-de...@lists.freedesktop.org
Signed-off-by: John Stultz 
---
 drivers/dma-buf/dma-heap.c | 31 +++
 include/linux/dma-heap.h   |  6 ++
 2 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c
index afd22c9dbdcf..90c3720acc1c 100644
--- a/drivers/dma-buf/dma-heap.c
+++ b/drivers/dma-buf/dma-heap.c
@@ -40,6 +40,8 @@ struct dma_heap {
dev_t heap_devt;
struct list_head list;
struct cdev heap_cdev;
+   int minor;
+   struct kref refcount;
 };
 
 static LIST_HEAD(heap_list);
@@ -190,11 +192,31 @@ void *dma_heap_get_drvdata(struct dma_heap *heap)
return heap->priv;
 }
 
+static void dma_heap_release(struct kref *ref)
+{
+   struct dma_heap *heap = container_of(ref, struct dma_heap, refcount);
+
+   /* Remove heap from the list */
+   mutex_lock(&heap_list_lock);
+   list_del(&heap->list);
+   mutex_unlock(&heap_list_lock);
+
+   device_destroy(dma_heap_class, heap->heap_devt);
+   cdev_del(&heap->heap_cdev);
+   xa_erase(&dma_heap_minors, heap->minor);
+
+   kfree(heap);
+}
+
+void dma_heap_put(struct dma_heap *h)
+{
+   kref_put(&h->refcount, dma_heap_release);
+}
+
 struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info)
 {
struct dma_heap *heap, *h, *err_ret;
struct device *dev_ret;
-   unsigned int minor;
int ret;
 
if (!exp_info->name || !strcmp(exp_info->name, "")) {
@@ -223,12 +245,13 @@ struct dma_heap *dma_heap_add(const struct 
dma_heap_export_info *exp_info)
if (!heap)
return ERR_PTR(-ENOMEM);
 
+   kref_init(&heap->refcount);
heap->name = exp_info->name;
heap->ops = exp_info->ops;
heap->priv = exp_info->priv;
 
/* Find unused minor number */
-   ret = xa_alloc(&dma_heap_minors, &minor, heap,
+   ret = xa_alloc(&dma_heap_minors, &heap->minor, heap,
   XA_LIMIT(0, NUM_HEAP_MINORS - 1), GFP_KERNEL);
if (ret < 0) {
pr_err("dma_heap: Unable to get minor number for heap\n");
@@ -237,7 +260,7 @@ struct dma_heap *dma_heap_add(const struct 
dma_heap_export_info *exp_info)
}
 
/* Create device */
-   heap->heap_devt = MKDEV(MAJOR(dma_heap_devt), minor);
+   heap->heap_devt = MKDEV(MAJOR(dma_heap_devt), heap->minor);
 
cdev_init(&heap->heap_cdev, &dma_heap_fops);
ret = cdev_add(&heap->heap_cdev, heap->heap_devt, 1);
@@ -267,7 +290,7 @@ struct dma_heap *dma_heap_add(const struct 
dma_heap_export_info *exp_info)
 err2:
cdev_del(&heap->heap_cdev);
 err1:
-   xa_erase(&dma_heap_minors, minor);
+   xa_erase(&dma_heap_minors, heap->minor);
 err0:
kfree(heap);
return err_ret;
diff --git a/include/linux/dma-heap.h b/include/linux/dma-heap.h
index 454e354d1ffb..c1572f29cfac 100644
--- a/include/linux/dma-heap.h
+++ b/include/linux/dma-heap.h
@@ -56,4 +56,10 @@ void *dma_heap_get_drvdata(struct dma_heap *heap);
  */
 struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info);
 
+/**
+ * dma_heap_put - drops a reference to a dmabuf heaps, potentially freeing it
+ * @heap:  heap pointer
+ */
+void dma_heap_put(struct dma_heap *heap);
+
 #endif /* _DMA_HEAPS_H */
-- 
2.17.1



Re: [v7, PATCH 2/7] mtk-mmsys: add mmsys private data

2020-07-24 Thread Yongqiang Niu
On Thu, 2020-07-23 at 11:32 +0200, Enric Balletbo Serra wrote:
> Hi Yongqiang Niu,
> 
> Thank you for your patch.
> 
> Missatge de Yongqiang Niu  del dia dj., 23
> de jul. 2020 a les 4:05:
> >
> > add mmsys private data
> >
> 
> I think this change requires a better explanation of what you are
> doing. Although I'm really uncomfortable with this change, why you
> need to create a new mt2701-mmsys file?

reason:
1.there will more and more Mediatek Soc upstream, and the display path
connection function mtk_mmsys_ddp_mout_en, mtk_mmsys_ddp_sel_in and
mtk_mmsys_ddp_sout_sel will complicated more and more, 
2. many of the connection are only used in some SoC, and useless for
other SoC and not readable,
3. if we add a new SoC connection, we need check is this affect other
Soc,
> 
> > Feature: drm/mediatek
> 
> Remove this.
next version will remove this
> 
> > Signed-off-by: Yongqiang Niu 
> > ---
> >  drivers/soc/mediatek/Makefile |   1 +
> >  drivers/soc/mediatek/mmsys/Makefile   |   2 +
> >  drivers/soc/mediatek/mmsys/mt2701-mmsys.c | 250 +++
> >  drivers/soc/mediatek/mtk-mmsys.c  | 271 
> > +-
> >  include/linux/soc/mediatek/mtk-mmsys.h|  15 ++
> >  5 files changed, 314 insertions(+), 225 deletions(-)
> >  create mode 100644 drivers/soc/mediatek/mmsys/Makefile
> >  create mode 100644 drivers/soc/mediatek/mmsys/mt2701-mmsys.c
> >
> > diff --git a/drivers/soc/mediatek/Makefile b/drivers/soc/mediatek/Makefile
> > index 2afa7b9..b37ac2c 100644
> > --- a/drivers/soc/mediatek/Makefile
> > +++ b/drivers/soc/mediatek/Makefile
> > @@ -3,3 +3,4 @@ obj-$(CONFIG_MTK_CMDQ) += mtk-cmdq-helper.o
> >  obj-$(CONFIG_MTK_PMIC_WRAP) += mtk-pmic-wrap.o
> >  obj-$(CONFIG_MTK_SCPSYS) += mtk-scpsys.o
> >  obj-$(CONFIG_MTK_MMSYS) += mtk-mmsys.o
> > +obj-$(CONFIG_MTK_MMSYS) += mmsys/
> > diff --git a/drivers/soc/mediatek/mmsys/Makefile 
> > b/drivers/soc/mediatek/mmsys/Makefile
> > new file mode 100644
> > index 000..33b0dab
> > --- /dev/null
> > +++ b/drivers/soc/mediatek/mmsys/Makefile
> > @@ -0,0 +1,2 @@
> > +# SPDX-License-Identifier: GPL-2.0-only
> > +obj-y += mt2701-mmsys.o
> > diff --git a/drivers/soc/mediatek/mmsys/mt2701-mmsys.c 
> > b/drivers/soc/mediatek/mmsys/mt2701-mmsys.c
> > new file mode 100644
> > index 000..b8e53b0
> > --- /dev/null
> > +++ b/drivers/soc/mediatek/mmsys/mt2701-mmsys.c
> > @@ -0,0 +1,250 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +//
> > +// Copyright (c) 2020 MediaTek Inc.
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#define DISP_REG_CONFIG_DISP_OVL0_MOUT_EN  0x040
> > +#define DISP_REG_CONFIG_DISP_OVL1_MOUT_EN  0x044
> > +#define DISP_REG_CONFIG_DISP_OD_MOUT_EN0x048
> > +#define DISP_REG_CONFIG_DISP_GAMMA_MOUT_EN 0x04c
> > +#define DISP_REG_CONFIG_DISP_UFOE_MOUT_EN  0x050
> > +#define DISP_REG_CONFIG_DISP_COLOR0_SEL_IN 0x084
> > +#define DISP_REG_CONFIG_DISP_COLOR1_SEL_IN 0x088
> > +#define DISP_REG_CONFIG_DSIE_SEL_IN0x0a4
> > +#define DISP_REG_CONFIG_DSIO_SEL_IN0x0a8
> > +#define DISP_REG_CONFIG_DPI_SEL_IN 0x0ac
> > +#define DISP_REG_CONFIG_DISP_RDMA2_SOUT0x0b8
> > +#define DISP_REG_CONFIG_DISP_RDMA0_SOUT_EN 0x0c4
> > +#define DISP_REG_CONFIG_DISP_RDMA1_SOUT_EN 0x0c8
> > +#define DISP_REG_CONFIG_MMSYS_CG_CON0  0x100
> > +
> > +#define DISP_REG_CONFIG_DISP_OVL_MOUT_EN   0x030
> > +#define DISP_REG_CONFIG_OUT_SEL0x04c
> > +#define DISP_REG_CONFIG_DSI_SEL0x050
> > +#define DISP_REG_CONFIG_DPI_SEL0x064
> > +
> > +#define OVL0_MOUT_EN_COLOR00x1
> > +#define OD_MOUT_EN_RDMA0   0x1
> > +#define OD1_MOUT_EN_RDMA1  BIT(16)
> > +#define UFOE_MOUT_EN_DSI0  0x1
> > +#define COLOR0_SEL_IN_OVL0 0x1
> > +#define OVL1_MOUT_EN_COLOR10x1
> > +#define GAMMA_MOUT_EN_RDMA10x1
> > +#define RDMA0_SOUT_DPI00x2
> > +#define RDMA0_SOUT_DPI10x3
> > +#define RDMA0_SOUT_DSI10x1
> > +#define RDMA0_SOUT_DSI20x4
> > +#define RDMA0_SOUT_DSI30x5
> > +#define RDMA1_SOUT_DPI00x2
> > +#define RDMA1_SOUT_DPI10x3
> > +#define RDMA1_SOUT_DSI10x1
> > +#define RDMA1_SOUT_DSI20x4
> > +#define RDMA1_SOUT_DSI30x5
> > +#define RDMA2_SOUT_DPI00x2
> > +#define RDMA2_SOUT_DPI10x3
> > +#define RDMA2_SOUT_DSI10x1
> > +#define RDMA2_SOUT_DSI20x4
> > +#defi

[tip:x86/build] BUILD SUCCESS 587af649bcc04eb016822f209a975005c0092151

2020-07-24 Thread kernel test robot
tree/branch: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git  
x86/build
branch HEAD: 587af649bcc04eb016822f209a975005c0092151  x86/build: Move 
max-page-size option to LDFLAGS_vmlinux

elapsed time: 722m

configs tested: 92
configs skipped: 70

The following configs have been built successfully.
More configs may be tested in the coming days.

arm64allyesconfig
arm64   defconfig
arm64allmodconfig
arm64 allnoconfig
arm defconfig
arm  allyesconfig
arm  allmodconfig
arm   allnoconfig
i386  allnoconfig
i386 allyesconfig
i386defconfig
i386  debian-10.3
ia64 allmodconfig
ia64defconfig
ia64  allnoconfig
ia64 allyesconfig
m68k allmodconfig
m68k  allnoconfig
m68k   sun3_defconfig
m68kdefconfig
m68k allyesconfig
nios2   defconfig
nios2allyesconfig
openriscdefconfig
c6x  allyesconfig
c6x   allnoconfig
openrisc allyesconfig
nds32   defconfig
nds32 allnoconfig
csky allyesconfig
cskydefconfig
alpha   defconfig
alphaallyesconfig
xtensa   allyesconfig
h8300allyesconfig
h8300allmodconfig
xtensa  defconfig
mips allyesconfig
mips  allnoconfig
mips allmodconfig
pariscallnoconfig
parisc  defconfig
parisc   allyesconfig
parisc   allmodconfig
powerpc  allyesconfig
powerpc  rhel-kconfig
powerpc  allmodconfig
powerpc   allnoconfig
i386 randconfig-a003-20200725
i386 randconfig-a005-20200725
i386 randconfig-a004-20200725
i386 randconfig-a006-20200725
i386 randconfig-a002-20200725
i386 randconfig-a001-20200725
x86_64   randconfig-a014-20200724
x86_64   randconfig-a016-20200724
x86_64   randconfig-a015-20200724
x86_64   randconfig-a012-20200724
x86_64   randconfig-a013-20200724
x86_64   randconfig-a011-20200724
i386 randconfig-a016-20200725
i386 randconfig-a013-20200725
i386 randconfig-a012-20200725
i386 randconfig-a015-20200725
i386 randconfig-a014-20200725
i386 randconfig-a011-20200725
i386 randconfig-a016-20200724
i386 randconfig-a013-20200724
i386 randconfig-a012-20200724
i386 randconfig-a015-20200724
i386 randconfig-a014-20200724
i386 randconfig-a011-20200724
riscvallyesconfig
riscv allnoconfig
riscv   defconfig
riscvallmodconfig
s390 allyesconfig
s390  allnoconfig
s390 allmodconfig
s390defconfig
sparcallyesconfig
sparc   defconfig
sparc64 defconfig
sparc64   allnoconfig
sparc64  allyesconfig
sparc64  allmodconfig
x86_64rhel-7.6-kselftests
x86_64   rhel-8.3
x86_64  kexec
x86_64   rhel
x86_64lkp
x86_64  fedora-25

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


Re: [v7, PATCH 7/7] drm/mediatek: add support for mediatek SOC MT8183

2020-07-24 Thread Yongqiang Niu
On Sat, 2020-07-25 at 07:24 +0800, Chun-Kuang Hu wrote:
> Hi Yongqiang:
> 
> Yongqiang Niu  於 2020年7月23日 週四 上午10:15寫道:
> >
> > This patch add support for mediatek SOC MT8183
> > 1.ovl_2l share driver with ovl
> 
> I think this is done in [1], [2], [3], this patch just add the support
> of mt8183-ovl and mt8183-ovl-2l.
> 
> [1] 
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/gpu/drm/mediatek?h=v5.8-rc6&id=132c6e250ed745443973cada8db17cdbaebdf551
> [2] 
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/gpu/drm/mediatek?h=v5.8-rc6&id=318462d1a568634ba09263cc730cb0fb1d56c2b3
> [3] 
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/gpu/drm/mediatek?h=v5.8-rc6&id=57148baac8b78461e394953cfd5317bde8f795ab
> 
> > 2.rdma1 share drive with rdma0, but fifo size is different
> 
> I think this is done in [4], this patch just add the support of mt8183-rdma.
> 
> [4] https://patchwork.kernel.org/patch/11679549/
> 
> > 3.add mt8183 mutex private data, and mmsys private data
> > 4.add mt8183 main and external path module for crtc create
> 
> The fourth item is the mmsys private data in third item, so you need
> not to repeat it.
> 

i will remove some useless description in next version.
> >
> > Signed-off-by: Yongqiang Niu 
> > ---
> >  drivers/gpu/drm/mediatek/mtk_disp_ovl.c  | 18 
> >  drivers/gpu/drm/mediatek/mtk_disp_rdma.c |  6 
> >  drivers/gpu/drm/mediatek/mtk_drm_ddp.c   | 47 
> > 
> >  drivers/gpu/drm/mediatek/mtk_drm_drv.c   | 43 +
> >  4 files changed, 114 insertions(+)
> >
> 
> [snip]
> 
> > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp.c 
> > b/drivers/gpu/drm/mediatek/mtk_drm_ddp.c
> > index 014c1bb..60788c1 100644
> > --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp.c
> > +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp.c
> > @@ -15,6 +15,8 @@
> >
> >  #define MT2701_DISP_MUTEX0_MOD00x2c
> >  #define MT2701_DISP_MUTEX0_SOF00x30
> > +#define MT8183_DISP_MUTEX0_MOD00x30
> > +#define MT8183_DISP_MUTEX0_SOF00x2c
> >
> >  #define DISP_REG_MUTEX_EN(n)   (0x20 + 0x20 * (n))
> >  #define DISP_REG_MUTEX(n)  (0x24 + 0x20 * (n))
> > @@ -25,6 +27,18 @@
> >
> >  #define INT_MUTEX  BIT(1)
> >
> > +#define MT8183_MUTEX_MOD_DISP_RDMA00
> > +#define MT8183_MUTEX_MOD_DISP_RDMA11
> > +#define MT8183_MUTEX_MOD_DISP_OVL0 9
> > +#define MT8183_MUTEX_MOD_DISP_OVL0_2L  10
> > +#define MT8183_MUTEX_MOD_DISP_OVL1_2L  11
> > +#define MT8183_MUTEX_MOD_DISP_WDMA012
> > +#define MT8183_MUTEX_MOD_DISP_COLOR0   13
> > +#define MT8183_MUTEX_MOD_DISP_CCORR0   14
> > +#define MT8183_MUTEX_MOD_DISP_AAL0 15
> > +#define MT8183_MUTEX_MOD_DISP_GAMMA0   16
> > +#define MT8183_MUTEX_MOD_DISP_DITHER0  17
> > +
> >  #define MT8173_MUTEX_MOD_DISP_OVL0 11
> >  #define MT8173_MUTEX_MOD_DISP_OVL1 12
> >  #define MT8173_MUTEX_MOD_DISP_RDMA013
> > @@ -74,6 +88,10 @@
> >  #define MUTEX_SOF_DSI2 5
> >  #define MUTEX_SOF_DSI3 6
> >
> > +#define MT8183_MUTEX_SOF_DPI0  2
> > +#define MT8183_MUTEX_EOF_DSI0  (MUTEX_SOF_DSI0 << 6)
> > +#define MT8183_MUTEX_EOF_DPI0  (MT8183_MUTEX_SOF_DPI0 << 6)
> > +
> >
> >  struct mtk_disp_mutex {
> > int id;
> > @@ -153,6 +171,20 @@ struct mtk_ddp {
> > [DDP_COMPONENT_WDMA1] = MT8173_MUTEX_MOD_DISP_WDMA1,
> >  };
> >
> > +static const unsigned int mt8183_mutex_mod[DDP_COMPONENT_ID_MAX] = {
> > +   [DDP_COMPONENT_AAL0] = MT8183_MUTEX_MOD_DISP_AAL0,
> > +   [DDP_COMPONENT_CCORR] = MT8183_MUTEX_MOD_DISP_CCORR0,
> > +   [DDP_COMPONENT_COLOR0] = MT8183_MUTEX_MOD_DISP_COLOR0,
> > +   [DDP_COMPONENT_DITHER] = MT8183_MUTEX_MOD_DISP_DITHER0,
> > +   [DDP_COMPONENT_GAMMA] = MT8183_MUTEX_MOD_DISP_GAMMA0,
> > +   [DDP_COMPONENT_OVL0] = MT8183_MUTEX_MOD_DISP_OVL0,
> > +   [DDP_COMPONENT_OVL_2L0] = MT8183_MUTEX_MOD_DISP_OVL0_2L,
> > +   [DDP_COMPONENT_OVL_2L1] = MT8183_MUTEX_MOD_DISP_OVL1_2L,
> > +   [DDP_COMPONENT_RDMA0] = MT8183_MUTEX_MOD_DISP_RDMA0,
> > +   [DDP_COMPONENT_RDMA1] = MT8183_MUTEX_MOD_DISP_RDMA1,
> > +   [DDP_COMPONENT_WDMA0] = MT8183_MUTEX_MOD_DISP_WDMA0,
> > +};
> > +
> >  static const unsigned int mt2712_mutex_sof[DDP_MUTEX_SOF_DSI3 + 1] = {
> > [DDP_MUTEX_SOF_SINGLE_MODE] = MUTEX_SOF_SINGLE_MODE,
> > [DDP_MUTEX_SOF_DSI0] = MUTEX_SOF_DSI0,
> > @@ -163,6 +195,12 @@ struct mtk_ddp {
> > [DDP_MUTEX_SOF_DSI3] = MUTEX_SOF_DSI3,
> >  };
> >
> > +static const unsigned int mt8183_mutex_sof[DDP_MUTEX_SOF_DSI3 + 1] = {
> > +   [DDP_MUTEX_SOF_SINGLE_MODE] = MUTEX_SOF_SINGLE_MODE,
> > +   [DDP_MUTE

[tip:master] BUILD SUCCESS ada8a84a9bb8ed2f17d30fff369c7c191a94bb9e

2020-07-24 Thread kernel test robot
tree/branch: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git  master
branch HEAD: ada8a84a9bb8ed2f17d30fff369c7c191a94bb9e  Merge branch 
'WIP.x86/build'

elapsed time: 722m

configs tested: 80
configs skipped: 1

The following configs have been built successfully.
More configs may be tested in the coming days.

arm defconfig
arm  allyesconfig
arm  allmodconfig
arm   allnoconfig
arm64allyesconfig
arm64   defconfig
arm64allmodconfig
arm64 allnoconfig
i386 allyesconfig
i386defconfig
i386  debian-10.3
i386  allnoconfig
ia64 allmodconfig
ia64defconfig
ia64  allnoconfig
ia64 allyesconfig
m68k allmodconfig
m68k  allnoconfig
m68k   sun3_defconfig
m68kdefconfig
m68k allyesconfig
nios2   defconfig
nios2allyesconfig
openriscdefconfig
c6x  allyesconfig
c6x   allnoconfig
openrisc allyesconfig
nds32   defconfig
nds32 allnoconfig
csky allyesconfig
cskydefconfig
alpha   defconfig
alphaallyesconfig
xtensa   allyesconfig
h8300allyesconfig
h8300allmodconfig
xtensa  defconfig
arc defconfig
arc  allyesconfig
sh   allmodconfig
shallnoconfig
microblazeallnoconfig
mips allyesconfig
mips  allnoconfig
mips allmodconfig
pariscallnoconfig
parisc  defconfig
parisc   allyesconfig
parisc   allmodconfig
powerpc defconfig
powerpc  allyesconfig
powerpc  rhel-kconfig
powerpc  allmodconfig
powerpc   allnoconfig
x86_64   randconfig-a014-20200724
x86_64   randconfig-a016-20200724
x86_64   randconfig-a015-20200724
x86_64   randconfig-a012-20200724
x86_64   randconfig-a013-20200724
x86_64   randconfig-a011-20200724
riscvallyesconfig
riscv allnoconfig
riscv   defconfig
riscvallmodconfig
s390 allyesconfig
s390  allnoconfig
s390 allmodconfig
s390defconfig
sparcallyesconfig
sparc   defconfig
sparc64 defconfig
sparc64   allnoconfig
sparc64  allyesconfig
sparc64  allmodconfig
x86_64rhel-7.6-kselftests
x86_64   rhel-8.3
x86_64  kexec
x86_64   rhel
x86_64lkp
x86_64  fedora-25

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


Re: [v7, PATCH 7/7] drm/mediatek: add support for mediatek SOC MT8183

2020-07-24 Thread Yongqiang Niu
On Thu, 2020-07-23 at 17:40 +0200, Matthias Brugger wrote:
> 
> On 23/07/2020 04:03, Yongqiang Niu wrote:
> > This patch add support for mediatek SOC MT8183
> > 1.ovl_2l share driver with ovl
> > 2.rdma1 share drive with rdma0, but fifo size is different
> > 3.add mt8183 mutex private data, and mmsys private data
> > 4.add mt8183 main and external path module for crtc create
> 
> Please fix your commit message, this is seems to describe what the whole 
> series 
> is doing.

will fix in next version
> 
> Regards,
> Matthias
> 
> > 
> > Signed-off-by: Yongqiang Niu 
> > ---
> >   drivers/gpu/drm/mediatek/mtk_disp_ovl.c  | 18 
> >   drivers/gpu/drm/mediatek/mtk_disp_rdma.c |  6 
> >   drivers/gpu/drm/mediatek/mtk_drm_ddp.c   | 47 
> > 
> >   drivers/gpu/drm/mediatek/mtk_drm_drv.c   | 43 
> > +
> >   4 files changed, 114 insertions(+)
> > 
> > diff --git a/drivers/gpu/drm/mediatek/mtk_disp_ovl.c 
> > b/drivers/gpu/drm/mediatek/mtk_disp_ovl.c
> > index 28651bc..8cf9f3b 100644
> > --- a/drivers/gpu/drm/mediatek/mtk_disp_ovl.c
> > +++ b/drivers/gpu/drm/mediatek/mtk_disp_ovl.c
> > @@ -430,11 +430,29 @@ static int mtk_disp_ovl_remove(struct platform_device 
> > *pdev)
> > .fmt_rgb565_is_0 = true,
> >   };
> >   
> > +static const struct mtk_disp_ovl_data mt8183_ovl_driver_data = {
> > +   .addr = DISP_REG_OVL_ADDR_MT8173,
> > +   .gmc_bits = 10,
> > +   .layer_nr = 4,
> > +   .fmt_rgb565_is_0 = true,
> > +};
> > +
> > +static const struct mtk_disp_ovl_data mt8183_ovl_2l_driver_data = {
> > +   .addr = DISP_REG_OVL_ADDR_MT8173,
> > +   .gmc_bits = 10,
> > +   .layer_nr = 2,
> > +   .fmt_rgb565_is_0 = true,
> > +};
> > +
> >   static const struct of_device_id mtk_disp_ovl_driver_dt_match[] = {
> > { .compatible = "mediatek,mt2701-disp-ovl",
> >   .data = &mt2701_ovl_driver_data},
> > { .compatible = "mediatek,mt8173-disp-ovl",
> >   .data = &mt8173_ovl_driver_data},
> > +   { .compatible = "mediatek,mt8183-disp-ovl",
> > + .data = &mt8183_ovl_driver_data},
> > +   { .compatible = "mediatek,mt8183-disp-ovl-2l",
> > + .data = &mt8183_ovl_2l_driver_data},
> > {},
> >   };
> >   MODULE_DEVICE_TABLE(of, mtk_disp_ovl_driver_dt_match);
> > diff --git a/drivers/gpu/drm/mediatek/mtk_disp_rdma.c 
> > b/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
> > index 794acc5..51f2a0c 100644
> > --- a/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
> > +++ b/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
> > @@ -355,11 +355,17 @@ static int mtk_disp_rdma_remove(struct 
> > platform_device *pdev)
> > .fifo_size = SZ_8K,
> >   };
> >   
> > +static const struct mtk_disp_rdma_data mt8183_rdma_driver_data = {
> > +   .fifo_size = 5 * SZ_1K,
> > +};
> > +
> >   static const struct of_device_id mtk_disp_rdma_driver_dt_match[] = {
> > { .compatible = "mediatek,mt2701-disp-rdma",
> >   .data = &mt2701_rdma_driver_data},
> > { .compatible = "mediatek,mt8173-disp-rdma",
> >   .data = &mt8173_rdma_driver_data},
> > +   { .compatible = "mediatek,mt8183-disp-rdma",
> > + .data = &mt8183_rdma_driver_data},
> > {},
> >   };
> >   MODULE_DEVICE_TABLE(of, mtk_disp_rdma_driver_dt_match);
> > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp.c 
> > b/drivers/gpu/drm/mediatek/mtk_drm_ddp.c
> > index 014c1bb..60788c1 100644
> > --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp.c
> > +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp.c
> > @@ -15,6 +15,8 @@
> >   
> >   #define MT2701_DISP_MUTEX0_MOD0   0x2c
> >   #define MT2701_DISP_MUTEX0_SOF0   0x30
> > +#define MT8183_DISP_MUTEX0_MOD00x30
> > +#define MT8183_DISP_MUTEX0_SOF00x2c
> >   
> >   #define DISP_REG_MUTEX_EN(n)  (0x20 + 0x20 * (n))
> >   #define DISP_REG_MUTEX(n) (0x24 + 0x20 * (n))
> > @@ -25,6 +27,18 @@
> >   
> >   #define INT_MUTEX BIT(1)
> >   
> > +#define MT8183_MUTEX_MOD_DISP_RDMA00
> > +#define MT8183_MUTEX_MOD_DISP_RDMA11
> > +#define MT8183_MUTEX_MOD_DISP_OVL0 9
> > +#define MT8183_MUTEX_MOD_DISP_OVL0_2L  10
> > +#define MT8183_MUTEX_MOD_DISP_OVL1_2L  11
> > +#define MT8183_MUTEX_MOD_DISP_WDMA012
> > +#define MT8183_MUTEX_MOD_DISP_COLOR0   13
> > +#define MT8183_MUTEX_MOD_DISP_CCORR0   14
> > +#define MT8183_MUTEX_MOD_DISP_AAL0 15
> > +#define MT8183_MUTEX_MOD_DISP_GAMMA0   16
> > +#define MT8183_MUTEX_MOD_DISP_DITHER0  17
> > +
> >   #define MT8173_MUTEX_MOD_DISP_OVL011
> >   #define MT8173_MUTEX_MOD_DISP_OVL112
> >   #define MT8173_MUTEX_MOD_DISP_RDMA0   13
> > @@ -74,6 +88,10 @@
> >   #define MUTEX_SOF_DSI25
> >   #define MUTEX_SOF_DSI36
> >   
> > +#define MT8183_MUTEX_SOF_DPI0  2
> > +#define MT8183_MUTEX_EOF_DSI0

[tip:timers/core] BUILD SUCCESS 31cd0e119d50cf27ebe214d1a8f7ca36692f13a5

2020-07-24 Thread kernel test robot
tree/branch: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git  
timers/core
branch HEAD: 31cd0e119d50cf27ebe214d1a8f7ca36692f13a5  timers: Recalculate next 
timer interrupt only when necessary

i386-tinyconfig vmlinux size:

=
 TOTAL  TEXT  run_timer_softirq()  calc_wheel_index()   
 
=
 0 00   0  30c66fc30ee7 timer: 
Prevent base->clk from moving backward
+7+50  +5  e2a71bdea816 timer: Fix 
wheel index calculation on last level 
 0 00   0  3d2e83a2a6a0 timers: 
Preserve higher bits of expiration on index calculat 
  +110  +1100+103  1f32cab0db4b timers: Use 
only bucket expiry for base->next_expiry value   
 0 00   0  9a2b764b06c8 timers: 
Move trigger_dyntick_cpu() to enqueue_timer()
 0 00   0  446889721162 timers: Add 
comments about calc_index() ceiling work 
 0 00   0  001ec1b3925d timers: 
Optimize _next_timer_interrupt() level iteration 
  +213  +213 +171   0  dc2a0f1fb2a0 timers: 
Always keep track of next expiry 
 0 00   0  90d52f65f303 timers: 
Reuse next expiry cache after nohz exit  
   +82   +82   +7   0  1f8a4212dc83 timers: 
Expand clk forward logic beyond nohz 
   +22   +22  +22   0  d4f7dae87096 timers: 
Spare timer softirq until next expiry
   -21   -21  -14   0  0975fb565b8b timers: 
Remove must_forward_clk  
+1+10   0  36cd28a4cdd0 timers: 
Lower base clock forwarding threshold
-1 00   0  1b7efaa61549 Merge tag 
'timers-v5.9' of https://git.linaro.org/people/dan 
   +16   +15   +7   0  31cd0e119d50 timers: 
Recalculate next timer interrupt only when necessary 
  +429  +427 +193+108  
dcb7fd82c75e..31cd0e119d50 (ALL COMMITS)  
=

elapsed time: 910m

configs tested: 74
configs skipped: 1

The following configs have been built successfully.
More configs may be tested in the coming days.

arm defconfig
arm  allyesconfig
arm  allmodconfig
arm   allnoconfig
arm64allyesconfig
arm64   defconfig
arm64allmodconfig
arm64 allnoconfig
i386 allyesconfig
i386defconfig
i386  debian-10.3
i386  allnoconfig
ia64 allmodconfig
ia64defconfig
ia64  allnoconfig
ia64 allyesconfig
m68k allmodconfig
m68k  allnoconfig
m68k   sun3_defconfig
m68kdefconfig
m68k allyesconfig
nios2   defconfig
nios2allyesconfig
openriscdefconfig
c6x  allyesconfig
c6x   allnoconfig
openrisc allyesconfig
nds32   defconfig
nds32 allnoconfig
csky allyesconfig
cskydefconfig
alpha   defconfig
alphaallyesconfig
xtensa   allyesconfig
h8300allyesconfig
h8300allmodconfig
xtensa  defconfig
arc defconfig
arc  allyesconfig
sh   allmodconfig
shallnoconfig
microblazeallnoconfig
mips allyesconfig
mips

[tip:perf/urgent] BUILD SUCCESS fe5ed7ab99c656bd2f5b79b49df0e9ebf2cead8a

2020-07-24 Thread kernel test robot
tree/branch: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git  
perf/urgent
branch HEAD: fe5ed7ab99c656bd2f5b79b49df0e9ebf2cead8a  uprobes: Change 
handle_swbp() to send SIGTRAP with si_code=SI_KERNEL, to fix GDB regression

elapsed time: 722m

configs tested: 98
configs skipped: 1

The following configs have been built successfully.
More configs may be tested in the coming days.

arm defconfig
arm  allyesconfig
arm  allmodconfig
arm   allnoconfig
arm64allyesconfig
arm64   defconfig
arm64allmodconfig
arm64 allnoconfig
i386  allnoconfig
i386 allyesconfig
i386defconfig
i386  debian-10.3
ia64 allmodconfig
ia64defconfig
ia64  allnoconfig
ia64 allyesconfig
m68k allmodconfig
m68k  allnoconfig
m68k   sun3_defconfig
m68kdefconfig
m68k allyesconfig
nios2   defconfig
nios2allyesconfig
openriscdefconfig
c6x  allyesconfig
c6x   allnoconfig
openrisc allyesconfig
nds32   defconfig
nds32 allnoconfig
csky allyesconfig
cskydefconfig
alpha   defconfig
alphaallyesconfig
xtensa   allyesconfig
h8300allyesconfig
h8300allmodconfig
xtensa  defconfig
arc defconfig
arc  allyesconfig
sh   allmodconfig
shallnoconfig
microblazeallnoconfig
mips allyesconfig
mips  allnoconfig
mips allmodconfig
pariscallnoconfig
parisc  defconfig
parisc   allyesconfig
parisc   allmodconfig
powerpc  allyesconfig
powerpc  rhel-kconfig
powerpc  allmodconfig
powerpc   allnoconfig
powerpc defconfig
i386 randconfig-a003-20200725
i386 randconfig-a005-20200725
i386 randconfig-a004-20200725
i386 randconfig-a006-20200725
i386 randconfig-a002-20200725
i386 randconfig-a001-20200725
x86_64   randconfig-a014-20200724
x86_64   randconfig-a016-20200724
x86_64   randconfig-a015-20200724
x86_64   randconfig-a012-20200724
x86_64   randconfig-a013-20200724
x86_64   randconfig-a011-20200724
i386 randconfig-a016-20200725
i386 randconfig-a013-20200725
i386 randconfig-a012-20200725
i386 randconfig-a015-20200725
i386 randconfig-a014-20200725
i386 randconfig-a011-20200725
i386 randconfig-a016-20200724
i386 randconfig-a013-20200724
i386 randconfig-a012-20200724
i386 randconfig-a015-20200724
i386 randconfig-a014-20200724
i386 randconfig-a011-20200724
riscvallyesconfig
riscv allnoconfig
riscv   defconfig
riscvallmodconfig
s390 allyesconfig
s390  allnoconfig
s390 allmodconfig
s390defconfig
sparcallyesconfig
sparc   defconfig
sparc64 defconfig
sparc64   allnoconfig
sparc64  allyesconfig
sparc64  allmodconfig
x86_64rhel-7.6-kselftests
x86_64   rhel-8.3
x86_64  kexec
x86_64   rhel
x86_64lkp
x86_64  fedora-25

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

Re: [v7, PATCH 7/7] drm/mediatek: add support for mediatek SOC MT8183

2020-07-24 Thread Chun-Kuang Hu
Hi, Yongqiang:

Yongqiang Niu  於 2020年7月25日 週六 上午11:32寫道:
>
> On Sat, 2020-07-25 at 07:24 +0800, Chun-Kuang Hu wrote:
> > Hi Yongqiang:
> >
> > Yongqiang Niu  於 2020年7月23日 週四 上午10:15寫道:
> > >
> > > This patch add support for mediatek SOC MT8183
> > > 1.ovl_2l share driver with ovl
> >
> > I think this is done in [1], [2], [3], this patch just add the support
> > of mt8183-ovl and mt8183-ovl-2l.
> >
> > [1] 
> > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/gpu/drm/mediatek?h=v5.8-rc6&id=132c6e250ed745443973cada8db17cdbaebdf551
> > [2] 
> > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/gpu/drm/mediatek?h=v5.8-rc6&id=318462d1a568634ba09263cc730cb0fb1d56c2b3
> > [3] 
> > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/gpu/drm/mediatek?h=v5.8-rc6&id=57148baac8b78461e394953cfd5317bde8f795ab
> >
> > > 2.rdma1 share drive with rdma0, but fifo size is different
> >
> > I think this is done in [4], this patch just add the support of mt8183-rdma.
> >
> > [4] https://patchwork.kernel.org/patch/11679549/
> >
> > > 3.add mt8183 mutex private data, and mmsys private data
> > > 4.add mt8183 main and external path module for crtc create
> >
> > The fourth item is the mmsys private data in third item, so you need
> > not to repeat it.
> >
>
> i will remove some useless description in next version.
> > >
> > > Signed-off-by: Yongqiang Niu 
> > > ---
> > >  drivers/gpu/drm/mediatek/mtk_disp_ovl.c  | 18 
> > >  drivers/gpu/drm/mediatek/mtk_disp_rdma.c |  6 
> > >  drivers/gpu/drm/mediatek/mtk_drm_ddp.c   | 47 
> > > 
> > >  drivers/gpu/drm/mediatek/mtk_drm_drv.c   | 43 
> > > +
> > >  4 files changed, 114 insertions(+)
> > >
> >
> > [snip]
> >
> > > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp.c 
> > > b/drivers/gpu/drm/mediatek/mtk_drm_ddp.c
> > > index 014c1bb..60788c1 100644
> > > --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp.c
> > > +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp.c
> > > @@ -15,6 +15,8 @@
> > >
> > >  #define MT2701_DISP_MUTEX0_MOD00x2c
> > >  #define MT2701_DISP_MUTEX0_SOF00x30
> > > +#define MT8183_DISP_MUTEX0_MOD00x30
> > > +#define MT8183_DISP_MUTEX0_SOF00x2c
> > >
> > >  #define DISP_REG_MUTEX_EN(n)   (0x20 + 0x20 * (n))
> > >  #define DISP_REG_MUTEX(n)  (0x24 + 0x20 * (n))
> > > @@ -25,6 +27,18 @@
> > >
> > >  #define INT_MUTEX  BIT(1)
> > >
> > > +#define MT8183_MUTEX_MOD_DISP_RDMA00
> > > +#define MT8183_MUTEX_MOD_DISP_RDMA11
> > > +#define MT8183_MUTEX_MOD_DISP_OVL0 9
> > > +#define MT8183_MUTEX_MOD_DISP_OVL0_2L  10
> > > +#define MT8183_MUTEX_MOD_DISP_OVL1_2L  11
> > > +#define MT8183_MUTEX_MOD_DISP_WDMA012
> > > +#define MT8183_MUTEX_MOD_DISP_COLOR0   13
> > > +#define MT8183_MUTEX_MOD_DISP_CCORR0   14
> > > +#define MT8183_MUTEX_MOD_DISP_AAL0 15
> > > +#define MT8183_MUTEX_MOD_DISP_GAMMA0   16
> > > +#define MT8183_MUTEX_MOD_DISP_DITHER0  17
> > > +
> > >  #define MT8173_MUTEX_MOD_DISP_OVL0 11
> > >  #define MT8173_MUTEX_MOD_DISP_OVL1 12
> > >  #define MT8173_MUTEX_MOD_DISP_RDMA013
> > > @@ -74,6 +88,10 @@
> > >  #define MUTEX_SOF_DSI2 5
> > >  #define MUTEX_SOF_DSI3 6
> > >
> > > +#define MT8183_MUTEX_SOF_DPI0  2
> > > +#define MT8183_MUTEX_EOF_DSI0  (MUTEX_SOF_DSI0 << 6)
> > > +#define MT8183_MUTEX_EOF_DPI0  (MT8183_MUTEX_SOF_DPI0 << 
> > > 6)
> > > +
> > >
> > >  struct mtk_disp_mutex {
> > > int id;
> > > @@ -153,6 +171,20 @@ struct mtk_ddp {
> > > [DDP_COMPONENT_WDMA1] = MT8173_MUTEX_MOD_DISP_WDMA1,
> > >  };
> > >
> > > +static const unsigned int mt8183_mutex_mod[DDP_COMPONENT_ID_MAX] = {
> > > +   [DDP_COMPONENT_AAL0] = MT8183_MUTEX_MOD_DISP_AAL0,
> > > +   [DDP_COMPONENT_CCORR] = MT8183_MUTEX_MOD_DISP_CCORR0,
> > > +   [DDP_COMPONENT_COLOR0] = MT8183_MUTEX_MOD_DISP_COLOR0,
> > > +   [DDP_COMPONENT_DITHER] = MT8183_MUTEX_MOD_DISP_DITHER0,
> > > +   [DDP_COMPONENT_GAMMA] = MT8183_MUTEX_MOD_DISP_GAMMA0,
> > > +   [DDP_COMPONENT_OVL0] = MT8183_MUTEX_MOD_DISP_OVL0,
> > > +   [DDP_COMPONENT_OVL_2L0] = MT8183_MUTEX_MOD_DISP_OVL0_2L,
> > > +   [DDP_COMPONENT_OVL_2L1] = MT8183_MUTEX_MOD_DISP_OVL1_2L,
> > > +   [DDP_COMPONENT_RDMA0] = MT8183_MUTEX_MOD_DISP_RDMA0,
> > > +   [DDP_COMPONENT_RDMA1] = MT8183_MUTEX_MOD_DISP_RDMA1,
> > > +   [DDP_COMPONENT_WDMA0] = MT8183_MUTEX_MOD_DISP_WDMA0,
> > > +};
> > > +
> > >  static const unsigned int mt2712_mutex_sof[DDP_MUTEX_SOF_DSI3 + 1] = {
> > > [DDP_MUTEX_SOF_SINGLE_MODE] = MUTEX_SOF_SINGLE_MODE,
> > > [DDP_MUTEX_SOF_DSI0] = M

[PATCH 00/10] crypto: hisilicon/zip - misc clean up

2020-07-24 Thread Yang Shen
This patchset make some clean up:
patch 1:remove useless parameters
patch 4:replace 'sprintf' with 'scnprintf'
patch 7:fix static check warning
and the rest patch fix some coding style

This patchset depends on:
https://patchwork.kernel.org/cover/11680181/

Shukun Tan (1):
  crypto: hisilicon/zip - modify debugfs interface parameters

Yang Shen (9):
  crypto: hisilicon/zip - remove some useless parameters
  crypto: hisilicon/zip - unify naming style for functions and macros
  crypto: hisilicon/zip - replace 'sprintf' with 'scnprintf'
  crypto: hisilicon/zip - use a enum parameter instead of some macros
  crypto: hisilicon/zip - add print for error branch
  crypto: hisilicon/zip - fix static check warning
  crypto: hisilicon/zip - move some private macros from 'zip.h' to
'zip_crypto.c'
  crypto: hisilicon/zip - supplement some comments
  crypto: hisilicon/zip - fix some coding styles

 drivers/crypto/hisilicon/zip/zip.h|  15 
 drivers/crypto/hisilicon/zip/zip_crypto.c | 126 -
 drivers/crypto/hisilicon/zip/zip_main.c   | 130 ++
 3 files changed, 148 insertions(+), 123 deletions(-)

--
2.7.4



[PATCH 10/10] crypto: hisilicon/zip - fix some coding styles

2020-07-24 Thread Yang Shen
1.Unified alignment styles
2.Remove unnecessary goto branch
3.Remove address printf

Signed-off-by: Yang Shen 
Reviewed-by: Zhou Wang 
---
 drivers/crypto/hisilicon/zip/zip_crypto.c | 13 ++---
 drivers/crypto/hisilicon/zip/zip_main.c   | 16 
 2 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/drivers/crypto/hisilicon/zip/zip_crypto.c 
b/drivers/crypto/hisilicon/zip/zip_crypto.c
index 7757e33..10b7adb 100644
--- a/drivers/crypto/hisilicon/zip/zip_crypto.c
+++ b/drivers/crypto/hisilicon/zip/zip_crypto.c
@@ -38,8 +38,10 @@
 #define HZIP_SGL_SGE_NR10

 static const u8 zlib_head[HZIP_ZLIB_HEAD_SIZE] = {0x78, 0x9c};
-static const u8 gzip_head[HZIP_GZIP_HEAD_SIZE] = {0x1f, 0x8b, 0x08, 0x0, 0x0,
- 0x0, 0x0, 0x0, 0x0, 0x03};
+static const u8 gzip_head[HZIP_GZIP_HEAD_SIZE] = {
+   0x1f, 0x8b, 0x08, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x03
+};
+
 enum hisi_zip_alg_type {
HZIP_ALG_TYPE_COMP = 0,
HZIP_ALG_TYPE_DECOMP = 1,
@@ -359,7 +361,6 @@ static void hisi_zip_acomp_cb(struct hisi_qp *qp, void 
*data)

atomic64_inc(&dfx->recv_cnt);
status = sqe->dw3 & HZIP_BD_STATUS_M;
-
if (status != 0 && status != HZIP_NC_ERR) {
dev_err(dev, "%scompress fail in qp%u: %u, output: %u\n",
(qp->alg_type == 0) ? "" : "de", qp->qp_id, status,
@@ -520,8 +521,7 @@ static int hisi_zip_do_work(struct hisi_zip_req *req,
struct hisi_acc_sgl_pool *pool = qp_ctx->sgl_pool;
struct hisi_zip_dfx *dfx = &qp_ctx->zip_dev->dfx;
struct hisi_zip_sqe zip_sqe;
-   dma_addr_t input;
-   dma_addr_t output;
+   dma_addr_t input, output;
int ret;

if (!a_req->src || !a_req->slen || !a_req->dst || !a_req->dlen)
@@ -540,9 +540,8 @@ static int hisi_zip_do_work(struct hisi_zip_req *req,
(req->req_id << 1) + 1,
&output);
if (IS_ERR(req->hw_dst)) {
-   dev_err(dev, "The dst map to hw SGL failed (%ld)!\n",
-   PTR_ERR(req->hw_dst));
ret = PTR_ERR(req->hw_dst);
+   dev_err(dev, "The dst map to hw SGL failed (%d)!\n", ret);
goto err_unmap_input;
}
req->dma_dst = output;
diff --git a/drivers/crypto/hisilicon/zip/zip_main.c 
b/drivers/crypto/hisilicon/zip/zip_main.c
index 49fad18..8bbae28 100644
--- a/drivers/crypto/hisilicon/zip/zip_main.c
+++ b/drivers/crypto/hisilicon/zip/zip_main.c
@@ -258,6 +258,7 @@ static int hisi_zip_set_user_domain_and_cache(struct 
hisi_qm *qm)
/* qm cache */
writel(AXI_M_CFG, base + QM_AXI_M_CFG);
writel(AXI_M_CFG_ENABLE, base + QM_AXI_M_CFG_ENABLE);
+
/* disable FLR triggered by BME(bus master enable) */
writel(PEH_AXUSER_CFG, base + QM_PEH_AXUSER_CFG);
writel(PEH_AXUSER_CFG_ENABLE, base + QM_PEH_AXUSER_CFG_ENABLE);
@@ -311,7 +312,7 @@ static void hisi_zip_hw_error_enable(struct hisi_qm *qm)
writel(0x1, qm->io_base + HZIP_CORE_INT_RAS_CE_ENB);
writel(0x0, qm->io_base + HZIP_CORE_INT_RAS_FE_ENB);
writel(HZIP_CORE_INT_RAS_NFE_ENABLE,
-   qm->io_base + HZIP_CORE_INT_RAS_NFE_ENB);
+  qm->io_base + HZIP_CORE_INT_RAS_NFE_ENB);

/* enable ZIP hw error interrupts */
writel(0, qm->io_base + HZIP_CORE_INT_MASK_REG);
@@ -487,7 +488,6 @@ static const struct file_operations ctrl_debug_fops = {
.write = hisi_zip_ctrl_debug_write,
 };

-
 static int zip_debugfs_atomic64_set(void *data, u64 val)
 {
if (val)
@@ -634,7 +634,7 @@ static void hisi_zip_log_hw_error(struct hisi_qm *qm, u32 
err_sts)
while (err->msg) {
if (err->int_msk & err_sts) {
dev_err(dev, "%s [error status=0x%x] found\n",
-err->msg, err->int_msk);
+   err->msg, err->int_msk);

if (err->int_msk & HZIP_CORE_INT_STATUS_M_ECC) {
err_val = readl(qm->io_base +
@@ -642,9 +642,6 @@ static void hisi_zip_log_hw_error(struct hisi_qm *qm, u32 
err_sts)
dev_err(dev, "hisi-zip multi ecc sram 
num=0x%x\n",
((err_val >>
HZIP_SRAM_ECC_ERR_NUM_SHIFT) & 0xFF));
-   dev_err(dev, "hisi-zip multi ecc sram 
addr=0x%x\n",
-   (err_val >>
-   HZIP_SRAM_ECC_ERR_ADDR_SHIFT));
}
}
err++;
@@ -904,15 +901,10 @@ static int __init hisi_zip_init(void)

ret = pci_register_driver(&hisi_zip_pci_driver);
if (ret < 0) {
+   hisi_zip_unregister_debugfs();
pr_err("Failed to register pci driver.\

[PATCH 07/10] crypto: hisilicon/zip - fix static check warning

2020-07-24 Thread Yang Shen
Fix some code for PClint warning:
Warning - Suspicious Cast

Signed-off-by: Yang Shen 
Reviewed-by: Zhou Wang 
---
 drivers/crypto/hisilicon/zip/zip_crypto.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/crypto/hisilicon/zip/zip_crypto.c 
b/drivers/crypto/hisilicon/zip/zip_crypto.c
index 7aa8a55..fdc5bd3 100644
--- a/drivers/crypto/hisilicon/zip/zip_crypto.c
+++ b/drivers/crypto/hisilicon/zip/zip_crypto.c
@@ -16,7 +16,7 @@

 #define GZIP_HEAD_FLG_SHIFT3
 #define GZIP_HEAD_FEXTRA_SHIFT 10
-#define GZIP_HEAD_FEXTRA_XLEN  2
+#define GZIP_HEAD_FEXTRA_XLEN  2UL
 #define GZIP_HEAD_FHCRC_SIZE   2

 #define HZIP_GZIP_HEAD_BUF 256
@@ -51,13 +51,13 @@ enum {

 struct hisi_zip_req {
struct acomp_req *req;
-   int sskip;
-   int dskip;
+   u32 sskip;
+   u32 dskip;
struct hisi_acc_hw_sgl *hw_src;
struct hisi_acc_hw_sgl *hw_dst;
dma_addr_t dma_src;
dma_addr_t dma_dst;
-   int req_id;
+   u16 req_id;
 };

 struct hisi_zip_req_q {
@@ -119,7 +119,7 @@ static void hisi_zip_config_tag(struct hisi_zip_sqe *sqe, 
u32 tag)

 static void hisi_zip_fill_sqe(struct hisi_zip_sqe *sqe, u8 req_type,
  dma_addr_t s_addr, dma_addr_t d_addr, u32 slen,
- u32 dlen, int sskip, int dskip)
+ u32 dlen, u32 sskip, u32 dskip)
 {
memset(sqe, 0, sizeof(struct hisi_zip_sqe));

@@ -573,7 +573,7 @@ static int hisi_zip_acompress(struct acomp_req *acomp_req)
return head_size;
}

-   req = hisi_zip_create_req(acomp_req, qp_ctx, (size_t)head_size, true);
+   req = hisi_zip_create_req(acomp_req, qp_ctx, head_size, true);
if (IS_ERR(req)) {
dev_err_ratelimited(dev, "Create request before compress failed 
(%ld)!\n",
PTR_ERR(req));
--
2.7.4



[PATCH 09/10] crypto: hisilicon/zip - supplement some comments

2020-07-24 Thread Yang Shen
Supplement some comments.

Signed-off-by: Yang Shen 
Reviewed-by: Zhou Wang 
---
 drivers/crypto/hisilicon/zip/zip_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/hisilicon/zip/zip_main.c 
b/drivers/crypto/hisilicon/zip/zip_main.c
index 7697fa5..49fad18 100644
--- a/drivers/crypto/hisilicon/zip/zip_main.c
+++ b/drivers/crypto/hisilicon/zip/zip_main.c
@@ -285,7 +285,7 @@ static int hisi_zip_set_user_domain_and_cache(struct 
hisi_qm *qm)
writel(HZIP_DECOMP_CHECK_ENABLE | HZIP_ALL_COMP_DECOMP_EN,
   base + HZIP_CLOCK_GATE_CTRL);

-   /* enable sqc writeback */
+   /* enable sqc,cqc writeback */
writel(SQC_CACHE_ENABLE | CQC_CACHE_ENABLE | SQC_CACHE_WB_ENABLE |
   CQC_CACHE_WB_ENABLE | FIELD_PREP(SQC_CACHE_WB_THRD, 1) |
   FIELD_PREP(CQC_CACHE_WB_THRD, 1), base + QM_CACHE_CTL);
@@ -358,7 +358,7 @@ static int current_qm_write(struct ctrl_debug_file *file, 
u32 val)
if (val > qm->vfs_num)
return -EINVAL;

-   /* Calculate curr_qm_qp_num and store */
+   /* According PF or VF Dev ID to calculation curr_qm_qp_num and store */
if (val == 0) {
qm->debug.curr_qm_qp_num = qm->qp_num;
} else {
--
2.7.4



[PATCH 01/10] crypto: hisilicon/zip - remove some useless parameters

2020-07-24 Thread Yang Shen
1.Remove the macro 'HZIP_VF_NUM'.
2.Remove 'list' of the struct 'hisi_zip'

Signed-off-by: Yang Shen 
Reviewed-by: Zhou Wang 
---
 drivers/crypto/hisilicon/zip/zip.h  | 1 -
 drivers/crypto/hisilicon/zip/zip_main.c | 1 -
 2 files changed, 2 deletions(-)

diff --git a/drivers/crypto/hisilicon/zip/zip.h 
b/drivers/crypto/hisilicon/zip/zip.h
index 4484be1..4b3aae8 100644
--- a/drivers/crypto/hisilicon/zip/zip.h
+++ b/drivers/crypto/hisilicon/zip/zip.h
@@ -39,7 +39,6 @@ struct hisi_zip_ctrl;

 struct hisi_zip {
struct hisi_qm qm;
-   struct list_head list;
struct hisi_zip_ctrl *ctrl;
struct hisi_zip_dfx dfx;
 };
diff --git a/drivers/crypto/hisilicon/zip/zip_main.c 
b/drivers/crypto/hisilicon/zip/zip_main.c
index 7e86b0f..445db04 100644
--- a/drivers/crypto/hisilicon/zip/zip_main.c
+++ b/drivers/crypto/hisilicon/zip/zip_main.c
@@ -17,7 +17,6 @@
 #define PCI_DEVICE_ID_ZIP_PF   0xa250
 #define PCI_DEVICE_ID_ZIP_VF   0xa251

-#define HZIP_VF_NUM63
 #define HZIP_QUEUE_NUM_V1  4096
 #define HZIP_QUEUE_NUM_V2  1024

--
2.7.4



[PATCH 04/10] crypto: hisilicon/zip - replace 'sprintf' with 'scnprintf'

2020-07-24 Thread Yang Shen
Replace 'sprintf' with 'scnprintf' to avoid overrun.

Signed-off-by: Yang Shen 
Reviewed-by: Zhou Wang 
---
 drivers/crypto/hisilicon/zip/zip_main.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/hisilicon/zip/zip_main.c 
b/drivers/crypto/hisilicon/zip/zip_main.c
index df1a16f..1883d1b 100644
--- a/drivers/crypto/hisilicon/zip/zip_main.c
+++ b/drivers/crypto/hisilicon/zip/zip_main.c
@@ -428,7 +428,7 @@ static ssize_t hisi_zip_ctrl_debug_read(struct file *filp, 
char __user *buf,
return -EINVAL;
}
spin_unlock_irq(&file->lock);
-   ret = sprintf(tbuf, "%u\n", val);
+   ret = scnprintf(tbuf, HZIP_BUF_SIZE, "%u\n", val);
return simple_read_from_buffer(buf, count, pos, tbuf, ret);
 }

@@ -514,13 +514,16 @@ static int hisi_zip_core_debug_init(struct hisi_qm *qm)
struct debugfs_regset32 *regset;
struct dentry *tmp_d;
char buf[HZIP_BUF_SIZE];
-   int i;
+   int i, ret;

for (i = 0; i < HZIP_CORE_NUM; i++) {
if (i < HZIP_COMP_CORE_NUM)
-   sprintf(buf, "comp_core%d", i);
+   ret = scnprintf(buf, HZIP_BUF_SIZE, "comp_core%d", i);
else
-   sprintf(buf, "decomp_core%d", i - HZIP_COMP_CORE_NUM);
+   ret = scnprintf(buf, HZIP_BUF_SIZE, "decomp_core%d",
+   i - HZIP_COMP_CORE_NUM);
+   if (!ret)
+   return -ENOMEM;

regset = devm_kzalloc(dev, sizeof(*regset), GFP_KERNEL);
if (!regset)
--
2.7.4



[PATCH 06/10] crypto: hisilicon/zip - add print for error branch

2020-07-24 Thread Yang Shen
Add print for some error branches.

Signed-off-by: Yang Shen 
Reviewed-by: Zhou Wang 
---
 drivers/crypto/hisilicon/zip/zip_crypto.c | 68 +++
 drivers/crypto/hisilicon/zip/zip_main.c   |  8 ++--
 2 files changed, 56 insertions(+), 20 deletions(-)

diff --git a/drivers/crypto/hisilicon/zip/zip_crypto.c 
b/drivers/crypto/hisilicon/zip/zip_crypto.c
index c2ea849..7aa8a55 100644
--- a/drivers/crypto/hisilicon/zip/zip_crypto.c
+++ b/drivers/crypto/hisilicon/zip/zip_crypto.c
@@ -146,7 +146,7 @@ static int hisi_zip_start_qp(struct hisi_qp *qp, struct 
hisi_zip_qp_ctx *ctx,

ret = hisi_qm_start_qp(qp, 0);
if (ret < 0) {
-   dev_err(dev, "start qp failed!\n");
+   dev_err(dev, "Start qp failed (%d)!\n", ret);
return ret;
}

@@ -169,7 +169,7 @@ static int hisi_zip_ctx_init(struct hisi_zip_ctx 
*hisi_zip_ctx, u8 req_type, int

ret = zip_create_qps(qps, HZIP_CTX_Q_NUM, node);
if (ret) {
-   pr_err("Can not create zip qps!\n");
+   pr_err("Can not create zip qps (%d)!\n", ret);
return -ENODEV;
}

@@ -380,19 +380,28 @@ static int hisi_zip_acomp_init(struct crypto_acomp *tfm)
 {
const char *alg_name = crypto_tfm_alg_name(&tfm->base);
struct hisi_zip_ctx *ctx = crypto_tfm_ctx(&tfm->base);
+   struct device *dev;
int ret;

ret = hisi_zip_ctx_init(ctx, COMP_NAME_TO_TYPE(alg_name), 
tfm->base.node);
-   if (ret)
+   if (ret) {
+   pr_err("Init ctx failed (%d)!\n", ret);
return ret;
+   }
+
+   dev = &ctx->qp_ctx[0].qp->qm->pdev->dev;

ret = hisi_zip_create_req_q(ctx);
-   if (ret)
+   if (ret) {
+   dev_err(dev, "Create request queue failed (%d)!\n", ret);
goto err_ctx_exit;
+   }

ret = hisi_zip_create_sgl_pool(ctx);
-   if (ret)
+   if (ret) {
+   dev_err(dev, "Create sgl pool failed (%d)!\n", ret);
goto err_release_req_q;
+   }

hisi_zip_set_acomp_cb(ctx, hisi_zip_acomp_cb);

@@ -422,8 +431,10 @@ static int add_comp_head(struct scatterlist *dst, u8 
req_type)
int ret;

ret = sg_copy_from_buffer(dst, sg_nents(dst), head, head_size);
-   if (ret != head_size)
+   if (ret != head_size) {
+   pr_err("The head size of buffer is wrong (%d)!\n", ret);
return -ENOMEM;
+   }

return head_size;
 }
@@ -445,7 +456,7 @@ static size_t get_comp_head_size(struct scatterlist *src, 
u8 req_type)
case HZIP_ALG_TYPE_GZIP:
return get_gzip_head_size(src);
default:
-   pr_err("request type does not support!\n");
+   pr_err("Request type does not support!\n");
return -EINVAL;
}
 }
@@ -464,7 +475,7 @@ static struct hisi_zip_req *hisi_zip_create_req(struct 
acomp_req *req,
req_id = find_first_zero_bit(req_q->req_bitmap, req_q->size);
if (req_id >= req_q->size) {
write_unlock(&req_q->req_lock);
-   dev_dbg(&qp_ctx->qp->qm->pdev->dev, "req cache is full!\n");
+   dev_dbg(&qp_ctx->qp->qm->pdev->dev, "Req cache is full!\n");
return ERR_PTR(-EBUSY);
}
set_bit(req_id, req_q->req_bitmap);
@@ -504,14 +515,19 @@ static int hisi_zip_do_work(struct hisi_zip_req *req,

req->hw_src = hisi_acc_sg_buf_map_to_hw_sgl(dev, a_req->src, pool,
req->req_id << 1, &input);
-   if (IS_ERR(req->hw_src))
+   if (IS_ERR(req->hw_src)) {
+   dev_err(dev, "The src map to hw SGL failed (%ld)!\n",
+   PTR_ERR(req->hw_src));
return PTR_ERR(req->hw_src);
+   }
req->dma_src = input;

req->hw_dst = hisi_acc_sg_buf_map_to_hw_sgl(dev, a_req->dst, pool,
(req->req_id << 1) + 1,
&output);
if (IS_ERR(req->hw_dst)) {
+   dev_err(dev, "The dst map to hw SGL failed (%ld)!\n",
+   PTR_ERR(req->hw_dst));
ret = PTR_ERR(req->hw_dst);
goto err_unmap_input;
}
@@ -527,6 +543,7 @@ static int hisi_zip_do_work(struct hisi_zip_req *req,
ret = hisi_qp_send(qp, &zip_sqe);
if (ret < 0) {
atomic64_inc(&dfx->send_busy_cnt);
+   dev_dbg_ratelimited(dev, "Send task message failed!\n");
goto err_unmap_output;
}

@@ -543,22 +560,32 @@ static int hisi_zip_acompress(struct acomp_req *acomp_req)
 {
struct hisi_zip_ctx *ctx = crypto_tfm_ctx(acomp_req->base.tfm);
struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[HZIP_QPC_COMP];
+   struct device *dev = &qp_ctx->qp->qm->pdev->dev;
struct hisi_zip_req *req;
int head_size;
int ret;

  

[PATCH 08/10] crypto: hisilicon/zip - move some private macros from 'zip.h' to 'zip_crypto.c'

2020-07-24 Thread Yang Shen
Some macros which are defined in 'zip.h' are related to the struct
'hisi_zip_sqe' and are only used in 'zip_crypto.c'. So move them from
'zip.h' to 'zip_crypto.c'.

Signed-off-by: Yang Shen 
Reviewed-by: Zhou Wang 
---
 drivers/crypto/hisilicon/zip/zip.h| 14 --
 drivers/crypto/hisilicon/zip/zip_crypto.c | 14 ++
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/crypto/hisilicon/zip/zip.h 
b/drivers/crypto/hisilicon/zip/zip.h
index 4b3aae8..92397f9 100644
--- a/drivers/crypto/hisilicon/zip/zip.h
+++ b/drivers/crypto/hisilicon/zip/zip.h
@@ -9,20 +9,6 @@
 #include 
 #include "../qm.h"

-/* hisi_zip_sqe dw3 */
-#define HZIP_BD_STATUS_M   GENMASK(7, 0)
-/* hisi_zip_sqe dw7 */
-#define HZIP_IN_SGE_DATA_OFFSET_M  GENMASK(23, 0)
-/* hisi_zip_sqe dw8 */
-#define HZIP_OUT_SGE_DATA_OFFSET_M GENMASK(23, 0)
-/* hisi_zip_sqe dw9 */
-#define HZIP_REQ_TYPE_MGENMASK(7, 0)
-#define HZIP_ALG_TYPE_ZLIB 0x02
-#define HZIP_ALG_TYPE_GZIP 0x03
-#define HZIP_BUF_TYPE_MGENMASK(11, 8)
-#define HZIP_PBUFFER   0x0
-#define HZIP_SGL   0x1
-
 enum hisi_zip_error_type {
/* negative compression */
HZIP_NC_ERR = 0x0d,
diff --git a/drivers/crypto/hisilicon/zip/zip_crypto.c 
b/drivers/crypto/hisilicon/zip/zip_crypto.c
index fdc5bd3..7757e33 100644
--- a/drivers/crypto/hisilicon/zip/zip_crypto.c
+++ b/drivers/crypto/hisilicon/zip/zip_crypto.c
@@ -6,6 +6,20 @@
 #include 
 #include "zip.h"

+/* hisi_zip_sqe dw3 */
+#define HZIP_BD_STATUS_M   GENMASK(7, 0)
+/* hisi_zip_sqe dw7 */
+#define HZIP_IN_SGE_DATA_OFFSET_M  GENMASK(23, 0)
+/* hisi_zip_sqe dw8 */
+#define HZIP_OUT_SGE_DATA_OFFSET_M GENMASK(23, 0)
+/* hisi_zip_sqe dw9 */
+#define HZIP_REQ_TYPE_MGENMASK(7, 0)
+#define HZIP_ALG_TYPE_ZLIB 0x02
+#define HZIP_ALG_TYPE_GZIP 0x03
+#define HZIP_BUF_TYPE_MGENMASK(11, 8)
+#define HZIP_PBUFFER   0x0
+#define HZIP_SGL   0x1
+
 #define HZIP_ZLIB_HEAD_SIZE2
 #define HZIP_GZIP_HEAD_SIZE10

--
2.7.4



[PATCH 03/10] crypto: hisilicon/zip - modify debugfs interface parameters

2020-07-24 Thread Yang Shen
From: Shukun Tan 

Update debugfs interface parameters

Signed-off-by: Shukun Tan 
Signed-off-by: Yang Shen 
Reviewed-by: Zhou Wang 
---
 drivers/crypto/hisilicon/zip/zip_main.c | 55 ++---
 1 file changed, 24 insertions(+), 31 deletions(-)

diff --git a/drivers/crypto/hisilicon/zip/zip_main.c 
b/drivers/crypto/hisilicon/zip/zip_main.c
index 058f744..df1a16f 100644
--- a/drivers/crypto/hisilicon/zip/zip_main.c
+++ b/drivers/crypto/hisilicon/zip/zip_main.c
@@ -156,7 +156,6 @@ struct ctrl_debug_file {
  */
 struct hisi_zip_ctrl {
struct hisi_zip *hisi_zip;
-   struct dentry *debug_root;
struct ctrl_debug_file files[HZIP_DEBUG_FILE_NUM];
 };

@@ -509,10 +508,8 @@ static int zip_debugfs_atomic64_get(void *data, u64 *val)
 DEFINE_DEBUGFS_ATTRIBUTE(zip_atomic64_ops, zip_debugfs_atomic64_get,
 zip_debugfs_atomic64_set, "%llu\n");

-static int hisi_zip_core_debug_init(struct hisi_zip_ctrl *ctrl)
+static int hisi_zip_core_debug_init(struct hisi_qm *qm)
 {
-   struct hisi_zip *hisi_zip = ctrl->hisi_zip;
-   struct hisi_qm *qm = &hisi_zip->qm;
struct device *dev = &qm->pdev->dev;
struct debugfs_regset32 *regset;
struct dentry *tmp_d;
@@ -533,7 +530,7 @@ static int hisi_zip_core_debug_init(struct hisi_zip_ctrl 
*ctrl)
regset->nregs = ARRAY_SIZE(hzip_dfx_regs);
regset->base = qm->io_base + core_offsets[i];

-   tmp_d = debugfs_create_dir(buf, ctrl->debug_root);
+   tmp_d = debugfs_create_dir(buf, qm->debug.debug_root);
debugfs_create_regset32("regs", 0444, tmp_d, regset);
}

@@ -552,33 +549,32 @@ static void hisi_zip_dfx_debug_init(struct hisi_qm *qm)
for (i = 0; i < ARRAY_SIZE(zip_dfx_files); i++) {
data = (atomic64_t *)((uintptr_t)dfx + zip_dfx_files[i].offset);
debugfs_create_file(zip_dfx_files[i].name,
-   0644,
-   tmp_dir,
-   data,
-   &zip_atomic64_ops);
+   0644, tmp_dir, data,
+   &zip_atomic64_ops);
}
 }

-static int hisi_zip_ctrl_debug_init(struct hisi_zip_ctrl *ctrl)
+static int hisi_zip_ctrl_debug_init(struct hisi_qm *qm)
 {
+   struct hisi_zip *zip = container_of(qm, struct hisi_zip, qm);
int i;

for (i = HZIP_CURRENT_QM; i < HZIP_DEBUG_FILE_NUM; i++) {
-   spin_lock_init(&ctrl->files[i].lock);
-   ctrl->files[i].ctrl = ctrl;
-   ctrl->files[i].index = i;
+   spin_lock_init(&zip->ctrl->files[i].lock);
+   zip->ctrl->files[i].ctrl = zip->ctrl;
+   zip->ctrl->files[i].index = i;

debugfs_create_file(ctrl_debug_file_name[i], 0600,
-   ctrl->debug_root, ctrl->files + i,
+   qm->debug.debug_root,
+   zip->ctrl->files + i,
&ctrl_debug_fops);
}

-   return hisi_zip_core_debug_init(ctrl);
+   return hisi_zip_core_debug_init(qm);
 }

-static int hisi_zip_debugfs_init(struct hisi_zip *hisi_zip)
+static int hisi_zip_debugfs_init(struct hisi_qm *qm)
 {
-   struct hisi_qm *qm = &hisi_zip->qm;
struct device *dev = &qm->pdev->dev;
struct dentry *dev_d;
int ret;
@@ -593,8 +589,7 @@ static int hisi_zip_debugfs_init(struct hisi_zip *hisi_zip)
goto failed_to_create;

if (qm->fun_type == QM_HW_PF) {
-   hisi_zip->ctrl->debug_root = dev_d;
-   ret = hisi_zip_ctrl_debug_init(hisi_zip->ctrl);
+   ret = hisi_zip_ctrl_debug_init(qm);
if (ret)
goto failed_to_create;
}
@@ -608,10 +603,8 @@ static int hisi_zip_debugfs_init(struct hisi_zip *hisi_zip)
return ret;
 }

-static void hisi_zip_debug_regs_clear(struct hisi_zip *hisi_zip)
+static void hisi_zip_debug_regs_clear(struct hisi_qm *qm)
 {
-   struct hisi_qm *qm = &hisi_zip->qm;
-
writel(0x0, qm->io_base + QM_DFX_MB_CNT_VF);
writel(0x0, qm->io_base + QM_DFX_DB_CNT_VF);
writel(0x0, qm->io_base + HZIP_SOFT_CTRL_CNT_CLR_CE);
@@ -619,14 +612,14 @@ static void hisi_zip_debug_regs_clear(struct hisi_zip 
*hisi_zip)
hisi_qm_debug_regs_clear(qm);
 }

-static void hisi_zip_debugfs_exit(struct hisi_zip *hisi_zip)
+static void hisi_zip_debugfs_exit(struct hisi_qm *qm)
 {
-   struct hisi_qm *qm = &hisi_zip->qm;
-
debugfs_remove_recursive(qm->debug.debug_root);

-   if (qm->fun_type == QM_HW_PF)
-   hisi_zip_debug_regs_clear(hisi_zip);
+   if (qm->fun_type == QM_HW_PF) {
+   hisi_zip_debug_regs_clear(qm);
+   qm->debug.curr_qm_qp_num = 0;
+   }
 }

 static void hisi_zip_log_hw_error(struct hisi_qm *qm, u32 err_sts)
@@ -733,7 +726,7 @@ stati

[PATCH 02/10] crypto: hisilicon/zip - unify naming style for functions and macros

2020-07-24 Thread Yang Shen
1.Add prefix 'HZIP' for some macros
2.Add prefix 'hisi_zip' for some functions

Signed-off-by: Yang Shen 
Reviewed-by: Zhou Wang 
---
 drivers/crypto/hisilicon/zip/zip_main.c | 35 +
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/drivers/crypto/hisilicon/zip/zip_main.c 
b/drivers/crypto/hisilicon/zip/zip_main.c
index 445db04..058f744 100644
--- a/drivers/crypto/hisilicon/zip/zip_main.c
+++ b/drivers/crypto/hisilicon/zip/zip_main.c
@@ -29,18 +29,18 @@
 #define DECOMP3_ENABLE BIT(5)
 #define DECOMP4_ENABLE BIT(6)
 #define DECOMP5_ENABLE BIT(7)
-#define ALL_COMP_DECOMP_EN (COMP0_ENABLE | COMP1_ENABLE |  \
+#define HZIP_ALL_COMP_DECOMP_EN(COMP0_ENABLE | COMP1_ENABLE | \
 DECOMP0_ENABLE | DECOMP1_ENABLE | \
 DECOMP2_ENABLE | DECOMP3_ENABLE | \
 DECOMP4_ENABLE | DECOMP5_ENABLE)
-#define DECOMP_CHECK_ENABLEBIT(16)
+#define HZIP_DECOMP_CHECK_ENABLE   BIT(16)
 #define HZIP_FSM_MAX_CNT   0x301008

 #define HZIP_PORT_ARCA_CHE_0   0x301040
 #define HZIP_PORT_ARCA_CHE_1   0x301044
 #define HZIP_PORT_AWCA_CHE_0   0x301060
 #define HZIP_PORT_AWCA_CHE_1   0x301064
-#define CACHE_ALL_EN   0x
+#define HZIP_CACHE_ALL_EN  0x

 #define HZIP_BD_RUSER_32_630x301110
 #define HZIP_SGL_RUSER_32_63   0x30111c
@@ -82,7 +82,7 @@
 #define HZIP_PF_DEF_Q_BASE 0

 #define HZIP_SOFT_CTRL_CNT_CLR_CE  0x301000
-#define SOFT_CTRL_CNT_CLR_CE_BIT   BIT(0)
+#define HZIP_SOFT_CTRL_CNT_CLR_CE_BIT  BIT(0)
 #define HZIP_SOFT_CTRL_ZIP_CONTROL 0x30100C
 #define HZIP_AXI_SHUTDOWN_ENABLE   BIT(14)
 #define HZIP_WR_PORT   BIT(11)
@@ -264,10 +264,10 @@ static int hisi_zip_set_user_domain_and_cache(struct 
hisi_qm *qm)
writel(PEH_AXUSER_CFG_ENABLE, base + QM_PEH_AXUSER_CFG_ENABLE);

/* cache */
-   writel(CACHE_ALL_EN, base + HZIP_PORT_ARCA_CHE_0);
-   writel(CACHE_ALL_EN, base + HZIP_PORT_ARCA_CHE_1);
-   writel(CACHE_ALL_EN, base + HZIP_PORT_AWCA_CHE_0);
-   writel(CACHE_ALL_EN, base + HZIP_PORT_AWCA_CHE_1);
+   writel(HZIP_CACHE_ALL_EN, base + HZIP_PORT_ARCA_CHE_0);
+   writel(HZIP_CACHE_ALL_EN, base + HZIP_PORT_ARCA_CHE_1);
+   writel(HZIP_CACHE_ALL_EN, base + HZIP_PORT_AWCA_CHE_0);
+   writel(HZIP_CACHE_ALL_EN, base + HZIP_PORT_AWCA_CHE_1);

/* user domain configurations */
writel(AXUSER_BASE, base + HZIP_BD_RUSER_32_63);
@@ -283,7 +283,7 @@ static int hisi_zip_set_user_domain_and_cache(struct 
hisi_qm *qm)
}

/* let's open all compression/decompression cores */
-   writel(DECOMP_CHECK_ENABLE | ALL_COMP_DECOMP_EN,
+   writel(HZIP_DECOMP_CHECK_ENABLE | HZIP_ALL_COMP_DECOMP_EN,
   base + HZIP_CLOCK_GATE_CTRL);

/* enable sqc writeback */
@@ -390,7 +390,7 @@ static u32 clear_enable_read(struct ctrl_debug_file *file)
struct hisi_qm *qm = file_to_qm(file);

return readl(qm->io_base + HZIP_SOFT_CTRL_CNT_CLR_CE) &
-  SOFT_CTRL_CNT_CLR_CE_BIT;
+HZIP_SOFT_CTRL_CNT_CLR_CE_BIT;
 }

 static int clear_enable_write(struct ctrl_debug_file *file, u32 val)
@@ -402,14 +402,14 @@ static int clear_enable_write(struct ctrl_debug_file 
*file, u32 val)
return -EINVAL;

tmp = (readl(qm->io_base + HZIP_SOFT_CTRL_CNT_CLR_CE) &
-  ~SOFT_CTRL_CNT_CLR_CE_BIT) | val;
+  ~HZIP_SOFT_CTRL_CNT_CLR_CE_BIT) | val;
writel(tmp, qm->io_base + HZIP_SOFT_CTRL_CNT_CLR_CE);

return  0;
 }

-static ssize_t ctrl_debug_read(struct file *filp, char __user *buf,
-  size_t count, loff_t *pos)
+static ssize_t hisi_zip_ctrl_debug_read(struct file *filp, char __user *buf,
+   size_t count, loff_t *pos)
 {
struct ctrl_debug_file *file = filp->private_data;
char tbuf[HZIP_BUF_SIZE];
@@ -433,8 +433,9 @@ static ssize_t ctrl_debug_read(struct file *filp, char 
__user *buf,
return simple_read_from_buffer(buf, count, pos, tbuf, ret);
 }

-static ssize_t ctrl_debug_write(struct file *filp, const char __user *buf,
-   size_t count, loff_t *pos)
+static ssize_t hisi_zip_ctrl_debug_write(struct file *filp,
+const char __user *buf,
+size_t count, loff_t *pos)
 {
struct ctrl_debug_file *file = filp->private_data;
char tbuf[HZIP_BUF_SIZE];
@@ -483,8 +484,8 @@ static ssize_t ctrl_debug_write(struct file *filp, const 
char __user *buf,
 static const struct file_operations ctrl_debug_fops = {
.owner = THIS_MODULE,
.open = simple_open,
-   .read = ctrl_debug_read,
-  

[PATCH 05/10] crypto: hisilicon/zip - use a enum parameter instead of some macros

2020-07-24 Thread Yang Shen
Macros 'QPC_COMP', 'QPC_DECOMP' and 'HZIP_CTX_Q_NUM' are relative and
incremental. So, use an enum instead.

Signed-off-by: Yang Shen 
Reviewed-by: Zhou Wang 
---
 drivers/crypto/hisilicon/zip/zip_crypto.c | 23 +--
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/drivers/crypto/hisilicon/zip/zip_crypto.c 
b/drivers/crypto/hisilicon/zip/zip_crypto.c
index aba1600..c2ea849 100644
--- a/drivers/crypto/hisilicon/zip/zip_crypto.c
+++ b/drivers/crypto/hisilicon/zip/zip_crypto.c
@@ -19,7 +19,6 @@
 #define GZIP_HEAD_FEXTRA_XLEN  2
 #define GZIP_HEAD_FHCRC_SIZE   2

-#define HZIP_CTX_Q_NUM 2
 #define HZIP_GZIP_HEAD_BUF 256
 #define HZIP_ALG_PRIORITY  300
 #define HZIP_SGL_SGE_NR10
@@ -32,6 +31,12 @@ enum hisi_zip_alg_type {
HZIP_ALG_TYPE_DECOMP = 1,
 };

+enum {
+   HZIP_QPC_COMP,
+   HZIP_QPC_DECOMP,
+   HZIP_CTX_Q_NUM
+};
+
 #define COMP_NAME_TO_TYPE(alg_name)\
(!strcmp((alg_name), "zlib-deflate") ? HZIP_ALG_TYPE_ZLIB : \
 !strcmp((alg_name), "gzip") ? HZIP_ALG_TYPE_GZIP : 0)  \
@@ -71,8 +76,6 @@ struct hisi_zip_qp_ctx {
 };

 struct hisi_zip_ctx {
-#define QPC_COMP   0
-#define QPC_DECOMP 1
struct hisi_zip_qp_ctx qp_ctx[HZIP_CTX_Q_NUM];
 };

@@ -264,11 +267,11 @@ static int hisi_zip_create_req_q(struct hisi_zip_ctx *ctx)
return 0;

 err_free_loop1:
-   kfree(ctx->qp_ctx[QPC_DECOMP].req_q.req_bitmap);
+   kfree(ctx->qp_ctx[HZIP_QPC_DECOMP].req_q.req_bitmap);
 err_free_loop0:
-   kfree(ctx->qp_ctx[QPC_COMP].req_q.q);
+   kfree(ctx->qp_ctx[HZIP_QPC_COMP].req_q.q);
 err_free_bitmap:
-   kfree(ctx->qp_ctx[QPC_COMP].req_q.req_bitmap);
+   kfree(ctx->qp_ctx[HZIP_QPC_COMP].req_q.req_bitmap);
return ret;
 }

@@ -303,8 +306,8 @@ static int hisi_zip_create_sgl_pool(struct hisi_zip_ctx 
*ctx)
return 0;

 err_free_sgl_pool0:
-   hisi_acc_free_sgl_pool(&ctx->qp_ctx[QPC_COMP].qp->qm->pdev->dev,
-  ctx->qp_ctx[QPC_COMP].sgl_pool);
+   hisi_acc_free_sgl_pool(&ctx->qp_ctx[HZIP_QPC_COMP].qp->qm->pdev->dev,
+  ctx->qp_ctx[HZIP_QPC_COMP].sgl_pool);
return -ENOMEM;
 }

@@ -539,7 +542,7 @@ static int hisi_zip_do_work(struct hisi_zip_req *req,
 static int hisi_zip_acompress(struct acomp_req *acomp_req)
 {
struct hisi_zip_ctx *ctx = crypto_tfm_ctx(acomp_req->base.tfm);
-   struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[QPC_COMP];
+   struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[HZIP_QPC_COMP];
struct hisi_zip_req *req;
int head_size;
int ret;
@@ -563,7 +566,7 @@ static int hisi_zip_acompress(struct acomp_req *acomp_req)
 static int hisi_zip_adecompress(struct acomp_req *acomp_req)
 {
struct hisi_zip_ctx *ctx = crypto_tfm_ctx(acomp_req->base.tfm);
-   struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[QPC_DECOMP];
+   struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[HZIP_QPC_DECOMP];
struct hisi_zip_req *req;
size_t head_size;
int ret;
--
2.7.4



Re: [v7, PATCH 6/7] drm/mediatek: add fifo_size into rdma private data

2020-07-24 Thread Chun-Kuang Hu
The primary thing of this patch is to get fifo size from device tree.
So you may modify title to show the primary thing.

Yongqiang Niu  於 2020年7月23日 週四 上午10:12寫道:
>
> the fifo size of rdma in mt8183 is different.
> rdma0 fifo size is 5k
> rdma1 fifo size is 2k

I would like the description to be "Get the fifo size from device tree
because each rdma in the same SoC may have different fifo size."

Regards,
Chun-Kuang.

>
> Signed-off-by: Yongqiang Niu 
> ---
>  drivers/gpu/drm/mediatek/mtk_disp_rdma.c | 19 ++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_disp_rdma.c 
> b/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
> index e04319f..794acc5 100644
> --- a/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
> +++ b/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
> @@ -63,6 +63,7 @@ struct mtk_disp_rdma {
> struct mtk_ddp_comp ddp_comp;
> struct drm_crtc *crtc;
> const struct mtk_disp_rdma_data *data;
> +   u32 fifo_size;
>  };
>
>  static inline struct mtk_disp_rdma *comp_to_rdma(struct mtk_ddp_comp *comp)
> @@ -131,12 +132,18 @@ static void mtk_rdma_config(struct mtk_ddp_comp *comp, 
> unsigned int width,
> unsigned int threshold;
> unsigned int reg;
> struct mtk_disp_rdma *rdma = comp_to_rdma(comp);
> +   u32 rdma_fifo_size;
>
> mtk_ddp_write_mask(cmdq_pkt, width, comp,
>DISP_REG_RDMA_SIZE_CON_0, 0xfff);
> mtk_ddp_write_mask(cmdq_pkt, height, comp,
>DISP_REG_RDMA_SIZE_CON_1, 0xf);
>
> +   if (rdma->fifo_size)
> +   rdma_fifo_size = rdma->fifo_size;
> +   else
> +   rdma_fifo_size = RDMA_FIFO_SIZE(rdma);
> +
> /*
>  * Enable FIFO underflow since DSI and DPI can't be blocked.
>  * Keep the FIFO pseudo size reset default of 8 KiB. Set the
> @@ -145,7 +152,7 @@ static void mtk_rdma_config(struct mtk_ddp_comp *comp, 
> unsigned int width,
>  */
> threshold = width * height * vrefresh * 4 * 7 / 100;
> reg = RDMA_FIFO_UNDERFLOW_EN |
> - RDMA_FIFO_PSEUDO_SIZE(RDMA_FIFO_SIZE(rdma)) |
> + RDMA_FIFO_PSEUDO_SIZE(rdma_fifo_size) |
>   RDMA_OUTPUT_VALID_FIFO_THRESHOLD(threshold);
> mtk_ddp_write(cmdq_pkt, reg, comp, DISP_REG_RDMA_FIFO_CON);
>  }
> @@ -291,6 +298,16 @@ static int mtk_disp_rdma_probe(struct platform_device 
> *pdev)
> return comp_id;
> }
>
> +   if (of_find_property(dev->of_node, "mediatek,rdma_fifo_size", &ret)) {
> +   ret = of_property_read_u32(dev->of_node,
> +  "mediatek,rdma_fifo_size",
> +  &priv->fifo_size);
> +   if (ret) {
> +   dev_err(dev, "Failed to get rdma fifo size\n");
> +   return ret;
> +   }
> +   }
> +
> ret = mtk_ddp_comp_init(dev, dev->of_node, &priv->ddp_comp, comp_id,
> &mtk_disp_rdma_funcs);
> if (ret) {
> --
> 1.8.1.1.dirty
> ___
> Linux-mediatek mailing list
> linux-media...@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-mediatek


[PATCH v6 0/5] Add USB PHY support for new Ingenic SoCs.

2020-07-24 Thread Zhou Yanjie
v5->v6:
1.Fix the warning that appears during compilation.
2.Used the generic PHY framework API to create the PHY,
  and move the driver to driver/phy/ingenic.

周琰杰 (Zhou Yanjie) (5):
  dt-bindings: USB: Add bindings for new Ingenic SoCs.
  USB: PHY: JZ4770: Unify code style and simplify code.
  USB: PHY: JZ4770: Add support for new Ingenic SoCs.
  USB: PHY: JZ4770: Reformat the code to align it.
  USB: PHY: JZ4770: Usethe generic PHY framework.

 .../bindings/usb/ingenic,jz4770-phy.yaml   |   6 +-
 drivers/phy/Kconfig|   1 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/ingenic/Kconfig|  12 +
 drivers/phy/ingenic/Makefile   |   2 +
 drivers/phy/ingenic/phy-ingenic-usb.c  | 403 +
 drivers/usb/phy/Kconfig|   8 -
 drivers/usb/phy/Makefile   |   1 -
 drivers/usb/phy/phy-jz4770.c   | 243 -
 9 files changed, 424 insertions(+), 253 deletions(-)
 create mode 100644 drivers/phy/ingenic/Kconfig
 create mode 100644 drivers/phy/ingenic/Makefile
 create mode 100644 drivers/phy/ingenic/phy-ingenic-usb.c
 delete mode 100644 drivers/usb/phy/phy-jz4770.c

-- 
2.11.0



[PATCH v6 1/5] dt-bindings: USB: Add bindings for new Ingenic SoCs.

2020-07-24 Thread Zhou Yanjie
Add the USB PHY bindings for the JZ4780 SoC, the X1000 SoC and
the X1830 SoC from Ingenic.

Tested-by: 周正 (Zhou Zheng) 
Signed-off-by: 周琰杰 (Zhou Yanjie) 
Acked-by: Rob Herring 
---

Notes:
v1->v2:
Add bindings for the JZ4780 SoC.

v2->v3:
No change.

v3->v4:
No change.

v4->v5:
No change.

v5->v6:
No change.

 Documentation/devicetree/bindings/usb/ingenic,jz4770-phy.yaml | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/usb/ingenic,jz4770-phy.yaml 
b/Documentation/devicetree/bindings/usb/ingenic,jz4770-phy.yaml
index a81b0b1a2226..2d61166ea5cf 100644
--- a/Documentation/devicetree/bindings/usb/ingenic,jz4770-phy.yaml
+++ b/Documentation/devicetree/bindings/usb/ingenic,jz4770-phy.yaml
@@ -4,10 +4,11 @@
 $id: http://devicetree.org/schemas/usb/ingenic,jz4770-phy.yaml#
 $schema: http://devicetree.org/meta-schemas/core.yaml#
 
-title: Ingenic JZ4770 USB PHY devicetree bindings
+title: Ingenic SoCs USB PHY devicetree bindings
 
 maintainers:
   - Paul Cercueil 
+  - 周琰杰 (Zhou Yanjie) 
 
 properties:
   $nodename:
@@ -16,6 +17,9 @@ properties:
   compatible:
 enum:
   - ingenic,jz4770-phy
+  - ingenic,jz4780-phy
+  - ingenic,x1000-phy
+  - ingenic,x1830-phy
 
   reg:
 maxItems: 1
-- 
2.11.0



[PATCH v6 2/5] USB: PHY: JZ4770: Unify code style and simplify code.

2020-07-24 Thread Zhou Yanjie
1.Modify the macro definition to unify "#define USBPCR_ n"
  into the "#define USBPCR_ (n << USBPCR__LSB)" style,
  so as to unify the code style in the "jz4770_phy_init()" and
  simplify the code.
2.Remove unused macro definitions to simplify the code.

Tested-by: 周正 (Zhou Zheng) 
Suggested-by: Paul Cercueil 
Signed-off-by: 周琰杰 (Zhou Yanjie) 
---

Notes:
v5:
New patch.

v5->v6:
No change.

 drivers/usb/phy/phy-jz4770.c | 34 +++---
 1 file changed, 11 insertions(+), 23 deletions(-)

diff --git a/drivers/usb/phy/phy-jz4770.c b/drivers/usb/phy/phy-jz4770.c
index 8f62dc2a90ff..00209d5469d3 100644
--- a/drivers/usb/phy/phy-jz4770.c
+++ b/drivers/usb/phy/phy-jz4770.c
@@ -20,8 +20,6 @@
 /* USBPCR */
 #define USBPCR_USB_MODEBIT(31)
 #define USBPCR_AVLD_REGBIT(30)
-#define USBPCR_INCRM   BIT(27)
-#define USBPCR_CLK12_ENBIT(26)
 #define USBPCR_COMMONONN   BIT(25)
 #define USBPCR_VBUSVLDEXT  BIT(24)
 #define USBPCR_VBUSVLDEXTSEL   BIT(23)
@@ -32,45 +30,39 @@
 
 #define USBPCR_IDPULLUP_LSB28
 #define USBPCR_IDPULLUP_MASK   GENMASK(29, USBPCR_IDPULLUP_LSB)
-#define USBPCR_IDPULLUP_ALWAYS (3 << USBPCR_IDPULLUP_LSB)
-#define USBPCR_IDPULLUP_SUSPEND(1 << USBPCR_IDPULLUP_LSB)
-#define USBPCR_IDPULLUP_OTG(0 << USBPCR_IDPULLUP_LSB)
+#define USBPCR_IDPULLUP_ALWAYS (0x2 << USBPCR_IDPULLUP_LSB)
+#define USBPCR_IDPULLUP_SUSPEND(0x1 << USBPCR_IDPULLUP_LSB)
+#define USBPCR_IDPULLUP_OTG(0x0 << USBPCR_IDPULLUP_LSB)
 
 #define USBPCR_COMPDISTUNE_LSB 17
 #define USBPCR_COMPDISTUNE_MASKGENMASK(19, USBPCR_COMPDISTUNE_LSB)
-#define USBPCR_COMPDISTUNE_DFT 4
+#define USBPCR_COMPDISTUNE_DFT (0x4 << USBPCR_COMPDISTUNE_LSB)
 
 #define USBPCR_OTGTUNE_LSB 14
 #define USBPCR_OTGTUNE_MASKGENMASK(16, USBPCR_OTGTUNE_LSB)
-#define USBPCR_OTGTUNE_DFT 4
+#define USBPCR_OTGTUNE_DFT (0x4 << USBPCR_OTGTUNE_LSB)
 
 #define USBPCR_SQRXTUNE_LSB11
 #define USBPCR_SQRXTUNE_MASK   GENMASK(13, USBPCR_SQRXTUNE_LSB)
-#define USBPCR_SQRXTUNE_DFT3
+#define USBPCR_SQRXTUNE_DFT(0x3 << USBPCR_SQRXTUNE_LSB)
 
 #define USBPCR_TXFSLSTUNE_LSB  7
 #define USBPCR_TXFSLSTUNE_MASK GENMASK(10, USBPCR_TXFSLSTUNE_LSB)
-#define USBPCR_TXFSLSTUNE_DFT  3
+#define USBPCR_TXFSLSTUNE_DFT  (0x3 << USBPCR_TXFSLSTUNE_LSB)
 
 #define USBPCR_TXRISETUNE_LSB  4
 #define USBPCR_TXRISETUNE_MASK GENMASK(5, USBPCR_TXRISETUNE_LSB)
-#define USBPCR_TXRISETUNE_DFT  3
+#define USBPCR_TXRISETUNE_DFT  (0x3 << USBPCR_TXRISETUNE_LSB)
 
 #define USBPCR_TXVREFTUNE_LSB  0
 #define USBPCR_TXVREFTUNE_MASK GENMASK(3, USBPCR_TXVREFTUNE_LSB)
-#define USBPCR_TXVREFTUNE_DFT  5
+#define USBPCR_TXVREFTUNE_DFT  (0x5 << USBPCR_TXVREFTUNE_LSB)
 
 /* USBRDT */
 #define USBRDT_VBFIL_LD_EN BIT(25)
 #define USBRDT_IDDIG_ENBIT(24)
 #define USBRDT_IDDIG_REG   BIT(23)
 
-#define USBRDT_USBRDT_LSB  0
-#define USBRDT_USBRDT_MASK GENMASK(22, USBRDT_USBRDT_LSB)
-
-/* USBPCR1 */
-#define USBPCR1_UHC_POWON  BIT(5)
-
 struct jz4770_phy {
struct usb_phy phy;
struct usb_otg otg;
@@ -136,12 +128,8 @@ static int jz4770_phy_init(struct usb_phy *phy)
}
 
reg = USBPCR_AVLD_REG | USBPCR_COMMONONN | USBPCR_IDPULLUP_ALWAYS |
-   (USBPCR_COMPDISTUNE_DFT << USBPCR_COMPDISTUNE_LSB) |
-   (USBPCR_OTGTUNE_DFT << USBPCR_OTGTUNE_LSB) |
-   (USBPCR_SQRXTUNE_DFT << USBPCR_SQRXTUNE_LSB) |
-   (USBPCR_TXFSLSTUNE_DFT << USBPCR_TXFSLSTUNE_LSB) |
-   (USBPCR_TXRISETUNE_DFT << USBPCR_TXRISETUNE_LSB) |
-   (USBPCR_TXVREFTUNE_DFT << USBPCR_TXVREFTUNE_LSB) |
+   USBPCR_COMPDISTUNE_DFT | USBPCR_OTGTUNE_DFT | 
USBPCR_SQRXTUNE_DFT |
+   USBPCR_TXFSLSTUNE_DFT | USBPCR_TXRISETUNE_DFT | 
USBPCR_TXVREFTUNE_DFT |
USBPCR_POR;
writel(reg, priv->base + REG_USBPCR_OFFSET);
 
-- 
2.11.0



[PATCH v6 3/5] USB: PHY: JZ4770: Add support for new Ingenic SoCs.

2020-07-24 Thread Zhou Yanjie
Add support for probing the phy-jz4770 driver on the JZ4780 SoC,
the X1000 SoC and the X1830 SoC from Ingenic.

Tested-by: 周正 (Zhou Zheng) 
Co-developed-by: 漆鹏振 (Qi Pengzhen) 
Signed-off-by: 漆鹏振 (Qi Pengzhen) 
Signed-off-by: 周琰杰 (Zhou Yanjie) 
---

Notes:
v1->v2:
Add bindings for the JZ4780 SoC.

v2->v3:
Use "of_device_get_match_data" instead "of_match_device"
to get version information.

v3->v4:
Fix typos.

v4->v5:
1.Modify the help message, make it more future-proof.
2.Drop the unnecessary comment about hardware reset.
3.Create 'soc_info' structures instead having ID_* as platform data.

v5->v6:
Fix the warning that appears during compilation.
Reported-by: kernel test robot 

 drivers/usb/phy/Kconfig  |   4 +-
 drivers/usb/phy/phy-jz4770.c | 206 ---
 2 files changed, 177 insertions(+), 33 deletions(-)

diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index 4b3fa78995cf..ef4787cd3d37 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -185,11 +185,11 @@ config USB_ULPI_VIEWPORT
  controllers with a viewport register (e.g. Chipidea/ARC controllers).
 
 config JZ4770_PHY
-   tristate "Ingenic JZ4770 Transceiver Driver"
+   tristate "Ingenic SoCs Transceiver Driver"
depends on MIPS || COMPILE_TEST
select USB_PHY
help
  This driver provides PHY support for the USB controller found
- on the JZ4770 SoC from Ingenic.
+ on the JZ-series and X-series SoCs from Ingenic.
 
 endmenu
diff --git a/drivers/usb/phy/phy-jz4770.c b/drivers/usb/phy/phy-jz4770.c
index 00209d5469d3..b1540e059a09 100644
--- a/drivers/usb/phy/phy-jz4770.c
+++ b/drivers/usb/phy/phy-jz4770.c
@@ -1,7 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Ingenic JZ4770 USB PHY driver
+ * Ingenic SoCs USB PHY driver
  * Copyright (c) Paul Cercueil 
+ * Copyright (c) 漆鹏振 (Qi Pengzhen) 
+ * Copyright (c) 周琰杰 (Zhou Yanjie) 
  */
 
 #include 
@@ -12,12 +14,13 @@
 #include 
 #include 
 
+/* OTGPHY register offsets */
 #define REG_USBPCR_OFFSET  0x00
 #define REG_USBRDT_OFFSET  0x04
 #define REG_USBVBFIL_OFFSET0x08
 #define REG_USBPCR1_OFFSET 0x0c
 
-/* USBPCR */
+/* bits within the USBPCR register */
 #define USBPCR_USB_MODEBIT(31)
 #define USBPCR_AVLD_REGBIT(30)
 #define USBPCR_COMMONONN   BIT(25)
@@ -44,11 +47,21 @@
 
 #define USBPCR_SQRXTUNE_LSB11
 #define USBPCR_SQRXTUNE_MASK   GENMASK(13, USBPCR_SQRXTUNE_LSB)
+#define USBPCR_SQRXTUNE_DCR_20PCT  (0x7 << USBPCR_SQRXTUNE_LSB)
 #define USBPCR_SQRXTUNE_DFT(0x3 << USBPCR_SQRXTUNE_LSB)
 
 #define USBPCR_TXFSLSTUNE_LSB  7
 #define USBPCR_TXFSLSTUNE_MASK GENMASK(10, USBPCR_TXFSLSTUNE_LSB)
+#define USBPCR_TXFSLSTUNE_DCR_50PPT(0xf << USBPCR_TXFSLSTUNE_LSB)
+#define USBPCR_TXFSLSTUNE_DCR_25PPT(0x7 << USBPCR_TXFSLSTUNE_LSB)
 #define USBPCR_TXFSLSTUNE_DFT  (0x3 << USBPCR_TXFSLSTUNE_LSB)
+#define USBPCR_TXFSLSTUNE_INC_25PPT(0x1 << USBPCR_TXFSLSTUNE_LSB)
+#define USBPCR_TXFSLSTUNE_INC_50PPT(0x0 << USBPCR_TXFSLSTUNE_LSB)
+
+#define USBPCR_TXHSXVTUNE_LSB  4
+#define USBPCR_TXHSXVTUNE_MASK GENMASK(5, USBPCR_TXHSXVTUNE_LSB)
+#define USBPCR_TXHSXVTUNE_DFT  (0x3 << USBPCR_TXHSXVTUNE_LSB)
+#define USBPCR_TXHSXVTUNE_DCR_15MV (0x1 << USBPCR_TXHSXVTUNE_LSB)
 
 #define USBPCR_TXRISETUNE_LSB  4
 #define USBPCR_TXRISETUNE_MASK GENMASK(5, USBPCR_TXRISETUNE_LSB)
@@ -56,14 +69,40 @@
 
 #define USBPCR_TXVREFTUNE_LSB  0
 #define USBPCR_TXVREFTUNE_MASK GENMASK(3, USBPCR_TXVREFTUNE_LSB)
+#define USBPCR_TXVREFTUNE_INC_25PPT(0x7 << USBPCR_TXVREFTUNE_LSB)
 #define USBPCR_TXVREFTUNE_DFT  (0x5 << USBPCR_TXVREFTUNE_LSB)
 
-/* USBRDT */
+/* bits within the USBRDTR register */
+#define USBRDT_UTMI_RSTBIT(27)
+#define USBRDT_HB_MASK BIT(26)
 #define USBRDT_VBFIL_LD_EN BIT(25)
 #define USBRDT_IDDIG_ENBIT(24)
 #define USBRDT_IDDIG_REG   BIT(23)
+#define USBRDT_VBFIL_ENBIT(2)
+
+/* bits within the USBPCR1 register */
+#define USBPCR1_BVLD_REG   BIT(31)
+#define USBPCR1_DPPD   BIT(29)
+#define USBPCR1_DMPD   BIT(28)
+#define USBPCR1_USB_SELBIT(28)
+#define USBPCR1_WORD_IF_16BIT  BIT(19)
+
+enum ingenic_usb_phy_version {
+   ID_JZ4770,
+   ID_JZ4780,
+   ID_X1000,
+   ID_X1830,
+};
+
+struct ingenic_soc_info {
+   enum ingenic_usb_phy_version version;
+
+   void (*usb_phy_init)(struct usb_phy *phy);
+};
 
 struct jz4770_phy {
+   const struct ingenic_soc_info *soc_info;
+
struct usb_phy phy;
struct usb_otg otg;
struct device *dev;
@@ -82,12 +121,18 @@ static inline struct jz4770_phy *phy_to_jz4770_phy(struct 
usb_phy *phy)
return container_of(phy, struct jz

[PATCH v6 4/5] USB: PHY: JZ4770: Reformat the code to align it.

2020-07-24 Thread Zhou Yanjie
Reformat the code (add one level of indentation before the values),
to align the code in the macro definition section.

Tested-by: 周正 (Zhou Zheng) 
Co-developed-by: 漆鹏振 (Qi Pengzhen) 
Signed-off-by: 漆鹏振 (Qi Pengzhen) 
Signed-off-by: 周琰杰 (Zhou Yanjie) 
---

Notes:
v1->v2:
Add support for the JZ4780 SoC.

v2->v3:
No change.

v3->v4:
No change.

v4->v5:
No change.

v5->v6:
No change.

 drivers/usb/phy/phy-jz4770.c | 74 ++--
 1 file changed, 37 insertions(+), 37 deletions(-)

diff --git a/drivers/usb/phy/phy-jz4770.c b/drivers/usb/phy/phy-jz4770.c
index b1540e059a09..23d38cbc150e 100644
--- a/drivers/usb/phy/phy-jz4770.c
+++ b/drivers/usb/phy/phy-jz4770.c
@@ -15,46 +15,46 @@
 #include 
 
 /* OTGPHY register offsets */
-#define REG_USBPCR_OFFSET  0x00
-#define REG_USBRDT_OFFSET  0x04
-#define REG_USBVBFIL_OFFSET0x08
-#define REG_USBPCR1_OFFSET 0x0c
+#define REG_USBPCR_OFFSET  0x00
+#define REG_USBRDT_OFFSET  0x04
+#define REG_USBVBFIL_OFFSET0x08
+#define REG_USBPCR1_OFFSET 0x0c
 
 /* bits within the USBPCR register */
-#define USBPCR_USB_MODEBIT(31)
-#define USBPCR_AVLD_REGBIT(30)
-#define USBPCR_COMMONONN   BIT(25)
-#define USBPCR_VBUSVLDEXT  BIT(24)
-#define USBPCR_VBUSVLDEXTSEL   BIT(23)
-#define USBPCR_POR BIT(22)
-#define USBPCR_SIDDQ   BIT(21)
-#define USBPCR_OTG_DISABLE BIT(20)
-#define USBPCR_TXPREEMPHTUNE   BIT(6)
+#define USBPCR_USB_MODEBIT(31)
+#define USBPCR_AVLD_REGBIT(30)
+#define USBPCR_COMMONONN   BIT(25)
+#define USBPCR_VBUSVLDEXT  BIT(24)
+#define USBPCR_VBUSVLDEXTSEL   BIT(23)
+#define USBPCR_POR BIT(22)
+#define USBPCR_SIDDQ   BIT(21)
+#define USBPCR_OTG_DISABLE BIT(20)
+#define USBPCR_TXPREEMPHTUNE   BIT(6)
 
 #define USBPCR_IDPULLUP_LSB28
-#define USBPCR_IDPULLUP_MASK   GENMASK(29, USBPCR_IDPULLUP_LSB)
-#define USBPCR_IDPULLUP_ALWAYS (0x2 << USBPCR_IDPULLUP_LSB)
-#define USBPCR_IDPULLUP_SUSPEND(0x1 << USBPCR_IDPULLUP_LSB)
-#define USBPCR_IDPULLUP_OTG(0x0 << USBPCR_IDPULLUP_LSB)
+#define USBPCR_IDPULLUP_MASK   GENMASK(29, USBPCR_IDPULLUP_LSB)
+#define USBPCR_IDPULLUP_ALWAYS (0x2 << USBPCR_IDPULLUP_LSB)
+#define USBPCR_IDPULLUP_SUSPEND(0x1 << USBPCR_IDPULLUP_LSB)
+#define USBPCR_IDPULLUP_OTG(0x0 << USBPCR_IDPULLUP_LSB)
 
-#define USBPCR_COMPDISTUNE_LSB 17
-#define USBPCR_COMPDISTUNE_MASKGENMASK(19, USBPCR_COMPDISTUNE_LSB)
-#define USBPCR_COMPDISTUNE_DFT (0x4 << USBPCR_COMPDISTUNE_LSB)
+#define USBPCR_COMPDISTUNE_LSB 17
+#define USBPCR_COMPDISTUNE_MASKGENMASK(19, 
USBPCR_COMPDISTUNE_LSB)
+#define USBPCR_COMPDISTUNE_DFT (0x4 << USBPCR_COMPDISTUNE_LSB)
 
-#define USBPCR_OTGTUNE_LSB 14
-#define USBPCR_OTGTUNE_MASKGENMASK(16, USBPCR_OTGTUNE_LSB)
-#define USBPCR_OTGTUNE_DFT (0x4 << USBPCR_OTGTUNE_LSB)
+#define USBPCR_OTGTUNE_LSB 14
+#define USBPCR_OTGTUNE_MASKGENMASK(16, USBPCR_OTGTUNE_LSB)
+#define USBPCR_OTGTUNE_DFT (0x4 << USBPCR_OTGTUNE_LSB)
 
 #define USBPCR_SQRXTUNE_LSB11
-#define USBPCR_SQRXTUNE_MASK   GENMASK(13, USBPCR_SQRXTUNE_LSB)
+#define USBPCR_SQRXTUNE_MASK   GENMASK(13, USBPCR_SQRXTUNE_LSB)
 #define USBPCR_SQRXTUNE_DCR_20PCT  (0x7 << USBPCR_SQRXTUNE_LSB)
-#define USBPCR_SQRXTUNE_DFT(0x3 << USBPCR_SQRXTUNE_LSB)
+#define USBPCR_SQRXTUNE_DFT(0x3 << USBPCR_SQRXTUNE_LSB)
 
-#define USBPCR_TXFSLSTUNE_LSB  7
-#define USBPCR_TXFSLSTUNE_MASK GENMASK(10, USBPCR_TXFSLSTUNE_LSB)
+#define USBPCR_TXFSLSTUNE_LSB  7
+#define USBPCR_TXFSLSTUNE_MASK GENMASK(10, USBPCR_TXFSLSTUNE_LSB)
 #define USBPCR_TXFSLSTUNE_DCR_50PPT(0xf << USBPCR_TXFSLSTUNE_LSB)
 #define USBPCR_TXFSLSTUNE_DCR_25PPT(0x7 << USBPCR_TXFSLSTUNE_LSB)
-#define USBPCR_TXFSLSTUNE_DFT  (0x3 << USBPCR_TXFSLSTUNE_LSB)
+#define USBPCR_TXFSLSTUNE_DFT  (0x3 << USBPCR_TXFSLSTUNE_LSB)
 #define USBPCR_TXFSLSTUNE_INC_25PPT(0x1 << USBPCR_TXFSLSTUNE_LSB)
 #define USBPCR_TXFSLSTUNE_INC_50PPT(0x0 << USBPCR_TXFSLSTUNE_LSB)
 
@@ -63,21 +63,21 @@
 #define USBPCR_TXHSXVTUNE_DFT  (0x3 << USBPCR_TXHSXVTUNE_LSB)
 #define USBPCR_TXHSXVTUNE_DCR_15MV (0x1 << USBPCR_TXHSXVTUNE_LSB)
 
-#define USBPCR_TXRISETUNE_LSB  4
-#define USBPCR_TXRISETUNE_MASK GENMASK(5, USBPCR_TXRISETUNE_LSB)
-#define USBPCR_TXRISETUNE_DFT  (0x3 << USBPCR_TXRISETUNE_LSB)
+#define USBPCR_TXRISETUNE_LSB  4
+#define USBPCR_TXRISETUNE_MASK GENMASK(5, USBPCR_TXRISETUNE_LSB)
+#define USBPCR_TXRISETUNE_DFT  (0x3 << USBPCR_TXRISETUNE_LSB)
 
-#define USBPCR_TXVR

[PATCH v8 2/5] ACPI/PCI: Ignore _OSC negotiation result if pcie_ports_native is set.

2020-07-24 Thread sathyanarayanan . kuppuswamy
From: Kuppuswamy Sathyanarayanan 

pcie_ports_native is set only if user requests native handling
of PCIe capabilities via pcie_port_setup command line option.
User input takes precedence over _OSC based control negotiation
result. So consider the _OSC negotiated result only if
pcie_ports_native is unset.

Also, since struct pci_host_bridge ->native_* members caches the
ownership status of various PCIe capabilities, use them instead
of distributed checks for pcie_ports_native.

Signed-off-by: Kuppuswamy Sathyanarayanan 

---
 drivers/acpi/pci_root.c   | 61 ++-
 drivers/pci/hotplug/pciehp_core.c |  2 +-
 drivers/pci/pci-acpi.c|  3 --
 drivers/pci/pcie/aer.c|  2 +-
 drivers/pci/pcie/portdrv_core.c   |  9 ++---
 5 files changed, 56 insertions(+), 21 deletions(-)

diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index f90e841c59f5..f8981d4e044d 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -145,6 +145,17 @@ static struct pci_osc_bit_struct pci_osc_control_bit[] = {
{ OSC_PCI_EXPRESS_DPC_CONTROL, "DPC" },
 };
 
+static char *get_osc_desc(u32 bit)
+{
+   int i = 0;
+
+   for (i = 0; i < ARRAY_SIZE(pci_osc_control_bit); i++)
+   if (bit == pci_osc_control_bit[i].bit)
+   return pci_osc_control_bit[i].desc;
+
+   return NULL;
+}
+
 static void decode_osc_bits(struct acpi_pci_root *root, char *msg, u32 word,
struct pci_osc_bit_struct *table, int size)
 {
@@ -914,18 +925,48 @@ struct pci_bus *acpi_pci_root_create(struct acpi_pci_root 
*root,
goto out_release_info;
 
host_bridge = to_pci_host_bridge(bus->bridge);
-   if (!(root->osc_control_set & OSC_PCI_EXPRESS_NATIVE_HP_CONTROL))
-   host_bridge->native_pcie_hotplug = 0;
+   if (!(root->osc_control_set & OSC_PCI_EXPRESS_NATIVE_HP_CONTROL)) {
+   if (!pcie_ports_native)
+   host_bridge->native_pcie_hotplug = 0;
+   else
+   dev_warn(&bus->dev, "OS overrides %s firmware control",
+   get_osc_desc(OSC_PCI_EXPRESS_NATIVE_HP_CONTROL));
+   }
+
if (!(root->osc_control_set & OSC_PCI_SHPC_NATIVE_HP_CONTROL))
host_bridge->native_shpc_hotplug = 0;
-   if (!(root->osc_control_set & OSC_PCI_EXPRESS_AER_CONTROL))
-   host_bridge->native_aer = 0;
-   if (!(root->osc_control_set & OSC_PCI_EXPRESS_PME_CONTROL))
-   host_bridge->native_pme = 0;
-   if (!(root->osc_control_set & OSC_PCI_EXPRESS_LTR_CONTROL))
-   host_bridge->native_ltr = 0;
-   if (!(root->osc_control_set & OSC_PCI_EXPRESS_DPC_CONTROL))
-   host_bridge->native_dpc = 0;
+
+   if (!(root->osc_control_set & OSC_PCI_EXPRESS_AER_CONTROL)) {
+   if (!pcie_ports_native)
+   host_bridge->native_aer = 0;
+   else
+   dev_warn(&bus->dev, "OS overrides %s firmware control",
+   get_osc_desc(OSC_PCI_EXPRESS_AER_CONTROL));
+   }
+
+   if (!(root->osc_control_set & OSC_PCI_EXPRESS_PME_CONTROL)) {
+   if (!pcie_ports_native)
+   host_bridge->native_pme = 0;
+   else
+   dev_warn(&bus->dev, "OS overrides %s firmware control",
+   get_osc_desc(OSC_PCI_EXPRESS_PME_CONTROL));
+   }
+
+   if (!(root->osc_control_set & OSC_PCI_EXPRESS_LTR_CONTROL)) {
+   if (!pcie_ports_native)
+   host_bridge->native_ltr = 0;
+   else
+   dev_warn(&bus->dev, "OS overrides %s firmware control",
+   get_osc_desc(OSC_PCI_EXPRESS_LTR_CONTROL));
+   }
+
+   if (!(root->osc_control_set & OSC_PCI_EXPRESS_DPC_CONTROL)) {
+   if (!pcie_ports_native)
+   host_bridge->native_dpc = 0;
+   else
+   dev_warn(&bus->dev, "OS overrides %s firmware control",
+   get_osc_desc(OSC_PCI_EXPRESS_DPC_CONTROL));
+   }
 
/*
 * Evaluate the "PCI Boot Configuration" _DSM Function.  If it
diff --git a/drivers/pci/hotplug/pciehp_core.c 
b/drivers/pci/hotplug/pciehp_core.c
index bf779f291f15..5fc999bf6f1b 100644
--- a/drivers/pci/hotplug/pciehp_core.c
+++ b/drivers/pci/hotplug/pciehp_core.c
@@ -255,7 +255,7 @@ static bool pme_is_native(struct pcie_device *dev)
const struct pci_host_bridge *host;
 
host = pci_find_host_bridge(dev->port->bus);
-   return pcie_ports_native || host->native_pme;
+   return host->native_pme;
 }
 
 static void pciehp_disable_interrupt(struct pcie_device *dev)
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index 7224b1e5f2a8..e09589571a9d 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -800,9 +800,6 @@ bool pciehp_is_native(struct pc

[PATCH v8 5/5] PCI/DPC: Move AER/DPC dependency checks out of DPC driver

2020-07-24 Thread sathyanarayanan . kuppuswamy
From: Kuppuswamy Sathyanarayanan 

Currently, AER and DPC Capabilities dependency checks is
distributed between DPC and portdrv service drivers. So move
them out of DPC driver.

Also, since services & PCIE_PORT_SERVICE_AER check already
ensures AER native ownership, no need to add additional
pcie_aer_is_native() check.

Signed-off-by: Kuppuswamy Sathyanarayanan 

---
 drivers/pci/pcie/dpc.c  | 3 ---
 drivers/pci/pcie/portdrv_core.c | 1 +
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/pci/pcie/dpc.c b/drivers/pci/pcie/dpc.c
index 5b1025a2994d..3efbe43764f3 100644
--- a/drivers/pci/pcie/dpc.c
+++ b/drivers/pci/pcie/dpc.c
@@ -285,9 +285,6 @@ static int dpc_probe(struct pcie_device *dev)
int status;
u16 ctl, cap;
 
-   if (!pcie_aer_is_native(pdev) && !host->native_dpc)
-   return -ENOTSUPP;
-
status = devm_request_threaded_irq(device, dev->irq, dpc_irq,
   dpc_handler, IRQF_SHARED,
   "pcie-dpc", pdev);
diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
index e257a2ca3595..ffa1d9fc458e 100644
--- a/drivers/pci/pcie/portdrv_core.c
+++ b/drivers/pci/pcie/portdrv_core.c
@@ -252,6 +252,7 @@ static int get_port_device_capability(struct pci_dev *dev)
 * permission to use AER.
 */
if (pci_find_ext_capability(dev, PCI_EXT_CAP_ID_DPC) &&
+   host->native_dpc &&
(host->native_dpc || (services & PCIE_PORT_SERVICE_AER)))
services |= PCIE_PORT_SERVICE_DPC;
 
-- 
2.17.1



[PATCH v8 4/5] PCI/portdrv: Remove redundant pci_aer_available() check in DPC enable logic

2020-07-24 Thread sathyanarayanan . kuppuswamy
From: Kuppuswamy Sathyanarayanan 

In DPC service enable logic, check for
services & PCIE_PORT_SERVICE_AER implies pci_aer_available()
is true. So there is no need to explicitly check it again.

Also, passing pcie_ports=dpc-native in kernel command line
implies DPC needs to be enabled in native mode irrespective
of AER ownership status. So checking for pci_aer_available()
without checking for pcie_ports status is incorrect.

Signed-off-by: Kuppuswamy Sathyanarayanan 

---
 drivers/pci/pcie/portdrv_core.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
index 2c0278f0fdcc..e257a2ca3595 100644
--- a/drivers/pci/pcie/portdrv_core.c
+++ b/drivers/pci/pcie/portdrv_core.c
@@ -252,7 +252,6 @@ static int get_port_device_capability(struct pci_dev *dev)
 * permission to use AER.
 */
if (pci_find_ext_capability(dev, PCI_EXT_CAP_ID_DPC) &&
-   pci_aer_available() &&
(host->native_dpc || (services & PCIE_PORT_SERVICE_AER)))
services |= PCIE_PORT_SERVICE_DPC;
 
-- 
2.17.1



[PATCH v8 3/5] ACPI/PCI: Ignore _OSC DPC negotiation result if pcie_ports_dpc_native is set.

2020-07-24 Thread sathyanarayanan . kuppuswamy
From: Kuppuswamy Sathyanarayanan 

pcie_ports_dpc_native is set only if user requests native handling
of PCIe DPC capability via pcie_port_setup command line option.
User input takes precedence over _OSC based control negotiation
result. So consider the _OSC negotiated result for DPC ownership
only if pcie_ports_dpc_native is unset.

Signed-off-by: Kuppuswamy Sathyanarayanan 

---
 drivers/acpi/pci_root.c | 2 +-
 drivers/pci/pcie/dpc.c  | 3 ++-
 drivers/pci/pcie/portdrv.h  | 2 --
 drivers/pci/pcie/portdrv_core.c | 2 +-
 include/linux/pci.h | 2 ++
 5 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index f8981d4e044d..3942bb42cb93 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -961,7 +961,7 @@ struct pci_bus *acpi_pci_root_create(struct acpi_pci_root 
*root,
}
 
if (!(root->osc_control_set & OSC_PCI_EXPRESS_DPC_CONTROL)) {
-   if (!pcie_ports_native)
+   if (!pcie_ports_native && !pcie_ports_dpc_native)
host_bridge->native_dpc = 0;
else
dev_warn(&bus->dev, "OS overrides %s firmware control",
diff --git a/drivers/pci/pcie/dpc.c b/drivers/pci/pcie/dpc.c
index daa9a4153776..5b1025a2994d 100644
--- a/drivers/pci/pcie/dpc.c
+++ b/drivers/pci/pcie/dpc.c
@@ -280,11 +280,12 @@ void pci_dpc_init(struct pci_dev *pdev)
 static int dpc_probe(struct pcie_device *dev)
 {
struct pci_dev *pdev = dev->port;
+   struct pci_host_bridge *host = pci_find_host_bridge(pdev->bus);
struct device *device = &dev->device;
int status;
u16 ctl, cap;
 
-   if (!pcie_aer_is_native(pdev) && !pcie_ports_dpc_native)
+   if (!pcie_aer_is_native(pdev) && !host->native_dpc)
return -ENOTSUPP;
 
status = devm_request_threaded_irq(device, dev->irq, dpc_irq,
diff --git a/drivers/pci/pcie/portdrv.h b/drivers/pci/pcie/portdrv.h
index af7cf237432a..0ac20feef24e 100644
--- a/drivers/pci/pcie/portdrv.h
+++ b/drivers/pci/pcie/portdrv.h
@@ -25,8 +25,6 @@
 
 #define PCIE_PORT_DEVICE_MAXSERVICES   5
 
-extern bool pcie_ports_dpc_native;
-
 #ifdef CONFIG_PCIEAER
 int pcie_aer_init(void);
 int pcie_aer_is_native(struct pci_dev *dev);
diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
index ccd5e0ce5605..2c0278f0fdcc 100644
--- a/drivers/pci/pcie/portdrv_core.c
+++ b/drivers/pci/pcie/portdrv_core.c
@@ -253,7 +253,7 @@ static int get_port_device_capability(struct pci_dev *dev)
 */
if (pci_find_ext_capability(dev, PCI_EXT_CAP_ID_DPC) &&
pci_aer_available() &&
-   (pcie_ports_dpc_native || (services & PCIE_PORT_SERVICE_AER)))
+   (host->native_dpc || (services & PCIE_PORT_SERVICE_AER)))
services |= PCIE_PORT_SERVICE_DPC;
 
if (pci_pcie_type(dev) == PCI_EXP_TYPE_DOWNSTREAM ||
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 34c1c4f45288..fe7ce06a4f40 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1556,9 +1556,11 @@ static inline int pci_irqd_intx_xlate(struct irq_domain 
*d,
 #ifdef CONFIG_PCIEPORTBUS
 extern bool pcie_ports_disabled;
 extern bool pcie_ports_native;
+extern bool pcie_ports_dpc_native;
 #else
 #define pcie_ports_disabledtrue
 #define pcie_ports_native  false
+#define pcie_ports_dpc_native  false
 #endif
 
 #define PCIE_LINK_STATE_L0SBIT(0)
-- 
2.17.1



[PATCH v8 0/5] Simplify PCIe native ownership detection logic

2020-07-24 Thread sathyanarayanan . kuppuswamy
From: Kuppuswamy Sathyanarayanan 

Currently, PCIe capabilities ownership status is detected by
verifying the status of pcie_ports_native, pcie_ports_dpc_native
and _OSC negotiated results (cached in  struct pci_host_bridge
->native_* members). But this logic can be simplified, and we can
use only struct pci_host_bridge ->native_* members to detect it. 

This patchset removes the distributed checks for pcie_ports_native,
pcie_ports_dpc_native parameters.

Changes since v7:
 * Fixed "fix array_size.cocci warnings".

Changes since v6:
 * Created new patch for CONFIG_PCIEPORTBUS check in
   pci_init_host_bridge().
 * Added warning message for a case when pcie_ports_native
   overrides _OSC negotiation result.

Changes since v5:
 * Rebased on top of v5.8-rc1

Changes since v4:
 * Changed the patch set title (Original link: 
https://lkml.org/lkml/2020/5/26/1710)
 * Added AER/DPC dependency logic cleanup fixes.
 

Kuppuswamy Sathyanarayanan (5):
  PCI: Conditionally initialize host bridge native_* members
  ACPI/PCI: Ignore _OSC negotiation result if pcie_ports_native is set.
  ACPI/PCI: Ignore _OSC DPC negotiation result if pcie_ports_dpc_native
is set.
  PCI/portdrv: Remove redundant pci_aer_available() check in DPC enable
logic
  PCI/DPC: Move AER/DPC dependency checks out of DPC driver

 drivers/acpi/pci_root.c   | 61 ++-
 drivers/pci/hotplug/pciehp_core.c |  2 +-
 drivers/pci/pci-acpi.c|  3 --
 drivers/pci/pcie/aer.c|  2 +-
 drivers/pci/pcie/dpc.c|  4 +-
 drivers/pci/pcie/portdrv.h|  2 -
 drivers/pci/pcie/portdrv_core.c   | 13 +++
 drivers/pci/probe.c   |  4 +-
 include/linux/pci.h   |  2 +
 9 files changed, 64 insertions(+), 29 deletions(-)

-- 
2.17.1



[PATCH v8 1/5] PCI: Conditionally initialize host bridge native_* members

2020-07-24 Thread sathyanarayanan . kuppuswamy
From: Kuppuswamy Sathyanarayanan 

If CONFIG_PCIEPORTBUS is not enabled in kernel then initialing
struct pci_host_bridge PCIe specific native_* members to "1" is
incorrect. So protect the PCIe specific member initialization
with CONFIG_PCIEPORTBUS.

Signed-off-by: Kuppuswamy Sathyanarayanan 

---
 drivers/pci/probe.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 2f66988cea25..a94b97564ceb 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -588,12 +588,14 @@ static void pci_init_host_bridge(struct pci_host_bridge 
*bridge)
 * may implement its own AER handling and use _OSC to prevent the
 * OS from interfering.
 */
+#ifdef CONFIG_PCIEPORTBUS
bridge->native_aer = 1;
bridge->native_pcie_hotplug = 1;
-   bridge->native_shpc_hotplug = 1;
bridge->native_pme = 1;
bridge->native_ltr = 1;
bridge->native_dpc = 1;
+#endif
+   bridge->native_shpc_hotplug = 1;
 
device_initialize(&bridge->dev);
 }
-- 
2.17.1



Re: [PATCH v3 0/3] Add functions to operate USB PHY related clock.

2020-07-24 Thread Zhou Yanjie

Gentle ping.

在 2020/7/1 上午12:38, 周琰杰 (Zhou Yanjie) 写道:

v2->v3:
1.Remove the wrong "WARN()".
2.Remove extra blank line.
3.Fix wrong parameters in recalc_rate/set_rate functions.

周琰杰 (Zhou Yanjie) (3):
   clk: JZ4780: Add functions for enable and disable USB PHY.
   clk: JZ4780: Reformat the code to align it.
   clk: X1000: Add support for calculat REFCLK of USB PHY.

  drivers/clk/ingenic/jz4780-cgu.c | 153 ---
  drivers/clk/ingenic/x1000-cgu.c  |  84 -
  2 files changed, 162 insertions(+), 75 deletions(-)



[PATCH 14216/14216] ALSA: usb-audio: This patch for prevent auto wakeup from s3 trig by usb disconnect signal from Lenovo Thinkcentre TI024Gen3 USB-audio.

2020-07-24 Thread penghao
From: "peng...@deepin.com" 

 TI024Gen3 USB-audio is controlled by TI024Gen3,when TI024Gens
 enter sleep mode, USB-audio will disconnect from USB bus port,
 so disabled the /sys/bus/usb/*/power/wakeup Fixesimmediately
 wakup form s3 state

Signed-off-by: peng...@uniontech.com 
Signed-off-by: peng...@deepin.com 
---
 sound/usb/card.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/sound/usb/card.c b/sound/usb/card.c
index 2644a5ae2b75..969c3809e051 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -640,6 +640,12 @@ static int usb_audio_probe(struct usb_interface *intf,
}
}
dev_set_drvdata(&dev->dev, chip);
+   /*
+* ALSA: usb-audio: Add prevent wakeup from s3 state trig by lenovo
+* ThinkCentre TI024Gen3 USB-audio
+*/
+   if ((usb_id->idVendor == 0x17ef) && (usb_id->idProduct == 0xa012))
+   device_set_wakeup_enable(&dev->dev, 0);
 
/*
 * For devices with more than one control interface, we assume the
@@ -914,3 +920,4 @@ static struct usb_driver usb_audio_driver = {
 };
 
 module_usb_driver(usb_audio_driver);
+
-- 
2.11.0





[PATCH v2 01/18] gpio: uapi: define GPIO_MAX_NAME_SIZE for array sizes

2020-07-24 Thread Kent Gibson
Replace constant array sizes with a macro constant to clarify the source
of array sizes, provide a place to document any constraints on the size,
and to simplify array sizing in userspace if constructing structs
from their composite fields.

Signed-off-by: Kent Gibson 
---

This change is not terribly important for V1, but in adding V2 more
documentation for the usage of this value is appropriate.
As it is also used with V1 it warrants a separate patch.

 include/uapi/linux/gpio.h | 17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/include/uapi/linux/gpio.h b/include/uapi/linux/gpio.h
index 9c27cecf406f..285cc10355b2 100644
--- a/include/uapi/linux/gpio.h
+++ b/include/uapi/linux/gpio.h
@@ -14,6 +14,11 @@
 #include 
 #include 
 
+/*
+ * The maximum size of name and label arrays.
+ */
+#define GPIO_MAX_NAME_SIZE 32
+
 /**
  * struct gpiochip_info - Information about a certain GPIO chip
  * @name: the Linux kernel name of this GPIO chip
@@ -22,8 +27,8 @@
  * @lines: number of GPIO lines on this chip
  */
 struct gpiochip_info {
-   char name[32];
-   char label[32];
+   char name[GPIO_MAX_NAME_SIZE];
+   char label[GPIO_MAX_NAME_SIZE];
__u32 lines;
 };
 
@@ -52,8 +57,8 @@ struct gpiochip_info {
 struct gpioline_info {
__u32 line_offset;
__u32 flags;
-   char name[32];
-   char consumer[32];
+   char name[GPIO_MAX_NAME_SIZE];
+   char consumer[GPIO_MAX_NAME_SIZE];
 };
 
 /* Maximum number of requested handles */
@@ -123,7 +128,7 @@ struct gpiohandle_request {
__u32 lineoffsets[GPIOHANDLES_MAX];
__u32 flags;
__u8 default_values[GPIOHANDLES_MAX];
-   char consumer_label[32];
+   char consumer_label[GPIO_MAX_NAME_SIZE];
__u32 lines;
int fd;
 };
@@ -182,7 +187,7 @@ struct gpioevent_request {
__u32 lineoffset;
__u32 handleflags;
__u32 eventflags;
-   char consumer_label[32];
+   char consumer_label[GPIO_MAX_NAME_SIZE];
int fd;
 };
 
-- 
2.27.0



[PATCH v2 00/18] gpio: cdev: add uAPI V2

2020-07-24 Thread Kent Gibson
This patchset defines and implements adds a new version of the
GPIO CDEV uAPI to address existing 32/64-bit alignment issues, add
support for debounce, event sequence numbers, and allowing for requested
lines with different configurations.
It provides some future proofing by adding optional configuration fields
and padding reserved for future use.

The series can be partitioned into two sets; the first eleven
contain the V2 uAPI implementation, and the final seven port
the GPIO tools to the V2 uAPI and extend them to use new uAPI features.

The more complicated patches include their own commentary where
appropriate.

Cheers,
Kent.

Changes since v1:
 - split out cleanup patches into a separate series.
 - split implementation patch into a patch for each ioctl or major feature.
 - split tool port patch into a patch per tool.
 - rework uAPI to allow requested lines with different configurations.

Kent Gibson (18):
  gpio: uapi: define GPIO_MAX_NAME_SIZE for array sizes
  gpio: uapi: define uAPI v2
  gpiolib: make cdev a build option
  gpiolib: add build option for CDEV v1 ABI
  gpiolib: cdev: support GPIO_GET_LINE_IOCTL and
GPIOLINE_GET_VALUES_IOCTL
  gpiolib: cdev: support GPIO_GET_LINEINFO_V2_IOCTL and
GPIO_GET_LINEINFO_WATCH_V2_IOCTL
  gpiolib: cdev: support edge detection for uAPI v2
  gpiolib: cdev: support GPIOLINE_SET_CONFIG_IOCTL
  gpiolib: cdev: support GPIOLINE_SET_VALUES_IOCTL
  gpiolib: cdev: support setting debounce
  gpio: uapi: document uAPI v1 as deprecated
  tools: gpio: port lsgpio to v2 uAPI
  tools: gpio: port gpio-watch to v2 uAPI
  tools: gpio: rename nlines to num_lines
  tools: gpio: port gpio-hammer to v2 uAPI
  tools: gpio: port gpio-event-mon to v2 uAPI
  tools: gpio: add debounce support to gpio-event-mon
  tools: gpio: add multi-line monitoring to gpio-event-mon

 drivers/gpio/Kconfig|   28 +-
 drivers/gpio/Makefile   |2 +-
 drivers/gpio/gpiolib-cdev.c | 1296 ++-
 drivers/gpio/gpiolib-cdev.h |   15 +
 drivers/gpio/gpiolib.c  |2 +
 drivers/gpio/gpiolib.h  |6 +
 include/uapi/linux/gpio.h   |  327 -
 tools/gpio/gpio-event-mon.c |  137 ++--
 tools/gpio/gpio-hammer.c|   27 +-
 tools/gpio/gpio-utils.c |  117 ++--
 tools/gpio/gpio-utils.h |   48 +-
 tools/gpio/gpio-watch.c |   10 +-
 tools/gpio/lsgpio.c |  102 ++-
 13 files changed, 1882 insertions(+), 235 deletions(-)


base-commit: 8fc3ed3a474d76cd76dd0a154ea904373e9a5530
-- 
2.27.0



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

2020-07-24 Thread Kent Gibson
Make the gpiolib-cdev module a build option.  This allows the CDEV
interface to be removed from the kernel to reduce kernel size in
applications where is it not required, and provides the parent for
other other CDEV interface specific build options to follow.

Suggested-by: Bartosz Golaszewski 
Signed-off-by: Kent Gibson 
---
 drivers/gpio/Kconfig| 16 ++--
 drivers/gpio/Makefile   |  2 +-
 drivers/gpio/gpiolib-cdev.h | 15 +++
 3 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 8030fd91a3cc..b5bb9efc1092 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -66,8 +66,20 @@ config GPIO_SYSFS
 
  This ABI is deprecated. If you want to use GPIO from userspace,
  use the character device /dev/gpiochipN with the appropriate
- ioctl() operations instead. The character device is always
- available.
+ ioctl() operations instead.
+
+config GPIO_CDEV
+   bool "/dev/gpiochipN (character device interface)"
+   default y
+   help
+ Say Y here to add the character device /dev/gpiochipN interface
+ for GPIOs. The character device allows userspace to control GPIOs
+ using ioctl() operations.
+
+ Only say N is you are sure that the GPIO character device is not
+ required.
+
+ If unsure, say Y.
 
 config GPIO_GENERIC
depends on HAS_IOMEM # Only for IOMEM drivers
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 4f9abff4f2dc..7c24c8d77068 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -7,8 +7,8 @@ obj-$(CONFIG_GPIOLIB)   += gpiolib.o
 obj-$(CONFIG_GPIOLIB)  += gpiolib-devres.o
 obj-$(CONFIG_GPIOLIB)  += gpiolib-legacy.o
 obj-$(CONFIG_GPIOLIB)  += gpiolib-devprop.o
-obj-$(CONFIG_GPIOLIB)  += gpiolib-cdev.o
 obj-$(CONFIG_OF_GPIO)  += gpiolib-of.o
+obj-$(CONFIG_GPIO_CDEV)+= gpiolib-cdev.o
 obj-$(CONFIG_GPIO_SYSFS)   += gpiolib-sysfs.o
 obj-$(CONFIG_GPIO_ACPI)+= gpiolib-acpi.o
 
diff --git a/drivers/gpio/gpiolib-cdev.h b/drivers/gpio/gpiolib-cdev.h
index 973578e7ad10..19a4e3d57120 100644
--- a/drivers/gpio/gpiolib-cdev.h
+++ b/drivers/gpio/gpiolib-cdev.h
@@ -5,7 +5,22 @@
 
 #include 
 
+#ifdef CONFIG_GPIO_CDEV
+
 int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt);
 void gpiolib_cdev_unregister(struct gpio_device *gdev);
 
+#else
+
+static inline int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt)
+{
+   return 0;
+}
+
+static inline void gpiolib_cdev_unregister(struct gpio_device *gdev)
+{
+}
+
+#endif /* CONFIG_GPIO_CDEV */
+
 #endif /* GPIOLIB_CDEV_H */
-- 
2.27.0



[PATCH v2 04/18] gpiolib: add build option for CDEV v1 ABI

2020-07-24 Thread Kent Gibson
Add a build option to allow the removal of the CDEV v1 ABI.

Suggested-by: Bartosz Golaszewski 
Signed-off-by: Kent Gibson 
---

This patch is before the V2 implementation, and is non-functional until
that patch, as some parts of that patch would be written slightly
differently if removing V1 was not considered.
Adding this patch after that would necessitate revisiting the V2 changes,
so this ordering results in two simpler patches.

 drivers/gpio/Kconfig | 12 
 1 file changed, 12 insertions(+)

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index b5bb9efc1092..d9775998a997 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -81,6 +81,18 @@ config GPIO_CDEV
 
  If unsure, say Y.
 
+config GPIO_CDEV_V1
+   bool "Support GPIO ABI Version 1"
+   default y
+   depends on GPIO_CDEV
+   help
+ Say Y here to support version 1 of the GPIO CDEV ABI.
+
+ This ABI version is deprecated and will be removed in the future.
+ Please use the latest ABI for new developments.
+
+ If unsure, say Y.
+
 config GPIO_GENERIC
depends on HAS_IOMEM # Only for IOMEM drivers
tristate
-- 
2.27.0



[PATCH v2 02/18] gpio: uapi: define uAPI v2

2020-07-24 Thread Kent Gibson
Add a new version of the uAPI to address existing 32/64-bit alignment
issues, add support for debounce and event sequence numbers, and provide
some future proofing by adding padding reserved for future use.

The alignment issue relates to the gpioevent_data, which packs to different
sizes on 32-bit and 64-bit platforms. That creates problems for 32-bit apps
running on 64-bit kernels.  The patch addresses that particular issue, and
the problem more generally, by adding pad fields that explicitly pad
structs out to 64-bit boundaries, so they will pack to the same size now,
and even if some of the reserved padding is used for __u64 fields in the
future.

The lack of future proofing in v1 makes it impossible to, for example,
add the debounce feature that is included in v2.
The future proofing is addressed by providing reserved padding in all
structs for future features.  Specifically, the line request,
config, info, info_changed and event structs receive updated versions,
and the first three new ioctls.

Signed-off-by: Kent Gibson 
---

I haven't added any padding to gpiochip_info, as I haven't seen any calls
for new features for the corresponding ioctl, but I'm open to updating that
as well.

As the majority of the structs and ioctls were being replaced, it seemed
opportune to rework some of the other aspects of the uAPI.

Firstly, I've reworked the flags field throughout.  v1 has three different
flags fields, each with their own separate bit definitions.  In v2 that is
collapsed to one.

I've also merged the handle and event requests into a single request, the
line request, as the two requests were mostly the same, other than the
edge detection provided by event requests.  As a byproduct, the v2 uAPI
allows for multiple lines producing edge events on the same line handle.
This is a new capability as v1 only supports a single line in an event
request.

This means there are now only two types of file handle to be concerned with,
the chip and the line, and it is clearer which ioctls apply to which type
of handle.

There is also some minor renaming of fields for consistency compared to
their v1 counterparts, e.g. offset rather than lineoffset or line_offset,
and consumer rather than consumer_label.

Additionally, v1 GPIOHANDLES_MAX becomes GPIOLINES_MAX in v2 for clarity,
and the gpiohandle_data __u8 array becomes a bitmap gpioline_values.

The v2 uAPI is mostly just a reorganisation of v1, so userspace code,
particularly libgpiod, should easily port to it.

Changes since v1:
 - lower case V1 and V2, except in capitalized names
 - hyphenate 32/64-bit
 - rename bitmap field to bits
 - drop PAD_SIZE consts in favour of hard coded numbers
 - sort includes
 - change config flags to __u64
 - increase padding of gpioline_event
 - relocate GPIOLINE_CHANGED enum into v2 section (is common with v1)
 - rework config to collapse direction, drive, bias and edge enums back
   into flags and add optional attributes that can be associated with a
   subset of the requested lines.

Changes since the RFC:
 - document the constraints on array sizes to maintain 32/64 alignment
 - add sequence numbers to gpioline_event
 - use bitmap for values instead of array of __u8
 - gpioline_info_v2 contains gpioline_config instead of its composite fields
 - provide constants for all array sizes, especially padding
 - renamed "GPIOLINE_FLAG_V2_KERNEL" to "GPIOLINE_FLAG_V2_USED"
 - renamed "default_values" to "values"
 - made gpioline_direction zero based
 - document clock used in gpioline_event timestamp
 - add event_buffer_size to gpioline_request
 - rename debounce to debounce_period
 - rename lines to num_lines
 
 include/uapi/linux/gpio.h | 284 --
 1 file changed, 270 insertions(+), 14 deletions(-)

diff --git a/include/uapi/linux/gpio.h b/include/uapi/linux/gpio.h
index 285cc10355b2..3f6db33014f0 100644
--- a/include/uapi/linux/gpio.h
+++ b/include/uapi/linux/gpio.h
@@ -12,10 +12,13 @@
 #define _UAPI_GPIO_H_
 
 #include 
+#include 
 #include 
 
 /*
  * The maximum size of name and label arrays.
+ *
+ * Must be a multiple of 8 to ensure 32/64-bit alignment of structs.
  */
 #define GPIO_MAX_NAME_SIZE 32
 
@@ -32,6 +35,251 @@ struct gpiochip_info {
__u32 lines;
 };
 
+/*
+ * Maximum number of requested lines.
+ *
+ * Must be a multiple of 8 to ensure 32/64-bit alignment of structs.
+ */
+#define GPIOLINES_MAX 64
+
+/* The number of __u64 required for a bitmap for GPIOLINES_MAX lines */
+#define GPIOLINES_BITMAP_SIZE  __KERNEL_DIV_ROUND_UP(GPIOLINES_MAX, 64)
+
+/*
+ * The maximum number of configuration attributes associated with a line
+ * request.
+ */
+#define GPIOLINE_NUM_ATTRS_MAX 10
+
+/**
+ * enum gpioline_flag_v2 - &struct gpioline_attribute.flags values
+ */
+enum gpioline_flag_v2 {
+   GPIOLINE_FLAG_V2_USED   = 1UL << 0, /* line is not 
available for request */
+   GPIOLINE_FLAG_V2_ACTIVE_LOW = 1UL << 1,
+   GPIOLINE_FLAG_V2_INPUT  = 

[PATCH v2 09/18] gpiolib: cdev: support GPIOLINE_SET_VALUES_IOCTL

2020-07-24 Thread Kent Gibson
Add support for the GPIOLINE_SET_VALUES_IOCTL.

Signed-off-by: Kent Gibson 
---
 drivers/gpio/gpiolib-cdev.c | 66 +
 1 file changed, 66 insertions(+)

diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index 4822cb10aa40..0482a16388a0 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -785,6 +785,70 @@ static long line_get_values(struct line *line, void __user 
*ip)
return 0;
 }
 
+static long line_set_values_locked(struct line *line,
+  struct gpioline_set_values *lsv)
+{
+   unsigned long *vals = (unsigned long *)lsv->bits;
+   unsigned long *mask = (unsigned long *)lsv->mask;
+   struct gpio_desc **descs;
+   int ret, i, didx, num_set = 0;
+
+   for (i = 0; i < line->num_descs; i++) {
+   if (test_bit(i, mask)) {
+   if (!test_bit(FLAG_IS_OUT, &line->descs[i]->flags))
+   return -EPERM;
+   num_set++;
+   }
+   }
+   if (num_set == 0)
+   return -EINVAL;
+
+   if (num_set == line->num_descs)
+   /* Reuse the array setting function */
+   return gpiod_set_array_value_complex(false,
+true,
+line->num_descs,
+line->descs,
+NULL,
+vals);
+
+   /* build compacted desc array and values */
+   descs = kmalloc_array(num_set, sizeof(*descs), GFP_KERNEL);
+   for (didx = 0, i = 0; i < line->num_descs; i++) {
+   if (test_bit(i, mask)) {
+   descs[didx] = line->descs[i];
+   assign_bit(didx, vals, test_bit(i, vals));
+   didx++;
+   }
+   }
+   ret = gpiod_set_array_value_complex(false,
+   true,
+   num_set,
+   descs,
+   NULL,
+   vals);
+
+   kfree(descs);
+   return ret;
+}
+
+static long line_set_values(struct line *line, void __user *ip)
+{
+   struct gpioline_set_values lsv;
+   int ret;
+
+   if (copy_from_user(&lsv, ip, sizeof(lsv)))
+   return -EFAULT;
+
+   mutex_lock(&line->config_mutex);
+
+   ret = line_set_values_locked(line, &lsv);
+
+   mutex_unlock(&line->config_mutex);
+
+   return ret;
+}
+
 static long line_set_config_locked(struct line *line,
   struct gpioline_config *lc)
 {
@@ -853,6 +917,8 @@ static long line_ioctl(struct file *file, unsigned int cmd,
 
if (cmd == GPIOLINE_GET_VALUES_IOCTL)
return line_get_values(line, ip);
+   else if (cmd == GPIOLINE_SET_VALUES_IOCTL)
+   return line_set_values(line, ip);
else if (cmd == GPIOLINE_SET_CONFIG_IOCTL)
return line_set_config(line, ip);
 
-- 
2.27.0



[PATCH v2 10/18] gpiolib: cdev: support setting debounce

2020-07-24 Thread Kent Gibson
Add support for setting debounce on a line via the GPIO uAPI.
Where debounce is not supported by hardware, a software debounce is
provided.

Signed-off-by: Kent Gibson 
---

The implementation of the software debouncer waits for the line to be
stable for the debounce period before determining if a level change,
and a corresponding edge event, has occurred.  This provides maximum
protection against glitches, but also introduces a debounce_period
latency to edge events.

The software debouncer is integrated with the edge detection as it
utilises the line interrupt, and integration is simpler than getting
the two to interwork.  Where software debounce AND edge detection is
required, the debouncer provides both.

Due to the tight integration between the debouncer and edge detection,
and to avoid particular corner cases, it is not allowed to alter the
debounce value if edge detection is enabled.  Changing the debounce with
edge detection enabled is a very unlikely use case, so it is preferable
to disallow it rather than complicate the code to allow it.
Should the user wish to alter the debounce value in such cases they will
need to release and re-request the line.

Changes since v1:
 - improve documentation on fields shared by threads.
 - use READ_ONCE/WRITE_ONCE for shared fields rather than atomic_t
   which was overkill.


 drivers/gpio/gpiolib-cdev.c | 261 +++-
 drivers/gpio/gpiolib.h  |   4 +
 2 files changed, 260 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index 9f2f3336c62a..b6761d267a7d 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -6,6 +6,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -22,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "gpiolib.h"
@@ -394,6 +396,9 @@ static int linehandle_create(struct gpio_device *gdev, void 
__user *ip)
  * for the corresponding line request. Ths is drawn from the @line.
  * @line_seqno: the seqno for the current edge event in the sequence of
  * events for this line.
+ * @work: the worker that implements software debouncing
+ * @sw_debounced: flag indicating if the software debouncer is active
+ * @level: the current debounced physical level of the line
  */
 struct edge_detector {
struct line *line;
@@ -405,7 +410,27 @@ struct edge_detector {
 */
u64 timestamp;
u32 seqno;
+   /*
+* line_seqno is used by either edge_irq_thread() or
+* debounce_work_func() which are themselves mutually exclusive.
+*/
u32 line_seqno;
+   /*
+* -- debouncer specific fields --
+*/
+   struct delayed_work work;
+   /*
+* sw_debounce is shared by line_set_config(), which is the only
+* setter, and line_ioctl(), which can live with a slightly stale
+* value.
+*/
+   unsigned int sw_debounced;
+   /*
+* level is shared by debounce_work_func(), which is the only
+* setter, and line_ioctl() which can live with a slightly stale
+* value.
+*/
+   unsigned int level;
 };
 
 /**
@@ -523,6 +548,10 @@ static int edge_detector_start(struct edge_detector *edet)
int ret, irq, irqflags = 0;
struct gpio_desc *desc;
 
+   if (READ_ONCE(edet->sw_debounced))
+   /* debouncer is setup and will provide edge detection */
+   return 0;
+
desc = edge_detector_desc(edet);
irq = gpiod_to_irq(desc);
 
@@ -554,17 +583,212 @@ static int edge_detector_start(struct edge_detector 
*edet)
return 0;
 }
 
+/*
+ * returns the current debounced logical value.
+ */
+static int debounced_value(struct edge_detector *edet)
+{
+   int value;
+
+   /*
+* minor race - debouncer may be stopped here, so edge_detector_stop
+* must leave the value unchanged so the following will read the level
+* from when the debouncer was last running.
+*/
+   value = READ_ONCE(edet->level);
+
+   if (test_bit(FLAG_ACTIVE_LOW, &edge_detector_desc(edet)->flags))
+   value = !value;
+
+   return value;
+}
+
+static irqreturn_t debounce_irq_handler(int irq, void *p)
+{
+   struct edge_detector *edet = p;
+   struct gpio_desc *desc = edge_detector_desc(edet);
+
+   mod_delayed_work(system_wq,
+&edet->work,
+usecs_to_jiffies(READ_ONCE(desc->debounce_period)));
+
+   return IRQ_HANDLED;
+}
+
+static void debounce_work_func(struct work_struct *work)
+{
+   struct gpioline_event le;
+   int ret, level;
+   struct edge_detector *edet =
+   container_of(work, struct edge_detector, work.work);
+   struct gpio_desc *desc = edge_detector_desc(edet);
+   struct line *line;
+
+   level = gpiod_get_raw_value_cansleep(desc);
+   if (level < 0) {
+   pr_debug_ratel

[PATCH v2 06/18] gpiolib: cdev: support GPIO_GET_LINEINFO_V2_IOCTL and GPIO_GET_LINEINFO_WATCH_V2_IOCTL

2020-07-24 Thread Kent Gibson
Add support for GPIO_GET_LINEINFO_V2_IOCTL and
GPIO_GET_LINEINFO_WATCH_V2_IOCTL.

Signed-off-by: Kent Gibson 
---

The core of this change is the event kfifo switching to contain
struct gpioline_info_changed_v2, instead of V1 as V2 is richer.

The two uAPI versions are mostly independent - other than where they both
provide line info changes via reads on the chip fd.  As the info change
structs differ between V1 and V2, the infowatch implementation tracks which
version of the infowatch ioctl, either GPIO_GET_LINEINFO_WATCH_IOCTL or
GPIO_GET_LINEINFO_WATCH_V2_IOCTL, initiates the initial watch and returns
the corresponding info change struct to the read.  The version supported
on that fd locks to that version on the first watch request, so subsequent
watches from that process must use the same uAPI version.

drivers/gpio/gpiolib-cdev.c | 187 +++-
 1 file changed, 164 insertions(+), 23 deletions(-)

diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index 0908ae117b7d..1f282207fb70 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -1108,10 +1108,52 @@ static int lineevent_create(struct gpio_device *gdev, 
void __user *ip)
return ret;
 }
 
+static void gpioline_info_v2_to_v1(struct gpioline_info_v2 *info_v2,
+  struct gpioline_info *info_v1)
+{
+   int flagsv2 = info_v2->flags;
+
+   strncpy(info_v1->name, info_v2->name, sizeof(info_v1->name));
+   strncpy(info_v1->consumer, info_v2->consumer,
+   sizeof(info_v1->consumer));
+   info_v1->line_offset = info_v2->offset;
+   info_v1->flags = 0;
+
+   if (flagsv2 & GPIOLINE_FLAG_V2_USED)
+   info_v1->flags |= GPIOLINE_FLAG_KERNEL;
+
+   if (flagsv2 & GPIOLINE_FLAG_V2_OUTPUT)
+   info_v1->flags |= GPIOLINE_FLAG_IS_OUT;
+
+   if (flagsv2 & GPIOLINE_FLAG_V2_ACTIVE_LOW)
+   info_v1->flags |= GPIOLINE_FLAG_ACTIVE_LOW;
+
+   if (flagsv2 & GPIOLINE_FLAG_V2_OPEN_DRAIN)
+   info_v1->flags |= GPIOLINE_FLAG_OPEN_DRAIN;
+   if (flagsv2 & GPIOLINE_FLAG_V2_OPEN_SOURCE)
+   info_v1->flags |= GPIOLINE_FLAG_OPEN_SOURCE;
+
+   if (flagsv2 & GPIOLINE_FLAG_V2_BIAS_PULL_UP)
+   info_v1->flags |= GPIOLINE_FLAG_BIAS_PULL_UP;
+   if (flagsv2 & GPIOLINE_FLAG_V2_BIAS_PULL_DOWN)
+   info_v1->flags |= GPIOLINE_FLAG_BIAS_PULL_DOWN;
+   if (flagsv2 & GPIOLINE_FLAG_V2_BIAS_DISABLED)
+   info_v1->flags |= GPIOLINE_FLAG_BIAS_DISABLE;
+}
+
+static void gpioline_info_changed_v2_to_v1(
+   struct gpioline_info_changed_v2 *lic_v2,
+   struct gpioline_info_changed *lic_v1)
+{
+   gpioline_info_v2_to_v1(&lic_v2->info, &lic_v1->info);
+   lic_v1->timestamp = lic_v2->timestamp;
+   lic_v1->event_type = lic_v2->event_type;
+}
+
 #endif /* CONFIG_GPIO_CDEV_V1 */
 
 static void gpio_desc_to_lineinfo(struct gpio_desc *desc,
- struct gpioline_info *info)
+ struct gpioline_info_v2 *info)
 {
struct gpio_chip *gc = desc->gdev->chip;
bool ok_for_pinctrl;
@@ -1125,7 +1167,7 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *desc,
 * lock common to both frameworks?
 */
ok_for_pinctrl =
-   pinctrl_gpio_can_use_line(gc->base + info->line_offset);
+   pinctrl_gpio_can_use_line(gc->base + info->offset);
 
spin_lock_irqsave(&gpio_lock, flags);
 
@@ -1154,23 +1196,27 @@ static void gpio_desc_to_lineinfo(struct gpio_desc 
*desc,
test_bit(FLAG_EXPORT, &desc->flags) ||
test_bit(FLAG_SYSFS, &desc->flags) ||
!ok_for_pinctrl)
-   info->flags |= GPIOLINE_FLAG_KERNEL;
+   info->flags |= GPIOLINE_FLAG_V2_USED;
+
if (test_bit(FLAG_IS_OUT, &desc->flags))
-   info->flags |= GPIOLINE_FLAG_IS_OUT;
+   info->flags |= GPIOLINE_FLAG_V2_OUTPUT;
+   else
+   info->flags |= GPIOLINE_FLAG_V2_INPUT;
+
if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
-   info->flags |= GPIOLINE_FLAG_ACTIVE_LOW;
+   info->flags |= GPIOLINE_FLAG_V2_ACTIVE_LOW;
+
if (test_bit(FLAG_OPEN_DRAIN, &desc->flags))
-   info->flags |= (GPIOLINE_FLAG_OPEN_DRAIN |
-   GPIOLINE_FLAG_IS_OUT);
+   info->flags |= GPIOLINE_FLAG_V2_OPEN_DRAIN;
if (test_bit(FLAG_OPEN_SOURCE, &desc->flags))
-   info->flags |= (GPIOLINE_FLAG_OPEN_SOURCE |
-   GPIOLINE_FLAG_IS_OUT);
+   info->flags |= GPIOLINE_FLAG_V2_OPEN_SOURCE;
+
if (test_bit(FLAG_BIAS_DISABLE, &desc->flags))
-   info->flags |= GPIOLINE_FLAG_BIAS_DISABLE;
+   info->flags |= GPIOLINE_FLAG_V2_BIAS_DISABLED;
if (test_bit(FLAG_PULL_DOWN, &desc->flags))
-   info->flags |= GPIOLINE_FLA

[PATCH v2 08/18] gpiolib: cdev: support GPIOLINE_SET_CONFIG_IOCTL

2020-07-24 Thread Kent Gibson
Add support for GPIOLINE_SET_CONFIG_IOCTL, the uAPI v2
line set config ioctl.

Signed-off-by: Kent Gibson 
---
 drivers/gpio/gpiolib-cdev.c | 91 +
 1 file changed, 91 insertions(+)

diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index 8caebb460557..9d944ca0ff59 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -16,6 +16,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -417,6 +418,8 @@ struct edge_detector {
  * @seqno: the sequence number for edge events generated on all lines in
  * this line request.  Note that this is not used when @num_descs is 1, as
  * the line_seqno is then the same and is cheaper to calculate.
+ * @config_mutex: mutex for serializing ioctl() calls to ensure consistency
+ * of configuration, partiuclarly multi-step accesses to desc flags.
  * @edets: an array of edge detectors, of size @num_descs
  * @descs: the GPIO descriptors held by this line request, with @num_descs
  * elements.
@@ -428,6 +431,7 @@ struct line {
wait_queue_head_t wait;
DECLARE_KFIFO_PTR(events, struct gpioline_event);
atomic_t seqno;
+   struct mutex config_mutex;
struct edge_detector *edets;
/* descs must be last so it can be dynamically sized */
struct gpio_desc *descs[];
@@ -709,6 +713,30 @@ static int gpioline_config_validate(struct gpioline_config 
*lc, int num_lines)
return 0;
 }
 
+static int gpioline_config_change_validate(struct line *line,
+  struct gpioline_config *lc)
+{
+   int i;
+   u64 flags;
+   struct gpio_desc *desc;
+
+   for (i = 0; i < line->num_descs; i++) {
+   desc = line->descs[i];
+   flags = gpioline_config_flags(lc, i);
+   /* disallow edge detection changes */
+   if (line->edets[i].flags != (flags & GPIOLINE_EDGE_FLAGS))
+   return -EINVAL;
+
+   if (line->edets[i].flags) {
+   /* disallow polarity changes */
+   if (test_bit(FLAG_ACTIVE_LOW, &desc->flags) !=
+   ((flags & GPIOLINE_FLAG_V2_ACTIVE_LOW) != 0))
+   return -EINVAL;
+   }
+   }
+   return 0;
+}
+
 static void gpioline_config_flags_to_desc_flags(u64 flags,
unsigned long *flagsp)
 {
@@ -757,6 +785,66 @@ static long line_get_values(struct line *line, void __user 
*ip)
return 0;
 }
 
+static long line_set_config_locked(struct line *line,
+  struct gpioline_config *lc)
+{
+   struct gpio_desc *desc;
+   int i, ret;
+   u64 flags;
+
+   ret = gpioline_config_change_validate(line, lc);
+   if (ret)
+   return ret;
+
+   for (i = 0; i < line->num_descs; i++) {
+   desc = line->descs[i];
+   flags = gpioline_config_flags(lc, i);
+
+   gpioline_config_flags_to_desc_flags(flags, &desc->flags);
+   /*
+* Lines have to be requested explicitly for input
+* or output, else the line will be treated "as is".
+*/
+   if (flags & GPIOLINE_FLAG_V2_OUTPUT) {
+   int val = gpioline_config_output_value(lc, i);
+
+   edge_detector_stop(&line->edets[i]);
+   ret = gpiod_direction_output(desc, val);
+   if (ret)
+   return ret;
+   } else if (flags & GPIOLINE_FLAG_V2_INPUT) {
+   ret = gpiod_direction_input(desc);
+   if (ret)
+   return ret;
+   }
+
+   blocking_notifier_call_chain(&desc->gdev->notifier,
+GPIOLINE_CHANGED_CONFIG, desc);
+   }
+   return 0;
+}
+
+static long line_set_config(struct line *line, void __user *ip)
+{
+   struct gpioline_config lc;
+   int ret;
+
+   if (copy_from_user(&lc, ip, sizeof(lc)))
+   return -EFAULT;
+
+   ret = gpioline_config_validate(&lc, line->num_descs);
+   if (ret)
+   return ret;
+
+   mutex_lock(&line->config_mutex);
+
+   ret = line_set_config_locked(line, &lc);
+
+   mutex_unlock(&line->config_mutex);
+
+   return ret;
+}
+
 static long line_ioctl(struct file *file, unsigned int cmd,
   unsigned long arg)
 {
@@ -765,6 +853,8 @@ static long line_ioctl(struct file *file, unsigned int cmd,
 
if (cmd == GPIOLINE_GET_VALUES_IOCTL)
return line_get_values(line, ip);
+   else if (cmd == GPIOLINE_SET_CONFIG_IOCTL)
+   return line_set_config(line, ip);
 
return -EINVAL;
 }
@@ -937,6 +1027,7 @@ static int line_create(struct gpio_device *gdev, void 
__user *ip)
  

[PATCH v2 05/18] gpiolib: cdev: support GPIO_GET_LINE_IOCTL and GPIOLINE_GET_VALUES_IOCTL

2020-07-24 Thread Kent Gibson
Add support for requesting lines using the GPIO_GET_LINE_IOCTL, and
returning their current values using GPIOLINE_GET_VALUES_IOCTL.

Signed-off-by: Kent Gibson 
---

The struct line implementation is based on the V1 struct linehandle
implementation.

The line_ioctl() is a simple wrapper around line_get_values() here, but
will be extended with other ioctls in subsequent patches.

 drivers/gpio/gpiolib-cdev.c | 389 
 1 file changed, 389 insertions(+)

diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index e6c9b78adfc2..0908ae117b7d 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -1,7 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0
 
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -34,6 +36,7 @@
  * GPIO line handle management
  */
 
+#ifdef CONFIG_GPIO_CDEV_V1
 /**
  * struct linehandle_state - contains the state of a userspace handle
  * @gdev: the GPIO device the handle pertains to
@@ -376,6 +379,366 @@ static int linehandle_create(struct gpio_device *gdev, 
void __user *ip)
linehandle_free(lh);
return ret;
 }
+#endif /* CONFIG_GPIO_CDEV_V1 */
+
+/**
+ * struct line - contains the state of a userspace line request
+ * @gdev: the GPIO device the line request pertains to
+ * @label: consumer label used to tag descriptors
+ * @num_descs: the number of descriptors held in the descs array
+ * @descs: the GPIO descriptors held by this line request, with @num_descs
+ * elements.
+ */
+struct line {
+   struct gpio_device *gdev;
+   const char *label;
+   u32 num_descs;
+   /* descs must be last so it can be dynamically sized */
+   struct gpio_desc *descs[];
+};
+
+static bool padding_not_zeroed(__u32 *padding, int pad_size)
+{
+   int i, sum = 0;
+
+   for (i = 0; i < pad_size; i++)
+   sum |= padding[i];
+
+   return sum;
+}
+
+#define GPIOLINE_BIAS_FLAGS \
+   (GPIOLINE_FLAG_V2_BIAS_PULL_UP | \
+GPIOLINE_FLAG_V2_BIAS_PULL_DOWN | \
+GPIOLINE_FLAG_V2_BIAS_DISABLED)
+
+#define GPIOLINE_DIRECTION_FLAGS \
+   (GPIOLINE_FLAG_V2_INPUT | \
+GPIOLINE_FLAG_V2_OUTPUT)
+
+#define GPIOLINE_DRIVE_FLAGS \
+   (GPIOLINE_FLAG_V2_OPEN_DRAIN | \
+GPIOLINE_FLAG_V2_OPEN_SOURCE)
+
+#define GPIOLINE_VALID_FLAGS \
+   (GPIOLINE_FLAG_V2_ACTIVE_LOW | \
+GPIOLINE_DIRECTION_FLAGS | \
+GPIOLINE_DRIVE_FLAGS | \
+GPIOLINE_BIAS_FLAGS)
+
+static u64 gpioline_config_flags(struct gpioline_config *lc, int line_idx)
+{
+   int i;
+
+   for (i = lc->num_attrs - 1; i >= 0; i--) {
+   if ((lc->attrs[i].attr.id == GPIOLINE_ATTR_ID_FLAGS) &&
+   test_bit(line_idx, (unsigned long *)lc->attrs[i].mask))
+   return lc->attrs[i].attr.flags;
+   }
+   return lc->flags;
+}
+
+static int gpioline_config_output_value(struct gpioline_config *lc,
+   int line_idx)
+{
+   int i;
+
+   for (i = lc->num_attrs - 1; i >= 0; i--) {
+   if ((lc->attrs[i].attr.id == GPIOLINE_ATTR_ID_OUTPUT_VALUES) &&
+   test_bit(line_idx, (unsigned long *)lc->attrs[i].mask))
+   return test_bit(line_idx,
+   (unsigned long *)lc->attrs[i].attr.values.bits);
+   }
+   return 0;
+}
+
+static int gpioline_flags_validate(u64 flags)
+{
+   /* Return an error if an unknown flag is set */
+   if (flags & ~GPIOLINE_VALID_FLAGS)
+   return -EINVAL;
+
+   /*
+* Do not allow both INPUT & OUTPUT flags to be set as they are
+* contradictory.
+*/
+   if ((flags & GPIOLINE_FLAG_V2_INPUT) &&
+   (flags & GPIOLINE_FLAG_V2_OUTPUT))
+   return -EINVAL;
+
+   /*
+* Do not allow OPEN_SOURCE & OPEN_DRAIN flags in a single request. If
+* the hardware actually supports enabling both at the same time the
+* electrical result would be disastrous.
+*/
+   if ((flags & GPIOLINE_FLAG_V2_OPEN_DRAIN) &&
+   (flags & GPIOLINE_FLAG_V2_OPEN_SOURCE))
+   return -EINVAL;
+
+   /* Drive requires explicit output direction. */
+   if ((flags & GPIOLINE_DRIVE_FLAGS) &&
+   !(flags & GPIOLINE_FLAG_V2_OUTPUT))
+   return -EINVAL;
+
+   /* Bias requies explicit direction. */
+   if ((flags & GPIOLINE_BIAS_FLAGS) &&
+   !(flags & GPIOLINE_DIRECTION_FLAGS))
+   return -EINVAL;
+
+   /* Only one bias flag can be set. */
+   if (((flags & GPIOLINE_FLAG_V2_BIAS_DISABLED) &&
+(flags & (GPIOLINE_FLAG_V2_BIAS_PULL_DOWN |
+  GPIOLINE_FLAG_V2_BIAS_PULL_UP))) ||
+   ((flags & GPIOLINE_FLAG_V2_BIAS_PULL_DOWN) &&
+(flags & GPIOLINE_FLAG_V2_BIAS_PULL_UP)))
+   return -EINVAL;
+
+   return 0;
+}
+
+static int gpioline_config_validate(struct gpioline_co

[PATCH v2 07/18] gpiolib: cdev: support edge detection for uAPI v2

2020-07-24 Thread Kent Gibson
Add support for edge detection to lines requested using
GPIO_GET_LINE_IOCTL.

Signed-off-by: Kent Gibson 
---

The edge_detector implementation is based on the V1 lineevent implementation.

 drivers/gpio/gpiolib-cdev.c | 314 +++-
 drivers/gpio/gpiolib.c  |   2 +
 drivers/gpio/gpiolib.h  |   2 +
 3 files changed, 317 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index 1f282207fb70..8caebb460557 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -381,11 +381,43 @@ static int linehandle_create(struct gpio_device *gdev, 
void __user *ip)
 }
 #endif /* CONFIG_GPIO_CDEV_V1 */
 
+/**
+ * struct edge_detector - contains the state of a line edge detector
+ * @line: the corresponding line request
+ * @irq: the interrupt triggered in response to events on this GPIO
+ * @flags: the flags, GPIOLINE_FLAG_V2_EDGE_RISING and/or
+ * GPIOLINE_FLAG_V2_EDGE_FALLING, indicating the edge detection applied
+ * @timestamp: cache for the timestamp storing it between hardirq and IRQ
+ * thread, used to bring the timestamp close to the actual event
+ * @seqno: the seqno for the current edge event in the sequence of events
+ * for the corresponding line request. Ths is drawn from the @line.
+ * @line_seqno: the seqno for the current edge event in the sequence of
+ * events for this line.
+ */
+struct edge_detector {
+   struct line *line;
+   unsigned int irq;
+   u64 flags;
+   /*
+* timestamp and seqno are shared by edge_irq_handler() and
+* edge_irq_thread() which are themselves mutually exclusive.
+*/
+   u64 timestamp;
+   u32 seqno;
+   u32 line_seqno;
+};
+
 /**
  * struct line - contains the state of a userspace line request
  * @gdev: the GPIO device the line request pertains to
  * @label: consumer label used to tag descriptors
  * @num_descs: the number of descriptors held in the descs array
+ * @wait: wait queue that handles blocking reads of events
+ * @events: KFIFO for the GPIO events
+ * @seqno: the sequence number for edge events generated on all lines in
+ * this line request.  Note that this is not used when @num_descs is 1, as
+ * the line_seqno is then the same and is cheaper to calculate.
+ * @edets: an array of edge detectors, of size @num_descs
  * @descs: the GPIO descriptors held by this line request, with @num_descs
  * elements.
  */
@@ -393,10 +425,147 @@ struct line {
struct gpio_device *gdev;
const char *label;
u32 num_descs;
+   wait_queue_head_t wait;
+   DECLARE_KFIFO_PTR(events, struct gpioline_event);
+   atomic_t seqno;
+   struct edge_detector *edets;
/* descs must be last so it can be dynamically sized */
struct gpio_desc *descs[];
 };
 
+static inline struct gpio_desc *edge_detector_desc(
+   const struct edge_detector *edet)
+{
+   return edet->line->descs[edet - &edet->line->edets[0]];
+}
+
+static irqreturn_t edge_irq_thread(int irq, void *p)
+{
+   struct edge_detector *edet = p;
+   struct line *line = edet->line;
+   struct gpio_desc *desc = edge_detector_desc(edet);
+   struct gpioline_event le;
+   int ret;
+
+   /* Do not leak kernel stack to userspace */
+   memset(&le, 0, sizeof(le));
+
+   /*
+* We may be running from a nested threaded interrupt in which case
+* we didn't get the timestamp from edge_irq_handler().
+*/
+   if (!edet->timestamp) {
+   le.timestamp = ktime_get_ns();
+   if (line->num_descs != 1)
+   edet->seqno = atomic_inc_return(&line->seqno);
+   } else {
+   le.timestamp = edet->timestamp;
+   }
+   edet->timestamp = 0;
+
+   if (edet->flags == (GPIOLINE_FLAG_V2_EDGE_RISING |
+   GPIOLINE_FLAG_V2_EDGE_FALLING)) {
+   int level = gpiod_get_value_cansleep(desc);
+
+   if (level)
+   /* Emit low-to-high event */
+   le.id = GPIOLINE_EVENT_RISING_EDGE;
+   else
+   /* Emit high-to-low event */
+   le.id = GPIOLINE_EVENT_FALLING_EDGE;
+   } else if (edet->flags == GPIOLINE_FLAG_V2_EDGE_RISING) {
+   /* Emit low-to-high event */
+   le.id = GPIOLINE_EVENT_RISING_EDGE;
+   } else if (edet->flags == GPIOLINE_FLAG_V2_EDGE_FALLING) {
+   /* Emit high-to-low event */
+   le.id = GPIOLINE_EVENT_FALLING_EDGE;
+   } else {
+   return IRQ_NONE;
+   }
+   edet->line_seqno++;
+   le.line_seqno = edet->line_seqno;
+   le.seqno = (line->num_descs == 1) ? le.line_seqno : edet->seqno;
+   le.offset = gpio_chip_hwgpio(desc);
+
+   ret = kfifo_in_spinlocked_noirqsave(&line->events, &le,
+   1, &line->wait.lock);
+   if (ret)
+   w

[PATCH v2 13/18] tools: gpio: port gpio-watch to v2 uAPI

2020-07-24 Thread Kent Gibson
Port the gpio-watch tool to the latest GPIO uAPI.

Signed-off-by: Kent Gibson 
---
 tools/gpio/gpio-watch.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/gpio/gpio-watch.c b/tools/gpio/gpio-watch.c
index 5cea24fddfa7..0dd5a04ab250 100644
--- a/tools/gpio/gpio-watch.c
+++ b/tools/gpio/gpio-watch.c
@@ -21,8 +21,8 @@
 
 int main(int argc, char **argv)
 {
-   struct gpioline_info_changed chg;
-   struct gpioline_info req;
+   struct gpioline_info_changed_v2 chg;
+   struct gpioline_info_v2 req;
struct pollfd pfd;
int fd, i, j, ret;
char *event, *end;
@@ -40,11 +40,11 @@ int main(int argc, char **argv)
for (i = 0, j = 2; i < argc - 2; i++, j++) {
memset(&req, 0, sizeof(req));
 
-   req.line_offset = strtoul(argv[j], &end, 0);
+   req.offset = strtoul(argv[j], &end, 0);
if (*end != '\0')
goto err_usage;
 
-   ret = ioctl(fd, GPIO_GET_LINEINFO_WATCH_IOCTL, &req);
+   ret = ioctl(fd, GPIO_GET_LINEINFO_WATCH_V2_IOCTL, &req);
if (ret) {
perror("unable to set up line watch");
return EXIT_FAILURE;
@@ -87,7 +87,7 @@ int main(int argc, char **argv)
}
 
printf("line %u: %s at %llu\n",
-  chg.info.line_offset, event, chg.timestamp);
+  chg.info.offset, event, chg.timestamp);
}
}
 
-- 
2.27.0



  1   2   3   4   5   6   7   8   9   10   >